/** * @nahisaho/musubix-codegraph - Base Extractor * * Abstract base class for language-specific AST extractors * * @see REQ-CG-MULTILANG-NFR-003 - Extensibility * @see DES-CG-BASE * @see TSK-CG-001 */ import type { Language, Entity, Relation, ParseResult, EntityType, RelationType } from '../../types.js'; /** * Syntax tree type from tree-sitter */ export interface SyntaxTree { rootNode: SyntaxNode; } /** * Syntax node type from tree-sitter */ export interface SyntaxNode { type: string; text: string; startPosition: { row: number; column: number; }; endPosition: { row: number; column: number; }; children: SyntaxNode[]; namedChildren: SyntaxNode[]; childForFieldName(name: string): SyntaxNode | null; parent: SyntaxNode | null; } /** * Language configuration for extractors * @see DES-CG-BASE */ export interface LanguageConfig { /** Language identifier */ name: Language; /** Supported file extensions */ extensions: string[]; /** Tree-sitter grammar name */ treeSitterName: string; /** AST node types for functions */ functionNodes: string[]; /** AST node types for classes/structs */ classNodes: string[]; /** AST node types for imports */ importNodes: string[]; /** AST node types for interfaces (optional) */ interfaceNodes?: string[]; /** AST node types for modules/namespaces (optional) */ moduleNodes?: string[]; } /** * Options for creating an entity */ export interface CreateEntityOptions { type: EntityType; name: string; filePath?: string; startLine: number; endLine: number; language: Language; namespace?: string; docstring?: string; signature?: string; sourceCode?: string; metadata?: Record; } /** * Options for creating a relation */ export interface CreateRelationOptions { type: RelationType; sourceId: string; targetId: string; filePath?: string; weight?: number; metadata?: Record; } /** * Abstract base class for language extractors * * Implements Template Method pattern for AST extraction. * Subclasses implement language-specific extraction logic. * * @see DES-CG-BASE * @see TSK-CG-001 */ export declare abstract class BaseExtractor { /** * Language configuration for this extractor */ abstract readonly config: LanguageConfig; /** * Get the language identifier for this extractor * @returns Language name */ getLanguage(): Language; /** * Get the configuration for this extractor * @returns Language configuration */ getConfig(): LanguageConfig; /** * Extract entities and relations from AST * * Template method - must be implemented by subclasses * * @param tree - Parsed syntax tree * @param filePath - Source file path * @param sourceCode - Original source code * @returns Parse result with entities and relations */ abstract extract(tree: SyntaxTree, filePath: string, sourceCode: string): ParseResult; /** * Create an entity with generated ID * * Factory method for consistent entity creation * * @param options - Entity creation options * @returns Created entity */ protected createEntity(options: CreateEntityOptions): Entity; /** * Create a relation between entities * * Factory method for consistent relation creation * * @param options - Relation creation options * @returns Created relation */ protected createRelation(options: CreateRelationOptions): Relation; /** * Walk AST tree with visitor pattern * * Depth-first traversal of the syntax tree * * @param node - Starting node * @param visitor - Visitor callback function * @param depth - Current depth (default 0) */ protected walkTree(node: SyntaxNode, visitor: (node: SyntaxNode, depth: number) => void, depth?: number): void; /** * Get text content from AST node * * @param node - Syntax node * @returns Node text content */ protected getNodeText(node: SyntaxNode): string; /** * Find child node by field name * * @param node - Parent node * @param field - Field name * @returns Child node or null */ protected getChildByField(node: SyntaxNode, field: string): SyntaxNode | null; /** * Find first child by node type * * @param node - Parent node * @param type - Node type to find * @returns First matching child or null */ protected findChildByType(node: SyntaxNode, type: string): SyntaxNode | null; /** * Find all children by node type * * @param node - Parent node * @param type - Node type to find * @returns Array of matching children */ protected findChildrenByType(node: SyntaxNode, type: string): SyntaxNode[]; /** * Extract name from identifier node * * @param node - Identifier node * @returns Identifier name */ protected extractIdentifier(node: SyntaxNode): string; /** * Extract docstring/comment above a node * * @param node - Target node * @returns Docstring text or undefined */ protected extractDocstring(node: SyntaxNode): string | undefined; /** * Clean docstring by removing comment markers * * @param raw - Raw docstring text * @returns Cleaned docstring */ protected cleanDocstring(raw: string): string; /** * Get line number from node position * * @param node - Syntax node * @param position - 'start' or 'end' * @returns 1-indexed line number */ protected getLineNumber(node: SyntaxNode, position: 'start' | 'end'): number; /** * Create a file entity for the current source file * * @param filePath - Source file path * @param sourceCode - Source code content * @returns File entity */ protected createFileEntity(filePath: string, sourceCode: string): Entity; /** * Check if a node type is a function declaration * * @param nodeType - AST node type * @returns True if function node */ protected isFunctionNode(nodeType: string): boolean; /** * Check if a node type is a class declaration * * @param nodeType - AST node type * @returns True if class node */ protected isClassNode(nodeType: string): boolean; /** * Check if a node type is an import statement * * @param nodeType - AST node type * @returns True if import node */ protected isImportNode(nodeType: string): boolean; /** * Check if a node type is an interface declaration * * @param nodeType - AST node type * @returns True if interface node */ protected isInterfaceNode(nodeType: string): boolean; /** * Check if a node type is a module/namespace declaration * * @param nodeType - AST node type * @returns True if module node */ protected isModuleNode(nodeType: string): boolean; } //# sourceMappingURL=base-extractor.d.ts.map