Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /Consiliency_treesitter-chunker /chunker /languages /c.py
| from __future__ import annotations | |
| from .base import LanguageConfig | |
| from .plugin_base import LanguagePlugin | |
| class CConfig(LanguageConfig): | |
| """Language configuration for C.""" | |
| def language_id(self) -> str: | |
| return "c" | |
| def chunk_types(self) -> set[str]: | |
| """C-specific chunk types.""" | |
| return { | |
| "function_definition", | |
| "struct_specifier", | |
| "union_specifier", | |
| "enum_specifier", | |
| "type_definition", | |
| } | |
| def file_extensions(self) -> set[str]: | |
| return {".c", ".h"} | |
| # Register the C configuration | |
| from .base import language_config_registry | |
| language_config_registry.register(CConfig()) | |
| from typing import TYPE_CHECKING | |
| if TYPE_CHECKING: | |
| from tree_sitter import Node | |
| from chunker.types import CodeChunk | |
| class CPlugin(LanguagePlugin): | |
| """Plugin for C language chunking.""" | |
| def language_name(self) -> str: | |
| return "c" | |
| def supported_extensions(self) -> set[str]: | |
| return {".c", ".h"} | |
| def default_chunk_types(self) -> set[str]: | |
| return { | |
| "function_definition", | |
| "struct_specifier", | |
| "union_specifier", | |
| "enum_specifier", | |
| "type_definition", | |
| } | |
| def get_node_name(node: Node, source: bytes) -> str | None: | |
| """Extract name from C nodes.""" | |
| if node.type == "function_definition": | |
| for child in node.children: | |
| if child.type == "function_declarator": | |
| for subchild in child.children: | |
| if subchild.type == "identifier": | |
| return source[ | |
| subchild.start_byte : subchild.end_byte | |
| ].decode("utf-8") | |
| for child in node.children: | |
| if child.type in {"identifier", "type_identifier"}: | |
| return source[child.start_byte : child.end_byte].decode("utf-8") | |
| return None | |
| def get_context_for_children(self, node: Node, chunk: CodeChunk) -> str: | |
| """Build context string for nested definitions.""" | |
| name = self.get_node_name(node, chunk.content.encode()) | |
| if name: | |
| if node.type == "struct_specifier": | |
| return f"struct {name}" | |
| if node.type == "union_specifier": | |
| return f"union {name}" | |
| if node.type == "enum_specifier": | |
| return f"enum {name}" | |
| if node.type == "function_definition": | |
| return f"function {name}" | |
| return node.type | |
Xet Storage Details
- Size:
- 2.68 kB
- Xet hash:
- 424d19697e291208a8ce57627e34a742f2d9f8672d50bd7536de0a464ded2a0f
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.