/[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.132 by wakaba, Sun Apr 13 10:36:40 2008 UTC revision 1.167 by wakaba, Sat Sep 13 09:02:28 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 332  my $c1_entity_char = { Line 348  my $c1_entity_char = {
348  }; # $c1_entity_char  }; # $c1_entity_char
349    
350  sub parse_byte_string ($$$$;$) {  sub parse_byte_string ($$$$;$) {
351      my $self = shift;
352      my $charset_name = shift;
353      open my $input, '<', ref $_[0] ? $_[0] : \($_[0]);
354      return $self->parse_byte_stream ($charset_name, $input, @_[1..$#_]);
355    } # parse_byte_string
356    
357    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 = shift;    my $charset_name = shift;
361    my $bytes_s = ref $_[0] ? $_[0] : \($_[0]);    my $byte_stream = $_[0];
362    my $s;  
363        my $onerror = $_[2] || sub {
364    if (defined $charset) {      my (%opt) = @_;
365      require Encode; ## TODO: decode(utf8) don't delete BOM      warn "Parse error ($opt{type})\n";
366      $s = \ (Encode::decode ($charset, $$bytes_s));    };
367      $self->{input_encoding} = lc $charset; ## TODO: normalize name    $self->{parse_error} = $onerror; # updated later by parse_char_string
368      $self->{confident} = 1;  
369    } else {    my $get_wrapper = $_[3] || sub ($) {
370      ## TODO: Implement HTML5 detection algorithm      return $_[0]; # $_[0] = byte stream handle, returned = arg to char handle
371      };
372    
373      ## HTML5 encoding sniffing algorithm
374      require Message::Charset::Info;
375      my $charset;
376      my $buffer;
377      my ($char_stream, $e_status);
378    
379      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
388        if (defined $charset_name) {
389          $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.
394          ($char_stream, $e_status) = $charset->get_decode_handle
395              ($byte_stream, allow_error_reporting => 1,
396               allow_fallback => 1);
397          if ($char_stream) {
398            $self->{confident} = 1;
399            last SNIFFING;
400          } else {
401            ## TODO: unsupported error
402          }
403        }
404    
405        ## Step 2
406        my $byte_buffer = '';
407        for (1..1024) {
408          my $char = $byte_stream->getc;
409          last unless defined $char;
410          $byte_buffer .= $char;
411        } ## TODO: timeout
412    
413        ## Step 3
414        if ($byte_buffer =~ /^\xFE\xFF/) {
415          $charset = Message::Charset::Info->get_by_html_name ('utf-16be');
416          ($char_stream, $e_status) = $charset->get_decode_handle
417              ($byte_stream, allow_error_reporting => 1,
418               allow_fallback => 1, byte_buffer => \$byte_buffer);
419          $self->{confident} = 1;
420          last SNIFFING;
421        } elsif ($byte_buffer =~ /^\xFF\xFE/) {
422          $charset = Message::Charset::Info->get_by_html_name ('utf-16le');
423          ($char_stream, $e_status) = $charset->get_decode_handle
424              ($byte_stream, allow_error_reporting => 1,
425               allow_fallback => 1, byte_buffer => \$byte_buffer);
426          $self->{confident} = 1;
427          last SNIFFING;
428        } elsif ($byte_buffer =~ /^\xEF\xBB\xBF/) {
429          $charset = Message::Charset::Info->get_by_html_name ('utf-8');
430          ($char_stream, $e_status) = $charset->get_decode_handle
431              ($byte_stream, allow_error_reporting => 1,
432               allow_fallback => 1, byte_buffer => \$byte_buffer);
433          $self->{confident} = 1;
434          last SNIFFING;
435        }
436    
437        ## Step 4
438        ## TODO: <meta charset>
439    
440        ## Step 5
441        ## TODO: from history
442    
443        ## Step 6
444      require Whatpm::Charset::UniversalCharDet;      require Whatpm::Charset::UniversalCharDet;
445      $charset = Whatpm::Charset::UniversalCharDet->detect_byte_string      $charset_name = Whatpm::Charset::UniversalCharDet->detect_byte_string
446          (substr ($$bytes_s, 0, 1024));          ($byte_buffer);
447      $charset ||= 'windows-1252';      if (defined $charset_name) {
448      $s = \ (Encode::decode ($charset, $$bytes_s));        $charset = Message::Charset::Info->get_by_html_name ($charset_name);
449      $self->{input_encoding} = $charset;  
450          ## ISSUE: Unsupported encoding is not ignored according to the spec.
451          require Whatpm::Charset::DecodeHandle;
452          $buffer = Whatpm::Charset::DecodeHandle::ByteBuffer->new
453              ($byte_stream);
454          ($char_stream, $e_status) = $charset->get_decode_handle
455              ($buffer, allow_error_reporting => 1,
456               allow_fallback => 1, byte_buffer => \$byte_buffer);
457          if ($char_stream) {
458            $buffer->{buffer} = $byte_buffer;
459            !!!parse-error (type => 'sniffing:chardet',
460                            text => $charset_name,
461                            level => $self->{level}->{info},
462                            layer => 'encode',
463                            line => 1, column => 1);
464            $self->{confident} = 0;
465            last SNIFFING;
466          }
467        }
468    
469        ## Step 7: default
470        ## TODO: Make this configurable.
471        $charset = Message::Charset::Info->get_by_html_name ('windows-1252');
472            ## NOTE: We choose |windows-1252| here, since |utf-8| should be
473            ## detectable in the step 6.
474        require Whatpm::Charset::DecodeHandle;
475        $buffer = Whatpm::Charset::DecodeHandle::ByteBuffer->new
476            ($byte_stream);
477        ($char_stream, $e_status)
478            = $charset->get_decode_handle ($buffer,
479                                           allow_error_reporting => 1,
480                                           allow_fallback => 1,
481                                           byte_buffer => \$byte_buffer);
482        $buffer->{buffer} = $byte_buffer;
483        !!!parse-error (type => 'sniffing:default',
484                        text => 'windows-1252',
485                        level => $self->{level}->{info},
486                        line => 1, column => 1,
487                        layer => 'encode');
488      $self->{confident} = 0;      $self->{confident} = 0;
489      } # SNIFFING
490    
491      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
492        $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name?
493        !!!parse-error (type => 'chardecode:fallback',
494                        #text => $self->{input_encoding},
495                        level => $self->{level}->{uncertain},
496                        line => 1, column => 1,
497                        layer => 'encode');
498      } elsif (not ($e_status &
499                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
500        $self->{input_encoding} = $charset->get_iana_name;
501        !!!parse-error (type => 'chardecode:no error',
502                        text => $self->{input_encoding},
503                        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 {
511      my $self = shift;      my $self = shift;
512      my $charset = lc shift;      $charset_name = shift;
513      my $token = shift;      my $token = shift;
     ## TODO: if $charset is supported  
     ## TODO: normalize charset name  
514    
515      ## "Change the encoding" algorithm:      $charset = Message::Charset::Info->get_by_html_name ($charset_name);
516        ($char_stream, $e_status) = $charset->get_decode_handle
517            ($byte_stream, allow_error_reporting => 1, allow_fallback => 1,
518             byte_buffer => \ $buffer->{buffer});
519        
520        if ($char_stream) { # if supported
521          ## "Change the encoding" algorithm:
522    
523      ## Step 1            ## Step 1    
524      if ($charset eq 'utf-16') { ## ISSUE: UTF-16BE -> UTF-8? UTF-16LE -> UTF-8?        if ($charset->{category} &
525        $charset = '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
528                ($byte_stream,
529                 byte_buffer => \ $buffer->{buffer});
530          }
531          $charset_name = $charset->get_iana_name;
532          
533          ## Step 2
534          if (defined $self->{input_encoding} and
535              $self->{input_encoding} eq $charset_name) {
536            !!!parse-error (type => 'charset label:matching',
537                            text => $charset_name,
538                            level => $self->{level}->{info});
539            $self->{confident} = 1;
540            return;
541          }
542    
543      ## Step 2        !!!parse-error (type => 'charset label detected',
544      if (defined $self->{input_encoding} and                        text => $self->{input_encoding},
545          $self->{input_encoding} eq $charset) {                        value => $charset_name,
546        $self->{confident} = 1;                        level => $self->{level}->{warn},
547        return;                        token => $token);
548          
549          ## Step 3
550          # if (can) {
551            ## change the encoding on the fly.
552            #$self->{confident} = 1;
553            #return;
554          # }
555          
556          ## Step 4
557          throw Whatpm::HTML::RestartParser ();
558      }      }
559      }; # $self->{change_encoding}
560    
561      !!!parse-error (type => 'charset label detected:'.$self->{input_encoding}.    my $char_onerror = sub {
562          ':'.$charset, level => 'w', token => $token);      my (undef, $type, %opt) = @_;
563        !!!parse-error (layer => 'encode',
564      ## Step 3                      %opt, type => $type,
565      # if (can) {                      line => $self->{line}, column => $self->{column} + 1);
566        ## change the encoding on the fly.      if ($opt{octets}) {
567        #$self->{confident} = 1;        ${$opt{octets}} = "\x{FFFD}"; # relacement character
568        #return;      }
569      # }    };
570    
571      ## Step 4    my $wrapped_char_stream = $get_wrapper->($char_stream);
572      throw Whatpm::HTML::RestartParser (charset => $charset);    $wrapped_char_stream->onerror ($char_onerror);
   }; # $self->{change_encoding}  
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_string ($s, @args);        $return = $self->parse_char_stream ($wrapped_char_stream, @args);  
578    } catch Whatpm::HTML::RestartParser with {    } catch Whatpm::HTML::RestartParser with {
579      my $charset = shift->{charset};      ## NOTE: Invoked after {change_encoding}.
580      $s = \ (Encode::decode ($charset, $$bytes_s));      
581      $self->{input_encoding} = $charset; ## TODO: normalize      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
582          $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name?
583          !!!parse-error (type => 'chardecode:fallback',
584                          level => $self->{level}->{uncertain},
585                          #text => $self->{input_encoding},
586                          line => 1, column => 1,
587                          layer => 'encode');
588        } elsif (not ($e_status &
589                      Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
590          $self->{input_encoding} = $charset->get_iana_name;
591          !!!parse-error (type => 'chardecode:no error',
592                          text => $self->{input_encoding},
593                          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      $return = $self->parse_char_string ($s, @args);  
601        $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_string  } # parse_byte_stream
608    
609  ## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM  ## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM
610  ## and the HTML layer MUST ignore it.  However, we does strip BOM in  ## and the HTML layer MUST ignore it.  However, we does strip BOM in
# Line 411  sub parse_byte_string ($$$$;$) { Line 615  sub parse_byte_string ($$$$;$) {
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  *parse_char_string = \&parse_string;  sub parse_char_string ($$$;$$) {
619      #my ($self, $s, $doc, $onerror, $get_wrapper) = @_;
620      my $self = shift;
621      require utf8;
622      my $s = ref $_[0] ? $_[0] : \($_[0]);
623      open my $input, '<' . (utf8::is_utf8 ($$s) ? ':utf8' : ''), $s;
624      if ($_[3]) {
625        $input = $_[3]->($input);
626      }
627      return $self->parse_char_stream ($input, @_[1..$#_]);
628    } # parse_char_string
629    *parse_string = \&parse_char_string; ## NOTE: Alias for backward compatibility.
630    
631  sub parse_string ($$$;$) {  sub parse_char_stream ($$$;$) {
632    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
633    my $s = ref $_[0] ? $_[0] : \($_[0]);    my $input = $_[0];
634    $self->{document} = $_[1];    $self->{document} = $_[1];
635    @{$self->{document}->child_nodes} = ();    @{$self->{document}->child_nodes} = ();
636    
# Line 434  sub parse_string ($$$;$) { Line 649  sub parse_string ($$$;$) {
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      $self->{next_char} = -1 and return if $i >= length $$s;      my $char;
653      $self->{next_char} = ord substr $$s, $i++, 1;      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;
660        $self->{next_char} = ord $char;
661    
662      ($self->{line_prev}, $self->{column_prev})      ($self->{line_prev}, $self->{column_prev})
663          = ($self->{line}, $self->{column});          = ($self->{line}, $self->{column});
# Line 447  sub parse_string ($$$;$) { Line 669  sub parse_string ($$$;$) {
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        $i++ if substr ($$s, $i, 1) eq "\x0A";        my $next = $input->getc;
673          if (defined $next and $next ne "\x0A") {
674            $self->{next_next_char} = $next;
675          }
676        $self->{next_char} = 0x000A; # LF # MUST        $self->{next_char} = 0x000A; # LF # MUST
677        $self->{line}++;        $self->{line}++;
678        $self->{column} = 0;        $self->{column} = 0;
# Line 475  sub parse_string ($$$;$) { Line 700  sub parse_string ($$$;$) {
700                0x10FFFE => 1, 0x10FFFF => 1,                0x10FFFE => 1, 0x10FFFF => 1,
701               }->{$self->{next_char}}) {               }->{$self->{next_char}}) {
702        !!!cp ('j5');        !!!cp ('j5');
703        !!!parse-error (type => 'control char', level => $self->{must_level});        if ($self->{next_char} < 0x10000) {
704  ## TODO: error type documentation          !!!parse-error (type => 'control char',
705                            text => (sprintf 'U+%04X', $self->{next_char}));
706          } else {
707            !!!parse-error (type => 'control char',
708                            text => (sprintf 'U-%08X', $self->{next_char}));
709          }
710      }      }
711    };    };
712    $self->{prev_char} = [-1, -1, -1];    $self->{prev_char} = [-1, -1, -1];
# Line 500  sub parse_string ($$$;$) { Line 730  sub parse_string ($$$;$) {
730    delete $self->{parse_error}; # remove loop    delete $self->{parse_error}; # remove loop
731    
732    return $self->{document};    return $self->{document};
733  } # parse_string  } # parse_char_stream
734    
735  sub new ($) {  sub new ($) {
736    my $class = shift;    my $class = shift;
737    my $self = bless {}, $class;    my $self = bless {
738        level => {must => 'm',
739                  should => 's',
740                  warn => 'w',
741                  info => 'i',
742                  uncertain => 'u'},
743      }, $class;
744    $self->{set_next_char} = sub {    $self->{set_next_char} = sub {
745      $self->{next_char} = -1;      $self->{next_char} = -1;
746    };    };
# Line 567  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STAT Line 803  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STAT
803  sub BOGUS_DOCTYPE_STATE () { 32 }  sub BOGUS_DOCTYPE_STATE () { 32 }
804  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }
805  sub SELF_CLOSING_START_TAG_STATE () { 34 }  sub SELF_CLOSING_START_TAG_STATE () { 34 }
806  sub CDATA_BLOCK_STATE () { 35 }  sub CDATA_SECTION_STATE () { 35 }
807    sub MD_HYPHEN_STATE () { 36 } # "markup declaration open state" in the spec
808    sub MD_DOCTYPE_STATE () { 37 } # "markup declaration open state" in the spec
809    sub MD_CDATA_STATE () { 38 } # "markup declaration open state" in the spec
810    sub CDATA_PCDATA_CLOSE_TAG_STATE () { 39 } # "close tag open state" in the spec
811    sub CDATA_SECTION_MSE1_STATE () { 40 } # "CDATA section state" in the spec
812    sub CDATA_SECTION_MSE2_STATE () { 41 } # "CDATA section state" in the spec
813    sub PUBLIC_STATE () { 42 } # "after DOCTYPE name state" in the spec
814    sub SYSTEM_STATE () { 43 } # "after DOCTYPE name state" in the spec
815    sub ENTITY_STATE () { 44 } # "consume a character reference" in the spec
816    
817  sub DOCTYPE_TOKEN () { 1 }  sub DOCTYPE_TOKEN () { 1 }
818  sub COMMENT_TOKEN () { 2 }  sub COMMENT_TOKEN () { 2 }
# Line 620  sub IN_COLUMN_GROUP_IM () { 0b10 } Line 865  sub IN_COLUMN_GROUP_IM () { 0b10 }
865  sub _initialize_tokenizer ($) {  sub _initialize_tokenizer ($) {
866    my $self = shift;    my $self = shift;
867    $self->{state} = DATA_STATE; # MUST    $self->{state} = DATA_STATE; # MUST
868      #$self->{state_keyword}; # initialized when used
869    $self->{content_model} = PCDATA_CONTENT_MODEL; # be    $self->{content_model} = PCDATA_CONTENT_MODEL; # be
870    undef $self->{current_token}; # start tag, end tag, comment, or DOCTYPE    undef $self->{current_token};
871    undef $self->{current_attribute};    undef $self->{current_attribute};
872    undef $self->{last_emitted_start_tag_name};    undef $self->{last_emitted_start_tag_name};
873    undef $self->{last_attribute_value_state};    undef $self->{last_attribute_value_state};
# Line 650  sub _initialize_tokenizer ($) { Line 896  sub _initialize_tokenizer ($) {
896  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|
897  ##     while the token is pushed back to the stack.  ##     while the token is pushed back to the stack.
898    
 ## 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?  
   
899  ## Emitted token MUST immediately be handled by the tree construction state.  ## Emitted token MUST immediately be handled by the tree construction state.
900    
901  ## 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 699  sub _get_next_token ($) { Line 941  sub _get_next_token ($) {
941          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA
942              not $self->{escape}) {              not $self->{escape}) {
943            !!!cp (1);            !!!cp (1);
944            $self->{state} = ENTITY_DATA_STATE;            ## NOTE: In the spec, the tokenizer is switched to the
945              ## "entity data state".  In this implementation, the tokenizer
946              ## is switched to the |ENTITY_STATE|, which is an implementation
947              ## of the "consume a character reference" algorithm.
948              #$self->{state} = ENTITY_DATA_STATE;
949              $self->{entity_in_attr} = 0;
950              $self->{entity_additional} = -1;
951              $self->{state} = ENTITY_STATE;
952            !!!next-input-character;            !!!next-input-character;
953            redo A;            redo A;
954          } else {          } else {
# Line 770  sub _get_next_token ($) { Line 1019  sub _get_next_token ($) {
1019    
1020        redo A;        redo A;
1021      } elsif ($self->{state} == ENTITY_DATA_STATE) {      } elsif ($self->{state} == ENTITY_DATA_STATE) {
       ## (cannot happen in CDATA state)  
   
1022        my ($l, $c) = ($self->{line_prev}, $self->{column_prev});        my ($l, $c) = ($self->{line_prev}, $self->{column_prev});
1023          
1024        my $token = $self->_tokenize_attempt_to_consume_an_entity (0, -1);        my $token = $self->{entity_return};
1025    
1026        $self->{state} = DATA_STATE;        $self->{state} = DATA_STATE;
1027        # next-input-character is already done        # next-input-character is already done
# Line 869  sub _get_next_token ($) { Line 1116  sub _get_next_token ($) {
1116            redo A;            redo A;
1117          } else {          } else {
1118            !!!cp (23);            !!!cp (23);
1119            !!!parse-error (type => 'bare stago');            !!!parse-error (type => 'bare stago',
1120                              line => $self->{line_prev},
1121                              column => $self->{column_prev});
1122            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1123            ## reconsume            ## reconsume
1124    
# Line 884  sub _get_next_token ($) { Line 1133  sub _get_next_token ($) {
1133          die "$0: $self->{content_model} in tag open";          die "$0: $self->{content_model} in tag open";
1134        }        }
1135      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {
1136          ## NOTE: The "close tag open state" in the spec is implemented as
1137          ## |CLOSE_TAG_OPEN_STATE| and |CDATA_PCDATA_CLOSE_TAG_STATE|.
1138    
1139        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"
1140        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1141          if (defined $self->{last_emitted_start_tag_name}) {          if (defined $self->{last_emitted_start_tag_name}) {
1142              $self->{state} = CDATA_PCDATA_CLOSE_TAG_STATE;
1143            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>            $self->{state_keyword} = '';
1144            my @next_char;            ## Reconsume.
1145            TAGNAME: for (my $i = 0; $i < length $self->{last_emitted_start_tag_name}; $i++) {            redo A;
             push @next_char, $self->{next_char};  
             my $c = ord substr ($self->{last_emitted_start_tag_name}, $i, 1);  
             my $C = 0x0061 <= $c && $c <= 0x007A ? $c - 0x0020 : $c;  
             if ($self->{next_char} == $c or $self->{next_char} == $C) {  
               !!!cp (24);  
               !!!next-input-character;  
               next TAGNAME;  
             } else {  
               !!!cp (25);  
               $self->{next_char} = shift @next_char; # reconsume  
               !!!back-next-input-character (@next_char);  
               $self->{state} = DATA_STATE;  
   
               !!!emit ({type => CHARACTER_TOKEN, data => '</',  
                         line => $l, column => $c,  
                        });  
     
               redo A;  
             }  
           }  
           push @next_char, $self->{next_char};  
         
           unless ($self->{next_char} == 0x0009 or # HT  
                   $self->{next_char} == 0x000A or # LF  
                   $self->{next_char} == 0x000B or # VT  
                   $self->{next_char} == 0x000C or # FF  
                   $self->{next_char} == 0x0020 or # SP  
                   $self->{next_char} == 0x003E or # >  
                   $self->{next_char} == 0x002F or # /  
                   $self->{next_char} == -1) {  
             !!!cp (26);  
             $self->{next_char} = shift @next_char; # reconsume  
             !!!back-next-input-character (@next_char);  
             $self->{state} = DATA_STATE;  
             !!!emit ({type => CHARACTER_TOKEN, data => '</',  
                       line => $l, column => $c,  
                      });  
             redo A;  
           } else {  
             !!!cp (27);  
             $self->{next_char} = shift @next_char;  
             !!!back-next-input-character (@next_char);  
             # and consume...  
           }  
1146          } else {          } else {
1147            ## No start tag token has ever been emitted            ## No start tag token has ever been emitted
1148              ## NOTE: See <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>.
1149            !!!cp (28);            !!!cp (28);
           # next-input-character is already done  
1150            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1151              ## Reconsume.
1152            !!!emit ({type => CHARACTER_TOKEN, data => '</',            !!!emit ({type => CHARACTER_TOKEN, data => '</',
1153                      line => $l, column => $c,                      line => $l, column => $c,
1154                     });                     });
1155            redo A;            redo A;
1156          }          }
1157        }        }
1158          
1159        if (0x0041 <= $self->{next_char} and        if (0x0041 <= $self->{next_char} and
1160            $self->{next_char} <= 0x005A) { # A..Z            $self->{next_char} <= 0x005A) { # A..Z
1161          !!!cp (29);          !!!cp (29);
# Line 993  sub _get_next_token ($) { Line 1202  sub _get_next_token ($) {
1202                                    line => $self->{line_prev}, # "<" of "</"                                    line => $self->{line_prev}, # "<" of "</"
1203                                    column => $self->{column_prev} - 1,                                    column => $self->{column_prev} - 1,
1204                                   };                                   };
1205          ## $self->{next_char} is intentionally left as is          ## NOTE: $self->{next_char} is intentionally left as is.
1206          redo A;          ## Although the "anything else" case of the spec not explicitly
1207            ## states that the next input character is to be reconsumed,
1208            ## it will be included to the |data| of the comment token
1209            ## generated from the bogus end tag, as defined in the
1210            ## "bogus comment state" entry.
1211            redo A;
1212          }
1213        } elsif ($self->{state} == CDATA_PCDATA_CLOSE_TAG_STATE) {
1214          my $ch = substr $self->{last_emitted_start_tag_name}, length $self->{state_keyword}, 1;
1215          if (length $ch) {
1216            my $CH = $ch;
1217            $ch =~ tr/a-z/A-Z/;
1218            my $nch = chr $self->{next_char};
1219            if ($nch eq $ch or $nch eq $CH) {
1220              !!!cp (24);
1221              ## Stay in the state.
1222              $self->{state_keyword} .= $nch;
1223              !!!next-input-character;
1224              redo A;
1225            } else {
1226              !!!cp (25);
1227              $self->{state} = DATA_STATE;
1228              ## Reconsume.
1229              !!!emit ({type => CHARACTER_TOKEN,
1230                        data => '</' . $self->{state_keyword},
1231                        line => $self->{line_prev},
1232                        column => $self->{column_prev} - 1 - length $self->{state_keyword},
1233                       });
1234              redo A;
1235            }
1236          } else { # after "<{tag-name}"
1237            unless ({
1238                     0x0009 => 1, # HT
1239                     0x000A => 1, # LF
1240                     0x000B => 1, # VT
1241                     0x000C => 1, # FF
1242                     0x0020 => 1, # SP
1243                     0x003E => 1, # >
1244                     0x002F => 1, # /
1245                     -1 => 1, # EOF
1246                    }->{$self->{next_char}}) {
1247              !!!cp (26);
1248              ## Reconsume.
1249              $self->{state} = DATA_STATE;
1250              !!!emit ({type => CHARACTER_TOKEN,
1251                        data => '</' . $self->{state_keyword},
1252                        line => $self->{line_prev},
1253                        column => $self->{column_prev} - 1 - length $self->{state_keyword},
1254                       });
1255              redo A;
1256            } else {
1257              !!!cp (27);
1258              $self->{current_token}
1259                  = {type => END_TAG_TOKEN,
1260                     tag_name => $self->{last_emitted_start_tag_name},
1261                     line => $self->{line_prev},
1262                     column => $self->{column_prev} - 1 - length $self->{state_keyword}};
1263              $self->{state} = TAG_NAME_STATE;
1264              ## Reconsume.
1265              redo A;
1266            }
1267        }        }
1268      } elsif ($self->{state} == TAG_NAME_STATE) {      } elsif ($self->{state} == TAG_NAME_STATE) {
1269        if ($self->{next_char} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
# Line 1164  sub _get_next_token ($) { Line 1433  sub _get_next_token ($) {
1433          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
1434              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
1435            !!!cp (57);            !!!cp (57);
1436            !!!parse-error (type => 'duplicate attribute:'.$self->{current_attribute}->{name}, line => $self->{current_attribute}->{line}, column => $self->{current_attribute}->{column});            !!!parse-error (type => 'duplicate attribute', text => $self->{current_attribute}->{name}, line => $self->{current_attribute}->{line}, column => $self->{current_attribute}->{column});
1437            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{current_attribute} # MUST
1438          } else {          } else {
1439            !!!cp (58);            !!!cp (58);
# Line 1335  sub _get_next_token ($) { Line 1604  sub _get_next_token ($) {
1604    
1605          redo A;          redo A;
1606        } else {        } else {
1607          !!!cp (82);          if ($self->{next_char} == 0x0022 or # "
1608                $self->{next_char} == 0x0027) { # '
1609              !!!cp (78);
1610              !!!parse-error (type => 'bad attribute name');
1611            } else {
1612              !!!cp (82);
1613            }
1614          $self->{current_attribute}          $self->{current_attribute}
1615              = {name => chr ($self->{next_char}),              = {name => chr ($self->{next_char}),
1616                 value => '',                 value => '',
# Line 1370  sub _get_next_token ($) { Line 1645  sub _get_next_token ($) {
1645          !!!next-input-character;          !!!next-input-character;
1646          redo A;          redo A;
1647        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1648            !!!parse-error (type => 'empty unquoted attribute value');
1649          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1650            !!!cp (87);            !!!cp (87);
1651            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
# Line 1435  sub _get_next_token ($) { Line 1711  sub _get_next_token ($) {
1711        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1712          !!!cp (96);          !!!cp (96);
1713          $self->{last_attribute_value_state} = $self->{state};          $self->{last_attribute_value_state} = $self->{state};
1714          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## NOTE: In the spec, the tokenizer is switched to the
1715            ## "entity in attribute value state".  In this implementation, the
1716            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1717            ## implementation of the "consume a character reference" algorithm.
1718            #$self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;
1719            $self->{entity_in_attr} = 1;
1720            $self->{entity_additional} = 0x0022; # "
1721            $self->{state} = ENTITY_STATE;
1722          !!!next-input-character;          !!!next-input-character;
1723          redo A;          redo A;
1724        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
# Line 1477  sub _get_next_token ($) { Line 1760  sub _get_next_token ($) {
1760        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1761          !!!cp (102);          !!!cp (102);
1762          $self->{last_attribute_value_state} = $self->{state};          $self->{last_attribute_value_state} = $self->{state};
1763          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## NOTE: In the spec, the tokenizer is switched to the
1764            ## "entity in attribute value state".  In this implementation, the
1765            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1766            ## implementation of the "consume a character reference" algorithm.
1767            #$self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;
1768            $self->{entity_in_attr} = 1;
1769            $self->{entity_additional} = 0x0027; # '
1770            $self->{state} = ENTITY_STATE;
1771          !!!next-input-character;          !!!next-input-character;
1772          redo A;          redo A;
1773        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
# Line 1523  sub _get_next_token ($) { Line 1813  sub _get_next_token ($) {
1813        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1814          !!!cp (108);          !!!cp (108);
1815          $self->{last_attribute_value_state} = $self->{state};          $self->{last_attribute_value_state} = $self->{state};
1816          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## NOTE: In the spec, the tokenizer is switched to the
1817            ## "entity in attribute value state".  In this implementation, the
1818            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1819            ## implementation of the "consume a character reference" algorithm.
1820            #$self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;
1821            $self->{entity_in_attr} = 1;
1822            $self->{entity_additional} = -1;
1823            $self->{state} = ENTITY_STATE;
1824          !!!next-input-character;          !!!next-input-character;
1825          redo A;          redo A;
1826        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
# Line 1588  sub _get_next_token ($) { Line 1885  sub _get_next_token ($) {
1885          redo A;          redo A;
1886        }        }
1887      } elsif ($self->{state} == ENTITY_IN_ATTRIBUTE_VALUE_STATE) {      } elsif ($self->{state} == ENTITY_IN_ATTRIBUTE_VALUE_STATE) {
1888        my $token = $self->_tokenize_attempt_to_consume_an_entity        my $token = $self->{entity_return};
           (1,  
            $self->{last_attribute_value_state}  
              == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE ? 0x0022 : # "  
            $self->{last_attribute_value_state}  
              == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE ? 0x0027 : # '  
            -1);  
1889    
1890        unless (defined $token) {        unless (defined $token) {
1891          !!!cp (117);          !!!cp (117);
# Line 1646  sub _get_next_token ($) { Line 1937  sub _get_next_token ($) {
1937          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1938          !!!next-input-character;          !!!next-input-character;
1939          redo A;          redo A;
1940          } elsif ($self->{next_char} == -1) {
1941            !!!parse-error (type => 'unclosed tag');
1942            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1943              !!!cp (122.3);
1944              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1945            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1946              if ($self->{current_token}->{attributes}) {
1947                !!!cp (122.1);
1948                !!!parse-error (type => 'end tag attribute');
1949              } else {
1950                ## NOTE: This state should never be reached.
1951                !!!cp (122.2);
1952              }
1953            } else {
1954              die "$0: $self->{current_token}->{type}: Unknown token type";
1955            }
1956            $self->{state} = DATA_STATE;
1957            ## Reconsume.
1958            !!!emit ($self->{current_token}); # start tag or end tag
1959            redo A;
1960        } else {        } else {
1961          !!!cp ('124.1');          !!!cp ('124.1');
1962          !!!parse-error (type => 'no space between attributes');          !!!parse-error (type => 'no space between attributes');
# Line 1678  sub _get_next_token ($) { Line 1989  sub _get_next_token ($) {
1989          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
1990    
1991          redo A;          redo A;
1992          } elsif ($self->{next_char} == -1) {
1993            !!!parse-error (type => 'unclosed tag');
1994            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1995              !!!cp (124.7);
1996              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1997            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1998              if ($self->{current_token}->{attributes}) {
1999                !!!cp (124.5);
2000                !!!parse-error (type => 'end tag attribute');
2001              } else {
2002                ## NOTE: This state should never be reached.
2003                !!!cp (124.6);
2004              }
2005            } else {
2006              die "$0: $self->{current_token}->{type}: Unknown token type";
2007            }
2008            $self->{state} = DATA_STATE;
2009            ## Reconsume.
2010            !!!emit ($self->{current_token}); # start tag or end tag
2011            redo A;
2012        } else {        } else {
2013          !!!cp ('124.4');          !!!cp ('124.4');
2014          !!!parse-error (type => 'nestc');          !!!parse-error (type => 'nestc');
# Line 1688  sub _get_next_token ($) { Line 2019  sub _get_next_token ($) {
2019        }        }
2020      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {
2021        ## (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  
   
           redo A;  
         } elsif ($self->{next_char} == -1) {  
           !!!cp (125);  
           $self->{state} = DATA_STATE;  
           ## reconsume  
2022    
2023            !!!emit ($self->{current_token}); # comment        ## NOTE: Unlike spec's "bogus comment state", this implementation
2024          ## consumes characters one-by-one basis.
2025          
2026          if ($self->{next_char} == 0x003E) { # >
2027            !!!cp (124);
2028            $self->{state} = DATA_STATE;
2029            !!!next-input-character;
2030    
2031            redo A;          !!!emit ($self->{current_token}); # comment
2032          } else {          redo A;
2033            !!!cp (126);        } elsif ($self->{next_char} == -1) {
2034            $self->{current_token}->{data} .= chr ($self->{next_char}); # comment          !!!cp (125);
2035            !!!next-input-character;          $self->{state} = DATA_STATE;
2036            redo BC;          ## reconsume
         }  
       } # BC  
2037    
2038        die "$0: _get_next_token: unexpected case [BC]";          !!!emit ($self->{current_token}); # comment
2039            redo A;
2040          } else {
2041            !!!cp (126);
2042            $self->{current_token}->{data} .= chr ($self->{next_char}); # comment
2043            ## Stay in the state.
2044            !!!next-input-character;
2045            redo A;
2046          }
2047      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {
2048        ## (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};  
2049                
2050        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
2051            !!!cp (133);
2052            $self->{state} = MD_HYPHEN_STATE;
2053          !!!next-input-character;          !!!next-input-character;
2054          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);  
         }  
