Example usage for org.antlr.v4.runtime ParserRuleContext getStart

List of usage examples for org.antlr.v4.runtime ParserRuleContext getStart

Introduction

In this page you can find the example usage for org.antlr.v4.runtime ParserRuleContext getStart.

Prototype

public Token getStart() 

Source Link

Document

Get the initial token in this context.

Usage

From source file:org.tvl.goworks.editor.go.parser.GoParserAnchorListener.java

License:Open Source License

private void handleEnterAnchor(ParserRuleContext ctx) {
    anchorPositions.push(ctx.getStart().getStartIndex());
}

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();//  ww w .  jav  a 2 s.  c  o m
    if (stop != null) {
        endLine = stop.getLine();
        endCol = stop.getCharPositionInLine() + 1;
    }

    return new DiagnosticPos(diagnosticSrc, startLine, endLine, startCol, endCol);
}

From source file:org.xgmtk.lore.ast.ASTBuilder.java

License:Apache License

protected void idNodeAsResult(ParserRuleContext ctx, String idString) {
    this.result(id(idString, loc(src, ctx.getStart().getLine())));
}

From source file:org.xgmtk.lore.ast.ASTBuilder.java

License:Apache License

protected AST buildOperatorTree(ParserRuleContext ctx, final NonTerminalSymbol[] ops) {
    //      printContext(ctx);
    List<AST> cs = this.getChildrenList();
    //      System.err.println("ParseTree: \""+ctx.getText()+"\"");
    //      System.err.println("AST Children: "+cs.size());
    //      System.err.println("ParseTree Children: "+ctx.getChildCount());
    AST left = cs.get(0);/*from  w  w  w.j ava  2 s.c  om*/
    int ci = 1;
    for (int i = 1; i < ctx.getChildCount(); i += 2) {
        AST right = cs.get(ci++);
        NonTerminalSymbol t = selectNonterminalSymbol(ctx, ctx.getChild(i).getText(), ops);
        left = node(t, loc(src, ctx.getStart().getLine()), left, right);
    }
    return left;
}

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);//from   w w  w.j  a v a 2  s  .  c om
}

From source file:processing.mode.java.preproc.PdeParseTreeListener.java

License:Open Source License

/**
 * Endpoint for ANTLR to call after parsing a method declaration.
 *
 * <p>//from  w  w w .  j a va 2 s.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:ruke.vrj.phase.Definition.java

License:Open Source License

private final void addAlreadyDefiedResult(final ParserRuleContext ctx, final int start, final int end,
        final Symbol original) {
    this.addAlreadyDefiedResult(ctx.getStart().getInputStream().getSourceName(), ctx.getStart().getLine(),
            start, end, original);//from   w w  w. java  2 s  .c o m
}

From source file:ruke.vrj.phase.TypeCheck.java

License:Open Source License

private final void checkForNumeric(final ParserRuleContext ctx, final Symbol expression) {
    if (!TypeChecker.isValidNumber(expression)) {
        this.results.add(new Result(ctx.getStart().getInputStream().getSourceName(), ctx.getStart().getLine(),
                ctx.getStart().getCharPositionInLine(),
                ctx.getStart().getCharPositionInLine() + ctx.getText().length(), "Expected number"));
    }/*from  w  w  w  .  j  av a  2s. co  m*/
}

From source file:ruke.vrj.phase.TypeCheck.java

License:Open Source License

private final void checkForBoolean(final ParserRuleContext ctx, final Symbol expression) {
    if (!TypeChecker.compatible(this.booleanType, expression)) {
        this.results.add(new Result(ctx.getStart().getInputStream().getSourceName(), ctx.getStart().getLine(),
                ctx.getStart().getCharPositionInLine(),
                ctx.getStart().getCharPositionInLine() + ctx.getText().length(),
                "Expected boolean expression"));
    }/*w  ww.j  a va 2 s.co  m*/
}

From source file:swiprolog.visitor.Visitor4Internal.java

License:Open Source License

/**
 * Create {@link SourceInfoObject} for given context.
 *
 * @param ctx/*from  ww w  . ja  va 2s.  c o 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);
}