Chromium Code Reviews| 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); |