Parse object/end blocks and extract components + event handlers
(fileNodeId: string)
| 77 | |
| 78 | /** Parse object/end blocks and extract components + event handlers */ |
| 79 | private parseComponents(fileNodeId: string): void { |
| 80 | const lines = this.source.split('\n'); |
| 81 | const stack: string[] = [fileNodeId]; |
| 82 | |
| 83 | const objectPattern = /^\s*(object|inherited|inline)\s+(\w+)\s*:\s*(\w+)/; |
| 84 | const eventPattern = /^\s*(On\w+)\s*=\s*(\w+)\s*$/; |
| 85 | const endPattern = /^\s*end\s*$/; |
| 86 | const multiLineStart = /=\s*\(\s*$/; |
| 87 | const multiLineItemStart = /=\s*<\s*$/; |
| 88 | let inMultiLine = false; |
| 89 | let multiLineEndChar = ')'; |
| 90 | |
| 91 | for (let i = 0; i < lines.length; i++) { |
| 92 | const line = lines[i]!; |
| 93 | const lineNum = i + 1; |
| 94 | |
| 95 | // Skip multi-line properties |
| 96 | if (inMultiLine) { |
| 97 | if (line.trimEnd().endsWith(multiLineEndChar)) inMultiLine = false; |
| 98 | continue; |
| 99 | } |
| 100 | if (multiLineStart.test(line)) { |
| 101 | inMultiLine = true; |
| 102 | multiLineEndChar = ')'; |
| 103 | continue; |
| 104 | } |
| 105 | if (multiLineItemStart.test(line)) { |
| 106 | inMultiLine = true; |
| 107 | multiLineEndChar = '>'; |
| 108 | continue; |
| 109 | } |
| 110 | |
| 111 | // Component declaration |
| 112 | const objMatch = line.match(objectPattern); |
| 113 | if (objMatch) { |
| 114 | const [, , name, typeName] = objMatch; |
| 115 | const nodeId = generateNodeId(this.filePath, 'component', name!, lineNum); |
| 116 | this.nodes.push({ |
| 117 | id: nodeId, |
| 118 | kind: 'component', |
| 119 | name: name!, |
| 120 | qualifiedName: `${this.filePath}#${name}`, |
| 121 | filePath: this.filePath, |
| 122 | language: 'pascal', |
| 123 | startLine: lineNum, |
| 124 | endLine: lineNum, |
| 125 | startColumn: 0, |
| 126 | endColumn: line.length, |
| 127 | signature: typeName, |
| 128 | updatedAt: Date.now(), |
| 129 | }); |
| 130 | this.edges.push({ |
| 131 | source: stack[stack.length - 1]!, |
| 132 | target: nodeId, |
| 133 | kind: 'contains', |
| 134 | }); |
| 135 | stack.push(nodeId); |
| 136 | continue; |
no test coverage detected