treesitter_types_json/lib.rs
1//! Strongly-typed AST types for JSON, auto-generated from
2//! [`tree-sitter-json`](https://docs.rs/tree-sitter-json)'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//! [SchemaStore](https://github.com/SchemaStore/schemastore) 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_json::*;
17//!
18//! // A small JSON document.
19//! let src = b"\
20//! {
21//! \"name\": \"hello\",
22//! \"version\": 42
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_json::LANGUAGE.into()).unwrap();
29//! let tree = parser.parse(src, None).unwrap();
30//! let document = Document::from_node(tree.root_node(), src).unwrap();
31//!
32//! // The document contains one top-level value: a JSON object.
33//! assert_eq!(document.children.len(), 1);
34//! let Value::Object(object) = &document.children[0] else {
35//! panic!("expected an object");
36//! };
37//!
38//! // The object has two key-value pairs.
39//! assert_eq!(object.children.len(), 2);
40//!
41//! // First pair: "name" => "hello".
42//! let first_pair = &object.children[0];
43//! assert_eq!(first_pair.key.span.start.row, 1);
44//!
45//! // Second pair: "version" => 42.
46//! let second_pair = &object.children[1];
47//! let Value::Number(num) = &second_pair.value else {
48//! panic!("expected a number");
49//! };
50//! assert_eq!(num.text(), "42");
51//! ```
52
53pub use tree_sitter_json;
54pub use treesitter_types::tree_sitter;
55pub use treesitter_types::{FromNode, LeafNode, ParseError, Span, Spanned};
56
57mod generated;
58pub use generated::*;