Thread: [Pyparsing] Help using Combine()
Brought to you by:
ptmcg
From: Joshua J. K. <jk...@sk...> - 2008-03-05 21:39:12
|
I have this construct: primary_key = (p.CaselessKeyword('primary') + p.CaselessKeyword('key') + p.Or([p.CaselessKeyword('clustered'), p.CaselessKeyword('nonclustered')]) + p.nestedExpr(content=p.delimitedList(bracket_quoted.setResultsName('key_column'))) + p.CaselessKeyword('on').suppress() + bracket_quoted.suppress() ) which I'm using to parse: PRIMARY KEY CLUSTERED ([login_id]) ON [PRIMARY] All is well, and that gives: ['primary', 'key', 'clustered', ['login_id']] I'd like that first element to be 'primary key' so I do: primary_key = (p.Combine(p.CaselessKeyword('primary') + p.CaselessKeyword('key'), joinString=' ') + p.Or([p.CaselessKeyword('clustered'), p.CaselessKeyword('nonclustered')]) + p.nestedExpr(content=p.delimitedList(bracket_quoted.setResultsName('key_column'))) + p.CaselessKeyword('on').suppress() + bracket_quoted.suppress() ) But that gives me: ParseException: Expected "key" (at char 7), (line:1, col:8) So apparently I'm not using Group as intended, and the docs don't provide an example of use. Might someone point me to the docs that explain how to accomplish what I'm trying to do? Thanks! j -- Joshua Kugler VOC/SigNet Provider (aka Web App Programmer) S&K Aerospace Alaska |
From: Joshua J. K. <jk...@sk...> - 2008-03-06 01:51:24
|
Sigh...I went back and re-read the docs and saw the part about adjacent. Problem solved. Sorry about the noise. j On Wed, 2008-03-05 at 12:39 -0900, Joshua J. Kugler wrote: > I have this construct: > > primary_key = (p.CaselessKeyword('primary') + > p.CaselessKeyword('key') + > p.Or([p.CaselessKeyword('clustered'), p.CaselessKeyword('nonclustered')]) + > p.nestedExpr(content=p.delimitedList(bracket_quoted.setResultsName('key_column'))) + > p.CaselessKeyword('on').suppress() + > bracket_quoted.suppress() > ) > > which I'm using to parse: > > PRIMARY KEY CLUSTERED ([login_id]) ON [PRIMARY] > > All is well, and that gives: > > ['primary', 'key', 'clustered', ['login_id']] > > I'd like that first element to be 'primary key' so I do: > > primary_key = (p.Combine(p.CaselessKeyword('primary') + > p.CaselessKeyword('key'), joinString=' ') + > p.Or([p.CaselessKeyword('clustered'), p.CaselessKeyword('nonclustered')]) + > p.nestedExpr(content=p.delimitedList(bracket_quoted.setResultsName('key_column'))) + > p.CaselessKeyword('on').suppress() + > bracket_quoted.suppress() > ) > > But that gives me: > > ParseException: Expected "key" (at char 7), (line:1, col:8) > > So apparently I'm not using Group as intended, and the docs don't > provide an example of use. Might someone point me to the docs that > explain how to accomplish what I'm trying to do? > > Thanks! > > j > -- Joshua Kugler VOC/SigNet Provider (aka Web App Programmer) S&K Aerospace Alaska |
From: Paul M. <pa...@al...> - 2008-03-06 02:02:24
|
Joshua - Sorry not to respond sooner, I'm glad you were able to work this out on your own. I assume you modified the Combine constructor using adjacent=False, to accept whitespace between tokens. -- Paul -----Original Message----- From: pyp...@li... [mailto:pyp...@li...] On Behalf Of Joshua J. Kugler Sent: Wednesday, March 05, 2008 7:52 PM To: PyParsing User List Subject: Re: [Pyparsing] Help using Combine() Sigh...I went back and re-read the docs and saw the part about adjacent. Problem solved. Sorry about the noise. j On Wed, 2008-03-05 at 12:39 -0900, Joshua J. Kugler wrote: > I have this construct: > > primary_key = (p.CaselessKeyword('primary') + > p.CaselessKeyword('key') + > p.Or([p.CaselessKeyword('clustered'), p.CaselessKeyword('nonclustered')]) + > p.nestedExpr(content=p.delimitedList(bracket_quoted.setResultsName('key_colu mn'))) + > p.CaselessKeyword('on').suppress() + > bracket_quoted.suppress() > ) > > which I'm using to parse: > > PRIMARY KEY CLUSTERED ([login_id]) ON [PRIMARY] > > All is well, and that gives: > > ['primary', 'key', 'clustered', ['login_id']] > > I'd like that first element to be 'primary key' so I do: > > primary_key = (p.Combine(p.CaselessKeyword('primary') + > p.CaselessKeyword('key'), joinString=' ') + > p.Or([p.CaselessKeyword('clustered'), p.CaselessKeyword('nonclustered')]) + > p.nestedExpr(content=p.delimitedList(bracket_quoted.setResultsName('key_colu mn'))) + > p.CaselessKeyword('on').suppress() + > bracket_quoted.suppress() > ) > > But that gives me: > > ParseException: Expected "key" (at char 7), (line:1, col:8) > > So apparently I'm not using Group as intended, and the docs don't > provide an example of use. Might someone point me to the docs that > explain how to accomplish what I'm trying to do? > > Thanks! > > j > -- Joshua Kugler VOC/SigNet Provider (aka Web App Programmer) S&K Aerospace Alaska ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users |
From: Joshua J. K. <jk...@sk...> - 2008-03-06 02:07:37
|
On Wed, 2008-03-05 at 20:02 -0600, Paul McGuire wrote: > Sorry not to respond sooner, I'm glad you were able to work this out on your > own. I assume you modified the Combine constructor using adjacent=False, to > accept whitespace between tokens. No worries about the delay. I was expecting instant response. Yes, I used ajacent=False and it worked nicely. Thanks. j -- Joshua Kugler VOC/SigNet Provider (aka Web App Programmer) S&K Aerospace Alaska |
From: Joshua J. K. <jk...@sk...> - 2008-03-06 02:13:19
|
On Wed, 2008-03-05 at 17:08 -0900, Joshua J. Kugler wrote: > I was expecting instant response. Sigh...I *wasn't* expecting. j -- Joshua Kugler VOC/SigNet Provider (aka Web App Programmer) S&K Aerospace Alaska |