Search in sources :

Example 36 with SyntaxException

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

the class ActionReader method readActions.

public ActionList readActions() {
    List<Action> actions = new ArrayList<>();
    Set<String> changeableTags = new HashSet<>();
    scanner.skipSpace();
    if (!scanner.checkToken("{"))
        return new ActionList(actions, changeableTags);
    scanner.nextToken();
    while (inAction()) {
        Token tok = scanner.nextToken();
        if (tok.isValue(";"))
            continue;
        if (tok.isValue("'") || tok.isValue("\""))
            throw new SyntaxException(scanner, "quoted word found where command expected");
        String cmd = tok.getValue();
        if ("set".equals(cmd)) {
            actions.add(readTagValue(true, changeableTags));
        } else if ("add".equals(cmd)) {
            actions.add(readTagValue(false, changeableTags));
        } else if ("setaccess".equals(cmd)) {
            actions.add(readAccessValue(true, changeableTags));
        } else if ("addaccess".equals(cmd)) {
            actions.add(readAccessValue(false, changeableTags));
        } else if ("apply".equals(cmd)) {
            actions.add(readAllCmd(false));
        } else if ("apply_once".equals(cmd)) {
            actions.add(readAllCmd(true));
        } else if ("name".equals(cmd)) {
            actions.add(readValueBuilder(new NameAction()));
            changeableTags.add("mkgmap:label:1");
        } else if ("addlabel".equals(cmd)) {
            actions.add(readValueBuilder(new AddLabelAction()));
            for (int labelNo = 1; labelNo <= 4; labelNo++) changeableTags.add("mkgmap:label:" + labelNo);
        } else if ("delete".equals(cmd)) {
            String tag = scanner.nextWord();
            actions.add(new DeleteAction(tag));
        } else if ("deletealltags".equals(cmd)) {
            actions.add(new DeleteAllTagsAction());
        } else if ("rename".equals(cmd)) {
            String from = scanner.nextWord();
            String to = scanner.nextWord();
            Action act = new RenameAction(from, to);
            actions.add(act);
            // The 'to' tag may come into existence and you may attempt
            // to match on it, therefore we have to save it.
            changeableTags.add(to);
            // the from tag must not be dropped from the input
            usedTags.add(from);
        } else if ("echo".equals(cmd)) {
            String str = scanner.nextWord();
            actions.add(new EchoAction(str));
        } else if ("echotags".equals(cmd)) {
            String str = scanner.nextWord();
            actions.add(new EchoTagsAction(str));
        } else {
            throw new SyntaxException(scanner, "Unrecognised command '" + cmd + '\'');
        }
        scanner.skipSpace();
    }
    if (scanner.checkToken("}"))
        scanner.nextToken();
    scanner.skipSpace();
    return new ActionList(actions, changeableTags);
}
Also used : ArrayList(java.util.ArrayList) Token(uk.me.parabola.mkgmap.scan.Token) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) HashSet(java.util.HashSet)

Example 37 with SyntaxException

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

the class ExpressionReader method saveOp.

/**
 * An operation is saved on the operation stack.  The tree is built
 * as operations of different priorities arrive.
 */
private void saveOp(String value) {
    log.debug("save op", value);
    if (value.equals("#")) {
        scanner.skipLine();
        return;
    }
    Op op;
    try {
        op = AbstractOp.createOp(value);
        while (!opStack.isEmpty() && opStack.peek().hasHigherPriority(op)) runOp(scanner);
    } catch (SyntaxException e) {
        throw new SyntaxException(scanner, e.getRawMessage());
    }
    if (op.getType() == CLOSE_PAREN) {
        // Check that there was an opening parenthesis and remove it
        if (opStack.isEmpty() || !opStack.peek().isType(OPEN_PAREN))
            throw new SyntaxException(scanner, "No matching open parenthesis");
        opStack.pop();
    } else {
        opStack.push(op);
    }
}
Also used : SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException)

Example 38 with SyntaxException

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

the class MdrConfig method genTypesForRange.

/**
 * Create all POI types for a given range.
 * @param set set of integers. Generated types are added to it.
 * @param start first type
 * @param stop last type (included)
 */
private void genTypesForRange(Set<Integer> set, String start, String stop) {
    GType[] types = new GType[2];
    String[] ranges = { start, stop };
    boolean ok = true;
    for (int i = 0; i < 2; i++) {
        try {
            types[i] = new GType(FeatureKind.POINT, ranges[i]);
        } catch (ExitException e) {
            ok = false;
        }
        if (!ok || !GType.checkType(types[i].getFeatureKind(), types[i].getType())) {
            throw new SyntaxException("invalid type " + ranges[i] + " for " + FeatureKind.POINT + " in option " + Arrays.toString(ranges));
        }
    }
    if (types[0].getType() > types[1].getType()) {
        GType gt = types[0];
        types[0] = types[1];
        types[1] = gt;
    }
    for (int i = types[0].getType(); i <= types[1].getType(); i++) {
        if ((i & 0xff) > 0x1f)
            i = ((i >> 8) + 1) << 8;
        set.add(i);
    }
}
Also used : GType(uk.me.parabola.mkgmap.reader.osm.GType) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) ExitException(uk.me.parabola.imgfmt.ExitException)

