Search in sources :

Example 31 with SyntaxException

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

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

the class RuleFileReader method readInclude.

private boolean readInclude(StyleFileLoader currentLoader, TokenScanner scanner) {
    // Consume the 'include' token and skip spaces
    Token token = scanner.nextToken();
    scanner.skipSpace();
    // If include is being used as a keyword then it is followed by a word or a quoted word.
    Token next = scanner.peekToken();
    if (next.getType() == TokType.TEXT || next.getType() == TokType.SYMBOL && (next.isValue("'") || next.isValue("\""))) {
        String filename = scanner.nextWord();
        StyleFileLoader loader = currentLoader;
        scanner.skipSpace();
        // style-name in that case.
        if (scanner.checkToken("from")) {
            scanner.nextToken();
            String styleName = scanner.nextWord();
            if (Objects.equals(styleName, ";"))
                throw new SyntaxException(scanner, "No style name after 'from'");
            try {
                loader = StyleFileLoader.createStyleLoader(null, styleName);
            } catch (FileNotFoundException e) {
                throw new SyntaxException(scanner, "Cannot find style: " + styleName);
            }
        }
        if (scanner.checkToken(";"))
            scanner.nextToken();
        try {
            loadFile(loader, filename);
            return true;
        } catch (FileNotFoundException e) {
            throw new SyntaxException(scanner, "Cannot open included file: " + filename);
        } finally {
            if (loader != currentLoader)
                Utils.closeFile(loader);
        }
    } else {
        // Wrong syntax for include statement, so push back token to allow a possible expression to be read
        scanner.pushToken(token);
    }
    return false;
}
Also used : SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) FileNotFoundException(java.io.FileNotFoundException) Token(uk.me.parabola.mkgmap.scan.Token)

Example 33 with SyntaxException

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

the class ValueBuilder method addFilter.

private void addFilter(ValueItem item, String expr) {
    Matcher matcher = NAME_ARG_SPLIT.matcher(expr);
    matcher.matches();
    String cmd = matcher.group(1);
    String arg = matcher.group(2);
    switch(cmd) {
        case "def":
            item.addFilter(new DefaultFilter(arg));
            break;
        case "conv":
            item.addFilter(new ConvertFilter(arg));
            break;
        case "subst":
            item.addFilter(new SubstitutionFilter(arg));
            break;
        case "prefix":
            item.addFilter(new PrependFilter(arg));
            break;
        case "highway-symbol":
            item.addFilter(new HighwaySymbolFilter(arg));
            break;
        case "height":
            item.addFilter(new HeightFilter(arg));
            break;
        case "not-equal":
            item.addFilter(new NotEqualFilter(arg));
            break;
        case "substring":
            item.addFilter(new SubstringFilter(arg));
            break;
        case "part":
            item.addFilter(new PartFilter(arg));
            break;
        case "ascii":
            item.addFilter(new TransliterateFilter("ascii"));
            break;
        case "latin1":
            item.addFilter(new TransliterateFilter("latin1"));
            break;
        case "country-ISO":
            item.addFilter(new CountryISOFilter());
            break;
        case "not-contained":
            item.addFilter(new NotContainedFilter(arg));
            break;
        default:
            throw new SyntaxException(String.format("Unknown filter '%s'", cmd));
    }
}
Also used : Matcher(java.util.regex.Matcher) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException)

Example 34 with SyntaxException

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

the class AbstractOp method createOp.

public static Op createOp(String value) {
    char c = value.charAt(0);
    Op op;
    switch(c) {
        case '=':
            op = new EqualsOp();
            break;
        case '&':
            if (value.length() > 1)
                throw new SyntaxException(String.format("Use '&' instead of '%s'", value));
            op = new AndOp();
            break;
        case '|':
            if (value.length() > 1)
                throw new SyntaxException(String.format("Use '|' instead of '%s'", value));
            op = new OrOp();
            break;
        case '~':
            op = new RegexOp();
            break;
        case '(':
            op = new OpenOp();
            break;
        case ')':
            op = new CloseOp();
            break;
        case '>':
            if (value.equals(">="))
                op = new GTEOp();
            else
                op = new GTOp();
            break;
        case '<':
            if (value.equals("<="))
                op = new LTEOp();
            else
                op = new LTOp();
            break;
        case '!':
            if (value.equals("!="))
                op = new NotEqualOp();
            else
                op = new NotOp();
            break;
        default:
            throw new SyntaxException("Unrecognised operation " + c);
    }
    return op;
}
Also used : SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException)

Example 35 with SyntaxException

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

the class ActionReader method readTagValue.

/**
 * Read a tag/value pair.  If the action is executed then the tag name
 * will possibly be modified or set.  If that is the case then we will
 * have to make sure that we are executing rules for that tag.
 *
 * @param modify If true the tag value can be modified.  If it is not set
 * then a tag can only be added; if it already exists, then it will not
 * be changed.
 * @param changeableTags Tags that could be changed by the action.  This is
 * an output parameter, any such tags should be added to this set.
 * @return The new add tag action.
 */
private AddTagAction readTagValue(boolean modify, Set<String> changeableTags) {
    String key = scanner.nextWord();
    if (!scanner.checkToken("="))
        throw new SyntaxException(scanner, "Expecting tag=value");
    scanner.nextToken();
    AddTagAction action = null;
    do {
        if (!inActionCmd())
            throw new SyntaxException(scanner, "unexpected end of add/set list");
        String val = scanner.nextWord();
        if (action == null)
            action = new AddTagAction(key, val, modify);
        else
            action.add(val);
        // value will be.  Otherwise save the full tag=value
        if (val.contains("$")) {
            changeableTags.add(key);
        } else {
            changeableTags.add(key + "=" + val);
        }
    } while (hasMoreWords());
    usedTags.addAll(action.getUsedTags());
    return action;
}
Also used : SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException)

Aggregations

SyntaxException (uk.me.parabola.mkgmap.scan.SyntaxException)42 Token (uk.me.parabola.mkgmap.scan.Token)8 FileNotFoundException (java.io.FileNotFoundException)5 TokenScanner (uk.me.parabola.mkgmap.scan.TokenScanner)5 EqualsOp (uk.me.parabola.mkgmap.osmstyle.eval.EqualsOp)4 Op (uk.me.parabola.mkgmap.osmstyle.eval.Op)4 ValueOp (uk.me.parabola.mkgmap.osmstyle.eval.ValueOp)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 NotOp (uk.me.parabola.mkgmap.osmstyle.eval.NotOp)3 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 Matcher (java.util.regex.Matcher)2 ExitException (uk.me.parabola.imgfmt.ExitException)2 MapFailedException (uk.me.parabola.imgfmt.MapFailedException)2 BitmapImage (uk.me.parabola.imgfmt.app.typ.BitmapImage)2 ColourInfo (uk.me.parabola.imgfmt.app.typ.ColourInfo)2 TYPFile (uk.me.parabola.imgfmt.app.typ.TYPFile)2 TypData (uk.me.parabola.imgfmt.app.typ.TypData)2 Xpm (uk.me.parabola.imgfmt.app.typ.Xpm)2