v0.0.402 add PackageName() and TypeName() to enums_codegen
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m12s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m12s
This commit is contained in:
@@ -26,6 +26,10 @@ type CSIDDef struct {
|
||||
Prefix string
|
||||
}
|
||||
|
||||
type CSIDGenOptions struct {
|
||||
DebugOutput *bool
|
||||
}
|
||||
|
||||
var rexCSIDPackage = rext.W(regexp.MustCompile(`^package\s+(?P<name>[A-Za-z0-9_]+)\s*$`))
|
||||
|
||||
var rexCSIDDef = rext.W(regexp.MustCompile(`^\s*type\s+(?P<name>[A-Za-z0-9_]+)\s+string\s*//\s*(@csid:type)\s+\[(?P<prefix>[A-Z0-9]{3})].*$`))
|
||||
@@ -35,7 +39,9 @@ var rexCSIDChecksumConst = rext.W(regexp.MustCompile(`const ChecksumCharsetIDGen
|
||||
//go:embed csid-generate.template
|
||||
var templateCSIDGenerateText string
|
||||
|
||||
func GenerateCharsetIDSpecs(sourceDir string, destFile string) error {
|
||||
func GenerateCharsetIDSpecs(sourceDir string, destFile string, opt CSIDGenOptions) error {
|
||||
|
||||
debugOutput := langext.Coalesce(opt.DebugOutput, false)
|
||||
|
||||
files, err := os.ReadDir(sourceDir)
|
||||
if err != nil {
|
||||
@@ -81,13 +87,18 @@ func GenerateCharsetIDSpecs(sourceDir string, destFile string) error {
|
||||
pkgname := ""
|
||||
|
||||
for _, f := range files {
|
||||
fmt.Printf("========= %s =========\n\n", f.Name())
|
||||
fileIDs, pn, err := processCSIDFile(sourceDir, path.Join(sourceDir, f.Name()))
|
||||
if debugOutput {
|
||||
fmt.Printf("========= %s =========\n\n", f.Name())
|
||||
}
|
||||
|
||||
fileIDs, pn, err := processCSIDFile(sourceDir, path.Join(sourceDir, f.Name()), debugOutput)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("\n")
|
||||
if debugOutput {
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
|
||||
allIDs = append(allIDs, fileIDs...)
|
||||
|
||||
@@ -113,7 +124,7 @@ func GenerateCharsetIDSpecs(sourceDir string, destFile string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func processCSIDFile(basedir string, fn string) ([]CSIDDef, string, error) {
|
||||
func processCSIDFile(basedir string, fn string, debugOutput bool) ([]CSIDDef, string, error) {
|
||||
file, err := os.Open(fn)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
@@ -155,7 +166,11 @@ func processCSIDFile(basedir string, fn string) ([]CSIDDef, string, error) {
|
||||
Name: match.GroupByName("name").Value(),
|
||||
Prefix: match.GroupByName("prefix").Value(),
|
||||
}
|
||||
fmt.Printf("Found ID definition { '%s' }\n", def.Name)
|
||||
|
||||
if debugOutput {
|
||||
fmt.Printf("Found ID definition { '%s' }\n", def.Name)
|
||||
}
|
||||
|
||||
ids = append(ids, def)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user