On 07/08/12 13:40, Roger Calvert wrote:
I have been unable to make this work. I have copied all the admin_level
rules from the default style files into my style, and introduced
pre-compiled bounds. Using mkgmap r2130 and Wanmil's sample rule (as
below), I always get a java exception (below). I have tried various
variants on the rule and various data sets, with no differences.
Advice welcomed!
There is probably a typo in the lines file, if you send it to me
I can probably spot it.
We can do a better error message than that though. Attached is a
patch which should print the line number of the problem and make it
a lot easier to find.
..Steve
Index: src/uk/me/parabola/mkgmap/osmstyle/eval/ExpressionReader.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/uk/me/parabola/mkgmap/osmstyle/eval/ExpressionReader.java (revision 2311)
+++ src/uk/me/parabola/mkgmap/osmstyle/eval/ExpressionReader.java (revision )
@@ -46,7 +46,7 @@
// Complete building the tree
while (!opStack.isEmpty())
- runOp();
+ runOp(scanner);
// The stack should contain one entry which is the complete tree
if (stack.size() != 1)
@@ -104,7 +104,7 @@
try {
op = createOp(value);
while (!opStack.isEmpty() && opStack.peek().hasHigherPriority(op))
- runOp();
+ runOp(scanner);
} catch (SyntaxException e) {
throw new SyntaxException(scanner, e.getRawMessage());
}
@@ -121,12 +121,17 @@
/**
* Combine the operation at the top of its stack with its values.
+ * @param scanner The token scanner; used for line numbers.
*/
- private void runOp() {
+ private void runOp(TokenScanner scanner) {
Op op = opStack.pop();
log.debug("Running op...", op.getType());
if (op instanceof BinaryOp) {
+ if (stack.size() < 2)
+ throw new SyntaxException(scanner, String.format("Not enough arguments for '%s' operator",
+ op.getType()));
+
Op arg2 = stack.pop();
Op arg1 = stack.pop();
BinaryOp binaryOp = (BinaryOp) op;
@@ -144,8 +149,13 @@
op.setFirst(arg1);
}
} else if (!op.isType(OPEN_PAREN)) {
+ if (stack.size() < 1)
+ throw new SyntaxException(scanner, String.format("Missing argument for %s operator", op.getType()));
op.setFirst(stack.pop());
}
+
+ if (op.getFirst() == null)
+ throw new SyntaxException(scanner, "Invalid expression");
if (op.getFirst().isType(VALUE))
usedTags.add(op.getFirst().value());
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev