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

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

Issue 10957060: First stab at parsing redirecting constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Parsing correct syntax. Created 8 years, 3 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 | « lib/compiler/implementation/resolver.dart ('k') | lib/compiler/implementation/ssa/builder.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/scanner/parser.dart
diff --git a/lib/compiler/implementation/scanner/parser.dart b/lib/compiler/implementation/scanner/parser.dart
index 9139d10745f64835214eca4db35f5300fa4c38b6..155390b3fe862b653a289a936fcb887364e49645 100644
--- a/lib/compiler/implementation/scanner/parser.dart
+++ b/lib/compiler/implementation/scanner/parser.dart
@@ -916,7 +916,11 @@ class Parser {
token = parseIdentifier(token.next);
}
token = parseFormalParameters(token);
- token = parseFunctionBody(token, false);
+ if (optional('=', token)) {
+ token = parseRedirectingFactoryBody(token);
+ } else {
+ token = parseFunctionBody(token, false);
+ }
listener.endFactoryMethod(start, period, token);
return token.next;
}
@@ -991,6 +995,25 @@ class Parser {
return isBlock ? token.next : token;
}
+ Token parseRedirectingFactoryBody(Token token) {
ahe 2012/09/26 10:42:55 listener.beginFoo
+ // Parses a redirecting factory body "= Some<T>.bar;" into a synthetic
+ // return new Some<T>.bar()
+ // with no arguments and '=' as token for both return and new.
+ assert('=' === token.stringValue);
+ Token equals = token;
+ token = parseType(token.next);
+ bool named = false;
+ if (optional('.', token)) {
+ named = true;
+ token = parseIdentifier(token.next);
+ }
+ expectSemicolon(token);
+ listener.endArguments(0, null, null);
+ listener.handleNewExpression(equals, named);
+ listener.endReturnStatement(true, equals, token);
ahe 2012/09/26 10:42:55 Just one listener.endFoo.
+ return token;
+ }
+
Token parseFunctionBody(Token token, bool isExpression) {
if (optional(';', token)) {
listener.endFunctionBody(0, null, token);
« no previous file with comments | « lib/compiler/implementation/resolver.dart ('k') | lib/compiler/implementation/ssa/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698