发信人: kenmlee()
整理人: kenmlee(2000-07-08 16:48:47), 站内信件
|
2 Notational Conventions and Generic Grammar
#2 符号转换和一般语法/#
2.1 Augmented BNF
2.1 扩展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 [9]. Implementers will need to be familiar with the
notation in order to understand this specification. The augmented B
NF
includes the following constructs:
#本文所描述的所有机制均采用文字描述和类似于RFC 822[9]的
扩展巴卡斯范式(augmented Backus-Naur Form - BNF).实现
者需要熟悉这些符号以便理解本文的说明.扩展BNF包括下列结构:/#
name = definition
The name of a rule is simply the name itself (without any enclosi
ng
"<" and ">") and is separated from its definition by the equal "=
"
character. Whitespace is only significant in that indentation of
continuation lines is used to indicate a rule definition that spa
ns
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.
#名称=定义
规则的名字就是简单的名称本身(不包括任何在"<"和">"之间
的内容),并用"="号与其定义分开.当规则定义跨越多于一行时
空格仅用于连续行的缩排.某些基本规则使用大写字符,如SP,
LWS,HT,CRLF,DIGIT,ALPHA等.尖括号用于在定义中使用规则
名时能方便的辨识./#
"literal"
Quotation marks surround literal text. Unless stated otherwise, t
he
text is case-insensitive.
#"文字"
引号包含的文字文本,除非特别声明文本是大小写敏感的./#
rule1 | rule2
Elements separated by a bar ("|") are alternatives, e.g., "yes |
no" will accept yes or no.
#规则1 | 规则2
用("|")分割的元素是可互代替的,例如:"yes | no"将接受yes或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".
#(规则1 规则2)
括号中的元素作为一个单独的元素使用.因此"(elem (foo | bar) elem)"可
以
是"elem foo elem"和"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.
#*规则
元素前的*号代表重复,完整形式是"<n>*<m>元素",指元素最少出现<n>次,
最多出现<m>次.缺省值是零和无限,因此"*(元素)"允许元素出现任何次,
包括0次,"1*元素"要求至少一次,"1*2元素"允许一次或两次./#
[rule]
Square brackets enclose optional elements; "[foo bar]" is
equivalent to "*1(foo bar)".
#[规则]
方括号中是可选元素,"[foo bar]"等于"*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.
#N 规则
特殊的重复标志:"<n>(元素)"等于"<n>*<n>(元素)",指元素必须出现<n>次
.
因此2DIGIT是两个数字,3ALPHA是三个字母./#
#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 comma
s
(",") and optional linear whitespace (LWS). This makes the usual
form of lists very easy; a rule such as "( *LWS element *( *LWS "
,"
*LWS element )) " can be shown as "1#element". Wherever this
construct is used, null elements are allowed, but do not contribu
te
to the count of elements present. That is, "(element), , (elemen
t)
" is permitted, but counts as only two elements. Therefore, where
at least one element is required, at least one non-null element
must be present. Default values are 0 and infinity so that
"#element" allows any number, including zero; "1#element" require
s
at least one; and "1#2element" allows one or two.
##规则
#号与*号类似,用于定义元素列表.完整的形式是"<n>#<m>元素",指出最少有
<n>个
最多<m>个元素,每个元素被逗号","和可选的空白(LWS linear whitespace
)分隔.
这使一般的列表变得简单了,例如:"( *LWS 元素 *(*LWS "," *LWS 元素 )
)"可以
表示为"1#元素".无论在那里空元素都是允许的,但不计入元素数量中,也就
是说
"(元素), , (元素)"是允许的,但元素数量只是两个.因此,在至少一个元素
的情况下
也就至少有一个非空元素.缺省值是零和无限,因此"#元素"允许任意数量包
括零,
"1#元素"要求至少一个,"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 whitespace (LWS) can be included
between any two adjacent words (token or quoted-string), and
between adjacent tokens and delimiters (tspecials), without
changing the interpretation of a field. At least one delimiter
(tspecials) must exist between any two tokens, since they would
otherwise be interpreted as a single token.
#隐式 *LWS
本语法描述的内容是基于单词的,除非特别声明,空白(LWS)可以出现在任意
两个
相邻的单词(标示或引用串)间,也可以出现在相邻的标示和定界符(tspecia
ls)
之间,而不改变其意义.两个标示间至少要有一个定界符,否则他们将被解释
为一
个单个的标示./#
2.2 Basic Rules
#2.2 基本规则/#
The following rules are used throughout this specification to
describe basic parsing constructs. The US-ASCII coded character set
is defined by ANSI X3.4-1986 [21].
#以下规则在本文中用于描述基本的解析结构.US-ASCII编码字符集由
ANSI X3.4-1986 [21]定义./#
OCTET = <any 8-bit sequence of data>
CHAR = <any US-ASCII character (octets 0 - 127)>
UPALPHA = <any US-ASCII uppercase letter "A".."Z">
LOALPHA = <any US-ASCII lowercase letter "a".."z">
ALPHA = UPALPHA | LOALPHA
DIGIT = <any US-ASCII digit "0".."9">
CTL = <any US-ASCII control character
(octets 0 - 31) and DEL (127)>
CR = <US-ASCII CR, carriage return (13)>
LF = <US-ASCII LF, linefeed (10)>
SP = <US-ASCII SP, space (32)>
HT = <US-ASCII HT, horizontal-tab (9)>
<"> = <US-ASCII double-quote mark (34)>
# OCTET = <任何8比特序列数据>
CHAR = <任何 US-ASCII 字符 (八进制 0 - 127)>
UPALPHA = <任何 US-ASCII 大写字母 "A".."Z">
LOALPHA = <任何 US-ASCII 小写字母 "a".."z">
ALPHA = UPALPHA | LOALPHA
DIGIT = <任何 US-ASCII 数字 "0".."9">
CTL = <任何 US-ASCII 控制字符 (八进制 0 - 31) 和
DEL (127)>
CR = <US-ASCII CR, 回车 (13)>
LF = <US-ASCII LF, 换行 (10)>
SP = <US-ASCII SP, 空格 (32)>
HT = <US-ASCII HT, 制表符 (9)>
<"> = <US-ASCII 双引号 (34)>
/#
HTTP/1.1 defines the sequence CR LF as the end-of-line marker for a
ll
protocol elements except the entity-body (see appendix 19.3 for
tolerant applications). The end-of-line marker within an entity-bod
y
is defined by its associated media type, as described in section 3.
7.
CRLF = CR LF
# HTTP/1.1定义CR LF序列为所有协议元素的行结束标志,除了实体体部分.(看附
录19.3
关于应用容错).实体体的行结束标志有它相关的媒体类型定义,见3.7部分.
CRLF = CR LF
/#
HTTP/1.1 headers can be folded onto multiple lines if the
continuation line begins with a space or horizontal tab. All linear
white space, including folding, has the same semantics as SP.
LWS = [CRLF] 1*( SP | HT )
# HTTP/1.1头部可以折成多行,但下行行首必须由空格或制表符开头.空白包括折
行与
SP语法上相同.
LWS = [CRLF] 1*( SP | HT )
/#
The TEXT rule is only used for descriptive field contents and value
s
that are not intended to be interpreted by the message parser. Word
s
of *TEXT may contain characters from character sets other than ISO
8859-1 [22] only when encoded according to the rules of RFC 1522
[14].
TEXT = <any OCTET except CTLs,
but including LWS>
# TEXT规则仅用于描述域内容和不被消息解析所解释的值.当依据RFC 1522[14]
编码时,
*TEXT中的单词可以包含ISO 8859-1[22]以外的字符.
TEXT = <any OCTET except CTLs,
but including LWS>
/#
Hexadecimal numeric characters are used in several protocol element
s.
HEX = "A" | "B" | "C" | "D" | "E" | "F"
| "a" | "b" | "c" | "d" | "e" | "f" | DIGIT
# 几个协议元素用到了十六进制数字字符.
HEX = "A" | "B" | "C" | "D" | "E" | "F"
| "a" | "b" | "c" | "d" | "e" | "f" | DIGIT
/#
Many HTTP/1.1 header field values consist of words separated by LWS
or special characters. These special characters MUST be in a quoted
string to be used within a parameter value.
token = 1*<any CHAR except CTLs or tspecials>
tspecials = "(" | ")" | "<" | ">" | "@"
| "," | ";" | ":" | "\" | <">
| "/" | "[" | "]" | "?" | "="
| "{" | "}" | SP | HT
# 一些HTTP/1.1头域的值由被LWS或特殊字符分割的单词组成,这些特殊的字符在
参数值
中使用时必须被放在引用字符串中.
token = 1*<任意 CHAR 除 CTLs 或 tspecials 以外>
tspecials = "(" | ")" | "<" | ">" | "@"
| "," | ";" | ":" | "\" | <">
| "/" | "[" | "]" | "?" | "="
| "{" | "}" | SP | HT
/#
Comments can be included in some HTTP header fields by surrounding
the comment text with parentheses. Comments are only allowed in
fields containing "comment" as part of their field value definition
.
In all other fields, parentheses are considered part of the field
value.
comment = "(" *( ctext | comment ) ")"
ctext = <any TEXT excluding "(" and ")">
# 括号中的文本可以放在一些HTTP头域中作为注释,只有该域的定义中注释可以
做为域值
的一部分时才允许使用注释.其它域中的括号被认为是域值的一部分.
comment = "(" *( ctext | comment ) ")"
ctext = <任何 TEXT 除了 "(" 和 ")">
/#
A string of text is parsed as a single word if it is quoted using
double-quote marks.
quoted-string = ( <"> *(qdtext) <"> )
qdtext = <any TEXT except <">>
# 如果一串文本被双引号引起,将被解析为一个单个的词.
quoted-string = ( <"> *(qdtext) <"> )
qdtext = <any TEXT except <">>
/#
The backslash character ("\") may be used as a single-character quo
ting
mechanism only within quoted-string and comment constructs.
quoted-pair = "\" CHAR
# 反斜杠("\")用于单个字符的引用机制,但只用于引起的字符串和注释中.
quoted-pair = "\" CHAR
/#
-- ※ 修改:.kenmlee 于 Jul 8 16:18:36 修改本文.[FROM: 61.140.188.222] ※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 61.140.188.222]
|
|