Differences From Artifact [10fa9090c50cdaf9]:
- File
polemy/value.d
- 2010-11-20 12:57:15 - part of checkin [3f6f41b558] on branch trunk - ast - table conversion (NOT AT ALL TESTED) (user: kinaba) [annotate]
To Artifact [ff42bce4fb7dc674]:
- File
polemy/value.d
- 2010-11-20 14:04:44 - part of checkin [8e3db9ef20] on branch trunk - macro worked! (user: kinaba) [annotate]
145 145 else
146 146 {
147 147 if(auto next = this.access!Table(lay,path))
148 148 return next.access!T(lay,rest);
149 149 }
150 150 return null;
151 151 }
152 +
153 + string toStringWithoutParen() const
154 + {
155 + string result;
156 + bool first = true;
157 + foreach(k, l2d; data)
158 + foreach(l,d; l2d)
159 + {
160 + if(first) first=false; else result~=", ";
161 + result ~= k;
162 + result ~= l;
163 + result ~= ":";
164 + result ~= text(cast(Value)d);
165 + }
166 + if( prototype !is null )
167 + {
168 + result ~= " / ";
169 + result ~= prototype.toStringWithoutParen();
170 + }
171 + return result;
172 + }
173 +
174 + string toString() const
175 + {
176 + return "{" ~ toStringWithoutParen() ~ "}";
177 + }
152 178
153 179 private:
154 180 Table prototype;
155 181 Kind kind;
156 182 Value[Layer][string] data;
157 183
158 184 bool setIfExist(string i, Layer lay, Value v)
................................................................................
242 268 if(auto t = cast(Table)v)
243 269 result ~= tableToAST(theLayer,t);
244 270 else
245 271 throw genex!RuntimeException(cast(LexPosition)null, "Invalid AST (non-table in cons-list)");
246 272 return result;
247 273 }
248 274
249 -AST tableToAST( Layer theLayer, Table t )
275 +AST tableToAST( Layer theLayer, Value vvvv )
250 276 {
277 + Table t = cast(Table)vvvv;
278 + if( t is null )
279 + throw genex!RuntimeException(cast(LexPosition)null, "Invalid AST (not a table)");
280 +
251 281 auto nodeType = t.access!StrValue(theLayer, "is");
252 282 if( nodeType is null )
253 283 throw genex!RuntimeException(cast(LexPosition)null, "Invalid AST {is:(not string)}");
254 284 auto pos = extractPos(t);
255 285 switch(nodeType.data)
256 286 {
257 287 case "int":
................................................................................
304 334 if(auto ll = tt.access!Table(theLayer, "layer"))
305 335 {
306 336 Layer[] ls;
307 337 foreach(lll; tableAsConsList(theLayer, ll))
308 338 if(auto l = cast(StrValue)lll)
309 339 ls ~= l.data;
310 340 else
311 - throw genex!RuntimeException(cast(LexPosition)null, `Invalid AST {bad fun params}`);
341 + throw genex!RuntimeException(cast(LexPosition)null, sprintf!`Invalid AST {bad fun params %s}`(lll));
312 342 ps ~= new Parameter(ss.data, ls);
313 343 continue;
314 344 }
315 345 else
316 346 {
317 347 Layer[] emp;
318 348 ps ~= new Parameter(ss.data, emp);
349 + continue;
319 350 }
320 - throw genex!RuntimeException(cast(LexPosition)null, `Invalid AST {bad fun params}`);
351 + throw genex!RuntimeException(cast(LexPosition)null, sprintf!`Invalid AST {bad fun params %s}`(v));
321 352 }
322 353 auto bb = tableToAST(theLayer, b);
323 354 return new FunLiteral(pos,ps,bb);
324 355 }
325 356 throw genex!RuntimeException(cast(LexPosition)null, `Invalid AST {is:"fun", param:???, body:???}`);
326 357 default:
327 358 throw genex!RuntimeException(cast(LexPosition)null, sprintf!`Invalid AST {is: "%s"} unknown`(nodeType.data));
328 359 }
329 360 }