/[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.138 by wakaba, Sun May 18 04:15:48 2008 UTC revision 1.172 by wakaba, Sun Sep 14 03:07:58 2008 UTC
# Line 8  use Error qw(:try); Line 8  use Error qw(:try);
8  ## doc.write ('');  ## doc.write ('');
9  ## alert (doc.compatMode);  ## alert (doc.compatMode);
10    
11  ## TODO: 1252 parse error (revision 1264)  require IO::Handle;
 ## TODO: 8859-11 = 874 (revision 1271)  
12    
13  my $HTML_NS = q<http://www.w3.org/1999/xhtml>;  my $HTML_NS = q<http://www.w3.org/1999/xhtml>;
14  my $MML_NS = q<http://www.w3.org/1998/Math/MathML>;  my $MML_NS = q<http://www.w3.org/1998/Math/MathML>;
# Line 46  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 53  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 97  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 171  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 212  my $el_category_f = { Line 231  my $el_category_f = {
231  };  };
232    
233  my $svg_attr_name = {  my $svg_attr_name = {
234      attributename => 'attributeName',
235    attributetype => 'attributeType',    attributetype => 'attributeType',
236    basefrequency => 'baseFrequency',    basefrequency => 'baseFrequency',
237    baseprofile => 'baseProfile',    baseprofile => 'baseProfile',
# Line 222  my $svg_attr_name = { Line 242  my $svg_attr_name = {
242    diffuseconstant => 'diffuseConstant',    diffuseconstant => 'diffuseConstant',
243    edgemode => 'edgeMode',    edgemode => 'edgeMode',
244    externalresourcesrequired => 'externalResourcesRequired',    externalresourcesrequired => 'externalResourcesRequired',
   fecolormatrix => 'feColorMatrix',  
   fecomposite => 'feComposite',  
   fegaussianblur => 'feGaussianBlur',  
   femorphology => 'feMorphology',  
   fetile => 'feTile',  
245    filterres => 'filterRes',    filterres => 'filterRes',
246    filterunits => 'filterUnits',    filterunits => 'filterUnits',
247    glyphref => 'glyphRef',    glyphref => 'glyphRef',
# Line 260  my $svg_attr_name = { Line 275  my $svg_attr_name = {
275    repeatcount => 'repeatCount',    repeatcount => 'repeatCount',
276    repeatdur => 'repeatDur',    repeatdur => 'repeatDur',
277    requiredextensions => 'requiredExtensions',    requiredextensions => 'requiredExtensions',
278      requiredfeatures => 'requiredFeatures',
279    specularconstant => 'specularConstant',    specularconstant => 'specularConstant',
280    specularexponent => 'specularExponent',    specularexponent => 'specularExponent',
281    spreadmethod => 'spreadMethod',    spreadmethod => 'spreadMethod',
# Line 338  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 349  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 356  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 383  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 416  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 427  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 438  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 450  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 476  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 485  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 496  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 520  sub parse_byte_stream ($$$$;$) { Line 560  sub parse_byte_stream ($$$$;$) {
560    
561    my $char_onerror = sub {    my $char_onerror = sub {
562      my (undef, $type, %opt) = @_;      my (undef, $type, %opt) = @_;
563      !!!parse-error (%opt, type => $type,      !!!parse-error (layer => 'encode',
564                        %opt, type => $type,
565                      line => $self->{line}, column => $self->{column} + 1);                      line => $self->{line}, column => $self->{column} + 1);
566      if ($opt{octets}) {      if ($opt{octets}) {
567        ${$opt{octets}} = "\x{FFFD}"; # relacement character        ${$opt{octets}} = "\x{FFFD}"; # relacement character
568      }      }
569    };    };
570    $char_stream->onerror ($char_onerror);  
571      my $wrapped_char_stream = $get_wrapper->($char_stream);
572      $wrapped_char_stream->onerror ($char_onerror);
573    
574    my @args = @_; shift @args; # $s    my @args = @_; shift @args; # $s
575    my $return;    my $return;
576    try {    try {
577      $return = $self->parse_char_stream ($char_stream, @args);        $return = $self->parse_char_stream ($wrapped_char_stream, @args);  
578    } catch Whatpm::HTML::RestartParser with {    } catch Whatpm::HTML::RestartParser with {
579      ## NOTE: Invoked after {change_encoding}.      ## NOTE: Invoked after {change_encoding}.
580    
     $self->{input_encoding} = $charset->get_iana_name;  
581      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
582        !!!parse-error (type => 'chardecode:fallback', ## TODO: type name        $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name?
583                        value => $self->{input_encoding},        !!!parse-error (type => 'chardecode:fallback',
584                        level => $self->{unsupported_level},                        level => $self->{level}->{uncertain},
585                        line => 1, column => 1);                        #text => $self->{input_encoding},
586                          line => 1, column => 1,
587                          layer => 'encode');
588      } elsif (not ($e_status &      } elsif (not ($e_status &
589                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
590        !!!parse-error (type => 'chardecode:no error', ## TODO: type name        $self->{input_encoding} = $charset->get_iana_name;
591                        value => $self->{input_encoding},        !!!parse-error (type => 'chardecode:no error',
592                        level => $self->{unsupported_level},                        text => $self->{input_encoding},
593                        line => 1, column => 1);                        level => $self->{level}->{uncertain},
594                          line => 1, column => 1,
595                          layer => 'encode');
596        } else {
597          $self->{input_encoding} = $charset->get_iana_name;
598      }      }
599      $self->{confident} = 1;      $self->{confident} = 1;
600      $char_stream->onerror ($char_onerror);  
601      $return = $self->parse_char_stream ($char_stream, @args);      $wrapped_char_stream = $get_wrapper->($char_stream);
602        $wrapped_char_stream->onerror ($char_onerror);
603    
604        $return = $self->parse_char_stream ($wrapped_char_stream, @args);
605    };    };
606    return $return;    return $return;
607  } # parse_byte_stream  } # parse_byte_stream
# Line 564  sub parse_byte_stream ($$$$;$) { Line 615  sub parse_byte_stream ($$$$;$) {
615  ## such as |parse_byte_string| in this module, must ensure that it does  ## such as |parse_byte_string| in this module, must ensure that it does
616  ## strip the BOM and never strip any ZWNBSP.  ## strip the BOM and never strip any ZWNBSP.
617    
618  sub parse_char_string ($$$;$) {  sub parse_char_string ($$$;$$) {
619      #my ($self, $s, $doc, $onerror, $get_wrapper) = @_;
620    my $self = shift;    my $self = shift;
621    open my $input, '<:utf8', ref $_[0] ? $_[0] : \($_[0]);    my $s = ref $_[0] ? $_[0] : \($_[0]);
622      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 592  sub parse_char_stream ($$$;$) { Line 649  sub parse_char_stream ($$$;$) {
649      pop @{$self->{prev_char}};      pop @{$self->{prev_char}};
650      unshift @{$self->{prev_char}}, $self->{next_char};      unshift @{$self->{prev_char}}, $self->{next_char};
651    
652      my $char = $input->getc;      my $char;
653        if (defined $self->{next_next_char}) {
654          $char = $self->{next_next_char};
655          delete $self->{next_next_char};
656        } else {
657          $char = $input->getc;
658        }
659      $self->{next_char} = -1 and return unless defined $char;      $self->{next_char} = -1 and return unless defined $char;
660      $self->{next_char} = ord $char;      $self->{next_char} = ord $char;
661    
# Line 606  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 ($next ne "\x0A") {        if (defined $next and $next ne "\x0A") {
675          $input->ungetc ($next);          $self->{next_next_char} = $next;
676        }        }
677        $self->{next_char} = 0x000A; # LF # MUST        $self->{next_char} = 0x000A; # LF # MUST
678        $self->{line}++;        $self->{line}++;
# Line 625  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 637  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{FFFE}\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        if ($count) {
726          $self->{column} += $count;
727          $self->{column_prev} += $count;
728          $self->{prev_char} = [-1, -1, -1];
729          $self->{next_char} = -1;
730        }
731        return $count;
732      }; # $self->{read_until}
733    
734    my $onerror = $_[2] || sub {    my $onerror = $_[2] || sub {
735      my (%opt) = @_;      my (%opt) = @_;
736      my $line = $opt{token} ? $opt{token}->{line} : $opt{line};      my $line = $opt{token} ? $opt{token}->{line} : $opt{line};
# Line 667  sub parse_char_stream ($$$;$) { Line 754  sub parse_char_stream ($$$;$) {
754  sub new ($) {  sub new ($) {
755    my $class = shift;    my $class = shift;
756    my $self = bless {    my $self = bless {
757      must_level => 'm',      level => {must => 'm',
758      should_level => 's',                should => 's',
759      good_level => 'w',                warn => 'w',
760      warn_level => 'w',                info => 'i',
761      info_level => 'i',                uncertain => 'u'},
     unsupported_level => 'u',  
762    }, $class;    }, $class;
763    $self->{set_next_char} = sub {    $self->{set_next_char} = sub {
764      $self->{next_char} = -1;      $self->{next_char} = -1;
# Line 702  sub RCDATA_CONTENT_MODEL () { CM_ENTITY Line 788  sub RCDATA_CONTENT_MODEL () { CM_ENTITY
788  sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }  sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }
789    
790  sub DATA_STATE () { 0 }  sub DATA_STATE () { 0 }
791  sub ENTITY_DATA_STATE () { 1 }  #sub ENTITY_DATA_STATE () { 1 }
792  sub TAG_OPEN_STATE () { 2 }  sub TAG_OPEN_STATE () { 2 }
793  sub CLOSE_TAG_OPEN_STATE () { 3 }  sub CLOSE_TAG_OPEN_STATE () { 3 }
794  sub TAG_NAME_STATE () { 4 }  sub TAG_NAME_STATE () { 4 }
# Line 713  sub BEFORE_ATTRIBUTE_VALUE_STATE () { 8 Line 799  sub BEFORE_ATTRIBUTE_VALUE_STATE () { 8
799  sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 }  sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 }
800  sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 }  sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 }
801  sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 }  sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 }
802  sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 }  #sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 }
803  sub MARKUP_DECLARATION_OPEN_STATE () { 13 }  sub MARKUP_DECLARATION_OPEN_STATE () { 13 }
804  sub COMMENT_START_STATE () { 14 }  sub COMMENT_START_STATE () { 14 }
805  sub COMMENT_START_DASH_STATE () { 15 }  sub COMMENT_START_DASH_STATE () { 15 }
# Line 736  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STAT Line 822  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STAT
822  sub BOGUS_DOCTYPE_STATE () { 32 }  sub BOGUS_DOCTYPE_STATE () { 32 }
823  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }
824  sub SELF_CLOSING_START_TAG_STATE () { 34 }  sub SELF_CLOSING_START_TAG_STATE () { 34 }
825  sub CDATA_BLOCK_STATE () { 35 }  sub CDATA_SECTION_STATE () { 35 }
826    sub MD_HYPHEN_STATE () { 36 } # "markup declaration open state" in the spec
827    sub MD_DOCTYPE_STATE () { 37 } # "markup declaration open state" in the spec
828    sub MD_CDATA_STATE () { 38 } # "markup declaration open state" in the spec
829    sub CDATA_PCDATA_CLOSE_TAG_STATE () { 39 } # "close tag open state" in the spec
830    sub CDATA_SECTION_MSE1_STATE () { 40 } # "CDATA section state" in the spec
831    sub CDATA_SECTION_MSE2_STATE () { 41 } # "CDATA section state" in the spec
832    sub PUBLIC_STATE () { 42 } # "after DOCTYPE name state" in the spec
833    sub SYSTEM_STATE () { 43 } # "after DOCTYPE name state" in the spec
834    ## NOTE: "Entity data state", "entity in attribute value state", and
835    ## "consume a character reference" algorithm are jointly implemented
836    ## using the following six states:
837    sub ENTITY_STATE () { 44 }
838    sub ENTITY_HASH_STATE () { 45 }
839    sub NCR_NUM_STATE () { 46 }
840    sub HEXREF_X_STATE () { 47 }
841    sub HEXREF_HEX_STATE () { 48 }
842    sub ENTITY_NAME_STATE () { 49 }
843    
844  sub DOCTYPE_TOKEN () { 1 }  sub DOCTYPE_TOKEN () { 1 }
845  sub COMMENT_TOKEN () { 2 }  sub COMMENT_TOKEN () { 2 }
# Line 789  sub IN_COLUMN_GROUP_IM () { 0b10 } Line 892  sub IN_COLUMN_GROUP_IM () { 0b10 }
892  sub _initialize_tokenizer ($) {  sub _initialize_tokenizer ($) {
893    my $self = shift;    my $self = shift;
894    $self->{state} = DATA_STATE; # MUST    $self->{state} = DATA_STATE; # MUST
895      #$self->{state_keyword}; # initialized when used
896      #$self->{entity__value}; # initialized when used
897      #$self->{entity__match}; # initialized when used
898    $self->{content_model} = PCDATA_CONTENT_MODEL; # be    $self->{content_model} = PCDATA_CONTENT_MODEL; # be
899    undef $self->{current_token}; # start tag, end tag, comment, or DOCTYPE    undef $self->{current_token};
900    undef $self->{current_attribute};    undef $self->{current_attribute};
901    undef $self->{last_emitted_start_tag_name};    undef $self->{last_emitted_start_tag_name};
902    undef $self->{last_attribute_value_state};    #$self->{prev_state}; # initialized when used
903    delete $self->{self_closing};    delete $self->{self_closing};
   $self->{char} = [];  
904    # $self->{next_char}    # $self->{next_char}
905    !!!next-input-character;    !!!next-input-character;
906    $self->{token} = [];    $self->{token} = [];
# Line 819  sub _initialize_tokenizer ($) { Line 924  sub _initialize_tokenizer ($) {
924  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|
925  ##     while the token is pushed back to the stack.  ##     while the token is pushed back to the stack.
926    
 ## 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?  
   
927  ## Emitted token MUST immediately be handled by the tree construction state.  ## Emitted token MUST immediately be handled by the tree construction state.
928    
929  ## 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 831  sub _initialize_tokenizer ($) { Line 932  sub _initialize_tokenizer ($) {
932  ## has completed loading.  If one has, then it MUST be executed  ## has completed loading.  If one has, then it MUST be executed
933  ## and removed from the list.  ## and removed from the list.
934    
935  ## NOTE: HTML5 "Writing HTML documents" section, applied to  ## TODO: Polytheistic slash SHOULD NOT be used. (Applied only to atheists.)
936  ## 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,  
937    
938  sub _get_next_token ($) {  sub _get_next_token ($) {
939    my $self = shift;    my $self = shift;
# Line 868  sub _get_next_token ($) { Line 957  sub _get_next_token ($) {
957          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA
958              not $self->{escape}) {              not $self->{escape}) {
959            !!!cp (1);            !!!cp (1);
960            $self->{state} = ENTITY_DATA_STATE;            ## NOTE: In the spec, the tokenizer is switched to the
961              ## "entity data state".  In this implementation, the tokenizer
962              ## is switched to the |ENTITY_STATE|, which is an implementation
963              ## of the "consume a character reference" algorithm.
964              $self->{entity_additional} = -1;
965              $self->{prev_state} = DATA_STATE;
966              $self->{state} = ENTITY_STATE;
967            !!!next-input-character;            !!!next-input-character;
968            redo A;            redo A;
969          } else {          } else {
# Line 932  sub _get_next_token ($) { Line 1027  sub _get_next_token ($) {
1027                     data => chr $self->{next_char},                     data => chr $self->{next_char},
1028                     line => $self->{line}, column => $self->{column},                     line => $self->{line}, column => $self->{column},
1029                    };                    };
1030          $self->{read_until}->($token->{data}, q[-!<>&], length $token->{data});
1031    
1032        ## Stay in the data state        ## Stay in the data state
1033        !!!next-input-character;        !!!next-input-character;
1034    
1035        !!!emit ($token);        !!!emit ($token);
1036    
1037        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;  
1038      } elsif ($self->{state} == TAG_OPEN_STATE) {      } elsif ($self->{state} == TAG_OPEN_STATE) {
1039        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1040          if ($self->{next_char} == 0x002F) { # /          if ($self->{next_char} == 0x002F) { # /
# Line 1055  sub _get_next_token ($) { Line 1131  sub _get_next_token ($) {
1131          die "$0: $self->{content_model} in tag open";          die "$0: $self->{content_model} in tag open";
1132        }        }
1133      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {
1134          ## NOTE: The "close tag open state" in the spec is implemented as
1135          ## |CLOSE_TAG_OPEN_STATE| and |CDATA_PCDATA_CLOSE_TAG_STATE|.
1136    
1137        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"
1138        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1139          if (defined $self->{last_emitted_start_tag_name}) {          if (defined $self->{last_emitted_start_tag_name}) {
1140              $self->{state} = CDATA_PCDATA_CLOSE_TAG_STATE;
1141            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>            $self->{state_keyword} = '';
1142            my @next_char;            ## Reconsume.
1143            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...  
           }  
1144          } else {          } else {
1145            ## No start tag token has ever been emitted            ## No start tag token has ever been emitted
1146              ## NOTE: See <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>.
1147            !!!cp (28);            !!!cp (28);
           # next-input-character is already done  
1148            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1149              ## Reconsume.
1150            !!!emit ({type => CHARACTER_TOKEN, data => '</',            !!!emit ({type => CHARACTER_TOKEN, data => '</',
1151                      line => $l, column => $c,                      line => $l, column => $c,
1152                     });                     });
1153            redo A;            redo A;
1154          }          }
1155        }        }
1156          
1157        if (0x0041 <= $self->{next_char} and        if (0x0041 <= $self->{next_char} and
1158            $self->{next_char} <= 0x005A) { # A..Z            $self->{next_char} <= 0x005A) { # A..Z
1159          !!!cp (29);          !!!cp (29);
# Line 1164  sub _get_next_token ($) { Line 1200  sub _get_next_token ($) {
1200                                    line => $self->{line_prev}, # "<" of "</"                                    line => $self->{line_prev}, # "<" of "</"
1201                                    column => $self->{column_prev} - 1,                                    column => $self->{column_prev} - 1,
1202                                   };                                   };
1203          ## $self->{next_char} is intentionally left as is          ## NOTE: $self->{next_char} is intentionally left as is.
1204          redo A;          ## Although the "anything else" case of the spec not explicitly
1205            ## states that the next input character is to be reconsumed,
1206            ## it will be included to the |data| of the comment token
1207            ## generated from the bogus end tag, as defined in the
1208            ## "bogus comment state" entry.
1209            redo A;
1210          }
1211        } elsif ($self->{state} == CDATA_PCDATA_CLOSE_TAG_STATE) {
1212          my $ch = substr $self->{last_emitted_start_tag_name}, length $self->{state_keyword}, 1;
1213          if (length $ch) {
1214            my $CH = $ch;
1215            $ch =~ tr/a-z/A-Z/;
1216            my $nch = chr $self->{next_char};
1217            if ($nch eq $ch or $nch eq $CH) {
1218              !!!cp (24);
1219              ## Stay in the state.
1220              $self->{state_keyword} .= $nch;
1221              !!!next-input-character;
1222              redo A;
1223            } else {
1224              !!!cp (25);
1225              $self->{state} = DATA_STATE;
1226              ## Reconsume.
1227              !!!emit ({type => CHARACTER_TOKEN,
1228                        data => '</' . $self->{state_keyword},
1229                        line => $self->{line_prev},
1230                        column => $self->{column_prev} - 1 - length $self->{state_keyword},
1231                       });
1232              redo A;
1233            }
1234          } else { # after "<{tag-name}"
1235            unless ({
1236                     0x0009 => 1, # HT
1237                     0x000A => 1, # LF
1238                     0x000B => 1, # VT
1239                     0x000C => 1, # FF
1240                     0x0020 => 1, # SP
1241                     0x003E => 1, # >
1242                     0x002F => 1, # /
1243                     -1 => 1, # EOF
1244                    }->{$self->{next_char}}) {
1245              !!!cp (26);
1246              ## Reconsume.
1247              $self->{state} = DATA_STATE;
1248              !!!emit ({type => CHARACTER_TOKEN,
1249                        data => '</' . $self->{state_keyword},
1250                        line => $self->{line_prev},
1251                        column => $self->{column_prev} - 1 - length $self->{state_keyword},
1252                       });
1253              redo A;
1254            } else {
1255              !!!cp (27);
1256              $self->{current_token}
1257                  = {type => END_TAG_TOKEN,
1258                     tag_name => $self->{last_emitted_start_tag_name},
1259                     line => $self->{line_prev},
1260                     column => $self->{column_prev} - 1 - length $self->{state_keyword}};
1261              $self->{state} = TAG_NAME_STATE;
1262              ## Reconsume.
1263              redo A;
1264            }
1265        }        }
1266      } elsif ($self->{state} == TAG_NAME_STATE) {      } elsif ($self->{state} == TAG_NAME_STATE) {
1267        if ($self->{next_char} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
# Line 1335  sub _get_next_token ($) { Line 1431  sub _get_next_token ($) {
1431          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
1432              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
1433            !!!cp (57);            !!!cp (57);
1434            !!!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});
1435            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{current_attribute} # MUST
1436          } else {          } else {
1437            !!!cp (58);            !!!cp (58);
# Line 1506  sub _get_next_token ($) { Line 1602  sub _get_next_token ($) {
1602    
1603          redo A;          redo A;
1604        } else {        } else {
1605          !!!cp (82);          if ($self->{next_char} == 0x0022 or # "
1606                $self->{next_char} == 0x0027) { # '
1607              !!!cp (78);
1608              !!!parse-error (type => 'bad attribute name');
1609            } else {
1610              !!!cp (82);
1611            }
1612          $self->{current_attribute}          $self->{current_attribute}
1613              = {name => chr ($self->{next_char}),              = {name => chr ($self->{next_char}),
1614                 value => '',                 value => '',
# Line 1541  sub _get_next_token ($) { Line 1643  sub _get_next_token ($) {
1643          !!!next-input-character;          !!!next-input-character;
1644          redo A;          redo A;
1645        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1646            !!!parse-error (type => 'empty unquoted attribute value');
1647          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1648            !!!cp (87);            !!!cp (87);
1649            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
# Line 1605  sub _get_next_token ($) { Line 1708  sub _get_next_token ($) {
1708          redo A;          redo A;
1709        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1710          !!!cp (96);          !!!cp (96);
1711          $self->{last_attribute_value_state} = $self->{state};          ## NOTE: In the spec, the tokenizer is switched to the
1712          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## "entity in attribute value state".  In this implementation, the
1713            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1714            ## implementation of the "consume a character reference" algorithm.
1715            $self->{prev_state} = $self->{state};
1716            $self->{entity_additional} = 0x0022; # "
1717            $self->{state} = ENTITY_STATE;
1718          !!!next-input-character;          !!!next-input-character;
1719          redo A;          redo A;
1720        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
# Line 1647  sub _get_next_token ($) { Line 1755  sub _get_next_token ($) {
1755          redo A;          redo A;
1756        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1757          !!!cp (102);          !!!cp (102);
1758          $self->{last_attribute_value_state} = $self->{state};          ## NOTE: In the spec, the tokenizer is switched to the
1759          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## "entity in attribute value state".  In this implementation, the
1760            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1761            ## implementation of the "consume a character reference" algorithm.
1762            $self->{entity_additional} = 0x0027; # '
1763            $self->{prev_state} = $self->{state};
1764            $self->{state} = ENTITY_STATE;
1765          !!!next-input-character;          !!!next-input-character;
1766          redo A;          redo A;
1767        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
# Line 1693  sub _get_next_token ($) { Line 1806  sub _get_next_token ($) {
1806          redo A;          redo A;
1807        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1808          !!!cp (108);          !!!cp (108);
1809          $self->{last_attribute_value_state} = $self->{state};          ## NOTE: In the spec, the tokenizer is switched to the
1810          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## "entity in attribute value state".  In this implementation, the
1811            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1812            ## implementation of the "consume a character reference" algorithm.
1813            $self->{entity_additional} = -1;
1814            $self->{prev_state} = $self->{state};
1815            $self->{state} = ENTITY_STATE;
1816          !!!next-input-character;          !!!next-input-character;
1817          redo A;          redo A;
1818        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
# Line 1758  sub _get_next_token ($) { Line 1876  sub _get_next_token ($) {
1876          !!!next-input-character;          !!!next-input-character;
1877          redo A;          redo A;
1878        }        }
     } 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;  
