From a9a2daeebf8ef351b3efe74549026ce7619873ff Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Sat, 29 Jan 2011 14:00:00 +0100 Subject: fixed syntax errors --- src/nodejs/main.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/nodejs/main.js b/src/nodejs/main.js index ce4518d..a7ff07b 100644 --- a/src/nodejs/main.js +++ b/src/nodejs/main.js @@ -98,7 +98,7 @@ var urlToXpathObj = function urlToXpathObj(url){ var parseBboxList = function(string){ - result = /(.+)(:?,(.+)){3}/.exec(string): + result = /(.+)(:?,(.+)){3}/.exec(string); if(result.length != 4){ throw "error"; @@ -107,10 +107,11 @@ var urlToXpathObj = function urlToXpathObj(url){ result.shift(); return { - 'left' : result[0]; - 'bottom' : result[1]; - 'right' : result[2]; - 'top' : result[3]; + 'left' : result[0], + 'bottom' : result[1], + 'right' : result[2], + 'top' : result[3] + }; } var xp = {}; -- cgit v1.2.3 From fb8641c55e99b6a207dcd7507310d9c4b3bbc376 Mon Sep 17 00:00:00 2001 From: booo Date: Sun, 30 Jan 2011 01:20:51 +0100 Subject: the parsing solution? --- src/nodejs/alternative/parser.js | 1168 ++++++++++++++++++++++++++++++++++++ src/nodejs/alternative/testgrammar | 28 + 2 files changed, 1196 insertions(+) create mode 100644 src/nodejs/alternative/parser.js create mode 100644 src/nodejs/alternative/testgrammar diff --git a/src/nodejs/alternative/parser.js b/src/nodejs/alternative/parser.js new file mode 100644 index 0000000..ac10479 --- /dev/null +++ b/src/nodejs/alternative/parser.js @@ -0,0 +1,1168 @@ +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 result7 = parse_object(context); + if (result7 !== null) { + var result8 = parse_predicate(context); + if (result8 !== null) { + var result9 = parse_predicate(context); + if (result9 !== null) { + var result6 = [result7, result8, result9]; + } else { + var result6 = null; + pos = savedPos1; + } + } else { + var result6 = null; + pos = savedPos1; + } + } else { + var result6 = null; + pos = savedPos1; + } + var result5 = result6 !== 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;})(result6[0], result6[1], result6[2]) + : null; + if (result5 !== null) { + var result0 = result5; + } else { + var savedPos0 = pos; + var result3 = parse_object(context); + if (result3 !== null) { + var result4 = parse_predicate(context); + if (result4 !== null) { + var result2 = [result3, result4]; + } else { + var result2 = null; + pos = savedPos0; + } + } else { + var result2 = null; + pos = savedPos0; + } + if (result2 !== null) { + var result0 = result2; + } else { + var result1 = parse_object(context); + 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..e212493 --- /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 predicate / 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} -- cgit v1.2.3 From 46956a6a4079917bca0d5a22497116caa82386db Mon Sep 17 00:00:00 2001 From: booo Date: Sun, 30 Jan 2011 01:35:57 +0100 Subject: almost working; do some testing... --- src/nodejs/alternative/parser.js | 54 +++++++++++++++++++++----------------- src/nodejs/alternative/testgrammar | 2 +- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/nodejs/alternative/parser.js b/src/nodejs/alternative/parser.js index ac10479..d388471 100644 --- a/src/nodejs/alternative/parser.js +++ b/src/nodejs/alternative/parser.js @@ -96,49 +96,55 @@ exports.parser = parser = (function(){ var savedPos1 = pos; - var result7 = parse_object(context); - if (result7 !== null) { - var result8 = parse_predicate(context); - if (result8 !== null) { - var result9 = parse_predicate(context); - if (result9 !== null) { - var result6 = [result7, result8, result9]; + 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 result6 = null; + var result8 = null; pos = savedPos1; } } else { - var result6 = null; + var result8 = null; pos = savedPos1; } } else { - var result6 = null; + var result8 = null; pos = savedPos1; } - var result5 = result6 !== 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;})(result6[0], result6[1], result6[2]) + 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 (result5 !== null) { - var result0 = result5; + if (result7 !== null) { + var result0 = result7; } else { var savedPos0 = pos; - var result3 = parse_object(context); - if (result3 !== null) { - var result4 = parse_predicate(context); - if (result4 !== null) { - var result2 = [result3, result4]; + var result5 = parse_object(context); + if (result5 !== null) { + var result6 = parse_predicate(context); + if (result6 !== null) { + var result4 = [result5, result6]; } else { - var result2 = null; + var result4 = null; pos = savedPos0; } } else { - var result2 = null; + var result4 = null; pos = savedPos0; } - if (result2 !== null) { - var result0 = result2; + 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 result1 = parse_object(context); + var result2 = parse_object(context); + var result1 = result2 !== null + ? (function(object) { return {object:object}})(result2) + : null; if (result1 !== null) { var result0 = result1; } else { diff --git a/src/nodejs/alternative/testgrammar b/src/nodejs/alternative/testgrammar index e212493..0e43013 100644 --- a/src/nodejs/alternative/testgrammar +++ b/src/nodejs/alternative/testgrammar @@ -3,7 +3,7 @@ * "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 predicate / object +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} -- cgit v1.2.3 From 710407ad022b919c78659a3d30c7ce695eea9560 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Tue, 1 Feb 2011 02:03:28 +0100 Subject: remove trailing whitespaces --- src/nodejs/main.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/nodejs/main.js b/src/nodejs/main.js index 80bd051..96d1043 100644 --- a/src/nodejs/main.js +++ b/src/nodejs/main.js @@ -93,7 +93,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 +101,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 +125,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 +136,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 +153,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); @@ -278,11 +278,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 +296,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); -- cgit v1.2.3 From 380016154f5049460f5221fc1eec655d3e868622 Mon Sep 17 00:00:00 2001 From: booo Date: Sun, 13 Feb 2011 12:00:08 +0100 Subject: handle tags with new node-postgres module; xml escaping still broken --- src/nodejs/main.js | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/nodejs/main.js b/src/nodejs/main.js index 96d1043..faa7e12 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 Date: Mon, 14 Feb 2011 17:27:26 +0100 Subject: reflect changes on node-postgres branch --- src/nodejs/main.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/nodejs/main.js b/src/nodejs/main.js index faa7e12..5006dbc 100644 --- a/src/nodejs/main.js +++ b/src/nodejs/main.js @@ -171,9 +171,10 @@ function buildMainQuery(reqJso){ query += ';' return { - text:query, - values:replacements, - name: query + text : query, + values : replacements, + name : query, + binary : true }; } -- cgit v1.2.3 From b16f5bc714acfc3aa8ea9bff87c20bc810c67566 Mon Sep 17 00:00:00 2001 From: booo Date: Fri, 4 Mar 2011 16:41:30 +0100 Subject: removed obsolete information; added contact information; added information about dependencies --- README | 46 +++++++++++----------------------------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/README b/README index b940be3..f9894d1 100644 --- a/README +++ b/README @@ -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 : ( -| {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 -- cgit v1.2.3 From 2c799a47e2d64467565791a7db3468f254a1f142 Mon Sep 17 00:00:00 2001 From: booo Date: Thu, 14 Apr 2011 17:27:53 +0200 Subject: removed async_testing as sub repo; fixed test suites --- src/nodejs/tests/async_basis_test.js | 2 +- src/nodejs/tests/node-async-testing | 1 - src/nodejs/tests/pathparsing.js | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) delete mode 160000 src/nodejs/tests/node-async-testing 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 index a87f89d..0000000 --- a/src/nodejs/tests/node-async-testing +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a87f89d3f2437133364e1edc059a71a895208355 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'); -- cgit v1.2.3 From 9a62f0c465cb1250e5f1ec825aed12a0792291de Mon Sep 17 00:00:00 2001 From: booo Date: Sun, 17 Apr 2011 17:53:19 +0200 Subject: presentation (introduction) added --- doc/cc.png | Bin 0 -> 10135 bytes doc/introduction.tex | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 doc/cc.png create mode 100644 doc/introduction.tex diff --git a/doc/cc.png b/doc/cc.png new file mode 100644 index 0000000..d181cc0 Binary files /dev/null and b/doc/cc.png differ 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} + + + + \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} + + + + + + + + \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} + + + + + + + + \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} + + \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} -- cgit v1.2.3