Files
core/lexer/runes.go
T
amery 7dc14d5b5e lexer: IsNot(), IsIn(), IsOneOf()
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-08-29 23:06:38 +00:00

42 lines
891 B
Go

package lexer
import (
"strings"
"unicode"
)
// IsNot generates a rune condition checker that reverses the
// decision of the given checker.
func IsNot(cond func(rune) bool) func(rune) bool {
return func(r rune) bool {
return !cond(r)
}
}
// IsIn generates a rune condition checker that accepts runes
// contained on the provided string
func IsIn(s string) func(rune) bool {
return func(r rune) bool {
return strings.ContainsRune(s, r)
}
}
// IsOneOf generates a run condition checker that accepts runes
// accepted by any of the given checkers
func IsOneOf(s ...func(rune) bool) func(rune) bool {
return func(r rune) bool {
for _, cond := range s {
if cond(r) {
return true
}
}
return false
}
}
// IsSpace reports whether the rune is a space character as
// defined by Unicode's White Space property
func IsSpace(r rune) bool {
return unicode.IsSpace(r)
}