List of usage examples for org.antlr.v4.runtime Token getCharPositionInLine
int getCharPositionInLine();
From source file:jetbrick.template.parser.AstCodeVisitor.java
License:Open Source License
@Override public AstNode visitDirective_tag(Directive_tagContext ctx) { Token token = ((TerminalNode) ctx.getChild(0)).getSymbol(); Position position = new Position(token.getLine(), token.getCharPositionInLine() + 5); String name = ctx.getChild(0).getText(); name = StringUtils.substringBetween(name, " ", "(").trim(); AstExpressionList expressionList = accept(ctx.expression_list()); AstStatementList block = accept(ctx.block()); return new AstDirectiveTag(name, expressionList, block, position); }
From source file:jetbrick.template.parser.AstCodeVisitor.java
License:Open Source License
@Override public AstNode visitDirective_call(Directive_callContext ctx) { Token token = ((TerminalNode) ctx.getChild(0)).getSymbol(); Position position = new Position(token.getLine(), token.getCharPositionInLine() + 6); String name = ctx.getChild(0).getText(); name = StringUtils.substringBetween(name, " ", "(").trim(); AstExpressionList expressionList = accept(ctx.expression_list()); return new AstDirectiveCall(name, expressionList, position); }
From source file:jetbrick.template.parser.AstCodeVisitor.java
License:Open Source License
@Override public AstNode visitDirective_macro(Directive_macroContext ctx) { Token token = ((TerminalNode) ctx.getChild(0)).getSymbol(); Position position = new Position(token.getLine(), token.getCharPositionInLine() + 7); String name = token.getText(); name = StringUtils.substringBetween(name, " ", "(").trim(); parseCtx.enterMacros();/*w ww . j a va 2s.c o m*/ // ?? accept(ctx.directive_macro_arguments()); // ???( body ??) List<String> argumentNames = parseCtx.getMacroArgumentNames(); AstStatementList block = accept(ctx.block()); AstDirectiveMacro macro = new AstDirectiveMacro(name, argumentNames, parseCtx.getSymbols(), block, position); try { parseCtx.defineMacro(macro); } catch (IllegalStateException e) { throw new SyntaxException(e).set(position); } parseCtx.exitMacros(); return AstDirectiveNoop.INSTANCE; }
From source file:jetbrick.template.parser.AstCodeVisitor.java
License:Open Source License
private Position pos(ParserRuleContext ctx, int childIndex) { ParseTree node = ctx.getChild(childIndex); if (node instanceof TerminalNode) { Token token = ((TerminalNode) node).getSymbol(); return new Position(token.getLine(), token.getCharPositionInLine()); } else if (node instanceof ParserRuleContext) { Token token = ctx.getStart();/*from w ww .j a v a2 s. c om*/ return new Position(token.getLine(), token.getCharPositionInLine()); } throw new UnsupportedOperationException(); }
From source file:jetbrick.template.parser.AstCodeVisitor.java
License:Open Source License
private Position pos(Object ctx) { Token token = null; if (ctx instanceof ParserRuleContext) { token = ((ParserRuleContext) ctx).getStart(); } else if (ctx instanceof TerminalNode) { token = ((TerminalNode) ctx).getSymbol(); } else if (ctx instanceof Token) { token = (Token) ctx;// www.j ava2 s . co m } else if (ctx instanceof AstExpression) { return ((AstExpression) ctx).getPosition(); } else if (ctx instanceof AstType) { return ((AstType) ctx).getPosition(); } if (token != null) { return new Position(token.getLine(), token.getCharPositionInLine()); } throw new UnsupportedOperationException(); }
From source file:kr.simula.formula.ide.ast.SyntaxErrorAdapter.java
License:Apache License
protected static IProblem makeProblem(String fileName, String msg, RecognitionException e) { Token offendingToken = e.getOffendingToken(); IProblem problem = new DefaultProblem(fileName, msg, IProblem.Internal, new String[0], ProblemSeverities.Fatal, offendingToken.getLine(), offendingToken.getCharPositionInLine(), offendingToken.getStartIndex(), offendingToken.getStopIndex()); return problem; }
From source file:languageTools.parser.InputStreamPosition.java
License:Open Source License
/** * TODO/*from w ww . j a v a 2s. com*/ * * @param start * @param stop * @param sourceFile */ public InputStreamPosition(Token start, Token stop, File sourceFile) { this(start.getLine(), start.getCharPositionInLine(), start.getStartIndex(), stop.getStopIndex(), sourceFile); }
From source file:languageTools.parser.InputStreamPosition.java
License:Open Source License
/** * TODO/* w w w.ja v a 2 s .c om*/ * * @param token * @param index * @param source */ public InputStreamPosition(Token token, int index, File source) { this(token.getLine(), token.getCharPositionInLine(), index, token.getText() == null ? index : index + token.getText().length(), source); }
From source file:me.enerccio.sp.compiler.Bytecode.java
License:Open Source License
/** * Creates new PythonBytecode object based on the bytecode, sets the source * information based on the token.//ww w . j av a2s. c o m * * @param b * @param t * may be null * @return */ public static PythonBytecode makeBytecode(Bytecode b, Token t, String functionName, ModuleData module) { PythonBytecode bytecode = null; switch (b) { case CALL: bytecode = new Call(); break; case DEL: bytecode = new Del(); break; case TEST_FUTURE: bytecode = new TestFuture(); break; case DELATTR: bytecode = new DelAttr(); break; case RESOLVE_CLOSURE: bytecode = new ResolveClosure(); break; case LOADBUILTIN: bytecode = new LoadBuiltin(); break; case PUSH_LOCALS: bytecode = new PushLocals(); break; case RCALL: bytecode = new RCall(); break; case KCALL: bytecode = new KCall(); break; case ECALL: bytecode = new ECall(); break; case ACCEPT_ITER: bytecode = new AcceptIter(); break; case TRUTH_VALUE: bytecode = new TruthValue(); break; case DUP: bytecode = new Dup(); break; case GOTO: bytecode = new Goto(); break; case JUMPIFFALSE: bytecode = new JumpIfFalse(); break; case JUMPIFTRUE: bytecode = new JumpIfTrue(); break; case JUMPIFNONE: bytecode = new JumpIfNone(); break; case JUMPIFNORETURN: bytecode = new JumpIfNoReturn(); break; case LOAD: bytecode = new Load(); break; case LOADGLOBAL: bytecode = new LoadGlobal(); break; case LOAD_FUTURE: bytecode = new LoadFuture(); break; case MAKE_FUTURE: bytecode = new MakeFuture(); break; case NOP: bytecode = new Nop(); break; case POP: bytecode = new Pop(); break; case MAKE_FIRST: bytecode = new MakeFirst(); break; case PUSH: bytecode = new Push(); break; case PUSH_ENVIRONMENT: bytecode = new PushEnvironment(); break; case RETURN: bytecode = new Return(); break; case SAVE: bytecode = new Save(); break; case SAVEGLOBAL: bytecode = new SaveGlobal(); break; case SAVEDYNAMIC: bytecode = new SaveDynamic(); break; case LOADDYNAMIC: bytecode = new LoadDynamic(); break; case IMPORT: bytecode = new Import(); break; case SWAP_STACK: bytecode = new SwapStack(); break; case KWARG: bytecode = new KwArg(); break; case UNPACK_KWARG: bytecode = new UnpackKwArg(); break; case UNPACK_SEQUENCE: bytecode = new UnpackSequence(); break; case PUSH_LOCAL_CONTEXT: bytecode = new PushLocalContext(); break; case RESOLVE_ARGS: bytecode = new ResolveArgs(); break; case GETATTR: bytecode = new GetAttr(); break; case SETATTR: bytecode = new SetAttr(); break; case ISINSTANCE: bytecode = new IsInstance(); break; case RAISE: bytecode = new Raise(); break; case RERAISE: bytecode = new Reraise(); break; case PUSH_FRAME: bytecode = new PushFrame(); break; case PUSH_EXCEPTION: bytecode = new PushException(); break; case SAVE_LOCAL: bytecode = new SaveLocal(); break; case SETUP_LOOP: bytecode = new SetupLoop(); break; case GET_ITER: bytecode = new GetIter(); break; case YIELD: bytecode = new Yield(); break; case OPEN_LOCALS: bytecode = new OpenLocals(); break; case ADD: case AND: case DIV: case EQ: case GE: case GT: case LE: case LSHIFT: case LT: case MOD: case MUL: case NE: case OR: case POW: case RSHIFT: case SUB: case XOR: case DCOLON: case QM: case RARROW: case AT: bytecode = new BinaryOperator(b); break; case D_STARTFUNC: case D_RETURN: bytecode = new Debug(b); break; } if (module == null) throw new RuntimeException("Module cannot be null. Create static ModuleProvider if necessary."); bytecode.debugModule = module; bytecode.debugFunction = functionName == null ? NO_FUNCTION : functionName; if (t != null) { bytecode.debugLine = t.getLine(); bytecode.debugCharacter = t.getCharPositionInLine(); bytecode.debugFunction = functionName; } return bytecode; }
From source file:net.cpollet.thorium.ThoriumException.java
License:Apache License
protected static String location(Token token) { return token.getLine() + ":" + (token.getCharPositionInLine() + 1) + " (" + token.getText() + ")"; }