diff options
author | EuAndreh <eu@euandre.org> | 2024-12-10 12:29:03 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-12-10 12:29:03 -0300 |
commit | 8359c047aaebe274a2d811d61922b571ca7d10df (patch) | |
tree | 070e0ed93d27a842776ada805eeb4270e7e3c806 /src/urubu/cmd/ucdgen/main.go | |
parent | Start building test files (diff) | |
download | cotia-8359c047aaebe274a2d811d61922b571ca7d10df.tar.gz cotia-8359c047aaebe274a2d811d61922b571ca7d10df.tar.xz |
Namespace packages with "urubu/"
Diffstat (limited to 'src/urubu/cmd/ucdgen/main.go')
-rw-r--r-- | src/urubu/cmd/ucdgen/main.go | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/urubu/cmd/ucdgen/main.go b/src/urubu/cmd/ucdgen/main.go new file mode 100644 index 0000000..d5599a6 --- /dev/null +++ b/src/urubu/cmd/ucdgen/main.go @@ -0,0 +1,98 @@ +package main + +import ( + "fmt" + "net/http" + "os" + "strings" + "text/template" + + "urubu/ucd" +) + +func main() { + err := gen() + if err != nil { + fmt.Fprintf(os.Stderr, "%v\n", err) + os.Exit(1) + } +} + +func gen() error { + var propValAliases *ucd.PropertyValueAliases + { + resp, err := http.Get("https://www.unicode.org/Public/13.0.0/ucd/PropertyValueAliases.txt") + if err != nil { + return err + } + defer resp.Body.Close() + propValAliases, err = ucd.ParsePropertyValueAliases(resp.Body) + if err != nil { + return err + } + } + var unicodeData *ucd.UnicodeData + { + resp, err := http.Get("https://www.unicode.org/Public/13.0.0/ucd/UnicodeData.txt") + if err != nil { + return err + } + defer resp.Body.Close() + unicodeData, err = ucd.ParseUnicodeData(resp.Body, propValAliases) + if err != nil { + return err + } + } + var scripts *ucd.Scripts + { + resp, err := http.Get("https://www.unicode.org/Public/13.0.0/ucd/Scripts.txt") + if err != nil { + return err + } + defer resp.Body.Close() + scripts, err = ucd.ParseScripts(resp.Body, propValAliases) + if err != nil { + return err + } + } + var propList *ucd.PropList + { + resp, err := http.Get("https://www.unicode.org/Public/13.0.0/ucd/PropList.txt") + if err != nil { + return err + } + defer resp.Body.Close() + propList, err = ucd.ParsePropList(resp.Body) + if err != nil { + return err + } + } + tmpl, err := template.ParseFiles("../ucd/codepoint.go.tmpl") + if err != nil { + return err + } + var b strings.Builder + err = tmpl.Execute(&b, struct { + GeneratorName string + UnicodeData *ucd.UnicodeData + Scripts *ucd.Scripts + PropList *ucd.PropList + PropertyValueAliases *ucd.PropertyValueAliases + }{ + GeneratorName: "generator/main.go", + UnicodeData: unicodeData, + Scripts: scripts, + PropList: propList, + PropertyValueAliases: propValAliases, + }) + if err != nil { + return err + } + f, err := os.OpenFile("../ucd/codepoint.go", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644) + if err != nil { + return err + } + defer f.Close() + fmt.Fprint(f, b.String()) + return nil +} |