Browse Source

%ignore bug fixed in xearley (thanks to issue #44)

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.5.1
Erez Shinan 7 years ago
parent
commit
6f85ca4294
2 changed files with 8 additions and 7 deletions
  1. +1
    -7
      lark/parsers/xearley.py
  2. +7
    -0
      tests/test_parser.py

+ 1
- 7
lark/parsers/xearley.py View File

@@ -52,7 +52,6 @@ class Parser:
# Define parser functions
start_symbol = start_symbol or self.start_symbol
delayed_matches = defaultdict(list)
match_after_ignore = set()

text_line = 1
text_column = 0
@@ -89,8 +88,7 @@ class Parser:
m = x.match(stream, i)
if m:
delayed_matches[m.end()] += set(to_scan)
if m.end() == len(stream):
match_after_ignore.update(set(column.to_reduce))
delayed_matches[m.end()] += set(column.to_reduce)

# TODO add partial matches for ignore too?
# s = m.group(0)
@@ -142,10 +140,6 @@ class Parser:
solutions = [n.tree for n in column.to_reduce
if n.rule.origin==start_symbol and n.start is column0]

if not solutions:
solutions = [n.tree for n in match_after_ignore
if n.rule.origin==start_symbol and n.start is column0]

if not solutions:
raise ParseError('Incomplete parse: Could not find a solution to input')
elif len(solutions) == 1:


+ 7
- 0
tests/test_parser.py View File

@@ -962,6 +962,13 @@ def _make_parser_test(LEXER, PARSER):
tree = parser.parse("int 1 ! This is a comment") # A trailing ignore token can be tricky!
self.assertEqual(tree.children, ['1'])

parser = _Lark(r"""
start : "a"*
%ignore "b"
""")
tree = parser.parse("bb")
self.assertEqual(tree.children, [])


@unittest.skipIf(LEXER==None, "Scanless doesn't support regular expressions")
def test_regex_escaping(self):


Loading…
Cancel
Save