A
André
Hi everyone,
I would like to implement a parser for a mini-language
and would appreciate some pointers. The type of
text I would like to parse is an extension of:
http://www.websequencediagrams.com/examples.html
For those that don't want to go to the link, consider
the following, *very* simplified, example:
=======
programmer Guido
programmer "Fredrik Lundh" as effbot
programmer "Alex Martelli" as martellibot
programmer "Tim Peters" as timbot
note left of effbot: cutting sense of humor
note over martellibot:
Offers detailed note, explaining a problem,
accompanied by culinary diversion
to the delight of the reader
note over timbot: programmer "clever" as fox
timbot -> Guido: I give you doctest
Guido --> timbot: Have you checked my time machine?
=======
From this, I would like to be able to extract
("programmer", "Guido")
("programmer as", "Fredrik Lundh", "effbot")
....
("note left of", "effbot", "cutting sense of humor")
("note over", "martellibot", "Offers...")
("note over", "timbot", 'programmer "clever" as fox')
Some observations:
1. I want to use indentation to identify blocks.
(the site I referred to uses "end note" which I don't want)
2. "keywords" (such as "programmer", "note over")
can appear in text, and should not then be misidentified
3. I was thinking of using http://effbot.org/zone/simple-top-down-parsing.htm
as a guide; however, it is not clear to me how it could be
adapted to handle observations 1 and 2. (If it "easily" could,
just a few pointers would be enough, and I'll start from there...)
4. I want to do this only using modules in the standard Python
library, as I want to use this to learn about the basics
of parsing. So, please don't *simply* suggest to use a
third-party module, such as
[1] plex, [2] yapps, [3] pyparsing
The learning journey is more important for me than just
having a canned solution to my (current) parsing problem.
Cheers,
André
[1] http://www.cosc.canterbury.ac.nz/greg.ewing/python/Plex/
[2] http://theory.stanford.edu/~amitp/yapps/
[3] http://pyparsing.wikispaces.com/
I would like to implement a parser for a mini-language
and would appreciate some pointers. The type of
text I would like to parse is an extension of:
http://www.websequencediagrams.com/examples.html
For those that don't want to go to the link, consider
the following, *very* simplified, example:
=======
programmer Guido
programmer "Fredrik Lundh" as effbot
programmer "Alex Martelli" as martellibot
programmer "Tim Peters" as timbot
note left of effbot: cutting sense of humor
note over martellibot:
Offers detailed note, explaining a problem,
accompanied by culinary diversion
to the delight of the reader
note over timbot: programmer "clever" as fox
timbot -> Guido: I give you doctest
Guido --> timbot: Have you checked my time machine?
=======
From this, I would like to be able to extract
("programmer", "Guido")
("programmer as", "Fredrik Lundh", "effbot")
....
("note left of", "effbot", "cutting sense of humor")
("note over", "martellibot", "Offers...")
("note over", "timbot", 'programmer "clever" as fox')
Some observations:
1. I want to use indentation to identify blocks.
(the site I referred to uses "end note" which I don't want)
2. "keywords" (such as "programmer", "note over")
can appear in text, and should not then be misidentified
3. I was thinking of using http://effbot.org/zone/simple-top-down-parsing.htm
as a guide; however, it is not clear to me how it could be
adapted to handle observations 1 and 2. (If it "easily" could,
just a few pointers would be enough, and I'll start from there...)
4. I want to do this only using modules in the standard Python
library, as I want to use this to learn about the basics
of parsing. So, please don't *simply* suggest to use a
third-party module, such as
[1] plex, [2] yapps, [3] pyparsing
The learning journey is more important for me than just
having a canned solution to my (current) parsing problem.
Cheers,
André
[1] http://www.cosc.canterbury.ac.nz/greg.ewing/python/Plex/
[2] http://theory.stanford.edu/~amitp/yapps/
[3] http://pyparsing.wikispaces.com/