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 library parser_helper; | 5 library parser_helper; |
6 | 6 |
7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
8 | 8 |
9 import "package:compiler/src/elements/elements.dart"; | 9 import "package:compiler/src/elements/elements.dart"; |
10 import "package:compiler/src/tree/tree.dart"; | 10 import "package:compiler/src/tree/tree.dart"; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 Node parseBodyCode(String text, Function parseMethod, | 95 Node parseBodyCode(String text, Function parseMethod, |
96 {DiagnosticReporter reporter}) { | 96 {DiagnosticReporter reporter}) { |
97 Token tokens = scan(text); | 97 Token tokens = scan(text); |
98 if (reporter == null) reporter = new LoggerCanceler(); | 98 if (reporter == null) reporter = new LoggerCanceler(); |
99 Uri uri = new Uri(scheme: "source"); | 99 Uri uri = new Uri(scheme: "source"); |
100 Script script = new Script(uri, uri,new MockFile(text)); | 100 Script script = new Script(uri, uri,new MockFile(text)); |
101 LibraryElement library = new LibraryElementX(script); | 101 LibraryElement library = new LibraryElementX(script); |
102 NodeListener listener = new NodeListener( | 102 NodeListener listener = new NodeListener( |
103 new ScannerOptions(canUseNative: true), | 103 new ScannerOptions(canUseNative: true), |
104 reporter, library.entryCompilationUnit); | 104 reporter, library.entryCompilationUnit); |
105 Parser parser = new Parser(listener); | 105 Parser parser = new Parser(listener, enableConditionalDirectives: true); |
106 Token endToken = parseMethod(parser, tokens); | 106 Token endToken = parseMethod(parser, tokens); |
107 assert(endToken.kind == EOF_TOKEN); | 107 assert(endToken.kind == EOF_TOKEN); |
108 Node node = listener.popNode(); | 108 Node node = listener.popNode(); |
109 Expect.isNotNull(node); | 109 Expect.isNotNull(node); |
110 Expect.isTrue(listener.nodes.isEmpty, 'Not empty: ${listener.nodes}'); | 110 Expect.isTrue(listener.nodes.isEmpty, 'Not empty: ${listener.nodes}'); |
111 return node; | 111 return node; |
112 } | 112 } |
113 | 113 |
114 Node parseStatement(String text) => | 114 Node parseStatement(String text) => |
115 parseBodyCode(text, (parser, tokens) => parser.parseStatement(tokens)); | 115 parseBodyCode(text, (parser, tokens) => parser.parseStatement(tokens)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 reporter.withCurrentElement(unit, () => parser.parseUnit(tokens)); | 154 reporter.withCurrentElement(unit, () => parser.parseUnit(tokens)); |
155 return unit.localMembers; | 155 return unit.localMembers; |
156 } | 156 } |
157 | 157 |
158 NodeList fullParseUnit(String source, {DiagnosticReporter reporter}) { | 158 NodeList fullParseUnit(String source, {DiagnosticReporter reporter}) { |
159 return parseBodyCode( | 159 return parseBodyCode( |
160 source, | 160 source, |
161 (parser, tokens) => parser.parseUnit(tokens), | 161 (parser, tokens) => parser.parseUnit(tokens), |
162 reporter: reporter); | 162 reporter: reporter); |
163 } | 163 } |
OLD | NEW |