tree_sitter_odin/lib.rs
1//! This crate provides Odin language support for the [tree-sitter][] parsing library.
2//!
3//! Typically, you will use the [LANGUAGE][] 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 = r#"
8//! package main
9//!
10//! import "core:fmt"
11//!
12//! main :: proc() {
13//! fmt.println("Hellope!")
14//! }
15//! "#;
16//! let mut parser = tree_sitter::Parser::new();
17//! let language = tree_sitter_odin::LANGUAGE;
18//! parser
19//! .set_language(&language.into())
20//! .expect("Error loading Odin parser");
21//! let tree = parser.parse(code, None).unwrap();
22//! assert!(!tree.root_node().has_error());
23//! ```
24//!
25//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
26//! [tree-sitter]: https://tree-sitter.github.io/
27
28use tree_sitter_language::LanguageFn;
29
30extern "C" {
31 fn tree_sitter_odin() -> *const ();
32}
33
34/// The tree-sitter [`LanguageFn`][LanguageFn] for this grammar.
35///
36/// [LanguageFn]: https://docs.rs/tree-sitter-language/*/tree_sitter_language/struct.LanguageFn.html
37pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_odin) };
38
39/// The content of the [`node-types.json`][] file for this grammar.
40///
41/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
42pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
43
44/// The syntax highlighting query for this language.
45pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
46
47/// The injection query for this language.
48pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm");
49
50/// The local-variable syntax highlighting query for this language.
51pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm");
52
53#[cfg(test)]
54mod tests {
55 #[test]
56 fn test_can_load_grammar() {
57 let mut parser = tree_sitter::Parser::new();
58 parser
59 .set_language(&super::LANGUAGE.into())
60 .expect("Error loading Odin parser");
61 }
62}