Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3bd2c58fc3 | |||
| eb9261b478 | |||
| 0098052142 | |||
| a02326a0a6 |
@@ -1,6 +1,7 @@
|
|||||||
package lexer
|
package lexer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -9,6 +10,14 @@ var (
|
|||||||
_ error = (*Error)(nil)
|
_ error = (*Error)(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// ErrUnacceptableRune indicates the read rune isn't acceptable in the context
|
||||||
|
ErrUnacceptableRune = errors.New("rune not acceptable in context")
|
||||||
|
|
||||||
|
// ErrNotImplemented indicates something hasn't been implemented yet
|
||||||
|
ErrNotImplemented = errors.New("not implemented")
|
||||||
|
)
|
||||||
|
|
||||||
// Error represents a generic parsing error
|
// Error represents a generic parsing error
|
||||||
type Error struct {
|
type Error struct {
|
||||||
Filename string
|
Filename string
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package lexer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"unicode"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewIsNot generates a rune condition checker that reverses the
|
||||||
|
// decision of the given checker.
|
||||||
|
func NewIsNot(cond func(rune) bool) func(rune) bool {
|
||||||
|
return func(r rune) bool {
|
||||||
|
return !cond(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewIsIn generates a rune condition checker that accepts runes
|
||||||
|
// contained on the provided string
|
||||||
|
func NewIsIn(s string) func(rune) bool {
|
||||||
|
return func(r rune) bool {
|
||||||
|
return strings.ContainsRune(s, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewIsOneOf generates a run condition checker that accepts runes
|
||||||
|
// accepted by any of the given checkers
|
||||||
|
func NewIsOneOf(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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user