Forgive me if I have the incorrect terminology; perhaps just getting the "right" words to describe what I want is enough for me to find the answer on my own.
I am working on a parser for ODL (Object Description Language), an arcane language that as far as I can tell is now used only by NASA PDS (Planetary Data Systems; it's how NASA makes its data available to the public). Fortunately, PDS is finally moving to XML, but I still have to write software for a mission that fell just before the cutoff.
ODL defines objects in something like the following manner:
OBJECT = TABLE
ROWS = 128
ROW_BYTES = 512
END_OBJECT = TABLE
I am attempting to write a parser with pyparsing
, and I was doing fine right up until I came to the above construction.
I have to create some rule that is able to ensure that the right-hand-value of the OBJECT line is identical to the RHV of END_OBJECT. But I can't seem to put that into a pyparsing
rule. I can ensure that both are syntactically valid values, but I can't go the extra step and ensure that the values are identical.
- Am I correct in my intuition that this is a context-sensitive grammar? Is that the phrase I should be using to describe this problem?
- Whatever kind of grammar this is in the theoretical sense, is
pyparsing
able to handle this kind of construction? - If
pyparsing
is not able to handle it, is there another Python tool capable of doing so? How aboutply
(the Python implementation oflex
/yacc
)?
block
, and it can validate that thehead
andtail
values agree, or raise aParseException
. So you don't have to do a lot of "tree-walking". – Venita