aboutsummaryrefslogtreecommitdiff
path: root/compiler/ucd.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-11-27 21:39:42 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-11-27 22:02:52 +0900
commit5ebc2f4e9aa55bb77d82da7d9915a4140cddfbfb (patch)
treefa6d3cd57636290caa5a8f7deec25477c0caf01f /compiler/ucd.go
parentSupport Alphabetic property (Meet RL1.2 of UTS #18 partially) (diff)
downloadtre-5ebc2f4e9aa55bb77d82da7d9915a4140cddfbfb.tar.gz
tre-5ebc2f4e9aa55bb77d82da7d9915a4140cddfbfb.tar.xz
Move all UCD-related processes to ucd package
Diffstat (limited to 'compiler/ucd.go')
-rw-r--r--compiler/ucd.go109
1 files changed, 0 insertions, 109 deletions
diff --git a/compiler/ucd.go b/compiler/ucd.go
deleted file mode 100644
index 80b46ab..0000000
--- a/compiler/ucd.go
+++ /dev/null
@@ -1,109 +0,0 @@
-//go:generate go run ../cmd/generator/main.go
-//go:generate go fmt ucd_table.go
-
-package compiler
-
-import (
- "fmt"
- "strings"
-
- "github.com/nihei9/maleeni/ucd"
-)
-
-func normalizeCharacterProperty(propName, propVal string) (string, error) {
- name, ok := propertyNameAbbs[ucd.NormalizeSymbolicValue(propName)]
- if !ok {
- return "", fmt.Errorf("unsupported character property name: %v", propName)
- }
- props, ok := derivedCoreProperties[name]
- if !ok {
- return "", nil
- }
- var b strings.Builder
- yes, ok := binaryValues[ucd.NormalizeSymbolicValue(propVal)]
- if !ok {
- return "", fmt.Errorf("unsupported character property value: %v", propVal)
- }
- if yes {
- fmt.Fprint(&b, "[")
- } else {
- fmt.Fprint(&b, "[^")
- }
- for _, prop := range props {
- fmt.Fprint(&b, prop)
- }
- fmt.Fprint(&b, "]")
-
- return b.String(), nil
-}
-
-func findCodePointRanges(propName, propVal string) ([]*ucd.CodePointRange, bool, error) {
- name, ok := propertyNameAbbs[ucd.NormalizeSymbolicValue(propName)]
- if !ok {
- return nil, false, fmt.Errorf("unsupported character property name: %v", propName)
- }
- switch name {
- case "gc":
- val, ok := generalCategoryValueAbbs[ucd.NormalizeSymbolicValue(propVal)]
- if !ok {
- return nil, false, fmt.Errorf("unsupported character property value: %v", propVal)
- }
- vals, ok := compositGeneralCategories[val]
- if !ok {
- vals = []string{val}
- }
- var ranges []*ucd.CodePointRange
- for _, v := range vals {
- rs, ok := generalCategoryCodePoints[v]
- if !ok {
- return nil, false, fmt.Errorf("invalid value of the General_Category property: %v", v)
- }
- ranges = append(ranges, rs...)
- }
- return ranges, false, nil
- case "oalpha":
- yes, ok := binaryValues[ucd.NormalizeSymbolicValue(propVal)]
- if !ok {
- return nil, false, fmt.Errorf("unsupported character property value: %v", propVal)
- }
- if yes {
- return otherAlphabeticCodePoints, false, nil
- } else {
- return otherAlphabeticCodePoints, true, nil
- }
- case "olower":
- yes, ok := binaryValues[ucd.NormalizeSymbolicValue(propVal)]
- if !ok {
- return nil, false, fmt.Errorf("unsupported character property value: %v", propVal)
- }
- if yes {
- return otherLowercaseCodePoints, false, nil
- } else {
- return otherLowercaseCodePoints, true, nil
- }
- case "oupper":
- yes, ok := binaryValues[ucd.NormalizeSymbolicValue(propVal)]
- if !ok {
- return nil, false, fmt.Errorf("unsupported character property value: %v", propVal)
- }
- if yes {
- return otherUppercaseCodePoints, false, nil
- } else {
- return otherUppercaseCodePoints, true, nil
- }
- case "wspace":
- yes, ok := binaryValues[ucd.NormalizeSymbolicValue(propVal)]
- if !ok {
- return nil, false, fmt.Errorf("unsupported character property value: %v", propVal)
- }
- if yes {
- return whiteSpaceCodePoints, false, nil
- } else {
- return whiteSpaceCodePoints, true, nil
- }
- }
-
- // If the process reaches this code, it's a bug. We must handle all of the properties registered with
- // the `propertyNameAbbs`.
- return nil, false, fmt.Errorf("character property '%v' is unavailable", propName)
-}