1879      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {
1880        if ($self->{next_char} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
1881            $self->{next_char} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
# Line 1817  sub _get_next_token ($) { Line 1913  sub _get_next_token ($) {
1913          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1914          !!!next-input-character;          !!!next-input-character;
1915          redo A;          redo A;
1916          } elsif ($self->{next_char} == -1) {
1917            !!!parse-error (type => 'unclosed tag');
1918            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1919              !!!cp (122.3);
1920              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1921            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1922              if ($self->{current_token}->{attributes}) {
1923                !!!cp (122.1);
1924                !!!parse-error (type => 'end tag attribute');
1925              } else {
1926                ## NOTE: This state should never be reached.
1927                !!!cp (122.2);
1928              }
1929            } else {
1930              die "$0: $self->{current_token}->{type}: Unknown token type";
1931            }
1932            $self->{state} = DATA_STATE;
1933            ## Reconsume.
1934            !!!emit ($self->{current_token}); # start tag or end tag
1935            redo A;
1936        } else {        } else {
1937          !!!cp ('124.1');          !!!cp ('124.1');
1938          !!!parse-error (type => 'no space between attributes');          !!!parse-error (type => 'no space between attributes');
# Line 1849  sub _get_next_token ($) { Line 1965  sub _get_next_token ($) {
1965          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
1966    
1967          redo A;          redo A;
1968          } elsif ($self->{next_char} == -1) {
1969            !!!parse-error (type => 'unclosed tag');
1970            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1971              !!!cp (124.7);
1972              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1973            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1974              if ($self->{current_token}->{attributes}) {
1975                !!!cp (124.5);
1976                !!!parse-error (type => 'end tag attribute');
1977              } else {
1978                ## NOTE: This state should never be reached.
1979                !!!cp (124.6);
1980              }
1981            } else {
1982              die "$0: $self->{current_token}->{type}: Unknown token type";
1983            }
1984            $self->{state} = DATA_STATE;
1985            ## Reconsume.
1986            !!!emit ($self->{current_token}); # start tag or end tag
1987            redo A;
1988        } else {        } else {
1989          !!!cp ('124.4');          !!!cp ('124.4');
1990          !!!parse-error (type => 'nestc');          !!!parse-error (type => 'nestc');
# Line 1859  sub _get_next_token ($) { Line 1995  sub _get_next_token ($) {
1995        }        }
1996      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {
1997        ## (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  
1998    
1999            redo A;        ## NOTE: Unlike spec's "bogus comment state", this implementation
2000          } elsif ($self->{next_char} == -1) {        ## consumes characters one-by-one basis.
2001            !!!cp (125);        
2002            $self->{state} = DATA_STATE;        if ($self->{next_char} == 0x003E) { # >
2003            ## reconsume          !!!cp (124);
2004            $self->{state} = DATA_STATE;
2005            !!!emit ($self->{current_token}); # comment          !!!next-input-character;
2006    
2007            redo A;          !!!emit ($self->{current_token}); # comment
2008          } else {          redo A;
2009            !!!cp (126);        } elsif ($self->{next_char} == -1) {
2010            $self->{current_token}->{data} .= chr ($self->{next_char}); # comment          !!!cp (125);
2011            !!!next-input-character;          $self->{state} = DATA_STATE;
2012            redo BC;          ## reconsume
         }  
       } # BC  
2013    
2014        die "$0: _get_next_token: unexpected case [BC]";          !!!emit ($self->{current_token}); # comment
2015            redo A;
2016          } else {
2017            !!!cp (126);
2018            $self->{current_token}->{data} .= chr ($self->{next_char}); # comment
2019            ## Stay in the state.
2020            !!!next-input-character;
2021            redo A;
2022          }
2023      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {
2024        ## (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};  
2025                
2026        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
2027            !!!cp (133);
2028            $self->{state} = MD_HYPHEN_STATE;
2029          !!!next-input-character;          !!!next-input-character;
2030          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);  
         }  
2031        } elsif ($self->{next_char} == 0x0044 or # D        } elsif ($self->{next_char} == 0x0044 or # D
2032                 $self->{next_char} == 0x0064) { # d                 $self->{next_char} == 0x0064) { # d
2033            ## ASCII case-insensitive.
2034            !!!cp (130);
2035            $self->{state} = MD_DOCTYPE_STATE;
2036            $self->{state_keyword} = chr $self->{next_char};
2037          !!!next-input-character;          !!!next-input-character;
2038          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);  
         }  
2039        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and
2040                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and
2041                 $self->{next_char} == 0x005B) { # [                 $self->{next_char} == 0x005B) { # [
2042            !!!cp (135.4);                
2043            $self->{state} = MD_CDATA_STATE;
2044            $self->{state_keyword} = '[';
2045          !!!next-input-character;          !!!next-input-character;
2046          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);  
         }  
2047        } else {        } else {
2048          !!!cp (136);          !!!cp (136);
2049        }        }
2050    
2051        !!!parse-error (type => 'bogus comment');        !!!parse-error (type => 'bogus comment',
2052        $self->{next_char} = shift @next_char;                        line => $self->{line_prev},
2053        !!!back-next-input-character (@next_char);                        column => $self->{column_prev} - 1);
2054          ## Reconsume.
2055        $self->{state} = BOGUS_COMMENT_STATE;        $self->{state} = BOGUS_COMMENT_STATE;
2056        $self->{current_token} = {type => COMMENT_TOKEN, data => '',        $self->{current_token} = {type => COMMENT_TOKEN, data => '',
2057                                  line => $l, column => $c,                                  line => $self->{line_prev},
2058                                    column => $self->{column_prev} - 1,
2059                                 };                                 };
2060        redo A;        redo A;
2061              } elsif ($self->{state} == MD_HYPHEN_STATE) {
2062        ## ISSUE: typos in spec: chacacters, is is a parse error        if ($self->{next_char} == 0x002D) { # -
2063        ## 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);
2064            $self->{current_token} = {type => COMMENT_TOKEN, data => '',
2065                                      line => $self->{line_prev},
2066                                      column => $self->{column_prev} - 2,
2067                                     };
2068            $self->{state} = COMMENT_START_STATE;
2069            !!!next-input-character;
2070            redo A;
2071          } else {
2072            !!!cp (128);
2073            !!!parse-error (type => 'bogus comment',
2074                            line => $self->{line_prev},
2075                            column => $self->{column_prev} - 2);
2076            $self->{state} = BOGUS_COMMENT_STATE;
2077            ## Reconsume.
2078            $self->{current_token} = {type => COMMENT_TOKEN,
2079                                      data => '-',
2080                                      line => $self->{line_prev},
2081                                      column => $self->{column_prev} - 2,
2082                                     };
2083            redo A;
2084          }
2085        } elsif ($self->{state} == MD_DOCTYPE_STATE) {
2086          ## ASCII case-insensitive.
2087          if ($self->{next_char} == [
2088                undef,
2089                0x004F, # O
2090                0x0043, # C
2091                0x0054, # T
2092                0x0059, # Y
2093                0x0050, # P
2094              ]->[length $self->{state_keyword}] or
2095              $self->{next_char} == [
2096                undef,
2097                0x006F, # o
2098                0x0063, # c
2099                0x0074, # t
2100                0x0079, # y
2101                0x0070, # p
2102              ]->[length $self->{state_keyword}]) {
2103            !!!cp (131);
2104            ## Stay in the state.
2105            $self->{state_keyword} .= chr $self->{next_char};
2106            !!!next-input-character;
2107            redo A;
2108          } elsif ((length $self->{state_keyword}) == 6 and
2109                   ($self->{next_char} == 0x0045 or # E
2110                    $self->{next_char} == 0x0065)) { # e
2111            !!!cp (129);
2112            $self->{state} = DOCTYPE_STATE;
2113            $self->{current_token} = {type => DOCTYPE_TOKEN,
2114                                      quirks => 1,
2115                                      line => $self->{line_prev},
2116                                      column => $self->{column_prev} - 7,
2117                                     };
2118            !!!next-input-character;
2119            redo A;
2120          } else {
2121            !!!cp (132);        
2122            !!!parse-error (type => 'bogus comment',
2123                            line => $self->{line_prev},
2124                            column => $self->{column_prev} - 1 - length $self->{state_keyword});
2125            $self->{state} = BOGUS_COMMENT_STATE;
2126            ## Reconsume.
2127            $self->{current_token} = {type => COMMENT_TOKEN,
2128                                      data => $self->{state_keyword},
2129                                      line => $self->{line_prev},
2130                                      column => $self->{column_prev} - 1 - length $self->{state_keyword},
2131                                     };
2132            redo A;
2133          }
2134        } elsif ($self->{state} == MD_CDATA_STATE) {
2135          if ($self->{next_char} == {
2136                '[' => 0x0043, # C
2137                '[C' => 0x0044, # D
2138                '[CD' => 0x0041, # A
2139                '[CDA' => 0x0054, # T
2140                '[CDAT' => 0x0041, # A
2141              }->{$self->{state_keyword}}) {
2142            !!!cp (135.1);
2143            ## Stay in the state.
2144            $self->{state_keyword} .= chr $self->{next_char};
2145            !!!next-input-character;
2146            redo A;
2147          } elsif ($self->{state_keyword} eq '[CDATA' and
2148                   $self->{next_char} == 0x005B) { # [
2149            !!!cp (135.2);
2150            $self->{current_token} = {type => CHARACTER_TOKEN,
2151                                      data => '',
2152                                      line => $self->{line_prev},
2153                                      column => $self->{column_prev} - 7};
2154            $self->{state} = CDATA_SECTION_STATE;
2155            !!!next-input-character;
2156            redo A;
2157          } else {
2158            !!!cp (135.3);
2159            !!!parse-error (type => 'bogus comment',
2160                            line => $self->{line_prev},
2161                            column => $self->{column_prev} - 1 - length $self->{state_keyword});
2162            $self->{state} = BOGUS_COMMENT_STATE;
2163            ## Reconsume.
2164            $self->{current_token} = {type => COMMENT_TOKEN,
2165                                      data => $self->{state_keyword},
2166                                      line => $self->{line_prev},
2167                                      column => $self->{column_prev} - 1 - length $self->{state_keyword},
2168                                     };
2169            redo A;
2170          }
2171      } elsif ($self->{state} == COMMENT_START_STATE) {      } elsif ($self->{state} == COMMENT_START_STATE) {
2172        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
2173          !!!cp (137);          !!!cp (137);
# Line 2288  sub _get_next_token ($) { Line 2434  sub _get_next_token ($) {
2434          redo A;          redo A;
2435        } elsif ($self->{next_char} == 0x0050 or # P        } elsif ($self->{next_char} == 0x0050 or # P
2436                 $self->{next_char} == 0x0070) { # p                 $self->{next_char} == 0x0070) { # p
2437            $self->{state} = PUBLIC_STATE;
2438            $self->{state_keyword} = chr $self->{next_char};
2439          !!!next-input-character;          !!!next-input-character;
2440          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);  
         }  
   
         #  
2441        } elsif ($self->{next_char} == 0x0053 or # S        } elsif ($self->{next_char} == 0x0053 or # S
2442                 $self->{next_char} == 0x0073) { # s                 $self->{next_char} == 0x0073) { # s
2443            $self->{state} = SYSTEM_STATE;
2444            $self->{state_keyword} = chr $self->{next_char};
2445          !!!next-input-character;          !!!next-input-character;
2446          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);  
         }  
   
         #  
