pub mod rust_parser;
pub mod python_parser;
pub mod go_parser;
pub mod typescript_parser;
pub mod java_parser;
#[cfg(feature = "pattern")]
pub mod pattern;
#[cfg(feature = "text-search")]
pub mod text_search;
use deagle_core::{Language, Node, Result};
use std::path::Path;
pub use rust_parser::ParseResult;
pub fn parse_file(path: &Path, content: &str, language: Language) -> Result<Vec<Node>> {
match language {
Language::Rust => rust_parser::parse(path, content),
Language::Python => python_parser::parse(path, content),
Language::Go => go_parser::parse(path, content),
Language::TypeScript | Language::JavaScript => typescript_parser::parse(path, content),
Language::Java => java_parser::parse(path, content),
_ => Ok(Vec::new()),
}
}
pub fn parse_file_with_edges(path: &Path, content: &str, language: Language) -> Result<ParseResult> {
match language {
Language::Rust => rust_parser::parse_with_edges(path, content),
Language::Python => python_parser::parse_with_edges(path, content),
Language::Go => go_parser::parse_with_edges(path, content),
Language::TypeScript | Language::JavaScript => typescript_parser::parse_with_edges(path, content),
Language::Java => java_parser::parse_with_edges(path, content),
_ => Ok(ParseResult { nodes: Vec::new(), edges: Vec::new() }),
}
}
pub fn parse_auto(path: &Path, content: &str) -> Result<Vec<Node>> {
let ext = path.extension().and_then(|e| e.to_str()).unwrap_or("");
let lang = Language::from_extension(ext);
parse_file(path, content, lang)
}