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 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 if (optional('this', token)) { | 524 if (optional('this', token)) { |
525 thisKeyword = token; | 525 thisKeyword = token; |
526 token = expect('.', token.next); | 526 token = expect('.', token.next); |
527 token = parseIdentifier(token, IdentifierContext.fieldInitializer); | 527 token = parseIdentifier(token, IdentifierContext.fieldInitializer); |
528 } else { | 528 } else { |
529 token = parseIdentifier( | 529 token = parseIdentifier( |
530 token, IdentifierContext.formalParameterDeclaration); | 530 token, IdentifierContext.formalParameterDeclaration); |
531 } | 531 } |
532 } | 532 } |
533 | 533 |
534 // Generalized function types don't allow inline function types. | |
535 // The following isn't allowed: | |
536 // int Function(int bar(String x)). | |
537 if (optional('(', token)) { | 534 if (optional('(', token)) { |
538 Token inlineFunctionTypeStart = token; | 535 Token inlineFunctionTypeStart = token; |
539 listener.beginFunctionTypedFormalParameter(token); | 536 listener.beginFunctionTypedFormalParameter(token); |
540 listener.handleNoTypeVariables(token); | 537 listener.handleNoTypeVariables(token); |
541 token = parseFormalParameters(token); | 538 token = parseFormalParameters(token); |
542 listener.endFunctionTypedFormalParameter(token); | 539 listener.endFunctionTypedFormalParameter(token); |
| 540 // Generalized function types don't allow inline function types. |
| 541 // The following isn't allowed: |
| 542 // int Function(int bar(String x)). |
543 if (inFunctionType) { | 543 if (inFunctionType) { |
544 reportRecoverableError( | 544 reportRecoverableError( |
545 inlineFunctionTypeStart, ErrorKind.InvalidInlineFunctionType); | 545 inlineFunctionTypeStart, ErrorKind.InvalidInlineFunctionType); |
546 } | 546 } |
547 } else if (optional('<', token)) { | 547 } else if (optional('<', token)) { |
548 Token inlineFunctionTypeStart = token; | 548 Token inlineFunctionTypeStart = token; |
549 listener.beginFunctionTypedFormalParameter(token); | 549 listener.beginFunctionTypedFormalParameter(token); |
550 token = parseTypeVariablesOpt(token); | 550 token = parseTypeVariablesOpt(token); |
551 token = parseFormalParameters(token); | 551 token = parseFormalParameters(token); |
552 listener.endFunctionTypedFormalParameter(token); | 552 listener.endFunctionTypedFormalParameter(token); |
| 553 // Generalized function types don't allow inline function types. |
| 554 // The following isn't allowed: |
| 555 // int Function(int bar(String x)). |
553 if (inFunctionType) { | 556 if (inFunctionType) { |
554 reportRecoverableError( | 557 reportRecoverableError( |
555 inlineFunctionTypeStart, ErrorKind.InvalidInlineFunctionType); | 558 inlineFunctionTypeStart, ErrorKind.InvalidInlineFunctionType); |
556 } | 559 } |
557 } | 560 } |
558 String value = token.stringValue; | 561 String value = token.stringValue; |
559 if ((identical('=', value)) || (identical(':', value))) { | 562 if ((identical('=', value)) || (identical(':', value))) { |
560 // TODO(ahe): Validate that these are only used for optional parameters. | 563 // TODO(ahe): Validate that these are only used for optional parameters. |
561 Token equal = token; | 564 Token equal = token; |
562 token = parseExpression(token.next); | 565 token = parseExpression(token.next); |
(...skipping 2975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3538 break; | 3541 break; |
3539 } | 3542 } |
3540 if (isRecoverable) { | 3543 if (isRecoverable) { |
3541 listener.handleRecoverableError(token, kind, arguments); | 3544 listener.handleRecoverableError(token, kind, arguments); |
3542 return null; | 3545 return null; |
3543 } else { | 3546 } else { |
3544 return listener.handleUnrecoverableError(token, kind, arguments); | 3547 return listener.handleUnrecoverableError(token, kind, arguments); |
3545 } | 3548 } |
3546 } | 3549 } |
3547 } | 3550 } |
OLD | NEW |