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'; |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 import 'options_helper.dart'; | 31 import 'options_helper.dart'; |
32 | 32 |
33 export 'package:front_end/src/fasta/parser.dart' hide parse; | 33 export 'package:front_end/src/fasta/parser.dart' hide parse; |
34 export 'package:front_end/src/fasta/scanner.dart' hide scan; | 34 export 'package:front_end/src/fasta/scanner.dart' hide scan; |
35 export 'package:compiler/src/diagnostics/diagnostic_listener.dart'; | 35 export 'package:compiler/src/diagnostics/diagnostic_listener.dart'; |
36 export 'package:compiler/src/parser/node_listener.dart'; | 36 export 'package:compiler/src/parser/node_listener.dart'; |
37 export 'package:compiler/src/parser/diet_parser_task.dart'; | 37 export 'package:compiler/src/parser/diet_parser_task.dart'; |
38 export 'package:front_end/src/fasta/scanner/token_constants.dart'; | 38 export 'package:front_end/src/fasta/scanner/token_constants.dart'; |
39 | 39 |
| 40 import 'mock_compiler.dart'; |
| 41 |
40 class LoggerCanceler extends DiagnosticReporter { | 42 class LoggerCanceler extends DiagnosticReporter { |
41 DiagnosticOptions get options => const MockDiagnosticOptions(); | 43 DiagnosticOptions get options => const MockDiagnosticOptions(); |
42 | 44 |
43 void log(message) { | 45 void log(message) { |
44 print(message); | 46 print(message); |
45 } | 47 } |
46 | 48 |
47 void internalError(node, String message) { | 49 void internalError(node, String message) { |
48 log(message); | 50 log(message); |
49 } | 51 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 assert(endToken.kind == EOF_TOKEN); | 110 assert(endToken.kind == EOF_TOKEN); |
109 Node node = listener.popNode(); | 111 Node node = listener.popNode(); |
110 Expect.isNotNull(node); | 112 Expect.isNotNull(node); |
111 Expect.isTrue(listener.nodes.isEmpty, 'Not empty: ${listener.nodes}'); | 113 Expect.isTrue(listener.nodes.isEmpty, 'Not empty: ${listener.nodes}'); |
112 return node; | 114 return node; |
113 } | 115 } |
114 | 116 |
115 Node parseStatement(String text) => | 117 Node parseStatement(String text) => |
116 parseBodyCode(text, (parser, tokens) => parser.parseStatement(tokens)); | 118 parseBodyCode(text, (parser, tokens) => parser.parseStatement(tokens)); |
117 | 119 |
118 Node parseFunction(String text, Compiler compiler) { | 120 Node parseFunction(String text, MockCompiler compiler) { |
119 ElementX element = parseUnit(text, compiler, compiler.mainApp).head; | 121 ElementX element = parseUnit(text, compiler, compiler.mainApp).head; |
120 Expect.isNotNull(element); | 122 Expect.isNotNull(element); |
121 Expect.equals(ElementKind.FUNCTION, element.kind); | 123 Expect.equals(ElementKind.FUNCTION, element.kind); |
122 return element.parseNode(compiler.parsingContext); | 124 return element.parseNode(compiler.parsingContext); |
123 } | 125 } |
124 | 126 |
125 Node parseMember(String text, {DiagnosticReporter reporter}) { | 127 Node parseMember(String text, {DiagnosticReporter reporter}) { |
126 return parseBodyCode(text, (parser, tokens) => parser.parseMember(tokens), | 128 return parseBodyCode(text, (parser, tokens) => parser.parseMember(tokens), |
127 reporter: reporter); | 129 reporter: reporter); |
128 } | 130 } |
(...skipping 21 matching lines...) Expand all Loading... |
150 new IdGenerator()); | 152 new IdGenerator()); |
151 PartialParser parser = new PartialParser(listener); | 153 PartialParser parser = new PartialParser(listener); |
152 reporter.withCurrentElement(unit, () => parser.parseUnit(tokens)); | 154 reporter.withCurrentElement(unit, () => parser.parseUnit(tokens)); |
153 return unit.localMembers; | 155 return unit.localMembers; |
154 } | 156 } |
155 | 157 |
156 NodeList fullParseUnit(String source, {DiagnosticReporter reporter}) { | 158 NodeList fullParseUnit(String source, {DiagnosticReporter reporter}) { |
157 return parseBodyCode(source, (parser, tokens) => parser.parseUnit(tokens), | 159 return parseBodyCode(source, (parser, tokens) => parser.parseUnit(tokens), |
158 reporter: reporter); | 160 reporter: reporter); |
159 } | 161 } |
OLD | NEW |