A few small changes used for TOML support.

This commit is contained in:
Maurice Makaay 2019-06-23 12:06:31 +00:00
parent 5904da9677
commit 7ce12d1632
4 changed files with 9 additions and 7 deletions

View File

@ -191,10 +191,10 @@ func (p *API) Stop() {
// After setting an error, no more calls to API methods are allowed.
// 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?
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
// 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())
}

View File

@ -30,9 +30,9 @@ func callerFilepos(depth int) string {
return fmt.Sprintf("%s:%d", file, line)
}
func callerPanic(name, f string, args ...interface{}) {
func callerPanic(name, f string, data ...interface{}) {
filepos := callerBefore(name)
m := fmt.Sprintf(f, args...)
m := fmt.Sprintf(f, data...)
m = strings.Replace(m, "{caller}", filepos, -1)
m = strings.Replace(m, "{name}", name, -1)
panic(m)

View File

@ -6,9 +6,9 @@ import (
"strings"
)
func callerPanic(name, f string, args ...interface{}) {
func callerPanic(name, f string, data ...interface{}) {
filepos := callerBefore(name)
m := fmt.Sprintf(f, args...)
m := fmt.Sprintf(f, data...)
m = strings.Replace(m, "{caller}", filepos, -1)
m = strings.Replace(m, "{name}", name, -1)
panic(m)

View File

@ -128,6 +128,7 @@ var A = struct {
Digit Handler
DigitNotZero Handler
Digits Handler
Zero Handler
Float Handler
Boolean Handler
Integer Handler
@ -211,6 +212,7 @@ var A = struct {
Digit: MatchDigit(),
DigitNotZero: MatchDigitNotZero(),
Digits: MatchDigits(),
Zero: MatchRune('0'),
Integer: MatchInteger(),
Signed: MatchSigned,
IntegerBetween: MatchIntegerBetween,
@ -324,7 +326,7 @@ func MatchRune(expected rune) Handler {
}
// 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 {
s := string(expected)
return MatchRuneByCallback(func(r rune) bool { return strings.ContainsRune(s, r) })