Re: Parsing a search string

2004-12-31 Thread M.E.Farmer
py>b = shlex.shlex(a) py>while 1: ... tok = b.get_token() ... if not tok: break ... print tok ... moo cow + "farmer john" - dog Just wanted to share this just in case it might be relevant . It seems if we don't add +- to wordchars then we get a different split on "farmer john". M.E.Fa

Re: Parsing a search string

2004-12-31 Thread Freddie
Reinhold Birkenfeld wrote: Freddie wrote: Happy new year! Since I have run out of alcohol, I'll ask a question that I haven't really worked out an answer for yet. Is there an elegant way to turn something like: > moo cow "farmer john" -zug into: ['moo', 'cow', 'farmer john'], ['zug'] I'm trying

Re: Parsing a search string

2004-12-31 Thread It's me
"John Machin" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Andrew Dalke wrote: > > "It's me" wrote: > > > Here's a NDFA for your text: > > > > > >b 0 1-9 a-Z , . + - ' " \n > > > S0: S0 E E S1 E E E S3 E S2 E > > > S1: T1 E E S1 E E E E E E T1 > > > S2:

Re: Parsing a search string

2004-12-31 Thread John Machin
Andrew Dalke wrote: > "It's me" wrote: > > Here's a NDFA for your text: > > > >b 0 1-9 a-Z , . + - ' " \n > > S0: S0 E E S1 E E E S3 E S2 E > > S1: T1 E E S1 E E E E E E T1 > > S2: S2 E E S2 E E E E E T2 E > > S3: T3 E E S3 E E E E E E T3 > > Now if I only h

Re: Parsing a search string

2004-12-31 Thread Brian Beck
Freddie wrote: I'm trying to parse a search string so I can use it for SQL WHERE constraints, preferably without horrifying regular expressions. Uhh yeah. If you're interested, I've written a function that parses query strings using a customizable version of Google's search syntax. Features incl

Re: Parsing a search string

2004-12-31 Thread It's me
"Andrew Dalke" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "It's me" wrote: > > Here's a NDFA for your text: > > > >b 0 1-9 a-Z , . + - ' " \n > > S0: S0 E E S1 E E E S3 E S2 E > > S1: T1 E E S1 E E E E E E T1 > > S2: S2 E E S2 E E E E E T2 E > >

Re: Parsing a search string

2004-12-31 Thread Andrew Dalke
"It's me" wrote: > Here's a NDFA for your text: > >b 0 1-9 a-Z , . + - ' " \n > S0: S0 E E S1 E E E S3 E S2 E > S1: T1 E E S1 E E E E E E T1 > S2: S2 E E S2 E E E E E T2 E > S3: T3 E E S3 E E E E E E T3 Now if I only had an NDFA for parsing that syntax...

Re: Parsing a search string

2004-12-31 Thread Reinhold Birkenfeld
M.E.Farmer wrote: > Ah! that is what the __future__ brings I guess. > Damn that progress making me outdated ;) > Python 2.2.3 ( a lot of extensions I use are stuck there , so I still > use it) I'm also positively surprised how many cute little additions are there every new Python version.

Re: Parsing a search string

2004-12-31 Thread M.E.Farmer
Ah! that is what the __future__ brings I guess. Damn that progress making me outdated ;) Python 2.2.3 ( a lot of extensions I use are stuck there , so I still use it) M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: Parsing a search string

2004-12-31 Thread It's me
I am right in the middle of doing text parsing so I used your example as a mental exercise. :-) Here's a NDFA for your text: b 0 1-9 a-Z , . + - ' " \n S0: S0 E E S1 E E E S3 E S2 E S1: T1 E E S1 E E E E E E T1 S2: S2 E E S2 E E E E E T2 E S3: T3 E E S3 E E

Re: Parsing a search string

2004-12-31 Thread Reinhold Birkenfeld
M.E.Farmer wrote: > As I noted before shlex requires a file like object or a open file . > py> import shlex > py> a = shlex.shlex('fgfgfg dgfgfdgfdg') > py> a.get_token() > Traceback (most recent call last): > File "", line 1, in ? > File ".\shlex.py", line 74, in get_token > raw = self.read_token(

Re: Parsing a search string

2004-12-31 Thread M.E.Farmer
As I noted before shlex requires a file like object or a open file . py> import shlex py> a = shlex.shlex('fgfgfg dgfgfdgfdg') py> a.get_token() Traceback (most recent call last): File "", line 1, in ? File ".\shlex.py", line 74, in get_token raw = self.read_token() File ".\shlex.py", line 100, in

Re: Parsing a search string

2004-12-31 Thread Reinhold Birkenfeld
Freddie wrote: > Happy new year! Since I have run out of alcohol, I'll ask a question that I > haven't really worked out an answer for yet. Is there an elegant way to turn > something like: > > > moo cow "farmer john" -zug > > into: > > ['moo', 'cow', 'farmer john'], ['zug'] > > I'm trying t

Re: Parsing a search string

2004-12-31 Thread Fuzzyman
That's not bad going considering you've only run out of alcohol at 6 in the morning and *then* ask python questions. Anyway - you could write a charcter-by-character parser function that would do that in a few minutes... My 'listquote' module has one - but it splits on commas not whitespace. Soun

Re: Parsing a search string

2004-12-31 Thread M.E.Farmer
How , I just posted on something similar earlier ;) Ok first of all you might want to try shlex it is in the standard library. If you don't know what cStringIO is dont worry about it it is just to give a file like object to pass to shlex. If you have a file just pass it in opened. example: a = shl

Parsing a search string

2004-12-31 Thread Freddie
Happy new year! Since I have run out of alcohol, I'll ask a question that I haven't really worked out an answer for yet. Is there an elegant way to turn something like: > moo cow "farmer john" -zug into: ['moo', 'cow', 'farmer john'], ['zug'] I'm trying to parse a search string so I can use it f