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 dart2js.parser; | 5 library dart2js.parser; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../tokens/keyword.dart' show | 8 import '../tokens/keyword.dart' show |
| 9 Keyword; | 9 Keyword; |
| 10 import '../tokens/precedence.dart' show | 10 import '../tokens/precedence.dart' show |
| (...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 653 | 653 |
| 654 /** | 654 /** |
| 655 * Returns true if the stringValue of the [token] is [value]. | 655 * Returns true if the stringValue of the [token] is [value]. |
| 656 */ | 656 */ |
| 657 bool optional(String value, Token token) { | 657 bool optional(String value, Token token) { |
| 658 return identical(value, token.stringValue); | 658 return identical(value, token.stringValue); |
| 659 } | 659 } |
| 660 | 660 |
| 661 /** | 661 /** |
| 662 * Returns true if the stringValue of the [token] is either [value1], | 662 * Returns true if the stringValue of the [token] is either [value1], |
| 663 * [value2], or [value3]. | |
| 664 */ | |
| 665 bool isOneOf3(Token token, | |
| 666 String value1, String value2, String value3) { | |
|
karlklose
2015/12/08 09:23:30
Indentation.
Johnni Winther
2015/12/08 10:07:17
Done.
| |
| 667 String stringValue = token.stringValue; | |
| 668 return value1 == stringValue || | |
| 669 value2 == stringValue || | |
|
karlklose
2015/12/08 09:23:30
Indentation.
Johnni Winther
2015/12/08 10:07:17
Done.
| |
| 670 value3 == stringValue; | |
| 671 } | |
| 672 | |
| 673 /** | |
| 674 * Returns true if the stringValue of the [token] is either [value1], | |
| 663 * [value2], [value3], or [value4]. | 675 * [value2], [value3], or [value4]. |
| 664 */ | 676 */ |
| 665 bool isOneOf4(Token token, | 677 bool isOneOf4(Token token, |
| 666 String value1, String value2, String value3, String value4) { | 678 String value1, String value2, String value3, String value4) { |
| 667 String stringValue = token.stringValue; | 679 String stringValue = token.stringValue; |
| 668 return identical(value1, stringValue) || | 680 return value1 == stringValue || |
| 669 identical(value2, stringValue) || | 681 value2 == stringValue || |
| 670 identical(value3, stringValue) || | 682 value3 == stringValue || |
| 671 identical(value4, stringValue); | 683 value4 == stringValue; |
| 672 } | 684 } |
| 673 | 685 |
| 674 bool notEofOrValue(String value, Token token) { | 686 bool notEofOrValue(String value, Token token) { |
| 675 return !identical(token.kind, EOF_TOKEN) && | 687 return !identical(token.kind, EOF_TOKEN) && |
| 676 !identical(value, token.stringValue); | 688 !identical(value, token.stringValue); |
| 677 } | 689 } |
| 678 | 690 |
| 679 Token parseType(Token token) { | 691 Token parseType(Token token) { |
| 680 Token begin = token; | 692 Token begin = token; |
| 681 if (isValidTypeReference(token)) { | 693 if (isValidTypeReference(token)) { |
| (...skipping 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2420 } | 2432 } |
| 2421 return parseForRest(forToken, token); | 2433 return parseForRest(forToken, token); |
| 2422 } | 2434 } |
| 2423 } | 2435 } |
| 2424 | 2436 |
| 2425 Token parseVariablesDeclarationOrExpressionOpt(Token token) { | 2437 Token parseVariablesDeclarationOrExpressionOpt(Token token) { |
| 2426 final String value = token.stringValue; | 2438 final String value = token.stringValue; |
| 2427 if (identical(value, ';')) { | 2439 if (identical(value, ';')) { |
| 2428 listener.handleNoExpression(token); | 2440 listener.handleNoExpression(token); |
| 2429 return token; | 2441 return token; |
| 2430 } else if ((identical(value, 'var')) || (identical(value, 'final'))) { | 2442 } else if (isOneOf3(token, 'var', 'final', 'const')) { |
| 2431 return parseVariablesDeclarationNoSemicolon(token); | 2443 return parseVariablesDeclarationNoSemicolon(token); |
| 2432 } | 2444 } |
| 2433 Token identifier = peekIdentifierAfterType(token); | 2445 Token identifier = peekIdentifierAfterType(token); |
| 2434 if (identifier != null) { | 2446 if (identifier != null) { |
| 2435 assert(identifier.isIdentifier()); | 2447 assert(identifier.isIdentifier()); |
| 2436 if (isOneOf4(identifier.next, '=', ';', ',', 'in')) { | 2448 if (isOneOf4(identifier.next, '=', ';', ',', 'in')) { |
| 2437 return parseVariablesDeclarationNoSemicolon(token); | 2449 return parseVariablesDeclarationNoSemicolon(token); |
| 2438 } | 2450 } |
| 2439 } | 2451 } |
| 2440 return parseExpression(token); | 2452 return parseExpression(token); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2724 } | 2736 } |
| 2725 listener.handleContinueStatement(hasTarget, continueKeyword, token); | 2737 listener.handleContinueStatement(hasTarget, continueKeyword, token); |
| 2726 return expectSemicolon(token); | 2738 return expectSemicolon(token); |
| 2727 } | 2739 } |
| 2728 | 2740 |
| 2729 Token parseEmptyStatement(Token token) { | 2741 Token parseEmptyStatement(Token token) { |
| 2730 listener.handleEmptyStatement(token); | 2742 listener.handleEmptyStatement(token); |
| 2731 return expectSemicolon(token); | 2743 return expectSemicolon(token); |
| 2732 } | 2744 } |
| 2733 } | 2745 } |
| OLD | NEW |