Browse Source

Bug fix for Discard and make the syntax more pythonic

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.5.1
Kevin Latimer 6 years ago
parent
commit
26ce48b940
1 changed files with 9 additions and 13 deletions
  1. +9
    -13
      lark/tree.py

+ 9
- 13
lark/tree.py View File

@@ -106,11 +106,10 @@ class Transformer(object):
def transform(self, tree):
items = []
for c in tree.children:
if isinstance(c, Tree):
try:
items.append(self.transform(c))
except Discard:
pass
try:
items.append(self.transform(c) if isinstance(c, Tree) else c)
except Discard:
pass
try:
f = self._get_func(tree.data)
except AttributeError:
@@ -183,16 +182,13 @@ class Transformer_NoRecurse(Transformer):
else:
return f(t)

for subtree in (subtrees):
for subtree in reversed(subtrees):
children = []
for c in subtree.children:
if isinstance(c, Tree):
try:
children.append(_t(c))
except Discard:
pass
else:
children.append(c)
try:
children.append(_t(c) if isinstance(c, Tree) else c)
except Discard:
pass
subtree.children = children

return _t(tree)


Loading…
Cancel
Save