/[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.146 by wakaba, Sat May 24 14:19:55 2008 UTC revision 1.174 by wakaba, Sun Sep 14 06:32:49 2008 UTC
# Line 45  sub MISC_SPECIAL_EL () { 0b1000000000000 Line 45  sub MISC_SPECIAL_EL () { 0b1000000000000
45  sub FOREIGN_EL () { 0b10000000000000000000000000 }  sub FOREIGN_EL () { 0b10000000000000000000000000 }
46  sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 }  sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 }
47  sub MML_AXML_EL () { 0b1000000000000000000000000000 }  sub MML_AXML_EL () { 0b1000000000000000000000000000 }
48    sub RUBY_EL () { 0b10000000000000000000000000000 }
49    sub RUBY_COMPONENT_EL () { 0b100000000000000000000000000000 }
50    
51  sub TABLE_ROWS_EL () {  sub TABLE_ROWS_EL () {
52    TABLE_EL |    TABLE_EL |
# Line 52  sub TABLE_ROWS_EL () { Line 54  sub TABLE_ROWS_EL () {
54    TABLE_ROW_GROUP_EL    TABLE_ROW_GROUP_EL
55  }  }
56    
57    ## NOTE: Used in "generate implied end tags" algorithm.
58    ## NOTE: There is a code where a modified version of END_TAG_OPTIONAL_EL
59    ## is used in "generate implied end tags" implementation (search for the
60    ## function mae).
61  sub END_TAG_OPTIONAL_EL () {  sub END_TAG_OPTIONAL_EL () {
62    DD_EL |    DD_EL |
63    DT_EL |    DT_EL |
64    LI_EL |    LI_EL |
65    P_EL    P_EL |
66      RUBY_COMPONENT_EL
67  }  }
68    
69    ## NOTE: Used in </body> and EOF algorithms.
70  sub ALL_END_TAG_OPTIONAL_EL () {  sub ALL_END_TAG_OPTIONAL_EL () {
71    END_TAG_OPTIONAL_EL |    DD_EL |
72      DT_EL |
73      LI_EL |
74      P_EL |
75    
76    BODY_EL |    BODY_EL |
77    HTML_EL |    HTML_EL |
78    TABLE_CELL_EL |    TABLE_CELL_EL |
# Line 96  sub SPECIAL_EL () { Line 108  sub SPECIAL_EL () {
108    ADDRESS_EL |    ADDRESS_EL |
109    BODY_EL |    BODY_EL |
110    DIV_EL |    DIV_EL |
111    END_TAG_OPTIONAL_EL |  
112      DD_EL |
113      DT_EL |
114      LI_EL |
115      P_EL |
116    
117    FORM_EL |    FORM_EL |
118    FRAMESET_EL |    FRAMESET_EL |
119    HEADING_EL |    HEADING_EL |
# Line 170  my $el_category = { Line 187  my $el_category = {
187    param => MISC_SPECIAL_EL,    param => MISC_SPECIAL_EL,
188    plaintext => MISC_SPECIAL_EL,    plaintext => MISC_SPECIAL_EL,
189    pre => MISC_SPECIAL_EL,    pre => MISC_SPECIAL_EL,
190      rp => RUBY_COMPONENT_EL,
191      rt => RUBY_COMPONENT_EL,
192      ruby => RUBY_EL,
193    s => FORMATTING_EL,    s => FORMATTING_EL,
194    script => MISC_SPECIAL_EL,    script => MISC_SPECIAL_EL,
195    select => SELECT_EL,    select => SELECT_EL,
# Line 334  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 345  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 352  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 379  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 412  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 423  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 434  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 446  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 472  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 481  sub parse_byte_stream ($$$$;$) { Line 521  sub parse_byte_stream ($$$$;$) {
521        ## "Change the encoding" algorithm:        ## "Change the encoding" algorithm:
522    
523        ## Step 1            ## Step 1    
524        if ($charset->{iana_names}->{'utf-16'}) { ## ISSUE: UTF-16BE -> UTF-8? UTF-16LE -> UTF-8?        if ($charset->{category} &
525          $charset = Message::Charset::Info->get_by_iana_name ('utf-8');            Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) {
526            $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 492  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 516  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                      line => $self->{line}, column => $self->{column} + 1);                      line => $self->{line}, column => $self->{column} + 1,
565                        %opt, type => $type);
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 560  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;
   require utf8;  
621    my $s = ref $_[0] ? $_[0] : \($_[0]);    my $s = ref $_[0] ? $_[0] : \($_[0]);
622    open my $input, '<' . (utf8::is_utf8 ($$s) ? ':utf8' : ''), $s;    require Whatpm::Charset::DecodeHandle;
623      my $input = Whatpm::Charset::DecodeHandle::CharString->new ($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 610  sub parse_char_stream ($$$;$) { Line 669  sub parse_char_stream ($$$;$) {
669        $self->{column} = 0;        $self->{column} = 0;
670      } elsif ($self->{next_char} == 0x000D) { # CR      } elsif ($self->{next_char} == 0x000D) { # CR
671        !!!cp ('j2');        !!!cp ('j2');
672    ## TODO: support for abort/streaming
673        my $next = $input->getc;        my $next = $input->getc;
674        if (defined $next and $next ne "\x0A") {        if (defined $next and $next ne "\x0A") {
675          $self->{next_next_char} = $next;          $self->{next_next_char} = $next;
# Line 629  sub parse_char_stream ($$$;$) { Line 689  sub parse_char_stream ($$$;$) {
689               (0x007F <= $self->{next_char} and $self->{next_char} <= 0x009F) or               (0x007F <= $self->{next_char} and $self->{next_char} <= 0x009F) or
690               (0xD800 <= $self->{next_char} and $self->{next_char} <= 0xDFFF) or               (0xD800 <= $self->{next_char} and $self->{next_char} <= 0xDFFF) or
691               (0xFDD0 <= $self->{next_char} and $self->{next_char} <= 0xFDDF) or               (0xFDD0 <= $self->{next_char} and $self->{next_char} <= 0xFDDF) or
692    ## ISSUE: U+FDE0-U+FDEF are not excluded
693               {               {
694                0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,                0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,
695                0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,                0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,
# Line 641  sub parse_char_stream ($$$;$) { Line 702  sub parse_char_stream ($$$;$) {
702                0x10FFFE => 1, 0x10FFFF => 1,                0x10FFFE => 1, 0x10FFFF => 1,
703               }->{$self->{next_char}}) {               }->{$self->{next_char}}) {
704        !!!cp ('j5');        !!!cp ('j5');
705        !!!parse-error (type => 'control char', level => $self->{must_level});        if ($self->{next_char} < 0x10000) {
706  ## TODO: error type documentation          !!!parse-error (type => 'control char',
707                            text => (sprintf 'U+%04X', $self->{next_char}));
708          } else {
709            !!!parse-error (type => 'control char',
710                            text => (sprintf 'U-%08X', $self->{next_char}));
711          }
712      }      }
713    };    };
714    $self->{prev_char} = [-1, -1, -1];    $self->{prev_char} = [-1, -1, -1];
715    $self->{next_char} = -1;    $self->{next_char} = -1;
716    
717      $self->{read_until} = sub {
718        #my ($scalar, $specials_range, $offset) = @_;
719        my $specials_range = $_[1];
720        return 0 if defined $self->{next_next_char};
721        my $count = $input->manakai_read_until
722           ($_[0],
723            qr/(?![$specials_range\x{FDD0}-\x{FDDF}\x{FFFD}-\x{FFFF}\x{1FFFE}\x{1FFFF}\x{2FFFE}\x{2FFFF}\x{3FFFE}\x{3FFFF}\x{4FFFE}\x{4FFFF}\x{5FFFE}\x{5FFFF}\x{6FFFE}\x{6FFFF}\x{7FFFE}\x{7FFFF}\x{8FFFE}\x{8FFFF}\x{9FFFE}\x{9FFFF}\x{AFFFE}\x{AFFFF}\x{BFFFE}\x{BFFFF}\x{CFFFE}\x{CFFFF}\x{DFFFE}\x{DFFFF}\x{EFFFE}\x{EFFFF}\x{FFFFE}\x{FFFFF}])[\x20-\x7E\xA0-\x{D7FF}\x{E000}-\x{10FFFD}]/,
724            $_[2]);
725            ## NOTE: We need to exclude U+FFFD, otherwise reported line/column
726            ## of unassigned/illegal code point error would be wrong.
727        if ($count) {
728          $self->{column} += $count;
729          $self->{column_prev} += $count;
730          $self->{prev_char} = [-1, -1, -1];
731          $self->{next_char} = -1;
732        }
733        return $count;
734      }; # $self->{read_until}
735    
736    my $onerror = $_[2] || sub {    my $onerror = $_[2] || sub {
737      my (%opt) = @_;      my (%opt) = @_;
738      my $line = $opt{token} ? $opt{token}->{line} : $opt{line};      my $line = $opt{token} ? $opt{token}->{line} : $opt{line};
# Line 671  sub parse_char_stream ($$$;$) { Line 756  sub parse_char_stream ($$$;$) {
756  sub new ($) {  sub new ($) {
757    my $class = shift;    my $class = shift;
758    my $self = bless {    my $self = bless {
759      must_level => 'm',      level => {must => 'm',
760      should_level => 's',                should => 's',
761      good_level => 'w',                warn => 'w',
762      warn_level => 'w',                info => 'i',
763      info_level => 'i',                uncertain => 'u'},
     unsupported_level => 'u',  
764    }, $class;    }, $class;
765    $self->{set_next_char} = sub {    $self->{set_next_char} = sub {
766      $self->{next_char} = -1;      $self->{next_char} = -1;
# Line 706  sub RCDATA_CONTENT_MODEL () { CM_ENTITY Line 790  sub RCDATA_CONTENT_MODEL () { CM_ENTITY
790  sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }  sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }
791    
792  sub DATA_STATE () { 0 }  sub DATA_STATE () { 0 }
793  sub ENTITY_DATA_STATE () { 1 }  #sub ENTITY_DATA_STATE () { 1 }
794  sub TAG_OPEN_STATE () { 2 }  sub TAG_OPEN_STATE () { 2 }
795  sub CLOSE_TAG_OPEN_STATE () { 3 }  sub CLOSE_TAG_OPEN_STATE () { 3 }
796  sub TAG_NAME_STATE () { 4 }  sub TAG_NAME_STATE () { 4 }
# Line 717  sub BEFORE_ATTRIBUTE_VALUE_STATE () { 8 Line 801  sub BEFORE_ATTRIBUTE_VALUE_STATE () { 8
801  sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 }  sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 }
802  sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 }  sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 }
803  sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 }  sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 }
804  sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 }  #sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 }
805  sub MARKUP_DECLARATION_OPEN_STATE () { 13 }  sub MARKUP_DECLARATION_OPEN_STATE () { 13 }
806  sub COMMENT_START_STATE () { 14 }  sub COMMENT_START_STATE () { 14 }
807  sub COMMENT_START_DASH_STATE () { 15 }  sub COMMENT_START_DASH_STATE () { 15 }
# Line 740  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STAT Line 824  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STAT
824  sub BOGUS_DOCTYPE_STATE () { 32 }  sub BOGUS_DOCTYPE_STATE () { 32 }
825  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }
826  sub SELF_CLOSING_START_TAG_STATE () { 34 }  sub SELF_CLOSING_START_TAG_STATE () { 34 }
827  sub CDATA_BLOCK_STATE () { 35 }  sub CDATA_SECTION_STATE () { 35 }
828    sub MD_HYPHEN_STATE () { 36 } # "markup declaration open state" in the spec
829    sub MD_DOCTYPE_STATE () { 37 } # "markup declaration open state" in the spec
830    sub MD_CDATA_STATE () { 38 } # "markup declaration open state" in the spec
831    sub CDATA_PCDATA_CLOSE_TAG_STATE () { 39 } # "close tag open state" in the spec
832    sub CDATA_SECTION_MSE1_STATE () { 40 } # "CDATA section state" in the spec
833    sub CDATA_SECTION_MSE2_STATE () { 41 } # "CDATA section state" in the spec
834    sub PUBLIC_STATE () { 42 } # "after DOCTYPE name state" in the spec
835    sub SYSTEM_STATE () { 43 } # "after DOCTYPE name state" in the spec
836    ## NOTE: "Entity data state", "entity in attribute value state", and
837    ## "consume a character reference" algorithm are jointly implemented
838    ## using the following six states:
839    sub ENTITY_STATE () { 44 }
840    sub ENTITY_HASH_STATE () { 45 }
841    sub NCR_NUM_STATE () { 46 }
842    sub HEXREF_X_STATE () { 47 }
843    sub HEXREF_HEX_STATE () { 48 }
844    sub ENTITY_NAME_STATE () { 49 }
845    
846  sub DOCTYPE_TOKEN () { 1 }  sub DOCTYPE_TOKEN () { 1 }
847  sub COMMENT_TOKEN () { 2 }  sub COMMENT_TOKEN () { 2 }
# Line 793  sub IN_COLUMN_GROUP_IM () { 0b10 } Line 894  sub IN_COLUMN_GROUP_IM () { 0b10 }
894  sub _initialize_tokenizer ($) {  sub _initialize_tokenizer ($) {
895    my $self = shift;    my $self = shift;
896    $self->{state} = DATA_STATE; # MUST    $self->{state} = DATA_STATE; # MUST
897      #$self->{state_keyword}; # initialized when used
898      #$self->{entity__value}; # initialized when used
899      #$self->{entity__match}; # initialized when used
900    $self->{content_model} = PCDATA_CONTENT_MODEL; # be    $self->{content_model} = PCDATA_CONTENT_MODEL; # be
901    undef $self->{current_token}; # start tag, end tag, comment, or DOCTYPE    undef $self->{current_token};
902    undef $self->{current_attribute};    undef $self->{current_attribute};
903    undef $self->{last_emitted_start_tag_name};    undef $self->{last_emitted_start_tag_name};
904    undef $self->{last_attribute_value_state};    #$self->{prev_state}; # initialized when used
905    delete $self->{self_closing};    delete $self->{self_closing};
   $self->{char} = [];  
906    # $self->{next_char}    # $self->{next_char}
907    !!!next-input-character;    !!!next-input-character;
908    $self->{token} = [];    $self->{token} = [];
# Line 823  sub _initialize_tokenizer ($) { Line 926  sub _initialize_tokenizer ($) {
926  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|
927  ##     while the token is pushed back to the stack.  ##     while the token is pushed back to the stack.
928    
 ## ISSUE: "When a DOCTYPE token is created, its  
 ## <i>self-closing flag</i> must be unset (its other state is that it  
 ## be set), and its attributes list must be empty.": Wrong subject?  
   
929  ## Emitted token MUST immediately be handled by the tree construction state.  ## Emitted token MUST immediately be handled by the tree construction state.
930    
931  ## Before each step, UA MAY check to see if either one of the scripts in  ## Before each step, UA MAY check to see if either one of the scripts in
# Line 835  sub _initialize_tokenizer ($) { Line 934  sub _initialize_tokenizer ($) {
934  ## has completed loading.  If one has, then it MUST be executed  ## has completed loading.  If one has, then it MUST be executed
935  ## and removed from the list.  ## and removed from the list.
936    
937  ## NOTE: HTML5 "Writing HTML documents" section, applied to  ## TODO: Polytheistic slash SHOULD NOT be used. (Applied only to atheists.)
938  ## documents and not to user agents and conformance checkers,  ## (This requirement was dropped from HTML5 spec, unfortunately.)
 ## contains some requirements that are not detected by the  
 ## parsing algorithm:  
 ## - Some requirements on character encoding declarations. ## TODO  
 ## - "Elements MUST NOT contain content that their content model disallows."  
 ##   ... Some are parse error, some are not (will be reported by c.c.).  
 ## - Polytheistic slash SHOULD NOT be used. (Applied only to atheists.) ## TODO  
 ## - Text (in elements, attributes, and comments) SHOULD NOT contain  
 ##   control characters other than space characters. ## TODO: (what is control character? C0, C1 and DEL?  Unicode control character?)  
   
 ## TODO: HTML5 poses authors two SHOULD-level requirements that cannot  
 ## be detected by the HTML5 parsing algorithm:  
 ## - Text,  
939    
940  sub _get_next_token ($) {  sub _get_next_token ($) {
941    my $self = shift;    my $self = shift;
# Line 872  sub _get_next_token ($) { Line 959  sub _get_next_token ($) {
959          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA
960              not $self->{escape}) {              not $self->{escape}) {
961            !!!cp (1);            !!!cp (1);
962            $self->{state} = ENTITY_DATA_STATE;            ## NOTE: In the spec, the tokenizer is switched to the
963              ## "entity data state".  In this implementation, the tokenizer
964              ## is switched to the |ENTITY_STATE|, which is an implementation
965              ## of the "consume a character reference" algorithm.
966              $self->{entity_additional} = -1;
967              $self->{prev_state} = DATA_STATE;
968              $self->{state} = ENTITY_STATE;
969            !!!next-input-character;            !!!next-input-character;
970            redo A;            redo A;
971          } else {          } else {
# Line 936  sub _get_next_token ($) { Line 1029  sub _get_next_token ($) {
1029                     data => chr $self->{next_char},                     data => chr $self->{next_char},
1030                     line => $self->{line}, column => $self->{column},                     line => $self->{line}, column => $self->{column},
1031                    };                    };
1032          $self->{read_until}->($token->{data}, q[-!<>&], length $token->{data});
1033    
1034        ## Stay in the data state        ## Stay in the data state
1035        !!!next-input-character;        !!!next-input-character;
1036    
1037        !!!emit ($token);        !!!emit ($token);
1038    
1039        redo A;        redo A;
     } elsif ($self->{state} == ENTITY_DATA_STATE) {  
       ## (cannot happen in CDATA state)  
   
       my ($l, $c) = ($self->{line_prev}, $self->{column_prev});  
         
       my $token = $self->_tokenize_attempt_to_consume_an_entity (0, -1);  
   
       $self->{state} = DATA_STATE;  
       # next-input-character is already done  
   
       unless (defined $token) {  
         !!!cp (13);  
         !!!emit ({type => CHARACTER_TOKEN, data => '&',  
                   line => $l, column => $c,  
                  });  
       } else {  
         !!!cp (14);  
         !!!emit ($token);  
       }  
   
       redo A;  
1040      } elsif ($self->{state} == TAG_OPEN_STATE) {      } elsif ($self->{state} == TAG_OPEN_STATE) {
1041        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1042          if ($self->{next_char} == 0x002F) { # /          if ($self->{next_char} == 0x002F) { # /
# Line 1059  sub _get_next_token ($) { Line 1133  sub _get_next_token ($) {
1133          die "$0: $self->{content_model} in tag open";          die "$0: $self->{content_model} in tag open";
1134        }        }
1135      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {
1136          ## NOTE: The "close tag open state" in the spec is implemented as
1137          ## |CLOSE_TAG_OPEN_STATE| and |CDATA_PCDATA_CLOSE_TAG_STATE|.
1138    
1139        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"
1140        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1141          if (defined $self->{last_emitted_start_tag_name}) {          if (defined $self->{last_emitted_start_tag_name}) {
1142              $self->{state} = CDATA_PCDATA_CLOSE_TAG_STATE;
1143            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>            $self->{state_keyword} = '';
1144            my @next_char;            ## Reconsume.
1145            TAGNAME: for (my $i = 0; $i < length $self->{last_emitted_start_tag_name}; $i++) {            redo A;
             push @next_char, $self->{next_char};  
             my $c = ord substr ($self->{last_emitted_start_tag_name}, $i, 1);  
             my $C = 0x0061 <= $c && $c <= 0x007A ? $c - 0x0020 : $c;  
             if ($self->{next_char} == $c or $self->{next_char} == $C) {  
               !!!cp (24);  
               !!!next-input-character;  
               next TAGNAME;  
             } else {  
               !!!cp (25);  
               $self->{next_char} = shift @next_char; # reconsume  
               !!!back-next-input-character (@next_char);  
               $self->{state} = DATA_STATE;  
   
               !!!emit ({type => CHARACTER_TOKEN, data => '</',  
                         line => $l, column => $c,  
                        });  
     
               redo A;  
             }  
           }  
           push @next_char, $self->{next_char};  
         
           unless ($self->{next_char} == 0x0009 or # HT  
                   $self->{next_char} == 0x000A or # LF  
                   $self->{next_char} == 0x000B or # VT  
                   $self->{next_char} == 0x000C or # FF  
                   $self->{next_char} == 0x0020 or # SP  
                   $self->{next_char} == 0x003E or # >  
                   $self->{next_char} == 0x002F or # /  
                   $self->{next_char} == -1) {  
             !!!cp (26);  
             $self->{next_char} = shift @next_char; # reconsume  
             !!!back-next-input-character (@next_char);  
             $self->{state} = DATA_STATE;  
             !!!emit ({type => CHARACTER_TOKEN, data => '</',  
                       line => $l, column => $c,  
                      });  
             redo A;  
           } else {  
             !!!cp (27);  
             $self->{next_char} = shift @next_char;  
             !!!back-next-input-character (@next_char);  
             # and consume...  
           }  
1146          } else {          } else {
1147            ## No start tag token has ever been emitted            ## No start tag token has ever been emitted
1148              ## NOTE: See <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>.
1149            !!!cp (28);            !!!cp (28);
           # next-input-character is already done  
1150            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1151              ## Reconsume.
1152            !!!emit ({type => CHARACTER_TOKEN, data => '</',            !!!emit ({type => CHARACTER_TOKEN, data => '</',
1153                      line => $l, column => $c,                      line => $l, column => $c,
1154                     });                     });
1155            redo A;            redo A;
1156          }          }
1157        }        }
1158          
1159        if (0x0041 <= $self->{next_char} and        if (0x0041 <= $self->{next_char} and
1160            $self->{next_char} <= 0x005A) { # A..Z            $self->{next_char} <= 0x005A) { # A..Z
1161          !!!cp (29);          !!!cp (29);
# Line 1168  sub _get_next_token ($) { Line 1202  sub _get_next_token ($) {
1202                                    line => $self->{line_prev}, # "<" of "</"                                    line => $self->{line_prev}, # "<" of "</"
1203                                    column => $self->{column_prev} - 1,                                    column => $self->{column_prev} - 1,
1204                                   };                                   };
1205          ## $self->{next_char} is intentionally left as is          ## NOTE: $self->{next_char} is intentionally left as is.
1206          redo A;          ## Although the "anything else" case of the spec not explicitly
1207            ## states that the next input character is to be reconsumed,
1208            ## it will be included to the |data| of the comment token
1209            ## generated from the bogus end tag, as defined in the
1210            ## "bogus comment state" entry.
1211            redo A;
1212          }
1213        } elsif ($self->{state} == CDATA_PCDATA_CLOSE_TAG_STATE) {
1214          my $ch = substr $self->{last_emitted_start_tag_name}, length $self->{state_keyword}, 1;
1215          if (length $ch) {
1216            my $CH = $ch;
1217            $ch =~ tr/a-z/A-Z/;
1218            my $nch = chr $self->{next_char};
1219            if ($nch eq $ch or $nch eq $CH) {
1220              !!!cp (24);
1221              ## Stay in the state.
1222              $self->{state_keyword} .= $nch;
1223              !!!next-input-character;
1224              redo A;
1225            } else {
1226              !!!cp (25);
1227              $self->{state} = DATA_STATE;
1228              ## Reconsume.
1229              !!!emit ({type => CHARACTER_TOKEN,
1230                        data => '</' . $self->{state_keyword},
1231                        line => $self->{line_prev},
1232                        column => $self->{column_prev} - 1 - length $self->{state_keyword},
1233                       });
1234              redo A;
1235            }
1236          } else { # after "<{tag-name}"
1237            unless ({
1238                     0x0009 => 1, # HT
1239                     0x000A => 1, # LF
1240                     0x000B => 1, # VT
1241                     0x000C => 1, # FF
1242                     0x0020 => 1, # SP
1243                     0x003E => 1, # >
1244                     0x002F => 1, # /
1245                     -1 => 1, # EOF
1246                    }->{$self->{next_char}}) {
1247              !!!cp (26);
1248              ## Reconsume.
1249              $self->{state} = DATA_STATE;
1250              !!!emit ({type => CHARACTER_TOKEN,
1251                        data => '</' . $self->{state_keyword},
1252                        line => $self->{line_prev},
1253                        column => $self->{column_prev} - 1 - length $self->{state_keyword},
1254                       });
1255              redo A;
1256            } else {
1257              !!!cp (27);
1258              $self->{current_token}
1259                  = {type => END_TAG_TOKEN,
1260                     tag_name => $self->{last_emitted_start_tag_name},
1261                     line => $self->{line_prev},
1262                     column => $self->{column_prev} - 1 - length $self->{state_keyword}};
1263              $self->{state} = TAG_NAME_STATE;
1264              ## Reconsume.
1265              redo A;
1266            }
1267        }        }
1268      } elsif ($self->{state} == TAG_NAME_STATE) {      } elsif ($self->{state} == TAG_NAME_STATE) {
1269        if ($self->{next_char} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
# Line 1339  sub _get_next_token ($) { Line 1433  sub _get_next_token ($) {
1433          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
1434              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
1435            !!!cp (57);            !!!cp (57);
1436            !!!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});
1437            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{current_attribute} # MUST
1438          } else {          } else {
1439            !!!cp (58);            !!!cp (58);
# Line 1510  sub _get_next_token ($) { Line 1604  sub _get_next_token ($) {
1604    
1605          redo A;          redo A;
1606        } else {        } else {
1607          !!!cp (82);          if ($self->{next_char} == 0x0022 or # "
1608                $self->{next_char} == 0x0027) { # '
1609              !!!cp (78);
1610              !!!parse-error (type => 'bad attribute name');
1611            } else {
1612              !!!cp (82);
1613            }
1614          $self->{current_attribute}          $self->{current_attribute}
1615              = {name => chr ($self->{next_char}),              = {name => chr ($self->{next_char}),
1616                 value => '',                 value => '',
# Line 1545  sub _get_next_token ($) { Line 1645  sub _get_next_token ($) {
1645          !!!next-input-character;          !!!next-input-character;
1646          redo A;          redo A;
1647        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1648            !!!parse-error (type => 'empty unquoted attribute value');
1649          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1650            !!!cp (87);            !!!cp (87);
1651            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
# Line 1609  sub _get_next_token ($) { Line 1710  sub _get_next_token ($) {
1710          redo A;          redo A;
1711        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1712          !!!cp (96);          !!!cp (96);
1713          $self->{last_attribute_value_state} = $self->{state};          ## NOTE: In the spec, the tokenizer is switched to the
1714          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## "entity in attribute value state".  In this implementation, the
1715            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1716            ## implementation of the "consume a character reference" algorithm.
1717            $self->{prev_state} = $self->{state};
1718            $self->{entity_additional} = 0x0022; # "
1719            $self->{state} = ENTITY_STATE;
1720          !!!next-input-character;          !!!next-input-character;
1721          redo A;          redo A;
1722        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
# Line 1639  sub _get_next_token ($) { Line 1745  sub _get_next_token ($) {
1745        } else {        } else {
1746          !!!cp (100);          !!!cp (100);
1747          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{current_attribute}->{value} .= chr ($self->{next_char});
1748            $self->{read_until}->($self->{current_attribute}->{value},
1749                                  q["&],
1750                                  length $self->{current_attribute}->{value});
1751    
1752          ## Stay in the state          ## Stay in the state
1753          !!!next-input-character;          !!!next-input-character;
1754          redo A;          redo A;
# Line 1651  sub _get_next_token ($) { Line 1761  sub _get_next_token ($) {
1761          redo A;          redo A;
1762        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1763          !!!cp (102);          !!!cp (102);
1764          $self->{last_attribute_value_state} = $self->{state};          ## NOTE: In the spec, the tokenizer is switched to the
1765          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## "entity in attribute value state".  In this implementation, the
1766            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1767            ## implementation of the "consume a character reference" algorithm.
1768            $self->{entity_additional} = 0x0027; # '
1769            $self->{prev_state} = $self->{state};
1770            $self->{state} = ENTITY_STATE;
1771          !!!next-input-character;          !!!next-input-character;
1772          redo A;          redo A;
1773        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
# Line 1681  sub _get_next_token ($) { Line 1796  sub _get_next_token ($) {
1796        } else {        } else {
1797          !!!cp (106);          !!!cp (106);
1798          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{current_attribute}->{value} .= chr ($self->{next_char});
1799            $self->{read_until}->($self->{current_attribute}->{value},
1800                                  q['&],
1801                                  length $self->{current_attribute}->{value});
1802    
1803          ## Stay in the state          ## Stay in the state
1804          !!!next-input-character;          !!!next-input-character;
1805          redo A;          redo A;
# Line 1697  sub _get_next_token ($) { Line 1816  sub _get_next_token ($) {
1816          redo A;          redo A;
1817        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1818          !!!cp (108);          !!!cp (108);
1819          $self->{last_attribute_value_state} = $self->{state};          ## NOTE: In the spec, the tokenizer is switched to the
1820          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## "entity in attribute value state".  In this implementation, the
1821            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1822            ## implementation of the "consume a character reference" algorithm.
1823            $self->{entity_additional} = -1;
1824            $self->{prev_state} = $self->{state};
1825            $self->{state} = ENTITY_STATE;
1826          !!!next-input-character;          !!!next-input-character;
1827          redo A;          redo A;
1828        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
# Line 1758  sub _get_next_token ($) { Line 1882  sub _get_next_token ($) {
1882            !!!cp (116);            !!!cp (116);
1883          }          }
1884          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{current_attribute}->{value} .= chr ($self->{next_char});
1885            $self->{read_until}->($self->{current_attribute}->{value},
1886                                  q["'=& >],
1887                                  length $self->{current_attribute}->{value});
1888    
1889          ## Stay in the state          ## Stay in the state
1890          !!!next-input-character;          !!!next-input-character;
1891          redo A;          redo A;
1892        }        }
     } elsif ($self->{state} == ENTITY_IN_ATTRIBUTE_VALUE_STATE) {  
       my $token = $self->_tokenize_attempt_to_consume_an_entity  
           (1,  
            $self->{last_attribute_value_state}  
              == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE ? 0x0022 : # "  
            $self->{last_attribute_value_state}  
              == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE ? 0x0027 : # '  
            -1);  
   
       unless (defined $token) {  
         !!!cp (117);  
         $self->{current_attribute}->{value} .= '&';  
       } else {  
         !!!cp (118);  
         $self->{current_attribute}->{value} .= $token->{data};  
         $self->{current_attribute}->{has_reference} = $token->{has_reference};  
         ## ISSUE: spec says "append the returned character token to the current attribute's value"  
       }  
   
       $self->{state} = $self->{last_attribute_value_state};  
       # next-input-character is already done  
       redo A;  
1893      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {
1894        if ($self->{next_char} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
1895            $self->{next_char} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
# Line 1903  sub _get_next_token ($) { Line 2009  sub _get_next_token ($) {
2009        }        }
2010      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {
2011        ## (only happen if PCDATA state)        ## (only happen if PCDATA state)
         
       ## NOTE: Set by the previous state  
       #my $token = {type => COMMENT_TOKEN, data => ''};  
   
       BC: {  
         if ($self->{next_char} == 0x003E) { # >  
           !!!cp (124);  
           $self->{state} = DATA_STATE;  
           !!!next-input-character;  
   
           !!!emit ($self->{current_token}); # comment  
2012    
2013            redo A;        ## NOTE: Unlike spec's "bogus comment state", this implementation
2014          } elsif ($self->{next_char} == -1) {        ## consumes characters one-by-one basis.
2015            !!!cp (125);        
2016            $self->{state} = DATA_STATE;        if ($self->{next_char} == 0x003E) { # >
2017            ## reconsume          !!!cp (124);
2018            $self->{state} = DATA_STATE;
2019            !!!next-input-character;
2020    
2021            !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
2022            redo A;
2023          } elsif ($self->{next_char} == -1) {
2024            !!!cp (125);
2025            $self->{state} = DATA_STATE;
2026            ## reconsume
2027    
2028            redo A;          !!!emit ($self->{current_token}); # comment
2029          } else {          redo A;
2030            !!!cp (126);        } else {
2031            $self->{current_token}->{data} .= chr ($self->{next_char}); # comment          !!!cp (126);
2032            !!!next-input-character;          $self->{current_token}->{data} .= chr ($self->{next_char}); # comment
2033            redo BC;          $self->{read_until}->($self->{current_token}->{data},
2034          }                                q[>],
2035        } # BC                                length $self->{current_token}->{data});
2036    
2037        die "$0: _get_next_token: unexpected case [BC]";          ## Stay in the state.
2038            !!!next-input-character;
2039            redo A;
2040          }
2041      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {
2042        ## (only happen if PCDATA state)        ## (only happen if PCDATA state)
   
       my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1);  
   
       my @next_char;  
       push @next_char, $self->{next_char};  
2043                
2044        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
2045            !!!cp (133);
2046            $self->{state} = MD_HYPHEN_STATE;
2047          !!!next-input-character;          !!!next-input-character;
2048          push @next_char, $self->{next_char};          redo A;
         if ($self->{next_char} == 0x002D) { # -  
           !!!cp (127);  
           $self->{current_token} = {type => COMMENT_TOKEN, data => '',  
                                     line => $l, column => $c,  
                                    };  
           $self->{state} = COMMENT_START_STATE;  
           !!!next-input-character;  
           redo A;  
         } else {  
           !!!cp (128);  
         }  
2049        } elsif ($self->{next_char} == 0x0044 or # D        } elsif ($self->{next_char} == 0x0044 or # D
2050                 $self->{next_char} == 0x0064) { # d                 $self->{next_char} == 0x0064) { # d
2051            ## ASCII case-insensitive.
2052            !!!cp (130);
2053            $self->{state} = MD_DOCTYPE_STATE;
2054            $self->{state_keyword} = chr $self->{next_char};
2055          !!!next-input-character;          !!!next-input-character;
2056          push @next_char, $self->{next_char};          redo A;
         if ($self->{next_char} == 0x004F or # O  
             $self->{next_char} == 0x006F) { # o  
           !!!next-input-character;  
           push @next_char, $self->{next_char};  
           if ($self->{next_char} == 0x0043 or # C  
               $self->{next_char} == 0x0063) { # c  
             !!!next-input-character;  
             push @next_char, $self->{next_char};  
             if ($self->{next_char} == 0x0054 or # T  
                 $self->{next_char} == 0x0074) { # t  
               !!!next-input-character;  
               push @next_char, $self->{next_char};  
               if ($self->{next_char} == 0x0059 or # Y  
                   $self->{next_char} == 0x0079) { # y  
                 !!!next-input-character;  
                 push @next_char, $self->{next_char};  
                 if ($self->{next_char} == 0x0050 or # P  
                     $self->{next_char} == 0x0070) { # p  
                   !!!next-input-character;  
                   push @next_char, $self->{next_char};  
                   if ($self->{next_char} == 0x0045 or # E  
                       $self->{next_char} == 0x0065) { # e  
                     !!!cp (129);  
                     ## TODO: What a stupid code this is!  
                     $self->{state} = DOCTYPE_STATE;  
                     $self->{current_token} = {type => DOCTYPE_TOKEN,  
                                               quirks => 1,  
                                               line => $l, column => $c,  
                                              };  
                     !!!next-input-character;  
                     redo A;  
                   } else {  
                     !!!cp (130);  
                   }  
                 } else {  
                   !!!cp (131);  
                 }  
               } else {  
                 !!!cp (132);  
               }  
             } else {  
               !!!cp (133);  
             }  
           } else {  
             !!!cp (134);  
           }  
         } else {  
           !!!cp (135);  
         }  
2057        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and
2058                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and
2059                 $self->{next_char} == 0x005B) { # [                 $self->{next_char} == 0x005B) { # [
2060            !!!cp (135.4);                
2061            $self->{state} = MD_CDATA_STATE;
2062            $self->{state_keyword} = '[';
2063          !!!next-input-character;          !!!next-input-character;
2064          push @next_char, $self->{next_char};          redo A;
         if ($self->{next_char} == 0x0043) { # C  
           !!!next-input-character;  
           push @next_char, $self->{next_char};  
           if ($self->{next_char} == 0x0044) { # D  
             !!!next-input-character;  
             push @next_char, $self->{next_char};  
             if ($self->{next_char} == 0x0041) { # A  
               !!!next-input-character;  
               push @next_char, $self->{next_char};  
               if ($self->{next_char} == 0x0054) { # T  
                 !!!next-input-character;  
                 push @next_char, $self->{next_char};  
                 if ($self->{next_char} == 0x0041) { # A  
                   !!!next-input-character;  
                   push @next_char, $self->{next_char};  
                   if ($self->{next_char} == 0x005B) { # [  
                     !!!cp (135.1);  
                     $self->{state} = CDATA_BLOCK_STATE;  
                     !!!next-input-character;  
                     redo A;  
                   } else {  
                     !!!cp (135.2);  
                   }  
                 } else {  
                   !!!cp (135.3);  
                 }  
               } else {  
                 !!!cp (135.4);                  
               }  
             } else {  
               !!!cp (135.5);  
             }  
           } else {  
             !!!cp (135.6);  
           }  
         } else {  
           !!!cp (135.7);  
         }  
2065        } else {        } else {
2066          !!!cp (136);          !!!cp (136);
2067        }        }
2068    
2069        !!!parse-error (type => 'bogus comment');        !!!parse-error (type => 'bogus comment',
2070        $self->{next_char} = shift @next_char;                        line => $self->{line_prev},
2071        !!!back-next-input-character (@next_char);                        column => $self->{column_prev} - 1);
2072          ## Reconsume.
2073        $self->{state} = BOGUS_COMMENT_STATE;        $self->{state} = BOGUS_COMMENT_STATE;
2074        $self->{current_token} = {type => COMMENT_TOKEN, data => '',        $self->{current_token} = {type => COMMENT_TOKEN, data => '',
2075                                  line => $l, column => $c,                                  line => $self->{line_prev},
2076                                    column => $self->{column_prev} - 1,
2077                                 };                                 };
2078        redo A;        redo A;
2079              } elsif ($self->{state} == MD_HYPHEN_STATE) {
2080        ## ISSUE: typos in spec: chacacters, is is a parse error        if ($self->{next_char} == 0x002D) { # -
2081        ## ISSUE: spec is somewhat unclear on "is the first character that will be in the comment"; what is "that will be in the comment" is what the algorithm defines, isn't it?          !!!cp (127);
2082            $self->{current_token} = {type => COMMENT_TOKEN, data => '',
2083                                      line => $self->{line_prev},
2084                                      column => $self->{column_prev} - 2,
2085                                     };
2086            $self->{state} = COMMENT_START_STATE;
2087            !!!next-input-character;
2088            redo A;
2089          } else {
2090            !!!cp (128);
2091            !!!parse-error (type => 'bogus comment',
2092                            line => $self->{line_prev},
2093                            column => $self->{column_prev} - 2);
2094            $self->{state} = BOGUS_COMMENT_STATE;
2095            ## Reconsume.
2096            $self->{current_token} = {type => COMMENT_TOKEN,
2097                                      data => '-',
2098                                      line => $self->{line_prev},
2099                                      column => $self->{column_prev} - 2,
2100                                     };
2101            redo A;
2102          }
2103        } elsif ($self->{state} == MD_DOCTYPE_STATE) {
2104          ## ASCII case-insensitive.
2105          if ($self->{next_char} == [
2106                undef,
2107                0x004F, # O
2108                0x0043, # C
2109                0x0054, # T
2110                0x0059, # Y
2111                0x0050, # P
2112              ]->[length $self->{state_keyword}] or
2113              $self->{next_char} == [
2114                undef,
2115                0x006F, # o
2116                0x0063, # c
2117                0x0074, # t
2118                0x0079, # y
2119                0x0070, # p
2120              ]->[length $self->{state_keyword}]) {
2121            !!!cp (131);
2122            ## Stay in the state.
2123            $self->{state_keyword} .= chr $self->{next_char};
2124            !!!next-input-character;
2125            redo A;
2126          } elsif ((length $self->{state_keyword}) == 6 and
2127                   ($self->{next_char} == 0x0045 or # E
2128                    $self->{next_char} == 0x0065)) { # e
2129            !!!cp (129);
2130            $self->{state} = DOCTYPE_STATE;
2131            $self->{current_token} = {type => DOCTYPE_TOKEN,
2132                                      quirks => 1,
2133                                      line => $self->{line_prev},
2134                                      column => $self->{column_prev} - 7,
2135                                     };
2136            !!!next-input-character;
2137            redo A;
2138          } else {
2139            !!!cp (132);        
2140            !!!parse-error (type => 'bogus comment',
2141                            line => $self->{line_prev},
2142                            column => $self->{column_prev} - 1 - length $self->{state_keyword});
2143            $self->{state} = BOGUS_COMMENT_STATE;
2144            ## Reconsume.
2145            $self->{current_token} = {type => COMMENT_TOKEN,
2146                                      data => $self->{state_keyword},
2147                                      line => $self->{line_prev},
2148                                      column => $self->{column_prev} - 1 - length $self->{state_keyword},
2149                                     };
2150            redo A;
2151          }
2152        } elsif ($self->{state} == MD_CDATA_STATE) {
2153          if ($self->{next_char} == {
2154                '[' => 0x0043, # C
2155                '[C' => 0x0044, # D
2156                '[CD' => 0x0041, # A
2157                '[CDA' => 0x0054, # T
2158                '[CDAT' => 0x0041, # A
2159              }->{$self->{state_keyword}}) {
2160            !!!cp (135.1);
2161            ## Stay in the state.
2162            $self->{state_keyword} .= chr $self->{next_char};
2163            !!!next-input-character;
2164            redo A;
2165          } elsif ($self->{state_keyword} eq '[CDATA' and
2166                   $self->{next_char} == 0x005B) { # [
2167            !!!cp (135.2);
2168            $self->{current_token} = {type => CHARACTER_TOKEN,
2169                                      data => '',
2170                                      line => $self->{line_prev},
2171                                      column => $self->{column_prev} - 7};
2172            $self->{state} = CDATA_SECTION_STATE;
2173            !!!next-input-character;
2174            redo A;
2175          } else {
2176            !!!cp (135.3);
2177            !!!parse-error (type => 'bogus comment',
2178                            line => $self->{line_prev},
2179                            column => $self->{column_prev} - 1 - length $self->{state_keyword});
2180            $self->{state} = BOGUS_COMMENT_STATE;
2181            ## Reconsume.
2182            $self->{current_token} = {type => COMMENT_TOKEN,
2183                                      data => $self->{state_keyword},
2184                                      line => $self->{line_prev},
2185                                      column => $self->{column_prev} - 1 - length $self->{state_keyword},
2186                                     };
2187            redo A;
2188          }
2189      } elsif ($self->{state} == COMMENT_START_STATE) {      } elsif ($self->{state} == COMMENT_START_STATE) {
2190        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
2191          !!!cp (137);          !!!cp (137);
# Line 2148  sub _get_next_token ($) { Line 2268  sub _get_next_token ($) {
2268        } else {        } else {
2269          !!!cp (147);          !!!cp (147);
2270          $self->{current_token}->{data} .= chr ($self->{next_char}); # comment          $self->{current_token}->{data} .= chr ($self->{next_char}); # comment
2271            $self->{read_until}->($self->{current_token}->{data},
2272                                  q[-],
2273                                  length $self->{current_token}->{data});
2274    
2275          ## Stay in the state          ## Stay in the state
2276          !!!next-input-character;          !!!next-input-character;
2277          redo A;          redo A;
# Line 2332  sub _get_next_token ($) { Line 2456  sub _get_next_token ($) {
2456          redo A;          redo A;
2457        } elsif ($self->{next_char} == 0x0050 or # P        } elsif ($self->{next_char} == 0x0050 or # P
2458                 $self->{next_char} == 0x0070) { # p                 $self->{next_char} == 0x0070) { # p
2459            $self->{state} = PUBLIC_STATE;
2460            $self->{state_keyword} = chr $self->{next_char};
2461          !!!next-input-character;          !!!next-input-character;
2462          if ($self->{next_char} == 0x0055 or # U          redo A;
             $self->{next_char} == 0x0075) { # u  
           !!!next-input-character;  
           if ($self->{next_char} == 0x0042 or # B  
               $self->{next_char} == 0x0062) { # b  
             !!!next-input-character;  
             if ($self->{next_char} == 0x004C or # L  
                 $self->{next_char} == 0x006C) { # l  
               !!!next-input-character;  
               if ($self->{next_char} == 0x0049 or # I  
                   $self->{next_char} == 0x0069) { # i  
                 !!!next-input-character;  
                 if ($self->{next_char} == 0x0043 or # C  
                     $self->{next_char} == 0x0063) { # c  
                   !!!cp (168);  
                   $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;  
                   !!!next-input-character;  
                   redo A;  
                 } else {  
                   !!!cp (169);  
                 }  
               } else {  
                 !!!cp (170);  
               }  
             } else {  
               !!!cp (171);  
             }  
           } else {  
             !!!cp (172);  
           }  
         } else {  
           !!!cp (173);  
         }  
   
         #  
2463        } elsif ($self->{next_char} == 0x0053 or # S        } elsif ($self->{next_char} == 0x0053 or # S
2464                 $self->{next_char} == 0x0073) { # s                 $self->{next_char} == 0x0073) { # s
2465            $self->{state} = SYSTEM_STATE;
2466            $self->{state_keyword} = chr $self->{next_char};
2467          !!!next-input-character;          !!!next-input-character;
2468          if ($self->{next_char} == 0x0059 or # Y          redo A;
             $self->{next_char} == 0x0079) { # y  
           !!!next-input-character;  
           if ($self->{next_char} == 0x0053 or # S  
               $self->{next_char} == 0x0073) { # s  
             !!!next-input-character;  
             if ($self->{next_char} == 0x0054 or # T  
                 $self->{next_char} == 0x0074) { # t  
               !!!next-input-character;  
               if ($self->{next_char} == 0x0045 or # E  
                   $self->{next_char} == 0x0065) { # e  
                 !!!next-input-character;  
                 if ($self->{next_char} == 0x004D or # M  
                     $self->{next_char} == 0x006D) { # m  
                   !!!cp (174);  
                   $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;  
                   !!!next-input-character;  
                   redo A;  
                 } else {  
                   !!!cp (175);  
                 }  
               } else {  
                 !!!cp (176);  
               }  
             } else {  
               !!!cp (177);  
             }  
           } else {  
             !!!cp (178);  
           }  
         } else {  
           !!!cp (179);  
         }  
   
         #  
2469        } else {        } else {
2470          !!!cp (180);          !!!cp (180);
2471            !!!parse-error (type => 'string after DOCTYPE name');
2472            $self->{current_token}->{quirks} = 1;
2473    
2474            $self->{state} = BOGUS_DOCTYPE_STATE;
2475          !!!next-input-character;          !!!next-input-character;
2476          #          redo A;
2477        }        }
2478        } elsif ($self->{state} == PUBLIC_STATE) {
2479          ## ASCII case-insensitive
2480          if ($self->{next_char} == [
2481                undef,
2482                0x0055, # U
2483                0x0042, # B
2484                0x004C, # L
2485                0x0049, # I
2486              ]->[length $self->{state_keyword}] or
2487              $self->{next_char} == [
2488                undef,
2489                0x0075, # u
2490                0x0062, # b
2491                0x006C, # l
2492                0x0069, # i
2493              ]->[length $self->{state_keyword}]) {
2494            !!!cp (175);
2495            ## Stay in the state.
2496            $self->{state_keyword} .= chr $self->{next_char};
2497            !!!next-input-character;
2498            redo A;
2499          } elsif ((length $self->{state_keyword}) == 5 and
2500                   ($self->{next_char} == 0x0043 or # C
2501                    $self->{next_char} == 0x0063)) { # c
2502            !!!cp (168);
2503            $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
2504            !!!next-input-character;
2505            redo A;
2506          } else {
2507            !!!cp (169);
2508            !!!parse-error (type => 'string after DOCTYPE name',
2509                            line => $self->{line_prev},
2510                            column => $self->{column_prev} + 1 - length $self->{state_keyword});
2511            $self->{current_token}->{quirks} = 1;
2512    
2513        !!!parse-error (type => 'string after DOCTYPE name');          $self->{state} = BOGUS_DOCTYPE_STATE;
2514        $self->{current_token}->{quirks} = 1;          ## Reconsume.
2515            redo A;
2516          }
2517        } elsif ($self->{state} == SYSTEM_STATE) {
2518          ## ASCII case-insensitive
2519          if ($self->{next_char} == [
2520                undef,
2521                0x0059, # Y
2522                0x0053, # S
2523                0x0054, # T
2524                0x0045, # E
2525              ]->[length $self->{state_keyword}] or
2526              $self->{next_char} == [
2527                undef,
2528                0x0079, # y
2529                0x0073, # s
2530                0x0074, # t
2531                0x0065, # e
2532              ]->[length $self->{state_keyword}]) {
2533            !!!cp (170);
2534            ## Stay in the state.
2535            $self->{state_keyword} .= chr $self->{next_char};
2536            !!!next-input-character;
2537            redo A;
2538          } elsif ((length $self->{state_keyword}) == 5 and
2539                   ($self->{next_char} == 0x004D or # M
2540                    $self->{next_char} == 0x006D)) { # m
2541            !!!cp (171);
2542            $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2543            !!!next-input-character;
2544            redo A;
2545          } else {
2546            !!!cp (172);
2547            !!!parse-error (type => 'string after DOCTYPE name',
2548                            line => $self->{line_prev},
2549                            column => $self->{column_prev} + 1 - length $self->{state_keyword});
2550            $self->{current_token}->{quirks} = 1;
2551    
2552        $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2553        # next-input-character is already done          ## Reconsume.
2554        redo A;          redo A;
2555          }
2556      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {
2557        if ({        if ({
2558              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
# Line 2502  sub _get_next_token ($) { Line 2637  sub _get_next_token ($) {
2637          !!!cp (190);          !!!cp (190);
2638          $self->{current_token}->{public_identifier} # DOCTYPE          $self->{current_token}->{public_identifier} # DOCTYPE
2639              .= chr $self->{next_char};              .= chr $self->{next_char};
2640            $self->{read_until}->($self->{current_token}->{public_identifier},
2641                                  q[">],
2642                                  length $self->{current_token}->{public_identifier});
2643    
2644          ## Stay in the state          ## Stay in the state
2645          !!!next-input-character;          !!!next-input-character;
2646          redo A;          redo A;
# Line 2538  sub _get_next_token ($) { Line 2677  sub _get_next_token ($) {
2677          !!!cp (194);          !!!cp (194);
2678          $self->{current_token}->{public_identifier} # DOCTYPE          $self->{current_token}->{public_identifier} # DOCTYPE
2679              .= chr $self->{next_char};              .= chr $self->{next_char};
2680            $self->{read_until}->($self->{current_token}->{public_identifier},
2681                                  q['>],
2682                                  length $self->{current_token}->{public_identifier});
2683    
2684          ## Stay in the state          ## Stay in the state
2685          !!!next-input-character;          !!!next-input-character;
2686          redo A;          redo A;
# Line 2650  sub _get_next_token ($) { Line 2793  sub _get_next_token ($) {
2793          redo A;          redo A;
2794        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2795          !!!cp (208);          !!!cp (208);
2796          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2797    
2798          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2799          !!!next-input-character;          !!!next-input-character;
# Line 2674  sub _get_next_token ($) { Line 2817  sub _get_next_token ($) {
2817          !!!cp (210);          !!!cp (210);
2818          $self->{current_token}->{system_identifier} # DOCTYPE          $self->{current_token}->{system_identifier} # DOCTYPE
2819              .= chr $self->{next_char};              .= chr $self->{next_char};
2820            $self->{read_until}->($self->{current_token}->{system_identifier},
2821                                  q[">],
2822                                  length $self->{current_token}->{system_identifier});
2823    
2824          ## Stay in the state          ## Stay in the state
2825          !!!next-input-character;          !!!next-input-character;
2826          redo A;          redo A;
# Line 2686  sub _get_next_token ($) { Line 2833  sub _get_next_token ($) {
2833          redo A;          redo A;
2834        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2835          !!!cp (212);          !!!cp (212);
2836          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2837    
2838          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2839          !!!next-input-character;          !!!next-input-character;
# Line 2710  sub _get_next_token ($) { Line 2857  sub _get_next_token ($) {
2857          !!!cp (214);          !!!cp (214);
2858          $self->{current_token}->{system_identifier} # DOCTYPE          $self->{current_token}->{system_identifier} # DOCTYPE
2859              .= chr $self->{next_char};              .= chr $self->{next_char};
2860            $self->{read_until}->($self->{current_token}->{system_identifier},
2861                                  q['>],
2862                                  length $self->{current_token}->{system_identifier});
2863    
2864          ## Stay in the state          ## Stay in the state
2865          !!!next-input-character;          !!!next-input-character;
2866          redo A;          redo A;
# Line 2733  sub _get_next_token ($) { Line 2884  sub _get_next_token ($) {
2884          redo A;          redo A;
2885        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
2886          !!!cp (217);          !!!cp (217);
2887            !!!parse-error (type => 'unclosed DOCTYPE');
2888          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2889          ## reconsume          ## reconsume
2890    
# Line 2770  sub _get_next_token ($) { Line 2921  sub _get_next_token ($) {
2921          redo A;          redo A;
2922        } else {        } else {
2923          !!!cp (221);          !!!cp (221);
2924            my $s = '';
2925            $self->{read_until}->($s, q[>], 0);
2926    
2927          ## Stay in the state          ## Stay in the state
2928          !!!next-input-character;          !!!next-input-character;
2929          redo A;          redo A;
2930        }        }
2931      } elsif ($self->{state} == CDATA_BLOCK_STATE) {      } elsif ($self->{state} == CDATA_SECTION_STATE) {
2932        my $s = '';        ## NOTE: "CDATA section state" in the state is jointly implemented
2933          ## by three states, |CDATA_SECTION_STATE|, |CDATA_SECTION_MSE1_STATE|,
2934          ## and |CDATA_SECTION_MSE2_STATE|.
2935                
2936        my ($l, $c) = ($self->{line}, $self->{column});        if ($self->{next_char} == 0x005D) { # ]
2937            !!!cp (221.1);
2938        CS: while ($self->{next_char} != -1) {          $self->{state} = CDATA_SECTION_MSE1_STATE;
         if ($self->{next_char} == 0x005D) { # ]  
           !!!next-input-character;  
           if ($self->{next_char} == 0x005D) { # ]  
             !!!next-input-character;  
             MDC: {  
               if ($self->{next_char} == 0x003E) { # >  
                 !!!cp (221.1);  
                 !!!next-input-character;  
                 last CS;  
               } elsif ($self->{next_char} == 0x005D) { # ]  
                 !!!cp (221.2);  
                 $s .= ']';  
                 !!!next-input-character;  
                 redo MDC;  
               } else {  
                 !!!cp (221.3);  
                 $s .= ']]';  
                 #  
               }  
             } # MDC  
           } else {  
             !!!cp (221.4);  
             $s .= ']';  
             #  
           }  
         } else {  
           !!!cp (221.5);  
           #  
         }  
         $s .= chr $self->{next_char};  
2939          !!!next-input-character;          !!!next-input-character;
2940        } # CS          redo A;
2941          } elsif ($self->{next_char} == -1) {
2942            $self->{state} = DATA_STATE;
2943            !!!next-input-character;
2944            if (length $self->{current_token}->{data}) { # character
2945              !!!cp (221.2);
2946              !!!emit ($self->{current_token}); # character
2947            } else {
2948              !!!cp (221.3);
2949              ## No token to emit. $self->{current_token} is discarded.
2950            }        
2951            redo A;
2952          } else {
2953            !!!cp (221.4);
2954            $self->{current_token}->{data} .= chr $self->{next_char};
2955            $self->{read_until}->($self->{current_token}->{data},
2956                                  q<]>,
2957                                  length $self->{current_token}->{data});
2958    
2959        $self->{state} = DATA_STATE;          ## Stay in the state.
2960        ## next-input-character done or EOF, which is reconsumed.          !!!next-input-character;
2961            redo A;
2962          }
2963    
2964        if (length $s) {        ## ISSUE: "text tokens" in spec.
2965        } elsif ($self->{state} == CDATA_SECTION_MSE1_STATE) {
2966          if ($self->{next_char} == 0x005D) { # ]
2967            !!!cp (221.5);
2968            $self->{state} = CDATA_SECTION_MSE2_STATE;
2969            !!!next-input-character;
2970            redo A;
2971          } else {
2972          !!!cp (221.6);          !!!cp (221.6);
2973          !!!emit ({type => CHARACTER_TOKEN, data => $s,          $self->{current_token}->{data} .= ']';
2974                    line => $l, column => $c});          $self->{state} = CDATA_SECTION_STATE;
2975            ## Reconsume.
2976            redo A;
2977          }
2978        } elsif ($self->{state} == CDATA_SECTION_MSE2_STATE) {
2979          if ($self->{next_char} == 0x003E) { # >
2980            $self->{state} = DATA_STATE;
2981            !!!next-input-character;
2982            if (length $self->{current_token}->{data}) { # character
2983              !!!cp (221.7);
2984              !!!emit ($self->{current_token}); # character
2985            } else {
2986              !!!cp (221.8);
2987              ## No token to emit. $self->{current_token} is discarded.
2988            }
2989            redo A;
2990          } elsif ($self->{next_char} == 0x005D) { # ]
2991            !!!cp (221.9); # character
2992            $self->{current_token}->{data} .= ']'; ## Add first "]" of "]]]".
2993            ## Stay in the state.
2994            !!!next-input-character;
2995            redo A;
2996        } else {        } else {
2997          !!!cp (221.7);          !!!cp (221.11);
2998            $self->{current_token}->{data} .= ']]'; # character
2999            $self->{state} = CDATA_SECTION_STATE;
3000            ## Reconsume.
3001            redo A;
3002          }
3003        } elsif ($self->{state} == ENTITY_STATE) {
3004          if ({
3005            0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,
3006            0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, &
3007            $self->{entity_additional} => 1,
3008          }->{$self->{next_char}}) {
3009            !!!cp (1001);
3010            ## Don't consume
3011            ## No error
3012            ## Return nothing.
3013            #
3014          } elsif ($self->{next_char} == 0x0023) { # #
3015            !!!cp (999);
3016            $self->{state} = ENTITY_HASH_STATE;
3017            $self->{state_keyword} = '#';
3018            !!!next-input-character;
3019            redo A;
3020          } elsif ((0x0041 <= $self->{next_char} and
3021                    $self->{next_char} <= 0x005A) or # A..Z
3022                   (0x0061 <= $self->{next_char} and
3023                    $self->{next_char} <= 0x007A)) { # a..z
3024            !!!cp (998);
3025            require Whatpm::_NamedEntityList;
3026            $self->{state} = ENTITY_NAME_STATE;
3027            $self->{state_keyword} = chr $self->{next_char};
3028            $self->{entity__value} = $self->{state_keyword};
3029            $self->{entity__match} = 0;
3030            !!!next-input-character;
3031            redo A;
3032          } else {
3033            !!!cp (1027);
3034            !!!parse-error (type => 'bare ero');
3035            ## Return nothing.
3036            #
3037        }        }
3038    
3039        redo A;        ## NOTE: No character is consumed by the "consume a character
3040          ## reference" algorithm.  In other word, there is an "&" character
3041        ## ISSUE: "text tokens" in spec.        ## that does not introduce a character reference, which would be
3042        ## TODO: Streaming support        ## appended to the parent element or the attribute value in later
3043      } else {        ## process of the tokenizer.
3044        die "$0: $self->{state}: Unknown state";  
3045      }        if ($self->{prev_state} == DATA_STATE) {
3046    } # A            !!!cp (997);
3047            $self->{state} = $self->{prev_state};
3048    die "$0: _get_next_token: unexpected case";          ## Reconsume.
3049  } # _get_next_token          !!!emit ({type => CHARACTER_TOKEN, data => '&',
3050                      line => $self->{line_prev},
3051  sub _tokenize_attempt_to_consume_an_entity ($$$) {                    column => $self->{column_prev},
3052    my ($self, $in_attr, $additional) = @_;                   });
3053            redo A;
3054    my ($l, $c) = ($self->{line_prev}, $self->{column_prev});        } else {
3055            !!!cp (996);
3056            $self->{current_attribute}->{value} .= '&';
3057            $self->{state} = $self->{prev_state};
3058            ## Reconsume.
3059            redo A;
3060          }
3061        } elsif ($self->{state} == ENTITY_HASH_STATE) {
3062          if ($self->{next_char} == 0x0078 or # x
3063              $self->{next_char} == 0x0058) { # X
3064            !!!cp (995);
3065            $self->{state} = HEXREF_X_STATE;
3066            $self->{state_keyword} .= chr $self->{next_char};
3067            !!!next-input-character;
3068            redo A;
3069          } elsif (0x0030 <= $self->{next_char} and
3070                   $self->{next_char} <= 0x0039) { # 0..9
3071            !!!cp (994);
3072            $self->{state} = NCR_NUM_STATE;
3073            $self->{state_keyword} = $self->{next_char} - 0x0030;
3074            !!!next-input-character;
3075            redo A;
3076          } else {
3077            !!!parse-error (type => 'bare nero',
3078                            line => $self->{line_prev},
3079                            column => $self->{column_prev} - 1);
3080    
3081    if ({          ## NOTE: According to the spec algorithm, nothing is returned,
3082         0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,          ## and then "&#" is appended to the parent element or the attribute
3083         0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR          ## value in the later processing.
3084         $additional => 1,  
3085        }->{$self->{next_char}}) {          if ($self->{prev_state} == DATA_STATE) {
3086      !!!cp (1001);            !!!cp (1019);
3087      ## Don't consume            $self->{state} = $self->{prev_state};
3088      ## No error            ## Reconsume.
3089      return undef;            !!!emit ({type => CHARACTER_TOKEN,
3090    } elsif ($self->{next_char} == 0x0023) { # #                      data => '&#',
3091      !!!next-input-character;                      line => $self->{line_prev},
3092      if ($self->{next_char} == 0x0078 or # x                      column => $self->{column_prev} - 1,
3093          $self->{next_char} == 0x0058) { # X                     });
3094        my $code;            redo A;
       X: {  
         my $x_char = $self->{next_char};  
         !!!next-input-character;  
         if (0x0030 <= $self->{next_char} and  
             $self->{next_char} <= 0x0039) { # 0..9  
           !!!cp (1002);  
           $code ||= 0;  
           $code *= 0x10;  
           $code += $self->{next_char} - 0x0030;  
           redo X;  
         } elsif (0x0061 <= $self->{next_char} and  
                  $self->{next_char} <= 0x0066) { # a..f  
           !!!cp (1003);  
           $code ||= 0;  
           $code *= 0x10;  
           $code += $self->{next_char} - 0x0060 + 9;  
           redo X;  
         } elsif (0x0041 <= $self->{next_char} and  
                  $self->{next_char} <= 0x0046) { # A..F  
           !!!cp (1004);  
           $code ||= 0;  
           $code *= 0x10;  
           $code += $self->{next_char} - 0x0040 + 9;  
           redo X;  
         } elsif (not defined $code) { # no hexadecimal digit  
           !!!cp (1005);  
           !!!parse-error (type => 'bare hcro', line => $l, column => $c);  
           !!!back-next-input-character ($x_char, $self->{next_char});  
           $self->{next_char} = 0x0023; # #  
           return undef;  
         } elsif ($self->{next_char} == 0x003B) { # ;  
           !!!cp (1006);  
           !!!next-input-character;  
3095          } else {          } else {
3096            !!!cp (1007);            !!!cp (993);
3097            !!!parse-error (type => 'no refc', line => $l, column => $c);            $self->{current_attribute}->{value} .= '&#';
3098              $self->{state} = $self->{prev_state};
3099              ## Reconsume.
3100              redo A;
3101          }          }
3102          }
3103          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {      } elsif ($self->{state} == NCR_NUM_STATE) {
3104            !!!cp (1008);        if (0x0030 <= $self->{next_char} and
3105            !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);            $self->{next_char} <= 0x0039) { # 0..9
           $code = 0xFFFD;  
         } elsif ($code > 0x10FFFF) {  
           !!!cp (1009);  
           !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);  
           $code = 0xFFFD;  
         } elsif ($code == 0x000D) {  
           !!!cp (1010);  
           !!!parse-error (type => 'CR character reference', line => $l, column => $c);  
           $code = 0x000A;  
         } elsif (0x80 <= $code and $code <= 0x9F) {  
           !!!cp (1011);  
           !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);  
           $code = $c1_entity_char->{$code};  
         }  
   
         return {type => CHARACTER_TOKEN, data => chr $code,  
                 has_reference => 1,  
                 line => $l, column => $c,  
                };  
       } # X  
     } elsif (0x0030 <= $self->{next_char} and  
              $self->{next_char} <= 0x0039) { # 0..9  
       my $code = $self->{next_char} - 0x0030;  
       !!!next-input-character;  
         
       while (0x0030 <= $self->{next_char} and  
                 $self->{next_char} <= 0x0039) { # 0..9  
3106          !!!cp (1012);          !!!cp (1012);
3107          $code *= 10;          $self->{state_keyword} *= 10;
3108          $code += $self->{next_char} - 0x0030;          $self->{state_keyword} += $self->{next_char} - 0x0030;
3109                    
3110            ## Stay in the state.
3111          !!!next-input-character;          !!!next-input-character;
3112        }          redo A;
3113          } elsif ($self->{next_char} == 0x003B) { # ;
       if ($self->{next_char} == 0x003B) { # ;  
3114          !!!cp (1013);          !!!cp (1013);
3115          !!!next-input-character;          !!!next-input-character;
3116            #
3117        } else {        } else {
3118          !!!cp (1014);          !!!cp (1014);
3119          !!!parse-error (type => 'no refc', line => $l, column => $c);          !!!parse-error (type => 'no refc');
3120            ## Reconsume.
3121            #
3122        }        }
3123    
3124          my $code = $self->{state_keyword};
3125          my $l = $self->{line_prev};
3126          my $c = $self->{column_prev};
3127        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3128          !!!cp (1015);          !!!cp (1015);
3129          !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3130                            text => (sprintf 'U+%04X', $code),
3131                            line => $l, column => $c);
3132          $code = 0xFFFD;          $code = 0xFFFD;
3133        } elsif ($code > 0x10FFFF) {        } elsif ($code > 0x10FFFF) {
3134          !!!cp (1016);          !!!cp (1016);
3135          !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3136                            text => (sprintf 'U-%08X', $code),
3137                            line => $l, column => $c);
3138          $code = 0xFFFD;          $code = 0xFFFD;
3139        } elsif ($code == 0x000D) {        } elsif ($code == 0x000D) {
3140          !!!cp (1017);          !!!cp (1017);
3141          !!!parse-error (type => 'CR character reference', line => $l, column => $c);          !!!parse-error (type => 'CR character reference',
3142                            line => $l, column => $c);
3143          $code = 0x000A;          $code = 0x000A;
3144        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
3145          !!!cp (1018);          !!!cp (1018);
3146          !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'C1 character reference',
3147                            text => (sprintf 'U+%04X', $code),
3148                            line => $l, column => $c);
3149          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
3150        }        }
3151          
3152        return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1,        if ($self->{prev_state} == DATA_STATE) {
3153                line => $l, column => $c,          !!!cp (992);
3154               };          $self->{state} = $self->{prev_state};
3155      } else {          ## Reconsume.
3156        !!!cp (1019);          !!!emit ({type => CHARACTER_TOKEN, data => chr $code,
3157        !!!parse-error (type => 'bare nero', line => $l, column => $c);                    line => $l, column => $c,
3158        !!!back-next-input-character ($self->{next_char});                   });
3159        $self->{next_char} = 0x0023; # #          redo A;
3160        return undef;        } else {
3161      }          !!!cp (991);
3162    } elsif ((0x0041 <= $self->{next_char} and          $self->{current_attribute}->{value} .= chr $code;
3163              $self->{next_char} <= 0x005A) or          $self->{current_attribute}->{has_reference} = 1;
3164             (0x0061 <= $self->{next_char} and          $self->{state} = $self->{prev_state};
3165              $self->{next_char} <= 0x007A)) {          ## Reconsume.
3166      my $entity_name = chr $self->{next_char};          redo A;
3167      !!!next-input-character;        }
3168        } elsif ($self->{state} == HEXREF_X_STATE) {
3169      my $value = $entity_name;        if ((0x0030 <= $self->{next_char} and $self->{next_char} <= 0x0039) or
3170      my $match = 0;            (0x0041 <= $self->{next_char} and $self->{next_char} <= 0x0046) or
3171      require Whatpm::_NamedEntityList;            (0x0061 <= $self->{next_char} and $self->{next_char} <= 0x0066)) {
3172      our $EntityChar;          # 0..9, A..F, a..f
3173            !!!cp (990);
3174      while (length $entity_name < 30 and          $self->{state} = HEXREF_HEX_STATE;
3175             ## NOTE: Some number greater than the maximum length of entity name          $self->{state_keyword} = 0;
3176             ((0x0041 <= $self->{next_char} and # a          ## Reconsume.
3177               $self->{next_char} <= 0x005A) or # x          redo A;
3178              (0x0061 <= $self->{next_char} and # a        } else {
3179               $self->{next_char} <= 0x007A) or # z          !!!parse-error (type => 'bare hcro',
3180              (0x0030 <= $self->{next_char} and # 0                          line => $self->{line_prev},
3181               $self->{next_char} <= 0x0039) or # 9                          column => $self->{column_prev} - 2);
3182              $self->{next_char} == 0x003B)) { # ;  
3183        $entity_name .= chr $self->{next_char};          ## NOTE: According to the spec algorithm, nothing is returned,
3184        if (defined $EntityChar->{$entity_name}) {          ## and then "&#" followed by "X" or "x" is appended to the parent
3185          if ($self->{next_char} == 0x003B) { # ;          ## element or the attribute value in the later processing.
3186            !!!cp (1020);  
3187            $value = $EntityChar->{$entity_name};          if ($self->{prev_state} == DATA_STATE) {
3188            $match = 1;            !!!cp (1005);
3189            !!!next-input-character;            $self->{state} = $self->{prev_state};
3190            last;            ## Reconsume.
3191              !!!emit ({type => CHARACTER_TOKEN,
3192                        data => '&' . $self->{state_keyword},
3193                        line => $self->{line_prev},
3194                        column => $self->{column_prev} - length $self->{state_keyword},
3195                       });
3196              redo A;
3197            } else {
3198              !!!cp (989);
3199              $self->{current_attribute}->{value} .= '&' . $self->{state_keyword};
3200              $self->{state} = $self->{prev_state};
3201              ## Reconsume.
3202              redo A;
3203            }
3204          }
3205        } elsif ($self->{state} == HEXREF_HEX_STATE) {
3206          if (0x0030 <= $self->{next_char} and $self->{next_char} <= 0x0039) {
3207            # 0..9
3208            !!!cp (1002);
3209            $self->{state_keyword} *= 0x10;
3210            $self->{state_keyword} += $self->{next_char} - 0x0030;
3211            ## Stay in the state.
3212            !!!next-input-character;
3213            redo A;
3214          } elsif (0x0061 <= $self->{next_char} and
3215                   $self->{next_char} <= 0x0066) { # a..f
3216            !!!cp (1003);
3217            $self->{state_keyword} *= 0x10;
3218            $self->{state_keyword} += $self->{next_char} - 0x0060 + 9;
3219            ## Stay in the state.
3220            !!!next-input-character;
3221            redo A;
3222          } elsif (0x0041 <= $self->{next_char} and
3223                   $self->{next_char} <= 0x0046) { # A..F
3224            !!!cp (1004);
3225            $self->{state_keyword} *= 0x10;
3226            $self->{state_keyword} += $self->{next_char} - 0x0040 + 9;
3227            ## Stay in the state.
3228            !!!next-input-character;
3229            redo A;
3230          } elsif ($self->{next_char} == 0x003B) { # ;
3231            !!!cp (1006);
3232            !!!next-input-character;
3233            #
3234          } else {
3235            !!!cp (1007);
3236            !!!parse-error (type => 'no refc',
3237                            line => $self->{line},
3238                            column => $self->{column});
3239            ## Reconsume.
3240            #
3241          }
3242    
3243          my $code = $self->{state_keyword};
3244          my $l = $self->{line_prev};
3245          my $c = $self->{column_prev};
3246          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3247            !!!cp (1008);
3248            !!!parse-error (type => 'invalid character reference',
3249                            text => (sprintf 'U+%04X', $code),
3250                            line => $l, column => $c);
3251            $code = 0xFFFD;
3252          } elsif ($code > 0x10FFFF) {
3253            !!!cp (1009);
3254            !!!parse-error (type => 'invalid character reference',
3255                            text => (sprintf 'U-%08X', $code),
3256                            line => $l, column => $c);
3257            $code = 0xFFFD;
3258          } elsif ($code == 0x000D) {
3259            !!!cp (1010);
3260            !!!parse-error (type => 'CR character reference', line => $l, column => $c);
3261            $code = 0x000A;
3262          } elsif (0x80 <= $code and $code <= 0x9F) {
3263            !!!cp (1011);
3264            !!!parse-error (type => 'C1 character reference', text => (sprintf 'U+%04X', $code), line => $l, column => $c);
3265            $code = $c1_entity_char->{$code};
3266          }
3267    
3268          if ($self->{prev_state} == DATA_STATE) {
3269            !!!cp (988);
3270            $self->{state} = $self->{prev_state};
3271            ## Reconsume.
3272            !!!emit ({type => CHARACTER_TOKEN, data => chr $code,
3273                      line => $l, column => $c,
3274                     });
3275            redo A;
3276          } else {
3277            !!!cp (987);
3278            $self->{current_attribute}->{value} .= chr $code;
3279            $self->{current_attribute}->{has_reference} = 1;
3280            $self->{state} = $self->{prev_state};
3281            ## Reconsume.
3282            redo A;
3283          }
3284        } elsif ($self->{state} == ENTITY_NAME_STATE) {
3285          if (length $self->{state_keyword} < 30 and
3286              ## NOTE: Some number greater than the maximum length of entity name
3287              ((0x0041 <= $self->{next_char} and # a
3288                $self->{next_char} <= 0x005A) or # x
3289               (0x0061 <= $self->{next_char} and # a
3290                $self->{next_char} <= 0x007A) or # z
3291               (0x0030 <= $self->{next_char} and # 0
3292                $self->{next_char} <= 0x0039) or # 9
3293               $self->{next_char} == 0x003B)) { # ;
3294            our $EntityChar;
3295            $self->{state_keyword} .= chr $self->{next_char};
3296            if (defined $EntityChar->{$self->{state_keyword}}) {
3297              if ($self->{next_char} == 0x003B) { # ;
3298                !!!cp (1020);
3299                $self->{entity__value} = $EntityChar->{$self->{state_keyword}};
3300                $self->{entity__match} = 1;
3301                !!!next-input-character;
3302                #
3303              } else {
3304                !!!cp (1021);
3305                $self->{entity__value} = $EntityChar->{$self->{state_keyword}};
3306                $self->{entity__match} = -1;
3307                ## Stay in the state.
3308                !!!next-input-character;
3309                redo A;
3310              }
3311          } else {          } else {
3312            !!!cp (1021);            !!!cp (1022);
3313            $value = $EntityChar->{$entity_name};            $self->{entity__value} .= chr $self->{next_char};
3314            $match = -1;            $self->{entity__match} *= 2;
3315              ## Stay in the state.
3316            !!!next-input-character;            !!!next-input-character;
3317              redo A;
3318            }
3319          }
3320    
3321          my $data;
3322          my $has_ref;
3323          if ($self->{entity__match} > 0) {
3324            !!!cp (1023);
3325            $data = $self->{entity__value};
3326            $has_ref = 1;
3327            #
3328          } elsif ($self->{entity__match} < 0) {
3329            !!!parse-error (type => 'no refc');
3330            if ($self->{prev_state} != DATA_STATE and # in attribute
3331                $self->{entity__match} < -1) {
3332              !!!cp (1024);
3333              $data = '&' . $self->{state_keyword};
3334              #
3335            } else {
3336              !!!cp (1025);
3337              $data = $self->{entity__value};
3338              $has_ref = 1;
3339              #
3340          }          }
3341        } else {        } else {
3342          !!!cp (1022);          !!!cp (1026);
3343          $value .= chr $self->{next_char};          !!!parse-error (type => 'bare ero',
3344          $match *= 2;                          line => $self->{line_prev},
3345          !!!next-input-character;                          column => $self->{column_prev});
3346            $data = '&' . $self->{state_keyword};
3347            #
3348        }        }
3349      }    
3350              ## NOTE: In these cases, when a character reference is found,
3351      if ($match > 0) {        ## it is consumed and a character token is returned, or, otherwise,
3352        !!!cp (1023);        ## nothing is consumed and returned, according to the spec algorithm.
3353        return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,        ## In this implementation, anything that has been examined by the
3354                line => $l, column => $c,        ## tokenizer is appended to the parent element or the attribute value
3355               };        ## as string, either literal string when no character reference or
3356      } elsif ($match < 0) {        ## entity-replaced string otherwise, in this stage, since any characters
3357        !!!parse-error (type => 'no refc', line => $l, column => $c);        ## that would not be consumed are appended in the data state or in an
3358        if ($in_attr and $match < -1) {        ## appropriate attribute value state anyway.
3359          !!!cp (1024);  
3360          return {type => CHARACTER_TOKEN, data => '&'.$entity_name,        if ($self->{prev_state} == DATA_STATE) {
3361                  line => $l, column => $c,          !!!cp (986);
3362                 };          $self->{state} = $self->{prev_state};
3363        } else {          ## Reconsume.
3364          !!!cp (1025);          !!!emit ({type => CHARACTER_TOKEN,
3365          return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,                    data => $data,
3366                  line => $l, column => $c,                    line => $self->{line_prev},
3367                 };                    column => $self->{column_prev} + 1 - length $self->{state_keyword},
3368                     });
3369            redo A;
3370          } else {
3371            !!!cp (985);
3372            $self->{current_attribute}->{value} .= $data;
3373            $self->{current_attribute}->{has_reference} = 1 if $has_ref;
3374            $self->{state} = $self->{prev_state};
3375            ## Reconsume.
3376            redo A;
3377        }        }
3378      } else {      } else {
3379        !!!cp (1026);        die "$0: $self->{state}: Unknown state";
       !!!parse-error (type => 'bare ero', line => $l, column => $c);  
       ## NOTE: "No characters are consumed" in the spec.  
       return {type => CHARACTER_TOKEN, data => '&'.$value,  
               line => $l, column => $c,  
              };  
3380      }      }
3381    } else {    } # A  
3382      !!!cp (1027);  
3383      ## no characters are consumed    die "$0: _get_next_token: unexpected case";
3384      !!!parse-error (type => 'bare ero', line => $l, column => $c);  } # _get_next_token
     return undef;  
   }  
 } # _tokenize_attempt_to_consume_an_entity  
