Skip to content

Commit b062dc3

Browse files
committed
Fixing enum value definitions
1 parent 5b0d96e commit b062dc3

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

ast/definitions.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,18 @@ type EnumValueDefinition struct {
271271
BaseNode
272272
Name *Name `json:"name"`
273273
Description *StringValue `json:"description,omitempty"` // Optional
274+
Index *IntValue `json:"index"`
275+
Display *StringValue `json:"display,omitempty"` // Optional
274276
AnnotatedNode
275277
}
276278

277-
func NewEnumValueDefinition(loc *Location, name *Name, description *StringValue, annotations []*Annotation) *EnumValueDefinition {
279+
func NewEnumValueDefinition(loc *Location, name *Name, description *StringValue, index *IntValue, display *StringValue, annotations []*Annotation) *EnumValueDefinition {
278280
return &EnumValueDefinition{
279281
BaseNode: BaseNode{kinds.EnumValueDefinition, loc},
280282
Name: name,
281283
Description: description,
284+
Index: index,
285+
Display: display,
282286
AnnotatedNode: AnnotatedNode{annotations},
283287
}
284288
}

parser/parser.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,14 +1178,34 @@ func parseEnumValueDefinition(parser *Parser) (interface{}, error) {
11781178
if err != nil {
11791179
return nil, err
11801180
}
1181+
_, err = expect(parser, lexer.TokenKind[lexer.EQUALS])
1182+
if err != nil {
1183+
return nil, err
1184+
}
1185+
token, err := expect(parser, lexer.TokenKind[lexer.INT])
1186+
if err != nil {
1187+
return nil, err
1188+
}
1189+
indexValue, err := strconv.Atoi(token.Value)
1190+
index := ast.NewIntValue(loc(parser, token.Start), indexValue)
11811191
annotations, err := parseAnnotations(parser)
11821192
if err != nil {
11831193
return nil, err
11841194
}
1195+
var display *ast.StringValue
1196+
if _, ok, err := optionalKeyWord(parser, "as"); err != nil {
1197+
return nil, err
1198+
} else if ok {
1199+
if display, err = parseStringLiteral(parser); err != nil {
1200+
return nil, err
1201+
}
1202+
}
11851203
return ast.NewEnumValueDefinition(
11861204
loc(parser, start),
11871205
name,
11881206
description,
1207+
index,
1208+
display,
11891209
annotations,
11901210
), nil
11911211
}

0 commit comments

Comments
 (0)