Class PrintVisitor
java.lang.Object
org.antlr.v4.runtime.tree.AbstractParseTreeVisitor<Void>
io.github.douira.glsl_transformer.print.PrintVisitor
- All Implemented Interfaces:
ParseTreeVisitor<Void>
The print visitor visits the parse tree and reprints it while preserving the
position and content of hidden tokens. This means it preserves all newlines
even if the parsed nodes that contains them was removed. This is useful
because it doesn't necessarily change the line numbers during patching.
Local roots in the parse tree tell print visitor what changes have been made
to the original parse tree and from which alternative token streams it has to
read when it prints newly inserted nodes (=local roots) and their subtrees.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringprintTree(BufferedTokenStream rootTokenStream, ExtendedContext tree) Prints the given parse tree that references the given token stream.static StringprintTree(BufferedTokenStream rootTokenStream, ExtendedContext tree, TokenFilter<?> tokenFilter) Prints the given parse tree that references the given token stream.visitChildren(RuleNode node) The visitor method that the print visitor overrides in order to collect each node's intervals.visitTerminal(TerminalNode node) Methods inherited from class org.antlr.v4.runtime.tree.AbstractParseTreeVisitor
aggregateResult, defaultResult, shouldVisitNextChild, visit, visitErrorNode
-
Method Details
-
printTree
public static String printTree(BufferedTokenStream rootTokenStream, ExtendedContext tree, TokenFilter<?> tokenFilter) Prints the given parse tree that references the given token stream. Sets up the given node as a root node if that hasn't happened already. If the given token filter is notnull, it will be used to check if each otherwise qualified token should be printed.- Parameters:
rootTokenStream- The token stream for the parse treetree- The parse tree to printtokenFilter- An additional token filter to check before printing each otherwise qualified token- Returns:
- The printed parse tree that includes the results of the transformations
-
printTree
Prints the given parse tree that references the given token stream. Sets up the given node as a root node if that hasn't happened already.- Parameters:
rootTokenStream- The token stream for the parse treetree- The parse tree to print- Returns:
- The printed parse tree that includes the results of the transformations
- See Also:
-
visitAndJoin(BufferedTokenStream, ExtendedContext, Interval, TokenFilter)printTree(BufferedTokenStream, ExtendedContext, TokenFilter)
-
visitChildren
The visitor method that the print visitor overrides in order to collect each node's intervals. The current local root is updated when a local root node is found. Any created intervals for printing are attributed to the current local root in order to know which token stream the interval's indexes refer to.- Specified by:
visitChildrenin interfaceParseTreeVisitor<Void>- Overrides:
visitChildrenin classAbstractParseTreeVisitor<Void>- Implementation Note:
- intervals that cover tokens that are not part of children (which are only hidden tokens like whitespace because terminal nodes are children too) are moved after inserted nodes, which are local roots, through this process. this happens because fetchNext is not updated for local roots which causes the next non-local-root child (or at the after end of the child list) to add the whole interval covering the child after the child itself has been visited.
-
visitTerminal
- Specified by:
visitTerminalin interfaceParseTreeVisitor<Void>- Overrides:
visitTerminalin classAbstractParseTreeVisitor<Void>
-