treesitter_types_css/lib.rs
1//! Strongly-typed AST types for CSS, auto-generated from
2//! [`tree-sitter-css`](https://docs.rs/tree-sitter-css)'s `node-types.json`.
3//!
4//! This crate is generated by [`treesitter-types`](https://docs.rs/treesitter-types) and is
5//! automatically kept up to date when a new version of the grammar crate is released.
6//!
7//! These types have been tested by parsing the
8//! [Bootstrap](https://github.com/twbs/bootstrap) source code.
9//!
10//! See the [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) project for more
11//! information about the underlying parser framework.
12//!
13//! # Example
14//!
15//! ```
16//! use treesitter_types_css::*;
17//!
18//! // A small CSS stylesheet.
19//! let src = b"\
20//! body {
21//! color: red;
22//! font-size: 16px;
23//! }
24//! ";
25//!
26//! // Parse the source with tree-sitter and convert into typed AST.
27//! let mut parser = tree_sitter::Parser::new();
28//! parser.set_language(&tree_sitter_css::LANGUAGE.into()).unwrap();
29//! let tree = parser.parse(src, None).unwrap();
30//! let stylesheet = Stylesheet::from_node(tree.root_node(), src).unwrap();
31//!
32//! // The stylesheet has one top-level child: a rule set for `body`.
33//! assert_eq!(stylesheet.children.len(), 1);
34//!
35//! let StylesheetChildren::RuleSet(rule_set) = &stylesheet.children[0] else {
36//! panic!("expected a rule set");
37//! };
38//! // The rule set contains the selector and declarations.
39//! assert!(!rule_set.children.is_empty());
40//! assert_eq!(rule_set.span.start.row, 0);
41//! ```
42
43pub use tree_sitter_css;
44pub use treesitter_types::tree_sitter;
45pub use treesitter_types::{FromNode, LeafNode, ParseError, Span, Spanned};
46
47mod generated;
48pub use generated::*;