pyparsing-users Mailing List for Python parsing module (Page 10)
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: thomas_h <th...@gm...> - 2011-09-17 19:02:58
|
Sorry, I botched these two examples. They should read: > py.Regex(r'^\s*B', re.M).searchString('foo\nB') and > py.Regex(r'^\s*B', re.M).searchString('foo\n B') (I wanted to get away from the '*' special character). Thomas |
From: thomas_h <th...@gm...> - 2011-09-17 18:59:08
|
Paul, thanks for looking into this. On Mon, Sep 12, 2011 at 12:13 PM, Paul McGuire <pt...@au...> wrote: > The snag here is pyparsing's default whitespace skipping. You are leading > off your Regex with whitespace, but pyparsing skips over that stuff unless > you tell it not to. I see. I was aware of the whitespace skipping, and thought the '*' quantifier after '\s' would take care of this. So in the case that the regex wouldn't see the whitespace at all '^\s*\*' should still match. But it doesn't. > This expression gives you your inner comment lines (the > negative lookahead expression '(?!/)' tells the re engine not to match if > the '*' is followed by a '/', the the trailing '*/' line is left out). > > comment_inner = Regex(r"^\s+\*(?!/).*", re.M).leaveWhitespace() This is working nicely, but I'm still concerned about the '^' anchor. If you speak about skipping whitespace, I suppose this includes newlines?! Then why is the '$' anchor working as expected, but '^' isn't? Looking further into this, I found that py.Regex(r'^\s*\*', re.M).searchString('foo\nB') matches, while py.Regex(r'^\s*\*', re.M).searchString('foo\n B') doesn't (mind the additional space towards the end of the search string). So, even without leaveWhitespace(), the start-of-line anchor seems to be honored, if there is no subsequent white space. But if there is, the match fails. Again, using the end-of-line anchor it matches as expected, and white space seems to be passed to the regex (which is what I initially expected): py.Regex(r'o\s*$', re.M).searchString('foo \nB') This matches with or without intervening space between the second 'o' and '\n', and potential whitespace is included in the match. Thomas |
From: Paul M. <pt...@au...> - 2011-09-12 14:51:13
|
First off, you have some mixed spaces/tabs in your file, you should clean that up. By using '^' operators inside a Forward recursive expression, your parser is doing a lot of extra work. I got some better response by changing the commented lines below: #~ value = Word(alphas) + ( ( sls + SkipTo(']',include=False)+srs ) ^ Word(alphas +"_") ) value = Word(alphas) + ( ( sls + SkipTo(']',include=False)+srs ) | Word(alphas +"_") ) value.setParseAction(p_val) named_block = Forward() #~ block_content = OneOrMore( value ^ named_block ) block_content = OneOrMore( named_block | value ) named_block << OneOrMore(Word(alphas)) + slc + block_content + src named_block.setParseAction( p_nb ) named_block.ignore(pythonStyleComment) #~ named_block.enablePackrat() There were 3.2 million calls to "hash", most likely due to the packrat parsing. By changing Or's to MatchFirst's, the packratting was not necessary, and was in fact costing extra performance. -- Paul -----Original Message----- From: Max...@dl... [mailto:Max...@dl...] Sent: Monday, September 12, 2011 7:10 AM To: pyp...@li... Subject: [Pyparsing] Parsing large files using SkipTo is slow. Hello, I am trying to parse a simple CAD file using pyparsing, where the grammar is quite simple and most of the lines of the file are supposed to be skipped. However this is still slower than I would expect it to be. The parser is in the parse_iv.py file, the CAD file is the screwdriver_2.iv and the CProfile result is th err file. It seems like parseString is called for each line. I don't understand the internal workings of pyparsing but would it be possible to use something like file.index( skiptostr ) to speed things up? ftp://ftp.robotic.dlr.de/outgoing/Argus/ BR, Max ---------------------------------------------------------------------------- -- Doing More with Less: The Next Generation Virtual Desktop What are the key obstacles that have prevented many mid-market businesses from deploying virtual desktops? How do next-generation virtual desktops provide companies an easier-to-deploy, easier-to-manage and more affordable virtual desktop model.http://www.accelacomm.com/jaw/sfnl/114/51426474/ _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users |
From: Ralph C. <ra...@in...> - 2011-09-12 14:06:38
|
Hi Paul, > > ftp://ftp.robotic.dlr.de/outgoing/Argus/ > > The FTP link you posted does not respond for me. Can you try posting > code and any ASCII files at pastebin.com? Try ftp://ftp.dlr.de/robotic/outgoing/Argus/ Cheers, Ralph. |
From: Paul M. <pt...@au...> - 2011-09-12 12:48:11
|
Max - The FTP link you posted does not respond for me. Can you try posting code and any ASCII files at pastebin.com? -- Paul -----Original Message----- From: Max...@dl... [mailto:Max...@dl...] Sent: Monday, September 12, 2011 6:06 AM To: pyp...@li... Subject: [Pyparsing] Parsing large files using SkipTo is slow. Hello, I am trying to parse a simple CAD file using pyparsing, where the grammar is quite simple and most of the lines of the file are supposed to be skipped. However this is still slower than I would expect it to be. The parser is in the parse_iv.py file, the CAD file is the screwdriver_2.iv and the CProfile result is th err file. It seems like parseString is called for each line. I don't understand the internal workings of pyparsing but would it be possible to use something like file.index( skiptostr ) to speed things up? ftp://ftp.robotic.dlr.de/outgoing/Argus/ BR, Max ---------------------------------------------------------------------------- -- Doing More with Less: The Next Generation Virtual Desktop What are the key obstacles that have prevented many mid-market businesses from deploying virtual desktops? How do next-generation virtual desktops provide companies an easier-to-deploy, easier-to-manage and more affordable virtual desktop model.http://www.accelacomm.com/jaw/sfnl/114/51426474/ _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users |
From: Ralph C. <ra...@in...> - 2011-09-12 12:43:34
|
Hi Max, Your email has reached the list, several times, please stop sending it. :-) Cheers, Ralph. |
From: <Max...@dl...> - 2011-09-12 12:10:34
|
Hello, I am trying to parse a simple CAD file using pyparsing, where the grammar is quite simple and most of the lines of the file are supposed to be skipped. However this is still slower than I would expect it to be. The parser is in the parse_iv.py file, the CAD file is the screwdriver_2.iv and the CProfile result is th err file. It seems like parseString is called for each line. I don't understand the internal workings of pyparsing but would it be possible to use something like file.index( skiptostr ) to speed things up? ftp://ftp.robotic.dlr.de/outgoing/Argus/ BR, Max |
From: <Max...@dl...> - 2011-09-12 11:54:07
|
Hello, I am trying to parse a simple CAD file using pyparsing, where the grammar is quite simple and most of the lines of the file are supposed to be skipped. However this is still slower than I would expect it to be. The parser is in the parse_iv.py file, the CAD file is the screwdriver_2.iv and the CProfile result is th err file. It seems like parseString is called for each line. I don't understand the internal workings of pyparsing but would it be possible to use something like file.index( skiptostr ) to speed things up? ftp://ftp.robotic.dlr.de/outgoing/Argus/ BR, Max |
From: <Max...@dl...> - 2011-09-12 11:54:07
|
Hello, I am trying to parse a simple CAD file using pyparsing, where the grammar is quite simple and most of the lines of the file are supposed to be skipped. However this is still slower than I would expect it to be. The parser is in the parse_iv.py file, the CAD file is the screwdriver_2.iv and the CProfile result is th err file. It seems like parseString is called for each line. I don't understand the internal workings of pyparsing but would it be possible to use something like file.index( skiptostr ) to speed things up? ftp://ftp.robotic.dlr.de/outgoing/Argus/ BR, Max |
From: <Max...@dl...> - 2011-09-12 11:20:10
|
Hello, I am trying to parse a simple CAD file using pyparsing, where the grammar is quite simple and most of the lines of the file are supposed to be skipped. However this is still slower than I would expect it to be. The parser is in the parse_iv.py file, the CAD file is the screwdriver_2.iv and the CProfile result is th err file. It seems like parseString is called for each line. I don't understand the internal workings of pyparsing but would it be possible to use something like file.index( skiptostr ) to speed things up? ftp://ftp.robotic.dlr.de/outgoing/Argus/ BR, Max |
From: <Max...@dl...> - 2011-09-12 11:20:09
|
Hello, I am trying to parse a simple CAD file using pyparsing, where the grammar is quite simple and most of the lines of the file are supposed to be skipped. However this is still slower than I would expect it to be. The parser is in the parse_iv.py file, the CAD file is the screwdriver_2.iv and the CProfile result is th err file. It seems like parseString is called for each line. I don't understand the internal workings of pyparsing but would it be possible to use something like file.index( skiptostr ) to speed things up? ftp://ftp.robotic.dlr.de/outgoing/Argus/ BR, Max |
From: <Max...@dl...> - 2011-09-12 11:05:54
|
Hello, I am trying to parse a simple CAD file using pyparsing, where the grammar is quite simple and most of the lines of the file are supposed to be skipped. However this is still slower than I would expect it to be. The parser is in the parse_iv.py file, the CAD file is the screwdriver_2.iv and the CProfile result is th err file. It seems like parseString is called for each line. I don't understand the internal workings of pyparsing but would it be possible to use something like file.index( skiptostr ) to speed things up? ftp://ftp.robotic.dlr.de/outgoing/Argus/ BR, Max |
From: Paul M. <pt...@au...> - 2011-09-12 10:13:19
|
The snag here is pyparsing's default whitespace skipping. You are leading off your Regex with whitespace, but pyparsing skips over that stuff unless you tell it not to. This expression gives you your inner comment lines (the negative lookahead expression '(?!/)' tells the re engine not to match if the '*' is followed by a '/', the the trailing '*/' line is left out). comment_inner = Regex(r"^\s+\*(?!/).*", re.M).leaveWhitespace() I played with this a little bit, and this Regex will give you a named group 'body', which pyparsing will convert to a results name that you can access directly: comment_inner = Regex(r"^(\s+\*)+(?!/)\s*(?P<body>.*)", re.M).leaveWhitespace() print '\n'.join(s.body for s in comment_inner.searchString(comment)) Prints: Checks if a class is compatible to the given mixin (no conflicts) @param mixin {Mixin} mixin to check @param clazz {Class} class to check @throws an exception when the given mixin is incompatible to the class @return {Boolean} true if the mixin is compatible to the given class I'm glad to hear you are finding pyparsing to be useful! -- Paul -----Original Message----- From: thomas_h [mailto:th...@gm...] Sent: Wednesday, August 31, 2011 4:51 AM To: pyp...@li... Subject: [Pyparsing] Anchoring py.Regex Hi, first off, thanks for pyparsing - great stuff. Using pyparsing 1.5.5, I'm struggling with using the ^ anchor in a regular expression passed to py.Regex. E.g. if my input string is comment = ''' /** * Checks if a class is compatible to the given mixin (no conflicts) * * @param mixin {Mixin} mixin to check * @param clazz {Class} class to check * @throws an exception when the given mixin is incompatible to the class * @return {Boolean} true if the mixin is compatible to the given class */ ''' I want to match in my grammar the " *" prefix that precedes each payload in a line (except the first and last, of course). I tried py.Regex(r'^\s*\*', re.M).searchString(comment) which gives me just ([], {}). Leaving away the ^ anchor, I get all expected matches. Also using the $ anchor, e.g. in py.Regex(r'k$', re.M).searchString(comment) it seems to work and I get all expected matches (from the "... check" lines). So what am I doing wrong with ^? Thomas |
From: gyro f. <gyr...@gm...> - 2011-09-08 17:08:17
|
On 2011-09-08 9:49 AM, Mark Tolonen wrote: > > "gyro funch" <gyr...@gm...> wrote in message > news:4E6...@gm...... >> Hi, >> >> I have a set of strings that look similar to this: >> >> N1-(N2,N3-(N4,N5),N6-(N7,N8-(N9,N10),N11)) >> >> Each string essentially represents a tree structure, where the 'N#' >> represent nodes and the '-' are connections or edges. Entries in >> parentheses represent branches from the previous node. >> >> I would like to parse the string and then enumerate all of the paths >> through the tree, starting at the root and out to each leaf. >> >> In the case of the above string, the desired output would be as follows: >> >> N1-N2 >> N1-N3-N4 >> N1-N3-N5 >> N1-N6-N7 >> N1-N6-N11 >> N1-N6-N8-N9 >> N1-N6-N8-N10 >> >> >> I would greatly appreciate hints on how to use Pyparsing to help >> achieve this functionality. > > Use a recursive grammar: > > from pyparsing import * > name = Word('N',nums) > node = Forward() > nodeList = delimitedList(node) > node << Group(name + Group(Optional(Suppress('-(') + nodeList + > Suppress(')')))) > > s = "N1-(N2,N3-(N4,N5),N6-(N7,N8-(N9,N10),N11))" > > tree = node.parseString(s) > print tree > > This generates nodes in the format "[name,[child,...]]": > > [['N1', [['N2', []], ['N3', [['N4', []], ['N5', []]]], ['N6', [['N7', []], > ['N8', [['N9', []], ['N10', []]]], ['N11', []]]]]]] > > Here's a function to display it in the format you require: > > def traverse(node): > if node[1]: > for n in node[1]: > for item in traverse(n): > yield '{}-{}'.format(node[0],item) > else: > yield node[0] > > for item in traverse(tree[0]): > print item > > Output: > > N1-N2 > N1-N3-N4 > N1-N3-N5 > N1-N6-N7 > N1-N6-N8-N9 > N1-N6-N8-N10 > N1-N6-N11 > > -Mark > > Thanks, Mark! That was *extremely* helpful. -gyro |
From: Mark T. <met...@gm...> - 2011-09-08 16:05:19
|
"gyro funch" <gyr...@gm...> wrote in message news:4E6...@gm...... > Hi, > > I have a set of strings that look similar to this: > > N1-(N2,N3-(N4,N5),N6-(N7,N8-(N9,N10),N11)) > > Each string essentially represents a tree structure, where the 'N#' > represent nodes and the '-' are connections or edges. Entries in > parentheses represent branches from the previous node. > > I would like to parse the string and then enumerate all of the paths > through the tree, starting at the root and out to each leaf. > > In the case of the above string, the desired output would be as follows: > > N1-N2 > N1-N3-N4 > N1-N3-N5 > N1-N6-N7 > N1-N6-N11 > N1-N6-N8-N9 > N1-N6-N8-N10 > > > I would greatly appreciate hints on how to use Pyparsing to help > achieve this functionality. Use a recursive grammar: from pyparsing import * name = Word('N',nums) node = Forward() nodeList = delimitedList(node) node << Group(name + Group(Optional(Suppress('-(') + nodeList + Suppress(')')))) s = "N1-(N2,N3-(N4,N5),N6-(N7,N8-(N9,N10),N11))" tree = node.parseString(s) print tree This generates nodes in the format "[name,[child,...]]": [['N1', [['N2', []], ['N3', [['N4', []], ['N5', []]]], ['N6', [['N7', []], ['N8', [['N9', []], ['N10', []]]], ['N11', []]]]]]] Here's a function to display it in the format you require: def traverse(node): if node[1]: for n in node[1]: for item in traverse(n): yield '{}-{}'.format(node[0],item) else: yield node[0] for item in traverse(tree[0]): print item Output: N1-N2 N1-N3-N4 N1-N3-N5 N1-N6-N7 N1-N6-N8-N9 N1-N6-N8-N10 N1-N6-N11 -Mark |
From: gyro f. <gyr...@gm...> - 2011-09-05 00:47:11
|
Hi, I have a set of strings that look similar to this: N1-(N2,N3-(N4,N5),N6-(N7,N8-(N9,N10),N11)) Each string essentially represents a tree structure, where the 'N#' represent nodes and the '-' are connections or edges. Entries in parentheses represent branches from the previous node. I would like to parse the string and then enumerate all of the paths through the tree, starting at the root and out to each leaf. In the case of the above string, the desired output would be as follows: N1-N2 N1-N3-N4 N1-N3-N5 N1-N6-N7 N1-N6-N11 N1-N6-N8-N9 N1-N6-N8-N10 I would greatly appreciate hints on how to use Pyparsing to help achieve this functionality. Thank you. -g |
From: thomas_h <th...@gm...> - 2011-08-31 09:50:43
|
Hi, first off, thanks for pyparsing - great stuff. Using pyparsing 1.5.5, I'm struggling with using the ^ anchor in a regular expression passed to py.Regex. E.g. if my input string is comment = ''' /** * Checks if a class is compatible to the given mixin (no conflicts) * * @param mixin {Mixin} mixin to check * @param clazz {Class} class to check * @throws an exception when the given mixin is incompatible to the class * @return {Boolean} true if the mixin is compatible to the given class */ ''' I want to match in my grammar the " *" prefix that precedes each payload in a line (except the first and last, of course). I tried py.Regex(r'^\s*\*', re.M).searchString(comment) which gives me just ([], {}). Leaving away the ^ anchor, I get all expected matches. Also using the $ anchor, e.g. in py.Regex(r'k$', re.M).searchString(comment) it seems to work and I get all expected matches (from the "... check" lines). So what am I doing wrong with ^? Thomas |
From: Haifeng <min...@gm...> - 2011-08-24 23:07:16
|
Thanks a lot for the response. I was trying to apply part of C grammar in my small parser. Your answer solved my problem. Haifeng On Mon, Aug 22, 2011 at 10:57 PM, Paul McGuire <pt...@au...> wrote: > Haifeng - > > You have 2 problems going on here: > - you are matching 'a' before trying to match 'a->b'; the leading 'a' will > match, and the trailing '->b' will then raise an error > - you have defined a left-recursive expression (to match 'a->b', you will > try to match 'a->b', but first you will match 'a->b', etc.); the > left-recursion is what validate() is complaining about > > Pyparsing is not like lex/yacc or LR parsers - it works purely > left-to-right > through the input text, according to the definitions in the grammar. There > is no lookahead to try to achieve longer matches, as is done in regular > expressions. In pyparsing expressions, the '|' is a short-circuiting > alternative operator, creating MatchFirst expressions: the first > alternative > expression to match will be the "winner", even if a later alternative might > match a longer part of the input string. You can force all alternatives to > be tested for matching (with the longest match chosen) using the '^' > operator, which creates Or expressions. > > Pyparsing does not allow you to directly implement a BNF definition, since > BNF follows different rules for matching, and has different constraints for > notation. There is more description of the BNF->pyparsing process here > (http://pyparsing.wikispaces.com/message/view/home/11262229 and > http://pyparsing.wikispaces.com/message/view/home/41102255). > > You use some terms like "postfix" in your grammar, but I don't see a lot of > postfixing going on. You do describe an infix '->' operator, but this too > is somewhat confusing; in your example, you just show "a->b", but from your > implementation, it looks like you want to support unbounded repetition, > presumably something like "a->b->c->d". > > To implement your grammar to parse your two examples, you would write: > > ARROW = Literal('->') > identifier = Word(alphas+"_", alphanums+"_") > > primary_expression = identifier > compound_expression = identifier + ARROW + identifier > > # must test for compound_expression before primary_expression > expression = compound_expression | primary_expression > > > To add repetition to compound_expression, you could simply change it to: > > compound_expression = identifier + OneOrMore(ARROW + identifier) > > > -- Paul > > > > -----Original Message----- > From: Haifeng [mailto:min...@gm...] > Sent: Sunday, August 21, 2011 2:43 AM > To: pyp...@li... > Subject: [Pyparsing] [pyparsing] RecursiveGrammarException > > Hi > > I am new to pyparsing. I am trying to parse just the following C > expressions: > a > a->b > > My code looks like: > > from pyparsing import * > > ARROW = Literal('->') > identifier = Word(alphas+"_", alphanums+"_") > > primary_expression = identifier > > postfix_expression = Forward() > postfix_expression << ( primary_expression | (postfix_expression + ARROW + > identifier)) > > But it failed on postfix_expression.validate(). What did I do wrongly here? > Thanks > > ---------------------------------------------------------------------------- > -- > Get a FREE DOWNLOAD! and learn more about uberSVN rich system, > user administration capabilities and model configuration. Take > the hassle out of deploying and managing Subversion and the > tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2 > _______________________________________________ > Pyparsing-users mailing list > Pyp...@li... > https://lists.sourceforge.net/lists/listinfo/pyparsing-users > > |
From: Paul M. <pt...@au...> - 2011-08-23 05:58:35
|
Haifeng - You have 2 problems going on here: - you are matching 'a' before trying to match 'a->b'; the leading 'a' will match, and the trailing '->b' will then raise an error - you have defined a left-recursive expression (to match 'a->b', you will try to match 'a->b', but first you will match 'a->b', etc.); the left-recursion is what validate() is complaining about Pyparsing is not like lex/yacc or LR parsers - it works purely left-to-right through the input text, according to the definitions in the grammar. There is no lookahead to try to achieve longer matches, as is done in regular expressions. In pyparsing expressions, the '|' is a short-circuiting alternative operator, creating MatchFirst expressions: the first alternative expression to match will be the "winner", even if a later alternative might match a longer part of the input string. You can force all alternatives to be tested for matching (with the longest match chosen) using the '^' operator, which creates Or expressions. Pyparsing does not allow you to directly implement a BNF definition, since BNF follows different rules for matching, and has different constraints for notation. There is more description of the BNF->pyparsing process here (http://pyparsing.wikispaces.com/message/view/home/11262229 and http://pyparsing.wikispaces.com/message/view/home/41102255). You use some terms like "postfix" in your grammar, but I don't see a lot of postfixing going on. You do describe an infix '->' operator, but this too is somewhat confusing; in your example, you just show "a->b", but from your implementation, it looks like you want to support unbounded repetition, presumably something like "a->b->c->d". To implement your grammar to parse your two examples, you would write: ARROW = Literal('->') identifier = Word(alphas+"_", alphanums+"_") primary_expression = identifier compound_expression = identifier + ARROW + identifier # must test for compound_expression before primary_expression expression = compound_expression | primary_expression To add repetition to compound_expression, you could simply change it to: compound_expression = identifier + OneOrMore(ARROW + identifier) -- Paul -----Original Message----- From: Haifeng [mailto:min...@gm...] Sent: Sunday, August 21, 2011 2:43 AM To: pyp...@li... Subject: [Pyparsing] [pyparsing] RecursiveGrammarException Hi I am new to pyparsing. I am trying to parse just the following C expressions: a a->b My code looks like: from pyparsing import * ARROW = Literal('->') identifier = Word(alphas+"_", alphanums+"_") primary_expression = identifier postfix_expression = Forward() postfix_expression << ( primary_expression | (postfix_expression + ARROW + identifier)) But it failed on postfix_expression.validate(). What did I do wrongly here? Thanks ---------------------------------------------------------------------------- -- Get a FREE DOWNLOAD! and learn more about uberSVN rich system, user administration capabilities and model configuration. Take the hassle out of deploying and managing Subversion and the tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2 _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users |
From: Haifeng <min...@gm...> - 2011-08-21 07:43:29
|
Hi I am new to pyparsing. I am trying to parse just the following C expressions: a a->b My code looks like: from pyparsing import * ARROW = Literal('->') identifier = Word(alphas+"_", alphanums+"_") primary_expression = identifier postfix_expression = Forward() postfix_expression << ( primary_expression | (postfix_expression + ARROW + identifier)) But it failed on postfix_expression.validate(). What did I do wrongly here? Thanks |
From: Paul M. <pt...@au...> - 2011-08-09 12:08:13
|
List members beware - do not click the link in Gre7g Luterman's list message! -----Original Message----- From: Gre7g Luterman [mailto:haf...@ya...] Sent: Tuesday, August 09, 2011 6:34 AM To: pyp...@li...; st...@gm...; st...@ya...; Tod...@fc...; aw...@t-... Subject: [Pyparsing] (no subject) http://dvdmoviesandtapes.<<rest of bogus URL elided>> ---------------------------------------------------------------------------- -- uberSVN's rich system and user administration capabilities and model configuration take the hassle out of deploying and managing Subversion and the tools developers use with it. Learn more about uberSVN and get a free download at: http://p.sf.net/sfu/wandisco-dev2dev _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users |
From: Gre7g L. <haf...@ya...> - 2011-08-09 11:34:31
|
http://dvdmoviesandtapes.com/store/admin/backups/love.php?html72 |
From: Paul M. <pt...@au...> - 2011-08-04 14:08:59
|
Rita - There are really two parts to your question - how to parse the expression you've given, and then how to construct a useful data structure from it. >From your example, I haven't gone too far into creating a true parent-child graph, I'm just implementing the problem as you have stated it. Here is a little annotated script to try: from pyparsing import Suppress, Word, alphas, alphanums, Literal, Group, delimitedList # define basic punctuation, operators, and our parentage item LPAR,RPAR = map(Suppress, '()') parentOp = Literal("->") item = Word(alphas, alphanums) # define a group of possible items, as in '(b|c)' altItems = Group(LPAR + delimitedList(item,'|') + RPAR) # define a hierarchy expression as a list of items delimited by parentOps hierarchyExpr = delimitedList(item | altItems, parentOp) # parse the test string testStr = "a -> (b|c) -> d" gens = hierarchyExpr.parseString(testStr) # use zip to convert the list of hierarchy entries into parent-child pairs for parent,child in zip(gens,gens[1:]): print 'parent', ' '.join(parent), 'child', ' '.join(child) See if that gets you further along. -- Paul -----Original Message----- From: Rita [mailto:rmo...@gm...] Sent: Wednesday, August 03, 2011 6:18 PM To: pyp...@li... Subject: [Pyparsing] parse algebra like expressions Hello, I would like to parse a string into something like this str = "a -> (b|c) -> d" This should generate parent a child b c parent b c child d Any ideas how I can do this with pyparse? -- --- Get your facts first, then you can distort them as you please.-- ---------------------------------------------------------------------------- -- BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA The must-attend event for mobile developers. Connect with experts. Get tools for creating Super Apps. See the latest technologies. Sessions, hands-on labs, demos & much more. Register early & save! http://p.sf.net/sfu/rim-blackberry-1 _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users |
From: Rita <rmo...@gm...> - 2011-08-03 23:18:12
|
Hello, I would like to parse a string into something like this str = "a -> (b|c) -> d" This should generate parent a child b c parent b c child d Any ideas how I can do this with pyparse? -- --- Get your facts first, then you can distort them as you please.-- |
From: cathal c. <cof...@gm...> - 2011-07-02 23:19:17
|
Paul, I much prefer the new form of setResultsName(), its much more elegant. Thank you for the descriptive example, it really aided in my understanding. I've been building a project using pyparsing for about a month now. In this time I have learnt so much about pyparsing that I keep rewriting my project: making it faster, more expressive and succinct. Thank you for pyparsing, I haven't had this much fun in ages. Cathal (from Ireland) |