1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-30 11:19:00 +01:00
liquid/parser/ast.go
2017-07-12 08:43:23 -04:00

61 lines
1.3 KiB
Go

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
Clauses []*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
}
// 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.
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")
}