From c2603e5993a47bbe271e11613fd340e93805a214 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Thu, 5 Feb 2026 08:42:32 +0000 Subject: [PATCH] Add code analyzers (Python, JS, Go, Rust) with tree-sitter --- src/auto_readme/analyzers/analyzer_factory.py | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/auto_readme/analyzers/analyzer_factory.py diff --git a/src/auto_readme/analyzers/analyzer_factory.py b/src/auto_readme/analyzers/analyzer_factory.py new file mode 100644 index 0000000..1ad6d24 --- /dev/null +++ b/src/auto_readme/analyzers/analyzer_factory.py @@ -0,0 +1,39 @@ +"""Code analyzer factory for routing to correct analyzer.""" + +from pathlib import Path +from typing import Optional + +from . import CodeAnalyzer +from .python_analyzer import PythonAnalyzer +from .javascript_analyzer import JavaScriptAnalyzer +from .go_analyzer import GoAnalyzer +from .rust_analyzer import RustAnalyzer + + +class CodeAnalyzerFactory: + """Factory for creating appropriate code analyzers.""" + + ANALYZERS = [ + PythonAnalyzer(), + JavaScriptAnalyzer(), + GoAnalyzer(), + RustAnalyzer(), + ] + + @classmethod + def get_analyzer(cls, path: Path) -> Optional[CodeAnalyzer]: + """Get the appropriate analyzer for a file.""" + for analyzer in cls.ANALYZERS: + if analyzer.can_analyze(path): + return analyzer + return None + + @classmethod + def get_all_analyzers(cls) -> list[CodeAnalyzer]: + """Get all available analyzers.""" + return cls.ANALYZERS.copy() + + @classmethod + def can_analyze(cls, path: Path) -> bool: + """Check if any analyzer can handle the file.""" + return cls.get_analyzer(path) is not None