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

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

Issue 11783089: Fix VariableDefinitions.endToken for formal parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Handle for-in. Created 7 years, 10 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: sdk/lib/_internal/compiler/implementation/scanner/parser.dart
diff --git a/sdk/lib/_internal/compiler/implementation/scanner/parser.dart b/sdk/lib/_internal/compiler/implementation/scanner/parser.dart
index ef0f4174df60b630e8d2e16f7d3970609700f8ed..b142d4d0cd6c95916534a3ff2354f75f722edd19 100644
--- a/sdk/lib/_internal/compiler/implementation/scanner/parser.dart
+++ b/sdk/lib/_internal/compiler/implementation/scanner/parser.dart
@@ -363,7 +363,7 @@ class Parser {
token = parseExpression(token.next);
listener.handleValuedFormalParameter(equal, token);
}
- listener.endFormalParameter(token, thisKeyword);
+ listener.endFormalParameter(thisKeyword);
return token;
}
@@ -554,10 +554,25 @@ class Parser {
/**
* Returns true if the stringValue of the [token] is [value].
*/
- bool optional(String value, Token token) => identical(value, token.stringValue);
+ bool optional(String value, Token token) =>
+ identical(value, token.stringValue);
ahe 2013/02/04 13:38:26 Since it doesn't fit on one line, I'd prefer using
Johnni Winther 2013/02/05 09:03:09 Done.
+
+ /**
+ * Returns true if the stringValue of the [token] is either [value1],
+ * [value2], [value3], or [value4].
+ */
+ bool isOneOf4(Token token,
+ String value1, String value2, String value3, String value4) {
+ String stringValue = token.stringValue;
+ return identical(value1, stringValue) ||
+ identical(value2, stringValue) ||
+ identical(value3, stringValue) ||
+ identical(value4, stringValue);
+ }
bool notEofOrValue(String value, Token token) {
- return !identical(token.kind, EOF_TOKEN) && !identical(value, token.stringValue);
+ return !identical(token.kind, EOF_TOKEN) &&
+ !identical(value, token.stringValue);
}
Token parseType(Token token) {
@@ -1868,11 +1883,15 @@ class Parser {
}
Token parseVariablesDeclaration(Token token) {
- token = parseVariablesDeclarationNoSemicolon(token);
- return expectSemicolon(token);
+ return parseVariablesDeclarationMaybeSemicolon(token, true);
}
Token parseVariablesDeclarationNoSemicolon(Token token) {
+ return parseVariablesDeclarationMaybeSemicolon(token, false);
+ }
+
+ Token parseVariablesDeclarationMaybeSemicolon(Token token,
+ bool endWithSemicolon) {
int count = 1;
listener.beginVariablesDeclaration(token);
token = parseModifiers(token);
@@ -1882,8 +1901,14 @@ class Parser {
token = parseOptionallyInitializedIdentifier(token.next);
++count;
}
- listener.endVariablesDeclaration(count, token);
- return token;
+ if (endWithSemicolon) {
+ expectSemicolon(token);
ahe 2013/02/04 13:38:26 I have a prototype that recovers on missing semico
Johnni Winther 2013/02/05 09:03:09 Done.
+ listener.endVariablesDeclaration(count, token);
+ return token.next;
+ } else {
+ listener.endVariablesDeclaration(count, null);
+ return token;
+ }
}
Token parseOptionallyInitializedIdentifier(Token token) {
@@ -1933,10 +1958,7 @@ class Parser {
Token identifier = peekIdentifierAfterType(token);
if (identifier != null) {
assert(identifier.isIdentifier());
- Token afterId = identifier.next;
- int afterIdKind = afterId.kind;
- if (identical(afterIdKind, EQ_TOKEN) || identical(afterIdKind, SEMICOLON_TOKEN) ||
- identical(afterIdKind, COMMA_TOKEN) || optional('in', afterId)) {
+ if (isOneOf4(identifier.next, '=', ';', ',', 'in')) {
return parseVariablesDeclarationNoSemicolon(token);
}
}

Powered by Google App Engine
This is Rietveld 408576698