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 library dart_parser.parser; | 5 library dart_parser.parser; |
6 | 6 |
7 import 'package:dart_scanner/src/keyword.dart' show | 7 import 'package:dart_scanner/src/keyword.dart' show |
8 Keyword; | 8 Keyword; |
9 | 9 |
10 import 'package:dart_scanner/src/precedence.dart' show | 10 import 'package:dart_scanner/src/precedence.dart' show |
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 !identical(value, token.stringValue); | 845 !identical(value, token.stringValue); |
846 } | 846 } |
847 | 847 |
848 Token parseType(Token token) { | 848 Token parseType(Token token) { |
849 Token begin = token; | 849 Token begin = token; |
850 if (isValidTypeReference(token)) { | 850 if (isValidTypeReference(token)) { |
851 token = parseIdentifier(token); | 851 token = parseIdentifier(token); |
852 token = parseQualifiedRestOpt(token); | 852 token = parseQualifiedRestOpt(token); |
853 } else { | 853 } else { |
854 token = reportUnrecoverableError(token, ErrorKind.ExpectedType); | 854 token = reportUnrecoverableError(token, ErrorKind.ExpectedType); |
| 855 listener.handleInvalidTypeReference(token); |
855 } | 856 } |
856 token = parseTypeArgumentsOpt(token); | 857 token = parseTypeArgumentsOpt(token); |
857 listener.endType(begin, token); | 858 listener.endType(begin, token); |
858 return token; | 859 return token; |
859 } | 860 } |
860 | 861 |
861 Token parseTypeArgumentsOpt(Token token) { | 862 Token parseTypeArgumentsOpt(Token token) { |
862 return parseStuff( | 863 return parseStuff( |
863 token, | 864 token, |
864 (t) => listener.beginTypeArguments(t), | 865 (t) => listener.beginTypeArguments(t), |
(...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1785 expectSemicolon(token); | 1786 expectSemicolon(token); |
1786 listener.endReturnStatement(true, begin, token); | 1787 listener.endReturnStatement(true, begin, token); |
1787 } else { | 1788 } else { |
1788 listener.endReturnStatement(true, begin, null); | 1789 listener.endReturnStatement(true, begin, null); |
1789 } | 1790 } |
1790 return token; | 1791 return token; |
1791 } | 1792 } |
1792 Token begin = token; | 1793 Token begin = token; |
1793 int statementCount = 0; | 1794 int statementCount = 0; |
1794 if (!optional('{', token)) { | 1795 if (!optional('{', token)) { |
1795 return reportUnrecoverableError(token, ErrorKind.ExpectedFunctionBody); | 1796 token = reportUnrecoverableError(token, ErrorKind.ExpectedFunctionBody); |
| 1797 listener.handleInvalidFunctionBody(token); |
| 1798 return token; |
1796 } | 1799 } |
1797 | 1800 |
1798 listener.beginFunctionBody(begin); | 1801 listener.beginFunctionBody(begin); |
1799 token = token.next; | 1802 token = token.next; |
1800 while (notEofOrValue('}', token)) { | 1803 while (notEofOrValue('}', token)) { |
1801 token = parseStatement(token); | 1804 token = parseStatement(token); |
1802 ++statementCount; | 1805 ++statementCount; |
1803 } | 1806 } |
1804 listener.endFunctionBody(statementCount, begin, token); | 1807 listener.endFunctionBody(statementCount, begin, token); |
1805 expect('}', token); | 1808 expect('}', token); |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2359 } else if (value == 'super') { | 2362 } else if (value == 'super') { |
2360 return parseSuperExpression(token); | 2363 return parseSuperExpression(token); |
2361 } else if (value == 'new') { | 2364 } else if (value == 'new') { |
2362 return parseNewExpression(token); | 2365 return parseNewExpression(token); |
2363 } else if (value == 'const') { | 2366 } else if (value == 'const') { |
2364 return parseConstExpression(token); | 2367 return parseConstExpression(token); |
2365 } else if (value == 'void') { | 2368 } else if (value == 'void') { |
2366 return parseFunctionExpression(token); | 2369 return parseFunctionExpression(token); |
2367 } else if (asyncAwaitKeywordsEnabled && | 2370 } else if (asyncAwaitKeywordsEnabled && |
2368 (value == 'yield' || value == 'async')) { | 2371 (value == 'yield' || value == 'async')) { |
2369 return reportUnrecoverableError(token, ErrorKind.ExpectedExpression); | 2372 return expressionExpected(token); |
2370 } else if (token.isIdentifier()) { | 2373 } else if (token.isIdentifier()) { |
2371 return parseSendOrFunctionLiteral(token); | 2374 return parseSendOrFunctionLiteral(token); |
2372 } else { | 2375 } else { |
2373 return reportUnrecoverableError(token, ErrorKind.ExpectedExpression); | 2376 return expressionExpected(token); |
2374 } | 2377 } |
2375 } else if (kind == OPEN_PAREN_TOKEN) { | 2378 } else if (kind == OPEN_PAREN_TOKEN) { |
2376 return parseParenthesizedExpressionOrFunctionLiteral(token); | 2379 return parseParenthesizedExpressionOrFunctionLiteral(token); |
2377 } else if (kind == OPEN_SQUARE_BRACKET_TOKEN || token.stringValue == '[]') { | 2380 } else if (kind == OPEN_SQUARE_BRACKET_TOKEN || token.stringValue == '[]') { |
2378 listener.handleNoTypeArguments(token); | 2381 listener.handleNoTypeArguments(token); |
2379 return parseLiteralListSuffix(token, null); | 2382 return parseLiteralListSuffix(token, null); |
2380 } else if (kind == OPEN_CURLY_BRACKET_TOKEN) { | 2383 } else if (kind == OPEN_CURLY_BRACKET_TOKEN) { |
2381 listener.handleNoTypeArguments(token); | 2384 listener.handleNoTypeArguments(token); |
2382 return parseLiteralMapSuffix(token, null); | 2385 return parseLiteralMapSuffix(token, null); |
2383 } else if (kind == LT_TOKEN) { | 2386 } else if (kind == LT_TOKEN) { |
2384 return parseLiteralListOrMapOrFunction(token, null); | 2387 return parseLiteralListOrMapOrFunction(token, null); |
2385 } else { | 2388 } else { |
2386 return reportUnrecoverableError(token, ErrorKind.ExpectedExpression); | 2389 return expressionExpected(token); |
2387 } | 2390 } |
2388 } | 2391 } |
2389 | 2392 |
| 2393 Token expressionExpected(Token token) { |
| 2394 token = reportUnrecoverableError(token, ErrorKind.ExpectedExpression); |
| 2395 listener.handleInvalidExpression(token); |
| 2396 return token; |
| 2397 } |
| 2398 |
2390 Token parseParenthesizedExpressionOrFunctionLiteral(Token token) { | 2399 Token parseParenthesizedExpressionOrFunctionLiteral(Token token) { |
2391 BeginGroupToken beginGroup = token; | 2400 BeginGroupToken beginGroup = token; |
2392 // TODO(eernst): Check for NPE as described in issue 26252. | 2401 // TODO(eernst): Check for NPE as described in issue 26252. |
2393 Token nextToken = beginGroup.endGroup.next; | 2402 Token nextToken = beginGroup.endGroup.next; |
2394 int kind = nextToken.kind; | 2403 int kind = nextToken.kind; |
2395 if (mayParseFunctionExpressions && | 2404 if (mayParseFunctionExpressions && |
2396 (identical(kind, FUNCTION_TOKEN) || | 2405 (identical(kind, FUNCTION_TOKEN) || |
2397 identical(kind, OPEN_CURLY_BRACKET_TOKEN) || | 2406 identical(kind, OPEN_CURLY_BRACKET_TOKEN) || |
2398 (identical(kind, KEYWORD_TOKEN) && | 2407 (identical(kind, KEYWORD_TOKEN) && |
2399 (nextToken.value == 'async' || nextToken.value == 'sync')))) { | 2408 (nextToken.value == 'async' || nextToken.value == 'sync')))) { |
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3305 r'${': '}', | 3314 r'${': '}', |
3306 }[openBrace]; | 3315 }[openBrace]; |
3307 } | 3316 } |
3308 | 3317 |
3309 Token skipToEof(Token token) { | 3318 Token skipToEof(Token token) { |
3310 while (!identical(token.info, EOF_INFO)) { | 3319 while (!identical(token.info, EOF_INFO)) { |
3311 token = token.next; | 3320 token = token.next; |
3312 } | 3321 } |
3313 return token; | 3322 return token; |
3314 } | 3323 } |
OLD | NEW |