Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: pkg/fasta/lib/src/kernel/body_builder.dart

Issue 2650813002: Restructure parser error handling and recovery. (Closed)
Patch Set: Address comments. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/dart_parser/lib/src/parser.dart ('k') | pkg/fasta/lib/src/source/diet_parser.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 fasta.body_builder; 5 library fasta.body_builder;
6 6
7 import 'package:dart_parser/src/parser.dart' show 7 import 'package:dart_parser/src/parser.dart' show
8 FormalParameterType, 8 FormalParameterType,
9 optional; 9 optional;
10 10
11 import 'package:dart_parser/src/error_kind.dart' show 11 import 'package:dart_parser/src/error_kind.dart' show
12 ErrorKind; 12 ErrorKind;
13 13
14 import 'package:kernel/ast.dart'; 14 import 'package:kernel/ast.dart';
15 15
16 import 'package:kernel/clone.dart' show 16 import 'package:kernel/clone.dart' show
17 CloneVisitor; 17 CloneVisitor;
18 18
19 import 'package:kernel/transformations/flags.dart' show 19 import 'package:kernel/transformations/flags.dart' show
20 TransformerFlag; 20 TransformerFlag;
21 21
22 import 'package:kernel/class_hierarchy.dart' show 22 import 'package:kernel/class_hierarchy.dart' show
23 ClassHierarchy; 23 ClassHierarchy;
24 24
25 import 'package:kernel/core_types.dart' show 25 import 'package:kernel/core_types.dart' show
26 CoreTypes; 26 CoreTypes;
27 27
28 import 'package:dart_scanner/src/token.dart' show 28 import 'package:dart_scanner/src/token.dart' show
29 BeginGroupToken, 29 BeginGroupToken,
30 ErrorToken,
31 Token, 30 Token,
32 isBinaryOperator, 31 isBinaryOperator,
33 isMinusOperator; 32 isMinusOperator;
34 33
35 import '../errors.dart' show 34 import '../errors.dart' show
36 InputError, 35 InputError,
37 internalError; 36 internalError;
38 37
39 import '../errors.dart' as errors show 38 import '../errors.dart' as errors show
40 inputError; 39 inputError;
(...skipping 2073 matching lines...) Expand 10 before | Expand all | Expand 10 after
2114 } 2113 }
2115 2114
2116 @override 2115 @override
2117 void handleModifiers(int count) { 2116 void handleModifiers(int count) {
2118 debugEvent("Modifiers"); 2117 debugEvent("Modifiers");
2119 // TODO(ahe): Copied from outline_builder.dart. 2118 // TODO(ahe): Copied from outline_builder.dart.
2120 push(popList(count) ?? NullValue.Modifiers); 2119 push(popList(count) ?? NullValue.Modifiers);
2121 } 2120 }
2122 2121
2123 @override 2122 @override
2124 void reportErrorHelper(Token token, ErrorKind kind, Map arguments) { 2123 void handleRecoverableError(Token token, ErrorKind kind, Map arguments) {
2125 super.reportErrorHelper(token, kind, arguments); 2124 super.handleRecoverableError(token, kind, arguments);
2126 if (!hasParserError) { 2125 if (!hasParserError) {
2127 print("$uri:${recoverableErrors.last}"); 2126 print("$uri:${recoverableErrors.last}");
2128 } 2127 }
2129 hasParserError = true; 2128 hasParserError = true;
2130 } 2129 }
2131 2130
2132 @override 2131 @override
2133 Token expectedExpression(Token token) { 2132 Token handleUnrecoverableError(Token token, ErrorKind kind, Map arguments) {
2134 if (token is ErrorToken) { 2133 if (kind == ErrorKind.UnexpectedToken) {
2135 reportErrorToken(token); 2134 String expected = arguments["expected"];
2136 push(new Throw(new StringLiteral("${recoverableErrors.last}"))); 2135 const List<String> trailing = const <String>[")", "}", ";", ","];
2137 do { 2136 if (trailing.contains(token.stringValue) && trailing.contains(expected)) {
2138 token = token.next; 2137 arguments.putIfAbsent("actual", () => token.value);
2139 } while (token is ErrorToken); 2138 handleRecoverableError(token, ErrorKind.ExpectedButGot, arguments);
2140 return token;
2141 } else {
2142 push(new InvalidExpression());
2143 return super.expectedExpression(token);
2144 }
2145 }
2146
2147 @override
2148 Token expected(String string, Token token) {
2149 if (token is ErrorToken) {
2150 reportErrorToken(token);
2151 do {
2152 token = token.next;
2153 } while (token is ErrorToken);
2154 return token;
2155 }
2156 const List<String> trailing = const <String>[")", "}", ";", ","];
2157 if (trailing.contains(token.stringValue) && trailing.contains(string)) {
2158 // We're just trying to get out an error.
2159 if (recoverableErrors.isNotEmpty) {
2160 reportError(token, ErrorKind.Unspecified,
2161 {"text": "Expected: '$string', but got '${token.value}'"});
2162 } 2139 }
2163 return token; 2140 return token;
2164 } 2141 }
2165 return super.expected(string, token); 2142 return super.handleUnrecoverableError(token, kind, arguments);
2166 } 2143 }
2167 2144
2168 void warning(error, [int charOffset = -1]) { 2145 void warning(error, [int charOffset = -1]) {
2169 String message = new InputError(uri, charOffset, error).format(); 2146 String message = new InputError(uri, charOffset, error).format();
2170 print(message); 2147 print(message);
2171 } 2148 }
2172 2149
2173 void nit(error, [int charOffset = -1]) { 2150 void nit(error, [int charOffset = -1]) {
2174 if (!showNits) return; 2151 if (!showNits) return;
2175 String message = new InputError(uri, charOffset, error).format(); 2152 String message = new InputError(uri, charOffset, error).format();
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
2644 } else if (node is TypeDeclarationBuilder) { 2621 } else if (node is TypeDeclarationBuilder) {
2645 return node.name; 2622 return node.name;
2646 } else if (node is PrefixBuilder) { 2623 } else if (node is PrefixBuilder) {
2647 return node.name; 2624 return node.name;
2648 } else if (node is ThisPropertyAccessor) { 2625 } else if (node is ThisPropertyAccessor) {
2649 return node.name.name; 2626 return node.name.name;
2650 } else { 2627 } else {
2651 return internalError("Unhandled: ${node.runtimeType}"); 2628 return internalError("Unhandled: ${node.runtimeType}");
2652 } 2629 }
2653 } 2630 }
OLDNEW
« no previous file with comments | « pkg/dart_parser/lib/src/parser.dart ('k') | pkg/fasta/lib/src/source/diet_parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698