]> git.r.bdr.sh - rbdr/tree-sitter-api-notation/blame_incremental - bindings/rust/lib.rs
Add comment
[rbdr/tree-sitter-api-notation] / bindings / rust / lib.rs
... / ...
CommitLineData
1//! This crate provides api-notation 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_api_notation::language()).expect("Error loading api-notation 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
18use tree_sitter::Language;
19
20extern "C" {
21 fn tree_sitter_api_notation() -> 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
27pub fn language() -> Language {
28 unsafe { tree_sitter_api_notation() }
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
34pub 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)]
44mod 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 api-notation language");
51 }
52}