| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 #library('idlparser_test'); | |
| 6 #import('../../../utils/peg/pegparser.dart'); | |
| 7 #source('idlparser.dart'); | |
| 8 #source('idlrenderer.dart'); | |
| 9 | |
| 10 main() { | |
| 11 IDLParser parser = new IDLParser(FREMONTCUT_SYNTAX); | |
| 12 Grammar g = parser.grammar; | |
| 13 | |
| 14 var Type = g['Type']; | |
| 15 | |
| 16 show(g, Type, 'int'); | |
| 17 show(g, Type, 'int ?'); | |
| 18 show(g, Type, 'sequence<int?> ?'); | |
| 19 show(g, Type, 'unsigned long long?'); | |
| 20 show(g, Type, 'unsignedlonglong?'); | |
| 21 | |
| 22 | |
| 23 var MaybeAnnotations = g['MaybeAnnotations']; | |
| 24 | |
| 25 show(g, MaybeAnnotations, ''); | |
| 26 show(g, MaybeAnnotations, '@Foo'); | |
| 27 show(g, MaybeAnnotations, '@Foo @Bar'); | |
| 28 show(g, MaybeAnnotations, '@Foo(A,B=1) @Bar'); | |
| 29 | |
| 30 var MaybeExtAttrs = g['MaybeExtAttrs']; | |
| 31 print(MaybeExtAttrs); | |
| 32 | |
| 33 show(g, MaybeExtAttrs, ''); | |
| 34 show(g, MaybeExtAttrs, '[A]'); | |
| 35 | |
| 36 var Module = g['Module']; | |
| 37 | |
| 38 show(g, Module, 'module Harry { const int bob = 30;};'); | |
| 39 show(g, Module, """ | |
| 40 module Harry { [X,Y,Z=99] const int bob = 30; typedef x y; | |
| 41 | |
| 42 interface Thing : SuperA, @Friendly SuperB { | |
| 43 | |
| 44 [Nice] const unsigned long long kFoo = 12345; | |
| 45 [A,B,C,D,E] attribute int attr1; | |
| 46 [F=f(int a),K=99,DartName=Bert] int smudge(int a, int b, double x); | |
| 47 | |
| 48 [X,Y,Z] int xyz([U,V] optional in optional int z); | |
| 49 [P,Q,R] int pqr(); | |
| 50 int op1(); | |
| 51 @Smurf @Beans(B=1,C,A=2) int op2(); | |
| 52 | |
| 53 snippet { yadda | |
| 54 yadda | |
| 55 }; | |
| 56 }; | |
| 57 | |
| 58 //[A] const unsigned long long dweeb = 0xff; | |
| 59 | |
| 60 }; | |
| 61 """); | |
| 62 } | |
| 63 | |
| 64 | |
| 65 | |
| 66 show(grammar, rule, input) { | |
| 67 print('show: "$input"'); | |
| 68 var ast; | |
| 69 try { | |
| 70 ast = grammar.parse(rule, input); | |
| 71 } catch (var exception) { | |
| 72 if (exception is ParseError) | |
| 73 ast = exception; | |
| 74 else | |
| 75 throw; | |
| 76 } | |
| 77 print('${printList(ast)}'); | |
| 78 print(render(ast)); | |
| 79 } | |
| 80 | |
| 81 void check(grammar, rule, input, expected) { | |
| 82 // If [expected] is String then the result is coerced to string. | |
| 83 // If [expected] is !String, the result is compared directly. | |
| 84 print('check: "$input"'); | |
| 85 var ast; | |
| 86 try { | |
| 87 ast = grammar.parse(rule, input); | |
| 88 } catch (var exception) { | |
| 89 ast = exception; | |
| 90 } | |
| 91 | |
| 92 var formatted = ast; | |
| 93 if (expected is String) | |
| 94 formatted = printList(ast); | |
| 95 | |
| 96 Expect.equals(expected, formatted, "parse: $input"); | |
| 97 } | |
| 98 | |
| 99 // Prints the list in [1,2,3] notation, including nested lists. | |
| 100 void printList(item) { | |
| 101 if (item is List) { | |
| 102 StringBuffer sb = new StringBuffer(); | |
| 103 sb.add('['); | |
| 104 var sep = ''; | |
| 105 for (var x in item) { | |
| 106 sb.add(sep); | |
| 107 sb.add(printList(x)); | |
| 108 sep = ','; | |
| 109 } | |
| 110 sb.add(']'); | |
| 111 return sb.toString(); | |
| 112 } | |
| 113 if (item == null) | |
| 114 return 'null'; | |
| 115 return item.toString(); | |
| 116 } | |
| OLD | NEW |