修复: byte/rune 长度混淆及错误位置丢失

This commit is contained in:
2026-04-01 10:43:16 +08:00
parent 1b5b6aff8f
commit 2f9d81dc17
8 changed files with 603 additions and 93 deletions

19
internal/poserror.go Normal file
View File

@@ -0,0 +1,19 @@
package internal
import "fmt"
// PosError is an internal error type that carries source position information.
// Lexer and parser return this so that the public wrapParseError can extract the position.
type PosError struct {
Line int
Col int
Message string
}
func (e *PosError) Error() string {
return fmt.Sprintf("line %d, col %d: %s", e.Line, e.Col, e.Message)
}
func PosErrorf(line, col int, format string, args ...any) *PosError {
return &PosError{Line: line, Col: col, Message: fmt.Sprintf(format, args...)}
}