[Tutor] making a custom file parser?
Alex Hall
mehgcap at gmail.com
Sat Jan 7 18:53:22 CET 2012
Hello all,
I have a file with xml-ish code in it, the definitions for units in a
real-time strategy game. I say xml-ish because the tags are like xml,
but no quotes are used and most tags do not have to end. Also,
comments in this file are prefaced by an apostrophe, and there is no
multi-line commenting syntax. For example:
<unit>
<number=1>
<name=my unit>
<canMove=True>
<canCarry=unit2, unit3, unit4>
'this line is a comment
</unit>
The game is not mine, but I would like to put together a python
interface to more easily manage custom units for it. To do that, I
have to be able to parse these files, but elementtree does not seem to
like them very much. I imagine it is due to the lack of quotes, the
non-standard commenting method, and the lack of closing tags. I think
my only recourse here is to create my own parser and tell elementtree
to use that. The docs say this is possible, but they also seem to
indicate that the parser has to already exist in the elementtree
package and there is no mention of making one's own method for
parsing. Even if this were possible, though, I am not sure how to go
about it. I can of course strip comments, but that is as far as I have
gotten.
Bottom line: can I create a method and tell elementtree to parse using
it, and what would such a function look like (generally) if I can?
Thanks!
--
Have a great day,
Alex (msg sent from GMail website)
mehgcap at gmail.com; http://www.facebook.com/mehgcap
More information about the Tutor
mailing list