use std::path::Path;
use graphify_core::model::ExtractionResult;
pub trait Parser: Send + Sync {
fn parse(&self, path: &Path, source: &[u8]) -> ExtractionResult;
fn supported_extensions(&self) -> &[&str];
}
pub struct RegexParser;
impl Parser for RegexParser {
fn parse(&self, path: &Path, source: &[u8]) -> ExtractionResult {
let lang = crate::language_for_path(path).unwrap_or("generic");
let source_str = String::from_utf8_lossy(source);
crate::ast_extract::extract_file(path, &source_str, lang)
}
fn supported_extensions(&self) -> &[&str] {
&[
".py", ".js", ".jsx", ".ts", ".tsx", ".go", ".rs", ".java", ".c", ".h", ".cpp", ".cc",
".cxx", ".hpp", ".rb", ".cs", ".kt", ".kts", ".scala", ".php", ".swift", ".lua",
".toc", ".zig", ".ps1", ".ex", ".exs", ".m", ".mm", ".jl",
]
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::path::Path;
#[test]
fn regex_parser_is_send_sync() {
fn assert_send_sync<T: Send + Sync>() {}
assert_send_sync::<RegexParser>();
}
#[test]
fn regex_parser_produces_output() {
let parser = RegexParser;
let source = b"def hello():\n pass\n";
let result = parser.parse(Path::new("test.py"), source);
assert!(!result.nodes.is_empty());
}
}