| 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 (aka a token stream). | 7 * all tokens in a linked list (aka a token stream). |
| 8 * | 8 * |
| 9 * The class [Scanner] is used to generate a token stream. See the | 9 * The class [Scanner] is used to generate a token stream. See the |
| 10 * file scanner.dart. | 10 * file scanner.dart. |
| (...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 927 token = parseArgumentOrIndexStar(token); | 927 token = parseArgumentOrIndexStar(token); |
| 928 } else if ((info === PLUS_PLUS_INFO) || | 928 } else if ((info === PLUS_PLUS_INFO) || |
| 929 (info === MINUS_MINUS_INFO)) { | 929 (info === MINUS_MINUS_INFO)) { |
| 930 listener.handleUnaryPostfixAssignmentExpression(token); | 930 listener.handleUnaryPostfixAssignmentExpression(token); |
| 931 token = token.next; | 931 token = token.next; |
| 932 } else { | 932 } else { |
| 933 token = listener.unexpected(token); | 933 token = listener.unexpected(token); |
| 934 } | 934 } |
| 935 } else if (info === IS_INFO) { | 935 } else if (info === IS_INFO) { |
| 936 token = parseIsOperatorRest(token); | 936 token = parseIsOperatorRest(token); |
| 937 } else if (info === AS_INFO) { |
| 938 token = parseAsOperatorRest(token); |
| 937 } else if (info === QUESTION_INFO) { | 939 } else if (info === QUESTION_INFO) { |
| 938 token = parseConditionalExpressionRest(token); | 940 token = parseConditionalExpressionRest(token); |
| 939 } else { | 941 } else { |
| 940 // Left associative, so we recurse at the next higher | 942 // Left associative, so we recurse at the next higher |
| 941 // precedence level. | 943 // precedence level. |
| 942 token = parsePrecedenceExpression(token.next, level + 1, | 944 token = parsePrecedenceExpression(token.next, level + 1, |
| 943 withoutCascades); | 945 withoutCascades); |
| 944 listener.handleBinaryExpression(operator); | 946 listener.handleBinaryExpression(operator); |
| 945 } | 947 } |
| 946 info = token.info; | 948 info = token.info; |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1369 Token parseIsOperatorRest(Token token) { | 1371 Token parseIsOperatorRest(Token token) { |
| 1370 assert(optional('is', token)); | 1372 assert(optional('is', token)); |
| 1371 Token operator = token; | 1373 Token operator = token; |
| 1372 Token not = null; | 1374 Token not = null; |
| 1373 if (optional('!', token.next)) { | 1375 if (optional('!', token.next)) { |
| 1374 token = token.next; | 1376 token = token.next; |
| 1375 not = token; | 1377 not = token; |
| 1376 } | 1378 } |
| 1377 token = parseType(token.next); | 1379 token = parseType(token.next); |
| 1378 listener.handleIsOperator(operator, not, token); | 1380 listener.handleIsOperator(operator, not, token); |
| 1379 if (optional('is', token)) { | 1381 String value = token.stringValue; |
| 1380 // The is-operator cannot be chained, but it can take part of | 1382 if (value === 'is' || value === 'as') { |
| 1383 // The is- and as-operators cannot be chained, but they can take part of |
| 1381 // expressions like: foo is Foo || foo is Bar. | 1384 // expressions like: foo is Foo || foo is Bar. |
| 1382 listener.unexpected(token); | 1385 listener.unexpected(token); |
| 1383 } | 1386 } |
| 1384 return token; | 1387 return token; |
| 1385 } | 1388 } |
| 1386 | 1389 |
| 1390 Token parseAsOperatorRest(Token token) { |
| 1391 assert(optional('as', token)); |
| 1392 Token operator = token; |
| 1393 token = parseType(token.next); |
| 1394 listener.handleAsOperator(operator, token); |
| 1395 String value = token.stringValue; |
| 1396 if (value === 'is' || value === 'as') { |
| 1397 // The is- and as-operators cannot be chained. |
| 1398 listener.unexpected(token); |
| 1399 } |
| 1400 return token; |
| 1401 } |
| 1402 |
| 1387 Token parseVariablesDeclaration(Token token) { | 1403 Token parseVariablesDeclaration(Token token) { |
| 1388 token = parseVariablesDeclarationNoSemicolon(token); | 1404 token = parseVariablesDeclarationNoSemicolon(token); |
| 1389 return expectSemicolon(token); | 1405 return expectSemicolon(token); |
| 1390 } | 1406 } |
| 1391 | 1407 |
| 1392 Token parseVariablesDeclarationNoSemicolon(Token token) { | 1408 Token parseVariablesDeclarationNoSemicolon(Token token) { |
| 1393 int count = 1; | 1409 int count = 1; |
| 1394 listener.beginVariablesDeclaration(token); | 1410 listener.beginVariablesDeclaration(token); |
| 1395 token = parseModifiers(token); | 1411 token = parseModifiers(token); |
| 1396 token = parseTypeOpt(token); | 1412 token = parseTypeOpt(token); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1691 } | 1707 } |
| 1692 listener.handleContinueStatement(hasTarget, continueKeyword, token); | 1708 listener.handleContinueStatement(hasTarget, continueKeyword, token); |
| 1693 return expectSemicolon(token); | 1709 return expectSemicolon(token); |
| 1694 } | 1710 } |
| 1695 | 1711 |
| 1696 Token parseEmptyStatement(Token token) { | 1712 Token parseEmptyStatement(Token token) { |
| 1697 listener.handleEmptyStatement(token); | 1713 listener.handleEmptyStatement(token); |
| 1698 return expectSemicolon(token); | 1714 return expectSemicolon(token); |
| 1699 } | 1715 } |
| 1700 } | 1716 } |
| OLD | NEW |