Hey there, As part of a previous project, I wrote a SQL parser using Jison. It's actually a subset/fork of SQL that works over any queryable backend (database, Web API, etc.). There's currently support for MongoDB and Usergrid, a backend-as-a-service. This project was spawned out of another, and I still need to migrate over drivers for CouchDB and Salesforce.
The project is Calypso: https://github.com/kevinswiber/calypso Calypso also has ORM-like functionality. The query language it uses is called CaQL (https://github.com/kevinswiber/calypso#calypso-query-language). I plan on breaking out the query parsing parts into a separate library, as I actually need it for a separate project, but if you want to get at the parsing guts today, check here: https://github.com/kevinswiber/calypso/tree/master/compiling . Here's a railroad diagram of the syntax, but it might be slightly out of date: http://kevinswiber.github.io/surface/diagram.html If you take this route, let me know if you have any questions. Working with Jison was a lot of fun! Cheers, -- Kevin Swiber Projects: https://github.com/kevinswiber Twitter: @kevinswiber On Tuesday, July 15, 2014 1:25:06 PM UTC-4, João Rodrigues 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/7b94df87-7e08-48a4-9d73-32c76bbb189d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
