Re: [Pyparsing] fixed-length field preceded by length?
Brought to you by:
ptmcg
From: Paul M. <pt...@au...> - 2011-12-31 23:01:03
|
John - Sorry you were disappointed in GSWP; I had proposed a longer outline to O'Reilly which included a reference section, but this would have inflated the book beyond the 60-70 page length which was their ebook target at the time. Please take a look at how countedArray is implemented in the pyparsing code. I think you could copy this method and write a countedLengthTextString method using the same principles. If you are still spinning your wheels, write back! -- Paul (There are docs, how-to's, UML diagrams, and many examples included in the source distribution, please see if that material helps flesh out what you didn't get from GSWP. Also, there is online htmldoc (generated by epydoc) at http://packages.python.org/pyparsing/, and a link to an HTML how-to at http://pyparsing.svn.sourceforge.net/viewvc/pyparsing/src/HowToUsePyparsing. html.) -----Original Message----- From: John W. Shipman [mailto:jo...@nm...] Sent: Saturday, December 31, 2011 2:40 PM To: Pyp...@li... Subject: [Pyparsing] fixed-length field preceded by length? 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 ---------------------------------------------------------------------------- -- Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users |