Search in sources :

Example 1 with Token

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

the class RuleFileReader method readFinalize.

private boolean readFinalize(TokenScanner scanner) {
    Token token = scanner.nextToken();
    if (scanner.checkToken("finalize")) {
        Token finalizeToken = scanner.nextToken();
        if (scanner.checkToken(">")) {
            if (inFinalizeSection) {
                // there are two finalize sections which is not allowed
                throw new SyntaxException(scanner, "There is only one finalize section allowed");
            } else {
                // consume the > token
                scanner.nextToken();
                // mark start of the finalize block
                inFinalizeSection = true;
                finalizeRules = new RuleSet();
                return true;
            }
        } else {
            scanner.pushToken(finalizeToken);
            scanner.pushToken(token);
        }
    } else {
        scanner.pushToken(token);
    }
    return false;
}
Also used : SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) Token(uk.me.parabola.mkgmap.scan.Token)

Example 2 with Token

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

the class RuleFileReader method readElse.

private boolean readElse(TokenScanner scanner) {
    Token tok = scanner.nextToken();
    scanner.skipSpace();
    Token next = scanner.peekToken();
    if (next.getType() == TokType.SYMBOL && !next.isValue("(") && !next.isValue("!")) {
        scanner.pushToken(tok);
        return false;
    }
    Op[] ifExpressions = ifStack.removeLast();
    for (int i = 0; i < ifExpressions.length; i++) {
        Op op = ifExpressions[i];
        NotOp not = new NotOp();
        not.setFirst(op);
        ifExpressions[i] = not;
    }
    ifStack.addLast(ifExpressions);
    return true;
}
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) Token(uk.me.parabola.mkgmap.scan.Token) NotOp(uk.me.parabola.mkgmap.osmstyle.eval.NotOp)

Example 3 with Token

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

the class SrtTextReader method read.

/**
 * Read in a file and save the information in a form that can be used
 * to compare strings.
 * @param filename The name of the file, used for display purposes. It need
 * not refer to a file that actually exists.
 * @param r The opened file or other readable source.
 * @throws SyntaxException If the format of the file is incorrect.
 */
public void read(String filename, Reader r) {
    TokenScanner scanner = new TokenScanner(filename, r);
    resetPos();
    state = IN_INITIAL;
    while (!scanner.isEndOfFile()) {
        Token tok = scanner.nextToken();
        // We deal with whole line comments here
        if (tok.isValue("#")) {
            scanner.skipLine();
            continue;
        }
        switch(state) {
            case IN_INITIAL:
                initialState(scanner, tok);
                break;
            case IN_CHARACTER:
                characterState(scanner, tok);
                break;
            case IN_EXPAND:
                expandState(scanner, tok);
                break;
        }
    }
    sort.setExpansions(expansions);
    sort.finish();
}
Also used : TokenScanner(uk.me.parabola.mkgmap.scan.TokenScanner) Token(uk.me.parabola.mkgmap.scan.Token)

Example 4 with Token

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

the class CommonSection method readExtraColourInfo.

/**
 * Get any keywords that are on the end of the colour line. Must not step
 * over the new line boundary.
 */
private void readExtraColourInfo(TokenScanner scanner, AlphaAdder colour) {
    while (!scanner.isEndOfFile()) {
        Token tok = scanner.nextRawToken();
        if (tok.isEol())
            break;
        String word = tok.getValue();
        // TypWiz uses alpha, TypViewer uses "canalalpha"
        if (word.endsWith("alpha")) {
            scanner.validateNext("=");
            String aval = scanner.nextValue();
            try {
                // Convert to rgba format
                int alpha = Integer.decode(aval);
                alpha = 255 - ((alpha << 4) + alpha);
                colour.addAlpha(alpha);
            } catch (NumberFormatException e) {
                throw new SyntaxException(scanner, "Bad number for alpha value " + aval);
            }
        }
    // ignore everything we don't recognise.
    }
}
Also used : SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) Token(uk.me.parabola.mkgmap.scan.Token)

Example 5 with Token

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

the class TypTextReader method read.

public void read(String filename, Reader r) {
    TokenScanner scanner = new TokenScanner(filename, r);
    // the '#' comment character is not appropriate for this file
    scanner.setCommentChar(null);
    ProcessSection currentSection = null;
    while (!scanner.isEndOfFile()) {
        Token tok = scanner.nextToken();
        if (tok.getType() == TokType.EOF)
            break;
        // We deal with whole line comments here
        if (tok.isValue(";")) {
            scanner.skipLine();
            continue;
        }
        if (tok.getType() == TokType.SYMBOL) {
            switch(tok.getValue().charAt(0)) {
                case ';':
                    scanner.skipLine();
                    break;
                case '[':
                    ProcessSection newSection = readSectionType(scanner);
                    if (currentSection != null)
                        currentSection.finish(scanner);
                    currentSection = newSection;
                    break;
                case '"':
                    scanner.skipLine();
                    break;
            }
        } else {
            if (currentSection == null)
                throw new SyntaxException(scanner, "Missing section start");
            // Line inside a section
            String name = tok.getValue();
            String sep = scanner.nextValue();
            if (!sep.equals("=") && !sep.equals(":"))
                throw new SyntaxException(scanner, "Expecting '=' or ':' instead of " + sep);
            String value = scanner.readLine();
            currentSection.processLine(scanner, name, value);
        }
        scanner.skipSpace();
    }
}
Also used : TokenScanner(uk.me.parabola.mkgmap.scan.TokenScanner) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) Token(uk.me.parabola.mkgmap.scan.Token)

Aggregations

Token (uk.me.parabola.mkgmap.scan.Token)14 SyntaxException (uk.me.parabola.mkgmap.scan.SyntaxException)8 TokenScanner (uk.me.parabola.mkgmap.scan.TokenScanner)4 BufferedReader (java.io.BufferedReader)2 ArrayList (java.util.ArrayList)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 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 HashSet (java.util.HashSet)1 CodePosition (uk.me.parabola.imgfmt.app.srt.CodePosition)1 ColourInfo (uk.me.parabola.imgfmt.app.typ.ColourInfo)1 Rgb (uk.me.parabola.imgfmt.app.typ.Rgb)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 GetTagFunction (uk.me.parabola.mkgmap.osmstyle.function.GetTagFunction)1