A few small changes used for TOML support.
This commit is contained in:
parent
5904da9677
commit
7ce12d1632
|
@ -191,10 +191,10 @@ func (p *API) Stop() {
|
||||||
// After setting an error, no more calls to API methods are allowed.
|
// After setting an error, no more calls to API methods are allowed.
|
||||||
// Calling a method in this state will result in a panic.
|
// Calling a method in this state will result in a panic.
|
||||||
// TODO ... wait how do I read the error? I don't I guess, I just return it. Is Error() a good name or SetError() better for example?
|
// TODO ... wait how do I read the error? I don't I guess, I just return it. Is Error() a good name or SetError() better for example?
|
||||||
func (p *API) Error(format string, args ...interface{}) {
|
func (p *API) Error(format string, data ...interface{}) {
|
||||||
// No call to p.panicWhenStoppedOrInError(), to allow a parser to
|
// No call to p.panicWhenStoppedOrInError(), to allow a parser to
|
||||||
// set a different error message when needed.
|
// set a different error message when needed.
|
||||||
message := fmt.Sprintf(format, args...)
|
message := fmt.Sprintf(format, data...)
|
||||||
p.err = fmt.Errorf("%s at %s", message, *p.tokenAPI.Result().Cursor())
|
p.err = fmt.Errorf("%s at %s", message, *p.tokenAPI.Result().Cursor())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,9 +30,9 @@ func callerFilepos(depth int) string {
|
||||||
return fmt.Sprintf("%s:%d", file, line)
|
return fmt.Sprintf("%s:%d", file, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
func callerPanic(name, f string, args ...interface{}) {
|
func callerPanic(name, f string, data ...interface{}) {
|
||||||
filepos := callerBefore(name)
|
filepos := callerBefore(name)
|
||||||
m := fmt.Sprintf(f, args...)
|
m := fmt.Sprintf(f, data...)
|
||||||
m = strings.Replace(m, "{caller}", filepos, -1)
|
m = strings.Replace(m, "{caller}", filepos, -1)
|
||||||
m = strings.Replace(m, "{name}", name, -1)
|
m = strings.Replace(m, "{name}", name, -1)
|
||||||
panic(m)
|
panic(m)
|
||||||
|
|
|
@ -6,9 +6,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func callerPanic(name, f string, args ...interface{}) {
|
func callerPanic(name, f string, data ...interface{}) {
|
||||||
filepos := callerBefore(name)
|
filepos := callerBefore(name)
|
||||||
m := fmt.Sprintf(f, args...)
|
m := fmt.Sprintf(f, data...)
|
||||||
m = strings.Replace(m, "{caller}", filepos, -1)
|
m = strings.Replace(m, "{caller}", filepos, -1)
|
||||||
m = strings.Replace(m, "{name}", name, -1)
|
m = strings.Replace(m, "{name}", name, -1)
|
||||||
panic(m)
|
panic(m)
|
||||||
|
|
|
@ -128,6 +128,7 @@ var A = struct {
|
||||||
Digit Handler
|
Digit Handler
|
||||||
DigitNotZero Handler
|
DigitNotZero Handler
|
||||||
Digits Handler
|
Digits Handler
|
||||||
|
Zero Handler
|
||||||
Float Handler
|
Float Handler
|
||||||
Boolean Handler
|
Boolean Handler
|
||||||
Integer Handler
|
Integer Handler
|
||||||
|
@ -211,6 +212,7 @@ var A = struct {
|
||||||
Digit: MatchDigit(),
|
Digit: MatchDigit(),
|
||||||
DigitNotZero: MatchDigitNotZero(),
|
DigitNotZero: MatchDigitNotZero(),
|
||||||
Digits: MatchDigits(),
|
Digits: MatchDigits(),
|
||||||
|
Zero: MatchRune('0'),
|
||||||
Integer: MatchInteger(),
|
Integer: MatchInteger(),
|
||||||
Signed: MatchSigned,
|
Signed: MatchSigned,
|
||||||
IntegerBetween: MatchIntegerBetween,
|
IntegerBetween: MatchIntegerBetween,
|
||||||
|
@ -324,7 +326,7 @@ func MatchRune(expected rune) Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MatchRunes creates a Handler function that checks if the input matches
|
// MatchRunes creates a Handler function that checks if the input matches
|
||||||
// one of the provided runes.
|
// one of the provided runes. The first match counts.
|
||||||
func MatchRunes(expected ...rune) Handler {
|
func MatchRunes(expected ...rune) Handler {
|
||||||
s := string(expected)
|
s := string(expected)
|
||||||
return MatchRuneByCallback(func(r rune) bool { return strings.ContainsRune(s, r) })
|
return MatchRuneByCallback(func(r rune) bool { return strings.ContainsRune(s, r) })
|
||||||
|
|
Loading…
Reference in New Issue