Rule term() { return FirstOf(condition(), Parens()); }
Rule value() { return FirstOf(select(), date(), valueText()); }
Rule EscapeSimple() { return Sequence('\\', FirstOf(AnyOf("#btnfr\'\\"+LITERAL_CLOSE_SIMPLE), OctalEscape(), UnicodeEscape())); }
Rule Escape() { return Sequence('\\', FirstOf(AnyOf("#btnfr\'\\" +LITERAL_OPEN_SIMPLE+LITERAL_CLOSE_SIMPLE+LITERAL_OPEN_DOUBLE+LITERAL_CLOSE_DOUBLE), OctalEscape(), UnicodeEscape())); }
Rule EscapeDouble() { return Sequence('\\', FirstOf(AnyOf("#btnfr\'\\"+LITERAL_CLOSE_DOUBLE), OctalEscape(), UnicodeEscape())); }
Rule field() { return OneOrMore(FirstOf(CharRange('0', '9'), CharRange('a', 'z'), CharRange('A', 'Z'), AnyOf("_.*"))); }
/** * Une chaine simple sans espace, parenthese, retour chariot, tabulation, * accolade, crochet, ", '. * @return */ Rule SimpleString() { return OneOrMore(FirstOf( Escape(), Sequence(TestNot(AnyOf(" #\t\r\n\\" +COMMA +LITERAL_OPEN_SIMPLE+LITERAL_OPEN_DOUBLE +BRACKET_OPEN+BRACKET_CLOSE +CURLY_BRACKET_OPEN+CURLY_BRACKET_CLOSE +SQUARE_BRACKET_OPEN+SQUARE_BRACKET_CLOSE)), ANY) )).suppressSubnodes(); }
Rule StringLiteralSimple() { return Sequence( LITERAL_OPEN_SIMPLE, ZeroOrMore( FirstOf( EscapeSimple(), Sequence(TestNot(AnyOf("\r\n\\"+LITERAL_CLOSE_SIMPLE)), ANY) ) ).suppressSubnodes(), LITERAL_CLOSE_SIMPLE ); }
Rule StringLiteralDouble() { return Sequence( LITERAL_OPEN_DOUBLE, ZeroOrMore( FirstOf( EscapeDouble(), Sequence(TestNot(AnyOf("\r\n\\"+LITERAL_CLOSE_DOUBLE)), ANY) ) ).suppressSubnodes(), LITERAL_CLOSE_DOUBLE ); }
Rule OctalEscape() { return FirstOf( Sequence(CharRange('0', '3'), CharRange('0', '7'), CharRange('0', '7')), Sequence(CharRange('0', '7'), CharRange('0', '7')), CharRange('0', '7') ); }
Rule functionOrFieldOrString() { return Sequence(FirstOf(function(), fieldFunction(), stringFunction()), push(addToList(pop(1), pop()))); }
Rule valueText() { return Sequence(FirstOf(StringLiteralDouble(), StringLiteralSimple(), SimpleString()), push(new ConditionValueString(removeQuote(match())))); }
Rule limit() { return Optional(space(), icLIMIT, FirstOf(EQUALS, space()), OneOrMore(AnyOf("1234567890")), push(((WikittyQuery)pop()).setLimit(toInt(match()))) ); }
Rule depth() { return Optional(space(), icDEPTH, FirstOf(EQUALS, space()), OneOrMore(AnyOf("1234567890")), push(((WikittyQuery)pop()).setWikittyFieldSearchDepth(toInt(match()))) ); }
Rule function() { Var<String> alias = new Var<String>(); return Sequence(OneOrMore(FirstOf(field(), AnyOf("#"))), push(match()), BRACKET_OPEN, push(new LinkedList()), Optional(functionOrFieldOrString(), ZeroOrMore(COMMA, functionOrFieldOrString())), BRACKET_CLOSE, Optional(alias(alias)), push(WikittyQueryFunction.create(pop(1).toString(), alias.get(), (List)pop()))); }
Rule offset() { return Optional(space(), icOFFSET, FirstOf(EQUALS, space()), OneOrMore(AnyOf("1234567890")), push(((WikittyQuery)pop()).setOffset(toInt(match()))) ); }
Rule start() { return Sequence(FirstOf(or(), empty()), push(new WikittyQuery((Condition)pop())), offset(), limit(), depth(), space(), EOI); }
Rule select() { return Sequence(icSELECT, space(), functionOrFieldList() /*, field(), push(match())*/, space(), FirstOf(Sequence(icWHERE, space(), term()), empty()), push(new Select(((WikittyQueryFunction)pop(1)), (Condition)pop()))); }
Rule and() { return Sequence(term(), ZeroOrMore( // when no AND or OR is used, AND is default // don't change order of FirstOf, this order is important FirstOf(Sequence(space(), icAND, space()), Sequence(space(), TestNot(icOR))), term(), push(new And((Condition)pop(1), (Condition)pop())))); }
Rule condition() { // ATTENTION l'ordre est important par exemple le '>' doit etre apres le '>=' return FirstOf( not(), isNull(), isNotNull(), select(), greatereq(), lesseq(), between(), containsAll(), containsOne(), eq(), neq(), eqIgnoreCaseAndAccent(), neqIgnoreCaseAndAccent(), less(), greater(), like(), notlike(), rTrue(), rFalse(), keyword() ); }