Pyparsing: Grammar Suggestion
ptmcg at austin.rr._bogus_.com
Wed May 17 20:57:11 CEST 2006
"Khoa Nguyen" <khoa.coffee at gmail.com> wrote in message
news:mailman.5825.1147888678.27775.python-list at python.org...
> Thanks for your reply. This looks promising, but I have a few more
> 1. If f(i) is non-terminal (e.g f(i) is another grammar expression),
> how would I adapt your idea to a more generic way?
> 2. The field delimiter is not always ',' in my case. So I guess I'll
> have to use delimtedList instead?
> Thanks again,
Yes, it sounds like delimitedList is the way to go. Note that the delimiter
for delimitedList can also be an expression, it does not have to be a
literal string, or terminal. Also, do not bother using delimitedList if
your delimiter is just whitespace - pyparsing breaks up tokens on whitespace
by default, that is:
will correctly parse "This is a sentence made up of alphabetic words",
['This', 'is', 'a', 'sentence', 'made', 'up', 'of', 'alphabetic', 'words']
without having to represent the delimiting whitespace in the grammar.
More information about the Python-list