[Pyparsing] fixed-length field preceded by length?
Brought to you by:
ptmcg
From: John W. S. <jo...@nm...> - 2011-12-31 20:40:00
|
I'm trying to parse the .calendar file used by the old Unix ical calendar program (the one written by Sanjay Ghemawat, not any of the modern iCal utilities). Here is a typical line from this file: Text [6 [Easter]] As you can see, the length is given explicitly, followed by whitespace, and the text string in brackets. How do I write the pyparsing syntax for lines of this form? The length may be any number, and I'd like to handle the case where '[' or ']' characters occur inside the text string. It's quite straightforward to write the patterns, but how do I write the pattern for the text string in such a way that it gets the length from a previous token in the same pattern? I just paid $10 for Paul McGuire's "Getting Started" eBook and was quite disappointed that there's no reference section, and no obvious solution to my problem. Any suggestions? Best regards (and happy new year!), John Shipman (jo...@nm...), Applications Specialist, NM Tech Computer Center, Speare 146, Socorro, NM 87801, (575) 835-5735, http://www.nmt.edu/~john ``Let's go outside and commiserate with nature.'' --Dave Farber |