Class ExtendedContext
java.lang.Object
org.antlr.v4.runtime.RuleContext
org.antlr.v4.runtime.ParserRuleContext
io.github.douira.glsl_transformer.tree.ExtendedContext
- All Implemented Interfaces:
MoveCheckable,TreeMember,ParseTree,RuleNode,SyntaxTree,Tree
Implements custom behavior in parse rule contexts. This class is used as the
super class for all contexts in the parser.
This class is not meant to be constructed manually but is the base class
which ANTLR extends in the generated parser code.
The token indexes of the token intervals of new nodes have nothing to do with
the token indexes of existing nodes. Therefore, new nodes are registered as
local roots that have their own token index domain and a set of intervals in
which non-hidden tokens should not be printed.
Local root nodes store information about which nodes in their subtree have
been removed. The printer then uses this to not print any non-hidden tokens
contained within any local root's omission set.
-
Field Summary
Fields inherited from class org.antlr.v4.runtime.ParserRuleContext
children, exception, start, stopFields inherited from class org.antlr.v4.runtime.RuleContext
EMPTY, invokingState, parent -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new extended parser rule context without a parent.ExtendedContext(ParserRuleContext parent, int invokingStateNumber) Creates a new extended parser rule context. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a child to the list of children with at the given index.intgetChildIndexLike(Class<? extends ParseTree> ctxType) Finds the index of the first contained child that matches the given type.Gets the source interval for this local root that includes the whole token stream with unparsed tokens before and after the parsed tokens that this node encompasses.Gets the source interval for this node that covers the largest space.Returns a navigable set of the token indexes of the nodes that were removed from this local root.The omission set is present if this node is a local root.Override to make type more specificReturns the node that this node replaced during a tree transformation.getRoot()Find the tree's global root by checking the enclosing local root's reference.The token stream is present if this node is a local root.booleanChecks if this node is a local root.booleanisRoot()Checks if this node is the global root.voidmakeLocalRoot(BufferedTokenStream tokenStream) Registers this node as a new local root node together with its corresponding token stream.voidMarks the tokens encompassed by this node as omitted.voidprocessRemoval(Interval tokenInterval) Omits the given token interval on this node's local root.voidsetParent(ExtendedContext parent) Sets the parent and copies the root reference from the parent.voidsetPreviousNode(ParseTree previousNode) Allows the transformation phase to tell this node which node it replaces.Methods inherited from class org.antlr.v4.runtime.ParserRuleContext
addAnyChild, addChild, addChild, addChild, addErrorNode, addErrorNode, copyFrom, enterRule, exitRule, getChild, getChild, getChildCount, getRuleContext, getRuleContexts, getSourceInterval, getStart, getStop, getToken, getTokens, removeLastChild, toInfoStringMethods inherited from class org.antlr.v4.runtime.RuleContext
accept, depth, getAltNumber, getPayload, getRuleContext, getRuleIndex, getText, isEmpty, setAltNumber, setParent, toString, toString, toString, toString, toString, toStringTree, toStringTree, toStringTreeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.antlr.v4.runtime.tree.ParseTree
accept, getChild, getText, setParent, toStringTreeMethods inherited from interface org.antlr.v4.runtime.tree.SyntaxTree
getSourceIntervalMethods inherited from interface org.antlr.v4.runtime.tree.Tree
getChildCount, getPayload, toStringTree
-
Constructor Details
-
ExtendedContext
Creates a new extended parser rule context. This is required for the generated parse code to be valid.- Parameters:
parent- The parent nodeinvokingStateNumber- The invoking state number
-
ExtendedContext
public ExtendedContext()Creates a new extended parser rule context without a parent. This is also used in the generated code.
-
-
Method Details
-
getPreviousNode
Description copied from interface:MoveCheckableReturns the node that this node replaced during a tree transformation.- Specified by:
getPreviousNodein interfaceMoveCheckable- Returns:
- The replaced node
-
setPreviousNode
Description copied from interface:MoveCheckableAllows the transformation phase to tell this node which node it replaces.- Specified by:
setPreviousNodein interfaceMoveCheckable- Parameters:
previousNode- The node to set as the previous node in this position in the parent's child array that this node replaces
-
getParent
Override to make type more specific- Specified by:
getParentin interfaceParseTree- Specified by:
getParentin interfaceTree- Specified by:
getParentin interfaceTreeMember- Overrides:
getParentin classParserRuleContext
-
setParent
Sets the parent and copies the root reference from the parent. This requires the parent to have been set up before the child.- Parameters:
parent- The paren to set on this node
-
makeLocalRoot
Registers this node as a new local root node together with its corresponding token stream. This means it has its own omission set and token interval space. The token interval of omitted nodes are added to the omission set of the closest local root ancestor.- Parameters:
tokenStream- The token stream from which this node was parsed
-
isLocalRoot
public boolean isLocalRoot()Checks if this node is a local root.- Returns:
trueif the node is a local root
-
isRoot
public boolean isRoot()Checks if this node is the global root.- Returns:
trueif this node is the global root- Implementation Note:
- This is faster to check than finding the local root, taking it's root and checking if it's the same.
-
getRoot
Find the tree's global root by checking the enclosing local root's reference.- Returns:
- The accessible global tree root
-
processRemoval
public void processRemoval()Marks the tokens encompassed by this node as omitted. Non-hidden tokens will not be printed if they are withing the token source token interval of this node. Other nodes will however, still be printed in order to preserve whitespace.- Specified by:
processRemovalin interfaceTreeMember
-
processRemoval
Omits the given token interval on this node's local root.- Parameters:
tokenInterval- The token interval to be omitted- See Also:
-
getLocalRootTokenOmissions
The omission set is present if this node is a local root. Then it contains the token intervals that should be omitted by the printer when printing this local root's subtree. This method should only be called on objects that do in fact contain a local root such as those added to an attributed interval.- Returns:
- This local root's token stream if this node is a local root
-
getLocalRootOpenings
Returns a navigable set of the token indexes of the nodes that were removed from this local root.- Returns:
- Navigable set with openings
-
getTokenStream
The token stream is present if this node is a local root. Then it's the token stream that was used to construct this local root's subtree.- Returns:
- The token stream for this local root if this node is a local root,
nullotherwise
-
getFullSourceInterval
Gets the source interval for this local root that includes the whole token stream with unparsed tokens before and after the parsed tokens that this node encompasses.- Returns:
- The full source interval of the contained token stream if this node
is a local root,
nullotherwise.
-
getLargestSourceInterval
Gets the source interval for this node that covers the largest space. For local roots this is the full source interval covering all tokens in the token stream. For all other nodes it's the regular source interval covering only the tokens parsed for this node.- Returns:
- The largest source interval, never
null.
-
getChildIndexLike
Finds the index of the first contained child that matches the given type.- Parameters:
ctxType- The child type to look for- Returns:
- The index of the first child with the given index. If no child with that type was found, the length of the child array is returned as the "last" index.
-
addChild
Adds a child to the list of children with at the given index.- Parameters:
index- The index to add the node atnode- The node to add
-