1pub mod rust_parser;
11pub mod python_parser;
12pub mod go_parser;
13pub mod typescript_parser;
14
15#[cfg(feature = "pattern")]
16pub mod pattern;
17
18#[cfg(feature = "text-search")]
19pub mod text_search;
20
21use deagle_core::{Language, Node, Result};
22use std::path::Path;
23
24pub use rust_parser::ParseResult;
25
26pub fn parse_file(path: &Path, content: &str, language: Language) -> Result<Vec<Node>> {
28 match language {
29 Language::Rust => rust_parser::parse(path, content),
30 Language::Python => python_parser::parse(path, content),
31 Language::Go => go_parser::parse(path, content),
32 Language::TypeScript | Language::JavaScript => typescript_parser::parse(path, content),
33 _ => Ok(Vec::new()),
34 }
35}
36
37pub fn parse_file_with_edges(path: &Path, content: &str, language: Language) -> Result<ParseResult> {
39 match language {
40 Language::Rust => rust_parser::parse_with_edges(path, content),
41 Language::Python => python_parser::parse_with_edges(path, content),
42 Language::Go => go_parser::parse_with_edges(path, content),
43 Language::TypeScript | Language::JavaScript => typescript_parser::parse_with_edges(path, content),
44 _ => Ok(ParseResult { nodes: Vec::new(), edges: Vec::new() }),
45 }
46}
47
48pub fn parse_auto(path: &Path, content: &str) -> Result<Vec<Node>> {
50 let ext = path.extension().and_then(|e| e.to_str()).unwrap_or("");
51 let lang = Language::from_extension(ext);
52 parse_file(path, content, lang)
53}