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 part of scanner; | 5 part of scanner; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * An event generating parser of Dart programs. This parser expects | 8 * An event generating parser of Dart programs. This parser expects |
| 9 * all tokens in a linked list (aka a token stream). | 9 * all tokens in a linked list (aka a token stream). |
| 10 * | 10 * |
| (...skipping 1179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1190 } else if (identical(value, '{')) { | 1190 } else if (identical(value, '{')) { |
| 1191 return parseBlock(token); | 1191 return parseBlock(token); |
| 1192 } else if (identical(value, 'return')) { | 1192 } else if (identical(value, 'return')) { |
| 1193 return parseReturnStatement(token); | 1193 return parseReturnStatement(token); |
| 1194 } else if (identical(value, 'var') || identical(value, 'final')) { | 1194 } else if (identical(value, 'var') || identical(value, 'final')) { |
| 1195 return parseVariablesDeclaration(token); | 1195 return parseVariablesDeclaration(token); |
| 1196 } else if (identical(value, 'if')) { | 1196 } else if (identical(value, 'if')) { |
| 1197 return parseIfStatement(token); | 1197 return parseIfStatement(token); |
| 1198 } else if (identical(value, 'for')) { | 1198 } else if (identical(value, 'for')) { |
| 1199 return parseForStatement(token); | 1199 return parseForStatement(token); |
| 1200 } else if (identical(value, 'throw')) { | 1200 } else if (identical(value, 'rethrow')) { |
| 1201 return parseThrowStatement(token); | 1201 return parseRethrowStatement(token); |
| 1202 } else if (identical(value, 'throw') && optional(';', token.next)) { | |
| 1203 // TODO(kasperl): Stop dealing with throw here. | |
| 1204 return parseRethrowStatement(token); | |
|
ahe
2013/04/23 09:37:25
I think this should report a deprecated feature. I
kasperl
2013/04/23 11:26:12
Done in the listener.
| |
| 1202 } else if (identical(value, 'void')) { | 1205 } else if (identical(value, 'void')) { |
| 1203 return parseExpressionStatementOrDeclaration(token); | 1206 return parseExpressionStatementOrDeclaration(token); |
| 1204 } else if (identical(value, 'while')) { | 1207 } else if (identical(value, 'while')) { |
| 1205 return parseWhileStatement(token); | 1208 return parseWhileStatement(token); |
| 1206 } else if (identical(value, 'do')) { | 1209 } else if (identical(value, 'do')) { |
| 1207 return parseDoWhileStatement(token); | 1210 return parseDoWhileStatement(token); |
| 1208 } else if (identical(value, 'try')) { | 1211 } else if (identical(value, 'try')) { |
| 1209 return parseTryStatement(token); | 1212 return parseTryStatement(token); |
| 1210 } else if (identical(value, 'switch')) { | 1213 } else if (identical(value, 'switch')) { |
| 1211 return parseSwitchStatement(token); | 1214 return parseSwitchStatement(token); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1344 } | 1347 } |
| 1345 | 1348 |
| 1346 Token parseExpressionStatement(Token token) { | 1349 Token parseExpressionStatement(Token token) { |
| 1347 listener.beginExpressionStatement(token); | 1350 listener.beginExpressionStatement(token); |
| 1348 token = parseExpression(token); | 1351 token = parseExpression(token); |
| 1349 listener.endExpressionStatement(token); | 1352 listener.endExpressionStatement(token); |
| 1350 return expectSemicolon(token); | 1353 return expectSemicolon(token); |
| 1351 } | 1354 } |
| 1352 | 1355 |
| 1353 Token parseExpression(Token token) { | 1356 Token parseExpression(Token token) { |
| 1354 return parsePrecedenceExpression(token, ASSIGNMENT_PRECEDENCE, true); | 1357 if (optional('throw', token)) { |
| 1358 return parseThrowExpression(token, true); | |
|
ahe
2013/04/23 09:37:25
I don't think this will handle situations like "1
kasperl
2013/04/23 11:26:12
I think that is true, but the grammar in the speci
| |
| 1359 } else { | |
| 1360 return parsePrecedenceExpression(token, ASSIGNMENT_PRECEDENCE, true); | |
| 1361 } | |
| 1355 } | 1362 } |
| 1356 | 1363 |
| 1357 Token parseExpressionWithoutCascade(Token token) { | 1364 Token parseExpressionWithoutCascade(Token token) { |
| 1358 return parsePrecedenceExpression(token, ASSIGNMENT_PRECEDENCE, false); | 1365 if (optional('throw', token)) { |
| 1366 return parseThrowExpression(token, false); | |
| 1367 } else { | |
| 1368 return parsePrecedenceExpression(token, ASSIGNMENT_PRECEDENCE, false); | |
| 1369 } | |
| 1359 } | 1370 } |
| 1360 | 1371 |
| 1361 Token parseConditionalExpressionRest(Token token) { | 1372 Token parseConditionalExpressionRest(Token token) { |
| 1362 assert(optional('?', token)); | 1373 assert(optional('?', token)); |
| 1363 Token question = token; | 1374 Token question = token; |
| 1364 token = parseExpressionWithoutCascade(token.next); | 1375 token = parseExpressionWithoutCascade(token.next); |
| 1365 Token colon = token; | 1376 Token colon = token; |
| 1366 token = expect(':', token); | 1377 token = expect(':', token); |
| 1367 token = parseExpressionWithoutCascade(token); | 1378 token = parseExpressionWithoutCascade(token); |
| 1368 listener.handleConditionalExpression(question, colon); | 1379 listener.handleConditionalExpression(question, colon); |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2028 int statementCount = 0; | 2039 int statementCount = 0; |
| 2029 token = expect('{', token); | 2040 token = expect('{', token); |
| 2030 while (notEofOrValue('}', token)) { | 2041 while (notEofOrValue('}', token)) { |
| 2031 token = parseStatement(token); | 2042 token = parseStatement(token); |
| 2032 ++statementCount; | 2043 ++statementCount; |
| 2033 } | 2044 } |
| 2034 listener.endBlock(statementCount, begin, token); | 2045 listener.endBlock(statementCount, begin, token); |
| 2035 return expect('}', token); | 2046 return expect('}', token); |
| 2036 } | 2047 } |
| 2037 | 2048 |
| 2038 Token parseThrowStatement(Token token) { | 2049 Token parseThrowExpression(Token token, bool allowCascades) { |
| 2039 Token throwToken = token; | 2050 Token throwToken = token; |
| 2040 listener.beginThrowStatement(throwToken); | 2051 listener.beginThrowExpression(throwToken); |
| 2041 token = expect('throw', token); | 2052 token = expect('throw', token); |
| 2042 if (optional(';', token)) { | 2053 token = allowCascades |
| 2043 listener.endRethrowStatement(throwToken, token); | 2054 ? parseExpression(token) |
| 2044 return token.next; | 2055 : parseExpressionWithoutCascade(token); |
| 2056 listener.endThrowExpression(throwToken, token); | |
| 2057 return token; | |
| 2058 } | |
| 2059 | |
| 2060 Token parseRethrowStatement(Token token) { | |
| 2061 Token throwToken = token; | |
| 2062 listener.beginRethrowStatement(throwToken); | |
| 2063 // TODO(kasperl): Disallow throw here. | |
| 2064 if (identical(throwToken.stringValue, 'throw')) { | |
| 2065 token = expect('throw', token); | |
| 2045 } else { | 2066 } else { |
| 2046 token = parseExpression(token); | 2067 token = expect('rethrow', token); |
| 2047 listener.endThrowStatement(throwToken, token); | |
| 2048 return expectSemicolon(token); | |
| 2049 } | 2068 } |
| 2069 listener.endRethrowStatement(throwToken, token); | |
| 2070 return expectSemicolon(token); | |
| 2050 } | 2071 } |
| 2051 | 2072 |
| 2052 Token parseTryStatement(Token token) { | 2073 Token parseTryStatement(Token token) { |
| 2053 assert(optional('try', token)); | 2074 assert(optional('try', token)); |
| 2054 Token tryKeyword = token; | 2075 Token tryKeyword = token; |
| 2055 listener.beginTryStatement(tryKeyword); | 2076 listener.beginTryStatement(tryKeyword); |
| 2056 token = parseBlock(token.next); | 2077 token = parseBlock(token.next); |
| 2057 int catchCount = 0; | 2078 int catchCount = 0; |
| 2058 | 2079 |
| 2059 String value = token.stringValue; | 2080 String value = token.stringValue; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2220 } | 2241 } |
| 2221 listener.handleContinueStatement(hasTarget, continueKeyword, token); | 2242 listener.handleContinueStatement(hasTarget, continueKeyword, token); |
| 2222 return expectSemicolon(token); | 2243 return expectSemicolon(token); |
| 2223 } | 2244 } |
| 2224 | 2245 |
| 2225 Token parseEmptyStatement(Token token) { | 2246 Token parseEmptyStatement(Token token) { |
| 2226 listener.handleEmptyStatement(token); | 2247 listener.handleEmptyStatement(token); |
| 2227 return expectSemicolon(token); | 2248 return expectSemicolon(token); |
| 2228 } | 2249 } |
| 2229 } | 2250 } |
| OLD | NEW |