Skip to content

Commit 1aacac4

Browse files
committed
add delimited many
1 parent a992775 commit 1aacac4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Sources/GraphQL/Language/Lexer.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ func advanceLexer(lexer: Lexer) throws -> Token {
4646
return token
4747
}
4848

49+
/**
50+
* Returns a non-empty list of parse nodes, determined by the parseFn.
51+
* This list may begin with a lex token of delimiterKind followed by items separated by lex tokens of tokenKind.
52+
* Advances the parser to the next lex token after last item in the list.
53+
*/
54+
func delimitedMany<T>(lexer: Lexer, kind: Token.Kind, parseFn: (Lexer) throws -> T) throws -> [T] {
55+
_ = try expectOptional(lexer: lexer, kind: kind)
56+
57+
var nodes: [T] = []
58+
repeat {
59+
try nodes.append(parseFn(lexer))
60+
} while (try expectOptional(lexer: lexer, kind: kind) != nil)
61+
62+
return nodes
63+
}
64+
4965
/**
5066
* The return type of createLexer.
5167
*/

0 commit comments

Comments
 (0)