3385    
3386  sub _initialize_tree_constructor ($) {  sub _initialize_tree_constructor ($) {
3387    my $self = shift;    my $self = shift;
# Line 3050  sub _initialize_tree_constructor ($) { Line 3390  sub _initialize_tree_constructor ($) {
3390    ## TODO: Turn mutation events off # MUST    ## TODO: Turn mutation events off # MUST
3391    ## TODO: Turn loose Document option (manakai extension) on    ## TODO: Turn loose Document option (manakai extension) on
3392    $self->{document}->manakai_is_html (1); # MUST    $self->{document}->manakai_is_html (1); # MUST
3393      $self->{document}->set_user_data (manakai_source_line => 1);
3394      $self->{document}->set_user_data (manakai_source_column => 1);
3395  } # _initialize_tree_constructor  } # _initialize_tree_constructor
3396    
3397  sub _terminate_tree_constructor ($) {  sub _terminate_tree_constructor ($) {
# Line 3104  sub _tree_construction_initial ($) { Line 3446  sub _tree_construction_initial ($) {
3446        ## language.        ## language.
3447        my $doctype_name = $token->{name};        my $doctype_name = $token->{name};
3448        $doctype_name = '' unless defined $doctype_name;        $doctype_name = '' unless defined $doctype_name;
3449        $doctype_name =~ tr/a-z/A-Z/;        $doctype_name =~ tr/a-z/A-Z/; # ASCII case-insensitive
3450        if (not defined $token->{name} or # <!DOCTYPE>        if (not defined $token->{name} or # <!DOCTYPE>
           defined $token->{public_identifier} or  
3451            defined $token->{system_identifier}) {            defined $token->{system_identifier}) {
3452          !!!cp ('t1');          !!!cp ('t1');
3453          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3454        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
3455          !!!cp ('t2');          !!!cp ('t2');
         ## ISSUE: ASCII case-insensitive? (in fact it does not matter)  
3456          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3457          } elsif (defined $token->{public_identifier}) {
3458            if ($token->{public_identifier} eq 'XSLT-compat') {
3459              !!!cp ('t1.2');
3460              !!!parse-error (type => 'XSLT-compat', token => $token,
3461                              level => $self->{level}->{should});
3462            } else {
3463              !!!parse-error (type => 'not HTML5', token => $token);
3464            }
3465        } else {        } else {
3466          !!!cp ('t3');          !!!cp ('t3');
3467            #
3468        }        }
3469                
3470        my $doctype = $self->{document}->create_document_type_definition        my $doctype = $self->{document}->create_document_type_definition
# Line 3416  sub _reset_insertion_mode ($) { Line 3765  sub _reset_insertion_mode ($) {
3765          ## NOTE: Strictly spaking, the line below only applies to MathML and          ## NOTE: Strictly spaking, the line below only applies to MathML and
3766          ## SVG elements.  Currently the HTML syntax supports only MathML and          ## SVG elements.  Currently the HTML syntax supports only MathML and
3767          ## SVG elements as foreigners.          ## SVG elements as foreigners.
3768          $new_mode = $self->{insertion_mode} | IN_FOREIGN_CONTENT_IM;          $new_mode = IN_BODY_IM | IN_FOREIGN_CONTENT_IM;
         ## ISSUE: What is set as the secondary insertion mode?  
3769        } elsif ($node->[1] & TABLE_CELL_EL) {        } elsif ($node->[1] & TABLE_CELL_EL) {
3770          if ($last) {          if ($last) {
3771            !!!cp ('t28.2');            !!!cp ('t28.2');
# Line 3618  sub _tree_construction_main ($) { Line 3966  sub _tree_construction_main ($) {
3966        ## NOTE: An end-of-file token.        ## NOTE: An end-of-file token.
3967        if ($content_model_flag == CDATA_CONTENT_MODEL) {        if ($content_model_flag == CDATA_CONTENT_MODEL) {
3968          !!!cp ('t43');          !!!cp ('t43');
3969          !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in CDATA:#eof', token => $token);
3970        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
3971          !!!cp ('t44');          !!!cp ('t44');
3972          !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in RCDATA:#eof', token => $token);
3973        } else {        } else {
3974          die "$0: $content_model_flag in parse_rcdata";          die "$0: $content_model_flag in parse_rcdata";
3975        }        }
# Line 3658  sub _tree_construction_main ($) { Line 4006  sub _tree_construction_main ($) {
4006        ## Ignore the token        ## Ignore the token
4007      } else {      } else {
4008        !!!cp ('t48');        !!!cp ('t48');
4009        !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);        !!!parse-error (type => 'in CDATA:#eof', token => $token);
4010        ## ISSUE: And ignore?        ## ISSUE: And ignore?
4011        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
4012      }      }
# Line 3709  sub _tree_construction_main ($) { Line 4057  sub _tree_construction_main ($) {
4057        } # AFE        } # AFE
4058        unless (defined $formatting_element) {        unless (defined $formatting_element) {
4059          !!!cp ('t53');          !!!cp ('t53');
4060          !!!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);
4061          ## Ignore the token          ## Ignore the token
4062          !!!next-token;          !!!next-token;
4063          return;          return;
# Line 3726  sub _tree_construction_main ($) { Line 4074  sub _tree_construction_main ($) {
4074              last INSCOPE;              last INSCOPE;
4075            } else { # in open elements but not in scope            } else { # in open elements but not in scope
4076              !!!cp ('t55');              !!!cp ('t55');
4077              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},              !!!parse-error (type => 'unmatched end tag',
4078                                text => $token->{tag_name},
4079                              token => $end_tag_token);                              token => $end_tag_token);
4080              ## Ignore the token              ## Ignore the token
4081              !!!next-token;              !!!next-token;
# Line 3739  sub _tree_construction_main ($) { Line 4088  sub _tree_construction_main ($) {
4088        } # INSCOPE        } # INSCOPE
4089        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
4090          !!!cp ('t57');          !!!cp ('t57');
4091          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},          !!!parse-error (type => 'unmatched end tag',
4092                            text => $token->{tag_name},
4093                          token => $end_tag_token);                          token => $end_tag_token);
4094          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
4095          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
# Line 3748  sub _tree_construction_main ($) { Line 4098  sub _tree_construction_main ($) {
4098        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
4099          !!!cp ('t58');          !!!cp ('t58');
4100          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
4101                          value => $self->{open_elements}->[-1]->[0]                          text => $self->{open_elements}->[-1]->[0]
4102                              ->manakai_local_name,                              ->manakai_local_name,
4103                          token => $end_tag_token);                          token => $end_tag_token);
4104        }        }
# Line 3957  sub _tree_construction_main ($) { Line 4307  sub _tree_construction_main ($) {
4307    B: while (1) {    B: while (1) {
4308      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
4309        !!!cp ('t73');        !!!cp ('t73');
4310        !!!parse-error (type => 'DOCTYPE in the middle', token => $token);        !!!parse-error (type => 'in html:#DOCTYPE', token => $token);
4311        ## Ignore the token        ## Ignore the token
4312        ## Stay in the phase        ## Stay in the phase
4313        !!!next-token;        !!!next-token;
# Line 3966  sub _tree_construction_main ($) { Line 4316  sub _tree_construction_main ($) {
4316               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
4317        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
4318          !!!cp ('t79');          !!!cp ('t79');
4319          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4320          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
4321        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
4322          !!!cp ('t80');          !!!cp ('t80');
4323          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4324          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
4325        } else {        } else {
4326          !!!cp ('t81');          !!!cp ('t81');
# Line 4031  sub _tree_construction_main ($) { Line 4381  sub _tree_construction_main ($) {
4381                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
4382            !!!cp ('t87.2');            !!!cp ('t87.2');
4383            !!!parse-error (type => 'not closed',            !!!parse-error (type => 'not closed',
4384                            value => $self->{open_elements}->[-1]->[0]                            text => $self->{open_elements}->[-1]->[0]
4385                                ->manakai_local_name,                                ->manakai_local_name,
4386                            token => $token);                            token => $token);
4387    
# Line 4109  sub _tree_construction_main ($) { Line 4459  sub _tree_construction_main ($) {
4459        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
4460          !!!cp ('t87.6');          !!!cp ('t87.6');
4461          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
4462                          value => $self->{open_elements}->[-1]->[0]                          text => $self->{open_elements}->[-1]->[0]
4463                              ->manakai_local_name,                              ->manakai_local_name,
4464                          token => $token);                          token => $token);
4465    
# Line 4159  sub _tree_construction_main ($) { Line 4509  sub _tree_construction_main ($) {
4509            !!!cp ('t90');            !!!cp ('t90');
4510            ## As if </noscript>            ## As if </noscript>
4511            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
4512            !!!parse-error (type => 'in noscript:#character', token => $token);            !!!parse-error (type => 'in noscript:#text', token => $token);
4513                        
4514            ## Reprocess in the "in head" insertion mode...            ## Reprocess in the "in head" insertion mode...
4515            ## As if </head>            ## As if </head>
# Line 4196  sub _tree_construction_main ($) { Line 4546  sub _tree_construction_main ($) {
4546              next B;              next B;
4547            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4548              !!!cp ('t93.2');              !!!cp ('t93.2');
4549              !!!parse-error (type => 'after head:head', token => $token); ## TODO: error type              !!!parse-error (type => 'after head', text => 'head',
4550                                token => $token);
4551              ## Ignore the token              ## Ignore the token
4552              !!!nack ('t93.3');              !!!nack ('t93.3');
4553              !!!next-token;              !!!next-token;
4554              next B;              next B;
4555            } else {            } else {
4556              !!!cp ('t95');              !!!cp ('t95');
4557              !!!parse-error (type => 'in head:head', token => $token); # or in head noscript              !!!parse-error (type => 'in head:head',
4558                                token => $token); # or in head noscript
4559              ## Ignore the token              ## Ignore the token
4560              !!!nack ('t95.1');              !!!nack ('t95.1');
4561              !!!next-token;              !!!next-token;
# Line 4228  sub _tree_construction_main ($) { Line 4580  sub _tree_construction_main ($) {
4580                  !!!cp ('t98');                  !!!cp ('t98');
4581                  ## As if </noscript>                  ## As if </noscript>
4582                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4583                  !!!parse-error (type => 'in noscript:base', token => $token);                  !!!parse-error (type => 'in noscript', text => 'base',
4584                                    token => $token);
4585                                
4586                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4587                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
# Line 4239  sub _tree_construction_main ($) { Line 4592  sub _tree_construction_main ($) {
4592                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4593                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4594                  !!!cp ('t100');                  !!!cp ('t100');
4595                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4596                                    text => $token->{tag_name}, token => $token);
4597                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4598                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4599                } else {                } else {
# Line 4256  sub _tree_construction_main ($) { Line 4610  sub _tree_construction_main ($) {
4610                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4611                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4612                  !!!cp ('t102');                  !!!cp ('t102');
4613                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4614                                    text => $token->{tag_name}, token => $token);
4615                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4616                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4617                } else {                } else {
# Line 4273  sub _tree_construction_main ($) { Line 4628  sub _tree_construction_main ($) {
4628                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4629                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4630                  !!!cp ('t104');                  !!!cp ('t104');
4631                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4632                                    text => $token->{tag_name}, token => $token);
4633                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4634                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4635                } else {                } else {
# Line 4342  sub _tree_construction_main ($) { Line 4698  sub _tree_construction_main ($) {
4698                  !!!cp ('t111');                  !!!cp ('t111');
4699                  ## As if </noscript>                  ## As if </noscript>
4700                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4701                  !!!parse-error (type => 'in noscript:title', token => $token);                  !!!parse-error (type => 'in noscript', text => 'title',
4702                                    token => $token);
4703                                
4704                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4705                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4706                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4707                  !!!cp ('t112');                  !!!cp ('t112');
4708                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4709                                    text => $token->{tag_name}, token => $token);
4710                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4711                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4712                } else {                } else {
# Line 4362  sub _tree_construction_main ($) { Line 4720  sub _tree_construction_main ($) {
4720                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4721                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4722                next B;                next B;
4723              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style' or
4724                         $token->{tag_name} eq 'noframes') {
4725                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and
4726                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
4727                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4728                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4729                  !!!cp ('t114');                  !!!cp ('t114');
4730                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4731                                    text => $token->{tag_name}, token => $token);
4732                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4733                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4734                } else {                } else {
# Line 4389  sub _tree_construction_main ($) { Line 4749  sub _tree_construction_main ($) {
4749                  next B;                  next B;
4750                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4751                  !!!cp ('t117');                  !!!cp ('t117');
4752                  !!!parse-error (type => 'in noscript:noscript', token => $token);                  !!!parse-error (type => 'in noscript', text => 'noscript',
4753                                    token => $token);
4754                  ## Ignore the token                  ## Ignore the token
4755                  !!!nack ('t117.1');                  !!!nack ('t117.1');
4756                  !!!next-token;                  !!!next-token;
# Line 4403  sub _tree_construction_main ($) { Line 4764  sub _tree_construction_main ($) {
4764                  !!!cp ('t119');                  !!!cp ('t119');
4765                  ## As if </noscript>                  ## As if </noscript>
4766                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4767                  !!!parse-error (type => 'in noscript:script', token => $token);                  !!!parse-error (type => 'in noscript', text => 'script',
4768                                    token => $token);
4769                                
4770                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4771                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4772                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4773                  !!!cp ('t120');                  !!!cp ('t120');
4774                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4775                                    text => $token->{tag_name}, token => $token);
4776                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4777                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4778                } else {                } else {
# Line 4427  sub _tree_construction_main ($) { Line 4790  sub _tree_construction_main ($) {
4790                  !!!cp ('t122');                  !!!cp ('t122');
4791                  ## As if </noscript>                  ## As if </noscript>
4792                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4793                  !!!parse-error (type => 'in noscript:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in noscript',
4794                                    text => $token->{tag_name}, token => $token);
4795                                    
4796                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4797                  ## As if </head>                  ## As if </head>
# Line 4466  sub _tree_construction_main ($) { Line 4830  sub _tree_construction_main ($) {
4830                !!!cp ('t129');                !!!cp ('t129');
4831                ## As if </noscript>                ## As if </noscript>
4832                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4833                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4834                                  text => $token->{tag_name}, token => $token);
4835                                
4836                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4837                ## As if </head>                ## As if </head>
# Line 4509  sub _tree_construction_main ($) { Line 4874  sub _tree_construction_main ($) {
4874                  !!!cp ('t133');                  !!!cp ('t133');
4875                  ## As if </noscript>                  ## As if </noscript>
4876                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4877                  !!!parse-error (type => 'in noscript:/head', token => $token);                  !!!parse-error (type => 'in noscript:/',
4878                                    text => 'head', token => $token);
4879                                    
4880                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4881                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 4524  sub _tree_construction_main ($) { Line 4890  sub _tree_construction_main ($) {
4890                  next B;                  next B;
4891                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4892                  !!!cp ('t134.1');                  !!!cp ('t134.1');
4893                  !!!parse-error (type => 'unmatched end tag:head', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'head',
4894                                    token => $token);
4895                  ## Ignore the token                  ## Ignore the token
4896                  !!!next-token;                  !!!next-token;
4897                  next B;                  next B;
# Line 4541  sub _tree_construction_main ($) { Line 4908  sub _tree_construction_main ($) {
4908                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or
4909                         $self->{insertion_mode} == AFTER_HEAD_IM) {                         $self->{insertion_mode} == AFTER_HEAD_IM) {
4910                  !!!cp ('t137');                  !!!cp ('t137');
4911                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4912                                    text => 'noscript', token => $token);
4913                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
4914                  !!!next-token;                  !!!next-token;
4915                  next B;                  next B;
# Line 4556  sub _tree_construction_main ($) { Line 4924  sub _tree_construction_main ($) {
4924                    $self->{insertion_mode} == IN_HEAD_IM or                    $self->{insertion_mode} == IN_HEAD_IM or
4925                    $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                    $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4926                  !!!cp ('t140');                  !!!cp ('t140');
4927                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4928                                    text => $token->{tag_name}, token => $token);
4929                  ## Ignore the token                  ## Ignore the token
4930                  !!!next-token;                  !!!next-token;
4931                  next B;                  next B;
4932                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4933                  !!!cp ('t140.1');                  !!!cp ('t140.1');
4934                  !!!parse-error (type => 'unmatched end tag:' . $token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4935                                    text => $token->{tag_name}, token => $token);
4936                  ## Ignore the token                  ## Ignore the token
4937                  !!!next-token;                  !!!next-token;
4938                  next B;                  next B;
# Line 4571  sub _tree_construction_main ($) { Line 4941  sub _tree_construction_main ($) {
4941                }                }
4942              } elsif ($token->{tag_name} eq 'p') {              } elsif ($token->{tag_name} eq 'p') {
4943                !!!cp ('t142');                !!!cp ('t142');
4944                !!!parse-error (type => 'unmatched end tag:p', token => $token);                !!!parse-error (type => 'unmatched end tag',
4945                                  text => $token->{tag_name}, token => $token);
4946                ## Ignore the token                ## Ignore the token
4947                !!!next-token;                !!!next-token;
4948                next B;                next B;
# Line 4594  sub _tree_construction_main ($) { Line 4965  sub _tree_construction_main ($) {
4965                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4966                  !!!cp ('t143.3');                  !!!cp ('t143.3');
4967                  ## ISSUE: Two parse errors for <head><noscript></br>                  ## ISSUE: Two parse errors for <head><noscript></br>
4968                  !!!parse-error (type => 'unmatched end tag:br', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4969                                    text => 'br', token => $token);
4970                  ## As if </noscript>                  ## As if </noscript>
4971                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4972                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
# Line 4613  sub _tree_construction_main ($) { Line 4985  sub _tree_construction_main ($) {
4985                }                }
4986    
4987                ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.                ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.
4988                !!!parse-error (type => 'unmatched end tag:br', token => $token);                !!!parse-error (type => 'unmatched end tag',
4989                                  text => 'br', token => $token);
4990                ## Ignore the token                ## Ignore the token
4991                !!!next-token;                !!!next-token;
4992                next B;                next B;
4993              } else {              } else {
4994                !!!cp ('t145');                !!!cp ('t145');
4995                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
4996                                  text => $token->{tag_name}, token => $token);
4997                ## Ignore the token                ## Ignore the token
4998                !!!next-token;                !!!next-token;
4999                next B;                next B;
# Line 4629  sub _tree_construction_main ($) { Line 5003  sub _tree_construction_main ($) {
5003                !!!cp ('t146');                !!!cp ('t146');
5004                ## As if </noscript>                ## As if </noscript>
5005                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5006                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
5007                                  text => $token->{tag_name}, token => $token);
5008                                
5009                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
5010                ## As if </head>                ## As if </head>
# Line 4645  sub _tree_construction_main ($) { Line 5020  sub _tree_construction_main ($) {
5020              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
5021  ## ISSUE: This case cannot be reached?  ## ISSUE: This case cannot be reached?
5022                !!!cp ('t148');                !!!cp ('t148');
5023                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
5024                                  text => $token->{tag_name}, token => $token);
5025                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
5026                !!!next-token;                !!!next-token;
5027                next B;                next B;
# Line 4756  sub _tree_construction_main ($) { Line 5132  sub _tree_construction_main ($) {
5132    
5133                  !!!cp ('t153');                  !!!cp ('t153');
5134                  !!!parse-error (type => 'start tag not allowed',                  !!!parse-error (type => 'start tag not allowed',
5135                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
5136                  ## Ignore the token                  ## Ignore the token
5137                  !!!nack ('t153.1');                  !!!nack ('t153.1');
5138                  !!!next-token;                  !!!next-token;
5139                  next B;                  next B;
5140                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
5141                  !!!parse-error (type => 'not closed:caption', token => $token);                  !!!parse-error (type => 'not closed', text => 'caption',
5142                                    token => $token);
5143                                    
5144                  ## NOTE: As if </caption>.                  ## NOTE: As if </caption>.
5145                  ## have a table element in table scope                  ## have a table element in table scope
# Line 4782  sub _tree_construction_main ($) { Line 5159  sub _tree_construction_main ($) {
5159    
5160                    !!!cp ('t157');                    !!!cp ('t157');
5161                    !!!parse-error (type => 'start tag not allowed',                    !!!parse-error (type => 'start tag not allowed',
5162                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
5163                    ## Ignore the token                    ## Ignore the token
5164                    !!!nack ('t157.1');                    !!!nack ('t157.1');
5165                    !!!next-token;                    !!!next-token;
# Line 4799  sub _tree_construction_main ($) { Line 5176  sub _tree_construction_main ($) {
5176                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5177                    !!!cp ('t159');                    !!!cp ('t159');
5178                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5179                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5180                                        ->manakai_local_name,                                        ->manakai_local_name,
5181                                    token => $token);                                    token => $token);
5182                  } else {                  } else {
# Line 4841  sub _tree_construction_main ($) { Line 5218  sub _tree_construction_main ($) {
5218                  } # INSCOPE                  } # INSCOPE
5219                    unless (defined $i) {                    unless (defined $i) {
5220                      !!!cp ('t165');                      !!!cp ('t165');
5221                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5222                                        text => $token->{tag_name},
5223                                        token => $token);
5224                      ## Ignore the token                      ## Ignore the token
5225                      !!!next-token;                      !!!next-token;
5226                      next B;                      next B;
# Line 4858  sub _tree_construction_main ($) { Line 5237  sub _tree_construction_main ($) {
5237                          ne $token->{tag_name}) {                          ne $token->{tag_name}) {
5238                    !!!cp ('t167');                    !!!cp ('t167');
5239                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5240                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5241                                        ->manakai_local_name,                                        ->manakai_local_name,
5242                                    token => $token);                                    token => $token);
5243                  } else {                  } else {
# Line 4875  sub _tree_construction_main ($) { Line 5254  sub _tree_construction_main ($) {
5254                  next B;                  next B;
5255                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
5256                  !!!cp ('t169');                  !!!cp ('t169');
5257                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5258                                    text => $token->{tag_name}, token => $token);
5259                  ## Ignore the token                  ## Ignore the token
5260                  !!!next-token;                  !!!next-token;
5261                  next B;                  next B;
# Line 4902  sub _tree_construction_main ($) { Line 5282  sub _tree_construction_main ($) {
5282    
5283                    !!!cp ('t173');                    !!!cp ('t173');
5284                    !!!parse-error (type => 'unmatched end tag',                    !!!parse-error (type => 'unmatched end tag',
5285                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
5286                    ## Ignore the token                    ## Ignore the token
5287                    !!!next-token;                    !!!next-token;
5288                    next B;                    next B;
# Line 4918  sub _tree_construction_main ($) { Line 5298  sub _tree_construction_main ($) {
5298                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5299                    !!!cp ('t175');                    !!!cp ('t175');
5300                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5301                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5302                                        ->manakai_local_name,                                        ->manakai_local_name,
5303                                    token => $token);                                    token => $token);
5304                  } else {                  } else {
# Line 4935  sub _tree_construction_main ($) { Line 5315  sub _tree_construction_main ($) {
5315                  next B;                  next B;
5316                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
5317                  !!!cp ('t177');                  !!!cp ('t177');
5318                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5319                                    text => $token->{tag_name}, token => $token);
5320                  ## Ignore the token                  ## Ignore the token
5321                  !!!next-token;                  !!!next-token;
5322                  next B;                  next B;
# Line 4978  sub _tree_construction_main ($) { Line 5359  sub _tree_construction_main ($) {
5359    
5360                  !!!cp ('t182');                  !!!cp ('t182');
5361                  !!!parse-error (type => 'unmatched end tag',                  !!!parse-error (type => 'unmatched end tag',
5362                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
5363                  ## Ignore the token                  ## Ignore the token
5364                  !!!next-token;                  !!!next-token;
5365                  next B;                  next B;
5366                } # INSCOPE                } # INSCOPE
5367              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
5368                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5369                !!!parse-error (type => 'not closed:caption', token => $token);                !!!parse-error (type => 'not closed', text => 'caption',
5370                                  token => $token);
5371    
5372                ## As if </caption>                ## As if </caption>
5373                ## have a table element in table scope                ## have a table element in table scope
# Line 5003  sub _tree_construction_main ($) { Line 5385  sub _tree_construction_main ($) {
5385                } # INSCOPE                } # INSCOPE
5386                unless (defined $i) {                unless (defined $i) {
5387                  !!!cp ('t186');                  !!!cp ('t186');
5388                  !!!parse-error (type => 'unmatched end tag:caption', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5389                                    text => 'caption', token => $token);
5390                  ## Ignore the token                  ## Ignore the token
5391                  !!!next-token;                  !!!next-token;
5392                  next B;                  next B;
# Line 5018  sub _tree_construction_main ($) { Line 5401  sub _tree_construction_main ($) {
5401                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5402                  !!!cp ('t188');                  !!!cp ('t188');
5403                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5404                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5405                                      ->manakai_local_name,                                      ->manakai_local_name,
5406                                  token => $token);                                  token => $token);
5407                } else {                } else {
# Line 5038  sub _tree_construction_main ($) { Line 5421  sub _tree_construction_main ($) {
5421                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5422                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
5423                  !!!cp ('t190');                  !!!cp ('t190');
5424                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5425                                    text => $token->{tag_name}, token => $token);
5426                  ## Ignore the token                  ## Ignore the token
5427                  !!!next-token;                  !!!next-token;
5428                  next B;                  next B;
# Line 5052  sub _tree_construction_main ($) { Line 5436  sub _tree_construction_main ($) {
5436                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
5437                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5438                !!!cp ('t192');                !!!cp ('t192');
5439                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
5440                                  text => $token->{tag_name}, token => $token);
5441                ## Ignore the token                ## Ignore the token
5442                !!!next-token;                !!!next-token;
5443                next B;                next B;
# Line 5092  sub _tree_construction_main ($) { Line 5477  sub _tree_construction_main ($) {
5477            }            }
5478          }          }
5479    
5480              !!!parse-error (type => 'in table:#character', token => $token);          !!!parse-error (type => 'in table:#text', token => $token);
5481    
5482              ## As if in body, but insert into foster parent element              ## As if in body, but insert into foster parent element
5483              ## ISSUE: Spec says that "whenever a node would be inserted              ## ISSUE: Spec says that "whenever a node would be inserted
# Line 5143  sub _tree_construction_main ($) { Line 5528  sub _tree_construction_main ($) {
5528          !!!next-token;          !!!next-token;
5529          next B;          next B;
5530        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5531              if ({          if ({
5532                   tr => ($self->{insertion_mode} != IN_ROW_IM),               tr => ($self->{insertion_mode} != IN_ROW_IM),
5533                   th => 1, td => 1,               th => 1, td => 1,
5534                  }->{$token->{tag_name}}) {              }->{$token->{tag_name}}) {
5535                if ($self->{insertion_mode} == IN_TABLE_IM) {            if ($self->{insertion_mode} == IN_TABLE_IM) {
5536                  ## Clear back to table context              ## Clear back to table context
5537                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5538                                  & TABLE_SCOPING_EL)) {                              & TABLE_SCOPING_EL)) {
5539                    !!!cp ('t201');                !!!cp ('t201');
5540                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5541                  }              }
5542                                
5543                  !!!insert-element ('tbody',, $token);              !!!insert-element ('tbody',, $token);
5544                  $self->{insertion_mode} = IN_TABLE_BODY_IM;              $self->{insertion_mode} = IN_TABLE_BODY_IM;
5545                  ## reprocess in the "in table body" insertion mode...              ## reprocess in the "in table body" insertion mode...
5546                }            }
5547              
5548                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {            if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
5549                  unless ($token->{tag_name} eq 'tr') {              unless ($token->{tag_name} eq 'tr') {
5550                    !!!cp ('t202');                !!!cp ('t202');
5551                    !!!parse-error (type => 'missing start tag:tr', token => $token);                !!!parse-error (type => 'missing start tag:tr', token => $token);
5552                  }              }
5553                                    
5554                  ## Clear back to table body context              ## Clear back to table body context
5555                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5556                                  & TABLE_ROWS_SCOPING_EL)) {                              & TABLE_ROWS_SCOPING_EL)) {
5557                    !!!cp ('t203');                !!!cp ('t203');
5558                    ## ISSUE: Can this case be reached?                ## ISSUE: Can this case be reached?
5559                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5560                  }              }
5561                                    
5562                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
5563                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
# Line 5228  sub _tree_construction_main ($) { Line 5613  sub _tree_construction_main ($) {
5613                  unless (defined $i) {                  unless (defined $i) {
5614                    !!!cp ('t210');                    !!!cp ('t210');
5615  ## TODO: This type is wrong.  ## TODO: This type is wrong.
5616                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmacthed end tag',
5617                                      text => $token->{tag_name}, token => $token);
5618                    ## Ignore the token                    ## Ignore the token
5619                    !!!nack ('t210.1');                    !!!nack ('t210.1');
5620                    !!!next-token;                    !!!next-token;
# Line 5272  sub _tree_construction_main ($) { Line 5658  sub _tree_construction_main ($) {
5658                  } # INSCOPE                  } # INSCOPE
5659                  unless (defined $i) {                  unless (defined $i) {
5660                    !!!cp ('t216');                    !!!cp ('t216');
5661  ## TODO: This erorr type ios wrong.  ## TODO: This erorr type is wrong.
5662                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5663                                      text => $token->{tag_name}, token => $token);
5664                    ## Ignore the token                    ## Ignore the token
5665                    !!!nack ('t216.1');                    !!!nack ('t216.1');
5666                    !!!next-token;                    !!!next-token;
# Line 5348  sub _tree_construction_main ($) { Line 5735  sub _tree_construction_main ($) {
5735                }                }
5736              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
5737                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
5738                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
5739                                    ->manakai_local_name,                                    ->manakai_local_name,
5740                                token => $token);                                token => $token);
5741    
# Line 5369  sub _tree_construction_main ($) { Line 5756  sub _tree_construction_main ($) {
5756                unless (defined $i) {                unless (defined $i) {
5757                  !!!cp ('t223');                  !!!cp ('t223');
5758  ## TODO: The following is wrong, maybe.  ## TODO: The following is wrong, maybe.
5759                  !!!parse-error (type => 'unmatched end tag:table', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'table',
5760                                    token => $token);
5761                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
5762                  !!!nack ('t223.1');                  !!!nack ('t223.1');
5763                  !!!next-token;                  !!!next-token;
5764                  next B;                  next B;
5765                }                }
5766                                
5767  ## TODO: Followings are removed from the latest spec.  ## TODO: Followings are removed from the latest spec.
5768                ## generate implied end tags                ## generate implied end tags
5769                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
5770                  !!!cp ('t224');                  !!!cp ('t224');
# Line 5387  sub _tree_construction_main ($) { Line 5775  sub _tree_construction_main ($) {
5775                  !!!cp ('t225');                  !!!cp ('t225');
5776                  ## NOTE: |<table><tr><table>|                  ## NOTE: |<table><tr><table>|
5777                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5778                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5779                                      ->manakai_local_name,                                      ->manakai_local_name,
5780                                  token => $token);                                  token => $token);
5781                } else {                } else {
# Line 5428  sub _tree_construction_main ($) { Line 5816  sub _tree_construction_main ($) {
5816                my $type = lc $token->{attributes}->{type}->{value};                my $type = lc $token->{attributes}->{type}->{value};
5817                if ($type eq 'hidden') {                if ($type eq 'hidden') {
5818                  !!!cp ('t227.3');                  !!!cp ('t227.3');
5819                  !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in table',
5820                                    text => $token->{tag_name}, token => $token);
5821    
5822                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5823    
# Line 5456  sub _tree_construction_main ($) { Line 5845  sub _tree_construction_main ($) {
5845            #            #
5846          }          }
5847    
5848          !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in table', text => $token->{tag_name},
5849                            token => $token);
5850    
5851          $insert = $insert_to_foster;          $insert = $insert_to_foster;
5852          #          #
# Line 5478  sub _tree_construction_main ($) { Line 5868  sub _tree_construction_main ($) {
5868                } # INSCOPE                } # INSCOPE
5869                unless (defined $i) {                unless (defined $i) {
5870                  !!!cp ('t230');                  !!!cp ('t230');
5871                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5872                                    text => $token->{tag_name}, token => $token);
5873                  ## Ignore the token                  ## Ignore the token
5874                  !!!nack ('t230.1');                  !!!nack ('t230.1');
5875                  !!!next-token;                  !!!next-token;
# Line 5519  sub _tree_construction_main ($) { Line 5910  sub _tree_construction_main ($) {
5910                  unless (defined $i) {                  unless (defined $i) {
5911                    !!!cp ('t235');                    !!!cp ('t235');
5912  ## TODO: The following is wrong.  ## TODO: The following is wrong.
5913                    !!!parse-error (type => 'unmatched end tag:'.$token->{type}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5914                                      text => $token->{type}, token => $token);
5915                    ## Ignore the token                    ## Ignore the token
5916                    !!!nack ('t236.1');                    !!!nack ('t236.1');
5917                    !!!next-token;                    !!!next-token;
# Line 5555  sub _tree_construction_main ($) { Line 5947  sub _tree_construction_main ($) {
5947                  } # INSCOPE                  } # INSCOPE
5948                  unless (defined $i) {                  unless (defined $i) {
5949                    !!!cp ('t239');                    !!!cp ('t239');
5950                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5951                                      text => $token->{tag_name}, token => $token);
5952                    ## Ignore the token                    ## Ignore the token
5953                    !!!nack ('t239.1');                    !!!nack ('t239.1');
5954                    !!!next-token;                    !!!next-token;
# Line 5601  sub _tree_construction_main ($) { Line 5994  sub _tree_construction_main ($) {
5994                } # INSCOPE                } # INSCOPE
5995                unless (defined $i) {                unless (defined $i) {
5996                  !!!cp ('t243');                  !!!cp ('t243');
5997                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5998                                    text => $token->{tag_name}, token => $token);
5999                  ## Ignore the token                  ## Ignore the token
6000                  !!!nack ('t243.1');                  !!!nack ('t243.1');
6001                  !!!next-token;                  !!!next-token;
# Line 5635  sub _tree_construction_main ($) { Line 6029  sub _tree_construction_main ($) {
6029                  } # INSCOPE                  } # INSCOPE
6030                    unless (defined $i) {                    unless (defined $i) {
6031                      !!!cp ('t249');                      !!!cp ('t249');
6032                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
6033                                        text => $token->{tag_name}, token => $token);
6034                      ## Ignore the token                      ## Ignore the token
6035                      !!!nack ('t249.1');                      !!!nack ('t249.1');
6036                      !!!next-token;                      !!!next-token;
# Line 5658  sub _tree_construction_main ($) { Line 6053  sub _tree_construction_main ($) {
6053                  } # INSCOPE                  } # INSCOPE
6054                    unless (defined $i) {                    unless (defined $i) {
6055                      !!!cp ('t252');                      !!!cp ('t252');
6056                      !!!parse-error (type => 'unmatched end tag:tr', token => $token);                      !!!parse-error (type => 'unmatched end tag',
6057                                        text => 'tr', token => $token);
6058                      ## Ignore the token                      ## Ignore the token
6059                      !!!nack ('t252.1');                      !!!nack ('t252.1');
6060                      !!!next-token;                      !!!next-token;
# Line 5693  sub _tree_construction_main ($) { Line 6089  sub _tree_construction_main ($) {
6089                } # INSCOPE                } # INSCOPE
6090                unless (defined $i) {                unless (defined $i) {
6091                  !!!cp ('t256');                  !!!cp ('t256');
6092                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
6093                                    text => $token->{tag_name}, token => $token);
6094                  ## Ignore the token                  ## Ignore the token
6095                  !!!nack ('t256.1');                  !!!nack ('t256.1');
6096                  !!!next-token;                  !!!next-token;
# Line 5720  sub _tree_construction_main ($) { Line 6117  sub _tree_construction_main ($) {
6117                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
6118                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
6119            !!!cp ('t258');            !!!cp ('t258');
6120            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
6121                              text => $token->{tag_name}, token => $token);
6122            ## Ignore the token            ## Ignore the token
6123            !!!nack ('t258.1');            !!!nack ('t258.1');
6124             !!!next-token;             !!!next-token;
6125            next B;            next B;
6126          } else {          } else {
6127            !!!cp ('t259');            !!!cp ('t259');
6128            !!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in table:/',
6129                              text => $token->{tag_name}, token => $token);
6130    
6131            $insert = $insert_to_foster;            $insert = $insert_to_foster;
6132            #            #
# Line 5777  sub _tree_construction_main ($) { Line 6176  sub _tree_construction_main ($) {
6176              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
6177                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
6178                  !!!cp ('t264');                  !!!cp ('t264');
6179                  !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);                  !!!parse-error (type => 'unmatched end tag',
6180                                    text => 'colgroup', token => $token);
6181                  ## Ignore the token                  ## Ignore the token
6182                  !!!next-token;                  !!!next-token;
6183                  next B;                  next B;
# Line 5790  sub _tree_construction_main ($) { Line 6190  sub _tree_construction_main ($) {
6190                }                }
6191              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
6192                !!!cp ('t266');                !!!cp ('t266');
6193                !!!parse-error (type => 'unmatched end tag:col', token => $token);                !!!parse-error (type => 'unmatched end tag',
6194                                  text => 'col', token => $token);
6195                ## Ignore the token                ## Ignore the token
6196                !!!next-token;                !!!next-token;
6197                next B;                next B;
# Line 5820  sub _tree_construction_main ($) { Line 6221  sub _tree_construction_main ($) {
6221            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
6222              !!!cp ('t269');              !!!cp ('t269');
6223  ## TODO: Wrong error type?  ## TODO: Wrong error type?
6224              !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);              !!!parse-error (type => 'unmatched end tag',
6225                                text => 'colgroup', token => $token);
6226              ## Ignore the token              ## Ignore the token
6227              !!!nack ('t269.1');              !!!nack ('t269.1');
6228              !!!next-token;              !!!next-token;
# Line 5884  sub _tree_construction_main ($) { Line 6286  sub _tree_construction_main ($) {
6286                     tr => 1, td => 1, th => 1,                     tr => 1, td => 1, th => 1,
6287                    }->{$token->{tag_name}})) {                    }->{$token->{tag_name}})) {
6288            ## TODO: The type below is not good - <select> is replaced by </select>            ## TODO: The type below is not good - <select> is replaced by </select>
6289            !!!parse-error (type => 'not closed:select', token => $token);            !!!parse-error (type => 'not closed', text => 'select',
6290                              token => $token);
6291            ## NOTE: As if the token were </select> (<select> case) or            ## NOTE: As if the token were </select> (<select> case) or
6292            ## as if there were </select> (otherwise).            ## as if there were </select> (otherwise).
6293            ## have an element in table scope            ## have an element in table scope
# Line 5902  sub _tree_construction_main ($) { Line 6305  sub _tree_construction_main ($) {
6305            } # INSCOPE            } # INSCOPE
6306            unless (defined $i) {            unless (defined $i) {
6307              !!!cp ('t280');              !!!cp ('t280');
6308              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6309                                text => 'select', token => $token);
6310              ## Ignore the token              ## Ignore the token
6311              !!!nack ('t280.1');              !!!nack ('t280.1');
6312              !!!next-token;              !!!next-token;
# Line 5926  sub _tree_construction_main ($) { Line 6330  sub _tree_construction_main ($) {
6330            }            }
6331          } else {          } else {
6332            !!!cp ('t282');            !!!cp ('t282');
6333            !!!parse-error (type => 'in select:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select',
6334                              text => $token->{tag_name}, token => $token);
6335            ## Ignore the token            ## Ignore the token
6336            !!!nack ('t282.1');            !!!nack ('t282.1');
6337            !!!next-token;            !!!next-token;
# Line 5944  sub _tree_construction_main ($) { Line 6349  sub _tree_construction_main ($) {
6349              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6350            } else {            } else {
6351              !!!cp ('t285');              !!!cp ('t285');
6352              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6353                                text => $token->{tag_name}, token => $token);
6354              ## Ignore the token              ## Ignore the token
6355            }            }
6356            !!!nack ('t285.1');            !!!nack ('t285.1');
# Line 5956  sub _tree_construction_main ($) { Line 6362  sub _tree_construction_main ($) {
6362              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6363            } else {            } else {
6364              !!!cp ('t287');              !!!cp ('t287');
6365              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6366                                text => $token->{tag_name}, token => $token);
6367              ## Ignore the token              ## Ignore the token
6368            }            }
6369            !!!nack ('t287.1');            !!!nack ('t287.1');
# Line 5978  sub _tree_construction_main ($) { Line 6385  sub _tree_construction_main ($) {
6385            } # INSCOPE            } # INSCOPE
6386            unless (defined $i) {            unless (defined $i) {
6387              !!!cp ('t290');              !!!cp ('t290');
6388              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6389                                text => $token->{tag_name}, token => $token);
6390              ## Ignore the token              ## Ignore the token
6391              !!!nack ('t290.1');              !!!nack ('t290.1');
6392              !!!next-token;              !!!next-token;
# Line 5999  sub _tree_construction_main ($) { Line 6407  sub _tree_construction_main ($) {
6407                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
6408                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
6409  ## TODO: The following is wrong?  ## TODO: The following is wrong?
6410            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
6411                              text => $token->{tag_name}, token => $token);
6412                                
6413            ## have an element in table scope            ## have an element in table scope
6414            my $i;            my $i;
# Line 6040  sub _tree_construction_main ($) { Line 6449  sub _tree_construction_main ($) {
6449            unless (defined $i) {            unless (defined $i) {
6450              !!!cp ('t297');              !!!cp ('t297');
6451  ## TODO: The following error type is correct?  ## TODO: The following error type is correct?
6452              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6453                                text => 'select', token => $token);
6454              ## Ignore the </select> token              ## Ignore the </select> token
6455              !!!nack ('t297.1');              !!!nack ('t297.1');
6456              !!!next-token; ## TODO: ok?              !!!next-token; ## TODO: ok?
# Line 6057  sub _tree_construction_main ($) { Line 6467  sub _tree_construction_main ($) {
6467            next B;            next B;
6468          } else {          } else {
6469            !!!cp ('t299');            !!!cp ('t299');
6470            !!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select:/',
6471                              text => $token->{tag_name}, token => $token);
6472            ## Ignore the token            ## Ignore the token
6473            !!!nack ('t299.3');            !!!nack ('t299.3');
6474            !!!next-token;            !!!next-token;
# Line 6095  sub _tree_construction_main ($) { Line 6506  sub _tree_construction_main ($) {
6506                    
6507          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6508            !!!cp ('t301');            !!!cp ('t301');
6509            !!!parse-error (type => 'after html:#character', token => $token);            !!!parse-error (type => 'after html:#text', token => $token);
6510    
6511            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6512          } else {          } else {
# Line 6103  sub _tree_construction_main ($) { Line 6514  sub _tree_construction_main ($) {
6514          }          }
6515                    
6516          ## "after body" insertion mode          ## "after body" insertion mode
6517          !!!parse-error (type => 'after body:#character', token => $token);          !!!parse-error (type => 'after body:#text', token => $token);
6518    
6519          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6520          ## reprocess          ## reprocess
# Line 6111  sub _tree_construction_main ($) { Line 6522  sub _tree_construction_main ($) {
6522        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
6523          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6524            !!!cp ('t303');            !!!cp ('t303');
6525            !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html',
6526                              text => $token->{tag_name}, token => $token);
6527                        
6528            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6529          } else {          } else {
# Line 6119  sub _tree_construction_main ($) { Line 6531  sub _tree_construction_main ($) {
6531          }          }
6532    
6533          ## "after body" insertion mode          ## "after body" insertion mode
6534          !!!parse-error (type => 'after body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'after body',
6535                            text => $token->{tag_name}, token => $token);
6536    
6537          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6538          !!!ack-later;          !!!ack-later;
# Line 6128  sub _tree_construction_main ($) { Line 6541  sub _tree_construction_main ($) {
6541        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6542          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6543            !!!cp ('t305');            !!!cp ('t305');
6544            !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html:/',
6545                              text => $token->{tag_name}, token => $token);
6546                        
6547            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6548            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
# Line 6140  sub _tree_construction_main ($) { Line 6554  sub _tree_construction_main ($) {
6554          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
6555            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
6556              !!!cp ('t307');              !!!cp ('t307');
6557              !!!parse-error (type => 'unmatched end tag:html', token => $token);              !!!parse-error (type => 'unmatched end tag',
6558                                text => 'html', token => $token);
6559              ## Ignore the token              ## Ignore the token
6560              !!!next-token;              !!!next-token;
6561              next B;              next B;
# Line 6152  sub _tree_construction_main ($) { Line 6567  sub _tree_construction_main ($) {
6567            }            }
6568          } else {          } else {
6569            !!!cp ('t309');            !!!cp ('t309');
6570            !!!parse-error (type => 'after body:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after body:/',
6571                              text => $token->{tag_name}, token => $token);
6572    
6573            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
6574            ## reprocess            ## reprocess
# Line 6180  sub _tree_construction_main ($) { Line 6596  sub _tree_construction_main ($) {
6596          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
6597            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6598              !!!cp ('t311');              !!!cp ('t311');
6599              !!!parse-error (type => 'in frameset:#character', token => $token);              !!!parse-error (type => 'in frameset:#text', token => $token);
6600            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6601              !!!cp ('t312');              !!!cp ('t312');
6602              !!!parse-error (type => 'after frameset:#character', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6603            } else { # "after html frameset"            } else { # "after after frameset"
6604              !!!cp ('t313');              !!!cp ('t313');
6605              !!!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);  
6606            }            }
6607                        
6608            ## Ignore the token.            ## Ignore the token.
# Line 6206  sub _tree_construction_main ($) { Line 6618  sub _tree_construction_main ($) {
6618                    
6619          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
6620        } 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');  
         }  
   
