| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine.html; | 8 library engine.html; |
| 9 | 9 |
| 10 import 'dart:collection'; | 10 import 'dart:collection'; |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 } on HtmlUnitUtils_FoundTagNodeError catch (e) { | 281 } on HtmlUnitUtils_FoundTagNodeError catch (e) { |
| 282 return result[0]; | 282 return result[0]; |
| 283 } | 283 } |
| 284 return null; | 284 return null; |
| 285 } | 285 } |
| 286 | 286 |
| 287 /** | 287 /** |
| 288 * Returns the [Expression] that is part of the given root [AstNode] and enclo
ses the | 288 * Returns the [Expression] that is part of the given root [AstNode] and enclo
ses the |
| 289 * given offset. | 289 * given offset. |
| 290 */ | 290 */ |
| 291 static Expression getExpressionAt(AstNode root, int offset) { | 291 static Expression _getExpressionAt(AstNode root, int offset) { |
| 292 if (root.offset <= offset && offset < root.end) { | 292 if (root.offset <= offset && offset < root.end) { |
| 293 AstNode dartNode = new NodeLocator.con1(offset).searchWithin(root); | 293 AstNode dartNode = new NodeLocator.con1(offset).searchWithin(root); |
| 294 if (dartNode is Expression) { | 294 if (dartNode is Expression) { |
| 295 return dartNode; | 295 return dartNode; |
| 296 } | 296 } |
| 297 } | 297 } |
| 298 return null; | 298 return null; |
| 299 } | 299 } |
| 300 } | 300 } |
| 301 | 301 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 326 } | 326 } |
| 327 | 327 |
| 328 class ExpressionVisitor_HtmlUnitUtils_getExpression extends ExpressionVisitor { | 328 class ExpressionVisitor_HtmlUnitUtils_getExpression extends ExpressionVisitor { |
| 329 int offset = 0; | 329 int offset = 0; |
| 330 | 330 |
| 331 List<Expression> result; | 331 List<Expression> result; |
| 332 | 332 |
| 333 ExpressionVisitor_HtmlUnitUtils_getExpression(this.offset, this.result) : supe
r(); | 333 ExpressionVisitor_HtmlUnitUtils_getExpression(this.offset, this.result) : supe
r(); |
| 334 | 334 |
| 335 void visitExpression(Expression expression) { | 335 void visitExpression(Expression expression) { |
| 336 Expression at = HtmlUnitUtils.getExpressionAt(expression, offset); | 336 Expression at = HtmlUnitUtils._getExpressionAt(expression, offset); |
| 337 if (at != null) { | 337 if (at != null) { |
| 338 result[0] = at; | 338 result[0] = at; |
| 339 throw new HtmlUnitUtils_FoundExpressionError(); | 339 throw new HtmlUnitUtils_FoundExpressionError(); |
| 340 } | 340 } |
| 341 } | 341 } |
| 342 } | 342 } |
| 343 | 343 |
| 344 class RecursiveXmlVisitor_HtmlUnitUtils_getTagNode extends RecursiveXmlVisitor<O
bject> { | 344 class RecursiveXmlVisitor_HtmlUnitUtils_getTagNode extends RecursiveXmlVisitor<O
bject> { |
| 345 int offset = 0; | 345 int offset = 0; |
| 346 | 346 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 } | 551 } |
| 552 // This will create ArrayList for exactly given number of elements. | 552 // This will create ArrayList for exactly given number of elements. |
| 553 return new List.from(children); | 553 return new List.from(children); |
| 554 } | 554 } |
| 555 return children; | 555 return children; |
| 556 } | 556 } |
| 557 | 557 |
| 558 /** | 558 /** |
| 559 * This method exists for debugging purposes only. | 559 * This method exists for debugging purposes only. |
| 560 */ | 560 */ |
| 561 void appendIdentifier(JavaStringBuilder builder, XmlNode node) { | 561 void _appendIdentifier(JavaStringBuilder builder, XmlNode node) { |
| 562 if (node is XmlTagNode) { | 562 if (node is XmlTagNode) { |
| 563 builder.append(node.tag); | 563 builder.append(node.tag); |
| 564 } else if (node is XmlAttributeNode) { | 564 } else if (node is XmlAttributeNode) { |
| 565 builder.append(node.name); | 565 builder.append(node.name); |
| 566 } else { | 566 } else { |
| 567 builder.append("htmlUnit"); | 567 builder.append("htmlUnit"); |
| 568 } | 568 } |
| 569 } | 569 } |
| 570 | 570 |
| 571 /** | 571 /** |
| 572 * This method exists for debugging purposes only. | 572 * This method exists for debugging purposes only. |
| 573 */ | 573 */ |
| 574 String buildRecursiveStructureMessage(XmlNode newParent) { | 574 String _buildRecursiveStructureMessage(XmlNode newParent) { |
| 575 JavaStringBuilder builder = new JavaStringBuilder(); | 575 JavaStringBuilder builder = new JavaStringBuilder(); |
| 576 builder.append("Attempt to create recursive structure: "); | 576 builder.append("Attempt to create recursive structure: "); |
| 577 XmlNode current = newParent; | 577 XmlNode current = newParent; |
| 578 while (current != null) { | 578 while (current != null) { |
| 579 if (current != newParent) { | 579 if (current != newParent) { |
| 580 builder.append(" -> "); | 580 builder.append(" -> "); |
| 581 } | 581 } |
| 582 if (identical(current, this)) { | 582 if (identical(current, this)) { |
| 583 builder.appendChar(0x2A); | 583 builder.appendChar(0x2A); |
| 584 appendIdentifier(builder, current); | 584 _appendIdentifier(builder, current); |
| 585 builder.appendChar(0x2A); | 585 builder.appendChar(0x2A); |
| 586 } else { | 586 } else { |
| 587 appendIdentifier(builder, current); | 587 _appendIdentifier(builder, current); |
| 588 } | 588 } |
| 589 current = current.parent; | 589 current = current.parent; |
| 590 } | 590 } |
| 591 return builder.toString(); | 591 return builder.toString(); |
| 592 } | 592 } |
| 593 | 593 |
| 594 /** | 594 /** |
| 595 * Set the parent of this node to the given node. | 595 * Set the parent of this node to the given node. |
| 596 * | 596 * |
| 597 * @param newParent the node that is to be made the parent of this node | 597 * @param newParent the node that is to be made the parent of this node |
| 598 */ | 598 */ |
| 599 void set parent(XmlNode newParent) { | 599 void set parent(XmlNode newParent) { |
| 600 XmlNode current = newParent; | 600 XmlNode current = newParent; |
| 601 while (current != null) { | 601 while (current != null) { |
| 602 if (identical(current, this)) { | 602 if (identical(current, this)) { |
| 603 AnalysisEngine.instance.logger.logError2("Circular structure while setti
ng an XML node's parent", new IllegalArgumentException(buildRecursiveStructureMe
ssage(newParent))); | 603 AnalysisEngine.instance.logger.logError2("Circular structure while setti
ng an XML node's parent", new IllegalArgumentException(_buildRecursiveStructureM
essage(newParent))); |
| 604 return; | 604 return; |
| 605 } | 605 } |
| 606 current = current.parent; | 606 current = current.parent; |
| 607 } | 607 } |
| 608 _parent = newParent; | 608 _parent = newParent; |
| 609 } | 609 } |
| 610 } | 610 } |
| 611 | 611 |
| 612 /** | 612 /** |
| 613 * Instances of the class `SimpleXmlVisitor` implement an AST visitor that will
do nothing | 613 * Instances of the class `SimpleXmlVisitor` implement an AST visitor that will
do nothing |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 void set passThroughElements(List<String> passThroughElements) { | 691 void set passThroughElements(List<String> passThroughElements) { |
| 692 this._passThroughElements = passThroughElements != null ? passThroughElement
s : _NO_PASS_THROUGH_ELEMENTS; | 692 this._passThroughElements = passThroughElements != null ? passThroughElement
s : _NO_PASS_THROUGH_ELEMENTS; |
| 693 } | 693 } |
| 694 | 694 |
| 695 /** | 695 /** |
| 696 * Scan the source code to produce a list of tokens representing the source. | 696 * Scan the source code to produce a list of tokens representing the source. |
| 697 * | 697 * |
| 698 * @return the first token in the list of tokens that were produced | 698 * @return the first token in the list of tokens that were produced |
| 699 */ | 699 */ |
| 700 Token tokenize() { | 700 Token tokenize() { |
| 701 scan(); | 701 _scan(); |
| 702 appendEofToken(); | 702 _appendEofToken(); |
| 703 return firstToken(); | 703 return _firstToken(); |
| 704 } | 704 } |
| 705 | 705 |
| 706 /** | 706 /** |
| 707 * Advance the current position and return the character at the new current po
sition. | 707 * Advance the current position and return the character at the new current po
sition. |
| 708 * | 708 * |
| 709 * @return the character at the new current position | 709 * @return the character at the new current position |
| 710 */ | 710 */ |
| 711 int advance(); | 711 int advance(); |
| 712 | 712 |
| 713 /** | 713 /** |
| (...skipping 15 matching lines...) Expand all Loading... |
| 729 */ | 729 */ |
| 730 int peek(); | 730 int peek(); |
| 731 | 731 |
| 732 /** | 732 /** |
| 733 * Record the fact that we are at the beginning of a new line in the source. | 733 * Record the fact that we are at the beginning of a new line in the source. |
| 734 */ | 734 */ |
| 735 void recordStartOfLine() { | 735 void recordStartOfLine() { |
| 736 _lineStarts.add(offset); | 736 _lineStarts.add(offset); |
| 737 } | 737 } |
| 738 | 738 |
| 739 void appendEofToken() { | 739 void _appendEofToken() { |
| 740 Token eofToken = new Token.con1(TokenType.EOF, offset); | 740 Token eofToken = new Token.con1(TokenType.EOF, offset); |
| 741 // The EOF token points to itself so that there is always infinite look-ahea
d. | 741 // The EOF token points to itself so that there is always infinite look-ahea
d. |
| 742 eofToken.setNext(eofToken); | 742 eofToken.setNext(eofToken); |
| 743 _tail = _tail.setNext(eofToken); | 743 _tail = _tail.setNext(eofToken); |
| 744 } | 744 } |
| 745 | 745 |
| 746 Token emit(Token token) { | 746 Token _emit(Token token) { |
| 747 _tail.setNext(token); | 747 _tail.setNext(token); |
| 748 _tail = token; | 748 _tail = token; |
| 749 return token; | 749 return token; |
| 750 } | 750 } |
| 751 | 751 |
| 752 Token emitWithOffset(TokenType type, int start) => emit(new Token.con1(type, s
tart)); | 752 Token _emitWithOffset(TokenType type, int start) => _emit(new Token.con1(type,
start)); |
| 753 | 753 |
| 754 Token emitWithOffsetAndLength(TokenType type, int start, int count) => emit(ne
w Token.con2(type, start, getString(start, count))); | 754 Token _emitWithOffsetAndLength(TokenType type, int start, int count) => _emit(
new Token.con2(type, start, getString(start, count))); |
| 755 | 755 |
| 756 Token firstToken() => _tokens.next; | 756 Token _firstToken() => _tokens.next; |
| 757 | 757 |
| 758 int recordStartOfLineAndAdvance(int c) { | 758 int _recordStartOfLineAndAdvance(int c) { |
| 759 if (c == 0xD) { | 759 if (c == 0xD) { |
| 760 c = advance(); | 760 c = advance(); |
| 761 if (c == 0xA) { | 761 if (c == 0xA) { |
| 762 c = advance(); | 762 c = advance(); |
| 763 } | 763 } |
| 764 recordStartOfLine(); | 764 recordStartOfLine(); |
| 765 } else if (c == 0xA) { | 765 } else if (c == 0xA) { |
| 766 c = advance(); | 766 c = advance(); |
| 767 recordStartOfLine(); | 767 recordStartOfLine(); |
| 768 } else { | 768 } else { |
| 769 c = advance(); | 769 c = advance(); |
| 770 } | 770 } |
| 771 return c; | 771 return c; |
| 772 } | 772 } |
| 773 | 773 |
| 774 void scan() { | 774 void _scan() { |
| 775 bool inBrackets = false; | 775 bool inBrackets = false; |
| 776 String endPassThrough = null; | 776 String endPassThrough = null; |
| 777 int c = advance(); | 777 int c = advance(); |
| 778 while (c >= 0) { | 778 while (c >= 0) { |
| 779 int start = offset; | 779 int start = offset; |
| 780 if (c == 0x3C) { | 780 if (c == 0x3C) { |
| 781 c = advance(); | 781 c = advance(); |
| 782 if (c == 0x21) { | 782 if (c == 0x21) { |
| 783 c = advance(); | 783 c = advance(); |
| 784 if (c == 0x2D && peek() == 0x2D) { | 784 if (c == 0x2D && peek() == 0x2D) { |
| 785 // handle a comment | 785 // handle a comment |
| 786 c = advance(); | 786 c = advance(); |
| 787 int dashCount = 1; | 787 int dashCount = 1; |
| 788 while (c >= 0) { | 788 while (c >= 0) { |
| 789 if (c == 0x2D) { | 789 if (c == 0x2D) { |
| 790 dashCount++; | 790 dashCount++; |
| 791 } else if (c == 0x3E && dashCount >= 2) { | 791 } else if (c == 0x3E && dashCount >= 2) { |
| 792 c = advance(); | 792 c = advance(); |
| 793 break; | 793 break; |
| 794 } else { | 794 } else { |
| 795 dashCount = 0; | 795 dashCount = 0; |
| 796 } | 796 } |
| 797 c = recordStartOfLineAndAdvance(c); | 797 c = _recordStartOfLineAndAdvance(c); |
| 798 } | 798 } |
| 799 emitWithOffsetAndLength(TokenType.COMMENT, start, -1); | 799 _emitWithOffsetAndLength(TokenType.COMMENT, start, -1); |
| 800 // Capture <!--> and <!---> as tokens but report an error | 800 // Capture <!--> and <!---> as tokens but report an error |
| 801 if (_tail.length < 7) { | 801 if (_tail.length < 7) { |
| 802 } | 802 } |
| 803 } else { | 803 } else { |
| 804 // handle a declaration | 804 // handle a declaration |
| 805 while (c >= 0) { | 805 while (c >= 0) { |
| 806 if (c == 0x3E) { | 806 if (c == 0x3E) { |
| 807 c = advance(); | 807 c = advance(); |
| 808 break; | 808 break; |
| 809 } | 809 } |
| 810 c = recordStartOfLineAndAdvance(c); | 810 c = _recordStartOfLineAndAdvance(c); |
| 811 } | 811 } |
| 812 emitWithOffsetAndLength(TokenType.DECLARATION, start, -1); | 812 _emitWithOffsetAndLength(TokenType.DECLARATION, start, -1); |
| 813 if (!StringUtilities.endsWithChar(_tail.lexeme, 0x3E)) { | 813 if (!StringUtilities.endsWithChar(_tail.lexeme, 0x3E)) { |
| 814 } | 814 } |
| 815 } | 815 } |
| 816 } else if (c == 0x3F) { | 816 } else if (c == 0x3F) { |
| 817 // handle a directive | 817 // handle a directive |
| 818 while (c >= 0) { | 818 while (c >= 0) { |
| 819 if (c == 0x3F) { | 819 if (c == 0x3F) { |
| 820 c = advance(); | 820 c = advance(); |
| 821 if (c == 0x3E) { | 821 if (c == 0x3E) { |
| 822 c = advance(); | 822 c = advance(); |
| 823 break; | 823 break; |
| 824 } | 824 } |
| 825 } else { | 825 } else { |
| 826 c = recordStartOfLineAndAdvance(c); | 826 c = _recordStartOfLineAndAdvance(c); |
| 827 } | 827 } |
| 828 } | 828 } |
| 829 emitWithOffsetAndLength(TokenType.DIRECTIVE, start, -1); | 829 _emitWithOffsetAndLength(TokenType.DIRECTIVE, start, -1); |
| 830 if (_tail.length < 4) { | 830 if (_tail.length < 4) { |
| 831 } | 831 } |
| 832 } else if (c == 0x2F) { | 832 } else if (c == 0x2F) { |
| 833 emitWithOffset(TokenType.LT_SLASH, start); | 833 _emitWithOffset(TokenType.LT_SLASH, start); |
| 834 inBrackets = true; | 834 inBrackets = true; |
| 835 c = advance(); | 835 c = advance(); |
| 836 } else { | 836 } else { |
| 837 inBrackets = true; | 837 inBrackets = true; |
| 838 emitWithOffset(TokenType.LT, start); | 838 _emitWithOffset(TokenType.LT, start); |
| 839 // ignore whitespace in braces | 839 // ignore whitespace in braces |
| 840 while (Character.isWhitespace(c)) { | 840 while (Character.isWhitespace(c)) { |
| 841 c = recordStartOfLineAndAdvance(c); | 841 c = _recordStartOfLineAndAdvance(c); |
| 842 } | 842 } |
| 843 // get tag | 843 // get tag |
| 844 if (Character.isLetterOrDigit(c)) { | 844 if (Character.isLetterOrDigit(c)) { |
| 845 int tagStart = offset; | 845 int tagStart = offset; |
| 846 c = advance(); | 846 c = advance(); |
| 847 while (Character.isLetterOrDigit(c) || c == 0x2D || c == 0x5F) { | 847 while (Character.isLetterOrDigit(c) || c == 0x2D || c == 0x5F) { |
| 848 c = advance(); | 848 c = advance(); |
| 849 } | 849 } |
| 850 emitWithOffsetAndLength(TokenType.TAG, tagStart, -1); | 850 _emitWithOffsetAndLength(TokenType.TAG, tagStart, -1); |
| 851 // check tag against passThrough elements | 851 // check tag against passThrough elements |
| 852 String tag = _tail.lexeme; | 852 String tag = _tail.lexeme; |
| 853 for (String str in _passThroughElements) { | 853 for (String str in _passThroughElements) { |
| 854 if (str == tag) { | 854 if (str == tag) { |
| 855 endPassThrough = "</${str}>"; | 855 endPassThrough = "</${str}>"; |
| 856 break; | 856 break; |
| 857 } | 857 } |
| 858 } | 858 } |
| 859 } | 859 } |
| 860 } | 860 } |
| 861 } else if (c == 0x3E) { | 861 } else if (c == 0x3E) { |
| 862 emitWithOffset(TokenType.GT, start); | 862 _emitWithOffset(TokenType.GT, start); |
| 863 inBrackets = false; | 863 inBrackets = false; |
| 864 c = advance(); | 864 c = advance(); |
| 865 // if passThrough != null, read until we match it | 865 // if passThrough != null, read until we match it |
| 866 if (endPassThrough != null) { | 866 if (endPassThrough != null) { |
| 867 bool endFound = false; | 867 bool endFound = false; |
| 868 int len = endPassThrough.length; | 868 int len = endPassThrough.length; |
| 869 int firstC = endPassThrough.codeUnitAt(0); | 869 int firstC = endPassThrough.codeUnitAt(0); |
| 870 int index = 0; | 870 int index = 0; |
| 871 int nextC = firstC; | 871 int nextC = firstC; |
| 872 while (c >= 0) { | 872 while (c >= 0) { |
| 873 if (c == nextC) { | 873 if (c == nextC) { |
| 874 index++; | 874 index++; |
| 875 if (index == len) { | 875 if (index == len) { |
| 876 endFound = true; | 876 endFound = true; |
| 877 break; | 877 break; |
| 878 } | 878 } |
| 879 nextC = endPassThrough.codeUnitAt(index); | 879 nextC = endPassThrough.codeUnitAt(index); |
| 880 } else if (c == firstC) { | 880 } else if (c == firstC) { |
| 881 index = 1; | 881 index = 1; |
| 882 nextC = endPassThrough.codeUnitAt(1); | 882 nextC = endPassThrough.codeUnitAt(1); |
| 883 } else { | 883 } else { |
| 884 index = 0; | 884 index = 0; |
| 885 nextC = firstC; | 885 nextC = firstC; |
| 886 } | 886 } |
| 887 c = recordStartOfLineAndAdvance(c); | 887 c = _recordStartOfLineAndAdvance(c); |
| 888 } | 888 } |
| 889 if (start + 1 < offset) { | 889 if (start + 1 < offset) { |
| 890 if (endFound) { | 890 if (endFound) { |
| 891 emitWithOffsetAndLength(TokenType.TEXT, start + 1, -len); | 891 _emitWithOffsetAndLength(TokenType.TEXT, start + 1, -len); |
| 892 emitWithOffset(TokenType.LT_SLASH, offset - len + 1); | 892 _emitWithOffset(TokenType.LT_SLASH, offset - len + 1); |
| 893 emitWithOffsetAndLength(TokenType.TAG, offset - len + 3, -1); | 893 _emitWithOffsetAndLength(TokenType.TAG, offset - len + 3, -1); |
| 894 } else { | 894 } else { |
| 895 emitWithOffsetAndLength(TokenType.TEXT, start + 1, -1); | 895 _emitWithOffsetAndLength(TokenType.TEXT, start + 1, -1); |
| 896 } | 896 } |
| 897 } | 897 } |
| 898 endPassThrough = null; | 898 endPassThrough = null; |
| 899 } | 899 } |
| 900 } else if (c == 0x2F && peek() == 0x3E) { | 900 } else if (c == 0x2F && peek() == 0x3E) { |
| 901 advance(); | 901 advance(); |
| 902 emitWithOffset(TokenType.SLASH_GT, start); | 902 _emitWithOffset(TokenType.SLASH_GT, start); |
| 903 inBrackets = false; | 903 inBrackets = false; |
| 904 c = advance(); | 904 c = advance(); |
| 905 } else if (!inBrackets) { | 905 } else if (!inBrackets) { |
| 906 c = recordStartOfLineAndAdvance(c); | 906 c = _recordStartOfLineAndAdvance(c); |
| 907 while (c != 0x3C && c >= 0) { | 907 while (c != 0x3C && c >= 0) { |
| 908 c = recordStartOfLineAndAdvance(c); | 908 c = _recordStartOfLineAndAdvance(c); |
| 909 } | 909 } |
| 910 emitWithOffsetAndLength(TokenType.TEXT, start, -1); | 910 _emitWithOffsetAndLength(TokenType.TEXT, start, -1); |
| 911 } else if (c == 0x22 || c == 0x27) { | 911 } else if (c == 0x22 || c == 0x27) { |
| 912 // read a string | 912 // read a string |
| 913 int endQuote = c; | 913 int endQuote = c; |
| 914 c = advance(); | 914 c = advance(); |
| 915 while (c >= 0) { | 915 while (c >= 0) { |
| 916 if (c == endQuote) { | 916 if (c == endQuote) { |
| 917 c = advance(); | 917 c = advance(); |
| 918 break; | 918 break; |
| 919 } | 919 } |
| 920 c = recordStartOfLineAndAdvance(c); | 920 c = _recordStartOfLineAndAdvance(c); |
| 921 } | 921 } |
| 922 emitWithOffsetAndLength(TokenType.STRING, start, -1); | 922 _emitWithOffsetAndLength(TokenType.STRING, start, -1); |
| 923 } else if (c == 0x3D) { | 923 } else if (c == 0x3D) { |
| 924 // a non-char token | 924 // a non-char token |
| 925 emitWithOffset(TokenType.EQ, start); | 925 _emitWithOffset(TokenType.EQ, start); |
| 926 c = advance(); | 926 c = advance(); |
| 927 } else if (Character.isWhitespace(c)) { | 927 } else if (Character.isWhitespace(c)) { |
| 928 // ignore whitespace in braces | 928 // ignore whitespace in braces |
| 929 do { | 929 do { |
| 930 c = recordStartOfLineAndAdvance(c); | 930 c = _recordStartOfLineAndAdvance(c); |
| 931 } while (Character.isWhitespace(c)); | 931 } while (Character.isWhitespace(c)); |
| 932 } else if (Character.isLetterOrDigit(c)) { | 932 } else if (Character.isLetterOrDigit(c)) { |
| 933 c = advance(); | 933 c = advance(); |
| 934 while (Character.isLetterOrDigit(c) || c == 0x2D || c == 0x5F) { | 934 while (Character.isLetterOrDigit(c) || c == 0x2D || c == 0x5F) { |
| 935 c = advance(); | 935 c = advance(); |
| 936 } | 936 } |
| 937 emitWithOffsetAndLength(TokenType.TAG, start, -1); | 937 _emitWithOffsetAndLength(TokenType.TAG, start, -1); |
| 938 } else { | 938 } else { |
| 939 // a non-char token | 939 // a non-char token |
| 940 emitWithOffsetAndLength(TokenType.TEXT, start, 0); | 940 _emitWithOffsetAndLength(TokenType.TEXT, start, 0); |
| 941 c = advance(); | 941 c = advance(); |
| 942 } | 942 } |
| 943 } | 943 } |
| 944 } | 944 } |
| 945 } | 945 } |
| 946 | 946 |
| 947 /** | 947 /** |
| 948 * Instances of the class `StringScanner` implement a scanner that reads from a
string. The | 948 * Instances of the class `StringScanner` implement a scanner that reads from a
string. The |
| 949 * scanning logic is in the superclass. | 949 * scanning logic is in the superclass. |
| 950 */ | 950 */ |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 * @param writer the writer to which the source is to be written | 1017 * @param writer the writer to which the source is to be written |
| 1018 */ | 1018 */ |
| 1019 ToSourceVisitor(PrintWriter writer) { | 1019 ToSourceVisitor(PrintWriter writer) { |
| 1020 this._writer = writer; | 1020 this._writer = writer; |
| 1021 } | 1021 } |
| 1022 | 1022 |
| 1023 Object visitHtmlScriptTagNode(HtmlScriptTagNode node) => visitXmlTagNode(node)
; | 1023 Object visitHtmlScriptTagNode(HtmlScriptTagNode node) => visitXmlTagNode(node)
; |
| 1024 | 1024 |
| 1025 Object visitHtmlUnit(HtmlUnit node) { | 1025 Object visitHtmlUnit(HtmlUnit node) { |
| 1026 for (XmlTagNode child in node.tagNodes) { | 1026 for (XmlTagNode child in node.tagNodes) { |
| 1027 visit(child); | 1027 _visit(child); |
| 1028 } | 1028 } |
| 1029 return null; | 1029 return null; |
| 1030 } | 1030 } |
| 1031 | 1031 |
| 1032 Object visitXmlAttributeNode(XmlAttributeNode node) { | 1032 Object visitXmlAttributeNode(XmlAttributeNode node) { |
| 1033 String name = node.name; | 1033 String name = node.name; |
| 1034 Token value = node.valueToken; | 1034 Token value = node.valueToken; |
| 1035 if (name.length == 0) { | 1035 if (name.length == 0) { |
| 1036 _writer.print("__"); | 1036 _writer.print("__"); |
| 1037 } else { | 1037 } else { |
| 1038 _writer.print(name); | 1038 _writer.print(name); |
| 1039 } | 1039 } |
| 1040 _writer.print("="); | 1040 _writer.print("="); |
| 1041 if (value == null) { | 1041 if (value == null) { |
| 1042 _writer.print("__"); | 1042 _writer.print("__"); |
| 1043 } else { | 1043 } else { |
| 1044 _writer.print(value.lexeme); | 1044 _writer.print(value.lexeme); |
| 1045 } | 1045 } |
| 1046 return null; | 1046 return null; |
| 1047 } | 1047 } |
| 1048 | 1048 |
| 1049 Object visitXmlTagNode(XmlTagNode node) { | 1049 Object visitXmlTagNode(XmlTagNode node) { |
| 1050 _writer.print("<"); | 1050 _writer.print("<"); |
| 1051 String tagName = node.tag; | 1051 String tagName = node.tag; |
| 1052 _writer.print(tagName); | 1052 _writer.print(tagName); |
| 1053 for (XmlAttributeNode attribute in node.attributes) { | 1053 for (XmlAttributeNode attribute in node.attributes) { |
| 1054 _writer.print(" "); | 1054 _writer.print(" "); |
| 1055 visit(attribute); | 1055 _visit(attribute); |
| 1056 } | 1056 } |
| 1057 _writer.print(node.attributeEnd.lexeme); | 1057 _writer.print(node.attributeEnd.lexeme); |
| 1058 if (node.closingTag != null) { | 1058 if (node.closingTag != null) { |
| 1059 for (XmlTagNode child in node.tagNodes) { | 1059 for (XmlTagNode child in node.tagNodes) { |
| 1060 visit(child); | 1060 _visit(child); |
| 1061 } | 1061 } |
| 1062 _writer.print("</"); | 1062 _writer.print("</"); |
| 1063 _writer.print(tagName); | 1063 _writer.print(tagName); |
| 1064 _writer.print(">"); | 1064 _writer.print(">"); |
| 1065 } | 1065 } |
| 1066 return null; | 1066 return null; |
| 1067 } | 1067 } |
| 1068 | 1068 |
| 1069 /** | 1069 /** |
| 1070 * Safely visit the given node. | 1070 * Safely visit the given node. |
| 1071 * | 1071 * |
| 1072 * @param node the node to be visited | 1072 * @param node the node to be visited |
| 1073 */ | 1073 */ |
| 1074 void visit(XmlNode node) { | 1074 void _visit(XmlNode node) { |
| 1075 if (node != null) { | 1075 if (node != null) { |
| 1076 node.accept(this); | 1076 node.accept(this); |
| 1077 } | 1077 } |
| 1078 } | 1078 } |
| 1079 } | 1079 } |
| 1080 | 1080 |
| 1081 /** | 1081 /** |
| 1082 * The enumeration `TokenType` defines the types of tokens that can be returned
by the | 1082 * The enumeration `TokenType` defines the types of tokens that can be returned
by the |
| 1083 * scanner. | 1083 * scanner. |
| 1084 */ | 1084 */ |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1361 * token stream. | 1361 * token stream. |
| 1362 * | 1362 * |
| 1363 * @return the list of tag nodes found (not `null`, contains no `null`) | 1363 * @return the list of tag nodes found (not `null`, contains no `null`) |
| 1364 */ | 1364 */ |
| 1365 List<XmlTagNode> parseTopTagNodes(Token firstToken) { | 1365 List<XmlTagNode> parseTopTagNodes(Token firstToken) { |
| 1366 _currentToken = firstToken; | 1366 _currentToken = firstToken; |
| 1367 List<XmlTagNode> tagNodes = new List<XmlTagNode>(); | 1367 List<XmlTagNode> tagNodes = new List<XmlTagNode>(); |
| 1368 TokenType type = _currentToken.type; | 1368 TokenType type = _currentToken.type; |
| 1369 while (type != TokenType.EOF) { | 1369 while (type != TokenType.EOF) { |
| 1370 if (identical(type, TokenType.LT)) { | 1370 if (identical(type, TokenType.LT)) { |
| 1371 tagNodes.add(parseTagNode()); | 1371 tagNodes.add(_parseTagNode()); |
| 1372 } else if (identical(type, TokenType.DECLARATION) || identical(type, Token
Type.DIRECTIVE) || identical(type, TokenType.COMMENT)) { | 1372 } else if (identical(type, TokenType.DECLARATION) || identical(type, Token
Type.DIRECTIVE) || identical(type, TokenType.COMMENT)) { |
| 1373 // ignored tokens | 1373 // ignored tokens |
| 1374 _currentToken = _currentToken.next; | 1374 _currentToken = _currentToken.next; |
| 1375 } else { | 1375 } else { |
| 1376 reportUnexpectedToken(); | 1376 _reportUnexpectedToken(); |
| 1377 _currentToken = _currentToken.next; | 1377 _currentToken = _currentToken.next; |
| 1378 } | 1378 } |
| 1379 type = _currentToken.type; | 1379 type = _currentToken.type; |
| 1380 } | 1380 } |
| 1381 return tagNodes; | 1381 return tagNodes; |
| 1382 } | 1382 } |
| 1383 | 1383 |
| 1384 /** | 1384 /** |
| 1385 * Answer the current token. | 1385 * Answer the current token. |
| 1386 * | 1386 * |
| 1387 * @return the current token | 1387 * @return the current token |
| 1388 */ | 1388 */ |
| 1389 Token get currentToken => _currentToken; | 1389 Token get currentToken => _currentToken; |
| 1390 | 1390 |
| 1391 /** | 1391 /** |
| 1392 * Insert a synthetic token of the specified type before the current token | 1392 * Insert a synthetic token of the specified type before the current token |
| 1393 * | 1393 * |
| 1394 * @param type the type of token to be inserted (not `null`) | 1394 * @param type the type of token to be inserted (not `null`) |
| 1395 * @return the synthetic token that was inserted (not `null`) | 1395 * @return the synthetic token that was inserted (not `null`) |
| 1396 */ | 1396 */ |
| 1397 Token insertSyntheticToken(TokenType type) { | 1397 Token _insertSyntheticToken(TokenType type) { |
| 1398 Token token = new Token.con2(type, _currentToken.offset, ""); | 1398 Token token = new Token.con2(type, _currentToken.offset, ""); |
| 1399 _currentToken.previous.setNext(token); | 1399 _currentToken.previous.setNext(token); |
| 1400 token.setNext(_currentToken); | 1400 token.setNext(_currentToken); |
| 1401 return token; | 1401 return token; |
| 1402 } | 1402 } |
| 1403 | 1403 |
| 1404 /** | 1404 /** |
| 1405 * Parse the token stream for an attribute. This method advances the current t
oken over the | 1405 * Parse the token stream for an attribute. This method advances the current t
oken over the |
| 1406 * attribute, but should not be called if the [currentToken] is not [TokenType
#TAG]. | 1406 * attribute, but should not be called if the [currentToken] is not [TokenType
#TAG]. |
| 1407 * | 1407 * |
| 1408 * @return the attribute (not `null`) | 1408 * @return the attribute (not `null`) |
| 1409 */ | 1409 */ |
| 1410 XmlAttributeNode parseAttribute() { | 1410 XmlAttributeNode _parseAttribute() { |
| 1411 // Assume the current token is a tag | 1411 // Assume the current token is a tag |
| 1412 Token name = _currentToken; | 1412 Token name = _currentToken; |
| 1413 _currentToken = _currentToken.next; | 1413 _currentToken = _currentToken.next; |
| 1414 // Equals sign | 1414 // Equals sign |
| 1415 Token equals; | 1415 Token equals; |
| 1416 if (identical(_currentToken.type, TokenType.EQ)) { | 1416 if (identical(_currentToken.type, TokenType.EQ)) { |
| 1417 equals = _currentToken; | 1417 equals = _currentToken; |
| 1418 _currentToken = _currentToken.next; | 1418 _currentToken = _currentToken.next; |
| 1419 } else { | 1419 } else { |
| 1420 reportUnexpectedToken(); | 1420 _reportUnexpectedToken(); |
| 1421 equals = insertSyntheticToken(TokenType.EQ); | 1421 equals = _insertSyntheticToken(TokenType.EQ); |
| 1422 } | 1422 } |
| 1423 // String value | 1423 // String value |
| 1424 Token value; | 1424 Token value; |
| 1425 if (identical(_currentToken.type, TokenType.STRING)) { | 1425 if (identical(_currentToken.type, TokenType.STRING)) { |
| 1426 value = _currentToken; | 1426 value = _currentToken; |
| 1427 _currentToken = _currentToken.next; | 1427 _currentToken = _currentToken.next; |
| 1428 } else { | 1428 } else { |
| 1429 reportUnexpectedToken(); | 1429 _reportUnexpectedToken(); |
| 1430 value = insertSyntheticToken(TokenType.STRING); | 1430 value = _insertSyntheticToken(TokenType.STRING); |
| 1431 } | 1431 } |
| 1432 return createAttributeNode(name, equals, value); | 1432 return createAttributeNode(name, equals, value); |
| 1433 } | 1433 } |
| 1434 | 1434 |
| 1435 /** | 1435 /** |
| 1436 * Parse the stream for a sequence of attributes. This method advances the cur
rent token to the | 1436 * Parse the stream for a sequence of attributes. This method advances the cur
rent token to the |
| 1437 * next [TokenType#GT], [TokenType#SLASH_GT], or [TokenType#EOF]. | 1437 * next [TokenType#GT], [TokenType#SLASH_GT], or [TokenType#EOF]. |
| 1438 * | 1438 * |
| 1439 * @return a collection of zero or more attributes (not `null`, contains no `n
ull`s) | 1439 * @return a collection of zero or more attributes (not `null`, contains no `n
ull`s) |
| 1440 */ | 1440 */ |
| 1441 List<XmlAttributeNode> parseAttributes() { | 1441 List<XmlAttributeNode> _parseAttributes() { |
| 1442 TokenType type = _currentToken.type; | 1442 TokenType type = _currentToken.type; |
| 1443 if (identical(type, TokenType.GT) || identical(type, TokenType.SLASH_GT) ||
identical(type, TokenType.EOF)) { | 1443 if (identical(type, TokenType.GT) || identical(type, TokenType.SLASH_GT) ||
identical(type, TokenType.EOF)) { |
| 1444 return XmlTagNode.NO_ATTRIBUTES; | 1444 return XmlTagNode.NO_ATTRIBUTES; |
| 1445 } | 1445 } |
| 1446 List<XmlAttributeNode> attributes = new List<XmlAttributeNode>(); | 1446 List<XmlAttributeNode> attributes = new List<XmlAttributeNode>(); |
| 1447 while (type != TokenType.GT && type != TokenType.SLASH_GT && type != TokenTy
pe.EOF) { | 1447 while (type != TokenType.GT && type != TokenType.SLASH_GT && type != TokenTy
pe.EOF) { |
| 1448 if (identical(type, TokenType.TAG)) { | 1448 if (identical(type, TokenType.TAG)) { |
| 1449 attributes.add(parseAttribute()); | 1449 attributes.add(_parseAttribute()); |
| 1450 } else { | 1450 } else { |
| 1451 reportUnexpectedToken(); | 1451 _reportUnexpectedToken(); |
| 1452 _currentToken = _currentToken.next; | 1452 _currentToken = _currentToken.next; |
| 1453 } | 1453 } |
| 1454 type = _currentToken.type; | 1454 type = _currentToken.type; |
| 1455 } | 1455 } |
| 1456 return attributes; | 1456 return attributes; |
| 1457 } | 1457 } |
| 1458 | 1458 |
| 1459 /** | 1459 /** |
| 1460 * Parse the stream for a sequence of tag nodes existing within a parent tag n
ode. This method | 1460 * Parse the stream for a sequence of tag nodes existing within a parent tag n
ode. This method |
| 1461 * advances the current token to the next [TokenType#LT_SLASH] or [TokenType#E
OF]. | 1461 * advances the current token to the next [TokenType#LT_SLASH] or [TokenType#E
OF]. |
| 1462 * | 1462 * |
| 1463 * @return a list of nodes (not `null`, contains no `null`s) | 1463 * @return a list of nodes (not `null`, contains no `null`s) |
| 1464 */ | 1464 */ |
| 1465 List<XmlTagNode> parseChildTagNodes() { | 1465 List<XmlTagNode> _parseChildTagNodes() { |
| 1466 TokenType type = _currentToken.type; | 1466 TokenType type = _currentToken.type; |
| 1467 if (identical(type, TokenType.LT_SLASH) || identical(type, TokenType.EOF)) { | 1467 if (identical(type, TokenType.LT_SLASH) || identical(type, TokenType.EOF)) { |
| 1468 return XmlTagNode.NO_TAG_NODES; | 1468 return XmlTagNode.NO_TAG_NODES; |
| 1469 } | 1469 } |
| 1470 List<XmlTagNode> nodes = new List<XmlTagNode>(); | 1470 List<XmlTagNode> nodes = new List<XmlTagNode>(); |
| 1471 while (type != TokenType.LT_SLASH && type != TokenType.EOF) { | 1471 while (type != TokenType.LT_SLASH && type != TokenType.EOF) { |
| 1472 if (identical(type, TokenType.LT)) { | 1472 if (identical(type, TokenType.LT)) { |
| 1473 nodes.add(parseTagNode()); | 1473 nodes.add(_parseTagNode()); |
| 1474 } else if (identical(type, TokenType.COMMENT)) { | 1474 } else if (identical(type, TokenType.COMMENT)) { |
| 1475 // ignored token | 1475 // ignored token |
| 1476 _currentToken = _currentToken.next; | 1476 _currentToken = _currentToken.next; |
| 1477 } else { | 1477 } else { |
| 1478 reportUnexpectedToken(); | 1478 _reportUnexpectedToken(); |
| 1479 _currentToken = _currentToken.next; | 1479 _currentToken = _currentToken.next; |
| 1480 } | 1480 } |
| 1481 type = _currentToken.type; | 1481 type = _currentToken.type; |
| 1482 } | 1482 } |
| 1483 return nodes; | 1483 return nodes; |
| 1484 } | 1484 } |
| 1485 | 1485 |
| 1486 /** | 1486 /** |
| 1487 * Parse the token stream for the next tag node. This method advances current
token over the | 1487 * Parse the token stream for the next tag node. This method advances current
token over the |
| 1488 * parsed tag node, but should only be called if the current token is [TokenTy
pe#LT] | 1488 * parsed tag node, but should only be called if the current token is [TokenTy
pe#LT] |
| 1489 * | 1489 * |
| 1490 * @return the tag node or `null` if none found | 1490 * @return the tag node or `null` if none found |
| 1491 */ | 1491 */ |
| 1492 XmlTagNode parseTagNode() { | 1492 XmlTagNode _parseTagNode() { |
| 1493 // Assume that the current node is a tag node start TokenType#LT | 1493 // Assume that the current node is a tag node start TokenType#LT |
| 1494 Token nodeStart = _currentToken; | 1494 Token nodeStart = _currentToken; |
| 1495 _currentToken = _currentToken.next; | 1495 _currentToken = _currentToken.next; |
| 1496 // Get the tag or create a synthetic tag and report an error | 1496 // Get the tag or create a synthetic tag and report an error |
| 1497 Token tag; | 1497 Token tag; |
| 1498 if (identical(_currentToken.type, TokenType.TAG)) { | 1498 if (identical(_currentToken.type, TokenType.TAG)) { |
| 1499 tag = _currentToken; | 1499 tag = _currentToken; |
| 1500 _currentToken = _currentToken.next; | 1500 _currentToken = _currentToken.next; |
| 1501 } else { | 1501 } else { |
| 1502 reportUnexpectedToken(); | 1502 _reportUnexpectedToken(); |
| 1503 tag = insertSyntheticToken(TokenType.TAG); | 1503 tag = _insertSyntheticToken(TokenType.TAG); |
| 1504 } | 1504 } |
| 1505 // Parse the attributes | 1505 // Parse the attributes |
| 1506 List<XmlAttributeNode> attributes = parseAttributes(); | 1506 List<XmlAttributeNode> attributes = _parseAttributes(); |
| 1507 // Token ending attribute list | 1507 // Token ending attribute list |
| 1508 Token attributeEnd; | 1508 Token attributeEnd; |
| 1509 if (identical(_currentToken.type, TokenType.GT) || identical(_currentToken.t
ype, TokenType.SLASH_GT)) { | 1509 if (identical(_currentToken.type, TokenType.GT) || identical(_currentToken.t
ype, TokenType.SLASH_GT)) { |
| 1510 attributeEnd = _currentToken; | 1510 attributeEnd = _currentToken; |
| 1511 _currentToken = _currentToken.next; | 1511 _currentToken = _currentToken.next; |
| 1512 } else { | 1512 } else { |
| 1513 reportUnexpectedToken(); | 1513 _reportUnexpectedToken(); |
| 1514 attributeEnd = insertSyntheticToken(TokenType.SLASH_GT); | 1514 attributeEnd = _insertSyntheticToken(TokenType.SLASH_GT); |
| 1515 } | 1515 } |
| 1516 // If the node has no children, then return the node | 1516 // If the node has no children, then return the node |
| 1517 if (identical(attributeEnd.type, TokenType.SLASH_GT) || isSelfClosing(tag))
{ | 1517 if (identical(attributeEnd.type, TokenType.SLASH_GT) || isSelfClosing(tag))
{ |
| 1518 return createTagNode(nodeStart, tag, attributes, attributeEnd, XmlTagNode.
NO_TAG_NODES, _currentToken, null, attributeEnd); | 1518 return createTagNode(nodeStart, tag, attributes, attributeEnd, XmlTagNode.
NO_TAG_NODES, _currentToken, null, attributeEnd); |
| 1519 } | 1519 } |
| 1520 // Parse the child tag nodes | 1520 // Parse the child tag nodes |
| 1521 List<XmlTagNode> tagNodes = parseChildTagNodes(); | 1521 List<XmlTagNode> tagNodes = _parseChildTagNodes(); |
| 1522 // Token ending child tag nodes | 1522 // Token ending child tag nodes |
| 1523 Token contentEnd; | 1523 Token contentEnd; |
| 1524 if (identical(_currentToken.type, TokenType.LT_SLASH)) { | 1524 if (identical(_currentToken.type, TokenType.LT_SLASH)) { |
| 1525 contentEnd = _currentToken; | 1525 contentEnd = _currentToken; |
| 1526 _currentToken = _currentToken.next; | 1526 _currentToken = _currentToken.next; |
| 1527 } else { | 1527 } else { |
| 1528 // TODO (danrubel): handle self closing HTML elements by inserting synthet
ic tokens | 1528 // TODO (danrubel): handle self closing HTML elements by inserting synthet
ic tokens |
| 1529 // but not reporting an error | 1529 // but not reporting an error |
| 1530 reportUnexpectedToken(); | 1530 _reportUnexpectedToken(); |
| 1531 contentEnd = insertSyntheticToken(TokenType.LT_SLASH); | 1531 contentEnd = _insertSyntheticToken(TokenType.LT_SLASH); |
| 1532 } | 1532 } |
| 1533 // Closing tag | 1533 // Closing tag |
| 1534 Token closingTag; | 1534 Token closingTag; |
| 1535 if (identical(_currentToken.type, TokenType.TAG)) { | 1535 if (identical(_currentToken.type, TokenType.TAG)) { |
| 1536 closingTag = _currentToken; | 1536 closingTag = _currentToken; |
| 1537 _currentToken = _currentToken.next; | 1537 _currentToken = _currentToken.next; |
| 1538 } else { | 1538 } else { |
| 1539 reportUnexpectedToken(); | 1539 _reportUnexpectedToken(); |
| 1540 closingTag = insertSyntheticToken(TokenType.TAG); | 1540 closingTag = _insertSyntheticToken(TokenType.TAG); |
| 1541 } | 1541 } |
| 1542 // Token ending node | 1542 // Token ending node |
| 1543 Token nodeEnd; | 1543 Token nodeEnd; |
| 1544 if (identical(_currentToken.type, TokenType.GT)) { | 1544 if (identical(_currentToken.type, TokenType.GT)) { |
| 1545 nodeEnd = _currentToken; | 1545 nodeEnd = _currentToken; |
| 1546 _currentToken = _currentToken.next; | 1546 _currentToken = _currentToken.next; |
| 1547 } else { | 1547 } else { |
| 1548 reportUnexpectedToken(); | 1548 _reportUnexpectedToken(); |
| 1549 nodeEnd = insertSyntheticToken(TokenType.GT); | 1549 nodeEnd = _insertSyntheticToken(TokenType.GT); |
| 1550 } | 1550 } |
| 1551 return createTagNode(nodeStart, tag, attributes, attributeEnd, tagNodes, con
tentEnd, closingTag, nodeEnd); | 1551 return createTagNode(nodeStart, tag, attributes, attributeEnd, tagNodes, con
tentEnd, closingTag, nodeEnd); |
| 1552 } | 1552 } |
| 1553 | 1553 |
| 1554 /** | 1554 /** |
| 1555 * Report the current token as unexpected | 1555 * Report the current token as unexpected |
| 1556 */ | 1556 */ |
| 1557 void reportUnexpectedToken() { | 1557 void _reportUnexpectedToken() { |
| 1558 } | 1558 } |
| 1559 } | 1559 } |
| 1560 | 1560 |
| 1561 /** | 1561 /** |
| 1562 * Instances of `XmlTagNode` represent XML or HTML elements such as `` and | 1562 * Instances of `XmlTagNode` represent XML or HTML elements such as `` and |
| 1563 * `<body foo="bar"> ... </body>`. | 1563 * `<body foo="bar"> ... </body>`. |
| 1564 */ | 1564 */ |
| 1565 class XmlTagNode extends XmlNode { | 1565 class XmlTagNode extends XmlNode { |
| 1566 /** | 1566 /** |
| 1567 * Constant representing empty list of attributes. | 1567 * Constant representing empty list of attributes. |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1863 */ | 1863 */ |
| 1864 HtmlUnit parse(Token token, LineInfo lineInfo) { | 1864 HtmlUnit parse(Token token, LineInfo lineInfo) { |
| 1865 this._lineInfo = lineInfo; | 1865 this._lineInfo = lineInfo; |
| 1866 List<XmlTagNode> tagNodes = parseTopTagNodes(token); | 1866 List<XmlTagNode> tagNodes = parseTopTagNodes(token); |
| 1867 return new HtmlUnit(token, tagNodes, currentToken); | 1867 return new HtmlUnit(token, tagNodes, currentToken); |
| 1868 } | 1868 } |
| 1869 | 1869 |
| 1870 XmlAttributeNode createAttributeNode(Token name, Token equals, Token value) =>
new XmlAttributeNode(name, equals, value); | 1870 XmlAttributeNode createAttributeNode(Token name, Token equals, Token value) =>
new XmlAttributeNode(name, equals, value); |
| 1871 | 1871 |
| 1872 XmlTagNode createTagNode(Token nodeStart, Token tag, List<XmlAttributeNode> at
tributes, Token attributeEnd, List<XmlTagNode> tagNodes, Token contentEnd, Token
closingTag, Token nodeEnd) { | 1872 XmlTagNode createTagNode(Token nodeStart, Token tag, List<XmlAttributeNode> at
tributes, Token attributeEnd, List<XmlTagNode> tagNodes, Token contentEnd, Token
closingTag, Token nodeEnd) { |
| 1873 if (isScriptNode(tag, attributes, tagNodes)) { | 1873 if (_isScriptNode(tag, attributes, tagNodes)) { |
| 1874 HtmlScriptTagNode tagNode = new HtmlScriptTagNode(nodeStart, tag, attribut
es, attributeEnd, tagNodes, contentEnd, closingTag, nodeEnd); | 1874 HtmlScriptTagNode tagNode = new HtmlScriptTagNode(nodeStart, tag, attribut
es, attributeEnd, tagNodes, contentEnd, closingTag, nodeEnd); |
| 1875 String contents = tagNode.content; | 1875 String contents = tagNode.content; |
| 1876 int contentOffset = attributeEnd.end; | 1876 int contentOffset = attributeEnd.end; |
| 1877 LineInfo_Location location = _lineInfo.getLocation(contentOffset); | 1877 LineInfo_Location location = _lineInfo.getLocation(contentOffset); |
| 1878 sc.Scanner scanner = new sc.Scanner(source, new sc.SubSequenceReader(conte
nts, contentOffset), _errorListener); | 1878 sc.Scanner scanner = new sc.Scanner(source, new sc.SubSequenceReader(conte
nts, contentOffset), _errorListener); |
| 1879 scanner.setSourceStart(location.lineNumber, location.columnNumber); | 1879 scanner.setSourceStart(location.lineNumber, location.columnNumber); |
| 1880 sc.Token firstToken = scanner.tokenize(); | 1880 sc.Token firstToken = scanner.tokenize(); |
| 1881 Parser parser = new Parser(source, _errorListener); | 1881 Parser parser = new Parser(source, _errorListener); |
| 1882 CompilationUnit unit = parser.parseCompilationUnit(firstToken); | 1882 CompilationUnit unit = parser.parseCompilationUnit(firstToken); |
| 1883 unit.lineInfo = _lineInfo; | 1883 unit.lineInfo = _lineInfo; |
| 1884 tagNode.script = unit; | 1884 tagNode.script = unit; |
| 1885 return tagNode; | 1885 return tagNode; |
| 1886 } | 1886 } |
| 1887 return new XmlTagNode(nodeStart, tag, attributes, attributeEnd, tagNodes, co
ntentEnd, closingTag, nodeEnd); | 1887 return new XmlTagNode(nodeStart, tag, attributes, attributeEnd, tagNodes, co
ntentEnd, closingTag, nodeEnd); |
| 1888 } | 1888 } |
| 1889 | 1889 |
| 1890 bool isSelfClosing(Token tag) => SELF_CLOSING.contains(tag.lexeme); | 1890 bool isSelfClosing(Token tag) => SELF_CLOSING.contains(tag.lexeme); |
| 1891 | 1891 |
| 1892 /** | 1892 /** |
| 1893 * Determine if the specified node is a Dart script. | 1893 * Determine if the specified node is a Dart script. |
| 1894 * | 1894 * |
| 1895 * @param node the node to be tested (not `null`) | 1895 * @param node the node to be tested (not `null`) |
| 1896 * @return `true` if the node is a Dart script | 1896 * @return `true` if the node is a Dart script |
| 1897 */ | 1897 */ |
| 1898 bool isScriptNode(Token tag, List<XmlAttributeNode> attributes, List<XmlTagNod
e> tagNodes) { | 1898 bool _isScriptNode(Token tag, List<XmlAttributeNode> attributes, List<XmlTagNo
de> tagNodes) { |
| 1899 if (tagNodes.length != 0 || tag.lexeme != _SCRIPT) { | 1899 if (tagNodes.length != 0 || tag.lexeme != _SCRIPT) { |
| 1900 return false; | 1900 return false; |
| 1901 } | 1901 } |
| 1902 for (XmlAttributeNode attribute in attributes) { | 1902 for (XmlAttributeNode attribute in attributes) { |
| 1903 if (attribute.name == _TYPE) { | 1903 if (attribute.name == _TYPE) { |
| 1904 Token valueToken = attribute.valueToken; | 1904 Token valueToken = attribute.valueToken; |
| 1905 if (valueToken != null) { | 1905 if (valueToken != null) { |
| 1906 String value = valueToken.lexeme; | 1906 String value = valueToken.lexeme; |
| 1907 if (value == _APPLICATION_DART_IN_DOUBLE_QUOTES || value == _APPLICATI
ON_DART_IN_SINGLE_QUOTES) { | 1907 if (value == _APPLICATION_DART_IN_DOUBLE_QUOTES || value == _APPLICATI
ON_DART_IN_SINGLE_QUOTES) { |
| 1908 return true; | 1908 return true; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1969 } | 1969 } |
| 1970 super.element = element; | 1970 super.element = element; |
| 1971 } | 1971 } |
| 1972 | 1972 |
| 1973 void visitChildren(XmlVisitor visitor) { | 1973 void visitChildren(XmlVisitor visitor) { |
| 1974 for (XmlTagNode node in _tagNodes) { | 1974 for (XmlTagNode node in _tagNodes) { |
| 1975 node.accept(visitor); | 1975 node.accept(visitor); |
| 1976 } | 1976 } |
| 1977 } | 1977 } |
| 1978 } | 1978 } |
| OLD | NEW |