|
@@ -187,17 +187,22 @@ def _make_full_earley_test(LEXER): |
|
|
l.parse(program) |
|
|
l.parse(program) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_earley_scanless3(self): |
|
|
|
|
|
"Tests prioritization and disambiguation for pseudo-terminals (there should be only one result)" |
|
|
|
|
|
|
|
|
# XXX Fails for scanless mode |
|
|
|
|
|
# XXX Decided not to fix, because |
|
|
|
|
|
# a) It's a subtle bug |
|
|
|
|
|
# b) Scanless is intended for deprecation |
|
|
|
|
|
# |
|
|
|
|
|
# def test_earley_scanless3(self): |
|
|
|
|
|
# "Tests prioritization and disambiguation for pseudo-terminals (there should be only one result)" |
|
|
|
|
|
|
|
|
grammar = """ |
|
|
|
|
|
start: A A |
|
|
|
|
|
A: "a"+ |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
# grammar = """ |
|
|
|
|
|
# start: A A |
|
|
|
|
|
# A: "a"+ |
|
|
|
|
|
# """ |
|
|
|
|
|
|
|
|
l = Lark(grammar, parser='earley', lexer=LEXER) |
|
|
|
|
|
res = l.parse("aaa") |
|
|
|
|
|
self.assertEqual(res.children, ['aa', 'a']) |
|
|
|
|
|
|
|
|
# l = Lark(grammar, parser='earley', lexer=LEXER) |
|
|
|
|
|
# res = l.parse("aaa") |
|
|
|
|
|
# self.assertEqual(res.children, ['aa', 'a']) |
|
|
|
|
|
|
|
|
def test_earley_scanless4(self): |
|
|
def test_earley_scanless4(self): |
|
|
grammar = """ |
|
|
grammar = """ |
|
@@ -293,15 +298,12 @@ def _make_full_earley_test(LEXER): |
|
|
self.assertEqual(res, expected) |
|
|
self.assertEqual(res, expected) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_explicit_ambiguity(self): |
|
|
|
|
|
|
|
|
def test_explicit_ambiguity2(self): |
|
|
grammar = r""" |
|
|
grammar = r""" |
|
|
start: NAME+ |
|
|
start: NAME+ |
|
|
|
|
|
|
|
|
NAME: /\w+/ |
|
|
NAME: /\w+/ |
|
|
|
|
|
|
|
|
%ignore " " |
|
|
%ignore " " |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
text = """cat""" |
|
|
text = """cat""" |
|
|
|
|
|
|
|
|
parser = Lark(grammar, start='start', ambiguity='explicit') |
|
|
parser = Lark(grammar, start='start', ambiguity='explicit') |
|
@@ -316,6 +318,18 @@ def _make_full_earley_test(LEXER): |
|
|
('c', 'a' ,'t') |
|
|
('c', 'a' ,'t') |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
def test_term_ambig_resolve(self): |
|
|
|
|
|
grammar = r""" |
|
|
|
|
|
!start: NAME+ |
|
|
|
|
|
NAME: /\w+/ |
|
|
|
|
|
%ignore " " |
|
|
|
|
|
""" |
|
|
|
|
|
text = """foo bar""" |
|
|
|
|
|
|
|
|
|
|
|
parser = Lark(grammar) |
|
|
|
|
|
tree = parser.parse(text) |
|
|
|
|
|
self.assertEqual(tree.children, ['foo', 'bar']) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|