| @@ -44,7 +44,7 @@ _NL: /(\r?\n)+\s*/ | |||||
| %import common.INT -> NUMBER | %import common.INT -> NUMBER | ||||
| %import common.WS_INLINE | %import common.WS_INLINE | ||||
| COMMENT: "//" /[^\n]/* | |||||
| COMMENT: /\s*/ "//" /[^\n]/* | |||||
| %ignore WS_INLINE | %ignore WS_INLINE | ||||
| %ignore COMMENT | %ignore COMMENT | ||||
| @@ -85,7 +85,7 @@ TERMINALS = { | |||||
| 'REGEXP': r'/(?!/)(\\/|\\\\|[^/\n])*?/[%s]*' % _RE_FLAGS, | 'REGEXP': r'/(?!/)(\\/|\\\\|[^/\n])*?/[%s]*' % _RE_FLAGS, | ||||
| '_NL': r'(\r?\n)+\s*', | '_NL': r'(\r?\n)+\s*', | ||||
| 'WS': r'[ \t]+', | 'WS': r'[ \t]+', | ||||
| 'COMMENT': r'//[^\n]*', | |||||
| 'COMMENT': r'\s*//[^\n]*', | |||||
| '_TO': '->', | '_TO': '->', | ||||
| '_IGNORE': r'%ignore', | '_IGNORE': r'%ignore', | ||||
| '_DECLARE': r'%declare', | '_DECLARE': r'%declare', | ||||
| @@ -94,6 +94,16 @@ class TestParsers(unittest.TestCase): | |||||
| r = g.parse('xx') | r = g.parse('xx') | ||||
| self.assertEqual( r.children[0].data, "c" ) | self.assertEqual( r.children[0].data, "c" ) | ||||
| def test_comment_in_rule_definition(self): | |||||
| g = Lark("""start: a | |||||
| a: "a" | |||||
| // A comment | |||||
| // Another | |||||
| | "b" | |||||
| """) | |||||
| r = g.parse('b') | |||||
| self.assertEqual( r.children[0].data, "a" ) | |||||
| def test_visit_tokens(self): | def test_visit_tokens(self): | ||||
| class T(Transformer): | class T(Transformer): | ||||
| def a(self, children): | def a(self, children): | ||||