File size: 971 Bytes
71fa0c7
 
 
60532a1
 
71fa0c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c20abe2
 
 
 
 
71fa0c7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from abc import ABC, abstractmethod
from typing import List
from pathlib import Path
from knowlang.core.types import CodeChunk
from knowlang.configs.config import AppConfig, LanguageConfig
from tree_sitter import Language, Parser

class LanguageParser(ABC):
    """Abstract base class for language-specific parsers"""
    
    def __init__(self, config: AppConfig):
        self.config : AppConfig = config
        self.language : Language = None
        self.parser : Parser = None
        self.language_config : LanguageConfig = None
    
    @abstractmethod
    def setup(self) -> None:
        """Set up the parser (e.g., initialize tree-sitter)"""
        pass

    @abstractmethod
    def parse_file(self, file_path: Path) -> List[CodeChunk]:
        """Parse a single file and return code chunks"""
        pass

    @abstractmethod
    def supports_extension(self, ext: str) -> bool:
        """Check if this parser supports a given file extension"""
        pass