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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 ASTNode node = new NodeLocator.con1(offset).searchWithin(expression); | 159 ASTNode node = new NodeLocator.con1(offset).searchWithin(expression); |
160 if (node != null) { | 160 if (node != null) { |
161 Element element = ElementLocator.locate(node); | 161 Element element = ElementLocator.locate(node); |
162 return new XmlExpression_Reference(element, node.offset, node.length); | 162 return new XmlExpression_Reference(element, node.offset, node.length); |
163 } | 163 } |
164 return null; | 164 return null; |
165 } | 165 } |
166 } | 166 } |
167 | 167 |
168 /** | 168 /** |
169 * Instances of `HtmlParseResult` hold the result of parsing an HTML file. | |
170 * | |
171 * @coverage dart.engine.html | |
172 */ | |
173 class HtmlParseResult extends HtmlScanResult { | |
174 /** | |
175 * The unit containing the parsed information (not `null`). | |
176 */ | |
177 HtmlUnit _unit; | |
178 | |
179 HtmlParseResult(int modificationTime, Token token, List<int> lineStarts, HtmlU
nit unit) : super(modificationTime, token, lineStarts) { | |
180 this._unit = unit; | |
181 } | |
182 | |
183 /** | |
184 * Answer the unit generated by parsing the source | |
185 * | |
186 * @return the unit (not `null`) | |
187 */ | |
188 HtmlUnit get htmlUnit => _unit; | |
189 } | |
190 | |
191 /** | |
192 * Instances of the class `RecursiveXmlVisitor` implement an XML visitor that wi
ll recursively | 169 * Instances of the class `RecursiveXmlVisitor` implement an XML visitor that wi
ll recursively |
193 * visit all of the nodes in an XML structure. For example, using an instance of
this class to visit | 170 * visit all of the nodes in an XML structure. For example, using an instance of
this class to visit |
194 * a [XmlTagNode] will also cause all of the contained [XmlAttributeNode]s and | 171 * a [XmlTagNode] will also cause all of the contained [XmlAttributeNode]s and |
195 * [XmlTagNode]s to be visited. | 172 * [XmlTagNode]s to be visited. |
196 * | 173 * |
197 * Subclasses that override a visit method must either invoke the overridden vis
it method or must | 174 * Subclasses that override a visit method must either invoke the overridden vis
it method or must |
198 * explicitly ask the visited node to visit its children. Failure to do so will
cause the children | 175 * explicitly ask the visited node to visit its children. Failure to do so will
cause the children |
199 * of the visited node to not be visited. | 176 * of the visited node to not be visited. |
200 * | 177 * |
201 * @coverage dart.engine.html | 178 * @coverage dart.engine.html |
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 } else { | 946 } else { |
970 // a non-char token | 947 // a non-char token |
971 emit3(TokenType.TEXT, start, 0); | 948 emit3(TokenType.TEXT, start, 0); |
972 c = advance(); | 949 c = advance(); |
973 } | 950 } |
974 } | 951 } |
975 } | 952 } |
976 } | 953 } |
977 | 954 |
978 /** | 955 /** |
979 * Instances of `HtmlScanResult` hold the result of scanning an HTML file. | |
980 * | |
981 * @coverage dart.engine.html | |
982 */ | |
983 class HtmlScanResult { | |
984 /** | |
985 * The time at which the contents of the source were last set. | |
986 */ | |
987 final int modificationTime; | |
988 | |
989 /** | |
990 * The first token in the token stream (not `null`). | |
991 */ | |
992 final Token token; | |
993 | |
994 /** | |
995 * The line start information that was produced. | |
996 */ | |
997 final List<int> lineStarts; | |
998 | |
999 HtmlScanResult(this.modificationTime, this.token, this.lineStarts); | |
1000 } | |
1001 | |
1002 /** | |
1003 * Instances of the class `StringScanner` implement a scanner that reads from a
string. The | 956 * Instances of the class `StringScanner` implement a scanner that reads from a
string. The |
1004 * scanning logic is in the superclass. | 957 * scanning logic is in the superclass. |
1005 * | 958 * |
1006 * @coverage dart.engine.html | 959 * @coverage dart.engine.html |
1007 */ | 960 */ |
1008 class StringScanner extends AbstractScanner { | 961 class StringScanner extends AbstractScanner { |
1009 /** | 962 /** |
1010 * The string from which characters will be read. | 963 * The string from which characters will be read. |
1011 */ | 964 */ |
1012 String _string; | 965 String _string; |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1359 int length = 0; | 1312 int length = 0; |
1360 | 1313 |
1361 XmlExpression_Reference(Element element, int offset, int length) { | 1314 XmlExpression_Reference(Element element, int offset, int length) { |
1362 this.element = element; | 1315 this.element = element; |
1363 this.offset = offset; | 1316 this.offset = offset; |
1364 this.length = length; | 1317 this.length = length; |
1365 } | 1318 } |
1366 } | 1319 } |
1367 | 1320 |
1368 /** | 1321 /** |
1369 * Instances of `HtmlScanner` receive and scan HTML content from a [Source].<br/
> | |
1370 * For example, the following code scans HTML source and returns the result: | |
1371 * | |
1372 * <pre> | |
1373 * HtmlScanner scanner = new HtmlScanner(source); | |
1374 * source.getContents(scanner); | |
1375 * return scanner.getResult(); | |
1376 * </pre> | |
1377 * | |
1378 * @coverage dart.engine.html | |
1379 */ | |
1380 class HtmlScanner implements Source_ContentReceiver { | |
1381 List<String> _SCRIPT_TAG = <String> ["script"]; | |
1382 | |
1383 /** | |
1384 * The source being scanned (not `null`) | |
1385 */ | |
1386 Source _source; | |
1387 | |
1388 /** | |
1389 * The time at which the contents of the source were last set. | |
1390 */ | |
1391 int _modificationTime = 0; | |
1392 | |
1393 /** | |
1394 * The scanner used to scan the source | |
1395 */ | |
1396 AbstractScanner _scanner; | |
1397 | |
1398 /** | |
1399 * The first token in the token stream. | |
1400 */ | |
1401 Token _token; | |
1402 | |
1403 /** | |
1404 * Construct a new instance to scan the specified source. | |
1405 * | |
1406 * @param source the source to be scanned (not `null`) | |
1407 */ | |
1408 HtmlScanner(Source source) { | |
1409 this._source = source; | |
1410 } | |
1411 | |
1412 void accept(String contents, int modificationTime) { | |
1413 this._modificationTime = modificationTime; | |
1414 _scanner = new StringScanner(_source, contents); | |
1415 _scanner.passThroughElements = _SCRIPT_TAG; | |
1416 _token = _scanner.tokenize(); | |
1417 } | |
1418 | |
1419 /** | |
1420 * Answer the result of scanning the source | |
1421 * | |
1422 * @return the result (not `null`) | |
1423 */ | |
1424 HtmlScanResult get result => new HtmlScanResult(_modificationTime, _token, _sc
anner.lineStarts); | |
1425 } | |
1426 | |
1427 /** | |
1428 * Instances of the class `XmlParser` are used to parse tokens into a AST struct
ure comprised | 1322 * Instances of the class `XmlParser` are used to parse tokens into a AST struct
ure comprised |
1429 * of [XmlNode]s. | 1323 * of [XmlNode]s. |
1430 * | 1324 * |
1431 * @coverage dart.engine.html | 1325 * @coverage dart.engine.html |
1432 */ | 1326 */ |
1433 class XmlParser { | 1327 class XmlParser { |
1434 /** | 1328 /** |
1435 * The source being parsed. | 1329 * The source being parsed. |
1436 */ | 1330 */ |
1437 final Source source; | 1331 final Source source; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1484 | 1378 |
1485 /** | 1379 /** |
1486 * Parse the entire token stream and in the process, advance the current token
to the end of the | 1380 * Parse the entire token stream and in the process, advance the current token
to the end of the |
1487 * token stream. | 1381 * token stream. |
1488 * | 1382 * |
1489 * @return the list of tag nodes found (not `null`, contains no `null`) | 1383 * @return the list of tag nodes found (not `null`, contains no `null`) |
1490 */ | 1384 */ |
1491 List<XmlTagNode> parseTopTagNodes(Token firstToken) { | 1385 List<XmlTagNode> parseTopTagNodes(Token firstToken) { |
1492 _currentToken = firstToken; | 1386 _currentToken = firstToken; |
1493 List<XmlTagNode> tagNodes = new List<XmlTagNode>(); | 1387 List<XmlTagNode> tagNodes = new List<XmlTagNode>(); |
1494 while (true) { | 1388 TokenType type = _currentToken.type; |
1495 while (true) { | 1389 while (type != TokenType.EOF) { |
1496 if (_currentToken.type == TokenType.LT) { | 1390 if (identical(type, TokenType.LT)) { |
1497 tagNodes.add(parseTagNode()); | 1391 tagNodes.add(parseTagNode()); |
1498 } else if (_currentToken.type == TokenType.DECLARATION || _currentToken.
type == TokenType.DIRECTIVE || _currentToken.type == TokenType.COMMENT) { | 1392 } else if (identical(type, TokenType.DECLARATION) || identical(type, Token
Type.DIRECTIVE) || identical(type, TokenType.COMMENT)) { |
1499 // ignored tokens | 1393 // ignored tokens |
1500 _currentToken = _currentToken.next; | 1394 _currentToken = _currentToken.next; |
1501 } else if (_currentToken.type == TokenType.EOF) { | 1395 } else { |
1502 return tagNodes; | 1396 reportUnexpectedToken(); |
1503 } else { | 1397 _currentToken = _currentToken.next; |
1504 reportUnexpectedToken(); | |
1505 _currentToken = _currentToken.next; | |
1506 } | |
1507 break; | |
1508 } | 1398 } |
| 1399 type = _currentToken.type; |
1509 } | 1400 } |
| 1401 return tagNodes; |
1510 } | 1402 } |
1511 | 1403 |
1512 /** | 1404 /** |
1513 * Answer the current token. | 1405 * Answer the current token. |
1514 * | 1406 * |
1515 * @return the current token | 1407 * @return the current token |
1516 */ | 1408 */ |
1517 Token get currentToken => _currentToken; | 1409 Token get currentToken => _currentToken; |
1518 | 1410 |
1519 /** | 1411 /** |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1565 * next [TokenType#GT], [TokenType#SLASH_GT], or [TokenType#EOF]. | 1457 * next [TokenType#GT], [TokenType#SLASH_GT], or [TokenType#EOF]. |
1566 * | 1458 * |
1567 * @return a collection of zero or more attributes (not `null`, contains no `n
ull`s) | 1459 * @return a collection of zero or more attributes (not `null`, contains no `n
ull`s) |
1568 */ | 1460 */ |
1569 List<XmlAttributeNode> parseAttributes() { | 1461 List<XmlAttributeNode> parseAttributes() { |
1570 TokenType type = _currentToken.type; | 1462 TokenType type = _currentToken.type; |
1571 if (identical(type, TokenType.GT) || identical(type, TokenType.SLASH_GT) ||
identical(type, TokenType.EOF)) { | 1463 if (identical(type, TokenType.GT) || identical(type, TokenType.SLASH_GT) ||
identical(type, TokenType.EOF)) { |
1572 return XmlTagNode.NO_ATTRIBUTES; | 1464 return XmlTagNode.NO_ATTRIBUTES; |
1573 } | 1465 } |
1574 List<XmlAttributeNode> attributes = new List<XmlAttributeNode>(); | 1466 List<XmlAttributeNode> attributes = new List<XmlAttributeNode>(); |
1575 while (true) { | 1467 while (type != TokenType.GT && type != TokenType.SLASH_GT && type != TokenTy
pe.EOF) { |
1576 while (true) { | 1468 if (identical(type, TokenType.TAG)) { |
1577 if (_currentToken.type == TokenType.GT || _currentToken.type == TokenTyp
e.SLASH_GT || _currentToken.type == TokenType.EOF) { | 1469 attributes.add(parseAttribute()); |
1578 return attributes; | 1470 } else { |
1579 } else if (_currentToken.type == TokenType.TAG) { | 1471 reportUnexpectedToken(); |
1580 attributes.add(parseAttribute()); | 1472 _currentToken = _currentToken.next; |
1581 } else { | |
1582 reportUnexpectedToken(); | |
1583 _currentToken = _currentToken.next; | |
1584 } | |
1585 break; | |
1586 } | 1473 } |
| 1474 type = _currentToken.type; |
1587 } | 1475 } |
| 1476 return attributes; |
1588 } | 1477 } |
1589 | 1478 |
1590 /** | 1479 /** |
1591 * Parse the stream for a sequence of tag nodes existing within a parent tag n
ode. This method | 1480 * Parse the stream for a sequence of tag nodes existing within a parent tag n
ode. This method |
1592 * advances the current token to the next [TokenType#LT_SLASH] or [TokenType#E
OF]. | 1481 * advances the current token to the next [TokenType#LT_SLASH] or [TokenType#E
OF]. |
1593 * | 1482 * |
1594 * @return a list of nodes (not `null`, contains no `null`s) | 1483 * @return a list of nodes (not `null`, contains no `null`s) |
1595 */ | 1484 */ |
1596 List<XmlTagNode> parseChildTagNodes() { | 1485 List<XmlTagNode> parseChildTagNodes() { |
1597 TokenType type = _currentToken.type; | 1486 TokenType type = _currentToken.type; |
1598 if (identical(type, TokenType.LT_SLASH) || identical(type, TokenType.EOF)) { | 1487 if (identical(type, TokenType.LT_SLASH) || identical(type, TokenType.EOF)) { |
1599 return XmlTagNode.NO_TAG_NODES; | 1488 return XmlTagNode.NO_TAG_NODES; |
1600 } | 1489 } |
1601 List<XmlTagNode> nodes = new List<XmlTagNode>(); | 1490 List<XmlTagNode> nodes = new List<XmlTagNode>(); |
1602 while (true) { | 1491 while (type != TokenType.LT_SLASH && type != TokenType.EOF) { |
1603 while (true) { | 1492 if (identical(type, TokenType.LT)) { |
1604 if (_currentToken.type == TokenType.LT) { | 1493 nodes.add(parseTagNode()); |
1605 nodes.add(parseTagNode()); | 1494 } else if (identical(type, TokenType.COMMENT)) { |
1606 } else if (_currentToken.type == TokenType.LT_SLASH || _currentToken.typ
e == TokenType.EOF) { | 1495 // ignored token |
1607 return nodes; | 1496 _currentToken = _currentToken.next; |
1608 } else if (_currentToken.type == TokenType.COMMENT) { | 1497 } else { |
1609 // ignored token | 1498 reportUnexpectedToken(); |
1610 _currentToken = _currentToken.next; | 1499 _currentToken = _currentToken.next; |
1611 } else { | |
1612 reportUnexpectedToken(); | |
1613 _currentToken = _currentToken.next; | |
1614 } | |
1615 break; | |
1616 } | 1500 } |
| 1501 type = _currentToken.type; |
1617 } | 1502 } |
| 1503 return nodes; |
1618 } | 1504 } |
1619 | 1505 |
1620 /** | 1506 /** |
1621 * Parse the token stream for the next tag node. This method advances current
token over the | 1507 * Parse the token stream for the next tag node. This method advances current
token over the |
1622 * parsed tag node, but should only be called if the current token is [TokenTy
pe#LT] | 1508 * parsed tag node, but should only be called if the current token is [TokenTy
pe#LT] |
1623 * | 1509 * |
1624 * @return the tag node or `null` if none found | 1510 * @return the tag node or `null` if none found |
1625 */ | 1511 */ |
1626 XmlTagNode parseTagNode() { | 1512 XmlTagNode parseTagNode() { |
1627 // Assume that the current node is a tag node start TokenType#LT | 1513 // Assume that the current node is a tag node start TokenType#LT |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1990 * Construct a parser for the specified source. | 1876 * Construct a parser for the specified source. |
1991 * | 1877 * |
1992 * @param source the source being parsed | 1878 * @param source the source being parsed |
1993 * @param errorListener the error listener to which errors will be reported | 1879 * @param errorListener the error listener to which errors will be reported |
1994 */ | 1880 */ |
1995 HtmlParser(Source source, AnalysisErrorListener errorListener) : super(source)
{ | 1881 HtmlParser(Source source, AnalysisErrorListener errorListener) : super(source)
{ |
1996 this._errorListener = errorListener; | 1882 this._errorListener = errorListener; |
1997 } | 1883 } |
1998 | 1884 |
1999 /** | 1885 /** |
2000 * Parse the tokens specified by the given scan result. | 1886 * Parse the given tokens. |
2001 * | 1887 * |
2002 * @param scanResult the result of scanning an HTML source (not `null`) | 1888 * @param token the first token in the stream of tokens to be parsed |
| 1889 * @param lineInfo the line information created by the scanner |
2003 * @return the parse result (not `null`) | 1890 * @return the parse result (not `null`) |
2004 */ | 1891 */ |
2005 HtmlParseResult parse(HtmlScanResult scanResult) { | 1892 HtmlUnit parse(Token token, LineInfo lineInfo) { |
2006 List<int> lineStarts = scanResult.lineStarts; | 1893 this._lineInfo = lineInfo; |
2007 _lineInfo = new LineInfo(lineStarts); | 1894 List<XmlTagNode> tagNodes = parseTopTagNodes(token); |
2008 Token firstToken = scanResult.token; | 1895 return new HtmlUnit(token, tagNodes, currentToken); |
2009 List<XmlTagNode> tagNodes = parseTopTagNodes(firstToken); | |
2010 HtmlUnit unit = new HtmlUnit(firstToken, tagNodes, currentToken); | |
2011 return new HtmlParseResult(scanResult.modificationTime, firstToken, scanResu
lt.lineStarts, unit); | |
2012 } | |
2013 | |
2014 /** | |
2015 * Scan then parse the specified source. | |
2016 * | |
2017 * @param source the source to be scanned and parsed (not `null`) | |
2018 * @return the parse result (not `null`) | |
2019 */ | |
2020 HtmlParseResult parse2(Source source) { | |
2021 HtmlScanner scanner = new HtmlScanner(source); | |
2022 source.getContents(scanner); | |
2023 return parse(scanner.result); | |
2024 } | 1896 } |
2025 | 1897 |
2026 XmlAttributeNode createAttributeNode(Token name, Token equals, Token value) =>
new XmlAttributeNode(name, equals, value); | 1898 XmlAttributeNode createAttributeNode(Token name, Token equals, Token value) =>
new XmlAttributeNode(name, equals, value); |
2027 | 1899 |
2028 XmlTagNode createTagNode(Token nodeStart, Token tag, List<XmlAttributeNode> at
tributes, Token attributeEnd, List<XmlTagNode> tagNodes, Token contentEnd, Token
closingTag, Token nodeEnd) { | 1900 XmlTagNode createTagNode(Token nodeStart, Token tag, List<XmlAttributeNode> at
tributes, Token attributeEnd, List<XmlTagNode> tagNodes, Token contentEnd, Token
closingTag, Token nodeEnd) { |
2029 if (isScriptNode(tag, attributes, tagNodes)) { | 1901 if (isScriptNode(tag, attributes, tagNodes)) { |
2030 HtmlScriptTagNode tagNode = new HtmlScriptTagNode(nodeStart, tag, attribut
es, attributeEnd, tagNodes, contentEnd, closingTag, nodeEnd); | 1902 HtmlScriptTagNode tagNode = new HtmlScriptTagNode(nodeStart, tag, attribut
es, attributeEnd, tagNodes, contentEnd, closingTag, nodeEnd); |
2031 String contents = tagNode.content; | 1903 String contents = tagNode.content; |
2032 int contentOffset = attributeEnd.end; | 1904 int contentOffset = attributeEnd.end; |
2033 LineInfo_Location location = _lineInfo.getLocation(contentOffset); | 1905 LineInfo_Location location = _lineInfo.getLocation(contentOffset); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2127 } | 1999 } |
2128 super.element = element; | 2000 super.element = element; |
2129 } | 2001 } |
2130 | 2002 |
2131 void visitChildren(XmlVisitor visitor) { | 2003 void visitChildren(XmlVisitor visitor) { |
2132 for (XmlTagNode node in _tagNodes) { | 2004 for (XmlTagNode node in _tagNodes) { |
2133 node.accept(visitor); | 2005 node.accept(visitor); |
2134 } | 2006 } |
2135 } | 2007 } |
2136 } | 2008 } |
OLD | NEW |