On 02/11/13 07:43, Bernhard Hiller wrote:
Steve,
thanks for the patch. I've just re-created the test map, and it works!
When will that patch be included in future releases?
Great! There are a couple of things not implemented/bugs in the first
patch which are fixed in the attached patch.
- Fix crash in some cases, when a tag was not set
- The comparison can be the only term in the expression.
The second means that you can write just
minspeed < $maxspeed
and it will be converted automatically to:
minspeed=* & minspeed < $maxspeed
There should be no difference to anything that worked with the previous
patch.
There are also some tests.
I also need to add to the documentation.
But if there are no other problems noticed I think it is now good to go.
..Steve
Index: src/uk/me/parabola/mkgmap/osmstyle/eval/NumericOp.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/uk/me/parabola/mkgmap/osmstyle/eval/NumericOp.java (revision 2795)
+++ src/uk/me/parabola/mkgmap/osmstyle/eval/NumericOp.java (revision )
@@ -49,7 +49,10 @@
return false;
ValueWithUnit result = new ValueWithUnit(val);
- ValueWithUnit ourVal = new ValueWithUnit(getSecond().value(el));
+ String val2 = getSecond().value(el);
+ if (val2 == null)
+ return false;
+ ValueWithUnit ourVal = new ValueWithUnit(val2);
if (!result.isValid() || !ourVal.isValid())
return false;
Index: src/uk/me/parabola/mkgmap/osmstyle/function/GetTagFunction.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/uk/me/parabola/mkgmap/osmstyle/function/GetTagFunction.java (revision 2795)
+++ src/uk/me/parabola/mkgmap/osmstyle/function/GetTagFunction.java (revision )
@@ -41,6 +41,6 @@
}
public String toString() {
- return getKeyValue();
+ return "$" + getKeyValue();
}
}
Index: test/resources/rules/get_tag.test
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- test/resources/rules/get_tag.test (revision )
+++ test/resources/rules/get_tag.test (revision )
@@ -0,0 +1,100 @@
+
+WAY
+highway=primary
+maxspeed=60
+
+WAY 2
+highway=primary
+maxspeed:forward=30
+
+WAY 3
+highway=primary
+maxspeed:backward=20
+
+WAY 4
+highway=primary
+maxspeed=30
+maxspeed:forward=32
+
+WAY 5
+highway=primary
+maxspeed=30
+maxspeed:forward=28
+
+WAY 6
+highway=primary
+maxspeed=30
+maxspeed:backward=32
+
+WAY 7
+highway=primary
+maxspeed=30
+maxspeed:backward=28
+
+WAY 8
+highway=primary
+maxspeed=30
+maxspeed:forward=26
+maxspeed:backward=27
+
+WAY 9
+highway=primary
+maxspeed:forward=26
+maxspeed:backward=27
+
+WAY 10
+highway=secondary
+test=2
+test1=1
+test2=2
+name=fred
+
+WAY 11
+highway=secondary
+test=2
+name=fred
+
+WAY 12
+highway=secondary
+test=2
+test1=10
+name=fred
+
+WAY 14
+highway=secondary
+test3=3
+test1=1
+name=fred
+
+<<<lines>>>
+maxspeed:forward=* & maxspeed!=* { set maxspeed='${maxspeed:forward}' }
+maxspeed:forward=* & $maxspeed:forward < $maxspeed { set maxspeed='${maxspeed:forward}' }
+maxspeed:backward=* & maxspeed!=* { set maxspeed='${maxspeed:backward}' }
+maxspeed:backward=* & (maxspeed:backward < $maxspeed) { set maxspeed='${maxspeed:backward}' }
+
+highway=primary {name '${maxspeed}' } [0x1]
+
+
+test=test1 { name 'wrong' }
+test=test2 { name 'wrong' }
+test=$test1 { name 'wrong' }
+test=$test2 { name 'ok' }
+$test1 < $test2 { set ref=A2 }
+$test1 > 4 { set ref=A4 }
+test1=* & test3 > test1 { set ref=A99}
+highway=secondary [0x2]
+
+<<<results>>>
+WAY 1: Line 0x1, name=<60>, ref=<null>, res=24-24 (1/1),(2/2),
+WAY 2: Line 0x1, name=<30>, ref=<null>, res=24-24 (1/1),(2/2),
+WAY 3: Line 0x1, name=<20>, ref=<null>, res=24-24 (1/1),(2/2),
+WAY 4: Line 0x1, name=<30>, ref=<null>, res=24-24 (1/1),(2/2),
+WAY 5: Line 0x1, name=<28>, ref=<null>, res=24-24 (1/1),(2/2),
+WAY 6: Line 0x1, name=<30>, ref=<null>, res=24-24 (1/1),(2/2),
+WAY 7: Line 0x1, name=<28>, ref=<null>, res=24-24 (1/1),(2/2),
+WAY 8: Line 0x1, name=<26>, ref=<null>, res=24-24 (1/1),(2/2),
+WAY 9: Line 0x1, name=<26>, ref=<null>, res=24-24 (1/1),(2/2),
+WAY 10: Line 0x2, name=<ok>, ref=<A2>, res=24-24 (1/1),(2/2),
+WAY 11: Line 0x2, name=<fred>, ref=<null>, res=24-24 (1/1),(2/2),
+WAY 12: Line 0x2, name=<fred>, ref=<A4>, res=24-24 (1/1),(2/2),
+WAY 14: Line 0x2, name=<fred>, ref=<A99>, res=24-24 (1/1),(2/2),
Index: src/uk/me/parabola/mkgmap/osmstyle/RuleFileReader.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/uk/me/parabola/mkgmap/osmstyle/RuleFileReader.java (revision 2795)
+++ src/uk/me/parabola/mkgmap/osmstyle/RuleFileReader.java (revision )
@@ -332,7 +332,8 @@
* Exists operation.
*/
private static boolean isIndexable(Op op) {
- return (op.isType(EQUALS) && ((ValueOp) op.getFirst()).isIndexable())
+ return (op.isType(EQUALS)
+ && ((ValueOp) op.getFirst()).isIndexable() && op.getSecond().isType(VALUE))
|| (op.isType(EXISTS) && ((ValueOp) op.getFirst()).isIndexable());
}
@@ -424,12 +425,8 @@
* An OR at the top level.
*/
String keystring;
- if (op.isType(EQUALS)) {
- if (first.isType(FUNCTION) && second.isType(VALUE)) {
+ if (op.isType(EQUALS) && (first.isType(FUNCTION) && second.isType(VALUE))) {
- keystring = first.getKeyValue() + "=" + second.getKeyValue();
+ keystring = first.getKeyValue() + "=" + second.getKeyValue();
- } else {
- throw new SyntaxException(scanner, "Invalid rule expression: " + op);
- }
} else if (op.isType(AND)) {
if (first.isType(EQUALS)) {
keystring = first.getFirst().getKeyValue() + "=" + first.getSecond().getKeyValue();
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 2795)
+++ src/uk/me/parabola/mkgmap/osmstyle/eval/ExpressionReader.java (revision )
@@ -45,9 +45,18 @@
break;
WordInfo wordInfo = scanner.nextWordWithInfo();
- if (isOperation(wordInfo))
+ if (isOperation(wordInfo)) {
saveOp(wordInfo.getText());
- else if (scanner.checkToken("(")) {
+ } 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("(");
@@ -150,7 +159,7 @@
Op arg2 = stack.pop();
Op arg1 = stack.pop();
- if (arg1.isType(VALUE) && arg2.isType(VALUE))
+ if (arg1.isType(VALUE) /*&& arg2.isType(VALUE)*/)
arg1 = new GetTagFunction(arg1.getKeyValue());
BinaryOp binaryOp = (BinaryOp) op;
Index: src/uk/me/parabola/mkgmap/osmstyle/eval/ValueOp.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/uk/me/parabola/mkgmap/osmstyle/eval/ValueOp.java (revision 2795)
+++ src/uk/me/parabola/mkgmap/osmstyle/eval/ValueOp.java (revision )
@@ -58,7 +58,7 @@
/**
* Returns true if you can index the rule from this value.
- * This should almost always return false, override in subclasses where it is the case.
+ * This should almost always return false, override in subclasses that are indexable.
*/
public boolean isIndexable() {
return false;
Index: test/uk/me/parabola/mkgmap/osmstyle/RuleFileReaderTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- test/uk/me/parabola/mkgmap/osmstyle/RuleFileReaderTest.java (revision 2795)
+++ test/uk/me/parabola/mkgmap/osmstyle/RuleFileReaderTest.java (revision )
@@ -959,6 +959,45 @@
}
/**
+ * Test the syntax to get a tag value on the RHS of the expression.
+ */
+ @Test
+ public void testGetTagValueEquality() {
+ RuleSet rs = makeRuleSet("a=b & a=$c [0x5] a=b [0x6]");
+ Way w = new Way(1);
+ w.addTag("a", "b");
+ w.addTag("c", "b");
+
+ GType type = getFirstType(rs, w);
+ assertNotNull(type);
+ assertEquals(5, type.getType());
+
+ w.addTag("c", "x");
+ type = getFirstType(rs, w);
+ assertEquals(6, type.getType());
+ }
+
+ @Test
+ public void testGetTagValueNotFound() {
+ RuleSet rs = makeRuleSet("a=b & b<$c [0x5] a=b [0x6]");
+ Way w = new Way(1);
+ w.addTag("a", "b");
+ w.addTag("b", "50");
+ GType type = getFirstType(rs, w);
+ assertEquals(6, type.getType());
+ }
+
+ @Test
+ public void testGetTagValueAlone() {
+ RuleSet rs = makeRuleSet("a<$b [0x5] a=b [0x6]");
+ Way w = new Way(1);
+ w.addTag("a", "1");
+ w.addTag("b", "2");
+ GType type = getFirstType(rs, w);
+ assertEquals(5, type.getType());
+ }
+
+ /**
* Get a way with a few points for testing length.
*
* The length of this segment was independently confirmed to be around 91m.
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://lists.mkgmap.org.uk/mailman/listinfo/mkgmap-dev