Search in sources :

Example 26 with SyntaxException

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

the class TypeReader method readType.

public GType readType(TokenScanner ts, boolean performChecks, Map<Integer, List<Integer>> overlays) {
    // We should have a '[' to start with
    Token t = ts.nextToken();
    if (t == null || t.getType() == TokType.EOF)
        throw new SyntaxException(ts, "No garmin type information given");
    if (!t.getValue().equals("[")) {
        throw new SyntaxException(ts, "No type definition");
    }
    ts.skipSpace();
    String type = ts.nextValue();
    if (!Character.isDigit(type.charAt(0)))
        throw new SyntaxException(ts, "Garmin type number must be first.  Saw '" + type + '\'');
    log.debug("gtype", type);
    GType gt = new GType(kind, type);
    if (GType.checkType(gt.getFeatureKind(), gt.getType()) == false) {
        if (!performChecks && (kind != FeatureKind.POLYLINE || overlays == null || overlays.get(gt.getType()) == null))
            throw new SyntaxException("invalid type " + type + " for " + kind + " in style file " + ts.getFileName() + ", line " + ts.getLinenumber());
    }
    while (!ts.isEndOfFile()) {
        ts.skipSpace();
        String w = ts.nextValue();
        if (w.equals("]"))
            break;
        if (w.equals("level")) {
            setLevel(ts, gt);
        } else if (w.equals("resolution")) {
            setResolution(ts, gt);
        } else if (w.equals("default_name")) {
            gt.setDefaultName(nextValue(ts));
        } else if (w.equals("road_class")) {
            gt.setRoadClass(nextIntValue(ts));
        } else if (w.equals("road_speed")) {
            gt.setRoadSpeed(nextIntValue(ts));
        } else if (w.equals("copy")) {
        // Reserved
        } else if (w.equals("continue")) {
            gt.setContinueSearch(true);
            // By default no propagate of actions on continue
            gt.propagateActions(false);
        } else if (w.equals("propagate") || w.equals("with_actions") || w.equals("withactions")) {
            gt.propagateActions(true);
        } else if (w.equals("no_propagate")) {
            gt.propagateActions(false);
        } else if (w.equals("oneway")) {
        // reserved
        } else if (w.equals("access")) {
        // reserved
        } else {
            throw new SyntaxException(ts, "Unrecognised type command '" + w + '\'');
        }
    }
    gt.fixLevels(levels);
    if ("lines".equals(ts.getFileName())) {
        if (gt.getRoadClass() < 0 || gt.getRoadClass() > 4)
            log.error("road class value", gt.getRoadClass(), "not in the range 0-4 in style file lines, line " + ts.getLinenumber());
        if (gt.getRoadSpeed() < 0 || gt.getRoadSpeed() > 7)
            log.error("road speed value ", gt.getRoadSpeed(), "not in the range 0-7 in style file lines, line " + ts.getLinenumber());
    }
    if (performChecks) {
        boolean fromOverlays = false;
        List<Integer> usedTypes = null;
        if (gt.getMaxResolution() < levels[0].getBits() || gt.getMaxResolution() > 24) {
            System.out.println("Warning: Object with max resolution of " + gt.getMaxResolution() + " is ignored. Check levels option and style file " + ts.getFileName() + ", line " + ts.getLinenumber());
        } else if (gt.getMinResolution() > 24) {
            System.out.println("Warning: Object with min resolution of " + gt.getMinResolution() + " is ignored. Check levels option and style file " + ts.getFileName() + ", line " + ts.getLinenumber());
        }
        if (overlays != null && kind == FeatureKind.POLYLINE) {
            usedTypes = overlays.get(gt.getType());
            if (usedTypes != null)
                fromOverlays = true;
        }
        if (usedTypes == null)
            usedTypes = Arrays.asList(gt.getType());
        boolean foundRoutableType = false;
        for (int i = 0; i < usedTypes.size(); i++) {
            int usedType = usedTypes.get(i);
            String typeOverlaidMsg = ". Type is overlaid with " + GType.formatType(usedType);
            if (GType.checkType(kind, usedType) == false) {
                String msg = "Warning: invalid type " + type + " for " + kind + " in style file " + ts.getFileName() + ", line " + ts.getLinenumber();
                if (fromOverlays)
                    msg += typeOverlaidMsg;
                System.out.println(msg);
            }
            if (kind == FeatureKind.POLYLINE && gt.getMinLevel() == 0 && gt.getMaxLevel() >= 0) {
                if (GType.isSpecialRoutableLineType(usedType)) {
                    if (gt.hasRoadAttribute() == false) {
                        String msg = "Warning: routable type " + type + " is used for non-routable line with level 0. This may break routing. Style file " + ts.getFileName() + ", line " + ts.getLinenumber();
                        if (fromOverlays)
                            msg += typeOverlaidMsg;
                        System.out.println(msg);
                    } else if (i > 0) {
                        System.out.println("Warning: routable type " + type + " is used for non-routable line with level 0. " + "This may break routing. Style file " + ts.getFileName() + ", line " + ts.getLinenumber() + typeOverlaidMsg + " which is used for adding the non-routable copy of the way.");
                    }
                }
            }
            if (kind == FeatureKind.POLYLINE && GType.isRoutableLineType(usedType)) {
                foundRoutableType = true;
            }
        }
        if (gt.hasRoadAttribute() && foundRoutableType == false && gt.getMinLevel() == 0 && gt.getMaxLevel() >= 0) {
            String msg = "Warning: non-routable type " + type + " is used in combination with road_class/road_speed. Line will not be routable. Style file " + ts.getFileName() + ", line " + ts.getLinenumber();
            if (fromOverlays)
                msg += ". Type is overlaid, but not with a routable type";
            System.out.println(msg);
        }
    }
    return gt;
}
Also used : GType(uk.me.parabola.mkgmap.reader.osm.GType) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) Token(uk.me.parabola.mkgmap.scan.Token)

