Skip to main content

Crate treesitter_types_html

Crate treesitter_types_html 

Source
Expand description

Strongly-typed AST types for HTML, auto-generated from tree-sitter-html’s node-types.json.

This crate is generated by treesitter-types and is automatically kept up to date when a new version of the grammar crate is released.

These types have been tested by parsing the NiceHashQuickMiner source code.

See the Tree-sitter project for more information about the underlying parser framework.

§Example

use treesitter_types_html::*;

// A minimal HTML document.
let src = b"\
<!DOCTYPE html>
<html>
  <body>
    <h1>Hello, World!</h1>
  </body>
</html>
";

// Parse the source with tree-sitter and convert into typed AST.
let mut parser = tree_sitter::Parser::new();
parser.set_language(&tree_sitter_html::LANGUAGE.into()).unwrap();
let tree = parser.parse(src, None).unwrap();
let document = Document::from_node(tree.root_node(), src).unwrap();

// The document contains the doctype and the <html> element.
assert!(!document.children.is_empty());

// The first child is the doctype declaration.
let DocumentChildren::Doctype(doctype) = &document.children[0] else {
    panic!("expected a doctype");
};
assert_eq!(doctype.span.start.row, 0);

// The second child is the <html> element.
let DocumentChildren::Element(html_elem) = &document.children[1] else {
    panic!("expected an element");
};
// The <html> element contains child elements (<body>, text, etc.).
assert!(!html_elem.children.is_empty());

Re-exports§

pub use tree_sitter_html;
pub use treesitter_types::tree_sitter;

Structs§

Attribute
AttributeName
AttributeValue
Comment
Doctype
Document
Element
EndTag
Entity
ErroneousEndTag
ErroneousEndTagName
QuotedAttributeValue
RawText
ScriptElement
SelfClosingTag
Span
StartTag
StyleElement
TagName
Text

Enums§

AnyNode
AttributeChildren
DocumentChildren
ElementChildren
ParseError
ScriptElementChildren
SelfClosingTagChildren
StartTagChildren
StyleElementChildren

Traits§

FromNode
Every generated struct and enum implements this.
LeafNode
Implemented by every generated leaf type (identifiers, literals, etc.)
Spanned
Implemented by every generated type that has a source location.