aboutsummaryrefslogtreecommitdiffstats
path: root/src/nodejs/alternative/testgrammar
diff options
context:
space:
mode:
authorslomo <steve.harrison@gmx.net>2011-04-17 21:33:42 +0200
committerslomo <steve.harrison@gmx.net>2011-04-17 21:33:42 +0200
commitffa69485eaaad5283162dd90b19fd284bc9f87ca (patch)
treecd89f170bf433c4cb77785fc46c5370f9195e24b /src/nodejs/alternative/testgrammar
parentbfbc478c5ec2e07d5047ae020361bedfa4e5f4c6 (diff)
parent9a62f0c465cb1250e5f1ec825aed12a0792291de (diff)
downloadosm-xapi-ffa69485eaaad5283162dd90b19fd284bc9f87ca.tar.gz
osm-xapi-ffa69485eaaad5283162dd90b19fd284bc9f87ca.tar.xz
osm-xapi-ffa69485eaaad5283162dd90b19fd284bc9f87ca.zip
Merge branch 'master' of github.com:slomo/osm-spline-xapi
Diffstat (limited to 'src/nodejs/alternative/testgrammar')
-rw-r--r--src/nodejs/alternative/testgrammar28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/nodejs/alternative/testgrammar b/src/nodejs/alternative/testgrammar
new file mode 100644
index 0000000..0e43013
--- /dev/null
+++ b/src/nodejs/alternative/testgrammar
@@ -0,0 +1,28 @@
+/*
+ * Classic example grammar, which recognizes simple arithmetic expressions like
+ * "2*(3+4)". The parser generated from this grammar then computes their value.
+ */
+
+url = object:object p1:predicate p2:predicate { var result = {object:object}; if(p1.tags != undefined) {result.tags= p1.tags} else if(p1.bbox != undefined) {result.bbox=p1.bbox;} if(p2.tags != undefined) {result.tags= p2.tags} else if(p2.bbox != undefined) {result.bbox=p2.bbox;} return result;}/ object:object p:predicate {var result={}; result.object=object; if(p.tags != undefined) {result.tags=p.tags} else {result.bbox=p.bbox} return result} / object:object { return {object:object}}
+
+object = v:"node" {return v} / v:"way" {return v} / v:"relation" {return v} / v:"*" {return v}
+
+
+
+predicate = bboxpredicate / v:tagpredicate {return {tags:v}}/ childpredicate
+
+tagpredicate = "["keys:keys"="values:values"]" {return {keys:keys, values:values}}
+
+childpredicate = "not(nd)"
+bboxpredicate = "[bbox=" left:float "," top:float","right:float","bottom:float"]" { return {bbox:{left:left,top:top,right:right,bottom:bottom}}}
+
+keys = key:key keys:("|" keys)+ { var result = new Array(); result.push(key); return result.concat(keys[0][1])} / key:key { var result = new Array(); result.push(key); return result}
+
+values = value:value values:("|" values)+ { var result = new Array(); result.push(value); return result.concat(values[0][1])} / value:value { var result = new Array(); result.push(value); return result}
+
+key = key:letter+ {return key.join("")}
+value = value:letter+ {return value.join("")}
+letter = "\\*" {return "*"} / "\\[" {return "["} / "\\]" {return "]" } / "\\\\" {return "\\"} / "\\|" {return "|" } / [^*|=\\\][]
+
+//add negative values
+float = m:"-"?digits:[0-9]+"."digits2:[0-9]+ { result = parseInt(digits.join(""))+parseFloat("0."+digits2.join("")); if(m == "-") {result=result*-1}; return result} / m:"-"?digits:[0-9]+ { result = parseInt(digits.join("")); if(m == "-") {result = result*-1}; return result}