arbor_core/languages/
mod.rs1mod c;
8mod cpp;
9mod csharp;
10mod dart;
11mod go;
12mod java;
13mod python;
14mod rust;
15mod typescript;
16
17use crate::fallback_parser::is_fallback_supported_extension;
18use crate::node::CodeNode;
19
20pub trait LanguageParser: Send + Sync {
26 fn language(&self) -> tree_sitter::Language;
28
29 fn extensions(&self) -> &[&str];
31
32 fn extract_nodes(
37 &self,
38 tree: &tree_sitter::Tree,
39 source: &str,
40 file_path: &str,
41 ) -> Vec<CodeNode>;
42}
43
44pub fn get_parser(extension: &str) -> Option<Box<dyn LanguageParser>> {
48 match extension.to_lowercase().as_str() {
49 "ts" | "tsx" | "mts" | "cts" => Some(Box::new(typescript::TypeScriptParser)),
51 "js" | "jsx" | "mjs" | "cjs" => Some(Box::new(typescript::TypeScriptParser)),
52
53 "rs" => Some(Box::new(rust::RustParser)),
55
56 "py" | "pyi" => Some(Box::new(python::PythonParser)),
58
59 "go" => Some(Box::new(go::GoParser)),
61
62 "java" => Some(Box::new(java::JavaParser)),
64
65 "c" | "h" => Some(Box::new(c::CParser)),
67
68 "cpp" | "hpp" | "cc" | "hh" | "cxx" | "hxx" => Some(Box::new(cpp::CppParser)),
70
71 "cs" => Some(Box::new(csharp::CSharpParser)),
73
74 "dart" => Some(Box::new(dart::DartParser)),
76
77 _ => None,
78 }
79}
80
81pub fn supported_extensions() -> &'static [&'static str] {
83 &[
84 "ts", "tsx", "mts", "cts", "js", "jsx", "mjs", "cjs", "rs", "py", "pyi", "go", "java", "c", "h", "cpp", "hpp", "cc", "hh", "cxx", "hxx", "cs", "dart", "kt", "kts", "swift", "rb", "php", "phtml", "sh", "bash", "zsh", ]
100}
101
102pub fn supported_language_names() -> &'static [&'static str] {
104 &[
105 "typescript",
106 "javascript",
107 "rust",
108 "python",
109 "go",
110 "java",
111 "c",
112 "cpp",
113 "csharp",
114 "dart",
115 "kotlin",
116 "swift",
117 "ruby",
118 "php",
119 "shell",
120 ]
121}
122
123pub fn is_supported(extension: &str) -> bool {
125 get_parser(extension).is_some() || is_fallback_supported_extension(extension)
126}