/[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.128 by wakaba, Sat Apr 12 15:31:56 2008 UTC revision 1.165 by wakaba, Sat Sep 13 07:51:33 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: Control charcters and noncharacters are not allowed (HTML5 revision 1263)  require IO::Handle;
 ## TODO: 1252 parse error (revision 1264)  
 ## 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 47  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 54  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 98  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 172  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 205  my $el_category_f = { Line 223  my $el_category_f = {
223      mtext => FOREIGN_FLOW_CONTENT_EL,      mtext => FOREIGN_FLOW_CONTENT_EL,
224    },    },
225    $SVG_NS => {    $SVG_NS => {
226      foreignobject => FOREIGN_FLOW_CONTENT_EL, ## TODO: case      foreignObject => FOREIGN_FLOW_CONTENT_EL,
227      desc => FOREIGN_FLOW_CONTENT_EL,      desc => FOREIGN_FLOW_CONTENT_EL,
228      title => FOREIGN_FLOW_CONTENT_EL,      title => FOREIGN_FLOW_CONTENT_EL,
229    },    },
230    ## NOTE: In addition, FOREIGN_EL is set to non-HTML elements.    ## NOTE: In addition, FOREIGN_EL is set to non-HTML elements.
231  };  };
232    
233    my $svg_attr_name = {
234      attributename => 'attributeName',
235      attributetype => 'attributeType',
236      basefrequency => 'baseFrequency',
237      baseprofile => 'baseProfile',
238      calcmode => 'calcMode',
239      clippathunits => 'clipPathUnits',
240      contentscripttype => 'contentScriptType',
241      contentstyletype => 'contentStyleType',
242      diffuseconstant => 'diffuseConstant',
243      edgemode => 'edgeMode',
244      externalresourcesrequired => 'externalResourcesRequired',
245      filterres => 'filterRes',
246      filterunits => 'filterUnits',
247      glyphref => 'glyphRef',
248      gradienttransform => 'gradientTransform',
249      gradientunits => 'gradientUnits',
250      kernelmatrix => 'kernelMatrix',
251      kernelunitlength => 'kernelUnitLength',
252      keypoints => 'keyPoints',
253      keysplines => 'keySplines',
254      keytimes => 'keyTimes',
255      lengthadjust => 'lengthAdjust',
256      limitingconeangle => 'limitingConeAngle',
257      markerheight => 'markerHeight',
258      markerunits => 'markerUnits',
259      markerwidth => 'markerWidth',
260      maskcontentunits => 'maskContentUnits',
261      maskunits => 'maskUnits',
262      numoctaves => 'numOctaves',
263      pathlength => 'pathLength',
264      patterncontentunits => 'patternContentUnits',
265      patterntransform => 'patternTransform',
266      patternunits => 'patternUnits',
267      pointsatx => 'pointsAtX',
268      pointsaty => 'pointsAtY',
269      pointsatz => 'pointsAtZ',
270      preservealpha => 'preserveAlpha',
271      preserveaspectratio => 'preserveAspectRatio',
272      primitiveunits => 'primitiveUnits',
273      refx => 'refX',
274      refy => 'refY',
275      repeatcount => 'repeatCount',
276      repeatdur => 'repeatDur',
277      requiredextensions => 'requiredExtensions',
278      requiredfeatures => 'requiredFeatures',
279      specularconstant => 'specularConstant',
280      specularexponent => 'specularExponent',
281      spreadmethod => 'spreadMethod',
282      startoffset => 'startOffset',
283      stddeviation => 'stdDeviation',
284      stitchtiles => 'stitchTiles',
285      surfacescale => 'surfaceScale',
286      systemlanguage => 'systemLanguage',
287      tablevalues => 'tableValues',
288      targetx => 'targetX',
289      targety => 'targetY',
290      textlength => 'textLength',
291      viewbox => 'viewBox',
292      viewtarget => 'viewTarget',
293      xchannelselector => 'xChannelSelector',
294      ychannelselector => 'yChannelSelector',
295      zoomandpan => 'zoomAndPan',
296    };
297    
298    my $foreign_attr_xname = {
299      'xlink:actuate' => [$XLINK_NS, ['xlink', 'actuate']],
300      'xlink:arcrole' => [$XLINK_NS, ['xlink', 'arcrole']],
301      'xlink:href' => [$XLINK_NS, ['xlink', 'href']],
302      'xlink:role' => [$XLINK_NS, ['xlink', 'role']],
303      'xlink:show' => [$XLINK_NS, ['xlink', 'show']],
304      'xlink:title' => [$XLINK_NS, ['xlink', 'title']],
305      'xlink:type' => [$XLINK_NS, ['xlink', 'type']],
306      'xml:base' => [$XML_NS, ['xml', 'base']],
307      'xml:lang' => [$XML_NS, ['xml', 'lang']],
308      'xml:space' => [$XML_NS, ['xml', 'space']],
309      'xmlns' => [$XMLNS_NS, [undef, 'xmlns']],
310      'xmlns:xlink' => [$XMLNS_NS, ['xmlns', 'xlink']],
311    };
312    
313    ## ISSUE: xmlns:xlink="non-xlink-ns" is not an error.
314    
315  my $c1_entity_char = {  my $c1_entity_char = {
316    0x80 => 0x20AC,    0x80 => 0x20AC,
317    0x81 => 0xFFFD,    0x81 => 0xFFFD,
# Line 248  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 327  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 350  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});
664      $self->{column}++;      $self->{column}++;
665            
666      if ($self->{next_char} == 0x000A) { # LF      if ($self->{next_char} == 0x000A) { # LF
667          !!!cp ('j1');
668        $self->{line}++;        $self->{line}++;
669        $self->{column} = 0;        $self->{column} = 0;
670      } elsif ($self->{next_char} == 0x000D) { # CR      } elsif ($self->{next_char} == 0x000D) { # CR
671        $i++ if substr ($$s, $i, 1) eq "\x0A";        !!!cp ('j2');
672          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;
679      } elsif ($self->{next_char} > 0x10FFFF) {      } elsif ($self->{next_char} > 0x10FFFF) {
680          !!!cp ('j3');
681        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
682      } elsif ($self->{next_char} == 0x0000) { # NULL      } elsif ($self->{next_char} == 0x0000) { # NULL
683          !!!cp ('j4');
684        !!!parse-error (type => 'NULL');        !!!parse-error (type => 'NULL');
685        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
686        } elsif ($self->{next_char} <= 0x0008 or
687                 (0x000E <= $self->{next_char} and $self->{next_char} <= 0x001F) or
688                 (0x007F <= $self->{next_char} and $self->{next_char} <= 0x009F) or
689                 (0xD800 <= $self->{next_char} and $self->{next_char} <= 0xDFFF) or
690                 (0xFDD0 <= $self->{next_char} and $self->{next_char} <= 0xFDDF) or
691                 {
692                  0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,
693                  0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,
694                  0x4FFFE => 1, 0x4FFFF => 1, 0x5FFFE => 1, 0x5FFFF => 1,
695                  0x6FFFE => 1, 0x6FFFF => 1, 0x7FFFE => 1, 0x7FFFF => 1,
696                  0x8FFFE => 1, 0x8FFFF => 1, 0x9FFFE => 1, 0x9FFFF => 1,
697                  0xAFFFE => 1, 0xAFFFF => 1, 0xBFFFE => 1, 0xBFFFF => 1,
698                  0xCFFFE => 1, 0xCFFFF => 1, 0xDFFFE => 1, 0xDFFFF => 1,
699                  0xEFFFE => 1, 0xEFFFF => 1, 0xFFFFE => 1, 0xFFFFF => 1,
700                  0x10FFFE => 1, 0x10FFFF => 1,
701                 }->{$self->{next_char}}) {
702          !!!cp ('j5');
703          if ($self->{next_char} < 0x10000) {
704            !!!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 393  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 460  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    
814  sub DOCTYPE_TOKEN () { 1 }  sub DOCTYPE_TOKEN () { 1 }
815  sub COMMENT_TOKEN () { 2 }  sub COMMENT_TOKEN () { 2 }
# Line 513  sub IN_COLUMN_GROUP_IM () { 0b10 } Line 862  sub IN_COLUMN_GROUP_IM () { 0b10 }
862  sub _initialize_tokenizer ($) {  sub _initialize_tokenizer ($) {
863    my $self = shift;    my $self = shift;
864    $self->{state} = DATA_STATE; # MUST    $self->{state} = DATA_STATE; # MUST
865      #$self->{state_keyword}; # initialized when used
866    $self->{content_model} = PCDATA_CONTENT_MODEL; # be    $self->{content_model} = PCDATA_CONTENT_MODEL; # be
867    undef $self->{current_token}; # start tag, end tag, comment, or DOCTYPE    undef $self->{current_token};
868    undef $self->{current_attribute};    undef $self->{current_attribute};
869    undef $self->{last_emitted_start_tag_name};    undef $self->{last_emitted_start_tag_name};
870    undef $self->{last_attribute_value_state};    undef $self->{last_attribute_value_state};
# Line 543  sub _initialize_tokenizer ($) { Line 893  sub _initialize_tokenizer ($) {
893  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|
894  ##     while the token is pushed back to the stack.  ##     while the token is pushed back to the stack.
895    
 ## 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?  
   
896  ## Emitted token MUST immediately be handled by the tree construction state.  ## Emitted token MUST immediately be handled by the tree construction state.
897    
898  ## 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 762  sub _get_next_token ($) { Line 1108  sub _get_next_token ($) {
1108            redo A;            redo A;
1109          } else {          } else {
1110            !!!cp (23);            !!!cp (23);
1111            !!!parse-error (type => 'bare stago');            !!!parse-error (type => 'bare stago',
1112                              line => $self->{line_prev},
1113                              column => $self->{column_prev});
1114            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1115            ## reconsume            ## reconsume
1116    
# Line 777  sub _get_next_token ($) { Line 1125  sub _get_next_token ($) {
1125          die "$0: $self->{content_model} in tag open";          die "$0: $self->{content_model} in tag open";
1126        }        }
1127      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {
1128          ## NOTE: The "close tag open state" in the spec is implemented as
1129          ## |CLOSE_TAG_OPEN_STATE| and |CDATA_PCDATA_CLOSE_TAG_STATE|.
1130    
1131        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"
1132        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1133          if (defined $self->{last_emitted_start_tag_name}) {          if (defined $self->{last_emitted_start_tag_name}) {
1134              $self->{state} = CDATA_PCDATA_CLOSE_TAG_STATE;
1135            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>            $self->{state_keyword} = '';
1136            my @next_char;            ## Reconsume.
1137            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...  
           }  
1138          } else {          } else {
1139            ## No start tag token has ever been emitted            ## No start tag token has ever been emitted
1140              ## NOTE: See <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>.
1141            !!!cp (28);            !!!cp (28);
           # next-input-character is already done  
1142            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1143              ## Reconsume.
1144            !!!emit ({type => CHARACTER_TOKEN, data => '</',            !!!emit ({type => CHARACTER_TOKEN, data => '</',
1145                      line => $l, column => $c,                      line => $l, column => $c,
1146                     });                     });
1147            redo A;            redo A;
1148          }          }
1149        }        }
1150          
1151        if (0x0041 <= $self->{next_char} and        if (0x0041 <= $self->{next_char} and
1152            $self->{next_char} <= 0x005A) { # A..Z            $self->{next_char} <= 0x005A) { # A..Z
1153          !!!cp (29);          !!!cp (29);
# Line 886  sub _get_next_token ($) { Line 1194  sub _get_next_token ($) {
1194                                    line => $self->{line_prev}, # "<" of "</"                                    line => $self->{line_prev}, # "<" of "</"
1195                                    column => $self->{column_prev} - 1,                                    column => $self->{column_prev} - 1,
1196                                   };                                   };
1197          ## $self->{next_char} is intentionally left as is          ## NOTE: $self->{next_char} is intentionally left as is.
1198          redo A;          ## Although the "anything else" case of the spec not explicitly
1199            ## states that the next input character is to be reconsumed,
1200            ## it will be included to the |data| of the comment token
1201            ## generated from the bogus end tag, as defined in the
1202            ## "bogus comment state" entry.
1203            redo A;
1204          }
1205        } elsif ($self->{state} == CDATA_PCDATA_CLOSE_TAG_STATE) {
1206          my $ch = substr $self->{last_emitted_start_tag_name}, length $self->{state_keyword}, 1;
1207          if (length $ch) {
1208            my $CH = $ch;
1209            $ch =~ tr/a-z/A-Z/;
1210            my $nch = chr $self->{next_char};
1211            if ($nch eq $ch or $nch eq $CH) {
1212              !!!cp (24);
1213              ## Stay in the state.
1214              $self->{state_keyword} .= $nch;
1215              !!!next-input-character;
1216              redo A;
1217            } else {
1218              !!!cp (25);
1219              $self->{state} = DATA_STATE;
1220              ## Reconsume.
1221              !!!emit ({type => CHARACTER_TOKEN,
1222                        data => '</' . $self->{state_keyword},
1223                        line => $self->{line_prev},
1224                        column => $self->{column_prev} - 1 - length $self->{state_keyword},
1225                       });
1226              redo A;
1227            }
1228          } else { # after "<{tag-name}"
1229            unless ({
1230                     0x0009 => 1, # HT
1231                     0x000A => 1, # LF
1232                     0x000B => 1, # VT
1233                     0x000C => 1, # FF
1234                     0x0020 => 1, # SP
1235                     0x003E => 1, # >
1236                     0x002F => 1, # /
1237                     -1 => 1, # EOF
1238                    }->{$self->{next_char}}) {
1239              !!!cp (26);
1240              ## Reconsume.
1241              $self->{state} = DATA_STATE;
1242              !!!emit ({type => CHARACTER_TOKEN,
1243                        data => '</' . $self->{state_keyword},
1244                        line => $self->{line_prev},
1245                        column => $self->{column_prev} - 1 - length $self->{state_keyword},
1246                       });
1247              redo A;
1248            } else {
1249              !!!cp (27);
1250              $self->{current_token}
1251                  = {type => END_TAG_TOKEN,
1252                     tag_name => $self->{last_emitted_start_tag_name},
1253                     line => $self->{line_prev},
1254                     column => $self->{column_prev} - 1 - length $self->{state_keyword}};
1255              $self->{state} = TAG_NAME_STATE;
1256              ## Reconsume.
1257              redo A;
1258            }
1259        }        }
1260      } elsif ($self->{state} == TAG_NAME_STATE) {      } elsif ($self->{state} == TAG_NAME_STATE) {
1261        if ($self->{next_char} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
# Line 1057  sub _get_next_token ($) { Line 1425  sub _get_next_token ($) {
1425          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
1426              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
1427            !!!cp (57);            !!!cp (57);
1428            !!!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});
1429            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{current_attribute} # MUST
1430          } else {          } else {
1431            !!!cp (58);            !!!cp (58);
# Line 1228  sub _get_next_token ($) { Line 1596  sub _get_next_token ($) {
1596    
1597          redo A;          redo A;
1598        } else {        } else {
1599          !!!cp (82);          if ($self->{next_char} == 0x0022 or # "
1600                $self->{next_char} == 0x0027) { # '
1601              !!!cp (78);
1602              !!!parse-error (type => 'bad attribute name');
1603            } else {
1604              !!!cp (82);
1605            }
1606          $self->{current_attribute}          $self->{current_attribute}
1607              = {name => chr ($self->{next_char}),              = {name => chr ($self->{next_char}),
1608                 value => '',                 value => '',
# Line 1263  sub _get_next_token ($) { Line 1637  sub _get_next_token ($) {
1637          !!!next-input-character;          !!!next-input-character;
1638          redo A;          redo A;
1639        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1640            !!!parse-error (type => 'empty unquoted attribute value');
1641          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1642            !!!cp (87);            !!!cp (87);
1643            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
# Line 1539  sub _get_next_token ($) { Line 1914  sub _get_next_token ($) {
1914          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1915          !!!next-input-character;          !!!next-input-character;
1916          redo A;          redo A;
1917          } elsif ($self->{next_char} == -1) {
1918            !!!parse-error (type => 'unclosed tag');
1919            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1920              !!!cp (122.3);
1921              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1922            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1923              if ($self->{current_token}->{attributes}) {
1924                !!!cp (122.1);
1925                !!!parse-error (type => 'end tag attribute');
1926              } else {
1927                ## NOTE: This state should never be reached.
1928                !!!cp (122.2);
1929              }
1930            } else {
1931              die "$0: $self->{current_token}->{type}: Unknown token type";
1932            }
1933            $self->{state} = DATA_STATE;
1934            ## Reconsume.
1935            !!!emit ($self->{current_token}); # start tag or end tag
1936            redo A;
1937        } else {        } else {
1938          !!!cp ('124.1');          !!!cp ('124.1');
1939          !!!parse-error (type => 'no space between attributes');          !!!parse-error (type => 'no space between attributes');
# Line 1571  sub _get_next_token ($) { Line 1966  sub _get_next_token ($) {
1966          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
1967    
1968          redo A;          redo A;
1969          } elsif ($self->{next_char} == -1) {
1970            !!!parse-error (type => 'unclosed tag');
1971            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1972              !!!cp (124.7);
1973              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1974            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1975              if ($self->{current_token}->{attributes}) {
1976                !!!cp (124.5);
1977                !!!parse-error (type => 'end tag attribute');
1978              } else {
1979                ## NOTE: This state should never be reached.
1980                !!!cp (124.6);
1981              }
1982            } else {
1983              die "$0: $self->{current_token}->{type}: Unknown token type";
1984            }
1985            $self->{state} = DATA_STATE;
1986            ## Reconsume.
1987            !!!emit ($self->{current_token}); # start tag or end tag
1988            redo A;
1989        } else {        } else {
1990          !!!cp ('124.4');          !!!cp ('124.4');
1991          !!!parse-error (type => 'nestc');          !!!parse-error (type => 'nestc');
# Line 1613  sub _get_next_token ($) { Line 2028  sub _get_next_token ($) {
2028        die "$0: _get_next_token: unexpected case [BC]";        die "$0: _get_next_token: unexpected case [BC]";
2029      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {
2030        ## (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};  
2031                
2032        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
2033            !!!cp (133);
2034            $self->{state} = MD_HYPHEN_STATE;
2035          !!!next-input-character;          !!!next-input-character;
2036          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);  
         }  
