This post originated from an RSS feed registered with Python Buzz
by Andrew Dalke.
Original Post: Parser Generators and Decorators
Feed Title: Andrew Dalke's writings
Feed URL: http://www.dalkescientific.com/writings/diary/diary-rss.xml
Feed Description: Writings from the software side of bioinformatics and chemical informatics, with a heaping of Python thrown in for good measure.
Years ago John Aycock's SPARK
introduced the idea of using docstring to store the pattern and rule
definitions for a parser generator. Rather, that's where I first
heard of it; someone else could have been first.
Here's part of the scanner definition from Biopython for parsing
GenBank locations:
The idea of using the docstring was rather cute but a bit of a hack.
That was the easiest way to associate data with a function. Modern
Python has decorators and function object attributes are writeable.
Has anyone revisted the approach except using a decorator instead of a
docstring?
The above two examples would look something like this:
I looked at SPARK for about 2 minutes to figure out if it was doable.
It is, but would take a couple hours to do. SPARK is stable, meaning
the code hasn't changed in years. John has updated the page recently
but only to add a reference to another parsing project. I don't know
if he's interested in this and will take diffs.
Plus, I want to try out PyParsing, which looks like it uses ideas
similar to that in my Martel project, which I took from Greg Ewing's
Plex. I recall that ?!ng was also an early advocate of that style but
would need to dig through archives for verification. (In other words,
I was a late-comer to the game and make no suggestion that PyParsing
based anything on Martel.)