SQL parser for ruby?

226 views
Skip to first unread message

Tim Harper

unread,
Sep 16, 2008, 2:29:05 PM9/16/08
to <urug@googlegroups.com>
I've been hearing quite a bit of talk about grammar parsers lately,
and recently had the urge to find a SQL parser for ruby (want to make
a 'tidy query' function).

I've checked out treetop, but the documentation is pretty sparse, and
I'm not sure if someone's already done this. Is anyone aware of a
good SQL parser for ruby?

Ben Mabey

unread,
Sep 16, 2008, 2:33:13 PM9/16/08
to ur...@googlegroups.com

SQL parser in treetop:
https://github.com/smtlaissezfaire/guillotine/tree

It is pretty new but seems promising.

-Ben

Tim Harper

unread,
Sep 16, 2008, 10:34:25 PM9/16/08
to ur...@googlegroups.com
Hmm, looks cool - couldn't get it to parse my query though :( Threw
some weird, untraceable error.

Tim

Jeremy Nicoll

unread,
Sep 16, 2008, 10:45:53 PM9/16/08
to ur...@googlegroups.com
That wasn't the parser. That was the query being passed to your
database software. ;)

Tim Harper

unread,
Sep 16, 2008, 10:46:59 PM9/16/08
to ur...@googlegroups.com
lol - yes, I figured that. However, there is a parser in there that I
pulled out, and I was able to get it to parse simple queries, but it
didn't parse my query :)

Tim

Ben Mabey

unread,
Sep 16, 2008, 11:34:13 PM9/16/08
to ur...@googlegroups.com

Yeah, it is definitely a young project but I think some really cool
things could be done with it. I was interested in it because I think it
would be extremely useful from a testing point of view.

If you are looking for good resources on treetop I would suggest
watching the confreaks video from RubyConf about it. If you haven't
seen it already it provides a great introduction to treetop by walking
you through creating a simple arithmetic parser.
Heres the link:
http://rubyconf2007.confreaks.com/d1t1p5_treetop.html

-Ben

David Richards

unread,
Sep 19, 2008, 12:41:32 PM9/19/08
to Utah Ruby Users Group
I've tried to cut my teeth on treetop several times, even with this
video. I just concluded I'm not smart enough to handle it. I think
some documentation would also be nice. If anyone finds more resources
on this, I'd sure like to see them.

David

grady player

unread,
Sep 19, 2008, 1:36:32 PM9/19/08
to ur...@googlegroups.com
I am not entirely sure as to what you are trying to do,
and It may be heretical to suggest this (not very DRY, OOP, new or cool. etc.) to a ruby group,
but there are ruby lex and yacc projects
I haven't ever looked at them, but If i need parsin' I always start out with some %%'s

Scott Taylor (smtlaissezfaire)

unread,
Sep 22, 2008, 1:48:59 AM9/22/08
to Utah Ruby Users Group


On Sep 16, 10:34 pm, Tim Harper <timchar...@gmail.com> wrote:
> Hmm, looks cool - couldn't get it to parse my query though :(  Threw  
> some weird, untraceable error.'

Hey Tim,

What's the query? As it is in it's current state, *many* sql
statements aren't supported:

- Any selection that isn't a "star" query, meaning a select *
- Group by
- Offset, or limit with offset
- joins
- explicit table names. so: SELECT * FROM users where users.name =
"foo"

Also, make sure all sql keywords are capitalized. I'm either going to
write a pre-parser which does this, or else patch treetop to allow
case-insensitive regexps.

Regarding treetop, you might want to watch some of these "theory of
computation" courses. They are really a gem, and will introduce you
to state machines and parsing:

http://www.archive.org/details/arsdigita_08_theory_of_computation
Reply all
Reply to author
Forward
0 new messages