[1] RFC 1945 ([[HTTP/1.0]]), RFC 2068 / RFC 2616 ([[HTTP/1.1]]) で使われている [[ABNF]] です。 [[RFC 822のABNF]] を元にしていますが、選択 ([Q[or]]) は [CODE(ABNF)["/"]] ではなく [CODE(ABNF)["|"]] を使います。 [2] [[RFC 1945]], [[RFC 2068]], [[RFC 2616]] 2.1節で規定されています。 -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 [4] HTTP RFC では、 [CODE(ABNF)[*[[LWS]]]] の挿入可能箇所を構文では明記せずに、 本文で説明しています。 [3] [[RFC 2295]] (3.) は更に追加の記法を定義しています。 -element /= ssv -ssv = ( [number] "%" [number] ) element ;; %rule --;; [CODE(ABNF)[1%rule]] == [CODE(ABNF)[rule *(FWS rule)]] [[#comment]] * 仕様書から ** RFC 1945 (HTTP/1.0) 2.; RFC 2068・2616 (HTTP/1.1) 2 Notational Conventions and Generic Grammar ***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 "*element" indicating at least and at most 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[]]*[VAR[]][VAR[element]]]] で、 最低 [VAR[]] 個、最高 [VAR[]] 個の [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: "(element)" is equivalent to "*(element)"; that is, exactly occurrences of (element). Thus 2DIGIT is a 2-digit number, and 3ALPHA is a string of three alphabetic characters. 特定反復: [CODE(ABNF)[[VAR[]]([VAR[element]])]] は [CODE(ABNF)[[VAR[]]*[VAR[]]([VAR[element]])]] と同等です。 つまり、丁度 [VAR[]] 回の [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 "#element " indicating at least and at most 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[]]#[VAR[]][VAR[element]]]] で、最低 [VAR[]] 個、最高 [VAR[]] 個の [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//メッセージ]] * AtomPub の変種 [10] [[RFC 5023]] は [CODE(HTTP)@en[[[Slug]]:]] [[頭欄]]の定義に [[RFC 2616のABNF}] を使っているとしています。 ;; [CITE@en[RFC 5023 - The Atom Publishing Protocol]] ([TIME[2008-11-20 18:52:14 +09:00]] 版) [11] しかし、実際には [[RFC 4234のABNF]] にある [CODE(ABNF)[%20-7E]] という表現が混在しています。 ;; [CODE(ABNF)[[[|]]]] を使っているので、 [[RFC 4234のABNF]] ではありません。 * メモ