diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-11-25 21:18:34 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-11-25 21:18:34 +0900 |
commit | 6ebbc8f9829bf0f3127367769c662d1a8f881a2d (patch) | |
tree | e45af1104e3ce736134353c1805fe0c91d04998a /compiler/ucd.go | |
parent | Support White_Space property (Meet RL1.2 of UTS #18 partially) (diff) | |
download | tre-6ebbc8f9829bf0f3127367769c662d1a8f881a2d.tar.gz tre-6ebbc8f9829bf0f3127367769c662d1a8f881a2d.tar.xz |
Support Lowercase and Uppercase property (Meet RL1.2 of UTS #18 partially)
Diffstat (limited to 'compiler/ucd.go')
-rw-r--r-- | compiler/ucd.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/compiler/ucd.go b/compiler/ucd.go index 5ad0986..3c0bee1 100644 --- a/compiler/ucd.go +++ b/compiler/ucd.go @@ -5,10 +5,38 @@ 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 { @@ -33,6 +61,26 @@ func findCodePointRanges(propName, propVal string) ([]*ucd.CodePointRange, bool, ranges = append(ranges, rs...) } return ranges, false, 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 { |