diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-05-08 19:44:17 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-05-08 19:44:17 +0900 |
commit | 7e9f616639c29436ab66cc08c70028beded2877d (patch) | |
tree | c5f2f2823336c36e76bc4deb666a33e1f26ce1ea /cmd/generator/main.go | |
parent | Add --break-on-error option to lex command (diff) | |
download | tre-7e9f616639c29436ab66cc08c70028beded2877d.tar.gz tre-7e9f616639c29436ab66cc08c70028beded2877d.tar.xz |
Change package structure
The executable can be installed using `go install ./cmd/maleeni`.
Diffstat (limited to 'cmd/generator/main.go')
-rw-r--r-- | cmd/generator/main.go | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/cmd/generator/main.go b/cmd/generator/main.go new file mode 100644 index 0000000..3edcef5 --- /dev/null +++ b/cmd/generator/main.go @@ -0,0 +1,70 @@ +package main + +import ( + "fmt" + "net/http" + "os" + "strings" + "text/template" + + "github.com/nihei9/maleeni/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 + } + } + tmpl, err := template.ParseFiles("../compiler/ucd_table.go.tmpl") + if err != nil { + return err + } + var b strings.Builder + err = tmpl.Execute(&b, struct { + GeneratorName string + UnicodeData *ucd.UnicodeData + PropertyValueAliases *ucd.PropertyValueAliases + }{ + GeneratorName: "generator/main.go", + UnicodeData: unicodeData, + PropertyValueAliases: propValAliases, + }) + if err != nil { + return err + } + f, err := os.OpenFile("../compiler/ucd_table.go", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644) + if err != nil { + return err + } + defer f.Close() + fmt.Fprintf(f, b.String()) + return nil +} |