/
errors.go
42 lines (34 loc) · 832 Bytes
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2015 Google Inc. All Rights Reserved.
// This file is available under the Apache license.
package vm
import "fmt"
type compileError struct {
pos position
msg string
}
func (e compileError) Error() string {
return e.pos.String() + ": " + e.msg
}
// ErrorList contains a list of compile errors.
type ErrorList []*compileError
// Add appends an error at a position to the list of errors.
func (p *ErrorList) Add(pos *position, msg string) {
*p = append(*p, &compileError{*pos, msg})
}
func (p *ErrorList) Append(l ErrorList) {
*p = append(*p, l...)
}
// ErrorList implements the error interface.
func (p ErrorList) Error() string {
switch len(p) {
case 0:
return "no errors"
case 1:
return p[0].Error()
}
var r string
for _, e := range p {
r = r + fmt.Sprintf("%s\n", e)
}
return r[:len(r)-1]
}