go-toml/parser/comment.go

26 lines
546 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")
if 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.On(endOfLine).Skip():
p.EmitLiteralTrim(ItemComment)
p.RouteReturn()
case p.On(any).Accept():
p.RouteRepeat()
}
}