Skip to content

Add Transformer API for in-place manipulation of AST #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 13, 2019

Conversation

Pike
Copy link
Contributor

@Pike Pike commented Feb 12, 2019

Also, deprecate .traverse.

@Pike Pike requested a review from stasm February 12, 2019 17:45
Copy link
Contributor

@stasm stasm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@@ -14,25 +14,59 @@ class Visitor(object):
descends into the children of the given AST node.
'''
def visit(self, value):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I liked the split between visit and visit_node, but it's perfectly fine to combine them into a single method. I guess this is done for symmetry with Transformer.visit? Also, nit: rename value to node?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, and also to follow the pattern of ast more closely. What really bothered me was that Transformer subclasses Visitor (for reasons I find odd but didn't debate), and thus had visit_node, but couldn't use it, really.

if isinstance(value, BaseNode):
return value.clone()
if isinstance(value, list):
return [visit(child) for child in value]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember that at some point we add a tuple check here: cf564c3. I think the goal was to support Annotations' args field which is a tuple.

We should probably fix it in

class ParseError(Exception):
def __init__(self, code, *args):
self.code = code
self.args = args
self.message = get_error_message(code, args)
, but perhaps it's safer to added the check here first?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pike Pike merged commit 23e649e into projectfluent:master Feb 13, 2019
@Pike Pike deleted the Transformer branch February 13, 2019 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants