throw new IllegalStateException("can't find closing bracket in expression: " + s); Statement inner = new Statement();
case FOR: case WHILE: closure.add(s.prepare(model, functions, imports)); break;
case FOR: case WHILE: closure.add(s.prepare(model, functions, imports)); break;
throw new IllegalStateException("can't find closing bracket in expression: " + s); Statement inner = new Statement();
static List<Statement> getStatements(String s) { List<Statement> statements = new ArrayList<Statement>(); Matcher m = IF_FOR_WHILE.matcher(s); int start = 0; int to = s.length(); while (m.find(start)) { if (m.start() != start) { statements.add(new Statement(s.substring(start, m.start()))); } Statement statement = new Statement(); start = getBlock(s, m.start(), to, statement); statements.add(statement.bodyStatement); } if (start != to) { String sub = s.substring(start, to).trim(); if (sub.length() > 0) statements.add(new Statement(sub)); } return statements; }
public Expression prepare(Map<String, Object> model, Map<String, UserFunction> functions, List<String> imports) { switch (type) { case IF: { List<String> args = getBlocks(statement, true); if (args.size() > 1) throw new IllegalStateException("more then one statement in condition: " + statement); AsBooleanExpression condition = new AsBooleanExpression(EvalTools.prepare(args.get(0), model, functions, imports)); Expression then = bodyStatement != null ? bodyStatement.prepare(model, functions, imports) : EvalTools.prepare(body, model, functions, imports); Expression elseExpression = optionalStatement != null ? optionalStatement.prepare(model, functions, imports) : EvalTools.prepare(optional, model, functions, imports); if (elseExpression == null) return new IfExpression(condition, then); else return new IfExpression(condition, then, elseExpression); } default: throw new IllegalStateException("not implemented yet"); } }
static List<Statement> getStatements(String s) { List<Statement> statements = new ArrayList<Statement>(); Matcher m = IF_FOR_WHILE.matcher(s); int start = 0; int to = s.length(); while (m.find(start)) { if (m.start() != start) { statements.add(new Statement(s.substring(start, m.start()))); } Statement statement = new Statement(); start = getBlock(s, m.start(), to, statement); statements.add(statement.bodyStatement); } if (start != to) { String sub = s.substring(start, to).trim(); if (sub.length() > 0) statements.add(new Statement(sub)); } return statements; }
public Expression prepare(Map<String, Object> model, Map<String, UserFunction> functions, List<String> imports) { switch (type) { case IF: { List<String> args = getBlocks(statement, true); if (args.size() > 1) throw new IllegalStateException("more then one statement in condition: " + statement); AsBooleanExpression condition = new AsBooleanExpression(EvalTools.prepare(args.get(0), model, functions, imports)); Expression then = bodyStatement != null ? bodyStatement.prepare(model, functions, imports) : EvalTools.prepare(body, model, functions, imports); Expression elseExpression = optionalStatement != null ? optionalStatement.prepare(model, functions, imports) : EvalTools.prepare(optional, model, functions, imports); if (elseExpression == null) return new IfExpression(condition, then); else return new IfExpression(condition, then, elseExpression); } default: throw new IllegalStateException("not implemented yet"); } }