Skip to content

Commit c3b9ca3

Browse files
committed
Reuse 'many' for parsing document
Replicates graphql/graphql-js@cb0097c
1 parent 2362ef3 commit c3b9ca3

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

graphql/language/parser.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,14 @@ def parse_name(lexer: Lexer) -> NameNode:
115115
return NameNode(value=token.value, loc=loc(lexer, token))
116116

117117

118+
# Implement the parsing rules in the Document section.
119+
118120
def parse_document(lexer: Lexer) -> DocumentNode:
119121
"""Document: Definition+"""
120122
start = lexer.token
121-
expect(lexer, TokenKind.SOF)
122-
definitions: List[DefinitionNode] = []
123-
append = definitions.append
124-
while True:
125-
append(parse_definition(lexer))
126-
if skip(lexer, TokenKind.EOF):
127-
break
128-
return DocumentNode(definitions=definitions, loc=loc(lexer, start))
123+
return DocumentNode(definitions=many_nodes(
124+
lexer, TokenKind.SOF, parse_definition, TokenKind.EOF),
125+
loc=loc(lexer, start))
129126

130127

131128
def parse_definition(lexer: Lexer) -> DefinitionNode:
@@ -345,7 +342,7 @@ def parse_fragment_name(lexer: Lexer) -> NameNode:
345342
return parse_name(lexer)
346343

347344

348-
# Implements the parsing rules in the Values section.
345+
# Implement the parsing rules in the Values section.
349346

350347
def parse_value_literal(lexer: Lexer, is_const: bool) -> ValueNode:
351348
func = _parse_value_literal_functions.get(lexer.token.kind)

0 commit comments

Comments
 (0)