I need a system for creating Python subclasses in a simple manner, and I was thinking of using a (custom) config language similar to
Here's the initial structure I thought of (one file = one subclass, files are in a folder where they're read from automatically), which is basically just a simple config language, with Python function bodies on as event handlers:
name: Warrior description: Excels at close combat Item: name: Shield description: Block 10% of incoming damage, but move 10% slower Event defend: # Everything after "event <event_name>" line # is parsed as normal python until unindentation event_args['damage'] *= 0.9 Event spawn: event_args['player'].speed -= 0.1
I'm open for any suggestions, so if it's much easier to use some other formatting (XML or such), I'm up for it. However, this would be the ideal format.
How would I go on about writing mixed Python and config language? Are there any existing projects which I could study? I've researched
ast a little, which is apparently designed for Python parsing, but I'm just looking for some guidance to get started.
The only solution that comes into mind is to:
- read through the file line-by-line, and parse every line manually with Python's string functions like
- If the line content matches regex
^Event .*:$, I will parse as Python until an unindentation (how do I do this?)
But even this seems unfeasible, and it feels like there must be a better way.