2037        } elsif ($self->{next_char} == 0x0044 or # D        } elsif ($self->{next_char} == 0x0044 or # D
2038                 $self->{next_char} == 0x0064) { # d                 $self->{next_char} == 0x0064) { # d
2039            ## ASCII case-insensitive.
2040            !!!cp (130);
2041            $self->{state} = MD_DOCTYPE_STATE;
2042            $self->{state_keyword} = chr $self->{next_char};
2043          !!!next-input-character;          !!!next-input-character;
2044          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);  
         }  
2045        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and
2046                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and
2047                 $self->{next_char} == 0x005B) { # [                 $self->{next_char} == 0x005B) { # [
2048            !!!cp (135.4);                
2049            $self->{state} = MD_CDATA_STATE;
2050            $self->{state_keyword} = '[';
2051          !!!next-input-character;          !!!next-input-character;
2052          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);  
         }  
2053        } else {        } else {
2054          !!!cp (136);          !!!cp (136);
2055        }        }
2056    
2057        !!!parse-error (type => 'bogus comment');        !!!parse-error (type => 'bogus comment',
2058        $self->{next_char} = shift @next_char;                        line => $self->{line_prev},
2059        !!!back-next-input-character (@next_char);                        column => $self->{column_prev} - 1);
2060          ## Reconsume.
2061        $self->{state} = BOGUS_COMMENT_STATE;        $self->{state} = BOGUS_COMMENT_STATE;
2062        $self->{current_token} = {type => COMMENT_TOKEN, data => '',        $self->{current_token} = {type => COMMENT_TOKEN, data => '',
2063                                  line => $l, column => $c,                                  line => $self->{line_prev},
2064                                    column => $self->{column_prev} - 1,
2065                                 };                                 };
2066        redo A;        redo A;
2067              } elsif ($self->{state} == MD_HYPHEN_STATE) {
2068        ## ISSUE: typos in spec: chacacters, is is a parse error        if ($self->{next_char} == 0x002D) { # -
2069        ## 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);
2070            $self->{current_token} = {type => COMMENT_TOKEN, data => '',
2071                                      line => $self->{line_prev},
2072                                      column => $self->{column_prev} - 2,
2073                                     };
2074            $self->{state} = COMMENT_START_STATE;
2075            !!!next-input-character;
2076            redo A;
2077          } else {
2078            !!!cp (128);
2079            !!!parse-error (type => 'bogus comment',
2080                            line => $self->{line_prev},
2081                            column => $self->{column_prev} - 2);
2082            $self->{state} = BOGUS_COMMENT_STATE;
2083            ## Reconsume.
2084            $self->{current_token} = {type => COMMENT_TOKEN,
2085                                      data => '-',
2086                                      line => $self->{line_prev},
2087                                      column => $self->{column_prev} - 2,
2088                                     };
2089            redo A;
2090          }
2091        } elsif ($self->{state} == MD_DOCTYPE_STATE) {
2092          ## ASCII case-insensitive.
2093          if ($self->{next_char} == [
2094                undef,
2095                0x004F, # O
2096                0x0043, # C
2097                0x0054, # T
2098                0x0059, # Y
2099                0x0050, # P
2100              ]->[length $self->{state_keyword}] or
2101              $self->{next_char} == [
2102                undef,
2103                0x006F, # o
2104                0x0063, # c
2105                0x0074, # t
2106                0x0079, # y
2107                0x0070, # p
2108              ]->[length $self->{state_keyword}]) {
2109            !!!cp (131);
2110            ## Stay in the state.
2111            $self->{state_keyword} .= chr $self->{next_char};
2112            !!!next-input-character;
2113            redo A;
2114          } elsif ((length $self->{state_keyword}) == 6 and
2115                   ($self->{next_char} == 0x0045 or # E
2116                    $self->{next_char} == 0x0065)) { # e
2117            !!!cp (129);
2118            $self->{state} = DOCTYPE_STATE;
2119            $self->{current_token} = {type => DOCTYPE_TOKEN,
2120                                      quirks => 1,
2121                                      line => $self->{line_prev},
2122                                      column => $self->{column_prev} - 7,
2123                                     };
2124            !!!next-input-character;
2125            redo A;
2126          } else {
2127            !!!cp (132);        
2128            !!!parse-error (type => 'bogus comment',
2129                            line => $self->{line_prev},
2130                            column => $self->{column_prev} - 1 - length $self->{state_keyword});
2131            $self->{state} = BOGUS_COMMENT_STATE;
2132            ## Reconsume.
2133            $self->{current_token} = {type => COMMENT_TOKEN,
2134                                      data => $self->{state_keyword},
2135                                      line => $self->{line_prev},
2136                                      column => $self->{column_prev} - 1 - length $self->{state_keyword},
2137                                     };
2138            redo A;
2139          }
2140        } elsif ($self->{state} == MD_CDATA_STATE) {
2141          if ($self->{next_char} == {
2142                '[' => 0x0043, # C
2143                '[C' => 0x0044, # D
2144                '[CD' => 0x0041, # A
2145                '[CDA' => 0x0054, # T
2146                '[CDAT' => 0x0041, # A
2147              }->{$self->{state_keyword}}) {
2148            !!!cp (135.1);
2149            ## Stay in the state.
2150            $self->{state_keyword} .= chr $self->{next_char};
2151            !!!next-input-character;
2152            redo A;
2153          } elsif ($self->{state_keyword} eq '[CDATA' and
2154                   $self->{next_char} == 0x005B) { # [
2155            !!!cp (135.2);
2156            $self->{current_token} = {type => CHARACTER_TOKEN,
2157                                      data => '',
2158                                      line => $self->{line_prev},
2159                                      column => $self->{column_prev} - 7};
2160            $self->{state} = CDATA_SECTION_STATE;
2161            !!!next-input-character;
2162            redo A;
2163          } else {
2164            !!!cp (135.3);
2165            !!!parse-error (type => 'bogus comment',
2166                            line => $self->{line_prev},
2167                            column => $self->{column_prev} - 1 - length $self->{state_keyword});
2168            $self->{state} = BOGUS_COMMENT_STATE;
2169            ## Reconsume.
2170            $self->{current_token} = {type => COMMENT_TOKEN,
2171                                      data => $self->{state_keyword},
2172                                      line => $self->{line_prev},
2173                                      column => $self->{column_prev} - 1 - length $self->{state_keyword},
2174                                     };
2175            redo A;
2176          }
2177      } elsif ($self->{state} == COMMENT_START_STATE) {      } elsif ($self->{state} == COMMENT_START_STATE) {
2178        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
2179          !!!cp (137);          !!!cp (137);
# Line 2328  sub _get_next_token ($) { Line 2758  sub _get_next_token ($) {
2758          redo A;          redo A;
2759        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2760          !!!cp (208);          !!!cp (208);
2761          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2762    
2763          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2764          !!!next-input-character;          !!!next-input-character;
# Line 2364  sub _get_next_token ($) { Line 2794  sub _get_next_token ($) {
2794          redo A;          redo A;
2795        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2796          !!!cp (212);          !!!cp (212);
2797          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2798    
2799          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2800          !!!next-input-character;          !!!next-input-character;
# Line 2412  sub _get_next_token ($) { Line 2842  sub _get_next_token ($) {
2842        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
2843          !!!cp (217);          !!!cp (217);
2844          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
   
2845          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2846          ## reconsume          ## reconsume
2847    
# Line 2453  sub _get_next_token ($) { Line 2882  sub _get_next_token ($) {
2882          !!!next-input-character;          !!!next-input-character;
2883          redo A;          redo A;
2884        }        }
2885      } elsif ($self->{state} == CDATA_BLOCK_STATE) {      } elsif ($self->{state} == CDATA_SECTION_STATE) {
2886        my $s = '';        ## NOTE: "CDATA section state" in the state is jointly implemented
2887          ## by three states, |CDATA_SECTION_STATE|, |CDATA_SECTION_MSE1_STATE|,
2888          ## and |CDATA_SECTION_MSE2_STATE|.
2889                
2890        my ($l, $c) = ($self->{line}, $self->{column});        if ($self->{next_char} == 0x005D) { # ]
2891            !!!cp (221.1);
2892            $self->{state} = CDATA_SECTION_MSE1_STATE;
2893            !!!next-input-character;
2894            redo A;
2895          } elsif ($self->{next_char} == -1) {
2896            $self->{state} = DATA_STATE;
2897            !!!next-input-character;
2898            if (length $self->{current_token}->{data}) { # character
2899              !!!cp (221.2);
2900              !!!emit ($self->{current_token}); # character
2901            } else {
2902              !!!cp (221.3);
2903              ## No token to emit. $self->{current_token} is discarded.
2904            }        
2905            redo A;
2906          } else {
2907            !!!cp (221.4);
2908            $self->{current_token}->{data} .= chr $self->{next_char};
2909            ## Stay in the state.
2910            !!!next-input-character;
2911            redo A;
2912          }
2913    
2914        CS: while ($self->{next_char} != -1) {        ## ISSUE: "text tokens" in spec.
2915          if ($self->{next_char} == 0x005D) { # ]      } elsif ($self->{state} == CDATA_SECTION_MSE1_STATE) {
2916            !!!next-input-character;        if ($self->{next_char} == 0x005D) { # ]
2917            if ($self->{next_char} == 0x005D) { # ]          !!!cp (221.5);
2918              !!!next-input-character;          $self->{state} = CDATA_SECTION_MSE2_STATE;
2919              MDC: {          !!!next-input-character;
2920                if ($self->{next_char} == 0x003E) { # >          redo A;
2921                  !!!cp (221.1);        } else {
2922                  !!!next-input-character;          !!!cp (221.6);
2923                  last CS;          $self->{current_token}->{data} .= ']';
2924                } elsif ($self->{next_char} == 0x005D) { # ]          $self->{state} = CDATA_SECTION_STATE;
2925                  !!!cp (221.2);          ## Reconsume.
2926                  $s .= ']';          redo A;
2927                  !!!next-input-character;        }
2928                  redo MDC;      } elsif ($self->{state} == CDATA_SECTION_MSE2_STATE) {
2929                } else {        if ($self->{next_char} == 0x003E) { # >
2930                  !!!cp (221.3);          $self->{state} = DATA_STATE;
2931                  $s .= ']]';          !!!next-input-character;
2932                  #          if (length $self->{current_token}->{data}) { # character
2933                }            !!!cp (221.7);
2934              } # MDC            !!!emit ($self->{current_token}); # character
           } else {  
             !!!cp (221.4);  
             $s .= ']';  
             #  
           }  
2935          } else {          } else {
2936            !!!cp (221.5);            !!!cp (221.8);
2937            #            ## No token to emit. $self->{current_token} is discarded.
2938          }          }
2939          $s .= chr $self->{next_char};          redo A;
2940          } elsif ($self->{next_char} == 0x005D) { # ]
2941            !!!cp (221.9); # character
2942            $self->{current_token}->{data} .= ']'; ## Add first "]" of "]]]".
2943            ## Stay in the state.
2944          !!!next-input-character;          !!!next-input-character;
2945        } # 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});  
2946        } else {        } else {
2947          !!!cp (221.7);          !!!cp (221.11);
2948            $self->{current_token}->{data} .= ']]'; # character
2949            $self->{state} = CDATA_SECTION_STATE;
2950            ## Reconsume.
2951            redo A;
2952        }        }
   
       redo A;  
   
       ## ISSUE: "text tokens" in spec.  
       ## TODO: Streaming support  
