@@ -780,7 +780,12 @@ func parseObjectTypeDefinition(lexer: Lexer) throws -> ObjectTypeDefinition {
780
780
let name = try parseName ( lexer: lexer)
781
781
let interfaces = try parseImplementsInterfaces ( lexer: lexer)
782
782
let directives = try parseDirectives ( lexer: lexer)
783
- let fields = try optionalMany ( lexer: lexer, openKind: . openingBrace, closeKind: . closingBrace, parse: parseFieldDefinition)
783
+ let fields = try optionalMany (
784
+ lexer: lexer,
785
+ openKind: . openingBrace,
786
+ closeKind: . closingBrace,
787
+ parse: parseFieldDefinition
788
+ )
784
789
return ObjectTypeDefinition (
785
790
loc: loc ( lexer: lexer, startToken: start) ,
786
791
description: description,
@@ -798,8 +803,8 @@ func parseObjectTypeDefinition(lexer: Lexer) throws -> ObjectTypeDefinition {
798
803
*/
799
804
func parseImplementsInterfaces( lexer: Lexer ) throws -> [ NamedType ] {
800
805
try expectOptionalKeyword ( lexer: lexer, value: " implements " )
801
- ? delimitedMany ( lexer: lexer, kind: . amp, parseFn: parseNamedType)
802
- : [ ]
806
+ ? delimitedMany ( lexer: lexer, kind: . amp, parseFn: parseNamedType)
807
+ : [ ]
803
808
}
804
809
805
810
/**
@@ -877,7 +882,12 @@ func parseInterfaceTypeDefinition(lexer: Lexer) throws -> InterfaceTypeDefinitio
877
882
let name = try parseName ( lexer: lexer)
878
883
let interfaces = try parseImplementsInterfaces ( lexer: lexer)
879
884
let directives = try parseDirectives ( lexer: lexer)
880
- let fields = try optionalMany ( lexer: lexer, openKind: . openingBrace, closeKind: . closingBrace, parse: parseFieldDefinition)
885
+ let fields = try optionalMany (
886
+ lexer: lexer,
887
+ openKind: . openingBrace,
888
+ closeKind: . closingBrace,
889
+ parse: parseFieldDefinition
890
+ )
881
891
return InterfaceTypeDefinition (
882
892
loc: loc ( lexer: lexer, startToken: start) ,
883
893
description: description,
@@ -915,8 +925,8 @@ func parseUnionTypeDefinition(lexer: Lexer) throws -> UnionTypeDefinition {
915
925
*/
916
926
func parseUnionMembers( lexer: Lexer ) throws -> [ NamedType ] {
917
927
try expectOptional ( lexer: lexer, kind: . equals) != nil
918
- ? delimitedMany ( lexer: lexer, kind: . pipe, parseFn: parseNamedType)
919
- : [ ]
928
+ ? delimitedMany ( lexer: lexer, kind: . pipe, parseFn: parseNamedType)
929
+ : [ ]
920
930
}
921
931
922
932
/**
@@ -930,7 +940,12 @@ func parseEnumTypeDefinition(lexer: Lexer) throws -> EnumTypeDefinition {
930
940
try expectKeyword ( lexer: lexer, value: " enum " )
931
941
let name = try parseName ( lexer: lexer)
932
942
let directives = try parseDirectives ( lexer: lexer)
933
- let values = try optionalMany ( lexer: lexer, openKind: . openingBrace, closeKind: . closingBrace, parse: parseEnumValueDefinition)
943
+ let values = try optionalMany (
944
+ lexer: lexer,
945
+ openKind: . openingBrace,
946
+ closeKind: . closingBrace,
947
+ parse: parseEnumValueDefinition
948
+ )
934
949
return EnumTypeDefinition (
935
950
loc: loc ( lexer: lexer, startToken: start) ,
936
951
description: description,
@@ -969,7 +984,12 @@ func parseInputObjectTypeDefinition(lexer: Lexer) throws -> InputObjectTypeDefin
969
984
try expectKeyword ( lexer: lexer, value: " input " )
970
985
let name = try parseName ( lexer: lexer)
971
986
let directives = try parseDirectives ( lexer: lexer)
972
- let fields = try optionalMany ( lexer: lexer, openKind: . openingBrace, closeKind: . closingBrace, parse: parseInputValueDef)
987
+ let fields = try optionalMany (
988
+ lexer: lexer,
989
+ openKind: . openingBrace,
990
+ closeKind: . closingBrace,
991
+ parse: parseInputValueDef
992
+ )
973
993
return InputObjectTypeDefinition (
974
994
loc: loc ( lexer: lexer, startToken: start) ,
975
995
description: description,
@@ -1228,13 +1248,13 @@ func expectKeyword(lexer: Lexer, value: String) throws -> Token {
1228
1248
}
1229
1249
1230
1250
/**
1231
- * If the next token is a given keyword, return "true" after advancing the lexer.
1232
- * Otherwise, do not change the parser state and return "false".
1233
- */
1251
+ * If the next token is a given keyword, return "true" after advancing the lexer.
1252
+ * Otherwise, do not change the parser state and return "false".
1253
+ */
1234
1254
@discardableResult
1235
1255
func expectOptionalKeyword( lexer: Lexer , value: String ) throws -> Bool {
1236
1256
let token = lexer. token
1237
- guard token. kind == . name && token. value == value else {
1257
+ guard token. kind == . name, token. value == value else {
1238
1258
return false
1239
1259
}
1240
1260
try lexer. advance ( )
@@ -1277,12 +1297,17 @@ func any<T>(
1277
1297
}
1278
1298
1279
1299
/**
1280
- * Returns a list of parse nodes, determined by the parseFn.
1281
- * It can be empty only if open token is missing otherwise it will always return non-empty list
1282
- * that begins with a lex token of openKind and ends with a lex token of closeKind.
1283
- * Advances the parser to the next lex token after the closing token.
1284
- */
1285
- func optionalMany< T> ( lexer: Lexer , openKind: Token . Kind , closeKind: Token . Kind , parse: ( Lexer ) throws -> T ) throws -> [ T ] {
1300
+ * Returns a list of parse nodes, determined by the parseFn.
1301
+ * It can be empty only if open token is missing otherwise it will always return non-empty list
1302
+ * that begins with a lex token of openKind and ends with a lex token of closeKind.
1303
+ * Advances the parser to the next lex token after the closing token.
1304
+ */
1305
+ func optionalMany< T> (
1306
+ lexer: Lexer ,
1307
+ openKind: Token . Kind ,
1308
+ closeKind: Token . Kind ,
1309
+ parse: ( Lexer ) throws -> T
1310
+ ) throws -> [ T ] {
1286
1311
guard try expectOptional ( lexer: lexer, kind: openKind) != nil else {
1287
1312
return [ ]
1288
1313
}
0 commit comments