Skip to main content

dk_engine/parser/
mod.rs

1pub mod python_parser;
2pub mod registry;
3pub mod rust_parser;
4pub mod typescript_parser;
5
6pub use registry::ParserRegistry;
7
8use dk_core::{FileAnalysis, Import, RawCallEdge, Result, Symbol, TypeInfo};
9use std::path::Path;
10
11/// Trait implemented by each language-specific parser.
12///
13/// Stub parsers return empty results; real tree-sitter implementations
14/// will be added in Tasks 5-7.
15pub trait LanguageParser: Send + Sync {
16    /// File extensions this parser handles (without leading dot).
17    fn extensions(&self) -> &[&str];
18
19    /// Extract all symbols from source code.
20    fn extract_symbols(&self, source: &[u8], file_path: &Path) -> Result<Vec<Symbol>>;
21
22    /// Extract raw call edges (unresolved names).
23    fn extract_calls(&self, source: &[u8], file_path: &Path) -> Result<Vec<RawCallEdge>>;
24
25    /// Extract type information for symbols.
26    fn extract_types(&self, source: &[u8], file_path: &Path) -> Result<Vec<TypeInfo>>;
27
28    /// Extract import statements.
29    fn extract_imports(&self, source: &[u8], file_path: &Path) -> Result<Vec<Import>>;
30
31    /// Parse a file and return all extracted data.
32    ///
33    /// Default implementation delegates to the four individual extract methods.
34    fn parse_file(&self, source: &[u8], file_path: &Path) -> Result<FileAnalysis> {
35        Ok(FileAnalysis {
36            symbols: self.extract_symbols(source, file_path)?,
37            calls: self.extract_calls(source, file_path)?,
38            types: self.extract_types(source, file_path)?,
39            imports: self.extract_imports(source, file_path)?,
40        })
41    }
42}