2017-07-07 11:41:37 +02:00
|
|
|
package parser
|
2017-06-25 17:23:20 +02:00
|
|
|
|
|
|
|
import (
|
2022-01-06 18:43:17 +01:00
|
|
|
"github.com/danog/liquid/expressions"
|
2017-06-25 17:23:20 +02:00
|
|
|
)
|
|
|
|
|
2017-06-26 18:41:41 +02:00
|
|
|
// ASTNode is a node of an AST.
|
2017-07-10 17:49:14 +02:00
|
|
|
type ASTNode interface {
|
|
|
|
SourceLocation() SourceLoc
|
|
|
|
SourceText() string
|
|
|
|
}
|
2017-07-06 14:59:10 +02:00
|
|
|
|
|
|
|
// ASTBlock represents a {% tag %}…{% endtag %}.
|
|
|
|
type ASTBlock struct {
|
2017-07-09 17:18:35 +02:00
|
|
|
Token
|
2017-07-12 14:27:15 +02:00
|
|
|
syntax BlockSyntax
|
|
|
|
Body []ASTNode // Body is the nodes before the first branch
|
|
|
|
Clauses []*ASTBlock // E.g. else and elseif w/in an if
|
2017-06-25 17:23:20 +02:00
|
|
|
}
|
|
|
|
|
2017-06-27 23:40:15 +02:00
|
|
|
// ASTRaw holds the text between the start and end of a raw tag.
|
|
|
|
type ASTRaw struct {
|
2017-07-07 11:41:37 +02:00
|
|
|
Slices []string
|
2017-07-10 17:49:14 +02:00
|
|
|
sourcelessNode
|
2017-06-27 23:40:15 +02:00
|
|
|
}
|
|
|
|
|
2017-07-09 17:18:35 +02:00
|
|
|
// ASTTag is a tag {% tag %} that is not a block start or end.
|
2017-07-06 15:35:12 +02:00
|
|
|
type ASTTag struct {
|
2017-07-09 17:18:35 +02:00
|
|
|
Token
|
2017-06-26 21:36:05 +02:00
|
|
|
}
|
|
|
|
|
2017-07-09 17:18:35 +02:00
|
|
|
// ASTText is a text span, that is rendered verbatim.
|
2017-06-25 17:23:20 +02:00
|
|
|
type ASTText struct {
|
2017-07-09 17:18:35 +02:00
|
|
|
Token
|
2017-06-25 17:23:20 +02:00
|
|
|
}
|
|
|
|
|
2017-06-27 17:19:12 +02:00
|
|
|
// ASTObject is an {{ object }} object.
|
2017-06-25 17:23:20 +02:00
|
|
|
type ASTObject struct {
|
2017-07-09 17:18:35 +02:00
|
|
|
Token
|
2017-07-14 02:18:23 +02:00
|
|
|
Expr expressions.Expression
|
2017-06-25 17:23:20 +02:00
|
|
|
}
|
|
|
|
|
2017-07-06 14:59:10 +02:00
|
|
|
// ASTSeq is a sequence of nodes.
|
|
|
|
type ASTSeq struct {
|
|
|
|
Children []ASTNode
|
2017-07-10 17:49:14 +02:00
|
|
|
sourcelessNode
|
|
|
|
}
|
|
|
|
|
2017-07-12 14:27:15 +02:00
|
|
|
// It shouldn't be possible to get an error from one of these node types.
|
|
|
|
// If it is, this needs to be re-thought to figure out where the source
|
|
|
|
// location comes from.
|
2017-07-10 17:49:14 +02:00
|
|
|
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")
|
2017-06-25 17:23:20 +02:00
|
|
|
}
|