-
Notifications
You must be signed in to change notification settings - Fork 28
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
fluent.syntax/fluent/syntax/ast.py
Outdated
@@ -14,25 +14,59 @@ class Visitor(object): | |||
descends into the children of the given AST node. | |||
''' | |||
def visit(self, value): |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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
python-fluent/fluent.syntax/fluent/syntax/errors.py
Lines 4 to 8 in f3f9053
class ParseError(Exception): | |
def __init__(self, code, *args): | |
self.code = code | |
self.args = args | |
self.message = get_error_message(code, args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind blown.
You cannot un-tuple .args
.
Also, deprecate
.traverse
.