Browse Source

Merge pull request 'lexer: add Hint to Error, which is expanded as "%s" instead of "%q"' (#12)

Reviewed-on: #12
dev-amery
Alejandro Mery 1 year ago
parent
commit
5f81eb0ea5
  1. 26
      lexer/error.go

26
lexer/error.go

@ -25,17 +25,29 @@ type Error struct {
Column int Column int
Content string Content string
Hint string
Err error 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 { func (err Error) Error() string {
var s []string var s []string
switch { prefix := err.prefix()
case err.Line > 0 || err.Column > 0: if prefix != "" {
s = append(s, fmt.Sprintf("%s:%v:%v", err.Filename, err.Line, err.Column)) s = append(s, prefix)
case err.Filename != "":
s = append(s, err.Filename)
} }
if err.Err != nil { if err.Err != nil {
@ -46,6 +58,10 @@ func (err Error) Error() string {
s = append(s, fmt.Sprintf("%q", err.Content)) s = append(s, fmt.Sprintf("%q", err.Content))
} }
if err.Hint != "" {
s = append(s, err.Hint)
}
return strings.Join(s, ": ") return strings.Join(s, ": ")
} }

Loading…
Cancel
Save