Treat source as runes to allow for unicode characters (e.g. greek, japanese)
This commit is contained in:
parent
74bf43d387
commit
402644d219
2 changed files with 4 additions and 4 deletions
|
|
@ -65,7 +65,7 @@ func (cmd *RunCmd) Run(ctx *Context) error {
|
|||
panic(r)
|
||||
}
|
||||
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 len(p.Errors) > 0 {
|
||||
for _, e := range p.Errors {
|
||||
print(e.Format(src))
|
||||
print(e.Format([]rune(src)))
|
||||
}
|
||||
log.Fatal("Parsing had errors")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ type ParsingError struct {
|
|||
}
|
||||
|
||||
// Print a rich and informative error
|
||||
func (p *ParsingError) Format(src string) string {
|
||||
func (p *ParsingError) Format(src []rune) string {
|
||||
builder := strings.Builder{}
|
||||
|
||||
lineNumber := 1
|
||||
|
|
@ -38,7 +38,7 @@ func (p *ParsingError) Format(src string) string {
|
|||
builder.WriteString(p.Description)
|
||||
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 ^")
|
||||
for i := lineBeginning; i <= int(p.Causer.Start); i++ {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue