Beispiel #1
0
 @Override
 public Expression parse(Parser parser, ParserToken token) throws ParseException {
   if (parser.hasNext()
       && !parser.tokenStream().lookAheadType(0).equals(Operator.AND)
       && !parser.tokenStream().lookAheadType(0).equals(Operator.OR)
       && !parser.tokenStream().lookAheadType(0).equals(CommonTypes.CLOSEPARENS)) {
     return new BinaryOperatorExpression(
         new ValueExpression(token.text, token.type),
         new ParserToken(defaultOperator.toString(), defaultOperator),
         parser.next());
   }
   return new ValueExpression(token.text, token.getType());
 }
Beispiel #2
0
 public SerializablePredicate<HString> parse(String query) throws ParseException {
   Parser parser = new Parser(grammar, lexer.lex(query));
   List<SerializablePredicate<HString>> predicates = new ArrayList<>();
   while (parser.hasNext()) {
     Expression expression = parser.next();
     predicates.add(generate(expression));
   }
   if (predicates.isEmpty()) {
     return d -> true;
   }
   SerializablePredicate<HString> finalPredicate = predicates.get(0);
   for (int i = 1; i < predicates.size(); i++) {
     finalPredicate =
         defaultOperator == Operator.AND
             ? and(finalPredicate, predicates.get(i))
             : or(finalPredicate, predicates.get(i));
   }
   return finalPredicate;
 }