-
Notifications
You must be signed in to change notification settings - Fork 4
/
tokentype_jsonenums.go
71 lines (64 loc) · 1.7 KB
/
tokentype_jsonenums.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
69
70
71
// generated by jsonenums -type=TokenType; DO NOT EDIT
package ling
import (
"encoding/json"
"fmt"
)
var (
_TokenTypeNameToValue = map[string]TokenType{
"EOF": EOF,
"Space": Space,
"Symbol": Symbol,
"Number": Number,
"Letters": Letters,
"Punct": Punct,
"Word": Word,
}
_TokenTypeValueToName = map[TokenType]string{
EOF: "EOF",
Space: "Space",
Symbol: "Symbol",
Number: "Number",
Letters: "Letters",
Punct: "Punct",
Word: "Word",
}
)
func init() {
var v TokenType
if _, ok := interface{}(v).(fmt.Stringer); ok {
_TokenTypeNameToValue = map[string]TokenType{
interface{}(EOF).(fmt.Stringer).String(): EOF,
interface{}(Space).(fmt.Stringer).String(): Space,
interface{}(Symbol).(fmt.Stringer).String(): Symbol,
interface{}(Number).(fmt.Stringer).String(): Number,
interface{}(Letters).(fmt.Stringer).String(): Letters,
interface{}(Punct).(fmt.Stringer).String(): Punct,
interface{}(Word).(fmt.Stringer).String(): Word,
}
}
}
// MarshalJSON is generated so TokenType satisfies json.Marshaler.
func (r TokenType) MarshalJSON() ([]byte, error) {
if s, ok := interface{}(r).(fmt.Stringer); ok {
return json.Marshal(s.String())
}
s, ok := _TokenTypeValueToName[r]
if !ok {
return nil, fmt.Errorf("invalid TokenType: %d", r)
}
return json.Marshal(s)
}
// UnmarshalJSON is generated so TokenType satisfies json.Unmarshaler.
func (r *TokenType) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("TokenType should be a string, got %s", data)
}
v, ok := _TokenTypeNameToValue[s]
if !ok {
return fmt.Errorf("invalid TokenType %q", s)
}
*r = v
return nil
}