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 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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 // This enables the case where `covariant` is the name of the parameter: | 471 // This enables the case where `covariant` is the name of the parameter: |
| 472 // void foo(covariant); | 472 // void foo(covariant); |
| 473 if (identical(token.stringValue, 'covariant') && | 473 if (identical(token.stringValue, 'covariant') && |
| 474 (token.next.isIdentifier() || isModifier(token.next))) { | 474 (token.next.isIdentifier() || isModifier(token.next))) { |
| 475 token = token.next; | 475 token = token.next; |
| 476 } | 476 } |
| 477 token = parseModifiers(token); | 477 token = parseModifiers(token); |
| 478 // TODO(ahe): Validate that there are formal parameters if void. | 478 // TODO(ahe): Validate that there are formal parameters if void. |
| 479 token = parseReturnTypeOpt(token); | 479 token = parseReturnTypeOpt(token); |
| 480 Token thisKeyword = null; | 480 Token thisKeyword = null; |
| 481 Token period = null; | |
| 481 if (optional('this', token)) { | 482 if (optional('this', token)) { |
| 482 thisKeyword = token; | 483 thisKeyword = token; |
| 484 period = token.next; | |
|
Paul Berry
2017/02/22 20:41:09
This seems problematic for error recovery. If the
scheglov
2017/02/23 06:43:50
This is the pattern that is used everywhere else i
ahe
2017/02/23 16:27:11
I agree that it is a problem for error recovery.
| |
| 483 // TODO(ahe): Validate field initializers are only used in | 485 // TODO(ahe): Validate field initializers are only used in |
| 484 // constructors, and not for function-typed arguments. | 486 // constructors, and not for function-typed arguments. |
| 485 token = expect('.', token.next); | 487 token = expect('.', period); |
| 486 } | 488 } |
| 487 token = parseIdentifier(token); | 489 token = parseIdentifier(token); |
| 488 if (optional('(', token)) { | 490 if (optional('(', token)) { |
| 489 listener.beginFunctionTypedFormalParameter(token); | 491 listener.beginFunctionTypedFormalParameter(token); |
| 490 listener.handleNoTypeVariables(token); | 492 listener.handleNoTypeVariables(token); |
| 491 token = parseFormalParameters(token); | 493 token = parseFormalParameters(token); |
| 492 listener.endFunctionTypedFormalParameter(token); | 494 listener.endFunctionTypedFormalParameter(token); |
| 493 } else if (optional('<', token)) { | 495 } else if (optional('<', token)) { |
| 494 listener.beginFunctionTypedFormalParameter(token); | 496 listener.beginFunctionTypedFormalParameter(token); |
| 495 token = parseTypeVariablesOpt(token); | 497 token = parseTypeVariablesOpt(token); |
| 496 token = parseFormalParameters(token); | 498 token = parseFormalParameters(token); |
| 497 listener.endFunctionTypedFormalParameter(token); | 499 listener.endFunctionTypedFormalParameter(token); |
| 498 } | 500 } |
| 499 String value = token.stringValue; | 501 String value = token.stringValue; |
| 500 if ((identical('=', value)) || (identical(':', value))) { | 502 if ((identical('=', value)) || (identical(':', value))) { |
| 501 // TODO(ahe): Validate that these are only used for optional parameters. | 503 // TODO(ahe): Validate that these are only used for optional parameters. |
| 502 Token equal = token; | 504 Token equal = token; |
| 503 token = parseExpression(token.next); | 505 token = parseExpression(token.next); |
| 504 listener.handleValuedFormalParameter(equal, token); | 506 listener.handleValuedFormalParameter(equal, token); |
| 505 if (type.isRequired) { | 507 if (type.isRequired) { |
| 506 reportRecoverableError( | 508 reportRecoverableError( |
| 507 equal, ErrorKind.RequiredParameterWithDefault); | 509 equal, ErrorKind.RequiredParameterWithDefault); |
| 508 } else if (type.isPositional && identical(':', value)) { | 510 } else if (type.isPositional && identical(':', value)) { |
| 509 reportRecoverableError( | 511 reportRecoverableError( |
| 510 equal, ErrorKind.PositionalParameterWithEquals); | 512 equal, ErrorKind.PositionalParameterWithEquals); |
| 511 } | 513 } |
| 512 } | 514 } |
| 513 listener.endFormalParameter(thisKeyword); | 515 listener.endFormalParameter(thisKeyword, period); |
|
ahe
2017/02/23 16:27:11
This isn't necessary. The period can be found with
| |
| 514 return token; | 516 return token; |
| 515 } | 517 } |
| 516 | 518 |
| 517 Token parseOptionalFormalParameters(Token token, bool isNamed) { | 519 Token parseOptionalFormalParameters(Token token, bool isNamed) { |
| 518 Token begin = token; | 520 Token begin = token; |
| 519 listener.beginOptionalFormalParameters(begin); | 521 listener.beginOptionalFormalParameters(begin); |
| 520 assert((isNamed && optional('{', token)) || optional('[', token)); | 522 assert((isNamed && optional('{', token)) || optional('[', token)); |
| 521 int parameterCount = 0; | 523 int parameterCount = 0; |
| 522 do { | 524 do { |
| 523 token = token.next; | 525 token = token.next; |
| (...skipping 2799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3323 break; | 3325 break; |
| 3324 } | 3326 } |
| 3325 if (isRecoverable) { | 3327 if (isRecoverable) { |
| 3326 listener.handleRecoverableError(token, kind, arguments); | 3328 listener.handleRecoverableError(token, kind, arguments); |
| 3327 return null; | 3329 return null; |
| 3328 } else { | 3330 } else { |
| 3329 return listener.handleUnrecoverableError(token, kind, arguments); | 3331 return listener.handleUnrecoverableError(token, kind, arguments); |
| 3330 } | 3332 } |
| 3331 } | 3333 } |
| 3332 } | 3334 } |
| OLD | NEW |