6621          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6622              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6623            !!!cp ('t318');            !!!cp ('t318');
# Line 6233  sub _tree_construction_main ($) { Line 6635  sub _tree_construction_main ($) {
6635            next B;            next B;
6636          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
6637            !!!cp ('t320');            !!!cp ('t320');
6638            ## NOTE: As if in body.            ## NOTE: As if in head.
6639            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
6640            next B;            next B;
6641    
6642              ## NOTE: |<!DOCTYPE HTML><frameset></frameset></html><noframes></noframes>|
6643              ## has no parse error.
6644          } else {          } else {
6645            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6646              !!!cp ('t321');              !!!cp ('t321');
6647              !!!parse-error (type => 'in frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset',
6648            } else {                              text => $token->{tag_name}, token => $token);
6649              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6650              !!!cp ('t322');              !!!cp ('t322');
6651              !!!parse-error (type => 'after frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after frameset',
6652                                text => $token->{tag_name}, token => $token);
6653              } else { # "after after frameset"
6654                !!!cp ('t322.2');
6655                !!!parse-error (type => 'after after frameset',
6656                                text => $token->{tag_name}, token => $token);
6657            }            }
6658            ## Ignore the token            ## Ignore the token
6659            !!!nack ('t322.1');            !!!nack ('t322.1');
# Line 6250  sub _tree_construction_main ($) { Line 6661  sub _tree_construction_main ($) {
6661            next B;            next B;
6662          }          }
6663        } 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');  
         }  
   
