Class DynamicParseTreeWalker

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

public class DynamicParseTreeWalker extends org.antlr.v4.runtime.tree.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 Summary

    Fields
    Modifier and Type
    Field
    Description
    The default instance of the dynamic parse tree walker.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    walk(org.antlr.v4.runtime.tree.ParseTreeListener listener, org.antlr.v4.runtime.tree.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.

    Methods inherited from class org.antlr.v4.runtime.tree.ParseTreeWalker

    enterRule, exitRule

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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(org.antlr.v4.runtime.tree.ParseTreeListener listener, org.antlr.v4.runtime.tree.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 org.antlr.v4.runtime.tree.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.