-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
148 lines (126 loc) · 3.32 KB
/
types.go
File metadata and controls
148 lines (126 loc) · 3.32 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package adapter
import (
"github.com/code-game-project/cge-parser/parser"
"github.com/code-game-project/cge-parser/protobuf/schema"
)
type Metadata struct {
CGEVersion string
}
func metadataFromProtobuf(metadata *schema.Metadata) Metadata {
return Metadata{
CGEVersion: metadata.CgeVersion,
}
}
type Object struct {
Name string
Type ObjectType
Comment string
Properties []Property
}
type ObjectType int
const (
OTConfig = ObjectType(schema.Object_CONFIG)
OTCommand = ObjectType(schema.Object_COMMAND)
OTEvent = ObjectType(schema.Object_EVENT)
OTType = ObjectType(schema.Object_TYPE)
OTEnum = ObjectType(schema.Object_ENUM)
)
func objectFromProtobuf(object *schema.Object) Object {
if object.Comment == nil {
var c string
object.Comment = &c
}
properties := make([]Property, 0, len(object.Properties))
for _, p := range object.Properties {
properties = append(properties, propertyFromProtobuf(p))
}
return Object{
Name: object.Name,
Type: ObjectType(object.Type),
Comment: *object.Comment,
Properties: properties,
}
}
type Property struct {
Name string
Type *PropertyType
Comment string
}
type PropertyType struct {
Name string
Type DataType
Generic *PropertyType
}
type DataType int
const (
DTString = DataType(schema.Property_Type_STRING)
DTBool = DataType(schema.Property_Type_BOOL)
DTInt32 = DataType(schema.Property_Type_INT32)
DTInt64 = DataType(schema.Property_Type_INT64)
DTFloat32 = DataType(schema.Property_Type_FLOAT32)
DTFloat64 = DataType(schema.Property_Type_FLOAT64)
DTMap = DataType(schema.Property_Type_MAP)
DTList = DataType(schema.Property_Type_LIST)
DTEnumValue = DataType(schema.Property_Type_ENUM_VALUE)
DTCustom = DataType(schema.Property_Type_CUSTOM)
)
func propertyFromProtobuf(property *schema.Property) Property {
if property.Comment == nil {
var c string
property.Comment = &c
}
return Property{
Name: property.Name,
Type: propertyTypeFromProtobuf(property.Type),
Comment: *property.Comment,
}
}
func propertyTypeFromProtobuf(propertyType *schema.Property_Type) *PropertyType {
var generic *PropertyType
if propertyType.Generic != nil {
generic = propertyTypeFromProtobuf(propertyType.Generic)
}
return &PropertyType{
Name: propertyType.Name,
Type: DataType(propertyType.Type),
Generic: generic,
}
}
type DiagnosticType int
const (
DiagInfo = DiagnosticType(schema.Diagnostic_INFO)
DiagWarning = DiagnosticType(schema.Diagnostic_WARNING)
DiagError = DiagnosticType(schema.Diagnostic_ERROR)
)
type Diagnostic struct {
Type DiagnosticType
Message string
StartLine int
StartColumn int
EndLine int
EndColumn int
}
func diagnosticFromProtobuf(diagnostic *schema.Diagnostic) Diagnostic {
return Diagnostic{
Type: DiagnosticType(diagnostic.Type),
Message: diagnostic.Msg,
StartLine: int(diagnostic.Start.Line),
StartColumn: int(diagnostic.Start.Column),
EndLine: int(diagnostic.End.Line),
EndColumn: int(diagnostic.End.Column),
}
}
type Token struct {
Type parser.TokenType
Lexeme string
Line int
Column int
}
func tokenFromProtobuf(token *schema.Token) Token {
return Token{
Type: parser.TokenType(token.Type),
Lexeme: token.Lexeme,
Line: int(token.Pos.Line),
Column: int(token.Pos.Column),
}
}