/[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.140 by wakaba, Sat May 24 09:59:52 2008 UTC revision 1.160 by wakaba, Wed Sep 10 10:27:08 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 358  sub parse_byte_stream ($$$$;$) { Line 372  sub parse_byte_stream ($$$$;$) {
372    my ($char_stream, $e_status);    my ($char_stream, $e_status);
373    
374    SNIFFING: {    SNIFFING: {
375        ## NOTE: By setting |allow_fallback| option true when the
376        ## |get_decode_handle| method is invoked, we ignore what the HTML5
377        ## spec requires, i.e. unsupported encoding should be ignored.
378          ## TODO: We should not do this unless the parser is invoked
379          ## in the conformance checking mode, in which this behavior
380          ## would be useful.
381    
382      ## Step 1      ## Step 1
383      if (defined $charset_name) {      if (defined $charset_name) {
# Line 429  sub parse_byte_stream ($$$$;$) { Line 449  sub parse_byte_stream ($$$$;$) {
449             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
450        if ($char_stream) {        if ($char_stream) {
451          $buffer->{buffer} = $byte_buffer;          $buffer->{buffer} = $byte_buffer;
452          !!!parse-error (type => 'sniffing:chardet', ## TODO: type name          !!!parse-error (type => 'sniffing:chardet',
453                          value => $charset_name,                          text => $charset_name,
454                          level => $self->{info_level},                          level => $self->{level}->{info},
455                            layer => 'encode',
456                          line => 1, column => 1);                          line => 1, column => 1);
457          $self->{confident} = 0;          $self->{confident} = 0;
458          last SNIFFING;          last SNIFFING;
# Line 452  sub parse_byte_stream ($$$$;$) { Line 473  sub parse_byte_stream ($$$$;$) {
473                                         allow_fallback => 1,                                         allow_fallback => 1,
474                                         byte_buffer => \$byte_buffer);                                         byte_buffer => \$byte_buffer);
475      $buffer->{buffer} = $byte_buffer;      $buffer->{buffer} = $byte_buffer;
476      !!!parse-error (type => 'sniffing:default', ## TODO: type name      !!!parse-error (type => 'sniffing:default',
477                      value => 'windows-1252',                      text => 'windows-1252',
478                      level => $self->{info_level},                      level => $self->{level}->{info},
479                      line => 1, column => 1);                      line => 1, column => 1,
480                        layer => 'encode');
481      $self->{confident} = 0;      $self->{confident} = 0;
482    } # SNIFFING    } # SNIFFING
483    
   $self->{input_encoding} = $charset->get_iana_name;  
484    if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {    if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
485      !!!parse-error (type => 'chardecode:fallback', ## TODO: type name      $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name?
486                      value => $self->{input_encoding},      !!!parse-error (type => 'chardecode:fallback',
487                      level => $self->{unsupported_level},                      #text => $self->{input_encoding},
488                      line => 1, column => 1);                      level => $self->{level}->{uncertain},
489                        line => 1, column => 1,
490                        layer => 'encode');
491    } elsif (not ($e_status &    } elsif (not ($e_status &
492                  Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {                  Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
493      !!!parse-error (type => 'chardecode:no error', ## TODO: type name      $self->{input_encoding} = $charset->get_iana_name;
494                      value => $self->{input_encoding},      !!!parse-error (type => 'chardecode:no error',
495                      level => $self->{unsupported_level},                      text => $self->{input_encoding},
496                      line => 1, column => 1);                      level => $self->{level}->{uncertain},
497                        line => 1, column => 1,
498                        layer => 'encode');
499      } else {
500        $self->{input_encoding} = $charset->get_iana_name;
501    }    }
502    
503    $self->{change_encoding} = sub {    $self->{change_encoding} = sub {
# Line 487  sub parse_byte_stream ($$$$;$) { Line 514  sub parse_byte_stream ($$$$;$) {
514        ## "Change the encoding" algorithm:        ## "Change the encoding" algorithm:
515    
516        ## Step 1            ## Step 1    
517        if ($charset->{iana_names}->{'utf-16'}) { ## ISSUE: UTF-16BE -> UTF-8? UTF-16LE -> UTF-8?        if ($charset->{category} &
518              Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) {
519          $charset = Message::Charset::Info->get_by_iana_name ('utf-8');          $charset = Message::Charset::Info->get_by_iana_name ('utf-8');
520          ($char_stream, $e_status) = $charset->get_decode_handle          ($char_stream, $e_status) = $charset->get_decode_handle
521              ($byte_stream,              ($byte_stream,
# Line 498  sub parse_byte_stream ($$$$;$) { Line 526  sub parse_byte_stream ($$$$;$) {
526        ## Step 2        ## Step 2
527        if (defined $self->{input_encoding} and        if (defined $self->{input_encoding} and
528            $self->{input_encoding} eq $charset_name) {            $self->{input_encoding} eq $charset_name) {
529          !!!parse-error (type => 'charset label:matching', ## TODO: type          !!!parse-error (type => 'charset label:matching',
530                          value => $charset_name,                          text => $charset_name,
531                          level => $self->{info_level});                          level => $self->{level}->{info});
532          $self->{confident} = 1;          $self->{confident} = 1;
533          return;          return;
534        }        }
535    
536        !!!parse-error (type => 'charset label detected:'.$self->{input_encoding}.        !!!parse-error (type => 'charset label detected',
537            ':'.$charset_name, level => 'w', token => $token);                        text => $self->{input_encoding},
538                          value => $charset_name,
539                          level => $self->{level}->{warn},
540                          token => $token);
541                
542        ## Step 3        ## Step 3
543        # if (can) {        # if (can) {
# Line 522  sub parse_byte_stream ($$$$;$) { Line 553  sub parse_byte_stream ($$$$;$) {
553    
554    my $char_onerror = sub {    my $char_onerror = sub {
555      my (undef, $type, %opt) = @_;      my (undef, $type, %opt) = @_;
556      !!!parse-error (%opt, type => $type,      !!!parse-error (layer => 'encode',
557                        %opt, type => $type,
558                      line => $self->{line}, column => $self->{column} + 1);                      line => $self->{line}, column => $self->{column} + 1);
559      if ($opt{octets}) {      if ($opt{octets}) {
560        ${$opt{octets}} = "\x{FFFD}"; # relacement character        ${$opt{octets}} = "\x{FFFD}"; # relacement character
# Line 537  sub parse_byte_stream ($$$$;$) { Line 569  sub parse_byte_stream ($$$$;$) {
569    } catch Whatpm::HTML::RestartParser with {    } catch Whatpm::HTML::RestartParser with {
570      ## NOTE: Invoked after {change_encoding}.      ## NOTE: Invoked after {change_encoding}.
571    
     $self->{input_encoding} = $charset->get_iana_name;  
572      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
573        !!!parse-error (type => 'chardecode:fallback', ## TODO: type name        $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name?
574                        value => $self->{input_encoding},        !!!parse-error (type => 'chardecode:fallback',
575                        level => $self->{unsupported_level},                        level => $self->{level}->{uncertain},
576                        line => 1, column => 1);                        #text => $self->{input_encoding},
577                          line => 1, column => 1,
578                          layer => 'encode');
579      } elsif (not ($e_status &      } elsif (not ($e_status &
580                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
581        !!!parse-error (type => 'chardecode:no error', ## TODO: type name        $self->{input_encoding} = $charset->get_iana_name;
582                        value => $self->{input_encoding},        !!!parse-error (type => 'chardecode:no error',
583                        level => $self->{unsupported_level},                        text => $self->{input_encoding},
584                        line => 1, column => 1);                        level => $self->{level}->{uncertain},
585                          line => 1, column => 1,
586                          layer => 'encode');
587        } else {
588          $self->{input_encoding} = $charset->get_iana_name;
589      }      }
590      $self->{confident} = 1;      $self->{confident} = 1;
591      $char_stream->onerror ($char_onerror);      $char_stream->onerror ($char_onerror);
# Line 647  sub parse_char_stream ($$$;$) { Line 684  sub parse_char_stream ($$$;$) {
684                0x10FFFE => 1, 0x10FFFF => 1,                0x10FFFE => 1, 0x10FFFF => 1,
685               }->{$self->{next_char}}) {               }->{$self->{next_char}}) {
686        !!!cp ('j5');        !!!cp ('j5');
687        !!!parse-error (type => 'control char', level => $self->{must_level});        if ($self->{next_char} < 0x10000) {
688  ## TODO: error type documentation          !!!parse-error (type => 'control char',
689                            text => (sprintf 'U+%04X', $self->{next_char}));
690          } else {
691            !!!parse-error (type => 'control char',
692                            text => (sprintf 'U-%08X', $self->{next_char}));
693          }
694      }      }
695    };    };
696    $self->{prev_char} = [-1, -1, -1];    $self->{prev_char} = [-1, -1, -1];
# Line 677  sub parse_char_stream ($$$;$) { Line 719  sub parse_char_stream ($$$;$) {
719  sub new ($) {  sub new ($) {
720    my $class = shift;    my $class = shift;
721    my $self = bless {    my $self = bless {
722      must_level => 'm',      level => {must => 'm',
723      should_level => 's',                should => 's',
724      good_level => 'w',                warn => 'w',
725      warn_level => 'w',                info => 'i',
726      info_level => 'i',                uncertain => 'u'},
     unsupported_level => 'u',  
727    }, $class;    }, $class;
728    $self->{set_next_char} = sub {    $self->{set_next_char} = sub {
729      $self->{next_char} = -1;      $self->{next_char} = -1;
# Line 829  sub _initialize_tokenizer ($) { Line 870  sub _initialize_tokenizer ($) {
870  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|
871  ##     while the token is pushed back to the stack.  ##     while the token is pushed back to the stack.
872    
 ## 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?  
   
873  ## Emitted token MUST immediately be handled by the tree construction state.  ## Emitted token MUST immediately be handled by the tree construction state.
874    
875  ## 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 1382  sub _get_next_token ($) {
1382          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
1383              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
1384            !!!cp (57);            !!!cp (57);
1385            !!!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});
1386            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{current_attribute} # MUST
1387          } else {          } else {
1388            !!!cp (58);            !!!cp (58);
# Line 1516  sub _get_next_token ($) { Line 1553  sub _get_next_token ($) {
1553    
1554          redo A;          redo A;
1555        } else {        } else {
1556          !!!cp (82);          if ($self->{next_char} == 0x0022 or # "
1557                $self->{next_char} == 0x0027) { # '
1558              !!!cp (78);
1559              !!!parse-error (type => 'bad attribute name');
1560            } else {
1561              !!!cp (82);
1562            }
1563          $self->{current_attribute}          $self->{current_attribute}
1564              = {name => chr ($self->{next_char}),              = {name => chr ($self->{next_char}),
1565                 value => '',                 value => '',
# Line 1551  sub _get_next_token ($) { Line 1594  sub _get_next_token ($) {
1594          !!!next-input-character;          !!!next-input-character;
1595          redo A;          redo A;
1596        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1597            !!!parse-error (type => 'empty unquoted attribute value');
1598          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1599            !!!cp (87);            !!!cp (87);
1600            $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 1871  sub _get_next_token ($) {
1871          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1872          !!!next-input-character;          !!!next-input-character;
1873          redo A;          redo A;
1874          } elsif ($self->{next_char} == -1) {
1875            !!!parse-error (type => 'unclosed tag');
1876            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1877              !!!cp (122.3);
1878              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1879            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1880              if ($self->{current_token}->{attributes}) {
1881                !!!cp (122.1);
1882                !!!parse-error (type => 'end tag attribute');
1883              } else {
1884                ## NOTE: This state should never be reached.
1885                !!!cp (122.2);
1886              }
1887            } else {
1888              die "$0: $self->{current_token}->{type}: Unknown token type";
1889            }
1890            $self->{state} = DATA_STATE;
1891            ## Reconsume.
1892            !!!emit ($self->{current_token}); # start tag or end tag
1893            redo A;
1894        } else {        } else {
1895          !!!cp ('124.1');          !!!cp ('124.1');
1896          !!!parse-error (type => 'no space between attributes');          !!!parse-error (type => 'no space between attributes');
# Line 1859  sub _get_next_token ($) { Line 1923  sub _get_next_token ($) {
1923          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
1924    
1925          redo A;          redo A;
1926          } elsif ($self->{next_char} == -1) {
1927            !!!parse-error (type => 'unclosed tag');
1928            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1929              !!!cp (124.7);
1930              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1931            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1932              if ($self->{current_token}->{attributes}) {
1933                !!!cp (124.5);
1934                !!!parse-error (type => 'end tag attribute');
1935              } else {
1936                ## NOTE: This state should never be reached.
1937                !!!cp (124.6);
1938              }
1939            } else {
1940              die "$0: $self->{current_token}->{type}: Unknown token type";
1941            }
1942            $self->{state} = DATA_STATE;
1943            ## Reconsume.
1944            !!!emit ($self->{current_token}); # start tag or end tag
1945            redo A;
1946        } else {        } else {
1947          !!!cp ('124.4');          !!!cp ('124.4');
1948          !!!parse-error (type => 'nestc');          !!!parse-error (type => 'nestc');
# Line 2616  sub _get_next_token ($) { Line 2700  sub _get_next_token ($) {
2700          redo A;          redo A;
2701        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2702          !!!cp (208);          !!!cp (208);
2703          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2704    
2705          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2706          !!!next-input-character;          !!!next-input-character;
# Line 2652  sub _get_next_token ($) { Line 2736  sub _get_next_token ($) {
2736          redo A;          redo A;
2737        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2738          !!!cp (212);          !!!cp (212);
2739          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2740    
2741          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2742          !!!next-input-character;          !!!next-input-character;
# Line 2700  sub _get_next_token ($) { Line 2784  sub _get_next_token ($) {
2784        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
2785          !!!cp (217);          !!!cp (217);
2786          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
   
2787          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2788          ## reconsume          ## reconsume
2789    
# Line 2862  sub _tokenize_attempt_to_consume_an_enti Line 2945  sub _tokenize_attempt_to_consume_an_enti
2945    
2946          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2947            !!!cp (1008);            !!!cp (1008);
2948            !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
2949                              text => (sprintf 'U+%04X', $code),
2950                              line => $l, column => $c);
2951            $code = 0xFFFD;            $code = 0xFFFD;
2952          } elsif ($code > 0x10FFFF) {          } elsif ($code > 0x10FFFF) {
2953            !!!cp (1009);            !!!cp (1009);
2954            !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
2955                              text => (sprintf 'U-%08X', $code),
2956                              line => $l, column => $c);
2957            $code = 0xFFFD;            $code = 0xFFFD;
2958          } elsif ($code == 0x000D) {          } elsif ($code == 0x000D) {
2959            !!!cp (1010);            !!!cp (1010);
# Line 2874  sub _tokenize_attempt_to_consume_an_enti Line 2961  sub _tokenize_attempt_to_consume_an_enti
2961            $code = 0x000A;            $code = 0x000A;
2962          } elsif (0x80 <= $code and $code <= 0x9F) {          } elsif (0x80 <= $code and $code <= 0x9F) {
2963            !!!cp (1011);            !!!cp (1011);
2964            !!!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);
2965            $code = $c1_entity_char->{$code};            $code = $c1_entity_char->{$code};
2966          }          }
2967    
# Line 2907  sub _tokenize_attempt_to_consume_an_enti Line 2994  sub _tokenize_attempt_to_consume_an_enti
2994    
2995        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2996          !!!cp (1015);          !!!cp (1015);
2997          !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
2998                            text => (sprintf 'U+%04X', $code),
2999                            line => $l, column => $c);
3000          $code = 0xFFFD;          $code = 0xFFFD;
3001        } elsif ($code > 0x10FFFF) {        } elsif ($code > 0x10FFFF) {
3002          !!!cp (1016);          !!!cp (1016);
3003          !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3004                            text => (sprintf 'U-%08X', $code),
3005                            line => $l, column => $c);
3006          $code = 0xFFFD;          $code = 0xFFFD;
3007        } elsif ($code == 0x000D) {        } elsif ($code == 0x000D) {
3008          !!!cp (1017);          !!!cp (1017);
3009          !!!parse-error (type => 'CR character reference', line => $l, column => $c);          !!!parse-error (type => 'CR character reference',
3010                            line => $l, column => $c);
3011          $code = 0x000A;          $code = 0x000A;
3012        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
3013          !!!cp (1018);          !!!cp (1018);
3014          !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'C1 character reference',
3015                            text => (sprintf 'U+%04X', $code),
3016                            line => $l, column => $c);
3017          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
3018        }        }
3019                
# Line 3017  sub _initialize_tree_constructor ($) { Line 3111  sub _initialize_tree_constructor ($) {
3111    ## TODO: Turn mutation events off # MUST    ## TODO: Turn mutation events off # MUST
3112    ## TODO: Turn loose Document option (manakai extension) on    ## TODO: Turn loose Document option (manakai extension) on
3113    $self->{document}->manakai_is_html (1); # MUST    $self->{document}->manakai_is_html (1); # MUST
3114      $self->{document}->set_user_data (manakai_source_line => 1);
3115      $self->{document}->set_user_data (manakai_source_column => 1);
3116  } # _initialize_tree_constructor  } # _initialize_tree_constructor
3117    
3118  sub _terminate_tree_constructor ($) {  sub _terminate_tree_constructor ($) {
# Line 3071  sub _tree_construction_initial ($) { Line 3167  sub _tree_construction_initial ($) {
3167        ## language.        ## language.
3168        my $doctype_name = $token->{name};        my $doctype_name = $token->{name};
3169        $doctype_name = '' unless defined $doctype_name;        $doctype_name = '' unless defined $doctype_name;
3170        $doctype_name =~ tr/a-z/A-Z/;        $doctype_name =~ tr/a-z/A-Z/; # ASCII case-insensitive
3171        if (not defined $token->{name} or # <!DOCTYPE>        if (not defined $token->{name} or # <!DOCTYPE>
           defined $token->{public_identifier} or  
3172            defined $token->{system_identifier}) {            defined $token->{system_identifier}) {
3173          !!!cp ('t1');          !!!cp ('t1');
3174          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3175        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
3176          !!!cp ('t2');          !!!cp ('t2');
         ## ISSUE: ASCII case-insensitive? (in fact it does not matter)  
3177          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3178          } elsif (defined $token->{public_identifier}) {
3179            if ($token->{public_identifier} eq 'XSLT-compat') {
3180              !!!cp ('t1.2');
3181              !!!parse-error (type => 'XSLT-compat', token => $token,
3182                              level => $self->{level}->{should});
3183            } else {
3184              !!!parse-error (type => 'not HTML5', token => $token);
3185            }
3186        } else {        } else {
3187          !!!cp ('t3');          !!!cp ('t3');
3188            #
3189        }        }
3190                
3191        my $doctype = $self->{document}->create_document_type_definition        my $doctype = $self->{document}->create_document_type_definition
# Line 3103  sub _tree_construction_initial ($) { Line 3206  sub _tree_construction_initial ($) {
3206        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{public_identifier}) {
3207          my $pubid = $token->{public_identifier};          my $pubid = $token->{public_identifier};
3208          $pubid =~ tr/a-z/A-z/;          $pubid =~ tr/a-z/A-z/;
3209          if ({          my $prefix = [
3210            "+//SILMARIL//DTD HTML PRO V0R11 19970101//EN" => 1,            "+//SILMARIL//DTD HTML PRO V0R11 19970101//",
3211            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3212            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3213            "-//IETF//DTD HTML 2.0 LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 1//",
3214            "-//IETF//DTD HTML 2.0 LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 2//",
3215            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//",
3216            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//",
3217            "-//IETF//DTD HTML 2.0 STRICT//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT//",
3218            "-//IETF//DTD HTML 2.0//EN" => 1,            "-//IETF//DTD HTML 2.0//",
3219            "-//IETF//DTD HTML 2.1E//EN" => 1,            "-//IETF//DTD HTML 2.1E//",
3220            "-//IETF//DTD HTML 3.0//EN" => 1,            "-//IETF//DTD HTML 3.0//",
3221            "-//IETF//DTD HTML 3.0//EN//" => 1,            "-//IETF//DTD HTML 3.2 FINAL//",
3222            "-//IETF//DTD HTML 3.2 FINAL//EN" => 1,            "-//IETF//DTD HTML 3.2//",
3223            "-//IETF//DTD HTML 3.2//EN" => 1,            "-//IETF//DTD HTML 3//",
3224            "-//IETF//DTD HTML 3//EN" => 1,            "-//IETF//DTD HTML LEVEL 0//",
3225            "-//IETF//DTD HTML LEVEL 0//EN" => 1,            "-//IETF//DTD HTML LEVEL 1//",
3226            "-//IETF//DTD HTML LEVEL 0//EN//2.0" => 1,            "-//IETF//DTD HTML LEVEL 2//",
3227            "-//IETF//DTD HTML LEVEL 1//EN" => 1,            "-//IETF//DTD HTML LEVEL 3//",
3228            "-//IETF//DTD HTML LEVEL 1//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 0//",
3229            "-//IETF//DTD HTML LEVEL 2//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 1//",
3230            "-//IETF//DTD HTML LEVEL 2//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 2//",
3231            "-//IETF//DTD HTML LEVEL 3//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 3//",
3232            "-//IETF//DTD HTML LEVEL 3//EN//3.0" => 1,            "-//IETF//DTD HTML STRICT//",
3233            "-//IETF//DTD HTML STRICT LEVEL 0//EN" => 1,            "-//IETF//DTD HTML//",
3234            "-//IETF//DTD HTML STRICT LEVEL 0//EN//2.0" => 1,            "-//METRIUS//DTD METRIUS PRESENTATIONAL//",
3235            "-//IETF//DTD HTML STRICT LEVEL 1//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//",
3236            "-//IETF//DTD HTML STRICT LEVEL 1//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//",
3237            "-//IETF//DTD HTML STRICT LEVEL 2//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//",
3238            "-//IETF//DTD HTML STRICT LEVEL 2//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//",
3239            "-//IETF//DTD HTML STRICT LEVEL 3//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//",
3240            "-//IETF//DTD HTML STRICT LEVEL 3//EN//3.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//",
3241            "-//IETF//DTD HTML STRICT//EN" => 1,            "-//NETSCAPE COMM. CORP.//DTD HTML//",
3242            "-//IETF//DTD HTML STRICT//EN//2.0" => 1,            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//",
3243            "-//IETF//DTD HTML STRICT//EN//3.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//",
3244            "-//IETF//DTD HTML//EN" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//",
3245            "-//IETF//DTD HTML//EN//2.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//",
3246            "-//IETF//DTD HTML//EN//3.0" => 1,            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//",
3247            "-//METRIUS//DTD METRIUS PRESENTATIONAL//EN" => 1,            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//",
3248            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//EN" => 1,            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//",
3249            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//EN" => 1,            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//",
3250            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//",
3251            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//",
3252            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//EN" => 1,            "-//W3C//DTD HTML 3 1995-03-24//",
3253            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//EN" => 1,            "-//W3C//DTD HTML 3.2 DRAFT//",
3254            "-//NETSCAPE COMM. CORP.//DTD HTML//EN" => 1,            "-//W3C//DTD HTML 3.2 FINAL//",
3255            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//EN" => 1,            "-//W3C//DTD HTML 3.2//",
3256            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//EN" => 1,            "-//W3C//DTD HTML 3.2S DRAFT//",
3257            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 FRAMESET//",
3258            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 TRANSITIONAL//",
3259            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMETNAL 19960712//",
3260            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMENTAL 970421//",
3261            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//EN" => 1,            "-//W3C//DTD W3 HTML//",
3262            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//EN" => 1,            "-//W3O//DTD W3 HTML 3.0//",
3263            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML 2.0//",
3264            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML//",
3265            "-//W3C//DTD HTML 3 1995-03-24//EN" => 1,          ]; # $prefix
3266            "-//W3C//DTD HTML 3.2 DRAFT//EN" => 1,          my $match;
3267            "-//W3C//DTD HTML 3.2 FINAL//EN" => 1,          for (@$prefix) {
3268            "-//W3C//DTD HTML 3.2//EN" => 1,            if (substr ($prefix, 0, length $_) eq $_) {
3269            "-//W3C//DTD HTML 3.2S DRAFT//EN" => 1,              $match = 1;
3270            "-//W3C//DTD HTML 4.0 FRAMESET//EN" => 1,              last;
3271            "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN" => 1,            }
3272            "-//W3C//DTD HTML EXPERIMETNAL 19960712//EN" => 1,          }
3273            "-//W3C//DTD HTML EXPERIMENTAL 970421//EN" => 1,          if ($match or
3274            "-//W3C//DTD W3 HTML//EN" => 1,              $pubid eq "-//W3O//DTD W3 HTML STRICT 3.0//EN//" or
3275            "-//W3O//DTD W3 HTML 3.0//EN" => 1,              $pubid eq "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" or
3276            "-//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}) {  
3277            !!!cp ('t5');            !!!cp ('t5');
3278            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3279          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD HTML 4.01 FRAMESET//] or
3280                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD HTML 4.01 TRANSITIONAL//]) {
3281            if (defined $token->{system_identifier}) {            if (defined $token->{system_identifier}) {
3282              !!!cp ('t6');              !!!cp ('t6');
3283              $self->{document}->manakai_compat_mode ('quirks');              $self->{document}->manakai_compat_mode ('quirks');
# Line 3188  sub _tree_construction_initial ($) { Line 3285  sub _tree_construction_initial ($) {
3285              !!!cp ('t7');              !!!cp ('t7');
3286              $self->{document}->manakai_compat_mode ('limited quirks');              $self->{document}->manakai_compat_mode ('limited quirks');
3287            }            }
3288          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD XHTML 1.0 FRAMESET//] or
3289                   $pubid eq "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD XHTML 1.0 TRANSITIONAL//]) {
3290            !!!cp ('t8');            !!!cp ('t8');
3291            $self->{document}->manakai_compat_mode ('limited quirks');            $self->{document}->manakai_compat_mode ('limited quirks');
3292          } else {          } else {
# Line 3202  sub _tree_construction_initial ($) { Line 3299  sub _tree_construction_initial ($) {
3299          my $sysid = $token->{system_identifier};          my $sysid = $token->{system_identifier};
3300          $sysid =~ tr/A-Z/a-z/;          $sysid =~ tr/A-Z/a-z/;
3301          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") {
3302            ## TODO: Check the spec: PUBLIC "(limited quirks)" "(quirks)"            ## NOTE: Ensure that |PUBLIC "(limited quirks)" "(quirks)"| is
3303              ## marked as quirks.
3304            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3305            !!!cp ('t11');            !!!cp ('t11');
3306          } else {          } else {
# Line 3388  sub _reset_insertion_mode ($) { Line 3486  sub _reset_insertion_mode ($) {
3486          ## NOTE: Strictly spaking, the line below only applies to MathML and          ## NOTE: Strictly spaking, the line below only applies to MathML and
3487          ## SVG elements.  Currently the HTML syntax supports only MathML and          ## SVG elements.  Currently the HTML syntax supports only MathML and
3488          ## SVG elements as foreigners.          ## SVG elements as foreigners.
3489          $new_mode = $self->{insertion_mode} | IN_FOREIGN_CONTENT_IM;          $new_mode = IN_BODY_IM | IN_FOREIGN_CONTENT_IM;
         ## ISSUE: What is set as the secondary insertion mode?  
3490        } elsif ($node->[1] & TABLE_CELL_EL) {        } elsif ($node->[1] & TABLE_CELL_EL) {
3491          if ($last) {          if ($last) {
3492            !!!cp ('t28.2');            !!!cp ('t28.2');
# Line 3590  sub _tree_construction_main ($) { Line 3687  sub _tree_construction_main ($) {
3687        ## NOTE: An end-of-file token.        ## NOTE: An end-of-file token.
3688        if ($content_model_flag == CDATA_CONTENT_MODEL) {        if ($content_model_flag == CDATA_CONTENT_MODEL) {
3689          !!!cp ('t43');          !!!cp ('t43');
3690          !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in CDATA:#eof', token => $token);
3691        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
3692          !!!cp ('t44');          !!!cp ('t44');
3693          !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in RCDATA:#eof', token => $token);
3694        } else {        } else {
3695          die "$0: $content_model_flag in parse_rcdata";          die "$0: $content_model_flag in parse_rcdata";
3696        }        }
# Line 3630  sub _tree_construction_main ($) { Line 3727  sub _tree_construction_main ($) {
3727        ## Ignore the token        ## Ignore the token
3728      } else {      } else {
3729        !!!cp ('t48');        !!!cp ('t48');
3730        !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);        !!!parse-error (type => 'in CDATA:#eof', token => $token);
3731        ## ISSUE: And ignore?        ## ISSUE: And ignore?
3732        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
3733      }      }
# Line 3681  sub _tree_construction_main ($) { Line 3778  sub _tree_construction_main ($) {
3778        } # AFE        } # AFE
3779        unless (defined $formatting_element) {        unless (defined $formatting_element) {
3780          !!!cp ('t53');          !!!cp ('t53');
3781          !!!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);
3782          ## Ignore the token          ## Ignore the token
3783          !!!next-token;          !!!next-token;
3784          return;          return;
# Line 3698  sub _tree_construction_main ($) { Line 3795  sub _tree_construction_main ($) {
3795              last INSCOPE;              last INSCOPE;
3796            } else { # in open elements but not in scope            } else { # in open elements but not in scope
3797              !!!cp ('t55');              !!!cp ('t55');
3798              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},              !!!parse-error (type => 'unmatched end tag',
3799                                text => $token->{tag_name},
3800                              token => $end_tag_token);                              token => $end_tag_token);
3801              ## Ignore the token              ## Ignore the token
3802              !!!next-token;              !!!next-token;
# Line 3711  sub _tree_construction_main ($) { Line 3809  sub _tree_construction_main ($) {
3809        } # INSCOPE        } # INSCOPE
3810        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
3811          !!!cp ('t57');          !!!cp ('t57');
3812          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},          !!!parse-error (type => 'unmatched end tag',
3813                            text => $token->{tag_name},
3814                          token => $end_tag_token);                          token => $end_tag_token);
3815          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
3816          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
# Line 3720  sub _tree_construction_main ($) { Line 3819  sub _tree_construction_main ($) {
3819        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
3820          !!!cp ('t58');          !!!cp ('t58');
3821          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
3822                          value => $self->{open_elements}->[-1]->[0]                          text => $self->{open_elements}->[-1]->[0]
3823                              ->manakai_local_name,                              ->manakai_local_name,
3824                          token => $end_tag_token);                          token => $end_tag_token);
3825        }        }
# Line 3929  sub _tree_construction_main ($) { Line 4028  sub _tree_construction_main ($) {
4028    B: while (1) {    B: while (1) {
4029      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
4030        !!!cp ('t73');        !!!cp ('t73');
4031        !!!parse-error (type => 'DOCTYPE in the middle', token => $token);        !!!parse-error (type => 'in html:#DOCTYPE', token => $token);
4032        ## Ignore the token        ## Ignore the token
4033        ## Stay in the phase        ## Stay in the phase
4034        !!!next-token;        !!!next-token;
# Line 3938  sub _tree_construction_main ($) { Line 4037  sub _tree_construction_main ($) {
4037               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
4038        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
4039          !!!cp ('t79');          !!!cp ('t79');
4040          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4041          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
4042        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
4043          !!!cp ('t80');          !!!cp ('t80');
4044          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4045          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
4046        } else {        } else {
4047          !!!cp ('t81');          !!!cp ('t81');
# Line 3993  sub _tree_construction_main ($) { Line 4092  sub _tree_construction_main ($) {
4092            #            #
4093          } elsif ({          } elsif ({
4094                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,
4095                    center => 1, code => 1, dd => 1, div => 1, dl => 1, em => 1,                    center => 1, code => 1, dd => 1, div => 1, dl => 1, dt => 1,
4096                    embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1, ## No h4!                    em => 1, embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1,
4097                    h5 => 1, h6 => 1, head => 1, hr => 1, i => 1, img => 1,                    h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, i => 1,
4098                    li => 1, menu => 1, meta => 1, nobr => 1, p => 1, pre => 1,                    img => 1, li => 1, listing => 1, menu => 1, meta => 1,
4099                    ruby => 1, s => 1, small => 1, span => 1, strong => 1,                    nobr => 1, ol => 1, p => 1, pre => 1, ruby => 1, s => 1,
4100                    sub => 1, sup => 1, table => 1, tt => 1, u => 1, ul => 1,                    small => 1, span => 1, strong => 1, strike => 1, sub => 1,
4101                    var => 1,                    sup => 1, table => 1, tt => 1, u => 1, ul => 1, var => 1,
4102                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
4103            !!!cp ('t87.2');            !!!cp ('t87.2');
4104            !!!parse-error (type => 'not closed',            !!!parse-error (type => 'not closed',
4105                            value => $self->{open_elements}->[-1]->[0]                            text => $self->{open_elements}->[-1]->[0]
4106                                ->manakai_local_name,                                ->manakai_local_name,
4107                            token => $token);                            token => $token);
4108    
# Line 4079  sub _tree_construction_main ($) { Line 4178  sub _tree_construction_main ($) {
4178          !!!cp ('t87.5');          !!!cp ('t87.5');
4179          #          #
4180        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
         ## NOTE: "using the rules for secondary insertion mode" then "continue"  
4181          !!!cp ('t87.6');          !!!cp ('t87.6');
4182          #          !!!parse-error (type => 'not closed',
4183          ## TODO: ...                          text => $self->{open_elements}->[-1]->[0]
4184                                ->manakai_local_name,
4185                            token => $token);
4186    
4187            pop @{$self->{open_elements}}
4188                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;
4189    
4190            $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
4191            ## Reprocess.
4192            next B;
4193        } else {        } else {
4194          die "$0: $token->{type}: Unknown token type";                  die "$0: $token->{type}: Unknown token type";        
4195        }        }
# Line 4123  sub _tree_construction_main ($) { Line 4230  sub _tree_construction_main ($) {
4230            !!!cp ('t90');            !!!cp ('t90');
4231            ## As if </noscript>            ## As if </noscript>
4232            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
4233            !!!parse-error (type => 'in noscript:#character', token => $token);            !!!parse-error (type => 'in noscript:#text', token => $token);
4234                        
4235            ## Reprocess in the "in head" insertion mode...            ## Reprocess in the "in head" insertion mode...
4236            ## As if </head>            ## As if </head>
# Line 4160  sub _tree_construction_main ($) { Line 4267  sub _tree_construction_main ($) {
4267              next B;              next B;
4268            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4269              !!!cp ('t93.2');              !!!cp ('t93.2');
4270              !!!parse-error (type => 'after head:head', token => $token); ## TODO: error type              !!!parse-error (type => 'after head', text => 'head',
4271                                token => $token);
4272              ## Ignore the token              ## Ignore the token
4273              !!!nack ('t93.3');              !!!nack ('t93.3');
4274              !!!next-token;              !!!next-token;
4275              next B;              next B;
4276            } else {            } else {
4277              !!!cp ('t95');              !!!cp ('t95');
4278              !!!parse-error (type => 'in head:head', token => $token); # or in head noscript              !!!parse-error (type => 'in head:head',
4279                                token => $token); # or in head noscript
4280              ## Ignore the token              ## Ignore the token
4281              !!!nack ('t95.1');              !!!nack ('t95.1');
4282              !!!next-token;              !!!next-token;
# Line 4192  sub _tree_construction_main ($) { Line 4301  sub _tree_construction_main ($) {
4301                  !!!cp ('t98');                  !!!cp ('t98');
4302                  ## As if </noscript>                  ## As if </noscript>
4303                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4304                  !!!parse-error (type => 'in noscript:base', token => $token);                  !!!parse-error (type => 'in noscript', text => 'base',
4305                                    token => $token);
4306                                
4307                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4308                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
# Line 4203  sub _tree_construction_main ($) { Line 4313  sub _tree_construction_main ($) {
4313                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4314                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4315                  !!!cp ('t100');                  !!!cp ('t100');
4316                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4317                                    text => $token->{tag_name}, token => $token);
4318                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4319                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4320                } else {                } else {
# Line 4220  sub _tree_construction_main ($) { Line 4331  sub _tree_construction_main ($) {
4331                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4332                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4333                  !!!cp ('t102');                  !!!cp ('t102');
4334                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4335                                    text => $token->{tag_name}, token => $token);
4336                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4337                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4338                } else {                } else {
# Line 4237  sub _tree_construction_main ($) { Line 4349  sub _tree_construction_main ($) {
4349                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4350                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4351                  !!!cp ('t104');                  !!!cp ('t104');
4352                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4353                                    text => $token->{tag_name}, token => $token);
4354                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4355                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4356                } else {                } else {
# Line 4261  sub _tree_construction_main ($) { Line 4374  sub _tree_construction_main ($) {
4374                                                 ->{has_reference});                                                 ->{has_reference});
4375                  } elsif ($token->{attributes}->{content}) {                  } elsif ($token->{attributes}->{content}) {
4376                    if ($token->{attributes}->{content}->{value}                    if ($token->{attributes}->{content}->{value}
4377                        =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                        =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
4378                            [\x09-\x0D\x20]*=                            [\x09-\x0D\x20]*=
4379                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
4380                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
4381                      !!!cp ('t107');                      !!!cp ('t107');
4382                      ## NOTE: Whether the encoding is supported or not is handled                      ## NOTE: Whether the encoding is supported or not is handled
4383                      ## in the {change_encoding} callback.                      ## in the {change_encoding} callback.
# Line 4306  sub _tree_construction_main ($) { Line 4419  sub _tree_construction_main ($) {
4419                  !!!cp ('t111');                  !!!cp ('t111');
4420                  ## As if </noscript>                  ## As if </noscript>
4421                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4422                  !!!parse-error (type => 'in noscript:title', token => $token);                  !!!parse-error (type => 'in noscript', text => 'title',
4423                                    token => $token);
4424                                
4425                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4426                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4427                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4428                  !!!cp ('t112');                  !!!cp ('t112');
4429                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4430                                    text => $token->{tag_name}, token => $token);
4431                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4432                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4433                } else {                } else {
# Line 4326  sub _tree_construction_main ($) { Line 4441  sub _tree_construction_main ($) {
4441                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4442                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4443                next B;                next B;
4444              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style' or
4445                         $token->{tag_name} eq 'noframes') {
4446                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and
4447                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
4448                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4449                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4450                  !!!cp ('t114');                  !!!cp ('t114');
4451                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4452                                    text => $token->{tag_name}, token => $token);
4453                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4454                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4455                } else {                } else {
# Line 4353  sub _tree_construction_main ($) { Line 4470  sub _tree_construction_main ($) {
4470                  next B;                  next B;
4471                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4472                  !!!cp ('t117');                  !!!cp ('t117');
4473                  !!!parse-error (type => 'in noscript:noscript', token => $token);                  !!!parse-error (type => 'in noscript', text => 'noscript',
4474                                    token => $token);
4475                  ## Ignore the token                  ## Ignore the token
4476                  !!!nack ('t117.1');                  !!!nack ('t117.1');
4477                  !!!next-token;                  !!!next-token;
# Line 4367  sub _tree_construction_main ($) { Line 4485  sub _tree_construction_main ($) {
4485                  !!!cp ('t119');                  !!!cp ('t119');
4486                  ## As if </noscript>                  ## As if </noscript>
4487                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4488                  !!!parse-error (type => 'in noscript:script', token => $token);                  !!!parse-error (type => 'in noscript', text => 'script',
4489                                    token => $token);
4490                                
4491                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4492                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4493                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4494                  !!!cp ('t120');                  !!!cp ('t120');
4495                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4496                                    text => $token->{tag_name}, token => $token);
4497                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4498                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4499                } else {                } else {
# Line 4391  sub _tree_construction_main ($) { Line 4511  sub _tree_construction_main ($) {
4511                  !!!cp ('t122');                  !!!cp ('t122');
4512                  ## As if </noscript>                  ## As if </noscript>
4513                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4514                  !!!parse-error (type => 'in noscript:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in noscript',
4515                                    text => $token->{tag_name}, token => $token);
4516                                    
4517                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4518                  ## As if </head>                  ## As if </head>
# Line 4430  sub _tree_construction_main ($) { Line 4551  sub _tree_construction_main ($) {
4551                !!!cp ('t129');                !!!cp ('t129');
4552                ## As if </noscript>                ## As if </noscript>
4553                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4554                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4555                                  text => $token->{tag_name}, token => $token);
4556                                
4557                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4558                ## As if </head>                ## As if </head>
# Line 4473  sub _tree_construction_main ($) { Line 4595  sub _tree_construction_main ($) {
4595                  !!!cp ('t133');                  !!!cp ('t133');
4596                  ## As if </noscript>                  ## As if </noscript>
4597                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4598                  !!!parse-error (type => 'in noscript:/head', token => $token);                  !!!parse-error (type => 'in noscript:/',
4599                                    text => 'head', token => $token);
4600                                    
4601                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4602                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 4488  sub _tree_construction_main ($) { Line 4611  sub _tree_construction_main ($) {
4611                  next B;                  next B;
4612                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4613                  !!!cp ('t134.1');                  !!!cp ('t134.1');
4614                  !!!parse-error (type => 'unmatched end tag:head', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'head',
4615                                    token => $token);
4616                  ## Ignore the token                  ## Ignore the token
4617                  !!!next-token;                  !!!next-token;
4618                  next B;                  next B;
# Line 4505  sub _tree_construction_main ($) { Line 4629  sub _tree_construction_main ($) {
4629                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or
4630                         $self->{insertion_mode} == AFTER_HEAD_IM) {                         $self->{insertion_mode} == AFTER_HEAD_IM) {
4631                  !!!cp ('t137');                  !!!cp ('t137');
4632                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4633                                    text => 'noscript', token => $token);
4634                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
4635                  !!!next-token;                  !!!next-token;
4636                  next B;                  next B;
# Line 4520  sub _tree_construction_main ($) { Line 4645  sub _tree_construction_main ($) {
4645                    $self->{insertion_mode} == IN_HEAD_IM or                    $self->{insertion_mode} == IN_HEAD_IM or
4646                    $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                    $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4647                  !!!cp ('t140');                  !!!cp ('t140');
4648                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4649                                    text => $token->{tag_name}, token => $token);
4650                  ## Ignore the token                  ## Ignore the token
4651                  !!!next-token;                  !!!next-token;
4652                  next B;                  next B;
4653                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4654                  !!!cp ('t140.1');                  !!!cp ('t140.1');
4655                  !!!parse-error (type => 'unmatched end tag:' . $token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4656                                    text => $token->{tag_name}, token => $token);
4657                  ## Ignore the token                  ## Ignore the token
4658                  !!!next-token;                  !!!next-token;
4659                  next B;                  next B;
# Line 4535  sub _tree_construction_main ($) { Line 4662  sub _tree_construction_main ($) {
4662                }                }
4663              } elsif ($token->{tag_name} eq 'p') {              } elsif ($token->{tag_name} eq 'p') {
4664                !!!cp ('t142');                !!!cp ('t142');
4665                !!!parse-error (type => 'unmatched end tag:p', token => $token);                !!!parse-error (type => 'unmatched end tag',
4666                                  text => $token->{tag_name}, token => $token);
4667                ## Ignore the token                ## Ignore the token
4668                !!!next-token;                !!!next-token;
4669                next B;                next B;
# Line 4558  sub _tree_construction_main ($) { Line 4686  sub _tree_construction_main ($) {
4686                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4687                  !!!cp ('t143.3');                  !!!cp ('t143.3');
4688                  ## ISSUE: Two parse errors for <head><noscript></br>                  ## ISSUE: Two parse errors for <head><noscript></br>
4689                  !!!parse-error (type => 'unmatched end tag:br', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4690                                    text => 'br', token => $token);
4691                  ## As if </noscript>                  ## As if </noscript>
4692                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4693                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
# Line 4577  sub _tree_construction_main ($) { Line 4706  sub _tree_construction_main ($) {
4706                }                }
4707    
4708                ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.                ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.
4709                !!!parse-error (type => 'unmatched end tag:br', token => $token);                !!!parse-error (type => 'unmatched end tag',
4710                                  text => 'br', token => $token);
4711                ## Ignore the token                ## Ignore the token
4712                !!!next-token;                !!!next-token;
4713                next B;                next B;
4714              } else {              } else {
4715                !!!cp ('t145');                !!!cp ('t145');
4716                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
4717                                  text => $token->{tag_name}, token => $token);
4718                ## Ignore the token                ## Ignore the token
4719                !!!next-token;                !!!next-token;
4720                next B;                next B;
# Line 4593  sub _tree_construction_main ($) { Line 4724  sub _tree_construction_main ($) {
4724                !!!cp ('t146');                !!!cp ('t146');
4725                ## As if </noscript>                ## As if </noscript>
4726                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4727                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4728                                  text => $token->{tag_name}, token => $token);
4729                                
4730                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4731                ## As if </head>                ## As if </head>
# Line 4609  sub _tree_construction_main ($) { Line 4741  sub _tree_construction_main ($) {
4741              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4742  ## ISSUE: This case cannot be reached?  ## ISSUE: This case cannot be reached?
4743                !!!cp ('t148');                !!!cp ('t148');
4744                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
4745                                  text => $token->{tag_name}, token => $token);
4746                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
4747                !!!next-token;                !!!next-token;
4748                next B;                next B;
# Line 4720  sub _tree_construction_main ($) { Line 4853  sub _tree_construction_main ($) {
4853    
4854                  !!!cp ('t153');                  !!!cp ('t153');
4855                  !!!parse-error (type => 'start tag not allowed',                  !!!parse-error (type => 'start tag not allowed',
4856                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
4857                  ## Ignore the token                  ## Ignore the token
4858                  !!!nack ('t153.1');                  !!!nack ('t153.1');
4859                  !!!next-token;                  !!!next-token;
4860                  next B;                  next B;
4861                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4862                  !!!parse-error (type => 'not closed:caption', token => $token);                  !!!parse-error (type => 'not closed', text => 'caption',
4863                                    token => $token);
4864                                    
4865                  ## NOTE: As if </caption>.                  ## NOTE: As if </caption>.
4866                  ## have a table element in table scope                  ## have a table element in table scope
# Line 4746  sub _tree_construction_main ($) { Line 4880  sub _tree_construction_main ($) {
4880    
4881                    !!!cp ('t157');                    !!!cp ('t157');
4882                    !!!parse-error (type => 'start tag not allowed',                    !!!parse-error (type => 'start tag not allowed',
4883                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
4884                    ## Ignore the token                    ## Ignore the token
4885                    !!!nack ('t157.1');                    !!!nack ('t157.1');
4886                    !!!next-token;                    !!!next-token;
# Line 4763  sub _tree_construction_main ($) { Line 4897  sub _tree_construction_main ($) {
4897                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
4898                    !!!cp ('t159');                    !!!cp ('t159');
4899                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
4900                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
4901                                        ->manakai_local_name,                                        ->manakai_local_name,
4902                                    token => $token);                                    token => $token);
4903                  } else {                  } else {
# Line 4805  sub _tree_construction_main ($) { Line 4939  sub _tree_construction_main ($) {
4939                  } # INSCOPE                  } # INSCOPE
4940                    unless (defined $i) {                    unless (defined $i) {
4941                      !!!cp ('t165');                      !!!cp ('t165');
4942                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
4943                                        text => $token->{tag_name},
4944                                        token => $token);
4945                      ## Ignore the token                      ## Ignore the token
4946                      !!!next-token;                      !!!next-token;
4947                      next B;                      next B;
# Line 4822  sub _tree_construction_main ($) { Line 4958  sub _tree_construction_main ($) {
4958                          ne $token->{tag_name}) {                          ne $token->{tag_name}) {
4959                    !!!cp ('t167');                    !!!cp ('t167');
4960                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
4961                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
4962                                        ->manakai_local_name,                                        ->manakai_local_name,
4963                                    token => $token);                                    token => $token);
4964                  } else {                  } else {
# Line 4839  sub _tree_construction_main ($) { Line 4975  sub _tree_construction_main ($) {
4975                  next B;                  next B;
4976                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4977                  !!!cp ('t169');                  !!!cp ('t169');
4978                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4979                                    text => $token->{tag_name}, token => $token);
4980                  ## Ignore the token                  ## Ignore the token
4981                  !!!next-token;                  !!!next-token;
4982                  next B;                  next B;
# Line 4866  sub _tree_construction_main ($) { Line 5003  sub _tree_construction_main ($) {
5003    
5004                    !!!cp ('t173');                    !!!cp ('t173');
5005                    !!!parse-error (type => 'unmatched end tag',                    !!!parse-error (type => 'unmatched end tag',
5006                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
5007                    ## Ignore the token                    ## Ignore the token
5008                    !!!next-token;                    !!!next-token;
5009                    next B;                    next B;
# Line 4882  sub _tree_construction_main ($) { Line 5019  sub _tree_construction_main ($) {
5019                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5020                    !!!cp ('t175');                    !!!cp ('t175');
5021                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5022                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5023                                        ->manakai_local_name,                                        ->manakai_local_name,
5024                                    token => $token);                                    token => $token);
5025                  } else {                  } else {
# Line 4899  sub _tree_construction_main ($) { Line 5036  sub _tree_construction_main ($) {
5036                  next B;                  next B;
5037                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
5038                  !!!cp ('t177');                  !!!cp ('t177');
5039                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5040                                    text => $token->{tag_name}, token => $token);
5041                  ## Ignore the token                  ## Ignore the token
5042                  !!!next-token;                  !!!next-token;
5043                  next B;                  next B;
# Line 4942  sub _tree_construction_main ($) { Line 5080  sub _tree_construction_main ($) {
5080    
5081                  !!!cp ('t182');                  !!!cp ('t182');
5082                  !!!parse-error (type => 'unmatched end tag',                  !!!parse-error (type => 'unmatched end tag',
5083                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
5084                  ## Ignore the token                  ## Ignore the token
5085                  !!!next-token;                  !!!next-token;
5086                  next B;                  next B;
5087                } # INSCOPE                } # INSCOPE
5088              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
5089                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5090                !!!parse-error (type => 'not closed:caption', token => $token);                !!!parse-error (type => 'not closed', text => 'caption',
5091                                  token => $token);
5092    
5093                ## As if </caption>                ## As if </caption>
5094                ## have a table element in table scope                ## have a table element in table scope
# Line 4967  sub _tree_construction_main ($) { Line 5106  sub _tree_construction_main ($) {
5106                } # INSCOPE                } # INSCOPE
5107                unless (defined $i) {                unless (defined $i) {
5108                  !!!cp ('t186');                  !!!cp ('t186');
5109                  !!!parse-error (type => 'unmatched end tag:caption', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5110                                    text => 'caption', token => $token);
5111                  ## Ignore the token                  ## Ignore the token
5112                  !!!next-token;                  !!!next-token;
5113                  next B;                  next B;
# Line 4982  sub _tree_construction_main ($) { Line 5122  sub _tree_construction_main ($) {
5122                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5123                  !!!cp ('t188');                  !!!cp ('t188');
5124                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5125                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5126                                      ->manakai_local_name,                                      ->manakai_local_name,
5127                                  token => $token);                                  token => $token);
5128                } else {                } else {
# Line 5002  sub _tree_construction_main ($) { Line 5142  sub _tree_construction_main ($) {
5142                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5143                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
5144                  !!!cp ('t190');                  !!!cp ('t190');
5145                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5146                                    text => $token->{tag_name}, token => $token);
5147                  ## Ignore the token                  ## Ignore the token
5148                  !!!next-token;                  !!!next-token;
5149                  next B;                  next B;
# Line 5016  sub _tree_construction_main ($) { Line 5157  sub _tree_construction_main ($) {
5157                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
5158                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5159                !!!cp ('t192');                !!!cp ('t192');
5160                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
5161                                  text => $token->{tag_name}, token => $token);
5162                ## Ignore the token                ## Ignore the token
5163                !!!next-token;                !!!next-token;
5164                next B;                next B;
# Line 5056  sub _tree_construction_main ($) { Line 5198  sub _tree_construction_main ($) {
5198            }            }
5199          }          }
5200    
5201              !!!parse-error (type => 'in table:#character', token => $token);          !!!parse-error (type => 'in table:#text', token => $token);
5202    
5203              ## As if in body, but insert into foster parent element              ## As if in body, but insert into foster parent element
5204              ## ISSUE: Spec says that "whenever a node would be inserted              ## ISSUE: Spec says that "whenever a node would be inserted
# Line 5107  sub _tree_construction_main ($) { Line 5249  sub _tree_construction_main ($) {
5249          !!!next-token;          !!!next-token;
5250          next B;          next B;
5251        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5252              if ({          if ({
5253                   tr => ($self->{insertion_mode} != IN_ROW_IM),               tr => ($self->{insertion_mode} != IN_ROW_IM),
5254                   th => 1, td => 1,               th => 1, td => 1,
5255                  }->{$token->{tag_name}}) {              }->{$token->{tag_name}}) {
5256                if ($self->{insertion_mode} == IN_TABLE_IM) {            if ($self->{insertion_mode} == IN_TABLE_IM) {
5257                  ## Clear back to table context              ## Clear back to table context
5258                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5259                                  & TABLE_SCOPING_EL)) {                              & TABLE_SCOPING_EL)) {
5260                    !!!cp ('t201');                !!!cp ('t201');
5261                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5262                  }              }
5263                                
5264                  !!!insert-element ('tbody',, $token);              !!!insert-element ('tbody',, $token);
5265                  $self->{insertion_mode} = IN_TABLE_BODY_IM;              $self->{insertion_mode} = IN_TABLE_BODY_IM;
5266                  ## reprocess in the "in table body" insertion mode...              ## reprocess in the "in table body" insertion mode...
5267                }            }
5268              
5269                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {            if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
5270                  unless ($token->{tag_name} eq 'tr') {              unless ($token->{tag_name} eq 'tr') {
5271                    !!!cp ('t202');                !!!cp ('t202');
5272                    !!!parse-error (type => 'missing start tag:tr', token => $token);                !!!parse-error (type => 'missing start tag:tr', token => $token);
5273                  }              }
5274                                    
5275                  ## Clear back to table body context              ## Clear back to table body context
5276                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5277                                  & TABLE_ROWS_SCOPING_EL)) {                              & TABLE_ROWS_SCOPING_EL)) {
5278                    !!!cp ('t203');                !!!cp ('t203');
5279                    ## ISSUE: Can this case be reached?                ## ISSUE: Can this case be reached?
5280                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5281                  }              }
5282                                    
5283                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
5284                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
# Line 5192  sub _tree_construction_main ($) { Line 5334  sub _tree_construction_main ($) {
5334                  unless (defined $i) {                  unless (defined $i) {
5335                    !!!cp ('t210');                    !!!cp ('t210');
5336  ## TODO: This type is wrong.  ## TODO: This type is wrong.
5337                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmacthed end tag',
5338                                      text => $token->{tag_name}, token => $token);
5339                    ## Ignore the token                    ## Ignore the token
5340                    !!!nack ('t210.1');                    !!!nack ('t210.1');
5341                    !!!next-token;                    !!!next-token;
# Line 5236  sub _tree_construction_main ($) { Line 5379  sub _tree_construction_main ($) {
5379                  } # INSCOPE                  } # INSCOPE
5380                  unless (defined $i) {                  unless (defined $i) {
5381                    !!!cp ('t216');                    !!!cp ('t216');
5382  ## TODO: This erorr type ios wrong.  ## TODO: This erorr type is wrong.
5383                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5384                                      text => $token->{tag_name}, token => $token);
5385                    ## Ignore the token                    ## Ignore the token
5386                    !!!nack ('t216.1');                    !!!nack ('t216.1');
5387                    !!!next-token;                    !!!next-token;
# Line 5312  sub _tree_construction_main ($) { Line 5456  sub _tree_construction_main ($) {
5456                }                }
5457              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
5458                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
5459                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
5460                                    ->manakai_local_name,                                    ->manakai_local_name,
5461                                token => $token);                                token => $token);
5462    
# Line 5333  sub _tree_construction_main ($) { Line 5477  sub _tree_construction_main ($) {
5477                unless (defined $i) {                unless (defined $i) {
5478                  !!!cp ('t223');                  !!!cp ('t223');
5479  ## TODO: The following is wrong, maybe.  ## TODO: The following is wrong, maybe.
5480                  !!!parse-error (type => 'unmatched end tag:table', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'table',
5481                                    token => $token);
5482                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
5483                  !!!nack ('t223.1');                  !!!nack ('t223.1');
5484                  !!!next-token;                  !!!next-token;
5485                  next B;                  next B;
5486                }                }
5487                                
5488  ## TODO: Followings are removed from the latest spec.  ## TODO: Followings are removed from the latest spec.
5489                ## generate implied end tags                ## generate implied end tags
5490                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
5491                  !!!cp ('t224');                  !!!cp ('t224');
# Line 5351  sub _tree_construction_main ($) { Line 5496  sub _tree_construction_main ($) {
5496                  !!!cp ('t225');                  !!!cp ('t225');
5497                  ## NOTE: |<table><tr><table>|                  ## NOTE: |<table><tr><table>|
5498                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5499                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5500                                      ->manakai_local_name,                                      ->manakai_local_name,
5501                                  token => $token);                                  token => $token);
5502                } else {                } else {
# Line 5392  sub _tree_construction_main ($) { Line 5537  sub _tree_construction_main ($) {
5537                my $type = lc $token->{attributes}->{type}->{value};                my $type = lc $token->{attributes}->{type}->{value};
5538                if ($type eq 'hidden') {                if ($type eq 'hidden') {
5539                  !!!cp ('t227.3');                  !!!cp ('t227.3');
5540                  !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in table',
5541                                    text => $token->{tag_name}, token => $token);
5542    
5543                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5544    
# Line 5420  sub _tree_construction_main ($) { Line 5566  sub _tree_construction_main ($) {
5566            #            #
5567          }          }
5568    
5569          !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in table', text => $token->{tag_name},
5570                            token => $token);
5571    
5572          $insert = $insert_to_foster;          $insert = $insert_to_foster;
5573          #          #
# Line 5442  sub _tree_construction_main ($) { Line 5589  sub _tree_construction_main ($) {
5589                } # INSCOPE                } # INSCOPE
5590                unless (defined $i) {                unless (defined $i) {
5591                  !!!cp ('t230');                  !!!cp ('t230');
5592                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5593                                    text => $token->{tag_name}, token => $token);
5594                  ## Ignore the token                  ## Ignore the token
5595                  !!!nack ('t230.1');                  !!!nack ('t230.1');
5596                  !!!next-token;                  !!!next-token;
# Line 5483  sub _tree_construction_main ($) { Line 5631  sub _tree_construction_main ($) {
5631                  unless (defined $i) {                  unless (defined $i) {
5632                    !!!cp ('t235');                    !!!cp ('t235');
5633  ## TODO: The following is wrong.  ## TODO: The following is wrong.
5634                    !!!parse-error (type => 'unmatched end tag:'.$token->{type}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5635                                      text => $token->{type}, token => $token);
5636                    ## Ignore the token                    ## Ignore the token
5637                    !!!nack ('t236.1');                    !!!nack ('t236.1');
5638                    !!!next-token;                    !!!next-token;
# Line 5519  sub _tree_construction_main ($) { Line 5668  sub _tree_construction_main ($) {
5668                  } # INSCOPE                  } # INSCOPE
5669                  unless (defined $i) {                  unless (defined $i) {
5670                    !!!cp ('t239');                    !!!cp ('t239');
5671                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5672                                      text => $token->{tag_name}, token => $token);
5673                    ## Ignore the token                    ## Ignore the token
5674                    !!!nack ('t239.1');                    !!!nack ('t239.1');
5675                    !!!next-token;                    !!!next-token;
# Line 5565  sub _tree_construction_main ($) { Line 5715  sub _tree_construction_main ($) {
5715                } # INSCOPE                } # INSCOPE
5716                unless (defined $i) {                unless (defined $i) {
5717                  !!!cp ('t243');                  !!!cp ('t243');
5718                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5719                                    text => $token->{tag_name}, token => $token);
5720                  ## Ignore the token                  ## Ignore the token
5721                  !!!nack ('t243.1');                  !!!nack ('t243.1');
5722                  !!!next-token;                  !!!next-token;
# Line 5599  sub _tree_construction_main ($) { Line 5750  sub _tree_construction_main ($) {
5750                  } # INSCOPE                  } # INSCOPE
5751                    unless (defined $i) {                    unless (defined $i) {
5752                      !!!cp ('t249');                      !!!cp ('t249');
5753                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5754                                        text => $token->{tag_name}, token => $token);
5755                      ## Ignore the token                      ## Ignore the token
5756                      !!!nack ('t249.1');                      !!!nack ('t249.1');
5757                      !!!next-token;                      !!!next-token;
# Line 5622  sub _tree_construction_main ($) { Line 5774  sub _tree_construction_main ($) {
5774                  } # INSCOPE                  } # INSCOPE
5775                    unless (defined $i) {                    unless (defined $i) {
5776                      !!!cp ('t252');                      !!!cp ('t252');
5777                      !!!parse-error (type => 'unmatched end tag:tr', token => $token);                      !!!parse-error (type => 'unmatched end tag',
5778                                        text => 'tr', token => $token);
5779                      ## Ignore the token                      ## Ignore the token
5780                      !!!nack ('t252.1');                      !!!nack ('t252.1');
5781                      !!!next-token;                      !!!next-token;
# Line 5657  sub _tree_construction_main ($) { Line 5810  sub _tree_construction_main ($) {
5810                } # INSCOPE                } # INSCOPE
5811                unless (defined $i) {                unless (defined $i) {
5812                  !!!cp ('t256');                  !!!cp ('t256');
5813                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5814                                    text => $token->{tag_name}, token => $token);
5815                  ## Ignore the token                  ## Ignore the token
5816                  !!!nack ('t256.1');                  !!!nack ('t256.1');
5817                  !!!next-token;                  !!!next-token;
# Line 5684  sub _tree_construction_main ($) { Line 5838  sub _tree_construction_main ($) {
5838                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
5839                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5840            !!!cp ('t258');            !!!cp ('t258');
5841            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
5842                              text => $token->{tag_name}, token => $token);
5843            ## Ignore the token            ## Ignore the token
5844            !!!nack ('t258.1');            !!!nack ('t258.1');
5845             !!!next-token;             !!!next-token;
5846            next B;            next B;
5847          } else {          } else {
5848            !!!cp ('t259');            !!!cp ('t259');
5849            !!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in table:/',
5850                              text => $token->{tag_name}, token => $token);
5851    
5852            $insert = $insert_to_foster;            $insert = $insert_to_foster;
5853            #            #
# Line 5741  sub _tree_construction_main ($) { Line 5897  sub _tree_construction_main ($) {
5897              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
5898                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
5899                  !!!cp ('t264');                  !!!cp ('t264');
5900                  !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5901                                    text => 'colgroup', token => $token);
5902                  ## Ignore the token                  ## Ignore the token
5903                  !!!next-token;                  !!!next-token;
5904                  next B;                  next B;
# Line 5754  sub _tree_construction_main ($) { Line 5911  sub _tree_construction_main ($) {
5911                }                }
5912              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
5913                !!!cp ('t266');                !!!cp ('t266');
5914                !!!parse-error (type => 'unmatched end tag:col', token => $token);                !!!parse-error (type => 'unmatched end tag',
5915                                  text => 'col', token => $token);
5916                ## Ignore the token                ## Ignore the token
5917                !!!next-token;                !!!next-token;
5918                next B;                next B;
# Line 5784  sub _tree_construction_main ($) { Line 5942  sub _tree_construction_main ($) {
5942            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
5943              !!!cp ('t269');              !!!cp ('t269');
5944  ## TODO: Wrong error type?  ## TODO: Wrong error type?
5945              !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);              !!!parse-error (type => 'unmatched end tag',
5946                                text => 'colgroup', token => $token);
5947              ## Ignore the token              ## Ignore the token
5948              !!!nack ('t269.1');              !!!nack ('t269.1');
5949              !!!next-token;              !!!next-token;
# Line 5838  sub _tree_construction_main ($) { Line 5997  sub _tree_construction_main ($) {
5997            !!!nack ('t277.1');            !!!nack ('t277.1');
5998            !!!next-token;            !!!next-token;
5999            next B;            next B;
6000          } elsif ($token->{tag_name} eq 'select' or          } elsif ({
6001                   $token->{tag_name} eq 'input' or                     select => 1, input => 1, textarea => 1,
6002                     }->{$token->{tag_name}} or
6003                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
6004                    {                    {
6005                     caption => 1, table => 1,                     caption => 1, table => 1,
# Line 5847  sub _tree_construction_main ($) { Line 6007  sub _tree_construction_main ($) {
6007                     tr => 1, td => 1, th => 1,                     tr => 1, td => 1, th => 1,
6008                    }->{$token->{tag_name}})) {                    }->{$token->{tag_name}})) {
6009            ## TODO: The type below is not good - <select> is replaced by </select>            ## TODO: The type below is not good - <select> is replaced by </select>
6010            !!!parse-error (type => 'not closed:select', token => $token);            !!!parse-error (type => 'not closed', text => 'select',
6011                              token => $token);
6012            ## NOTE: As if the token were </select> (<select> case) or            ## NOTE: As if the token were </select> (<select> case) or
6013            ## as if there were </select> (otherwise).            ## as if there were </select> (otherwise).
6014            ## have an element in table scope            ## have an element in table scope
# Line 5865  sub _tree_construction_main ($) { Line 6026  sub _tree_construction_main ($) {
6026            } # INSCOPE            } # INSCOPE
6027            unless (defined $i) {            unless (defined $i) {
6028              !!!cp ('t280');              !!!cp ('t280');
6029              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6030                                text => 'select', token => $token);
6031              ## Ignore the token              ## Ignore the token
6032              !!!nack ('t280.1');              !!!nack ('t280.1');
6033              !!!next-token;              !!!next-token;
# Line 5889  sub _tree_construction_main ($) { Line 6051  sub _tree_construction_main ($) {
6051            }            }
6052          } else {          } else {
6053            !!!cp ('t282');            !!!cp ('t282');
6054            !!!parse-error (type => 'in select:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select',
6055                              text => $token->{tag_name}, token => $token);
6056            ## Ignore the token            ## Ignore the token
6057            !!!nack ('t282.1');            !!!nack ('t282.1');
6058            !!!next-token;            !!!next-token;
# Line 5907  sub _tree_construction_main ($) { Line 6070  sub _tree_construction_main ($) {
6070              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6071            } else {            } else {
6072              !!!cp ('t285');              !!!cp ('t285');
6073              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6074                                text => $token->{tag_name}, token => $token);
6075              ## Ignore the token              ## Ignore the token
6076            }            }
6077            !!!nack ('t285.1');            !!!nack ('t285.1');
# Line 5919  sub _tree_construction_main ($) { Line 6083  sub _tree_construction_main ($) {
6083              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6084            } else {            } else {
6085              !!!cp ('t287');              !!!cp ('t287');
6086              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6087                                text => $token->{tag_name}, token => $token);
6088              ## Ignore the token              ## Ignore the token
6089            }            }
6090            !!!nack ('t287.1');            !!!nack ('t287.1');
# Line 5941  sub _tree_construction_main ($) { Line 6106  sub _tree_construction_main ($) {
6106            } # INSCOPE            } # INSCOPE
6107            unless (defined $i) {            unless (defined $i) {
6108              !!!cp ('t290');              !!!cp ('t290');
6109              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6110                                text => $token->{tag_name}, token => $token);
6111              ## Ignore the token              ## Ignore the token
6112              !!!nack ('t290.1');              !!!nack ('t290.1');
6113              !!!next-token;              !!!next-token;
# Line 5962  sub _tree_construction_main ($) { Line 6128  sub _tree_construction_main ($) {
6128                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
6129                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
6130  ## TODO: The following is wrong?  ## TODO: The following is wrong?
6131            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
6132                              text => $token->{tag_name}, token => $token);
6133                                
6134            ## have an element in table scope            ## have an element in table scope
6135            my $i;            my $i;
# Line 6003  sub _tree_construction_main ($) { Line 6170  sub _tree_construction_main ($) {
6170            unless (defined $i) {            unless (defined $i) {
6171              !!!cp ('t297');              !!!cp ('t297');
6172  ## TODO: The following error type is correct?  ## TODO: The following error type is correct?
6173              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6174                                text => 'select', token => $token);
6175              ## Ignore the </select> token              ## Ignore the </select> token
6176              !!!nack ('t297.1');              !!!nack ('t297.1');
6177              !!!next-token; ## TODO: ok?              !!!next-token; ## TODO: ok?
# Line 6020  sub _tree_construction_main ($) { Line 6188  sub _tree_construction_main ($) {
6188            next B;            next B;
6189          } else {          } else {
6190            !!!cp ('t299');            !!!cp ('t299');
6191            !!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select:/',
6192                              text => $token->{tag_name}, token => $token);
6193            ## Ignore the token            ## Ignore the token
6194            !!!nack ('t299.3');            !!!nack ('t299.3');
6195            !!!next-token;            !!!next-token;
# Line 6058  sub _tree_construction_main ($) { Line 6227  sub _tree_construction_main ($) {
6227                    
6228          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6229            !!!cp ('t301');            !!!cp ('t301');
6230            !!!parse-error (type => 'after html:#character', token => $token);            !!!parse-error (type => 'after html:#text', token => $token);
6231    
6232            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6233          } else {          } else {
# Line 6066  sub _tree_construction_main ($) { Line 6235  sub _tree_construction_main ($) {
6235          }          }
6236                    
6237          ## "after body" insertion mode          ## "after body" insertion mode
6238          !!!parse-error (type => 'after body:#character', token => $token);          !!!parse-error (type => 'after body:#text', token => $token);
6239    
6240          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6241          ## reprocess          ## reprocess
# Line 6074  sub _tree_construction_main ($) { Line 6243  sub _tree_construction_main ($) {
6243        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
6244          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6245            !!!cp ('t303');            !!!cp ('t303');
6246            !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html',
6247                              text => $token->{tag_name}, token => $token);
6248                        
6249            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6250          } else {          } else {
# Line 6082  sub _tree_construction_main ($) { Line 6252  sub _tree_construction_main ($) {
6252          }          }
6253    
6254          ## "after body" insertion mode          ## "after body" insertion mode
6255          !!!parse-error (type => 'after body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'after body',
6256                            text => $token->{tag_name}, token => $token);
6257    
6258          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6259          !!!ack-later;          !!!ack-later;
# Line 6091  sub _tree_construction_main ($) { Line 6262  sub _tree_construction_main ($) {
6262        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6263          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6264            !!!cp ('t305');            !!!cp ('t305');
6265            !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html:/',
6266                              text => $token->{tag_name}, token => $token);
6267                        
6268            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6269            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
# Line 6103  sub _tree_construction_main ($) { Line 6275  sub _tree_construction_main ($) {
6275          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
6276            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
6277              !!!cp ('t307');              !!!cp ('t307');
6278              !!!parse-error (type => 'unmatched end tag:html', token => $token);              !!!parse-error (type => 'unmatched end tag',
6279                                text => 'html', token => $token);
6280              ## Ignore the token              ## Ignore the token
6281              !!!next-token;              !!!next-token;
6282              next B;              next B;
# Line 6115  sub _tree_construction_main ($) { Line 6288  sub _tree_construction_main ($) {
6288            }            }
6289          } else {          } else {
6290            !!!cp ('t309');            !!!cp ('t309');
6291            !!!parse-error (type => 'after body:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after body:/',
6292                              text => $token->{tag_name}, token => $token);
6293    
6294            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
6295            ## reprocess            ## reprocess
# Line 6143  sub _tree_construction_main ($) { Line 6317  sub _tree_construction_main ($) {
6317          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
6318            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6319              !!!cp ('t311');              !!!cp ('t311');
6320              !!!parse-error (type => 'in frameset:#character', token => $token);              !!!parse-error (type => 'in frameset:#text', token => $token);
6321            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6322              !!!cp ('t312');              !!!cp ('t312');
6323              !!!parse-error (type => 'after frameset:#character', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6324            } else { # "after html frameset"            } else { # "after after frameset"
6325              !!!cp ('t313');              !!!cp ('t313');
6326              !!!parse-error (type => 'after html:#character', token => $token);              !!!parse-error (type => 'after html:#text', token => $token);
   
             $self->{insertion_mode} = AFTER_FRAMESET_IM;  
             ## Reprocess in the "after frameset" insertion mode.  
             !!!parse-error (type => 'after frameset:#character', token => $token);  
6327            }            }
6328                        
6329            ## Ignore the token.            ## Ignore the token.
# Line 6169  sub _tree_construction_main ($) { Line 6339  sub _tree_construction_main ($) {
6339                    
6340          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
6341        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
         if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {  
           !!!cp ('t316');  
           !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);  
   
           $self->{insertion_mode} = AFTER_FRAMESET_IM;  
           ## Process in the "after frameset" insertion mode.  
         } else {  
           !!!cp ('t317');  
         }  
   
