| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 * Defines the tokens that are produced by the scanner, used by the parser, and | 6 * Defines the tokens that are produced by the scanner, used by the parser, and |
| 7 * referenced from the [AST structure](ast.dart). | 7 * referenced from the [AST structure](ast.dart). |
| 8 */ | 8 */ |
| 9 import 'dart:collection'; | 9 import 'dart:collection'; |
| 10 | 10 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 @override | 78 @override |
| 79 CommentToken get precedingComments => _precedingComment; | 79 CommentToken get precedingComments => _precedingComment; |
| 80 | 80 |
| 81 @override | 81 @override |
| 82 void set precedingComments(CommentToken comment) { | 82 void set precedingComments(CommentToken comment) { |
| 83 _precedingComment = comment; | 83 _precedingComment = comment; |
| 84 _setCommentParent(_precedingComment); | 84 _setCommentParent(_precedingComment); |
| 85 } | 85 } |
| 86 | 86 |
| 87 @override | 87 @override |
| 88 void applyDelta(int delta) { |
| 89 super.applyDelta(delta); |
| 90 Token token = precedingComments; |
| 91 while (token != null) { |
| 92 token.applyDelta(delta); |
| 93 token = token.next; |
| 94 } |
| 95 } |
| 96 |
| 97 @override |
| 88 Token copy() => | 98 Token copy() => |
| 89 new BeginTokenWithComment(type, offset, copyComments(precedingComments)); | 99 new BeginTokenWithComment(type, offset, copyComments(precedingComments)); |
| 90 } | 100 } |
| 91 | 101 |
| 92 /** | 102 /** |
| 93 * A token representing a comment. | 103 * A token representing a comment. |
| 94 */ | 104 */ |
| 95 class CommentToken extends StringToken { | 105 class CommentToken extends StringToken { |
| 96 /** | 106 /** |
| 97 * The token that contains this comment. | 107 * The token that contains this comment. |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 | 483 |
| 474 @override | 484 @override |
| 475 CommentToken get precedingComments => _precedingComment; | 485 CommentToken get precedingComments => _precedingComment; |
| 476 | 486 |
| 477 void set precedingComments(CommentToken comment) { | 487 void set precedingComments(CommentToken comment) { |
| 478 _precedingComment = comment; | 488 _precedingComment = comment; |
| 479 _setCommentParent(_precedingComment); | 489 _setCommentParent(_precedingComment); |
| 480 } | 490 } |
| 481 | 491 |
| 482 @override | 492 @override |
| 493 void applyDelta(int delta) { |
| 494 super.applyDelta(delta); |
| 495 Token token = precedingComments; |
| 496 while (token != null) { |
| 497 token.applyDelta(delta); |
| 498 token = token.next; |
| 499 } |
| 500 } |
| 501 |
| 502 @override |
| 483 Token copy() => new KeywordTokenWithComment( | 503 Token copy() => new KeywordTokenWithComment( |
| 484 keyword, offset, copyComments(precedingComments)); | 504 keyword, offset, copyComments(precedingComments)); |
| 485 } | 505 } |
| 486 | 506 |
| 487 /** | 507 /** |
| 488 * A token that was scanned from the input. Each token knows which tokens | 508 * A token that was scanned from the input. Each token knows which tokens |
| 489 * precede and follow it, acting as a link in a doubly linked list of tokens. | 509 * precede and follow it, acting as a link in a doubly linked list of tokens. |
| 490 */ | 510 */ |
| 491 class SimpleToken implements Token { | 511 class SimpleToken implements Token { |
| 492 /** | 512 /** |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 @override | 575 @override |
| 556 String get lexeme => type.lexeme; | 576 String get lexeme => type.lexeme; |
| 557 | 577 |
| 558 @override | 578 @override |
| 559 CommentToken get precedingComments => null; | 579 CommentToken get precedingComments => null; |
| 560 | 580 |
| 561 @override | 581 @override |
| 562 String get stringValue => type.stringValue; | 582 String get stringValue => type.stringValue; |
| 563 | 583 |
| 564 @override | 584 @override |
| 585 void applyDelta(int delta) { |
| 586 offset += delta; |
| 587 } |
| 588 |
| 589 @override |
| 565 Token copy() => new Token(type, offset); | 590 Token copy() => new Token(type, offset); |
| 566 | 591 |
| 567 @override | 592 @override |
| 568 Token copyComments(Token token) { | 593 Token copyComments(Token token) { |
| 569 if (token == null) { | 594 if (token == null) { |
| 570 return null; | 595 return null; |
| 571 } | 596 } |
| 572 Token head = token.copy(); | 597 Token head = token.copy(); |
| 573 Token tail = head; | 598 Token tail = head; |
| 574 token = token.next; | 599 token = token.next; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 | 697 |
| 673 @override | 698 @override |
| 674 CommentToken get precedingComments => _precedingComment; | 699 CommentToken get precedingComments => _precedingComment; |
| 675 | 700 |
| 676 void set precedingComments(CommentToken comment) { | 701 void set precedingComments(CommentToken comment) { |
| 677 _precedingComment = comment; | 702 _precedingComment = comment; |
| 678 _setCommentParent(_precedingComment); | 703 _setCommentParent(_precedingComment); |
| 679 } | 704 } |
| 680 | 705 |
| 681 @override | 706 @override |
| 707 void applyDelta(int delta) { |
| 708 super.applyDelta(delta); |
| 709 Token token = precedingComments; |
| 710 while (token != null) { |
| 711 token.applyDelta(delta); |
| 712 token = token.next; |
| 713 } |
| 714 } |
| 715 |
| 716 @override |
| 682 Token copy() => new StringTokenWithComment( | 717 Token copy() => new StringTokenWithComment( |
| 683 type, lexeme, offset, copyComments(precedingComments)); | 718 type, lexeme, offset, copyComments(precedingComments)); |
| 684 } | 719 } |
| 685 | 720 |
| 686 /** | 721 /** |
| 687 * A synthetic keyword token. | 722 * A synthetic keyword token. |
| 688 */ | 723 */ |
| 689 class SyntheticKeywordToken extends KeywordToken { | 724 class SyntheticKeywordToken extends KeywordToken { |
| 690 /** | 725 /** |
| 691 * Initialize a newly created token to represent the given [keyword] at the | 726 * Initialize a newly created token to represent the given [keyword] at the |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 * returns false because stringValue returns [:null:]. | 889 * returns false because stringValue returns [:null:]. |
| 855 */ | 890 */ |
| 856 String get stringValue; | 891 String get stringValue; |
| 857 | 892 |
| 858 /** | 893 /** |
| 859 * Return the type of the token. | 894 * Return the type of the token. |
| 860 */ | 895 */ |
| 861 TokenType get type; | 896 TokenType get type; |
| 862 | 897 |
| 863 /** | 898 /** |
| 899 * Apply (add) the given [delta] to this token's offset. |
| 900 */ |
| 901 void applyDelta(int delta); |
| 902 |
| 903 /** |
| 864 * Return a newly created token that is a copy of this tokens | 904 * Return a newly created token that is a copy of this tokens |
| 865 * including any [preceedingComment] tokens, | 905 * including any [preceedingComment] tokens, |
| 866 * but that is not a part of any token stream. | 906 * but that is not a part of any token stream. |
| 867 */ | 907 */ |
| 868 Token copy(); | 908 Token copy(); |
| 869 | 909 |
| 870 /** | 910 /** |
| 871 * Copy a linked list of comment tokens identical to the given comment tokens. | 911 * Copy a linked list of comment tokens identical to the given comment tokens. |
| 872 */ | 912 */ |
| 873 Token copyComments(Token token); | 913 Token copyComments(Token token); |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1618 | 1658 |
| 1619 void set precedingComments(CommentToken comment) { | 1659 void set precedingComments(CommentToken comment) { |
| 1620 _precedingComment = comment; | 1660 _precedingComment = comment; |
| 1621 _setCommentParent(_precedingComment); | 1661 _setCommentParent(_precedingComment); |
| 1622 } | 1662 } |
| 1623 | 1663 |
| 1624 @override | 1664 @override |
| 1625 Token copy() => | 1665 Token copy() => |
| 1626 new TokenWithComment(type, offset, copyComments(precedingComments)); | 1666 new TokenWithComment(type, offset, copyComments(precedingComments)); |
| 1627 } | 1667 } |
| OLD | NEW |