macro_rules! grammar {
($feat:literal, $module:ident, $konst:ident, $func:ident) => {
#[cfg(feature = $feat)]
pub mod $module {
use tree_sitter_language::LanguageFn;
extern "C" {
fn $func() -> *const ();
}
pub const $konst: LanguageFn = unsafe { LanguageFn::from_raw($func) };
}
};
($feat:literal, $module:ident, $konst:ident, $func:ident, highlights) => {
#[cfg(feature = $feat)]
pub mod $module {
use tree_sitter_language::LanguageFn;
extern "C" {
fn $func() -> *const ();
}
pub const $konst: LanguageFn = unsafe { LanguageFn::from_raw($func) };
pub const HIGHLIGHTS_QUERY: &str = include_str!(concat!(
"../grammars/",
stringify!($module),
"/highlights.scm"
));
}
};
}
grammar!("parse", rust, LANGUAGE, tree_sitter_rust);
grammar!("parse", python, LANGUAGE, tree_sitter_python, highlights);
grammar!(
"typescript",
typescript,
LANGUAGE_TYPESCRIPT,
tree_sitter_typescript
);
grammar!("lean", lean, LANGUAGE, tree_sitter_lean, highlights);
grammar!("wgsl", wgsl, LANGUAGE, tree_sitter_wgsl);
grammar!("bash", bash, LANGUAGE, tree_sitter_bash, highlights);
grammar!("html", html, LANGUAGE, tree_sitter_html, highlights);
grammar!("zsh", zsh, LANGUAGE, tree_sitter_zsh, highlights);
grammar!("nix", nix, LANGUAGE, tree_sitter_nix, highlights);
grammar!("sql", sql, LANGUAGE, tree_sitter_sql, highlights);