Re: [Pyparsing] Parsing Stanford Polygon File Format (PLY)
Brought to you by:
ptmcg
|
From: <pt...@au...> - 2016-12-24 05:48:49
|
> > 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 |