2055        } elsif ($self->{next_char} == 0x0044 or # D        } elsif ($self->{next_char} == 0x0044 or # D
2056                 $self->{next_char} == 0x0064) { # d                 $self->{next_char} == 0x0064) { # d
2057            ## ASCII case-insensitive.
2058            !!!cp (130);
2059            $self->{state} = MD_DOCTYPE_STATE;
2060            $self->{state_keyword} = chr $self->{next_char};
2061          !!!next-input-character;          !!!next-input-character;
2062          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);  
         }  
2063        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and
2064                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and
2065                 $self->{next_char} == 0x005B) { # [                 $self->{next_char} == 0x005B) { # [
2066            !!!cp (135.4);                
2067            $self->{state} = MD_CDATA_STATE;
2068            $self->{state_keyword} = '[';
2069          !!!next-input-character;          !!!next-input-character;
2070          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);  
         }  
2071        } else {        } else {
2072          !!!cp (136);          !!!cp (136);
2073        }        }
2074    
2075        !!!parse-error (type => 'bogus comment');        !!!parse-error (type => 'bogus comment',
2076        $self->{next_char} = shift @next_char;                        line => $self->{line_prev},
2077        !!!back-next-input-character (@next_char);                        column => $self->{column_prev} - 1);
2078          ## Reconsume.
2079        $self->{state} = BOGUS_COMMENT_STATE;        $self->{state} = BOGUS_COMMENT_STATE;
2080        $self->{current_token} = {type => COMMENT_TOKEN, data => '',        $self->{current_token} = {type => COMMENT_TOKEN, data => '',
2081                                  line => $l, column => $c,                                  line => $self->{line_prev},
2082                                    column => $self->{column_prev} - 1,
2083                                 };                                 };
2084        redo A;        redo A;
2085              } elsif ($self->{state} == MD_HYPHEN_STATE) {
2086        ## ISSUE: typos in spec: chacacters, is is a parse error        if ($self->{next_char} == 0x002D) { # -
2087        ## 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);
2088            $self->{current_token} = {type => COMMENT_TOKEN, data => '',
2089                                      line => $self->{line_prev},
2090                                      column => $self->{column_prev} - 2,
2091                                     };
2092            $self->{state} = COMMENT_START_STATE;
2093            !!!next-input-character;
2094            redo A;
2095          } else {
2096            !!!cp (128);
2097            !!!parse-error (type => 'bogus comment',
2098                            line => $self->{line_prev},
2099                            column => $self->{column_prev} - 2);
2100            $self->{state} = BOGUS_COMMENT_STATE;
2101            ## Reconsume.
2102            $self->{current_token} = {type => COMMENT_TOKEN,
2103                                      data => '-',
2104                                      line => $self->{line_prev},
2105                                      column => $self->{column_prev} - 2,
2106                                     };
2107            redo A;
2108          }
2109        } elsif ($self->{state} == MD_DOCTYPE_STATE) {
2110          ## ASCII case-insensitive.
2111          if ($self->{next_char} == [
2112                undef,
2113                0x004F, # O
2114                0x0043, # C
2115                0x0054, # T
2116                0x0059, # Y
2117                0x0050, # P
2118              ]->[length $self->{state_keyword}] or
2119              $self->{next_char} == [
2120                undef,
2121                0x006F, # o
2122                0x0063, # c
2123                0x0074, # t
2124                0x0079, # y
2125                0x0070, # p
2126              ]->[length $self->{state_keyword}]) {
2127            !!!cp (131);
2128            ## Stay in the state.
2129            $self->{state_keyword} .= chr $self->{next_char};
2130            !!!next-input-character;
2131            redo A;
2132          } elsif ((length $self->{state_keyword}) == 6 and
2133                   ($self->{next_char} == 0x0045 or # E
2134                    $self->{next_char} == 0x0065)) { # e
2135            !!!cp (129);
2136            $self->{state} = DOCTYPE_STATE;
2137            $self->{current_token} = {type => DOCTYPE_TOKEN,
2138                                      quirks => 1,
2139                                      line => $self->{line_prev},
2140                                      column => $self->{column_prev} - 7,
2141                                     };
2142            !!!next-input-character;
2143            redo A;
2144          } else {
2145            !!!cp (132);        
2146            !!!parse-error (type => 'bogus comment',
2147                            line => $self->{line_prev},
2148                            column => $self->{column_prev} - 1 - length $self->{state_keyword});
2149            $self->{state} = BOGUS_COMMENT_STATE;
2150            ## Reconsume.
2151            $self->{current_token} = {type => COMMENT_TOKEN,
2152                                      data => $self->{state_keyword},
2153                                      line => $self->{line_prev},
2154                                      column => $self->{column_prev} - 1 - length $self->{state_keyword},
2155                                     };
2156            redo A;
2157          }
2158        } elsif ($self->{state} == MD_CDATA_STATE) {
2159          if ($self->{next_char} == {
2160                '[' => 0x0043, # C
2161                '[C' => 0x0044, # D
2162                '[CD' => 0x0041, # A
2163                '[CDA' => 0x0054, # T
2164                '[CDAT' => 0x0041, # A
2165              }->{$self->{state_keyword}}) {
2166            !!!cp (135.1);
2167            ## Stay in the state.
2168            $self->{state_keyword} .= chr $self->{next_char};
2169            !!!next-input-character;
2170            redo A;
2171          } elsif ($self->{state_keyword} eq '[CDATA' and
2172                   $self->{next_char} == 0x005B) { # [
2173            !!!cp (135.2);
2174            $self->{current_token} = {type => CHARACTER_TOKEN,
2175                                      data => '',
2176                                      line => $self->{line_prev},
2177                                      column => $self->{column_prev} - 7};
2178            $self->{state} = CDATA_SECTION_STATE;
2179            !!!next-input-character;
2180            redo A;
2181          } else {
2182            !!!cp (135.3);
2183            !!!parse-error (type => 'bogus comment',
2184                            line => $self->{line_prev},
2185                            column => $self->{column_prev} - 1 - length $self->{state_keyword});
2186            $self->{state} = BOGUS_COMMENT_STATE;
2187            ## Reconsume.
2188            $self->{current_token} = {type => COMMENT_TOKEN,
2189                                      data => $self->{state_keyword},
2190                                      line => $self->{line_prev},
2191                                      column => $self->{column_prev} - 1 - length $self->{state_keyword},
2192                                     };
2193            redo A;
2194          }
2195      } elsif ($self->{state} == COMMENT_START_STATE) {      } elsif ($self->{state} == COMMENT_START_STATE) {
2196        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
2197          !!!cp (137);          !!!cp (137);
# Line 2117  sub _get_next_token ($) { Line 2458  sub _get_next_token ($) {
2458          redo A;          redo A;
2459        } elsif ($self->{next_char} == 0x0050 or # P        } elsif ($self->{next_char} == 0x0050 or # P
2460                 $self->{next_char} == 0x0070) { # p                 $self->{next_char} == 0x0070) { # p
2461            $self->{state} = PUBLIC_STATE;
2462            $self->{state_keyword} = chr $self->{next_char};
2463          !!!next-input-character;          !!!next-input-character;
2464          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);  
         }  
   
         #  
