| OLD | NEW |
| 1 // Copyright (c) 2016, 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/id_generator.dart'; | 10 import 'package:compiler/src/id_generator.dart'; |
| 11 import "package:compiler/src/tree/tree.dart"; | 11 import 'package:compiler/src/tree/tree.dart'; |
| 12 import "package:compiler/src/parser/element_listener.dart"; | 12 import 'package:compiler/src/parser/element_listener.dart'; |
| 13 import "package:compiler/src/parser/node_listener.dart"; | 13 import 'package:compiler/src/parser/node_listener.dart'; |
| 14 import "package:compiler/src/parser/parser.dart"; | 14 import 'package:compiler/src/parser/partial_elements.dart'; |
| 15 import "package:compiler/src/parser/partial_parser.dart"; | 15 import 'package:dart_parser/dart_parser.dart' hide parse; |
| 16 import "package:compiler/src/scanner/string_scanner.dart"; | 16 import 'package:dart_scanner/dart_scanner.dart' hide scan; |
| 17 import "package:compiler/src/tokens/token.dart"; | 17 import 'package:compiler/src/io/source_file.dart'; |
| 18 import "package:compiler/src/tokens/token_constants.dart"; | 18 import 'package:compiler/src/util/util.dart'; |
| 19 import "package:compiler/src/io/source_file.dart"; | |
| 20 import "package:compiler/src/util/util.dart"; | |
| 21 | 19 |
| 22 import "package:compiler/src/elements/modelx.dart" | 20 import 'package:compiler/src/elements/modelx.dart' |
| 23 show CompilationUnitElementX, ElementX, LibraryElementX; | 21 show CompilationUnitElementX, ElementX, LibraryElementX; |
| 24 | 22 |
| 25 import "package:compiler/src/compiler.dart"; | 23 import 'package:compiler/src/compiler.dart'; |
| 26 import 'package:compiler/src/options.dart'; | 24 import 'package:compiler/src/options.dart'; |
| 27 import "package:compiler/src/diagnostics/source_span.dart"; | 25 import 'package:compiler/src/diagnostics/source_span.dart'; |
| 28 import "package:compiler/src/diagnostics/spannable.dart"; | 26 import 'package:compiler/src/diagnostics/spannable.dart'; |
| 29 import "package:compiler/src/diagnostics/diagnostic_listener.dart"; | 27 import 'package:compiler/src/diagnostics/diagnostic_listener.dart'; |
| 30 import "package:compiler/src/diagnostics/messages.dart"; | 28 import 'package:compiler/src/diagnostics/messages.dart'; |
| 31 import "package:compiler/src/script.dart"; | 29 import 'package:compiler/src/script.dart'; |
| 32 | 30 |
| 33 import "options_helper.dart"; | 31 import 'options_helper.dart'; |
| 34 | 32 |
| 35 export "package:compiler/src/diagnostics/diagnostic_listener.dart"; | 33 export 'package:dart_parser/dart_parser.dart' hide parse; |
| 36 export 'package:compiler/src/parser/listener.dart'; | 34 export 'package:dart_scanner/dart_scanner.dart' hide scan; |
| 35 export 'package:compiler/src/diagnostics/diagnostic_listener.dart'; |
| 37 export 'package:compiler/src/parser/node_listener.dart'; | 36 export 'package:compiler/src/parser/node_listener.dart'; |
| 38 export 'package:compiler/src/parser/parser.dart'; | |
| 39 export 'package:compiler/src/parser/partial_parser.dart'; | |
| 40 export 'package:compiler/src/parser/partial_elements.dart'; | 37 export 'package:compiler/src/parser/partial_elements.dart'; |
| 41 export "package:compiler/src/tokens/token.dart"; | 38 export 'package:dart_scanner/src/token_constants.dart'; |
| 42 export "package:compiler/src/tokens/token_constants.dart"; | |
| 43 | 39 |
| 44 class LoggerCanceler extends DiagnosticReporter { | 40 class LoggerCanceler extends DiagnosticReporter { |
| 45 DiagnosticOptions get options => const MockDiagnosticOptions(); | 41 DiagnosticOptions get options => const MockDiagnosticOptions(); |
| 46 | 42 |
| 47 void log(message) { | 43 void log(message) { |
| 48 print(message); | 44 print(message); |
| 49 } | 45 } |
| 50 | 46 |
| 51 void internalError(node, String message) { | 47 void internalError(node, String message) { |
| 52 log(message); | 48 log(message); |
| 53 } | 49 } |
| 54 | 50 |
| 55 SourceSpan spanFromSpannable(node) { | 51 SourceSpan spanFromSpannable(node) { |
| 56 throw 'unsupported operation'; | 52 throw 'unsupported operation'; |
| 57 } | 53 } |
| 58 | 54 |
| 55 SourceSpan spanFromToken(token) => null; |
| 56 |
| 59 void reportError(DiagnosticMessage message, | 57 void reportError(DiagnosticMessage message, |
| 60 [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) { | 58 [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) { |
| 61 log(message); | 59 log(message); |
| 62 infos.forEach(log); | 60 infos.forEach(log); |
| 63 } | 61 } |
| 64 | 62 |
| 65 void reportWarning(DiagnosticMessage message, | 63 void reportWarning(DiagnosticMessage message, |
| 66 [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) { | 64 [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) { |
| 67 log(message); | 65 log(message); |
| 68 infos.forEach(log); | 66 infos.forEach(log); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 85 DiagnosticMessage createMessage(Spannable spannable, MessageKind messageKind, | 83 DiagnosticMessage createMessage(Spannable spannable, MessageKind messageKind, |
| 86 [Map arguments = const {}]) { | 84 [Map arguments = const {}]) { |
| 87 return new DiagnosticMessage(null, spannable, | 85 return new DiagnosticMessage(null, spannable, |
| 88 new Message(MessageTemplate.TEMPLATES[messageKind], arguments, false)); | 86 new Message(MessageTemplate.TEMPLATES[messageKind], arguments, false)); |
| 89 } | 87 } |
| 90 | 88 |
| 91 @override | 89 @override |
| 92 bool get hasReportedError => false; | 90 bool get hasReportedError => false; |
| 93 } | 91 } |
| 94 | 92 |
| 95 Token scan(String text) => new StringScanner.fromString(text).tokenize(); | 93 Token scan(String text) => new StringScanner(text).tokenize(); |
| 96 | 94 |
| 97 Node parseBodyCode(String text, Function parseMethod, | 95 Node parseBodyCode(String text, Function parseMethod, |
| 98 {DiagnosticReporter reporter}) { | 96 {DiagnosticReporter reporter}) { |
| 99 Token tokens = scan(text); | 97 Token tokens = scan(text); |
| 100 if (reporter == null) reporter = new LoggerCanceler(); | 98 if (reporter == null) reporter = new LoggerCanceler(); |
| 101 Uri uri = new Uri(scheme: "source"); | 99 Uri uri = new Uri(scheme: "source"); |
| 102 Script script = new Script(uri, uri, new MockFile(text)); | 100 Script script = new Script(uri, uri, new MockFile(text)); |
| 103 LibraryElement library = new LibraryElementX(script); | 101 LibraryElement library = new LibraryElementX(script); |
| 104 NodeListener listener = new NodeListener( | 102 NodeListener listener = new NodeListener( |
| 105 new ScannerOptions(canUseNative: true), | 103 new ScannerOptions(canUseNative: true), |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 new IdGenerator()); | 150 new IdGenerator()); |
| 153 PartialParser parser = new PartialParser(listener); | 151 PartialParser parser = new PartialParser(listener); |
| 154 reporter.withCurrentElement(unit, () => parser.parseUnit(tokens)); | 152 reporter.withCurrentElement(unit, () => parser.parseUnit(tokens)); |
| 155 return unit.localMembers; | 153 return unit.localMembers; |
| 156 } | 154 } |
| 157 | 155 |
| 158 NodeList fullParseUnit(String source, {DiagnosticReporter reporter}) { | 156 NodeList fullParseUnit(String source, {DiagnosticReporter reporter}) { |
| 159 return parseBodyCode(source, (parser, tokens) => parser.parseUnit(tokens), | 157 return parseBodyCode(source, (parser, tokens) => parser.parseUnit(tokens), |
| 160 reporter: reporter); | 158 reporter: reporter); |
| 161 } | 159 } |
| OLD | NEW |