54 virtual string woof() =0;
55 virtual string honk() =0;
56 virtual string moo() =0;
57 virtual string meh() =0;
60 const string BEGINNING(
"silence");
63 using VerbSeq = vector<Verb>;
79 string woof() {
return "Woof-Woof!"; }
80 string honk() {
return "Honk-Honk!"; }
81 string moo() {
return "Moo-Moo!"; }
82 string meh() {
return "Meh!"; }
96 buildResultTerm (
string nextToken)
98 string resultExpression (fmt_ % verb_ % nextToken);
100 return resultExpression;
104 string woof() {
return buildResultTerm (VERB_woof); }
105 string honk() {
return buildResultTerm (VERB_honk); }
106 string moo() {
return buildResultTerm (VERB_moo); }
107 string meh() {
return buildResultTerm (VERB_meh); }
113 , fmt_(
"%s followed by %s")
139 VerbSeq tokens = build_test_feed();
140 render_verbose (tokens);
141 verify_dispatch (tokens);
167 VerboseRenderer receiver;
168 for (Verb verb : tokens)
169 cout <<
"consuming " << verb
171 << verb.applyTo(receiver)
182 RecollectingReceiver receiver;
183 string previous = BEGINNING;
184 for (Verb verb : tokens)
186 CHECK (previous+
" followed by "+
string(verb) == verb.applyTo(receiver));
187 previous = string(verb);
Action token implemented by double dispatch to a handler function, as defined in the "receiver" inter...
Building blocks for a simple DSL using double dispatch to a handler function.
void verify_dispatch(VerbSeq tokens)
A front-end for using printf-style formatting.
VerbSeq build_test_feed()
prepare a sequence of verbs for the actual tests to work on
Implementation namespace for support and library code.
void render_verbose(VerbSeq tokens)
Simple test class runner.
a receiver of verb-tokens, which renders them verbosely
virtual ~Receiver()
this is an interface
Statefull receiver of verb-tokens.
the "visitor" interface to invoke