diff options
Diffstat (limited to 'compiler/ucd.go')
-rw-r--r-- | compiler/ucd.go | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/compiler/ucd.go b/compiler/ucd.go index 506f03a..5ad0986 100644 --- a/compiler/ucd.go +++ b/compiler/ucd.go @@ -9,28 +9,43 @@ import ( "github.com/nihei9/maleeni/ucd" ) -func findCodePointRanges(propName, propVal string) ([]*ucd.CodePointRange, error) { - name := ucd.NormalizeSymbolicValue(propName) - val := ucd.NormalizeSymbolicValue(propVal) - name, ok := propertyNameAbbs[name] +func findCodePointRanges(propName, propVal string) ([]*ucd.CodePointRange, bool, error) { + name, ok := propertyNameAbbs[ucd.NormalizeSymbolicValue(propName)] if !ok { - return nil, fmt.Errorf("unsupported character property: %v", propName) + return nil, false, fmt.Errorf("unsupported character property name: %v", propName) } - val, ok = generalCategoryValueAbbs[val] - if !ok { - return nil, fmt.Errorf("unsupported character property value: %v", val) - } - vals, ok := compositGeneralCategories[val] - if !ok { - vals = []string{val} - } - var ranges []*ucd.CodePointRange - for _, v := range vals { - rs, ok := generalCategoryCodePoints[v] + 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 { - return nil, fmt.Errorf("invalie value of the General_Category property: %v", v) + 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 "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 } - ranges = append(ranges, rs...) } - return ranges, 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) } |