* Handle Pascal-specific AST structures. * Returns true if the node was fully handled and children should be skipped.
(node: SyntaxNode)
| 8752 | * Returns true if the node was fully handled and children should be skipped. |
| 8753 | */ |
| 8754 | private visitPascalNode(node: SyntaxNode): boolean { |
| 8755 | const nodeType = node.type; |
| 8756 | |
| 8757 | // Unit/Program/Library → module node |
| 8758 | if (nodeType === 'unit' || nodeType === 'program' || nodeType === 'library') { |
| 8759 | const moduleNameNode = node.namedChildren.find( |
| 8760 | (c: SyntaxNode) => c.type === 'moduleName' |
| 8761 | ); |
| 8762 | const name = moduleNameNode ? getNodeText(moduleNameNode, this.source) : ''; |
| 8763 | // Fallback to filename without extension if module name is empty |
| 8764 | const moduleName = name || path.basename(this.filePath).replace(/\.[^.]+$/, ''); |
| 8765 | this.createNode('module', moduleName, node); |
| 8766 | // Continue visiting children (interface/implementation sections) |
| 8767 | for (let i = 0; i < node.namedChildCount; i++) { |
| 8768 | const child = node.namedChild(i); |
| 8769 | if (child) this.visitNode(child); |
| 8770 | } |
| 8771 | return true; |
| 8772 | } |
| 8773 | |
| 8774 | // declType wraps declClass/declIntf/declEnum/type-alias |
| 8775 | // The name lives on declType, the inner node determines the kind |
| 8776 | if (nodeType === 'declType') { |
| 8777 | this.extractPascalDeclType(node); |
| 8778 | return true; |
| 8779 | } |
| 8780 | |
| 8781 | // declUses → import nodes for each unit name |
| 8782 | if (nodeType === 'declUses') { |
| 8783 | this.extractPascalUses(node); |
| 8784 | return true; |
| 8785 | } |
| 8786 | |
| 8787 | // declConsts → container; visit children for individual declConst |
| 8788 | if (nodeType === 'declConsts') { |
| 8789 | for (let i = 0; i < node.namedChildCount; i++) { |
| 8790 | const child = node.namedChild(i); |
| 8791 | if (child?.type === 'declConst') { |
| 8792 | this.extractPascalConst(child); |
| 8793 | } |
| 8794 | } |
| 8795 | return true; |
| 8796 | } |
| 8797 | |
| 8798 | // declConst at top level (outside declConsts) |
| 8799 | if (nodeType === 'declConst') { |
| 8800 | this.extractPascalConst(node); |
| 8801 | return true; |
| 8802 | } |
| 8803 | |
| 8804 | // declTypes → container for type declarations |
| 8805 | if (nodeType === 'declTypes') { |
| 8806 | for (let i = 0; i < node.namedChildCount; i++) { |
| 8807 | const child = node.namedChild(i); |
| 8808 | if (child) this.visitNode(child); |
| 8809 | } |
| 8810 | return true; |
| 8811 | } |
no test coverage detected