-
Notifications
You must be signed in to change notification settings - Fork 4
/
error.go
36 lines (30 loc) · 907 Bytes
/
error.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
package ddperror
import (
"fmt"
"github.com/DDP-Projekt/Kompilierer/src/token"
)
// Error type for ddp-errors
type Error struct {
Code Code // the error code
Range token.Range // the range the error spans in its source
Msg string // the error message
File string // the filepath (or uri, url or whatever) in which the error occured
}
// simple string representation of the error
// should only be used for debugging
// the error-handlers handle the real formatting
func (err Error) String() string {
return fmt.Sprintf("(%04d) %s (Z: %d, S: %d): %s", err.Code, err.File, err.Range.Start.Line, err.Range.Start.Column, err.Msg)
}
func (err Error) Error() string {
return err.Msg
}
// create a new Error from the given parameters
func New(code Code, Range token.Range, msg, file string) Error {
return Error{
Code: code,
Range: Range,
Msg: msg,
File: file,
}
}