tree_sitter_tlaplus/
lib.rs

1//! This crate provides Tlaplus 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//! use tree_sitter::Parser;
8//!
9//! let code = r#"
10//! VARIABLE clock
11//!
12//! Init == clock \in {0, 1}
13//!
14//! Tick == IF clock = 0 THEN clock' = 1 ELSE clock' = 0
15//!
16//! Spec == Init /\ [][Tick]_<<clock>>
17//! "#;
18//! let mut parser = Parser::new();
19//! let language = tree_sitter_tlaplus::LANGUAGE;
20//! parser
21//!     .set_language(&language.into())
22//!     .expect("Error loading Tlaplus parser");
23//! let tree = parser.parse(code, None).unwrap();
24//! assert!(!tree.root_node().has_error());
25//! ```
26//!
27//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
28//! [language func]: fn.language.html
29//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
30//! [tree-sitter]: https://tree-sitter.github.io/
31
32use tree_sitter_language::LanguageFn;
33
34extern "C" {
35    fn tree_sitter_tlaplus() -> *const ();
36}
37
38/// The tree-sitter [`LanguageFn`] for this grammar.
39pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_tlaplus) };
40
41/// The content of the [`node-types.json`][] file for this grammar.
42///
43/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
44pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
45
46/// The syntax highlighting query for this language.
47pub const HIGHLIGHT_QUERY: &'static str = include_str!("../../queries/highlights.scm");
48
49// The locals tagging query for this language.
50pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
51
52/// The symbol tagging query for this language.
53// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
54
55#[cfg(test)]
56mod tests {
57    #[test]
58    fn test_can_load_grammar() {
59        let mut parser = tree_sitter::Parser::new();
60        parser
61            .set_language(&super::LANGUAGE.into())
62            .expect("Error loading Tlaplus parser");
63    }
64}