Browse Source

Some fixes in examples

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.5.1
Erez Shinan 7 years ago
parent
commit
4397d38daa
2 changed files with 4 additions and 6 deletions
  1. +1
    -1
      examples/conf_nolex.py
  2. +3
    -5
      lark/reconstruct.py

+ 1
- 1
examples/conf_nolex.py View File

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


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


if __name__ == '__main__': if __name__ == '__main__':
test() test()

+ 3
- 5
lark/reconstruct.py View File

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


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


rules = [] 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 name, expansions in d.items():
for expansion in expansions: for expansion in expansions:
@@ -86,8 +86,6 @@ class Reconstructor:
(MatchTerminal(sym) if is_terminal(sym) else MatchTree(sym),) (MatchTerminal(sym) if is_terminal(sym) else MatchTree(sym),)
for sym in expansion if not is_discarded_terminal(sym)] for sym in expansion if not is_discarded_terminal(sym)]


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

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




Loading…
Cancel
Save