use of uk.me.parabola.mkgmap.scan.WordInfo in project mkgmap by openstreetmap.
the class ExpressionReader method readConditions.
/**
* Read the conditions. They are terminated by a '[' or '{' character
* or by end of file.
* @param ifStack expressions of enclosing if / else
*/
public Op readConditions(Collection<Op[]> ifStack) {
boolean consumedNonBlank = false;
while (!scanner.isEndOfFile()) {
scanner.skipSpace();
if (scanner.checkToken("[") || scanner.checkToken("{") || scanner.checkToken("then"))
break;
consumedNonBlank = true;
WordInfo wordInfo = scanner.nextWordWithInfo();
if (isOperation(wordInfo)) {
saveOp(wordInfo.getText());
} else if (wordInfo.isQuoted()) {
pushValue(wordInfo.getText());
} else if (wordInfo.getText().charAt(0) == '$') {
String tagname = scanner.nextWord();
if (tagname.equals("{")) {
tagname = scanner.nextWord();
scanner.validateNext("}");
}
stack.push(new GetTagFunction(tagname));
} else if (scanner.checkToken("(")) {
// it is a function
// this requires a () after the function name
scanner.validateNext("(");
scanner.validateNext(")");
saveFunction(wordInfo.getText());
} else {
pushValue(wordInfo.getText());
}
}
// Complete building the tree
while (!opStack.isEmpty()) runOp(scanner);
if (consumedNonBlank && !ifStack.isEmpty() && stack.size() <= 1) {
// add expressions from enclosing if /else statements
Op op = null;
if (!stack.isEmpty())
op = stack.pop();
stack.push(appendIfExpr(op, ifStack));
}
// The stack should contain one entry which is the complete tree
if (stack.size() != 1) {
throw new SyntaxException(scanner, "Stack size is " + stack.size() + " (missing or incomplete expression)");
}
assert stack.size() == 1;
Op op = stack.pop();
if (op instanceof ValueOp)
throw new SyntaxException(scanner, "Incomplete expression, just a single symbol: " + op);
return op;
}
Aggregations