arbor_core/languages/
mod.rs1mod c;
8mod cpp;
9mod dart;
10mod go;
11mod java;
12mod python;
13mod rust;
14mod typescript;
15
16use crate::fallback_parser::is_fallback_supported_extension;
17use crate::node::CodeNode;
18
19pub trait LanguageParser: Send + Sync {
25 fn language(&self) -> tree_sitter::Language;
27
28 fn extensions(&self) -> &[&str];
30
31 fn extract_nodes(
36 &self,
37 tree: &tree_sitter::Tree,
38 source: &str,
39 file_path: &str,
40 ) -> Vec<CodeNode>;
41}
42
43pub fn get_parser(extension: &str) -> Option<Box<dyn LanguageParser>> {
47 match extension.to_lowercase().as_str() {
48 "ts" | "tsx" | "mts" | "cts" => Some(Box::new(typescript::TypeScriptParser)),
50 "js" | "jsx" | "mjs" | "cjs" => Some(Box::new(typescript::TypeScriptParser)),
51
52 "rs" => Some(Box::new(rust::RustParser)),
54
55 "py" | "pyi" => Some(Box::new(python::PythonParser)),
57
58 "go" => Some(Box::new(go::GoParser)),
60
61 "java" => Some(Box::new(java::JavaParser)),
63
64 "c" | "h" => Some(Box::new(c::CParser)),
66
67 "cpp" | "hpp" | "cc" | "hh" | "cxx" | "hxx" => Some(Box::new(cpp::CppParser)),
69
70 "dart" => Some(Box::new(dart::DartParser)),
72
73 _ => None,
74 }
75}
76
77pub fn supported_extensions() -> &'static [&'static str] {
79 &[
80 "ts", "tsx", "mts", "cts", "js", "jsx", "mjs", "cjs", "rs", "py", "pyi", "go", "java", "c", "h", "cpp", "hpp", "cc", "hh", "cxx", "hxx", "dart", "kt", "kts", "swift", "rb", "php", "phtml", "sh", "bash", "zsh", ]
95}
96
97pub fn supported_language_names() -> &'static [&'static str] {
99 &[
100 "typescript",
101 "javascript",
102 "rust",
103 "python",
104 "go",
105 "java",
106 "c",
107 "cpp",
108 "csharp",
109 "dart",
110 "kotlin",
111 "swift",
112 "ruby",
113 "php",
114 "shell",
115 ]
116}
117
118pub fn is_supported(extension: &str) -> bool {
120 get_parser(extension).is_some() || is_fallback_supported_extension(extension)
121}