Re: [Pyparsing] setParseAction()
Brought to you by:
ptmcg
From: Athanasios A. <ath...@gm...> - 2014-08-29 12:29:08
|
Hello Andreas I briefly had a look at your example and I noticed two things: 1) Do you really need your parsed string to be enclosed in three single quotes? 2) The error you are getting is reasonable. The rule p expects to start at the beginning of the parsed string. Be defining g as 'b'+p, you are placing rule p AFTER the beginning of the line (which is where the character 'b' will be). Removing LineStart and enclosing the last string in single quotes (and of course, escaping the line breaks) seems to be working as expected (?). If you want to parse the string EXACTLY as it appears (including the line breaks) you will have to include them in your rules. Hope this helps AA On Thu, Aug 28, 2014 at 10:56 PM, Andreas Matthias < and...@gm...> wrote: > The following example works as expected. But if I uncomment the > line ``p.setParseAction(foo)'' I get the error: > > pyparsing.ParseException: Expected start of line (at char 1), (line:1, > col:1) > > I do not understand what's going on here. Any help? > > Ciao > Andreas > > > > import pyparsing as pypa > > p = \ > pypa.LineStart() + \ > pypa.OneOrMore( pypa.Literal('a').setWhitespaceChars(' ') ) + \ > pypa.LineEnd() > > def foo (t): > print(t) > > #p.setParseAction(foo) > > g = pypa.Literal('b') + p > > res = g.parseString('''b > a a > a > ''') > > print(res) > > > > ------------------------------------------------------------------------------ > Slashdot TV. > Video for Nerds. Stuff that matters. > http://tv.slashdot.org/ > _______________________________________________ > Pyparsing-users mailing list > Pyp...@li... > https://lists.sourceforge.net/lists/listinfo/pyparsing-users > |