ref 0: internal.checker renamed typecheck (no more internal)
This commit is contained in:
parent
8d45d3241b
commit
16d3399ee9
|
@ -1,8 +1,6 @@
|
||||||
package builtin
|
package builtin
|
||||||
|
|
||||||
import (
|
import "git.xdrm.io/go/aicra/typecheck"
|
||||||
"git.xdrm.io/go/aicra/internal/checker"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Any is a permissive type checker
|
// Any is a permissive type checker
|
||||||
type Any struct{}
|
type Any struct{}
|
||||||
|
@ -13,7 +11,7 @@ func NewAny() *Any {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checker returns the checker function
|
// Checker returns the checker function
|
||||||
func (Any) Checker(typeName string) checker.Checker {
|
func (Any) Checker(typeName string) typecheck.Checker {
|
||||||
// nothing if type not handled
|
// nothing if type not handled
|
||||||
if typeName != "any" {
|
if typeName != "any" {
|
||||||
return nil
|
return nil
|
|
@ -1,6 +1,6 @@
|
||||||
package builtin
|
package builtin
|
||||||
|
|
||||||
import "git.xdrm.io/go/aicra/internal/checker"
|
import "git.xdrm.io/go/aicra/typecheck"
|
||||||
|
|
||||||
// Bool checks if a value is a boolean
|
// Bool checks if a value is a boolean
|
||||||
type Bool struct{}
|
type Bool struct{}
|
||||||
|
@ -11,7 +11,7 @@ func NewBool() *Bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checker returns the checker function
|
// Checker returns the checker function
|
||||||
func (Bool) Checker(typeName string) checker.Checker {
|
func (Bool) Checker(typeName string) typecheck.Checker {
|
||||||
// nothing if type not handled
|
// nothing if type not handled
|
||||||
if typeName != "bool" {
|
if typeName != "bool" {
|
||||||
return nil
|
return nil
|
|
@ -1,6 +1,6 @@
|
||||||
package builtin
|
package builtin
|
||||||
|
|
||||||
import "git.xdrm.io/go/aicra/internal/checker"
|
import "git.xdrm.io/go/aicra/typecheck"
|
||||||
|
|
||||||
// Float64 checks if a value is a float64
|
// Float64 checks if a value is a float64
|
||||||
type Float64 struct{}
|
type Float64 struct{}
|
||||||
|
@ -11,7 +11,7 @@ func NewFloat64() *Float64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checker returns the checker function
|
// Checker returns the checker function
|
||||||
func (Float64) Checker(typeName string) checker.Checker {
|
func (Float64) Checker(typeName string) typecheck.Checker {
|
||||||
// nothing if type not handled
|
// nothing if type not handled
|
||||||
if typeName != "float64" && typeName != "float" {
|
if typeName != "float64" && typeName != "float" {
|
||||||
return nil
|
return nil
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"git.xdrm.io/go/aicra/internal/checker"
|
"git.xdrm.io/go/aicra/typecheck"
|
||||||
)
|
)
|
||||||
|
|
||||||
var fixedLengthRegex = regexp.MustCompile(`^string\((\d+))$`)
|
var fixedLengthRegex = regexp.MustCompile(`^string\((\d+))$`)
|
||||||
|
@ -19,7 +19,7 @@ func NewString() *String {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checker returns the checker function. Availables type names are : `string`, `string(length)` and `string(minLength, maxLength)`.
|
// Checker returns the checker function. Availables type names are : `string`, `string(length)` and `string(minLength, maxLength)`.
|
||||||
func (s String) Checker(typeName string) checker.Checker {
|
func (s String) Checker(typeName string) typecheck.Checker {
|
||||||
isSimpleString := typeName == "string"
|
isSimpleString := typeName == "string"
|
||||||
fixedLengthMatches := fixedLengthRegex.FindStringSubmatch(typeName)
|
fixedLengthMatches := fixedLengthRegex.FindStringSubmatch(typeName)
|
||||||
variableLengthMatches := variableLengthRegex.FindStringSubmatch(typeName)
|
variableLengthMatches := variableLengthRegex.FindStringSubmatch(typeName)
|
|
@ -1,4 +1,4 @@
|
||||||
package checker
|
package typecheck
|
||||||
|
|
||||||
// Set of type checkers
|
// Set of type checkers
|
||||||
type Set struct {
|
type Set struct {
|
||||||
|
@ -35,9 +35,8 @@ func (s *Set) Run(typeName string, value interface{}) error {
|
||||||
// check value
|
// check value
|
||||||
if checkerFunc(value) {
|
if checkerFunc(value) {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
|
||||||
return ErrDoesNotMatch
|
|
||||||
}
|
}
|
||||||
|
return ErrDoesNotMatch
|
||||||
}
|
}
|
||||||
|
|
||||||
return ErrNoMatchingType
|
return ErrNoMatchingType
|
|
@ -1,4 +1,4 @@
|
||||||
package checker
|
package typecheck
|
||||||
|
|
||||||
import "errors"
|
import "errors"
|
||||||
|
|
Loading…
Reference in New Issue