Example 39 with SyntaxException

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

the class SrtTextReader method characterState.

/**
 * Block consisting of characters and relations between them.
 *
 * The sort order is derived from this.
 *
 * @param scanner The scanner for more tokens.
 * @param tok The current token to process.
 */
private void characterState(TokenScanner scanner, Token tok) {
    String val = tok.getValue();
    TokType type = tok.getType();
    if (type == TokType.TEXT) {
        switch(val) {
            case "flags":
                scanner.validateNext("=");
                cflags = scanner.nextWord();
                // TODO not yet
                break;
            case // Used to set the actual sort position value, not used any more
            "pos":
                scanner.validateNext("=");
                try {
                    int newPos = Integer.decode(scanner.nextWord());
                    if (newPos < pos1)
                        throw new SyntaxException(scanner, "cannot set primary position backwards, was " + pos1);
                    pos1 = newPos;
                } catch (NumberFormatException e) {
                    throw new SyntaxException(scanner, "invalid integer for position");
                }
                break;
            case // Used to set the actual sort position value, not used any more
            "pos2":
                scanner.validateNext("=");
                pos2 = Integer.decode(scanner.nextWord());
                break;
            case // Used to set the actual sort position value, not used any more
            "pos3":
                scanner.validateNext("=");
                pos3 = Integer.decode(scanner.nextWord());
                break;
            // the old name, use 'characters'
            case "code":
            case "characters":
                advancePos();
                break;
            case "expand":
                // scanner.pushToken(tok);
                state = IN_EXPAND;
                break;
            default:
                addCharacter(scanner, val);
                break;
        }
    } else if (type == TokType.SYMBOL) {
        switch(val) {
            case "=":
                break;
            case ",":
                pos3++;
                break;
            case ";":
                pos3 = 1;
                pos2++;
                break;
            case "<":
                advancePos();
                break;
            default:
                addCharacter(scanner, val);
                break;
        }
    }
}
Also used : SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) TokType(uk.me.parabola.mkgmap.scan.TokType)

Example 40 with SyntaxException

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

the class SrtTextReader method expandState.

/**
 * Within an 'expand' command. The whole command is read before return, they can not span
 * lines.
 *
 * @param tok The first token after the keyword.
 */
private void expandState(TokenScanner scanner, Token tok) {
    String val = tok.getValue();
    Code code = new Code(scanner, val).read();
    String s = scanner.nextValue();
    if (!s.equals("to"))
        throw new SyntaxException(scanner, "Expected the word 'to' in expand command");
    int secondary = 0;
    int tertiary = 0;
    int num = 0;
    while (!scanner.isEndOfFile()) {
        Token t = scanner.nextRawToken();
        if (t.isEol())
            break;
        if (t.isWhiteSpace())
            continue;
        Code r = new Code(scanner, t.getValue()).read();
        CodePosition cp = new CodePosition();
        int b = r.getBval();
        int primary = sort.getPrimary(b);
        cp.setPrimary((char) primary);
        // character so adjust the ordering at other strengths.  May need further tweaks.
        if (EXPERIMENTAL) {
            secondary = sort.getSecondary(b);
            tertiary = sort.getTertiary(b);
            if (num++ == 0) {
                Integer max = maxSec.get(primary);
                secondary += max == null ? 0 : max;
                if (charFlags(code) == 1) {
                    max = maxTert.get(primary);
                    tertiary += max == null ? 0 : max;
                }
            } else {
                secondary = 1;
            }
            cp.setSecondary((byte) (secondary));
            cp.setTertiary((byte) (tertiary));
        } else {
            num++;
            secondary = sort.getSecondary(b) & 0xff;
            cp.setSecondary((byte) (secondary + 7));
            tertiary = sort.getTertiary(b) & 0xff;
            cp.setTertiary((byte) (tertiary + 2));
        }
        expansions.add(cp);
    }
    int flags = charFlags(code) | (num - 1) << 4;
    sort.add(code.getBval(), expansions.size() - num + 1, 0, 0, flags);
    state = IN_INITIAL;
}
Also used : CodePosition(uk.me.parabola.imgfmt.app.srt.CodePosition) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) Token(uk.me.parabola.mkgmap.scan.Token)

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