Replies: 6 comments 5 replies
-
Yeah this makes a lot of sense. The only thing I think I would change is to have a top-level Also this would be useful for the rust binding; this would be traits. |
Beta Was this translation helpful? Give feedback.
-
If this is reasonable we should probably bike shed a little then 😄 A first attempt will be for regexp flag processing since it is very repetitive codewise. |
Beta Was this translation helpful? Give feedback.
-
My only thing is I think I'd prefer to call them "interfaces" rather than "contracts" |
Beta Was this translation helpful? Give feedback.
-
Do we anticipate multiple contracts/interfaces per node? I think it's unlikely. |
Beta Was this translation helpful? Give feedback.
-
Another thought/note related to this is we could also use it for *TargetNode and the corresponding non-target variant since they share most fields except the value. |
Beta Was this translation helpful? Give feedback.
-
@eregon The contract for any template which uses them could decide to pick what works best. We can choose whether abstract superclass fits best or whether interface does. |
Beta Was this translation helpful? Give feedback.
-
Four regexp nodes (e.g RegularExpressionNode, InterpolatedRegularExpressionNode, ...) have the same set of
isIgnoreCase
regexp flag methods to evaluate RegularExpressionFlags). There are some other common things we do like getName() across several node types where we can share common logic due to the node having an interface attached. It would be nice to attach these subsets of behavior to nodes. Look at thecontracts
field below:I picked names and I don't want to bike shed on that at the moment so let's consider the idea more first. In this case, RegularExpressionFlagsContract would have a pre-made Java interface which contains all the signatures associated with examining flags. The generator for Nodes would just add
implements
for each contract. Without something like this we are in the position if we want to call these methods we need four independent piece of code (since we have 4 regexp types with flags).The added possible bonus here is this could be useful for Ruby as well. At a minimum we could make empty marker modules so we could flag things as performing calls (e.g. node.kind_of? PerformsCallContract). Markers would decouple some of the need to try and keep things are one combined node when more smaller nodes would work. The other possibility here is it could make some rbs or sorbet sorts of typing systems with richer information.
I should add I realize for regexp we could just add that interface manually just in the Java side of things but I like being able to read config.yml and I like the notion this could be more useful than some hard-coded Java. Having said that if this has no value being in config.yml we will just likely only fix this in Java generated code.
Beta Was this translation helpful? Give feedback.
All reactions