| OLD | NEW |
| 1 // This code was auto-generated, is not intended to be edited, and is subject to | 1 // This code was auto-generated, is not intended to be edited, and is subject to |
| 2 // significant change. Please see the README file for more information. | 2 // significant change. Please see the README file for more information. |
| 3 | 3 |
| 4 library engine.parser; | 4 library engine.parser; |
| 5 | 5 |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 import 'java_core.dart'; | 7 import 'java_core.dart'; |
| 8 import 'java_engine.dart'; | 8 import 'java_engine.dart'; |
| 9 import 'instrumentation.dart'; | 9 import 'instrumentation.dart'; |
| 10 import 'error.dart'; | 10 import 'error.dart'; |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 */ | 424 */ |
| 425 Token createSyntheticToken2(TokenType type) => new StringToken(type, "", _curr
entToken.offset); | 425 Token createSyntheticToken2(TokenType type) => new StringToken(type, "", _curr
entToken.offset); |
| 426 /** | 426 /** |
| 427 * Check that the given expression is assignable and report an error if it isn
't. | 427 * Check that the given expression is assignable and report an error if it isn
't. |
| 428 * <pre> | 428 * <pre> |
| 429 * assignableExpression ::= | 429 * assignableExpression ::= |
| 430 * primary (arguments* assignableSelector)+ | 430 * primary (arguments* assignableSelector)+ |
| 431 * | 'super' assignableSelector | 431 * | 'super' assignableSelector |
| 432 * | identifier | 432 * | identifier |
| 433 * assignableSelector ::= | 433 * assignableSelector ::= |
| 434 * '[' expression ']' | 434 * '[[' expression ']]' |
| 435 * | '.' identifier | 435 * | '.' identifier |
| 436 * </pre> | 436 * </pre> |
| 437 * @param expression the expression being checked | 437 * @param expression the expression being checked |
| 438 */ | 438 */ |
| 439 void ensureAssignable(Expression expression) { | 439 void ensureAssignable(Expression expression) { |
| 440 if (expression != null && !expression.isAssignable()) { | 440 if (expression != null && !expression.isAssignable()) { |
| 441 reportError4(ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE, []); | 441 reportError4(ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE, []); |
| 442 } | 442 } |
| 443 } | 443 } |
| 444 /** | 444 /** |
| (...skipping 20 matching lines...) Expand all Loading... |
| 465 return andAdvance; | 465 return andAdvance; |
| 466 } | 466 } |
| 467 if (identical(type, TokenType.SEMICOLON)) { | 467 if (identical(type, TokenType.SEMICOLON)) { |
| 468 reportError5(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [type
.lexeme]); | 468 reportError5(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [type
.lexeme]); |
| 469 } else { | 469 } else { |
| 470 reportError4(ParserErrorCode.EXPECTED_TOKEN, [type.lexeme]); | 470 reportError4(ParserErrorCode.EXPECTED_TOKEN, [type.lexeme]); |
| 471 } | 471 } |
| 472 return _currentToken; | 472 return _currentToken; |
| 473 } | 473 } |
| 474 /** | 474 /** |
| 475 * Search the given list of ranges for a range that contains the given index.
Return the range |
| 476 * that was found, or {@code null} if none of the ranges contain the index. |
| 477 * @param ranges the ranges to be searched |
| 478 * @param index the index contained in the returned range |
| 479 * @return the range that was found |
| 480 */ |
| 481 List<int> findRange(List<List<int>> ranges, int index) { |
| 482 for (List<int> range in ranges) { |
| 483 if (range[0] <= index && index <= range[1]) { |
| 484 return range; |
| 485 } else if (index < range[0]) { |
| 486 return null; |
| 487 } |
| 488 } |
| 489 return null; |
| 490 } |
| 491 /** |
| 475 * Advance to the next token in the token stream, making it the new current to
ken. | 492 * Advance to the next token in the token stream, making it the new current to
ken. |
| 476 * @return the token that was current before this method was invoked | 493 * @return the token that was current before this method was invoked |
| 477 */ | 494 */ |
| 478 Token get andAdvance { | 495 Token get andAdvance { |
| 479 Token token = _currentToken; | 496 Token token = _currentToken; |
| 480 advance(); | 497 advance(); |
| 481 return token; | 498 return token; |
| 482 } | 499 } |
| 483 /** | 500 /** |
| 501 * Return a list of the ranges of characters in the given comment string that
should be treated as |
| 502 * code blocks. |
| 503 * @param comment the comment being processed |
| 504 * @return the ranges of characters that should be treated as code blocks |
| 505 */ |
| 506 List<List<int>> getCodeBlockRanges(String comment) { |
| 507 List<List<int>> ranges = new List<List<int>>(); |
| 508 int length2 = comment.length; |
| 509 int index = 0; |
| 510 if (comment.startsWith("/**") || comment.startsWith("///")) { |
| 511 index = 3; |
| 512 } |
| 513 while (index < length2) { |
| 514 int currentChar = comment.codeUnitAt(index); |
| 515 if (currentChar == 0xD || currentChar == 0xA) { |
| 516 index = index + 1; |
| 517 while (index < length2 && Character.isWhitespace(comment.codeUnitAt(inde
x))) { |
| 518 index = index + 1; |
| 519 } |
| 520 if (JavaString.startsWithBefore(comment, "* ", index)) { |
| 521 int end = index + 6; |
| 522 while (end < length2 && comment.codeUnitAt(end) != 0xD && comment.code
UnitAt(end) != 0xA) { |
| 523 end = end + 1; |
| 524 } |
| 525 ranges.add(<int> [index, end]); |
| 526 index = end; |
| 527 } |
| 528 } else if (JavaString.startsWithBefore(comment, "[:", index)) { |
| 529 int end = comment.indexOf(":]", index + 2); |
| 530 if (end < 0) { |
| 531 end = length2; |
| 532 } |
| 533 ranges.add(<int> [index, end]); |
| 534 index = end + 1; |
| 535 } else { |
| 536 index = index + 1; |
| 537 } |
| 538 } |
| 539 return ranges; |
| 540 } |
| 541 /** |
| 484 * Return {@code true} if the current token is the first token of a return typ
e that is followed | 542 * Return {@code true} if the current token is the first token of a return typ
e that is followed |
| 485 * by an identifier, possibly followed by a list of type parameters, followed
by a | 543 * by an identifier, possibly followed by a list of type parameters, followed
by a |
| 486 * left-parenthesis. This is used by parseTypeAlias to determine whether or no
t to parse a return | 544 * left-parenthesis. This is used by parseTypeAlias to determine whether or no
t to parse a return |
| 487 * type. | 545 * type. |
| 488 * @return {@code true} if we can successfully parse the rest of a type alias
if we first parse a | 546 * @return {@code true} if we can successfully parse the rest of a type alias
if we first parse a |
| 489 * return type. | 547 * return type. |
| 490 */ | 548 */ |
| 491 bool hasReturnTypeInTypeAlias() { | 549 bool hasReturnTypeInTypeAlias() { |
| 492 Token next = skipReturnType(_currentToken); | 550 Token next = skipReturnType(_currentToken); |
| 493 if (next == null) { | 551 if (next == null) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 return false; | 623 return false; |
| 566 } | 624 } |
| 567 token = skipSimpleIdentifier(token); | 625 token = skipSimpleIdentifier(token); |
| 568 if (token == null) { | 626 if (token == null) { |
| 569 return false; | 627 return false; |
| 570 } | 628 } |
| 571 TokenType type2 = token.type; | 629 TokenType type2 = token.type; |
| 572 return identical(type2, TokenType.EQ) || identical(type2, TokenType.COMMA) |
| identical(type2, TokenType.SEMICOLON) || matches3(token, Keyword.IN); | 630 return identical(type2, TokenType.EQ) || identical(type2, TokenType.COMMA) |
| identical(type2, TokenType.SEMICOLON) || matches3(token, Keyword.IN); |
| 573 } | 631 } |
| 574 /** | 632 /** |
| 633 * Given that we have just found bracketed text within a comment, look to see
whether that text is |
| 634 * (a) followed by a parenthesized link address, (b) followed by a colon, or (
c) followed by |
| 635 * optional whitespace and another square bracket. |
| 636 * <p> |
| 637 * This method uses the syntax described by the <a |
| 638 * href="http://daringfireball.net/projects/markdown/syntax">markdown</a> proj
ect. |
| 639 * @param comment the comment text in which the bracketed text was found |
| 640 * @param rightIndex the index of the right bracket |
| 641 * @return {@code true} if the bracketed text is followed by a link address |
| 642 */ |
| 643 bool isLinkText(String comment, int rightIndex) { |
| 644 int length2 = comment.length; |
| 645 int index = rightIndex + 1; |
| 646 if (index >= length2) { |
| 647 return false; |
| 648 } |
| 649 int nextChar = comment.codeUnitAt(index); |
| 650 if (nextChar == 0x28 || nextChar == 0x3A) { |
| 651 return true; |
| 652 } |
| 653 while (Character.isWhitespace(nextChar)) { |
| 654 index = index + 1; |
| 655 if (index >= length2) { |
| 656 return false; |
| 657 } |
| 658 nextChar = comment.codeUnitAt(index); |
| 659 } |
| 660 return nextChar == 0x5B; |
| 661 } |
| 662 /** |
| 575 * Return {@code true} if the given token appears to be the beginning of an op
erator declaration. | 663 * Return {@code true} if the given token appears to be the beginning of an op
erator declaration. |
| 576 * @param startToken the token that might be the start of an operator declarat
ion | 664 * @param startToken the token that might be the start of an operator declarat
ion |
| 577 * @return {@code true} if the given token appears to be the beginning of an o
perator declaration | 665 * @return {@code true} if the given token appears to be the beginning of an o
perator declaration |
| 578 */ | 666 */ |
| 579 bool isOperator(Token startToken) { | 667 bool isOperator(Token startToken) { |
| 580 if (startToken.isOperator()) { | 668 if (startToken.isOperator()) { |
| 581 Token token = startToken.next; | 669 Token token = startToken.next; |
| 582 while (token.isOperator()) { | 670 while (token.isOperator()) { |
| 583 token = token.next; | 671 token = token.next; |
| 584 } | 672 } |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 return expression; | 997 return expression; |
| 910 } | 998 } |
| 911 expression = selectorExpression; | 999 expression = selectorExpression; |
| 912 isOptional = true; | 1000 isOptional = true; |
| 913 } | 1001 } |
| 914 } | 1002 } |
| 915 /** | 1003 /** |
| 916 * Parse an assignable selector. | 1004 * Parse an assignable selector. |
| 917 * <pre> | 1005 * <pre> |
| 918 * assignableSelector ::= | 1006 * assignableSelector ::= |
| 919 * '[' expression ']' | 1007 * '[[' expression ']]' |
| 920 * | '.' identifier | 1008 * | '.' identifier |
| 921 * </pre> | 1009 * </pre> |
| 922 * @param prefix the expression preceding the selector | 1010 * @param prefix the expression preceding the selector |
| 923 * @param optional {@code true} if the selector is optional | 1011 * @param optional {@code true} if the selector is optional |
| 924 * @return the assignable selector that was parsed | 1012 * @return the assignable selector that was parsed |
| 925 */ | 1013 */ |
| 926 Expression parseAssignableSelector(Expression prefix, bool optional) { | 1014 Expression parseAssignableSelector(Expression prefix, bool optional) { |
| 927 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) { | 1015 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) { |
| 928 Token leftBracket = andAdvance; | 1016 Token leftBracket = andAdvance; |
| 929 Expression index = parseExpression2(); | 1017 Expression index = parseExpression2(); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1050 } | 1138 } |
| 1051 Token semicolon = expect2(TokenType.SEMICOLON); | 1139 Token semicolon = expect2(TokenType.SEMICOLON); |
| 1052 return new BreakStatement.full(breakKeyword, label, semicolon); | 1140 return new BreakStatement.full(breakKeyword, label, semicolon); |
| 1053 } | 1141 } |
| 1054 /** | 1142 /** |
| 1055 * Parse a cascade section. | 1143 * Parse a cascade section. |
| 1056 * <pre> | 1144 * <pre> |
| 1057 * cascadeSection ::= | 1145 * cascadeSection ::= |
| 1058 * '..' (cascadeSelector arguments*) (assignableSelector arguments*)* cascadeA
ssignment? | 1146 * '..' (cascadeSelector arguments*) (assignableSelector arguments*)* cascadeA
ssignment? |
| 1059 * cascadeSelector ::= | 1147 * cascadeSelector ::= |
| 1060 * '[' expression ']' | 1148 * '[[' expression ']]' |
| 1061 * | identifier | 1149 * | identifier |
| 1062 * cascadeAssignment ::= | 1150 * cascadeAssignment ::= |
| 1063 * assignmentOperator expressionWithoutCascade | 1151 * assignmentOperator expressionWithoutCascade |
| 1064 * </pre> | 1152 * </pre> |
| 1065 * @return the expression representing the cascaded method invocation | 1153 * @return the expression representing the cascaded method invocation |
| 1066 */ | 1154 */ |
| 1067 Expression parseCascadeSection() { | 1155 Expression parseCascadeSection() { |
| 1068 Token period = expect2(TokenType.PERIOD_PERIOD); | 1156 Token period = expect2(TokenType.PERIOD_PERIOD); |
| 1069 Expression expression = null; | 1157 Expression expression = null; |
| 1070 SimpleIdentifier functionName = null; | 1158 SimpleIdentifier functionName = null; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 reportError5(ParserErrorCode.MULTIPLE_IMPLEMENTS_CLAUSES, implementsCl
ause.keyword, []); | 1256 reportError5(ParserErrorCode.MULTIPLE_IMPLEMENTS_CLAUSES, implementsCl
ause.keyword, []); |
| 1169 parseImplementsClause(); | 1257 parseImplementsClause(); |
| 1170 } | 1258 } |
| 1171 } else { | 1259 } else { |
| 1172 foundClause = false; | 1260 foundClause = false; |
| 1173 } | 1261 } |
| 1174 } | 1262 } |
| 1175 if (withClause != null && extendsClause == null) { | 1263 if (withClause != null && extendsClause == null) { |
| 1176 reportError5(ParserErrorCode.WITH_WITHOUT_EXTENDS, withClause.withKeyword,
[]); | 1264 reportError5(ParserErrorCode.WITH_WITHOUT_EXTENDS, withClause.withKeyword,
[]); |
| 1177 } | 1265 } |
| 1266 if (matches2(_NATIVE) && matches4(peek(), TokenType.STRING)) { |
| 1267 advance(); |
| 1268 advance(); |
| 1269 } |
| 1178 Token leftBracket = null; | 1270 Token leftBracket = null; |
| 1179 List<ClassMember> members = null; | 1271 List<ClassMember> members = null; |
| 1180 Token rightBracket = null; | 1272 Token rightBracket = null; |
| 1181 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { | 1273 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { |
| 1182 leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); | 1274 leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); |
| 1183 members = parseClassMembers(className, ((leftBracket as BeginToken)).endTo
ken != null); | 1275 members = parseClassMembers(className, ((leftBracket as BeginToken)).endTo
ken != null); |
| 1184 rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); | 1276 rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); |
| 1185 } else { | 1277 } else { |
| 1186 leftBracket = createSyntheticToken2(TokenType.OPEN_CURLY_BRACKET); | 1278 leftBracket = createSyntheticToken2(TokenType.OPEN_CURLY_BRACKET); |
| 1187 rightBracket = createSyntheticToken2(TokenType.CLOSE_CURLY_BRACKET); | 1279 rightBracket = createSyntheticToken2(TokenType.CLOSE_CURLY_BRACKET); |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1412 CommentReference parseCommentReference(String referenceSource, int sourceOffse
t) { | 1504 CommentReference parseCommentReference(String referenceSource, int sourceOffse
t) { |
| 1413 if (referenceSource.length == 0) { | 1505 if (referenceSource.length == 0) { |
| 1414 return null; | 1506 return null; |
| 1415 } | 1507 } |
| 1416 try { | 1508 try { |
| 1417 List<bool> errorFound = [false]; | 1509 List<bool> errorFound = [false]; |
| 1418 AnalysisErrorListener listener = new AnalysisErrorListener_12(errorFound); | 1510 AnalysisErrorListener listener = new AnalysisErrorListener_12(errorFound); |
| 1419 StringScanner scanner = new StringScanner(null, referenceSource, listener)
; | 1511 StringScanner scanner = new StringScanner(null, referenceSource, listener)
; |
| 1420 scanner.setSourceStart(1, 1, sourceOffset); | 1512 scanner.setSourceStart(1, 1, sourceOffset); |
| 1421 Token firstToken = scanner.tokenize(); | 1513 Token firstToken = scanner.tokenize(); |
| 1422 if (!errorFound[0]) { | 1514 if (errorFound[0]) { |
| 1423 Token newKeyword = null; | 1515 return null; |
| 1424 if (matches3(firstToken, Keyword.NEW)) { | 1516 } |
| 1425 newKeyword = firstToken; | 1517 Token newKeyword = null; |
| 1426 firstToken = firstToken.next; | 1518 if (matches3(firstToken, Keyword.NEW)) { |
| 1519 newKeyword = firstToken; |
| 1520 firstToken = firstToken.next; |
| 1521 } |
| 1522 if (matchesIdentifier2(firstToken)) { |
| 1523 Token secondToken = firstToken.next; |
| 1524 Token thirdToken = secondToken.next; |
| 1525 Token nextToken; |
| 1526 Identifier identifier; |
| 1527 if (matches4(secondToken, TokenType.PERIOD) && matchesIdentifier2(thirdT
oken)) { |
| 1528 identifier = new PrefixedIdentifier.full(new SimpleIdentifier.full(fir
stToken), secondToken, new SimpleIdentifier.full(thirdToken)); |
| 1529 nextToken = thirdToken.next; |
| 1530 } else { |
| 1531 identifier = new SimpleIdentifier.full(firstToken); |
| 1532 nextToken = firstToken.next; |
| 1427 } | 1533 } |
| 1428 if (matchesIdentifier2(firstToken)) { | 1534 if (nextToken.type != TokenType.EOF) { |
| 1429 Token secondToken = firstToken.next; | |
| 1430 Token thirdToken = secondToken.next; | |
| 1431 Token nextToken; | |
| 1432 Identifier identifier; | |
| 1433 if (matches4(secondToken, TokenType.PERIOD) && matchesIdentifier2(thir
dToken)) { | |
| 1434 identifier = new PrefixedIdentifier.full(new SimpleIdentifier.full(f
irstToken), secondToken, new SimpleIdentifier.full(thirdToken)); | |
| 1435 nextToken = thirdToken.next; | |
| 1436 } else { | |
| 1437 identifier = new SimpleIdentifier.full(firstToken); | |
| 1438 nextToken = firstToken.next; | |
| 1439 } | |
| 1440 if (nextToken.type != TokenType.EOF) { | |
| 1441 } | |
| 1442 return new CommentReference.full(newKeyword, identifier); | |
| 1443 } else if (matches3(firstToken, Keyword.THIS) || matches3(firstToken, Ke
yword.NULL) || matches3(firstToken, Keyword.TRUE) || matches3(firstToken, Keywor
d.FALSE)) { | |
| 1444 return null; | 1535 return null; |
| 1445 } else if (matches4(firstToken, TokenType.STRING)) { | |
| 1446 } else { | |
| 1447 } | 1536 } |
| 1537 return new CommentReference.full(newKeyword, identifier); |
| 1538 } else if (matches3(firstToken, Keyword.THIS) || matches3(firstToken, Keyw
ord.NULL) || matches3(firstToken, Keyword.TRUE) || matches3(firstToken, Keyword.
FALSE)) { |
| 1539 return null; |
| 1448 } | 1540 } |
| 1449 } catch (exception) { | 1541 } catch (exception) { |
| 1450 } | 1542 } |
| 1451 return null; | 1543 return null; |
| 1452 } | 1544 } |
| 1453 /** | 1545 /** |
| 1454 * Parse all of the comment references occurring in the given array of documen
tation comments. | 1546 * Parse all of the comment references occurring in the given array of documen
tation comments. |
| 1455 * <pre> | 1547 * <pre> |
| 1456 * commentReference ::= | 1548 * commentReference ::= |
| 1457 * '[' 'new'? qualified ']' libraryReference? | 1549 * '[[' 'new'? qualified ']]' libraryReference? |
| 1458 * libraryReference ::= | 1550 * libraryReference ::= |
| 1459 * '(' stringLiteral ')' | 1551 * '(' stringLiteral ')' |
| 1460 * </pre> | 1552 * </pre> |
| 1461 * @param tokens the comment tokens representing the documentation comments to
be parsed | 1553 * @param tokens the comment tokens representing the documentation comments to
be parsed |
| 1462 * @return the comment references that were parsed | 1554 * @return the comment references that were parsed |
| 1463 */ | 1555 */ |
| 1464 List<CommentReference> parseCommentReferences(List<Token> tokens) { | 1556 List<CommentReference> parseCommentReferences(List<Token> tokens) { |
| 1465 List<CommentReference> references = new List<CommentReference>(); | 1557 List<CommentReference> references = new List<CommentReference>(); |
| 1466 for (Token token in tokens) { | 1558 for (Token token in tokens) { |
| 1467 String comment = token.lexeme; | 1559 String comment = token.lexeme; |
| 1560 int length2 = comment.length; |
| 1561 List<List<int>> codeBlockRanges = getCodeBlockRanges(comment); |
| 1468 int leftIndex = comment.indexOf('['); | 1562 int leftIndex = comment.indexOf('['); |
| 1469 while (leftIndex >= 0) { | 1563 while (leftIndex >= 0 && leftIndex + 1 < length2) { |
| 1470 int rightIndex = comment.indexOf(']', leftIndex); | 1564 List<int> range = findRange(codeBlockRanges, leftIndex); |
| 1471 if (rightIndex >= 0) { | 1565 if (range == null) { |
| 1472 int firstChar = comment.codeUnitAt(leftIndex + 1); | 1566 int rightIndex = comment.indexOf(']', leftIndex); |
| 1473 if (firstChar != 0x27 && firstChar != 0x22 && firstChar != 0x3A) { | 1567 if (rightIndex >= 0) { |
| 1474 CommentReference reference = parseCommentReference(comment.substring
(leftIndex + 1, rightIndex), token.offset + leftIndex + 1); | 1568 int firstChar = comment.codeUnitAt(leftIndex + 1); |
| 1475 if (reference != null) { | 1569 if (firstChar != 0x27 && firstChar != 0x22) { |
| 1476 references.add(reference); | 1570 if (isLinkText(comment, rightIndex)) { |
| 1571 } else { |
| 1572 CommentReference reference = parseCommentReference(comment.subst
ring(leftIndex + 1, rightIndex), token.offset + leftIndex + 1); |
| 1573 if (reference != null) { |
| 1574 references.add(reference); |
| 1575 } |
| 1576 } |
| 1477 } | 1577 } |
| 1578 } else { |
| 1579 rightIndex = leftIndex + 1; |
| 1478 } | 1580 } |
| 1581 leftIndex = comment.indexOf('[', rightIndex); |
| 1479 } else { | 1582 } else { |
| 1480 rightIndex = leftIndex + 1; | 1583 leftIndex = comment.indexOf('[', range[1] + 1); |
| 1481 } | 1584 } |
| 1482 leftIndex = comment.indexOf('[', rightIndex); | |
| 1483 } | 1585 } |
| 1484 } | 1586 } |
| 1485 return references; | 1587 return references; |
| 1486 } | 1588 } |
| 1487 /** | 1589 /** |
| 1488 * Parse a compilation unit. | 1590 * Parse a compilation unit. |
| 1489 * <p> | 1591 * <p> |
| 1490 * Specified: | 1592 * Specified: |
| 1491 * <pre> | 1593 * <pre> |
| 1492 * compilationUnit ::= | 1594 * compilationUnit ::= |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2096 * formalParameterList ::= | 2198 * formalParameterList ::= |
| 2097 * '(' ')' | 2199 * '(' ')' |
| 2098 * | '(' normalFormalParameters (',' optionalFormalParameters)? ')' | 2200 * | '(' normalFormalParameters (',' optionalFormalParameters)? ')' |
| 2099 * | '(' optionalFormalParameters ')' | 2201 * | '(' optionalFormalParameters ')' |
| 2100 * normalFormalParameters ::= | 2202 * normalFormalParameters ::= |
| 2101 * normalFormalParameter (',' normalFormalParameter) | 2203 * normalFormalParameter (',' normalFormalParameter) |
| 2102 * optionalFormalParameters ::= | 2204 * optionalFormalParameters ::= |
| 2103 * optionalPositionalFormalParameters | 2205 * optionalPositionalFormalParameters |
| 2104 * | namedFormalParameters | 2206 * | namedFormalParameters |
| 2105 * optionalPositionalFormalParameters ::= | 2207 * optionalPositionalFormalParameters ::= |
| 2106 * '[' defaultFormalParameter (',' defaultFormalParameter)* ']' | 2208 * '[[' defaultFormalParameter (',' defaultFormalParameter)* ']]' |
| 2107 * namedFormalParameters ::= | 2209 * namedFormalParameters ::= |
| 2108 * '{' defaultNamedParameter (',' defaultNamedParameter)* '}' | 2210 * '{' defaultNamedParameter (',' defaultNamedParameter)* '}' |
| 2109 * </pre> | 2211 * </pre> |
| 2110 * @return the formal parameters that were parsed | 2212 * @return the formal parameters that were parsed |
| 2111 */ | 2213 */ |
| 2112 FormalParameterList parseFormalParameterList() { | 2214 FormalParameterList parseFormalParameterList() { |
| 2113 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); | 2215 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); |
| 2114 if (matches5(TokenType.CLOSE_PAREN)) { | 2216 if (matches5(TokenType.CLOSE_PAREN)) { |
| 2115 return new FormalParameterList.full(leftParenthesis, null, null, null, and
Advance); | 2217 return new FormalParameterList.full(leftParenthesis, null, null, null, and
Advance); |
| 2116 } | 2218 } |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2317 Expression expression = parseExpression2(); | 2419 Expression expression = parseExpression2(); |
| 2318 Token semicolon = null; | 2420 Token semicolon = null; |
| 2319 if (!inExpression) { | 2421 if (!inExpression) { |
| 2320 semicolon = expect2(TokenType.SEMICOLON); | 2422 semicolon = expect2(TokenType.SEMICOLON); |
| 2321 } | 2423 } |
| 2322 return new ExpressionFunctionBody.full(functionDefinition, expression, s
emicolon); | 2424 return new ExpressionFunctionBody.full(functionDefinition, expression, s
emicolon); |
| 2323 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) { | 2425 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) { |
| 2324 return new BlockFunctionBody.full(parseBlock()); | 2426 return new BlockFunctionBody.full(parseBlock()); |
| 2325 } else if (matches2(_NATIVE)) { | 2427 } else if (matches2(_NATIVE)) { |
| 2326 Token nativeToken = andAdvance; | 2428 Token nativeToken = andAdvance; |
| 2327 StringLiteral stringLiteral = parseStringLiteral(); | 2429 StringLiteral stringLiteral = null; |
| 2430 if (matches5(TokenType.STRING)) { |
| 2431 stringLiteral = parseStringLiteral(); |
| 2432 } |
| 2328 return new NativeFunctionBody.full(nativeToken, stringLiteral, expect2(T
okenType.SEMICOLON)); | 2433 return new NativeFunctionBody.full(nativeToken, stringLiteral, expect2(T
okenType.SEMICOLON)); |
| 2329 } else { | 2434 } else { |
| 2330 reportError4(ParserErrorCode.MISSING_FUNCTION_BODY, []); | 2435 reportError4(ParserErrorCode.MISSING_FUNCTION_BODY, []); |
| 2331 return new EmptyFunctionBody.full(createSyntheticToken2(TokenType.SEMICO
LON)); | 2436 return new EmptyFunctionBody.full(createSyntheticToken2(TokenType.SEMICO
LON)); |
| 2332 } | 2437 } |
| 2333 } finally { | 2438 } finally { |
| 2334 _inLoop = wasInLoop; | 2439 _inLoop = wasInLoop; |
| 2335 _inSwitch = wasInSwitch; | 2440 _inSwitch = wasInSwitch; |
| 2336 } | 2441 } |
| 2337 } | 2442 } |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2648 reportError5(missingNameError, missingNameToken, []); | 2753 reportError5(missingNameError, missingNameToken, []); |
| 2649 } | 2754 } |
| 2650 List<SimpleIdentifier> components = new List<SimpleIdentifier>(); | 2755 List<SimpleIdentifier> components = new List<SimpleIdentifier>(); |
| 2651 components.add(createSyntheticIdentifier()); | 2756 components.add(createSyntheticIdentifier()); |
| 2652 return new LibraryIdentifier.full(components); | 2757 return new LibraryIdentifier.full(components); |
| 2653 } | 2758 } |
| 2654 /** | 2759 /** |
| 2655 * Parse a list literal. | 2760 * Parse a list literal. |
| 2656 * <pre> | 2761 * <pre> |
| 2657 * listLiteral ::= | 2762 * listLiteral ::= |
| 2658 * 'const'? typeArguments? '[' (expressionList ','?)? ']' | 2763 * 'const'? typeArguments? '[[' (expressionList ','?)? ']]' |
| 2659 * </pre> | 2764 * </pre> |
| 2660 * @param modifier the 'const' modifier appearing before the literal, or {@cod
e null} if there is | 2765 * @param modifier the 'const' modifier appearing before the literal, or {@cod
e null} if there is |
| 2661 * no modifier | 2766 * no modifier |
| 2662 * @param typeArguments the type arguments appearing before the literal, or {@
code null} if there | 2767 * @param typeArguments the type arguments appearing before the literal, or {@
code null} if there |
| 2663 * are no type arguments | 2768 * are no type arguments |
| 2664 * @return the list literal that was parsed | 2769 * @return the list literal that was parsed |
| 2665 */ | 2770 */ |
| 2666 ListLiteral parseListLiteral(Token modifier, TypeArgumentList typeArguments) { | 2771 ListLiteral parseListLiteral(Token modifier, TypeArgumentList typeArguments) { |
| 2667 if (matches5(TokenType.INDEX)) { | 2772 if (matches5(TokenType.INDEX)) { |
| 2668 BeginToken leftBracket = new BeginToken(TokenType.OPEN_SQUARE_BRACKET, _cu
rrentToken.offset); | 2773 BeginToken leftBracket = new BeginToken(TokenType.OPEN_SQUARE_BRACKET, _cu
rrentToken.offset); |
| (...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4037 } | 4142 } |
| 4038 return token; | 4143 return token; |
| 4039 } | 4144 } |
| 4040 /** | 4145 /** |
| 4041 * Report an error with the given error code and arguments. | 4146 * Report an error with the given error code and arguments. |
| 4042 * @param errorCode the error code of the error to be reported | 4147 * @param errorCode the error code of the error to be reported |
| 4043 * @param node the node specifying the location of the error | 4148 * @param node the node specifying the location of the error |
| 4044 * @param arguments the arguments to the error, used to compose the error mess
age | 4149 * @param arguments the arguments to the error, used to compose the error mess
age |
| 4045 */ | 4150 */ |
| 4046 void reportError(ParserErrorCode errorCode, ASTNode node, List<Object> argumen
ts) { | 4151 void reportError(ParserErrorCode errorCode, ASTNode node, List<Object> argumen
ts) { |
| 4047 _errorListener.onError(new AnalysisError.con2(_source, node.offset, node.len
gth, errorCode, [arguments])); | 4152 _errorListener.onError(new AnalysisError.con2(_source, node.offset, node.len
gth, errorCode, arguments)); |
| 4048 } | 4153 } |
| 4049 /** | 4154 /** |
| 4050 * Report an error with the given error code and arguments. | 4155 * Report an error with the given error code and arguments. |
| 4051 * @param errorCode the error code of the error to be reported | 4156 * @param errorCode the error code of the error to be reported |
| 4052 * @param arguments the arguments to the error, used to compose the error mess
age | 4157 * @param arguments the arguments to the error, used to compose the error mess
age |
| 4053 */ | 4158 */ |
| 4054 void reportError4(ParserErrorCode errorCode, List<Object> arguments) { | 4159 void reportError4(ParserErrorCode errorCode, List<Object> arguments) { |
| 4055 reportError5(errorCode, _currentToken, arguments); | 4160 reportError5(errorCode, _currentToken, arguments); |
| 4056 } | 4161 } |
| 4057 /** | 4162 /** |
| 4058 * Report an error with the given error code and arguments. | 4163 * Report an error with the given error code and arguments. |
| 4059 * @param errorCode the error code of the error to be reported | 4164 * @param errorCode the error code of the error to be reported |
| 4060 * @param token the token specifying the location of the error | 4165 * @param token the token specifying the location of the error |
| 4061 * @param arguments the arguments to the error, used to compose the error mess
age | 4166 * @param arguments the arguments to the error, used to compose the error mess
age |
| 4062 */ | 4167 */ |
| 4063 void reportError5(ParserErrorCode errorCode, Token token, List<Object> argumen
ts) { | 4168 void reportError5(ParserErrorCode errorCode, Token token, List<Object> argumen
ts) { |
| 4064 _errorListener.onError(new AnalysisError.con2(_source, token.offset, token.l
ength, errorCode, [arguments])); | 4169 _errorListener.onError(new AnalysisError.con2(_source, token.offset, token.l
ength, errorCode, arguments)); |
| 4065 } | 4170 } |
| 4066 /** | 4171 /** |
| 4067 * Parse the 'final', 'const', 'var' or type preceding a variable declaration,
starting at the | 4172 * Parse the 'final', 'const', 'var' or type preceding a variable declaration,
starting at the |
| 4068 * given token, without actually creating a type or changing the current token
. Return the token | 4173 * given token, without actually creating a type or changing the current token
. Return the token |
| 4069 * following the type that was parsed, or {@code null} if the given token is n
ot the first token | 4174 * following the type that was parsed, or {@code null} if the given token is n
ot the first token |
| 4070 * in a valid type. | 4175 * in a valid type. |
| 4071 * <pre> | 4176 * <pre> |
| 4072 * finalConstVarOrType ::= | 4177 * finalConstVarOrType ::= |
| 4073 * | 'final' type? | 4178 * | 'final' type? |
| 4074 * | 'const' type? | 4179 * | 'const' type? |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4111 * formalParameterList ::= | 4216 * formalParameterList ::= |
| 4112 * '(' ')' | 4217 * '(' ')' |
| 4113 * | '(' normalFormalParameters (',' optionalFormalParameters)? ')' | 4218 * | '(' normalFormalParameters (',' optionalFormalParameters)? ')' |
| 4114 * | '(' optionalFormalParameters ')' | 4219 * | '(' optionalFormalParameters ')' |
| 4115 * normalFormalParameters ::= | 4220 * normalFormalParameters ::= |
| 4116 * normalFormalParameter (',' normalFormalParameter) | 4221 * normalFormalParameter (',' normalFormalParameter) |
| 4117 * optionalFormalParameters ::= | 4222 * optionalFormalParameters ::= |
| 4118 * optionalPositionalFormalParameters | 4223 * optionalPositionalFormalParameters |
| 4119 * | namedFormalParameters | 4224 * | namedFormalParameters |
| 4120 * optionalPositionalFormalParameters ::= | 4225 * optionalPositionalFormalParameters ::= |
| 4121 * '[' defaultFormalParameter (',' defaultFormalParameter)* ']' | 4226 * '[[' defaultFormalParameter (',' defaultFormalParameter)* ']]' |
| 4122 * namedFormalParameters ::= | 4227 * namedFormalParameters ::= |
| 4123 * '{' defaultNamedParameter (',' defaultNamedParameter)* '}' | 4228 * '{' defaultNamedParameter (',' defaultNamedParameter)* '}' |
| 4124 * </pre> | 4229 * </pre> |
| 4125 * @param startToken the token at which parsing is to begin | 4230 * @param startToken the token at which parsing is to begin |
| 4126 * @return the token following the formal parameter list that was parsed | 4231 * @return the token following the formal parameter list that was parsed |
| 4127 */ | 4232 */ |
| 4128 Token skipFormalParameterList(Token startToken) { | 4233 Token skipFormalParameterList(Token startToken) { |
| 4129 if (!matches4(startToken, TokenType.OPEN_PAREN)) { | 4234 if (!matches4(startToken, TokenType.OPEN_PAREN)) { |
| 4130 return null; | 4235 return null; |
| 4131 } | 4236 } |
| (...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4907 /** | 5012 /** |
| 4908 * The message template used to create the message to be displayed for this er
ror. | 5013 * The message template used to create the message to be displayed for this er
ror. |
| 4909 */ | 5014 */ |
| 4910 String _message; | 5015 String _message; |
| 4911 /** | 5016 /** |
| 4912 * Initialize a newly created error code to have the given severity and messag
e. | 5017 * Initialize a newly created error code to have the given severity and messag
e. |
| 4913 * @param severity the severity of the error | 5018 * @param severity the severity of the error |
| 4914 * @param message the message template used to create the message to be displa
yed for the error | 5019 * @param message the message template used to create the message to be displa
yed for the error |
| 4915 */ | 5020 */ |
| 4916 ParserErrorCode.con1(String ___name, int ___ordinal, ErrorSeverity severity2,
String message2) { | 5021 ParserErrorCode.con1(String ___name, int ___ordinal, ErrorSeverity severity2,
String message2) { |
| 4917 _jtd_constructor_301_impl(___name, ___ordinal, severity2, message2); | 5022 _jtd_constructor_302_impl(___name, ___ordinal, severity2, message2); |
| 4918 } | 5023 } |
| 4919 _jtd_constructor_301_impl(String ___name, int ___ordinal, ErrorSeverity severi
ty2, String message2) { | 5024 _jtd_constructor_302_impl(String ___name, int ___ordinal, ErrorSeverity severi
ty2, String message2) { |
| 4920 __name = ___name; | 5025 __name = ___name; |
| 4921 __ordinal = ___ordinal; | 5026 __ordinal = ___ordinal; |
| 4922 this._severity = severity2; | 5027 this._severity = severity2; |
| 4923 this._message = message2; | 5028 this._message = message2; |
| 4924 } | 5029 } |
| 4925 /** | 5030 /** |
| 4926 * Initialize a newly created error code to have the given message and a sever
ity of ERROR. | 5031 * Initialize a newly created error code to have the given message and a sever
ity of ERROR. |
| 4927 * @param message the message template used to create the message to be displa
yed for the error | 5032 * @param message the message template used to create the message to be displa
yed for the error |
| 4928 */ | 5033 */ |
| 4929 ParserErrorCode.con2(String ___name, int ___ordinal, String message) { | 5034 ParserErrorCode.con2(String ___name, int ___ordinal, String message) { |
| 4930 _jtd_constructor_302_impl(___name, ___ordinal, message); | 5035 _jtd_constructor_303_impl(___name, ___ordinal, message); |
| 4931 } | 5036 } |
| 4932 _jtd_constructor_302_impl(String ___name, int ___ordinal, String message) { | 5037 _jtd_constructor_303_impl(String ___name, int ___ordinal, String message) { |
| 4933 _jtd_constructor_301_impl(___name, ___ordinal, ErrorSeverity.ERROR, message)
; | 5038 _jtd_constructor_302_impl(___name, ___ordinal, ErrorSeverity.ERROR, message)
; |
| 4934 } | 5039 } |
| 4935 ErrorSeverity get errorSeverity => _severity; | 5040 ErrorSeverity get errorSeverity => _severity; |
| 4936 String get message => _message; | 5041 String get message => _message; |
| 4937 ErrorType get type => ErrorType.SYNTACTIC_ERROR; | 5042 ErrorType get type => ErrorType.SYNTACTIC_ERROR; |
| 4938 bool needsRecompilation() => true; | 5043 bool needsRecompilation() => true; |
| 4939 int compareTo(ParserErrorCode other) => __ordinal - other.__ordinal; | 5044 int compareTo(ParserErrorCode other) => __ordinal - other.__ordinal; |
| 4940 String toString() => __name; | 5045 String toString() => __name; |
| 4941 } | 5046 } |
| 4942 /** | 5047 /** |
| 4943 * Instances of the class {link ToFormattedSourceVisitor} write a source represe
ntation of a visited | 5048 * Instances of the class {link ToFormattedSourceVisitor} write a source represe
ntation of a visited |
| (...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5815 for (int i = 0; i < size2; i++) { | 5920 for (int i = 0; i < size2; i++) { |
| 5816 if (i > 0) { | 5921 if (i > 0) { |
| 5817 _writer.print(separator); | 5922 _writer.print(separator); |
| 5818 } | 5923 } |
| 5819 nodes[i].accept(this); | 5924 nodes[i].accept(this); |
| 5820 } | 5925 } |
| 5821 } | 5926 } |
| 5822 } | 5927 } |
| 5823 } | 5928 } |
| 5824 } | 5929 } |
| OLD | NEW |