2465        } elsif ($self->{next_char} == 0x0053 or # S        } elsif ($self->{next_char} == 0x0053 or # S
2466                 $self->{next_char} == 0x0073) { # s                 $self->{next_char} == 0x0073) { # s
2467            $self->{state} = SYSTEM_STATE;
2468            $self->{state_keyword} = chr $self->{next_char};
2469          !!!next-input-character;          !!!next-input-character;
2470          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);  
         }  
   
         #  
2471        } else {        } else {
2472          !!!cp (180);          !!!cp (180);
2473            !!!parse-error (type => 'string after DOCTYPE name');
2474            $self->{current_token}->{quirks} = 1;
2475    
2476            $self->{state} = BOGUS_DOCTYPE_STATE;
2477          !!!next-input-character;          !!!next-input-character;
2478          #          redo A;
2479        }        }
2480        } elsif ($self->{state} == PUBLIC_STATE) {
2481          ## ASCII case-insensitive
2482          if ($self->{next_char} == [
2483                undef,
2484                0x0055, # U
2485                0x0042, # B
2486                0x004C, # L
2487                0x0049, # I
2488              ]->[length $self->{state_keyword}] or
2489              $self->{next_char} == [
2490                undef,
2491                0x0075, # u
2492                0x0062, # b
2493                0x006C, # l
2494                0x0069, # i
2495              ]->[length $self->{state_keyword}]) {
2496            !!!cp (175);
2497            ## Stay in the state.
2498            $self->{state_keyword} .= chr $self->{next_char};
2499            !!!next-input-character;
2500            redo A;
2501          } elsif ((length $self->{state_keyword}) == 5 and
2502                   ($self->{next_char} == 0x0043 or # C
2503                    $self->{next_char} == 0x0063)) { # c
2504            !!!cp (168);
2505            $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
2506            !!!next-input-character;
2507            redo A;
2508          } else {
2509            !!!cp (169);
2510            !!!parse-error (type => 'string after DOCTYPE name',
2511                            line => $self->{line_prev},
2512                            column => $self->{column_prev} + 1 - length $self->{state_keyword});
2513            $self->{current_token}->{quirks} = 1;
2514    
2515        !!!parse-error (type => 'string after DOCTYPE name');          $self->{state} = BOGUS_DOCTYPE_STATE;
2516        $self->{current_token}->{quirks} = 1;          ## Reconsume.
2517            redo A;
2518          }
2519        } elsif ($self->{state} == SYSTEM_STATE) {
2520          ## ASCII case-insensitive
2521          if ($self->{next_char} == [
2522                undef,
2523                0x0059, # Y
2524                0x0053, # S
2525                0x0054, # T
2526                0x0045, # E
2527              ]->[length $self->{state_keyword}] or
2528              $self->{next_char} == [
2529                undef,
2530                0x0079, # y
2531                0x0073, # s
2532                0x0074, # t
2533                0x0065, # e
2534              ]->[length $self->{state_keyword}]) {
2535            !!!cp (170);
2536            ## Stay in the state.
2537            $self->{state_keyword} .= chr $self->{next_char};
2538            !!!next-input-character;
2539            redo A;
2540          } elsif ((length $self->{state_keyword}) == 5 and
2541                   ($self->{next_char} == 0x004D or # M
2542                    $self->{next_char} == 0x006D)) { # m
2543            !!!cp (171);
2544            $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2545            !!!next-input-character;
2546            redo A;
2547          } else {
2548            !!!cp (172);
2549            !!!parse-error (type => 'string after DOCTYPE name',
2550                            line => $self->{line_prev},
2551                            column => $self->{column_prev} + 1 - length $self->{state_keyword});
2552            $self->{current_token}->{quirks} = 1;
2553    
2554        $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2555        # next-input-character is already done          ## Reconsume.
2556        redo A;          redo A;
2557          }
2558      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {
2559        if ({        if ({
2560              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
# Line 2435  sub _get_next_token ($) { Line 2787  sub _get_next_token ($) {
2787          redo A;          redo A;
2788        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2789          !!!cp (208);          !!!cp (208);
2790          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2791    
2792          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2793          !!!next-input-character;          !!!next-input-character;
# Line 2471  sub _get_next_token ($) { Line 2823  sub _get_next_token ($) {
2823          redo A;          redo A;
2824        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2825          !!!cp (212);          !!!cp (212);
2826          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2827    
2828          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2829          !!!next-input-character;          !!!next-input-character;
# Line 2519  sub _get_next_token ($) { Line 2871  sub _get_next_token ($) {
2871        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
2872          !!!cp (217);          !!!cp (217);
2873          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
   
2874          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2875          ## reconsume          ## reconsume
2876    
# Line 2560  sub _get_next_token ($) { Line 2911  sub _get_next_token ($) {
2911          !!!next-input-character;          !!!next-input-character;
2912          redo A;          redo A;
2913        }        }
2914      } elsif ($self->{state} == CDATA_BLOCK_STATE) {      } elsif ($self->{state} == CDATA_SECTION_STATE) {
2915        my $s = '';        ## NOTE: "CDATA section state" in the state is jointly implemented
2916          ## by three states, |CDATA_SECTION_STATE|, |CDATA_SECTION_MSE1_STATE|,
2917          ## and |CDATA_SECTION_MSE2_STATE|.
2918                
2919        my ($l, $c) = ($self->{line}, $self->{column});        if ($self->{next_char} == 0x005D) { # ]
2920            !!!cp (221.1);
2921            $self->{state} = CDATA_SECTION_MSE1_STATE;
2922            !!!next-input-character;
2923            redo A;
2924          } elsif ($self->{next_char} == -1) {
2925            $self->{state} = DATA_STATE;
2926            !!!next-input-character;
2927            if (length $self->{current_token}->{data}) { # character
2928              !!!cp (221.2);
2929              !!!emit ($self->{current_token}); # character
2930            } else {
2931              !!!cp (221.3);
2932              ## No token to emit. $self->{current_token} is discarded.
2933            }        
2934            redo A;
2935          } else {
2936            !!!cp (221.4);
2937            $self->{current_token}->{data} .= chr $self->{next_char};
2938            ## Stay in the state.
2939            !!!next-input-character;
2940            redo A;
2941          }
2942    
2943        CS: while ($self->{next_char} != -1) {        ## ISSUE: "text tokens" in spec.
2944          if ($self->{next_char} == 0x005D) { # ]      } elsif ($self->{state} == CDATA_SECTION_MSE1_STATE) {
2945            !!!next-input-character;        if ($self->{next_char} == 0x005D) { # ]
2946            if ($self->{next_char} == 0x005D) { # ]          !!!cp (221.5);
2947              !!!next-input-character;          $self->{state} = CDATA_SECTION_MSE2_STATE;
2948              MDC: {          !!!next-input-character;
2949                if ($self->{next_char} == 0x003E) { # >          redo A;
2950                  !!!cp (221.1);        } else {
2951                  !!!next-input-character;          !!!cp (221.6);
2952                  last CS;          $self->{current_token}->{data} .= ']';
2953                } elsif ($self->{next_char} == 0x005D) { # ]          $self->{state} = CDATA_SECTION_STATE;
2954                  !!!cp (221.2);          ## Reconsume.
2955                  $s .= ']';          redo A;
2956                  !!!next-input-character;        }
2957                  redo MDC;      } elsif ($self->{state} == CDATA_SECTION_MSE2_STATE) {
2958                } else {        if ($self->{next_char} == 0x003E) { # >
2959                  !!!cp (221.3);          $self->{state} = DATA_STATE;
2960                  $s .= ']]';          !!!next-input-character;
2961                  #          if (length $self->{current_token}->{data}) { # character
2962                }            !!!cp (221.7);
2963              } # MDC            !!!emit ($self->{current_token}); # character
           } else {  
             !!!cp (221.4);  
             $s .= ']';  
             #  
           }  
2964          } else {          } else {
2965            !!!cp (221.5);            !!!cp (221.8);
2966            #            ## No token to emit. $self->{current_token} is discarded.
2967          }          }
2968          $s .= chr $self->{next_char};          redo A;
2969          } elsif ($self->{next_char} == 0x005D) { # ]
2970            !!!cp (221.9); # character
2971            $self->{current_token}->{data} .= ']'; ## Add first "]" of "]]]".
2972            ## Stay in the state.
2973          !!!next-input-character;          !!!next-input-character;
2974        } # 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});  
2975        } else {        } else {
2976          !!!cp (221.7);          !!!cp (221.11);
2977            $self->{current_token}->{data} .= ']]'; # character
2978            $self->{state} = CDATA_SECTION_STATE;
2979            ## Reconsume.
2980            redo A;
2981        }        }
2982    
2983        redo A;      } elsif ($self->{state} == ENTITY_STATE) {
2984          my $in_attr = $self->{entity_in_attr};
2985        ## ISSUE: "text tokens" in spec.        my $additional = $self->{entity_additional};
       ## TODO: Streaming support  
     } else {  
       die "$0: $self->{state}: Unknown state";  
     }  
   } # A    
   
   die "$0: _get_next_token: unexpected case";  
 } # _get_next_token  
   
 sub _tokenize_attempt_to_consume_an_entity ($$$) {  
   my ($self, $in_attr, $additional) = @_;  
2986    
2987    my ($l, $c) = ($self->{line_prev}, $self->{column_prev});    my ($l, $c) = ($self->{line_prev}, $self->{column_prev});
2988    
# Line 2635  sub _tokenize_attempt_to_consume_an_enti Line 2994  sub _tokenize_attempt_to_consume_an_enti
2994      !!!cp (1001);      !!!cp (1001);
2995      ## Don't consume      ## Don't consume
2996      ## No error      ## No error
2997      return undef;      $self->{entity_return} = undef;
2998        $self->{state} = $self->{entity_in_attr} ? ENTITY_IN_ATTRIBUTE_VALUE_STATE : ENTITY_DATA_STATE;
2999        redo A;
3000    } elsif ($self->{next_char} == 0x0023) { # #    } elsif ($self->{next_char} == 0x0023) { # #
3001      !!!next-input-character;      !!!next-input-character;
3002      if ($self->{next_char} == 0x0078 or # x      if ($self->{next_char} == 0x0078 or # x
# Line 2670  sub _tokenize_attempt_to_consume_an_enti Line 3031  sub _tokenize_attempt_to_consume_an_enti
3031            !!!parse-error (type => 'bare hcro', line => $l, column => $c);            !!!parse-error (type => 'bare hcro', line => $l, column => $c);
3032            !!!back-next-input-character ($x_char, $self->{next_char});            !!!back-next-input-character ($x_char, $self->{next_char});
3033            $self->{next_char} = 0x0023; # #            $self->{next_char} = 0x0023; # #
3034            return undef;            $self->{entity_return} = undef;
3035              $self->{state} = $self->{entity_in_attr} ? ENTITY_IN_ATTRIBUTE_VALUE_STATE : ENTITY_DATA_STATE;
3036              redo A;
3037          } elsif ($self->{next_char} == 0x003B) { # ;          } elsif ($self->{next_char} == 0x003B) { # ;
3038            !!!cp (1006);            !!!cp (1006);
3039            !!!next-input-character;            !!!next-input-character;
# Line 2681  sub _tokenize_attempt_to_consume_an_enti Line 3044  sub _tokenize_attempt_to_consume_an_enti
3044    
3045          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3046            !!!cp (1008);            !!!cp (1008);
3047            !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
3048                              text => (sprintf 'U+%04X', $code),
3049                              line => $l, column => $c);
3050            $code = 0xFFFD;            $code = 0xFFFD;
3051          } elsif ($code > 0x10FFFF) {          } elsif ($code > 0x10FFFF) {
3052            !!!cp (1009);            !!!cp (1009);
3053            !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
3054                              text => (sprintf 'U-%08X', $code),
3055                              line => $l, column => $c);
3056            $code = 0xFFFD;            $code = 0xFFFD;
3057          } elsif ($code == 0x000D) {          } elsif ($code == 0x000D) {
3058            !!!cp (1010);            !!!cp (1010);
# Line 2693  sub _tokenize_attempt_to_consume_an_enti Line 3060  sub _tokenize_attempt_to_consume_an_enti
3060            $code = 0x000A;            $code = 0x000A;
3061          } elsif (0x80 <= $code and $code <= 0x9F) {          } elsif (0x80 <= $code and $code <= 0x9F) {
3062            !!!cp (1011);            !!!cp (1011);
3063            !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);            !!!parse-error (type => 'C1 character reference', text => (sprintf 'U+%04X', $code), line => $l, column => $c);
3064            $code = $c1_entity_char->{$code};            $code = $c1_entity_char->{$code};
3065          }          }
3066    
3067          return {type => CHARACTER_TOKEN, data => chr $code,          $self->{entity_return} = {type => CHARACTER_TOKEN, data => chr $code,
3068                  has_reference => 1,                  has_reference => 1,
3069                  line => $l, column => $c,                  line => $l, column => $c,
3070                 };                 };
3071            $self->{state} = $self->{entity_in_attr} ? ENTITY_IN_ATTRIBUTE_VALUE_STATE : ENTITY_DATA_STATE;
3072            redo A;
3073        } # X        } # X
3074      } elsif (0x0030 <= $self->{next_char} and      } elsif (0x0030 <= $self->{next_char} and
3075               $self->{next_char} <= 0x0039) { # 0..9               $self->{next_char} <= 0x0039) { # 0..9
# Line 2726  sub _tokenize_attempt_to_consume_an_enti Line 3095  sub _tokenize_attempt_to_consume_an_enti
3095    
3096        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3097          !!!cp (1015);          !!!cp (1015);
3098          !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3099                            text => (sprintf 'U+%04X', $code),
3100                            line => $l, column => $c);
3101          $code = 0xFFFD;          $code = 0xFFFD;
3102        } elsif ($code > 0x10FFFF) {        } elsif ($code > 0x10FFFF) {
3103          !!!cp (1016);          !!!cp (1016);
3104          !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3105                            text => (sprintf 'U-%08X', $code),
3106                            line => $l, column => $c);
3107          $code = 0xFFFD;          $code = 0xFFFD;
3108        } elsif ($code == 0x000D) {        } elsif ($code == 0x000D) {
3109          !!!cp (1017);          !!!cp (1017);
3110          !!!parse-error (type => 'CR character reference', line => $l, column => $c);          !!!parse-error (type => 'CR character reference',
3111                            line => $l, column => $c);
3112          $code = 0x000A;          $code = 0x000A;
3113        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
3114          !!!cp (1018);          !!!cp (1018);
3115          !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'C1 character reference',
3116                            text => (sprintf 'U+%04X', $code),
3117                            line => $l, column => $c);
3118          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
3119        }        }
3120                
3121        return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1,        $self->{entity_return} = {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1,
3122                line => $l, column => $c,                line => $l, column => $c,
3123               };               };
3124          $self->{state} = $self->{entity_in_attr} ? ENTITY_IN_ATTRIBUTE_VALUE_STATE : ENTITY_DATA_STATE;
3125          redo A;
3126      } else {      } else {
3127        !!!cp (1019);        !!!cp (1019);
3128        !!!parse-error (type => 'bare nero', line => $l, column => $c);        !!!parse-error (type => 'bare nero', line => $l, column => $c);
3129        !!!back-next-input-character ($self->{next_char});        !!!back-next-input-character ($self->{next_char});
3130        $self->{next_char} = 0x0023; # #        $self->{next_char} = 0x0023; # #
3131        return undef;        $self->{entity_return} = undef;
3132          $self->{state} = $self->{entity_in_attr} ? ENTITY_IN_ATTRIBUTE_VALUE_STATE : ENTITY_DATA_STATE;
3133          redo A;
3134      }      }
3135    } elsif ((0x0041 <= $self->{next_char} and    } elsif ((0x0041 <= $self->{next_char} and
3136              $self->{next_char} <= 0x005A) or              $self->{next_char} <= 0x005A) or
# Line 2797  sub _tokenize_attempt_to_consume_an_enti Line 3177  sub _tokenize_attempt_to_consume_an_enti
3177            
3178      if ($match > 0) {      if ($match > 0) {
3179        !!!cp (1023);        !!!cp (1023);
3180        return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,        $self->{entity_return} = {type => CHARACTER_TOKEN, data => $value, has_reference => 1,
3181                line => $l, column => $c,                line => $l, column => $c,
3182               };               };
3183          $self->{state} = $self->{entity_in_attr} ? ENTITY_IN_ATTRIBUTE_VALUE_STATE : ENTITY_DATA_STATE;
3184          redo A;
3185      } elsif ($match < 0) {      } elsif ($match < 0) {
3186        !!!parse-error (type => 'no refc', line => $l, column => $c);        !!!parse-error (type => 'no refc', line => $l, column => $c);
3187        if ($in_attr and $match < -1) {        if ($in_attr and $match < -1) {
3188          !!!cp (1024);          !!!cp (1024);
3189          return {type => CHARACTER_TOKEN, data => '&'.$entity_name,          $self->{entity_return} = {type => CHARACTER_TOKEN, data => '&'.$entity_name,
3190                  line => $l, column => $c,                  line => $l, column => $c,
3191                 };                 };
3192            $self->{state} = $self->{entity_in_attr} ? ENTITY_IN_ATTRIBUTE_VALUE_STATE : ENTITY_DATA_STATE;
3193            redo A;
3194        } else {        } else {
3195          !!!cp (1025);          !!!cp (1025);
3196          return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,          $self->{entity_return} = {type => CHARACTER_TOKEN, data => $value, has_reference => 1,
3197                  line => $l, column => $c,                  line => $l, column => $c,
3198                 };                 };
3199            $self->{state} = $self->{entity_in_attr} ? ENTITY_IN_ATTRIBUTE_VALUE_STATE : ENTITY_DATA_STATE;
3200            redo A;
3201        }        }
3202      } else {      } else {
3203        !!!cp (1026);        !!!cp (1026);
3204        !!!parse-error (type => 'bare ero', line => $l, column => $c);        !!!parse-error (type => 'bare ero', line => $l, column => $c);
3205        ## NOTE: "No characters are consumed" in the spec.        ## NOTE: "No characters are consumed" in the spec.
3206        return {type => CHARACTER_TOKEN, data => '&'.$value,        $self->{entity_return} = {type => CHARACTER_TOKEN, data => '&'.$value,
3207                line => $l, column => $c,                line => $l, column => $c,
3208               };               };
3209          $self->{state} = $self->{entity_in_attr} ? ENTITY_IN_ATTRIBUTE_VALUE_STATE : ENTITY_DATA_STATE;
3210          redo A;
3211      }      }
3212    } else {    } else {
3213      !!!cp (1027);      !!!cp (1027);
3214      ## no characters are consumed      ## no characters are consumed
3215      !!!parse-error (type => 'bare ero', line => $l, column => $c);      !!!parse-error (type => 'bare ero', line => $l, column => $c);
3216      return undef;      $self->{entity_return} = undef;
3217        $self->{state} = $self->{entity_in_attr} ? ENTITY_IN_ATTRIBUTE_VALUE_STATE : ENTITY_DATA_STATE;
3218        redo A;
3219    }    }
3220  } # _tokenize_attempt_to_consume_an_entity  
3221        } else {
3222          die "$0: $self->{state}: Unknown state";
3223        }
3224      } # A  
3225    
3226      die "$0: _get_next_token: unexpected case";
3227    } # _get_next_token
3228    
3229  sub _initialize_tree_constructor ($) {  sub _initialize_tree_constructor ($) {
3230    my $self = shift;    my $self = shift;
# Line 2836  sub _initialize_tree_constructor ($) { Line 3233  sub _initialize_tree_constructor ($) {
3233    ## TODO: Turn mutation events off # MUST    ## TODO: Turn mutation events off # MUST
3234    ## TODO: Turn loose Document option (manakai extension) on    ## TODO: Turn loose Document option (manakai extension) on
3235    $self->{document}->manakai_is_html (1); # MUST    $self->{document}->manakai_is_html (1); # MUST
3236      $self->{document}->set_user_data (manakai_source_line => 1);
3237      $self->{document}->set_user_data (manakai_source_column => 1);
3238  } # _initialize_tree_constructor  } # _initialize_tree_constructor
3239    
3240  sub _terminate_tree_constructor ($) {  sub _terminate_tree_constructor ($) {
# Line 2890  sub _tree_construction_initial ($) { Line 3289  sub _tree_construction_initial ($) {
3289        ## language.        ## language.
3290        my $doctype_name = $token->{name};        my $doctype_name = $token->{name};
3291        $doctype_name = '' unless defined $doctype_name;        $doctype_name = '' unless defined $doctype_name;
3292        $doctype_name =~ tr/a-z/A-Z/;        $doctype_name =~ tr/a-z/A-Z/; # ASCII case-insensitive
3293        if (not defined $token->{name} or # <!DOCTYPE>        if (not defined $token->{name} or # <!DOCTYPE>
           defined $token->{public_identifier} or  
3294            defined $token->{system_identifier}) {            defined $token->{system_identifier}) {
3295          !!!cp ('t1');          !!!cp ('t1');
3296          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3297        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
3298          !!!cp ('t2');          !!!cp ('t2');
         ## ISSUE: ASCII case-insensitive? (in fact it does not matter)  
3299          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3300          } elsif (defined $token->{public_identifier}) {
3301            if ($token->{public_identifier} eq 'XSLT-compat') {
3302              !!!cp ('t1.2');
3303              !!!parse-error (type => 'XSLT-compat', token => $token,
3304                              level => $self->{level}->{should});
3305            } else {
3306              !!!parse-error (type => 'not HTML5', token => $token);
3307            }
3308        } else {        } else {
3309          !!!cp ('t3');          !!!cp ('t3');
3310            #
3311        }        }
3312                
3313        my $doctype = $self->{document}->create_document_type_definition        my $doctype = $self->{document}->create_document_type_definition
# Line 2922  sub _tree_construction_initial ($) { Line 3328  sub _tree_construction_initial ($) {
3328        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{public_identifier}) {
3329          my $pubid = $token->{public_identifier};          my $pubid = $token->{public_identifier};
3330          $pubid =~ tr/a-z/A-z/;          $pubid =~ tr/a-z/A-z/;
3331          if ({          my $prefix = [
3332            "+//SILMARIL//DTD HTML PRO V0R11 19970101//EN" => 1,            "+//SILMARIL//DTD HTML PRO V0R11 19970101//",
3333            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3334            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3335            "-//IETF//DTD HTML 2.0 LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 1//",
3336            "-//IETF//DTD HTML 2.0 LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 2//",
3337            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//",
3338            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//",
3339            "-//IETF//DTD HTML 2.0 STRICT//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT//",
3340            "-//IETF//DTD HTML 2.0//EN" => 1,            "-//IETF//DTD HTML 2.0//",
3341            "-//IETF//DTD HTML 2.1E//EN" => 1,            "-//IETF//DTD HTML 2.1E//",
3342            "-//IETF//DTD HTML 3.0//EN" => 1,            "-//IETF//DTD HTML 3.0//",
3343            "-//IETF//DTD HTML 3.0//EN//" => 1,            "-//IETF//DTD HTML 3.2 FINAL//",
3344            "-//IETF//DTD HTML 3.2 FINAL//EN" => 1,            "-//IETF//DTD HTML 3.2//",
3345            "-//IETF//DTD HTML 3.2//EN" => 1,            "-//IETF//DTD HTML 3//",
3346            "-//IETF//DTD HTML 3//EN" => 1,            "-//IETF//DTD HTML LEVEL 0//",
3347            "-//IETF//DTD HTML LEVEL 0//EN" => 1,            "-//IETF//DTD HTML LEVEL 1//",
3348            "-//IETF//DTD HTML LEVEL 0//EN//2.0" => 1,            "-//IETF//DTD HTML LEVEL 2//",
3349            "-//IETF//DTD HTML LEVEL 1//EN" => 1,            "-//IETF//DTD HTML LEVEL 3//",
3350            "-//IETF//DTD HTML LEVEL 1//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 0//",
3351            "-//IETF//DTD HTML LEVEL 2//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 1//",
3352            "-//IETF//DTD HTML LEVEL 2//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 2//",
3353            "-//IETF//DTD HTML LEVEL 3//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 3//",
3354            "-//IETF//DTD HTML LEVEL 3//EN//3.0" => 1,            "-//IETF//DTD HTML STRICT//",
3355            "-//IETF//DTD HTML STRICT LEVEL 0//EN" => 1,            "-//IETF//DTD HTML//",
3356            "-//IETF//DTD HTML STRICT LEVEL 0//EN//2.0" => 1,            "-//METRIUS//DTD METRIUS PRESENTATIONAL//",
3357            "-//IETF//DTD HTML STRICT LEVEL 1//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//",
3358            "-//IETF//DTD HTML STRICT LEVEL 1//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//",
3359            "-//IETF//DTD HTML STRICT LEVEL 2//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//",
3360            "-//IETF//DTD HTML STRICT LEVEL 2//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//",
3361            "-//IETF//DTD HTML STRICT LEVEL 3//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//",
3362            "-//IETF//DTD HTML STRICT LEVEL 3//EN//3.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//",
3363            "-//IETF//DTD HTML STRICT//EN" => 1,            "-//NETSCAPE COMM. CORP.//DTD HTML//",
3364            "-//IETF//DTD HTML STRICT//EN//2.0" => 1,            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//",
3365            "-//IETF//DTD HTML STRICT//EN//3.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//",
3366            "-//IETF//DTD HTML//EN" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//",
3367            "-//IETF//DTD HTML//EN//2.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//",
3368            "-//IETF//DTD HTML//EN//3.0" => 1,            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//",
3369            "-//METRIUS//DTD METRIUS PRESENTATIONAL//EN" => 1,            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//",
3370            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//EN" => 1,            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//",
3371            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//EN" => 1,            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//",
3372            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//",
3373            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//",
3374            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//EN" => 1,            "-//W3C//DTD HTML 3 1995-03-24//",
3375            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//EN" => 1,            "-//W3C//DTD HTML 3.2 DRAFT//",
3376            "-//NETSCAPE COMM. CORP.//DTD HTML//EN" => 1,            "-//W3C//DTD HTML 3.2 FINAL//",
3377            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//EN" => 1,            "-//W3C//DTD HTML 3.2//",
3378            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//EN" => 1,            "-//W3C//DTD HTML 3.2S DRAFT//",
3379            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 FRAMESET//",
3380            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 TRANSITIONAL//",
3381            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMETNAL 19960712//",
3382            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMENTAL 970421//",
3383            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//EN" => 1,            "-//W3C//DTD W3 HTML//",
3384            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//EN" => 1,            "-//W3O//DTD W3 HTML 3.0//",
3385            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML 2.0//",
3386            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML//",
3387            "-//W3C//DTD HTML 3 1995-03-24//EN" => 1,          ]; # $prefix
3388            "-//W3C//DTD HTML 3.2 DRAFT//EN" => 1,          my $match;
3389            "-//W3C//DTD HTML 3.2 FINAL//EN" => 1,          for (@$prefix) {
3390            "-//W3C//DTD HTML 3.2//EN" => 1,            if (substr ($prefix, 0, length $_) eq $_) {
3391            "-//W3C//DTD HTML 3.2S DRAFT//EN" => 1,              $match = 1;
3392            "-//W3C//DTD HTML 4.0 FRAMESET//EN" => 1,              last;
3393            "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN" => 1,            }
3394            "-//W3C//DTD HTML EXPERIMETNAL 19960712//EN" => 1,          }
3395            "-//W3C//DTD HTML EXPERIMENTAL 970421//EN" => 1,          if ($match or
3396            "-//W3C//DTD W3 HTML//EN" => 1,              $pubid eq "-//W3O//DTD W3 HTML STRICT 3.0//EN//" or
3397            "-//W3O//DTD W3 HTML 3.0//EN" => 1,              $pubid eq "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" or
3398            "-//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}) {  
3399            !!!cp ('t5');            !!!cp ('t5');
3400            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3401          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD HTML 4.01 FRAMESET//] or
3402                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD HTML 4.01 TRANSITIONAL//]) {
3403            if (defined $token->{system_identifier}) {            if (defined $token->{system_identifier}) {
3404              !!!cp ('t6');              !!!cp ('t6');
3405              $self->{document}->manakai_compat_mode ('quirks');              $self->{document}->manakai_compat_mode ('quirks');
# Line 3007  sub _tree_construction_initial ($) { Line 3407  sub _tree_construction_initial ($) {
3407              !!!cp ('t7');              !!!cp ('t7');
3408              $self->{document}->manakai_compat_mode ('limited quirks');              $self->{document}->manakai_compat_mode ('limited quirks');
3409            }            }
3410          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD XHTML 1.0 FRAMESET//] or
3411                   $pubid eq "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD XHTML 1.0 TRANSITIONAL//]) {
3412            !!!cp ('t8');            !!!cp ('t8');
3413            $self->{document}->manakai_compat_mode ('limited quirks');            $self->{document}->manakai_compat_mode ('limited quirks');
3414          } else {          } else {
# Line 3021  sub _tree_construction_initial ($) { Line 3421  sub _tree_construction_initial ($) {
3421          my $sysid = $token->{system_identifier};          my $sysid = $token->{system_identifier};
3422          $sysid =~ tr/A-Z/a-z/;          $sysid =~ tr/A-Z/a-z/;
3423          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") {
3424            ## TODO: Check the spec: PUBLIC "(limited quirks)" "(quirks)"            ## NOTE: Ensure that |PUBLIC "(limited quirks)" "(quirks)"| is
3425              ## marked as quirks.
3426            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3427            !!!cp ('t11');            !!!cp ('t11');
3428          } else {          } else {
# Line 3193  sub _reset_insertion_mode ($) { Line 3594  sub _reset_insertion_mode ($) {
3594        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
3595          $last = 1;          $last = 1;
3596          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
3597            if ($self->{inner_html_node}->[1] & TABLE_CELL_EL) {            !!!cp ('t28');
3598              !!!cp ('t27');            $node = $self->{inner_html_node};
3599              #          } else {
3600            } else {            die "_reset_insertion_mode: t27";
             !!!cp ('t28');  
             $node = $self->{inner_html_node};  
           }  
3601          }          }
3602        }        }
3603              
3604      ## Step 4..14        ## Step 4..14
3605      my $new_mode;        my $new_mode;
3606      if ($node->[1] & FOREIGN_EL) {        if ($node->[1] & FOREIGN_EL) {
3607        ## NOTE: Strictly spaking, the line below only applies to MathML and          !!!cp ('t28.1');
3608        ## SVG elements.  Currently the HTML syntax supports only MathML and          ## NOTE: Strictly spaking, the line below only applies to MathML and
3609        ## SVG elements as foreigners.          ## SVG elements.  Currently the HTML syntax supports only MathML and
3610        $new_mode = $self->{insertion_mode} | IN_FOREIGN_CONTENT_IM;          ## SVG elements as foreigners.
3611        ## ISSUE: What is set as the secondary insertion mode?          $new_mode = IN_BODY_IM | IN_FOREIGN_CONTENT_IM;
3612      } else {        } elsif ($node->[1] & TABLE_CELL_EL) {
3613        $new_mode = {          if ($last) {
3614              !!!cp ('t28.2');
3615              #
3616            } else {
3617              !!!cp ('t28.3');
3618              $new_mode = IN_CELL_IM;
3619            }
3620          } else {
3621            !!!cp ('t28.4');
3622            $new_mode = {
3623                        select => IN_SELECT_IM,                        select => IN_SELECT_IM,
3624                        ## NOTE: |option| and |optgroup| do not set                        ## NOTE: |option| and |optgroup| do not set
3625                        ## insertion mode to "in select" by themselves.                        ## insertion mode to "in select" by themselves.
                       td => IN_CELL_IM,  
                       th => IN_CELL_IM,  
3626                        tr => IN_ROW_IM,                        tr => IN_ROW_IM,
3627                        tbody => IN_TABLE_BODY_IM,                        tbody => IN_TABLE_BODY_IM,
3628                        thead => IN_TABLE_BODY_IM,                        thead => IN_TABLE_BODY_IM,
# Line 3229  sub _reset_insertion_mode ($) { Line 3634  sub _reset_insertion_mode ($) {
3634                        body => IN_BODY_IM,                        body => IN_BODY_IM,
3635                        frameset => IN_FRAMESET_IM,                        frameset => IN_FRAMESET_IM,
3636                       }->{$node->[0]->manakai_local_name};                       }->{$node->[0]->manakai_local_name};
3637      }        }
3638      $self->{insertion_mode} = $new_mode and return if defined $new_mode;        $self->{insertion_mode} = $new_mode and return if defined $new_mode;
3639                
3640        ## Step 15        ## Step 15
3641        if ($node->[1] & HTML_EL) {        if ($node->[1] & HTML_EL) {
# Line 3404  sub _tree_construction_main ($) { Line 3809  sub _tree_construction_main ($) {
3809        ## NOTE: An end-of-file token.        ## NOTE: An end-of-file token.
3810        if ($content_model_flag == CDATA_CONTENT_MODEL) {        if ($content_model_flag == CDATA_CONTENT_MODEL) {
3811          !!!cp ('t43');          !!!cp ('t43');
3812          !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in CDATA:#eof', token => $token);
3813        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
3814          !!!cp ('t44');          !!!cp ('t44');
3815          !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in RCDATA:#eof', token => $token);
3816        } else {        } else {
3817          die "$0: $content_model_flag in parse_rcdata";          die "$0: $content_model_flag in parse_rcdata";
3818        }        }
# Line 3444  sub _tree_construction_main ($) { Line 3849  sub _tree_construction_main ($) {
3849        ## Ignore the token        ## Ignore the token
3850      } else {      } else {
3851        !!!cp ('t48');        !!!cp ('t48');
3852        !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);        !!!parse-error (type => 'in CDATA:#eof', token => $token);
3853        ## ISSUE: And ignore?        ## ISSUE: And ignore?
3854        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
3855      }      }
# Line 3495  sub _tree_construction_main ($) { Line 3900  sub _tree_construction_main ($) {
3900        } # AFE        } # AFE
3901        unless (defined $formatting_element) {        unless (defined $formatting_element) {
3902          !!!cp ('t53');          !!!cp ('t53');
3903          !!!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);
3904          ## Ignore the token          ## Ignore the token
3905          !!!next-token;          !!!next-token;
3906          return;          return;
# Line 3512  sub _tree_construction_main ($) { Line 3917  sub _tree_construction_main ($) {
3917              last INSCOPE;              last INSCOPE;
3918            } else { # in open elements but not in scope            } else { # in open elements but not in scope
3919              !!!cp ('t55');              !!!cp ('t55');
3920              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},              !!!parse-error (type => 'unmatched end tag',
3921                                text => $token->{tag_name},
3922                              token => $end_tag_token);                              token => $end_tag_token);
3923              ## Ignore the token              ## Ignore the token
3924              !!!next-token;              !!!next-token;
# Line 3525  sub _tree_construction_main ($) { Line 3931  sub _tree_construction_main ($) {
3931        } # INSCOPE        } # INSCOPE
3932        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
3933          !!!cp ('t57');          !!!cp ('t57');
3934          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},          !!!parse-error (type => 'unmatched end tag',
3935                            text => $token->{tag_name},
3936                          token => $end_tag_token);                          token => $end_tag_token);
3937          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
3938          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
# Line 3534  sub _tree_construction_main ($) { Line 3941  sub _tree_construction_main ($) {
3941        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
3942          !!!cp ('t58');          !!!cp ('t58');
3943          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
3944                          value => $self->{open_elements}->[-1]->[0]                          text => $self->{open_elements}->[-1]->[0]
3945                              ->manakai_local_name,                              ->manakai_local_name,
3946                          token => $end_tag_token);                          token => $end_tag_token);
3947        }        }
# Line 3743  sub _tree_construction_main ($) { Line 4150  sub _tree_construction_main ($) {
4150    B: while (1) {    B: while (1) {
4151      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
4152        !!!cp ('t73');        !!!cp ('t73');
4153        !!!parse-error (type => 'DOCTYPE in the middle', token => $token);        !!!parse-error (type => 'in html:#DOCTYPE', token => $token);
4154        ## Ignore the token        ## Ignore the token
4155        ## Stay in the phase        ## Stay in the phase
4156        !!!next-token;        !!!next-token;
# Line 3752  sub _tree_construction_main ($) { Line 4159  sub _tree_construction_main ($) {
4159               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
4160        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
4161          !!!cp ('t79');          !!!cp ('t79');
4162          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4163          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
4164        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
4165          !!!cp ('t80');          !!!cp ('t80');
4166          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4167          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
4168        } else {        } else {
4169          !!!cp ('t81');          !!!cp ('t81');
# Line 3807  sub _tree_construction_main ($) { Line 4214  sub _tree_construction_main ($) {
4214            #            #
4215          } elsif ({          } elsif ({
4216                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,
4217                    center => 1, code => 1, dd => 1, div => 1, dl => 1, em => 1,                    center => 1, code => 1, dd => 1, div => 1, dl => 1, dt => 1,
4218                    embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1, ## No h4!                    em => 1, embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1,
4219                    h5 => 1, h6 => 1, head => 1, hr => 1, i => 1, img => 1,                    h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, i => 1,
4220                    li => 1, menu => 1, meta => 1, nobr => 1, p => 1, pre => 1,                    img => 1, li => 1, listing => 1, menu => 1, meta => 1,
4221                    ruby => 1, s => 1, small => 1, span => 1, strong => 1,                    nobr => 1, ol => 1, p => 1, pre => 1, ruby => 1, s => 1,
4222                    sub => 1, sup => 1, table => 1, tt => 1, u => 1, ul => 1,                    small => 1, span => 1, strong => 1, strike => 1, sub => 1,
4223                    var => 1,                    sup => 1, table => 1, tt => 1, u => 1, ul => 1, var => 1,
4224                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
4225            !!!cp ('t87.2');            !!!cp ('t87.2');
4226            !!!parse-error (type => 'not closed',            !!!parse-error (type => 'not closed',
4227                            value => $self->{open_elements}->[-1]->[0]                            text => $self->{open_elements}->[-1]->[0]
4228                                ->manakai_local_name,                                ->manakai_local_name,
4229                            token => $token);                            token => $token);
4230    
# Line 3893  sub _tree_construction_main ($) { Line 4300  sub _tree_construction_main ($) {
4300          !!!cp ('t87.5');          !!!cp ('t87.5');
4301          #          #
4302        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
         ## NOTE: "using the rules for secondary insertion mode" then "continue"  
4303          !!!cp ('t87.6');          !!!cp ('t87.6');
4304          #          !!!parse-error (type => 'not closed',
4305          ## TODO: ...                          text => $self->{open_elements}->[-1]->[0]
4306                                ->manakai_local_name,
4307                            token => $token);
4308    
4309            pop @{$self->{open_elements}}
4310                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;
4311    
4312            $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
4313            ## Reprocess.
4314            next B;
4315        } else {        } else {
4316          die "$0: $token->{type}: Unknown token type";                  die "$0: $token->{type}: Unknown token type";        
4317        }        }
# Line 3937  sub _tree_construction_main ($) { Line 4352  sub _tree_construction_main ($) {
4352            !!!cp ('t90');            !!!cp ('t90');
4353            ## As if </noscript>            ## As if </noscript>
4354            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
4355            !!!parse-error (type => 'in noscript:#character', token => $token);            !!!parse-error (type => 'in noscript:#text', token => $token);
4356                        
4357            ## Reprocess in the "in head" insertion mode...            ## Reprocess in the "in head" insertion mode...
4358            ## As if </head>            ## As if </head>
# Line 3973  sub _tree_construction_main ($) { Line 4388  sub _tree_construction_main ($) {
4388              !!!next-token;              !!!next-token;
4389              next B;              next B;
4390            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4391              !!!cp ('t94');              !!!cp ('t93.2');
4392              #              !!!parse-error (type => 'after head', text => 'head',
4393                                token => $token);
4394                ## Ignore the token
4395                !!!nack ('t93.3');
4396                !!!next-token;
4397                next B;
4398            } else {            } else {
4399              !!!cp ('t95');              !!!cp ('t95');
4400              !!!parse-error (type => 'in head:head', token => $token); # or in head noscript              !!!parse-error (type => 'in head:head',
4401                                token => $token); # or in head noscript
4402              ## Ignore the token              ## Ignore the token
4403              !!!nack ('t95.1');              !!!nack ('t95.1');
4404              !!!next-token;              !!!next-token;
# Line 4002  sub _tree_construction_main ($) { Line 4423  sub _tree_construction_main ($) {
4423                  !!!cp ('t98');                  !!!cp ('t98');
4424                  ## As if </noscript>                  ## As if </noscript>
4425                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4426                  !!!parse-error (type => 'in noscript:base', token => $token);                  !!!parse-error (type => 'in noscript', text => 'base',
4427                                    token => $token);
4428                                
4429                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4430                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
# Line 4013  sub _tree_construction_main ($) { Line 4435  sub _tree_construction_main ($) {
4435                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4436                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4437                  !!!cp ('t100');                  !!!cp ('t100');
4438                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4439                                    text => $token->{tag_name}, token => $token);
4440                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4441                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4442                } else {                } else {
# Line 4030  sub _tree_construction_main ($) { Line 4453  sub _tree_construction_main ($) {
4453                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4454                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4455                  !!!cp ('t102');                  !!!cp ('t102');
4456                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4457                                    text => $token->{tag_name}, token => $token);
4458                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4459                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4460                } else {                } else {
# Line 4047  sub _tree_construction_main ($) { Line 4471  sub _tree_construction_main ($) {
4471                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4472                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4473                  !!!cp ('t104');                  !!!cp ('t104');
4474                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4475                                    text => $token->{tag_name}, token => $token);
4476                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4477                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4478                } else {                } else {
# Line 4057  sub _tree_construction_main ($) { Line 4482  sub _tree_construction_main ($) {
4482                my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
4483    
4484                unless ($self->{confident}) {                unless ($self->{confident}) {
4485                  if ($token->{attributes}->{charset}) { ## TODO: And if supported                  if ($token->{attributes}->{charset}) {
4486                    !!!cp ('t106');                    !!!cp ('t106');
4487                      ## NOTE: Whether the encoding is supported or not is handled
4488                      ## in the {change_encoding} callback.
4489                    $self->{change_encoding}                    $self->{change_encoding}
4490                        ->($self, $token->{attributes}->{charset}->{value},                        ->($self, $token->{attributes}->{charset}->{value},
4491                           $token);                           $token);
# Line 4068  sub _tree_construction_main ($) { Line 4495  sub _tree_construction_main ($) {
4495                                             $token->{attributes}->{charset}                                             $token->{attributes}->{charset}
4496                                                 ->{has_reference});                                                 ->{has_reference});
4497                  } elsif ($token->{attributes}->{content}) {                  } elsif ($token->{attributes}->{content}) {
                   ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.  
4498                    if ($token->{attributes}->{content}->{value}                    if ($token->{attributes}->{content}->{value}
4499                        =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                        =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
4500                            [\x09-\x0D\x20]*=                            [\x09-\x0D\x20]*=
4501                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
4502                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
4503                      !!!cp ('t107');                      !!!cp ('t107');
4504                        ## NOTE: Whether the encoding is supported or not is handled
4505                        ## in the {change_encoding} callback.
4506                      $self->{change_encoding}                      $self->{change_encoding}
4507                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3,                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3,
4508                             $token);                             $token);
# Line 4113  sub _tree_construction_main ($) { Line 4541  sub _tree_construction_main ($) {
4541                  !!!cp ('t111');                  !!!cp ('t111');
4542                  ## As if </noscript>                  ## As if </noscript>
4543                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4544                  !!!parse-error (type => 'in noscript:title', token => $token);                  !!!parse-error (type => 'in noscript', text => 'title',
4545                                    token => $token);
4546                                
4547                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4548                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4549                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4550                  !!!cp ('t112');                  !!!cp ('t112');
4551                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4552                                    text => $token->{tag_name}, token => $token);
4553                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4554                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4555                } else {                } else {
# Line 4133  sub _tree_construction_main ($) { Line 4563  sub _tree_construction_main ($) {
4563                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4564                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4565                next B;                next B;
4566              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style' or
4567                         $token->{tag_name} eq 'noframes') {
4568                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and
4569                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
4570                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4571                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4572                  !!!cp ('t114');                  !!!cp ('t114');
4573                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4574                                    text => $token->{tag_name}, token => $token);
4575                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4576                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4577                } else {                } else {
# Line 4160  sub _tree_construction_main ($) { Line 4592  sub _tree_construction_main ($) {
4592                  next B;                  next B;
4593                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4594                  !!!cp ('t117');                  !!!cp ('t117');
4595                  !!!parse-error (type => 'in noscript:noscript', token => $token);                  !!!parse-error (type => 'in noscript', text => 'noscript',
4596                                    token => $token);
4597                  ## Ignore the token                  ## Ignore the token
4598                  !!!nack ('t117.1');                  !!!nack ('t117.1');
4599                  !!!next-token;                  !!!next-token;
# Line 4174  sub _tree_construction_main ($) { Line 4607  sub _tree_construction_main ($) {
4607                  !!!cp ('t119');                  !!!cp ('t119');
4608                  ## As if </noscript>                  ## As if </noscript>
4609                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4610                  !!!parse-error (type => 'in noscript:script', token => $token);                  !!!parse-error (type => 'in noscript', text => 'script',
4611                                    token => $token);
4612                                
4613                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4614                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4615                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4616                  !!!cp ('t120');                  !!!cp ('t120');
4617                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4618                                    text => $token->{tag_name}, token => $token);
4619                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4620                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4621                } else {                } else {
# Line 4198  sub _tree_construction_main ($) { Line 4633  sub _tree_construction_main ($) {
4633                  !!!cp ('t122');                  !!!cp ('t122');
4634                  ## As if </noscript>                  ## As if </noscript>
4635                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4636                  !!!parse-error (type => 'in noscript:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in noscript',
4637                                    text => $token->{tag_name}, token => $token);
4638                                    
4639                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4640                  ## As if </head>                  ## As if </head>
# Line 4237  sub _tree_construction_main ($) { Line 4673  sub _tree_construction_main ($) {
4673                !!!cp ('t129');                !!!cp ('t129');
4674                ## As if </noscript>                ## As if </noscript>
4675                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4676                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4677                                  text => $token->{tag_name}, token => $token);
4678                                
4679                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4680                ## As if </head>                ## As if </head>
# Line 4280  sub _tree_construction_main ($) { Line 4717  sub _tree_construction_main ($) {
4717                  !!!cp ('t133');                  !!!cp ('t133');
4718                  ## As if </noscript>                  ## As if </noscript>
4719                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4720                  !!!parse-error (type => 'in noscript:/head', token => $token);                  !!!parse-error (type => 'in noscript:/',
4721                                    text => 'head', token => $token);
4722                                    
4723                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4724                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 4293  sub _tree_construction_main ($) { Line 4731  sub _tree_construction_main ($) {
4731                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
4732                  !!!next-token;                  !!!next-token;
4733                  next B;                  next B;
4734                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4735                    !!!cp ('t134.1');
4736                    !!!parse-error (type => 'unmatched end tag', text => 'head',
4737                                    token => $token);
4738                    ## Ignore the token
4739                    !!!next-token;
4740                    next B;
4741                } else {                } else {
4742                  !!!cp ('t135');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
                 #  
4743                }                }
4744              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
4745                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
# Line 4304  sub _tree_construction_main ($) { Line 4748  sub _tree_construction_main ($) {
4748                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4749                  !!!next-token;                  !!!next-token;
4750                  next B;                  next B;
4751                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or
4752                           $self->{insertion_mode} == AFTER_HEAD_IM) {
4753                  !!!cp ('t137');                  !!!cp ('t137');
4754                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4755                                    text => 'noscript', token => $token);
4756                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
4757                  !!!next-token;                  !!!next-token;
4758                  next B;                  next B;
# Line 4317  sub _tree_construction_main ($) { Line 4763  sub _tree_construction_main ($) {
4763              } elsif ({              } elsif ({
4764                        body => 1, html => 1,                        body => 1, html => 1,
4765                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4766                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM or
4767                  !!!cp ('t139');                    $self->{insertion_mode} == IN_HEAD_IM or
4768                  ## 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) {  
4769                  !!!cp ('t140');                  !!!cp ('t140');
4770                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4771                                    text => $token->{tag_name}, token => $token);
4772                    ## Ignore the token
4773                    !!!next-token;
4774                    next B;
4775                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4776                    !!!cp ('t140.1');
4777                    !!!parse-error (type => 'unmatched end tag',
4778                                    text => $token->{tag_name}, token => $token);
4779                  ## Ignore the token                  ## Ignore the token
4780                  !!!next-token;                  !!!next-token;
4781                  next B;                  next B;
4782                } else {                } else {
4783                  !!!cp ('t141');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
4784                }                }
4785                              } elsif ($token->{tag_name} eq 'p') {
4786                #                !!!cp ('t142');
4787              } elsif ({                !!!parse-error (type => 'unmatched end tag',
4788                        p => 1, br => 1,                                text => $token->{tag_name}, token => $token);
4789                       }->{$token->{tag_name}}) {                ## Ignore the token
4790                  !!!next-token;
4791                  next B;
4792                } elsif ($token->{tag_name} eq 'br') {
4793                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4794                  !!!cp ('t142');                  !!!cp ('t142.2');
4795                  ## As if <head>                  ## (before head) as if <head>, (in head) as if </head>
4796                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
4797                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
4798                  push @{$self->{open_elements}},                  $self->{insertion_mode} = AFTER_HEAD_IM;
4799                      [$self->{head_element}, $el_category->{head}];    
4800                    ## Reprocess in the "after head" insertion mode...
4801                  } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
4802                    !!!cp ('t143.2');
4803                    ## As if </head>
4804                    pop @{$self->{open_elements}};
4805                    $self->{insertion_mode} = AFTER_HEAD_IM;
4806      
4807                    ## Reprocess in the "after head" insertion mode...
4808                  } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4809                    !!!cp ('t143.3');
4810                    ## ISSUE: Two parse errors for <head><noscript></br>
4811                    !!!parse-error (type => 'unmatched end tag',
4812                                    text => 'br', token => $token);
4813                    ## As if </noscript>
4814                    pop @{$self->{open_elements}};
4815                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4816    
4817                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4818                } else {                  ## As if </head>
4819                  !!!cp ('t143');                  pop @{$self->{open_elements}};
4820                }                  $self->{insertion_mode} = AFTER_HEAD_IM;
4821    
4822                #                  ## Reprocess in the "after head" insertion mode...
4823              } else {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4824                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                  !!!cp ('t143.4');
                 !!!cp ('t144');  
4825                  #                  #
4826                } else {                } else {
4827                  !!!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;  
4828                }                }
4829    
4830                  ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.
4831                  !!!parse-error (type => 'unmatched end tag',
4832                                  text => 'br', token => $token);
4833                  ## Ignore the token
4834                  !!!next-token;
4835                  next B;
4836                } else {
4837                  !!!cp ('t145');
4838                  !!!parse-error (type => 'unmatched end tag',
4839                                  text => $token->{tag_name}, token => $token);
4840                  ## Ignore the token
4841                  !!!next-token;
4842                  next B;
4843              }              }
4844    
4845              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4846                !!!cp ('t146');                !!!cp ('t146');
4847                ## As if </noscript>                ## As if </noscript>
4848                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4849                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4850                                  text => $token->{tag_name}, token => $token);
4851                                
4852                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4853                ## As if </head>                ## As if </head>
# Line 4389  sub _tree_construction_main ($) { Line 4863  sub _tree_construction_main ($) {
4863              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4864  ## ISSUE: This case cannot be reached?  ## ISSUE: This case cannot be reached?
4865                !!!cp ('t148');                !!!cp ('t148');
4866                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
4867                                  text => $token->{tag_name}, 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 4500  sub _tree_construction_main ($) { Line 4975  sub _tree_construction_main ($) {
4975    
4976                  !!!cp ('t153');                  !!!cp ('t153');
4977                  !!!parse-error (type => 'start tag not allowed',                  !!!parse-error (type => 'start tag not allowed',
4978                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
4979                  ## Ignore the token                  ## Ignore the token
4980                  !!!nack ('t153.1');                  !!!nack ('t153.1');
4981                  !!!next-token;                  !!!next-token;
4982                  next B;                  next B;
4983                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4984                  !!!parse-error (type => 'not closed:caption', token => $token);                  !!!parse-error (type => 'not closed', text => 'caption',
4985                                    token => $token);
4986                                    
4987                  ## NOTE: As if </caption>.                  ## NOTE: As if </caption>.
4988                  ## have a table element in table scope                  ## have a table element in table scope
# Line 4526  sub _tree_construction_main ($) { Line 5002  sub _tree_construction_main ($) {
5002    
5003                    !!!cp ('t157');                    !!!cp ('t157');
5004                    !!!parse-error (type => 'start tag not allowed',                    !!!parse-error (type => 'start tag not allowed',
5005                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
5006                    ## Ignore the token                    ## Ignore the token
5007                    !!!nack ('t157.1');                    !!!nack ('t157.1');
5008                    !!!next-token;                    !!!next-token;
# Line 4543  sub _tree_construction_main ($) { Line 5019  sub _tree_construction_main ($) {
5019                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5020                    !!!cp ('t159');                    !!!cp ('t159');
5021                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5022                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5023                                        ->manakai_local_name,                                        ->manakai_local_name,
5024                                    token => $token);                                    token => $token);
5025                  } else {                  } else {
# Line 4585  sub _tree_construction_main ($) { Line 5061  sub _tree_construction_main ($) {
5061                  } # INSCOPE                  } # INSCOPE
5062                    unless (defined $i) {                    unless (defined $i) {
5063                      !!!cp ('t165');                      !!!cp ('t165');
5064                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5065                                        text => $token->{tag_name},
5066                                        token => $token);
5067                      ## Ignore the token                      ## Ignore the token
5068                      !!!next-token;                      !!!next-token;
5069                      next B;                      next B;
# Line 4602  sub _tree_construction_main ($) { Line 5080  sub _tree_construction_main ($) {
5080                          ne $token->{tag_name}) {                          ne $token->{tag_name}) {
5081                    !!!cp ('t167');                    !!!cp ('t167');
5082                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5083                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5084                                        ->manakai_local_name,                                        ->manakai_local_name,
5085                                    token => $token);                                    token => $token);
5086                  } else {                  } else {
# Line 4619  sub _tree_construction_main ($) { Line 5097  sub _tree_construction_main ($) {
5097                  next B;                  next B;
5098                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
5099                  !!!cp ('t169');                  !!!cp ('t169');
5100                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5101                                    text => $token->{tag_name}, token => $token);
5102                  ## Ignore the token                  ## Ignore the token
5103                  !!!next-token;                  !!!next-token;
5104                  next B;                  next B;
# Line 4646  sub _tree_construction_main ($) { Line 5125  sub _tree_construction_main ($) {
5125    
5126                    !!!cp ('t173');                    !!!cp ('t173');
5127                    !!!parse-error (type => 'unmatched end tag',                    !!!parse-error (type => 'unmatched end tag',
5128                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
5129                    ## Ignore the token                    ## Ignore the token
5130                    !!!next-token;                    !!!next-token;
5131                    next B;                    next B;
# Line 4662  sub _tree_construction_main ($) { Line 5141  sub _tree_construction_main ($) {
5141                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5142                    !!!cp ('t175');                    !!!cp ('t175');
5143                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5144                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5145                                        ->manakai_local_name,                                        ->manakai_local_name,
5146                                    token => $token);                                    token => $token);
5147                  } else {                  } else {
# Line 4679  sub _tree_construction_main ($) { Line 5158  sub _tree_construction_main ($) {
5158                  next B;                  next B;
5159                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
5160                  !!!cp ('t177');                  !!!cp ('t177');
5161                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5162                                    text => $token->{tag_name}, token => $token);
5163                  ## Ignore the token                  ## Ignore the token
5164                  !!!next-token;                  !!!next-token;
5165                  next B;                  next B;
# Line 4722  sub _tree_construction_main ($) { Line 5202  sub _tree_construction_main ($) {
5202    
5203                  !!!cp ('t182');                  !!!cp ('t182');
5204                  !!!parse-error (type => 'unmatched end tag',                  !!!parse-error (type => 'unmatched end tag',
5205                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
5206                  ## Ignore the token                  ## Ignore the token
5207                  !!!next-token;                  !!!next-token;
5208                  next B;                  next B;
5209                } # INSCOPE                } # INSCOPE
5210              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
5211                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5212                !!!parse-error (type => 'not closed:caption', token => $token);                !!!parse-error (type => 'not closed', text => 'caption',
5213                                  token => $token);
5214    
5215                ## As if </caption>                ## As if </caption>
5216                ## have a table element in table scope                ## have a table element in table scope
# Line 4747  sub _tree_construction_main ($) { Line 5228  sub _tree_construction_main ($) {
5228                } # INSCOPE                } # INSCOPE
5229                unless (defined $i) {                unless (defined $i) {
5230                  !!!cp ('t186');                  !!!cp ('t186');
5231                  !!!parse-error (type => 'unmatched end tag:caption', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5232                                    text => 'caption', token => $token);
5233                  ## Ignore the token                  ## Ignore the token
5234                  !!!next-token;                  !!!next-token;
5235                  next B;                  next B;
# Line 4762  sub _tree_construction_main ($) { Line 5244  sub _tree_construction_main ($) {
5244                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5245                  !!!cp ('t188');                  !!!cp ('t188');
5246                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5247                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5248                                      ->manakai_local_name,                                      ->manakai_local_name,
5249                                  token => $token);                                  token => $token);
5250                } else {                } else {
# Line 4782  sub _tree_construction_main ($) { Line 5264  sub _tree_construction_main ($) {
5264                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5265                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
5266                  !!!cp ('t190');                  !!!cp ('t190');
5267                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5268                                    text => $token->{tag_name}, token => $token);
5269                  ## Ignore the token                  ## Ignore the token
5270                  !!!next-token;                  !!!next-token;
5271                  next B;                  next B;
# Line 4796  sub _tree_construction_main ($) { Line 5279  sub _tree_construction_main ($) {
5279                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
5280                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5281                !!!cp ('t192');                !!!cp ('t192');
5282                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
5283                                  text => $token->{tag_name}, token => $token);
5284                ## Ignore the token                ## Ignore the token
5285                !!!next-token;                !!!next-token;
5286                next B;                next B;
# Line 4836  sub _tree_construction_main ($) { Line 5320  sub _tree_construction_main ($) {
5320            }            }
5321          }          }
5322    
5323              !!!parse-error (type => 'in table:#character', token => $token);          !!!parse-error (type => 'in table:#text', token => $token);
5324    
5325              ## As if in body, but insert into foster parent element              ## As if in body, but insert into foster parent element
5326              ## ISSUE: Spec says that "whenever a node would be inserted              ## ISSUE: Spec says that "whenever a node would be inserted
# Line 4887  sub _tree_construction_main ($) { Line 5371  sub _tree_construction_main ($) {
5371          !!!next-token;          !!!next-token;
5372          next B;          next B;
5373        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5374              if ({          if ({
5375                   tr => ($self->{insertion_mode} != IN_ROW_IM),               tr => ($self->{insertion_mode} != IN_ROW_IM),
5376                   th => 1, td => 1,               th => 1, td => 1,
5377                  }->{$token->{tag_name}}) {              }->{$token->{tag_name}}) {
5378                if ($self->{insertion_mode} == IN_TABLE_IM) {            if ($self->{insertion_mode} == IN_TABLE_IM) {
5379                  ## Clear back to table context              ## Clear back to table context
5380                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5381                                  & TABLE_SCOPING_EL)) {                              & TABLE_SCOPING_EL)) {
5382                    !!!cp ('t201');                !!!cp ('t201');
5383                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5384                  }              }
5385                                
5386                  !!!insert-element ('tbody',, $token);              !!!insert-element ('tbody',, $token);
5387                  $self->{insertion_mode} = IN_TABLE_BODY_IM;              $self->{insertion_mode} = IN_TABLE_BODY_IM;
5388                  ## reprocess in the "in table body" insertion mode...              ## reprocess in the "in table body" insertion mode...
5389                }            }
5390              
5391                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {            if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
5392                  unless ($token->{tag_name} eq 'tr') {              unless ($token->{tag_name} eq 'tr') {
5393                    !!!cp ('t202');                !!!cp ('t202');
5394                    !!!parse-error (type => 'missing start tag:tr', token => $token);                !!!parse-error (type => 'missing start tag:tr', token => $token);
5395                  }              }
5396                                    
5397                  ## Clear back to table body context              ## Clear back to table body context
5398                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5399                                  & TABLE_ROWS_SCOPING_EL)) {                              & TABLE_ROWS_SCOPING_EL)) {
5400                    !!!cp ('t203');                !!!cp ('t203');
5401                    ## ISSUE: Can this case be reached?                ## ISSUE: Can this case be reached?
5402                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5403                  }              }
5404                                    
5405                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
5406                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
# Line 4972  sub _tree_construction_main ($) { Line 5456  sub _tree_construction_main ($) {
5456                  unless (defined $i) {                  unless (defined $i) {
5457                    !!!cp ('t210');                    !!!cp ('t210');
5458  ## TODO: This type is wrong.  ## TODO: This type is wrong.
5459                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmacthed end tag',
5460                                      text => $token->{tag_name}, token => $token);
5461                    ## Ignore the token                    ## Ignore the token
5462                    !!!nack ('t210.1');                    !!!nack ('t210.1');
5463                    !!!next-token;                    !!!next-token;
# Line 5016  sub _tree_construction_main ($) { Line 5501  sub _tree_construction_main ($) {
5501                  } # INSCOPE                  } # INSCOPE
5502                  unless (defined $i) {                  unless (defined $i) {
5503                    !!!cp ('t216');                    !!!cp ('t216');
5504  ## TODO: This erorr type ios wrong.  ## TODO: This erorr type is wrong.
5505                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5506                                      text => $token->{tag_name}, token => $token);
5507                    ## Ignore the token                    ## Ignore the token
5508                    !!!nack ('t216.1');                    !!!nack ('t216.1');
5509                    !!!next-token;                    !!!next-token;
# Line 5092  sub _tree_construction_main ($) { Line 5578  sub _tree_construction_main ($) {
5578                }                }
5579              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
5580                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
5581                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
5582                                    ->manakai_local_name,                                    ->manakai_local_name,
5583                                token => $token);                                token => $token);
5584    
# Line 5113  sub _tree_construction_main ($) { Line 5599  sub _tree_construction_main ($) {
5599                unless (defined $i) {                unless (defined $i) {
5600                  !!!cp ('t223');                  !!!cp ('t223');
5601  ## TODO: The following is wrong, maybe.  ## TODO: The following is wrong, maybe.
5602                  !!!parse-error (type => 'unmatched end tag:table', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'table',
5603                                    token => $token);
5604                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
5605                  !!!nack ('t223.1');                  !!!nack ('t223.1');
5606                  !!!next-token;                  !!!next-token;
5607                  next B;                  next B;
5608                }                }
5609                                
5610  ## TODO: Followings are removed from the latest spec.  ## TODO: Followings are removed from the latest spec.
5611                ## generate implied end tags                ## generate implied end tags
5612                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
5613                  !!!cp ('t224');                  !!!cp ('t224');
# Line 5131  sub _tree_construction_main ($) { Line 5618  sub _tree_construction_main ($) {
5618                  !!!cp ('t225');                  !!!cp ('t225');
5619                  ## NOTE: |<table><tr><table>|                  ## NOTE: |<table><tr><table>|
5620                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5621                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5622                                      ->manakai_local_name,                                      ->manakai_local_name,
5623                                  token => $token);                                  token => $token);
5624                } else {                } else {
# Line 5172  sub _tree_construction_main ($) { Line 5659  sub _tree_construction_main ($) {
5659                my $type = lc $token->{attributes}->{type}->{value};                my $type = lc $token->{attributes}->{type}->{value};
5660                if ($type eq 'hidden') {                if ($type eq 'hidden') {
5661                  !!!cp ('t227.3');                  !!!cp ('t227.3');
5662                  !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in table',
5663                                    text => $token->{tag_name}, token => $token);
5664    
5665                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5666    
# Line 5200  sub _tree_construction_main ($) { Line 5688  sub _tree_construction_main ($) {
5688            #            #
5689          }          }
5690    
5691          !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in table', text => $token->{tag_name},
5692                            token => $token);
5693    
5694          $insert = $insert_to_foster;          $insert = $insert_to_foster;
5695          #          #
# Line 5222  sub _tree_construction_main ($) { Line 5711  sub _tree_construction_main ($) {
5711                } # INSCOPE                } # INSCOPE
5712                unless (defined $i) {                unless (defined $i) {
5713                  !!!cp ('t230');                  !!!cp ('t230');
5714                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5715                                    text => $token->{tag_name}, token => $token);
5716                  ## Ignore the token                  ## Ignore the token
5717                  !!!nack ('t230.1');                  !!!nack ('t230.1');
5718                  !!!next-token;                  !!!next-token;
# Line 5263  sub _tree_construction_main ($) { Line 5753  sub _tree_construction_main ($) {
5753                  unless (defined $i) {                  unless (defined $i) {
5754                    !!!cp ('t235');                    !!!cp ('t235');
5755  ## TODO: The following is wrong.  ## TODO: The following is wrong.
5756                    !!!parse-error (type => 'unmatched end tag:'.$token->{type}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5757                                      text => $token->{type}, token => $token);
5758                    ## Ignore the token                    ## Ignore the token
5759                    !!!nack ('t236.1');                    !!!nack ('t236.1');
5760                    !!!next-token;                    !!!next-token;
# Line 5299  sub _tree_construction_main ($) { Line 5790  sub _tree_construction_main ($) {
5790                  } # INSCOPE                  } # INSCOPE
5791                  unless (defined $i) {                  unless (defined $i) {
5792                    !!!cp ('t239');                    !!!cp ('t239');
5793                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5794                                      text => $token->{tag_name}, token => $token);
5795                    ## Ignore the token                    ## Ignore the token
5796                    !!!nack ('t239.1');                    !!!nack ('t239.1');
5797                    !!!next-token;                    !!!next-token;
# Line 5345  sub _tree_construction_main ($) { Line 5837  sub _tree_construction_main ($) {
5837                } # INSCOPE                } # INSCOPE
5838                unless (defined $i) {                unless (defined $i) {
5839                  !!!cp ('t243');                  !!!cp ('t243');
5840                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5841                                    text => $token->{tag_name}, token => $token);
5842                  ## Ignore the token                  ## Ignore the token
5843                  !!!nack ('t243.1');                  !!!nack ('t243.1');
5844                  !!!next-token;                  !!!next-token;
# Line 5379  sub _tree_construction_main ($) { Line 5872  sub _tree_construction_main ($) {
5872                  } # INSCOPE                  } # INSCOPE
5873                    unless (defined $i) {                    unless (defined $i) {
5874                      !!!cp ('t249');                      !!!cp ('t249');
5875                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5876                                        text => $token->{tag_name}, token => $token);
5877                      ## Ignore the token                      ## Ignore the token
5878                      !!!nack ('t249.1');                      !!!nack ('t249.1');
5879                      !!!next-token;                      !!!next-token;
# Line 5402  sub _tree_construction_main ($) { Line 5896  sub _tree_construction_main ($) {
5896                  } # INSCOPE                  } # INSCOPE
5897                    unless (defined $i) {                    unless (defined $i) {
5898                      !!!cp ('t252');                      !!!cp ('t252');
5899                      !!!parse-error (type => 'unmatched end tag:tr', token => $token);                      !!!parse-error (type => 'unmatched end tag',
5900                                        text => 'tr', token => $token);
5901                      ## Ignore the token                      ## Ignore the token
5902                      !!!nack ('t252.1');                      !!!nack ('t252.1');
5903                      !!!next-token;                      !!!next-token;
# Line 5437  sub _tree_construction_main ($) { Line 5932  sub _tree_construction_main ($) {
5932                } # INSCOPE                } # INSCOPE
5933                unless (defined $i) {                unless (defined $i) {
5934                  !!!cp ('t256');                  !!!cp ('t256');
5935                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5936                                    text => $token->{tag_name}, token => $token);
5937                  ## Ignore the token                  ## Ignore the token
5938                  !!!nack ('t256.1');                  !!!nack ('t256.1');
5939                  !!!next-token;                  !!!next-token;
# Line 5464  sub _tree_construction_main ($) { Line 5960  sub _tree_construction_main ($) {
5960                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
5961                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5962            !!!cp ('t258');            !!!cp ('t258');
5963            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
5964                              text => $token->{tag_name}, token => $token);
5965            ## Ignore the token            ## Ignore the token
5966            !!!nack ('t258.1');            !!!nack ('t258.1');
5967             !!!next-token;             !!!next-token;
5968            next B;            next B;
5969          } else {          } else {
5970            !!!cp ('t259');            !!!cp ('t259');
5971            !!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in table:/',
5972                              text => $token->{tag_name}, token => $token);
5973    
5974            $insert = $insert_to_foster;            $insert = $insert_to_foster;
5975            #            #
# Line 5521  sub _tree_construction_main ($) { Line 6019  sub _tree_construction_main ($) {
6019              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
6020                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
6021                  !!!cp ('t264');                  !!!cp ('t264');
6022                  !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);                  !!!parse-error (type => 'unmatched end tag',
6023                                    text => 'colgroup', token => $token);
6024                  ## Ignore the token                  ## Ignore the token
6025                  !!!next-token;                  !!!next-token;
6026                  next B;                  next B;
# Line 5534  sub _tree_construction_main ($) { Line 6033  sub _tree_construction_main ($) {
6033                }                }
6034              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
6035                !!!cp ('t266');                !!!cp ('t266');
6036                !!!parse-error (type => 'unmatched end tag:col', token => $token);                !!!parse-error (type => 'unmatched end tag',
6037                                  text => 'col', token => $token);
6038                ## Ignore the token                ## Ignore the token
6039                !!!next-token;                !!!next-token;
6040                next B;                next B;
# Line 5564  sub _tree_construction_main ($) { Line 6064  sub _tree_construction_main ($) {
6064            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
6065              !!!cp ('t269');              !!!cp ('t269');
6066  ## TODO: Wrong error type?  ## TODO: Wrong error type?
6067              !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);              !!!parse-error (type => 'unmatched end tag',
6068                                text => 'colgroup', token => $token);
6069              ## Ignore the token              ## Ignore the token
6070              !!!nack ('t269.1');              !!!nack ('t269.1');
6071              !!!next-token;              !!!next-token;
# Line 5618  sub _tree_construction_main ($) { Line 6119  sub _tree_construction_main ($) {
6119            !!!nack ('t277.1');            !!!nack ('t277.1');
6120            !!!next-token;            !!!next-token;
6121            next B;            next B;
6122          } elsif ($token->{tag_name} eq 'select' or          } elsif ({
6123                   $token->{tag_name} eq 'input' or                     select => 1, input => 1, textarea => 1,
6124                     }->{$token->{tag_name}} or
6125                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
6126                    {                    {
6127                     caption => 1, table => 1,                     caption => 1, table => 1,
# Line 5627  sub _tree_construction_main ($) { Line 6129  sub _tree_construction_main ($) {
6129                     tr => 1, td => 1, th => 1,                     tr => 1, td => 1, th => 1,
6130                    }->{$token->{tag_name}})) {                    }->{$token->{tag_name}})) {
6131            ## TODO: The type below is not good - <select> is replaced by </select>            ## TODO: The type below is not good - <select> is replaced by </select>
6132            !!!parse-error (type => 'not closed:select', token => $token);            !!!parse-error (type => 'not closed', text => 'select',
6133                              token => $token);
6134            ## NOTE: As if the token were </select> (<select> case) or            ## NOTE: As if the token were </select> (<select> case) or
6135            ## as if there were </select> (otherwise).            ## as if there were </select> (otherwise).
6136            ## have an element in table scope            ## have an element in table scope
# Line 5645  sub _tree_construction_main ($) { Line 6148  sub _tree_construction_main ($) {
6148            } # INSCOPE            } # INSCOPE
6149            unless (defined $i) {            unless (defined $i) {
6150              !!!cp ('t280');              !!!cp ('t280');
6151              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6152                                text => 'select', token => $token);
6153              ## Ignore the token              ## Ignore the token
6154              !!!nack ('t280.1');              !!!nack ('t280.1');
6155              !!!next-token;              !!!next-token;
# Line 5669  sub _tree_construction_main ($) { Line 6173  sub _tree_construction_main ($) {
6173            }            }
6174          } else {          } else {
6175            !!!cp ('t282');            !!!cp ('t282');
6176            !!!parse-error (type => 'in select:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select',
6177                              text => $token->{tag_name}, token => $token);
6178            ## Ignore the token            ## Ignore the token
6179            !!!nack ('t282.1');            !!!nack ('t282.1');
6180            !!!next-token;            !!!next-token;
# Line 5687  sub _tree_construction_main ($) { Line 6192  sub _tree_construction_main ($) {
6192              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6193            } else {            } else {
6194              !!!cp ('t285');              !!!cp ('t285');
6195              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6196                                text => $token->{tag_name}, token => $token);
6197              ## Ignore the token              ## Ignore the token
6198            }            }
6199            !!!nack ('t285.1');            !!!nack ('t285.1');
# Line 5699  sub _tree_construction_main ($) { Line 6205  sub _tree_construction_main ($) {
6205              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6206            } else {            } else {
6207              !!!cp ('t287');              !!!cp ('t287');
6208              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6209                                text => $token->{tag_name}, token => $token);
6210              ## Ignore the token              ## Ignore the token
6211            }            }
6212            !!!nack ('t287.1');            !!!nack ('t287.1');
# Line 5721  sub _tree_construction_main ($) { Line 6228  sub _tree_construction_main ($) {
6228            } # INSCOPE            } # INSCOPE
6229            unless (defined $i) {            unless (defined $i) {
6230              !!!cp ('t290');              !!!cp ('t290');
6231              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6232                                text => $token->{tag_name}, token => $token);
6233              ## Ignore the token              ## Ignore the token
6234              !!!nack ('t290.1');              !!!nack ('t290.1');
6235              !!!next-token;              !!!next-token;
# Line 5742  sub _tree_construction_main ($) { Line 6250  sub _tree_construction_main ($) {
6250                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
6251                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
6252  ## TODO: The following is wrong?  ## TODO: The following is wrong?
6253            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
6254                              text => $token->{tag_name}, token => $token);
6255                                
6256            ## have an element in table scope            ## have an element in table scope
6257            my $i;            my $i;
# Line 5783  sub _tree_construction_main ($) { Line 6292  sub _tree_construction_main ($) {
6292            unless (defined $i) {            unless (defined $i) {
6293              !!!cp ('t297');              !!!cp ('t297');
6294  ## TODO: The following error type is correct?  ## TODO: The following error type is correct?
6295              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6296                                text => 'select', token => $token);
6297              ## Ignore the </select> token              ## Ignore the </select> token
6298              !!!nack ('t297.1');              !!!nack ('t297.1');
6299              !!!next-token; ## TODO: ok?              !!!next-token; ## TODO: ok?
# Line 5800  sub _tree_construction_main ($) { Line 6310  sub _tree_construction_main ($) {
6310            next B;            next B;
6311          } else {          } else {
6312            !!!cp ('t299');            !!!cp ('t299');
6313            !!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select:/',
6314                              text => $token->{tag_name}, token => $token);
6315            ## Ignore the token            ## Ignore the token
6316            !!!nack ('t299.3');            !!!nack ('t299.3');
6317            !!!next-token;            !!!next-token;
# Line 5838  sub _tree_construction_main ($) { Line 6349  sub _tree_construction_main ($) {
6349                    
6350          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6351            !!!cp ('t301');            !!!cp ('t301');
6352            !!!parse-error (type => 'after html:#character', token => $token);            !!!parse-error (type => 'after html:#text', token => $token);
6353    
6354            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6355          } else {          } else {
# Line 5846  sub _tree_construction_main ($) { Line 6357  sub _tree_construction_main ($) {
6357          }          }
6358                    
6359          ## "after body" insertion mode          ## "after body" insertion mode
6360          !!!parse-error (type => 'after body:#character', token => $token);          !!!parse-error (type => 'after body:#text', token => $token);
6361    
6362          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6363          ## reprocess          ## reprocess
# Line 5854  sub _tree_construction_main ($) { Line 6365  sub _tree_construction_main ($) {
6365        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
6366          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6367            !!!cp ('t303');            !!!cp ('t303');
6368            !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html',
6369                              text => $token->{tag_name}, token => $token);
6370                        
6371            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6372          } else {          } else {
# Line 5862  sub _tree_construction_main ($) { Line 6374  sub _tree_construction_main ($) {
6374          }          }
6375    
6376          ## "after body" insertion mode          ## "after body" insertion mode
6377          !!!parse-error (type => 'after body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'after body',
6378                            text => $token->{tag_name}, token => $token);
6379    
6380          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6381          !!!ack-later;          !!!ack-later;
# Line 5871  sub _tree_construction_main ($) { Line 6384  sub _tree_construction_main ($) {
6384        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6385          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6386            !!!cp ('t305');            !!!cp ('t305');
6387            !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html:/',
6388                              text => $token->{tag_name}, token => $token);
6389                        
6390            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6391            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
# Line 5883  sub _tree_construction_main ($) { Line 6397  sub _tree_construction_main ($) {
6397          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
6398            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
6399              !!!cp ('t307');              !!!cp ('t307');
6400              !!!parse-error (type => 'unmatched end tag:html', token => $token);              !!!parse-error (type => 'unmatched end tag',
6401                                text => 'html', token => $token);
6402              ## Ignore the token              ## Ignore the token
6403              !!!next-token;              !!!next-token;
6404              next B;              next B;
# Line 5895  sub _tree_construction_main ($) { Line 6410  sub _tree_construction_main ($) {
6410            }            }
6411          } else {          } else {
6412            !!!cp ('t309');            !!!cp ('t309');
6413            !!!parse-error (type => 'after body:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after body:/',
6414                              text => $token->{tag_name}, token => $token);
6415    
6416            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
6417            ## reprocess            ## reprocess
# Line 5923  sub _tree_construction_main ($) { Line 6439  sub _tree_construction_main ($) {
6439          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
6440            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6441              !!!cp ('t311');              !!!cp ('t311');
6442              !!!parse-error (type => 'in frameset:#character', token => $token);              !!!parse-error (type => 'in frameset:#text', token => $token);
6443            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6444              !!!cp ('t312');              !!!cp ('t312');
6445              !!!parse-error (type => 'after frameset:#character', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6446            } else { # "after html frameset"            } else { # "after after frameset"
6447              !!!cp ('t313');              !!!cp ('t313');
6448              !!!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);  
6449            }            }
6450                        
6451            ## Ignore the token.            ## Ignore the token.
# Line 5949  sub _tree_construction_main ($) { Line 6461  sub _tree_construction_main ($) {
6461                    
6462          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
6463        } 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');  
         }  
   
