Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
hermansje committed May 24, 2019
1 parent d08d5eb commit 4439f71
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions antlr_ast/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,16 @@ def process_tree(antlr_tree, base_visitor_cls=None, transformer_cls=None, simpli
return tree


# TODO
# TODO use protowhat dump + DumpConfig
# duplicated in ast-viewer (also for Python)
# structure vs to_json()?
def dump_node(node, node_class=AST):
if isinstance(node, node_class):
fields = OrderedDict()
for name in node._fields:
attr = getattr(node, name, None)
if attr is None:
continue
elif isinstance(attr, node_class):
if attr is not None:
fields[name] = dump_node(attr, node_class=node_class)
elif isinstance(attr, list):
fields[name] = [dump_node(x, node_class=node_class) for x in attr]
else:
fields[name] = attr
return {"type": node.__class__.__name__, "data": fields}
elif isinstance(node, list):
return [dump_node(x, node_class=node_class) for x in node]
Expand Down

0 comments on commit 4439f71

Please sign in to comment.