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");
}
}
}
}
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;
}
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));
}
}
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;
}
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;
}
Aggregations