You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GraphQL syntactical grammars intend to be unambiguous. While lexical grammars should also be - there has historically been an assumption that lexical parsing is greedy. This is obvious for numbers and words, but less obvious for empty block strings.
Either way, the additional clarity removes ambiguity from the spec
Partial fix for #564
Specifically addresses #564 (comment)
Copy file name to clipboardExpand all lines: spec/Section 2 -- Language.md
+25-6Lines changed: 25 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -7,11 +7,18 @@ common unit of composition allowing for query reuse.
7
7
8
8
A GraphQL document is defined as a syntactic grammar where terminal symbols are
9
9
tokens (indivisible lexical units). These tokens are defined in a lexical
10
-
grammar which matches patterns of source characters (defined by a
11
-
double-colon `::`).
10
+
grammar which matches patterns of source characters. In this document, syntactic
11
+
grammar productions are distinguished with a colon `:` while lexical grammar
12
+
productions are distinguished with a double-colon `::`.
12
13
13
-
Note: See [Appendix A](#sec-Appendix-Notation-Conventions) for more details about the definition of lexical and syntactic grammar and other notational conventions
14
-
used in this document.
14
+
The source text of a GraphQL document must be a sequence of {SourceCharacter}.
15
+
The character sequence must be described by a sequence of {Token} and {Ignored}
16
+
lexical grammars. The lexical token sequence, omitting {Ignored}, must be
17
+
described by a single {Document} syntactic grammar.
18
+
19
+
Note: See [Appendix A](#sec-Appendix-Notation-Conventions) for more information
20
+
about the lexical and syntactic grammar and other notational conventions used
21
+
throughout this document.
15
22
16
23
17
24
## Source Text
@@ -25,6 +32,19 @@ ASCII range so as to be as widely compatible with as many existing tools,
25
32
languages, and serialization formats as possible and avoid display issues in
26
33
text editors and source control.
27
34
35
+
**Greedy Lexical Parsing**
36
+
37
+
The source text of a GraphQL document is first converted into a sequence of
38
+
lexical tokens, {Token}, and ignored tokens, {Ignored}. The source text is
39
+
scanned from left to right, repeatedly taking the longest possible sequence of
40
+
unicode characters as the next token.
41
+
42
+
For example, the sequence `123` is always interpreted as a single {IntValue},
43
+
and `""""""` is always interpreted as a single block {StringValue}.
44
+
45
+
This sequence of lexical tokens are then scanned from left to right to produce
46
+
an abstract syntax tree (AST) according to the {Document} syntactical grammar.
47
+
28
48
29
49
### Unicode
30
50
@@ -118,8 +138,7 @@ Token ::
118
138
A GraphQL document is comprised of several kinds of indivisible lexical tokens
119
139
defined here in a lexical grammar by patterns of source Unicode characters.
120
140
121
-
Tokens are later used as terminal symbols in a GraphQL Document
122
-
syntactic grammars.
141
+
Tokens are later used as terminal symbols in GraphQL syntactic grammar rules.
0 commit comments