Files
u-tpl/internal/node.go
绝尘 1b5b6aff8f 新增: @use 同文件片段复用
支持 @use("name") 引用同一文件内 @tpl 定义的块,
消除 _list/_count 模板中 WHERE 条件重复问题。
2026-04-01 01:59:51 +08:00

119 lines
1.6 KiB
Go

package internal
type Node interface {
nodeType() string
}
type Pos struct {
Line int
Col int
}
type TextNode struct {
Pos Pos
Text string
}
func (n *TextNode) nodeType() string { return "Text" }
type ParamNode struct {
Pos Pos
Name string
}
func (n *ParamNode) nodeType() string { return "Param" }
type RawNode struct {
Pos Pos
Name string
}
func (n *RawNode) nodeType() string { return "Raw" }
type IfNode struct {
Pos Pos
Cond *Expr
Body []Node
Else []Node
ElseIf []*ElseIfBranch
}
func (n *IfNode) nodeType() string { return "If" }
type ElseIfBranch struct {
Pos Pos
Cond *Expr
Body []Node
}
type ForNode struct {
Pos Pos
KeyVar string
ValVar string
List *Expr
Body []Node
}
func (n *ForNode) nodeType() string { return "For" }
type BlockNode struct {
Pos Pos
Name string
Body []Node
}
func (n *BlockNode) nodeType() string { return "Block" }
type IncludeNode struct {
Pos Pos
Path string
}
func (n *IncludeNode) nodeType() string { return "Include" }
type NamespaceNode struct {
Pos Pos
Name string
}
func (n *NamespaceNode) nodeType() string { return "Namespace" }
type CommentNode struct {
Pos Pos
Text string
}
func (n *CommentNode) nodeType() string { return "Comment" }
type UseNode struct {
Pos Pos
Name string
}
func (n *UseNode) nodeType() string { return "Use" }
type ExprType int
const (
ExprLiteral ExprType = iota
ExprVariable
ExprBinary
ExprUnary
ExprFuncCall
ExprNil
)
type Expr struct {
Pos Pos
ExprType ExprType
Name string
Value any
Left *Expr
Op string
Right *Expr
UnaryOp string
Operand *Expr
FuncName string
FuncArgs []*Expr
}