Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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) { | |
| 999 listener.beginRedirectingFactoryBody(token); | |
| 1000 assert('=' === token.stringValue); | |
|
ahe
2012/10/05 08:23:20
assert(optional('=', token));
I should clean up t
Lasse Reichstein Nielsen
2012/10/09 09:46:54
Done.
| |
| 1001 Token equals = token; | |
| 1002 token = parseType(token.next); | |
| 1003 Token dot = null; | |
| 1004 if (optional('.', token)) { | |
| 1005 dot = token; | |
| 1006 token = parseIdentifier(token.next); | |
| 1007 } | |
| 1008 expectSemicolon(token); | |
| 1009 listener.endRedirectingFactoryBody(equals, dot, token); | |
| 1010 return token; | |
|
ahe
2012/10/05 08:23:20
You should consume the semicolon token if you requ
Lasse Reichstein Nielsen
2012/10/09 09:46:54
I don't think that's compatible with parseFunction
| |
| 1011 } | |
| 1012 | |
| 994 Token parseFunctionBody(Token token, bool isExpression) { | 1013 Token parseFunctionBody(Token token, bool isExpression) { |
| 995 if (optional(';', token)) { | 1014 if (optional(';', token)) { |
| 996 listener.endFunctionBody(0, null, token); | 1015 listener.endFunctionBody(0, null, token); |
| 997 return token; | 1016 return token; |
| 998 } else if (optional('=>', token)) { | 1017 } else if (optional('=>', token)) { |
| 999 Token begin = token; | 1018 Token begin = token; |
| 1000 token = parseExpression(token.next); | 1019 token = parseExpression(token.next); |
| 1001 if (!isExpression) { | 1020 if (!isExpression) { |
| 1002 expectSemicolon(token); | 1021 expectSemicolon(token); |
| 1003 listener.endReturnStatement(true, begin, token); | 1022 listener.endReturnStatement(true, begin, token); |
| (...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2045 } | 2064 } |
| 2046 listener.handleContinueStatement(hasTarget, continueKeyword, token); | 2065 listener.handleContinueStatement(hasTarget, continueKeyword, token); |
| 2047 return expectSemicolon(token); | 2066 return expectSemicolon(token); |
| 2048 } | 2067 } |
| 2049 | 2068 |
| 2050 Token parseEmptyStatement(Token token) { | 2069 Token parseEmptyStatement(Token token) { |
| 2051 listener.handleEmptyStatement(token); | 2070 listener.handleEmptyStatement(token); |
| 2052 return expectSemicolon(token); | 2071 return expectSemicolon(token); |
| 2053 } | 2072 } |
| 2054 } | 2073 } |
| OLD | NEW |