/[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.151 by wakaba, Sun Jun 8 05:08:42 2008 UTC revision 1.162 by wakaba, Thu Sep 11 09:12:27 2008 UTC
# Line 354  sub parse_byte_string ($$$$;$) { Line 354  sub parse_byte_string ($$$$;$) {
354    return $self->parse_byte_stream ($charset_name, $input, @_[1..$#_]);    return $self->parse_byte_stream ($charset_name, $input, @_[1..$#_]);
355  } # parse_byte_string  } # parse_byte_string
356    
357  sub parse_byte_stream ($$$$;$) {  sub parse_byte_stream ($$$$;$$) {
358      # my ($self, $charset_name, $byte_stream, $doc, $onerror, $get_wrapper) = @_;
359    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
360    my $charset_name = shift;    my $charset_name = shift;
361    my $byte_stream = $_[0];    my $byte_stream = $_[0];
# Line 365  sub parse_byte_stream ($$$$;$) { Line 366  sub parse_byte_stream ($$$$;$) {
366    };    };
367    $self->{parse_error} = $onerror; # updated later by parse_char_string    $self->{parse_error} = $onerror; # updated later by parse_char_string
368    
369      my $get_wrapper = $_[3] || sub ($) {
370        return $_[0]; # $_[0] = byte stream handle, returned = arg to char handle
371      };
372    
373    ## HTML5 encoding sniffing algorithm    ## HTML5 encoding sniffing algorithm
374    require Message::Charset::Info;    require Message::Charset::Info;
375    my $charset;    my $charset;
# Line 372  sub parse_byte_stream ($$$$;$) { Line 377  sub parse_byte_stream ($$$$;$) {
377    my ($char_stream, $e_status);    my ($char_stream, $e_status);
378    
379    SNIFFING: {    SNIFFING: {
380        ## NOTE: By setting |allow_fallback| option true when the
381        ## |get_decode_handle| method is invoked, we ignore what the HTML5
382        ## spec requires, i.e. unsupported encoding should be ignored.
383          ## TODO: We should not do this unless the parser is invoked
384          ## in the conformance checking mode, in which this behavior
385          ## would be useful.
386    
387      ## Step 1      ## Step 1
388      if (defined $charset_name) {      if (defined $charset_name) {
389        $charset = Message::Charset::Info->get_by_iana_name ($charset_name);        $charset = Message::Charset::Info->get_by_html_name ($charset_name);
390              ## TODO: Is this ok?  Transfer protocol's parameter should be
391              ## interpreted in its semantics?
392    
393        ## ISSUE: Unsupported encoding is not ignored according to the spec.        ## ISSUE: Unsupported encoding is not ignored according to the spec.
394        ($char_stream, $e_status) = $charset->get_decode_handle        ($char_stream, $e_status) = $charset->get_decode_handle
# Line 399  sub parse_byte_stream ($$$$;$) { Line 412  sub parse_byte_stream ($$$$;$) {
412    
413      ## Step 3      ## Step 3
414      if ($byte_buffer =~ /^\xFE\xFF/) {      if ($byte_buffer =~ /^\xFE\xFF/) {
415        $charset = Message::Charset::Info->get_by_iana_name ('utf-16be');        $charset = Message::Charset::Info->get_by_html_name ('utf-16be');
416        ($char_stream, $e_status) = $charset->get_decode_handle        ($char_stream, $e_status) = $charset->get_decode_handle
417            ($byte_stream, allow_error_reporting => 1,            ($byte_stream, allow_error_reporting => 1,
418             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
419        $self->{confident} = 1;        $self->{confident} = 1;
420        last SNIFFING;        last SNIFFING;
421      } elsif ($byte_buffer =~ /^\xFF\xFE/) {      } elsif ($byte_buffer =~ /^\xFF\xFE/) {
422        $charset = Message::Charset::Info->get_by_iana_name ('utf-16le');        $charset = Message::Charset::Info->get_by_html_name ('utf-16le');
423        ($char_stream, $e_status) = $charset->get_decode_handle        ($char_stream, $e_status) = $charset->get_decode_handle
424            ($byte_stream, allow_error_reporting => 1,            ($byte_stream, allow_error_reporting => 1,
425             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
426        $self->{confident} = 1;        $self->{confident} = 1;
427        last SNIFFING;        last SNIFFING;
428      } elsif ($byte_buffer =~ /^\xEF\xBB\xBF/) {      } elsif ($byte_buffer =~ /^\xEF\xBB\xBF/) {
429        $charset = Message::Charset::Info->get_by_iana_name ('utf-8');        $charset = Message::Charset::Info->get_by_html_name ('utf-8');
430        ($char_stream, $e_status) = $charset->get_decode_handle        ($char_stream, $e_status) = $charset->get_decode_handle
431            ($byte_stream, allow_error_reporting => 1,            ($byte_stream, allow_error_reporting => 1,
432             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
# Line 432  sub parse_byte_stream ($$$$;$) { Line 445  sub parse_byte_stream ($$$$;$) {
445      $charset_name = Whatpm::Charset::UniversalCharDet->detect_byte_string      $charset_name = Whatpm::Charset::UniversalCharDet->detect_byte_string
446          ($byte_buffer);          ($byte_buffer);
447      if (defined $charset_name) {      if (defined $charset_name) {
448        $charset = Message::Charset::Info->get_by_iana_name ($charset_name);        $charset = Message::Charset::Info->get_by_html_name ($charset_name);
449    
450        ## ISSUE: Unsupported encoding is not ignored according to the spec.        ## ISSUE: Unsupported encoding is not ignored according to the spec.
451        require Whatpm::Charset::DecodeHandle;        require Whatpm::Charset::DecodeHandle;
# Line 443  sub parse_byte_stream ($$$$;$) { Line 456  sub parse_byte_stream ($$$$;$) {
456             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
457        if ($char_stream) {        if ($char_stream) {
458          $buffer->{buffer} = $byte_buffer;          $buffer->{buffer} = $byte_buffer;
459          !!!parse-error (type => 'sniffing:chardet', ## TODO: type name          !!!parse-error (type => 'sniffing:chardet',
460                          value => $charset_name,                          text => $charset_name,
461                          level => $self->{info_level},                          level => $self->{level}->{info},
462                            layer => 'encode',
463                          line => 1, column => 1);                          line => 1, column => 1);
464          $self->{confident} = 0;          $self->{confident} = 0;
465          last SNIFFING;          last SNIFFING;
# Line 454  sub parse_byte_stream ($$$$;$) { Line 468  sub parse_byte_stream ($$$$;$) {
468    
469      ## Step 7: default      ## Step 7: default
470      ## TODO: Make this configurable.      ## TODO: Make this configurable.
471      $charset = Message::Charset::Info->get_by_iana_name ('windows-1252');      $charset = Message::Charset::Info->get_by_html_name ('windows-1252');
472          ## NOTE: We choose |windows-1252| here, since |utf-8| should be          ## NOTE: We choose |windows-1252| here, since |utf-8| should be
473          ## detectable in the step 6.          ## detectable in the step 6.
474      require Whatpm::Charset::DecodeHandle;      require Whatpm::Charset::DecodeHandle;
# Line 466  sub parse_byte_stream ($$$$;$) { Line 480  sub parse_byte_stream ($$$$;$) {
480                                         allow_fallback => 1,                                         allow_fallback => 1,
481                                         byte_buffer => \$byte_buffer);                                         byte_buffer => \$byte_buffer);
482      $buffer->{buffer} = $byte_buffer;      $buffer->{buffer} = $byte_buffer;
483      !!!parse-error (type => 'sniffing:default', ## TODO: type name      !!!parse-error (type => 'sniffing:default',
484                      value => 'windows-1252',                      text => 'windows-1252',
485                      level => $self->{info_level},                      level => $self->{level}->{info},
486                      line => 1, column => 1);                      line => 1, column => 1,
487                        layer => 'encode');
488      $self->{confident} = 0;      $self->{confident} = 0;
489    } # SNIFFING    } # SNIFFING
490    
   $self->{input_encoding} = $charset->get_iana_name;  
491    if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {    if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
492      !!!parse-error (type => 'chardecode:fallback', ## TODO: type name      $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name?
493                      value => $self->{input_encoding},      !!!parse-error (type => 'chardecode:fallback',
494                      level => $self->{unsupported_level},                      #text => $self->{input_encoding},
495                      line => 1, column => 1);                      level => $self->{level}->{uncertain},
496                        line => 1, column => 1,
497                        layer => 'encode');
498    } elsif (not ($e_status &    } elsif (not ($e_status &
499                  Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {                  Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
500      !!!parse-error (type => 'chardecode:no error', ## TODO: type name      $self->{input_encoding} = $charset->get_iana_name;
501                      value => $self->{input_encoding},      !!!parse-error (type => 'chardecode:no error',
502                      level => $self->{unsupported_level},                      text => $self->{input_encoding},
503                      line => 1, column => 1);                      level => $self->{level}->{uncertain},
504                        line => 1, column => 1,
505                        layer => 'encode');
506      } else {
507        $self->{input_encoding} = $charset->get_iana_name;
508    }    }
509    
510    $self->{change_encoding} = sub {    $self->{change_encoding} = sub {
# Line 492  sub parse_byte_stream ($$$$;$) { Line 512  sub parse_byte_stream ($$$$;$) {
512      $charset_name = shift;      $charset_name = shift;
513      my $token = shift;      my $token = shift;
514    
515      $charset = Message::Charset::Info->get_by_iana_name ($charset_name);      $charset = Message::Charset::Info->get_by_html_name ($charset_name);
516      ($char_stream, $e_status) = $charset->get_decode_handle      ($char_stream, $e_status) = $charset->get_decode_handle
517          ($byte_stream, allow_error_reporting => 1, allow_fallback => 1,          ($byte_stream, allow_error_reporting => 1, allow_fallback => 1,
518           byte_buffer => \ $buffer->{buffer});           byte_buffer => \ $buffer->{buffer});
# Line 503  sub parse_byte_stream ($$$$;$) { Line 523  sub parse_byte_stream ($$$$;$) {
523        ## Step 1            ## Step 1    
524        if ($charset->{category} &        if ($charset->{category} &
525            Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) {            Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) {
526          $charset = Message::Charset::Info->get_by_iana_name ('utf-8');          $charset = Message::Charset::Info->get_by_html_name ('utf-8');
527          ($char_stream, $e_status) = $charset->get_decode_handle          ($char_stream, $e_status) = $charset->get_decode_handle
528              ($byte_stream,              ($byte_stream,
529               byte_buffer => \ $buffer->{buffer});               byte_buffer => \ $buffer->{buffer});
# Line 513  sub parse_byte_stream ($$$$;$) { Line 533  sub parse_byte_stream ($$$$;$) {
533        ## Step 2        ## Step 2
534        if (defined $self->{input_encoding} and        if (defined $self->{input_encoding} and
535            $self->{input_encoding} eq $charset_name) {            $self->{input_encoding} eq $charset_name) {
536          !!!parse-error (type => 'charset label:matching', ## TODO: type          !!!parse-error (type => 'charset label:matching',
537                          value => $charset_name,                          text => $charset_name,
538                          level => $self->{info_level});                          level => $self->{level}->{info});
539          $self->{confident} = 1;          $self->{confident} = 1;
540          return;          return;
541        }        }
542    
543        !!!parse-error (type => 'charset label detected:'.$self->{input_encoding}.        !!!parse-error (type => 'charset label detected',
544            ':'.$charset_name, level => 'w', token => $token);                        text => $self->{input_encoding},
545                          value => $charset_name,
546                          level => $self->{level}->{warn},
547                          token => $token);
548                
549        ## Step 3        ## Step 3
550        # if (can) {        # if (can) {
# Line 537  sub parse_byte_stream ($$$$;$) { Line 560  sub parse_byte_stream ($$$$;$) {
560    
561    my $char_onerror = sub {    my $char_onerror = sub {
562      my (undef, $type, %opt) = @_;      my (undef, $type, %opt) = @_;
563      !!!parse-error (%opt, type => $type,      !!!parse-error (layer => 'encode',
564                        %opt, type => $type,
565                      line => $self->{line}, column => $self->{column} + 1);                      line => $self->{line}, column => $self->{column} + 1);
566      if ($opt{octets}) {      if ($opt{octets}) {
567        ${$opt{octets}} = "\x{FFFD}"; # relacement character        ${$opt{octets}} = "\x{FFFD}"; # relacement character
568      }      }
569    };    };
570    $char_stream->onerror ($char_onerror);  
571      my $wrapped_char_stream = $get_wrapper->($char_stream);
572      $wrapped_char_stream->onerror ($char_onerror);
573    
574    my @args = @_; shift @args; # $s    my @args = @_; shift @args; # $s
575    my $return;    my $return;
576    try {    try {
577      $return = $self->parse_char_stream ($char_stream, @args);        $return = $self->parse_char_stream ($wrapped_char_stream, @args);  
578    } catch Whatpm::HTML::RestartParser with {    } catch Whatpm::HTML::RestartParser with {
579      ## NOTE: Invoked after {change_encoding}.      ## NOTE: Invoked after {change_encoding}.
580    
     $self->{input_encoding} = $charset->get_iana_name;  
581      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
582        !!!parse-error (type => 'chardecode:fallback', ## TODO: type name        $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name?
583                        value => $self->{input_encoding},        !!!parse-error (type => 'chardecode:fallback',
584                        level => $self->{unsupported_level},                        level => $self->{level}->{uncertain},
585                        line => 1, column => 1);                        #text => $self->{input_encoding},
586                          line => 1, column => 1,
587                          layer => 'encode');
588      } elsif (not ($e_status &      } elsif (not ($e_status &
589                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
590        !!!parse-error (type => 'chardecode:no error', ## TODO: type name        $self->{input_encoding} = $charset->get_iana_name;
591                        value => $self->{input_encoding},        !!!parse-error (type => 'chardecode:no error',
592                        level => $self->{unsupported_level},                        text => $self->{input_encoding},
593                        line => 1, column => 1);                        level => $self->{level}->{uncertain},
594                          line => 1, column => 1,
595                          layer => 'encode');
596        } else {
597          $self->{input_encoding} = $charset->get_iana_name;
598      }      }
599      $self->{confident} = 1;      $self->{confident} = 1;
600      $char_stream->onerror ($char_onerror);  
601      $return = $self->parse_char_stream ($char_stream, @args);      $wrapped_char_stream = $get_wrapper->($char_stream);
602        $wrapped_char_stream->onerror ($char_onerror);
603    
604        $return = $self->parse_char_stream ($wrapped_char_stream, @args);
605    };    };
606    return $return;    return $return;
607  } # parse_byte_stream  } # parse_byte_stream
# Line 581  sub parse_byte_stream ($$$$;$) { Line 615  sub parse_byte_stream ($$$$;$) {
615  ## such as |parse_byte_string| in this module, must ensure that it does  ## such as |parse_byte_string| in this module, must ensure that it does
616  ## strip the BOM and never strip any ZWNBSP.  ## strip the BOM and never strip any ZWNBSP.
617    
618  sub parse_char_string ($$$;$) {  sub parse_char_string ($$$;$$) {
619      #my ($self, $s, $doc, $onerror, $get_wrapper) = @_;
620    my $self = shift;    my $self = shift;
621    require utf8;    require utf8;
622    my $s = ref $_[0] ? $_[0] : \($_[0]);    my $s = ref $_[0] ? $_[0] : \($_[0]);
623    open my $input, '<' . (utf8::is_utf8 ($$s) ? ':utf8' : ''), $s;    open my $input, '<' . (utf8::is_utf8 ($$s) ? ':utf8' : ''), $s;
624      if ($_[3]) {
625        $input = $_[3]->($input);
626      }
627    return $self->parse_char_stream ($input, @_[1..$#_]);    return $self->parse_char_stream ($input, @_[1..$#_]);
628  } # parse_char_string  } # parse_char_string
629  *parse_string = \&parse_char_string;  *parse_string = \&parse_char_string; ## NOTE: Alias for backward compatibility.
630    
631  sub parse_char_stream ($$$;$) {  sub parse_char_stream ($$$;$) {
632    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
# Line 662  sub parse_char_stream ($$$;$) { Line 700  sub parse_char_stream ($$$;$) {
700                0x10FFFE => 1, 0x10FFFF => 1,                0x10FFFE => 1, 0x10FFFF => 1,
701               }->{$self->{next_char}}) {               }->{$self->{next_char}}) {
702        !!!cp ('j5');        !!!cp ('j5');
703        !!!parse-error (type => 'control char', level => $self->{must_level});        if ($self->{next_char} < 0x10000) {
704  ## TODO: error type documentation          !!!parse-error (type => 'control char',
705                            text => (sprintf 'U+%04X', $self->{next_char}));
706          } else {
707            !!!parse-error (type => 'control char',
708                            text => (sprintf 'U-%08X', $self->{next_char}));
709          }
710      }      }
711    };    };
712    $self->{prev_char} = [-1, -1, -1];    $self->{prev_char} = [-1, -1, -1];
# Line 692  sub parse_char_stream ($$$;$) { Line 735  sub parse_char_stream ($$$;$) {
735  sub new ($) {  sub new ($) {
736    my $class = shift;    my $class = shift;
737    my $self = bless {    my $self = bless {
738      must_level => 'm',      level => {must => 'm',
739      should_level => 's',                should => 's',
740      good_level => 'w',                warn => 'w',
741      warn_level => 'w',                info => 'i',
742      info_level => 'i',                uncertain => 'u'},
     unsupported_level => 'u',  
743    }, $class;    }, $class;
744    $self->{set_next_char} = sub {    $self->{set_next_char} = sub {
745      $self->{next_char} = -1;      $self->{next_char} = -1;
# Line 1356  sub _get_next_token ($) { Line 1398  sub _get_next_token ($) {
1398          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
1399              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
1400            !!!cp (57);            !!!cp (57);
1401            !!!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});
1402            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{current_attribute} # MUST
1403          } else {          } else {
1404            !!!cp (58);            !!!cp (58);
# Line 1527  sub _get_next_token ($) { Line 1569  sub _get_next_token ($) {
1569    
1570          redo A;          redo A;
1571        } else {        } else {
1572          !!!cp (82);          if ($self->{next_char} == 0x0022 or # "
1573                $self->{next_char} == 0x0027) { # '
1574              !!!cp (78);
1575              !!!parse-error (type => 'bad attribute name');
1576            } else {
1577              !!!cp (82);
1578            }
1579          $self->{current_attribute}          $self->{current_attribute}
1580              = {name => chr ($self->{next_char}),              = {name => chr ($self->{next_char}),
1581                 value => '',                 value => '',
# Line 1562  sub _get_next_token ($) { Line 1610  sub _get_next_token ($) {
1610          !!!next-input-character;          !!!next-input-character;
1611          redo A;          redo A;
1612        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1613            !!!parse-error (type => 'empty unquoted attribute value');
1614          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1615            !!!cp (87);            !!!cp (87);
1616            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
# Line 2667  sub _get_next_token ($) { Line 2716  sub _get_next_token ($) {
2716          redo A;          redo A;
2717        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2718          !!!cp (208);          !!!cp (208);
2719          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2720    
2721          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2722          !!!next-input-character;          !!!next-input-character;
# Line 2703  sub _get_next_token ($) { Line 2752  sub _get_next_token ($) {
2752          redo A;          redo A;
2753        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2754          !!!cp (212);          !!!cp (212);
2755          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2756    
2757          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2758          !!!next-input-character;          !!!next-input-character;
# Line 2912  sub _tokenize_attempt_to_consume_an_enti Line 2961  sub _tokenize_attempt_to_consume_an_enti
2961    
2962          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2963            !!!cp (1008);            !!!cp (1008);
2964            !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
2965                              text => (sprintf 'U+%04X', $code),
2966                              line => $l, column => $c);
2967            $code = 0xFFFD;            $code = 0xFFFD;
2968          } elsif ($code > 0x10FFFF) {          } elsif ($code > 0x10FFFF) {
2969            !!!cp (1009);            !!!cp (1009);
2970            !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
2971                              text => (sprintf 'U-%08X', $code),
2972                              line => $l, column => $c);
2973            $code = 0xFFFD;            $code = 0xFFFD;
2974          } elsif ($code == 0x000D) {          } elsif ($code == 0x000D) {
2975            !!!cp (1010);            !!!cp (1010);
# Line 2924  sub _tokenize_attempt_to_consume_an_enti Line 2977  sub _tokenize_attempt_to_consume_an_enti
2977            $code = 0x000A;            $code = 0x000A;
2978          } elsif (0x80 <= $code and $code <= 0x9F) {          } elsif (0x80 <= $code and $code <= 0x9F) {
2979            !!!cp (1011);            !!!cp (1011);
2980            !!!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);
2981            $code = $c1_entity_char->{$code};            $code = $c1_entity_char->{$code};
2982          }          }
2983    
# Line 2957  sub _tokenize_attempt_to_consume_an_enti Line 3010  sub _tokenize_attempt_to_consume_an_enti
3010    
3011        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3012          !!!cp (1015);          !!!cp (1015);
3013          !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3014                            text => (sprintf 'U+%04X', $code),
3015                            line => $l, column => $c);
3016          $code = 0xFFFD;          $code = 0xFFFD;
3017        } elsif ($code > 0x10FFFF) {        } elsif ($code > 0x10FFFF) {
3018          !!!cp (1016);          !!!cp (1016);
3019          !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3020                            text => (sprintf 'U-%08X', $code),
3021                            line => $l, column => $c);
3022          $code = 0xFFFD;          $code = 0xFFFD;
3023        } elsif ($code == 0x000D) {        } elsif ($code == 0x000D) {
3024          !!!cp (1017);          !!!cp (1017);
3025          !!!parse-error (type => 'CR character reference', line => $l, column => $c);          !!!parse-error (type => 'CR character reference',
3026                            line => $l, column => $c);
3027          $code = 0x000A;          $code = 0x000A;
3028        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
3029          !!!cp (1018);          !!!cp (1018);
3030          !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'C1 character reference',
3031                            text => (sprintf 'U+%04X', $code),
3032                            line => $l, column => $c);
3033          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
3034        }        }
3035                
# Line 3067  sub _initialize_tree_constructor ($) { Line 3127  sub _initialize_tree_constructor ($) {
3127    ## TODO: Turn mutation events off # MUST    ## TODO: Turn mutation events off # MUST
3128    ## TODO: Turn loose Document option (manakai extension) on    ## TODO: Turn loose Document option (manakai extension) on
3129    $self->{document}->manakai_is_html (1); # MUST    $self->{document}->manakai_is_html (1); # MUST
3130      $self->{document}->set_user_data (manakai_source_line => 1);
3131      $self->{document}->set_user_data (manakai_source_column => 1);
3132  } # _initialize_tree_constructor  } # _initialize_tree_constructor
3133    
3134  sub _terminate_tree_constructor ($) {  sub _terminate_tree_constructor ($) {
# Line 3121  sub _tree_construction_initial ($) { Line 3183  sub _tree_construction_initial ($) {
3183        ## language.        ## language.
3184        my $doctype_name = $token->{name};        my $doctype_name = $token->{name};
3185        $doctype_name = '' unless defined $doctype_name;        $doctype_name = '' unless defined $doctype_name;
3186        $doctype_name =~ tr/a-z/A-Z/;        $doctype_name =~ tr/a-z/A-Z/; # ASCII case-insensitive
3187        if (not defined $token->{name} or # <!DOCTYPE>        if (not defined $token->{name} or # <!DOCTYPE>
           defined $token->{public_identifier} or  
3188            defined $token->{system_identifier}) {            defined $token->{system_identifier}) {
3189          !!!cp ('t1');          !!!cp ('t1');
3190          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3191        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
3192          !!!cp ('t2');          !!!cp ('t2');
         ## ISSUE: ASCII case-insensitive? (in fact it does not matter)  
3193          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3194          } elsif (defined $token->{public_identifier}) {
3195            if ($token->{public_identifier} eq 'XSLT-compat') {
3196              !!!cp ('t1.2');
3197              !!!parse-error (type => 'XSLT-compat', token => $token,
3198                              level => $self->{level}->{should});
3199            } else {
3200              !!!parse-error (type => 'not HTML5', token => $token);
3201            }
3202        } else {        } else {
3203          !!!cp ('t3');          !!!cp ('t3');
3204            #
3205        }        }
3206                
3207        my $doctype = $self->{document}->create_document_type_definition        my $doctype = $self->{document}->create_document_type_definition
# Line 3634  sub _tree_construction_main ($) { Line 3703  sub _tree_construction_main ($) {
3703        ## NOTE: An end-of-file token.        ## NOTE: An end-of-file token.
3704        if ($content_model_flag == CDATA_CONTENT_MODEL) {        if ($content_model_flag == CDATA_CONTENT_MODEL) {
3705          !!!cp ('t43');          !!!cp ('t43');
3706          !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in CDATA:#eof', token => $token);
3707        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
3708          !!!cp ('t44');          !!!cp ('t44');
3709          !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in RCDATA:#eof', token => $token);
3710        } else {        } else {
3711          die "$0: $content_model_flag in parse_rcdata";          die "$0: $content_model_flag in parse_rcdata";
3712        }        }
# Line 3674  sub _tree_construction_main ($) { Line 3743  sub _tree_construction_main ($) {
3743        ## Ignore the token        ## Ignore the token
3744      } else {      } else {
3745        !!!cp ('t48');        !!!cp ('t48');
3746        !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);        !!!parse-error (type => 'in CDATA:#eof', token => $token);
3747        ## ISSUE: And ignore?        ## ISSUE: And ignore?
3748        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
3749      }      }
# Line 3725  sub _tree_construction_main ($) { Line 3794  sub _tree_construction_main ($) {
3794        } # AFE        } # AFE
3795        unless (defined $formatting_element) {        unless (defined $formatting_element) {
3796          !!!cp ('t53');          !!!cp ('t53');
3797          !!!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);
3798          ## Ignore the token          ## Ignore the token
3799          !!!next-token;          !!!next-token;
3800          return;          return;
# Line 3742  sub _tree_construction_main ($) { Line 3811  sub _tree_construction_main ($) {
3811              last INSCOPE;              last INSCOPE;
3812            } else { # in open elements but not in scope            } else { # in open elements but not in scope
3813              !!!cp ('t55');              !!!cp ('t55');
3814              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},              !!!parse-error (type => 'unmatched end tag',
3815                                text => $token->{tag_name},
3816                              token => $end_tag_token);                              token => $end_tag_token);
3817              ## Ignore the token              ## Ignore the token
3818              !!!next-token;              !!!next-token;
# Line 3755  sub _tree_construction_main ($) { Line 3825  sub _tree_construction_main ($) {
3825        } # INSCOPE        } # INSCOPE
3826        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
3827          !!!cp ('t57');          !!!cp ('t57');
3828          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},          !!!parse-error (type => 'unmatched end tag',
3829                            text => $token->{tag_name},
3830                          token => $end_tag_token);                          token => $end_tag_token);
3831          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
3832          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
# Line 3764  sub _tree_construction_main ($) { Line 3835  sub _tree_construction_main ($) {
3835        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
3836          !!!cp ('t58');          !!!cp ('t58');
3837          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
3838                          value => $self->{open_elements}->[-1]->[0]                          text => $self->{open_elements}->[-1]->[0]
3839                              ->manakai_local_name,                              ->manakai_local_name,
3840                          token => $end_tag_token);                          token => $end_tag_token);
3841        }        }
# Line 3973  sub _tree_construction_main ($) { Line 4044  sub _tree_construction_main ($) {
4044    B: while (1) {    B: while (1) {
4045      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
4046        !!!cp ('t73');        !!!cp ('t73');
4047        !!!parse-error (type => 'DOCTYPE in the middle', token => $token);        !!!parse-error (type => 'in html:#DOCTYPE', token => $token);
4048        ## Ignore the token        ## Ignore the token
4049        ## Stay in the phase        ## Stay in the phase
4050        !!!next-token;        !!!next-token;
# Line 3982  sub _tree_construction_main ($) { Line 4053  sub _tree_construction_main ($) {
4053               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
4054        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
4055          !!!cp ('t79');          !!!cp ('t79');
4056          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4057          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
4058        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
4059          !!!cp ('t80');          !!!cp ('t80');
4060          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4061          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
4062        } else {        } else {
4063          !!!cp ('t81');          !!!cp ('t81');
# Line 4047  sub _tree_construction_main ($) { Line 4118  sub _tree_construction_main ($) {
4118                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
4119            !!!cp ('t87.2');            !!!cp ('t87.2');
4120            !!!parse-error (type => 'not closed',            !!!parse-error (type => 'not closed',
4121                            value => $self->{open_elements}->[-1]->[0]                            text => $self->{open_elements}->[-1]->[0]
4122                                ->manakai_local_name,                                ->manakai_local_name,
4123                            token => $token);                            token => $token);
4124    
# Line 4125  sub _tree_construction_main ($) { Line 4196  sub _tree_construction_main ($) {
4196        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
4197          !!!cp ('t87.6');          !!!cp ('t87.6');
4198          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
4199                          value => $self->{open_elements}->[-1]->[0]                          text => $self->{open_elements}->[-1]->[0]
4200                              ->manakai_local_name,                              ->manakai_local_name,
4201                          token => $token);                          token => $token);
4202    
# Line 4175  sub _tree_construction_main ($) { Line 4246  sub _tree_construction_main ($) {
4246            !!!cp ('t90');            !!!cp ('t90');
4247            ## As if </noscript>            ## As if </noscript>
4248            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
4249            !!!parse-error (type => 'in noscript:#character', token => $token);            !!!parse-error (type => 'in noscript:#text', token => $token);
4250                        
4251            ## Reprocess in the "in head" insertion mode...            ## Reprocess in the "in head" insertion mode...
4252            ## As if </head>            ## As if </head>
# Line 4212  sub _tree_construction_main ($) { Line 4283  sub _tree_construction_main ($) {
4283              next B;              next B;
4284            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4285              !!!cp ('t93.2');              !!!cp ('t93.2');
4286              !!!parse-error (type => 'after head:head', token => $token); ## TODO: error type              !!!parse-error (type => 'after head', text => 'head',
4287                                token => $token);
4288              ## Ignore the token              ## Ignore the token
4289              !!!nack ('t93.3');              !!!nack ('t93.3');
4290              !!!next-token;              !!!next-token;
4291              next B;              next B;
4292            } else {            } else {
4293              !!!cp ('t95');              !!!cp ('t95');
4294              !!!parse-error (type => 'in head:head', token => $token); # or in head noscript              !!!parse-error (type => 'in head:head',
4295                                token => $token); # or in head noscript
4296              ## Ignore the token              ## Ignore the token
4297              !!!nack ('t95.1');              !!!nack ('t95.1');
4298              !!!next-token;              !!!next-token;
# Line 4244  sub _tree_construction_main ($) { Line 4317  sub _tree_construction_main ($) {
4317                  !!!cp ('t98');                  !!!cp ('t98');
4318                  ## As if </noscript>                  ## As if </noscript>
4319                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4320                  !!!parse-error (type => 'in noscript:base', token => $token);                  !!!parse-error (type => 'in noscript', text => 'base',
4321                                    token => $token);
4322                                
4323                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4324                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
# Line 4255  sub _tree_construction_main ($) { Line 4329  sub _tree_construction_main ($) {
4329                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4330                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4331                  !!!cp ('t100');                  !!!cp ('t100');
4332                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4333                                    text => $token->{tag_name}, token => $token);
4334                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4335                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4336                } else {                } else {
# Line 4272  sub _tree_construction_main ($) { Line 4347  sub _tree_construction_main ($) {
4347                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4348                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4349                  !!!cp ('t102');                  !!!cp ('t102');
4350                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4351                                    text => $token->{tag_name}, token => $token);
4352                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4353                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4354                } else {                } else {
# Line 4289  sub _tree_construction_main ($) { Line 4365  sub _tree_construction_main ($) {
4365                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4366                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4367                  !!!cp ('t104');                  !!!cp ('t104');
4368                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4369                                    text => $token->{tag_name}, token => $token);
4370                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4371                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4372                } else {                } else {
# Line 4358  sub _tree_construction_main ($) { Line 4435  sub _tree_construction_main ($) {
4435                  !!!cp ('t111');                  !!!cp ('t111');
4436                  ## As if </noscript>                  ## As if </noscript>
4437                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4438                  !!!parse-error (type => 'in noscript:title', token => $token);                  !!!parse-error (type => 'in noscript', text => 'title',
4439                                    token => $token);
4440                                
4441                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4442                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4443                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4444                  !!!cp ('t112');                  !!!cp ('t112');
4445                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4446                                    text => $token->{tag_name}, token => $token);
4447                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4448                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4449                } else {                } else {
# Line 4385  sub _tree_construction_main ($) { Line 4464  sub _tree_construction_main ($) {
4464                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4465                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4466                  !!!cp ('t114');                  !!!cp ('t114');
4467                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4468                                    text => $token->{tag_name}, token => $token);
4469                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4470                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4471                } else {                } else {
# Line 4406  sub _tree_construction_main ($) { Line 4486  sub _tree_construction_main ($) {
4486                  next B;                  next B;
4487                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4488                  !!!cp ('t117');                  !!!cp ('t117');
4489                  !!!parse-error (type => 'in noscript:noscript', token => $token);                  !!!parse-error (type => 'in noscript', text => 'noscript',
4490                                    token => $token);
4491                  ## Ignore the token                  ## Ignore the token
4492                  !!!nack ('t117.1');                  !!!nack ('t117.1');
4493                  !!!next-token;                  !!!next-token;
# Line 4420  sub _tree_construction_main ($) { Line 4501  sub _tree_construction_main ($) {
4501                  !!!cp ('t119');                  !!!cp ('t119');
4502                  ## As if </noscript>                  ## As if </noscript>
4503                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4504                  !!!parse-error (type => 'in noscript:script', token => $token);                  !!!parse-error (type => 'in noscript', text => 'script',
4505                                    token => $token);
4506                                
4507                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4508                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4509                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4510                  !!!cp ('t120');                  !!!cp ('t120');
4511                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4512                                    text => $token->{tag_name}, token => $token);
4513                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4514                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4515                } else {                } else {
# Line 4444  sub _tree_construction_main ($) { Line 4527  sub _tree_construction_main ($) {
4527                  !!!cp ('t122');                  !!!cp ('t122');
4528                  ## As if </noscript>                  ## As if </noscript>
4529                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4530                  !!!parse-error (type => 'in noscript:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in noscript',
4531                                    text => $token->{tag_name}, token => $token);
4532                                    
4533                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4534                  ## As if </head>                  ## As if </head>
# Line 4483  sub _tree_construction_main ($) { Line 4567  sub _tree_construction_main ($) {
4567                !!!cp ('t129');                !!!cp ('t129');
4568                ## As if </noscript>                ## As if </noscript>
4569                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4570                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4571                                  text => $token->{tag_name}, token => $token);
4572                                
4573                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4574                ## As if </head>                ## As if </head>
# Line 4526  sub _tree_construction_main ($) { Line 4611  sub _tree_construction_main ($) {
4611                  !!!cp ('t133');                  !!!cp ('t133');
4612                  ## As if </noscript>                  ## As if </noscript>
4613                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4614                  !!!parse-error (type => 'in noscript:/head', token => $token);                  !!!parse-error (type => 'in noscript:/',
4615                                    text => 'head', token => $token);
4616                                    
4617                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4618                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 4541  sub _tree_construction_main ($) { Line 4627  sub _tree_construction_main ($) {
4627                  next B;                  next B;
4628                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4629                  !!!cp ('t134.1');                  !!!cp ('t134.1');
4630                  !!!parse-error (type => 'unmatched end tag:head', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'head',
4631                                    token => $token);
4632                  ## Ignore the token                  ## Ignore the token
4633                  !!!next-token;                  !!!next-token;
4634                  next B;                  next B;
# Line 4558  sub _tree_construction_main ($) { Line 4645  sub _tree_construction_main ($) {
4645                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or
4646                         $self->{insertion_mode} == AFTER_HEAD_IM) {                         $self->{insertion_mode} == AFTER_HEAD_IM) {
4647                  !!!cp ('t137');                  !!!cp ('t137');
4648                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4649                                    text => 'noscript', token => $token);
4650                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
4651                  !!!next-token;                  !!!next-token;
4652                  next B;                  next B;
# Line 4573  sub _tree_construction_main ($) { Line 4661  sub _tree_construction_main ($) {
4661                    $self->{insertion_mode} == IN_HEAD_IM or                    $self->{insertion_mode} == IN_HEAD_IM or
4662                    $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                    $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4663                  !!!cp ('t140');                  !!!cp ('t140');
4664                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4665                                    text => $token->{tag_name}, token => $token);
4666                  ## Ignore the token                  ## Ignore the token
4667                  !!!next-token;                  !!!next-token;
4668                  next B;                  next B;
4669                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4670                  !!!cp ('t140.1');                  !!!cp ('t140.1');
4671                  !!!parse-error (type => 'unmatched end tag:' . $token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4672                                    text => $token->{tag_name}, token => $token);
4673                  ## Ignore the token                  ## Ignore the token
4674                  !!!next-token;                  !!!next-token;
4675                  next B;                  next B;
# Line 4588  sub _tree_construction_main ($) { Line 4678  sub _tree_construction_main ($) {
4678                }                }
4679              } elsif ($token->{tag_name} eq 'p') {              } elsif ($token->{tag_name} eq 'p') {
4680                !!!cp ('t142');                !!!cp ('t142');
4681                !!!parse-error (type => 'unmatched end tag:p', token => $token);                !!!parse-error (type => 'unmatched end tag',
4682                                  text => $token->{tag_name}, token => $token);
4683                ## Ignore the token                ## Ignore the token
4684                !!!next-token;                !!!next-token;
4685                next B;                next B;
# Line 4611  sub _tree_construction_main ($) { Line 4702  sub _tree_construction_main ($) {
4702                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4703                  !!!cp ('t143.3');                  !!!cp ('t143.3');
4704                  ## ISSUE: Two parse errors for <head><noscript></br>                  ## ISSUE: Two parse errors for <head><noscript></br>
4705                  !!!parse-error (type => 'unmatched end tag:br', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4706                                    text => 'br', token => $token);
4707                  ## As if </noscript>                  ## As if </noscript>
4708                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4709                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
# Line 4630  sub _tree_construction_main ($) { Line 4722  sub _tree_construction_main ($) {
4722                }                }
4723    
4724                ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.                ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.
4725                !!!parse-error (type => 'unmatched end tag:br', token => $token);                !!!parse-error (type => 'unmatched end tag',
4726                                  text => 'br', token => $token);
4727                ## Ignore the token                ## Ignore the token
4728                !!!next-token;                !!!next-token;
4729                next B;                next B;
4730              } else {              } else {
4731                !!!cp ('t145');                !!!cp ('t145');
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                ## Ignore the token
4735                !!!next-token;                !!!next-token;
4736                next B;                next B;
# Line 4646  sub _tree_construction_main ($) { Line 4740  sub _tree_construction_main ($) {
4740                !!!cp ('t146');                !!!cp ('t146');
4741                ## As if </noscript>                ## As if </noscript>
4742                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4743                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4744                                  text => $token->{tag_name}, token => $token);
4745                                
4746                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4747                ## As if </head>                ## As if </head>
# Line 4662  sub _tree_construction_main ($) { Line 4757  sub _tree_construction_main ($) {
4757              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4758  ## ISSUE: This case cannot be reached?  ## ISSUE: This case cannot be reached?
4759                !!!cp ('t148');                !!!cp ('t148');
4760                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
4761                                  text => $token->{tag_name}, token => $token);
4762                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
4763                !!!next-token;                !!!next-token;
4764                next B;                next B;
# Line 4773  sub _tree_construction_main ($) { Line 4869  sub _tree_construction_main ($) {
4869    
4870                  !!!cp ('t153');                  !!!cp ('t153');
4871                  !!!parse-error (type => 'start tag not allowed',                  !!!parse-error (type => 'start tag not allowed',
4872                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
4873                  ## Ignore the token                  ## Ignore the token
4874                  !!!nack ('t153.1');                  !!!nack ('t153.1');
4875                  !!!next-token;                  !!!next-token;
4876                  next B;                  next B;
4877                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4878                  !!!parse-error (type => 'not closed:caption', token => $token);                  !!!parse-error (type => 'not closed', text => 'caption',
4879                                    token => $token);
4880                                    
4881                  ## NOTE: As if </caption>.                  ## NOTE: As if </caption>.
4882                  ## have a table element in table scope                  ## have a table element in table scope
# Line 4799  sub _tree_construction_main ($) { Line 4896  sub _tree_construction_main ($) {
4896    
4897                    !!!cp ('t157');                    !!!cp ('t157');
4898                    !!!parse-error (type => 'start tag not allowed',                    !!!parse-error (type => 'start tag not allowed',
4899                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
4900                    ## Ignore the token                    ## Ignore the token
4901                    !!!nack ('t157.1');                    !!!nack ('t157.1');
4902                    !!!next-token;                    !!!next-token;
# Line 4816  sub _tree_construction_main ($) { Line 4913  sub _tree_construction_main ($) {
4913                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
4914                    !!!cp ('t159');                    !!!cp ('t159');
4915                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
4916                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
4917                                        ->manakai_local_name,                                        ->manakai_local_name,
4918                                    token => $token);                                    token => $token);
4919                  } else {                  } else {
# Line 4858  sub _tree_construction_main ($) { Line 4955  sub _tree_construction_main ($) {
4955                  } # INSCOPE                  } # INSCOPE
4956                    unless (defined $i) {                    unless (defined $i) {
4957                      !!!cp ('t165');                      !!!cp ('t165');
4958                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
4959                                        text => $token->{tag_name},
4960                                        token => $token);
4961                      ## Ignore the token                      ## Ignore the token
4962                      !!!next-token;                      !!!next-token;
4963                      next B;                      next B;
# Line 4875  sub _tree_construction_main ($) { Line 4974  sub _tree_construction_main ($) {
4974                          ne $token->{tag_name}) {                          ne $token->{tag_name}) {
4975                    !!!cp ('t167');                    !!!cp ('t167');
4976                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
4977                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
4978                                        ->manakai_local_name,                                        ->manakai_local_name,
4979                                    token => $token);                                    token => $token);
4980                  } else {                  } else {
# Line 4892  sub _tree_construction_main ($) { Line 4991  sub _tree_construction_main ($) {
4991                  next B;                  next B;
4992                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4993                  !!!cp ('t169');                  !!!cp ('t169');
4994                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4995                                    text => $token->{tag_name}, token => $token);
4996                  ## Ignore the token                  ## Ignore the token
4997                  !!!next-token;                  !!!next-token;
4998                  next B;                  next B;
# Line 4919  sub _tree_construction_main ($) { Line 5019  sub _tree_construction_main ($) {
5019    
5020                    !!!cp ('t173');                    !!!cp ('t173');
5021                    !!!parse-error (type => 'unmatched end tag',                    !!!parse-error (type => 'unmatched end tag',
5022                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
5023                    ## Ignore the token                    ## Ignore the token
5024                    !!!next-token;                    !!!next-token;
5025                    next B;                    next B;
# Line 4935  sub _tree_construction_main ($) { Line 5035  sub _tree_construction_main ($) {
5035                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5036                    !!!cp ('t175');                    !!!cp ('t175');
5037                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5038                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5039                                        ->manakai_local_name,                                        ->manakai_local_name,
5040                                    token => $token);                                    token => $token);
5041                  } else {                  } else {
# Line 4952  sub _tree_construction_main ($) { Line 5052  sub _tree_construction_main ($) {
5052                  next B;                  next B;
5053                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
5054                  !!!cp ('t177');                  !!!cp ('t177');
5055                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5056                                    text => $token->{tag_name}, token => $token);
5057                  ## Ignore the token                  ## Ignore the token
5058                  !!!next-token;                  !!!next-token;
5059                  next B;                  next B;
# Line 4995  sub _tree_construction_main ($) { Line 5096  sub _tree_construction_main ($) {
5096    
5097                  !!!cp ('t182');                  !!!cp ('t182');
5098                  !!!parse-error (type => 'unmatched end tag',                  !!!parse-error (type => 'unmatched end tag',
5099                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
5100                  ## Ignore the token                  ## Ignore the token
5101                  !!!next-token;                  !!!next-token;
5102                  next B;                  next B;
5103                } # INSCOPE                } # INSCOPE
5104              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
5105                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5106                !!!parse-error (type => 'not closed:caption', token => $token);                !!!parse-error (type => 'not closed', text => 'caption',
5107                                  token => $token);
5108    
5109                ## As if </caption>                ## As if </caption>
5110                ## have a table element in table scope                ## have a table element in table scope
# Line 5020  sub _tree_construction_main ($) { Line 5122  sub _tree_construction_main ($) {
5122                } # INSCOPE                } # INSCOPE
5123                unless (defined $i) {                unless (defined $i) {
5124                  !!!cp ('t186');                  !!!cp ('t186');
5125                  !!!parse-error (type => 'unmatched end tag:caption', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5126                                    text => 'caption', token => $token);
5127                  ## Ignore the token                  ## Ignore the token
5128                  !!!next-token;                  !!!next-token;
5129                  next B;                  next B;
# Line 5035  sub _tree_construction_main ($) { Line 5138  sub _tree_construction_main ($) {
5138                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5139                  !!!cp ('t188');                  !!!cp ('t188');
5140                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5141                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5142                                      ->manakai_local_name,                                      ->manakai_local_name,
5143                                  token => $token);                                  token => $token);
5144                } else {                } else {
# Line 5055  sub _tree_construction_main ($) { Line 5158  sub _tree_construction_main ($) {
5158                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5159                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
5160                  !!!cp ('t190');                  !!!cp ('t190');
5161                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5162                                    text => $token->{tag_name}, token => $token);
5163                  ## Ignore the token                  ## Ignore the token
5164                  !!!next-token;                  !!!next-token;
5165                  next B;                  next B;
# Line 5069  sub _tree_construction_main ($) { Line 5173  sub _tree_construction_main ($) {
5173                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
5174                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5175                !!!cp ('t192');                !!!cp ('t192');
5176                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
5177                                  text => $token->{tag_name}, token => $token);
5178                ## Ignore the token                ## Ignore the token
5179                !!!next-token;                !!!next-token;
5180                next B;                next B;
# Line 5109  sub _tree_construction_main ($) { Line 5214  sub _tree_construction_main ($) {
5214            }            }
5215          }          }
5216    
5217              !!!parse-error (type => 'in table:#character', token => $token);          !!!parse-error (type => 'in table:#text', token => $token);
5218    
5219              ## As if in body, but insert into foster parent element              ## As if in body, but insert into foster parent element
5220              ## ISSUE: Spec says that "whenever a node would be inserted              ## ISSUE: Spec says that "whenever a node would be inserted
# Line 5160  sub _tree_construction_main ($) { Line 5265  sub _tree_construction_main ($) {
5265          !!!next-token;          !!!next-token;
5266          next B;          next B;
5267        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5268              if ({          if ({
5269                   tr => ($self->{insertion_mode} != IN_ROW_IM),               tr => ($self->{insertion_mode} != IN_ROW_IM),
5270                   th => 1, td => 1,               th => 1, td => 1,
5271                  }->{$token->{tag_name}}) {              }->{$token->{tag_name}}) {
5272                if ($self->{insertion_mode} == IN_TABLE_IM) {            if ($self->{insertion_mode} == IN_TABLE_IM) {
5273                  ## Clear back to table context              ## Clear back to table context
5274                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5275                                  & TABLE_SCOPING_EL)) {                              & TABLE_SCOPING_EL)) {
5276                    !!!cp ('t201');                !!!cp ('t201');
5277                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5278                  }              }
5279                                
5280                  !!!insert-element ('tbody',, $token);              !!!insert-element ('tbody',, $token);
5281                  $self->{insertion_mode} = IN_TABLE_BODY_IM;              $self->{insertion_mode} = IN_TABLE_BODY_IM;
5282                  ## reprocess in the "in table body" insertion mode...              ## reprocess in the "in table body" insertion mode...
5283                }            }
5284              
5285                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {            if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
5286                  unless ($token->{tag_name} eq 'tr') {              unless ($token->{tag_name} eq 'tr') {
5287                    !!!cp ('t202');                !!!cp ('t202');
5288                    !!!parse-error (type => 'missing start tag:tr', token => $token);                !!!parse-error (type => 'missing start tag:tr', token => $token);
5289                  }              }
5290                                    
5291                  ## Clear back to table body context              ## Clear back to table body context
5292                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5293                                  & TABLE_ROWS_SCOPING_EL)) {                              & TABLE_ROWS_SCOPING_EL)) {
5294                    !!!cp ('t203');                !!!cp ('t203');
5295                    ## ISSUE: Can this case be reached?                ## ISSUE: Can this case be reached?
5296                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5297                  }              }
5298                                    
5299                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
5300                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
# Line 5245  sub _tree_construction_main ($) { Line 5350  sub _tree_construction_main ($) {
5350                  unless (defined $i) {                  unless (defined $i) {
5351                    !!!cp ('t210');                    !!!cp ('t210');
5352  ## TODO: This type is wrong.  ## TODO: This type is wrong.
5353                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmacthed end tag',
5354                                      text => $token->{tag_name}, token => $token);
5355                    ## Ignore the token                    ## Ignore the token
5356                    !!!nack ('t210.1');                    !!!nack ('t210.1');
5357                    !!!next-token;                    !!!next-token;
# Line 5289  sub _tree_construction_main ($) { Line 5395  sub _tree_construction_main ($) {
5395                  } # INSCOPE                  } # INSCOPE
5396                  unless (defined $i) {                  unless (defined $i) {
5397                    !!!cp ('t216');                    !!!cp ('t216');
5398  ## TODO: This erorr type ios wrong.  ## TODO: This erorr type is wrong.
5399                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5400                                      text => $token->{tag_name}, token => $token);
5401                    ## Ignore the token                    ## Ignore the token
5402                    !!!nack ('t216.1');                    !!!nack ('t216.1');
5403                    !!!next-token;                    !!!next-token;
# Line 5365  sub _tree_construction_main ($) { Line 5472  sub _tree_construction_main ($) {
5472                }                }
5473              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
5474                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
5475                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
5476                                    ->manakai_local_name,                                    ->manakai_local_name,
5477                                token => $token);                                token => $token);
5478    
# Line 5386  sub _tree_construction_main ($) { Line 5493  sub _tree_construction_main ($) {
5493                unless (defined $i) {                unless (defined $i) {
5494                  !!!cp ('t223');                  !!!cp ('t223');
5495  ## TODO: The following is wrong, maybe.  ## TODO: The following is wrong, maybe.
5496                  !!!parse-error (type => 'unmatched end tag:table', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'table',
5497                                    token => $token);
5498                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
5499                  !!!nack ('t223.1');                  !!!nack ('t223.1');
5500                  !!!next-token;                  !!!next-token;
# Line 5404  sub _tree_construction_main ($) { Line 5512  sub _tree_construction_main ($) {
5512                  !!!cp ('t225');                  !!!cp ('t225');
5513                  ## NOTE: |<table><tr><table>|                  ## NOTE: |<table><tr><table>|
5514                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5515                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5516                                      ->manakai_local_name,                                      ->manakai_local_name,
5517                                  token => $token);                                  token => $token);
5518                } else {                } else {
# Line 5445  sub _tree_construction_main ($) { Line 5553  sub _tree_construction_main ($) {
5553                my $type = lc $token->{attributes}->{type}->{value};                my $type = lc $token->{attributes}->{type}->{value};
5554                if ($type eq 'hidden') {                if ($type eq 'hidden') {
5555                  !!!cp ('t227.3');                  !!!cp ('t227.3');
5556                  !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in table',
5557                                    text => $token->{tag_name}, token => $token);
5558    
5559                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5560    
# Line 5473  sub _tree_construction_main ($) { Line 5582  sub _tree_construction_main ($) {
5582            #            #
5583          }          }
5584    
5585          !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in table', text => $token->{tag_name},
5586                            token => $token);
5587    
5588          $insert = $insert_to_foster;          $insert = $insert_to_foster;
5589          #          #
# Line 5495  sub _tree_construction_main ($) { Line 5605  sub _tree_construction_main ($) {
5605                } # INSCOPE                } # INSCOPE
5606                unless (defined $i) {                unless (defined $i) {
5607                  !!!cp ('t230');                  !!!cp ('t230');
5608                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5609                                    text => $token->{tag_name}, token => $token);
5610                  ## Ignore the token                  ## Ignore the token
5611                  !!!nack ('t230.1');                  !!!nack ('t230.1');
5612                  !!!next-token;                  !!!next-token;
# Line 5536  sub _tree_construction_main ($) { Line 5647  sub _tree_construction_main ($) {
5647                  unless (defined $i) {                  unless (defined $i) {
5648                    !!!cp ('t235');                    !!!cp ('t235');
5649  ## TODO: The following is wrong.  ## TODO: The following is wrong.
5650                    !!!parse-error (type => 'unmatched end tag:'.$token->{type}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5651                                      text => $token->{type}, token => $token);
5652                    ## Ignore the token                    ## Ignore the token
5653                    !!!nack ('t236.1');                    !!!nack ('t236.1');
5654                    !!!next-token;                    !!!next-token;
# Line 5572  sub _tree_construction_main ($) { Line 5684  sub _tree_construction_main ($) {
5684                  } # INSCOPE                  } # INSCOPE
5685                  unless (defined $i) {                  unless (defined $i) {
5686                    !!!cp ('t239');                    !!!cp ('t239');
5687                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5688                                      text => $token->{tag_name}, token => $token);
5689                    ## Ignore the token                    ## Ignore the token
5690                    !!!nack ('t239.1');                    !!!nack ('t239.1');
5691                    !!!next-token;                    !!!next-token;
# Line 5618  sub _tree_construction_main ($) { Line 5731  sub _tree_construction_main ($) {
5731                } # INSCOPE                } # INSCOPE
5732                unless (defined $i) {                unless (defined $i) {
5733                  !!!cp ('t243');                  !!!cp ('t243');
5734                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5735                                    text => $token->{tag_name}, token => $token);
5736                  ## Ignore the token                  ## Ignore the token
5737                  !!!nack ('t243.1');                  !!!nack ('t243.1');
5738                  !!!next-token;                  !!!next-token;
# Line 5652  sub _tree_construction_main ($) { Line 5766  sub _tree_construction_main ($) {
5766                  } # INSCOPE                  } # INSCOPE
5767                    unless (defined $i) {                    unless (defined $i) {
5768                      !!!cp ('t249');                      !!!cp ('t249');
5769                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5770                                        text => $token->{tag_name}, token => $token);
5771                      ## Ignore the token                      ## Ignore the token
5772                      !!!nack ('t249.1');                      !!!nack ('t249.1');
5773                      !!!next-token;                      !!!next-token;
# Line 5675  sub _tree_construction_main ($) { Line 5790  sub _tree_construction_main ($) {
5790                  } # INSCOPE                  } # INSCOPE
5791                    unless (defined $i) {                    unless (defined $i) {
5792                      !!!cp ('t252');                      !!!cp ('t252');
5793                      !!!parse-error (type => 'unmatched end tag:tr', token => $token);                      !!!parse-error (type => 'unmatched end tag',
5794                                        text => 'tr', token => $token);
5795                      ## Ignore the token                      ## Ignore the token
5796                      !!!nack ('t252.1');                      !!!nack ('t252.1');
5797                      !!!next-token;                      !!!next-token;
# Line 5710  sub _tree_construction_main ($) { Line 5826  sub _tree_construction_main ($) {
5826                } # INSCOPE                } # INSCOPE
5827                unless (defined $i) {                unless (defined $i) {
5828                  !!!cp ('t256');                  !!!cp ('t256');
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 ('t256.1');                  !!!nack ('t256.1');
5833                  !!!next-token;                  !!!next-token;
# Line 5737  sub _tree_construction_main ($) { Line 5854  sub _tree_construction_main ($) {
5854                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
5855                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5856            !!!cp ('t258');            !!!cp ('t258');
5857            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
5858                              text => $token->{tag_name}, token => $token);
5859            ## Ignore the token            ## Ignore the token
5860            !!!nack ('t258.1');            !!!nack ('t258.1');
5861             !!!next-token;             !!!next-token;
5862            next B;            next B;
5863          } else {          } else {
5864            !!!cp ('t259');            !!!cp ('t259');
5865            !!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in table:/',
5866                              text => $token->{tag_name}, token => $token);
5867    
5868            $insert = $insert_to_foster;            $insert = $insert_to_foster;
5869            #            #
# Line 5794  sub _tree_construction_main ($) { Line 5913  sub _tree_construction_main ($) {
5913              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
5914                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
5915                  !!!cp ('t264');                  !!!cp ('t264');
5916                  !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5917                                    text => 'colgroup', token => $token);
5918                  ## Ignore the token                  ## Ignore the token
5919                  !!!next-token;                  !!!next-token;
5920                  next B;                  next B;
# Line 5807  sub _tree_construction_main ($) { Line 5927  sub _tree_construction_main ($) {
5927                }                }
5928              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
5929                !!!cp ('t266');                !!!cp ('t266');
5930                !!!parse-error (type => 'unmatched end tag:col', token => $token);                !!!parse-error (type => 'unmatched end tag',
5931                                  text => 'col', token => $token);
5932                ## Ignore the token                ## Ignore the token
5933                !!!next-token;                !!!next-token;
5934                next B;                next B;
# Line 5837  sub _tree_construction_main ($) { Line 5958  sub _tree_construction_main ($) {
5958            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
5959              !!!cp ('t269');              !!!cp ('t269');
5960  ## TODO: Wrong error type?  ## TODO: Wrong error type?
5961              !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);              !!!parse-error (type => 'unmatched end tag',
5962                                text => 'colgroup', token => $token);
5963              ## Ignore the token              ## Ignore the token
5964              !!!nack ('t269.1');              !!!nack ('t269.1');
5965              !!!next-token;              !!!next-token;
# Line 5901  sub _tree_construction_main ($) { Line 6023  sub _tree_construction_main ($) {
6023                     tr => 1, td => 1, th => 1,                     tr => 1, td => 1, th => 1,
6024                    }->{$token->{tag_name}})) {                    }->{$token->{tag_name}})) {
6025            ## TODO: The type below is not good - <select> is replaced by </select>            ## TODO: The type below is not good - <select> is replaced by </select>
6026            !!!parse-error (type => 'not closed:select', token => $token);            !!!parse-error (type => 'not closed', text => 'select',
6027                              token => $token);
6028            ## NOTE: As if the token were </select> (<select> case) or            ## NOTE: As if the token were </select> (<select> case) or
6029            ## as if there were </select> (otherwise).            ## as if there were </select> (otherwise).
6030            ## have an element in table scope            ## have an element in table scope
# Line 5919  sub _tree_construction_main ($) { Line 6042  sub _tree_construction_main ($) {
6042            } # INSCOPE            } # INSCOPE
6043            unless (defined $i) {            unless (defined $i) {
6044              !!!cp ('t280');              !!!cp ('t280');
6045              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6046                                text => 'select', token => $token);
6047              ## Ignore the token              ## Ignore the token
6048              !!!nack ('t280.1');              !!!nack ('t280.1');
6049              !!!next-token;              !!!next-token;
# Line 5943  sub _tree_construction_main ($) { Line 6067  sub _tree_construction_main ($) {
6067            }            }
6068          } else {          } else {
6069            !!!cp ('t282');            !!!cp ('t282');
6070            !!!parse-error (type => 'in select:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select',
6071                              text => $token->{tag_name}, token => $token);
6072            ## Ignore the token            ## Ignore the token
6073            !!!nack ('t282.1');            !!!nack ('t282.1');
6074            !!!next-token;            !!!next-token;
# Line 5961  sub _tree_construction_main ($) { Line 6086  sub _tree_construction_main ($) {
6086              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6087            } else {            } else {
6088              !!!cp ('t285');              !!!cp ('t285');
6089              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6090                                text => $token->{tag_name}, token => $token);
6091              ## Ignore the token              ## Ignore the token
6092            }            }
6093            !!!nack ('t285.1');            !!!nack ('t285.1');
# Line 5973  sub _tree_construction_main ($) { Line 6099  sub _tree_construction_main ($) {
6099              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6100            } else {            } else {
6101              !!!cp ('t287');              !!!cp ('t287');
6102              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6103                                text => $token->{tag_name}, token => $token);
6104              ## Ignore the token              ## Ignore the token
6105            }            }
6106            !!!nack ('t287.1');            !!!nack ('t287.1');
# Line 5995  sub _tree_construction_main ($) { Line 6122  sub _tree_construction_main ($) {
6122            } # INSCOPE            } # INSCOPE
6123            unless (defined $i) {            unless (defined $i) {
6124              !!!cp ('t290');              !!!cp ('t290');
6125              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6126                                text => $token->{tag_name}, token => $token);
6127              ## Ignore the token              ## Ignore the token
6128              !!!nack ('t290.1');              !!!nack ('t290.1');
6129              !!!next-token;              !!!next-token;
# Line 6016  sub _tree_construction_main ($) { Line 6144  sub _tree_construction_main ($) {
6144                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
6145                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
6146  ## TODO: The following is wrong?  ## TODO: The following is wrong?
6147            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
6148                              text => $token->{tag_name}, token => $token);
6149                                
6150            ## have an element in table scope            ## have an element in table scope
6151            my $i;            my $i;
# Line 6057  sub _tree_construction_main ($) { Line 6186  sub _tree_construction_main ($) {
6186            unless (defined $i) {            unless (defined $i) {
6187              !!!cp ('t297');              !!!cp ('t297');
6188  ## TODO: The following error type is correct?  ## TODO: The following error type is correct?
6189              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6190                                text => 'select', token => $token);
6191              ## Ignore the </select> token              ## Ignore the </select> token
6192              !!!nack ('t297.1');              !!!nack ('t297.1');
6193              !!!next-token; ## TODO: ok?              !!!next-token; ## TODO: ok?
# Line 6074  sub _tree_construction_main ($) { Line 6204  sub _tree_construction_main ($) {
6204            next B;            next B;
6205          } else {          } else {
6206            !!!cp ('t299');            !!!cp ('t299');
6207            !!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select:/',
6208                              text => $token->{tag_name}, token => $token);
6209            ## Ignore the token            ## Ignore the token
6210            !!!nack ('t299.3');            !!!nack ('t299.3');
6211            !!!next-token;            !!!next-token;
# Line 6112  sub _tree_construction_main ($) { Line 6243  sub _tree_construction_main ($) {
6243                    
6244          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6245            !!!cp ('t301');            !!!cp ('t301');
6246            !!!parse-error (type => 'after html:#character', token => $token);            !!!parse-error (type => 'after html:#text', token => $token);
6247    
6248            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6249          } else {          } else {
# Line 6120  sub _tree_construction_main ($) { Line 6251  sub _tree_construction_main ($) {
6251          }          }
6252                    
6253          ## "after body" insertion mode          ## "after body" insertion mode
6254          !!!parse-error (type => 'after body:#character', token => $token);          !!!parse-error (type => 'after body:#text', token => $token);
6255    
6256          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6257          ## reprocess          ## reprocess
# Line 6128  sub _tree_construction_main ($) { Line 6259  sub _tree_construction_main ($) {
6259        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
6260          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6261            !!!cp ('t303');            !!!cp ('t303');
6262            !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html',
6263                              text => $token->{tag_name}, token => $token);
6264                        
6265            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6266          } else {          } else {
# Line 6136  sub _tree_construction_main ($) { Line 6268  sub _tree_construction_main ($) {
6268          }          }
6269    
6270          ## "after body" insertion mode          ## "after body" insertion mode
6271          !!!parse-error (type => 'after body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'after body',
6272                            text => $token->{tag_name}, token => $token);
6273    
6274          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6275          !!!ack-later;          !!!ack-later;
# Line 6145  sub _tree_construction_main ($) { Line 6278  sub _tree_construction_main ($) {
6278        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6279          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6280            !!!cp ('t305');            !!!cp ('t305');
6281            !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html:/',
6282                              text => $token->{tag_name}, token => $token);
6283                        
6284            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6285            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
# Line 6157  sub _tree_construction_main ($) { Line 6291  sub _tree_construction_main ($) {
6291          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
6292            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
6293              !!!cp ('t307');              !!!cp ('t307');
6294              !!!parse-error (type => 'unmatched end tag:html', token => $token);              !!!parse-error (type => 'unmatched end tag',
6295                                text => 'html', token => $token);
6296              ## Ignore the token              ## Ignore the token
6297              !!!next-token;              !!!next-token;
6298              next B;              next B;
# Line 6169  sub _tree_construction_main ($) { Line 6304  sub _tree_construction_main ($) {
6304            }            }
6305          } else {          } else {
6306            !!!cp ('t309');            !!!cp ('t309');
6307            !!!parse-error (type => 'after body:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after body:/',
6308                              text => $token->{tag_name}, token => $token);
6309    
6310            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
6311            ## reprocess            ## reprocess
# Line 6197  sub _tree_construction_main ($) { Line 6333  sub _tree_construction_main ($) {
6333          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
6334            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6335              !!!cp ('t311');              !!!cp ('t311');
6336              !!!parse-error (type => 'in frameset:#character', token => $token);              !!!parse-error (type => 'in frameset:#text', token => $token);
6337            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6338              !!!cp ('t312');              !!!cp ('t312');
6339              !!!parse-error (type => 'after frameset:#character', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6340            } else { # "after html frameset"            } else { # "after after frameset"
6341              !!!cp ('t313');              !!!cp ('t313');
6342              !!!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);  
6343            }            }
6344                        
6345            ## Ignore the token.            ## Ignore the token.
# Line 6223  sub _tree_construction_main ($) { Line 6355  sub _tree_construction_main ($) {
6355                    
6356          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
6357        } 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');  
         }  
   
