- Lexer/Parser/Executor 三阶段架构
- #{param} 参数化 + ${raw} 原样替换 + 白名单安全策略
- @if/@for/@tpl/@include/@namespace 控制流
- 表达式引擎: 比较、逻辑、nil 检查、len() 内置函数
- 支持 ?/$1/:1 多数据库占位符风格
- 零依赖,纯 Go 标准库实现
41 lines
607 B
Go
41 lines
607 B
Go
package internal
|
|
|
|
import "fmt"
|
|
|
|
type PlaceholderStyle int
|
|
|
|
const (
|
|
QuestionMark PlaceholderStyle = iota
|
|
DollarNumber
|
|
ColonNumber
|
|
)
|
|
|
|
type Placeholder struct {
|
|
style PlaceholderStyle
|
|
count int
|
|
}
|
|
|
|
func NewPlaceholder(style PlaceholderStyle) *Placeholder {
|
|
return &Placeholder{style: style}
|
|
}
|
|
|
|
func (p *Placeholder) Next() string {
|
|
p.count++
|
|
switch p.style {
|
|
case DollarNumber:
|
|
return fmt.Sprintf("$%d", p.count)
|
|
case ColonNumber:
|
|
return fmt.Sprintf(":%d", p.count)
|
|
default:
|
|
return "?"
|
|
}
|
|
}
|
|
|
|
func (p *Placeholder) Reset() {
|
|
p.count = 0
|
|
}
|
|
|
|
func (p *Placeholder) Count() int {
|
|
return p.count
|
|
}
|