BUGIX in lexer: Embedding strings overwrote priority (Issue #121)

This commit is contained in:
Erez Shinan 2018-04-24 15:36:53 +03:00
parent 594a271a4e
commit 0f0776c0fa
2 changed files with 14 additions and 0 deletions

View File

@ -143,6 +143,8 @@ def _create_unless(tokens):
for retok in tokens_by_type.get(PatternRE, []):
unless = [] # {}
for strtok in tokens_by_type.get(PatternStr, []):
if strtok.priority > retok.priority:
continue
s = strtok.pattern.value
m = re.match(retok.pattern.to_regexp(), s)
if m and m.group(0) == s:

View File

@ -1173,6 +1173,18 @@ def _make_parser_test(LEXER, PARSER):
self.assertRaises((ParseError, UnexpectedInput), l.parse, u'ABB')
self.assertRaises((ParseError, UnexpectedInput), l.parse, u'AAAABB')
@unittest.skipIf(PARSER=='earley', "Priority not handled correctly right now") # TODO XXX
def test_priority_vs_embedded(self):
g = """
A.2: "a"
WORD: ("a".."z")+
start: (A | WORD)+
"""
l = _Lark(g)
t = l.parse('abc')
self.assertEqual(t.children, ['a', 'bc'])
self.assertEqual(t.children[0].type, 'A')