tree_sitter_nwscript/
lib.rs

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