org.apache.calcite.sql.SqlPrefixOperator Java Examples
The following examples show how to use
org.apache.calcite.sql.SqlPrefixOperator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SqlParserUtil.java From Bats with Apache License 2.0 | 5 votes |
@Override public PrecedenceClimbingParser parser(int start, Predicate<PrecedenceClimbingParser.Token> predicate) { final PrecedenceClimbingParser.Builder builder = new PrecedenceClimbingParser.Builder(); for (Object o : Util.skip(list, start)) { if (o instanceof ToTreeListItem) { final ToTreeListItem item = (ToTreeListItem) o; final SqlOperator op = item.getOperator(); if (op instanceof SqlPrefixOperator) { builder.prefix(item, op.getLeftPrec()); } else if (op instanceof SqlPostfixOperator) { builder.postfix(item, op.getRightPrec()); } else if (op instanceof SqlBinaryOperator) { builder.infix(item, op.getLeftPrec(), op.getLeftPrec() < op.getRightPrec()); } else if (op instanceof SqlSpecialOperator) { builder.special(item, op.getLeftPrec(), op.getRightPrec(), (parser, op2) -> { final List<PrecedenceClimbingParser.Token> tokens = parser.all(); final SqlSpecialOperator op1 = (SqlSpecialOperator) ((ToTreeListItem) op2.o).op; SqlSpecialOperator.ReduceResult r = op1.reduceExpr(tokens.indexOf(op2), new TokenSequenceImpl(parser)); return new PrecedenceClimbingParser.Result( tokens.get(r.startOrdinal), tokens.get(r.endOrdinal - 1), parser.atom(r.node)); }); } else { throw new AssertionError(); } } else { builder.atom(o); } } return builder.build(); }
Example #2
Source File: SqlParserUtil.java From calcite with Apache License 2.0 | 5 votes |
@Override public PrecedenceClimbingParser parser(int start, Predicate<PrecedenceClimbingParser.Token> predicate) { final PrecedenceClimbingParser.Builder builder = new PrecedenceClimbingParser.Builder(); for (Object o : Util.skip(list, start)) { if (o instanceof ToTreeListItem) { final ToTreeListItem item = (ToTreeListItem) o; final SqlOperator op = item.getOperator(); if (op instanceof SqlPrefixOperator) { builder.prefix(item, op.getLeftPrec()); } else if (op instanceof SqlPostfixOperator) { builder.postfix(item, op.getRightPrec()); } else if (op instanceof SqlBinaryOperator) { builder.infix(item, op.getLeftPrec(), op.getLeftPrec() < op.getRightPrec()); } else if (op instanceof SqlSpecialOperator) { builder.special(item, op.getLeftPrec(), op.getRightPrec(), (parser, op2) -> { final List<PrecedenceClimbingParser.Token> tokens = parser.all(); final SqlSpecialOperator op1 = (SqlSpecialOperator) ((ToTreeListItem) op2.o).op; SqlSpecialOperator.ReduceResult r = op1.reduceExpr(tokens.indexOf(op2), new TokenSequenceImpl(parser)); return new PrecedenceClimbingParser.Result( tokens.get(r.startOrdinal), tokens.get(r.endOrdinal - 1), parser.atom(r.node)); }); } else { throw new AssertionError(); } } else { builder.atom(o); } } return builder.build(); }