treesitter_types_toml/lib.rs
1//! Strongly-typed AST types for TOML, auto-generated from
2//! [`tree-sitter-toml-ng`](https://docs.rs/tree-sitter-toml-ng)'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//! See the [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) project for more
8//! information about the underlying parser framework.
9//!
10//! # Example
11//!
12//! ```
13//! use treesitter_types_toml::*;
14//!
15//! // A small TOML document.
16//! let src = b"\
17//! [package]
18//! name = \"hello\"
19//! version = \"1.0.0\"
20//! ";
21//!
22//! // Parse the source with tree-sitter and convert into typed AST.
23//! let mut parser = tree_sitter::Parser::new();
24//! parser.set_language(&tree_sitter_toml_ng::LANGUAGE.into()).unwrap();
25//! let tree = parser.parse(src, None).unwrap();
26//! let document = Document::from_node(tree.root_node(), src).unwrap();
27//!
28//! // The document has one top-level child: a [package] table.
29//! assert_eq!(document.children.len(), 1);
30//!
31//! let DocumentChildren::Table(table) = &document.children[0] else {
32//! panic!("expected a table");
33//! };
34//! // The table contains the key-value pairs: `name` and `version`.
35//! assert!(!table.children.is_empty());
36//! assert_eq!(table.span.start.row, 0);
37//! ```
38
39pub use tree_sitter_toml_ng;
40pub use treesitter_types::tree_sitter;
41pub use treesitter_types::{FromNode, LeafNode, ParseError, Span, Spanned};
42
43mod generated;
44pub use generated::*;