2447        } else {        } else {
2448          !!!cp (180);          !!!cp (180);
2449            !!!parse-error (type => 'string after DOCTYPE name');
2450            $self->{current_token}->{quirks} = 1;
2451    
2452            $self->{state} = BOGUS_DOCTYPE_STATE;
2453          !!!next-input-character;          !!!next-input-character;
2454          #          redo A;
2455        }        }
2456        } elsif ($self->{state} == PUBLIC_STATE) {
2457          ## ASCII case-insensitive
2458          if ($self->{next_char} == [
2459                undef,
2460                0x0055, # U
2461                0x0042, # B
2462                0x004C, # L
2463                0x0049, # I
2464              ]->[length $self->{state_keyword}] or
2465              $self->{next_char} == [
2466                undef,
2467                0x0075, # u
2468                0x0062, # b
2469                0x006C, # l
2470                0x0069, # i
2471              ]->[length $self->{state_keyword}]) {
2472            !!!cp (175);
2473            ## Stay in the state.
2474            $self->{state_keyword} .= chr $self->{next_char};
2475            !!!next-input-character;
2476            redo A;
2477          } elsif ((length $self->{state_keyword}) == 5 and
2478                   ($self->{next_char} == 0x0043 or # C
2479                    $self->{next_char} == 0x0063)) { # c
2480            !!!cp (168);
2481            $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
2482            !!!next-input-character;
2483            redo A;
2484          } else {
2485            !!!cp (169);
2486            !!!parse-error (type => 'string after DOCTYPE name',
2487                            line => $self->{line_prev},
2488                            column => $self->{column_prev} + 1 - length $self->{state_keyword});
2489            $self->{current_token}->{quirks} = 1;
2490    
2491        !!!parse-error (type => 'string after DOCTYPE name');          $self->{state} = BOGUS_DOCTYPE_STATE;
2492        $self->{current_token}->{quirks} = 1;          ## Reconsume.
2493            redo A;
2494          }
2495        } elsif ($self->{state} == SYSTEM_STATE) {
2496          ## ASCII case-insensitive
2497          if ($self->{next_char} == [
2498                undef,
2499                0x0059, # Y
2500                0x0053, # S
2501                0x0054, # T
2502                0x0045, # E
2503              ]->[length $self->{state_keyword}] or
2504              $self->{next_char} == [
2505                undef,
2506                0x0079, # y
2507                0x0073, # s
2508                0x0074, # t
2509                0x0065, # e
2510              ]->[length $self->{state_keyword}]) {
2511            !!!cp (170);
2512            ## Stay in the state.
2513            $self->{state_keyword} .= chr $self->{next_char};
2514            !!!next-input-character;
2515            redo A;
2516          } elsif ((length $self->{state_keyword}) == 5 and
2517                   ($self->{next_char} == 0x004D or # M
2518                    $self->{next_char} == 0x006D)) { # m
2519            !!!cp (171);
2520            $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2521            !!!next-input-character;
2522            redo A;
2523          } else {
2524            !!!cp (172);
2525            !!!parse-error (type => 'string after DOCTYPE name',
2526                            line => $self->{line_prev},
2527                            column => $self->{column_prev} + 1 - length $self->{state_keyword});
2528            $self->{current_token}->{quirks} = 1;
2529    
2530        $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2531        # next-input-character is already done          ## Reconsume.
2532        redo A;          redo A;
2533          }
2534      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {
2535        if ({        if ({
2536              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
# Line 2606  sub _get_next_token ($) { Line 2763  sub _get_next_token ($) {
2763          redo A;          redo A;
2764        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2765          !!!cp (208);          !!!cp (208);
2766          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2767    
2768          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2769          !!!next-input-character;          !!!next-input-character;
# Line 2642  sub _get_next_token ($) { Line 2799  sub _get_next_token ($) {
2799          redo A;          redo A;
2800        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2801          !!!cp (212);          !!!cp (212);
2802          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2803    
2804          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2805          !!!next-input-character;          !!!next-input-character;
# Line 2690  sub _get_next_token ($) { Line 2847  sub _get_next_token ($) {
2847        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
2848          !!!cp (217);          !!!cp (217);
2849          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
   
2850          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2851          ## reconsume          ## reconsume
2852    
# Line 2731  sub _get_next_token ($) { Line 2887  sub _get_next_token ($) {
2887          !!!next-input-character;          !!!next-input-character;
2888          redo A;          redo A;
2889        }        }
2890      } elsif ($self->{state} == CDATA_BLOCK_STATE) {      } elsif ($self->{state} == CDATA_SECTION_STATE) {
2891        my $s = '';        ## NOTE: "CDATA section state" in the state is jointly implemented
2892          ## by three states, |CDATA_SECTION_STATE|, |CDATA_SECTION_MSE1_STATE|,
2893          ## and |CDATA_SECTION_MSE2_STATE|.
2894                
2895        my ($l, $c) = ($self->{line}, $self->{column});        if ($self->{next_char} == 0x005D) { # ]
2896            !!!cp (221.1);
2897            $self->{state} = CDATA_SECTION_MSE1_STATE;
2898            !!!next-input-character;
2899            redo A;
2900          } elsif ($self->{next_char} == -1) {
2901            $self->{state} = DATA_STATE;
2902            !!!next-input-character;
2903            if (length $self->{current_token}->{data}) { # character
2904              !!!cp (221.2);
2905              !!!emit ($self->{current_token}); # character
2906            } else {
2907              !!!cp (221.3);
2908              ## No token to emit. $self->{current_token} is discarded.
2909            }        
2910            redo A;
2911          } else {
2912            !!!cp (221.4);
2913            $self->{current_token}->{data} .= chr $self->{next_char};
2914            ## Stay in the state.
2915            !!!next-input-character;
2916            redo A;
2917          }
2918    
2919        CS: while ($self->{next_char} != -1) {        ## ISSUE: "text tokens" in spec.
2920          if ($self->{next_char} == 0x005D) { # ]      } elsif ($self->{state} == CDATA_SECTION_MSE1_STATE) {
2921            !!!next-input-character;        if ($self->{next_char} == 0x005D) { # ]
2922            if ($self->{next_char} == 0x005D) { # ]          !!!cp (221.5);
2923              !!!next-input-character;          $self->{state} = CDATA_SECTION_MSE2_STATE;
2924              MDC: {          !!!next-input-character;
2925                if ($self->{next_char} == 0x003E) { # >          redo A;
2926                  !!!cp (221.1);        } else {
2927                  !!!next-input-character;          !!!cp (221.6);
2928                  last CS;          $self->{current_token}->{data} .= ']';
2929                } elsif ($self->{next_char} == 0x005D) { # ]          $self->{state} = CDATA_SECTION_STATE;
2930                  !!!cp (221.2);          ## Reconsume.
2931                  $s .= ']';          redo A;
2932                  !!!next-input-character;        }
2933                  redo MDC;      } elsif ($self->{state} == CDATA_SECTION_MSE2_STATE) {
2934                } else {        if ($self->{next_char} == 0x003E) { # >
2935                  !!!cp (221.3);          $self->{state} = DATA_STATE;
2936                  $s .= ']]';          !!!next-input-character;
2937                  #          if (length $self->{current_token}->{data}) { # character
2938                }            !!!cp (221.7);
2939              } # MDC            !!!emit ($self->{current_token}); # character
           } else {  
             !!!cp (221.4);  
             $s .= ']';  
             #  
           }  
2940          } else {          } else {
2941            !!!cp (221.5);            !!!cp (221.8);
2942            #            ## No token to emit. $self->{current_token} is discarded.
2943          }          }
2944          $s .= chr $self->{next_char};          redo A;
2945          } elsif ($self->{next_char} == 0x005D) { # ]
2946            !!!cp (221.9); # character
2947            $self->{current_token}->{data} .= ']'; ## Add first "]" of "]]]".
2948            ## Stay in the state.
2949          !!!next-input-character;          !!!next-input-character;
2950        } # CS          redo A;
   
       $self->{state} = DATA_STATE;  
       ## next-input-character done or EOF, which is reconsumed.  
   
       if (length $s) {  
         !!!cp (221.6);  
         !!!emit ({type => CHARACTER_TOKEN, data => $s,  
                   line => $l, column => $c});  
2951        } else {        } else {
2952          !!!cp (221.7);          !!!cp (221.11);
2953            $self->{current_token}->{data} .= ']]'; # character
2954            $self->{state} = CDATA_SECTION_STATE;
2955            ## Reconsume.
2956            redo A;
2957          }
2958        } elsif ($self->{state} == ENTITY_STATE) {
2959          if ({
2960            0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,
2961            0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, &
2962            $self->{entity_additional} => 1,
2963          }->{$self->{next_char}}) {
2964            !!!cp (1001);
2965            ## Don't consume
2966            ## No error
2967            ## Return nothing.
2968            #
2969          } elsif ($self->{next_char} == 0x0023) { # #
2970            !!!cp (999);
2971            $self->{state} = ENTITY_HASH_STATE;
2972            $self->{state_keyword} = '#';
2973            !!!next-input-character;
2974            redo A;
2975          } elsif ((0x0041 <= $self->{next_char} and
2976                    $self->{next_char} <= 0x005A) or # A..Z
2977                   (0x0061 <= $self->{next_char} and
2978                    $self->{next_char} <= 0x007A)) { # a..z
2979            !!!cp (998);
2980            require Whatpm::_NamedEntityList;
2981            $self->{state} = ENTITY_NAME_STATE;
2982            $self->{state_keyword} = chr $self->{next_char};
2983            $self->{entity__value} = $self->{state_keyword};
2984            $self->{entity__match} = 0;
2985            !!!next-input-character;
2986            redo A;
2987          } else {
2988            !!!cp (1027);
2989            !!!parse-error (type => 'bare ero');
2990            ## Return nothing.
2991            #
2992        }        }
2993    
2994        redo A;        ## NOTE: No character is consumed by the "consume a character
2995          ## reference" algorithm.  In other word, there is an "&" character
2996        ## ISSUE: "text tokens" in spec.        ## that does not introduce a character reference, which would be
2997        ## TODO: Streaming support        ## appended to the parent element or the attribute value in later
2998      } else {        ## process of the tokenizer.
2999        die "$0: $self->{state}: Unknown state";  
3000      }        if ($self->{prev_state} == DATA_STATE) {
3001    } # A            !!!cp (997);
3002            $self->{state} = $self->{prev_state};
3003    die "$0: _get_next_token: unexpected case";          ## Reconsume.
3004  } # _get_next_token          !!!emit ({type => CHARACTER_TOKEN, data => '&',
3005                      line => $self->{line_prev},
3006  sub _tokenize_attempt_to_consume_an_entity ($$$) {                    column => $self->{column_prev},
3007    my ($self, $in_attr, $additional) = @_;                   });
3008            redo A;
3009    my ($l, $c) = ($self->{line_prev}, $self->{column_prev});        } else {
3010            !!!cp (996);
3011            $self->{current_attribute}->{value} .= '&';
3012            $self->{state} = $self->{prev_state};
3013            ## Reconsume.
3014            redo A;
3015          }
3016        } elsif ($self->{state} == ENTITY_HASH_STATE) {
3017          if ($self->{next_char} == 0x0078 or # x
3018              $self->{next_char} == 0x0058) { # X
3019            !!!cp (995);
3020            $self->{state} = HEXREF_X_STATE;
3021            $self->{state_keyword} .= chr $self->{next_char};
3022            !!!next-input-character;
3023            redo A;
3024          } elsif (0x0030 <= $self->{next_char} and
3025                   $self->{next_char} <= 0x0039) { # 0..9
3026            !!!cp (994);
3027            $self->{state} = NCR_NUM_STATE;
3028            $self->{state_keyword} = $self->{next_char} - 0x0030;
3029            !!!next-input-character;
3030            redo A;
3031          } else {
3032            !!!parse-error (type => 'bare nero',
3033                            line => $self->{line_prev},
3034                            column => $self->{column_prev} - 1);
3035    
3036    if ({          ## NOTE: According to the spec algorithm, nothing is returned,
3037         0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,          ## and then "&#" is appended to the parent element or the attribute
3038         0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR          ## value in the later processing.
3039         $additional => 1,  
3040        }->{$self->{next_char}}) {          if ($self->{prev_state} == DATA_STATE) {
3041      !!!cp (1001);            !!!cp (1019);
3042      ## Don't consume            $self->{state} = $self->{prev_state};
3043      ## No error            ## Reconsume.
3044      return undef;            !!!emit ({type => CHARACTER_TOKEN,
3045    } elsif ($self->{next_char} == 0x0023) { # #                      data => '&#',
3046      !!!next-input-character;                      line => $self->{line_prev},
3047      if ($self->{next_char} == 0x0078 or # x                      column => $self->{column_prev} - 1,
3048          $self->{next_char} == 0x0058) { # X                     });
3049        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;  
3050          } else {          } else {
3051            !!!cp (1007);            !!!cp (993);
3052            !!!parse-error (type => 'no refc', line => $l, column => $c);            $self->{current_attribute}->{value} .= '&#';
3053              $self->{state} = $self->{prev_state};
3054              ## Reconsume.
3055              redo A;
3056          }          }
3057          }
3058          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {      } elsif ($self->{state} == NCR_NUM_STATE) {
3059            !!!cp (1008);        if (0x0030 <= $self->{next_char} and
3060            !!!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  
3061          !!!cp (1012);          !!!cp (1012);
3062          $code *= 10;          $self->{state_keyword} *= 10;
3063          $code += $self->{next_char} - 0x0030;          $self->{state_keyword} += $self->{next_char} - 0x0030;
3064                    
3065            ## Stay in the state.
3066          !!!next-input-character;          !!!next-input-character;
3067        }          redo A;
3068          } elsif ($self->{next_char} == 0x003B) { # ;
       if ($self->{next_char} == 0x003B) { # ;  
3069          !!!cp (1013);          !!!cp (1013);
3070          !!!next-input-character;          !!!next-input-character;
3071            #
3072        } else {        } else {
3073          !!!cp (1014);          !!!cp (1014);
3074          !!!parse-error (type => 'no refc', line => $l, column => $c);          !!!parse-error (type => 'no refc');
3075            ## Reconsume.
3076            #
3077        }        }
3078    
3079          my $code = $self->{state_keyword};
3080          my $l = $self->{line_prev};
3081          my $c = $self->{column_prev};
3082        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3083          !!!cp (1015);          !!!cp (1015);
3084          !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3085                            text => (sprintf 'U+%04X', $code),
3086                            line => $l, column => $c);
3087          $code = 0xFFFD;          $code = 0xFFFD;
3088        } elsif ($code > 0x10FFFF) {        } elsif ($code > 0x10FFFF) {
3089          !!!cp (1016);          !!!cp (1016);
3090          !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3091                            text => (sprintf 'U-%08X', $code),
3092                            line => $l, column => $c);
3093          $code = 0xFFFD;          $code = 0xFFFD;
3094        } elsif ($code == 0x000D) {        } elsif ($code == 0x000D) {
3095          !!!cp (1017);          !!!cp (1017);
3096          !!!parse-error (type => 'CR character reference', line => $l, column => $c);          !!!parse-error (type => 'CR character reference',
3097                            line => $l, column => $c);
3098          $code = 0x000A;          $code = 0x000A;
3099        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
3100          !!!cp (1018);          !!!cp (1018);
3101          !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'C1 character reference',
3102                            text => (sprintf 'U+%04X', $code),
3103                            line => $l, column => $c);
3104          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
3105        }        }
3106          
3107        return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1,        if ($self->{prev_state} == DATA_STATE) {
3108                line => $l, column => $c,          !!!cp (992);
3109               };          $self->{state} = $self->{prev_state};
3110      } else {          ## Reconsume.
3111        !!!cp (1019);          !!!emit ({type => CHARACTER_TOKEN, data => chr $code,
3112        !!!parse-error (type => 'bare nero', line => $l, column => $c);                    line => $l, column => $c,
3113        !!!back-next-input-character ($self->{next_char});                   });
3114        $self->{next_char} = 0x0023; # #          redo A;
3115        return undef;        } else {
3116      }          !!!cp (991);
3117    } elsif ((0x0041 <= $self->{next_char} and          $self->{current_attribute}->{value} .= chr $code;
3118              $self->{next_char} <= 0x005A) or          $self->{current_attribute}->{has_reference} = 1;
3119             (0x0061 <= $self->{next_char} and          $self->{state} = $self->{prev_state};
3120              $self->{next_char} <= 0x007A)) {          ## Reconsume.
3121      my $entity_name = chr $self->{next_char};          redo A;
3122      !!!next-input-character;        }
3123        } elsif ($self->{state} == HEXREF_X_STATE) {
3124      my $value = $entity_name;        if ((0x0030 <= $self->{next_char} and $self->{next_char} <= 0x0039) or
3125      my $match = 0;            (0x0041 <= $self->{next_char} and $self->{next_char} <= 0x0046) or
3126      require Whatpm::_NamedEntityList;            (0x0061 <= $self->{next_char} and $self->{next_char} <= 0x0066)) {
3127      our $EntityChar;          # 0..9, A..F, a..f
3128            !!!cp (990);
3129      while (length $entity_name < 30 and          $self->{state} = HEXREF_HEX_STATE;
3130             ## NOTE: Some number greater than the maximum length of entity name          $self->{state_keyword} = 0;
3131             ((0x0041 <= $self->{next_char} and # a          ## Reconsume.
3132               $self->{next_char} <= 0x005A) or # x          redo A;
3133              (0x0061 <= $self->{next_char} and # a        } else {
3134               $self->{next_char} <= 0x007A) or # z          !!!parse-error (type => 'bare hcro',
3135              (0x0030 <= $self->{next_char} and # 0                          line => $self->{line_prev},
3136               $self->{next_char} <= 0x0039) or # 9                          column => $self->{column_prev} - 2);
3137              $self->{next_char} == 0x003B)) { # ;  
3138        $entity_name .= chr $self->{next_char};          ## NOTE: According to the spec algorithm, nothing is returned,
3139        if (defined $EntityChar->{$entity_name}) {          ## and then "&#" followed by "X" or "x" is appended to the parent
3140          if ($self->{next_char} == 0x003B) { # ;          ## element or the attribute value in the later processing.
3141            !!!cp (1020);  
3142            $value = $EntityChar->{$entity_name};          if ($self->{prev_state} == DATA_STATE) {
3143            $match = 1;            !!!cp (1005);
3144            !!!next-input-character;            $self->{state} = $self->{prev_state};
3145            last;            ## Reconsume.
3146              !!!emit ({type => CHARACTER_TOKEN,
3147                        data => '&' . $self->{state_keyword},
3148                        line => $self->{line_prev},
3149                        column => $self->{column_prev} - length $self->{state_keyword},
3150                       });
3151              redo A;
3152            } else {
3153              !!!cp (989);
3154              $self->{current_attribute}->{value} .= '&' . $self->{state_keyword};
3155              $self->{state} = $self->{prev_state};
3156              ## Reconsume.
3157              redo A;
3158            }
3159          }
3160        } elsif ($self->{state} == HEXREF_HEX_STATE) {
3161          if (0x0030 <= $self->{next_char} and $self->{next_char} <= 0x0039) {
3162            # 0..9
3163            !!!cp (1002);
3164            $self->{state_keyword} *= 0x10;
3165            $self->{state_keyword} += $self->{next_char} - 0x0030;
3166            ## Stay in the state.
3167            !!!next-input-character;
3168            redo A;
3169          } elsif (0x0061 <= $self->{next_char} and
3170                   $self->{next_char} <= 0x0066) { # a..f
3171            !!!cp (1003);
3172            $self->{state_keyword} *= 0x10;
3173            $self->{state_keyword} += $self->{next_char} - 0x0060 + 9;
3174            ## Stay in the state.
3175            !!!next-input-character;
3176            redo A;
3177          } elsif (0x0041 <= $self->{next_char} and
3178                   $self->{next_char} <= 0x0046) { # A..F
3179            !!!cp (1004);
3180            $self->{state_keyword} *= 0x10;
3181            $self->{state_keyword} += $self->{next_char} - 0x0040 + 9;
3182            ## Stay in the state.
3183            !!!next-input-character;
3184            redo A;
3185          } elsif ($self->{next_char} == 0x003B) { # ;
3186            !!!cp (1006);
3187            !!!next-input-character;
3188            #
3189          } else {
3190            !!!cp (1007);
3191            !!!parse-error (type => 'no refc',
3192                            line => $self->{line},
3193                            column => $self->{column});
3194            ## Reconsume.
3195            #
3196          }
3197    
3198          my $code = $self->{state_keyword};
3199          my $l = $self->{line_prev};
3200          my $c = $self->{column_prev};
3201          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3202            !!!cp (1008);
3203            !!!parse-error (type => 'invalid character reference',
3204                            text => (sprintf 'U+%04X', $code),
3205                            line => $l, column => $c);
3206            $code = 0xFFFD;
3207          } elsif ($code > 0x10FFFF) {
3208            !!!cp (1009);
3209            !!!parse-error (type => 'invalid character reference',
3210                            text => (sprintf 'U-%08X', $code),
3211                            line => $l, column => $c);
3212            $code = 0xFFFD;
3213          } elsif ($code == 0x000D) {
3214            !!!cp (1010);
3215            !!!parse-error (type => 'CR character reference', line => $l, column => $c);
3216            $code = 0x000A;
3217          } elsif (0x80 <= $code and $code <= 0x9F) {
3218            !!!cp (1011);
3219            !!!parse-error (type => 'C1 character reference', text => (sprintf 'U+%04X', $code), line => $l, column => $c);
3220            $code = $c1_entity_char->{$code};
3221          }
3222    
3223          if ($self->{prev_state} == DATA_STATE) {
3224            !!!cp (988);
3225            $self->{state} = $self->{prev_state};
3226            ## Reconsume.
3227            !!!emit ({type => CHARACTER_TOKEN, data => chr $code,
3228                      line => $l, column => $c,
3229                     });
3230            redo A;
3231          } else {
3232            !!!cp (987);
3233            $self->{current_attribute}->{value} .= chr $code;
3234            $self->{current_attribute}->{has_reference} = 1;
3235            $self->{state} = $self->{prev_state};
3236            ## Reconsume.
3237            redo A;
3238          }
3239        } elsif ($self->{state} == ENTITY_NAME_STATE) {
3240          if (length $self->{state_keyword} < 30 and
3241              ## NOTE: Some number greater than the maximum length of entity name
3242              ((0x0041 <= $self->{next_char} and # a
3243                $self->{next_char} <= 0x005A) or # x
3244               (0x0061 <= $self->{next_char} and # a
3245                $self->{next_char} <= 0x007A) or # z
3246               (0x0030 <= $self->{next_char} and # 0
3247                $self->{next_char} <= 0x0039) or # 9
3248               $self->{next_char} == 0x003B)) { # ;
3249            our $EntityChar;
3250            $self->{state_keyword} .= chr $self->{next_char};
3251            if (defined $EntityChar->{$self->{state_keyword}}) {
3252              if ($self->{next_char} == 0x003B) { # ;
3253                !!!cp (1020);
3254                $self->{entity__value} = $EntityChar->{$self->{state_keyword}};
3255                $self->{entity__match} = 1;
3256                !!!next-input-character;
3257                #
3258              } else {
3259                !!!cp (1021);
3260                $self->{entity__value} = $EntityChar->{$self->{state_keyword}};
3261                $self->{entity__match} = -1;
3262                ## Stay in the state.
3263                !!!next-input-character;
3264                redo A;
3265              }
3266          } else {          } else {
3267            !!!cp (1021);            !!!cp (1022);
3268            $value = $EntityChar->{$entity_name};            $self->{entity__value} .= chr $self->{next_char};
3269            $match = -1;            $self->{entity__match} *= 2;
3270              ## Stay in the state.
3271            !!!next-input-character;            !!!next-input-character;
3272              redo A;
3273            }
3274          }
3275    
3276          my $data;
3277          my $has_ref;
3278          if ($self->{entity__match} > 0) {
3279            !!!cp (1023);
3280            $data = $self->{entity__value};
3281            $has_ref = 1;
3282            #
3283          } elsif ($self->{entity__match} < 0) {
3284            !!!parse-error (type => 'no refc');
3285            if ($self->{prev_state} != DATA_STATE and # in attribute
3286                $self->{entity__match} < -1) {
3287              !!!cp (1024);
3288              $data = '&' . $self->{state_keyword};
3289              #
3290            } else {
3291              !!!cp (1025);
3292              $data = $self->{entity__value};
3293              $has_ref = 1;
3294              #
3295          }          }
3296        } else {        } else {
3297          !!!cp (1022);          !!!cp (1026);
3298          $value .= chr $self->{next_char};          !!!parse-error (type => 'bare ero',
3299          $match *= 2;                          line => $self->{line_prev},
3300          !!!next-input-character;                          column => $self->{column_prev});
3301            $data = '&' . $self->{state_keyword};
3302            #
3303        }        }
3304      }    
3305              ## NOTE: In these cases, when a character reference is found,
3306      if ($match > 0) {        ## it is consumed and a character token is returned, or, otherwise,
3307        !!!cp (1023);        ## nothing is consumed and returned, according to the spec algorithm.
3308        return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,        ## In this implementation, anything that has been examined by the
3309                line => $l, column => $c,        ## tokenizer is appended to the parent element or the attribute value
3310               };        ## as string, either literal string when no character reference or
3311      } elsif ($match < 0) {        ## entity-replaced string otherwise, in this stage, since any characters
3312        !!!parse-error (type => 'no refc', line => $l, column => $c);        ## that would not be consumed are appended in the data state or in an
3313        if ($in_attr and $match < -1) {        ## appropriate attribute value state anyway.
3314          !!!cp (1024);  
3315          return {type => CHARACTER_TOKEN, data => '&'.$entity_name,        if ($self->{prev_state} == DATA_STATE) {
3316                  line => $l, column => $c,          !!!cp (986);
3317                 };          $self->{state} = $self->{prev_state};
3318        } else {          ## Reconsume.
3319          !!!cp (1025);          !!!emit ({type => CHARACTER_TOKEN,
3320          return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,                    data => $data,
3321                  line => $l, column => $c,                    line => $self->{line_prev},
3322                 };                    column => $self->{column_prev} + 1 - length $self->{state_keyword},
3323                     });
3324            redo A;
3325          } else {
3326            !!!cp (985);
3327            $self->{current_attribute}->{value} .= $data;
3328            $self->{current_attribute}->{has_reference} = 1 if $has_ref;
3329            $self->{state} = $self->{prev_state};
3330            ## Reconsume.
3331            redo A;
3332        }        }
3333      } else {      } else {
3334        !!!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,  
              };  
