Search in sources :

Example 6 with TokenScanner

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

Example 7 with TokenScanner

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

the class Options method readOptionFile.

public void readOptionFile(Reader r, String filename) {
    BufferedReader br = new BufferedReader(r);
    TokenScanner ts = new TokenScanner(filename, br);
    ts.setExtraWordChars("-");
    File file = new File(filename);
    String parent = file.getParent();
    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 if (punc.equals("{")) {
                ts.skipSpace();
                val = ts.readUntil(TokType.SYMBOL, "}");
                // discard the closing brace
                ts.nextToken();
            } else {
                ts.skipLine();
                continue;
            }
            // location of the argument file.
            if (key.equals("input-file") && !new File(val).isAbsolute())
                val = new File(parent, val).getPath();
            proc.processOption(new Option(key, val));
        } else if (key != null) {
            proc.processOption(new Option(key, ""));
        } else {
            ts.skipLine();
        }
    }
}
Also used : TokenScanner(uk.me.parabola.mkgmap.scan.TokenScanner) BufferedReader(java.io.BufferedReader) Token(uk.me.parabola.mkgmap.scan.Token) File(java.io.File)

Example 8 with TokenScanner

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

the class ExpressionArrangerTest method createOp.

private Op createOp(String s) {
    TokenScanner scanner = new TokenScanner("test.file", new StringReader(s));
    ExpressionReader er = new ExpressionReader(scanner, FeatureKind.POLYLINE);
    return er.readConditions();
}
Also used : TokenScanner(uk.me.parabola.mkgmap.scan.TokenScanner) StringReader(java.io.StringReader) ExpressionReader(uk.me.parabola.mkgmap.osmstyle.eval.ExpressionReader)

Example 9 with TokenScanner

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

the class RulesTest method runArrangeTest.

private boolean runArrangeTest(String rule, int id) {
    TokenScanner scanner = new TokenScanner("test.file", new StringReader(rule));
    ExpressionReader er = new ExpressionReader(scanner, FeatureKind.POLYLINE);
    Op op = er.readConditions();
    boolean[] orig = evalWays(op);
    Op result = arranger.arrange(op);
    if (!isSolved(result))
        throw new SyntaxException("Could not solve rule expression: best attempt was " + fmtExpr(result));
    boolean[] after = evalWays(result);
    boolean ok = Arrays.equals(after, orig);
    if (ok) {
        if (!onlyErrors)
            System.out.println("OK: " + rule);
    } else {
        System.out.println("ERROR: FAILED test: " + rule);
        System.out.println("  new expr: " + op);
        for (int i = 0; i < orig.length; i++) {
            if (orig[i] != after[i]) {
                System.out.println("  way " + testWays.get(i) + ", orig=" + orig[i] + ", arranged=" + after[i]);
            }
        }
        checkStopOnFail();
    }
    return ok;
}
Also used : NotExistsOp(uk.me.parabola.mkgmap.osmstyle.eval.NotExistsOp) Op(uk.me.parabola.mkgmap.osmstyle.eval.Op) GTEOp(uk.me.parabola.mkgmap.osmstyle.eval.GTEOp) LTOp(uk.me.parabola.mkgmap.osmstyle.eval.LTOp) NotEqualOp(uk.me.parabola.mkgmap.osmstyle.eval.NotEqualOp) BinaryOp(uk.me.parabola.mkgmap.osmstyle.eval.BinaryOp) OrOp(uk.me.parabola.mkgmap.osmstyle.eval.OrOp) NotOp(uk.me.parabola.mkgmap.osmstyle.eval.NotOp) ValueOp(uk.me.parabola.mkgmap.osmstyle.eval.ValueOp) EqualsOp(uk.me.parabola.mkgmap.osmstyle.eval.EqualsOp) RegexOp(uk.me.parabola.mkgmap.osmstyle.eval.RegexOp) ExistsOp(uk.me.parabola.mkgmap.osmstyle.eval.ExistsOp) AndOp(uk.me.parabola.mkgmap.osmstyle.eval.AndOp) TokenScanner(uk.me.parabola.mkgmap.scan.TokenScanner) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) StringReader(java.io.StringReader) ExpressionReader(uk.me.parabola.mkgmap.osmstyle.eval.ExpressionReader)

Example 10 with TokenScanner

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

the class StyleImpl method checkVersion.

private void checkVersion() throws FileNotFoundException {
    Reader r = fileLoader.open(FILE_VERSION);
    TokenScanner scan = new TokenScanner(FILE_VERSION, r);
    int version;
    try {
        version = scan.nextInt();
        log.debug("Got version", version);
    } catch (NumberFormatException e) {
        // default to 0 if no version can be found.
        version = 0;
    }
    if (version > VERSION) {
        System.err.println("Warning: unrecognised style version " + version + ", but only versions up to " + VERSION + " are understood");
    }
}
Also used : TokenScanner(uk.me.parabola.mkgmap.scan.TokenScanner) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader)

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