tree_sitter_commonlisp/
lib.rs

1//! This crate provides commonlisp language support for the [tree-sitter][] parsing library.
2//!
3//! Typically, you will use the [LANGUAGE_COMMONLISP][] constant 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
10//!   .set_language(&tree_sitter_commonlisp::LANGUAGE_COMMONLISP.into())
11//!   .expect("Error loading commonlisp language");
12//! let tree = parser.parse(code, None).unwrap();
13//! ```
14//!
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::LanguageFn;
19
20unsafe extern "C" {
21    fn tree_sitter_commonlisp() -> *const ();
22}
23
24/// The tree-sitter [`LanguageFn`] for CommonLisp.
25///
26/// [LanguageFn]: https://docs.rs/tree-sitter-language/*/tree_sitter_language/struct.LanguageFn.html
27pub const LANGUAGE_COMMONLISP: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_commonlisp) };
28
29/// The content of the [`node-types.json`][] file for this grammar.
30///
31/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
32pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
33
34// Uncomment these to include any queries that this grammar contains
35
36// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
37// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
38// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
39// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
40
41#[cfg(test)]
42mod tests {
43    use crate::LANGUAGE_COMMONLISP;
44
45    #[test]
46    fn test_can_load_grammar() {
47        let mut parser = tree_sitter::Parser::new();
48        parser
49            .set_language(&LANGUAGE_COMMONLISP.into())
50            .expect("Error loading commonlisp language");
51    }
52}