/** * Append the text preserving the formatting (space symbols) between tokens */ void append(StringBuilder str, String appendStr, Token start, Token stop) { String spaces = start.getInputStream().getText(new org.antlr.v4.runtime.misc.Interval(start.getStartIndex(), stop.getStopIndex())); spaces = spaces.substring(start.getText().length(), spaces.length() - stop.getText().length()); str.append(spaces); str.append(appendStr); }
/** * Get formatted text between 2 tokens */ public String getFormattedText(ParserRuleContext ctx) { return ctx.start.getInputStream().getText( new org.antlr.v4.runtime.misc.Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); }
/** * Get node text including spaces */ String getText(ParserRuleContext ctx) { return ctx.start.getInputStream().getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); }
/** * Get node text including spaces */ String getText(ParserRuleContext ctx) { return ctx.start.getInputStream().getText(new org.antlr.v4.runtime.misc.Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); }
private static String getStatementString( final SingleStatementContext singleStatementContext ) { final CharStream charStream = singleStatementContext.start.getInputStream(); return charStream.getText(Interval.of( singleStatementContext.start.getStartIndex(), singleStatementContext.stop.getStopIndex() )); } }
String getText(ParserRuleContext ctx, Token start, Token stop) { return ctx.start.getInputStream().getText(new org.antlr.v4.runtime.misc.Interval(start.getStartIndex(), stop.getStopIndex())); }
/** * Returns matched part of the getText for the context. * * @param ctx the parser rule context; may not be null * @return matched part of the getText */ public static String getText(ParserRuleContext ctx) { Interval interval = new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()); return ctx.start.getInputStream().getText(interval); }
void append(StringBuilder str, TerminalNode start, TerminalNode stop) { String text = start.getSymbol().getInputStream().getText(new org.antlr.v4.runtime.misc.Interval(start.getSymbol().getStartIndex(), stop.getSymbol().getStopIndex())); str.append(text); }
/** * Executing OS command */ @Override public Integer visitHost_cmd(HplsqlParser.Host_cmdContext ctx) { trace(ctx, "HOST"); execHost(ctx, ctx.start.getInputStream().getText( new org.antlr.v4.runtime.misc.Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()))); return 0; }
@Override public void exitNonReserved(SqlBaseParser.NonReservedContext context) { // we can't modify the tree during rule enter/exit event handling unless we're dealing with a terminal. // Otherwise, ANTLR gets confused an fires spurious notifications. if (!(context.getChild(0) instanceof TerminalNode)) { int rule = ((ParserRuleContext) context.getChild(0)).getRuleIndex(); throw new AssertionError("nonReserved can only contain tokens. Found nested rule: " + ruleNames.get(rule)); } // replace nonReserved words with IDENT tokens context.getParent().removeLastChild(); Token token = (Token) context.getChild(0).getPayload(); context.getParent().addChild(new CommonToken( new Pair<>(token.getTokenSource(), token.getInputStream()), SqlBaseLexer.IDENTIFIER, token.getChannel(), token.getStartIndex(), token.getStopIndex())); } }
@Override public void enterDropTable(MySqlParser.DropTableContext ctx) { Interval interval = new Interval(ctx.start.getStartIndex(), ctx.tables().start.getStartIndex() - 1); String prefix = ctx.start.getInputStream().getText(interval); ctx.tables().tableName().forEach(tableNameContext -> { TableId tableId = parser.parseQualifiedTableId(tableNameContext.fullId()); parser.databaseTables().removeTable(tableId); parser.signalDropTable(tableId, prefix + tableId.table() + (ctx.dropType != null ? " " + ctx.dropType.getText() : "")); }); super.enterDropTable(ctx); } }
/** * {@inheritDoc} */ @Override public CharStream getInputStream() { if (i < tokens.size()) { return tokens.get(i).getInputStream(); } else if (eofToken != null) { return eofToken.getInputStream(); } else if (tokens.size() > 0) { return tokens.get(tokens.size() - 1).getInputStream(); } // no input stream information is available return null; }
/** * Constructs a new {@link CommonToken} as a copy of another {@link Token}. * * <p> * If {@code oldToken} is also a {@link CommonToken} instance, the newly * constructed token will share a reference to the {@link #text} field and * the {@link Pair} stored in {@link #source}. Otherwise, {@link #text} will * be assigned the result of calling {@link #getText}, and {@link #source} * will be constructed from the result of {@link Token#getTokenSource} and * {@link Token#getInputStream}.</p> * * @param oldToken The token to copy. */ public CommonToken(Token oldToken) { type = oldToken.getType(); line = oldToken.getLine(); index = oldToken.getTokenIndex(); charPositionInLine = oldToken.getCharPositionInLine(); channel = oldToken.getChannel(); start = oldToken.getStartIndex(); stop = oldToken.getStopIndex(); if (oldToken instanceof CommonToken) { text = ((CommonToken)oldToken).text; source = ((CommonToken)oldToken).source; } else { text = oldToken.getText(); source = new Pair<TokenSource, CharStream>(oldToken.getTokenSource(), oldToken.getInputStream()); } }
@Override public CharStream getInputStream() { if(token.isEmpty()) { return eofToken.getInputStream(); } else { return token.get(0).getInputStream(); } }
@Override public String getSourceName() { if(token.isEmpty()) { return eofToken.getInputStream().getSourceName(); } else { return token.get(0).getInputStream().getSourceName(); } }
/** * Returns matched part of the getText for the context. * * @param ctx the parser rule context; may not be null * @return matched part of the getText */ public static String getText(ParserRuleContext ctx) { Interval interval = new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()); return ctx.start.getInputStream().getText(interval); }
public static String getOriginalText(ParserRuleContext ctx) { int a = ctx.start.getStartIndex(); int b = ctx.stop.getStopIndex(); Interval interval = new Interval( a, b ); return ctx.getStart().getInputStream().getText( interval ); }
public static String getSourceText(ParserRuleContext ctx){ if (ctx.start == null || ctx.stop == null) { return ctx.getText(); } int startIndex = ctx.start.getStartIndex(); int stopIndex = ctx.stop.getStopIndex(); if (stopIndex < startIndex) { return ""; // Just return the empty string. } CharStream inputStream = ctx.start.getInputStream(); return inputStream.getText(new Interval(startIndex, stopIndex)); }
private String getOriginalText( ParserRuleContext ctx ) { int a = ctx.start.getStartIndex(); int b = ctx.stop.getStopIndex(); Interval interval = new Interval(a,b); return ctx.getStart().getInputStream().getText(interval); }
private String getText(ParserRuleContext ctx) { int start = ctx.start.getStartIndex(); int stop = (ctx.stop == null) ? start : ctx.stop.getStopIndex(); return ctx.getStart().getInputStream().getText(new Interval(start, stop)); } }