| 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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 listener.handleNoFormalParameters(token); | 417 listener.handleNoFormalParameters(token); |
| 418 return token; | 418 return token; |
| 419 } | 419 } |
| 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)) { | |
| 428 listener.endFormalParameters(parameterCount, begin, token.next); | |
| 429 return token.next.next; | |
| 430 } | |
| 431 do { | 427 do { |
| 428 token = token.next; |
| 429 if (optional(')', token)) { |
| 430 break; |
| 431 } |
| 432 ++parameterCount; | 432 ++parameterCount; |
| 433 token = token.next; | |
| 434 String value = token.stringValue; | 433 String value = token.stringValue; |
| 435 if (identical(value, '[')) { | 434 if (identical(value, '[')) { |
| 436 token = parseOptionalFormalParameters(token, false); | 435 token = parseOptionalFormalParameters(token, false); |
| 437 break; | 436 break; |
| 438 } else if (identical(value, '{')) { | 437 } else if (identical(value, '{')) { |
| 439 token = parseOptionalFormalParameters(token, true); | 438 token = parseOptionalFormalParameters(token, true); |
| 440 break; | 439 break; |
| 441 } | 440 } |
| 442 token = parseFormalParameter(token, FormalParameterType.REQUIRED); | 441 token = parseFormalParameter(token, FormalParameterType.REQUIRED); |
| 443 } while (optional(',', token)); | 442 } while (optional(',', token)); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 return token; | 487 return token; |
| 489 } | 488 } |
| 490 | 489 |
| 491 Token parseOptionalFormalParameters(Token token, bool isNamed) { | 490 Token parseOptionalFormalParameters(Token token, bool isNamed) { |
| 492 Token begin = token; | 491 Token begin = token; |
| 493 listener.beginOptionalFormalParameters(begin); | 492 listener.beginOptionalFormalParameters(begin); |
| 494 assert((isNamed && optional('{', token)) || optional('[', token)); | 493 assert((isNamed && optional('{', token)) || optional('[', token)); |
| 495 int parameterCount = 0; | 494 int parameterCount = 0; |
| 496 do { | 495 do { |
| 497 token = token.next; | 496 token = token.next; |
| 497 if (isNamed && optional('}', token)) { |
| 498 break; |
| 499 } else if (!isNamed && optional(']', token)) { |
| 500 break; |
| 501 } |
| 498 var type = | 502 var type = |
| 499 isNamed ? FormalParameterType.NAMED : FormalParameterType.POSITIONAL; | 503 isNamed ? FormalParameterType.NAMED : FormalParameterType.POSITIONAL; |
| 500 token = parseFormalParameter(token, type); | 504 token = parseFormalParameter(token, type); |
| 501 ++parameterCount; | 505 ++parameterCount; |
| 502 } while (optional(',', token)); | 506 } while (optional(',', token)); |
| 507 if (parameterCount == 0) { |
| 508 listener.reportError( |
| 509 token, |
| 510 isNamed |
| 511 ? MessageKind.EMPTY_NAMED_PARAMETER_LIST |
| 512 : MessageKind.EMPTY_OPTIONAL_PARAMETER_LIST); |
| 513 } |
| 503 listener.endOptionalFormalParameters(parameterCount, begin, token); | 514 listener.endOptionalFormalParameters(parameterCount, begin, token); |
| 504 if (isNamed) { | 515 if (isNamed) { |
| 505 return expect('}', token); | 516 return expect('}', token); |
| 506 } else { | 517 } else { |
| 507 return expect(']', token); | 518 return expect(']', token); |
| 508 } | 519 } |
| 509 } | 520 } |
| 510 | 521 |
| 511 Token parseTypeOpt(Token token) { | 522 Token parseTypeOpt(Token token) { |
| 512 Token peek = peekAfterIfType(token); | 523 Token peek = peekAfterIfType(token); |
| (...skipping 2045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2558 listener.beginArguments(begin); | 2569 listener.beginArguments(begin); |
| 2559 assert(identical('(', token.stringValue)); | 2570 assert(identical('(', token.stringValue)); |
| 2560 int argumentCount = 0; | 2571 int argumentCount = 0; |
| 2561 if (optional(')', token.next)) { | 2572 if (optional(')', token.next)) { |
| 2562 listener.endArguments(argumentCount, begin, token.next); | 2573 listener.endArguments(argumentCount, begin, token.next); |
| 2563 return token.next.next; | 2574 return token.next.next; |
| 2564 } | 2575 } |
| 2565 bool old = mayParseFunctionExpressions; | 2576 bool old = mayParseFunctionExpressions; |
| 2566 mayParseFunctionExpressions = true; | 2577 mayParseFunctionExpressions = true; |
| 2567 do { | 2578 do { |
| 2579 if (optional(')', token.next)) { |
| 2580 token = token.next; |
| 2581 break; |
| 2582 } |
| 2568 Token colon = null; | 2583 Token colon = null; |
| 2569 if (optional(':', token.next.next)) { | 2584 if (optional(':', token.next.next)) { |
| 2570 token = parseIdentifier(token.next); | 2585 token = parseIdentifier(token.next); |
| 2571 colon = token; | 2586 colon = token; |
| 2572 } | 2587 } |
| 2573 token = parseExpression(token.next); | 2588 token = parseExpression(token.next); |
| 2574 if (colon != null) listener.handleNamedArgument(colon); | 2589 if (colon != null) listener.handleNamedArgument(colon); |
| 2575 ++argumentCount; | 2590 ++argumentCount; |
| 2576 } while (optional(',', token)); | 2591 } while (optional(',', token)); |
| 2577 mayParseFunctionExpressions = old; | 2592 mayParseFunctionExpressions = old; |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2982 } | 2997 } |
| 2983 listener.handleContinueStatement(hasTarget, continueKeyword, token); | 2998 listener.handleContinueStatement(hasTarget, continueKeyword, token); |
| 2984 return expectSemicolon(token); | 2999 return expectSemicolon(token); |
| 2985 } | 3000 } |
| 2986 | 3001 |
| 2987 Token parseEmptyStatement(Token token) { | 3002 Token parseEmptyStatement(Token token) { |
| 2988 listener.handleEmptyStatement(token); | 3003 listener.handleEmptyStatement(token); |
| 2989 return expectSemicolon(token); | 3004 return expectSemicolon(token); |
| 2990 } | 3005 } |
| 2991 } | 3006 } |
| OLD | NEW |