2009-09-09T09:31:17
Dave Pawson.
link
Home
python
I received something from a shopkeeper this morning. At 9 minutes past nine! Made me think when the shopkeeper noted the time and date combination.
I've been playing with Python again. Converting a wiki syntax into Docbook v5. I looked at Flex and Bison, but the O'Reilly book of that name I found quite unusable and just gave up. I'm surprised no one in the parser generator software world has deemed XML worthy as an output format. Anyway, I used Python, and as usual, found it up to the job with no problem. I struggled a bit with recursion, until I found Python syntax that matched tail recursion in Schema or Erlang. Sweet. Just need to expose it to the wiki people and get some real world testing.
Along the way I started to lose track of which module held what functions, so tried to use egrep and gawk to list it. egrep worked nicely with
egrep "(^def| def)" *.py >tmp.tmp
But when I tried to get gawk to sort out the resulting lines, of the format
files.py: def pushback(self, line): files.py: def lineNumber(self): files.py:def main(): # test access inlines.py:def prInlines(line, lineno, toXML=True ):
I really came unstuck. I couldn't get gawk variables to work, I suspected my regexen and gradually became frustrated... falling back to Python. This was my script
BEGIN {FS="def"}
/[a-z]+\.py\:([:space:]){4}*def/ {print $0}
{print $1,$2}
The awkward bit it hacking the optional ws in between the colon and the def word. Present in class definitions. Using emacs, if I use a tab it is turned into a series of four space characters. Testing worked on files.py but not when I used *.py. I hacked up the Python version in an hour.
Such a nice language. And I'm eagerly awaiting version 3.0, available, but Fedora haven't given it their seal of approval as yet.
Keywords: python
Comments (View)Return to main index