6342          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6343              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6344            !!!cp ('t318');            !!!cp ('t318');
# Line 6196  sub _tree_construction_main ($) { Line 6356  sub _tree_construction_main ($) {
6356            next B;            next B;
6357          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
6358            !!!cp ('t320');            !!!cp ('t320');
6359            ## NOTE: As if in body.            ## NOTE: As if in head.
6360            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
6361            next B;            next B;
6362    
6363              ## NOTE: |<!DOCTYPE HTML><frameset></frameset></html><noframes></noframes>|
6364              ## has no parse error.
6365          } else {          } else {
6366            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6367              !!!cp ('t321');              !!!cp ('t321');
6368              !!!parse-error (type => 'in frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset',
6369            } else {                              text => $token->{tag_name}, token => $token);
6370              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6371              !!!cp ('t322');              !!!cp ('t322');
6372              !!!parse-error (type => 'after frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after frameset',
6373                                text => $token->{tag_name}, token => $token);
6374              } else { # "after after frameset"
6375                !!!cp ('t322.2');
6376                !!!parse-error (type => 'after after frameset',
6377                                text => $token->{tag_name}, token => $token);
6378            }            }
6379            ## Ignore the token            ## Ignore the token
6380            !!!nack ('t322.1');            !!!nack ('t322.1');
# Line 6213  sub _tree_construction_main ($) { Line 6382  sub _tree_construction_main ($) {
6382            next B;            next B;
6383          }          }
6384        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
         if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {  
           !!!cp ('t323');  
           !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);  
   
           $self->{insertion_mode} = AFTER_FRAMESET_IM;  
           ## Process in the "after frameset" insertion mode.  
         } else {  
           !!!cp ('t324');  
         }  
   
