...
1 package parser
2
3 import (
4 log "github.com/sirupsen/logrus"
5
6 "github.com/noirbizarre/gonja/nodes"
7 )
8
9 func (p *Parser) ParseTest(expr nodes.Expression) (nodes.Expression, error) {
10 log.WithFields(log.Fields{
11 "current": p.Current(),
12 }).Trace("parseTest")
13
14 expr, err := p.ParseFilterExpression(expr)
15 if err != nil {
16 return nil, err
17 }
18
19 if p.MatchName("is") != nil {
20 not := p.MatchName("not")
21 ident := p.Next()
22
23 test := &nodes.TestCall{
24 Token: ident,
25 Name: ident.Val,
26 Args: []nodes.Expression{},
27 Kwargs: map[string]nodes.Expression{},
28 }
29
30 arg, err := p.ParseExpression()
31 if err == nil && arg != nil {
32 test.Args = append(test.Args, arg)
33 }
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 expr = &nodes.TestExpression{
69 Expression: expr,
70 Test: test,
71 }
72
73 if not != nil {
74 expr = &nodes.Negation{expr, not}
75 }
76 }
77
78 log.WithFields(log.Fields{
79 "expr": expr,
80 }).Trace("parseTest return")
81 return expr, nil
82 }
83
View as plain text