MCPcopy Create free account
hub / github.com/BUPT-GAMMA/MASFactory / parse

Method parse

masfactory-visualizer/src/parser/parser.ts:2197–2389  ·  view source on GitHub ↗

* Parse Python code and extract graph structure * @param controlFlowCtx - Optional control flow context with user-specified loop iterations and condition values

(
        code: string,
        controlFlowCtx?: ControlFlowContext,
        sourceFilePath?: string,
        opts?: { templateName?: string | null }
    )

Source from the content-addressed store, hash-verified

2195 * @param controlFlowCtx - Optional control flow context with user-specified loop iterations and condition values
2196 */
2197 parse(
2198 code: string,
2199 controlFlowCtx?: ControlFlowContext,
2200 sourceFilePath?: string,
2201 opts?: { templateName?: string | null }
2202 ): GraphData {
2203 this.lastSourceFilePath = sourceFilePath;
2204 const parser = this.getParser();
2205 const tree = parser ? parser.parse(code) : null;
2206 if (!tree) {
2207 const result = this.initializeResult(BASE_TYPES.GRAPH, '');
2208 return {
2209 nodes: result.nodes,
2210 nodeTypes: result.nodeTypes,
2211 edges: result.edges,
2212 subgraphs: result.subgraphs,
2213 subgraphTypes: result.subgraphTypes,
2214 subgraphParents: result.subgraphParents,
2215 nodeLineNumbers: result.nodeLineNumbers,
2216 nodePullKeys: result.nodePullKeys,
2217 nodePushKeys: result.nodePushKeys,
2218 nodeAttributes: result.nodeAttributes,
2219 warnings: [
2220 'Python parser is still initializing (Tree-sitter). Please wait a moment or click Refresh.'
2221 ]
2222 };
2223 }
2224 const rootNode = tree.rootNode;
2225 const localClassBases = collectClassBases(rootNode, code);
2226
2227 // Parse import statements for cross-file resolution
2228 this.imports = parseImports(rootNode, code);
2229 console.log(`[Parser] Found ${this.imports.size} imports`);
2230
2231 // Clear pending builder calls from previous parse
2232 this.pendingBuilderCalls.clear();
2233
2234 // Check if this is a builder function file
2235 const builderInfo = detectBuilderFunction(code);
2236 if (builderInfo && this.features.builderFunctions !== false) {
2237 console.log(`[Parser] Detected builder function: ${builderInfo.functionName}`);
2238 return this.parseBuilderFunctionFile(code, builderInfo);
2239 }
2240
2241 // Find build method and determine base type
2242 const { buildMethod, baseType, className } = findBuildMethodAndBaseType(rootNode);
2243
2244 // Initialize result containers
2245 const result = this.initializeResult(baseType, className);
2246
2247 // Create parsing contexts
2248 const nodeCtx: NodeParseContext = {
2249 nodes: result.nodes,
2250 nodeTypes: result.nodeTypes,
2251 nodeLineNumbers: result.nodeLineNumbers,
2252 variableToNodeName: result.variableToNodeName,
2253 nodePullKeys: result.nodePullKeys,
2254 nodePushKeys: result.nodePushKeys,

Callers 15

parseWithConditionsMethod · 0.95
summarize_python_fileFunction · 0.80
_module_docstringFunction · 0.80
cloneFunction · 0.80
_render_templateFunction · 0.80
_analyze_loop_configFunction · 0.80
_extract_placeholdersFunction · 0.80
mainFunction · 0.80
parseEdgeCreationFunction · 0.80

Calls 15

getParserMethod · 0.95
initializeResultMethod · 0.95
parseNonClassCodeMethod · 0.95
logParseResultMethod · 0.95
extractLoopControlsMethod · 0.95
determineGraphTypeMethod · 0.95

Tested by

no test coverage detected