internal/pathrule/gen -dart renders the Unicode and best-fit tables as const lists of a Dart library, as -ts does for datekeys-ts: the same data and the same TablesDigest, with the formatter turned off for the file. tables.go and the TypeScript module come out unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>v0.12
parent
424cdf3406
commit
c531e936fa
@ -0,0 +1,108 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// dartSource renders the tables as a Dart library for datekeys-dart, the
|
||||
// third implementation (spec §29.5.1): the same data as tables.go and the
|
||||
// module of tsSource, as const lists of ints, and the same digest, which its
|
||||
// tests recompute from the lists with the canonical text of Canonical. The
|
||||
// lists run to thousands of lines, so the library turns the formatter off:
|
||||
// dart format keeps it as written here.
|
||||
func (t *tables) dartSource() []byte {
|
||||
var b bytes.Buffer
|
||||
w := func(format string, args ...any) { fmt.Fprintf(&b, format, args...) }
|
||||
ints := func(indent string, vs []int64) {
|
||||
for i, v := range vs {
|
||||
if i%16 == 0 {
|
||||
w("\n%s", indent)
|
||||
} else {
|
||||
w(" ")
|
||||
}
|
||||
w("%d,", v)
|
||||
}
|
||||
}
|
||||
list := func(name, doc string, vs []int64) {
|
||||
w("/// %s\nconst List<int> %s = [", doc, name)
|
||||
ints(" ", vs)
|
||||
w("\n];\n\n")
|
||||
}
|
||||
runes := func(rs []rune) []int64 {
|
||||
out := make([]int64, len(rs))
|
||||
for i, r := range rs {
|
||||
out[i] = int64(r)
|
||||
}
|
||||
return out
|
||||
}
|
||||
pairs := func(rs [][2]rune) []int64 {
|
||||
out := make([]int64, 0, 2*len(rs))
|
||||
for _, r := range rs {
|
||||
out = append(out, int64(r[0]), int64(r[1]))
|
||||
}
|
||||
return out
|
||||
}
|
||||
mapping := func(prefix, doc string, m map[rune][]rune) {
|
||||
keys := sortedKeys(m)
|
||||
var start, data []int64
|
||||
for _, k := range keys {
|
||||
start = append(start, int64(len(data)))
|
||||
data = append(data, runes(m[k])...)
|
||||
}
|
||||
start = append(start, int64(len(data)))
|
||||
list(prefix+"Keys", doc+": the code points that have one, sorted.", runes(keys))
|
||||
list(prefix+"Start", doc+": where the value of each key starts in "+prefix+"Data, and its end.", start)
|
||||
list(prefix+"Data", doc+": the values, one after another.", data)
|
||||
}
|
||||
|
||||
w("// Code generated by internal/pathrule/gen of the Go reference, from Unicode\n")
|
||||
w("// %s and WindowsBestFit. DO NOT EDIT: regenerate it from datekeys-go.\n", UnicodeVersion)
|
||||
w("//\n// The lists run to thousands of lines: the formatter leaves them as the\n")
|
||||
w("// generator writes them.\n// dart format off\n\n")
|
||||
w("/// The Unicode and best-fit tables of the path and text rules (spec\n")
|
||||
w("/// §29.5.1), as internal/pathrule/tables.go of datekeys-go.\n")
|
||||
w("///\n/// Internal: lib/datekeys.dart does not export it.\nlibrary;\n\n")
|
||||
w("/// The version of Unicode of these tables, fixed with capsule format 3 (spec §29.5.1).\n")
|
||||
w("const unicodeVersion = '%s';\n\n", UnicodeVersion)
|
||||
w("/// The SHA-256 of the canonical text of these tables, as the Go reference\n")
|
||||
w("/// computes it in pathrule.Canonical: the tests recompute it from the lists.\n")
|
||||
w("const tablesDigest = '%s';\n\n", t.digest())
|
||||
w("/// The data files of the tables and their SHA-256 (spec §29.5.1).\n")
|
||||
w("const List<({String path, String sha256})> sources = [\n")
|
||||
for _, s := range t.sources {
|
||||
w(" (path: '%s', sha256: '%s'),\n", s.path, s.sha256)
|
||||
}
|
||||
w("];\n\n")
|
||||
|
||||
list("assignedRanges", "The assigned code points, as inclusive ranges: lo, hi, lo, hi, ...", pairs(t.assigned))
|
||||
list("ignorableRanges", "Default_Ignorable_Code_Point, as inclusive ranges.", pairs(t.ignorable))
|
||||
var ccc []int64
|
||||
for _, k := range sortedKeys(t.ccc) {
|
||||
ccc = append(ccc, int64(k)<<8|int64(t.ccc[k]))
|
||||
}
|
||||
list("cccTable", "Each code point with a non-zero canonical combining class, as code point * 256 + class, sorted.", ccc)
|
||||
mapping("decomposition", "The full canonical decomposition, Hangul syllables excepted", t.decomp)
|
||||
mapping("folding", "The case folding of CaseFolding.txt, statuses C and F", t.fold)
|
||||
mapping("lowercase", "The simple lowercase mapping of UnicodeData.txt, field 13", t.lower)
|
||||
list("vs15Bases", "The characters of an emoji variation sequence with U+FE0E, sorted.", runes(t.vs15))
|
||||
list("vs16Bases", "The characters of an emoji variation sequence with U+FE0F, sorted.", runes(t.vs16))
|
||||
|
||||
w("/// For each code page of WindowsBestFit, the code points of U+0080 and above\n")
|
||||
w("/// that it maps to a single ASCII byte, sorted, and those bytes.\n")
|
||||
w("const List<({String name, List<int> from, List<int> to})> bestFitTables = [\n")
|
||||
for _, bt := range t.bestFit {
|
||||
keys := sortedKeys(bt.to)
|
||||
to := make([]int64, len(keys))
|
||||
for i, k := range keys {
|
||||
to[i] = int64(bt.to[k])
|
||||
}
|
||||
w(" (\n name: '%s',\n from: [", bt.name)
|
||||
ints(" ", runes(keys))
|
||||
w("\n ],\n to: [")
|
||||
ints(" ", to)
|
||||
w("\n ],\n ),\n")
|
||||
}
|
||||
w("];\n")
|
||||
return b.Bytes()
|
||||
}
|
||||
Loading…
Reference in new issue