go-toml/parser/comment.go

22 lines
542 B
Go

package parser
import (
"github.com/mmakaay/toml/parsekit"
)
// A '#' hash symbol marks the rest of the line as a comment.
func startComment(p *parsekit.P) {
p.Expects("start of comment")
p.On(c.OneOrMore(hash)).Skip().RouteTo(commentContents)
}
// All characters up to the end of the line are included in the comment.
func commentContents(p *parsekit.P) {
p.Expects("comment contents")
switch {
case p.On(endOfLine).Skip().RouteReturn().End():
p.EmitLiteralTrim(ItemComment)
case p.On(anyRune).Accept().RouteRepeat().End():
}
}