List of usage examples for org.antlr.v4.runtime ParserRuleContext getStop
public Token getStop()
From source file:org.teavm.flavour.expr.Parser.java
License:Apache License
private <T extends Expr> T withLocation(T expr, ParserRuleContext startCtx, ParserRuleContext endCtx) { expr.setStart(startCtx.getStart().getStartIndex()); expr.setEnd(endCtx.getStop().getStopIndex() + 1); return expr;//w ww. ja va 2 s . c o m }
From source file:org.tvl.goworks.editor.go.parser.GoParserAnchorListener.java
License:Open Source License
private void handleExitAnchor(ParserRuleContext ctx, int anchorId) { int start = anchorPositions.pop(); int stop = ctx.getStop() != null ? ctx.getStop().getStopIndex() + 1 : snapshot.length(); TrackingPositionRegion.Bias trackingMode = ctx.getStop() != null ? TrackingPositionRegion.Bias.Exclusive : TrackingPositionRegion.Bias.Forward; anchors.add(createAnchor(ctx, start, stop, trackingMode, anchorId)); }
From source file:org.wso2.ballerinalang.compiler.parser.BLangParserListener.java
License:Open Source License
private DiagnosticPos getCurrentPos(ParserRuleContext ctx) { int startLine = ctx.getStart().getLine(); int startCol = ctx.getStart().getCharPositionInLine() + 1; int endLine = -1; int endCol = -1; Token stop = ctx.getStop(); if (stop != null) { endLine = stop.getLine();/*from w w w .ja va2 s . c o m*/ endCol = stop.getCharPositionInLine() + 1; } return new DiagnosticPos(diagnosticSrc, startLine, endLine, startCol, endCol); }
From source file:plugins.quorum.Libraries.Language.Compile.JavaToQuorumListener.java
private void setLocation(ParserRuleContext context, quorum.Libraries.Language.Compile.Context.ParseContext$Interface quorumContext) { quorum.Libraries.Language.Compile.Location$Interface location = quorumContext.GetLocation(); location.SetLineNumber(context.getStart().getLine()); location.SetLineNumberEnd(context.getStop().getLine()); location.SetColumnNumber(context.getStart().getCharPositionInLine()); location.SetColumnNumberEnd(context.getStop().getCharPositionInLine()); location.SetIndex(context.getStart().getStartIndex()); location.SetIndex(context.getStop().getStartIndex()); location.SetFile(file);/* w ww . j a va 2 s. c o m*/ }
From source file:processing.mode.java.preproc.PdeParseTreeListener.java
License:Open Source License
/** * Endpoint for ANTLR to call after parsing a method declaration. * * <p>// w ww . ja v a 2s. c o m * Endpoint for ANTLR to call after parsing a method declaration, making any method "public" * that has: * * <ul> * <li>no other access modifier</li> * <li>return type "void"</li> * <li>is either in the context of the sketch class</li> * <li>is in the context of a class definition that extends PApplet</li> * </ul> * </p> * * @param ctx ANTLR context for the method declaration */ public void exitMethodDeclaration(ProcessingParser.MethodDeclarationContext ctx) { ParserRuleContext memCtx = ctx.getParent(); ParserRuleContext clsBdyDclCtx = memCtx.getParent(); ParserRuleContext clsBdyCtx = clsBdyDclCtx.getParent(); ParserRuleContext clsDclCtx = clsBdyCtx.getParent(); boolean inSketchContext = clsBdyCtx instanceof ProcessingParser.StaticProcessingSketchContext || clsBdyCtx instanceof ProcessingParser.ActiveProcessingSketchContext; boolean inPAppletContext = inSketchContext || (clsDclCtx instanceof ProcessingParser.ClassDeclarationContext && clsDclCtx.getChildCount() >= 4 && clsDclCtx.getChild(2).getText().equals("extends") && clsDclCtx.getChild(3).getText().endsWith("PApplet")); // Find modifiers ParserRuleContext possibleModifiers = ctx; while (!(possibleModifiers instanceof ProcessingParser.ClassBodyDeclarationContext)) { possibleModifiers = possibleModifiers.getParent(); } // Look for visibility modifiers and annotations boolean hasVisibilityModifier = false; int numChildren = possibleModifiers.getChildCount(); ParserRuleContext annoationPoint = null; for (int i = 0; i < numChildren; i++) { boolean childIsVisibility; ParseTree child = possibleModifiers.getChild(i); String childText = child.getText(); childIsVisibility = childText.equals("public"); childIsVisibility = childIsVisibility || childText.equals("private"); childIsVisibility = childIsVisibility || childText.equals("protected"); hasVisibilityModifier = hasVisibilityModifier || childIsVisibility; boolean isModifier = child instanceof ProcessingParser.ModifierContext; if (isModifier && isAnnoation((ProcessingParser.ModifierContext) child)) { annoationPoint = (ParserRuleContext) child; } } // Insert at start of method or after annoation if (!hasVisibilityModifier) { if (annoationPoint == null) { createInsertBefore(possibleModifiers.getStart(), " public "); } else { createInsertAfter(annoationPoint.getStop(), " public "); } } // Check if this was main if ((inSketchContext || inPAppletContext) && hasVisibilityModifier && ctx.getChild(1).getText().equals("main")) { foundMain = true; } }
From source file:swiprolog.visitor.Visitor4Internal.java
License:Open Source License
/** * Create {@link SourceInfoObject} for given context. * * @param ctx// w w w.j ava2 s. co m * the {@link DirectiveContext} from the parsed object * @return {@link SourceInfoObject} */ private SourceInfo getSourceInfo(ParserRuleContext ctx) { Token start = (ctx == null) ? null : ctx.getStart(); Token stop = (ctx == null) ? null : ctx.getStop(); if (stop == null) { // happens if we are at EOF... stop = start; } return (start == null) ? null : new SourceInfoObject(this.source.getSource(), start.getLine(), start.getCharPositionInLine(), this.source.getStartIndex() + start.getStartIndex() + 1, this.source.getStartIndex() + stop.getStopIndex() + 1); }
From source file:tuprolog.visitor.Visitor4Internal.java
License:Open Source License
/** * Create {@link SourceInfoObject} for given context. * * @param ctx//from w w w . j av a 2s . c o m * the {@link DirectiveContext} from the parsed object * @return {@link SourceInfoObject} */ private SourceInfo getSourceInfo(ParserRuleContext ctx) { Token start = ctx.getStart(); Token stop = ctx.getStop(); if (stop == null) { // happens if we are at EOF... stop = start; } return new SourceInfoObject(this.source.getSource(), start.getLine(), start.getCharPositionInLine(), this.source.getStartIndex() + start.getStartIndex() + 1, this.source.getStartIndex() + stop.getStopIndex() + 1); }