1 |
wakaba |
1.2 |
package Whatpm::HTML; |
2 |
wakaba |
1.1 |
use strict; |
3 |
wakaba |
1.115 |
our $VERSION=do{my @r=(q$Revision: 1.114 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
4 |
wakaba |
1.63 |
use Error qw(:try); |
5 |
wakaba |
1.1 |
|
6 |
wakaba |
1.18 |
## ISSUE: |
7 |
|
|
## var doc = implementation.createDocument (null, null, null); |
8 |
|
|
## doc.write (''); |
9 |
|
|
## alert (doc.compatMode); |
10 |
wakaba |
1.1 |
|
11 |
wakaba |
1.70 |
## TODO: Control charcters and noncharacters are not allowed (HTML5 revision 1263) |
12 |
|
|
## TODO: 1252 parse error (revision 1264) |
13 |
|
|
## TODO: 8859-11 = 874 (revision 1271) |
14 |
|
|
|
15 |
wakaba |
1.1 |
my $permitted_slash_tag_name = { |
16 |
|
|
base => 1, |
17 |
|
|
link => 1, |
18 |
|
|
meta => 1, |
19 |
|
|
hr => 1, |
20 |
|
|
br => 1, |
21 |
wakaba |
1.71 |
img => 1, |
22 |
wakaba |
1.1 |
embed => 1, |
23 |
|
|
param => 1, |
24 |
|
|
area => 1, |
25 |
|
|
col => 1, |
26 |
|
|
input => 1, |
27 |
|
|
}; |
28 |
|
|
|
29 |
wakaba |
1.4 |
my $c1_entity_char = { |
30 |
wakaba |
1.10 |
0x80 => 0x20AC, |
31 |
|
|
0x81 => 0xFFFD, |
32 |
|
|
0x82 => 0x201A, |
33 |
|
|
0x83 => 0x0192, |
34 |
|
|
0x84 => 0x201E, |
35 |
|
|
0x85 => 0x2026, |
36 |
|
|
0x86 => 0x2020, |
37 |
|
|
0x87 => 0x2021, |
38 |
|
|
0x88 => 0x02C6, |
39 |
|
|
0x89 => 0x2030, |
40 |
|
|
0x8A => 0x0160, |
41 |
|
|
0x8B => 0x2039, |
42 |
|
|
0x8C => 0x0152, |
43 |
|
|
0x8D => 0xFFFD, |
44 |
|
|
0x8E => 0x017D, |
45 |
|
|
0x8F => 0xFFFD, |
46 |
|
|
0x90 => 0xFFFD, |
47 |
|
|
0x91 => 0x2018, |
48 |
|
|
0x92 => 0x2019, |
49 |
|
|
0x93 => 0x201C, |
50 |
|
|
0x94 => 0x201D, |
51 |
|
|
0x95 => 0x2022, |
52 |
|
|
0x96 => 0x2013, |
53 |
|
|
0x97 => 0x2014, |
54 |
|
|
0x98 => 0x02DC, |
55 |
|
|
0x99 => 0x2122, |
56 |
|
|
0x9A => 0x0161, |
57 |
|
|
0x9B => 0x203A, |
58 |
|
|
0x9C => 0x0153, |
59 |
|
|
0x9D => 0xFFFD, |
60 |
|
|
0x9E => 0x017E, |
61 |
|
|
0x9F => 0x0178, |
62 |
wakaba |
1.4 |
}; # $c1_entity_char |
63 |
wakaba |
1.1 |
|
64 |
|
|
my $special_category = { |
65 |
|
|
address => 1, area => 1, base => 1, basefont => 1, bgsound => 1, |
66 |
|
|
blockquote => 1, body => 1, br => 1, center => 1, col => 1, colgroup => 1, |
67 |
|
|
dd => 1, dir => 1, div => 1, dl => 1, dt => 1, embed => 1, fieldset => 1, |
68 |
|
|
form => 1, frame => 1, frameset => 1, h1 => 1, h2 => 1, h3 => 1, |
69 |
|
|
h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, iframe => 1, image => 1, |
70 |
|
|
img => 1, input => 1, isindex => 1, li => 1, link => 1, listing => 1, |
71 |
|
|
menu => 1, meta => 1, noembed => 1, noframes => 1, noscript => 1, |
72 |
|
|
ol => 1, optgroup => 1, option => 1, p => 1, param => 1, plaintext => 1, |
73 |
|
|
pre => 1, script => 1, select => 1, spacer => 1, style => 1, tbody => 1, |
74 |
|
|
textarea => 1, tfoot => 1, thead => 1, title => 1, tr => 1, ul => 1, wbr => 1, |
75 |
|
|
}; |
76 |
|
|
my $scoping_category = { |
77 |
wakaba |
1.103 |
applet => 1, button => 1, caption => 1, html => 1, marquee => 1, object => 1, |
78 |
wakaba |
1.1 |
table => 1, td => 1, th => 1, |
79 |
|
|
}; |
80 |
|
|
my $formatting_category = { |
81 |
|
|
a => 1, b => 1, big => 1, em => 1, font => 1, i => 1, nobr => 1, |
82 |
|
|
s => 1, small => 1, strile => 1, strong => 1, tt => 1, u => 1, |
83 |
|
|
}; |
84 |
|
|
# $phrasing_category: all other elements |
85 |
|
|
|
86 |
wakaba |
1.63 |
sub parse_byte_string ($$$$;$) { |
87 |
|
|
my $self = ref $_[0] ? shift : shift->new; |
88 |
|
|
my $charset = shift; |
89 |
|
|
my $bytes_s = ref $_[0] ? $_[0] : \($_[0]); |
90 |
|
|
my $s; |
91 |
|
|
|
92 |
|
|
if (defined $charset) { |
93 |
wakaba |
1.64 |
require Encode; ## TODO: decode(utf8) don't delete BOM |
94 |
wakaba |
1.63 |
$s = \ (Encode::decode ($charset, $$bytes_s)); |
95 |
wakaba |
1.64 |
$self->{input_encoding} = lc $charset; ## TODO: normalize name |
96 |
wakaba |
1.63 |
$self->{confident} = 1; |
97 |
|
|
} else { |
98 |
wakaba |
1.65 |
## TODO: Implement HTML5 detection algorithm |
99 |
|
|
require Whatpm::Charset::UniversalCharDet; |
100 |
|
|
$charset = Whatpm::Charset::UniversalCharDet->detect_byte_string |
101 |
|
|
(substr ($$bytes_s, 0, 1024)); |
102 |
|
|
$charset ||= 'windows-1252'; |
103 |
wakaba |
1.64 |
$s = \ (Encode::decode ($charset, $$bytes_s)); |
104 |
|
|
$self->{input_encoding} = $charset; |
105 |
wakaba |
1.63 |
$self->{confident} = 0; |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
$self->{change_encoding} = sub { |
109 |
|
|
my $self = shift; |
110 |
|
|
my $charset = lc shift; |
111 |
wakaba |
1.114 |
my $token = shift; |
112 |
wakaba |
1.63 |
## TODO: if $charset is supported |
113 |
|
|
## TODO: normalize charset name |
114 |
|
|
|
115 |
|
|
## "Change the encoding" algorithm: |
116 |
|
|
|
117 |
|
|
## Step 1 |
118 |
|
|
if ($charset eq 'utf-16') { ## ISSUE: UTF-16BE -> UTF-8? UTF-16LE -> UTF-8? |
119 |
|
|
$charset = 'utf-8'; |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
## Step 2 |
123 |
|
|
if (defined $self->{input_encoding} and |
124 |
|
|
$self->{input_encoding} eq $charset) { |
125 |
|
|
$self->{confident} = 1; |
126 |
|
|
return; |
127 |
|
|
} |
128 |
|
|
|
129 |
wakaba |
1.64 |
!!!parse-error (type => 'charset label detected:'.$self->{input_encoding}. |
130 |
wakaba |
1.114 |
':'.$charset, level => 'w', token => $token); |
131 |
wakaba |
1.63 |
|
132 |
|
|
## Step 3 |
133 |
|
|
# if (can) { |
134 |
|
|
## change the encoding on the fly. |
135 |
|
|
#$self->{confident} = 1; |
136 |
|
|
#return; |
137 |
|
|
# } |
138 |
|
|
|
139 |
|
|
## Step 4 |
140 |
|
|
throw Whatpm::HTML::RestartParser (charset => $charset); |
141 |
|
|
}; # $self->{change_encoding} |
142 |
|
|
|
143 |
|
|
my @args = @_; shift @args; # $s |
144 |
|
|
my $return; |
145 |
|
|
try { |
146 |
|
|
$return = $self->parse_char_string ($s, @args); |
147 |
|
|
} catch Whatpm::HTML::RestartParser with { |
148 |
|
|
my $charset = shift->{charset}; |
149 |
|
|
$s = \ (Encode::decode ($charset, $$bytes_s)); |
150 |
wakaba |
1.64 |
$self->{input_encoding} = $charset; ## TODO: normalize |
151 |
wakaba |
1.63 |
$self->{confident} = 1; |
152 |
|
|
$return = $self->parse_char_string ($s, @args); |
153 |
|
|
}; |
154 |
|
|
return $return; |
155 |
|
|
} # parse_byte_string |
156 |
|
|
|
157 |
wakaba |
1.71 |
## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM |
158 |
|
|
## and the HTML layer MUST ignore it. However, we does strip BOM in |
159 |
|
|
## the encoding layer and the HTML layer does not ignore any U+FEFF, |
160 |
|
|
## because the core part of our HTML parser expects a string of character, |
161 |
|
|
## not a string of bytes or code units or anything which might contain a BOM. |
162 |
|
|
## Therefore, any parser interface that accepts a string of bytes, |
163 |
|
|
## such as |parse_byte_string| in this module, must ensure that it does |
164 |
|
|
## strip the BOM and never strip any ZWNBSP. |
165 |
|
|
|
166 |
wakaba |
1.63 |
*parse_char_string = \&parse_string; |
167 |
|
|
|
168 |
wakaba |
1.1 |
sub parse_string ($$$;$) { |
169 |
wakaba |
1.63 |
my $self = ref $_[0] ? shift : shift->new; |
170 |
|
|
my $s = ref $_[0] ? $_[0] : \($_[0]); |
171 |
wakaba |
1.1 |
$self->{document} = $_[1]; |
172 |
wakaba |
1.63 |
@{$self->{document}->child_nodes} = (); |
173 |
wakaba |
1.1 |
|
174 |
wakaba |
1.3 |
## NOTE: |set_inner_html| copies most of this method's code |
175 |
|
|
|
176 |
wakaba |
1.63 |
$self->{confident} = 1 unless exists $self->{confident}; |
177 |
wakaba |
1.64 |
$self->{document}->input_encoding ($self->{input_encoding}) |
178 |
|
|
if defined $self->{input_encoding}; |
179 |
wakaba |
1.63 |
|
180 |
wakaba |
1.1 |
my $i = 0; |
181 |
wakaba |
1.112 |
$self->{line_prev} = $self->{line} = 1; |
182 |
|
|
$self->{column_prev} = $self->{column} = 0; |
183 |
wakaba |
1.76 |
$self->{set_next_char} = sub { |
184 |
wakaba |
1.1 |
my $self = shift; |
185 |
wakaba |
1.13 |
|
186 |
wakaba |
1.76 |
pop @{$self->{prev_char}}; |
187 |
|
|
unshift @{$self->{prev_char}}, $self->{next_char}; |
188 |
wakaba |
1.13 |
|
189 |
wakaba |
1.76 |
$self->{next_char} = -1 and return if $i >= length $$s; |
190 |
|
|
$self->{next_char} = ord substr $$s, $i++, 1; |
191 |
wakaba |
1.112 |
|
192 |
|
|
($self->{line_prev}, $self->{column_prev}) |
193 |
|
|
= ($self->{line}, $self->{column}); |
194 |
|
|
$self->{column}++; |
195 |
wakaba |
1.1 |
|
196 |
wakaba |
1.76 |
if ($self->{next_char} == 0x000A) { # LF |
197 |
wakaba |
1.112 |
$self->{line}++; |
198 |
|
|
$self->{column} = 0; |
199 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x000D) { # CR |
200 |
wakaba |
1.15 |
$i++ if substr ($$s, $i, 1) eq "\x0A"; |
201 |
wakaba |
1.76 |
$self->{next_char} = 0x000A; # LF # MUST |
202 |
wakaba |
1.112 |
$self->{line}++; |
203 |
|
|
$self->{column} = 0; |
204 |
wakaba |
1.76 |
} elsif ($self->{next_char} > 0x10FFFF) { |
205 |
|
|
$self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST |
206 |
|
|
} elsif ($self->{next_char} == 0x0000) { # NULL |
207 |
wakaba |
1.8 |
!!!parse-error (type => 'NULL'); |
208 |
wakaba |
1.76 |
$self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST |
209 |
wakaba |
1.1 |
} |
210 |
|
|
}; |
211 |
wakaba |
1.76 |
$self->{prev_char} = [-1, -1, -1]; |
212 |
|
|
$self->{next_char} = -1; |
213 |
wakaba |
1.1 |
|
214 |
wakaba |
1.3 |
my $onerror = $_[2] || sub { |
215 |
|
|
my (%opt) = @_; |
216 |
wakaba |
1.112 |
my $line = $opt{token} ? $opt{token}->{line} : $opt{line}; |
217 |
|
|
my $column = $opt{token} ? $opt{token}->{column} : $opt{column}; |
218 |
|
|
warn "Parse error ($opt{type}) at line $line column $column\n"; |
219 |
wakaba |
1.3 |
}; |
220 |
|
|
$self->{parse_error} = sub { |
221 |
wakaba |
1.112 |
$onerror->(line => $self->{line}, column => $self->{column}, @_); |
222 |
wakaba |
1.1 |
}; |
223 |
|
|
|
224 |
|
|
$self->_initialize_tokenizer; |
225 |
|
|
$self->_initialize_tree_constructor; |
226 |
|
|
$self->_construct_tree; |
227 |
|
|
$self->_terminate_tree_constructor; |
228 |
|
|
|
229 |
wakaba |
1.112 |
delete $self->{parse_error}; # remove loop |
230 |
|
|
|
231 |
wakaba |
1.1 |
return $self->{document}; |
232 |
|
|
} # parse_string |
233 |
|
|
|
234 |
|
|
sub new ($) { |
235 |
|
|
my $class = shift; |
236 |
|
|
my $self = bless {}, $class; |
237 |
wakaba |
1.76 |
$self->{set_next_char} = sub { |
238 |
|
|
$self->{next_char} = -1; |
239 |
wakaba |
1.1 |
}; |
240 |
|
|
$self->{parse_error} = sub { |
241 |
|
|
# |
242 |
|
|
}; |
243 |
wakaba |
1.63 |
$self->{change_encoding} = sub { |
244 |
|
|
# if ($_[0] is a supported encoding) { |
245 |
|
|
# run "change the encoding" algorithm; |
246 |
|
|
# throw Whatpm::HTML::RestartParser (charset => $new_encoding); |
247 |
|
|
# } |
248 |
|
|
}; |
249 |
wakaba |
1.61 |
$self->{application_cache_selection} = sub { |
250 |
|
|
# |
251 |
|
|
}; |
252 |
wakaba |
1.1 |
return $self; |
253 |
|
|
} # new |
254 |
|
|
|
255 |
wakaba |
1.40 |
sub CM_ENTITY () { 0b001 } # & markup in data |
256 |
|
|
sub CM_LIMITED_MARKUP () { 0b010 } # < markup in data (limited) |
257 |
|
|
sub CM_FULL_MARKUP () { 0b100 } # < markup in data (any) |
258 |
|
|
|
259 |
|
|
sub PLAINTEXT_CONTENT_MODEL () { 0 } |
260 |
|
|
sub CDATA_CONTENT_MODEL () { CM_LIMITED_MARKUP } |
261 |
|
|
sub RCDATA_CONTENT_MODEL () { CM_ENTITY | CM_LIMITED_MARKUP } |
262 |
|
|
sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP } |
263 |
|
|
|
264 |
wakaba |
1.57 |
sub DATA_STATE () { 0 } |
265 |
|
|
sub ENTITY_DATA_STATE () { 1 } |
266 |
|
|
sub TAG_OPEN_STATE () { 2 } |
267 |
|
|
sub CLOSE_TAG_OPEN_STATE () { 3 } |
268 |
|
|
sub TAG_NAME_STATE () { 4 } |
269 |
|
|
sub BEFORE_ATTRIBUTE_NAME_STATE () { 5 } |
270 |
|
|
sub ATTRIBUTE_NAME_STATE () { 6 } |
271 |
|
|
sub AFTER_ATTRIBUTE_NAME_STATE () { 7 } |
272 |
|
|
sub BEFORE_ATTRIBUTE_VALUE_STATE () { 8 } |
273 |
|
|
sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 } |
274 |
|
|
sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 } |
275 |
|
|
sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 } |
276 |
|
|
sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 } |
277 |
|
|
sub MARKUP_DECLARATION_OPEN_STATE () { 13 } |
278 |
|
|
sub COMMENT_START_STATE () { 14 } |
279 |
|
|
sub COMMENT_START_DASH_STATE () { 15 } |
280 |
|
|
sub COMMENT_STATE () { 16 } |
281 |
|
|
sub COMMENT_END_STATE () { 17 } |
282 |
|
|
sub COMMENT_END_DASH_STATE () { 18 } |
283 |
|
|
sub BOGUS_COMMENT_STATE () { 19 } |
284 |
|
|
sub DOCTYPE_STATE () { 20 } |
285 |
|
|
sub BEFORE_DOCTYPE_NAME_STATE () { 21 } |
286 |
|
|
sub DOCTYPE_NAME_STATE () { 22 } |
287 |
|
|
sub AFTER_DOCTYPE_NAME_STATE () { 23 } |
288 |
|
|
sub BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE () { 24 } |
289 |
|
|
sub DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE () { 25 } |
290 |
|
|
sub DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE () { 26 } |
291 |
|
|
sub AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE () { 27 } |
292 |
|
|
sub BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE () { 28 } |
293 |
|
|
sub DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE () { 29 } |
294 |
|
|
sub DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE () { 30 } |
295 |
|
|
sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE () { 31 } |
296 |
|
|
sub BOGUS_DOCTYPE_STATE () { 32 } |
297 |
wakaba |
1.72 |
sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 } |
298 |
wakaba |
1.57 |
|
299 |
wakaba |
1.55 |
sub DOCTYPE_TOKEN () { 1 } |
300 |
|
|
sub COMMENT_TOKEN () { 2 } |
301 |
|
|
sub START_TAG_TOKEN () { 3 } |
302 |
|
|
sub END_TAG_TOKEN () { 4 } |
303 |
|
|
sub END_OF_FILE_TOKEN () { 5 } |
304 |
|
|
sub CHARACTER_TOKEN () { 6 } |
305 |
|
|
|
306 |
wakaba |
1.54 |
sub AFTER_HTML_IMS () { 0b100 } |
307 |
|
|
sub HEAD_IMS () { 0b1000 } |
308 |
|
|
sub BODY_IMS () { 0b10000 } |
309 |
wakaba |
1.56 |
sub BODY_TABLE_IMS () { 0b100000 } |
310 |
wakaba |
1.54 |
sub TABLE_IMS () { 0b1000000 } |
311 |
wakaba |
1.56 |
sub ROW_IMS () { 0b10000000 } |
312 |
wakaba |
1.54 |
sub BODY_AFTER_IMS () { 0b100000000 } |
313 |
|
|
sub FRAME_IMS () { 0b1000000000 } |
314 |
wakaba |
1.101 |
sub SELECT_IMS () { 0b10000000000 } |
315 |
wakaba |
1.54 |
|
316 |
wakaba |
1.84 |
## NOTE: "initial" and "before html" insertion modes have no constants. |
317 |
|
|
|
318 |
|
|
## NOTE: "after after body" insertion mode. |
319 |
wakaba |
1.54 |
sub AFTER_HTML_BODY_IM () { AFTER_HTML_IMS | BODY_AFTER_IMS } |
320 |
wakaba |
1.84 |
|
321 |
|
|
## NOTE: "after after frameset" insertion mode. |
322 |
wakaba |
1.54 |
sub AFTER_HTML_FRAMESET_IM () { AFTER_HTML_IMS | FRAME_IMS } |
323 |
wakaba |
1.84 |
|
324 |
wakaba |
1.54 |
sub IN_HEAD_IM () { HEAD_IMS | 0b00 } |
325 |
|
|
sub IN_HEAD_NOSCRIPT_IM () { HEAD_IMS | 0b01 } |
326 |
|
|
sub AFTER_HEAD_IM () { HEAD_IMS | 0b10 } |
327 |
|
|
sub BEFORE_HEAD_IM () { HEAD_IMS | 0b11 } |
328 |
|
|
sub IN_BODY_IM () { BODY_IMS } |
329 |
wakaba |
1.56 |
sub IN_CELL_IM () { BODY_IMS | BODY_TABLE_IMS | 0b01 } |
330 |
|
|
sub IN_CAPTION_IM () { BODY_IMS | BODY_TABLE_IMS | 0b10 } |
331 |
|
|
sub IN_ROW_IM () { TABLE_IMS | ROW_IMS | 0b01 } |
332 |
|
|
sub IN_TABLE_BODY_IM () { TABLE_IMS | ROW_IMS | 0b10 } |
333 |
wakaba |
1.54 |
sub IN_TABLE_IM () { TABLE_IMS } |
334 |
|
|
sub AFTER_BODY_IM () { BODY_AFTER_IMS } |
335 |
|
|
sub IN_FRAMESET_IM () { FRAME_IMS | 0b01 } |
336 |
|
|
sub AFTER_FRAMESET_IM () { FRAME_IMS | 0b10 } |
337 |
wakaba |
1.101 |
sub IN_SELECT_IM () { SELECT_IMS | 0b01 } |
338 |
|
|
sub IN_SELECT_IN_TABLE_IM () { SELECT_IMS | 0b10 } |
339 |
wakaba |
1.54 |
sub IN_COLUMN_GROUP_IM () { 0b10 } |
340 |
|
|
|
341 |
wakaba |
1.1 |
## Implementations MUST act as if state machine in the spec |
342 |
|
|
|
343 |
|
|
sub _initialize_tokenizer ($) { |
344 |
|
|
my $self = shift; |
345 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; # MUST |
346 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # be |
347 |
wakaba |
1.1 |
undef $self->{current_token}; # start tag, end tag, comment, or DOCTYPE |
348 |
|
|
undef $self->{current_attribute}; |
349 |
|
|
undef $self->{last_emitted_start_tag_name}; |
350 |
|
|
undef $self->{last_attribute_value_state}; |
351 |
|
|
$self->{char} = []; |
352 |
wakaba |
1.76 |
# $self->{next_char} |
353 |
wakaba |
1.1 |
!!!next-input-character; |
354 |
|
|
$self->{token} = []; |
355 |
wakaba |
1.18 |
# $self->{escape} |
356 |
wakaba |
1.1 |
} # _initialize_tokenizer |
357 |
|
|
|
358 |
|
|
## A token has: |
359 |
wakaba |
1.55 |
## ->{type} == DOCTYPE_TOKEN, START_TAG_TOKEN, END_TAG_TOKEN, COMMENT_TOKEN, |
360 |
|
|
## CHARACTER_TOKEN, or END_OF_FILE_TOKEN |
361 |
|
|
## ->{name} (DOCTYPE_TOKEN) |
362 |
|
|
## ->{tag_name} (START_TAG_TOKEN, END_TAG_TOKEN) |
363 |
|
|
## ->{public_identifier} (DOCTYPE_TOKEN) |
364 |
|
|
## ->{system_identifier} (DOCTYPE_TOKEN) |
365 |
wakaba |
1.75 |
## ->{quirks} == 1 or 0 (DOCTYPE_TOKEN): "force-quirks" flag |
366 |
wakaba |
1.55 |
## ->{attributes} isa HASH (START_TAG_TOKEN, END_TAG_TOKEN) |
367 |
wakaba |
1.66 |
## ->{name} |
368 |
|
|
## ->{value} |
369 |
|
|
## ->{has_reference} == 1 or 0 |
370 |
wakaba |
1.55 |
## ->{data} (COMMENT_TOKEN, CHARACTER_TOKEN) |
371 |
wakaba |
1.1 |
|
372 |
|
|
## Emitted token MUST immediately be handled by the tree construction state. |
373 |
|
|
|
374 |
|
|
## Before each step, UA MAY check to see if either one of the scripts in |
375 |
|
|
## "list of scripts that will execute as soon as possible" or the first |
376 |
|
|
## script in the "list of scripts that will execute asynchronously", |
377 |
|
|
## has completed loading. If one has, then it MUST be executed |
378 |
|
|
## and removed from the list. |
379 |
|
|
|
380 |
wakaba |
1.59 |
## NOTE: HTML5 "Writing HTML documents" section, applied to |
381 |
|
|
## documents and not to user agents and conformance checkers, |
382 |
|
|
## contains some requirements that are not detected by the |
383 |
|
|
## parsing algorithm: |
384 |
|
|
## - Some requirements on character encoding declarations. ## TODO |
385 |
|
|
## - "Elements MUST NOT contain content that their content model disallows." |
386 |
|
|
## ... Some are parse error, some are not (will be reported by c.c.). |
387 |
|
|
## - Polytheistic slash SHOULD NOT be used. (Applied only to atheists.) ## TODO |
388 |
|
|
## - Text (in elements, attributes, and comments) SHOULD NOT contain |
389 |
|
|
## control characters other than space characters. ## TODO: (what is control character? C0, C1 and DEL? Unicode control character?) |
390 |
|
|
|
391 |
|
|
## TODO: HTML5 poses authors two SHOULD-level requirements that cannot |
392 |
|
|
## be detected by the HTML5 parsing algorithm: |
393 |
|
|
## - Text, |
394 |
|
|
|
395 |
wakaba |
1.1 |
sub _get_next_token ($) { |
396 |
|
|
my $self = shift; |
397 |
|
|
if (@{$self->{token}}) { |
398 |
|
|
return shift @{$self->{token}}; |
399 |
|
|
} |
400 |
|
|
|
401 |
|
|
A: { |
402 |
wakaba |
1.57 |
if ($self->{state} == DATA_STATE) { |
403 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0026) { # & |
404 |
wakaba |
1.72 |
if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA |
405 |
|
|
not $self->{escape}) { |
406 |
wakaba |
1.77 |
!!!cp (1); |
407 |
wakaba |
1.57 |
$self->{state} = ENTITY_DATA_STATE; |
408 |
wakaba |
1.1 |
!!!next-input-character; |
409 |
|
|
redo A; |
410 |
|
|
} else { |
411 |
wakaba |
1.77 |
!!!cp (2); |
412 |
wakaba |
1.1 |
# |
413 |
|
|
} |
414 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x002D) { # - |
415 |
wakaba |
1.40 |
if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA |
416 |
wakaba |
1.13 |
unless ($self->{escape}) { |
417 |
wakaba |
1.76 |
if ($self->{prev_char}->[0] == 0x002D and # - |
418 |
|
|
$self->{prev_char}->[1] == 0x0021 and # ! |
419 |
|
|
$self->{prev_char}->[2] == 0x003C) { # < |
420 |
wakaba |
1.77 |
!!!cp (3); |
421 |
wakaba |
1.13 |
$self->{escape} = 1; |
422 |
wakaba |
1.77 |
} else { |
423 |
|
|
!!!cp (4); |
424 |
wakaba |
1.13 |
} |
425 |
wakaba |
1.77 |
} else { |
426 |
|
|
!!!cp (5); |
427 |
wakaba |
1.13 |
} |
428 |
|
|
} |
429 |
|
|
|
430 |
|
|
# |
431 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003C) { # < |
432 |
wakaba |
1.40 |
if ($self->{content_model} & CM_FULL_MARKUP or # PCDATA |
433 |
|
|
(($self->{content_model} & CM_LIMITED_MARKUP) and # CDATA | RCDATA |
434 |
wakaba |
1.13 |
not $self->{escape})) { |
435 |
wakaba |
1.77 |
!!!cp (6); |
436 |
wakaba |
1.57 |
$self->{state} = TAG_OPEN_STATE; |
437 |
wakaba |
1.1 |
!!!next-input-character; |
438 |
|
|
redo A; |
439 |
|
|
} else { |
440 |
wakaba |
1.77 |
!!!cp (7); |
441 |
wakaba |
1.1 |
# |
442 |
|
|
} |
443 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
444 |
wakaba |
1.13 |
if ($self->{escape} and |
445 |
wakaba |
1.40 |
($self->{content_model} & CM_LIMITED_MARKUP)) { # RCDATA | CDATA |
446 |
wakaba |
1.76 |
if ($self->{prev_char}->[0] == 0x002D and # - |
447 |
|
|
$self->{prev_char}->[1] == 0x002D) { # - |
448 |
wakaba |
1.77 |
!!!cp (8); |
449 |
wakaba |
1.13 |
delete $self->{escape}; |
450 |
wakaba |
1.77 |
} else { |
451 |
|
|
!!!cp (9); |
452 |
wakaba |
1.13 |
} |
453 |
wakaba |
1.77 |
} else { |
454 |
|
|
!!!cp (10); |
455 |
wakaba |
1.13 |
} |
456 |
|
|
|
457 |
|
|
# |
458 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
459 |
wakaba |
1.77 |
!!!cp (11); |
460 |
wakaba |
1.112 |
!!!emit ({type => END_OF_FILE_TOKEN, |
461 |
|
|
line => $self->{line}, column => $self->{column}}); |
462 |
wakaba |
1.1 |
last A; ## TODO: ok? |
463 |
wakaba |
1.77 |
} else { |
464 |
|
|
!!!cp (12); |
465 |
wakaba |
1.1 |
} |
466 |
|
|
# Anything else |
467 |
wakaba |
1.55 |
my $token = {type => CHARACTER_TOKEN, |
468 |
wakaba |
1.112 |
data => chr $self->{next_char}, |
469 |
|
|
line => $self->{line}, column => $self->{column}}; |
470 |
wakaba |
1.1 |
## Stay in the data state |
471 |
|
|
!!!next-input-character; |
472 |
|
|
|
473 |
|
|
!!!emit ($token); |
474 |
|
|
|
475 |
|
|
redo A; |
476 |
wakaba |
1.57 |
} elsif ($self->{state} == ENTITY_DATA_STATE) { |
477 |
wakaba |
1.1 |
## (cannot happen in CDATA state) |
478 |
wakaba |
1.112 |
|
479 |
|
|
my ($l, $c) = ($self->{line_prev}, $self->{column_prev}); |
480 |
wakaba |
1.1 |
|
481 |
wakaba |
1.72 |
my $token = $self->_tokenize_attempt_to_consume_an_entity (0, -1); |
482 |
wakaba |
1.1 |
|
483 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
484 |
wakaba |
1.1 |
# next-input-character is already done |
485 |
|
|
|
486 |
|
|
unless (defined $token) { |
487 |
wakaba |
1.77 |
!!!cp (13); |
488 |
wakaba |
1.112 |
!!!emit ({type => CHARACTER_TOKEN, data => '&', |
489 |
|
|
line => $l, column => $c}); |
490 |
wakaba |
1.1 |
} else { |
491 |
wakaba |
1.77 |
!!!cp (14); |
492 |
wakaba |
1.1 |
!!!emit ($token); |
493 |
|
|
} |
494 |
|
|
|
495 |
|
|
redo A; |
496 |
wakaba |
1.57 |
} elsif ($self->{state} == TAG_OPEN_STATE) { |
497 |
wakaba |
1.40 |
if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA |
498 |
wakaba |
1.76 |
if ($self->{next_char} == 0x002F) { # / |
499 |
wakaba |
1.77 |
!!!cp (15); |
500 |
wakaba |
1.1 |
!!!next-input-character; |
501 |
wakaba |
1.57 |
$self->{state} = CLOSE_TAG_OPEN_STATE; |
502 |
wakaba |
1.1 |
redo A; |
503 |
|
|
} else { |
504 |
wakaba |
1.77 |
!!!cp (16); |
505 |
wakaba |
1.1 |
## reconsume |
506 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
507 |
wakaba |
1.1 |
|
508 |
wakaba |
1.112 |
!!!emit ({type => CHARACTER_TOKEN, data => '<', |
509 |
|
|
line => $self->{line_prev}, |
510 |
|
|
column => $self->{column_prev}}); |
511 |
wakaba |
1.1 |
|
512 |
|
|
redo A; |
513 |
|
|
} |
514 |
wakaba |
1.40 |
} elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA |
515 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0021) { # ! |
516 |
wakaba |
1.77 |
!!!cp (17); |
517 |
wakaba |
1.57 |
$self->{state} = MARKUP_DECLARATION_OPEN_STATE; |
518 |
wakaba |
1.1 |
!!!next-input-character; |
519 |
|
|
redo A; |
520 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x002F) { # / |
521 |
wakaba |
1.77 |
!!!cp (18); |
522 |
wakaba |
1.57 |
$self->{state} = CLOSE_TAG_OPEN_STATE; |
523 |
wakaba |
1.1 |
!!!next-input-character; |
524 |
|
|
redo A; |
525 |
wakaba |
1.76 |
} elsif (0x0041 <= $self->{next_char} and |
526 |
|
|
$self->{next_char} <= 0x005A) { # A..Z |
527 |
wakaba |
1.77 |
!!!cp (19); |
528 |
wakaba |
1.1 |
$self->{current_token} |
529 |
wakaba |
1.55 |
= {type => START_TAG_TOKEN, |
530 |
wakaba |
1.112 |
tag_name => chr ($self->{next_char} + 0x0020), |
531 |
|
|
line => $self->{line_prev}, |
532 |
|
|
column => $self->{column_prev}}; |
533 |
wakaba |
1.57 |
$self->{state} = TAG_NAME_STATE; |
534 |
wakaba |
1.1 |
!!!next-input-character; |
535 |
|
|
redo A; |
536 |
wakaba |
1.76 |
} elsif (0x0061 <= $self->{next_char} and |
537 |
|
|
$self->{next_char} <= 0x007A) { # a..z |
538 |
wakaba |
1.77 |
!!!cp (20); |
539 |
wakaba |
1.55 |
$self->{current_token} = {type => START_TAG_TOKEN, |
540 |
wakaba |
1.112 |
tag_name => chr ($self->{next_char}), |
541 |
|
|
line => $self->{line_prev}, |
542 |
|
|
column => $self->{column_prev}}; |
543 |
wakaba |
1.57 |
$self->{state} = TAG_NAME_STATE; |
544 |
wakaba |
1.1 |
!!!next-input-character; |
545 |
|
|
redo A; |
546 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
547 |
wakaba |
1.77 |
!!!cp (21); |
548 |
wakaba |
1.115 |
!!!parse-error (type => 'empty start tag', |
549 |
|
|
line => $self->{line_prev}, |
550 |
|
|
column => $self->{column_prev}); |
551 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
552 |
wakaba |
1.1 |
!!!next-input-character; |
553 |
|
|
|
554 |
wakaba |
1.112 |
!!!emit ({type => CHARACTER_TOKEN, data => '<>', |
555 |
|
|
line => $self->{line_prev}, |
556 |
|
|
column => $self->{column_prev}}); |
557 |
wakaba |
1.1 |
|
558 |
|
|
redo A; |
559 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003F) { # ? |
560 |
wakaba |
1.77 |
!!!cp (22); |
561 |
wakaba |
1.115 |
!!!parse-error (type => 'pio', |
562 |
|
|
line => $self->{line_prev}, |
563 |
|
|
column => $self->{column_prev}); |
564 |
wakaba |
1.57 |
$self->{state} = BOGUS_COMMENT_STATE; |
565 |
wakaba |
1.112 |
$self->{current_token} = {type => COMMENT_TOKEN, data => '', |
566 |
|
|
line => $self->{line_prev}, |
567 |
|
|
column => $self->{column_prev}}; |
568 |
wakaba |
1.76 |
## $self->{next_char} is intentionally left as is |
569 |
wakaba |
1.1 |
redo A; |
570 |
|
|
} else { |
571 |
wakaba |
1.77 |
!!!cp (23); |
572 |
wakaba |
1.3 |
!!!parse-error (type => 'bare stago'); |
573 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
574 |
wakaba |
1.1 |
## reconsume |
575 |
|
|
|
576 |
wakaba |
1.112 |
!!!emit ({type => CHARACTER_TOKEN, data => '<', |
577 |
|
|
line => $self->{line_prev}, |
578 |
|
|
column => $self->{column_prev}}); |
579 |
wakaba |
1.1 |
|
580 |
|
|
redo A; |
581 |
|
|
} |
582 |
|
|
} else { |
583 |
wakaba |
1.40 |
die "$0: $self->{content_model} in tag open"; |
584 |
wakaba |
1.1 |
} |
585 |
wakaba |
1.57 |
} elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) { |
586 |
wakaba |
1.113 |
my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</" |
587 |
wakaba |
1.40 |
if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA |
588 |
wakaba |
1.23 |
if (defined $self->{last_emitted_start_tag_name}) { |
589 |
wakaba |
1.112 |
|
590 |
wakaba |
1.30 |
## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564> |
591 |
wakaba |
1.23 |
my @next_char; |
592 |
|
|
TAGNAME: for (my $i = 0; $i < length $self->{last_emitted_start_tag_name}; $i++) { |
593 |
wakaba |
1.76 |
push @next_char, $self->{next_char}; |
594 |
wakaba |
1.23 |
my $c = ord substr ($self->{last_emitted_start_tag_name}, $i, 1); |
595 |
|
|
my $C = 0x0061 <= $c && $c <= 0x007A ? $c - 0x0020 : $c; |
596 |
wakaba |
1.76 |
if ($self->{next_char} == $c or $self->{next_char} == $C) { |
597 |
wakaba |
1.77 |
!!!cp (24); |
598 |
wakaba |
1.23 |
!!!next-input-character; |
599 |
|
|
next TAGNAME; |
600 |
|
|
} else { |
601 |
wakaba |
1.77 |
!!!cp (25); |
602 |
wakaba |
1.76 |
$self->{next_char} = shift @next_char; # reconsume |
603 |
wakaba |
1.23 |
!!!back-next-input-character (@next_char); |
604 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
605 |
wakaba |
1.23 |
|
606 |
wakaba |
1.112 |
!!!emit ({type => CHARACTER_TOKEN, data => '</', |
607 |
|
|
line => $l, column => $c}); |
608 |
wakaba |
1.23 |
|
609 |
|
|
redo A; |
610 |
|
|
} |
611 |
|
|
} |
612 |
wakaba |
1.76 |
push @next_char, $self->{next_char}; |
613 |
wakaba |
1.23 |
|
614 |
wakaba |
1.76 |
unless ($self->{next_char} == 0x0009 or # HT |
615 |
|
|
$self->{next_char} == 0x000A or # LF |
616 |
|
|
$self->{next_char} == 0x000B or # VT |
617 |
|
|
$self->{next_char} == 0x000C or # FF |
618 |
|
|
$self->{next_char} == 0x0020 or # SP |
619 |
|
|
$self->{next_char} == 0x003E or # > |
620 |
|
|
$self->{next_char} == 0x002F or # / |
621 |
|
|
$self->{next_char} == -1) { |
622 |
wakaba |
1.77 |
!!!cp (26); |
623 |
wakaba |
1.76 |
$self->{next_char} = shift @next_char; # reconsume |
624 |
wakaba |
1.1 |
!!!back-next-input-character (@next_char); |
625 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
626 |
wakaba |
1.112 |
!!!emit ({type => CHARACTER_TOKEN, data => '</', |
627 |
|
|
line => $l, column => $c}); |
628 |
wakaba |
1.1 |
redo A; |
629 |
wakaba |
1.23 |
} else { |
630 |
wakaba |
1.77 |
!!!cp (27); |
631 |
wakaba |
1.76 |
$self->{next_char} = shift @next_char; |
632 |
wakaba |
1.23 |
!!!back-next-input-character (@next_char); |
633 |
|
|
# and consume... |
634 |
wakaba |
1.1 |
} |
635 |
wakaba |
1.23 |
} else { |
636 |
|
|
## No start tag token has ever been emitted |
637 |
wakaba |
1.77 |
!!!cp (28); |
638 |
wakaba |
1.23 |
# next-input-character is already done |
639 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
640 |
wakaba |
1.112 |
!!!emit ({type => CHARACTER_TOKEN, data => '</', |
641 |
|
|
line => $l, column => $c}); |
642 |
wakaba |
1.1 |
redo A; |
643 |
|
|
} |
644 |
|
|
} |
645 |
|
|
|
646 |
wakaba |
1.76 |
if (0x0041 <= $self->{next_char} and |
647 |
|
|
$self->{next_char} <= 0x005A) { # A..Z |
648 |
wakaba |
1.77 |
!!!cp (29); |
649 |
wakaba |
1.112 |
$self->{current_token} |
650 |
|
|
= {type => END_TAG_TOKEN, |
651 |
|
|
tag_name => chr ($self->{next_char} + 0x0020), |
652 |
|
|
line => $l, column => $c}; |
653 |
wakaba |
1.57 |
$self->{state} = TAG_NAME_STATE; |
654 |
wakaba |
1.1 |
!!!next-input-character; |
655 |
|
|
redo A; |
656 |
wakaba |
1.76 |
} elsif (0x0061 <= $self->{next_char} and |
657 |
|
|
$self->{next_char} <= 0x007A) { # a..z |
658 |
wakaba |
1.77 |
!!!cp (30); |
659 |
wakaba |
1.55 |
$self->{current_token} = {type => END_TAG_TOKEN, |
660 |
wakaba |
1.112 |
tag_name => chr ($self->{next_char}), |
661 |
|
|
line => $l, column => $c}; |
662 |
wakaba |
1.57 |
$self->{state} = TAG_NAME_STATE; |
663 |
wakaba |
1.1 |
!!!next-input-character; |
664 |
|
|
redo A; |
665 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
666 |
wakaba |
1.77 |
!!!cp (31); |
667 |
wakaba |
1.115 |
!!!parse-error (type => 'empty end tag', |
668 |
|
|
line => $self->{line_prev}, ## "<" in "</>" |
669 |
|
|
column => $self->{column_prev} - 1); |
670 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
671 |
wakaba |
1.1 |
!!!next-input-character; |
672 |
|
|
redo A; |
673 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
674 |
wakaba |
1.77 |
!!!cp (32); |
675 |
wakaba |
1.3 |
!!!parse-error (type => 'bare etago'); |
676 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
677 |
wakaba |
1.1 |
# reconsume |
678 |
|
|
|
679 |
wakaba |
1.112 |
!!!emit ({type => CHARACTER_TOKEN, data => '</', |
680 |
|
|
line => $l, column => $c}); |
681 |
wakaba |
1.1 |
|
682 |
|
|
redo A; |
683 |
|
|
} else { |
684 |
wakaba |
1.77 |
!!!cp (33); |
685 |
wakaba |
1.3 |
!!!parse-error (type => 'bogus end tag'); |
686 |
wakaba |
1.57 |
$self->{state} = BOGUS_COMMENT_STATE; |
687 |
wakaba |
1.112 |
$self->{current_token} = {type => COMMENT_TOKEN, data => '', |
688 |
|
|
line => $self->{line_prev}, # "<" of "</" |
689 |
|
|
column => $self->{column_prev} - 1}; |
690 |
wakaba |
1.76 |
## $self->{next_char} is intentionally left as is |
691 |
wakaba |
1.1 |
redo A; |
692 |
|
|
} |
693 |
wakaba |
1.57 |
} elsif ($self->{state} == TAG_NAME_STATE) { |
694 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0009 or # HT |
695 |
|
|
$self->{next_char} == 0x000A or # LF |
696 |
|
|
$self->{next_char} == 0x000B or # VT |
697 |
|
|
$self->{next_char} == 0x000C or # FF |
698 |
|
|
$self->{next_char} == 0x0020) { # SP |
699 |
wakaba |
1.77 |
!!!cp (34); |
700 |
wakaba |
1.57 |
$self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
701 |
wakaba |
1.1 |
!!!next-input-character; |
702 |
|
|
redo A; |
703 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
704 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
705 |
wakaba |
1.77 |
!!!cp (35); |
706 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
707 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
708 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
709 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
710 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
711 |
wakaba |
1.78 |
#if ($self->{current_token}->{attributes}) { |
712 |
|
|
# ## NOTE: This should never be reached. |
713 |
|
|
# !!! cp (36); |
714 |
|
|
# !!! parse-error (type => 'end tag attribute'); |
715 |
|
|
#} else { |
716 |
wakaba |
1.77 |
!!!cp (37); |
717 |
wakaba |
1.78 |
#} |
718 |
wakaba |
1.1 |
} else { |
719 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
720 |
|
|
} |
721 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
722 |
wakaba |
1.1 |
!!!next-input-character; |
723 |
|
|
|
724 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
725 |
|
|
|
726 |
|
|
redo A; |
727 |
wakaba |
1.76 |
} elsif (0x0041 <= $self->{next_char} and |
728 |
|
|
$self->{next_char} <= 0x005A) { # A..Z |
729 |
wakaba |
1.77 |
!!!cp (38); |
730 |
wakaba |
1.76 |
$self->{current_token}->{tag_name} .= chr ($self->{next_char} + 0x0020); |
731 |
wakaba |
1.1 |
# start tag or end tag |
732 |
|
|
## Stay in this state |
733 |
|
|
!!!next-input-character; |
734 |
|
|
redo A; |
735 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
736 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed tag'); |
737 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
738 |
wakaba |
1.77 |
!!!cp (39); |
739 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
740 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
741 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
742 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
743 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
744 |
wakaba |
1.78 |
#if ($self->{current_token}->{attributes}) { |
745 |
|
|
# ## NOTE: This state should never be reached. |
746 |
|
|
# !!! cp (40); |
747 |
|
|
# !!! parse-error (type => 'end tag attribute'); |
748 |
|
|
#} else { |
749 |
wakaba |
1.77 |
!!!cp (41); |
750 |
wakaba |
1.78 |
#} |
751 |
wakaba |
1.1 |
} else { |
752 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
753 |
|
|
} |
754 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
755 |
wakaba |
1.1 |
# reconsume |
756 |
|
|
|
757 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
758 |
|
|
|
759 |
|
|
redo A; |
760 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x002F) { # / |
761 |
wakaba |
1.1 |
!!!next-input-character; |
762 |
wakaba |
1.76 |
if ($self->{next_char} == 0x003E and # > |
763 |
wakaba |
1.55 |
$self->{current_token}->{type} == START_TAG_TOKEN and |
764 |
wakaba |
1.1 |
$permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) { |
765 |
|
|
# permitted slash |
766 |
wakaba |
1.77 |
!!!cp (42); |
767 |
wakaba |
1.1 |
# |
768 |
|
|
} else { |
769 |
wakaba |
1.77 |
!!!cp (43); |
770 |
wakaba |
1.3 |
!!!parse-error (type => 'nestc'); |
771 |
wakaba |
1.1 |
} |
772 |
wakaba |
1.57 |
$self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
773 |
wakaba |
1.1 |
# next-input-character is already done |
774 |
|
|
redo A; |
775 |
|
|
} else { |
776 |
wakaba |
1.77 |
!!!cp (44); |
777 |
wakaba |
1.76 |
$self->{current_token}->{tag_name} .= chr $self->{next_char}; |
778 |
wakaba |
1.1 |
# start tag or end tag |
779 |
|
|
## Stay in the state |
780 |
|
|
!!!next-input-character; |
781 |
|
|
redo A; |
782 |
|
|
} |
783 |
wakaba |
1.57 |
} elsif ($self->{state} == BEFORE_ATTRIBUTE_NAME_STATE) { |
784 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0009 or # HT |
785 |
|
|
$self->{next_char} == 0x000A or # LF |
786 |
|
|
$self->{next_char} == 0x000B or # VT |
787 |
|
|
$self->{next_char} == 0x000C or # FF |
788 |
|
|
$self->{next_char} == 0x0020) { # SP |
789 |
wakaba |
1.77 |
!!!cp (45); |
790 |
wakaba |
1.1 |
## Stay in the state |
791 |
|
|
!!!next-input-character; |
792 |
|
|
redo A; |
793 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
794 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
795 |
wakaba |
1.77 |
!!!cp (46); |
796 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
797 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
798 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
799 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
800 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
801 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
802 |
wakaba |
1.77 |
!!!cp (47); |
803 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
804 |
wakaba |
1.77 |
} else { |
805 |
|
|
!!!cp (48); |
806 |
wakaba |
1.1 |
} |
807 |
|
|
} else { |
808 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
809 |
|
|
} |
810 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
811 |
wakaba |
1.1 |
!!!next-input-character; |
812 |
|
|
|
813 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
814 |
|
|
|
815 |
|
|
redo A; |
816 |
wakaba |
1.76 |
} elsif (0x0041 <= $self->{next_char} and |
817 |
|
|
$self->{next_char} <= 0x005A) { # A..Z |
818 |
wakaba |
1.77 |
!!!cp (49); |
819 |
wakaba |
1.76 |
$self->{current_attribute} = {name => chr ($self->{next_char} + 0x0020), |
820 |
wakaba |
1.1 |
value => ''}; |
821 |
wakaba |
1.57 |
$self->{state} = ATTRIBUTE_NAME_STATE; |
822 |
wakaba |
1.1 |
!!!next-input-character; |
823 |
|
|
redo A; |
824 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x002F) { # / |
825 |
wakaba |
1.1 |
!!!next-input-character; |
826 |
wakaba |
1.76 |
if ($self->{next_char} == 0x003E and # > |
827 |
wakaba |
1.55 |
$self->{current_token}->{type} == START_TAG_TOKEN and |
828 |
wakaba |
1.1 |
$permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) { |
829 |
|
|
# permitted slash |
830 |
wakaba |
1.77 |
!!!cp (50); |
831 |
wakaba |
1.1 |
# |
832 |
|
|
} else { |
833 |
wakaba |
1.77 |
!!!cp (51); |
834 |
wakaba |
1.3 |
!!!parse-error (type => 'nestc'); |
835 |
wakaba |
1.1 |
} |
836 |
|
|
## Stay in the state |
837 |
|
|
# next-input-character is already done |
838 |
|
|
redo A; |
839 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
840 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed tag'); |
841 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
842 |
wakaba |
1.77 |
!!!cp (52); |
843 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
844 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
845 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
846 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
847 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
848 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
849 |
wakaba |
1.77 |
!!!cp (53); |
850 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
851 |
wakaba |
1.77 |
} else { |
852 |
|
|
!!!cp (54); |
853 |
wakaba |
1.1 |
} |
854 |
|
|
} else { |
855 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
856 |
|
|
} |
857 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
858 |
wakaba |
1.1 |
# reconsume |
859 |
|
|
|
860 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
861 |
|
|
|
862 |
|
|
redo A; |
863 |
|
|
} else { |
864 |
wakaba |
1.72 |
if ({ |
865 |
|
|
0x0022 => 1, # " |
866 |
|
|
0x0027 => 1, # ' |
867 |
|
|
0x003D => 1, # = |
868 |
wakaba |
1.76 |
}->{$self->{next_char}}) { |
869 |
wakaba |
1.77 |
!!!cp (55); |
870 |
wakaba |
1.72 |
!!!parse-error (type => 'bad attribute name'); |
871 |
wakaba |
1.77 |
} else { |
872 |
|
|
!!!cp (56); |
873 |
wakaba |
1.72 |
} |
874 |
wakaba |
1.76 |
$self->{current_attribute} = {name => chr ($self->{next_char}), |
875 |
wakaba |
1.1 |
value => ''}; |
876 |
wakaba |
1.57 |
$self->{state} = ATTRIBUTE_NAME_STATE; |
877 |
wakaba |
1.1 |
!!!next-input-character; |
878 |
|
|
redo A; |
879 |
|
|
} |
880 |
wakaba |
1.57 |
} elsif ($self->{state} == ATTRIBUTE_NAME_STATE) { |
881 |
wakaba |
1.1 |
my $before_leave = sub { |
882 |
|
|
if (exists $self->{current_token}->{attributes} # start tag or end tag |
883 |
|
|
->{$self->{current_attribute}->{name}}) { # MUST |
884 |
wakaba |
1.77 |
!!!cp (57); |
885 |
wakaba |
1.39 |
!!!parse-error (type => 'duplicate attribute:'.$self->{current_attribute}->{name}); |
886 |
wakaba |
1.1 |
## Discard $self->{current_attribute} # MUST |
887 |
|
|
} else { |
888 |
wakaba |
1.77 |
!!!cp (58); |
889 |
wakaba |
1.1 |
$self->{current_token}->{attributes}->{$self->{current_attribute}->{name}} |
890 |
|
|
= $self->{current_attribute}; |
891 |
|
|
} |
892 |
|
|
}; # $before_leave |
893 |
|
|
|
894 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0009 or # HT |
895 |
|
|
$self->{next_char} == 0x000A or # LF |
896 |
|
|
$self->{next_char} == 0x000B or # VT |
897 |
|
|
$self->{next_char} == 0x000C or # FF |
898 |
|
|
$self->{next_char} == 0x0020) { # SP |
899 |
wakaba |
1.77 |
!!!cp (59); |
900 |
wakaba |
1.1 |
$before_leave->(); |
901 |
wakaba |
1.57 |
$self->{state} = AFTER_ATTRIBUTE_NAME_STATE; |
902 |
wakaba |
1.1 |
!!!next-input-character; |
903 |
|
|
redo A; |
904 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003D) { # = |
905 |
wakaba |
1.77 |
!!!cp (60); |
906 |
wakaba |
1.1 |
$before_leave->(); |
907 |
wakaba |
1.57 |
$self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE; |
908 |
wakaba |
1.1 |
!!!next-input-character; |
909 |
|
|
redo A; |
910 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
911 |
wakaba |
1.1 |
$before_leave->(); |
912 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
913 |
wakaba |
1.77 |
!!!cp (61); |
914 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
915 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
916 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
917 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
918 |
wakaba |
1.77 |
!!!cp (62); |
919 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
920 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
921 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
922 |
wakaba |
1.1 |
} |
923 |
|
|
} else { |
924 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
925 |
|
|
} |
926 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
927 |
wakaba |
1.1 |
!!!next-input-character; |
928 |
|
|
|
929 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
930 |
|
|
|
931 |
|
|
redo A; |
932 |
wakaba |
1.76 |
} elsif (0x0041 <= $self->{next_char} and |
933 |
|
|
$self->{next_char} <= 0x005A) { # A..Z |
934 |
wakaba |
1.77 |
!!!cp (63); |
935 |
wakaba |
1.76 |
$self->{current_attribute}->{name} .= chr ($self->{next_char} + 0x0020); |
936 |
wakaba |
1.1 |
## Stay in the state |
937 |
|
|
!!!next-input-character; |
938 |
|
|
redo A; |
939 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x002F) { # / |
940 |
wakaba |
1.1 |
$before_leave->(); |
941 |
|
|
!!!next-input-character; |
942 |
wakaba |
1.76 |
if ($self->{next_char} == 0x003E and # > |
943 |
wakaba |
1.55 |
$self->{current_token}->{type} == START_TAG_TOKEN and |
944 |
wakaba |
1.1 |
$permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) { |
945 |
|
|
# permitted slash |
946 |
wakaba |
1.77 |
!!!cp (64); |
947 |
wakaba |
1.1 |
# |
948 |
|
|
} else { |
949 |
wakaba |
1.77 |
!!!cp (65); |
950 |
wakaba |
1.3 |
!!!parse-error (type => 'nestc'); |
951 |
wakaba |
1.1 |
} |
952 |
wakaba |
1.57 |
$self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
953 |
wakaba |
1.1 |
# next-input-character is already done |
954 |
|
|
redo A; |
955 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
956 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed tag'); |
957 |
wakaba |
1.1 |
$before_leave->(); |
958 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
959 |
wakaba |
1.77 |
!!!cp (66); |
960 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
961 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
962 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
963 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
964 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
965 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
966 |
wakaba |
1.77 |
!!!cp (67); |
967 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
968 |
wakaba |
1.77 |
} else { |
969 |
wakaba |
1.78 |
## NOTE: This state should never be reached. |
970 |
wakaba |
1.77 |
!!!cp (68); |
971 |
wakaba |
1.1 |
} |
972 |
|
|
} else { |
973 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
974 |
|
|
} |
975 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
976 |
wakaba |
1.1 |
# reconsume |
977 |
|
|
|
978 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
979 |
|
|
|
980 |
|
|
redo A; |
981 |
|
|
} else { |
982 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0022 or # " |
983 |
|
|
$self->{next_char} == 0x0027) { # ' |
984 |
wakaba |
1.77 |
!!!cp (69); |
985 |
wakaba |
1.72 |
!!!parse-error (type => 'bad attribute name'); |
986 |
wakaba |
1.77 |
} else { |
987 |
|
|
!!!cp (70); |
988 |
wakaba |
1.72 |
} |
989 |
wakaba |
1.76 |
$self->{current_attribute}->{name} .= chr ($self->{next_char}); |
990 |
wakaba |
1.1 |
## Stay in the state |
991 |
|
|
!!!next-input-character; |
992 |
|
|
redo A; |
993 |
|
|
} |
994 |
wakaba |
1.57 |
} elsif ($self->{state} == AFTER_ATTRIBUTE_NAME_STATE) { |
995 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0009 or # HT |
996 |
|
|
$self->{next_char} == 0x000A or # LF |
997 |
|
|
$self->{next_char} == 0x000B or # VT |
998 |
|
|
$self->{next_char} == 0x000C or # FF |
999 |
|
|
$self->{next_char} == 0x0020) { # SP |
1000 |
wakaba |
1.77 |
!!!cp (71); |
1001 |
wakaba |
1.1 |
## Stay in the state |
1002 |
|
|
!!!next-input-character; |
1003 |
|
|
redo A; |
1004 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003D) { # = |
1005 |
wakaba |
1.77 |
!!!cp (72); |
1006 |
wakaba |
1.57 |
$self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE; |
1007 |
wakaba |
1.1 |
!!!next-input-character; |
1008 |
|
|
redo A; |
1009 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
1010 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
1011 |
wakaba |
1.77 |
!!!cp (73); |
1012 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
1013 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
1014 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
1015 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
1016 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
1017 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
1018 |
wakaba |
1.77 |
!!!cp (74); |
1019 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
1020 |
wakaba |
1.77 |
} else { |
1021 |
wakaba |
1.78 |
## NOTE: This state should never be reached. |
1022 |
wakaba |
1.77 |
!!!cp (75); |
1023 |
wakaba |
1.1 |
} |
1024 |
|
|
} else { |
1025 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
1026 |
|
|
} |
1027 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1028 |
wakaba |
1.1 |
!!!next-input-character; |
1029 |
|
|
|
1030 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
1031 |
|
|
|
1032 |
|
|
redo A; |
1033 |
wakaba |
1.76 |
} elsif (0x0041 <= $self->{next_char} and |
1034 |
|
|
$self->{next_char} <= 0x005A) { # A..Z |
1035 |
wakaba |
1.77 |
!!!cp (76); |
1036 |
wakaba |
1.76 |
$self->{current_attribute} = {name => chr ($self->{next_char} + 0x0020), |
1037 |
wakaba |
1.1 |
value => ''}; |
1038 |
wakaba |
1.57 |
$self->{state} = ATTRIBUTE_NAME_STATE; |
1039 |
wakaba |
1.1 |
!!!next-input-character; |
1040 |
|
|
redo A; |
1041 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x002F) { # / |
1042 |
wakaba |
1.1 |
!!!next-input-character; |
1043 |
wakaba |
1.76 |
if ($self->{next_char} == 0x003E and # > |
1044 |
wakaba |
1.55 |
$self->{current_token}->{type} == START_TAG_TOKEN and |
1045 |
wakaba |
1.1 |
$permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) { |
1046 |
|
|
# permitted slash |
1047 |
wakaba |
1.77 |
!!!cp (77); |
1048 |
wakaba |
1.1 |
# |
1049 |
|
|
} else { |
1050 |
wakaba |
1.77 |
!!!cp (78); |
1051 |
wakaba |
1.3 |
!!!parse-error (type => 'nestc'); |
1052 |
wakaba |
1.33 |
## TODO: Different error type for <aa / bb> than <aa/> |
1053 |
wakaba |
1.1 |
} |
1054 |
wakaba |
1.57 |
$self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
1055 |
wakaba |
1.1 |
# next-input-character is already done |
1056 |
|
|
redo A; |
1057 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
1058 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed tag'); |
1059 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
1060 |
wakaba |
1.77 |
!!!cp (79); |
1061 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
1062 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
1063 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
1064 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
1065 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
1066 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
1067 |
wakaba |
1.77 |
!!!cp (80); |
1068 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
1069 |
wakaba |
1.77 |
} else { |
1070 |
wakaba |
1.78 |
## NOTE: This state should never be reached. |
1071 |
wakaba |
1.77 |
!!!cp (81); |
1072 |
wakaba |
1.1 |
} |
1073 |
|
|
} else { |
1074 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
1075 |
|
|
} |
1076 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1077 |
wakaba |
1.1 |
# reconsume |
1078 |
|
|
|
1079 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
1080 |
|
|
|
1081 |
|
|
redo A; |
1082 |
|
|
} else { |
1083 |
wakaba |
1.77 |
!!!cp (82); |
1084 |
wakaba |
1.76 |
$self->{current_attribute} = {name => chr ($self->{next_char}), |
1085 |
wakaba |
1.1 |
value => ''}; |
1086 |
wakaba |
1.57 |
$self->{state} = ATTRIBUTE_NAME_STATE; |
1087 |
wakaba |
1.1 |
!!!next-input-character; |
1088 |
|
|
redo A; |
1089 |
|
|
} |
1090 |
wakaba |
1.57 |
} elsif ($self->{state} == BEFORE_ATTRIBUTE_VALUE_STATE) { |
1091 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0009 or # HT |
1092 |
|
|
$self->{next_char} == 0x000A or # LF |
1093 |
|
|
$self->{next_char} == 0x000B or # VT |
1094 |
|
|
$self->{next_char} == 0x000C or # FF |
1095 |
|
|
$self->{next_char} == 0x0020) { # SP |
1096 |
wakaba |
1.77 |
!!!cp (83); |
1097 |
wakaba |
1.1 |
## Stay in the state |
1098 |
|
|
!!!next-input-character; |
1099 |
|
|
redo A; |
1100 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x0022) { # " |
1101 |
wakaba |
1.77 |
!!!cp (84); |
1102 |
wakaba |
1.57 |
$self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE; |
1103 |
wakaba |
1.1 |
!!!next-input-character; |
1104 |
|
|
redo A; |
1105 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x0026) { # & |
1106 |
wakaba |
1.77 |
!!!cp (85); |
1107 |
wakaba |
1.57 |
$self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE; |
1108 |
wakaba |
1.1 |
## reconsume |
1109 |
|
|
redo A; |
1110 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x0027) { # ' |
1111 |
wakaba |
1.77 |
!!!cp (86); |
1112 |
wakaba |
1.57 |
$self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE; |
1113 |
wakaba |
1.1 |
!!!next-input-character; |
1114 |
|
|
redo A; |
1115 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
1116 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
1117 |
wakaba |
1.77 |
!!!cp (87); |
1118 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
1119 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
1120 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
1121 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
1122 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
1123 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
1124 |
wakaba |
1.77 |
!!!cp (88); |
1125 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
1126 |
wakaba |
1.77 |
} else { |
1127 |
wakaba |
1.78 |
## NOTE: This state should never be reached. |
1128 |
wakaba |
1.77 |
!!!cp (89); |
1129 |
wakaba |
1.1 |
} |
1130 |
|
|
} else { |
1131 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
1132 |
|
|
} |
1133 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1134 |
wakaba |
1.1 |
!!!next-input-character; |
1135 |
|
|
|
1136 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
1137 |
|
|
|
1138 |
|
|
redo A; |
1139 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
1140 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed tag'); |
1141 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
1142 |
wakaba |
1.77 |
!!!cp (90); |
1143 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
1144 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
1145 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
1146 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
1147 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
1148 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
1149 |
wakaba |
1.77 |
!!!cp (91); |
1150 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
1151 |
wakaba |
1.77 |
} else { |
1152 |
wakaba |
1.78 |
## NOTE: This state should never be reached. |
1153 |
wakaba |
1.77 |
!!!cp (92); |
1154 |
wakaba |
1.1 |
} |
1155 |
|
|
} else { |
1156 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
1157 |
|
|
} |
1158 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1159 |
wakaba |
1.1 |
## reconsume |
1160 |
|
|
|
1161 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
1162 |
|
|
|
1163 |
|
|
redo A; |
1164 |
|
|
} else { |
1165 |
wakaba |
1.76 |
if ($self->{next_char} == 0x003D) { # = |
1166 |
wakaba |
1.77 |
!!!cp (93); |
1167 |
wakaba |
1.72 |
!!!parse-error (type => 'bad attribute value'); |
1168 |
wakaba |
1.77 |
} else { |
1169 |
|
|
!!!cp (94); |
1170 |
wakaba |
1.72 |
} |
1171 |
wakaba |
1.76 |
$self->{current_attribute}->{value} .= chr ($self->{next_char}); |
1172 |
wakaba |
1.57 |
$self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE; |
1173 |
wakaba |
1.1 |
!!!next-input-character; |
1174 |
|
|
redo A; |
1175 |
|
|
} |
1176 |
wakaba |
1.57 |
} elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) { |
1177 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0022) { # " |
1178 |
wakaba |
1.77 |
!!!cp (95); |
1179 |
wakaba |
1.72 |
$self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE; |
1180 |
wakaba |
1.1 |
!!!next-input-character; |
1181 |
|
|
redo A; |
1182 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x0026) { # & |
1183 |
wakaba |
1.77 |
!!!cp (96); |
1184 |
wakaba |
1.57 |
$self->{last_attribute_value_state} = $self->{state}; |
1185 |
|
|
$self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE; |
1186 |
wakaba |
1.1 |
!!!next-input-character; |
1187 |
|
|
redo A; |
1188 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
1189 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed attribute value'); |
1190 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
1191 |
wakaba |
1.77 |
!!!cp (97); |
1192 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
1193 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
1194 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
1195 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
1196 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
1197 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
1198 |
wakaba |
1.77 |
!!!cp (98); |
1199 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
1200 |
wakaba |
1.77 |
} else { |
1201 |
wakaba |
1.78 |
## NOTE: This state should never be reached. |
1202 |
wakaba |
1.77 |
!!!cp (99); |
1203 |
wakaba |
1.1 |
} |
1204 |
|
|
} else { |
1205 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
1206 |
|
|
} |
1207 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1208 |
wakaba |
1.1 |
## reconsume |
1209 |
|
|
|
1210 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
1211 |
|
|
|
1212 |
|
|
redo A; |
1213 |
|
|
} else { |
1214 |
wakaba |
1.77 |
!!!cp (100); |
1215 |
wakaba |
1.76 |
$self->{current_attribute}->{value} .= chr ($self->{next_char}); |
1216 |
wakaba |
1.1 |
## Stay in the state |
1217 |
|
|
!!!next-input-character; |
1218 |
|
|
redo A; |
1219 |
|
|
} |
1220 |
wakaba |
1.57 |
} elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) { |
1221 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0027) { # ' |
1222 |
wakaba |
1.77 |
!!!cp (101); |
1223 |
wakaba |
1.72 |
$self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE; |
1224 |
wakaba |
1.1 |
!!!next-input-character; |
1225 |
|
|
redo A; |
1226 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x0026) { # & |
1227 |
wakaba |
1.77 |
!!!cp (102); |
1228 |
wakaba |
1.57 |
$self->{last_attribute_value_state} = $self->{state}; |
1229 |
|
|
$self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE; |
1230 |
wakaba |
1.1 |
!!!next-input-character; |
1231 |
|
|
redo A; |
1232 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
1233 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed attribute value'); |
1234 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
1235 |
wakaba |
1.77 |
!!!cp (103); |
1236 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
1237 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
1238 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
1239 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
1240 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
1241 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
1242 |
wakaba |
1.77 |
!!!cp (104); |
1243 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
1244 |
wakaba |
1.77 |
} else { |
1245 |
wakaba |
1.78 |
## NOTE: This state should never be reached. |
1246 |
wakaba |
1.77 |
!!!cp (105); |
1247 |
wakaba |
1.1 |
} |
1248 |
|
|
} else { |
1249 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
1250 |
|
|
} |
1251 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1252 |
wakaba |
1.1 |
## reconsume |
1253 |
|
|
|
1254 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
1255 |
|
|
|
1256 |
|
|
redo A; |
1257 |
|
|
} else { |
1258 |
wakaba |
1.77 |
!!!cp (106); |
1259 |
wakaba |
1.76 |
$self->{current_attribute}->{value} .= chr ($self->{next_char}); |
1260 |
wakaba |
1.1 |
## Stay in the state |
1261 |
|
|
!!!next-input-character; |
1262 |
|
|
redo A; |
1263 |
|
|
} |
1264 |
wakaba |
1.57 |
} elsif ($self->{state} == ATTRIBUTE_VALUE_UNQUOTED_STATE) { |
1265 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0009 or # HT |
1266 |
|
|
$self->{next_char} == 0x000A or # LF |
1267 |
|
|
$self->{next_char} == 0x000B or # HT |
1268 |
|
|
$self->{next_char} == 0x000C or # FF |
1269 |
|
|
$self->{next_char} == 0x0020) { # SP |
1270 |
wakaba |
1.77 |
!!!cp (107); |
1271 |
wakaba |
1.57 |
$self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
1272 |
wakaba |
1.1 |
!!!next-input-character; |
1273 |
|
|
redo A; |
1274 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x0026) { # & |
1275 |
wakaba |
1.77 |
!!!cp (108); |
1276 |
wakaba |
1.57 |
$self->{last_attribute_value_state} = $self->{state}; |
1277 |
|
|
$self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE; |
1278 |
wakaba |
1.1 |
!!!next-input-character; |
1279 |
|
|
redo A; |
1280 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
1281 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
1282 |
wakaba |
1.77 |
!!!cp (109); |
1283 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
1284 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
1285 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
1286 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
1287 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
1288 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
1289 |
wakaba |
1.77 |
!!!cp (110); |
1290 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
1291 |
wakaba |
1.77 |
} else { |
1292 |
wakaba |
1.78 |
## NOTE: This state should never be reached. |
1293 |
wakaba |
1.77 |
!!!cp (111); |
1294 |
wakaba |
1.1 |
} |
1295 |
|
|
} else { |
1296 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
1297 |
|
|
} |
1298 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1299 |
wakaba |
1.1 |
!!!next-input-character; |
1300 |
|
|
|
1301 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
1302 |
|
|
|
1303 |
|
|
redo A; |
1304 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
1305 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed tag'); |
1306 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
1307 |
wakaba |
1.77 |
!!!cp (112); |
1308 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
1309 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
1310 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
1311 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
1312 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
1313 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
1314 |
wakaba |
1.77 |
!!!cp (113); |
1315 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
1316 |
wakaba |
1.77 |
} else { |
1317 |
wakaba |
1.78 |
## NOTE: This state should never be reached. |
1318 |
wakaba |
1.77 |
!!!cp (114); |
1319 |
wakaba |
1.1 |
} |
1320 |
|
|
} else { |
1321 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
1322 |
|
|
} |
1323 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1324 |
wakaba |
1.1 |
## reconsume |
1325 |
|
|
|
1326 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
1327 |
|
|
|
1328 |
|
|
redo A; |
1329 |
|
|
} else { |
1330 |
wakaba |
1.72 |
if ({ |
1331 |
|
|
0x0022 => 1, # " |
1332 |
|
|
0x0027 => 1, # ' |
1333 |
|
|
0x003D => 1, # = |
1334 |
wakaba |
1.76 |
}->{$self->{next_char}}) { |
1335 |
wakaba |
1.77 |
!!!cp (115); |
1336 |
wakaba |
1.72 |
!!!parse-error (type => 'bad attribute value'); |
1337 |
wakaba |
1.77 |
} else { |
1338 |
|
|
!!!cp (116); |
1339 |
wakaba |
1.72 |
} |
1340 |
wakaba |
1.76 |
$self->{current_attribute}->{value} .= chr ($self->{next_char}); |
1341 |
wakaba |
1.1 |
## Stay in the state |
1342 |
|
|
!!!next-input-character; |
1343 |
|
|
redo A; |
1344 |
|
|
} |
1345 |
wakaba |
1.57 |
} elsif ($self->{state} == ENTITY_IN_ATTRIBUTE_VALUE_STATE) { |
1346 |
wakaba |
1.72 |
my $token = $self->_tokenize_attempt_to_consume_an_entity |
1347 |
|
|
(1, |
1348 |
|
|
$self->{last_attribute_value_state} |
1349 |
|
|
== ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE ? 0x0022 : # " |
1350 |
|
|
$self->{last_attribute_value_state} |
1351 |
|
|
== ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE ? 0x0027 : # ' |
1352 |
|
|
-1); |
1353 |
wakaba |
1.1 |
|
1354 |
|
|
unless (defined $token) { |
1355 |
wakaba |
1.77 |
!!!cp (117); |
1356 |
wakaba |
1.1 |
$self->{current_attribute}->{value} .= '&'; |
1357 |
|
|
} else { |
1358 |
wakaba |
1.77 |
!!!cp (118); |
1359 |
wakaba |
1.1 |
$self->{current_attribute}->{value} .= $token->{data}; |
1360 |
wakaba |
1.66 |
$self->{current_attribute}->{has_reference} = $token->{has_reference}; |
1361 |
wakaba |
1.1 |
## ISSUE: spec says "append the returned character token to the current attribute's value" |
1362 |
|
|
} |
1363 |
|
|
|
1364 |
|
|
$self->{state} = $self->{last_attribute_value_state}; |
1365 |
|
|
# next-input-character is already done |
1366 |
|
|
redo A; |
1367 |
wakaba |
1.72 |
} elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) { |
1368 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0009 or # HT |
1369 |
|
|
$self->{next_char} == 0x000A or # LF |
1370 |
|
|
$self->{next_char} == 0x000B or # VT |
1371 |
|
|
$self->{next_char} == 0x000C or # FF |
1372 |
|
|
$self->{next_char} == 0x0020) { # SP |
1373 |
wakaba |
1.77 |
!!!cp (118); |
1374 |
wakaba |
1.72 |
$self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
1375 |
|
|
!!!next-input-character; |
1376 |
|
|
redo A; |
1377 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
1378 |
wakaba |
1.72 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
1379 |
wakaba |
1.77 |
!!!cp (119); |
1380 |
wakaba |
1.72 |
$self->{current_token}->{first_start_tag} |
1381 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
1382 |
|
|
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
1383 |
|
|
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
1384 |
|
|
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
1385 |
|
|
if ($self->{current_token}->{attributes}) { |
1386 |
wakaba |
1.77 |
!!!cp (120); |
1387 |
wakaba |
1.72 |
!!!parse-error (type => 'end tag attribute'); |
1388 |
wakaba |
1.77 |
} else { |
1389 |
wakaba |
1.78 |
## NOTE: This state should never be reached. |
1390 |
wakaba |
1.77 |
!!!cp (121); |
1391 |
wakaba |
1.72 |
} |
1392 |
|
|
} else { |
1393 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
1394 |
|
|
} |
1395 |
|
|
$self->{state} = DATA_STATE; |
1396 |
|
|
!!!next-input-character; |
1397 |
|
|
|
1398 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
1399 |
|
|
|
1400 |
|
|
redo A; |
1401 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x002F) { # / |
1402 |
wakaba |
1.72 |
!!!next-input-character; |
1403 |
wakaba |
1.76 |
if ($self->{next_char} == 0x003E and # > |
1404 |
wakaba |
1.72 |
$self->{current_token}->{type} == START_TAG_TOKEN and |
1405 |
|
|
$permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) { |
1406 |
|
|
# permitted slash |
1407 |
wakaba |
1.77 |
!!!cp (122); |
1408 |
wakaba |
1.72 |
# |
1409 |
|
|
} else { |
1410 |
wakaba |
1.77 |
!!!cp (123); |
1411 |
wakaba |
1.72 |
!!!parse-error (type => 'nestc'); |
1412 |
|
|
} |
1413 |
|
|
$self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
1414 |
|
|
# next-input-character is already done |
1415 |
|
|
redo A; |
1416 |
|
|
} else { |
1417 |
wakaba |
1.77 |
!!!cp (124); |
1418 |
wakaba |
1.72 |
!!!parse-error (type => 'no space between attributes'); |
1419 |
|
|
$self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
1420 |
|
|
## reconsume |
1421 |
|
|
redo A; |
1422 |
|
|
} |
1423 |
wakaba |
1.57 |
} elsif ($self->{state} == BOGUS_COMMENT_STATE) { |
1424 |
wakaba |
1.1 |
## (only happen if PCDATA state) |
1425 |
|
|
|
1426 |
wakaba |
1.112 |
## NOTE: Set by the previous state |
1427 |
|
|
#my $token = {type => COMMENT_TOKEN, data => ''}; |
1428 |
wakaba |
1.1 |
|
1429 |
|
|
BC: { |
1430 |
wakaba |
1.76 |
if ($self->{next_char} == 0x003E) { # > |
1431 |
wakaba |
1.77 |
!!!cp (124); |
1432 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1433 |
wakaba |
1.1 |
!!!next-input-character; |
1434 |
|
|
|
1435 |
wakaba |
1.112 |
!!!emit ($self->{current_token}); # comment |
1436 |
wakaba |
1.1 |
|
1437 |
|
|
redo A; |
1438 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
1439 |
wakaba |
1.77 |
!!!cp (125); |
1440 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1441 |
wakaba |
1.1 |
## reconsume |
1442 |
|
|
|
1443 |
wakaba |
1.112 |
!!!emit ($self->{current_token}); # comment |
1444 |
wakaba |
1.1 |
|
1445 |
|
|
redo A; |
1446 |
|
|
} else { |
1447 |
wakaba |
1.77 |
!!!cp (126); |
1448 |
wakaba |
1.112 |
$self->{current_token}->{data} .= chr ($self->{next_char}); # comment |
1449 |
wakaba |
1.1 |
!!!next-input-character; |
1450 |
|
|
redo BC; |
1451 |
|
|
} |
1452 |
|
|
} # BC |
1453 |
wakaba |
1.77 |
|
1454 |
|
|
die "$0: _get_next_token: unexpected case [BC]"; |
1455 |
wakaba |
1.57 |
} elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) { |
1456 |
wakaba |
1.1 |
## (only happen if PCDATA state) |
1457 |
|
|
|
1458 |
wakaba |
1.112 |
my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); |
1459 |
|
|
|
1460 |
wakaba |
1.1 |
my @next_char; |
1461 |
wakaba |
1.76 |
push @next_char, $self->{next_char}; |
1462 |
wakaba |
1.1 |
|
1463 |
wakaba |
1.76 |
if ($self->{next_char} == 0x002D) { # - |
1464 |
wakaba |
1.1 |
!!!next-input-character; |
1465 |
wakaba |
1.76 |
push @next_char, $self->{next_char}; |
1466 |
|
|
if ($self->{next_char} == 0x002D) { # - |
1467 |
wakaba |
1.77 |
!!!cp (127); |
1468 |
wakaba |
1.112 |
$self->{current_token} = {type => COMMENT_TOKEN, data => '', |
1469 |
|
|
line => $l, column => $c}; |
1470 |
wakaba |
1.57 |
$self->{state} = COMMENT_START_STATE; |
1471 |
wakaba |
1.1 |
!!!next-input-character; |
1472 |
|
|
redo A; |
1473 |
wakaba |
1.77 |
} else { |
1474 |
|
|
!!!cp (128); |
1475 |
wakaba |
1.1 |
} |
1476 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x0044 or # D |
1477 |
|
|
$self->{next_char} == 0x0064) { # d |
1478 |
wakaba |
1.1 |
!!!next-input-character; |
1479 |
wakaba |
1.76 |
push @next_char, $self->{next_char}; |
1480 |
|
|
if ($self->{next_char} == 0x004F or # O |
1481 |
|
|
$self->{next_char} == 0x006F) { # o |
1482 |
wakaba |
1.1 |
!!!next-input-character; |
1483 |
wakaba |
1.76 |
push @next_char, $self->{next_char}; |
1484 |
|
|
if ($self->{next_char} == 0x0043 or # C |
1485 |
|
|
$self->{next_char} == 0x0063) { # c |
1486 |
wakaba |
1.1 |
!!!next-input-character; |
1487 |
wakaba |
1.76 |
push @next_char, $self->{next_char}; |
1488 |
|
|
if ($self->{next_char} == 0x0054 or # T |
1489 |
|
|
$self->{next_char} == 0x0074) { # t |
1490 |
wakaba |
1.1 |
!!!next-input-character; |
1491 |
wakaba |
1.76 |
push @next_char, $self->{next_char}; |
1492 |
|
|
if ($self->{next_char} == 0x0059 or # Y |
1493 |
|
|
$self->{next_char} == 0x0079) { # y |
1494 |
wakaba |
1.1 |
!!!next-input-character; |
1495 |
wakaba |
1.76 |
push @next_char, $self->{next_char}; |
1496 |
|
|
if ($self->{next_char} == 0x0050 or # P |
1497 |
|
|
$self->{next_char} == 0x0070) { # p |
1498 |
wakaba |
1.1 |
!!!next-input-character; |
1499 |
wakaba |
1.76 |
push @next_char, $self->{next_char}; |
1500 |
|
|
if ($self->{next_char} == 0x0045 or # E |
1501 |
|
|
$self->{next_char} == 0x0065) { # e |
1502 |
wakaba |
1.77 |
!!!cp (129); |
1503 |
|
|
## TODO: What a stupid code this is! |
1504 |
wakaba |
1.57 |
$self->{state} = DOCTYPE_STATE; |
1505 |
wakaba |
1.112 |
$self->{current_token} = {type => DOCTYPE_TOKEN, |
1506 |
|
|
quirks => 1, |
1507 |
|
|
line => $l, column => $c}; |
1508 |
wakaba |
1.1 |
!!!next-input-character; |
1509 |
|
|
redo A; |
1510 |
wakaba |
1.77 |
} else { |
1511 |
|
|
!!!cp (130); |
1512 |
wakaba |
1.1 |
} |
1513 |
wakaba |
1.77 |
} else { |
1514 |
|
|
!!!cp (131); |
1515 |
wakaba |
1.1 |
} |
1516 |
wakaba |
1.77 |
} else { |
1517 |
|
|
!!!cp (132); |
1518 |
wakaba |
1.1 |
} |
1519 |
wakaba |
1.77 |
} else { |
1520 |
|
|
!!!cp (133); |
1521 |
wakaba |
1.1 |
} |
1522 |
wakaba |
1.77 |
} else { |
1523 |
|
|
!!!cp (134); |
1524 |
wakaba |
1.1 |
} |
1525 |
wakaba |
1.77 |
} else { |
1526 |
|
|
!!!cp (135); |
1527 |
wakaba |
1.1 |
} |
1528 |
wakaba |
1.77 |
} else { |
1529 |
|
|
!!!cp (136); |
1530 |
wakaba |
1.1 |
} |
1531 |
|
|
|
1532 |
wakaba |
1.30 |
!!!parse-error (type => 'bogus comment'); |
1533 |
wakaba |
1.76 |
$self->{next_char} = shift @next_char; |
1534 |
wakaba |
1.1 |
!!!back-next-input-character (@next_char); |
1535 |
wakaba |
1.57 |
$self->{state} = BOGUS_COMMENT_STATE; |
1536 |
wakaba |
1.112 |
$self->{current_token} = {type => COMMENT_TOKEN, data => '', |
1537 |
|
|
line => $l, column => $c}; |
1538 |
wakaba |
1.1 |
redo A; |
1539 |
|
|
|
1540 |
|
|
## ISSUE: typos in spec: chacacters, is is a parse error |
1541 |
|
|
## ISSUE: spec is somewhat unclear on "is the first character that will be in the comment"; what is "that will be in the comment" is what the algorithm defines, isn't it? |
1542 |
wakaba |
1.57 |
} elsif ($self->{state} == COMMENT_START_STATE) { |
1543 |
wakaba |
1.76 |
if ($self->{next_char} == 0x002D) { # - |
1544 |
wakaba |
1.77 |
!!!cp (137); |
1545 |
wakaba |
1.57 |
$self->{state} = COMMENT_START_DASH_STATE; |
1546 |
wakaba |
1.23 |
!!!next-input-character; |
1547 |
|
|
redo A; |
1548 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
1549 |
wakaba |
1.77 |
!!!cp (138); |
1550 |
wakaba |
1.23 |
!!!parse-error (type => 'bogus comment'); |
1551 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1552 |
wakaba |
1.23 |
!!!next-input-character; |
1553 |
|
|
|
1554 |
|
|
!!!emit ($self->{current_token}); # comment |
1555 |
|
|
|
1556 |
|
|
redo A; |
1557 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
1558 |
wakaba |
1.77 |
!!!cp (139); |
1559 |
wakaba |
1.23 |
!!!parse-error (type => 'unclosed comment'); |
1560 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1561 |
wakaba |
1.23 |
## reconsume |
1562 |
|
|
|
1563 |
|
|
!!!emit ($self->{current_token}); # comment |
1564 |
|
|
|
1565 |
|
|
redo A; |
1566 |
|
|
} else { |
1567 |
wakaba |
1.77 |
!!!cp (140); |
1568 |
wakaba |
1.23 |
$self->{current_token}->{data} # comment |
1569 |
wakaba |
1.76 |
.= chr ($self->{next_char}); |
1570 |
wakaba |
1.57 |
$self->{state} = COMMENT_STATE; |
1571 |
wakaba |
1.23 |
!!!next-input-character; |
1572 |
|
|
redo A; |
1573 |
|
|
} |
1574 |
wakaba |
1.57 |
} elsif ($self->{state} == COMMENT_START_DASH_STATE) { |
1575 |
wakaba |
1.76 |
if ($self->{next_char} == 0x002D) { # - |
1576 |
wakaba |
1.77 |
!!!cp (141); |
1577 |
wakaba |
1.57 |
$self->{state} = COMMENT_END_STATE; |
1578 |
wakaba |
1.23 |
!!!next-input-character; |
1579 |
|
|
redo A; |
1580 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
1581 |
wakaba |
1.77 |
!!!cp (142); |
1582 |
wakaba |
1.23 |
!!!parse-error (type => 'bogus comment'); |
1583 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1584 |
wakaba |
1.23 |
!!!next-input-character; |
1585 |
|
|
|
1586 |
|
|
!!!emit ($self->{current_token}); # comment |
1587 |
|
|
|
1588 |
|
|
redo A; |
1589 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
1590 |
wakaba |
1.77 |
!!!cp (143); |
1591 |
wakaba |
1.23 |
!!!parse-error (type => 'unclosed comment'); |
1592 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1593 |
wakaba |
1.23 |
## reconsume |
1594 |
|
|
|
1595 |
|
|
!!!emit ($self->{current_token}); # comment |
1596 |
|
|
|
1597 |
|
|
redo A; |
1598 |
|
|
} else { |
1599 |
wakaba |
1.77 |
!!!cp (144); |
1600 |
wakaba |
1.23 |
$self->{current_token}->{data} # comment |
1601 |
wakaba |
1.76 |
.= '-' . chr ($self->{next_char}); |
1602 |
wakaba |
1.57 |
$self->{state} = COMMENT_STATE; |
1603 |
wakaba |
1.23 |
!!!next-input-character; |
1604 |
|
|
redo A; |
1605 |
|
|
} |
1606 |
wakaba |
1.57 |
} elsif ($self->{state} == COMMENT_STATE) { |
1607 |
wakaba |
1.76 |
if ($self->{next_char} == 0x002D) { # - |
1608 |
wakaba |
1.77 |
!!!cp (145); |
1609 |
wakaba |
1.57 |
$self->{state} = COMMENT_END_DASH_STATE; |
1610 |
wakaba |
1.1 |
!!!next-input-character; |
1611 |
|
|
redo A; |
1612 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
1613 |
wakaba |
1.77 |
!!!cp (146); |
1614 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed comment'); |
1615 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1616 |
wakaba |
1.1 |
## reconsume |
1617 |
|
|
|
1618 |
|
|
!!!emit ($self->{current_token}); # comment |
1619 |
|
|
|
1620 |
|
|
redo A; |
1621 |
|
|
} else { |
1622 |
wakaba |
1.77 |
!!!cp (147); |
1623 |
wakaba |
1.76 |
$self->{current_token}->{data} .= chr ($self->{next_char}); # comment |
1624 |
wakaba |
1.1 |
## Stay in the state |
1625 |
|
|
!!!next-input-character; |
1626 |
|
|
redo A; |
1627 |
|
|
} |
1628 |
wakaba |
1.57 |
} elsif ($self->{state} == COMMENT_END_DASH_STATE) { |
1629 |
wakaba |
1.76 |
if ($self->{next_char} == 0x002D) { # - |
1630 |
wakaba |
1.77 |
!!!cp (148); |
1631 |
wakaba |
1.57 |
$self->{state} = COMMENT_END_STATE; |
1632 |
wakaba |
1.1 |
!!!next-input-character; |
1633 |
|
|
redo A; |
1634 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
1635 |
wakaba |
1.77 |
!!!cp (149); |
1636 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed comment'); |
1637 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1638 |
wakaba |
1.1 |
## reconsume |
1639 |
|
|
|
1640 |
|
|
!!!emit ($self->{current_token}); # comment |
1641 |
|
|
|
1642 |
|
|
redo A; |
1643 |
|
|
} else { |
1644 |
wakaba |
1.77 |
!!!cp (150); |
1645 |
wakaba |
1.76 |
$self->{current_token}->{data} .= '-' . chr ($self->{next_char}); # comment |
1646 |
wakaba |
1.57 |
$self->{state} = COMMENT_STATE; |
1647 |
wakaba |
1.1 |
!!!next-input-character; |
1648 |
|
|
redo A; |
1649 |
|
|
} |
1650 |
wakaba |
1.57 |
} elsif ($self->{state} == COMMENT_END_STATE) { |
1651 |
wakaba |
1.76 |
if ($self->{next_char} == 0x003E) { # > |
1652 |
wakaba |
1.77 |
!!!cp (151); |
1653 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1654 |
wakaba |
1.1 |
!!!next-input-character; |
1655 |
|
|
|
1656 |
|
|
!!!emit ($self->{current_token}); # comment |
1657 |
|
|
|
1658 |
|
|
redo A; |
1659 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x002D) { # - |
1660 |
wakaba |
1.77 |
!!!cp (152); |
1661 |
wakaba |
1.114 |
!!!parse-error (type => 'dash in comment', |
1662 |
|
|
line => $self->{line_prev}, |
1663 |
|
|
column => $self->{column_prev}); |
1664 |
wakaba |
1.1 |
$self->{current_token}->{data} .= '-'; # comment |
1665 |
|
|
## Stay in the state |
1666 |
|
|
!!!next-input-character; |
1667 |
|
|
redo A; |
1668 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
1669 |
wakaba |
1.77 |
!!!cp (153); |
1670 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed comment'); |
1671 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1672 |
wakaba |
1.1 |
## reconsume |
1673 |
|
|
|
1674 |
|
|
!!!emit ($self->{current_token}); # comment |
1675 |
|
|
|
1676 |
|
|
redo A; |
1677 |
|
|
} else { |
1678 |
wakaba |
1.77 |
!!!cp (154); |
1679 |
wakaba |
1.114 |
!!!parse-error (type => 'dash in comment', |
1680 |
|
|
line => $self->{line_prev}, |
1681 |
|
|
column => $self->{column_prev}); |
1682 |
wakaba |
1.76 |
$self->{current_token}->{data} .= '--' . chr ($self->{next_char}); # comment |
1683 |
wakaba |
1.57 |
$self->{state} = COMMENT_STATE; |
1684 |
wakaba |
1.1 |
!!!next-input-character; |
1685 |
|
|
redo A; |
1686 |
|
|
} |
1687 |
wakaba |
1.57 |
} elsif ($self->{state} == DOCTYPE_STATE) { |
1688 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0009 or # HT |
1689 |
|
|
$self->{next_char} == 0x000A or # LF |
1690 |
|
|
$self->{next_char} == 0x000B or # VT |
1691 |
|
|
$self->{next_char} == 0x000C or # FF |
1692 |
|
|
$self->{next_char} == 0x0020) { # SP |
1693 |
wakaba |
1.77 |
!!!cp (155); |
1694 |
wakaba |
1.57 |
$self->{state} = BEFORE_DOCTYPE_NAME_STATE; |
1695 |
wakaba |
1.1 |
!!!next-input-character; |
1696 |
|
|
redo A; |
1697 |
|
|
} else { |
1698 |
wakaba |
1.77 |
!!!cp (156); |
1699 |
wakaba |
1.3 |
!!!parse-error (type => 'no space before DOCTYPE name'); |
1700 |
wakaba |
1.57 |
$self->{state} = BEFORE_DOCTYPE_NAME_STATE; |
1701 |
wakaba |
1.1 |
## reconsume |
1702 |
|
|
redo A; |
1703 |
|
|
} |
1704 |
wakaba |
1.57 |
} elsif ($self->{state} == BEFORE_DOCTYPE_NAME_STATE) { |
1705 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0009 or # HT |
1706 |
|
|
$self->{next_char} == 0x000A or # LF |
1707 |
|
|
$self->{next_char} == 0x000B or # VT |
1708 |
|
|
$self->{next_char} == 0x000C or # FF |
1709 |
|
|
$self->{next_char} == 0x0020) { # SP |
1710 |
wakaba |
1.77 |
!!!cp (157); |
1711 |
wakaba |
1.1 |
## Stay in the state |
1712 |
|
|
!!!next-input-character; |
1713 |
|
|
redo A; |
1714 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
1715 |
wakaba |
1.77 |
!!!cp (158); |
1716 |
wakaba |
1.3 |
!!!parse-error (type => 'no DOCTYPE name'); |
1717 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1718 |
wakaba |
1.1 |
!!!next-input-character; |
1719 |
|
|
|
1720 |
wakaba |
1.112 |
!!!emit ($self->{current_token}); # DOCTYPE (quirks) |
1721 |
wakaba |
1.1 |
|
1722 |
|
|
redo A; |
1723 |
wakaba |
1.77 |
} elsif ($self->{next_char} == -1) { |
1724 |
|
|
!!!cp (159); |
1725 |
wakaba |
1.3 |
!!!parse-error (type => 'no DOCTYPE name'); |
1726 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1727 |
wakaba |
1.1 |
## reconsume |
1728 |
|
|
|
1729 |
wakaba |
1.112 |
!!!emit ($self->{current_token}); # DOCTYPE (quirks) |
1730 |
wakaba |
1.1 |
|
1731 |
|
|
redo A; |
1732 |
|
|
} else { |
1733 |
wakaba |
1.77 |
!!!cp (160); |
1734 |
wakaba |
1.112 |
$self->{current_token}->{name} = chr $self->{next_char}; |
1735 |
|
|
delete $self->{current_token}->{quirks}; |
1736 |
wakaba |
1.4 |
## ISSUE: "Set the token's name name to the" in the spec |
1737 |
wakaba |
1.57 |
$self->{state} = DOCTYPE_NAME_STATE; |
1738 |
wakaba |
1.1 |
!!!next-input-character; |
1739 |
|
|
redo A; |
1740 |
|
|
} |
1741 |
wakaba |
1.57 |
} elsif ($self->{state} == DOCTYPE_NAME_STATE) { |
1742 |
wakaba |
1.18 |
## ISSUE: Redundant "First," in the spec. |
1743 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0009 or # HT |
1744 |
|
|
$self->{next_char} == 0x000A or # LF |
1745 |
|
|
$self->{next_char} == 0x000B or # VT |
1746 |
|
|
$self->{next_char} == 0x000C or # FF |
1747 |
|
|
$self->{next_char} == 0x0020) { # SP |
1748 |
wakaba |
1.77 |
!!!cp (161); |
1749 |
wakaba |
1.57 |
$self->{state} = AFTER_DOCTYPE_NAME_STATE; |
1750 |
wakaba |
1.1 |
!!!next-input-character; |
1751 |
|
|
redo A; |
1752 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
1753 |
wakaba |
1.77 |
!!!cp (162); |
1754 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1755 |
wakaba |
1.1 |
!!!next-input-character; |
1756 |
|
|
|
1757 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1758 |
|
|
|
1759 |
|
|
redo A; |
1760 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
1761 |
wakaba |
1.77 |
!!!cp (163); |
1762 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed DOCTYPE'); |
1763 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1764 |
wakaba |
1.1 |
## reconsume |
1765 |
|
|
|
1766 |
wakaba |
1.75 |
$self->{current_token}->{quirks} = 1; |
1767 |
wakaba |
1.18 |
!!!emit ($self->{current_token}); # DOCTYPE |
1768 |
wakaba |
1.1 |
|
1769 |
|
|
redo A; |
1770 |
|
|
} else { |
1771 |
wakaba |
1.77 |
!!!cp (164); |
1772 |
wakaba |
1.1 |
$self->{current_token}->{name} |
1773 |
wakaba |
1.76 |
.= chr ($self->{next_char}); # DOCTYPE |
1774 |
wakaba |
1.1 |
## Stay in the state |
1775 |
|
|
!!!next-input-character; |
1776 |
|
|
redo A; |
1777 |
|
|
} |
1778 |
wakaba |
1.57 |
} elsif ($self->{state} == AFTER_DOCTYPE_NAME_STATE) { |
1779 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0009 or # HT |
1780 |
|
|
$self->{next_char} == 0x000A or # LF |
1781 |
|
|
$self->{next_char} == 0x000B or # VT |
1782 |
|
|
$self->{next_char} == 0x000C or # FF |
1783 |
|
|
$self->{next_char} == 0x0020) { # SP |
1784 |
wakaba |
1.77 |
!!!cp (165); |
1785 |
wakaba |
1.1 |
## Stay in the state |
1786 |
|
|
!!!next-input-character; |
1787 |
|
|
redo A; |
1788 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
1789 |
wakaba |
1.77 |
!!!cp (166); |
1790 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1791 |
wakaba |
1.1 |
!!!next-input-character; |
1792 |
|
|
|
1793 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1794 |
|
|
|
1795 |
|
|
redo A; |
1796 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
1797 |
wakaba |
1.77 |
!!!cp (167); |
1798 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed DOCTYPE'); |
1799 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1800 |
wakaba |
1.1 |
## reconsume |
1801 |
|
|
|
1802 |
wakaba |
1.75 |
$self->{current_token}->{quirks} = 1; |
1803 |
wakaba |
1.18 |
!!!emit ($self->{current_token}); # DOCTYPE |
1804 |
|
|
|
1805 |
|
|
redo A; |
1806 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x0050 or # P |
1807 |
|
|
$self->{next_char} == 0x0070) { # p |
1808 |
wakaba |
1.18 |
!!!next-input-character; |
1809 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0055 or # U |
1810 |
|
|
$self->{next_char} == 0x0075) { # u |
1811 |
wakaba |
1.18 |
!!!next-input-character; |
1812 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0042 or # B |
1813 |
|
|
$self->{next_char} == 0x0062) { # b |
1814 |
wakaba |
1.18 |
!!!next-input-character; |
1815 |
wakaba |
1.76 |
if ($self->{next_char} == 0x004C or # L |
1816 |
|
|
$self->{next_char} == 0x006C) { # l |
1817 |
wakaba |
1.18 |
!!!next-input-character; |
1818 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0049 or # I |
1819 |
|
|
$self->{next_char} == 0x0069) { # i |
1820 |
wakaba |
1.18 |
!!!next-input-character; |
1821 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0043 or # C |
1822 |
|
|
$self->{next_char} == 0x0063) { # c |
1823 |
wakaba |
1.77 |
!!!cp (168); |
1824 |
wakaba |
1.57 |
$self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE; |
1825 |
wakaba |
1.18 |
!!!next-input-character; |
1826 |
|
|
redo A; |
1827 |
wakaba |
1.77 |
} else { |
1828 |
|
|
!!!cp (169); |
1829 |
wakaba |
1.18 |
} |
1830 |
wakaba |
1.77 |
} else { |
1831 |
|
|
!!!cp (170); |
1832 |
wakaba |
1.18 |
} |
1833 |
wakaba |
1.77 |
} else { |
1834 |
|
|
!!!cp (171); |
1835 |
wakaba |
1.18 |
} |
1836 |
wakaba |
1.77 |
} else { |
1837 |
|
|
!!!cp (172); |
1838 |
wakaba |
1.18 |
} |
1839 |
wakaba |
1.77 |
} else { |
1840 |
|
|
!!!cp (173); |
1841 |
wakaba |
1.18 |
} |
1842 |
|
|
|
1843 |
|
|
# |
1844 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x0053 or # S |
1845 |
|
|
$self->{next_char} == 0x0073) { # s |
1846 |
wakaba |
1.18 |
!!!next-input-character; |
1847 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0059 or # Y |
1848 |
|
|
$self->{next_char} == 0x0079) { # y |
1849 |
wakaba |
1.18 |
!!!next-input-character; |
1850 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0053 or # S |
1851 |
|
|
$self->{next_char} == 0x0073) { # s |
1852 |
wakaba |
1.18 |
!!!next-input-character; |
1853 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0054 or # T |
1854 |
|
|
$self->{next_char} == 0x0074) { # t |
1855 |
wakaba |
1.18 |
!!!next-input-character; |
1856 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0045 or # E |
1857 |
|
|
$self->{next_char} == 0x0065) { # e |
1858 |
wakaba |
1.18 |
!!!next-input-character; |
1859 |
wakaba |
1.76 |
if ($self->{next_char} == 0x004D or # M |
1860 |
|
|
$self->{next_char} == 0x006D) { # m |
1861 |
wakaba |
1.77 |
!!!cp (174); |
1862 |
wakaba |
1.57 |
$self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE; |
1863 |
wakaba |
1.18 |
!!!next-input-character; |
1864 |
|
|
redo A; |
1865 |
wakaba |
1.77 |
} else { |
1866 |
|
|
!!!cp (175); |
1867 |
wakaba |
1.18 |
} |
1868 |
wakaba |
1.77 |
} else { |
1869 |
|
|
!!!cp (176); |
1870 |
wakaba |
1.18 |
} |
1871 |
wakaba |
1.77 |
} else { |
1872 |
|
|
!!!cp (177); |
1873 |
wakaba |
1.18 |
} |
1874 |
wakaba |
1.77 |
} else { |
1875 |
|
|
!!!cp (178); |
1876 |
wakaba |
1.18 |
} |
1877 |
wakaba |
1.77 |
} else { |
1878 |
|
|
!!!cp (179); |
1879 |
wakaba |
1.18 |
} |
1880 |
|
|
|
1881 |
|
|
# |
1882 |
|
|
} else { |
1883 |
wakaba |
1.77 |
!!!cp (180); |
1884 |
wakaba |
1.18 |
!!!next-input-character; |
1885 |
|
|
# |
1886 |
|
|
} |
1887 |
|
|
|
1888 |
|
|
!!!parse-error (type => 'string after DOCTYPE name'); |
1889 |
wakaba |
1.75 |
$self->{current_token}->{quirks} = 1; |
1890 |
wakaba |
1.73 |
|
1891 |
wakaba |
1.57 |
$self->{state} = BOGUS_DOCTYPE_STATE; |
1892 |
wakaba |
1.18 |
# next-input-character is already done |
1893 |
|
|
redo A; |
1894 |
wakaba |
1.57 |
} elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) { |
1895 |
wakaba |
1.18 |
if ({ |
1896 |
|
|
0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, |
1897 |
|
|
#0x000D => 1, # HT, LF, VT, FF, SP, CR |
1898 |
wakaba |
1.76 |
}->{$self->{next_char}}) { |
1899 |
wakaba |
1.77 |
!!!cp (181); |
1900 |
wakaba |
1.18 |
## Stay in the state |
1901 |
|
|
!!!next-input-character; |
1902 |
|
|
redo A; |
1903 |
wakaba |
1.76 |
} elsif ($self->{next_char} eq 0x0022) { # " |
1904 |
wakaba |
1.77 |
!!!cp (182); |
1905 |
wakaba |
1.18 |
$self->{current_token}->{public_identifier} = ''; # DOCTYPE |
1906 |
wakaba |
1.57 |
$self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE; |
1907 |
wakaba |
1.18 |
!!!next-input-character; |
1908 |
|
|
redo A; |
1909 |
wakaba |
1.76 |
} elsif ($self->{next_char} eq 0x0027) { # ' |
1910 |
wakaba |
1.77 |
!!!cp (183); |
1911 |
wakaba |
1.18 |
$self->{current_token}->{public_identifier} = ''; # DOCTYPE |
1912 |
wakaba |
1.57 |
$self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE; |
1913 |
wakaba |
1.18 |
!!!next-input-character; |
1914 |
|
|
redo A; |
1915 |
wakaba |
1.76 |
} elsif ($self->{next_char} eq 0x003E) { # > |
1916 |
wakaba |
1.77 |
!!!cp (184); |
1917 |
wakaba |
1.18 |
!!!parse-error (type => 'no PUBLIC literal'); |
1918 |
|
|
|
1919 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1920 |
wakaba |
1.18 |
!!!next-input-character; |
1921 |
|
|
|
1922 |
wakaba |
1.75 |
$self->{current_token}->{quirks} = 1; |
1923 |
wakaba |
1.18 |
!!!emit ($self->{current_token}); # DOCTYPE |
1924 |
|
|
|
1925 |
|
|
redo A; |
1926 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
1927 |
wakaba |
1.77 |
!!!cp (185); |
1928 |
wakaba |
1.18 |
!!!parse-error (type => 'unclosed DOCTYPE'); |
1929 |
|
|
|
1930 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1931 |
wakaba |
1.18 |
## reconsume |
1932 |
|
|
|
1933 |
wakaba |
1.75 |
$self->{current_token}->{quirks} = 1; |
1934 |
wakaba |
1.18 |
!!!emit ($self->{current_token}); # DOCTYPE |
1935 |
|
|
|
1936 |
|
|
redo A; |
1937 |
|
|
} else { |
1938 |
wakaba |
1.77 |
!!!cp (186); |
1939 |
wakaba |
1.18 |
!!!parse-error (type => 'string after PUBLIC'); |
1940 |
wakaba |
1.75 |
$self->{current_token}->{quirks} = 1; |
1941 |
wakaba |
1.73 |
|
1942 |
wakaba |
1.57 |
$self->{state} = BOGUS_DOCTYPE_STATE; |
1943 |
wakaba |
1.18 |
!!!next-input-character; |
1944 |
|
|
redo A; |
1945 |
|
|
} |
1946 |
wakaba |
1.57 |
} elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE) { |
1947 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0022) { # " |
1948 |
wakaba |
1.77 |
!!!cp (187); |
1949 |
wakaba |
1.57 |
$self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE; |
1950 |
wakaba |
1.18 |
!!!next-input-character; |
1951 |
|
|
redo A; |
1952 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
1953 |
wakaba |
1.77 |
!!!cp (188); |
1954 |
wakaba |
1.69 |
!!!parse-error (type => 'unclosed PUBLIC literal'); |
1955 |
|
|
|
1956 |
|
|
$self->{state} = DATA_STATE; |
1957 |
|
|
!!!next-input-character; |
1958 |
|
|
|
1959 |
wakaba |
1.75 |
$self->{current_token}->{quirks} = 1; |
1960 |
wakaba |
1.69 |
!!!emit ($self->{current_token}); # DOCTYPE |
1961 |
|
|
|
1962 |
|
|
redo A; |
1963 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
1964 |
wakaba |
1.77 |
!!!cp (189); |
1965 |
wakaba |
1.18 |
!!!parse-error (type => 'unclosed PUBLIC literal'); |
1966 |
|
|
|
1967 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1968 |
wakaba |
1.18 |
## reconsume |
1969 |
|
|
|
1970 |
wakaba |
1.75 |
$self->{current_token}->{quirks} = 1; |
1971 |
wakaba |
1.18 |
!!!emit ($self->{current_token}); # DOCTYPE |
1972 |
|
|
|
1973 |
|
|
redo A; |
1974 |
|
|
} else { |
1975 |
wakaba |
1.77 |
!!!cp (190); |
1976 |
wakaba |
1.18 |
$self->{current_token}->{public_identifier} # DOCTYPE |
1977 |
wakaba |
1.76 |
.= chr $self->{next_char}; |
1978 |
wakaba |
1.18 |
## Stay in the state |
1979 |
|
|
!!!next-input-character; |
1980 |
|
|
redo A; |
1981 |
|
|
} |
1982 |
wakaba |
1.57 |
} elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE) { |
1983 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0027) { # ' |
1984 |
wakaba |
1.77 |
!!!cp (191); |
1985 |
wakaba |
1.57 |
$self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE; |
1986 |
wakaba |
1.18 |
!!!next-input-character; |
1987 |
|
|
redo A; |
1988 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
1989 |
wakaba |
1.77 |
!!!cp (192); |
1990 |
wakaba |
1.69 |
!!!parse-error (type => 'unclosed PUBLIC literal'); |
1991 |
|
|
|
1992 |
|
|
$self->{state} = DATA_STATE; |
1993 |
|
|
!!!next-input-character; |
1994 |
|
|
|
1995 |
wakaba |
1.75 |
$self->{current_token}->{quirks} = 1; |
1996 |
wakaba |
1.69 |
!!!emit ($self->{current_token}); # DOCTYPE |
1997 |
|
|
|
1998 |
|
|
redo A; |
1999 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
2000 |
wakaba |
1.77 |
!!!cp (193); |
2001 |
wakaba |
1.18 |
!!!parse-error (type => 'unclosed PUBLIC literal'); |
2002 |
|
|
|
2003 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
2004 |
wakaba |
1.18 |
## reconsume |
2005 |
|
|
|
2006 |
wakaba |
1.75 |
$self->{current_token}->{quirks} = 1; |
2007 |
wakaba |
1.18 |
!!!emit ($self->{current_token}); # DOCTYPE |
2008 |
|
|
|
2009 |
|
|
redo A; |
2010 |
|
|
} else { |
2011 |
wakaba |
1.77 |
!!!cp (194); |
2012 |
wakaba |
1.18 |
$self->{current_token}->{public_identifier} # DOCTYPE |
2013 |
wakaba |
1.76 |
.= chr $self->{next_char}; |
2014 |
wakaba |
1.18 |
## Stay in the state |
2015 |
|
|
!!!next-input-character; |
2016 |
|
|
redo A; |
2017 |
|
|
} |
2018 |
wakaba |
1.57 |
} elsif ($self->{state} == AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE) { |
2019 |
wakaba |
1.18 |
if ({ |
2020 |
|
|
0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, |
2021 |
|
|
#0x000D => 1, # HT, LF, VT, FF, SP, CR |
2022 |
wakaba |
1.76 |
}->{$self->{next_char}}) { |
2023 |
wakaba |
1.77 |
!!!cp (195); |
2024 |
wakaba |
1.18 |
## Stay in the state |
2025 |
|
|
!!!next-input-character; |
2026 |
|
|
redo A; |
2027 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x0022) { # " |
2028 |
wakaba |
1.77 |
!!!cp (196); |
2029 |
wakaba |
1.18 |
$self->{current_token}->{system_identifier} = ''; # DOCTYPE |
2030 |
wakaba |
1.57 |
$self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE; |
2031 |
wakaba |
1.18 |
!!!next-input-character; |
2032 |
|
|
redo A; |
2033 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x0027) { # ' |
2034 |
wakaba |
1.77 |
!!!cp (197); |
2035 |
wakaba |
1.18 |
$self->{current_token}->{system_identifier} = ''; # DOCTYPE |
2036 |
wakaba |
1.57 |
$self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE; |
2037 |
wakaba |
1.18 |
!!!next-input-character; |
2038 |
|
|
redo A; |
2039 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
2040 |
wakaba |
1.77 |
!!!cp (198); |
2041 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
2042 |
wakaba |
1.18 |
!!!next-input-character; |
2043 |
|
|
|
2044 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
2045 |
|
|
|
2046 |
|
|
redo A; |
2047 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
2048 |
wakaba |
1.77 |
!!!cp (199); |
2049 |
wakaba |
1.18 |
!!!parse-error (type => 'unclosed DOCTYPE'); |
2050 |
|
|
|
2051 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
2052 |
wakaba |
1.26 |
## reconsume |
2053 |
wakaba |
1.18 |
|
2054 |
wakaba |
1.75 |
$self->{current_token}->{quirks} = 1; |
2055 |
wakaba |
1.18 |
!!!emit ($self->{current_token}); # DOCTYPE |
2056 |
|
|
|
2057 |
|
|
redo A; |
2058 |
|
|
} else { |
2059 |
wakaba |
1.77 |
!!!cp (200); |
2060 |
wakaba |
1.18 |
!!!parse-error (type => 'string after PUBLIC literal'); |
2061 |
wakaba |
1.75 |
$self->{current_token}->{quirks} = 1; |
2062 |
wakaba |
1.73 |
|
2063 |
wakaba |
1.57 |
$self->{state} = BOGUS_DOCTYPE_STATE; |
2064 |
wakaba |
1.18 |
!!!next-input-character; |
2065 |
|
|
redo A; |
2066 |
|
|
} |
2067 |
wakaba |
1.57 |
} elsif ($self->{state} == BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE) { |
2068 |
wakaba |
1.18 |
if ({ |
2069 |
|
|
0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, |
2070 |
|
|
#0x000D => 1, # HT, LF, VT, FF, SP, CR |
2071 |
wakaba |
1.76 |
}->{$self->{next_char}}) { |
2072 |
wakaba |
1.77 |
!!!cp (201); |
2073 |
wakaba |
1.18 |
## Stay in the state |
2074 |
|
|
!!!next-input-character; |
2075 |
|
|
redo A; |
2076 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x0022) { # " |
2077 |
wakaba |
1.77 |
!!!cp (202); |
2078 |
wakaba |
1.18 |
$self->{current_token}->{system_identifier} = ''; # DOCTYPE |
2079 |
wakaba |
1.57 |
$self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE; |
2080 |
wakaba |
1.18 |
!!!next-input-character; |
2081 |
|
|
redo A; |
2082 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x0027) { # ' |
2083 |
wakaba |
1.77 |
!!!cp (203); |
2084 |
wakaba |
1.18 |
$self->{current_token}->{system_identifier} = ''; # DOCTYPE |
2085 |
wakaba |
1.57 |
$self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE; |
2086 |
wakaba |
1.18 |
!!!next-input-character; |
2087 |
|
|
redo A; |
2088 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
2089 |
wakaba |
1.77 |
!!!cp (204); |
2090 |
wakaba |
1.18 |
!!!parse-error (type => 'no SYSTEM literal'); |
2091 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
2092 |
wakaba |
1.18 |
!!!next-input-character; |
2093 |
|
|
|
2094 |
wakaba |
1.75 |
$self->{current_token}->{quirks} = 1; |
2095 |
wakaba |
1.18 |
!!!emit ($self->{current_token}); # DOCTYPE |
2096 |
|
|
|
2097 |
|
|
redo A; |
2098 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
2099 |
wakaba |
1.77 |
!!!cp (205); |
2100 |
wakaba |
1.18 |
!!!parse-error (type => 'unclosed DOCTYPE'); |
2101 |
|
|
|
2102 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
2103 |
wakaba |
1.26 |
## reconsume |
2104 |
wakaba |
1.18 |
|
2105 |
wakaba |
1.75 |
$self->{current_token}->{quirks} = 1; |
2106 |
wakaba |
1.18 |
!!!emit ($self->{current_token}); # DOCTYPE |
2107 |
|
|
|
2108 |
|
|
redo A; |
2109 |
|
|
} else { |
2110 |
wakaba |
1.77 |
!!!cp (206); |
2111 |
wakaba |
1.30 |
!!!parse-error (type => 'string after SYSTEM'); |
2112 |
wakaba |
1.75 |
$self->{current_token}->{quirks} = 1; |
2113 |
wakaba |
1.73 |
|
2114 |
wakaba |
1.57 |
$self->{state} = BOGUS_DOCTYPE_STATE; |
2115 |
wakaba |
1.18 |
!!!next-input-character; |
2116 |
|
|
redo A; |
2117 |
|
|
} |
2118 |
wakaba |
1.57 |
} elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE) { |
2119 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0022) { # " |
2120 |
wakaba |
1.77 |
!!!cp (207); |
2121 |
wakaba |
1.57 |
$self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE; |
2122 |
wakaba |
1.18 |
!!!next-input-character; |
2123 |
|
|
redo A; |
2124 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
2125 |
wakaba |
1.77 |
!!!cp (208); |
2126 |
wakaba |
1.69 |
!!!parse-error (type => 'unclosed PUBLIC literal'); |
2127 |
|
|
|
2128 |
|
|
$self->{state} = DATA_STATE; |
2129 |
|
|
!!!next-input-character; |
2130 |
|
|
|
2131 |
wakaba |
1.75 |
$self->{current_token}->{quirks} = 1; |
2132 |
wakaba |
1.69 |
!!!emit ($self->{current_token}); # DOCTYPE |
2133 |
|
|
|
2134 |
|
|
redo A; |
2135 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
2136 |
wakaba |
1.77 |
!!!cp (209); |
2137 |
wakaba |
1.18 |
!!!parse-error (type => 'unclosed SYSTEM literal'); |
2138 |
|
|
|
2139 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
2140 |
wakaba |
1.18 |
## reconsume |
2141 |
|
|
|
2142 |
wakaba |
1.75 |
$self->{current_token}->{quirks} = 1; |
2143 |
wakaba |
1.18 |
!!!emit ($self->{current_token}); # DOCTYPE |
2144 |
|
|
|
2145 |
|
|
redo A; |
2146 |
|
|
} else { |
2147 |
wakaba |
1.77 |
!!!cp (210); |
2148 |
wakaba |
1.18 |
$self->{current_token}->{system_identifier} # DOCTYPE |
2149 |
wakaba |
1.76 |
.= chr $self->{next_char}; |
2150 |
wakaba |
1.18 |
## Stay in the state |
2151 |
|
|
!!!next-input-character; |
2152 |
|
|
redo A; |
2153 |
|
|
} |
2154 |
wakaba |
1.57 |
} elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE) { |
2155 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0027) { # ' |
2156 |
wakaba |
1.77 |
!!!cp (211); |
2157 |
wakaba |
1.57 |
$self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE; |
2158 |
wakaba |
1.18 |
!!!next-input-character; |
2159 |
|
|
redo A; |
2160 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
2161 |
wakaba |
1.77 |
!!!cp (212); |
2162 |
wakaba |
1.69 |
!!!parse-error (type => 'unclosed PUBLIC literal'); |
2163 |
|
|
|
2164 |
|
|
$self->{state} = DATA_STATE; |
2165 |
|
|
!!!next-input-character; |
2166 |
|
|
|
2167 |
wakaba |
1.75 |
$self->{current_token}->{quirks} = 1; |
2168 |
wakaba |
1.69 |
!!!emit ($self->{current_token}); # DOCTYPE |
2169 |
|
|
|
2170 |
|
|
redo A; |
2171 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
2172 |
wakaba |
1.77 |
!!!cp (213); |
2173 |
wakaba |
1.18 |
!!!parse-error (type => 'unclosed SYSTEM literal'); |
2174 |
|
|
|
2175 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
2176 |
wakaba |
1.18 |
## reconsume |
2177 |
|
|
|
2178 |
wakaba |
1.75 |
$self->{current_token}->{quirks} = 1; |
2179 |
wakaba |
1.1 |
!!!emit ($self->{current_token}); # DOCTYPE |
2180 |
|
|
|
2181 |
|
|
redo A; |
2182 |
|
|
} else { |
2183 |
wakaba |
1.77 |
!!!cp (214); |
2184 |
wakaba |
1.18 |
$self->{current_token}->{system_identifier} # DOCTYPE |
2185 |
wakaba |
1.76 |
.= chr $self->{next_char}; |
2186 |
wakaba |
1.18 |
## Stay in the state |
2187 |
|
|
!!!next-input-character; |
2188 |
|
|
redo A; |
2189 |
|
|
} |
2190 |
wakaba |
1.57 |
} elsif ($self->{state} == AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE) { |
2191 |
wakaba |
1.18 |
if ({ |
2192 |
|
|
0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, |
2193 |
|
|
#0x000D => 1, # HT, LF, VT, FF, SP, CR |
2194 |
wakaba |
1.76 |
}->{$self->{next_char}}) { |
2195 |
wakaba |
1.77 |
!!!cp (215); |
2196 |
wakaba |
1.18 |
## Stay in the state |
2197 |
|
|
!!!next-input-character; |
2198 |
|
|
redo A; |
2199 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003E) { # > |
2200 |
wakaba |
1.77 |
!!!cp (216); |
2201 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
2202 |
wakaba |
1.18 |
!!!next-input-character; |
2203 |
|
|
|
2204 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
2205 |
|
|
|
2206 |
|
|
redo A; |
2207 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
2208 |
wakaba |
1.77 |
!!!cp (217); |
2209 |
wakaba |
1.18 |
!!!parse-error (type => 'unclosed DOCTYPE'); |
2210 |
|
|
|
2211 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
2212 |
wakaba |
1.26 |
## reconsume |
2213 |
wakaba |
1.18 |
|
2214 |
wakaba |
1.75 |
$self->{current_token}->{quirks} = 1; |
2215 |
wakaba |
1.18 |
!!!emit ($self->{current_token}); # DOCTYPE |
2216 |
|
|
|
2217 |
|
|
redo A; |
2218 |
|
|
} else { |
2219 |
wakaba |
1.77 |
!!!cp (218); |
2220 |
wakaba |
1.18 |
!!!parse-error (type => 'string after SYSTEM literal'); |
2221 |
wakaba |
1.75 |
#$self->{current_token}->{quirks} = 1; |
2222 |
wakaba |
1.73 |
|
2223 |
wakaba |
1.57 |
$self->{state} = BOGUS_DOCTYPE_STATE; |
2224 |
wakaba |
1.1 |
!!!next-input-character; |
2225 |
|
|
redo A; |
2226 |
|
|
} |
2227 |
wakaba |
1.57 |
} elsif ($self->{state} == BOGUS_DOCTYPE_STATE) { |
2228 |
wakaba |
1.76 |
if ($self->{next_char} == 0x003E) { # > |
2229 |
wakaba |
1.77 |
!!!cp (219); |
2230 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
2231 |
wakaba |
1.1 |
!!!next-input-character; |
2232 |
|
|
|
2233 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
2234 |
|
|
|
2235 |
|
|
redo A; |
2236 |
wakaba |
1.76 |
} elsif ($self->{next_char} == -1) { |
2237 |
wakaba |
1.77 |
!!!cp (220); |
2238 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed DOCTYPE'); |
2239 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
2240 |
wakaba |
1.1 |
## reconsume |
2241 |
|
|
|
2242 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
2243 |
|
|
|
2244 |
|
|
redo A; |
2245 |
|
|
} else { |
2246 |
wakaba |
1.77 |
!!!cp (221); |
2247 |
wakaba |
1.1 |
## Stay in the state |
2248 |
|
|
!!!next-input-character; |
2249 |
|
|
redo A; |
2250 |
|
|
} |
2251 |
|
|
} else { |
2252 |
|
|
die "$0: $self->{state}: Unknown state"; |
2253 |
|
|
} |
2254 |
|
|
} # A |
2255 |
|
|
|
2256 |
|
|
die "$0: _get_next_token: unexpected case"; |
2257 |
|
|
} # _get_next_token |
2258 |
|
|
|
2259 |
wakaba |
1.72 |
sub _tokenize_attempt_to_consume_an_entity ($$$) { |
2260 |
|
|
my ($self, $in_attr, $additional) = @_; |
2261 |
wakaba |
1.20 |
|
2262 |
wakaba |
1.112 |
my ($l, $c) = ($self->{line_prev}, $self->{column_prev}); |
2263 |
|
|
|
2264 |
wakaba |
1.20 |
if ({ |
2265 |
|
|
0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF, |
2266 |
|
|
0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR |
2267 |
wakaba |
1.72 |
$additional => 1, |
2268 |
wakaba |
1.76 |
}->{$self->{next_char}}) { |
2269 |
wakaba |
1.78 |
!!!cp (1001); |
2270 |
wakaba |
1.20 |
## Don't consume |
2271 |
|
|
## No error |
2272 |
|
|
return undef; |
2273 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x0023) { # # |
2274 |
wakaba |
1.1 |
!!!next-input-character; |
2275 |
wakaba |
1.76 |
if ($self->{next_char} == 0x0078 or # x |
2276 |
|
|
$self->{next_char} == 0x0058) { # X |
2277 |
wakaba |
1.26 |
my $code; |
2278 |
wakaba |
1.1 |
X: { |
2279 |
wakaba |
1.76 |
my $x_char = $self->{next_char}; |
2280 |
wakaba |
1.1 |
!!!next-input-character; |
2281 |
wakaba |
1.76 |
if (0x0030 <= $self->{next_char} and |
2282 |
|
|
$self->{next_char} <= 0x0039) { # 0..9 |
2283 |
wakaba |
1.78 |
!!!cp (1002); |
2284 |
wakaba |
1.26 |
$code ||= 0; |
2285 |
|
|
$code *= 0x10; |
2286 |
wakaba |
1.76 |
$code += $self->{next_char} - 0x0030; |
2287 |
wakaba |
1.1 |
redo X; |
2288 |
wakaba |
1.76 |
} elsif (0x0061 <= $self->{next_char} and |
2289 |
|
|
$self->{next_char} <= 0x0066) { # a..f |
2290 |
wakaba |
1.78 |
!!!cp (1003); |
2291 |
wakaba |
1.26 |
$code ||= 0; |
2292 |
|
|
$code *= 0x10; |
2293 |
wakaba |
1.76 |
$code += $self->{next_char} - 0x0060 + 9; |
2294 |
wakaba |
1.1 |
redo X; |
2295 |
wakaba |
1.76 |
} elsif (0x0041 <= $self->{next_char} and |
2296 |
|
|
$self->{next_char} <= 0x0046) { # A..F |
2297 |
wakaba |
1.78 |
!!!cp (1004); |
2298 |
wakaba |
1.26 |
$code ||= 0; |
2299 |
|
|
$code *= 0x10; |
2300 |
wakaba |
1.76 |
$code += $self->{next_char} - 0x0040 + 9; |
2301 |
wakaba |
1.1 |
redo X; |
2302 |
wakaba |
1.26 |
} elsif (not defined $code) { # no hexadecimal digit |
2303 |
wakaba |
1.78 |
!!!cp (1005); |
2304 |
wakaba |
1.112 |
!!!parse-error (type => 'bare hcro', line => $l, column => $c); |
2305 |
wakaba |
1.76 |
!!!back-next-input-character ($x_char, $self->{next_char}); |
2306 |
|
|
$self->{next_char} = 0x0023; # # |
2307 |
wakaba |
1.1 |
return undef; |
2308 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x003B) { # ; |
2309 |
wakaba |
1.78 |
!!!cp (1006); |
2310 |
wakaba |
1.1 |
!!!next-input-character; |
2311 |
|
|
} else { |
2312 |
wakaba |
1.78 |
!!!cp (1007); |
2313 |
wakaba |
1.112 |
!!!parse-error (type => 'no refc', line => $l, column => $c); |
2314 |
wakaba |
1.1 |
} |
2315 |
|
|
|
2316 |
wakaba |
1.26 |
if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) { |
2317 |
wakaba |
1.78 |
!!!cp (1008); |
2318 |
wakaba |
1.112 |
!!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c); |
2319 |
wakaba |
1.26 |
$code = 0xFFFD; |
2320 |
|
|
} elsif ($code > 0x10FFFF) { |
2321 |
wakaba |
1.78 |
!!!cp (1009); |
2322 |
wakaba |
1.112 |
!!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c); |
2323 |
wakaba |
1.26 |
$code = 0xFFFD; |
2324 |
|
|
} elsif ($code == 0x000D) { |
2325 |
wakaba |
1.78 |
!!!cp (1010); |
2326 |
wakaba |
1.112 |
!!!parse-error (type => 'CR character reference', line => $l, column => $c); |
2327 |
wakaba |
1.26 |
$code = 0x000A; |
2328 |
|
|
} elsif (0x80 <= $code and $code <= 0x9F) { |
2329 |
wakaba |
1.78 |
!!!cp (1011); |
2330 |
wakaba |
1.112 |
!!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c); |
2331 |
wakaba |
1.26 |
$code = $c1_entity_char->{$code}; |
2332 |
wakaba |
1.1 |
} |
2333 |
|
|
|
2334 |
wakaba |
1.66 |
return {type => CHARACTER_TOKEN, data => chr $code, |
2335 |
wakaba |
1.112 |
has_reference => 1, line => $l, column => $c}; |
2336 |
wakaba |
1.1 |
} # X |
2337 |
wakaba |
1.76 |
} elsif (0x0030 <= $self->{next_char} and |
2338 |
|
|
$self->{next_char} <= 0x0039) { # 0..9 |
2339 |
|
|
my $code = $self->{next_char} - 0x0030; |
2340 |
wakaba |
1.1 |
!!!next-input-character; |
2341 |
|
|
|
2342 |
wakaba |
1.76 |
while (0x0030 <= $self->{next_char} and |
2343 |
|
|
$self->{next_char} <= 0x0039) { # 0..9 |
2344 |
wakaba |
1.78 |
!!!cp (1012); |
2345 |
wakaba |
1.1 |
$code *= 10; |
2346 |
wakaba |
1.76 |
$code += $self->{next_char} - 0x0030; |
2347 |
wakaba |
1.1 |
|
2348 |
|
|
!!!next-input-character; |
2349 |
|
|
} |
2350 |
|
|
|
2351 |
wakaba |
1.76 |
if ($self->{next_char} == 0x003B) { # ; |
2352 |
wakaba |
1.78 |
!!!cp (1013); |
2353 |
wakaba |
1.1 |
!!!next-input-character; |
2354 |
|
|
} else { |
2355 |
wakaba |
1.78 |
!!!cp (1014); |
2356 |
wakaba |
1.112 |
!!!parse-error (type => 'no refc', line => $l, column => $c); |
2357 |
wakaba |
1.1 |
} |
2358 |
|
|
|
2359 |
wakaba |
1.26 |
if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) { |
2360 |
wakaba |
1.78 |
!!!cp (1015); |
2361 |
wakaba |
1.112 |
!!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c); |
2362 |
wakaba |
1.26 |
$code = 0xFFFD; |
2363 |
|
|
} elsif ($code > 0x10FFFF) { |
2364 |
wakaba |
1.78 |
!!!cp (1016); |
2365 |
wakaba |
1.112 |
!!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c); |
2366 |
wakaba |
1.26 |
$code = 0xFFFD; |
2367 |
|
|
} elsif ($code == 0x000D) { |
2368 |
wakaba |
1.78 |
!!!cp (1017); |
2369 |
wakaba |
1.112 |
!!!parse-error (type => 'CR character reference', line => $l, column => $c); |
2370 |
wakaba |
1.26 |
$code = 0x000A; |
2371 |
wakaba |
1.4 |
} elsif (0x80 <= $code and $code <= 0x9F) { |
2372 |
wakaba |
1.78 |
!!!cp (1018); |
2373 |
wakaba |
1.112 |
!!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c); |
2374 |
wakaba |
1.4 |
$code = $c1_entity_char->{$code}; |
2375 |
wakaba |
1.1 |
} |
2376 |
|
|
|
2377 |
wakaba |
1.112 |
return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1, |
2378 |
|
|
line => $l, column => $c}; |
2379 |
wakaba |
1.1 |
} else { |
2380 |
wakaba |
1.78 |
!!!cp (1019); |
2381 |
wakaba |
1.112 |
!!!parse-error (type => 'bare nero', line => $l, column => $c); |
2382 |
wakaba |
1.76 |
!!!back-next-input-character ($self->{next_char}); |
2383 |
|
|
$self->{next_char} = 0x0023; # # |
2384 |
wakaba |
1.1 |
return undef; |
2385 |
|
|
} |
2386 |
wakaba |
1.76 |
} elsif ((0x0041 <= $self->{next_char} and |
2387 |
|
|
$self->{next_char} <= 0x005A) or |
2388 |
|
|
(0x0061 <= $self->{next_char} and |
2389 |
|
|
$self->{next_char} <= 0x007A)) { |
2390 |
|
|
my $entity_name = chr $self->{next_char}; |
2391 |
wakaba |
1.1 |
!!!next-input-character; |
2392 |
|
|
|
2393 |
|
|
my $value = $entity_name; |
2394 |
wakaba |
1.37 |
my $match = 0; |
2395 |
wakaba |
1.16 |
require Whatpm::_NamedEntityList; |
2396 |
|
|
our $EntityChar; |
2397 |
wakaba |
1.1 |
|
2398 |
|
|
while (length $entity_name < 10 and |
2399 |
|
|
## NOTE: Some number greater than the maximum length of entity name |
2400 |
wakaba |
1.76 |
((0x0041 <= $self->{next_char} and # a |
2401 |
|
|
$self->{next_char} <= 0x005A) or # x |
2402 |
|
|
(0x0061 <= $self->{next_char} and # a |
2403 |
|
|
$self->{next_char} <= 0x007A) or # z |
2404 |
|
|
(0x0030 <= $self->{next_char} and # 0 |
2405 |
|
|
$self->{next_char} <= 0x0039) or # 9 |
2406 |
|
|
$self->{next_char} == 0x003B)) { # ; |
2407 |
|
|
$entity_name .= chr $self->{next_char}; |
2408 |
wakaba |
1.16 |
if (defined $EntityChar->{$entity_name}) { |
2409 |
wakaba |
1.76 |
if ($self->{next_char} == 0x003B) { # ; |
2410 |
wakaba |
1.78 |
!!!cp (1020); |
2411 |
wakaba |
1.26 |
$value = $EntityChar->{$entity_name}; |
2412 |
wakaba |
1.16 |
$match = 1; |
2413 |
|
|
!!!next-input-character; |
2414 |
|
|
last; |
2415 |
wakaba |
1.37 |
} else { |
2416 |
wakaba |
1.78 |
!!!cp (1021); |
2417 |
wakaba |
1.26 |
$value = $EntityChar->{$entity_name}; |
2418 |
|
|
$match = -1; |
2419 |
wakaba |
1.37 |
!!!next-input-character; |
2420 |
wakaba |
1.16 |
} |
2421 |
wakaba |
1.1 |
} else { |
2422 |
wakaba |
1.78 |
!!!cp (1022); |
2423 |
wakaba |
1.76 |
$value .= chr $self->{next_char}; |
2424 |
wakaba |
1.37 |
$match *= 2; |
2425 |
|
|
!!!next-input-character; |
2426 |
wakaba |
1.1 |
} |
2427 |
|
|
} |
2428 |
|
|
|
2429 |
wakaba |
1.16 |
if ($match > 0) { |
2430 |
wakaba |
1.78 |
!!!cp (1023); |
2431 |
wakaba |
1.112 |
return {type => CHARACTER_TOKEN, data => $value, has_reference => 1, |
2432 |
|
|
line => $l, column => $c}; |
2433 |
wakaba |
1.16 |
} elsif ($match < 0) { |
2434 |
wakaba |
1.112 |
!!!parse-error (type => 'no refc', line => $l, column => $c); |
2435 |
wakaba |
1.37 |
if ($in_attr and $match < -1) { |
2436 |
wakaba |
1.78 |
!!!cp (1024); |
2437 |
wakaba |
1.112 |
return {type => CHARACTER_TOKEN, data => '&'.$entity_name, |
2438 |
|
|
line => $l, column => $c}; |
2439 |
wakaba |
1.37 |
} else { |
2440 |
wakaba |
1.78 |
!!!cp (1025); |
2441 |
wakaba |
1.112 |
return {type => CHARACTER_TOKEN, data => $value, has_reference => 1, |
2442 |
|
|
line => $l, column => $c}; |
2443 |
wakaba |
1.37 |
} |
2444 |
wakaba |
1.1 |
} else { |
2445 |
wakaba |
1.78 |
!!!cp (1026); |
2446 |
wakaba |
1.112 |
!!!parse-error (type => 'bare ero', line => $l, column => $c); |
2447 |
wakaba |
1.66 |
## NOTE: "No characters are consumed" in the spec. |
2448 |
wakaba |
1.112 |
return {type => CHARACTER_TOKEN, data => '&'.$value, |
2449 |
|
|
line => $l, column => $c}; |
2450 |
wakaba |
1.1 |
} |
2451 |
|
|
} else { |
2452 |
wakaba |
1.78 |
!!!cp (1027); |
2453 |
wakaba |
1.1 |
## no characters are consumed |
2454 |
wakaba |
1.112 |
!!!parse-error (type => 'bare ero', line => $l, column => $c); |
2455 |
wakaba |
1.1 |
return undef; |
2456 |
|
|
} |
2457 |
|
|
} # _tokenize_attempt_to_consume_an_entity |
2458 |
|
|
|
2459 |
|
|
sub _initialize_tree_constructor ($) { |
2460 |
|
|
my $self = shift; |
2461 |
|
|
## NOTE: $self->{document} MUST be specified before this method is called |
2462 |
|
|
$self->{document}->strict_error_checking (0); |
2463 |
|
|
## TODO: Turn mutation events off # MUST |
2464 |
|
|
## TODO: Turn loose Document option (manakai extension) on |
2465 |
wakaba |
1.18 |
$self->{document}->manakai_is_html (1); # MUST |
2466 |
wakaba |
1.1 |
} # _initialize_tree_constructor |
2467 |
|
|
|
2468 |
|
|
sub _terminate_tree_constructor ($) { |
2469 |
|
|
my $self = shift; |
2470 |
|
|
$self->{document}->strict_error_checking (1); |
2471 |
|
|
## TODO: Turn mutation events on |
2472 |
|
|
} # _terminate_tree_constructor |
2473 |
|
|
|
2474 |
|
|
## ISSUE: Should append_child (for example) in script executed in tree construction stage fire mutation events? |
2475 |
|
|
|
2476 |
wakaba |
1.3 |
{ # tree construction stage |
2477 |
|
|
my $token; |
2478 |
|
|
|
2479 |
wakaba |
1.1 |
sub _construct_tree ($) { |
2480 |
|
|
my ($self) = @_; |
2481 |
|
|
|
2482 |
|
|
## When an interactive UA render the $self->{document} available |
2483 |
|
|
## to the user, or when it begin accepting user input, are |
2484 |
|
|
## not defined. |
2485 |
|
|
|
2486 |
|
|
## Append a character: collect it and all subsequent consecutive |
2487 |
|
|
## characters and insert one Text node whose data is concatenation |
2488 |
|
|
## of all those characters. # MUST |
2489 |
|
|
|
2490 |
|
|
!!!next-token; |
2491 |
|
|
|
2492 |
wakaba |
1.3 |
undef $self->{form_element}; |
2493 |
|
|
undef $self->{head_element}; |
2494 |
|
|
$self->{open_elements} = []; |
2495 |
|
|
undef $self->{inner_html_node}; |
2496 |
|
|
|
2497 |
wakaba |
1.84 |
## NOTE: The "initial" insertion mode. |
2498 |
wakaba |
1.3 |
$self->_tree_construction_initial; # MUST |
2499 |
wakaba |
1.84 |
|
2500 |
|
|
## NOTE: The "before html" insertion mode. |
2501 |
wakaba |
1.3 |
$self->_tree_construction_root_element; |
2502 |
wakaba |
1.84 |
$self->{insertion_mode} = BEFORE_HEAD_IM; |
2503 |
|
|
|
2504 |
|
|
## NOTE: The "before head" insertion mode and so on. |
2505 |
wakaba |
1.3 |
$self->_tree_construction_main; |
2506 |
|
|
} # _construct_tree |
2507 |
|
|
|
2508 |
|
|
sub _tree_construction_initial ($) { |
2509 |
|
|
my $self = shift; |
2510 |
wakaba |
1.84 |
|
2511 |
|
|
## NOTE: "initial" insertion mode |
2512 |
|
|
|
2513 |
wakaba |
1.18 |
INITIAL: { |
2514 |
wakaba |
1.55 |
if ($token->{type} == DOCTYPE_TOKEN) { |
2515 |
wakaba |
1.18 |
## NOTE: Conformance checkers MAY, instead of reporting "not HTML5" |
2516 |
|
|
## error, switch to a conformance checking mode for another |
2517 |
|
|
## language. |
2518 |
|
|
my $doctype_name = $token->{name}; |
2519 |
|
|
$doctype_name = '' unless defined $doctype_name; |
2520 |
|
|
$doctype_name =~ tr/a-z/A-Z/; |
2521 |
|
|
if (not defined $token->{name} or # <!DOCTYPE> |
2522 |
|
|
defined $token->{public_identifier} or |
2523 |
|
|
defined $token->{system_identifier}) { |
2524 |
wakaba |
1.79 |
!!!cp ('t1'); |
2525 |
wakaba |
1.113 |
!!!parse-error (type => 'not HTML5', token => $token); |
2526 |
wakaba |
1.18 |
} elsif ($doctype_name ne 'HTML') { |
2527 |
wakaba |
1.79 |
!!!cp ('t2'); |
2528 |
wakaba |
1.18 |
## ISSUE: ASCII case-insensitive? (in fact it does not matter) |
2529 |
wakaba |
1.113 |
!!!parse-error (type => 'not HTML5', token => $token); |
2530 |
wakaba |
1.79 |
} else { |
2531 |
|
|
!!!cp ('t3'); |
2532 |
wakaba |
1.18 |
} |
2533 |
|
|
|
2534 |
|
|
my $doctype = $self->{document}->create_document_type_definition |
2535 |
|
|
($token->{name}); ## ISSUE: If name is missing (e.g. <!DOCTYPE>)? |
2536 |
|
|
$doctype->public_id ($token->{public_identifier}) |
2537 |
|
|
if defined $token->{public_identifier}; |
2538 |
|
|
$doctype->system_id ($token->{system_identifier}) |
2539 |
|
|
if defined $token->{system_identifier}; |
2540 |
|
|
## NOTE: Other DocumentType attributes are null or empty lists. |
2541 |
|
|
## ISSUE: internalSubset = null?? |
2542 |
|
|
$self->{document}->append_child ($doctype); |
2543 |
|
|
|
2544 |
wakaba |
1.75 |
if ($token->{quirks} or $doctype_name ne 'HTML') { |
2545 |
wakaba |
1.79 |
!!!cp ('t4'); |
2546 |
wakaba |
1.18 |
$self->{document}->manakai_compat_mode ('quirks'); |
2547 |
|
|
} elsif (defined $token->{public_identifier}) { |
2548 |
|
|
my $pubid = $token->{public_identifier}; |
2549 |
|
|
$pubid =~ tr/a-z/A-z/; |
2550 |
|
|
if ({ |
2551 |
|
|
"+//SILMARIL//DTD HTML PRO V0R11 19970101//EN" => 1, |
2552 |
|
|
"-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1, |
2553 |
|
|
"-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1, |
2554 |
|
|
"-//IETF//DTD HTML 2.0 LEVEL 1//EN" => 1, |
2555 |
|
|
"-//IETF//DTD HTML 2.0 LEVEL 2//EN" => 1, |
2556 |
|
|
"-//IETF//DTD HTML 2.0 STRICT LEVEL 1//EN" => 1, |
2557 |
|
|
"-//IETF//DTD HTML 2.0 STRICT LEVEL 2//EN" => 1, |
2558 |
|
|
"-//IETF//DTD HTML 2.0 STRICT//EN" => 1, |
2559 |
|
|
"-//IETF//DTD HTML 2.0//EN" => 1, |
2560 |
|
|
"-//IETF//DTD HTML 2.1E//EN" => 1, |
2561 |
|
|
"-//IETF//DTD HTML 3.0//EN" => 1, |
2562 |
|
|
"-//IETF//DTD HTML 3.0//EN//" => 1, |
2563 |
|
|
"-//IETF//DTD HTML 3.2 FINAL//EN" => 1, |
2564 |
|
|
"-//IETF//DTD HTML 3.2//EN" => 1, |
2565 |
|
|
"-//IETF//DTD HTML 3//EN" => 1, |
2566 |
|
|
"-//IETF//DTD HTML LEVEL 0//EN" => 1, |
2567 |
|
|
"-//IETF//DTD HTML LEVEL 0//EN//2.0" => 1, |
2568 |
|
|
"-//IETF//DTD HTML LEVEL 1//EN" => 1, |
2569 |
|
|
"-//IETF//DTD HTML LEVEL 1//EN//2.0" => 1, |
2570 |
|
|
"-//IETF//DTD HTML LEVEL 2//EN" => 1, |
2571 |
|
|
"-//IETF//DTD HTML LEVEL 2//EN//2.0" => 1, |
2572 |
|
|
"-//IETF//DTD HTML LEVEL 3//EN" => 1, |
2573 |
|
|
"-//IETF//DTD HTML LEVEL 3//EN//3.0" => 1, |
2574 |
|
|
"-//IETF//DTD HTML STRICT LEVEL 0//EN" => 1, |
2575 |
|
|
"-//IETF//DTD HTML STRICT LEVEL 0//EN//2.0" => 1, |
2576 |
|
|
"-//IETF//DTD HTML STRICT LEVEL 1//EN" => 1, |
2577 |
|
|
"-//IETF//DTD HTML STRICT LEVEL 1//EN//2.0" => 1, |
2578 |
|
|
"-//IETF//DTD HTML STRICT LEVEL 2//EN" => 1, |
2579 |
|
|
"-//IETF//DTD HTML STRICT LEVEL 2//EN//2.0" => 1, |
2580 |
|
|
"-//IETF//DTD HTML STRICT LEVEL 3//EN" => 1, |
2581 |
|
|
"-//IETF//DTD HTML STRICT LEVEL 3//EN//3.0" => 1, |
2582 |
|
|
"-//IETF//DTD HTML STRICT//EN" => 1, |
2583 |
|
|
"-//IETF//DTD HTML STRICT//EN//2.0" => 1, |
2584 |
|
|
"-//IETF//DTD HTML STRICT//EN//3.0" => 1, |
2585 |
|
|
"-//IETF//DTD HTML//EN" => 1, |
2586 |
|
|
"-//IETF//DTD HTML//EN//2.0" => 1, |
2587 |
|
|
"-//IETF//DTD HTML//EN//3.0" => 1, |
2588 |
|
|
"-//METRIUS//DTD METRIUS PRESENTATIONAL//EN" => 1, |
2589 |
|
|
"-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//EN" => 1, |
2590 |
|
|
"-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//EN" => 1, |
2591 |
|
|
"-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//EN" => 1, |
2592 |
|
|
"-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//EN" => 1, |
2593 |
|
|
"-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//EN" => 1, |
2594 |
|
|
"-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//EN" => 1, |
2595 |
|
|
"-//NETSCAPE COMM. CORP.//DTD HTML//EN" => 1, |
2596 |
|
|
"-//NETSCAPE COMM. CORP.//DTD STRICT HTML//EN" => 1, |
2597 |
|
|
"-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//EN" => 1, |
2598 |
|
|
"-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//EN" => 1, |
2599 |
wakaba |
1.72 |
"-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//EN" => 1, |
2600 |
|
|
"-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//EN" => 1, |
2601 |
|
|
"-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//EN" => 1, |
2602 |
wakaba |
1.18 |
"-//SPYGLASS//DTD HTML 2.0 EXTENDED//EN" => 1, |
2603 |
|
|
"-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//EN" => 1, |
2604 |
|
|
"-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//EN" => 1, |
2605 |
|
|
"-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//EN" => 1, |
2606 |
|
|
"-//W3C//DTD HTML 3 1995-03-24//EN" => 1, |
2607 |
|
|
"-//W3C//DTD HTML 3.2 DRAFT//EN" => 1, |
2608 |
|
|
"-//W3C//DTD HTML 3.2 FINAL//EN" => 1, |
2609 |
|
|
"-//W3C//DTD HTML 3.2//EN" => 1, |
2610 |
|
|
"-//W3C//DTD HTML 3.2S DRAFT//EN" => 1, |
2611 |
|
|
"-//W3C//DTD HTML 4.0 FRAMESET//EN" => 1, |
2612 |
|
|
"-//W3C//DTD HTML 4.0 TRANSITIONAL//EN" => 1, |
2613 |
|
|
"-//W3C//DTD HTML EXPERIMETNAL 19960712//EN" => 1, |
2614 |
|
|
"-//W3C//DTD HTML EXPERIMENTAL 970421//EN" => 1, |
2615 |
|
|
"-//W3C//DTD W3 HTML//EN" => 1, |
2616 |
|
|
"-//W3O//DTD W3 HTML 3.0//EN" => 1, |
2617 |
|
|
"-//W3O//DTD W3 HTML 3.0//EN//" => 1, |
2618 |
|
|
"-//W3O//DTD W3 HTML STRICT 3.0//EN//" => 1, |
2619 |
|
|
"-//WEBTECHS//DTD MOZILLA HTML 2.0//EN" => 1, |
2620 |
|
|
"-//WEBTECHS//DTD MOZILLA HTML//EN" => 1, |
2621 |
|
|
"-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" => 1, |
2622 |
|
|
"HTML" => 1, |
2623 |
|
|
}->{$pubid}) { |
2624 |
wakaba |
1.79 |
!!!cp ('t5'); |
2625 |
wakaba |
1.18 |
$self->{document}->manakai_compat_mode ('quirks'); |
2626 |
|
|
} elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or |
2627 |
|
|
$pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") { |
2628 |
|
|
if (defined $token->{system_identifier}) { |
2629 |
wakaba |
1.79 |
!!!cp ('t6'); |
2630 |
wakaba |
1.18 |
$self->{document}->manakai_compat_mode ('quirks'); |
2631 |
|
|
} else { |
2632 |
wakaba |
1.79 |
!!!cp ('t7'); |
2633 |
wakaba |
1.18 |
$self->{document}->manakai_compat_mode ('limited quirks'); |
2634 |
wakaba |
1.3 |
} |
2635 |
wakaba |
1.80 |
} elsif ($pubid eq "-//W3C//DTD XHTML 1.0 FRAMESET//EN" or |
2636 |
|
|
$pubid eq "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN") { |
2637 |
wakaba |
1.79 |
!!!cp ('t8'); |
2638 |
wakaba |
1.18 |
$self->{document}->manakai_compat_mode ('limited quirks'); |
2639 |
wakaba |
1.79 |
} else { |
2640 |
|
|
!!!cp ('t9'); |
2641 |
wakaba |
1.18 |
} |
2642 |
wakaba |
1.79 |
} else { |
2643 |
|
|
!!!cp ('t10'); |
2644 |
wakaba |
1.18 |
} |
2645 |
|
|
if (defined $token->{system_identifier}) { |
2646 |
|
|
my $sysid = $token->{system_identifier}; |
2647 |
|
|
$sysid =~ tr/A-Z/a-z/; |
2648 |
|
|
if ($sysid eq "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") { |
2649 |
wakaba |
1.80 |
## TODO: Check the spec: PUBLIC "(limited quirks)" "(quirks)" |
2650 |
wakaba |
1.18 |
$self->{document}->manakai_compat_mode ('quirks'); |
2651 |
wakaba |
1.79 |
!!!cp ('t11'); |
2652 |
|
|
} else { |
2653 |
|
|
!!!cp ('t12'); |
2654 |
wakaba |
1.18 |
} |
2655 |
wakaba |
1.79 |
} else { |
2656 |
|
|
!!!cp ('t13'); |
2657 |
wakaba |
1.18 |
} |
2658 |
|
|
|
2659 |
wakaba |
1.84 |
## Go to the "before html" insertion mode. |
2660 |
wakaba |
1.18 |
!!!next-token; |
2661 |
|
|
return; |
2662 |
|
|
} elsif ({ |
2663 |
wakaba |
1.55 |
START_TAG_TOKEN, 1, |
2664 |
|
|
END_TAG_TOKEN, 1, |
2665 |
|
|
END_OF_FILE_TOKEN, 1, |
2666 |
wakaba |
1.18 |
}->{$token->{type}}) { |
2667 |
wakaba |
1.79 |
!!!cp ('t14'); |
2668 |
wakaba |
1.113 |
!!!parse-error (type => 'no DOCTYPE', token => $token); |
2669 |
wakaba |
1.18 |
$self->{document}->manakai_compat_mode ('quirks'); |
2670 |
wakaba |
1.84 |
## Go to the "before html" insertion mode. |
2671 |
wakaba |
1.18 |
## reprocess |
2672 |
|
|
return; |
2673 |
wakaba |
1.55 |
} elsif ($token->{type} == CHARACTER_TOKEN) { |
2674 |
wakaba |
1.18 |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D |
2675 |
|
|
## Ignore the token |
2676 |
wakaba |
1.26 |
|
2677 |
wakaba |
1.18 |
unless (length $token->{data}) { |
2678 |
wakaba |
1.79 |
!!!cp ('t15'); |
2679 |
wakaba |
1.84 |
## Stay in the insertion mode. |
2680 |
wakaba |
1.18 |
!!!next-token; |
2681 |
|
|
redo INITIAL; |
2682 |
wakaba |
1.79 |
} else { |
2683 |
|
|
!!!cp ('t16'); |
2684 |
wakaba |
1.3 |
} |
2685 |
wakaba |
1.79 |
} else { |
2686 |
|
|
!!!cp ('t17'); |
2687 |
wakaba |
1.3 |
} |
2688 |
wakaba |
1.18 |
|
2689 |
wakaba |
1.113 |
!!!parse-error (type => 'no DOCTYPE', token => $token); |
2690 |
wakaba |
1.18 |
$self->{document}->manakai_compat_mode ('quirks'); |
2691 |
wakaba |
1.84 |
## Go to the "before html" insertion mode. |
2692 |
wakaba |
1.18 |
## reprocess |
2693 |
|
|
return; |
2694 |
wakaba |
1.55 |
} elsif ($token->{type} == COMMENT_TOKEN) { |
2695 |
wakaba |
1.79 |
!!!cp ('t18'); |
2696 |
wakaba |
1.18 |
my $comment = $self->{document}->create_comment ($token->{data}); |
2697 |
|
|
$self->{document}->append_child ($comment); |
2698 |
|
|
|
2699 |
wakaba |
1.84 |
## Stay in the insertion mode. |
2700 |
wakaba |
1.18 |
!!!next-token; |
2701 |
|
|
redo INITIAL; |
2702 |
|
|
} else { |
2703 |
wakaba |
1.55 |
die "$0: $token->{type}: Unknown token type"; |
2704 |
wakaba |
1.18 |
} |
2705 |
|
|
} # INITIAL |
2706 |
wakaba |
1.79 |
|
2707 |
|
|
die "$0: _tree_construction_initial: This should be never reached"; |
2708 |
wakaba |
1.3 |
} # _tree_construction_initial |
2709 |
|
|
|
2710 |
|
|
sub _tree_construction_root_element ($) { |
2711 |
|
|
my $self = shift; |
2712 |
wakaba |
1.84 |
|
2713 |
|
|
## NOTE: "before html" insertion mode. |
2714 |
wakaba |
1.3 |
|
2715 |
|
|
B: { |
2716 |
wakaba |
1.55 |
if ($token->{type} == DOCTYPE_TOKEN) { |
2717 |
wakaba |
1.79 |
!!!cp ('t19'); |
2718 |
wakaba |
1.113 |
!!!parse-error (type => 'in html:#DOCTYPE', token => $token); |
2719 |
wakaba |
1.3 |
## Ignore the token |
2720 |
wakaba |
1.84 |
## Stay in the insertion mode. |
2721 |
wakaba |
1.3 |
!!!next-token; |
2722 |
|
|
redo B; |
2723 |
wakaba |
1.55 |
} elsif ($token->{type} == COMMENT_TOKEN) { |
2724 |
wakaba |
1.79 |
!!!cp ('t20'); |
2725 |
wakaba |
1.3 |
my $comment = $self->{document}->create_comment ($token->{data}); |
2726 |
|
|
$self->{document}->append_child ($comment); |
2727 |
wakaba |
1.84 |
## Stay in the insertion mode. |
2728 |
wakaba |
1.3 |
!!!next-token; |
2729 |
|
|
redo B; |
2730 |
wakaba |
1.55 |
} elsif ($token->{type} == CHARACTER_TOKEN) { |
2731 |
wakaba |
1.26 |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D |
2732 |
|
|
## Ignore the token. |
2733 |
|
|
|
2734 |
wakaba |
1.3 |
unless (length $token->{data}) { |
2735 |
wakaba |
1.79 |
!!!cp ('t21'); |
2736 |
wakaba |
1.84 |
## Stay in the insertion mode. |
2737 |
wakaba |
1.3 |
!!!next-token; |
2738 |
|
|
redo B; |
2739 |
wakaba |
1.79 |
} else { |
2740 |
|
|
!!!cp ('t22'); |
2741 |
wakaba |
1.3 |
} |
2742 |
wakaba |
1.79 |
} else { |
2743 |
|
|
!!!cp ('t23'); |
2744 |
wakaba |
1.3 |
} |
2745 |
wakaba |
1.61 |
|
2746 |
|
|
$self->{application_cache_selection}->(undef); |
2747 |
|
|
|
2748 |
|
|
# |
2749 |
|
|
} elsif ($token->{type} == START_TAG_TOKEN) { |
2750 |
wakaba |
1.84 |
if ($token->{tag_name} eq 'html') { |
2751 |
|
|
my $root_element; |
2752 |
|
|
!!!create-element ($root_element, $token->{tag_name}, $token->{attributes}); |
2753 |
|
|
$self->{document}->append_child ($root_element); |
2754 |
|
|
push @{$self->{open_elements}}, [$root_element, 'html']; |
2755 |
|
|
|
2756 |
|
|
if ($token->{attributes}->{manifest}) { |
2757 |
|
|
!!!cp ('t24'); |
2758 |
|
|
$self->{application_cache_selection} |
2759 |
|
|
->($token->{attributes}->{manifest}->{value}); |
2760 |
|
|
## ISSUE: No relative reference resolution? |
2761 |
|
|
} else { |
2762 |
|
|
!!!cp ('t25'); |
2763 |
|
|
$self->{application_cache_selection}->(undef); |
2764 |
|
|
} |
2765 |
|
|
|
2766 |
|
|
!!!next-token; |
2767 |
|
|
return; ## Go to the "before head" insertion mode. |
2768 |
wakaba |
1.61 |
} else { |
2769 |
wakaba |
1.84 |
!!!cp ('t25.1'); |
2770 |
|
|
# |
2771 |
wakaba |
1.61 |
} |
2772 |
wakaba |
1.3 |
} elsif ({ |
2773 |
wakaba |
1.55 |
END_TAG_TOKEN, 1, |
2774 |
|
|
END_OF_FILE_TOKEN, 1, |
2775 |
wakaba |
1.3 |
}->{$token->{type}}) { |
2776 |
wakaba |
1.79 |
!!!cp ('t26'); |
2777 |
wakaba |
1.3 |
# |
2778 |
|
|
} else { |
2779 |
wakaba |
1.55 |
die "$0: $token->{type}: Unknown token type"; |
2780 |
wakaba |
1.3 |
} |
2781 |
wakaba |
1.61 |
|
2782 |
wakaba |
1.84 |
my $root_element; !!!create-element ($root_element, 'html'); |
2783 |
|
|
$self->{document}->append_child ($root_element); |
2784 |
|
|
push @{$self->{open_elements}}, [$root_element, 'html']; |
2785 |
|
|
|
2786 |
|
|
$self->{application_cache_selection}->(undef); |
2787 |
|
|
|
2788 |
|
|
## NOTE: Reprocess the token. |
2789 |
|
|
return; ## Go to the "before head" insertion mode. |
2790 |
|
|
|
2791 |
|
|
## ISSUE: There is an issue in the spec |
2792 |
wakaba |
1.3 |
} # B |
2793 |
wakaba |
1.79 |
|
2794 |
|
|
die "$0: _tree_construction_root_element: This should never be reached"; |
2795 |
wakaba |
1.3 |
} # _tree_construction_root_element |
2796 |
|
|
|
2797 |
|
|
sub _reset_insertion_mode ($) { |
2798 |
|
|
my $self = shift; |
2799 |
|
|
|
2800 |
|
|
## Step 1 |
2801 |
|
|
my $last; |
2802 |
|
|
|
2803 |
|
|
## Step 2 |
2804 |
|
|
my $i = -1; |
2805 |
|
|
my $node = $self->{open_elements}->[$i]; |
2806 |
|
|
|
2807 |
|
|
## Step 3 |
2808 |
|
|
S3: { |
2809 |
wakaba |
1.29 |
if ($self->{open_elements}->[0]->[0] eq $node->[0]) { |
2810 |
|
|
$last = 1; |
2811 |
|
|
if (defined $self->{inner_html_node}) { |
2812 |
|
|
if ($self->{inner_html_node}->[1] eq 'td' or |
2813 |
|
|
$self->{inner_html_node}->[1] eq 'th') { |
2814 |
wakaba |
1.79 |
!!!cp ('t27'); |
2815 |
wakaba |
1.29 |
# |
2816 |
|
|
} else { |
2817 |
wakaba |
1.79 |
!!!cp ('t28'); |
2818 |
wakaba |
1.29 |
$node = $self->{inner_html_node}; |
2819 |
|
|
} |
2820 |
wakaba |
1.3 |
} |
2821 |
|
|
} |
2822 |
|
|
|
2823 |
|
|
## Step 4..13 |
2824 |
|
|
my $new_mode = { |
2825 |
wakaba |
1.54 |
select => IN_SELECT_IM, |
2826 |
wakaba |
1.83 |
## NOTE: |option| and |optgroup| do not set |
2827 |
|
|
## insertion mode to "in select" by themselves. |
2828 |
wakaba |
1.54 |
td => IN_CELL_IM, |
2829 |
|
|
th => IN_CELL_IM, |
2830 |
|
|
tr => IN_ROW_IM, |
2831 |
|
|
tbody => IN_TABLE_BODY_IM, |
2832 |
|
|
thead => IN_TABLE_BODY_IM, |
2833 |
|
|
tfoot => IN_TABLE_BODY_IM, |
2834 |
|
|
caption => IN_CAPTION_IM, |
2835 |
|
|
colgroup => IN_COLUMN_GROUP_IM, |
2836 |
|
|
table => IN_TABLE_IM, |
2837 |
|
|
head => IN_BODY_IM, # not in head! |
2838 |
|
|
body => IN_BODY_IM, |
2839 |
|
|
frameset => IN_FRAMESET_IM, |
2840 |
wakaba |
1.3 |
}->{$node->[1]}; |
2841 |
|
|
$self->{insertion_mode} = $new_mode and return if defined $new_mode; |
2842 |
|
|
|
2843 |
|
|
## Step 14 |
2844 |
|
|
if ($node->[1] eq 'html') { |
2845 |
|
|
unless (defined $self->{head_element}) { |
2846 |
wakaba |
1.79 |
!!!cp ('t29'); |
2847 |
wakaba |
1.54 |
$self->{insertion_mode} = BEFORE_HEAD_IM; |
2848 |
wakaba |
1.3 |
} else { |
2849 |
wakaba |
1.81 |
## ISSUE: Can this state be reached? |
2850 |
wakaba |
1.79 |
!!!cp ('t30'); |
2851 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_HEAD_IM; |
2852 |
wakaba |
1.3 |
} |
2853 |
|
|
return; |
2854 |
wakaba |
1.79 |
} else { |
2855 |
|
|
!!!cp ('t31'); |
2856 |
wakaba |
1.3 |
} |
2857 |
|
|
|
2858 |
|
|
## Step 15 |
2859 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_BODY_IM and return if $last; |
2860 |
wakaba |
1.3 |
|
2861 |
|
|
## Step 16 |
2862 |
|
|
$i--; |
2863 |
|
|
$node = $self->{open_elements}->[$i]; |
2864 |
|
|
|
2865 |
|
|
## Step 17 |
2866 |
|
|
redo S3; |
2867 |
|
|
} # S3 |
2868 |
wakaba |
1.79 |
|
2869 |
|
|
die "$0: _reset_insertion_mode: This line should never be reached"; |
2870 |
wakaba |
1.3 |
} # _reset_insertion_mode |
2871 |
|
|
|
2872 |
|
|
sub _tree_construction_main ($) { |
2873 |
|
|
my $self = shift; |
2874 |
|
|
|
2875 |
wakaba |
1.1 |
my $active_formatting_elements = []; |
2876 |
|
|
|
2877 |
|
|
my $reconstruct_active_formatting_elements = sub { # MUST |
2878 |
|
|
my $insert = shift; |
2879 |
|
|
|
2880 |
|
|
## Step 1 |
2881 |
|
|
return unless @$active_formatting_elements; |
2882 |
|
|
|
2883 |
|
|
## Step 3 |
2884 |
|
|
my $i = -1; |
2885 |
|
|
my $entry = $active_formatting_elements->[$i]; |
2886 |
|
|
|
2887 |
|
|
## Step 2 |
2888 |
|
|
return if $entry->[0] eq '#marker'; |
2889 |
wakaba |
1.3 |
for (@{$self->{open_elements}}) { |
2890 |
wakaba |
1.1 |
if ($entry->[0] eq $_->[0]) { |
2891 |
wakaba |
1.79 |
!!!cp ('t32'); |
2892 |
wakaba |
1.1 |
return; |
2893 |
|
|
} |
2894 |
|
|
} |
2895 |
|
|
|
2896 |
|
|
S4: { |
2897 |
|
|
## Step 4 |
2898 |
|
|
last S4 if $active_formatting_elements->[0]->[0] eq $entry->[0]; |
2899 |
|
|
|
2900 |
|
|
## Step 5 |
2901 |
|
|
$i--; |
2902 |
|
|
$entry = $active_formatting_elements->[$i]; |
2903 |
|
|
|
2904 |
|
|
## Step 6 |
2905 |
|
|
if ($entry->[0] eq '#marker') { |
2906 |
wakaba |
1.81 |
!!!cp ('t33_1'); |
2907 |
wakaba |
1.1 |
# |
2908 |
|
|
} else { |
2909 |
|
|
my $in_open_elements; |
2910 |
wakaba |
1.3 |
OE: for (@{$self->{open_elements}}) { |
2911 |
wakaba |
1.1 |
if ($entry->[0] eq $_->[0]) { |
2912 |
wakaba |
1.79 |
!!!cp ('t33'); |
2913 |
wakaba |
1.1 |
$in_open_elements = 1; |
2914 |
|
|
last OE; |
2915 |
|
|
} |
2916 |
|
|
} |
2917 |
|
|
if ($in_open_elements) { |
2918 |
wakaba |
1.79 |
!!!cp ('t34'); |
2919 |
wakaba |
1.1 |
# |
2920 |
|
|
} else { |
2921 |
wakaba |
1.81 |
## NOTE: <!DOCTYPE HTML><p><b><i><u></p> <p>X |
2922 |
wakaba |
1.79 |
!!!cp ('t35'); |
2923 |
wakaba |
1.1 |
redo S4; |
2924 |
|
|
} |
2925 |
|
|
} |
2926 |
|
|
|
2927 |
|
|
## Step 7 |
2928 |
|
|
$i++; |
2929 |
|
|
$entry = $active_formatting_elements->[$i]; |
2930 |
|
|
} # S4 |
2931 |
|
|
|
2932 |
|
|
S7: { |
2933 |
|
|
## Step 8 |
2934 |
|
|
my $clone = [$entry->[0]->clone_node (0), $entry->[1]]; |
2935 |
|
|
|
2936 |
|
|
## Step 9 |
2937 |
|
|
$insert->($clone->[0]); |
2938 |
wakaba |
1.3 |
push @{$self->{open_elements}}, $clone; |
2939 |
wakaba |
1.1 |
|
2940 |
|
|
## Step 10 |
2941 |
wakaba |
1.3 |
$active_formatting_elements->[$i] = $self->{open_elements}->[-1]; |
2942 |
wakaba |
1.1 |
|
2943 |
|
|
## Step 11 |
2944 |
|
|
unless ($clone->[0] eq $active_formatting_elements->[-1]->[0]) { |
2945 |
wakaba |
1.79 |
!!!cp ('t36'); |
2946 |
wakaba |
1.1 |
## Step 7' |
2947 |
|
|
$i++; |
2948 |
|
|
$entry = $active_formatting_elements->[$i]; |
2949 |
|
|
|
2950 |
|
|
redo S7; |
2951 |
|
|
} |
2952 |
wakaba |
1.79 |
|
2953 |
|
|
!!!cp ('t37'); |
2954 |
wakaba |
1.1 |
} # S7 |
2955 |
|
|
}; # $reconstruct_active_formatting_elements |
2956 |
|
|
|
2957 |
|
|
my $clear_up_to_marker = sub { |
2958 |
|
|
for (reverse 0..$#$active_formatting_elements) { |
2959 |
|
|
if ($active_formatting_elements->[$_]->[0] eq '#marker') { |
2960 |
wakaba |
1.79 |
!!!cp ('t38'); |
2961 |
wakaba |
1.1 |
splice @$active_formatting_elements, $_; |
2962 |
|
|
return; |
2963 |
|
|
} |
2964 |
|
|
} |
2965 |
wakaba |
1.79 |
|
2966 |
|
|
!!!cp ('t39'); |
2967 |
wakaba |
1.1 |
}; # $clear_up_to_marker |
2968 |
|
|
|
2969 |
wakaba |
1.96 |
my $insert; |
2970 |
|
|
|
2971 |
|
|
my $parse_rcdata = sub ($) { |
2972 |
|
|
my ($content_model_flag) = @_; |
2973 |
wakaba |
1.25 |
|
2974 |
|
|
## Step 1 |
2975 |
|
|
my $start_tag_name = $token->{tag_name}; |
2976 |
|
|
my $el; |
2977 |
|
|
!!!create-element ($el, $start_tag_name, $token->{attributes}); |
2978 |
|
|
|
2979 |
|
|
## Step 2 |
2980 |
wakaba |
1.96 |
$insert->($el); |
2981 |
wakaba |
1.25 |
|
2982 |
|
|
## Step 3 |
2983 |
wakaba |
1.40 |
$self->{content_model} = $content_model_flag; # CDATA or RCDATA |
2984 |
wakaba |
1.13 |
delete $self->{escape}; # MUST |
2985 |
wakaba |
1.25 |
|
2986 |
|
|
## Step 4 |
2987 |
wakaba |
1.1 |
my $text = ''; |
2988 |
|
|
!!!next-token; |
2989 |
wakaba |
1.55 |
while ($token->{type} == CHARACTER_TOKEN) { # or until stop tokenizing |
2990 |
wakaba |
1.79 |
!!!cp ('t40'); |
2991 |
wakaba |
1.1 |
$text .= $token->{data}; |
2992 |
|
|
!!!next-token; |
2993 |
wakaba |
1.25 |
} |
2994 |
|
|
|
2995 |
|
|
## Step 5 |
2996 |
wakaba |
1.1 |
if (length $text) { |
2997 |
wakaba |
1.79 |
!!!cp ('t41'); |
2998 |
wakaba |
1.25 |
my $text = $self->{document}->create_text_node ($text); |
2999 |
|
|
$el->append_child ($text); |
3000 |
wakaba |
1.1 |
} |
3001 |
wakaba |
1.25 |
|
3002 |
|
|
## Step 6 |
3003 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; |
3004 |
wakaba |
1.25 |
|
3005 |
|
|
## Step 7 |
3006 |
wakaba |
1.79 |
if ($token->{type} == END_TAG_TOKEN and |
3007 |
|
|
$token->{tag_name} eq $start_tag_name) { |
3008 |
|
|
!!!cp ('t42'); |
3009 |
wakaba |
1.1 |
## Ignore the token |
3010 |
|
|
} else { |
3011 |
wakaba |
1.96 |
## NOTE: An end-of-file token. |
3012 |
|
|
if ($content_model_flag == CDATA_CONTENT_MODEL) { |
3013 |
|
|
!!!cp ('t43'); |
3014 |
wakaba |
1.113 |
!!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token); |
3015 |
wakaba |
1.96 |
} elsif ($content_model_flag == RCDATA_CONTENT_MODEL) { |
3016 |
|
|
!!!cp ('t44'); |
3017 |
wakaba |
1.113 |
!!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token); |
3018 |
wakaba |
1.96 |
} else { |
3019 |
|
|
die "$0: $content_model_flag in parse_rcdata"; |
3020 |
|
|
} |
3021 |
wakaba |
1.1 |
} |
3022 |
|
|
!!!next-token; |
3023 |
wakaba |
1.25 |
}; # $parse_rcdata |
3024 |
wakaba |
1.1 |
|
3025 |
wakaba |
1.96 |
my $script_start_tag = sub () { |
3026 |
wakaba |
1.1 |
my $script_el; |
3027 |
|
|
!!!create-element ($script_el, 'script', $token->{attributes}); |
3028 |
|
|
## TODO: mark as "parser-inserted" |
3029 |
|
|
|
3030 |
wakaba |
1.40 |
$self->{content_model} = CDATA_CONTENT_MODEL; |
3031 |
wakaba |
1.13 |
delete $self->{escape}; # MUST |
3032 |
wakaba |
1.1 |
|
3033 |
|
|
my $text = ''; |
3034 |
|
|
!!!next-token; |
3035 |
wakaba |
1.55 |
while ($token->{type} == CHARACTER_TOKEN) { |
3036 |
wakaba |
1.79 |
!!!cp ('t45'); |
3037 |
wakaba |
1.1 |
$text .= $token->{data}; |
3038 |
|
|
!!!next-token; |
3039 |
|
|
} # stop if non-character token or tokenizer stops tokenising |
3040 |
|
|
if (length $text) { |
3041 |
wakaba |
1.79 |
!!!cp ('t46'); |
3042 |
wakaba |
1.1 |
$script_el->manakai_append_text ($text); |
3043 |
|
|
} |
3044 |
|
|
|
3045 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; |
3046 |
wakaba |
1.1 |
|
3047 |
wakaba |
1.55 |
if ($token->{type} == END_TAG_TOKEN and |
3048 |
wakaba |
1.1 |
$token->{tag_name} eq 'script') { |
3049 |
wakaba |
1.79 |
!!!cp ('t47'); |
3050 |
wakaba |
1.1 |
## Ignore the token |
3051 |
|
|
} else { |
3052 |
wakaba |
1.79 |
!!!cp ('t48'); |
3053 |
wakaba |
1.113 |
!!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token); |
3054 |
wakaba |
1.1 |
## ISSUE: And ignore? |
3055 |
|
|
## TODO: mark as "already executed" |
3056 |
|
|
} |
3057 |
|
|
|
3058 |
wakaba |
1.3 |
if (defined $self->{inner_html_node}) { |
3059 |
wakaba |
1.79 |
!!!cp ('t49'); |
3060 |
wakaba |
1.3 |
## TODO: mark as "already executed" |
3061 |
|
|
} else { |
3062 |
wakaba |
1.79 |
!!!cp ('t50'); |
3063 |
wakaba |
1.1 |
## TODO: $old_insertion_point = current insertion point |
3064 |
|
|
## TODO: insertion point = just before the next input character |
3065 |
wakaba |
1.25 |
|
3066 |
|
|
$insert->($script_el); |
3067 |
wakaba |
1.1 |
|
3068 |
|
|
## TODO: insertion point = $old_insertion_point (might be "undefined") |
3069 |
|
|
|
3070 |
|
|
## TODO: if there is a script that will execute as soon as the parser resume, then... |
3071 |
|
|
} |
3072 |
|
|
|
3073 |
|
|
!!!next-token; |
3074 |
|
|
}; # $script_start_tag |
3075 |
|
|
|
3076 |
wakaba |
1.102 |
## NOTE: $open_tables->[-1]->[0] is the "current table" element node. |
3077 |
|
|
## NOTE: $open_tables->[-1]->[1] is the "tainted" flag. |
3078 |
|
|
my $open_tables = [[$self->{open_elements}->[0]->[0]]]; |
3079 |
|
|
|
3080 |
wakaba |
1.1 |
my $formatting_end_tag = sub { |
3081 |
wakaba |
1.113 |
my $end_tag_token = shift; |
3082 |
|
|
my $tag_name = $end_tag_token->{tag_name}; |
3083 |
wakaba |
1.1 |
|
3084 |
wakaba |
1.103 |
## NOTE: The adoption agency algorithm (AAA). |
3085 |
wakaba |
1.102 |
|
3086 |
wakaba |
1.1 |
FET: { |
3087 |
|
|
## Step 1 |
3088 |
|
|
my $formatting_element; |
3089 |
|
|
my $formatting_element_i_in_active; |
3090 |
|
|
AFE: for (reverse 0..$#$active_formatting_elements) { |
3091 |
|
|
if ($active_formatting_elements->[$_]->[1] eq $tag_name) { |
3092 |
wakaba |
1.79 |
!!!cp ('t51'); |
3093 |
wakaba |
1.1 |
$formatting_element = $active_formatting_elements->[$_]; |
3094 |
|
|
$formatting_element_i_in_active = $_; |
3095 |
|
|
last AFE; |
3096 |
|
|
} elsif ($active_formatting_elements->[$_]->[0] eq '#marker') { |
3097 |
wakaba |
1.79 |
!!!cp ('t52'); |
3098 |
wakaba |
1.1 |
last AFE; |
3099 |
|
|
} |
3100 |
|
|
} # AFE |
3101 |
|
|
unless (defined $formatting_element) { |
3102 |
wakaba |
1.79 |
!!!cp ('t53'); |
3103 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$tag_name, token => $end_tag_token); |
3104 |
wakaba |
1.1 |
## Ignore the token |
3105 |
|
|
!!!next-token; |
3106 |
|
|
return; |
3107 |
|
|
} |
3108 |
|
|
## has an element in scope |
3109 |
|
|
my $in_scope = 1; |
3110 |
|
|
my $formatting_element_i_in_open; |
3111 |
wakaba |
1.3 |
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
3112 |
|
|
my $node = $self->{open_elements}->[$_]; |
3113 |
wakaba |
1.1 |
if ($node->[0] eq $formatting_element->[0]) { |
3114 |
|
|
if ($in_scope) { |
3115 |
wakaba |
1.79 |
!!!cp ('t54'); |
3116 |
wakaba |
1.1 |
$formatting_element_i_in_open = $_; |
3117 |
|
|
last INSCOPE; |
3118 |
|
|
} else { # in open elements but not in scope |
3119 |
wakaba |
1.79 |
!!!cp ('t55'); |
3120 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, |
3121 |
|
|
token => $end_tag_token); |
3122 |
wakaba |
1.1 |
## Ignore the token |
3123 |
|
|
!!!next-token; |
3124 |
|
|
return; |
3125 |
|
|
} |
3126 |
|
|
} elsif ({ |
3127 |
wakaba |
1.103 |
applet => 1, table => 1, caption => 1, td => 1, th => 1, |
3128 |
wakaba |
1.1 |
button => 1, marquee => 1, object => 1, html => 1, |
3129 |
|
|
}->{$node->[1]}) { |
3130 |
wakaba |
1.79 |
!!!cp ('t56'); |
3131 |
wakaba |
1.1 |
$in_scope = 0; |
3132 |
|
|
} |
3133 |
|
|
} # INSCOPE |
3134 |
|
|
unless (defined $formatting_element_i_in_open) { |
3135 |
wakaba |
1.79 |
!!!cp ('t57'); |
3136 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, |
3137 |
|
|
token => $end_tag_token); |
3138 |
wakaba |
1.1 |
pop @$active_formatting_elements; # $formatting_element |
3139 |
|
|
!!!next-token; ## TODO: ok? |
3140 |
|
|
return; |
3141 |
|
|
} |
3142 |
wakaba |
1.3 |
if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) { |
3143 |
wakaba |
1.79 |
!!!cp ('t58'); |
3144 |
wakaba |
1.113 |
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], |
3145 |
|
|
token => $end_tag_token); |
3146 |
wakaba |
1.1 |
} |
3147 |
|
|
|
3148 |
|
|
## Step 2 |
3149 |
|
|
my $furthest_block; |
3150 |
|
|
my $furthest_block_i_in_open; |
3151 |
wakaba |
1.3 |
OE: for (reverse 0..$#{$self->{open_elements}}) { |
3152 |
|
|
my $node = $self->{open_elements}->[$_]; |
3153 |
wakaba |
1.1 |
if (not $formatting_category->{$node->[1]} and |
3154 |
|
|
#not $phrasing_category->{$node->[1]} and |
3155 |
|
|
($special_category->{$node->[1]} or |
3156 |
wakaba |
1.103 |
$scoping_category->{$node->[1]})) { ## Scoping is redundant, maybe |
3157 |
wakaba |
1.79 |
!!!cp ('t59'); |
3158 |
wakaba |
1.1 |
$furthest_block = $node; |
3159 |
|
|
$furthest_block_i_in_open = $_; |
3160 |
|
|
} elsif ($node->[0] eq $formatting_element->[0]) { |
3161 |
wakaba |
1.79 |
!!!cp ('t60'); |
3162 |
wakaba |
1.1 |
last OE; |
3163 |
|
|
} |
3164 |
|
|
} # OE |
3165 |
|
|
|
3166 |
|
|
## Step 3 |
3167 |
|
|
unless (defined $furthest_block) { # MUST |
3168 |
wakaba |
1.79 |
!!!cp ('t61'); |
3169 |
wakaba |
1.3 |
splice @{$self->{open_elements}}, $formatting_element_i_in_open; |
3170 |
wakaba |
1.1 |
splice @$active_formatting_elements, $formatting_element_i_in_active, 1; |
3171 |
|
|
!!!next-token; |
3172 |
|
|
return; |
3173 |
|
|
} |
3174 |
|
|
|
3175 |
|
|
## Step 4 |
3176 |
wakaba |
1.3 |
my $common_ancestor_node = $self->{open_elements}->[$formatting_element_i_in_open - 1]; |
3177 |
wakaba |
1.1 |
|
3178 |
|
|
## Step 5 |
3179 |
|
|
my $furthest_block_parent = $furthest_block->[0]->parent_node; |
3180 |
|
|
if (defined $furthest_block_parent) { |
3181 |
wakaba |
1.79 |
!!!cp ('t62'); |
3182 |
wakaba |
1.1 |
$furthest_block_parent->remove_child ($furthest_block->[0]); |
3183 |
|
|
} |
3184 |
|
|
|
3185 |
|
|
## Step 6 |
3186 |
|
|
my $bookmark_prev_el |
3187 |
|
|
= $active_formatting_elements->[$formatting_element_i_in_active - 1] |
3188 |
|
|
->[0]; |
3189 |
|
|
|
3190 |
|
|
## Step 7 |
3191 |
|
|
my $node = $furthest_block; |
3192 |
|
|
my $node_i_in_open = $furthest_block_i_in_open; |
3193 |
|
|
my $last_node = $furthest_block; |
3194 |
|
|
S7: { |
3195 |
|
|
## Step 1 |
3196 |
|
|
$node_i_in_open--; |
3197 |
wakaba |
1.3 |
$node = $self->{open_elements}->[$node_i_in_open]; |
3198 |
wakaba |
1.1 |
|
3199 |
|
|
## Step 2 |
3200 |
|
|
my $node_i_in_active; |
3201 |
|
|
S7S2: { |
3202 |
|
|
for (reverse 0..$#$active_formatting_elements) { |
3203 |
|
|
if ($active_formatting_elements->[$_]->[0] eq $node->[0]) { |
3204 |
wakaba |
1.79 |
!!!cp ('t63'); |
3205 |
wakaba |
1.1 |
$node_i_in_active = $_; |
3206 |
|
|
last S7S2; |
3207 |
|
|
} |
3208 |
|
|
} |
3209 |
wakaba |
1.3 |
splice @{$self->{open_elements}}, $node_i_in_open, 1; |
3210 |
wakaba |
1.1 |
redo S7; |
3211 |
|
|
} # S7S2 |
3212 |
|
|
|
3213 |
|
|
## Step 3 |
3214 |
|
|
last S7 if $node->[0] eq $formatting_element->[0]; |
3215 |
|
|
|
3216 |
|
|
## Step 4 |
3217 |
|
|
if ($last_node->[0] eq $furthest_block->[0]) { |
3218 |
wakaba |
1.79 |
!!!cp ('t64'); |
3219 |
wakaba |
1.1 |
$bookmark_prev_el = $node->[0]; |
3220 |
|
|
} |
3221 |
|
|
|
3222 |
|
|
## Step 5 |
3223 |
|
|
if ($node->[0]->has_child_nodes ()) { |
3224 |
wakaba |
1.79 |
!!!cp ('t65'); |
3225 |
wakaba |
1.1 |
my $clone = [$node->[0]->clone_node (0), $node->[1]]; |
3226 |
|
|
$active_formatting_elements->[$node_i_in_active] = $clone; |
3227 |
wakaba |
1.3 |
$self->{open_elements}->[$node_i_in_open] = $clone; |
3228 |
wakaba |
1.1 |
$node = $clone; |
3229 |
|
|
} |
3230 |
|
|
|
3231 |
|
|
## Step 6 |
3232 |
|
|
$node->[0]->append_child ($last_node->[0]); |
3233 |
|
|
|
3234 |
|
|
## Step 7 |
3235 |
|
|
$last_node = $node; |
3236 |
|
|
|
3237 |
|
|
## Step 8 |
3238 |
|
|
redo S7; |
3239 |
|
|
} # S7 |
3240 |
|
|
|
3241 |
|
|
## Step 8 |
3242 |
wakaba |
1.102 |
if ({ |
3243 |
|
|
table => 1, tbody => 1, tfoot => 1, thead => 1, tr => 1, |
3244 |
|
|
}->{$common_ancestor_node->[1]}) { |
3245 |
|
|
my $foster_parent_element; |
3246 |
|
|
my $next_sibling; |
3247 |
|
|
OE: for (reverse 0..$#{$self->{open_elements}}) { |
3248 |
|
|
if ($self->{open_elements}->[$_]->[1] eq 'table') { |
3249 |
|
|
my $parent = $self->{open_elements}->[$_]->[0]->parent_node; |
3250 |
|
|
if (defined $parent and $parent->node_type == 1) { |
3251 |
|
|
!!!cp ('t65.1'); |
3252 |
|
|
$foster_parent_element = $parent; |
3253 |
|
|
$next_sibling = $self->{open_elements}->[$_]->[0]; |
3254 |
|
|
} else { |
3255 |
|
|
!!!cp ('t65.2'); |
3256 |
|
|
$foster_parent_element |
3257 |
|
|
= $self->{open_elements}->[$_ - 1]->[0]; |
3258 |
|
|
} |
3259 |
|
|
last OE; |
3260 |
|
|
} |
3261 |
|
|
} # OE |
3262 |
|
|
$foster_parent_element = $self->{open_elements}->[0]->[0] |
3263 |
|
|
unless defined $foster_parent_element; |
3264 |
|
|
$foster_parent_element->insert_before ($last_node->[0], $next_sibling); |
3265 |
|
|
$open_tables->[-1]->[1] = 1; # tainted |
3266 |
|
|
} else { |
3267 |
|
|
!!!cp ('t65.3'); |
3268 |
|
|
$common_ancestor_node->[0]->append_child ($last_node->[0]); |
3269 |
|
|
} |
3270 |
wakaba |
1.1 |
|
3271 |
|
|
## Step 9 |
3272 |
|
|
my $clone = [$formatting_element->[0]->clone_node (0), |
3273 |
|
|
$formatting_element->[1]]; |
3274 |
|
|
|
3275 |
|
|
## Step 10 |
3276 |
|
|
my @cn = @{$furthest_block->[0]->child_nodes}; |
3277 |
|
|
$clone->[0]->append_child ($_) for @cn; |
3278 |
|
|
|
3279 |
|
|
## Step 11 |
3280 |
|
|
$furthest_block->[0]->append_child ($clone->[0]); |
3281 |
|
|
|
3282 |
|
|
## Step 12 |
3283 |
|
|
my $i; |
3284 |
|
|
AFE: for (reverse 0..$#$active_formatting_elements) { |
3285 |
|
|
if ($active_formatting_elements->[$_]->[0] eq $formatting_element->[0]) { |
3286 |
wakaba |
1.79 |
!!!cp ('t66'); |
3287 |
wakaba |
1.1 |
splice @$active_formatting_elements, $_, 1; |
3288 |
|
|
$i-- and last AFE if defined $i; |
3289 |
|
|
} elsif ($active_formatting_elements->[$_]->[0] eq $bookmark_prev_el) { |
3290 |
wakaba |
1.79 |
!!!cp ('t67'); |
3291 |
wakaba |
1.1 |
$i = $_; |
3292 |
|
|
} |
3293 |
|
|
} # AFE |
3294 |
|
|
splice @$active_formatting_elements, $i + 1, 0, $clone; |
3295 |
|
|
|
3296 |
|
|
## Step 13 |
3297 |
|
|
undef $i; |
3298 |
wakaba |
1.3 |
OE: for (reverse 0..$#{$self->{open_elements}}) { |
3299 |
|
|
if ($self->{open_elements}->[$_]->[0] eq $formatting_element->[0]) { |
3300 |
wakaba |
1.79 |
!!!cp ('t68'); |
3301 |
wakaba |
1.3 |
splice @{$self->{open_elements}}, $_, 1; |
3302 |
wakaba |
1.1 |
$i-- and last OE if defined $i; |
3303 |
wakaba |
1.3 |
} elsif ($self->{open_elements}->[$_]->[0] eq $furthest_block->[0]) { |
3304 |
wakaba |
1.79 |
!!!cp ('t69'); |
3305 |
wakaba |
1.1 |
$i = $_; |
3306 |
|
|
} |
3307 |
|
|
} # OE |
3308 |
wakaba |
1.3 |
splice @{$self->{open_elements}}, $i + 1, 1, $clone; |
3309 |
wakaba |
1.1 |
|
3310 |
|
|
## Step 14 |
3311 |
|
|
redo FET; |
3312 |
|
|
} # FET |
3313 |
|
|
}; # $formatting_end_tag |
3314 |
|
|
|
3315 |
wakaba |
1.96 |
$insert = my $insert_to_current = sub { |
3316 |
wakaba |
1.25 |
$self->{open_elements}->[-1]->[0]->append_child ($_[0]); |
3317 |
wakaba |
1.1 |
}; # $insert_to_current |
3318 |
|
|
|
3319 |
|
|
my $insert_to_foster = sub { |
3320 |
wakaba |
1.95 |
my $child = shift; |
3321 |
|
|
if ({ |
3322 |
|
|
table => 1, tbody => 1, tfoot => 1, thead => 1, tr => 1, |
3323 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
3324 |
|
|
# MUST |
3325 |
|
|
my $foster_parent_element; |
3326 |
|
|
my $next_sibling; |
3327 |
wakaba |
1.3 |
OE: for (reverse 0..$#{$self->{open_elements}}) { |
3328 |
|
|
if ($self->{open_elements}->[$_]->[1] eq 'table') { |
3329 |
|
|
my $parent = $self->{open_elements}->[$_]->[0]->parent_node; |
3330 |
wakaba |
1.1 |
if (defined $parent and $parent->node_type == 1) { |
3331 |
wakaba |
1.79 |
!!!cp ('t70'); |
3332 |
wakaba |
1.1 |
$foster_parent_element = $parent; |
3333 |
wakaba |
1.3 |
$next_sibling = $self->{open_elements}->[$_]->[0]; |
3334 |
wakaba |
1.1 |
} else { |
3335 |
wakaba |
1.79 |
!!!cp ('t71'); |
3336 |
wakaba |
1.1 |
$foster_parent_element |
3337 |
wakaba |
1.3 |
= $self->{open_elements}->[$_ - 1]->[0]; |
3338 |
wakaba |
1.1 |
} |
3339 |
|
|
last OE; |
3340 |
|
|
} |
3341 |
|
|
} # OE |
3342 |
wakaba |
1.3 |
$foster_parent_element = $self->{open_elements}->[0]->[0] |
3343 |
wakaba |
1.1 |
unless defined $foster_parent_element; |
3344 |
|
|
$foster_parent_element->insert_before |
3345 |
|
|
($child, $next_sibling); |
3346 |
wakaba |
1.95 |
$open_tables->[-1]->[1] = 1; # tainted |
3347 |
|
|
} else { |
3348 |
|
|
!!!cp ('t72'); |
3349 |
|
|
$self->{open_elements}->[-1]->[0]->append_child ($child); |
3350 |
|
|
} |
3351 |
wakaba |
1.1 |
}; # $insert_to_foster |
3352 |
|
|
|
3353 |
wakaba |
1.52 |
B: { |
3354 |
wakaba |
1.55 |
if ($token->{type} == DOCTYPE_TOKEN) { |
3355 |
wakaba |
1.79 |
!!!cp ('t73'); |
3356 |
wakaba |
1.113 |
!!!parse-error (type => 'DOCTYPE in the middle', token => $token); |
3357 |
wakaba |
1.52 |
## Ignore the token |
3358 |
|
|
## Stay in the phase |
3359 |
|
|
!!!next-token; |
3360 |
|
|
redo B; |
3361 |
wakaba |
1.55 |
} elsif ($token->{type} == START_TAG_TOKEN and |
3362 |
wakaba |
1.52 |
$token->{tag_name} eq 'html') { |
3363 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) { |
3364 |
wakaba |
1.79 |
!!!cp ('t79'); |
3365 |
wakaba |
1.113 |
!!!parse-error (type => 'after html:html', token => $token); |
3366 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_BODY_IM; |
3367 |
|
|
} elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) { |
3368 |
wakaba |
1.79 |
!!!cp ('t80'); |
3369 |
wakaba |
1.113 |
!!!parse-error (type => 'after html:html', token => $token); |
3370 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_FRAMESET_IM; |
3371 |
wakaba |
1.79 |
} else { |
3372 |
|
|
!!!cp ('t81'); |
3373 |
wakaba |
1.52 |
} |
3374 |
|
|
|
3375 |
wakaba |
1.84 |
!!!cp ('t82'); |
3376 |
wakaba |
1.113 |
!!!parse-error (type => 'not first start tag', token => $token); |
3377 |
wakaba |
1.52 |
my $top_el = $self->{open_elements}->[0]->[0]; |
3378 |
|
|
for my $attr_name (keys %{$token->{attributes}}) { |
3379 |
|
|
unless ($top_el->has_attribute_ns (undef, $attr_name)) { |
3380 |
wakaba |
1.79 |
!!!cp ('t84'); |
3381 |
wakaba |
1.52 |
$top_el->set_attribute_ns |
3382 |
|
|
(undef, [undef, $attr_name], |
3383 |
|
|
$token->{attributes}->{$attr_name}->{value}); |
3384 |
|
|
} |
3385 |
|
|
} |
3386 |
|
|
!!!next-token; |
3387 |
|
|
redo B; |
3388 |
wakaba |
1.55 |
} elsif ($token->{type} == COMMENT_TOKEN) { |
3389 |
wakaba |
1.52 |
my $comment = $self->{document}->create_comment ($token->{data}); |
3390 |
wakaba |
1.56 |
if ($self->{insertion_mode} & AFTER_HTML_IMS) { |
3391 |
wakaba |
1.79 |
!!!cp ('t85'); |
3392 |
wakaba |
1.52 |
$self->{document}->append_child ($comment); |
3393 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == AFTER_BODY_IM) { |
3394 |
wakaba |
1.79 |
!!!cp ('t86'); |
3395 |
wakaba |
1.52 |
$self->{open_elements}->[0]->[0]->append_child ($comment); |
3396 |
|
|
} else { |
3397 |
wakaba |
1.79 |
!!!cp ('t87'); |
3398 |
wakaba |
1.52 |
$self->{open_elements}->[-1]->[0]->append_child ($comment); |
3399 |
|
|
} |
3400 |
|
|
!!!next-token; |
3401 |
|
|
redo B; |
3402 |
wakaba |
1.56 |
} elsif ($self->{insertion_mode} & HEAD_IMS) { |
3403 |
wakaba |
1.55 |
if ($token->{type} == CHARACTER_TOKEN) { |
3404 |
wakaba |
1.52 |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { |
3405 |
wakaba |
1.99 |
unless ($self->{insertion_mode} == BEFORE_HEAD_IM) { |
3406 |
|
|
!!!cp ('t88.2'); |
3407 |
|
|
$self->{open_elements}->[-1]->[0]->manakai_append_text ($1); |
3408 |
|
|
} else { |
3409 |
|
|
!!!cp ('t88.1'); |
3410 |
|
|
## Ignore the token. |
3411 |
|
|
!!!next-token; |
3412 |
|
|
redo B; |
3413 |
|
|
} |
3414 |
wakaba |
1.52 |
unless (length $token->{data}) { |
3415 |
wakaba |
1.79 |
!!!cp ('t88'); |
3416 |
wakaba |
1.52 |
!!!next-token; |
3417 |
|
|
redo B; |
3418 |
wakaba |
1.1 |
} |
3419 |
|
|
} |
3420 |
wakaba |
1.52 |
|
3421 |
wakaba |
1.54 |
if ($self->{insertion_mode} == BEFORE_HEAD_IM) { |
3422 |
wakaba |
1.79 |
!!!cp ('t89'); |
3423 |
wakaba |
1.52 |
## As if <head> |
3424 |
|
|
!!!create-element ($self->{head_element}, 'head'); |
3425 |
|
|
$self->{open_elements}->[-1]->[0]->append_child ($self->{head_element}); |
3426 |
|
|
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
3427 |
|
|
|
3428 |
|
|
## Reprocess in the "in head" insertion mode... |
3429 |
|
|
pop @{$self->{open_elements}}; |
3430 |
|
|
|
3431 |
|
|
## Reprocess in the "after head" insertion mode... |
3432 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
3433 |
wakaba |
1.79 |
!!!cp ('t90'); |
3434 |
wakaba |
1.52 |
## As if </noscript> |
3435 |
|
|
pop @{$self->{open_elements}}; |
3436 |
wakaba |
1.113 |
!!!parse-error (type => 'in noscript:#character', token => $token); |
3437 |
wakaba |
1.1 |
|
3438 |
wakaba |
1.52 |
## Reprocess in the "in head" insertion mode... |
3439 |
|
|
## As if </head> |
3440 |
|
|
pop @{$self->{open_elements}}; |
3441 |
|
|
|
3442 |
|
|
## Reprocess in the "after head" insertion mode... |
3443 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_HEAD_IM) { |
3444 |
wakaba |
1.79 |
!!!cp ('t91'); |
3445 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; |
3446 |
|
|
|
3447 |
|
|
## Reprocess in the "after head" insertion mode... |
3448 |
wakaba |
1.79 |
} else { |
3449 |
|
|
!!!cp ('t92'); |
3450 |
wakaba |
1.1 |
} |
3451 |
wakaba |
1.52 |
|
3452 |
|
|
## "after head" insertion mode |
3453 |
|
|
## As if <body> |
3454 |
|
|
!!!insert-element ('body'); |
3455 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_BODY_IM; |
3456 |
wakaba |
1.52 |
## reprocess |
3457 |
|
|
redo B; |
3458 |
wakaba |
1.55 |
} elsif ($token->{type} == START_TAG_TOKEN) { |
3459 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'head') { |
3460 |
wakaba |
1.54 |
if ($self->{insertion_mode} == BEFORE_HEAD_IM) { |
3461 |
wakaba |
1.79 |
!!!cp ('t93'); |
3462 |
wakaba |
1.52 |
!!!create-element ($self->{head_element}, $token->{tag_name}, $token->{attributes}); |
3463 |
|
|
$self->{open_elements}->[-1]->[0]->append_child ($self->{head_element}); |
3464 |
|
|
push @{$self->{open_elements}}, [$self->{head_element}, $token->{tag_name}]; |
3465 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_HEAD_IM; |
3466 |
wakaba |
1.52 |
!!!next-token; |
3467 |
|
|
redo B; |
3468 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == AFTER_HEAD_IM) { |
3469 |
wakaba |
1.79 |
!!!cp ('t94'); |
3470 |
wakaba |
1.54 |
# |
3471 |
|
|
} else { |
3472 |
wakaba |
1.79 |
!!!cp ('t95'); |
3473 |
wakaba |
1.113 |
!!!parse-error (type => 'in head:head', token => $token); # or in head noscript |
3474 |
wakaba |
1.52 |
## Ignore the token |
3475 |
|
|
!!!next-token; |
3476 |
|
|
redo B; |
3477 |
|
|
} |
3478 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) { |
3479 |
wakaba |
1.79 |
!!!cp ('t96'); |
3480 |
wakaba |
1.52 |
## As if <head> |
3481 |
|
|
!!!create-element ($self->{head_element}, 'head'); |
3482 |
|
|
$self->{open_elements}->[-1]->[0]->append_child ($self->{head_element}); |
3483 |
|
|
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
3484 |
|
|
|
3485 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_HEAD_IM; |
3486 |
wakaba |
1.52 |
## Reprocess in the "in head" insertion mode... |
3487 |
wakaba |
1.79 |
} else { |
3488 |
|
|
!!!cp ('t97'); |
3489 |
wakaba |
1.1 |
} |
3490 |
wakaba |
1.52 |
|
3491 |
wakaba |
1.49 |
if ($token->{tag_name} eq 'base') { |
3492 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
3493 |
wakaba |
1.79 |
!!!cp ('t98'); |
3494 |
wakaba |
1.49 |
## As if </noscript> |
3495 |
|
|
pop @{$self->{open_elements}}; |
3496 |
wakaba |
1.113 |
!!!parse-error (type => 'in noscript:base', token => $token); |
3497 |
wakaba |
1.49 |
|
3498 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_HEAD_IM; |
3499 |
wakaba |
1.49 |
## Reprocess in the "in head" insertion mode... |
3500 |
wakaba |
1.79 |
} else { |
3501 |
|
|
!!!cp ('t99'); |
3502 |
wakaba |
1.49 |
} |
3503 |
|
|
|
3504 |
|
|
## NOTE: There is a "as if in head" code clone. |
3505 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HEAD_IM) { |
3506 |
wakaba |
1.79 |
!!!cp ('t100'); |
3507 |
wakaba |
1.113 |
!!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token); |
3508 |
wakaba |
1.49 |
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
3509 |
wakaba |
1.79 |
} else { |
3510 |
|
|
!!!cp ('t101'); |
3511 |
wakaba |
1.49 |
} |
3512 |
|
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
3513 |
|
|
pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec. |
3514 |
wakaba |
1.100 |
pop @{$self->{open_elements}} # <head> |
3515 |
wakaba |
1.54 |
if $self->{insertion_mode} == AFTER_HEAD_IM; |
3516 |
wakaba |
1.49 |
!!!next-token; |
3517 |
|
|
redo B; |
3518 |
|
|
} elsif ($token->{tag_name} eq 'link') { |
3519 |
wakaba |
1.25 |
## NOTE: There is a "as if in head" code clone. |
3520 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HEAD_IM) { |
3521 |
wakaba |
1.79 |
!!!cp ('t102'); |
3522 |
wakaba |
1.113 |
!!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token); |
3523 |
wakaba |
1.25 |
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
3524 |
wakaba |
1.79 |
} else { |
3525 |
|
|
!!!cp ('t103'); |
3526 |
wakaba |
1.25 |
} |
3527 |
|
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
3528 |
|
|
pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec. |
3529 |
wakaba |
1.100 |
pop @{$self->{open_elements}} # <head> |
3530 |
wakaba |
1.54 |
if $self->{insertion_mode} == AFTER_HEAD_IM; |
3531 |
wakaba |
1.1 |
!!!next-token; |
3532 |
wakaba |
1.25 |
redo B; |
3533 |
wakaba |
1.34 |
} elsif ($token->{tag_name} eq 'meta') { |
3534 |
|
|
## NOTE: There is a "as if in head" code clone. |
3535 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HEAD_IM) { |
3536 |
wakaba |
1.79 |
!!!cp ('t104'); |
3537 |
wakaba |
1.113 |
!!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token); |
3538 |
wakaba |
1.34 |
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
3539 |
wakaba |
1.79 |
} else { |
3540 |
|
|
!!!cp ('t105'); |
3541 |
wakaba |
1.34 |
} |
3542 |
|
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
3543 |
wakaba |
1.66 |
my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec. |
3544 |
wakaba |
1.34 |
|
3545 |
|
|
unless ($self->{confident}) { |
3546 |
|
|
if ($token->{attributes}->{charset}) { ## TODO: And if supported |
3547 |
wakaba |
1.79 |
!!!cp ('t106'); |
3548 |
wakaba |
1.63 |
$self->{change_encoding} |
3549 |
wakaba |
1.114 |
->($self, $token->{attributes}->{charset}->{value}, |
3550 |
|
|
$token); |
3551 |
wakaba |
1.66 |
|
3552 |
|
|
$meta_el->[0]->get_attribute_node_ns (undef, 'charset') |
3553 |
|
|
->set_user_data (manakai_has_reference => |
3554 |
|
|
$token->{attributes}->{charset} |
3555 |
|
|
->{has_reference}); |
3556 |
wakaba |
1.63 |
} elsif ($token->{attributes}->{content}) { |
3557 |
wakaba |
1.35 |
## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition. |
3558 |
wakaba |
1.63 |
if ($token->{attributes}->{content}->{value} |
3559 |
wakaba |
1.70 |
=~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt] |
3560 |
|
|
[\x09-\x0D\x20]*= |
3561 |
wakaba |
1.34 |
[\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'| |
3562 |
|
|
([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) { |
3563 |
wakaba |
1.79 |
!!!cp ('t107'); |
3564 |
wakaba |
1.63 |
$self->{change_encoding} |
3565 |
wakaba |
1.114 |
->($self, defined $1 ? $1 : defined $2 ? $2 : $3, |
3566 |
|
|
$token); |
3567 |
wakaba |
1.68 |
$meta_el->[0]->get_attribute_node_ns (undef, 'content') |
3568 |
|
|
->set_user_data (manakai_has_reference => |
3569 |
|
|
$token->{attributes}->{content} |
3570 |
|
|
->{has_reference}); |
3571 |
wakaba |
1.79 |
} else { |
3572 |
|
|
!!!cp ('t108'); |
3573 |
wakaba |
1.63 |
} |
3574 |
wakaba |
1.34 |
} |
3575 |
wakaba |
1.66 |
} else { |
3576 |
|
|
if ($token->{attributes}->{charset}) { |
3577 |
wakaba |
1.79 |
!!!cp ('t109'); |
3578 |
wakaba |
1.66 |
$meta_el->[0]->get_attribute_node_ns (undef, 'charset') |
3579 |
|
|
->set_user_data (manakai_has_reference => |
3580 |
|
|
$token->{attributes}->{charset} |
3581 |
|
|
->{has_reference}); |
3582 |
|
|
} |
3583 |
wakaba |
1.68 |
if ($token->{attributes}->{content}) { |
3584 |
wakaba |
1.79 |
!!!cp ('t110'); |
3585 |
wakaba |
1.68 |
$meta_el->[0]->get_attribute_node_ns (undef, 'content') |
3586 |
|
|
->set_user_data (manakai_has_reference => |
3587 |
|
|
$token->{attributes}->{content} |
3588 |
|
|
->{has_reference}); |
3589 |
|
|
} |
3590 |
wakaba |
1.34 |
} |
3591 |
|
|
|
3592 |
wakaba |
1.100 |
pop @{$self->{open_elements}} # <head> |
3593 |
wakaba |
1.54 |
if $self->{insertion_mode} == AFTER_HEAD_IM; |
3594 |
wakaba |
1.34 |
!!!next-token; |
3595 |
|
|
redo B; |
3596 |
wakaba |
1.49 |
} elsif ($token->{tag_name} eq 'title') { |
3597 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
3598 |
wakaba |
1.79 |
!!!cp ('t111'); |
3599 |
wakaba |
1.49 |
## As if </noscript> |
3600 |
|
|
pop @{$self->{open_elements}}; |
3601 |
wakaba |
1.113 |
!!!parse-error (type => 'in noscript:title', token => $token); |
3602 |
wakaba |
1.49 |
|
3603 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_HEAD_IM; |
3604 |
wakaba |
1.49 |
## Reprocess in the "in head" insertion mode... |
3605 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == AFTER_HEAD_IM) { |
3606 |
wakaba |
1.79 |
!!!cp ('t112'); |
3607 |
wakaba |
1.113 |
!!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token); |
3608 |
wakaba |
1.25 |
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
3609 |
wakaba |
1.79 |
} else { |
3610 |
|
|
!!!cp ('t113'); |
3611 |
wakaba |
1.25 |
} |
3612 |
wakaba |
1.49 |
|
3613 |
|
|
## NOTE: There is a "as if in head" code clone. |
3614 |
wakaba |
1.31 |
my $parent = defined $self->{head_element} ? $self->{head_element} |
3615 |
|
|
: $self->{open_elements}->[-1]->[0]; |
3616 |
wakaba |
1.96 |
$parse_rcdata->(RCDATA_CONTENT_MODEL); |
3617 |
wakaba |
1.100 |
pop @{$self->{open_elements}} # <head> |
3618 |
wakaba |
1.54 |
if $self->{insertion_mode} == AFTER_HEAD_IM; |
3619 |
wakaba |
1.25 |
redo B; |
3620 |
|
|
} elsif ($token->{tag_name} eq 'style') { |
3621 |
|
|
## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and |
3622 |
wakaba |
1.54 |
## insertion mode IN_HEAD_IM) |
3623 |
wakaba |
1.25 |
## NOTE: There is a "as if in head" code clone. |
3624 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HEAD_IM) { |
3625 |
wakaba |
1.79 |
!!!cp ('t114'); |
3626 |
wakaba |
1.113 |
!!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token); |
3627 |
wakaba |
1.25 |
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
3628 |
wakaba |
1.79 |
} else { |
3629 |
|
|
!!!cp ('t115'); |
3630 |
wakaba |
1.25 |
} |
3631 |
wakaba |
1.96 |
$parse_rcdata->(CDATA_CONTENT_MODEL); |
3632 |
wakaba |
1.100 |
pop @{$self->{open_elements}} # <head> |
3633 |
wakaba |
1.54 |
if $self->{insertion_mode} == AFTER_HEAD_IM; |
3634 |
wakaba |
1.25 |
redo B; |
3635 |
|
|
} elsif ($token->{tag_name} eq 'noscript') { |
3636 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_HEAD_IM) { |
3637 |
wakaba |
1.79 |
!!!cp ('t116'); |
3638 |
wakaba |
1.25 |
## NOTE: and scripting is disalbed |
3639 |
|
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
3640 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_HEAD_NOSCRIPT_IM; |
3641 |
wakaba |
1.1 |
!!!next-token; |
3642 |
wakaba |
1.25 |
redo B; |
3643 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
3644 |
wakaba |
1.79 |
!!!cp ('t117'); |
3645 |
wakaba |
1.113 |
!!!parse-error (type => 'in noscript:noscript', token => $token); |
3646 |
wakaba |
1.1 |
## Ignore the token |
3647 |
wakaba |
1.41 |
!!!next-token; |
3648 |
wakaba |
1.25 |
redo B; |
3649 |
wakaba |
1.1 |
} else { |
3650 |
wakaba |
1.79 |
!!!cp ('t118'); |
3651 |
wakaba |
1.25 |
# |
3652 |
wakaba |
1.1 |
} |
3653 |
wakaba |
1.49 |
} elsif ($token->{tag_name} eq 'script') { |
3654 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
3655 |
wakaba |
1.79 |
!!!cp ('t119'); |
3656 |
wakaba |
1.49 |
## As if </noscript> |
3657 |
|
|
pop @{$self->{open_elements}}; |
3658 |
wakaba |
1.113 |
!!!parse-error (type => 'in noscript:script', token => $token); |
3659 |
wakaba |
1.49 |
|
3660 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_HEAD_IM; |
3661 |
wakaba |
1.49 |
## Reprocess in the "in head" insertion mode... |
3662 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == AFTER_HEAD_IM) { |
3663 |
wakaba |
1.79 |
!!!cp ('t120'); |
3664 |
wakaba |
1.113 |
!!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token); |
3665 |
wakaba |
1.25 |
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
3666 |
wakaba |
1.79 |
} else { |
3667 |
|
|
!!!cp ('t121'); |
3668 |
wakaba |
1.25 |
} |
3669 |
wakaba |
1.49 |
|
3670 |
wakaba |
1.25 |
## NOTE: There is a "as if in head" code clone. |
3671 |
wakaba |
1.100 |
$script_start_tag->(); |
3672 |
|
|
pop @{$self->{open_elements}} # <head> |
3673 |
wakaba |
1.54 |
if $self->{insertion_mode} == AFTER_HEAD_IM; |
3674 |
wakaba |
1.1 |
redo B; |
3675 |
wakaba |
1.49 |
} elsif ($token->{tag_name} eq 'body' or |
3676 |
wakaba |
1.25 |
$token->{tag_name} eq 'frameset') { |
3677 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
3678 |
wakaba |
1.79 |
!!!cp ('t122'); |
3679 |
wakaba |
1.49 |
## As if </noscript> |
3680 |
|
|
pop @{$self->{open_elements}}; |
3681 |
wakaba |
1.113 |
!!!parse-error (type => 'in noscript:'.$token->{tag_name}, token => $token); |
3682 |
wakaba |
1.49 |
|
3683 |
|
|
## Reprocess in the "in head" insertion mode... |
3684 |
|
|
## As if </head> |
3685 |
|
|
pop @{$self->{open_elements}}; |
3686 |
|
|
|
3687 |
|
|
## Reprocess in the "after head" insertion mode... |
3688 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_HEAD_IM) { |
3689 |
wakaba |
1.79 |
!!!cp ('t124'); |
3690 |
wakaba |
1.49 |
pop @{$self->{open_elements}}; |
3691 |
|
|
|
3692 |
|
|
## Reprocess in the "after head" insertion mode... |
3693 |
wakaba |
1.79 |
} else { |
3694 |
|
|
!!!cp ('t125'); |
3695 |
wakaba |
1.49 |
} |
3696 |
|
|
|
3697 |
|
|
## "after head" insertion mode |
3698 |
|
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
3699 |
wakaba |
1.54 |
if ($token->{tag_name} eq 'body') { |
3700 |
wakaba |
1.79 |
!!!cp ('t126'); |
3701 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_BODY_IM; |
3702 |
|
|
} elsif ($token->{tag_name} eq 'frameset') { |
3703 |
wakaba |
1.79 |
!!!cp ('t127'); |
3704 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_FRAMESET_IM; |
3705 |
|
|
} else { |
3706 |
|
|
die "$0: tag name: $self->{tag_name}"; |
3707 |
|
|
} |
3708 |
wakaba |
1.1 |
!!!next-token; |
3709 |
|
|
redo B; |
3710 |
|
|
} else { |
3711 |
wakaba |
1.79 |
!!!cp ('t128'); |
3712 |
wakaba |
1.1 |
# |
3713 |
|
|
} |
3714 |
wakaba |
1.49 |
|
3715 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
3716 |
wakaba |
1.79 |
!!!cp ('t129'); |
3717 |
wakaba |
1.49 |
## As if </noscript> |
3718 |
|
|
pop @{$self->{open_elements}}; |
3719 |
wakaba |
1.113 |
!!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token); |
3720 |
wakaba |
1.49 |
|
3721 |
|
|
## Reprocess in the "in head" insertion mode... |
3722 |
|
|
## As if </head> |
3723 |
wakaba |
1.25 |
pop @{$self->{open_elements}}; |
3724 |
wakaba |
1.49 |
|
3725 |
|
|
## Reprocess in the "after head" insertion mode... |
3726 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_HEAD_IM) { |
3727 |
wakaba |
1.79 |
!!!cp ('t130'); |
3728 |
wakaba |
1.49 |
## As if </head> |
3729 |
wakaba |
1.25 |
pop @{$self->{open_elements}}; |
3730 |
wakaba |
1.49 |
|
3731 |
|
|
## Reprocess in the "after head" insertion mode... |
3732 |
wakaba |
1.79 |
} else { |
3733 |
|
|
!!!cp ('t131'); |
3734 |
wakaba |
1.49 |
} |
3735 |
|
|
|
3736 |
|
|
## "after head" insertion mode |
3737 |
|
|
## As if <body> |
3738 |
|
|
!!!insert-element ('body'); |
3739 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_BODY_IM; |
3740 |
wakaba |
1.49 |
## reprocess |
3741 |
|
|
redo B; |
3742 |
wakaba |
1.55 |
} elsif ($token->{type} == END_TAG_TOKEN) { |
3743 |
wakaba |
1.49 |
if ($token->{tag_name} eq 'head') { |
3744 |
wakaba |
1.54 |
if ($self->{insertion_mode} == BEFORE_HEAD_IM) { |
3745 |
wakaba |
1.79 |
!!!cp ('t132'); |
3746 |
wakaba |
1.50 |
## As if <head> |
3747 |
|
|
!!!create-element ($self->{head_element}, 'head'); |
3748 |
|
|
$self->{open_elements}->[-1]->[0]->append_child ($self->{head_element}); |
3749 |
|
|
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
3750 |
|
|
|
3751 |
|
|
## Reprocess in the "in head" insertion mode... |
3752 |
|
|
pop @{$self->{open_elements}}; |
3753 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_HEAD_IM; |
3754 |
wakaba |
1.50 |
!!!next-token; |
3755 |
|
|
redo B; |
3756 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
3757 |
wakaba |
1.79 |
!!!cp ('t133'); |
3758 |
wakaba |
1.49 |
## As if </noscript> |
3759 |
|
|
pop @{$self->{open_elements}}; |
3760 |
wakaba |
1.113 |
!!!parse-error (type => 'in noscript:/head', token => $token); |
3761 |
wakaba |
1.49 |
|
3762 |
|
|
## Reprocess in the "in head" insertion mode... |
3763 |
wakaba |
1.50 |
pop @{$self->{open_elements}}; |
3764 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_HEAD_IM; |
3765 |
wakaba |
1.50 |
!!!next-token; |
3766 |
|
|
redo B; |
3767 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_HEAD_IM) { |
3768 |
wakaba |
1.79 |
!!!cp ('t134'); |
3769 |
wakaba |
1.49 |
pop @{$self->{open_elements}}; |
3770 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_HEAD_IM; |
3771 |
wakaba |
1.49 |
!!!next-token; |
3772 |
|
|
redo B; |
3773 |
|
|
} else { |
3774 |
wakaba |
1.79 |
!!!cp ('t135'); |
3775 |
wakaba |
1.49 |
# |
3776 |
|
|
} |
3777 |
|
|
} elsif ($token->{tag_name} eq 'noscript') { |
3778 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
3779 |
wakaba |
1.79 |
!!!cp ('t136'); |
3780 |
wakaba |
1.49 |
pop @{$self->{open_elements}}; |
3781 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_HEAD_IM; |
3782 |
wakaba |
1.49 |
!!!next-token; |
3783 |
|
|
redo B; |
3784 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) { |
3785 |
wakaba |
1.79 |
!!!cp ('t137'); |
3786 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:noscript', token => $token); |
3787 |
wakaba |
1.50 |
## Ignore the token ## ISSUE: An issue in the spec. |
3788 |
|
|
!!!next-token; |
3789 |
|
|
redo B; |
3790 |
wakaba |
1.49 |
} else { |
3791 |
wakaba |
1.79 |
!!!cp ('t138'); |
3792 |
wakaba |
1.49 |
# |
3793 |
|
|
} |
3794 |
|
|
} elsif ({ |
3795 |
wakaba |
1.31 |
body => 1, html => 1, |
3796 |
|
|
}->{$token->{tag_name}}) { |
3797 |
wakaba |
1.54 |
if ($self->{insertion_mode} == BEFORE_HEAD_IM) { |
3798 |
wakaba |
1.79 |
!!!cp ('t139'); |
3799 |
wakaba |
1.50 |
## As if <head> |
3800 |
|
|
!!!create-element ($self->{head_element}, 'head'); |
3801 |
|
|
$self->{open_elements}->[-1]->[0]->append_child ($self->{head_element}); |
3802 |
|
|
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
3803 |
|
|
|
3804 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_HEAD_IM; |
3805 |
wakaba |
1.50 |
## Reprocess in the "in head" insertion mode... |
3806 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
3807 |
wakaba |
1.79 |
!!!cp ('t140'); |
3808 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
3809 |
wakaba |
1.49 |
## Ignore the token |
3810 |
|
|
!!!next-token; |
3811 |
|
|
redo B; |
3812 |
wakaba |
1.79 |
} else { |
3813 |
|
|
!!!cp ('t141'); |
3814 |
wakaba |
1.49 |
} |
3815 |
wakaba |
1.50 |
|
3816 |
|
|
# |
3817 |
wakaba |
1.49 |
} elsif ({ |
3818 |
wakaba |
1.31 |
p => 1, br => 1, |
3819 |
|
|
}->{$token->{tag_name}}) { |
3820 |
wakaba |
1.54 |
if ($self->{insertion_mode} == BEFORE_HEAD_IM) { |
3821 |
wakaba |
1.79 |
!!!cp ('t142'); |
3822 |
wakaba |
1.50 |
## As if <head> |
3823 |
|
|
!!!create-element ($self->{head_element}, 'head'); |
3824 |
|
|
$self->{open_elements}->[-1]->[0]->append_child ($self->{head_element}); |
3825 |
|
|
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
3826 |
|
|
|
3827 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_HEAD_IM; |
3828 |
wakaba |
1.50 |
## Reprocess in the "in head" insertion mode... |
3829 |
wakaba |
1.79 |
} else { |
3830 |
|
|
!!!cp ('t143'); |
3831 |
wakaba |
1.50 |
} |
3832 |
|
|
|
3833 |
wakaba |
1.1 |
# |
3834 |
wakaba |
1.25 |
} else { |
3835 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HEAD_IM) { |
3836 |
wakaba |
1.79 |
!!!cp ('t144'); |
3837 |
wakaba |
1.54 |
# |
3838 |
|
|
} else { |
3839 |
wakaba |
1.79 |
!!!cp ('t145'); |
3840 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
3841 |
wakaba |
1.49 |
## Ignore the token |
3842 |
|
|
!!!next-token; |
3843 |
|
|
redo B; |
3844 |
|
|
} |
3845 |
|
|
} |
3846 |
|
|
|
3847 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
3848 |
wakaba |
1.79 |
!!!cp ('t146'); |
3849 |
wakaba |
1.49 |
## As if </noscript> |
3850 |
|
|
pop @{$self->{open_elements}}; |
3851 |
wakaba |
1.113 |
!!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token); |
3852 |
wakaba |
1.49 |
|
3853 |
|
|
## Reprocess in the "in head" insertion mode... |
3854 |
|
|
## As if </head> |
3855 |
|
|
pop @{$self->{open_elements}}; |
3856 |
|
|
|
3857 |
|
|
## Reprocess in the "after head" insertion mode... |
3858 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_HEAD_IM) { |
3859 |
wakaba |
1.79 |
!!!cp ('t147'); |
3860 |
wakaba |
1.49 |
## As if </head> |
3861 |
|
|
pop @{$self->{open_elements}}; |
3862 |
|
|
|
3863 |
|
|
## Reprocess in the "after head" insertion mode... |
3864 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) { |
3865 |
wakaba |
1.82 |
## ISSUE: This case cannot be reached? |
3866 |
wakaba |
1.79 |
!!!cp ('t148'); |
3867 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
3868 |
wakaba |
1.50 |
## Ignore the token ## ISSUE: An issue in the spec. |
3869 |
|
|
!!!next-token; |
3870 |
|
|
redo B; |
3871 |
wakaba |
1.79 |
} else { |
3872 |
|
|
!!!cp ('t149'); |
3873 |
wakaba |
1.1 |
} |
3874 |
|
|
|
3875 |
wakaba |
1.49 |
## "after head" insertion mode |
3876 |
|
|
## As if <body> |
3877 |
wakaba |
1.52 |
!!!insert-element ('body'); |
3878 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_BODY_IM; |
3879 |
wakaba |
1.52 |
## reprocess |
3880 |
|
|
redo B; |
3881 |
wakaba |
1.104 |
} elsif ($token->{type} == END_OF_FILE_TOKEN) { |
3882 |
|
|
if ($self->{insertion_mode} == BEFORE_HEAD_IM) { |
3883 |
|
|
!!!cp ('t149.1'); |
3884 |
|
|
|
3885 |
|
|
## NOTE: As if <head> |
3886 |
|
|
!!!create-element ($self->{head_element}, 'head'); |
3887 |
|
|
$self->{open_elements}->[-1]->[0]->append_child |
3888 |
|
|
($self->{head_element}); |
3889 |
|
|
#push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
3890 |
|
|
#$self->{insertion_mode} = IN_HEAD_IM; |
3891 |
|
|
## NOTE: Reprocess. |
3892 |
|
|
|
3893 |
|
|
## NOTE: As if </head> |
3894 |
|
|
#pop @{$self->{open_elements}}; |
3895 |
|
|
#$self->{insertion_mode} = IN_AFTER_HEAD_IM; |
3896 |
|
|
## NOTE: Reprocess. |
3897 |
|
|
|
3898 |
|
|
# |
3899 |
|
|
} elsif ($self->{insertion_mode} == IN_HEAD_IM) { |
3900 |
|
|
!!!cp ('t149.2'); |
3901 |
|
|
|
3902 |
|
|
## NOTE: As if </head> |
3903 |
|
|
pop @{$self->{open_elements}}; |
3904 |
|
|
#$self->{insertion_mode} = IN_AFTER_HEAD_IM; |
3905 |
|
|
## NOTE: Reprocess. |
3906 |
|
|
|
3907 |
|
|
# |
3908 |
|
|
} elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
3909 |
|
|
!!!cp ('t149.3'); |
3910 |
|
|
|
3911 |
wakaba |
1.113 |
!!!parse-error (type => 'in noscript:#eof', token => $token); |
3912 |
wakaba |
1.104 |
|
3913 |
|
|
## As if </noscript> |
3914 |
|
|
pop @{$self->{open_elements}}; |
3915 |
|
|
#$self->{insertion_mode} = IN_HEAD_IM; |
3916 |
|
|
## NOTE: Reprocess. |
3917 |
|
|
|
3918 |
|
|
## NOTE: As if </head> |
3919 |
|
|
pop @{$self->{open_elements}}; |
3920 |
|
|
#$self->{insertion_mode} = IN_AFTER_HEAD_IM; |
3921 |
|
|
## NOTE: Reprocess. |
3922 |
|
|
|
3923 |
|
|
# |
3924 |
|
|
} else { |
3925 |
|
|
!!!cp ('t149.4'); |
3926 |
|
|
# |
3927 |
|
|
} |
3928 |
|
|
|
3929 |
|
|
## NOTE: As if <body> |
3930 |
|
|
!!!insert-element ('body'); |
3931 |
|
|
$self->{insertion_mode} = IN_BODY_IM; |
3932 |
|
|
## NOTE: Reprocess. |
3933 |
|
|
redo B; |
3934 |
|
|
} else { |
3935 |
|
|
die "$0: $token->{type}: Unknown token type"; |
3936 |
|
|
} |
3937 |
wakaba |
1.52 |
|
3938 |
|
|
## ISSUE: An issue in the spec. |
3939 |
wakaba |
1.56 |
} elsif ($self->{insertion_mode} & BODY_IMS) { |
3940 |
wakaba |
1.55 |
if ($token->{type} == CHARACTER_TOKEN) { |
3941 |
wakaba |
1.79 |
!!!cp ('t150'); |
3942 |
wakaba |
1.52 |
## NOTE: There is a code clone of "character in body". |
3943 |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
3944 |
|
|
|
3945 |
|
|
$self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data}); |
3946 |
|
|
|
3947 |
|
|
!!!next-token; |
3948 |
|
|
redo B; |
3949 |
wakaba |
1.55 |
} elsif ($token->{type} == START_TAG_TOKEN) { |
3950 |
wakaba |
1.52 |
if ({ |
3951 |
|
|
caption => 1, col => 1, colgroup => 1, tbody => 1, |
3952 |
|
|
td => 1, tfoot => 1, th => 1, thead => 1, tr => 1, |
3953 |
|
|
}->{$token->{tag_name}}) { |
3954 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_CELL_IM) { |
3955 |
wakaba |
1.52 |
## have an element in table scope |
3956 |
wakaba |
1.108 |
for (reverse 0..$#{$self->{open_elements}}) { |
3957 |
wakaba |
1.52 |
my $node = $self->{open_elements}->[$_]; |
3958 |
|
|
if ($node->[1] eq 'td' or $node->[1] eq 'th') { |
3959 |
wakaba |
1.79 |
!!!cp ('t151'); |
3960 |
wakaba |
1.108 |
|
3961 |
|
|
## Close the cell |
3962 |
|
|
!!!back-token; # <?> |
3963 |
wakaba |
1.114 |
$token = {type => END_TAG_TOKEN, tag_name => $node->[1], |
3964 |
|
|
line => $token->{line}, |
3965 |
|
|
column => $token->{column}}; |
3966 |
wakaba |
1.108 |
redo B; |
3967 |
wakaba |
1.52 |
} elsif ({ |
3968 |
|
|
table => 1, html => 1, |
3969 |
|
|
}->{$node->[1]}) { |
3970 |
wakaba |
1.79 |
!!!cp ('t152'); |
3971 |
wakaba |
1.108 |
## ISSUE: This case can never be reached, maybe. |
3972 |
|
|
last; |
3973 |
wakaba |
1.52 |
} |
3974 |
wakaba |
1.108 |
} |
3975 |
|
|
|
3976 |
|
|
!!!cp ('t153'); |
3977 |
|
|
!!!parse-error (type => 'start tag not allowed', |
3978 |
wakaba |
1.113 |
value => $token->{tag_name}, token => $token); |
3979 |
wakaba |
1.108 |
## Ignore the token |
3980 |
|
|
!!!next-token; |
3981 |
wakaba |
1.52 |
redo B; |
3982 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_CAPTION_IM) { |
3983 |
wakaba |
1.113 |
!!!parse-error (type => 'not closed:caption', token => $token); |
3984 |
wakaba |
1.52 |
|
3985 |
wakaba |
1.108 |
## NOTE: As if </caption>. |
3986 |
wakaba |
1.52 |
## have a table element in table scope |
3987 |
|
|
my $i; |
3988 |
wakaba |
1.108 |
INSCOPE: { |
3989 |
|
|
for (reverse 0..$#{$self->{open_elements}}) { |
3990 |
|
|
my $node = $self->{open_elements}->[$_]; |
3991 |
|
|
if ($node->[1] eq 'caption') { |
3992 |
|
|
!!!cp ('t155'); |
3993 |
|
|
$i = $_; |
3994 |
|
|
last INSCOPE; |
3995 |
|
|
} elsif ({ |
3996 |
|
|
table => 1, html => 1, |
3997 |
|
|
}->{$node->[1]}) { |
3998 |
|
|
!!!cp ('t156'); |
3999 |
|
|
last; |
4000 |
|
|
} |
4001 |
wakaba |
1.52 |
} |
4002 |
wakaba |
1.108 |
|
4003 |
|
|
!!!cp ('t157'); |
4004 |
|
|
!!!parse-error (type => 'start tag not allowed', |
4005 |
wakaba |
1.113 |
value => $token->{tag_name}, token => $token); |
4006 |
wakaba |
1.108 |
## Ignore the token |
4007 |
|
|
!!!next-token; |
4008 |
|
|
redo B; |
4009 |
wakaba |
1.52 |
} # INSCOPE |
4010 |
|
|
|
4011 |
|
|
## generate implied end tags |
4012 |
wakaba |
1.86 |
while ({ |
4013 |
|
|
dd => 1, dt => 1, li => 1, p => 1, |
4014 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4015 |
wakaba |
1.79 |
!!!cp ('t158'); |
4016 |
wakaba |
1.86 |
pop @{$self->{open_elements}}; |
4017 |
wakaba |
1.52 |
} |
4018 |
|
|
|
4019 |
|
|
if ($self->{open_elements}->[-1]->[1] ne 'caption') { |
4020 |
wakaba |
1.79 |
!!!cp ('t159'); |
4021 |
wakaba |
1.113 |
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token); |
4022 |
wakaba |
1.79 |
} else { |
4023 |
|
|
!!!cp ('t160'); |
4024 |
wakaba |
1.52 |
} |
4025 |
|
|
|
4026 |
|
|
splice @{$self->{open_elements}}, $i; |
4027 |
|
|
|
4028 |
|
|
$clear_up_to_marker->(); |
4029 |
|
|
|
4030 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_IM; |
4031 |
wakaba |
1.52 |
|
4032 |
|
|
## reprocess |
4033 |
|
|
redo B; |
4034 |
|
|
} else { |
4035 |
wakaba |
1.79 |
!!!cp ('t161'); |
4036 |
wakaba |
1.52 |
# |
4037 |
|
|
} |
4038 |
|
|
} else { |
4039 |
wakaba |
1.79 |
!!!cp ('t162'); |
4040 |
wakaba |
1.52 |
# |
4041 |
|
|
} |
4042 |
wakaba |
1.55 |
} elsif ($token->{type} == END_TAG_TOKEN) { |
4043 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'td' or $token->{tag_name} eq 'th') { |
4044 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_CELL_IM) { |
4045 |
wakaba |
1.43 |
## have an element in table scope |
4046 |
wakaba |
1.52 |
my $i; |
4047 |
wakaba |
1.43 |
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4048 |
|
|
my $node = $self->{open_elements}->[$_]; |
4049 |
wakaba |
1.52 |
if ($node->[1] eq $token->{tag_name}) { |
4050 |
wakaba |
1.79 |
!!!cp ('t163'); |
4051 |
wakaba |
1.52 |
$i = $_; |
4052 |
wakaba |
1.43 |
last INSCOPE; |
4053 |
|
|
} elsif ({ |
4054 |
|
|
table => 1, html => 1, |
4055 |
|
|
}->{$node->[1]}) { |
4056 |
wakaba |
1.79 |
!!!cp ('t164'); |
4057 |
wakaba |
1.43 |
last INSCOPE; |
4058 |
|
|
} |
4059 |
|
|
} # INSCOPE |
4060 |
wakaba |
1.52 |
unless (defined $i) { |
4061 |
wakaba |
1.79 |
!!!cp ('t165'); |
4062 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
4063 |
wakaba |
1.43 |
## Ignore the token |
4064 |
|
|
!!!next-token; |
4065 |
|
|
redo B; |
4066 |
|
|
} |
4067 |
|
|
|
4068 |
wakaba |
1.52 |
## generate implied end tags |
4069 |
wakaba |
1.86 |
while ({ |
4070 |
|
|
dd => 1, dt => 1, li => 1, p => 1, |
4071 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4072 |
wakaba |
1.79 |
!!!cp ('t166'); |
4073 |
wakaba |
1.86 |
pop @{$self->{open_elements}}; |
4074 |
wakaba |
1.52 |
} |
4075 |
wakaba |
1.86 |
|
4076 |
wakaba |
1.52 |
if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) { |
4077 |
wakaba |
1.79 |
!!!cp ('t167'); |
4078 |
wakaba |
1.113 |
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token); |
4079 |
wakaba |
1.79 |
} else { |
4080 |
|
|
!!!cp ('t168'); |
4081 |
wakaba |
1.52 |
} |
4082 |
|
|
|
4083 |
|
|
splice @{$self->{open_elements}}, $i; |
4084 |
|
|
|
4085 |
|
|
$clear_up_to_marker->(); |
4086 |
|
|
|
4087 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_ROW_IM; |
4088 |
wakaba |
1.52 |
|
4089 |
|
|
!!!next-token; |
4090 |
wakaba |
1.43 |
redo B; |
4091 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_CAPTION_IM) { |
4092 |
wakaba |
1.79 |
!!!cp ('t169'); |
4093 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
4094 |
wakaba |
1.52 |
## Ignore the token |
4095 |
|
|
!!!next-token; |
4096 |
|
|
redo B; |
4097 |
|
|
} else { |
4098 |
wakaba |
1.79 |
!!!cp ('t170'); |
4099 |
wakaba |
1.52 |
# |
4100 |
|
|
} |
4101 |
|
|
} elsif ($token->{tag_name} eq 'caption') { |
4102 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_CAPTION_IM) { |
4103 |
wakaba |
1.43 |
## have a table element in table scope |
4104 |
|
|
my $i; |
4105 |
wakaba |
1.108 |
INSCOPE: { |
4106 |
|
|
for (reverse 0..$#{$self->{open_elements}}) { |
4107 |
|
|
my $node = $self->{open_elements}->[$_]; |
4108 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
4109 |
|
|
!!!cp ('t171'); |
4110 |
|
|
$i = $_; |
4111 |
|
|
last INSCOPE; |
4112 |
|
|
} elsif ({ |
4113 |
|
|
table => 1, html => 1, |
4114 |
|
|
}->{$node->[1]}) { |
4115 |
|
|
!!!cp ('t172'); |
4116 |
|
|
last; |
4117 |
|
|
} |
4118 |
wakaba |
1.43 |
} |
4119 |
wakaba |
1.108 |
|
4120 |
|
|
!!!cp ('t173'); |
4121 |
|
|
!!!parse-error (type => 'unmatched end tag', |
4122 |
wakaba |
1.113 |
value => $token->{tag_name}, token => $token); |
4123 |
wakaba |
1.108 |
## Ignore the token |
4124 |
|
|
!!!next-token; |
4125 |
|
|
redo B; |
4126 |
wakaba |
1.43 |
} # INSCOPE |
4127 |
|
|
|
4128 |
|
|
## generate implied end tags |
4129 |
wakaba |
1.86 |
while ({ |
4130 |
|
|
dd => 1, dt => 1, li => 1, p => 1, |
4131 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4132 |
wakaba |
1.79 |
!!!cp ('t174'); |
4133 |
wakaba |
1.86 |
pop @{$self->{open_elements}}; |
4134 |
wakaba |
1.43 |
} |
4135 |
wakaba |
1.52 |
|
4136 |
|
|
if ($self->{open_elements}->[-1]->[1] ne 'caption') { |
4137 |
wakaba |
1.79 |
!!!cp ('t175'); |
4138 |
wakaba |
1.113 |
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token); |
4139 |
wakaba |
1.79 |
} else { |
4140 |
|
|
!!!cp ('t176'); |
4141 |
wakaba |
1.52 |
} |
4142 |
|
|
|
4143 |
|
|
splice @{$self->{open_elements}}, $i; |
4144 |
|
|
|
4145 |
|
|
$clear_up_to_marker->(); |
4146 |
|
|
|
4147 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_IM; |
4148 |
wakaba |
1.52 |
|
4149 |
|
|
!!!next-token; |
4150 |
|
|
redo B; |
4151 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_CELL_IM) { |
4152 |
wakaba |
1.79 |
!!!cp ('t177'); |
4153 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
4154 |
wakaba |
1.52 |
## Ignore the token |
4155 |
|
|
!!!next-token; |
4156 |
|
|
redo B; |
4157 |
|
|
} else { |
4158 |
wakaba |
1.79 |
!!!cp ('t178'); |
4159 |
wakaba |
1.52 |
# |
4160 |
|
|
} |
4161 |
|
|
} elsif ({ |
4162 |
|
|
table => 1, tbody => 1, tfoot => 1, |
4163 |
|
|
thead => 1, tr => 1, |
4164 |
|
|
}->{$token->{tag_name}} and |
4165 |
wakaba |
1.54 |
$self->{insertion_mode} == IN_CELL_IM) { |
4166 |
wakaba |
1.52 |
## have an element in table scope |
4167 |
|
|
my $i; |
4168 |
|
|
my $tn; |
4169 |
wakaba |
1.108 |
INSCOPE: { |
4170 |
|
|
for (reverse 0..$#{$self->{open_elements}}) { |
4171 |
|
|
my $node = $self->{open_elements}->[$_]; |
4172 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
4173 |
|
|
!!!cp ('t179'); |
4174 |
|
|
$i = $_; |
4175 |
|
|
|
4176 |
|
|
## Close the cell |
4177 |
|
|
!!!back-token; # </?> |
4178 |
wakaba |
1.114 |
$token = {type => END_TAG_TOKEN, tag_name => $tn, |
4179 |
|
|
line => $token->{line}, |
4180 |
|
|
column => $token->{column}}; |
4181 |
wakaba |
1.108 |
redo B; |
4182 |
|
|
} elsif ($node->[1] eq 'td' or $node->[1] eq 'th') { |
4183 |
|
|
!!!cp ('t180'); |
4184 |
|
|
$tn = $node->[1]; |
4185 |
|
|
## NOTE: There is exactly one |td| or |th| element |
4186 |
|
|
## in scope in the stack of open elements by definition. |
4187 |
|
|
} elsif ({ |
4188 |
|
|
table => 1, html => 1, |
4189 |
|
|
}->{$node->[1]}) { |
4190 |
|
|
## ISSUE: Can this be reached? |
4191 |
|
|
!!!cp ('t181'); |
4192 |
|
|
last; |
4193 |
|
|
} |
4194 |
wakaba |
1.52 |
} |
4195 |
wakaba |
1.108 |
|
4196 |
wakaba |
1.79 |
!!!cp ('t182'); |
4197 |
wakaba |
1.108 |
!!!parse-error (type => 'unmatched end tag', |
4198 |
wakaba |
1.113 |
value => $token->{tag_name}, token => $token); |
4199 |
wakaba |
1.52 |
## Ignore the token |
4200 |
|
|
!!!next-token; |
4201 |
|
|
redo B; |
4202 |
wakaba |
1.108 |
} # INSCOPE |
4203 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'table' and |
4204 |
wakaba |
1.54 |
$self->{insertion_mode} == IN_CAPTION_IM) { |
4205 |
wakaba |
1.113 |
!!!parse-error (type => 'not closed:caption', token => $token); |
4206 |
wakaba |
1.52 |
|
4207 |
|
|
## As if </caption> |
4208 |
|
|
## have a table element in table scope |
4209 |
|
|
my $i; |
4210 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4211 |
|
|
my $node = $self->{open_elements}->[$_]; |
4212 |
|
|
if ($node->[1] eq 'caption') { |
4213 |
wakaba |
1.79 |
!!!cp ('t184'); |
4214 |
wakaba |
1.52 |
$i = $_; |
4215 |
|
|
last INSCOPE; |
4216 |
|
|
} elsif ({ |
4217 |
|
|
table => 1, html => 1, |
4218 |
|
|
}->{$node->[1]}) { |
4219 |
wakaba |
1.79 |
!!!cp ('t185'); |
4220 |
wakaba |
1.52 |
last INSCOPE; |
4221 |
|
|
} |
4222 |
|
|
} # INSCOPE |
4223 |
|
|
unless (defined $i) { |
4224 |
wakaba |
1.79 |
!!!cp ('t186'); |
4225 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:caption', token => $token); |
4226 |
wakaba |
1.52 |
## Ignore the token |
4227 |
|
|
!!!next-token; |
4228 |
|
|
redo B; |
4229 |
|
|
} |
4230 |
|
|
|
4231 |
|
|
## generate implied end tags |
4232 |
wakaba |
1.86 |
while ({ |
4233 |
|
|
dd => 1, dt => 1, li => 1, p => 1, |
4234 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4235 |
wakaba |
1.79 |
!!!cp ('t187'); |
4236 |
wakaba |
1.86 |
pop @{$self->{open_elements}}; |
4237 |
wakaba |
1.52 |
} |
4238 |
|
|
|
4239 |
|
|
if ($self->{open_elements}->[-1]->[1] ne 'caption') { |
4240 |
wakaba |
1.79 |
!!!cp ('t188'); |
4241 |
wakaba |
1.113 |
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token); |
4242 |
wakaba |
1.79 |
} else { |
4243 |
|
|
!!!cp ('t189'); |
4244 |
wakaba |
1.52 |
} |
4245 |
|
|
|
4246 |
|
|
splice @{$self->{open_elements}}, $i; |
4247 |
|
|
|
4248 |
|
|
$clear_up_to_marker->(); |
4249 |
|
|
|
4250 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_IM; |
4251 |
wakaba |
1.52 |
|
4252 |
|
|
## reprocess |
4253 |
|
|
redo B; |
4254 |
|
|
} elsif ({ |
4255 |
|
|
body => 1, col => 1, colgroup => 1, html => 1, |
4256 |
|
|
}->{$token->{tag_name}}) { |
4257 |
wakaba |
1.56 |
if ($self->{insertion_mode} & BODY_TABLE_IMS) { |
4258 |
wakaba |
1.79 |
!!!cp ('t190'); |
4259 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
4260 |
wakaba |
1.52 |
## Ignore the token |
4261 |
|
|
!!!next-token; |
4262 |
|
|
redo B; |
4263 |
|
|
} else { |
4264 |
wakaba |
1.79 |
!!!cp ('t191'); |
4265 |
wakaba |
1.52 |
# |
4266 |
|
|
} |
4267 |
|
|
} elsif ({ |
4268 |
|
|
tbody => 1, tfoot => 1, |
4269 |
|
|
thead => 1, tr => 1, |
4270 |
|
|
}->{$token->{tag_name}} and |
4271 |
wakaba |
1.54 |
$self->{insertion_mode} == IN_CAPTION_IM) { |
4272 |
wakaba |
1.79 |
!!!cp ('t192'); |
4273 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
4274 |
wakaba |
1.52 |
## Ignore the token |
4275 |
|
|
!!!next-token; |
4276 |
|
|
redo B; |
4277 |
|
|
} else { |
4278 |
wakaba |
1.79 |
!!!cp ('t193'); |
4279 |
wakaba |
1.52 |
# |
4280 |
|
|
} |
4281 |
wakaba |
1.104 |
} elsif ($token->{type} == END_OF_FILE_TOKEN) { |
4282 |
|
|
for my $entry (@{$self->{open_elements}}) { |
4283 |
|
|
if (not { |
4284 |
|
|
dd => 1, dt => 1, li => 1, p => 1, tbody => 1, td => 1, tfoot => 1, |
4285 |
|
|
th => 1, thead => 1, tr => 1, body => 1, html => 1, |
4286 |
|
|
}->{$entry->[1]}) { |
4287 |
|
|
!!!cp ('t75'); |
4288 |
wakaba |
1.113 |
!!!parse-error (type => 'in body:#eof', token => $token); |
4289 |
wakaba |
1.104 |
last; |
4290 |
|
|
} |
4291 |
|
|
} |
4292 |
|
|
|
4293 |
|
|
## Stop parsing. |
4294 |
|
|
last B; |
4295 |
wakaba |
1.52 |
} else { |
4296 |
|
|
die "$0: $token->{type}: Unknown token type"; |
4297 |
|
|
} |
4298 |
|
|
|
4299 |
|
|
$insert = $insert_to_current; |
4300 |
|
|
# |
4301 |
wakaba |
1.56 |
} elsif ($self->{insertion_mode} & TABLE_IMS) { |
4302 |
wakaba |
1.58 |
if ($token->{type} == CHARACTER_TOKEN) { |
4303 |
wakaba |
1.95 |
if (not $open_tables->[-1]->[1] and # tainted |
4304 |
|
|
$token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { |
4305 |
|
|
$self->{open_elements}->[-1]->[0]->manakai_append_text ($1); |
4306 |
wakaba |
1.52 |
|
4307 |
wakaba |
1.95 |
unless (length $token->{data}) { |
4308 |
|
|
!!!cp ('t194'); |
4309 |
|
|
!!!next-token; |
4310 |
|
|
redo B; |
4311 |
|
|
} else { |
4312 |
|
|
!!!cp ('t195'); |
4313 |
|
|
} |
4314 |
|
|
} |
4315 |
wakaba |
1.52 |
|
4316 |
wakaba |
1.113 |
!!!parse-error (type => 'in table:#character', token => $token); |
4317 |
wakaba |
1.52 |
|
4318 |
|
|
## As if in body, but insert into foster parent element |
4319 |
|
|
## ISSUE: Spec says that "whenever a node would be inserted |
4320 |
|
|
## into the current node" while characters might not be |
4321 |
|
|
## result in a new Text node. |
4322 |
|
|
$reconstruct_active_formatting_elements->($insert_to_foster); |
4323 |
|
|
|
4324 |
|
|
if ({ |
4325 |
|
|
table => 1, tbody => 1, tfoot => 1, |
4326 |
|
|
thead => 1, tr => 1, |
4327 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4328 |
|
|
# MUST |
4329 |
|
|
my $foster_parent_element; |
4330 |
|
|
my $next_sibling; |
4331 |
|
|
my $prev_sibling; |
4332 |
|
|
OE: for (reverse 0..$#{$self->{open_elements}}) { |
4333 |
|
|
if ($self->{open_elements}->[$_]->[1] eq 'table') { |
4334 |
|
|
my $parent = $self->{open_elements}->[$_]->[0]->parent_node; |
4335 |
|
|
if (defined $parent and $parent->node_type == 1) { |
4336 |
wakaba |
1.79 |
!!!cp ('t196'); |
4337 |
wakaba |
1.52 |
$foster_parent_element = $parent; |
4338 |
|
|
$next_sibling = $self->{open_elements}->[$_]->[0]; |
4339 |
|
|
$prev_sibling = $next_sibling->previous_sibling; |
4340 |
|
|
} else { |
4341 |
wakaba |
1.79 |
!!!cp ('t197'); |
4342 |
wakaba |
1.52 |
$foster_parent_element = $self->{open_elements}->[$_ - 1]->[0]; |
4343 |
|
|
$prev_sibling = $foster_parent_element->last_child; |
4344 |
|
|
} |
4345 |
|
|
last OE; |
4346 |
|
|
} |
4347 |
|
|
} # OE |
4348 |
|
|
$foster_parent_element = $self->{open_elements}->[0]->[0] and |
4349 |
|
|
$prev_sibling = $foster_parent_element->last_child |
4350 |
|
|
unless defined $foster_parent_element; |
4351 |
|
|
if (defined $prev_sibling and |
4352 |
|
|
$prev_sibling->node_type == 3) { |
4353 |
wakaba |
1.79 |
!!!cp ('t198'); |
4354 |
wakaba |
1.52 |
$prev_sibling->manakai_append_text ($token->{data}); |
4355 |
|
|
} else { |
4356 |
wakaba |
1.79 |
!!!cp ('t199'); |
4357 |
wakaba |
1.52 |
$foster_parent_element->insert_before |
4358 |
|
|
($self->{document}->create_text_node ($token->{data}), |
4359 |
|
|
$next_sibling); |
4360 |
|
|
} |
4361 |
wakaba |
1.95 |
$open_tables->[-1]->[1] = 1; # tainted |
4362 |
|
|
} else { |
4363 |
|
|
!!!cp ('t200'); |
4364 |
|
|
$self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data}); |
4365 |
|
|
} |
4366 |
wakaba |
1.52 |
|
4367 |
wakaba |
1.95 |
!!!next-token; |
4368 |
|
|
redo B; |
4369 |
wakaba |
1.58 |
} elsif ($token->{type} == START_TAG_TOKEN) { |
4370 |
wakaba |
1.52 |
if ({ |
4371 |
wakaba |
1.54 |
tr => ($self->{insertion_mode} != IN_ROW_IM), |
4372 |
wakaba |
1.52 |
th => 1, td => 1, |
4373 |
|
|
}->{$token->{tag_name}}) { |
4374 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_TABLE_IM) { |
4375 |
wakaba |
1.52 |
## Clear back to table context |
4376 |
|
|
while ($self->{open_elements}->[-1]->[1] ne 'table' and |
4377 |
|
|
$self->{open_elements}->[-1]->[1] ne 'html') { |
4378 |
wakaba |
1.79 |
!!!cp ('t201'); |
4379 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; |
4380 |
wakaba |
1.43 |
} |
4381 |
|
|
|
4382 |
wakaba |
1.52 |
!!!insert-element ('tbody'); |
4383 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_BODY_IM; |
4384 |
wakaba |
1.52 |
## reprocess in the "in table body" insertion mode... |
4385 |
|
|
} |
4386 |
|
|
|
4387 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_TABLE_BODY_IM) { |
4388 |
wakaba |
1.52 |
unless ($token->{tag_name} eq 'tr') { |
4389 |
wakaba |
1.79 |
!!!cp ('t202'); |
4390 |
wakaba |
1.113 |
!!!parse-error (type => 'missing start tag:tr', token => $token); |
4391 |
wakaba |
1.52 |
} |
4392 |
wakaba |
1.43 |
|
4393 |
wakaba |
1.52 |
## Clear back to table body context |
4394 |
|
|
while (not { |
4395 |
|
|
tbody => 1, tfoot => 1, thead => 1, html => 1, |
4396 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4397 |
wakaba |
1.79 |
!!!cp ('t203'); |
4398 |
wakaba |
1.83 |
## ISSUE: Can this case be reached? |
4399 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; |
4400 |
|
|
} |
4401 |
wakaba |
1.43 |
|
4402 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_ROW_IM; |
4403 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'tr') { |
4404 |
wakaba |
1.79 |
!!!cp ('t204'); |
4405 |
wakaba |
1.52 |
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
4406 |
|
|
!!!next-token; |
4407 |
|
|
redo B; |
4408 |
|
|
} else { |
4409 |
wakaba |
1.79 |
!!!cp ('t205'); |
4410 |
wakaba |
1.52 |
!!!insert-element ('tr'); |
4411 |
|
|
## reprocess in the "in row" insertion mode |
4412 |
|
|
} |
4413 |
wakaba |
1.79 |
} else { |
4414 |
|
|
!!!cp ('t206'); |
4415 |
wakaba |
1.52 |
} |
4416 |
|
|
|
4417 |
|
|
## Clear back to table row context |
4418 |
|
|
while (not { |
4419 |
|
|
tr => 1, html => 1, |
4420 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4421 |
wakaba |
1.79 |
!!!cp ('t207'); |
4422 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; |
4423 |
wakaba |
1.43 |
} |
4424 |
wakaba |
1.52 |
|
4425 |
|
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
4426 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_CELL_IM; |
4427 |
wakaba |
1.52 |
|
4428 |
|
|
push @$active_formatting_elements, ['#marker', '']; |
4429 |
|
|
|
4430 |
|
|
!!!next-token; |
4431 |
|
|
redo B; |
4432 |
|
|
} elsif ({ |
4433 |
|
|
caption => 1, col => 1, colgroup => 1, |
4434 |
|
|
tbody => 1, tfoot => 1, thead => 1, |
4435 |
wakaba |
1.54 |
tr => 1, # $self->{insertion_mode} == IN_ROW_IM |
4436 |
wakaba |
1.52 |
}->{$token->{tag_name}}) { |
4437 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_ROW_IM) { |
4438 |
wakaba |
1.52 |
## As if </tr> |
4439 |
wakaba |
1.43 |
## have an element in table scope |
4440 |
|
|
my $i; |
4441 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4442 |
|
|
my $node = $self->{open_elements}->[$_]; |
4443 |
wakaba |
1.52 |
if ($node->[1] eq 'tr') { |
4444 |
wakaba |
1.79 |
!!!cp ('t208'); |
4445 |
wakaba |
1.43 |
$i = $_; |
4446 |
|
|
last INSCOPE; |
4447 |
|
|
} elsif ({ |
4448 |
wakaba |
1.83 |
html => 1, |
4449 |
|
|
|
4450 |
|
|
## NOTE: This element does not appear here, maybe. |
4451 |
|
|
table => 1, |
4452 |
wakaba |
1.43 |
}->{$node->[1]}) { |
4453 |
wakaba |
1.79 |
!!!cp ('t209'); |
4454 |
wakaba |
1.43 |
last INSCOPE; |
4455 |
|
|
} |
4456 |
|
|
} # INSCOPE |
4457 |
wakaba |
1.79 |
unless (defined $i) { |
4458 |
|
|
!!!cp ('t210'); |
4459 |
wakaba |
1.83 |
## TODO: This type is wrong. |
4460 |
wakaba |
1.113 |
!!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name}, token => $token); |
4461 |
wakaba |
1.52 |
## Ignore the token |
4462 |
|
|
!!!next-token; |
4463 |
wakaba |
1.43 |
redo B; |
4464 |
|
|
} |
4465 |
|
|
|
4466 |
wakaba |
1.52 |
## Clear back to table row context |
4467 |
|
|
while (not { |
4468 |
|
|
tr => 1, html => 1, |
4469 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4470 |
wakaba |
1.79 |
!!!cp ('t211'); |
4471 |
wakaba |
1.83 |
## ISSUE: Can this case be reached? |
4472 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; |
4473 |
wakaba |
1.1 |
} |
4474 |
wakaba |
1.43 |
|
4475 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; # tr |
4476 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_BODY_IM; |
4477 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'tr') { |
4478 |
wakaba |
1.79 |
!!!cp ('t212'); |
4479 |
wakaba |
1.52 |
## reprocess |
4480 |
|
|
redo B; |
4481 |
|
|
} else { |
4482 |
wakaba |
1.79 |
!!!cp ('t213'); |
4483 |
wakaba |
1.52 |
## reprocess in the "in table body" insertion mode... |
4484 |
|
|
} |
4485 |
wakaba |
1.1 |
} |
4486 |
wakaba |
1.52 |
|
4487 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_TABLE_BODY_IM) { |
4488 |
wakaba |
1.52 |
## have an element in table scope |
4489 |
wakaba |
1.43 |
my $i; |
4490 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4491 |
|
|
my $node = $self->{open_elements}->[$_]; |
4492 |
wakaba |
1.52 |
if ({ |
4493 |
|
|
tbody => 1, thead => 1, tfoot => 1, |
4494 |
|
|
}->{$node->[1]}) { |
4495 |
wakaba |
1.79 |
!!!cp ('t214'); |
4496 |
wakaba |
1.43 |
$i = $_; |
4497 |
|
|
last INSCOPE; |
4498 |
|
|
} elsif ({ |
4499 |
|
|
table => 1, html => 1, |
4500 |
|
|
}->{$node->[1]}) { |
4501 |
wakaba |
1.79 |
!!!cp ('t215'); |
4502 |
wakaba |
1.43 |
last INSCOPE; |
4503 |
|
|
} |
4504 |
|
|
} # INSCOPE |
4505 |
wakaba |
1.52 |
unless (defined $i) { |
4506 |
wakaba |
1.79 |
!!!cp ('t216'); |
4507 |
wakaba |
1.82 |
## TODO: This erorr type ios wrong. |
4508 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
4509 |
wakaba |
1.52 |
## Ignore the token |
4510 |
|
|
!!!next-token; |
4511 |
wakaba |
1.43 |
redo B; |
4512 |
|
|
} |
4513 |
wakaba |
1.52 |
|
4514 |
|
|
## Clear back to table body context |
4515 |
|
|
while (not { |
4516 |
|
|
tbody => 1, tfoot => 1, thead => 1, html => 1, |
4517 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4518 |
wakaba |
1.79 |
!!!cp ('t217'); |
4519 |
wakaba |
1.83 |
## ISSUE: Can this state be reached? |
4520 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; |
4521 |
wakaba |
1.43 |
} |
4522 |
|
|
|
4523 |
wakaba |
1.52 |
## As if <{current node}> |
4524 |
|
|
## have an element in table scope |
4525 |
|
|
## true by definition |
4526 |
wakaba |
1.43 |
|
4527 |
wakaba |
1.52 |
## Clear back to table body context |
4528 |
|
|
## nop by definition |
4529 |
wakaba |
1.43 |
|
4530 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; |
4531 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_IM; |
4532 |
wakaba |
1.52 |
## reprocess in "in table" insertion mode... |
4533 |
wakaba |
1.79 |
} else { |
4534 |
|
|
!!!cp ('t218'); |
4535 |
wakaba |
1.52 |
} |
4536 |
|
|
|
4537 |
|
|
if ($token->{tag_name} eq 'col') { |
4538 |
|
|
## Clear back to table context |
4539 |
|
|
while ($self->{open_elements}->[-1]->[1] ne 'table' and |
4540 |
|
|
$self->{open_elements}->[-1]->[1] ne 'html') { |
4541 |
wakaba |
1.79 |
!!!cp ('t219'); |
4542 |
wakaba |
1.83 |
## ISSUE: Can this state be reached? |
4543 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; |
4544 |
|
|
} |
4545 |
wakaba |
1.43 |
|
4546 |
wakaba |
1.52 |
!!!insert-element ('colgroup'); |
4547 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_COLUMN_GROUP_IM; |
4548 |
wakaba |
1.52 |
## reprocess |
4549 |
wakaba |
1.43 |
redo B; |
4550 |
wakaba |
1.52 |
} elsif ({ |
4551 |
|
|
caption => 1, |
4552 |
|
|
colgroup => 1, |
4553 |
|
|
tbody => 1, tfoot => 1, thead => 1, |
4554 |
|
|
}->{$token->{tag_name}}) { |
4555 |
|
|
## Clear back to table context |
4556 |
|
|
while ($self->{open_elements}->[-1]->[1] ne 'table' and |
4557 |
|
|
$self->{open_elements}->[-1]->[1] ne 'html') { |
4558 |
wakaba |
1.79 |
!!!cp ('t220'); |
4559 |
wakaba |
1.83 |
## ISSUE: Can this state be reached? |
4560 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; |
4561 |
wakaba |
1.1 |
} |
4562 |
wakaba |
1.52 |
|
4563 |
|
|
push @$active_formatting_elements, ['#marker', ''] |
4564 |
|
|
if $token->{tag_name} eq 'caption'; |
4565 |
|
|
|
4566 |
|
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
4567 |
|
|
$self->{insertion_mode} = { |
4568 |
wakaba |
1.54 |
caption => IN_CAPTION_IM, |
4569 |
|
|
colgroup => IN_COLUMN_GROUP_IM, |
4570 |
|
|
tbody => IN_TABLE_BODY_IM, |
4571 |
|
|
tfoot => IN_TABLE_BODY_IM, |
4572 |
|
|
thead => IN_TABLE_BODY_IM, |
4573 |
wakaba |
1.52 |
}->{$token->{tag_name}}; |
4574 |
wakaba |
1.1 |
!!!next-token; |
4575 |
|
|
redo B; |
4576 |
wakaba |
1.52 |
} else { |
4577 |
|
|
die "$0: in table: <>: $token->{tag_name}"; |
4578 |
wakaba |
1.1 |
} |
4579 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'table') { |
4580 |
wakaba |
1.113 |
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token); |
4581 |
wakaba |
1.1 |
|
4582 |
wakaba |
1.52 |
## As if </table> |
4583 |
wakaba |
1.1 |
## have a table element in table scope |
4584 |
|
|
my $i; |
4585 |
wakaba |
1.3 |
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4586 |
|
|
my $node = $self->{open_elements}->[$_]; |
4587 |
wakaba |
1.52 |
if ($node->[1] eq 'table') { |
4588 |
wakaba |
1.79 |
!!!cp ('t221'); |
4589 |
wakaba |
1.1 |
$i = $_; |
4590 |
|
|
last INSCOPE; |
4591 |
|
|
} elsif ({ |
4592 |
wakaba |
1.83 |
#table => 1, |
4593 |
|
|
html => 1, |
4594 |
wakaba |
1.1 |
}->{$node->[1]}) { |
4595 |
wakaba |
1.79 |
!!!cp ('t222'); |
4596 |
wakaba |
1.1 |
last INSCOPE; |
4597 |
|
|
} |
4598 |
|
|
} # INSCOPE |
4599 |
|
|
unless (defined $i) { |
4600 |
wakaba |
1.79 |
!!!cp ('t223'); |
4601 |
wakaba |
1.83 |
## TODO: The following is wrong, maybe. |
4602 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:table', token => $token); |
4603 |
wakaba |
1.52 |
## Ignore tokens </table><table> |
4604 |
wakaba |
1.1 |
!!!next-token; |
4605 |
|
|
redo B; |
4606 |
|
|
} |
4607 |
|
|
|
4608 |
wakaba |
1.106 |
## TODO: Followings are removed from the latest spec. |
4609 |
wakaba |
1.1 |
## generate implied end tags |
4610 |
wakaba |
1.86 |
while ({ |
4611 |
|
|
dd => 1, dt => 1, li => 1, p => 1, |
4612 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4613 |
wakaba |
1.79 |
!!!cp ('t224'); |
4614 |
wakaba |
1.86 |
pop @{$self->{open_elements}}; |
4615 |
wakaba |
1.1 |
} |
4616 |
|
|
|
4617 |
wakaba |
1.52 |
if ($self->{open_elements}->[-1]->[1] ne 'table') { |
4618 |
wakaba |
1.79 |
!!!cp ('t225'); |
4619 |
wakaba |
1.83 |
## ISSUE: Can this case be reached? |
4620 |
wakaba |
1.113 |
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token); |
4621 |
wakaba |
1.79 |
} else { |
4622 |
|
|
!!!cp ('t226'); |
4623 |
wakaba |
1.1 |
} |
4624 |
|
|
|
4625 |
wakaba |
1.3 |
splice @{$self->{open_elements}}, $i; |
4626 |
wakaba |
1.95 |
pop @{$open_tables}; |
4627 |
wakaba |
1.1 |
|
4628 |
wakaba |
1.52 |
$self->_reset_insertion_mode; |
4629 |
wakaba |
1.1 |
|
4630 |
|
|
## reprocess |
4631 |
|
|
redo B; |
4632 |
wakaba |
1.100 |
} elsif ($token->{tag_name} eq 'style') { |
4633 |
|
|
if (not $open_tables->[-1]->[1]) { # tainted |
4634 |
|
|
!!!cp ('t227.8'); |
4635 |
|
|
## NOTE: This is a "as if in head" code clone. |
4636 |
|
|
$parse_rcdata->(CDATA_CONTENT_MODEL); |
4637 |
|
|
redo B; |
4638 |
|
|
} else { |
4639 |
|
|
!!!cp ('t227.7'); |
4640 |
|
|
# |
4641 |
|
|
} |
4642 |
|
|
} elsif ($token->{tag_name} eq 'script') { |
4643 |
|
|
if (not $open_tables->[-1]->[1]) { # tainted |
4644 |
|
|
!!!cp ('t227.6'); |
4645 |
|
|
## NOTE: This is a "as if in head" code clone. |
4646 |
|
|
$script_start_tag->(); |
4647 |
|
|
redo B; |
4648 |
|
|
} else { |
4649 |
|
|
!!!cp ('t227.5'); |
4650 |
|
|
# |
4651 |
|
|
} |
4652 |
wakaba |
1.98 |
} elsif ($token->{tag_name} eq 'input') { |
4653 |
|
|
if (not $open_tables->[-1]->[1]) { # tainted |
4654 |
|
|
if ($token->{attributes}->{type}) { ## TODO: case |
4655 |
|
|
my $type = lc $token->{attributes}->{type}->{value}; |
4656 |
|
|
if ($type eq 'hidden') { |
4657 |
|
|
!!!cp ('t227.3'); |
4658 |
wakaba |
1.113 |
!!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token); |
4659 |
wakaba |
1.98 |
|
4660 |
|
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
4661 |
|
|
|
4662 |
|
|
## TODO: form element pointer |
4663 |
|
|
|
4664 |
|
|
pop @{$self->{open_elements}}; |
4665 |
|
|
|
4666 |
|
|
!!!next-token; |
4667 |
|
|
redo B; |
4668 |
|
|
} else { |
4669 |
|
|
!!!cp ('t227.2'); |
4670 |
|
|
# |
4671 |
|
|
} |
4672 |
|
|
} else { |
4673 |
|
|
!!!cp ('t227.1'); |
4674 |
|
|
# |
4675 |
|
|
} |
4676 |
|
|
} else { |
4677 |
|
|
!!!cp ('t227.4'); |
4678 |
|
|
# |
4679 |
|
|
} |
4680 |
wakaba |
1.58 |
} else { |
4681 |
wakaba |
1.79 |
!!!cp ('t227'); |
4682 |
wakaba |
1.58 |
# |
4683 |
|
|
} |
4684 |
wakaba |
1.98 |
|
4685 |
wakaba |
1.113 |
!!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token); |
4686 |
wakaba |
1.98 |
|
4687 |
|
|
$insert = $insert_to_foster; |
4688 |
|
|
# |
4689 |
wakaba |
1.58 |
} elsif ($token->{type} == END_TAG_TOKEN) { |
4690 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'tr' and |
4691 |
wakaba |
1.54 |
$self->{insertion_mode} == IN_ROW_IM) { |
4692 |
wakaba |
1.52 |
## have an element in table scope |
4693 |
|
|
my $i; |
4694 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4695 |
|
|
my $node = $self->{open_elements}->[$_]; |
4696 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
4697 |
wakaba |
1.79 |
!!!cp ('t228'); |
4698 |
wakaba |
1.52 |
$i = $_; |
4699 |
|
|
last INSCOPE; |
4700 |
|
|
} elsif ({ |
4701 |
|
|
table => 1, html => 1, |
4702 |
|
|
}->{$node->[1]}) { |
4703 |
wakaba |
1.79 |
!!!cp ('t229'); |
4704 |
wakaba |
1.52 |
last INSCOPE; |
4705 |
|
|
} |
4706 |
|
|
} # INSCOPE |
4707 |
|
|
unless (defined $i) { |
4708 |
wakaba |
1.79 |
!!!cp ('t230'); |
4709 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
4710 |
wakaba |
1.52 |
## Ignore the token |
4711 |
wakaba |
1.42 |
!!!next-token; |
4712 |
|
|
redo B; |
4713 |
wakaba |
1.79 |
} else { |
4714 |
|
|
!!!cp ('t232'); |
4715 |
wakaba |
1.42 |
} |
4716 |
|
|
|
4717 |
wakaba |
1.52 |
## Clear back to table row context |
4718 |
|
|
while (not { |
4719 |
|
|
tr => 1, html => 1, |
4720 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4721 |
wakaba |
1.79 |
!!!cp ('t231'); |
4722 |
wakaba |
1.83 |
## ISSUE: Can this state be reached? |
4723 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; |
4724 |
|
|
} |
4725 |
wakaba |
1.42 |
|
4726 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; # tr |
4727 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_BODY_IM; |
4728 |
wakaba |
1.52 |
!!!next-token; |
4729 |
|
|
redo B; |
4730 |
|
|
} elsif ($token->{tag_name} eq 'table') { |
4731 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_ROW_IM) { |
4732 |
wakaba |
1.52 |
## As if </tr> |
4733 |
|
|
## have an element in table scope |
4734 |
|
|
my $i; |
4735 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4736 |
|
|
my $node = $self->{open_elements}->[$_]; |
4737 |
|
|
if ($node->[1] eq 'tr') { |
4738 |
wakaba |
1.79 |
!!!cp ('t233'); |
4739 |
wakaba |
1.52 |
$i = $_; |
4740 |
|
|
last INSCOPE; |
4741 |
|
|
} elsif ({ |
4742 |
|
|
table => 1, html => 1, |
4743 |
|
|
}->{$node->[1]}) { |
4744 |
wakaba |
1.79 |
!!!cp ('t234'); |
4745 |
wakaba |
1.52 |
last INSCOPE; |
4746 |
wakaba |
1.42 |
} |
4747 |
wakaba |
1.52 |
} # INSCOPE |
4748 |
|
|
unless (defined $i) { |
4749 |
wakaba |
1.79 |
!!!cp ('t235'); |
4750 |
wakaba |
1.83 |
## TODO: The following is wrong. |
4751 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{type}, token => $token); |
4752 |
wakaba |
1.52 |
## Ignore the token |
4753 |
|
|
!!!next-token; |
4754 |
|
|
redo B; |
4755 |
wakaba |
1.42 |
} |
4756 |
wakaba |
1.52 |
|
4757 |
|
|
## Clear back to table row context |
4758 |
|
|
while (not { |
4759 |
|
|
tr => 1, html => 1, |
4760 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4761 |
wakaba |
1.79 |
!!!cp ('t236'); |
4762 |
wakaba |
1.83 |
## ISSUE: Can this state be reached? |
4763 |
wakaba |
1.46 |
pop @{$self->{open_elements}}; |
4764 |
wakaba |
1.1 |
} |
4765 |
wakaba |
1.46 |
|
4766 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; # tr |
4767 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_BODY_IM; |
4768 |
wakaba |
1.46 |
## reprocess in the "in table body" insertion mode... |
4769 |
wakaba |
1.1 |
} |
4770 |
|
|
|
4771 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_TABLE_BODY_IM) { |
4772 |
wakaba |
1.52 |
## have an element in table scope |
4773 |
|
|
my $i; |
4774 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4775 |
|
|
my $node = $self->{open_elements}->[$_]; |
4776 |
|
|
if ({ |
4777 |
|
|
tbody => 1, thead => 1, tfoot => 1, |
4778 |
|
|
}->{$node->[1]}) { |
4779 |
wakaba |
1.79 |
!!!cp ('t237'); |
4780 |
wakaba |
1.52 |
$i = $_; |
4781 |
|
|
last INSCOPE; |
4782 |
|
|
} elsif ({ |
4783 |
|
|
table => 1, html => 1, |
4784 |
|
|
}->{$node->[1]}) { |
4785 |
wakaba |
1.79 |
!!!cp ('t238'); |
4786 |
wakaba |
1.52 |
last INSCOPE; |
4787 |
|
|
} |
4788 |
|
|
} # INSCOPE |
4789 |
|
|
unless (defined $i) { |
4790 |
wakaba |
1.79 |
!!!cp ('t239'); |
4791 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
4792 |
wakaba |
1.52 |
## Ignore the token |
4793 |
|
|
!!!next-token; |
4794 |
|
|
redo B; |
4795 |
wakaba |
1.47 |
} |
4796 |
|
|
|
4797 |
|
|
## Clear back to table body context |
4798 |
|
|
while (not { |
4799 |
|
|
tbody => 1, tfoot => 1, thead => 1, html => 1, |
4800 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4801 |
wakaba |
1.79 |
!!!cp ('t240'); |
4802 |
wakaba |
1.47 |
pop @{$self->{open_elements}}; |
4803 |
|
|
} |
4804 |
|
|
|
4805 |
wakaba |
1.52 |
## As if <{current node}> |
4806 |
|
|
## have an element in table scope |
4807 |
|
|
## true by definition |
4808 |
|
|
|
4809 |
|
|
## Clear back to table body context |
4810 |
|
|
## nop by definition |
4811 |
|
|
|
4812 |
|
|
pop @{$self->{open_elements}}; |
4813 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_IM; |
4814 |
wakaba |
1.52 |
## reprocess in the "in table" insertion mode... |
4815 |
|
|
} |
4816 |
|
|
|
4817 |
wakaba |
1.94 |
## NOTE: </table> in the "in table" insertion mode. |
4818 |
|
|
## When you edit the code fragment below, please ensure that |
4819 |
|
|
## the code for <table> in the "in table" insertion mode |
4820 |
|
|
## is synced with it. |
4821 |
|
|
|
4822 |
wakaba |
1.52 |
## have a table element in table scope |
4823 |
|
|
my $i; |
4824 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4825 |
|
|
my $node = $self->{open_elements}->[$_]; |
4826 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
4827 |
wakaba |
1.79 |
!!!cp ('t241'); |
4828 |
wakaba |
1.52 |
$i = $_; |
4829 |
|
|
last INSCOPE; |
4830 |
|
|
} elsif ({ |
4831 |
|
|
table => 1, html => 1, |
4832 |
|
|
}->{$node->[1]}) { |
4833 |
wakaba |
1.79 |
!!!cp ('t242'); |
4834 |
wakaba |
1.52 |
last INSCOPE; |
4835 |
wakaba |
1.47 |
} |
4836 |
wakaba |
1.52 |
} # INSCOPE |
4837 |
|
|
unless (defined $i) { |
4838 |
wakaba |
1.79 |
!!!cp ('t243'); |
4839 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
4840 |
wakaba |
1.52 |
## Ignore the token |
4841 |
|
|
!!!next-token; |
4842 |
|
|
redo B; |
4843 |
wakaba |
1.3 |
} |
4844 |
wakaba |
1.52 |
|
4845 |
|
|
splice @{$self->{open_elements}}, $i; |
4846 |
wakaba |
1.95 |
pop @{$open_tables}; |
4847 |
wakaba |
1.1 |
|
4848 |
wakaba |
1.52 |
$self->_reset_insertion_mode; |
4849 |
wakaba |
1.47 |
|
4850 |
|
|
!!!next-token; |
4851 |
|
|
redo B; |
4852 |
|
|
} elsif ({ |
4853 |
wakaba |
1.48 |
tbody => 1, tfoot => 1, thead => 1, |
4854 |
wakaba |
1.52 |
}->{$token->{tag_name}} and |
4855 |
wakaba |
1.56 |
$self->{insertion_mode} & ROW_IMS) { |
4856 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_ROW_IM) { |
4857 |
wakaba |
1.52 |
## have an element in table scope |
4858 |
|
|
my $i; |
4859 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4860 |
|
|
my $node = $self->{open_elements}->[$_]; |
4861 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
4862 |
wakaba |
1.79 |
!!!cp ('t247'); |
4863 |
wakaba |
1.52 |
$i = $_; |
4864 |
|
|
last INSCOPE; |
4865 |
|
|
} elsif ({ |
4866 |
|
|
table => 1, html => 1, |
4867 |
|
|
}->{$node->[1]}) { |
4868 |
wakaba |
1.79 |
!!!cp ('t248'); |
4869 |
wakaba |
1.52 |
last INSCOPE; |
4870 |
|
|
} |
4871 |
|
|
} # INSCOPE |
4872 |
|
|
unless (defined $i) { |
4873 |
wakaba |
1.79 |
!!!cp ('t249'); |
4874 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
4875 |
wakaba |
1.52 |
## Ignore the token |
4876 |
|
|
!!!next-token; |
4877 |
|
|
redo B; |
4878 |
|
|
} |
4879 |
|
|
|
4880 |
wakaba |
1.48 |
## As if </tr> |
4881 |
|
|
## have an element in table scope |
4882 |
|
|
my $i; |
4883 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4884 |
|
|
my $node = $self->{open_elements}->[$_]; |
4885 |
|
|
if ($node->[1] eq 'tr') { |
4886 |
wakaba |
1.79 |
!!!cp ('t250'); |
4887 |
wakaba |
1.48 |
$i = $_; |
4888 |
|
|
last INSCOPE; |
4889 |
|
|
} elsif ({ |
4890 |
|
|
table => 1, html => 1, |
4891 |
|
|
}->{$node->[1]}) { |
4892 |
wakaba |
1.79 |
!!!cp ('t251'); |
4893 |
wakaba |
1.48 |
last INSCOPE; |
4894 |
|
|
} |
4895 |
|
|
} # INSCOPE |
4896 |
wakaba |
1.52 |
unless (defined $i) { |
4897 |
wakaba |
1.79 |
!!!cp ('t252'); |
4898 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:tr', token => $token); |
4899 |
wakaba |
1.52 |
## Ignore the token |
4900 |
|
|
!!!next-token; |
4901 |
|
|
redo B; |
4902 |
|
|
} |
4903 |
wakaba |
1.48 |
|
4904 |
|
|
## Clear back to table row context |
4905 |
|
|
while (not { |
4906 |
|
|
tr => 1, html => 1, |
4907 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4908 |
wakaba |
1.79 |
!!!cp ('t253'); |
4909 |
wakaba |
1.83 |
## ISSUE: Can this case be reached? |
4910 |
wakaba |
1.48 |
pop @{$self->{open_elements}}; |
4911 |
|
|
} |
4912 |
|
|
|
4913 |
|
|
pop @{$self->{open_elements}}; # tr |
4914 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_BODY_IM; |
4915 |
wakaba |
1.52 |
## reprocess in the "in table body" insertion mode... |
4916 |
|
|
} |
4917 |
|
|
|
4918 |
|
|
## have an element in table scope |
4919 |
|
|
my $i; |
4920 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4921 |
|
|
my $node = $self->{open_elements}->[$_]; |
4922 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
4923 |
wakaba |
1.79 |
!!!cp ('t254'); |
4924 |
wakaba |
1.52 |
$i = $_; |
4925 |
|
|
last INSCOPE; |
4926 |
|
|
} elsif ({ |
4927 |
|
|
table => 1, html => 1, |
4928 |
|
|
}->{$node->[1]}) { |
4929 |
wakaba |
1.79 |
!!!cp ('t255'); |
4930 |
wakaba |
1.52 |
last INSCOPE; |
4931 |
|
|
} |
4932 |
|
|
} # INSCOPE |
4933 |
|
|
unless (defined $i) { |
4934 |
wakaba |
1.79 |
!!!cp ('t256'); |
4935 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
4936 |
wakaba |
1.52 |
## Ignore the token |
4937 |
|
|
!!!next-token; |
4938 |
|
|
redo B; |
4939 |
|
|
} |
4940 |
|
|
|
4941 |
|
|
## Clear back to table body context |
4942 |
|
|
while (not { |
4943 |
|
|
tbody => 1, tfoot => 1, thead => 1, html => 1, |
4944 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4945 |
wakaba |
1.79 |
!!!cp ('t257'); |
4946 |
wakaba |
1.83 |
## ISSUE: Can this case be reached? |
4947 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; |
4948 |
|
|
} |
4949 |
|
|
|
4950 |
|
|
pop @{$self->{open_elements}}; |
4951 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_IM; |
4952 |
wakaba |
1.52 |
!!!next-token; |
4953 |
|
|
redo B; |
4954 |
|
|
} elsif ({ |
4955 |
|
|
body => 1, caption => 1, col => 1, colgroup => 1, |
4956 |
|
|
html => 1, td => 1, th => 1, |
4957 |
wakaba |
1.54 |
tr => 1, # $self->{insertion_mode} == IN_ROW_IM |
4958 |
|
|
tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM |
4959 |
wakaba |
1.52 |
}->{$token->{tag_name}}) { |
4960 |
wakaba |
1.79 |
!!!cp ('t258'); |
4961 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
4962 |
wakaba |
1.52 |
## Ignore the token |
4963 |
|
|
!!!next-token; |
4964 |
|
|
redo B; |
4965 |
wakaba |
1.58 |
} else { |
4966 |
wakaba |
1.79 |
!!!cp ('t259'); |
4967 |
wakaba |
1.113 |
!!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token); |
4968 |
wakaba |
1.52 |
|
4969 |
wakaba |
1.58 |
$insert = $insert_to_foster; |
4970 |
|
|
# |
4971 |
|
|
} |
4972 |
wakaba |
1.104 |
} elsif ($token->{type} == END_OF_FILE_TOKEN) { |
4973 |
|
|
unless ($self->{open_elements}->[-1]->[1] eq 'html' and |
4974 |
|
|
@{$self->{open_elements}} == 1) { # redundant, maybe |
4975 |
wakaba |
1.113 |
!!!parse-error (type => 'in body:#eof', token => $token); |
4976 |
wakaba |
1.104 |
!!!cp ('t259.1'); |
4977 |
wakaba |
1.105 |
# |
4978 |
wakaba |
1.104 |
} else { |
4979 |
|
|
!!!cp ('t259.2'); |
4980 |
wakaba |
1.105 |
# |
4981 |
wakaba |
1.104 |
} |
4982 |
|
|
|
4983 |
|
|
## Stop parsing |
4984 |
|
|
last B; |
4985 |
wakaba |
1.58 |
} else { |
4986 |
|
|
die "$0: $token->{type}: Unknown token type"; |
4987 |
|
|
} |
4988 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_COLUMN_GROUP_IM) { |
4989 |
wakaba |
1.55 |
if ($token->{type} == CHARACTER_TOKEN) { |
4990 |
wakaba |
1.52 |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { |
4991 |
|
|
$self->{open_elements}->[-1]->[0]->manakai_append_text ($1); |
4992 |
|
|
unless (length $token->{data}) { |
4993 |
wakaba |
1.79 |
!!!cp ('t260'); |
4994 |
wakaba |
1.52 |
!!!next-token; |
4995 |
|
|
redo B; |
4996 |
|
|
} |
4997 |
|
|
} |
4998 |
|
|
|
4999 |
wakaba |
1.79 |
!!!cp ('t261'); |
5000 |
wakaba |
1.52 |
# |
5001 |
wakaba |
1.55 |
} elsif ($token->{type} == START_TAG_TOKEN) { |
5002 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'col') { |
5003 |
wakaba |
1.79 |
!!!cp ('t262'); |
5004 |
wakaba |
1.52 |
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
5005 |
|
|
pop @{$self->{open_elements}}; |
5006 |
|
|
!!!next-token; |
5007 |
|
|
redo B; |
5008 |
|
|
} else { |
5009 |
wakaba |
1.79 |
!!!cp ('t263'); |
5010 |
wakaba |
1.52 |
# |
5011 |
|
|
} |
5012 |
wakaba |
1.55 |
} elsif ($token->{type} == END_TAG_TOKEN) { |
5013 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'colgroup') { |
5014 |
|
|
if ($self->{open_elements}->[-1]->[1] eq 'html') { |
5015 |
wakaba |
1.79 |
!!!cp ('t264'); |
5016 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:colgroup', token => $token); |
5017 |
wakaba |
1.52 |
## Ignore the token |
5018 |
|
|
!!!next-token; |
5019 |
|
|
redo B; |
5020 |
|
|
} else { |
5021 |
wakaba |
1.79 |
!!!cp ('t265'); |
5022 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; # colgroup |
5023 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_IM; |
5024 |
wakaba |
1.52 |
!!!next-token; |
5025 |
|
|
redo B; |
5026 |
|
|
} |
5027 |
|
|
} elsif ($token->{tag_name} eq 'col') { |
5028 |
wakaba |
1.79 |
!!!cp ('t266'); |
5029 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:col', token => $token); |
5030 |
wakaba |
1.52 |
## Ignore the token |
5031 |
|
|
!!!next-token; |
5032 |
|
|
redo B; |
5033 |
|
|
} else { |
5034 |
wakaba |
1.79 |
!!!cp ('t267'); |
5035 |
wakaba |
1.52 |
# |
5036 |
|
|
} |
5037 |
wakaba |
1.104 |
} elsif ($token->{type} == END_OF_FILE_TOKEN) { |
5038 |
|
|
if ($self->{open_elements}->[-1]->[1] eq 'html' or |
5039 |
|
|
@{$self->{open_elements}} == 1) { # redundant, maybe |
5040 |
|
|
!!!cp ('t270.2'); |
5041 |
|
|
## Stop parsing. |
5042 |
|
|
last B; |
5043 |
|
|
} else { |
5044 |
|
|
## NOTE: As if </colgroup>. |
5045 |
|
|
!!!cp ('t270.1'); |
5046 |
|
|
pop @{$self->{open_elements}}; # colgroup |
5047 |
|
|
$self->{insertion_mode} = IN_TABLE_IM; |
5048 |
|
|
## Reprocess. |
5049 |
|
|
redo B; |
5050 |
|
|
} |
5051 |
|
|
} else { |
5052 |
|
|
die "$0: $token->{type}: Unknown token type"; |
5053 |
|
|
} |
5054 |
wakaba |
1.52 |
|
5055 |
|
|
## As if </colgroup> |
5056 |
|
|
if ($self->{open_elements}->[-1]->[1] eq 'html') { |
5057 |
wakaba |
1.79 |
!!!cp ('t269'); |
5058 |
wakaba |
1.104 |
## TODO: Wrong error type? |
5059 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:colgroup', token => $token); |
5060 |
wakaba |
1.52 |
## Ignore the token |
5061 |
|
|
!!!next-token; |
5062 |
|
|
redo B; |
5063 |
|
|
} else { |
5064 |
wakaba |
1.79 |
!!!cp ('t270'); |
5065 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; # colgroup |
5066 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_IM; |
5067 |
wakaba |
1.52 |
## reprocess |
5068 |
|
|
redo B; |
5069 |
|
|
} |
5070 |
wakaba |
1.101 |
} elsif ($self->{insertion_mode} & SELECT_IMS) { |
5071 |
wakaba |
1.58 |
if ($token->{type} == CHARACTER_TOKEN) { |
5072 |
wakaba |
1.79 |
!!!cp ('t271'); |
5073 |
wakaba |
1.58 |
$self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data}); |
5074 |
|
|
!!!next-token; |
5075 |
|
|
redo B; |
5076 |
|
|
} elsif ($token->{type} == START_TAG_TOKEN) { |
5077 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'option') { |
5078 |
|
|
if ($self->{open_elements}->[-1]->[1] eq 'option') { |
5079 |
wakaba |
1.79 |
!!!cp ('t272'); |
5080 |
wakaba |
1.52 |
## As if </option> |
5081 |
|
|
pop @{$self->{open_elements}}; |
5082 |
wakaba |
1.79 |
} else { |
5083 |
|
|
!!!cp ('t273'); |
5084 |
wakaba |
1.52 |
} |
5085 |
|
|
|
5086 |
|
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
5087 |
|
|
!!!next-token; |
5088 |
|
|
redo B; |
5089 |
|
|
} elsif ($token->{tag_name} eq 'optgroup') { |
5090 |
|
|
if ($self->{open_elements}->[-1]->[1] eq 'option') { |
5091 |
wakaba |
1.79 |
!!!cp ('t274'); |
5092 |
wakaba |
1.52 |
## As if </option> |
5093 |
|
|
pop @{$self->{open_elements}}; |
5094 |
wakaba |
1.79 |
} else { |
5095 |
|
|
!!!cp ('t275'); |
5096 |
wakaba |
1.52 |
} |
5097 |
|
|
|
5098 |
|
|
if ($self->{open_elements}->[-1]->[1] eq 'optgroup') { |
5099 |
wakaba |
1.79 |
!!!cp ('t276'); |
5100 |
wakaba |
1.52 |
## As if </optgroup> |
5101 |
|
|
pop @{$self->{open_elements}}; |
5102 |
wakaba |
1.79 |
} else { |
5103 |
|
|
!!!cp ('t277'); |
5104 |
wakaba |
1.52 |
} |
5105 |
|
|
|
5106 |
|
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
5107 |
|
|
!!!next-token; |
5108 |
|
|
redo B; |
5109 |
wakaba |
1.101 |
} elsif ($token->{tag_name} eq 'select' or |
5110 |
|
|
$token->{tag_name} eq 'input' or |
5111 |
|
|
($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and |
5112 |
|
|
{ |
5113 |
|
|
caption => 1, table => 1, |
5114 |
|
|
tbody => 1, tfoot => 1, thead => 1, |
5115 |
|
|
tr => 1, td => 1, th => 1, |
5116 |
|
|
}->{$token->{tag_name}})) { |
5117 |
|
|
## TODO: The type below is not good - <select> is replaced by </select> |
5118 |
wakaba |
1.113 |
!!!parse-error (type => 'not closed:select', token => $token); |
5119 |
wakaba |
1.101 |
## NOTE: As if the token were </select> (<select> case) or |
5120 |
|
|
## as if there were </select> (otherwise). |
5121 |
wakaba |
1.52 |
## have an element in table scope |
5122 |
|
|
my $i; |
5123 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
5124 |
|
|
my $node = $self->{open_elements}->[$_]; |
5125 |
wakaba |
1.101 |
if ($node->[1] eq 'select') { |
5126 |
wakaba |
1.79 |
!!!cp ('t278'); |
5127 |
wakaba |
1.52 |
$i = $_; |
5128 |
|
|
last INSCOPE; |
5129 |
|
|
} elsif ({ |
5130 |
|
|
table => 1, html => 1, |
5131 |
|
|
}->{$node->[1]}) { |
5132 |
wakaba |
1.79 |
!!!cp ('t279'); |
5133 |
wakaba |
1.52 |
last INSCOPE; |
5134 |
wakaba |
1.47 |
} |
5135 |
wakaba |
1.52 |
} # INSCOPE |
5136 |
|
|
unless (defined $i) { |
5137 |
wakaba |
1.79 |
!!!cp ('t280'); |
5138 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:select', token => $token); |
5139 |
wakaba |
1.52 |
## Ignore the token |
5140 |
|
|
!!!next-token; |
5141 |
|
|
redo B; |
5142 |
wakaba |
1.47 |
} |
5143 |
wakaba |
1.52 |
|
5144 |
wakaba |
1.79 |
!!!cp ('t281'); |
5145 |
wakaba |
1.52 |
splice @{$self->{open_elements}}, $i; |
5146 |
|
|
|
5147 |
|
|
$self->_reset_insertion_mode; |
5148 |
wakaba |
1.47 |
|
5149 |
wakaba |
1.101 |
if ($token->{tag_name} eq 'select') { |
5150 |
|
|
!!!cp ('t281.2'); |
5151 |
|
|
!!!next-token; |
5152 |
|
|
redo B; |
5153 |
|
|
} else { |
5154 |
|
|
!!!cp ('t281.1'); |
5155 |
|
|
## Reprocess the token. |
5156 |
|
|
redo B; |
5157 |
|
|
} |
5158 |
wakaba |
1.58 |
} else { |
5159 |
wakaba |
1.79 |
!!!cp ('t282'); |
5160 |
wakaba |
1.113 |
!!!parse-error (type => 'in select:'.$token->{tag_name}, token => $token); |
5161 |
wakaba |
1.58 |
## Ignore the token |
5162 |
|
|
!!!next-token; |
5163 |
|
|
redo B; |
5164 |
|
|
} |
5165 |
|
|
} elsif ($token->{type} == END_TAG_TOKEN) { |
5166 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'optgroup') { |
5167 |
|
|
if ($self->{open_elements}->[-1]->[1] eq 'option' and |
5168 |
|
|
$self->{open_elements}->[-2]->[1] eq 'optgroup') { |
5169 |
wakaba |
1.79 |
!!!cp ('t283'); |
5170 |
wakaba |
1.52 |
## As if </option> |
5171 |
|
|
splice @{$self->{open_elements}}, -2; |
5172 |
|
|
} elsif ($self->{open_elements}->[-1]->[1] eq 'optgroup') { |
5173 |
wakaba |
1.79 |
!!!cp ('t284'); |
5174 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; |
5175 |
|
|
} else { |
5176 |
wakaba |
1.79 |
!!!cp ('t285'); |
5177 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
5178 |
wakaba |
1.52 |
## Ignore the token |
5179 |
|
|
} |
5180 |
|
|
!!!next-token; |
5181 |
|
|
redo B; |
5182 |
|
|
} elsif ($token->{tag_name} eq 'option') { |
5183 |
|
|
if ($self->{open_elements}->[-1]->[1] eq 'option') { |
5184 |
wakaba |
1.79 |
!!!cp ('t286'); |
5185 |
wakaba |
1.47 |
pop @{$self->{open_elements}}; |
5186 |
wakaba |
1.52 |
} else { |
5187 |
wakaba |
1.79 |
!!!cp ('t287'); |
5188 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
5189 |
wakaba |
1.52 |
## Ignore the token |
5190 |
wakaba |
1.1 |
} |
5191 |
wakaba |
1.52 |
!!!next-token; |
5192 |
|
|
redo B; |
5193 |
|
|
} elsif ($token->{tag_name} eq 'select') { |
5194 |
|
|
## have an element in table scope |
5195 |
|
|
my $i; |
5196 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
5197 |
|
|
my $node = $self->{open_elements}->[$_]; |
5198 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
5199 |
wakaba |
1.79 |
!!!cp ('t288'); |
5200 |
wakaba |
1.52 |
$i = $_; |
5201 |
|
|
last INSCOPE; |
5202 |
|
|
} elsif ({ |
5203 |
|
|
table => 1, html => 1, |
5204 |
|
|
}->{$node->[1]}) { |
5205 |
wakaba |
1.79 |
!!!cp ('t289'); |
5206 |
wakaba |
1.52 |
last INSCOPE; |
5207 |
wakaba |
1.48 |
} |
5208 |
wakaba |
1.52 |
} # INSCOPE |
5209 |
|
|
unless (defined $i) { |
5210 |
wakaba |
1.79 |
!!!cp ('t290'); |
5211 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
5212 |
wakaba |
1.52 |
## Ignore the token |
5213 |
|
|
!!!next-token; |
5214 |
wakaba |
1.48 |
redo B; |
5215 |
wakaba |
1.52 |
} |
5216 |
|
|
|
5217 |
wakaba |
1.79 |
!!!cp ('t291'); |
5218 |
wakaba |
1.52 |
splice @{$self->{open_elements}}, $i; |
5219 |
|
|
|
5220 |
|
|
$self->_reset_insertion_mode; |
5221 |
|
|
|
5222 |
|
|
!!!next-token; |
5223 |
|
|
redo B; |
5224 |
wakaba |
1.101 |
} elsif ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and |
5225 |
|
|
{ |
5226 |
|
|
caption => 1, table => 1, tbody => 1, |
5227 |
|
|
tfoot => 1, thead => 1, tr => 1, td => 1, th => 1, |
5228 |
|
|
}->{$token->{tag_name}}) { |
5229 |
wakaba |
1.83 |
## TODO: The following is wrong? |
5230 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
5231 |
wakaba |
1.52 |
|
5232 |
|
|
## have an element in table scope |
5233 |
|
|
my $i; |
5234 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
5235 |
|
|
my $node = $self->{open_elements}->[$_]; |
5236 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
5237 |
wakaba |
1.79 |
!!!cp ('t292'); |
5238 |
wakaba |
1.52 |
$i = $_; |
5239 |
|
|
last INSCOPE; |
5240 |
|
|
} elsif ({ |
5241 |
|
|
table => 1, html => 1, |
5242 |
|
|
}->{$node->[1]}) { |
5243 |
wakaba |
1.79 |
!!!cp ('t293'); |
5244 |
wakaba |
1.52 |
last INSCOPE; |
5245 |
wakaba |
1.1 |
} |
5246 |
wakaba |
1.52 |
} # INSCOPE |
5247 |
|
|
unless (defined $i) { |
5248 |
wakaba |
1.79 |
!!!cp ('t294'); |
5249 |
wakaba |
1.52 |
## Ignore the token |
5250 |
wakaba |
1.1 |
!!!next-token; |
5251 |
|
|
redo B; |
5252 |
|
|
} |
5253 |
wakaba |
1.52 |
|
5254 |
|
|
## As if </select> |
5255 |
|
|
## have an element in table scope |
5256 |
|
|
undef $i; |
5257 |
wakaba |
1.3 |
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
5258 |
|
|
my $node = $self->{open_elements}->[$_]; |
5259 |
wakaba |
1.52 |
if ($node->[1] eq 'select') { |
5260 |
wakaba |
1.79 |
!!!cp ('t295'); |
5261 |
wakaba |
1.1 |
$i = $_; |
5262 |
|
|
last INSCOPE; |
5263 |
|
|
} elsif ({ |
5264 |
|
|
table => 1, html => 1, |
5265 |
wakaba |
1.52 |
}->{$node->[1]}) { |
5266 |
wakaba |
1.83 |
## ISSUE: Can this state be reached? |
5267 |
wakaba |
1.79 |
!!!cp ('t296'); |
5268 |
wakaba |
1.52 |
last INSCOPE; |
5269 |
|
|
} |
5270 |
|
|
} # INSCOPE |
5271 |
|
|
unless (defined $i) { |
5272 |
wakaba |
1.79 |
!!!cp ('t297'); |
5273 |
wakaba |
1.83 |
## TODO: The following error type is correct? |
5274 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:select', token => $token); |
5275 |
wakaba |
1.52 |
## Ignore the </select> token |
5276 |
|
|
!!!next-token; ## TODO: ok? |
5277 |
|
|
redo B; |
5278 |
|
|
} |
5279 |
|
|
|
5280 |
wakaba |
1.79 |
!!!cp ('t298'); |
5281 |
wakaba |
1.52 |
splice @{$self->{open_elements}}, $i; |
5282 |
|
|
|
5283 |
|
|
$self->_reset_insertion_mode; |
5284 |
|
|
|
5285 |
|
|
## reprocess |
5286 |
|
|
redo B; |
5287 |
wakaba |
1.58 |
} else { |
5288 |
wakaba |
1.79 |
!!!cp ('t299'); |
5289 |
wakaba |
1.113 |
!!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token); |
5290 |
wakaba |
1.52 |
## Ignore the token |
5291 |
|
|
!!!next-token; |
5292 |
|
|
redo B; |
5293 |
wakaba |
1.58 |
} |
5294 |
wakaba |
1.104 |
} elsif ($token->{type} == END_OF_FILE_TOKEN) { |
5295 |
|
|
unless ($self->{open_elements}->[-1]->[1] eq 'html' and |
5296 |
|
|
@{$self->{open_elements}} == 1) { # redundant, maybe |
5297 |
|
|
!!!cp ('t299.1'); |
5298 |
wakaba |
1.113 |
!!!parse-error (type => 'in body:#eof', token => $token); |
5299 |
wakaba |
1.104 |
} else { |
5300 |
|
|
!!!cp ('t299.2'); |
5301 |
|
|
} |
5302 |
|
|
|
5303 |
|
|
## Stop parsing. |
5304 |
|
|
last B; |
5305 |
wakaba |
1.58 |
} else { |
5306 |
|
|
die "$0: $token->{type}: Unknown token type"; |
5307 |
|
|
} |
5308 |
wakaba |
1.56 |
} elsif ($self->{insertion_mode} & BODY_AFTER_IMS) { |
5309 |
wakaba |
1.55 |
if ($token->{type} == CHARACTER_TOKEN) { |
5310 |
wakaba |
1.52 |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { |
5311 |
|
|
my $data = $1; |
5312 |
|
|
## As if in body |
5313 |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
5314 |
|
|
|
5315 |
|
|
$self->{open_elements}->[-1]->[0]->manakai_append_text ($1); |
5316 |
|
|
|
5317 |
|
|
unless (length $token->{data}) { |
5318 |
wakaba |
1.79 |
!!!cp ('t300'); |
5319 |
wakaba |
1.52 |
!!!next-token; |
5320 |
|
|
redo B; |
5321 |
|
|
} |
5322 |
|
|
} |
5323 |
|
|
|
5324 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) { |
5325 |
wakaba |
1.79 |
!!!cp ('t301'); |
5326 |
wakaba |
1.113 |
!!!parse-error (type => 'after html:#character', token => $token); |
5327 |
wakaba |
1.52 |
|
5328 |
wakaba |
1.84 |
## Reprocess in the "after body" insertion mode. |
5329 |
wakaba |
1.79 |
} else { |
5330 |
|
|
!!!cp ('t302'); |
5331 |
wakaba |
1.52 |
} |
5332 |
|
|
|
5333 |
|
|
## "after body" insertion mode |
5334 |
wakaba |
1.113 |
!!!parse-error (type => 'after body:#character', token => $token); |
5335 |
wakaba |
1.52 |
|
5336 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_BODY_IM; |
5337 |
wakaba |
1.52 |
## reprocess |
5338 |
|
|
redo B; |
5339 |
wakaba |
1.55 |
} elsif ($token->{type} == START_TAG_TOKEN) { |
5340 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) { |
5341 |
wakaba |
1.79 |
!!!cp ('t303'); |
5342 |
wakaba |
1.113 |
!!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token); |
5343 |
wakaba |
1.52 |
|
5344 |
wakaba |
1.84 |
## Reprocess in the "after body" insertion mode. |
5345 |
wakaba |
1.79 |
} else { |
5346 |
|
|
!!!cp ('t304'); |
5347 |
wakaba |
1.52 |
} |
5348 |
|
|
|
5349 |
|
|
## "after body" insertion mode |
5350 |
wakaba |
1.113 |
!!!parse-error (type => 'after body:'.$token->{tag_name}, token => $token); |
5351 |
wakaba |
1.52 |
|
5352 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_BODY_IM; |
5353 |
wakaba |
1.52 |
## reprocess |
5354 |
|
|
redo B; |
5355 |
wakaba |
1.55 |
} elsif ($token->{type} == END_TAG_TOKEN) { |
5356 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) { |
5357 |
wakaba |
1.79 |
!!!cp ('t305'); |
5358 |
wakaba |
1.113 |
!!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token); |
5359 |
wakaba |
1.52 |
|
5360 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_BODY_IM; |
5361 |
wakaba |
1.84 |
## Reprocess in the "after body" insertion mode. |
5362 |
wakaba |
1.79 |
} else { |
5363 |
|
|
!!!cp ('t306'); |
5364 |
wakaba |
1.52 |
} |
5365 |
|
|
|
5366 |
|
|
## "after body" insertion mode |
5367 |
|
|
if ($token->{tag_name} eq 'html') { |
5368 |
|
|
if (defined $self->{inner_html_node}) { |
5369 |
wakaba |
1.79 |
!!!cp ('t307'); |
5370 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:html', token => $token); |
5371 |
wakaba |
1.52 |
## Ignore the token |
5372 |
|
|
!!!next-token; |
5373 |
|
|
redo B; |
5374 |
|
|
} else { |
5375 |
wakaba |
1.79 |
!!!cp ('t308'); |
5376 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_HTML_BODY_IM; |
5377 |
wakaba |
1.52 |
!!!next-token; |
5378 |
|
|
redo B; |
5379 |
|
|
} |
5380 |
|
|
} else { |
5381 |
wakaba |
1.79 |
!!!cp ('t309'); |
5382 |
wakaba |
1.113 |
!!!parse-error (type => 'after body:/'.$token->{tag_name}, token => $token); |
5383 |
wakaba |
1.52 |
|
5384 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_BODY_IM; |
5385 |
wakaba |
1.52 |
## reprocess |
5386 |
|
|
redo B; |
5387 |
|
|
} |
5388 |
wakaba |
1.104 |
} elsif ($token->{type} == END_OF_FILE_TOKEN) { |
5389 |
|
|
!!!cp ('t309.2'); |
5390 |
|
|
## Stop parsing |
5391 |
|
|
last B; |
5392 |
wakaba |
1.52 |
} else { |
5393 |
|
|
die "$0: $token->{type}: Unknown token type"; |
5394 |
|
|
} |
5395 |
wakaba |
1.56 |
} elsif ($self->{insertion_mode} & FRAME_IMS) { |
5396 |
wakaba |
1.55 |
if ($token->{type} == CHARACTER_TOKEN) { |
5397 |
wakaba |
1.52 |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { |
5398 |
|
|
$self->{open_elements}->[-1]->[0]->manakai_append_text ($1); |
5399 |
|
|
|
5400 |
|
|
unless (length $token->{data}) { |
5401 |
wakaba |
1.79 |
!!!cp ('t310'); |
5402 |
wakaba |
1.52 |
!!!next-token; |
5403 |
|
|
redo B; |
5404 |
|
|
} |
5405 |
|
|
} |
5406 |
|
|
|
5407 |
|
|
if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) { |
5408 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_FRAMESET_IM) { |
5409 |
wakaba |
1.79 |
!!!cp ('t311'); |
5410 |
wakaba |
1.113 |
!!!parse-error (type => 'in frameset:#character', token => $token); |
5411 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) { |
5412 |
wakaba |
1.79 |
!!!cp ('t312'); |
5413 |
wakaba |
1.113 |
!!!parse-error (type => 'after frameset:#character', token => $token); |
5414 |
wakaba |
1.52 |
} else { # "after html frameset" |
5415 |
wakaba |
1.79 |
!!!cp ('t313'); |
5416 |
wakaba |
1.113 |
!!!parse-error (type => 'after html:#character', token => $token); |
5417 |
wakaba |
1.52 |
|
5418 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_FRAMESET_IM; |
5419 |
wakaba |
1.84 |
## Reprocess in the "after frameset" insertion mode. |
5420 |
wakaba |
1.113 |
!!!parse-error (type => 'after frameset:#character', token => $token); |
5421 |
wakaba |
1.52 |
} |
5422 |
|
|
|
5423 |
|
|
## Ignore the token. |
5424 |
|
|
if (length $token->{data}) { |
5425 |
wakaba |
1.79 |
!!!cp ('t314'); |
5426 |
wakaba |
1.52 |
## reprocess the rest of characters |
5427 |
|
|
} else { |
5428 |
wakaba |
1.79 |
!!!cp ('t315'); |
5429 |
wakaba |
1.52 |
!!!next-token; |
5430 |
|
|
} |
5431 |
|
|
redo B; |
5432 |
|
|
} |
5433 |
|
|
|
5434 |
|
|
die qq[$0: Character "$token->{data}"]; |
5435 |
wakaba |
1.55 |
} elsif ($token->{type} == START_TAG_TOKEN) { |
5436 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) { |
5437 |
wakaba |
1.79 |
!!!cp ('t316'); |
5438 |
wakaba |
1.113 |
!!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token); |
5439 |
wakaba |
1.1 |
|
5440 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_FRAMESET_IM; |
5441 |
wakaba |
1.84 |
## Process in the "after frameset" insertion mode. |
5442 |
wakaba |
1.79 |
} else { |
5443 |
|
|
!!!cp ('t317'); |
5444 |
|
|
} |
5445 |
wakaba |
1.1 |
|
5446 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'frameset' and |
5447 |
wakaba |
1.54 |
$self->{insertion_mode} == IN_FRAMESET_IM) { |
5448 |
wakaba |
1.79 |
!!!cp ('t318'); |
5449 |
wakaba |
1.52 |
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
5450 |
|
|
!!!next-token; |
5451 |
|
|
redo B; |
5452 |
|
|
} elsif ($token->{tag_name} eq 'frame' and |
5453 |
wakaba |
1.54 |
$self->{insertion_mode} == IN_FRAMESET_IM) { |
5454 |
wakaba |
1.79 |
!!!cp ('t319'); |
5455 |
wakaba |
1.52 |
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
5456 |
|
|
pop @{$self->{open_elements}}; |
5457 |
|
|
!!!next-token; |
5458 |
|
|
redo B; |
5459 |
|
|
} elsif ($token->{tag_name} eq 'noframes') { |
5460 |
wakaba |
1.79 |
!!!cp ('t320'); |
5461 |
wakaba |
1.52 |
## NOTE: As if in body. |
5462 |
wakaba |
1.96 |
$parse_rcdata->(CDATA_CONTENT_MODEL); |
5463 |
wakaba |
1.52 |
redo B; |
5464 |
|
|
} else { |
5465 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_FRAMESET_IM) { |
5466 |
wakaba |
1.79 |
!!!cp ('t321'); |
5467 |
wakaba |
1.113 |
!!!parse-error (type => 'in frameset:'.$token->{tag_name}, token => $token); |
5468 |
wakaba |
1.52 |
} else { |
5469 |
wakaba |
1.79 |
!!!cp ('t322'); |
5470 |
wakaba |
1.113 |
!!!parse-error (type => 'after frameset:'.$token->{tag_name}, token => $token); |
5471 |
wakaba |
1.52 |
} |
5472 |
|
|
## Ignore the token |
5473 |
|
|
!!!next-token; |
5474 |
|
|
redo B; |
5475 |
|
|
} |
5476 |
wakaba |
1.55 |
} elsif ($token->{type} == END_TAG_TOKEN) { |
5477 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) { |
5478 |
wakaba |
1.79 |
!!!cp ('t323'); |
5479 |
wakaba |
1.113 |
!!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token); |
5480 |
wakaba |
1.1 |
|
5481 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_FRAMESET_IM; |
5482 |
wakaba |
1.84 |
## Process in the "after frameset" insertion mode. |
5483 |
wakaba |
1.79 |
} else { |
5484 |
|
|
!!!cp ('t324'); |
5485 |
wakaba |
1.52 |
} |
5486 |
wakaba |
1.1 |
|
5487 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'frameset' and |
5488 |
wakaba |
1.54 |
$self->{insertion_mode} == IN_FRAMESET_IM) { |
5489 |
wakaba |
1.52 |
if ($self->{open_elements}->[-1]->[1] eq 'html' and |
5490 |
|
|
@{$self->{open_elements}} == 1) { |
5491 |
wakaba |
1.79 |
!!!cp ('t325'); |
5492 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
5493 |
wakaba |
1.52 |
## Ignore the token |
5494 |
|
|
!!!next-token; |
5495 |
|
|
} else { |
5496 |
wakaba |
1.79 |
!!!cp ('t326'); |
5497 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; |
5498 |
|
|
!!!next-token; |
5499 |
|
|
} |
5500 |
wakaba |
1.47 |
|
5501 |
wakaba |
1.52 |
if (not defined $self->{inner_html_node} and |
5502 |
|
|
$self->{open_elements}->[-1]->[1] ne 'frameset') { |
5503 |
wakaba |
1.79 |
!!!cp ('t327'); |
5504 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_FRAMESET_IM; |
5505 |
wakaba |
1.79 |
} else { |
5506 |
|
|
!!!cp ('t328'); |
5507 |
wakaba |
1.52 |
} |
5508 |
|
|
redo B; |
5509 |
|
|
} elsif ($token->{tag_name} eq 'html' and |
5510 |
wakaba |
1.54 |
$self->{insertion_mode} == AFTER_FRAMESET_IM) { |
5511 |
wakaba |
1.79 |
!!!cp ('t329'); |
5512 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_HTML_FRAMESET_IM; |
5513 |
wakaba |
1.52 |
!!!next-token; |
5514 |
|
|
redo B; |
5515 |
|
|
} else { |
5516 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_FRAMESET_IM) { |
5517 |
wakaba |
1.79 |
!!!cp ('t330'); |
5518 |
wakaba |
1.113 |
!!!parse-error (type => 'in frameset:/'.$token->{tag_name}, token => $token); |
5519 |
wakaba |
1.52 |
} else { |
5520 |
wakaba |
1.79 |
!!!cp ('t331'); |
5521 |
wakaba |
1.113 |
!!!parse-error (type => 'after frameset:/'.$token->{tag_name}, token => $token); |
5522 |
wakaba |
1.52 |
} |
5523 |
|
|
## Ignore the token |
5524 |
|
|
!!!next-token; |
5525 |
|
|
redo B; |
5526 |
|
|
} |
5527 |
wakaba |
1.104 |
} elsif ($token->{type} == END_OF_FILE_TOKEN) { |
5528 |
|
|
unless ($self->{open_elements}->[-1]->[1] eq 'html' and |
5529 |
|
|
@{$self->{open_elements}} == 1) { # redundant, maybe |
5530 |
|
|
!!!cp ('t331.1'); |
5531 |
wakaba |
1.113 |
!!!parse-error (type => 'in body:#eof', token => $token); |
5532 |
wakaba |
1.104 |
} else { |
5533 |
|
|
!!!cp ('t331.2'); |
5534 |
|
|
} |
5535 |
|
|
|
5536 |
|
|
## Stop parsing |
5537 |
|
|
last B; |
5538 |
wakaba |
1.52 |
} else { |
5539 |
|
|
die "$0: $token->{type}: Unknown token type"; |
5540 |
|
|
} |
5541 |
wakaba |
1.47 |
|
5542 |
wakaba |
1.52 |
## ISSUE: An issue in spec here |
5543 |
|
|
} else { |
5544 |
|
|
die "$0: $self->{insertion_mode}: Unknown insertion mode"; |
5545 |
|
|
} |
5546 |
wakaba |
1.47 |
|
5547 |
wakaba |
1.52 |
## "in body" insertion mode |
5548 |
wakaba |
1.55 |
if ($token->{type} == START_TAG_TOKEN) { |
5549 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'script') { |
5550 |
wakaba |
1.79 |
!!!cp ('t332'); |
5551 |
wakaba |
1.52 |
## NOTE: This is an "as if in head" code clone |
5552 |
wakaba |
1.100 |
$script_start_tag->(); |
5553 |
wakaba |
1.53 |
redo B; |
5554 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'style') { |
5555 |
wakaba |
1.79 |
!!!cp ('t333'); |
5556 |
wakaba |
1.52 |
## NOTE: This is an "as if in head" code clone |
5557 |
wakaba |
1.96 |
$parse_rcdata->(CDATA_CONTENT_MODEL); |
5558 |
wakaba |
1.53 |
redo B; |
5559 |
wakaba |
1.52 |
} elsif ({ |
5560 |
|
|
base => 1, link => 1, |
5561 |
|
|
}->{$token->{tag_name}}) { |
5562 |
wakaba |
1.79 |
!!!cp ('t334'); |
5563 |
wakaba |
1.52 |
## NOTE: This is an "as if in head" code clone, only "-t" differs |
5564 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
5565 |
|
|
pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec. |
5566 |
|
|
!!!next-token; |
5567 |
wakaba |
1.53 |
redo B; |
5568 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'meta') { |
5569 |
|
|
## NOTE: This is an "as if in head" code clone, only "-t" differs |
5570 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
5571 |
wakaba |
1.66 |
my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec. |
5572 |
wakaba |
1.46 |
|
5573 |
wakaba |
1.52 |
unless ($self->{confident}) { |
5574 |
|
|
if ($token->{attributes}->{charset}) { ## TODO: And if supported |
5575 |
wakaba |
1.79 |
!!!cp ('t335'); |
5576 |
wakaba |
1.63 |
$self->{change_encoding} |
5577 |
wakaba |
1.114 |
->($self, $token->{attributes}->{charset}->{value}, $token); |
5578 |
wakaba |
1.66 |
|
5579 |
|
|
$meta_el->[0]->get_attribute_node_ns (undef, 'charset') |
5580 |
|
|
->set_user_data (manakai_has_reference => |
5581 |
|
|
$token->{attributes}->{charset} |
5582 |
|
|
->{has_reference}); |
5583 |
wakaba |
1.63 |
} elsif ($token->{attributes}->{content}) { |
5584 |
wakaba |
1.52 |
## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition. |
5585 |
wakaba |
1.63 |
if ($token->{attributes}->{content}->{value} |
5586 |
wakaba |
1.70 |
=~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt] |
5587 |
|
|
[\x09-\x0D\x20]*= |
5588 |
wakaba |
1.52 |
[\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'| |
5589 |
|
|
([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) { |
5590 |
wakaba |
1.79 |
!!!cp ('t336'); |
5591 |
wakaba |
1.63 |
$self->{change_encoding} |
5592 |
wakaba |
1.114 |
->($self, defined $1 ? $1 : defined $2 ? $2 : $3, $token); |
5593 |
wakaba |
1.68 |
$meta_el->[0]->get_attribute_node_ns (undef, 'content') |
5594 |
|
|
->set_user_data (manakai_has_reference => |
5595 |
|
|
$token->{attributes}->{content} |
5596 |
|
|
->{has_reference}); |
5597 |
wakaba |
1.63 |
} |
5598 |
wakaba |
1.52 |
} |
5599 |
wakaba |
1.66 |
} else { |
5600 |
|
|
if ($token->{attributes}->{charset}) { |
5601 |
wakaba |
1.79 |
!!!cp ('t337'); |
5602 |
wakaba |
1.66 |
$meta_el->[0]->get_attribute_node_ns (undef, 'charset') |
5603 |
|
|
->set_user_data (manakai_has_reference => |
5604 |
|
|
$token->{attributes}->{charset} |
5605 |
|
|
->{has_reference}); |
5606 |
|
|
} |
5607 |
wakaba |
1.68 |
if ($token->{attributes}->{content}) { |
5608 |
wakaba |
1.79 |
!!!cp ('t338'); |
5609 |
wakaba |
1.68 |
$meta_el->[0]->get_attribute_node_ns (undef, 'content') |
5610 |
|
|
->set_user_data (manakai_has_reference => |
5611 |
|
|
$token->{attributes}->{content} |
5612 |
|
|
->{has_reference}); |
5613 |
|
|
} |
5614 |
wakaba |
1.52 |
} |
5615 |
wakaba |
1.1 |
|
5616 |
wakaba |
1.52 |
!!!next-token; |
5617 |
wakaba |
1.53 |
redo B; |
5618 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'title') { |
5619 |
wakaba |
1.79 |
!!!cp ('t341'); |
5620 |
wakaba |
1.52 |
## NOTE: This is an "as if in head" code clone |
5621 |
wakaba |
1.96 |
$parse_rcdata->(RCDATA_CONTENT_MODEL); |
5622 |
wakaba |
1.53 |
redo B; |
5623 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'body') { |
5624 |
wakaba |
1.113 |
!!!parse-error (type => 'in body:body', token => $token); |
5625 |
wakaba |
1.46 |
|
5626 |
wakaba |
1.52 |
if (@{$self->{open_elements}} == 1 or |
5627 |
|
|
$self->{open_elements}->[1]->[1] ne 'body') { |
5628 |
wakaba |
1.79 |
!!!cp ('t342'); |
5629 |
wakaba |
1.52 |
## Ignore the token |
5630 |
|
|
} else { |
5631 |
|
|
my $body_el = $self->{open_elements}->[1]->[0]; |
5632 |
|
|
for my $attr_name (keys %{$token->{attributes}}) { |
5633 |
|
|
unless ($body_el->has_attribute_ns (undef, $attr_name)) { |
5634 |
wakaba |
1.79 |
!!!cp ('t343'); |
5635 |
wakaba |
1.52 |
$body_el->set_attribute_ns |
5636 |
|
|
(undef, [undef, $attr_name], |
5637 |
|
|
$token->{attributes}->{$attr_name}->{value}); |
5638 |
|
|
} |
5639 |
|
|
} |
5640 |
|
|
} |
5641 |
|
|
!!!next-token; |
5642 |
wakaba |
1.53 |
redo B; |
5643 |
wakaba |
1.52 |
} elsif ({ |
5644 |
|
|
address => 1, blockquote => 1, center => 1, dir => 1, |
5645 |
wakaba |
1.85 |
div => 1, dl => 1, fieldset => 1, |
5646 |
|
|
h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1, |
5647 |
wakaba |
1.97 |
menu => 1, ol => 1, p => 1, ul => 1, |
5648 |
|
|
pre => 1, listing => 1, |
5649 |
wakaba |
1.109 |
form => 1, |
5650 |
|
|
table => 1, |
5651 |
|
|
hr => 1, |
5652 |
wakaba |
1.52 |
}->{$token->{tag_name}}) { |
5653 |
wakaba |
1.109 |
if ($token->{tag_name} eq 'form' and defined $self->{form_element}) { |
5654 |
|
|
!!!cp ('t350'); |
5655 |
wakaba |
1.113 |
!!!parse-error (type => 'in form:form', token => $token); |
5656 |
wakaba |
1.109 |
## Ignore the token |
5657 |
|
|
!!!next-token; |
5658 |
|
|
redo B; |
5659 |
|
|
} |
5660 |
|
|
|
5661 |
wakaba |
1.52 |
## has a p element in scope |
5662 |
|
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
5663 |
|
|
if ($_->[1] eq 'p') { |
5664 |
wakaba |
1.79 |
!!!cp ('t344'); |
5665 |
wakaba |
1.52 |
!!!back-token; |
5666 |
wakaba |
1.114 |
$token = {type => END_TAG_TOKEN, tag_name => 'p', |
5667 |
|
|
line => $token->{line}, column => $token->{column}}; |
5668 |
wakaba |
1.53 |
redo B; |
5669 |
wakaba |
1.52 |
} elsif ({ |
5670 |
wakaba |
1.103 |
applet => 1, table => 1, caption => 1, td => 1, th => 1, |
5671 |
wakaba |
1.52 |
button => 1, marquee => 1, object => 1, html => 1, |
5672 |
|
|
}->{$_->[1]}) { |
5673 |
wakaba |
1.79 |
!!!cp ('t345'); |
5674 |
wakaba |
1.52 |
last INSCOPE; |
5675 |
|
|
} |
5676 |
|
|
} # INSCOPE |
5677 |
|
|
|
5678 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
5679 |
wakaba |
1.97 |
if ($token->{tag_name} eq 'pre' or $token->{tag_name} eq 'listing') { |
5680 |
wakaba |
1.52 |
!!!next-token; |
5681 |
wakaba |
1.55 |
if ($token->{type} == CHARACTER_TOKEN) { |
5682 |
wakaba |
1.52 |
$token->{data} =~ s/^\x0A//; |
5683 |
|
|
unless (length $token->{data}) { |
5684 |
wakaba |
1.79 |
!!!cp ('t346'); |
5685 |
wakaba |
1.1 |
!!!next-token; |
5686 |
wakaba |
1.79 |
} else { |
5687 |
|
|
!!!cp ('t349'); |
5688 |
wakaba |
1.52 |
} |
5689 |
wakaba |
1.79 |
} else { |
5690 |
|
|
!!!cp ('t348'); |
5691 |
wakaba |
1.52 |
} |
5692 |
wakaba |
1.109 |
} elsif ($token->{tag_name} eq 'form') { |
5693 |
|
|
!!!cp ('t347.1'); |
5694 |
|
|
$self->{form_element} = $self->{open_elements}->[-1]->[0]; |
5695 |
|
|
|
5696 |
|
|
!!!next-token; |
5697 |
|
|
} elsif ($token->{tag_name} eq 'table') { |
5698 |
|
|
!!!cp ('t382'); |
5699 |
|
|
push @{$open_tables}, [$self->{open_elements}->[-1]->[0]]; |
5700 |
|
|
|
5701 |
|
|
$self->{insertion_mode} = IN_TABLE_IM; |
5702 |
|
|
|
5703 |
|
|
!!!next-token; |
5704 |
|
|
} elsif ($token->{tag_name} eq 'hr') { |
5705 |
|
|
!!!cp ('t386'); |
5706 |
|
|
pop @{$self->{open_elements}}; |
5707 |
|
|
|
5708 |
|
|
!!!next-token; |
5709 |
wakaba |
1.52 |
} else { |
5710 |
wakaba |
1.79 |
!!!cp ('t347'); |
5711 |
wakaba |
1.52 |
!!!next-token; |
5712 |
|
|
} |
5713 |
wakaba |
1.53 |
redo B; |
5714 |
wakaba |
1.109 |
} elsif ({li => 1, dt => 1, dd => 1}->{$token->{tag_name}}) { |
5715 |
wakaba |
1.52 |
## has a p element in scope |
5716 |
|
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
5717 |
|
|
if ($_->[1] eq 'p') { |
5718 |
wakaba |
1.79 |
!!!cp ('t353'); |
5719 |
wakaba |
1.52 |
!!!back-token; |
5720 |
wakaba |
1.114 |
$token = {type => END_TAG_TOKEN, tag_name => 'p', |
5721 |
|
|
line => $token->{line}, column => $token->{column}}; |
5722 |
wakaba |
1.53 |
redo B; |
5723 |
wakaba |
1.52 |
} elsif ({ |
5724 |
wakaba |
1.103 |
applet => 1, table => 1, caption => 1, td => 1, th => 1, |
5725 |
wakaba |
1.52 |
button => 1, marquee => 1, object => 1, html => 1, |
5726 |
|
|
}->{$_->[1]}) { |
5727 |
wakaba |
1.79 |
!!!cp ('t354'); |
5728 |
wakaba |
1.52 |
last INSCOPE; |
5729 |
|
|
} |
5730 |
|
|
} # INSCOPE |
5731 |
|
|
|
5732 |
|
|
## Step 1 |
5733 |
|
|
my $i = -1; |
5734 |
|
|
my $node = $self->{open_elements}->[$i]; |
5735 |
wakaba |
1.109 |
my $li_or_dtdd = {li => {li => 1}, |
5736 |
|
|
dt => {dt => 1, dd => 1}, |
5737 |
|
|
dd => {dt => 1, dd => 1}}->{$token->{tag_name}}; |
5738 |
wakaba |
1.52 |
LI: { |
5739 |
|
|
## Step 2 |
5740 |
wakaba |
1.109 |
if ($li_or_dtdd->{$node->[1]}) { |
5741 |
wakaba |
1.52 |
if ($i != -1) { |
5742 |
wakaba |
1.79 |
!!!cp ('t355'); |
5743 |
wakaba |
1.52 |
!!!parse-error (type => 'end tag missing:'. |
5744 |
wakaba |
1.113 |
$self->{open_elements}->[-1]->[1], token => $token); |
5745 |
wakaba |
1.79 |
} else { |
5746 |
|
|
!!!cp ('t356'); |
5747 |
wakaba |
1.52 |
} |
5748 |
|
|
splice @{$self->{open_elements}}, $i; |
5749 |
|
|
last LI; |
5750 |
wakaba |
1.79 |
} else { |
5751 |
|
|
!!!cp ('t357'); |
5752 |
wakaba |
1.52 |
} |
5753 |
|
|
|
5754 |
|
|
## Step 3 |
5755 |
|
|
if (not $formatting_category->{$node->[1]} and |
5756 |
|
|
#not $phrasing_category->{$node->[1]} and |
5757 |
|
|
($special_category->{$node->[1]} or |
5758 |
|
|
$scoping_category->{$node->[1]}) and |
5759 |
|
|
$node->[1] ne 'address' and $node->[1] ne 'div') { |
5760 |
wakaba |
1.79 |
!!!cp ('t358'); |
5761 |
wakaba |
1.52 |
last LI; |
5762 |
|
|
} |
5763 |
|
|
|
5764 |
wakaba |
1.79 |
!!!cp ('t359'); |
5765 |
wakaba |
1.52 |
## Step 4 |
5766 |
|
|
$i--; |
5767 |
|
|
$node = $self->{open_elements}->[$i]; |
5768 |
|
|
redo LI; |
5769 |
|
|
} # LI |
5770 |
|
|
|
5771 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
5772 |
|
|
!!!next-token; |
5773 |
wakaba |
1.53 |
redo B; |
5774 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'plaintext') { |
5775 |
|
|
## has a p element in scope |
5776 |
|
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
5777 |
|
|
if ($_->[1] eq 'p') { |
5778 |
wakaba |
1.79 |
!!!cp ('t367'); |
5779 |
wakaba |
1.52 |
!!!back-token; |
5780 |
wakaba |
1.114 |
$token = {type => END_TAG_TOKEN, tag_name => 'p', |
5781 |
|
|
line => $token->{line}, column => $token->{column}}; |
5782 |
wakaba |
1.53 |
redo B; |
5783 |
wakaba |
1.52 |
} elsif ({ |
5784 |
wakaba |
1.103 |
applet => 1, table => 1, caption => 1, td => 1, th => 1, |
5785 |
wakaba |
1.52 |
button => 1, marquee => 1, object => 1, html => 1, |
5786 |
|
|
}->{$_->[1]}) { |
5787 |
wakaba |
1.79 |
!!!cp ('t368'); |
5788 |
wakaba |
1.52 |
last INSCOPE; |
5789 |
wakaba |
1.46 |
} |
5790 |
wakaba |
1.52 |
} # INSCOPE |
5791 |
|
|
|
5792 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
5793 |
|
|
|
5794 |
|
|
$self->{content_model} = PLAINTEXT_CONTENT_MODEL; |
5795 |
|
|
|
5796 |
|
|
!!!next-token; |
5797 |
wakaba |
1.53 |
redo B; |
5798 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'a') { |
5799 |
|
|
AFE: for my $i (reverse 0..$#$active_formatting_elements) { |
5800 |
|
|
my $node = $active_formatting_elements->[$i]; |
5801 |
|
|
if ($node->[1] eq 'a') { |
5802 |
wakaba |
1.79 |
!!!cp ('t371'); |
5803 |
wakaba |
1.113 |
!!!parse-error (type => 'in a:a', token => $token); |
5804 |
wakaba |
1.52 |
|
5805 |
|
|
!!!back-token; |
5806 |
wakaba |
1.114 |
$token = {type => END_TAG_TOKEN, tag_name => 'a', |
5807 |
|
|
line => $token->{line}, column => $token->{column}}; |
5808 |
wakaba |
1.113 |
$formatting_end_tag->($token); |
5809 |
wakaba |
1.52 |
|
5810 |
|
|
AFE2: for (reverse 0..$#$active_formatting_elements) { |
5811 |
|
|
if ($active_formatting_elements->[$_]->[0] eq $node->[0]) { |
5812 |
wakaba |
1.79 |
!!!cp ('t372'); |
5813 |
wakaba |
1.52 |
splice @$active_formatting_elements, $_, 1; |
5814 |
|
|
last AFE2; |
5815 |
wakaba |
1.1 |
} |
5816 |
wakaba |
1.52 |
} # AFE2 |
5817 |
|
|
OE: for (reverse 0..$#{$self->{open_elements}}) { |
5818 |
|
|
if ($self->{open_elements}->[$_]->[0] eq $node->[0]) { |
5819 |
wakaba |
1.79 |
!!!cp ('t373'); |
5820 |
wakaba |
1.52 |
splice @{$self->{open_elements}}, $_, 1; |
5821 |
|
|
last OE; |
5822 |
wakaba |
1.1 |
} |
5823 |
wakaba |
1.52 |
} # OE |
5824 |
|
|
last AFE; |
5825 |
|
|
} elsif ($node->[0] eq '#marker') { |
5826 |
wakaba |
1.79 |
!!!cp ('t374'); |
5827 |
wakaba |
1.52 |
last AFE; |
5828 |
|
|
} |
5829 |
|
|
} # AFE |
5830 |
|
|
|
5831 |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
5832 |
wakaba |
1.1 |
|
5833 |
wakaba |
1.52 |
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
5834 |
|
|
push @$active_formatting_elements, $self->{open_elements}->[-1]; |
5835 |
wakaba |
1.1 |
|
5836 |
wakaba |
1.52 |
!!!next-token; |
5837 |
wakaba |
1.53 |
redo B; |
5838 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'nobr') { |
5839 |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
5840 |
wakaba |
1.1 |
|
5841 |
wakaba |
1.52 |
## has a |nobr| element in scope |
5842 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
5843 |
|
|
my $node = $self->{open_elements}->[$_]; |
5844 |
|
|
if ($node->[1] eq 'nobr') { |
5845 |
wakaba |
1.79 |
!!!cp ('t376'); |
5846 |
wakaba |
1.113 |
!!!parse-error (type => 'in nobr:nobr', token => $token); |
5847 |
wakaba |
1.52 |
!!!back-token; |
5848 |
wakaba |
1.114 |
$token = {type => END_TAG_TOKEN, tag_name => 'nobr', |
5849 |
|
|
line => $token->{line}, column => $token->{column}}; |
5850 |
wakaba |
1.53 |
redo B; |
5851 |
wakaba |
1.52 |
} elsif ({ |
5852 |
wakaba |
1.103 |
applet => 1, table => 1, caption => 1, td => 1, th => 1, |
5853 |
wakaba |
1.52 |
button => 1, marquee => 1, object => 1, html => 1, |
5854 |
|
|
}->{$node->[1]}) { |
5855 |
wakaba |
1.79 |
!!!cp ('t377'); |
5856 |
wakaba |
1.52 |
last INSCOPE; |
5857 |
|
|
} |
5858 |
|
|
} # INSCOPE |
5859 |
|
|
|
5860 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
5861 |
|
|
push @$active_formatting_elements, $self->{open_elements}->[-1]; |
5862 |
|
|
|
5863 |
|
|
!!!next-token; |
5864 |
wakaba |
1.53 |
redo B; |
5865 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'button') { |
5866 |
|
|
## has a button element in scope |
5867 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
5868 |
|
|
my $node = $self->{open_elements}->[$_]; |
5869 |
|
|
if ($node->[1] eq 'button') { |
5870 |
wakaba |
1.79 |
!!!cp ('t378'); |
5871 |
wakaba |
1.113 |
!!!parse-error (type => 'in button:button', token => $token); |
5872 |
wakaba |
1.52 |
!!!back-token; |
5873 |
wakaba |
1.114 |
$token = {type => END_TAG_TOKEN, tag_name => 'button', |
5874 |
|
|
line => $token->{line}, column => $token->{column}}; |
5875 |
wakaba |
1.53 |
redo B; |
5876 |
wakaba |
1.52 |
} elsif ({ |
5877 |
wakaba |
1.103 |
applet => 1, table => 1, caption => 1, td => 1, th => 1, |
5878 |
wakaba |
1.52 |
button => 1, marquee => 1, object => 1, html => 1, |
5879 |
|
|
}->{$node->[1]}) { |
5880 |
wakaba |
1.79 |
!!!cp ('t379'); |
5881 |
wakaba |
1.52 |
last INSCOPE; |
5882 |
|
|
} |
5883 |
|
|
} # INSCOPE |
5884 |
|
|
|
5885 |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
5886 |
|
|
|
5887 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
5888 |
wakaba |
1.85 |
|
5889 |
|
|
## TODO: associate with $self->{form_element} if defined |
5890 |
|
|
|
5891 |
wakaba |
1.52 |
push @$active_formatting_elements, ['#marker', '']; |
5892 |
wakaba |
1.1 |
|
5893 |
wakaba |
1.52 |
!!!next-token; |
5894 |
wakaba |
1.53 |
redo B; |
5895 |
wakaba |
1.103 |
} elsif ({ |
5896 |
wakaba |
1.109 |
xmp => 1, |
5897 |
|
|
iframe => 1, |
5898 |
|
|
noembed => 1, |
5899 |
|
|
noframes => 1, |
5900 |
|
|
noscript => 0, ## TODO: 1 if scripting is enabled |
5901 |
wakaba |
1.103 |
}->{$token->{tag_name}}) { |
5902 |
wakaba |
1.109 |
if ($token->{tag_name} eq 'xmp') { |
5903 |
|
|
!!!cp ('t381'); |
5904 |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
5905 |
|
|
} else { |
5906 |
|
|
!!!cp ('t399'); |
5907 |
|
|
} |
5908 |
|
|
## NOTE: There is an "as if in body" code clone. |
5909 |
wakaba |
1.96 |
$parse_rcdata->(CDATA_CONTENT_MODEL); |
5910 |
wakaba |
1.53 |
redo B; |
5911 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'isindex') { |
5912 |
wakaba |
1.113 |
!!!parse-error (type => 'isindex', token => $token); |
5913 |
wakaba |
1.52 |
|
5914 |
|
|
if (defined $self->{form_element}) { |
5915 |
wakaba |
1.79 |
!!!cp ('t389'); |
5916 |
wakaba |
1.52 |
## Ignore the token |
5917 |
|
|
!!!next-token; |
5918 |
wakaba |
1.53 |
redo B; |
5919 |
wakaba |
1.52 |
} else { |
5920 |
|
|
my $at = $token->{attributes}; |
5921 |
|
|
my $form_attrs; |
5922 |
|
|
$form_attrs->{action} = $at->{action} if $at->{action}; |
5923 |
|
|
my $prompt_attr = $at->{prompt}; |
5924 |
|
|
$at->{name} = {name => 'name', value => 'isindex'}; |
5925 |
|
|
delete $at->{action}; |
5926 |
|
|
delete $at->{prompt}; |
5927 |
|
|
my @tokens = ( |
5928 |
wakaba |
1.55 |
{type => START_TAG_TOKEN, tag_name => 'form', |
5929 |
wakaba |
1.114 |
attributes => $form_attrs, |
5930 |
|
|
line => $token->{line}, column => $token->{column}}, |
5931 |
|
|
{type => START_TAG_TOKEN, tag_name => 'hr', |
5932 |
|
|
line => $token->{line}, column => $token->{column}}, |
5933 |
|
|
{type => START_TAG_TOKEN, tag_name => 'p', |
5934 |
|
|
line => $token->{line}, column => $token->{column}}, |
5935 |
|
|
{type => START_TAG_TOKEN, tag_name => 'label', |
5936 |
|
|
line => $token->{line}, column => $token->{column}}, |
5937 |
wakaba |
1.52 |
); |
5938 |
|
|
if ($prompt_attr) { |
5939 |
wakaba |
1.79 |
!!!cp ('t390'); |
5940 |
wakaba |
1.114 |
push @tokens, {type => CHARACTER_TOKEN, data => $prompt_attr->{value}, |
5941 |
|
|
line => $token->{line}, column => $token->{column}}; |
5942 |
wakaba |
1.1 |
} else { |
5943 |
wakaba |
1.79 |
!!!cp ('t391'); |
5944 |
wakaba |
1.55 |
push @tokens, {type => CHARACTER_TOKEN, |
5945 |
wakaba |
1.114 |
data => 'This is a searchable index. Insert your search keywords here: ', |
5946 |
|
|
line => $token->{line}, column => $token->{column}}; # SHOULD |
5947 |
wakaba |
1.52 |
## TODO: make this configurable |
5948 |
wakaba |
1.1 |
} |
5949 |
wakaba |
1.52 |
push @tokens, |
5950 |
wakaba |
1.114 |
{type => START_TAG_TOKEN, tag_name => 'input', attributes => $at, |
5951 |
|
|
line => $token->{line}, column => $token->{column}}, |
5952 |
wakaba |
1.55 |
#{type => CHARACTER_TOKEN, data => ''}, # SHOULD |
5953 |
wakaba |
1.114 |
{type => END_TAG_TOKEN, tag_name => 'label', |
5954 |
|
|
line => $token->{line}, column => $token->{column}}, |
5955 |
|
|
{type => END_TAG_TOKEN, tag_name => 'p', |
5956 |
|
|
line => $token->{line}, column => $token->{column}}, |
5957 |
|
|
{type => START_TAG_TOKEN, tag_name => 'hr', |
5958 |
|
|
line => $token->{line}, column => $token->{column}}, |
5959 |
|
|
{type => END_TAG_TOKEN, tag_name => 'form', |
5960 |
|
|
line => $token->{line}, column => $token->{column}}; |
5961 |
wakaba |
1.52 |
$token = shift @tokens; |
5962 |
|
|
!!!back-token (@tokens); |
5963 |
wakaba |
1.53 |
redo B; |
5964 |
wakaba |
1.52 |
} |
5965 |
|
|
} elsif ($token->{tag_name} eq 'textarea') { |
5966 |
|
|
my $tag_name = $token->{tag_name}; |
5967 |
|
|
my $el; |
5968 |
|
|
!!!create-element ($el, $token->{tag_name}, $token->{attributes}); |
5969 |
|
|
|
5970 |
|
|
## TODO: $self->{form_element} if defined |
5971 |
|
|
$self->{content_model} = RCDATA_CONTENT_MODEL; |
5972 |
|
|
delete $self->{escape}; # MUST |
5973 |
|
|
|
5974 |
|
|
$insert->($el); |
5975 |
|
|
|
5976 |
|
|
my $text = ''; |
5977 |
|
|
!!!next-token; |
5978 |
wakaba |
1.55 |
if ($token->{type} == CHARACTER_TOKEN) { |
5979 |
wakaba |
1.52 |
$token->{data} =~ s/^\x0A//; |
5980 |
wakaba |
1.51 |
unless (length $token->{data}) { |
5981 |
wakaba |
1.79 |
!!!cp ('t392'); |
5982 |
wakaba |
1.51 |
!!!next-token; |
5983 |
wakaba |
1.79 |
} else { |
5984 |
|
|
!!!cp ('t393'); |
5985 |
wakaba |
1.51 |
} |
5986 |
wakaba |
1.79 |
} else { |
5987 |
|
|
!!!cp ('t394'); |
5988 |
wakaba |
1.51 |
} |
5989 |
wakaba |
1.55 |
while ($token->{type} == CHARACTER_TOKEN) { |
5990 |
wakaba |
1.79 |
!!!cp ('t395'); |
5991 |
wakaba |
1.52 |
$text .= $token->{data}; |
5992 |
|
|
!!!next-token; |
5993 |
|
|
} |
5994 |
|
|
if (length $text) { |
5995 |
wakaba |
1.79 |
!!!cp ('t396'); |
5996 |
wakaba |
1.52 |
$el->manakai_append_text ($text); |
5997 |
|
|
} |
5998 |
|
|
|
5999 |
|
|
$self->{content_model} = PCDATA_CONTENT_MODEL; |
6000 |
wakaba |
1.51 |
|
6001 |
wakaba |
1.55 |
if ($token->{type} == END_TAG_TOKEN and |
6002 |
wakaba |
1.52 |
$token->{tag_name} eq $tag_name) { |
6003 |
wakaba |
1.79 |
!!!cp ('t397'); |
6004 |
wakaba |
1.52 |
## Ignore the token |
6005 |
|
|
} else { |
6006 |
wakaba |
1.79 |
!!!cp ('t398'); |
6007 |
wakaba |
1.113 |
!!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token); |
6008 |
wakaba |
1.51 |
} |
6009 |
wakaba |
1.52 |
!!!next-token; |
6010 |
wakaba |
1.53 |
redo B; |
6011 |
wakaba |
1.52 |
} elsif ({ |
6012 |
|
|
caption => 1, col => 1, colgroup => 1, frame => 1, |
6013 |
|
|
frameset => 1, head => 1, option => 1, optgroup => 1, |
6014 |
|
|
tbody => 1, td => 1, tfoot => 1, th => 1, |
6015 |
|
|
thead => 1, tr => 1, |
6016 |
|
|
}->{$token->{tag_name}}) { |
6017 |
wakaba |
1.79 |
!!!cp ('t401'); |
6018 |
wakaba |
1.113 |
!!!parse-error (type => 'in body:'.$token->{tag_name}, token => $token); |
6019 |
wakaba |
1.52 |
## Ignore the token |
6020 |
|
|
!!!next-token; |
6021 |
wakaba |
1.53 |
redo B; |
6022 |
wakaba |
1.52 |
|
6023 |
|
|
## ISSUE: An issue on HTML5 new elements in the spec. |
6024 |
|
|
} else { |
6025 |
wakaba |
1.110 |
if ($token->{tag_name} eq 'image') { |
6026 |
|
|
!!!cp ('t384'); |
6027 |
wakaba |
1.113 |
!!!parse-error (type => 'image', token => $token); |
6028 |
wakaba |
1.110 |
$token->{tag_name} = 'img'; |
6029 |
|
|
} else { |
6030 |
|
|
!!!cp ('t385'); |
6031 |
|
|
} |
6032 |
|
|
|
6033 |
|
|
## NOTE: There is an "as if <br>" code clone. |
6034 |
wakaba |
1.52 |
$reconstruct_active_formatting_elements->($insert_to_current); |
6035 |
|
|
|
6036 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
6037 |
wakaba |
1.109 |
|
6038 |
wakaba |
1.110 |
if ({ |
6039 |
|
|
applet => 1, marquee => 1, object => 1, |
6040 |
|
|
}->{$token->{tag_name}}) { |
6041 |
|
|
!!!cp ('t380'); |
6042 |
|
|
push @$active_formatting_elements, ['#marker', '']; |
6043 |
|
|
} elsif ({ |
6044 |
|
|
b => 1, big => 1, em => 1, font => 1, i => 1, |
6045 |
|
|
s => 1, small => 1, strile => 1, |
6046 |
|
|
strong => 1, tt => 1, u => 1, |
6047 |
|
|
}->{$token->{tag_name}}) { |
6048 |
|
|
!!!cp ('t375'); |
6049 |
|
|
push @$active_formatting_elements, $self->{open_elements}->[-1]; |
6050 |
|
|
} elsif ($token->{tag_name} eq 'input') { |
6051 |
|
|
!!!cp ('t388'); |
6052 |
|
|
## TODO: associate with $self->{form_element} if defined |
6053 |
|
|
pop @{$self->{open_elements}}; |
6054 |
|
|
} elsif ({ |
6055 |
|
|
area => 1, basefont => 1, bgsound => 1, br => 1, |
6056 |
|
|
embed => 1, img => 1, param => 1, spacer => 1, wbr => 1, |
6057 |
|
|
#image => 1, |
6058 |
|
|
}->{$token->{tag_name}}) { |
6059 |
|
|
!!!cp ('t388.1'); |
6060 |
|
|
pop @{$self->{open_elements}}; |
6061 |
|
|
} elsif ($token->{tag_name} eq 'select') { |
6062 |
wakaba |
1.109 |
## TODO: associate with $self->{form_element} if defined |
6063 |
|
|
|
6064 |
|
|
if ($self->{insertion_mode} & TABLE_IMS or |
6065 |
|
|
$self->{insertion_mode} & BODY_TABLE_IMS or |
6066 |
|
|
$self->{insertion_mode} == IN_COLUMN_GROUP_IM) { |
6067 |
|
|
!!!cp ('t400.1'); |
6068 |
|
|
$self->{insertion_mode} = IN_SELECT_IN_TABLE_IM; |
6069 |
|
|
} else { |
6070 |
|
|
!!!cp ('t400.2'); |
6071 |
|
|
$self->{insertion_mode} = IN_SELECT_IM; |
6072 |
|
|
} |
6073 |
wakaba |
1.110 |
} else { |
6074 |
|
|
!!!cp ('t402'); |
6075 |
wakaba |
1.109 |
} |
6076 |
wakaba |
1.51 |
|
6077 |
wakaba |
1.52 |
!!!next-token; |
6078 |
wakaba |
1.53 |
redo B; |
6079 |
wakaba |
1.52 |
} |
6080 |
wakaba |
1.55 |
} elsif ($token->{type} == END_TAG_TOKEN) { |
6081 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'body') { |
6082 |
wakaba |
1.107 |
## has a |body| element in scope |
6083 |
|
|
my $i; |
6084 |
wakaba |
1.111 |
INSCOPE: { |
6085 |
|
|
for (reverse @{$self->{open_elements}}) { |
6086 |
|
|
if ($_->[1] eq 'body') { |
6087 |
|
|
!!!cp ('t405'); |
6088 |
|
|
$i = $_; |
6089 |
|
|
last INSCOPE; |
6090 |
|
|
} elsif ({ |
6091 |
|
|
applet => 1, table => 1, caption => 1, td => 1, th => 1, |
6092 |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
6093 |
|
|
}->{$_->[1]}) { |
6094 |
|
|
!!!cp ('t405.1'); |
6095 |
|
|
last; |
6096 |
|
|
} |
6097 |
wakaba |
1.52 |
} |
6098 |
wakaba |
1.111 |
|
6099 |
|
|
!!!parse-error (type => 'start tag not allowed', |
6100 |
wakaba |
1.113 |
value => $token->{tag_name}, token => $token); |
6101 |
wakaba |
1.107 |
## NOTE: Ignore the token. |
6102 |
wakaba |
1.52 |
!!!next-token; |
6103 |
wakaba |
1.53 |
redo B; |
6104 |
wakaba |
1.111 |
} # INSCOPE |
6105 |
wakaba |
1.107 |
|
6106 |
|
|
for (@{$self->{open_elements}}) { |
6107 |
|
|
unless ({ |
6108 |
|
|
dd => 1, dt => 1, li => 1, p => 1, td => 1, |
6109 |
|
|
th => 1, tr => 1, body => 1, html => 1, |
6110 |
|
|
tbody => 1, tfoot => 1, thead => 1, |
6111 |
|
|
}->{$_->[1]}) { |
6112 |
|
|
!!!cp ('t403'); |
6113 |
wakaba |
1.113 |
!!!parse-error (type => 'not closed:'.$_->[1], token => $token); |
6114 |
wakaba |
1.107 |
last; |
6115 |
|
|
} else { |
6116 |
|
|
!!!cp ('t404'); |
6117 |
|
|
} |
6118 |
|
|
} |
6119 |
|
|
|
6120 |
|
|
$self->{insertion_mode} = AFTER_BODY_IM; |
6121 |
|
|
!!!next-token; |
6122 |
|
|
redo B; |
6123 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'html') { |
6124 |
|
|
if (@{$self->{open_elements}} > 1 and $self->{open_elements}->[1]->[1] eq 'body') { |
6125 |
|
|
## ISSUE: There is an issue in the spec. |
6126 |
|
|
if ($self->{open_elements}->[-1]->[1] ne 'body') { |
6127 |
wakaba |
1.79 |
!!!cp ('t406'); |
6128 |
wakaba |
1.113 |
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[1]->[1], token => $token); |
6129 |
wakaba |
1.79 |
} else { |
6130 |
|
|
!!!cp ('t407'); |
6131 |
wakaba |
1.1 |
} |
6132 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_BODY_IM; |
6133 |
wakaba |
1.52 |
## reprocess |
6134 |
wakaba |
1.53 |
redo B; |
6135 |
wakaba |
1.51 |
} else { |
6136 |
wakaba |
1.79 |
!!!cp ('t408'); |
6137 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
6138 |
wakaba |
1.52 |
## Ignore the token |
6139 |
|
|
!!!next-token; |
6140 |
wakaba |
1.53 |
redo B; |
6141 |
wakaba |
1.51 |
} |
6142 |
wakaba |
1.52 |
} elsif ({ |
6143 |
|
|
address => 1, blockquote => 1, center => 1, dir => 1, |
6144 |
|
|
div => 1, dl => 1, fieldset => 1, listing => 1, |
6145 |
|
|
menu => 1, ol => 1, pre => 1, ul => 1, |
6146 |
|
|
dd => 1, dt => 1, li => 1, |
6147 |
wakaba |
1.103 |
applet => 1, button => 1, marquee => 1, object => 1, |
6148 |
wakaba |
1.52 |
}->{$token->{tag_name}}) { |
6149 |
|
|
## has an element in scope |
6150 |
|
|
my $i; |
6151 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
6152 |
|
|
my $node = $self->{open_elements}->[$_]; |
6153 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
6154 |
wakaba |
1.79 |
!!!cp ('t410'); |
6155 |
wakaba |
1.52 |
$i = $_; |
6156 |
wakaba |
1.87 |
last INSCOPE; |
6157 |
wakaba |
1.52 |
} elsif ({ |
6158 |
wakaba |
1.103 |
applet => 1, table => 1, caption => 1, td => 1, th => 1, |
6159 |
wakaba |
1.52 |
button => 1, marquee => 1, object => 1, html => 1, |
6160 |
|
|
}->{$node->[1]}) { |
6161 |
wakaba |
1.79 |
!!!cp ('t411'); |
6162 |
wakaba |
1.52 |
last INSCOPE; |
6163 |
wakaba |
1.51 |
} |
6164 |
wakaba |
1.52 |
} # INSCOPE |
6165 |
wakaba |
1.89 |
|
6166 |
|
|
unless (defined $i) { # has an element in scope |
6167 |
|
|
!!!cp ('t413'); |
6168 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
6169 |
wakaba |
1.89 |
} else { |
6170 |
|
|
## Step 1. generate implied end tags |
6171 |
|
|
while ({ |
6172 |
|
|
dd => ($token->{tag_name} ne 'dd'), |
6173 |
|
|
dt => ($token->{tag_name} ne 'dt'), |
6174 |
|
|
li => ($token->{tag_name} ne 'li'), |
6175 |
|
|
p => 1, |
6176 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
6177 |
|
|
!!!cp ('t409'); |
6178 |
|
|
pop @{$self->{open_elements}}; |
6179 |
|
|
} |
6180 |
|
|
|
6181 |
|
|
## Step 2. |
6182 |
|
|
if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) { |
6183 |
wakaba |
1.79 |
!!!cp ('t412'); |
6184 |
wakaba |
1.113 |
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token); |
6185 |
wakaba |
1.51 |
} else { |
6186 |
wakaba |
1.89 |
!!!cp ('t414'); |
6187 |
wakaba |
1.51 |
} |
6188 |
wakaba |
1.89 |
|
6189 |
|
|
## Step 3. |
6190 |
wakaba |
1.52 |
splice @{$self->{open_elements}}, $i; |
6191 |
wakaba |
1.89 |
|
6192 |
|
|
## Step 4. |
6193 |
|
|
$clear_up_to_marker->() |
6194 |
|
|
if { |
6195 |
wakaba |
1.103 |
applet => 1, button => 1, marquee => 1, object => 1, |
6196 |
wakaba |
1.89 |
}->{$token->{tag_name}}; |
6197 |
wakaba |
1.51 |
} |
6198 |
wakaba |
1.52 |
!!!next-token; |
6199 |
wakaba |
1.53 |
redo B; |
6200 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'form') { |
6201 |
wakaba |
1.92 |
undef $self->{form_element}; |
6202 |
|
|
|
6203 |
wakaba |
1.52 |
## has an element in scope |
6204 |
wakaba |
1.92 |
my $i; |
6205 |
wakaba |
1.52 |
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
6206 |
|
|
my $node = $self->{open_elements}->[$_]; |
6207 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
6208 |
wakaba |
1.79 |
!!!cp ('t418'); |
6209 |
wakaba |
1.92 |
$i = $_; |
6210 |
wakaba |
1.52 |
last INSCOPE; |
6211 |
|
|
} elsif ({ |
6212 |
wakaba |
1.103 |
applet => 1, table => 1, caption => 1, td => 1, th => 1, |
6213 |
wakaba |
1.52 |
button => 1, marquee => 1, object => 1, html => 1, |
6214 |
|
|
}->{$node->[1]}) { |
6215 |
wakaba |
1.79 |
!!!cp ('t419'); |
6216 |
wakaba |
1.52 |
last INSCOPE; |
6217 |
|
|
} |
6218 |
|
|
} # INSCOPE |
6219 |
wakaba |
1.92 |
|
6220 |
|
|
unless (defined $i) { # has an element in scope |
6221 |
wakaba |
1.79 |
!!!cp ('t421'); |
6222 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
6223 |
wakaba |
1.92 |
} else { |
6224 |
|
|
## Step 1. generate implied end tags |
6225 |
|
|
while ({ |
6226 |
|
|
dd => 1, dt => 1, li => 1, p => 1, |
6227 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
6228 |
|
|
!!!cp ('t417'); |
6229 |
|
|
pop @{$self->{open_elements}}; |
6230 |
|
|
} |
6231 |
|
|
|
6232 |
|
|
## Step 2. |
6233 |
|
|
if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) { |
6234 |
|
|
!!!cp ('t417.1'); |
6235 |
wakaba |
1.113 |
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token); |
6236 |
wakaba |
1.92 |
} else { |
6237 |
|
|
!!!cp ('t420'); |
6238 |
|
|
} |
6239 |
|
|
|
6240 |
|
|
## Step 3. |
6241 |
|
|
splice @{$self->{open_elements}}, $i; |
6242 |
wakaba |
1.52 |
} |
6243 |
|
|
|
6244 |
|
|
!!!next-token; |
6245 |
wakaba |
1.53 |
redo B; |
6246 |
wakaba |
1.52 |
} elsif ({ |
6247 |
|
|
h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1, |
6248 |
|
|
}->{$token->{tag_name}}) { |
6249 |
|
|
## has an element in scope |
6250 |
|
|
my $i; |
6251 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
6252 |
|
|
my $node = $self->{open_elements}->[$_]; |
6253 |
|
|
if ({ |
6254 |
|
|
h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1, |
6255 |
|
|
}->{$node->[1]}) { |
6256 |
wakaba |
1.79 |
!!!cp ('t423'); |
6257 |
wakaba |
1.52 |
$i = $_; |
6258 |
|
|
last INSCOPE; |
6259 |
|
|
} elsif ({ |
6260 |
wakaba |
1.103 |
applet => 1, table => 1, caption => 1, td => 1, th => 1, |
6261 |
wakaba |
1.52 |
button => 1, marquee => 1, object => 1, html => 1, |
6262 |
|
|
}->{$node->[1]}) { |
6263 |
wakaba |
1.79 |
!!!cp ('t424'); |
6264 |
wakaba |
1.52 |
last INSCOPE; |
6265 |
wakaba |
1.51 |
} |
6266 |
wakaba |
1.52 |
} # INSCOPE |
6267 |
wakaba |
1.93 |
|
6268 |
|
|
unless (defined $i) { # has an element in scope |
6269 |
|
|
!!!cp ('t425.1'); |
6270 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
6271 |
wakaba |
1.79 |
} else { |
6272 |
wakaba |
1.93 |
## Step 1. generate implied end tags |
6273 |
|
|
while ({ |
6274 |
|
|
dd => 1, dt => 1, li => 1, p => 1, |
6275 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
6276 |
|
|
!!!cp ('t422'); |
6277 |
|
|
pop @{$self->{open_elements}}; |
6278 |
|
|
} |
6279 |
|
|
|
6280 |
|
|
## Step 2. |
6281 |
|
|
if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) { |
6282 |
|
|
!!!cp ('t425'); |
6283 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
6284 |
wakaba |
1.93 |
} else { |
6285 |
|
|
!!!cp ('t426'); |
6286 |
|
|
} |
6287 |
|
|
|
6288 |
|
|
## Step 3. |
6289 |
|
|
splice @{$self->{open_elements}}, $i; |
6290 |
wakaba |
1.36 |
} |
6291 |
wakaba |
1.52 |
|
6292 |
|
|
!!!next-token; |
6293 |
wakaba |
1.53 |
redo B; |
6294 |
wakaba |
1.87 |
} elsif ($token->{tag_name} eq 'p') { |
6295 |
|
|
## has an element in scope |
6296 |
|
|
my $i; |
6297 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
6298 |
|
|
my $node = $self->{open_elements}->[$_]; |
6299 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
6300 |
|
|
!!!cp ('t410.1'); |
6301 |
|
|
$i = $_; |
6302 |
wakaba |
1.88 |
last INSCOPE; |
6303 |
wakaba |
1.87 |
} elsif ({ |
6304 |
wakaba |
1.103 |
applet => 1, table => 1, caption => 1, td => 1, th => 1, |
6305 |
wakaba |
1.87 |
button => 1, marquee => 1, object => 1, html => 1, |
6306 |
|
|
}->{$node->[1]}) { |
6307 |
|
|
!!!cp ('t411.1'); |
6308 |
|
|
last INSCOPE; |
6309 |
|
|
} |
6310 |
|
|
} # INSCOPE |
6311 |
wakaba |
1.91 |
|
6312 |
|
|
if (defined $i) { |
6313 |
|
|
if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) { |
6314 |
wakaba |
1.87 |
!!!cp ('t412.1'); |
6315 |
wakaba |
1.113 |
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token); |
6316 |
wakaba |
1.87 |
} else { |
6317 |
wakaba |
1.91 |
!!!cp ('t414.1'); |
6318 |
wakaba |
1.87 |
} |
6319 |
wakaba |
1.91 |
|
6320 |
wakaba |
1.87 |
splice @{$self->{open_elements}}, $i; |
6321 |
|
|
} else { |
6322 |
wakaba |
1.91 |
!!!cp ('t413.1'); |
6323 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
6324 |
wakaba |
1.91 |
|
6325 |
wakaba |
1.87 |
!!!cp ('t415.1'); |
6326 |
|
|
## As if <p>, then reprocess the current token |
6327 |
|
|
my $el; |
6328 |
|
|
!!!create-element ($el, 'p'); |
6329 |
|
|
$insert->($el); |
6330 |
wakaba |
1.91 |
## NOTE: Not inserted into |$self->{open_elements}|. |
6331 |
wakaba |
1.87 |
} |
6332 |
wakaba |
1.91 |
|
6333 |
wakaba |
1.87 |
!!!next-token; |
6334 |
|
|
redo B; |
6335 |
wakaba |
1.52 |
} elsif ({ |
6336 |
|
|
a => 1, |
6337 |
|
|
b => 1, big => 1, em => 1, font => 1, i => 1, |
6338 |
|
|
nobr => 1, s => 1, small => 1, strile => 1, |
6339 |
|
|
strong => 1, tt => 1, u => 1, |
6340 |
|
|
}->{$token->{tag_name}}) { |
6341 |
wakaba |
1.79 |
!!!cp ('t427'); |
6342 |
wakaba |
1.113 |
$formatting_end_tag->($token); |
6343 |
wakaba |
1.53 |
redo B; |
6344 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'br') { |
6345 |
wakaba |
1.79 |
!!!cp ('t428'); |
6346 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:br', token => $token); |
6347 |
wakaba |
1.52 |
|
6348 |
|
|
## As if <br> |
6349 |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
6350 |
|
|
|
6351 |
|
|
my $el; |
6352 |
|
|
!!!create-element ($el, 'br'); |
6353 |
|
|
$insert->($el); |
6354 |
|
|
|
6355 |
|
|
## Ignore the token. |
6356 |
|
|
!!!next-token; |
6357 |
wakaba |
1.53 |
redo B; |
6358 |
wakaba |
1.52 |
} elsif ({ |
6359 |
|
|
caption => 1, col => 1, colgroup => 1, frame => 1, |
6360 |
|
|
frameset => 1, head => 1, option => 1, optgroup => 1, |
6361 |
|
|
tbody => 1, td => 1, tfoot => 1, th => 1, |
6362 |
|
|
thead => 1, tr => 1, |
6363 |
|
|
area => 1, basefont => 1, bgsound => 1, |
6364 |
|
|
embed => 1, hr => 1, iframe => 1, image => 1, |
6365 |
|
|
img => 1, input => 1, isindex => 1, noembed => 1, |
6366 |
|
|
noframes => 1, param => 1, select => 1, spacer => 1, |
6367 |
|
|
table => 1, textarea => 1, wbr => 1, |
6368 |
|
|
noscript => 0, ## TODO: if scripting is enabled |
6369 |
|
|
}->{$token->{tag_name}}) { |
6370 |
wakaba |
1.79 |
!!!cp ('t429'); |
6371 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
6372 |
wakaba |
1.52 |
## Ignore the token |
6373 |
|
|
!!!next-token; |
6374 |
wakaba |
1.53 |
redo B; |
6375 |
wakaba |
1.52 |
|
6376 |
|
|
## ISSUE: Issue on HTML5 new elements in spec |
6377 |
|
|
|
6378 |
|
|
} else { |
6379 |
|
|
## Step 1 |
6380 |
|
|
my $node_i = -1; |
6381 |
|
|
my $node = $self->{open_elements}->[$node_i]; |
6382 |
wakaba |
1.51 |
|
6383 |
wakaba |
1.52 |
## Step 2 |
6384 |
|
|
S2: { |
6385 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
6386 |
|
|
## Step 1 |
6387 |
|
|
## generate implied end tags |
6388 |
wakaba |
1.86 |
while ({ |
6389 |
|
|
dd => 1, dt => 1, li => 1, p => 1, |
6390 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
6391 |
wakaba |
1.79 |
!!!cp ('t430'); |
6392 |
wakaba |
1.83 |
## ISSUE: Can this case be reached? |
6393 |
wakaba |
1.86 |
pop @{$self->{open_elements}}; |
6394 |
wakaba |
1.52 |
} |
6395 |
|
|
|
6396 |
|
|
## Step 2 |
6397 |
|
|
if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) { |
6398 |
wakaba |
1.79 |
!!!cp ('t431'); |
6399 |
wakaba |
1.58 |
## NOTE: <x><y></x> |
6400 |
wakaba |
1.113 |
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token); |
6401 |
wakaba |
1.79 |
} else { |
6402 |
|
|
!!!cp ('t432'); |
6403 |
wakaba |
1.52 |
} |
6404 |
|
|
|
6405 |
|
|
## Step 3 |
6406 |
|
|
splice @{$self->{open_elements}}, $node_i; |
6407 |
wakaba |
1.51 |
|
6408 |
wakaba |
1.1 |
!!!next-token; |
6409 |
wakaba |
1.52 |
last S2; |
6410 |
wakaba |
1.1 |
} else { |
6411 |
wakaba |
1.52 |
## Step 3 |
6412 |
|
|
if (not $formatting_category->{$node->[1]} and |
6413 |
|
|
#not $phrasing_category->{$node->[1]} and |
6414 |
|
|
($special_category->{$node->[1]} or |
6415 |
|
|
$scoping_category->{$node->[1]})) { |
6416 |
wakaba |
1.79 |
!!!cp ('t433'); |
6417 |
wakaba |
1.113 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token); |
6418 |
wakaba |
1.52 |
## Ignore the token |
6419 |
|
|
!!!next-token; |
6420 |
|
|
last S2; |
6421 |
|
|
} |
6422 |
wakaba |
1.79 |
|
6423 |
|
|
!!!cp ('t434'); |
6424 |
wakaba |
1.1 |
} |
6425 |
wakaba |
1.52 |
|
6426 |
|
|
## Step 4 |
6427 |
|
|
$node_i--; |
6428 |
|
|
$node = $self->{open_elements}->[$node_i]; |
6429 |
|
|
|
6430 |
|
|
## Step 5; |
6431 |
|
|
redo S2; |
6432 |
|
|
} # S2 |
6433 |
wakaba |
1.53 |
redo B; |
6434 |
wakaba |
1.1 |
} |
6435 |
|
|
} |
6436 |
wakaba |
1.52 |
redo B; |
6437 |
wakaba |
1.1 |
} # B |
6438 |
|
|
|
6439 |
|
|
## Stop parsing # MUST |
6440 |
|
|
|
6441 |
|
|
## TODO: script stuffs |
6442 |
wakaba |
1.3 |
} # _tree_construct_main |
6443 |
|
|
|
6444 |
|
|
sub set_inner_html ($$$) { |
6445 |
|
|
my $class = shift; |
6446 |
|
|
my $node = shift; |
6447 |
|
|
my $s = \$_[0]; |
6448 |
|
|
my $onerror = $_[1]; |
6449 |
|
|
|
6450 |
wakaba |
1.63 |
## ISSUE: Should {confident} be true? |
6451 |
|
|
|
6452 |
wakaba |
1.3 |
my $nt = $node->node_type; |
6453 |
|
|
if ($nt == 9) { |
6454 |
|
|
# MUST |
6455 |
|
|
|
6456 |
|
|
## Step 1 # MUST |
6457 |
|
|
## TODO: If the document has an active parser, ... |
6458 |
|
|
## ISSUE: There is an issue in the spec. |
6459 |
|
|
|
6460 |
|
|
## Step 2 # MUST |
6461 |
|
|
my @cn = @{$node->child_nodes}; |
6462 |
|
|
for (@cn) { |
6463 |
|
|
$node->remove_child ($_); |
6464 |
|
|
} |
6465 |
|
|
|
6466 |
|
|
## Step 3, 4, 5 # MUST |
6467 |
|
|
$class->parse_string ($$s => $node, $onerror); |
6468 |
|
|
} elsif ($nt == 1) { |
6469 |
|
|
## TODO: If non-html element |
6470 |
|
|
|
6471 |
|
|
## NOTE: Most of this code is copied from |parse_string| |
6472 |
|
|
|
6473 |
|
|
## Step 1 # MUST |
6474 |
wakaba |
1.14 |
my $this_doc = $node->owner_document; |
6475 |
|
|
my $doc = $this_doc->implementation->create_document; |
6476 |
wakaba |
1.18 |
$doc->manakai_is_html (1); |
6477 |
wakaba |
1.3 |
my $p = $class->new; |
6478 |
|
|
$p->{document} = $doc; |
6479 |
|
|
|
6480 |
wakaba |
1.84 |
## Step 8 # MUST |
6481 |
wakaba |
1.3 |
my $i = 0; |
6482 |
|
|
my $line = 1; |
6483 |
|
|
my $column = 0; |
6484 |
wakaba |
1.76 |
$p->{set_next_char} = sub { |
6485 |
wakaba |
1.3 |
my $self = shift; |
6486 |
wakaba |
1.14 |
|
6487 |
wakaba |
1.76 |
pop @{$self->{prev_char}}; |
6488 |
|
|
unshift @{$self->{prev_char}}, $self->{next_char}; |
6489 |
wakaba |
1.14 |
|
6490 |
wakaba |
1.76 |
$self->{next_char} = -1 and return if $i >= length $$s; |
6491 |
|
|
$self->{next_char} = ord substr $$s, $i++, 1; |
6492 |
wakaba |
1.3 |
$column++; |
6493 |
wakaba |
1.4 |
|
6494 |
wakaba |
1.76 |
if ($self->{next_char} == 0x000A) { # LF |
6495 |
wakaba |
1.4 |
$line++; |
6496 |
|
|
$column = 0; |
6497 |
wakaba |
1.79 |
!!!cp ('i1'); |
6498 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x000D) { # CR |
6499 |
wakaba |
1.15 |
$i++ if substr ($$s, $i, 1) eq "\x0A"; |
6500 |
wakaba |
1.76 |
$self->{next_char} = 0x000A; # LF # MUST |
6501 |
wakaba |
1.3 |
$line++; |
6502 |
wakaba |
1.4 |
$column = 0; |
6503 |
wakaba |
1.79 |
!!!cp ('i2'); |
6504 |
wakaba |
1.76 |
} elsif ($self->{next_char} > 0x10FFFF) { |
6505 |
|
|
$self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST |
6506 |
wakaba |
1.79 |
!!!cp ('i3'); |
6507 |
wakaba |
1.76 |
} elsif ($self->{next_char} == 0x0000) { # NULL |
6508 |
wakaba |
1.79 |
!!!cp ('i4'); |
6509 |
wakaba |
1.14 |
!!!parse-error (type => 'NULL'); |
6510 |
wakaba |
1.76 |
$self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST |
6511 |
wakaba |
1.3 |
} |
6512 |
|
|
}; |
6513 |
wakaba |
1.76 |
$p->{prev_char} = [-1, -1, -1]; |
6514 |
|
|
$p->{next_char} = -1; |
6515 |
wakaba |
1.3 |
|
6516 |
|
|
my $ponerror = $onerror || sub { |
6517 |
|
|
my (%opt) = @_; |
6518 |
|
|
warn "Parse error ($opt{type}) at line $opt{line} column $opt{column}\n"; |
6519 |
|
|
}; |
6520 |
|
|
$p->{parse_error} = sub { |
6521 |
|
|
$ponerror->(@_, line => $line, column => $column); |
6522 |
|
|
}; |
6523 |
|
|
|
6524 |
|
|
$p->_initialize_tokenizer; |
6525 |
|
|
$p->_initialize_tree_constructor; |
6526 |
|
|
|
6527 |
|
|
## Step 2 |
6528 |
wakaba |
1.71 |
my $node_ln = $node->manakai_local_name; |
6529 |
wakaba |
1.40 |
$p->{content_model} = { |
6530 |
|
|
title => RCDATA_CONTENT_MODEL, |
6531 |
|
|
textarea => RCDATA_CONTENT_MODEL, |
6532 |
|
|
style => CDATA_CONTENT_MODEL, |
6533 |
|
|
script => CDATA_CONTENT_MODEL, |
6534 |
|
|
xmp => CDATA_CONTENT_MODEL, |
6535 |
|
|
iframe => CDATA_CONTENT_MODEL, |
6536 |
|
|
noembed => CDATA_CONTENT_MODEL, |
6537 |
|
|
noframes => CDATA_CONTENT_MODEL, |
6538 |
|
|
noscript => CDATA_CONTENT_MODEL, |
6539 |
|
|
plaintext => PLAINTEXT_CONTENT_MODEL, |
6540 |
|
|
}->{$node_ln}; |
6541 |
|
|
$p->{content_model} = PCDATA_CONTENT_MODEL |
6542 |
|
|
unless defined $p->{content_model}; |
6543 |
|
|
## ISSUE: What is "the name of the element"? local name? |
6544 |
wakaba |
1.3 |
|
6545 |
|
|
$p->{inner_html_node} = [$node, $node_ln]; |
6546 |
|
|
|
6547 |
wakaba |
1.84 |
## Step 3 |
6548 |
wakaba |
1.3 |
my $root = $doc->create_element_ns |
6549 |
|
|
('http://www.w3.org/1999/xhtml', [undef, 'html']); |
6550 |
|
|
|
6551 |
wakaba |
1.84 |
## Step 4 # MUST |
6552 |
wakaba |
1.3 |
$doc->append_child ($root); |
6553 |
|
|
|
6554 |
wakaba |
1.84 |
## Step 5 # MUST |
6555 |
wakaba |
1.3 |
push @{$p->{open_elements}}, [$root, 'html']; |
6556 |
|
|
|
6557 |
|
|
undef $p->{head_element}; |
6558 |
|
|
|
6559 |
wakaba |
1.84 |
## Step 6 # MUST |
6560 |
wakaba |
1.3 |
$p->_reset_insertion_mode; |
6561 |
|
|
|
6562 |
wakaba |
1.84 |
## Step 7 # MUST |
6563 |
wakaba |
1.3 |
my $anode = $node; |
6564 |
|
|
AN: while (defined $anode) { |
6565 |
|
|
if ($anode->node_type == 1) { |
6566 |
|
|
my $nsuri = $anode->namespace_uri; |
6567 |
|
|
if (defined $nsuri and $nsuri eq 'http://www.w3.org/1999/xhtml') { |
6568 |
wakaba |
1.71 |
if ($anode->manakai_local_name eq 'form') { |
6569 |
wakaba |
1.79 |
!!!cp ('i5'); |
6570 |
wakaba |
1.3 |
$p->{form_element} = $anode; |
6571 |
|
|
last AN; |
6572 |
|
|
} |
6573 |
|
|
} |
6574 |
|
|
} |
6575 |
|
|
$anode = $anode->parent_node; |
6576 |
|
|
} # AN |
6577 |
|
|
|
6578 |
wakaba |
1.84 |
## Step 9 # MUST |
6579 |
wakaba |
1.3 |
{ |
6580 |
|
|
my $self = $p; |
6581 |
|
|
!!!next-token; |
6582 |
|
|
} |
6583 |
|
|
$p->_tree_construction_main; |
6584 |
|
|
|
6585 |
wakaba |
1.84 |
## Step 10 # MUST |
6586 |
wakaba |
1.3 |
my @cn = @{$node->child_nodes}; |
6587 |
|
|
for (@cn) { |
6588 |
|
|
$node->remove_child ($_); |
6589 |
|
|
} |
6590 |
|
|
## ISSUE: mutation events? read-only? |
6591 |
|
|
|
6592 |
wakaba |
1.84 |
## Step 11 # MUST |
6593 |
wakaba |
1.3 |
@cn = @{$root->child_nodes}; |
6594 |
|
|
for (@cn) { |
6595 |
wakaba |
1.14 |
$this_doc->adopt_node ($_); |
6596 |
wakaba |
1.3 |
$node->append_child ($_); |
6597 |
|
|
} |
6598 |
wakaba |
1.14 |
## ISSUE: mutation events? |
6599 |
wakaba |
1.3 |
|
6600 |
|
|
$p->_terminate_tree_constructor; |
6601 |
|
|
} else { |
6602 |
|
|
die "$0: |set_inner_html| is not defined for node of type $nt"; |
6603 |
|
|
} |
6604 |
|
|
} # set_inner_html |
6605 |
|
|
|
6606 |
|
|
} # tree construction stage |
6607 |
wakaba |
1.1 |
|
6608 |
wakaba |
1.63 |
package Whatpm::HTML::RestartParser; |
6609 |
|
|
push our @ISA, 'Error'; |
6610 |
|
|
|
6611 |
wakaba |
1.1 |
1; |
6612 |
wakaba |
1.115 |
# $Date: 2008/03/16 11:40:19 $ |