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 /** | 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 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 token = parseSend(token); | 930 token = parseSend(token); |
931 listener.handleBinaryExpression(cascadeOperator); | 931 listener.handleBinaryExpression(cascadeOperator); |
932 } else { | 932 } else { |
933 return listener.unexpected(token); | 933 return listener.unexpected(token); |
934 } | 934 } |
935 Token mark; | 935 Token mark; |
936 do { | 936 do { |
937 mark = token; | 937 mark = token; |
938 if (optional('.', token)) { | 938 if (optional('.', token)) { |
939 Token period = token; | 939 Token period = token; |
940 token = parseSend(period.token); | 940 token = parseSend(token); |
941 listener.handleBinaryExpression(period); | 941 listener.handleBinaryExpression(period); |
942 } | 942 } |
943 token = parseArgumentOrIndexStar(token); | 943 token = parseArgumentOrIndexStar(token); |
944 } while (mark !== token); | 944 } while (mark !== token); |
945 | 945 |
946 if (token.info.precedence === ASSIGNMENT_PRECEDENCE) { | 946 if (token.info.precedence === ASSIGNMENT_PRECEDENCE) { |
947 Token assignment = token; | 947 Token assignment = token; |
948 token = parsePrecedenceExpression(token.token, CASCADE_PRECEDENCE + 1); | 948 token = parsePrecedenceExpression(token, CASCADE_PRECEDENCE + 1); |
949 listener.handleAssignmentExpression(assignment); | 949 listener.handleAssignmentExpression(assignment); |
950 } | 950 } |
951 listener.endCascade(); | 951 listener.endCascade(); |
952 return token; | 952 return token; |
953 } | 953 } |
954 | 954 |
955 Token parseUnaryExpression(Token token) { | 955 Token parseUnaryExpression(Token token) { |
956 String value = token.stringValue; | 956 String value = token.stringValue; |
957 // Prefix: | 957 // Prefix: |
958 if (value === '+') { | 958 if (value === '+') { |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1550 Token label = null; | 1550 Token label = null; |
1551 // First an optional label. | 1551 // First an optional label. |
1552 if (isIdentifier(token)) { | 1552 if (isIdentifier(token)) { |
1553 label = token; | 1553 label = token; |
1554 token = parseIdentifier(token); | 1554 token = parseIdentifier(token); |
1555 token = expect(':', token); | 1555 token = expect(':', token); |
1556 } | 1556 } |
1557 // Then one or more case expressions, the last of which may be | 1557 // Then one or more case expressions, the last of which may be |
1558 // 'default' instead. | 1558 // 'default' instead. |
1559 int expressionCount = 0; | 1559 int expressionCount = 0; |
1560 String value = token.stringValue; | 1560 { |
1561 do { | 1561 String value = token.stringValue; |
1562 if (value === 'default') { | 1562 do { |
1563 defaultKeyword = token; | 1563 if (value === 'default') { |
1564 token = expect(':', token.next); | 1564 defaultKeyword = token; |
1565 break; | 1565 token = expect(':', token.next); |
1566 } | 1566 break; |
1567 token = expect('case', token); | 1567 } |
1568 token = parseExpression(token); | 1568 token = expect('case', token); |
1569 token = expect(':', token); | 1569 token = parseExpression(token); |
1570 expressionCount++; | 1570 token = expect(':', token); |
1571 value = token.stringValue; | 1571 expressionCount++; |
1572 } while (value === 'case' || value === 'default'); | 1572 value = token.stringValue; |
| 1573 } while (value === 'case' || value === 'default'); |
| 1574 } |
1573 // Finally zero or more statements. | 1575 // Finally zero or more statements. |
1574 int statementCount = 0; | 1576 int statementCount = 0; |
1575 while (token.kind !== EOF_TOKEN) { | 1577 while (token.kind !== EOF_TOKEN) { |
1576 String value; | 1578 String value; |
1577 if (isIdentifier(token) && optional(':', token.next)) { | 1579 if (isIdentifier(token) && optional(':', token.next)) { |
1578 // Skip label. | 1580 // Skip label. |
1579 value = token.next.next.stringValue; | 1581 value = token.next.next.stringValue; |
1580 } else { | 1582 } else { |
1581 value = token.stringValue; | 1583 value = token.stringValue; |
1582 } | 1584 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1616 } | 1618 } |
1617 listener.handleContinueStatement(hasTarget, continueKeyword, token); | 1619 listener.handleContinueStatement(hasTarget, continueKeyword, token); |
1618 return expectSemicolon(token); | 1620 return expectSemicolon(token); |
1619 } | 1621 } |
1620 | 1622 |
1621 Token parseEmptyStatement(Token token) { | 1623 Token parseEmptyStatement(Token token) { |
1622 listener.handleEmptyStatement(token); | 1624 listener.handleEmptyStatement(token); |
1623 return expectSemicolon(token); | 1625 return expectSemicolon(token); |
1624 } | 1626 } |
1625 } | 1627 } |
OLD | NEW |