Fix inline comment handling in struct/union parsing

- Fixed multi-line comment detection to not treat inline comments as multi-line
- Lines with /**< ... */ on same line now parse correctly
- Added support for const char ** pointer type conversion
- Union fields with inline documentation now generate properly
This commit is contained in:
Peterino2 2026-01-22 15:15:59 -08:00
parent d270b3fc84
commit a2ab0f0f21
2 changed files with 33 additions and 8 deletions

View File

@ -510,10 +510,22 @@ pub const Scanner = struct {
const trimmed = std.mem.trim(u8, line, " \t\r");
// Track multi-line comments (both /** and /*)
if (std.mem.indexOf(u8, trimmed, "/*") != null) {
in_multiline_comment = true;
}
if (in_multiline_comment) {
// Only start tracking if /* appears without */ on the same line
if (!in_multiline_comment) {
if (std.mem.indexOf(u8, trimmed, "/*")) |start_pos| {
if (std.mem.indexOf(u8, trimmed, "*/")) |_| {
// Both /* and */ on same line - it's an inline comment, not multi-line
// If line starts with /*, skip it entirely
if (start_pos == 0) continue;
// Otherwise it contains an inline comment, process the line normally
} else {
// Found /* without */ - start of multi-line comment
in_multiline_comment = true;
continue;
}
}
} else {
// We're in a multi-line comment, look for */
if (std.mem.indexOf(u8, trimmed, "*/") != null) {
in_multiline_comment = false;
}
@ -590,10 +602,22 @@ pub const Scanner = struct {
const trimmed = std.mem.trim(u8, line, " \t\r");
// Track multi-line comments (both /** and /*)
if (std.mem.indexOf(u8, trimmed, "/*") != null) {
in_multiline_comment = true;
}
if (in_multiline_comment) {
// Only start tracking if /* appears without */ on the same line
if (!in_multiline_comment) {
if (std.mem.indexOf(u8, trimmed, "/*")) |start_pos| {
if (std.mem.indexOf(u8, trimmed, "*/")) |_| {
// Both /* and */ on same line - it's an inline comment, not multi-line
// If line starts with /*, skip it entirely
if (start_pos == 0) continue;
// Otherwise it contains an inline comment, process the line normally
} else {
// Found /* without */ - start of multi-line comment
in_multiline_comment = true;
continue;
}
}
} else {
// We're in a multi-line comment, look for */
if (std.mem.indexOf(u8, trimmed, "*/") != null) {
in_multiline_comment = false;
}

View File

@ -42,6 +42,7 @@ pub fn convertType(c_type: []const u8, allocator: Allocator) ![]const u8 {
// Common pointer types
if (std.mem.eql(u8, trimmed, "const char *")) return try allocator.dupe(u8, "[*c]const u8");
if (std.mem.eql(u8, trimmed, "const char **")) return try allocator.dupe(u8, "[*c][*c]const u8");
if (std.mem.eql(u8, trimmed, "const char * const *")) return try allocator.dupe(u8, "[*c]const [*c]const u8");
if (std.mem.eql(u8, trimmed, "char *")) return try allocator.dupe(u8, "[*c]u8");
if (std.mem.eql(u8, trimmed, "void *")) return try allocator.dupe(u8, "?*anyopaque");