go-toml/parse/value_boolean.go

27 lines
574 B
Go

package parse
import (
"git.makaay.nl/mauricem/go-parsekit/parse"
"git.makaay.nl/mauricem/go-toml/ast"
)
var (
trueStr = a.Str("true")
falseStr = a.Str("false")
falseValue = ast.NewValue(ast.TypeBool, false)
trueValue = ast.NewValue(ast.TypeBool, true)
)
// Booleans are just the tokens you're used to. Always lowercase.
func (t *parser) parseBoolean(p *parse.API) (*ast.Value, bool) {
switch {
case p.Skip(trueStr):
return trueValue, true
case p.Skip(falseStr):
return falseValue, true
default:
p.Expected("true or false")
return nil, false
}
}