diff --git a/examples/python3.g b/examples/python3.g index 61dc1ee..bb5a4e8 100644 --- a/examples/python3.g +++ b/examples/python3.g @@ -165,7 +165,7 @@ string: STRING | LONG_STRING // Tokens NAME: /[a-zA-Z_]\w*/ -COMMENT: /\#[^\n]*/ +COMMENT: /#[^\n]*/ _NEWLINE: ( /\r?\n[\t ]*/ | COMMENT )+ @@ -177,8 +177,8 @@ _NEWLINE: ( /\r?\n[\t ]*/ | COMMENT )+ // STRING : /[ub]?r?("(?!"").*?(?', '_IGNORE': r'%ignore', '_IMPORT': r'%import', - 'NUMBER': '\d+', + 'NUMBER': r'\d+', } RULES = { @@ -294,7 +294,9 @@ def _literal_to_pattern(literal): flags = None assert v[0] == v[-1] and v[0] in '"/' - x = v[1:-1].replace("'", r"\'") + x = v[1:-1] + x = re.sub(r'(\\[wd/]|\\\[|\\\])', r'\\\1', x) + x = x.replace("'", r"\'") s = literal_eval("u'''%s'''" % x) return { 'STRING': PatternStr, 'REGEXP': PatternRE }[literal.type](s, flags) diff --git a/lark/tools/nearley.py b/lark/tools/nearley.py index c6f9a2d..107b8ae 100644 --- a/lark/tools/nearley.py +++ b/lark/tools/nearley.py @@ -30,7 +30,7 @@ nearley_grammar = r""" js: JS? NAME: /[a-zA-Z_$]\w*/ - COMMENT: /\#[^\n]*/ + COMMENT: /#[^\n]*/ REGEXP: /\[.*?\]/ STRING: /".*?"/