tree_sitter_bsv/lib.rs
1/*
2 Copyright: Copyright (c) 2025 Dyumnin Semiconductors. All rights reserved.
3 Author: Vijayvithal <jahagirdar.vs@gmail.com>
4 Created on: 2025-12-26
5 Description: A brief description of the file's purpose.
6*/
7//! This crate provides Bsv language support for the [tree-sitter] parsing library.
8//!
9//! Typically, you will use the [`LANGUAGE`] constant to add this language to a
10//! tree-sitter [`Parser`], and then use the parser to parse some code:
11//!
12//! ```
13//! let code = r#"
14//! "#;
15//! let mut parser = tree_sitter::Parser::new();
16//! let language = tree_sitter_bsv::LANGUAGE;
17//! parser
18//! .set_language(&language.into())
19//! .expect("Error loading Bsv parser");
20//! let tree = parser.parse(code, None).unwrap();
21//! assert!(!tree.root_node().has_error());
22//! ```
23//!
24//! [`Parser`]: https://docs.rs/tree-sitter/0.26.3/tree_sitter/struct.Parser.html
25//! [tree-sitter]: https://tree-sitter.github.io/
26
27use tree_sitter_language::LanguageFn;
28
29extern "C" {
30 fn tree_sitter_bsv() -> *const ();
31}
32
33/// The tree-sitter [`LanguageFn`] for this grammar.
34pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_bsv) };
35
36/// The content of the [`node-types.json`] file for this grammar.
37///
38/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers/6-static-node-types
39pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
40
41#[cfg(with_highlights_query)]
42/// The syntax highlighting query for this grammar.
43pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
44
45#[cfg(with_injections_query)]
46/// The language injection query for this grammar.
47pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm");
48
49#[cfg(with_locals_query)]
50/// The local variable query for this grammar.
51pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm");
52
53#[cfg(with_tags_query)]
54/// The symbol tagging query for this grammar.
55pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm");
56
57#[cfg(test)]
58mod tests {
59 #[test]
60 fn test_can_load_grammar() {
61 let mut parser = tree_sitter::Parser::new();
62 parser
63 .set_language(&super::LANGUAGE.into())
64 .expect("Error loading Bsv parser");
65 }
66}