...
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 func (p *Parser) ParseComment() (*nodes.Comment, error) {
12 log.WithFields(log.Fields{
13 "current": p.Current(),
14 }).Trace("ParseComment")
15
16 tok := p.Match(tokens.CommentBegin)
17 if tok == nil {
18 msg := fmt.Sprintf(`Expected '%s' , got %s`, p.Config.CommentStartString, p.Current())
19 return nil, p.Error(msg, p.Current())
20 }
21
22 comment := &nodes.Comment{
23 Start: tok,
24 Trim: &nodes.Trim{},
25 }
26
27 tok = p.Match(tokens.Data)
28 if tok == nil {
29 comment.Text = ""
30 } else {
31 comment.Text = tok.Val
32 }
33
34 tok = p.Match(tokens.CommentEnd)
35 if tok == nil {
36 msg := fmt.Sprintf(`Expected '%s' , got %s`, p.Config.CommentEndString, p.Current())
37 return nil, p.Error(msg, p.Current())
38 }
39 comment.End = tok
40
41 log.WithFields(log.Fields{
42 "node": comment,
43 }).Trace("ParseComment return")
44 return comment, nil
45 }
46
View as plain text