mod c;
mod cpp;
mod csharp;
mod dart;
mod go;
mod java;
mod python;
mod rust;
mod typescript;
use crate::fallback_parser::is_fallback_supported_extension;
use crate::node::CodeNode;
pub trait LanguageParser: Send + Sync {
fn language(&self) -> tree_sitter::Language;
fn extensions(&self) -> &[&str];
fn extract_nodes(
&self,
tree: &tree_sitter::Tree,
source: &str,
file_path: &str,
) -> Vec<CodeNode>;
}
pub fn get_parser(extension: &str) -> Option<Box<dyn LanguageParser>> {
match extension.to_lowercase().as_str() {
"ts" | "tsx" | "mts" | "cts" => Some(Box::new(typescript::TypeScriptParser)),
"js" | "jsx" | "mjs" | "cjs" => Some(Box::new(typescript::TypeScriptParser)),
"rs" => Some(Box::new(rust::RustParser)),
"py" | "pyi" => Some(Box::new(python::PythonParser)),
"go" => Some(Box::new(go::GoParser)),
"java" => Some(Box::new(java::JavaParser)),
"c" | "h" => Some(Box::new(c::CParser)),
"cpp" | "hpp" | "cc" | "hh" | "cxx" | "hxx" => Some(Box::new(cpp::CppParser)),
"cs" => Some(Box::new(csharp::CSharpParser)),
"dart" => Some(Box::new(dart::DartParser)),
_ => None,
}
}
pub fn supported_extensions() -> &'static [&'static str] {
&[
"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", ]
}
pub fn supported_language_names() -> &'static [&'static str] {
&[
"typescript",
"javascript",
"rust",
"python",
"go",
"java",
"c",
"cpp",
"csharp",
"dart",
"kotlin",
"swift",
"ruby",
"php",
"shell",
]
}
pub fn is_supported(extension: &str) -> bool {
get_parser(extension).is_some() || is_fallback_supported_extension(extension)
}