2953      } else {      } else {
2954        die "$0: $self->{state}: Unknown state";        die "$0: $self->{state}: Unknown state";
2955      }      }
# Line 2574  sub _tokenize_attempt_to_consume_an_enti Line 3017  sub _tokenize_attempt_to_consume_an_enti
3017    
3018          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3019            !!!cp (1008);            !!!cp (1008);
3020            !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
3021                              text => (sprintf 'U+%04X', $code),
3022                              line => $l, column => $c);
3023            $code = 0xFFFD;            $code = 0xFFFD;
3024          } elsif ($code > 0x10FFFF) {          } elsif ($code > 0x10FFFF) {
3025            !!!cp (1009);            !!!cp (1009);
3026            !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
3027                              text => (sprintf 'U-%08X', $code),
3028                              line => $l, column => $c);
3029            $code = 0xFFFD;            $code = 0xFFFD;
3030          } elsif ($code == 0x000D) {          } elsif ($code == 0x000D) {
3031            !!!cp (1010);            !!!cp (1010);
# Line 2586  sub _tokenize_attempt_to_consume_an_enti Line 3033  sub _tokenize_attempt_to_consume_an_enti
3033            $code = 0x000A;            $code = 0x000A;
3034          } elsif (0x80 <= $code and $code <= 0x9F) {          } elsif (0x80 <= $code and $code <= 0x9F) {
3035            !!!cp (1011);            !!!cp (1011);
3036            !!!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);
3037            $code = $c1_entity_char->{$code};            $code = $c1_entity_char->{$code};
3038          }          }
3039    
# Line 2619  sub _tokenize_attempt_to_consume_an_enti Line 3066  sub _tokenize_attempt_to_consume_an_enti
3066    
3067        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3068          !!!cp (1015);          !!!cp (1015);
3069          !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3070                            text => (sprintf 'U+%04X', $code),
3071                            line => $l, column => $c);
3072          $code = 0xFFFD;          $code = 0xFFFD;
3073        } elsif ($code > 0x10FFFF) {        } elsif ($code > 0x10FFFF) {
3074          !!!cp (1016);          !!!cp (1016);
3075          !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3076                            text => (sprintf 'U-%08X', $code),
3077                            line => $l, column => $c);
3078          $code = 0xFFFD;          $code = 0xFFFD;
3079        } elsif ($code == 0x000D) {        } elsif ($code == 0x000D) {
3080          !!!cp (1017);          !!!cp (1017);
3081          !!!parse-error (type => 'CR character reference', line => $l, column => $c);          !!!parse-error (type => 'CR character reference',
3082                            line => $l, column => $c);
3083          $code = 0x000A;          $code = 0x000A;
3084        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
3085          !!!cp (1018);          !!!cp (1018);
3086          !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'C1 character reference',
3087                            text => (sprintf 'U+%04X', $code),
3088                            line => $l, column => $c);
3089          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
3090        }        }
3091                
# Line 2729  sub _initialize_tree_constructor ($) { Line 3183  sub _initialize_tree_constructor ($) {
3183    ## TODO: Turn mutation events off # MUST    ## TODO: Turn mutation events off # MUST
3184    ## TODO: Turn loose Document option (manakai extension) on    ## TODO: Turn loose Document option (manakai extension) on
3185    $self->{document}->manakai_is_html (1); # MUST    $self->{document}->manakai_is_html (1); # MUST
3186      $self->{document}->set_user_data (manakai_source_line => 1);
3187      $self->{document}->set_user_data (manakai_source_column => 1);
3188  } # _initialize_tree_constructor  } # _initialize_tree_constructor
3189    
3190  sub _terminate_tree_constructor ($) {  sub _terminate_tree_constructor ($) {
# Line 2783  sub _tree_construction_initial ($) { Line 3239  sub _tree_construction_initial ($) {
3239        ## language.        ## language.
3240        my $doctype_name = $token->{name};        my $doctype_name = $token->{name};
3241        $doctype_name = '' unless defined $doctype_name;        $doctype_name = '' unless defined $doctype_name;
3242        $doctype_name =~ tr/a-z/A-Z/;        $doctype_name =~ tr/a-z/A-Z/; # ASCII case-insensitive
3243        if (not defined $token->{name} or # <!DOCTYPE>        if (not defined $token->{name} or # <!DOCTYPE>
           defined $token->{public_identifier} or  
3244            defined $token->{system_identifier}) {            defined $token->{system_identifier}) {
3245          !!!cp ('t1');          !!!cp ('t1');
3246          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3247        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
3248          !!!cp ('t2');          !!!cp ('t2');
         ## ISSUE: ASCII case-insensitive? (in fact it does not matter)  
3249          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3250          } elsif (defined $token->{public_identifier}) {
3251            if ($token->{public_identifier} eq 'XSLT-compat') {
3252              !!!cp ('t1.2');
3253              !!!parse-error (type => 'XSLT-compat', token => $token,
3254                              level => $self->{level}->{should});
3255            } else {
3256              !!!parse-error (type => 'not HTML5', token => $token);
3257            }
3258        } else {        } else {
3259          !!!cp ('t3');          !!!cp ('t3');
3260            #
3261        }        }
3262                
3263        my $doctype = $self->{document}->create_document_type_definition        my $doctype = $self->{document}->create_document_type_definition
# Line 2815  sub _tree_construction_initial ($) { Line 3278  sub _tree_construction_initial ($) {
3278        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{public_identifier}) {
3279          my $pubid = $token->{public_identifier};          my $pubid = $token->{public_identifier};
3280          $pubid =~ tr/a-z/A-z/;          $pubid =~ tr/a-z/A-z/;
3281          if ({          my $prefix = [
3282            "+//SILMARIL//DTD HTML PRO V0R11 19970101//EN" => 1,            "+//SILMARIL//DTD HTML PRO V0R11 19970101//",
3283            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3284            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3285            "-//IETF//DTD HTML 2.0 LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 1//",
3286            "-//IETF//DTD HTML 2.0 LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 2//",
3287            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//",
3288            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//",
3289            "-//IETF//DTD HTML 2.0 STRICT//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT//",
3290            "-//IETF//DTD HTML 2.0//EN" => 1,            "-//IETF//DTD HTML 2.0//",
3291            "-//IETF//DTD HTML 2.1E//EN" => 1,            "-//IETF//DTD HTML 2.1E//",
3292            "-//IETF//DTD HTML 3.0//EN" => 1,            "-//IETF//DTD HTML 3.0//",
3293            "-//IETF//DTD HTML 3.0//EN//" => 1,            "-//IETF//DTD HTML 3.2 FINAL//",
3294            "-//IETF//DTD HTML 3.2 FINAL//EN" => 1,            "-//IETF//DTD HTML 3.2//",
3295            "-//IETF//DTD HTML 3.2//EN" => 1,            "-//IETF//DTD HTML 3//",
3296            "-//IETF//DTD HTML 3//EN" => 1,            "-//IETF//DTD HTML LEVEL 0//",
3297            "-//IETF//DTD HTML LEVEL 0//EN" => 1,            "-//IETF//DTD HTML LEVEL 1//",
3298            "-//IETF//DTD HTML LEVEL 0//EN//2.0" => 1,            "-//IETF//DTD HTML LEVEL 2//",
3299            "-//IETF//DTD HTML LEVEL 1//EN" => 1,            "-//IETF//DTD HTML LEVEL 3//",
3300            "-//IETF//DTD HTML LEVEL 1//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 0//",
3301            "-//IETF//DTD HTML LEVEL 2//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 1//",
3302            "-//IETF//DTD HTML LEVEL 2//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 2//",
3303            "-//IETF//DTD HTML LEVEL 3//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 3//",
3304            "-//IETF//DTD HTML LEVEL 3//EN//3.0" => 1,            "-//IETF//DTD HTML STRICT//",
3305            "-//IETF//DTD HTML STRICT LEVEL 0//EN" => 1,            "-//IETF//DTD HTML//",
3306            "-//IETF//DTD HTML STRICT LEVEL 0//EN//2.0" => 1,            "-//METRIUS//DTD METRIUS PRESENTATIONAL//",
3307            "-//IETF//DTD HTML STRICT LEVEL 1//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//",
3308            "-//IETF//DTD HTML STRICT LEVEL 1//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//",
3309            "-//IETF//DTD HTML STRICT LEVEL 2//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//",
3310            "-//IETF//DTD HTML STRICT LEVEL 2//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//",
3311            "-//IETF//DTD HTML STRICT LEVEL 3//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//",
3312            "-//IETF//DTD HTML STRICT LEVEL 3//EN//3.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//",
3313            "-//IETF//DTD HTML STRICT//EN" => 1,            "-//NETSCAPE COMM. CORP.//DTD HTML//",
3314            "-//IETF//DTD HTML STRICT//EN//2.0" => 1,            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//",
3315            "-//IETF//DTD HTML STRICT//EN//3.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//",
3316            "-//IETF//DTD HTML//EN" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//",
3317            "-//IETF//DTD HTML//EN//2.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//",
3318            "-//IETF//DTD HTML//EN//3.0" => 1,            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//",
3319            "-//METRIUS//DTD METRIUS PRESENTATIONAL//EN" => 1,            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//",
3320            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//EN" => 1,            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//",
3321            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//EN" => 1,            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//",
3322            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//",
3323            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//",
3324            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//EN" => 1,            "-//W3C//DTD HTML 3 1995-03-24//",
3325            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//EN" => 1,            "-//W3C//DTD HTML 3.2 DRAFT//",
3326            "-//NETSCAPE COMM. CORP.//DTD HTML//EN" => 1,            "-//W3C//DTD HTML 3.2 FINAL//",
3327            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//EN" => 1,            "-//W3C//DTD HTML 3.2//",
3328            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//EN" => 1,            "-//W3C//DTD HTML 3.2S DRAFT//",
3329            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 FRAMESET//",
3330            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 TRANSITIONAL//",
3331            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMETNAL 19960712//",
3332            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMENTAL 970421//",
3333            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//EN" => 1,            "-//W3C//DTD W3 HTML//",
3334            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//EN" => 1,            "-//W3O//DTD W3 HTML 3.0//",
3335            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML 2.0//",
3336            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML//",
3337            "-//W3C//DTD HTML 3 1995-03-24//EN" => 1,          ]; # $prefix
3338            "-//W3C//DTD HTML 3.2 DRAFT//EN" => 1,          my $match;
3339            "-//W3C//DTD HTML 3.2 FINAL//EN" => 1,          for (@$prefix) {
3340            "-//W3C//DTD HTML 3.2//EN" => 1,            if (substr ($prefix, 0, length $_) eq $_) {
3341            "-//W3C//DTD HTML 3.2S DRAFT//EN" => 1,              $match = 1;
3342            "-//W3C//DTD HTML 4.0 FRAMESET//EN" => 1,              last;
3343            "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN" => 1,            }
3344            "-//W3C//DTD HTML EXPERIMETNAL 19960712//EN" => 1,          }
3345            "-//W3C//DTD HTML EXPERIMENTAL 970421//EN" => 1,          if ($match or
3346            "-//W3C//DTD W3 HTML//EN" => 1,              $pubid eq "-//W3O//DTD W3 HTML STRICT 3.0//EN//" or
3347            "-//W3O//DTD W3 HTML 3.0//EN" => 1,              $pubid eq "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" or
3348            "-//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}) {  
3349            !!!cp ('t5');            !!!cp ('t5');
3350            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3351          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD HTML 4.01 FRAMESET//] or
3352                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD HTML 4.01 TRANSITIONAL//]) {
3353            if (defined $token->{system_identifier}) {            if (defined $token->{system_identifier}) {
3354              !!!cp ('t6');              !!!cp ('t6');
3355              $self->{document}->manakai_compat_mode ('quirks');              $self->{document}->manakai_compat_mode ('quirks');
# Line 2900  sub _tree_construction_initial ($) { Line 3357  sub _tree_construction_initial ($) {
3357              !!!cp ('t7');              !!!cp ('t7');
3358              $self->{document}->manakai_compat_mode ('limited quirks');              $self->{document}->manakai_compat_mode ('limited quirks');
3359            }            }
3360          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD XHTML 1.0 FRAMESET//] or
3361                   $pubid eq "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD XHTML 1.0 TRANSITIONAL//]) {
3362            !!!cp ('t8');            !!!cp ('t8');
3363            $self->{document}->manakai_compat_mode ('limited quirks');            $self->{document}->manakai_compat_mode ('limited quirks');
3364          } else {          } else {
# Line 2914  sub _tree_construction_initial ($) { Line 3371  sub _tree_construction_initial ($) {
3371          my $sysid = $token->{system_identifier};          my $sysid = $token->{system_identifier};
3372          $sysid =~ tr/A-Z/a-z/;          $sysid =~ tr/A-Z/a-z/;
3373          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") {
3374            ## TODO: Check the spec: PUBLIC "(limited quirks)" "(quirks)"            ## NOTE: Ensure that |PUBLIC "(limited quirks)" "(quirks)"| is
3375              ## marked as quirks.
3376            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3377            !!!cp ('t11');            !!!cp ('t11');
3378          } else {          } else {
# Line 3086  sub _reset_insertion_mode ($) { Line 3544  sub _reset_insertion_mode ($) {
3544        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
3545          $last = 1;          $last = 1;
3546          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
3547            if ($self->{inner_html_node}->[1] & TABLE_CELL_EL) {            !!!cp ('t28');
3548              !!!cp ('t27');            $node = $self->{inner_html_node};
3549              #          } else {
3550            } else {            die "_reset_insertion_mode: t27";
             !!!cp ('t28');  
             $node = $self->{inner_html_node};  
           }  
3551          }          }
3552        }        }
3553              
3554      ## Step 4..14        ## Step 4..14
3555      my $new_mode;        my $new_mode;
3556      if ($node->[1] & FOREIGN_EL) {        if ($node->[1] & FOREIGN_EL) {
3557        ## NOTE: Strictly spaking, the line below only applies to MathML and          !!!cp ('t28.1');
3558        ## SVG elements.  Currently the HTML syntax supports only MathML and          ## NOTE: Strictly spaking, the line below only applies to MathML and
3559        ## SVG elements as foreigners.          ## SVG elements.  Currently the HTML syntax supports only MathML and
3560        $new_mode = $self->{insertion_mode} | IN_FOREIGN_CONTENT_IM;          ## SVG elements as foreigners.
3561        ## ISSUE: What is set as the secondary insertion mode?          $new_mode = IN_BODY_IM | IN_FOREIGN_CONTENT_IM;
3562      } else {        } elsif ($node->[1] & TABLE_CELL_EL) {
3563        $new_mode = {          if ($last) {
3564              !!!cp ('t28.2');
3565              #
3566            } else {
3567              !!!cp ('t28.3');
3568              $new_mode = IN_CELL_IM;
3569            }
3570          } else {
3571            !!!cp ('t28.4');
3572            $new_mode = {
3573                        select => IN_SELECT_IM,                        select => IN_SELECT_IM,
3574                        ## NOTE: |option| and |optgroup| do not set                        ## NOTE: |option| and |optgroup| do not set
3575                        ## insertion mode to "in select" by themselves.                        ## insertion mode to "in select" by themselves.
                       td => IN_CELL_IM,  
                       th => IN_CELL_IM,  
3576                        tr => IN_ROW_IM,                        tr => IN_ROW_IM,
3577                        tbody => IN_TABLE_BODY_IM,                        tbody => IN_TABLE_BODY_IM,
3578                        thead => IN_TABLE_BODY_IM,                        thead => IN_TABLE_BODY_IM,
# Line 3122  sub _reset_insertion_mode ($) { Line 3584  sub _reset_insertion_mode ($) {
3584                        body => IN_BODY_IM,                        body => IN_BODY_IM,
3585                        frameset => IN_FRAMESET_IM,                        frameset => IN_FRAMESET_IM,
3586                       }->{$node->[0]->manakai_local_name};                       }->{$node->[0]->manakai_local_name};
3587      }        }
3588      $self->{insertion_mode} = $new_mode and return if defined $new_mode;        $self->{insertion_mode} = $new_mode and return if defined $new_mode;
3589                
3590        ## Step 15        ## Step 15
3591        if ($node->[1] & HTML_EL) {        if ($node->[1] & HTML_EL) {
# Line 3297  sub _tree_construction_main ($) { Line 3759  sub _tree_construction_main ($) {
3759        ## NOTE: An end-of-file token.        ## NOTE: An end-of-file token.
3760        if ($content_model_flag == CDATA_CONTENT_MODEL) {        if ($content_model_flag == CDATA_CONTENT_MODEL) {
3761          !!!cp ('t43');          !!!cp ('t43');
3762          !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in CDATA:#eof', token => $token);
3763        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
3764          !!!cp ('t44');          !!!cp ('t44');
3765          !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in RCDATA:#eof', token => $token);
3766        } else {        } else {
3767          die "$0: $content_model_flag in parse_rcdata";          die "$0: $content_model_flag in parse_rcdata";
3768        }        }
# Line 3337  sub _tree_construction_main ($) { Line 3799  sub _tree_construction_main ($) {
3799        ## Ignore the token        ## Ignore the token
3800      } else {      } else {
3801        !!!cp ('t48');        !!!cp ('t48');
3802        !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);        !!!parse-error (type => 'in CDATA:#eof', token => $token);
3803        ## ISSUE: And ignore?        ## ISSUE: And ignore?
3804        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
3805      }      }
# Line 3388  sub _tree_construction_main ($) { Line 3850  sub _tree_construction_main ($) {
3850        } # AFE        } # AFE
3851        unless (defined $formatting_element) {        unless (defined $formatting_element) {
3852          !!!cp ('t53');          !!!cp ('t53');
3853          !!!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);
3854          ## Ignore the token          ## Ignore the token
3855          !!!next-token;          !!!next-token;
3856          return;          return;
# Line 3405  sub _tree_construction_main ($) { Line 3867  sub _tree_construction_main ($) {
3867              last INSCOPE;              last INSCOPE;
3868            } else { # in open elements but not in scope            } else { # in open elements but not in scope
3869              !!!cp ('t55');              !!!cp ('t55');
3870              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},              !!!parse-error (type => 'unmatched end tag',
3871                                text => $token->{tag_name},
3872                              token => $end_tag_token);                              token => $end_tag_token);
3873              ## Ignore the token              ## Ignore the token
3874              !!!next-token;              !!!next-token;
# Line 3418  sub _tree_construction_main ($) { Line 3881  sub _tree_construction_main ($) {
3881        } # INSCOPE        } # INSCOPE
3882        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
3883          !!!cp ('t57');          !!!cp ('t57');
3884          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},          !!!parse-error (type => 'unmatched end tag',
3885                            text => $token->{tag_name},
3886                          token => $end_tag_token);                          token => $end_tag_token);
3887          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
3888          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
# Line 3427  sub _tree_construction_main ($) { Line 3891  sub _tree_construction_main ($) {
3891        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
3892          !!!cp ('t58');          !!!cp ('t58');
3893          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
3894                          value => $self->{open_elements}->[-1]->[0]                          text => $self->{open_elements}->[-1]->[0]
3895                              ->manakai_local_name,                              ->manakai_local_name,
3896                          token => $end_tag_token);                          token => $end_tag_token);
3897        }        }
# Line 3636  sub _tree_construction_main ($) { Line 4100  sub _tree_construction_main ($) {
4100    B: while (1) {    B: while (1) {
4101      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
4102        !!!cp ('t73');        !!!cp ('t73');
4103        !!!parse-error (type => 'DOCTYPE in the middle', token => $token);        !!!parse-error (type => 'in html:#DOCTYPE', token => $token);
4104        ## Ignore the token        ## Ignore the token
4105        ## Stay in the phase        ## Stay in the phase
4106        !!!next-token;        !!!next-token;
# Line 3645  sub _tree_construction_main ($) { Line 4109  sub _tree_construction_main ($) {
4109               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
4110        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
4111          !!!cp ('t79');          !!!cp ('t79');
4112          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4113          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
4114        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
4115          !!!cp ('t80');          !!!cp ('t80');
4116          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4117          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
4118        } else {        } else {
4119          !!!cp ('t81');          !!!cp ('t81');
# Line 3690  sub _tree_construction_main ($) { Line 4154  sub _tree_construction_main ($) {
4154          !!!next-token;          !!!next-token;
4155          next B;          next B;
4156        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
4157          if ($self->{open_elements}->[-1]->[1] & FOREIGN_FLOW_CONTENT_EL or          if ((not {mglyph => 1, malignmark => 1}->{$token->{tag_name}} and
4158                 $self->{open_elements}->[-1]->[1] & FOREIGN_FLOW_CONTENT_EL) or
4159              not ($self->{open_elements}->[-1]->[1] & FOREIGN_EL) or              not ($self->{open_elements}->[-1]->[1] & FOREIGN_EL) or
4160              ($token->{tag_name} eq 'svg' and              ($token->{tag_name} eq 'svg' and
4161               $self->{open_elements}->[-1]->[1] & MML_AXML_EL)) {               $self->{open_elements}->[-1]->[1] & MML_AXML_EL)) {
# Line 3698  sub _tree_construction_main ($) { Line 4163  sub _tree_construction_main ($) {
4163            !!!cp ('t87.2');            !!!cp ('t87.2');
4164            #            #
4165          } elsif ({          } elsif ({
4166    ## TODO:                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,
4167                      center => 1, code => 1, dd => 1, div => 1, dl => 1, dt => 1,
4168                      em => 1, embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1,
4169                      h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, i => 1,
4170                      img => 1, li => 1, listing => 1, menu => 1, meta => 1,
4171                      nobr => 1, ol => 1, p => 1, pre => 1, ruby => 1, s => 1,
4172                      small => 1, span => 1, strong => 1, strike => 1, sub => 1,
4173                      sup => 1, table => 1, tt => 1, u => 1, ul => 1, var => 1,
4174                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
4175            !!!cp ('t87.2');            !!!cp ('t87.2');
4176            !!!parse-error (type => 'not closed',            !!!parse-error (type => 'not closed',
4177                            value => $self->{open_elements}->[-1]->[0]                            text => $self->{open_elements}->[-1]->[0]
4178                                ->manakai_local_name,                                ->manakai_local_name,
4179                            token => $token);                            token => $token);
4180    
4181            pop @{$self->{open_elements}}            pop @{$self->{open_elements}}
4182                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;
4183    
4184            $self->{insertion_mode} &= ~ $self->{insertion_mode};            $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
4185            ## Reprocess.            ## Reprocess.
4186            next B;            next B;
4187          } else {          } else {
4188            ## TODO: case fixup            my $nsuri = $self->{open_elements}->[-1]->[0]->namespace_uri;
4189              my $tag_name = $token->{tag_name};
4190              if ($nsuri eq $SVG_NS) {
4191                $tag_name = {
4192                   altglyph => 'altGlyph',
4193                   altglyphdef => 'altGlyphDef',
4194                   altglyphitem => 'altGlyphItem',
4195                   animatecolor => 'animateColor',
4196                   animatemotion => 'animateMotion',
4197                   animatetransform => 'animateTransform',
4198                   clippath => 'clipPath',
4199                   feblend => 'feBlend',
4200                   fecolormatrix => 'feColorMatrix',
4201                   fecomponenttransfer => 'feComponentTransfer',
4202                   fecomposite => 'feComposite',
4203                   feconvolvematrix => 'feConvolveMatrix',
4204                   fediffuselighting => 'feDiffuseLighting',
4205                   fedisplacementmap => 'feDisplacementMap',
4206                   fedistantlight => 'feDistantLight',
4207                   feflood => 'feFlood',
4208                   fefunca => 'feFuncA',
4209                   fefuncb => 'feFuncB',
4210                   fefuncg => 'feFuncG',
4211                   fefuncr => 'feFuncR',
4212                   fegaussianblur => 'feGaussianBlur',
4213                   feimage => 'feImage',
4214                   femerge => 'feMerge',
4215                   femergenode => 'feMergeNode',
4216                   femorphology => 'feMorphology',
4217                   feoffset => 'feOffset',
4218                   fepointlight => 'fePointLight',
4219                   fespecularlighting => 'feSpecularLighting',
4220                   fespotlight => 'feSpotLight',
4221                   fetile => 'feTile',
4222                   feturbulence => 'feTurbulence',
4223                   foreignobject => 'foreignObject',
4224                   glyphref => 'glyphRef',
4225                   lineargradient => 'linearGradient',
4226                   radialgradient => 'radialGradient',
4227                   #solidcolor => 'solidColor', ## NOTE: Commented in spec (SVG1.2)
4228                   textpath => 'textPath',  
4229                }->{$tag_name} || $tag_name;
4230              }
4231    
4232              ## "adjust SVG attributes" (SVG only) - done in insert-element-f
4233    
4234            !!!insert-element-f ($self->{open_elements}->[-1]->[0]->namespace_uri, $token);            ## "adjust foreign attributes" - done in insert-element-f
4235    
4236              !!!insert-element-f ($nsuri, $tag_name, $token->{attributes}, $token);
4237    
4238            if ($self->{self_closing}) {            if ($self->{self_closing}) {
4239              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
# Line 3732  sub _tree_construction_main ($) { Line 4250  sub _tree_construction_main ($) {
4250          !!!cp ('t87.5');          !!!cp ('t87.5');
4251          #          #
4252        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
         ## NOTE: "using the rules for secondary insertion mode" then "continue"  
4253          !!!cp ('t87.6');          !!!cp ('t87.6');
4254          #          !!!parse-error (type => 'not closed',
4255          ## TODO: ...                          text => $self->{open_elements}->[-1]->[0]
4256                                ->manakai_local_name,
4257                            token => $token);
4258    
4259            pop @{$self->{open_elements}}
4260                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;
4261    
4262            $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
4263            ## Reprocess.
4264            next B;
4265        } else {        } else {
4266          die "$0: $token->{type}: Unknown token type";                  die "$0: $token->{type}: Unknown token type";        
4267        }        }
# Line 3776  sub _tree_construction_main ($) { Line 4302  sub _tree_construction_main ($) {
4302            !!!cp ('t90');            !!!cp ('t90');
4303            ## As if </noscript>            ## As if </noscript>
4304            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
4305            !!!parse-error (type => 'in noscript:#character', token => $token);            !!!parse-error (type => 'in noscript:#text', token => $token);
4306                        
4307            ## Reprocess in the "in head" insertion mode...            ## Reprocess in the "in head" insertion mode...
4308            ## As if </head>            ## As if </head>
# Line 3812  sub _tree_construction_main ($) { Line 4338  sub _tree_construction_main ($) {
4338              !!!next-token;              !!!next-token;
4339              next B;              next B;
4340            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4341              !!!cp ('t94');              !!!cp ('t93.2');
4342              #              !!!parse-error (type => 'after head', text => 'head',
4343                                token => $token);
4344                ## Ignore the token
4345                !!!nack ('t93.3');
4346                !!!next-token;
4347                next B;
4348            } else {            } else {
4349              !!!cp ('t95');              !!!cp ('t95');
4350              !!!parse-error (type => 'in head:head', token => $token); # or in head noscript              !!!parse-error (type => 'in head:head',
4351                                token => $token); # or in head noscript
4352              ## Ignore the token              ## Ignore the token
4353              !!!nack ('t95.1');              !!!nack ('t95.1');
4354              !!!next-token;              !!!next-token;
# Line 3841  sub _tree_construction_main ($) { Line 4373  sub _tree_construction_main ($) {
4373                  !!!cp ('t98');                  !!!cp ('t98');
4374                  ## As if </noscript>                  ## As if </noscript>
4375                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4376                  !!!parse-error (type => 'in noscript:base', token => $token);                  !!!parse-error (type => 'in noscript', text => 'base',
4377                                    token => $token);
4378                                
4379                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4380                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
# Line 3852  sub _tree_construction_main ($) { Line 4385  sub _tree_construction_main ($) {
4385                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4386                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4387                  !!!cp ('t100');                  !!!cp ('t100');
4388                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4389                                    text => $token->{tag_name}, token => $token);
4390                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4391                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4392                } else {                } else {
# Line 3869  sub _tree_construction_main ($) { Line 4403  sub _tree_construction_main ($) {
4403                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4404                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4405                  !!!cp ('t102');                  !!!cp ('t102');
4406                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4407                                    text => $token->{tag_name}, token => $token);
4408                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4409                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4410                } else {                } else {
# Line 3886  sub _tree_construction_main ($) { Line 4421  sub _tree_construction_main ($) {
4421                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4422                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4423                  !!!cp ('t104');                  !!!cp ('t104');
4424                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4425                                    text => $token->{tag_name}, token => $token);
4426                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4427                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4428                } else {                } else {
# Line 3896  sub _tree_construction_main ($) { Line 4432  sub _tree_construction_main ($) {
4432                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.
4433    
4434                unless ($self->{confident}) {                unless ($self->{confident}) {
4435                  if ($token->{attributes}->{charset}) { ## TODO: And if supported                  if ($token->{attributes}->{charset}) {
4436                    !!!cp ('t106');                    !!!cp ('t106');
4437                      ## NOTE: Whether the encoding is supported or not is handled
4438                      ## in the {change_encoding} callback.
4439                    $self->{change_encoding}                    $self->{change_encoding}
4440                        ->($self, $token->{attributes}->{charset}->{value},                        ->($self, $token->{attributes}->{charset}->{value},
4441                           $token);                           $token);
# Line 3907  sub _tree_construction_main ($) { Line 4445  sub _tree_construction_main ($) {
4445                                             $token->{attributes}->{charset}                                             $token->{attributes}->{charset}
4446                                                 ->{has_reference});                                                 ->{has_reference});
4447                  } elsif ($token->{attributes}->{content}) {                  } elsif ($token->{attributes}->{content}) {
                   ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.  
4448                    if ($token->{attributes}->{content}->{value}                    if ($token->{attributes}->{content}->{value}
4449                        =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                        =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
4450                            [\x09-\x0D\x20]*=                            [\x09-\x0D\x20]*=
4451                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
4452                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
4453                      !!!cp ('t107');                      !!!cp ('t107');
4454                        ## NOTE: Whether the encoding is supported or not is handled
4455                        ## in the {change_encoding} callback.
4456                      $self->{change_encoding}                      $self->{change_encoding}
4457                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3,                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3,
4458                             $token);                             $token);
# Line 3952  sub _tree_construction_main ($) { Line 4491  sub _tree_construction_main ($) {
4491                  !!!cp ('t111');                  !!!cp ('t111');
4492                  ## As if </noscript>                  ## As if </noscript>
4493                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4494                  !!!parse-error (type => 'in noscript:title', token => $token);                  !!!parse-error (type => 'in noscript', text => 'title',
4495                                    token => $token);
4496                                
4497                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4498                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4499                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4500                  !!!cp ('t112');                  !!!cp ('t112');
4501                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4502                                    text => $token->{tag_name}, token => $token);
4503                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4504                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4505                } else {                } else {
# Line 3972  sub _tree_construction_main ($) { Line 4513  sub _tree_construction_main ($) {
4513                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4514                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4515                next B;                next B;
4516              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style' or
4517                         $token->{tag_name} eq 'noframes') {
4518                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and
4519                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
4520                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4521                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4522                  !!!cp ('t114');                  !!!cp ('t114');
4523                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4524                                    text => $token->{tag_name}, token => $token);
4525                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4526                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4527                } else {                } else {
# Line 3999  sub _tree_construction_main ($) { Line 4542  sub _tree_construction_main ($) {
4542                  next B;                  next B;
4543                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4544                  !!!cp ('t117');                  !!!cp ('t117');
4545                  !!!parse-error (type => 'in noscript:noscript', token => $token);                  !!!parse-error (type => 'in noscript', text => 'noscript',
4546                                    token => $token);
4547                  ## Ignore the token                  ## Ignore the token
4548                  !!!nack ('t117.1');                  !!!nack ('t117.1');
4549                  !!!next-token;                  !!!next-token;
# Line 4013  sub _tree_construction_main ($) { Line 4557  sub _tree_construction_main ($) {
4557                  !!!cp ('t119');                  !!!cp ('t119');
4558                  ## As if </noscript>                  ## As if </noscript>
4559                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4560                  !!!parse-error (type => 'in noscript:script', token => $token);                  !!!parse-error (type => 'in noscript', text => 'script',
4561                                    token => $token);
4562                                
4563                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4564                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4565                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4566                  !!!cp ('t120');                  !!!cp ('t120');
4567                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4568                                    text => $token->{tag_name}, token => $token);
4569                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4570                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4571                } else {                } else {
# Line 4037  sub _tree_construction_main ($) { Line 4583  sub _tree_construction_main ($) {
4583                  !!!cp ('t122');                  !!!cp ('t122');
4584                  ## As if </noscript>                  ## As if </noscript>
4585                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4586                  !!!parse-error (type => 'in noscript:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in noscript',
4587                                    text => $token->{tag_name}, token => $token);
4588                                    
4589                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4590                  ## As if </head>                  ## As if </head>
# Line 4076  sub _tree_construction_main ($) { Line 4623  sub _tree_construction_main ($) {
4623                !!!cp ('t129');                !!!cp ('t129');
4624                ## As if </noscript>                ## As if </noscript>
4625                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4626                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4627                                  text => $token->{tag_name}, token => $token);
4628                                
4629                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4630                ## As if </head>                ## As if </head>
# Line 4119  sub _tree_construction_main ($) { Line 4667  sub _tree_construction_main ($) {
4667                  !!!cp ('t133');                  !!!cp ('t133');
4668                  ## As if </noscript>                  ## As if </noscript>
4669                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4670                  !!!parse-error (type => 'in noscript:/head', token => $token);                  !!!parse-error (type => 'in noscript:/',
4671                                    text => 'head', token => $token);
4672                                    
4673                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4674                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 4132  sub _tree_construction_main ($) { Line 4681  sub _tree_construction_main ($) {
4681                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
4682                  !!!next-token;                  !!!next-token;
4683                  next B;                  next B;
4684                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4685                    !!!cp ('t134.1');
4686                    !!!parse-error (type => 'unmatched end tag', text => 'head',
4687                                    token => $token);
4688                    ## Ignore the token
4689                    !!!next-token;
4690                    next B;
4691                } else {                } else {
4692                  !!!cp ('t135');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
                 #  
4693                }                }
4694              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
4695                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
# Line 4143  sub _tree_construction_main ($) { Line 4698  sub _tree_construction_main ($) {
4698                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4699                  !!!next-token;                  !!!next-token;
4700                  next B;                  next B;
4701                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or
4702                           $self->{insertion_mode} == AFTER_HEAD_IM) {
4703                  !!!cp ('t137');                  !!!cp ('t137');
4704                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4705                                    text => 'noscript', token => $token);
4706                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
4707                  !!!next-token;                  !!!next-token;
4708                  next B;                  next B;
# Line 4156  sub _tree_construction_main ($) { Line 4713  sub _tree_construction_main ($) {
4713              } elsif ({              } elsif ({
4714                        body => 1, html => 1,                        body => 1, html => 1,
4715                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4716                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM or
4717                  !!!cp ('t139');                    $self->{insertion_mode} == IN_HEAD_IM or
4718                  ## 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) {  
4719                  !!!cp ('t140');                  !!!cp ('t140');
4720                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4721                                    text => $token->{tag_name}, token => $token);
4722                    ## Ignore the token
4723                    !!!next-token;
4724                    next B;
4725                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4726                    !!!cp ('t140.1');
4727                    !!!parse-error (type => 'unmatched end tag',
4728                                    text => $token->{tag_name}, token => $token);
4729                  ## Ignore the token                  ## Ignore the token
4730                  !!!next-token;                  !!!next-token;
4731                  next B;                  next B;
4732                } else {                } else {
4733                  !!!cp ('t141');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
4734                }                }
4735                              } elsif ($token->{tag_name} eq 'p') {
4736                #                !!!cp ('t142');
4737              } elsif ({                !!!parse-error (type => 'unmatched end tag',
4738                        p => 1, br => 1,                                text => $token->{tag_name}, token => $token);
4739                       }->{$token->{tag_name}}) {                ## Ignore the token
4740                  !!!next-token;
4741                  next B;
4742                } elsif ($token->{tag_name} eq 'br') {
4743                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4744                  !!!cp ('t142');                  !!!cp ('t142.2');
4745                  ## As if <head>                  ## (before head) as if <head>, (in head) as if </head>
4746                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
4747                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
4748                  push @{$self->{open_elements}},                  $self->{insertion_mode} = AFTER_HEAD_IM;
4749                      [$self->{head_element}, $el_category->{head}];    
4750                    ## Reprocess in the "after head" insertion mode...
4751                  } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
4752                    !!!cp ('t143.2');
4753                    ## As if </head>
4754                    pop @{$self->{open_elements}};
4755                    $self->{insertion_mode} = AFTER_HEAD_IM;
4756      
4757                    ## Reprocess in the "after head" insertion mode...
4758                  } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4759                    !!!cp ('t143.3');
4760                    ## ISSUE: Two parse errors for <head><noscript></br>
4761                    !!!parse-error (type => 'unmatched end tag',
4762                                    text => 'br', token => $token);
4763                    ## As if </noscript>
4764                    pop @{$self->{open_elements}};
4765                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4766    
4767                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4768                } else {                  ## As if </head>
4769                  !!!cp ('t143');                  pop @{$self->{open_elements}};
4770                }                  $self->{insertion_mode} = AFTER_HEAD_IM;
4771    
4772                #                  ## Reprocess in the "after head" insertion mode...
4773              } else {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4774                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                  !!!cp ('t143.4');
                 !!!cp ('t144');  
4775                  #                  #
4776                } else {                } else {
4777                  !!!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;  
4778                }                }
4779    
4780                  ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.
4781                  !!!parse-error (type => 'unmatched end tag',
4782                                  text => 'br', token => $token);
4783                  ## Ignore the token
4784                  !!!next-token;
4785                  next B;
4786                } else {
4787                  !!!cp ('t145');
4788                  !!!parse-error (type => 'unmatched end tag',
4789                                  text => $token->{tag_name}, token => $token);
4790                  ## Ignore the token
4791                  !!!next-token;
4792                  next B;
4793              }              }
4794    
4795              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4796                !!!cp ('t146');                !!!cp ('t146');
4797                ## As if </noscript>                ## As if </noscript>
4798                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4799                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4800                                  text => $token->{tag_name}, token => $token);
4801                                
4802                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4803                ## As if </head>                ## As if </head>
# Line 4228  sub _tree_construction_main ($) { Line 4813  sub _tree_construction_main ($) {
4813              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4814  ## ISSUE: This case cannot be reached?  ## ISSUE: This case cannot be reached?
4815                !!!cp ('t148');                !!!cp ('t148');
4816                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
4817                                  text => $token->{tag_name}, token => $token);
4818                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
4819                !!!next-token;                !!!next-token;
4820                next B;                next B;
# Line 4339  sub _tree_construction_main ($) { Line 4925  sub _tree_construction_main ($) {
4925    
4926                  !!!cp ('t153');                  !!!cp ('t153');
4927                  !!!parse-error (type => 'start tag not allowed',                  !!!parse-error (type => 'start tag not allowed',
4928                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
4929                  ## Ignore the token                  ## Ignore the token
4930                  !!!nack ('t153.1');                  !!!nack ('t153.1');
4931                  !!!next-token;                  !!!next-token;
4932                  next B;                  next B;
4933                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4934                  !!!parse-error (type => 'not closed:caption', token => $token);                  !!!parse-error (type => 'not closed', text => 'caption',
4935                                    token => $token);
4936                                    
4937                  ## NOTE: As if </caption>.                  ## NOTE: As if </caption>.
4938                  ## have a table element in table scope                  ## have a table element in table scope
# Line 4365  sub _tree_construction_main ($) { Line 4952  sub _tree_construction_main ($) {
4952    
4953                    !!!cp ('t157');                    !!!cp ('t157');
4954                    !!!parse-error (type => 'start tag not allowed',                    !!!parse-error (type => 'start tag not allowed',
4955                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
4956                    ## Ignore the token                    ## Ignore the token
4957                    !!!nack ('t157.1');                    !!!nack ('t157.1');
4958                    !!!next-token;                    !!!next-token;
# Line 4382  sub _tree_construction_main ($) { Line 4969  sub _tree_construction_main ($) {
4969                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
4970                    !!!cp ('t159');                    !!!cp ('t159');
4971                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
4972                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
4973                                        ->manakai_local_name,                                        ->manakai_local_name,
4974                                    token => $token);                                    token => $token);
4975                  } else {                  } else {
# Line 4424  sub _tree_construction_main ($) { Line 5011  sub _tree_construction_main ($) {
5011                  } # INSCOPE                  } # INSCOPE
5012                    unless (defined $i) {                    unless (defined $i) {
5013                      !!!cp ('t165');                      !!!cp ('t165');
5014                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5015                                        text => $token->{tag_name},
5016                                        token => $token);
5017                      ## Ignore the token                      ## Ignore the token
5018                      !!!next-token;                      !!!next-token;
5019                      next B;                      next B;
# Line 4441  sub _tree_construction_main ($) { Line 5030  sub _tree_construction_main ($) {
5030                          ne $token->{tag_name}) {                          ne $token->{tag_name}) {
5031                    !!!cp ('t167');                    !!!cp ('t167');
5032                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5033                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5034                                        ->manakai_local_name,                                        ->manakai_local_name,
5035                                    token => $token);                                    token => $token);
5036                  } else {                  } else {
# Line 4458  sub _tree_construction_main ($) { Line 5047  sub _tree_construction_main ($) {
5047                  next B;                  next B;
5048                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
5049                  !!!cp ('t169');                  !!!cp ('t169');
5050                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5051                                    text => $token->{tag_name}, token => $token);
5052                  ## Ignore the token                  ## Ignore the token
5053                  !!!next-token;                  !!!next-token;
5054                  next B;                  next B;
# Line 4485  sub _tree_construction_main ($) { Line 5075  sub _tree_construction_main ($) {
5075    
5076                    !!!cp ('t173');                    !!!cp ('t173');
5077                    !!!parse-error (type => 'unmatched end tag',                    !!!parse-error (type => 'unmatched end tag',
5078                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
5079                    ## Ignore the token                    ## Ignore the token
5080                    !!!next-token;                    !!!next-token;
5081                    next B;                    next B;
# Line 4501  sub _tree_construction_main ($) { Line 5091  sub _tree_construction_main ($) {
5091                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5092                    !!!cp ('t175');                    !!!cp ('t175');
5093                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5094                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5095                                        ->manakai_local_name,                                        ->manakai_local_name,
5096                                    token => $token);                                    token => $token);
5097                  } else {                  } else {
# Line 4518  sub _tree_construction_main ($) { Line 5108  sub _tree_construction_main ($) {
5108                  next B;                  next B;
5109                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
5110                  !!!cp ('t177');                  !!!cp ('t177');
5111                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5112                                    text => $token->{tag_name}, token => $token);
5113                  ## Ignore the token                  ## Ignore the token
5114                  !!!next-token;                  !!!next-token;
5115                  next B;                  next B;
# Line 4561  sub _tree_construction_main ($) { Line 5152  sub _tree_construction_main ($) {
5152    
5153                  !!!cp ('t182');                  !!!cp ('t182');
5154                  !!!parse-error (type => 'unmatched end tag',                  !!!parse-error (type => 'unmatched end tag',
5155                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
5156                  ## Ignore the token                  ## Ignore the token
5157                  !!!next-token;                  !!!next-token;
5158                  next B;                  next B;
5159                } # INSCOPE                } # INSCOPE
5160              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
5161                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5162                !!!parse-error (type => 'not closed:caption', token => $token);                !!!parse-error (type => 'not closed', text => 'caption',
5163                                  token => $token);
5164    
5165                ## As if </caption>                ## As if </caption>
5166                ## have a table element in table scope                ## have a table element in table scope
# Line 4586  sub _tree_construction_main ($) { Line 5178  sub _tree_construction_main ($) {
5178                } # INSCOPE                } # INSCOPE
5179                unless (defined $i) {                unless (defined $i) {
5180                  !!!cp ('t186');                  !!!cp ('t186');
5181                  !!!parse-error (type => 'unmatched end tag:caption', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5182                                    text => 'caption', token => $token);
5183                  ## Ignore the token                  ## Ignore the token
5184                  !!!next-token;                  !!!next-token;
5185                  next B;                  next B;
# Line 4601  sub _tree_construction_main ($) { Line 5194  sub _tree_construction_main ($) {
5194                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5195                  !!!cp ('t188');                  !!!cp ('t188');
5196                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5197                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5198                                      ->manakai_local_name,                                      ->manakai_local_name,
5199                                  token => $token);                                  token => $token);
5200                } else {                } else {
# Line 4621  sub _tree_construction_main ($) { Line 5214  sub _tree_construction_main ($) {
5214                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5215                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
5216                  !!!cp ('t190');                  !!!cp ('t190');
5217                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5218                                    text => $token->{tag_name}, token => $token);
5219                  ## Ignore the token                  ## Ignore the token
5220                  !!!next-token;                  !!!next-token;
5221                  next B;                  next B;
# Line 4635  sub _tree_construction_main ($) { Line 5229  sub _tree_construction_main ($) {
5229                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
5230                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5231                !!!cp ('t192');                !!!cp ('t192');
5232                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
5233                                  text => $token->{tag_name}, token => $token);
5234                ## Ignore the token                ## Ignore the token
5235                !!!next-token;                !!!next-token;
5236                next B;                next B;
# Line 4675  sub _tree_construction_main ($) { Line 5270  sub _tree_construction_main ($) {
5270            }            }
5271          }          }
5272    
5273              !!!parse-error (type => 'in table:#character', token => $token);          !!!parse-error (type => 'in table:#text', token => $token);
5274    
5275              ## As if in body, but insert into foster parent element              ## As if in body, but insert into foster parent element
5276              ## ISSUE: Spec says that "whenever a node would be inserted              ## ISSUE: Spec says that "whenever a node would be inserted
# Line 4726  sub _tree_construction_main ($) { Line 5321  sub _tree_construction_main ($) {
5321          !!!next-token;          !!!next-token;
5322          next B;          next B;
5323        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5324              if ({          if ({
5325                   tr => ($self->{insertion_mode} != IN_ROW_IM),               tr => ($self->{insertion_mode} != IN_ROW_IM),
5326                   th => 1, td => 1,               th => 1, td => 1,
5327                  }->{$token->{tag_name}}) {              }->{$token->{tag_name}}) {
5328                if ($self->{insertion_mode} == IN_TABLE_IM) {            if ($self->{insertion_mode} == IN_TABLE_IM) {
5329                  ## Clear back to table context              ## Clear back to table context
5330                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5331                                  & TABLE_SCOPING_EL)) {                              & TABLE_SCOPING_EL)) {
5332                    !!!cp ('t201');                !!!cp ('t201');
5333                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5334                  }              }
5335                                
5336                  !!!insert-element ('tbody',, $token);              !!!insert-element ('tbody',, $token);
5337                  $self->{insertion_mode} = IN_TABLE_BODY_IM;              $self->{insertion_mode} = IN_TABLE_BODY_IM;
5338                  ## reprocess in the "in table body" insertion mode...              ## reprocess in the "in table body" insertion mode...
5339                }            }
5340              
5341                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {            if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
5342                  unless ($token->{tag_name} eq 'tr') {              unless ($token->{tag_name} eq 'tr') {
5343                    !!!cp ('t202');                !!!cp ('t202');
5344                    !!!parse-error (type => 'missing start tag:tr', token => $token);                !!!parse-error (type => 'missing start tag:tr', token => $token);
5345                  }              }
5346                                    
5347                  ## Clear back to table body context              ## Clear back to table body context
5348                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5349                                  & TABLE_ROWS_SCOPING_EL)) {                              & TABLE_ROWS_SCOPING_EL)) {
5350                    !!!cp ('t203');                !!!cp ('t203');
5351                    ## ISSUE: Can this case be reached?                ## ISSUE: Can this case be reached?
5352                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5353                  }              }
5354                                    
5355                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
5356                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
# Line 4811  sub _tree_construction_main ($) { Line 5406  sub _tree_construction_main ($) {
5406                  unless (defined $i) {                  unless (defined $i) {
5407                    !!!cp ('t210');                    !!!cp ('t210');
5408  ## TODO: This type is wrong.  ## TODO: This type is wrong.
5409                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmacthed end tag',
5410                                      text => $token->{tag_name}, token => $token);
5411                    ## Ignore the token                    ## Ignore the token
5412                    !!!nack ('t210.1');                    !!!nack ('t210.1');
5413                    !!!next-token;                    !!!next-token;
# Line 4855  sub _tree_construction_main ($) { Line 5451  sub _tree_construction_main ($) {
5451                  } # INSCOPE                  } # INSCOPE
5452                  unless (defined $i) {                  unless (defined $i) {
5453                    !!!cp ('t216');                    !!!cp ('t216');
5454  ## TODO: This erorr type ios wrong.  ## TODO: This erorr type is wrong.
5455                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5456                                      text => $token->{tag_name}, token => $token);
5457                    ## Ignore the token                    ## Ignore the token
5458                    !!!nack ('t216.1');                    !!!nack ('t216.1');
5459                    !!!next-token;                    !!!next-token;
# Line 4931  sub _tree_construction_main ($) { Line 5528  sub _tree_construction_main ($) {
5528                }                }
5529              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
5530                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
5531                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
5532                                    ->manakai_local_name,                                    ->manakai_local_name,
5533                                token => $token);                                token => $token);
5534    
# Line 4952  sub _tree_construction_main ($) { Line 5549  sub _tree_construction_main ($) {
5549                unless (defined $i) {                unless (defined $i) {
5550                  !!!cp ('t223');                  !!!cp ('t223');
5551  ## TODO: The following is wrong, maybe.  ## TODO: The following is wrong, maybe.
5552                  !!!parse-error (type => 'unmatched end tag:table', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'table',
5553                                    token => $token);
5554                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
5555                  !!!nack ('t223.1');                  !!!nack ('t223.1');
5556                  !!!next-token;                  !!!next-token;
5557                  next B;                  next B;
5558                }                }
5559                                
5560  ## TODO: Followings are removed from the latest spec.  ## TODO: Followings are removed from the latest spec.
5561                ## generate implied end tags                ## generate implied end tags
5562                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
5563                  !!!cp ('t224');                  !!!cp ('t224');
# Line 4970  sub _tree_construction_main ($) { Line 5568  sub _tree_construction_main ($) {
5568                  !!!cp ('t225');                  !!!cp ('t225');
5569                  ## NOTE: |<table><tr><table>|                  ## NOTE: |<table><tr><table>|
5570                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5571                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5572                                      ->manakai_local_name,                                      ->manakai_local_name,
5573                                  token => $token);                                  token => $token);
5574                } else {                } else {
# Line 5011  sub _tree_construction_main ($) { Line 5609  sub _tree_construction_main ($) {
5609                my $type = lc $token->{attributes}->{type}->{value};                my $type = lc $token->{attributes}->{type}->{value};
5610                if ($type eq 'hidden') {                if ($type eq 'hidden') {
5611                  !!!cp ('t227.3');                  !!!cp ('t227.3');
5612                  !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in table',
5613                                    text => $token->{tag_name}, token => $token);
5614    
5615                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5616    
# Line 5039  sub _tree_construction_main ($) { Line 5638  sub _tree_construction_main ($) {
5638            #            #
5639          }          }
5640    
5641          !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in table', text => $token->{tag_name},
5642                            token => $token);
5643    
5644          $insert = $insert_to_foster;          $insert = $insert_to_foster;
5645          #          #
# Line 5061  sub _tree_construction_main ($) { Line 5661  sub _tree_construction_main ($) {
5661                } # INSCOPE                } # INSCOPE
5662                unless (defined $i) {                unless (defined $i) {
5663                  !!!cp ('t230');                  !!!cp ('t230');
5664                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5665                                    text => $token->{tag_name}, token => $token);
5666                  ## Ignore the token                  ## Ignore the token
5667                  !!!nack ('t230.1');                  !!!nack ('t230.1');
5668                  !!!next-token;                  !!!next-token;
# Line 5102  sub _tree_construction_main ($) { Line 5703  sub _tree_construction_main ($) {
5703                  unless (defined $i) {                  unless (defined $i) {
5704                    !!!cp ('t235');                    !!!cp ('t235');
5705  ## TODO: The following is wrong.  ## TODO: The following is wrong.
5706                    !!!parse-error (type => 'unmatched end tag:'.$token->{type}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5707                                      text => $token->{type}, token => $token);
5708                    ## Ignore the token                    ## Ignore the token
5709                    !!!nack ('t236.1');                    !!!nack ('t236.1');
5710                    !!!next-token;                    !!!next-token;
# Line 5138  sub _tree_construction_main ($) { Line 5740  sub _tree_construction_main ($) {
5740                  } # INSCOPE                  } # INSCOPE
5741                  unless (defined $i) {                  unless (defined $i) {
5742                    !!!cp ('t239');                    !!!cp ('t239');
5743                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5744                                      text => $token->{tag_name}, token => $token);
5745                    ## Ignore the token                    ## Ignore the token
5746                    !!!nack ('t239.1');                    !!!nack ('t239.1');
5747                    !!!next-token;                    !!!next-token;
# Line 5184  sub _tree_construction_main ($) { Line 5787  sub _tree_construction_main ($) {
5787                } # INSCOPE                } # INSCOPE
5788                unless (defined $i) {                unless (defined $i) {
5789                  !!!cp ('t243');                  !!!cp ('t243');
5790                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5791                                    text => $token->{tag_name}, token => $token);
5792                  ## Ignore the token                  ## Ignore the token
5793                  !!!nack ('t243.1');                  !!!nack ('t243.1');
5794                  !!!next-token;                  !!!next-token;
# Line 5218  sub _tree_construction_main ($) { Line 5822  sub _tree_construction_main ($) {
5822                  } # INSCOPE                  } # INSCOPE
5823                    unless (defined $i) {                    unless (defined $i) {
5824                      !!!cp ('t249');                      !!!cp ('t249');
5825                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5826                                        text => $token->{tag_name}, token => $token);
5827                      ## Ignore the token                      ## Ignore the token
5828                      !!!nack ('t249.1');                      !!!nack ('t249.1');
5829                      !!!next-token;                      !!!next-token;
# Line 5241  sub _tree_construction_main ($) { Line 5846  sub _tree_construction_main ($) {
5846                  } # INSCOPE                  } # INSCOPE
5847                    unless (defined $i) {                    unless (defined $i) {
5848                      !!!cp ('t252');                      !!!cp ('t252');
5849                      !!!parse-error (type => 'unmatched end tag:tr', token => $token);                      !!!parse-error (type => 'unmatched end tag',
5850                                        text => 'tr', token => $token);
5851                      ## Ignore the token                      ## Ignore the token
5852                      !!!nack ('t252.1');                      !!!nack ('t252.1');
5853                      !!!next-token;                      !!!next-token;
# Line 5276  sub _tree_construction_main ($) { Line 5882  sub _tree_construction_main ($) {
5882                } # INSCOPE                } # INSCOPE
5883                unless (defined $i) {                unless (defined $i) {
5884                  !!!cp ('t256');                  !!!cp ('t256');
5885                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5886                                    text => $token->{tag_name}, token => $token);
5887                  ## Ignore the token                  ## Ignore the token
5888                  !!!nack ('t256.1');                  !!!nack ('t256.1');
5889                  !!!next-token;                  !!!next-token;
# Line 5303  sub _tree_construction_main ($) { Line 5910  sub _tree_construction_main ($) {
5910                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
5911                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5912            !!!cp ('t258');            !!!cp ('t258');
5913            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
5914                              text => $token->{tag_name}, token => $token);
5915            ## Ignore the token            ## Ignore the token
5916            !!!nack ('t258.1');            !!!nack ('t258.1');
5917             !!!next-token;             !!!next-token;
5918            next B;            next B;
5919          } else {          } else {
5920            !!!cp ('t259');            !!!cp ('t259');
5921            !!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in table:/',
5922                              text => $token->{tag_name}, token => $token);
5923    
5924            $insert = $insert_to_foster;            $insert = $insert_to_foster;
5925            #            #
# Line 5360  sub _tree_construction_main ($) { Line 5969  sub _tree_construction_main ($) {
5969              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
5970                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
5971                  !!!cp ('t264');                  !!!cp ('t264');
5972                  !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5973                                    text => 'colgroup', token => $token);
5974                  ## Ignore the token                  ## Ignore the token
5975                  !!!next-token;                  !!!next-token;
5976                  next B;                  next B;
# Line 5373  sub _tree_construction_main ($) { Line 5983  sub _tree_construction_main ($) {
5983                }                }
5984              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
5985                !!!cp ('t266');                !!!cp ('t266');
5986                !!!parse-error (type => 'unmatched end tag:col', token => $token);                !!!parse-error (type => 'unmatched end tag',
5987                                  text => 'col', token => $token);
5988                ## Ignore the token                ## Ignore the token
5989                !!!next-token;                !!!next-token;
5990                next B;                next B;
# Line 5403  sub _tree_construction_main ($) { Line 6014  sub _tree_construction_main ($) {
6014            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
6015              !!!cp ('t269');              !!!cp ('t269');
6016  ## TODO: Wrong error type?  ## TODO: Wrong error type?
6017              !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);              !!!parse-error (type => 'unmatched end tag',
6018                                text => 'colgroup', token => $token);
6019              ## Ignore the token              ## Ignore the token
6020              !!!nack ('t269.1');              !!!nack ('t269.1');
6021              !!!next-token;              !!!next-token;
# Line 5457  sub _tree_construction_main ($) { Line 6069  sub _tree_construction_main ($) {
6069            !!!nack ('t277.1');            !!!nack ('t277.1');
6070            !!!next-token;            !!!next-token;
6071            next B;            next B;
6072          } elsif ($token->{tag_name} eq 'select' or          } elsif ({
6073                   $token->{tag_name} eq 'input' or                     select => 1, input => 1, textarea => 1,
6074                     }->{$token->{tag_name}} or
6075                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
6076                    {                    {
6077                     caption => 1, table => 1,                     caption => 1, table => 1,
# Line 5466  sub _tree_construction_main ($) { Line 6079  sub _tree_construction_main ($) {
6079                     tr => 1, td => 1, th => 1,                     tr => 1, td => 1, th => 1,
6080                    }->{$token->{tag_name}})) {                    }->{$token->{tag_name}})) {
6081            ## TODO: The type below is not good - <select> is replaced by </select>            ## TODO: The type below is not good - <select> is replaced by </select>
6082            !!!parse-error (type => 'not closed:select', token => $token);            !!!parse-error (type => 'not closed', text => 'select',
6083                              token => $token);
6084            ## NOTE: As if the token were </select> (<select> case) or            ## NOTE: As if the token were </select> (<select> case) or
6085            ## as if there were </select> (otherwise).            ## as if there were </select> (otherwise).
6086            ## have an element in table scope            ## have an element in table scope
# Line 5484  sub _tree_construction_main ($) { Line 6098  sub _tree_construction_main ($) {
6098            } # INSCOPE            } # INSCOPE
6099            unless (defined $i) {            unless (defined $i) {
6100              !!!cp ('t280');              !!!cp ('t280');
6101              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6102                                text => 'select', token => $token);
6103              ## Ignore the token              ## Ignore the token
6104              !!!nack ('t280.1');              !!!nack ('t280.1');
6105              !!!next-token;              !!!next-token;
# Line 5508  sub _tree_construction_main ($) { Line 6123  sub _tree_construction_main ($) {
6123            }            }
6124          } else {          } else {
6125            !!!cp ('t282');            !!!cp ('t282');
6126            !!!parse-error (type => 'in select:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select',
6127                              text => $token->{tag_name}, token => $token);
6128            ## Ignore the token            ## Ignore the token
6129            !!!nack ('t282.1');            !!!nack ('t282.1');
6130            !!!next-token;            !!!next-token;
# Line 5526  sub _tree_construction_main ($) { Line 6142  sub _tree_construction_main ($) {
6142              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6143            } else {            } else {
6144              !!!cp ('t285');              !!!cp ('t285');
6145              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6146                                text => $token->{tag_name}, token => $token);
6147              ## Ignore the token              ## Ignore the token
6148            }            }
6149            !!!nack ('t285.1');            !!!nack ('t285.1');
# Line 5538  sub _tree_construction_main ($) { Line 6155  sub _tree_construction_main ($) {
6155              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6156            } else {            } else {
6157              !!!cp ('t287');              !!!cp ('t287');
6158              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6159                                text => $token->{tag_name}, token => $token);
6160              ## Ignore the token              ## Ignore the token
6161            }            }
6162            !!!nack ('t287.1');            !!!nack ('t287.1');
# Line 5560  sub _tree_construction_main ($) { Line 6178  sub _tree_construction_main ($) {
6178            } # INSCOPE            } # INSCOPE
6179            unless (defined $i) {            unless (defined $i) {
6180              !!!cp ('t290');              !!!cp ('t290');
6181              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6182                                text => $token->{tag_name}, token => $token);
6183              ## Ignore the token              ## Ignore the token
6184              !!!nack ('t290.1');              !!!nack ('t290.1');
6185              !!!next-token;              !!!next-token;
# Line 5581  sub _tree_construction_main ($) { Line 6200  sub _tree_construction_main ($) {
6200                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
6201                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
6202  ## TODO: The following is wrong?  ## TODO: The following is wrong?
6203            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
6204                              text => $token->{tag_name}, token => $token);
6205                                
6206            ## have an element in table scope            ## have an element in table scope
6207            my $i;            my $i;
# Line 5622  sub _tree_construction_main ($) { Line 6242  sub _tree_construction_main ($) {
6242            unless (defined $i) {            unless (defined $i) {
6243              !!!cp ('t297');              !!!cp ('t297');
6244  ## TODO: The following error type is correct?  ## TODO: The following error type is correct?
6245              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6246                                text => 'select', token => $token);
6247              ## Ignore the </select> token              ## Ignore the </select> token
6248              !!!nack ('t297.1');              !!!nack ('t297.1');
6249              !!!next-token; ## TODO: ok?              !!!next-token; ## TODO: ok?
# Line 5639  sub _tree_construction_main ($) { Line 6260  sub _tree_construction_main ($) {
6260            next B;            next B;
6261          } else {          } else {
6262            !!!cp ('t299');            !!!cp ('t299');
6263            !!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select:/',
6264                              text => $token->{tag_name}, token => $token);
6265            ## Ignore the token            ## Ignore the token
6266            !!!nack ('t299.3');            !!!nack ('t299.3');
6267            !!!next-token;            !!!next-token;
# Line 5677  sub _tree_construction_main ($) { Line 6299  sub _tree_construction_main ($) {
6299                    
6300          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6301            !!!cp ('t301');            !!!cp ('t301');
6302            !!!parse-error (type => 'after html:#character', token => $token);            !!!parse-error (type => 'after html:#text', token => $token);
6303    
6304            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6305          } else {          } else {
# Line 5685  sub _tree_construction_main ($) { Line 6307  sub _tree_construction_main ($) {
6307          }          }
6308                    
6309          ## "after body" insertion mode          ## "after body" insertion mode
6310          !!!parse-error (type => 'after body:#character', token => $token);          !!!parse-error (type => 'after body:#text', token => $token);
6311    
6312          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6313          ## reprocess          ## reprocess
# Line 5693  sub _tree_construction_main ($) { Line 6315  sub _tree_construction_main ($) {
6315        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
6316          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6317            !!!cp ('t303');            !!!cp ('t303');
6318            !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html',
6319                              text => $token->{tag_name}, token => $token);
6320                        
6321            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6322          } else {          } else {
# Line 5701  sub _tree_construction_main ($) { Line 6324  sub _tree_construction_main ($) {
6324          }          }
6325    
6326          ## "after body" insertion mode          ## "after body" insertion mode
6327          !!!parse-error (type => 'after body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'after body',
6328                            text => $token->{tag_name}, token => $token);
6329    
6330          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6331          !!!ack-later;          !!!ack-later;
# Line 5710  sub _tree_construction_main ($) { Line 6334  sub _tree_construction_main ($) {
6334        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6335          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6336            !!!cp ('t305');            !!!cp ('t305');
6337            !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html:/',
6338                              text => $token->{tag_name}, token => $token);
6339                        
6340            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6341            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
# Line 5722  sub _tree_construction_main ($) { Line 6347  sub _tree_construction_main ($) {
6347          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
6348            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
6349              !!!cp ('t307');              !!!cp ('t307');
6350              !!!parse-error (type => 'unmatched end tag:html', token => $token);              !!!parse-error (type => 'unmatched end tag',
6351                                text => 'html', token => $token);
6352              ## Ignore the token              ## Ignore the token
6353              !!!next-token;              !!!next-token;
6354              next B;              next B;
# Line 5734  sub _tree_construction_main ($) { Line 6360  sub _tree_construction_main ($) {
6360            }            }
6361          } else {          } else {
6362            !!!cp ('t309');            !!!cp ('t309');
6363            !!!parse-error (type => 'after body:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after body:/',
6364                              text => $token->{tag_name}, token => $token);
6365    
6366            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
6367            ## reprocess            ## reprocess
# Line 5762  sub _tree_construction_main ($) { Line 6389  sub _tree_construction_main ($) {
6389          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
6390            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6391              !!!cp ('t311');              !!!cp ('t311');
6392              !!!parse-error (type => 'in frameset:#character', token => $token);              !!!parse-error (type => 'in frameset:#text', token => $token);
6393            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6394              !!!cp ('t312');              !!!cp ('t312');
6395              !!!parse-error (type => 'after frameset:#character', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6396            } else { # "after html frameset"            } else { # "after after frameset"
6397              !!!cp ('t313');              !!!cp ('t313');
6398              !!!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);  
6399            }            }
6400                        
6401            ## Ignore the token.            ## Ignore the token.
# Line 5788  sub _tree_construction_main ($) { Line 6411  sub _tree_construction_main ($) {
6411                    
6412          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
6413        } 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');  
         }  
   
