Moustache: syntax file and tests
Tests and a hairy syntax file.
A recent post by Gilad Bracha echoed with my experience designing two small internal DSL in Clojure (Moustache and Enlive’s selectors).
It’s not the same kind of non-understanding which I have in mind. I’m talking about a macro/DSL being able to not understand what is passed to it.
I think it’s an important feature for the user to be able to get out of your DSL and back in regular Clojure.
In both Moustache and Enlive, I avoid to give a special meaning to lists (in Clojure you also have vectors, maps and sets), hence lists always denote user-code and are embedded as-is in the macro expansion. (If I really had to use lists for a DSL, I would check a list doesn’t start with a special value (eg do
or unquote
(~) — thanks to MB’s comment) before processing it).
That’s why in Enlive you can easily add your own selectors step [:p (my-selector-step arg1 arg2)]
as long as (my-selector-step arg1 arg2)
evaluates to a correct value (here a state machine).
That’s also how Moustache supports wrapping another Ring handler or custom route validation.