comparison parse.rhope @ 134:386f4a874821

More work on new parser
author Mike Pavone <pavone@retrodev.com>
date Wed, 10 Nov 2010 22:29:49 -0500
parents 1f238280047f
children 47ab97730865
comparison
equal deleted inserted replaced
133:e1911b2fd5cc 134:386f4a874821
122 String@Pipe Value[pipe:out] 122 String@Pipe Value[pipe:out]
123 { 123 {
124 out <- ["Pipe Value\n\tName:\t"]Append[[pipe]Name >>] 124 out <- ["Pipe Value\n\tName:\t"]Append[[pipe]Name >>]
125 } 125 }
126 126
127 Blueprint Literal
128 {
129 Value
130 }
131
132 Literal[val:out]
133 {
134 out <- [Build[Literal()]]Value <<[val]
135 }
136
127 Blueprint Block 137 Blueprint Block
128 { 138 {
129 Tree 139 Tree
130 } 140 }
131 141
149 Field Call[name,set?:out] 159 Field Call[name,set?:out]
150 { 160 {
151 out <- [[[Build[Field Call()]]Name <<[name]]Set? <<[set?]]Arguments <<[()] 161 out <- [[[Build[Field Call()]]Name <<[name]]Set? <<[set?]]Arguments <<[()]
152 } 162 }
153 163
164 After Literal[tokens,current,literal:out,out index]
165 {
166 next index <- [tokens]Next[current]
167 {
168 after <- [tokens]Index[~]
169 [after]Type Match["Call Separator"]
170 {
171 out,out index <- To Call[tokens,next index,[()]Append[literal]]
172 }{
173 [after]Type Match[("Newline","Block End","List End")]
174 {
175 out <- literal
176 out index <- current
177 }
178 }
179 }{
180 out <- literal
181 out index <- current
182 }
183 }
184
185 Parse Hex[text:out,error]
186 {
187
188 }
189
190 Parse Number[text:out,error]
191 {
192 [text]Starts With["0x"]
193 {
194 [text]Slice[2] {}
195 { out,error <- Parse Hex[~] }
196 }{
197 [text]Contains["."]
198 {
199
200 }{
201 val,sign,size <-[text]Partition[("u","i")] {} {} {}
202 {
203 //TODO: Produce "bigint" instead of Int32
204 out <- Int32[text]
205 }
206 }
207 }
208 }
209
154 Expression[tokens,current:out,out index,none] 210 Expression[tokens,current:out,out index,none]
155 { 211 {
156 token <- [tokens]Index[current] 212 token <- [tokens]Index[current]
157 [token]Type Match["Symbol"] 213 [token]Type Match["Symbol"]
158 { 214 {
161 after <- [tokens]Index[~] 217 after <- [tokens]Index[~]
162 [after]Type Match["Args Begin"] 218 [after]Type Match["Args Begin"]
163 { 219 {
164 220
165 }{ 221 }{
166 222 [after]Type Match["Call Separator"]
223 {
224
225 }{
226 [after]Type Match["Newline"]
227 {
228
229 }{
230
231 }
232 }
167 } 233 }
168 } 234 }
169 }{ 235 }{
170 [token]Type Match[("Field Get","Field Set")] 236 [token]Type Match[("Field Get","Field Set")]
171 { 237 {
180 }{ 246 }{
181 [token]Type Match["List Begin"] 247 [token]Type Match["List Begin"]
182 { 248 {
183 249
184 }{ 250 }{
185 [token]Type Match[("String Literal","Numeric Literal")] 251 [token]Type Match["String Literal"]
186 { 252 {
187 253 lit <- [token]Text >>
188 }{ 254 }{
189 [token]Type Match["Newline"] 255 [token]Type Match["Numeric Literal"]
190 { 256 {
191 ,none <- [tokens]Next[current] 257 lit <- Parse Number[[token]Text >>]
192 { out, out index <- Expression[tokens, ~] }
193 }{ 258 }{
194 none, unexpected token <- [token]Type Match["Block End"] 259 [token]Type Match["Newline"]
260 {
261 ,none <- [tokens]Next[current]
262 { out, out index <- Expression[tokens, ~] }
263 }{
264 none, unexpected token <- [token]Type Match["Block End"]
265 }
195 } 266 }
196 } 267 }
268 out,out index <- After Literal[tokens,current,Literal[lit]]
197 } 269 }
198 } 270 }
199 } 271 }
200 } 272 }
201 } 273 }
206 Print[["Body: Depth="]Append[String[depth]]] 278 Print[["Body: Depth="]Append[String[depth]]]
207 If[[depth] > [0]] 279 If[[depth] > [0]]
208 { 280 {
209 //symbol list = Symbol [List Separator symbol list] 281 //symbol list = Symbol [List Separator symbol list]
210 //value = String Literal | Number Literal | List Literal | Symbol | Block Reference | expression 282 //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] 283 //call = [Args Begin arg list Args End]Symbol[Args Begin arg list Args End] | (value | Arg Placeholder) Call Separator Symbol
212 //arg list = value | Arg Placeholder [List Separator arg list] 284 //arg list = value | Arg Placeholder [List Separator arg list]
213 //block = Block Begin [expressions] Block End 285 //block = Block Begin [expressions] Block End
214 //blocks = block [blocks] 286 //blocks = block [blocks]
215 //expressions = expression [expressions] 287 //expressions = expression [expressions]
216 //expression = [symbol list Assignment] call | value blocks | Newline 288 //expression = [symbol list Assignment] call | value blocks | Newline