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

Unified Diff: dart/frog/leg/scanner/parser.dart

Issue 9112008: Improve error recovery in parser. (Closed) Base URL: ssh://aaricia.aar/home/ahe/Dart/all/dart.googlecode.com.git@master
Patch Set: Update language-leg.status Created 8 years, 12 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
« no previous file with comments | « dart/frog/leg/scanner/listener.dart ('k') | dart/frog/leg/tools/find_file_to_parse.sh » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/frog/leg/scanner/parser.dart
diff --git a/dart/frog/leg/scanner/parser.dart b/dart/frog/leg/scanner/parser.dart
index 759988e26e29c6a6a2d78b39e44dfe88804fdfaf..009867fe19cdc7707f46e0e749d90c94f76c93a0 100644
--- a/dart/frog/leg/scanner/parser.dart
+++ b/dart/frog/leg/scanner/parser.dart
@@ -277,6 +277,10 @@ class Parser {
bool optional(String value, Token token) => value === token.stringValue;
+ bool notEofOrValue(String value, Token token) {
+ return token.kind !== EOF_TOKEN && value !== token.stringValue;
+ }
+
Token parseType(Token token) {
// TODO(ahe): Rename this method to parseTypeOrVar?
Token begin = token;
@@ -362,6 +366,12 @@ class Parser {
break;
} else {
token = listener.unexpected(token);
+ if (token.kind === EOF_TOKEN) {
+ // TODO(ahe): This is a hack. It would be better to tell the
+ // listener more explicitly that it must pop an identifier.
+ listener.endTopLevelFields(0, start, token);
+ return token;
+ }
}
}
if (isField) {
@@ -501,7 +511,7 @@ class Parser {
}
token = token.next;
int count = 0;
- while (!optional('}', token)) {
+ while (notEofOrValue('}', token)) {
token = parseMember(token);
++count;
}
@@ -684,7 +694,7 @@ class Parser {
int statementCount = 0;
listener.beginFunctionBody(begin);
token = expect('{', token);
- while (!optional('}', token)) {
+ while (notEofOrValue('}', token)) {
token = parseStatement(token);
++statementCount;
}
@@ -1358,7 +1368,7 @@ class Parser {
listener.beginBlock(begin);
int statementCount = 0;
token = expect('{', token);
- while (!optional('}', token)) {
+ while (notEofOrValue('}', token)) {
token = parseStatement(token);
++statementCount;
}
« no previous file with comments | « dart/frog/leg/scanner/listener.dart ('k') | dart/frog/leg/tools/find_file_to_parse.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698