Rule binary(Rule first, Rule rest, Operator... operators) { return Sequence( first, push(new OperationBinary(simplify(pop()))), ZeroOrMore( firstOperatorOf(operators), ((OperationBinary) peek(1)).addOperator(((Constant<Operator>) pop()).getValue()), mandatory( Sequence( rest, ((OperationBinary) peek(1)).add(simplify(pop())) ), new ParseException("Wrong binary operation syntax") ) ) ); }
Rule binary(Rule first, Rule rest, Operator... operators) { return Sequence( first, push(new OperationBinary(simplify(pop()))), ZeroOrMore( firstOperatorOf(operators), ((OperationBinary) peek(1)).addOperator(((Constant<Operator>) pop()).getValue()), mandatory( Sequence( rest, ((OperationBinary) peek(1)).add(simplify(pop())) ), new ParseException("Wrong binary operation syntax") ) ) ); }
Rule enumeratedList() { return Sequence( symbol(OPEN_BRACKET), push(new ValueList()), mandatory( Sequence( Optional( expression(), ((ValueList) peek(1)).add(pop()), ZeroOrMore( symbol(COMMA), expression(), ((ValueList) peek(1)).add(pop()) ) ), symbol(CLOSE_BRACKET) ), new ParseException("Wrong list syntax") ) ); }
Rule enumeratedList() { return Sequence( symbol(OPEN_BRACKET), push(new ValueList()), mandatory( Sequence( Optional( expression(), ((ValueList) peek(1)).add(pop()), ZeroOrMore( symbol(COMMA), expression(), ((ValueList) peek(1)).add(pop()) ) ), symbol(CLOSE_BRACKET) ), new ParseException("Wrong list syntax") ) ); }
Rule functionWithBrackets() { return Sequence( variable(), symbol(OPEN_PARENT), push(new FunctionElement(popVariableName())), mandatory( Sequence( expression(), ((FunctionElement) peek(1)).add(pop()), ZeroOrMore( symbol(COMMA), expression(), ((FunctionElement) peek(1)).add(pop()) ), symbol(CLOSE_PARENT) ), new ParseException("Wrong function syntax") ) ); }
Rule functionWithBrackets() { return Sequence( variable(), symbol(OPEN_PARENT), push(new FunctionElement(popVariableName())), mandatory( Sequence( expression(), ((FunctionElement) peek(1)).add(pop()), ZeroOrMore( symbol(COMMA), expression(), ((FunctionElement) peek(1)).add(pop()) ), symbol(CLOSE_PARENT) ), new ParseException("Wrong function syntax") ) ); }
Rule isOperation() { return Sequence( primary(), push(new OperationBinary(simplify(pop()))), ZeroOrMore( operator(IS), popValue(), mandatory( Sequence( FirstOf( Sequence( operator(NOT), popValue(), ((OperationBinary) peek()).addOperator(Operator.IS_NOT) ), ((OperationBinary) peek()).addOperator(Operator.IS) ), FirstOf( functionWithBrackets(), functionWithTwoWordsAsName(), variable(), keywordAsVariable(NULL) ), ((OperationBinary) peek(1)).add(simplify(pop())) ), new ParseException("Wrong binary operation syntax") ) ) ); }
Rule isOperation() { return Sequence( primary(), push(new OperationBinary(simplify(pop()))), ZeroOrMore( operator(IS), popValue(), mandatory( Sequence( FirstOf( Sequence( operator(NOT), popValue(), ((OperationBinary) peek()).addOperator(Operator.IS_NOT) ), ((OperationBinary) peek()).addOperator(Operator.IS) ), FirstOf( functionWithBrackets(), functionWithTwoWordsAsName(), variable(), keywordAsVariable(NULL) ), ((OperationBinary) peek(1)).add(simplify(pop())) ), new ParseException("Wrong binary operation syntax") ) ) ); }