use of org.activityinfo.model.formula.diagnostic.FormulaSyntaxException in project activityinfo by bedatadriven.
the class DateComponentFunction method apply.
@Override
public final FieldValue apply(List<FieldValue> arguments) {
checkArity(arguments, 1);
FieldValue argument = arguments.get(0);
if (!(argument instanceof LocalDate)) {
throw new FormulaSyntaxException("Expected date argument");
}
LocalDate date = (LocalDate) argument;
return new Quantity(apply(date));
}
use of org.activityinfo.model.formula.diagnostic.FormulaSyntaxException in project activityinfo by bedatadriven.
the class ComparisonOperator method columnApply.
@Override
public ColumnView columnApply(int numRows, List<ColumnView> arguments) {
checkArity(arguments, 2);
ColumnView a = arguments.get(0);
ColumnView b = arguments.get(1);
if (a.numRows() != b.numRows()) {
throw new FormulaSyntaxException("Arguments must have the same number of rows");
}
if (a.getType() == ColumnType.NUMBER && b.getType() == ColumnType.NUMBER) {
return columnApplyNumber(a, b);
} else if (a.getType() == ColumnType.STRING && b.getType() == ColumnType.STRING) {
if (a instanceof EnumColumnView) {
return columnApplyEnum((EnumColumnView) a, b);
} else if (b instanceof EnumColumnView) {
return columnApplyEnum((EnumColumnView) b, a);
} else {
return columnApplyString(a, b);
}
} else {
throw new FormulaSyntaxException("Comparsion between incompatible types: " + a.getType() + ", " + b.getType());
}
}
use of org.activityinfo.model.formula.diagnostic.FormulaSyntaxException 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();
}
use of org.activityinfo.model.formula.diagnostic.FormulaSyntaxException 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();
}
Aggregations