1 |
wakaba |
1.2 |
package Whatpm::HTML; |
2 |
wakaba |
1.1 |
use strict; |
3 |
wakaba |
1.73 |
our $VERSION=do{my @r=(q$Revision: 1.72 $=~/\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 |
|
|
button => 1, caption => 1, html => 1, marquee => 1, object => 1, |
78 |
|
|
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 |
|
|
## TODO: if $charset is supported |
112 |
|
|
## TODO: normalize charset name |
113 |
|
|
|
114 |
|
|
## "Change the encoding" algorithm: |
115 |
|
|
|
116 |
|
|
## Step 1 |
117 |
|
|
if ($charset eq 'utf-16') { ## ISSUE: UTF-16BE -> UTF-8? UTF-16LE -> UTF-8? |
118 |
|
|
$charset = 'utf-8'; |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
## Step 2 |
122 |
|
|
if (defined $self->{input_encoding} and |
123 |
|
|
$self->{input_encoding} eq $charset) { |
124 |
|
|
$self->{confident} = 1; |
125 |
|
|
return; |
126 |
|
|
} |
127 |
|
|
|
128 |
wakaba |
1.64 |
!!!parse-error (type => 'charset label detected:'.$self->{input_encoding}. |
129 |
|
|
':'.$charset, level => 'w'); |
130 |
wakaba |
1.63 |
|
131 |
|
|
## Step 3 |
132 |
|
|
# if (can) { |
133 |
|
|
## change the encoding on the fly. |
134 |
|
|
#$self->{confident} = 1; |
135 |
|
|
#return; |
136 |
|
|
# } |
137 |
|
|
|
138 |
|
|
## Step 4 |
139 |
|
|
throw Whatpm::HTML::RestartParser (charset => $charset); |
140 |
|
|
}; # $self->{change_encoding} |
141 |
|
|
|
142 |
|
|
my @args = @_; shift @args; # $s |
143 |
|
|
my $return; |
144 |
|
|
try { |
145 |
|
|
$return = $self->parse_char_string ($s, @args); |
146 |
|
|
} catch Whatpm::HTML::RestartParser with { |
147 |
|
|
my $charset = shift->{charset}; |
148 |
|
|
$s = \ (Encode::decode ($charset, $$bytes_s)); |
149 |
wakaba |
1.64 |
$self->{input_encoding} = $charset; ## TODO: normalize |
150 |
wakaba |
1.63 |
$self->{confident} = 1; |
151 |
|
|
$return = $self->parse_char_string ($s, @args); |
152 |
|
|
}; |
153 |
|
|
return $return; |
154 |
|
|
} # parse_byte_string |
155 |
|
|
|
156 |
wakaba |
1.71 |
## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM |
157 |
|
|
## and the HTML layer MUST ignore it. However, we does strip BOM in |
158 |
|
|
## the encoding layer and the HTML layer does not ignore any U+FEFF, |
159 |
|
|
## because the core part of our HTML parser expects a string of character, |
160 |
|
|
## not a string of bytes or code units or anything which might contain a BOM. |
161 |
|
|
## Therefore, any parser interface that accepts a string of bytes, |
162 |
|
|
## such as |parse_byte_string| in this module, must ensure that it does |
163 |
|
|
## strip the BOM and never strip any ZWNBSP. |
164 |
|
|
|
165 |
wakaba |
1.63 |
*parse_char_string = \&parse_string; |
166 |
|
|
|
167 |
wakaba |
1.1 |
sub parse_string ($$$;$) { |
168 |
wakaba |
1.63 |
my $self = ref $_[0] ? shift : shift->new; |
169 |
|
|
my $s = ref $_[0] ? $_[0] : \($_[0]); |
170 |
wakaba |
1.1 |
$self->{document} = $_[1]; |
171 |
wakaba |
1.63 |
@{$self->{document}->child_nodes} = (); |
172 |
wakaba |
1.1 |
|
173 |
wakaba |
1.3 |
## NOTE: |set_inner_html| copies most of this method's code |
174 |
|
|
|
175 |
wakaba |
1.63 |
$self->{confident} = 1 unless exists $self->{confident}; |
176 |
wakaba |
1.64 |
$self->{document}->input_encoding ($self->{input_encoding}) |
177 |
|
|
if defined $self->{input_encoding}; |
178 |
wakaba |
1.63 |
|
179 |
wakaba |
1.1 |
my $i = 0; |
180 |
wakaba |
1.3 |
my $line = 1; |
181 |
|
|
my $column = 0; |
182 |
wakaba |
1.1 |
$self->{set_next_input_character} = sub { |
183 |
|
|
my $self = shift; |
184 |
wakaba |
1.13 |
|
185 |
|
|
pop @{$self->{prev_input_character}}; |
186 |
|
|
unshift @{$self->{prev_input_character}}, $self->{next_input_character}; |
187 |
|
|
|
188 |
wakaba |
1.1 |
$self->{next_input_character} = -1 and return if $i >= length $$s; |
189 |
|
|
$self->{next_input_character} = ord substr $$s, $i++, 1; |
190 |
wakaba |
1.3 |
$column++; |
191 |
wakaba |
1.1 |
|
192 |
wakaba |
1.4 |
if ($self->{next_input_character} == 0x000A) { # LF |
193 |
|
|
$line++; |
194 |
|
|
$column = 0; |
195 |
|
|
} elsif ($self->{next_input_character} == 0x000D) { # CR |
196 |
wakaba |
1.15 |
$i++ if substr ($$s, $i, 1) eq "\x0A"; |
197 |
wakaba |
1.1 |
$self->{next_input_character} = 0x000A; # LF # MUST |
198 |
wakaba |
1.3 |
$line++; |
199 |
wakaba |
1.4 |
$column = 0; |
200 |
wakaba |
1.1 |
} elsif ($self->{next_input_character} > 0x10FFFF) { |
201 |
|
|
$self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST |
202 |
|
|
} elsif ($self->{next_input_character} == 0x0000) { # NULL |
203 |
wakaba |
1.8 |
!!!parse-error (type => 'NULL'); |
204 |
wakaba |
1.1 |
$self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST |
205 |
|
|
} |
206 |
|
|
}; |
207 |
wakaba |
1.13 |
$self->{prev_input_character} = [-1, -1, -1]; |
208 |
|
|
$self->{next_input_character} = -1; |
209 |
wakaba |
1.1 |
|
210 |
wakaba |
1.3 |
my $onerror = $_[2] || sub { |
211 |
|
|
my (%opt) = @_; |
212 |
|
|
warn "Parse error ($opt{type}) at line $opt{line} column $opt{column}\n"; |
213 |
|
|
}; |
214 |
|
|
$self->{parse_error} = sub { |
215 |
|
|
$onerror->(@_, line => $line, column => $column); |
216 |
wakaba |
1.1 |
}; |
217 |
|
|
|
218 |
|
|
$self->_initialize_tokenizer; |
219 |
|
|
$self->_initialize_tree_constructor; |
220 |
|
|
$self->_construct_tree; |
221 |
|
|
$self->_terminate_tree_constructor; |
222 |
|
|
|
223 |
|
|
return $self->{document}; |
224 |
|
|
} # parse_string |
225 |
|
|
|
226 |
|
|
sub new ($) { |
227 |
|
|
my $class = shift; |
228 |
|
|
my $self = bless {}, $class; |
229 |
|
|
$self->{set_next_input_character} = sub { |
230 |
|
|
$self->{next_input_character} = -1; |
231 |
|
|
}; |
232 |
|
|
$self->{parse_error} = sub { |
233 |
|
|
# |
234 |
|
|
}; |
235 |
wakaba |
1.63 |
$self->{change_encoding} = sub { |
236 |
|
|
# if ($_[0] is a supported encoding) { |
237 |
|
|
# run "change the encoding" algorithm; |
238 |
|
|
# throw Whatpm::HTML::RestartParser (charset => $new_encoding); |
239 |
|
|
# } |
240 |
|
|
}; |
241 |
wakaba |
1.61 |
$self->{application_cache_selection} = sub { |
242 |
|
|
# |
243 |
|
|
}; |
244 |
wakaba |
1.1 |
return $self; |
245 |
|
|
} # new |
246 |
|
|
|
247 |
wakaba |
1.40 |
sub CM_ENTITY () { 0b001 } # & markup in data |
248 |
|
|
sub CM_LIMITED_MARKUP () { 0b010 } # < markup in data (limited) |
249 |
|
|
sub CM_FULL_MARKUP () { 0b100 } # < markup in data (any) |
250 |
|
|
|
251 |
|
|
sub PLAINTEXT_CONTENT_MODEL () { 0 } |
252 |
|
|
sub CDATA_CONTENT_MODEL () { CM_LIMITED_MARKUP } |
253 |
|
|
sub RCDATA_CONTENT_MODEL () { CM_ENTITY | CM_LIMITED_MARKUP } |
254 |
|
|
sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP } |
255 |
|
|
|
256 |
wakaba |
1.57 |
sub DATA_STATE () { 0 } |
257 |
|
|
sub ENTITY_DATA_STATE () { 1 } |
258 |
|
|
sub TAG_OPEN_STATE () { 2 } |
259 |
|
|
sub CLOSE_TAG_OPEN_STATE () { 3 } |
260 |
|
|
sub TAG_NAME_STATE () { 4 } |
261 |
|
|
sub BEFORE_ATTRIBUTE_NAME_STATE () { 5 } |
262 |
|
|
sub ATTRIBUTE_NAME_STATE () { 6 } |
263 |
|
|
sub AFTER_ATTRIBUTE_NAME_STATE () { 7 } |
264 |
|
|
sub BEFORE_ATTRIBUTE_VALUE_STATE () { 8 } |
265 |
|
|
sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 } |
266 |
|
|
sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 } |
267 |
|
|
sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 } |
268 |
|
|
sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 } |
269 |
|
|
sub MARKUP_DECLARATION_OPEN_STATE () { 13 } |
270 |
|
|
sub COMMENT_START_STATE () { 14 } |
271 |
|
|
sub COMMENT_START_DASH_STATE () { 15 } |
272 |
|
|
sub COMMENT_STATE () { 16 } |
273 |
|
|
sub COMMENT_END_STATE () { 17 } |
274 |
|
|
sub COMMENT_END_DASH_STATE () { 18 } |
275 |
|
|
sub BOGUS_COMMENT_STATE () { 19 } |
276 |
|
|
sub DOCTYPE_STATE () { 20 } |
277 |
|
|
sub BEFORE_DOCTYPE_NAME_STATE () { 21 } |
278 |
|
|
sub DOCTYPE_NAME_STATE () { 22 } |
279 |
|
|
sub AFTER_DOCTYPE_NAME_STATE () { 23 } |
280 |
|
|
sub BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE () { 24 } |
281 |
|
|
sub DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE () { 25 } |
282 |
|
|
sub DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE () { 26 } |
283 |
|
|
sub AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE () { 27 } |
284 |
|
|
sub BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE () { 28 } |
285 |
|
|
sub DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE () { 29 } |
286 |
|
|
sub DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE () { 30 } |
287 |
|
|
sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE () { 31 } |
288 |
|
|
sub BOGUS_DOCTYPE_STATE () { 32 } |
289 |
wakaba |
1.72 |
sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 } |
290 |
wakaba |
1.57 |
|
291 |
wakaba |
1.55 |
sub DOCTYPE_TOKEN () { 1 } |
292 |
|
|
sub COMMENT_TOKEN () { 2 } |
293 |
|
|
sub START_TAG_TOKEN () { 3 } |
294 |
|
|
sub END_TAG_TOKEN () { 4 } |
295 |
|
|
sub END_OF_FILE_TOKEN () { 5 } |
296 |
|
|
sub CHARACTER_TOKEN () { 6 } |
297 |
|
|
|
298 |
wakaba |
1.54 |
sub AFTER_HTML_IMS () { 0b100 } |
299 |
|
|
sub HEAD_IMS () { 0b1000 } |
300 |
|
|
sub BODY_IMS () { 0b10000 } |
301 |
wakaba |
1.56 |
sub BODY_TABLE_IMS () { 0b100000 } |
302 |
wakaba |
1.54 |
sub TABLE_IMS () { 0b1000000 } |
303 |
wakaba |
1.56 |
sub ROW_IMS () { 0b10000000 } |
304 |
wakaba |
1.54 |
sub BODY_AFTER_IMS () { 0b100000000 } |
305 |
|
|
sub FRAME_IMS () { 0b1000000000 } |
306 |
|
|
|
307 |
|
|
sub AFTER_HTML_BODY_IM () { AFTER_HTML_IMS | BODY_AFTER_IMS } |
308 |
|
|
sub AFTER_HTML_FRAMESET_IM () { AFTER_HTML_IMS | FRAME_IMS } |
309 |
|
|
sub IN_HEAD_IM () { HEAD_IMS | 0b00 } |
310 |
|
|
sub IN_HEAD_NOSCRIPT_IM () { HEAD_IMS | 0b01 } |
311 |
|
|
sub AFTER_HEAD_IM () { HEAD_IMS | 0b10 } |
312 |
|
|
sub BEFORE_HEAD_IM () { HEAD_IMS | 0b11 } |
313 |
|
|
sub IN_BODY_IM () { BODY_IMS } |
314 |
wakaba |
1.56 |
sub IN_CELL_IM () { BODY_IMS | BODY_TABLE_IMS | 0b01 } |
315 |
|
|
sub IN_CAPTION_IM () { BODY_IMS | BODY_TABLE_IMS | 0b10 } |
316 |
|
|
sub IN_ROW_IM () { TABLE_IMS | ROW_IMS | 0b01 } |
317 |
|
|
sub IN_TABLE_BODY_IM () { TABLE_IMS | ROW_IMS | 0b10 } |
318 |
wakaba |
1.54 |
sub IN_TABLE_IM () { TABLE_IMS } |
319 |
|
|
sub AFTER_BODY_IM () { BODY_AFTER_IMS } |
320 |
|
|
sub IN_FRAMESET_IM () { FRAME_IMS | 0b01 } |
321 |
|
|
sub AFTER_FRAMESET_IM () { FRAME_IMS | 0b10 } |
322 |
|
|
sub IN_SELECT_IM () { 0b01 } |
323 |
|
|
sub IN_COLUMN_GROUP_IM () { 0b10 } |
324 |
|
|
|
325 |
wakaba |
1.1 |
## Implementations MUST act as if state machine in the spec |
326 |
|
|
|
327 |
|
|
sub _initialize_tokenizer ($) { |
328 |
|
|
my $self = shift; |
329 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; # MUST |
330 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # be |
331 |
wakaba |
1.1 |
undef $self->{current_token}; # start tag, end tag, comment, or DOCTYPE |
332 |
|
|
undef $self->{current_attribute}; |
333 |
|
|
undef $self->{last_emitted_start_tag_name}; |
334 |
|
|
undef $self->{last_attribute_value_state}; |
335 |
|
|
$self->{char} = []; |
336 |
|
|
# $self->{next_input_character} |
337 |
|
|
!!!next-input-character; |
338 |
|
|
$self->{token} = []; |
339 |
wakaba |
1.18 |
# $self->{escape} |
340 |
wakaba |
1.1 |
} # _initialize_tokenizer |
341 |
|
|
|
342 |
|
|
## A token has: |
343 |
wakaba |
1.55 |
## ->{type} == DOCTYPE_TOKEN, START_TAG_TOKEN, END_TAG_TOKEN, COMMENT_TOKEN, |
344 |
|
|
## CHARACTER_TOKEN, or END_OF_FILE_TOKEN |
345 |
|
|
## ->{name} (DOCTYPE_TOKEN) |
346 |
|
|
## ->{tag_name} (START_TAG_TOKEN, END_TAG_TOKEN) |
347 |
|
|
## ->{public_identifier} (DOCTYPE_TOKEN) |
348 |
|
|
## ->{system_identifier} (DOCTYPE_TOKEN) |
349 |
|
|
## ->{correct} == 1 or 0 (DOCTYPE_TOKEN) |
350 |
|
|
## ->{attributes} isa HASH (START_TAG_TOKEN, END_TAG_TOKEN) |
351 |
wakaba |
1.66 |
## ->{name} |
352 |
|
|
## ->{value} |
353 |
|
|
## ->{has_reference} == 1 or 0 |
354 |
wakaba |
1.55 |
## ->{data} (COMMENT_TOKEN, CHARACTER_TOKEN) |
355 |
wakaba |
1.1 |
|
356 |
|
|
## Emitted token MUST immediately be handled by the tree construction state. |
357 |
|
|
|
358 |
|
|
## Before each step, UA MAY check to see if either one of the scripts in |
359 |
|
|
## "list of scripts that will execute as soon as possible" or the first |
360 |
|
|
## script in the "list of scripts that will execute asynchronously", |
361 |
|
|
## has completed loading. If one has, then it MUST be executed |
362 |
|
|
## and removed from the list. |
363 |
|
|
|
364 |
wakaba |
1.59 |
## NOTE: HTML5 "Writing HTML documents" section, applied to |
365 |
|
|
## documents and not to user agents and conformance checkers, |
366 |
|
|
## contains some requirements that are not detected by the |
367 |
|
|
## parsing algorithm: |
368 |
|
|
## - Some requirements on character encoding declarations. ## TODO |
369 |
|
|
## - "Elements MUST NOT contain content that their content model disallows." |
370 |
|
|
## ... Some are parse error, some are not (will be reported by c.c.). |
371 |
|
|
## - Polytheistic slash SHOULD NOT be used. (Applied only to atheists.) ## TODO |
372 |
|
|
## - Text (in elements, attributes, and comments) SHOULD NOT contain |
373 |
|
|
## control characters other than space characters. ## TODO: (what is control character? C0, C1 and DEL? Unicode control character?) |
374 |
|
|
|
375 |
|
|
## TODO: HTML5 poses authors two SHOULD-level requirements that cannot |
376 |
|
|
## be detected by the HTML5 parsing algorithm: |
377 |
|
|
## - Text, |
378 |
|
|
|
379 |
wakaba |
1.1 |
sub _get_next_token ($) { |
380 |
|
|
my $self = shift; |
381 |
|
|
if (@{$self->{token}}) { |
382 |
|
|
return shift @{$self->{token}}; |
383 |
|
|
} |
384 |
|
|
|
385 |
|
|
A: { |
386 |
wakaba |
1.57 |
if ($self->{state} == DATA_STATE) { |
387 |
wakaba |
1.1 |
if ($self->{next_input_character} == 0x0026) { # & |
388 |
wakaba |
1.72 |
if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA |
389 |
|
|
not $self->{escape}) { |
390 |
wakaba |
1.57 |
$self->{state} = ENTITY_DATA_STATE; |
391 |
wakaba |
1.1 |
!!!next-input-character; |
392 |
|
|
redo A; |
393 |
|
|
} else { |
394 |
|
|
# |
395 |
|
|
} |
396 |
wakaba |
1.13 |
} elsif ($self->{next_input_character} == 0x002D) { # - |
397 |
wakaba |
1.40 |
if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA |
398 |
wakaba |
1.13 |
unless ($self->{escape}) { |
399 |
|
|
if ($self->{prev_input_character}->[0] == 0x002D and # - |
400 |
|
|
$self->{prev_input_character}->[1] == 0x0021 and # ! |
401 |
|
|
$self->{prev_input_character}->[2] == 0x003C) { # < |
402 |
|
|
$self->{escape} = 1; |
403 |
|
|
} |
404 |
|
|
} |
405 |
|
|
} |
406 |
|
|
|
407 |
|
|
# |
408 |
wakaba |
1.1 |
} elsif ($self->{next_input_character} == 0x003C) { # < |
409 |
wakaba |
1.40 |
if ($self->{content_model} & CM_FULL_MARKUP or # PCDATA |
410 |
|
|
(($self->{content_model} & CM_LIMITED_MARKUP) and # CDATA | RCDATA |
411 |
wakaba |
1.13 |
not $self->{escape})) { |
412 |
wakaba |
1.57 |
$self->{state} = TAG_OPEN_STATE; |
413 |
wakaba |
1.1 |
!!!next-input-character; |
414 |
|
|
redo A; |
415 |
|
|
} else { |
416 |
|
|
# |
417 |
|
|
} |
418 |
wakaba |
1.13 |
} elsif ($self->{next_input_character} == 0x003E) { # > |
419 |
|
|
if ($self->{escape} and |
420 |
wakaba |
1.40 |
($self->{content_model} & CM_LIMITED_MARKUP)) { # RCDATA | CDATA |
421 |
wakaba |
1.13 |
if ($self->{prev_input_character}->[0] == 0x002D and # - |
422 |
|
|
$self->{prev_input_character}->[1] == 0x002D) { # - |
423 |
|
|
delete $self->{escape}; |
424 |
|
|
} |
425 |
|
|
} |
426 |
|
|
|
427 |
|
|
# |
428 |
wakaba |
1.1 |
} elsif ($self->{next_input_character} == -1) { |
429 |
wakaba |
1.55 |
!!!emit ({type => END_OF_FILE_TOKEN}); |
430 |
wakaba |
1.1 |
last A; ## TODO: ok? |
431 |
|
|
} |
432 |
|
|
# Anything else |
433 |
wakaba |
1.55 |
my $token = {type => CHARACTER_TOKEN, |
434 |
wakaba |
1.1 |
data => chr $self->{next_input_character}}; |
435 |
|
|
## Stay in the data state |
436 |
|
|
!!!next-input-character; |
437 |
|
|
|
438 |
|
|
!!!emit ($token); |
439 |
|
|
|
440 |
|
|
redo A; |
441 |
wakaba |
1.57 |
} elsif ($self->{state} == ENTITY_DATA_STATE) { |
442 |
wakaba |
1.1 |
## (cannot happen in CDATA state) |
443 |
|
|
|
444 |
wakaba |
1.72 |
my $token = $self->_tokenize_attempt_to_consume_an_entity (0, -1); |
445 |
wakaba |
1.1 |
|
446 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
447 |
wakaba |
1.1 |
# next-input-character is already done |
448 |
|
|
|
449 |
|
|
unless (defined $token) { |
450 |
wakaba |
1.55 |
!!!emit ({type => CHARACTER_TOKEN, data => '&'}); |
451 |
wakaba |
1.1 |
} else { |
452 |
|
|
!!!emit ($token); |
453 |
|
|
} |
454 |
|
|
|
455 |
|
|
redo A; |
456 |
wakaba |
1.57 |
} elsif ($self->{state} == TAG_OPEN_STATE) { |
457 |
wakaba |
1.40 |
if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA |
458 |
wakaba |
1.1 |
if ($self->{next_input_character} == 0x002F) { # / |
459 |
|
|
!!!next-input-character; |
460 |
wakaba |
1.57 |
$self->{state} = CLOSE_TAG_OPEN_STATE; |
461 |
wakaba |
1.1 |
redo A; |
462 |
|
|
} else { |
463 |
|
|
## reconsume |
464 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
465 |
wakaba |
1.1 |
|
466 |
wakaba |
1.55 |
!!!emit ({type => CHARACTER_TOKEN, data => '<'}); |
467 |
wakaba |
1.1 |
|
468 |
|
|
redo A; |
469 |
|
|
} |
470 |
wakaba |
1.40 |
} elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA |
471 |
wakaba |
1.1 |
if ($self->{next_input_character} == 0x0021) { # ! |
472 |
wakaba |
1.57 |
$self->{state} = MARKUP_DECLARATION_OPEN_STATE; |
473 |
wakaba |
1.1 |
!!!next-input-character; |
474 |
|
|
redo A; |
475 |
|
|
} elsif ($self->{next_input_character} == 0x002F) { # / |
476 |
wakaba |
1.57 |
$self->{state} = CLOSE_TAG_OPEN_STATE; |
477 |
wakaba |
1.1 |
!!!next-input-character; |
478 |
|
|
redo A; |
479 |
|
|
} elsif (0x0041 <= $self->{next_input_character} and |
480 |
|
|
$self->{next_input_character} <= 0x005A) { # A..Z |
481 |
|
|
$self->{current_token} |
482 |
wakaba |
1.55 |
= {type => START_TAG_TOKEN, |
483 |
wakaba |
1.1 |
tag_name => chr ($self->{next_input_character} + 0x0020)}; |
484 |
wakaba |
1.57 |
$self->{state} = TAG_NAME_STATE; |
485 |
wakaba |
1.1 |
!!!next-input-character; |
486 |
|
|
redo A; |
487 |
|
|
} elsif (0x0061 <= $self->{next_input_character} and |
488 |
|
|
$self->{next_input_character} <= 0x007A) { # a..z |
489 |
wakaba |
1.55 |
$self->{current_token} = {type => START_TAG_TOKEN, |
490 |
wakaba |
1.1 |
tag_name => chr ($self->{next_input_character})}; |
491 |
wakaba |
1.57 |
$self->{state} = TAG_NAME_STATE; |
492 |
wakaba |
1.1 |
!!!next-input-character; |
493 |
|
|
redo A; |
494 |
|
|
} elsif ($self->{next_input_character} == 0x003E) { # > |
495 |
wakaba |
1.3 |
!!!parse-error (type => 'empty start tag'); |
496 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
497 |
wakaba |
1.1 |
!!!next-input-character; |
498 |
|
|
|
499 |
wakaba |
1.55 |
!!!emit ({type => CHARACTER_TOKEN, data => '<>'}); |
500 |
wakaba |
1.1 |
|
501 |
|
|
redo A; |
502 |
|
|
} elsif ($self->{next_input_character} == 0x003F) { # ? |
503 |
wakaba |
1.3 |
!!!parse-error (type => 'pio'); |
504 |
wakaba |
1.57 |
$self->{state} = BOGUS_COMMENT_STATE; |
505 |
wakaba |
1.1 |
## $self->{next_input_character} is intentionally left as is |
506 |
|
|
redo A; |
507 |
|
|
} else { |
508 |
wakaba |
1.3 |
!!!parse-error (type => 'bare stago'); |
509 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
510 |
wakaba |
1.1 |
## reconsume |
511 |
|
|
|
512 |
wakaba |
1.55 |
!!!emit ({type => CHARACTER_TOKEN, data => '<'}); |
513 |
wakaba |
1.1 |
|
514 |
|
|
redo A; |
515 |
|
|
} |
516 |
|
|
} else { |
517 |
wakaba |
1.40 |
die "$0: $self->{content_model} in tag open"; |
518 |
wakaba |
1.1 |
} |
519 |
wakaba |
1.57 |
} elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) { |
520 |
wakaba |
1.40 |
if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA |
521 |
wakaba |
1.23 |
if (defined $self->{last_emitted_start_tag_name}) { |
522 |
wakaba |
1.30 |
## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564> |
523 |
wakaba |
1.23 |
my @next_char; |
524 |
|
|
TAGNAME: for (my $i = 0; $i < length $self->{last_emitted_start_tag_name}; $i++) { |
525 |
|
|
push @next_char, $self->{next_input_character}; |
526 |
|
|
my $c = ord substr ($self->{last_emitted_start_tag_name}, $i, 1); |
527 |
|
|
my $C = 0x0061 <= $c && $c <= 0x007A ? $c - 0x0020 : $c; |
528 |
|
|
if ($self->{next_input_character} == $c or $self->{next_input_character} == $C) { |
529 |
|
|
!!!next-input-character; |
530 |
|
|
next TAGNAME; |
531 |
|
|
} else { |
532 |
|
|
$self->{next_input_character} = shift @next_char; # reconsume |
533 |
|
|
!!!back-next-input-character (@next_char); |
534 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
535 |
wakaba |
1.23 |
|
536 |
wakaba |
1.55 |
!!!emit ({type => CHARACTER_TOKEN, data => '</'}); |
537 |
wakaba |
1.23 |
|
538 |
|
|
redo A; |
539 |
|
|
} |
540 |
|
|
} |
541 |
wakaba |
1.1 |
push @next_char, $self->{next_input_character}; |
542 |
wakaba |
1.23 |
|
543 |
|
|
unless ($self->{next_input_character} == 0x0009 or # HT |
544 |
|
|
$self->{next_input_character} == 0x000A or # LF |
545 |
|
|
$self->{next_input_character} == 0x000B or # VT |
546 |
|
|
$self->{next_input_character} == 0x000C or # FF |
547 |
|
|
$self->{next_input_character} == 0x0020 or # SP |
548 |
|
|
$self->{next_input_character} == 0x003E or # > |
549 |
|
|
$self->{next_input_character} == 0x002F or # / |
550 |
|
|
$self->{next_input_character} == -1) { |
551 |
wakaba |
1.1 |
$self->{next_input_character} = shift @next_char; # reconsume |
552 |
|
|
!!!back-next-input-character (@next_char); |
553 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
554 |
wakaba |
1.55 |
!!!emit ({type => CHARACTER_TOKEN, data => '</'}); |
555 |
wakaba |
1.1 |
redo A; |
556 |
wakaba |
1.23 |
} else { |
557 |
|
|
$self->{next_input_character} = shift @next_char; |
558 |
|
|
!!!back-next-input-character (@next_char); |
559 |
|
|
# and consume... |
560 |
wakaba |
1.1 |
} |
561 |
wakaba |
1.23 |
} else { |
562 |
|
|
## No start tag token has ever been emitted |
563 |
|
|
# next-input-character is already done |
564 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
565 |
wakaba |
1.55 |
!!!emit ({type => CHARACTER_TOKEN, data => '</'}); |
566 |
wakaba |
1.1 |
redo A; |
567 |
|
|
} |
568 |
|
|
} |
569 |
|
|
|
570 |
|
|
if (0x0041 <= $self->{next_input_character} and |
571 |
|
|
$self->{next_input_character} <= 0x005A) { # A..Z |
572 |
wakaba |
1.55 |
$self->{current_token} = {type => END_TAG_TOKEN, |
573 |
wakaba |
1.1 |
tag_name => chr ($self->{next_input_character} + 0x0020)}; |
574 |
wakaba |
1.57 |
$self->{state} = TAG_NAME_STATE; |
575 |
wakaba |
1.1 |
!!!next-input-character; |
576 |
|
|
redo A; |
577 |
|
|
} elsif (0x0061 <= $self->{next_input_character} and |
578 |
|
|
$self->{next_input_character} <= 0x007A) { # a..z |
579 |
wakaba |
1.55 |
$self->{current_token} = {type => END_TAG_TOKEN, |
580 |
wakaba |
1.1 |
tag_name => chr ($self->{next_input_character})}; |
581 |
wakaba |
1.57 |
$self->{state} = TAG_NAME_STATE; |
582 |
wakaba |
1.1 |
!!!next-input-character; |
583 |
|
|
redo A; |
584 |
|
|
} elsif ($self->{next_input_character} == 0x003E) { # > |
585 |
wakaba |
1.3 |
!!!parse-error (type => 'empty end tag'); |
586 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
587 |
wakaba |
1.1 |
!!!next-input-character; |
588 |
|
|
redo A; |
589 |
|
|
} elsif ($self->{next_input_character} == -1) { |
590 |
wakaba |
1.3 |
!!!parse-error (type => 'bare etago'); |
591 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
592 |
wakaba |
1.1 |
# reconsume |
593 |
|
|
|
594 |
wakaba |
1.55 |
!!!emit ({type => CHARACTER_TOKEN, data => '</'}); |
595 |
wakaba |
1.1 |
|
596 |
|
|
redo A; |
597 |
|
|
} else { |
598 |
wakaba |
1.3 |
!!!parse-error (type => 'bogus end tag'); |
599 |
wakaba |
1.57 |
$self->{state} = BOGUS_COMMENT_STATE; |
600 |
wakaba |
1.1 |
## $self->{next_input_character} is intentionally left as is |
601 |
|
|
redo A; |
602 |
|
|
} |
603 |
wakaba |
1.57 |
} elsif ($self->{state} == TAG_NAME_STATE) { |
604 |
wakaba |
1.1 |
if ($self->{next_input_character} == 0x0009 or # HT |
605 |
|
|
$self->{next_input_character} == 0x000A or # LF |
606 |
|
|
$self->{next_input_character} == 0x000B or # VT |
607 |
|
|
$self->{next_input_character} == 0x000C or # FF |
608 |
|
|
$self->{next_input_character} == 0x0020) { # SP |
609 |
wakaba |
1.57 |
$self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
610 |
wakaba |
1.1 |
!!!next-input-character; |
611 |
|
|
redo A; |
612 |
|
|
} elsif ($self->{next_input_character} == 0x003E) { # > |
613 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
614 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
615 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
616 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
617 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
618 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
619 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
620 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
621 |
wakaba |
1.1 |
} |
622 |
|
|
} else { |
623 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
624 |
|
|
} |
625 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
626 |
wakaba |
1.1 |
!!!next-input-character; |
627 |
|
|
|
628 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
629 |
|
|
|
630 |
|
|
redo A; |
631 |
|
|
} elsif (0x0041 <= $self->{next_input_character} and |
632 |
|
|
$self->{next_input_character} <= 0x005A) { # A..Z |
633 |
|
|
$self->{current_token}->{tag_name} .= chr ($self->{next_input_character} + 0x0020); |
634 |
|
|
# start tag or end tag |
635 |
|
|
## Stay in this state |
636 |
|
|
!!!next-input-character; |
637 |
|
|
redo A; |
638 |
wakaba |
1.17 |
} elsif ($self->{next_input_character} == -1) { |
639 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed tag'); |
640 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
641 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
642 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
643 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
644 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
645 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
646 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
647 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
648 |
wakaba |
1.1 |
} |
649 |
|
|
} else { |
650 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
651 |
|
|
} |
652 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
653 |
wakaba |
1.1 |
# reconsume |
654 |
|
|
|
655 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
656 |
|
|
|
657 |
|
|
redo A; |
658 |
|
|
} elsif ($self->{next_input_character} == 0x002F) { # / |
659 |
|
|
!!!next-input-character; |
660 |
|
|
if ($self->{next_input_character} == 0x003E and # > |
661 |
wakaba |
1.55 |
$self->{current_token}->{type} == START_TAG_TOKEN and |
662 |
wakaba |
1.1 |
$permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) { |
663 |
|
|
# permitted slash |
664 |
|
|
# |
665 |
|
|
} else { |
666 |
wakaba |
1.3 |
!!!parse-error (type => 'nestc'); |
667 |
wakaba |
1.1 |
} |
668 |
wakaba |
1.57 |
$self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
669 |
wakaba |
1.1 |
# next-input-character is already done |
670 |
|
|
redo A; |
671 |
|
|
} else { |
672 |
|
|
$self->{current_token}->{tag_name} .= chr $self->{next_input_character}; |
673 |
|
|
# start tag or end tag |
674 |
|
|
## Stay in the state |
675 |
|
|
!!!next-input-character; |
676 |
|
|
redo A; |
677 |
|
|
} |
678 |
wakaba |
1.57 |
} elsif ($self->{state} == BEFORE_ATTRIBUTE_NAME_STATE) { |
679 |
wakaba |
1.1 |
if ($self->{next_input_character} == 0x0009 or # HT |
680 |
|
|
$self->{next_input_character} == 0x000A or # LF |
681 |
|
|
$self->{next_input_character} == 0x000B or # VT |
682 |
|
|
$self->{next_input_character} == 0x000C or # FF |
683 |
|
|
$self->{next_input_character} == 0x0020) { # SP |
684 |
|
|
## Stay in the state |
685 |
|
|
!!!next-input-character; |
686 |
|
|
redo A; |
687 |
|
|
} elsif ($self->{next_input_character} == 0x003E) { # > |
688 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
689 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
690 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
691 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
692 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
693 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
694 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
695 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
696 |
wakaba |
1.1 |
} |
697 |
|
|
} else { |
698 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
699 |
|
|
} |
700 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
701 |
wakaba |
1.1 |
!!!next-input-character; |
702 |
|
|
|
703 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
704 |
|
|
|
705 |
|
|
redo A; |
706 |
|
|
} elsif (0x0041 <= $self->{next_input_character} and |
707 |
|
|
$self->{next_input_character} <= 0x005A) { # A..Z |
708 |
|
|
$self->{current_attribute} = {name => chr ($self->{next_input_character} + 0x0020), |
709 |
|
|
value => ''}; |
710 |
wakaba |
1.57 |
$self->{state} = ATTRIBUTE_NAME_STATE; |
711 |
wakaba |
1.1 |
!!!next-input-character; |
712 |
|
|
redo A; |
713 |
|
|
} elsif ($self->{next_input_character} == 0x002F) { # / |
714 |
|
|
!!!next-input-character; |
715 |
|
|
if ($self->{next_input_character} == 0x003E and # > |
716 |
wakaba |
1.55 |
$self->{current_token}->{type} == START_TAG_TOKEN and |
717 |
wakaba |
1.1 |
$permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) { |
718 |
|
|
# permitted slash |
719 |
|
|
# |
720 |
|
|
} else { |
721 |
wakaba |
1.3 |
!!!parse-error (type => 'nestc'); |
722 |
wakaba |
1.1 |
} |
723 |
|
|
## Stay in the state |
724 |
|
|
# next-input-character is already done |
725 |
|
|
redo A; |
726 |
wakaba |
1.17 |
} elsif ($self->{next_input_character} == -1) { |
727 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed tag'); |
728 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
729 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
730 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
731 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
732 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
733 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
734 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
735 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
736 |
wakaba |
1.1 |
} |
737 |
|
|
} else { |
738 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
739 |
|
|
} |
740 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
741 |
wakaba |
1.1 |
# reconsume |
742 |
|
|
|
743 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
744 |
|
|
|
745 |
|
|
redo A; |
746 |
|
|
} else { |
747 |
wakaba |
1.72 |
if ({ |
748 |
|
|
0x0022 => 1, # " |
749 |
|
|
0x0027 => 1, # ' |
750 |
|
|
0x003D => 1, # = |
751 |
|
|
}->{$self->{next_input_character}}) { |
752 |
|
|
!!!parse-error (type => 'bad attribute name'); |
753 |
|
|
} |
754 |
wakaba |
1.1 |
$self->{current_attribute} = {name => chr ($self->{next_input_character}), |
755 |
|
|
value => ''}; |
756 |
wakaba |
1.57 |
$self->{state} = ATTRIBUTE_NAME_STATE; |
757 |
wakaba |
1.1 |
!!!next-input-character; |
758 |
|
|
redo A; |
759 |
|
|
} |
760 |
wakaba |
1.57 |
} elsif ($self->{state} == ATTRIBUTE_NAME_STATE) { |
761 |
wakaba |
1.1 |
my $before_leave = sub { |
762 |
|
|
if (exists $self->{current_token}->{attributes} # start tag or end tag |
763 |
|
|
->{$self->{current_attribute}->{name}}) { # MUST |
764 |
wakaba |
1.39 |
!!!parse-error (type => 'duplicate attribute:'.$self->{current_attribute}->{name}); |
765 |
wakaba |
1.1 |
## Discard $self->{current_attribute} # MUST |
766 |
|
|
} else { |
767 |
|
|
$self->{current_token}->{attributes}->{$self->{current_attribute}->{name}} |
768 |
|
|
= $self->{current_attribute}; |
769 |
|
|
} |
770 |
|
|
}; # $before_leave |
771 |
|
|
|
772 |
|
|
if ($self->{next_input_character} == 0x0009 or # HT |
773 |
|
|
$self->{next_input_character} == 0x000A or # LF |
774 |
|
|
$self->{next_input_character} == 0x000B or # VT |
775 |
|
|
$self->{next_input_character} == 0x000C or # FF |
776 |
|
|
$self->{next_input_character} == 0x0020) { # SP |
777 |
|
|
$before_leave->(); |
778 |
wakaba |
1.57 |
$self->{state} = AFTER_ATTRIBUTE_NAME_STATE; |
779 |
wakaba |
1.1 |
!!!next-input-character; |
780 |
|
|
redo A; |
781 |
|
|
} elsif ($self->{next_input_character} == 0x003D) { # = |
782 |
|
|
$before_leave->(); |
783 |
wakaba |
1.57 |
$self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE; |
784 |
wakaba |
1.1 |
!!!next-input-character; |
785 |
|
|
redo A; |
786 |
|
|
} elsif ($self->{next_input_character} == 0x003E) { # > |
787 |
|
|
$before_leave->(); |
788 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
789 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
790 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
791 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
792 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
793 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
794 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
795 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
796 |
wakaba |
1.1 |
} |
797 |
|
|
} else { |
798 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
799 |
|
|
} |
800 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
801 |
wakaba |
1.1 |
!!!next-input-character; |
802 |
|
|
|
803 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
804 |
|
|
|
805 |
|
|
redo A; |
806 |
|
|
} elsif (0x0041 <= $self->{next_input_character} and |
807 |
|
|
$self->{next_input_character} <= 0x005A) { # A..Z |
808 |
|
|
$self->{current_attribute}->{name} .= chr ($self->{next_input_character} + 0x0020); |
809 |
|
|
## Stay in the state |
810 |
|
|
!!!next-input-character; |
811 |
|
|
redo A; |
812 |
|
|
} elsif ($self->{next_input_character} == 0x002F) { # / |
813 |
|
|
$before_leave->(); |
814 |
|
|
!!!next-input-character; |
815 |
|
|
if ($self->{next_input_character} == 0x003E and # > |
816 |
wakaba |
1.55 |
$self->{current_token}->{type} == START_TAG_TOKEN and |
817 |
wakaba |
1.1 |
$permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) { |
818 |
|
|
# permitted slash |
819 |
|
|
# |
820 |
|
|
} else { |
821 |
wakaba |
1.3 |
!!!parse-error (type => 'nestc'); |
822 |
wakaba |
1.1 |
} |
823 |
wakaba |
1.57 |
$self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
824 |
wakaba |
1.1 |
# next-input-character is already done |
825 |
|
|
redo A; |
826 |
wakaba |
1.17 |
} elsif ($self->{next_input_character} == -1) { |
827 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed tag'); |
828 |
wakaba |
1.1 |
$before_leave->(); |
829 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
830 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
831 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
832 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
833 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
834 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
835 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
836 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
837 |
wakaba |
1.1 |
} |
838 |
|
|
} else { |
839 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
840 |
|
|
} |
841 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
842 |
wakaba |
1.1 |
# reconsume |
843 |
|
|
|
844 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
845 |
|
|
|
846 |
|
|
redo A; |
847 |
|
|
} else { |
848 |
wakaba |
1.72 |
if ($self->{next_input_character} == 0x0022 or # " |
849 |
|
|
$self->{next_input_character} == 0x0027) { # ' |
850 |
|
|
!!!parse-error (type => 'bad attribute name'); |
851 |
|
|
} |
852 |
wakaba |
1.1 |
$self->{current_attribute}->{name} .= chr ($self->{next_input_character}); |
853 |
|
|
## Stay in the state |
854 |
|
|
!!!next-input-character; |
855 |
|
|
redo A; |
856 |
|
|
} |
857 |
wakaba |
1.57 |
} elsif ($self->{state} == AFTER_ATTRIBUTE_NAME_STATE) { |
858 |
wakaba |
1.1 |
if ($self->{next_input_character} == 0x0009 or # HT |
859 |
|
|
$self->{next_input_character} == 0x000A or # LF |
860 |
|
|
$self->{next_input_character} == 0x000B or # VT |
861 |
|
|
$self->{next_input_character} == 0x000C or # FF |
862 |
|
|
$self->{next_input_character} == 0x0020) { # SP |
863 |
|
|
## Stay in the state |
864 |
|
|
!!!next-input-character; |
865 |
|
|
redo A; |
866 |
|
|
} elsif ($self->{next_input_character} == 0x003D) { # = |
867 |
wakaba |
1.57 |
$self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE; |
868 |
wakaba |
1.1 |
!!!next-input-character; |
869 |
|
|
redo A; |
870 |
|
|
} elsif ($self->{next_input_character} == 0x003E) { # > |
871 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
872 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
873 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
874 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
875 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
876 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
877 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
878 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
879 |
wakaba |
1.1 |
} |
880 |
|
|
} else { |
881 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
882 |
|
|
} |
883 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
884 |
wakaba |
1.1 |
!!!next-input-character; |
885 |
|
|
|
886 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
887 |
|
|
|
888 |
|
|
redo A; |
889 |
|
|
} elsif (0x0041 <= $self->{next_input_character} and |
890 |
|
|
$self->{next_input_character} <= 0x005A) { # A..Z |
891 |
|
|
$self->{current_attribute} = {name => chr ($self->{next_input_character} + 0x0020), |
892 |
|
|
value => ''}; |
893 |
wakaba |
1.57 |
$self->{state} = ATTRIBUTE_NAME_STATE; |
894 |
wakaba |
1.1 |
!!!next-input-character; |
895 |
|
|
redo A; |
896 |
|
|
} elsif ($self->{next_input_character} == 0x002F) { # / |
897 |
|
|
!!!next-input-character; |
898 |
|
|
if ($self->{next_input_character} == 0x003E and # > |
899 |
wakaba |
1.55 |
$self->{current_token}->{type} == START_TAG_TOKEN and |
900 |
wakaba |
1.1 |
$permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) { |
901 |
|
|
# permitted slash |
902 |
|
|
# |
903 |
|
|
} else { |
904 |
wakaba |
1.3 |
!!!parse-error (type => 'nestc'); |
905 |
wakaba |
1.33 |
## TODO: Different error type for <aa / bb> than <aa/> |
906 |
wakaba |
1.1 |
} |
907 |
wakaba |
1.57 |
$self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
908 |
wakaba |
1.1 |
# next-input-character is already done |
909 |
|
|
redo A; |
910 |
wakaba |
1.17 |
} elsif ($self->{next_input_character} == -1) { |
911 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed tag'); |
912 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
913 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
914 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
915 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
916 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
917 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
918 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
919 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
920 |
wakaba |
1.1 |
} |
921 |
|
|
} else { |
922 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
923 |
|
|
} |
924 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
925 |
wakaba |
1.1 |
# reconsume |
926 |
|
|
|
927 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
928 |
|
|
|
929 |
|
|
redo A; |
930 |
|
|
} else { |
931 |
|
|
$self->{current_attribute} = {name => chr ($self->{next_input_character}), |
932 |
|
|
value => ''}; |
933 |
wakaba |
1.57 |
$self->{state} = ATTRIBUTE_NAME_STATE; |
934 |
wakaba |
1.1 |
!!!next-input-character; |
935 |
|
|
redo A; |
936 |
|
|
} |
937 |
wakaba |
1.57 |
} elsif ($self->{state} == BEFORE_ATTRIBUTE_VALUE_STATE) { |
938 |
wakaba |
1.1 |
if ($self->{next_input_character} == 0x0009 or # HT |
939 |
|
|
$self->{next_input_character} == 0x000A or # LF |
940 |
|
|
$self->{next_input_character} == 0x000B or # VT |
941 |
|
|
$self->{next_input_character} == 0x000C or # FF |
942 |
|
|
$self->{next_input_character} == 0x0020) { # SP |
943 |
|
|
## Stay in the state |
944 |
|
|
!!!next-input-character; |
945 |
|
|
redo A; |
946 |
|
|
} elsif ($self->{next_input_character} == 0x0022) { # " |
947 |
wakaba |
1.57 |
$self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE; |
948 |
wakaba |
1.1 |
!!!next-input-character; |
949 |
|
|
redo A; |
950 |
|
|
} elsif ($self->{next_input_character} == 0x0026) { # & |
951 |
wakaba |
1.57 |
$self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE; |
952 |
wakaba |
1.1 |
## reconsume |
953 |
|
|
redo A; |
954 |
|
|
} elsif ($self->{next_input_character} == 0x0027) { # ' |
955 |
wakaba |
1.57 |
$self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE; |
956 |
wakaba |
1.1 |
!!!next-input-character; |
957 |
|
|
redo A; |
958 |
|
|
} elsif ($self->{next_input_character} == 0x003E) { # > |
959 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
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.3 |
!!!parse-error (type => 'end tag attribute'); |
967 |
wakaba |
1.1 |
} |
968 |
|
|
} else { |
969 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
970 |
|
|
} |
971 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
972 |
wakaba |
1.1 |
!!!next-input-character; |
973 |
|
|
|
974 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
975 |
|
|
|
976 |
|
|
redo A; |
977 |
wakaba |
1.17 |
} elsif ($self->{next_input_character} == -1) { |
978 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed tag'); |
979 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
980 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
981 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
982 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
983 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
984 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
985 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
986 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
987 |
wakaba |
1.1 |
} |
988 |
|
|
} else { |
989 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
990 |
|
|
} |
991 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
992 |
wakaba |
1.1 |
## reconsume |
993 |
|
|
|
994 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
995 |
|
|
|
996 |
|
|
redo A; |
997 |
|
|
} else { |
998 |
wakaba |
1.72 |
if ($self->{next_input_character} == 0x003D) { # = |
999 |
|
|
!!!parse-error (type => 'bad attribute value'); |
1000 |
|
|
} |
1001 |
wakaba |
1.1 |
$self->{current_attribute}->{value} .= chr ($self->{next_input_character}); |
1002 |
wakaba |
1.57 |
$self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE; |
1003 |
wakaba |
1.1 |
!!!next-input-character; |
1004 |
|
|
redo A; |
1005 |
|
|
} |
1006 |
wakaba |
1.57 |
} elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) { |
1007 |
wakaba |
1.1 |
if ($self->{next_input_character} == 0x0022) { # " |
1008 |
wakaba |
1.72 |
$self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE; |
1009 |
wakaba |
1.1 |
!!!next-input-character; |
1010 |
|
|
redo A; |
1011 |
|
|
} elsif ($self->{next_input_character} == 0x0026) { # & |
1012 |
wakaba |
1.57 |
$self->{last_attribute_value_state} = $self->{state}; |
1013 |
|
|
$self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE; |
1014 |
wakaba |
1.1 |
!!!next-input-character; |
1015 |
|
|
redo A; |
1016 |
|
|
} elsif ($self->{next_input_character} == -1) { |
1017 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed attribute value'); |
1018 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
1019 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
1020 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
1021 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
1022 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
1023 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
1024 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
1025 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
1026 |
wakaba |
1.1 |
} |
1027 |
|
|
} else { |
1028 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
1029 |
|
|
} |
1030 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1031 |
wakaba |
1.1 |
## reconsume |
1032 |
|
|
|
1033 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
1034 |
|
|
|
1035 |
|
|
redo A; |
1036 |
|
|
} else { |
1037 |
|
|
$self->{current_attribute}->{value} .= chr ($self->{next_input_character}); |
1038 |
|
|
## Stay in the state |
1039 |
|
|
!!!next-input-character; |
1040 |
|
|
redo A; |
1041 |
|
|
} |
1042 |
wakaba |
1.57 |
} elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) { |
1043 |
wakaba |
1.1 |
if ($self->{next_input_character} == 0x0027) { # ' |
1044 |
wakaba |
1.72 |
$self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE; |
1045 |
wakaba |
1.1 |
!!!next-input-character; |
1046 |
|
|
redo A; |
1047 |
|
|
} elsif ($self->{next_input_character} == 0x0026) { # & |
1048 |
wakaba |
1.57 |
$self->{last_attribute_value_state} = $self->{state}; |
1049 |
|
|
$self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE; |
1050 |
wakaba |
1.1 |
!!!next-input-character; |
1051 |
|
|
redo A; |
1052 |
|
|
} elsif ($self->{next_input_character} == -1) { |
1053 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed attribute value'); |
1054 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
1055 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
1056 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
1057 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
1058 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
1059 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
1060 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
1061 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
1062 |
wakaba |
1.1 |
} |
1063 |
|
|
} else { |
1064 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
1065 |
|
|
} |
1066 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1067 |
wakaba |
1.1 |
## reconsume |
1068 |
|
|
|
1069 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
1070 |
|
|
|
1071 |
|
|
redo A; |
1072 |
|
|
} else { |
1073 |
|
|
$self->{current_attribute}->{value} .= chr ($self->{next_input_character}); |
1074 |
|
|
## Stay in the state |
1075 |
|
|
!!!next-input-character; |
1076 |
|
|
redo A; |
1077 |
|
|
} |
1078 |
wakaba |
1.57 |
} elsif ($self->{state} == ATTRIBUTE_VALUE_UNQUOTED_STATE) { |
1079 |
wakaba |
1.1 |
if ($self->{next_input_character} == 0x0009 or # HT |
1080 |
|
|
$self->{next_input_character} == 0x000A or # LF |
1081 |
|
|
$self->{next_input_character} == 0x000B or # HT |
1082 |
|
|
$self->{next_input_character} == 0x000C or # FF |
1083 |
|
|
$self->{next_input_character} == 0x0020) { # SP |
1084 |
wakaba |
1.57 |
$self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
1085 |
wakaba |
1.1 |
!!!next-input-character; |
1086 |
|
|
redo A; |
1087 |
|
|
} elsif ($self->{next_input_character} == 0x0026) { # & |
1088 |
wakaba |
1.57 |
$self->{last_attribute_value_state} = $self->{state}; |
1089 |
|
|
$self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE; |
1090 |
wakaba |
1.1 |
!!!next-input-character; |
1091 |
|
|
redo A; |
1092 |
|
|
} elsif ($self->{next_input_character} == 0x003E) { # > |
1093 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
1094 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
1095 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
1096 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
1097 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
1098 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
1099 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
1100 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
1101 |
wakaba |
1.1 |
} |
1102 |
|
|
} else { |
1103 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
1104 |
|
|
} |
1105 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1106 |
wakaba |
1.1 |
!!!next-input-character; |
1107 |
|
|
|
1108 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
1109 |
|
|
|
1110 |
|
|
redo A; |
1111 |
wakaba |
1.17 |
} elsif ($self->{next_input_character} == -1) { |
1112 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed tag'); |
1113 |
wakaba |
1.55 |
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
1114 |
wakaba |
1.28 |
$self->{current_token}->{first_start_tag} |
1115 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
1116 |
wakaba |
1.1 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
1117 |
wakaba |
1.55 |
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
1118 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
1119 |
wakaba |
1.1 |
if ($self->{current_token}->{attributes}) { |
1120 |
wakaba |
1.3 |
!!!parse-error (type => 'end tag attribute'); |
1121 |
wakaba |
1.1 |
} |
1122 |
|
|
} else { |
1123 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
1124 |
|
|
} |
1125 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1126 |
wakaba |
1.1 |
## reconsume |
1127 |
|
|
|
1128 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
1129 |
|
|
|
1130 |
|
|
redo A; |
1131 |
|
|
} else { |
1132 |
wakaba |
1.72 |
if ({ |
1133 |
|
|
0x0022 => 1, # " |
1134 |
|
|
0x0027 => 1, # ' |
1135 |
|
|
0x003D => 1, # = |
1136 |
|
|
}->{$self->{next_input_character}}) { |
1137 |
|
|
!!!parse-error (type => 'bad attribute value'); |
1138 |
|
|
} |
1139 |
wakaba |
1.1 |
$self->{current_attribute}->{value} .= chr ($self->{next_input_character}); |
1140 |
|
|
## Stay in the state |
1141 |
|
|
!!!next-input-character; |
1142 |
|
|
redo A; |
1143 |
|
|
} |
1144 |
wakaba |
1.57 |
} elsif ($self->{state} == ENTITY_IN_ATTRIBUTE_VALUE_STATE) { |
1145 |
wakaba |
1.72 |
my $token = $self->_tokenize_attempt_to_consume_an_entity |
1146 |
|
|
(1, |
1147 |
|
|
$self->{last_attribute_value_state} |
1148 |
|
|
== ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE ? 0x0022 : # " |
1149 |
|
|
$self->{last_attribute_value_state} |
1150 |
|
|
== ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE ? 0x0027 : # ' |
1151 |
|
|
-1); |
1152 |
wakaba |
1.1 |
|
1153 |
|
|
unless (defined $token) { |
1154 |
|
|
$self->{current_attribute}->{value} .= '&'; |
1155 |
|
|
} else { |
1156 |
|
|
$self->{current_attribute}->{value} .= $token->{data}; |
1157 |
wakaba |
1.66 |
$self->{current_attribute}->{has_reference} = $token->{has_reference}; |
1158 |
wakaba |
1.1 |
## ISSUE: spec says "append the returned character token to the current attribute's value" |
1159 |
|
|
} |
1160 |
|
|
|
1161 |
|
|
$self->{state} = $self->{last_attribute_value_state}; |
1162 |
|
|
# next-input-character is already done |
1163 |
|
|
redo A; |
1164 |
wakaba |
1.72 |
} elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) { |
1165 |
|
|
if ($self->{next_input_character} == 0x0009 or # HT |
1166 |
|
|
$self->{next_input_character} == 0x000A or # LF |
1167 |
|
|
$self->{next_input_character} == 0x000B or # VT |
1168 |
|
|
$self->{next_input_character} == 0x000C or # FF |
1169 |
|
|
$self->{next_input_character} == 0x0020) { # SP |
1170 |
|
|
$self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
1171 |
|
|
!!!next-input-character; |
1172 |
|
|
redo A; |
1173 |
|
|
} elsif ($self->{next_input_character} == 0x003E) { # > |
1174 |
|
|
if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
1175 |
|
|
$self->{current_token}->{first_start_tag} |
1176 |
|
|
= not defined $self->{last_emitted_start_tag_name}; |
1177 |
|
|
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
1178 |
|
|
} elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
1179 |
|
|
$self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
1180 |
|
|
if ($self->{current_token}->{attributes}) { |
1181 |
|
|
!!!parse-error (type => 'end tag attribute'); |
1182 |
|
|
} |
1183 |
|
|
} else { |
1184 |
|
|
die "$0: $self->{current_token}->{type}: Unknown token type"; |
1185 |
|
|
} |
1186 |
|
|
$self->{state} = DATA_STATE; |
1187 |
|
|
!!!next-input-character; |
1188 |
|
|
|
1189 |
|
|
!!!emit ($self->{current_token}); # start tag or end tag |
1190 |
|
|
|
1191 |
|
|
redo A; |
1192 |
|
|
} elsif ($self->{next_input_character} == 0x002F) { # / |
1193 |
|
|
!!!next-input-character; |
1194 |
|
|
if ($self->{next_input_character} == 0x003E and # > |
1195 |
|
|
$self->{current_token}->{type} == START_TAG_TOKEN and |
1196 |
|
|
$permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) { |
1197 |
|
|
# permitted slash |
1198 |
|
|
# |
1199 |
|
|
} else { |
1200 |
|
|
!!!parse-error (type => 'nestc'); |
1201 |
|
|
} |
1202 |
|
|
$self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
1203 |
|
|
# next-input-character is already done |
1204 |
|
|
redo A; |
1205 |
|
|
} else { |
1206 |
|
|
!!!parse-error (type => 'no space between attributes'); |
1207 |
|
|
$self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
1208 |
|
|
## reconsume |
1209 |
|
|
redo A; |
1210 |
|
|
} |
1211 |
wakaba |
1.57 |
} elsif ($self->{state} == BOGUS_COMMENT_STATE) { |
1212 |
wakaba |
1.1 |
## (only happen if PCDATA state) |
1213 |
|
|
|
1214 |
wakaba |
1.55 |
my $token = {type => COMMENT_TOKEN, data => ''}; |
1215 |
wakaba |
1.1 |
|
1216 |
|
|
BC: { |
1217 |
|
|
if ($self->{next_input_character} == 0x003E) { # > |
1218 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1219 |
wakaba |
1.1 |
!!!next-input-character; |
1220 |
|
|
|
1221 |
|
|
!!!emit ($token); |
1222 |
|
|
|
1223 |
|
|
redo A; |
1224 |
|
|
} elsif ($self->{next_input_character} == -1) { |
1225 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1226 |
wakaba |
1.1 |
## reconsume |
1227 |
|
|
|
1228 |
|
|
!!!emit ($token); |
1229 |
|
|
|
1230 |
|
|
redo A; |
1231 |
|
|
} else { |
1232 |
|
|
$token->{data} .= chr ($self->{next_input_character}); |
1233 |
|
|
!!!next-input-character; |
1234 |
|
|
redo BC; |
1235 |
|
|
} |
1236 |
|
|
} # BC |
1237 |
wakaba |
1.57 |
} elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) { |
1238 |
wakaba |
1.1 |
## (only happen if PCDATA state) |
1239 |
|
|
|
1240 |
|
|
my @next_char; |
1241 |
|
|
push @next_char, $self->{next_input_character}; |
1242 |
|
|
|
1243 |
|
|
if ($self->{next_input_character} == 0x002D) { # - |
1244 |
|
|
!!!next-input-character; |
1245 |
|
|
push @next_char, $self->{next_input_character}; |
1246 |
|
|
if ($self->{next_input_character} == 0x002D) { # - |
1247 |
wakaba |
1.55 |
$self->{current_token} = {type => COMMENT_TOKEN, data => ''}; |
1248 |
wakaba |
1.57 |
$self->{state} = COMMENT_START_STATE; |
1249 |
wakaba |
1.1 |
!!!next-input-character; |
1250 |
|
|
redo A; |
1251 |
|
|
} |
1252 |
|
|
} elsif ($self->{next_input_character} == 0x0044 or # D |
1253 |
|
|
$self->{next_input_character} == 0x0064) { # d |
1254 |
|
|
!!!next-input-character; |
1255 |
|
|
push @next_char, $self->{next_input_character}; |
1256 |
|
|
if ($self->{next_input_character} == 0x004F or # O |
1257 |
|
|
$self->{next_input_character} == 0x006F) { # o |
1258 |
|
|
!!!next-input-character; |
1259 |
|
|
push @next_char, $self->{next_input_character}; |
1260 |
|
|
if ($self->{next_input_character} == 0x0043 or # C |
1261 |
|
|
$self->{next_input_character} == 0x0063) { # c |
1262 |
|
|
!!!next-input-character; |
1263 |
|
|
push @next_char, $self->{next_input_character}; |
1264 |
|
|
if ($self->{next_input_character} == 0x0054 or # T |
1265 |
|
|
$self->{next_input_character} == 0x0074) { # t |
1266 |
|
|
!!!next-input-character; |
1267 |
|
|
push @next_char, $self->{next_input_character}; |
1268 |
|
|
if ($self->{next_input_character} == 0x0059 or # Y |
1269 |
|
|
$self->{next_input_character} == 0x0079) { # y |
1270 |
|
|
!!!next-input-character; |
1271 |
|
|
push @next_char, $self->{next_input_character}; |
1272 |
|
|
if ($self->{next_input_character} == 0x0050 or # P |
1273 |
|
|
$self->{next_input_character} == 0x0070) { # p |
1274 |
|
|
!!!next-input-character; |
1275 |
|
|
push @next_char, $self->{next_input_character}; |
1276 |
|
|
if ($self->{next_input_character} == 0x0045 or # E |
1277 |
|
|
$self->{next_input_character} == 0x0065) { # e |
1278 |
|
|
## ISSUE: What a stupid code this is! |
1279 |
wakaba |
1.57 |
$self->{state} = DOCTYPE_STATE; |
1280 |
wakaba |
1.1 |
!!!next-input-character; |
1281 |
|
|
redo A; |
1282 |
|
|
} |
1283 |
|
|
} |
1284 |
|
|
} |
1285 |
|
|
} |
1286 |
|
|
} |
1287 |
|
|
} |
1288 |
|
|
} |
1289 |
|
|
|
1290 |
wakaba |
1.30 |
!!!parse-error (type => 'bogus comment'); |
1291 |
wakaba |
1.1 |
$self->{next_input_character} = shift @next_char; |
1292 |
|
|
!!!back-next-input-character (@next_char); |
1293 |
wakaba |
1.57 |
$self->{state} = BOGUS_COMMENT_STATE; |
1294 |
wakaba |
1.1 |
redo A; |
1295 |
|
|
|
1296 |
|
|
## ISSUE: typos in spec: chacacters, is is a parse error |
1297 |
|
|
## 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? |
1298 |
wakaba |
1.57 |
} elsif ($self->{state} == COMMENT_START_STATE) { |
1299 |
wakaba |
1.23 |
if ($self->{next_input_character} == 0x002D) { # - |
1300 |
wakaba |
1.57 |
$self->{state} = COMMENT_START_DASH_STATE; |
1301 |
wakaba |
1.23 |
!!!next-input-character; |
1302 |
|
|
redo A; |
1303 |
|
|
} elsif ($self->{next_input_character} == 0x003E) { # > |
1304 |
|
|
!!!parse-error (type => 'bogus comment'); |
1305 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1306 |
wakaba |
1.23 |
!!!next-input-character; |
1307 |
|
|
|
1308 |
|
|
!!!emit ($self->{current_token}); # comment |
1309 |
|
|
|
1310 |
|
|
redo A; |
1311 |
|
|
} elsif ($self->{next_input_character} == -1) { |
1312 |
|
|
!!!parse-error (type => 'unclosed comment'); |
1313 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1314 |
wakaba |
1.23 |
## reconsume |
1315 |
|
|
|
1316 |
|
|
!!!emit ($self->{current_token}); # comment |
1317 |
|
|
|
1318 |
|
|
redo A; |
1319 |
|
|
} else { |
1320 |
|
|
$self->{current_token}->{data} # comment |
1321 |
|
|
.= chr ($self->{next_input_character}); |
1322 |
wakaba |
1.57 |
$self->{state} = COMMENT_STATE; |
1323 |
wakaba |
1.23 |
!!!next-input-character; |
1324 |
|
|
redo A; |
1325 |
|
|
} |
1326 |
wakaba |
1.57 |
} elsif ($self->{state} == COMMENT_START_DASH_STATE) { |
1327 |
wakaba |
1.23 |
if ($self->{next_input_character} == 0x002D) { # - |
1328 |
wakaba |
1.57 |
$self->{state} = COMMENT_END_STATE; |
1329 |
wakaba |
1.23 |
!!!next-input-character; |
1330 |
|
|
redo A; |
1331 |
|
|
} elsif ($self->{next_input_character} == 0x003E) { # > |
1332 |
|
|
!!!parse-error (type => 'bogus comment'); |
1333 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1334 |
wakaba |
1.23 |
!!!next-input-character; |
1335 |
|
|
|
1336 |
|
|
!!!emit ($self->{current_token}); # comment |
1337 |
|
|
|
1338 |
|
|
redo A; |
1339 |
|
|
} elsif ($self->{next_input_character} == -1) { |
1340 |
|
|
!!!parse-error (type => 'unclosed comment'); |
1341 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1342 |
wakaba |
1.23 |
## reconsume |
1343 |
|
|
|
1344 |
|
|
!!!emit ($self->{current_token}); # comment |
1345 |
|
|
|
1346 |
|
|
redo A; |
1347 |
|
|
} else { |
1348 |
|
|
$self->{current_token}->{data} # comment |
1349 |
wakaba |
1.33 |
.= '-' . chr ($self->{next_input_character}); |
1350 |
wakaba |
1.57 |
$self->{state} = COMMENT_STATE; |
1351 |
wakaba |
1.23 |
!!!next-input-character; |
1352 |
|
|
redo A; |
1353 |
|
|
} |
1354 |
wakaba |
1.57 |
} elsif ($self->{state} == COMMENT_STATE) { |
1355 |
wakaba |
1.1 |
if ($self->{next_input_character} == 0x002D) { # - |
1356 |
wakaba |
1.57 |
$self->{state} = COMMENT_END_DASH_STATE; |
1357 |
wakaba |
1.1 |
!!!next-input-character; |
1358 |
|
|
redo A; |
1359 |
|
|
} elsif ($self->{next_input_character} == -1) { |
1360 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed comment'); |
1361 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1362 |
wakaba |
1.1 |
## reconsume |
1363 |
|
|
|
1364 |
|
|
!!!emit ($self->{current_token}); # comment |
1365 |
|
|
|
1366 |
|
|
redo A; |
1367 |
|
|
} else { |
1368 |
|
|
$self->{current_token}->{data} .= chr ($self->{next_input_character}); # comment |
1369 |
|
|
## Stay in the state |
1370 |
|
|
!!!next-input-character; |
1371 |
|
|
redo A; |
1372 |
|
|
} |
1373 |
wakaba |
1.57 |
} elsif ($self->{state} == COMMENT_END_DASH_STATE) { |
1374 |
wakaba |
1.1 |
if ($self->{next_input_character} == 0x002D) { # - |
1375 |
wakaba |
1.57 |
$self->{state} = COMMENT_END_STATE; |
1376 |
wakaba |
1.1 |
!!!next-input-character; |
1377 |
|
|
redo A; |
1378 |
|
|
} elsif ($self->{next_input_character} == -1) { |
1379 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed comment'); |
1380 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1381 |
wakaba |
1.1 |
## reconsume |
1382 |
|
|
|
1383 |
|
|
!!!emit ($self->{current_token}); # comment |
1384 |
|
|
|
1385 |
|
|
redo A; |
1386 |
|
|
} else { |
1387 |
|
|
$self->{current_token}->{data} .= '-' . chr ($self->{next_input_character}); # comment |
1388 |
wakaba |
1.57 |
$self->{state} = COMMENT_STATE; |
1389 |
wakaba |
1.1 |
!!!next-input-character; |
1390 |
|
|
redo A; |
1391 |
|
|
} |
1392 |
wakaba |
1.57 |
} elsif ($self->{state} == COMMENT_END_STATE) { |
1393 |
wakaba |
1.1 |
if ($self->{next_input_character} == 0x003E) { # > |
1394 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1395 |
wakaba |
1.1 |
!!!next-input-character; |
1396 |
|
|
|
1397 |
|
|
!!!emit ($self->{current_token}); # comment |
1398 |
|
|
|
1399 |
|
|
redo A; |
1400 |
|
|
} elsif ($self->{next_input_character} == 0x002D) { # - |
1401 |
wakaba |
1.3 |
!!!parse-error (type => 'dash in comment'); |
1402 |
wakaba |
1.1 |
$self->{current_token}->{data} .= '-'; # comment |
1403 |
|
|
## Stay in the state |
1404 |
|
|
!!!next-input-character; |
1405 |
|
|
redo A; |
1406 |
|
|
} elsif ($self->{next_input_character} == -1) { |
1407 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed comment'); |
1408 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1409 |
wakaba |
1.1 |
## reconsume |
1410 |
|
|
|
1411 |
|
|
!!!emit ($self->{current_token}); # comment |
1412 |
|
|
|
1413 |
|
|
redo A; |
1414 |
|
|
} else { |
1415 |
wakaba |
1.3 |
!!!parse-error (type => 'dash in comment'); |
1416 |
wakaba |
1.1 |
$self->{current_token}->{data} .= '--' . chr ($self->{next_input_character}); # comment |
1417 |
wakaba |
1.57 |
$self->{state} = COMMENT_STATE; |
1418 |
wakaba |
1.1 |
!!!next-input-character; |
1419 |
|
|
redo A; |
1420 |
|
|
} |
1421 |
wakaba |
1.57 |
} elsif ($self->{state} == DOCTYPE_STATE) { |
1422 |
wakaba |
1.1 |
if ($self->{next_input_character} == 0x0009 or # HT |
1423 |
|
|
$self->{next_input_character} == 0x000A or # LF |
1424 |
|
|
$self->{next_input_character} == 0x000B or # VT |
1425 |
|
|
$self->{next_input_character} == 0x000C or # FF |
1426 |
|
|
$self->{next_input_character} == 0x0020) { # SP |
1427 |
wakaba |
1.57 |
$self->{state} = BEFORE_DOCTYPE_NAME_STATE; |
1428 |
wakaba |
1.1 |
!!!next-input-character; |
1429 |
|
|
redo A; |
1430 |
|
|
} else { |
1431 |
wakaba |
1.3 |
!!!parse-error (type => 'no space before DOCTYPE name'); |
1432 |
wakaba |
1.57 |
$self->{state} = BEFORE_DOCTYPE_NAME_STATE; |
1433 |
wakaba |
1.1 |
## reconsume |
1434 |
|
|
redo A; |
1435 |
|
|
} |
1436 |
wakaba |
1.57 |
} elsif ($self->{state} == BEFORE_DOCTYPE_NAME_STATE) { |
1437 |
wakaba |
1.1 |
if ($self->{next_input_character} == 0x0009 or # HT |
1438 |
|
|
$self->{next_input_character} == 0x000A or # LF |
1439 |
|
|
$self->{next_input_character} == 0x000B or # VT |
1440 |
|
|
$self->{next_input_character} == 0x000C or # FF |
1441 |
|
|
$self->{next_input_character} == 0x0020) { # SP |
1442 |
|
|
## Stay in the state |
1443 |
|
|
!!!next-input-character; |
1444 |
|
|
redo A; |
1445 |
|
|
} elsif ($self->{next_input_character} == 0x003E) { # > |
1446 |
wakaba |
1.3 |
!!!parse-error (type => 'no DOCTYPE name'); |
1447 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1448 |
wakaba |
1.1 |
!!!next-input-character; |
1449 |
|
|
|
1450 |
wakaba |
1.55 |
!!!emit ({type => DOCTYPE_TOKEN}); # incorrect |
1451 |
wakaba |
1.1 |
|
1452 |
|
|
redo A; |
1453 |
|
|
} elsif ($self->{next_input_character} == -1) { |
1454 |
wakaba |
1.3 |
!!!parse-error (type => 'no DOCTYPE name'); |
1455 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1456 |
wakaba |
1.1 |
## reconsume |
1457 |
|
|
|
1458 |
wakaba |
1.55 |
!!!emit ({type => DOCTYPE_TOKEN}); # incorrect |
1459 |
wakaba |
1.1 |
|
1460 |
|
|
redo A; |
1461 |
|
|
} else { |
1462 |
wakaba |
1.18 |
$self->{current_token} |
1463 |
wakaba |
1.55 |
= {type => DOCTYPE_TOKEN, |
1464 |
wakaba |
1.18 |
name => chr ($self->{next_input_character}), |
1465 |
|
|
correct => 1}; |
1466 |
wakaba |
1.4 |
## ISSUE: "Set the token's name name to the" in the spec |
1467 |
wakaba |
1.57 |
$self->{state} = DOCTYPE_NAME_STATE; |
1468 |
wakaba |
1.1 |
!!!next-input-character; |
1469 |
|
|
redo A; |
1470 |
|
|
} |
1471 |
wakaba |
1.57 |
} elsif ($self->{state} == DOCTYPE_NAME_STATE) { |
1472 |
wakaba |
1.18 |
## ISSUE: Redundant "First," in the spec. |
1473 |
wakaba |
1.1 |
if ($self->{next_input_character} == 0x0009 or # HT |
1474 |
|
|
$self->{next_input_character} == 0x000A or # LF |
1475 |
|
|
$self->{next_input_character} == 0x000B or # VT |
1476 |
|
|
$self->{next_input_character} == 0x000C or # FF |
1477 |
|
|
$self->{next_input_character} == 0x0020) { # SP |
1478 |
wakaba |
1.57 |
$self->{state} = AFTER_DOCTYPE_NAME_STATE; |
1479 |
wakaba |
1.1 |
!!!next-input-character; |
1480 |
|
|
redo A; |
1481 |
|
|
} elsif ($self->{next_input_character} == 0x003E) { # > |
1482 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1483 |
wakaba |
1.1 |
!!!next-input-character; |
1484 |
|
|
|
1485 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1486 |
|
|
|
1487 |
|
|
redo A; |
1488 |
|
|
} elsif ($self->{next_input_character} == -1) { |
1489 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed DOCTYPE'); |
1490 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1491 |
wakaba |
1.1 |
## reconsume |
1492 |
|
|
|
1493 |
wakaba |
1.18 |
delete $self->{current_token}->{correct}; |
1494 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1495 |
wakaba |
1.1 |
|
1496 |
|
|
redo A; |
1497 |
|
|
} else { |
1498 |
|
|
$self->{current_token}->{name} |
1499 |
|
|
.= chr ($self->{next_input_character}); # DOCTYPE |
1500 |
|
|
## Stay in the state |
1501 |
|
|
!!!next-input-character; |
1502 |
|
|
redo A; |
1503 |
|
|
} |
1504 |
wakaba |
1.57 |
} elsif ($self->{state} == AFTER_DOCTYPE_NAME_STATE) { |
1505 |
wakaba |
1.1 |
if ($self->{next_input_character} == 0x0009 or # HT |
1506 |
|
|
$self->{next_input_character} == 0x000A or # LF |
1507 |
|
|
$self->{next_input_character} == 0x000B or # VT |
1508 |
|
|
$self->{next_input_character} == 0x000C or # FF |
1509 |
|
|
$self->{next_input_character} == 0x0020) { # SP |
1510 |
|
|
## Stay in the state |
1511 |
|
|
!!!next-input-character; |
1512 |
|
|
redo A; |
1513 |
|
|
} elsif ($self->{next_input_character} == 0x003E) { # > |
1514 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1515 |
wakaba |
1.1 |
!!!next-input-character; |
1516 |
|
|
|
1517 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1518 |
|
|
|
1519 |
|
|
redo A; |
1520 |
|
|
} elsif ($self->{next_input_character} == -1) { |
1521 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed DOCTYPE'); |
1522 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1523 |
wakaba |
1.1 |
## reconsume |
1524 |
|
|
|
1525 |
wakaba |
1.18 |
delete $self->{current_token}->{correct}; |
1526 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1527 |
|
|
|
1528 |
|
|
redo A; |
1529 |
|
|
} elsif ($self->{next_input_character} == 0x0050 or # P |
1530 |
|
|
$self->{next_input_character} == 0x0070) { # p |
1531 |
|
|
!!!next-input-character; |
1532 |
|
|
if ($self->{next_input_character} == 0x0055 or # U |
1533 |
|
|
$self->{next_input_character} == 0x0075) { # u |
1534 |
|
|
!!!next-input-character; |
1535 |
|
|
if ($self->{next_input_character} == 0x0042 or # B |
1536 |
|
|
$self->{next_input_character} == 0x0062) { # b |
1537 |
|
|
!!!next-input-character; |
1538 |
|
|
if ($self->{next_input_character} == 0x004C or # L |
1539 |
|
|
$self->{next_input_character} == 0x006C) { # l |
1540 |
|
|
!!!next-input-character; |
1541 |
|
|
if ($self->{next_input_character} == 0x0049 or # I |
1542 |
|
|
$self->{next_input_character} == 0x0069) { # i |
1543 |
|
|
!!!next-input-character; |
1544 |
|
|
if ($self->{next_input_character} == 0x0043 or # C |
1545 |
|
|
$self->{next_input_character} == 0x0063) { # c |
1546 |
wakaba |
1.57 |
$self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE; |
1547 |
wakaba |
1.18 |
!!!next-input-character; |
1548 |
|
|
redo A; |
1549 |
|
|
} |
1550 |
|
|
} |
1551 |
|
|
} |
1552 |
|
|
} |
1553 |
|
|
} |
1554 |
|
|
|
1555 |
|
|
# |
1556 |
|
|
} elsif ($self->{next_input_character} == 0x0053 or # S |
1557 |
|
|
$self->{next_input_character} == 0x0073) { # s |
1558 |
|
|
!!!next-input-character; |
1559 |
|
|
if ($self->{next_input_character} == 0x0059 or # Y |
1560 |
|
|
$self->{next_input_character} == 0x0079) { # y |
1561 |
|
|
!!!next-input-character; |
1562 |
|
|
if ($self->{next_input_character} == 0x0053 or # S |
1563 |
|
|
$self->{next_input_character} == 0x0073) { # s |
1564 |
|
|
!!!next-input-character; |
1565 |
|
|
if ($self->{next_input_character} == 0x0054 or # T |
1566 |
|
|
$self->{next_input_character} == 0x0074) { # t |
1567 |
|
|
!!!next-input-character; |
1568 |
|
|
if ($self->{next_input_character} == 0x0045 or # E |
1569 |
|
|
$self->{next_input_character} == 0x0065) { # e |
1570 |
|
|
!!!next-input-character; |
1571 |
|
|
if ($self->{next_input_character} == 0x004D or # M |
1572 |
|
|
$self->{next_input_character} == 0x006D) { # m |
1573 |
wakaba |
1.57 |
$self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE; |
1574 |
wakaba |
1.18 |
!!!next-input-character; |
1575 |
|
|
redo A; |
1576 |
|
|
} |
1577 |
|
|
} |
1578 |
|
|
} |
1579 |
|
|
} |
1580 |
|
|
} |
1581 |
|
|
|
1582 |
|
|
# |
1583 |
|
|
} else { |
1584 |
|
|
!!!next-input-character; |
1585 |
|
|
# |
1586 |
|
|
} |
1587 |
|
|
|
1588 |
|
|
!!!parse-error (type => 'string after DOCTYPE name'); |
1589 |
wakaba |
1.73 |
delete $self->{current_token}->{correct}; |
1590 |
|
|
|
1591 |
wakaba |
1.57 |
$self->{state} = BOGUS_DOCTYPE_STATE; |
1592 |
wakaba |
1.18 |
# next-input-character is already done |
1593 |
|
|
redo A; |
1594 |
wakaba |
1.57 |
} elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) { |
1595 |
wakaba |
1.18 |
if ({ |
1596 |
|
|
0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, |
1597 |
|
|
#0x000D => 1, # HT, LF, VT, FF, SP, CR |
1598 |
|
|
}->{$self->{next_input_character}}) { |
1599 |
|
|
## Stay in the state |
1600 |
|
|
!!!next-input-character; |
1601 |
|
|
redo A; |
1602 |
|
|
} elsif ($self->{next_input_character} eq 0x0022) { # " |
1603 |
|
|
$self->{current_token}->{public_identifier} = ''; # DOCTYPE |
1604 |
wakaba |
1.57 |
$self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE; |
1605 |
wakaba |
1.18 |
!!!next-input-character; |
1606 |
|
|
redo A; |
1607 |
|
|
} elsif ($self->{next_input_character} eq 0x0027) { # ' |
1608 |
|
|
$self->{current_token}->{public_identifier} = ''; # DOCTYPE |
1609 |
wakaba |
1.57 |
$self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE; |
1610 |
wakaba |
1.18 |
!!!next-input-character; |
1611 |
|
|
redo A; |
1612 |
|
|
} elsif ($self->{next_input_character} eq 0x003E) { # > |
1613 |
|
|
!!!parse-error (type => 'no PUBLIC literal'); |
1614 |
|
|
|
1615 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1616 |
wakaba |
1.18 |
!!!next-input-character; |
1617 |
|
|
|
1618 |
|
|
delete $self->{current_token}->{correct}; |
1619 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1620 |
|
|
|
1621 |
|
|
redo A; |
1622 |
|
|
} elsif ($self->{next_input_character} == -1) { |
1623 |
|
|
!!!parse-error (type => 'unclosed DOCTYPE'); |
1624 |
|
|
|
1625 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1626 |
wakaba |
1.18 |
## reconsume |
1627 |
|
|
|
1628 |
|
|
delete $self->{current_token}->{correct}; |
1629 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1630 |
|
|
|
1631 |
|
|
redo A; |
1632 |
|
|
} else { |
1633 |
|
|
!!!parse-error (type => 'string after PUBLIC'); |
1634 |
wakaba |
1.73 |
delete $self->{current_token}->{correct}; |
1635 |
|
|
|
1636 |
wakaba |
1.57 |
$self->{state} = BOGUS_DOCTYPE_STATE; |
1637 |
wakaba |
1.18 |
!!!next-input-character; |
1638 |
|
|
redo A; |
1639 |
|
|
} |
1640 |
wakaba |
1.57 |
} elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE) { |
1641 |
wakaba |
1.18 |
if ($self->{next_input_character} == 0x0022) { # " |
1642 |
wakaba |
1.57 |
$self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE; |
1643 |
wakaba |
1.18 |
!!!next-input-character; |
1644 |
|
|
redo A; |
1645 |
wakaba |
1.69 |
} elsif ($self->{next_input_character} == 0x003E) { # > |
1646 |
|
|
!!!parse-error (type => 'unclosed PUBLIC literal'); |
1647 |
|
|
|
1648 |
|
|
$self->{state} = DATA_STATE; |
1649 |
|
|
!!!next-input-character; |
1650 |
|
|
|
1651 |
|
|
delete $self->{current_token}->{correct}; |
1652 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1653 |
|
|
|
1654 |
|
|
redo A; |
1655 |
wakaba |
1.18 |
} elsif ($self->{next_input_character} == -1) { |
1656 |
|
|
!!!parse-error (type => 'unclosed PUBLIC literal'); |
1657 |
|
|
|
1658 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1659 |
wakaba |
1.18 |
## reconsume |
1660 |
|
|
|
1661 |
|
|
delete $self->{current_token}->{correct}; |
1662 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1663 |
|
|
|
1664 |
|
|
redo A; |
1665 |
|
|
} else { |
1666 |
|
|
$self->{current_token}->{public_identifier} # DOCTYPE |
1667 |
|
|
.= chr $self->{next_input_character}; |
1668 |
|
|
## Stay in the state |
1669 |
|
|
!!!next-input-character; |
1670 |
|
|
redo A; |
1671 |
|
|
} |
1672 |
wakaba |
1.57 |
} elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE) { |
1673 |
wakaba |
1.18 |
if ($self->{next_input_character} == 0x0027) { # ' |
1674 |
wakaba |
1.57 |
$self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE; |
1675 |
wakaba |
1.18 |
!!!next-input-character; |
1676 |
|
|
redo A; |
1677 |
wakaba |
1.69 |
} elsif ($self->{next_input_character} == 0x003E) { # > |
1678 |
|
|
!!!parse-error (type => 'unclosed PUBLIC literal'); |
1679 |
|
|
|
1680 |
|
|
$self->{state} = DATA_STATE; |
1681 |
|
|
!!!next-input-character; |
1682 |
|
|
|
1683 |
|
|
delete $self->{current_token}->{correct}; |
1684 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1685 |
|
|
|
1686 |
|
|
redo A; |
1687 |
wakaba |
1.18 |
} elsif ($self->{next_input_character} == -1) { |
1688 |
|
|
!!!parse-error (type => 'unclosed PUBLIC literal'); |
1689 |
|
|
|
1690 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1691 |
wakaba |
1.18 |
## reconsume |
1692 |
|
|
|
1693 |
|
|
delete $self->{current_token}->{correct}; |
1694 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1695 |
|
|
|
1696 |
|
|
redo A; |
1697 |
|
|
} else { |
1698 |
|
|
$self->{current_token}->{public_identifier} # DOCTYPE |
1699 |
|
|
.= chr $self->{next_input_character}; |
1700 |
|
|
## Stay in the state |
1701 |
|
|
!!!next-input-character; |
1702 |
|
|
redo A; |
1703 |
|
|
} |
1704 |
wakaba |
1.57 |
} elsif ($self->{state} == AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE) { |
1705 |
wakaba |
1.18 |
if ({ |
1706 |
|
|
0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, |
1707 |
|
|
#0x000D => 1, # HT, LF, VT, FF, SP, CR |
1708 |
|
|
}->{$self->{next_input_character}}) { |
1709 |
|
|
## Stay in the state |
1710 |
|
|
!!!next-input-character; |
1711 |
|
|
redo A; |
1712 |
|
|
} elsif ($self->{next_input_character} == 0x0022) { # " |
1713 |
|
|
$self->{current_token}->{system_identifier} = ''; # DOCTYPE |
1714 |
wakaba |
1.57 |
$self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE; |
1715 |
wakaba |
1.18 |
!!!next-input-character; |
1716 |
|
|
redo A; |
1717 |
|
|
} elsif ($self->{next_input_character} == 0x0027) { # ' |
1718 |
|
|
$self->{current_token}->{system_identifier} = ''; # DOCTYPE |
1719 |
wakaba |
1.57 |
$self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE; |
1720 |
wakaba |
1.18 |
!!!next-input-character; |
1721 |
|
|
redo A; |
1722 |
|
|
} elsif ($self->{next_input_character} == 0x003E) { # > |
1723 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1724 |
wakaba |
1.18 |
!!!next-input-character; |
1725 |
|
|
|
1726 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1727 |
|
|
|
1728 |
|
|
redo A; |
1729 |
|
|
} elsif ($self->{next_input_character} == -1) { |
1730 |
|
|
!!!parse-error (type => 'unclosed DOCTYPE'); |
1731 |
|
|
|
1732 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1733 |
wakaba |
1.26 |
## reconsume |
1734 |
wakaba |
1.18 |
|
1735 |
|
|
delete $self->{current_token}->{correct}; |
1736 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1737 |
|
|
|
1738 |
|
|
redo A; |
1739 |
|
|
} else { |
1740 |
|
|
!!!parse-error (type => 'string after PUBLIC literal'); |
1741 |
wakaba |
1.73 |
delete $self->{current_token}->{correct}; |
1742 |
|
|
|
1743 |
wakaba |
1.57 |
$self->{state} = BOGUS_DOCTYPE_STATE; |
1744 |
wakaba |
1.18 |
!!!next-input-character; |
1745 |
|
|
redo A; |
1746 |
|
|
} |
1747 |
wakaba |
1.57 |
} elsif ($self->{state} == BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE) { |
1748 |
wakaba |
1.18 |
if ({ |
1749 |
|
|
0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, |
1750 |
|
|
#0x000D => 1, # HT, LF, VT, FF, SP, CR |
1751 |
|
|
}->{$self->{next_input_character}}) { |
1752 |
|
|
## Stay in the state |
1753 |
|
|
!!!next-input-character; |
1754 |
|
|
redo A; |
1755 |
|
|
} elsif ($self->{next_input_character} == 0x0022) { # " |
1756 |
|
|
$self->{current_token}->{system_identifier} = ''; # DOCTYPE |
1757 |
wakaba |
1.57 |
$self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE; |
1758 |
wakaba |
1.18 |
!!!next-input-character; |
1759 |
|
|
redo A; |
1760 |
|
|
} elsif ($self->{next_input_character} == 0x0027) { # ' |
1761 |
|
|
$self->{current_token}->{system_identifier} = ''; # DOCTYPE |
1762 |
wakaba |
1.57 |
$self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE; |
1763 |
wakaba |
1.18 |
!!!next-input-character; |
1764 |
|
|
redo A; |
1765 |
|
|
} elsif ($self->{next_input_character} == 0x003E) { # > |
1766 |
|
|
!!!parse-error (type => 'no SYSTEM literal'); |
1767 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1768 |
wakaba |
1.18 |
!!!next-input-character; |
1769 |
|
|
|
1770 |
|
|
delete $self->{current_token}->{correct}; |
1771 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1772 |
|
|
|
1773 |
|
|
redo A; |
1774 |
|
|
} elsif ($self->{next_input_character} == -1) { |
1775 |
|
|
!!!parse-error (type => 'unclosed DOCTYPE'); |
1776 |
|
|
|
1777 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1778 |
wakaba |
1.26 |
## reconsume |
1779 |
wakaba |
1.18 |
|
1780 |
|
|
delete $self->{current_token}->{correct}; |
1781 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1782 |
|
|
|
1783 |
|
|
redo A; |
1784 |
|
|
} else { |
1785 |
wakaba |
1.30 |
!!!parse-error (type => 'string after SYSTEM'); |
1786 |
wakaba |
1.73 |
delete $self->{current_token}->{correct}; |
1787 |
|
|
|
1788 |
wakaba |
1.57 |
$self->{state} = BOGUS_DOCTYPE_STATE; |
1789 |
wakaba |
1.18 |
!!!next-input-character; |
1790 |
|
|
redo A; |
1791 |
|
|
} |
1792 |
wakaba |
1.57 |
} elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE) { |
1793 |
wakaba |
1.18 |
if ($self->{next_input_character} == 0x0022) { # " |
1794 |
wakaba |
1.57 |
$self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE; |
1795 |
wakaba |
1.18 |
!!!next-input-character; |
1796 |
|
|
redo A; |
1797 |
wakaba |
1.69 |
} elsif ($self->{next_input_character} == 0x003E) { # > |
1798 |
|
|
!!!parse-error (type => 'unclosed PUBLIC literal'); |
1799 |
|
|
|
1800 |
|
|
$self->{state} = DATA_STATE; |
1801 |
|
|
!!!next-input-character; |
1802 |
|
|
|
1803 |
|
|
delete $self->{current_token}->{correct}; |
1804 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1805 |
|
|
|
1806 |
|
|
redo A; |
1807 |
wakaba |
1.18 |
} elsif ($self->{next_input_character} == -1) { |
1808 |
|
|
!!!parse-error (type => 'unclosed SYSTEM literal'); |
1809 |
|
|
|
1810 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1811 |
wakaba |
1.18 |
## reconsume |
1812 |
|
|
|
1813 |
|
|
delete $self->{current_token}->{correct}; |
1814 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1815 |
|
|
|
1816 |
|
|
redo A; |
1817 |
|
|
} else { |
1818 |
|
|
$self->{current_token}->{system_identifier} # DOCTYPE |
1819 |
|
|
.= chr $self->{next_input_character}; |
1820 |
|
|
## Stay in the state |
1821 |
|
|
!!!next-input-character; |
1822 |
|
|
redo A; |
1823 |
|
|
} |
1824 |
wakaba |
1.57 |
} elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE) { |
1825 |
wakaba |
1.18 |
if ($self->{next_input_character} == 0x0027) { # ' |
1826 |
wakaba |
1.57 |
$self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE; |
1827 |
wakaba |
1.18 |
!!!next-input-character; |
1828 |
|
|
redo A; |
1829 |
wakaba |
1.69 |
} elsif ($self->{next_input_character} == 0x003E) { # > |
1830 |
|
|
!!!parse-error (type => 'unclosed PUBLIC literal'); |
1831 |
|
|
|
1832 |
|
|
$self->{state} = DATA_STATE; |
1833 |
|
|
!!!next-input-character; |
1834 |
|
|
|
1835 |
|
|
delete $self->{current_token}->{correct}; |
1836 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1837 |
|
|
|
1838 |
|
|
redo A; |
1839 |
wakaba |
1.18 |
} elsif ($self->{next_input_character} == -1) { |
1840 |
|
|
!!!parse-error (type => 'unclosed SYSTEM literal'); |
1841 |
|
|
|
1842 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1843 |
wakaba |
1.18 |
## reconsume |
1844 |
|
|
|
1845 |
|
|
delete $self->{current_token}->{correct}; |
1846 |
wakaba |
1.1 |
!!!emit ($self->{current_token}); # DOCTYPE |
1847 |
|
|
|
1848 |
|
|
redo A; |
1849 |
|
|
} else { |
1850 |
wakaba |
1.18 |
$self->{current_token}->{system_identifier} # DOCTYPE |
1851 |
|
|
.= chr $self->{next_input_character}; |
1852 |
|
|
## Stay in the state |
1853 |
|
|
!!!next-input-character; |
1854 |
|
|
redo A; |
1855 |
|
|
} |
1856 |
wakaba |
1.57 |
} elsif ($self->{state} == AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE) { |
1857 |
wakaba |
1.18 |
if ({ |
1858 |
|
|
0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, |
1859 |
|
|
#0x000D => 1, # HT, LF, VT, FF, SP, CR |
1860 |
|
|
}->{$self->{next_input_character}}) { |
1861 |
|
|
## Stay in the state |
1862 |
|
|
!!!next-input-character; |
1863 |
|
|
redo A; |
1864 |
|
|
} elsif ($self->{next_input_character} == 0x003E) { # > |
1865 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1866 |
wakaba |
1.18 |
!!!next-input-character; |
1867 |
|
|
|
1868 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1869 |
|
|
|
1870 |
|
|
redo A; |
1871 |
|
|
} elsif ($self->{next_input_character} == -1) { |
1872 |
|
|
!!!parse-error (type => 'unclosed DOCTYPE'); |
1873 |
|
|
|
1874 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1875 |
wakaba |
1.26 |
## reconsume |
1876 |
wakaba |
1.18 |
|
1877 |
|
|
delete $self->{current_token}->{correct}; |
1878 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1879 |
|
|
|
1880 |
|
|
redo A; |
1881 |
|
|
} else { |
1882 |
|
|
!!!parse-error (type => 'string after SYSTEM literal'); |
1883 |
wakaba |
1.73 |
delete $self->{current_token}->{correct}; |
1884 |
|
|
|
1885 |
wakaba |
1.57 |
$self->{state} = BOGUS_DOCTYPE_STATE; |
1886 |
wakaba |
1.1 |
!!!next-input-character; |
1887 |
|
|
redo A; |
1888 |
|
|
} |
1889 |
wakaba |
1.57 |
} elsif ($self->{state} == BOGUS_DOCTYPE_STATE) { |
1890 |
wakaba |
1.1 |
if ($self->{next_input_character} == 0x003E) { # > |
1891 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1892 |
wakaba |
1.1 |
!!!next-input-character; |
1893 |
|
|
|
1894 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1895 |
|
|
|
1896 |
|
|
redo A; |
1897 |
|
|
} elsif ($self->{next_input_character} == -1) { |
1898 |
wakaba |
1.3 |
!!!parse-error (type => 'unclosed DOCTYPE'); |
1899 |
wakaba |
1.57 |
$self->{state} = DATA_STATE; |
1900 |
wakaba |
1.1 |
## reconsume |
1901 |
|
|
|
1902 |
|
|
!!!emit ($self->{current_token}); # DOCTYPE |
1903 |
|
|
|
1904 |
|
|
redo A; |
1905 |
|
|
} else { |
1906 |
|
|
## Stay in the state |
1907 |
|
|
!!!next-input-character; |
1908 |
|
|
redo A; |
1909 |
|
|
} |
1910 |
|
|
} else { |
1911 |
|
|
die "$0: $self->{state}: Unknown state"; |
1912 |
|
|
} |
1913 |
|
|
} # A |
1914 |
|
|
|
1915 |
|
|
die "$0: _get_next_token: unexpected case"; |
1916 |
|
|
} # _get_next_token |
1917 |
|
|
|
1918 |
wakaba |
1.72 |
sub _tokenize_attempt_to_consume_an_entity ($$$) { |
1919 |
|
|
my ($self, $in_attr, $additional) = @_; |
1920 |
wakaba |
1.20 |
|
1921 |
|
|
if ({ |
1922 |
|
|
0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF, |
1923 |
|
|
0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR |
1924 |
wakaba |
1.72 |
$additional => 1, |
1925 |
wakaba |
1.20 |
}->{$self->{next_input_character}}) { |
1926 |
|
|
## Don't consume |
1927 |
|
|
## No error |
1928 |
|
|
return undef; |
1929 |
|
|
} elsif ($self->{next_input_character} == 0x0023) { # # |
1930 |
wakaba |
1.1 |
!!!next-input-character; |
1931 |
|
|
if ($self->{next_input_character} == 0x0078 or # x |
1932 |
|
|
$self->{next_input_character} == 0x0058) { # X |
1933 |
wakaba |
1.26 |
my $code; |
1934 |
wakaba |
1.1 |
X: { |
1935 |
|
|
my $x_char = $self->{next_input_character}; |
1936 |
|
|
!!!next-input-character; |
1937 |
|
|
if (0x0030 <= $self->{next_input_character} and |
1938 |
|
|
$self->{next_input_character} <= 0x0039) { # 0..9 |
1939 |
wakaba |
1.26 |
$code ||= 0; |
1940 |
|
|
$code *= 0x10; |
1941 |
|
|
$code += $self->{next_input_character} - 0x0030; |
1942 |
wakaba |
1.1 |
redo X; |
1943 |
|
|
} elsif (0x0061 <= $self->{next_input_character} and |
1944 |
|
|
$self->{next_input_character} <= 0x0066) { # a..f |
1945 |
wakaba |
1.26 |
$code ||= 0; |
1946 |
|
|
$code *= 0x10; |
1947 |
|
|
$code += $self->{next_input_character} - 0x0060 + 9; |
1948 |
wakaba |
1.1 |
redo X; |
1949 |
|
|
} elsif (0x0041 <= $self->{next_input_character} and |
1950 |
|
|
$self->{next_input_character} <= 0x0046) { # A..F |
1951 |
wakaba |
1.26 |
$code ||= 0; |
1952 |
|
|
$code *= 0x10; |
1953 |
|
|
$code += $self->{next_input_character} - 0x0040 + 9; |
1954 |
wakaba |
1.1 |
redo X; |
1955 |
wakaba |
1.26 |
} elsif (not defined $code) { # no hexadecimal digit |
1956 |
wakaba |
1.3 |
!!!parse-error (type => 'bare hcro'); |
1957 |
wakaba |
1.37 |
!!!back-next-input-character ($x_char, $self->{next_input_character}); |
1958 |
wakaba |
1.1 |
$self->{next_input_character} = 0x0023; # # |
1959 |
|
|
return undef; |
1960 |
|
|
} elsif ($self->{next_input_character} == 0x003B) { # ; |
1961 |
|
|
!!!next-input-character; |
1962 |
|
|
} else { |
1963 |
wakaba |
1.3 |
!!!parse-error (type => 'no refc'); |
1964 |
wakaba |
1.1 |
} |
1965 |
|
|
|
1966 |
wakaba |
1.26 |
if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) { |
1967 |
|
|
!!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code); |
1968 |
|
|
$code = 0xFFFD; |
1969 |
|
|
} elsif ($code > 0x10FFFF) { |
1970 |
|
|
!!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code); |
1971 |
|
|
$code = 0xFFFD; |
1972 |
|
|
} elsif ($code == 0x000D) { |
1973 |
|
|
!!!parse-error (type => 'CR character reference'); |
1974 |
|
|
$code = 0x000A; |
1975 |
|
|
} elsif (0x80 <= $code and $code <= 0x9F) { |
1976 |
wakaba |
1.30 |
!!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code); |
1977 |
wakaba |
1.26 |
$code = $c1_entity_char->{$code}; |
1978 |
wakaba |
1.1 |
} |
1979 |
|
|
|
1980 |
wakaba |
1.66 |
return {type => CHARACTER_TOKEN, data => chr $code, |
1981 |
|
|
has_reference => 1}; |
1982 |
wakaba |
1.1 |
} # X |
1983 |
|
|
} elsif (0x0030 <= $self->{next_input_character} and |
1984 |
|
|
$self->{next_input_character} <= 0x0039) { # 0..9 |
1985 |
|
|
my $code = $self->{next_input_character} - 0x0030; |
1986 |
|
|
!!!next-input-character; |
1987 |
|
|
|
1988 |
|
|
while (0x0030 <= $self->{next_input_character} and |
1989 |
|
|
$self->{next_input_character} <= 0x0039) { # 0..9 |
1990 |
|
|
$code *= 10; |
1991 |
|
|
$code += $self->{next_input_character} - 0x0030; |
1992 |
|
|
|
1993 |
|
|
!!!next-input-character; |
1994 |
|
|
} |
1995 |
|
|
|
1996 |
|
|
if ($self->{next_input_character} == 0x003B) { # ; |
1997 |
|
|
!!!next-input-character; |
1998 |
|
|
} else { |
1999 |
wakaba |
1.3 |
!!!parse-error (type => 'no refc'); |
2000 |
wakaba |
1.1 |
} |
2001 |
|
|
|
2002 |
wakaba |
1.26 |
if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) { |
2003 |
|
|
!!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code); |
2004 |
|
|
$code = 0xFFFD; |
2005 |
|
|
} elsif ($code > 0x10FFFF) { |
2006 |
|
|
!!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code); |
2007 |
|
|
$code = 0xFFFD; |
2008 |
|
|
} elsif ($code == 0x000D) { |
2009 |
|
|
!!!parse-error (type => 'CR character reference'); |
2010 |
|
|
$code = 0x000A; |
2011 |
wakaba |
1.4 |
} elsif (0x80 <= $code and $code <= 0x9F) { |
2012 |
wakaba |
1.30 |
!!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code); |
2013 |
wakaba |
1.4 |
$code = $c1_entity_char->{$code}; |
2014 |
wakaba |
1.1 |
} |
2015 |
|
|
|
2016 |
wakaba |
1.66 |
return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1}; |
2017 |
wakaba |
1.1 |
} else { |
2018 |
wakaba |
1.3 |
!!!parse-error (type => 'bare nero'); |
2019 |
wakaba |
1.1 |
!!!back-next-input-character ($self->{next_input_character}); |
2020 |
|
|
$self->{next_input_character} = 0x0023; # # |
2021 |
|
|
return undef; |
2022 |
|
|
} |
2023 |
|
|
} elsif ((0x0041 <= $self->{next_input_character} and |
2024 |
|
|
$self->{next_input_character} <= 0x005A) or |
2025 |
|
|
(0x0061 <= $self->{next_input_character} and |
2026 |
|
|
$self->{next_input_character} <= 0x007A)) { |
2027 |
|
|
my $entity_name = chr $self->{next_input_character}; |
2028 |
|
|
!!!next-input-character; |
2029 |
|
|
|
2030 |
|
|
my $value = $entity_name; |
2031 |
wakaba |
1.37 |
my $match = 0; |
2032 |
wakaba |
1.16 |
require Whatpm::_NamedEntityList; |
2033 |
|
|
our $EntityChar; |
2034 |
wakaba |
1.1 |
|
2035 |
|
|
while (length $entity_name < 10 and |
2036 |
|
|
## NOTE: Some number greater than the maximum length of entity name |
2037 |
wakaba |
1.16 |
((0x0041 <= $self->{next_input_character} and # a |
2038 |
|
|
$self->{next_input_character} <= 0x005A) or # x |
2039 |
|
|
(0x0061 <= $self->{next_input_character} and # a |
2040 |
|
|
$self->{next_input_character} <= 0x007A) or # z |
2041 |
|
|
(0x0030 <= $self->{next_input_character} and # 0 |
2042 |
|
|
$self->{next_input_character} <= 0x0039) or # 9 |
2043 |
|
|
$self->{next_input_character} == 0x003B)) { # ; |
2044 |
wakaba |
1.1 |
$entity_name .= chr $self->{next_input_character}; |
2045 |
wakaba |
1.16 |
if (defined $EntityChar->{$entity_name}) { |
2046 |
|
|
if ($self->{next_input_character} == 0x003B) { # ; |
2047 |
wakaba |
1.26 |
$value = $EntityChar->{$entity_name}; |
2048 |
wakaba |
1.16 |
$match = 1; |
2049 |
|
|
!!!next-input-character; |
2050 |
|
|
last; |
2051 |
wakaba |
1.37 |
} else { |
2052 |
wakaba |
1.26 |
$value = $EntityChar->{$entity_name}; |
2053 |
|
|
$match = -1; |
2054 |
wakaba |
1.37 |
!!!next-input-character; |
2055 |
wakaba |
1.16 |
} |
2056 |
wakaba |
1.1 |
} else { |
2057 |
|
|
$value .= chr $self->{next_input_character}; |
2058 |
wakaba |
1.37 |
$match *= 2; |
2059 |
|
|
!!!next-input-character; |
2060 |
wakaba |
1.1 |
} |
2061 |
|
|
} |
2062 |
|
|
|
2063 |
wakaba |
1.16 |
if ($match > 0) { |
2064 |
wakaba |
1.66 |
return {type => CHARACTER_TOKEN, data => $value, has_reference => 1}; |
2065 |
wakaba |
1.16 |
} elsif ($match < 0) { |
2066 |
wakaba |
1.30 |
!!!parse-error (type => 'no refc'); |
2067 |
wakaba |
1.37 |
if ($in_attr and $match < -1) { |
2068 |
wakaba |
1.55 |
return {type => CHARACTER_TOKEN, data => '&'.$entity_name}; |
2069 |
wakaba |
1.37 |
} else { |
2070 |
wakaba |
1.66 |
return {type => CHARACTER_TOKEN, data => $value, has_reference => 1}; |
2071 |
wakaba |
1.37 |
} |
2072 |
wakaba |
1.1 |
} else { |
2073 |
wakaba |
1.3 |
!!!parse-error (type => 'bare ero'); |
2074 |
wakaba |
1.66 |
## NOTE: "No characters are consumed" in the spec. |
2075 |
wakaba |
1.55 |
return {type => CHARACTER_TOKEN, data => '&'.$value}; |
2076 |
wakaba |
1.1 |
} |
2077 |
|
|
} else { |
2078 |
|
|
## no characters are consumed |
2079 |
wakaba |
1.3 |
!!!parse-error (type => 'bare ero'); |
2080 |
wakaba |
1.1 |
return undef; |
2081 |
|
|
} |
2082 |
|
|
} # _tokenize_attempt_to_consume_an_entity |
2083 |
|
|
|
2084 |
|
|
sub _initialize_tree_constructor ($) { |
2085 |
|
|
my $self = shift; |
2086 |
|
|
## NOTE: $self->{document} MUST be specified before this method is called |
2087 |
|
|
$self->{document}->strict_error_checking (0); |
2088 |
|
|
## TODO: Turn mutation events off # MUST |
2089 |
|
|
## TODO: Turn loose Document option (manakai extension) on |
2090 |
wakaba |
1.18 |
$self->{document}->manakai_is_html (1); # MUST |
2091 |
wakaba |
1.1 |
} # _initialize_tree_constructor |
2092 |
|
|
|
2093 |
|
|
sub _terminate_tree_constructor ($) { |
2094 |
|
|
my $self = shift; |
2095 |
|
|
$self->{document}->strict_error_checking (1); |
2096 |
|
|
## TODO: Turn mutation events on |
2097 |
|
|
} # _terminate_tree_constructor |
2098 |
|
|
|
2099 |
|
|
## ISSUE: Should append_child (for example) in script executed in tree construction stage fire mutation events? |
2100 |
|
|
|
2101 |
wakaba |
1.3 |
{ # tree construction stage |
2102 |
|
|
my $token; |
2103 |
|
|
|
2104 |
wakaba |
1.1 |
sub _construct_tree ($) { |
2105 |
|
|
my ($self) = @_; |
2106 |
|
|
|
2107 |
|
|
## When an interactive UA render the $self->{document} available |
2108 |
|
|
## to the user, or when it begin accepting user input, are |
2109 |
|
|
## not defined. |
2110 |
|
|
|
2111 |
|
|
## Append a character: collect it and all subsequent consecutive |
2112 |
|
|
## characters and insert one Text node whose data is concatenation |
2113 |
|
|
## of all those characters. # MUST |
2114 |
|
|
|
2115 |
|
|
!!!next-token; |
2116 |
|
|
|
2117 |
wakaba |
1.54 |
$self->{insertion_mode} = BEFORE_HEAD_IM; |
2118 |
wakaba |
1.3 |
undef $self->{form_element}; |
2119 |
|
|
undef $self->{head_element}; |
2120 |
|
|
$self->{open_elements} = []; |
2121 |
|
|
undef $self->{inner_html_node}; |
2122 |
|
|
|
2123 |
|
|
$self->_tree_construction_initial; # MUST |
2124 |
|
|
$self->_tree_construction_root_element; |
2125 |
|
|
$self->_tree_construction_main; |
2126 |
|
|
} # _construct_tree |
2127 |
|
|
|
2128 |
|
|
sub _tree_construction_initial ($) { |
2129 |
|
|
my $self = shift; |
2130 |
wakaba |
1.18 |
INITIAL: { |
2131 |
wakaba |
1.55 |
if ($token->{type} == DOCTYPE_TOKEN) { |
2132 |
wakaba |
1.18 |
## NOTE: Conformance checkers MAY, instead of reporting "not HTML5" |
2133 |
|
|
## error, switch to a conformance checking mode for another |
2134 |
|
|
## language. |
2135 |
|
|
my $doctype_name = $token->{name}; |
2136 |
|
|
$doctype_name = '' unless defined $doctype_name; |
2137 |
|
|
$doctype_name =~ tr/a-z/A-Z/; |
2138 |
|
|
if (not defined $token->{name} or # <!DOCTYPE> |
2139 |
|
|
defined $token->{public_identifier} or |
2140 |
|
|
defined $token->{system_identifier}) { |
2141 |
|
|
!!!parse-error (type => 'not HTML5'); |
2142 |
|
|
} elsif ($doctype_name ne 'HTML') { |
2143 |
|
|
## ISSUE: ASCII case-insensitive? (in fact it does not matter) |
2144 |
|
|
!!!parse-error (type => 'not HTML5'); |
2145 |
|
|
} |
2146 |
|
|
|
2147 |
|
|
my $doctype = $self->{document}->create_document_type_definition |
2148 |
|
|
($token->{name}); ## ISSUE: If name is missing (e.g. <!DOCTYPE>)? |
2149 |
|
|
$doctype->public_id ($token->{public_identifier}) |
2150 |
|
|
if defined $token->{public_identifier}; |
2151 |
|
|
$doctype->system_id ($token->{system_identifier}) |
2152 |
|
|
if defined $token->{system_identifier}; |
2153 |
|
|
## NOTE: Other DocumentType attributes are null or empty lists. |
2154 |
|
|
## ISSUE: internalSubset = null?? |
2155 |
|
|
$self->{document}->append_child ($doctype); |
2156 |
|
|
|
2157 |
|
|
if (not $token->{correct} or $doctype_name ne 'HTML') { |
2158 |
|
|
$self->{document}->manakai_compat_mode ('quirks'); |
2159 |
|
|
} elsif (defined $token->{public_identifier}) { |
2160 |
|
|
my $pubid = $token->{public_identifier}; |
2161 |
|
|
$pubid =~ tr/a-z/A-z/; |
2162 |
|
|
if ({ |
2163 |
|
|
"+//SILMARIL//DTD HTML PRO V0R11 19970101//EN" => 1, |
2164 |
|
|
"-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1, |
2165 |
|
|
"-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1, |
2166 |
|
|
"-//IETF//DTD HTML 2.0 LEVEL 1//EN" => 1, |
2167 |
|
|
"-//IETF//DTD HTML 2.0 LEVEL 2//EN" => 1, |
2168 |
|
|
"-//IETF//DTD HTML 2.0 STRICT LEVEL 1//EN" => 1, |
2169 |
|
|
"-//IETF//DTD HTML 2.0 STRICT LEVEL 2//EN" => 1, |
2170 |
|
|
"-//IETF//DTD HTML 2.0 STRICT//EN" => 1, |
2171 |
|
|
"-//IETF//DTD HTML 2.0//EN" => 1, |
2172 |
|
|
"-//IETF//DTD HTML 2.1E//EN" => 1, |
2173 |
|
|
"-//IETF//DTD HTML 3.0//EN" => 1, |
2174 |
|
|
"-//IETF//DTD HTML 3.0//EN//" => 1, |
2175 |
|
|
"-//IETF//DTD HTML 3.2 FINAL//EN" => 1, |
2176 |
|
|
"-//IETF//DTD HTML 3.2//EN" => 1, |
2177 |
|
|
"-//IETF//DTD HTML 3//EN" => 1, |
2178 |
|
|
"-//IETF//DTD HTML LEVEL 0//EN" => 1, |
2179 |
|
|
"-//IETF//DTD HTML LEVEL 0//EN//2.0" => 1, |
2180 |
|
|
"-//IETF//DTD HTML LEVEL 1//EN" => 1, |
2181 |
|
|
"-//IETF//DTD HTML LEVEL 1//EN//2.0" => 1, |
2182 |
|
|
"-//IETF//DTD HTML LEVEL 2//EN" => 1, |
2183 |
|
|
"-//IETF//DTD HTML LEVEL 2//EN//2.0" => 1, |
2184 |
|
|
"-//IETF//DTD HTML LEVEL 3//EN" => 1, |
2185 |
|
|
"-//IETF//DTD HTML LEVEL 3//EN//3.0" => 1, |
2186 |
|
|
"-//IETF//DTD HTML STRICT LEVEL 0//EN" => 1, |
2187 |
|
|
"-//IETF//DTD HTML STRICT LEVEL 0//EN//2.0" => 1, |
2188 |
|
|
"-//IETF//DTD HTML STRICT LEVEL 1//EN" => 1, |
2189 |
|
|
"-//IETF//DTD HTML STRICT LEVEL 1//EN//2.0" => 1, |
2190 |
|
|
"-//IETF//DTD HTML STRICT LEVEL 2//EN" => 1, |
2191 |
|
|
"-//IETF//DTD HTML STRICT LEVEL 2//EN//2.0" => 1, |
2192 |
|
|
"-//IETF//DTD HTML STRICT LEVEL 3//EN" => 1, |
2193 |
|
|
"-//IETF//DTD HTML STRICT LEVEL 3//EN//3.0" => 1, |
2194 |
|
|
"-//IETF//DTD HTML STRICT//EN" => 1, |
2195 |
|
|
"-//IETF//DTD HTML STRICT//EN//2.0" => 1, |
2196 |
|
|
"-//IETF//DTD HTML STRICT//EN//3.0" => 1, |
2197 |
|
|
"-//IETF//DTD HTML//EN" => 1, |
2198 |
|
|
"-//IETF//DTD HTML//EN//2.0" => 1, |
2199 |
|
|
"-//IETF//DTD HTML//EN//3.0" => 1, |
2200 |
|
|
"-//METRIUS//DTD METRIUS PRESENTATIONAL//EN" => 1, |
2201 |
|
|
"-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//EN" => 1, |
2202 |
|
|
"-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//EN" => 1, |
2203 |
|
|
"-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//EN" => 1, |
2204 |
|
|
"-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//EN" => 1, |
2205 |
|
|
"-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//EN" => 1, |
2206 |
|
|
"-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//EN" => 1, |
2207 |
|
|
"-//NETSCAPE COMM. CORP.//DTD HTML//EN" => 1, |
2208 |
|
|
"-//NETSCAPE COMM. CORP.//DTD STRICT HTML//EN" => 1, |
2209 |
|
|
"-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//EN" => 1, |
2210 |
|
|
"-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//EN" => 1, |
2211 |
wakaba |
1.72 |
"-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//EN" => 1, |
2212 |
|
|
"-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//EN" => 1, |
2213 |
|
|
"-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//EN" => 1, |
2214 |
wakaba |
1.18 |
"-//SPYGLASS//DTD HTML 2.0 EXTENDED//EN" => 1, |
2215 |
|
|
"-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//EN" => 1, |
2216 |
|
|
"-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//EN" => 1, |
2217 |
|
|
"-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//EN" => 1, |
2218 |
|
|
"-//W3C//DTD HTML 3 1995-03-24//EN" => 1, |
2219 |
|
|
"-//W3C//DTD HTML 3.2 DRAFT//EN" => 1, |
2220 |
|
|
"-//W3C//DTD HTML 3.2 FINAL//EN" => 1, |
2221 |
|
|
"-//W3C//DTD HTML 3.2//EN" => 1, |
2222 |
|
|
"-//W3C//DTD HTML 3.2S DRAFT//EN" => 1, |
2223 |
|
|
"-//W3C//DTD HTML 4.0 FRAMESET//EN" => 1, |
2224 |
|
|
"-//W3C//DTD HTML 4.0 TRANSITIONAL//EN" => 1, |
2225 |
|
|
"-//W3C//DTD HTML EXPERIMETNAL 19960712//EN" => 1, |
2226 |
|
|
"-//W3C//DTD HTML EXPERIMENTAL 970421//EN" => 1, |
2227 |
|
|
"-//W3C//DTD W3 HTML//EN" => 1, |
2228 |
|
|
"-//W3O//DTD W3 HTML 3.0//EN" => 1, |
2229 |
|
|
"-//W3O//DTD W3 HTML 3.0//EN//" => 1, |
2230 |
|
|
"-//W3O//DTD W3 HTML STRICT 3.0//EN//" => 1, |
2231 |
|
|
"-//WEBTECHS//DTD MOZILLA HTML 2.0//EN" => 1, |
2232 |
|
|
"-//WEBTECHS//DTD MOZILLA HTML//EN" => 1, |
2233 |
|
|
"-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" => 1, |
2234 |
|
|
"HTML" => 1, |
2235 |
|
|
}->{$pubid}) { |
2236 |
|
|
$self->{document}->manakai_compat_mode ('quirks'); |
2237 |
|
|
} elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or |
2238 |
|
|
$pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") { |
2239 |
|
|
if (defined $token->{system_identifier}) { |
2240 |
|
|
$self->{document}->manakai_compat_mode ('quirks'); |
2241 |
|
|
} else { |
2242 |
|
|
$self->{document}->manakai_compat_mode ('limited quirks'); |
2243 |
wakaba |
1.3 |
} |
2244 |
wakaba |
1.18 |
} elsif ($pubid eq "-//W3C//DTD XHTML 1.0 Frameset//EN" or |
2245 |
|
|
$pubid eq "-//W3C//DTD XHTML 1.0 Transitional//EN") { |
2246 |
|
|
$self->{document}->manakai_compat_mode ('limited quirks'); |
2247 |
|
|
} |
2248 |
|
|
} |
2249 |
|
|
if (defined $token->{system_identifier}) { |
2250 |
|
|
my $sysid = $token->{system_identifier}; |
2251 |
|
|
$sysid =~ tr/A-Z/a-z/; |
2252 |
|
|
if ($sysid eq "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") { |
2253 |
|
|
$self->{document}->manakai_compat_mode ('quirks'); |
2254 |
|
|
} |
2255 |
|
|
} |
2256 |
|
|
|
2257 |
|
|
## Go to the root element phase. |
2258 |
|
|
!!!next-token; |
2259 |
|
|
return; |
2260 |
|
|
} elsif ({ |
2261 |
wakaba |
1.55 |
START_TAG_TOKEN, 1, |
2262 |
|
|
END_TAG_TOKEN, 1, |
2263 |
|
|
END_OF_FILE_TOKEN, 1, |
2264 |
wakaba |
1.18 |
}->{$token->{type}}) { |
2265 |
|
|
!!!parse-error (type => 'no DOCTYPE'); |
2266 |
|
|
$self->{document}->manakai_compat_mode ('quirks'); |
2267 |
|
|
## Go to the root element phase |
2268 |
|
|
## reprocess |
2269 |
|
|
return; |
2270 |
wakaba |
1.55 |
} elsif ($token->{type} == CHARACTER_TOKEN) { |
2271 |
wakaba |
1.18 |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D |
2272 |
|
|
## Ignore the token |
2273 |
wakaba |
1.26 |
|
2274 |
wakaba |
1.18 |
unless (length $token->{data}) { |
2275 |
|
|
## Stay in the phase |
2276 |
|
|
!!!next-token; |
2277 |
|
|
redo INITIAL; |
2278 |
wakaba |
1.3 |
} |
2279 |
|
|
} |
2280 |
wakaba |
1.18 |
|
2281 |
|
|
!!!parse-error (type => 'no DOCTYPE'); |
2282 |
|
|
$self->{document}->manakai_compat_mode ('quirks'); |
2283 |
|
|
## Go to the root element phase |
2284 |
|
|
## reprocess |
2285 |
|
|
return; |
2286 |
wakaba |
1.55 |
} elsif ($token->{type} == COMMENT_TOKEN) { |
2287 |
wakaba |
1.18 |
my $comment = $self->{document}->create_comment ($token->{data}); |
2288 |
|
|
$self->{document}->append_child ($comment); |
2289 |
|
|
|
2290 |
|
|
## Stay in the phase. |
2291 |
|
|
!!!next-token; |
2292 |
|
|
redo INITIAL; |
2293 |
|
|
} else { |
2294 |
wakaba |
1.55 |
die "$0: $token->{type}: Unknown token type"; |
2295 |
wakaba |
1.18 |
} |
2296 |
|
|
} # INITIAL |
2297 |
wakaba |
1.3 |
} # _tree_construction_initial |
2298 |
|
|
|
2299 |
|
|
sub _tree_construction_root_element ($) { |
2300 |
|
|
my $self = shift; |
2301 |
|
|
|
2302 |
|
|
B: { |
2303 |
wakaba |
1.55 |
if ($token->{type} == DOCTYPE_TOKEN) { |
2304 |
wakaba |
1.3 |
!!!parse-error (type => 'in html:#DOCTYPE'); |
2305 |
|
|
## Ignore the token |
2306 |
|
|
## Stay in the phase |
2307 |
|
|
!!!next-token; |
2308 |
|
|
redo B; |
2309 |
wakaba |
1.55 |
} elsif ($token->{type} == COMMENT_TOKEN) { |
2310 |
wakaba |
1.3 |
my $comment = $self->{document}->create_comment ($token->{data}); |
2311 |
|
|
$self->{document}->append_child ($comment); |
2312 |
|
|
## Stay in the phase |
2313 |
|
|
!!!next-token; |
2314 |
|
|
redo B; |
2315 |
wakaba |
1.55 |
} elsif ($token->{type} == CHARACTER_TOKEN) { |
2316 |
wakaba |
1.26 |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D |
2317 |
|
|
## Ignore the token. |
2318 |
|
|
|
2319 |
wakaba |
1.3 |
unless (length $token->{data}) { |
2320 |
|
|
## Stay in the phase |
2321 |
|
|
!!!next-token; |
2322 |
|
|
redo B; |
2323 |
|
|
} |
2324 |
|
|
} |
2325 |
wakaba |
1.61 |
|
2326 |
|
|
$self->{application_cache_selection}->(undef); |
2327 |
|
|
|
2328 |
|
|
# |
2329 |
|
|
} elsif ($token->{type} == START_TAG_TOKEN) { |
2330 |
|
|
if ($token->{tag_name} eq 'html' and |
2331 |
wakaba |
1.67 |
$token->{attributes}->{manifest}) { |
2332 |
wakaba |
1.61 |
$self->{application_cache_selection} |
2333 |
|
|
->($token->{attributes}->{manifest}->{value}); |
2334 |
|
|
## ISSUE: No relative reference resolution? |
2335 |
|
|
} else { |
2336 |
|
|
$self->{application_cache_selection}->(undef); |
2337 |
|
|
} |
2338 |
|
|
|
2339 |
|
|
## ISSUE: There is an issue in the spec |
2340 |
wakaba |
1.3 |
# |
2341 |
|
|
} elsif ({ |
2342 |
wakaba |
1.55 |
END_TAG_TOKEN, 1, |
2343 |
|
|
END_OF_FILE_TOKEN, 1, |
2344 |
wakaba |
1.3 |
}->{$token->{type}}) { |
2345 |
wakaba |
1.61 |
$self->{application_cache_selection}->(undef); |
2346 |
|
|
|
2347 |
wakaba |
1.3 |
## ISSUE: There is an issue in the spec |
2348 |
|
|
# |
2349 |
|
|
} else { |
2350 |
wakaba |
1.55 |
die "$0: $token->{type}: Unknown token type"; |
2351 |
wakaba |
1.3 |
} |
2352 |
wakaba |
1.61 |
|
2353 |
wakaba |
1.3 |
my $root_element; !!!create-element ($root_element, 'html'); |
2354 |
|
|
$self->{document}->append_child ($root_element); |
2355 |
|
|
push @{$self->{open_elements}}, [$root_element, 'html']; |
2356 |
|
|
## reprocess |
2357 |
|
|
#redo B; |
2358 |
wakaba |
1.35 |
return; ## Go to the main phase. |
2359 |
wakaba |
1.3 |
} # B |
2360 |
|
|
} # _tree_construction_root_element |
2361 |
|
|
|
2362 |
|
|
sub _reset_insertion_mode ($) { |
2363 |
|
|
my $self = shift; |
2364 |
|
|
|
2365 |
|
|
## Step 1 |
2366 |
|
|
my $last; |
2367 |
|
|
|
2368 |
|
|
## Step 2 |
2369 |
|
|
my $i = -1; |
2370 |
|
|
my $node = $self->{open_elements}->[$i]; |
2371 |
|
|
|
2372 |
|
|
## Step 3 |
2373 |
|
|
S3: { |
2374 |
wakaba |
1.29 |
## ISSUE: Oops! "If node is the first node in the stack of open |
2375 |
|
|
## elements, then set last to true. If the context element of the |
2376 |
|
|
## HTML fragment parsing algorithm is neither a td element nor a |
2377 |
|
|
## th element, then set node to the context element. (fragment case)": |
2378 |
|
|
## The second "if" is in the scope of the first "if"!? |
2379 |
|
|
if ($self->{open_elements}->[0]->[0] eq $node->[0]) { |
2380 |
|
|
$last = 1; |
2381 |
|
|
if (defined $self->{inner_html_node}) { |
2382 |
|
|
if ($self->{inner_html_node}->[1] eq 'td' or |
2383 |
|
|
$self->{inner_html_node}->[1] eq 'th') { |
2384 |
|
|
# |
2385 |
|
|
} else { |
2386 |
|
|
$node = $self->{inner_html_node}; |
2387 |
|
|
} |
2388 |
wakaba |
1.3 |
} |
2389 |
|
|
} |
2390 |
|
|
|
2391 |
|
|
## Step 4..13 |
2392 |
|
|
my $new_mode = { |
2393 |
wakaba |
1.54 |
select => IN_SELECT_IM, |
2394 |
|
|
td => IN_CELL_IM, |
2395 |
|
|
th => IN_CELL_IM, |
2396 |
|
|
tr => IN_ROW_IM, |
2397 |
|
|
tbody => IN_TABLE_BODY_IM, |
2398 |
|
|
thead => IN_TABLE_BODY_IM, |
2399 |
|
|
tfoot => IN_TABLE_BODY_IM, |
2400 |
|
|
caption => IN_CAPTION_IM, |
2401 |
|
|
colgroup => IN_COLUMN_GROUP_IM, |
2402 |
|
|
table => IN_TABLE_IM, |
2403 |
|
|
head => IN_BODY_IM, # not in head! |
2404 |
|
|
body => IN_BODY_IM, |
2405 |
|
|
frameset => IN_FRAMESET_IM, |
2406 |
wakaba |
1.3 |
}->{$node->[1]}; |
2407 |
|
|
$self->{insertion_mode} = $new_mode and return if defined $new_mode; |
2408 |
|
|
|
2409 |
|
|
## Step 14 |
2410 |
|
|
if ($node->[1] eq 'html') { |
2411 |
|
|
unless (defined $self->{head_element}) { |
2412 |
wakaba |
1.54 |
$self->{insertion_mode} = BEFORE_HEAD_IM; |
2413 |
wakaba |
1.3 |
} else { |
2414 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_HEAD_IM; |
2415 |
wakaba |
1.3 |
} |
2416 |
|
|
return; |
2417 |
|
|
} |
2418 |
|
|
|
2419 |
|
|
## Step 15 |
2420 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_BODY_IM and return if $last; |
2421 |
wakaba |
1.3 |
|
2422 |
|
|
## Step 16 |
2423 |
|
|
$i--; |
2424 |
|
|
$node = $self->{open_elements}->[$i]; |
2425 |
|
|
|
2426 |
|
|
## Step 17 |
2427 |
|
|
redo S3; |
2428 |
|
|
} # S3 |
2429 |
|
|
} # _reset_insertion_mode |
2430 |
|
|
|
2431 |
|
|
sub _tree_construction_main ($) { |
2432 |
|
|
my $self = shift; |
2433 |
|
|
|
2434 |
wakaba |
1.1 |
my $active_formatting_elements = []; |
2435 |
|
|
|
2436 |
|
|
my $reconstruct_active_formatting_elements = sub { # MUST |
2437 |
|
|
my $insert = shift; |
2438 |
|
|
|
2439 |
|
|
## Step 1 |
2440 |
|
|
return unless @$active_formatting_elements; |
2441 |
|
|
|
2442 |
|
|
## Step 3 |
2443 |
|
|
my $i = -1; |
2444 |
|
|
my $entry = $active_formatting_elements->[$i]; |
2445 |
|
|
|
2446 |
|
|
## Step 2 |
2447 |
|
|
return if $entry->[0] eq '#marker'; |
2448 |
wakaba |
1.3 |
for (@{$self->{open_elements}}) { |
2449 |
wakaba |
1.1 |
if ($entry->[0] eq $_->[0]) { |
2450 |
|
|
return; |
2451 |
|
|
} |
2452 |
|
|
} |
2453 |
|
|
|
2454 |
|
|
S4: { |
2455 |
|
|
## Step 4 |
2456 |
|
|
last S4 if $active_formatting_elements->[0]->[0] eq $entry->[0]; |
2457 |
|
|
|
2458 |
|
|
## Step 5 |
2459 |
|
|
$i--; |
2460 |
|
|
$entry = $active_formatting_elements->[$i]; |
2461 |
|
|
|
2462 |
|
|
## Step 6 |
2463 |
|
|
if ($entry->[0] eq '#marker') { |
2464 |
|
|
# |
2465 |
|
|
} else { |
2466 |
|
|
my $in_open_elements; |
2467 |
wakaba |
1.3 |
OE: for (@{$self->{open_elements}}) { |
2468 |
wakaba |
1.1 |
if ($entry->[0] eq $_->[0]) { |
2469 |
|
|
$in_open_elements = 1; |
2470 |
|
|
last OE; |
2471 |
|
|
} |
2472 |
|
|
} |
2473 |
|
|
if ($in_open_elements) { |
2474 |
|
|
# |
2475 |
|
|
} else { |
2476 |
|
|
redo S4; |
2477 |
|
|
} |
2478 |
|
|
} |
2479 |
|
|
|
2480 |
|
|
## Step 7 |
2481 |
|
|
$i++; |
2482 |
|
|
$entry = $active_formatting_elements->[$i]; |
2483 |
|
|
} # S4 |
2484 |
|
|
|
2485 |
|
|
S7: { |
2486 |
|
|
## Step 8 |
2487 |
|
|
my $clone = [$entry->[0]->clone_node (0), $entry->[1]]; |
2488 |
|
|
|
2489 |
|
|
## Step 9 |
2490 |
|
|
$insert->($clone->[0]); |
2491 |
wakaba |
1.3 |
push @{$self->{open_elements}}, $clone; |
2492 |
wakaba |
1.1 |
|
2493 |
|
|
## Step 10 |
2494 |
wakaba |
1.3 |
$active_formatting_elements->[$i] = $self->{open_elements}->[-1]; |
2495 |
wakaba |
1.1 |
|
2496 |
|
|
## Step 11 |
2497 |
|
|
unless ($clone->[0] eq $active_formatting_elements->[-1]->[0]) { |
2498 |
|
|
## Step 7' |
2499 |
|
|
$i++; |
2500 |
|
|
$entry = $active_formatting_elements->[$i]; |
2501 |
|
|
|
2502 |
|
|
redo S7; |
2503 |
|
|
} |
2504 |
|
|
} # S7 |
2505 |
|
|
}; # $reconstruct_active_formatting_elements |
2506 |
|
|
|
2507 |
|
|
my $clear_up_to_marker = sub { |
2508 |
|
|
for (reverse 0..$#$active_formatting_elements) { |
2509 |
|
|
if ($active_formatting_elements->[$_]->[0] eq '#marker') { |
2510 |
|
|
splice @$active_formatting_elements, $_; |
2511 |
|
|
return; |
2512 |
|
|
} |
2513 |
|
|
} |
2514 |
|
|
}; # $clear_up_to_marker |
2515 |
|
|
|
2516 |
wakaba |
1.25 |
my $parse_rcdata = sub ($$) { |
2517 |
|
|
my ($content_model_flag, $insert) = @_; |
2518 |
|
|
|
2519 |
|
|
## Step 1 |
2520 |
|
|
my $start_tag_name = $token->{tag_name}; |
2521 |
|
|
my $el; |
2522 |
|
|
!!!create-element ($el, $start_tag_name, $token->{attributes}); |
2523 |
|
|
|
2524 |
|
|
## Step 2 |
2525 |
|
|
$insert->($el); # /context node/->append_child ($el) |
2526 |
|
|
|
2527 |
|
|
## Step 3 |
2528 |
wakaba |
1.40 |
$self->{content_model} = $content_model_flag; # CDATA or RCDATA |
2529 |
wakaba |
1.13 |
delete $self->{escape}; # MUST |
2530 |
wakaba |
1.25 |
|
2531 |
|
|
## Step 4 |
2532 |
wakaba |
1.1 |
my $text = ''; |
2533 |
|
|
!!!next-token; |
2534 |
wakaba |
1.55 |
while ($token->{type} == CHARACTER_TOKEN) { # or until stop tokenizing |
2535 |
wakaba |
1.1 |
$text .= $token->{data}; |
2536 |
|
|
!!!next-token; |
2537 |
wakaba |
1.25 |
} |
2538 |
|
|
|
2539 |
|
|
## Step 5 |
2540 |
wakaba |
1.1 |
if (length $text) { |
2541 |
wakaba |
1.25 |
my $text = $self->{document}->create_text_node ($text); |
2542 |
|
|
$el->append_child ($text); |
2543 |
wakaba |
1.1 |
} |
2544 |
wakaba |
1.25 |
|
2545 |
|
|
## Step 6 |
2546 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; |
2547 |
wakaba |
1.25 |
|
2548 |
|
|
## Step 7 |
2549 |
wakaba |
1.55 |
if ($token->{type} == END_TAG_TOKEN and $token->{tag_name} eq $start_tag_name) { |
2550 |
wakaba |
1.1 |
## Ignore the token |
2551 |
wakaba |
1.40 |
} elsif ($content_model_flag == CDATA_CONTENT_MODEL) { |
2552 |
|
|
!!!parse-error (type => 'in CDATA:#'.$token->{type}); |
2553 |
|
|
} elsif ($content_model_flag == RCDATA_CONTENT_MODEL) { |
2554 |
|
|
!!!parse-error (type => 'in RCDATA:#'.$token->{type}); |
2555 |
wakaba |
1.1 |
} else { |
2556 |
wakaba |
1.40 |
die "$0: $content_model_flag in parse_rcdata"; |
2557 |
wakaba |
1.1 |
} |
2558 |
|
|
!!!next-token; |
2559 |
wakaba |
1.25 |
}; # $parse_rcdata |
2560 |
wakaba |
1.1 |
|
2561 |
wakaba |
1.25 |
my $script_start_tag = sub ($) { |
2562 |
|
|
my $insert = $_[0]; |
2563 |
wakaba |
1.1 |
my $script_el; |
2564 |
|
|
!!!create-element ($script_el, 'script', $token->{attributes}); |
2565 |
|
|
## TODO: mark as "parser-inserted" |
2566 |
|
|
|
2567 |
wakaba |
1.40 |
$self->{content_model} = CDATA_CONTENT_MODEL; |
2568 |
wakaba |
1.13 |
delete $self->{escape}; # MUST |
2569 |
wakaba |
1.1 |
|
2570 |
|
|
my $text = ''; |
2571 |
|
|
!!!next-token; |
2572 |
wakaba |
1.55 |
while ($token->{type} == CHARACTER_TOKEN) { |
2573 |
wakaba |
1.1 |
$text .= $token->{data}; |
2574 |
|
|
!!!next-token; |
2575 |
|
|
} # stop if non-character token or tokenizer stops tokenising |
2576 |
|
|
if (length $text) { |
2577 |
|
|
$script_el->manakai_append_text ($text); |
2578 |
|
|
} |
2579 |
|
|
|
2580 |
wakaba |
1.40 |
$self->{content_model} = PCDATA_CONTENT_MODEL; |
2581 |
wakaba |
1.1 |
|
2582 |
wakaba |
1.55 |
if ($token->{type} == END_TAG_TOKEN and |
2583 |
wakaba |
1.1 |
$token->{tag_name} eq 'script') { |
2584 |
|
|
## Ignore the token |
2585 |
|
|
} else { |
2586 |
wakaba |
1.3 |
!!!parse-error (type => 'in CDATA:#'.$token->{type}); |
2587 |
wakaba |
1.1 |
## ISSUE: And ignore? |
2588 |
|
|
## TODO: mark as "already executed" |
2589 |
|
|
} |
2590 |
|
|
|
2591 |
wakaba |
1.3 |
if (defined $self->{inner_html_node}) { |
2592 |
|
|
## TODO: mark as "already executed" |
2593 |
|
|
} else { |
2594 |
wakaba |
1.1 |
## TODO: $old_insertion_point = current insertion point |
2595 |
|
|
## TODO: insertion point = just before the next input character |
2596 |
wakaba |
1.25 |
|
2597 |
|
|
$insert->($script_el); |
2598 |
wakaba |
1.1 |
|
2599 |
|
|
## TODO: insertion point = $old_insertion_point (might be "undefined") |
2600 |
|
|
|
2601 |
|
|
## TODO: if there is a script that will execute as soon as the parser resume, then... |
2602 |
|
|
} |
2603 |
|
|
|
2604 |
|
|
!!!next-token; |
2605 |
|
|
}; # $script_start_tag |
2606 |
|
|
|
2607 |
|
|
my $formatting_end_tag = sub { |
2608 |
|
|
my $tag_name = shift; |
2609 |
|
|
|
2610 |
|
|
FET: { |
2611 |
|
|
## Step 1 |
2612 |
|
|
my $formatting_element; |
2613 |
|
|
my $formatting_element_i_in_active; |
2614 |
|
|
AFE: for (reverse 0..$#$active_formatting_elements) { |
2615 |
|
|
if ($active_formatting_elements->[$_]->[1] eq $tag_name) { |
2616 |
|
|
$formatting_element = $active_formatting_elements->[$_]; |
2617 |
|
|
$formatting_element_i_in_active = $_; |
2618 |
|
|
last AFE; |
2619 |
|
|
} elsif ($active_formatting_elements->[$_]->[0] eq '#marker') { |
2620 |
|
|
last AFE; |
2621 |
|
|
} |
2622 |
|
|
} # AFE |
2623 |
|
|
unless (defined $formatting_element) { |
2624 |
wakaba |
1.3 |
!!!parse-error (type => 'unmatched end tag:'.$tag_name); |
2625 |
wakaba |
1.1 |
## Ignore the token |
2626 |
|
|
!!!next-token; |
2627 |
|
|
return; |
2628 |
|
|
} |
2629 |
|
|
## has an element in scope |
2630 |
|
|
my $in_scope = 1; |
2631 |
|
|
my $formatting_element_i_in_open; |
2632 |
wakaba |
1.3 |
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
2633 |
|
|
my $node = $self->{open_elements}->[$_]; |
2634 |
wakaba |
1.1 |
if ($node->[0] eq $formatting_element->[0]) { |
2635 |
|
|
if ($in_scope) { |
2636 |
|
|
$formatting_element_i_in_open = $_; |
2637 |
|
|
last INSCOPE; |
2638 |
|
|
} else { # in open elements but not in scope |
2639 |
wakaba |
1.4 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
2640 |
wakaba |
1.1 |
## Ignore the token |
2641 |
|
|
!!!next-token; |
2642 |
|
|
return; |
2643 |
|
|
} |
2644 |
|
|
} elsif ({ |
2645 |
|
|
table => 1, caption => 1, td => 1, th => 1, |
2646 |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
2647 |
|
|
}->{$node->[1]}) { |
2648 |
|
|
$in_scope = 0; |
2649 |
|
|
} |
2650 |
|
|
} # INSCOPE |
2651 |
|
|
unless (defined $formatting_element_i_in_open) { |
2652 |
wakaba |
1.4 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
2653 |
wakaba |
1.1 |
pop @$active_formatting_elements; # $formatting_element |
2654 |
|
|
!!!next-token; ## TODO: ok? |
2655 |
|
|
return; |
2656 |
|
|
} |
2657 |
wakaba |
1.3 |
if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) { |
2658 |
wakaba |
1.4 |
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
2659 |
wakaba |
1.1 |
} |
2660 |
|
|
|
2661 |
|
|
## Step 2 |
2662 |
|
|
my $furthest_block; |
2663 |
|
|
my $furthest_block_i_in_open; |
2664 |
wakaba |
1.3 |
OE: for (reverse 0..$#{$self->{open_elements}}) { |
2665 |
|
|
my $node = $self->{open_elements}->[$_]; |
2666 |
wakaba |
1.1 |
if (not $formatting_category->{$node->[1]} and |
2667 |
|
|
#not $phrasing_category->{$node->[1]} and |
2668 |
|
|
($special_category->{$node->[1]} or |
2669 |
|
|
$scoping_category->{$node->[1]})) { |
2670 |
|
|
$furthest_block = $node; |
2671 |
|
|
$furthest_block_i_in_open = $_; |
2672 |
|
|
} elsif ($node->[0] eq $formatting_element->[0]) { |
2673 |
|
|
last OE; |
2674 |
|
|
} |
2675 |
|
|
} # OE |
2676 |
|
|
|
2677 |
|
|
## Step 3 |
2678 |
|
|
unless (defined $furthest_block) { # MUST |
2679 |
wakaba |
1.3 |
splice @{$self->{open_elements}}, $formatting_element_i_in_open; |
2680 |
wakaba |
1.1 |
splice @$active_formatting_elements, $formatting_element_i_in_active, 1; |
2681 |
|
|
!!!next-token; |
2682 |
|
|
return; |
2683 |
|
|
} |
2684 |
|
|
|
2685 |
|
|
## Step 4 |
2686 |
wakaba |
1.3 |
my $common_ancestor_node = $self->{open_elements}->[$formatting_element_i_in_open - 1]; |
2687 |
wakaba |
1.1 |
|
2688 |
|
|
## Step 5 |
2689 |
|
|
my $furthest_block_parent = $furthest_block->[0]->parent_node; |
2690 |
|
|
if (defined $furthest_block_parent) { |
2691 |
|
|
$furthest_block_parent->remove_child ($furthest_block->[0]); |
2692 |
|
|
} |
2693 |
|
|
|
2694 |
|
|
## Step 6 |
2695 |
|
|
my $bookmark_prev_el |
2696 |
|
|
= $active_formatting_elements->[$formatting_element_i_in_active - 1] |
2697 |
|
|
->[0]; |
2698 |
|
|
|
2699 |
|
|
## Step 7 |
2700 |
|
|
my $node = $furthest_block; |
2701 |
|
|
my $node_i_in_open = $furthest_block_i_in_open; |
2702 |
|
|
my $last_node = $furthest_block; |
2703 |
|
|
S7: { |
2704 |
|
|
## Step 1 |
2705 |
|
|
$node_i_in_open--; |
2706 |
wakaba |
1.3 |
$node = $self->{open_elements}->[$node_i_in_open]; |
2707 |
wakaba |
1.1 |
|
2708 |
|
|
## Step 2 |
2709 |
|
|
my $node_i_in_active; |
2710 |
|
|
S7S2: { |
2711 |
|
|
for (reverse 0..$#$active_formatting_elements) { |
2712 |
|
|
if ($active_formatting_elements->[$_]->[0] eq $node->[0]) { |
2713 |
|
|
$node_i_in_active = $_; |
2714 |
|
|
last S7S2; |
2715 |
|
|
} |
2716 |
|
|
} |
2717 |
wakaba |
1.3 |
splice @{$self->{open_elements}}, $node_i_in_open, 1; |
2718 |
wakaba |
1.1 |
redo S7; |
2719 |
|
|
} # S7S2 |
2720 |
|
|
|
2721 |
|
|
## Step 3 |
2722 |
|
|
last S7 if $node->[0] eq $formatting_element->[0]; |
2723 |
|
|
|
2724 |
|
|
## Step 4 |
2725 |
|
|
if ($last_node->[0] eq $furthest_block->[0]) { |
2726 |
|
|
$bookmark_prev_el = $node->[0]; |
2727 |
|
|
} |
2728 |
|
|
|
2729 |
|
|
## Step 5 |
2730 |
|
|
if ($node->[0]->has_child_nodes ()) { |
2731 |
|
|
my $clone = [$node->[0]->clone_node (0), $node->[1]]; |
2732 |
|
|
$active_formatting_elements->[$node_i_in_active] = $clone; |
2733 |
wakaba |
1.3 |
$self->{open_elements}->[$node_i_in_open] = $clone; |
2734 |
wakaba |
1.1 |
$node = $clone; |
2735 |
|
|
} |
2736 |
|
|
|
2737 |
|
|
## Step 6 |
2738 |
|
|
$node->[0]->append_child ($last_node->[0]); |
2739 |
|
|
|
2740 |
|
|
## Step 7 |
2741 |
|
|
$last_node = $node; |
2742 |
|
|
|
2743 |
|
|
## Step 8 |
2744 |
|
|
redo S7; |
2745 |
|
|
} # S7 |
2746 |
|
|
|
2747 |
|
|
## Step 8 |
2748 |
|
|
$common_ancestor_node->[0]->append_child ($last_node->[0]); |
2749 |
|
|
|
2750 |
|
|
## Step 9 |
2751 |
|
|
my $clone = [$formatting_element->[0]->clone_node (0), |
2752 |
|
|
$formatting_element->[1]]; |
2753 |
|
|
|
2754 |
|
|
## Step 10 |
2755 |
|
|
my @cn = @{$furthest_block->[0]->child_nodes}; |
2756 |
|
|
$clone->[0]->append_child ($_) for @cn; |
2757 |
|
|
|
2758 |
|
|
## Step 11 |
2759 |
|
|
$furthest_block->[0]->append_child ($clone->[0]); |
2760 |
|
|
|
2761 |
|
|
## Step 12 |
2762 |
|
|
my $i; |
2763 |
|
|
AFE: for (reverse 0..$#$active_formatting_elements) { |
2764 |
|
|
if ($active_formatting_elements->[$_]->[0] eq $formatting_element->[0]) { |
2765 |
|
|
splice @$active_formatting_elements, $_, 1; |
2766 |
|
|
$i-- and last AFE if defined $i; |
2767 |
|
|
} elsif ($active_formatting_elements->[$_]->[0] eq $bookmark_prev_el) { |
2768 |
|
|
$i = $_; |
2769 |
|
|
} |
2770 |
|
|
} # AFE |
2771 |
|
|
splice @$active_formatting_elements, $i + 1, 0, $clone; |
2772 |
|
|
|
2773 |
|
|
## Step 13 |
2774 |
|
|
undef $i; |
2775 |
wakaba |
1.3 |
OE: for (reverse 0..$#{$self->{open_elements}}) { |
2776 |
|
|
if ($self->{open_elements}->[$_]->[0] eq $formatting_element->[0]) { |
2777 |
|
|
splice @{$self->{open_elements}}, $_, 1; |
2778 |
wakaba |
1.1 |
$i-- and last OE if defined $i; |
2779 |
wakaba |
1.3 |
} elsif ($self->{open_elements}->[$_]->[0] eq $furthest_block->[0]) { |
2780 |
wakaba |
1.1 |
$i = $_; |
2781 |
|
|
} |
2782 |
|
|
} # OE |
2783 |
wakaba |
1.3 |
splice @{$self->{open_elements}}, $i + 1, 1, $clone; |
2784 |
wakaba |
1.1 |
|
2785 |
|
|
## Step 14 |
2786 |
|
|
redo FET; |
2787 |
|
|
} # FET |
2788 |
|
|
}; # $formatting_end_tag |
2789 |
|
|
|
2790 |
|
|
my $insert_to_current = sub { |
2791 |
wakaba |
1.25 |
$self->{open_elements}->[-1]->[0]->append_child ($_[0]); |
2792 |
wakaba |
1.1 |
}; # $insert_to_current |
2793 |
|
|
|
2794 |
|
|
my $insert_to_foster = sub { |
2795 |
|
|
my $child = shift; |
2796 |
|
|
if ({ |
2797 |
|
|
table => 1, tbody => 1, tfoot => 1, |
2798 |
|
|
thead => 1, tr => 1, |
2799 |
wakaba |
1.3 |
}->{$self->{open_elements}->[-1]->[1]}) { |
2800 |
wakaba |
1.1 |
# MUST |
2801 |
|
|
my $foster_parent_element; |
2802 |
|
|
my $next_sibling; |
2803 |
wakaba |
1.3 |
OE: for (reverse 0..$#{$self->{open_elements}}) { |
2804 |
|
|
if ($self->{open_elements}->[$_]->[1] eq 'table') { |
2805 |
|
|
my $parent = $self->{open_elements}->[$_]->[0]->parent_node; |
2806 |
wakaba |
1.1 |
if (defined $parent and $parent->node_type == 1) { |
2807 |
|
|
$foster_parent_element = $parent; |
2808 |
wakaba |
1.3 |
$next_sibling = $self->{open_elements}->[$_]->[0]; |
2809 |
wakaba |
1.1 |
} else { |
2810 |
|
|
$foster_parent_element |
2811 |
wakaba |
1.3 |
= $self->{open_elements}->[$_ - 1]->[0]; |
2812 |
wakaba |
1.1 |
} |
2813 |
|
|
last OE; |
2814 |
|
|
} |
2815 |
|
|
} # OE |
2816 |
wakaba |
1.3 |
$foster_parent_element = $self->{open_elements}->[0]->[0] |
2817 |
wakaba |
1.1 |
unless defined $foster_parent_element; |
2818 |
|
|
$foster_parent_element->insert_before |
2819 |
|
|
($child, $next_sibling); |
2820 |
|
|
} else { |
2821 |
wakaba |
1.3 |
$self->{open_elements}->[-1]->[0]->append_child ($child); |
2822 |
wakaba |
1.1 |
} |
2823 |
|
|
}; # $insert_to_foster |
2824 |
|
|
|
2825 |
wakaba |
1.52 |
my $insert; |
2826 |
wakaba |
1.34 |
|
2827 |
wakaba |
1.52 |
B: { |
2828 |
wakaba |
1.55 |
if ($token->{type} == DOCTYPE_TOKEN) { |
2829 |
wakaba |
1.52 |
!!!parse-error (type => 'DOCTYPE in the middle'); |
2830 |
|
|
## Ignore the token |
2831 |
|
|
## Stay in the phase |
2832 |
|
|
!!!next-token; |
2833 |
|
|
redo B; |
2834 |
wakaba |
1.55 |
} elsif ($token->{type} == END_OF_FILE_TOKEN) { |
2835 |
wakaba |
1.56 |
if ($self->{insertion_mode} & AFTER_HTML_IMS) { |
2836 |
wakaba |
1.52 |
# |
2837 |
|
|
} else { |
2838 |
|
|
## Generate implied end tags |
2839 |
|
|
if ({ |
2840 |
|
|
dd => 1, dt => 1, li => 1, p => 1, td => 1, th => 1, tr => 1, |
2841 |
|
|
tbody => 1, tfoot=> 1, thead => 1, |
2842 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
2843 |
|
|
!!!back-token; |
2844 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, tag_name => $self->{open_elements}->[-1]->[1]}; |
2845 |
wakaba |
1.52 |
redo B; |
2846 |
|
|
} |
2847 |
|
|
|
2848 |
|
|
if (@{$self->{open_elements}} > 2 or |
2849 |
|
|
(@{$self->{open_elements}} == 2 and $self->{open_elements}->[1]->[1] ne 'body')) { |
2850 |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
2851 |
|
|
} elsif (defined $self->{inner_html_node} and |
2852 |
|
|
@{$self->{open_elements}} > 1 and |
2853 |
|
|
$self->{open_elements}->[1]->[1] ne 'body') { |
2854 |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
2855 |
wakaba |
1.34 |
} |
2856 |
|
|
|
2857 |
wakaba |
1.52 |
## ISSUE: There is an issue in the spec. |
2858 |
|
|
} |
2859 |
|
|
|
2860 |
|
|
## Stop parsing |
2861 |
|
|
last B; |
2862 |
wakaba |
1.55 |
} elsif ($token->{type} == START_TAG_TOKEN and |
2863 |
wakaba |
1.52 |
$token->{tag_name} eq 'html') { |
2864 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) { |
2865 |
wakaba |
1.52 |
## Turn into the main phase |
2866 |
|
|
!!!parse-error (type => 'after html:html'); |
2867 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_BODY_IM; |
2868 |
|
|
} elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) { |
2869 |
wakaba |
1.52 |
## Turn into the main phase |
2870 |
|
|
!!!parse-error (type => 'after html:html'); |
2871 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_FRAMESET_IM; |
2872 |
wakaba |
1.52 |
} |
2873 |
|
|
|
2874 |
|
|
## ISSUE: "aa<html>" is not a parse error. |
2875 |
|
|
## ISSUE: "<html>" in fragment is not a parse error. |
2876 |
|
|
unless ($token->{first_start_tag}) { |
2877 |
|
|
!!!parse-error (type => 'not first start tag'); |
2878 |
|
|
} |
2879 |
|
|
my $top_el = $self->{open_elements}->[0]->[0]; |
2880 |
|
|
for my $attr_name (keys %{$token->{attributes}}) { |
2881 |
|
|
unless ($top_el->has_attribute_ns (undef, $attr_name)) { |
2882 |
|
|
$top_el->set_attribute_ns |
2883 |
|
|
(undef, [undef, $attr_name], |
2884 |
|
|
$token->{attributes}->{$attr_name}->{value}); |
2885 |
|
|
} |
2886 |
|
|
} |
2887 |
|
|
!!!next-token; |
2888 |
|
|
redo B; |
2889 |
wakaba |
1.55 |
} elsif ($token->{type} == COMMENT_TOKEN) { |
2890 |
wakaba |
1.52 |
my $comment = $self->{document}->create_comment ($token->{data}); |
2891 |
wakaba |
1.56 |
if ($self->{insertion_mode} & AFTER_HTML_IMS) { |
2892 |
wakaba |
1.52 |
$self->{document}->append_child ($comment); |
2893 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == AFTER_BODY_IM) { |
2894 |
wakaba |
1.52 |
$self->{open_elements}->[0]->[0]->append_child ($comment); |
2895 |
|
|
} else { |
2896 |
|
|
$self->{open_elements}->[-1]->[0]->append_child ($comment); |
2897 |
|
|
} |
2898 |
|
|
!!!next-token; |
2899 |
|
|
redo B; |
2900 |
wakaba |
1.56 |
} elsif ($self->{insertion_mode} & HEAD_IMS) { |
2901 |
wakaba |
1.55 |
if ($token->{type} == CHARACTER_TOKEN) { |
2902 |
wakaba |
1.52 |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { |
2903 |
|
|
$self->{open_elements}->[-1]->[0]->manakai_append_text ($1); |
2904 |
|
|
unless (length $token->{data}) { |
2905 |
|
|
!!!next-token; |
2906 |
|
|
redo B; |
2907 |
wakaba |
1.1 |
} |
2908 |
|
|
} |
2909 |
wakaba |
1.52 |
|
2910 |
wakaba |
1.54 |
if ($self->{insertion_mode} == BEFORE_HEAD_IM) { |
2911 |
wakaba |
1.52 |
## As if <head> |
2912 |
|
|
!!!create-element ($self->{head_element}, 'head'); |
2913 |
|
|
$self->{open_elements}->[-1]->[0]->append_child ($self->{head_element}); |
2914 |
|
|
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
2915 |
|
|
|
2916 |
|
|
## Reprocess in the "in head" insertion mode... |
2917 |
|
|
pop @{$self->{open_elements}}; |
2918 |
|
|
|
2919 |
|
|
## Reprocess in the "after head" insertion mode... |
2920 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
2921 |
wakaba |
1.52 |
## As if </noscript> |
2922 |
|
|
pop @{$self->{open_elements}}; |
2923 |
|
|
!!!parse-error (type => 'in noscript:#character'); |
2924 |
wakaba |
1.1 |
|
2925 |
wakaba |
1.52 |
## Reprocess in the "in head" insertion mode... |
2926 |
|
|
## As if </head> |
2927 |
|
|
pop @{$self->{open_elements}}; |
2928 |
|
|
|
2929 |
|
|
## Reprocess in the "after head" insertion mode... |
2930 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_HEAD_IM) { |
2931 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; |
2932 |
|
|
|
2933 |
|
|
## Reprocess in the "after head" insertion mode... |
2934 |
wakaba |
1.1 |
} |
2935 |
wakaba |
1.52 |
|
2936 |
|
|
## "after head" insertion mode |
2937 |
|
|
## As if <body> |
2938 |
|
|
!!!insert-element ('body'); |
2939 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_BODY_IM; |
2940 |
wakaba |
1.52 |
## reprocess |
2941 |
|
|
redo B; |
2942 |
wakaba |
1.55 |
} elsif ($token->{type} == START_TAG_TOKEN) { |
2943 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'head') { |
2944 |
wakaba |
1.54 |
if ($self->{insertion_mode} == BEFORE_HEAD_IM) { |
2945 |
wakaba |
1.52 |
!!!create-element ($self->{head_element}, $token->{tag_name}, $token->{attributes}); |
2946 |
|
|
$self->{open_elements}->[-1]->[0]->append_child ($self->{head_element}); |
2947 |
|
|
push @{$self->{open_elements}}, [$self->{head_element}, $token->{tag_name}]; |
2948 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_HEAD_IM; |
2949 |
wakaba |
1.52 |
!!!next-token; |
2950 |
|
|
redo B; |
2951 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == AFTER_HEAD_IM) { |
2952 |
|
|
# |
2953 |
|
|
} else { |
2954 |
wakaba |
1.52 |
!!!parse-error (type => 'in head:head'); # or in head noscript |
2955 |
|
|
## Ignore the token |
2956 |
|
|
!!!next-token; |
2957 |
|
|
redo B; |
2958 |
|
|
} |
2959 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) { |
2960 |
wakaba |
1.52 |
## As if <head> |
2961 |
|
|
!!!create-element ($self->{head_element}, 'head'); |
2962 |
|
|
$self->{open_elements}->[-1]->[0]->append_child ($self->{head_element}); |
2963 |
|
|
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
2964 |
|
|
|
2965 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_HEAD_IM; |
2966 |
wakaba |
1.52 |
## Reprocess in the "in head" insertion mode... |
2967 |
wakaba |
1.1 |
} |
2968 |
wakaba |
1.52 |
|
2969 |
wakaba |
1.49 |
if ($token->{tag_name} eq 'base') { |
2970 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
2971 |
wakaba |
1.49 |
## As if </noscript> |
2972 |
|
|
pop @{$self->{open_elements}}; |
2973 |
|
|
!!!parse-error (type => 'in noscript:base'); |
2974 |
|
|
|
2975 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_HEAD_IM; |
2976 |
wakaba |
1.49 |
## Reprocess in the "in head" insertion mode... |
2977 |
|
|
} |
2978 |
|
|
|
2979 |
|
|
## NOTE: There is a "as if in head" code clone. |
2980 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HEAD_IM) { |
2981 |
wakaba |
1.49 |
!!!parse-error (type => 'after head:'.$token->{tag_name}); |
2982 |
|
|
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
2983 |
|
|
} |
2984 |
|
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
2985 |
|
|
pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec. |
2986 |
|
|
pop @{$self->{open_elements}} |
2987 |
wakaba |
1.54 |
if $self->{insertion_mode} == AFTER_HEAD_IM; |
2988 |
wakaba |
1.49 |
!!!next-token; |
2989 |
|
|
redo B; |
2990 |
|
|
} elsif ($token->{tag_name} eq 'link') { |
2991 |
wakaba |
1.25 |
## NOTE: There is a "as if in head" code clone. |
2992 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HEAD_IM) { |
2993 |
wakaba |
1.25 |
!!!parse-error (type => 'after head:'.$token->{tag_name}); |
2994 |
|
|
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
2995 |
|
|
} |
2996 |
|
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
2997 |
|
|
pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec. |
2998 |
|
|
pop @{$self->{open_elements}} |
2999 |
wakaba |
1.54 |
if $self->{insertion_mode} == AFTER_HEAD_IM; |
3000 |
wakaba |
1.1 |
!!!next-token; |
3001 |
wakaba |
1.25 |
redo B; |
3002 |
wakaba |
1.34 |
} elsif ($token->{tag_name} eq 'meta') { |
3003 |
|
|
## NOTE: There is a "as if in head" code clone. |
3004 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HEAD_IM) { |
3005 |
wakaba |
1.34 |
!!!parse-error (type => 'after head:'.$token->{tag_name}); |
3006 |
|
|
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
3007 |
|
|
} |
3008 |
|
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
3009 |
wakaba |
1.66 |
my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec. |
3010 |
wakaba |
1.34 |
|
3011 |
|
|
unless ($self->{confident}) { |
3012 |
|
|
if ($token->{attributes}->{charset}) { ## TODO: And if supported |
3013 |
wakaba |
1.63 |
$self->{change_encoding} |
3014 |
|
|
->($self, $token->{attributes}->{charset}->{value}); |
3015 |
wakaba |
1.66 |
|
3016 |
|
|
$meta_el->[0]->get_attribute_node_ns (undef, 'charset') |
3017 |
|
|
->set_user_data (manakai_has_reference => |
3018 |
|
|
$token->{attributes}->{charset} |
3019 |
|
|
->{has_reference}); |
3020 |
wakaba |
1.63 |
} elsif ($token->{attributes}->{content}) { |
3021 |
wakaba |
1.35 |
## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition. |
3022 |
wakaba |
1.63 |
if ($token->{attributes}->{content}->{value} |
3023 |
wakaba |
1.70 |
=~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt] |
3024 |
|
|
[\x09-\x0D\x20]*= |
3025 |
wakaba |
1.34 |
[\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'| |
3026 |
|
|
([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) { |
3027 |
wakaba |
1.63 |
$self->{change_encoding} |
3028 |
|
|
->($self, defined $1 ? $1 : defined $2 ? $2 : $3); |
3029 |
wakaba |
1.68 |
$meta_el->[0]->get_attribute_node_ns (undef, 'content') |
3030 |
|
|
->set_user_data (manakai_has_reference => |
3031 |
|
|
$token->{attributes}->{content} |
3032 |
|
|
->{has_reference}); |
3033 |
wakaba |
1.63 |
} |
3034 |
wakaba |
1.34 |
} |
3035 |
wakaba |
1.66 |
} else { |
3036 |
|
|
if ($token->{attributes}->{charset}) { |
3037 |
|
|
$meta_el->[0]->get_attribute_node_ns (undef, 'charset') |
3038 |
|
|
->set_user_data (manakai_has_reference => |
3039 |
|
|
$token->{attributes}->{charset} |
3040 |
|
|
->{has_reference}); |
3041 |
|
|
} |
3042 |
wakaba |
1.68 |
if ($token->{attributes}->{content}) { |
3043 |
|
|
$meta_el->[0]->get_attribute_node_ns (undef, 'content') |
3044 |
|
|
->set_user_data (manakai_has_reference => |
3045 |
|
|
$token->{attributes}->{content} |
3046 |
|
|
->{has_reference}); |
3047 |
|
|
} |
3048 |
wakaba |
1.34 |
} |
3049 |
|
|
|
3050 |
|
|
pop @{$self->{open_elements}} |
3051 |
wakaba |
1.54 |
if $self->{insertion_mode} == AFTER_HEAD_IM; |
3052 |
wakaba |
1.34 |
!!!next-token; |
3053 |
|
|
redo B; |
3054 |
wakaba |
1.49 |
} elsif ($token->{tag_name} eq 'title') { |
3055 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
3056 |
wakaba |
1.49 |
## As if </noscript> |
3057 |
|
|
pop @{$self->{open_elements}}; |
3058 |
|
|
!!!parse-error (type => 'in noscript:title'); |
3059 |
|
|
|
3060 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_HEAD_IM; |
3061 |
wakaba |
1.49 |
## Reprocess in the "in head" insertion mode... |
3062 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == AFTER_HEAD_IM) { |
3063 |
wakaba |
1.25 |
!!!parse-error (type => 'after head:'.$token->{tag_name}); |
3064 |
|
|
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
3065 |
|
|
} |
3066 |
wakaba |
1.49 |
|
3067 |
|
|
## NOTE: There is a "as if in head" code clone. |
3068 |
wakaba |
1.31 |
my $parent = defined $self->{head_element} ? $self->{head_element} |
3069 |
|
|
: $self->{open_elements}->[-1]->[0]; |
3070 |
wakaba |
1.40 |
$parse_rcdata->(RCDATA_CONTENT_MODEL, |
3071 |
|
|
sub { $parent->append_child ($_[0]) }); |
3072 |
wakaba |
1.25 |
pop @{$self->{open_elements}} |
3073 |
wakaba |
1.54 |
if $self->{insertion_mode} == AFTER_HEAD_IM; |
3074 |
wakaba |
1.25 |
redo B; |
3075 |
|
|
} elsif ($token->{tag_name} eq 'style') { |
3076 |
|
|
## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and |
3077 |
wakaba |
1.54 |
## insertion mode IN_HEAD_IM) |
3078 |
wakaba |
1.25 |
## NOTE: There is a "as if in head" code clone. |
3079 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HEAD_IM) { |
3080 |
wakaba |
1.25 |
!!!parse-error (type => 'after head:'.$token->{tag_name}); |
3081 |
|
|
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
3082 |
|
|
} |
3083 |
wakaba |
1.40 |
$parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current); |
3084 |
wakaba |
1.25 |
pop @{$self->{open_elements}} |
3085 |
wakaba |
1.54 |
if $self->{insertion_mode} == AFTER_HEAD_IM; |
3086 |
wakaba |
1.25 |
redo B; |
3087 |
|
|
} elsif ($token->{tag_name} eq 'noscript') { |
3088 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_HEAD_IM) { |
3089 |
wakaba |
1.25 |
## NOTE: and scripting is disalbed |
3090 |
|
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
3091 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_HEAD_NOSCRIPT_IM; |
3092 |
wakaba |
1.1 |
!!!next-token; |
3093 |
wakaba |
1.25 |
redo B; |
3094 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
3095 |
wakaba |
1.30 |
!!!parse-error (type => 'in noscript:noscript'); |
3096 |
wakaba |
1.1 |
## Ignore the token |
3097 |
wakaba |
1.41 |
!!!next-token; |
3098 |
wakaba |
1.25 |
redo B; |
3099 |
wakaba |
1.1 |
} else { |
3100 |
wakaba |
1.25 |
# |
3101 |
wakaba |
1.1 |
} |
3102 |
wakaba |
1.49 |
} elsif ($token->{tag_name} eq 'script') { |
3103 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
3104 |
wakaba |
1.49 |
## As if </noscript> |
3105 |
|
|
pop @{$self->{open_elements}}; |
3106 |
|
|
!!!parse-error (type => 'in noscript:script'); |
3107 |
|
|
|
3108 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_HEAD_IM; |
3109 |
wakaba |
1.49 |
## Reprocess in the "in head" insertion mode... |
3110 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == AFTER_HEAD_IM) { |
3111 |
wakaba |
1.25 |
!!!parse-error (type => 'after head:'.$token->{tag_name}); |
3112 |
|
|
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
3113 |
|
|
} |
3114 |
wakaba |
1.49 |
|
3115 |
wakaba |
1.25 |
## NOTE: There is a "as if in head" code clone. |
3116 |
|
|
$script_start_tag->($insert_to_current); |
3117 |
|
|
pop @{$self->{open_elements}} |
3118 |
wakaba |
1.54 |
if $self->{insertion_mode} == AFTER_HEAD_IM; |
3119 |
wakaba |
1.1 |
redo B; |
3120 |
wakaba |
1.49 |
} elsif ($token->{tag_name} eq 'body' or |
3121 |
wakaba |
1.25 |
$token->{tag_name} eq 'frameset') { |
3122 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
3123 |
wakaba |
1.49 |
## As if </noscript> |
3124 |
|
|
pop @{$self->{open_elements}}; |
3125 |
|
|
!!!parse-error (type => 'in noscript:'.$token->{tag_name}); |
3126 |
|
|
|
3127 |
|
|
## Reprocess in the "in head" insertion mode... |
3128 |
|
|
## As if </head> |
3129 |
|
|
pop @{$self->{open_elements}}; |
3130 |
|
|
|
3131 |
|
|
## Reprocess in the "after head" insertion mode... |
3132 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_HEAD_IM) { |
3133 |
wakaba |
1.49 |
pop @{$self->{open_elements}}; |
3134 |
|
|
|
3135 |
|
|
## Reprocess in the "after head" insertion mode... |
3136 |
|
|
} |
3137 |
|
|
|
3138 |
|
|
## "after head" insertion mode |
3139 |
|
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
3140 |
wakaba |
1.54 |
if ($token->{tag_name} eq 'body') { |
3141 |
|
|
$self->{insertion_mode} = IN_BODY_IM; |
3142 |
|
|
} elsif ($token->{tag_name} eq 'frameset') { |
3143 |
|
|
$self->{insertion_mode} = IN_FRAMESET_IM; |
3144 |
|
|
} else { |
3145 |
|
|
die "$0: tag name: $self->{tag_name}"; |
3146 |
|
|
} |
3147 |
wakaba |
1.1 |
!!!next-token; |
3148 |
|
|
redo B; |
3149 |
|
|
} else { |
3150 |
|
|
# |
3151 |
|
|
} |
3152 |
wakaba |
1.49 |
|
3153 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
3154 |
wakaba |
1.49 |
## As if </noscript> |
3155 |
|
|
pop @{$self->{open_elements}}; |
3156 |
|
|
!!!parse-error (type => 'in noscript:/'.$token->{tag_name}); |
3157 |
|
|
|
3158 |
|
|
## Reprocess in the "in head" insertion mode... |
3159 |
|
|
## As if </head> |
3160 |
wakaba |
1.25 |
pop @{$self->{open_elements}}; |
3161 |
wakaba |
1.49 |
|
3162 |
|
|
## Reprocess in the "after head" insertion mode... |
3163 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_HEAD_IM) { |
3164 |
wakaba |
1.49 |
## As if </head> |
3165 |
wakaba |
1.25 |
pop @{$self->{open_elements}}; |
3166 |
wakaba |
1.49 |
|
3167 |
|
|
## Reprocess in the "after head" insertion mode... |
3168 |
|
|
} |
3169 |
|
|
|
3170 |
|
|
## "after head" insertion mode |
3171 |
|
|
## As if <body> |
3172 |
|
|
!!!insert-element ('body'); |
3173 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_BODY_IM; |
3174 |
wakaba |
1.49 |
## reprocess |
3175 |
|
|
redo B; |
3176 |
wakaba |
1.55 |
} elsif ($token->{type} == END_TAG_TOKEN) { |
3177 |
wakaba |
1.49 |
if ($token->{tag_name} eq 'head') { |
3178 |
wakaba |
1.54 |
if ($self->{insertion_mode} == BEFORE_HEAD_IM) { |
3179 |
wakaba |
1.50 |
## As if <head> |
3180 |
|
|
!!!create-element ($self->{head_element}, 'head'); |
3181 |
|
|
$self->{open_elements}->[-1]->[0]->append_child ($self->{head_element}); |
3182 |
|
|
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
3183 |
|
|
|
3184 |
|
|
## Reprocess in the "in head" insertion mode... |
3185 |
|
|
pop @{$self->{open_elements}}; |
3186 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_HEAD_IM; |
3187 |
wakaba |
1.50 |
!!!next-token; |
3188 |
|
|
redo B; |
3189 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
3190 |
wakaba |
1.49 |
## As if </noscript> |
3191 |
|
|
pop @{$self->{open_elements}}; |
3192 |
|
|
!!!parse-error (type => 'in noscript:script'); |
3193 |
|
|
|
3194 |
|
|
## Reprocess in the "in head" insertion mode... |
3195 |
wakaba |
1.50 |
pop @{$self->{open_elements}}; |
3196 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_HEAD_IM; |
3197 |
wakaba |
1.50 |
!!!next-token; |
3198 |
|
|
redo B; |
3199 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_HEAD_IM) { |
3200 |
wakaba |
1.49 |
pop @{$self->{open_elements}}; |
3201 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_HEAD_IM; |
3202 |
wakaba |
1.49 |
!!!next-token; |
3203 |
|
|
redo B; |
3204 |
|
|
} else { |
3205 |
|
|
# |
3206 |
|
|
} |
3207 |
|
|
} elsif ($token->{tag_name} eq 'noscript') { |
3208 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
3209 |
wakaba |
1.49 |
pop @{$self->{open_elements}}; |
3210 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_HEAD_IM; |
3211 |
wakaba |
1.49 |
!!!next-token; |
3212 |
|
|
redo B; |
3213 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) { |
3214 |
wakaba |
1.50 |
!!!parse-error (type => 'unmatched end tag:noscript'); |
3215 |
|
|
## Ignore the token ## ISSUE: An issue in the spec. |
3216 |
|
|
!!!next-token; |
3217 |
|
|
redo B; |
3218 |
wakaba |
1.49 |
} else { |
3219 |
|
|
# |
3220 |
|
|
} |
3221 |
|
|
} elsif ({ |
3222 |
wakaba |
1.31 |
body => 1, html => 1, |
3223 |
|
|
}->{$token->{tag_name}}) { |
3224 |
wakaba |
1.54 |
if ($self->{insertion_mode} == BEFORE_HEAD_IM) { |
3225 |
wakaba |
1.50 |
## As if <head> |
3226 |
|
|
!!!create-element ($self->{head_element}, 'head'); |
3227 |
|
|
$self->{open_elements}->[-1]->[0]->append_child ($self->{head_element}); |
3228 |
|
|
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
3229 |
|
|
|
3230 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_HEAD_IM; |
3231 |
wakaba |
1.50 |
## Reprocess in the "in head" insertion mode... |
3232 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
3233 |
wakaba |
1.49 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
3234 |
|
|
## Ignore the token |
3235 |
|
|
!!!next-token; |
3236 |
|
|
redo B; |
3237 |
|
|
} |
3238 |
wakaba |
1.50 |
|
3239 |
|
|
# |
3240 |
wakaba |
1.49 |
} elsif ({ |
3241 |
wakaba |
1.31 |
p => 1, br => 1, |
3242 |
|
|
}->{$token->{tag_name}}) { |
3243 |
wakaba |
1.54 |
if ($self->{insertion_mode} == BEFORE_HEAD_IM) { |
3244 |
wakaba |
1.50 |
## As if <head> |
3245 |
|
|
!!!create-element ($self->{head_element}, 'head'); |
3246 |
|
|
$self->{open_elements}->[-1]->[0]->append_child ($self->{head_element}); |
3247 |
|
|
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
3248 |
|
|
|
3249 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_HEAD_IM; |
3250 |
wakaba |
1.50 |
## Reprocess in the "in head" insertion mode... |
3251 |
|
|
} |
3252 |
|
|
|
3253 |
wakaba |
1.1 |
# |
3254 |
wakaba |
1.25 |
} else { |
3255 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HEAD_IM) { |
3256 |
|
|
# |
3257 |
|
|
} else { |
3258 |
wakaba |
1.49 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
3259 |
|
|
## Ignore the token |
3260 |
|
|
!!!next-token; |
3261 |
|
|
redo B; |
3262 |
|
|
} |
3263 |
|
|
} |
3264 |
|
|
|
3265 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) { |
3266 |
wakaba |
1.49 |
## As if </noscript> |
3267 |
|
|
pop @{$self->{open_elements}}; |
3268 |
|
|
!!!parse-error (type => 'in noscript:/'.$token->{tag_name}); |
3269 |
|
|
|
3270 |
|
|
## Reprocess in the "in head" insertion mode... |
3271 |
|
|
## As if </head> |
3272 |
|
|
pop @{$self->{open_elements}}; |
3273 |
|
|
|
3274 |
|
|
## Reprocess in the "after head" insertion mode... |
3275 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_HEAD_IM) { |
3276 |
wakaba |
1.49 |
## As if </head> |
3277 |
|
|
pop @{$self->{open_elements}}; |
3278 |
|
|
|
3279 |
|
|
## Reprocess in the "after head" insertion mode... |
3280 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) { |
3281 |
wakaba |
1.50 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
3282 |
|
|
## Ignore the token ## ISSUE: An issue in the spec. |
3283 |
|
|
!!!next-token; |
3284 |
|
|
redo B; |
3285 |
wakaba |
1.1 |
} |
3286 |
|
|
|
3287 |
wakaba |
1.49 |
## "after head" insertion mode |
3288 |
|
|
## As if <body> |
3289 |
wakaba |
1.52 |
!!!insert-element ('body'); |
3290 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_BODY_IM; |
3291 |
wakaba |
1.52 |
## reprocess |
3292 |
|
|
redo B; |
3293 |
|
|
} else { |
3294 |
|
|
die "$0: $token->{type}: Unknown token type"; |
3295 |
|
|
} |
3296 |
|
|
|
3297 |
|
|
## ISSUE: An issue in the spec. |
3298 |
wakaba |
1.56 |
} elsif ($self->{insertion_mode} & BODY_IMS) { |
3299 |
wakaba |
1.55 |
if ($token->{type} == CHARACTER_TOKEN) { |
3300 |
wakaba |
1.52 |
## NOTE: There is a code clone of "character in body". |
3301 |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
3302 |
|
|
|
3303 |
|
|
$self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data}); |
3304 |
|
|
|
3305 |
|
|
!!!next-token; |
3306 |
|
|
redo B; |
3307 |
wakaba |
1.55 |
} elsif ($token->{type} == START_TAG_TOKEN) { |
3308 |
wakaba |
1.52 |
if ({ |
3309 |
|
|
caption => 1, col => 1, colgroup => 1, tbody => 1, |
3310 |
|
|
td => 1, tfoot => 1, th => 1, thead => 1, tr => 1, |
3311 |
|
|
}->{$token->{tag_name}}) { |
3312 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_CELL_IM) { |
3313 |
wakaba |
1.52 |
## have an element in table scope |
3314 |
|
|
my $tn; |
3315 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
3316 |
|
|
my $node = $self->{open_elements}->[$_]; |
3317 |
|
|
if ($node->[1] eq 'td' or $node->[1] eq 'th') { |
3318 |
|
|
$tn = $node->[1]; |
3319 |
|
|
last INSCOPE; |
3320 |
|
|
} elsif ({ |
3321 |
|
|
table => 1, html => 1, |
3322 |
|
|
}->{$node->[1]}) { |
3323 |
|
|
last INSCOPE; |
3324 |
|
|
} |
3325 |
|
|
} # INSCOPE |
3326 |
|
|
unless (defined $tn) { |
3327 |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
3328 |
|
|
## Ignore the token |
3329 |
|
|
!!!next-token; |
3330 |
|
|
redo B; |
3331 |
|
|
} |
3332 |
|
|
|
3333 |
|
|
## Close the cell |
3334 |
|
|
!!!back-token; # <?> |
3335 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, tag_name => $tn}; |
3336 |
wakaba |
1.52 |
redo B; |
3337 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_CAPTION_IM) { |
3338 |
wakaba |
1.52 |
!!!parse-error (type => 'not closed:caption'); |
3339 |
|
|
|
3340 |
|
|
## As if </caption> |
3341 |
|
|
## have a table element in table scope |
3342 |
|
|
my $i; |
3343 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
3344 |
|
|
my $node = $self->{open_elements}->[$_]; |
3345 |
|
|
if ($node->[1] eq 'caption') { |
3346 |
|
|
$i = $_; |
3347 |
|
|
last INSCOPE; |
3348 |
|
|
} elsif ({ |
3349 |
|
|
table => 1, html => 1, |
3350 |
|
|
}->{$node->[1]}) { |
3351 |
|
|
last INSCOPE; |
3352 |
|
|
} |
3353 |
|
|
} # INSCOPE |
3354 |
|
|
unless (defined $i) { |
3355 |
|
|
!!!parse-error (type => 'unmatched end tag:caption'); |
3356 |
|
|
## Ignore the token |
3357 |
|
|
!!!next-token; |
3358 |
|
|
redo B; |
3359 |
|
|
} |
3360 |
|
|
|
3361 |
|
|
## generate implied end tags |
3362 |
|
|
if ({ |
3363 |
|
|
dd => 1, dt => 1, li => 1, p => 1, |
3364 |
|
|
td => 1, th => 1, tr => 1, |
3365 |
|
|
tbody => 1, tfoot=> 1, thead => 1, |
3366 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
3367 |
|
|
!!!back-token; # <?> |
3368 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, tag_name => 'caption'}; |
3369 |
wakaba |
1.52 |
!!!back-token; |
3370 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, |
3371 |
wakaba |
1.52 |
tag_name => $self->{open_elements}->[-1]->[1]}; # MUST |
3372 |
|
|
redo B; |
3373 |
|
|
} |
3374 |
|
|
|
3375 |
|
|
if ($self->{open_elements}->[-1]->[1] ne 'caption') { |
3376 |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
3377 |
|
|
} |
3378 |
|
|
|
3379 |
|
|
splice @{$self->{open_elements}}, $i; |
3380 |
|
|
|
3381 |
|
|
$clear_up_to_marker->(); |
3382 |
|
|
|
3383 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_IM; |
3384 |
wakaba |
1.52 |
|
3385 |
|
|
## reprocess |
3386 |
|
|
redo B; |
3387 |
|
|
} else { |
3388 |
|
|
# |
3389 |
|
|
} |
3390 |
|
|
} else { |
3391 |
|
|
# |
3392 |
|
|
} |
3393 |
wakaba |
1.55 |
} elsif ($token->{type} == END_TAG_TOKEN) { |
3394 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'td' or $token->{tag_name} eq 'th') { |
3395 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_CELL_IM) { |
3396 |
wakaba |
1.43 |
## have an element in table scope |
3397 |
wakaba |
1.52 |
my $i; |
3398 |
wakaba |
1.43 |
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
3399 |
|
|
my $node = $self->{open_elements}->[$_]; |
3400 |
wakaba |
1.52 |
if ($node->[1] eq $token->{tag_name}) { |
3401 |
|
|
$i = $_; |
3402 |
wakaba |
1.43 |
last INSCOPE; |
3403 |
|
|
} elsif ({ |
3404 |
|
|
table => 1, html => 1, |
3405 |
|
|
}->{$node->[1]}) { |
3406 |
|
|
last INSCOPE; |
3407 |
|
|
} |
3408 |
|
|
} # INSCOPE |
3409 |
wakaba |
1.52 |
unless (defined $i) { |
3410 |
wakaba |
1.43 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
3411 |
|
|
## Ignore the token |
3412 |
|
|
!!!next-token; |
3413 |
|
|
redo B; |
3414 |
|
|
} |
3415 |
|
|
|
3416 |
wakaba |
1.52 |
## generate implied end tags |
3417 |
|
|
if ({ |
3418 |
|
|
dd => 1, dt => 1, li => 1, p => 1, |
3419 |
|
|
td => ($token->{tag_name} eq 'th'), |
3420 |
|
|
th => ($token->{tag_name} eq 'td'), |
3421 |
|
|
tr => 1, |
3422 |
|
|
tbody => 1, tfoot=> 1, thead => 1, |
3423 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
3424 |
|
|
!!!back-token; |
3425 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, |
3426 |
wakaba |
1.52 |
tag_name => $self->{open_elements}->[-1]->[1]}; # MUST |
3427 |
|
|
redo B; |
3428 |
|
|
} |
3429 |
|
|
|
3430 |
|
|
if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) { |
3431 |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
3432 |
|
|
} |
3433 |
|
|
|
3434 |
|
|
splice @{$self->{open_elements}}, $i; |
3435 |
|
|
|
3436 |
|
|
$clear_up_to_marker->(); |
3437 |
|
|
|
3438 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_ROW_IM; |
3439 |
wakaba |
1.52 |
|
3440 |
|
|
!!!next-token; |
3441 |
wakaba |
1.43 |
redo B; |
3442 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_CAPTION_IM) { |
3443 |
wakaba |
1.52 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
3444 |
|
|
## Ignore the token |
3445 |
|
|
!!!next-token; |
3446 |
|
|
redo B; |
3447 |
|
|
} else { |
3448 |
|
|
# |
3449 |
|
|
} |
3450 |
|
|
} elsif ($token->{tag_name} eq 'caption') { |
3451 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_CAPTION_IM) { |
3452 |
wakaba |
1.43 |
## have a table element in table scope |
3453 |
|
|
my $i; |
3454 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
3455 |
|
|
my $node = $self->{open_elements}->[$_]; |
3456 |
wakaba |
1.52 |
if ($node->[1] eq $token->{tag_name}) { |
3457 |
wakaba |
1.43 |
$i = $_; |
3458 |
|
|
last INSCOPE; |
3459 |
|
|
} elsif ({ |
3460 |
|
|
table => 1, html => 1, |
3461 |
|
|
}->{$node->[1]}) { |
3462 |
|
|
last INSCOPE; |
3463 |
|
|
} |
3464 |
|
|
} # INSCOPE |
3465 |
|
|
unless (defined $i) { |
3466 |
wakaba |
1.52 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
3467 |
wakaba |
1.43 |
## Ignore the token |
3468 |
|
|
!!!next-token; |
3469 |
|
|
redo B; |
3470 |
|
|
} |
3471 |
|
|
|
3472 |
|
|
## generate implied end tags |
3473 |
|
|
if ({ |
3474 |
|
|
dd => 1, dt => 1, li => 1, p => 1, |
3475 |
|
|
td => 1, th => 1, tr => 1, |
3476 |
|
|
tbody => 1, tfoot=> 1, thead => 1, |
3477 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
3478 |
|
|
!!!back-token; |
3479 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, |
3480 |
wakaba |
1.43 |
tag_name => $self->{open_elements}->[-1]->[1]}; # MUST |
3481 |
|
|
redo B; |
3482 |
|
|
} |
3483 |
wakaba |
1.52 |
|
3484 |
|
|
if ($self->{open_elements}->[-1]->[1] ne 'caption') { |
3485 |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
3486 |
|
|
} |
3487 |
|
|
|
3488 |
|
|
splice @{$self->{open_elements}}, $i; |
3489 |
|
|
|
3490 |
|
|
$clear_up_to_marker->(); |
3491 |
|
|
|
3492 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_IM; |
3493 |
wakaba |
1.52 |
|
3494 |
|
|
!!!next-token; |
3495 |
|
|
redo B; |
3496 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_CELL_IM) { |
3497 |
wakaba |
1.52 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
3498 |
|
|
## Ignore the token |
3499 |
|
|
!!!next-token; |
3500 |
|
|
redo B; |
3501 |
|
|
} else { |
3502 |
|
|
# |
3503 |
|
|
} |
3504 |
|
|
} elsif ({ |
3505 |
|
|
table => 1, tbody => 1, tfoot => 1, |
3506 |
|
|
thead => 1, tr => 1, |
3507 |
|
|
}->{$token->{tag_name}} and |
3508 |
wakaba |
1.54 |
$self->{insertion_mode} == IN_CELL_IM) { |
3509 |
wakaba |
1.52 |
## have an element in table scope |
3510 |
|
|
my $i; |
3511 |
|
|
my $tn; |
3512 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
3513 |
|
|
my $node = $self->{open_elements}->[$_]; |
3514 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
3515 |
|
|
$i = $_; |
3516 |
|
|
last INSCOPE; |
3517 |
|
|
} elsif ($node->[1] eq 'td' or $node->[1] eq 'th') { |
3518 |
|
|
$tn = $node->[1]; |
3519 |
|
|
## NOTE: There is exactly one |td| or |th| element |
3520 |
|
|
## in scope in the stack of open elements by definition. |
3521 |
|
|
} elsif ({ |
3522 |
|
|
table => 1, html => 1, |
3523 |
|
|
}->{$node->[1]}) { |
3524 |
|
|
last INSCOPE; |
3525 |
|
|
} |
3526 |
|
|
} # INSCOPE |
3527 |
|
|
unless (defined $i) { |
3528 |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
3529 |
|
|
## Ignore the token |
3530 |
|
|
!!!next-token; |
3531 |
|
|
redo B; |
3532 |
|
|
} |
3533 |
|
|
|
3534 |
|
|
## Close the cell |
3535 |
|
|
!!!back-token; # </?> |
3536 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, tag_name => $tn}; |
3537 |
wakaba |
1.52 |
redo B; |
3538 |
|
|
} elsif ($token->{tag_name} eq 'table' and |
3539 |
wakaba |
1.54 |
$self->{insertion_mode} == IN_CAPTION_IM) { |
3540 |
wakaba |
1.52 |
!!!parse-error (type => 'not closed:caption'); |
3541 |
|
|
|
3542 |
|
|
## As if </caption> |
3543 |
|
|
## have a table element in table scope |
3544 |
|
|
my $i; |
3545 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
3546 |
|
|
my $node = $self->{open_elements}->[$_]; |
3547 |
|
|
if ($node->[1] eq 'caption') { |
3548 |
|
|
$i = $_; |
3549 |
|
|
last INSCOPE; |
3550 |
|
|
} elsif ({ |
3551 |
|
|
table => 1, html => 1, |
3552 |
|
|
}->{$node->[1]}) { |
3553 |
|
|
last INSCOPE; |
3554 |
|
|
} |
3555 |
|
|
} # INSCOPE |
3556 |
|
|
unless (defined $i) { |
3557 |
|
|
!!!parse-error (type => 'unmatched end tag:caption'); |
3558 |
|
|
## Ignore the token |
3559 |
|
|
!!!next-token; |
3560 |
|
|
redo B; |
3561 |
|
|
} |
3562 |
|
|
|
3563 |
|
|
## generate implied end tags |
3564 |
|
|
if ({ |
3565 |
|
|
dd => 1, dt => 1, li => 1, p => 1, |
3566 |
|
|
td => 1, th => 1, tr => 1, |
3567 |
|
|
tbody => 1, tfoot=> 1, thead => 1, |
3568 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
3569 |
|
|
!!!back-token; # </table> |
3570 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, tag_name => 'caption'}; |
3571 |
wakaba |
1.52 |
!!!back-token; |
3572 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, |
3573 |
wakaba |
1.52 |
tag_name => $self->{open_elements}->[-1]->[1]}; # MUST |
3574 |
|
|
redo B; |
3575 |
|
|
} |
3576 |
|
|
|
3577 |
|
|
if ($self->{open_elements}->[-1]->[1] ne 'caption') { |
3578 |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
3579 |
|
|
} |
3580 |
|
|
|
3581 |
|
|
splice @{$self->{open_elements}}, $i; |
3582 |
|
|
|
3583 |
|
|
$clear_up_to_marker->(); |
3584 |
|
|
|
3585 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_IM; |
3586 |
wakaba |
1.52 |
|
3587 |
|
|
## reprocess |
3588 |
|
|
redo B; |
3589 |
|
|
} elsif ({ |
3590 |
|
|
body => 1, col => 1, colgroup => 1, html => 1, |
3591 |
|
|
}->{$token->{tag_name}}) { |
3592 |
wakaba |
1.56 |
if ($self->{insertion_mode} & BODY_TABLE_IMS) { |
3593 |
wakaba |
1.52 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
3594 |
|
|
## Ignore the token |
3595 |
|
|
!!!next-token; |
3596 |
|
|
redo B; |
3597 |
|
|
} else { |
3598 |
|
|
# |
3599 |
|
|
} |
3600 |
|
|
} elsif ({ |
3601 |
|
|
tbody => 1, tfoot => 1, |
3602 |
|
|
thead => 1, tr => 1, |
3603 |
|
|
}->{$token->{tag_name}} and |
3604 |
wakaba |
1.54 |
$self->{insertion_mode} == IN_CAPTION_IM) { |
3605 |
wakaba |
1.52 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
3606 |
|
|
## Ignore the token |
3607 |
|
|
!!!next-token; |
3608 |
|
|
redo B; |
3609 |
|
|
} else { |
3610 |
|
|
# |
3611 |
|
|
} |
3612 |
|
|
} else { |
3613 |
|
|
die "$0: $token->{type}: Unknown token type"; |
3614 |
|
|
} |
3615 |
|
|
|
3616 |
|
|
$insert = $insert_to_current; |
3617 |
|
|
# |
3618 |
wakaba |
1.56 |
} elsif ($self->{insertion_mode} & TABLE_IMS) { |
3619 |
wakaba |
1.58 |
if ($token->{type} == CHARACTER_TOKEN) { |
3620 |
wakaba |
1.52 |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { |
3621 |
|
|
$self->{open_elements}->[-1]->[0]->manakai_append_text ($1); |
3622 |
|
|
|
3623 |
|
|
unless (length $token->{data}) { |
3624 |
|
|
!!!next-token; |
3625 |
|
|
redo B; |
3626 |
|
|
} |
3627 |
|
|
} |
3628 |
|
|
|
3629 |
|
|
!!!parse-error (type => 'in table:#character'); |
3630 |
|
|
|
3631 |
|
|
## As if in body, but insert into foster parent element |
3632 |
|
|
## ISSUE: Spec says that "whenever a node would be inserted |
3633 |
|
|
## into the current node" while characters might not be |
3634 |
|
|
## result in a new Text node. |
3635 |
|
|
$reconstruct_active_formatting_elements->($insert_to_foster); |
3636 |
|
|
|
3637 |
|
|
if ({ |
3638 |
|
|
table => 1, tbody => 1, tfoot => 1, |
3639 |
|
|
thead => 1, tr => 1, |
3640 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
3641 |
|
|
# MUST |
3642 |
|
|
my $foster_parent_element; |
3643 |
|
|
my $next_sibling; |
3644 |
|
|
my $prev_sibling; |
3645 |
|
|
OE: for (reverse 0..$#{$self->{open_elements}}) { |
3646 |
|
|
if ($self->{open_elements}->[$_]->[1] eq 'table') { |
3647 |
|
|
my $parent = $self->{open_elements}->[$_]->[0]->parent_node; |
3648 |
|
|
if (defined $parent and $parent->node_type == 1) { |
3649 |
|
|
$foster_parent_element = $parent; |
3650 |
|
|
$next_sibling = $self->{open_elements}->[$_]->[0]; |
3651 |
|
|
$prev_sibling = $next_sibling->previous_sibling; |
3652 |
|
|
} else { |
3653 |
|
|
$foster_parent_element = $self->{open_elements}->[$_ - 1]->[0]; |
3654 |
|
|
$prev_sibling = $foster_parent_element->last_child; |
3655 |
|
|
} |
3656 |
|
|
last OE; |
3657 |
|
|
} |
3658 |
|
|
} # OE |
3659 |
|
|
$foster_parent_element = $self->{open_elements}->[0]->[0] and |
3660 |
|
|
$prev_sibling = $foster_parent_element->last_child |
3661 |
|
|
unless defined $foster_parent_element; |
3662 |
|
|
if (defined $prev_sibling and |
3663 |
|
|
$prev_sibling->node_type == 3) { |
3664 |
|
|
$prev_sibling->manakai_append_text ($token->{data}); |
3665 |
|
|
} else { |
3666 |
|
|
$foster_parent_element->insert_before |
3667 |
|
|
($self->{document}->create_text_node ($token->{data}), |
3668 |
|
|
$next_sibling); |
3669 |
|
|
} |
3670 |
|
|
} else { |
3671 |
|
|
$self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data}); |
3672 |
|
|
} |
3673 |
|
|
|
3674 |
|
|
!!!next-token; |
3675 |
|
|
redo B; |
3676 |
wakaba |
1.58 |
} elsif ($token->{type} == START_TAG_TOKEN) { |
3677 |
wakaba |
1.52 |
if ({ |
3678 |
wakaba |
1.54 |
tr => ($self->{insertion_mode} != IN_ROW_IM), |
3679 |
wakaba |
1.52 |
th => 1, td => 1, |
3680 |
|
|
}->{$token->{tag_name}}) { |
3681 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_TABLE_IM) { |
3682 |
wakaba |
1.52 |
## Clear back to table context |
3683 |
|
|
while ($self->{open_elements}->[-1]->[1] ne 'table' and |
3684 |
|
|
$self->{open_elements}->[-1]->[1] ne 'html') { |
3685 |
wakaba |
1.43 |
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
3686 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; |
3687 |
wakaba |
1.43 |
} |
3688 |
|
|
|
3689 |
wakaba |
1.52 |
!!!insert-element ('tbody'); |
3690 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_BODY_IM; |
3691 |
wakaba |
1.52 |
## reprocess in the "in table body" insertion mode... |
3692 |
|
|
} |
3693 |
|
|
|
3694 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_TABLE_BODY_IM) { |
3695 |
wakaba |
1.52 |
unless ($token->{tag_name} eq 'tr') { |
3696 |
|
|
!!!parse-error (type => 'missing start tag:tr'); |
3697 |
|
|
} |
3698 |
wakaba |
1.43 |
|
3699 |
wakaba |
1.52 |
## Clear back to table body context |
3700 |
|
|
while (not { |
3701 |
|
|
tbody => 1, tfoot => 1, thead => 1, html => 1, |
3702 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
3703 |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
3704 |
|
|
pop @{$self->{open_elements}}; |
3705 |
|
|
} |
3706 |
wakaba |
1.43 |
|
3707 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_ROW_IM; |
3708 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'tr') { |
3709 |
|
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
3710 |
|
|
!!!next-token; |
3711 |
|
|
redo B; |
3712 |
|
|
} else { |
3713 |
|
|
!!!insert-element ('tr'); |
3714 |
|
|
## reprocess in the "in row" insertion mode |
3715 |
|
|
} |
3716 |
|
|
} |
3717 |
|
|
|
3718 |
|
|
## Clear back to table row context |
3719 |
|
|
while (not { |
3720 |
|
|
tr => 1, html => 1, |
3721 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
3722 |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
3723 |
|
|
pop @{$self->{open_elements}}; |
3724 |
wakaba |
1.43 |
} |
3725 |
wakaba |
1.52 |
|
3726 |
|
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
3727 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_CELL_IM; |
3728 |
wakaba |
1.52 |
|
3729 |
|
|
push @$active_formatting_elements, ['#marker', '']; |
3730 |
|
|
|
3731 |
|
|
!!!next-token; |
3732 |
|
|
redo B; |
3733 |
|
|
} elsif ({ |
3734 |
|
|
caption => 1, col => 1, colgroup => 1, |
3735 |
|
|
tbody => 1, tfoot => 1, thead => 1, |
3736 |
wakaba |
1.54 |
tr => 1, # $self->{insertion_mode} == IN_ROW_IM |
3737 |
wakaba |
1.52 |
}->{$token->{tag_name}}) { |
3738 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_ROW_IM) { |
3739 |
wakaba |
1.52 |
## As if </tr> |
3740 |
wakaba |
1.43 |
## have an element in table scope |
3741 |
|
|
my $i; |
3742 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
3743 |
|
|
my $node = $self->{open_elements}->[$_]; |
3744 |
wakaba |
1.52 |
if ($node->[1] eq 'tr') { |
3745 |
wakaba |
1.43 |
$i = $_; |
3746 |
|
|
last INSCOPE; |
3747 |
|
|
} elsif ({ |
3748 |
|
|
table => 1, html => 1, |
3749 |
|
|
}->{$node->[1]}) { |
3750 |
|
|
last INSCOPE; |
3751 |
|
|
} |
3752 |
|
|
} # INSCOPE |
3753 |
wakaba |
1.52 |
unless (defined $i) { |
3754 |
|
|
!!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name}); |
3755 |
|
|
## Ignore the token |
3756 |
|
|
!!!next-token; |
3757 |
wakaba |
1.43 |
redo B; |
3758 |
|
|
} |
3759 |
|
|
|
3760 |
wakaba |
1.52 |
## Clear back to table row context |
3761 |
|
|
while (not { |
3762 |
|
|
tr => 1, html => 1, |
3763 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
3764 |
wakaba |
1.43 |
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
3765 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; |
3766 |
wakaba |
1.1 |
} |
3767 |
wakaba |
1.43 |
|
3768 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; # tr |
3769 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_BODY_IM; |
3770 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'tr') { |
3771 |
|
|
## reprocess |
3772 |
|
|
redo B; |
3773 |
|
|
} else { |
3774 |
|
|
## reprocess in the "in table body" insertion mode... |
3775 |
|
|
} |
3776 |
wakaba |
1.1 |
} |
3777 |
wakaba |
1.52 |
|
3778 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_TABLE_BODY_IM) { |
3779 |
wakaba |
1.52 |
## have an element in table scope |
3780 |
wakaba |
1.43 |
my $i; |
3781 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
3782 |
|
|
my $node = $self->{open_elements}->[$_]; |
3783 |
wakaba |
1.52 |
if ({ |
3784 |
|
|
tbody => 1, thead => 1, tfoot => 1, |
3785 |
|
|
}->{$node->[1]}) { |
3786 |
wakaba |
1.43 |
$i = $_; |
3787 |
|
|
last INSCOPE; |
3788 |
|
|
} elsif ({ |
3789 |
|
|
table => 1, html => 1, |
3790 |
|
|
}->{$node->[1]}) { |
3791 |
|
|
last INSCOPE; |
3792 |
|
|
} |
3793 |
|
|
} # INSCOPE |
3794 |
wakaba |
1.52 |
unless (defined $i) { |
3795 |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
3796 |
|
|
## Ignore the token |
3797 |
|
|
!!!next-token; |
3798 |
wakaba |
1.43 |
redo B; |
3799 |
|
|
} |
3800 |
wakaba |
1.52 |
|
3801 |
|
|
## Clear back to table body context |
3802 |
|
|
while (not { |
3803 |
|
|
tbody => 1, tfoot => 1, thead => 1, html => 1, |
3804 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
3805 |
wakaba |
1.43 |
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
3806 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; |
3807 |
wakaba |
1.43 |
} |
3808 |
|
|
|
3809 |
wakaba |
1.52 |
## As if <{current node}> |
3810 |
|
|
## have an element in table scope |
3811 |
|
|
## true by definition |
3812 |
wakaba |
1.43 |
|
3813 |
wakaba |
1.52 |
## Clear back to table body context |
3814 |
|
|
## nop by definition |
3815 |
wakaba |
1.43 |
|
3816 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; |
3817 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_IM; |
3818 |
wakaba |
1.52 |
## reprocess in "in table" insertion mode... |
3819 |
|
|
} |
3820 |
|
|
|
3821 |
|
|
if ($token->{tag_name} eq 'col') { |
3822 |
|
|
## Clear back to table context |
3823 |
|
|
while ($self->{open_elements}->[-1]->[1] ne 'table' and |
3824 |
|
|
$self->{open_elements}->[-1]->[1] ne 'html') { |
3825 |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
3826 |
|
|
pop @{$self->{open_elements}}; |
3827 |
|
|
} |
3828 |
wakaba |
1.43 |
|
3829 |
wakaba |
1.52 |
!!!insert-element ('colgroup'); |
3830 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_COLUMN_GROUP_IM; |
3831 |
wakaba |
1.52 |
## reprocess |
3832 |
wakaba |
1.43 |
redo B; |
3833 |
wakaba |
1.52 |
} elsif ({ |
3834 |
|
|
caption => 1, |
3835 |
|
|
colgroup => 1, |
3836 |
|
|
tbody => 1, tfoot => 1, thead => 1, |
3837 |
|
|
}->{$token->{tag_name}}) { |
3838 |
|
|
## Clear back to table context |
3839 |
|
|
while ($self->{open_elements}->[-1]->[1] ne 'table' and |
3840 |
|
|
$self->{open_elements}->[-1]->[1] ne 'html') { |
3841 |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
3842 |
|
|
pop @{$self->{open_elements}}; |
3843 |
wakaba |
1.1 |
} |
3844 |
wakaba |
1.52 |
|
3845 |
|
|
push @$active_formatting_elements, ['#marker', ''] |
3846 |
|
|
if $token->{tag_name} eq 'caption'; |
3847 |
|
|
|
3848 |
|
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
3849 |
|
|
$self->{insertion_mode} = { |
3850 |
wakaba |
1.54 |
caption => IN_CAPTION_IM, |
3851 |
|
|
colgroup => IN_COLUMN_GROUP_IM, |
3852 |
|
|
tbody => IN_TABLE_BODY_IM, |
3853 |
|
|
tfoot => IN_TABLE_BODY_IM, |
3854 |
|
|
thead => IN_TABLE_BODY_IM, |
3855 |
wakaba |
1.52 |
}->{$token->{tag_name}}; |
3856 |
wakaba |
1.1 |
!!!next-token; |
3857 |
|
|
redo B; |
3858 |
wakaba |
1.52 |
} else { |
3859 |
|
|
die "$0: in table: <>: $token->{tag_name}"; |
3860 |
wakaba |
1.1 |
} |
3861 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'table') { |
3862 |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
3863 |
wakaba |
1.1 |
|
3864 |
wakaba |
1.52 |
## As if </table> |
3865 |
wakaba |
1.1 |
## have a table element in table scope |
3866 |
|
|
my $i; |
3867 |
wakaba |
1.3 |
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
3868 |
|
|
my $node = $self->{open_elements}->[$_]; |
3869 |
wakaba |
1.52 |
if ($node->[1] eq 'table') { |
3870 |
wakaba |
1.1 |
$i = $_; |
3871 |
|
|
last INSCOPE; |
3872 |
|
|
} elsif ({ |
3873 |
|
|
table => 1, html => 1, |
3874 |
|
|
}->{$node->[1]}) { |
3875 |
|
|
last INSCOPE; |
3876 |
|
|
} |
3877 |
|
|
} # INSCOPE |
3878 |
|
|
unless (defined $i) { |
3879 |
wakaba |
1.52 |
!!!parse-error (type => 'unmatched end tag:table'); |
3880 |
|
|
## Ignore tokens </table><table> |
3881 |
wakaba |
1.1 |
!!!next-token; |
3882 |
|
|
redo B; |
3883 |
|
|
} |
3884 |
|
|
|
3885 |
|
|
## generate implied end tags |
3886 |
|
|
if ({ |
3887 |
|
|
dd => 1, dt => 1, li => 1, p => 1, |
3888 |
|
|
td => 1, th => 1, tr => 1, |
3889 |
wakaba |
1.31 |
tbody => 1, tfoot=> 1, thead => 1, |
3890 |
wakaba |
1.3 |
}->{$self->{open_elements}->[-1]->[1]}) { |
3891 |
wakaba |
1.52 |
!!!back-token; # <table> |
3892 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, tag_name => 'table'}; |
3893 |
wakaba |
1.1 |
!!!back-token; |
3894 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, |
3895 |
wakaba |
1.3 |
tag_name => $self->{open_elements}->[-1]->[1]}; # MUST |
3896 |
wakaba |
1.1 |
redo B; |
3897 |
|
|
} |
3898 |
|
|
|
3899 |
wakaba |
1.52 |
if ($self->{open_elements}->[-1]->[1] ne 'table') { |
3900 |
wakaba |
1.3 |
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
3901 |
wakaba |
1.1 |
} |
3902 |
|
|
|
3903 |
wakaba |
1.3 |
splice @{$self->{open_elements}}, $i; |
3904 |
wakaba |
1.1 |
|
3905 |
wakaba |
1.52 |
$self->_reset_insertion_mode; |
3906 |
wakaba |
1.1 |
|
3907 |
|
|
## reprocess |
3908 |
|
|
redo B; |
3909 |
wakaba |
1.58 |
} else { |
3910 |
|
|
!!!parse-error (type => 'in table:'.$token->{tag_name}); |
3911 |
|
|
|
3912 |
|
|
$insert = $insert_to_foster; |
3913 |
|
|
# |
3914 |
|
|
} |
3915 |
|
|
} elsif ($token->{type} == END_TAG_TOKEN) { |
3916 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'tr' and |
3917 |
wakaba |
1.54 |
$self->{insertion_mode} == IN_ROW_IM) { |
3918 |
wakaba |
1.52 |
## have an element in table scope |
3919 |
|
|
my $i; |
3920 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
3921 |
|
|
my $node = $self->{open_elements}->[$_]; |
3922 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
3923 |
|
|
$i = $_; |
3924 |
|
|
last INSCOPE; |
3925 |
|
|
} elsif ({ |
3926 |
|
|
table => 1, html => 1, |
3927 |
|
|
}->{$node->[1]}) { |
3928 |
|
|
last INSCOPE; |
3929 |
|
|
} |
3930 |
|
|
} # INSCOPE |
3931 |
|
|
unless (defined $i) { |
3932 |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
3933 |
|
|
## Ignore the token |
3934 |
wakaba |
1.42 |
!!!next-token; |
3935 |
|
|
redo B; |
3936 |
|
|
} |
3937 |
|
|
|
3938 |
wakaba |
1.52 |
## Clear back to table row context |
3939 |
|
|
while (not { |
3940 |
|
|
tr => 1, html => 1, |
3941 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
3942 |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
3943 |
|
|
pop @{$self->{open_elements}}; |
3944 |
|
|
} |
3945 |
wakaba |
1.42 |
|
3946 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; # tr |
3947 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_BODY_IM; |
3948 |
wakaba |
1.52 |
!!!next-token; |
3949 |
|
|
redo B; |
3950 |
|
|
} elsif ($token->{tag_name} eq 'table') { |
3951 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_ROW_IM) { |
3952 |
wakaba |
1.52 |
## As if </tr> |
3953 |
|
|
## have an element in table scope |
3954 |
|
|
my $i; |
3955 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
3956 |
|
|
my $node = $self->{open_elements}->[$_]; |
3957 |
|
|
if ($node->[1] eq 'tr') { |
3958 |
|
|
$i = $_; |
3959 |
|
|
last INSCOPE; |
3960 |
|
|
} elsif ({ |
3961 |
|
|
table => 1, html => 1, |
3962 |
|
|
}->{$node->[1]}) { |
3963 |
|
|
last INSCOPE; |
3964 |
wakaba |
1.42 |
} |
3965 |
wakaba |
1.52 |
} # INSCOPE |
3966 |
|
|
unless (defined $i) { |
3967 |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{type}); |
3968 |
|
|
## Ignore the token |
3969 |
|
|
!!!next-token; |
3970 |
|
|
redo B; |
3971 |
wakaba |
1.42 |
} |
3972 |
wakaba |
1.52 |
|
3973 |
|
|
## Clear back to table row context |
3974 |
|
|
while (not { |
3975 |
|
|
tr => 1, html => 1, |
3976 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
3977 |
wakaba |
1.46 |
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
3978 |
|
|
pop @{$self->{open_elements}}; |
3979 |
wakaba |
1.1 |
} |
3980 |
wakaba |
1.46 |
|
3981 |
wakaba |
1.52 |
pop @{$self->{open_elements}}; # tr |
3982 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_BODY_IM; |
3983 |
wakaba |
1.46 |
## reprocess in the "in table body" insertion mode... |
3984 |
wakaba |
1.1 |
} |
3985 |
|
|
|
3986 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_TABLE_BODY_IM) { |
3987 |
wakaba |
1.52 |
## have an element in table scope |
3988 |
|
|
my $i; |
3989 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
3990 |
|
|
my $node = $self->{open_elements}->[$_]; |
3991 |
|
|
if ({ |
3992 |
|
|
tbody => 1, thead => 1, tfoot => 1, |
3993 |
|
|
}->{$node->[1]}) { |
3994 |
|
|
$i = $_; |
3995 |
|
|
last INSCOPE; |
3996 |
|
|
} elsif ({ |
3997 |
|
|
table => 1, html => 1, |
3998 |
|
|
}->{$node->[1]}) { |
3999 |
|
|
last INSCOPE; |
4000 |
|
|
} |
4001 |
|
|
} # INSCOPE |
4002 |
|
|
unless (defined $i) { |
4003 |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
4004 |
|
|
## Ignore the token |
4005 |
|
|
!!!next-token; |
4006 |
|
|
redo B; |
4007 |
wakaba |
1.47 |
} |
4008 |
|
|
|
4009 |
|
|
## Clear back to table body context |
4010 |
|
|
while (not { |
4011 |
|
|
tbody => 1, tfoot => 1, thead => 1, html => 1, |
4012 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4013 |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
4014 |
|
|
pop @{$self->{open_elements}}; |
4015 |
|
|
} |
4016 |
|
|
|
4017 |
wakaba |
1.52 |
## As if <{current node}> |
4018 |
|
|
## have an element in table scope |
4019 |
|
|
## true by definition |
4020 |
|
|
|
4021 |
|
|
## Clear back to table body context |
4022 |
|
|
## nop by definition |
4023 |
|
|
|
4024 |
|
|
pop @{$self->{open_elements}}; |
4025 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_IM; |
4026 |
wakaba |
1.52 |
## reprocess in the "in table" insertion mode... |
4027 |
|
|
} |
4028 |
|
|
|
4029 |
|
|
## have a table element in table scope |
4030 |
|
|
my $i; |
4031 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4032 |
|
|
my $node = $self->{open_elements}->[$_]; |
4033 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
4034 |
|
|
$i = $_; |
4035 |
|
|
last INSCOPE; |
4036 |
|
|
} elsif ({ |
4037 |
|
|
table => 1, html => 1, |
4038 |
|
|
}->{$node->[1]}) { |
4039 |
|
|
last INSCOPE; |
4040 |
wakaba |
1.47 |
} |
4041 |
wakaba |
1.52 |
} # INSCOPE |
4042 |
|
|
unless (defined $i) { |
4043 |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
4044 |
|
|
## Ignore the token |
4045 |
|
|
!!!next-token; |
4046 |
|
|
redo B; |
4047 |
wakaba |
1.3 |
} |
4048 |
|
|
|
4049 |
wakaba |
1.52 |
## generate implied end tags |
4050 |
|
|
if ({ |
4051 |
|
|
dd => 1, dt => 1, li => 1, p => 1, |
4052 |
|
|
td => 1, th => 1, tr => 1, |
4053 |
|
|
tbody => 1, tfoot=> 1, thead => 1, |
4054 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4055 |
|
|
!!!back-token; |
4056 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, |
4057 |
wakaba |
1.52 |
tag_name => $self->{open_elements}->[-1]->[1]}; # MUST |
4058 |
|
|
redo B; |
4059 |
|
|
} |
4060 |
|
|
|
4061 |
|
|
if ($self->{open_elements}->[-1]->[1] ne 'table') { |
4062 |
wakaba |
1.3 |
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
4063 |
wakaba |
1.1 |
} |
4064 |
wakaba |
1.52 |
|
4065 |
|
|
splice @{$self->{open_elements}}, $i; |
4066 |
wakaba |
1.1 |
|
4067 |
wakaba |
1.52 |
$self->_reset_insertion_mode; |
4068 |
wakaba |
1.47 |
|
4069 |
|
|
!!!next-token; |
4070 |
|
|
redo B; |
4071 |
|
|
} elsif ({ |
4072 |
wakaba |
1.48 |
tbody => 1, tfoot => 1, thead => 1, |
4073 |
wakaba |
1.52 |
}->{$token->{tag_name}} and |
4074 |
wakaba |
1.56 |
$self->{insertion_mode} & ROW_IMS) { |
4075 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_ROW_IM) { |
4076 |
wakaba |
1.52 |
## have an element in table scope |
4077 |
|
|
my $i; |
4078 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4079 |
|
|
my $node = $self->{open_elements}->[$_]; |
4080 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
4081 |
|
|
$i = $_; |
4082 |
|
|
last INSCOPE; |
4083 |
|
|
} elsif ({ |
4084 |
|
|
table => 1, html => 1, |
4085 |
|
|
}->{$node->[1]}) { |
4086 |
|
|
last INSCOPE; |
4087 |
|
|
} |
4088 |
|
|
} # INSCOPE |
4089 |
|
|
unless (defined $i) { |
4090 |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
4091 |
|
|
## Ignore the token |
4092 |
|
|
!!!next-token; |
4093 |
|
|
redo B; |
4094 |
|
|
} |
4095 |
|
|
|
4096 |
wakaba |
1.48 |
## As if </tr> |
4097 |
|
|
## have an element in table scope |
4098 |
|
|
my $i; |
4099 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4100 |
|
|
my $node = $self->{open_elements}->[$_]; |
4101 |
|
|
if ($node->[1] eq 'tr') { |
4102 |
|
|
$i = $_; |
4103 |
|
|
last INSCOPE; |
4104 |
|
|
} elsif ({ |
4105 |
|
|
table => 1, html => 1, |
4106 |
|
|
}->{$node->[1]}) { |
4107 |
|
|
last INSCOPE; |
4108 |
|
|
} |
4109 |
|
|
} # INSCOPE |
4110 |
wakaba |
1.52 |
unless (defined $i) { |
4111 |
|
|
!!!parse-error (type => 'unmatched end tag:tr'); |
4112 |
|
|
## Ignore the token |
4113 |
|
|
!!!next-token; |
4114 |
|
|
redo B; |
4115 |
|
|
} |
4116 |
wakaba |
1.48 |
|
4117 |
|
|
## Clear back to table row context |
4118 |
|
|
while (not { |
4119 |
|
|
tr => 1, html => 1, |
4120 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4121 |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
4122 |
|
|
pop @{$self->{open_elements}}; |
4123 |
|
|
} |
4124 |
|
|
|
4125 |
|
|
pop @{$self->{open_elements}}; # tr |
4126 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_BODY_IM; |
4127 |
wakaba |
1.52 |
## reprocess in the "in table body" insertion mode... |
4128 |
|
|
} |
4129 |
|
|
|
4130 |
|
|
## have an element in table scope |
4131 |
|
|
my $i; |
4132 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4133 |
|
|
my $node = $self->{open_elements}->[$_]; |
4134 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
4135 |
|
|
$i = $_; |
4136 |
|
|
last INSCOPE; |
4137 |
|
|
} elsif ({ |
4138 |
|
|
table => 1, html => 1, |
4139 |
|
|
}->{$node->[1]}) { |
4140 |
|
|
last INSCOPE; |
4141 |
|
|
} |
4142 |
|
|
} # INSCOPE |
4143 |
|
|
unless (defined $i) { |
4144 |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
4145 |
|
|
## Ignore the token |
4146 |
|
|
!!!next-token; |
4147 |
|
|
redo B; |
4148 |
|
|
} |
4149 |
|
|
|
4150 |
|
|
## Clear back to table body context |
4151 |
|
|
while (not { |
4152 |
|
|
tbody => 1, tfoot => 1, thead => 1, html => 1, |
4153 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4154 |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
4155 |
|
|
pop @{$self->{open_elements}}; |
4156 |
|
|
} |
4157 |
|
|
|
4158 |
|
|
pop @{$self->{open_elements}}; |
4159 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_IM; |
4160 |
wakaba |
1.52 |
!!!next-token; |
4161 |
|
|
redo B; |
4162 |
|
|
} elsif ({ |
4163 |
|
|
body => 1, caption => 1, col => 1, colgroup => 1, |
4164 |
|
|
html => 1, td => 1, th => 1, |
4165 |
wakaba |
1.54 |
tr => 1, # $self->{insertion_mode} == IN_ROW_IM |
4166 |
|
|
tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM |
4167 |
wakaba |
1.52 |
}->{$token->{tag_name}}) { |
4168 |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
4169 |
|
|
## Ignore the token |
4170 |
|
|
!!!next-token; |
4171 |
|
|
redo B; |
4172 |
wakaba |
1.58 |
} else { |
4173 |
|
|
!!!parse-error (type => 'in table:/'.$token->{tag_name}); |
4174 |
wakaba |
1.52 |
|
4175 |
wakaba |
1.58 |
$insert = $insert_to_foster; |
4176 |
|
|
# |
4177 |
|
|
} |
4178 |
|
|
} else { |
4179 |
|
|
die "$0: $token->{type}: Unknown token type"; |
4180 |
|
|
} |
4181 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_COLUMN_GROUP_IM) { |
4182 |
wakaba |
1.55 |
if ($token->{type} == CHARACTER_TOKEN) { |
4183 |
wakaba |
1.52 |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { |
4184 |
|
|
$self->{open_elements}->[-1]->[0]->manakai_append_text ($1); |
4185 |
|
|
unless (length $token->{data}) { |
4186 |
|
|
!!!next-token; |
4187 |
|
|
redo B; |
4188 |
|
|
} |
4189 |
|
|
} |
4190 |
|
|
|
4191 |
|
|
# |
4192 |
wakaba |
1.55 |
} elsif ($token->{type} == START_TAG_TOKEN) { |
4193 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'col') { |
4194 |
|
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
4195 |
|
|
pop @{$self->{open_elements}}; |
4196 |
|
|
!!!next-token; |
4197 |
|
|
redo B; |
4198 |
|
|
} else { |
4199 |
|
|
# |
4200 |
|
|
} |
4201 |
wakaba |
1.55 |
} elsif ($token->{type} == END_TAG_TOKEN) { |
4202 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'colgroup') { |
4203 |
|
|
if ($self->{open_elements}->[-1]->[1] eq 'html') { |
4204 |
|
|
!!!parse-error (type => 'unmatched end tag:colgroup'); |
4205 |
|
|
## Ignore the token |
4206 |
|
|
!!!next-token; |
4207 |
|
|
redo B; |
4208 |
|
|
} else { |
4209 |
|
|
pop @{$self->{open_elements}}; # colgroup |
4210 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_IM; |
4211 |
wakaba |
1.52 |
!!!next-token; |
4212 |
|
|
redo B; |
4213 |
|
|
} |
4214 |
|
|
} elsif ($token->{tag_name} eq 'col') { |
4215 |
|
|
!!!parse-error (type => 'unmatched end tag:col'); |
4216 |
|
|
## Ignore the token |
4217 |
|
|
!!!next-token; |
4218 |
|
|
redo B; |
4219 |
|
|
} else { |
4220 |
|
|
# |
4221 |
|
|
} |
4222 |
|
|
} else { |
4223 |
|
|
# |
4224 |
|
|
} |
4225 |
|
|
|
4226 |
|
|
## As if </colgroup> |
4227 |
|
|
if ($self->{open_elements}->[-1]->[1] eq 'html') { |
4228 |
|
|
!!!parse-error (type => 'unmatched end tag:colgroup'); |
4229 |
|
|
## Ignore the token |
4230 |
|
|
!!!next-token; |
4231 |
|
|
redo B; |
4232 |
|
|
} else { |
4233 |
|
|
pop @{$self->{open_elements}}; # colgroup |
4234 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_IM; |
4235 |
wakaba |
1.52 |
## reprocess |
4236 |
|
|
redo B; |
4237 |
|
|
} |
4238 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == IN_SELECT_IM) { |
4239 |
wakaba |
1.58 |
if ($token->{type} == CHARACTER_TOKEN) { |
4240 |
|
|
$self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data}); |
4241 |
|
|
!!!next-token; |
4242 |
|
|
redo B; |
4243 |
|
|
} elsif ($token->{type} == START_TAG_TOKEN) { |
4244 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'option') { |
4245 |
|
|
if ($self->{open_elements}->[-1]->[1] eq 'option') { |
4246 |
|
|
## As if </option> |
4247 |
|
|
pop @{$self->{open_elements}}; |
4248 |
|
|
} |
4249 |
|
|
|
4250 |
|
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
4251 |
|
|
!!!next-token; |
4252 |
|
|
redo B; |
4253 |
|
|
} elsif ($token->{tag_name} eq 'optgroup') { |
4254 |
|
|
if ($self->{open_elements}->[-1]->[1] eq 'option') { |
4255 |
|
|
## As if </option> |
4256 |
|
|
pop @{$self->{open_elements}}; |
4257 |
|
|
} |
4258 |
|
|
|
4259 |
|
|
if ($self->{open_elements}->[-1]->[1] eq 'optgroup') { |
4260 |
|
|
## As if </optgroup> |
4261 |
|
|
pop @{$self->{open_elements}}; |
4262 |
|
|
} |
4263 |
|
|
|
4264 |
|
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
4265 |
|
|
!!!next-token; |
4266 |
|
|
redo B; |
4267 |
|
|
} elsif ($token->{tag_name} eq 'select') { |
4268 |
|
|
!!!parse-error (type => 'not closed:select'); |
4269 |
|
|
## As if </select> instead |
4270 |
|
|
## have an element in table scope |
4271 |
|
|
my $i; |
4272 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4273 |
|
|
my $node = $self->{open_elements}->[$_]; |
4274 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
4275 |
|
|
$i = $_; |
4276 |
|
|
last INSCOPE; |
4277 |
|
|
} elsif ({ |
4278 |
|
|
table => 1, html => 1, |
4279 |
|
|
}->{$node->[1]}) { |
4280 |
|
|
last INSCOPE; |
4281 |
wakaba |
1.47 |
} |
4282 |
wakaba |
1.52 |
} # INSCOPE |
4283 |
|
|
unless (defined $i) { |
4284 |
|
|
!!!parse-error (type => 'unmatched end tag:select'); |
4285 |
|
|
## Ignore the token |
4286 |
|
|
!!!next-token; |
4287 |
|
|
redo B; |
4288 |
wakaba |
1.47 |
} |
4289 |
wakaba |
1.52 |
|
4290 |
|
|
splice @{$self->{open_elements}}, $i; |
4291 |
|
|
|
4292 |
|
|
$self->_reset_insertion_mode; |
4293 |
wakaba |
1.47 |
|
4294 |
wakaba |
1.52 |
!!!next-token; |
4295 |
|
|
redo B; |
4296 |
wakaba |
1.58 |
} else { |
4297 |
|
|
!!!parse-error (type => 'in select:'.$token->{tag_name}); |
4298 |
|
|
## Ignore the token |
4299 |
|
|
!!!next-token; |
4300 |
|
|
redo B; |
4301 |
|
|
} |
4302 |
|
|
} elsif ($token->{type} == END_TAG_TOKEN) { |
4303 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'optgroup') { |
4304 |
|
|
if ($self->{open_elements}->[-1]->[1] eq 'option' and |
4305 |
|
|
$self->{open_elements}->[-2]->[1] eq 'optgroup') { |
4306 |
|
|
## As if </option> |
4307 |
|
|
splice @{$self->{open_elements}}, -2; |
4308 |
|
|
} elsif ($self->{open_elements}->[-1]->[1] eq 'optgroup') { |
4309 |
|
|
pop @{$self->{open_elements}}; |
4310 |
|
|
} else { |
4311 |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
4312 |
|
|
## Ignore the token |
4313 |
|
|
} |
4314 |
|
|
!!!next-token; |
4315 |
|
|
redo B; |
4316 |
|
|
} elsif ($token->{tag_name} eq 'option') { |
4317 |
|
|
if ($self->{open_elements}->[-1]->[1] eq 'option') { |
4318 |
wakaba |
1.47 |
pop @{$self->{open_elements}}; |
4319 |
wakaba |
1.52 |
} else { |
4320 |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
4321 |
|
|
## Ignore the token |
4322 |
wakaba |
1.1 |
} |
4323 |
wakaba |
1.52 |
!!!next-token; |
4324 |
|
|
redo B; |
4325 |
|
|
} elsif ($token->{tag_name} eq 'select') { |
4326 |
|
|
## have an element in table scope |
4327 |
|
|
my $i; |
4328 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4329 |
|
|
my $node = $self->{open_elements}->[$_]; |
4330 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
4331 |
|
|
$i = $_; |
4332 |
|
|
last INSCOPE; |
4333 |
|
|
} elsif ({ |
4334 |
|
|
table => 1, html => 1, |
4335 |
|
|
}->{$node->[1]}) { |
4336 |
|
|
last INSCOPE; |
4337 |
wakaba |
1.48 |
} |
4338 |
wakaba |
1.52 |
} # INSCOPE |
4339 |
|
|
unless (defined $i) { |
4340 |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
4341 |
|
|
## Ignore the token |
4342 |
|
|
!!!next-token; |
4343 |
wakaba |
1.48 |
redo B; |
4344 |
wakaba |
1.52 |
} |
4345 |
|
|
|
4346 |
|
|
splice @{$self->{open_elements}}, $i; |
4347 |
|
|
|
4348 |
|
|
$self->_reset_insertion_mode; |
4349 |
|
|
|
4350 |
|
|
!!!next-token; |
4351 |
|
|
redo B; |
4352 |
|
|
} elsif ({ |
4353 |
|
|
caption => 1, table => 1, tbody => 1, |
4354 |
|
|
tfoot => 1, thead => 1, tr => 1, td => 1, th => 1, |
4355 |
|
|
}->{$token->{tag_name}}) { |
4356 |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
4357 |
|
|
|
4358 |
|
|
## have an element in table scope |
4359 |
|
|
my $i; |
4360 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4361 |
|
|
my $node = $self->{open_elements}->[$_]; |
4362 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
4363 |
|
|
$i = $_; |
4364 |
|
|
last INSCOPE; |
4365 |
|
|
} elsif ({ |
4366 |
|
|
table => 1, html => 1, |
4367 |
|
|
}->{$node->[1]}) { |
4368 |
|
|
last INSCOPE; |
4369 |
wakaba |
1.1 |
} |
4370 |
wakaba |
1.52 |
} # INSCOPE |
4371 |
|
|
unless (defined $i) { |
4372 |
|
|
## Ignore the token |
4373 |
wakaba |
1.1 |
!!!next-token; |
4374 |
|
|
redo B; |
4375 |
|
|
} |
4376 |
wakaba |
1.52 |
|
4377 |
|
|
## As if </select> |
4378 |
|
|
## have an element in table scope |
4379 |
|
|
undef $i; |
4380 |
wakaba |
1.3 |
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4381 |
|
|
my $node = $self->{open_elements}->[$_]; |
4382 |
wakaba |
1.52 |
if ($node->[1] eq 'select') { |
4383 |
wakaba |
1.1 |
$i = $_; |
4384 |
|
|
last INSCOPE; |
4385 |
|
|
} elsif ({ |
4386 |
|
|
table => 1, html => 1, |
4387 |
wakaba |
1.52 |
}->{$node->[1]}) { |
4388 |
|
|
last INSCOPE; |
4389 |
|
|
} |
4390 |
|
|
} # INSCOPE |
4391 |
|
|
unless (defined $i) { |
4392 |
|
|
!!!parse-error (type => 'unmatched end tag:select'); |
4393 |
|
|
## Ignore the </select> token |
4394 |
|
|
!!!next-token; ## TODO: ok? |
4395 |
|
|
redo B; |
4396 |
|
|
} |
4397 |
|
|
|
4398 |
|
|
splice @{$self->{open_elements}}, $i; |
4399 |
|
|
|
4400 |
|
|
$self->_reset_insertion_mode; |
4401 |
|
|
|
4402 |
|
|
## reprocess |
4403 |
|
|
redo B; |
4404 |
wakaba |
1.58 |
} else { |
4405 |
|
|
!!!parse-error (type => 'in select:/'.$token->{tag_name}); |
4406 |
wakaba |
1.52 |
## Ignore the token |
4407 |
|
|
!!!next-token; |
4408 |
|
|
redo B; |
4409 |
wakaba |
1.58 |
} |
4410 |
|
|
} else { |
4411 |
|
|
die "$0: $token->{type}: Unknown token type"; |
4412 |
|
|
} |
4413 |
wakaba |
1.56 |
} elsif ($self->{insertion_mode} & BODY_AFTER_IMS) { |
4414 |
wakaba |
1.55 |
if ($token->{type} == CHARACTER_TOKEN) { |
4415 |
wakaba |
1.52 |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { |
4416 |
|
|
my $data = $1; |
4417 |
|
|
## As if in body |
4418 |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
4419 |
|
|
|
4420 |
|
|
$self->{open_elements}->[-1]->[0]->manakai_append_text ($1); |
4421 |
|
|
|
4422 |
|
|
unless (length $token->{data}) { |
4423 |
|
|
!!!next-token; |
4424 |
|
|
redo B; |
4425 |
|
|
} |
4426 |
|
|
} |
4427 |
|
|
|
4428 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) { |
4429 |
wakaba |
1.52 |
!!!parse-error (type => 'after html:#character'); |
4430 |
|
|
|
4431 |
|
|
## Reprocess in the "main" phase, "after body" insertion mode... |
4432 |
|
|
} |
4433 |
|
|
|
4434 |
|
|
## "after body" insertion mode |
4435 |
|
|
!!!parse-error (type => 'after body:#character'); |
4436 |
|
|
|
4437 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_BODY_IM; |
4438 |
wakaba |
1.52 |
## reprocess |
4439 |
|
|
redo B; |
4440 |
wakaba |
1.55 |
} elsif ($token->{type} == START_TAG_TOKEN) { |
4441 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) { |
4442 |
wakaba |
1.52 |
!!!parse-error (type => 'after html:'.$token->{tag_name}); |
4443 |
|
|
|
4444 |
|
|
## Reprocess in the "main" phase, "after body" insertion mode... |
4445 |
|
|
} |
4446 |
|
|
|
4447 |
|
|
## "after body" insertion mode |
4448 |
|
|
!!!parse-error (type => 'after body:'.$token->{tag_name}); |
4449 |
|
|
|
4450 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_BODY_IM; |
4451 |
wakaba |
1.52 |
## reprocess |
4452 |
|
|
redo B; |
4453 |
wakaba |
1.55 |
} elsif ($token->{type} == END_TAG_TOKEN) { |
4454 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) { |
4455 |
wakaba |
1.52 |
!!!parse-error (type => 'after html:/'.$token->{tag_name}); |
4456 |
|
|
|
4457 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_BODY_IM; |
4458 |
wakaba |
1.52 |
## Reprocess in the "main" phase, "after body" insertion mode... |
4459 |
|
|
} |
4460 |
|
|
|
4461 |
|
|
## "after body" insertion mode |
4462 |
|
|
if ($token->{tag_name} eq 'html') { |
4463 |
|
|
if (defined $self->{inner_html_node}) { |
4464 |
|
|
!!!parse-error (type => 'unmatched end tag:html'); |
4465 |
|
|
## Ignore the token |
4466 |
|
|
!!!next-token; |
4467 |
|
|
redo B; |
4468 |
|
|
} else { |
4469 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_HTML_BODY_IM; |
4470 |
wakaba |
1.52 |
!!!next-token; |
4471 |
|
|
redo B; |
4472 |
|
|
} |
4473 |
|
|
} else { |
4474 |
|
|
!!!parse-error (type => 'after body:/'.$token->{tag_name}); |
4475 |
|
|
|
4476 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_BODY_IM; |
4477 |
wakaba |
1.52 |
## reprocess |
4478 |
|
|
redo B; |
4479 |
|
|
} |
4480 |
|
|
} else { |
4481 |
|
|
die "$0: $token->{type}: Unknown token type"; |
4482 |
|
|
} |
4483 |
wakaba |
1.56 |
} elsif ($self->{insertion_mode} & FRAME_IMS) { |
4484 |
wakaba |
1.55 |
if ($token->{type} == CHARACTER_TOKEN) { |
4485 |
wakaba |
1.52 |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { |
4486 |
|
|
$self->{open_elements}->[-1]->[0]->manakai_append_text ($1); |
4487 |
|
|
|
4488 |
|
|
unless (length $token->{data}) { |
4489 |
|
|
!!!next-token; |
4490 |
|
|
redo B; |
4491 |
|
|
} |
4492 |
|
|
} |
4493 |
|
|
|
4494 |
|
|
if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) { |
4495 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_FRAMESET_IM) { |
4496 |
wakaba |
1.52 |
!!!parse-error (type => 'in frameset:#character'); |
4497 |
wakaba |
1.54 |
} elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) { |
4498 |
wakaba |
1.52 |
!!!parse-error (type => 'after frameset:#character'); |
4499 |
|
|
} else { # "after html frameset" |
4500 |
|
|
!!!parse-error (type => 'after html:#character'); |
4501 |
|
|
|
4502 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_FRAMESET_IM; |
4503 |
wakaba |
1.52 |
## Reprocess in the "main" phase, "after frameset"... |
4504 |
|
|
!!!parse-error (type => 'after frameset:#character'); |
4505 |
|
|
} |
4506 |
|
|
|
4507 |
|
|
## Ignore the token. |
4508 |
|
|
if (length $token->{data}) { |
4509 |
|
|
## reprocess the rest of characters |
4510 |
|
|
} else { |
4511 |
|
|
!!!next-token; |
4512 |
|
|
} |
4513 |
|
|
redo B; |
4514 |
|
|
} |
4515 |
|
|
|
4516 |
|
|
die qq[$0: Character "$token->{data}"]; |
4517 |
wakaba |
1.55 |
} elsif ($token->{type} == START_TAG_TOKEN) { |
4518 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) { |
4519 |
wakaba |
1.52 |
!!!parse-error (type => 'after html:'.$token->{tag_name}); |
4520 |
wakaba |
1.1 |
|
4521 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_FRAMESET_IM; |
4522 |
wakaba |
1.52 |
## Process in the "main" phase, "after frameset" insertion mode... |
4523 |
|
|
} |
4524 |
wakaba |
1.1 |
|
4525 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'frameset' and |
4526 |
wakaba |
1.54 |
$self->{insertion_mode} == IN_FRAMESET_IM) { |
4527 |
wakaba |
1.52 |
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
4528 |
|
|
!!!next-token; |
4529 |
|
|
redo B; |
4530 |
|
|
} elsif ($token->{tag_name} eq 'frame' and |
4531 |
wakaba |
1.54 |
$self->{insertion_mode} == IN_FRAMESET_IM) { |
4532 |
wakaba |
1.52 |
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
4533 |
|
|
pop @{$self->{open_elements}}; |
4534 |
|
|
!!!next-token; |
4535 |
|
|
redo B; |
4536 |
|
|
} elsif ($token->{tag_name} eq 'noframes') { |
4537 |
|
|
## NOTE: As if in body. |
4538 |
|
|
$parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current); |
4539 |
|
|
redo B; |
4540 |
|
|
} else { |
4541 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_FRAMESET_IM) { |
4542 |
wakaba |
1.52 |
!!!parse-error (type => 'in frameset:'.$token->{tag_name}); |
4543 |
|
|
} else { |
4544 |
|
|
!!!parse-error (type => 'after frameset:'.$token->{tag_name}); |
4545 |
|
|
} |
4546 |
|
|
## Ignore the token |
4547 |
|
|
!!!next-token; |
4548 |
|
|
redo B; |
4549 |
|
|
} |
4550 |
wakaba |
1.55 |
} elsif ($token->{type} == END_TAG_TOKEN) { |
4551 |
wakaba |
1.54 |
if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) { |
4552 |
wakaba |
1.52 |
!!!parse-error (type => 'after html:/'.$token->{tag_name}); |
4553 |
wakaba |
1.1 |
|
4554 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_FRAMESET_IM; |
4555 |
wakaba |
1.52 |
## Process in the "main" phase, "after frameset" insertion mode... |
4556 |
|
|
} |
4557 |
wakaba |
1.1 |
|
4558 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'frameset' and |
4559 |
wakaba |
1.54 |
$self->{insertion_mode} == IN_FRAMESET_IM) { |
4560 |
wakaba |
1.52 |
if ($self->{open_elements}->[-1]->[1] eq 'html' and |
4561 |
|
|
@{$self->{open_elements}} == 1) { |
4562 |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
4563 |
|
|
## Ignore the token |
4564 |
|
|
!!!next-token; |
4565 |
|
|
} else { |
4566 |
|
|
pop @{$self->{open_elements}}; |
4567 |
|
|
!!!next-token; |
4568 |
|
|
} |
4569 |
wakaba |
1.47 |
|
4570 |
wakaba |
1.52 |
if (not defined $self->{inner_html_node} and |
4571 |
|
|
$self->{open_elements}->[-1]->[1] ne 'frameset') { |
4572 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_FRAMESET_IM; |
4573 |
wakaba |
1.52 |
} |
4574 |
|
|
redo B; |
4575 |
|
|
} elsif ($token->{tag_name} eq 'html' and |
4576 |
wakaba |
1.54 |
$self->{insertion_mode} == AFTER_FRAMESET_IM) { |
4577 |
|
|
$self->{insertion_mode} = AFTER_HTML_FRAMESET_IM; |
4578 |
wakaba |
1.52 |
!!!next-token; |
4579 |
|
|
redo B; |
4580 |
|
|
} else { |
4581 |
wakaba |
1.54 |
if ($self->{insertion_mode} == IN_FRAMESET_IM) { |
4582 |
wakaba |
1.52 |
!!!parse-error (type => 'in frameset:/'.$token->{tag_name}); |
4583 |
|
|
} else { |
4584 |
|
|
!!!parse-error (type => 'after frameset:/'.$token->{tag_name}); |
4585 |
|
|
} |
4586 |
|
|
## Ignore the token |
4587 |
|
|
!!!next-token; |
4588 |
|
|
redo B; |
4589 |
|
|
} |
4590 |
|
|
} else { |
4591 |
|
|
die "$0: $token->{type}: Unknown token type"; |
4592 |
|
|
} |
4593 |
wakaba |
1.47 |
|
4594 |
wakaba |
1.52 |
## ISSUE: An issue in spec here |
4595 |
|
|
} else { |
4596 |
|
|
die "$0: $self->{insertion_mode}: Unknown insertion mode"; |
4597 |
|
|
} |
4598 |
wakaba |
1.47 |
|
4599 |
wakaba |
1.52 |
## "in body" insertion mode |
4600 |
wakaba |
1.55 |
if ($token->{type} == START_TAG_TOKEN) { |
4601 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'script') { |
4602 |
|
|
## NOTE: This is an "as if in head" code clone |
4603 |
|
|
$script_start_tag->($insert); |
4604 |
wakaba |
1.53 |
redo B; |
4605 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'style') { |
4606 |
|
|
## NOTE: This is an "as if in head" code clone |
4607 |
|
|
$parse_rcdata->(CDATA_CONTENT_MODEL, $insert); |
4608 |
wakaba |
1.53 |
redo B; |
4609 |
wakaba |
1.52 |
} elsif ({ |
4610 |
|
|
base => 1, link => 1, |
4611 |
|
|
}->{$token->{tag_name}}) { |
4612 |
|
|
## NOTE: This is an "as if in head" code clone, only "-t" differs |
4613 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4614 |
|
|
pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec. |
4615 |
|
|
!!!next-token; |
4616 |
wakaba |
1.53 |
redo B; |
4617 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'meta') { |
4618 |
|
|
## NOTE: This is an "as if in head" code clone, only "-t" differs |
4619 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4620 |
wakaba |
1.66 |
my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec. |
4621 |
wakaba |
1.46 |
|
4622 |
wakaba |
1.52 |
unless ($self->{confident}) { |
4623 |
|
|
if ($token->{attributes}->{charset}) { ## TODO: And if supported |
4624 |
wakaba |
1.63 |
$self->{change_encoding} |
4625 |
|
|
->($self, $token->{attributes}->{charset}->{value}); |
4626 |
wakaba |
1.66 |
|
4627 |
|
|
$meta_el->[0]->get_attribute_node_ns (undef, 'charset') |
4628 |
|
|
->set_user_data (manakai_has_reference => |
4629 |
|
|
$token->{attributes}->{charset} |
4630 |
|
|
->{has_reference}); |
4631 |
wakaba |
1.63 |
} elsif ($token->{attributes}->{content}) { |
4632 |
wakaba |
1.52 |
## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition. |
4633 |
wakaba |
1.63 |
if ($token->{attributes}->{content}->{value} |
4634 |
wakaba |
1.70 |
=~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt] |
4635 |
|
|
[\x09-\x0D\x20]*= |
4636 |
wakaba |
1.52 |
[\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'| |
4637 |
|
|
([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) { |
4638 |
wakaba |
1.63 |
$self->{change_encoding} |
4639 |
|
|
->($self, defined $1 ? $1 : defined $2 ? $2 : $3); |
4640 |
wakaba |
1.68 |
$meta_el->[0]->get_attribute_node_ns (undef, 'content') |
4641 |
|
|
->set_user_data (manakai_has_reference => |
4642 |
|
|
$token->{attributes}->{content} |
4643 |
|
|
->{has_reference}); |
4644 |
wakaba |
1.63 |
} |
4645 |
wakaba |
1.52 |
} |
4646 |
wakaba |
1.66 |
} else { |
4647 |
|
|
if ($token->{attributes}->{charset}) { |
4648 |
|
|
$meta_el->[0]->get_attribute_node_ns (undef, 'charset') |
4649 |
|
|
->set_user_data (manakai_has_reference => |
4650 |
|
|
$token->{attributes}->{charset} |
4651 |
|
|
->{has_reference}); |
4652 |
|
|
} |
4653 |
wakaba |
1.68 |
if ($token->{attributes}->{content}) { |
4654 |
|
|
$meta_el->[0]->get_attribute_node_ns (undef, 'content') |
4655 |
|
|
->set_user_data (manakai_has_reference => |
4656 |
|
|
$token->{attributes}->{content} |
4657 |
|
|
->{has_reference}); |
4658 |
|
|
} |
4659 |
wakaba |
1.52 |
} |
4660 |
wakaba |
1.1 |
|
4661 |
wakaba |
1.52 |
!!!next-token; |
4662 |
wakaba |
1.53 |
redo B; |
4663 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'title') { |
4664 |
|
|
!!!parse-error (type => 'in body:title'); |
4665 |
|
|
## NOTE: This is an "as if in head" code clone |
4666 |
|
|
$parse_rcdata->(RCDATA_CONTENT_MODEL, sub { |
4667 |
|
|
if (defined $self->{head_element}) { |
4668 |
|
|
$self->{head_element}->append_child ($_[0]); |
4669 |
|
|
} else { |
4670 |
|
|
$insert->($_[0]); |
4671 |
|
|
} |
4672 |
|
|
}); |
4673 |
wakaba |
1.53 |
redo B; |
4674 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'body') { |
4675 |
|
|
!!!parse-error (type => 'in body:body'); |
4676 |
wakaba |
1.46 |
|
4677 |
wakaba |
1.52 |
if (@{$self->{open_elements}} == 1 or |
4678 |
|
|
$self->{open_elements}->[1]->[1] ne 'body') { |
4679 |
|
|
## Ignore the token |
4680 |
|
|
} else { |
4681 |
|
|
my $body_el = $self->{open_elements}->[1]->[0]; |
4682 |
|
|
for my $attr_name (keys %{$token->{attributes}}) { |
4683 |
|
|
unless ($body_el->has_attribute_ns (undef, $attr_name)) { |
4684 |
|
|
$body_el->set_attribute_ns |
4685 |
|
|
(undef, [undef, $attr_name], |
4686 |
|
|
$token->{attributes}->{$attr_name}->{value}); |
4687 |
|
|
} |
4688 |
|
|
} |
4689 |
|
|
} |
4690 |
|
|
!!!next-token; |
4691 |
wakaba |
1.53 |
redo B; |
4692 |
wakaba |
1.52 |
} elsif ({ |
4693 |
|
|
address => 1, blockquote => 1, center => 1, dir => 1, |
4694 |
|
|
div => 1, dl => 1, fieldset => 1, listing => 1, |
4695 |
|
|
menu => 1, ol => 1, p => 1, ul => 1, |
4696 |
|
|
pre => 1, |
4697 |
|
|
}->{$token->{tag_name}}) { |
4698 |
|
|
## has a p element in scope |
4699 |
|
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
4700 |
|
|
if ($_->[1] eq 'p') { |
4701 |
|
|
!!!back-token; |
4702 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, tag_name => 'p'}; |
4703 |
wakaba |
1.53 |
redo B; |
4704 |
wakaba |
1.52 |
} elsif ({ |
4705 |
|
|
table => 1, caption => 1, td => 1, th => 1, |
4706 |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
4707 |
|
|
}->{$_->[1]}) { |
4708 |
|
|
last INSCOPE; |
4709 |
|
|
} |
4710 |
|
|
} # INSCOPE |
4711 |
|
|
|
4712 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4713 |
|
|
if ($token->{tag_name} eq 'pre') { |
4714 |
|
|
!!!next-token; |
4715 |
wakaba |
1.55 |
if ($token->{type} == CHARACTER_TOKEN) { |
4716 |
wakaba |
1.52 |
$token->{data} =~ s/^\x0A//; |
4717 |
|
|
unless (length $token->{data}) { |
4718 |
wakaba |
1.1 |
!!!next-token; |
4719 |
wakaba |
1.52 |
} |
4720 |
|
|
} |
4721 |
|
|
} else { |
4722 |
|
|
!!!next-token; |
4723 |
|
|
} |
4724 |
wakaba |
1.53 |
redo B; |
4725 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'form') { |
4726 |
|
|
if (defined $self->{form_element}) { |
4727 |
|
|
!!!parse-error (type => 'in form:form'); |
4728 |
|
|
## Ignore the token |
4729 |
|
|
!!!next-token; |
4730 |
wakaba |
1.53 |
redo B; |
4731 |
wakaba |
1.52 |
} else { |
4732 |
|
|
## has a p element in scope |
4733 |
|
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
4734 |
|
|
if ($_->[1] eq 'p') { |
4735 |
|
|
!!!back-token; |
4736 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, tag_name => 'p'}; |
4737 |
wakaba |
1.53 |
redo B; |
4738 |
wakaba |
1.46 |
} elsif ({ |
4739 |
wakaba |
1.52 |
table => 1, caption => 1, td => 1, th => 1, |
4740 |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
4741 |
|
|
}->{$_->[1]}) { |
4742 |
|
|
last INSCOPE; |
4743 |
|
|
} |
4744 |
|
|
} # INSCOPE |
4745 |
|
|
|
4746 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4747 |
|
|
$self->{form_element} = $self->{open_elements}->[-1]->[0]; |
4748 |
|
|
!!!next-token; |
4749 |
wakaba |
1.53 |
redo B; |
4750 |
wakaba |
1.52 |
} |
4751 |
|
|
} elsif ($token->{tag_name} eq 'li') { |
4752 |
|
|
## has a p element in scope |
4753 |
|
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
4754 |
|
|
if ($_->[1] eq 'p') { |
4755 |
|
|
!!!back-token; |
4756 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, tag_name => 'p'}; |
4757 |
wakaba |
1.53 |
redo B; |
4758 |
wakaba |
1.52 |
} elsif ({ |
4759 |
|
|
table => 1, caption => 1, td => 1, th => 1, |
4760 |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
4761 |
|
|
}->{$_->[1]}) { |
4762 |
|
|
last INSCOPE; |
4763 |
|
|
} |
4764 |
|
|
} # INSCOPE |
4765 |
|
|
|
4766 |
|
|
## Step 1 |
4767 |
|
|
my $i = -1; |
4768 |
|
|
my $node = $self->{open_elements}->[$i]; |
4769 |
|
|
LI: { |
4770 |
|
|
## Step 2 |
4771 |
|
|
if ($node->[1] eq 'li') { |
4772 |
|
|
if ($i != -1) { |
4773 |
|
|
!!!parse-error (type => 'end tag missing:'. |
4774 |
|
|
$self->{open_elements}->[-1]->[1]); |
4775 |
|
|
} |
4776 |
|
|
splice @{$self->{open_elements}}, $i; |
4777 |
|
|
last LI; |
4778 |
|
|
} |
4779 |
|
|
|
4780 |
|
|
## Step 3 |
4781 |
|
|
if (not $formatting_category->{$node->[1]} and |
4782 |
|
|
#not $phrasing_category->{$node->[1]} and |
4783 |
|
|
($special_category->{$node->[1]} or |
4784 |
|
|
$scoping_category->{$node->[1]}) and |
4785 |
|
|
$node->[1] ne 'address' and $node->[1] ne 'div') { |
4786 |
|
|
last LI; |
4787 |
|
|
} |
4788 |
|
|
|
4789 |
|
|
## Step 4 |
4790 |
|
|
$i--; |
4791 |
|
|
$node = $self->{open_elements}->[$i]; |
4792 |
|
|
redo LI; |
4793 |
|
|
} # LI |
4794 |
|
|
|
4795 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4796 |
|
|
!!!next-token; |
4797 |
wakaba |
1.53 |
redo B; |
4798 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'dd' or $token->{tag_name} eq 'dt') { |
4799 |
|
|
## has a p element in scope |
4800 |
|
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
4801 |
|
|
if ($_->[1] eq 'p') { |
4802 |
|
|
!!!back-token; |
4803 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, tag_name => 'p'}; |
4804 |
wakaba |
1.53 |
redo B; |
4805 |
wakaba |
1.52 |
} elsif ({ |
4806 |
|
|
table => 1, caption => 1, td => 1, th => 1, |
4807 |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
4808 |
|
|
}->{$_->[1]}) { |
4809 |
|
|
last INSCOPE; |
4810 |
|
|
} |
4811 |
|
|
} # INSCOPE |
4812 |
|
|
|
4813 |
|
|
## Step 1 |
4814 |
|
|
my $i = -1; |
4815 |
|
|
my $node = $self->{open_elements}->[$i]; |
4816 |
|
|
LI: { |
4817 |
|
|
## Step 2 |
4818 |
|
|
if ($node->[1] eq 'dt' or $node->[1] eq 'dd') { |
4819 |
|
|
if ($i != -1) { |
4820 |
|
|
!!!parse-error (type => 'end tag missing:'. |
4821 |
|
|
$self->{open_elements}->[-1]->[1]); |
4822 |
wakaba |
1.1 |
} |
4823 |
wakaba |
1.52 |
splice @{$self->{open_elements}}, $i; |
4824 |
|
|
last LI; |
4825 |
|
|
} |
4826 |
|
|
|
4827 |
|
|
## Step 3 |
4828 |
|
|
if (not $formatting_category->{$node->[1]} and |
4829 |
|
|
#not $phrasing_category->{$node->[1]} and |
4830 |
|
|
($special_category->{$node->[1]} or |
4831 |
|
|
$scoping_category->{$node->[1]}) and |
4832 |
|
|
$node->[1] ne 'address' and $node->[1] ne 'div') { |
4833 |
|
|
last LI; |
4834 |
wakaba |
1.1 |
} |
4835 |
wakaba |
1.52 |
|
4836 |
|
|
## Step 4 |
4837 |
|
|
$i--; |
4838 |
|
|
$node = $self->{open_elements}->[$i]; |
4839 |
|
|
redo LI; |
4840 |
|
|
} # LI |
4841 |
|
|
|
4842 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4843 |
|
|
!!!next-token; |
4844 |
wakaba |
1.53 |
redo B; |
4845 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'plaintext') { |
4846 |
|
|
## has a p element in scope |
4847 |
|
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
4848 |
|
|
if ($_->[1] eq 'p') { |
4849 |
|
|
!!!back-token; |
4850 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, tag_name => 'p'}; |
4851 |
wakaba |
1.53 |
redo B; |
4852 |
wakaba |
1.52 |
} elsif ({ |
4853 |
|
|
table => 1, caption => 1, td => 1, th => 1, |
4854 |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
4855 |
|
|
}->{$_->[1]}) { |
4856 |
|
|
last INSCOPE; |
4857 |
wakaba |
1.46 |
} |
4858 |
wakaba |
1.52 |
} # INSCOPE |
4859 |
|
|
|
4860 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4861 |
|
|
|
4862 |
|
|
$self->{content_model} = PLAINTEXT_CONTENT_MODEL; |
4863 |
|
|
|
4864 |
|
|
!!!next-token; |
4865 |
wakaba |
1.53 |
redo B; |
4866 |
wakaba |
1.52 |
} elsif ({ |
4867 |
|
|
h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1, |
4868 |
|
|
}->{$token->{tag_name}}) { |
4869 |
|
|
## has a p element in scope |
4870 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4871 |
|
|
my $node = $self->{open_elements}->[$_]; |
4872 |
|
|
if ($node->[1] eq 'p') { |
4873 |
|
|
!!!back-token; |
4874 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, tag_name => 'p'}; |
4875 |
wakaba |
1.53 |
redo B; |
4876 |
wakaba |
1.52 |
} elsif ({ |
4877 |
|
|
table => 1, caption => 1, td => 1, th => 1, |
4878 |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
4879 |
|
|
}->{$node->[1]}) { |
4880 |
|
|
last INSCOPE; |
4881 |
wakaba |
1.46 |
} |
4882 |
wakaba |
1.52 |
} # INSCOPE |
4883 |
|
|
|
4884 |
|
|
## NOTE: See <http://html5.org/tools/web-apps-tracker?from=925&to=926> |
4885 |
|
|
## has an element in scope |
4886 |
|
|
#my $i; |
4887 |
|
|
#INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4888 |
|
|
# my $node = $self->{open_elements}->[$_]; |
4889 |
|
|
# if ({ |
4890 |
|
|
# h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1, |
4891 |
|
|
# }->{$node->[1]}) { |
4892 |
|
|
# $i = $_; |
4893 |
|
|
# last INSCOPE; |
4894 |
|
|
# } elsif ({ |
4895 |
|
|
# table => 1, caption => 1, td => 1, th => 1, |
4896 |
|
|
# button => 1, marquee => 1, object => 1, html => 1, |
4897 |
|
|
# }->{$node->[1]}) { |
4898 |
|
|
# last INSCOPE; |
4899 |
|
|
# } |
4900 |
|
|
#} # INSCOPE |
4901 |
|
|
# |
4902 |
|
|
#if (defined $i) { |
4903 |
|
|
# !!! parse-error (type => 'in hn:hn'); |
4904 |
|
|
# splice @{$self->{open_elements}}, $i; |
4905 |
|
|
#} |
4906 |
|
|
|
4907 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4908 |
|
|
|
4909 |
|
|
!!!next-token; |
4910 |
wakaba |
1.53 |
redo B; |
4911 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'a') { |
4912 |
|
|
AFE: for my $i (reverse 0..$#$active_formatting_elements) { |
4913 |
|
|
my $node = $active_formatting_elements->[$i]; |
4914 |
|
|
if ($node->[1] eq 'a') { |
4915 |
|
|
!!!parse-error (type => 'in a:a'); |
4916 |
|
|
|
4917 |
|
|
!!!back-token; |
4918 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, tag_name => 'a'}; |
4919 |
wakaba |
1.52 |
$formatting_end_tag->($token->{tag_name}); |
4920 |
|
|
|
4921 |
|
|
AFE2: for (reverse 0..$#$active_formatting_elements) { |
4922 |
|
|
if ($active_formatting_elements->[$_]->[0] eq $node->[0]) { |
4923 |
|
|
splice @$active_formatting_elements, $_, 1; |
4924 |
|
|
last AFE2; |
4925 |
wakaba |
1.1 |
} |
4926 |
wakaba |
1.52 |
} # AFE2 |
4927 |
|
|
OE: for (reverse 0..$#{$self->{open_elements}}) { |
4928 |
|
|
if ($self->{open_elements}->[$_]->[0] eq $node->[0]) { |
4929 |
|
|
splice @{$self->{open_elements}}, $_, 1; |
4930 |
|
|
last OE; |
4931 |
wakaba |
1.1 |
} |
4932 |
wakaba |
1.52 |
} # OE |
4933 |
|
|
last AFE; |
4934 |
|
|
} elsif ($node->[0] eq '#marker') { |
4935 |
|
|
last AFE; |
4936 |
|
|
} |
4937 |
|
|
} # AFE |
4938 |
|
|
|
4939 |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
4940 |
wakaba |
1.1 |
|
4941 |
wakaba |
1.52 |
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4942 |
|
|
push @$active_formatting_elements, $self->{open_elements}->[-1]; |
4943 |
wakaba |
1.1 |
|
4944 |
wakaba |
1.52 |
!!!next-token; |
4945 |
wakaba |
1.53 |
redo B; |
4946 |
wakaba |
1.52 |
} elsif ({ |
4947 |
|
|
b => 1, big => 1, em => 1, font => 1, i => 1, |
4948 |
|
|
s => 1, small => 1, strile => 1, |
4949 |
|
|
strong => 1, tt => 1, u => 1, |
4950 |
|
|
}->{$token->{tag_name}}) { |
4951 |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
4952 |
|
|
|
4953 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4954 |
|
|
push @$active_formatting_elements, $self->{open_elements}->[-1]; |
4955 |
|
|
|
4956 |
|
|
!!!next-token; |
4957 |
wakaba |
1.53 |
redo B; |
4958 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'nobr') { |
4959 |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
4960 |
wakaba |
1.1 |
|
4961 |
wakaba |
1.52 |
## has a |nobr| element in scope |
4962 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4963 |
|
|
my $node = $self->{open_elements}->[$_]; |
4964 |
|
|
if ($node->[1] eq 'nobr') { |
4965 |
wakaba |
1.58 |
!!!parse-error (type => 'in nobr:nobr'); |
4966 |
wakaba |
1.52 |
!!!back-token; |
4967 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, tag_name => 'nobr'}; |
4968 |
wakaba |
1.53 |
redo B; |
4969 |
wakaba |
1.52 |
} elsif ({ |
4970 |
|
|
table => 1, caption => 1, td => 1, th => 1, |
4971 |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
4972 |
|
|
}->{$node->[1]}) { |
4973 |
|
|
last INSCOPE; |
4974 |
|
|
} |
4975 |
|
|
} # INSCOPE |
4976 |
|
|
|
4977 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4978 |
|
|
push @$active_formatting_elements, $self->{open_elements}->[-1]; |
4979 |
|
|
|
4980 |
|
|
!!!next-token; |
4981 |
wakaba |
1.53 |
redo B; |
4982 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'button') { |
4983 |
|
|
## has a button element in scope |
4984 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4985 |
|
|
my $node = $self->{open_elements}->[$_]; |
4986 |
|
|
if ($node->[1] eq 'button') { |
4987 |
|
|
!!!parse-error (type => 'in button:button'); |
4988 |
|
|
!!!back-token; |
4989 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, tag_name => 'button'}; |
4990 |
wakaba |
1.53 |
redo B; |
4991 |
wakaba |
1.52 |
} elsif ({ |
4992 |
|
|
table => 1, caption => 1, td => 1, th => 1, |
4993 |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
4994 |
|
|
}->{$node->[1]}) { |
4995 |
|
|
last INSCOPE; |
4996 |
|
|
} |
4997 |
|
|
} # INSCOPE |
4998 |
|
|
|
4999 |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
5000 |
|
|
|
5001 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
5002 |
|
|
push @$active_formatting_elements, ['#marker', '']; |
5003 |
wakaba |
1.1 |
|
5004 |
wakaba |
1.52 |
!!!next-token; |
5005 |
wakaba |
1.53 |
redo B; |
5006 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'marquee' or |
5007 |
|
|
$token->{tag_name} eq 'object') { |
5008 |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
5009 |
|
|
|
5010 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
5011 |
|
|
push @$active_formatting_elements, ['#marker', '']; |
5012 |
|
|
|
5013 |
|
|
!!!next-token; |
5014 |
wakaba |
1.53 |
redo B; |
5015 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'xmp') { |
5016 |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
5017 |
|
|
$parse_rcdata->(CDATA_CONTENT_MODEL, $insert); |
5018 |
wakaba |
1.53 |
redo B; |
5019 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'table') { |
5020 |
|
|
## has a p element in scope |
5021 |
|
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
5022 |
|
|
if ($_->[1] eq 'p') { |
5023 |
|
|
!!!back-token; |
5024 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, tag_name => 'p'}; |
5025 |
wakaba |
1.53 |
redo B; |
5026 |
wakaba |
1.52 |
} elsif ({ |
5027 |
|
|
table => 1, caption => 1, td => 1, th => 1, |
5028 |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
5029 |
|
|
}->{$_->[1]}) { |
5030 |
|
|
last INSCOPE; |
5031 |
|
|
} |
5032 |
|
|
} # INSCOPE |
5033 |
|
|
|
5034 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
5035 |
|
|
|
5036 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_TABLE_IM; |
5037 |
wakaba |
1.52 |
|
5038 |
|
|
!!!next-token; |
5039 |
wakaba |
1.53 |
redo B; |
5040 |
wakaba |
1.52 |
} elsif ({ |
5041 |
|
|
area => 1, basefont => 1, bgsound => 1, br => 1, |
5042 |
|
|
embed => 1, img => 1, param => 1, spacer => 1, wbr => 1, |
5043 |
|
|
image => 1, |
5044 |
|
|
}->{$token->{tag_name}}) { |
5045 |
|
|
if ($token->{tag_name} eq 'image') { |
5046 |
|
|
!!!parse-error (type => 'image'); |
5047 |
|
|
$token->{tag_name} = 'img'; |
5048 |
|
|
} |
5049 |
wakaba |
1.1 |
|
5050 |
wakaba |
1.52 |
## NOTE: There is an "as if <br>" code clone. |
5051 |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
5052 |
|
|
|
5053 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
5054 |
|
|
pop @{$self->{open_elements}}; |
5055 |
|
|
|
5056 |
|
|
!!!next-token; |
5057 |
wakaba |
1.53 |
redo B; |
5058 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'hr') { |
5059 |
|
|
## has a p element in scope |
5060 |
|
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
5061 |
|
|
if ($_->[1] eq 'p') { |
5062 |
|
|
!!!back-token; |
5063 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, tag_name => 'p'}; |
5064 |
wakaba |
1.53 |
redo B; |
5065 |
wakaba |
1.52 |
} elsif ({ |
5066 |
|
|
table => 1, caption => 1, td => 1, th => 1, |
5067 |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
5068 |
|
|
}->{$_->[1]}) { |
5069 |
|
|
last INSCOPE; |
5070 |
|
|
} |
5071 |
|
|
} # INSCOPE |
5072 |
|
|
|
5073 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
5074 |
|
|
pop @{$self->{open_elements}}; |
5075 |
|
|
|
5076 |
|
|
!!!next-token; |
5077 |
wakaba |
1.53 |
redo B; |
5078 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'input') { |
5079 |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
5080 |
|
|
|
5081 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
5082 |
|
|
## TODO: associate with $self->{form_element} if defined |
5083 |
|
|
pop @{$self->{open_elements}}; |
5084 |
|
|
|
5085 |
|
|
!!!next-token; |
5086 |
wakaba |
1.53 |
redo B; |
5087 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'isindex') { |
5088 |
|
|
!!!parse-error (type => 'isindex'); |
5089 |
|
|
|
5090 |
|
|
if (defined $self->{form_element}) { |
5091 |
|
|
## Ignore the token |
5092 |
|
|
!!!next-token; |
5093 |
wakaba |
1.53 |
redo B; |
5094 |
wakaba |
1.52 |
} else { |
5095 |
|
|
my $at = $token->{attributes}; |
5096 |
|
|
my $form_attrs; |
5097 |
|
|
$form_attrs->{action} = $at->{action} if $at->{action}; |
5098 |
|
|
my $prompt_attr = $at->{prompt}; |
5099 |
|
|
$at->{name} = {name => 'name', value => 'isindex'}; |
5100 |
|
|
delete $at->{action}; |
5101 |
|
|
delete $at->{prompt}; |
5102 |
|
|
my @tokens = ( |
5103 |
wakaba |
1.55 |
{type => START_TAG_TOKEN, tag_name => 'form', |
5104 |
wakaba |
1.52 |
attributes => $form_attrs}, |
5105 |
wakaba |
1.55 |
{type => START_TAG_TOKEN, tag_name => 'hr'}, |
5106 |
|
|
{type => START_TAG_TOKEN, tag_name => 'p'}, |
5107 |
|
|
{type => START_TAG_TOKEN, tag_name => 'label'}, |
5108 |
wakaba |
1.52 |
); |
5109 |
|
|
if ($prompt_attr) { |
5110 |
wakaba |
1.55 |
push @tokens, {type => CHARACTER_TOKEN, data => $prompt_attr->{value}}; |
5111 |
wakaba |
1.1 |
} else { |
5112 |
wakaba |
1.55 |
push @tokens, {type => CHARACTER_TOKEN, |
5113 |
wakaba |
1.52 |
data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD |
5114 |
|
|
## TODO: make this configurable |
5115 |
wakaba |
1.1 |
} |
5116 |
wakaba |
1.52 |
push @tokens, |
5117 |
wakaba |
1.55 |
{type => START_TAG_TOKEN, tag_name => 'input', attributes => $at}, |
5118 |
|
|
#{type => CHARACTER_TOKEN, data => ''}, # SHOULD |
5119 |
|
|
{type => END_TAG_TOKEN, tag_name => 'label'}, |
5120 |
|
|
{type => END_TAG_TOKEN, tag_name => 'p'}, |
5121 |
|
|
{type => START_TAG_TOKEN, tag_name => 'hr'}, |
5122 |
|
|
{type => END_TAG_TOKEN, tag_name => 'form'}; |
5123 |
wakaba |
1.52 |
$token = shift @tokens; |
5124 |
|
|
!!!back-token (@tokens); |
5125 |
wakaba |
1.53 |
redo B; |
5126 |
wakaba |
1.52 |
} |
5127 |
|
|
} elsif ($token->{tag_name} eq 'textarea') { |
5128 |
|
|
my $tag_name = $token->{tag_name}; |
5129 |
|
|
my $el; |
5130 |
|
|
!!!create-element ($el, $token->{tag_name}, $token->{attributes}); |
5131 |
|
|
|
5132 |
|
|
## TODO: $self->{form_element} if defined |
5133 |
|
|
$self->{content_model} = RCDATA_CONTENT_MODEL; |
5134 |
|
|
delete $self->{escape}; # MUST |
5135 |
|
|
|
5136 |
|
|
$insert->($el); |
5137 |
|
|
|
5138 |
|
|
my $text = ''; |
5139 |
|
|
!!!next-token; |
5140 |
wakaba |
1.55 |
if ($token->{type} == CHARACTER_TOKEN) { |
5141 |
wakaba |
1.52 |
$token->{data} =~ s/^\x0A//; |
5142 |
wakaba |
1.51 |
unless (length $token->{data}) { |
5143 |
|
|
!!!next-token; |
5144 |
|
|
} |
5145 |
|
|
} |
5146 |
wakaba |
1.55 |
while ($token->{type} == CHARACTER_TOKEN) { |
5147 |
wakaba |
1.52 |
$text .= $token->{data}; |
5148 |
|
|
!!!next-token; |
5149 |
|
|
} |
5150 |
|
|
if (length $text) { |
5151 |
|
|
$el->manakai_append_text ($text); |
5152 |
|
|
} |
5153 |
|
|
|
5154 |
|
|
$self->{content_model} = PCDATA_CONTENT_MODEL; |
5155 |
wakaba |
1.51 |
|
5156 |
wakaba |
1.55 |
if ($token->{type} == END_TAG_TOKEN and |
5157 |
wakaba |
1.52 |
$token->{tag_name} eq $tag_name) { |
5158 |
|
|
## Ignore the token |
5159 |
|
|
} else { |
5160 |
|
|
!!!parse-error (type => 'in RCDATA:#'.$token->{type}); |
5161 |
wakaba |
1.51 |
} |
5162 |
wakaba |
1.52 |
!!!next-token; |
5163 |
wakaba |
1.53 |
redo B; |
5164 |
wakaba |
1.52 |
} elsif ({ |
5165 |
|
|
iframe => 1, |
5166 |
|
|
noembed => 1, |
5167 |
|
|
noframes => 1, |
5168 |
|
|
noscript => 0, ## TODO: 1 if scripting is enabled |
5169 |
|
|
}->{$token->{tag_name}}) { |
5170 |
wakaba |
1.58 |
## NOTE: There is an "as if in body" code clone. |
5171 |
wakaba |
1.52 |
$parse_rcdata->(CDATA_CONTENT_MODEL, $insert); |
5172 |
wakaba |
1.53 |
redo B; |
5173 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'select') { |
5174 |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
5175 |
|
|
|
5176 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
5177 |
|
|
|
5178 |
wakaba |
1.54 |
$self->{insertion_mode} = IN_SELECT_IM; |
5179 |
wakaba |
1.52 |
!!!next-token; |
5180 |
wakaba |
1.53 |
redo B; |
5181 |
wakaba |
1.52 |
} elsif ({ |
5182 |
|
|
caption => 1, col => 1, colgroup => 1, frame => 1, |
5183 |
|
|
frameset => 1, head => 1, option => 1, optgroup => 1, |
5184 |
|
|
tbody => 1, td => 1, tfoot => 1, th => 1, |
5185 |
|
|
thead => 1, tr => 1, |
5186 |
|
|
}->{$token->{tag_name}}) { |
5187 |
|
|
!!!parse-error (type => 'in body:'.$token->{tag_name}); |
5188 |
|
|
## Ignore the token |
5189 |
|
|
!!!next-token; |
5190 |
wakaba |
1.53 |
redo B; |
5191 |
wakaba |
1.52 |
|
5192 |
|
|
## ISSUE: An issue on HTML5 new elements in the spec. |
5193 |
|
|
} else { |
5194 |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
5195 |
|
|
|
5196 |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
5197 |
wakaba |
1.51 |
|
5198 |
wakaba |
1.52 |
!!!next-token; |
5199 |
wakaba |
1.53 |
redo B; |
5200 |
wakaba |
1.52 |
} |
5201 |
wakaba |
1.55 |
} elsif ($token->{type} == END_TAG_TOKEN) { |
5202 |
wakaba |
1.52 |
if ($token->{tag_name} eq 'body') { |
5203 |
|
|
if (@{$self->{open_elements}} > 1 and |
5204 |
|
|
$self->{open_elements}->[1]->[1] eq 'body') { |
5205 |
|
|
for (@{$self->{open_elements}}) { |
5206 |
|
|
unless ({ |
5207 |
|
|
dd => 1, dt => 1, li => 1, p => 1, td => 1, |
5208 |
|
|
th => 1, tr => 1, body => 1, html => 1, |
5209 |
|
|
tbody => 1, tfoot => 1, thead => 1, |
5210 |
|
|
}->{$_->[1]}) { |
5211 |
|
|
!!!parse-error (type => 'not closed:'.$_->[1]); |
5212 |
|
|
} |
5213 |
|
|
} |
5214 |
wakaba |
1.51 |
|
5215 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_BODY_IM; |
5216 |
wakaba |
1.52 |
!!!next-token; |
5217 |
wakaba |
1.53 |
redo B; |
5218 |
wakaba |
1.52 |
} else { |
5219 |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
5220 |
|
|
## Ignore the token |
5221 |
|
|
!!!next-token; |
5222 |
wakaba |
1.53 |
redo B; |
5223 |
wakaba |
1.51 |
} |
5224 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'html') { |
5225 |
|
|
if (@{$self->{open_elements}} > 1 and $self->{open_elements}->[1]->[1] eq 'body') { |
5226 |
|
|
## ISSUE: There is an issue in the spec. |
5227 |
|
|
if ($self->{open_elements}->[-1]->[1] ne 'body') { |
5228 |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[1]->[1]); |
5229 |
wakaba |
1.1 |
} |
5230 |
wakaba |
1.54 |
$self->{insertion_mode} = AFTER_BODY_IM; |
5231 |
wakaba |
1.52 |
## reprocess |
5232 |
wakaba |
1.53 |
redo B; |
5233 |
wakaba |
1.51 |
} else { |
5234 |
wakaba |
1.52 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
5235 |
|
|
## Ignore the token |
5236 |
|
|
!!!next-token; |
5237 |
wakaba |
1.53 |
redo B; |
5238 |
wakaba |
1.51 |
} |
5239 |
wakaba |
1.52 |
} elsif ({ |
5240 |
|
|
address => 1, blockquote => 1, center => 1, dir => 1, |
5241 |
|
|
div => 1, dl => 1, fieldset => 1, listing => 1, |
5242 |
|
|
menu => 1, ol => 1, pre => 1, ul => 1, |
5243 |
|
|
p => 1, |
5244 |
|
|
dd => 1, dt => 1, li => 1, |
5245 |
|
|
button => 1, marquee => 1, object => 1, |
5246 |
|
|
}->{$token->{tag_name}}) { |
5247 |
|
|
## has an element in scope |
5248 |
|
|
my $i; |
5249 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
5250 |
|
|
my $node = $self->{open_elements}->[$_]; |
5251 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
5252 |
|
|
## generate implied end tags |
5253 |
|
|
if ({ |
5254 |
|
|
dd => ($token->{tag_name} ne 'dd'), |
5255 |
|
|
dt => ($token->{tag_name} ne 'dt'), |
5256 |
|
|
li => ($token->{tag_name} ne 'li'), |
5257 |
|
|
p => ($token->{tag_name} ne 'p'), |
5258 |
|
|
td => 1, th => 1, tr => 1, |
5259 |
|
|
tbody => 1, tfoot=> 1, thead => 1, |
5260 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
5261 |
|
|
!!!back-token; |
5262 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, |
5263 |
wakaba |
1.52 |
tag_name => $self->{open_elements}->[-1]->[1]}; # MUST |
5264 |
wakaba |
1.53 |
redo B; |
5265 |
wakaba |
1.52 |
} |
5266 |
|
|
$i = $_; |
5267 |
|
|
last INSCOPE unless $token->{tag_name} eq 'p'; |
5268 |
|
|
} elsif ({ |
5269 |
|
|
table => 1, caption => 1, td => 1, th => 1, |
5270 |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
5271 |
|
|
}->{$node->[1]}) { |
5272 |
|
|
last INSCOPE; |
5273 |
wakaba |
1.51 |
} |
5274 |
wakaba |
1.52 |
} # INSCOPE |
5275 |
|
|
|
5276 |
|
|
if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) { |
5277 |
|
|
if (defined $i) { |
5278 |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
5279 |
wakaba |
1.51 |
} else { |
5280 |
wakaba |
1.52 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
5281 |
wakaba |
1.51 |
} |
5282 |
|
|
} |
5283 |
|
|
|
5284 |
wakaba |
1.52 |
if (defined $i) { |
5285 |
|
|
splice @{$self->{open_elements}}, $i; |
5286 |
|
|
} elsif ($token->{tag_name} eq 'p') { |
5287 |
|
|
## As if <p>, then reprocess the current token |
5288 |
|
|
my $el; |
5289 |
|
|
!!!create-element ($el, 'p'); |
5290 |
|
|
$insert->($el); |
5291 |
wakaba |
1.51 |
} |
5292 |
wakaba |
1.52 |
$clear_up_to_marker->() |
5293 |
|
|
if { |
5294 |
|
|
button => 1, marquee => 1, object => 1, |
5295 |
|
|
}->{$token->{tag_name}}; |
5296 |
|
|
!!!next-token; |
5297 |
wakaba |
1.53 |
redo B; |
5298 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'form') { |
5299 |
|
|
## has an element in scope |
5300 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
5301 |
|
|
my $node = $self->{open_elements}->[$_]; |
5302 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
5303 |
|
|
## generate implied end tags |
5304 |
|
|
if ({ |
5305 |
|
|
dd => 1, dt => 1, li => 1, p => 1, |
5306 |
|
|
td => 1, th => 1, tr => 1, |
5307 |
|
|
tbody => 1, tfoot=> 1, thead => 1, |
5308 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
5309 |
|
|
!!!back-token; |
5310 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, |
5311 |
wakaba |
1.52 |
tag_name => $self->{open_elements}->[-1]->[1]}; # MUST |
5312 |
wakaba |
1.53 |
redo B; |
5313 |
wakaba |
1.52 |
} |
5314 |
|
|
last INSCOPE; |
5315 |
|
|
} elsif ({ |
5316 |
|
|
table => 1, caption => 1, td => 1, th => 1, |
5317 |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
5318 |
|
|
}->{$node->[1]}) { |
5319 |
|
|
last INSCOPE; |
5320 |
|
|
} |
5321 |
|
|
} # INSCOPE |
5322 |
|
|
|
5323 |
|
|
if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) { |
5324 |
wakaba |
1.36 |
pop @{$self->{open_elements}}; |
5325 |
|
|
} else { |
5326 |
wakaba |
1.58 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
5327 |
wakaba |
1.52 |
} |
5328 |
|
|
|
5329 |
|
|
undef $self->{form_element}; |
5330 |
|
|
!!!next-token; |
5331 |
wakaba |
1.53 |
redo B; |
5332 |
wakaba |
1.52 |
} elsif ({ |
5333 |
|
|
h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1, |
5334 |
|
|
}->{$token->{tag_name}}) { |
5335 |
|
|
## has an element in scope |
5336 |
|
|
my $i; |
5337 |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
5338 |
|
|
my $node = $self->{open_elements}->[$_]; |
5339 |
|
|
if ({ |
5340 |
|
|
h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1, |
5341 |
|
|
}->{$node->[1]}) { |
5342 |
|
|
## generate implied end tags |
5343 |
|
|
if ({ |
5344 |
|
|
dd => 1, dt => 1, li => 1, p => 1, |
5345 |
|
|
td => 1, th => 1, tr => 1, |
5346 |
|
|
tbody => 1, tfoot=> 1, thead => 1, |
5347 |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
5348 |
|
|
!!!back-token; |
5349 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, |
5350 |
wakaba |
1.52 |
tag_name => $self->{open_elements}->[-1]->[1]}; # MUST |
5351 |
wakaba |
1.53 |
redo B; |
5352 |
wakaba |
1.52 |
} |
5353 |
|
|
$i = $_; |
5354 |
|
|
last INSCOPE; |
5355 |
|
|
} elsif ({ |
5356 |
|
|
table => 1, caption => 1, td => 1, th => 1, |
5357 |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
5358 |
|
|
}->{$node->[1]}) { |
5359 |
|
|
last INSCOPE; |
5360 |
wakaba |
1.51 |
} |
5361 |
wakaba |
1.52 |
} # INSCOPE |
5362 |
|
|
|
5363 |
|
|
if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) { |
5364 |
wakaba |
1.58 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
5365 |
wakaba |
1.36 |
} |
5366 |
wakaba |
1.52 |
|
5367 |
|
|
splice @{$self->{open_elements}}, $i if defined $i; |
5368 |
|
|
!!!next-token; |
5369 |
wakaba |
1.53 |
redo B; |
5370 |
wakaba |
1.52 |
} elsif ({ |
5371 |
|
|
a => 1, |
5372 |
|
|
b => 1, big => 1, em => 1, font => 1, i => 1, |
5373 |
|
|
nobr => 1, s => 1, small => 1, strile => 1, |
5374 |
|
|
strong => 1, tt => 1, u => 1, |
5375 |
|
|
}->{$token->{tag_name}}) { |
5376 |
|
|
$formatting_end_tag->($token->{tag_name}); |
5377 |
wakaba |
1.53 |
redo B; |
5378 |
wakaba |
1.52 |
} elsif ($token->{tag_name} eq 'br') { |
5379 |
|
|
!!!parse-error (type => 'unmatched end tag:br'); |
5380 |
|
|
|
5381 |
|
|
## As if <br> |
5382 |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
5383 |
|
|
|
5384 |
|
|
my $el; |
5385 |
|
|
!!!create-element ($el, 'br'); |
5386 |
|
|
$insert->($el); |
5387 |
|
|
|
5388 |
|
|
## Ignore the token. |
5389 |
|
|
!!!next-token; |
5390 |
wakaba |
1.53 |
redo B; |
5391 |
wakaba |
1.52 |
} elsif ({ |
5392 |
|
|
caption => 1, col => 1, colgroup => 1, frame => 1, |
5393 |
|
|
frameset => 1, head => 1, option => 1, optgroup => 1, |
5394 |
|
|
tbody => 1, td => 1, tfoot => 1, th => 1, |
5395 |
|
|
thead => 1, tr => 1, |
5396 |
|
|
area => 1, basefont => 1, bgsound => 1, |
5397 |
|
|
embed => 1, hr => 1, iframe => 1, image => 1, |
5398 |
|
|
img => 1, input => 1, isindex => 1, noembed => 1, |
5399 |
|
|
noframes => 1, param => 1, select => 1, spacer => 1, |
5400 |
|
|
table => 1, textarea => 1, wbr => 1, |
5401 |
|
|
noscript => 0, ## TODO: if scripting is enabled |
5402 |
|
|
}->{$token->{tag_name}}) { |
5403 |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
5404 |
|
|
## Ignore the token |
5405 |
|
|
!!!next-token; |
5406 |
wakaba |
1.53 |
redo B; |
5407 |
wakaba |
1.52 |
|
5408 |
|
|
## ISSUE: Issue on HTML5 new elements in spec |
5409 |
|
|
|
5410 |
|
|
} else { |
5411 |
|
|
## Step 1 |
5412 |
|
|
my $node_i = -1; |
5413 |
|
|
my $node = $self->{open_elements}->[$node_i]; |
5414 |
wakaba |
1.51 |
|
5415 |
wakaba |
1.52 |
## Step 2 |
5416 |
|
|
S2: { |
5417 |
|
|
if ($node->[1] eq $token->{tag_name}) { |
5418 |
|
|
## Step 1 |
5419 |
|
|
## generate implied end tags |
5420 |
|
|
if ({ |
5421 |
|
|
dd => 1, dt => 1, li => 1, p => 1, |
5422 |
|
|
td => 1, th => 1, tr => 1, |
5423 |
wakaba |
1.55 |
tbody => 1, tfoot => 1, thead => 1, |
5424 |
wakaba |
1.52 |
}->{$self->{open_elements}->[-1]->[1]}) { |
5425 |
|
|
!!!back-token; |
5426 |
wakaba |
1.55 |
$token = {type => END_TAG_TOKEN, |
5427 |
wakaba |
1.52 |
tag_name => $self->{open_elements}->[-1]->[1]}; # MUST |
5428 |
wakaba |
1.53 |
redo B; |
5429 |
wakaba |
1.52 |
} |
5430 |
|
|
|
5431 |
|
|
## Step 2 |
5432 |
|
|
if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) { |
5433 |
wakaba |
1.58 |
## NOTE: <x><y></x> |
5434 |
wakaba |
1.52 |
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
5435 |
|
|
} |
5436 |
|
|
|
5437 |
|
|
## Step 3 |
5438 |
|
|
splice @{$self->{open_elements}}, $node_i; |
5439 |
wakaba |
1.51 |
|
5440 |
wakaba |
1.1 |
!!!next-token; |
5441 |
wakaba |
1.52 |
last S2; |
5442 |
wakaba |
1.1 |
} else { |
5443 |
wakaba |
1.52 |
## Step 3 |
5444 |
|
|
if (not $formatting_category->{$node->[1]} and |
5445 |
|
|
#not $phrasing_category->{$node->[1]} and |
5446 |
|
|
($special_category->{$node->[1]} or |
5447 |
|
|
$scoping_category->{$node->[1]})) { |
5448 |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
5449 |
|
|
## Ignore the token |
5450 |
|
|
!!!next-token; |
5451 |
|
|
last S2; |
5452 |
|
|
} |
5453 |
wakaba |
1.1 |
} |
5454 |
wakaba |
1.52 |
|
5455 |
|
|
## Step 4 |
5456 |
|
|
$node_i--; |
5457 |
|
|
$node = $self->{open_elements}->[$node_i]; |
5458 |
|
|
|
5459 |
|
|
## Step 5; |
5460 |
|
|
redo S2; |
5461 |
|
|
} # S2 |
5462 |
wakaba |
1.53 |
redo B; |
5463 |
wakaba |
1.1 |
} |
5464 |
|
|
} |
5465 |
wakaba |
1.52 |
redo B; |
5466 |
wakaba |
1.1 |
} # B |
5467 |
|
|
|
5468 |
wakaba |
1.51 |
## NOTE: The "trailing end" phase in HTML5 is split into |
5469 |
|
|
## two insertion modes: "after html body" and "after html frameset". |
5470 |
|
|
## NOTE: States in the main stage is preserved while |
5471 |
|
|
## the parser stays in the trailing end phase. # MUST |
5472 |
|
|
|
5473 |
wakaba |
1.1 |
## Stop parsing # MUST |
5474 |
|
|
|
5475 |
|
|
## TODO: script stuffs |
5476 |
wakaba |
1.3 |
} # _tree_construct_main |
5477 |
|
|
|
5478 |
|
|
sub set_inner_html ($$$) { |
5479 |
|
|
my $class = shift; |
5480 |
|
|
my $node = shift; |
5481 |
|
|
my $s = \$_[0]; |
5482 |
|
|
my $onerror = $_[1]; |
5483 |
|
|
|
5484 |
wakaba |
1.63 |
## ISSUE: Should {confident} be true? |
5485 |
|
|
|
5486 |
wakaba |
1.3 |
my $nt = $node->node_type; |
5487 |
|
|
if ($nt == 9) { |
5488 |
|
|
# MUST |
5489 |
|
|
|
5490 |
|
|
## Step 1 # MUST |
5491 |
|
|
## TODO: If the document has an active parser, ... |
5492 |
|
|
## ISSUE: There is an issue in the spec. |
5493 |
|
|
|
5494 |
|
|
## Step 2 # MUST |
5495 |
|
|
my @cn = @{$node->child_nodes}; |
5496 |
|
|
for (@cn) { |
5497 |
|
|
$node->remove_child ($_); |
5498 |
|
|
} |
5499 |
|
|
|
5500 |
|
|
## Step 3, 4, 5 # MUST |
5501 |
|
|
$class->parse_string ($$s => $node, $onerror); |
5502 |
|
|
} elsif ($nt == 1) { |
5503 |
|
|
## TODO: If non-html element |
5504 |
|
|
|
5505 |
|
|
## NOTE: Most of this code is copied from |parse_string| |
5506 |
|
|
|
5507 |
|
|
## Step 1 # MUST |
5508 |
wakaba |
1.14 |
my $this_doc = $node->owner_document; |
5509 |
|
|
my $doc = $this_doc->implementation->create_document; |
5510 |
wakaba |
1.18 |
$doc->manakai_is_html (1); |
5511 |
wakaba |
1.3 |
my $p = $class->new; |
5512 |
|
|
$p->{document} = $doc; |
5513 |
|
|
|
5514 |
|
|
## Step 9 # MUST |
5515 |
|
|
my $i = 0; |
5516 |
|
|
my $line = 1; |
5517 |
|
|
my $column = 0; |
5518 |
|
|
$p->{set_next_input_character} = sub { |
5519 |
|
|
my $self = shift; |
5520 |
wakaba |
1.14 |
|
5521 |
|
|
pop @{$self->{prev_input_character}}; |
5522 |
|
|
unshift @{$self->{prev_input_character}}, $self->{next_input_character}; |
5523 |
|
|
|
5524 |
wakaba |
1.3 |
$self->{next_input_character} = -1 and return if $i >= length $$s; |
5525 |
|
|
$self->{next_input_character} = ord substr $$s, $i++, 1; |
5526 |
|
|
$column++; |
5527 |
wakaba |
1.4 |
|
5528 |
|
|
if ($self->{next_input_character} == 0x000A) { # LF |
5529 |
|
|
$line++; |
5530 |
|
|
$column = 0; |
5531 |
|
|
} elsif ($self->{next_input_character} == 0x000D) { # CR |
5532 |
wakaba |
1.15 |
$i++ if substr ($$s, $i, 1) eq "\x0A"; |
5533 |
wakaba |
1.3 |
$self->{next_input_character} = 0x000A; # LF # MUST |
5534 |
|
|
$line++; |
5535 |
wakaba |
1.4 |
$column = 0; |
5536 |
wakaba |
1.3 |
} elsif ($self->{next_input_character} > 0x10FFFF) { |
5537 |
|
|
$self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST |
5538 |
|
|
} elsif ($self->{next_input_character} == 0x0000) { # NULL |
5539 |
wakaba |
1.14 |
!!!parse-error (type => 'NULL'); |
5540 |
wakaba |
1.3 |
$self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST |
5541 |
|
|
} |
5542 |
|
|
}; |
5543 |
wakaba |
1.14 |
$p->{prev_input_character} = [-1, -1, -1]; |
5544 |
|
|
$p->{next_input_character} = -1; |
5545 |
wakaba |
1.3 |
|
5546 |
|
|
my $ponerror = $onerror || sub { |
5547 |
|
|
my (%opt) = @_; |
5548 |
|
|
warn "Parse error ($opt{type}) at line $opt{line} column $opt{column}\n"; |
5549 |
|
|
}; |
5550 |
|
|
$p->{parse_error} = sub { |
5551 |
|
|
$ponerror->(@_, line => $line, column => $column); |
5552 |
|
|
}; |
5553 |
|
|
|
5554 |
|
|
$p->_initialize_tokenizer; |
5555 |
|
|
$p->_initialize_tree_constructor; |
5556 |
|
|
|
5557 |
|
|
## Step 2 |
5558 |
wakaba |
1.71 |
my $node_ln = $node->manakai_local_name; |
5559 |
wakaba |
1.40 |
$p->{content_model} = { |
5560 |
|
|
title => RCDATA_CONTENT_MODEL, |
5561 |
|
|
textarea => RCDATA_CONTENT_MODEL, |
5562 |
|
|
style => CDATA_CONTENT_MODEL, |
5563 |
|
|
script => CDATA_CONTENT_MODEL, |
5564 |
|
|
xmp => CDATA_CONTENT_MODEL, |
5565 |
|
|
iframe => CDATA_CONTENT_MODEL, |
5566 |
|
|
noembed => CDATA_CONTENT_MODEL, |
5567 |
|
|
noframes => CDATA_CONTENT_MODEL, |
5568 |
|
|
noscript => CDATA_CONTENT_MODEL, |
5569 |
|
|
plaintext => PLAINTEXT_CONTENT_MODEL, |
5570 |
|
|
}->{$node_ln}; |
5571 |
|
|
$p->{content_model} = PCDATA_CONTENT_MODEL |
5572 |
|
|
unless defined $p->{content_model}; |
5573 |
|
|
## ISSUE: What is "the name of the element"? local name? |
5574 |
wakaba |
1.3 |
|
5575 |
|
|
$p->{inner_html_node} = [$node, $node_ln]; |
5576 |
|
|
|
5577 |
|
|
## Step 4 |
5578 |
|
|
my $root = $doc->create_element_ns |
5579 |
|
|
('http://www.w3.org/1999/xhtml', [undef, 'html']); |
5580 |
|
|
|
5581 |
|
|
## Step 5 # MUST |
5582 |
|
|
$doc->append_child ($root); |
5583 |
|
|
|
5584 |
|
|
## Step 6 # MUST |
5585 |
|
|
push @{$p->{open_elements}}, [$root, 'html']; |
5586 |
|
|
|
5587 |
|
|
undef $p->{head_element}; |
5588 |
|
|
|
5589 |
|
|
## Step 7 # MUST |
5590 |
|
|
$p->_reset_insertion_mode; |
5591 |
|
|
|
5592 |
|
|
## Step 8 # MUST |
5593 |
|
|
my $anode = $node; |
5594 |
|
|
AN: while (defined $anode) { |
5595 |
|
|
if ($anode->node_type == 1) { |
5596 |
|
|
my $nsuri = $anode->namespace_uri; |
5597 |
|
|
if (defined $nsuri and $nsuri eq 'http://www.w3.org/1999/xhtml') { |
5598 |
wakaba |
1.71 |
if ($anode->manakai_local_name eq 'form') { |
5599 |
wakaba |
1.3 |
$p->{form_element} = $anode; |
5600 |
|
|
last AN; |
5601 |
|
|
} |
5602 |
|
|
} |
5603 |
|
|
} |
5604 |
|
|
$anode = $anode->parent_node; |
5605 |
|
|
} # AN |
5606 |
|
|
|
5607 |
|
|
## Step 3 # MUST |
5608 |
|
|
## Step 10 # MUST |
5609 |
|
|
{ |
5610 |
|
|
my $self = $p; |
5611 |
|
|
!!!next-token; |
5612 |
|
|
} |
5613 |
|
|
$p->_tree_construction_main; |
5614 |
|
|
|
5615 |
|
|
## Step 11 # MUST |
5616 |
|
|
my @cn = @{$node->child_nodes}; |
5617 |
|
|
for (@cn) { |
5618 |
|
|
$node->remove_child ($_); |
5619 |
|
|
} |
5620 |
|
|
## ISSUE: mutation events? read-only? |
5621 |
|
|
|
5622 |
|
|
## Step 12 # MUST |
5623 |
|
|
@cn = @{$root->child_nodes}; |
5624 |
|
|
for (@cn) { |
5625 |
wakaba |
1.14 |
$this_doc->adopt_node ($_); |
5626 |
wakaba |
1.3 |
$node->append_child ($_); |
5627 |
|
|
} |
5628 |
wakaba |
1.14 |
## ISSUE: mutation events? |
5629 |
wakaba |
1.3 |
|
5630 |
|
|
$p->_terminate_tree_constructor; |
5631 |
|
|
} else { |
5632 |
|
|
die "$0: |set_inner_html| is not defined for node of type $nt"; |
5633 |
|
|
} |
5634 |
|
|
} # set_inner_html |
5635 |
|
|
|
5636 |
|
|
} # tree construction stage |
5637 |
wakaba |
1.1 |
|
5638 |
wakaba |
1.63 |
package Whatpm::HTML::RestartParser; |
5639 |
|
|
push our @ISA, 'Error'; |
5640 |
|
|
|
5641 |
wakaba |
1.1 |
1; |
5642 |
wakaba |
1.73 |
# $Date: 2008/03/02 14:32:26 $ |