3335      }      }
3336    } else {    } # A  
3337      !!!cp (1027);  
3338      ## no characters are consumed    die "$0: _get_next_token: unexpected case";
3339      !!!parse-error (type => 'bare ero', line => $l, column => $c);  } # _get_next_token
     return undef;  
   }  
 } # _tokenize_attempt_to_consume_an_entity  
3340    
3341  sub _initialize_tree_constructor ($) {  sub _initialize_tree_constructor ($) {
3342    my $self = shift;    my $self = shift;
# Line 3007  sub _initialize_tree_constructor ($) { Line 3345  sub _initialize_tree_constructor ($) {
3345    ## TODO: Turn mutation events off # MUST    ## TODO: Turn mutation events off # MUST
3346    ## TODO: Turn loose Document option (manakai extension) on    ## TODO: Turn loose Document option (manakai extension) on
3347    $self->{document}->manakai_is_html (1); # MUST    $self->{document}->manakai_is_html (1); # MUST
3348      $self->{document}->set_user_data (manakai_source_line => 1);
3349      $self->{document}->set_user_data (manakai_source_column => 1);
3350  } # _initialize_tree_constructor  } # _initialize_tree_constructor
3351    
3352  sub _terminate_tree_constructor ($) {  sub _terminate_tree_constructor ($) {
# Line 3061  sub _tree_construction_initial ($) { Line 3401  sub _tree_construction_initial ($) {
3401        ## language.        ## language.
3402        my $doctype_name = $token->{name};        my $doctype_name = $token->{name};
3403        $doctype_name = '' unless defined $doctype_name;        $doctype_name = '' unless defined $doctype_name;
3404        $doctype_name =~ tr/a-z/A-Z/;        $doctype_name =~ tr/a-z/A-Z/; # ASCII case-insensitive
3405        if (not defined $token->{name} or # <!DOCTYPE>        if (not defined $token->{name} or # <!DOCTYPE>
           defined $token->{public_identifier} or  
3406            defined $token->{system_identifier}) {            defined $token->{system_identifier}) {
3407          !!!cp ('t1');          !!!cp ('t1');
3408          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3409        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
3410          !!!cp ('t2');          !!!cp ('t2');
         ## ISSUE: ASCII case-insensitive? (in fact it does not matter)  
3411          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3412          } elsif (defined $token->{public_identifier}) {
3413            if ($token->{public_identifier} eq 'XSLT-compat') {
3414              !!!cp ('t1.2');
3415              !!!parse-error (type => 'XSLT-compat', token => $token,
3416                              level => $self->{level}->{should});
3417            } else {
3418              !!!parse-error (type => 'not HTML5', token => $token);
3419            }
3420        } else {        } else {
3421          !!!cp ('t3');          !!!cp ('t3');
3422            #
3423        }        }
3424                
3425        my $doctype = $self->{document}->create_document_type_definition        my $doctype = $self->{document}->create_document_type_definition
# Line 3093  sub _tree_construction_initial ($) { Line 3440  sub _tree_construction_initial ($) {
3440        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{public_identifier}) {
3441          my $pubid = $token->{public_identifier};          my $pubid = $token->{public_identifier};
3442          $pubid =~ tr/a-z/A-z/;          $pubid =~ tr/a-z/A-z/;
3443          if ({          my $prefix = [
3444            "+//SILMARIL//DTD HTML PRO V0R11 19970101//EN" => 1,            "+//SILMARIL//DTD HTML PRO V0R11 19970101//",
3445            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3446            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3447            "-//IETF//DTD HTML 2.0 LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 1//",
3448            "-//IETF//DTD HTML 2.0 LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 2//",
3449            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//",
3450            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//",
3451            "-//IETF//DTD HTML 2.0 STRICT//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT//",
3452            "-//IETF//DTD HTML 2.0//EN" => 1,            "-//IETF//DTD HTML 2.0//",
3453            "-//IETF//DTD HTML 2.1E//EN" => 1,            "-//IETF//DTD HTML 2.1E//",
3454            "-//IETF//DTD HTML 3.0//EN" => 1,            "-//IETF//DTD HTML 3.0//",
3455            "-//IETF//DTD HTML 3.0//EN//" => 1,            "-//IETF//DTD HTML 3.2 FINAL//",
3456            "-//IETF//DTD HTML 3.2 FINAL//EN" => 1,            "-//IETF//DTD HTML 3.2//",
3457            "-//IETF//DTD HTML 3.2//EN" => 1,            "-//IETF//DTD HTML 3//",
3458            "-//IETF//DTD HTML 3//EN" => 1,            "-//IETF//DTD HTML LEVEL 0//",
3459            "-//IETF//DTD HTML LEVEL 0//EN" => 1,            "-//IETF//DTD HTML LEVEL 1//",
3460            "-//IETF//DTD HTML LEVEL 0//EN//2.0" => 1,            "-//IETF//DTD HTML LEVEL 2//",
3461            "-//IETF//DTD HTML LEVEL 1//EN" => 1,            "-//IETF//DTD HTML LEVEL 3//",
3462            "-//IETF//DTD HTML LEVEL 1//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 0//",
3463            "-//IETF//DTD HTML LEVEL 2//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 1//",
3464            "-//IETF//DTD HTML LEVEL 2//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 2//",
3465            "-//IETF//DTD HTML LEVEL 3//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 3//",
3466            "-//IETF//DTD HTML LEVEL 3//EN//3.0" => 1,            "-//IETF//DTD HTML STRICT//",
3467            "-//IETF//DTD HTML STRICT LEVEL 0//EN" => 1,            "-//IETF//DTD HTML//",
3468            "-//IETF//DTD HTML STRICT LEVEL 0//EN//2.0" => 1,            "-//METRIUS//DTD METRIUS PRESENTATIONAL//",
3469            "-//IETF//DTD HTML STRICT LEVEL 1//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//",
3470            "-//IETF//DTD HTML STRICT LEVEL 1//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//",
3471            "-//IETF//DTD HTML STRICT LEVEL 2//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//",
3472            "-//IETF//DTD HTML STRICT LEVEL 2//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//",
3473            "-//IETF//DTD HTML STRICT LEVEL 3//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//",
3474            "-//IETF//DTD HTML STRICT LEVEL 3//EN//3.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//",
3475            "-//IETF//DTD HTML STRICT//EN" => 1,            "-//NETSCAPE COMM. CORP.//DTD HTML//",
3476            "-//IETF//DTD HTML STRICT//EN//2.0" => 1,            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//",
3477            "-//IETF//DTD HTML STRICT//EN//3.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//",
3478            "-//IETF//DTD HTML//EN" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//",
3479            "-//IETF//DTD HTML//EN//2.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//",
3480            "-//IETF//DTD HTML//EN//3.0" => 1,            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//",
3481            "-//METRIUS//DTD METRIUS PRESENTATIONAL//EN" => 1,            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//",
3482            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//EN" => 1,            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//",
3483            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//EN" => 1,            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//",
3484            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//",
3485            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//",
3486            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//EN" => 1,            "-//W3C//DTD HTML 3 1995-03-24//",
3487            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//EN" => 1,            "-//W3C//DTD HTML 3.2 DRAFT//",
3488            "-//NETSCAPE COMM. CORP.//DTD HTML//EN" => 1,            "-//W3C//DTD HTML 3.2 FINAL//",
3489            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//EN" => 1,            "-//W3C//DTD HTML 3.2//",
3490            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//EN" => 1,            "-//W3C//DTD HTML 3.2S DRAFT//",
3491            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 FRAMESET//",
3492            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 TRANSITIONAL//",
3493            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMETNAL 19960712//",
3494            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMENTAL 970421//",
3495            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//EN" => 1,            "-//W3C//DTD W3 HTML//",
3496            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//EN" => 1,            "-//W3O//DTD W3 HTML 3.0//",
3497            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML 2.0//",
3498            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML//",
3499            "-//W3C//DTD HTML 3 1995-03-24//EN" => 1,          ]; # $prefix
3500            "-//W3C//DTD HTML 3.2 DRAFT//EN" => 1,          my $match;
3501            "-//W3C//DTD HTML 3.2 FINAL//EN" => 1,          for (@$prefix) {
3502            "-//W3C//DTD HTML 3.2//EN" => 1,            if (substr ($prefix, 0, length $_) eq $_) {
3503            "-//W3C//DTD HTML 3.2S DRAFT//EN" => 1,              $match = 1;
3504            "-//W3C//DTD HTML 4.0 FRAMESET//EN" => 1,              last;
3505            "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN" => 1,            }
3506            "-//W3C//DTD HTML EXPERIMETNAL 19960712//EN" => 1,          }
3507            "-//W3C//DTD HTML EXPERIMENTAL 970421//EN" => 1,          if ($match or
3508            "-//W3C//DTD W3 HTML//EN" => 1,              $pubid eq "-//W3O//DTD W3 HTML STRICT 3.0//EN//" or
3509            "-//W3O//DTD W3 HTML 3.0//EN" => 1,              $pubid eq "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" or
3510            "-//W3O//DTD W3 HTML 3.0//EN//" => 1,              $pubid eq "HTML") {
           "-//W3O//DTD W3 HTML STRICT 3.0//EN//" => 1,  
           "-//WEBTECHS//DTD MOZILLA HTML 2.0//EN" => 1,  
           "-//WEBTECHS//DTD MOZILLA HTML//EN" => 1,  
           "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" => 1,  
           "HTML" => 1,  
         }->{$pubid}) {  
3511            !!!cp ('t5');            !!!cp ('t5');
3512            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3513          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD HTML 4.01 FRAMESET//] or
3514                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD HTML 4.01 TRANSITIONAL//]) {
3515            if (defined $token->{system_identifier}) {            if (defined $token->{system_identifier}) {
3516              !!!cp ('t6');              !!!cp ('t6');
3517              $self->{document}->manakai_compat_mode ('quirks');              $self->{document}->manakai_compat_mode ('quirks');
# Line 3178  sub _tree_construction_initial ($) { Line 3519  sub _tree_construction_initial ($) {
3519              !!!cp ('t7');              !!!cp ('t7');
3520              $self->{document}->manakai_compat_mode ('limited quirks');              $self->{document}->manakai_compat_mode ('limited quirks');
3521            }            }
3522          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD XHTML 1.0 FRAMESET//] or
3523                   $pubid eq "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD XHTML 1.0 TRANSITIONAL//]) {
3524            !!!cp ('t8');            !!!cp ('t8');
3525            $self->{document}->manakai_compat_mode ('limited quirks');            $self->{document}->manakai_compat_mode ('limited quirks');
3526          } else {          } else {
# Line 3192  sub _tree_construction_initial ($) { Line 3533  sub _tree_construction_initial ($) {
3533          my $sysid = $token->{system_identifier};          my $sysid = $token->{system_identifier};
3534          $sysid =~ tr/A-Z/a-z/;          $sysid =~ tr/A-Z/a-z/;
3535          if ($sysid eq "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") {          if ($sysid eq "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") {
3536            ## TODO: Check the spec: PUBLIC "(limited quirks)" "(quirks)"            ## NOTE: Ensure that |PUBLIC "(limited quirks)" "(quirks)"| is
3537              ## marked as quirks.
3538            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3539            !!!cp ('t11');            !!!cp ('t11');
3540          } else {          } else {
# Line 3364  sub _reset_insertion_mode ($) { Line 3706  sub _reset_insertion_mode ($) {
3706        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
3707          $last = 1;          $last = 1;
3708          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
3709            if ($self->{inner_html_node}->[1] & TABLE_CELL_EL) {            !!!cp ('t28');
3710              !!!cp ('t27');            $node = $self->{inner_html_node};
3711              #          } else {
3712            } else {            die "_reset_insertion_mode: t27";
             !!!cp ('t28');  
             $node = $self->{inner_html_node};  
           }  
3713          }          }
3714        }        }
3715              
3716      ## Step 4..14        ## Step 4..14
3717      my $new_mode;        my $new_mode;
3718      if ($node->[1] & FOREIGN_EL) {        if ($node->[1] & FOREIGN_EL) {
3719        ## NOTE: Strictly spaking, the line below only applies to MathML and          !!!cp ('t28.1');
3720        ## SVG elements.  Currently the HTML syntax supports only MathML and          ## NOTE: Strictly spaking, the line below only applies to MathML and
3721        ## SVG elements as foreigners.          ## SVG elements.  Currently the HTML syntax supports only MathML and
3722        $new_mode = $self->{insertion_mode} | IN_FOREIGN_CONTENT_IM;          ## SVG elements as foreigners.
3723        ## ISSUE: What is set as the secondary insertion mode?          $new_mode = IN_BODY_IM | IN_FOREIGN_CONTENT_IM;
3724      } else {        } elsif ($node->[1] & TABLE_CELL_EL) {
3725        $new_mode = {          if ($last) {
3726              !!!cp ('t28.2');
3727              #
3728            } else {
3729              !!!cp ('t28.3');
3730              $new_mode = IN_CELL_IM;
3731            }
3732          } else {
3733            !!!cp ('t28.4');
3734            $new_mode = {
3735                        select => IN_SELECT_IM,                        select => IN_SELECT_IM,
3736                        ## NOTE: |option| and |optgroup| do not set                        ## NOTE: |option| and |optgroup| do not set
3737                        ## insertion mode to "in select" by themselves.                        ## insertion mode to "in select" by themselves.
                       td => IN_CELL_IM,  
                       th => IN_CELL_IM,  
3738                        tr => IN_ROW_IM,                        tr => IN_ROW_IM,
3739                        tbody => IN_TABLE_BODY_IM,                        tbody => IN_TABLE_BODY_IM,
3740                        thead => IN_TABLE_BODY_IM,                        thead => IN_TABLE_BODY_IM,
# Line 3400  sub _reset_insertion_mode ($) { Line 3746  sub _reset_insertion_mode ($) {
3746                        body => IN_BODY_IM,                        body => IN_BODY_IM,
3747                        frameset => IN_FRAMESET_IM,                        frameset => IN_FRAMESET_IM,
3748                       }->{$node->[0]->manakai_local_name};                       }->{$node->[0]->manakai_local_name};
3749      }        }
3750      $self->{insertion_mode} = $new_mode and return if defined $new_mode;        $self->{insertion_mode} = $new_mode and return if defined $new_mode;
3751                
3752        ## Step 15        ## Step 15
3753        if ($node->[1] & HTML_EL) {        if ($node->[1] & HTML_EL) {
# Line 3575  sub _tree_construction_main ($) { Line 3921  sub _tree_construction_main ($) {
3921        ## NOTE: An end-of-file token.        ## NOTE: An end-of-file token.
3922        if ($content_model_flag == CDATA_CONTENT_MODEL) {        if ($content_model_flag == CDATA_CONTENT_MODEL) {
3923          !!!cp ('t43');          !!!cp ('t43');
3924          !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in CDATA:#eof', token => $token);
3925        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
3926          !!!cp ('t44');          !!!cp ('t44');
3927          !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in RCDATA:#eof', token => $token);
3928        } else {        } else {
3929          die "$0: $content_model_flag in parse_rcdata";          die "$0: $content_model_flag in parse_rcdata";
3930        }        }
# Line 3615  sub _tree_construction_main ($) { Line 3961  sub _tree_construction_main ($) {
3961        ## Ignore the token        ## Ignore the token
3962      } else {      } else {
3963        !!!cp ('t48');        !!!cp ('t48');
3964        !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);        !!!parse-error (type => 'in CDATA:#eof', token => $token);
3965        ## ISSUE: And ignore?        ## ISSUE: And ignore?
3966        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
3967      }      }
# Line 3666  sub _tree_construction_main ($) { Line 4012  sub _tree_construction_main ($) {
4012        } # AFE        } # AFE
4013        unless (defined $formatting_element) {        unless (defined $formatting_element) {
4014          !!!cp ('t53');          !!!cp ('t53');
4015          !!!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);
4016          ## Ignore the token          ## Ignore the token
4017          !!!next-token;          !!!next-token;
4018          return;          return;
# Line 3683  sub _tree_construction_main ($) { Line 4029  sub _tree_construction_main ($) {
4029              last INSCOPE;              last INSCOPE;
4030            } else { # in open elements but not in scope            } else { # in open elements but not in scope
4031              !!!cp ('t55');              !!!cp ('t55');
4032              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},              !!!parse-error (type => 'unmatched end tag',
4033                                text => $token->{tag_name},
4034                              token => $end_tag_token);                              token => $end_tag_token);
4035              ## Ignore the token              ## Ignore the token
4036              !!!next-token;              !!!next-token;
# Line 3696  sub _tree_construction_main ($) { Line 4043  sub _tree_construction_main ($) {
4043        } # INSCOPE        } # INSCOPE
4044        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
4045          !!!cp ('t57');          !!!cp ('t57');
4046          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},          !!!parse-error (type => 'unmatched end tag',
4047                            text => $token->{tag_name},
4048                          token => $end_tag_token);                          token => $end_tag_token);
4049          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
4050          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
# Line 3705  sub _tree_construction_main ($) { Line 4053  sub _tree_construction_main ($) {
4053        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
4054          !!!cp ('t58');          !!!cp ('t58');
4055          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
4056                          value => $self->{open_elements}->[-1]->[0]                          text => $self->{open_elements}->[-1]->[0]
4057                              ->manakai_local_name,                              ->manakai_local_name,
4058                          token => $end_tag_token);                          token => $end_tag_token);
4059        }        }
# Line 3914  sub _tree_construction_main ($) { Line 4262  sub _tree_construction_main ($) {
4262    B: while (1) {    B: while (1) {
4263      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
4264        !!!cp ('t73');        !!!cp ('t73');
4265        !!!parse-error (type => 'DOCTYPE in the middle', token => $token);        !!!parse-error (type => 'in html:#DOCTYPE', token => $token);
4266        ## Ignore the token        ## Ignore the token
4267        ## Stay in the phase        ## Stay in the phase
4268        !!!next-token;        !!!next-token;
# Line 3923  sub _tree_construction_main ($) { Line 4271  sub _tree_construction_main ($) {
4271               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
4272        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
4273          !!!cp ('t79');          !!!cp ('t79');
4274          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4275          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
4276        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
4277          !!!cp ('t80');          !!!cp ('t80');
4278          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4279          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
4280        } else {        } else {
4281          !!!cp ('t81');          !!!cp ('t81');
# Line 3978  sub _tree_construction_main ($) { Line 4326  sub _tree_construction_main ($) {
4326            #            #
4327          } elsif ({          } elsif ({
4328                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,
4329                    center => 1, code => 1, dd => 1, div => 1, dl => 1, em => 1,                    center => 1, code => 1, dd => 1, div => 1, dl => 1, dt => 1,
4330                    embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1, ## No h4!                    em => 1, embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1,
4331                    h5 => 1, h6 => 1, head => 1, hr => 1, i => 1, img => 1,                    h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, i => 1,
4332                    li => 1, menu => 1, meta => 1, nobr => 1, p => 1, pre => 1,                    img => 1, li => 1, listing => 1, menu => 1, meta => 1,
4333                    ruby => 1, s => 1, small => 1, span => 1, strong => 1,                    nobr => 1, ol => 1, p => 1, pre => 1, ruby => 1, s => 1,
4334                    sub => 1, sup => 1, table => 1, tt => 1, u => 1, ul => 1,                    small => 1, span => 1, strong => 1, strike => 1, sub => 1,
4335                    var => 1,                    sup => 1, table => 1, tt => 1, u => 1, ul => 1, var => 1,
4336                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
4337            !!!cp ('t87.2');            !!!cp ('t87.2');
4338            !!!parse-error (type => 'not closed',            !!!parse-error (type => 'not closed',
4339                            value => $self->{open_elements}->[-1]->[0]                            text => $self->{open_elements}->[-1]->[0]
4340                                ->manakai_local_name,                                ->manakai_local_name,
4341                            token => $token);                            token => $token);
4342    
# Line 4064  sub _tree_construction_main ($) { Line 4412  sub _tree_construction_main ($) {
4412          !!!cp ('t87.5');          !!!cp ('t87.5');
4413          #          #
4414        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
         ## NOTE: "using the rules for secondary insertion mode" then "continue"  
4415          !!!cp ('t87.6');          !!!cp ('t87.6');
4416          #          !!!parse-error (type => 'not closed',
4417          ## TODO: ...                          text => $self->{open_elements}->[-1]->[0]
4418                                ->manakai_local_name,
4419                            token => $token);
4420    
4421            pop @{$self->{open_elements}}
4422                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;
4423    
4424            $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
4425            ## Reprocess.
4426            next B;
4427        } else {        } else {
4428          die "$0: $token->{type}: Unknown token type";                  die "$0: $token->{type}: Unknown token type";        
4429        }        }
# Line 4108  sub _tree_construction_main ($) { Line 4464  sub _tree_construction_main ($) {
4464            !!!cp ('t90');            !!!cp ('t90');
4465            ## As if </noscript>            ## As if </noscript>
4466            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
4467            !!!parse-error (type => 'in noscript:#character', token => $token);            !!!parse-error (type => 'in noscript:#text', token => $token);
4468                        
4469            ## Reprocess in the "in head" insertion mode...            ## Reprocess in the "in head" insertion mode...
4470            ## As if </head>            ## As if </head>
# Line 4144  sub _tree_construction_main ($) { Line 4500  sub _tree_construction_main ($) {
4500              !!!next-token;              !!!next-token;
4501              next B;              next B;
4502            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4503              !!!cp ('t94');              !!!cp ('t93.2');
4504              #              !!!parse-error (type => 'after head', text => 'head',
4505                                token => $token);
4506                ## Ignore the token
4507                !!!nack ('t93.3');
4508                !!!next-token;
4509                next B;
4510            } else {            } else {
4511              !!!cp ('t95');              !!!cp ('t95');
4512              !!!parse-error (type => 'in head:head', token => $token); # or in head noscript              !!!parse-error (type => 'in head:head',
4513                                token => $token); # or in head noscript
4514              ## Ignore the token              ## Ignore the token
4515              !!!nack ('t95.1');              !!!nack ('t95.1');
4516              !!!next-token;              !!!next-token;
# Line 4173  sub _tree_construction_main ($) { Line 4535  sub _tree_construction_main ($) {
4535                  !!!cp ('t98');                  !!!cp ('t98');
4536                  ## As if </noscript>                  ## As if </noscript>
4537                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4538                  !!!parse-error (type => 'in noscript:base', token => $token);                  !!!parse-error (type => 'in noscript', text => 'base',
4539                                    token => $token);
4540                                
4541                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4542                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
# Line 4184  sub _tree_construction_main ($) { Line 4547  sub _tree_construction_main ($) {
4547                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4548                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4549                  !!!cp ('t100');                  !!!cp ('t100');
4550                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4551                                    text => $token->{tag_name}, token => $token);
4552                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4553                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4554                } else {                } else {
# Line 4201  sub _tree_construction_main ($) { Line 4565  sub _tree_construction_main ($) {
4565                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4566                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4567                  !!!cp ('t102');                  !!!cp ('t102');
4568                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4569                                    text => $token->{tag_name}, token => $token);
4570                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4571                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4572                } else {                } else {
# Line 4218  sub _tree_construction_main ($) { Line 4583  sub _tree_construction_main ($) {
4583                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4584                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4585                  !!!cp ('t104');                  !!!cp ('t104');
4586                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4587                                    text => $token->{tag_name}, token => $token);
4588                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4589                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4590                } else {                } else {
# Line 4242  sub _tree_construction_main ($) { Line 4608  sub _tree_construction_main ($) {
4608                                                 ->{has_reference});                                                 ->{has_reference});
4609                  } elsif ($token->{attributes}->{content}) {                  } elsif ($token->{attributes}->{content}) {
4610                    if ($token->{attributes}->{content}->{value}                    if ($token->{attributes}->{content}->{value}
4611                        =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                        =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
4612                            [\x09-\x0D\x20]*=                            [\x09-\x0D\x20]*=
4613                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
4614                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
4615                      !!!cp ('t107');                      !!!cp ('t107');
4616                      ## NOTE: Whether the encoding is supported or not is handled                      ## NOTE: Whether the encoding is supported or not is handled
4617                      ## in the {change_encoding} callback.                      ## in the {change_encoding} callback.
# Line 4287  sub _tree_construction_main ($) { Line 4653  sub _tree_construction_main ($) {
4653                  !!!cp ('t111');                  !!!cp ('t111');
4654                  ## As if </noscript>                  ## As if </noscript>
4655                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4656                  !!!parse-error (type => 'in noscript:title', token => $token);                  !!!parse-error (type => 'in noscript', text => 'title',
4657                                    token => $token);
4658                                
4659                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4660                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4661                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4662                  !!!cp ('t112');                  !!!cp ('t112');
4663                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4664                                    text => $token->{tag_name}, token => $token);
4665                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4666                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4667                } else {                } else {
# Line 4307  sub _tree_construction_main ($) { Line 4675  sub _tree_construction_main ($) {
4675                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4676                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4677                next B;                next B;
4678              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style' or
4679                         $token->{tag_name} eq 'noframes') {
4680                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and
4681                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
4682                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4683                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4684                  !!!cp ('t114');                  !!!cp ('t114');
4685                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4686                                    text => $token->{tag_name}, token => $token);
4687                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4688                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4689                } else {                } else {
# Line 4334  sub _tree_construction_main ($) { Line 4704  sub _tree_construction_main ($) {
4704                  next B;                  next B;
4705                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4706                  !!!cp ('t117');                  !!!cp ('t117');
4707                  !!!parse-error (type => 'in noscript:noscript', token => $token);                  !!!parse-error (type => 'in noscript', text => 'noscript',
4708                                    token => $token);
4709                  ## Ignore the token                  ## Ignore the token
4710                  !!!nack ('t117.1');                  !!!nack ('t117.1');
4711                  !!!next-token;                  !!!next-token;
# Line 4348  sub _tree_construction_main ($) { Line 4719  sub _tree_construction_main ($) {
4719                  !!!cp ('t119');                  !!!cp ('t119');
4720                  ## As if </noscript>                  ## As if </noscript>
4721                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4722                  !!!parse-error (type => 'in noscript:script', token => $token);                  !!!parse-error (type => 'in noscript', text => 'script',
4723                                    token => $token);
4724                                
4725                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4726                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4727                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4728                  !!!cp ('t120');                  !!!cp ('t120');
4729                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4730                                    text => $token->{tag_name}, token => $token);
4731                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4732                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4733                } else {                } else {
# Line 4372  sub _tree_construction_main ($) { Line 4745  sub _tree_construction_main ($) {
4745                  !!!cp ('t122');                  !!!cp ('t122');
4746                  ## As if </noscript>                  ## As if </noscript>
4747                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4748                  !!!parse-error (type => 'in noscript:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in noscript',
4749                                    text => $token->{tag_name}, token => $token);
4750                                    
4751                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4752                  ## As if </head>                  ## As if </head>
# Line 4411  sub _tree_construction_main ($) { Line 4785  sub _tree_construction_main ($) {
4785                !!!cp ('t129');                !!!cp ('t129');
4786                ## As if </noscript>                ## As if </noscript>
4787                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4788                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4789                                  text => $token->{tag_name}, token => $token);
4790                                
4791                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4792                ## As if </head>                ## As if </head>
# Line 4454  sub _tree_construction_main ($) { Line 4829  sub _tree_construction_main ($) {
4829                  !!!cp ('t133');                  !!!cp ('t133');
4830                  ## As if </noscript>                  ## As if </noscript>
4831                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4832                  !!!parse-error (type => 'in noscript:/head', token => $token);                  !!!parse-error (type => 'in noscript:/',
4833                                    text => 'head', token => $token);
4834                                    
4835                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4836                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 4467  sub _tree_construction_main ($) { Line 4843  sub _tree_construction_main ($) {
4843                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
4844                  !!!next-token;                  !!!next-token;
4845                  next B;                  next B;
4846                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4847                    !!!cp ('t134.1');
4848                    !!!parse-error (type => 'unmatched end tag', text => 'head',
4849                                    token => $token);
4850                    ## Ignore the token
4851                    !!!next-token;
4852                    next B;
4853                } else {                } else {
4854                  !!!cp ('t135');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
                 #  
4855                }                }
4856              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
4857                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
# Line 4478  sub _tree_construction_main ($) { Line 4860  sub _tree_construction_main ($) {
4860                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4861                  !!!next-token;                  !!!next-token;
4862                  next B;                  next B;
4863                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or
4864                           $self->{insertion_mode} == AFTER_HEAD_IM) {
4865                  !!!cp ('t137');                  !!!cp ('t137');
4866                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4867                                    text => 'noscript', token => $token);
4868                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
4869                  !!!next-token;                  !!!next-token;
4870                  next B;                  next B;
# Line 4491  sub _tree_construction_main ($) { Line 4875  sub _tree_construction_main ($) {
4875              } elsif ({              } elsif ({
4876                        body => 1, html => 1,                        body => 1, html => 1,
4877                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4878                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM or
4879                  !!!cp ('t139');                    $self->{insertion_mode} == IN_HEAD_IM or
4880                  ## As if <head>                    $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
                 !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);  
                 $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});  
                 push @{$self->{open_elements}},  
                     [$self->{head_element}, $el_category->{head}];  
   
                 $self->{insertion_mode} = IN_HEAD_IM;  
                 ## Reprocess in the "in head" insertion mode...  
               } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {  
4881                  !!!cp ('t140');                  !!!cp ('t140');
4882                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4883                                    text => $token->{tag_name}, token => $token);
4884                    ## Ignore the token
4885                    !!!next-token;
4886                    next B;
4887                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4888                    !!!cp ('t140.1');
4889                    !!!parse-error (type => 'unmatched end tag',
4890                                    text => $token->{tag_name}, token => $token);
4891                  ## Ignore the token                  ## Ignore the token
4892                  !!!next-token;                  !!!next-token;
4893                  next B;                  next B;
4894                } else {                } else {
4895                  !!!cp ('t141');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
4896                }                }
4897                              } elsif ($token->{tag_name} eq 'p') {
4898                #                !!!cp ('t142');
4899              } elsif ({                !!!parse-error (type => 'unmatched end tag',
4900                        p => 1, br => 1,                                text => $token->{tag_name}, token => $token);
4901                       }->{$token->{tag_name}}) {                ## Ignore the token
4902                  !!!next-token;
4903                  next B;
4904                } elsif ($token->{tag_name} eq 'br') {
4905                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4906                  !!!cp ('t142');                  !!!cp ('t142.2');
4907                  ## As if <head>                  ## (before head) as if <head>, (in head) as if </head>
4908                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
4909                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
4910                  push @{$self->{open_elements}},                  $self->{insertion_mode} = AFTER_HEAD_IM;
4911                      [$self->{head_element}, $el_category->{head}];    
4912                    ## Reprocess in the "after head" insertion mode...
4913                  } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
4914                    !!!cp ('t143.2');
4915                    ## As if </head>
4916                    pop @{$self->{open_elements}};
4917                    $self->{insertion_mode} = AFTER_HEAD_IM;
4918      
4919                    ## Reprocess in the "after head" insertion mode...
4920                  } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4921                    !!!cp ('t143.3');
4922                    ## ISSUE: Two parse errors for <head><noscript></br>
4923                    !!!parse-error (type => 'unmatched end tag',
4924                                    text => 'br', token => $token);
4925                    ## As if </noscript>
4926                    pop @{$self->{open_elements}};
4927                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4928    
4929                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4930                } else {                  ## As if </head>
4931                  !!!cp ('t143');                  pop @{$self->{open_elements}};
4932                }                  $self->{insertion_mode} = AFTER_HEAD_IM;
4933    
4934                #                  ## Reprocess in the "after head" insertion mode...
4935              } else {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4936                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                  !!!cp ('t143.4');
                 !!!cp ('t144');  
4937                  #                  #
4938                } else {                } else {
4939                  !!!cp ('t145');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
                 !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);  
                 ## Ignore the token  
                 !!!next-token;  
                 next B;  
