Package de.monticore.antlr4
Class MCBuildVisitor
java.lang.Object
de.monticore.antlr4.MCBuildVisitor
BuildVisitors are used in the second stage of the two-phase-parsers.
Phase one results in an ANTLR parse tree (without any AST-specific actions),
and phase is done by ANTLR
ParseTreeVisitor-instances of this class building the
MontiCore-AST representation of the input.
This class mainly provides SourcePosition and Comment related functionality.
The concrete ParseTree-to-AST transformation is handled in the generated instances of this class.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.antlr.v4.runtime.BufferedTokenStreamprotected intprotected org.antlr.v4.runtime.misc.IntervalSetstatic booleanA flag for further debugging of comment-handling.protected Stringprotected intprotected int -
Constructor Summary
ConstructorsConstructorDescriptionMCBuildVisitor(String fileName, org.antlr.v4.runtime.BufferedTokenStream bufferedTokenStream) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFinalComments(ASTNode node, org.antlr.v4.runtime.ParserRuleContext ctx) Finally, add all comment-tokens after the final AST-element as post-comments to the element.de.se_rwth.commons.SourcePositioncomputeEndPosition(org.antlr.v4.runtime.Token token) de.se_rwth.commons.SourcePositioncomputePosition(org.antlr.v4.runtime.Token token) protected CommentcreateComment(org.antlr.v4.runtime.Token token) Create a new MontiCore comment from an ANTLR token.protected voiddoComments(Consumer<Comment> addConsumer, int start, int stop) Find all (not yet found) hidden/comment tokens and calls the consumer for eachprotected voidhandleInnerComments(ASTNodeBuilder<?> builder, org.antlr.v4.runtime.ParserRuleContext ctx) Collect all fresh tokens of the same line on thecommentChannelchannel and store them as post-commentsprotected voidhandlePreComments(ASTNodeBuilder<?> builder, org.antlr.v4.runtime.ParserRuleContext ctx) Collect fresh tokens on thecommentChannelchannel and store them as pre-commentsprotected booleanisComment(org.antlr.v4.runtime.Token token) protected <T extends ASTNodeBuilder<?>>
TsetSourcePos(T builder, org.antlr.v4.runtime.ParserRuleContext ctx)
-
Field Details
-
fileName
-
bufferedTokenStream
protected org.antlr.v4.runtime.BufferedTokenStream bufferedTokenStream -
debug
public static boolean debugA flag for further debugging of comment-handling. Not printed by default due to performance -
pevPreCommentTokenIndex
protected int pevPreCommentTokenIndex -
tokenIndex
protected int tokenIndex -
commentChannel
protected int commentChannel -
commentSet
protected org.antlr.v4.runtime.misc.IntervalSet commentSet
-
-
Constructor Details
-
MCBuildVisitor
public MCBuildVisitor(String fileName, org.antlr.v4.runtime.BufferedTokenStream bufferedTokenStream)
-
-
Method Details
-
getFileName
-
setSourcePos
protected <T extends ASTNodeBuilder<?>> T setSourcePos(T builder, org.antlr.v4.runtime.ParserRuleContext ctx) -
computePosition
public de.se_rwth.commons.SourcePosition computePosition(org.antlr.v4.runtime.Token token) -
computeEndPosition
public de.se_rwth.commons.SourcePosition computeEndPosition(@Nonnull org.antlr.v4.runtime.Token token) -
handlePreComments
protected void handlePreComments(ASTNodeBuilder<?> builder, org.antlr.v4.runtime.ParserRuleContext ctx) Collect fresh tokens on thecommentChannelchannel and store them as pre-comments- Parameters:
builder- the builder to store the pre-comments onctx- the context object to walk up to
-
handleInnerComments
protected void handleInnerComments(ASTNodeBuilder<?> builder, org.antlr.v4.runtime.ParserRuleContext ctx) Collect all fresh tokens of the same line on thecommentChannelchannel and store them as post-comments- Parameters:
builder- the builder to store the post-comments onctx- the context object in which line we check
-
addFinalComments
Finally, add all comment-tokens after the final AST-element as post-comments to the element.- Parameters:
node- the final ASTNodectx- the parse tree
-
doComments
Find all (not yet found) hidden/comment tokens and calls the consumer for each- Parameters:
addConsumer- e.g.ASTNode.add_PreComment(Comment)start-IntervalSet.complement(int, int)stop-IntervalSet.complement(int, int)
-
isComment
protected boolean isComment(org.antlr.v4.runtime.Token token) -
createComment
Create a new MontiCore comment from an ANTLR token. Sets the start and end position, as well as the text.- Parameters:
token- the token- Returns:
- the comment
-