Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: pkg/front_end/lib/src/fasta/parser/parser.dart

Issue 2709783003: Parse optional and named parameters. (Closed)
Patch Set: Add 'FormalParameterType kind' to endFormalParameter() and add handleFormalParameterWithoutValue(). Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 } else if (identical(value, '{')) { 455 } else if (identical(value, '{')) {
456 token = parseOptionalFormalParameters(token, true); 456 token = parseOptionalFormalParameters(token, true);
457 break; 457 break;
458 } 458 }
459 token = parseFormalParameter(token, FormalParameterType.REQUIRED); 459 token = parseFormalParameter(token, FormalParameterType.REQUIRED);
460 } while (optional(',', token)); 460 } while (optional(',', token));
461 listener.endFormalParameters(parameterCount, begin, token); 461 listener.endFormalParameters(parameterCount, begin, token);
462 return expect(')', token); 462 return expect(')', token);
463 } 463 }
464 464
465 Token parseFormalParameter(Token token, FormalParameterType type) { 465 Token parseFormalParameter(Token token, FormalParameterType kind) {
466 token = parseMetadataStar(token, forParameter: true); 466 token = parseMetadataStar(token, forParameter: true);
467 listener.beginFormalParameter(token); 467 listener.beginFormalParameter(token);
468 468
469 // Skip over `covariant` token, if the next token is an identifier or 469 // Skip over `covariant` token, if the next token is an identifier or
470 // modifier. 470 // modifier.
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;
(...skipping 19 matching lines...) Expand all
495 token = parseTypeVariablesOpt(token); 495 token = parseTypeVariablesOpt(token);
496 token = parseFormalParameters(token); 496 token = parseFormalParameters(token);
497 listener.endFunctionTypedFormalParameter(token); 497 listener.endFunctionTypedFormalParameter(token);
498 } 498 }
499 String value = token.stringValue; 499 String value = token.stringValue;
500 if ((identical('=', value)) || (identical(':', value))) { 500 if ((identical('=', value)) || (identical(':', value))) {
501 // TODO(ahe): Validate that these are only used for optional parameters. 501 // TODO(ahe): Validate that these are only used for optional parameters.
502 Token equal = token; 502 Token equal = token;
503 token = parseExpression(token.next); 503 token = parseExpression(token.next);
504 listener.handleValuedFormalParameter(equal, token); 504 listener.handleValuedFormalParameter(equal, token);
505 if (type.isRequired) { 505 if (kind.isRequired) {
506 reportRecoverableError( 506 reportRecoverableError(
507 equal, ErrorKind.RequiredParameterWithDefault); 507 equal, ErrorKind.RequiredParameterWithDefault);
508 } else if (type.isPositional && identical(':', value)) { 508 } else if (kind.isPositional && identical(':', value)) {
509 reportRecoverableError( 509 reportRecoverableError(
510 equal, ErrorKind.PositionalParameterWithEquals); 510 equal, ErrorKind.PositionalParameterWithEquals);
511 } 511 }
512 } else {
513 listener.handleFormalParameterWithoutValue(token);
512 } 514 }
513 listener.endFormalParameter(thisKeyword); 515 listener.endFormalParameter(thisKeyword, kind);
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698