37 lines
767 B
Go
37 lines
767 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.
|
|
detectTable = a.SquareOpen
|
|
|
|
whiteSpaceNewlinesAndComments = whitespaceInclNewlines.Or(comment)
|
|
)
|
|
|
|
func (t *parser) startDocument(p *parse.API) {
|
|
for {
|
|
switch {
|
|
case p.Accept(whiteSpaceNewlinesAndComments):
|
|
// NOOP
|
|
case p.Peek(detectTable):
|
|
p.Handle(t.startTable)
|
|
case p.Peek(detectKey):
|
|
p.Handle(t.startKeyValuePair)
|
|
case p.Accept(a.EndOfFile):
|
|
p.Stop()
|
|
default:
|
|
p.Expected("key/value pair, table or array of tables")
|
|
return
|
|
}
|
|
if p.IsStoppedOrInError() {
|
|
return
|
|
}
|
|
}
|
|
}
|