1pub mod python;
5pub mod rust;
6pub mod typescript;
7
8pub trait LanguageSupport: Send + Sync {
9 fn name(&self) -> &'static str;
10 fn language(&self) -> tree_sitter::Language;
11 fn query(&self) -> &tree_sitter::Query;
12}
13
14pub fn support_for(lang: &str) -> Option<Box<dyn LanguageSupport>> {
15 match lang {
16 "rust" => Some(Box::new(rust::Rust::new())),
17 "typescript" => Some(Box::new(typescript::TypeScript::new())),
18 "javascript" => Some(Box::new(typescript::JavaScript::new())),
19 "python" => Some(Box::new(python::Python::new())),
20 _ => None,
21 }
22}
23
24#[cfg(test)]
25mod tests {
26 use super::*;
27
28 #[test]
29 fn dispatches_supported_languages() {
30 for l in ["rust", "typescript", "javascript", "python"] {
31 assert!(support_for(l).is_some(), "missing support for {l}");
32 }
33 assert!(support_for("cobol").is_none());
34 }
35}