Parent Directory
|
Revision Log
|
Patch
| revision 1.33 by wakaba, Sat Jul 7 13:41:05 2007 UTC | revision 1.129 by wakaba, Sat Apr 12 15:37:33 2008 UTC | |
|---|---|---|
| # | Line 1 | Line 1 |
| 1 | package Whatpm::HTML; | package Whatpm::HTML; |
| 2 | use strict; | use strict; |
| 3 | our $VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; | our $VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
| 4 | use Error qw(:try); | |
| 5 | ||
| 6 | ## ISSUE: | ## ISSUE: |
| 7 | ## var doc = implementation.createDocument (null, null, null); | ## var doc = implementation.createDocument (null, null, null); |
| 8 | ## doc.write (''); | ## doc.write (''); |
| 9 | ## alert (doc.compatMode); | ## alert (doc.compatMode); |
| 10 | ||
| 11 | ## ISSUE: HTML5 revision 967 says that the encoding layer MUST NOT | ## TODO: Control charcters and noncharacters are not allowed (HTML5 revision 1263) |
| 12 | ## strip BOM and the HTML layer MUST ignore it. Whether we can do it | ## TODO: 1252 parse error (revision 1264) |
| 13 | ## is not yet clear. | ## TODO: 8859-11 = 874 (revision 1271) |
| 14 | ## "{U+FEFF}..." in UTF-16BE/UTF-16LE is three or four characters? | |
| 15 | ## "{U+FEFF}..." in GB18030? | my $HTML_NS = q<http://www.w3.org/1999/xhtml>; |
| 16 | my $MML_NS = q<http://www.w3.org/1998/Math/MathML>; | |
| 17 | my $permitted_slash_tag_name = { | my $SVG_NS = q<http://www.w3.org/2000/svg>; |
| 18 | base => 1, | my $XLINK_NS = q<http://www.w3.org/1999/xlink>; |
| 19 | link => 1, | my $XML_NS = q<http://www.w3.org/XML/1998/namespace>; |
| 20 | meta => 1, | my $XMLNS_NS = q<http://www.w3.org/2000/xmlns/>; |
| 21 | hr => 1, | |
| 22 | br => 1, | sub A_EL () { 0b1 } |
| 23 | img=> 1, | sub ADDRESS_EL () { 0b10 } |
| 24 | embed => 1, | sub BODY_EL () { 0b100 } |
| 25 | param => 1, | sub BUTTON_EL () { 0b1000 } |
| 26 | area => 1, | sub CAPTION_EL () { 0b10000 } |
| 27 | col => 1, | sub DD_EL () { 0b100000 } |
| 28 | input => 1, | sub DIV_EL () { 0b1000000 } |
| 29 | sub DT_EL () { 0b10000000 } | |
| 30 | sub FORM_EL () { 0b100000000 } | |
| 31 | sub FORMATTING_EL () { 0b1000000000 } | |
| 32 | sub FRAMESET_EL () { 0b10000000000 } | |
| 33 | sub HEADING_EL () { 0b100000000000 } | |
| 34 | sub HTML_EL () { 0b1000000000000 } | |
| 35 | sub LI_EL () { 0b10000000000000 } | |
| 36 | sub NOBR_EL () { 0b100000000000000 } | |
| 37 | sub OPTION_EL () { 0b1000000000000000 } | |
| 38 | sub OPTGROUP_EL () { 0b10000000000000000 } | |
| 39 | sub P_EL () { 0b100000000000000000 } | |
| 40 | sub SELECT_EL () { 0b1000000000000000000 } | |
| 41 | sub TABLE_EL () { 0b10000000000000000000 } | |
| 42 | sub TABLE_CELL_EL () { 0b100000000000000000000 } | |
| 43 | sub TABLE_ROW_EL () { 0b1000000000000000000000 } | |
| 44 | sub TABLE_ROW_GROUP_EL () { 0b10000000000000000000000 } | |
| 45 | sub MISC_SCOPING_EL () { 0b100000000000000000000000 } | |
| 46 | sub MISC_SPECIAL_EL () { 0b1000000000000000000000000 } | |
| 47 | sub FOREIGN_EL () { 0b10000000000000000000000000 } | |
| 48 | sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 } | |
| 49 | sub MML_AXML_EL () { 0b1000000000000000000000000000 } | |
| 50 | ||
| 51 | sub TABLE_ROWS_EL () { | |
| 52 | TABLE_EL | | |
| 53 | TABLE_ROW_EL | | |
| 54 | TABLE_ROW_GROUP_EL | |
| 55 | } | |
| 56 | ||
| 57 | sub END_TAG_OPTIONAL_EL () { | |
| 58 | DD_EL | | |
| 59 | DT_EL | | |
| 60 | LI_EL | | |
| 61 | P_EL | |
| 62 | } | |
| 63 | ||
| 64 | sub ALL_END_TAG_OPTIONAL_EL () { | |
| 65 | END_TAG_OPTIONAL_EL | | |
| 66 | BODY_EL | | |
| 67 | HTML_EL | | |
| 68 | TABLE_CELL_EL | | |
| 69 | TABLE_ROW_EL | | |
| 70 | TABLE_ROW_GROUP_EL | |
| 71 | } | |
| 72 | ||
| 73 | sub SCOPING_EL () { | |
| 74 | BUTTON_EL | | |
| 75 | CAPTION_EL | | |
| 76 | HTML_EL | | |
| 77 | TABLE_EL | | |
| 78 | TABLE_CELL_EL | | |
| 79 | MISC_SCOPING_EL | |
| 80 | } | |
| 81 | ||
| 82 | sub TABLE_SCOPING_EL () { | |
| 83 | HTML_EL | | |
| 84 | TABLE_EL | |
| 85 | } | |
| 86 | ||
| 87 | sub TABLE_ROWS_SCOPING_EL () { | |
| 88 | HTML_EL | | |
| 89 | TABLE_ROW_GROUP_EL | |
| 90 | } | |
| 91 | ||
| 92 | sub TABLE_ROW_SCOPING_EL () { | |
| 93 | HTML_EL | | |
| 94 | TABLE_ROW_EL | |
| 95 | } | |
| 96 | ||
| 97 | sub SPECIAL_EL () { | |
| 98 | ADDRESS_EL | | |
| 99 | BODY_EL | | |
| 100 | DIV_EL | | |
| 101 | END_TAG_OPTIONAL_EL | | |
| 102 | FORM_EL | | |
| 103 | FRAMESET_EL | | |
| 104 | HEADING_EL | | |
| 105 | OPTION_EL | | |
| 106 | OPTGROUP_EL | | |
| 107 | SELECT_EL | | |
| 108 | TABLE_ROW_EL | | |
| 109 | TABLE_ROW_GROUP_EL | | |
| 110 | MISC_SPECIAL_EL | |
| 111 | } | |
| 112 | ||
| 113 | my $el_category = { | |
| 114 | a => A_EL | FORMATTING_EL, | |
| 115 | address => ADDRESS_EL, | |
| 116 | applet => MISC_SCOPING_EL, | |
| 117 | area => MISC_SPECIAL_EL, | |
| 118 | b => FORMATTING_EL, | |
| 119 | base => MISC_SPECIAL_EL, | |
| 120 | basefont => MISC_SPECIAL_EL, | |
| 121 | bgsound => MISC_SPECIAL_EL, | |
| 122 | big => FORMATTING_EL, | |
| 123 | blockquote => MISC_SPECIAL_EL, | |
| 124 | body => BODY_EL, | |
| 125 | br => MISC_SPECIAL_EL, | |
| 126 | button => BUTTON_EL, | |
| 127 | caption => CAPTION_EL, | |
| 128 | center => MISC_SPECIAL_EL, | |
| 129 | col => MISC_SPECIAL_EL, | |
| 130 | colgroup => MISC_SPECIAL_EL, | |
| 131 | dd => DD_EL, | |
| 132 | dir => MISC_SPECIAL_EL, | |
| 133 | div => DIV_EL, | |
| 134 | dl => MISC_SPECIAL_EL, | |
| 135 | dt => DT_EL, | |
| 136 | em => FORMATTING_EL, | |
| 137 | embed => MISC_SPECIAL_EL, | |
| 138 | fieldset => MISC_SPECIAL_EL, | |
| 139 | font => FORMATTING_EL, | |
| 140 | form => FORM_EL, | |
| 141 | frame => MISC_SPECIAL_EL, | |
| 142 | frameset => FRAMESET_EL, | |
| 143 | h1 => HEADING_EL, | |
| 144 | h2 => HEADING_EL, | |
| 145 | h3 => HEADING_EL, | |
| 146 | h4 => HEADING_EL, | |
| 147 | h5 => HEADING_EL, | |
| 148 | h6 => HEADING_EL, | |
| 149 | head => MISC_SPECIAL_EL, | |
| 150 | hr => MISC_SPECIAL_EL, | |
| 151 | html => HTML_EL, | |
| 152 | i => FORMATTING_EL, | |
| 153 | iframe => MISC_SPECIAL_EL, | |
| 154 | img => MISC_SPECIAL_EL, | |
| 155 | input => MISC_SPECIAL_EL, | |
| 156 | isindex => MISC_SPECIAL_EL, | |
| 157 | li => LI_EL, | |
| 158 | link => MISC_SPECIAL_EL, | |
| 159 | listing => MISC_SPECIAL_EL, | |
| 160 | marquee => MISC_SCOPING_EL, | |
| 161 | menu => MISC_SPECIAL_EL, | |
| 162 | meta => MISC_SPECIAL_EL, | |
| 163 | nobr => NOBR_EL | FORMATTING_EL, | |
| 164 | noembed => MISC_SPECIAL_EL, | |
| 165 | noframes => MISC_SPECIAL_EL, | |
| 166 | noscript => MISC_SPECIAL_EL, | |
| 167 | object => MISC_SCOPING_EL, | |
| 168 | ol => MISC_SPECIAL_EL, | |
| 169 | optgroup => OPTGROUP_EL, | |
| 170 | option => OPTION_EL, | |
| 171 | p => P_EL, | |
| 172 | param => MISC_SPECIAL_EL, | |
| 173 | plaintext => MISC_SPECIAL_EL, | |
| 174 | pre => MISC_SPECIAL_EL, | |
| 175 | s => FORMATTING_EL, | |
| 176 | script => MISC_SPECIAL_EL, | |
| 177 | select => SELECT_EL, | |
| 178 | small => FORMATTING_EL, | |
| 179 | spacer => MISC_SPECIAL_EL, | |
| 180 | strike => FORMATTING_EL, | |
| 181 | strong => FORMATTING_EL, | |
| 182 | style => MISC_SPECIAL_EL, | |
| 183 | table => TABLE_EL, | |
| 184 | tbody => TABLE_ROW_GROUP_EL, | |
| 185 | td => TABLE_CELL_EL, | |
| 186 | textarea => MISC_SPECIAL_EL, | |
| 187 | tfoot => TABLE_ROW_GROUP_EL, | |
| 188 | th => TABLE_CELL_EL, | |
| 189 | thead => TABLE_ROW_GROUP_EL, | |
| 190 | title => MISC_SPECIAL_EL, | |
| 191 | tr => TABLE_ROW_EL, | |
| 192 | tt => FORMATTING_EL, | |
| 193 | u => FORMATTING_EL, | |
| 194 | ul => MISC_SPECIAL_EL, | |
| 195 | wbr => MISC_SPECIAL_EL, | |
| 196 | }; | |
| 197 | ||
| 198 | my $el_category_f = { | |
| 199 | $MML_NS => { | |
| 200 | 'annotation-xml' => MML_AXML_EL, | |
| 201 | mi => FOREIGN_FLOW_CONTENT_EL, | |
| 202 | mo => FOREIGN_FLOW_CONTENT_EL, | |
| 203 | mn => FOREIGN_FLOW_CONTENT_EL, | |
| 204 | ms => FOREIGN_FLOW_CONTENT_EL, | |
| 205 | mtext => FOREIGN_FLOW_CONTENT_EL, | |
| 206 | }, | |
| 207 | $SVG_NS => { | |
| 208 | foreignobject => FOREIGN_FLOW_CONTENT_EL, ## TODO: case | |
| 209 | desc => FOREIGN_FLOW_CONTENT_EL, | |
| 210 | title => FOREIGN_FLOW_CONTENT_EL, | |
| 211 | }, | |
| 212 | ## NOTE: In addition, FOREIGN_EL is set to non-HTML elements. | |
| 213 | }; | }; |
| 214 | ||
| 215 | my $c1_entity_char = { | my $c1_entity_char = { |
| # | Line 62 my $c1_entity_char = { | Line 247 my $c1_entity_char = { |
| 247 | 0x9F => 0x0178, | 0x9F => 0x0178, |
| 248 | }; # $c1_entity_char | }; # $c1_entity_char |
| 249 | ||
| 250 | my $special_category = { | sub parse_byte_string ($$$$;$) { |
| 251 | address => 1, area => 1, base => 1, basefont => 1, bgsound => 1, | my $self = ref $_[0] ? shift : shift->new; |
| 252 | blockquote => 1, body => 1, br => 1, center => 1, col => 1, colgroup => 1, | my $charset = shift; |
| 253 | dd => 1, dir => 1, div => 1, dl => 1, dt => 1, embed => 1, fieldset => 1, | my $bytes_s = ref $_[0] ? $_[0] : \($_[0]); |
| 254 | form => 1, frame => 1, frameset => 1, h1 => 1, h2 => 1, h3 => 1, | my $s; |
| 255 | h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, iframe => 1, image => 1, | |
| 256 | img => 1, input => 1, isindex => 1, li => 1, link => 1, listing => 1, | if (defined $charset) { |
| 257 | menu => 1, meta => 1, noembed => 1, noframes => 1, noscript => 1, | require Encode; ## TODO: decode(utf8) don't delete BOM |
| 258 | ol => 1, optgroup => 1, option => 1, p => 1, param => 1, plaintext => 1, | $s = \ (Encode::decode ($charset, $$bytes_s)); |
| 259 | pre => 1, script => 1, select => 1, spacer => 1, style => 1, tbody => 1, | $self->{input_encoding} = lc $charset; ## TODO: normalize name |
| 260 | textarea => 1, tfoot => 1, thead => 1, title => 1, tr => 1, ul => 1, wbr => 1, | $self->{confident} = 1; |
| 261 | }; | } else { |
| 262 | my $scoping_category = { | ## TODO: Implement HTML5 detection algorithm |
| 263 | button => 1, caption => 1, html => 1, marquee => 1, object => 1, | require Whatpm::Charset::UniversalCharDet; |
| 264 | table => 1, td => 1, th => 1, | $charset = Whatpm::Charset::UniversalCharDet->detect_byte_string |
| 265 | }; | (substr ($$bytes_s, 0, 1024)); |
| 266 | my $formatting_category = { | $charset ||= 'windows-1252'; |
| 267 | a => 1, b => 1, big => 1, em => 1, font => 1, i => 1, nobr => 1, | $s = \ (Encode::decode ($charset, $$bytes_s)); |
| 268 | s => 1, small => 1, strile => 1, strong => 1, tt => 1, u => 1, | $self->{input_encoding} = $charset; |
| 269 | }; | $self->{confident} = 0; |
| 270 | # $phrasing_category: all other elements | } |
| 271 | ||
| 272 | $self->{change_encoding} = sub { | |
| 273 | my $self = shift; | |
| 274 | my $charset = lc shift; | |
| 275 | my $token = shift; | |
| 276 | ## TODO: if $charset is supported | |
| 277 | ## TODO: normalize charset name | |
| 278 | ||
| 279 | ## "Change the encoding" algorithm: | |
| 280 | ||
| 281 | ## Step 1 | |
| 282 | if ($charset eq 'utf-16') { ## ISSUE: UTF-16BE -> UTF-8? UTF-16LE -> UTF-8? | |
| 283 | $charset = 'utf-8'; | |
| 284 | } | |
| 285 | ||
| 286 | ## Step 2 | |
| 287 | if (defined $self->{input_encoding} and | |
| 288 | $self->{input_encoding} eq $charset) { | |
| 289 | $self->{confident} = 1; | |
| 290 | return; | |
| 291 | } | |
| 292 | ||
| 293 | !!!parse-error (type => 'charset label detected:'.$self->{input_encoding}. | |
| 294 | ':'.$charset, level => 'w', token => $token); | |
| 295 | ||
| 296 | ## Step 3 | |
| 297 | # if (can) { | |
| 298 | ## change the encoding on the fly. | |
| 299 | #$self->{confident} = 1; | |
| 300 | #return; | |
| 301 | # } | |
| 302 | ||
| 303 | ## Step 4 | |
| 304 | throw Whatpm::HTML::RestartParser (charset => $charset); | |
| 305 | }; # $self->{change_encoding} | |
| 306 | ||
| 307 | my @args = @_; shift @args; # $s | |
| 308 | my $return; | |
| 309 | try { | |
| 310 | $return = $self->parse_char_string ($s, @args); | |
| 311 | } catch Whatpm::HTML::RestartParser with { | |
| 312 | my $charset = shift->{charset}; | |
| 313 | $s = \ (Encode::decode ($charset, $$bytes_s)); | |
| 314 | $self->{input_encoding} = $charset; ## TODO: normalize | |
| 315 | $self->{confident} = 1; | |
| 316 | $return = $self->parse_char_string ($s, @args); | |
| 317 | }; | |
| 318 | return $return; | |
| 319 | } # parse_byte_string | |
| 320 | ||
| 321 | ## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM | |
| 322 | ## and the HTML layer MUST ignore it. However, we does strip BOM in | |
| 323 | ## the encoding layer and the HTML layer does not ignore any U+FEFF, | |
| 324 | ## because the core part of our HTML parser expects a string of character, | |
| 325 | ## not a string of bytes or code units or anything which might contain a BOM. | |
| 326 | ## Therefore, any parser interface that accepts a string of bytes, | |
| 327 | ## such as |parse_byte_string| in this module, must ensure that it does | |
| 328 | ## strip the BOM and never strip any ZWNBSP. | |
| 329 | ||
| 330 | *parse_char_string = \&parse_string; | |
| 331 | ||
| 332 | sub parse_string ($$$;$) { | sub parse_string ($$$;$) { |
| 333 | my $self = shift->new; | my $self = ref $_[0] ? shift : shift->new; |
| 334 | my $s = \$_[0]; | my $s = ref $_[0] ? $_[0] : \($_[0]); |
| 335 | $self->{document} = $_[1]; | $self->{document} = $_[1]; |
| 336 | @{$self->{document}->child_nodes} = (); | |
| 337 | ||
| 338 | ## NOTE: |set_inner_html| copies most of this method's code | ## NOTE: |set_inner_html| copies most of this method's code |
| 339 | ||
| 340 | $self->{confident} = 1 unless exists $self->{confident}; | |
| 341 | $self->{document}->input_encoding ($self->{input_encoding}) | |
| 342 | if defined $self->{input_encoding}; | |
| 343 | ||
| 344 | my $i = 0; | my $i = 0; |
| 345 | my $line = 1; | $self->{line_prev} = $self->{line} = 1; |
| 346 | my $column = 0; | $self->{column_prev} = $self->{column} = 0; |
| 347 | $self->{set_next_input_character} = sub { | $self->{set_next_char} = sub { |
| 348 | my $self = shift; | my $self = shift; |
| 349 | ||
| 350 | pop @{$self->{prev_input_character}}; | pop @{$self->{prev_char}}; |
| 351 | unshift @{$self->{prev_input_character}}, $self->{next_input_character}; | unshift @{$self->{prev_char}}, $self->{next_char}; |
| 352 | ||
| 353 | $self->{next_char} = -1 and return if $i >= length $$s; | |
| 354 | $self->{next_char} = ord substr $$s, $i++, 1; | |
| 355 | ||
| 356 | $self->{next_input_character} = -1 and return if $i >= length $$s; | ($self->{line_prev}, $self->{column_prev}) |
| 357 | $self->{next_input_character} = ord substr $$s, $i++, 1; | = ($self->{line}, $self->{column}); |
| 358 | $column++; | $self->{column}++; |
| 359 | ||
| 360 | if ($self->{next_input_character} == 0x000A) { # LF | if ($self->{next_char} == 0x000A) { # LF |
| 361 | $line++; | $self->{line}++; |
| 362 | $column = 0; | $self->{column} = 0; |
| 363 | } elsif ($self->{next_input_character} == 0x000D) { # CR | } elsif ($self->{next_char} == 0x000D) { # CR |
| 364 | $i++ if substr ($$s, $i, 1) eq "\x0A"; | $i++ if substr ($$s, $i, 1) eq "\x0A"; |
| 365 | $self->{next_input_character} = 0x000A; # LF # MUST | $self->{next_char} = 0x000A; # LF # MUST |
| 366 | $line++; | $self->{line}++; |
| 367 | $column = 0; | $self->{column} = 0; |
| 368 | } elsif ($self->{next_input_character} > 0x10FFFF) { | } elsif ($self->{next_char} > 0x10FFFF) { |
| 369 | $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST | $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST |
| 370 | } elsif ($self->{next_input_character} == 0x0000) { # NULL | } elsif ($self->{next_char} == 0x0000) { # NULL |
| 371 | !!!parse-error (type => 'NULL'); | !!!parse-error (type => 'NULL'); |
| 372 | $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST | $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST |
| 373 | } | } |
| 374 | }; | }; |
| 375 | $self->{prev_input_character} = [-1, -1, -1]; | $self->{prev_char} = [-1, -1, -1]; |
| 376 | $self->{next_input_character} = -1; | $self->{next_char} = -1; |
| 377 | ||
| 378 | my $onerror = $_[2] || sub { | my $onerror = $_[2] || sub { |
| 379 | my (%opt) = @_; | my (%opt) = @_; |
| 380 | warn "Parse error ($opt{type}) at line $opt{line} column $opt{column}\n"; | my $line = $opt{token} ? $opt{token}->{line} : $opt{line}; |
| 381 | my $column = $opt{token} ? $opt{token}->{column} : $opt{column}; | |
| 382 | warn "Parse error ($opt{type}) at line $line column $column\n"; | |
| 383 | }; | }; |
| 384 | $self->{parse_error} = sub { | $self->{parse_error} = sub { |
| 385 | $onerror->(@_, line => $line, column => $column); | $onerror->(line => $self->{line}, column => $self->{column}, @_); |
| 386 | }; | }; |
| 387 | ||
| 388 | $self->_initialize_tokenizer; | $self->_initialize_tokenizer; |
| # | Line 135 sub parse_string ($$$;$) { | Line 390 sub parse_string ($$$;$) { |
| 390 | $self->_construct_tree; | $self->_construct_tree; |
| 391 | $self->_terminate_tree_constructor; | $self->_terminate_tree_constructor; |
| 392 | ||
| 393 | delete $self->{parse_error}; # remove loop | |
| 394 | ||
| 395 | return $self->{document}; | return $self->{document}; |
| 396 | } # parse_string | } # parse_string |
| 397 | ||
| 398 | sub new ($) { | sub new ($) { |
| 399 | my $class = shift; | my $class = shift; |
| 400 | my $self = bless {}, $class; | my $self = bless {}, $class; |
| 401 | $self->{set_next_input_character} = sub { | $self->{set_next_char} = sub { |
| 402 | $self->{next_input_character} = -1; | $self->{next_char} = -1; |
| 403 | }; | }; |
| 404 | $self->{parse_error} = sub { | $self->{parse_error} = sub { |
| 405 | # | # |
| 406 | }; | }; |
| 407 | $self->{change_encoding} = sub { | |
| 408 | # if ($_[0] is a supported encoding) { | |
| 409 | # run "change the encoding" algorithm; | |
| 410 | # throw Whatpm::HTML::RestartParser (charset => $new_encoding); | |
| 411 | # } | |
| 412 | }; | |
| 413 | $self->{application_cache_selection} = sub { | |
| 414 | # | |
| 415 | }; | |
| 416 | return $self; | return $self; |
| 417 | } # new | } # new |
| 418 | ||
| 419 | sub CM_ENTITY () { 0b001 } # & markup in data | |
| 420 | sub CM_LIMITED_MARKUP () { 0b010 } # < markup in data (limited) | |
| 421 | sub CM_FULL_MARKUP () { 0b100 } # < markup in data (any) | |
| 422 | ||
| 423 | sub PLAINTEXT_CONTENT_MODEL () { 0 } | |
| 424 | sub CDATA_CONTENT_MODEL () { CM_LIMITED_MARKUP } | |
| 425 | sub RCDATA_CONTENT_MODEL () { CM_ENTITY | CM_LIMITED_MARKUP } | |
| 426 | sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP } | |
| 427 | ||
| 428 | sub DATA_STATE () { 0 } | |
| 429 | sub ENTITY_DATA_STATE () { 1 } | |
| 430 | sub TAG_OPEN_STATE () { 2 } | |
| 431 | sub CLOSE_TAG_OPEN_STATE () { 3 } | |
| 432 | sub TAG_NAME_STATE () { 4 } | |
| 433 | sub BEFORE_ATTRIBUTE_NAME_STATE () { 5 } | |
| 434 | sub ATTRIBUTE_NAME_STATE () { 6 } | |
| 435 | sub AFTER_ATTRIBUTE_NAME_STATE () { 7 } | |
| 436 | sub BEFORE_ATTRIBUTE_VALUE_STATE () { 8 } | |
| 437 | sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 } | |
| 438 | sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 } | |
| 439 | sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 } | |
| 440 | sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 } | |
| 441 | sub MARKUP_DECLARATION_OPEN_STATE () { 13 } | |
| 442 | sub COMMENT_START_STATE () { 14 } | |
| 443 | sub COMMENT_START_DASH_STATE () { 15 } | |
| 444 | sub COMMENT_STATE () { 16 } | |
| 445 | sub COMMENT_END_STATE () { 17 } | |
| 446 | sub COMMENT_END_DASH_STATE () { 18 } | |
| 447 | sub BOGUS_COMMENT_STATE () { 19 } | |
| 448 | sub DOCTYPE_STATE () { 20 } | |
| 449 | sub BEFORE_DOCTYPE_NAME_STATE () { 21 } | |
| 450 | sub DOCTYPE_NAME_STATE () { 22 } | |
| 451 | sub AFTER_DOCTYPE_NAME_STATE () { 23 } | |
| 452 | sub BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE () { 24 } | |
| 453 | sub DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE () { 25 } | |
| 454 | sub DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE () { 26 } | |
| 455 | sub AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE () { 27 } | |
| 456 | sub BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE () { 28 } | |
| 457 | sub DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE () { 29 } | |
| 458 | sub DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE () { 30 } | |
| 459 | sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE () { 31 } | |
| 460 | sub BOGUS_DOCTYPE_STATE () { 32 } | |
| 461 | sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 } | |
| 462 | sub SELF_CLOSING_START_TAG_STATE () { 34 } | |
| 463 | sub CDATA_BLOCK_STATE () { 35 } | |
| 464 | ||
| 465 | sub DOCTYPE_TOKEN () { 1 } | |
| 466 | sub COMMENT_TOKEN () { 2 } | |
| 467 | sub START_TAG_TOKEN () { 3 } | |
| 468 | sub END_TAG_TOKEN () { 4 } | |
| 469 | sub END_OF_FILE_TOKEN () { 5 } | |
| 470 | sub CHARACTER_TOKEN () { 6 } | |
| 471 | ||
| 472 | sub AFTER_HTML_IMS () { 0b100 } | |
| 473 | sub HEAD_IMS () { 0b1000 } | |
| 474 | sub BODY_IMS () { 0b10000 } | |
| 475 | sub BODY_TABLE_IMS () { 0b100000 } | |
| 476 | sub TABLE_IMS () { 0b1000000 } | |
| 477 | sub ROW_IMS () { 0b10000000 } | |
| 478 | sub BODY_AFTER_IMS () { 0b100000000 } | |
| 479 | sub FRAME_IMS () { 0b1000000000 } | |
| 480 | sub SELECT_IMS () { 0b10000000000 } | |
| 481 | sub IN_FOREIGN_CONTENT_IM () { 0b100000000000 } | |
| 482 | ## NOTE: "in foreign content" insertion mode is special; it is combined | |
| 483 | ## with the secondary insertion mode. In this parser, they are stored | |
| 484 | ## together in the bit-or'ed form. | |
| 485 | ||
| 486 | ## NOTE: "initial" and "before html" insertion modes have no constants. | |
| 487 | ||
| 488 | ## NOTE: "after after body" insertion mode. | |
| 489 | sub AFTER_HTML_BODY_IM () { AFTER_HTML_IMS | BODY_AFTER_IMS } | |
| 490 | ||
| 491 | ## NOTE: "after after frameset" insertion mode. | |
| 492 | sub AFTER_HTML_FRAMESET_IM () { AFTER_HTML_IMS | FRAME_IMS } | |
| 493 | ||
| 494 | sub IN_HEAD_IM () { HEAD_IMS | 0b00 } | |
| 495 | sub IN_HEAD_NOSCRIPT_IM () { HEAD_IMS | 0b01 } | |
| 496 | sub AFTER_HEAD_IM () { HEAD_IMS | 0b10 } | |
| 497 | sub BEFORE_HEAD_IM () { HEAD_IMS | 0b11 } | |
| 498 | sub IN_BODY_IM () { BODY_IMS } | |
| 499 | sub IN_CELL_IM () { BODY_IMS | BODY_TABLE_IMS | 0b01 } | |
| 500 | sub IN_CAPTION_IM () { BODY_IMS | BODY_TABLE_IMS | 0b10 } | |
| 501 | sub IN_ROW_IM () { TABLE_IMS | ROW_IMS | 0b01 } | |
| 502 | sub IN_TABLE_BODY_IM () { TABLE_IMS | ROW_IMS | 0b10 } | |
| 503 | sub IN_TABLE_IM () { TABLE_IMS } | |
| 504 | sub AFTER_BODY_IM () { BODY_AFTER_IMS } | |
| 505 | sub IN_FRAMESET_IM () { FRAME_IMS | 0b01 } | |
| 506 | sub AFTER_FRAMESET_IM () { FRAME_IMS | 0b10 } | |
| 507 | sub IN_SELECT_IM () { SELECT_IMS | 0b01 } | |
| 508 | sub IN_SELECT_IN_TABLE_IM () { SELECT_IMS | 0b10 } | |
| 509 | sub IN_COLUMN_GROUP_IM () { 0b10 } | |
| 510 | ||
| 511 | ## Implementations MUST act as if state machine in the spec | ## Implementations MUST act as if state machine in the spec |
| 512 | ||
| 513 | sub _initialize_tokenizer ($) { | sub _initialize_tokenizer ($) { |
| 514 | my $self = shift; | my $self = shift; |
| 515 | $self->{state} = 'data'; # MUST | $self->{state} = DATA_STATE; # MUST |
| 516 | $self->{content_model_flag} = 'PCDATA'; # be | $self->{content_model} = PCDATA_CONTENT_MODEL; # be |
| 517 | undef $self->{current_token}; # start tag, end tag, comment, or DOCTYPE | undef $self->{current_token}; # start tag, end tag, comment, or DOCTYPE |
| 518 | undef $self->{current_attribute}; | undef $self->{current_attribute}; |
| 519 | undef $self->{last_emitted_start_tag_name}; | undef $self->{last_emitted_start_tag_name}; |
| 520 | undef $self->{last_attribute_value_state}; | undef $self->{last_attribute_value_state}; |
| 521 | delete $self->{self_closing}; | |
| 522 | $self->{char} = []; | $self->{char} = []; |
| 523 | # $self->{next_input_character} | # $self->{next_char} |
| 524 | !!!next-input-character; | !!!next-input-character; |
| 525 | $self->{token} = []; | $self->{token} = []; |
| 526 | # $self->{escape} | # $self->{escape} |
| 527 | } # _initialize_tokenizer | } # _initialize_tokenizer |
| 528 | ||
| 529 | ## A token has: | ## A token has: |
| 530 | ## ->{type} eq 'DOCTYPE', 'start tag', 'end tag', 'comment', | ## ->{type} == DOCTYPE_TOKEN, START_TAG_TOKEN, END_TAG_TOKEN, COMMENT_TOKEN, |
| 531 | ## 'character', or 'end-of-file' | ## CHARACTER_TOKEN, or END_OF_FILE_TOKEN |
| 532 | ## ->{name} (DOCTYPE, start tag (tag name), end tag (tag name)) | ## ->{name} (DOCTYPE_TOKEN) |
| 533 | ## ->{public_identifier} (DOCTYPE) | ## ->{tag_name} (START_TAG_TOKEN, END_TAG_TOKEN) |
| 534 | ## ->{system_identifier} (DOCTYPE) | ## ->{public_identifier} (DOCTYPE_TOKEN) |
| 535 | ## ->{correct} == 1 or 0 (DOCTYPE) | ## ->{system_identifier} (DOCTYPE_TOKEN) |
| 536 | ## ->{attributes} isa HASH (start tag, end tag) | ## ->{quirks} == 1 or 0 (DOCTYPE_TOKEN): "force-quirks" flag |
| 537 | ## ->{data} (comment, character) | ## ->{attributes} isa HASH (START_TAG_TOKEN, END_TAG_TOKEN) |
| 538 | ## ->{name} | |
| 539 | ## ->{value} | |
| 540 | ## ->{has_reference} == 1 or 0 | |
| 541 | ## ->{data} (COMMENT_TOKEN, CHARACTER_TOKEN) | |
| 542 | ## NOTE: The "self-closing flag" is hold as |$self->{self_closing}|. | |
| 543 | ## |->{self_closing}| is used to save the value of |$self->{self_closing}| | |
| 544 | ## while the token is pushed back to the stack. | |
| 545 | ||
| 546 | ## ISSUE: "When a DOCTYPE token is created, its | |
| 547 | ## <i>self-closing flag</i> must be unset (its other state is that it | |
| 548 | ## be set), and its attributes list must be empty.": Wrong subject? | |
| 549 | ||
| 550 | ## Emitted token MUST immediately be handled by the tree construction state. | ## Emitted token MUST immediately be handled by the tree construction state. |
| 551 | ||
| # | Line 185 sub _initialize_tokenizer ($) { | Line 555 sub _initialize_tokenizer ($) { |
| 555 | ## has completed loading. If one has, then it MUST be executed | ## has completed loading. If one has, then it MUST be executed |
| 556 | ## and removed from the list. | ## and removed from the list. |
| 557 | ||
| 558 | ## NOTE: HTML5 "Writing HTML documents" section, applied to | |
| 559 | ## documents and not to user agents and conformance checkers, | |
| 560 | ## contains some requirements that are not detected by the | |
| 561 | ## parsing algorithm: | |
| 562 | ## - Some requirements on character encoding declarations. ## TODO | |
| 563 | ## - "Elements MUST NOT contain content that their content model disallows." | |
| 564 | ## ... Some are parse error, some are not (will be reported by c.c.). | |
| 565 | ## - Polytheistic slash SHOULD NOT be used. (Applied only to atheists.) ## TODO | |
| 566 | ## - Text (in elements, attributes, and comments) SHOULD NOT contain | |
| 567 | ## control characters other than space characters. ## TODO: (what is control character? C0, C1 and DEL? Unicode control character?) | |
| 568 | ||
| 569 | ## TODO: HTML5 poses authors two SHOULD-level requirements that cannot | |
| 570 | ## be detected by the HTML5 parsing algorithm: | |
| 571 | ## - Text, | |
| 572 | ||
| 573 | sub _get_next_token ($) { | sub _get_next_token ($) { |
| 574 | my $self = shift; | my $self = shift; |
| 575 | ||
| 576 | if ($self->{self_closing}) { | |
| 577 | !!!parse-error (type => 'nestc', token => $self->{current_token}); | |
| 578 | ## NOTE: The |self_closing| flag is only set by start tag token. | |
| 579 | ## In addition, when a start tag token is emitted, it is always set to | |
| 580 | ## |current_token|. | |
| 581 | delete $self->{self_closing}; | |
| 582 | } | |
| 583 | ||
| 584 | if (@{$self->{token}}) { | if (@{$self->{token}}) { |
| 585 | $self->{self_closing} = $self->{token}->[0]->{self_closing}; | |
| 586 | return shift @{$self->{token}}; | return shift @{$self->{token}}; |
| 587 | } | } |
| 588 | ||
| 589 | A: { | A: { |
| 590 | if ($self->{state} eq 'data') { | if ($self->{state} == DATA_STATE) { |
| 591 | if ($self->{next_input_character} == 0x0026) { # & | if ($self->{next_char} == 0x0026) { # & |
| 592 | if ($self->{content_model_flag} eq 'PCDATA' or | if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA |
| 593 | $self->{content_model_flag} eq 'RCDATA') { | not $self->{escape}) { |
| 594 | $self->{state} = 'entity data'; | !!!cp (1); |
| 595 | $self->{state} = ENTITY_DATA_STATE; | |
| 596 | !!!next-input-character; | !!!next-input-character; |
| 597 | redo A; | redo A; |
| 598 | } else { | } else { |
| 599 | !!!cp (2); | |
| 600 | # | # |
| 601 | } | } |
| 602 | } elsif ($self->{next_input_character} == 0x002D) { # - | } elsif ($self->{next_char} == 0x002D) { # - |
| 603 | if ($self->{content_model_flag} eq 'RCDATA' or | if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA |
| $self->{content_model_flag} eq 'CDATA') { | ||
| 604 | unless ($self->{escape}) { | unless ($self->{escape}) { |
| 605 | if ($self->{prev_input_character}->[0] == 0x002D and # - | if ($self->{prev_char}->[0] == 0x002D and # - |
| 606 | $self->{prev_input_character}->[1] == 0x0021 and # ! | $self->{prev_char}->[1] == 0x0021 and # ! |
| 607 | $self->{prev_input_character}->[2] == 0x003C) { # < | $self->{prev_char}->[2] == 0x003C) { # < |
| 608 | !!!cp (3); | |
| 609 | $self->{escape} = 1; | $self->{escape} = 1; |
| 610 | } else { | |
| 611 | !!!cp (4); | |
| 612 | } | } |
| 613 | } else { | |
| 614 | !!!cp (5); | |
| 615 | } | } |
| 616 | } | } |
| 617 | ||
| 618 | # | # |
| 619 | } elsif ($self->{next_input_character} == 0x003C) { # < | } elsif ($self->{next_char} == 0x003C) { # < |
| 620 | if ($self->{content_model_flag} eq 'PCDATA' or | if ($self->{content_model} & CM_FULL_MARKUP or # PCDATA |
| 621 | (($self->{content_model_flag} eq 'CDATA' or | (($self->{content_model} & CM_LIMITED_MARKUP) and # CDATA | RCDATA |
| $self->{content_model_flag} eq 'RCDATA') and | ||
| 622 | not $self->{escape})) { | not $self->{escape})) { |
| 623 | $self->{state} = 'tag open'; | !!!cp (6); |
| 624 | $self->{state} = TAG_OPEN_STATE; | |
| 625 | !!!next-input-character; | !!!next-input-character; |
| 626 | redo A; | redo A; |
| 627 | } else { | } else { |
| 628 | !!!cp (7); | |
| 629 | # | # |
| 630 | } | } |
| 631 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 632 | if ($self->{escape} and | if ($self->{escape} and |
| 633 | ($self->{content_model_flag} eq 'RCDATA' or | ($self->{content_model} & CM_LIMITED_MARKUP)) { # RCDATA | CDATA |
| 634 | $self->{content_model_flag} eq 'CDATA')) { | if ($self->{prev_char}->[0] == 0x002D and # - |
| 635 | if ($self->{prev_input_character}->[0] == 0x002D and # - | $self->{prev_char}->[1] == 0x002D) { # - |
| 636 | $self->{prev_input_character}->[1] == 0x002D) { # - | !!!cp (8); |
| 637 | delete $self->{escape}; | delete $self->{escape}; |
| 638 | } else { | |
| 639 | !!!cp (9); | |
| 640 | } | } |
| 641 | } else { | |
| 642 | !!!cp (10); | |
| 643 | } | } |
| 644 | ||
| 645 | # | # |
| 646 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 647 | !!!emit ({type => 'end-of-file'}); | !!!cp (11); |
| 648 | !!!emit ({type => END_OF_FILE_TOKEN, | |
| 649 | line => $self->{line}, column => $self->{column}}); | |
| 650 | last A; ## TODO: ok? | last A; ## TODO: ok? |
| 651 | } else { | |
| 652 | !!!cp (12); | |
| 653 | } | } |
| 654 | # Anything else | # Anything else |
| 655 | my $token = {type => 'character', | my $token = {type => CHARACTER_TOKEN, |
| 656 | data => chr $self->{next_input_character}}; | data => chr $self->{next_char}, |
| 657 | line => $self->{line}, column => $self->{column}, | |
| 658 | }; | |
| 659 | ## Stay in the data state | ## Stay in the data state |
| 660 | !!!next-input-character; | !!!next-input-character; |
| 661 | ||
| 662 | !!!emit ($token); | !!!emit ($token); |
| 663 | ||
| 664 | redo A; | redo A; |
| 665 | } elsif ($self->{state} eq 'entity data') { | } elsif ($self->{state} == ENTITY_DATA_STATE) { |
| 666 | ## (cannot happen in CDATA state) | ## (cannot happen in CDATA state) |
| 667 | ||
| 668 | my ($l, $c) = ($self->{line_prev}, $self->{column_prev}); | |
| 669 | ||
| 670 | my $token = $self->_tokenize_attempt_to_consume_an_entity (0); | my $token = $self->_tokenize_attempt_to_consume_an_entity (0, -1); |
| 671 | ||
| 672 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 673 | # next-input-character is already done | # next-input-character is already done |
| 674 | ||
| 675 | unless (defined $token) { | unless (defined $token) { |
| 676 | !!!emit ({type => 'character', data => '&'}); | !!!cp (13); |
| 677 | !!!emit ({type => CHARACTER_TOKEN, data => '&', | |
| 678 | line => $l, column => $c, | |
| 679 | }); | |
| 680 | } else { | } else { |
| 681 | !!!cp (14); | |
| 682 | !!!emit ($token); | !!!emit ($token); |
| 683 | } | } |
| 684 | ||
| 685 | redo A; | redo A; |
| 686 | } elsif ($self->{state} eq 'tag open') { | } elsif ($self->{state} == TAG_OPEN_STATE) { |
| 687 | if ($self->{content_model_flag} eq 'RCDATA' or | if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA |
| 688 | $self->{content_model_flag} eq 'CDATA') { | if ($self->{next_char} == 0x002F) { # / |
| 689 | if ($self->{next_input_character} == 0x002F) { # / | !!!cp (15); |
| 690 | !!!next-input-character; | !!!next-input-character; |
| 691 | $self->{state} = 'close tag open'; | $self->{state} = CLOSE_TAG_OPEN_STATE; |
| 692 | redo A; | redo A; |
| 693 | } else { | } else { |
| 694 | !!!cp (16); | |
| 695 | ## reconsume | ## reconsume |
| 696 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 697 | ||
| 698 | !!!emit ({type => 'character', data => '<'}); | !!!emit ({type => CHARACTER_TOKEN, data => '<', |
| 699 | line => $self->{line_prev}, | |
| 700 | column => $self->{column_prev}, | |
| 701 | }); | |
| 702 | ||
| 703 | redo A; | redo A; |
| 704 | } | } |
| 705 | } elsif ($self->{content_model_flag} eq 'PCDATA') { | } elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA |
| 706 | if ($self->{next_input_character} == 0x0021) { # ! | if ($self->{next_char} == 0x0021) { # ! |
| 707 | $self->{state} = 'markup declaration open'; | !!!cp (17); |
| 708 | $self->{state} = MARKUP_DECLARATION_OPEN_STATE; | |
| 709 | !!!next-input-character; | !!!next-input-character; |
| 710 | redo A; | redo A; |
| 711 | } elsif ($self->{next_input_character} == 0x002F) { # / | } elsif ($self->{next_char} == 0x002F) { # / |
| 712 | $self->{state} = 'close tag open'; | !!!cp (18); |
| 713 | $self->{state} = CLOSE_TAG_OPEN_STATE; | |
| 714 | !!!next-input-character; | !!!next-input-character; |
| 715 | redo A; | redo A; |
| 716 | } elsif (0x0041 <= $self->{next_input_character} and | } elsif (0x0041 <= $self->{next_char} and |
| 717 | $self->{next_input_character} <= 0x005A) { # A..Z | $self->{next_char} <= 0x005A) { # A..Z |
| 718 | !!!cp (19); | |
| 719 | $self->{current_token} | $self->{current_token} |
| 720 | = {type => 'start tag', | = {type => START_TAG_TOKEN, |
| 721 | tag_name => chr ($self->{next_input_character} + 0x0020)}; | tag_name => chr ($self->{next_char} + 0x0020), |
| 722 | $self->{state} = 'tag name'; | line => $self->{line_prev}, |
| 723 | column => $self->{column_prev}}; | |
| 724 | $self->{state} = TAG_NAME_STATE; | |
| 725 | !!!next-input-character; | !!!next-input-character; |
| 726 | redo A; | redo A; |
| 727 | } elsif (0x0061 <= $self->{next_input_character} and | } elsif (0x0061 <= $self->{next_char} and |
| 728 | $self->{next_input_character} <= 0x007A) { # a..z | $self->{next_char} <= 0x007A) { # a..z |
| 729 | $self->{current_token} = {type => 'start tag', | !!!cp (20); |
| 730 | tag_name => chr ($self->{next_input_character})}; | $self->{current_token} = {type => START_TAG_TOKEN, |
| 731 | $self->{state} = 'tag name'; | tag_name => chr ($self->{next_char}), |
| 732 | line => $self->{line_prev}, | |
| 733 | column => $self->{column_prev}}; | |
| 734 | $self->{state} = TAG_NAME_STATE; | |
| 735 | !!!next-input-character; | !!!next-input-character; |
| 736 | redo A; | redo A; |
| 737 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 738 | !!!parse-error (type => 'empty start tag'); | !!!cp (21); |
| 739 | $self->{state} = 'data'; | !!!parse-error (type => 'empty start tag', |
| 740 | line => $self->{line_prev}, | |
| 741 | column => $self->{column_prev}); | |
| 742 | $self->{state} = DATA_STATE; | |
| 743 | !!!next-input-character; | !!!next-input-character; |
| 744 | ||
| 745 | !!!emit ({type => 'character', data => '<>'}); | !!!emit ({type => CHARACTER_TOKEN, data => '<>', |
| 746 | line => $self->{line_prev}, | |
| 747 | column => $self->{column_prev}, | |
| 748 | }); | |
| 749 | ||
| 750 | redo A; | redo A; |
| 751 | } elsif ($self->{next_input_character} == 0x003F) { # ? | } elsif ($self->{next_char} == 0x003F) { # ? |
| 752 | !!!parse-error (type => 'pio'); | !!!cp (22); |
| 753 | $self->{state} = 'bogus comment'; | !!!parse-error (type => 'pio', |
| 754 | ## $self->{next_input_character} is intentionally left as is | line => $self->{line_prev}, |
| 755 | column => $self->{column_prev}); | |
| 756 | $self->{state} = BOGUS_COMMENT_STATE; | |
| 757 | $self->{current_token} = {type => COMMENT_TOKEN, data => '', | |
| 758 | line => $self->{line_prev}, | |
| 759 | column => $self->{column_prev}, | |
| 760 | }; | |
| 761 | ## $self->{next_char} is intentionally left as is | |
| 762 | redo A; | redo A; |
| 763 | } else { | } else { |
| 764 | !!!cp (23); | |
| 765 | !!!parse-error (type => 'bare stago'); | !!!parse-error (type => 'bare stago'); |
| 766 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 767 | ## reconsume | ## reconsume |
| 768 | ||
| 769 | !!!emit ({type => 'character', data => '<'}); | !!!emit ({type => CHARACTER_TOKEN, data => '<', |
| 770 | line => $self->{line_prev}, | |
| 771 | column => $self->{column_prev}, | |
| 772 | }); | |
| 773 | ||
| 774 | redo A; | redo A; |
| 775 | } | } |
| 776 | } else { | } else { |
| 777 | die "$0: $self->{content_model_flag}: Unknown content model flag"; | die "$0: $self->{content_model} in tag open"; |
| 778 | } | } |
| 779 | } elsif ($self->{state} eq 'close tag open') { | } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) { |
| 780 | if ($self->{content_model_flag} eq 'RCDATA' or | my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</" |
| 781 | $self->{content_model_flag} eq 'CDATA') { | if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA |
| 782 | if (defined $self->{last_emitted_start_tag_name}) { | if (defined $self->{last_emitted_start_tag_name}) { |
| 783 | ||
| 784 | ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564> | ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564> |
| 785 | my @next_char; | my @next_char; |
| 786 | TAGNAME: for (my $i = 0; $i < length $self->{last_emitted_start_tag_name}; $i++) { | TAGNAME: for (my $i = 0; $i < length $self->{last_emitted_start_tag_name}; $i++) { |
| 787 | push @next_char, $self->{next_input_character}; | push @next_char, $self->{next_char}; |
| 788 | my $c = ord substr ($self->{last_emitted_start_tag_name}, $i, 1); | my $c = ord substr ($self->{last_emitted_start_tag_name}, $i, 1); |
| 789 | my $C = 0x0061 <= $c && $c <= 0x007A ? $c - 0x0020 : $c; | my $C = 0x0061 <= $c && $c <= 0x007A ? $c - 0x0020 : $c; |
| 790 | if ($self->{next_input_character} == $c or $self->{next_input_character} == $C) { | if ($self->{next_char} == $c or $self->{next_char} == $C) { |
| 791 | !!!cp (24); | |
| 792 | !!!next-input-character; | !!!next-input-character; |
| 793 | next TAGNAME; | next TAGNAME; |
| 794 | } else { | } else { |
| 795 | $self->{next_input_character} = shift @next_char; # reconsume | !!!cp (25); |
| 796 | $self->{next_char} = shift @next_char; # reconsume | |
| 797 | !!!back-next-input-character (@next_char); | !!!back-next-input-character (@next_char); |
| 798 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 799 | ||
| 800 | !!!emit ({type => 'character', data => '</'}); | !!!emit ({type => CHARACTER_TOKEN, data => '</', |
| 801 | line => $l, column => $c, | |
| 802 | }); | |
| 803 | ||
| 804 | redo A; | redo A; |
| 805 | } | } |
| 806 | } | } |
| 807 | push @next_char, $self->{next_input_character}; | push @next_char, $self->{next_char}; |
| 808 | ||
| 809 | unless ($self->{next_input_character} == 0x0009 or # HT | unless ($self->{next_char} == 0x0009 or # HT |
| 810 | $self->{next_input_character} == 0x000A or # LF | $self->{next_char} == 0x000A or # LF |
| 811 | $self->{next_input_character} == 0x000B or # VT | $self->{next_char} == 0x000B or # VT |
| 812 | $self->{next_input_character} == 0x000C or # FF | $self->{next_char} == 0x000C or # FF |
| 813 | $self->{next_input_character} == 0x0020 or # SP | $self->{next_char} == 0x0020 or # SP |
| 814 | $self->{next_input_character} == 0x003E or # > | $self->{next_char} == 0x003E or # > |
| 815 | $self->{next_input_character} == 0x002F or # / | $self->{next_char} == 0x002F or # / |
| 816 | $self->{next_input_character} == -1) { | $self->{next_char} == -1) { |
| 817 | $self->{next_input_character} = shift @next_char; # reconsume | !!!cp (26); |
| 818 | $self->{next_char} = shift @next_char; # reconsume | |
| 819 | !!!back-next-input-character (@next_char); | !!!back-next-input-character (@next_char); |
| 820 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 821 | !!!emit ({type => 'character', data => '</'}); | !!!emit ({type => CHARACTER_TOKEN, data => '</', |
| 822 | line => $l, column => $c, | |
| 823 | }); | |
| 824 | redo A; | redo A; |
| 825 | } else { | } else { |
| 826 | $self->{next_input_character} = shift @next_char; | !!!cp (27); |
| 827 | $self->{next_char} = shift @next_char; | |
| 828 | !!!back-next-input-character (@next_char); | !!!back-next-input-character (@next_char); |
| 829 | # and consume... | # and consume... |
| 830 | } | } |
| 831 | } else { | } else { |
| 832 | ## No start tag token has ever been emitted | ## No start tag token has ever been emitted |
| 833 | !!!cp (28); | |
| 834 | # next-input-character is already done | # next-input-character is already done |
| 835 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 836 | !!!emit ({type => 'character', data => '</'}); | !!!emit ({type => CHARACTER_TOKEN, data => '</', |
| 837 | line => $l, column => $c, | |
| 838 | }); | |
| 839 | redo A; | redo A; |
| 840 | } | } |
| 841 | } | } |
| 842 | ||
| 843 | if (0x0041 <= $self->{next_input_character} and | if (0x0041 <= $self->{next_char} and |
| 844 | $self->{next_input_character} <= 0x005A) { # A..Z | $self->{next_char} <= 0x005A) { # A..Z |
| 845 | $self->{current_token} = {type => 'end tag', | !!!cp (29); |
| 846 | tag_name => chr ($self->{next_input_character} + 0x0020)}; | $self->{current_token} |
| 847 | $self->{state} = 'tag name'; | = {type => END_TAG_TOKEN, |
| 848 | !!!next-input-character; | tag_name => chr ($self->{next_char} + 0x0020), |
| 849 | redo A; | line => $l, column => $c}; |
| 850 | } elsif (0x0061 <= $self->{next_input_character} and | $self->{state} = TAG_NAME_STATE; |
| 851 | $self->{next_input_character} <= 0x007A) { # a..z | !!!next-input-character; |
| 852 | $self->{current_token} = {type => 'end tag', | redo A; |
| 853 | tag_name => chr ($self->{next_input_character})}; | } elsif (0x0061 <= $self->{next_char} and |
| 854 | $self->{state} = 'tag name'; | $self->{next_char} <= 0x007A) { # a..z |
| 855 | !!!next-input-character; | !!!cp (30); |
| 856 | redo A; | $self->{current_token} = {type => END_TAG_TOKEN, |
| 857 | } elsif ($self->{next_input_character} == 0x003E) { # > | tag_name => chr ($self->{next_char}), |
| 858 | !!!parse-error (type => 'empty end tag'); | line => $l, column => $c}; |
| 859 | $self->{state} = 'data'; | $self->{state} = TAG_NAME_STATE; |
| 860 | !!!next-input-character; | |
| 861 | redo A; | |
| 862 | } elsif ($self->{next_char} == 0x003E) { # > | |
| 863 | !!!cp (31); | |
| 864 | !!!parse-error (type => 'empty end tag', | |
| 865 | line => $self->{line_prev}, ## "<" in "</>" | |
| 866 | column => $self->{column_prev} - 1); | |
| 867 | $self->{state} = DATA_STATE; | |
| 868 | !!!next-input-character; | !!!next-input-character; |
| 869 | redo A; | redo A; |
| 870 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 871 | !!!cp (32); | |
| 872 | !!!parse-error (type => 'bare etago'); | !!!parse-error (type => 'bare etago'); |
| 873 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 874 | # reconsume | # reconsume |
| 875 | ||
| 876 | !!!emit ({type => 'character', data => '</'}); | !!!emit ({type => CHARACTER_TOKEN, data => '</', |
| 877 | line => $l, column => $c, | |
| 878 | }); | |
| 879 | ||
| 880 | redo A; | redo A; |
| 881 | } else { | } else { |
| 882 | !!!cp (33); | |
| 883 | !!!parse-error (type => 'bogus end tag'); | !!!parse-error (type => 'bogus end tag'); |
| 884 | $self->{state} = 'bogus comment'; | $self->{state} = BOGUS_COMMENT_STATE; |
| 885 | ## $self->{next_input_character} is intentionally left as is | $self->{current_token} = {type => COMMENT_TOKEN, data => '', |
| 886 | redo A; | line => $self->{line_prev}, # "<" of "</" |
| 887 | } | column => $self->{column_prev} - 1, |
| 888 | } elsif ($self->{state} eq 'tag name') { | }; |
| 889 | if ($self->{next_input_character} == 0x0009 or # HT | ## $self->{next_char} is intentionally left as is |
| 890 | $self->{next_input_character} == 0x000A or # LF | redo A; |
| 891 | $self->{next_input_character} == 0x000B or # VT | } |
| 892 | $self->{next_input_character} == 0x000C or # FF | } elsif ($self->{state} == TAG_NAME_STATE) { |
| 893 | $self->{next_input_character} == 0x0020) { # SP | if ($self->{next_char} == 0x0009 or # HT |
| 894 | $self->{state} = 'before attribute name'; | $self->{next_char} == 0x000A or # LF |
| 895 | !!!next-input-character; | $self->{next_char} == 0x000B or # VT |
| 896 | redo A; | $self->{next_char} == 0x000C or # FF |
| 897 | } elsif ($self->{next_input_character} == 0x003E) { # > | $self->{next_char} == 0x0020) { # SP |
| 898 | if ($self->{current_token}->{type} eq 'start tag') { | !!!cp (34); |
| 899 | $self->{current_token}->{first_start_tag} | $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
| 900 | = not defined $self->{last_emitted_start_tag_name}; | !!!next-input-character; |
| 901 | redo A; | |
| 902 | } elsif ($self->{next_char} == 0x003E) { # > | |
| 903 | if ($self->{current_token}->{type} == START_TAG_TOKEN) { | |
| 904 | !!!cp (35); | |
| 905 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 906 | } elsif ($self->{current_token}->{type} eq 'end tag') { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 907 | $self->{content_model_flag} = 'PCDATA'; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 908 | if ($self->{current_token}->{attributes}) { | #if ($self->{current_token}->{attributes}) { |
| 909 | !!!parse-error (type => 'end tag attribute'); | # ## NOTE: This should never be reached. |
| 910 | } | # !!! cp (36); |
| 911 | # !!! parse-error (type => 'end tag attribute'); | |
| 912 | #} else { | |
| 913 | !!!cp (37); | |
| 914 | #} | |
| 915 | } else { | } else { |
| 916 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| 917 | } | } |
| 918 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 919 | !!!next-input-character; | !!!next-input-character; |
| 920 | ||
| 921 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 922 | ||
| 923 | redo A; | redo A; |
| 924 | } elsif (0x0041 <= $self->{next_input_character} and | } elsif (0x0041 <= $self->{next_char} and |
| 925 | $self->{next_input_character} <= 0x005A) { # A..Z | $self->{next_char} <= 0x005A) { # A..Z |
| 926 | $self->{current_token}->{tag_name} .= chr ($self->{next_input_character} + 0x0020); | !!!cp (38); |
| 927 | $self->{current_token}->{tag_name} .= chr ($self->{next_char} + 0x0020); | |
| 928 | # start tag or end tag | # start tag or end tag |
| 929 | ## Stay in this state | ## Stay in this state |
| 930 | !!!next-input-character; | !!!next-input-character; |
| 931 | redo A; | redo A; |
| 932 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 933 | !!!parse-error (type => 'unclosed tag'); | !!!parse-error (type => 'unclosed tag'); |
| 934 | if ($self->{current_token}->{type} eq 'start tag') { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 935 | $self->{current_token}->{first_start_tag} | !!!cp (39); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 936 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 937 | } elsif ($self->{current_token}->{type} eq 'end tag') { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 938 | $self->{content_model_flag} = 'PCDATA'; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 939 | if ($self->{current_token}->{attributes}) { | #if ($self->{current_token}->{attributes}) { |
| 940 | !!!parse-error (type => 'end tag attribute'); | # ## NOTE: This state should never be reached. |
| 941 | } | # !!! cp (40); |
| 942 | # !!! parse-error (type => 'end tag attribute'); | |
| 943 | #} else { | |
| 944 | !!!cp (41); | |
| 945 | #} | |
| 946 | } else { | } else { |
| 947 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| 948 | } | } |
| 949 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 950 | # reconsume | # reconsume |
| 951 | ||
| 952 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 953 | ||
| 954 | redo A; | redo A; |
| 955 | } elsif ($self->{next_input_character} == 0x002F) { # / | } elsif ($self->{next_char} == 0x002F) { # / |
| 956 | !!!cp (42); | |
| 957 | $self->{state} = SELF_CLOSING_START_TAG_STATE; | |
| 958 | !!!next-input-character; | !!!next-input-character; |
| if ($self->{next_input_character} == 0x003E and # > | ||
| $self->{current_token}->{type} eq 'start tag' and | ||
| $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) { | ||
| # permitted slash | ||
| # | ||
| } else { | ||
| !!!parse-error (type => 'nestc'); | ||
| } | ||
| $self->{state} = 'before attribute name'; | ||
| # next-input-character is already done | ||
| 959 | redo A; | redo A; |
| 960 | } else { | } else { |
| 961 | $self->{current_token}->{tag_name} .= chr $self->{next_input_character}; | !!!cp (44); |
| 962 | $self->{current_token}->{tag_name} .= chr $self->{next_char}; | |
| 963 | # start tag or end tag | # start tag or end tag |
| 964 | ## Stay in the state | ## Stay in the state |
| 965 | !!!next-input-character; | !!!next-input-character; |
| 966 | redo A; | redo A; |
| 967 | } | } |
| 968 | } elsif ($self->{state} eq 'before attribute name') { | } elsif ($self->{state} == BEFORE_ATTRIBUTE_NAME_STATE) { |
| 969 | if ($self->{next_input_character} == 0x0009 or # HT | if ($self->{next_char} == 0x0009 or # HT |
| 970 | $self->{next_input_character} == 0x000A or # LF | $self->{next_char} == 0x000A or # LF |
| 971 | $self->{next_input_character} == 0x000B or # VT | $self->{next_char} == 0x000B or # VT |
| 972 | $self->{next_input_character} == 0x000C or # FF | $self->{next_char} == 0x000C or # FF |
| 973 | $self->{next_input_character} == 0x0020) { # SP | $self->{next_char} == 0x0020) { # SP |
| 974 | !!!cp (45); | |
| 975 | ## Stay in the state | ## Stay in the state |
| 976 | !!!next-input-character; | !!!next-input-character; |
| 977 | redo A; | redo A; |
| 978 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 979 | if ($self->{current_token}->{type} eq 'start tag') { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 980 | $self->{current_token}->{first_start_tag} | !!!cp (46); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 981 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 982 | } elsif ($self->{current_token}->{type} eq 'end tag') { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 983 | $self->{content_model_flag} = 'PCDATA'; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 984 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 985 | !!!cp (47); | |
| 986 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 987 | } else { | |
| 988 | !!!cp (48); | |
| 989 | } | } |
| 990 | } else { | } else { |
| 991 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| 992 | } | } |
| 993 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 994 | !!!next-input-character; | !!!next-input-character; |
| 995 | ||
| 996 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 997 | ||
| 998 | redo A; | redo A; |
| 999 | } elsif (0x0041 <= $self->{next_input_character} and | } elsif (0x0041 <= $self->{next_char} and |
| 1000 | $self->{next_input_character} <= 0x005A) { # A..Z | $self->{next_char} <= 0x005A) { # A..Z |
| 1001 | $self->{current_attribute} = {name => chr ($self->{next_input_character} + 0x0020), | !!!cp (49); |
| 1002 | value => ''}; | $self->{current_attribute} |
| 1003 | $self->{state} = 'attribute name'; | = {name => chr ($self->{next_char} + 0x0020), |
| 1004 | value => '', | |
| 1005 | line => $self->{line}, column => $self->{column}}; | |
| 1006 | $self->{state} = ATTRIBUTE_NAME_STATE; | |
| 1007 | !!!next-input-character; | |
| 1008 | redo A; | |
| 1009 | } elsif ($self->{next_char} == 0x002F) { # / | |
| 1010 | !!!cp (50); | |
| 1011 | $self->{state} = SELF_CLOSING_START_TAG_STATE; | |
| 1012 | !!!next-input-character; | !!!next-input-character; |
| 1013 | redo A; | redo A; |
| 1014 | } elsif ($self->{next_input_character} == 0x002F) { # / | } elsif ($self->{next_char} == -1) { |
| !!!next-input-character; | ||
| if ($self->{next_input_character} == 0x003E and # > | ||
| $self->{current_token}->{type} eq 'start tag' and | ||
| $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) { | ||
| # permitted slash | ||
| # | ||
| } else { | ||
| !!!parse-error (type => 'nestc'); | ||
| } | ||
| ## Stay in the state | ||
| # next-input-character is already done | ||
| redo A; | ||
| } elsif ($self->{next_input_character} == -1) { | ||
| 1015 | !!!parse-error (type => 'unclosed tag'); | !!!parse-error (type => 'unclosed tag'); |
| 1016 | if ($self->{current_token}->{type} eq 'start tag') { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1017 | $self->{current_token}->{first_start_tag} | !!!cp (52); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1018 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1019 | } elsif ($self->{current_token}->{type} eq 'end tag') { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1020 | $self->{content_model_flag} = 'PCDATA'; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1021 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1022 | !!!cp (53); | |
| 1023 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1024 | } else { | |
| 1025 | !!!cp (54); | |
| 1026 | } | } |
| 1027 | } else { | } else { |
| 1028 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| 1029 | } | } |
| 1030 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 1031 | # reconsume | # reconsume |
| 1032 | ||
| 1033 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 1034 | ||
| 1035 | redo A; | redo A; |
| 1036 | } else { | } else { |
| 1037 | $self->{current_attribute} = {name => chr ($self->{next_input_character}), | if ({ |
| 1038 | value => ''}; | 0x0022 => 1, # " |
| 1039 | $self->{state} = 'attribute name'; | 0x0027 => 1, # ' |
| 1040 | 0x003D => 1, # = | |
| 1041 | }->{$self->{next_char}}) { | |
| 1042 | !!!cp (55); | |
| 1043 | !!!parse-error (type => 'bad attribute name'); | |
| 1044 | } else { | |
| 1045 | !!!cp (56); | |
| 1046 | } | |
| 1047 | $self->{current_attribute} | |
| 1048 | = {name => chr ($self->{next_char}), | |
| 1049 | value => '', | |
| 1050 | line => $self->{line}, column => $self->{column}}; | |
| 1051 | $self->{state} = ATTRIBUTE_NAME_STATE; | |
| 1052 | !!!next-input-character; | !!!next-input-character; |
| 1053 | redo A; | redo A; |
| 1054 | } | } |
| 1055 | } elsif ($self->{state} eq 'attribute name') { | } elsif ($self->{state} == ATTRIBUTE_NAME_STATE) { |
| 1056 | my $before_leave = sub { | my $before_leave = sub { |
| 1057 | if (exists $self->{current_token}->{attributes} # start tag or end tag | if (exists $self->{current_token}->{attributes} # start tag or end tag |
| 1058 | ->{$self->{current_attribute}->{name}}) { # MUST | ->{$self->{current_attribute}->{name}}) { # MUST |
| 1059 | !!!parse-error (type => 'dupulicate attribute'); | !!!cp (57); |
| 1060 | !!!parse-error (type => 'duplicate attribute:'.$self->{current_attribute}->{name}, line => $self->{current_attribute}->{line}, column => $self->{current_attribute}->{column}); | |
| 1061 | ## Discard $self->{current_attribute} # MUST | ## Discard $self->{current_attribute} # MUST |
| 1062 | } else { | } else { |
| 1063 | !!!cp (58); | |
| 1064 | $self->{current_token}->{attributes}->{$self->{current_attribute}->{name}} | $self->{current_token}->{attributes}->{$self->{current_attribute}->{name}} |
| 1065 | = $self->{current_attribute}; | = $self->{current_attribute}; |
| 1066 | } | } |
| 1067 | }; # $before_leave | }; # $before_leave |
| 1068 | ||
| 1069 | if ($self->{next_input_character} == 0x0009 or # HT | if ($self->{next_char} == 0x0009 or # HT |
| 1070 | $self->{next_input_character} == 0x000A or # LF | $self->{next_char} == 0x000A or # LF |
| 1071 | $self->{next_input_character} == 0x000B or # VT | $self->{next_char} == 0x000B or # VT |
| 1072 | $self->{next_input_character} == 0x000C or # FF | $self->{next_char} == 0x000C or # FF |
| 1073 | $self->{next_input_character} == 0x0020) { # SP | $self->{next_char} == 0x0020) { # SP |
| 1074 | !!!cp (59); | |
| 1075 | $before_leave->(); | $before_leave->(); |
| 1076 | $self->{state} = 'after attribute name'; | $self->{state} = AFTER_ATTRIBUTE_NAME_STATE; |
| 1077 | !!!next-input-character; | !!!next-input-character; |
| 1078 | redo A; | redo A; |
| 1079 | } elsif ($self->{next_input_character} == 0x003D) { # = | } elsif ($self->{next_char} == 0x003D) { # = |
| 1080 | !!!cp (60); | |
| 1081 | $before_leave->(); | $before_leave->(); |
| 1082 | $self->{state} = 'before attribute value'; | $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE; |
| 1083 | !!!next-input-character; | !!!next-input-character; |
| 1084 | redo A; | redo A; |
| 1085 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 1086 | $before_leave->(); | $before_leave->(); |
| 1087 | if ($self->{current_token}->{type} eq 'start tag') { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1088 | $self->{current_token}->{first_start_tag} | !!!cp (61); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1089 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1090 | } elsif ($self->{current_token}->{type} eq 'end tag') { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1091 | $self->{content_model_flag} = 'PCDATA'; # MUST | !!!cp (62); |
| 1092 | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST | |
| 1093 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1094 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1095 | } | } |
| 1096 | } else { | } else { |
| 1097 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| 1098 | } | } |
| 1099 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 1100 | !!!next-input-character; | !!!next-input-character; |
| 1101 | ||
| 1102 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 1103 | ||
| 1104 | redo A; | redo A; |
| 1105 | } elsif (0x0041 <= $self->{next_input_character} and | } elsif (0x0041 <= $self->{next_char} and |
| 1106 | $self->{next_input_character} <= 0x005A) { # A..Z | $self->{next_char} <= 0x005A) { # A..Z |
| 1107 | $self->{current_attribute}->{name} .= chr ($self->{next_input_character} + 0x0020); | !!!cp (63); |
| 1108 | $self->{current_attribute}->{name} .= chr ($self->{next_char} + 0x0020); | |
| 1109 | ## Stay in the state | ## Stay in the state |
| 1110 | !!!next-input-character; | !!!next-input-character; |
| 1111 | redo A; | redo A; |
| 1112 | } elsif ($self->{next_input_character} == 0x002F) { # / | } elsif ($self->{next_char} == 0x002F) { # / |
| 1113 | !!!cp (64); | |
| 1114 | $before_leave->(); | $before_leave->(); |
| 1115 | $self->{state} = SELF_CLOSING_START_TAG_STATE; | |
| 1116 | !!!next-input-character; | !!!next-input-character; |
| if ($self->{next_input_character} == 0x003E and # > | ||
| $self->{current_token}->{type} eq 'start tag' and | ||
| $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) { | ||
| # permitted slash | ||
| # | ||
| } else { | ||
| !!!parse-error (type => 'nestc'); | ||
| } | ||
| $self->{state} = 'before attribute name'; | ||
| # next-input-character is already done | ||
| 1117 | redo A; | redo A; |
| 1118 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1119 | !!!parse-error (type => 'unclosed tag'); | !!!parse-error (type => 'unclosed tag'); |
| 1120 | $before_leave->(); | $before_leave->(); |
| 1121 | if ($self->{current_token}->{type} eq 'start tag') { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1122 | $self->{current_token}->{first_start_tag} | !!!cp (66); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1123 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1124 | } elsif ($self->{current_token}->{type} eq 'end tag') { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1125 | $self->{content_model_flag} = 'PCDATA'; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1126 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1127 | !!!cp (67); | |
| 1128 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1129 | } else { | |
| 1130 | ## NOTE: This state should never be reached. | |
| 1131 | !!!cp (68); | |
| 1132 | } | } |
| 1133 | } else { | } else { |
| 1134 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| 1135 | } | } |
| 1136 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 1137 | # reconsume | # reconsume |
| 1138 | ||
| 1139 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 1140 | ||
| 1141 | redo A; | redo A; |
| 1142 | } else { | } else { |
| 1143 | $self->{current_attribute}->{name} .= chr ($self->{next_input_character}); | if ($self->{next_char} == 0x0022 or # " |
| 1144 | $self->{next_char} == 0x0027) { # ' | |
| 1145 | !!!cp (69); | |
| 1146 | !!!parse-error (type => 'bad attribute name'); | |
| 1147 | } else { | |
| 1148 | !!!cp (70); | |
| 1149 | } | |
| 1150 | $self->{current_attribute}->{name} .= chr ($self->{next_char}); | |
| 1151 | ## Stay in the state | ## Stay in the state |
| 1152 | !!!next-input-character; | !!!next-input-character; |
| 1153 | redo A; | redo A; |
| 1154 | } | } |
| 1155 | } elsif ($self->{state} eq 'after attribute name') { | } elsif ($self->{state} == AFTER_ATTRIBUTE_NAME_STATE) { |
| 1156 | if ($self->{next_input_character} == 0x0009 or # HT | if ($self->{next_char} == 0x0009 or # HT |
| 1157 | $self->{next_input_character} == 0x000A or # LF | $self->{next_char} == 0x000A or # LF |
| 1158 | $self->{next_input_character} == 0x000B or # VT | $self->{next_char} == 0x000B or # VT |
| 1159 | $self->{next_input_character} == 0x000C or # FF | $self->{next_char} == 0x000C or # FF |
| 1160 | $self->{next_input_character} == 0x0020) { # SP | $self->{next_char} == 0x0020) { # SP |
| 1161 | !!!cp (71); | |
| 1162 | ## Stay in the state | ## Stay in the state |
| 1163 | !!!next-input-character; | !!!next-input-character; |
| 1164 | redo A; | redo A; |
| 1165 | } elsif ($self->{next_input_character} == 0x003D) { # = | } elsif ($self->{next_char} == 0x003D) { # = |
| 1166 | $self->{state} = 'before attribute value'; | !!!cp (72); |
| 1167 | $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE; | |
| 1168 | !!!next-input-character; | !!!next-input-character; |
| 1169 | redo A; | redo A; |
| 1170 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 1171 | if ($self->{current_token}->{type} eq 'start tag') { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1172 | $self->{current_token}->{first_start_tag} | !!!cp (73); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1173 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1174 | } elsif ($self->{current_token}->{type} eq 'end tag') { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1175 | $self->{content_model_flag} = 'PCDATA'; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1176 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1177 | !!!cp (74); | |
| 1178 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1179 | } else { | |
| 1180 | ## NOTE: This state should never be reached. | |
| 1181 | !!!cp (75); | |
| 1182 | } | } |
| 1183 | } else { | } else { |
| 1184 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| 1185 | } | } |
| 1186 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 1187 | !!!next-input-character; | !!!next-input-character; |
| 1188 | ||
| 1189 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 1190 | ||
| 1191 | redo A; | redo A; |
| 1192 | } elsif (0x0041 <= $self->{next_input_character} and | } elsif (0x0041 <= $self->{next_char} and |
| 1193 | $self->{next_input_character} <= 0x005A) { # A..Z | $self->{next_char} <= 0x005A) { # A..Z |
| 1194 | $self->{current_attribute} = {name => chr ($self->{next_input_character} + 0x0020), | !!!cp (76); |
| 1195 | value => ''}; | $self->{current_attribute} |
| 1196 | $self->{state} = 'attribute name'; | = {name => chr ($self->{next_char} + 0x0020), |
| 1197 | value => '', | |
| 1198 | line => $self->{line}, column => $self->{column}}; | |
| 1199 | $self->{state} = ATTRIBUTE_NAME_STATE; | |
| 1200 | !!!next-input-character; | |
| 1201 | redo A; | |
| 1202 | } elsif ($self->{next_char} == 0x002F) { # / | |
| 1203 | !!!cp (77); | |
| 1204 | $self->{state} = SELF_CLOSING_START_TAG_STATE; | |
| 1205 | !!!next-input-character; | !!!next-input-character; |
| 1206 | redo A; | redo A; |
| 1207 | } elsif ($self->{next_input_character} == 0x002F) { # / | } elsif ($self->{next_char} == -1) { |
| !!!next-input-character; | ||
| if ($self->{next_input_character} == 0x003E and # > | ||
| $self->{current_token}->{type} eq 'start tag' and | ||
| $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) { | ||
| # permitted slash | ||
| # | ||
| } else { | ||
| !!!parse-error (type => 'nestc'); | ||
| ## TODO: Different error type for <aa / bb> than <aa/> | ||
| } | ||
| $self->{state} = 'before attribute name'; | ||
| # next-input-character is already done | ||
| redo A; | ||
| } elsif ($self->{next_input_character} == -1) { | ||
| 1208 | !!!parse-error (type => 'unclosed tag'); | !!!parse-error (type => 'unclosed tag'); |
| 1209 | if ($self->{current_token}->{type} eq 'start tag') { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1210 | $self->{current_token}->{first_start_tag} | !!!cp (79); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1211 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1212 | } elsif ($self->{current_token}->{type} eq 'end tag') { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1213 | $self->{content_model_flag} = 'PCDATA'; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1214 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1215 | !!!cp (80); | |
| 1216 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1217 | } else { | |
| 1218 | ## NOTE: This state should never be reached. | |
| 1219 | !!!cp (81); | |
| 1220 | } | } |
| 1221 | } else { | } else { |
| 1222 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| 1223 | } | } |
| 1224 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 1225 | # reconsume | # reconsume |
| 1226 | ||
| 1227 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 1228 | ||
| 1229 | redo A; | redo A; |
| 1230 | } else { | } else { |
| 1231 | $self->{current_attribute} = {name => chr ($self->{next_input_character}), | !!!cp (82); |
| 1232 | value => ''}; | $self->{current_attribute} |
| 1233 | $self->{state} = 'attribute name'; | = {name => chr ($self->{next_char}), |
| 1234 | value => '', | |
| 1235 | line => $self->{line}, column => $self->{column}}; | |
| 1236 | $self->{state} = ATTRIBUTE_NAME_STATE; | |
| 1237 | !!!next-input-character; | !!!next-input-character; |
| 1238 | redo A; | redo A; |
| 1239 | } | } |
| 1240 | } elsif ($self->{state} eq 'before attribute value') { | } elsif ($self->{state} == BEFORE_ATTRIBUTE_VALUE_STATE) { |
| 1241 | if ($self->{next_input_character} == 0x0009 or # HT | if ($self->{next_char} == 0x0009 or # HT |
| 1242 | $self->{next_input_character} == 0x000A or # LF | $self->{next_char} == 0x000A or # LF |
| 1243 | $self->{next_input_character} == 0x000B or # VT | $self->{next_char} == 0x000B or # VT |
| 1244 | $self->{next_input_character} == 0x000C or # FF | $self->{next_char} == 0x000C or # FF |
| 1245 | $self->{next_input_character} == 0x0020) { # SP | $self->{next_char} == 0x0020) { # SP |
| 1246 | !!!cp (83); | |
| 1247 | ## Stay in the state | ## Stay in the state |
| 1248 | !!!next-input-character; | !!!next-input-character; |
| 1249 | redo A; | redo A; |
| 1250 | } elsif ($self->{next_input_character} == 0x0022) { # " | } elsif ($self->{next_char} == 0x0022) { # " |
| 1251 | $self->{state} = 'attribute value (double-quoted)'; | !!!cp (84); |
| 1252 | $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE; | |
| 1253 | !!!next-input-character; | !!!next-input-character; |
| 1254 | redo A; | redo A; |
| 1255 | } elsif ($self->{next_input_character} == 0x0026) { # & | } elsif ($self->{next_char} == 0x0026) { # & |
| 1256 | $self->{state} = 'attribute value (unquoted)'; | !!!cp (85); |
| 1257 | $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE; | |
| 1258 | ## reconsume | ## reconsume |
| 1259 | redo A; | redo A; |
| 1260 | } elsif ($self->{next_input_character} == 0x0027) { # ' | } elsif ($self->{next_char} == 0x0027) { # ' |
| 1261 | $self->{state} = 'attribute value (single-quoted)'; | !!!cp (86); |
| 1262 | $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE; | |
| 1263 | !!!next-input-character; | !!!next-input-character; |
| 1264 | redo A; | redo A; |
| 1265 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 1266 | if ($self->{current_token}->{type} eq 'start tag') { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1267 | $self->{current_token}->{first_start_tag} | !!!cp (87); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1268 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1269 | } elsif ($self->{current_token}->{type} eq 'end tag') { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1270 | $self->{content_model_flag} = 'PCDATA'; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1271 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1272 | !!!cp (88); | |
| 1273 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1274 | } else { | |
| 1275 | ## NOTE: This state should never be reached. | |
| 1276 | !!!cp (89); | |
| 1277 | } | } |
| 1278 | } else { | } else { |
| 1279 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| 1280 | } | } |
| 1281 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 1282 | !!!next-input-character; | !!!next-input-character; |
| 1283 | ||
| 1284 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 1285 | ||
| 1286 | redo A; | redo A; |
| 1287 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1288 | !!!parse-error (type => 'unclosed tag'); | !!!parse-error (type => 'unclosed tag'); |
| 1289 | if ($self->{current_token}->{type} eq 'start tag') { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1290 | $self->{current_token}->{first_start_tag} | !!!cp (90); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1291 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1292 | } elsif ($self->{current_token}->{type} eq 'end tag') { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1293 | $self->{content_model_flag} = 'PCDATA'; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1294 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1295 | !!!cp (91); | |
| 1296 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1297 | } else { | |
| 1298 | ## NOTE: This state should never be reached. | |
| 1299 | !!!cp (92); | |
| 1300 | } | } |
| 1301 | } else { | } else { |
| 1302 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| 1303 | } | } |
| 1304 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 1305 | ## reconsume | ## reconsume |
| 1306 | ||
| 1307 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 1308 | ||
| 1309 | redo A; | redo A; |
| 1310 | } else { | } else { |
| 1311 | $self->{current_attribute}->{value} .= chr ($self->{next_input_character}); | if ($self->{next_char} == 0x003D) { # = |
| 1312 | $self->{state} = 'attribute value (unquoted)'; | !!!cp (93); |
| 1313 | !!!parse-error (type => 'bad attribute value'); | |
| 1314 | } else { | |
| 1315 | !!!cp (94); | |
| 1316 | } | |
| 1317 | $self->{current_attribute}->{value} .= chr ($self->{next_char}); | |
| 1318 | $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE; | |
| 1319 | !!!next-input-character; | !!!next-input-character; |
| 1320 | redo A; | redo A; |
| 1321 | } | } |
| 1322 | } elsif ($self->{state} eq 'attribute value (double-quoted)') { | } elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) { |
| 1323 | if ($self->{next_input_character} == 0x0022) { # " | if ($self->{next_char} == 0x0022) { # " |
| 1324 | $self->{state} = 'before attribute name'; | !!!cp (95); |
| 1325 | $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE; | |
| 1326 | !!!next-input-character; | !!!next-input-character; |
| 1327 | redo A; | redo A; |
| 1328 | } elsif ($self->{next_input_character} == 0x0026) { # & | } elsif ($self->{next_char} == 0x0026) { # & |
| 1329 | $self->{last_attribute_value_state} = 'attribute value (double-quoted)'; | !!!cp (96); |
| 1330 | $self->{state} = 'entity in attribute value'; | $self->{last_attribute_value_state} = $self->{state}; |
| 1331 | $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE; | |
| 1332 | !!!next-input-character; | !!!next-input-character; |
| 1333 | redo A; | redo A; |
| 1334 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1335 | !!!parse-error (type => 'unclosed attribute value'); | !!!parse-error (type => 'unclosed attribute value'); |
| 1336 | if ($self->{current_token}->{type} eq 'start tag') { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1337 | $self->{current_token}->{first_start_tag} | !!!cp (97); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1338 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1339 | } elsif ($self->{current_token}->{type} eq 'end tag') { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1340 | $self->{content_model_flag} = 'PCDATA'; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1341 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1342 | !!!cp (98); | |
| 1343 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1344 | } else { | |
| 1345 | ## NOTE: This state should never be reached. | |
| 1346 | !!!cp (99); | |
| 1347 | } | } |
| 1348 | } else { | } else { |
| 1349 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| 1350 | } | } |
| 1351 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 1352 | ## reconsume | ## reconsume |
| 1353 | ||
| 1354 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 1355 | ||
| 1356 | redo A; | redo A; |
| 1357 | } else { | } else { |
| 1358 | $self->{current_attribute}->{value} .= chr ($self->{next_input_character}); | !!!cp (100); |
| 1359 | $self->{current_attribute}->{value} .= chr ($self->{next_char}); | |
| 1360 | ## Stay in the state | ## Stay in the state |
| 1361 | !!!next-input-character; | !!!next-input-character; |
| 1362 | redo A; | redo A; |
| 1363 | } | } |
| 1364 | } elsif ($self->{state} eq 'attribute value (single-quoted)') { | } elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) { |
| 1365 | if ($self->{next_input_character} == 0x0027) { # ' | if ($self->{next_char} == 0x0027) { # ' |
| 1366 | $self->{state} = 'before attribute name'; | !!!cp (101); |
| 1367 | $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE; | |
| 1368 | !!!next-input-character; | !!!next-input-character; |
| 1369 | redo A; | redo A; |
| 1370 | } elsif ($self->{next_input_character} == 0x0026) { # & | } elsif ($self->{next_char} == 0x0026) { # & |
| 1371 | $self->{last_attribute_value_state} = 'attribute value (single-quoted)'; | !!!cp (102); |
| 1372 | $self->{state} = 'entity in attribute value'; | $self->{last_attribute_value_state} = $self->{state}; |
| 1373 | $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE; | |
| 1374 | !!!next-input-character; | !!!next-input-character; |
| 1375 | redo A; | redo A; |
| 1376 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1377 | !!!parse-error (type => 'unclosed attribute value'); | !!!parse-error (type => 'unclosed attribute value'); |
| 1378 | if ($self->{current_token}->{type} eq 'start tag') { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1379 | $self->{current_token}->{first_start_tag} | !!!cp (103); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1380 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1381 | } elsif ($self->{current_token}->{type} eq 'end tag') { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1382 | $self->{content_model_flag} = 'PCDATA'; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1383 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1384 | !!!cp (104); | |
| 1385 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1386 | } else { | |
| 1387 | ## NOTE: This state should never be reached. | |
| 1388 | !!!cp (105); | |
| 1389 | } | } |
| 1390 | } else { | } else { |
| 1391 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| 1392 | } | } |
| 1393 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 1394 | ## reconsume | ## reconsume |
| 1395 | ||
| 1396 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 1397 | ||
| 1398 | redo A; | redo A; |
| 1399 | } else { | } else { |
| 1400 | $self->{current_attribute}->{value} .= chr ($self->{next_input_character}); | !!!cp (106); |
| 1401 | $self->{current_attribute}->{value} .= chr ($self->{next_char}); | |
| 1402 | ## Stay in the state | ## Stay in the state |
| 1403 | !!!next-input-character; | !!!next-input-character; |
| 1404 | redo A; | redo A; |
| 1405 | } | } |
| 1406 | } elsif ($self->{state} eq 'attribute value (unquoted)') { | } elsif ($self->{state} == ATTRIBUTE_VALUE_UNQUOTED_STATE) { |
| 1407 | if ($self->{next_input_character} == 0x0009 or # HT | if ($self->{next_char} == 0x0009 or # HT |
| 1408 | $self->{next_input_character} == 0x000A or # LF | $self->{next_char} == 0x000A or # LF |
| 1409 | $self->{next_input_character} == 0x000B or # HT | $self->{next_char} == 0x000B or # HT |
| 1410 | $self->{next_input_character} == 0x000C or # FF | $self->{next_char} == 0x000C or # FF |
| 1411 | $self->{next_input_character} == 0x0020) { # SP | $self->{next_char} == 0x0020) { # SP |
| 1412 | $self->{state} = 'before attribute name'; | !!!cp (107); |
| 1413 | !!!next-input-character; | $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
| 1414 | redo A; | !!!next-input-character; |
| 1415 | } elsif ($self->{next_input_character} == 0x0026) { # & | redo A; |
| 1416 | $self->{last_attribute_value_state} = 'attribute value (unquoted)'; | } elsif ($self->{next_char} == 0x0026) { # & |
| 1417 | $self->{state} = 'entity in attribute value'; | !!!cp (108); |
| 1418 | !!!next-input-character; | $self->{last_attribute_value_state} = $self->{state}; |
| 1419 | redo A; | $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE; |
| 1420 | } elsif ($self->{next_input_character} == 0x003E) { # > | !!!next-input-character; |
| 1421 | if ($self->{current_token}->{type} eq 'start tag') { | redo A; |
| 1422 | $self->{current_token}->{first_start_tag} | } elsif ($self->{next_char} == 0x003E) { # > |
| 1423 | = not defined $self->{last_emitted_start_tag_name}; | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1424 | !!!cp (109); | |
| 1425 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1426 | } elsif ($self->{current_token}->{type} eq 'end tag') { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1427 | $self->{content_model_flag} = 'PCDATA'; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1428 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1429 | !!!cp (110); | |
| 1430 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1431 | } else { | |
| 1432 | ## NOTE: This state should never be reached. | |
| 1433 | !!!cp (111); | |
| 1434 | } | } |
| 1435 | } else { | } else { |
| 1436 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| 1437 | } | } |
| 1438 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 1439 | !!!next-input-character; | !!!next-input-character; |
| 1440 | ||
| 1441 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 1442 | ||
| 1443 | redo A; | redo A; |
| 1444 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1445 | !!!parse-error (type => 'unclosed tag'); | !!!parse-error (type => 'unclosed tag'); |
| 1446 | if ($self->{current_token}->{type} eq 'start tag') { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1447 | $self->{current_token}->{first_start_tag} | !!!cp (112); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1448 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1449 | } elsif ($self->{current_token}->{type} eq 'end tag') { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1450 | $self->{content_model_flag} = 'PCDATA'; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1451 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1452 | !!!cp (113); | |
| 1453 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1454 | } else { | |
| 1455 | ## NOTE: This state should never be reached. | |
| 1456 | !!!cp (114); | |
| 1457 | } | } |
| 1458 | } else { | } else { |
| 1459 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| 1460 | } | } |
| 1461 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 1462 | ## reconsume | ## reconsume |
| 1463 | ||
| 1464 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 1465 | ||
| 1466 | redo A; | redo A; |
| 1467 | } else { | } else { |
| 1468 | $self->{current_attribute}->{value} .= chr ($self->{next_input_character}); | if ({ |
| 1469 | 0x0022 => 1, # " | |
| 1470 | 0x0027 => 1, # ' | |
| 1471 | 0x003D => 1, # = | |
| 1472 | }->{$self->{next_char}}) { | |
| 1473 | !!!cp (115); | |
| 1474 | !!!parse-error (type => 'bad attribute value'); | |
| 1475 | } else { | |
| 1476 | !!!cp (116); | |
| 1477 | } | |
| 1478 | $self->{current_attribute}->{value} .= chr ($self->{next_char}); | |
| 1479 | ## Stay in the state | ## Stay in the state |
| 1480 | !!!next-input-character; | !!!next-input-character; |
| 1481 | redo A; | redo A; |
| 1482 | } | } |
| 1483 | } elsif ($self->{state} eq 'entity in attribute value') { | } elsif ($self->{state} == ENTITY_IN_ATTRIBUTE_VALUE_STATE) { |
| 1484 | my $token = $self->_tokenize_attempt_to_consume_an_entity (1); | my $token = $self->_tokenize_attempt_to_consume_an_entity |
| 1485 | (1, | |
| 1486 | $self->{last_attribute_value_state} | |
| 1487 | == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE ? 0x0022 : # " | |
| 1488 | $self->{last_attribute_value_state} | |
| 1489 | == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE ? 0x0027 : # ' | |
| 1490 | -1); | |
| 1491 | ||
| 1492 | unless (defined $token) { | unless (defined $token) { |
| 1493 | !!!cp (117); | |
| 1494 | $self->{current_attribute}->{value} .= '&'; | $self->{current_attribute}->{value} .= '&'; |
| 1495 | } else { | } else { |
| 1496 | !!!cp (118); | |
| 1497 | $self->{current_attribute}->{value} .= $token->{data}; | $self->{current_attribute}->{value} .= $token->{data}; |
| 1498 | $self->{current_attribute}->{has_reference} = $token->{has_reference}; | |
| 1499 | ## ISSUE: spec says "append the returned character token to the current attribute's value" | ## ISSUE: spec says "append the returned character token to the current attribute's value" |
| 1500 | } | } |
| 1501 | ||
| 1502 | $self->{state} = $self->{last_attribute_value_state}; | $self->{state} = $self->{last_attribute_value_state}; |
| 1503 | # next-input-character is already done | # next-input-character is already done |
| 1504 | redo A; | redo A; |
| 1505 | } elsif ($self->{state} eq 'bogus comment') { | } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) { |
| 1506 | if ($self->{next_char} == 0x0009 or # HT | |
| 1507 | $self->{next_char} == 0x000A or # LF | |
| 1508 | $self->{next_char} == 0x000B or # VT | |
| 1509 | $self->{next_char} == 0x000C or # FF | |
| 1510 | $self->{next_char} == 0x0020) { # SP | |
| 1511 | !!!cp (118); | |
| 1512 | $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; | |
| 1513 | !!!next-input-character; | |
| 1514 | redo A; | |
| 1515 | } elsif ($self->{next_char} == 0x003E) { # > | |
| 1516 | if ($self->{current_token}->{type} == START_TAG_TOKEN) { | |
| 1517 | !!!cp (119); | |
| 1518 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | |
| 1519 | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { | |
| 1520 | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST | |
| 1521 | if ($self->{current_token}->{attributes}) { | |
| 1522 | !!!cp (120); | |
| 1523 | !!!parse-error (type => 'end tag attribute'); | |
| 1524 | } else { | |
| 1525 | ## NOTE: This state should never be reached. | |
| 1526 | !!!cp (121); | |
| 1527 | } | |
| 1528 | } else { | |
| 1529 | die "$0: $self->{current_token}->{type}: Unknown token type"; | |
| 1530 | } | |
| 1531 | $self->{state} = DATA_STATE; | |
| 1532 | !!!next-input-character; | |
| 1533 | ||
| 1534 | !!!emit ($self->{current_token}); # start tag or end tag | |
| 1535 | ||
| 1536 | redo A; | |
| 1537 | } elsif ($self->{next_char} == 0x002F) { # / | |
| 1538 | !!!cp (122); | |
| 1539 | $self->{state} = SELF_CLOSING_START_TAG_STATE; | |
| 1540 | !!!next-input-character; | |
| 1541 | redo A; | |
| 1542 | } else { | |
| 1543 | !!!cp ('124.1'); | |
| 1544 | !!!parse-error (type => 'no space between attributes'); | |
| 1545 | $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; | |
| 1546 | ## reconsume | |
| 1547 | redo A; | |
| 1548 | } | |
| 1549 | } elsif ($self->{state} == SELF_CLOSING_START_TAG_STATE) { | |
| 1550 | if ($self->{next_char} == 0x003E) { # > | |
| 1551 | if ($self->{current_token}->{type} == END_TAG_TOKEN) { | |
| 1552 | !!!cp ('124.2'); | |
| 1553 | !!!parse-error (type => 'nestc', token => $self->{current_token}); | |
| 1554 | ## TODO: Different type than slash in start tag | |
| 1555 | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST | |
| 1556 | if ($self->{current_token}->{attributes}) { | |
| 1557 | !!!cp ('124.4'); | |
| 1558 | !!!parse-error (type => 'end tag attribute'); | |
| 1559 | } else { | |
| 1560 | !!!cp ('124.5'); | |
| 1561 | } | |
| 1562 | ## TODO: Test |<title></title/>| | |
| 1563 | } else { | |
| 1564 | !!!cp ('124.3'); | |
| 1565 | $self->{self_closing} = 1; | |
| 1566 | } | |
| 1567 | ||
| 1568 | $self->{state} = DATA_STATE; | |
| 1569 | !!!next-input-character; | |
| 1570 | ||
| 1571 | !!!emit ($self->{current_token}); # start tag or end tag | |
| 1572 | ||
| 1573 | redo A; | |
| 1574 | } else { | |
| 1575 | !!!cp ('124.4'); | |
| 1576 | !!!parse-error (type => 'nestc'); | |
| 1577 | ## TODO: This error type is wrong. | |
| 1578 | $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; | |
| 1579 | ## Reconsume. | |
| 1580 | redo A; | |
| 1581 | } | |
| 1582 | } elsif ($self->{state} == BOGUS_COMMENT_STATE) { | |
| 1583 | ## (only happen if PCDATA state) | ## (only happen if PCDATA state) |
| 1584 | ||
| 1585 | my $token = {type => 'comment', data => ''}; | ## NOTE: Set by the previous state |
| 1586 | #my $token = {type => COMMENT_TOKEN, data => ''}; | |
| 1587 | ||
| 1588 | BC: { | BC: { |
| 1589 | if ($self->{next_input_character} == 0x003E) { # > | if ($self->{next_char} == 0x003E) { # > |
| 1590 | $self->{state} = 'data'; | !!!cp (124); |
| 1591 | $self->{state} = DATA_STATE; | |
| 1592 | !!!next-input-character; | !!!next-input-character; |
| 1593 | ||
| 1594 | !!!emit ($token); | !!!emit ($self->{current_token}); # comment |
| 1595 | ||
| 1596 | redo A; | redo A; |
| 1597 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1598 | $self->{state} = 'data'; | !!!cp (125); |
| 1599 | $self->{state} = DATA_STATE; | |
| 1600 | ## reconsume | ## reconsume |
| 1601 | ||
| 1602 | !!!emit ($token); | !!!emit ($self->{current_token}); # comment |
| 1603 | ||
| 1604 | redo A; | redo A; |
| 1605 | } else { | } else { |
| 1606 | $token->{data} .= chr ($self->{next_input_character}); | !!!cp (126); |
| 1607 | $self->{current_token}->{data} .= chr ($self->{next_char}); # comment | |
| 1608 | !!!next-input-character; | !!!next-input-character; |
| 1609 | redo BC; | redo BC; |
| 1610 | } | } |
| 1611 | } # BC | } # BC |
| 1612 | } elsif ($self->{state} eq 'markup declaration open') { | |
| 1613 | die "$0: _get_next_token: unexpected case [BC]"; | |
| 1614 | } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) { | |
| 1615 | ## (only happen if PCDATA state) | ## (only happen if PCDATA state) |
| 1616 | ||
| 1617 | my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); | |
| 1618 | ||
| 1619 | my @next_char; | my @next_char; |
| 1620 | push @next_char, $self->{next_input_character}; | push @next_char, $self->{next_char}; |
| 1621 | ||
| 1622 | if ($self->{next_input_character} == 0x002D) { # - | if ($self->{next_char} == 0x002D) { # - |
| 1623 | !!!next-input-character; | !!!next-input-character; |
| 1624 | push @next_char, $self->{next_input_character}; | push @next_char, $self->{next_char}; |
| 1625 | if ($self->{next_input_character} == 0x002D) { # - | if ($self->{next_char} == 0x002D) { # - |
| 1626 | $self->{current_token} = {type => 'comment', data => ''}; | !!!cp (127); |
| 1627 | $self->{state} = 'comment start'; | $self->{current_token} = {type => COMMENT_TOKEN, data => '', |
| 1628 | line => $l, column => $c, | |
| 1629 | }; | |
| 1630 | $self->{state} = COMMENT_START_STATE; | |
| 1631 | !!!next-input-character; | !!!next-input-character; |
| 1632 | redo A; | redo A; |
| 1633 | } else { | |
| 1634 | !!!cp (128); | |
| 1635 | } | |
| 1636 | } elsif ($self->{next_char} == 0x0044 or # D | |
| 1637 | $self->{next_char} == 0x0064) { # d | |
| 1638 | !!!next-input-character; | |
| 1639 | push @next_char, $self->{next_char}; | |
| 1640 | if ($self->{next_char} == 0x004F or # O | |
| 1641 | $self->{next_char} == 0x006F) { # o | |
| 1642 | !!!next-input-character; | |
| 1643 | push @next_char, $self->{next_char}; | |
| 1644 | if ($self->{next_char} == 0x0043 or # C | |
| 1645 | $self->{next_char} == 0x0063) { # c | |
| 1646 | !!!next-input-character; | |
| 1647 | push @next_char, $self->{next_char}; | |
| 1648 | if ($self->{next_char} == 0x0054 or # T | |
| 1649 | $self->{next_char} == 0x0074) { # t | |
| 1650 | !!!next-input-character; | |
| 1651 | push @next_char, $self->{next_char}; | |
| 1652 | if ($self->{next_char} == 0x0059 or # Y | |
| 1653 | $self->{next_char} == 0x0079) { # y | |
| 1654 | !!!next-input-character; | |
| 1655 | push @next_char, $self->{next_char}; | |
| 1656 | if ($self->{next_char} == 0x0050 or # P | |
| 1657 | $self->{next_char} == 0x0070) { # p | |
| 1658 | !!!next-input-character; | |
| 1659 | push @next_char, $self->{next_char}; | |
| 1660 | if ($self->{next_char} == 0x0045 or # E | |
| 1661 | $self->{next_char} == 0x0065) { # e | |
| 1662 | !!!cp (129); | |
| 1663 | ## TODO: What a stupid code this is! | |
| 1664 | $self->{state} = DOCTYPE_STATE; | |
| 1665 | $self->{current_token} = {type => DOCTYPE_TOKEN, | |
| 1666 | quirks => 1, | |
| 1667 | line => $l, column => $c, | |
| 1668 | }; | |
| 1669 | !!!next-input-character; | |
| 1670 | redo A; | |
| 1671 | } else { | |
| 1672 | !!!cp (130); | |
| 1673 | } | |
| 1674 | } else { | |
| 1675 | !!!cp (131); | |
| 1676 | } | |
| 1677 | } else { | |
| 1678 | !!!cp (132); | |
| 1679 | } | |
| 1680 | } else { | |
| 1681 | !!!cp (133); | |
| 1682 | } | |
| 1683 | } else { | |
| 1684 | !!!cp (134); | |
| 1685 | } | |
| 1686 | } else { | |
| 1687 | !!!cp (135); | |
| 1688 | } | } |
| 1689 | } elsif ($self->{next_input_character} == 0x0044 or # D | } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and |
| 1690 | $self->{next_input_character} == 0x0064) { # d | $self->{open_elements}->[-1]->[1] & FOREIGN_EL and |
| 1691 | $self->{next_char} == 0x005B) { # [ | |
| 1692 | !!!next-input-character; | !!!next-input-character; |
| 1693 | push @next_char, $self->{next_input_character}; | push @next_char, $self->{next_char}; |
| 1694 | if ($self->{next_input_character} == 0x004F or # O | if ($self->{next_char} == 0x0043) { # C |
| $self->{next_input_character} == 0x006F) { # o | ||
| 1695 | !!!next-input-character; | !!!next-input-character; |
| 1696 | push @next_char, $self->{next_input_character}; | push @next_char, $self->{next_char}; |
| 1697 | if ($self->{next_input_character} == 0x0043 or # C | if ($self->{next_char} == 0x0044) { # D |
| $self->{next_input_character} == 0x0063) { # c | ||
| 1698 | !!!next-input-character; | !!!next-input-character; |
| 1699 | push @next_char, $self->{next_input_character}; | push @next_char, $self->{next_char}; |
| 1700 | if ($self->{next_input_character} == 0x0054 or # T | if ($self->{next_char} == 0x0041) { # A |
| $self->{next_input_character} == 0x0074) { # t | ||
| 1701 | !!!next-input-character; | !!!next-input-character; |
| 1702 | push @next_char, $self->{next_input_character}; | push @next_char, $self->{next_char}; |
| 1703 | if ($self->{next_input_character} == 0x0059 or # Y | if ($self->{next_char} == 0x0054) { # T |
| $self->{next_input_character} == 0x0079) { # y | ||
| 1704 | !!!next-input-character; | !!!next-input-character; |
| 1705 | push @next_char, $self->{next_input_character}; | push @next_char, $self->{next_char}; |
| 1706 | if ($self->{next_input_character} == 0x0050 or # P | if ($self->{next_char} == 0x0041) { # A |
| $self->{next_input_character} == 0x0070) { # p | ||
| 1707 | !!!next-input-character; | !!!next-input-character; |
| 1708 | push @next_char, $self->{next_input_character}; | push @next_char, $self->{next_char}; |
| 1709 | if ($self->{next_input_character} == 0x0045 or # E | if ($self->{next_char} == 0x005B) { # [ |
| 1710 | $self->{next_input_character} == 0x0065) { # e | !!!cp (135.1); |
| 1711 | ## ISSUE: What a stupid code this is! | $self->{state} = CDATA_BLOCK_STATE; |
| $self->{state} = 'DOCTYPE'; | ||
| 1712 | !!!next-input-character; | !!!next-input-character; |
| 1713 | redo A; | redo A; |
| 1714 | } else { | |
| 1715 | !!!cp (135.2); | |
| 1716 | } | } |
| 1717 | } else { | |
| 1718 | !!!cp (135.3); | |
| 1719 | } | } |
| 1720 | } else { | |
| 1721 | !!!cp (135.4); | |
| 1722 | } | } |
| 1723 | } else { | |
| 1724 | !!!cp (135.5); | |
| 1725 | } | } |
| 1726 | } else { | |
| 1727 | !!!cp (135.6); | |
| 1728 | } | } |
| 1729 | } else { | |
| 1730 | !!!cp (135.7); | |
| 1731 | } | } |
| 1732 | } else { | |
| 1733 | !!!cp (136); | |
| 1734 | } | } |
| 1735 | ||
| 1736 | !!!parse-error (type => 'bogus comment'); | !!!parse-error (type => 'bogus comment'); |
| 1737 | $self->{next_input_character} = shift @next_char; | $self->{next_char} = shift @next_char; |
| 1738 | !!!back-next-input-character (@next_char); | !!!back-next-input-character (@next_char); |
| 1739 | $self->{state} = 'bogus comment'; | $self->{state} = BOGUS_COMMENT_STATE; |
| 1740 | $self->{current_token} = {type => COMMENT_TOKEN, data => '', | |
| 1741 | line => $l, column => $c, | |
| 1742 | }; | |
| 1743 | redo A; | redo A; |
| 1744 | ||
| 1745 | ## ISSUE: typos in spec: chacacters, is is a parse error | ## ISSUE: typos in spec: chacacters, is is a parse error |
| 1746 | ## 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? | ## 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? |
| 1747 | } elsif ($self->{state} eq 'comment start') { | } elsif ($self->{state} == COMMENT_START_STATE) { |
| 1748 | if ($self->{next_input_character} == 0x002D) { # - | if ($self->{next_char} == 0x002D) { # - |
| 1749 | $self->{state} = 'comment start dash'; | !!!cp (137); |
| 1750 | $self->{state} = COMMENT_START_DASH_STATE; | |
| 1751 | !!!next-input-character; | !!!next-input-character; |
| 1752 | redo A; | redo A; |
| 1753 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 1754 | !!!cp (138); | |
| 1755 | !!!parse-error (type => 'bogus comment'); | !!!parse-error (type => 'bogus comment'); |
| 1756 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 1757 | !!!next-input-character; | !!!next-input-character; |
| 1758 | ||
| 1759 | !!!emit ($self->{current_token}); # comment | !!!emit ($self->{current_token}); # comment |
| 1760 | ||
| 1761 | redo A; | redo A; |
| 1762 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1763 | !!!cp (139); | |
| 1764 | !!!parse-error (type => 'unclosed comment'); | !!!parse-error (type => 'unclosed comment'); |
| 1765 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 1766 | ## reconsume | ## reconsume |
| 1767 | ||
| 1768 | !!!emit ($self->{current_token}); # comment | !!!emit ($self->{current_token}); # comment |
| 1769 | ||
| 1770 | redo A; | redo A; |
| 1771 | } else { | } else { |
| 1772 | !!!cp (140); | |
| 1773 | $self->{current_token}->{data} # comment | $self->{current_token}->{data} # comment |
| 1774 | .= chr ($self->{next_input_character}); | .= chr ($self->{next_char}); |
| 1775 | $self->{state} = 'comment'; | $self->{state} = COMMENT_STATE; |
| 1776 | !!!next-input-character; | !!!next-input-character; |
| 1777 | redo A; | redo A; |
| 1778 | } | } |
| 1779 | } elsif ($self->{state} eq 'comment start dash') { | } elsif ($self->{state} == COMMENT_START_DASH_STATE) { |
| 1780 | if ($self->{next_input_character} == 0x002D) { # - | if ($self->{next_char} == 0x002D) { # - |
| 1781 | $self->{state} = 'comment end'; | !!!cp (141); |
| 1782 | $self->{state} = COMMENT_END_STATE; | |
| 1783 | !!!next-input-character; | !!!next-input-character; |
| 1784 | redo A; | redo A; |
| 1785 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 1786 | !!!cp (142); | |
| 1787 | !!!parse-error (type => 'bogus comment'); | !!!parse-error (type => 'bogus comment'); |
| 1788 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 1789 | !!!next-input-character; | !!!next-input-character; |
| 1790 | ||
| 1791 | !!!emit ($self->{current_token}); # comment | !!!emit ($self->{current_token}); # comment |
| 1792 | ||
| 1793 | redo A; | redo A; |
| 1794 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1795 | !!!cp (143); | |
| 1796 | !!!parse-error (type => 'unclosed comment'); | !!!parse-error (type => 'unclosed comment'); |
| 1797 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 1798 | ## reconsume | ## reconsume |
| 1799 | ||
| 1800 | !!!emit ($self->{current_token}); # comment | !!!emit ($self->{current_token}); # comment |
| 1801 | ||
| 1802 | redo A; | redo A; |
| 1803 | } else { | } else { |
| 1804 | !!!cp (144); | |
| 1805 | $self->{current_token}->{data} # comment | $self->{current_token}->{data} # comment |
| 1806 | .= '-' . chr ($self->{next_input_character}); | .= '-' . chr ($self->{next_char}); |
| 1807 | $self->{state} = 'comment'; | $self->{state} = COMMENT_STATE; |
| 1808 | !!!next-input-character; | !!!next-input-character; |
| 1809 | redo A; | redo A; |
| 1810 | } | } |
| 1811 | } elsif ($self->{state} eq 'comment') { | } elsif ($self->{state} == COMMENT_STATE) { |
| 1812 | if ($self->{next_input_character} == 0x002D) { # - | if ($self->{next_char} == 0x002D) { # - |
| 1813 | $self->{state} = 'comment end dash'; | !!!cp (145); |
| 1814 | $self->{state} = COMMENT_END_DASH_STATE; | |
| 1815 | !!!next-input-character; | !!!next-input-character; |
| 1816 | redo A; | redo A; |
| 1817 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1818 | !!!cp (146); | |
| 1819 | !!!parse-error (type => 'unclosed comment'); | !!!parse-error (type => 'unclosed comment'); |
| 1820 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 1821 | ## reconsume | ## reconsume |
| 1822 | ||
| 1823 | !!!emit ($self->{current_token}); # comment | !!!emit ($self->{current_token}); # comment |
| 1824 | ||
| 1825 | redo A; | redo A; |
| 1826 | } else { | } else { |
| 1827 | $self->{current_token}->{data} .= chr ($self->{next_input_character}); # comment | !!!cp (147); |
| 1828 | $self->{current_token}->{data} .= chr ($self->{next_char}); # comment | |
| 1829 | ## Stay in the state | ## Stay in the state |
| 1830 | !!!next-input-character; | !!!next-input-character; |
| 1831 | redo A; | redo A; |
| 1832 | } | } |
| 1833 | } elsif ($self->{state} eq 'comment end dash') { | } elsif ($self->{state} == COMMENT_END_DASH_STATE) { |
| 1834 | if ($self->{next_input_character} == 0x002D) { # - | if ($self->{next_char} == 0x002D) { # - |
| 1835 | $self->{state} = 'comment end'; | !!!cp (148); |
| 1836 | $self->{state} = COMMENT_END_STATE; | |
| 1837 | !!!next-input-character; | !!!next-input-character; |
| 1838 | redo A; | redo A; |
| 1839 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1840 | !!!cp (149); | |
| 1841 | !!!parse-error (type => 'unclosed comment'); | !!!parse-error (type => 'unclosed comment'); |
| 1842 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 1843 | ## reconsume | ## reconsume |
| 1844 | ||
| 1845 | !!!emit ($self->{current_token}); # comment | !!!emit ($self->{current_token}); # comment |
| 1846 | ||
| 1847 | redo A; | redo A; |
| 1848 | } else { | } else { |
| 1849 | $self->{current_token}->{data} .= '-' . chr ($self->{next_input_character}); # comment | !!!cp (150); |
| 1850 | $self->{state} = 'comment'; | $self->{current_token}->{data} .= '-' . chr ($self->{next_char}); # comment |
| 1851 | $self->{state} = COMMENT_STATE; | |
| 1852 | !!!next-input-character; | !!!next-input-character; |
| 1853 | redo A; | redo A; |
| 1854 | } | } |
| 1855 | } elsif ($self->{state} eq 'comment end') { | } elsif ($self->{state} == COMMENT_END_STATE) { |
| 1856 | if ($self->{next_input_character} == 0x003E) { # > | if ($self->{next_char} == 0x003E) { # > |
| 1857 | $self->{state} = 'data'; | !!!cp (151); |
| 1858 | $self->{state} = DATA_STATE; | |
| 1859 | !!!next-input-character; | !!!next-input-character; |
| 1860 | ||
| 1861 | !!!emit ($self->{current_token}); # comment | !!!emit ($self->{current_token}); # comment |
| 1862 | ||
| 1863 | redo A; | redo A; |
| 1864 | } elsif ($self->{next_input_character} == 0x002D) { # - | } elsif ($self->{next_char} == 0x002D) { # - |
| 1865 | !!!parse-error (type => 'dash in comment'); | !!!cp (152); |
| 1866 | !!!parse-error (type => 'dash in comment', | |
| 1867 | line => $self->{line_prev}, | |
| 1868 | column => $self->{column_prev}); | |
| 1869 | $self->{current_token}->{data} .= '-'; # comment | $self->{current_token}->{data} .= '-'; # comment |
| 1870 | ## Stay in the state | ## Stay in the state |
| 1871 | !!!next-input-character; | !!!next-input-character; |
| 1872 | redo A; | redo A; |
| 1873 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1874 | !!!cp (153); | |
| 1875 | !!!parse-error (type => 'unclosed comment'); | !!!parse-error (type => 'unclosed comment'); |
| 1876 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 1877 | ## reconsume | ## reconsume |
| 1878 | ||
| 1879 | !!!emit ($self->{current_token}); # comment | !!!emit ($self->{current_token}); # comment |
| 1880 | ||
| 1881 | redo A; | redo A; |
| 1882 | } else { | } else { |
| 1883 | !!!parse-error (type => 'dash in comment'); | !!!cp (154); |
| 1884 | $self->{current_token}->{data} .= '--' . chr ($self->{next_input_character}); # comment | !!!parse-error (type => 'dash in comment', |
| 1885 | $self->{state} = 'comment'; | line => $self->{line_prev}, |
| 1886 | column => $self->{column_prev}); | |
| 1887 | $self->{current_token}->{data} .= '--' . chr ($self->{next_char}); # comment | |
| 1888 | $self->{state} = COMMENT_STATE; | |
| 1889 | !!!next-input-character; | !!!next-input-character; |
| 1890 | redo A; | redo A; |
| 1891 | } | } |
| 1892 | } elsif ($self->{state} eq 'DOCTYPE') { | } elsif ($self->{state} == DOCTYPE_STATE) { |
| 1893 | if ($self->{next_input_character} == 0x0009 or # HT | if ($self->{next_char} == 0x0009 or # HT |
| 1894 | $self->{next_input_character} == 0x000A or # LF | $self->{next_char} == 0x000A or # LF |
| 1895 | $self->{next_input_character} == 0x000B or # VT | $self->{next_char} == 0x000B or # VT |
| 1896 | $self->{next_input_character} == 0x000C or # FF | $self->{next_char} == 0x000C or # FF |
| 1897 | $self->{next_input_character} == 0x0020) { # SP | $self->{next_char} == 0x0020) { # SP |
| 1898 | $self->{state} = 'before DOCTYPE name'; | !!!cp (155); |
| 1899 | $self->{state} = BEFORE_DOCTYPE_NAME_STATE; | |
| 1900 | !!!next-input-character; | !!!next-input-character; |
| 1901 | redo A; | redo A; |
| 1902 | } else { | } else { |
| 1903 | !!!cp (156); | |
| 1904 | !!!parse-error (type => 'no space before DOCTYPE name'); | !!!parse-error (type => 'no space before DOCTYPE name'); |
| 1905 | $self->{state} = 'before DOCTYPE name'; | $self->{state} = BEFORE_DOCTYPE_NAME_STATE; |
| 1906 | ## reconsume | ## reconsume |
| 1907 | redo A; | redo A; |
| 1908 | } | } |
| 1909 | } elsif ($self->{state} eq 'before DOCTYPE name') { | } elsif ($self->{state} == BEFORE_DOCTYPE_NAME_STATE) { |
| 1910 | if ($self->{next_input_character} == 0x0009 or # HT | if ($self->{next_char} == 0x0009 or # HT |
| 1911 | $self->{next_input_character} == 0x000A or # LF | $self->{next_char} == 0x000A or # LF |
| 1912 | $self->{next_input_character} == 0x000B or # VT | $self->{next_char} == 0x000B or # VT |
| 1913 | $self->{next_input_character} == 0x000C or # FF | $self->{next_char} == 0x000C or # FF |
| 1914 | $self->{next_input_character} == 0x0020) { # SP | $self->{next_char} == 0x0020) { # SP |
| 1915 | !!!cp (157); | |
| 1916 | ## Stay in the state | ## Stay in the state |
| 1917 | !!!next-input-character; | !!!next-input-character; |
| 1918 | redo A; | redo A; |
| 1919 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 1920 | !!!cp (158); | |
| 1921 | !!!parse-error (type => 'no DOCTYPE name'); | !!!parse-error (type => 'no DOCTYPE name'); |
| 1922 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 1923 | !!!next-input-character; | !!!next-input-character; |
| 1924 | ||
| 1925 | !!!emit ({type => 'DOCTYPE'}); # incorrect | !!!emit ($self->{current_token}); # DOCTYPE (quirks) |
| 1926 | ||
| 1927 | redo A; | redo A; |
| 1928 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1929 | !!!cp (159); | |
| 1930 | !!!parse-error (type => 'no DOCTYPE name'); | !!!parse-error (type => 'no DOCTYPE name'); |
| 1931 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 1932 | ## reconsume | ## reconsume |
| 1933 | ||
| 1934 | !!!emit ({type => 'DOCTYPE'}); # incorrect | !!!emit ($self->{current_token}); # DOCTYPE (quirks) |
| 1935 | ||
| 1936 | redo A; | redo A; |
| 1937 | } else { | } else { |
| 1938 | $self->{current_token} | !!!cp (160); |
| 1939 | = {type => 'DOCTYPE', | $self->{current_token}->{name} = chr $self->{next_char}; |
| 1940 | name => chr ($self->{next_input_character}), | delete $self->{current_token}->{quirks}; |
| correct => 1}; | ||
| 1941 | ## ISSUE: "Set the token's name name to the" in the spec | ## ISSUE: "Set the token's name name to the" in the spec |
| 1942 | $self->{state} = 'DOCTYPE name'; | $self->{state} = DOCTYPE_NAME_STATE; |
| 1943 | !!!next-input-character; | !!!next-input-character; |
| 1944 | redo A; | redo A; |
| 1945 | } | } |
| 1946 | } elsif ($self->{state} eq 'DOCTYPE name') { | } elsif ($self->{state} == DOCTYPE_NAME_STATE) { |
| 1947 | ## ISSUE: Redundant "First," in the spec. | ## ISSUE: Redundant "First," in the spec. |
| 1948 | if ($self->{next_input_character} == 0x0009 or # HT | if ($self->{next_char} == 0x0009 or # HT |
| 1949 | $self->{next_input_character} == 0x000A or # LF | $self->{next_char} == 0x000A or # LF |
| 1950 | $self->{next_input_character} == 0x000B or # VT | $self->{next_char} == 0x000B or # VT |
| 1951 | $self->{next_input_character} == 0x000C or # FF | $self->{next_char} == 0x000C or # FF |
| 1952 | $self->{next_input_character} == 0x0020) { # SP | $self->{next_char} == 0x0020) { # SP |
| 1953 | $self->{state} = 'after DOCTYPE name'; | !!!cp (161); |
| 1954 | $self->{state} = AFTER_DOCTYPE_NAME_STATE; | |
| 1955 | !!!next-input-character; | !!!next-input-character; |
| 1956 | redo A; | redo A; |
| 1957 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 1958 | $self->{state} = 'data'; | !!!cp (162); |
| 1959 | $self->{state} = DATA_STATE; | |
| 1960 | !!!next-input-character; | !!!next-input-character; |
| 1961 | ||
| 1962 | !!!emit ($self->{current_token}); # DOCTYPE | !!!emit ($self->{current_token}); # DOCTYPE |
| 1963 | ||
| 1964 | redo A; | redo A; |
| 1965 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1966 | !!!cp (163); | |
| 1967 | !!!parse-error (type => 'unclosed DOCTYPE'); | !!!parse-error (type => 'unclosed DOCTYPE'); |
| 1968 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 1969 | ## reconsume | ## reconsume |
| 1970 | ||
| 1971 | delete $self->{current_token}->{correct}; | $self->{current_token}->{quirks} = 1; |
| 1972 | !!!emit ($self->{current_token}); # DOCTYPE | !!!emit ($self->{current_token}); # DOCTYPE |
| 1973 | ||
| 1974 | redo A; | redo A; |
| 1975 | } else { | } else { |
| 1976 | !!!cp (164); | |
| 1977 | $self->{current_token}->{name} | $self->{current_token}->{name} |
| 1978 | .= chr ($self->{next_input_character}); # DOCTYPE | .= chr ($self->{next_char}); # DOCTYPE |
| 1979 | ## Stay in the state | ## Stay in the state |
| 1980 | !!!next-input-character; | !!!next-input-character; |
| 1981 | redo A; | redo A; |
| 1982 | } | } |
| 1983 | } elsif ($self->{state} eq 'after DOCTYPE name') { | } elsif ($self->{state} == AFTER_DOCTYPE_NAME_STATE) { |
| 1984 | if ($self->{next_input_character} == 0x0009 or # HT | if ($self->{next_char} == 0x0009 or # HT |
| 1985 | $self->{next_input_character} == 0x000A or # LF | $self->{next_char} == 0x000A or # LF |
| 1986 | $self->{next_input_character} == 0x000B or # VT | $self->{next_char} == 0x000B or # VT |
| 1987 | $self->{next_input_character} == 0x000C or # FF | $self->{next_char} == 0x000C or # FF |
| 1988 | $self->{next_input_character} == 0x0020) { # SP | $self->{next_char} == 0x0020) { # SP |
| 1989 | !!!cp (165); | |
| 1990 | ## Stay in the state | ## Stay in the state |
| 1991 | !!!next-input-character; | !!!next-input-character; |
| 1992 | redo A; | redo A; |
| 1993 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 1994 | $self->{state} = 'data'; | !!!cp (166); |
| 1995 | $self->{state} = DATA_STATE; | |
| 1996 | !!!next-input-character; | !!!next-input-character; |
| 1997 | ||
| 1998 | !!!emit ($self->{current_token}); # DOCTYPE | !!!emit ($self->{current_token}); # DOCTYPE |
| 1999 | ||
| 2000 | redo A; | redo A; |
| 2001 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 2002 | !!!cp (167); | |
| 2003 | !!!parse-error (type => 'unclosed DOCTYPE'); | !!!parse-error (type => 'unclosed DOCTYPE'); |
| 2004 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 2005 | ## reconsume | ## reconsume |
| 2006 | ||
| 2007 | delete $self->{current_token}->{correct}; | $self->{current_token}->{quirks} = 1; |
| 2008 | !!!emit ($self->{current_token}); # DOCTYPE | !!!emit ($self->{current_token}); # DOCTYPE |
| 2009 | ||
| 2010 | redo A; | redo A; |
| 2011 | } elsif ($self->{next_input_character} == 0x0050 or # P | } elsif ($self->{next_char} == 0x0050 or # P |
| 2012 | $self->{next_input_character} == 0x0070) { # p | $self->{next_char} == 0x0070) { # p |
| 2013 | !!!next-input-character; | !!!next-input-character; |
| 2014 | if ($self->{next_input_character} == 0x0055 or # U | if ($self->{next_char} == 0x0055 or # U |
| 2015 | $self->{next_input_character} == 0x0075) { # u | $self->{next_char} == 0x0075) { # u |
| 2016 | !!!next-input-character; | !!!next-input-character; |
| 2017 | if ($self->{next_input_character} == 0x0042 or # B | if ($self->{next_char} == 0x0042 or # B |
| 2018 | $self->{next_input_character} == 0x0062) { # b | $self->{next_char} == 0x0062) { # b |
| 2019 | !!!next-input-character; | !!!next-input-character; |
| 2020 | if ($self->{next_input_character} == 0x004C or # L | if ($self->{next_char} == 0x004C or # L |
| 2021 | $self->{next_input_character} == 0x006C) { # l | $self->{next_char} == 0x006C) { # l |
| 2022 | !!!next-input-character; | !!!next-input-character; |
| 2023 | if ($self->{next_input_character} == 0x0049 or # I | if ($self->{next_char} == 0x0049 or # I |
| 2024 | $self->{next_input_character} == 0x0069) { # i | $self->{next_char} == 0x0069) { # i |
| 2025 | !!!next-input-character; | !!!next-input-character; |
| 2026 | if ($self->{next_input_character} == 0x0043 or # C | if ($self->{next_char} == 0x0043 or # C |
| 2027 | $self->{next_input_character} == 0x0063) { # c | $self->{next_char} == 0x0063) { # c |
| 2028 | $self->{state} = 'before DOCTYPE public identifier'; | !!!cp (168); |
| 2029 | $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE; | |
| 2030 | !!!next-input-character; | !!!next-input-character; |
| 2031 | redo A; | redo A; |
| 2032 | } else { | |
| 2033 | !!!cp (169); | |
| 2034 | } | } |
| 2035 | } else { | |
| 2036 | !!!cp (170); | |
| 2037 | } | } |
| 2038 | } else { | |
| 2039 | !!!cp (171); | |
| 2040 | } | } |
| 2041 | } else { | |
| 2042 | !!!cp (172); | |
| 2043 | } | } |
| 2044 | } else { | |
| 2045 | !!!cp (173); | |
| 2046 | } | } |
| 2047 | ||
| 2048 | # | # |
| 2049 | } elsif ($self->{next_input_character} == 0x0053 or # S | } elsif ($self->{next_char} == 0x0053 or # S |
| 2050 | $self->{next_input_character} == 0x0073) { # s | $self->{next_char} == 0x0073) { # s |
| 2051 | !!!next-input-character; | !!!next-input-character; |
| 2052 | if ($self->{next_input_character} == 0x0059 or # Y | if ($self->{next_char} == 0x0059 or # Y |
| 2053 | $self->{next_input_character} == 0x0079) { # y | $self->{next_char} == 0x0079) { # y |
| 2054 | !!!next-input-character; | !!!next-input-character; |
| 2055 | if ($self->{next_input_character} == 0x0053 or # S | if ($self->{next_char} == 0x0053 or # S |
| 2056 | $self->{next_input_character} == 0x0073) { # s | $self->{next_char} == 0x0073) { # s |
| 2057 | !!!next-input-character; | !!!next-input-character; |
| 2058 | if ($self->{next_input_character} == 0x0054 or # T | if ($self->{next_char} == 0x0054 or # T |
| 2059 | $self->{next_input_character} == 0x0074) { # t | $self->{next_char} == 0x0074) { # t |
| 2060 | !!!next-input-character; | !!!next-input-character; |
| 2061 | if ($self->{next_input_character} == 0x0045 or # E | if ($self->{next_char} == 0x0045 or # E |
| 2062 | $self->{next_input_character} == 0x0065) { # e | $self->{next_char} == 0x0065) { # e |
| 2063 | !!!next-input-character; | !!!next-input-character; |
| 2064 | if ($self->{next_input_character} == 0x004D or # M | if ($self->{next_char} == 0x004D or # M |
| 2065 | $self->{next_input_character} == 0x006D) { # m | $self->{next_char} == 0x006D) { # m |
| 2066 | $self->{state} = 'before DOCTYPE system identifier'; | !!!cp (174); |
| 2067 | $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE; | |
| 2068 | !!!next-input-character; | !!!next-input-character; |
| 2069 | redo A; | redo A; |
| 2070 | } else { | |
| 2071 | !!!cp (175); | |
| 2072 | } | } |
| 2073 | } else { | |
| 2074 | !!!cp (176); | |
| 2075 | } | } |
| 2076 | } else { | |
| 2077 | !!!cp (177); | |
| 2078 | } | } |
| 2079 | } else { | |
| 2080 | !!!cp (178); | |
| 2081 | } | } |
| 2082 | } else { | |
| 2083 | !!!cp (179); | |
| 2084 | } | } |
| 2085 | ||
| 2086 | # | # |
| 2087 | } else { | } else { |
| 2088 | !!!cp (180); | |
| 2089 | !!!next-input-character; | !!!next-input-character; |
| 2090 | # | # |
| 2091 | } | } |
| 2092 | ||
| 2093 | !!!parse-error (type => 'string after DOCTYPE name'); | !!!parse-error (type => 'string after DOCTYPE name'); |
| 2094 | $self->{state} = 'bogus DOCTYPE'; | $self->{current_token}->{quirks} = 1; |
| 2095 | ||
| 2096 | $self->{state} = BOGUS_DOCTYPE_STATE; | |
| 2097 | # next-input-character is already done | # next-input-character is already done |
| 2098 | redo A; | redo A; |
| 2099 | } elsif ($self->{state} eq 'before DOCTYPE public identifier') { | } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) { |
| 2100 | if ({ | if ({ |
| 2101 | 0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, | 0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, |
| 2102 | #0x000D => 1, # HT, LF, VT, FF, SP, CR | #0x000D => 1, # HT, LF, VT, FF, SP, CR |
| 2103 | }->{$self->{next_input_character}}) { | }->{$self->{next_char}}) { |
| 2104 | !!!cp (181); | |
| 2105 | ## Stay in the state | ## Stay in the state |
| 2106 | !!!next-input-character; | !!!next-input-character; |
| 2107 | redo A; | redo A; |
| 2108 | } elsif ($self->{next_input_character} eq 0x0022) { # " | } elsif ($self->{next_char} eq 0x0022) { # " |
| 2109 | !!!cp (182); | |
| 2110 | $self->{current_token}->{public_identifier} = ''; # DOCTYPE | $self->{current_token}->{public_identifier} = ''; # DOCTYPE |
| 2111 | $self->{state} = 'DOCTYPE public identifier (double-quoted)'; | $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE; |
| 2112 | !!!next-input-character; | !!!next-input-character; |
| 2113 | redo A; | redo A; |
| 2114 | } elsif ($self->{next_input_character} eq 0x0027) { # ' | } elsif ($self->{next_char} eq 0x0027) { # ' |
| 2115 | !!!cp (183); | |
| 2116 | $self->{current_token}->{public_identifier} = ''; # DOCTYPE | $self->{current_token}->{public_identifier} = ''; # DOCTYPE |
| 2117 | $self->{state} = 'DOCTYPE public identifier (single-quoted)'; | $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE; |
| 2118 | !!!next-input-character; | !!!next-input-character; |
| 2119 | redo A; | redo A; |
| 2120 | } elsif ($self->{next_input_character} eq 0x003E) { # > | } elsif ($self->{next_char} eq 0x003E) { # > |
| 2121 | !!!cp (184); | |
| 2122 | !!!parse-error (type => 'no PUBLIC literal'); | !!!parse-error (type => 'no PUBLIC literal'); |
| 2123 | ||
| 2124 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 2125 | !!!next-input-character; | !!!next-input-character; |
| 2126 | ||
| 2127 | delete $self->{current_token}->{correct}; | $self->{current_token}->{quirks} = 1; |
| 2128 | !!!emit ($self->{current_token}); # DOCTYPE | !!!emit ($self->{current_token}); # DOCTYPE |
| 2129 | ||
| 2130 | redo A; | redo A; |
| 2131 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 2132 | !!!cp (185); | |
| 2133 | !!!parse-error (type => 'unclosed DOCTYPE'); | !!!parse-error (type => 'unclosed DOCTYPE'); |
| 2134 | ||
| 2135 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 2136 | ## reconsume | ## reconsume |
| 2137 | ||
| 2138 | delete $self->{current_token}->{correct}; | $self->{current_token}->{quirks} = 1; |
| 2139 | !!!emit ($self->{current_token}); # DOCTYPE | !!!emit ($self->{current_token}); # DOCTYPE |
| 2140 | ||
| 2141 | redo A; | redo A; |
| 2142 | } else { | } else { |
| 2143 | !!!cp (186); | |
| 2144 | !!!parse-error (type => 'string after PUBLIC'); | !!!parse-error (type => 'string after PUBLIC'); |
| 2145 | $self->{state} = 'bogus DOCTYPE'; | $self->{current_token}->{quirks} = 1; |
| 2146 | ||
| 2147 | $self->{state} = BOGUS_DOCTYPE_STATE; | |
| 2148 | !!!next-input-character; | !!!next-input-character; |
| 2149 | redo A; | redo A; |
| 2150 | } | } |
| 2151 | } elsif ($self->{state} eq 'DOCTYPE public identifier (double-quoted)') { | } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE) { |
| 2152 | if ($self->{next_input_character} == 0x0022) { # " | if ($self->{next_char} == 0x0022) { # " |
| 2153 | $self->{state} = 'after DOCTYPE public identifier'; | !!!cp (187); |
| 2154 | $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE; | |
| 2155 | !!!next-input-character; | |
| 2156 | redo A; | |
| 2157 | } elsif ($self->{next_char} == 0x003E) { # > | |
| 2158 | !!!cp (188); | |
| 2159 | !!!parse-error (type => 'unclosed PUBLIC literal'); | |
| 2160 | ||
| 2161 | $self->{state} = DATA_STATE; | |
| 2162 | !!!next-input-character; | !!!next-input-character; |
| 2163 | ||
| 2164 | $self->{current_token}->{quirks} = 1; | |
| 2165 | !!!emit ($self->{current_token}); # DOCTYPE | |
| 2166 | ||
| 2167 | redo A; | redo A; |
| 2168 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 2169 | !!!cp (189); | |
| 2170 | !!!parse-error (type => 'unclosed PUBLIC literal'); | !!!parse-error (type => 'unclosed PUBLIC literal'); |
| 2171 | ||
| 2172 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 2173 | ## reconsume | ## reconsume |
| 2174 | ||
| 2175 | delete $self->{current_token}->{correct}; | $self->{current_token}->{quirks} = 1; |
| 2176 | !!!emit ($self->{current_token}); # DOCTYPE | !!!emit ($self->{current_token}); # DOCTYPE |
| 2177 | ||
| 2178 | redo A; | redo A; |
| 2179 | } else { | } else { |
| 2180 | !!!cp (190); | |
| 2181 | $self->{current_token}->{public_identifier} # DOCTYPE | $self->{current_token}->{public_identifier} # DOCTYPE |
| 2182 | .= chr $self->{next_input_character}; | .= chr $self->{next_char}; |
| 2183 | ## Stay in the state | ## Stay in the state |
| 2184 | !!!next-input-character; | !!!next-input-character; |
| 2185 | redo A; | redo A; |
| 2186 | } | } |
| 2187 | } elsif ($self->{state} eq 'DOCTYPE public identifier (single-quoted)') { | } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE) { |
| 2188 | if ($self->{next_input_character} == 0x0027) { # ' | if ($self->{next_char} == 0x0027) { # ' |
| 2189 | $self->{state} = 'after DOCTYPE public identifier'; | !!!cp (191); |
| 2190 | $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE; | |
| 2191 | !!!next-input-character; | !!!next-input-character; |
| 2192 | redo A; | redo A; |
| 2193 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == 0x003E) { # > |
| 2194 | !!!cp (192); | |
| 2195 | !!!parse-error (type => 'unclosed PUBLIC literal'); | !!!parse-error (type => 'unclosed PUBLIC literal'); |
| 2196 | ||
| 2197 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 2198 | !!!next-input-character; | |
| 2199 | ||
| 2200 | $self->{current_token}->{quirks} = 1; | |
| 2201 | !!!emit ($self->{current_token}); # DOCTYPE | |
| 2202 | ||
| 2203 | redo A; | |
| 2204 | } elsif ($self->{next_char} == -1) { | |
| 2205 | !!!cp (193); | |
| 2206 | !!!parse-error (type => 'unclosed PUBLIC literal'); | |
| 2207 | ||
| 2208 | $self->{state} = DATA_STATE; | |
| 2209 | ## reconsume | ## reconsume |
| 2210 | ||
| 2211 | delete $self->{current_token}->{correct}; | $self->{current_token}->{quirks} = 1; |
| 2212 | !!!emit ($self->{current_token}); # DOCTYPE | !!!emit ($self->{current_token}); # DOCTYPE |
| 2213 | ||
| 2214 | redo A; | redo A; |
| 2215 | } else { | } else { |
| 2216 | !!!cp (194); | |
| 2217 | $self->{current_token}->{public_identifier} # DOCTYPE | $self->{current_token}->{public_identifier} # DOCTYPE |
| 2218 | .= chr $self->{next_input_character}; | .= chr $self->{next_char}; |
| 2219 | ## Stay in the state | ## Stay in the state |
| 2220 | !!!next-input-character; | !!!next-input-character; |
| 2221 | redo A; | redo A; |
| 2222 | } | } |
| 2223 | } elsif ($self->{state} eq 'after DOCTYPE public identifier') { | } elsif ($self->{state} == AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE) { |
| 2224 | if ({ | if ({ |
| 2225 | 0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, | 0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, |
| 2226 | #0x000D => 1, # HT, LF, VT, FF, SP, CR | #0x000D => 1, # HT, LF, VT, FF, SP, CR |
| 2227 | }->{$self->{next_input_character}}) { | }->{$self->{next_char}}) { |
| 2228 | !!!cp (195); | |
| 2229 | ## Stay in the state | ## Stay in the state |
| 2230 | !!!next-input-character; | !!!next-input-character; |
| 2231 | redo A; | redo A; |
| 2232 | } elsif ($self->{next_input_character} == 0x0022) { # " | } elsif ($self->{next_char} == 0x0022) { # " |
| 2233 | !!!cp (196); | |
| 2234 | $self->{current_token}->{system_identifier} = ''; # DOCTYPE | $self->{current_token}->{system_identifier} = ''; # DOCTYPE |
| 2235 | $self->{state} = 'DOCTYPE system identifier (double-quoted)'; | $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE; |
| 2236 | !!!next-input-character; | !!!next-input-character; |
| 2237 | redo A; | redo A; |
| 2238 | } elsif ($self->{next_input_character} == 0x0027) { # ' | } elsif ($self->{next_char} == 0x0027) { # ' |
| 2239 | !!!cp (197); | |
| 2240 | $self->{current_token}->{system_identifier} = ''; # DOCTYPE | $self->{current_token}->{system_identifier} = ''; # DOCTYPE |
| 2241 | $self->{state} = 'DOCTYPE system identifier (single-quoted)'; | $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE; |
| 2242 | !!!next-input-character; | !!!next-input-character; |
| 2243 | redo A; | redo A; |
| 2244 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 2245 | $self->{state} = 'data'; | !!!cp (198); |
| 2246 | $self->{state} = DATA_STATE; | |
| 2247 | !!!next-input-character; | !!!next-input-character; |
| 2248 | ||
| 2249 | !!!emit ($self->{current_token}); # DOCTYPE | !!!emit ($self->{current_token}); # DOCTYPE |
| 2250 | ||
| 2251 | redo A; | redo A; |
| 2252 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 2253 | !!!cp (199); | |
| 2254 | !!!parse-error (type => 'unclosed DOCTYPE'); | !!!parse-error (type => 'unclosed DOCTYPE'); |
| 2255 | ||
| 2256 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 2257 | ## reconsume | ## reconsume |
| 2258 | ||
| 2259 | delete $self->{current_token}->{correct}; | $self->{current_token}->{quirks} = 1; |
| 2260 | !!!emit ($self->{current_token}); # DOCTYPE | !!!emit ($self->{current_token}); # DOCTYPE |
| 2261 | ||
| 2262 | redo A; | redo A; |
| 2263 | } else { | } else { |
| 2264 | !!!cp (200); | |
| 2265 | !!!parse-error (type => 'string after PUBLIC literal'); | !!!parse-error (type => 'string after PUBLIC literal'); |
| 2266 | $self->{state} = 'bogus DOCTYPE'; | $self->{current_token}->{quirks} = 1; |
| 2267 | ||
| 2268 | $self->{state} = BOGUS_DOCTYPE_STATE; | |
| 2269 | !!!next-input-character; | !!!next-input-character; |
| 2270 | redo A; | redo A; |
| 2271 | } | } |
| 2272 | } elsif ($self->{state} eq 'before DOCTYPE system identifier') { | } elsif ($self->{state} == BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE) { |
| 2273 | if ({ | if ({ |
| 2274 | 0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, | 0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, |
| 2275 | #0x000D => 1, # HT, LF, VT, FF, SP, CR | #0x000D => 1, # HT, LF, VT, FF, SP, CR |
| 2276 | }->{$self->{next_input_character}}) { | }->{$self->{next_char}}) { |
| 2277 | !!!cp (201); | |
| 2278 | ## Stay in the state | ## Stay in the state |
| 2279 | !!!next-input-character; | !!!next-input-character; |
| 2280 | redo A; | redo A; |
| 2281 | } elsif ($self->{next_input_character} == 0x0022) { # " | } elsif ($self->{next_char} == 0x0022) { # " |
| 2282 | !!!cp (202); | |
| 2283 | $self->{current_token}->{system_identifier} = ''; # DOCTYPE | $self->{current_token}->{system_identifier} = ''; # DOCTYPE |
| 2284 | $self->{state} = 'DOCTYPE system identifier (double-quoted)'; | $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE; |
| 2285 | !!!next-input-character; | !!!next-input-character; |
| 2286 | redo A; | redo A; |
| 2287 | } elsif ($self->{next_input_character} == 0x0027) { # ' | } elsif ($self->{next_char} == 0x0027) { # ' |
| 2288 | !!!cp (203); | |
| 2289 | $self->{current_token}->{system_identifier} = ''; # DOCTYPE | $self->{current_token}->{system_identifier} = ''; # DOCTYPE |
| 2290 | $self->{state} = 'DOCTYPE system identifier (single-quoted)'; | $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE; |
| 2291 | !!!next-input-character; | !!!next-input-character; |
| 2292 | redo A; | redo A; |
| 2293 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 2294 | !!!cp (204); | |
| 2295 | !!!parse-error (type => 'no SYSTEM literal'); | !!!parse-error (type => 'no SYSTEM literal'); |
| 2296 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 2297 | !!!next-input-character; | !!!next-input-character; |
| 2298 | ||
| 2299 | delete $self->{current_token}->{correct}; | $self->{current_token}->{quirks} = 1; |
| 2300 | !!!emit ($self->{current_token}); # DOCTYPE | !!!emit ($self->{current_token}); # DOCTYPE |
| 2301 | ||
| 2302 | redo A; | redo A; |
| 2303 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 2304 | !!!cp (205); | |
| 2305 | !!!parse-error (type => 'unclosed DOCTYPE'); | !!!parse-error (type => 'unclosed DOCTYPE'); |
| 2306 | ||
| 2307 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 2308 | ## reconsume | ## reconsume |
| 2309 | ||
| 2310 | delete $self->{current_token}->{correct}; | $self->{current_token}->{quirks} = 1; |
| 2311 | !!!emit ($self->{current_token}); # DOCTYPE | !!!emit ($self->{current_token}); # DOCTYPE |
| 2312 | ||
| 2313 | redo A; | redo A; |
| 2314 | } else { | } else { |
| 2315 | !!!cp (206); | |
| 2316 | !!!parse-error (type => 'string after SYSTEM'); | !!!parse-error (type => 'string after SYSTEM'); |
| 2317 | $self->{state} = 'bogus DOCTYPE'; | $self->{current_token}->{quirks} = 1; |
| 2318 | ||
| 2319 | $self->{state} = BOGUS_DOCTYPE_STATE; | |
| 2320 | !!!next-input-character; | !!!next-input-character; |
| 2321 | redo A; | redo A; |
| 2322 | } | } |
| 2323 | } elsif ($self->{state} eq 'DOCTYPE system identifier (double-quoted)') { | } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE) { |
| 2324 | if ($self->{next_input_character} == 0x0022) { # " | if ($self->{next_char} == 0x0022) { # " |
| 2325 | $self->{state} = 'after DOCTYPE system identifier'; | !!!cp (207); |
| 2326 | $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE; | |
| 2327 | !!!next-input-character; | !!!next-input-character; |
| 2328 | redo A; | redo A; |
| 2329 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == 0x003E) { # > |
| 2330 | !!!cp (208); | |
| 2331 | !!!parse-error (type => 'unclosed PUBLIC literal'); | |
| 2332 | ||
| 2333 | $self->{state} = DATA_STATE; | |
| 2334 | !!!next-input-character; | |
| 2335 | ||
| 2336 | $self->{current_token}->{quirks} = 1; | |
| 2337 | !!!emit ($self->{current_token}); # DOCTYPE | |
| 2338 | ||
| 2339 | redo A; | |
| 2340 | } elsif ($self->{next_char} == -1) { | |
| 2341 | !!!cp (209); | |
| 2342 | !!!parse-error (type => 'unclosed SYSTEM literal'); | !!!parse-error (type => 'unclosed SYSTEM literal'); |
| 2343 | ||
| 2344 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 2345 | ## reconsume | ## reconsume |
| 2346 | ||
| 2347 | delete $self->{current_token}->{correct}; | $self->{current_token}->{quirks} = 1; |
| 2348 | !!!emit ($self->{current_token}); # DOCTYPE | !!!emit ($self->{current_token}); # DOCTYPE |
| 2349 | ||
| 2350 | redo A; | redo A; |
| 2351 | } else { | } else { |
| 2352 | !!!cp (210); | |
| 2353 | $self->{current_token}->{system_identifier} # DOCTYPE | $self->{current_token}->{system_identifier} # DOCTYPE |
| 2354 | .= chr $self->{next_input_character}; | .= chr $self->{next_char}; |
| 2355 | ## Stay in the state | ## Stay in the state |
| 2356 | !!!next-input-character; | !!!next-input-character; |
| 2357 | redo A; | redo A; |
| 2358 | } | } |
| 2359 | } elsif ($self->{state} eq 'DOCTYPE system identifier (single-quoted)') { | } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE) { |
| 2360 | if ($self->{next_input_character} == 0x0027) { # ' | if ($self->{next_char} == 0x0027) { # ' |
| 2361 | $self->{state} = 'after DOCTYPE system identifier'; | !!!cp (211); |
| 2362 | $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE; | |
| 2363 | !!!next-input-character; | !!!next-input-character; |
| 2364 | redo A; | redo A; |
| 2365 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == 0x003E) { # > |
| 2366 | !!!cp (212); | |
| 2367 | !!!parse-error (type => 'unclosed PUBLIC literal'); | |
| 2368 | ||
| 2369 | $self->{state} = DATA_STATE; | |
| 2370 | !!!next-input-character; | |
| 2371 | ||
| 2372 | $self->{current_token}->{quirks} = 1; | |
| 2373 | !!!emit ($self->{current_token}); # DOCTYPE | |
| 2374 | ||
| 2375 | redo A; | |
| 2376 | } elsif ($self->{next_char} == -1) { | |
| 2377 | !!!cp (213); | |
| 2378 | !!!parse-error (type => 'unclosed SYSTEM literal'); | !!!parse-error (type => 'unclosed SYSTEM literal'); |
| 2379 | ||
| 2380 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 2381 | ## reconsume | ## reconsume |
| 2382 | ||
| 2383 | delete $self->{current_token}->{correct}; | $self->{current_token}->{quirks} = 1; |
| 2384 | !!!emit ($self->{current_token}); # DOCTYPE | !!!emit ($self->{current_token}); # DOCTYPE |
| 2385 | ||
| 2386 | redo A; | redo A; |
| 2387 | } else { | } else { |
| 2388 | !!!cp (214); | |
| 2389 | $self->{current_token}->{system_identifier} # DOCTYPE | $self->{current_token}->{system_identifier} # DOCTYPE |
| 2390 | .= chr $self->{next_input_character}; | .= chr $self->{next_char}; |
| 2391 | ## Stay in the state | ## Stay in the state |
| 2392 | !!!next-input-character; | !!!next-input-character; |
| 2393 | redo A; | redo A; |
| 2394 | } | } |
| 2395 | } elsif ($self->{state} eq 'after DOCTYPE system identifier') { | } elsif ($self->{state} == AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE) { |
| 2396 | if ({ | if ({ |
| 2397 | 0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, | 0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, |
| 2398 | #0x000D => 1, # HT, LF, VT, FF, SP, CR | #0x000D => 1, # HT, LF, VT, FF, SP, CR |
| 2399 | }->{$self->{next_input_character}}) { | }->{$self->{next_char}}) { |
| 2400 | !!!cp (215); | |
| 2401 | ## Stay in the state | ## Stay in the state |
| 2402 | !!!next-input-character; | !!!next-input-character; |
| 2403 | redo A; | redo A; |
| 2404 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 2405 | $self->{state} = 'data'; | !!!cp (216); |
| 2406 | $self->{state} = DATA_STATE; | |
| 2407 | !!!next-input-character; | !!!next-input-character; |
| 2408 | ||
| 2409 | !!!emit ($self->{current_token}); # DOCTYPE | !!!emit ($self->{current_token}); # DOCTYPE |
| 2410 | ||
| 2411 | redo A; | redo A; |
| 2412 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 2413 | !!!cp (217); | |
| 2414 | !!!parse-error (type => 'unclosed DOCTYPE'); | !!!parse-error (type => 'unclosed DOCTYPE'); |
| 2415 | ||
| 2416 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 2417 | ## reconsume | ## reconsume |
| 2418 | ||
| 2419 | delete $self->{current_token}->{correct}; | $self->{current_token}->{quirks} = 1; |
| 2420 | !!!emit ($self->{current_token}); # DOCTYPE | !!!emit ($self->{current_token}); # DOCTYPE |
| 2421 | ||
| 2422 | redo A; | redo A; |
| 2423 | } else { | } else { |
| 2424 | !!!cp (218); | |
| 2425 | !!!parse-error (type => 'string after SYSTEM literal'); | !!!parse-error (type => 'string after SYSTEM literal'); |
| 2426 | $self->{state} = 'bogus DOCTYPE'; | #$self->{current_token}->{quirks} = 1; |
| 2427 | ||
| 2428 | $self->{state} = BOGUS_DOCTYPE_STATE; | |
| 2429 | !!!next-input-character; | !!!next-input-character; |
| 2430 | redo A; | redo A; |
| 2431 | } | } |
| 2432 | } elsif ($self->{state} eq 'bogus DOCTYPE') { | } elsif ($self->{state} == BOGUS_DOCTYPE_STATE) { |
| 2433 | if ($self->{next_input_character} == 0x003E) { # > | if ($self->{next_char} == 0x003E) { # > |
| 2434 | $self->{state} = 'data'; | !!!cp (219); |
| 2435 | $self->{state} = DATA_STATE; | |
| 2436 | !!!next-input-character; | !!!next-input-character; |
| 2437 | ||
| delete $self->{current_token}->{correct}; | ||
| 2438 | !!!emit ($self->{current_token}); # DOCTYPE | !!!emit ($self->{current_token}); # DOCTYPE |
| 2439 | ||
| 2440 | redo A; | redo A; |
| 2441 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 2442 | !!!cp (220); | |
| 2443 | !!!parse-error (type => 'unclosed DOCTYPE'); | !!!parse-error (type => 'unclosed DOCTYPE'); |
| 2444 | $self->{state} = 'data'; | $self->{state} = DATA_STATE; |
| 2445 | ## reconsume | ## reconsume |
| 2446 | ||
| delete $self->{current_token}->{correct}; | ||
| 2447 | !!!emit ($self->{current_token}); # DOCTYPE | !!!emit ($self->{current_token}); # DOCTYPE |
| 2448 | ||
| 2449 | redo A; | redo A; |
| 2450 | } else { | } else { |
| 2451 | !!!cp (221); | |
| 2452 | ## Stay in the state | ## Stay in the state |
| 2453 | !!!next-input-character; | !!!next-input-character; |
| 2454 | redo A; | redo A; |
| 2455 | } | } |
| 2456 | } elsif ($self->{state} == CDATA_BLOCK_STATE) { | |
| 2457 | my $s = ''; | |
| 2458 | ||
| 2459 | my ($l, $c) = ($self->{line}, $self->{column}); | |
| 2460 | ||
| 2461 | CS: while ($self->{next_char} != -1) { | |
| 2462 | if ($self->{next_char} == 0x005D) { # ] | |
| 2463 | !!!next-input-character; | |
| 2464 | if ($self->{next_char} == 0x005D) { # ] | |
| 2465 | !!!next-input-character; | |
| 2466 | MDC: { | |
| 2467 | if ($self->{next_char} == 0x003E) { # > | |
| 2468 | !!!cp (221.1); | |
| 2469 | !!!next-input-character; | |
| 2470 | last CS; | |
| 2471 | } elsif ($self->{next_char} == 0x005D) { # ] | |
| 2472 | !!!cp (221.2); | |
| 2473 | $s .= ']'; | |
| 2474 | !!!next-input-character; | |
| 2475 | redo MDC; | |
| 2476 | } else { | |
| 2477 | !!!cp (221.3); | |
| 2478 | $s .= ']]'; | |
| 2479 | # | |
| 2480 | } | |
| 2481 | } # MDC | |
| 2482 | } else { | |
| 2483 | !!!cp (221.4); | |
| 2484 | $s .= ']'; | |
| 2485 | # | |
| 2486 | } | |
| 2487 | } else { | |
| 2488 | !!!cp (221.5); | |
| 2489 | # | |
| 2490 | } | |
| 2491 | $s .= chr $self->{next_char}; | |
| 2492 | !!!next-input-character; | |
| 2493 | } # CS | |
| 2494 | ||
| 2495 | $self->{state} = DATA_STATE; | |
| 2496 | ## next-input-character done or EOF, which is reconsumed. | |
| 2497 | ||
| 2498 | if (length $s) { | |
| 2499 | !!!cp (221.6); | |
| 2500 | !!!emit ({type => CHARACTER_TOKEN, data => $s, | |
| 2501 | line => $l, column => $c}); | |
| 2502 | } else { | |
| 2503 | !!!cp (221.7); | |
| 2504 | } | |
| 2505 | ||
| 2506 | redo A; | |
| 2507 | ||
| 2508 | ## ISSUE: "text tokens" in spec. | |
| 2509 | ## TODO: Streaming support | |
| 2510 | } else { | } else { |
| 2511 | die "$0: $self->{state}: Unknown state"; | die "$0: $self->{state}: Unknown state"; |
| 2512 | } | } |
| # | Line 1606 sub _get_next_token ($) { | Line 2515 sub _get_next_token ($) { |
| 2515 | die "$0: _get_next_token: unexpected case"; | die "$0: _get_next_token: unexpected case"; |
| 2516 | } # _get_next_token | } # _get_next_token |
| 2517 | ||
| 2518 | sub _tokenize_attempt_to_consume_an_entity ($$) { | sub _tokenize_attempt_to_consume_an_entity ($$$) { |
| 2519 | my ($self, $in_attr) = @_; | my ($self, $in_attr, $additional) = @_; |
| 2520 | ||
| 2521 | my ($l, $c) = ($self->{line_prev}, $self->{column_prev}); | |
| 2522 | ||
| 2523 | if ({ | if ({ |
| 2524 | 0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF, | 0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF, |
| 2525 | 0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR | 0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR |
| 2526 | }->{$self->{next_input_character}}) { | $additional => 1, |
| 2527 | }->{$self->{next_char}}) { | |
| 2528 | !!!cp (1001); | |
| 2529 | ## Don't consume | ## Don't consume |
| 2530 | ## No error | ## No error |
| 2531 | return undef; | return undef; |
| 2532 | } elsif ($self->{next_input_character} == 0x0023) { # # | } elsif ($self->{next_char} == 0x0023) { # # |
| 2533 | !!!next-input-character; | !!!next-input-character; |
| 2534 | if ($self->{next_input_character} == 0x0078 or # x | if ($self->{next_char} == 0x0078 or # x |
| 2535 | $self->{next_input_character} == 0x0058) { # X | $self->{next_char} == 0x0058) { # X |
| 2536 | my $code; | my $code; |
| 2537 | X: { | X: { |
| 2538 | my $x_char = $self->{next_input_character}; | my $x_char = $self->{next_char}; |
| 2539 | !!!next-input-character; | !!!next-input-character; |
| 2540 | if (0x0030 <= $self->{next_input_character} and | if (0x0030 <= $self->{next_char} and |
| 2541 | $self->{next_input_character} <= 0x0039) { # 0..9 | $self->{next_char} <= 0x0039) { # 0..9 |
| 2542 | !!!cp (1002); | |
| 2543 | $code ||= 0; | $code ||= 0; |
| 2544 | $code *= 0x10; | $code *= 0x10; |
| 2545 | $code += $self->{next_input_character} - 0x0030; | $code += $self->{next_char} - 0x0030; |
| 2546 | redo X; | redo X; |
| 2547 | } elsif (0x0061 <= $self->{next_input_character} and | } elsif (0x0061 <= $self->{next_char} and |
| 2548 | $self->{next_input_character} <= 0x0066) { # a..f | $self->{next_char} <= 0x0066) { # a..f |
| 2549 | !!!cp (1003); | |
| 2550 | $code ||= 0; | $code ||= 0; |
| 2551 | $code *= 0x10; | $code *= 0x10; |
| 2552 | $code += $self->{next_input_character} - 0x0060 + 9; | $code += $self->{next_char} - 0x0060 + 9; |
| 2553 | redo X; | redo X; |
| 2554 | } elsif (0x0041 <= $self->{next_input_character} and | } elsif (0x0041 <= $self->{next_char} and |
| 2555 | $self->{next_input_character} <= 0x0046) { # A..F | $self->{next_char} <= 0x0046) { # A..F |
| 2556 | !!!cp (1004); | |
| 2557 | $code ||= 0; | $code ||= 0; |
| 2558 | $code *= 0x10; | $code *= 0x10; |
| 2559 | $code += $self->{next_input_character} - 0x0040 + 9; | $code += $self->{next_char} - 0x0040 + 9; |
| 2560 | redo X; | redo X; |
| 2561 | } elsif (not defined $code) { # no hexadecimal digit | } elsif (not defined $code) { # no hexadecimal digit |
| 2562 | !!!parse-error (type => 'bare hcro'); | !!!cp (1005); |
| 2563 | $self->{next_input_character} = 0x0023; # # | !!!parse-error (type => 'bare hcro', line => $l, column => $c); |
| 2564 | !!!back-next-input-character ($x_char); | !!!back-next-input-character ($x_char, $self->{next_char}); |
| 2565 | $self->{next_char} = 0x0023; # # | |
| 2566 | return undef; | return undef; |
| 2567 | } elsif ($self->{next_input_character} == 0x003B) { # ; | } elsif ($self->{next_char} == 0x003B) { # ; |
| 2568 | !!!cp (1006); | |
| 2569 | !!!next-input-character; | !!!next-input-character; |
| 2570 | } else { | } else { |
| 2571 | !!!parse-error (type => 'no refc'); | !!!cp (1007); |
| 2572 | !!!parse-error (type => 'no refc', line => $l, column => $c); | |
| 2573 | } | } |
| 2574 | ||
| 2575 | if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) { | if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) { |
| 2576 | !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code); | !!!cp (1008); |
| 2577 | !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c); | |
| 2578 | $code = 0xFFFD; | $code = 0xFFFD; |
| 2579 | } elsif ($code > 0x10FFFF) { | } elsif ($code > 0x10FFFF) { |
| 2580 | !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code); | !!!cp (1009); |
| 2581 | !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c); | |
| 2582 | $code = 0xFFFD; | $code = 0xFFFD; |
| 2583 | } elsif ($code == 0x000D) { | } elsif ($code == 0x000D) { |
| 2584 | !!!parse-error (type => 'CR character reference'); | !!!cp (1010); |
| 2585 | !!!parse-error (type => 'CR character reference', line => $l, column => $c); | |
| 2586 | $code = 0x000A; | $code = 0x000A; |
| 2587 | } elsif (0x80 <= $code and $code <= 0x9F) { | } elsif (0x80 <= $code and $code <= 0x9F) { |
| 2588 | !!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code); | !!!cp (1011); |
| 2589 | !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c); | |
| 2590 | $code = $c1_entity_char->{$code}; | $code = $c1_entity_char->{$code}; |
| 2591 | } | } |
| 2592 | ||
| 2593 | return {type => 'character', data => chr $code}; | return {type => CHARACTER_TOKEN, data => chr $code, |
| 2594 | has_reference => 1, | |
| 2595 | line => $l, column => $c, | |
| 2596 | }; | |
| 2597 | } # X | } # X |
| 2598 | } elsif (0x0030 <= $self->{next_input_character} and | } elsif (0x0030 <= $self->{next_char} and |
| 2599 | $self->{next_input_character} <= 0x0039) { # 0..9 | $self->{next_char} <= 0x0039) { # 0..9 |
| 2600 | my $code = $self->{next_input_character} - 0x0030; | my $code = $self->{next_char} - 0x0030; |
| 2601 | !!!next-input-character; | !!!next-input-character; |
| 2602 | ||
| 2603 | while (0x0030 <= $self->{next_input_character} and | while (0x0030 <= $self->{next_char} and |
| 2604 | $self->{next_input_character} <= 0x0039) { # 0..9 | $self->{next_char} <= 0x0039) { # 0..9 |
| 2605 | !!!cp (1012); | |
| 2606 | $code *= 10; | $code *= 10; |
| 2607 | $code += $self->{next_input_character} - 0x0030; | $code += $self->{next_char} - 0x0030; |
| 2608 | ||
| 2609 | !!!next-input-character; | !!!next-input-character; |
| 2610 | } | } |
| 2611 | ||
| 2612 | if ($self->{next_input_character} == 0x003B) { # ; | if ($self->{next_char} == 0x003B) { # ; |
| 2613 | !!!cp (1013); | |
| 2614 | !!!next-input-character; | !!!next-input-character; |
| 2615 | } else { | } else { |
| 2616 | !!!parse-error (type => 'no refc'); | !!!cp (1014); |
| 2617 | !!!parse-error (type => 'no refc', line => $l, column => $c); | |
| 2618 | } | } |
| 2619 | ||
| 2620 | if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) { | if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) { |
| 2621 | !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code); | !!!cp (1015); |
| 2622 | !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c); | |
| 2623 | $code = 0xFFFD; | $code = 0xFFFD; |
| 2624 | } elsif ($code > 0x10FFFF) { | } elsif ($code > 0x10FFFF) { |
| 2625 | !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code); | !!!cp (1016); |
| 2626 | !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c); | |
| 2627 | $code = 0xFFFD; | $code = 0xFFFD; |
| 2628 | } elsif ($code == 0x000D) { | } elsif ($code == 0x000D) { |
| 2629 | !!!parse-error (type => 'CR character reference'); | !!!cp (1017); |
| 2630 | !!!parse-error (type => 'CR character reference', line => $l, column => $c); | |
| 2631 | $code = 0x000A; | $code = 0x000A; |
| 2632 | } elsif (0x80 <= $code and $code <= 0x9F) { | } elsif (0x80 <= $code and $code <= 0x9F) { |
| 2633 | !!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code); | !!!cp (1018); |
| 2634 | !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c); | |
| 2635 | $code = $c1_entity_char->{$code}; | $code = $c1_entity_char->{$code}; |
| 2636 | } | } |
| 2637 | ||
| 2638 | return {type => 'character', data => chr $code}; | return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1, |
| 2639 | line => $l, column => $c, | |
| 2640 | }; | |
| 2641 | } else { | } else { |
| 2642 | !!!parse-error (type => 'bare nero'); | !!!cp (1019); |
| 2643 | !!!back-next-input-character ($self->{next_input_character}); | !!!parse-error (type => 'bare nero', line => $l, column => $c); |
| 2644 | $self->{next_input_character} = 0x0023; # # | !!!back-next-input-character ($self->{next_char}); |
| 2645 | $self->{next_char} = 0x0023; # # | |
| 2646 | return undef; | return undef; |
| 2647 | } | } |
| 2648 | } elsif ((0x0041 <= $self->{next_input_character} and | } elsif ((0x0041 <= $self->{next_char} and |
| 2649 | $self->{next_input_character} <= 0x005A) or | $self->{next_char} <= 0x005A) or |
| 2650 | (0x0061 <= $self->{next_input_character} and | (0x0061 <= $self->{next_char} and |
| 2651 | $self->{next_input_character} <= 0x007A)) { | $self->{next_char} <= 0x007A)) { |
| 2652 | my $entity_name = chr $self->{next_input_character}; | my $entity_name = chr $self->{next_char}; |
| 2653 | !!!next-input-character; | !!!next-input-character; |
| 2654 | ||
| 2655 | my $value = $entity_name; | my $value = $entity_name; |
| 2656 | my $match; | my $match = 0; |
| 2657 | require Whatpm::_NamedEntityList; | require Whatpm::_NamedEntityList; |
| 2658 | our $EntityChar; | our $EntityChar; |
| 2659 | ||
| 2660 | while (length $entity_name < 10 and | while (length $entity_name < 30 and |
| 2661 | ## NOTE: Some number greater than the maximum length of entity name | ## NOTE: Some number greater than the maximum length of entity name |
| 2662 | ((0x0041 <= $self->{next_input_character} and # a | ((0x0041 <= $self->{next_char} and # a |
| 2663 | $self->{next_input_character} <= 0x005A) or # x | $self->{next_char} <= 0x005A) or # x |
| 2664 | (0x0061 <= $self->{next_input_character} and # a | (0x0061 <= $self->{next_char} and # a |
| 2665 | $self->{next_input_character} <= 0x007A) or # z | $self->{next_char} <= 0x007A) or # z |
| 2666 | (0x0030 <= $self->{next_input_character} and # 0 | (0x0030 <= $self->{next_char} and # 0 |
| 2667 | $self->{next_input_character} <= 0x0039) or # 9 | $self->{next_char} <= 0x0039) or # 9 |
| 2668 | $self->{next_input_character} == 0x003B)) { # ; | $self->{next_char} == 0x003B)) { # ; |
| 2669 | $entity_name .= chr $self->{next_input_character}; | $entity_name .= chr $self->{next_char}; |
| 2670 | if (defined $EntityChar->{$entity_name}) { | if (defined $EntityChar->{$entity_name}) { |
| 2671 | if ($self->{next_input_character} == 0x003B) { # ; | if ($self->{next_char} == 0x003B) { # ; |
| 2672 | !!!cp (1020); | |
| 2673 | $value = $EntityChar->{$entity_name}; | $value = $EntityChar->{$entity_name}; |
| 2674 | $match = 1; | $match = 1; |
| 2675 | !!!next-input-character; | !!!next-input-character; |
| 2676 | last; | last; |
| 2677 | } elsif (not $in_attr) { | } else { |
| 2678 | !!!cp (1021); | |
| 2679 | $value = $EntityChar->{$entity_name}; | $value = $EntityChar->{$entity_name}; |
| 2680 | $match = -1; | $match = -1; |
| 2681 | } else { | !!!next-input-character; |
| $value .= chr $self->{next_input_character}; | ||
| 2682 | } | } |
| 2683 | } else { | } else { |
| 2684 | $value .= chr $self->{next_input_character}; | !!!cp (1022); |
| 2685 | $value .= chr $self->{next_char}; | |
| 2686 | $match *= 2; | |
| 2687 | !!!next-input-character; | |
| 2688 | } | } |
| !!!next-input-character; | ||
| 2689 | } | } |
| 2690 | ||
| 2691 | if ($match > 0) { | if ($match > 0) { |
| 2692 | return {type => 'character', data => $value}; | !!!cp (1023); |
| 2693 | return {type => CHARACTER_TOKEN, data => $value, has_reference => 1, | |
| 2694 | line => $l, column => $c, | |
| 2695 | }; | |
| 2696 | } elsif ($match < 0) { | } elsif ($match < 0) { |
| 2697 | !!!parse-error (type => 'no refc'); | !!!parse-error (type => 'no refc', line => $l, column => $c); |
| 2698 | return {type => 'character', data => $value}; | if ($in_attr and $match < -1) { |
| 2699 | !!!cp (1024); | |
| 2700 | return {type => CHARACTER_TOKEN, data => '&'.$entity_name, | |
| 2701 | line => $l, column => $c, | |
| 2702 | }; | |
| 2703 | } else { | |
| 2704 | !!!cp (1025); | |
| 2705 | return {type => CHARACTER_TOKEN, data => $value, has_reference => 1, | |
| 2706 | line => $l, column => $c, | |
| 2707 | }; | |
| 2708 | } | |
| 2709 | } else { | } else { |
| 2710 | !!!parse-error (type => 'bare ero'); | !!!cp (1026); |
| 2711 | ## NOTE: No characters are consumed in the spec. | !!!parse-error (type => 'bare ero', line => $l, column => $c); |
| 2712 | return {type => 'character', data => '&'.$value}; | ## NOTE: "No characters are consumed" in the spec. |
| 2713 | return {type => CHARACTER_TOKEN, data => '&'.$value, | |
| 2714 | line => $l, column => $c, | |
| 2715 | }; | |
| 2716 | } | } |
| 2717 | } else { | } else { |
| 2718 | !!!cp (1027); | |
| 2719 | ## no characters are consumed | ## no characters are consumed |
| 2720 | !!!parse-error (type => 'bare ero'); | !!!parse-error (type => 'bare ero', line => $l, column => $c); |
| 2721 | return undef; | return undef; |
| 2722 | } | } |
| 2723 | } # _tokenize_attempt_to_consume_an_entity | } # _tokenize_attempt_to_consume_an_entity |
| # | Line 1799 sub _construct_tree ($) { | Line 2755 sub _construct_tree ($) { |
| 2755 | ||
| 2756 | !!!next-token; | !!!next-token; |
| 2757 | ||
| $self->{insertion_mode} = 'before head'; | ||
| 2758 | undef $self->{form_element}; | undef $self->{form_element}; |
| 2759 | undef $self->{head_element}; | undef $self->{head_element}; |
| 2760 | $self->{open_elements} = []; | $self->{open_elements} = []; |
| 2761 | undef $self->{inner_html_node}; | undef $self->{inner_html_node}; |
| 2762 | ||
| 2763 | ## NOTE: The "initial" insertion mode. | |
| 2764 | $self->_tree_construction_initial; # MUST | $self->_tree_construction_initial; # MUST |
| 2765 | ||
| 2766 | ## NOTE: The "before html" insertion mode. | |
| 2767 | $self->_tree_construction_root_element; | $self->_tree_construction_root_element; |
| 2768 | $self->{insertion_mode} = BEFORE_HEAD_IM; | |
| 2769 | ||
| 2770 | ## NOTE: The "before head" insertion mode and so on. | |
| 2771 | $self->_tree_construction_main; | $self->_tree_construction_main; |
| 2772 | } # _construct_tree | } # _construct_tree |
| 2773 | ||
| 2774 | sub _tree_construction_initial ($) { | sub _tree_construction_initial ($) { |
| 2775 | my $self = shift; | my $self = shift; |
| 2776 | ||
| 2777 | ## NOTE: "initial" insertion mode | |
| 2778 | ||
| 2779 | INITIAL: { | INITIAL: { |
| 2780 | if ($token->{type} eq 'DOCTYPE') { | if ($token->{type} == DOCTYPE_TOKEN) { |
| 2781 | ## NOTE: Conformance checkers MAY, instead of reporting "not HTML5" | ## NOTE: Conformance checkers MAY, instead of reporting "not HTML5" |
| 2782 | ## error, switch to a conformance checking mode for another | ## error, switch to a conformance checking mode for another |
| 2783 | ## language. | ## language. |
| # | Line 1823 sub _tree_construction_initial ($) { | Line 2787 sub _tree_construction_initial ($) { |
| 2787 | if (not defined $token->{name} or # <!DOCTYPE> | if (not defined $token->{name} or # <!DOCTYPE> |
| 2788 | defined $token->{public_identifier} or | defined $token->{public_identifier} or |
| 2789 | defined $token->{system_identifier}) { | defined $token->{system_identifier}) { |
| 2790 | !!!parse-error (type => 'not HTML5'); | !!!cp ('t1'); |
| 2791 | !!!parse-error (type => 'not HTML5', token => $token); | |
| 2792 | } elsif ($doctype_name ne 'HTML') { | } elsif ($doctype_name ne 'HTML') { |
| 2793 | !!!cp ('t2'); | |
| 2794 | ## ISSUE: ASCII case-insensitive? (in fact it does not matter) | ## ISSUE: ASCII case-insensitive? (in fact it does not matter) |
| 2795 | !!!parse-error (type => 'not HTML5'); | !!!parse-error (type => 'not HTML5', token => $token); |
| 2796 | } else { | |
| 2797 | !!!cp ('t3'); | |
| 2798 | } | } |
| 2799 | ||
| 2800 | my $doctype = $self->{document}->create_document_type_definition | my $doctype = $self->{document}->create_document_type_definition |
| 2801 | ($token->{name}); ## ISSUE: If name is missing (e.g. <!DOCTYPE>)? | ($token->{name}); ## ISSUE: If name is missing (e.g. <!DOCTYPE>)? |
| 2802 | ## NOTE: Default value for both |public_id| and |system_id| attributes | |
| 2803 | ## are empty strings, so that we don't set any value in missing cases. | |
| 2804 | $doctype->public_id ($token->{public_identifier}) | $doctype->public_id ($token->{public_identifier}) |
| 2805 | if defined $token->{public_identifier}; | if defined $token->{public_identifier}; |
| 2806 | $doctype->system_id ($token->{system_identifier}) | $doctype->system_id ($token->{system_identifier}) |
| # | Line 1839 sub _tree_construction_initial ($) { | Line 2809 sub _tree_construction_initial ($) { |
| 2809 | ## ISSUE: internalSubset = null?? | ## ISSUE: internalSubset = null?? |
| 2810 | $self->{document}->append_child ($doctype); | $self->{document}->append_child ($doctype); |
| 2811 | ||
| 2812 | if (not $token->{correct} or $doctype_name ne 'HTML') { | if ($token->{quirks} or $doctype_name ne 'HTML') { |
| 2813 | !!!cp ('t4'); | |
| 2814 | $self->{document}->manakai_compat_mode ('quirks'); | $self->{document}->manakai_compat_mode ('quirks'); |
| 2815 | } elsif (defined $token->{public_identifier}) { | } elsif (defined $token->{public_identifier}) { |
| 2816 | my $pubid = $token->{public_identifier}; | my $pubid = $token->{public_identifier}; |
| # | Line 1893 sub _tree_construction_initial ($) { | Line 2864 sub _tree_construction_initial ($) { |
| 2864 | "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//EN" => 1, | "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//EN" => 1, |
| 2865 | "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//EN" => 1, | "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//EN" => 1, |
| 2866 | "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//EN" => 1, | "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//EN" => 1, |
| 2867 | "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//EN" => 1, | |
| 2868 | "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//EN" => 1, | |
| 2869 | "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//EN" => 1, | |
| 2870 | "-//SPYGLASS//DTD HTML 2.0 EXTENDED//EN" => 1, | "-//SPYGLASS//DTD HTML 2.0 EXTENDED//EN" => 1, |
| 2871 | "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//EN" => 1, | "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//EN" => 1, |
| 2872 | "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//EN" => 1, | "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//EN" => 1, |
| # | Line 1915 sub _tree_construction_initial ($) { | Line 2889 sub _tree_construction_initial ($) { |
| 2889 | "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" => 1, | "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" => 1, |
| 2890 | "HTML" => 1, | "HTML" => 1, |
| 2891 | }->{$pubid}) { | }->{$pubid}) { |
| 2892 | !!!cp ('t5'); | |
| 2893 | $self->{document}->manakai_compat_mode ('quirks'); | $self->{document}->manakai_compat_mode ('quirks'); |
| 2894 | } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or | } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or |
| 2895 | $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") { | $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") { |
| 2896 | if (defined $token->{system_identifier}) { | if (defined $token->{system_identifier}) { |
| 2897 | !!!cp ('t6'); | |
| 2898 | $self->{document}->manakai_compat_mode ('quirks'); | $self->{document}->manakai_compat_mode ('quirks'); |
| 2899 | } else { | } else { |
| 2900 | !!!cp ('t7'); | |
| 2901 | $self->{document}->manakai_compat_mode ('limited quirks'); | $self->{document}->manakai_compat_mode ('limited quirks'); |
| 2902 | } | } |
| 2903 | } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 Frameset//EN" or | } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 FRAMESET//EN" or |
| 2904 | $pubid eq "-//W3C//DTD XHTML 1.0 Transitional//EN") { | $pubid eq "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN") { |
| 2905 | !!!cp ('t8'); | |
| 2906 | $self->{document}->manakai_compat_mode ('limited quirks'); | $self->{document}->manakai_compat_mode ('limited quirks'); |
| 2907 | } else { | |
| 2908 | !!!cp ('t9'); | |
| 2909 | } | } |
| 2910 | } else { | |
| 2911 | !!!cp ('t10'); | |
| 2912 | } | } |
| 2913 | if (defined $token->{system_identifier}) { | if (defined $token->{system_identifier}) { |
| 2914 | my $sysid = $token->{system_identifier}; | my $sysid = $token->{system_identifier}; |
| 2915 | $sysid =~ tr/A-Z/a-z/; | $sysid =~ tr/A-Z/a-z/; |
| 2916 | if ($sysid eq "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") { | if ($sysid eq "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") { |
| 2917 | ## TODO: Check the spec: PUBLIC "(limited quirks)" "(quirks)" | |
| 2918 | $self->{document}->manakai_compat_mode ('quirks'); | $self->{document}->manakai_compat_mode ('quirks'); |
| 2919 | !!!cp ('t11'); | |
| 2920 | } else { | |
| 2921 | !!!cp ('t12'); | |
| 2922 | } | } |
| 2923 | } else { | |
| 2924 | !!!cp ('t13'); | |
| 2925 | } | } |
| 2926 | ||
| 2927 | ## Go to the root element phase. | ## Go to the "before html" insertion mode. |
| 2928 | !!!next-token; | !!!next-token; |
| 2929 | return; | return; |
| 2930 | } elsif ({ | } elsif ({ |
| 2931 | 'start tag' => 1, | START_TAG_TOKEN, 1, |
| 2932 | 'end tag' => 1, | END_TAG_TOKEN, 1, |
| 2933 | 'end-of-file' => 1, | END_OF_FILE_TOKEN, 1, |
| 2934 | }->{$token->{type}}) { | }->{$token->{type}}) { |
| 2935 | !!!parse-error (type => 'no DOCTYPE'); | !!!cp ('t14'); |
| 2936 | !!!parse-error (type => 'no DOCTYPE', token => $token); | |
| 2937 | $self->{document}->manakai_compat_mode ('quirks'); | $self->{document}->manakai_compat_mode ('quirks'); |
| 2938 | ## Go to the root element phase | ## Go to the "before html" insertion mode. |
| 2939 | ## reprocess | ## reprocess |
| 2940 | !!!ack-later; | |
| 2941 | return; | return; |
| 2942 | } elsif ($token->{type} eq 'character') { | } elsif ($token->{type} == CHARACTER_TOKEN) { |
| 2943 | if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D | if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D |
| 2944 | ## Ignore the token | ## Ignore the token |
| 2945 | ||
| 2946 | unless (length $token->{data}) { | unless (length $token->{data}) { |
| 2947 | ## Stay in the phase | !!!cp ('t15'); |
| 2948 | ## Stay in the insertion mode. | |
| 2949 | !!!next-token; | !!!next-token; |
| 2950 | redo INITIAL; | redo INITIAL; |
| 2951 | } else { | |
| 2952 | !!!cp ('t16'); | |
| 2953 | } | } |
| 2954 | } else { | |
| 2955 | !!!cp ('t17'); | |
| 2956 | } | } |
| 2957 | ||
| 2958 | !!!parse-error (type => 'no DOCTYPE'); | !!!parse-error (type => 'no DOCTYPE', token => $token); |
| 2959 | $self->{document}->manakai_compat_mode ('quirks'); | $self->{document}->manakai_compat_mode ('quirks'); |
| 2960 | ## Go to the root element phase | ## Go to the "before html" insertion mode. |
| 2961 | ## reprocess | ## reprocess |
| 2962 | return; | return; |
| 2963 | } elsif ($token->{type} eq 'comment') { | } elsif ($token->{type} == COMMENT_TOKEN) { |
| 2964 | !!!cp ('t18'); | |
| 2965 | my $comment = $self->{document}->create_comment ($token->{data}); | my $comment = $self->{document}->create_comment ($token->{data}); |
| 2966 | $self->{document}->append_child ($comment); | $self->{document}->append_child ($comment); |
| 2967 | ||
| 2968 | ## Stay in the phase. | ## Stay in the insertion mode. |
| 2969 | !!!next-token; | !!!next-token; |
| 2970 | redo INITIAL; | redo INITIAL; |
| 2971 | } else { | } else { |
| 2972 | die "$0: $token->{type}: Unknown token"; | die "$0: $token->{type}: Unknown token type"; |
| 2973 | } | } |
| 2974 | } # INITIAL | } # INITIAL |
| 2975 | ||
| 2976 | die "$0: _tree_construction_initial: This should be never reached"; | |
| 2977 | } # _tree_construction_initial | } # _tree_construction_initial |
| 2978 | ||
| 2979 | sub _tree_construction_root_element ($) { | sub _tree_construction_root_element ($) { |
| 2980 | my $self = shift; | my $self = shift; |
| 2981 | ||
| 2982 | ## NOTE: "before html" insertion mode. | |
| 2983 | ||
| 2984 | B: { | B: { |
| 2985 | if ($token->{type} eq 'DOCTYPE') { | if ($token->{type} == DOCTYPE_TOKEN) { |
| 2986 | !!!parse-error (type => 'in html:#DOCTYPE'); | !!!cp ('t19'); |
| 2987 | !!!parse-error (type => 'in html:#DOCTYPE', token => $token); | |
| 2988 | ## Ignore the token | ## Ignore the token |
| 2989 | ## Stay in the phase | ## Stay in the insertion mode. |
| 2990 | !!!next-token; | !!!next-token; |
| 2991 | redo B; | redo B; |
| 2992 | } elsif ($token->{type} eq 'comment') { | } elsif ($token->{type} == COMMENT_TOKEN) { |
| 2993 | !!!cp ('t20'); | |
| 2994 | my $comment = $self->{document}->create_comment ($token->{data}); | my $comment = $self->{document}->create_comment ($token->{data}); |
| 2995 | $self->{document}->append_child ($comment); | $self->{document}->append_child ($comment); |
| 2996 | ## Stay in the phase | ## Stay in the insertion mode. |
| 2997 | !!!next-token; | !!!next-token; |
| 2998 | redo B; | redo B; |
| 2999 | } elsif ($token->{type} eq 'character') { | } elsif ($token->{type} == CHARACTER_TOKEN) { |
| 3000 | if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D | if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D |
| 3001 | ## Ignore the token. | ## Ignore the token. |
| 3002 | ||
| 3003 | unless (length $token->{data}) { | unless (length $token->{data}) { |
| 3004 | ## Stay in the phase | !!!cp ('t21'); |
| 3005 | ## Stay in the insertion mode. | |
| 3006 | !!!next-token; | !!!next-token; |
| 3007 | redo B; | redo B; |
| 3008 | } else { | |
| 3009 | !!!cp ('t22'); | |
| 3010 | } | } |
| 3011 | } else { | |
| 3012 | !!!cp ('t23'); | |
| 3013 | } | } |
| 3014 | ||
| 3015 | $self->{application_cache_selection}->(undef); | |
| 3016 | ||
| 3017 | # | # |
| 3018 | } elsif ($token->{type} == START_TAG_TOKEN) { | |
| 3019 | if ($token->{tag_name} eq 'html') { | |
| 3020 | my $root_element; | |
| 3021 | !!!create-element ($root_element, $HTML_NS, $token->{tag_name}, $token->{attributes}, $token); | |
| 3022 | $self->{document}->append_child ($root_element); | |
| 3023 | push @{$self->{open_elements}}, | |
| 3024 | [$root_element, $el_category->{html}]; | |
| 3025 | ||
| 3026 | if ($token->{attributes}->{manifest}) { | |
| 3027 | !!!cp ('t24'); | |
| 3028 | $self->{application_cache_selection} | |
| 3029 | ->($token->{attributes}->{manifest}->{value}); | |
| 3030 | ## ISSUE: Spec is unclear on relative references. | |
| 3031 | ## According to Hixie (#whatwg 2008-03-19), it should be | |
| 3032 | ## resolved against the base URI of the document in HTML | |
| 3033 | ## or xml:base of the element in XHTML. | |
| 3034 | } else { | |
| 3035 | !!!cp ('t25'); | |
| 3036 | $self->{application_cache_selection}->(undef); | |
| 3037 | } | |
| 3038 | ||
| 3039 | !!!nack ('t25c'); | |
| 3040 | ||
| 3041 | !!!next-token; | |
| 3042 | return; ## Go to the "before head" insertion mode. | |
| 3043 | } else { | |
| 3044 | !!!cp ('t25.1'); | |
| 3045 | # | |
| 3046 | } | |
| 3047 | } elsif ({ | } elsif ({ |
| 3048 | 'start tag' => 1, | END_TAG_TOKEN, 1, |
| 3049 | 'end tag' => 1, | END_OF_FILE_TOKEN, 1, |
| 'end-of-file' => 1, | ||
| 3050 | }->{$token->{type}}) { | }->{$token->{type}}) { |
| 3051 | ## ISSUE: There is an issue in the spec | !!!cp ('t26'); |
| 3052 | # | # |
| 3053 | } else { | } else { |
| 3054 | die "$0: $token->{type}: Unknown token"; | die "$0: $token->{type}: Unknown token type"; |
| 3055 | } | } |
| 3056 | my $root_element; !!!create-element ($root_element, 'html'); | |
| 3057 | $self->{document}->append_child ($root_element); | my $root_element; |
| 3058 | push @{$self->{open_elements}}, [$root_element, 'html']; | !!!create-element ($root_element, $HTML_NS, 'html',, $token); |
| 3059 | #$phase = 'main'; | $self->{document}->append_child ($root_element); |
| 3060 | ## reprocess | push @{$self->{open_elements}}, [$root_element, $el_category->{html}]; |
| 3061 | #redo B; | |
| 3062 | return; | $self->{application_cache_selection}->(undef); |
| 3063 | ||
| 3064 | ## NOTE: Reprocess the token. | |
| 3065 | !!!ack-later; | |
| 3066 | return; ## Go to the "before head" insertion mode. | |
| 3067 | ||
| 3068 | ## ISSUE: There is an issue in the spec | |
| 3069 | } # B | } # B |
| 3070 | ||
| 3071 | die "$0: _tree_construction_root_element: This should never be reached"; | |
| 3072 | } # _tree_construction_root_element | } # _tree_construction_root_element |
| 3073 | ||
| 3074 | sub _reset_insertion_mode ($) { | sub _reset_insertion_mode ($) { |
| # | Line 2037 sub _reset_insertion_mode ($) { | Line 3083 sub _reset_insertion_mode ($) { |
| 3083 | ||
| 3084 | ## Step 3 | ## Step 3 |
| 3085 | S3: { | S3: { |
| ## ISSUE: Oops! "If node is the first node in the stack of open | ||
| ## elements, then set last to true. If the context element of the | ||
| ## HTML fragment parsing algorithm is neither a td element nor a | ||
| ## th element, then set node to the context element. (fragment case)": | ||
| ## The second "if" is in the scope of the first "if"!? | ||
| 3086 | if ($self->{open_elements}->[0]->[0] eq $node->[0]) { | if ($self->{open_elements}->[0]->[0] eq $node->[0]) { |
| 3087 | $last = 1; | $last = 1; |
| 3088 | if (defined $self->{inner_html_node}) { | if (defined $self->{inner_html_node}) { |
| 3089 | if ($self->{inner_html_node}->[1] eq 'td' or | if ($self->{inner_html_node}->[1] & TABLE_CELL_EL) { |
| 3090 | $self->{inner_html_node}->[1] eq 'th') { | !!!cp ('t27'); |
| 3091 | # | # |
| 3092 | } else { | } else { |
| 3093 | !!!cp ('t28'); | |
| 3094 | $node = $self->{inner_html_node}; | $node = $self->{inner_html_node}; |
| 3095 | } | } |
| 3096 | } | } |
| 3097 | } | } |
| 3098 | ||
| 3099 | ## Step 4..13 | ## Step 4..14 |
| 3100 | my $new_mode = { | my $new_mode; |
| 3101 | select => 'in select', | if ($node->[1] & FOREIGN_EL) { |
| 3102 | td => 'in cell', | ## NOTE: Strictly spaking, the line below only applies to MathML and |
| 3103 | th => 'in cell', | ## SVG elements. Currently the HTML syntax supports only MathML and |
| 3104 | tr => 'in row', | ## SVG elements as foreigners. |
| 3105 | tbody => 'in table body', | $new_mode = $self->{insertion_mode} | IN_FOREIGN_CONTENT_IM; |
| 3106 | thead => 'in table head', | ## ISSUE: What is set as the secondary insertion mode? |
| 3107 | tfoot => 'in table foot', | } else { |
| 3108 | caption => 'in caption', | $new_mode = { |
| 3109 | colgroup => 'in column group', | select => IN_SELECT_IM, |
| 3110 | table => 'in table', | ## NOTE: |option| and |optgroup| do not set |
| 3111 | head => 'in body', # not in head! | ## insertion mode to "in select" by themselves. |
| 3112 | body => 'in body', | td => IN_CELL_IM, |
| 3113 | frameset => 'in frameset', | th => IN_CELL_IM, |
| 3114 | }->{$node->[1]}; | tr => IN_ROW_IM, |
| 3115 | $self->{insertion_mode} = $new_mode and return if defined $new_mode; | tbody => IN_TABLE_BODY_IM, |
| 3116 | thead => IN_TABLE_BODY_IM, | |
| 3117 | tfoot => IN_TABLE_BODY_IM, | |
| 3118 | caption => IN_CAPTION_IM, | |
| 3119 | colgroup => IN_COLUMN_GROUP_IM, | |
| 3120 | table => IN_TABLE_IM, | |
| 3121 | head => IN_BODY_IM, # not in head! | |
| 3122 | body => IN_BODY_IM, | |
| 3123 | frameset => IN_FRAMESET_IM, | |
| 3124 | }->{$node->[0]->manakai_local_name}; | |
| 3125 | } | |
| 3126 | $self->{insertion_mode} = $new_mode and return if defined $new_mode; | |
| 3127 | ||
| 3128 | ## Step 14 | ## Step 15 |
| 3129 | if ($node->[1] eq 'html') { | if ($node->[1] & HTML_EL) { |
| 3130 | unless (defined $self->{head_element}) { | unless (defined $self->{head_element}) { |
| 3131 | $self->{insertion_mode} = 'before head'; | !!!cp ('t29'); |
| 3132 | $self->{insertion_mode} = BEFORE_HEAD_IM; | |
| 3133 | } else { | } else { |
| 3134 | $self->{insertion_mode} = 'after head'; | ## ISSUE: Can this state be reached? |
| 3135 | !!!cp ('t30'); | |
| 3136 | $self->{insertion_mode} = AFTER_HEAD_IM; | |
| 3137 | } | } |
| 3138 | return; | return; |
| 3139 | } else { | |
| 3140 | !!!cp ('t31'); | |
| 3141 | } | } |
| 3142 | ||
| ## Step 15 | ||
| $self->{insertion_mode} = 'in body' and return if $last; | ||
| 3143 | ## Step 16 | ## Step 16 |
| 3144 | $self->{insertion_mode} = IN_BODY_IM and return if $last; | |
| 3145 | ||
| 3146 | ## Step 17 | |
| 3147 | $i--; | $i--; |
| 3148 | $node = $self->{open_elements}->[$i]; | $node = $self->{open_elements}->[$i]; |
| 3149 | ||
| 3150 | ## Step 17 | ## Step 18 |
| 3151 | redo S3; | redo S3; |
| 3152 | } # S3 | } # S3 |
| 3153 | ||
| 3154 | die "$0: _reset_insertion_mode: This line should never be reached"; | |
| 3155 | } # _reset_insertion_mode | } # _reset_insertion_mode |
| 3156 | ||
| 3157 | sub _tree_construction_main ($) { | sub _tree_construction_main ($) { |
| 3158 | my $self = shift; | my $self = shift; |
| 3159 | ||
| my $phase = 'main'; | ||
| 3160 | my $active_formatting_elements = []; | my $active_formatting_elements = []; |
| 3161 | ||
| 3162 | my $reconstruct_active_formatting_elements = sub { # MUST | my $reconstruct_active_formatting_elements = sub { # MUST |
| # | Line 2115 sub _tree_construction_main ($) { | Line 3173 sub _tree_construction_main ($) { |
| 3173 | return if $entry->[0] eq '#marker'; | return if $entry->[0] eq '#marker'; |
| 3174 | for (@{$self->{open_elements}}) { | for (@{$self->{open_elements}}) { |
| 3175 | if ($entry->[0] eq $_->[0]) { | if ($entry->[0] eq $_->[0]) { |
| 3176 | !!!cp ('t32'); | |
| 3177 | return; | return; |
| 3178 | } | } |
| 3179 | } | } |
| # | Line 2129 sub _tree_construction_main ($) { | Line 3188 sub _tree_construction_main ($) { |
| 3188 | ||
| 3189 | ## Step 6 | ## Step 6 |
| 3190 | if ($entry->[0] eq '#marker') { | if ($entry->[0] eq '#marker') { |
| 3191 | !!!cp ('t33_1'); | |
| 3192 | # | # |
| 3193 | } else { | } else { |
| 3194 | my $in_open_elements; | my $in_open_elements; |
| 3195 | OE: for (@{$self->{open_elements}}) { | OE: for (@{$self->{open_elements}}) { |
| 3196 | if ($entry->[0] eq $_->[0]) { | if ($entry->[0] eq $_->[0]) { |
| 3197 | !!!cp ('t33'); | |
| 3198 | $in_open_elements = 1; | $in_open_elements = 1; |
| 3199 | last OE; | last OE; |
| 3200 | } | } |
| 3201 | } | } |
| 3202 | if ($in_open_elements) { | if ($in_open_elements) { |
| 3203 | !!!cp ('t34'); | |
| 3204 | # | # |
| 3205 | } else { | } else { |
| 3206 | ## NOTE: <!DOCTYPE HTML><p><b><i><u></p> <p>X | |
| 3207 | !!!cp ('t35'); | |
| 3208 | redo S4; | redo S4; |
| 3209 | } | } |
| 3210 | } | } |
| # | Line 2163 sub _tree_construction_main ($) { | Line 3227 sub _tree_construction_main ($) { |
| 3227 | ||
| 3228 | ## Step 11 | ## Step 11 |
| 3229 | unless ($clone->[0] eq $active_formatting_elements->[-1]->[0]) { | unless ($clone->[0] eq $active_formatting_elements->[-1]->[0]) { |
| 3230 | !!!cp ('t36'); | |
| 3231 | ## Step 7' | ## Step 7' |
| 3232 | $i++; | $i++; |
| 3233 | $entry = $active_formatting_elements->[$i]; | $entry = $active_formatting_elements->[$i]; |
| 3234 | ||
| 3235 | redo S7; | redo S7; |
| 3236 | } | } |
| 3237 | ||
| 3238 | !!!cp ('t37'); | |
| 3239 | } # S7 | } # S7 |
| 3240 | }; # $reconstruct_active_formatting_elements | }; # $reconstruct_active_formatting_elements |
| 3241 | ||
| 3242 | my $clear_up_to_marker = sub { | my $clear_up_to_marker = sub { |
| 3243 | for (reverse 0..$#$active_formatting_elements) { | for (reverse 0..$#$active_formatting_elements) { |
| 3244 | if ($active_formatting_elements->[$_]->[0] eq '#marker') { | if ($active_formatting_elements->[$_]->[0] eq '#marker') { |
| 3245 | !!!cp ('t38'); | |
| 3246 | splice @$active_formatting_elements, $_; | splice @$active_formatting_elements, $_; |
| 3247 | return; | return; |
| 3248 | } | } |
| 3249 | } | } |
| 3250 | ||
| 3251 | !!!cp ('t39'); | |
| 3252 | }; # $clear_up_to_marker | }; # $clear_up_to_marker |
| 3253 | ||
| 3254 | my $parse_rcdata = sub ($$) { | my $insert; |
| 3255 | my ($content_model_flag, $insert) = @_; | |
| 3256 | my $parse_rcdata = sub ($) { | |
| 3257 | my ($content_model_flag) = @_; | |
| 3258 | ||
| 3259 | ## Step 1 | ## Step 1 |
| 3260 | my $start_tag_name = $token->{tag_name}; | my $start_tag_name = $token->{tag_name}; |
| 3261 | my $el; | my $el; |
| 3262 | !!!create-element ($el, $start_tag_name, $token->{attributes}); | !!!create-element ($el, $HTML_NS, $start_tag_name, $token->{attributes}, $token); |
| 3263 | ||
| 3264 | ## Step 2 | ## Step 2 |
| 3265 | $insert->($el); # /context node/->append_child ($el) | $insert->($el); |
| 3266 | ||
| 3267 | ## Step 3 | ## Step 3 |
| 3268 | $self->{content_model_flag} = $content_model_flag; # CDATA or RCDATA | $self->{content_model} = $content_model_flag; # CDATA or RCDATA |
| 3269 | delete $self->{escape}; # MUST | delete $self->{escape}; # MUST |
| 3270 | ||
| 3271 | ## Step 4 | ## Step 4 |
| 3272 | my $text = ''; | my $text = ''; |
| 3273 | !!!nack ('t40.1'); | |
| 3274 | !!!next-token; | !!!next-token; |
| 3275 | while ($token->{type} eq 'character') { # or until stop tokenizing | while ($token->{type} == CHARACTER_TOKEN) { # or until stop tokenizing |
| 3276 | !!!cp ('t40'); | |
| 3277 | $text .= $token->{data}; | $text .= $token->{data}; |
| 3278 | !!!next-token; | !!!next-token; |
| 3279 | } | } |
| 3280 | ||
| 3281 | ## Step 5 | ## Step 5 |
| 3282 | if (length $text) { | if (length $text) { |
| 3283 | !!!cp ('t41'); | |
| 3284 | my $text = $self->{document}->create_text_node ($text); | my $text = $self->{document}->create_text_node ($text); |
| 3285 | $el->append_child ($text); | $el->append_child ($text); |
| 3286 | } | } |
| 3287 | ||
| 3288 | ## Step 6 | ## Step 6 |
| 3289 | $self->{content_model_flag} = 'PCDATA'; | $self->{content_model} = PCDATA_CONTENT_MODEL; |
| 3290 | ||
| 3291 | ## Step 7 | ## Step 7 |
| 3292 | if ($token->{type} eq 'end tag' and $token->{tag_name} eq $start_tag_name) { | if ($token->{type} == END_TAG_TOKEN and |
| 3293 | $token->{tag_name} eq $start_tag_name) { | |
| 3294 | !!!cp ('t42'); | |
| 3295 | ## Ignore the token | ## Ignore the token |
| 3296 | } else { | } else { |
| 3297 | !!!parse-error (type => 'in '.$content_model_flag.':#'.$token->{type}); | ## NOTE: An end-of-file token. |
| 3298 | if ($content_model_flag == CDATA_CONTENT_MODEL) { | |
| 3299 | !!!cp ('t43'); | |
| 3300 | !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token); | |
| 3301 | } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) { | |
| 3302 | !!!cp ('t44'); | |
| 3303 | !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token); | |
| 3304 | } else { | |
| 3305 | die "$0: $content_model_flag in parse_rcdata"; | |
| 3306 | } | |
| 3307 | } | } |
| 3308 | !!!next-token; | !!!next-token; |
| 3309 | }; # $parse_rcdata | }; # $parse_rcdata |
| 3310 | ||
| 3311 | my $script_start_tag = sub ($) { | my $script_start_tag = sub () { |
| my $insert = $_[0]; | ||
| 3312 | my $script_el; | my $script_el; |
| 3313 | !!!create-element ($script_el, 'script', $token->{attributes}); | !!!create-element ($script_el, $HTML_NS, 'script', $token->{attributes}, $token); |
| 3314 | ## TODO: mark as "parser-inserted" | ## TODO: mark as "parser-inserted" |
| 3315 | ||