Hallucinate fixes to return types and comments

This commit is contained in:
2025-07-20 17:07:11 +02:00
parent 49593a0861
commit 8e1561fff9
3 changed files with 224 additions and 21 deletions

46
main.go
View File

@@ -2,6 +2,7 @@ package main
import (
"flag"
"strings"
_ "embed"
@@ -35,11 +36,56 @@ func main() {
}
func MapType(t string) string {
// Handle complex types like table<int, string>
if strings.Contains(t, "<") && strings.Contains(t, ">") {
// Extract the base type and inner types
openBracket := strings.Index(t, "<")
closeBracket := strings.LastIndex(t, ">")
if openBracket != -1 && closeBracket != -1 {
baseType := t[:openBracket]
innerTypes := t[openBracket+1 : closeBracket]
// Split inner types by comma, but be careful about nested brackets
var mappedInnerTypes []string
var current strings.Builder
bracketDepth := 0
for i := 0; i < len(innerTypes); i++ {
char := innerTypes[i]
if char == '<' {
bracketDepth++
current.WriteByte(char)
} else if char == '>' {
bracketDepth--
current.WriteByte(char)
} else if char == ',' && bracketDepth == 0 {
// Only split on commas that are not inside nested brackets
mappedInnerTypes = append(mappedInnerTypes, MapType(strings.TrimSpace(current.String())))
current.Reset()
} else {
current.WriteByte(char)
}
}
// Add the last inner type
if current.Len() > 0 {
mappedInnerTypes = append(mappedInnerTypes, MapType(strings.TrimSpace(current.String())))
}
// Reconstruct the complex type
return baseType + "<" + strings.Join(mappedInnerTypes, ", ") + ">"
}
}
// Handle simple types
switch t {
case "var":
return "any"
case "var...":
return "any..."
case "int":
return "number"
case "unsigned int":
return "number"
case "float":
return "number"
case "double":