47 lines
988 B
Go
47 lines
988 B
Go
package ucl
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/alecthomas/participle/v2/lexer"
|
|
)
|
|
|
|
var (
|
|
ErrNotConvertable = errors.New("result not convertable to go")
|
|
)
|
|
|
|
var (
|
|
tooManyFinallyBlocksError = newBadUsage("try needs at most 1 finally")
|
|
notIndexableError = newBadUsage("index only support on lists and hashes")
|
|
notModIndexableError = newBadUsage("list or hash cannot be modified")
|
|
assignToNilIndex = newBadUsage("assigning to nil index value")
|
|
)
|
|
|
|
type errorWithPos struct {
|
|
err error
|
|
pos lexer.Position
|
|
}
|
|
|
|
func (e errorWithPos) Error() string {
|
|
return fmt.Sprintf("%v:%v - %v", e.pos.Line, e.pos.Offset, e.err.Error())
|
|
}
|
|
|
|
func (e errorWithPos) Unwrap() error {
|
|
return e.err
|
|
}
|
|
|
|
type errBadUsage struct {
|
|
msg string
|
|
}
|
|
|
|
func newBadUsage(msg string) func(pos lexer.Position) error {
|
|
return func(pos lexer.Position) error {
|
|
return errorWithPos{err: errBadUsage{msg: msg}, pos: pos}
|
|
}
|
|
}
|
|
|
|
func (e errBadUsage) Error() string {
|
|
return "bad usage: " + e.msg
|
|
}
|