Search in sources :

Example 1 with TokenScanner

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

the class RuleFileReader method loadFile.

/**
 * Load a rules file.  This should be used when calling recursively when including
 * files.
 */
private void loadFile(StyleFileLoader loader, String name) throws FileNotFoundException {
    Reader r = loader.open(name);
    TokenScanner scanner = new TokenScanner(name, r);
    scanner.setExtraWordChars("-:.");
    ExpressionReader expressionReader = new ExpressionReader(scanner, kind);
    ActionReader actionReader = new ActionReader(scanner);
    // Read all the rules in the file.
    scanner.skipSpace();
    while (!scanner.isEndOfFile()) {
        if (checkCommand(loader, scanner, expressionReader))
            continue;
        if (scanner.isEndOfFile())
            break;
        Op expr = expressionReader.readConditions(ifStack);
        expr = arranger.arrange(expr);
        ActionList actionList = actionReader.readActions();
        checkIfStack(actionList);
        if (performChecks && this.kind == FeatureKind.RELATION) {
            String actionsString = actionList.getList().toString();
            if (actionsString.contains("set mkgmap:stylefilter") || actionsString.contains("add mkgmap:stylefilter")) {
                log.error("Style file", name, "should not set or add the special tag mkgmap:stylefilter:", actionsString);
            }
        }
        List<GType> types = new ArrayList<>();
        while (scanner.checkToken("[")) {
            GType type = typeReader.readType(scanner, performChecks, overlays);
            types.add(type);
            scanner.skipSpace();
        }
        // If there is an action list, then we don't need a type
        if (types.isEmpty() && actionList.isEmpty())
            throw new SyntaxException(scanner, "No type definition given");
        if (types.isEmpty())
            saveRule(scanner, expr, actionList, null);
        if (types.size() >= 2 && actionList.isModifyingTags()) {
            throw new SyntaxException(scanner, "Combination of multiple type definitions with tag modifying action is not yet supported.");
        }
        for (int i = 0; i < types.size(); i++) {
            GType type = types.get(i);
            if (i + 1 < types.size()) {
                type.setContinueSearch(true);
            }
            // No need to create a deep copy of expr
            saveRule(scanner, expr, actionList, type);
            actionList = new ActionList(Collections.emptyList(), Collections.emptySet());
        }
    }
    rules.addUsedTags(expressionReader.getUsedTags());
    rules.addUsedTags(actionReader.getUsedTags());
}
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) GType(uk.me.parabola.mkgmap.reader.osm.GType) TokenScanner(uk.me.parabola.mkgmap.scan.TokenScanner) ActionReader(uk.me.parabola.mkgmap.osmstyle.actions.ActionReader) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) ArrayList(java.util.ArrayList) ActionReader(uk.me.parabola.mkgmap.osmstyle.actions.ActionReader) Reader(java.io.Reader) ExpressionReader(uk.me.parabola.mkgmap.osmstyle.eval.ExpressionReader) ActionList(uk.me.parabola.mkgmap.osmstyle.actions.ActionList) ExpressionReader(uk.me.parabola.mkgmap.osmstyle.eval.ExpressionReader)

Example 2 with TokenScanner

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

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

the class CommonSection method parseXpmHeader.

/**
 * Parse the XPM header in a typ file.
 *
 * There are extensions compared to a regular XPM file.
 *
 * @param scanner Only for reporting syntax errors.
 * @param info Information read from the string is stored here.
 * @param header The string containing the xpm header and other extended data provided on the
 * same line.
 */
private void parseXpmHeader(TokenScanner scanner, ColourInfo info, String header) {
    TokenScanner s2 = new TokenScanner("string", new StringReader(header));
    if (s2.checkToken("\""))
        s2.nextToken();
    try {
        info.setWidth(s2.nextInt());
        info.setHeight(s2.nextInt());
        info.setNumberOfColours(s2.nextInt());
        info.setCharsPerPixel(s2.nextInt());
    } catch (NumberFormatException e) {
        throw new SyntaxException(scanner, "Bad number in XPM header " + header);
    }
}
Also used : TokenScanner(uk.me.parabola.mkgmap.scan.TokenScanner) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) StringReader(java.io.StringReader)

Example 4 with TokenScanner

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

the class ActionReaderTest method readActionsFromString.

/**
 * Read a action list from a string.
 */
private List<Action> readActionsFromString(String in) {
    Reader sr = new StringReader(in);
    TokenScanner ts = new TokenScanner("string", sr);
    ActionReader ar = new ActionReader(ts);
    return ar.readActions().getList();
}
Also used : TokenScanner(uk.me.parabola.mkgmap.scan.TokenScanner) ActionReader(uk.me.parabola.mkgmap.osmstyle.actions.ActionReader) StringReader(java.io.StringReader) Reader(java.io.Reader) ActionReader(uk.me.parabola.mkgmap.osmstyle.actions.ActionReader) StringReader(java.io.StringReader)

Example 5 with TokenScanner

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

the class TypeReaderTest method makeType.

private GType makeType(String in) {
    LevelInfo[] levels = LevelInfo.createFromString("0:24 1:20 2:18 3:16 4:14");
    TypeReader tr = new TypeReader(FeatureKind.POLYLINE, levels);
    TokenScanner ts = new TokenScanner("string", new StringReader(in));
    ts.setExtraWordChars("-:");
    return tr.readType(ts);
}
Also used : TokenScanner(uk.me.parabola.mkgmap.scan.TokenScanner) LevelInfo(uk.me.parabola.mkgmap.general.LevelInfo) StringReader(java.io.StringReader)

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