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 fasta.parser.parser; | 5 library fasta.parser.parser; |
6 | 6 |
7 import '../scanner.dart' show ErrorToken; | 7 import '../scanner.dart' show ErrorToken; |
8 | 8 |
9 import '../scanner/recover.dart' show closeBraceFor, skipToEof; | 9 import '../scanner/recover.dart' show closeBraceFor, skipToEof; |
10 | 10 |
(...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1346 /// get foo async* { return null } | 1346 /// get foo async* { return null } |
1347 /// results in | 1347 /// results in |
1348 /// ['{', 'foo', 'get'] | 1348 /// ['{', 'foo', 'get'] |
1349 /// | 1349 /// |
1350 /// | 1350 /// |
1351 /// operator *(arg) => null; | 1351 /// operator *(arg) => null; |
1352 /// results in | 1352 /// results in |
1353 /// ['(', '*', 'operator'] | 1353 /// ['(', '*', 'operator'] |
1354 /// | 1354 /// |
1355 Link<Token> findMemberName(Token token) { | 1355 Link<Token> findMemberName(Token token) { |
| 1356 // TODO(ahe): This method is rather broken for examples like this: |
| 1357 // |
| 1358 // get<T>(){} |
| 1359 // |
| 1360 // In addition, the loop below will include things that can't be |
| 1361 // identifiers. This may be desirable (for error recovery), or |
| 1362 // not. Regardless, this method probably needs an overhaul. |
1356 Link<Token> identifiers = const Link<Token>(); | 1363 Link<Token> identifiers = const Link<Token>(); |
1357 | 1364 |
1358 // `true` if 'get' has been seen. | 1365 // `true` if 'get' has been seen. |
1359 bool isGetter = false; | 1366 bool isGetter = false; |
1360 // `true` if an identifier has been seen after 'get'. | 1367 // `true` if an identifier has been seen after 'get'. |
1361 bool hasName = false; | 1368 bool hasName = false; |
1362 | 1369 |
1363 while (token.kind != EOF_TOKEN) { | 1370 while (token.kind != EOF_TOKEN) { |
1364 if (optional('get', token)) { | 1371 if (optional('get', token)) { |
1365 isGetter = true; | 1372 isGetter = true; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 reportUnrecoverableError(token, ErrorKind.UnexpectedToken); | 1542 reportUnrecoverableError(token, ErrorKind.UnexpectedToken); |
1536 // Skip the remaining modifiers. | 1543 // Skip the remaining modifiers. |
1537 break; | 1544 break; |
1538 } | 1545 } |
1539 count++; | 1546 count++; |
1540 } | 1547 } |
1541 listener.handleModifiers(count); | 1548 listener.handleModifiers(count); |
1542 } | 1549 } |
1543 | 1550 |
1544 Token parseModifiers(Token token) { | 1551 Token parseModifiers(Token token) { |
| 1552 // TODO(ahe): The calling convention of this method probably needs to |
| 1553 // change. For example, this is parsed as a local variable declaration: |
| 1554 // `abstract foo;`. Ideally, this example should be handled as a local |
| 1555 // variable having the type `abstract` (which should be reported as |
| 1556 // `ErrorKind.BuiltInIdentifierAsType` by [parseIdentifier]). |
1545 int count = 0; | 1557 int count = 0; |
1546 while (identical(token.kind, KEYWORD_TOKEN)) { | 1558 while (identical(token.kind, KEYWORD_TOKEN)) { |
1547 if (!isModifier(token)) break; | 1559 if (!isModifier(token)) break; |
1548 token = parseModifier(token); | 1560 token = parseModifier(token); |
1549 count++; | 1561 count++; |
1550 } | 1562 } |
1551 listener.handleModifiers(count); | 1563 listener.handleModifiers(count); |
1552 return token; | 1564 return token; |
1553 } | 1565 } |
1554 | 1566 |
(...skipping 2069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3624 break; | 3636 break; |
3625 } | 3637 } |
3626 if (isRecoverable) { | 3638 if (isRecoverable) { |
3627 listener.handleRecoverableError(token, kind, arguments); | 3639 listener.handleRecoverableError(token, kind, arguments); |
3628 return null; | 3640 return null; |
3629 } else { | 3641 } else { |
3630 return listener.handleUnrecoverableError(token, kind, arguments); | 3642 return listener.handleUnrecoverableError(token, kind, arguments); |
3631 } | 3643 } |
3632 } | 3644 } |
3633 } | 3645 } |
OLD | NEW |