新增: u-tpl SQL 模板引擎完整实现
- Lexer/Parser/Executor 三阶段架构
- #{param} 参数化 + ${raw} 原样替换 + 白名单安全策略
- @if/@for/@tpl/@include/@namespace 控制流
- 表达式引擎: 比较、逻辑、nil 检查、len() 内置函数
- 支持 ?/$1/:1 多数据库占位符风格
- 零依赖,纯 Go 标准库实现
This commit is contained in:
111
internal/node.go
Normal file
111
internal/node.go
Normal file
@@ -0,0 +1,111 @@
|
||||
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 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
|
||||
}
|
||||
Reference in New Issue
Block a user