| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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"; |
| 11 import "package:compiler/src/parser/element_listener.dart"; | 11 import "package:compiler/src/parser/element_listener.dart"; |
| 12 import "package:compiler/src/parser/node_listener.dart"; | 12 import "package:compiler/src/parser/node_listener.dart"; |
| 13 import "package:compiler/src/parser/parser.dart"; | 13 import "package:compiler/src/parser/parser.dart"; |
| 14 import "package:compiler/src/parser/partial_parser.dart"; | 14 import "package:compiler/src/parser/partial_parser.dart"; |
| 15 import "package:compiler/src/scanner/string_scanner.dart"; | 15 import "package:compiler/src/scanner/string_scanner.dart"; |
| 16 import "package:compiler/src/tokens/token.dart"; | 16 import "package:compiler/src/tokens/token.dart"; |
| 17 import "package:compiler/src/tokens/token_constants.dart"; | 17 import "package:compiler/src/tokens/token_constants.dart"; |
| 18 import "package:compiler/src/io/source_file.dart"; | 18 import "package:compiler/src/io/source_file.dart"; |
| 19 import "package:compiler/src/util/util.dart"; | 19 import "package:compiler/src/util/util.dart"; |
| 20 | 20 |
| 21 import "package:compiler/src/elements/modelx.dart" | 21 import "package:compiler/src/elements/modelx.dart" |
| 22 show CompilationUnitElementX, ElementX, LibraryElementX; | 22 show CompilationUnitElementX, ElementX, LibraryElementX; |
| 23 | 23 |
| 24 import "package:compiler/src/compiler.dart"; | 24 import "package:compiler/src/compiler.dart"; |
| 25 import 'package:compiler/src/options.dart'; |
| 25 import "package:compiler/src/diagnostics/source_span.dart"; | 26 import "package:compiler/src/diagnostics/source_span.dart"; |
| 26 import "package:compiler/src/diagnostics/spannable.dart"; | 27 import "package:compiler/src/diagnostics/spannable.dart"; |
| 27 import "package:compiler/src/diagnostics/diagnostic_listener.dart"; | 28 import "package:compiler/src/diagnostics/diagnostic_listener.dart"; |
| 28 import "package:compiler/src/diagnostics/messages.dart"; | 29 import "package:compiler/src/diagnostics/messages.dart"; |
| 29 import "package:compiler/src/script.dart"; | 30 import "package:compiler/src/script.dart"; |
| 30 | 31 |
| 32 import "options_helper.dart"; |
| 33 |
| 31 export "package:compiler/src/diagnostics/diagnostic_listener.dart"; | 34 export "package:compiler/src/diagnostics/diagnostic_listener.dart"; |
| 32 export 'package:compiler/src/parser/listener.dart'; | 35 export 'package:compiler/src/parser/listener.dart'; |
| 33 export 'package:compiler/src/parser/node_listener.dart'; | 36 export 'package:compiler/src/parser/node_listener.dart'; |
| 34 export 'package:compiler/src/parser/parser.dart'; | 37 export 'package:compiler/src/parser/parser.dart'; |
| 35 export 'package:compiler/src/parser/partial_parser.dart'; | 38 export 'package:compiler/src/parser/partial_parser.dart'; |
| 36 export 'package:compiler/src/parser/partial_elements.dart'; | 39 export 'package:compiler/src/parser/partial_elements.dart'; |
| 37 export "package:compiler/src/tokens/token.dart"; | 40 export "package:compiler/src/tokens/token.dart"; |
| 38 export "package:compiler/src/tokens/token_constants.dart"; | 41 export "package:compiler/src/tokens/token_constants.dart"; |
| 39 | 42 |
| 40 class LoggerCanceler extends DiagnosticReporter { | 43 class LoggerCanceler extends DiagnosticReporter { |
| 44 DiagnosticOptions get options => const MockDiagnosticOptions(); |
| 45 |
| 41 void log(message) { | 46 void log(message) { |
| 42 print(message); | 47 print(message); |
| 43 } | 48 } |
| 44 | 49 |
| 45 void internalError(node, String message) { | 50 void internalError(node, String message) { |
| 46 log(message); | 51 log(message); |
| 47 } | 52 } |
| 48 | 53 |
| 49 SourceSpan spanFromSpannable(node) { | 54 SourceSpan spanFromSpannable(node) { |
| 50 throw 'unsupported operation'; | 55 throw 'unsupported operation'; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 Node parseBodyCode(String text, Function parseMethod, | 100 Node parseBodyCode(String text, Function parseMethod, |
| 96 {DiagnosticReporter reporter}) { | 101 {DiagnosticReporter reporter}) { |
| 97 Token tokens = scan(text); | 102 Token tokens = scan(text); |
| 98 if (reporter == null) reporter = new LoggerCanceler(); | 103 if (reporter == null) reporter = new LoggerCanceler(); |
| 99 Uri uri = new Uri(scheme: "source"); | 104 Uri uri = new Uri(scheme: "source"); |
| 100 Script script = new Script(uri, uri,new MockFile(text)); | 105 Script script = new Script(uri, uri,new MockFile(text)); |
| 101 LibraryElement library = new LibraryElementX(script); | 106 LibraryElement library = new LibraryElementX(script); |
| 102 NodeListener listener = new NodeListener( | 107 NodeListener listener = new NodeListener( |
| 103 new ScannerOptions(canUseNative: true), | 108 new ScannerOptions(canUseNative: true), |
| 104 reporter, library.entryCompilationUnit); | 109 reporter, library.entryCompilationUnit); |
| 105 Parser parser = new Parser(listener, enableConditionalDirectives: true); | 110 Parser parser = new Parser(listener, new MockParserOptions()); |
| 106 Token endToken = parseMethod(parser, tokens); | 111 Token endToken = parseMethod(parser, tokens); |
| 107 assert(endToken.kind == EOF_TOKEN); | 112 assert(endToken.kind == EOF_TOKEN); |
| 108 Node node = listener.popNode(); | 113 Node node = listener.popNode(); |
| 109 Expect.isNotNull(node); | 114 Expect.isNotNull(node); |
| 110 Expect.isTrue(listener.nodes.isEmpty, 'Not empty: ${listener.nodes}'); | 115 Expect.isTrue(listener.nodes.isEmpty, 'Not empty: ${listener.nodes}'); |
| 111 return node; | 116 return node; |
| 112 } | 117 } |
| 113 | 118 |
| 114 Node parseStatement(String text) => | 119 Node parseStatement(String text) => |
| 115 parseBodyCode(text, (parser, tokens) => parser.parseStatement(tokens)); | 120 parseBodyCode(text, (parser, tokens) => parser.parseStatement(tokens)); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 143 if (registerSource != null) { | 148 if (registerSource != null) { |
| 144 registerSource(uri, text); | 149 registerSource(uri, text); |
| 145 } | 150 } |
| 146 var script = new Script(uri, uri, new MockFile(text)); | 151 var script = new Script(uri, uri, new MockFile(text)); |
| 147 var unit = new CompilationUnitElementX(script, library); | 152 var unit = new CompilationUnitElementX(script, library); |
| 148 int id = 0; | 153 int id = 0; |
| 149 DiagnosticReporter reporter = compiler.reporter; | 154 DiagnosticReporter reporter = compiler.reporter; |
| 150 ElementListener listener = new ElementListener( | 155 ElementListener listener = new ElementListener( |
| 151 compiler.parsing.getScannerOptionsFor(library), | 156 compiler.parsing.getScannerOptionsFor(library), |
| 152 reporter, unit, () => id++); | 157 reporter, unit, () => id++); |
| 153 PartialParser parser = new PartialParser(listener); | 158 PartialParser parser = new PartialParser(listener, new MockParserOptions()); |
| 154 reporter.withCurrentElement(unit, () => parser.parseUnit(tokens)); | 159 reporter.withCurrentElement(unit, () => parser.parseUnit(tokens)); |
| 155 return unit.localMembers; | 160 return unit.localMembers; |
| 156 } | 161 } |
| 157 | 162 |
| 158 NodeList fullParseUnit(String source, {DiagnosticReporter reporter}) { | 163 NodeList fullParseUnit(String source, {DiagnosticReporter reporter}) { |
| 159 return parseBodyCode( | 164 return parseBodyCode( |
| 160 source, | 165 source, |
| 161 (parser, tokens) => parser.parseUnit(tokens), | 166 (parser, tokens) => parser.parseUnit(tokens), |
| 162 reporter: reporter); | 167 reporter: reporter); |
| 163 } | 168 } |
| OLD | NEW |