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.
-
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.static voidwalkTree(ParseTreeListener listener, ParseTree tree)Walks the given tree with the given walker.Methods inherited from class org.antlr.v4.runtime.tree.ParseTreeWalker
enterRule, exitRule
-
Constructor Details
-
DynamicParseTreeWalker
public DynamicParseTreeWalker()
-
-
Method Details
-
walkTree
Walks the given tree with the given walker. This uses the default walker instance.- Parameters:
listener- The listener to usetree- The tree to walk
-
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.
-