feat: some experiments

This commit is contained in:
Max Richter
2025-09-26 17:32:16 +02:00
parent ea978b48f6
commit 8ca5152c3c
12 changed files with 147 additions and 66 deletions

36
template/error.go Normal file
View File

@@ -0,0 +1,36 @@
package template
import (
"fmt"
"strings"
)
type Error struct {
err error
start, end int
}
func (e Error) Error() string {
content := e.err.Error()
if strings.Contains(content, " @pos ") {
if e.start == e.end {
return strings.ReplaceAll(content, " @pos ", " ")
}
return strings.ReplaceAll(content, " @pos ", fmt.Sprintf(" position=%d:%d ", e.start, e.end))
}
return content
}
func NewErrorf(msg string, args ...any) Error {
return Error{
err: fmt.Errorf(msg, args...),
}
}
func (e Error) WithPosition(start, end int) Error {
e.start = start
e.end = end
return e
}