feat(parser): Add C and C++ support to ASTParser
This commit is contained in:
+9
-2
@@ -38,6 +38,8 @@ from pathlib import Path
|
||||
from typing import Optional, Any, List, Tuple, Dict
|
||||
import tree_sitter
|
||||
import tree_sitter_python
|
||||
import tree_sitter_cpp
|
||||
import tree_sitter_c
|
||||
import re
|
||||
|
||||
_ast_cache: Dict[str, Tuple[float, tree_sitter.Tree]] = {}
|
||||
@@ -49,11 +51,16 @@ class ASTParser:
|
||||
"""
|
||||
|
||||
def __init__(self, language: str) -> None:
|
||||
if language != "python":
|
||||
if language not in ("python", "cpp", "c"):
|
||||
raise ValueError(f"Language '{language}' not supported yet.")
|
||||
self.language_name = language
|
||||
# Load the tree-sitter language grammar
|
||||
self.language = tree_sitter.Language(tree_sitter_python.language())
|
||||
if language == "python":
|
||||
self.language = tree_sitter.Language(tree_sitter_python.language())
|
||||
elif language == "cpp":
|
||||
self.language = tree_sitter.Language(tree_sitter_cpp.language())
|
||||
elif language == "c":
|
||||
self.language = tree_sitter.Language(tree_sitter_c.language())
|
||||
self.parser = tree_sitter.Parser(self.language)
|
||||
|
||||
def parse(self, code: str) -> tree_sitter.Tree:
|
||||
|
||||
Reference in New Issue
Block a user