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 throws |
|
ahe
2012/02/03 11:28:51
throws -> throw
| |
| 948 (value === '~')) { | 948 // it away here when we know that we have an unary plus, not a |
|
ahe
2012/02/03 11:28:51
"an unary" -> "a unary"
http://owl.english.purdue
| |
| 949 // binary one. | |
|
Lasse Reichstein Nielsen
2012/02/03 13:30:17
Comment updated.
| |
| 950 Token next = token.next; | |
| 951 if (next.charOffset === token.charOffset + 1) { | |
| 952 if (next.kind === INT_TOKEN) return parseLiteralInt(next); | |
|
ahe
2012/02/03 11:28:51
We shouldn't throw tokens away. Long term, it beco
Lasse Reichstein Nielsen
2012/02/03 13:10:22
I think we should throw it away in the listener in
ahe
2012/02/03 13:19:11
Unfortunately, that way of thinking is counter-pro
Lasse Reichstein Nielsen
2012/02/03 13:30:17
I'm not advocating throwing the character away, bu
ahe
2012/02/03 13:41:10
We could do that. I guess it would be limited to L
| |
| 953 if (next.kind === DOUBLE_TOKEN) return parseLiteralDouble(next); | |
| 954 } | |
| 955 listener.recoverableError("Unexpected token '+'", token: token); | |
| 956 return parseUnaryExpression(next); | |
| 957 } else if ((value === '!') || | |
| 958 (value === '-') || | |
| 959 (value === '~')) { | |
| 949 Token operator = token; | 960 Token operator = token; |
| 950 // Right associative, so we recurse at the same precedence | 961 // Right associative, so we recurse at the same precedence |
| 951 // level. | 962 // level. |
| 952 token = parsePrecedenceExpression(token.next, POSTFIX_PRECEDENCE); | 963 token = parsePrecedenceExpression(token.next, POSTFIX_PRECEDENCE); |
| 953 listener.handleUnaryPrefixExpression(operator); | 964 listener.handleUnaryPrefixExpression(operator); |
| 954 } else if ((value === '++') || value === '--') { | 965 } else if ((value === '++') || value === '--') { |
| 955 // TODO(ahe): Validate this is used correctly. | 966 // TODO(ahe): Validate this is used correctly. |
| 956 Token operator = token; | 967 Token operator = token; |
| 957 // Right associative, so we recurse at the same precedence | 968 // Right associative, so we recurse at the same precedence |
| 958 // level. | 969 // level. |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1604 } | 1615 } |
| 1605 listener.handleContinueStatement(hasTarget, continueKeyword, token); | 1616 listener.handleContinueStatement(hasTarget, continueKeyword, token); |
| 1606 return expectSemicolon(token); | 1617 return expectSemicolon(token); |
| 1607 } | 1618 } |
| 1608 | 1619 |
| 1609 Token parseEmptyStatement(Token token) { | 1620 Token parseEmptyStatement(Token token) { |
| 1610 listener.handleEmptyStatement(token); | 1621 listener.handleEmptyStatement(token); |
| 1611 return expectSemicolon(token); | 1622 return expectSemicolon(token); |
| 1612 } | 1623 } |
| 1613 } | 1624 } |
| OLD | NEW |