Search in sources :

Example 1 with ActionList

use of uk.me.parabola.mkgmap.osmstyle.actions.ActionList in project mkgmap by openstreetmap.

the class RuleFileReader method loadFile.

/**
 * Load a rules file.  This should be used when calling recursively when including
 * files.
 */
private void loadFile(StyleFileLoader loader, String name) throws FileNotFoundException {
    Reader r = loader.open(name);
    TokenScanner scanner = new TokenScanner(name, r);
    scanner.setExtraWordChars("-:.");
    ExpressionReader expressionReader = new ExpressionReader(scanner, kind);
    ActionReader actionReader = new ActionReader(scanner);
    // Read all the rules in the file.
    scanner.skipSpace();
    while (!scanner.isEndOfFile()) {
        if (checkCommand(loader, scanner, expressionReader))
            continue;
        if (scanner.isEndOfFile())
            break;
        Op expr = expressionReader.readConditions(ifStack);
        expr = arranger.arrange(expr);
        ActionList actionList = actionReader.readActions();
        checkIfStack(actionList);
        if (performChecks && this.kind == FeatureKind.RELATION) {
            String actionsString = actionList.getList().toString();
            if (actionsString.contains("set mkgmap:stylefilter") || actionsString.contains("add mkgmap:stylefilter")) {
                log.error("Style file", name, "should not set or add the special tag mkgmap:stylefilter:", actionsString);
            }
        }
        List<GType> types = new ArrayList<>();
        while (scanner.checkToken("[")) {
            GType type = typeReader.readType(scanner, performChecks, overlays);
            types.add(type);
            scanner.skipSpace();
        }
        // If there is an action list, then we don't need a type
        if (types.isEmpty() && actionList.isEmpty())
            throw new SyntaxException(scanner, "No type definition given");
        if (types.isEmpty())
            saveRule(scanner, expr, actionList, null);
        if (types.size() >= 2 && actionList.isModifyingTags()) {
            throw new SyntaxException(scanner, "Combination of multiple type definitions with tag modifying action is not yet supported.");
        }
        for (int i = 0; i < types.size(); i++) {
            GType type = types.get(i);
            if (i + 1 < types.size()) {
                type.setContinueSearch(true);
            }
            // No need to create a deep copy of expr
            saveRule(scanner, expr, actionList, type);
            actionList = new ActionList(Collections.emptyList(), Collections.emptySet());
        }
    }
    rules.addUsedTags(expressionReader.getUsedTags());
    rules.addUsedTags(actionReader.getUsedTags());
}
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) GType(uk.me.parabola.mkgmap.reader.osm.GType) TokenScanner(uk.me.parabola.mkgmap.scan.TokenScanner) ActionReader(uk.me.parabola.mkgmap.osmstyle.actions.ActionReader) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) ArrayList(java.util.ArrayList) ActionReader(uk.me.parabola.mkgmap.osmstyle.actions.ActionReader) Reader(java.io.Reader) ExpressionReader(uk.me.parabola.mkgmap.osmstyle.eval.ExpressionReader) ActionList(uk.me.parabola.mkgmap.osmstyle.actions.ActionList) ExpressionReader(uk.me.parabola.mkgmap.osmstyle.eval.ExpressionReader)

Example 2 with ActionList

use of uk.me.parabola.mkgmap.osmstyle.actions.ActionList 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)2 ActionList (uk.me.parabola.mkgmap.osmstyle.actions.ActionList)2 EqualsOp (uk.me.parabola.mkgmap.osmstyle.eval.EqualsOp)2 NotOp (uk.me.parabola.mkgmap.osmstyle.eval.NotOp)2 Op (uk.me.parabola.mkgmap.osmstyle.eval.Op)2 ValueOp (uk.me.parabola.mkgmap.osmstyle.eval.ValueOp)2 Reader (java.io.Reader)1 Action (uk.me.parabola.mkgmap.osmstyle.actions.Action)1 ActionReader (uk.me.parabola.mkgmap.osmstyle.actions.ActionReader)1 AddTagAction (uk.me.parabola.mkgmap.osmstyle.actions.AddTagAction)1 DeleteAction (uk.me.parabola.mkgmap.osmstyle.actions.DeleteAction)1 ExpressionReader (uk.me.parabola.mkgmap.osmstyle.eval.ExpressionReader)1 GetTagFunction (uk.me.parabola.mkgmap.osmstyle.function.GetTagFunction)1 GType (uk.me.parabola.mkgmap.reader.osm.GType)1 SyntaxException (uk.me.parabola.mkgmap.scan.SyntaxException)1 Token (uk.me.parabola.mkgmap.scan.Token)1 TokenScanner (uk.me.parabola.mkgmap.scan.TokenScanner)1