go-toml/value.go

40 lines
1.1 KiB
Go

package toml
import (
"git.makaay.nl/mauricem/go-parsekit/parse"
)
var (
detectString = a.SingleQuote.Or(a.DoubleQuote)
detectBoolean = a.Str("true").Or(a.Str("false"))
detectNumberSpecials = c.Any(a.Plus, a.Minus, a.Str("inf"), a.Str("nan"))
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) (*item, 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
}
}