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 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1133 } else if (identical(value, '{')) { | 1133 } else if (identical(value, '{')) { |
| 1134 return parseBlock(token); | 1134 return parseBlock(token); |
| 1135 } else if (identical(value, 'return')) { | 1135 } else if (identical(value, 'return')) { |
| 1136 return parseReturnStatement(token); | 1136 return parseReturnStatement(token); |
| 1137 } else if (identical(value, 'var') || identical(value, 'final')) { | 1137 } else if (identical(value, 'var') || identical(value, 'final')) { |
| 1138 return parseVariablesDeclaration(token); | 1138 return parseVariablesDeclaration(token); |
| 1139 } else if (identical(value, 'if')) { | 1139 } else if (identical(value, 'if')) { |
| 1140 return parseIfStatement(token); | 1140 return parseIfStatement(token); |
| 1141 } else if (identical(value, 'for')) { | 1141 } else if (identical(value, 'for')) { |
| 1142 return parseForStatement(token); | 1142 return parseForStatement(token); |
| 1143 } else if (identical(value, 'throw')) { | |
| 1144 return parseThrowStatement(token); | |
| 1145 } else if (identical(value, 'void')) { | 1143 } else if (identical(value, 'void')) { |
| 1146 return parseExpressionStatementOrDeclaration(token); | 1144 return parseExpressionStatementOrDeclaration(token); |
| 1147 } else if (identical(value, 'while')) { | 1145 } else if (identical(value, 'while')) { |
| 1148 return parseWhileStatement(token); | 1146 return parseWhileStatement(token); |
| 1149 } else if (identical(value, 'do')) { | 1147 } else if (identical(value, 'do')) { |
| 1150 return parseDoWhileStatement(token); | 1148 return parseDoWhileStatement(token); |
| 1151 } else if (identical(value, 'try')) { | 1149 } else if (identical(value, 'try')) { |
| 1152 return parseTryStatement(token); | 1150 return parseTryStatement(token); |
| 1153 } else if (identical(value, 'switch')) { | 1151 } else if (identical(value, 'switch')) { |
| 1154 return parseSwitchStatement(token); | 1152 return parseSwitchStatement(token); |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1487 } else if (identical(value, 'this')) { | 1485 } else if (identical(value, 'this')) { |
| 1488 return parseThisExpression(token); | 1486 return parseThisExpression(token); |
| 1489 } else if (identical(value, 'super')) { | 1487 } else if (identical(value, 'super')) { |
| 1490 return parseSuperExpression(token); | 1488 return parseSuperExpression(token); |
| 1491 } else if (identical(value, 'new')) { | 1489 } else if (identical(value, 'new')) { |
| 1492 return parseNewExpression(token); | 1490 return parseNewExpression(token); |
| 1493 } else if (identical(value, 'const')) { | 1491 } else if (identical(value, 'const')) { |
| 1494 return parseConstExpression(token); | 1492 return parseConstExpression(token); |
| 1495 } else if (identical(value, 'void')) { | 1493 } else if (identical(value, 'void')) { |
| 1496 return parseFunctionExpression(token); | 1494 return parseFunctionExpression(token); |
| 1495 } else if (identical(value, 'throw')) { | |
| 1496 return parseThrow(token); | |
| 1497 } else if (token.isIdentifier()) { | 1497 } else if (token.isIdentifier()) { |
| 1498 return parseSendOrFunctionLiteral(token); | 1498 return parseSendOrFunctionLiteral(token); |
| 1499 } else { | 1499 } else { |
| 1500 return listener.expectedExpression(token); | 1500 return listener.expectedExpression(token); |
| 1501 } | 1501 } |
| 1502 } else if (identical(kind, OPEN_PAREN_TOKEN)) { | 1502 } else if (identical(kind, OPEN_PAREN_TOKEN)) { |
| 1503 return parseParenthesizedExpressionOrFunctionLiteral(token); | 1503 return parseParenthesizedExpressionOrFunctionLiteral(token); |
| 1504 } else if ((identical(kind, LT_TOKEN)) || | 1504 } else if ((identical(kind, LT_TOKEN)) || |
| 1505 (identical(kind, OPEN_SQUARE_BRACKET_TOKEN)) || | 1505 (identical(kind, OPEN_SQUARE_BRACKET_TOKEN)) || |
| 1506 (identical(kind, OPEN_CURLY_BRACKET_TOKEN)) || | 1506 (identical(kind, OPEN_CURLY_BRACKET_TOKEN)) || |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1886 listener.handleNoExpression(token); | 1886 listener.handleNoExpression(token); |
| 1887 return token; | 1887 return token; |
| 1888 } else if ((identical(value, 'var')) || (identical(value, 'final'))) { | 1888 } else if ((identical(value, 'var')) || (identical(value, 'final'))) { |
| 1889 return parseVariablesDeclarationNoSemicolon(token); | 1889 return parseVariablesDeclarationNoSemicolon(token); |
| 1890 } | 1890 } |
| 1891 Token identifier = peekIdentifierAfterType(token); | 1891 Token identifier = peekIdentifierAfterType(token); |
| 1892 if (identifier != null) { | 1892 if (identifier != null) { |
| 1893 assert(identifier.isIdentifier()); | 1893 assert(identifier.isIdentifier()); |
| 1894 Token afterId = identifier.next; | 1894 Token afterId = identifier.next; |
| 1895 int afterIdKind = afterId.kind; | 1895 int afterIdKind = afterId.kind; |
| 1896 if (identical(afterIdKind, EQ_TOKEN) || identical(afterIdKind, SEMICOLON_T OKEN) || | 1896 if (identical(afterIdKind, EQ_TOKEN) || identical(afterIdKind, SEMICOLON_T OKEN) || |
|
kasperl
2012/12/10 14:50:05
Long line.
| |
| 1897 identical(afterIdKind, COMMA_TOKEN) || optional('in', afterId)) { | 1897 identical(afterIdKind, COMMA_TOKEN) || optional('in', afterId)) { |
| 1898 return parseVariablesDeclarationNoSemicolon(token); | 1898 return parseVariablesDeclarationNoSemicolon(token); |
| 1899 } | 1899 } |
| 1900 } | 1900 } |
| 1901 return parseExpression(token); | 1901 return parseExpression(token); |
| 1902 } | 1902 } |
| 1903 | 1903 |
| 1904 Token parseForRest(Token forToken, Token token) { | 1904 Token parseForRest(Token forToken, Token token) { |
| 1905 token = expectSemicolon(token); | 1905 token = expectSemicolon(token); |
| 1906 if (optional(';', token)) { | 1906 if (optional(';', token)) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1963 int statementCount = 0; | 1963 int statementCount = 0; |
| 1964 token = expect('{', token); | 1964 token = expect('{', token); |
| 1965 while (notEofOrValue('}', token)) { | 1965 while (notEofOrValue('}', token)) { |
| 1966 token = parseStatement(token); | 1966 token = parseStatement(token); |
| 1967 ++statementCount; | 1967 ++statementCount; |
| 1968 } | 1968 } |
| 1969 listener.endBlock(statementCount, begin, token); | 1969 listener.endBlock(statementCount, begin, token); |
| 1970 return expect('}', token); | 1970 return expect('}', token); |
| 1971 } | 1971 } |
| 1972 | 1972 |
| 1973 Token parseThrowStatement(Token token) { | 1973 Token parseThrow(Token token) { |
| 1974 Token throwToken = token; | 1974 Token throwToken = token; |
| 1975 listener.beginThrowStatement(throwToken); | 1975 listener.beginThrow(throwToken); |
| 1976 token = expect('throw', token); | 1976 token = expect('throw', token); |
| 1977 if (optional(';', token)) { | 1977 if (optional(';', token)) { |
| 1978 listener.endRethrowStatement(throwToken, token); | 1978 listener.endRethrow(throwToken, token); |
|
kasperl
2012/12/10 14:50:05
Add a comment that it's important that you aren't
| |
| 1979 return token.next; | |
| 1980 } else { | 1979 } else { |
| 1981 token = parseExpression(token); | 1980 token = parseExpression(token); |
| 1982 listener.endThrowStatement(throwToken, token); | 1981 listener.endThrow(throwToken, token); |
| 1983 return expectSemicolon(token); | |
| 1984 } | 1982 } |
| 1983 return token; | |
| 1985 } | 1984 } |
| 1986 | 1985 |
| 1987 Token parseTryStatement(Token token) { | 1986 Token parseTryStatement(Token token) { |
| 1988 assert(optional('try', token)); | 1987 assert(optional('try', token)); |
| 1989 Token tryKeyword = token; | 1988 Token tryKeyword = token; |
| 1990 listener.beginTryStatement(tryKeyword); | 1989 listener.beginTryStatement(tryKeyword); |
| 1991 token = parseBlock(token.next); | 1990 token = parseBlock(token.next); |
| 1992 int catchCount = 0; | 1991 int catchCount = 0; |
| 1993 | 1992 |
| 1994 String value = token.stringValue; | 1993 String value = token.stringValue; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2155 } | 2154 } |
| 2156 listener.handleContinueStatement(hasTarget, continueKeyword, token); | 2155 listener.handleContinueStatement(hasTarget, continueKeyword, token); |
| 2157 return expectSemicolon(token); | 2156 return expectSemicolon(token); |
| 2158 } | 2157 } |
| 2159 | 2158 |
| 2160 Token parseEmptyStatement(Token token) { | 2159 Token parseEmptyStatement(Token token) { |
| 2161 listener.handleEmptyStatement(token); | 2160 listener.handleEmptyStatement(token); |
| 2162 return expectSemicolon(token); | 2161 return expectSemicolon(token); |
| 2163 } | 2162 } |
| 2164 } | 2163 } |
| OLD | NEW |