You'll need to write a parser. There are tools to help, e.g.
http://pegjs.majda.cz/documentation


On Tue, Jul 15, 2014 at 1:25 PM, João Rodrigues <[email protected]>
wrote:

> 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 <http://zaach.github.io/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
> <http://dev.openlayers.org/docs/files/OpenLayers/Rule-js.html> 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 [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nodejs/0a27c552-6cd5-432a-92fe-f567e853f86d%40googlegroups.com
> <https://groups.google.com/d/msgid/nodejs/0a27c552-6cd5-432a-92fe-f567e853f86d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/CAPJ5V2bK_q9ndJYdLwsiOR6Kf-zN1fvR%3DpPOtUOOwmKNagEbNw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to