-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
50 lines (40 loc) · 853 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
43
44
45
46
47
48
49
50
package mist
import "fmt"
// +---------+
// | Lexical |
// +---------+
type LexicalError struct {
Origin Origin
Message string
Token string
}
func NewLexicalError(filename string, line, column int, message, token string) error {
return LexicalError{
NewOrigin(filename, line, column),
message,
token,
}
}
func (e LexicalError) Error() string {
end := ""
if e.Token != "" {
end = ": " + e.Token
}
return fmt.Sprintf("%v: lexical error: %s%s", e.Origin, e.Message, end)
}
// +-------------+
// | Compilation |
// +-------------+
type CompilationError struct {
Origin Origin
Message string
}
func NewCompilationError(origin Origin, message string) error {
return CompilationError{
origin,
message,
}
}
func (e CompilationError) Error() string {
return fmt.Sprintf("%v: compilation error: %s", e.Origin, e.Message)
}