Skip to content

Commit

Permalink
improved stdlib docs gen speed
Browse files Browse the repository at this point in the history
  • Loading branch information
NotLe0n committed Jun 10, 2024
1 parent f4c7a38 commit 5e9cf85
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions gen/stdlib-generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,37 +83,37 @@ func main() {
inputFile, err := io.ReadAll(resp.Body)
panicIfErr(err)

MakeMdFiles(inputFile, outputPathDe, "DE")
MakeMdFiles(inputFile, outputPathEn, "EN")
fmt.Printf("parsing module %s...\n", entry.Name)
module, err := parser.Parse(parser.Options{
Source: inputFile,
ErrorHandler: ddperror.EmptyHandler,
})
panicIfErr(err)

// turn the map into a slice
publicDecls := make([]ast.Declaration, 0, len(module.PublicDecls))
for _, decl := range module.PublicDecls {
publicDecls = append(publicDecls, decl)
}

// sort the decls by order of appereance
sort.Slice(publicDecls, func(i, j int) bool {
return publicDecls[i].GetRange().Start.IsBefore(publicDecls[j].GetRange().Start)
})

MakeMdFiles(publicDecls, inputFile, outputPathDe, "DE")
MakeMdFiles(publicDecls, inputFile, outputPathEn, "EN")
}
}

func MakeMdFiles(inputFile []byte, outputFilePath, lang string) {
func MakeMdFiles(publicDecls []ast.Declaration, inputFile []byte, outputFilePath, lang string) {
fmt.Printf("creating output file '%s'...\n", outputFilePath)

os.MkdirAll(filepath.Dir(outputFilePath), os.ModeDir|os.ModePerm)
outputFile, err := os.Create(outputFilePath)
panicIfErr(err)
defer outputFile.Close()

fmt.Printf("parsing module...\n")
module, err := parser.Parse(parser.Options{
Source: inputFile,
ErrorHandler: ddperror.EmptyHandler,
})
panicIfErr(err)

// turn the map into a slice
publicDecls := make([]ast.Declaration, 0, len(module.PublicDecls))
for _, decl := range module.PublicDecls {
publicDecls = append(publicDecls, decl)
}

// sort the decls by order of appereance
sort.Slice(publicDecls, func(i, j int) bool {
return publicDecls[i].GetRange().Start.IsBefore(publicDecls[j].GetRange().Start)
})

fmt.Println("writing md file...")

writeMD(string(inputFile), outputFile, publicDecls, lang)
Expand Down

0 comments on commit 5e9cf85

Please sign in to comment.