6464          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6465              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6466            !!!cp ('t318');            !!!cp ('t318');
# Line 5976  sub _tree_construction_main ($) { Line 6478  sub _tree_construction_main ($) {
6478            next B;            next B;
6479          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
6480            !!!cp ('t320');            !!!cp ('t320');
6481            ## NOTE: As if in body.            ## NOTE: As if in head.
6482            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
6483            next B;            next B;
6484    
6485              ## NOTE: |<!DOCTYPE HTML><frameset></frameset></html><noframes></noframes>|
6486              ## has no parse error.
6487          } else {          } else {
6488            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6489              !!!cp ('t321');              !!!cp ('t321');
6490              !!!parse-error (type => 'in frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset',
6491            } else {                              text => $token->{tag_name}, token => $token);
6492              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6493              !!!cp ('t322');              !!!cp ('t322');
6494              !!!parse-error (type => 'after frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after frameset',
6495                                text => $token->{tag_name}, token => $token);
6496              } else { # "after after frameset"
6497                !!!cp ('t322.2');
6498                !!!parse-error (type => 'after after frameset',
6499                                text => $token->{tag_name}, token => $token);
6500            }            }
6501            ## Ignore the token            ## Ignore the token
6502            !!!nack ('t322.1');            !!!nack ('t322.1');
# Line 5993  sub _tree_construction_main ($) { Line 6504  sub _tree_construction_main ($) {
6504            next B;            next B;
6505          }          }
6506        } 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');  
         }  
   
