I have a python library which builds special iterators (a behavior tree) out of nested function calls. While the API has a fairly nice and light-weight syntax (due to it being python), it could really use a declarative DSL.
Here's a rough sketch of what I'm envisioning:
The DSL (using YAML):
tree:
- sequence:
- do_action1
- do_action2
- select:
- do_action3
- sequence:
- do_action4
- do_action5
- do_action6
would result in the following nested function calls:
visit(
sequence(
do_action1(),
do_action2(),
select(
do_action3(),
sequence(
do_action4(),
do_action5(),
),
do_action6(),
)
)
)
I'm having trouble visualizing exactly how to do this. Because the DSL must represent a tree, a simple depth-first traversal seems appropriate. But in order to build the nested function calls, I have to turn this inside out somehow. It probably involves something clever with an intermediary stack or some-such, but I can't quite grasp it. What's the correct way to perform this transformation?