use of uk.me.parabola.mkgmap.scan.SyntaxException 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.scan.SyntaxException in project mkgmap by openstreetmap.
the class RuleFileReader method saveRule.
/**
* Save the expression as a rule. We need to extract an index such
* as highway=primary first and then add the rest of the expression as
* the condition for it.
*
* So in other words each condition is dropped into a number of different
* baskets based on the first 'tag=value' term. We then only look
* for expressions that are in the correct basket. For each expression
* in a basket we know that the first term is true so we can drop that
* from the expression.
*/
private void saveRule(TokenScanner scanner, Op op, ActionList actions, GType gt) {
log.debug("EXP", op, ", type=", gt);
// check if the type definition is allowed
if (inFinalizeSection && gt != null)
throw new SyntaxException(scanner, "Element type definition is not allowed in <finalize> section");
Iterator<Op> it = arranger.prepareForSave(op);
while (it.hasNext()) {
Op prepared = it.next();
String keystring = arranger.getKeystring(scanner, prepared);
createAndSaveRule(keystring, prepared, actions, gt);
}
}
use of uk.me.parabola.mkgmap.scan.SyntaxException in project mkgmap by openstreetmap.
the class LengthFunction method calcLength.
private double calcLength(Element el) {
if (el instanceof Way) {
Way w = (Way) el;
double length = 0;
Coord prevC = null;
for (Coord c : w.getPoints()) {
if (prevC != null) {
length += prevC.distance(c);
}
prevC = c;
}
return length;
} else if (el instanceof Relation) {
Relation rel = (Relation) el;
double length = 0;
for (Entry<String, Element> relElem : rel.getElements()) {
if (relElem.getValue() instanceof Way || relElem.getValue() instanceof Relation) {
if (rel == relElem.getValue()) {
// avoid recursive call
log.error("Relation " + rel.getId() + " contains itself as element. This is not supported.");
} else {
length += calcLength(relElem.getValue());
}
}
}
return length;
} else {
throw new SyntaxException("length() cannot calculate elements of type " + el.getClass().getName());
}
}
use of uk.me.parabola.mkgmap.scan.SyntaxException in project mkgmap by openstreetmap.
the class ActionReader method readAllCmd.
private Action readAllCmd(boolean once) {
String role = null;
if (scanner.checkToken("role")) {
scanner.nextToken();
String eq = scanner.nextValue();
if (!"=".equals(eq))
throw new SyntaxException(scanner, "Expecting '=' after role keyword");
role = scanner.nextWord();
}
SubAction subAction = new SubAction(role, once);
List<Action> actionList = readActions().getList();
for (Action a : actionList) subAction.add(a);
return subAction;
}
use of uk.me.parabola.mkgmap.scan.SyntaxException in project mkgmap by openstreetmap.
the class ActionReader method readValueBuilder.
/**
* A name command has a number of alternatives separated by '|' characters.
*/
private Action readValueBuilder(ValueBuildedAction action) {
do {
if (!inActionCmd())
throw new SyntaxException(scanner, "unexpected end of add/set list");
String val = scanner.nextWord();
action.add(val);
} while (hasMoreWords());
usedTags.addAll(action.getUsedTags());
return action;
}
Aggregations