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 dart2js.parser; | 5 library dart2js.parser; |
6 | 6 |
7 import '../options.dart' show ParserOptions; | 7 import '../options.dart' show ParserOptions; |
8 import '../common.dart'; | 8 import '../common.dart'; |
9 import '../tokens/keyword.dart' show Keyword; | 9 import '../tokens/keyword.dart' show Keyword; |
10 import '../tokens/precedence.dart' show PrecedenceInfo; | 10 import '../tokens/precedence.dart' show PrecedenceInfo; |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
420 } | 420 } |
421 | 421 |
422 Token parseFormalParameters(Token token) { | 422 Token parseFormalParameters(Token token) { |
423 Token begin = token; | 423 Token begin = token; |
424 listener.beginFormalParameters(begin); | 424 listener.beginFormalParameters(begin); |
425 expect('(', token); | 425 expect('(', token); |
426 int parameterCount = 0; | 426 int parameterCount = 0; |
427 if (optional(')', token.next)) { | 427 if (optional(')', token.next)) { |
428 listener.endFormalParameters(parameterCount, begin, token.next); | 428 listener.endFormalParameters(parameterCount, begin, token.next); |
429 return token.next.next; | 429 return token.next.next; |
430 } | 430 } |
Lasse Reichstein Nielsen
2016/07/08 05:45:18
Is this `if` necessary now?
| |
431 do { | 431 do { |
432 token = token.next; | |
433 if (optional(')', token)) { | |
434 break; | |
435 } | |
432 ++parameterCount; | 436 ++parameterCount; |
433 token = token.next; | |
434 String value = token.stringValue; | 437 String value = token.stringValue; |
435 if (identical(value, '[')) { | 438 if (identical(value, '[')) { |
436 token = parseOptionalFormalParameters(token, false); | 439 token = parseOptionalFormalParameters(token, false); |
437 break; | 440 break; |
438 } else if (identical(value, '{')) { | 441 } else if (identical(value, '{')) { |
439 token = parseOptionalFormalParameters(token, true); | 442 token = parseOptionalFormalParameters(token, true); |
440 break; | 443 break; |
441 } | 444 } |
442 token = parseFormalParameter(token, FormalParameterType.REQUIRED); | 445 token = parseFormalParameter(token, FormalParameterType.REQUIRED); |
443 } while (optional(',', token)); | 446 } while (optional(',', token)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 return token; | 491 return token; |
489 } | 492 } |
490 | 493 |
491 Token parseOptionalFormalParameters(Token token, bool isNamed) { | 494 Token parseOptionalFormalParameters(Token token, bool isNamed) { |
492 Token begin = token; | 495 Token begin = token; |
493 listener.beginOptionalFormalParameters(begin); | 496 listener.beginOptionalFormalParameters(begin); |
494 assert((isNamed && optional('{', token)) || optional('[', token)); | 497 assert((isNamed && optional('{', token)) || optional('[', token)); |
495 int parameterCount = 0; | 498 int parameterCount = 0; |
496 do { | 499 do { |
497 token = token.next; | 500 token = token.next; |
501 if (isNamed && optional('}', token)) { | |
502 break; | |
503 } else if (!isNamed && optional(']', token)) { | |
504 break; | |
505 } | |
498 var type = | 506 var type = |
499 isNamed ? FormalParameterType.NAMED : FormalParameterType.POSITIONAL; | 507 isNamed ? FormalParameterType.NAMED : FormalParameterType.POSITIONAL; |
500 token = parseFormalParameter(token, type); | 508 token = parseFormalParameter(token, type); |
501 ++parameterCount; | 509 ++parameterCount; |
502 } while (optional(',', token)); | 510 } while (optional(',', token)); |
511 if (parameterCount == 0) { | |
512 listener.reportError( | |
513 token, | |
514 isNamed | |
515 ? MessageKind.EMPTY_NAMED_PARAMETER_LIST | |
516 : MessageKind.EMPTY_OPTIONAL_PARAMETER_LIST); | |
517 } | |
503 listener.endOptionalFormalParameters(parameterCount, begin, token); | 518 listener.endOptionalFormalParameters(parameterCount, begin, token); |
504 if (isNamed) { | 519 if (isNamed) { |
505 return expect('}', token); | 520 return expect('}', token); |
506 } else { | 521 } else { |
507 return expect(']', token); | 522 return expect(']', token); |
508 } | 523 } |
509 } | 524 } |
510 | 525 |
511 Token parseTypeOpt(Token token) { | 526 Token parseTypeOpt(Token token) { |
512 Token peek = peekAfterIfType(token); | 527 Token peek = peekAfterIfType(token); |
(...skipping 2045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2558 listener.beginArguments(begin); | 2573 listener.beginArguments(begin); |
2559 assert(identical('(', token.stringValue)); | 2574 assert(identical('(', token.stringValue)); |
2560 int argumentCount = 0; | 2575 int argumentCount = 0; |
2561 if (optional(')', token.next)) { | 2576 if (optional(')', token.next)) { |
2562 listener.endArguments(argumentCount, begin, token.next); | 2577 listener.endArguments(argumentCount, begin, token.next); |
2563 return token.next.next; | 2578 return token.next.next; |
2564 } | 2579 } |
2565 bool old = mayParseFunctionExpressions; | 2580 bool old = mayParseFunctionExpressions; |
2566 mayParseFunctionExpressions = true; | 2581 mayParseFunctionExpressions = true; |
2567 do { | 2582 do { |
2583 if (optional(')', token.next)) { | |
2584 token = token.next; | |
2585 break; | |
2586 } | |
2568 Token colon = null; | 2587 Token colon = null; |
2569 if (optional(':', token.next.next)) { | 2588 if (optional(':', token.next.next)) { |
2570 token = parseIdentifier(token.next); | 2589 token = parseIdentifier(token.next); |
2571 colon = token; | 2590 colon = token; |
2572 } | 2591 } |
2573 token = parseExpression(token.next); | 2592 token = parseExpression(token.next); |
2574 if (colon != null) listener.handleNamedArgument(colon); | 2593 if (colon != null) listener.handleNamedArgument(colon); |
2575 ++argumentCount; | 2594 ++argumentCount; |
2576 } while (optional(',', token)); | 2595 } while (optional(',', token)); |
2577 mayParseFunctionExpressions = old; | 2596 mayParseFunctionExpressions = old; |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2982 } | 3001 } |
2983 listener.handleContinueStatement(hasTarget, continueKeyword, token); | 3002 listener.handleContinueStatement(hasTarget, continueKeyword, token); |
2984 return expectSemicolon(token); | 3003 return expectSemicolon(token); |
2985 } | 3004 } |
2986 | 3005 |
2987 Token parseEmptyStatement(Token token) { | 3006 Token parseEmptyStatement(Token token) { |
2988 listener.handleEmptyStatement(token); | 3007 listener.handleEmptyStatement(token); |
2989 return expectSemicolon(token); | 3008 return expectSemicolon(token); |
2990 } | 3009 } |
2991 } | 3010 } |
OLD | NEW |