forked from osteele/liquid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodes.go
63 lines (51 loc) · 1.35 KB
/
nodes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
package render
import (
"io"
"github.com/massdriver-cloud/liquid/expressions"
"github.com/massdriver-cloud/liquid/parser"
)
// Node is a node of the render tree.
type Node interface {
SourceLocation() parser.SourceLoc // for error reporting
SourceText() string // for error reporting
render(*trimWriter, nodeContext) Error
}
// BlockNode represents a {% tag %}…{% endtag %}.
type BlockNode struct {
parser.Token
renderer func(io.Writer, Context) error
Body []Node
Clauses []*BlockNode
}
// RawNode holds the text between the start and end of a raw tag.
type RawNode struct {
slices []string
sourcelessNode
}
// TagNode renders itself via a render function that is created during parsing.
type TagNode struct {
parser.Token
renderer func(io.Writer, Context) error
}
// TextNode is a text chunk, that is rendered verbatim.
type TextNode struct {
parser.Token
}
// ObjectNode is an {{ object }} object.
type ObjectNode struct {
parser.Token
expr expressions.Expression
}
// SeqNode is a sequence of nodes.
type SeqNode struct {
Children []Node
sourcelessNode
}
// FIXME requiring this is a bad design
type sourcelessNode struct{}
func (n *sourcelessNode) SourceLocation() parser.SourceLoc {
panic("unexpected call on sourceless node")
}
func (n *sourcelessNode) SourceText() string {
panic("unexpected call on sourceless node")
}