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 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
924 token = parseArgumentOrIndexStar(token); | 924 token = parseArgumentOrIndexStar(token); |
925 } else if ((info === PLUS_PLUS_INFO) || | 925 } else if ((info === PLUS_PLUS_INFO) || |
926 (info === MINUS_MINUS_INFO)) { | 926 (info === MINUS_MINUS_INFO)) { |
927 listener.handleUnaryPostfixAssignmentExpression(token); | 927 listener.handleUnaryPostfixAssignmentExpression(token); |
928 token = token.next; | 928 token = token.next; |
929 } else { | 929 } else { |
930 token = listener.unexpected(token); | 930 token = listener.unexpected(token); |
931 } | 931 } |
932 } else if (info === IS_INFO) { | 932 } else if (info === IS_INFO) { |
933 token = parseIsOperatorRest(token); | 933 token = parseIsOperatorRest(token); |
934 } else if (info === AS_INFO) { | |
935 token = parseAsOperatorRest(token); | |
934 } else if (info === QUESTION_INFO) { | 936 } else if (info === QUESTION_INFO) { |
935 token = parseConditionalExpressionRest(token); | 937 token = parseConditionalExpressionRest(token); |
936 } else { | 938 } else { |
937 // Left associative, so we recurse at the next higher | 939 // Left associative, so we recurse at the next higher |
938 // precedence level. | 940 // precedence level. |
939 token = parsePrecedenceExpression(token.next, level + 1, | 941 token = parsePrecedenceExpression(token.next, level + 1, |
940 withoutCascades); | 942 withoutCascades); |
941 listener.handleBinaryExpression(operator); | 943 listener.handleBinaryExpression(operator); |
942 } | 944 } |
943 info = token.info; | 945 info = token.info; |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1350 Token parseIsOperatorRest(Token token) { | 1352 Token parseIsOperatorRest(Token token) { |
1351 assert(optional('is', token)); | 1353 assert(optional('is', token)); |
1352 Token operator = token; | 1354 Token operator = token; |
1353 Token not = null; | 1355 Token not = null; |
1354 if (optional('!', token.next)) { | 1356 if (optional('!', token.next)) { |
1355 token = token.next; | 1357 token = token.next; |
1356 not = token; | 1358 not = token; |
1357 } | 1359 } |
1358 token = parseType(token.next); | 1360 token = parseType(token.next); |
1359 listener.handleIsOperator(operator, not, token); | 1361 listener.handleIsOperator(operator, not, token); |
1360 if (optional('is', token)) { | 1362 if (optional('is', token) || optional('as', token)) { |
ahe
2012/06/25 10:36:56
Please put stringValue in a local variable instead
Lasse Reichstein Nielsen
2012/06/25 11:20:06
Done.
| |
1361 // The is-operator cannot be chained, but it can take part of | 1363 // The is- and as-operators cannot be chained, but they can take part of |
1362 // expressions like: foo is Foo || foo is Bar. | 1364 // expressions like: foo is Foo || foo is Bar. |
1363 listener.unexpected(token); | 1365 listener.unexpected(token); |
1364 } | 1366 } |
1365 return token; | 1367 return token; |
1366 } | 1368 } |
1367 | 1369 |
1370 Token parseAsOperatorRest(Token token) { | |
1371 assert(optional('as', token)); | |
1372 Token operator = token; | |
1373 token = parseType(token.next); | |
1374 listener.handleAsOperator(operator, token); | |
1375 if (optional('is', token) || optional('as', token)) { | |
ahe
2012/06/25 10:36:56
Ditto.
Lasse Reichstein Nielsen
2012/06/25 11:20:06
Done.
| |
1376 // The is- and as-operators cannot be chained. | |
1377 listener.unexpected(token); | |
1378 } | |
1379 return token; | |
1380 } | |
1381 | |
1368 Token parseVariablesDeclaration(Token token) { | 1382 Token parseVariablesDeclaration(Token token) { |
1369 token = parseVariablesDeclarationNoSemicolon(token); | 1383 token = parseVariablesDeclarationNoSemicolon(token); |
1370 return expectSemicolon(token); | 1384 return expectSemicolon(token); |
1371 } | 1385 } |
1372 | 1386 |
1373 Token parseVariablesDeclarationNoSemicolon(Token token) { | 1387 Token parseVariablesDeclarationNoSemicolon(Token token) { |
1374 int count = 1; | 1388 int count = 1; |
1375 listener.beginVariablesDeclaration(token); | 1389 listener.beginVariablesDeclaration(token); |
1376 token = parseModifiers(token); | 1390 token = parseModifiers(token); |
1377 token = parseTypeOpt(token); | 1391 token = parseTypeOpt(token); |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1672 } | 1686 } |
1673 listener.handleContinueStatement(hasTarget, continueKeyword, token); | 1687 listener.handleContinueStatement(hasTarget, continueKeyword, token); |
1674 return expectSemicolon(token); | 1688 return expectSemicolon(token); |
1675 } | 1689 } |
1676 | 1690 |
1677 Token parseEmptyStatement(Token token) { | 1691 Token parseEmptyStatement(Token token) { |
1678 listener.handleEmptyStatement(token); | 1692 listener.handleEmptyStatement(token); |
1679 return expectSemicolon(token); | 1693 return expectSemicolon(token); |
1680 } | 1694 } |
1681 } | 1695 } |
OLD | NEW |