Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** | 5 /** |
| 6 * An event generating parser of Dart programs. This parser expects | 6 * An event generating parser of Dart programs. This parser expects |
| 7 * all tokens in a linked list. | 7 * all tokens in a linked list. |
| 8 */ | 8 */ |
| 9 class Parser { | 9 class Parser { |
| 10 final Listener listener; | 10 final Listener listener; |
| (...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 935 info = token.info; | 935 info = token.info; |
| 936 tokenLevel = info.precedence; | 936 tokenLevel = info.precedence; |
| 937 } | 937 } |
| 938 } | 938 } |
| 939 return token; | 939 return token; |
| 940 } | 940 } |
| 941 | 941 |
| 942 Token parseUnaryExpression(Token token) { | 942 Token parseUnaryExpression(Token token) { |
| 943 String value = token.stringValue; | 943 String value = token.stringValue; |
| 944 // Prefix: | 944 // Prefix: |
| 945 if ((value === '!') || | 945 if (value === '+') { |
| 946 (value === '+') || // TODO(ahe): Being removed from specification. | 946 // Dart only allows "prefix plus" as an initial part of a |
| 947 (value === '-') || | 947 // decimal literal. We scan it as a separate token and then throw |
| 948 (value === '~')) { | 948 // it away here when we know that we have a unary plus, not a |
|
ahe
2012/02/03 13:19:11
We are not throwing it away anymore :-)
| |
| 949 // binary one. | |
| 950 Token operator = token; | |
| 951 Token next = token.next; | |
| 952 if (next.charOffset !== token.charOffset + 1 || | |
| 953 (next.kind !== INT_TOKEN && next.kind !== DOUBLE_TOKEN)) { | |
| 954 listener.recoverableError("Unexpected token '+'", token: token); | |
| 955 } | |
| 956 token = parsePrecedenceExpression(next, POSTFIX_PRECEDENCE); | |
| 957 listener.handleUnaryPrefixExpression(operator); | |
| 958 } else if ((value === '!') || | |
| 959 (value === '-') || | |
| 960 (value === '~')) { | |
| 949 Token operator = token; | 961 Token operator = token; |
| 950 // Right associative, so we recurse at the same precedence | 962 // Right associative, so we recurse at the same precedence |
| 951 // level. | 963 // level. |
| 952 token = parsePrecedenceExpression(token.next, POSTFIX_PRECEDENCE); | 964 token = parsePrecedenceExpression(token.next, POSTFIX_PRECEDENCE); |
| 953 listener.handleUnaryPrefixExpression(operator); | 965 listener.handleUnaryPrefixExpression(operator); |
| 954 } else if ((value === '++') || value === '--') { | 966 } else if ((value === '++') || value === '--') { |
| 955 // TODO(ahe): Validate this is used correctly. | 967 // TODO(ahe): Validate this is used correctly. |
| 956 Token operator = token; | 968 Token operator = token; |
| 957 // Right associative, so we recurse at the same precedence | 969 // Right associative, so we recurse at the same precedence |
| 958 // level. | 970 // level. |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1604 } | 1616 } |
| 1605 listener.handleContinueStatement(hasTarget, continueKeyword, token); | 1617 listener.handleContinueStatement(hasTarget, continueKeyword, token); |
| 1606 return expectSemicolon(token); | 1618 return expectSemicolon(token); |
| 1607 } | 1619 } |
| 1608 | 1620 |
| 1609 Token parseEmptyStatement(Token token) { | 1621 Token parseEmptyStatement(Token token) { |
| 1610 listener.handleEmptyStatement(token); | 1622 listener.handleEmptyStatement(token); |
| 1611 return expectSemicolon(token); | 1623 return expectSemicolon(token); |
| 1612 } | 1624 } |
| 1613 } | 1625 } |
| OLD | NEW |