修复: byte/rune 长度混淆及错误位置丢失
This commit is contained in:
19
internal/poserror.go
Normal file
19
internal/poserror.go
Normal 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...)}
|
||||
}
|
||||
Reference in New Issue
Block a user