6358          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6359              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6360            !!!cp ('t318');            !!!cp ('t318');
# Line 6253  sub _tree_construction_main ($) { Line 6375  sub _tree_construction_main ($) {
6375            ## NOTE: As if in head.            ## NOTE: As if in head.
6376            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
6377            next B;            next B;
6378    
6379              ## NOTE: |<!DOCTYPE HTML><frameset></frameset></html><noframes></noframes>|
6380              ## has no parse error.
6381          } else {          } else {
6382            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6383              !!!cp ('t321');              !!!cp ('t321');
6384              !!!parse-error (type => 'in frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset',
6385            } else {                              text => $token->{tag_name}, token => $token);
6386              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6387              !!!cp ('t322');              !!!cp ('t322');
6388              !!!parse-error (type => 'after frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after frameset',
6389                                text => $token->{tag_name}, token => $token);
6390              } else { # "after after frameset"
6391                !!!cp ('t322.2');
6392                !!!parse-error (type => 'after after frameset',
6393                                text => $token->{tag_name}, token => $token);
6394            }            }
6395            ## Ignore the token            ## Ignore the token
6396            !!!nack ('t322.1');            !!!nack ('t322.1');
# Line 6267  sub _tree_construction_main ($) { Line 6398  sub _tree_construction_main ($) {
6398            next B;            next B;
6399          }          }
6400        } 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');  
         }  
   
