Class DynamicParseTreeWalker
java.lang.Object
org.antlr.v4.runtime.tree.ParseTreeWalker
io.github.douira.glsl_transformer.traversal.DynamicParseTreeWalker
The dynamic parse tree walker can handle some structural modification of a
node's child array. This enables injection of new nodes without disallowing
such modifications to happen during tree walking.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DynamicParseTreeWalkerThe default instance of the dynamic parse tree walker. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidwalk(ParseTreeListener listener, ParseTree tree) Copied from ANTLR'sParseTreeWalker.walk(org.antlr.v4.runtime.tree.ParseTreeListener, org.antlr.v4.runtime.tree.ParseTree)but with compensation for items being added to the child array.Methods inherited from class org.antlr.v4.runtime.tree.ParseTreeWalker
enterRule, exitRule
-
Field Details
-
DEFAULT
The default instance of the dynamic parse tree walker.
-
-
Constructor Details
-
DynamicParseTreeWalker
public DynamicParseTreeWalker()
-
-
Method Details
-
walk
Copied from ANTLR'sParseTreeWalker.walk(org.antlr.v4.runtime.tree.ParseTreeListener, org.antlr.v4.runtime.tree.ParseTree)but with compensation for items being added to the child array. TODO: Check if using empty terminal nodes in general messes up ANTLR's parse tree matching (with patterns or xpath)- Overrides:
walkin classParseTreeWalker- Implementation Note:
- Node removal never reduces the length of the array so "removal" is not an issue. (since removed nodes are instead replaced with empty terminal nodes) Node addition after the current position is ok since the length is dynamically determined in the loop. The only problematic thing is node addition before the current position for which the current iteration index needs to be compensated for. This is done by fast-forwarding the iteration index after the walk happened until the current node is found again.
-