go-toml/parse/value.go

41 lines
1.2 KiB
Go

package parse
import (
"git.makaay.nl/mauricem/go-parsekit/parse"
"git.makaay.nl/mauricem/go-toml/ast"
)
var (
detectString = a.Char('\'', '"')
detectBoolean = a.Str("true").Or(a.Str("false")) // TODO use 't' or 'f' and let the boolean handler format errors on mismatch
detectNumberSpecials = c.Any(a.Plus, a.Minus, a.Str("inf"), a.Str("nan")) // TODO likewise as for boolean
detectDateTime = a.Digits.Then(a.Minus.Or(a.Colon))
detectNumber = a.Digit
detectArray = a.SquareOpen
detectInlineTable = a.CurlyOpen
)
// Values must be of the following types: String, Integer, Float, Boolean,
// Datetime, Array, or Inline Table. Unspecified values are invalid.
func (t *parser) parseValue(p *parse.API) (*ast.Value, bool) {
switch {
case p.Peek(detectString):
return t.parseString(p)
case p.Peek(detectBoolean):
return t.parseBoolean(p)
case p.Peek(detectNumberSpecials):
return t.parseNumber(p)
case p.Peek(detectDateTime):
return t.parseDateTime(p)
case p.Peek(detectNumber):
return t.parseNumber(p)
case p.Peek(detectArray):
return t.parseArray(p)
case p.Peek(detectInlineTable):
return t.parseInlineTable(p)
default:
p.Expected("a value")
return nil, false
}
}