Mercurial > repos > rhope
annotate parse.rhope @ 115:04148770c229
Merge
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 13 Oct 2010 01:18:53 +0000 |
parents | a4d2d633a356 |
children | 0a4682be2db2 |
rev | line source |
---|---|
2 | 1 |
2 Blueprint Error | |
3 { | |
4 Message | |
5 Line | |
6 Column | |
7 } | |
8 | |
9 Error[msg,text:out] | |
10 { | |
11 out <- [[[Build["Error"]]Message <<[msg]]Line << [ [[text]Line >>]+[1] ]]Column << [ [[text]Column >>]+[1] ] | |
12 } | |
13 | |
14 To String@Error[error:out] | |
15 { | |
16 out <- [[[[[error]Message >>]Append[" on line "]]Append[[error]Line >>]]Append[" at column "]]Append[[error]Column >>] | |
17 } | |
18 | |
19 Blueprint PImport Node | |
20 { | |
21 File | |
22 } | |
23 | |
24 PImport Node[file:out] | |
25 { | |
26 out <- [Build["PImport Node"]]File <<[file] | |
27 } | |
28 | |
29 Blueprint Worker Node | |
30 { | |
31 Name | |
32 Blueprint | |
33 Inputs | |
34 Outputs | |
35 Tree | |
36 } | |
37 | |
38 Add Node Input@Worker Node[node,input:out] | |
39 { | |
40 Print["Add Node Input"] | |
41 Print[["Input: "]Append[To String[input]]] | |
42 out <- [node]Inputs <<[[[node]Inputs >>]Append[input]] | |
43 } | |
44 | |
45 Add Node Output@Worker Node[node,output:out] | |
46 { | |
47 out <- [node]Outputs <<[[[node]Outputs >>]Append[output]] | |
48 } | |
49 | |
5
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
50 Blueprint Statement |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
51 { |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
52 Expression |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
53 Assignments |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
54 Blocks |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
55 } |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
56 |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
57 Statement[expression,assignments:out] |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
58 { |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
59 out <- [[[Build["Statement"]]Expression <<[expression]]Assignments <<[assignments]]Blocks <<[()] |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
60 } |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
61 |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
62 Add Block@Statement[statement,block:out] |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
63 { |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
64 out <- [statement]Blocks <<[ [[statement]Blocks >>]Append[block] ] |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
65 } |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
66 |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
67 Blueprint Worker Expression |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
68 { |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
69 Worker |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
70 Blueprint |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
71 Arguments |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
72 } |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
73 |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
74 Blueprint Global Expression |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
75 { |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
76 Store |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
77 Variable |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
78 } |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
79 |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
80 Blueprint Pipe Expression |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
81 { |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
82 Name |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
83 } |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
84 |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
85 Pipe Expression[name:out] |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
86 { |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
87 out <- [Build["Pipe Expression"]]Name <<[name] |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
88 } |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
89 |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
90 Blueprint Block |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
91 { |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
92 Tree |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
93 } |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
94 |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
95 Block[:out] |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
96 { |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
97 out <- [Build["Block"]]Tree <<[()] |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
98 } |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
99 |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
100 Blueprint Field Expression |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
101 { |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
102 Name |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
103 Set? |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
104 } |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
105 |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
106 Field Expression[name,set?:out] |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
107 { |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
108 out <- [[Build["Field Expression"]]Name <<[name]]Set? <<[set?] |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
109 } |
a4d2d633a356
Groundwork for parsing expressions in new parser
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
110 |
2 | 111 Body[node,tokens,current,depth:out,out index, done] |
112 { | |
113 Print[["Body: Depth="]Append[depth]] | |
114 If[[depth] > [0]] | |
115 { | |
116 token <- [tokens]Index[current] | |
117 [token]Type Match["Block Begin"] | |
118 { | |
119 ,end stream <- [tokens]Next[current] | |
120 { | |
121 out,out index, done <- Body[node,tokens,~,[depth]+[1]] | |
122 } | |
123 }{ | |
124 [token]Type Match["Block End"] | |
125 { | |
126 [tokens]Next[current] | |
127 { | |
128 out,out index, done <- Body[node,tokens,~,[depth]-[1]] | |
129 }{ | |
130 ,end stream <- If[[depth] = [1]] | |
131 { | |
132 Print["done"] | |
133 out <- Val[node] | |
134 done <- Yes | |
135 } | |
136 } | |
137 }{ | |
138 ,end stream <- [tokens]Next[current] | |
139 { | |
140 out,out index, done <- Body[node,tokens,~,depth] | |
141 } | |
142 } | |
143 } | |
144 }{ | |
145 out <- node | |
146 out index <- current | |
147 } | |
148 Val[end stream] | |
149 { | |
150 Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]] | |
151 } | |
152 } | |
153 | |
154 Before Body[node,tokens,current:out,out index, done] | |
155 { | |
156 Print["Before body"] | |
157 token <- [tokens]Index[current] | |
158 next,end stream <- [tokens]Next[current] | |
159 { | |
160 [token]Type Match["Block Begin"] | |
161 { | |
162 out,out index, done <- Body[node,tokens,next,1] | |
163 }{ | |
164 out,out index, done <- Before Body[node,tokens,next] | |
165 } | |
166 } | |
167 Val[end stream] | |
168 { | |
169 Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]] | |
170 } | |
171 } | |
172 | |
173 Outputs[node,tokens,current:out,out index, done] | |
174 { | |
175 Print["outputs"] | |
176 token <- [tokens]Index[current] | |
177 next,end stream <- [tokens]Next[current] | |
178 { | |
179 [token]Type Match["Symbol"] | |
180 { | |
181 out,out index, done <- Outputs[[node]Add Node Output[[token]Text >>], tokens, next] | |
182 }{ | |
183 [token]Type Match["Args End"] | |
184 { | |
185 out,out index, done <- Before Body[node, tokens, next] | |
186 }{ | |
187 [token]Type Match[("List Separator","Block Comment","Line Comment","Newline")] | |
188 { | |
189 out,out index, done <- Outputs[node, tokens, next] | |
190 }{ | |
191 Print[To String[Error[["Unexpected token of type "]Append[[token]Type >>], [token]Raw Text >>]]] | |
192 } | |
193 } | |
194 } | |
195 } | |
196 Val[end stream] | |
197 { | |
198 Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]] | |
199 } | |
200 } | |
201 | |
202 Inputs[node,tokens,current:out,out index, done] | |
203 { | |
204 Print["Inputs"] | |
205 token <- [tokens]Index[current] | |
206 next,end stream <- [tokens]Next[current] | |
207 { | |
208 [token]Type Match["Symbol"] | |
209 { | |
210 | |
211 out,out index, done <- Inputs[[node]Add Node Input[[token]Text >>], tokens, next] | |
212 }{ | |
213 [token]Type Match["Name Separator"] | |
214 { | |
215 Print["in out sep"] | |
216 out,out index, done <- Outputs[node, tokens, next] | |
217 }{ | |
218 [token]Type Match["Args End"] | |
219 { | |
220 out,out index, done <- Before Body[node, tokens, next] | |
221 }{ | |
222 [token]Type Match[("List Separator","Block Comment","Line Comment","Newline")] | |
223 { | |
224 out,out index,done <- Inputs[node, tokens, next] | |
225 }{ | |
226 Print[To String[Error[["Unexpected token of type "]Append[[token]Type >>], [token]Raw Text >>]]] | |
227 } | |
228 } | |
229 } | |
230 } | |
231 } | |
232 Val[end stream] | |
233 { | |
234 Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]] | |
235 } | |
236 } | |
237 | |
238 Method[node,tokens,current:out,out index,done] | |
239 { | |
240 token <- [tokens]Index[current] | |
241 next <- [tokens]Next[current] | |
242 { | |
243 [token]Type Match["Symbol"] | |
244 { | |
245 out,out index,done <- Before Inputs[[node]Blueprint <<[[token]Text >>], tokens, next] | |
246 }{ | |
247 [token]Type Match[("List Separator","Block Comment","Line Comment","Newline")] | |
248 { | |
249 out,out index,done <- Method[node, tokens, next] | |
250 }{ | |
251 Print[To String[Error[["Unexpected token of type "]Append[[token]Type >>], [token]Raw Text >>]]] | |
252 } | |
253 } | |
254 }{ | |
255 Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]] | |
256 } | |
257 } | |
258 | |
259 //TODO: support method declarations | |
260 Before Inputs[node, tokens, current:out, out index, done] | |
261 { | |
262 Print["Before Inputs"] | |
263 token <- [tokens]Index[current] | |
264 [token]Type Match["Args Begin"] | |
265 { | |
266 [tokens]Next[current] | |
267 { | |
268 out,out index, done <- Inputs[node, tokens, ~] | |
269 }{ | |
270 Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]] | |
271 } | |
272 }{ | |
273 [token]Type Match["Method Separator"] | |
274 { | |
275 [tokens]Next[current] | |
276 { | |
277 out,out index,done <- Method[node, tokens, ~] | |
278 }{ | |
279 Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]] | |
280 } | |
281 }{ | |
282 [token]Type Match[("Line Comment","Block Comment","Newline")] | |
283 { | |
284 continue <- Yes | |
285 }{ | |
286 Print[To String[Error[["Unexpected token of type "]Append[[token]Type >>], [token]Raw Text >>]]] | |
287 } | |
288 Val[continue] | |
289 { | |
290 [tokens]Next[current] | |
291 { | |
292 out,out index, done <- Before Inputs[node, tokens, ~] | |
293 }{ | |
294 Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]] | |
295 } | |
296 } | |
297 } | |
298 } | |
299 } | |
300 | |
301 Worker Node[name, tokens, current:out,out index, done] | |
302 { | |
303 Print[["Worker: "]Append[To String[name]]] | |
304 out,out index, done <- Before Inputs[[[[[Build["Worker Node"]]Name <<[name]]Inputs <<[()]]Outputs <<[()]]Tree <<[()], tokens, current] | |
305 } | |
306 | |
4
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
307 Skip Nodes[toskip, stop, tokens, current:out] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
308 { |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
309 token <- [tokens]Index[current] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
310 next <- [tokens]Next[current] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
311 { |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
312 [token]Type Match[stop] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
313 { |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
314 out <- Val[next] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
315 }{ |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
316 [token]Type Match[toskip] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
317 { |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
318 out <- Skip Nodes[toskip, stop, tokens, next] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
319 }{ |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
320 Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
321 } |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
322 } |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
323 }{ |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
324 Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
325 } |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
326 } |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
327 |
2 | 328 Blueprint PBlueprint Node |
329 { | |
330 Name | |
331 Fields | |
332 } | |
333 | |
4
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
334 Fields[node,tokens,current:out,out index,done] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
335 { |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
336 token <- [tokens]Index[current] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
337 next <- [tokens]Next[current] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
338 { |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
339 [token]Type Match["Symbol"] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
340 { |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
341 out,out index,done <- Fields[[node]Add BField[[token]Text >>], tokens, next] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
342 }{ |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
343 [token]Type Match["Block End"] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
344 { |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
345 out <- Val[node] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
346 out index <- Val[next] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
347 }{ |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
348 [token]Type Match[("Newline","Line Comment","Block Comment")] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
349 { |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
350 out,out index,done <- Fields[node, tokens, next] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
351 }{ |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
352 Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
353 } |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
354 } |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
355 } |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
356 }{ |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
357 [token]Type Match["Block End"] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
358 { |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
359 out <- Val[node] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
360 done <- Yes |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
361 }{ |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
362 Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
363 } |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
364 } |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
365 } |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
366 |
2 | 367 PBlueprint Node[name, tokens, current:out,out index,done] |
368 { | |
4
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
369 node <- [[Build["PBlueprint Node"]]Name <<[name]]Fields <<[()] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
370 next <- Skip Nodes[("Newline","Block Comment","Comment"), "Block Begin", tokens, current] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
371 out,out index,done <- Fields[node, tokens, next] |
2 | 372 } |
373 | |
4
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
374 Add BField@PBlueprint Node[node,field:out] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
375 { |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
376 out <- [node]Fields <<[[[node]Fields >>]Append[field]] |
0c5f24b4f69d
Handle blueprints in new parser
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
377 } |
2 | 378 |
379 Top Level[tokens, current, nodes:out] | |
380 { | |
381 token <- [tokens]Index[current] | |
382 Print[[token]Type >>] | |
383 [token]Type Match["Symbol"] | |
384 { | |
385 [[token]Text >>]After["Import "] | |
386 { | |
387 next nodes <- [nodes]Append[PImport Node[~]] | |
388 next index <- Val[current] | |
389 }{ | |
390 blueprint name,worker name <- [~]After["Blueprint "] | |
391 { | |
392 [tokens]Next[current] | |
393 { | |
394 , next index <- PBlueprint Node[blueprint name, tokens, ~] | |
395 { | |
396 next nodes <- [nodes]Append[~] | |
397 } {} { | |
398 Print["done!"] | |
399 out <- Val[next nodes] | |
400 } | |
401 }{ | |
402 Print[To String[Error[["Unexpected end of stream after symbol "]Append[[token]Text >>], [token]Raw Text >>]]] | |
403 } | |
404 }{ | |
405 [tokens]Next[current] | |
406 { | |
407 , next index <- Worker Node[worker name, tokens, ~] | |
408 { | |
409 next nodes <- [nodes]Append[~] | |
410 } {} { | |
411 Print["done!"] | |
412 out <- Val[next nodes] | |
413 } | |
414 }{ | |
415 Print[To String[Error[["Unexpected end of stream after symbol "]Append[[token]Text >>], [token]Raw Text >>]]] | |
416 } | |
417 } | |
418 } | |
419 | |
420 }{ | |
421 [token]Type Match[("Newline","Block Comment","Line Comment")] | |
422 { | |
423 next nodes <- Val[nodes] | |
424 next index <- Val[current] | |
425 }{ | |
426 Print[To String[Error[["Unexpected token of type "]Append[[token]Type >>], [token]Raw Text >>]]] | |
427 } | |
428 } | |
429 [tokens]Next[next index] | |
430 { | |
431 out <- Top Level[tokens, ~, next nodes] | |
432 }{ | |
433 out <- Val[next nodes] | |
434 } | |
435 } | |
436 | |
437 Parse[tokens:out] | |
438 { | |
439 [tokens]First | |
440 { | |
441 out <- Top Level[tokens, ~, ()] | |
442 }{ | |
443 out <- () | |
444 } | |
445 } |