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
+20-6Lines changed: 20 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -7,11 +7,13 @@ 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
+
Note: See [Appendix A](#sec-Appendix-Notation-Conventions) for more information
15
+
about the lexical and syntactic grammar and other notational conventions used
16
+
throughout this document.
15
17
16
18
17
19
## Source Text
@@ -25,6 +27,19 @@ ASCII range so as to be as widely compatible with as many existing tools,
25
27
languages, and serialization formats as possible and avoid display issues in
26
28
text editors and source control.
27
29
30
+
**Greedy Lexical Parsing**
31
+
32
+
The source text of a GraphQL document is first converted into a sequence of
33
+
lexical tokens, {Token}, and ignored tokens, {Ignored}. The source text is
34
+
scanned from left to right, repeatedly taking the longest possible sequence of
35
+
unicode characters as the next token.
36
+
37
+
For example, the sequence `123` is always interpreted as a single {IntValue},
38
+
and `""""""` is always interpreted as a single block {StringValue}.
39
+
40
+
This sequence of lexical tokens are then scanned from left to right to produce
41
+
an abstract syntax tree (AST) according to the {Document} syntactical grammar.
42
+
28
43
29
44
### Unicode
30
45
@@ -118,8 +133,7 @@ Token ::
118
133
A GraphQL document is comprised of several kinds of indivisible lexical tokens
119
134
defined here in a lexical grammar by patterns of source Unicode characters.
120
135
121
-
Tokens are later used as terminal symbols in a GraphQL Document
122
-
syntactic grammars.
136
+
Tokens are later used as terminal symbols in GraphQL syntactic grammar rules.
0 commit comments