make sure entire string was parsed
steven.bethard at gmail.com
Sun Sep 11 20:05:13 CEST 2005
Paul McGuire wrote:
> Thanks for giving pyparsing a try! To see whether your input text
> consumes the whole string, add a StringEnd() element to the end of your
> BNF. Then if there is more text after the parsed text, parseString
> will throw a ParseException.
Thanks, that's exactly what I was looking for.
> I notice you call leaveWhitespace on several of your parse elements, so
> you may have to rstrip() the input text before calling parseString. I
> am curious whether leaveWhitespace is really necessary for your
> grammar. If it is, you can usually just call leaveWhitespace on the
> root element, and this will propagate to all the sub elements.
Yeah, sorry, I was still messing around with that part of the code. My
problem is that I have to differentiate between:
I'm doing this now using Combine. Does that seem right?
> Lastly, you may get caught up with operator precedence, I think your
> node assignment statement may need to change from
> node << start + (branch_node | leaf_node) + end
> node << (start + (branch_node | leaf_node) + end)
I think I'm okay:
py> 2 << 1 + 2
py> (2 << 1) + 2
py> 2 << (1 + 2)
Thanks for the help!
More information about the Python-list