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 | 7 import '../scanner.dart' show |
8 ErrorToken; | 8 ErrorToken; |
9 | 9 |
10 import '../scanner/recover.dart' show | 10 import '../scanner/recover.dart' show |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 492 |
493 Token parseFormalParameter(Token token, FormalParameterType kind, | 493 Token parseFormalParameter(Token token, FormalParameterType kind, |
494 {bool inFunctionType: false}) { | 494 {bool inFunctionType: false}) { |
495 token = parseMetadataStar(token, forParameter: true); | 495 token = parseMetadataStar(token, forParameter: true); |
496 listener.beginFormalParameter(token); | 496 listener.beginFormalParameter(token); |
497 | 497 |
498 // Skip over `covariant` token, if the next token is an identifier or | 498 // Skip over `covariant` token, if the next token is an identifier or |
499 // modifier. | 499 // modifier. |
500 // This enables the case where `covariant` is the name of the parameter: | 500 // This enables the case where `covariant` is the name of the parameter: |
501 // void foo(covariant); | 501 // void foo(covariant); |
| 502 Token covariantKeyword; |
502 if (identical(token.stringValue, 'covariant') && | 503 if (identical(token.stringValue, 'covariant') && |
503 (token.next.isIdentifier() || isModifier(token.next))) { | 504 (token.next.isIdentifier() || isModifier(token.next))) { |
| 505 covariantKeyword = token; |
504 token = token.next; | 506 token = token.next; |
505 } | 507 } |
506 token = parseModifiers(token); | 508 token = parseModifiers(token); |
507 bool isNamedParameter = kind == FormalParameterType.NAMED; | 509 bool isNamedParameter = kind == FormalParameterType.NAMED; |
508 | 510 |
509 Token thisKeyword = null; | 511 Token thisKeyword = null; |
510 if (inFunctionType && isNamedParameter) { | 512 if (inFunctionType && isNamedParameter) { |
511 token = parseType(token); | 513 token = parseType(token); |
512 token = | 514 token = |
513 parseIdentifier(token, IdentifierContext.formalParameterDeclaration); | 515 parseIdentifier(token, IdentifierContext.formalParameterDeclaration); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 if (kind.isRequired) { | 569 if (kind.isRequired) { |
568 reportRecoverableError( | 570 reportRecoverableError( |
569 equal, ErrorKind.RequiredParameterWithDefault); | 571 equal, ErrorKind.RequiredParameterWithDefault); |
570 } else if (kind.isPositional && identical(':', value)) { | 572 } else if (kind.isPositional && identical(':', value)) { |
571 reportRecoverableError( | 573 reportRecoverableError( |
572 equal, ErrorKind.PositionalParameterWithEquals); | 574 equal, ErrorKind.PositionalParameterWithEquals); |
573 } | 575 } |
574 } else { | 576 } else { |
575 listener.handleFormalParameterWithoutValue(token); | 577 listener.handleFormalParameterWithoutValue(token); |
576 } | 578 } |
577 listener.endFormalParameter(thisKeyword, kind); | 579 listener.endFormalParameter(covariantKeyword, thisKeyword, kind); |
578 return token; | 580 return token; |
579 } | 581 } |
580 | 582 |
581 Token parseOptionalFormalParameters(Token token, bool isNamed, | 583 Token parseOptionalFormalParameters(Token token, bool isNamed, |
582 {bool inFunctionType: false}) { | 584 {bool inFunctionType: false}) { |
583 Token begin = token; | 585 Token begin = token; |
584 listener.beginOptionalFormalParameters(begin); | 586 listener.beginOptionalFormalParameters(begin); |
585 assert((isNamed && optional('{', token)) || optional('[', token)); | 587 assert((isNamed && optional('{', token)) || optional('[', token)); |
586 int parameterCount = 0; | 588 int parameterCount = 0; |
587 do { | 589 do { |
(...skipping 2955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3543 break; | 3545 break; |
3544 } | 3546 } |
3545 if (isRecoverable) { | 3547 if (isRecoverable) { |
3546 listener.handleRecoverableError(token, kind, arguments); | 3548 listener.handleRecoverableError(token, kind, arguments); |
3547 return null; | 3549 return null; |
3548 } else { | 3550 } else { |
3549 return listener.handleUnrecoverableError(token, kind, arguments); | 3551 return listener.handleUnrecoverableError(token, kind, arguments); |
3550 } | 3552 } |
3551 } | 3553 } |
3552 } | 3554 } |
OLD | NEW |