Search in sources :

Example 11 with TokenScanner

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

the class OverlayReader method readOverlays.

public void readOverlays() {
    TokenScanner ts = new TokenScanner(filename, reader);
    while (!ts.isEndOfFile()) {
        String line = ts.readLine();
        // Remove comments before parsing
        int commentstart = line.indexOf("#");
        if (commentstart != -1)
            line = line.substring(0, commentstart);
        String[] fields = line.split(":", 2);
        if (fields.length == 2) {
            try {
                overlays.put(Integer.decode(fields[0]), readReplacements(ts, fields[1]));
            } catch (NumberFormatException e) {
                throw new SyntaxException(ts, "Expecting a number");
            }
        }
    }
}
Also used : TokenScanner(uk.me.parabola.mkgmap.scan.TokenScanner) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException)

Example 12 with TokenScanner

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

the class PrefixSuffixFilter method readOptionFile.

/**
 * @param r
 * @param filename
 */
private void readOptionFile(Reader r, String filename) {
    BufferedReader br = new BufferedReader(r);
    TokenScanner ts = new TokenScanner(filename, br);
    ts.setExtraWordChars(":");
    while (!ts.isEndOfFile()) {
        Token tok = ts.nextToken();
        if (tok.isValue("#")) {
            ts.skipLine();
            continue;
        }
        String key = tok.getValue();
        ts.skipSpace();
        tok = ts.peekToken();
        if (tok.getType() == TokType.SYMBOL) {
            String punc = ts.nextValue();
            String val;
            if (punc.equals(":") || punc.equals("=")) {
                val = ts.readLine();
            } else {
                ts.skipLine();
                continue;
            }
            processOption(key, val);
        } else if (key != null) {
            throw new IllegalArgumentException("don't understand line with " + key);
        } else {
            ts.skipLine();
        }
    }
    /**
     * process lines starting with prefix1 or prefix2.
     */
    for (String lang : languages) {
        String prefix1 = options.getProperty("prefix1:" + lang, null);
        if (prefix1 == null)
            continue;
        String prefix2 = options.getProperty("prefix2:" + lang, null);
        List<String> p1 = prefix1 != null ? Arrays.asList(prefix1.split(",")) : Collections.emptyList();
        List<String> p2 = prefix2 != null ? Arrays.asList(prefix2.split(",")) : Collections.emptyList();
        langPrefixMap.put(lang, genPrefix(p1, p2));
    }
}
Also used : TokenScanner(uk.me.parabola.mkgmap.scan.TokenScanner) BufferedReader(java.io.BufferedReader) Token(uk.me.parabola.mkgmap.scan.Token)

Aggregations

TokenScanner (uk.me.parabola.mkgmap.scan.TokenScanner)12 StringReader (java.io.StringReader)5 SyntaxException (uk.me.parabola.mkgmap.scan.SyntaxException)5 Token (uk.me.parabola.mkgmap.scan.Token)4 BufferedReader (java.io.BufferedReader)3 Reader (java.io.Reader)3 ExpressionReader (uk.me.parabola.mkgmap.osmstyle.eval.ExpressionReader)3 ActionReader (uk.me.parabola.mkgmap.osmstyle.actions.ActionReader)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 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 LevelInfo (uk.me.parabola.mkgmap.general.LevelInfo)1 ActionList (uk.me.parabola.mkgmap.osmstyle.actions.ActionList)1 AndOp (uk.me.parabola.mkgmap.osmstyle.eval.AndOp)1 BinaryOp (uk.me.parabola.mkgmap.osmstyle.eval.BinaryOp)1 ExistsOp (uk.me.parabola.mkgmap.osmstyle.eval.ExistsOp)1