27 lines
578 B
Go
27 lines
578 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.Accept(trueStr):
|
|
return trueValue, true
|
|
case p.Accept(falseStr):
|
|
return falseValue, true
|
|
default:
|
|
p.Expected("true or false")
|
|
return nil, false
|
|
}
|
|
}
|