6401          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6402              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6403            if ($self->{open_elements}->[-1]->[1] & HTML_EL and            if ($self->{open_elements}->[-1]->[1] & HTML_EL and
6404                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
6405              !!!cp ('t325');              !!!cp ('t325');
6406              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6407                                text => $token->{tag_name}, token => $token);
6408              ## Ignore the token              ## Ignore the token
6409              !!!next-token;              !!!next-token;
6410            } else {            } else {
# Line 6308  sub _tree_construction_main ($) { Line 6430  sub _tree_construction_main ($) {
6430          } else {          } else {
6431            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6432              !!!cp ('t330');              !!!cp ('t330');
6433              !!!parse-error (type => 'in frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset:/',
6434            } else {                              text => $token->{tag_name}, token => $token);
6435              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6436                !!!cp ('t330.1');
6437                !!!parse-error (type => 'after frameset:/',
6438                                text => $token->{tag_name}, token => $token);
6439              } else { # "after after html"
6440              !!!cp ('t331');              !!!cp ('t331');
6441              !!!parse-error (type => 'after frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after after frameset:/',
6442                                text => $token->{tag_name}, token => $token);
6443            }            }
6444            ## Ignore the token            ## Ignore the token
6445            !!!next-token;            !!!next-token;
# Line 6419  sub _tree_construction_main ($) { Line 6547  sub _tree_construction_main ($) {
6547          $parse_rcdata->(RCDATA_CONTENT_MODEL);          $parse_rcdata->(RCDATA_CONTENT_MODEL);
6548          next B;          next B;
6549        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
6550          !!!parse-error (type => 'in body:body', token => $token);          !!!parse-error (type => 'in body', text => 'body', token => $token);
6551                                
6552          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
6553              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {
# Line 6539  sub _tree_construction_main ($) { Line 6667  sub _tree_construction_main ($) {
6667              if ($i != -1) {              if ($i != -1) {
6668                !!!cp ('t355');                !!!cp ('t355');
6669                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
6670                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
6671                                    ->manakai_local_name,                                    ->manakai_local_name,
6672                                token => $token);                                token => $token);
6673              } else {              } else {
# Line 6807  sub _tree_construction_main ($) { Line 6935  sub _tree_construction_main ($) {
6935            ## Ignore the token            ## Ignore the token
6936          } else {          } else {
6937            !!!cp ('t398');            !!!cp ('t398');
6938            !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);            !!!parse-error (type => 'in RCDATA:#eof', token => $token);
6939          }          }
6940          !!!next-token;          !!!next-token;
6941          next B;          next B;
# Line 6826  sub _tree_construction_main ($) { Line 6954  sub _tree_construction_main ($) {
6954              unless ($self->{open_elements}->[-1]->[1] & RUBY_EL) {              unless ($self->{open_elements}->[-1]->[1] & RUBY_EL) {
6955                !!!cp ('t398.3');                !!!cp ('t398.3');
6956                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
6957                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
6958                                    ->manakai_local_name,                                    ->manakai_local_name,
6959                                token => $token);                                token => $token);
6960                pop @{$self->{open_elements}}                pop @{$self->{open_elements}}
# Line 6848  sub _tree_construction_main ($) { Line 6976  sub _tree_construction_main ($) {
6976                 $token->{tag_name} eq 'svg') {                 $token->{tag_name} eq 'svg') {
6977          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
6978    
6979            ## "Adjust MathML attributes" ('math' only) - done in insert-element-f
6980    
6981          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f
6982    
6983          ## "adjust foreign attributes" - done in insert-element-f          ## "adjust foreign attributes" - done in insert-element-f
# Line 6874  sub _tree_construction_main ($) { Line 7004  sub _tree_construction_main ($) {
7004                  thead => 1, tr => 1,                  thead => 1, tr => 1,
7005                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7006          !!!cp ('t401');          !!!cp ('t401');
7007          !!!parse-error (type => 'in body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in body',
7008                            text => $token->{tag_name}, token => $token);
7009          ## Ignore the token          ## Ignore the token
7010          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.
7011          !!!next-token;          !!!next-token;
# Line 6959  sub _tree_construction_main ($) { Line 7090  sub _tree_construction_main ($) {
7090            }            }
7091    
7092            !!!parse-error (type => 'start tag not allowed',            !!!parse-error (type => 'start tag not allowed',
7093                            value => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7094            ## NOTE: Ignore the token.            ## NOTE: Ignore the token.
7095            !!!next-token;            !!!next-token;
7096            next B;            next B;
# Line 6969  sub _tree_construction_main ($) { Line 7100  sub _tree_construction_main ($) {
7100            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {
7101              !!!cp ('t403');              !!!cp ('t403');
7102              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7103                              value => $_->[0]->manakai_local_name,                              text => $_->[0]->manakai_local_name,
7104                              token => $token);                              token => $token);
7105              last;              last;
7106            } else {            } else {
# Line 6989  sub _tree_construction_main ($) { Line 7120  sub _tree_construction_main ($) {
7120            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {
7121              !!!cp ('t406');              !!!cp ('t406');
7122              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7123                              value => $self->{open_elements}->[1]->[0]                              text => $self->{open_elements}->[1]->[0]
7124                                  ->manakai_local_name,                                  ->manakai_local_name,
7125                              token => $token);                              token => $token);
7126            } else {            } else {
# Line 7000  sub _tree_construction_main ($) { Line 7131  sub _tree_construction_main ($) {
7131            next B;            next B;
7132          } else {          } else {
7133            !!!cp ('t408');            !!!cp ('t408');
7134            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7135                              text => $token->{tag_name}, token => $token);
7136            ## Ignore the token            ## Ignore the token
7137            !!!next-token;            !!!next-token;
7138            next B;            next B;
# Line 7028  sub _tree_construction_main ($) { Line 7160  sub _tree_construction_main ($) {
7160    
7161          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7162            !!!cp ('t413');            !!!cp ('t413');
7163            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7164                              text => $token->{tag_name}, token => $token);
7165              ## NOTE: Ignore the token.
7166          } else {          } else {
7167            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7168            while ({            while ({
# Line 7049  sub _tree_construction_main ($) { Line 7183  sub _tree_construction_main ($) {
7183                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7184              !!!cp ('t412');              !!!cp ('t412');
7185              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7186                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7187                                  ->manakai_local_name,                                  ->manakai_local_name,
7188                              token => $token);                              token => $token);
7189            } else {            } else {
# Line 7086  sub _tree_construction_main ($) { Line 7220  sub _tree_construction_main ($) {
7220    
7221          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7222            !!!cp ('t421');            !!!cp ('t421');
7223            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7224                              text => $token->{tag_name}, token => $token);
7225              ## NOTE: Ignore the token.
7226          } else {          } else {
7227            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7228            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7099  sub _tree_construction_main ($) { Line 7235  sub _tree_construction_main ($) {
7235                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7236              !!!cp ('t417.1');              !!!cp ('t417.1');
7237              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7238                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7239                                  ->manakai_local_name,                                  ->manakai_local_name,
7240                              token => $token);                              token => $token);
7241            } else {            } else {
# Line 7131  sub _tree_construction_main ($) { Line 7267  sub _tree_construction_main ($) {
7267    
7268          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7269            !!!cp ('t425.1');            !!!cp ('t425.1');
7270            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7271                              text => $token->{tag_name}, token => $token);
7272              ## NOTE: Ignore the token.
7273          } else {          } else {
7274            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7275            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7143  sub _tree_construction_main ($) { Line 7281  sub _tree_construction_main ($) {
7281            if ($self->{open_elements}->[-1]->[0]->manakai_local_name            if ($self->{open_elements}->[-1]->[0]->manakai_local_name
7282                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7283              !!!cp ('t425');              !!!cp ('t425');
7284              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
7285                                text => $token->{tag_name}, token => $token);
7286            } else {            } else {
7287              !!!cp ('t426');              !!!cp ('t426');
7288            }            }
# Line 7174  sub _tree_construction_main ($) { Line 7313  sub _tree_construction_main ($) {
7313                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7314              !!!cp ('t412.1');              !!!cp ('t412.1');
7315              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7316                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7317                                  ->manakai_local_name,                                  ->manakai_local_name,
7318                              token => $token);                              token => $token);
7319            } else {            } else {
# Line 7184  sub _tree_construction_main ($) { Line 7323  sub _tree_construction_main ($) {
7323            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
7324          } else {          } else {
7325            !!!cp ('t413.1');            !!!cp ('t413.1');
7326            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7327                              text => $token->{tag_name}, token => $token);
7328    
7329            !!!cp ('t415.1');            !!!cp ('t415.1');
7330            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
# Line 7207  sub _tree_construction_main ($) { Line 7347  sub _tree_construction_main ($) {
7347          next B;          next B;
7348        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
7349          !!!cp ('t428');          !!!cp ('t428');
7350          !!!parse-error (type => 'unmatched end tag:br', token => $token);          !!!parse-error (type => 'unmatched end tag',
7351                            text => 'br', token => $token);
7352    
7353          ## As if <br>          ## As if <br>
7354          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
# Line 7232  sub _tree_construction_main ($) { Line 7373  sub _tree_construction_main ($) {
7373                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
7374                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7375          !!!cp ('t429');          !!!cp ('t429');
7376          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'unmatched end tag',
7377                            text => $token->{tag_name}, token => $token);
7378          ## Ignore the token          ## Ignore the token
7379          !!!next-token;          !!!next-token;
7380          next B;          next B;
# Line 7264  sub _tree_construction_main ($) { Line 7406  sub _tree_construction_main ($) {
7406                !!!cp ('t431');                !!!cp ('t431');
7407                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
7408                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
7409                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
7410                                    ->manakai_local_name,                                    ->manakai_local_name,
7411                                token => $token);                                token => $token);
7412              } else {              } else {
# Line 7283  sub _tree_construction_main ($) { Line 7425  sub _tree_construction_main ($) {
7425                  ($node->[1] & SPECIAL_EL or                  ($node->[1] & SPECIAL_EL or
7426                   $node->[1] & SCOPING_EL)) {                   $node->[1] & SCOPING_EL)) {
7427                !!!cp ('t433');                !!!cp ('t433');
7428                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
7429                                  text => $token->{tag_name}, token => $token);
7430                ## Ignore the token                ## Ignore the token
7431                !!!next-token;                !!!next-token;
7432                last S2;                last S2;
# Line 7329  sub _tree_construction_main ($) { Line 7472  sub _tree_construction_main ($) {
7472    ## TODO: script stuffs    ## TODO: script stuffs
7473  } # _tree_construct_main  } # _tree_construct_main
7474    
7475  sub set_inner_html ($$$) {  sub set_inner_html ($$$;$) {
7476    my $class = shift;    my $class = shift;
7477    my $node = shift;    my $node = shift;
7478    my $s = \$_[0];    my $s = \$_[0];
7479    my $onerror = $_[1];    my $onerror = $_[1];
7480      my $get_wrapper = $_[2] || sub ($) { return $_[0] };
7481    
7482    ## ISSUE: Should {confident} be true?    ## ISSUE: Should {confident} be true?
7483    
# Line 7352  sub set_inner_html ($$$) { Line 7496  sub set_inner_html ($$$) {
7496      }      }
7497    
7498      ## Step 3, 4, 5 # MUST      ## Step 3, 4, 5 # MUST
7499      $class->parse_string ($$s => $node, $onerror);      $class->parse_char_string ($$s => $node, $onerror, $get_wrapper);
7500    } elsif ($nt == 1) {    } elsif ($nt == 1) {
7501      ## TODO: If non-html element      ## TODO: If non-html element
7502    
7503      ## NOTE: Most of this code is copied from |parse_string|      ## NOTE: Most of this code is copied from |parse_string|
7504    
7505    ## TODO: Support for $get_wrapper
7506    
7507      ## Step 1 # MUST      ## Step 1 # MUST
7508      my $this_doc = $node->owner_document;      my $this_doc = $node->owner_document;
7509      my $doc = $this_doc->implementation->create_document;      my $doc = $this_doc->implementation->create_document;
# Line 7419  sub set_inner_html ($$$) { Line 7565  sub set_inner_html ($$$) {
7565                  0x10FFFE => 1, 0x10FFFF => 1,                  0x10FFFE => 1, 0x10FFFF => 1,
7566                 }->{$self->{next_char}}) {                 }->{$self->{next_char}}) {
7567          !!!cp ('i4.1');          !!!cp ('i4.1');
7568          !!!parse-error (type => 'control char', level => $self->{must_level});          if ($self->{next_char} < 0x10000) {
7569  ## TODO: error type documentation            !!!parse-error (type => 'control char',
7570                              text => (sprintf 'U+%04X', $self->{next_char}));
7571            } else {
7572              !!!parse-error (type => 'control char',
7573                              text => (sprintf 'U-%08X', $self->{next_char}));
7574            }
7575        }        }
7576      };      };
7577      $p->{prev_char} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];

Legend:
Removed from v.1.151  
changed lines
  Added in v.1.162

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24