public String toString(Recognizer r) { String channelStr = ""; if ( channel>0 ) { channelStr=",channel="+channel; } String txt = getText(); if ( txt!=null ) { txt = txt.replace("\n","\\n"); txt = txt.replace("\r","\\r"); txt = txt.replace("\t","\\t"); } else { txt = "<no text>"; } String typeString = String.valueOf(type); if ( r!=null ) { typeString = r.getVocabulary().getDisplayName(type); } return "[@"+getTokenIndex()+","+start+":"+stop+"='"+txt+"',<"+typeString+">"+channelStr+","+line+":"+getCharPositionInLine()+"]"; } }
@Override public String getText() { if (type != null) { setText(type); } return super.getText(); } }
@Override public String toString() { String channelStr = ""; if ( channel>0 ) { channelStr=",channel="+channel; } String txt = getText(); if ( txt!=null ) { txt = txt.replace("\n","\\n"); txt = txt.replace("\r","\\r"); txt = txt.replace("\t","\\t"); } else { txt = "<no text>"; } return "[@"+getTokenIndex()+","+start+":"+stop+"='"+txt+"',<"+type+">"+channelStr+","+line+":"+getCharPositionInLine()+"]"; } }
@Override public String toString() { String channelStr = ""; if ( channel>0 ) { channelStr=",channel="+channel; } String txt = getText(); if ( txt!=null ) { txt = txt.replace("\n","\\n"); txt = txt.replace("\r","\\r"); txt = txt.replace("\t","\\t"); } else { txt = "<no text>"; } return "[@"+getTokenIndex()+","+start+":"+stop+"='"+txt+"',<"+type+">"+channelStr+","+line+":"+getCharPositionInLine()+"]"; } }
@Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { int fromIndex = getCharIndex(inputContent, line-1, charPositionInLine); CommonToken token = (CommonToken) offendingSymbol; int toIndex; if (token != null && token.getType() != Token.EOF) toIndex = fromIndex + token.getText().length() - 1; else toIndex = fromIndex; errors.add(new Range(fromIndex, toIndex)); }
public String toString(Recognizer r) { String channelStr = ""; if ( channel>0 ) { channelStr=",channel="+channel; } String txt = getText(); if ( txt!=null ) { txt = txt.replace("\n","\\n"); txt = txt.replace("\r","\\r"); txt = txt.replace("\t","\\t"); } else { txt = "<no text>"; } String typeString = String.valueOf(type); if ( r!=null ) { typeString = r.getVocabulary().getDisplayName(type); } return "[@"+getTokenIndex()+","+start+":"+stop+"='"+txt+"',<"+typeString+">"+channelStr+","+line+":"+getCharPositionInLine()+"]"; } }
private static SyntaxErrorEvent generateInvalidVariableError(Object offendingSymbol, int line, int charPositionInLine, RecognitionException e, CommonToken token) { String chars = token.getText().length() == 1 ? "character" : "sequence of characters"; if( charPositionInLine == 0 ) { if( "in".equals( token.getText() ) || REUSABLE_KEYWORDS.contains( token.getText() ) ) { return new SyntaxErrorEvent( FEELEvent.Severity.ERROR, Msg.createMessage( Msg.INVALID_VARIABLE_NAME_START, "keyword", token.getText() ), e, line, return new SyntaxErrorEvent( FEELEvent.Severity.ERROR, Msg.createMessage( Msg.INVALID_VARIABLE_NAME_START, chars, token.getText() ), e, line, } else if( "in".equals( token.getText() ) ) { return new SyntaxErrorEvent(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.INVALID_VARIABLE_NAME, "keyword", token.getText()), e, line, charPositionInLine, offendingSymbol); } else if( "}".equals( token.getText() ) && e != null && e.getRecognizer() instanceof Parser && ((Parser)e.getRecognizer()).getRuleInvocationStack().contains( "key" ) ) { return new SyntaxErrorEvent(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.MISSING_EXPRESSION, e.getCtx().getText()), } else { return new SyntaxErrorEvent( FEELEvent.Severity.ERROR, Msg.createMessage( Msg.INVALID_VARIABLE_NAME, chars, token.getText() ),
public String toString(@Nullable Recognizer<?, ?> r) { String channelStr = ""; if ( channel>0 ) { channelStr=",channel="+channel; } String txt = getText(); if ( txt!=null ) { txt = txt.replace("\n","\\n"); txt = txt.replace("\r","\\r"); txt = txt.replace("\t","\\t"); } else { txt = "<no text>"; } String typeString = String.valueOf(type); if ( r!=null ) { typeString = r.getVocabulary().getDisplayName(type); } return "[@"+getTokenIndex()+","+start+":"+stop+"='"+txt+"',<"+typeString+">"+channelStr+","+line+":"+getCharPositionInLine()+"]"; } }
if( parser.getRuleInvocationStack().contains( "nameDefinition" ) ) { error = generateInvalidVariableError(offendingSymbol, line, charPositionInLine, e, token); } else if ( "}".equals(token.getText()) && tokenIndex > 1 && ":".equals(parser.getTokenStream().get(tokenIndex - 1).getText()) ) { error = new SyntaxErrorEvent( FEELEvent.Severity.ERROR, Msg.createMessage(Msg.MISSING_EXPRESSION, parser.getTokenStream().get(tokenIndex - 2).getText()),
public static void wipeCharPositionInfoAndWhitespaceTokens(CodeBuffTokenStream tokens) { tokens.fill(); CommonToken dummy = new CommonToken(Token.INVALID_TYPE, ""); dummy.setChannel(Token.HIDDEN_CHANNEL); Token firstRealToken = tokens.getNextRealToken(-1); for (int i = 0; i<tokens.size(); i++) { if ( i==firstRealToken.getTokenIndex() ) continue; // don't wack first token CommonToken t = (CommonToken)tokens.get(i); if ( t.getText().matches("\\s+") ) { tokens.getTokens().set(i, dummy); // wack whitespace token so we can't use it during prediction } else { t.setLine(0); t.setCharPositionInLine(-1); } } }
public void processToken(int indexIntoRealTokens, int tokenIndexInStream, boolean collectAnalysis) { CommonToken curToken = (CommonToken)testDoc.tokens.get(tokenIndexInStream); String tokText = curToken.getText(); TerminalNode node = tokenToNodeMap.get(curToken);
text = super.getText();
text = super.getText();
@Override public void syntaxError(@NotNull Recognizer<?, ?> recognizer, @Nullable Object offendingSymbol, int line, int charPositionInLine, @NotNull String msg, @Nullable RecognitionException e) { TrackBack trackback = new TrackBack(new VersionedIdentifier().withId("unknown"), line, charPositionInLine, line, charPositionInLine); // CqlTranslator.this.errors.add(new CqlTranslatorException(msg, trackback, e)); if (detailedErrors) { builder.recordParsingException(new CqlSyntaxException(msg, trackback, e)); builder.recordParsingException(new CqlTranslatorException(msg, trackback, e)); } else { if (offendingSymbol instanceof CommonToken) { CommonToken token = (CommonToken) offendingSymbol; builder.recordParsingException(new CqlSyntaxException(String.format("Syntax error at %s", token.getText()), trackback, e)); } else { builder.recordParsingException(new CqlSyntaxException("Syntax error", trackback, e)); } } } }