use of uk.me.parabola.mkgmap.osmstyle.actions.Action in project mkgmap by openstreetmap.
the class ActionRule method resolveType.
public int resolveType(int cacheId, Element el, TypeResult result) {
Element element = el;
if (expression != null) {
numEval++;
if (!expression.eval(cacheId, element))
return cacheId;
numTrue++;
// There is another reason we need to copy: since there will be
if (type != null && !type.isPropogateActions() && !(element instanceof Relation)) {
element = element.copy();
}
}
// an action will be performed, so we may have to invalidate the cache
boolean invalidate_cache = false;
for (Action a : actions) {
if (a.perform(element)) {
invalidate_cache = true;
}
}
if (invalidate_cache)
cacheId++;
if (type != null && finalizeRule != null) {
if (el == element && type.isContinueSearch())
// if there is a continue statement changes performed in
// the finalize block must not be persistent
element = element.copy();
// there is a type so first execute the finalize rules
if (type.getDefaultName() != null)
element.addTag("mkgmap:default_name", type.getDefaultName());
cacheId = finalizeRule.resolveType(cacheId, element, finalizeTypeResult);
}
result.add(element, type);
return cacheId;
}
use of uk.me.parabola.mkgmap.osmstyle.actions.Action in project mkgmap by openstreetmap.
the class ActionRule method resolveType.
public void resolveType(Element el, TypeResult result) {
Element element = el;
if (expression != null) {
numEval++;
if (!expression.eval(element))
return;
numTrue++;
// There is another reason we need to copy: since there will be
if (type != null && !type.isPropogateActions() && !(element instanceof Relation)) {
element = element.copy();
}
}
for (Action a : actions) a.perform(element);
if (type != null && finalizeRule != null) {
if (el == element && type.isContinueSearch())
// if there is a continue statement changes performed in
// the finalize block must not be persistent
element = element.copy();
// there is a type so first execute the finalize rules
if (type.getDefaultName() != null)
element.addTag("mkgmap:default_name", type.getDefaultName());
finalizeRule.resolveType(element, finalizeTypeResult);
}
result.add(element, type);
}
use of uk.me.parabola.mkgmap.osmstyle.actions.Action in project mkgmap by openstreetmap.
the class RuleFileReader method readIf.
private boolean readIf(TokenScanner scanner, ExpressionReader expressionReader) {
// Take the 'if' token
Token tok = scanner.nextToken();
scanner.skipSpace();
// If 'if'' is being used as a keyword then it is followed by a '('.
Token next = scanner.peekToken();
if (next.getType() == TokType.SYMBOL && next.isValue("(")) {
Op origExpr = expressionReader.readConditions();
scanner.validateNext("then");
// add rule expr { set <ifVar> = true }
String ifVar = getNextIfVar();
ArrayList<Action> actions = new ArrayList<>(1);
actions.add(new AddTagAction(ifVar, "true", true));
ActionList actionList = new ActionList(actions, Collections.singleton(ifVar + "=true"));
saveRule(scanner, origExpr, actionList, null);
// create expression (<ifVar> = true)
EqualsOp safeExpr = new EqualsOp();
safeExpr.setFirst(new GetTagFunction(ifVar));
safeExpr.setSecond(new ValueOp("true"));
Op[] ifExpressions = { origExpr, safeExpr };
ifStack.addLast(ifExpressions);
return true;
} else {
// Wrong syntax for if statement, so push back token to allow a possible expression to be read
scanner.pushToken(tok);
}
return false;
}
Aggregations