]> git.r.bdr.sh - rbdr/tree-sitter-api-notation/blob - bindings/rust/lib.rs
ee3d3440fc85cb473a73542a04a2edbfe0a3c5af
[rbdr/tree-sitter-api-notation] / bindings / rust / lib.rs
1 //! This crate provides apinotation language support for the [tree-sitter][] parsing library.
2 //!
3 //! Typically, you will use the [language][language func] function to add this language to a
4 //! tree-sitter [Parser][], and then use the parser to parse some code:
5 //!
6 //! ```
7 //! let code = "";
8 //! let mut parser = tree_sitter::Parser::new();
9 //! parser.set_language(tree_sitter_apinotation::language()).expect("Error loading apinotation grammar");
10 //! let tree = parser.parse(code, None).unwrap();
11 //! ```
12 //!
13 //! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
14 //! [language func]: fn.language.html
15 //! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
16 //! [tree-sitter]: https://tree-sitter.github.io/
17
18 use tree_sitter::Language;
19
20 extern "C" {
21 fn tree_sitter_apinotation() -> Language;
22 }
23
24 /// Get the tree-sitter [Language][] for this grammar.
25 ///
26 /// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
27 pub fn language() -> Language {
28 unsafe { tree_sitter_apinotation() }
29 }
30
31 /// The content of the [`node-types.json`][] file for this grammar.
32 ///
33 /// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
34 pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
35
36 // Uncomment these to include any queries that this grammar contains
37
38 // pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
39 // pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
40 // pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
41 // pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
42
43 #[cfg(test)]
44 mod tests {
45 #[test]
46 fn test_can_load_grammar() {
47 let mut parser = tree_sitter::Parser::new();
48 parser
49 .set_language(super::language())
50 .expect("Error loading apinotation language");
51 }
52 }