pyparsing-users Mailing List for Python parsing module (Page 25)
Brought to you by:
ptmcg
You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
(2) |
Sep
|
Oct
|
Nov
(2) |
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(2) |
Feb
|
Mar
(2) |
Apr
(12) |
May
(2) |
Jun
|
Jul
|
Aug
(12) |
Sep
|
Oct
(1) |
Nov
|
Dec
|
2006 |
Jan
(5) |
Feb
(1) |
Mar
(10) |
Apr
(3) |
May
(7) |
Jun
(2) |
Jul
(2) |
Aug
(7) |
Sep
(8) |
Oct
(17) |
Nov
|
Dec
(3) |
2007 |
Jan
(4) |
Feb
|
Mar
(10) |
Apr
|
May
(6) |
Jun
(11) |
Jul
(1) |
Aug
|
Sep
(19) |
Oct
(8) |
Nov
(32) |
Dec
(8) |
2008 |
Jan
(12) |
Feb
(6) |
Mar
(42) |
Apr
(47) |
May
(17) |
Jun
(15) |
Jul
(7) |
Aug
(2) |
Sep
(13) |
Oct
(6) |
Nov
(11) |
Dec
(3) |
2009 |
Jan
(2) |
Feb
(3) |
Mar
|
Apr
|
May
(11) |
Jun
(13) |
Jul
(19) |
Aug
(17) |
Sep
(8) |
Oct
(3) |
Nov
(7) |
Dec
(1) |
2010 |
Jan
(2) |
Feb
|
Mar
(19) |
Apr
(6) |
May
|
Jun
(2) |
Jul
|
Aug
(1) |
Sep
|
Oct
(4) |
Nov
(3) |
Dec
(2) |
2011 |
Jan
(4) |
Feb
|
Mar
(5) |
Apr
(1) |
May
(3) |
Jun
(8) |
Jul
(6) |
Aug
(8) |
Sep
(35) |
Oct
(1) |
Nov
(1) |
Dec
(2) |
2012 |
Jan
(2) |
Feb
|
Mar
(3) |
Apr
(4) |
May
|
Jun
(1) |
Jul
|
Aug
(6) |
Sep
(18) |
Oct
|
Nov
(1) |
Dec
|
2013 |
Jan
(7) |
Feb
(7) |
Mar
(1) |
Apr
(4) |
May
|
Jun
|
Jul
(1) |
Aug
(5) |
Sep
(3) |
Oct
(11) |
Nov
(3) |
Dec
|
2014 |
Jan
(3) |
Feb
(1) |
Mar
|
Apr
(6) |
May
(10) |
Jun
(4) |
Jul
|
Aug
(5) |
Sep
(2) |
Oct
(4) |
Nov
(1) |
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
(13) |
May
(1) |
Jun
|
Jul
(2) |
Aug
|
Sep
(9) |
Oct
(2) |
Nov
(11) |
Dec
(2) |
2016 |
Jan
|
Feb
(3) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
(3) |
Aug
|
Sep
|
Oct
(1) |
Nov
(1) |
Dec
(4) |
2017 |
Jan
(2) |
Feb
(2) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
(4) |
Aug
|
Sep
|
Oct
(4) |
Nov
(3) |
Dec
|
2018 |
Jan
(10) |
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
2019 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2020 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2022 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2023 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2024 |
Jan
|
Feb
(1) |
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
(1) |
Aug
(3) |
Sep
(1) |
Oct
(1) |
Nov
|
Dec
|
From: Ralph C. <ra...@in...> - 2007-11-09 11:57:04
|
Hi Thomas, > from pyparsing import * > number = Word(nums) > aexp = Forward() > aexp = Or ([ > number, > number + '+' + aexp , > ]) > > Running the code yields: > > aexp.parseString("3+4") => (['3'], {}) Examine aexp shows >>> aexp {W:(0123...) ^ {{W:(0123...) "+"} Forward:None}} which indicates to me that the Forward hasn't been set to anything. That's because Forwards have to be assigned with `<<' rather than `='. You're forgetting about the Forward created with the initial assignment to aexp by altering aexp to be an Or. I can't find the documentation online, but have a look for something like /usr/share/doc/python2.4-pyparsing/htmldoc/index.html on your machine and see Forward: Forward declaration of an expression to be defined later - used for recursive grammars, such as algebraic infix notation. When the expression is known, it is assigned to the Forward variable using the '<<' operator. When I try: >>> aexp = Forward() >>> aexp << Or ([ ... number, ... number + '+' + aexp , ... ]) Forward:{W:(0123...) ^ {{W:(0123...) "+"} ...}} Which looks a bit better. >>> aexp.parseString("3+4") (['3', '+', '4'], {}) Cheers, Ralph. |
From: thomas_h <th...@go...> - 2007-11-09 11:04:56
|
Hi all, I'm new to pyparsing, and I'm struggling with recursive production rules. As an example, I want to parse expressions that are either numbers or additions of numbers. Grammar: number :: '0'..'9'* aexp :: number | number '+' aexp The following straight-forward implementation doesn't work: from pyparsing import * number = Word(nums) aexp = Forward() aexp = Or ([ number, number + '+' + aexp , ]) Running the code yields: aexp.parseString("3+4") => (['3'], {}) I probably miss something simple here, but I can't figure out what. If I make aexp non-recursive ("..., number + '+' + number,])") it works, but this doesn't solve the general problem (re-arranging the cases in the 'Or' argument doesn't help either). I looked into the "fourFn.py" example, but this is much too elaborate to answer my question. Thanks, Thomas |
From: Paul M. <pa...@al...> - 2007-11-08 15:24:43
|
I assumed that the couple always referred to an x-y coordinate pair, which is why I grouped them. If you don't wan the grouping, just make couple read: couple = floatNum + comma + floatNum and those inner groups will go away. -- Paul -----Original Message----- From: pyp...@li... [mailto:pyp...@li...] On Behalf Of Donn Ingle Sent: Thursday, November 08, 2007 9:23 AM To: pyp...@li... Subject: Re: [Pyparsing] pyparsing svg - noob > float = ... whatever ... AAARRRGGGHHH! :) A Homer moment. > phrase = OneOrMore(Group(command)) # what I would recommend instead > My recommended version of phrase makes each command its own nested > list, > like: > [['M', [float,float]], > ['C',[float,float,float,float,float,float]], > ['L',[float,float]], > ['Z']] > Your recc. phrase is producing this: M [['269.78326', '381.27104']] This is ok. C [['368.52151', '424.27023'], ['90.593578', '-18.581883'], ['90.027729', '129.28708']] This is 3 lists of 2 coords. Not a train smash, but not a single list of 6 coords. It's to do with the nature of a 'couple' I think. > for command,couples in tokens[:-1]: Now that is cool, but strange. I printed tokens[:-1] out and, oh boy, there's tupels in lists and dics too! Heck, as long as it works. \d ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users |
From: Donn <don...@gm...> - 2007-11-08 15:22:11
|
> object-like behavior too. I see I overlooked pop() in ParseResults' > methods, I'll try to remember to include that in the next version. Thanks. > (You may have to resort to reading some documentation soon...) I hear you. You've been magnificently patient with me :) > If you really, really, really want to pop your way through the tokens, you > can convert the results to a list by using asList(), and then pop() away! Great! It's an approach my mind likes - it lets me process things logically while in a loop that simply gets shorter as it loops! > floatNum.setParseAction(lambda toks:float(toks[0])) This and your other example are great ideas, I'll give 'em a whirl. I hope I don't hit many more walls, I'm actually aiming at other things and all this parsing kind of hit me over the head. I'll have to change gears and slow down. Thanks again. \d |
From: Donn I. <don...@gm...> - 2007-11-08 15:18:37
|
> float = ... whatever ... AAARRRGGGHHH! :) A Homer moment. > phrase = OneOrMore(Group(command)) # what I would recommend instead > My recommended version of phrase makes each command its own nested list, > like: > [['M', [float,float]], > ['C',[float,float,float,float,float,float]], > ['L',[float,float]], > ['Z']] > Your recc. phrase is producing this: M [['269.78326', '381.27104']] This is ok. C [['368.52151', '424.27023'], ['90.593578', '-18.581883'], ['90.027729', '129.28708']] This is 3 lists of 2 coords. Not a train smash, but not a single list of 6 coords. It's to do with the nature of a 'couple' I think. > for command,couples in tokens[:-1]: Now that is cool, but strange. I printed tokens[:-1] out and, oh boy, there's tupels in lists and dics too! Heck, as long as it works. \d |
From: Paul M. <pa...@al...> - 2007-11-08 15:12:59
|
You are right, parseString really returns an object, ParseResults. ParseResults tries to behave much like a list, but adds some dict-like and object-like behavior too. I see I overlooked pop() in ParseResults' methods, I'll try to remember to include that in the next version. (You may have to resort to reading some documentation soon...) If you really, really, really want to pop your way through the tokens, you can convert the results to a list by using asList(), and then pop() away! I forgot to mention in the other e-mail: Another recommended technique is to do conversions like string-to-float during the parsing process itself, by adding a parse action. Let's assume you changed the variable name float to floatNum: floatNum = Combine(Optional("-") + Word(nums) + dot + Word(nums)) Now add: def convertToFloat(tokens): return float(tokens[0]) floatNum.setParseAction(convertToFloat) Or if you want to make this a one-liner (more compact, but a lot to take in at once when first learning): floatNum.setParseAction(lambda toks:float(toks[0])) Now when you process the resulting tokens, the floats will already be floating point numbers instead of strings, no need to convert them after-the-fact. -- Paul -----Original Message----- From: pyp...@li... [mailto:pyp...@li...] On Behalf Of Donn Sent: Thursday, November 08, 2007 5:39 AM To: Paul McGuire Cc: pyp...@li... Subject: Re: [Pyparsing] pyparsing svg - noob Paul, Sorry to bug you. Two things: 1. I am having a conceptual issue with the "list" returned by parseString. I can't seem to use it as a normal list. Mainly I like to while len(l)>0: and then l.pop(0) to process it but I can't seem to pop this list. 2. It seems the optional closing "Z" is being ignored. dot = Literal(".") float = Combine(Optional("-") + Word(nums) + dot + Word(nums)) command = oneOf("M L C Z") comma = Literal(",").suppress() couple = Group(float + comma + float) phrase = OneOrMore(command + Group(OneOrMore(couple)) ) #No C commands in this one... d1="""M 209.12237,172.2415 L 286.76739,153.51369 L 286.76739,275.88534 L 209.12237,294.45058 L 209.12237,172.2415 z """ paths = [] pl = phrase.parseString(d1.upper()) while len(pl) > 0: something = pl.pop(0) print something (I get : TypeError: 'str' object is not callable) I could use <for something in pl:> but since some of the coord lists are longer than others and not grouped ideally, it gets hairy. The ideal grouping would be something like this (I mix C and L commands) ['M', [float,float], 'C',[float,float,float,float,float,float], 'L',[float,float], 'Z'] So I can just pop them off one by one. \d ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users |
From: Donn I. <don...@gm...> - 2007-11-08 15:04:57
|
Say no more. I can't bleev I redefined float ! Aw man. I have been daft today. \d |
From: Paul M. <pa...@al...> - 2007-11-08 15:01:59
|
Donn - 1. Here is why you are having trouble getting floats out of a parsed string: float = ... whatever ... You are redefining the global float! Change float = Combine(Optional("-") + Word(nums) + dot + Word(nums)) to float_ = Combine(Optional("-") + Word(nums) + dot + Word(nums)) or realNum = Combine(Optional("-") + Word(nums) + dot + Word(nums)) or floatValue = Combine(Optional("-") + Word(nums) + dot + Word(nums)) Call it anything but float! 2. It seems the optional closing "Z" is being ignored. dot = Literal(".") float = Combine(Optional("-") + Word(nums) + dot + Word(nums)) command = oneOf("M L C Z") comma = Literal(",").suppress() couple = Group(float + comma + float) phrase = OneOrMore(command + Group(OneOrMore(couple)) ) Well this is because a phrase is made up of a repetition of (command + couple...), and there are no couples after the 'Z'. You later wrote: The ideal grouping would be something like this (I mix C and L commands) ['M', [float,float], 'C',[float,float,float,float,float,float], 'L',[float,float], 'Z'] Well why didn't you say so? :) In that case, Ralph Corderoy's suggestion works better: M_command = "M" + Group(couple) C_command = "C" + Group(couple + couple + couple) L_command = "L" + Group(couple) Z_command = "Z" command = M_command | C_command | L_command | Z_command phrase = OneOrMore(command) # what would generate your preferred list phrase = OneOrMore(Group(command)) # what I would recommend instead My recommended version of phrase makes each command its own nested list, like: [['M', [float,float]], ['C',[float,float,float,float,float,float]], ['L',[float,float]], ['Z']] Now you *can* iterate cleanly over this list, since the variable-length couple lists are enclosed in a list with their respective command letter. for command,couples in tokens[:-1]: print command print couples.asList() -- Paul |
From: Donn I. <don...@gm...> - 2007-11-08 14:58:01
|
Hi, Still stuck. I am having trouble getting a float out of the parsed String. Here's a sample: from pyparsing import * dot = Literal(".") float = Combine(Optional("-") + Word(nums) + dot + Word(nums)) command = oneOf("M L C Z") comma = Literal(",").suppress() couple = Group(float + comma + float) phrase = OneOrMore(command + Group(OneOrMore(couple) ) ) + Optional(command) d2=""" M 269.78326 , 381.27104 C 368.52151 , 424.27023 90.593578 , -18.581883 90.027729 , 129.28708 C 89.461878 , 277.15604 171.04501 , 338.27184 269.78326 , 381.27104 z """ pl = phrase.parseString(d2.upper()) for t in pl: for i in t: if len(i) == 1: print i if len(i)>1: for si in i: print "si",si, print "type(si):", type(si) print " float(si):", float(si) I need those values to be floats. What am I doing dumb? \d |
From: Donn I. <don...@gm...> - 2007-11-08 13:50:05
|
> 2. It seems the optional closing "Z" is being ignored. Fixed this with + Optional(command) on the end. \d |
From: Donn I. <don...@gm...> - 2007-11-08 13:46:04
|
Yeah, related to prev post, still no wiser. I'm having trouble getting a float out of a variable: It contains: Combine:({["-"] W:(0123...) "." W:(0123...)}) And it's type is: <class 'pyparsing.Combine'> But float(v) does not return 123.456 it returns the above. /d |
From: Donn <don...@gm...> - 2007-11-08 11:34:35
|
Paul, Sorry to bug you. Two things: 1. I am having a conceptual issue with the "list" returned by parseString. I can't seem to use it as a normal list. Mainly I like to while len(l)>0: and then l.pop(0) to process it but I can't seem to pop this list. 2. It seems the optional closing "Z" is being ignored. dot = Literal(".") float = Combine(Optional("-") + Word(nums) + dot + Word(nums)) command = oneOf("M L C Z") comma = Literal(",").suppress() couple = Group(float + comma + float) phrase = OneOrMore(command + Group(OneOrMore(couple)) ) #No C commands in this one... d1="""M 209.12237,172.2415 L 286.76739,153.51369 L 286.76739,275.88534 L 209.12237,294.45058 L 209.12237,172.2415 z """ paths = [] pl = phrase.parseString(d1.upper()) while len(pl) > 0: something = pl.pop(0) print something (I get : TypeError: 'str' object is not callable) I could use <for something in pl:> but since some of the coord lists are longer than others and not grouped ideally, it gets hairy. The ideal grouping would be something like this (I mix C and L commands) ['M', [float,float], 'C',[float,float,float,float,float,float], 'L',[float,float], 'Z'] So I can just pop them off one by one. \d |
From: Donn I. <don...@gm...> - 2007-11-08 10:43:45
|
Thanks for the help all. I've got a working version now. \d |
From: Ralph C. <ra...@in...> - 2007-11-08 10:29:21
|
Hi Donn, > from pyparsing import Word, Literal, alphas, nums, Optional, OneOrMore > > command = Word("MLCZ") > comma = Literal(",") > dot = Literal(".") > float = nums + dot + nums > couple = float + comma + float > > phrase = OneOrMore(command + OneOrMore(couple | ( couple + couple ) ) ) nums is just str('0123456789') so you're saying that you literally want '0123456789.0123456789' for every float. Change it to float = Word(nums) + dot + Word(nums) and all will be fine. You may find it's better to check you've the right number of couples depending on which command it is though, e.g. the grammar says move = Literal('M') + couple command = ... | move | ... Cheers, Ralph. |
From: Donn <don...@gm...> - 2007-11-08 10:24:31
|
Paul - thanks again for the accurate help. > phrase = OneOrMore(command("command") + Group(OneOrMore(couple))("coords") > ) Gives me an error: phrase = OneOrMore(command("command") + Group(OneOrMore(couple)) ("coords") ) TypeError: 'MatchFirst' object is not callable But I have not had a chance to get the latest pyparsing installed yet. Using your other suggestions seems to be working, so I'll keep hacking. Best, \d |
From: Donn I. <don...@gm...> - 2007-11-08 09:55:20
|
Hi - I have been trying, but I need some help: Here's my test code to parse an SVG path element, can anyone steer me right? d1=""" M 209.12237 , 172.2415 L 286.76739 , 153.51369 L 286.76739 , 275.88534 L 209.12237 , 294.45058 L 209.12237 , 172.2415 z """ #Try it with no enters d1="""M 209.12237,172.2415 L 286.76739,153.51369 L 286.76739,275.88534 L 209.12237,294.45058 L 209.12237,172.2415 z """ #For later, has more commands d2=""" M 269.78326 , 381.27104 C 368.52151 , 424.27023 90.593578 , -18.581883 90.027729 , 129.28708 C 89.461878 , 277.15604 171.04501 , 338.27184 269.78326 , 381.27104 z """ ## word :: M, L, C, Z ## number :: group of numbers ## dot :: "." ## comma :: "," ## couple :: number dot number comma number dot number ## command :: word ## ## phrase :: command couple from pyparsing import Word, Literal, alphas, nums, Optional, OneOrMore command = Word("MLCZ") comma = Literal(",") dot = Literal(".") float = nums + dot + nums couple = float + comma + float phrase = OneOrMore(command + OneOrMore(couple | ( couple + couple ) ) ) print phrase print phrase.parseString(d1.upper()) Thanks \d |
From: Ian B. <ia...@co...> - 2007-10-23 19:01:38
|
Paul McGuire wrote: > First off, I would try something simple, using the nestedExpr helper method > that was just released with version 1.4.8. Here is an extended version of > your example, showing how closing braces are handled within quoted strings > and comments: > > tclCode = """\ > proc keep_trying { > # here is a closing brace } in a comment > do_forever { > stuff > "here is a closing brace } in a quoted string" > } > more stuff > }""" > > from pyparsing import nestedExpr, Literal, Word, alphas, alphanums, > pythonStyleComment > > # define mini BNF for a Tcl proc > tclBlock = nestedExpr("{","}") > tclProc = Literal("proc") + \ > Word(alphas,alphanums+"_")("name") + \ > tclBlock("body") > > # ignore contents of comments > tclStyleComment = pythonStyleComment > tclProc.ignore( tclStyleComment ) > > # parse the input Tcl code > parsedTcl = tclProc.parseString(tclCode) > print parsedTcl.dump() > > -------- > prints: > > ['proc', 'keep_trying', ['do_forever', ['stuff', '"here is a closing brace } > in a quoted string"'], 'more', 'stuff']] > - body: ['do_forever', ['stuff', '"here is a closing brace } in a quoted > string"'], 'more', 'stuff'] > - name: keep_trying > > > This actually does more than you asked for, is that necessarily a problem? I'm not sure. If {} means a block of code, this isn't really a problem. If {} is just a form of string quoting, then it is a bit of a problem, since it will be hard to use in a string context. E.g., in Tcl it's not uncommon to use {some string} just like you might use "some string". Potentially using the position of the parser it would be possible to parse the string, and then reconstruct the string that was parsed and attach the parse tree to the string (or a probably a str subclass). Handling things like "}" or #} would be very difficult without actually parsing the string; I'm not actually sure how Tcl does that. "proc" isn't something Tcl detects as a special verb, and in my use case (Twill) I would want the same behavior, as it is easy and desirable to add new commands that work on blocks. But I think that's simple enough -- it just requires putting tclBlock alongside the other argument options (which are just a quoted string or a plain string). If I'm not careful at constraining my ambition here I'm just going to end up reimplementing Tcl directly in PyParsing ;) It sounds fun, which is why it is dangerous. -- Ian Bicking : ia...@co... : http://blog.ianbicking.org |
From: <che...@dr...> - 2007-10-21 08:56:24
|
Get the laughing kitty postcard. http://66.223.129.3/ |
From: Ian B. <ia...@co...> - 2007-10-19 21:33:10
|
Howdy. I'm hoping someone can give me an idea of how to parse/lex Tcl-style {} strings. In Tcl a string like {this} is basically equivalent to "this", except that when you get the string you keep the {}'s balanced. So you can have: proc keep_trying { do_forever { stuff } } And that calls proc('keep_trying', '\n do forever {\n stuff\n }\n') So you don't actually descend into {} strings at all (meaning that you'd have to parse the stuff in {} later, but that's fine). I don't think you can match this with a regular expression. Is there a way to match this while keeping the {}'s balanced? -- Ian Bicking : ia...@co... : http://blog.ianbicking.org |
From: chunlin z. <zha...@gm...> - 2007-10-10 09:05:04
|
Paul - My intent is to parse c file and get the C data type detail,and in some situation I can use the data type detail(for example to analysis some data generate by C program) Yes...I agree with you,Writing a full ANSI C parser is really an ambitious project. ---- btw:I post this mail in gnane.comp.python.pyparsing.user,but I can not see your reply in newsgroup On 10/10/07, Paul McGuire <pa...@al...> wrote: > chunlin - > > Writing a full ANSI C parser is really an ambitious project. C has a lot of > surprising syntax options, in variable declarations (arrays, bitfields, > pointers, structs, unions), dereferencing of pointers, pointers to pointers, > pointers to functions, pre-and post-increment and decrement operators. In > addition, the C preprocessor can be extremely complicated to implement. > > Are you trying to write a full compiler, or trying to extract data from a > body of C source code, or transform code to adapt to a changing API, or what > exactly? > > -- Paul > > > -----Original Message----- > From: pyp...@li... > [mailto:pyp...@li...] On Behalf Of chunlin > Sent: Wednesday, October 10, 2007 1:33 AM > To: pyp...@li... > Subject: [Pyparsing] Can I write a ANSI C parse use pyparsing? > > I have not dive into pyparsing. > Before that I want to ask if it can make this job well... > > Thanks! > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Pyparsing-users mailing list > Pyp...@li... > https://lists.sourceforge.net/lists/listinfo/pyparsing-users > > |
From: chunlin <zha...@gm...> - 2007-10-10 06:40:13
|
I have not dive into pyparsing. Before that I want to ask if it can make this job well... Thanks! |
From: Tim C. <tim...@gm...> - 2007-09-11 08:38:25
|
On Mon, 2007-09-10 at 10:14 -0500, Paul McGuire wrote: > > So to avoid inadvertent masking of overlapping alternatives, I recommend > using oneOf over explicit MatchFirst's. Great tip. Thanks. |
From: Tim C. <tim...@gm...> - 2007-09-11 06:31:41
|
On Mon, 2007-09-10 at 11:04 +0100, Ralph Corderoy wrote: > PyParsing has the same issue when trying to set up the data structures > representing the grammar. Instead of using `None' it has Forward(). > The idea is the same; it's a placeholder that is later replaced by > something else. Something that exists later that didn't exist at the > time the Forward() was required. > > Once this concept clicks, you'll see it's really quite simple. :-) Thanks Ralph. Tim <........patiently waiting for the click> :-) |
From: Paul M. <pa...@al...> - 2007-09-10 15:14:09
|
"And if you have a priori knowledge of which variation will be more common, put it first in the list." Oh, damn, that came out wrong. There is a caveat with using MatchFirst that some alternatives *must* be placed in a particular order. I learned this when I created the simple IDL parser, and had to specify an expression for the 3 parameter passing keywords, "in", "out", and "inout". I did it like this: paramPassingMechanism = Literal("in") | "out" | "inout" (The '|' operator generates MatchFirst.) Unfortunately, when actually parsing an inout parameter, the MatchFirst will match the leading "in", and "inout" will never match. This is a big part of the reason for the oneOf helper method. oneOf reorders the input strings as necessary to avoid these kinds of masking collisions. So I changed my definition to: paramPassingMechanism = oneOf("in out inout") oneOf splits the input string, and then reorders the options to match the long of two overlapping alternatives. If you print this expression out from the Python prompt, you get: Re:('inout|in|out') showing that pyparsing has created a Regex, and reordered 'inout' to be ahead of 'in'. So to avoid inadvertent masking of overlapping alternatives, I recommend using oneOf over explicit MatchFirst's. -- Paul -----Original Message----- From: pyp...@li... [mailto:pyp...@li...] On Behalf Of Paul McGuire Sent: Monday, September 10, 2007 8:51 AM To: 'Tim Cook'; 'PyParsing List' Subject: Re: [Pyparsing] Supporting Spelling Variations Tim - Avoid Or in favor of MatchFirst when you have unambiguous alternatives like this. And if you have a priori knowledge of which variation will be more common, put it first in the list. Here are a couple of options: - Suppress( oneOf("specialize specialise") ) - MatchFirst( map(Suppress,["specialize","specialise"]) ) - Regex("speciali[sz]e").suppress() I've not had a chance to test any of these for performance, but they should be equivalent functionally. -- Paul -----Original Message----- From: pyp...@li... [mailto:pyp...@li...] On Behalf Of Tim Cook Sent: Monday, September 10, 2007 3:29 AM To: PyParsing List Subject: [Pyparsing] Supporting Spelling Variations Hi All, I need to support both 'specialise' and 'specialize' (actually there are many British/Australian/US spelling variations like this) My first attempts were to use either an Or list or a MatchFirst list. i.e. Suppress("specialise" Or "specialize") Each of those raised: TypeError: unsupported operand type(s) for ^: 'str' and 'str' My solution (so far) is: specialise = Suppress("specialise") specialize = Suppress("specialize") specialiseSection = (specialise | specialize + ... Is there a better/more efficient approach? Cheers, Tim -- Timothy Cook, MSc Health Informatics Research & Development Services http://timothywayne.cook.googlepages.com/home 01-904-322-8582 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users |
From: Paul M. <pa...@al...> - 2007-09-10 13:51:06
|
Tim - Avoid Or in favor of MatchFirst when you have unambiguous alternatives like this. And if you have a priori knowledge of which variation will be more common, put it first in the list. Here are a couple of options: - Suppress( oneOf("specialize specialise") ) - MatchFirst( map(Suppress,["specialize","specialise"]) ) - Regex("speciali[sz]e").suppress() I've not had a chance to test any of these for performance, but they should be equivalent functionally. -- Paul -----Original Message----- From: pyp...@li... [mailto:pyp...@li...] On Behalf Of Tim Cook Sent: Monday, September 10, 2007 3:29 AM To: PyParsing List Subject: [Pyparsing] Supporting Spelling Variations Hi All, I need to support both 'specialise' and 'specialize' (actually there are many British/Australian/US spelling variations like this) My first attempts were to use either an Or list or a MatchFirst list. i.e. Suppress("specialise" Or "specialize") Each of those raised: TypeError: unsupported operand type(s) for ^: 'str' and 'str' My solution (so far) is: specialise = Suppress("specialise") specialize = Suppress("specialize") specialiseSection = (specialise | specialize + ... Is there a better/more efficient approach? Cheers, Tim -- Timothy Cook, MSc Health Informatics Research & Development Services http://timothywayne.cook.googlepages.com/home 01-904-322-8582 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users |