diff --git a/lexer/error.go b/lexer/error.go index 541c7f8..d18f3f2 100644 --- a/lexer/error.go +++ b/lexer/error.go @@ -25,17 +25,29 @@ type Error struct { Column int Content string + Hint string Err error } +func (err Error) prefix() string { + switch { + case err.Line > 0 || err.Column > 0: + if err.Filename != "" { + return fmt.Sprintf("%s:%v:%v", err.Filename, err.Line, err.Column) + } + + return fmt.Sprintf("%v:%v", err.Line, err.Column) + default: + return err.Filename + } +} + func (err Error) Error() string { var s []string - switch { - case err.Line > 0 || err.Column > 0: - s = append(s, fmt.Sprintf("%s:%v:%v", err.Filename, err.Line, err.Column)) - case err.Filename != "": - s = append(s, err.Filename) + prefix := err.prefix() + if prefix != "" { + s = append(s, prefix) } if err.Err != nil { @@ -46,6 +58,10 @@ func (err Error) Error() string { s = append(s, fmt.Sprintf("%q", err.Content)) } + if err.Hint != "" { + s = append(s, err.Hint) + } + return strings.Join(s, ": ") }