4940                }                }
4941    
4942                  ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.
4943                  !!!parse-error (type => 'unmatched end tag',
4944                                  text => 'br', token => $token);
4945                  ## Ignore the token
4946                  !!!next-token;
4947                  next B;
4948                } else {
4949                  !!!cp ('t145');
4950                  !!!parse-error (type => 'unmatched end tag',
4951                                  text => $token->{tag_name}, token => $token);
4952                  ## Ignore the token
4953                  !!!next-token;
4954                  next B;
4955              }              }
4956    
4957              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4958                !!!cp ('t146');                !!!cp ('t146');
4959                ## As if </noscript>                ## As if </noscript>
4960                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4961                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4962                                  text => $token->{tag_name}, token => $token);
4963                                
4964                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4965                ## As if </head>                ## As if </head>
# Line 4563  sub _tree_construction_main ($) { Line 4975  sub _tree_construction_main ($) {
4975              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4976  ## ISSUE: This case cannot be reached?  ## ISSUE: This case cannot be reached?
4977                !!!cp ('t148');                !!!cp ('t148');
4978                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
4979                                  text => $token->{tag_name}, token => $token);
4980                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
4981                !!!next-token;                !!!next-token;
4982                next B;                next B;
# Line 4674  sub _tree_construction_main ($) { Line 5087  sub _tree_construction_main ($) {
5087    
5088                  !!!cp ('t153');                  !!!cp ('t153');
5089                  !!!parse-error (type => 'start tag not allowed',                  !!!parse-error (type => 'start tag not allowed',
5090                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
5091                  ## Ignore the token                  ## Ignore the token
5092                  !!!nack ('t153.1');                  !!!nack ('t153.1');
5093                  !!!next-token;                  !!!next-token;
5094                  next B;                  next B;
5095                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
5096                  !!!parse-error (type => 'not closed:caption', token => $token);                  !!!parse-error (type => 'not closed', text => 'caption',
5097                                    token => $token);
5098                                    
5099                  ## NOTE: As if </caption>.                  ## NOTE: As if </caption>.
5100                  ## have a table element in table scope                  ## have a table element in table scope
# Line 4700  sub _tree_construction_main ($) { Line 5114  sub _tree_construction_main ($) {
5114    
5115                    !!!cp ('t157');                    !!!cp ('t157');
5116                    !!!parse-error (type => 'start tag not allowed',                    !!!parse-error (type => 'start tag not allowed',
5117                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
5118                    ## Ignore the token                    ## Ignore the token
5119                    !!!nack ('t157.1');                    !!!nack ('t157.1');
5120                    !!!next-token;                    !!!next-token;
# Line 4717  sub _tree_construction_main ($) { Line 5131  sub _tree_construction_main ($) {
5131                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5132                    !!!cp ('t159');                    !!!cp ('t159');
5133                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5134                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5135                                        ->manakai_local_name,                                        ->manakai_local_name,
5136                                    token => $token);                                    token => $token);
5137                  } else {                  } else {
# Line 4759  sub _tree_construction_main ($) { Line 5173  sub _tree_construction_main ($) {
5173                  } # INSCOPE                  } # INSCOPE
5174                    unless (defined $i) {                    unless (defined $i) {
5175                      !!!cp ('t165');                      !!!cp ('t165');
5176                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5177                                        text => $token->{tag_name},
5178                                        token => $token);
5179                      ## Ignore the token                      ## Ignore the token
5180                      !!!next-token;                      !!!next-token;
5181                      next B;                      next B;
# Line 4776  sub _tree_construction_main ($) { Line 5192  sub _tree_construction_main ($) {
5192                          ne $token->{tag_name}) {                          ne $token->{tag_name}) {
5193                    !!!cp ('t167');                    !!!cp ('t167');
5194                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5195                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5196                                        ->manakai_local_name,                                        ->manakai_local_name,
5197                                    token => $token);                                    token => $token);
5198                  } else {                  } else {
# Line 4793  sub _tree_construction_main ($) { Line 5209  sub _tree_construction_main ($) {
5209                  next B;                  next B;
5210                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
5211                  !!!cp ('t169');                  !!!cp ('t169');
5212                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5213                                    text => $token->{tag_name}, token => $token);
5214                  ## Ignore the token                  ## Ignore the token
5215                  !!!next-token;                  !!!next-token;
5216                  next B;                  next B;
# Line 4820  sub _tree_construction_main ($) { Line 5237  sub _tree_construction_main ($) {
5237    
5238                    !!!cp ('t173');                    !!!cp ('t173');
5239                    !!!parse-error (type => 'unmatched end tag',                    !!!parse-error (type => 'unmatched end tag',
5240                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
5241                    ## Ignore the token                    ## Ignore the token
5242                    !!!next-token;                    !!!next-token;
5243                    next B;                    next B;
# Line 4836  sub _tree_construction_main ($) { Line 5253  sub _tree_construction_main ($) {
5253                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5254                    !!!cp ('t175');                    !!!cp ('t175');
5255                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5256                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5257                                        ->manakai_local_name,                                        ->manakai_local_name,
5258                                    token => $token);                                    token => $token);
5259                  } else {                  } else {
# Line 4853  sub _tree_construction_main ($) { Line 5270  sub _tree_construction_main ($) {
5270                  next B;                  next B;
5271                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
5272                  !!!cp ('t177');                  !!!cp ('t177');
5273                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5274                                    text => $token->{tag_name}, token => $token);
5275                  ## Ignore the token                  ## Ignore the token
5276                  !!!next-token;                  !!!next-token;
5277                  next B;                  next B;
# Line 4896  sub _tree_construction_main ($) { Line 5314  sub _tree_construction_main ($) {
5314    
5315                  !!!cp ('t182');                  !!!cp ('t182');
5316                  !!!parse-error (type => 'unmatched end tag',                  !!!parse-error (type => 'unmatched end tag',
5317                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
5318                  ## Ignore the token                  ## Ignore the token
5319                  !!!next-token;                  !!!next-token;
5320                  next B;                  next B;
5321                } # INSCOPE                } # INSCOPE
5322              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
5323                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5324                !!!parse-error (type => 'not closed:caption', token => $token);                !!!parse-error (type => 'not closed', text => 'caption',
5325                                  token => $token);
5326    
5327                ## As if </caption>                ## As if </caption>
5328                ## have a table element in table scope                ## have a table element in table scope
# Line 4921  sub _tree_construction_main ($) { Line 5340  sub _tree_construction_main ($) {
5340                } # INSCOPE                } # INSCOPE
5341                unless (defined $i) {                unless (defined $i) {
5342                  !!!cp ('t186');                  !!!cp ('t186');
5343                  !!!parse-error (type => 'unmatched end tag:caption', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5344                                    text => 'caption', token => $token);
5345                  ## Ignore the token                  ## Ignore the token
5346                  !!!next-token;                  !!!next-token;
5347                  next B;                  next B;
# Line 4936  sub _tree_construction_main ($) { Line 5356  sub _tree_construction_main ($) {
5356                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5357                  !!!cp ('t188');                  !!!cp ('t188');
5358                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5359                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5360                                      ->manakai_local_name,                                      ->manakai_local_name,
5361                                  token => $token);                                  token => $token);
5362                } else {                } else {
# Line 4956  sub _tree_construction_main ($) { Line 5376  sub _tree_construction_main ($) {
5376                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5377                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
5378                  !!!cp ('t190');                  !!!cp ('t190');
5379                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5380                                    text => $token->{tag_name}, token => $token);
5381                  ## Ignore the token                  ## Ignore the token
5382                  !!!next-token;                  !!!next-token;
5383                  next B;                  next B;
# Line 4970  sub _tree_construction_main ($) { Line 5391  sub _tree_construction_main ($) {
5391                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
5392                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5393                !!!cp ('t192');                !!!cp ('t192');
5394                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
5395                                  text => $token->{tag_name}, token => $token);
5396                ## Ignore the token                ## Ignore the token
5397                !!!next-token;                !!!next-token;
5398                next B;                next B;
# Line 5010  sub _tree_construction_main ($) { Line 5432  sub _tree_construction_main ($) {
5432            }            }
5433          }          }
5434    
5435              !!!parse-error (type => 'in table:#character', token => $token);          !!!parse-error (type => 'in table:#text', token => $token);
5436    
5437              ## As if in body, but insert into foster parent element              ## As if in body, but insert into foster parent element
5438              ## ISSUE: Spec says that "whenever a node would be inserted              ## ISSUE: Spec says that "whenever a node would be inserted
# Line 5061  sub _tree_construction_main ($) { Line 5483  sub _tree_construction_main ($) {
5483          !!!next-token;          !!!next-token;
5484          next B;          next B;
5485        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5486              if ({          if ({
5487                   tr => ($self->{insertion_mode} != IN_ROW_IM),               tr => ($self->{insertion_mode} != IN_ROW_IM),
5488                   th => 1, td => 1,               th => 1, td => 1,
5489                  }->{$token->{tag_name}}) {              }->{$token->{tag_name}}) {
5490                if ($self->{insertion_mode} == IN_TABLE_IM) {            if ($self->{insertion_mode} == IN_TABLE_IM) {
5491                  ## Clear back to table context              ## Clear back to table context
5492                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5493                                  & TABLE_SCOPING_EL)) {                              & TABLE_SCOPING_EL)) {
5494                    !!!cp ('t201');                !!!cp ('t201');
5495                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5496                  }              }
5497                                
5498                  !!!insert-element ('tbody',, $token);              !!!insert-element ('tbody',, $token);
5499                  $self->{insertion_mode} = IN_TABLE_BODY_IM;              $self->{insertion_mode} = IN_TABLE_BODY_IM;
5500                  ## reprocess in the "in table body" insertion mode...              ## reprocess in the "in table body" insertion mode...
5501                }            }
5502              
5503                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {            if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
5504                  unless ($token->{tag_name} eq 'tr') {              unless ($token->{tag_name} eq 'tr') {
5505                    !!!cp ('t202');                !!!cp ('t202');
5506                    !!!parse-error (type => 'missing start tag:tr', token => $token);                !!!parse-error (type => 'missing start tag:tr', token => $token);
5507                  }              }
5508                                    
5509                  ## Clear back to table body context              ## Clear back to table body context
5510                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5511                                  & TABLE_ROWS_SCOPING_EL)) {                              & TABLE_ROWS_SCOPING_EL)) {
5512                    !!!cp ('t203');                !!!cp ('t203');
5513                    ## ISSUE: Can this case be reached?                ## ISSUE: Can this case be reached?
5514                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5515                  }              }
5516                                    
5517                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
5518                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
# Line 5146  sub _tree_construction_main ($) { Line 5568  sub _tree_construction_main ($) {
5568                  unless (defined $i) {                  unless (defined $i) {
5569                    !!!cp ('t210');                    !!!cp ('t210');
5570  ## TODO: This type is wrong.  ## TODO: This type is wrong.
5571                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmacthed end tag',
5572                                      text => $token->{tag_name}, token => $token);
5573                    ## Ignore the token                    ## Ignore the token
5574                    !!!nack ('t210.1');                    !!!nack ('t210.1');
5575                    !!!next-token;                    !!!next-token;
# Line 5190  sub _tree_construction_main ($) { Line 5613  sub _tree_construction_main ($) {
5613                  } # INSCOPE                  } # INSCOPE
5614                  unless (defined $i) {                  unless (defined $i) {
5615                    !!!cp ('t216');                    !!!cp ('t216');
5616  ## TODO: This erorr type ios wrong.  ## TODO: This erorr type is wrong.
5617                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5618                                      text => $token->{tag_name}, token => $token);
5619                    ## Ignore the token                    ## Ignore the token
5620                    !!!nack ('t216.1');                    !!!nack ('t216.1');
5621                    !!!next-token;                    !!!next-token;
# Line 5266  sub _tree_construction_main ($) { Line 5690  sub _tree_construction_main ($) {
5690                }                }
5691              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
5692                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
5693                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
5694                                    ->manakai_local_name,                                    ->manakai_local_name,
5695                                token => $token);                                token => $token);
5696    
# Line 5287  sub _tree_construction_main ($) { Line 5711  sub _tree_construction_main ($) {
5711                unless (defined $i) {                unless (defined $i) {
5712                  !!!cp ('t223');                  !!!cp ('t223');
5713  ## TODO: The following is wrong, maybe.  ## TODO: The following is wrong, maybe.
5714                  !!!parse-error (type => 'unmatched end tag:table', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'table',
5715                                    token => $token);
5716                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
5717                  !!!nack ('t223.1');                  !!!nack ('t223.1');
5718                  !!!next-token;                  !!!next-token;
5719                  next B;                  next B;
5720                }                }
5721                                
5722  ## TODO: Followings are removed from the latest spec.  ## TODO: Followings are removed from the latest spec.
5723                ## generate implied end tags                ## generate implied end tags
5724                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
5725                  !!!cp ('t224');                  !!!cp ('t224');
# Line 5305  sub _tree_construction_main ($) { Line 5730  sub _tree_construction_main ($) {
5730                  !!!cp ('t225');                  !!!cp ('t225');
5731                  ## NOTE: |<table><tr><table>|                  ## NOTE: |<table><tr><table>|
5732                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5733                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5734                                      ->manakai_local_name,                                      ->manakai_local_name,
5735                                  token => $token);                                  token => $token);
5736                } else {                } else {
# Line 5346  sub _tree_construction_main ($) { Line 5771  sub _tree_construction_main ($) {
5771                my $type = lc $token->{attributes}->{type}->{value};                my $type = lc $token->{attributes}->{type}->{value};
5772                if ($type eq 'hidden') {                if ($type eq 'hidden') {
5773                  !!!cp ('t227.3');                  !!!cp ('t227.3');
5774                  !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in table',
5775                                    text => $token->{tag_name}, token => $token);
5776    
5777                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5778    
# Line 5374  sub _tree_construction_main ($) { Line 5800  sub _tree_construction_main ($) {
5800            #            #
5801          }          }
5802    
5803          !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in table', text => $token->{tag_name},
5804                            token => $token);
5805    
5806          $insert = $insert_to_foster;          $insert = $insert_to_foster;
5807          #          #
# Line 5396  sub _tree_construction_main ($) { Line 5823  sub _tree_construction_main ($) {
5823                } # INSCOPE                } # INSCOPE
5824                unless (defined $i) {                unless (defined $i) {
5825                  !!!cp ('t230');                  !!!cp ('t230');
5826                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5827                                    text => $token->{tag_name}, token => $token);
5828                  ## Ignore the token                  ## Ignore the token
5829                  !!!nack ('t230.1');                  !!!nack ('t230.1');
5830                  !!!next-token;                  !!!next-token;
# Line 5437  sub _tree_construction_main ($) { Line 5865  sub _tree_construction_main ($) {
5865                  unless (defined $i) {                  unless (defined $i) {
5866                    !!!cp ('t235');                    !!!cp ('t235');
5867  ## TODO: The following is wrong.  ## TODO: The following is wrong.
5868                    !!!parse-error (type => 'unmatched end tag:'.$token->{type}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5869                                      text => $token->{type}, token => $token);
5870                    ## Ignore the token                    ## Ignore the token
5871                    !!!nack ('t236.1');                    !!!nack ('t236.1');
5872                    !!!next-token;                    !!!next-token;
# Line 5473  sub _tree_construction_main ($) { Line 5902  sub _tree_construction_main ($) {
5902                  } # INSCOPE                  } # INSCOPE
5903                  unless (defined $i) {                  unless (defined $i) {
5904                    !!!cp ('t239');                    !!!cp ('t239');
5905                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5906                                      text => $token->{tag_name}, token => $token);
5907                    ## Ignore the token                    ## Ignore the token
5908                    !!!nack ('t239.1');                    !!!nack ('t239.1');
5909                    !!!next-token;                    !!!next-token;
# Line 5519  sub _tree_construction_main ($) { Line 5949  sub _tree_construction_main ($) {
5949                } # INSCOPE                } # INSCOPE
5950                unless (defined $i) {                unless (defined $i) {
5951                  !!!cp ('t243');                  !!!cp ('t243');
5952                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5953                                    text => $token->{tag_name}, token => $token);
5954                  ## Ignore the token                  ## Ignore the token
5955                  !!!nack ('t243.1');                  !!!nack ('t243.1');
5956                  !!!next-token;                  !!!next-token;
# Line 5553  sub _tree_construction_main ($) { Line 5984  sub _tree_construction_main ($) {
5984                  } # INSCOPE                  } # INSCOPE
5985                    unless (defined $i) {                    unless (defined $i) {
5986                      !!!cp ('t249');                      !!!cp ('t249');
5987                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5988                                        text => $token->{tag_name}, token => $token);
5989                      ## Ignore the token                      ## Ignore the token
5990                      !!!nack ('t249.1');                      !!!nack ('t249.1');
5991                      !!!next-token;                      !!!next-token;
# Line 5576  sub _tree_construction_main ($) { Line 6008  sub _tree_construction_main ($) {
6008                  } # INSCOPE                  } # INSCOPE
6009                    unless (defined $i) {                    unless (defined $i) {
6010                      !!!cp ('t252');                      !!!cp ('t252');
6011                      !!!parse-error (type => 'unmatched end tag:tr', token => $token);                      !!!parse-error (type => 'unmatched end tag',
6012                                        text => 'tr', token => $token);
6013                      ## Ignore the token                      ## Ignore the token
6014                      !!!nack ('t252.1');                      !!!nack ('t252.1');
6015                      !!!next-token;                      !!!next-token;
# Line 5611  sub _tree_construction_main ($) { Line 6044  sub _tree_construction_main ($) {
6044                } # INSCOPE                } # INSCOPE
6045                unless (defined $i) {                unless (defined $i) {
6046                  !!!cp ('t256');                  !!!cp ('t256');
6047                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
6048                                    text => $token->{tag_name}, token => $token);
6049                  ## Ignore the token                  ## Ignore the token
6050                  !!!nack ('t256.1');                  !!!nack ('t256.1');
6051                  !!!next-token;                  !!!next-token;
# Line 5638  sub _tree_construction_main ($) { Line 6072  sub _tree_construction_main ($) {
6072                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
6073                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
6074            !!!cp ('t258');            !!!cp ('t258');
6075            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
6076                              text => $token->{tag_name}, token => $token);
6077            ## Ignore the token            ## Ignore the token
6078            !!!nack ('t258.1');            !!!nack ('t258.1');
6079             !!!next-token;             !!!next-token;
6080            next B;            next B;
6081          } else {          } else {
6082            !!!cp ('t259');            !!!cp ('t259');
6083            !!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in table:/',
6084                              text => $token->{tag_name}, token => $token);
6085    
6086            $insert = $insert_to_foster;            $insert = $insert_to_foster;
6087            #            #
# Line 5695  sub _tree_construction_main ($) { Line 6131  sub _tree_construction_main ($) {
6131              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
6132                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
6133                  !!!cp ('t264');                  !!!cp ('t264');
6134                  !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);                  !!!parse-error (type => 'unmatched end tag',
6135                                    text => 'colgroup', token => $token);
6136                  ## Ignore the token                  ## Ignore the token
6137                  !!!next-token;                  !!!next-token;
6138                  next B;                  next B;
# Line 5708  sub _tree_construction_main ($) { Line 6145  sub _tree_construction_main ($) {
6145                }                }
6146              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
6147                !!!cp ('t266');                !!!cp ('t266');
6148                !!!parse-error (type => 'unmatched end tag:col', token => $token);                !!!parse-error (type => 'unmatched end tag',
6149                                  text => 'col', token => $token);
6150                ## Ignore the token                ## Ignore the token
6151                !!!next-token;                !!!next-token;
6152                next B;                next B;
# Line 5738  sub _tree_construction_main ($) { Line 6176  sub _tree_construction_main ($) {
6176            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
6177              !!!cp ('t269');              !!!cp ('t269');
6178  ## TODO: Wrong error type?  ## TODO: Wrong error type?
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              !!!nack ('t269.1');              !!!nack ('t269.1');
6183              !!!next-token;              !!!next-token;
# Line 5792  sub _tree_construction_main ($) { Line 6231  sub _tree_construction_main ($) {
6231            !!!nack ('t277.1');            !!!nack ('t277.1');
6232            !!!next-token;            !!!next-token;
6233            next B;            next B;
6234          } elsif ($token->{tag_name} eq 'select' or          } elsif ({
6235                   $token->{tag_name} eq 'input' or                     select => 1, input => 1, textarea => 1,
6236                     }->{$token->{tag_name}} or
6237                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
6238                    {                    {
6239                     caption => 1, table => 1,                     caption => 1, table => 1,
# Line 5801  sub _tree_construction_main ($) { Line 6241  sub _tree_construction_main ($) {
6241                     tr => 1, td => 1, th => 1,                     tr => 1, td => 1, th => 1,
6242                    }->{$token->{tag_name}})) {                    }->{$token->{tag_name}})) {
6243            ## TODO: The type below is not good - <select> is replaced by </select>            ## TODO: The type below is not good - <select> is replaced by </select>
6244            !!!parse-error (type => 'not closed:select', token => $token);            !!!parse-error (type => 'not closed', text => 'select',
6245                              token => $token);
6246            ## NOTE: As if the token were </select> (<select> case) or            ## NOTE: As if the token were </select> (<select> case) or
6247            ## as if there were </select> (otherwise).            ## as if there were </select> (otherwise).
6248            ## have an element in table scope            ## have an element in table scope
# Line 5819  sub _tree_construction_main ($) { Line 6260  sub _tree_construction_main ($) {
6260            } # INSCOPE            } # INSCOPE
6261            unless (defined $i) {            unless (defined $i) {
6262              !!!cp ('t280');              !!!cp ('t280');
6263              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6264                                text => 'select', token => $token);
6265              ## Ignore the token              ## Ignore the token
6266              !!!nack ('t280.1');              !!!nack ('t280.1');
6267              !!!next-token;              !!!next-token;
# Line 5843  sub _tree_construction_main ($) { Line 6285  sub _tree_construction_main ($) {
6285            }            }
6286          } else {          } else {
6287            !!!cp ('t282');            !!!cp ('t282');
6288            !!!parse-error (type => 'in select:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select',
6289                              text => $token->{tag_name}, token => $token);
6290            ## Ignore the token            ## Ignore the token
6291            !!!nack ('t282.1');            !!!nack ('t282.1');
6292            !!!next-token;            !!!next-token;
# Line 5861  sub _tree_construction_main ($) { Line 6304  sub _tree_construction_main ($) {
6304              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6305            } else {            } else {
6306              !!!cp ('t285');              !!!cp ('t285');
6307              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6308                                text => $token->{tag_name}, token => $token);
6309              ## Ignore the token              ## Ignore the token
6310            }            }
6311            !!!nack ('t285.1');            !!!nack ('t285.1');
# Line 5873  sub _tree_construction_main ($) { Line 6317  sub _tree_construction_main ($) {
6317              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6318            } else {            } else {
6319              !!!cp ('t287');              !!!cp ('t287');
6320              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6321                                text => $token->{tag_name}, token => $token);
6322              ## Ignore the token              ## Ignore the token
6323            }            }
6324            !!!nack ('t287.1');            !!!nack ('t287.1');
# Line 5895  sub _tree_construction_main ($) { Line 6340  sub _tree_construction_main ($) {
6340            } # INSCOPE            } # INSCOPE
6341            unless (defined $i) {            unless (defined $i) {
6342              !!!cp ('t290');              !!!cp ('t290');
6343              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6344                                text => $token->{tag_name}, token => $token);
6345              ## Ignore the token              ## Ignore the token
6346              !!!nack ('t290.1');              !!!nack ('t290.1');
6347              !!!next-token;              !!!next-token;
# Line 5916  sub _tree_construction_main ($) { Line 6362  sub _tree_construction_main ($) {
6362                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
6363                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
6364  ## TODO: The following is wrong?  ## TODO: The following is wrong?
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                                
6368            ## have an element in table scope            ## have an element in table scope
6369            my $i;            my $i;
# Line 5957  sub _tree_construction_main ($) { Line 6404  sub _tree_construction_main ($) {
6404            unless (defined $i) {            unless (defined $i) {
6405              !!!cp ('t297');              !!!cp ('t297');
6406  ## TODO: The following error type is correct?  ## TODO: The following error type is correct?
6407              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6408                                text => 'select', token => $token);
6409              ## Ignore the </select> token              ## Ignore the </select> token
6410              !!!nack ('t297.1');              !!!nack ('t297.1');
6411              !!!next-token; ## TODO: ok?              !!!next-token; ## TODO: ok?
# Line 5974  sub _tree_construction_main ($) { Line 6422  sub _tree_construction_main ($) {
6422            next B;            next B;
6423          } else {          } else {
6424            !!!cp ('t299');            !!!cp ('t299');
6425            !!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select:/',
6426                              text => $token->{tag_name}, token => $token);
6427            ## Ignore the token            ## Ignore the token
6428            !!!nack ('t299.3');            !!!nack ('t299.3');
6429            !!!next-token;            !!!next-token;
# Line 6012  sub _tree_construction_main ($) { Line 6461  sub _tree_construction_main ($) {
6461                    
6462          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6463            !!!cp ('t301');            !!!cp ('t301');
6464            !!!parse-error (type => 'after html:#character', token => $token);            !!!parse-error (type => 'after html:#text', token => $token);
6465    
6466            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6467          } else {          } else {
# Line 6020  sub _tree_construction_main ($) { Line 6469  sub _tree_construction_main ($) {
6469          }          }
6470                    
6471          ## "after body" insertion mode          ## "after body" insertion mode
6472          !!!parse-error (type => 'after body:#character', token => $token);          !!!parse-error (type => 'after body:#text', token => $token);
6473    
6474          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6475          ## reprocess          ## reprocess
# Line 6028  sub _tree_construction_main ($) { Line 6477  sub _tree_construction_main ($) {
6477        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
6478          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6479            !!!cp ('t303');            !!!cp ('t303');
6480            !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html',
6481                              text => $token->{tag_name}, token => $token);
6482                        
6483            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6484          } else {          } else {
# Line 6036  sub _tree_construction_main ($) { Line 6486  sub _tree_construction_main ($) {
6486          }          }
6487    
6488          ## "after body" insertion mode          ## "after body" insertion mode
6489          !!!parse-error (type => 'after body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'after body',
6490                            text => $token->{tag_name}, token => $token);
6491    
6492          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6493          !!!ack-later;          !!!ack-later;
# Line 6045  sub _tree_construction_main ($) { Line 6496  sub _tree_construction_main ($) {
6496        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6497          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6498            !!!cp ('t305');            !!!cp ('t305');
6499            !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html:/',
6500                              text => $token->{tag_name}, token => $token);
6501                        
6502            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6503            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
# Line 6057  sub _tree_construction_main ($) { Line 6509  sub _tree_construction_main ($) {
6509          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
6510            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
6511              !!!cp ('t307');              !!!cp ('t307');
6512              !!!parse-error (type => 'unmatched end tag:html', token => $token);              !!!parse-error (type => 'unmatched end tag',
6513                                text => 'html', token => $token);
6514              ## Ignore the token              ## Ignore the token
6515              !!!next-token;              !!!next-token;
6516              next B;              next B;
# Line 6069  sub _tree_construction_main ($) { Line 6522  sub _tree_construction_main ($) {
6522            }            }
6523          } else {          } else {
6524            !!!cp ('t309');            !!!cp ('t309');
6525            !!!parse-error (type => 'after body:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after body:/',
6526                              text => $token->{tag_name}, token => $token);
6527    
6528            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
6529            ## reprocess            ## reprocess
# Line 6097  sub _tree_construction_main ($) { Line 6551  sub _tree_construction_main ($) {
6551          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
6552            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6553              !!!cp ('t311');              !!!cp ('t311');
6554              !!!parse-error (type => 'in frameset:#character', token => $token);              !!!parse-error (type => 'in frameset:#text', token => $token);
6555            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6556              !!!cp ('t312');              !!!cp ('t312');
6557              !!!parse-error (type => 'after frameset:#character', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6558            } else { # "after html frameset"            } else { # "after after frameset"
6559              !!!cp ('t313');              !!!cp ('t313');
6560              !!!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);  
6561            }            }
6562                        
6563            ## Ignore the token.            ## Ignore the token.
# Line 6123  sub _tree_construction_main ($) { Line 6573  sub _tree_construction_main ($) {
6573                    
6574          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
6575        } 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');  
         }  
   
