Class DynamicParseTreeWalker

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

public class DynamicParseTreeWalker extends ParseTreeWalker
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 Details

    • DynamicParseTreeWalker

      public DynamicParseTreeWalker()
  • Method Details

    • walkTree

      public static void walkTree(ParseTreeListener listener, ParseTree tree)
      Walks the given tree with the given walker. This uses the default walker instance.
      Parameters:
      listener - The listener to use
      tree - The tree to walk
    • 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.