2017-06-26 15:36:52 +02:00
|
|
|
package chunks
|
2017-06-25 17:23:20 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
2017-06-28 02:23:09 +02:00
|
|
|
|
|
|
|
"github.com/osteele/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.
|
|
|
|
type ASTNode interface {
|
2017-06-25 17:23:20 +02:00
|
|
|
Render(io.Writer, Context) error
|
|
|
|
}
|
|
|
|
|
2017-06-27 23:40:15 +02:00
|
|
|
// ASTRaw holds the text between the start and end of a raw tag.
|
|
|
|
type ASTRaw struct {
|
|
|
|
slices []string
|
|
|
|
}
|
|
|
|
|
2017-06-27 17:19:12 +02:00
|
|
|
// ASTSeq is a sequence of nodes.
|
2017-06-25 17:23:20 +02:00
|
|
|
type ASTSeq struct {
|
2017-06-26 18:41:41 +02:00
|
|
|
Children []ASTNode
|
2017-06-25 17:23:20 +02:00
|
|
|
}
|
|
|
|
|
2017-06-27 19:36:38 +02:00
|
|
|
// ASTChunks is a sequence of chunks.
|
2017-06-27 17:19:12 +02:00
|
|
|
// TODO probably safe to remove this type and method, once the test suite is larger
|
2017-06-25 17:23:20 +02:00
|
|
|
type ASTChunks struct {
|
|
|
|
chunks []Chunk
|
|
|
|
}
|
|
|
|
|
2017-06-28 02:23:09 +02:00
|
|
|
// ASTFunctional renders itself via a render function that is created during parsing.
|
|
|
|
type ASTFunctional struct {
|
|
|
|
Chunk
|
2017-06-26 21:36:05 +02:00
|
|
|
render func(io.Writer, Context) error
|
|
|
|
}
|
|
|
|
|
2017-06-27 17:19:12 +02:00
|
|
|
// ASTText is a text chunk, that is rendered verbatim.
|
2017-06-25 17:23:20 +02:00
|
|
|
type ASTText struct {
|
2017-06-27 17:19:12 +02:00
|
|
|
Chunk
|
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-06-27 17:19:12 +02:00
|
|
|
Chunk
|
2017-06-28 02:23:09 +02:00
|
|
|
expr expressions.Expression
|
2017-06-25 17:23:20 +02:00
|
|
|
}
|
|
|
|
|
2017-06-27 17:19:12 +02:00
|
|
|
// ASTControlTag is a control tag.
|
2017-06-25 17:23:20 +02:00
|
|
|
type ASTControlTag struct {
|
2017-06-27 17:19:12 +02:00
|
|
|
Chunk
|
2017-06-29 03:45:24 +02:00
|
|
|
renderer func(io.Writer, Context) error
|
2017-06-27 18:23:07 +02:00
|
|
|
cd *controlTagDefinition
|
2017-06-27 17:39:32 +02:00
|
|
|
Body []ASTNode
|
|
|
|
Branches []*ASTControlTag
|
2017-06-25 17:23:20 +02:00
|
|
|
}
|