use of uk.me.parabola.mkgmap.scan.SyntaxException in project mkgmap by openstreetmap.
the class StyleImpl method readStyle.
/**
* Evaluate the style options and try to read the style.
*
* The option --style-file give the location of an alternate file or
* directory containing styles rather than the default built in ones.
*
* The option --style gives the name of a style, either one of the
* built in ones or selects one from the given style-file.
*
* If there is no name given, but there is a file then the file should
* just contain one style.
*
* @param props the program properties
* @return A style instance or null in case of error.
*/
public static Style readStyle(EnhancedProperties props) {
String loc = props.getProperty("style-file");
if (loc == null)
loc = props.getProperty("map-features");
String name = props.getProperty("style");
if (loc == null && name == null)
name = "default";
if (name == null) {
StyleFileLoader loader = null;
try {
loader = StyleFileLoader.createStyleLoader(loc, null);
int numEntries = loader.list().length;
if (numEntries > 1)
throw new ExitException("Style file " + loc + " contains multiple styles, use option --style to select one.");
} catch (FileNotFoundException e) {
throw new ExitException("Could not open style file " + loc);
} finally {
Utils.closeFile(loader);
}
}
Style style;
try {
style = new StyleImpl(loc, name, props, WITHOUT_CHECKS);
} catch (SyntaxException e) {
System.err.println("Error in style: " + e.getMessage());
throw new ExitException("Could not open style " + (name == null ? "" : name));
} catch (FileNotFoundException e) {
String msg = "Could not open style ";
if (name != null) {
msg += name;
if (loc != null)
msg += " in " + loc;
} else
msg += loc + " . Make sure that it points to a style or add the --style option.";
throw new ExitException(msg);
}
return style;
}
use of uk.me.parabola.mkgmap.scan.SyntaxException in project mkgmap by openstreetmap.
the class TypeReader method setLevel.
/**
* Read a level spec, which is either the max level or a min to max range.
* This is immediately converted to resolution(s).
*/
private void setLevel(TokenScanner ts, GType gt) {
String str = ts.nextWord();
try {
if (str.indexOf('-') >= 0) {
String[] minmax = HYPHEN_PATTERN.split(str, 2);
int val1 = toResolution(Integer.parseInt(minmax[0]));
int val2 = toResolution(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(toResolution(Integer.parseInt(str)));
}
} catch (NumberFormatException e) {
throw new SyntaxException(ts, "Invalid value for level: '" + str + '\'');
}
}
use of uk.me.parabola.mkgmap.scan.SyntaxException in project mkgmap by openstreetmap.
the class TypCompiler method makeMap.
/**
* The integration with mkgmap.
*
* @param args The options that are in force.
* @param filename The input filename.
* @return Returns the name of the file that was written. It depends on the family id.
*/
public String makeMap(CommandArgs args, String filename) {
assert filename.toLowerCase().endsWith(".txt");
CharsetProbe probe = new CharsetProbe();
String readCharset = probe.probeCharset(filename);
TypData data;
try {
data = compile(filename, readCharset, args.getSort());
} catch (SyntaxException e) {
throw new MapFailedException("Compiling TYP txt file: " + e.getMessage());
} catch (FileNotFoundException e) {
throw new MapFailedException("Could not open TYP file " + filename + " to read");
}
TypParam param = data.getParam();
int family = args.get("family-id", -1);
int product = args.get("product-id", -1);
int cp = args.get("code-page", -1);
if (family != -1)
param.setFamilyId(family);
if (product != -1)
param.setProductId(product);
if (cp != -1)
param.setCodePage(cp);
File outFile = new File(filename);
String outName = outFile.getName();
int last;
if (outName.length() > 4 && (last = outName.lastIndexOf('.')) > 0)
outName = outName.substring(0, last);
outName += ".typ";
outFile = new File(args.getOutputDir(), outName);
try {
writeTyp(data, outFile);
} catch (TypLabelException e) {
throw new MapFailedException("TYP file cannot be written in code page " + data.getSort().getCodepage());
} catch (IOException e) {
throw new MapFailedException("Error while writing typ file", e);
}
return outFile.getPath();
}
use of uk.me.parabola.mkgmap.scan.SyntaxException in project mkgmap by openstreetmap.
the class ExpressionArranger method getKeystring.
/**
* Get the key string for this expression.
*
* We use a literal string such as highway=primary to index the rules. If it is not possible to find a key string,
* then the expression is not allowed. This should only happen with expression that could match an element with no
* tags.
*/
public String getKeystring(TokenScanner scanner, Op op) {
Op first = op.getFirst();
Op second = op.getSecond();
String keystring = null;
if (op.isType(EQUALS) && first.isType(FUNCTION) && second.isType(VALUE)) {
keystring = first.getKeyValue() + "=" + second.getKeyValue();
} else if (op.isType(EXISTS)) {
keystring = first.getKeyValue() + "=*";
} else if (op.isType(AND)) {
if (first.isType(EQUALS)) {
keystring = first.getFirst().getKeyValue() + "=" + first.getSecond().getKeyValue();
} else if (first.isType(EXISTS)) {
keystring = first.getFirst().getKeyValue() + "=*";
} else if (first.isType(NOT_EXISTS)) {
throw new SyntaxException(scanner, "Cannot start rule with tag!=*");
}
}
if (keystring == null)
throw new SyntaxException(scanner, "Invalid rule expression: " + op);
return keystring;
}
use of uk.me.parabola.mkgmap.scan.SyntaxException in project mkgmap by openstreetmap.
the class RuleFileReader method readFinalize.
private boolean readFinalize(TokenScanner scanner) {
Token token = scanner.nextToken();
if (scanner.checkToken("finalize")) {
Token finalizeToken = scanner.nextToken();
if (scanner.checkToken(">")) {
if (inFinalizeSection) {
// there are two finalize sections which is not allowed
throw new SyntaxException(scanner, "There is only one finalize section allowed");
} else {
// consume the > token
scanner.nextToken();
// mark start of the finalize block
inFinalizeSection = true;
finalizeRules = new RuleSet();
return true;
}
} else {
scanner.pushToken(finalizeToken);
scanner.pushToken(token);
}
} else {
scanner.pushToken(token);
}
return false;
}
Aggregations