-
Notifications
You must be signed in to change notification settings - Fork 4
/
884.txt
341 lines (263 loc) · 17.9 KB
/
884.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
[26] [[HTTP]] および関連仕様は、いくつかの [[ABNF]] の派生版を使っています。
* RFC 1945, RFC 2068, RFC 2616 の ABNF
[1] RFC 1945 ([[HTTP/1.0]]), RFC 2068 / RFC 2616 ([[HTTP/1.1]])
で使われている [[ABNF]] です。
[[RFC 822のABNF]] を元にしていますが、選択 ([Q[or]]) は [CODE(ABNF)["/"]]
ではなく [CODE(ABNF)["|"]] を使います。
[36] また、[[リスト]]を表す [CODE[#]] 記法が定義されています。
[2] [[RFC 1945]], [[RFC 2068]], [[RFC 2616]] 2.1節で規定されています。
[4] HTTP RFC では、 [CODE(ABNF)[*[[LWS]]]] の挿入可能箇所を構文では明記せずに、
本文で説明しています。
[14] 右辺が [CODE(ABNF)[< [VAR[自然言語文]] >]] のような形で定義されることがあります。
(がそのことは [[ABNF]] の定義に明記はされていません。)
[34] いくつかの [[HTTP]] 系の [[RFC]] などがこの [[ABNF]] を参照しています。
[35] [[RFC 2616]] の改訂版である [[RFC 7230]] は、この [[ABNF]]
を引き継がず、 [[IETF]] の [[ABNF]] ([[RFC 822]] から派生したもの) をベースにしています (後述)。
* RFC 1738 の ABNF
[37] [[RFC 1738]] は、 [[RFC 822]] の [[ABNF]] のバリエーションとして、
[FIG(list)[
- [38] 選択は [CODE[/]] ではなく [CODE[|]]
- [39] [[グループ化]]は [CODE[( ... )]] ではなく [CODE[ [ ... ] ]]
]FIG]
... としたものを使っていました。
;; 単なる [ ... ] は [[RFC 822]] と同じく省略を表します。 *[ ... ] は0個以上を表します。
1*[ ... ] は1個以上を表します。 ([CODE[*]] は [[RFC 822]] と同義です。)
[41] [[RFC 2056]] は [[RFC 1738]] と同じもの [SRC[>>40]] を採用していました。
[REFS[
- [8] [CITE@en[RFC 1738 - Uniform Resource Locators (URL)]] ([TIME[2015-06-28 14:20:24 +09:00]] 版) <http://tools.ietf.org/html/rfc1738#section-5>
- [40] [CITE@en[RFC 2056 - Uniform Resource Locators for Z39.50]] ([TIME[2015-06-14 14:22:55 +09:00]] 版) <http://tools.ietf.org/html/rfc2056#section-5>
]REFS]
* CGI の ABNF
[13] [[RFC 3875]] ([[CGI/1.1]]) は「[[RFC 822]] のものと似た [[ABNF]]」を定義しています。
実態としては [[HTTP]] の [[ABNF]] と同じものです。
[15] ただし [CODE(ABNF)[[['''#''']]]] や [CODE(ABNF)[[[;]]]] は定義されておらず使ってもいません。
[16] また [[LWS]] の挿入に関しては言及がありません (が実際には [[HTTP]] 同様特定の箇所で認められています)。
[REFS[
- [12] [CITE@en[RFC 3875 - The Common Gateway Interface (CGI) Version 1.1]] ([TIME[2011-05-08 16:20:31 +09:00]] 版) <http://tools.ietf.org/html/rfc3875>
]REFS]
[19] [[CGI]] では [[ABNF]] は特定の[[ビット列]]、[[バイト列]]を定義するものではなく、
[[文字列]]を表しており、その具体的な表現は[[システム定義]]または文脈依存であるとされています [SRC[>>12 2.2.]]。
[20] [[CGI]] の仕様では[[空文字列]]を明示するために [CODE(ABNF)[""]] と記述していることがよくあります。
[21] 明確に説明されていませんが、反復回数を変数のように表現することがあります。
[EG[
[22] 例えば
[PRE[
request-body = <CONTENT_LENGTH>OCTET
]PRE]
... は、 [CODE(ABNF)@en[[[OCTET]]]] の長さが [CODE(CGI)@en[[[CONTENT_LENGTH]]]]
であることを表します。
]EG]
[23] 一部の構造では、 [[ABNF]] 上で順序が定義されていても、実際には任意の順序で構わないと定義されています。
* RFC 2069 の ABNF
[24] [[Digest認証]]を規定する [[RFC 2068]] は、 [[HTTPのABNF]] を使うと述べていますが、
実際には [VAR[FOO(...)]] のような関数の表記を使っています。これは1個以上の引数に対して関数を適用した結果が[[生成規則]]の[[項]]として使われることを表しています。
* RFC 2295 の ABNF
[3] [[RFC 2295]] (3.) は [[HTTPのABNF]]に更に追加の記法
[DFN[[CODE(ABNF)[[[%]]]]]] [SRC[>>5]] を定義しています。
[FIG(ABNF)[
-element /= ssv
-ssv = ( [number] "%" [number] ) element ;; %rule
--;; [CODE(ABNF)[1%rule]] == [CODE(ABNF)[rule *(FWS rule)]]
]FIG]
[REFS[
- [5] [CITE@en[RFC 2295 - Transparent Content Negotiation in HTTP]] ([TIME[2014-08-31 19:36:42 +09:00]] 版) <http://tools.ietf.org/html/rfc2295#section-3>
]REFS]
* RFC 3229 の ABNF
[25] [[RFC 3229]] は [[RFC 2616]] の [[ABNF]] を使っているようですが (明記はされていません)、
既存の定義に更に新たな定義を付け加えることを表すために「[CODE(ABNF)[...]]」を使っています。
* AtomPub の ABNF
[10] [[RFC 5023]] は [CODE(HTTP)@en[[[Slug]]:]] [[頭欄]]の定義に
[[RFC 2616のABNF]] を使っているとしています。
[REFS[
-[17] [CITE@en[RFC 5023 - The Atom Publishing Protocol]] ([TIME[2008-11-20 18:52:14 +09:00]] 版) <http://tools.ietf.org/html/rfc5023#section-9.7.1>
]REFS]
[11] しかし、実際には [[RFC 4234のABNF]] にある
[CODE(ABNF)[%20-7E]] という表現が混在しています。
;; [CODE(ABNF)[[[|]]]] を使っているので、 [[RFC 4234のABNF]] ではありません。
* RFC 7230 の ABNF
[27] [[HTTP/1.1]] の第3次仕様である [[RFC 7230]] 他では、 [[RFC 5234]]
を拡張した [[ABNF]] を用いています。
[REFS[
- [28] [CITE@en[RFC 7230 - Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing]] ([TIME[2014-06-07 01:59:35 +09:00]] 版) <https://tools.ietf.org/html/rfc7230#section-1.2>
- [31] [CITE@en[RFC 7230 - Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing]] ([TIME[2014-06-07 01:59:35 +09:00]] 版) <https://tools.ietf.org/html/rfc7230#section-7>
]REFS]
[32] [[RFC 2616]] 以前と同様な[[リスト][リスト (HTTP)]]記法 ([CODE[#][リスト (HTTP)]]) が定義されています。
;; [33] 詳しくは[[リスト (HTTP)]]の項を参照してください。
[30] [[RFC 2822]] と同様に、 [CODE[[[obs-*]]]] という[[生成規則]]が[[廃止]]された構文を表す
[SRC[>>28]] ことになっています。
* 歴史
[FIG(quotation)[
[FIGCAPTION[
RFC 1945 (HTTP/1.0) 2.; RFC 2068・2616 (HTTP/1.1) 2 Notational Conventions and Generic Grammar
]FIGCAPTION]
*2.1 Augmented BNF
> All of the mechanisms specified in this document are described in
both prose and an augmented Backus-Naur Form (BNF) similar to that
used by RFC 822 [DEL[ [7] ]][INS[ [9] ]]. [DEL[[DEL[Implementors]] [INS[Implementers]]]] [INS[Implementors]] will need to be familiar with the
notation in order to understand this specification. The augmented BNF
includes the following constructs:
この文書で規定するすべての機構は、文章および [[RFC 822]]
で使われているものに似た増補 Backus・Naur 式 ([[BNF]])
で記述します。実装者は、この視湯所を理解するためにこの記法に精通する必要があります。
増補 BNF には、次の構造が含まれます。
>
:name = definition:
The name of a rule is simply the name itself (without any enclosing
"<" and ">") and is separated from its definition by the equal [DEL[character "="]] [INS["=" character]].
White[INS[ ]]space [INS[{2616}]] is only significant in that indentation of continuation lines is used to indicate a rule definition that spans
more than one line. Certain basic rules are in uppercase, such as
SP, LWS, HT, CRLF, DIGIT, ALPHA, etc. Angle brackets are used
within definitions whenever their presence will facilitate
discerning the use of rule names.
規則の名前は、単に名前自体 ([CODE[<]] や [CODE[>]] で囲まない。) であり、
その定義とは [CODE(ABNF)[=]] 文字で分離します。
[[空白]]は、規則定義が複数行にまたがっていることを示すための、
継続行標識として使われるときのみ意味を持ちます。
幾つかの基本規則は、 [CODE(ABNF)[[[SP]]]], [CODE(ABNF)[[[LWS]]]],
[CODE(ABNF)[[[HT]]]], [CODE(ABNF)[[[CRLF]]]], [CODE(ABNF)[[[DIGIT]]]],
[CODE(ABNF)[[[ALPHA]]]] などのように大文字です。
角括弧は、定義中で規則名を使っていることをわかりやすくできるのであれば使用します。
>
:"literal":
Quotation marks surround literal text. Unless stated otherwise, the
text is case-insensitive.
引用符は表記文を囲みます。特に言及されていない限り、
文は大文字・小文字を区別しません。
>
:rule1 | rule2:
Elements separated by a bar ([DEL["I"]][INS["|"]]) are alternatives,
e.g., "yes | no" will accept yes or no.
棒線 ([CODE(ABNF)[|]]) で分離した要素群は、代替選択肢で、
例えば [SAMP(ABNF)[yes | no]] は [SAMP(ABNF)[yes]] または [SAMP(ABNF)[no]]
を受け入れます。
>
:(rule1 rule2):
Elements enclosed in parentheses are treated as a single element.
Thus, "(elem (foo | bar) elem)" allows the token sequences "elem foo elem" and "elem bar elem".
括弧で囲まれた要素群は、単一の要素として扱います。
従って、 [SAMP(ABNF)[(elem (foo | bar) elem)]]
は字句列 [SAMP(ABNF)[elem foo elem]] および [SAMP(ABNF)[elem bar elem]]
を認めます。
>
:*rule:
The character "*" preceding an element indicates repetition. The
full form is "<n>*<m>element" indicating at least <n> and at most
<m> occurrences of element. Default values are 0 and infinity so
that "*(element)" allows any number, including zero; "1*element"
requires at least one; and "1*2element" allows one or two.
要素の前の文字 [CODE(ABNF)[*]] は、反復を示します。
完全形は [CODE(ABNF)[[VAR[<n>]]*[VAR[<m>]][VAR[element]]]] で、
最低 [VAR[<n>]] 個、最高 [VAR[<m>]] 個の [VAR(ABNF)[element]]
が現れることを示しています。既定値は [CODE[0]] と[[∞]]ですから、
[SAMP(ABNF)[*([VAR[element]])]] は零個を含む任意個を認めます。
[SAMP(ABNF)[1*[VAR[element]]]] は最低1つ必要です。
[SAMP(ABNF)[1*2[VAR[element]]]] は1つか2つ認めます。
>
:[rule]:
Square brackets enclose optional elements; "[foo bar]" is
equivalent to "*1(foo bar)".
四角括弧は任意選択要素を囲みます。 [SAMP(ABNF)[ [foo bar] ]]
は [SAMP(ABNF)[*1(foo bar)]] と同等です。
>
:N rule:
Specific repetition: "<n>(element)" is equivalent to
"<n>*<n>(element)"; that is, exactly <n> occurrences of (element).
Thus 2DIGIT is a 2-digit number, and 3ALPHA is a string of three alphabetic characters.
特定反復: [CODE(ABNF)[[VAR[<n>]]([VAR[element]])]] は
[CODE(ABNF)[[VAR[<n>]]*[VAR[<n>]]([VAR[element]])]] と同等です。
つまり、丁度 [VAR[<n>]] 回の [VAR(ABNF)[element]] の出現です。
従って、 [SAMP(ABNF)[2DIGIT]] は2桁の数字で、
[SAMP(ABNF)[3ALPHA]] は3文字の英数字の文字列です。
>
:#rule:
A construct "#" is defined, similar to "*", for defining lists of
elements. The full form is "<n>#<m>element " indicating at least
<n> and at most <m> elements, each separated by one or
more commas (",") and [DEL[optional]] [INS[[INS[{2616}]] OPTIONAL]] linear white[INS[ ]]space [INS[{2616}]] (LWS). This
makes the usual form of lists very easy; a rule such as [DEL["]]( *LWS element *( *LWS "," *LWS element )) [DEL["]] can be shown as [DEL["]]1#element[DEL["]] [INS[{削除部 = 1945,2068}]]. Wherever this
construct is used, null elements are allowed, but do not contribute
to the count of elements present. That is, "(element), , (element)"
is permitted, but counts as only two elements. Therefore, where
at least one element is required, at least one non-null element [DEL[must]] [INS[[INS[{2616}]] MUST]] be present. Default values are 0 and infinity so that [DEL[[INS[{1945}]] "#(element)"]] [INS["#element"]]
allows any number, including zero; "1#element" requires at least one; and "1#2element" allows one or two.
構造 [CODE(ABNF)[#]] は、要素の並びを定義するために、 [CODE(ABNF)[*]] と同様に定義します。完全形は [CODE(ABNF)[[VAR[<n>]]#[VAR[<m>]][VAR[element]]]] で、最低 [VAR[<n>]] 個、最高 [VAR[<m>]] 個の [VAR(ABNF)[element]] であり、それぞれは一つ以上の読点 ([CODE(ABNF)[,]]) と'''[[任意選択]]'''で[[線形空白]] ([CODE(ABNF)[[[LWS]]]]) で分離します。これは並びの通常形を非常に容易とします。 [SAMP(ABNF)[( *LWS element *( *LWS "," *LWS element ))]] のような規則は [SAMP(ABNF)[1#element]] と示すことができます。
個の構造が使われているときはいつでも空の要素が認められますが、出現要素の数に入れません。つまり、 [SAMP(ABNF)[(element), , (element)]] は認められますが、
2つだけの要素と数えます。従って、最低一つの要素が必要なところでは、最低一つの空でない要素が現れなければ'''なりません'''。既定値は 0 と無限大ですので、
[SAMP(ABNF)[#element]] は零個を含む任意個を認めます。 [SAMP(ABNF)[1#element]] は最低一個必要です。 [SAMP(ABNF)[1#2element]] は1個か2個認めます。
>
:; comment:
A semi-colon, set off some distance to the right of rule text,
starts a comment that continues to the end of line. This is a
simple way of including useful notes in parallel with the specifications.
セミコロンは、規則文の右端と少し離して、[[注釈]]のはじめとします。
注釈は行の終わりまで続きます。これは、仕様書と並行に有用な注記を含める簡単な方法です。
>
:implied *LWS:
The grammar described by this specification is word-based. Except
where noted otherwise, linear white[INS[ ]]space [INS[{2616}]] (LWS) can be included
between any two adjacent words (token or quoted-string), and
between adjacent [DEL[tokens and delimiters (tspecials)]] [INS[[INS[{2616}]] words and separators]], without
changing the interpretation of a field. At least one delimiter
([DEL[tspecials]] [INS[[INS[{2616}]] LWS and/or separators]]) [DEL[must]] [INS[[INS[{2616}]] MUST]] exist between any two tokens [INS[[INS[{2616}]] (for the definition of "token" below)]], since they would
otherwise be interpreted as a single token. [DEL[However, applications should attempt to follow "common form" when generating HTTP constructs, since there exist some implementations that fail to accept anything beyond the common forms.
:暗黙の [CODE(ABNF)[*[[LWS]]]]:個の仕様書で記述する文法は語を基にしたものです。
別途注記の無い限り、線形空白 (LWS) を二つの隣接する語
([CODE(ABNF)[[[token]]]] や [CODE(ABNF)[[[quoted-string]]]]) の間ならびに隣接する語と分離子の間に欄の解釈を変えてしまうことなく入れることができます。
二つの字句の間には、最低一つの区切子 ([CODE(ABNF)[LWS]] [[及び/又は]]分離子)
がなければ'''なりません'''。そうでないと、一つの字句として解釈されてしまいます。[DEL[しかしながら、[[応用]]は HTTP 構造を生成する時には「共通形」に従うように試みるべきです。共通形以外のものを受け入れてくれない実装もあります。]]
[INS[
注意 : 注記のない修正箇所は、 RFC 1945 → RFC 2068
での変更点です。
]INS]
*2.2 Basic Rules
→[[HTTP//メッセージ]]
]FIG]
[FIG(ABNF)[
[18]
-rule = rule-name defined-as elements [CFWS] ;; name = definition
-defined-as = [CFWS] "=" [CFWS]
-rule-name = ALPHA *(ALPHA / DIGIT / "-") ;; 名前文字の規定なし。
-elements = alternation
-alternation = concatenation *([CFWS] "|" [CFWS] concatenation) ;; rule1 | rule2
-concatenation = repetition *([CFWS] repetition)
-repetition = [repeat] element
--;; [CODE(ABNF)[element]] が [CODE(ABNF)[char-val]] の時は、 [CODE(ABNF)[repeat "(" char-val ")"]] とするのが普通。
-element = rule-name / group / option / char-val / prose-val / csv
-repeat = number / [number] "*" [number] ;; *rule / N rule
-group = "(" alternation ")" ;; (rule1 rule2)
-option = "[" alternation "]" ;; [rule]
-char-val = <"> 1*(CHAR - <">) <"> ;; "literal"
-prose-val = "<" 1*(CHAR / FWS) ">" ;; [CODE(ABNF)[<">]] 又は自由文。
--;; [CODE(ABNF)["<" / ">"]] が文中に入ることもある。
-csv = ( [number] "#" [number] ) element ;; #rule
--;; 1#element == ([FWS] [element] *([FWS] "," [FWS] [element]))
--;; ただし element は最低1つ必要。
-number = 1*DIGIT / rule-name
--;; [CODE(ABNF)[rule-name]] は、 [CODE(ABNF)[chunk-data = chunk-size(OCTET)]] という用例がある。
-CFWS = FWS *([comment] FWS)
-comment = ";" 1*CHAR CRLF 1*WSP ;; ; comment
]FIG]
** RFC 7230
[29] [[RFC 2616]] の改訂版である [[RFC 7230]] その他では、従来の独自 [[ABNF]]
にかわって、 [[RFC 5234]] を採用しています。ただしリストを表す [CODE[#]]
記法は引き続き独自に定義しています。
[FIG(quote)[
[FIGCAPTION[
[6] [CITE@en[RFC 6455 - The WebSocket Protocol]]
([TIME[2015-03-11 20:42:50 +09:00]] 版)
<http://tools.ietf.org/html/rfc6455#section-4.3>
]FIGCAPTION]
> Some names of the rules correspond to names of the corresponding
> header fields. Such rules express values of the corresponding header
> fields, for example, the Sec-WebSocket-Key ABNF rule describes syntax
> of the |Sec-WebSocket-Key| header field value. ABNF rules with the
> "-Client" suffix in the name are only used in requests sent by the
> client to the server; ABNF rules with the "-Server" suffix in the
> name are only used in responses sent by the server to the client.
]FIG]
[42] [CITE[BNF Notation for syntax]]
([TIME[1995-02-02 05:07:04 +09:00]])
<https://www.w3.org/Notation.html>
[43] [CITE@en[Clarify the ABNF flavor in use]]
([[annevk]]著, [TIME[2017-02-14 23:34:56 +09:00]])
<https://github.com/whatwg/fetch/commit/406f86052d37f9318efe4a3c6844d04ea38d5ae3>