From: Mat Schaffer Date: 2006-06-05T21:35:12+09:00 Subject: Re: parsing a boolean expression On Jun 5, 2006, at 2:32 AM, Daniel Baird wrote: > Hi all, > > I need to take a string typed by dirty users' fingers, that should > contain a > boolean expression, like this: > one and (two or three or (four and five) or six) and (seven or eight) > ..and parse it into some kind of sensible data structure, like a > tree or > something. Or reject it if it's mal-formed. > > I figure it might take me two or three days to write and debug from > scratch > (..hey, I'm fairly new to Ruby :\ ), but I'm sure there's a library > somewhere that will do the job. > > I've tried searching for bool*, expr* and pars* in fxri but didn't get > anything, and Googling just tells me that my search terms are too > generic to > find what I want. Any suggestions? > > Thanks in advance! > > ;Daniel > > -- > Daniel Baird > http://danielbaird.com (TiddlyW;nks! :: Whiteboard Koala :: Blog :: > Things > That Suck) If you can force (or just add on) an exterior set of parenthesis, S- Expressions could fill your parsing need as described here: http://www.artima.com//rubycs/articles/patterns_sexp_dsls3.html You'll have to work out the booleans yourself, but that shouldn't be too tricky. -Mat