#pattern
* Parsing HTML documents
#ja
$1 HTML 文書の構文解析
#en
This section only applies to user agents, data mining tools, and
conformance checkers.
#ja
この節は利用者エージェント、データ・マイニング・ツール、
適合性検査器のみに適用されます。
#en
The rules for parsing XML documents (and
thus XHTML documents) into DOM trees are covered by
the XML and Namespaces in XML specifications, and are out of scope of this
specification. [XML] [XMLNS]
#ja
XML 文書 (や XHTML 文書)
を構文解析して DOM 木を得るための規則は XML や XML 名前空間の仕様書で扱われており、
この仕様書の適用範囲外です。 [XML] HTML documents, user agents must use the
parsing rules described in this section to generate the DOM trees.
Together, these rules define what is referred to as the HTML parser.
#ja
HTML 文書については、利用者エージェントは、 DOM
木を生成するためにこの節で説明する構文解析規則を使用しなければ[[MUST:なりません]]。
また、この規則はHTML 構文解析器と呼ばれるものを定義します。
#en
While the HTML form of HTML5 bears a close resemblance to SGML and XML,
it is a separate language with its own parsing rules.
#ja
HTML5 の HTML 形式は SGML や XML によく似ていますが、
独自の構文解析規則を持つ別の言語です。
#en
Some earlier versions of HTML (in particular from HTML2 to HTML4) were
based on SGML and used SGML parsing rules. However, few (if any) web
browsers ever implemented true SGML parsing for HTML documents; the only
user agents to strictly handle HTML as an SGML application have
historically been validators. The resulting confusion — with
validators claiming documents to have one representation while widely
deployed Web browsers interoperably implemented a different
representation — has wasted decades of productivity. This version
of HTML thus returns to a non-SGML basis.
#ja
以前のいくつかの版の HTML (特に HTML2 から HTML4 まで) は SGML
に基づき、 SGML の構文解析規則を用いていました。しかし、 HTML
文書用に真の SGML 構文解析を実装していたウェブ・ブラウザは (あったとしても)
皆無に近い数でした。 HTML を厳密に SGML 応用として扱う唯一の利用者エージェントは歴史的に妥当性検証器だけでした。
その結果、妥当性検査器は文書がある形式であることを要求し、
一方で広く実用されている Web ブラウザはそれとは異なる形式を相互運用可能な形で実装するという混乱が生じ、
生産性を大きく低下させています。
ですので、この版の HTML は非 SGML ベースに回帰します。
#en
Authors interested in using SGML tools in their authoring pipeline are
encouraged to use XML tools and the XML serialization of HTML5.
#ja
文書準備の過程で SGML ツールを使いたいと考える著者には、
XML ツールと HTML5 の XML 直列化を用いることをお勧めします。
#en
This specification defines the parsing rules for HTML documents, whether
they are syntactically correct or not. Certain points in the parsing
algorithm are said to be parse
errors. The error handling for parse errors is well-defined: user
agents must either act as described below when encountering such problems,
or must abort processing at the first error that they encounter for which
they do not wish to apply the rules described below.
#ja
この仕様書は、構文的に正しいか否かに関わらず HTML
文書を構文解析する規則を定義します。構文解析算法中のいくつかの箇所は構文解析誤りであるとしています。
構文解析誤りの処理は明確に定義します。利用者エージェントは、
そのような問題に遭遇したときに後述のように動作するか、または後述の規則を適用することを望まないような誤りにはじめて遭遇した箇所で処理を停止しなければ[[MUST:なりません]]。
#en
Conformance checkers must report at least one parse error condition to
the user if one or more parse error conditions exist in the document and
must not report parse error conditions if none exist in the document.
Conformance checkers may report more than one parse error condition if
more than one parse error conditions exist in the document. Conformance
checkers are not required to recover from parse errors.
#ja
適合性検査器は、文書中に1つ以上の構文解析誤り条件が存在する場合、利用者に最低1つの構文解析誤り条件を報告しなければ[[MUST:ならず]]、
文書に誤りが存在しない場合、構文解析誤り条件を報告しては[[MUST NOT:なりません]]。
適合性検査器は、文書中に複数の構文解析誤り条件が存在する場合、
複数の構文解析誤り条件を報告して[[MAY:構いません]]。
適合性検査器は構文解析誤りから回復することを[[REQUIRED:要求]]されません。
#en
Parse errors are only errors with the syntax of
HTML. In addition to checking for parse errors, conformance checkers will
also verify that the document obeys all the other conformance requirements
described in this specification.
#ja
構文解析誤りは、 HTML の構文の誤りに過ぎません。
適合性検査器は、構文解析誤りの検査に加え、
文書がこの仕様書で説明されている他の適合性要件に従っているかも検査することになります。
#pattern
* The scripting state
#ja
$1 スクリプティング状態
#en
The scripting flag is set to "enabled" if the
Document with which the parser is associated was with script when the parser was created, and
"disabled" otherwise.
#ja
スクリプティング旗は、構文解析器が関連付けられている
Document が構文解析器の作成の時点でスクリプト付きである場合には「有効」、
それ以外の場合には「無効」です。
#pattern
* Tokenization
#ja
$1 字句化
#en
Implementations must act as if they used the following state machine to
tokenise HTML. The state machine must start in the data state. Most states consume a single character,
which may have various side-effects, and either switches the state machine
to a new state to reconsume the same character, or switches it to
a new state (to consume the next character), or repeats the same state (to
consume the next character). Some states have more complicated behavior
and can consume several characters before switching to another state.
#ja
実装は、次の状態機械を HTML の字句化に用いているかのように作用しなければ[[MUST:なりません]]。
状態機械は、データ状態で開始しなければ[[MUST:なりません]]。
ほとんどの状態は1文字消費しますが、
この時様々な副作用を持っても[[MAY:構わない]]他、
状態機械が新しい状態に切り替えられて同じ文字を再消費するか、
(次の文字を消費するために) 新しい状態に切り替えられるか、
(次の文字を消費するために) 同じ状態を繰り返すかのいずれかとなります。
より複雑な動作を持っていて、他の状態に切り替える前に複数の文字を消費することがある状態もあります。
#en
The exact behavior of certain states depends on a content model flag that is set after certain tokens are
emitted. The flag has several states: PCDATA, RCDATA, CDATA, and PLAINTEXT. Initially it must be in the PCDATA state. In the
RCDATA and CDATA states, a further escape flag is
used to control the behavior of the tokeniser. It is either true or false,
and initially must be set to the false state. The insertion
mode and the stack of open elements also
affects tokenization.
#ja
特定の状態の正確な動作は、特定の字句が放出された後に設定される内容モデル旗に依存します。
この旗は状態 PCDATA, RCDATA, CDATA, PLAINTEXT を持ちます。はじめは PCDATA
状態でなければ[[MUST:なりません]]。 RCDATA 状態と CDATA 状態では、
更に逃避旗が字句化器の動作を制御するために用いられます。
これは真か偽かのいずれかであり、はじめは偽の状態に設定されなければ[[MUST:なりません]]。
挿入モードと開いているようそのスタックも字句化器に影響します。
#en
The output of the tokenization step is a series of zero or more of the
following tokens: DOCTYPE, start tag, end tag, comment, character,
end-of-file. DOCTYPE tokens have a name, a public identifier, a system
identifier, and a force-quirks flag. When a DOCTYPE token is
created, its name, public identifier, and system identifier must be marked
as missing (which is a distinct state from the empty string), and the
force-quirks flag must be set to off (its other state is
on). Start and end tag tokens have a tag name, a self-closing
flag, and a list of attributes, each of which has a name and a value.
When a start or end tag token is created, its self-closing flag
must be unset (its other state is that it be set), and its attributes list
must be empty. Comment and character tokens have data.
#ja
字句化期の出力は、 DOCTYPE、開始タグ、終了タグ、注釈、文字、ファイル末のいずれかの字句の零個以上の系列です。
DOCTYPE 字句は名前、公開識別子、システム識別子、奇癖強制旗を持ちます。
When a DOCTYPE token is
created, its name, public identifier, and system identifier must be marked
as missing (which is a distinct state from the empty string), and the
force-quirks flag must be set to off (its other state is
on). Start and end tag tokens have a tag name, a self-closing
flag, and a list of attributes, each of which has a name and a value.
When a start or end tag token is created, its self-closing flag
must be unset (its other state is that it be set), and its attributes list
must be empty. Comment and character tokens have data.
#pattern
* Parse state
#ja
$1 構文解析状態
#pattern
* The insertion mode
#ja
$1 挿入モード
#en
Initially the insertion mode is "initial". It can change to "before html", "before head", "in head", "in head
noscript", "after
head", "in
body", "in
table", "in
caption", "in column group", "in table body", "in row", "in cell", "in select", "in select in table", "in foreign content", "after body", "in frameset",
"after
frameset", "after after body", and "after after frameset" during the course of the
parsing, as described in the tree
construction stage. The insertion mode affects how tokens are
processed and whether CDATA blocks are supported.
#ja
はじめ、挿入モードは "initial" です。挿入モードは、
構文解析の過程で、木構築期で説明するように、
"before html", "before head", "in head", "in head
noscript", "after
head", "in
body", "in
table", "in
caption", "in column group", "in table body", "in row", "in cell", "in select", "in select in table", "in foreign content", "after body", "in frameset",
"after
frameset", "after after body", "after after frameset"
に変わることができます。挿入モードは、字句がどう処理されるか、 CDATA
ブロックに対応するかどうかに影響します。
#en
Seven of these modes, namely "in head", "in body", "in table", "in table body", "in row", "in cell", and "in select", are special, in that the other modes defer to them
at various times. When the algorithm below says that the user agent is to
do something "using the rules for the m insertion mode", where m is one of
these modes, the user agent must use the rules described under that
insertion mode's section, but must leave the insertion
mode unchanged (unless the rules in that section themselves switch
the insertion mode).
#ja
挿入モードのうちの7つ、"in head", "in body", "in table", "in table body", "in row", "in cell", "in select" は特別で、他のモードが数箇所でこれらのモードに委ねています。
後述の算法が利用者エージェントは何かを「m 挿入モードの規則を用いて」
(m はこれらのモードのいずれか。) 行うと言っている時は、
利用者エージェントは、当該挿入モードの節で説明されている規則を用いなければ[[MUST:なりません]]が、
挿入モードは変更しないでおかなければ[[MUST:なりません]] (その節の規則自体が挿入モードを切り替える場合を除きます)。
#en
When the insertion mode is switched to "in foreign content", the
secondary insertion mode is also set. This
secondary mode is used within the rules for the "in foreign content" mode to
handle HTML (i.e. not foreign) content.
#ja
挿入モードが "in foreign content"
に切り替えられる時には、二次挿入モードも設定されます。
この二次モードは、 "in foreign content"
モードの規則の中で HTML (つまり、異言語でない) 内容を取り扱う際に使用します。
#en
When the steps below require the UA to reset the insertion
mode appropriately, it means the UA must follow these steps:
#ja
後述の段階が利用者エージェントに挿入モードを適切に再設定することを要求する場合、
利用者エージェントは次の段階に従わなければ[[MUST:ならない]]ことを意味しています。
#pattern
Let * be false.
#ja
$1 を偽とします。
#en
Let node be the last node in the stack of open elements.
#ja
node を開いている要素のスタックの最後の節点とします。
#en
If node is the first node in the stack of open
elements, then set last to true and set node to the context element. (fragment case)
#ja
node が開いている要素のスタックの最初の節点の場合、
last を真に設定し、 node を context 要素に設定します。
(素片の場合)
#pattern
If node is a * element, then
switch the insertion mode to "*" and abort these steps.
(fragment case)
#ja
node が $1 要素の場合、挿入モードを "$2" に切り替え、
これらの段階を停止します。
(素片の場合)
#pattern
If node is a * element, then
switch the insertion mode to "*" and abort these steps.
#ja
node が $1
要素の場合、挿入モードを "$2" に切り替え、
これらの段階を停止します。
#en
If node is a td or
th element and last is
false, then switch the insertion mode to "in cell" and abort these steps.
#ja
node が td 要素か
th 要素の場合で last
が偽の場合、挿入モードを "in cell" に切り替え、これらの段階を停止します。
#en
If node is an element from the MathML
namespace, then switch
the insertion mode to "in foreign content", let
the secondary insertion mode be "in body", and abort
these steps.
#ja
node が MathML
名前空間の要素の場合、挿入モードを "in foreign content"
に切り替え、二次挿入モードを "in body"
とし、これらの段階を停止します。
#en
If node is a head
element, then switch the insertion mode to "in body" ("in body"! not
"in head"!)
and abort these steps. (fragment case)
#ja
node が head
要素の場合、挿入モードを "in body" ("in body"! "in head"
ではなく!) に切り替え、これらの段階を停止します。
(素片の場合)
#en
If node is an html element, then: if the head element pointer is
null, switch the insertion mode to "before head", otherwise, switch
the insertion mode to "after head". In either case, abort these steps. (fragment case)
#ja
node が html 要素の場合: head 要素指示子が null
である場合には、挿入モードを "before head"
に切り替えます。そうでない場合には、挿入モードを "after head" に切り替えます。いずれの場合にも、
これらの段階を停止します。 (素片の場合)
#en
If last is true, then switch the insertion
mode to "in
body" and abort these steps. (fragment case)
#ja
last が真であれば、挿入モードを
"in
body" に切り替え、これらの段階を停止します。
(素片の場合)
#en
Let node now be the node before node in the stack of open elements.
#ja
新たな node を開いている要素のスタックで node の前にある節点とします。
#pattern
A sequence of bytes starting with: *
#ja
$1 で始まるバイト列
#en
Any other byte
#ja
その他のバイト
#en
Consume the next input character:
#ja
次入力文字を消費:
#en
A comment token
#ja
注釈字句
#en
A DOCTYPE token
#ja
DOCTYPE 字句
#pattern
A start tag whose tag name is "*"
#ja
タグ名が "$1" の開始タグ
#pattern
A start tag whose tag name is one of: *
#ja
タグ名が $1 のいずれかの開始タグ
#pattern
An end tag whose tag name is "*"
#ja
タグ名が "$1" の終了タグ
#pattern
An end tag whose tag name is one of: *
#ja
タグ名が $1 のいずれかの終了タグ
#en
Any other start tag
#ja
その他の開始タグ
#en
Any other end tag
#ja
その他の終了タグ
#en
Anything else
#ja
その他のもの
#en
Run the following algorithm:
#ja
次の算法を実行します:
#en
Otherwise:
#ja
それ以外の場合:
#pattern
Return to step *.
#ja
手順 $1 に戻ります。
#pattern
Act as if a start tag token with the tag name "*" had been seen,
then reprocess the current token.
#ja
タグ名が "$1" の開始タグ字句を見たかのように動作してから、
現在字句を再処理します。
#en
Parse error.
#ja
構文解析誤り。
#en
Parse error. Ignore the token.
#ja
構文解析誤り。字句を無視します。
#en
Take a deep breath, then act as described in the "any other end tag"
entry below.
#ja
深呼吸をして、後述の「その他の終了タグ」の項で説明されているように作用します。
#en
If the list of active formatting elements
contains an element whose tag name is "a" between the end of the list
and the last marker on the list (or the start of the list if there is no
marker on the list), then this is a parse error;
act as if an end tag with the tag name "a" had been seen, then remove
that element from the list of active formatting
elements and the stack of open elements if the
end tag didn't already remove it (it might not have if the element is
not in table
scope).
#ja
活性書式付け要素のリストがタグ名 "a"
の要素をリストの終わりとリスト中のリスト・マーカー (またはリスト中にマーカーがない場合はリストのはじめ)
の間に含まれている場合には、
これは構文解析誤りです。
タグ名 "a" の終了タグを見たかのように作用した後に、
その要素を活性書式付け要素のリストと開いている要素のスタック
(終了タグにより除去されていない場合。要素が表範囲中にない場合には除去されていないかもしれません。) から除去します。
#en
In the non-conforming stream
<a href=a>a<table><a href=b>b</table>x,
the first a element would be closed upon
seeing the second one, and the "x" character would be inside a link to
"b", not to "a". This is despite the fact that the outer a element is not in table scope (meaning that a
regular </a> end tag at the start of the table wouldn't
close the outer a element).
#ja
不適合ストリーム
<a href=a>a<table><a href=b>b</table>x
において、最初の a 要素は2つ目のを見たときに閉じられ、
「x」文字は「a」へのリンクではなく、「b」へのリンクの内側に入ります。
これは、外側の a 要素が表範囲中にないためです
(つまり、表の最初に普通の </a> 終了タグがあったとしても、
外側の a 要素を閉じないということになります)。
#en
Reconstruct the active formatting elements,
if any.
#ja
活性書式付け要素を再構築できれば、します。
#en
Insert an HTML element for the token. Add that
element to the list of active formatting
elements.
#ja
当該字句について HTML 要素を挿入します。
その要素を活性書式付け要素のリストに追加します。
#en
The behavior further depends on the character after the U+0023 NUMBER
SIGN:
#ja
動作は更に U+0023 NUMBER
SIGN の次の文字によって決まります。
#en
Consume the U+0023 NUMBER SIGN.
#ja
U+0023 NUMBER SIGN を消費します。
#en
Consume the X.
#ja
X を消費します。
#en
Follow the steps below, but using the range of characters U+0030
DIGIT ZERO through to U+0039 DIGIT NINE, U+0061 LATIN SMALL LETTER A
through to U+0066 LATIN SMALL LETTER F, and U+0041 LATIN CAPITAL
LETTER A, through to U+0046 LATIN CAPITAL LETTER F (in other words,
0-9, A-F, a-f).
#ja
次の段階に従いますが、文字の範囲 U+0030
DIGIT ZERO ~ U+0039 DIGIT NINE、U+0061 LATIN SMALL LETTER A
~ U+0066 LATIN SMALL LETTER F、 U+0041 LATIN CAPITAL
LETTER A ~ U+0046 LATIN CAPITAL LETTER F (つまり
0-9、A-F、a-f) を使います。
#en
When it comes to interpreting the number, interpret it as a
hexadecimal number.
#ja
数を解釈する折には、十六進数として解釈します。
#en
Follow the steps below, but using the range of characters U+0030
DIGIT ZERO through to U+0039 DIGIT NINE (i.e. just 0-9).
#ja
次の段階に従いますが、文字の範囲 U+0030
DIGIT ZERO ~ U+0039 DIGIT NINE (つまり 0-9 だけ) を使います。
#en
When it comes to interpreting the number, interpret it as a decimal
number.
#ja
数を解釈する折には、十進数として解釈します。
#en
Consume as many characters as match the range of characters given
above.
#ja
前述の文字の範囲に一致する文字を、一致するだけすべて消費します。
#en
If no characters match the range, then don't consume any characters
(and unconsume the U+0023 NUMBER SIGN character and, if appropriate, the
X character). This is a parse error; nothing is
returned.
#ja
範囲に一致する文字がない場合は、文字を消費しません
(更に、 U+0023 NUMBER SIGN 文字と、必要であれば X 文字をも消費しなかったこととします)。
これは構文解析誤りです。何も返しません。
#en
Otherwise, if the next character is a U+003B SEMICOLON, consume that
too. If it isn't, there is a parse error.
#ja
そうでない場合、次の文字が U+003B SEMICOLON
であれば、これも消費します。そうでない場合は、構文解析誤りです。
#en
If one or more characters match the range, then take them all and
interpret the string of characters as a number (either hexadecimal or
decimal as appropriate).
#ja
1文字以上が一致した場合は、それらすべてによる文字列を数 (十六進数または十進数の適切な方)
として解釈します。
#en
If that number is one of the numbers in the first column of the
following table, then this is a parse error. Find
the row with that number in the first column, and return a character
token for the Unicode character given in the second column of that row.
#ja
その数が次の表の最初の列の数のいずれかである場合は、
構文解析誤りです。
その数が最初の列に現れる行を探し、
その行の2つ目の列に示された Unicode 文字の文字字句を返します。
#en
Number
#ja
数
#en
Unicode character
#ja
Unicode 文字
#en
Otherwise, if the number is in the range 0x0000 to 0x0008,
0x000E to 0x001F, 0x007F
to 0x009F, 0xD800 to
0xDFFF , 0xFDD0 to 0xFDDF, or is one of
0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF, 0x2FFFE, 0x2FFFF, 0x3FFFE, 0x3FFFF,
0x4FFFE, 0x4FFFF, 0x5FFFE, 0x5FFFF, 0x6FFFE, 0x6FFFF, 0x7FFFE, 0x7FFFF,
0x8FFFE, 0x8FFFF, 0x9FFFE, 0x9FFFF, 0xAFFFE, 0xAFFFF, 0xBFFFE, 0xBFFFF,
0xCFFFE, 0xCFFFF, 0xDFFFE, 0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE, 0xFFFFF,
0x10FFFE, or 0x10FFFF, or is higher than 0x10FFFF, then this is a parse error; return a character token for the U+FFFD
REPLACEMENT CHARACTER character instead.
#ja
それ以外の場合、数が範囲 0x0000 ~ 0x0008、
0x000E、 0x001F、 0x007F
~ 0x009F、
0xD800 ~
0xDFFF 、0xFDD0 ~ 0xFDDF
のいずれかにあるか、
0xFFFE、0xFFFF、0x1FFFE、0x1FFFF、0x2FFFE、0x2FFFF、0x3FFFE、0x3FFFF、
0x4FFFE、0x4FFFF、0x5FFFE、0x5FFFF、0x6FFFE、0x6FFFF、 0x7FFFE、0x7FFFF、
0x8FFFE、0x8FFFF、0x9FFFE、0x9FFFF、0xAFFFE、0xAFFFF、0xBFFFE、0xBFFFF、
0xCFFFE、0xCFFFF、0xDFFFE、0xDFFFF、0xEFFFE、0xEFFFF、0xFFFFE、0xFFFFF、
0x10FFFE、0x10FFFF のいずれかであるか、
0x10FFFF より大きい場合、構文解析誤りです。
代わりに U+FFFD
REPLACEMENT CHARACTER 文字の文字字句を返します。
#en
Otherwise, return a character token for the Unicode character whose
code point is that number.
#ja
それ以外の場合、符号位置がその数である Unicode 文字の文字字句を返します。
#en
Consume the maximum number of characters possible, with the consumed
characters matching one of the identifiers in the first column of the named character references table (in a case-sensitive manner).
#ja
名前付き文字参照の表の最初の列にある識別子のいずれかと一致するような、
可能な最大数の文字を消費します。
#en
Insert an HTML element for the token.
#ja
当該字句について HTML
要素を挿入します。
#en
Set the head element
pointer to the newly created head
element.
#ja
head
要素指示子を新たに作られた head
要素に設定します。
#en
Switch the insertion mode to "in head".
#ja
挿入モードを "in head" に切り替えます。
#en
Act as if a start tag token with the tag name "head" and no attributes
had been seen, then reprocess the current token.
#ja
タグ名 "head" で属性のない開始タグ字句を見たかのように作用した後、
現在の字句を再処理します。
#en
This will result in an empty head element being generated, with the current
token being reprocessed in the "after head" insertion mode.
#ja
この結果空の head 要素が生成され、
現在の字句は "after head" 挿入モードで再処理されることとなります。
#pattern
* The "*" insertion mode
#ja
$1 "$4" 挿入モード
#pattern
When the insertion mode is "*", tokens must be handled as
follows:
#ja
挿入モードが "$3" の時、
字句は次のように取り扱わなければ[[MUST:なりません]]。
#en
Insert the character
into the current node.
#ja
現在節点に文字を挿入します。
#pattern
* Overview of the parsing model
#ja
$1 構文解析モデルの概要
#en
The input to the HTML parsing process consists of a stream of
Unicode characters, which is passed through a
tokenization stage (lexical analysis) followed by a
tree construction stage (semantic analysis). The output
is a Document object.
#ja
HTML 構文解析処理への入力は、Unicode 文字の列によって構成され、
まずは字句化段階 (字句解析)
に渡され、その後に木構築 段階 (意味解析)
に渡されます。
出力は、 Document オブジェクトです。
#en
Implementations that do not
support scripting do not have to actually create a DOM
Document object, but the DOM tree in such cases is
still used as the model for the rest of the specification.
#ja
スクリプティングに対応しない実装は実際に DOM
Document オブジェクトを作る必要はありませんが、
その場合であっても、この仕様書の残りの部分のモデルとしてはやはり DOM 木を使います。
#en
In the common case, the data handled by the tokenization stage
comes from the network, but it can also come from script, e.g. using the document.write() API.
#ja
多くの場合は字句化段階が取り扱うデータはネットワークから来るものですが、
スクリプトからも、例えば document.write() API
によって来ることがあります。
#en
#ja
#en
There is only one set of state for the
tokeniser stage and the tree construction stage, but the tree
construction stage is reentrant, meaning that while the tree
construction stage is handling one token, the tokeniser might be
resumed, causing further tokens to be emitted and processed before
the first token's processing is complete.
#ja
字句化器段階と木構築段階の状態は一揃いしかありませんが、
木構築段階は再入可能であり、木構築段階がある字句を処理している間に字句化器が再開して更に字句を放出し、
最初の字句の処理が完了する前に新しい字句が処理されることがあります。
#en
In the following example, the tree construction stage will be
called upon to handle a "p" start tag token while handling the
"script" start tag token:
#ja
次の例では、 "script" 開始タグ字句を処理している間に木構築段階が "p" 開始タグ字句を処理するために呼び出されることとなります。
#pattern
* The input stream
#ja
$1 入力ストリーム
#en
The stream of Unicode characters that consists the input to the
tokenization stage will be initially seen by the user agent as a
stream of bytes (typically coming over the network or from the local
file system). The bytes encode the actual characters according to a
particular character encoding, which the user agent must
use to decode the bytes into characters.
#ja
字句か段階への入力を構成する Unicode 文字のストリームは、はじめ利用者エージェントに
(普通はネットワークか局所ファイル・システムから来た) バイトのストリームとして見えます。
バイトは特定の文字符号化に従って実際の文字を符号化しており、
利用者エージェントはその文字符号化を使ってバイトを文字に復号しなければ[[MUST:なりません]]。
#en
For XML documents, the algorithm user agents must
use to determine the character encoding is given by the XML
specification. This section does not apply to XML documents. [XML]
#ja
XML 文書に関しては、文字符号化を決定するために利用者エージェントが使わなければ[[MUST:ならない]]算法は
XML 仕様書で与えられています。この節は XML 文書には適用しません。 [XML]
#pattern
* Determining the character encoding
#ja
$1 文字符号化の決定
#en
In some cases, it might be impractical to unambiguously determine
the encoding before parsing the document. Because of this, this
specification provides for a two-pass mechanism with an optional
pre-scan. Implementations are allowed, as described below, to apply
a simplified parsing algorithm to whatever bytes they have available
before beginning to parse the document. Then, the real parser is
started, using a tentative encoding derived from this pre-parse and
other out-of-band metadata. If, while the document is being loaded,
the user agent discovers an encoding declaration that conflicts with
this information, then the parser can get reinvoked to perform a
parse of the document with the real encoding.
#ja
場合によっては、文書の構文解析の前に符号化を曖昧なく決定することが非現実的かもしれません。
このため、この仕様書は任意選択の前走査を伴う2パス機構を提供します。
実装は、後述の通り、文書の構文解析を始める前に、利用可能になっているバイトに対して単純化した構文解析算法を適用することが認められています。
その後、実際の構文解析器が、この前構文解析やその他の外部メタデータによって得られた暫定符号化を用いて開始します。
文書が読み込まれる間に利用者エージェントがその情報と矛盾する符号化宣言を発見した場合、
構文解析器は、実際の符号化によって文書の構文解析を行うために再呼び出しされることがあります。