go-toml/parser/syn_comments.go

24 lines
553 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.On(c.OneOrMore(hash)).Skip()
p.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.AtEndOfLine() || p.On(endOfLine).Skip(): // TODO drop AtEndOfLine support
p.EmitLiteralTrim(ItemComment)
p.RouteReturn()
case p.On(any).Accept():
p.Repeat()
}
}