| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 // Without the lexical context, TEXT will grab intervening whitespace. | 62 // Without the lexical context, TEXT will grab intervening whitespace. |
| 63 check(g, TEXT(MANY(OR(['1','a']))), ' 1a1 ', '1a1'); | 63 check(g, TEXT(MANY(OR(['1','a']))), ' 1a1 ', '1a1'); |
| 64 check(g, TEXT(MANY(OR(['1','a']))), ' 1 a 1 ', '1 a 1'); | 64 check(g, TEXT(MANY(OR(['1','a']))), ' 1 a 1 ', '1 a 1'); |
| 65 | 65 |
| 66 // Custom processing of the TEXT substring. | 66 // Custom processing of the TEXT substring. |
| 67 var binaryNumber = | 67 var binaryNumber = |
| 68 TEXT(LEX(MANY(OR(['0','1']))), | 68 TEXT(LEX(MANY(OR(['0','1']))), |
| 69 (str, start, end) { | 69 (str, start, end) { |
| 70 var r = 0; | 70 var r = 0; |
| 71 var zero = '0'.charCodeAt(0); | 71 var zero = '0'.codeUnitAt(0); |
| 72 for (int i = start; i < end; i++) | 72 for (int i = start; i < end; i++) |
| 73 r = r * 2 + (str.charCodeAt(i) - zero); | 73 r = r * 2 + (str.codeUnitAt(i) - zero); |
| 74 return r; | 74 return r; |
| 75 }); | 75 }); |
| 76 | 76 |
| 77 check(g, binaryNumber, ' 10101 ', 21); | 77 check(g, binaryNumber, ' 10101 ', 21); |
| 78 check(g, binaryNumber, '1010111', 87); | 78 check(g, binaryNumber, '1010111', 87); |
| 79 check(g, binaryNumber, '1010 111', null); | 79 check(g, binaryNumber, '1010 111', null); |
| 80 } | 80 } |
| 81 | 81 |
| 82 testOR() { | 82 testOR() { |
| 83 // OR matches the first match. | 83 // OR matches the first match. |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |