1
package parser
2

3
import (
4
	"fmt"
5

6
	"github.com/noirbizarre/gonja/nodes"
7
	"github.com/noirbizarre/gonja/tokens"
8
	log "github.com/sirupsen/logrus"
9
)
10

11 4
func (p *Parser) ParseComment() (*nodes.Comment, error) {
12 4
	log.WithFields(log.Fields{
13 4
		"current": p.Current(),
14 4
	}).Trace("ParseComment")
15 1

16 4
	tok := p.Match(tokens.CommentBegin)
17 4
	if tok == nil {
18 0
		msg := fmt.Sprintf(`Expected '%s' , got %s`, p.Config.CommentStartString, p.Current())
19 0
		return nil, p.Error(msg, p.Current())
20 0
	}
21

22 4
	comment := &nodes.Comment{
23 4
		Start: tok,
24 4
		Trim:  &nodes.Trim{},
25 1
	}
26 1

27 4
	tok = p.Match(tokens.Data)
28 4
	if tok == nil {
29 0
		comment.Text = ""
30 4
	} else {
31 4
		comment.Text = tok.Val
32 1
	}
33

34 4
	tok = p.Match(tokens.CommentEnd)
35 4
	if tok == nil {
36 0
		msg := fmt.Sprintf(`Expected '%s' , got %s`, p.Config.CommentEndString, p.Current())
37 0
		return nil, p.Error(msg, p.Current())
38 0
	}
39 4
	comment.End = tok
40 1

41 4
	log.WithFields(log.Fields{
42 4
		"node": comment,
43 4
	}).Trace("ParseComment return")
44 4
	return comment, nil
45
}

Read our documentation on viewing source code .

Loading