Procházet zdrojové kódy

Improve match_examples() for Earley (Issue #760)

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.11.2
Erez Sh před 3 roky
rodič
revize
e6dcc43478
3 změnil soubory, kde provedl 5 přidání a 4 odebrání
  1. +2
    -2
      lark/parsers/earley.py
  2. +1
    -1
      lark/parsers/xearley.py
  3. +2
    -1
      tests/test_parser.py

+ 2
- 2
lark/parsers/earley.py Zobrazit soubor

@@ -245,7 +245,7 @@ class Parser:

if not next_set and not next_to_scan:
expect = {i.expect.name for i in to_scan}
raise UnexpectedToken(token, expect, considered_rules=set(to_scan), state=frozenset(i.expect for i in to_scan))
raise UnexpectedToken(token, expect, considered_rules=set(to_scan), state=frozenset(i.s for i in to_scan))

return next_to_scan

@@ -303,7 +303,7 @@ class Parser:
solutions = [n.node for n in columns[-1] if n.is_complete and n.node is not None and n.s == start_symbol and n.start == 0]
if not solutions:
expected_terminals = [t.expect for t in to_scan]
raise UnexpectedEOF(expected_terminals, state=frozenset(i.expect for i in to_scan))
raise UnexpectedEOF(expected_terminals, state=frozenset(i.s for i in to_scan))

if self.debug:
from .earley_forest import ForestToPyDotVisitor


+ 1
- 1
lark/parsers/xearley.py Zobrazit soubor

@@ -114,7 +114,7 @@ class Parser(BaseParser):

if not next_set and not delayed_matches and not next_to_scan:
raise UnexpectedCharacters(stream, i, text_line, text_column, {item.expect.name for item in to_scan},
set(to_scan), state=frozenset(i.expect for i in to_scan))
set(to_scan), state=frozenset(i.s for i in to_scan))

return next_to_scan



+ 2
- 1
tests/test_parser.py Zobrazit soubor

@@ -2355,7 +2355,7 @@ def _make_parser_test(LEXER, PARSER):
return u.match_examples(p.parse, {
0: ['abe'],
1: ['ab'],
2: ['cbc'],
2: ['cbc', 'dbc'],
})
assert False

@@ -2364,6 +2364,7 @@ def _make_parser_test(LEXER, PARSER):
assert match_error("bbc") == 2
assert match_error("cbc") == 2
self.assertEqual( match_error("dbc"), 2 )
self.assertEqual( match_error("ebc"), 2 )


@unittest.skipIf(not regex or sys.version_info[0] == 2, 'Unicode and Python 2 do not place nicely together.')


Načítá se…
Zrušit
Uložit