6385          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6386              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6387            if ($self->{open_elements}->[-1]->[1] & HTML_EL and            if ($self->{open_elements}->[-1]->[1] & HTML_EL and
6388                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
6389              !!!cp ('t325');              !!!cp ('t325');
6390              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6391                                text => $token->{tag_name}, token => $token);
6392              ## Ignore the token              ## Ignore the token
6393              !!!next-token;              !!!next-token;
6394            } else {            } else {
# Line 6254  sub _tree_construction_main ($) { Line 6414  sub _tree_construction_main ($) {
6414          } else {          } else {
6415            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6416              !!!cp ('t330');              !!!cp ('t330');
6417              !!!parse-error (type => 'in frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset:/',
6418            } else {                              text => $token->{tag_name}, token => $token);
6419              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6420                !!!cp ('t330.1');
6421                !!!parse-error (type => 'after frameset:/',
6422                                text => $token->{tag_name}, token => $token);
6423              } else { # "after after html"
6424              !!!cp ('t331');              !!!cp ('t331');
6425              !!!parse-error (type => 'after frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after after frameset:/',
6426                                text => $token->{tag_name}, token => $token);
6427            }            }
6428            ## Ignore the token            ## Ignore the token
6429            !!!next-token;            !!!next-token;
# Line 6324  sub _tree_construction_main ($) { Line 6490  sub _tree_construction_main ($) {
6490                                           ->{has_reference});                                           ->{has_reference});
6491            } elsif ($token->{attributes}->{content}) {            } elsif ($token->{attributes}->{content}) {
6492              if ($token->{attributes}->{content}->{value}              if ($token->{attributes}->{content}->{value}
6493                  =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                  =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
6494                      [\x09-\x0D\x20]*=                      [\x09-\x0D\x20]*=
6495                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
6496                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
6497                !!!cp ('t336');                !!!cp ('t336');
6498                ## NOTE: Whether the encoding is supported or not is handled                ## NOTE: Whether the encoding is supported or not is handled
6499                ## in the {change_encoding} callback.                ## in the {change_encoding} callback.
# Line 6365  sub _tree_construction_main ($) { Line 6531  sub _tree_construction_main ($) {
6531          $parse_rcdata->(RCDATA_CONTENT_MODEL);          $parse_rcdata->(RCDATA_CONTENT_MODEL);
6532          next B;          next B;
6533        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
6534          !!!parse-error (type => 'in body:body', token => $token);          !!!parse-error (type => 'in body', text => 'body', token => $token);
6535                                
6536          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
6537              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {
# Line 6485  sub _tree_construction_main ($) { Line 6651  sub _tree_construction_main ($) {
6651              if ($i != -1) {              if ($i != -1) {
6652                !!!cp ('t355');                !!!cp ('t355');
6653                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
6654                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
6655                                    ->manakai_local_name,                                    ->manakai_local_name,
6656                                token => $token);                                token => $token);
6657              } else {              } else {
# Line 6639  sub _tree_construction_main ($) { Line 6805  sub _tree_construction_main ($) {
6805                  xmp => 1,                  xmp => 1,
6806                  iframe => 1,                  iframe => 1,
6807                  noembed => 1,                  noembed => 1,
6808                  noframes => 1,                  noframes => 1, ## NOTE: This is an "as if in head" code clone.
6809                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
6810                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6811          if ($token->{tag_name} eq 'xmp') {          if ($token->{tag_name} eq 'xmp') {
# Line 6661  sub _tree_construction_main ($) { Line 6827  sub _tree_construction_main ($) {
6827            !!!next-token;            !!!next-token;
6828            next B;            next B;
6829          } else {          } else {
6830              !!!ack ('t391.1');
6831    
6832            my $at = $token->{attributes};            my $at = $token->{attributes};
6833            my $form_attrs;            my $form_attrs;
6834            $form_attrs->{action} = $at->{action} if $at->{action};            $form_attrs->{action} = $at->{action} if $at->{action};
# Line 6704  sub _tree_construction_main ($) { Line 6872  sub _tree_construction_main ($) {
6872                           line => $token->{line}, column => $token->{column}},                           line => $token->{line}, column => $token->{column}},
6873                          {type => END_TAG_TOKEN, tag_name => 'form',                          {type => END_TAG_TOKEN, tag_name => 'form',
6874                           line => $token->{line}, column => $token->{column}};                           line => $token->{line}, column => $token->{column}};
           !!!nack ('t391.1'); ## NOTE: Not acknowledged.  
6875            !!!back-token (@tokens);            !!!back-token (@tokens);
6876            !!!next-token;            !!!next-token;
6877            next B;            next B;
# Line 6752  sub _tree_construction_main ($) { Line 6919  sub _tree_construction_main ($) {
6919            ## Ignore the token            ## Ignore the token
6920          } else {          } else {
6921            !!!cp ('t398');            !!!cp ('t398');
6922            !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);            !!!parse-error (type => 'in RCDATA:#eof', token => $token);
6923          }          }
6924          !!!next-token;          !!!next-token;
6925          next B;          next B;
6926          } elsif ($token->{tag_name} eq 'rt' or
6927                   $token->{tag_name} eq 'rp') {
6928            ## has a |ruby| element in scope
6929            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6930              my $node = $self->{open_elements}->[$_];
6931              if ($node->[1] & RUBY_EL) {
6932                !!!cp ('t398.1');
6933                ## generate implied end tags
6934                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
6935                  !!!cp ('t398.2');
6936                  pop @{$self->{open_elements}};
6937                }
6938                unless ($self->{open_elements}->[-1]->[1] & RUBY_EL) {
6939                  !!!cp ('t398.3');
6940                  !!!parse-error (type => 'not closed',
6941                                  text => $self->{open_elements}->[-1]->[0]
6942                                      ->manakai_local_name,
6943                                  token => $token);
6944                  pop @{$self->{open_elements}}
6945                      while not $self->{open_elements}->[-1]->[1] & RUBY_EL;
6946                }
6947                last INSCOPE;
6948              } elsif ($node->[1] & SCOPING_EL) {
6949                !!!cp ('t398.4');
6950                last INSCOPE;
6951              }
6952            } # INSCOPE
6953    
6954            !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
6955    
6956            !!!nack ('t398.5');
6957            !!!next-token;
6958            redo B;
6959        } elsif ($token->{tag_name} eq 'math' or        } elsif ($token->{tag_name} eq 'math' or
6960                 $token->{tag_name} eq 'svg') {                 $token->{tag_name} eq 'svg') {
6961          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
6962    
6963            ## "Adjust MathML attributes" ('math' only) - done in insert-element-f
6964    
6965          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f
6966    
6967          ## "adjust foreign attributes" - done in insert-element-f          ## "adjust foreign attributes" - done in insert-element-f
# Line 6786  sub _tree_construction_main ($) { Line 6988  sub _tree_construction_main ($) {
6988                  thead => 1, tr => 1,                  thead => 1, tr => 1,
6989                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6990          !!!cp ('t401');          !!!cp ('t401');
6991          !!!parse-error (type => 'in body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in body',
6992                            text => $token->{tag_name}, token => $token);
6993          ## Ignore the token          ## Ignore the token
6994          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.
6995          !!!next-token;          !!!next-token;
# Line 6871  sub _tree_construction_main ($) { Line 7074  sub _tree_construction_main ($) {
7074            }            }
7075    
7076            !!!parse-error (type => 'start tag not allowed',            !!!parse-error (type => 'start tag not allowed',
7077                            value => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7078            ## NOTE: Ignore the token.            ## NOTE: Ignore the token.
7079            !!!next-token;            !!!next-token;
7080            next B;            next B;
# Line 6881  sub _tree_construction_main ($) { Line 7084  sub _tree_construction_main ($) {
7084            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {
7085              !!!cp ('t403');              !!!cp ('t403');
7086              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7087                              value => $_->[0]->manakai_local_name,                              text => $_->[0]->manakai_local_name,
7088                              token => $token);                              token => $token);
7089              last;              last;
7090            } else {            } else {
# Line 6901  sub _tree_construction_main ($) { Line 7104  sub _tree_construction_main ($) {
7104            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {
7105              !!!cp ('t406');              !!!cp ('t406');
7106              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7107                              value => $self->{open_elements}->[1]->[0]                              text => $self->{open_elements}->[1]->[0]
7108                                  ->manakai_local_name,                                  ->manakai_local_name,
7109                              token => $token);                              token => $token);
7110            } else {            } else {
# Line 6912  sub _tree_construction_main ($) { Line 7115  sub _tree_construction_main ($) {
7115            next B;            next B;
7116          } else {          } else {
7117            !!!cp ('t408');            !!!cp ('t408');
7118            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7119                              text => $token->{tag_name}, token => $token);
7120            ## Ignore the token            ## Ignore the token
7121            !!!next-token;            !!!next-token;
7122            next B;            next B;
# Line 6940  sub _tree_construction_main ($) { Line 7144  sub _tree_construction_main ($) {
7144    
7145          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7146            !!!cp ('t413');            !!!cp ('t413');
7147            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7148                              text => $token->{tag_name}, token => $token);
7149              ## NOTE: Ignore the token.
7150          } else {          } else {
7151            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7152            while ({            while ({
7153                      ## END_TAG_OPTIONAL_EL
7154                    dd => ($token->{tag_name} ne 'dd'),                    dd => ($token->{tag_name} ne 'dd'),
7155                    dt => ($token->{tag_name} ne 'dt'),                    dt => ($token->{tag_name} ne 'dt'),
7156                    li => ($token->{tag_name} ne 'li'),                    li => ($token->{tag_name} ne 'li'),
7157                    p => 1,                    p => 1,
7158                      rt => 1,
7159                      rp => 1,
7160                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {
7161              !!!cp ('t409');              !!!cp ('t409');
7162              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
# Line 6958  sub _tree_construction_main ($) { Line 7167  sub _tree_construction_main ($) {
7167                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7168              !!!cp ('t412');              !!!cp ('t412');
7169              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7170                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7171                                  ->manakai_local_name,                                  ->manakai_local_name,
7172                              token => $token);                              token => $token);
7173            } else {            } else {
# Line 6995  sub _tree_construction_main ($) { Line 7204  sub _tree_construction_main ($) {
7204    
7205          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7206            !!!cp ('t421');            !!!cp ('t421');
7207            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7208                              text => $token->{tag_name}, token => $token);
7209              ## NOTE: Ignore the token.
7210          } else {          } else {
7211            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7212            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7008  sub _tree_construction_main ($) { Line 7219  sub _tree_construction_main ($) {
7219                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7220              !!!cp ('t417.1');              !!!cp ('t417.1');
7221              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7222                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7223                                  ->manakai_local_name,                                  ->manakai_local_name,
7224                              token => $token);                              token => $token);
7225            } else {            } else {
# Line 7040  sub _tree_construction_main ($) { Line 7251  sub _tree_construction_main ($) {
7251    
7252          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7253            !!!cp ('t425.1');            !!!cp ('t425.1');
7254            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7255                              text => $token->{tag_name}, token => $token);
7256              ## NOTE: Ignore the token.
7257          } else {          } else {
7258            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7259            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7052  sub _tree_construction_main ($) { Line 7265  sub _tree_construction_main ($) {
7265            if ($self->{open_elements}->[-1]->[0]->manakai_local_name            if ($self->{open_elements}->[-1]->[0]->manakai_local_name
7266                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7267              !!!cp ('t425');              !!!cp ('t425');
7268              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
7269                                text => $token->{tag_name}, token => $token);
7270            } else {            } else {
7271              !!!cp ('t426');              !!!cp ('t426');
7272            }            }
# Line 7083  sub _tree_construction_main ($) { Line 7297  sub _tree_construction_main ($) {
7297                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7298              !!!cp ('t412.1');              !!!cp ('t412.1');
7299              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7300                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7301                                  ->manakai_local_name,                                  ->manakai_local_name,
7302                              token => $token);                              token => $token);
7303            } else {            } else {
# Line 7093  sub _tree_construction_main ($) { Line 7307  sub _tree_construction_main ($) {
7307            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
7308          } else {          } else {
7309            !!!cp ('t413.1');            !!!cp ('t413.1');
7310            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7311                              text => $token->{tag_name}, token => $token);
7312    
7313            !!!cp ('t415.1');            !!!cp ('t415.1');
7314            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
# Line 7116  sub _tree_construction_main ($) { Line 7331  sub _tree_construction_main ($) {
7331          next B;          next B;
7332        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
7333          !!!cp ('t428');          !!!cp ('t428');
7334          !!!parse-error (type => 'unmatched end tag:br', token => $token);          !!!parse-error (type => 'unmatched end tag',
7335                            text => 'br', token => $token);
7336    
7337          ## As if <br>          ## As if <br>
7338          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
# Line 7141  sub _tree_construction_main ($) { Line 7357  sub _tree_construction_main ($) {
7357                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
7358                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7359          !!!cp ('t429');          !!!cp ('t429');
7360          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'unmatched end tag',
7361                            text => $token->{tag_name}, token => $token);
7362          ## Ignore the token          ## Ignore the token
7363          !!!next-token;          !!!next-token;
7364          next B;          next B;
# Line 7160  sub _tree_construction_main ($) { Line 7377  sub _tree_construction_main ($) {
7377              ## generate implied end tags              ## generate implied end tags
7378              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7379                !!!cp ('t430');                !!!cp ('t430');
7380                ## ISSUE: Can this case be reached?                ## NOTE: |<ruby><rt></ruby>|.
7381                  ## ISSUE: <ruby><rt></rt> will also take this code path,
7382                  ## which seems wrong.
7383                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
7384                  $node_i++;
7385              }              }
7386                    
7387              ## Step 2              ## Step 2
# Line 7170  sub _tree_construction_main ($) { Line 7390  sub _tree_construction_main ($) {
7390                !!!cp ('t431');                !!!cp ('t431');
7391                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
7392                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
7393                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
7394                                    ->manakai_local_name,                                    ->manakai_local_name,
7395                                token => $token);                                token => $token);
7396              } else {              } else {
# Line 7178  sub _tree_construction_main ($) { Line 7398  sub _tree_construction_main ($) {
7398              }              }
7399                            
7400              ## Step 3              ## Step 3
7401              splice @{$self->{open_elements}}, $node_i;              splice @{$self->{open_elements}}, $node_i if $node_i < 0;
7402    
7403              !!!next-token;              !!!next-token;
7404              last S2;              last S2;
# Line 7189  sub _tree_construction_main ($) { Line 7409  sub _tree_construction_main ($) {
7409                  ($node->[1] & SPECIAL_EL or                  ($node->[1] & SPECIAL_EL or
7410                   $node->[1] & SCOPING_EL)) {                   $node->[1] & SCOPING_EL)) {
7411                !!!cp ('t433');                !!!cp ('t433');
7412                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
7413                                  text => $token->{tag_name}, token => $token);
7414                ## Ignore the token                ## Ignore the token
7415                !!!next-token;                !!!next-token;
7416                last S2;                last S2;
# Line 7325  sub set_inner_html ($$$) { Line 7546  sub set_inner_html ($$$) {
7546                  0x10FFFE => 1, 0x10FFFF => 1,                  0x10FFFE => 1, 0x10FFFF => 1,
7547                 }->{$self->{next_char}}) {                 }->{$self->{next_char}}) {
7548          !!!cp ('i4.1');          !!!cp ('i4.1');
7549          !!!parse-error (type => 'control char', level => $self->{must_level});          if ($self->{next_char} < 0x10000) {
7550  ## TODO: error type documentation            !!!parse-error (type => 'control char',
7551                              text => (sprintf 'U+%04X', $self->{next_char}));
7552            } else {
7553              !!!parse-error (type => 'control char',
7554                              text => (sprintf 'U-%08X', $self->{next_char}));
7555            }
7556        }        }
7557      };      };
7558      $p->{prev_char} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];

Legend:
Removed from v.1.140  
changed lines
  Added in v.1.160

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24