OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #import('pegparser.dart'); | 5 #import('../../../peg/pegparser.dart'); |
6 | 6 |
7 testParens() { | 7 testParens() { |
8 Grammar g = new Grammar(); | 8 Grammar g = new Grammar(); |
9 Symbol a = g['A']; | 9 Symbol a = g['A']; |
10 | 10 |
11 a.def = ['(', MANY(a, min:0), ')', (a) => a]; | 11 a.def = ['(', MANY(a, min:0), ')', (a) => a]; |
12 | 12 |
13 check(g, a, "", null); | 13 check(g, a, "", null); |
14 check(g, a, "()", '[]'); | 14 check(g, a, "()", '[]'); |
15 check(g, a, "(()())", '[[],[]]'); | 15 check(g, a, "(()())", '[[],[]]'); |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 } | 311 } |
312 | 312 |
313 var formatted = ast; | 313 var formatted = ast; |
314 if (expected is String) | 314 if (expected is String) |
315 formatted = printList(ast); | 315 formatted = printList(ast); |
316 | 316 |
317 Expect.equals(expected, formatted, "parse: $input"); | 317 Expect.equals(expected, formatted, "parse: $input"); |
318 } | 318 } |
319 | 319 |
320 // Prints the list in [1,2,3] notation, including nested lists. | 320 // Prints the list in [1,2,3] notation, including nested lists. |
321 void printList(item) { | 321 printList(item) { |
322 if (item is List) { | 322 if (item is List) { |
323 StringBuffer sb = new StringBuffer(); | 323 StringBuffer sb = new StringBuffer(); |
324 sb.add('['); | 324 sb.add('['); |
325 var sep = ''; | 325 var sep = ''; |
326 for (var x in item) { | 326 for (var x in item) { |
327 sb.add(sep); | 327 sb.add(sep); |
328 sb.add(printList(x)); | 328 sb.add(printList(x)); |
329 sep = ','; | 329 sep = ','; |
330 } | 330 } |
331 sb.add(']'); | 331 sb.add(']'); |
332 return sb.toString(); | 332 return sb.toString(); |
333 } | 333 } |
334 if (item == null) | 334 if (item == null) |
335 return 'null'; | 335 return 'null'; |
336 return item.toString(); | 336 return item.toString(); |
337 } | 337 } |
338 | 338 |
339 main() { | 339 main() { |
340 testCODE(); | 340 testCODE(); |
341 testParens(); | 341 testParens(); |
342 testOR(); | 342 testOR(); |
343 testTEXT(); | 343 testTEXT(); |
344 testBlockComment(); | 344 testBlockComment(); |
345 testC(); | 345 testC(); |
346 } | 346 } |
OLD | NEW |