package parse
import (
)
const parseErrorType = "parse error"
type Error struct {
Entries []*diag.Error
}
var _ diag.Shower = &Error{}
func ( error) *Error {
if , := .(*Error); {
return
}
return nil
}
func ( *Error) ( string, *diag.Context) {
:= &diag.Error{Type: parseErrorType, Message: , Context: *}
.Entries = append(.Entries, )
}
func ( *Error) () string {
switch len(.Entries) {
case 0:
return "no parse error"
case 1:
return .Entries[0].Error()
default:
:= new(strings.Builder)
fmt.Fprintf(, "multiple parse errors in %s: ", .Entries[0].Context.Name)
for , := range .Entries {
if > 0 {
fmt.Fprint(, "; ")
}
fmt.Fprintf(, "%d-%d: %s", .Context.From, .Context.To, .Message)
}
return .String()
}
}
func ( *Error) ( string) string {
switch len(.Entries) {
case 0:
return "no parse error"
case 1:
return .Entries[0].Show()
default:
:= new(strings.Builder)
fmt.Fprint(, "Multiple parse errors:")
for , := range .Entries {
.WriteString("\n" + + " ")
fmt.Fprintf(, "\033[31;1m%s\033[m\n", .Message)
.WriteString( + " ")
.WriteString(.Context.Show( + " "))
}
return .String()
}
}