Search in sources :

Example 6 with SyntaxException

use of uk.me.parabola.mkgmap.scan.SyntaxException 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 7 with SyntaxException

use of uk.me.parabola.mkgmap.scan.SyntaxException in project mkgmap by openstreetmap.

the class RuleFileReader method saveRule.

/**
 * Save the expression as a rule.  We need to extract an index such
 * as highway=primary first and then add the rest of the expression as
 * the condition for it.
 *
 * So in other words each condition is dropped into a number of different
 * baskets based on the first 'tag=value' term.  We then only look
 * for expressions that are in the correct basket.  For each expression
 * in a basket we know that the first term is true so we can drop that
 * from the expression.
 */
private void saveRule(TokenScanner scanner, Op op, ActionList actions, GType gt) {
    log.debug("EXP", op, ", type=", gt);
    // check if the type definition is allowed
    if (inFinalizeSection && gt != null)
        throw new SyntaxException(scanner, "Element type definition is not allowed in <finalize> section");
    Iterator<Op> it = arranger.prepareForSave(op);
    while (it.hasNext()) {
        Op prepared = it.next();
        String keystring = arranger.getKeystring(scanner, prepared);
        createAndSaveRule(keystring, prepared, actions, gt);
    }
}
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) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException)

Example 8 with SyntaxException

use of uk.me.parabola.mkgmap.scan.SyntaxException in project mkgmap by openstreetmap.

the class LengthFunction method calcLength.

private double calcLength(Element el) {
    if (el instanceof Way) {
        Way w = (Way) el;
        double length = 0;
        Coord prevC = null;
        for (Coord c : w.getPoints()) {
            if (prevC != null) {
                length += prevC.distance(c);
            }
            prevC = c;
        }
        return length;
    } else if (el instanceof Relation) {
        Relation rel = (Relation) el;
        double length = 0;
        for (Entry<String, Element> relElem : rel.getElements()) {
            if (relElem.getValue() instanceof Way || relElem.getValue() instanceof Relation) {
                if (rel == relElem.getValue()) {
                    // avoid recursive call
                    log.error("Relation " + rel.getId() + " contains itself as element. This is not supported.");
                } else {
                    length += calcLength(relElem.getValue());
                }
            }
        }
        return length;
    } else {
        throw new SyntaxException("length() cannot calculate elements of type " + el.getClass().getName());
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) Relation(uk.me.parabola.mkgmap.reader.osm.Relation) Entry(java.util.Map.Entry) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) Way(uk.me.parabola.mkgmap.reader.osm.Way)

Example 9 with SyntaxException

use of uk.me.parabola.mkgmap.scan.SyntaxException in project mkgmap by openstreetmap.

the class ActionReader method readAllCmd.

private Action readAllCmd(boolean once) {
    String role = null;
    if (scanner.checkToken("role")) {
        scanner.nextToken();
        String eq = scanner.nextValue();
        if (!"=".equals(eq))
            throw new SyntaxException(scanner, "Expecting '=' after role keyword");
        role = scanner.nextWord();
    }
    SubAction subAction = new SubAction(role, once);
    List<Action> actionList = readActions().getList();
    for (Action a : actionList) subAction.add(a);
    return subAction;
}
Also used : SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException)

Example 10 with SyntaxException

use of uk.me.parabola.mkgmap.scan.SyntaxException in project mkgmap by openstreetmap.

the class ActionReader method readValueBuilder.

/**
 * A name command has a number of alternatives separated by '|' characters.
 */
private Action readValueBuilder(ValueBuildedAction action) {
    do {
        if (!inActionCmd())
            throw new SyntaxException(scanner, "unexpected end of add/set list");
        String val = scanner.nextWord();
        action.add(val);
    } while (hasMoreWords());
    usedTags.addAll(action.getUsedTags());
    return action;
}
Also used : SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException)

Aggregations

SyntaxException (uk.me.parabola.mkgmap.scan.SyntaxException)42 Token (uk.me.parabola.mkgmap.scan.Token)8 FileNotFoundException (java.io.FileNotFoundException)5 TokenScanner (uk.me.parabola.mkgmap.scan.TokenScanner)5 EqualsOp (uk.me.parabola.mkgmap.osmstyle.eval.EqualsOp)4 Op (uk.me.parabola.mkgmap.osmstyle.eval.Op)4 ValueOp (uk.me.parabola.mkgmap.osmstyle.eval.ValueOp)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 NotOp (uk.me.parabola.mkgmap.osmstyle.eval.NotOp)3 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 Matcher (java.util.regex.Matcher)2 ExitException (uk.me.parabola.imgfmt.ExitException)2 MapFailedException (uk.me.parabola.imgfmt.MapFailedException)2 BitmapImage (uk.me.parabola.imgfmt.app.typ.BitmapImage)2 ColourInfo (uk.me.parabola.imgfmt.app.typ.ColourInfo)2 TYPFile (uk.me.parabola.imgfmt.app.typ.TYPFile)2 TypData (uk.me.parabola.imgfmt.app.typ.TypData)2 Xpm (uk.me.parabola.imgfmt.app.typ.Xpm)2