Re: [Pyparsing] Parsing Stanford Polygon File Format (PLY)
Brought to you by:
ptmcg
From: E Y. <you...@gm...> - 2017-01-15 09:41:22
|
Hi all, it took a while, but I managed to complete an initial working version of the PLY parser thanks to Paul's suggestions. The self-contained example you can find here: https://gist.github.com/youngec/76c5b552ab5bc04b43d1bfa9d3fa0a78. Its only dependency is the python package attrs (https://pypi.org/pypi/attrs), because it makes python classes a bit easier to manage. You're free to use that parser as you wish. The parser is part of a larger project at https://github.com/youngec/rootspace/tree/develop, and the respective unit tests are at https://github.com/youngec/rootspace/blob/develop/src/rootspace/tests/test_parsers.py . Theres one big caveat to the parser though, and I'm hoping you can provide some guidance: Currently, it only understands ASCII-based PLY files, but doesn't understand the two much more common binary formats (little- and big-endian). Can pyparsing handle binary data? Thanks so much! Best, Ellie On 24 December 2016 at 06:48, <pt...@au...> wrote: > > > > first off, I would like to thank the developer(s) for making such a great > > tool. It's such an elegant piece of work! > > Thank you - flattery is always a good start! I'm glad pyparsing has been > helpful for you, and that you find it to your liking. > > Kudos on your posted parser - starting with posting your BNF! So many > people skip this step, and then get mired down in distracting details, and > find they have overlooked or skipped significant parts. I'm also glad to > see that you are using the new pyparsing_common expressions. I had some > mixed feelings about including them, and your sample code shows them being > put to good use. > > > > > 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. > > > > This happens often enough, and there are several examples of such adaptive > parsers that I have posted over the years. The main concept is to define a > Forward for the part of the parser that needs to be adaptive, and then to > use a parse action attached to the part with the format description to > create the flexible part of the parser, and to then insert it into the > placeholder Forward using the '<<' operator. > > I touched up your parser from the gist that you posted, and have added > some sample code that will parse the test cube example. You can find it > here: https://gist.github.com/anonymous/4498de5ce91da8cf4292bad408076b97 > I think you'll be able to take it from there. (I also applied some > stylistic changes - removing explicit .setResultsName calls in favor of > implicit callable notation, changing CaselessLiteral to CaselessKeyword, a > Group added here or there for better structure and results name assignment. > Feel free to keep any, all, or none of these changes.) > > Please post a link to your finished project to this list, or the Pyparsing > Facebook page. > > Regards, > -- Paul McGuire > > > > > |