/[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.141 by wakaba, Sat May 24 10:18:26 2008 UTC revision 1.159 by wakaba, Fri Sep 5 17:57:47 2008 UTC
# Line 8  use Error qw(:try); Line 8  use Error qw(:try);
8  ## doc.write ('');  ## doc.write ('');
9  ## alert (doc.compatMode);  ## alert (doc.compatMode);
10    
 ## TODO: 1252 parse error (revision 1264)  
 ## TODO: 8859-11 = 874 (revision 1271)  
   
11  require IO::Handle;  require IO::Handle;
12    
13  my $HTML_NS = q<http://www.w3.org/1999/xhtml>;  my $HTML_NS = q<http://www.w3.org/1999/xhtml>;
# Line 48  sub MISC_SPECIAL_EL () { 0b1000000000000 Line 45  sub MISC_SPECIAL_EL () { 0b1000000000000
45  sub FOREIGN_EL () { 0b10000000000000000000000000 }  sub FOREIGN_EL () { 0b10000000000000000000000000 }
46  sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 }  sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 }
47  sub MML_AXML_EL () { 0b1000000000000000000000000000 }  sub MML_AXML_EL () { 0b1000000000000000000000000000 }
48    sub RUBY_EL () { 0b10000000000000000000000000000 }
49    sub RUBY_COMPONENT_EL () { 0b100000000000000000000000000000 }
50    
51  sub TABLE_ROWS_EL () {  sub TABLE_ROWS_EL () {
52    TABLE_EL |    TABLE_EL |
# Line 55  sub TABLE_ROWS_EL () { Line 54  sub TABLE_ROWS_EL () {
54    TABLE_ROW_GROUP_EL    TABLE_ROW_GROUP_EL
55  }  }
56    
57    ## NOTE: Used in "generate implied end tags" algorithm.
58    ## NOTE: There is a code where a modified version of END_TAG_OPTIONAL_EL
59    ## is used in "generate implied end tags" implementation (search for the
60    ## function mae).
61  sub END_TAG_OPTIONAL_EL () {  sub END_TAG_OPTIONAL_EL () {
62    DD_EL |    DD_EL |
63    DT_EL |    DT_EL |
64    LI_EL |    LI_EL |
65    P_EL    P_EL |
66      RUBY_COMPONENT_EL
67  }  }
68    
69    ## NOTE: Used in </body> and EOF algorithms.
70  sub ALL_END_TAG_OPTIONAL_EL () {  sub ALL_END_TAG_OPTIONAL_EL () {
71    END_TAG_OPTIONAL_EL |    DD_EL |
72      DT_EL |
73      LI_EL |
74      P_EL |
75    
76    BODY_EL |    BODY_EL |
77    HTML_EL |    HTML_EL |
78    TABLE_CELL_EL |    TABLE_CELL_EL |
# Line 99  sub SPECIAL_EL () { Line 108  sub SPECIAL_EL () {
108    ADDRESS_EL |    ADDRESS_EL |
109    BODY_EL |    BODY_EL |
110    DIV_EL |    DIV_EL |
111    END_TAG_OPTIONAL_EL |  
112      DD_EL |
113      DT_EL |
114      LI_EL |
115      P_EL |
116    
117    FORM_EL |    FORM_EL |
118    FRAMESET_EL |    FRAMESET_EL |
119    HEADING_EL |    HEADING_EL |
# Line 173  my $el_category = { Line 187  my $el_category = {
187    param => MISC_SPECIAL_EL,    param => MISC_SPECIAL_EL,
188    plaintext => MISC_SPECIAL_EL,    plaintext => MISC_SPECIAL_EL,
189    pre => MISC_SPECIAL_EL,    pre => MISC_SPECIAL_EL,
190      rp => RUBY_COMPONENT_EL,
191      rt => RUBY_COMPONENT_EL,
192      ruby => RUBY_EL,
193    s => FORMATTING_EL,    s => FORMATTING_EL,
194    script => MISC_SPECIAL_EL,    script => MISC_SPECIAL_EL,
195    select => SELECT_EL,    select => SELECT_EL,
# Line 214  my $el_category_f = { Line 231  my $el_category_f = {
231  };  };
232    
233  my $svg_attr_name = {  my $svg_attr_name = {
234      attributename => 'attributeName',
235    attributetype => 'attributeType',    attributetype => 'attributeType',
236    basefrequency => 'baseFrequency',    basefrequency => 'baseFrequency',
237    baseprofile => 'baseProfile',    baseprofile => 'baseProfile',
# Line 224  my $svg_attr_name = { Line 242  my $svg_attr_name = {
242    diffuseconstant => 'diffuseConstant',    diffuseconstant => 'diffuseConstant',
243    edgemode => 'edgeMode',    edgemode => 'edgeMode',
244    externalresourcesrequired => 'externalResourcesRequired',    externalresourcesrequired => 'externalResourcesRequired',
   fecolormatrix => 'feColorMatrix',  
   fecomposite => 'feComposite',  
   fegaussianblur => 'feGaussianBlur',  
   femorphology => 'feMorphology',  
   fetile => 'feTile',  
245    filterres => 'filterRes',    filterres => 'filterRes',
246    filterunits => 'filterUnits',    filterunits => 'filterUnits',
247    glyphref => 'glyphRef',    glyphref => 'glyphRef',
# Line 262  my $svg_attr_name = { Line 275  my $svg_attr_name = {
275    repeatcount => 'repeatCount',    repeatcount => 'repeatCount',
276    repeatdur => 'repeatDur',    repeatdur => 'repeatDur',
277    requiredextensions => 'requiredExtensions',    requiredextensions => 'requiredExtensions',
278      requiredfeatures => 'requiredFeatures',
279    specularconstant => 'specularConstant',    specularconstant => 'specularConstant',
280    specularexponent => 'specularExponent',    specularexponent => 'specularExponent',
281    spreadmethod => 'spreadMethod',    spreadmethod => 'spreadMethod',
# Line 429  sub parse_byte_stream ($$$$;$) { Line 443  sub parse_byte_stream ($$$$;$) {
443             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
444        if ($char_stream) {        if ($char_stream) {
445          $buffer->{buffer} = $byte_buffer;          $buffer->{buffer} = $byte_buffer;
446          !!!parse-error (type => 'sniffing:chardet', ## TODO: type name          !!!parse-error (type => 'sniffing:chardet',
447                          value => $charset_name,                          text => $charset_name,
448                          level => $self->{info_level},                          level => $self->{level}->{info},
449                            layer => 'encode',
450                          line => 1, column => 1);                          line => 1, column => 1);
451          $self->{confident} = 0;          $self->{confident} = 0;
452          last SNIFFING;          last SNIFFING;
# Line 452  sub parse_byte_stream ($$$$;$) { Line 467  sub parse_byte_stream ($$$$;$) {
467                                         allow_fallback => 1,                                         allow_fallback => 1,
468                                         byte_buffer => \$byte_buffer);                                         byte_buffer => \$byte_buffer);
469      $buffer->{buffer} = $byte_buffer;      $buffer->{buffer} = $byte_buffer;
470      !!!parse-error (type => 'sniffing:default', ## TODO: type name      !!!parse-error (type => 'sniffing:default',
471                      value => 'windows-1252',                      text => 'windows-1252',
472                      level => $self->{info_level},                      level => $self->{level}->{info},
473                      line => 1, column => 1);                      line => 1, column => 1,
474                        layer => 'encode');
475      $self->{confident} = 0;      $self->{confident} = 0;
476    } # SNIFFING    } # SNIFFING
477    
478    $self->{input_encoding} = $charset->get_iana_name;    $self->{input_encoding} = $charset->get_iana_name;
479    if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {    if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
480      !!!parse-error (type => 'chardecode:fallback', ## TODO: type name      !!!parse-error (type => 'chardecode:fallback',
481                      value => $self->{input_encoding},                      text => $self->{input_encoding},
482                      level => $self->{unsupported_level},                      level => $self->{level}->{uncertain},
483                      line => 1, column => 1);                      line => 1, column => 1,
484                        layer => 'encode');
485    } elsif (not ($e_status &    } elsif (not ($e_status &
486                  Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {                  Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
487      !!!parse-error (type => 'chardecode:no error', ## TODO: type name      !!!parse-error (type => 'chardecode:no error',
488                      value => $self->{input_encoding},                      text => $self->{input_encoding},
489                      level => $self->{unsupported_level},                      level => $self->{level}->{uncertain},
490                      line => 1, column => 1);                      line => 1, column => 1,
491                        layer => 'encode');
492    }    }
493    
494    $self->{change_encoding} = sub {    $self->{change_encoding} = sub {
# Line 487  sub parse_byte_stream ($$$$;$) { Line 505  sub parse_byte_stream ($$$$;$) {
505        ## "Change the encoding" algorithm:        ## "Change the encoding" algorithm:
506    
507        ## Step 1            ## Step 1    
508        if ($charset->{iana_names}->{'utf-16'}) { ## ISSUE: UTF-16BE -> UTF-8? UTF-16LE -> UTF-8?        if ($charset->{category} &
509              Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) {
510          $charset = Message::Charset::Info->get_by_iana_name ('utf-8');          $charset = Message::Charset::Info->get_by_iana_name ('utf-8');
511          ($char_stream, $e_status) = $charset->get_decode_handle          ($char_stream, $e_status) = $charset->get_decode_handle
512              ($byte_stream,              ($byte_stream,
# Line 498  sub parse_byte_stream ($$$$;$) { Line 517  sub parse_byte_stream ($$$$;$) {
517        ## Step 2        ## Step 2
518        if (defined $self->{input_encoding} and        if (defined $self->{input_encoding} and
519            $self->{input_encoding} eq $charset_name) {            $self->{input_encoding} eq $charset_name) {
520          !!!parse-error (type => 'charset label:matching', ## TODO: type          !!!parse-error (type => 'charset label:matching',
521                          value => $charset_name,                          text => $charset_name,
522                          level => $self->{info_level});                          level => $self->{level}->{info});
523          $self->{confident} = 1;          $self->{confident} = 1;
524          return;          return;
525        }        }
526    
527        !!!parse-error (type => 'charset label detected:'.$self->{input_encoding}.        !!!parse-error (type => 'charset label detected',
528            ':'.$charset_name, level => 'w', token => $token);                        text => $self->{input_encoding},
529                          value => $charset_name,
530                          level => $self->{level}->{warn},
531                          token => $token);
532                
533        ## Step 3        ## Step 3
534        # if (can) {        # if (can) {
# Line 522  sub parse_byte_stream ($$$$;$) { Line 544  sub parse_byte_stream ($$$$;$) {
544    
545    my $char_onerror = sub {    my $char_onerror = sub {
546      my (undef, $type, %opt) = @_;      my (undef, $type, %opt) = @_;
547      !!!parse-error (%opt, type => $type,      !!!parse-error (layer => 'encode',
548                        %opt, type => $type,
549                      line => $self->{line}, column => $self->{column} + 1);                      line => $self->{line}, column => $self->{column} + 1);
550      if ($opt{octets}) {      if ($opt{octets}) {
551        ${$opt{octets}} = "\x{FFFD}"; # relacement character        ${$opt{octets}} = "\x{FFFD}"; # relacement character
# Line 539  sub parse_byte_stream ($$$$;$) { Line 562  sub parse_byte_stream ($$$$;$) {
562    
563      $self->{input_encoding} = $charset->get_iana_name;      $self->{input_encoding} = $charset->get_iana_name;
564      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
565        !!!parse-error (type => 'chardecode:fallback', ## TODO: type name        !!!parse-error (type => 'chardecode:fallback',
566                        value => $self->{input_encoding},                        text => $self->{input_encoding},
567                        level => $self->{unsupported_level},                        level => $self->{level}->{uncertain},
568                        line => 1, column => 1);                        line => 1, column => 1,
569                          layer => 'encode');
570      } elsif (not ($e_status &      } elsif (not ($e_status &
571                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
572        !!!parse-error (type => 'chardecode:no error', ## TODO: type name        !!!parse-error (type => 'chardecode:no error',
573                        value => $self->{input_encoding},                        text => $self->{input_encoding},
574                        level => $self->{unsupported_level},                        level => $self->{level}->{uncertain},
575                        line => 1, column => 1);                        line => 1, column => 1,
576                          layer => 'encode');
577      }      }
578      $self->{confident} = 1;      $self->{confident} = 1;
579      $char_stream->onerror ($char_onerror);      $char_stream->onerror ($char_onerror);
# Line 647  sub parse_char_stream ($$$;$) { Line 672  sub parse_char_stream ($$$;$) {
672                0x10FFFE => 1, 0x10FFFF => 1,                0x10FFFE => 1, 0x10FFFF => 1,
673               }->{$self->{next_char}}) {               }->{$self->{next_char}}) {
674        !!!cp ('j5');        !!!cp ('j5');
675        !!!parse-error (type => 'control char', level => $self->{must_level});        if ($self->{next_char} < 0x10000) {
676  ## TODO: error type documentation          !!!parse-error (type => 'control char',
677                            text => (sprintf 'U+%04X', $self->{next_char}));
678          } else {
679            !!!parse-error (type => 'control char',
680                            text => (sprintf 'U-%08X', $self->{next_char}));
681          }
682      }      }
683    };    };
684    $self->{prev_char} = [-1, -1, -1];    $self->{prev_char} = [-1, -1, -1];
# Line 677  sub parse_char_stream ($$$;$) { Line 707  sub parse_char_stream ($$$;$) {
707  sub new ($) {  sub new ($) {
708    my $class = shift;    my $class = shift;
709    my $self = bless {    my $self = bless {
710      must_level => 'm',      level => {must => 'm',
711      should_level => 's',                should => 's',
712      good_level => 'w',                warn => 'w',
713      warn_level => 'w',                info => 'i',
714      info_level => 'i',                uncertain => 'u'},
     unsupported_level => 'u',  
715    }, $class;    }, $class;
716    $self->{set_next_char} = sub {    $self->{set_next_char} = sub {
717      $self->{next_char} = -1;      $self->{next_char} = -1;
# Line 829  sub _initialize_tokenizer ($) { Line 858  sub _initialize_tokenizer ($) {
858  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|
859  ##     while the token is pushed back to the stack.  ##     while the token is pushed back to the stack.
860    
 ## 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?  
   
861  ## Emitted token MUST immediately be handled by the tree construction state.  ## Emitted token MUST immediately be handled by the tree construction state.
862    
863  ## 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 1370  sub _get_next_token ($) {
1370          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
1371              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
1372            !!!cp (57);            !!!cp (57);
1373            !!!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});
1374            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{current_attribute} # MUST
1375          } else {          } else {
1376            !!!cp (58);            !!!cp (58);
# Line 1516  sub _get_next_token ($) { Line 1541  sub _get_next_token ($) {
1541    
1542          redo A;          redo A;
1543        } else {        } else {
1544          !!!cp (82);          if ($self->{next_char} == 0x0022 or # "
1545                $self->{next_char} == 0x0027) { # '
1546              !!!cp (78);
1547              !!!parse-error (type => 'bad attribute name');
1548            } else {
1549              !!!cp (82);
1550            }
1551          $self->{current_attribute}          $self->{current_attribute}
1552              = {name => chr ($self->{next_char}),              = {name => chr ($self->{next_char}),
1553                 value => '',                 value => '',
# Line 1551  sub _get_next_token ($) { Line 1582  sub _get_next_token ($) {
1582          !!!next-input-character;          !!!next-input-character;
1583          redo A;          redo A;
1584        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1585            !!!parse-error (type => 'empty unquoted attribute value');
1586          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1587            !!!cp (87);            !!!cp (87);
1588            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
# Line 2656  sub _get_next_token ($) { Line 2688  sub _get_next_token ($) {
2688          redo A;          redo A;
2689        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2690          !!!cp (208);          !!!cp (208);
2691          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2692    
2693          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2694          !!!next-input-character;          !!!next-input-character;
# Line 2692  sub _get_next_token ($) { Line 2724  sub _get_next_token ($) {
2724          redo A;          redo A;
2725        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2726          !!!cp (212);          !!!cp (212);
2727          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2728    
2729          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2730          !!!next-input-character;          !!!next-input-character;
# Line 2740  sub _get_next_token ($) { Line 2772  sub _get_next_token ($) {
2772        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
2773          !!!cp (217);          !!!cp (217);
2774          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
   
2775          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2776          ## reconsume          ## reconsume
2777    
# Line 2902  sub _tokenize_attempt_to_consume_an_enti Line 2933  sub _tokenize_attempt_to_consume_an_enti
2933    
2934          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2935            !!!cp (1008);            !!!cp (1008);
2936            !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
2937                              text => (sprintf 'U+%04X', $code),
2938                              line => $l, column => $c);
2939            $code = 0xFFFD;            $code = 0xFFFD;
2940          } elsif ($code > 0x10FFFF) {          } elsif ($code > 0x10FFFF) {
2941            !!!cp (1009);            !!!cp (1009);
2942            !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
2943                              text => (sprintf 'U-%08X', $code),
2944                              line => $l, column => $c);
2945            $code = 0xFFFD;            $code = 0xFFFD;
2946          } elsif ($code == 0x000D) {          } elsif ($code == 0x000D) {
2947            !!!cp (1010);            !!!cp (1010);
# Line 2914  sub _tokenize_attempt_to_consume_an_enti Line 2949  sub _tokenize_attempt_to_consume_an_enti
2949            $code = 0x000A;            $code = 0x000A;
2950          } elsif (0x80 <= $code and $code <= 0x9F) {          } elsif (0x80 <= $code and $code <= 0x9F) {
2951            !!!cp (1011);            !!!cp (1011);
2952            !!!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);
2953            $code = $c1_entity_char->{$code};            $code = $c1_entity_char->{$code};
2954          }          }
2955    
# Line 2947  sub _tokenize_attempt_to_consume_an_enti Line 2982  sub _tokenize_attempt_to_consume_an_enti
2982    
2983        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2984          !!!cp (1015);          !!!cp (1015);
2985          !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
2986                            text => (sprintf 'U+%04X', $code),
2987                            line => $l, column => $c);
2988          $code = 0xFFFD;          $code = 0xFFFD;
2989        } elsif ($code > 0x10FFFF) {        } elsif ($code > 0x10FFFF) {
2990          !!!cp (1016);          !!!cp (1016);
2991          !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
2992                            text => (sprintf 'U-%08X', $code),
2993                            line => $l, column => $c);
2994          $code = 0xFFFD;          $code = 0xFFFD;
2995        } elsif ($code == 0x000D) {        } elsif ($code == 0x000D) {
2996          !!!cp (1017);          !!!cp (1017);
2997          !!!parse-error (type => 'CR character reference', line => $l, column => $c);          !!!parse-error (type => 'CR character reference',
2998                            line => $l, column => $c);
2999          $code = 0x000A;          $code = 0x000A;
3000        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
3001          !!!cp (1018);          !!!cp (1018);
3002          !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'C1 character reference',
3003                            text => (sprintf 'U+%04X', $code),
3004                            line => $l, column => $c);
3005          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
3006        }        }
3007                
# Line 3057  sub _initialize_tree_constructor ($) { Line 3099  sub _initialize_tree_constructor ($) {
3099    ## TODO: Turn mutation events off # MUST    ## TODO: Turn mutation events off # MUST
3100    ## TODO: Turn loose Document option (manakai extension) on    ## TODO: Turn loose Document option (manakai extension) on
3101    $self->{document}->manakai_is_html (1); # MUST    $self->{document}->manakai_is_html (1); # MUST
3102      $self->{document}->set_user_data (manakai_source_line => 1);
3103      $self->{document}->set_user_data (manakai_source_column => 1);
3104  } # _initialize_tree_constructor  } # _initialize_tree_constructor
3105    
3106  sub _terminate_tree_constructor ($) {  sub _terminate_tree_constructor ($) {
# Line 3111  sub _tree_construction_initial ($) { Line 3155  sub _tree_construction_initial ($) {
3155        ## language.        ## language.
3156        my $doctype_name = $token->{name};        my $doctype_name = $token->{name};
3157        $doctype_name = '' unless defined $doctype_name;        $doctype_name = '' unless defined $doctype_name;
3158        $doctype_name =~ tr/a-z/A-Z/;        $doctype_name =~ tr/a-z/A-Z/; # ASCII case-insensitive
3159        if (not defined $token->{name} or # <!DOCTYPE>        if (not defined $token->{name} or # <!DOCTYPE>
           defined $token->{public_identifier} or  
3160            defined $token->{system_identifier}) {            defined $token->{system_identifier}) {
3161          !!!cp ('t1');          !!!cp ('t1');
3162          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3163        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
3164          !!!cp ('t2');          !!!cp ('t2');
         ## ISSUE: ASCII case-insensitive? (in fact it does not matter)  
3165          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3166          } elsif (defined $token->{public_identifier}) {
3167            if ($token->{public_identifier} eq 'XSLT-compat') {
3168              !!!cp ('t1.2');
3169              !!!parse-error (type => 'XSLT-compat', token => $token,
3170                              level => $self->{level}->{should});
3171            } else {
3172              !!!parse-error (type => 'not HTML5', token => $token);
3173            }
3174        } else {        } else {
3175          !!!cp ('t3');          !!!cp ('t3');
3176            #
3177        }        }
3178                
3179        my $doctype = $self->{document}->create_document_type_definition        my $doctype = $self->{document}->create_document_type_definition
# Line 3143  sub _tree_construction_initial ($) { Line 3194  sub _tree_construction_initial ($) {
3194        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{public_identifier}) {
3195          my $pubid = $token->{public_identifier};          my $pubid = $token->{public_identifier};
3196          $pubid =~ tr/a-z/A-z/;          $pubid =~ tr/a-z/A-z/;
3197          if ({          my $prefix = [
3198            "+//SILMARIL//DTD HTML PRO V0R11 19970101//EN" => 1,            "+//SILMARIL//DTD HTML PRO V0R11 19970101//",
3199            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3200            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3201            "-//IETF//DTD HTML 2.0 LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 1//",
3202            "-//IETF//DTD HTML 2.0 LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 2//",
3203            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//",
3204            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//",
3205            "-//IETF//DTD HTML 2.0 STRICT//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT//",
3206            "-//IETF//DTD HTML 2.0//EN" => 1,            "-//IETF//DTD HTML 2.0//",
3207            "-//IETF//DTD HTML 2.1E//EN" => 1,            "-//IETF//DTD HTML 2.1E//",
3208            "-//IETF//DTD HTML 3.0//EN" => 1,            "-//IETF//DTD HTML 3.0//",
3209            "-//IETF//DTD HTML 3.0//EN//" => 1,            "-//IETF//DTD HTML 3.2 FINAL//",
3210            "-//IETF//DTD HTML 3.2 FINAL//EN" => 1,            "-//IETF//DTD HTML 3.2//",
3211            "-//IETF//DTD HTML 3.2//EN" => 1,            "-//IETF//DTD HTML 3//",
3212            "-//IETF//DTD HTML 3//EN" => 1,            "-//IETF//DTD HTML LEVEL 0//",
3213            "-//IETF//DTD HTML LEVEL 0//EN" => 1,            "-//IETF//DTD HTML LEVEL 1//",
3214            "-//IETF//DTD HTML LEVEL 0//EN//2.0" => 1,            "-//IETF//DTD HTML LEVEL 2//",
3215            "-//IETF//DTD HTML LEVEL 1//EN" => 1,            "-//IETF//DTD HTML LEVEL 3//",
3216            "-//IETF//DTD HTML LEVEL 1//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 0//",
3217            "-//IETF//DTD HTML LEVEL 2//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 1//",
3218            "-//IETF//DTD HTML LEVEL 2//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 2//",
3219            "-//IETF//DTD HTML LEVEL 3//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 3//",
3220            "-//IETF//DTD HTML LEVEL 3//EN//3.0" => 1,            "-//IETF//DTD HTML STRICT//",
3221            "-//IETF//DTD HTML STRICT LEVEL 0//EN" => 1,            "-//IETF//DTD HTML//",
3222            "-//IETF//DTD HTML STRICT LEVEL 0//EN//2.0" => 1,            "-//METRIUS//DTD METRIUS PRESENTATIONAL//",
3223            "-//IETF//DTD HTML STRICT LEVEL 1//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//",
3224            "-//IETF//DTD HTML STRICT LEVEL 1//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//",
3225            "-//IETF//DTD HTML STRICT LEVEL 2//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//",
3226            "-//IETF//DTD HTML STRICT LEVEL 2//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//",
3227            "-//IETF//DTD HTML STRICT LEVEL 3//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//",
3228            "-//IETF//DTD HTML STRICT LEVEL 3//EN//3.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//",
3229            "-//IETF//DTD HTML STRICT//EN" => 1,            "-//NETSCAPE COMM. CORP.//DTD HTML//",
3230            "-//IETF//DTD HTML STRICT//EN//2.0" => 1,            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//",
3231            "-//IETF//DTD HTML STRICT//EN//3.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//",
3232            "-//IETF//DTD HTML//EN" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//",
3233            "-//IETF//DTD HTML//EN//2.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//",
3234            "-//IETF//DTD HTML//EN//3.0" => 1,            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//",
3235            "-//METRIUS//DTD METRIUS PRESENTATIONAL//EN" => 1,            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//",
3236            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//EN" => 1,            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//",
3237            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//EN" => 1,            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//",
3238            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//",
3239            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//",
3240            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//EN" => 1,            "-//W3C//DTD HTML 3 1995-03-24//",
3241            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//EN" => 1,            "-//W3C//DTD HTML 3.2 DRAFT//",
3242            "-//NETSCAPE COMM. CORP.//DTD HTML//EN" => 1,            "-//W3C//DTD HTML 3.2 FINAL//",
3243            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//EN" => 1,            "-//W3C//DTD HTML 3.2//",
3244            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//EN" => 1,            "-//W3C//DTD HTML 3.2S DRAFT//",
3245            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 FRAMESET//",
3246            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 TRANSITIONAL//",
3247            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMETNAL 19960712//",
3248            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMENTAL 970421//",
3249            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//EN" => 1,            "-//W3C//DTD W3 HTML//",
3250            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//EN" => 1,            "-//W3O//DTD W3 HTML 3.0//",
3251            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML 2.0//",
3252            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML//",
3253            "-//W3C//DTD HTML 3 1995-03-24//EN" => 1,          ]; # $prefix
3254            "-//W3C//DTD HTML 3.2 DRAFT//EN" => 1,          my $match;
3255            "-//W3C//DTD HTML 3.2 FINAL//EN" => 1,          for (@$prefix) {
3256            "-//W3C//DTD HTML 3.2//EN" => 1,            if (substr ($prefix, 0, length $_) eq $_) {
3257            "-//W3C//DTD HTML 3.2S DRAFT//EN" => 1,              $match = 1;
3258            "-//W3C//DTD HTML 4.0 FRAMESET//EN" => 1,              last;
3259            "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN" => 1,            }
3260            "-//W3C//DTD HTML EXPERIMETNAL 19960712//EN" => 1,          }
3261            "-//W3C//DTD HTML EXPERIMENTAL 970421//EN" => 1,          if ($match or
3262            "-//W3C//DTD W3 HTML//EN" => 1,              $pubid eq "-//W3O//DTD W3 HTML STRICT 3.0//EN//" or
3263            "-//W3O//DTD W3 HTML 3.0//EN" => 1,              $pubid eq "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" or
3264            "-//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}) {  
3265            !!!cp ('t5');            !!!cp ('t5');
3266            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3267          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD HTML 4.01 FRAMESET//] or
3268                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD HTML 4.01 TRANSITIONAL//]) {
3269            if (defined $token->{system_identifier}) {            if (defined $token->{system_identifier}) {
3270              !!!cp ('t6');              !!!cp ('t6');
3271              $self->{document}->manakai_compat_mode ('quirks');              $self->{document}->manakai_compat_mode ('quirks');
# Line 3228  sub _tree_construction_initial ($) { Line 3273  sub _tree_construction_initial ($) {
3273              !!!cp ('t7');              !!!cp ('t7');
3274              $self->{document}->manakai_compat_mode ('limited quirks');              $self->{document}->manakai_compat_mode ('limited quirks');
3275            }            }
3276          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD XHTML 1.0 FRAMESET//] or
3277                   $pubid eq "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD XHTML 1.0 TRANSITIONAL//]) {
3278            !!!cp ('t8');            !!!cp ('t8');
3279            $self->{document}->manakai_compat_mode ('limited quirks');            $self->{document}->manakai_compat_mode ('limited quirks');
3280          } else {          } else {
# Line 3242  sub _tree_construction_initial ($) { Line 3287  sub _tree_construction_initial ($) {
3287          my $sysid = $token->{system_identifier};          my $sysid = $token->{system_identifier};
3288          $sysid =~ tr/A-Z/a-z/;          $sysid =~ tr/A-Z/a-z/;
3289          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") {
3290            ## TODO: Check the spec: PUBLIC "(limited quirks)" "(quirks)"            ## NOTE: Ensure that |PUBLIC "(limited quirks)" "(quirks)"| is
3291              ## marked as quirks.
3292            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3293            !!!cp ('t11');            !!!cp ('t11');
3294          } else {          } else {
# Line 3428  sub _reset_insertion_mode ($) { Line 3474  sub _reset_insertion_mode ($) {
3474          ## NOTE: Strictly spaking, the line below only applies to MathML and          ## NOTE: Strictly spaking, the line below only applies to MathML and
3475          ## SVG elements.  Currently the HTML syntax supports only MathML and          ## SVG elements.  Currently the HTML syntax supports only MathML and
3476          ## SVG elements as foreigners.          ## SVG elements as foreigners.
3477          $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?  
3478        } elsif ($node->[1] & TABLE_CELL_EL) {        } elsif ($node->[1] & TABLE_CELL_EL) {
3479          if ($last) {          if ($last) {
3480            !!!cp ('t28.2');            !!!cp ('t28.2');
# Line 3630  sub _tree_construction_main ($) { Line 3675  sub _tree_construction_main ($) {
3675        ## NOTE: An end-of-file token.        ## NOTE: An end-of-file token.
3676        if ($content_model_flag == CDATA_CONTENT_MODEL) {        if ($content_model_flag == CDATA_CONTENT_MODEL) {
3677          !!!cp ('t43');          !!!cp ('t43');
3678          !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in CDATA:#eof', token => $token);
3679        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
3680          !!!cp ('t44');          !!!cp ('t44');
3681          !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in RCDATA:#eof', token => $token);
3682        } else {        } else {
3683          die "$0: $content_model_flag in parse_rcdata";          die "$0: $content_model_flag in parse_rcdata";
3684        }        }
# Line 3670  sub _tree_construction_main ($) { Line 3715  sub _tree_construction_main ($) {
3715        ## Ignore the token        ## Ignore the token
3716      } else {      } else {
3717        !!!cp ('t48');        !!!cp ('t48');
3718        !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);        !!!parse-error (type => 'in CDATA:#eof', token => $token);
3719        ## ISSUE: And ignore?        ## ISSUE: And ignore?
3720        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
3721      }      }
# Line 3721  sub _tree_construction_main ($) { Line 3766  sub _tree_construction_main ($) {
3766        } # AFE        } # AFE
3767        unless (defined $formatting_element) {        unless (defined $formatting_element) {
3768          !!!cp ('t53');          !!!cp ('t53');
3769          !!!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);
3770          ## Ignore the token          ## Ignore the token
3771          !!!next-token;          !!!next-token;
3772          return;          return;
# Line 3738  sub _tree_construction_main ($) { Line 3783  sub _tree_construction_main ($) {
3783              last INSCOPE;              last INSCOPE;
3784            } else { # in open elements but not in scope            } else { # in open elements but not in scope
3785              !!!cp ('t55');              !!!cp ('t55');
3786              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},              !!!parse-error (type => 'unmatched end tag',
3787                                text => $token->{tag_name},
3788                              token => $end_tag_token);                              token => $end_tag_token);
3789              ## Ignore the token              ## Ignore the token
3790              !!!next-token;              !!!next-token;
# Line 3751  sub _tree_construction_main ($) { Line 3797  sub _tree_construction_main ($) {
3797        } # INSCOPE        } # INSCOPE
3798        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
3799          !!!cp ('t57');          !!!cp ('t57');
3800          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},          !!!parse-error (type => 'unmatched end tag',
3801                            text => $token->{tag_name},
3802                          token => $end_tag_token);                          token => $end_tag_token);
3803          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
3804          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
# Line 3760  sub _tree_construction_main ($) { Line 3807  sub _tree_construction_main ($) {
3807        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
3808          !!!cp ('t58');          !!!cp ('t58');
3809          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
3810                          value => $self->{open_elements}->[-1]->[0]                          text => $self->{open_elements}->[-1]->[0]
3811                              ->manakai_local_name,                              ->manakai_local_name,
3812                          token => $end_tag_token);                          token => $end_tag_token);
3813        }        }
# Line 3969  sub _tree_construction_main ($) { Line 4016  sub _tree_construction_main ($) {
4016    B: while (1) {    B: while (1) {
4017      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
4018        !!!cp ('t73');        !!!cp ('t73');
4019        !!!parse-error (type => 'DOCTYPE in the middle', token => $token);        !!!parse-error (type => 'in html:#DOCTYPE', token => $token);
4020        ## Ignore the token        ## Ignore the token
4021        ## Stay in the phase        ## Stay in the phase
4022        !!!next-token;        !!!next-token;
# Line 3978  sub _tree_construction_main ($) { Line 4025  sub _tree_construction_main ($) {
4025               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
4026        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
4027          !!!cp ('t79');          !!!cp ('t79');
4028          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4029          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
4030        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
4031          !!!cp ('t80');          !!!cp ('t80');
4032          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4033          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
4034        } else {        } else {
4035          !!!cp ('t81');          !!!cp ('t81');
# Line 4033  sub _tree_construction_main ($) { Line 4080  sub _tree_construction_main ($) {
4080            #            #
4081          } elsif ({          } elsif ({
4082                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,
4083                    center => 1, code => 1, dd => 1, div => 1, dl => 1, em => 1,                    center => 1, code => 1, dd => 1, div => 1, dl => 1, dt => 1,
4084                    embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1, ## No h4!                    em => 1, embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1,
4085                    h5 => 1, h6 => 1, head => 1, hr => 1, i => 1, img => 1,                    h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, i => 1,
4086                    li => 1, menu => 1, meta => 1, nobr => 1, p => 1, pre => 1,                    img => 1, li => 1, listing => 1, menu => 1, meta => 1,
4087                    ruby => 1, s => 1, small => 1, span => 1, strong => 1,                    nobr => 1, ol => 1, p => 1, pre => 1, ruby => 1, s => 1,
4088                    sub => 1, sup => 1, table => 1, tt => 1, u => 1, ul => 1,                    small => 1, span => 1, strong => 1, strike => 1, sub => 1,
4089                    var => 1,                    sup => 1, table => 1, tt => 1, u => 1, ul => 1, var => 1,
4090                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
4091            !!!cp ('t87.2');            !!!cp ('t87.2');
4092            !!!parse-error (type => 'not closed',            !!!parse-error (type => 'not closed',
4093                            value => $self->{open_elements}->[-1]->[0]                            text => $self->{open_elements}->[-1]->[0]
4094                                ->manakai_local_name,                                ->manakai_local_name,
4095                            token => $token);                            token => $token);
4096    
# Line 4119  sub _tree_construction_main ($) { Line 4166  sub _tree_construction_main ($) {
4166          !!!cp ('t87.5');          !!!cp ('t87.5');
4167          #          #
4168        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
         ## NOTE: "using the rules for secondary insertion mode" then "continue"  
4169          !!!cp ('t87.6');          !!!cp ('t87.6');
4170          #          !!!parse-error (type => 'not closed',
4171          ## TODO: ...                          text => $self->{open_elements}->[-1]->[0]
4172                                ->manakai_local_name,
4173                            token => $token);
4174    
4175            pop @{$self->{open_elements}}
4176                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;
4177    
4178            $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
4179            ## Reprocess.
4180            next B;
4181        } else {        } else {
4182          die "$0: $token->{type}: Unknown token type";                  die "$0: $token->{type}: Unknown token type";        
4183        }        }
# Line 4163  sub _tree_construction_main ($) { Line 4218  sub _tree_construction_main ($) {
4218            !!!cp ('t90');            !!!cp ('t90');
4219            ## As if </noscript>            ## As if </noscript>
4220            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
4221            !!!parse-error (type => 'in noscript:#character', token => $token);            !!!parse-error (type => 'in noscript:#text', token => $token);
4222                        
4223            ## Reprocess in the "in head" insertion mode...            ## Reprocess in the "in head" insertion mode...
4224            ## As if </head>            ## As if </head>
# Line 4200  sub _tree_construction_main ($) { Line 4255  sub _tree_construction_main ($) {
4255              next B;              next B;
4256            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4257              !!!cp ('t93.2');              !!!cp ('t93.2');
4258              !!!parse-error (type => 'after head:head', token => $token); ## TODO: error type              !!!parse-error (type => 'after head', text => 'head',
4259                                token => $token);
4260              ## Ignore the token              ## Ignore the token
4261              !!!nack ('t93.3');              !!!nack ('t93.3');
4262              !!!next-token;              !!!next-token;
4263              next B;              next B;
4264            } else {            } else {
4265              !!!cp ('t95');              !!!cp ('t95');
4266              !!!parse-error (type => 'in head:head', token => $token); # or in head noscript              !!!parse-error (type => 'in head:head',
4267                                token => $token); # or in head noscript
4268              ## Ignore the token              ## Ignore the token
4269              !!!nack ('t95.1');              !!!nack ('t95.1');
4270              !!!next-token;              !!!next-token;
# Line 4232  sub _tree_construction_main ($) { Line 4289  sub _tree_construction_main ($) {
4289                  !!!cp ('t98');                  !!!cp ('t98');
4290                  ## As if </noscript>                  ## As if </noscript>
4291                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4292                  !!!parse-error (type => 'in noscript:base', token => $token);                  !!!parse-error (type => 'in noscript', text => 'base',
4293                                    token => $token);
4294                                
4295                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4296                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
# Line 4243  sub _tree_construction_main ($) { Line 4301  sub _tree_construction_main ($) {
4301                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4302                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4303                  !!!cp ('t100');                  !!!cp ('t100');
4304                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4305                                    text => $token->{tag_name}, token => $token);
4306                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4307                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4308                } else {                } else {
# Line 4260  sub _tree_construction_main ($) { Line 4319  sub _tree_construction_main ($) {
4319                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4320                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4321                  !!!cp ('t102');                  !!!cp ('t102');
4322                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4323                                    text => $token->{tag_name}, token => $token);
4324                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4325                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4326                } else {                } else {
# Line 4277  sub _tree_construction_main ($) { Line 4337  sub _tree_construction_main ($) {
4337                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4338                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4339                  !!!cp ('t104');                  !!!cp ('t104');
4340                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4341                                    text => $token->{tag_name}, token => $token);
4342                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4343                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4344                } else {                } else {
# Line 4301  sub _tree_construction_main ($) { Line 4362  sub _tree_construction_main ($) {
4362                                                 ->{has_reference});                                                 ->{has_reference});
4363                  } elsif ($token->{attributes}->{content}) {                  } elsif ($token->{attributes}->{content}) {
4364                    if ($token->{attributes}->{content}->{value}                    if ($token->{attributes}->{content}->{value}
4365                        =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                        =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
4366                            [\x09-\x0D\x20]*=                            [\x09-\x0D\x20]*=
4367                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
4368                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
4369                      !!!cp ('t107');                      !!!cp ('t107');
4370                      ## NOTE: Whether the encoding is supported or not is handled                      ## NOTE: Whether the encoding is supported or not is handled
4371                      ## in the {change_encoding} callback.                      ## in the {change_encoding} callback.
# Line 4346  sub _tree_construction_main ($) { Line 4407  sub _tree_construction_main ($) {
4407                  !!!cp ('t111');                  !!!cp ('t111');
4408                  ## As if </noscript>                  ## As if </noscript>
4409                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4410                  !!!parse-error (type => 'in noscript:title', token => $token);                  !!!parse-error (type => 'in noscript', text => 'title',
4411                                    token => $token);
4412                                
4413                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4414                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4415                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4416                  !!!cp ('t112');                  !!!cp ('t112');
4417                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4418                                    text => $token->{tag_name}, token => $token);
4419                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4420                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4421                } else {                } else {
# Line 4366  sub _tree_construction_main ($) { Line 4429  sub _tree_construction_main ($) {
4429                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4430                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4431                next B;                next B;
4432              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style' or
4433                         $token->{tag_name} eq 'noframes') {
4434                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and
4435                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
4436                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4437                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4438                  !!!cp ('t114');                  !!!cp ('t114');
4439                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4440                                    text => $token->{tag_name}, token => $token);
4441                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4442                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4443                } else {                } else {
# Line 4393  sub _tree_construction_main ($) { Line 4458  sub _tree_construction_main ($) {
4458                  next B;                  next B;
4459                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4460                  !!!cp ('t117');                  !!!cp ('t117');
4461                  !!!parse-error (type => 'in noscript:noscript', token => $token);                  !!!parse-error (type => 'in noscript', text => 'noscript',
4462                                    token => $token);
4463                  ## Ignore the token                  ## Ignore the token
4464                  !!!nack ('t117.1');                  !!!nack ('t117.1');
4465                  !!!next-token;                  !!!next-token;
# Line 4407  sub _tree_construction_main ($) { Line 4473  sub _tree_construction_main ($) {
4473                  !!!cp ('t119');                  !!!cp ('t119');
4474                  ## As if </noscript>                  ## As if </noscript>
4475                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4476                  !!!parse-error (type => 'in noscript:script', token => $token);                  !!!parse-error (type => 'in noscript', text => 'script',
4477                                    token => $token);
4478                                
4479                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4480                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4481                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4482                  !!!cp ('t120');                  !!!cp ('t120');
4483                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4484                                    text => $token->{tag_name}, token => $token);
4485                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4486                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4487                } else {                } else {
# Line 4431  sub _tree_construction_main ($) { Line 4499  sub _tree_construction_main ($) {
4499                  !!!cp ('t122');                  !!!cp ('t122');
4500                  ## As if </noscript>                  ## As if </noscript>
4501                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4502                  !!!parse-error (type => 'in noscript:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in noscript',
4503                                    text => $token->{tag_name}, token => $token);
4504                                    
4505                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4506                  ## As if </head>                  ## As if </head>
# Line 4470  sub _tree_construction_main ($) { Line 4539  sub _tree_construction_main ($) {
4539                !!!cp ('t129');                !!!cp ('t129');
4540                ## As if </noscript>                ## As if </noscript>
4541                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4542                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4543                                  text => $token->{tag_name}, token => $token);
4544                                
4545                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4546                ## As if </head>                ## As if </head>
# Line 4513  sub _tree_construction_main ($) { Line 4583  sub _tree_construction_main ($) {
4583                  !!!cp ('t133');                  !!!cp ('t133');
4584                  ## As if </noscript>                  ## As if </noscript>
4585                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4586                  !!!parse-error (type => 'in noscript:/head', token => $token);                  !!!parse-error (type => 'in noscript:/',
4587                                    text => 'head', token => $token);
4588                                    
4589                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4590                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 4528  sub _tree_construction_main ($) { Line 4599  sub _tree_construction_main ($) {
4599                  next B;                  next B;
4600                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4601                  !!!cp ('t134.1');                  !!!cp ('t134.1');
4602                  !!!parse-error (type => 'unmatched end tag:head', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'head',
4603                                    token => $token);
4604                  ## Ignore the token                  ## Ignore the token
4605                  !!!next-token;                  !!!next-token;
4606                  next B;                  next B;
# Line 4545  sub _tree_construction_main ($) { Line 4617  sub _tree_construction_main ($) {
4617                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or
4618                         $self->{insertion_mode} == AFTER_HEAD_IM) {                         $self->{insertion_mode} == AFTER_HEAD_IM) {
4619                  !!!cp ('t137');                  !!!cp ('t137');
4620                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4621                                    text => 'noscript', token => $token);
4622                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
4623                  !!!next-token;                  !!!next-token;
4624                  next B;                  next B;
# Line 4560  sub _tree_construction_main ($) { Line 4633  sub _tree_construction_main ($) {
4633                    $self->{insertion_mode} == IN_HEAD_IM or                    $self->{insertion_mode} == IN_HEAD_IM or
4634                    $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                    $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4635                  !!!cp ('t140');                  !!!cp ('t140');
4636                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4637                                    text => $token->{tag_name}, token => $token);
4638                  ## Ignore the token                  ## Ignore the token
4639                  !!!next-token;                  !!!next-token;
4640                  next B;                  next B;
4641                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4642                  !!!cp ('t140.1');                  !!!cp ('t140.1');
4643                  !!!parse-error (type => 'unmatched end tag:' . $token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4644                                    text => $token->{tag_name}, token => $token);
4645                  ## Ignore the token                  ## Ignore the token
4646                  !!!next-token;                  !!!next-token;
4647                  next B;                  next B;
# Line 4575  sub _tree_construction_main ($) { Line 4650  sub _tree_construction_main ($) {
4650                }                }
4651              } elsif ($token->{tag_name} eq 'p') {              } elsif ($token->{tag_name} eq 'p') {
4652                !!!cp ('t142');                !!!cp ('t142');
4653                !!!parse-error (type => 'unmatched end tag:p', token => $token);                !!!parse-error (type => 'unmatched end tag',
4654                                  text => $token->{tag_name}, token => $token);
4655                ## Ignore the token                ## Ignore the token
4656                !!!next-token;                !!!next-token;
4657                next B;                next B;
# Line 4598  sub _tree_construction_main ($) { Line 4674  sub _tree_construction_main ($) {
4674                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4675                  !!!cp ('t143.3');                  !!!cp ('t143.3');
4676                  ## ISSUE: Two parse errors for <head><noscript></br>                  ## ISSUE: Two parse errors for <head><noscript></br>
4677                  !!!parse-error (type => 'unmatched end tag:br', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4678                                    text => 'br', token => $token);
4679                  ## As if </noscript>                  ## As if </noscript>
4680                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4681                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
# Line 4617  sub _tree_construction_main ($) { Line 4694  sub _tree_construction_main ($) {
4694                }                }
4695    
4696                ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.                ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.
4697                !!!parse-error (type => 'unmatched end tag:br', token => $token);                !!!parse-error (type => 'unmatched end tag',
4698                                  text => 'br', token => $token);
4699                ## Ignore the token                ## Ignore the token
4700                !!!next-token;                !!!next-token;
4701                next B;                next B;
4702              } else {              } else {
4703                !!!cp ('t145');                !!!cp ('t145');
4704                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
4705                                  text => $token->{tag_name}, token => $token);
4706                ## Ignore the token                ## Ignore the token
4707                !!!next-token;                !!!next-token;
4708                next B;                next B;
# Line 4633  sub _tree_construction_main ($) { Line 4712  sub _tree_construction_main ($) {
4712                !!!cp ('t146');                !!!cp ('t146');
4713                ## As if </noscript>                ## As if </noscript>
4714                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4715                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4716                                  text => $token->{tag_name}, token => $token);
4717                                
4718                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4719                ## As if </head>                ## As if </head>
# Line 4649  sub _tree_construction_main ($) { Line 4729  sub _tree_construction_main ($) {
4729              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4730  ## ISSUE: This case cannot be reached?  ## ISSUE: This case cannot be reached?
4731                !!!cp ('t148');                !!!cp ('t148');
4732                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
4733                                  text => $token->{tag_name}, token => $token);
4734                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
4735                !!!next-token;                !!!next-token;
4736                next B;                next B;
# Line 4760  sub _tree_construction_main ($) { Line 4841  sub _tree_construction_main ($) {
4841    
4842                  !!!cp ('t153');                  !!!cp ('t153');
4843                  !!!parse-error (type => 'start tag not allowed',                  !!!parse-error (type => 'start tag not allowed',
4844                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
4845                  ## Ignore the token                  ## Ignore the token
4846                  !!!nack ('t153.1');                  !!!nack ('t153.1');
4847                  !!!next-token;                  !!!next-token;
4848                  next B;                  next B;
4849                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4850                  !!!parse-error (type => 'not closed:caption', token => $token);                  !!!parse-error (type => 'not closed', text => 'caption',
4851                                    token => $token);
4852                                    
4853                  ## NOTE: As if </caption>.                  ## NOTE: As if </caption>.
4854                  ## have a table element in table scope                  ## have a table element in table scope
# Line 4786  sub _tree_construction_main ($) { Line 4868  sub _tree_construction_main ($) {
4868    
4869                    !!!cp ('t157');                    !!!cp ('t157');
4870                    !!!parse-error (type => 'start tag not allowed',                    !!!parse-error (type => 'start tag not allowed',
4871                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
4872                    ## Ignore the token                    ## Ignore the token
4873                    !!!nack ('t157.1');                    !!!nack ('t157.1');
4874                    !!!next-token;                    !!!next-token;
# Line 4803  sub _tree_construction_main ($) { Line 4885  sub _tree_construction_main ($) {
4885                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
4886                    !!!cp ('t159');                    !!!cp ('t159');
4887                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
4888                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
4889                                        ->manakai_local_name,                                        ->manakai_local_name,
4890                                    token => $token);                                    token => $token);
4891                  } else {                  } else {
# Line 4845  sub _tree_construction_main ($) { Line 4927  sub _tree_construction_main ($) {
4927                  } # INSCOPE                  } # INSCOPE
4928                    unless (defined $i) {                    unless (defined $i) {
4929                      !!!cp ('t165');                      !!!cp ('t165');
4930                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
4931                                        text => $token->{tag_name},
4932                                        token => $token);
4933                      ## Ignore the token                      ## Ignore the token
4934                      !!!next-token;                      !!!next-token;
4935                      next B;                      next B;
# Line 4862  sub _tree_construction_main ($) { Line 4946  sub _tree_construction_main ($) {
4946                          ne $token->{tag_name}) {                          ne $token->{tag_name}) {
4947                    !!!cp ('t167');                    !!!cp ('t167');
4948                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
4949                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
4950                                        ->manakai_local_name,                                        ->manakai_local_name,
4951                                    token => $token);                                    token => $token);
4952                  } else {                  } else {
# Line 4879  sub _tree_construction_main ($) { Line 4963  sub _tree_construction_main ($) {
4963                  next B;                  next B;
4964                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4965                  !!!cp ('t169');                  !!!cp ('t169');
4966                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4967                                    text => $token->{tag_name}, token => $token);
4968                  ## Ignore the token                  ## Ignore the token
4969                  !!!next-token;                  !!!next-token;
4970                  next B;                  next B;
# Line 4906  sub _tree_construction_main ($) { Line 4991  sub _tree_construction_main ($) {
4991    
4992                    !!!cp ('t173');                    !!!cp ('t173');
4993                    !!!parse-error (type => 'unmatched end tag',                    !!!parse-error (type => 'unmatched end tag',
4994                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
4995                    ## Ignore the token                    ## Ignore the token
4996                    !!!next-token;                    !!!next-token;
4997                    next B;                    next B;
# Line 4922  sub _tree_construction_main ($) { Line 5007  sub _tree_construction_main ($) {
5007                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5008                    !!!cp ('t175');                    !!!cp ('t175');
5009                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5010                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5011                                        ->manakai_local_name,                                        ->manakai_local_name,
5012                                    token => $token);                                    token => $token);
5013                  } else {                  } else {
# Line 4939  sub _tree_construction_main ($) { Line 5024  sub _tree_construction_main ($) {
5024                  next B;                  next B;
5025                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
5026                  !!!cp ('t177');                  !!!cp ('t177');
5027                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5028                                    text => $token->{tag_name}, token => $token);
5029                  ## Ignore the token                  ## Ignore the token
5030                  !!!next-token;                  !!!next-token;
5031                  next B;                  next B;
# Line 4982  sub _tree_construction_main ($) { Line 5068  sub _tree_construction_main ($) {
5068    
5069                  !!!cp ('t182');                  !!!cp ('t182');
5070                  !!!parse-error (type => 'unmatched end tag',                  !!!parse-error (type => 'unmatched end tag',
5071                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
5072                  ## Ignore the token                  ## Ignore the token
5073                  !!!next-token;                  !!!next-token;
5074                  next B;                  next B;
5075                } # INSCOPE                } # INSCOPE
5076              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
5077                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5078                !!!parse-error (type => 'not closed:caption', token => $token);                !!!parse-error (type => 'not closed', text => 'caption',
5079                                  token => $token);
5080    
5081                ## As if </caption>                ## As if </caption>
5082                ## have a table element in table scope                ## have a table element in table scope
# Line 5007  sub _tree_construction_main ($) { Line 5094  sub _tree_construction_main ($) {
5094                } # INSCOPE                } # INSCOPE
5095                unless (defined $i) {                unless (defined $i) {
5096                  !!!cp ('t186');                  !!!cp ('t186');
5097                  !!!parse-error (type => 'unmatched end tag:caption', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5098                                    text => 'caption', token => $token);
5099                  ## Ignore the token                  ## Ignore the token
5100                  !!!next-token;                  !!!next-token;
5101                  next B;                  next B;
# Line 5022  sub _tree_construction_main ($) { Line 5110  sub _tree_construction_main ($) {
5110                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5111                  !!!cp ('t188');                  !!!cp ('t188');
5112                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5113                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5114                                      ->manakai_local_name,                                      ->manakai_local_name,
5115                                  token => $token);                                  token => $token);
5116                } else {                } else {
# Line 5042  sub _tree_construction_main ($) { Line 5130  sub _tree_construction_main ($) {
5130                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5131                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
5132                  !!!cp ('t190');                  !!!cp ('t190');
5133                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5134                                    text => $token->{tag_name}, token => $token);
5135                  ## Ignore the token                  ## Ignore the token
5136                  !!!next-token;                  !!!next-token;
5137                  next B;                  next B;
# Line 5056  sub _tree_construction_main ($) { Line 5145  sub _tree_construction_main ($) {
5145                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
5146                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5147                !!!cp ('t192');                !!!cp ('t192');
5148                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
5149                                  text => $token->{tag_name}, token => $token);
5150                ## Ignore the token                ## Ignore the token
5151                !!!next-token;                !!!next-token;
5152                next B;                next B;
# Line 5096  sub _tree_construction_main ($) { Line 5186  sub _tree_construction_main ($) {
5186            }            }
5187          }          }
5188    
5189              !!!parse-error (type => 'in table:#character', token => $token);          !!!parse-error (type => 'in table:#text', token => $token);
5190    
5191              ## As if in body, but insert into foster parent element              ## As if in body, but insert into foster parent element
5192              ## ISSUE: Spec says that "whenever a node would be inserted              ## ISSUE: Spec says that "whenever a node would be inserted
# Line 5147  sub _tree_construction_main ($) { Line 5237  sub _tree_construction_main ($) {
5237          !!!next-token;          !!!next-token;
5238          next B;          next B;
5239        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5240              if ({          if ({
5241                   tr => ($self->{insertion_mode} != IN_ROW_IM),               tr => ($self->{insertion_mode} != IN_ROW_IM),
5242                   th => 1, td => 1,               th => 1, td => 1,
5243                  }->{$token->{tag_name}}) {              }->{$token->{tag_name}}) {
5244                if ($self->{insertion_mode} == IN_TABLE_IM) {            if ($self->{insertion_mode} == IN_TABLE_IM) {
5245                  ## Clear back to table context              ## Clear back to table context
5246                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5247                                  & TABLE_SCOPING_EL)) {                              & TABLE_SCOPING_EL)) {
5248                    !!!cp ('t201');                !!!cp ('t201');
5249                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5250                  }              }
5251                                
5252                  !!!insert-element ('tbody',, $token);              !!!insert-element ('tbody',, $token);
5253                  $self->{insertion_mode} = IN_TABLE_BODY_IM;              $self->{insertion_mode} = IN_TABLE_BODY_IM;
5254                  ## reprocess in the "in table body" insertion mode...              ## reprocess in the "in table body" insertion mode...
5255                }            }
5256              
5257                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {            if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
5258                  unless ($token->{tag_name} eq 'tr') {              unless ($token->{tag_name} eq 'tr') {
5259                    !!!cp ('t202');                !!!cp ('t202');
5260                    !!!parse-error (type => 'missing start tag:tr', token => $token);                !!!parse-error (type => 'missing start tag:tr', token => $token);
5261                  }              }
5262                                    
5263                  ## Clear back to table body context              ## Clear back to table body context
5264                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5265                                  & TABLE_ROWS_SCOPING_EL)) {                              & TABLE_ROWS_SCOPING_EL)) {
5266                    !!!cp ('t203');                !!!cp ('t203');
5267                    ## ISSUE: Can this case be reached?                ## ISSUE: Can this case be reached?
5268                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5269                  }              }
5270                                    
5271                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
5272                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
# Line 5232  sub _tree_construction_main ($) { Line 5322  sub _tree_construction_main ($) {
5322                  unless (defined $i) {                  unless (defined $i) {
5323                    !!!cp ('t210');                    !!!cp ('t210');
5324  ## TODO: This type is wrong.  ## TODO: This type is wrong.
5325                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmacthed end tag',
5326                                      text => $token->{tag_name}, token => $token);
5327                    ## Ignore the token                    ## Ignore the token
5328                    !!!nack ('t210.1');                    !!!nack ('t210.1');
5329                    !!!next-token;                    !!!next-token;
# Line 5276  sub _tree_construction_main ($) { Line 5367  sub _tree_construction_main ($) {
5367                  } # INSCOPE                  } # INSCOPE
5368                  unless (defined $i) {                  unless (defined $i) {
5369                    !!!cp ('t216');                    !!!cp ('t216');
5370  ## TODO: This erorr type ios wrong.  ## TODO: This erorr type is wrong.
5371                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5372                                      text => $token->{tag_name}, token => $token);
5373                    ## Ignore the token                    ## Ignore the token
5374                    !!!nack ('t216.1');                    !!!nack ('t216.1');
5375                    !!!next-token;                    !!!next-token;
# Line 5352  sub _tree_construction_main ($) { Line 5444  sub _tree_construction_main ($) {
5444                }                }
5445              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
5446                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
5447                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
5448                                    ->manakai_local_name,                                    ->manakai_local_name,
5449                                token => $token);                                token => $token);
5450    
# Line 5373  sub _tree_construction_main ($) { Line 5465  sub _tree_construction_main ($) {
5465                unless (defined $i) {                unless (defined $i) {
5466                  !!!cp ('t223');                  !!!cp ('t223');
5467  ## TODO: The following is wrong, maybe.  ## TODO: The following is wrong, maybe.
5468                  !!!parse-error (type => 'unmatched end tag:table', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'table',
5469                                    token => $token);
5470                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
5471                  !!!nack ('t223.1');                  !!!nack ('t223.1');
5472                  !!!next-token;                  !!!next-token;
5473                  next B;                  next B;
5474                }                }
5475                                
5476  ## TODO: Followings are removed from the latest spec.  ## TODO: Followings are removed from the latest spec.
5477                ## generate implied end tags                ## generate implied end tags
5478                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
5479                  !!!cp ('t224');                  !!!cp ('t224');
# Line 5391  sub _tree_construction_main ($) { Line 5484  sub _tree_construction_main ($) {
5484                  !!!cp ('t225');                  !!!cp ('t225');
5485                  ## NOTE: |<table><tr><table>|                  ## NOTE: |<table><tr><table>|
5486                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5487                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5488                                      ->manakai_local_name,                                      ->manakai_local_name,
5489                                  token => $token);                                  token => $token);
5490                } else {                } else {
# Line 5432  sub _tree_construction_main ($) { Line 5525  sub _tree_construction_main ($) {
5525                my $type = lc $token->{attributes}->{type}->{value};                my $type = lc $token->{attributes}->{type}->{value};
5526                if ($type eq 'hidden') {                if ($type eq 'hidden') {
5527                  !!!cp ('t227.3');                  !!!cp ('t227.3');
5528                  !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in table',
5529                                    text => $token->{tag_name}, token => $token);
5530    
5531                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5532    
# Line 5460  sub _tree_construction_main ($) { Line 5554  sub _tree_construction_main ($) {
5554            #            #
5555          }          }
5556    
5557          !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in table', text => $token->{tag_name},
5558                            token => $token);
5559    
5560          $insert = $insert_to_foster;          $insert = $insert_to_foster;
5561          #          #
# Line 5482  sub _tree_construction_main ($) { Line 5577  sub _tree_construction_main ($) {
5577                } # INSCOPE                } # INSCOPE
5578                unless (defined $i) {                unless (defined $i) {
5579                  !!!cp ('t230');                  !!!cp ('t230');
5580                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5581                                    text => $token->{tag_name}, token => $token);
5582                  ## Ignore the token                  ## Ignore the token
5583                  !!!nack ('t230.1');                  !!!nack ('t230.1');
5584                  !!!next-token;                  !!!next-token;
# Line 5523  sub _tree_construction_main ($) { Line 5619  sub _tree_construction_main ($) {
5619                  unless (defined $i) {                  unless (defined $i) {
5620                    !!!cp ('t235');                    !!!cp ('t235');
5621  ## TODO: The following is wrong.  ## TODO: The following is wrong.
5622                    !!!parse-error (type => 'unmatched end tag:'.$token->{type}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5623                                      text => $token->{type}, token => $token);
5624                    ## Ignore the token                    ## Ignore the token
5625                    !!!nack ('t236.1');                    !!!nack ('t236.1');
5626                    !!!next-token;                    !!!next-token;
# Line 5559  sub _tree_construction_main ($) { Line 5656  sub _tree_construction_main ($) {
5656                  } # INSCOPE                  } # INSCOPE
5657                  unless (defined $i) {                  unless (defined $i) {
5658                    !!!cp ('t239');                    !!!cp ('t239');
5659                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5660                                      text => $token->{tag_name}, token => $token);
5661                    ## Ignore the token                    ## Ignore the token
5662                    !!!nack ('t239.1');                    !!!nack ('t239.1');
5663                    !!!next-token;                    !!!next-token;
# Line 5605  sub _tree_construction_main ($) { Line 5703  sub _tree_construction_main ($) {
5703                } # INSCOPE                } # INSCOPE
5704                unless (defined $i) {                unless (defined $i) {
5705                  !!!cp ('t243');                  !!!cp ('t243');
5706                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5707                                    text => $token->{tag_name}, token => $token);
5708                  ## Ignore the token                  ## Ignore the token
5709                  !!!nack ('t243.1');                  !!!nack ('t243.1');
5710                  !!!next-token;                  !!!next-token;
# Line 5639  sub _tree_construction_main ($) { Line 5738  sub _tree_construction_main ($) {
5738                  } # INSCOPE                  } # INSCOPE
5739                    unless (defined $i) {                    unless (defined $i) {
5740                      !!!cp ('t249');                      !!!cp ('t249');
5741                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5742                                        text => $token->{tag_name}, token => $token);
5743                      ## Ignore the token                      ## Ignore the token
5744                      !!!nack ('t249.1');                      !!!nack ('t249.1');
5745                      !!!next-token;                      !!!next-token;
# Line 5662  sub _tree_construction_main ($) { Line 5762  sub _tree_construction_main ($) {
5762                  } # INSCOPE                  } # INSCOPE
5763                    unless (defined $i) {                    unless (defined $i) {
5764                      !!!cp ('t252');                      !!!cp ('t252');
5765                      !!!parse-error (type => 'unmatched end tag:tr', token => $token);                      !!!parse-error (type => 'unmatched end tag',
5766                                        text => 'tr', token => $token);
5767                      ## Ignore the token                      ## Ignore the token
5768                      !!!nack ('t252.1');                      !!!nack ('t252.1');
5769                      !!!next-token;                      !!!next-token;
# Line 5697  sub _tree_construction_main ($) { Line 5798  sub _tree_construction_main ($) {
5798                } # INSCOPE                } # INSCOPE
5799                unless (defined $i) {                unless (defined $i) {
5800                  !!!cp ('t256');                  !!!cp ('t256');
5801                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5802                                    text => $token->{tag_name}, token => $token);
5803                  ## Ignore the token                  ## Ignore the token
5804                  !!!nack ('t256.1');                  !!!nack ('t256.1');
5805                  !!!next-token;                  !!!next-token;
# Line 5724  sub _tree_construction_main ($) { Line 5826  sub _tree_construction_main ($) {
5826                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
5827                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5828            !!!cp ('t258');            !!!cp ('t258');
5829            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
5830                              text => $token->{tag_name}, token => $token);
5831            ## Ignore the token            ## Ignore the token
5832            !!!nack ('t258.1');            !!!nack ('t258.1');
5833             !!!next-token;             !!!next-token;
5834            next B;            next B;
5835          } else {          } else {
5836            !!!cp ('t259');            !!!cp ('t259');
5837            !!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in table:/',
5838                              text => $token->{tag_name}, token => $token);
5839    
5840            $insert = $insert_to_foster;            $insert = $insert_to_foster;
5841            #            #
# Line 5781  sub _tree_construction_main ($) { Line 5885  sub _tree_construction_main ($) {
5885              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
5886                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
5887                  !!!cp ('t264');                  !!!cp ('t264');
5888                  !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5889                                    text => 'colgroup', token => $token);
5890                  ## Ignore the token                  ## Ignore the token
5891                  !!!next-token;                  !!!next-token;
5892                  next B;                  next B;
# Line 5794  sub _tree_construction_main ($) { Line 5899  sub _tree_construction_main ($) {
5899                }                }
5900              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
5901                !!!cp ('t266');                !!!cp ('t266');
5902                !!!parse-error (type => 'unmatched end tag:col', token => $token);                !!!parse-error (type => 'unmatched end tag',
5903                                  text => 'col', token => $token);
5904                ## Ignore the token                ## Ignore the token
5905                !!!next-token;                !!!next-token;
5906                next B;                next B;
# Line 5824  sub _tree_construction_main ($) { Line 5930  sub _tree_construction_main ($) {
5930            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
5931              !!!cp ('t269');              !!!cp ('t269');
5932  ## TODO: Wrong error type?  ## TODO: Wrong error type?
5933              !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);              !!!parse-error (type => 'unmatched end tag',
5934                                text => 'colgroup', token => $token);
5935              ## Ignore the token              ## Ignore the token
5936              !!!nack ('t269.1');              !!!nack ('t269.1');
5937              !!!next-token;              !!!next-token;
# Line 5878  sub _tree_construction_main ($) { Line 5985  sub _tree_construction_main ($) {
5985            !!!nack ('t277.1');            !!!nack ('t277.1');
5986            !!!next-token;            !!!next-token;
5987            next B;            next B;
5988          } elsif ($token->{tag_name} eq 'select' or          } elsif ({
5989                   $token->{tag_name} eq 'input' or                     select => 1, input => 1, textarea => 1,
5990                     }->{$token->{tag_name}} or
5991                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
5992                    {                    {
5993                     caption => 1, table => 1,                     caption => 1, table => 1,
# Line 5887  sub _tree_construction_main ($) { Line 5995  sub _tree_construction_main ($) {
5995                     tr => 1, td => 1, th => 1,                     tr => 1, td => 1, th => 1,
5996                    }->{$token->{tag_name}})) {                    }->{$token->{tag_name}})) {
5997            ## TODO: The type below is not good - <select> is replaced by </select>            ## TODO: The type below is not good - <select> is replaced by </select>
5998            !!!parse-error (type => 'not closed:select', token => $token);            !!!parse-error (type => 'not closed', text => 'select',
5999                              token => $token);
6000            ## NOTE: As if the token were </select> (<select> case) or            ## NOTE: As if the token were </select> (<select> case) or
6001            ## as if there were </select> (otherwise).            ## as if there were </select> (otherwise).
6002            ## have an element in table scope            ## have an element in table scope
# Line 5905  sub _tree_construction_main ($) { Line 6014  sub _tree_construction_main ($) {
6014            } # INSCOPE            } # INSCOPE
6015            unless (defined $i) {            unless (defined $i) {
6016              !!!cp ('t280');              !!!cp ('t280');
6017              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6018                                text => 'select', token => $token);
6019              ## Ignore the token              ## Ignore the token
6020              !!!nack ('t280.1');              !!!nack ('t280.1');
6021              !!!next-token;              !!!next-token;
# Line 5929  sub _tree_construction_main ($) { Line 6039  sub _tree_construction_main ($) {
6039            }            }
6040          } else {          } else {
6041            !!!cp ('t282');            !!!cp ('t282');
6042            !!!parse-error (type => 'in select:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select',
6043                              text => $token->{tag_name}, token => $token);
6044            ## Ignore the token            ## Ignore the token
6045            !!!nack ('t282.1');            !!!nack ('t282.1');
6046            !!!next-token;            !!!next-token;
# Line 5947  sub _tree_construction_main ($) { Line 6058  sub _tree_construction_main ($) {
6058              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6059            } else {            } else {
6060              !!!cp ('t285');              !!!cp ('t285');
6061              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6062                                text => $token->{tag_name}, token => $token);
6063              ## Ignore the token              ## Ignore the token
6064            }            }
6065            !!!nack ('t285.1');            !!!nack ('t285.1');
# Line 5959  sub _tree_construction_main ($) { Line 6071  sub _tree_construction_main ($) {
6071              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6072            } else {            } else {
6073              !!!cp ('t287');              !!!cp ('t287');
6074              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6075                                text => $token->{tag_name}, token => $token);
6076              ## Ignore the token              ## Ignore the token
6077            }            }
6078            !!!nack ('t287.1');            !!!nack ('t287.1');
# Line 5981  sub _tree_construction_main ($) { Line 6094  sub _tree_construction_main ($) {
6094            } # INSCOPE            } # INSCOPE
6095            unless (defined $i) {            unless (defined $i) {
6096              !!!cp ('t290');              !!!cp ('t290');
6097              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6098                                text => $token->{tag_name}, token => $token);
6099              ## Ignore the token              ## Ignore the token
6100              !!!nack ('t290.1');              !!!nack ('t290.1');
6101              !!!next-token;              !!!next-token;
# Line 6002  sub _tree_construction_main ($) { Line 6116  sub _tree_construction_main ($) {
6116                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
6117                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
6118  ## TODO: The following is wrong?  ## TODO: The following is wrong?
6119            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
6120                              text => $token->{tag_name}, token => $token);
6121                                
6122            ## have an element in table scope            ## have an element in table scope
6123            my $i;            my $i;
# Line 6043  sub _tree_construction_main ($) { Line 6158  sub _tree_construction_main ($) {
6158            unless (defined $i) {            unless (defined $i) {
6159              !!!cp ('t297');              !!!cp ('t297');
6160  ## TODO: The following error type is correct?  ## TODO: The following error type is correct?
6161              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6162                                text => 'select', token => $token);
6163              ## Ignore the </select> token              ## Ignore the </select> token
6164              !!!nack ('t297.1');              !!!nack ('t297.1');
6165              !!!next-token; ## TODO: ok?              !!!next-token; ## TODO: ok?
# Line 6060  sub _tree_construction_main ($) { Line 6176  sub _tree_construction_main ($) {
6176            next B;            next B;
6177          } else {          } else {
6178            !!!cp ('t299');            !!!cp ('t299');
6179            !!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select:/',
6180                              text => $token->{tag_name}, token => $token);
6181            ## Ignore the token            ## Ignore the token
6182            !!!nack ('t299.3');            !!!nack ('t299.3');
6183            !!!next-token;            !!!next-token;
# Line 6098  sub _tree_construction_main ($) { Line 6215  sub _tree_construction_main ($) {
6215                    
6216          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6217            !!!cp ('t301');            !!!cp ('t301');
6218            !!!parse-error (type => 'after html:#character', token => $token);            !!!parse-error (type => 'after html:#text', token => $token);
6219    
6220            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6221          } else {          } else {
# Line 6106  sub _tree_construction_main ($) { Line 6223  sub _tree_construction_main ($) {
6223          }          }
6224                    
6225          ## "after body" insertion mode          ## "after body" insertion mode
6226          !!!parse-error (type => 'after body:#character', token => $token);          !!!parse-error (type => 'after body:#text', token => $token);
6227    
6228          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6229          ## reprocess          ## reprocess
# Line 6114  sub _tree_construction_main ($) { Line 6231  sub _tree_construction_main ($) {
6231        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
6232          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6233            !!!cp ('t303');            !!!cp ('t303');
6234            !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html',
6235                              text => $token->{tag_name}, token => $token);
6236                        
6237            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6238          } else {          } else {
# Line 6122  sub _tree_construction_main ($) { Line 6240  sub _tree_construction_main ($) {
6240          }          }
6241    
6242          ## "after body" insertion mode          ## "after body" insertion mode
6243          !!!parse-error (type => 'after body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'after body',
6244                            text => $token->{tag_name}, token => $token);
6245    
6246          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6247          !!!ack-later;          !!!ack-later;
# Line 6131  sub _tree_construction_main ($) { Line 6250  sub _tree_construction_main ($) {
6250        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6251          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6252            !!!cp ('t305');            !!!cp ('t305');
6253            !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html:/',
6254                              text => $token->{tag_name}, token => $token);
6255                        
6256            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6257            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
# Line 6143  sub _tree_construction_main ($) { Line 6263  sub _tree_construction_main ($) {
6263          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
6264            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
6265              !!!cp ('t307');              !!!cp ('t307');
6266              !!!parse-error (type => 'unmatched end tag:html', token => $token);              !!!parse-error (type => 'unmatched end tag',
6267                                text => 'html', token => $token);
6268              ## Ignore the token              ## Ignore the token
6269              !!!next-token;              !!!next-token;
6270              next B;              next B;
# Line 6155  sub _tree_construction_main ($) { Line 6276  sub _tree_construction_main ($) {
6276            }            }
6277          } else {          } else {
6278            !!!cp ('t309');            !!!cp ('t309');
6279            !!!parse-error (type => 'after body:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after body:/',
6280                              text => $token->{tag_name}, token => $token);
6281    
6282            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
6283            ## reprocess            ## reprocess
# Line 6183  sub _tree_construction_main ($) { Line 6305  sub _tree_construction_main ($) {
6305          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
6306            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6307              !!!cp ('t311');              !!!cp ('t311');
6308              !!!parse-error (type => 'in frameset:#character', token => $token);              !!!parse-error (type => 'in frameset:#text', token => $token);
6309            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6310              !!!cp ('t312');              !!!cp ('t312');
6311              !!!parse-error (type => 'after frameset:#character', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6312            } else { # "after html frameset"            } else { # "after after frameset"
6313              !!!cp ('t313');              !!!cp ('t313');
6314              !!!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);  
6315            }            }
6316                        
6317            ## Ignore the token.            ## Ignore the token.
# Line 6209  sub _tree_construction_main ($) { Line 6327  sub _tree_construction_main ($) {
6327                    
6328          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
6329        } 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');  
         }  
   
