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