6414          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6415              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6416            !!!cp ('t318');            !!!cp ('t318');
# Line 5815  sub _tree_construction_main ($) { Line 6428  sub _tree_construction_main ($) {
6428            next B;            next B;
6429          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
6430            !!!cp ('t320');            !!!cp ('t320');
6431            ## NOTE: As if in body.            ## NOTE: As if in head.
6432            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
6433            next B;            next B;
6434    
6435              ## NOTE: |<!DOCTYPE HTML><frameset></frameset></html><noframes></noframes>|
6436              ## has no parse error.
6437          } else {          } else {
6438            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6439              !!!cp ('t321');              !!!cp ('t321');
6440              !!!parse-error (type => 'in frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset',
6441            } else {                              text => $token->{tag_name}, token => $token);
6442              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6443              !!!cp ('t322');              !!!cp ('t322');
6444              !!!parse-error (type => 'after frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after frameset',
6445                                text => $token->{tag_name}, token => $token);
6446              } else { # "after after frameset"
6447                !!!cp ('t322.2');
6448                !!!parse-error (type => 'after after frameset',
6449                                text => $token->{tag_name}, token => $token);
6450            }            }
6451            ## Ignore the token            ## Ignore the token
6452            !!!nack ('t322.1');            !!!nack ('t322.1');
# Line 5832  sub _tree_construction_main ($) { Line 6454  sub _tree_construction_main ($) {
6454            next B;            next B;
6455          }          }
6456        } 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');  
         }  
   
