Parsing an ad hoc tree

I have a flat file that looks like this:


++Shirt:Red & White Stripes



What's the most efficient way to parse this into a data structure in Python? Or else, how would I convert this to XML, JSON, or a simple Python object?

The resulting data structure must support some type of query, for example in psuedocode, for example:



should be able to return "Red and White Stripes"

Similarly, something of order,



should return None

Is there a module that would be helpful here?


source to share

1 answer

For such a thing, you can use Marpa :: R2 , Perl for Marpa, general BNF parser - parser , parse tree . Some more explanations in my answer to a related question Handling a re-structured text file with python

Example ast_traverse()

: Parses values ​​from a block of text based on specific keys



All Articles