E Young
2016-12-23 09:24:31 UTC
Dear All,
first off, I would like to thank the developer(s) for making such a great
tool. It's such an elegant piece of work!
Though, I'm happy if somebody can provide some help. I'm trying to
implement a Standford polygon file parser (
http://paulbourke.net/dataformats/ply/), but I'm having trouble getting it
to parse the file into the correct data structure, because parts of the
file depend on depend on declarations earlier in the same file.
For those not in the know, the PLY file format has a header and a body, as
seen in the example posted on the aforementioned link. The header declares
how the body is supposed to be parsed and the body consists only of numbers
(either textual or binary). The declarations dictate the order of the data
in the body. My attempt at a context free grammar is as follows:
ply_grammar ::= header body
header ::= "ply" declaration+ "end_header"
declaration ::= format | element | property
format ::= "format" format_type NUMBER
element ::= "element" element_type NUMBER
property ::= ("property" property_type IDENT) | ("property" "list"
property_type property_type IDENT)
format_type ::= "vertex" | "face" | "edge" | IDENT
property_type ::= "char" | "uchar" | "short" | "ushort" | "int" | "uint" |
"float" | "double"
body ::= statement+
statement ::= NUMBER+
The code is available at:
https://gist.github.com/anonymous/f7fee82634ba224e25e9022ec2c3c890
So far, I managed to parse the file header such that each declared element
has nested property declarations, but I'm unable to tell pyparsing how to
parse the body data accordingly. In the end, I would like to have instances
of numpy.ndarray or array.array for each element declared in the header.
Any help is greatly appreciated!
Best,
E
first off, I would like to thank the developer(s) for making such a great
tool. It's such an elegant piece of work!
Though, I'm happy if somebody can provide some help. I'm trying to
implement a Standford polygon file parser (
http://paulbourke.net/dataformats/ply/), but I'm having trouble getting it
to parse the file into the correct data structure, because parts of the
file depend on depend on declarations earlier in the same file.
For those not in the know, the PLY file format has a header and a body, as
seen in the example posted on the aforementioned link. The header declares
how the body is supposed to be parsed and the body consists only of numbers
(either textual or binary). The declarations dictate the order of the data
in the body. My attempt at a context free grammar is as follows:
ply_grammar ::= header body
header ::= "ply" declaration+ "end_header"
declaration ::= format | element | property
format ::= "format" format_type NUMBER
element ::= "element" element_type NUMBER
property ::= ("property" property_type IDENT) | ("property" "list"
property_type property_type IDENT)
format_type ::= "vertex" | "face" | "edge" | IDENT
property_type ::= "char" | "uchar" | "short" | "ushort" | "int" | "uint" |
"float" | "double"
body ::= statement+
statement ::= NUMBER+
The code is available at:
https://gist.github.com/anonymous/f7fee82634ba224e25e9022ec2c3c890
So far, I managed to parse the file header such that each declared element
has nested property declarations, but I'm unable to tell pyparsing how to
parse the body data accordingly. In the end, I would like to have instances
of numpy.ndarray or array.array for each element declared in the header.
Any help is greatly appreciated!
Best,
E