6576          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6577              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6578            !!!cp ('t318');            !!!cp ('t318');
# Line 6150  sub _tree_construction_main ($) { Line 6590  sub _tree_construction_main ($) {
6590            next B;            next B;
6591          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
6592            !!!cp ('t320');            !!!cp ('t320');
6593            ## NOTE: As if in body.            ## NOTE: As if in head.
6594            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
6595            next B;            next B;
6596    
6597              ## NOTE: |<!DOCTYPE HTML><frameset></frameset></html><noframes></noframes>|
6598              ## has no parse error.
6599          } else {          } else {
6600            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6601              !!!cp ('t321');              !!!cp ('t321');
6602              !!!parse-error (type => 'in frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset',
6603            } else {                              text => $token->{tag_name}, token => $token);
6604              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6605              !!!cp ('t322');              !!!cp ('t322');
6606              !!!parse-error (type => 'after frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after frameset',
6607                                text => $token->{tag_name}, token => $token);
6608              } else { # "after after frameset"
6609                !!!cp ('t322.2');
6610                !!!parse-error (type => 'after after frameset',
6611                                text => $token->{tag_name}, token => $token);
6612            }            }
6613            ## Ignore the token            ## Ignore the token
6614            !!!nack ('t322.1');            !!!nack ('t322.1');
# Line 6167  sub _tree_construction_main ($) { Line 6616  sub _tree_construction_main ($) {
6616            next B;            next B;
6617          }          }
6618        } 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');  
         }  
   
