private static LikeClause.PropertiesOption getPropertiesOption(Token token) { switch (token.getType()) { case SqlBaseLexer.INCLUDING: return LikeClause.PropertiesOption.INCLUDING; case SqlBaseLexer.EXCLUDING: return LikeClause.PropertiesOption.EXCLUDING; } throw new IllegalArgumentException("Unsupported LIKE option type: " + token.getText()); }
private static Expression requireNonNull(Expression expression, Token token) { if (expression != null) { return expression; } else { final int line = token.getLine(); final int positionInLine = token.getCharPositionInLine(); final String msg = "Invalid expression (line: " + line + ", column: " + positionInLine + ")"; final SyntaxError syntaxError = new SyntaxError(token.getText(), line, positionInLine, msg, null); throw new ParseException(Collections.singleton(syntaxError)); } }
public static NodeLocation getLocation(Token token) { requireNonNull(token, "token is null"); return new NodeLocation(token.getLine(), token.getCharPositionInLine()); }
private static ParsingException parseError(String message, ParserRuleContext context) { return new ParsingException(message, null, context.getStart().getLine(), context.getStart().getCharPositionInLine()); } }
public final Block_endContext block_end() throws RecognitionException { Block_endContext _localctx = new Block_endContext(_ctx, getState()); enterRule(_localctx, 8, RULE_block_end); try { enterOuterAlt(_localctx, 1); { setState(489); if (!(!_input.LT(2).getText().equalsIgnoreCase("TRANSACTION"))) throw new FailedPredicateException(this, "!_input.LT(2).getText().equalsIgnoreCase(\"TRANSACTION\")"); setState(490); match(T_END); } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.reportError(this, re); _errHandler.recover(this, re); } finally { exitRule(); } return _localctx; }
((RelExprContext)_localctx).e = ((RelExprContext)_localctx).left.e; setState(348); _errHandler.sync(this); _la = _input.LA(1); if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << GTEquals) | (1L << LTEquals) | (1L << GT) | (1L << LT))) != 0)) { ((RelExprContext)_localctx).cmpr = _input.LT(1); _la = _input.LA(1); if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << GTEquals) | (1L << LTEquals) | (1L << GT) | (1L << LT))) != 0)) ) { ((RelExprContext)_localctx).cmpr = (Token)_errHandler.recoverInline(this); if ( _input.LA(1)==Token.EOF ) matchedEOF = true; _errHandler.reportMatch(this); consume(); ((RelExprContext)_localctx).e = FunctionCallFactory.createExpression((((RelExprContext)_localctx).cmpr!=null?((RelExprContext)_localctx).cmpr.getText():null), pos((((RelExprContext)_localctx).left!=null?(((RelExprContext)_localctx).left.start):null)), ((RelExprContext)_localctx).left.e, ((RelExprContext)_localctx).right.e);
match(OParen); setState(95); _errHandler.sync(this); _la = _input.LA(1); if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << If) | (1L << Case) | (1L << Cast) | (1L << Convert) | (1L << AnyValue) | (1L << Excl) | (1L << Plus) | (1L << Minus) | (1L << OParen) | (1L << SingleQuote) | (1L << Bool))) != 0) || ((((_la - 64)) & ~0x3f) == 0 && ((1L << (_la - 64)) & ((1L << (Number - 64)) | (1L << (Identifier - 64)) | (1L << (QuotedIdentifier - 64)) | (1L << (String - 64)))) != 0)) { match(CParen); ((AnyValueCallContext)_localctx).e = FunctionCallFactory.createExpression((((AnyValueCallContext)_localctx).AnyValue!=null?((AnyValueCallContext)_localctx).AnyValue.getText():null), pos(((AnyValueCallContext)_localctx).AnyValue), (((AnyValueCallContext)_localctx).exprList == null ? new ArrayList<>() : ((AnyValueCallContext)_localctx).exprList.listE)); _errHandler.reportError(this, re); _errHandler.recover(this, re);
private ExpressionSegment extractFunctionExpressionSegment(final ParserRuleContext functionNode) { return new FunctionExpressionSegment(functionNode.getChild(0).getText(), functionNode.getStart().getStartIndex(), ((TerminalNode) functionNode.getChild(1)).getSymbol().getStartIndex(), functionNode.getStop().getStopIndex(), -1); }
@Override public void exitUnaryOpExpr(ExprParser.UnaryOpExprContext ctx) { int opCode = ((TerminalNode) ctx.getChild(0)).getSymbol().getType(); switch (opCode) { case ExprParser.MINUS: nodes.put(ctx, new UnaryMinusExpr((Expr) nodes.get(ctx.getChild(1)))); break; case ExprParser.NOT: nodes.put(ctx, new UnaryNotExpr((Expr) nodes.get(ctx.getChild(1)))); break; default: throw new RuntimeException("Unrecognized unary operator " + ctx.getChild(0).getText()); } }
public final ParseContext parse() throws RecognitionException { ParseContext _localctx = new ParseContext(_ctx, getState()); enterRule(_localctx, 0, RULE_parse); try { enterOuterAlt(_localctx, 1); { setState(72); ((ParseContext)_localctx).expression = expression(); setState(73); match(EOF); ((ParseContext)_localctx).e = ((ParseContext)_localctx).expression.e; if (fullExpression == null) fullExpression = (((ParseContext)_localctx).expression!=null?_input.getText(((ParseContext)_localctx).expression.start,((ParseContext)_localctx).expression.stop):null); tokenPos = (((ParseContext)_localctx).expression!=null?(((ParseContext)_localctx).expression.start):null).getTokenIndex(); } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.reportError(this, re); _errHandler.recover(this, re); } finally { exitRule(); } return _localctx; }
private boolean constructorDeclaration_sempred(ConstructorDeclarationContext _localctx, int predIndex) { switch (predIndex) { case 0: return _input.LT(_input.LT(1).getType() == VISIBILITY_MODIFIER ? 2 : 1).getText().equals(currentClassName) ; } return true; } private boolean expression_sempred(ExpressionContext _localctx, int predIndex) {
public static boolean isClassName(TokenStream _input) { try { int i=1; Token token = _input.LT(i); while (token!=null && i < _input.size() && _input.LT(i+1).getType() == GroovyParser.DOT) { i = i + 2; token = _input.LT(i); } if(token==null) return false; // TODO here return Character.isUpperCase(Character.codePointAt(token.getText(), 0)); } catch(Exception e) { e.printStackTrace(); } return false; }
@Override public Object visitFpackageswitch(SmaliParser.FpackageswitchContext ctx) { int start = parseInt(ctx.start.getText()); List<TerminalNode> ts = ctx.LABEL(); DexLabel labels[] = new DexLabel[ts.size()]; for (int i = 0; i < ts.size(); i++) { labels[i] = getLabel(ts.get(i).getSymbol().getText()); } scv.dPackedSwitch(start, labels); return null; }
/** * Get matched token by token type. * * @param tokenType token type * @return matched token * @throws RecognitionException mismatch throw exception */ public Token getMatchedToken(final int tokenType) throws RecognitionException { Token result = parser.getCurrentToken(); boolean isIdentifierCompatible = false; if (identifierTokenIndex == tokenType && identifierTokenIndex > result.getType()) { isIdentifierCompatible = true; } if (result.getType() == tokenType || isIdentifierCompatible) { if (Token.EOF != tokenType && isIdentifierCompatible && result instanceof CommonToken) { ((CommonToken) result).setType(identifierTokenIndex); } parser.getErrorHandler().reportMatch(parser); parser.consume(); } else { result = parser.getErrorHandler().recoverInline(parser); if (parser.getBuildParseTree() && -1 == result.getTokenIndex()) { parser.getContext().addErrorNode(parser.createErrorNode(parser.getContext(), result)); } } return result; } }
CommonTokenStream tokens = new CommonTokenStream(lexer); List<Token> allTokens = tokens.getTokens(); if (stop != null && allTokens != null && !allTokens.isEmpty()) { Token last = allTokens.get(allTokens.size() - 1); boolean notEOF = last.getType() != Token.EOF; boolean lastGreaterThanDocument = last.getTokenIndex() > stop.getTokenIndex(); boolean sameChannel = last.getChannel() == stop.getChannel(); if (notEOF && lastGreaterThanDocument && sameChannel) { throw bailStrategy.mkMoreTokensException(last);
@Override public void exitUnquotedIdentifier(SqlBaseParser.UnquotedIdentifierContext context) { String identifier = context.IDENTIFIER().getText(); for (IdentifierSymbol identifierSymbol : EnumSet.complementOf(allowedIdentifierSymbols)) { char symbol = identifierSymbol.getSymbol(); if (identifier.indexOf(symbol) >= 0) { throw new ParsingException("identifiers must not contain '" + identifierSymbol.getSymbol() + "'", null, context.IDENTIFIER().getSymbol().getLine(), context.IDENTIFIER().getSymbol().getCharPositionInLine()); } } }
private SelectItemSegment extractFunctionSelectItemSegment(final ParserRuleContext expressionNode, final ParserRuleContext functionNode) { String functionName = functionNode.getChild(0).getText(); Optional<AggregationType> aggregationType = findAggregationType(functionName); AliasAvailable result = aggregationType.isPresent() ? extractAggregationSelectItemSegment(aggregationType.get(), functionNode) : new ExpressionSelectItemSegment(functionNode.getText(), functionNode.getStart().getStartIndex(), functionNode.getStop().getStopIndex()); Optional<ParserRuleContext> aliasNode = ExtractorUtils.findFirstChildNode(expressionNode, RuleName.ALIAS); if (aliasNode.isPresent()) { result.setAlias(aliasNode.get().getText()); } return (SelectItemSegment) result; }
ParseTree mismatchedNode = null; if ( t1.getSymbol().getType() == t2.getSymbol().getType() ) { if ( t2.getSymbol() instanceof TokenTagToken ) { // x and <ID> TokenTagToken tokenTagToken = (TokenTagToken)t2.getSymbol(); if ( ruleTagToken!=null ) { ParseTreeMatch m = null; if ( r1.getRuleContext().getRuleIndex() == r2.getRuleContext().getRuleIndex() ) { if ( r1.getChildCount()!=r2.getChildCount() ) { if (mismatchedNode == null) { mismatchedNode = r1; int n = r1.getChildCount(); for (int i = 0; i<n; i++) { ParseTree childMatch = matchImpl(r1.getChild(i), patternTree.getChild(i), labels); if ( childMatch != null ) { return childMatch;
lexer.removeErrorListeners(); lexer.addErrorListener(new XPathLexerErrorListener()); CommonTokenStream tokenStream = new CommonTokenStream(lexer); try { tokenStream.fill(); List<Token> tokens = tokenStream.getTokens(); Token el = tokens.get(i); Token next = null; switch ( el.getType() ) { case XPathLexer.ROOT : case XPathLexer.ANYWHERE : boolean anywhere = el.getType() == XPathLexer.ANYWHERE; i++; next = tokens.get(i); boolean invert = next.getType()==XPathLexer.BANG; if ( invert ) { i++;