Просмотр исходного кода

Some fixes in examples

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.5.1
Erez Shinan 7 лет назад
Родитель
Сommit
4397d38daa
2 измененных файлов: 4 добавлений и 6 удалений
  1. +1
    -1
      examples/conf_nolex.py
  2. +3
    -5
      lark/reconstruct.py

+ 1
- 1
examples/conf_nolex.py Просмотреть файл

@@ -36,7 +36,7 @@ this="that",4
"""

r = parser.parse(sample_conf)
print r.pretty()
print (r.pretty())

if __name__ == '__main__':
test()

+ 3
- 5
lark/reconstruct.py Просмотреть файл

@@ -68,7 +68,7 @@ class Reconstructor:
return to_write

d = defaultdict(list)
for name, expansions in parser.rules.items():
for name, (expansions, options) in parser.rules.items():
for expansion, alias in expansions:
if alias:
d[alias].append(expansion)
@@ -77,8 +77,8 @@ class Reconstructor:
d[name].append(expansion)

rules = []
expand1s = {name.lstrip('!').lstrip('?') for name in d
if name.startswith(('?', '!?'))} # XXX Ugly code
expand1s = {name for name, (_x, options) in parser.rules.items()
if options and options.expand1}

for name, expansions in d.items():
for expansion in expansions:
@@ -86,8 +86,6 @@ class Reconstructor:
(MatchTerminal(sym) if is_terminal(sym) else MatchTree(sym),)
for sym in expansion if not is_discarded_terminal(sym)]

name = name.lstrip('!').lstrip('?')

rules.append((name, reduced, WriteTokens(name, expansion).f))
self.rules = rules



Загрузка…
Отмена
Сохранить