diff options
Diffstat (limited to '')
-rw-r--r-- | README | 46 | ||||
-rw-r--r-- | doc/cc.png | bin | 0 -> 10135 bytes | |||
-rw-r--r-- | doc/introduction.tex | 153 | ||||
-rw-r--r-- | src/nodejs/alternative/parser.js | 1174 | ||||
-rw-r--r-- | src/nodejs/alternative/testgrammar | 28 | ||||
-rw-r--r-- | src/nodejs/main.js | 67 | ||||
-rw-r--r-- | src/nodejs/tests/async_basis_test.js | 2 | ||||
m--------- | src/nodejs/tests/node-async-testing | 0 | ||||
-rw-r--r-- | src/nodejs/tests/pathparsing.js | 4 |
9 files changed, 1401 insertions, 73 deletions
@@ -5,7 +5,7 @@ osm@spline Xapi Contact ============ http://osm.spline.de -mailing list: osm@lists.spline.de +mailing list: osm@lists.spline.de or xapi@lists.spline.de irc: irc://irc.freenode.net/#spline Aim @@ -40,10 +40,18 @@ your local directory. If you don't trust us read the bootstrap.sh. If you have node and npm installed you can just use "npm link src/nodejs/" to install all the dependencies. +Dependencies +============= + +For dependencies checkout the package.json file. One special case is the node-postgres +lib. Use a patched version: https://github.com/AlexanderS/node-postgres + +If you try the libxml branch make sure you have installed libxml for developers. + Database setup ============= -We use postgres 9.* with postgis 1.5. Postgres 9.0 is used becaus we need some +We use postgres 9.* with postgis 1.5. Postgres 9.0 is used because we need some functions on hstores and postgis 1.5 is used for fancy geometry things. To setup a database you first need a runing postgres 9.0 instance. I hope you know @@ -90,40 +98,8 @@ Import data from xml with: osmosis --read-xml file="planet.osm.bz2" --wp host="localhost" password="TopSecretPassword" user="insertUserNameHere" database="osm" -Before or after import you may want to create a index or two. Examples below: +Before or after import you may want to create a indexes. Examples below: CREATE INDEX idx_nodes_tags ON nodes USING GIN(tags); CREATE INDEX idx_nodes_tags ON nodes USING GIST(tags); CREATE INDEX idx_ways_tags ON ways USING GIN(tags); CREATE INDEX idx_ways_tags ON ways USING GIST(tags); - -database shema (out dated) -================ - -We keep data in a highly specioaliced shema, that allows us to prevent tables -growing to big. And supports our requests at maximum speed. - -| CREATE TABLE <tagname>:<tagvalue> ( -| {bigint id} -| {longitude float4}, -| {latitude float4}, -| {object varchar} -| ) PRIMARY KEY id; - -Implmentation -============= - -Teilprobleme: -.............. - -1. Database import - -mögliche Technologien: -* Osmosis- plugin -* selbst in python (Protobuf consumer, async pgsql schreiber) - - -2. Web API -.............. - -mögliche Technologien: -* node.js diff --git a/doc/cc.png b/doc/cc.png Binary files differnew file mode 100644 index 0000000..d181cc0 --- /dev/null +++ b/doc/cc.png diff --git a/doc/introduction.tex b/doc/introduction.tex new file mode 100644 index 0000000..51487b5 --- /dev/null +++ b/doc/introduction.tex @@ -0,0 +1,153 @@ +\documentclass{beamer} +%packages +\usepackage[latin1]{inputenc} +\usepackage{minted} +\usepackage{graphicx} +\usepackage{hyperref} +\hypersetup{urlcolor=red,colorlinks} +\definecolor{bg}{rgb}{0.95,0.95,0.95} +\newminted{xml}{fontsize=\tiny} +\usetheme{Warsaw} +\title[OSM-Projekt - What is...]{OSM-Projekt - An introduction into OpenStreetMap} +\author{Philipp Borgers} +\institute{Institute for Computer Science, Free University Berlin} +\date{15.4.2011} +\begin{document} +\begin{frame} +\titlepage +\end{frame} + +\begin{frame}{Introduction} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Community} + \begin{itemize} + \item \href{http://wiki.openstreetmap.org/wiki/Develop}{Developer wikipage} + \item \href{http://lists.openstreetmap.org/listinfo}{Mailinglists (dev@lists...)} + \item \href{irc://irc.oftc.net/#osm-dev}{\#osm-dev} + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{data types - node} + \begin{itemize} + \item Id, Longitude, Latitude + \item Set of key/value pairs (tags) + \end{itemize} + \begin{xmlcode} + <node id="23" lat="51.5173639" lon="-0.140043" version="1" changeset="42" user="h4ck3r" + uid="23" visible="true" timestamp="2007-01-28T11:40:26Z"> + <tag k="name" v="h4ck3rs h0m3"/> + </node> + \end{xmlcode} +\end{frame} + +\begin{frame}[fragile] + \frametitle{data types - way} + \begin{itemize} + \item Id and common attributes + \item List of all node id's that make up the way + \item Last node == first node (optional, closed way) + \item A set of key/value pairs (tags) + \end{itemize} + \begin{xmlcode} + <way id="42" visible="true" timestamp="2009-01-19T19:07:25Z" version="42" changeset="2342" + user="h4ck3r" uid="23"> + <nd ref="1"/> + <nd ref="2"/> + <nd ref="3"/> + <nd ref="1"/> + <tag k="oneway" v="yes"/> + </way> + \end{xmlcode} +\end{frame} + +\begin{frame}[fragile] + \frametitle{data types - relation} + \begin{itemize} + \item Id and common attributes + \item A set of key/value pairs (tags) + \item An ordered list of primitives (members) with associated role attribute + \item A member consists of a type (node, way, relation), Id and a role attribute + \end{itemize} + \begin{xmlcode} + <relation id="23" timestamp="2008-12-21T19:31:43Z" user="h4ck3r" uid="42"> + <member type="way" ref="2332" role="whatever"/> + <member type="node" ref="43" role="asdf"/> + <member type="relation" ref="1234" role="l33t"/> + <member type="way" ref="5678" role=""/> + <tag k="name" v="sample relation"/> + </relation> + \end{xmlcode} +\end{frame} +\begin{frame}[fragile] + \frametitle{data types - tag} + \begin{itemize} + \item A key/value pair + \item They are everywhere, you can't hide + \end{itemize} + \begin{xmlcode} + <tag k="name" v="Institut fuer Informatik"/> + \end{xmlcode} +\end{frame} +\begin{frame}[fragile] + \frametitle{data types - more on data types and elements} + \begin{itemize} + \item \href{http://wiki.openstreetmap.org/wiki/Data_Primitives}{Data primitives} + \item \href{http://wiki.openstreetmap.org/wiki/Elements}{OSM elements} + \item \href{http://wiki.openstreetmap.org/wiki/API\_v0.6}{OSM API 0.6} + \end{itemize} +\end{frame} +\begin{frame}[fragile] + \frametitle{database - overview} + \begin{itemize} + \item bla + \end{itemize} +\end{frame} +\begin{frame}[fragile] + \frametitle{XAPI} + \begin{itemize} + \item Database frontend to retrieve node, ways and relations + \item XPATH like requests + \item Returns xml (osm xml schema) + \item \href{http://wiki.openstreetmap.org/wiki/Xapi}{Wiki page} + \end{itemize} +\end{frame} +\begin{frame}[fragile] + \frametitle{XAPI - Request format} + \begin{itemize} + \item api/0.6/node[predicate] + \item api/0.6/way[-6,50,2,61] + \item api/0.6/relation[name=U3] + \item api/0.6/*[-6,50,2,61][name=U3|U4|U5] + \item api/0.6/*[name=*] + \item api/0.6/node[amenity|leisure=golf\_curse] + \end{itemize} +\end{frame} +\begin{frame}[fragile] + \frametitle{XAPI - Implementations} + \begin{itemize} + \item \href{http://xapi.openstreetmap.org/scripts/}{G.TM implementation} + \item \href{https://github.com/iandees/xapi-servlet}{Java implementation} + \end{itemize} +\end{frame} + + +\begin{frame}[fragile] + \frametitle{Licence} + \begin{center} + \includegraphics[scale=0.25]{./cc.png} + \end{center} + \begin{center} + \href{http://creativecommons.org/licenses/by/3.0/}{Attribution 3.0 Unported (CC BY 3.0)} + \end{center} +\end{frame} + + + + + + + +\end{document} diff --git a/src/nodejs/alternative/parser.js b/src/nodejs/alternative/parser.js new file mode 100644 index 0000000..d388471 --- /dev/null +++ b/src/nodejs/alternative/parser.js @@ -0,0 +1,1174 @@ +exports.parser = parser = (function(){ + /* Generated by PEG.js (http://pegjs.majda.cz/). */ + + var result = { + /* + * Parses the input with a generated parser. If the parsing is successfull, + * returns a value explicitly or implicitly specified by the grammar from + * which the parser was generated (see |PEG.buildParser|). If the parsing is + * unsuccessful, throws |PEG.grammarParser.SyntaxError| describing the error. + */ + parse: function(input) { + var pos = 0; + var rightmostMatchFailuresPos = 0; + var rightmostMatchFailuresExpected = []; + var cache = {}; + + function padLeft(input, padding, length) { + var result = input; + + var padLength = length - input.length; + for (var i = 0; i < padLength; i++) { + result = padding + result; + } + + return result; + } + + function escape(ch) { + var charCode = ch.charCodeAt(0); + + if (charCode <= 0xFF) { + var escapeChar = 'x'; + var length = 2; + } else { + var escapeChar = 'u'; + var length = 4; + } + + return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length); + } + + function quoteString(s) { + /* + * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a + * string literal except for the closing quote character, backslash, + * carriage return, line separator, paragraph separator, and line feed. + * Any character may appear in the form of an escape sequence. + */ + return '"' + s + .replace(/\\/g, '\\\\') // backslash + .replace(/"/g, '\\"') // closing quote character + .replace(/\r/g, '\\r') // carriage return + .replace(/\u2028/g, '\\u2028') // line separator + .replace(/\u2029/g, '\\u2029') // paragraph separator + .replace(/\n/g, '\\n') // line feed + .replace(/[\x80-\uFFFF]/g, escape) // non-ASCII characters + + '"'; + } + + function arrayContains(array, value) { + /* + * Stupid IE does not have Array.prototype.indexOf, otherwise this + * function would be a one-liner. + */ + var length = array.length; + for (var i = 0; i < length; i++) { + if (array[i] === value) { + return true; + } + } + return false; + } + + function matchFailed(failure) { + if (pos < rightmostMatchFailuresPos) { + return; + } + + if (pos > rightmostMatchFailuresPos) { + rightmostMatchFailuresPos = pos; + rightmostMatchFailuresExpected = []; + } + + if (!arrayContains(rightmostMatchFailuresExpected, failure)) { + rightmostMatchFailuresExpected.push(failure); + } + } + + function parse_url(context) { + var cacheKey = "url" + '@' + pos; + var cachedResult = cache[cacheKey]; + if (cachedResult) { + pos = cachedResult.nextPos; + return cachedResult.result; + } + + + var savedPos1 = pos; + var result9 = parse_object(context); + if (result9 !== null) { + var result10 = parse_predicate(context); + if (result10 !== null) { + var result11 = parse_predicate(context); + if (result11 !== null) { + var result8 = [result9, result10, result11]; + } else { + var result8 = null; + pos = savedPos1; + } + } else { + var result8 = null; + pos = savedPos1; + } + } else { + var result8 = null; + pos = savedPos1; + } + var result7 = result8 !== null + ? (function(object, p1, p2) { 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;})(result8[0], result8[1], result8[2]) + : null; + if (result7 !== null) { + var result0 = result7; + } else { + var savedPos0 = pos; + var result5 = parse_object(context); + if (result5 !== null) { + var result6 = parse_predicate(context); + if (result6 !== null) { + var result4 = [result5, result6]; + } else { + var result4 = null; + pos = savedPos0; + } + } else { + var result4 = null; + pos = savedPos0; + } + var result3 = result4 !== null + ? (function(object, p) {var result={}; result.object=object; if(p.tags != undefined) {result.tags=p.tags} else {result.bbox=p.bbox} return result})(result4[0], result4[1]) + : null; + if (result3 !== null) { + var result0 = result3; + } else { + var result2 = parse_object(context); + var result1 = result2 !== null + ? (function(object) { return {object:object}})(result2) + : null; + if (result1 !== null) { + var result0 = result1; + } else { + var result0 = null;; + }; + }; + } + + + + cache[cacheKey] = { + nextPos: pos, + result: result0 + }; + return result0; + } + + function parse_object(context) { + var cacheKey = "object" + '@' + pos; + var cachedResult = cache[cacheKey]; + if (cachedResult) { + pos = cachedResult.nextPos; + return cachedResult.result; + } + + + if (input.substr(pos, 4) === "node") { + var result8 = "node"; + pos += 4; + } else { + var result8 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString("node")); + } + } + var result7 = result8 !== null + ? (function(v) {return v})(result8) + : null; + if (result7 !== null) { + var result0 = result7; + } else { + if (input.substr(pos, 3) === "way") { + var result6 = "way"; + pos += 3; + } else { + var result6 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString("way")); + } + } + var result5 = result6 !== null + ? (function(v) {return v})(result6) + : null; + if (result5 !== null) { + var result0 = result5; + } else { + if (input.substr(pos, 8) === "relation") { + var result4 = "relation"; + pos += 8; + } else { + var result4 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString("relation")); + } + } + var result3 = result4 !== null + ? (function(v) {return v})(result4) + : null; + if (result3 !== null) { + var result0 = result3; + } else { + if (input.substr(pos, 1) === "*") { + var result2 = "*"; + pos += 1; + } else { + var result2 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString("*")); + } + } + var result1 = result2 !== null + ? (function(v) {return v})(result2) + : null; + if (result1 !== null) { + var result0 = result1; + } else { + var result0 = null;; + }; + }; + }; + } + + + + cache[cacheKey] = { + nextPos: pos, + result: result0 + }; + return result0; + } + + function parse_predicate(context) { + var cacheKey = "predicate" + '@' + pos; + var cachedResult = cache[cacheKey]; + if (cachedResult) { + pos = cachedResult.nextPos; + return cachedResult.result; + } + + + var result4 = parse_bboxpredicate(context); + if (result4 !== null) { + var result0 = result4; + } else { + var result3 = parse_tagpredicate(context); + var result2 = result3 !== null + ? (function(v) {return {tags:v}})(result3) + : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result1 = parse_childpredicate(context); + if (result1 !== null) { + var result0 = result1; + } else { + var result0 = null;; + }; + }; + } + + + + cache[cacheKey] = { + nextPos: pos, + result: result0 + }; + return result0; + } + + function parse_tagpredicate(context) { + var cacheKey = "tagpredicate" + '@' + pos; + var cachedResult = cache[cacheKey]; + if (cachedResult) { + pos = cachedResult.nextPos; + return cachedResult.result; + } + + + var savedPos0 = pos; + if (input.substr(pos, 1) === "[") { + var result2 = "["; + pos += 1; + } else { + var result2 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString("[")); + } + } + if (result2 !== null) { + var result3 = parse_keys(context); + if (result3 !== null) { + if (input.substr(pos, 1) === "=") { + var result4 = "="; + pos += 1; + } else { + var result4 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString("=")); + } + } + if (result4 !== null) { + var result5 = parse_values(context); + if (result5 !== null) { + if (input.substr(pos, 1) === "]") { + var result6 = "]"; + pos += 1; + } else { + var result6 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString("]")); + } + } + if (result6 !== null) { + var result1 = [result2, result3, result4, result5, result6]; + } else { + var result1 = null; + pos = savedPos0; + } + } else { + var result1 = null; + pos = savedPos0; + } + } else { + var result1 = null; + pos = savedPos0; + } + } else { + var result1 = null; + pos = savedPos0; + } + } else { + var result1 = null; + pos = savedPos0; + } + var result0 = result1 !== null + ? (function(keys, values) {return {keys:keys, values:values}})(result1[1], result1[3]) + : null; + + + + cache[cacheKey] = { + nextPos: pos, + result: result0 + }; + return result0; + } + + function parse_childpredicate(context) { + var cacheKey = "childpredicate" + '@' + pos; + var cachedResult = cache[cacheKey]; + if (cachedResult) { + pos = cachedResult.nextPos; + return cachedResult.result; + } + + + if (input.substr(pos, 7) === "not(nd)") { + var result0 = "not(nd)"; + pos += 7; + } else { + var result0 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString("not(nd)")); + } + } + + + + cache[cacheKey] = { + nextPos: pos, + result: result0 + }; + return result0; + } + + function parse_bboxpredicate(context) { + var cacheKey = "bboxpredicate" + '@' + pos; + var cachedResult = cache[cacheKey]; + if (cachedResult) { + pos = cachedResult.nextPos; + return cachedResult.result; + } + + + var savedPos0 = pos; + if (input.substr(pos, 6) === "[bbox=") { + var result2 = "[bbox="; + pos += 6; + } else { + var result2 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString("[bbox=")); + } + } + if (result2 !== null) { + var result3 = parse_float(context); + if (result3 !== null) { + if (input.substr(pos, 1) === ",") { + var result4 = ","; + pos += 1; + } else { + var result4 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString(",")); + } + } + if (result4 !== null) { + var result5 = parse_float(context); + if (result5 !== null) { + if (input.substr(pos, 1) === ",") { + var result6 = ","; + pos += 1; + } else { + var result6 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString(",")); + } + } + if (result6 !== null) { + var result7 = parse_float(context); + if (result7 !== null) { + if (input.substr(pos, 1) === ",") { + var result8 = ","; + pos += 1; + } else { + var result8 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString(",")); + } + } + if (result8 !== null) { + var result9 = parse_float(context); + if (result9 !== null) { + if (input.substr(pos, 1) === "]") { + var result10 = "]"; + pos += 1; + } else { + var result10 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString("]")); + } + } + if (result10 !== null) { + var result1 = [result2, result3, result4, result5, result6, result7, result8, result9, result10]; + } else { + var result1 = null; + pos = savedPos0; + } + } else { + var result1 = null; + pos = savedPos0; + } + } else { + var result1 = null; + pos = savedPos0; + } + } else { + var result1 = null; + pos = savedPos0; + } + } else { + var result1 = null; + pos = savedPos0; + } + } else { + var result1 = null; + pos = savedPos0; + } + } else { + var result1 = null; + pos = savedPos0; + } + } else { + var result1 = null; + pos = savedPos0; + } + } else { + var result1 = null; + pos = savedPos0; + } + var result0 = result1 !== null + ? (function(left, top, right, bottom) { return {bbox:{left:left,top:top,right:right,bottom:bottom}}})(result1[1], result1[3], result1[5], result1[7]) + : null; + + + + cache[cacheKey] = { + nextPos: pos, + result: result0 + }; + return result0; + } + + function parse_keys(context) { + var cacheKey = "keys" + '@' + pos; + var cachedResult = cache[cacheKey]; + if (cachedResult) { + pos = cachedResult.nextPos; + return cachedResult.result; + } + + + var savedPos0 = pos; + var result5 = parse_key(context); + if (result5 !== null) { + var savedPos1 = pos; + if (input.substr(pos, 1) === "|") { + var result8 = "|"; + pos += 1; + } else { + var result8 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString("|")); + } + } + if (result8 !== null) { + var result9 = parse_keys(context); + if (result9 !== null) { + var result7 = [result8, result9]; + } else { + var result7 = null; + pos = savedPos1; + } + } else { + var result7 = null; + pos = savedPos1; + } + if (result7 !== null) { + var result6 = []; + while (result7 !== null) { + result6.push(result7); + var savedPos1 = pos; + if (input.substr(pos, 1) === "|") { + var result8 = "|"; + pos += 1; + } else { + var result8 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString("|")); + } + } + if (result8 !== null) { + var result9 = parse_keys(context); + if (result9 !== null) { + var result7 = [result8, result9]; + } else { + var result7 = null; + pos = savedPos1; + } + } else { + var result7 = null; + pos = savedPos1; + } + } + } else { + var result6 = null; + } + if (result6 !== null) { + var result4 = [result5, result6]; + } else { + var result4 = null; + pos = savedPos0; + } + } else { + var result4 = null; + pos = savedPos0; + } + var result3 = result4 !== null + ? (function(key, keys) { var result = new Array(); result.push(key); return result.concat(keys[0][1])})(result4[0], result4[1]) + : null; + if (result3 !== null) { + var result0 = result3; + } else { + var result2 = parse_key(context); + var result1 = result2 !== null + ? (function(key) { var result = new Array(); result.push(key); return result})(result2) + : null; + if (result1 !== null) { + var result0 = result1; + } else { + var result0 = null;; + }; + } + + + + cache[cacheKey] = { + nextPos: pos, + result: result0 + }; + return result0; + } + + function parse_values(context) { + var cacheKey = "values" + '@' + pos; + var cachedResult = cache[cacheKey]; + if (cachedResult) { + pos = cachedResult.nextPos; + return cachedResult.result; + } + + + var savedPos0 = pos; + var result5 = parse_value(context); + if (result5 !== null) { + var savedPos1 = pos; + if (input.substr(pos, 1) === "|") { + var result8 = "|"; + pos += 1; + } else { + var result8 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString("|")); + } + } + if (result8 !== null) { + var result9 = parse_values(context); + if (result9 !== null) { + var result7 = [result8, result9]; + } else { + var result7 = null; + pos = savedPos1; + } + } else { + var result7 = null; + pos = savedPos1; + } + if (result7 !== null) { + var result6 = []; + while (result7 !== null) { + result6.push(result7); + var savedPos1 = pos; + if (input.substr(pos, 1) === "|") { + var result8 = "|"; + pos += 1; + } else { + var result8 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString("|")); + } + } + if (result8 !== null) { + var result9 = parse_values(context); + if (result9 !== null) { + var result7 = [result8, result9]; + } else { + var result7 = null; + pos = savedPos1; + } + } else { + var result7 = null; + pos = savedPos1; + } + } + } else { + var result6 = null; + } + if (result6 !== null) { + var result4 = [result5, result6]; + } else { + var result4 = null; + pos = savedPos0; + } + } else { + var result4 = null; + pos = savedPos0; + } + var result3 = result4 !== null + ? (function(value, values) { var result = new Array(); result.push(value); return result.concat(values[0][1])})(result4[0], result4[1]) + : null; + if (result3 !== null) { + var result0 = result3; + } else { + var result2 = parse_value(context); + var result1 = result2 !== null + ? (function(value) { var result = new Array(); result.push(value); return result})(result2) + : null; + if (result1 !== null) { + var result0 = result1; + } else { + var result0 = null;; + }; + } + + + + cache[cacheKey] = { + nextPos: pos, + result: result0 + }; + return result0; + } + + function parse_key(context) { + var cacheKey = "key" + '@' + pos; + var cachedResult = cache[cacheKey]; + if (cachedResult) { + pos = cachedResult.nextPos; + return cachedResult.result; + } + + + var result2 = parse_letter(context); + if (result2 !== null) { + var result1 = []; + while (result2 !== null) { + result1.push(result2); + var result2 = parse_letter(context); + } + } else { + var result1 = null; + } + var result0 = result1 !== null + ? (function(key) {return key.join("")})(result1) + : null; + + + + cache[cacheKey] = { + nextPos: pos, + result: result0 + }; + return result0; + } + + function parse_value(context) { + var cacheKey = "value" + '@' + pos; + var cachedResult = cache[cacheKey]; + if (cachedResult) { + pos = cachedResult.nextPos; + return cachedResult.result; + } + + + var result2 = parse_letter(context); + if (result2 !== null) { + var result1 = []; + while (result2 !== null) { + result1.push(result2); + var result2 = parse_letter(context); + } + } else { + var result1 = null; + } + var result0 = result1 !== null + ? (function(value) {return value.join("")})(result1) + : null; + + + + cache[cacheKey] = { + nextPos: pos, + result: result0 + }; + return result0; + } + + function parse_letter(context) { + var cacheKey = "letter" + '@' + pos; + var cachedResult = cache[cacheKey]; + if (cachedResult) { + pos = cachedResult.nextPos; + return cachedResult.result; + } + + + if (input.substr(pos, 2) === "\\*") { + var result11 = "\\*"; + pos += 2; + } else { + var result11 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString("\\*")); + } + } + var result10 = result11 !== null + ? (function() {return "*"})() + : null; + if (result10 !== null) { + var result0 = result10; + } else { + if (input.substr(pos, 2) === "\\[") { + var result9 = "\\["; + pos += 2; + } else { + var result9 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString("\\[")); + } + } + var result8 = result9 !== null + ? (function() {return "["})() + : null; + if (result8 !== null) { + var result0 = result8; + } else { + if (input.substr(pos, 2) === "\\]") { + var result7 = "\\]"; + pos += 2; + } else { + var result7 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString("\\]")); + } + } + var result6 = result7 !== null + ? (function() {return "]" })() + : null; + if (result6 !== null) { + var result0 = result6; + } else { + if (input.substr(pos, 2) === "\\\\") { + var result5 = "\\\\"; + pos += 2; + } else { + var result5 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString("\\\\")); + } + } + var result4 = result5 !== null + ? (function() {return "\\"})() + : null; + if (result4 !== null) { + var result0 = result4; + } else { + if (input.substr(pos, 2) === "\\|") { + var result3 = "\\|"; + pos += 2; + } else { + var result3 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString("\\|")); + } + } + var result2 = result3 !== null + ? (function() {return "|" })() + : null; + if (result2 !== null) { + var result0 = result2; + } else { + if (input.substr(pos).match(/^[^*|=\\\][]/) !== null) { + var result1 = input.charAt(pos); + pos++; + } else { + var result1 = null; + if (context.reportMatchFailures) { + matchFailed("[^*|=\\\\\\][]"); + } + } + if (result1 !== null) { + var result0 = result1; + } else { + var result0 = null;; + }; + }; + }; + }; + }; + } + + + + cache[cacheKey] = { + nextPos: pos, + result: result0 + }; + return result0; + } + + function parse_float(context) { + var cacheKey = "float" + '@' + pos; + var cachedResult = cache[cacheKey]; + if (cachedResult) { + pos = cachedResult.nextPos; + return cachedResult.result; + } + + + var savedPos1 = pos; + if (input.substr(pos, 1) === "-") { + var result15 = "-"; + pos += 1; + } else { + var result15 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString("-")); + } + } + var result9 = result15 !== null ? result15 : ''; + if (result9 !== null) { + if (input.substr(pos).match(/^[0-9]/) !== null) { + var result14 = input.charAt(pos); + pos++; + } else { + var result14 = null; + if (context.reportMatchFailures) { + matchFailed("[0-9]"); + } + } + if (result14 !== null) { + var result10 = []; + while (result14 !== null) { + result10.push(result14); + if (input.substr(pos).match(/^[0-9]/) !== null) { + var result14 = input.charAt(pos); + pos++; + } else { + var result14 = null; + if (context.reportMatchFailures) { + matchFailed("[0-9]"); + } + } + } + } else { + var result10 = null; + } + if (result10 !== null) { + if (input.substr(pos, 1) === ".") { + var result11 = "."; + pos += 1; + } else { + var result11 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString(".")); + } + } + if (result11 !== null) { + if (input.substr(pos).match(/^[0-9]/) !== null) { + var result13 = input.charAt(pos); + pos++; + } else { + var result13 = null; + if (context.reportMatchFailures) { + matchFailed("[0-9]"); + } + } + if (result13 !== null) { + var result12 = []; + while (result13 !== null) { + result12.push(result13); + if (input.substr(pos).match(/^[0-9]/) !== null) { + var result13 = input.charAt(pos); + pos++; + } else { + var result13 = null; + if (context.reportMatchFailures) { + matchFailed("[0-9]"); + } + } + } + } else { + var result12 = null; + } + if (result12 !== null) { + var result8 = [result9, result10, result11, result12]; + } else { + var result8 = null; + pos = savedPos1; + } + } else { + var result8 = null; + pos = savedPos1; + } + } else { + var result8 = null; + pos = savedPos1; + } + } else { + var result8 = null; + pos = savedPos1; + } + var result7 = result8 !== null + ? (function(m, digits, digits2) { result = parseInt(digits.join(""))+parseFloat("0."+digits2.join("")); if(m == "-") {result=result*-1}; return result})(result8[0], result8[1], result8[3]) + : null; + if (result7 !== null) { + var result0 = result7; + } else { + var savedPos0 = pos; + if (input.substr(pos, 1) === "-") { + var result6 = "-"; + pos += 1; + } else { + var result6 = null; + if (context.reportMatchFailures) { + matchFailed(quoteString("-")); + } + } + var result3 = result6 !== null ? result6 : ''; + if (result3 !== null) { + if (input.substr(pos).match(/^[0-9]/) !== null) { + var result5 = input.charAt(pos); + pos++; + } else { + var result5 = null; + if (context.reportMatchFailures) { + matchFailed("[0-9]"); + } + } + if (result5 !== null) { + var result4 = []; + while (result5 !== null) { + result4.push(result5); + if (input.substr(pos).match(/^[0-9]/) !== null) { + var result5 = input.charAt(pos); + pos++; + } else { + var result5 = null; + if (context.reportMatchFailures) { + matchFailed("[0-9]"); + } + } + } + } else { + var result4 = null; + } + if (result4 !== null) { + var result2 = [result3, result4]; + } else { + var result2 = null; + pos = savedPos0; + } + } else { + var result2 = null; + pos = savedPos0; + } + var result1 = result2 !== null + ? (function(m, digits) { result = parseInt(digits.join("")); if(m == "-") {result = result*-1}; return result})(result2[0], result2[1]) + : null; + if (result1 !== null) { + var result0 = result1; + } else { + var result0 = null;; + }; + } + + + + cache[cacheKey] = { + nextPos: pos, + result: result0 + }; + return result0; + } + + function buildErrorMessage() { + function buildExpected(failuresExpected) { + switch (failuresExpected.length) { + case 0: + return 'end of input'; + case 1: + return failuresExpected[0]; + default: + failuresExpected.sort(); + return failuresExpected.slice(0, failuresExpected.length - 1).join(', ') + + ' or ' + + failuresExpected[failuresExpected.length - 1]; + } + } + + var expected = buildExpected(rightmostMatchFailuresExpected); + var actualPos = Math.max(pos, rightmostMatchFailuresPos); + var actual = actualPos < input.length + ? quoteString(input.charAt(actualPos)) + : 'end of input'; + + return 'Expected ' + expected + ' but ' + actual + ' found.'; + } + + function computeErrorPosition() { + /* + * The first idea was to use |String.split| to break the input up to the + * error position along newlines and derive the line and column from + * there. However IE's |split| implementation is so broken that it was + * enough to prevent it. + */ + + var line = 1; + var column = 1; + var seenCR = false; + + for (var i = 0; i < rightmostMatchFailuresPos; i++) { + var ch = input.charAt(i); + if (ch === '\n') { + if (!seenCR) { line++; } + column = 1; + seenCR = false; + } else if (ch === '\r' | ch === '\u2028' || ch === '\u2029') { + line++; + column = 1; + seenCR = true; + } else { + column++; + seenCR = false; + } + } + + return { line: line, column: column }; + } + + + + var result = parse_url({ reportMatchFailures: true }); + + /* + * The parser is now in one of the following three states: + * + * 1. The parser successfully parsed the whole input. + * + * - |result !== null| + * - |pos === input.length| + * - |rightmostMatchFailuresExpected| may or may not contain something + * + * 2. The parser successfully parsed only a part of the input. + * + * - |result !== null| + * - |pos < input.length| + * - |rightmostMatchFailuresExpected| may or may not contain something + * + * 3. The parser did not successfully parse any part of the input. + * + * - |result === null| + * - |pos === 0| + * - |rightmostMatchFailuresExpected| contains at least one failure + * + * All code following this comment (including called functions) must + * handle these states. + */ + if (result === null || pos !== input.length) { + var errorPosition = computeErrorPosition(); + throw new this.SyntaxError( + buildErrorMessage(), + errorPosition.line, + errorPosition.column + ); + } + + return result; + }, + + /* Returns the parser source code. */ + toSource: function() { return this._source; } + }; + + /* Thrown when a parser encounters a syntax error. */ + + result.SyntaxError = function(message, line, column) { + this.name = 'SyntaxError'; + this.message = message; + this.line = line; + this.column = column; + }; + + result.SyntaxError.prototype = Error.prototype; + + return result; +})(); 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} diff --git a/src/nodejs/main.js b/src/nodejs/main.js index 80bd051..5006dbc 100644 --- a/src/nodejs/main.js +++ b/src/nodejs/main.js @@ -43,21 +43,18 @@ function rowToNode(row){ 'lat' : row.lat, 'lon' : row.lon }; - - if(row.tags != '{}') { - node.tags = []; - temp = row.tags.replace("{","").replace("}","").split(","); - for(var x=0;x<temp.length;x=x+2){ + node.tags = [] + if(row.tags.length != 0) { + for(var i=0;i<row.tags.length;i=i+2) { node.tags.push({ - 'key' : temp[x], - 'value' : temp[x+1] - }); + 'key' : row.tags[i], + 'value' : row.tags[i+1] + }) } } return node; } -//FIXME: parsing of ways is meesed up function rowToWay(row){ var way = { 'id' : row.id, @@ -65,17 +62,16 @@ function rowToWay(row){ 'version' : row.version, 'changeset' : row.changeset_id }; - if(row.tags != '{}') { - way.tags = []; - // FIXME: something doesnt work at all - temp = row.tags.replace("{","").replace("}","").split(","); - for(var x=0;x<temp.length;x=x+2){ + way.tags = [] + if(row.tags.length != 0) { + for(var i=0;i<row.tags.length;i=i+2) { way.tags.push({ - 'k' : temp[x], - 'v' : temp[x+1] - }); + 'key' : row.tags[i], + 'value' : row.tags[i+1] + }) } } + //TODO return nodes of way return way; } @@ -93,7 +89,7 @@ var options = [ // { // object = node/way/relation/* , // bbox = { left : 1.0 , right : 1.0 , top : 1.0, bottom : 1.0 } -// tag = { key : [ ], value [ ] } +// tag = { key : [ ], value [ ] } // } @@ -101,14 +97,14 @@ function buildMainQuery(reqJso){ var id = 1; var replacements = Array(); - + var selectMap = { - 'node' : 'id,user_id,tstamp,version,changeset_id,hstore_to_array(tags) as tags, ' + + 'node' : 'id,user_id,tstamp,version,changeset_id,hstore_to_array(tags) as tags, ' + 'X(geom) as lat, Y(geom) as lon', 'way' : 'id,tstamp,version,changeset_id,nodes,user_id,hstore_to_array(tags) as tags ', 'relation' : '' //FIXME: plz - } - + } + // FIXME: help me i am not side effect free function buildTagsQuery(map){ @@ -125,7 +121,7 @@ function buildMainQuery(reqJso){ // FIXME: help me i am not side effect free function buildBbox(object,bbox){ - + var colName = { node : 'geom', way : 'linestring', @@ -136,7 +132,7 @@ function buildMainQuery(reqJso){ ' st_setsrid(st_makepoint($' + id++ + ', $' + id++ + '), 4326), ' + ' st_setsrid(st_makepoint($' + id++ + ', $' + id++ + '), 4326) ' + ' ), 4326) '; - + for( direction in bbox ) { replacements.push(bbox[direction]); } @@ -153,15 +149,15 @@ function buildMainQuery(reqJso){ } return map; } - + query = "SELECT " + selectMap[reqJso.object] + " FROM " + reqJso.object + "s"; - + whereClauses = Array(); if(reqJso.bbox != undefined){ whereClauses.push(buildBbox(reqJso.object,reqJso.bbox)); } - + // FIXME: rename tag to tags key to keys value to values if(reqJso.tag != undefined){ tags = explodeTags(reqJso.tag.key,reqJso.tag.value); @@ -175,9 +171,10 @@ function buildMainQuery(reqJso){ query += ';' return { - text:query, - values:replacements, - name: query + text : query, + values : replacements, + name : query, + binary : true }; } @@ -278,11 +275,11 @@ function myFunction(req,res){ res.writeHead(200); var reqObj = parser.urlToXpathObj(req.url); - + var queryDict = buildMainQuery(reqObj); - + var resXml = osmRes.mkXmlRes(res); - + console.log(JSON.stringify(queryDict)); console.log("??????????????????????????????"); @@ -296,12 +293,12 @@ function myFunction(req,res){ }); query.on('end', function() { - console.log(" EEEND "); + console.log(" EEEND "); res.atEnd(); }); query.on('row', function(row) { - //console.log(JSON.stringify(row)); + //console.log(JSON.stringify(row)); if(reqObj.object == "node") { var pojo = rowToNode(row); res.putNode(pojo); diff --git a/src/nodejs/tests/async_basis_test.js b/src/nodejs/tests/async_basis_test.js index 47062e3..c083a19 100644 --- a/src/nodejs/tests/async_basis_test.js +++ b/src/nodejs/tests/async_basis_test.js @@ -1,5 +1,5 @@ if (module == require.main) { - return require('./node-async-testing/lib/async_testing').run(process.ARGV); + return require('async_testing').run(__filename, process.ARGV); } module.exports = { diff --git a/src/nodejs/tests/node-async-testing b/src/nodejs/tests/node-async-testing deleted file mode 160000 -Subproject a87f89d3f2437133364e1edc059a71a89520835 diff --git a/src/nodejs/tests/pathparsing.js b/src/nodejs/tests/pathparsing.js index ebd5baf..a012329 100644 --- a/src/nodejs/tests/pathparsing.js +++ b/src/nodejs/tests/pathparsing.js @@ -1,6 +1,6 @@ if (module == require.main) { - async_testing = require('./node-async-testing/lib/async_testing'); - return async_testing.run(process.ARGV); + async_testing = require('async_testing'); + return async_testing.run(__filename, process.ARGV); } var assert = require('assert'); |