| 111 | * Parses Python code and extracts graph structure using Tree-sitter AST |
| 112 | */ |
| 113 | export class GraphParser { |
| 114 | private parser: TreeSitterParser | null = null; |
| 115 | private fileReader: FileReaderCallback | null = null; |
| 116 | private workspaceRoot: string = ''; |
| 117 | /** |
| 118 | * Cache for resolved component structures. |
| 119 | * |
| 120 | * Keyed by `${absoluteFilePath}::${exportedSymbolName}` to avoid collisions where two |
| 121 | * different modules export the same symbol name (common in multi-repo or script-style layouts). |
| 122 | */ |
| 123 | private componentCache: Map<string, ComponentStructure | null> = new Map(); |
| 124 | private builderCache: Map<string, BuilderCacheEntry> = new Map(); |
| 125 | private parsedFileCache: Map<string, ParsedPythonFile> = new Map(); |
| 126 | private imports: Map<string, ImportInfo> = new Map(); |
| 127 | private lastSourceFilePath: string | undefined; |
| 128 | // Track builder function calls found during parsing (loopName -> builderInfo) |
| 129 | private pendingBuilderCalls: Map<string, { functionName: string; modulePath: string }> = new Map(); |
| 130 | private features: ParserFeatures = mergeParserFeatures(null); |
| 131 | |
| 132 | constructor() {} |
| 133 | |
| 134 | private getParser(): TreeSitterParser | null { |
| 135 | if (this.parser) {return this.parser;} |
| 136 | const parser = createPythonParser(); |
| 137 | if (parser) { |
| 138 | this.parser = parser; |
| 139 | } |
| 140 | return parser; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Configure parser behavior flags for forward compatibility. |
| 145 | * Defaults preserve current behavior. |
| 146 | */ |
| 147 | setFeatures(features?: ParserFeatures | null): void { |
| 148 | this.features = mergeParserFeatures(features || null); |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Set the file reader callback for cross-file parsing |
| 153 | */ |
| 154 | setFileReader(reader: FileReaderCallback, workspaceRoot: string): void { |
| 155 | this.fileReader = reader; |
| 156 | this.workspaceRoot = workspaceRoot; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Get imports map (for use by nodeParser) |
| 161 | */ |
| 162 | getImports(): Map<string, ImportInfo> { |
| 163 | return this.imports; |
| 164 | } |
| 165 | |
| 166 | getLastSourceFilePath(): string | undefined { |
| 167 | return this.lastSourceFilePath; |
| 168 | } |
| 169 | |
| 170 | /** |
nothing calls this directly
no test coverage detected