Re: [Pyparsing] Unordered set of expressions
Brought to you by:
ptmcg
From: Russell D. <Rus...@as...> - 2011-09-29 23:43:58
|
On Thu, Sep 29, 2011 at 4:09 PM, Paul McGuire <pt...@au...> wrote: > Russell - > > I'm not seeing this behavior: > > EAEB > ['E', 'A', 'E', 'B'] > > You can have as many D's and E's as you like, anywhere, and at most 1 C > anywhere, but you must have 1 A and 1 B, somewhere. Odd, at some point I must have convinced myself something about Each that wasn't true. Ok, minor issue though, the Group keyword seems to cause this to stop working. Since the order doesn't matter, it'd be nice to Group them together. Naming them seems to be a workaround, but it produces strange parse output. ZeroOrMore(Literal("E")("Es"))) > > -----Original Message----- > From: Russell Dill [mailto:Rus...@as...] > Sent: Thursday, September 29, 2011 1:25 PM > To: pyp...@li... > Subject: [Pyparsing] Unordered set of expressions > > I have to parse something with an unordered set of expressions. In the > simplest case, some expressions are required, some are optional. For > this, parsing is easy: > > language = expr1 & expr2 & Optional(expr3) > > However, there are cases where an expression can occur zero or more > times, one or more times, or two or more times. But since they can > still occur in any order, I'm not sure how to handle it. If I try: > > language = expr1 & expr2 & Optional(expr3) & ZeroOrMore(expr4) & > ZeroOrMore(expr5) > > Then parsing fails if all expr4's are not adjacent. My current idea is > to do the following: > > multiples = ZeroOrMore(expr4 | expr5) > > language = (multiples + expr1) & (multiples + expr2) & > Optional(multiples + expr3) & multiples > > While its ugly, I can't think of any other way to do it. Additionally, > it doesn't get me any closer to implementing OneOrMore in an unsorted > set of expressions. > > ---------------------------------------------------------------------------- > -- > All the data continuously generated in your IT infrastructure contains a > definitive record of customers, application performance, security > threats, fraudulent activity and more. Splunk takes this data and makes > sense of it. Business sense. IT sense. Common sense. > http://p.sf.net/sfu/splunk-d2dcopy1 > _______________________________________________ > Pyparsing-users mailing list > Pyp...@li... > https://lists.sourceforge.net/lists/listinfo/pyparsing-users > > |