mirror of https://github.com/lark-parser/lark.git
BUGIX in lexer: Embedding strings overwrote priority (Issue #121)
This commit is contained in:
parent
594a271a4e
commit
0f0776c0fa
|
@ -143,6 +143,8 @@ def _create_unless(tokens):
|
||||||
for retok in tokens_by_type.get(PatternRE, []):
|
for retok in tokens_by_type.get(PatternRE, []):
|
||||||
unless = [] # {}
|
unless = [] # {}
|
||||||
for strtok in tokens_by_type.get(PatternStr, []):
|
for strtok in tokens_by_type.get(PatternStr, []):
|
||||||
|
if strtok.priority > retok.priority:
|
||||||
|
continue
|
||||||
s = strtok.pattern.value
|
s = strtok.pattern.value
|
||||||
m = re.match(retok.pattern.to_regexp(), s)
|
m = re.match(retok.pattern.to_regexp(), s)
|
||||||
if m and m.group(0) == s:
|
if m and m.group(0) == s:
|
||||||
|
|
|
@ -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'ABB')
|
||||||
self.assertRaises((ParseError, UnexpectedInput), l.parse, u'AAAABB')
|
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')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue