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

Side by Side 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, 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/compiler/implementation/resolver.dart ('k') | lib/compiler/implementation/ssa/builder.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * An event generating parser of Dart programs. This parser expects 6 * An event generating parser of Dart programs. This parser expects
7 * all tokens in a linked list (aka a token stream). 7 * all tokens in a linked list (aka a token stream).
8 * 8 *
9 * The class [Scanner] is used to generate a token stream. See the 9 * The class [Scanner] is used to generate a token stream. See the
10 * file scanner.dart. 10 * file scanner.dart.
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 token = token.next; // Skip 'factory'. 909 token = token.next; // Skip 'factory'.
910 token = parseIdentifier(token); 910 token = parseIdentifier(token);
911 token = parseQualifiedRestOpt(token); 911 token = parseQualifiedRestOpt(token);
912 token = parseTypeVariablesOpt(token); 912 token = parseTypeVariablesOpt(token);
913 Token period = null; 913 Token period = null;
914 if (optional('.', token)) { 914 if (optional('.', token)) {
915 period = token; 915 period = token;
916 token = parseIdentifier(token.next); 916 token = parseIdentifier(token.next);
917 } 917 }
918 token = parseFormalParameters(token); 918 token = parseFormalParameters(token);
919 token = parseFunctionBody(token, false); 919 if (optional('=', token)) {
920 token = parseRedirectingFactoryBody(token);
921 } else {
922 token = parseFunctionBody(token, false);
923 }
920 listener.endFactoryMethod(start, period, token); 924 listener.endFactoryMethod(start, period, token);
921 return token.next; 925 return token.next;
922 } 926 }
923 927
924 Token parseOperatorName(Token token) { 928 Token parseOperatorName(Token token) {
925 assert(optional('operator', token)); 929 assert(optional('operator', token));
926 if (isUserDefinableOperator(token.next.stringValue)) { 930 if (isUserDefinableOperator(token.next.stringValue)) {
927 Token operator = token; 931 Token operator = token;
928 token = token.next; 932 token = token.next;
929 listener.handleOperatorName(operator, token); 933 listener.handleOperatorName(operator, token);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 token = parseIdentifier(token); 988 token = parseIdentifier(token);
985 listener.endFunctionName(token); 989 listener.endFunctionName(token);
986 token = parseFormalParameters(token); 990 token = parseFormalParameters(token);
987 listener.handleNoInitializers(); 991 listener.handleNoInitializers();
988 bool isBlock = optional('{', token); 992 bool isBlock = optional('{', token);
989 token = parseFunctionBody(token, true); 993 token = parseFunctionBody(token, true);
990 listener.endFunction(null, token); 994 listener.endFunction(null, token);
991 return isBlock ? token.next : token; 995 return isBlock ? token.next : token;
992 } 996 }
993 997
998 Token parseRedirectingFactoryBody(Token token) {
ahe 2012/09/26 10:42:55 listener.beginFoo
999 // Parses a redirecting factory body "= Some<T>.bar;" into a synthetic
1000 // return new Some<T>.bar()
1001 // with no arguments and '=' as token for both return and new.
1002 assert('=' === token.stringValue);
1003 Token equals = token;
1004 token = parseType(token.next);
1005 bool named = false;
1006 if (optional('.', token)) {
1007 named = true;
1008 token = parseIdentifier(token.next);
1009 }
1010 expectSemicolon(token);
1011 listener.endArguments(0, null, null);
1012 listener.handleNewExpression(equals, named);
1013 listener.endReturnStatement(true, equals, token);
ahe 2012/09/26 10:42:55 Just one listener.endFoo.
1014 return token;
1015 }
1016
994 Token parseFunctionBody(Token token, bool isExpression) { 1017 Token parseFunctionBody(Token token, bool isExpression) {
995 if (optional(';', token)) { 1018 if (optional(';', token)) {
996 listener.endFunctionBody(0, null, token); 1019 listener.endFunctionBody(0, null, token);
997 return token; 1020 return token;
998 } else if (optional('=>', token)) { 1021 } else if (optional('=>', token)) {
999 Token begin = token; 1022 Token begin = token;
1000 token = parseExpression(token.next); 1023 token = parseExpression(token.next);
1001 if (!isExpression) { 1024 if (!isExpression) {
1002 expectSemicolon(token); 1025 expectSemicolon(token);
1003 listener.endReturnStatement(true, begin, token); 1026 listener.endReturnStatement(true, begin, token);
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after
2047 } 2070 }
2048 listener.handleContinueStatement(hasTarget, continueKeyword, token); 2071 listener.handleContinueStatement(hasTarget, continueKeyword, token);
2049 return expectSemicolon(token); 2072 return expectSemicolon(token);
2050 } 2073 }
2051 2074
2052 Token parseEmptyStatement(Token token) { 2075 Token parseEmptyStatement(Token token) {
2053 listener.handleEmptyStatement(token); 2076 listener.handleEmptyStatement(token);
2054 return expectSemicolon(token); 2077 return expectSemicolon(token);
2055 } 2078 }
2056 } 2079 }
OLDNEW
« 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