6619          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6620              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6621            if ($self->{open_elements}->[-1]->[1] & HTML_EL and            if ($self->{open_elements}->[-1]->[1] & HTML_EL and
6622                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
6623              !!!cp ('t325');              !!!cp ('t325');
6624              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6625                                text => $token->{tag_name}, token => $token);
6626              ## Ignore the token              ## Ignore the token
6627              !!!next-token;              !!!next-token;
6628            } else {            } else {
# Line 6208  sub _tree_construction_main ($) { Line 6648  sub _tree_construction_main ($) {
6648          } else {          } else {
6649            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6650              !!!cp ('t330');              !!!cp ('t330');
6651              !!!parse-error (type => 'in frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset:/',
6652            } else {                              text => $token->{tag_name}, token => $token);
6653              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6654                !!!cp ('t330.1');
6655                !!!parse-error (type => 'after frameset:/',
6656                                text => $token->{tag_name}, token => $token);
6657              } else { # "after after html"
6658              !!!cp ('t331');              !!!cp ('t331');
6659              !!!parse-error (type => 'after frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after after frameset:/',
6660                                text => $token->{tag_name}, token => $token);
6661            }            }
6662            ## Ignore the token            ## Ignore the token
6663            !!!next-token;            !!!next-token;
# Line 6278  sub _tree_construction_main ($) { Line 6724  sub _tree_construction_main ($) {
6724                                           ->{has_reference});                                           ->{has_reference});
6725            } elsif ($token->{attributes}->{content}) {            } elsif ($token->{attributes}->{content}) {
6726              if ($token->{attributes}->{content}->{value}              if ($token->{attributes}->{content}->{value}
6727                  =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                  =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
6728                      [\x09-\x0D\x20]*=                      [\x09-\x0D\x20]*=
6729                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
6730                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
6731                !!!cp ('t336');                !!!cp ('t336');
6732                ## NOTE: Whether the encoding is supported or not is handled                ## NOTE: Whether the encoding is supported or not is handled
6733                ## in the {change_encoding} callback.                ## in the {change_encoding} callback.
# Line 6319  sub _tree_construction_main ($) { Line 6765  sub _tree_construction_main ($) {
6765          $parse_rcdata->(RCDATA_CONTENT_MODEL);          $parse_rcdata->(RCDATA_CONTENT_MODEL);
6766          next B;          next B;
6767        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
6768          !!!parse-error (type => 'in body:body', token => $token);          !!!parse-error (type => 'in body', text => 'body', token => $token);
6769                                
6770          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
6771              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {
# Line 6439  sub _tree_construction_main ($) { Line 6885  sub _tree_construction_main ($) {
6885              if ($i != -1) {              if ($i != -1) {
6886                !!!cp ('t355');                !!!cp ('t355');
6887                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
6888                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
6889                                    ->manakai_local_name,                                    ->manakai_local_name,
6890                                token => $token);                                token => $token);
6891              } else {              } else {
# Line 6593  sub _tree_construction_main ($) { Line 7039  sub _tree_construction_main ($) {
7039                  xmp => 1,                  xmp => 1,
7040                  iframe => 1,                  iframe => 1,
7041                  noembed => 1,                  noembed => 1,
7042                  noframes => 1,                  noframes => 1, ## NOTE: This is an "as if in head" code clone.
7043                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
7044                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7045          if ($token->{tag_name} eq 'xmp') {          if ($token->{tag_name} eq 'xmp') {
# Line 6615  sub _tree_construction_main ($) { Line 7061  sub _tree_construction_main ($) {
7061            !!!next-token;            !!!next-token;
7062            next B;            next B;
7063          } else {          } else {
7064              !!!ack ('t391.1');
7065    
7066            my $at = $token->{attributes};            my $at = $token->{attributes};
7067            my $form_attrs;            my $form_attrs;
7068            $form_attrs->{action} = $at->{action} if $at->{action};            $form_attrs->{action} = $at->{action} if $at->{action};
# Line 6658  sub _tree_construction_main ($) { Line 7106  sub _tree_construction_main ($) {
7106                           line => $token->{line}, column => $token->{column}},                           line => $token->{line}, column => $token->{column}},
7107                          {type => END_TAG_TOKEN, tag_name => 'form',                          {type => END_TAG_TOKEN, tag_name => 'form',
7108                           line => $token->{line}, column => $token->{column}};                           line => $token->{line}, column => $token->{column}};
           !!!nack ('t391.1'); ## NOTE: Not acknowledged.  
7109            !!!back-token (@tokens);            !!!back-token (@tokens);
7110            !!!next-token;            !!!next-token;
7111            next B;            next B;
# Line 6706  sub _tree_construction_main ($) { Line 7153  sub _tree_construction_main ($) {
7153            ## Ignore the token            ## Ignore the token
7154          } else {          } else {
7155            !!!cp ('t398');            !!!cp ('t398');
7156            !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);            !!!parse-error (type => 'in RCDATA:#eof', token => $token);
7157          }          }
7158          !!!next-token;          !!!next-token;
7159          next B;          next B;
7160          } elsif ($token->{tag_name} eq 'rt' or
7161                   $token->{tag_name} eq 'rp') {
7162            ## has a |ruby| element in scope
7163            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
7164              my $node = $self->{open_elements}->[$_];
7165              if ($node->[1] & RUBY_EL) {
7166                !!!cp ('t398.1');
7167                ## generate implied end tags
7168                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7169                  !!!cp ('t398.2');
7170                  pop @{$self->{open_elements}};
7171                }
7172                unless ($self->{open_elements}->[-1]->[1] & RUBY_EL) {
7173                  !!!cp ('t398.3');
7174                  !!!parse-error (type => 'not closed',
7175                                  text => $self->{open_elements}->[-1]->[0]
7176                                      ->manakai_local_name,
7177                                  token => $token);
7178                  pop @{$self->{open_elements}}
7179                      while not $self->{open_elements}->[-1]->[1] & RUBY_EL;
7180                }
7181                last INSCOPE;
7182              } elsif ($node->[1] & SCOPING_EL) {
7183                !!!cp ('t398.4');
7184                last INSCOPE;
7185              }
7186            } # INSCOPE
7187    
7188            !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
7189    
7190            !!!nack ('t398.5');
7191            !!!next-token;
7192            redo B;
7193        } elsif ($token->{tag_name} eq 'math' or        } elsif ($token->{tag_name} eq 'math' or
7194                 $token->{tag_name} eq 'svg') {                 $token->{tag_name} eq 'svg') {
7195          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
7196    
7197            ## "Adjust MathML attributes" ('math' only) - done in insert-element-f
7198    
7199          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f
7200    
7201          ## "adjust foreign attributes" - done in insert-element-f          ## "adjust foreign attributes" - done in insert-element-f
# Line 6740  sub _tree_construction_main ($) { Line 7222  sub _tree_construction_main ($) {
7222                  thead => 1, tr => 1,                  thead => 1, tr => 1,
7223                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7224          !!!cp ('t401');          !!!cp ('t401');
7225          !!!parse-error (type => 'in body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in body',
7226                            text => $token->{tag_name}, token => $token);
7227          ## Ignore the token          ## Ignore the token
7228          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.
7229          !!!next-token;          !!!next-token;
# Line 6825  sub _tree_construction_main ($) { Line 7308  sub _tree_construction_main ($) {
7308            }            }
7309    
7310            !!!parse-error (type => 'start tag not allowed',            !!!parse-error (type => 'start tag not allowed',
7311                            value => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7312            ## NOTE: Ignore the token.            ## NOTE: Ignore the token.
7313            !!!next-token;            !!!next-token;
7314            next B;            next B;
# Line 6835  sub _tree_construction_main ($) { Line 7318  sub _tree_construction_main ($) {
7318            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {
7319              !!!cp ('t403');              !!!cp ('t403');
7320              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7321                              value => $_->[0]->manakai_local_name,                              text => $_->[0]->manakai_local_name,
7322                              token => $token);                              token => $token);
7323              last;              last;
7324            } else {            } else {
# Line 6855  sub _tree_construction_main ($) { Line 7338  sub _tree_construction_main ($) {
7338            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {
7339              !!!cp ('t406');              !!!cp ('t406');
7340              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7341                              value => $self->{open_elements}->[1]->[0]                              text => $self->{open_elements}->[1]->[0]
7342                                  ->manakai_local_name,                                  ->manakai_local_name,
7343                              token => $token);                              token => $token);
7344            } else {            } else {
# Line 6866  sub _tree_construction_main ($) { Line 7349  sub _tree_construction_main ($) {
7349            next B;            next B;
7350          } else {          } else {
7351            !!!cp ('t408');            !!!cp ('t408');
7352            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7353                              text => $token->{tag_name}, token => $token);
7354            ## Ignore the token            ## Ignore the token
7355            !!!next-token;            !!!next-token;
7356            next B;            next B;
# Line 6894  sub _tree_construction_main ($) { Line 7378  sub _tree_construction_main ($) {
7378    
7379          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7380            !!!cp ('t413');            !!!cp ('t413');
7381            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7382                              text => $token->{tag_name}, token => $token);
7383              ## NOTE: Ignore the token.
7384          } else {          } else {
7385            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7386            while ({            while ({
7387                      ## END_TAG_OPTIONAL_EL
7388                    dd => ($token->{tag_name} ne 'dd'),                    dd => ($token->{tag_name} ne 'dd'),
7389                    dt => ($token->{tag_name} ne 'dt'),                    dt => ($token->{tag_name} ne 'dt'),
7390                    li => ($token->{tag_name} ne 'li'),                    li => ($token->{tag_name} ne 'li'),
7391                    p => 1,                    p => 1,
7392                      rt => 1,
7393                      rp => 1,
7394                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {
7395              !!!cp ('t409');              !!!cp ('t409');
7396              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
# Line 6912  sub _tree_construction_main ($) { Line 7401  sub _tree_construction_main ($) {
7401                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7402              !!!cp ('t412');              !!!cp ('t412');
7403              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7404                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7405                                  ->manakai_local_name,                                  ->manakai_local_name,
7406                              token => $token);                              token => $token);
7407            } else {            } else {
# Line 6949  sub _tree_construction_main ($) { Line 7438  sub _tree_construction_main ($) {
7438    
7439          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7440            !!!cp ('t421');            !!!cp ('t421');
7441            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7442                              text => $token->{tag_name}, token => $token);
7443              ## NOTE: Ignore the token.
7444          } else {          } else {
7445            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7446            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 6962  sub _tree_construction_main ($) { Line 7453  sub _tree_construction_main ($) {
7453                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7454              !!!cp ('t417.1');              !!!cp ('t417.1');
7455              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7456                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7457                                  ->manakai_local_name,                                  ->manakai_local_name,
7458                              token => $token);                              token => $token);
7459            } else {            } else {
# Line 6994  sub _tree_construction_main ($) { Line 7485  sub _tree_construction_main ($) {
7485    
7486          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7487            !!!cp ('t425.1');            !!!cp ('t425.1');
7488            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7489                              text => $token->{tag_name}, token => $token);
7490              ## NOTE: Ignore the token.
7491          } else {          } else {
7492            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7493            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7006  sub _tree_construction_main ($) { Line 7499  sub _tree_construction_main ($) {
7499            if ($self->{open_elements}->[-1]->[0]->manakai_local_name            if ($self->{open_elements}->[-1]->[0]->manakai_local_name
7500                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7501              !!!cp ('t425');              !!!cp ('t425');
7502              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
7503                                text => $token->{tag_name}, token => $token);
7504            } else {            } else {
7505              !!!cp ('t426');              !!!cp ('t426');
7506            }            }
# Line 7037  sub _tree_construction_main ($) { Line 7531  sub _tree_construction_main ($) {
7531                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7532              !!!cp ('t412.1');              !!!cp ('t412.1');
7533              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7534                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7535                                  ->manakai_local_name,                                  ->manakai_local_name,
7536                              token => $token);                              token => $token);
7537            } else {            } else {
# Line 7047  sub _tree_construction_main ($) { Line 7541  sub _tree_construction_main ($) {
7541            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
7542          } else {          } else {
7543            !!!cp ('t413.1');            !!!cp ('t413.1');
7544            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7545                              text => $token->{tag_name}, token => $token);
7546    
7547            !!!cp ('t415.1');            !!!cp ('t415.1');
7548            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
# Line 7070  sub _tree_construction_main ($) { Line 7565  sub _tree_construction_main ($) {
7565          next B;          next B;
7566        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
7567          !!!cp ('t428');          !!!cp ('t428');
7568          !!!parse-error (type => 'unmatched end tag:br', token => $token);          !!!parse-error (type => 'unmatched end tag',
7569                            text => 'br', token => $token);
7570    
7571          ## As if <br>          ## As if <br>
7572          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
# Line 7095  sub _tree_construction_main ($) { Line 7591  sub _tree_construction_main ($) {
7591                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
7592                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7593          !!!cp ('t429');          !!!cp ('t429');
7594          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'unmatched end tag',
7595                            text => $token->{tag_name}, token => $token);
7596          ## Ignore the token          ## Ignore the token
7597          !!!next-token;          !!!next-token;
7598          next B;          next B;
# Line 7114  sub _tree_construction_main ($) { Line 7611  sub _tree_construction_main ($) {
7611              ## generate implied end tags              ## generate implied end tags
7612              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7613                !!!cp ('t430');                !!!cp ('t430');
7614                ## ISSUE: Can this case be reached?                ## NOTE: |<ruby><rt></ruby>|.
7615                  ## ISSUE: <ruby><rt></rt> will also take this code path,
7616                  ## which seems wrong.
7617                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
7618                  $node_i++;
7619              }              }
7620                    
7621              ## Step 2              ## Step 2
# Line 7124  sub _tree_construction_main ($) { Line 7624  sub _tree_construction_main ($) {
7624                !!!cp ('t431');                !!!cp ('t431');
7625                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
7626                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
7627                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
7628                                    ->manakai_local_name,                                    ->manakai_local_name,
7629                                token => $token);                                token => $token);
7630              } else {              } else {
# Line 7132  sub _tree_construction_main ($) { Line 7632  sub _tree_construction_main ($) {
7632              }              }
7633                            
7634              ## Step 3              ## Step 3
7635              splice @{$self->{open_elements}}, $node_i;              splice @{$self->{open_elements}}, $node_i if $node_i < 0;
7636    
7637              !!!next-token;              !!!next-token;
7638              last S2;              last S2;
# Line 7143  sub _tree_construction_main ($) { Line 7643  sub _tree_construction_main ($) {
7643                  ($node->[1] & SPECIAL_EL or                  ($node->[1] & SPECIAL_EL or
7644                   $node->[1] & SCOPING_EL)) {                   $node->[1] & SCOPING_EL)) {
7645                !!!cp ('t433');                !!!cp ('t433');
7646                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
7647                                  text => $token->{tag_name}, token => $token);
7648                ## Ignore the token                ## Ignore the token
7649                !!!next-token;                !!!next-token;
7650                last S2;                last S2;
# Line 7189  sub _tree_construction_main ($) { Line 7690  sub _tree_construction_main ($) {
7690    ## TODO: script stuffs    ## TODO: script stuffs
7691  } # _tree_construct_main  } # _tree_construct_main
7692    
7693  sub set_inner_html ($$$) {  sub set_inner_html ($$$;$) {
7694    my $class = shift;    my $class = shift;
7695    my $node = shift;    my $node = shift;
7696    my $s = \$_[0];    my $s = \$_[0];
7697    my $onerror = $_[1];    my $onerror = $_[1];
7698      my $get_wrapper = $_[2] || sub ($) { return $_[0] };
7699    
7700    ## ISSUE: Should {confident} be true?    ## ISSUE: Should {confident} be true?
7701    
# Line 7212  sub set_inner_html ($$$) { Line 7714  sub set_inner_html ($$$) {
7714      }      }
7715    
7716      ## Step 3, 4, 5 # MUST      ## Step 3, 4, 5 # MUST
7717      $class->parse_string ($$s => $node, $onerror);      $class->parse_char_string ($$s => $node, $onerror, $get_wrapper);
7718    } elsif ($nt == 1) {    } elsif ($nt == 1) {
7719      ## TODO: If non-html element      ## TODO: If non-html element
7720    
7721      ## NOTE: Most of this code is copied from |parse_string|      ## NOTE: Most of this code is copied from |parse_string|
7722    
7723    ## TODO: Support for $get_wrapper
7724    
7725      ## Step 1 # MUST      ## Step 1 # MUST
7726      my $this_doc = $node->owner_document;      my $this_doc = $node->owner_document;
7727      my $doc = $this_doc->implementation->create_document;      my $doc = $this_doc->implementation->create_document;
# Line 7279  sub set_inner_html ($$$) { Line 7783  sub set_inner_html ($$$) {
7783                  0x10FFFE => 1, 0x10FFFF => 1,                  0x10FFFE => 1, 0x10FFFF => 1,
7784                 }->{$self->{next_char}}) {                 }->{$self->{next_char}}) {
7785          !!!cp ('i4.1');          !!!cp ('i4.1');
7786          !!!parse-error (type => 'control char', level => $self->{must_level});          if ($self->{next_char} < 0x10000) {
7787  ## TODO: error type documentation            !!!parse-error (type => 'control char',
7788                              text => (sprintf 'U+%04X', $self->{next_char}));
7789            } else {
7790              !!!parse-error (type => 'control char',
7791                              text => (sprintf 'U-%08X', $self->{next_char}));
7792            }
7793        }        }
7794      };      };
7795      $p->{prev_char} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];
7796      $p->{next_char} = -1;      $p->{next_char} = -1;
7797        
7798        $p->{read_until} = sub {
7799          ## TODO: ...
7800          return 0;
7801        }; # $p->{read_until};
7802    
7803      my $ponerror = $onerror || sub {      my $ponerror = $onerror || sub {
7804        my (%opt) = @_;        my (%opt) = @_;
7805        my $line = $opt{line};        my $line = $opt{line};

Legend:
Removed from v.1.138  
changed lines
  Added in v.1.172

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24