diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2011-02-01 02:03:53 +0100 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2011-02-01 02:03:53 +0100 |
commit | b5d337df5ff322ff09ed4083777473f2bffa3e1d (patch) | |
tree | b444fac9e0a5ada755034823270a2d834011a15b /src/nodejs/alternative/testgrammar | |
parent | 710407ad022b919c78659a3d30c7ce695eea9560 (diff) | |
parent | 46956a6a4079917bca0d5a22497116caa82386db (diff) | |
download | osm-xapi-b5d337df5ff322ff09ed4083777473f2bffa3e1d.tar.gz osm-xapi-b5d337df5ff322ff09ed4083777473f2bffa3e1d.tar.xz osm-xapi-b5d337df5ff322ff09ed4083777473f2bffa3e1d.zip |
Merge remote branch 'upstream/master'
Diffstat (limited to '')
-rw-r--r-- | src/nodejs/alternative/testgrammar | 28 |
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} |