plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
plum-tooling/tree-sitter-plum/bindings/rust/lib.rs
| 0d8e2ab | 1 | //! This crate provides plum language support for the [tree-sitter][] parsing library. |
| 0d8e2ab | 2 | //! |
| 0d8e2ab | 3 | //! Typically, you will use the [LANGUAGE][] constant to add this language to a |
| 0d8e2ab | 4 | //! tree-sitter [Parser][], and then use the parser to parse some code: |
| 0d8e2ab | 5 | //! |
| 0d8e2ab | 6 | //! ``` |
| 0d8e2ab | 7 | //! let code = r#" |
| 0d8e2ab | 8 | //! "#; |
| 0d8e2ab | 9 | //! let mut parser = tree_sitter::Parser::new(); |
| 0d8e2ab | 10 | //! let language = tree_sitter_plum::LANGUAGE; |
| 0d8e2ab | 11 | //! parser |
| 0d8e2ab | 12 | //! .set_language(&language.into()) |
| 0d8e2ab | 13 | //! .expect("Error loading plum parser"); |
| 0d8e2ab | 14 | //! let tree = parser.parse(code, None).unwrap(); |
| 0d8e2ab | 15 | //! assert!(!tree.root_node().has_error()); |
| 0d8e2ab | 16 | //! ``` |
| 0d8e2ab | 17 | //! |
| 0d8e2ab | 18 | //! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html |
| 0d8e2ab | 19 | //! [tree-sitter]: https://tree-sitter.github.io/ |
| 0d8e2ab | 20 | |
| 0d8e2ab | 21 | use tree_sitter_language::LanguageFn; |
| 0d8e2ab | 22 | |
| 0d8e2ab | 23 | extern "C" { |
| 0d8e2ab | 24 | fn tree_sitter_plum() -> *const (); |
| 0d8e2ab | 25 | } |
| 0d8e2ab | 26 | |
| 0d8e2ab | 27 | /// The tree-sitter [`LanguageFn`][LanguageFn] for this grammar. |
| 0d8e2ab | 28 | /// |
| 0d8e2ab | 29 | /// [LanguageFn]: https://docs.rs/tree-sitter-language/*/tree_sitter_language/struct.LanguageFn.html |
| 0d8e2ab | 30 | pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_plum) }; |
| 0d8e2ab | 31 | |
| 0d8e2ab | 32 | /// The content of the [`node-types.json`][] file for this grammar. |
| 0d8e2ab | 33 | /// |
| 0d8e2ab | 34 | /// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types |
| 0d8e2ab | 35 | pub const NODE_TYPES: &str = include_str!("../../src/node-types.json"); |
| 0d8e2ab | 36 | |
| 0d8e2ab | 37 | // NOTE: uncomment these to include any queries that this grammar contains: |
| 0d8e2ab | 38 | |
| 0d8e2ab | 39 | // pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm"); |
| 0d8e2ab | 40 | // pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm"); |
| 0d8e2ab | 41 | // pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm"); |
| 0d8e2ab | 42 | // pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm"); |
| 0d8e2ab | 43 | |
| 0d8e2ab | 44 | #[cfg(test)] |
| 0d8e2ab | 45 | mod tests { |
| 0d8e2ab | 46 | #[test] |
| 0d8e2ab | 47 | fn test_can_load_grammar() { |
| 0d8e2ab | 48 | let mut parser = tree_sitter::Parser::new(); |
| 0d8e2ab | 49 | parser |
| 0d8e2ab | 50 | .set_language(&super::LANGUAGE.into()) |
| 0d8e2ab | 51 | .expect("Error loading plum parser"); |
| 0d8e2ab | 52 | } |
| 0d8e2ab | 53 | } |