Pyparsing: Grammar Suggestion. 2nd thought

Khoa Nguyen khoa.coffee at gmail.com
Wed May 17 20:05:15 CEST 2006


>
> for tokens,start,end in commaSeparatedList.scanString(data):
>     print tokens
>
>
> This returns:
>
> ['f1', 'f2', 'f3', 'f4', 'f5', 'f6']
> ['f1', 'f2']
> ['f1', 'f2', '', 'f4', '', 'f6']
>

Thanks for your reply. This looks promising, but I have a few more questions:
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,
Khoa

========
On 2nd thought, I don't think this will check for the correct order of
the fields. For example, the following would be incorrectly accepted:

f1,f5,f2 END_RECORD

Thanks,
Khoa



More information about the Python-list mailing list