use of uk.me.parabola.mkgmap.osmstyle.eval.ExpressionReader 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());
}
use of uk.me.parabola.mkgmap.osmstyle.eval.ExpressionReader in project mkgmap by openstreetmap.
the class ExpressionArrangerTest method createOp.
private Op createOp(String s) {
TokenScanner scanner = new TokenScanner("test.file", new StringReader(s));
ExpressionReader er = new ExpressionReader(scanner, FeatureKind.POLYLINE);
return er.readConditions();
}
use of uk.me.parabola.mkgmap.osmstyle.eval.ExpressionReader in project mkgmap by openstreetmap.
the class RulesTest method runArrangeTest.
private boolean runArrangeTest(String rule, int id) {
TokenScanner scanner = new TokenScanner("test.file", new StringReader(rule));
ExpressionReader er = new ExpressionReader(scanner, FeatureKind.POLYLINE);
Op op = er.readConditions();
boolean[] orig = evalWays(op);
Op result = arranger.arrange(op);
if (!isSolved(result))
throw new SyntaxException("Could not solve rule expression: best attempt was " + fmtExpr(result));
boolean[] after = evalWays(result);
boolean ok = Arrays.equals(after, orig);
if (ok) {
if (!onlyErrors)
System.out.println("OK: " + rule);
} else {
System.out.println("ERROR: FAILED test: " + rule);
System.out.println(" new expr: " + op);
for (int i = 0; i < orig.length; i++) {
if (orig[i] != after[i]) {
System.out.println(" way " + testWays.get(i) + ", orig=" + orig[i] + ", arranged=" + after[i]);
}
}
checkStopOnFail();
}
return ok;
}
Aggregations