| 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 #library("peg_tests"); | 5 #library("peg_tests"); |
| 6 #import('../../peg/pegparser.dart'); | 6 #import('../../peg/pegparser.dart'); |
| 7 | 7 |
| 8 testParens() { | 8 testParens() { |
| 9 Grammar g = new Grammar(); | 9 Grammar g = new Grammar(); |
| 10 Symbol a = g['A']; | 10 Symbol a = g['A']; |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 check(g, expression, 'sizeofa', 'sizeofa'); | 284 check(g, expression, 'sizeofa', 'sizeofa'); |
| 285 check(g, expression, 'sizeof (a)', '[sizeof-expr,a]'); | 285 check(g, expression, 'sizeof (a)', '[sizeof-expr,a]'); |
| 286 } | 286 } |
| 287 | 287 |
| 288 | 288 |
| 289 show(grammar, rule, input) { | 289 show(grammar, rule, input) { |
| 290 print('show: "$input"'); | 290 print('show: "$input"'); |
| 291 var ast; | 291 var ast; |
| 292 try { | 292 try { |
| 293 ast = grammar.parse(rule, input); | 293 ast = grammar.parse(rule, input); |
| 294 } catch (var exception) { | 294 } catch (exception) { |
| 295 if (exception is ParseError) | 295 if (exception is ParseError) |
| 296 ast = exception; | 296 ast = exception; |
| 297 else | 297 else |
| 298 throw; | 298 throw; |
| 299 } | 299 } |
| 300 print('${printList(ast)}'); | 300 print('${printList(ast)}'); |
| 301 } | 301 } |
| 302 | 302 |
| 303 void check(grammar, rule, input, expected) { | 303 void check(grammar, rule, input, expected) { |
| 304 // If [expected] is String then the result is coerced to string. | 304 // If [expected] is String then the result is coerced to string. |
| 305 // If [expected] is !String, the result is compared directly. | 305 // If [expected] is !String, the result is compared directly. |
| 306 print('check: "$input"'); | 306 print('check: "$input"'); |
| 307 var ast; | 307 var ast; |
| 308 try { | 308 try { |
| 309 ast = grammar.parse(rule, input); | 309 ast = grammar.parse(rule, input); |
| 310 } catch (var exception) { | 310 } catch (exception) { |
| 311 ast = exception; | 311 ast = exception; |
| 312 } | 312 } |
| 313 | 313 |
| 314 var formatted = ast; | 314 var formatted = ast; |
| 315 if (expected is String) | 315 if (expected is String) |
| 316 formatted = printList(ast); | 316 formatted = printList(ast); |
| 317 | 317 |
| 318 Expect.equals(expected, formatted, "parse: $input"); | 318 Expect.equals(expected, formatted, "parse: $input"); |
| 319 } | 319 } |
| 320 | 320 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 338 } | 338 } |
| 339 | 339 |
| 340 main() { | 340 main() { |
| 341 testCODE(); | 341 testCODE(); |
| 342 testParens(); | 342 testParens(); |
| 343 testOR(); | 343 testOR(); |
| 344 testTEXT(); | 344 testTEXT(); |
| 345 testBlockComment(); | 345 testBlockComment(); |
| 346 testC(); | 346 testC(); |
| 347 } | 347 } |
| OLD | NEW |