Class EditContext
java.lang.Object
io.github.douira.glsl_transformer.generic.EditContext
The edit context keeps track of all changes made to a parse tree. It stores
which tokens should be omitted during printing and which nodes have been
added in the mean time. This is necessary, because 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.
An edit context is tied to a specific parse tree and is passed around for
making modifications to it. They are effectively part of the same
data structure with the parse tree containing ANTLR's things and the edit
context storing the modification information.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA local root data record contains the omission set and token stream of a registered local root. -
Constructor Summary
ConstructorsConstructorDescriptionEditContext(org.antlr.v4.runtime.tree.ParseTree root, org.antlr.v4.runtime.BufferedTokenStream rootTokenStream) Creates a new edit context with a global root node and a global root token stream. -
Method Summary
Modifier and TypeMethodDescriptionvoidMarks the editing on this edit context as finished.voidomitNodeTokens(org.antlr.v4.runtime.tree.ParseTree node) Marks the tokens encompassed by the given node as omitted in this edit context.voidregisterLocalRoot(org.antlr.v4.runtime.tree.ParseTree localRoot, org.antlr.v4.runtime.BufferedTokenStream tokenStream) Registers a given node as a new local root node together with its corresponding token stream.
-
Constructor Details
-
EditContext
public EditContext(org.antlr.v4.runtime.tree.ParseTree root, org.antlr.v4.runtime.BufferedTokenStream rootTokenStream) Creates a new edit context with a global root node and a global root token stream. This is the same as creating an empty edit context (which is disallowed) and registering the global root node as a local root node because they are effectively the same.- Parameters:
root- The global root node of the parse treerootTokenStream- The token stream from which the root node was parsed
-
-
Method Details
-
finishEditing
public void finishEditing()Marks the editing on this edit context as finished. After this point no further modifications should be made. Because this sets all omission sets of the local roots to be readonly for better caching performance, making modifications after the edit context has been marked as finished can throw an exception. -
registerLocalRoot
public void registerLocalRoot(org.antlr.v4.runtime.tree.ParseTree localRoot, org.antlr.v4.runtime.BufferedTokenStream tokenStream) Registers a given 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. Omissions of certain nodes are added to the omission set of the closest local root ancestor.- Parameters:
localRoot- The node to register as a local roottokenStream- The token stream from which this node was parsed
-
omitNodeTokens
public void omitNodeTokens(org.antlr.v4.runtime.tree.ParseTree node) Marks the tokens encompassed by the given node as omitted in this edit context. Non-hidden tokens will not be printed if they are withing the token source token interval of the node. Other nodes will however, still be printed in order to preserve whitespace.- Parameters:
node- The node for which the tokens should should be omitted
-