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

Unified Diff: dart/sdk/lib/_internal/compiler/implementation/scanner/listener.dart

Issue 251523002: Improve error-recovery from unmatched braces. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Updated parser_test.dart Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: dart/sdk/lib/_internal/compiler/implementation/scanner/listener.dart
diff --git a/dart/sdk/lib/_internal/compiler/implementation/scanner/listener.dart b/dart/sdk/lib/_internal/compiler/implementation/scanner/listener.dart
index 762bd81ac40c6f2a712f606f9469ea1d291a5eac..5bb67901b6da46bac291dbdff3f55c5a84b59ad5 100644
--- a/dart/sdk/lib/_internal/compiler/implementation/scanner/listener.dart
+++ b/dart/sdk/lib/_internal/compiler/implementation/scanner/listener.dart
@@ -719,12 +719,27 @@ class Listener {
break;
}
reportError(token, kind, arguments);
+ } else if (token is UnmatchedToken) {
+ String begin = token.begin.value;
+ String end = closeBraceFor(begin);
+ reportError(
+ token, MessageKind.UNMATCHED_TOKEN, {'begin': begin, 'end': end});
} else {
throw new SpannableAssertionFailure(token, token.assertionMessage);
}
}
}
+String closeBraceFor(String openBrace) {
+ return const {
+ '(': ')',
+ '[': ']',
+ '{': '}',
+ '<': '>',
+ r'${': '}',
+ }[openBrace];
+}
+
class ParserError {
final String reason;
ParserError(this.reason);
@@ -1160,10 +1175,16 @@ class ElementListener extends Listener {
if (token is ErrorToken) {
reportErrorToken(token);
} else {
- reportFatalError(token,
- "Unmatched '${token.value}'.");
+ String begin = token.value;
+ String end = closeBraceFor(begin);
+ reportError(
+ token, MessageKind.UNMATCHED_TOKEN, {'begin': begin, 'end': end});
}
- return skipToEof(token);
+ Token next = token.next;
+ while (next is ErrorToken) {
+ next = next.next;
+ }
+ return next;
}
void recoverableError(Spannable node, String message) {

Powered by Google App Engine
This is Rietveld 408576698