changeset 53:1f8c474ca8b3

bug fix: modify escape character parsing rule.
author Ryoma SHINYA <shinya@firefly.cr.ie.u-ryukyu.ac.jp>
date Wed, 25 Aug 2010 20:50:52 +0900
parents abb0691e792a
children 36cdfcaf5420
files pyrect/regexp/lexer.py pyrect/regexp/parser.py
diffstat 2 files changed, 8 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/pyrect/regexp/lexer.py	Mon Aug 23 20:00:04 2010 +0900
+++ b/pyrect/regexp/lexer.py	Wed Aug 25 20:50:52 2010 +0900
@@ -13,14 +13,19 @@
     'CARET',
     'DOLLAR',
     'NORMALCHAR',
-    'ESCAPECHAR',
     'MBCHAR',
     'DASH',
     'ANYCHAR',
+    'ESCAPECHAR',
     'PLUS',
     'QMARK'
     )
 
+def t_ESCAPECHAR(t):
+    ur'\\[ -~]'
+    t.value = t.value[-1]
+    return t
+
 def t_UNION(t):
     ur'\|'
     return t
@@ -69,11 +74,6 @@
     ur'\.'
     return t
 
-def t_ESCAPECHAR(t):
-    ur'\\[ -~]'
-    t.value = t.value[-1]
-    return t
-
 def t_NORMALCHAR(t):
     ur'[ -~]' # match ascii
     t.value
--- a/pyrect/regexp/parser.py	Mon Aug 23 20:00:04 2010 +0900
+++ b/pyrect/regexp/parser.py	Wed Aug 25 20:50:52 2010 +0900
@@ -26,6 +26,7 @@
     Concat(Concat((MBCharacter:'あ').(Star:('い')*)).(MBCharacter:'う'))
     >>> parser.parse('[a-f123]')
     CharClass[(Range:'a'-'f'),(Character:'1'),(Character:'2'),(Character:'3')]
+    >>> parser.parse('/\* *TODO')
     """
     BASE_DIR = os.path.dirname(os.path.abspath(__file__))
 
@@ -168,7 +169,7 @@
 
 def p_atom8(p):
     'atom : ESCAPECHAR'
-    p[0] = EscapeCharacter(p[1])
+    p[0] = Character(p[1])
 
 def p_charclass1(p):
     'charclass : charclass cclass'