File: errors.go

package info (click to toggle)
mtail 0.0%2Bgit20161231.ae129e9-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,900 kB
  • ctags: 505
  • sloc: yacc: 427; makefile: 121; sh: 105; lisp: 66; awk: 17
file content (40 lines) | stat: -rw-r--r-- 757 bytes parent folder | download | duplicates (2)
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
// 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})
}

//

// 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
}