- Lexer/Parser/Executor 三阶段架构
- #{param} 参数化 + ${raw} 原样替换 + 白名单安全策略
- @if/@for/@tpl/@include/@namespace 控制流
- 表达式引擎: 比较、逻辑、nil 检查、len() 内置函数
- 支持 ?/$1/:1 多数据库占位符风格
- 零依赖,纯 Go 标准库实现
43 lines
742 B
Go
43 lines
742 B
Go
package utpl
|
|
|
|
import "fmt"
|
|
|
|
type Position struct {
|
|
Line int
|
|
Column int
|
|
}
|
|
|
|
func (p Position) String() string {
|
|
return fmt.Sprintf("line %d, column %d", p.Line, p.Column)
|
|
}
|
|
|
|
type ParseError struct {
|
|
Message string
|
|
Pos Position
|
|
Token string
|
|
}
|
|
|
|
func (e ParseError) Error() string {
|
|
return fmt.Sprintf("%s: %s (token: %q)", e.Pos, e.Message, e.Token)
|
|
}
|
|
|
|
type ExecError struct {
|
|
Pos Position
|
|
Message string
|
|
}
|
|
|
|
func (e ExecError) Error() string {
|
|
return fmt.Sprintf("%s: %s", e.Pos, e.Message)
|
|
}
|
|
|
|
type UnsafeRawError struct {
|
|
Message string
|
|
Pos Position
|
|
Param string
|
|
Value string
|
|
}
|
|
|
|
func (e UnsafeRawError) Error() string {
|
|
return fmt.Sprintf("%s: %s (param: %q, value: %q)", e.Pos, e.Message, e.Param, e.Value)
|
|
}
|