22 lines
550 B
Go
22 lines
550 B
Go
package parser
|
|
|
|
import (
|
|
"git.makaay.nl/mauricem/go-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(a.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(a.EndOfLine).Skip().RouteReturn().End():
|
|
p.EmitLiteralTrim(ItemComment)
|
|
case p.On(a.AnyRune).Accept().RouteRepeat().End():
|
|
}
|
|
}
|