Re: [Pyparsing] Unparsed cruft
Brought to you by:
ptmcg
From: Paul M. <pa...@al...> - 2008-03-08 21:49:53
|
Yes, this is in the FAQ's. Add a StringEnd() to the end of your grammar, telling pyparsing that at the end of the grammar, you expect to be at the end of the string. Word(nums).parseString("123 abc") -> ['123'] (Word(nums) + StringEnd()).parseString("123 abc") -> raises ParseException -- Paul -----Original Message----- From: pyp...@li... [mailto:pyp...@li...] On Behalf Of Gre7g Luterman Sent: Saturday, March 08, 2008 11:22 AM To: pyp...@li... Subject: [Pyparsing] Unparsed cruft My parser seems to parse everything correctly in a well-formed source file, which is great, but it seems to stumble a bit if the user's input is imperfect. Here's an example link: http://pastie.textmate.org/163282 This example tries to parse an invalid expression. The input is "x + 5 y" and it returns [['x', '+', 5]]. So it's able to handle everything that is well-formed, but instead of throwing an exception when it hits the part it can't parse, it just returns. This would be real problematic for me. If I can't parse all of the user's program, I need to know that instead of thinking that compilation was successful. Is there some way to determine how much of the string was actually parsed, or to force an exception if the string cannot be parsed in its entirety? Thanks, Gre7g __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users |