Treat source as runes to allow for unicode characters (e.g. greek, japanese)

This commit is contained in:
Neemek 2024-12-28 17:16:56 +01:00
parent 74bf43d387
commit 402644d219
Signed by: neemek
GPG key ID: 28360A8951CD0E9B
2 changed files with 4 additions and 4 deletions

View file

@ -65,7 +65,7 @@ func (cmd *RunCmd) Run(ctx *Context) error {
panic(r) panic(r)
} }
for _, e := range p.Errors { for _, e := range p.Errors {
print(e.Format(src)) print(e.Format([]rune(src)))
} }
} }
}() }()
@ -75,7 +75,7 @@ func (cmd *RunCmd) Run(ctx *Context) error {
// if there were parsing errors, print them out // if there were parsing errors, print them out
if len(p.Errors) > 0 { if len(p.Errors) > 0 {
for _, e := range p.Errors { for _, e := range p.Errors {
print(e.Format(src)) print(e.Format([]rune(src)))
} }
log.Fatal("Parsing had errors") log.Fatal("Parsing had errors")
} }

View file

@ -14,7 +14,7 @@ type ParsingError struct {
} }
// Print a rich and informative error // Print a rich and informative error
func (p *ParsingError) Format(src string) string { func (p *ParsingError) Format(src []rune) string {
builder := strings.Builder{} builder := strings.Builder{}
lineNumber := 1 lineNumber := 1
@ -38,7 +38,7 @@ func (p *ParsingError) Format(src string) string {
builder.WriteString(p.Description) builder.WriteString(p.Description)
builder.WriteRune('\n') builder.WriteRune('\n')
builder.WriteString(fmt.Sprintf(" %d:%d\t | %s", lineNumber, int(p.Causer.Start)-lineBeginning+1, src[lineBeginning:lineEnd])) builder.WriteString(fmt.Sprintf(" %d:%d\t | %s", lineNumber, int(p.Causer.Start)-lineBeginning+1, string(src[lineBeginning:lineEnd])))
builder.WriteString("\n\t ^") builder.WriteString("\n\t ^")
for i := lineBeginning; i <= int(p.Causer.Start); i++ { for i := lineBeginning; i <= int(p.Causer.Start); i++ {