Search in sources :

Example 1 with TokType

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

the class SrtTextReader method initialState.

/**
 * The initial state, looking for a variable to set or a command to change
 * the state.
 * @param scanner The scanner for more tokens.
 * @param tok The first token to process.
 */
private void initialState(TokenScanner scanner, Token tok) {
    String val = tok.getValue();
    TokType type = tok.getType();
    if (type == TokType.TEXT) {
        switch(val) {
            case "codepage":
                int codepage = scanner.nextInt();
                sort.setCodepage(codepage);
                encoder = sort.getCharset().newEncoder();
                break;
            case "description":
                sort.setDescription(scanner.nextWord());
                break;
            case "id1":
                sort.setId1(scanner.nextInt());
                break;
            case "id2":
                sort.setId2(scanner.nextInt());
                break;
            case "multi":
                sort.setMulti(true);
                break;
            // The old name; use characters
            case "code":
            case "characters":
                if (encoder == null)
                    throw new SyntaxException(scanner, "Missing codepage declaration before code");
                state = IN_CHARACTER;
                scanner.skipSpace();
                break;
            case "expand":
                state = IN_EXPAND;
                scanner.skipSpace();
                break;
            default:
                throw new SyntaxException(scanner, "Unrecognised command " + val);
        }
    }
}
Also used : SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) TokType(uk.me.parabola.mkgmap.scan.TokType)

Example 2 with TokType

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

Aggregations

SyntaxException (uk.me.parabola.mkgmap.scan.SyntaxException)2 TokType (uk.me.parabola.mkgmap.scan.TokType)2