6330          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6331              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6332            !!!cp ('t318');            !!!cp ('t318');
# Line 6236  sub _tree_construction_main ($) { Line 6344  sub _tree_construction_main ($) {
6344            next B;            next B;
6345          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
6346            !!!cp ('t320');            !!!cp ('t320');
6347            ## NOTE: As if in body.            ## NOTE: As if in head.
6348            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
6349            next B;            next B;
6350    
6351              ## NOTE: |<!DOCTYPE HTML><frameset></frameset></html><noframes></noframes>|
6352              ## has no parse error.
6353          } else {          } else {
6354            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6355              !!!cp ('t321');              !!!cp ('t321');
6356              !!!parse-error (type => 'in frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset',
6357            } else {                              text => $token->{tag_name}, token => $token);
6358              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6359              !!!cp ('t322');              !!!cp ('t322');
6360              !!!parse-error (type => 'after frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after frameset',
6361                                text => $token->{tag_name}, token => $token);
6362              } else { # "after after frameset"
6363                !!!cp ('t322.2');
6364                !!!parse-error (type => 'after after frameset',
6365                                text => $token->{tag_name}, token => $token);
6366            }            }
6367            ## Ignore the token            ## Ignore the token
6368            !!!nack ('t322.1');            !!!nack ('t322.1');
# Line 6253  sub _tree_construction_main ($) { Line 6370  sub _tree_construction_main ($) {
6370            next B;            next B;
6371          }          }
6372        } 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');  
         }  
   
