Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: client/dom/scripts/idlparser_test.dart

Issue 8404031: IDL parser (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « client/dom/scripts/idlparser.dart ('k') | client/dom/scripts/idlrenderer.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #import('../../../utils/peg/pegparser.dart');
6 #source('idlparser.dart');
7 #source('idlrenderer.dart');
8
9 main() {
10 IDLParser parser = new IDLParser(FREMONTCUT_SYNTAX);
11 Grammar g = parser.grammar;
12
13 var Type = g['Type'];
14
15 show(g, Type, 'int');
16 show(g, Type, 'int ?');
17 show(g, Type, 'sequence<int?> ?');
18 show(g, Type, 'unsigned long long?');
19 show(g, Type, 'unsignedlonglong?');
20
21
22 var MaybeAnnotations = g['MaybeAnnotations'];
23
24 show(g, MaybeAnnotations, '');
25 show(g, MaybeAnnotations, '@Foo');
26 show(g, MaybeAnnotations, '@Foo @Bar');
27 show(g, MaybeAnnotations, '@Foo(A,B=1) @Bar');
28
29 var MaybeExtAttrs = g['MaybeExtAttrs'];
30 print(MaybeExtAttrs);
31
32 show(g, MaybeExtAttrs, '');
33 show(g, MaybeExtAttrs, '[A]');
34
35 var Module = g['Module'];
36
37 show(g, Module, 'module Harry { const int bob = 30;};');
38 show(g, Module, """
39 module Harry { [X,Y,Z=99] const int bob = 30; typedef x y;
40
41 interface Thing : SuperA, @Friendly SuperB {
42
43 [Nice] const unsigned long long kFoo = 12345;
44 [A,B,C,D,E] attribute int attr1;
45 [F=f(int a),K=99,DartName=Bert] int smudge(int a, int b, double x);
46
47 [X,Y,Z] int xyz([U,V] optional in optional int z);
48 [P,Q,R] int pqr();
49 int op1();
50 @Smurf @Beans(B=1,C,A=2) int op2();
51
52 snippet { yadda
53 yadda
54 };
55 };
56
57 //[A] const unsigned long long dweeb = 0xff;
58
59 };
60 """);
61 }
62
63
64
65 show(grammar, rule, input) {
66 print('show: "$input"');
67 var ast;
68 try {
69 ast = grammar.parse(rule, input);
70 } catch (var exception) {
71 if (exception is ParseError)
72 ast = exception;
73 else
74 throw;
75 }
76 print('${printList(ast)}');
77 print(render(ast));
78 }
79
80 void check(grammar, rule, input, expected) {
81 // If [expected] is String then the result is coerced to string.
82 // If [expected] is !String, the result is compared directly.
83 print('check: "$input"');
84 var ast;
85 try {
86 ast = grammar.parse(rule, input);
87 } catch (var exception) {
88 ast = exception;
89 }
90
91 var formatted = ast;
92 if (expected is String)
93 formatted = printList(ast);
94
95 Expect.equals(expected, formatted, "parse: $input");
96 }
97
98 // Prints the list in [1,2,3] notation, including nested lists.
99 void printList(item) {
100 if (item is List) {
101 StringBuffer sb = new StringBuffer();
102 sb.add('[');
103 var sep = '';
104 for (var x in item) {
105 sb.add(sep);
106 sb.add(printList(x));
107 sep = ',';
108 }
109 sb.add(']');
110 return sb.toString();
111 }
112 if (item == null)
113 return 'null';
114 return item.toString();
115 }
OLDNEW
« no previous file with comments | « client/dom/scripts/idlparser.dart ('k') | client/dom/scripts/idlrenderer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698