33 lines
643 B
Go
33 lines
643 B
Go
package parse
|
|
|
|
import (
|
|
"git.makaay.nl/mauricem/go-parsekit/parse"
|
|
)
|
|
|
|
var (
|
|
// Keys may be either bare or quoted.
|
|
detectKey = c.Any(bareKeyRune, a.SingleQuote, a.DoubleQuote)
|
|
|
|
// Both [tables] and [[arrays of tables]] start with a square open bracket.
|
|
detectTableOrArrayOfTables = a.SquareOpen
|
|
)
|
|
|
|
func (t *parser) startDocument(p *parse.API) {
|
|
for {
|
|
p.Accept(dropWhitespace)
|
|
p.Accept(dropComment)
|
|
switch {
|
|
case p.Peek(detectTableOrArrayOfTables):
|
|
p.Handle(t.startTable)
|
|
case p.Peek(detectKey):
|
|
p.Handle(t.startKeyValuePair)
|
|
default:
|
|
p.ExpectEndOfFile()
|
|
return
|
|
}
|
|
if p.IsStoppedOrInError() {
|
|
return
|
|
}
|
|
}
|
|
}
|