List of usage examples for org.antlr.v4.runtime ParserRuleContext getStart
public Token getStart()
From source file:model.logic.ErrorHandling.java
public static void semanticError(ParserRuleContext rule, String message) { System.err.printf("<%d:%d> Error semantico: %s.\n", rule.getStart().getLine(), 1 + rule.getStart().getCharPositionInLine(), message); System.exit(0);//from w ww. j av a 2 s.c o m }
From source file:model.logic.ErrorHandling.java
public static void runtimeError(ParserRuleContext rule, String message) { System.err.printf("<%d:%d> Error en tiempo de ejecucion: %s.\n", rule.getStart().getLine(), 1 + rule.getStart().getCharPositionInLine(), message); System.exit(0);/*from w w w .j av a 2 s . c o m*/ }
From source file:net.certiv.json.converter.JsonPhaseBase.java
License:Open Source License
public String commentLeft(ParserRuleContext rc) { int tdx = rc.getStart().getTokenIndex(); if (tdx <= 0) return ""; int jdx = tdx - 1; boolean onlyWS = true; boolean done = false; while (!done) { switch (this.state.tokens.get(jdx).getType()) { case JsonLexer.Comment: case JsonLexer.CommentLine: onlyWS = false;// ww w . j a va 2 s .co m case JsonLexer.HorzWS: case JsonLexer.VertWS: if (jdx > 0) { jdx--; } else { done = true; } break; default: done = true; } } if (onlyWS) return ""; if (this.state.commentMarkers.contains(jdx)) { return ""; } else { this.state.commentMarkers.add(jdx); } StringBuilder sb = new StringBuilder(); for (; jdx < tdx; jdx++) { sb.append(this.state.tokens.get(jdx).getText()); } return sb.toString(); }
From source file:net.cpollet.thorium.analysis.listener.BaseListener.java
License:Apache License
protected Type getNodeType(ParserRuleContext ctx) { Set<Type> possibleTypes = getNodeTypes(ctx); if (possibleTypes.size() != 1) { analysisContext.addException(InvalidTypeException.ambiguousType(ctx.getStart(), possibleTypes)); return Types.NULLABLE_VOID; }/*from www .j a va 2s .c om*/ return possibleTypes.iterator().next(); }
From source file:net.cpollet.thorium.analysis.listener.BaseListener.java
License:Apache License
protected void registerVariableOrConstant(ParserRuleContext ctx, Symbol.SymbolKind symbolKind, String name, ThoriumParser.TypeContext typeCtx, ThoriumParser.ExpressionContext expressionCtx) { Type symbolType = findSymbolType(ctx, typeCtx, expressionCtx); if (symbolKind == Symbol.SymbolKind.CONSTANT && symbolType.isNullable()) { analysisContext.addException(InvalidTypeException.invalidType(ctx.getStart(), symbolType.nonNullable(), symbolType.nullable())); symbolType = symbolType.nonNullable(); }/*from w w w. j av a 2 s .com*/ if (!symbolType.isNullable() && expressionCtx == null) { analysisContext.addException(InvalidTypeException.invalidType(ctx.getStart(), symbolType.nullable(), symbolType.nonNullable())); symbolType = symbolType.nullable(); } Symbol symbol = registerSymbol(symbolKind, name, symbolType, ctx); if (symbol.getDefinedAt() != null && symbol.getDefinedAt() != ctx) { analysisContext.addException( InvalidSymbolException.alreadyDefined(ctx.getStart(), name, symbol.getDefinedAt().getStart())); } else { symbol.setDefinedAt(ctx); } if (symbol.getType() == Types.NULLABLE_VOID) { symbol.setType(symbolType); } analysisContext.setNodeTypes(ctx, asSet(symbol.getType())); if (symbol.getType() != Types.NULLABLE_VOID) { nodeObserverRegistry.notifyObservers(ctx, parseTreeListener); symbolObserverRegistry.notifyObservers(symbol, parseTreeListener); } }
From source file:net.cpollet.thorium.analysis.listener.BaseListener.java
License:Apache License
protected Symbol registerSymbol(Symbol.SymbolKind kind, String name, Type type, ParserRuleContext ctx) { SymbolTable<Symbol> ctxOriginalScope = analysisContext.getSymbolTable(ctx); if (!ctxOriginalScope.isDefinedInCurrentScope(name)) { Symbol symbol = Symbol.create(name, kind, type, ctx.getStart()); analysisContext.addSymbol(symbol); ctxOriginalScope.insert(name, symbol); }//from ww w.ja va 2s . com return ctxOriginalScope.lookup(name); }
From source file:net.cpollet.thorium.analysis.listener.ExpressionListener.java
License:Apache License
private void exitBinaryOperator(String operator, ThoriumParser.ExpressionContext leftExpr, ThoriumParser.ExpressionContext rightExpr, ParserRuleContext ctx) { Type leftType = getNodeType(leftExpr); Type rightType = getNodeType(rightExpr); if (leftType == Types.NULLABLE_VOID) { registerNodeObserver(ctx, leftExpr); }//from w w w . ja va 2 s. c o m if (rightType == Types.NULLABLE_VOID) { registerNodeObserver(ctx, rightExpr); } if (leftType == Types.NULLABLE_VOID || rightType == Types.NULLABLE_VOID) { setNodeTypes(ctx, asSet(Types.NULLABLE_VOID)); } else { Type resultType = inferMethodType(ctx.getStart(), operator, leftType, rightType); setNodeTypes(ctx, asSet(resultType)); notifyNodeObservers(ctx); } }
From source file:net.cpollet.thorium.analysis.listener.ValuesListener.java
License:Apache License
private void exitVariableOrConstantName(ParserRuleContext ctx, String name, Symbol.SymbolKind kind) { if (!getSymbolTable().isDefined(name)) { addException(InvalidSymbolException.identifierNotFound(ctx.getStart(), name)); registerSymbol(kind, name, Types.NULLABLE_VOID, ctx); }/*w ww . jav a 2 s . c o m*/ Symbol symbol = getSymbolTable().lookup(name); setNodeTypes(ctx, asSet(symbol.getType())); if (symbol.getType() == Types.NULLABLE_VOID) { registerSymbolObserver(ctx, symbol); } else { notifyNodeObservers(ctx); } }
From source file:net.maritimecloud.internal.msdl.parser.MsdlComment.java
License:Apache License
static MsdlComment parseComments(BufferedTokenStream bts, ParserRuleContext context) { return parseComments(bts.getHiddenTokensToLeft(context.getStart().getTokenIndex(), MsdlLexer.COMMENTS)); }
From source file:net.maritimecloud.internal.msdl.parser.ParsedMsdlFile.java
License:Apache License
String prefix(ParserRuleContext context) { return antlrFile.getPath() + ":[" + context.getStart().getLine() + ":" + context.getStart().getCharPositionInLine() + "] "; }