RE: [Pyparsing] RE: Pyparsing unicode
Brought to you by:
ptmcg
From: Paul M. <pa...@al...> - 2006-05-13 19:19:18
|
> -----Original Message----- > From: Jean-Paul Calderone [mailto:ex...@di...] > Sent: Saturday, May 13, 2006 1:37 PM > To: Paul McGuire > Cc: pyp...@li... > Subject: Re: [Pyparsing] RE: Pyparsing unicode > <snip> > > I took your lead and produced the attached stand-alone test > based on a couple actions in Imaginary. It includes a > slightly different version of targetString (one that uses > removeQuotes) and shows two different failures. Any insights > you have would be appreciated. > > Jean-Paul > Great test case! Ok, here is the problem: in 1.4.2, I expanded the concept of parse actions to support a list of parse actions, to be executed in a chain, instead of just one. Every call to setParseAction *adds* the current action to the expression's list of parse actions (yes, I see that this is *not* intuitive, and I will fix this! Instead of expanding the behavior of setParseAction, I should have added a new method, something like addParseAction, or something that clearly implies that we are adding the current parse action to whatever other actions have already been defined). Because you are calling setParseAction on the global quotedString, the results get pared back again and again. I might also adjust removeQuotes to only remove the first and last characters if they are in fact quote characters - I'm not sure about this yet, though. Here are 2 possible workarounds for you: 1. use a copy of quotedString in your definition of qstr inside targetString. Change: qstr = pyparsing.quotedString.setParseAction(pyparsing.removeQuotes) To: qstr = pyparsing.quotedString.copy().setParseAction(pyparsing.removeQuotes) 2. Take care to only attach removeQuotes to quotedString *once*, perhaps right after calling import. import pyparsing pyparsing.quotedString.setParseAction(pyparsing.removeQuotes) Then inside targetString, just assign qstr as: qstr = pyparsing.quotedString Sorry for the confusion! Let me know what you settle on doing. -- Paul |