-
Notifications
You must be signed in to change notification settings - Fork 55
/
ast.go
58 lines (47 loc) · 1.14 KB
/
ast.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
package parser
import (
"github.com/osteele/liquid/expression"
)
// ASTNode is a node of an AST.
type ASTNode interface {
SourceLocation() SourceLoc
SourceText() string
}
// ASTBlock represents a {% tag %}…{% endtag %}.
type ASTBlock struct {
Token
syntax BlockSyntax
Body []ASTNode // Body is the nodes before the first branch
Branches []*ASTBlock // E.g. else and elseif w/in an if
}
// ASTRaw holds the text between the start and end of a raw tag.
type ASTRaw struct {
Slices []string
sourcelessNode
}
// ASTTag is a tag {% tag %} that is not a block start or end.
type ASTTag struct {
Token
}
// ASTText is a text span, that is rendered verbatim.
type ASTText struct {
Token
}
// ASTObject is an {{ object }} object.
type ASTObject struct {
Token
Expr expression.Expression
}
// ASTSeq is a sequence of nodes.
type ASTSeq struct {
Children []ASTNode
sourcelessNode
}
// FIXME requiring this is a bad design
type sourcelessNode struct{}
func (n *sourcelessNode) SourceLocation() SourceLoc {
panic("unexpected call on sourceless node")
}
func (n *sourcelessNode) SourceText() string {
panic("unexpected call on sourceless node")
}