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

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

Issue 10891022: Update corelib/ and lib/ to use the new try-catch syntax. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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
OLDNEW
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('idlparser_test'); 5 #library('idlparser_test');
6 #import('../../../utils/peg/pegparser.dart'); 6 #import('../../../utils/peg/pegparser.dart');
7 #source('idlparser.dart'); 7 #source('idlparser.dart');
8 #source('idlrenderer.dart'); 8 #source('idlrenderer.dart');
9 9
10 main() { 10 main() {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 """); 61 """);
62 } 62 }
63 63
64 64
65 65
66 show(grammar, rule, input) { 66 show(grammar, rule, input) {
67 print('show: "$input"'); 67 print('show: "$input"');
68 var ast; 68 var ast;
69 try { 69 try {
70 ast = grammar.parse(rule, input); 70 ast = grammar.parse(rule, input);
71 } catch (var exception) { 71 } catch (exception) {
72 if (exception is ParseError) 72 if (exception is ParseError)
73 ast = exception; 73 ast = exception;
74 else 74 else
75 throw; 75 throw;
76 } 76 }
77 print('${printList(ast)}'); 77 print('${printList(ast)}');
78 print(render(ast)); 78 print(render(ast));
79 } 79 }
80 80
81 void check(grammar, rule, input, expected) { 81 void check(grammar, rule, input, expected) {
82 // If [expected] is String then the result is coerced to string. 82 // If [expected] is String then the result is coerced to string.
83 // If [expected] is !String, the result is compared directly. 83 // If [expected] is !String, the result is compared directly.
84 print('check: "$input"'); 84 print('check: "$input"');
85 var ast; 85 var ast;
86 try { 86 try {
87 ast = grammar.parse(rule, input); 87 ast = grammar.parse(rule, input);
88 } catch (var exception) { 88 } catch (exception) {
89 ast = exception; 89 ast = exception;
90 } 90 }
91 91
92 var formatted = ast; 92 var formatted = ast;
93 if (expected is String) 93 if (expected is String)
94 formatted = printList(ast); 94 formatted = printList(ast);
95 95
96 Expect.equals(expected, formatted, "parse: $input"); 96 Expect.equals(expected, formatted, "parse: $input");
97 } 97 }
98 98
99 // Prints the list in [1,2,3] notation, including nested lists. 99 // Prints the list in [1,2,3] notation, including nested lists.
100 void printList(item) { 100 void printList(item) {
101 if (item is List) { 101 if (item is List) {
102 StringBuffer sb = new StringBuffer(); 102 StringBuffer sb = new StringBuffer();
103 sb.add('['); 103 sb.add('[');
104 var sep = ''; 104 var sep = '';
105 for (var x in item) { 105 for (var x in item) {
106 sb.add(sep); 106 sb.add(sep);
107 sb.add(printList(x)); 107 sb.add(printList(x));
108 sep = ','; 108 sep = ',';
109 } 109 }
110 sb.add(']'); 110 sb.add(']');
111 return sb.toString(); 111 return sb.toString();
112 } 112 }
113 if (item == null) 113 if (item == null)
114 return 'null'; 114 return 'null';
115 return item.toString(); 115 return item.toString();
116 } 116 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/typechecker.dart ('k') | lib/dom/templates/html/dart2js/impl_Window.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698