@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())); } }
public Lexer(CharStream input) { this._input = input; this._tokenFactorySourcePair = new Pair<TokenSource, CharStream>(this, input); }
/** Set the char stream and reset the lexer */ @Override public void setInputStream(IntStream input) { this._input = null; this._tokenFactorySourcePair = new Pair<TokenSource, CharStream>(this, _input); reset(); this._input = (CharStream)input; this._tokenFactorySourcePair = new Pair<TokenSource, CharStream>(this, _input); }
@Override public void enterRecursionRule(ParserRuleContext localctx, int state, int ruleIndex, int precedence) { Pair<ParserRuleContext, Integer> pair = new Pair<ParserRuleContext, Integer>(_ctx, localctx.invokingState); _parentContextStack.push(pair); super.enterRecursionRule(localctx, state, ruleIndex, precedence); }
public List<Pair<K,V>> getPairs() { List<Pair<K,V>> pairs = new ArrayList<Pair<K,V>>(); for (K key : keySet()) { for (V value : get(key)) { pairs.add(new Pair<K,V>(key, value)); } } return pairs; } }
/** * {@inheritDoc} */ @Override public Token nextToken() { if (i >= tokens.size()) { if (eofToken == null) { int start = -1; if (tokens.size() > 0) { int previousStop = tokens.get(tokens.size() - 1).getStopIndex(); if (previousStop != -1) { start = previousStop + 1; } } int stop = Math.max(-1, start - 1); eofToken = _factory.create(new Pair<TokenSource, CharStream>(this, getInputStream()), Token.EOF, "EOF", Token.DEFAULT_CHANNEL, start, stop, getLine(), getCharPositionInLine()); } return eofToken; } Token t = tokens.get(i); if (i == tokens.size() - 1 && t.getType() == Token.EOF) { eofToken = t; } i++; return t; }
return new Pair<ATNConfigSet, ATNConfigSet>(succeeded,failed);
/** * 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()); } }
public Lexer(CharStream input) { this._input = input; this._tokenFactorySourcePair = new Pair<TokenSource, CharStream>(this, input); }
public Lexer(CharStream input) { this._input = input; this._tokenFactorySourcePair = new Pair<TokenSource, CharStream>(this, input); }
public Lexer(CharStream input) { this._input = input; this._tokenFactorySourcePair = new Pair<TokenSource, CharStream>(this, input); }
getTokenFactory().create(new Pair<TokenSource, CharStream>(tok.getTokenSource(), tok.getTokenSource().getInputStream()), expectedTokenType, tok.getText(), Token.DEFAULT_CHANNEL, Token tok = e.getOffendingToken(); Token errToken = getTokenFactory().create(new Pair<TokenSource, CharStream>(tok.getTokenSource(), tok.getTokenSource().getInputStream()), Token.INVALID_TYPE, tok.getText(), Token.DEFAULT_CHANNEL,
/** Set the char stream and reset the lexer */ @Override public void setInputStream(IntStream input) { this._input = null; this._tokenFactorySourcePair = new Pair<TokenSource, CharStream>(this, _input); reset(); this._input = (CharStream)input; this._tokenFactorySourcePair = new Pair<TokenSource, CharStream>(this, _input); }
/** Set the char stream and reset the lexer */ @Override public void setInputStream(IntStream input) { this._input = null; this._tokenFactorySourcePair = new Pair<TokenSource, CharStream>(this, _input); reset(); this._input = (CharStream)input; this._tokenFactorySourcePair = new Pair<TokenSource, CharStream>(this, _input); }
/** Set the char stream and reset the lexer */ @Override public void setInputStream(IntStream input) { this._input = null; this._tokenFactorySourcePair = new Pair<TokenSource, CharStream>(this, _input); reset(); this._input = (CharStream)input; this._tokenFactorySourcePair = new Pair<TokenSource, CharStream>(this, _input); }
@Override public void enterRecursionRule(ParserRuleContext localctx, int state, int ruleIndex, int precedence) { _parentContextStack.push(new Pair<ParserRuleContext, Integer>(_ctx, localctx.invokingState)); super.enterRecursionRule(localctx, state, ruleIndex, precedence); }
/** * Creates CSSToken of given type with cloning lexer state * automatically, allows to set text boundaries in input stream * @param type Type of token * @param state State of lexer, which will be copied * @param start Start position in stream * @param stop End position in stream */ public CSSToken(int type, CSSLexerState state, int start, int stop, TypeMapper typeMapper) { this(new Pair<TokenSource, CharStream>(null,null), type, Token.DEFAULT_CHANNEL, start, stop, typeMapper); this.ls = new CSSLexerState(state); }
@Override public void enterRecursionRule(ParserRuleContext localctx, int state, int ruleIndex, int precedence) { Pair<ParserRuleContext, Integer> pair = new Pair<ParserRuleContext, Integer>(_ctx, localctx.invokingState); _parentContextStack.push(pair); super.enterRecursionRule(localctx, state, ruleIndex, precedence); }
@Override public void enterRecursionRule(ParserRuleContext localctx, int state, int ruleIndex, int precedence) { Pair<ParserRuleContext, Integer> pair = new Pair<ParserRuleContext, Integer>(_ctx, localctx.invokingState); _parentContextStack.push(pair); super.enterRecursionRule(localctx, state, ruleIndex, precedence); }