6664          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6665              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6666            if ($self->{open_elements}->[-1]->[1] & HTML_EL and            if ($self->{open_elements}->[-1]->[1] & HTML_EL and
6667                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
6668              !!!cp ('t325');              !!!cp ('t325');
6669              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6670                                text => $token->{tag_name}, token => $token);
6671              ## Ignore the token              ## Ignore the token
6672              !!!next-token;              !!!next-token;
6673            } else {            } else {
# Line 6291  sub _tree_construction_main ($) { Line 6693  sub _tree_construction_main ($) {
6693          } else {          } else {
6694            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6695              !!!cp ('t330');              !!!cp ('t330');
6696              !!!parse-error (type => 'in frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset:/',
6697            } else {                              text => $token->{tag_name}, token => $token);
6698              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6699                !!!cp ('t330.1');
6700                !!!parse-error (type => 'after frameset:/',
6701                                text => $token->{tag_name}, token => $token);
6702              } else { # "after after html"
6703              !!!cp ('t331');              !!!cp ('t331');
6704              !!!parse-error (type => 'after frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after after frameset:/',
6705                                text => $token->{tag_name}, token => $token);
6706            }            }
6707            ## Ignore the token            ## Ignore the token
6708            !!!next-token;            !!!next-token;
# Line 6402  sub _tree_construction_main ($) { Line 6810  sub _tree_construction_main ($) {
6810          $parse_rcdata->(RCDATA_CONTENT_MODEL);          $parse_rcdata->(RCDATA_CONTENT_MODEL);
6811          next B;          next B;
6812        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
6813          !!!parse-error (type => 'in body:body', token => $token);          !!!parse-error (type => 'in body', text => 'body', token => $token);
6814                                
6815          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
6816              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {
# Line 6522  sub _tree_construction_main ($) { Line 6930  sub _tree_construction_main ($) {
6930              if ($i != -1) {              if ($i != -1) {
6931                !!!cp ('t355');                !!!cp ('t355');
6932                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
6933                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
6934                                    ->manakai_local_name,                                    ->manakai_local_name,
6935                                token => $token);                                token => $token);
6936              } else {              } else {
# Line 6676  sub _tree_construction_main ($) { Line 7084  sub _tree_construction_main ($) {
7084                  xmp => 1,                  xmp => 1,
7085                  iframe => 1,                  iframe => 1,
7086                  noembed => 1,                  noembed => 1,
7087                  noframes => 1,                  noframes => 1, ## NOTE: This is an "as if in head" code clone.
7088                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
7089                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7090          if ($token->{tag_name} eq 'xmp') {          if ($token->{tag_name} eq 'xmp') {
# Line 6698  sub _tree_construction_main ($) { Line 7106  sub _tree_construction_main ($) {
7106            !!!next-token;            !!!next-token;
7107            next B;            next B;
7108          } else {          } else {
7109              !!!ack ('t391.1');
7110    
7111            my $at = $token->{attributes};            my $at = $token->{attributes};
7112            my $form_attrs;            my $form_attrs;
7113            $form_attrs->{action} = $at->{action} if $at->{action};            $form_attrs->{action} = $at->{action} if $at->{action};
# Line 6741  sub _tree_construction_main ($) { Line 7151  sub _tree_construction_main ($) {
7151                           line => $token->{line}, column => $token->{column}},                           line => $token->{line}, column => $token->{column}},
7152                          {type => END_TAG_TOKEN, tag_name => 'form',                          {type => END_TAG_TOKEN, tag_name => 'form',
7153                           line => $token->{line}, column => $token->{column}};                           line => $token->{line}, column => $token->{column}};
           !!!nack ('t391.1'); ## NOTE: Not acknowledged.  
7154            !!!back-token (@tokens);            !!!back-token (@tokens);
7155            !!!next-token;            !!!next-token;
7156            next B;            next B;
# Line 6789  sub _tree_construction_main ($) { Line 7198  sub _tree_construction_main ($) {
7198            ## Ignore the token            ## Ignore the token
7199          } else {          } else {
7200            !!!cp ('t398');            !!!cp ('t398');
7201            !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);            !!!parse-error (type => 'in RCDATA:#eof', token => $token);
7202          }          }
7203          !!!next-token;          !!!next-token;
7204          next B;          next B;
7205          } elsif ($token->{tag_name} eq 'rt' or
7206                   $token->{tag_name} eq 'rp') {
7207            ## has a |ruby| element in scope
7208            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
7209              my $node = $self->{open_elements}->[$_];
7210              if ($node->[1] & RUBY_EL) {
7211                !!!cp ('t398.1');
7212                ## generate implied end tags
7213                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7214                  !!!cp ('t398.2');
7215                  pop @{$self->{open_elements}};
7216                }
7217                unless ($self->{open_elements}->[-1]->[1] & RUBY_EL) {
7218                  !!!cp ('t398.3');
7219                  !!!parse-error (type => 'not closed',
7220                                  text => $self->{open_elements}->[-1]->[0]
7221                                      ->manakai_local_name,
7222                                  token => $token);
7223                  pop @{$self->{open_elements}}
7224                      while not $self->{open_elements}->[-1]->[1] & RUBY_EL;
7225                }
7226                last INSCOPE;
7227              } elsif ($node->[1] & SCOPING_EL) {
7228                !!!cp ('t398.4');
7229                last INSCOPE;
7230              }
7231            } # INSCOPE
7232    
7233            !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
7234    
7235            !!!nack ('t398.5');
7236            !!!next-token;
7237            redo B;
7238        } elsif ($token->{tag_name} eq 'math' or        } elsif ($token->{tag_name} eq 'math' or
7239                 $token->{tag_name} eq 'svg') {                 $token->{tag_name} eq 'svg') {
7240          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
7241    
7242            ## "Adjust MathML attributes" ('math' only) - done in insert-element-f
7243    
7244          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f
7245    
7246          ## "adjust foreign attributes" - done in insert-element-f          ## "adjust foreign attributes" - done in insert-element-f
# Line 6823  sub _tree_construction_main ($) { Line 7267  sub _tree_construction_main ($) {
7267                  thead => 1, tr => 1,                  thead => 1, tr => 1,
7268                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7269          !!!cp ('t401');          !!!cp ('t401');
7270          !!!parse-error (type => 'in body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in body',
7271                            text => $token->{tag_name}, token => $token);
7272          ## Ignore the token          ## Ignore the token
7273          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.
7274          !!!next-token;          !!!next-token;
# Line 6908  sub _tree_construction_main ($) { Line 7353  sub _tree_construction_main ($) {
7353            }            }
7354    
7355            !!!parse-error (type => 'start tag not allowed',            !!!parse-error (type => 'start tag not allowed',
7356                            value => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7357            ## NOTE: Ignore the token.            ## NOTE: Ignore the token.
7358            !!!next-token;            !!!next-token;
7359            next B;            next B;
# Line 6918  sub _tree_construction_main ($) { Line 7363  sub _tree_construction_main ($) {
7363            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {
7364              !!!cp ('t403');              !!!cp ('t403');
7365              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7366                              value => $_->[0]->manakai_local_name,                              text => $_->[0]->manakai_local_name,
7367                              token => $token);                              token => $token);
7368              last;              last;
7369            } else {            } else {
# Line 6938  sub _tree_construction_main ($) { Line 7383  sub _tree_construction_main ($) {
7383            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {
7384              !!!cp ('t406');              !!!cp ('t406');
7385              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7386                              value => $self->{open_elements}->[1]->[0]                              text => $self->{open_elements}->[1]->[0]
7387                                  ->manakai_local_name,                                  ->manakai_local_name,
7388                              token => $token);                              token => $token);
7389            } else {            } else {
# Line 6949  sub _tree_construction_main ($) { Line 7394  sub _tree_construction_main ($) {
7394            next B;            next B;
7395          } else {          } else {
7396            !!!cp ('t408');            !!!cp ('t408');
7397            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7398                              text => $token->{tag_name}, token => $token);
7399            ## Ignore the token            ## Ignore the token
7400            !!!next-token;            !!!next-token;
7401            next B;            next B;
# Line 6977  sub _tree_construction_main ($) { Line 7423  sub _tree_construction_main ($) {
7423    
7424          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7425            !!!cp ('t413');            !!!cp ('t413');
7426            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7427                              text => $token->{tag_name}, token => $token);
7428              ## NOTE: Ignore the token.
7429          } else {          } else {
7430            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7431            while ({            while ({
7432                      ## END_TAG_OPTIONAL_EL
7433                    dd => ($token->{tag_name} ne 'dd'),                    dd => ($token->{tag_name} ne 'dd'),
7434                    dt => ($token->{tag_name} ne 'dt'),                    dt => ($token->{tag_name} ne 'dt'),
7435                    li => ($token->{tag_name} ne 'li'),                    li => ($token->{tag_name} ne 'li'),
7436                    p => 1,                    p => 1,
7437                      rt => 1,
7438                      rp => 1,
7439                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {
7440              !!!cp ('t409');              !!!cp ('t409');
7441              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
# Line 6995  sub _tree_construction_main ($) { Line 7446  sub _tree_construction_main ($) {
7446                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7447              !!!cp ('t412');              !!!cp ('t412');
7448              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7449                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7450                                  ->manakai_local_name,                                  ->manakai_local_name,
7451                              token => $token);                              token => $token);
7452            } else {            } else {
# Line 7032  sub _tree_construction_main ($) { Line 7483  sub _tree_construction_main ($) {
7483    
7484          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7485            !!!cp ('t421');            !!!cp ('t421');
7486            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7487                              text => $token->{tag_name}, token => $token);
7488              ## NOTE: Ignore the token.
7489          } else {          } else {
7490            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7491            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7045  sub _tree_construction_main ($) { Line 7498  sub _tree_construction_main ($) {
7498                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7499              !!!cp ('t417.1');              !!!cp ('t417.1');
7500              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7501                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7502                                  ->manakai_local_name,                                  ->manakai_local_name,
7503                              token => $token);                              token => $token);
7504            } else {            } else {
# Line 7077  sub _tree_construction_main ($) { Line 7530  sub _tree_construction_main ($) {
7530    
7531          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7532            !!!cp ('t425.1');            !!!cp ('t425.1');
7533            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7534                              text => $token->{tag_name}, token => $token);
7535              ## NOTE: Ignore the token.
7536          } else {          } else {
7537            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7538            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7089  sub _tree_construction_main ($) { Line 7544  sub _tree_construction_main ($) {
7544            if ($self->{open_elements}->[-1]->[0]->manakai_local_name            if ($self->{open_elements}->[-1]->[0]->manakai_local_name
7545                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7546              !!!cp ('t425');              !!!cp ('t425');
7547              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
7548                                text => $token->{tag_name}, token => $token);
7549            } else {            } else {
7550              !!!cp ('t426');              !!!cp ('t426');
7551            }            }
# Line 7120  sub _tree_construction_main ($) { Line 7576  sub _tree_construction_main ($) {
7576                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7577              !!!cp ('t412.1');              !!!cp ('t412.1');
7578              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7579                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7580                                  ->manakai_local_name,                                  ->manakai_local_name,
7581                              token => $token);                              token => $token);
7582            } else {            } else {
# Line 7130  sub _tree_construction_main ($) { Line 7586  sub _tree_construction_main ($) {
7586            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
7587          } else {          } else {
7588            !!!cp ('t413.1');            !!!cp ('t413.1');
7589            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7590                              text => $token->{tag_name}, token => $token);
7591    
7592            !!!cp ('t415.1');            !!!cp ('t415.1');
7593            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
# Line 7153  sub _tree_construction_main ($) { Line 7610  sub _tree_construction_main ($) {
7610          next B;          next B;
7611        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
7612          !!!cp ('t428');          !!!cp ('t428');
7613          !!!parse-error (type => 'unmatched end tag:br', token => $token);          !!!parse-error (type => 'unmatched end tag',
7614                            text => 'br', token => $token);
7615    
7616          ## As if <br>          ## As if <br>
7617          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
# Line 7178  sub _tree_construction_main ($) { Line 7636  sub _tree_construction_main ($) {
7636                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
7637                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7638          !!!cp ('t429');          !!!cp ('t429');
7639          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'unmatched end tag',
7640                            text => $token->{tag_name}, token => $token);
7641          ## Ignore the token          ## Ignore the token
7642          !!!next-token;          !!!next-token;
7643          next B;          next B;
# Line 7197  sub _tree_construction_main ($) { Line 7656  sub _tree_construction_main ($) {
7656              ## generate implied end tags              ## generate implied end tags
7657              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7658                !!!cp ('t430');                !!!cp ('t430');
7659                ## ISSUE: Can this case be reached?                ## NOTE: |<ruby><rt></ruby>|.
7660                  ## ISSUE: <ruby><rt></rt> will also take this code path,
7661                  ## which seems wrong.
7662                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
7663                  $node_i++;
7664              }              }
7665                    
7666              ## Step 2              ## Step 2
# Line 7207  sub _tree_construction_main ($) { Line 7669  sub _tree_construction_main ($) {
7669                !!!cp ('t431');                !!!cp ('t431');
7670                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
7671                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
7672                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
7673                                    ->manakai_local_name,                                    ->manakai_local_name,
7674                                token => $token);                                token => $token);
7675              } else {              } else {
# Line 7215  sub _tree_construction_main ($) { Line 7677  sub _tree_construction_main ($) {
7677              }              }
7678                            
7679              ## Step 3              ## Step 3
7680              splice @{$self->{open_elements}}, $node_i;              splice @{$self->{open_elements}}, $node_i if $node_i < 0;
7681    
7682              !!!next-token;              !!!next-token;
7683              last S2;              last S2;
# Line 7226  sub _tree_construction_main ($) { Line 7688  sub _tree_construction_main ($) {
7688                  ($node->[1] & SPECIAL_EL or                  ($node->[1] & SPECIAL_EL or
7689                   $node->[1] & SCOPING_EL)) {                   $node->[1] & SCOPING_EL)) {
7690                !!!cp ('t433');                !!!cp ('t433');
7691                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
7692                                  text => $token->{tag_name}, token => $token);
7693                ## Ignore the token                ## Ignore the token
7694                !!!next-token;                !!!next-token;
7695                last S2;                last S2;
# Line 7272  sub _tree_construction_main ($) { Line 7735  sub _tree_construction_main ($) {
7735    ## TODO: script stuffs    ## TODO: script stuffs
7736  } # _tree_construct_main  } # _tree_construct_main
7737    
7738  sub set_inner_html ($$$) {  sub set_inner_html ($$$;$) {
7739    my $class = shift;    my $class = shift;
7740    my $node = shift;    my $node = shift;
7741    my $s = \$_[0];    my $s = \$_[0];
7742    my $onerror = $_[1];    my $onerror = $_[1];
7743      my $get_wrapper = $_[2] || sub ($) { return $_[0] };
7744    
7745    ## ISSUE: Should {confident} be true?    ## ISSUE: Should {confident} be true?
7746    
# Line 7295  sub set_inner_html ($$$) { Line 7759  sub set_inner_html ($$$) {
7759      }      }
7760    
7761      ## Step 3, 4, 5 # MUST      ## Step 3, 4, 5 # MUST
7762      $class->parse_string ($$s => $node, $onerror);      $class->parse_char_string ($$s => $node, $onerror, $get_wrapper);
7763    } elsif ($nt == 1) {    } elsif ($nt == 1) {
7764      ## TODO: If non-html element      ## TODO: If non-html element
7765    
7766      ## NOTE: Most of this code is copied from |parse_string|      ## NOTE: Most of this code is copied from |parse_string|
7767    
7768    ## TODO: Support for $get_wrapper
7769    
7770      ## Step 1 # MUST      ## Step 1 # MUST
7771      my $this_doc = $node->owner_document;      my $this_doc = $node->owner_document;
7772      my $doc = $this_doc->implementation->create_document;      my $doc = $this_doc->implementation->create_document;
# Line 7362  sub set_inner_html ($$$) { Line 7828  sub set_inner_html ($$$) {
7828                  0x10FFFE => 1, 0x10FFFF => 1,                  0x10FFFE => 1, 0x10FFFF => 1,
7829                 }->{$self->{next_char}}) {                 }->{$self->{next_char}}) {
7830          !!!cp ('i4.1');          !!!cp ('i4.1');
7831          !!!parse-error (type => 'control char', level => $self->{must_level});          if ($self->{next_char} < 0x10000) {
7832  ## TODO: error type documentation            !!!parse-error (type => 'control char',
7833                              text => (sprintf 'U+%04X', $self->{next_char}));
7834            } else {
7835              !!!parse-error (type => 'control char',
7836                              text => (sprintf 'U-%08X', $self->{next_char}));
7837            }
7838        }        }
7839      };      };
7840      $p->{prev_char} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];
7841      $p->{next_char} = -1;      $p->{next_char} = -1;
7842        
7843        $p->{read_until} = sub {
7844          ## TODO: ...
7845          return 0;
7846        }; # $p->{read_until};
7847    
7848      my $ponerror = $onerror || sub {      my $ponerror = $onerror || sub {
7849        my (%opt) = @_;        my (%opt) = @_;
7850        my $line = $opt{line};        my $line = $opt{line};

Legend:
Removed from v.1.146  
changed lines
  Added in v.1.174

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24