And stil... it can be cleaner and simpler.

This commit is contained in:
Maurice Makaay 2019-06-18 23:26:15 +00:00
parent 1c8f5ffe7e
commit fd66f63588
1 changed files with 5 additions and 7 deletions

View File

@ -4,15 +4,13 @@ import (
"git.makaay.nl/mauricem/go-parsekit/parse" "git.makaay.nl/mauricem/go-parsekit/parse"
) )
var ( // Booleans are just the tokens you're used to. Always lowercase.
// Booleans are just the tokens you're used to. Always lowercase.
trueOrFalse = a.Str("true").Or(a.Str("false"))
)
func (t *parser) startBoolean(p *parse.API) { func (t *parser) startBoolean(p *parse.API) {
switch { switch {
case p.Accept(tok.Boolean(nil, trueOrFalse)): case p.Accept(a.Str("true")):
t.emitCommand(csetBoolVal, p.Result().Value(0).(bool)) t.emitCommand(csetBoolVal, true)
case p.Accept(a.Str("false")):
t.emitCommand(csetBoolVal, false)
default: default:
p.Expected("true or false") p.Expected("true or false")
} }