/[suikacvs]/markup/html/whatpm/Whatpm/HTML.pm.src
Suika

Diff of /markup/html/whatpm/Whatpm/HTML.pm.src

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.139 by wakaba, Sat May 24 04:26:27 2008 UTC revision 1.156 by wakaba, Sat Aug 30 13:43:50 2008 UTC
# Line 8  use Error qw(:try); Line 8  use Error qw(:try);
8  ## doc.write ('');  ## doc.write ('');
9  ## alert (doc.compatMode);  ## alert (doc.compatMode);
10    
 ## TODO: 1252 parse error (revision 1264)  
 ## TODO: 8859-11 = 874 (revision 1271)  
   
11  require IO::Handle;  require IO::Handle;
12    
13  my $HTML_NS = q<http://www.w3.org/1999/xhtml>;  my $HTML_NS = q<http://www.w3.org/1999/xhtml>;
# Line 48  sub MISC_SPECIAL_EL () { 0b1000000000000 Line 45  sub MISC_SPECIAL_EL () { 0b1000000000000
45  sub FOREIGN_EL () { 0b10000000000000000000000000 }  sub FOREIGN_EL () { 0b10000000000000000000000000 }
46  sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 }  sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 }
47  sub MML_AXML_EL () { 0b1000000000000000000000000000 }  sub MML_AXML_EL () { 0b1000000000000000000000000000 }
48    sub RUBY_EL () { 0b10000000000000000000000000000 }
49    sub RUBY_COMPONENT_EL () { 0b100000000000000000000000000000 }
50    
51  sub TABLE_ROWS_EL () {  sub TABLE_ROWS_EL () {
52    TABLE_EL |    TABLE_EL |
# Line 55  sub TABLE_ROWS_EL () { Line 54  sub TABLE_ROWS_EL () {
54    TABLE_ROW_GROUP_EL    TABLE_ROW_GROUP_EL
55  }  }
56    
57    ## NOTE: Used in "generate implied end tags" algorithm.
58    ## NOTE: There is a code where a modified version of END_TAG_OPTIONAL_EL
59    ## is used in "generate implied end tags" implementation (search for the
60    ## function mae).
61  sub END_TAG_OPTIONAL_EL () {  sub END_TAG_OPTIONAL_EL () {
62    DD_EL |    DD_EL |
63    DT_EL |    DT_EL |
64    LI_EL |    LI_EL |
65    P_EL    P_EL |
66      RUBY_COMPONENT_EL
67  }  }
68    
69    ## NOTE: Used in </body> and EOF algorithms.
70  sub ALL_END_TAG_OPTIONAL_EL () {  sub ALL_END_TAG_OPTIONAL_EL () {
71    END_TAG_OPTIONAL_EL |    DD_EL |
72      DT_EL |
73      LI_EL |
74      P_EL |
75    
76    BODY_EL |    BODY_EL |
77    HTML_EL |    HTML_EL |
78    TABLE_CELL_EL |    TABLE_CELL_EL |
# Line 99  sub SPECIAL_EL () { Line 108  sub SPECIAL_EL () {
108    ADDRESS_EL |    ADDRESS_EL |
109    BODY_EL |    BODY_EL |
110    DIV_EL |    DIV_EL |
111    END_TAG_OPTIONAL_EL |  
112      DD_EL |
113      DT_EL |
114      LI_EL |
115      P_EL |
116    
117    FORM_EL |    FORM_EL |
118    FRAMESET_EL |    FRAMESET_EL |
119    HEADING_EL |    HEADING_EL |
# Line 173  my $el_category = { Line 187  my $el_category = {
187    param => MISC_SPECIAL_EL,    param => MISC_SPECIAL_EL,
188    plaintext => MISC_SPECIAL_EL,    plaintext => MISC_SPECIAL_EL,
189    pre => MISC_SPECIAL_EL,    pre => MISC_SPECIAL_EL,
190      rp => RUBY_COMPONENT_EL,
191      rt => RUBY_COMPONENT_EL,
192      ruby => RUBY_EL,
193    s => FORMATTING_EL,    s => FORMATTING_EL,
194    script => MISC_SPECIAL_EL,    script => MISC_SPECIAL_EL,
195    select => SELECT_EL,    select => SELECT_EL,
# Line 214  my $el_category_f = { Line 231  my $el_category_f = {
231  };  };
232    
233  my $svg_attr_name = {  my $svg_attr_name = {
234      attributename => 'attributeName',
235    attributetype => 'attributeType',    attributetype => 'attributeType',
236    basefrequency => 'baseFrequency',    basefrequency => 'baseFrequency',
237    baseprofile => 'baseProfile',    baseprofile => 'baseProfile',
# Line 224  my $svg_attr_name = { Line 242  my $svg_attr_name = {
242    diffuseconstant => 'diffuseConstant',    diffuseconstant => 'diffuseConstant',
243    edgemode => 'edgeMode',    edgemode => 'edgeMode',
244    externalresourcesrequired => 'externalResourcesRequired',    externalresourcesrequired => 'externalResourcesRequired',
   fecolormatrix => 'feColorMatrix',  
   fecomposite => 'feComposite',  
   fegaussianblur => 'feGaussianBlur',  
   femorphology => 'feMorphology',  
   fetile => 'feTile',  
245    filterres => 'filterRes',    filterres => 'filterRes',
246    filterunits => 'filterUnits',    filterunits => 'filterUnits',
247    glyphref => 'glyphRef',    glyphref => 'glyphRef',
# Line 262  my $svg_attr_name = { Line 275  my $svg_attr_name = {
275    repeatcount => 'repeatCount',    repeatcount => 'repeatCount',
276    repeatdur => 'repeatDur',    repeatdur => 'repeatDur',
277    requiredextensions => 'requiredExtensions',    requiredextensions => 'requiredExtensions',
278      requiredfeatures => 'requiredFeatures',
279    specularconstant => 'specularConstant',    specularconstant => 'specularConstant',
280    specularexponent => 'specularExponent',    specularexponent => 'specularExponent',
281    spreadmethod => 'spreadMethod',    spreadmethod => 'spreadMethod',
# Line 429  sub parse_byte_stream ($$$$;$) { Line 443  sub parse_byte_stream ($$$$;$) {
443             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
444        if ($char_stream) {        if ($char_stream) {
445          $buffer->{buffer} = $byte_buffer;          $buffer->{buffer} = $byte_buffer;
446          !!!parse-error (type => 'sniffing:chardet', ## TODO: type name          !!!parse-error (type => 'sniffing:chardet',
447                          value => $charset_name,                          text => $charset_name,
448                          level => $self->{info_level},                          level => $self->{level}->{info},
449                            layer => 'encode',
450                          line => 1, column => 1);                          line => 1, column => 1);
451          $self->{confident} = 0;          $self->{confident} = 0;
452          last SNIFFING;          last SNIFFING;
# Line 452  sub parse_byte_stream ($$$$;$) { Line 467  sub parse_byte_stream ($$$$;$) {
467                                         allow_fallback => 1,                                         allow_fallback => 1,
468                                         byte_buffer => \$byte_buffer);                                         byte_buffer => \$byte_buffer);
469      $buffer->{buffer} = $byte_buffer;      $buffer->{buffer} = $byte_buffer;
470      !!!parse-error (type => 'sniffing:default', ## TODO: type name      !!!parse-error (type => 'sniffing:default',
471                      value => 'windows-1252',                      text => 'windows-1252',
472                      level => $self->{info_level},                      level => $self->{level}->{info},
473                      line => 1, column => 1);                      line => 1, column => 1,
474                        layer => 'encode');
475      $self->{confident} = 0;      $self->{confident} = 0;
476    } # SNIFFING    } # SNIFFING
477    
478    $self->{input_encoding} = $charset->get_iana_name;    $self->{input_encoding} = $charset->get_iana_name;
479    if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {    if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
480      !!!parse-error (type => 'chardecode:fallback', ## TODO: type name      !!!parse-error (type => 'chardecode:fallback',
481                      value => $self->{input_encoding},                      text => $self->{input_encoding},
482                      level => $self->{unsupported_level},                      level => $self->{level}->{uncertain},
483                      line => 1, column => 1);                      line => 1, column => 1,
484                        layer => 'encode');
485    } elsif (not ($e_status &    } elsif (not ($e_status &
486                  Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {                  Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
487      !!!parse-error (type => 'chardecode:no error', ## TODO: type name      !!!parse-error (type => 'chardecode:no error',
488                      value => $self->{input_encoding},                      text => $self->{input_encoding},
489                      level => $self->{unsupported_level},                      level => $self->{level}->{uncertain},
490                      line => 1, column => 1);                      line => 1, column => 1,
491                        layer => 'encode');
492    }    }
493    
494    $self->{change_encoding} = sub {    $self->{change_encoding} = sub {
# Line 487  sub parse_byte_stream ($$$$;$) { Line 505  sub parse_byte_stream ($$$$;$) {
505        ## "Change the encoding" algorithm:        ## "Change the encoding" algorithm:
506    
507        ## Step 1            ## Step 1    
508        if ($charset->{iana_names}->{'utf-16'}) { ## ISSUE: UTF-16BE -> UTF-8? UTF-16LE -> UTF-8?        if ($charset->{category} &
509              Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) {
510          $charset = Message::Charset::Info->get_by_iana_name ('utf-8');          $charset = Message::Charset::Info->get_by_iana_name ('utf-8');
511          ($char_stream, $e_status) = $charset->get_decode_handle          ($char_stream, $e_status) = $charset->get_decode_handle
512              ($byte_stream,              ($byte_stream,
# Line 498  sub parse_byte_stream ($$$$;$) { Line 517  sub parse_byte_stream ($$$$;$) {
517        ## Step 2        ## Step 2
518        if (defined $self->{input_encoding} and        if (defined $self->{input_encoding} and
519            $self->{input_encoding} eq $charset_name) {            $self->{input_encoding} eq $charset_name) {
520          !!!parse-error (type => 'charset label:matching', ## TODO: type          !!!parse-error (type => 'charset label:matching',
521                          value => $charset_name,                          text => $charset_name,
522                          level => $self->{info_level});                          level => $self->{level}->{info});
523          $self->{confident} = 1;          $self->{confident} = 1;
524          return;          return;
525        }        }
526    
527        !!!parse-error (type => 'charset label detected:'.$self->{input_encoding}.        !!!parse-error (type => 'charset label detected',
528            ':'.$charset_name, level => 'w', token => $token);                        text => $self->{input_encoding},
529                          value => $charset_name,
530                          level => $self->{level}->{warn},
531                          token => $token);
532                
533        ## Step 3        ## Step 3
534        # if (can) {        # if (can) {
# Line 522  sub parse_byte_stream ($$$$;$) { Line 544  sub parse_byte_stream ($$$$;$) {
544    
545    my $char_onerror = sub {    my $char_onerror = sub {
546      my (undef, $type, %opt) = @_;      my (undef, $type, %opt) = @_;
547      !!!parse-error (%opt, type => $type,      !!!parse-error (layer => 'encode',
548                        %opt, type => $type,
549                      line => $self->{line}, column => $self->{column} + 1);                      line => $self->{line}, column => $self->{column} + 1);
550      if ($opt{octets}) {      if ($opt{octets}) {
551        ${$opt{octets}} = "\x{FFFD}"; # relacement character        ${$opt{octets}} = "\x{FFFD}"; # relacement character
# Line 539  sub parse_byte_stream ($$$$;$) { Line 562  sub parse_byte_stream ($$$$;$) {
562    
563      $self->{input_encoding} = $charset->get_iana_name;      $self->{input_encoding} = $charset->get_iana_name;
564      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
565        !!!parse-error (type => 'chardecode:fallback', ## TODO: type name        !!!parse-error (type => 'chardecode:fallback',
566                        value => $self->{input_encoding},                        text => $self->{input_encoding},
567                        level => $self->{unsupported_level},                        level => $self->{level}->{uncertain},
568                        line => 1, column => 1);                        line => 1, column => 1,
569                          layer => 'encode');
570      } elsif (not ($e_status &      } elsif (not ($e_status &
571                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
572        !!!parse-error (type => 'chardecode:no error', ## TODO: type name        !!!parse-error (type => 'chardecode:no error',
573                        value => $self->{input_encoding},                        text => $self->{input_encoding},
574                        level => $self->{unsupported_level},                        level => $self->{level}->{uncertain},
575                        line => 1, column => 1);                        line => 1, column => 1,
576                          layer => 'encode');
577      }      }
578      $self->{confident} = 1;      $self->{confident} = 1;
579      $char_stream->onerror ($char_onerror);      $char_stream->onerror ($char_onerror);
# Line 647  sub parse_char_stream ($$$;$) { Line 672  sub parse_char_stream ($$$;$) {
672                0x10FFFE => 1, 0x10FFFF => 1,                0x10FFFE => 1, 0x10FFFF => 1,
673               }->{$self->{next_char}}) {               }->{$self->{next_char}}) {
674        !!!cp ('j5');        !!!cp ('j5');
675        !!!parse-error (type => 'control char', level => $self->{must_level});        if ($self->{next_char} < 0x10000) {
676  ## TODO: error type documentation          !!!parse-error (type => 'control char',
677                            text => (sprintf 'U+%04X', $self->{next_char}));
678          } else {
679            !!!parse-error (type => 'control char',
680                            text => (sprintf 'U-%08X', $self->{next_char}));
681          }
682      }      }
683    };    };
684    $self->{prev_char} = [-1, -1, -1];    $self->{prev_char} = [-1, -1, -1];
# Line 677  sub parse_char_stream ($$$;$) { Line 707  sub parse_char_stream ($$$;$) {
707  sub new ($) {  sub new ($) {
708    my $class = shift;    my $class = shift;
709    my $self = bless {    my $self = bless {
710      must_level => 'm',      level => {must => 'm',
711      should_level => 's',                warn => 'w',
712      good_level => 'w',                info => 'i',
713      warn_level => 'w',                uncertain => 'u'},
     info_level => 'i',  
     unsupported_level => 'u',  
714    }, $class;    }, $class;
715    $self->{set_next_char} = sub {    $self->{set_next_char} = sub {
716      $self->{next_char} = -1;      $self->{next_char} = -1;
# Line 829  sub _initialize_tokenizer ($) { Line 857  sub _initialize_tokenizer ($) {
857  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|
858  ##     while the token is pushed back to the stack.  ##     while the token is pushed back to the stack.
859    
 ## ISSUE: "When a DOCTYPE token is created, its  
 ## <i>self-closing flag</i> must be unset (its other state is that it  
 ## be set), and its attributes list must be empty.": Wrong subject?  
   
860  ## Emitted token MUST immediately be handled by the tree construction state.  ## Emitted token MUST immediately be handled by the tree construction state.
861    
862  ## Before each step, UA MAY check to see if either one of the scripts in  ## Before each step, UA MAY check to see if either one of the scripts in
# Line 1345  sub _get_next_token ($) { Line 1369  sub _get_next_token ($) {
1369          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
1370              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
1371            !!!cp (57);            !!!cp (57);
1372            !!!parse-error (type => 'duplicate attribute:'.$self->{current_attribute}->{name}, line => $self->{current_attribute}->{line}, column => $self->{current_attribute}->{column});            !!!parse-error (type => 'duplicate attribute', text => $self->{current_attribute}->{name}, line => $self->{current_attribute}->{line}, column => $self->{current_attribute}->{column});
1373            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{current_attribute} # MUST
1374          } else {          } else {
1375            !!!cp (58);            !!!cp (58);
# Line 1516  sub _get_next_token ($) { Line 1540  sub _get_next_token ($) {
1540    
1541          redo A;          redo A;
1542        } else {        } else {
1543          !!!cp (82);          if ($self->{next_char} == 0x0022 or # "
1544                $self->{next_char} == 0x0027) { # '
1545              !!!cp (78);
1546              !!!parse-error (type => 'bad attribute name');
1547            } else {
1548              !!!cp (82);
1549            }
1550          $self->{current_attribute}          $self->{current_attribute}
1551              = {name => chr ($self->{next_char}),              = {name => chr ($self->{next_char}),
1552                 value => '',                 value => '',
# Line 1551  sub _get_next_token ($) { Line 1581  sub _get_next_token ($) {
1581          !!!next-input-character;          !!!next-input-character;
1582          redo A;          redo A;
1583        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1584            !!!parse-error (type => 'empty unquoted attribute value');
1585          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1586            !!!cp (87);            !!!cp (87);
1587            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
# Line 1827  sub _get_next_token ($) { Line 1858  sub _get_next_token ($) {
1858          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1859          !!!next-input-character;          !!!next-input-character;
1860          redo A;          redo A;
1861          } elsif ($self->{next_char} == -1) {
1862            !!!parse-error (type => 'unclosed tag');
1863            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1864              !!!cp (122.3);
1865              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1866            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1867              if ($self->{current_token}->{attributes}) {
1868                !!!cp (122.1);
1869                !!!parse-error (type => 'end tag attribute');
1870              } else {
1871                ## NOTE: This state should never be reached.
1872                !!!cp (122.2);
1873              }
1874            } else {
1875              die "$0: $self->{current_token}->{type}: Unknown token type";
1876            }
1877            $self->{state} = DATA_STATE;
1878            ## Reconsume.
1879            !!!emit ($self->{current_token}); # start tag or end tag
1880            redo A;
1881        } else {        } else {
1882          !!!cp ('124.1');          !!!cp ('124.1');
1883          !!!parse-error (type => 'no space between attributes');          !!!parse-error (type => 'no space between attributes');
# Line 1859  sub _get_next_token ($) { Line 1910  sub _get_next_token ($) {
1910          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
1911    
1912          redo A;          redo A;
1913          } elsif ($self->{next_char} == -1) {
1914            !!!parse-error (type => 'unclosed tag');
1915            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1916              !!!cp (124.7);
1917              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1918            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1919              if ($self->{current_token}->{attributes}) {
1920                !!!cp (124.5);
1921                !!!parse-error (type => 'end tag attribute');
1922              } else {
1923                ## NOTE: This state should never be reached.
1924                !!!cp (124.6);
1925              }
1926            } else {
1927              die "$0: $self->{current_token}->{type}: Unknown token type";
1928            }
1929            $self->{state} = DATA_STATE;
1930            ## Reconsume.
1931            !!!emit ($self->{current_token}); # start tag or end tag
1932            redo A;
1933        } else {        } else {
1934          !!!cp ('124.4');          !!!cp ('124.4');
1935          !!!parse-error (type => 'nestc');          !!!parse-error (type => 'nestc');
# Line 2616  sub _get_next_token ($) { Line 2687  sub _get_next_token ($) {
2687          redo A;          redo A;
2688        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2689          !!!cp (208);          !!!cp (208);
2690          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2691    
2692          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2693          !!!next-input-character;          !!!next-input-character;
# Line 2652  sub _get_next_token ($) { Line 2723  sub _get_next_token ($) {
2723          redo A;          redo A;
2724        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2725          !!!cp (212);          !!!cp (212);
2726          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2727    
2728          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2729          !!!next-input-character;          !!!next-input-character;
# Line 2700  sub _get_next_token ($) { Line 2771  sub _get_next_token ($) {
2771        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
2772          !!!cp (217);          !!!cp (217);
2773          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
   
2774          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2775          ## reconsume          ## reconsume
2776    
# Line 2862  sub _tokenize_attempt_to_consume_an_enti Line 2932  sub _tokenize_attempt_to_consume_an_enti
2932    
2933          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2934            !!!cp (1008);            !!!cp (1008);
2935            !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
2936                              text => (sprintf 'U+%04X', $code),
2937                              line => $l, column => $c);
2938            $code = 0xFFFD;            $code = 0xFFFD;
2939          } elsif ($code > 0x10FFFF) {          } elsif ($code > 0x10FFFF) {
2940            !!!cp (1009);            !!!cp (1009);
2941            !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
2942                              text => (sprintf 'U-%08X', $code),
2943                              line => $l, column => $c);
2944            $code = 0xFFFD;            $code = 0xFFFD;
2945          } elsif ($code == 0x000D) {          } elsif ($code == 0x000D) {
2946            !!!cp (1010);            !!!cp (1010);
# Line 2874  sub _tokenize_attempt_to_consume_an_enti Line 2948  sub _tokenize_attempt_to_consume_an_enti
2948            $code = 0x000A;            $code = 0x000A;
2949          } elsif (0x80 <= $code and $code <= 0x9F) {          } elsif (0x80 <= $code and $code <= 0x9F) {
2950            !!!cp (1011);            !!!cp (1011);
2951            !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);            !!!parse-error (type => 'C1 character reference', text => (sprintf 'U+%04X', $code), line => $l, column => $c);
2952            $code = $c1_entity_char->{$code};            $code = $c1_entity_char->{$code};
2953          }          }
2954    
# Line 2907  sub _tokenize_attempt_to_consume_an_enti Line 2981  sub _tokenize_attempt_to_consume_an_enti
2981    
2982        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2983          !!!cp (1015);          !!!cp (1015);
2984          !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
2985                            text => (sprintf 'U+%04X', $code),
2986                            line => $l, column => $c);
2987          $code = 0xFFFD;          $code = 0xFFFD;
2988        } elsif ($code > 0x10FFFF) {        } elsif ($code > 0x10FFFF) {
2989          !!!cp (1016);          !!!cp (1016);
2990          !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
2991                            text => (sprintf 'U-%08X', $code),
2992                            line => $l, column => $c);
2993          $code = 0xFFFD;          $code = 0xFFFD;
2994        } elsif ($code == 0x000D) {        } elsif ($code == 0x000D) {
2995          !!!cp (1017);          !!!cp (1017);
2996          !!!parse-error (type => 'CR character reference', line => $l, column => $c);          !!!parse-error (type => 'CR character reference',
2997                            line => $l, column => $c);
2998          $code = 0x000A;          $code = 0x000A;
2999        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
3000          !!!cp (1018);          !!!cp (1018);
3001          !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'C1 character reference',
3002                            text => (sprintf 'U+%04X', $code),
3003                            line => $l, column => $c);
3004          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
3005        }        }
3006                
# Line 3017  sub _initialize_tree_constructor ($) { Line 3098  sub _initialize_tree_constructor ($) {
3098    ## TODO: Turn mutation events off # MUST    ## TODO: Turn mutation events off # MUST
3099    ## TODO: Turn loose Document option (manakai extension) on    ## TODO: Turn loose Document option (manakai extension) on
3100    $self->{document}->manakai_is_html (1); # MUST    $self->{document}->manakai_is_html (1); # MUST
3101      $self->{document}->set_user_data (manakai_source_line => 1);
3102      $self->{document}->set_user_data (manakai_source_column => 1);
3103  } # _initialize_tree_constructor  } # _initialize_tree_constructor
3104    
3105  sub _terminate_tree_constructor ($) {  sub _terminate_tree_constructor ($) {
# Line 3103  sub _tree_construction_initial ($) { Line 3186  sub _tree_construction_initial ($) {
3186        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{public_identifier}) {
3187          my $pubid = $token->{public_identifier};          my $pubid = $token->{public_identifier};
3188          $pubid =~ tr/a-z/A-z/;          $pubid =~ tr/a-z/A-z/;
3189          if ({          my $prefix = [
3190            "+//SILMARIL//DTD HTML PRO V0R11 19970101//EN" => 1,            "+//SILMARIL//DTD HTML PRO V0R11 19970101//",
3191            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3192            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3193            "-//IETF//DTD HTML 2.0 LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 1//",
3194            "-//IETF//DTD HTML 2.0 LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 2//",
3195            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//",
3196            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//",
3197            "-//IETF//DTD HTML 2.0 STRICT//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT//",
3198            "-//IETF//DTD HTML 2.0//EN" => 1,            "-//IETF//DTD HTML 2.0//",
3199            "-//IETF//DTD HTML 2.1E//EN" => 1,            "-//IETF//DTD HTML 2.1E//",
3200            "-//IETF//DTD HTML 3.0//EN" => 1,            "-//IETF//DTD HTML 3.0//",
3201            "-//IETF//DTD HTML 3.0//EN//" => 1,            "-//IETF//DTD HTML 3.2 FINAL//",
3202            "-//IETF//DTD HTML 3.2 FINAL//EN" => 1,            "-//IETF//DTD HTML 3.2//",
3203            "-//IETF//DTD HTML 3.2//EN" => 1,            "-//IETF//DTD HTML 3//",
3204            "-//IETF//DTD HTML 3//EN" => 1,            "-//IETF//DTD HTML LEVEL 0//",
3205            "-//IETF//DTD HTML LEVEL 0//EN" => 1,            "-//IETF//DTD HTML LEVEL 1//",
3206            "-//IETF//DTD HTML LEVEL 0//EN//2.0" => 1,            "-//IETF//DTD HTML LEVEL 2//",
3207            "-//IETF//DTD HTML LEVEL 1//EN" => 1,            "-//IETF//DTD HTML LEVEL 3//",
3208            "-//IETF//DTD HTML LEVEL 1//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 0//",
3209            "-//IETF//DTD HTML LEVEL 2//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 1//",
3210            "-//IETF//DTD HTML LEVEL 2//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 2//",
3211            "-//IETF//DTD HTML LEVEL 3//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 3//",
3212            "-//IETF//DTD HTML LEVEL 3//EN//3.0" => 1,            "-//IETF//DTD HTML STRICT//",
3213            "-//IETF//DTD HTML STRICT LEVEL 0//EN" => 1,            "-//IETF//DTD HTML//",
3214            "-//IETF//DTD HTML STRICT LEVEL 0//EN//2.0" => 1,            "-//METRIUS//DTD METRIUS PRESENTATIONAL//",
3215            "-//IETF//DTD HTML STRICT LEVEL 1//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//",
3216            "-//IETF//DTD HTML STRICT LEVEL 1//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//",
3217            "-//IETF//DTD HTML STRICT LEVEL 2//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//",
3218            "-//IETF//DTD HTML STRICT LEVEL 2//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//",
3219            "-//IETF//DTD HTML STRICT LEVEL 3//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//",
3220            "-//IETF//DTD HTML STRICT LEVEL 3//EN//3.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//",
3221            "-//IETF//DTD HTML STRICT//EN" => 1,            "-//NETSCAPE COMM. CORP.//DTD HTML//",
3222            "-//IETF//DTD HTML STRICT//EN//2.0" => 1,            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//",
3223            "-//IETF//DTD HTML STRICT//EN//3.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//",
3224            "-//IETF//DTD HTML//EN" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//",
3225            "-//IETF//DTD HTML//EN//2.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//",
3226            "-//IETF//DTD HTML//EN//3.0" => 1,            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//",
3227            "-//METRIUS//DTD METRIUS PRESENTATIONAL//EN" => 1,            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//",
3228            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//EN" => 1,            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//",
3229            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//EN" => 1,            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//",
3230            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//",
3231            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//",
3232            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//EN" => 1,            "-//W3C//DTD HTML 3 1995-03-24//",
3233            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//EN" => 1,            "-//W3C//DTD HTML 3.2 DRAFT//",
3234            "-//NETSCAPE COMM. CORP.//DTD HTML//EN" => 1,            "-//W3C//DTD HTML 3.2 FINAL//",
3235            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//EN" => 1,            "-//W3C//DTD HTML 3.2//",
3236            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//EN" => 1,            "-//W3C//DTD HTML 3.2S DRAFT//",
3237            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 FRAMESET//",
3238            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 TRANSITIONAL//",
3239            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMETNAL 19960712//",
3240            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMENTAL 970421//",
3241            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//EN" => 1,            "-//W3C//DTD W3 HTML//",
3242            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//EN" => 1,            "-//W3O//DTD W3 HTML 3.0//",
3243            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML 2.0//",
3244            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML//",
3245            "-//W3C//DTD HTML 3 1995-03-24//EN" => 1,          ]; # $prefix
3246            "-//W3C//DTD HTML 3.2 DRAFT//EN" => 1,          my $match;
3247            "-//W3C//DTD HTML 3.2 FINAL//EN" => 1,          for (@$prefix) {
3248            "-//W3C//DTD HTML 3.2//EN" => 1,            if (substr ($prefix, 0, length $_) eq $_) {
3249            "-//W3C//DTD HTML 3.2S DRAFT//EN" => 1,              $match = 1;
3250            "-//W3C//DTD HTML 4.0 FRAMESET//EN" => 1,              last;
3251            "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN" => 1,            }
3252            "-//W3C//DTD HTML EXPERIMETNAL 19960712//EN" => 1,          }
3253            "-//W3C//DTD HTML EXPERIMENTAL 970421//EN" => 1,          if ($match or
3254            "-//W3C//DTD W3 HTML//EN" => 1,              $pubid eq "-//W3O//DTD W3 HTML STRICT 3.0//EN//" or
3255            "-//W3O//DTD W3 HTML 3.0//EN" => 1,              $pubid eq "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" or
3256            "-//W3O//DTD W3 HTML 3.0//EN//" => 1,              $pubid eq "HTML") {
           "-//W3O//DTD W3 HTML STRICT 3.0//EN//" => 1,  
           "-//WEBTECHS//DTD MOZILLA HTML 2.0//EN" => 1,  
           "-//WEBTECHS//DTD MOZILLA HTML//EN" => 1,  
           "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" => 1,  
           "HTML" => 1,  
         }->{$pubid}) {  
3257            !!!cp ('t5');            !!!cp ('t5');
3258            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3259          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD HTML 4.01 FRAMESET//] or
3260                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD HTML 4.01 TRANSITIONAL//]) {
3261            if (defined $token->{system_identifier}) {            if (defined $token->{system_identifier}) {
3262              !!!cp ('t6');              !!!cp ('t6');
3263              $self->{document}->manakai_compat_mode ('quirks');              $self->{document}->manakai_compat_mode ('quirks');
# Line 3188  sub _tree_construction_initial ($) { Line 3265  sub _tree_construction_initial ($) {
3265              !!!cp ('t7');              !!!cp ('t7');
3266              $self->{document}->manakai_compat_mode ('limited quirks');              $self->{document}->manakai_compat_mode ('limited quirks');
3267            }            }
3268          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD XHTML 1.0 FRAMESET//] or
3269                   $pubid eq "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD XHTML 1.0 TRANSITIONAL//]) {
3270            !!!cp ('t8');            !!!cp ('t8');
3271            $self->{document}->manakai_compat_mode ('limited quirks');            $self->{document}->manakai_compat_mode ('limited quirks');
3272          } else {          } else {
# Line 3202  sub _tree_construction_initial ($) { Line 3279  sub _tree_construction_initial ($) {
3279          my $sysid = $token->{system_identifier};          my $sysid = $token->{system_identifier};
3280          $sysid =~ tr/A-Z/a-z/;          $sysid =~ tr/A-Z/a-z/;
3281          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") {
3282            ## TODO: Check the spec: PUBLIC "(limited quirks)" "(quirks)"            ## NOTE: Ensure that |PUBLIC "(limited quirks)" "(quirks)"| is
3283              ## marked as quirks.
3284            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3285            !!!cp ('t11');            !!!cp ('t11');
3286          } else {          } else {
# Line 3374  sub _reset_insertion_mode ($) { Line 3452  sub _reset_insertion_mode ($) {
3452        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
3453          $last = 1;          $last = 1;
3454          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
3455            if ($self->{inner_html_node}->[1] & TABLE_CELL_EL) {            !!!cp ('t28');
3456              !!!cp ('t27');            $node = $self->{inner_html_node};
3457              #          } else {
3458            } else {            die "_reset_insertion_mode: t27";
             !!!cp ('t28');  
             $node = $self->{inner_html_node};  
           }  
3459          }          }
3460        }        }
3461              
3462      ## Step 4..14        ## Step 4..14
3463      my $new_mode;        my $new_mode;
3464      if ($node->[1] & FOREIGN_EL) {        if ($node->[1] & FOREIGN_EL) {
3465        ## NOTE: Strictly spaking, the line below only applies to MathML and          !!!cp ('t28.1');
3466        ## SVG elements.  Currently the HTML syntax supports only MathML and          ## NOTE: Strictly spaking, the line below only applies to MathML and
3467        ## SVG elements as foreigners.          ## SVG elements.  Currently the HTML syntax supports only MathML and
3468        $new_mode = $self->{insertion_mode} | IN_FOREIGN_CONTENT_IM;          ## SVG elements as foreigners.
3469        ## ISSUE: What is set as the secondary insertion mode?          $new_mode = IN_BODY_IM | IN_FOREIGN_CONTENT_IM;
3470      } else {        } elsif ($node->[1] & TABLE_CELL_EL) {
3471        $new_mode = {          if ($last) {
3472              !!!cp ('t28.2');
3473              #
3474            } else {
3475              !!!cp ('t28.3');
3476              $new_mode = IN_CELL_IM;
3477            }
3478          } else {
3479            !!!cp ('t28.4');
3480            $new_mode = {
3481                        select => IN_SELECT_IM,                        select => IN_SELECT_IM,
3482                        ## NOTE: |option| and |optgroup| do not set                        ## NOTE: |option| and |optgroup| do not set
3483                        ## insertion mode to "in select" by themselves.                        ## insertion mode to "in select" by themselves.
                       td => IN_CELL_IM,  
                       th => IN_CELL_IM,  
3484                        tr => IN_ROW_IM,                        tr => IN_ROW_IM,
3485                        tbody => IN_TABLE_BODY_IM,                        tbody => IN_TABLE_BODY_IM,
3486                        thead => IN_TABLE_BODY_IM,                        thead => IN_TABLE_BODY_IM,
# Line 3410  sub _reset_insertion_mode ($) { Line 3492  sub _reset_insertion_mode ($) {
3492                        body => IN_BODY_IM,                        body => IN_BODY_IM,
3493                        frameset => IN_FRAMESET_IM,                        frameset => IN_FRAMESET_IM,
3494                       }->{$node->[0]->manakai_local_name};                       }->{$node->[0]->manakai_local_name};
3495      }        }
3496      $self->{insertion_mode} = $new_mode and return if defined $new_mode;        $self->{insertion_mode} = $new_mode and return if defined $new_mode;
3497                
3498        ## Step 15        ## Step 15
3499        if ($node->[1] & HTML_EL) {        if ($node->[1] & HTML_EL) {
# Line 3585  sub _tree_construction_main ($) { Line 3667  sub _tree_construction_main ($) {
3667        ## NOTE: An end-of-file token.        ## NOTE: An end-of-file token.
3668        if ($content_model_flag == CDATA_CONTENT_MODEL) {        if ($content_model_flag == CDATA_CONTENT_MODEL) {
3669          !!!cp ('t43');          !!!cp ('t43');
3670          !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in CDATA:#eof', token => $token);
3671        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
3672          !!!cp ('t44');          !!!cp ('t44');
3673          !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in RCDATA:#eof', token => $token);
3674        } else {        } else {
3675          die "$0: $content_model_flag in parse_rcdata";          die "$0: $content_model_flag in parse_rcdata";
3676        }        }
# Line 3625  sub _tree_construction_main ($) { Line 3707  sub _tree_construction_main ($) {
3707        ## Ignore the token        ## Ignore the token
3708      } else {      } else {
3709        !!!cp ('t48');        !!!cp ('t48');
3710        !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);        !!!parse-error (type => 'in CDATA:#eof', token => $token);
3711        ## ISSUE: And ignore?        ## ISSUE: And ignore?
3712        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
3713      }      }
# Line 3676  sub _tree_construction_main ($) { Line 3758  sub _tree_construction_main ($) {
3758        } # AFE        } # AFE
3759        unless (defined $formatting_element) {        unless (defined $formatting_element) {
3760          !!!cp ('t53');          !!!cp ('t53');
3761          !!!parse-error (type => 'unmatched end tag:'.$tag_name, token => $end_tag_token);          !!!parse-error (type => 'unmatched end tag', text => $tag_name, token => $end_tag_token);
3762          ## Ignore the token          ## Ignore the token
3763          !!!next-token;          !!!next-token;
3764          return;          return;
# Line 3693  sub _tree_construction_main ($) { Line 3775  sub _tree_construction_main ($) {
3775              last INSCOPE;              last INSCOPE;
3776            } else { # in open elements but not in scope            } else { # in open elements but not in scope
3777              !!!cp ('t55');              !!!cp ('t55');
3778              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},              !!!parse-error (type => 'unmatched end tag',
3779                                text => $token->{tag_name},
3780                              token => $end_tag_token);                              token => $end_tag_token);
3781              ## Ignore the token              ## Ignore the token
3782              !!!next-token;              !!!next-token;
# Line 3706  sub _tree_construction_main ($) { Line 3789  sub _tree_construction_main ($) {
3789        } # INSCOPE        } # INSCOPE
3790        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
3791          !!!cp ('t57');          !!!cp ('t57');
3792          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},          !!!parse-error (type => 'unmatched end tag',
3793                            text => $token->{tag_name},
3794                          token => $end_tag_token);                          token => $end_tag_token);
3795          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
3796          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
# Line 3715  sub _tree_construction_main ($) { Line 3799  sub _tree_construction_main ($) {
3799        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
3800          !!!cp ('t58');          !!!cp ('t58');
3801          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
3802                          value => $self->{open_elements}->[-1]->[0]                          text => $self->{open_elements}->[-1]->[0]
3803                              ->manakai_local_name,                              ->manakai_local_name,
3804                          token => $end_tag_token);                          token => $end_tag_token);
3805        }        }
# Line 3924  sub _tree_construction_main ($) { Line 4008  sub _tree_construction_main ($) {
4008    B: while (1) {    B: while (1) {
4009      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
4010        !!!cp ('t73');        !!!cp ('t73');
4011        !!!parse-error (type => 'DOCTYPE in the middle', token => $token);        !!!parse-error (type => 'in html:#DOCTYPE', token => $token);
4012        ## Ignore the token        ## Ignore the token
4013        ## Stay in the phase        ## Stay in the phase
4014        !!!next-token;        !!!next-token;
# Line 3933  sub _tree_construction_main ($) { Line 4017  sub _tree_construction_main ($) {
4017               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
4018        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
4019          !!!cp ('t79');          !!!cp ('t79');
4020          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4021          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
4022        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
4023          !!!cp ('t80');          !!!cp ('t80');
4024          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4025          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
4026        } else {        } else {
4027          !!!cp ('t81');          !!!cp ('t81');
# Line 3988  sub _tree_construction_main ($) { Line 4072  sub _tree_construction_main ($) {
4072            #            #
4073          } elsif ({          } elsif ({
4074                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,
4075                    center => 1, code => 1, dd => 1, div => 1, dl => 1, em => 1,                    center => 1, code => 1, dd => 1, div => 1, dl => 1, dt => 1,
4076                    embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1, ## No h4!                    em => 1, embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1,
4077                    h5 => 1, h6 => 1, head => 1, hr => 1, i => 1, img => 1,                    h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, i => 1,
4078                    li => 1, menu => 1, meta => 1, nobr => 1, p => 1, pre => 1,                    img => 1, li => 1, listing => 1, menu => 1, meta => 1,
4079                    ruby => 1, s => 1, small => 1, span => 1, strong => 1,                    nobr => 1, ol => 1, p => 1, pre => 1, ruby => 1, s => 1,
4080                    sub => 1, sup => 1, table => 1, tt => 1, u => 1, ul => 1,                    small => 1, span => 1, strong => 1, strike => 1, sub => 1,
4081                    var => 1,                    sup => 1, table => 1, tt => 1, u => 1, ul => 1, var => 1,
4082                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
4083            !!!cp ('t87.2');            !!!cp ('t87.2');
4084            !!!parse-error (type => 'not closed',            !!!parse-error (type => 'not closed',
4085                            value => $self->{open_elements}->[-1]->[0]                            text => $self->{open_elements}->[-1]->[0]
4086                                ->manakai_local_name,                                ->manakai_local_name,
4087                            token => $token);                            token => $token);
4088    
# Line 4074  sub _tree_construction_main ($) { Line 4158  sub _tree_construction_main ($) {
4158          !!!cp ('t87.5');          !!!cp ('t87.5');
4159          #          #
4160        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
         ## NOTE: "using the rules for secondary insertion mode" then "continue"  
4161          !!!cp ('t87.6');          !!!cp ('t87.6');
4162          #          !!!parse-error (type => 'not closed',
4163          ## TODO: ...                          text => $self->{open_elements}->[-1]->[0]
4164                                ->manakai_local_name,
4165                            token => $token);
4166    
4167            pop @{$self->{open_elements}}
4168                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;
4169    
4170            $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
4171            ## Reprocess.
4172            next B;
4173        } else {        } else {
4174          die "$0: $token->{type}: Unknown token type";                  die "$0: $token->{type}: Unknown token type";        
4175        }        }
# Line 4118  sub _tree_construction_main ($) { Line 4210  sub _tree_construction_main ($) {
4210            !!!cp ('t90');            !!!cp ('t90');
4211            ## As if </noscript>            ## As if </noscript>
4212            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
4213            !!!parse-error (type => 'in noscript:#character', token => $token);            !!!parse-error (type => 'in noscript:#text', token => $token);
4214                        
4215            ## Reprocess in the "in head" insertion mode...            ## Reprocess in the "in head" insertion mode...
4216            ## As if </head>            ## As if </head>
# Line 4155  sub _tree_construction_main ($) { Line 4247  sub _tree_construction_main ($) {
4247              next B;              next B;
4248            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4249              !!!cp ('t93.2');              !!!cp ('t93.2');
4250              !!!parse-error (type => 'after head:head', token => $token); ## TODO: error type              !!!parse-error (type => 'after head', text => 'head',
4251                                token => $token);
4252              ## Ignore the token              ## Ignore the token
4253              !!!nack ('t93.3');              !!!nack ('t93.3');
4254              !!!next-token;              !!!next-token;
4255              next B;              next B;
4256            } else {            } else {
4257              !!!cp ('t95');              !!!cp ('t95');
4258              !!!parse-error (type => 'in head:head', token => $token); # or in head noscript              !!!parse-error (type => 'in head:head',
4259                                token => $token); # or in head noscript
4260              ## Ignore the token              ## Ignore the token
4261              !!!nack ('t95.1');              !!!nack ('t95.1');
4262              !!!next-token;              !!!next-token;
# Line 4187  sub _tree_construction_main ($) { Line 4281  sub _tree_construction_main ($) {
4281                  !!!cp ('t98');                  !!!cp ('t98');
4282                  ## As if </noscript>                  ## As if </noscript>
4283                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4284                  !!!parse-error (type => 'in noscript:base', token => $token);                  !!!parse-error (type => 'in noscript', text => 'base',
4285                                    token => $token);
4286                                
4287                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4288                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
# Line 4198  sub _tree_construction_main ($) { Line 4293  sub _tree_construction_main ($) {
4293                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4294                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4295                  !!!cp ('t100');                  !!!cp ('t100');
4296                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4297                                    text => $token->{tag_name}, token => $token);
4298                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4299                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4300                } else {                } else {
# Line 4215  sub _tree_construction_main ($) { Line 4311  sub _tree_construction_main ($) {
4311                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4312                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4313                  !!!cp ('t102');                  !!!cp ('t102');
4314                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4315                                    text => $token->{tag_name}, token => $token);
4316                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4317                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4318                } else {                } else {
# Line 4232  sub _tree_construction_main ($) { Line 4329  sub _tree_construction_main ($) {
4329                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4330                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4331                  !!!cp ('t104');                  !!!cp ('t104');
4332                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4333                                    text => $token->{tag_name}, token => $token);
4334                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4335                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4336                } else {                } else {
# Line 4256  sub _tree_construction_main ($) { Line 4354  sub _tree_construction_main ($) {
4354                                                 ->{has_reference});                                                 ->{has_reference});
4355                  } elsif ($token->{attributes}->{content}) {                  } elsif ($token->{attributes}->{content}) {
4356                    if ($token->{attributes}->{content}->{value}                    if ($token->{attributes}->{content}->{value}
4357                        =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                        =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
4358                            [\x09-\x0D\x20]*=                            [\x09-\x0D\x20]*=
4359                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
4360                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
4361                      !!!cp ('t107');                      !!!cp ('t107');
4362                      ## NOTE: Whether the encoding is supported or not is handled                      ## NOTE: Whether the encoding is supported or not is handled
4363                      ## in the {change_encoding} callback.                      ## in the {change_encoding} callback.
# Line 4301  sub _tree_construction_main ($) { Line 4399  sub _tree_construction_main ($) {
4399                  !!!cp ('t111');                  !!!cp ('t111');
4400                  ## As if </noscript>                  ## As if </noscript>
4401                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4402                  !!!parse-error (type => 'in noscript:title', token => $token);                  !!!parse-error (type => 'in noscript', text => 'title',
4403                                    token => $token);
4404                                
4405                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4406                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4407                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4408                  !!!cp ('t112');                  !!!cp ('t112');
4409                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4410                                    text => $token->{tag_name}, token => $token);
4411                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4412                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4413                } else {                } else {
# Line 4321  sub _tree_construction_main ($) { Line 4421  sub _tree_construction_main ($) {
4421                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4422                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4423                next B;                next B;
4424              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style' or
4425                         $token->{tag_name} eq 'noframes') {
4426                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and
4427                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
4428                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4429                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4430                  !!!cp ('t114');                  !!!cp ('t114');
4431                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4432                                    text => $token->{tag_name}, token => $token);
4433                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4434                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4435                } else {                } else {
# Line 4348  sub _tree_construction_main ($) { Line 4450  sub _tree_construction_main ($) {
4450                  next B;                  next B;
4451                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4452                  !!!cp ('t117');                  !!!cp ('t117');
4453                  !!!parse-error (type => 'in noscript:noscript', token => $token);                  !!!parse-error (type => 'in noscript', text => 'noscript',
4454                                    token => $token);
4455                  ## Ignore the token                  ## Ignore the token
4456                  !!!nack ('t117.1');                  !!!nack ('t117.1');
4457                  !!!next-token;                  !!!next-token;
# Line 4362  sub _tree_construction_main ($) { Line 4465  sub _tree_construction_main ($) {
4465                  !!!cp ('t119');                  !!!cp ('t119');
4466                  ## As if </noscript>                  ## As if </noscript>
4467                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4468                  !!!parse-error (type => 'in noscript:script', token => $token);                  !!!parse-error (type => 'in noscript', text => 'script',
4469                                    token => $token);
4470                                
4471                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4472                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4473                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4474                  !!!cp ('t120');                  !!!cp ('t120');
4475                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4476                                    text => $token->{tag_name}, token => $token);
4477                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4478                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4479                } else {                } else {
# Line 4386  sub _tree_construction_main ($) { Line 4491  sub _tree_construction_main ($) {
4491                  !!!cp ('t122');                  !!!cp ('t122');
4492                  ## As if </noscript>                  ## As if </noscript>
4493                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4494                  !!!parse-error (type => 'in noscript:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in noscript',
4495                                    text => $token->{tag_name}, token => $token);
4496                                    
4497                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4498                  ## As if </head>                  ## As if </head>
# Line 4425  sub _tree_construction_main ($) { Line 4531  sub _tree_construction_main ($) {
4531                !!!cp ('t129');                !!!cp ('t129');
4532                ## As if </noscript>                ## As if </noscript>
4533                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4534                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4535                                  text => $token->{tag_name}, token => $token);
4536                                
4537                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4538                ## As if </head>                ## As if </head>
# Line 4468  sub _tree_construction_main ($) { Line 4575  sub _tree_construction_main ($) {
4575                  !!!cp ('t133');                  !!!cp ('t133');
4576                  ## As if </noscript>                  ## As if </noscript>
4577                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4578                  !!!parse-error (type => 'in noscript:/head', token => $token);                  !!!parse-error (type => 'in noscript:/',
4579                                    text => 'head', token => $token);
4580                                    
4581                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4582                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 4483  sub _tree_construction_main ($) { Line 4591  sub _tree_construction_main ($) {
4591                  next B;                  next B;
4592                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4593                  !!!cp ('t134.1');                  !!!cp ('t134.1');
4594                  !!!parse-error (type => 'unmatched end tag:head', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'head',
4595                                    token => $token);
4596                  ## Ignore the token                  ## Ignore the token
4597                  !!!next-token;                  !!!next-token;
4598                  next B;                  next B;
# Line 4500  sub _tree_construction_main ($) { Line 4609  sub _tree_construction_main ($) {
4609                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or
4610                         $self->{insertion_mode} == AFTER_HEAD_IM) {                         $self->{insertion_mode} == AFTER_HEAD_IM) {
4611                  !!!cp ('t137');                  !!!cp ('t137');
4612                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4613                                    text => 'noscript', token => $token);
4614                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
4615                  !!!next-token;                  !!!next-token;
4616                  next B;                  next B;
# Line 4515  sub _tree_construction_main ($) { Line 4625  sub _tree_construction_main ($) {
4625                    $self->{insertion_mode} == IN_HEAD_IM or                    $self->{insertion_mode} == IN_HEAD_IM or
4626                    $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                    $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4627                  !!!cp ('t140');                  !!!cp ('t140');
4628                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4629                                    text => $token->{tag_name}, token => $token);
4630                  ## Ignore the token                  ## Ignore the token
4631                  !!!next-token;                  !!!next-token;
4632                  next B;                  next B;
4633                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4634                  !!!cp ('t140.1');                  !!!cp ('t140.1');
4635                  !!!parse-error (type => 'unmatched end tag:' . $token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4636                                    text => $token->{tag_name}, token => $token);
4637                  ## Ignore the token                  ## Ignore the token
4638                  !!!next-token;                  !!!next-token;
4639                  next B;                  next B;
# Line 4530  sub _tree_construction_main ($) { Line 4642  sub _tree_construction_main ($) {
4642                }                }
4643              } elsif ($token->{tag_name} eq 'p') {              } elsif ($token->{tag_name} eq 'p') {
4644                !!!cp ('t142');                !!!cp ('t142');
4645                !!!parse-error (type => 'unmatched end tag:p', token => $token);                !!!parse-error (type => 'unmatched end tag',
4646                                  text => $token->{tag_name}, token => $token);
4647                ## Ignore the token                ## Ignore the token
4648                !!!next-token;                !!!next-token;
4649                next B;                next B;
# Line 4553  sub _tree_construction_main ($) { Line 4666  sub _tree_construction_main ($) {
4666                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4667                  !!!cp ('t143.3');                  !!!cp ('t143.3');
4668                  ## ISSUE: Two parse errors for <head><noscript></br>                  ## ISSUE: Two parse errors for <head><noscript></br>
4669                  !!!parse-error (type => 'unmatched end tag:br', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4670                                    text => 'br', token => $token);
4671                  ## As if </noscript>                  ## As if </noscript>
4672                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4673                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
# Line 4572  sub _tree_construction_main ($) { Line 4686  sub _tree_construction_main ($) {
4686                }                }
4687    
4688                ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.                ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.
4689                !!!parse-error (type => 'unmatched end tag:br', token => $token);                !!!parse-error (type => 'unmatched end tag',
4690                                  text => 'br', token => $token);
4691                ## Ignore the token                ## Ignore the token
4692                !!!next-token;                !!!next-token;
4693                next B;                next B;
4694              } else {              } else {
4695                !!!cp ('t145');                !!!cp ('t145');
4696                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
4697                                  text => $token->{tag_name}, token => $token);
4698                ## Ignore the token                ## Ignore the token
4699                !!!next-token;                !!!next-token;
4700                next B;                next B;
# Line 4588  sub _tree_construction_main ($) { Line 4704  sub _tree_construction_main ($) {
4704                !!!cp ('t146');                !!!cp ('t146');
4705                ## As if </noscript>                ## As if </noscript>
4706                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4707                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4708                                  text => $token->{tag_name}, token => $token);
4709                                
4710                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4711                ## As if </head>                ## As if </head>
# Line 4604  sub _tree_construction_main ($) { Line 4721  sub _tree_construction_main ($) {
4721              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4722  ## ISSUE: This case cannot be reached?  ## ISSUE: This case cannot be reached?
4723                !!!cp ('t148');                !!!cp ('t148');
4724                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
4725                                  text => $token->{tag_name}, token => $token);
4726                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
4727                !!!next-token;                !!!next-token;
4728                next B;                next B;
# Line 4715  sub _tree_construction_main ($) { Line 4833  sub _tree_construction_main ($) {
4833    
4834                  !!!cp ('t153');                  !!!cp ('t153');
4835                  !!!parse-error (type => 'start tag not allowed',                  !!!parse-error (type => 'start tag not allowed',
4836                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
4837                  ## Ignore the token                  ## Ignore the token
4838                  !!!nack ('t153.1');                  !!!nack ('t153.1');
4839                  !!!next-token;                  !!!next-token;
4840                  next B;                  next B;
4841                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4842                  !!!parse-error (type => 'not closed:caption', token => $token);                  !!!parse-error (type => 'not closed', text => 'caption',
4843                                    token => $token);
4844                                    
4845                  ## NOTE: As if </caption>.                  ## NOTE: As if </caption>.
4846                  ## have a table element in table scope                  ## have a table element in table scope
# Line 4741  sub _tree_construction_main ($) { Line 4860  sub _tree_construction_main ($) {
4860    
4861                    !!!cp ('t157');                    !!!cp ('t157');
4862                    !!!parse-error (type => 'start tag not allowed',                    !!!parse-error (type => 'start tag not allowed',
4863                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
4864                    ## Ignore the token                    ## Ignore the token
4865                    !!!nack ('t157.1');                    !!!nack ('t157.1');
4866                    !!!next-token;                    !!!next-token;
# Line 4758  sub _tree_construction_main ($) { Line 4877  sub _tree_construction_main ($) {
4877                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
4878                    !!!cp ('t159');                    !!!cp ('t159');
4879                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
4880                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
4881                                        ->manakai_local_name,                                        ->manakai_local_name,
4882                                    token => $token);                                    token => $token);
4883                  } else {                  } else {
# Line 4800  sub _tree_construction_main ($) { Line 4919  sub _tree_construction_main ($) {
4919                  } # INSCOPE                  } # INSCOPE
4920                    unless (defined $i) {                    unless (defined $i) {
4921                      !!!cp ('t165');                      !!!cp ('t165');
4922                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
4923                                        text => $token->{tag_name},
4924                                        token => $token);
4925                      ## Ignore the token                      ## Ignore the token
4926                      !!!next-token;                      !!!next-token;
4927                      next B;                      next B;
# Line 4817  sub _tree_construction_main ($) { Line 4938  sub _tree_construction_main ($) {
4938                          ne $token->{tag_name}) {                          ne $token->{tag_name}) {
4939                    !!!cp ('t167');                    !!!cp ('t167');
4940                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
4941                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
4942                                        ->manakai_local_name,                                        ->manakai_local_name,
4943                                    token => $token);                                    token => $token);
4944                  } else {                  } else {
# Line 4834  sub _tree_construction_main ($) { Line 4955  sub _tree_construction_main ($) {
4955                  next B;                  next B;
4956                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4957                  !!!cp ('t169');                  !!!cp ('t169');
4958                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4959                                    text => $token->{tag_name}, token => $token);
4960                  ## Ignore the token                  ## Ignore the token
4961                  !!!next-token;                  !!!next-token;
4962                  next B;                  next B;
# Line 4861  sub _tree_construction_main ($) { Line 4983  sub _tree_construction_main ($) {
4983    
4984                    !!!cp ('t173');                    !!!cp ('t173');
4985                    !!!parse-error (type => 'unmatched end tag',                    !!!parse-error (type => 'unmatched end tag',
4986                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
4987                    ## Ignore the token                    ## Ignore the token
4988                    !!!next-token;                    !!!next-token;
4989                    next B;                    next B;
# Line 4877  sub _tree_construction_main ($) { Line 4999  sub _tree_construction_main ($) {
4999                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5000                    !!!cp ('t175');                    !!!cp ('t175');
5001                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5002                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5003                                        ->manakai_local_name,                                        ->manakai_local_name,
5004                                    token => $token);                                    token => $token);
5005                  } else {                  } else {
# Line 4894  sub _tree_construction_main ($) { Line 5016  sub _tree_construction_main ($) {
5016                  next B;                  next B;
5017                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
5018                  !!!cp ('t177');                  !!!cp ('t177');
5019                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5020                                    text => $token->{tag_name}, token => $token);
5021                  ## Ignore the token                  ## Ignore the token
5022                  !!!next-token;                  !!!next-token;
5023                  next B;                  next B;
# Line 4937  sub _tree_construction_main ($) { Line 5060  sub _tree_construction_main ($) {
5060    
5061                  !!!cp ('t182');                  !!!cp ('t182');
5062                  !!!parse-error (type => 'unmatched end tag',                  !!!parse-error (type => 'unmatched end tag',
5063                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
5064                  ## Ignore the token                  ## Ignore the token
5065                  !!!next-token;                  !!!next-token;
5066                  next B;                  next B;
5067                } # INSCOPE                } # INSCOPE
5068              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
5069                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5070                !!!parse-error (type => 'not closed:caption', token => $token);                !!!parse-error (type => 'not closed', text => 'caption',
5071                                  token => $token);
5072    
5073                ## As if </caption>                ## As if </caption>
5074                ## have a table element in table scope                ## have a table element in table scope
# Line 4962  sub _tree_construction_main ($) { Line 5086  sub _tree_construction_main ($) {
5086                } # INSCOPE                } # INSCOPE
5087                unless (defined $i) {                unless (defined $i) {
5088                  !!!cp ('t186');                  !!!cp ('t186');
5089                  !!!parse-error (type => 'unmatched end tag:caption', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5090                                    text => 'caption', token => $token);
5091                  ## Ignore the token                  ## Ignore the token
5092                  !!!next-token;                  !!!next-token;
5093                  next B;                  next B;
# Line 4977  sub _tree_construction_main ($) { Line 5102  sub _tree_construction_main ($) {
5102                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5103                  !!!cp ('t188');                  !!!cp ('t188');
5104                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5105                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5106                                      ->manakai_local_name,                                      ->manakai_local_name,
5107                                  token => $token);                                  token => $token);
5108                } else {                } else {
# Line 4997  sub _tree_construction_main ($) { Line 5122  sub _tree_construction_main ($) {
5122                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5123                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
5124                  !!!cp ('t190');                  !!!cp ('t190');
5125                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5126                                    text => $token->{tag_name}, token => $token);
5127                  ## Ignore the token                  ## Ignore the token
5128                  !!!next-token;                  !!!next-token;
5129                  next B;                  next B;
# Line 5011  sub _tree_construction_main ($) { Line 5137  sub _tree_construction_main ($) {
5137                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
5138                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5139                !!!cp ('t192');                !!!cp ('t192');
5140                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
5141                                  text => $token->{tag_name}, token => $token);
5142                ## Ignore the token                ## Ignore the token
5143                !!!next-token;                !!!next-token;
5144                next B;                next B;
# Line 5051  sub _tree_construction_main ($) { Line 5178  sub _tree_construction_main ($) {
5178            }            }
5179          }          }
5180    
5181              !!!parse-error (type => 'in table:#character', token => $token);          !!!parse-error (type => 'in table:#text', token => $token);
5182    
5183              ## As if in body, but insert into foster parent element              ## As if in body, but insert into foster parent element
5184              ## ISSUE: Spec says that "whenever a node would be inserted              ## ISSUE: Spec says that "whenever a node would be inserted
# Line 5102  sub _tree_construction_main ($) { Line 5229  sub _tree_construction_main ($) {
5229          !!!next-token;          !!!next-token;
5230          next B;          next B;
5231        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5232              if ({          if ({
5233                   tr => ($self->{insertion_mode} != IN_ROW_IM),               tr => ($self->{insertion_mode} != IN_ROW_IM),
5234                   th => 1, td => 1,               th => 1, td => 1,
5235                  }->{$token->{tag_name}}) {              }->{$token->{tag_name}}) {
5236                if ($self->{insertion_mode} == IN_TABLE_IM) {            if ($self->{insertion_mode} == IN_TABLE_IM) {
5237                  ## Clear back to table context              ## Clear back to table context
5238                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5239                                  & TABLE_SCOPING_EL)) {                              & TABLE_SCOPING_EL)) {
5240                    !!!cp ('t201');                !!!cp ('t201');
5241                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5242                  }              }
5243                                
5244                  !!!insert-element ('tbody',, $token);              !!!insert-element ('tbody',, $token);
5245                  $self->{insertion_mode} = IN_TABLE_BODY_IM;              $self->{insertion_mode} = IN_TABLE_BODY_IM;
5246                  ## reprocess in the "in table body" insertion mode...              ## reprocess in the "in table body" insertion mode...
5247                }            }
5248              
5249                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {            if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
5250                  unless ($token->{tag_name} eq 'tr') {              unless ($token->{tag_name} eq 'tr') {
5251                    !!!cp ('t202');                !!!cp ('t202');
5252                    !!!parse-error (type => 'missing start tag:tr', token => $token);                !!!parse-error (type => 'missing start tag:tr', token => $token);
5253                  }              }
5254                                    
5255                  ## Clear back to table body context              ## Clear back to table body context
5256                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5257                                  & TABLE_ROWS_SCOPING_EL)) {                              & TABLE_ROWS_SCOPING_EL)) {
5258                    !!!cp ('t203');                !!!cp ('t203');
5259                    ## ISSUE: Can this case be reached?                ## ISSUE: Can this case be reached?
5260                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5261                  }              }
5262                                    
5263                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
5264                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
# Line 5187  sub _tree_construction_main ($) { Line 5314  sub _tree_construction_main ($) {
5314                  unless (defined $i) {                  unless (defined $i) {
5315                    !!!cp ('t210');                    !!!cp ('t210');
5316  ## TODO: This type is wrong.  ## TODO: This type is wrong.
5317                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmacthed end tag',
5318                                      text => $token->{tag_name}, token => $token);
5319                    ## Ignore the token                    ## Ignore the token
5320                    !!!nack ('t210.1');                    !!!nack ('t210.1');
5321                    !!!next-token;                    !!!next-token;
# Line 5231  sub _tree_construction_main ($) { Line 5359  sub _tree_construction_main ($) {
5359                  } # INSCOPE                  } # INSCOPE
5360                  unless (defined $i) {                  unless (defined $i) {
5361                    !!!cp ('t216');                    !!!cp ('t216');
5362  ## TODO: This erorr type ios wrong.  ## TODO: This erorr type is wrong.
5363                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5364                                      text => $token->{tag_name}, token => $token);
5365                    ## Ignore the token                    ## Ignore the token
5366                    !!!nack ('t216.1');                    !!!nack ('t216.1');
5367                    !!!next-token;                    !!!next-token;
# Line 5307  sub _tree_construction_main ($) { Line 5436  sub _tree_construction_main ($) {
5436                }                }
5437              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
5438                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
5439                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
5440                                    ->manakai_local_name,                                    ->manakai_local_name,
5441                                token => $token);                                token => $token);
5442    
# Line 5328  sub _tree_construction_main ($) { Line 5457  sub _tree_construction_main ($) {
5457                unless (defined $i) {                unless (defined $i) {
5458                  !!!cp ('t223');                  !!!cp ('t223');
5459  ## TODO: The following is wrong, maybe.  ## TODO: The following is wrong, maybe.
5460                  !!!parse-error (type => 'unmatched end tag:table', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'table',
5461                                    token => $token);
5462                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
5463                  !!!nack ('t223.1');                  !!!nack ('t223.1');
5464                  !!!next-token;                  !!!next-token;
5465                  next B;                  next B;
5466                }                }
5467                                
5468  ## TODO: Followings are removed from the latest spec.  ## TODO: Followings are removed from the latest spec.
5469                ## generate implied end tags                ## generate implied end tags
5470                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
5471                  !!!cp ('t224');                  !!!cp ('t224');
# Line 5346  sub _tree_construction_main ($) { Line 5476  sub _tree_construction_main ($) {
5476                  !!!cp ('t225');                  !!!cp ('t225');
5477                  ## NOTE: |<table><tr><table>|                  ## NOTE: |<table><tr><table>|
5478                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5479                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5480                                      ->manakai_local_name,                                      ->manakai_local_name,
5481                                  token => $token);                                  token => $token);
5482                } else {                } else {
# Line 5387  sub _tree_construction_main ($) { Line 5517  sub _tree_construction_main ($) {
5517                my $type = lc $token->{attributes}->{type}->{value};                my $type = lc $token->{attributes}->{type}->{value};
5518                if ($type eq 'hidden') {                if ($type eq 'hidden') {
5519                  !!!cp ('t227.3');                  !!!cp ('t227.3');
5520                  !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in table',
5521                                    text => $token->{tag_name}, token => $token);
5522    
5523                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5524    
# Line 5415  sub _tree_construction_main ($) { Line 5546  sub _tree_construction_main ($) {
5546            #            #
5547          }          }
5548    
5549          !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in table', text => $token->{tag_name},
5550                            token => $token);
5551    
5552          $insert = $insert_to_foster;          $insert = $insert_to_foster;
5553          #          #
# Line 5437  sub _tree_construction_main ($) { Line 5569  sub _tree_construction_main ($) {
5569                } # INSCOPE                } # INSCOPE
5570                unless (defined $i) {                unless (defined $i) {
5571                  !!!cp ('t230');                  !!!cp ('t230');
5572                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5573                                    text => $token->{tag_name}, token => $token);
5574                  ## Ignore the token                  ## Ignore the token
5575                  !!!nack ('t230.1');                  !!!nack ('t230.1');
5576                  !!!next-token;                  !!!next-token;
# Line 5478  sub _tree_construction_main ($) { Line 5611  sub _tree_construction_main ($) {
5611                  unless (defined $i) {                  unless (defined $i) {
5612                    !!!cp ('t235');                    !!!cp ('t235');
5613  ## TODO: The following is wrong.  ## TODO: The following is wrong.
5614                    !!!parse-error (type => 'unmatched end tag:'.$token->{type}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5615                                      text => $token->{type}, token => $token);
5616                    ## Ignore the token                    ## Ignore the token
5617                    !!!nack ('t236.1');                    !!!nack ('t236.1');
5618                    !!!next-token;                    !!!next-token;
# Line 5514  sub _tree_construction_main ($) { Line 5648  sub _tree_construction_main ($) {
5648                  } # INSCOPE                  } # INSCOPE
5649                  unless (defined $i) {                  unless (defined $i) {
5650                    !!!cp ('t239');                    !!!cp ('t239');
5651                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5652                                      text => $token->{tag_name}, token => $token);
5653                    ## Ignore the token                    ## Ignore the token
5654                    !!!nack ('t239.1');                    !!!nack ('t239.1');
5655                    !!!next-token;                    !!!next-token;
# Line 5560  sub _tree_construction_main ($) { Line 5695  sub _tree_construction_main ($) {
5695                } # INSCOPE                } # INSCOPE
5696                unless (defined $i) {                unless (defined $i) {
5697                  !!!cp ('t243');                  !!!cp ('t243');
5698                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5699                                    text => $token->{tag_name}, token => $token);
5700                  ## Ignore the token                  ## Ignore the token
5701                  !!!nack ('t243.1');                  !!!nack ('t243.1');
5702                  !!!next-token;                  !!!next-token;
# Line 5594  sub _tree_construction_main ($) { Line 5730  sub _tree_construction_main ($) {
5730                  } # INSCOPE                  } # INSCOPE
5731                    unless (defined $i) {                    unless (defined $i) {
5732                      !!!cp ('t249');                      !!!cp ('t249');
5733                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5734                                        text => $token->{tag_name}, token => $token);
5735                      ## Ignore the token                      ## Ignore the token
5736                      !!!nack ('t249.1');                      !!!nack ('t249.1');
5737                      !!!next-token;                      !!!next-token;
# Line 5617  sub _tree_construction_main ($) { Line 5754  sub _tree_construction_main ($) {
5754                  } # INSCOPE                  } # INSCOPE
5755                    unless (defined $i) {                    unless (defined $i) {
5756                      !!!cp ('t252');                      !!!cp ('t252');
5757                      !!!parse-error (type => 'unmatched end tag:tr', token => $token);                      !!!parse-error (type => 'unmatched end tag',
5758                                        text => 'tr', token => $token);
5759                      ## Ignore the token                      ## Ignore the token
5760                      !!!nack ('t252.1');                      !!!nack ('t252.1');
5761                      !!!next-token;                      !!!next-token;
# Line 5652  sub _tree_construction_main ($) { Line 5790  sub _tree_construction_main ($) {
5790                } # INSCOPE                } # INSCOPE
5791                unless (defined $i) {                unless (defined $i) {
5792                  !!!cp ('t256');                  !!!cp ('t256');
5793                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5794                                    text => $token->{tag_name}, token => $token);
5795                  ## Ignore the token                  ## Ignore the token
5796                  !!!nack ('t256.1');                  !!!nack ('t256.1');
5797                  !!!next-token;                  !!!next-token;
# Line 5679  sub _tree_construction_main ($) { Line 5818  sub _tree_construction_main ($) {
5818                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
5819                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5820            !!!cp ('t258');            !!!cp ('t258');
5821            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
5822                              text => $token->{tag_name}, token => $token);
5823            ## Ignore the token            ## Ignore the token
5824            !!!nack ('t258.1');            !!!nack ('t258.1');
5825             !!!next-token;             !!!next-token;
5826            next B;            next B;
5827          } else {          } else {
5828            !!!cp ('t259');            !!!cp ('t259');
5829            !!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in table:/',
5830                              text => $token->{tag_name}, token => $token);
5831    
5832            $insert = $insert_to_foster;            $insert = $insert_to_foster;
5833            #            #
# Line 5736  sub _tree_construction_main ($) { Line 5877  sub _tree_construction_main ($) {
5877              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
5878                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
5879                  !!!cp ('t264');                  !!!cp ('t264');
5880                  !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5881                                    text => 'colgroup', token => $token);
5882                  ## Ignore the token                  ## Ignore the token
5883                  !!!next-token;                  !!!next-token;
5884                  next B;                  next B;
# Line 5749  sub _tree_construction_main ($) { Line 5891  sub _tree_construction_main ($) {
5891                }                }
5892              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
5893                !!!cp ('t266');                !!!cp ('t266');
5894                !!!parse-error (type => 'unmatched end tag:col', token => $token);                !!!parse-error (type => 'unmatched end tag',
5895                                  text => 'col', token => $token);
5896                ## Ignore the token                ## Ignore the token
5897                !!!next-token;                !!!next-token;
5898                next B;                next B;
# Line 5779  sub _tree_construction_main ($) { Line 5922  sub _tree_construction_main ($) {
5922            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
5923              !!!cp ('t269');              !!!cp ('t269');
5924  ## TODO: Wrong error type?  ## TODO: Wrong error type?
5925              !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);              !!!parse-error (type => 'unmatched end tag',
5926                                text => 'colgroup', token => $token);
5927              ## Ignore the token              ## Ignore the token
5928              !!!nack ('t269.1');              !!!nack ('t269.1');
5929              !!!next-token;              !!!next-token;
# Line 5833  sub _tree_construction_main ($) { Line 5977  sub _tree_construction_main ($) {
5977            !!!nack ('t277.1');            !!!nack ('t277.1');
5978            !!!next-token;            !!!next-token;
5979            next B;            next B;
5980          } elsif ($token->{tag_name} eq 'select' or          } elsif ({
5981                   $token->{tag_name} eq 'input' or                     select => 1, input => 1, textarea => 1,
5982                     }->{$token->{tag_name}} or
5983                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
5984                    {                    {
5985                     caption => 1, table => 1,                     caption => 1, table => 1,
# Line 5842  sub _tree_construction_main ($) { Line 5987  sub _tree_construction_main ($) {
5987                     tr => 1, td => 1, th => 1,                     tr => 1, td => 1, th => 1,
5988                    }->{$token->{tag_name}})) {                    }->{$token->{tag_name}})) {
5989            ## TODO: The type below is not good - <select> is replaced by </select>            ## TODO: The type below is not good - <select> is replaced by </select>
5990            !!!parse-error (type => 'not closed:select', token => $token);            !!!parse-error (type => 'not closed', text => 'select',
5991                              token => $token);
5992            ## NOTE: As if the token were </select> (<select> case) or            ## NOTE: As if the token were </select> (<select> case) or
5993            ## as if there were </select> (otherwise).            ## as if there were </select> (otherwise).
5994            ## have an element in table scope            ## have an element in table scope
# Line 5860  sub _tree_construction_main ($) { Line 6006  sub _tree_construction_main ($) {
6006            } # INSCOPE            } # INSCOPE
6007            unless (defined $i) {            unless (defined $i) {
6008              !!!cp ('t280');              !!!cp ('t280');
6009              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6010                                text => 'select', token => $token);
6011              ## Ignore the token              ## Ignore the token
6012              !!!nack ('t280.1');              !!!nack ('t280.1');
6013              !!!next-token;              !!!next-token;
# Line 5884  sub _tree_construction_main ($) { Line 6031  sub _tree_construction_main ($) {
6031            }            }
6032          } else {          } else {
6033            !!!cp ('t282');            !!!cp ('t282');
6034            !!!parse-error (type => 'in select:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select',
6035                              text => $token->{tag_name}, token => $token);
6036            ## Ignore the token            ## Ignore the token
6037            !!!nack ('t282.1');            !!!nack ('t282.1');
6038            !!!next-token;            !!!next-token;
# Line 5902  sub _tree_construction_main ($) { Line 6050  sub _tree_construction_main ($) {
6050              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6051            } else {            } else {
6052              !!!cp ('t285');              !!!cp ('t285');
6053              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6054                                text => $token->{tag_name}, token => $token);
6055              ## Ignore the token              ## Ignore the token
6056            }            }
6057            !!!nack ('t285.1');            !!!nack ('t285.1');
# Line 5914  sub _tree_construction_main ($) { Line 6063  sub _tree_construction_main ($) {
6063              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6064            } else {            } else {
6065              !!!cp ('t287');              !!!cp ('t287');
6066              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6067                                text => $token->{tag_name}, token => $token);
6068              ## Ignore the token              ## Ignore the token
6069            }            }
6070            !!!nack ('t287.1');            !!!nack ('t287.1');
# Line 5936  sub _tree_construction_main ($) { Line 6086  sub _tree_construction_main ($) {
6086            } # INSCOPE            } # INSCOPE
6087            unless (defined $i) {            unless (defined $i) {
6088              !!!cp ('t290');              !!!cp ('t290');
6089              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6090                                text => $token->{tag_name}, token => $token);
6091              ## Ignore the token              ## Ignore the token
6092              !!!nack ('t290.1');              !!!nack ('t290.1');
6093              !!!next-token;              !!!next-token;
# Line 5957  sub _tree_construction_main ($) { Line 6108  sub _tree_construction_main ($) {
6108                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
6109                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
6110  ## TODO: The following is wrong?  ## TODO: The following is wrong?
6111            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
6112                              text => $token->{tag_name}, token => $token);
6113                                
6114            ## have an element in table scope            ## have an element in table scope
6115            my $i;            my $i;
# Line 5998  sub _tree_construction_main ($) { Line 6150  sub _tree_construction_main ($) {
6150            unless (defined $i) {            unless (defined $i) {
6151              !!!cp ('t297');              !!!cp ('t297');
6152  ## TODO: The following error type is correct?  ## TODO: The following error type is correct?
6153              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6154                                text => 'select', token => $token);
6155              ## Ignore the </select> token              ## Ignore the </select> token
6156              !!!nack ('t297.1');              !!!nack ('t297.1');
6157              !!!next-token; ## TODO: ok?              !!!next-token; ## TODO: ok?
# Line 6015  sub _tree_construction_main ($) { Line 6168  sub _tree_construction_main ($) {
6168            next B;            next B;
6169          } else {          } else {
6170            !!!cp ('t299');            !!!cp ('t299');
6171            !!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select:/',
6172                              text => $token->{tag_name}, token => $token);
6173            ## Ignore the token            ## Ignore the token
6174            !!!nack ('t299.3');            !!!nack ('t299.3');
6175            !!!next-token;            !!!next-token;
# Line 6053  sub _tree_construction_main ($) { Line 6207  sub _tree_construction_main ($) {
6207                    
6208          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6209            !!!cp ('t301');            !!!cp ('t301');
6210            !!!parse-error (type => 'after html:#character', token => $token);            !!!parse-error (type => 'after html:#text', token => $token);
6211    
6212            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6213          } else {          } else {
# Line 6061  sub _tree_construction_main ($) { Line 6215  sub _tree_construction_main ($) {
6215          }          }
6216                    
6217          ## "after body" insertion mode          ## "after body" insertion mode
6218          !!!parse-error (type => 'after body:#character', token => $token);          !!!parse-error (type => 'after body:#text', token => $token);
6219    
6220          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6221          ## reprocess          ## reprocess
# Line 6069  sub _tree_construction_main ($) { Line 6223  sub _tree_construction_main ($) {
6223        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
6224          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6225            !!!cp ('t303');            !!!cp ('t303');
6226            !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html',
6227                              text => $token->{tag_name}, token => $token);
6228                        
6229            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6230          } else {          } else {
# Line 6077  sub _tree_construction_main ($) { Line 6232  sub _tree_construction_main ($) {
6232          }          }
6233    
6234          ## "after body" insertion mode          ## "after body" insertion mode
6235          !!!parse-error (type => 'after body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'after body',
6236                            text => $token->{tag_name}, token => $token);
6237    
6238          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6239          !!!ack-later;          !!!ack-later;
# Line 6086  sub _tree_construction_main ($) { Line 6242  sub _tree_construction_main ($) {
6242        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6243          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6244            !!!cp ('t305');            !!!cp ('t305');
6245            !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html:/',
6246                              text => $token->{tag_name}, token => $token);
6247                        
6248            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6249            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
# Line 6098  sub _tree_construction_main ($) { Line 6255  sub _tree_construction_main ($) {
6255          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
6256            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
6257              !!!cp ('t307');              !!!cp ('t307');
6258              !!!parse-error (type => 'unmatched end tag:html', token => $token);              !!!parse-error (type => 'unmatched end tag',
6259                                text => 'html', token => $token);
6260              ## Ignore the token              ## Ignore the token
6261              !!!next-token;              !!!next-token;
6262              next B;              next B;
# Line 6110  sub _tree_construction_main ($) { Line 6268  sub _tree_construction_main ($) {
6268            }            }
6269          } else {          } else {
6270            !!!cp ('t309');            !!!cp ('t309');
6271            !!!parse-error (type => 'after body:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after body:/',
6272                              text => $token->{tag_name}, token => $token);
6273    
6274            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
6275            ## reprocess            ## reprocess
# Line 6138  sub _tree_construction_main ($) { Line 6297  sub _tree_construction_main ($) {
6297          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
6298            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6299              !!!cp ('t311');              !!!cp ('t311');
6300              !!!parse-error (type => 'in frameset:#character', token => $token);              !!!parse-error (type => 'in frameset:#text', token => $token);
6301            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6302              !!!cp ('t312');              !!!cp ('t312');
6303              !!!parse-error (type => 'after frameset:#character', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6304            } else { # "after html frameset"            } else { # "after html frameset"
6305              !!!cp ('t313');              !!!cp ('t313');
6306              !!!parse-error (type => 'after html:#character', token => $token);              !!!parse-error (type => 'after html:#text', token => $token);
6307    
6308              $self->{insertion_mode} = AFTER_FRAMESET_IM;              $self->{insertion_mode} = AFTER_FRAMESET_IM;
6309              ## Reprocess in the "after frameset" insertion mode.              ## Reprocess in the "after frameset" insertion mode.
6310              !!!parse-error (type => 'after frameset:#character', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6311            }            }
6312                        
6313            ## Ignore the token.            ## Ignore the token.
# Line 6166  sub _tree_construction_main ($) { Line 6325  sub _tree_construction_main ($) {
6325        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
6326          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
6327            !!!cp ('t316');            !!!cp ('t316');
6328            !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html',
6329                              text => $token->{tag_name}, token => $token);
6330    
6331            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
6332            ## Process in the "after frameset" insertion mode.            ## Process in the "after frameset" insertion mode.
# Line 6191  sub _tree_construction_main ($) { Line 6351  sub _tree_construction_main ($) {
6351            next B;            next B;
6352          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
6353            !!!cp ('t320');            !!!cp ('t320');
6354            ## NOTE: As if in body.            ## NOTE: As if in head.
6355            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
6356            next B;            next B;
6357          } else {          } else {
6358            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6359              !!!cp ('t321');              !!!cp ('t321');
6360              !!!parse-error (type => 'in frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset',
6361                                text => $token->{tag_name}, token => $token);
6362            } else {            } else {
6363              !!!cp ('t322');              !!!cp ('t322');
6364              !!!parse-error (type => 'after frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after frameset',
6365                                text => $token->{tag_name}, token => $token);
6366            }            }
6367            ## Ignore the token            ## Ignore the token
6368            !!!nack ('t322.1');            !!!nack ('t322.1');
# Line 6210  sub _tree_construction_main ($) { Line 6372  sub _tree_construction_main ($) {
6372        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6373          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
6374            !!!cp ('t323');            !!!cp ('t323');
6375            !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html:/',
6376                              text => $token->{tag_name}, token => $token);
6377    
6378            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
6379            ## Process in the "after frameset" insertion mode.            ## Process in the "after frameset" insertion mode.
# Line 6223  sub _tree_construction_main ($) { Line 6386  sub _tree_construction_main ($) {
6386            if ($self->{open_elements}->[-1]->[1] & HTML_EL and            if ($self->{open_elements}->[-1]->[1] & HTML_EL and
6387                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
6388              !!!cp ('t325');              !!!cp ('t325');
6389              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6390                                text => $token->{tag_name}, token => $token);
6391              ## Ignore the token              ## Ignore the token
6392              !!!next-token;              !!!next-token;
6393            } else {            } else {
# Line 6249  sub _tree_construction_main ($) { Line 6413  sub _tree_construction_main ($) {
6413          } else {          } else {
6414            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6415              !!!cp ('t330');              !!!cp ('t330');
6416              !!!parse-error (type => 'in frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset:/',
6417                                text => $token->{tag_name}, token => $token);
6418            } else {            } else {
6419              !!!cp ('t331');              !!!cp ('t331');
6420              !!!parse-error (type => 'after frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after frameset:/',
6421                                text => $token->{tag_name}, token => $token);
6422            }            }
6423            ## Ignore the token            ## Ignore the token
6424            !!!next-token;            !!!next-token;
# Line 6319  sub _tree_construction_main ($) { Line 6485  sub _tree_construction_main ($) {
6485                                           ->{has_reference});                                           ->{has_reference});
6486            } elsif ($token->{attributes}->{content}) {            } elsif ($token->{attributes}->{content}) {
6487              if ($token->{attributes}->{content}->{value}              if ($token->{attributes}->{content}->{value}
6488                  =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                  =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
6489                      [\x09-\x0D\x20]*=                      [\x09-\x0D\x20]*=
6490                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
6491                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
6492                !!!cp ('t336');                !!!cp ('t336');
6493                ## NOTE: Whether the encoding is supported or not is handled                ## NOTE: Whether the encoding is supported or not is handled
6494                ## in the {change_encoding} callback.                ## in the {change_encoding} callback.
# Line 6360  sub _tree_construction_main ($) { Line 6526  sub _tree_construction_main ($) {
6526          $parse_rcdata->(RCDATA_CONTENT_MODEL);          $parse_rcdata->(RCDATA_CONTENT_MODEL);
6527          next B;          next B;
6528        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
6529          !!!parse-error (type => 'in body:body', token => $token);          !!!parse-error (type => 'in body', text => 'body', token => $token);
6530                                
6531          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
6532              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {
# Line 6480  sub _tree_construction_main ($) { Line 6646  sub _tree_construction_main ($) {
6646              if ($i != -1) {              if ($i != -1) {
6647                !!!cp ('t355');                !!!cp ('t355');
6648                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
6649                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
6650                                    ->manakai_local_name,                                    ->manakai_local_name,
6651                                token => $token);                                token => $token);
6652              } else {              } else {
# Line 6634  sub _tree_construction_main ($) { Line 6800  sub _tree_construction_main ($) {
6800                  xmp => 1,                  xmp => 1,
6801                  iframe => 1,                  iframe => 1,
6802                  noembed => 1,                  noembed => 1,
6803                  noframes => 1,                  noframes => 1, ## NOTE: This is an "as if in head" code clone.
6804                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
6805                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6806          if ($token->{tag_name} eq 'xmp') {          if ($token->{tag_name} eq 'xmp') {
# Line 6656  sub _tree_construction_main ($) { Line 6822  sub _tree_construction_main ($) {
6822            !!!next-token;            !!!next-token;
6823            next B;            next B;
6824          } else {          } else {
6825              !!!ack ('t391.1');
6826    
6827            my $at = $token->{attributes};            my $at = $token->{attributes};
6828            my $form_attrs;            my $form_attrs;
6829            $form_attrs->{action} = $at->{action} if $at->{action};            $form_attrs->{action} = $at->{action} if $at->{action};
# Line 6699  sub _tree_construction_main ($) { Line 6867  sub _tree_construction_main ($) {
6867                           line => $token->{line}, column => $token->{column}},                           line => $token->{line}, column => $token->{column}},
6868                          {type => END_TAG_TOKEN, tag_name => 'form',                          {type => END_TAG_TOKEN, tag_name => 'form',
6869                           line => $token->{line}, column => $token->{column}};                           line => $token->{line}, column => $token->{column}};
           !!!nack ('t391.1'); ## NOTE: Not acknowledged.  
6870            !!!back-token (@tokens);            !!!back-token (@tokens);
6871            !!!next-token;            !!!next-token;
6872            next B;            next B;
# Line 6747  sub _tree_construction_main ($) { Line 6914  sub _tree_construction_main ($) {
6914            ## Ignore the token            ## Ignore the token
6915          } else {          } else {
6916            !!!cp ('t398');            !!!cp ('t398');
6917            !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);            !!!parse-error (type => 'in RCDATA:#eof', token => $token);
6918          }          }
6919          !!!next-token;          !!!next-token;
6920          next B;          next B;
6921          } elsif ($token->{tag_name} eq 'rt' or
6922                   $token->{tag_name} eq 'rp') {
6923            ## has a |ruby| element in scope
6924            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6925              my $node = $self->{open_elements}->[$_];
6926              if ($node->[1] & RUBY_EL) {
6927                !!!cp ('t398.1');
6928                ## generate implied end tags
6929                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
6930                  !!!cp ('t398.2');
6931                  pop @{$self->{open_elements}};
6932                }
6933                unless ($self->{open_elements}->[-1]->[1] & RUBY_EL) {
6934                  !!!cp ('t398.3');
6935                  !!!parse-error (type => 'not closed',
6936                                  text => $self->{open_elements}->[-1]->[0]
6937                                      ->manakai_local_name,
6938                                  token => $token);
6939                  pop @{$self->{open_elements}}
6940                      while not $self->{open_elements}->[-1]->[1] & RUBY_EL;
6941                }
6942                last INSCOPE;
6943              } elsif ($node->[1] & SCOPING_EL) {
6944                !!!cp ('t398.4');
6945                last INSCOPE;
6946              }
6947            } # INSCOPE
6948    
6949            !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
6950    
6951            !!!nack ('t398.5');
6952            !!!next-token;
6953            redo B;
6954        } elsif ($token->{tag_name} eq 'math' or        } elsif ($token->{tag_name} eq 'math' or
6955                 $token->{tag_name} eq 'svg') {                 $token->{tag_name} eq 'svg') {
6956          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
6957    
6958            ## "Adjust MathML attributes" ('math' only) - done in insert-element-f
6959    
6960          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f
6961    
6962          ## "adjust foreign attributes" - done in insert-element-f          ## "adjust foreign attributes" - done in insert-element-f
# Line 6781  sub _tree_construction_main ($) { Line 6983  sub _tree_construction_main ($) {
6983                  thead => 1, tr => 1,                  thead => 1, tr => 1,
6984                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6985          !!!cp ('t401');          !!!cp ('t401');
6986          !!!parse-error (type => 'in body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in body',
6987                            text => $token->{tag_name}, token => $token);
6988          ## Ignore the token          ## Ignore the token
6989          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.
6990          !!!next-token;          !!!next-token;
# Line 6866  sub _tree_construction_main ($) { Line 7069  sub _tree_construction_main ($) {
7069            }            }
7070    
7071            !!!parse-error (type => 'start tag not allowed',            !!!parse-error (type => 'start tag not allowed',
7072                            value => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7073            ## NOTE: Ignore the token.            ## NOTE: Ignore the token.
7074            !!!next-token;            !!!next-token;
7075            next B;            next B;
# Line 6876  sub _tree_construction_main ($) { Line 7079  sub _tree_construction_main ($) {
7079            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {
7080              !!!cp ('t403');              !!!cp ('t403');
7081              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7082                              value => $_->[0]->manakai_local_name,                              text => $_->[0]->manakai_local_name,
7083                              token => $token);                              token => $token);
7084              last;              last;
7085            } else {            } else {
# Line 6896  sub _tree_construction_main ($) { Line 7099  sub _tree_construction_main ($) {
7099            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {
7100              !!!cp ('t406');              !!!cp ('t406');
7101              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7102                              value => $self->{open_elements}->[1]->[0]                              text => $self->{open_elements}->[1]->[0]
7103                                  ->manakai_local_name,                                  ->manakai_local_name,
7104                              token => $token);                              token => $token);
7105            } else {            } else {
# Line 6907  sub _tree_construction_main ($) { Line 7110  sub _tree_construction_main ($) {
7110            next B;            next B;
7111          } else {          } else {
7112            !!!cp ('t408');            !!!cp ('t408');
7113            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7114                              text => $token->{tag_name}, token => $token);
7115            ## Ignore the token            ## Ignore the token
7116            !!!next-token;            !!!next-token;
7117            next B;            next B;
# Line 6935  sub _tree_construction_main ($) { Line 7139  sub _tree_construction_main ($) {
7139    
7140          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7141            !!!cp ('t413');            !!!cp ('t413');
7142            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7143                              text => $token->{tag_name}, token => $token);
7144          } else {          } else {
7145            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7146            while ({            while ({
7147                      ## END_TAG_OPTIONAL_EL
7148                    dd => ($token->{tag_name} ne 'dd'),                    dd => ($token->{tag_name} ne 'dd'),
7149                    dt => ($token->{tag_name} ne 'dt'),                    dt => ($token->{tag_name} ne 'dt'),
7150                    li => ($token->{tag_name} ne 'li'),                    li => ($token->{tag_name} ne 'li'),
7151                    p => 1,                    p => 1,
7152                      rt => 1,
7153                      rp => 1,
7154                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {
7155              !!!cp ('t409');              !!!cp ('t409');
7156              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
# Line 6953  sub _tree_construction_main ($) { Line 7161  sub _tree_construction_main ($) {
7161                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7162              !!!cp ('t412');              !!!cp ('t412');
7163              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7164                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7165                                  ->manakai_local_name,                                  ->manakai_local_name,
7166                              token => $token);                              token => $token);
7167            } else {            } else {
# Line 6990  sub _tree_construction_main ($) { Line 7198  sub _tree_construction_main ($) {
7198    
7199          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7200            !!!cp ('t421');            !!!cp ('t421');
7201            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7202                              text => $token->{tag_name}, token => $token);
7203          } else {          } else {
7204            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7205            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7003  sub _tree_construction_main ($) { Line 7212  sub _tree_construction_main ($) {
7212                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7213              !!!cp ('t417.1');              !!!cp ('t417.1');
7214              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7215                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7216                                  ->manakai_local_name,                                  ->manakai_local_name,
7217                              token => $token);                              token => $token);
7218            } else {            } else {
# Line 7035  sub _tree_construction_main ($) { Line 7244  sub _tree_construction_main ($) {
7244    
7245          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7246            !!!cp ('t425.1');            !!!cp ('t425.1');
7247            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7248                              text => $token->{tag_name}, token => $token);
7249          } else {          } else {
7250            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7251            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7047  sub _tree_construction_main ($) { Line 7257  sub _tree_construction_main ($) {
7257            if ($self->{open_elements}->[-1]->[0]->manakai_local_name            if ($self->{open_elements}->[-1]->[0]->manakai_local_name
7258                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7259              !!!cp ('t425');              !!!cp ('t425');
7260              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
7261                                text => $token->{tag_name}, token => $token);
7262            } else {            } else {
7263              !!!cp ('t426');              !!!cp ('t426');
7264            }            }
# Line 7078  sub _tree_construction_main ($) { Line 7289  sub _tree_construction_main ($) {
7289                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7290              !!!cp ('t412.1');              !!!cp ('t412.1');
7291              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7292                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7293                                  ->manakai_local_name,                                  ->manakai_local_name,
7294                              token => $token);                              token => $token);
7295            } else {            } else {
# Line 7088  sub _tree_construction_main ($) { Line 7299  sub _tree_construction_main ($) {
7299            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
7300          } else {          } else {
7301            !!!cp ('t413.1');            !!!cp ('t413.1');
7302            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7303                              text => $token->{tag_name}, token => $token);
7304    
7305            !!!cp ('t415.1');            !!!cp ('t415.1');
7306            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
# Line 7111  sub _tree_construction_main ($) { Line 7323  sub _tree_construction_main ($) {
7323          next B;          next B;
7324        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
7325          !!!cp ('t428');          !!!cp ('t428');
7326          !!!parse-error (type => 'unmatched end tag:br', token => $token);          !!!parse-error (type => 'unmatched end tag',
7327                            text => 'br', token => $token);
7328    
7329          ## As if <br>          ## As if <br>
7330          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
# Line 7136  sub _tree_construction_main ($) { Line 7349  sub _tree_construction_main ($) {
7349                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
7350                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7351          !!!cp ('t429');          !!!cp ('t429');
7352          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'unmatched end tag',
7353                            text => $token->{tag_name}, token => $token);
7354          ## Ignore the token          ## Ignore the token
7355          !!!next-token;          !!!next-token;
7356          next B;          next B;
# Line 7155  sub _tree_construction_main ($) { Line 7369  sub _tree_construction_main ($) {
7369              ## generate implied end tags              ## generate implied end tags
7370              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7371                !!!cp ('t430');                !!!cp ('t430');
7372                ## ISSUE: Can this case be reached?                ## NOTE: |<ruby><rt></ruby>|.
7373                  ## ISSUE: <ruby><rt></rt> will also take this code path,
7374                  ## which seems wrong.
7375                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
7376                  $node_i++;
7377              }              }
7378                    
7379              ## Step 2              ## Step 2
# Line 7165  sub _tree_construction_main ($) { Line 7382  sub _tree_construction_main ($) {
7382                !!!cp ('t431');                !!!cp ('t431');
7383                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
7384                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
7385                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
7386                                    ->manakai_local_name,                                    ->manakai_local_name,
7387                                token => $token);                                token => $token);
7388              } else {              } else {
# Line 7173  sub _tree_construction_main ($) { Line 7390  sub _tree_construction_main ($) {
7390              }              }
7391                            
7392              ## Step 3              ## Step 3
7393              splice @{$self->{open_elements}}, $node_i;              splice @{$self->{open_elements}}, $node_i if $node_i < 0;
7394    
7395              !!!next-token;              !!!next-token;
7396              last S2;              last S2;
# Line 7184  sub _tree_construction_main ($) { Line 7401  sub _tree_construction_main ($) {
7401                  ($node->[1] & SPECIAL_EL or                  ($node->[1] & SPECIAL_EL or
7402                   $node->[1] & SCOPING_EL)) {                   $node->[1] & SCOPING_EL)) {
7403                !!!cp ('t433');                !!!cp ('t433');
7404                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
7405                                  text => $token->{tag_name}, token => $token);
7406                ## Ignore the token                ## Ignore the token
7407                !!!next-token;                !!!next-token;
7408                last S2;                last S2;
# Line 7320  sub set_inner_html ($$$) { Line 7538  sub set_inner_html ($$$) {
7538                  0x10FFFE => 1, 0x10FFFF => 1,                  0x10FFFE => 1, 0x10FFFF => 1,
7539                 }->{$self->{next_char}}) {                 }->{$self->{next_char}}) {
7540          !!!cp ('i4.1');          !!!cp ('i4.1');
7541          !!!parse-error (type => 'control char', level => $self->{must_level});          if ($self->{next_char} < 0x10000) {
7542  ## TODO: error type documentation            !!!parse-error (type => 'control char',
7543                              text => (sprintf 'U+%04X', $self->{next_char}));
7544            } else {
7545              !!!parse-error (type => 'control char',
7546                              text => (sprintf 'U-%08X', $self->{next_char}));
7547            }
7548        }        }
7549      };      };
7550      $p->{prev_char} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];

Legend:
Removed from v.1.139  
changed lines
  Added in v.1.156

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24