4D Code to DocBlock Format Converter
Convert 4D programming language method comments and parameter declarations into standardized DocBlock (JSDoc-style) format documentation blocks.
About
4D (4th Dimension) methods use a proprietary commenting style and type declaration syntax (C_TEXT, C_LONGINT, C_OBJECT) that no standard documentation generator understands. If your codebase lacks machine-readable DocBlocks, automated API docs become impossible, onboarding slows, and refactoring turns dangerous. This converter parses 4D parameter declarations ($1…$n), return values ($0), and inline comments, then emits compliant /** … */ DocBlock output with @param, @returns, and @description tags. It handles 15 native 4D types and preserves comment context.
The tool assumes one method per input block. Multi-method files should be split before conversion. Nested C_* declarations inside conditionals are extracted but flagged as conditional parameters. Edge case: unnamed parameters (bare $1 without a preceding C_* line) are typed as unknown.
Formulas
The converter applies a deterministic state-machine pass over each line of 4D source code. The core transformation rule maps 4D type declarations to DocBlock parameter tags:
where C_TYPE is any 4D type keyword, $n is the parameter index (1…N), and mappedType is resolved from the type mapping table. Return values follow:
Leading comment lines (// prefix) preceding any C_* declaration are collected into the @description field. The regex pattern for type extraction is:
where capture group 1 yields the type name and group 2 yields the comma-separated variable list. Array declarations use a parallel pattern:
Reference Data
| 4D Type Declaration | DocBlock Type | Description | Default Value |
|---|---|---|---|
| C_TEXT | string | Unicode text string | "" |
| C_LONGINT | number | 32-bit signed integer (−231 to 231−1) | 0 |
| C_REAL | number | 64-bit IEEE 754 float | 0.0 |
| C_BOOLEAN | boolean | True/False flag | FALSE |
| C_POINTER | Pointer | Reference to any 4D object | NULL |
| C_OBJECT | Object | JSON-compatible object | NULL |
| C_COLLECTION | Collection | Ordered array of values | NULL |
| C_DATE | Date | Calendar date (no time) | 00/00/00 |
| C_TIME | Time | Duration in seconds from midnight | 00:00:00 |
| C_BLOB | Blob | Binary large object | NULL |
| C_PICTURE | Picture | Image data container | NULL |
| C_VARIANT | * | Any type (resolved at runtime) | undefined |
| C_INTEGER | number | 16-bit signed integer (legacy) | 0 |
| C_COMP | number | 64-bit integer (composite) | 0 |
| ARRAY TEXT | string[] | Array of text values | [] |
| ARRAY LONGINT | number[] | Array of 32-bit integers | [] |
| ARRAY REAL | number[] | Array of floats | [] |
| ARRAY BOOLEAN | boolean[] | Array of booleans | [] |
| ARRAY OBJECT | Object[] | Array of objects | [] |
| ARRAY POINTER | Pointer[] | Array of pointers | [] |
| ARRAY DATE | Date[] | Array of dates | [] |
| ARRAY PICTURE | Picture[] | Array of images | [] |