In The Cardinality of a Fluent Interface Michael Feathers posed a code kata in which one has to create a DSL in which constructs such as the following all provide the expected numeric value:
one two twelve twelve.hundred one.hundred.thousand.and.fifteen twelve.hundred.and.one five.hundred.and.fifty.seven
My first pass at a solution in Ruby is available on github. There’s still some duplication in there, and hopefully I’ll get around to removing it soon.
In his post, Mike asks whether the DSL’s “cardinality” — the number of classes required to implement the DSL — says anything about the DSL’s grammar. Well, my solution has 7 classes (although PartialValue exists only to remove a little duplication). I have no idea what that might mean in the DSL world.
You can get the code from the github repository.