From 43fdbf94ad87ea91a173c72688cad70a0a5f1ab4 Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Fri, 30 Apr 2021 01:54:02 +0900 Subject: Add character property expression (Meet RL1.2 of UTS #18 partially) \p{property name=property value} matches a character has the property. When the property name is General_Category, it can be omitted. That is, \p{Letter} equals \p{General_Category=Letter}. Currently, only General_Category is supported. This feature meets RL1.2 of UTS #18 partially. RL1.2 Properties: https://unicode.org/reports/tr18/#RL1.2 --- generator/main.go | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 generator/main.go (limited to 'generator/main.go') diff --git a/generator/main.go b/generator/main.go new file mode 100644 index 0000000..3edcef5 --- /dev/null +++ b/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 +} -- cgit v1.2.3