New to PyParsing. I'm trying to work out how to parse the draw (and similar) attributes in xdot files. There are a number of items where the number of following elements is given as an integer at the start - sort of similar to NetStrings. I've looked at some of the sample code to deal with netstring like constructs, but it does not seem to be working for me.
Here are some samples:
Polygon with 3 points (the 3 after the P indicates the number of points following):
P 3 811 190 815 180 806 185
should parse to 'P', [[811, 190], [815, 180], [806, 185]]
Polygon with 2 points:
P 2 811 190 815 180 806 185
should parse to 'P', [[811, 190], [815, 180]]
(with unparsed text at the end)
Pen fill colour (the 4 after the C indicates the number of characters after the '-' to consume):
C 4 -blue
should parse to 'C', 'blue'
Updated Info:
I think I was misleading by putting the examples on their own lines, without more context. Here is a real example:
S 5 -solid S 15 -setlinewidth(1) c 5 -black C 5 -black P 3 690 181 680 179 687 187
See http://www.graphviz.org/doc/info/output.html#d:xdot for the actual spec.
Note that there could be significant spaces in the text fields - setlinewidth(1) above could be "abcd efgh hijk " and as long as it was exactly 15 characters, it should be linked with the 'S' tag. There should be exactly 7 numbers (the initial counter + 3 pairs) after the 'P' tag, and anything else should raise a parse error, since there could be more tags following (on the same line), but numbers by themselves are not valid.
Hopefully that makes things a little clearer.