1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - 011load.cc</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v1">
<meta name="syntax" content="cpp">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background-color: #080808; }
body { font-family: monospace; color: #d0d0d0; background-color: #080808; }
* { font-size: 1em; }
.traceContains { color: #008000; }
.cSpecial { color: #008000; }
.Constant { color: #008080; }
.Comment { color: #8080ff; }
.Delimiter { color: #c000c0; }
.Special { color: #ff6060; }
.Identifier { color: #008080; }
.CommentedCode { color: #6c6c6c; }
-->
</style>
<script type='text/javascript'>
<!--
-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: Phase 1 of running mu code: load it from a textual representation.</span>
<span class="Delimiter">:(scenarios load)</span> <span class="Comment">// use 'load' instead of 'run' in all scenarios in this layer</span>
<span class="Delimiter">:(scenario first_recipe)</span>
recipe main [
<span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal
]
<span class="traceContains">+parse: instruction: copy</span>
<span class="traceContains">+parse: ingredient: {name: "23", properties: ["23": "literal"]}</span>
<span class="traceContains">+parse: product: {name: "1", properties: ["1": "number"]}</span>
<span class="Delimiter">:(code)</span>
vector<recipe_number> load<span class="Delimiter">(</span>string form<span class="Delimiter">)</span> <span class="Delimiter">{</span>
istringstream in<span class="Delimiter">(</span>form<span class="Delimiter">);</span>
in >> std::noskipws<span class="Delimiter">;</span>
<span class="Identifier">return</span> load<span class="Delimiter">(</span>in<span class="Delimiter">);</span>
<span class="Delimiter">}</span>
vector<recipe_number> load<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span>
vector<recipe_number> result<span class="Delimiter">;</span>
while <span class="Delimiter">(</span>!in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Delimiter">{</span>
skip_whitespace_and_comments<span class="Delimiter">(</span>in<span class="Delimiter">);</span>
if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
string command = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span>
<span class="Comment">// Command Handlers</span>
if <span class="Delimiter">(</span>command == <span class="Constant">"recipe"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
string recipe_name = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span>
if <span class="Delimiter">(</span>recipe_name<span class="Delimiter">.</span>empty<span class="Delimiter">())</span>
raise << <span class="Constant">"empty recipe name</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span>
if <span class="Delimiter">(</span>Recipe_number<span class="Delimiter">.</span>find<span class="Delimiter">(</span>recipe_name<span class="Delimiter">)</span> == Recipe_number<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span>
Recipe_number[recipe_name] = Next_recipe_number++<span class="Delimiter">;</span>
<span class="Delimiter">}</span>
if <span class="Delimiter">(</span>Recipe<span class="Delimiter">.</span>find<span class="Delimiter">(</span>Recipe_number[recipe_name]<span class="Delimiter">)</span> != Recipe<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span>
raise << <span class="Constant">"redefining recipe "</span> << Recipe[Recipe_number[recipe_name]]<span class="Delimiter">.</span>name << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span>
Recipe<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>Recipe_number[recipe_name]<span class="Delimiter">);</span>
<span class="Delimiter">}</span>
<span class="Comment">// todo: save user-defined recipes to mu's memory</span>
Recipe[Recipe_number[recipe_name]] = slurp_recipe<span class="Delimiter">(</span>in<span class="Delimiter">);</span>
Recipe[Recipe_number[recipe_name]]<span class="Delimiter">.</span>name = recipe_name<span class="Delimiter">;</span>
<span class="Comment">// track added recipes because we may need to undo them in tests; see below</span>
recently_added_recipes<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Recipe_number[recipe_name]<span class="Delimiter">);</span>
result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Recipe_number[recipe_name]<span class="Delimiter">);</span>
<span class="Delimiter">}</span>
<span class="Comment">// End Command Handlers</span>
else <span class="Delimiter">{</span>
raise << <span class="Constant">"unknown top-level command: "</span> << command << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">}</span>
<span class="Comment">// End Load Sanity Checks</span>
<span class="Identifier">return</span> result<span class="Delimiter">;</span>
<span class="Delimiter">}</span>
recipe slurp_recipe<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span>
recipe result<span class="Delimiter">;</span>
skip_whitespace<span class="Delimiter">(</span>in<span class="Delimiter">);</span>
if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>get<span class="Delimiter">()</span> != <span class="Constant">'['</span><span class="Delimiter">)</span>
raise << <span class="Constant">"recipe body must begin with '['</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span>
skip_whitespace_and_comments<span class="Delimiter">(</span>in<span class="Delimiter">);</span>
instruction curr<span class="Delimiter">;</span>
while <span class="Delimiter">(</span>next_instruction<span class="Delimiter">(</span>in<span class="Delimiter">,</span> &curr<span class="Delimiter">))</span> <span class="Delimiter">{</span>
<span class="Comment">// End Rewrite Instruction(curr)</span>
result<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>curr<span class="Delimiter">);</span>
<span class="Delimiter">}</span>
<span class="Identifier">return</span> result<span class="Delimiter">;</span>
<span class="Delimiter">}</span>
bool next_instruction<span class="Delimiter">(</span>istream& in<span class="Delimiter">,</span> instruction* curr<span class="Delimiter">)</span> <span class="Delimiter">{</span>
curr<span class="Delimiter">-></span>clear<span class="Delimiter">();</span>
if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="CommentedCode">//? show_rest_of_stream(in); //? 1</span>
skip_whitespace<span class="Delimiter">(</span>in<span class="Delimiter">);</span> if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="CommentedCode">//? show_rest_of_stream(in); //? 1</span>
skip_whitespace_and_comments<span class="Delimiter">(</span>in<span class="Delimiter">);</span> if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
vector<string> words<span class="Delimiter">;</span>
<span class="CommentedCode">//? show_rest_of_stream(in); //? 1</span>
while <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
skip_whitespace<span class="Delimiter">(</span>in<span class="Delimiter">);</span> if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="CommentedCode">//? show_rest_of_stream(in); //? 1</span>
string word = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span> if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
words<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>word<span class="Delimiter">);</span>
skip_whitespace<span class="Delimiter">(</span>in<span class="Delimiter">);</span> if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
skip_whitespace_and_comments<span class="Delimiter">(</span>in<span class="Delimiter">);</span> if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="CommentedCode">//? if (SIZE(words) == 1) cout << words.at(0) << ' ' << SIZE(words.at(0)) << '\n'; //? 1</span>
if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>words<span class="Delimiter">)</span> == <span class="Constant">1</span> && words<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">"]"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="CommentedCode">//? cout << "AAA\n"; //? 1</span>
<span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Comment">// end of recipe</span>
<span class="Delimiter">}</span>
if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>words<span class="Delimiter">)</span> == <span class="Constant">1</span> && !isalnum<span class="Delimiter">(</span>words<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> && words<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> != <span class="Constant">'$'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
curr<span class="Delimiter">-></span>is_label = <span class="Constant">true</span><span class="Delimiter">;</span>
curr<span class="Delimiter">-></span>label = words<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
trace<span class="Delimiter">(</span><span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"label: "</span> << curr<span class="Delimiter">-></span>label<span class="Delimiter">;</span>
<span class="Identifier">return</span> !in<span class="Delimiter">.</span>eof<span class="Delimiter">();</span>
<span class="Delimiter">}</span>
vector<string>::iterator p = words<span class="Delimiter">.</span>begin<span class="Delimiter">();</span>
if <span class="Delimiter">(</span>find<span class="Delimiter">(</span>words<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> words<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> <span class="Constant">"<-"</span><span class="Delimiter">)</span> != words<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span>
for <span class="Delimiter">(;</span> *p != <span class="Constant">"<-"</span><span class="Delimiter">;</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span>
if <span class="Delimiter">(</span>*p == <span class="Constant">","</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>
curr<span class="Delimiter">-></span>products<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span>*p<span class="Delimiter">));</span>
<span class="Delimiter">}</span>
++p<span class="Delimiter">;</span> <span class="Comment">// skip <-</span>
<span class="Delimiter">}</span>
curr<span class="Delimiter">-></span>name = *p<span class="Delimiter">;</span>
if <span class="Delimiter">(</span>Recipe_number<span class="Delimiter">.</span>find<span class="Delimiter">(</span>*p<span class="Delimiter">)</span> == Recipe_number<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span>
Recipe_number[*p] = Next_recipe_number++<span class="Delimiter">;</span>
<span class="CommentedCode">//? cout << "AAA: " << *p << " is now " << Recipe_number[*p] << '\n'; //? 1</span>
<span class="Delimiter">}</span>
if <span class="Delimiter">(</span>Recipe_number[*p] == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
raise << <span class="Constant">"Recipe "</span> << *p << <span class="Constant">" has number 0, which is reserved for IDLE.</span><span class="cSpecial">\n</span><span class="Constant">"</span> << die<span class="Delimiter">();</span>
<span class="Delimiter">}</span>
curr<span class="Delimiter">-></span>operation = Recipe_number[*p]<span class="Delimiter">;</span> ++p<span class="Delimiter">;</span>
for <span class="Delimiter">(;</span> p != words<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span>
if <span class="Delimiter">(</span>*p == <span class="Constant">","</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>
curr<span class="Delimiter">-></span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span>*p<span class="Delimiter">));</span>
<span class="Delimiter">}</span>
trace<span class="Delimiter">(</span><span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"instruction: "</span> << curr<span class="Delimiter">-></span>name<span class="Delimiter">;</span>
for <span class="Delimiter">(</span>vector<reagent>::iterator p = curr<span class="Delimiter">-></span>ingredients<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != curr<span class="Delimiter">-></span>ingredients<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">" ingredient: "</span> << p<span class="Delimiter">-></span>to_string<span class="Delimiter">();</span>
<span class="Delimiter">}</span>
for <span class="Delimiter">(</span>vector<reagent>::iterator p = curr<span class="Delimiter">-></span>products<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != curr<span class="Delimiter">-></span>products<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">" product: "</span> << p<span class="Delimiter">-></span>to_string<span class="Delimiter">();</span>
<span class="Delimiter">}</span>
<span class="Identifier">return</span> !in<span class="Delimiter">.</span>eof<span class="Delimiter">();</span>
<span class="Delimiter">}</span>
string next_word<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="CommentedCode">//? cout << "AAA next_word\n"; //? 1</span>
ostringstream out<span class="Delimiter">;</span>
skip_whitespace<span class="Delimiter">(</span>in<span class="Delimiter">);</span>
slurp_word<span class="Delimiter">(</span>in<span class="Delimiter">,</span> out<span class="Delimiter">);</span>
skip_whitespace<span class="Delimiter">(</span>in<span class="Delimiter">);</span>
skip_comment<span class="Delimiter">(</span>in<span class="Delimiter">);</span>
<span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span>
<span class="Delimiter">}</span>
void slurp_word<span class="Delimiter">(</span>istream& in<span class="Delimiter">,</span> ostream& out<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="CommentedCode">//? cout << "AAA slurp_word\n"; //? 1</span>
char c<span class="Delimiter">;</span>
if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">','</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
in >> c<span class="Delimiter">;</span>
out << c<span class="Delimiter">;</span>
<span class="Identifier">return</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
while <span class="Delimiter">(</span>in >> c<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="CommentedCode">//? cout << c << '\n'; //? 1</span>
if <span class="Delimiter">(</span>isspace<span class="Delimiter">(</span>c<span class="Delimiter">)</span> || c == <span class="Constant">','</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
in<span class="Delimiter">.</span>putback<span class="Delimiter">(</span>c<span class="Delimiter">);</span>
<span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
out << c<span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">}</span>
void skip_whitespace<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span>
while <span class="Delimiter">(</span>isspace<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">())</span> && in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
in<span class="Delimiter">.</span>get<span class="Delimiter">();</span>
<span class="Delimiter">}</span>
<span class="Delimiter">}</span>
void skip_whitespace_and_comments<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span>
while <span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
if <span class="Delimiter">(</span>isspace<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()))</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span>
else if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">'#'</span><span class="Delimiter">)</span> skip_comment<span class="Delimiter">(</span>in<span class="Delimiter">);</span>
else <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">}</span>
void skip_comment<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span>
if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">'#'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
in<span class="Delimiter">.</span>get<span class="Delimiter">();</span>
while <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span>
<span class="Delimiter">}</span>
<span class="Delimiter">}</span>
void skip_comma<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span>
skip_whitespace<span class="Delimiter">(</span>in<span class="Delimiter">);</span>
if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">','</span><span class="Delimiter">)</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span>
skip_whitespace<span class="Delimiter">(</span>in<span class="Delimiter">);</span>
<span class="Delimiter">}</span>
<span class="Comment">// for debugging</span>
<span class="Delimiter">:(before "End Globals")</span>
bool Show_rest_of_stream = <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Delimiter">:(code)</span>
void show_rest_of_stream<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span>
if <span class="Delimiter">(</span>!Show_rest_of_stream<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span>
cerr << <span class="Constant">'^'</span><span class="Delimiter">;</span>
char c<span class="Delimiter">;</span>
while <span class="Delimiter">(</span>in >> c<span class="Delimiter">)</span> <span class="Delimiter">{</span>
cerr << c<span class="Delimiter">;</span>
<span class="Delimiter">}</span>
cerr << <span class="Constant">"$</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span>
exit<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
<span class="Comment">//: Have tests clean up any recipes they added.</span>
<span class="Delimiter">:(before "End Globals")</span>
vector<recipe_number> recently_added_recipes<span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Setup")</span>
for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>recently_added_recipes<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="CommentedCode">//? cout << "AAA clearing " << Recipe[recently_added_recipes.at(i)].name << '\n'; //? 2</span>
Recipe_number<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>Recipe[recently_added_recipes<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span>]<span class="Delimiter">.</span>name<span class="Delimiter">);</span>
Recipe<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>recently_added_recipes<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span>
<span class="Delimiter">}</span>
<span class="Comment">// Clear Other State For recently_added_recipes</span>
recently_added_recipes<span class="Delimiter">.</span>clear<span class="Delimiter">();</span>
<span class="Delimiter">:(scenario parse_comment_outside_recipe)</span>
<span class="Comment"># this comment will be dropped by the tangler, so we need a dummy recipe to stop that</span>
recipe f1 [ ]
<span class="Comment"># this comment will go through to 'load'</span>
recipe main [
<span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal
]
<span class="traceContains">+parse: instruction: copy</span>
<span class="traceContains">+parse: ingredient: {name: "23", properties: ["23": "literal"]}</span>
<span class="traceContains">+parse: product: {name: "1", properties: ["1": "number"]}</span>
<span class="Delimiter">:(scenario parse_comment_amongst_instruction)</span>
recipe main [
<span class="Comment"># comment</span>
<span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal
]
<span class="traceContains">+parse: instruction: copy</span>
<span class="traceContains">+parse: ingredient: {name: "23", properties: ["23": "literal"]}</span>
<span class="traceContains">+parse: product: {name: "1", properties: ["1": "number"]}</span>
<span class="Delimiter">:(scenario parse_comment_amongst_instruction2)</span>
recipe main [
<span class="Comment"># comment</span>
<span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal
<span class="Comment"># comment</span>
]
<span class="traceContains">+parse: instruction: copy</span>
<span class="traceContains">+parse: ingredient: {name: "23", properties: ["23": "literal"]}</span>
<span class="traceContains">+parse: product: {name: "1", properties: ["1": "number"]}</span>
<span class="Delimiter">:(scenario parse_comment_amongst_instruction3)</span>
recipe main [
<span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal
<span class="Comment"># comment</span>
<span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal
]
<span class="traceContains">+parse: instruction: copy</span>
<span class="traceContains">+parse: ingredient: {name: "23", properties: ["23": "literal"]}</span>
<span class="traceContains">+parse: product: {name: "1", properties: ["1": "number"]}</span>
<span class="traceContains">+parse: instruction: copy</span>
<span class="traceContains">+parse: ingredient: {name: "23", properties: ["23": "literal"]}</span>
<span class="traceContains">+parse: product: {name: "2", properties: ["2": "number"]}</span>
<span class="Delimiter">:(scenario parse_comment_after_instruction)</span>
recipe main [
<span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal <span class="Comment"># comment</span>
]
<span class="traceContains">+parse: instruction: copy</span>
<span class="traceContains">+parse: ingredient: {name: "23", properties: ["23": "literal"]}</span>
<span class="traceContains">+parse: product: {name: "1", properties: ["1": "number"]}</span>
<span class="Delimiter">:(scenario parse_label)</span>
recipe main [
+foo
]
<span class="traceContains">+parse: label: +foo</span>
<span class="Delimiter">:(scenario parse_dollar_as_recipe_name)</span>
recipe main [
$foo
]
<span class="traceContains">+parse: instruction: $foo</span>
<span class="Delimiter">:(scenario parse_multiple_properties)</span>
recipe main [
<span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal/foo:bar:baz
]
<span class="traceContains">+parse: instruction: copy</span>
<span class="traceContains">+parse: ingredient: {name: "23", properties: ["23": "literal", "foo": "bar":"baz"]}</span>
<span class="traceContains">+parse: product: {name: "1", properties: ["1": "number"]}</span>
<span class="Delimiter">:(scenario parse_multiple_products)</span>
recipe main [
<span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal
]
<span class="traceContains">+parse: instruction: copy</span>
<span class="traceContains">+parse: ingredient: {name: "23", properties: ["23": "literal"]}</span>
<span class="traceContains">+parse: product: {name: "1", properties: ["1": "number"]}</span>
<span class="traceContains">+parse: product: {name: "2", properties: ["2": "number"]}</span>
<span class="Delimiter">:(scenario parse_multiple_ingredients)</span>
recipe main [
<span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal<span class="Delimiter">,</span> <span class="Constant">4</span>:number
]
<span class="traceContains">+parse: instruction: copy</span>
<span class="traceContains">+parse: ingredient: {name: "23", properties: ["23": "literal"]}</span>
<span class="traceContains">+parse: ingredient: {name: "4", properties: ["4": "number"]}</span>
<span class="traceContains">+parse: product: {name: "1", properties: ["1": "number"]}</span>
<span class="traceContains">+parse: product: {name: "2", properties: ["2": "number"]}</span>
<span class="Delimiter">:(scenario parse_multiple_types)</span>
recipe main [
<span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal<span class="Delimiter">,</span> <span class="Constant">4</span>:number
]
<span class="traceContains">+parse: instruction: copy</span>
<span class="traceContains">+parse: ingredient: {name: "23", properties: ["23": "literal"]}</span>
<span class="traceContains">+parse: ingredient: {name: "4", properties: ["4": "number"]}</span>
<span class="traceContains">+parse: product: {name: "1", properties: ["1": "number"]}</span>
<span class="traceContains">+parse: product: {name: "2", properties: ["2": "address":"number"]}</span>
<span class="Delimiter">:(scenario parse_properties)</span>
recipe main [
<span class="Constant">1</span>:number:address/deref<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal
]
<span class="traceContains">+parse: product: {name: "1", properties: ["1": "number":"address", "deref": ]}</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->
|