OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 import "package:compiler/src/parser/element_listener.dart"; | 6 import "package:compiler/src/parser/element_listener.dart"; |
7 import "package:compiler/src/parser/node_listener.dart"; | 7 import "package:compiler/src/parser/node_listener.dart"; |
8 import "package:compiler/src/parser/parser.dart"; | 8 import "package:compiler/src/parser/parser.dart"; |
9 import "package:compiler/src/scanner/string_scanner.dart"; | 9 import "package:compiler/src/scanner/string_scanner.dart"; |
10 import "package:compiler/src/tokens/token.dart"; | 10 import "package:compiler/src/tokens/token.dart"; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 86 |
87 String doUnparse(String source) { | 87 String doUnparse(String source) { |
88 MessageCollector diagnosticListener = new MessageCollector(); | 88 MessageCollector diagnosticListener = new MessageCollector(); |
89 Script script = new Script(null, null, null); | 89 Script script = new Script(null, null, null); |
90 LibraryElement lib = new LibraryElementX(script); | 90 LibraryElement lib = new LibraryElementX(script); |
91 CompilationUnitElement element = new CompilationUnitElementX(script, lib); | 91 CompilationUnitElement element = new CompilationUnitElementX(script, lib); |
92 StringScanner scanner = new StringScanner.fromString(source); | 92 StringScanner scanner = new StringScanner.fromString(source); |
93 Token beginToken = scanner.tokenize(); | 93 Token beginToken = scanner.tokenize(); |
94 NodeListener listener = | 94 NodeListener listener = |
95 new NodeListener(const ScannerOptions(), diagnosticListener, element); | 95 new NodeListener(const ScannerOptions(), diagnosticListener, element); |
96 Parser parser = new Parser(listener, new MockParserOptions()); | 96 Parser parser = new Parser(listener); |
97 parser.parseUnit(beginToken); | 97 parser.parseUnit(beginToken); |
98 Node node = listener.popNode(); | 98 Node node = listener.popNode(); |
99 Expect.isTrue(listener.nodes.isEmpty); | 99 Expect.isTrue(listener.nodes.isEmpty); |
100 return unparse(node); | 100 return unparse(node); |
101 } | 101 } |
102 | 102 |
103 class MessageCollector extends DiagnosticReporter { | 103 class MessageCollector extends DiagnosticReporter { |
104 List<String> messages; | 104 List<String> messages; |
105 MessageCollector() { | 105 MessageCollector() { |
106 messages = []; | 106 messages = []; |
107 } | 107 } |
108 void internalError(node, String reason) { | 108 void internalError(node, String reason) { |
109 messages.add(reason); | 109 messages.add(reason); |
110 throw reason; | 110 throw reason; |
111 } | 111 } |
112 | 112 |
113 void log(message) { | 113 void log(message) { |
114 messages.add(message); | 114 messages.add(message); |
115 } | 115 } |
116 | 116 |
117 noSuchMethod(Invocation invocation) => throw 'unsupported operation'; | 117 noSuchMethod(Invocation invocation) => throw 'unsupported operation'; |
118 } | 118 } |
OLD | NEW |