Example 27 with SyntaxException

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

the class TypeReader method setResolution.

/**
 * A resolution can be just a single number, in which case that is the
 * min resolution and the max defaults to 24.  Or a min to max range.
 */
private static void setResolution(TokenScanner ts, GType gt) {
    String str = ts.nextWord();
    log.debug("res word value", str);
    try {
        if (str.indexOf('-') >= 0) {
            String[] minmax = HYPHEN_PATTERN.split(str, 2);
            int val1 = Integer.parseInt(minmax[0]);
            int val2 = Integer.parseInt(minmax[1]);
            if (val1 > val2) {
                // Previously there was a bug where the order was reversed, so we swap the numbers if they are
                // the wrong way round.
                int h = val1;
                val1 = val2;
                val2 = h;
            }
            gt.setMinResolution(val1);
            gt.setMaxResolution(val2);
        } else {
            gt.setMinResolution(Integer.parseInt(str));
        }
    } catch (NumberFormatException e) {
        throw new SyntaxException(ts, "Invalid value for resolution: '" + str + '\'');
    }
}
Also used : SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException)

Example 28 with SyntaxException

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

the class Main method readOneStyle.

/**
 * Try to read a style from styleFile directory
 * @param name name of the style
 * @param performChecks perform checks?
 * @return the style or null in case of errors
 */
private Style readOneStyle(String name, boolean performChecks) {
    searchedStyleName = name;
    Style style = null;
    try {
        style = new StyleImpl(styleFile, name, new EnhancedProperties(), performChecks);
    } catch (SyntaxException e) {
        System.err.println("Error in style: " + e.getMessage());
    } catch (FileNotFoundException e) {
        log.debug("could not find style", name);
        try {
            searchedStyleName = new File(styleFile).getName();
            style = new StyleImpl(styleFile, null, new EnhancedProperties(), performChecks);
        } catch (SyntaxException e1) {
            System.err.println("Error in style: " + e1.getMessage());
        } catch (FileNotFoundException e1) {
            log.debug("could not find style", styleFile);
        }
    }
    return style;
}
Also used : EnhancedProperties(uk.me.parabola.util.EnhancedProperties) StyleImpl(uk.me.parabola.mkgmap.osmstyle.StyleImpl) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) FileNotFoundException(java.io.FileNotFoundException) Style(uk.me.parabola.mkgmap.reader.osm.Style) File(java.io.File)

Example 29 with SyntaxException

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

the class TypCompiler method standAloneRun.

private void standAloneRun(String in, String out) {
    CharsetProbe probe = new CharsetProbe();
    String readCharset = probe.probeCharset(in);
    TypData data;
    try {
        data = compile(in, readCharset, null);
    } catch (SyntaxException e) {
        System.out.println(e.getMessage());
        return;
    } catch (FileNotFoundException e) {
        throw new MapFailedException("Could not open TYP file " + in + " to read");
    }
    try {
        writeTyp(data, new File(out));
    } catch (IOException e) {
        System.out.println("Error writing file: " + e.getMessage());
    }
}
Also used : TypData(uk.me.parabola.imgfmt.app.typ.TypData) MapFailedException(uk.me.parabola.imgfmt.MapFailedException) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) TYPFile(uk.me.parabola.imgfmt.app.typ.TYPFile) File(java.io.File)

Example 30 with SyntaxException

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

the class OverlayReader method readReplacements.

/**
 * Read the line of replacements.
 */
private List<Integer> readReplacements(TokenScanner ts, String line) {
    List<Integer> l = new ArrayList<Integer>();
    String[] nums = line.split("[ ,]");
    for (String n : nums) {
        if (n == null || n.length() == 0)
            continue;
        try {
            l.add(Integer.decode(n));
        } catch (NumberFormatException e) {
            throw new SyntaxException(ts, "List of numbers expected");
        }
    }
    return l;
}
Also used : SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) ArrayList(java.util.ArrayList)

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