@@ -69,13 +69,62 @@ Example_param :
69
69
- D
70
70
71
71
72
+ ## Ignored Source
73
+
74
+ Before and after every lexical token may be any amount of ignored source
75
+ characters including whitespace and comments. No ignored regions of a source
76
+ document are significant, however ignored source characters may appear within a
77
+ lexical token, for example a {String} may contain whitespace.
78
+
79
+ * Ignoring commas*
80
+
81
+ GraphQL ignores the comma ` , ` character. This ensures that the absence or
82
+ presence of a comma does not meaningfully alter the interpreted syntax of the
83
+ document, as this can be a common user-error in other languages. It also allows
84
+ for the stylistic use of either trailing commas or line-terminators as
85
+ delimiters which are often desired for legibility and maintainability of source
86
+ code. The use of commas, whitespace, and line-terminators is encouraged when
87
+ they improve the legibility of GraphQL documents.
88
+
89
+ GraphQL ignores these character sequences:
90
+
91
+ Ignored :
92
+ - WhiteSpace
93
+ - LineTerminator
94
+ - Comment
95
+ - ,
96
+
97
+ WhiteSpace :
98
+ - "Horizontal Tab (U+0009)"
99
+ - "Vertical Tab (U+000B)"
100
+ - "Form Feed (U+000C)"
101
+ - "Space (U+0020)"
102
+ - "No-break Space (U+00A0)"
103
+
104
+ LineTerminator :
105
+ - "New Line (U+000A)"
106
+ - "Carriage Return (U+000D)"
107
+ - "Line Separator (U+2028)"
108
+ - "Paragraph Separator (U+2029)"
109
+
110
+ Comment :
111
+ - ` # ` CommentChar+?
112
+
113
+ CommentChar : "Any character" but not LineTerminator
114
+
115
+
72
116
## Tokens
73
117
74
118
A GraphQL document is comprised of several kinds of source tokens defined here
75
- in a lexical grammar and used as terminal symbols in GraphQL's syntactic
76
- grammar. This lexical grammar defines patterns of source characters by specifying
77
- character patterns in {` monospace ` } or as {/regular_expressions/}. Non-terminal
78
- patterns are defined as {Italics}.
119
+ in a lexical grammar. This lexical grammar defines patterns of source characters
120
+ by specifying character patterns in {` monospace ` } or as {/regular_expressions/}.
121
+ Non-terminal patterns are defined as {Italics}.
122
+
123
+ No characters are ignored while parsing a given token, for example no whitespace
124
+ is allowed between the characters defining a {FloatValue}, however ignored
125
+ characters are skipped before and after each well-formed Token.
126
+
127
+ Tokens are later used as terminal symbols in GraphQL's syntactic grammar.
79
128
80
129
The GraphQL document syntactic grammar is defined in terms of these
81
130
lexical tokens:
@@ -124,55 +173,19 @@ EscapedUnicode : u /[0-9A-Fa-f]{4}/
124
173
EscapedCharacter : one of ` " ` \ ` / ` b f n r t
125
174
126
175
127
-
128
- ### Ignored Source
129
-
130
- Before every lexical token may be any amount of ignored source characters
131
- such as whitespace and comments. Whitespace, other than within strings, is
132
- not significant.
133
-
134
- GraphQL treats comma ` , ` similarly to whitespace. This ensures that the absence
135
- or presence of a comma does not meaningfully alter the interpreted syntax of
136
- the document which is a common user-error in other languages. It also allows for
137
- the stylistic use of trailing commas or line-breaks as delimiters which are
138
- often desired for legibility and maintainability of source code. The use of
139
- commas and other whitespace is suggested when it improves legibility.
140
-
141
- GraphQL ignores these character sequences:
142
-
143
- Ignored :
144
- - WhiteSpace
145
- - LineTerminator
146
- - Comment
147
- - ,
148
-
149
- WhiteSpace :
150
- - "Horizontal Tab (U+0009)"
151
- - "Vertical Tab (U+000B)"
152
- - "Form Feed (U+000C)"
153
- - "Space (U+0020)"
154
- - "No-break Space (U+00A0)"
155
-
156
- LineTerminator :
157
- - "New Line (U+000A)"
158
- - "Carriage Return (U+000D)"
159
- - "Line Separator (U+2028)"
160
- - "Paragraph Separator (U+2029)"
161
-
162
- Comment :
163
- - ` # ` CommentChar+?
164
-
165
- CommentChar : "Any character" but not LineTerminator
166
-
167
-
168
-
169
176
## Syntax
170
177
171
178
A GraphQL document is defined in a syntactic grammar where terminal symbols are
172
179
expressed as either an italicized token (ex. {Document}) or as
173
- monospaced short-hand for a {Punctuator} (ex. {` : ` }) or {Name}
180
+ monospaced short-hand for a {Punctuator} (ex. {` : ` }) or short-hand for a {Name}
174
181
(ex. {` query ` }).
175
182
183
+ Since whitespace, comments, and other ignored source is skipped between each
184
+ well-formed token, this ignored source can appear at any point between the
185
+ terminal tokens in the syntactic grammars defined below. However GraphQL
186
+ source documents are encouraged to use ignored source only to
187
+ improve legibility.
188
+
176
189
177
190
### Document
178
191
0 commit comments