Search in sources :

Example 6 with FormulaFunction

use of org.activityinfo.model.formula.functions.FormulaFunction in project activityinfo by bedatadriven.

the class FormulaParser method disjunction.

private FormulaNode disjunction() {
    FormulaNode left = conjunction();
    while (lexer.hasNext() && lexer.peek().isOrOperator()) {
        FormulaFunction op = function();
        FormulaNode right = conjunction();
        left = binaryInfixCall(op, left, right);
    }
    return left;
}
Also used : FormulaFunction(org.activityinfo.model.formula.functions.FormulaFunction)

Example 7 with FormulaFunction

use of org.activityinfo.model.formula.functions.FormulaFunction in project activityinfo by bedatadriven.

the class FormulaParser method factor.

public FormulaNode factor() {
    // <factor> ::= <unary> | <factor> * <unary> | <factor> / <unary>
    FormulaNode left = unary();
    while (lexer.hasNext() && lexer.peek().isMultiplicativeOperator()) {
        FormulaFunction function = function();
        FormulaNode right = unary();
        left = binaryInfixCall(function, left, right);
    }
    return left;
}
Also used : FormulaFunction(org.activityinfo.model.formula.functions.FormulaFunction)

Example 8 with FormulaFunction

use of org.activityinfo.model.formula.functions.FormulaFunction in project activityinfo by bedatadriven.

the class FormulaParser method unary.

private FormulaNode unary() {
    if (!lexer.hasNext()) {
        throw new FormulaSyntaxException("Unexpected end of formula");
    }
    Token token = lexer.peek();
    if (token.getType() == TokenType.OPERATOR) {
        if (token.getString().equals("-") || token.getString().equals("+")) {
            Token opToken = lexer.next();
            FormulaFunction op = function(opToken);
            FormulaNode operand = unary();
            SourceRange sourceRange = new SourceRange(opToken.getStart(), operand.getSourceRange().getEnd());
            return new FunctionCallNode(op, singletonList(operand), sourceRange);
        }
    }
    return unary2();
}
Also used : FormulaFunction(org.activityinfo.model.formula.functions.FormulaFunction) FormulaSyntaxException(org.activityinfo.model.formula.diagnostic.FormulaSyntaxException)

Example 9 with FormulaFunction

use of org.activityinfo.model.formula.functions.FormulaFunction in project activityinfo by bedatadriven.

the class FormulaParser method unary2.

private FormulaNode unary2() {
    if (!lexer.hasNext()) {
        throw new FormulaSyntaxException("Unexpected end of formula");
    }
    Token token = lexer.peek();
    if (token.getType() == TokenType.OPERATOR) {
        if (token.getString().equals("!")) {
            Token opToken = lexer.next();
            FormulaFunction op = function(opToken);
            FormulaNode operand = primary();
            SourceRange sourceRange = new SourceRange(opToken.getStart(), operand.getSourceRange().getEnd());
            return new FunctionCallNode(op, singletonList(operand), sourceRange);
        }
    }
    return primary();
}
Also used : FormulaFunction(org.activityinfo.model.formula.functions.FormulaFunction) FormulaSyntaxException(org.activityinfo.model.formula.diagnostic.FormulaSyntaxException)

Example 10 with FormulaFunction

use of org.activityinfo.model.formula.functions.FormulaFunction in project activityinfo by bedatadriven.

the class FormulaParser method equality.

private FormulaNode equality() {
    FormulaNode left = relational();
    while (lexer.hasNext() && lexer.peek().isEqualityOperator()) {
        FormulaFunction op = function();
        FormulaNode right = relational();
        left = binaryInfixCall(op, left, right);
    }
    return left;
}
Also used : FormulaFunction(org.activityinfo.model.formula.functions.FormulaFunction)

Aggregations

FormulaFunction (org.activityinfo.model.formula.functions.FormulaFunction)10 FormulaSyntaxException (org.activityinfo.model.formula.diagnostic.FormulaSyntaxException)3 ArrayList (java.util.ArrayList)2 List (java.util.List)1 FieldValue (org.activityinfo.model.type.FieldValue)1 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)1 BooleanFieldValue (org.activityinfo.model.type.primitive.BooleanFieldValue)1