Class DynamicParseTreeWalker

java.lang.Object
org.antlr.v4.runtime.tree.ParseTreeWalker
io.github.douira.glsl_transformer.transform.DynamicParseTreeWalker

public class DynamicParseTreeWalker extends ParseTreeWalker
The dynamic parse tree walker can with structural modification of a node's child array. This enables injection of new nodes without disallowing such modifications to happen during tree walking.
  • Field Details

    • DEFAULT

      public static final DynamicParseTreeWalker DEFAULT
      The default instance of the dynamic parse tree walker.
  • Constructor Details

    • DynamicParseTreeWalker

      public DynamicParseTreeWalker()
  • Method Details

    • walk

      public void walk(ParseTreeListener listener, ParseTree tree)
      Copied from ANTLR's ParseTreeWalker.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:
      walk in class ParseTreeWalker
      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.