graphify_extract/
parser.rs1use std::path::Path;
8
9use graphify_core::model::ExtractionResult;
10
11pub trait Parser: Send + Sync {
16 fn parse(&self, path: &Path, source: &[u8]) -> ExtractionResult;
19
20 fn supported_extensions(&self) -> &[&str];
22}
23
24pub struct RegexParser;
26
27impl Parser for RegexParser {
28 fn parse(&self, path: &Path, source: &[u8]) -> ExtractionResult {
29 let lang = crate::language_for_path(path).unwrap_or("generic");
30 let source_str = String::from_utf8_lossy(source);
31 crate::ast_extract::extract_file(path, &source_str, lang)
32 }
33
34 fn supported_extensions(&self) -> &[&str] {
35 &[
37 ".py", ".js", ".jsx", ".ts", ".tsx", ".go", ".rs", ".java", ".c", ".h", ".cpp", ".cc",
38 ".cxx", ".hpp", ".rb", ".cs", ".kt", ".kts", ".scala", ".php", ".swift", ".lua",
39 ".toc", ".zig", ".ps1", ".ex", ".exs", ".m", ".mm", ".jl",
40 ]
41 }
42}
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47 use std::path::Path;
48
49 #[test]
50 fn regex_parser_is_send_sync() {
51 fn assert_send_sync<T: Send + Sync>() {}
52 assert_send_sync::<RegexParser>();
53 }
54
55 #[test]
56 fn regex_parser_produces_output() {
57 let parser = RegexParser;
58 let source = b"def hello():\n pass\n";
59 let result = parser.parse(Path::new("test.py"), source);
60 assert!(!result.nodes.is_empty());
62 }
63}