I want to create a parser, possibly recursive to use in my GIS application that work on top of OpenLayers 2.
I have a query like this:
name = 1 OR name = 2 OR name in(3,4)The query is written in SQL style.
I want an output like this (as an array of expressions and operators):
var rules = [
{
property:'name',
operator: 'equal',
value: 1
},
'OR',
{
property:'name',
operator: 'equal',
value: 2
},
'OR',
{
property:'name',
operator: 'in',
value: [3,4]
}
];The main problem here is haven't been able to parse the string. I have been looking for libraries that could do it automatically.
I found JISON, but it seems that I have to write the whole grammar.
I wonder if there is a library that parses this kind of SQL string into a JavaScript object/array, for future manipulation.
The purpose is to insert these data in an SLD rule of a layer in OpenLayers 2.
As a matter of fact, it should also be able to parse nested queries.
Thank you.
--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/0a27c552-6cd5-432a-92fe-f567e853f86d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You'll need to write a parser. There are tools to help, e.g. http://pegjs.majda.cz/documentation
Just include the word 'OR' as a key:value into your object and do not insert it into the array as a new element.
I means var rules = [..., {type:'OR', property:'name', operator:'equal', value:[1,2]} ,...];That will allow you to eval something like for(var idx in rules){ switch rules[idx].type; case 'OR' foo; case 'AND' bar; default ...}