-
Notifications
You must be signed in to change notification settings - Fork 7
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
Parameterized return type in generated visitors #123
Comments
We already have A field in the class implementing a |
Edit: A Converter is not a Visitor; A Converter is generated for each Sum type, so it does not serve the same purpose as Visitor |
The original visitors predate the |
Although, you could I guess create a |
Potentially, also terminology could be revisited. i.e. drop the existing |
Are you interested in keep all three "visitor" types (Visitor, VisitorFold, Converter)? As a new person looking in, I see that all three of these are covered by Visitor<R, C> |
I see how Converter is an interface, so you have to implement them all. Was that intentional to enforce? If I were writing a converter for say "uppercase all identifiers", then I wouldn't want to implement everything rather just override some public abstract class Visitor<R, C> {
public R visit(Node node, C context): R? = defaultVisit(node, context)
// ........
public R defaultVisit(Node node, C context): R? = visitChildren(node, context)
public R visitChildren(Node node, C context): R? {
for (Node child: node.children) {
child.accept(this, context)
}
return null
}
}
public Uppercaser : Visitor<Node, Unit> {
@override
public visit(IdentifierNode node, Unit context): Node? = IdentifierNode(
identifier = node.identifier.uppercase()
)
@override
public defaultVIsit(Node node, Unit context): Node? = node
} |
In principle, I would not be opposed to combining There is a 4th kind-- |
Yes. This works well in a number of scenarios. For example, converting The style of visitor you list there requires that all child nodes are contained within a Your visitor there is a use case for class UppercaseTransform : FooLang.VisitorTransform() {
fun transformExprIdentifier(node: FooLang.Expr.Identifier) = node.copy(name = node.name.toUppercase())
} Invoking this visitor returns a new tree, with nodes from the original tree re-used if there were no changes in them. i.e. only the nodes which are changed, and their parent nodes are cloned. |
@rchowell If you do make changes to these generated visitors, please make sure to include me in any design doc reviews / PRs, etc. I am the original author of PIG but I am now its customer and much of the work I am doing now with PartiQL's query planner is heavily dependent on the |
Understood. I am new to the team and was taking a look at this package and saw some potential to consolidate classes and logic. It's not prioritized now. |
You can do both, but since
|
For transformations, it is useful to have a visitors return nodes. This issue is a feature request to add a parameterized return type to the generated visitors. Below is what the VisitorFold might look like. Fold naming is a bit confusing vs like
ContextualVisitor
orVisitorWithContext
The text was updated successfully, but these errors were encountered: