Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/scanner/parser.dart

Issue 23450044: Update dart2js parser to disallow repeated comparisons and prefix +. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/scanner/token.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 part of scanner; 5 part of scanner;
6 6
7 class FormalParameterType { 7 class FormalParameterType {
8 final String type; 8 final String type;
9 const FormalParameterType(this.type); 9 const FormalParameterType(this.type);
10 bool get isRequired => this == REQUIRED; 10 bool get isRequired => this == REQUIRED;
(...skipping 1563 matching lines...) Expand 10 before | Expand all | Expand 10 after
1574 token = parseConditionalExpressionRest(token); 1574 token = parseConditionalExpressionRest(token);
1575 } else { 1575 } else {
1576 // Left associative, so we recurse at the next higher 1576 // Left associative, so we recurse at the next higher
1577 // precedence level. 1577 // precedence level.
1578 token = parsePrecedenceExpression(token.next, level + 1, 1578 token = parsePrecedenceExpression(token.next, level + 1,
1579 allowCascades); 1579 allowCascades);
1580 listener.handleBinaryExpression(operator); 1580 listener.handleBinaryExpression(operator);
1581 } 1581 }
1582 info = token.info; 1582 info = token.info;
1583 tokenLevel = info.precedence; 1583 tokenLevel = info.precedence;
1584 if (level == EQUALITY_PRECEDENCE || level == RELATIONAL_PRECEDENCE) {
1585 // We don't allow (a == b == c) or (a < b < c).
1586 // Continue the outer loop if we have matched one equality or
1587 // relational operator.
1588 break;
1589 }
1584 } 1590 }
1585 } 1591 }
1586 return token; 1592 return token;
1587 } 1593 }
1588 1594
1589 Token parseCascadeExpression(Token token) { 1595 Token parseCascadeExpression(Token token) {
1590 listener.beginCascade(token); 1596 listener.beginCascade(token);
1591 assert(optional('..', token)); 1597 assert(optional('..', token));
1592 Token cascadeOperator = token; 1598 Token cascadeOperator = token;
1593 token = token.next; 1599 token = token.next;
(...skipping 21 matching lines...) Expand all
1615 token = parseExpressionWithoutCascade(token.next); 1621 token = parseExpressionWithoutCascade(token.next);
1616 listener.handleAssignmentExpression(assignment); 1622 listener.handleAssignmentExpression(assignment);
1617 } 1623 }
1618 listener.endCascade(); 1624 listener.endCascade();
1619 return token; 1625 return token;
1620 } 1626 }
1621 1627
1622 Token parseUnaryExpression(Token token, bool allowCascades) { 1628 Token parseUnaryExpression(Token token, bool allowCascades) {
1623 String value = token.stringValue; 1629 String value = token.stringValue;
1624 // Prefix: 1630 // Prefix:
1625 if (identical(value, '+')) { 1631 if ((identical(value, '!')) ||
1626 // Dart only allows "prefix plus" as an initial part of a
1627 // decimal literal. We scan it as a separate token and let
1628 // the parser listener combine it with the digits.
1629 Token next = token.next;
1630 if (identical(next.charOffset, token.charOffset + 1)) {
1631 if (identical(next.kind, INT_TOKEN)) {
1632 listener.handleLiteralInt(token);
1633 return next.next;
1634 }
1635 if (identical(next.kind, DOUBLE_TOKEN)) {
1636 listener.handleLiteralDouble(token);
1637 return next.next;
1638 }
1639 }
1640 listener.recoverableError("Unexpected token '+'", token: token);
1641 return parsePrecedenceExpression(next, POSTFIX_PRECEDENCE,
1642 allowCascades);
Lasse Reichstein Nielsen 2013/09/18 13:41:19 WOuld it be better to keep the 'if' and the last t
ahe 2013/09/18 13:42:59 Yes. And it would be even better if you replace li
1643 } else if ((identical(value, '!')) ||
1644 (identical(value, '-')) || 1632 (identical(value, '-')) ||
1645 (identical(value, '~'))) { 1633 (identical(value, '~'))) {
1646 Token operator = token; 1634 Token operator = token;
1647 // Right associative, so we recurse at the same precedence 1635 // Right associative, so we recurse at the same precedence
1648 // level. 1636 // level.
1649 token = parsePrecedenceExpression(token.next, POSTFIX_PRECEDENCE, 1637 token = parsePrecedenceExpression(token.next, POSTFIX_PRECEDENCE,
1650 allowCascades); 1638 allowCascades);
1651 listener.handleUnaryPrefixExpression(operator); 1639 listener.handleUnaryPrefixExpression(operator);
1652 } else if ((identical(value, '++')) || identical(value, '--')) { 1640 } else if ((identical(value, '++')) || identical(value, '--')) {
1653 // TODO(ahe): Validate this is used correctly. 1641 // TODO(ahe): Validate this is used correctly.
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
2401 } 2389 }
2402 listener.handleContinueStatement(hasTarget, continueKeyword, token); 2390 listener.handleContinueStatement(hasTarget, continueKeyword, token);
2403 return expectSemicolon(token); 2391 return expectSemicolon(token);
2404 } 2392 }
2405 2393
2406 Token parseEmptyStatement(Token token) { 2394 Token parseEmptyStatement(Token token) {
2407 listener.handleEmptyStatement(token); 2395 listener.handleEmptyStatement(token);
2408 return expectSemicolon(token); 2396 return expectSemicolon(token);
2409 } 2397 }
2410 } 2398 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/scanner/token.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698