Add CI/CD and parser modules
This commit is contained in:
39
depaudit/parsers/factory.py
Normal file
39
depaudit/parsers/factory.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from depaudit.parsers import Parser
|
||||
from depaudit.parsers.javascript import JavaScriptParser
|
||||
from depaudit.parsers.python import PythonParser
|
||||
from depaudit.parsers.go import GoParser
|
||||
from depaudit.parsers.rust import RustParser
|
||||
from depaudit.parsers.java import JavaParser
|
||||
|
||||
|
||||
class ParserFactory:
|
||||
_parsers: list[Parser] = [
|
||||
JavaScriptParser(),
|
||||
PythonParser(),
|
||||
GoParser(),
|
||||
RustParser(),
|
||||
JavaParser(),
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def get_parser(cls, file_path: Path) -> Optional[Parser]:
|
||||
for parser in cls._parsers:
|
||||
if parser.can_parse(file_path):
|
||||
return parser
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def parse(cls, file_path: Path):
|
||||
parser = cls.get_parser(file_path)
|
||||
if parser is None:
|
||||
return None
|
||||
return parser.parse(file_path)
|
||||
|
||||
@classmethod
|
||||
def register_parser(cls, parser: Parser) -> None:
|
||||
cls._parsers.insert(0, parser)
|
||||
Reference in New Issue
Block a user