6507          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6508              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6509            if ($self->{open_elements}->[-1]->[1] & HTML_EL and            if ($self->{open_elements}->[-1]->[1] & HTML_EL and
6510                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
6511              !!!cp ('t325');              !!!cp ('t325');
6512              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6513                                text => $token->{tag_name}, token => $token);
6514              ## Ignore the token              ## Ignore the token
6515              !!!next-token;              !!!next-token;
6516            } else {            } else {
# Line 6034  sub _tree_construction_main ($) { Line 6536  sub _tree_construction_main ($) {
6536          } else {          } else {
6537            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6538              !!!cp ('t330');              !!!cp ('t330');
6539              !!!parse-error (type => 'in frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset:/',
6540            } else {                              text => $token->{tag_name}, token => $token);
6541              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6542                !!!cp ('t330.1');
6543                !!!parse-error (type => 'after frameset:/',
6544                                text => $token->{tag_name}, token => $token);
6545              } else { # "after after html"
6546              !!!cp ('t331');              !!!cp ('t331');
6547              !!!parse-error (type => 'after frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after after frameset:/',
6548                                text => $token->{tag_name}, token => $token);
6549            }            }
6550            ## Ignore the token            ## Ignore the token
6551            !!!next-token;            !!!next-token;
# Line 6091  sub _tree_construction_main ($) { Line 6599  sub _tree_construction_main ($) {
6599          my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.          my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
6600    
6601          unless ($self->{confident}) {          unless ($self->{confident}) {
6602            if ($token->{attributes}->{charset}) { ## TODO: And if supported            if ($token->{attributes}->{charset}) {
6603              !!!cp ('t335');              !!!cp ('t335');
6604                ## NOTE: Whether the encoding is supported or not is handled
6605                ## in the {change_encoding} callback.
6606              $self->{change_encoding}              $self->{change_encoding}
6607                  ->($self, $token->{attributes}->{charset}->{value}, $token);                  ->($self, $token->{attributes}->{charset}->{value}, $token);
6608                            
# Line 6101  sub _tree_construction_main ($) { Line 6611  sub _tree_construction_main ($) {
6611                                       $token->{attributes}->{charset}                                       $token->{attributes}->{charset}
6612                                           ->{has_reference});                                           ->{has_reference});
6613            } elsif ($token->{attributes}->{content}) {            } elsif ($token->{attributes}->{content}) {
             ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.  
6614              if ($token->{attributes}->{content}->{value}              if ($token->{attributes}->{content}->{value}
6615                  =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                  =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
6616                      [\x09-\x0D\x20]*=                      [\x09-\x0D\x20]*=
6617                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
6618                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
6619                !!!cp ('t336');                !!!cp ('t336');
6620                  ## NOTE: Whether the encoding is supported or not is handled
6621                  ## in the {change_encoding} callback.
6622                $self->{change_encoding}                $self->{change_encoding}
6623                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3, $token);                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3, $token);
6624                $meta_el->[0]->get_attribute_node_ns (undef, 'content')                $meta_el->[0]->get_attribute_node_ns (undef, 'content')
# Line 6142  sub _tree_construction_main ($) { Line 6653  sub _tree_construction_main ($) {
6653          $parse_rcdata->(RCDATA_CONTENT_MODEL);          $parse_rcdata->(RCDATA_CONTENT_MODEL);
6654          next B;          next B;
6655        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
6656          !!!parse-error (type => 'in body:body', token => $token);          !!!parse-error (type => 'in body', text => 'body', token => $token);
6657                                
6658          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
6659              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {
# Line 6262  sub _tree_construction_main ($) { Line 6773  sub _tree_construction_main ($) {
6773              if ($i != -1) {              if ($i != -1) {
6774                !!!cp ('t355');                !!!cp ('t355');
6775                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
6776                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
6777                                    ->manakai_local_name,                                    ->manakai_local_name,
6778                                token => $token);                                token => $token);
6779              } else {              } else {
# Line 6416  sub _tree_construction_main ($) { Line 6927  sub _tree_construction_main ($) {
6927                  xmp => 1,                  xmp => 1,
6928                  iframe => 1,                  iframe => 1,
6929                  noembed => 1,                  noembed => 1,
6930                  noframes => 1,                  noframes => 1, ## NOTE: This is an "as if in head" code clone.
6931                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
6932                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6933          if ($token->{tag_name} eq 'xmp') {          if ($token->{tag_name} eq 'xmp') {
# Line 6438  sub _tree_construction_main ($) { Line 6949  sub _tree_construction_main ($) {
6949            !!!next-token;            !!!next-token;
6950            next B;            next B;
6951          } else {          } else {
6952              !!!ack ('t391.1');
6953    
6954            my $at = $token->{attributes};            my $at = $token->{attributes};
6955            my $form_attrs;            my $form_attrs;
6956            $form_attrs->{action} = $at->{action} if $at->{action};            $form_attrs->{action} = $at->{action} if $at->{action};
# Line 6481  sub _tree_construction_main ($) { Line 6994  sub _tree_construction_main ($) {
6994                           line => $token->{line}, column => $token->{column}},                           line => $token->{line}, column => $token->{column}},
6995                          {type => END_TAG_TOKEN, tag_name => 'form',                          {type => END_TAG_TOKEN, tag_name => 'form',
6996                           line => $token->{line}, column => $token->{column}};                           line => $token->{line}, column => $token->{column}};
           !!!nack ('t391.1'); ## NOTE: Not acknowledged.  
6997            !!!back-token (@tokens);            !!!back-token (@tokens);
6998            !!!next-token;            !!!next-token;
6999            next B;            next B;
# Line 6529  sub _tree_construction_main ($) { Line 7041  sub _tree_construction_main ($) {
7041            ## Ignore the token            ## Ignore the token
7042          } else {          } else {
7043            !!!cp ('t398');            !!!cp ('t398');
7044            !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);            !!!parse-error (type => 'in RCDATA:#eof', token => $token);
7045          }          }
7046          !!!next-token;          !!!next-token;
7047          next B;          next B;
7048          } elsif ($token->{tag_name} eq 'rt' or
7049                   $token->{tag_name} eq 'rp') {
7050            ## has a |ruby| element in scope
7051            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
7052              my $node = $self->{open_elements}->[$_];
7053              if ($node->[1] & RUBY_EL) {
7054                !!!cp ('t398.1');
7055                ## generate implied end tags
7056                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7057                  !!!cp ('t398.2');
7058                  pop @{$self->{open_elements}};
7059                }
7060                unless ($self->{open_elements}->[-1]->[1] & RUBY_EL) {
7061                  !!!cp ('t398.3');
7062                  !!!parse-error (type => 'not closed',
7063                                  text => $self->{open_elements}->[-1]->[0]
7064                                      ->manakai_local_name,
7065                                  token => $token);
7066                  pop @{$self->{open_elements}}
7067                      while not $self->{open_elements}->[-1]->[1] & RUBY_EL;
7068                }
7069                last INSCOPE;
7070              } elsif ($node->[1] & SCOPING_EL) {
7071                !!!cp ('t398.4');
7072                last INSCOPE;
7073              }
7074            } # INSCOPE
7075    
7076            !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
7077    
7078            !!!nack ('t398.5');
7079            !!!next-token;
7080            redo B;
7081        } elsif ($token->{tag_name} eq 'math' or        } elsif ($token->{tag_name} eq 'math' or
7082                 $token->{tag_name} eq 'svg') {                 $token->{tag_name} eq 'svg') {
7083          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
7084    
7085            ## "Adjust MathML attributes" ('math' only) - done in insert-element-f
7086    
7087          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f
7088    
7089          ## "adjust foreign attributes" - done in insert-element-f          ## "adjust foreign attributes" - done in insert-element-f
# Line 6563  sub _tree_construction_main ($) { Line 7110  sub _tree_construction_main ($) {
7110                  thead => 1, tr => 1,                  thead => 1, tr => 1,
7111                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7112          !!!cp ('t401');          !!!cp ('t401');
7113          !!!parse-error (type => 'in body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in body',
7114                            text => $token->{tag_name}, token => $token);
7115          ## Ignore the token          ## Ignore the token
7116          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.
7117          !!!next-token;          !!!next-token;
# Line 6648  sub _tree_construction_main ($) { Line 7196  sub _tree_construction_main ($) {
7196            }            }
7197    
7198            !!!parse-error (type => 'start tag not allowed',            !!!parse-error (type => 'start tag not allowed',
7199                            value => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7200            ## NOTE: Ignore the token.            ## NOTE: Ignore the token.
7201            !!!next-token;            !!!next-token;
7202            next B;            next B;
# Line 6658  sub _tree_construction_main ($) { Line 7206  sub _tree_construction_main ($) {
7206            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {
7207              !!!cp ('t403');              !!!cp ('t403');
7208              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7209                              value => $_->[0]->manakai_local_name,                              text => $_->[0]->manakai_local_name,
7210                              token => $token);                              token => $token);
7211              last;              last;
7212            } else {            } else {
# Line 6678  sub _tree_construction_main ($) { Line 7226  sub _tree_construction_main ($) {
7226            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {
7227              !!!cp ('t406');              !!!cp ('t406');
7228              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7229                              value => $self->{open_elements}->[1]->[0]                              text => $self->{open_elements}->[1]->[0]
7230                                  ->manakai_local_name,                                  ->manakai_local_name,
7231                              token => $token);                              token => $token);
7232            } else {            } else {
# Line 6689  sub _tree_construction_main ($) { Line 7237  sub _tree_construction_main ($) {
7237            next B;            next B;
7238          } else {          } else {
7239            !!!cp ('t408');            !!!cp ('t408');
7240            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7241                              text => $token->{tag_name}, token => $token);
7242            ## Ignore the token            ## Ignore the token
7243            !!!next-token;            !!!next-token;
7244            next B;            next B;
# Line 6717  sub _tree_construction_main ($) { Line 7266  sub _tree_construction_main ($) {
7266    
7267          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7268            !!!cp ('t413');            !!!cp ('t413');
7269            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7270                              text => $token->{tag_name}, token => $token);
7271              ## NOTE: Ignore the token.
7272          } else {          } else {
7273            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7274            while ({            while ({
7275                      ## END_TAG_OPTIONAL_EL
7276                    dd => ($token->{tag_name} ne 'dd'),                    dd => ($token->{tag_name} ne 'dd'),
7277                    dt => ($token->{tag_name} ne 'dt'),                    dt => ($token->{tag_name} ne 'dt'),
7278                    li => ($token->{tag_name} ne 'li'),                    li => ($token->{tag_name} ne 'li'),
7279                    p => 1,                    p => 1,
7280                      rt => 1,
7281                      rp => 1,
7282                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {
7283              !!!cp ('t409');              !!!cp ('t409');
7284              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
# Line 6735  sub _tree_construction_main ($) { Line 7289  sub _tree_construction_main ($) {
7289                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7290              !!!cp ('t412');              !!!cp ('t412');
7291              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7292                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7293                                  ->manakai_local_name,                                  ->manakai_local_name,
7294                              token => $token);                              token => $token);
7295            } else {            } else {
# Line 6772  sub _tree_construction_main ($) { Line 7326  sub _tree_construction_main ($) {
7326    
7327          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7328            !!!cp ('t421');            !!!cp ('t421');
7329            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7330                              text => $token->{tag_name}, token => $token);
7331              ## NOTE: Ignore the token.
7332          } else {          } else {
7333            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7334            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 6785  sub _tree_construction_main ($) { Line 7341  sub _tree_construction_main ($) {
7341                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7342              !!!cp ('t417.1');              !!!cp ('t417.1');
7343              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7344                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7345                                  ->manakai_local_name,                                  ->manakai_local_name,
7346                              token => $token);                              token => $token);
7347            } else {            } else {
# Line 6817  sub _tree_construction_main ($) { Line 7373  sub _tree_construction_main ($) {
7373    
7374          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7375            !!!cp ('t425.1');            !!!cp ('t425.1');
7376            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7377                              text => $token->{tag_name}, token => $token);
7378              ## NOTE: Ignore the token.
7379          } else {          } else {
7380            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7381            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 6829  sub _tree_construction_main ($) { Line 7387  sub _tree_construction_main ($) {
7387            if ($self->{open_elements}->[-1]->[0]->manakai_local_name            if ($self->{open_elements}->[-1]->[0]->manakai_local_name
7388                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7389              !!!cp ('t425');              !!!cp ('t425');
7390              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
7391                                text => $token->{tag_name}, token => $token);
7392            } else {            } else {
7393              !!!cp ('t426');              !!!cp ('t426');
7394            }            }
# Line 6860  sub _tree_construction_main ($) { Line 7419  sub _tree_construction_main ($) {
7419                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7420              !!!cp ('t412.1');              !!!cp ('t412.1');
7421              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7422                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7423                                  ->manakai_local_name,                                  ->manakai_local_name,
7424                              token => $token);                              token => $token);
7425            } else {            } else {
# Line 6870  sub _tree_construction_main ($) { Line 7429  sub _tree_construction_main ($) {
7429            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
7430          } else {          } else {
7431            !!!cp ('t413.1');            !!!cp ('t413.1');
7432            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7433                              text => $token->{tag_name}, token => $token);
7434    
7435            !!!cp ('t415.1');            !!!cp ('t415.1');
7436            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
# Line 6893  sub _tree_construction_main ($) { Line 7453  sub _tree_construction_main ($) {
7453          next B;          next B;
7454        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
7455          !!!cp ('t428');          !!!cp ('t428');
7456          !!!parse-error (type => 'unmatched end tag:br', token => $token);          !!!parse-error (type => 'unmatched end tag',
7457                            text => 'br', token => $token);
7458    
7459          ## As if <br>          ## As if <br>
7460          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
# Line 6918  sub _tree_construction_main ($) { Line 7479  sub _tree_construction_main ($) {
7479                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
7480                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7481          !!!cp ('t429');          !!!cp ('t429');
7482          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'unmatched end tag',
7483                            text => $token->{tag_name}, token => $token);
7484          ## Ignore the token          ## Ignore the token
7485          !!!next-token;          !!!next-token;
7486          next B;          next B;
# Line 6937  sub _tree_construction_main ($) { Line 7499  sub _tree_construction_main ($) {
7499              ## generate implied end tags              ## generate implied end tags
7500              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7501                !!!cp ('t430');                !!!cp ('t430');
7502                ## ISSUE: Can this case be reached?                ## NOTE: |<ruby><rt></ruby>|.
7503                  ## ISSUE: <ruby><rt></rt> will also take this code path,
7504                  ## which seems wrong.
7505                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
7506                  $node_i++;
7507              }              }
7508                    
7509              ## Step 2              ## Step 2
# Line 6947  sub _tree_construction_main ($) { Line 7512  sub _tree_construction_main ($) {
7512                !!!cp ('t431');                !!!cp ('t431');
7513                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
7514                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
7515                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
7516                                    ->manakai_local_name,                                    ->manakai_local_name,
7517                                token => $token);                                token => $token);
7518              } else {              } else {
# Line 6955  sub _tree_construction_main ($) { Line 7520  sub _tree_construction_main ($) {
7520              }              }
7521                            
7522              ## Step 3              ## Step 3
7523              splice @{$self->{open_elements}}, $node_i;              splice @{$self->{open_elements}}, $node_i if $node_i < 0;
7524    
7525              !!!next-token;              !!!next-token;
7526              last S2;              last S2;
# Line 6966  sub _tree_construction_main ($) { Line 7531  sub _tree_construction_main ($) {
7531                  ($node->[1] & SPECIAL_EL or                  ($node->[1] & SPECIAL_EL or
7532                   $node->[1] & SCOPING_EL)) {                   $node->[1] & SCOPING_EL)) {
7533                !!!cp ('t433');                !!!cp ('t433');
7534                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
7535                                  text => $token->{tag_name}, token => $token);
7536                ## Ignore the token                ## Ignore the token
7537                !!!next-token;                !!!next-token;
7538                last S2;                last S2;
# Line 7012  sub _tree_construction_main ($) { Line 7578  sub _tree_construction_main ($) {
7578    ## TODO: script stuffs    ## TODO: script stuffs
7579  } # _tree_construct_main  } # _tree_construct_main
7580    
7581  sub set_inner_html ($$$) {  sub set_inner_html ($$$;$) {
7582    my $class = shift;    my $class = shift;
7583    my $node = shift;    my $node = shift;
7584    my $s = \$_[0];    my $s = \$_[0];
7585    my $onerror = $_[1];    my $onerror = $_[1];
7586      my $get_wrapper = $_[2] || sub ($) { return $_[0] };
7587    
7588    ## ISSUE: Should {confident} be true?    ## ISSUE: Should {confident} be true?
7589    
# Line 7035  sub set_inner_html ($$$) { Line 7602  sub set_inner_html ($$$) {
7602      }      }
7603    
7604      ## Step 3, 4, 5 # MUST      ## Step 3, 4, 5 # MUST
7605      $class->parse_string ($$s => $node, $onerror);      $class->parse_char_string ($$s => $node, $onerror, $get_wrapper);
7606    } elsif ($nt == 1) {    } elsif ($nt == 1) {
7607      ## TODO: If non-html element      ## TODO: If non-html element
7608    
7609      ## NOTE: Most of this code is copied from |parse_string|      ## NOTE: Most of this code is copied from |parse_string|
7610    
7611    ## TODO: Support for $get_wrapper
7612    
7613      ## Step 1 # MUST      ## Step 1 # MUST
7614      my $this_doc = $node->owner_document;      my $this_doc = $node->owner_document;
7615      my $doc = $this_doc->implementation->create_document;      my $doc = $this_doc->implementation->create_document;
# Line 7102  sub set_inner_html ($$$) { Line 7671  sub set_inner_html ($$$) {
7671                  0x10FFFE => 1, 0x10FFFF => 1,                  0x10FFFE => 1, 0x10FFFF => 1,
7672                 }->{$self->{next_char}}) {                 }->{$self->{next_char}}) {
7673          !!!cp ('i4.1');          !!!cp ('i4.1');
7674          !!!parse-error (type => 'control char', level => $self->{must_level});          if ($self->{next_char} < 0x10000) {
7675  ## TODO: error type documentation            !!!parse-error (type => 'control char',
7676                              text => (sprintf 'U+%04X', $self->{next_char}));
7677            } else {
7678              !!!parse-error (type => 'control char',
7679                              text => (sprintf 'U-%08X', $self->{next_char}));
7680            }
7681        }        }
7682      };      };
7683      $p->{prev_char} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];

Legend:
Removed from v.1.132  
changed lines
  Added in v.1.167

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24