1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/// From <https://github.com/serde-rs/json/issues/404#issuecomment-892957228>
use crate::;
pub use *;
pub use *;
pub use *;
pub use *;
/// Generate source code (tokens) for typed AST node wrappers.
///
/// # Parameters
/// - `types`: Anything that can be converted to a `NodeTypeMap`
///
/// # Examples
///
/// Using a file path:
///
/// ```rust
/// use type_sitter_gen::generate_nodes;
/// use std::path::Path;
///
/// fn main() {
/// let path = Path::new("../vendor/tree-sitter-rust/src/node-types.json");
/// let code = generate_nodes(path).unwrap().into_string();
/// assert!(code.contains("pub struct TraitItem"));
/// }
/// ```
///
/// Using the contents of `node-types.json` directly:
///
/// ```rust
/// use type_sitter_gen::generate_nodes;
///
/// fn main() {
/// let contents: &str = tree_sitter_rust::NODE_TYPES;
/// let code = generate_nodes(contents).unwrap().into_string();
/// assert!(code.contains("pub struct TraitItem"));
/// }
/// ```
///
/// Using a `NodeTypeMap`:
///
/// ```rust
/// use type_sitter_gen::{generate_nodes, NodeTypeMap};
///
/// fn main() {
/// let mut node_type_map = NodeTypeMap::try_from(tree_sitter_rust::NODE_TYPES).unwrap();
/// // customize node_type_map
/// let code = generate_nodes(node_type_map).unwrap().into_string();
/// assert!(code.contains("pub struct TraitItem"));
/// }
/// ```
/// Generate source code (tokens) for typed AST node wrappers, and the generated code will refer to
/// the provided modules instead of `type_sitter::raw` and `type_sitter` respectively.
///
/// # Parameters
/// - `types`: Anything that can be converted to a `NodeTypeMap`
/// - `tree_sitter`: Path to the crate with the tree-sitter API. In [`generate_nodes`] this is
/// [`type_sitter_raw`] but you can provide something else, like the re-exported [`tree_sitter`]
/// or [`yak_sitter`] directly.
/// - `type_sitter_lib`: Path to the crate with the type-sitter API. In [`generate_nodes`] this is
/// [`type_sitter`] but you can provide something else, like the re-exported [`type_sitter_lib`]
/// directly.
///
/// # Example
///
/// ```rust
/// use type_sitter_gen::{generate_nodes_with_custom_module_paths, tree_sitter, type_sitter_lib};
/// use std::path::Path;
///
/// fn main() {
/// let code = generate_nodes_with_custom_module_paths(
/// Path::new("../vendor/tree-sitter-rust/src/node-types.json"),
/// &tree_sitter(),
/// &type_sitter_lib()
/// ).unwrap().into_string();
/// assert!(code.contains("pub struct TraitItem"));
/// }
/// ```