This repository has been archived by the owner on May 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lang.go
68 lines (63 loc) · 2.03 KB
/
lang.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package idl
import (
"fmt"
)
var (
IdlTypes = []string{
"bool", // boolean (true/false)
"byte", // unsigned 8-bit integer (33, 22)
"int8", // signed 8-bit integer (-33, 22)
"int16", // signed 16-bit integer (-9655, 22)
"int32", // signed 32-bit integer (-944332, 22)
"int64", // signed 64-bit integer (-3443434343, 22)
"float32", // 32-bit floating point (3.14)
"float64", // 64-bit floating point (3.141592)
"string", // string of utf8 text ("\tSome text\r\n")
"datetime", // date-time object ("2013-09-09T13:44.22.341-05:00")
"decimal", // large decimal value ("300.2415443")
"char", // single utf8 character ("\r", "A")
"binary", // byte array or blob ("YXNhZGFzZAo=")
}
IdlContainers = []string{
"list",
"map",
}
)
// Error defines fields that will be logged in a uniform format for build tools to process
// Source (Line, Column): Category (error|warning) Code: Message
type Error struct {
Source string // source of the error - program name, file name, etc. Defaults to "babel"
Line int // Line number in the file (optional)
Column int // Column number within the line (optional)
Category string // Additional cateogrization "Commmand line", "Parsing", etc. (optional)
IsWarning bool // True if the message is a warning message
Code int // Specific error number
Message error // Text of the error message or another error
}
// Implement the error interface
func (e *Error) Error() string {
prefix := ""
if e.Source != "" {
prefix += e.Source
} else {
prefix += "babel"
}
if e.Line > 0 {
if e.Column > 0 {
prefix += fmt.Sprintf("(%d,%d)", e.Line, e.Column)
} else {
prefix += fmt.Sprintf("(%d)", e.Line)
}
}
prefix += ": "
if e.Category != "" {
prefix += e.Category + " "
}
if e.IsWarning {
prefix += fmt.Sprintf("warning %d: ", e.Code)
} else {
prefix += fmt.Sprintf("error %d: ", e.Code)
}
return prefix + e.Message.Error()
}
// Sample: return &idl.Error{Code = 500, Message = fmt.Errorf(...)}