public static Expression simplify(Expression object) { if (object instanceof OperationBinary) { if (isSingleArgumentedOperation((OperationBinary) object)) return simplify(getOperationArgument((OperationBinary) object)); } return object; }
public static Expression simplify(Expression object) { if (object instanceof OperationBinary) { if (isSingleArgumentedOperation((OperationBinary) object)) return simplify(getOperationArgument((OperationBinary) object)); } return object; }
public Rule expression() { return Sequence( specificJtwigOperators(), push(simplify(pop())) ); }
public Rule expression() { return Sequence( specificJtwigOperators(), push(simplify(pop())) ); }
Rule unary(Rule innerRule, Operator... operators) { return Sequence( firstOperatorOf(operators), push(new OperationUnary(((Constant<Operator>) pop()).getValue())), mandatory( Sequence( innerRule, ((OperationUnary) peek(1)).setOperand(simplify(pop())) ), new ParseException("Wrong unary operator syntax") ) ); }
Rule unary(Rule innerRule, Operator... operators) { return Sequence( firstOperatorOf(operators), push(new OperationUnary(((Constant<Operator>) pop()).getValue())), mandatory( Sequence( innerRule, ((OperationUnary) peek(1)).setOperand(simplify(pop())) ), new ParseException("Wrong unary operator 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 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 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") ) ) ); }