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

Side by Side Diff: sdk/lib/html/scripts/idlparser_test.dart

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

Powered by Google App Engine
This is Rietveld 408576698