6373          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6374              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6375            if ($self->{open_elements}->[-1]->[1] & HTML_EL and            if ($self->{open_elements}->[-1]->[1] & HTML_EL and
6376                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
6377              !!!cp ('t325');              !!!cp ('t325');
6378              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6379                                text => $token->{tag_name}, token => $token);
6380              ## Ignore the token              ## Ignore the token
6381              !!!next-token;              !!!next-token;
6382            } else {            } else {
# Line 6294  sub _tree_construction_main ($) { Line 6402  sub _tree_construction_main ($) {
6402          } else {          } else {
6403            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6404              !!!cp ('t330');              !!!cp ('t330');
6405              !!!parse-error (type => 'in frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset:/',
6406            } else {                              text => $token->{tag_name}, token => $token);
6407              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6408                !!!cp ('t330.1');
6409                !!!parse-error (type => 'after frameset:/',
6410                                text => $token->{tag_name}, token => $token);
6411              } else { # "after after html"
6412              !!!cp ('t331');              !!!cp ('t331');
6413              !!!parse-error (type => 'after frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after after frameset:/',
6414                                text => $token->{tag_name}, token => $token);
6415            }            }
6416            ## Ignore the token            ## Ignore the token
6417            !!!next-token;            !!!next-token;
# Line 6364  sub _tree_construction_main ($) { Line 6478  sub _tree_construction_main ($) {
6478                                           ->{has_reference});                                           ->{has_reference});
6479            } elsif ($token->{attributes}->{content}) {            } elsif ($token->{attributes}->{content}) {
6480              if ($token->{attributes}->{content}->{value}              if ($token->{attributes}->{content}->{value}
6481                  =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                  =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
6482                      [\x09-\x0D\x20]*=                      [\x09-\x0D\x20]*=
6483                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
6484                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
6485                !!!cp ('t336');                !!!cp ('t336');
6486                ## NOTE: Whether the encoding is supported or not is handled                ## NOTE: Whether the encoding is supported or not is handled
6487                ## in the {change_encoding} callback.                ## in the {change_encoding} callback.
# Line 6405  sub _tree_construction_main ($) { Line 6519  sub _tree_construction_main ($) {
6519          $parse_rcdata->(RCDATA_CONTENT_MODEL);          $parse_rcdata->(RCDATA_CONTENT_MODEL);
6520          next B;          next B;
6521        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
6522          !!!parse-error (type => 'in body:body', token => $token);          !!!parse-error (type => 'in body', text => 'body', token => $token);
6523                                
6524          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
6525              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {
# Line 6525  sub _tree_construction_main ($) { Line 6639  sub _tree_construction_main ($) {
6639              if ($i != -1) {              if ($i != -1) {
6640                !!!cp ('t355');                !!!cp ('t355');
6641                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
6642                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
6643                                    ->manakai_local_name,                                    ->manakai_local_name,
6644                                token => $token);                                token => $token);
6645              } else {              } else {
# Line 6679  sub _tree_construction_main ($) { Line 6793  sub _tree_construction_main ($) {
6793                  xmp => 1,                  xmp => 1,
6794                  iframe => 1,                  iframe => 1,
6795                  noembed => 1,                  noembed => 1,
6796                  noframes => 1,                  noframes => 1, ## NOTE: This is an "as if in head" code clone.
6797                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
6798                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6799          if ($token->{tag_name} eq 'xmp') {          if ($token->{tag_name} eq 'xmp') {
# Line 6701  sub _tree_construction_main ($) { Line 6815  sub _tree_construction_main ($) {
6815            !!!next-token;            !!!next-token;
6816            next B;            next B;
6817          } else {          } else {
6818              !!!ack ('t391.1');
6819    
6820            my $at = $token->{attributes};            my $at = $token->{attributes};
6821            my $form_attrs;            my $form_attrs;
6822            $form_attrs->{action} = $at->{action} if $at->{action};            $form_attrs->{action} = $at->{action} if $at->{action};
# Line 6744  sub _tree_construction_main ($) { Line 6860  sub _tree_construction_main ($) {
6860                           line => $token->{line}, column => $token->{column}},                           line => $token->{line}, column => $token->{column}},
6861                          {type => END_TAG_TOKEN, tag_name => 'form',                          {type => END_TAG_TOKEN, tag_name => 'form',
6862                           line => $token->{line}, column => $token->{column}};                           line => $token->{line}, column => $token->{column}};
           !!!nack ('t391.1'); ## NOTE: Not acknowledged.  
6863            !!!back-token (@tokens);            !!!back-token (@tokens);
6864            !!!next-token;            !!!next-token;
6865            next B;            next B;
# Line 6792  sub _tree_construction_main ($) { Line 6907  sub _tree_construction_main ($) {
6907            ## Ignore the token            ## Ignore the token
6908          } else {          } else {
6909            !!!cp ('t398');            !!!cp ('t398');
6910            !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);            !!!parse-error (type => 'in RCDATA:#eof', token => $token);
6911          }          }
6912          !!!next-token;          !!!next-token;
6913          next B;          next B;
6914          } elsif ($token->{tag_name} eq 'rt' or
6915                   $token->{tag_name} eq 'rp') {
6916            ## has a |ruby| element in scope
6917            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6918              my $node = $self->{open_elements}->[$_];
6919              if ($node->[1] & RUBY_EL) {
6920                !!!cp ('t398.1');
6921                ## generate implied end tags
6922                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
6923                  !!!cp ('t398.2');
6924                  pop @{$self->{open_elements}};
6925                }
6926                unless ($self->{open_elements}->[-1]->[1] & RUBY_EL) {
6927                  !!!cp ('t398.3');
6928                  !!!parse-error (type => 'not closed',
6929                                  text => $self->{open_elements}->[-1]->[0]
6930                                      ->manakai_local_name,
6931                                  token => $token);
6932                  pop @{$self->{open_elements}}
6933                      while not $self->{open_elements}->[-1]->[1] & RUBY_EL;
6934                }
6935                last INSCOPE;
6936              } elsif ($node->[1] & SCOPING_EL) {
6937                !!!cp ('t398.4');
6938                last INSCOPE;
6939              }
6940            } # INSCOPE
6941    
6942            !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
6943    
6944            !!!nack ('t398.5');
6945            !!!next-token;
6946            redo B;
6947        } elsif ($token->{tag_name} eq 'math' or        } elsif ($token->{tag_name} eq 'math' or
6948                 $token->{tag_name} eq 'svg') {                 $token->{tag_name} eq 'svg') {
6949          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
6950    
6951            ## "Adjust MathML attributes" ('math' only) - done in insert-element-f
6952    
6953          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f
6954    
6955          ## "adjust foreign attributes" - done in insert-element-f          ## "adjust foreign attributes" - done in insert-element-f
# Line 6826  sub _tree_construction_main ($) { Line 6976  sub _tree_construction_main ($) {
6976                  thead => 1, tr => 1,                  thead => 1, tr => 1,
6977                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6978          !!!cp ('t401');          !!!cp ('t401');
6979          !!!parse-error (type => 'in body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in body',
6980                            text => $token->{tag_name}, token => $token);
6981          ## Ignore the token          ## Ignore the token
6982          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.
6983          !!!next-token;          !!!next-token;
# Line 6911  sub _tree_construction_main ($) { Line 7062  sub _tree_construction_main ($) {
7062            }            }
7063    
7064            !!!parse-error (type => 'start tag not allowed',            !!!parse-error (type => 'start tag not allowed',
7065                            value => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7066            ## NOTE: Ignore the token.            ## NOTE: Ignore the token.
7067            !!!next-token;            !!!next-token;
7068            next B;            next B;
# Line 6921  sub _tree_construction_main ($) { Line 7072  sub _tree_construction_main ($) {
7072            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {
7073              !!!cp ('t403');              !!!cp ('t403');
7074              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7075                              value => $_->[0]->manakai_local_name,                              text => $_->[0]->manakai_local_name,
7076                              token => $token);                              token => $token);
7077              last;              last;
7078            } else {            } else {
# Line 6941  sub _tree_construction_main ($) { Line 7092  sub _tree_construction_main ($) {
7092            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {
7093              !!!cp ('t406');              !!!cp ('t406');
7094              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7095                              value => $self->{open_elements}->[1]->[0]                              text => $self->{open_elements}->[1]->[0]
7096                                  ->manakai_local_name,                                  ->manakai_local_name,
7097                              token => $token);                              token => $token);
7098            } else {            } else {
# Line 6952  sub _tree_construction_main ($) { Line 7103  sub _tree_construction_main ($) {
7103            next B;            next B;
7104          } else {          } else {
7105            !!!cp ('t408');            !!!cp ('t408');
7106            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7107                              text => $token->{tag_name}, token => $token);
7108            ## Ignore the token            ## Ignore the token
7109            !!!next-token;            !!!next-token;
7110            next B;            next B;
# Line 6980  sub _tree_construction_main ($) { Line 7132  sub _tree_construction_main ($) {
7132    
7133          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7134            !!!cp ('t413');            !!!cp ('t413');
7135            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7136                              text => $token->{tag_name}, token => $token);
7137              ## NOTE: Ignore the token.
7138          } else {          } else {
7139            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7140            while ({            while ({
7141                      ## END_TAG_OPTIONAL_EL
7142                    dd => ($token->{tag_name} ne 'dd'),                    dd => ($token->{tag_name} ne 'dd'),
7143                    dt => ($token->{tag_name} ne 'dt'),                    dt => ($token->{tag_name} ne 'dt'),
7144                    li => ($token->{tag_name} ne 'li'),                    li => ($token->{tag_name} ne 'li'),
7145                    p => 1,                    p => 1,
7146                      rt => 1,
7147                      rp => 1,
7148                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {
7149              !!!cp ('t409');              !!!cp ('t409');
7150              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
# Line 6998  sub _tree_construction_main ($) { Line 7155  sub _tree_construction_main ($) {
7155                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7156              !!!cp ('t412');              !!!cp ('t412');
7157              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7158                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7159                                  ->manakai_local_name,                                  ->manakai_local_name,
7160                              token => $token);                              token => $token);
7161            } else {            } else {
# Line 7035  sub _tree_construction_main ($) { Line 7192  sub _tree_construction_main ($) {
7192    
7193          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7194            !!!cp ('t421');            !!!cp ('t421');
7195            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7196                              text => $token->{tag_name}, token => $token);
7197              ## NOTE: Ignore the token.
7198          } else {          } else {
7199            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7200            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7048  sub _tree_construction_main ($) { Line 7207  sub _tree_construction_main ($) {
7207                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7208              !!!cp ('t417.1');              !!!cp ('t417.1');
7209              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7210                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7211                                  ->manakai_local_name,                                  ->manakai_local_name,
7212                              token => $token);                              token => $token);
7213            } else {            } else {
# Line 7080  sub _tree_construction_main ($) { Line 7239  sub _tree_construction_main ($) {
7239    
7240          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7241            !!!cp ('t425.1');            !!!cp ('t425.1');
7242            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7243                              text => $token->{tag_name}, token => $token);
7244              ## NOTE: Ignore the token.
7245          } else {          } else {
7246            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7247            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7092  sub _tree_construction_main ($) { Line 7253  sub _tree_construction_main ($) {
7253            if ($self->{open_elements}->[-1]->[0]->manakai_local_name            if ($self->{open_elements}->[-1]->[0]->manakai_local_name
7254                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7255              !!!cp ('t425');              !!!cp ('t425');
7256              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
7257                                text => $token->{tag_name}, token => $token);
7258            } else {            } else {
7259              !!!cp ('t426');              !!!cp ('t426');
7260            }            }
# Line 7123  sub _tree_construction_main ($) { Line 7285  sub _tree_construction_main ($) {
7285                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7286              !!!cp ('t412.1');              !!!cp ('t412.1');
7287              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7288                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7289                                  ->manakai_local_name,                                  ->manakai_local_name,
7290                              token => $token);                              token => $token);
7291            } else {            } else {
# Line 7133  sub _tree_construction_main ($) { Line 7295  sub _tree_construction_main ($) {
7295            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
7296          } else {          } else {
7297            !!!cp ('t413.1');            !!!cp ('t413.1');
7298            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7299                              text => $token->{tag_name}, token => $token);
7300    
7301            !!!cp ('t415.1');            !!!cp ('t415.1');
7302            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
# Line 7156  sub _tree_construction_main ($) { Line 7319  sub _tree_construction_main ($) {
7319          next B;          next B;
7320        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
7321          !!!cp ('t428');          !!!cp ('t428');
7322          !!!parse-error (type => 'unmatched end tag:br', token => $token);          !!!parse-error (type => 'unmatched end tag',
7323                            text => 'br', token => $token);
7324    
7325          ## As if <br>          ## As if <br>
7326          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
# Line 7181  sub _tree_construction_main ($) { Line 7345  sub _tree_construction_main ($) {
7345                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
7346                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7347          !!!cp ('t429');          !!!cp ('t429');
7348          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'unmatched end tag',
7349                            text => $token->{tag_name}, token => $token);
7350          ## Ignore the token          ## Ignore the token
7351          !!!next-token;          !!!next-token;
7352          next B;          next B;
# Line 7200  sub _tree_construction_main ($) { Line 7365  sub _tree_construction_main ($) {
7365              ## generate implied end tags              ## generate implied end tags
7366              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7367                !!!cp ('t430');                !!!cp ('t430');
7368                ## ISSUE: Can this case be reached?                ## NOTE: |<ruby><rt></ruby>|.
7369                  ## ISSUE: <ruby><rt></rt> will also take this code path,
7370                  ## which seems wrong.
7371                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
7372                  $node_i++;
7373              }              }
7374                    
7375              ## Step 2              ## Step 2
# Line 7210  sub _tree_construction_main ($) { Line 7378  sub _tree_construction_main ($) {
7378                !!!cp ('t431');                !!!cp ('t431');
7379                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
7380                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
7381                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
7382                                    ->manakai_local_name,                                    ->manakai_local_name,
7383                                token => $token);                                token => $token);
7384              } else {              } else {
# Line 7218  sub _tree_construction_main ($) { Line 7386  sub _tree_construction_main ($) {
7386              }              }
7387                            
7388              ## Step 3              ## Step 3
7389              splice @{$self->{open_elements}}, $node_i;              splice @{$self->{open_elements}}, $node_i if $node_i < 0;
7390    
7391              !!!next-token;              !!!next-token;
7392              last S2;              last S2;
# Line 7229  sub _tree_construction_main ($) { Line 7397  sub _tree_construction_main ($) {
7397                  ($node->[1] & SPECIAL_EL or                  ($node->[1] & SPECIAL_EL or
7398                   $node->[1] & SCOPING_EL)) {                   $node->[1] & SCOPING_EL)) {
7399                !!!cp ('t433');                !!!cp ('t433');
7400                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
7401                                  text => $token->{tag_name}, token => $token);
7402                ## Ignore the token                ## Ignore the token
7403                !!!next-token;                !!!next-token;
7404                last S2;                last S2;
# Line 7365  sub set_inner_html ($$$) { Line 7534  sub set_inner_html ($$$) {
7534                  0x10FFFE => 1, 0x10FFFF => 1,                  0x10FFFE => 1, 0x10FFFF => 1,
7535                 }->{$self->{next_char}}) {                 }->{$self->{next_char}}) {
7536          !!!cp ('i4.1');          !!!cp ('i4.1');
7537          !!!parse-error (type => 'control char', level => $self->{must_level});          if ($self->{next_char} < 0x10000) {
7538  ## TODO: error type documentation            !!!parse-error (type => 'control char',
7539                              text => (sprintf 'U+%04X', $self->{next_char}));
7540            } else {
7541              !!!parse-error (type => 'control char',
7542                              text => (sprintf 'U-%08X', $self->{next_char}));
7543            }
7544        }        }
7545      };      };
7546      $p->{prev_char} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];

Legend:
Removed from v.1.141  
changed lines
  Added in v.1.159

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24