45 virtual string woof() =0;
46 virtual string honk() =0;
47 virtual string moo() =0;
48 virtual string meh() =0;
51 const string BEGINNING(
"silence");
54 using VerbSeq = vector<Verb>;
70 string woof() {
return "Woof-Woof!"; }
71 string honk() {
return "Honk-Honk!"; }
72 string moo() {
return "Moo-Moo!"; }
73 string meh() {
return "Meh!"; }
87 buildResultTerm (
string nextToken)
89 string resultExpression (fmt_ % verb_ % nextToken);
91 return resultExpression;
95 string woof() {
return buildResultTerm (VERB_woof); }
96 string honk() {
return buildResultTerm (VERB_honk); }
97 string moo() {
return buildResultTerm (VERB_moo); }
98 string meh() {
return buildResultTerm (VERB_meh); }
104 , fmt_(
"%s followed by %s")
130 VerbSeq tokens = build_test_feed();
131 render_verbose (tokens);
132 verify_dispatch (tokens);
158 VerboseRenderer receiver;
159 for (Verb verb : tokens)
160 cout <<
"consuming " << verb
162 << verb.applyTo(receiver)
173 RecollectingReceiver receiver;
174 string previous = BEGINNING;
175 for (Verb verb : tokens)
177 CHECK (previous+
" followed by "+
string(verb) == verb.applyTo(receiver));
178 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)
Simplistic 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