| 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); |
| 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 return optional('throw', token) |
| 1358 ? parseThrowExpression(token, true) |
| 1359 : parsePrecedenceExpression(token, ASSIGNMENT_PRECEDENCE, true); |
| 1355 } | 1360 } |
| 1356 | 1361 |
| 1357 Token parseExpressionWithoutCascade(Token token) { | 1362 Token parseExpressionWithoutCascade(Token token) { |
| 1358 return parsePrecedenceExpression(token, ASSIGNMENT_PRECEDENCE, false); | 1363 return optional('throw', token) |
| 1364 ? parseThrowExpression(token, false) |
| 1365 : parsePrecedenceExpression(token, ASSIGNMENT_PRECEDENCE, false); |
| 1359 } | 1366 } |
| 1360 | 1367 |
| 1361 Token parseConditionalExpressionRest(Token token) { | 1368 Token parseConditionalExpressionRest(Token token) { |
| 1362 assert(optional('?', token)); | 1369 assert(optional('?', token)); |
| 1363 Token question = token; | 1370 Token question = token; |
| 1364 token = parseExpressionWithoutCascade(token.next); | 1371 token = parseExpressionWithoutCascade(token.next); |
| 1365 Token colon = token; | 1372 Token colon = token; |
| 1366 token = expect(':', token); | 1373 token = expect(':', token); |
| 1367 token = parseExpressionWithoutCascade(token); | 1374 token = parseExpressionWithoutCascade(token); |
| 1368 listener.handleConditionalExpression(question, colon); | 1375 listener.handleConditionalExpression(question, colon); |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2028 int statementCount = 0; | 2035 int statementCount = 0; |
| 2029 token = expect('{', token); | 2036 token = expect('{', token); |
| 2030 while (notEofOrValue('}', token)) { | 2037 while (notEofOrValue('}', token)) { |
| 2031 token = parseStatement(token); | 2038 token = parseStatement(token); |
| 2032 ++statementCount; | 2039 ++statementCount; |
| 2033 } | 2040 } |
| 2034 listener.endBlock(statementCount, begin, token); | 2041 listener.endBlock(statementCount, begin, token); |
| 2035 return expect('}', token); | 2042 return expect('}', token); |
| 2036 } | 2043 } |
| 2037 | 2044 |
| 2038 Token parseThrowStatement(Token token) { | 2045 Token parseThrowExpression(Token token, bool allowCascades) { |
| 2039 Token throwToken = token; | 2046 Token throwToken = token; |
| 2040 listener.beginThrowStatement(throwToken); | 2047 listener.beginThrowExpression(throwToken); |
| 2041 token = expect('throw', token); | 2048 token = expect('throw', token); |
| 2042 if (optional(';', token)) { | 2049 token = allowCascades |
| 2043 listener.endRethrowStatement(throwToken, token); | 2050 ? parseExpression(token) |
| 2044 return token.next; | 2051 : parseExpressionWithoutCascade(token); |
| 2052 listener.endThrowExpression(throwToken, token); |
| 2053 return token; |
| 2054 } |
| 2055 |
| 2056 Token parseRethrowStatement(Token token) { |
| 2057 Token throwToken = token; |
| 2058 listener.beginRethrowStatement(throwToken); |
| 2059 // TODO(kasperl): Disallow throw here. |
| 2060 if (identical(throwToken.stringValue, 'throw')) { |
| 2061 token = expect('throw', token); |
| 2045 } else { | 2062 } else { |
| 2046 token = parseExpression(token); | 2063 token = expect('rethrow', token); |
| 2047 listener.endThrowStatement(throwToken, token); | |
| 2048 return expectSemicolon(token); | |
| 2049 } | 2064 } |
| 2065 listener.endRethrowStatement(throwToken, token); |
| 2066 return expectSemicolon(token); |
| 2050 } | 2067 } |
| 2051 | 2068 |
| 2052 Token parseTryStatement(Token token) { | 2069 Token parseTryStatement(Token token) { |
| 2053 assert(optional('try', token)); | 2070 assert(optional('try', token)); |
| 2054 Token tryKeyword = token; | 2071 Token tryKeyword = token; |
| 2055 listener.beginTryStatement(tryKeyword); | 2072 listener.beginTryStatement(tryKeyword); |
| 2056 token = parseBlock(token.next); | 2073 token = parseBlock(token.next); |
| 2057 int catchCount = 0; | 2074 int catchCount = 0; |
| 2058 | 2075 |
| 2059 String value = token.stringValue; | 2076 String value = token.stringValue; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2220 } | 2237 } |
| 2221 listener.handleContinueStatement(hasTarget, continueKeyword, token); | 2238 listener.handleContinueStatement(hasTarget, continueKeyword, token); |
| 2222 return expectSemicolon(token); | 2239 return expectSemicolon(token); |
| 2223 } | 2240 } |
| 2224 | 2241 |
| 2225 Token parseEmptyStatement(Token token) { | 2242 Token parseEmptyStatement(Token token) { |
| 2226 listener.handleEmptyStatement(token); | 2243 listener.handleEmptyStatement(token); |
| 2227 return expectSemicolon(token); | 2244 return expectSemicolon(token); |
| 2228 } | 2245 } |
| 2229 } | 2246 } |
| OLD | NEW |