Search in sources :

Example 1 with EqualsOp

use of uk.me.parabola.mkgmap.osmstyle.eval.EqualsOp in project mkgmap by openstreetmap.

the class RuleFileReader method readIf.

private boolean readIf(TokenScanner scanner, ExpressionReader expressionReader) {
    // Take the 'if' token
    Token tok = scanner.nextToken();
    scanner.skipSpace();
    // If 'if'' is being used as a keyword then it is followed by a '('.
    Token next = scanner.peekToken();
    if (next.getType() == TokType.SYMBOL && next.isValue("(")) {
        Op origExpr = expressionReader.readConditions();
        scanner.validateNext("then");
        // add rule expr { set <ifVar> = true }
        String ifVar = getNextIfVar();
        ArrayList<Action> actions = new ArrayList<>(1);
        actions.add(new AddTagAction(ifVar, "true", true));
        ActionList actionList = new ActionList(actions, Collections.singleton(ifVar + "=true"));
        saveRule(scanner, origExpr, actionList, null);
        // create expression (<ifVar> = true)
        EqualsOp safeExpr = new EqualsOp();
        safeExpr.setFirst(new GetTagFunction(ifVar));
        safeExpr.setSecond(new ValueOp("true"));
        Op[] ifExpressions = { origExpr, safeExpr };
        ifStack.addLast(ifExpressions);
        return true;
    } else {
        // Wrong syntax for if statement, so push back token to allow a possible expression to be read
        scanner.pushToken(tok);
    }
    return false;
}
Also used : Op(uk.me.parabola.mkgmap.osmstyle.eval.Op) ValueOp(uk.me.parabola.mkgmap.osmstyle.eval.ValueOp) EqualsOp(uk.me.parabola.mkgmap.osmstyle.eval.EqualsOp) NotOp(uk.me.parabola.mkgmap.osmstyle.eval.NotOp) EqualsOp(uk.me.parabola.mkgmap.osmstyle.eval.EqualsOp) DeleteAction(uk.me.parabola.mkgmap.osmstyle.actions.DeleteAction) AddTagAction(uk.me.parabola.mkgmap.osmstyle.actions.AddTagAction) Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) AddTagAction(uk.me.parabola.mkgmap.osmstyle.actions.AddTagAction) ValueOp(uk.me.parabola.mkgmap.osmstyle.eval.ValueOp) ArrayList(java.util.ArrayList) GetTagFunction(uk.me.parabola.mkgmap.osmstyle.function.GetTagFunction) Token(uk.me.parabola.mkgmap.scan.Token) ActionList(uk.me.parabola.mkgmap.osmstyle.actions.ActionList)

Aggregations

ArrayList (java.util.ArrayList)1 Action (uk.me.parabola.mkgmap.osmstyle.actions.Action)1 ActionList (uk.me.parabola.mkgmap.osmstyle.actions.ActionList)1 AddTagAction (uk.me.parabola.mkgmap.osmstyle.actions.AddTagAction)1 DeleteAction (uk.me.parabola.mkgmap.osmstyle.actions.DeleteAction)1 EqualsOp (uk.me.parabola.mkgmap.osmstyle.eval.EqualsOp)1 NotOp (uk.me.parabola.mkgmap.osmstyle.eval.NotOp)1 Op (uk.me.parabola.mkgmap.osmstyle.eval.Op)1 ValueOp (uk.me.parabola.mkgmap.osmstyle.eval.ValueOp)1 GetTagFunction (uk.me.parabola.mkgmap.osmstyle.function.GetTagFunction)1 Token (uk.me.parabola.mkgmap.scan.Token)1