Mercurial > repos > rhope
comparison parse.rhope @ 132:1f238280047f
Some work on expression parsing in new parser
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 05 Nov 2010 01:23:25 -0400 |
parents | 0a4682be2db2 |
children | 386f4a874821 |
comparison
equal
deleted
inserted
replaced
131:0a4682be2db2 | 132:1f238280047f |
---|---|
84 ]Append[ [[String[[statement]Expression >>]]Split["\n"]]Join["\n\t"] ] | 84 ]Append[ [[String[[statement]Expression >>]]Split["\n"]]Join["\n\t"] ] |
85 ]Append[ ["\n\tAssignments:\t"]Append[[[statement]Assignments >>]Join[", "]] ] | 85 ]Append[ ["\n\tAssignments:\t"]Append[[[statement]Assignments >>]Join[", "]] ] |
86 ]Append[ ["\n\tBlocks:\t"]Append[ [[String[[statement]Blocks >>]]Split["\n"]]Join["\n\t"] ] ] | 86 ]Append[ ["\n\tBlocks:\t"]Append[ [[String[[statement]Blocks >>]]Split["\n"]]Join["\n\t"] ] ] |
87 } | 87 } |
88 | 88 |
89 Blueprint Worker Expression | 89 Blueprint Worker Call |
90 { | 90 { |
91 Worker | 91 Worker |
92 Blueprint | 92 Blueprint |
93 Arguments | 93 Arguments |
94 } | 94 } |
95 | 95 |
96 String@Worker Expression[exp:out] | 96 Worker Call[worker,blueprint:out] |
97 { | 97 { |
98 out <- ["Worker Expression\n\tWorker:\t"]Append[[exp]Worker >>] | 98 out <- [[[Build[Worker Call()]]Worker <<[worker]]Blueprint <<[blueprint]]Arguments <<[()] |
99 } | 99 } |
100 | 100 |
101 Blueprint Global Expression | 101 String@Worker Call[exp:out] |
102 { | |
103 out <- ["Worker Call\n\tWorker:\t"]Append[[exp]Worker >>] | |
104 } | |
105 | |
106 Blueprint Global Reference | |
102 { | 107 { |
103 Store | 108 Store |
104 Variable | 109 Variable |
105 } | 110 } |
106 | 111 |
107 Blueprint Pipe Expression | 112 Blueprint Pipe Value |
108 { | 113 { |
109 Name | 114 Name |
110 } | 115 } |
111 | 116 |
112 Pipe Expression[name:out] | 117 Pipe Value[name:out] |
113 { | 118 { |
114 out <- [Build[Pipe Expression()]]Name <<[name] | 119 out <- [Build[Pipe Value()]]Name <<[name] |
115 } | 120 } |
116 | 121 |
117 String@Pipe Expression[pipe:out] | 122 String@Pipe Value[pipe:out] |
118 { | 123 { |
119 out <- ["Pipe Expression\n\tName:\t"]Append[[pipe]Name >>] | 124 out <- ["Pipe Value\n\tName:\t"]Append[[pipe]Name >>] |
120 } | 125 } |
121 | 126 |
122 Blueprint Block | 127 Blueprint Block |
123 { | 128 { |
124 Tree | 129 Tree |
132 String@Block[block:out] | 137 String@Block[block:out] |
133 { | 138 { |
134 out <- Fold[_String Seq[?], "Block", [block]Tree >>] | 139 out <- Fold[_String Seq[?], "Block", [block]Tree >>] |
135 } | 140 } |
136 | 141 |
137 Blueprint Field Expression | 142 Blueprint Field Call |
138 { | 143 { |
139 Name | 144 Name |
140 Set? | 145 Set? |
141 } | 146 Arguments |
142 | 147 } |
143 Field Expression[name,set?:out] | 148 |
144 { | 149 Field Call[name,set?:out] |
145 out <- [[Build[Field Expression()]]Name <<[name]]Set? <<[set?] | 150 { |
146 } | 151 out <- [[[Build[Field Call()]]Name <<[name]]Set? <<[set?]]Arguments <<[()] |
152 } | |
153 | |
154 Expression[tokens,current:out,out index,none] | |
155 { | |
156 token <- [tokens]Index[current] | |
157 [token]Type Match["Symbol"] | |
158 { | |
159 ,end stream <- [tokens]Next[current] | |
160 { | |
161 after <- [tokens]Index[~] | |
162 [after]Type Match["Args Begin"] | |
163 { | |
164 | |
165 }{ | |
166 | |
167 } | |
168 } | |
169 }{ | |
170 [token]Type Match[("Field Get","Field Set")] | |
171 { | |
172 [token]Type Match["Field Set"] | |
173 { set? <- Yes } | |
174 { set? <- No } | |
175 Field Call[[token]Text >>, set?] | |
176 }{ | |
177 [token]Type Match["Args Begin"] | |
178 { | |
179 | |
180 }{ | |
181 [token]Type Match["List Begin"] | |
182 { | |
183 | |
184 }{ | |
185 [token]Type Match[("String Literal","Numeric Literal")] | |
186 { | |
187 | |
188 }{ | |
189 [token]Type Match["Newline"] | |
190 { | |
191 ,none <- [tokens]Next[current] | |
192 { out, out index <- Expression[tokens, ~] } | |
193 }{ | |
194 none, unexpected token <- [token]Type Match["Block End"] | |
195 } | |
196 } | |
197 } | |
198 } | |
199 } | |
200 } | |
201 } | |
202 | |
147 | 203 |
148 Body[node,tokens,current,depth:out,out index, done] | 204 Body[node,tokens,current,depth:out,out index, done] |
149 { | 205 { |
150 Print[["Body: Depth="]Append[String[depth]]] | 206 Print[["Body: Depth="]Append[String[depth]]] |
151 If[[depth] > [0]] | 207 If[[depth] > [0]] |
152 { | 208 { |
209 //symbol list = Symbol [List Separator symbol list] | |
210 //value = String Literal | Number Literal | List Literal | Symbol | Block Reference | expression | |
211 //call = [Args Begin arg list Args End]Symbol[Args Begin arg list Args End] | |
212 //arg list = value | Arg Placeholder [List Separator arg list] | |
213 //block = Block Begin [expressions] Block End | |
214 //blocks = block [blocks] | |
215 //expressions = expression [expressions] | |
216 //expression = [symbol list Assignment] call | value blocks | Newline | |
153 token <- [tokens]Index[current] | 217 token <- [tokens]Index[current] |
154 [token]Type Match["Block Begin"] | 218 [token]Type Match["Block Begin"] |
155 { | 219 { |
156 ,end stream <- [tokens]Next[current] | 220 ,end stream <- [tokens]Next[current] |
157 { | 221 { |
453 } | 517 } |
454 } | 518 } |
455 } | 519 } |
456 | 520 |
457 }{ | 521 }{ |
458 [token]Type Match[("Newline","Block Comment","Line Comment")] | 522 [token]Type Match["Newline"] |
459 { | 523 { |
460 next nodes <- Val[nodes] | 524 next nodes <- Val[nodes] |
461 next index <- Val[current] | 525 next index <- Val[current] |
462 }{ | 526 }{ |
463 Print[String[Error[["Unexpected token of type "]Append[[token]Type >>], [token]Raw Text >>]]] | 527 Print[String[Error[["Unexpected token of type "]Append[[token]Type >>], [token]Raw Text >>]]] |
469 }{ | 533 }{ |
470 out <- Val[next nodes] | 534 out <- Val[next nodes] |
471 } | 535 } |
472 } | 536 } |
473 | 537 |
538 NotComment[token:out] | |
539 { | |
540 [token]Type Match[("Block Comment","Line Comment")] | |
541 { | |
542 out <- No | |
543 }{ | |
544 out <- Yes | |
545 } | |
546 } | |
547 | |
474 Parse[tokens:out] | 548 Parse[tokens:out] |
475 { | 549 { |
476 [tokens]First | 550 [tokens]First |
477 { | 551 { |
478 out <- Top Level[tokens, ~, ()] | 552 out <- Top Level[Filter[tokens, NotComment[?]], ~, ()] |
479 }{ | 553 }{ |
480 out <- () | 554 out <- () |
481 } | 555 } |
482 } | 556 } |
557 |