6457          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6458              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6459            if ($self->{open_elements}->[-1]->[1] & HTML_EL and            if ($self->{open_elements}->[-1]->[1] & HTML_EL and
6460                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
6461              !!!cp ('t325');              !!!cp ('t325');
6462              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6463                                text => $token->{tag_name}, token => $token);
6464              ## Ignore the token              ## Ignore the token
6465              !!!next-token;              !!!next-token;
6466            } else {            } else {
# Line 5873  sub _tree_construction_main ($) { Line 6486  sub _tree_construction_main ($) {
6486          } else {          } else {
6487            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6488              !!!cp ('t330');              !!!cp ('t330');
6489              !!!parse-error (type => 'in frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset:/',
6490            } else {                              text => $token->{tag_name}, token => $token);
6491              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6492                !!!cp ('t330.1');
6493                !!!parse-error (type => 'after frameset:/',
6494                                text => $token->{tag_name}, token => $token);
6495              } else { # "after after html"
6496              !!!cp ('t331');              !!!cp ('t331');
6497              !!!parse-error (type => 'after frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after after frameset:/',
6498                                text => $token->{tag_name}, token => $token);
6499            }            }
6500            ## Ignore the token            ## Ignore the token
6501            !!!next-token;            !!!next-token;
# Line 5930  sub _tree_construction_main ($) { Line 6549  sub _tree_construction_main ($) {
6549          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.
6550    
6551          unless ($self->{confident}) {          unless ($self->{confident}) {
6552            if ($token->{attributes}->{charset}) { ## TODO: And if supported            if ($token->{attributes}->{charset}) {
6553              !!!cp ('t335');              !!!cp ('t335');
6554                ## NOTE: Whether the encoding is supported or not is handled
6555                ## in the {change_encoding} callback.
6556              $self->{change_encoding}              $self->{change_encoding}
6557                  ->($self, $token->{attributes}->{charset}->{value}, $token);                  ->($self, $token->{attributes}->{charset}->{value}, $token);
6558                            
# Line 5940  sub _tree_construction_main ($) { Line 6561  sub _tree_construction_main ($) {
6561                                       $token->{attributes}->{charset}                                       $token->{attributes}->{charset}
6562                                           ->{has_reference});                                           ->{has_reference});
6563            } elsif ($token->{attributes}->{content}) {            } elsif ($token->{attributes}->{content}) {
             ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.  
6564              if ($token->{attributes}->{content}->{value}              if ($token->{attributes}->{content}->{value}
6565                  =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                  =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
6566                      [\x09-\x0D\x20]*=                      [\x09-\x0D\x20]*=
6567                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
6568                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
6569                !!!cp ('t336');                !!!cp ('t336');
6570                  ## NOTE: Whether the encoding is supported or not is handled
6571                  ## in the {change_encoding} callback.
6572                $self->{change_encoding}                $self->{change_encoding}
6573                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3, $token);                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3, $token);
6574                $meta_el->[0]->get_attribute_node_ns (undef, 'content')                $meta_el->[0]->get_attribute_node_ns (undef, 'content')
# Line 5981  sub _tree_construction_main ($) { Line 6603  sub _tree_construction_main ($) {
6603          $parse_rcdata->(RCDATA_CONTENT_MODEL);          $parse_rcdata->(RCDATA_CONTENT_MODEL);
6604          next B;          next B;
6605        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
6606          !!!parse-error (type => 'in body:body', token => $token);          !!!parse-error (type => 'in body', text => 'body', token => $token);
6607                                
6608          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
6609              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {
# Line 6101  sub _tree_construction_main ($) { Line 6723  sub _tree_construction_main ($) {
6723              if ($i != -1) {              if ($i != -1) {
6724                !!!cp ('t355');                !!!cp ('t355');
6725                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
6726                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
6727                                    ->manakai_local_name,                                    ->manakai_local_name,
6728                                token => $token);                                token => $token);
6729              } else {              } else {
# Line 6255  sub _tree_construction_main ($) { Line 6877  sub _tree_construction_main ($) {
6877                  xmp => 1,                  xmp => 1,
6878                  iframe => 1,                  iframe => 1,
6879                  noembed => 1,                  noembed => 1,
6880                  noframes => 1,                  noframes => 1, ## NOTE: This is an "as if in head" code clone.
6881                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
6882                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6883          if ($token->{tag_name} eq 'xmp') {          if ($token->{tag_name} eq 'xmp') {
# Line 6277  sub _tree_construction_main ($) { Line 6899  sub _tree_construction_main ($) {
6899            !!!next-token;            !!!next-token;
6900            next B;            next B;
6901          } else {          } else {
6902              !!!ack ('t391.1');
6903    
6904            my $at = $token->{attributes};            my $at = $token->{attributes};
6905            my $form_attrs;            my $form_attrs;
6906            $form_attrs->{action} = $at->{action} if $at->{action};            $form_attrs->{action} = $at->{action} if $at->{action};
# Line 6320  sub _tree_construction_main ($) { Line 6944  sub _tree_construction_main ($) {
6944                           line => $token->{line}, column => $token->{column}},                           line => $token->{line}, column => $token->{column}},
6945                          {type => END_TAG_TOKEN, tag_name => 'form',                          {type => END_TAG_TOKEN, tag_name => 'form',
6946                           line => $token->{line}, column => $token->{column}};                           line => $token->{line}, column => $token->{column}};
           !!!nack ('t391.1'); ## NOTE: Not acknowledged.  
6947            !!!back-token (@tokens);            !!!back-token (@tokens);
6948            !!!next-token;            !!!next-token;
6949            next B;            next B;
# Line 6368  sub _tree_construction_main ($) { Line 6991  sub _tree_construction_main ($) {
6991            ## Ignore the token            ## Ignore the token
6992          } else {          } else {
6993            !!!cp ('t398');            !!!cp ('t398');
6994            !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);            !!!parse-error (type => 'in RCDATA:#eof', token => $token);
6995          }          }
6996          !!!next-token;          !!!next-token;
6997          next B;          next B;
6998          } elsif ($token->{tag_name} eq 'rt' or
6999                   $token->{tag_name} eq 'rp') {
7000            ## has a |ruby| element in scope
7001            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
7002              my $node = $self->{open_elements}->[$_];
7003              if ($node->[1] & RUBY_EL) {
7004                !!!cp ('t398.1');
7005                ## generate implied end tags
7006                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7007                  !!!cp ('t398.2');
7008                  pop @{$self->{open_elements}};
7009                }
7010                unless ($self->{open_elements}->[-1]->[1] & RUBY_EL) {
7011                  !!!cp ('t398.3');
7012                  !!!parse-error (type => 'not closed',
7013                                  text => $self->{open_elements}->[-1]->[0]
7014                                      ->manakai_local_name,
7015                                  token => $token);
7016                  pop @{$self->{open_elements}}
7017                      while not $self->{open_elements}->[-1]->[1] & RUBY_EL;
7018                }
7019                last INSCOPE;
7020              } elsif ($node->[1] & SCOPING_EL) {
7021                !!!cp ('t398.4');
7022                last INSCOPE;
7023              }
7024            } # INSCOPE
7025    
7026            !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
7027    
7028            !!!nack ('t398.5');
7029            !!!next-token;
7030            redo B;
7031        } elsif ($token->{tag_name} eq 'math' or        } elsif ($token->{tag_name} eq 'math' or
7032                 $token->{tag_name} eq 'svg') {                 $token->{tag_name} eq 'svg') {
7033          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
7034    
7035            ## "Adjust MathML attributes" ('math' only) - done in insert-element-f
7036    
7037            ## "adjust SVG attributes" ('svg' only) - done in insert-element-f
7038    
7039            ## "adjust foreign attributes" - done in insert-element-f
7040                    
7041          !!!insert-element-f ($token->{tag_name} eq 'math' ? $MML_NS : $SVG_NS, $token);          !!!insert-element-f ($token->{tag_name} eq 'math' ? $MML_NS : $SVG_NS, $token->{tag_name}, $token->{attributes}, $token);
7042                    
7043          if ($self->{self_closing}) {          if ($self->{self_closing}) {
7044            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
# Line 6398  sub _tree_construction_main ($) { Line 7060  sub _tree_construction_main ($) {
7060                  thead => 1, tr => 1,                  thead => 1, tr => 1,
7061                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7062          !!!cp ('t401');          !!!cp ('t401');
7063          !!!parse-error (type => 'in body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in body',
7064                            text => $token->{tag_name}, token => $token);
7065          ## Ignore the token          ## Ignore the token
7066          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.
7067          !!!next-token;          !!!next-token;
# Line 6483  sub _tree_construction_main ($) { Line 7146  sub _tree_construction_main ($) {
7146            }            }
7147    
7148            !!!parse-error (type => 'start tag not allowed',            !!!parse-error (type => 'start tag not allowed',
7149                            value => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7150            ## NOTE: Ignore the token.            ## NOTE: Ignore the token.
7151            !!!next-token;            !!!next-token;
7152            next B;            next B;
# Line 6493  sub _tree_construction_main ($) { Line 7156  sub _tree_construction_main ($) {
7156            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {
7157              !!!cp ('t403');              !!!cp ('t403');
7158              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7159                              value => $_->[0]->manakai_local_name,                              text => $_->[0]->manakai_local_name,
7160                              token => $token);                              token => $token);
7161              last;              last;
7162            } else {            } else {
# Line 6513  sub _tree_construction_main ($) { Line 7176  sub _tree_construction_main ($) {
7176            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {
7177              !!!cp ('t406');              !!!cp ('t406');
7178              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7179                              value => $self->{open_elements}->[1]->[0]                              text => $self->{open_elements}->[1]->[0]
7180                                  ->manakai_local_name,                                  ->manakai_local_name,
7181                              token => $token);                              token => $token);
7182            } else {            } else {
# Line 6524  sub _tree_construction_main ($) { Line 7187  sub _tree_construction_main ($) {
7187            next B;            next B;
7188          } else {          } else {
7189            !!!cp ('t408');            !!!cp ('t408');
7190            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7191                              text => $token->{tag_name}, token => $token);
7192            ## Ignore the token            ## Ignore the token
7193            !!!next-token;            !!!next-token;
7194            next B;            next B;
# Line 6552  sub _tree_construction_main ($) { Line 7216  sub _tree_construction_main ($) {
7216    
7217          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7218            !!!cp ('t413');            !!!cp ('t413');
7219            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7220                              text => $token->{tag_name}, token => $token);
7221              ## NOTE: Ignore the token.
7222          } else {          } else {
7223            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7224            while ({            while ({
7225                      ## END_TAG_OPTIONAL_EL
7226                    dd => ($token->{tag_name} ne 'dd'),                    dd => ($token->{tag_name} ne 'dd'),
7227                    dt => ($token->{tag_name} ne 'dt'),                    dt => ($token->{tag_name} ne 'dt'),
7228                    li => ($token->{tag_name} ne 'li'),                    li => ($token->{tag_name} ne 'li'),
7229                    p => 1,                    p => 1,
7230                      rt => 1,
7231                      rp => 1,
7232                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {
7233              !!!cp ('t409');              !!!cp ('t409');
7234              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
# Line 6570  sub _tree_construction_main ($) { Line 7239  sub _tree_construction_main ($) {
7239                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7240              !!!cp ('t412');              !!!cp ('t412');
7241              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7242                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7243                                  ->manakai_local_name,                                  ->manakai_local_name,
7244                              token => $token);                              token => $token);
7245            } else {            } else {
# Line 6607  sub _tree_construction_main ($) { Line 7276  sub _tree_construction_main ($) {
7276    
7277          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7278            !!!cp ('t421');            !!!cp ('t421');
7279            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7280                              text => $token->{tag_name}, token => $token);
7281              ## NOTE: Ignore the token.
7282          } else {          } else {
7283            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7284            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 6620  sub _tree_construction_main ($) { Line 7291  sub _tree_construction_main ($) {
7291                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7292              !!!cp ('t417.1');              !!!cp ('t417.1');
7293              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7294                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7295                                  ->manakai_local_name,                                  ->manakai_local_name,
7296                              token => $token);                              token => $token);
7297            } else {            } else {
# Line 6652  sub _tree_construction_main ($) { Line 7323  sub _tree_construction_main ($) {
7323    
7324          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7325            !!!cp ('t425.1');            !!!cp ('t425.1');
7326            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7327                              text => $token->{tag_name}, token => $token);
7328              ## NOTE: Ignore the token.
7329          } else {          } else {
7330            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7331            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 6664  sub _tree_construction_main ($) { Line 7337  sub _tree_construction_main ($) {
7337            if ($self->{open_elements}->[-1]->[0]->manakai_local_name            if ($self->{open_elements}->[-1]->[0]->manakai_local_name
7338                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7339              !!!cp ('t425');              !!!cp ('t425');
7340              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
7341                                text => $token->{tag_name}, token => $token);
7342            } else {            } else {
7343              !!!cp ('t426');              !!!cp ('t426');
7344            }            }
# Line 6695  sub _tree_construction_main ($) { Line 7369  sub _tree_construction_main ($) {
7369                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7370              !!!cp ('t412.1');              !!!cp ('t412.1');
7371              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7372                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7373                                  ->manakai_local_name,                                  ->manakai_local_name,
7374                              token => $token);                              token => $token);
7375            } else {            } else {
# Line 6705  sub _tree_construction_main ($) { Line 7379  sub _tree_construction_main ($) {
7379            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
7380          } else {          } else {
7381            !!!cp ('t413.1');            !!!cp ('t413.1');
7382            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7383                              text => $token->{tag_name}, token => $token);
7384    
7385            !!!cp ('t415.1');            !!!cp ('t415.1');
7386            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
# Line 6728  sub _tree_construction_main ($) { Line 7403  sub _tree_construction_main ($) {
7403          next B;          next B;
7404        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
7405          !!!cp ('t428');          !!!cp ('t428');
7406          !!!parse-error (type => 'unmatched end tag:br', token => $token);          !!!parse-error (type => 'unmatched end tag',
7407                            text => 'br', token => $token);
7408    
7409          ## As if <br>          ## As if <br>
7410          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
# Line 6753  sub _tree_construction_main ($) { Line 7429  sub _tree_construction_main ($) {
7429                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
7430                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7431          !!!cp ('t429');          !!!cp ('t429');
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          ## Ignore the token          ## Ignore the token
7435          !!!next-token;          !!!next-token;
7436          next B;          next B;
# Line 6772  sub _tree_construction_main ($) { Line 7449  sub _tree_construction_main ($) {
7449              ## generate implied end tags              ## generate implied end tags
7450              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7451                !!!cp ('t430');                !!!cp ('t430');
7452                ## ISSUE: Can this case be reached?                ## NOTE: |<ruby><rt></ruby>|.
7453                  ## ISSUE: <ruby><rt></rt> will also take this code path,
7454                  ## which seems wrong.
7455                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
7456                  $node_i++;
7457              }              }
7458                    
7459              ## Step 2              ## Step 2
# Line 6782  sub _tree_construction_main ($) { Line 7462  sub _tree_construction_main ($) {
7462                !!!cp ('t431');                !!!cp ('t431');
7463                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
7464                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
7465                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
7466                                    ->manakai_local_name,                                    ->manakai_local_name,
7467                                token => $token);                                token => $token);
7468              } else {              } else {
# Line 6790  sub _tree_construction_main ($) { Line 7470  sub _tree_construction_main ($) {
7470              }              }
7471                            
7472              ## Step 3              ## Step 3
7473              splice @{$self->{open_elements}}, $node_i;              splice @{$self->{open_elements}}, $node_i if $node_i < 0;
7474    
7475              !!!next-token;              !!!next-token;
7476              last S2;              last S2;
# Line 6801  sub _tree_construction_main ($) { Line 7481  sub _tree_construction_main ($) {
7481                  ($node->[1] & SPECIAL_EL or                  ($node->[1] & SPECIAL_EL or
7482                   $node->[1] & SCOPING_EL)) {                   $node->[1] & SCOPING_EL)) {
7483                !!!cp ('t433');                !!!cp ('t433');
7484                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
7485                                  text => $token->{tag_name}, token => $token);
7486                ## Ignore the token                ## Ignore the token
7487                !!!next-token;                !!!next-token;
7488                last S2;                last S2;
# Line 6847  sub _tree_construction_main ($) { Line 7528  sub _tree_construction_main ($) {
7528    ## TODO: script stuffs    ## TODO: script stuffs
7529  } # _tree_construct_main  } # _tree_construct_main
7530    
7531  sub set_inner_html ($$$) {  sub set_inner_html ($$$;$) {
7532    my $class = shift;    my $class = shift;
7533    my $node = shift;    my $node = shift;
7534    my $s = \$_[0];    my $s = \$_[0];
7535    my $onerror = $_[1];    my $onerror = $_[1];
7536      my $get_wrapper = $_[2] || sub ($) { return $_[0] };
7537    
7538    ## ISSUE: Should {confident} be true?    ## ISSUE: Should {confident} be true?
7539    
# Line 6870  sub set_inner_html ($$$) { Line 7552  sub set_inner_html ($$$) {
7552      }      }
7553    
7554      ## Step 3, 4, 5 # MUST      ## Step 3, 4, 5 # MUST
7555      $class->parse_string ($$s => $node, $onerror);      $class->parse_char_string ($$s => $node, $onerror, $get_wrapper);
7556    } elsif ($nt == 1) {    } elsif ($nt == 1) {
7557      ## TODO: If non-html element      ## TODO: If non-html element
7558    
7559      ## NOTE: Most of this code is copied from |parse_string|      ## NOTE: Most of this code is copied from |parse_string|
7560    
7561    ## TODO: Support for $get_wrapper
7562    
7563      ## Step 1 # MUST      ## Step 1 # MUST
7564      my $this_doc = $node->owner_document;      my $this_doc = $node->owner_document;
7565      my $doc = $this_doc->implementation->create_document;      my $doc = $this_doc->implementation->create_document;
# Line 6916  sub set_inner_html ($$$) { Line 7600  sub set_inner_html ($$$) {
7600          !!!cp ('i4');          !!!cp ('i4');
7601          !!!parse-error (type => 'NULL');          !!!parse-error (type => 'NULL');
7602          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
7603          } elsif ($self->{next_char} <= 0x0008 or
7604                   (0x000E <= $self->{next_char} and
7605                    $self->{next_char} <= 0x001F) or
7606                   (0x007F <= $self->{next_char} and
7607                    $self->{next_char} <= 0x009F) or
7608                   (0xD800 <= $self->{next_char} and
7609                    $self->{next_char} <= 0xDFFF) or
7610                   (0xFDD0 <= $self->{next_char} and
7611                    $self->{next_char} <= 0xFDDF) or
7612                   {
7613                    0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,
7614                    0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,
7615                    0x4FFFE => 1, 0x4FFFF => 1, 0x5FFFE => 1, 0x5FFFF => 1,
7616                    0x6FFFE => 1, 0x6FFFF => 1, 0x7FFFE => 1, 0x7FFFF => 1,
7617                    0x8FFFE => 1, 0x8FFFF => 1, 0x9FFFE => 1, 0x9FFFF => 1,
7618                    0xAFFFE => 1, 0xAFFFF => 1, 0xBFFFE => 1, 0xBFFFF => 1,
7619                    0xCFFFE => 1, 0xCFFFF => 1, 0xDFFFE => 1, 0xDFFFF => 1,
7620                    0xEFFFE => 1, 0xEFFFF => 1, 0xFFFFE => 1, 0xFFFFF => 1,
7621                    0x10FFFE => 1, 0x10FFFF => 1,
7622                   }->{$self->{next_char}}) {
7623            !!!cp ('i4.1');
7624            if ($self->{next_char} < 0x10000) {
7625              !!!parse-error (type => 'control char',
7626                              text => (sprintf 'U+%04X', $self->{next_char}));
7627            } else {
7628              !!!parse-error (type => 'control char',
7629                              text => (sprintf 'U-%08X', $self->{next_char}));
7630            }
7631        }        }
7632      };      };
7633      $p->{prev_char} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];

Legend:
Removed from v.1.128  
changed lines
  Added in v.1.165

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24