tree-sitter-omega
aien-dev/tree-sitter-omega
Brought by drakestapleton
tree-sitter-omega / bindings / rust / lib.rs
| 1 | //! This crate provides Omega 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 | //! "#; |
| 9 | //! let mut parser = tree_sitter::Parser::new(); |
| 10 | //! let language = tree_sitter_omega::LANGUAGE; |
| 11 | //! parser |
| 12 | //! .set_language(&language.into()) |
| 13 | //! .expect("Error loading Omega parser"); |
| 14 | //! let tree = parser.parse(code, None).unwrap(); |
| 15 | //! assert!(!tree.root_node().has_error()); |
| 16 | //! ``` |
| 17 | //! |
| 18 | //! [`Parser`]: https://docs.rs/tree-sitter/0.27.1/tree_sitter/struct.Parser.html |
| 19 | //! [tree-sitter]: https://tree-sitter.github.io/ |
| 20 | |
| 21 | use tree_sitter_language::LanguageFn; |
| 22 | |
| 23 | unsafe extern "C" { |
| 24 | fn tree_sitter_omega() -> *const (); |
| 25 | } |
| 26 | |
| 27 | /// The tree-sitter [`LanguageFn`] for this grammar. |
| 28 | pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_omega) }; |
| 29 | |
| 30 | /// The content of the [`node-types.json`] file for this grammar. |
| 31 | /// |
| 32 | /// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers/6-static-node-types |
| 33 | pub const NODE_TYPES: &str = include_str!("../../src/node-types.json"); |
| 34 | |
| 35 | #[cfg(with_highlights_query)] |
| 36 | /// The syntax highlighting query for this grammar. |
| 37 | pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm"); |
| 38 | |
| 39 | #[cfg(with_injections_query)] |
| 40 | /// The language injection query for this grammar. |
| 41 | pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm"); |
| 42 | |
| 43 | #[cfg(with_locals_query)] |
| 44 | /// The local variable query for this grammar. |
| 45 | pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm"); |
| 46 | |
| 47 | #[cfg(with_tags_query)] |
| 48 | /// The symbol tagging query for this grammar. |
| 49 | pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm"); |
| 50 | |
| 51 | #[cfg(test)] |
| 52 | mod tests { |
| 53 | #[test] |
| 54 | fn test_can_load_grammar() { |
| 55 | let mut parser = tree_sitter::Parser::new(); |
| 56 | parser |
| 57 | .set_language(&super::LANGUAGE.into()) |
| 58 | .expect("Error loading Omega parser"); |
| 59 | } |
| 60 | } |