/[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.137 by wakaba, Sun May 18 03:46:27 2008 UTC revision 1.170 by wakaba, Sat Sep 13 12:25:44 2008 UTC
# Line 8  use Error qw(:try); Line 8  use Error qw(:try);
8  ## doc.write ('');  ## doc.write ('');
9  ## alert (doc.compatMode);  ## alert (doc.compatMode);
10    
11  ## TODO: 1252 parse error (revision 1264)  require IO::Handle;
 ## TODO: 8859-11 = 874 (revision 1271)  
12    
13  my $HTML_NS = q<http://www.w3.org/1999/xhtml>;  my $HTML_NS = q<http://www.w3.org/1999/xhtml>;
14  my $MML_NS = q<http://www.w3.org/1998/Math/MathML>;  my $MML_NS = q<http://www.w3.org/1998/Math/MathML>;
# Line 46  sub MISC_SPECIAL_EL () { 0b1000000000000 Line 45  sub MISC_SPECIAL_EL () { 0b1000000000000
45  sub FOREIGN_EL () { 0b10000000000000000000000000 }  sub FOREIGN_EL () { 0b10000000000000000000000000 }
46  sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 }  sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 }
47  sub MML_AXML_EL () { 0b1000000000000000000000000000 }  sub MML_AXML_EL () { 0b1000000000000000000000000000 }
48    sub RUBY_EL () { 0b10000000000000000000000000000 }
49    sub RUBY_COMPONENT_EL () { 0b100000000000000000000000000000 }
50    
51  sub TABLE_ROWS_EL () {  sub TABLE_ROWS_EL () {
52    TABLE_EL |    TABLE_EL |
# Line 53  sub TABLE_ROWS_EL () { Line 54  sub TABLE_ROWS_EL () {
54    TABLE_ROW_GROUP_EL    TABLE_ROW_GROUP_EL
55  }  }
56    
57    ## NOTE: Used in "generate implied end tags" algorithm.
58    ## NOTE: There is a code where a modified version of END_TAG_OPTIONAL_EL
59    ## is used in "generate implied end tags" implementation (search for the
60    ## function mae).
61  sub END_TAG_OPTIONAL_EL () {  sub END_TAG_OPTIONAL_EL () {
62    DD_EL |    DD_EL |
63    DT_EL |    DT_EL |
64    LI_EL |    LI_EL |
65    P_EL    P_EL |
66      RUBY_COMPONENT_EL
67  }  }
68    
69    ## NOTE: Used in </body> and EOF algorithms.
70  sub ALL_END_TAG_OPTIONAL_EL () {  sub ALL_END_TAG_OPTIONAL_EL () {
71    END_TAG_OPTIONAL_EL |    DD_EL |
72      DT_EL |
73      LI_EL |
74      P_EL |
75    
76    BODY_EL |    BODY_EL |
77    HTML_EL |    HTML_EL |
78    TABLE_CELL_EL |    TABLE_CELL_EL |
# Line 97  sub SPECIAL_EL () { Line 108  sub SPECIAL_EL () {
108    ADDRESS_EL |    ADDRESS_EL |
109    BODY_EL |    BODY_EL |
110    DIV_EL |    DIV_EL |
111    END_TAG_OPTIONAL_EL |  
112      DD_EL |
113      DT_EL |
114      LI_EL |
115      P_EL |
116    
117    FORM_EL |    FORM_EL |
118    FRAMESET_EL |    FRAMESET_EL |
119    HEADING_EL |    HEADING_EL |
# Line 171  my $el_category = { Line 187  my $el_category = {
187    param => MISC_SPECIAL_EL,    param => MISC_SPECIAL_EL,
188    plaintext => MISC_SPECIAL_EL,    plaintext => MISC_SPECIAL_EL,
189    pre => MISC_SPECIAL_EL,    pre => MISC_SPECIAL_EL,
190      rp => RUBY_COMPONENT_EL,
191      rt => RUBY_COMPONENT_EL,
192      ruby => RUBY_EL,
193    s => FORMATTING_EL,    s => FORMATTING_EL,
194    script => MISC_SPECIAL_EL,    script => MISC_SPECIAL_EL,
195    select => SELECT_EL,    select => SELECT_EL,
# Line 212  my $el_category_f = { Line 231  my $el_category_f = {
231  };  };
232    
233  my $svg_attr_name = {  my $svg_attr_name = {
234      attributename => 'attributeName',
235    attributetype => 'attributeType',    attributetype => 'attributeType',
236    basefrequency => 'baseFrequency',    basefrequency => 'baseFrequency',
237    baseprofile => 'baseProfile',    baseprofile => 'baseProfile',
# Line 222  my $svg_attr_name = { Line 242  my $svg_attr_name = {
242    diffuseconstant => 'diffuseConstant',    diffuseconstant => 'diffuseConstant',
243    edgemode => 'edgeMode',    edgemode => 'edgeMode',
244    externalresourcesrequired => 'externalResourcesRequired',    externalresourcesrequired => 'externalResourcesRequired',
   fecolormatrix => 'feColorMatrix',  
   fecomposite => 'feComposite',  
   fegaussianblur => 'feGaussianBlur',  
   femorphology => 'feMorphology',  
   fetile => 'feTile',  
245    filterres => 'filterRes',    filterres => 'filterRes',
246    filterunits => 'filterUnits',    filterunits => 'filterUnits',
247    glyphref => 'glyphRef',    glyphref => 'glyphRef',
# Line 260  my $svg_attr_name = { Line 275  my $svg_attr_name = {
275    repeatcount => 'repeatCount',    repeatcount => 'repeatCount',
276    repeatdur => 'repeatDur',    repeatdur => 'repeatDur',
277    requiredextensions => 'requiredExtensions',    requiredextensions => 'requiredExtensions',
278      requiredfeatures => 'requiredFeatures',
279    specularconstant => 'specularConstant',    specularconstant => 'specularConstant',
280    specularexponent => 'specularExponent',    specularexponent => 'specularExponent',
281    spreadmethod => 'spreadMethod',    spreadmethod => 'spreadMethod',
# Line 332  my $c1_entity_char = { Line 348  my $c1_entity_char = {
348  }; # $c1_entity_char  }; # $c1_entity_char
349    
350  sub parse_byte_string ($$$$;$) {  sub parse_byte_string ($$$$;$) {
351      my $self = shift;
352      my $charset_name = shift;
353      open my $input, '<', ref $_[0] ? $_[0] : \($_[0]);
354      return $self->parse_byte_stream ($charset_name, $input, @_[1..$#_]);
355    } # parse_byte_string
356    
357    sub parse_byte_stream ($$$$;$$) {
358      # my ($self, $charset_name, $byte_stream, $doc, $onerror, $get_wrapper) = @_;
359    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
360    my $charset_name = shift;    my $charset_name = shift;
361    open my $byte_stream, '<', ref $_[0] ? $_[0] : \($_[0]);    my $byte_stream = $_[0];
362    
363    my $onerror = $_[2] || sub {    my $onerror = $_[2] || sub {
364      my (%opt) = @_;      my (%opt) = @_;
# Line 342  sub parse_byte_string ($$$$;$) { Line 366  sub parse_byte_string ($$$$;$) {
366    };    };
367    $self->{parse_error} = $onerror; # updated later by parse_char_string    $self->{parse_error} = $onerror; # updated later by parse_char_string
368    
369      my $get_wrapper = $_[3] || sub ($) {
370        return $_[0]; # $_[0] = byte stream handle, returned = arg to char handle
371      };
372    
373    ## HTML5 encoding sniffing algorithm    ## HTML5 encoding sniffing algorithm
374    require Message::Charset::Info;    require Message::Charset::Info;
375    my $charset;    my $charset;
# Line 349  sub parse_byte_string ($$$$;$) { Line 377  sub parse_byte_string ($$$$;$) {
377    my ($char_stream, $e_status);    my ($char_stream, $e_status);
378    
379    SNIFFING: {    SNIFFING: {
380        ## NOTE: By setting |allow_fallback| option true when the
381        ## |get_decode_handle| method is invoked, we ignore what the HTML5
382        ## spec requires, i.e. unsupported encoding should be ignored.
383          ## TODO: We should not do this unless the parser is invoked
384          ## in the conformance checking mode, in which this behavior
385          ## would be useful.
386    
387      ## Step 1      ## Step 1
388      if (defined $charset_name) {      if (defined $charset_name) {
389        $charset = Message::Charset::Info->get_by_iana_name ($charset_name);        $charset = Message::Charset::Info->get_by_html_name ($charset_name);
390              ## TODO: Is this ok?  Transfer protocol's parameter should be
391              ## interpreted in its semantics?
392    
393        ## ISSUE: Unsupported encoding is not ignored according to the spec.        ## ISSUE: Unsupported encoding is not ignored according to the spec.
394        ($char_stream, $e_status) = $charset->get_decode_handle        ($char_stream, $e_status) = $charset->get_decode_handle
# Line 376  sub parse_byte_string ($$$$;$) { Line 412  sub parse_byte_string ($$$$;$) {
412    
413      ## Step 3      ## Step 3
414      if ($byte_buffer =~ /^\xFE\xFF/) {      if ($byte_buffer =~ /^\xFE\xFF/) {
415        $charset = Message::Charset::Info->get_by_iana_name ('utf-16be');        $charset = Message::Charset::Info->get_by_html_name ('utf-16be');
416        ($char_stream, $e_status) = $charset->get_decode_handle        ($char_stream, $e_status) = $charset->get_decode_handle
417            ($byte_stream, allow_error_reporting => 1,            ($byte_stream, allow_error_reporting => 1,
418             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
419        $self->{confident} = 1;        $self->{confident} = 1;
420        last SNIFFING;        last SNIFFING;
421      } elsif ($byte_buffer =~ /^\xFF\xFE/) {      } elsif ($byte_buffer =~ /^\xFF\xFE/) {
422        $charset = Message::Charset::Info->get_by_iana_name ('utf-16le');        $charset = Message::Charset::Info->get_by_html_name ('utf-16le');
423        ($char_stream, $e_status) = $charset->get_decode_handle        ($char_stream, $e_status) = $charset->get_decode_handle
424            ($byte_stream, allow_error_reporting => 1,            ($byte_stream, allow_error_reporting => 1,
425             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
426        $self->{confident} = 1;        $self->{confident} = 1;
427        last SNIFFING;        last SNIFFING;
428      } elsif ($byte_buffer =~ /^\xEF\xBB\xBF/) {      } elsif ($byte_buffer =~ /^\xEF\xBB\xBF/) {
429        $charset = Message::Charset::Info->get_by_iana_name ('utf-8');        $charset = Message::Charset::Info->get_by_html_name ('utf-8');
430        ($char_stream, $e_status) = $charset->get_decode_handle        ($char_stream, $e_status) = $charset->get_decode_handle
431            ($byte_stream, allow_error_reporting => 1,            ($byte_stream, allow_error_reporting => 1,
432             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
# Line 409  sub parse_byte_string ($$$$;$) { Line 445  sub parse_byte_string ($$$$;$) {
445      $charset_name = Whatpm::Charset::UniversalCharDet->detect_byte_string      $charset_name = Whatpm::Charset::UniversalCharDet->detect_byte_string
446          ($byte_buffer);          ($byte_buffer);
447      if (defined $charset_name) {      if (defined $charset_name) {
448        $charset = Message::Charset::Info->get_by_iana_name ($charset_name);        $charset = Message::Charset::Info->get_by_html_name ($charset_name);
449    
450        ## ISSUE: Unsupported encoding is not ignored according to the spec.        ## ISSUE: Unsupported encoding is not ignored according to the spec.
451        require Whatpm::Charset::DecodeHandle;        require Whatpm::Charset::DecodeHandle;
# Line 420  sub parse_byte_string ($$$$;$) { Line 456  sub parse_byte_string ($$$$;$) {
456             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
457        if ($char_stream) {        if ($char_stream) {
458          $buffer->{buffer} = $byte_buffer;          $buffer->{buffer} = $byte_buffer;
459          !!!parse-error (type => 'sniffing:chardet', ## TODO: type name          !!!parse-error (type => 'sniffing:chardet',
460                          value => $charset_name,                          text => $charset_name,
461                          level => $self->{info_level},                          level => $self->{level}->{info},
462                            layer => 'encode',
463                          line => 1, column => 1);                          line => 1, column => 1);
464          $self->{confident} = 0;          $self->{confident} = 0;
465          last SNIFFING;          last SNIFFING;
# Line 431  sub parse_byte_string ($$$$;$) { Line 468  sub parse_byte_string ($$$$;$) {
468    
469      ## Step 7: default      ## Step 7: default
470      ## TODO: Make this configurable.      ## TODO: Make this configurable.
471      $charset = Message::Charset::Info->get_by_iana_name ('windows-1252');      $charset = Message::Charset::Info->get_by_html_name ('windows-1252');
472          ## NOTE: We choose |windows-1252| here, since |utf-8| should be          ## NOTE: We choose |windows-1252| here, since |utf-8| should be
473          ## detectable in the step 6.          ## detectable in the step 6.
474      require Whatpm::Charset::DecodeHandle;      require Whatpm::Charset::DecodeHandle;
# Line 443  sub parse_byte_string ($$$$;$) { Line 480  sub parse_byte_string ($$$$;$) {
480                                         allow_fallback => 1,                                         allow_fallback => 1,
481                                         byte_buffer => \$byte_buffer);                                         byte_buffer => \$byte_buffer);
482      $buffer->{buffer} = $byte_buffer;      $buffer->{buffer} = $byte_buffer;
483      !!!parse-error (type => 'sniffing:default', ## TODO: type name      !!!parse-error (type => 'sniffing:default',
484                      value => 'windows-1252',                      text => 'windows-1252',
485                      level => $self->{info_level},                      level => $self->{level}->{info},
486                      line => 1, column => 1);                      line => 1, column => 1,
487                        layer => 'encode');
488      $self->{confident} = 0;      $self->{confident} = 0;
489    } # SNIFFING    } # SNIFFING
490    
   $self->{input_encoding} = $charset->get_iana_name;  
491    if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {    if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
492      !!!parse-error (type => 'chardecode:fallback', ## TODO: type name      $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name?
493                      value => $self->{input_encoding},      !!!parse-error (type => 'chardecode:fallback',
494                      level => $self->{unsupported_level},                      #text => $self->{input_encoding},
495                      line => 1, column => 1);                      level => $self->{level}->{uncertain},
496                        line => 1, column => 1,
497                        layer => 'encode');
498    } elsif (not ($e_status &    } elsif (not ($e_status &
499                  Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {                  Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
500      !!!parse-error (type => 'chardecode:no error', ## TODO: type name      $self->{input_encoding} = $charset->get_iana_name;
501                      value => $self->{input_encoding},      !!!parse-error (type => 'chardecode:no error',
502                      level => $self->{unsupported_level},                      text => $self->{input_encoding},
503                      line => 1, column => 1);                      level => $self->{level}->{uncertain},
504                        line => 1, column => 1,
505                        layer => 'encode');
506      } else {
507        $self->{input_encoding} = $charset->get_iana_name;
508    }    }
509    
510    $self->{change_encoding} = sub {    $self->{change_encoding} = sub {
# Line 469  sub parse_byte_string ($$$$;$) { Line 512  sub parse_byte_string ($$$$;$) {
512      $charset_name = shift;      $charset_name = shift;
513      my $token = shift;      my $token = shift;
514    
515      $charset = Message::Charset::Info->get_by_iana_name ($charset_name);      $charset = Message::Charset::Info->get_by_html_name ($charset_name);
516      ($char_stream, $e_status) = $charset->get_decode_handle      ($char_stream, $e_status) = $charset->get_decode_handle
517          ($byte_stream, allow_error_reporting => 1, allow_fallback => 1,          ($byte_stream, allow_error_reporting => 1, allow_fallback => 1,
518           byte_buffer => \ $buffer->{buffer});           byte_buffer => \ $buffer->{buffer});
# Line 478  sub parse_byte_string ($$$$;$) { Line 521  sub parse_byte_string ($$$$;$) {
521        ## "Change the encoding" algorithm:        ## "Change the encoding" algorithm:
522    
523        ## Step 1            ## Step 1    
524        if ($charset->{iana_names}->{'utf-16'}) { ## ISSUE: UTF-16BE -> UTF-8? UTF-16LE -> UTF-8?        if ($charset->{category} &
525          $charset = Message::Charset::Info->get_by_iana_name ('utf-8');            Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) {
526            $charset = Message::Charset::Info->get_by_html_name ('utf-8');
527          ($char_stream, $e_status) = $charset->get_decode_handle          ($char_stream, $e_status) = $charset->get_decode_handle
528              ($byte_stream,              ($byte_stream,
529               byte_buffer => \ $buffer->{buffer});               byte_buffer => \ $buffer->{buffer});
# Line 489  sub parse_byte_string ($$$$;$) { Line 533  sub parse_byte_string ($$$$;$) {
533        ## Step 2        ## Step 2
534        if (defined $self->{input_encoding} and        if (defined $self->{input_encoding} and
535            $self->{input_encoding} eq $charset_name) {            $self->{input_encoding} eq $charset_name) {
536          !!!parse-error (type => 'charset label:matching', ## TODO: type          !!!parse-error (type => 'charset label:matching',
537                          value => $charset_name,                          text => $charset_name,
538                          level => $self->{info_level});                          level => $self->{level}->{info});
539          $self->{confident} = 1;          $self->{confident} = 1;
540          return;          return;
541        }        }
542    
543        !!!parse-error (type => 'charset label detected:'.$self->{input_encoding}.        !!!parse-error (type => 'charset label detected',
544            ':'.$charset_name, level => 'w', token => $token);                        text => $self->{input_encoding},
545                          value => $charset_name,
546                          level => $self->{level}->{warn},
547                          token => $token);
548                
549        ## Step 3        ## Step 3
550        # if (can) {        # if (can) {
# Line 513  sub parse_byte_string ($$$$;$) { Line 560  sub parse_byte_string ($$$$;$) {
560    
561    my $char_onerror = sub {    my $char_onerror = sub {
562      my (undef, $type, %opt) = @_;      my (undef, $type, %opt) = @_;
563      !!!parse-error (%opt, type => $type,      !!!parse-error (layer => 'encode',
564                        %opt, type => $type,
565                      line => $self->{line}, column => $self->{column} + 1);                      line => $self->{line}, column => $self->{column} + 1);
566      if ($opt{octets}) {      if ($opt{octets}) {
567        ${$opt{octets}} = "\x{FFFD}"; # relacement character        ${$opt{octets}} = "\x{FFFD}"; # relacement character
568      }      }
569    };    };
570    $char_stream->onerror ($char_onerror);  
571      my $wrapped_char_stream = $get_wrapper->($char_stream);
572      $wrapped_char_stream->onerror ($char_onerror);
573    
574    my @args = @_; shift @args; # $s    my @args = @_; shift @args; # $s
575    my $return;    my $return;
576    try {    try {
577      $return = $self->parse_char_stream ($char_stream, @args);        $return = $self->parse_char_stream ($wrapped_char_stream, @args);  
578    } catch Whatpm::HTML::RestartParser with {    } catch Whatpm::HTML::RestartParser with {
579      ## NOTE: Invoked after {change_encoding}.      ## NOTE: Invoked after {change_encoding}.
580    
     $self->{input_encoding} = $charset->get_iana_name;  
581      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
582        !!!parse-error (type => 'chardecode:fallback', ## TODO: type name        $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name?
583                        value => $self->{input_encoding},        !!!parse-error (type => 'chardecode:fallback',
584                        level => $self->{unsupported_level},                        level => $self->{level}->{uncertain},
585                        line => 1, column => 1);                        #text => $self->{input_encoding},
586                          line => 1, column => 1,
587                          layer => 'encode');
588      } elsif (not ($e_status &      } elsif (not ($e_status &
589                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
590        !!!parse-error (type => 'chardecode:no error', ## TODO: type name        $self->{input_encoding} = $charset->get_iana_name;
591                        value => $self->{input_encoding},        !!!parse-error (type => 'chardecode:no error',
592                        level => $self->{unsupported_level},                        text => $self->{input_encoding},
593                        line => 1, column => 1);                        level => $self->{level}->{uncertain},
594                          line => 1, column => 1,
595                          layer => 'encode');
596        } else {
597          $self->{input_encoding} = $charset->get_iana_name;
598      }      }
599      $self->{confident} = 1;      $self->{confident} = 1;
600      $char_stream->onerror ($char_onerror);  
601      $return = $self->parse_char_stream ($char_stream, @args);      $wrapped_char_stream = $get_wrapper->($char_stream);
602        $wrapped_char_stream->onerror ($char_onerror);
603    
604        $return = $self->parse_char_stream ($wrapped_char_stream, @args);
605    };    };
606    return $return;    return $return;
607  } # parse_byte_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 557  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  sub parse_char_string ($$$;$) {  sub parse_char_string ($$$;$$) {
619      #my ($self, $s, $doc, $onerror, $get_wrapper) = @_;
620    my $self = shift;    my $self = shift;
621    open my $input, '<:utf8', ref $_[0] ? $_[0] : \($_[0]);    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..$#_]);    return $self->parse_char_stream ($input, @_[1..$#_]);
628  } # parse_char_string  } # parse_char_string
629  *parse_string = \&parse_char_string;  *parse_string = \&parse_char_string; ## NOTE: Alias for backward compatibility.
630    
631  sub parse_char_stream ($$$;$) {  sub parse_char_stream ($$$;$) {
632    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
# Line 585  sub parse_char_stream ($$$;$) { Line 649  sub parse_char_stream ($$$;$) {
649      pop @{$self->{prev_char}};      pop @{$self->{prev_char}};
650      unshift @{$self->{prev_char}}, $self->{next_char};      unshift @{$self->{prev_char}}, $self->{next_char};
651    
652      my $char = $input->getc;      my $char;
653        if (defined $self->{next_next_char}) {
654          $char = $self->{next_next_char};
655          delete $self->{next_next_char};
656        } else {
657          $char = $input->getc;
658        }
659      $self->{next_char} = -1 and return unless defined $char;      $self->{next_char} = -1 and return unless defined $char;
660      $self->{next_char} = ord $char;      $self->{next_char} = ord $char;
661    
# Line 599  sub parse_char_stream ($$$;$) { Line 669  sub parse_char_stream ($$$;$) {
669        $self->{column} = 0;        $self->{column} = 0;
670      } elsif ($self->{next_char} == 0x000D) { # CR      } elsif ($self->{next_char} == 0x000D) { # CR
671        !!!cp ('j2');        !!!cp ('j2');
672    ## TODO: support for abort/streaming
673        my $next = $input->getc;        my $next = $input->getc;
674        if ($next ne "\x0A") {        if (defined $next and $next ne "\x0A") {
675          $input->ungetc ($next);          $self->{next_next_char} = $next;
676        }        }
677        $self->{next_char} = 0x000A; # LF # MUST        $self->{next_char} = 0x000A; # LF # MUST
678        $self->{line}++;        $self->{line}++;
# Line 630  sub parse_char_stream ($$$;$) { Line 701  sub parse_char_stream ($$$;$) {
701                0x10FFFE => 1, 0x10FFFF => 1,                0x10FFFE => 1, 0x10FFFF => 1,
702               }->{$self->{next_char}}) {               }->{$self->{next_char}}) {
703        !!!cp ('j5');        !!!cp ('j5');
704        !!!parse-error (type => 'control char', level => $self->{must_level});        if ($self->{next_char} < 0x10000) {
705  ## TODO: error type documentation          !!!parse-error (type => 'control char',
706                            text => (sprintf 'U+%04X', $self->{next_char}));
707          } else {
708            !!!parse-error (type => 'control char',
709                            text => (sprintf 'U-%08X', $self->{next_char}));
710          }
711      }      }
712    };    };
713    $self->{prev_char} = [-1, -1, -1];    $self->{prev_char} = [-1, -1, -1];
# Line 660  sub parse_char_stream ($$$;$) { Line 736  sub parse_char_stream ($$$;$) {
736  sub new ($) {  sub new ($) {
737    my $class = shift;    my $class = shift;
738    my $self = bless {    my $self = bless {
739      must_level => 'm',      level => {must => 'm',
740      should_level => 's',                should => 's',
741      good_level => 'w',                warn => 'w',
742      warn_level => 'w',                info => 'i',
743      info_level => 'i',                uncertain => 'u'},
     unsupported_level => 'u',  
744    }, $class;    }, $class;
745    $self->{set_next_char} = sub {    $self->{set_next_char} = sub {
746      $self->{next_char} = -1;      $self->{next_char} = -1;
# Line 695  sub RCDATA_CONTENT_MODEL () { CM_ENTITY Line 770  sub RCDATA_CONTENT_MODEL () { CM_ENTITY
770  sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }  sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }
771    
772  sub DATA_STATE () { 0 }  sub DATA_STATE () { 0 }
773  sub ENTITY_DATA_STATE () { 1 }  #sub ENTITY_DATA_STATE () { 1 }
774  sub TAG_OPEN_STATE () { 2 }  sub TAG_OPEN_STATE () { 2 }
775  sub CLOSE_TAG_OPEN_STATE () { 3 }  sub CLOSE_TAG_OPEN_STATE () { 3 }
776  sub TAG_NAME_STATE () { 4 }  sub TAG_NAME_STATE () { 4 }
# Line 706  sub BEFORE_ATTRIBUTE_VALUE_STATE () { 8 Line 781  sub BEFORE_ATTRIBUTE_VALUE_STATE () { 8
781  sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 }  sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 }
782  sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 }  sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 }
783  sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 }  sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 }
784  sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 }  #sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 }
785  sub MARKUP_DECLARATION_OPEN_STATE () { 13 }  sub MARKUP_DECLARATION_OPEN_STATE () { 13 }
786  sub COMMENT_START_STATE () { 14 }  sub COMMENT_START_STATE () { 14 }
787  sub COMMENT_START_DASH_STATE () { 15 }  sub COMMENT_START_DASH_STATE () { 15 }
# Line 729  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STAT Line 804  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STAT
804  sub BOGUS_DOCTYPE_STATE () { 32 }  sub BOGUS_DOCTYPE_STATE () { 32 }
805  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }
806  sub SELF_CLOSING_START_TAG_STATE () { 34 }  sub SELF_CLOSING_START_TAG_STATE () { 34 }
807  sub CDATA_BLOCK_STATE () { 35 }  sub CDATA_SECTION_STATE () { 35 }
808    sub MD_HYPHEN_STATE () { 36 } # "markup declaration open state" in the spec
809    sub MD_DOCTYPE_STATE () { 37 } # "markup declaration open state" in the spec
810    sub MD_CDATA_STATE () { 38 } # "markup declaration open state" in the spec
811    sub CDATA_PCDATA_CLOSE_TAG_STATE () { 39 } # "close tag open state" in the spec
812    sub CDATA_SECTION_MSE1_STATE () { 40 } # "CDATA section state" in the spec
813    sub CDATA_SECTION_MSE2_STATE () { 41 } # "CDATA section state" in the spec
814    sub PUBLIC_STATE () { 42 } # "after DOCTYPE name state" in the spec
815    sub SYSTEM_STATE () { 43 } # "after DOCTYPE name state" in the spec
816    ## NOTE: "Entity data state", "entity in attribute value state", and
817    ## "consume a character reference" algorithm are jointly implemented
818    ## using the following six states:
819    sub ENTITY_STATE () { 44 }
820    sub ENTITY_HASH_STATE () { 45 }
821    sub NCR_NUM_STATE () { 46 }
822    sub HEXREF_X_STATE () { 47 }
823    sub HEXREF_HEX_STATE () { 48 }
824    sub ENTITY_NAME_STATE () { 49 }
825    
826  sub DOCTYPE_TOKEN () { 1 }  sub DOCTYPE_TOKEN () { 1 }
827  sub COMMENT_TOKEN () { 2 }  sub COMMENT_TOKEN () { 2 }
# Line 782  sub IN_COLUMN_GROUP_IM () { 0b10 } Line 874  sub IN_COLUMN_GROUP_IM () { 0b10 }
874  sub _initialize_tokenizer ($) {  sub _initialize_tokenizer ($) {
875    my $self = shift;    my $self = shift;
876    $self->{state} = DATA_STATE; # MUST    $self->{state} = DATA_STATE; # MUST
877      #$self->{state_keyword}; # initialized when used
878      #$self->{entity__value}; # initialized when used
879      #$self->{entity__match}; # initialized when used
880    $self->{content_model} = PCDATA_CONTENT_MODEL; # be    $self->{content_model} = PCDATA_CONTENT_MODEL; # be
881    undef $self->{current_token}; # start tag, end tag, comment, or DOCTYPE    undef $self->{current_token};
882    undef $self->{current_attribute};    undef $self->{current_attribute};
883    undef $self->{last_emitted_start_tag_name};    undef $self->{last_emitted_start_tag_name};
884    undef $self->{last_attribute_value_state};    #$self->{prev_state}; # initialized when used
885    delete $self->{self_closing};    delete $self->{self_closing};
   $self->{char} = [];  
886    # $self->{next_char}    # $self->{next_char}
887    !!!next-input-character;    !!!next-input-character;
888    $self->{token} = [];    $self->{token} = [];
# Line 812  sub _initialize_tokenizer ($) { Line 906  sub _initialize_tokenizer ($) {
906  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|
907  ##     while the token is pushed back to the stack.  ##     while the token is pushed back to the stack.
908    
 ## 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?  
   
909  ## Emitted token MUST immediately be handled by the tree construction state.  ## Emitted token MUST immediately be handled by the tree construction state.
910    
911  ## 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 824  sub _initialize_tokenizer ($) { Line 914  sub _initialize_tokenizer ($) {
914  ## has completed loading.  If one has, then it MUST be executed  ## has completed loading.  If one has, then it MUST be executed
915  ## and removed from the list.  ## and removed from the list.
916    
917  ## NOTE: HTML5 "Writing HTML documents" section, applied to  ## TODO: Polytheistic slash SHOULD NOT be used. (Applied only to atheists.)
918  ## documents and not to user agents and conformance checkers,  ## (This requirement was dropped from HTML5 spec, unfortunately.)
 ## contains some requirements that are not detected by the  
 ## parsing algorithm:  
 ## - Some requirements on character encoding declarations. ## TODO  
 ## - "Elements MUST NOT contain content that their content model disallows."  
 ##   ... Some are parse error, some are not (will be reported by c.c.).  
 ## - Polytheistic slash SHOULD NOT be used. (Applied only to atheists.) ## TODO  
 ## - Text (in elements, attributes, and comments) SHOULD NOT contain  
 ##   control characters other than space characters. ## TODO: (what is control character? C0, C1 and DEL?  Unicode control character?)  
   
 ## TODO: HTML5 poses authors two SHOULD-level requirements that cannot  
 ## be detected by the HTML5 parsing algorithm:  
 ## - Text,  
919    
920  sub _get_next_token ($) {  sub _get_next_token ($) {
921    my $self = shift;    my $self = shift;
# Line 861  sub _get_next_token ($) { Line 939  sub _get_next_token ($) {
939          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA
940              not $self->{escape}) {              not $self->{escape}) {
941            !!!cp (1);            !!!cp (1);
942            $self->{state} = ENTITY_DATA_STATE;            ## NOTE: In the spec, the tokenizer is switched to the
943              ## "entity data state".  In this implementation, the tokenizer
944              ## is switched to the |ENTITY_STATE|, which is an implementation
945              ## of the "consume a character reference" algorithm.
946              $self->{entity_additional} = -1;
947              $self->{prev_state} = DATA_STATE;
948              $self->{state} = ENTITY_STATE;
949            !!!next-input-character;            !!!next-input-character;
950            redo A;            redo A;
951          } else {          } else {
# Line 931  sub _get_next_token ($) { Line 1015  sub _get_next_token ($) {
1015        !!!emit ($token);        !!!emit ($token);
1016    
1017        redo A;        redo A;
     } elsif ($self->{state} == ENTITY_DATA_STATE) {  
       ## (cannot happen in CDATA state)  
   
       my ($l, $c) = ($self->{line_prev}, $self->{column_prev});  
         
       my $token = $self->_tokenize_attempt_to_consume_an_entity (0, -1);  
   
       $self->{state} = DATA_STATE;  
       # next-input-character is already done  
   
       unless (defined $token) {  
         !!!cp (13);  
         !!!emit ({type => CHARACTER_TOKEN, data => '&',  
                   line => $l, column => $c,  
                  });  
       } else {  
         !!!cp (14);  
         !!!emit ($token);  
       }  
   
       redo A;  
1018      } elsif ($self->{state} == TAG_OPEN_STATE) {      } elsif ($self->{state} == TAG_OPEN_STATE) {
1019        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1020          if ($self->{next_char} == 0x002F) { # /          if ($self->{next_char} == 0x002F) { # /
# Line 1048  sub _get_next_token ($) { Line 1111  sub _get_next_token ($) {
1111          die "$0: $self->{content_model} in tag open";          die "$0: $self->{content_model} in tag open";
1112        }        }
1113      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {
1114          ## NOTE: The "close tag open state" in the spec is implemented as
1115          ## |CLOSE_TAG_OPEN_STATE| and |CDATA_PCDATA_CLOSE_TAG_STATE|.
1116    
1117        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"
1118        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1119          if (defined $self->{last_emitted_start_tag_name}) {          if (defined $self->{last_emitted_start_tag_name}) {
1120              $self->{state} = CDATA_PCDATA_CLOSE_TAG_STATE;
1121            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>            $self->{state_keyword} = '';
1122            my @next_char;            ## Reconsume.
1123            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...  
           }  
1124          } else {          } else {
1125            ## No start tag token has ever been emitted            ## No start tag token has ever been emitted
1126              ## NOTE: See <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>.
1127            !!!cp (28);            !!!cp (28);
           # next-input-character is already done  
1128            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1129              ## Reconsume.
1130            !!!emit ({type => CHARACTER_TOKEN, data => '</',            !!!emit ({type => CHARACTER_TOKEN, data => '</',
1131                      line => $l, column => $c,                      line => $l, column => $c,
1132                     });                     });
1133            redo A;            redo A;
1134          }          }
1135        }        }
1136          
1137        if (0x0041 <= $self->{next_char} and        if (0x0041 <= $self->{next_char} and
1138            $self->{next_char} <= 0x005A) { # A..Z            $self->{next_char} <= 0x005A) { # A..Z
1139          !!!cp (29);          !!!cp (29);
# Line 1157  sub _get_next_token ($) { Line 1180  sub _get_next_token ($) {
1180                                    line => $self->{line_prev}, # "<" of "</"                                    line => $self->{line_prev}, # "<" of "</"
1181                                    column => $self->{column_prev} - 1,                                    column => $self->{column_prev} - 1,
1182                                   };                                   };
1183          ## $self->{next_char} is intentionally left as is          ## NOTE: $self->{next_char} is intentionally left as is.
1184          redo A;          ## Although the "anything else" case of the spec not explicitly
1185            ## states that the next input character is to be reconsumed,
1186            ## it will be included to the |data| of the comment token
1187            ## generated from the bogus end tag, as defined in the
1188            ## "bogus comment state" entry.
1189            redo A;
1190          }
1191        } elsif ($self->{state} == CDATA_PCDATA_CLOSE_TAG_STATE) {
1192          my $ch = substr $self->{last_emitted_start_tag_name}, length $self->{state_keyword}, 1;
1193          if (length $ch) {
1194            my $CH = $ch;
1195            $ch =~ tr/a-z/A-Z/;
1196            my $nch = chr $self->{next_char};
1197            if ($nch eq $ch or $nch eq $CH) {
1198              !!!cp (24);
1199              ## Stay in the state.
1200              $self->{state_keyword} .= $nch;
1201              !!!next-input-character;
1202              redo A;
1203            } else {
1204              !!!cp (25);
1205              $self->{state} = DATA_STATE;
1206              ## Reconsume.
1207              !!!emit ({type => CHARACTER_TOKEN,
1208                        data => '</' . $self->{state_keyword},
1209                        line => $self->{line_prev},
1210                        column => $self->{column_prev} - 1 - length $self->{state_keyword},
1211                       });
1212              redo A;
1213            }
1214          } else { # after "<{tag-name}"
1215            unless ({
1216                     0x0009 => 1, # HT
1217                     0x000A => 1, # LF
1218                     0x000B => 1, # VT
1219                     0x000C => 1, # FF
1220                     0x0020 => 1, # SP
1221                     0x003E => 1, # >
1222                     0x002F => 1, # /
1223                     -1 => 1, # EOF
1224                    }->{$self->{next_char}}) {
1225              !!!cp (26);
1226              ## Reconsume.
1227              $self->{state} = DATA_STATE;
1228              !!!emit ({type => CHARACTER_TOKEN,
1229                        data => '</' . $self->{state_keyword},
1230                        line => $self->{line_prev},
1231                        column => $self->{column_prev} - 1 - length $self->{state_keyword},
1232                       });
1233              redo A;
1234            } else {
1235              !!!cp (27);
1236              $self->{current_token}
1237                  = {type => END_TAG_TOKEN,
1238                     tag_name => $self->{last_emitted_start_tag_name},
1239                     line => $self->{line_prev},
1240                     column => $self->{column_prev} - 1 - length $self->{state_keyword}};
1241              $self->{state} = TAG_NAME_STATE;
1242              ## Reconsume.
1243              redo A;
1244            }
1245        }        }
1246      } elsif ($self->{state} == TAG_NAME_STATE) {      } elsif ($self->{state} == TAG_NAME_STATE) {
1247        if ($self->{next_char} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
# Line 1328  sub _get_next_token ($) { Line 1411  sub _get_next_token ($) {
1411          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
1412              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
1413            !!!cp (57);            !!!cp (57);
1414            !!!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});
1415            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{current_attribute} # MUST
1416          } else {          } else {
1417            !!!cp (58);            !!!cp (58);
# Line 1499  sub _get_next_token ($) { Line 1582  sub _get_next_token ($) {
1582    
1583          redo A;          redo A;
1584        } else {        } else {
1585          !!!cp (82);          if ($self->{next_char} == 0x0022 or # "
1586                $self->{next_char} == 0x0027) { # '
1587              !!!cp (78);
1588              !!!parse-error (type => 'bad attribute name');
1589            } else {
1590              !!!cp (82);
1591            }
1592          $self->{current_attribute}          $self->{current_attribute}
1593              = {name => chr ($self->{next_char}),              = {name => chr ($self->{next_char}),
1594                 value => '',                 value => '',
# Line 1534  sub _get_next_token ($) { Line 1623  sub _get_next_token ($) {
1623          !!!next-input-character;          !!!next-input-character;
1624          redo A;          redo A;
1625        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1626            !!!parse-error (type => 'empty unquoted attribute value');
1627          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1628            !!!cp (87);            !!!cp (87);
1629            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
# Line 1598  sub _get_next_token ($) { Line 1688  sub _get_next_token ($) {
1688          redo A;          redo A;
1689        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1690          !!!cp (96);          !!!cp (96);
1691          $self->{last_attribute_value_state} = $self->{state};          ## NOTE: In the spec, the tokenizer is switched to the
1692          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## "entity in attribute value state".  In this implementation, the
1693            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1694            ## implementation of the "consume a character reference" algorithm.
1695            $self->{prev_state} = $self->{state};
1696            $self->{entity_additional} = 0x0022; # "
1697            $self->{state} = ENTITY_STATE;
1698          !!!next-input-character;          !!!next-input-character;
1699          redo A;          redo A;
1700        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
# Line 1640  sub _get_next_token ($) { Line 1735  sub _get_next_token ($) {
1735          redo A;          redo A;
1736        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1737          !!!cp (102);          !!!cp (102);
1738          $self->{last_attribute_value_state} = $self->{state};          ## NOTE: In the spec, the tokenizer is switched to the
1739          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## "entity in attribute value state".  In this implementation, the
1740            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1741            ## implementation of the "consume a character reference" algorithm.
1742            $self->{entity_additional} = 0x0027; # '
1743            $self->{prev_state} = $self->{state};
1744            $self->{state} = ENTITY_STATE;
1745          !!!next-input-character;          !!!next-input-character;
1746          redo A;          redo A;
1747        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
# Line 1686  sub _get_next_token ($) { Line 1786  sub _get_next_token ($) {
1786          redo A;          redo A;
1787        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1788          !!!cp (108);          !!!cp (108);
1789          $self->{last_attribute_value_state} = $self->{state};          ## NOTE: In the spec, the tokenizer is switched to the
1790          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## "entity in attribute value state".  In this implementation, the
1791            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1792            ## implementation of the "consume a character reference" algorithm.
1793            $self->{entity_additional} = -1;
1794            $self->{prev_state} = $self->{state};
1795            $self->{state} = ENTITY_STATE;
1796          !!!next-input-character;          !!!next-input-character;
1797          redo A;          redo A;
1798        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
# Line 1751  sub _get_next_token ($) { Line 1856  sub _get_next_token ($) {
1856          !!!next-input-character;          !!!next-input-character;
1857          redo A;          redo A;
1858        }        }
     } elsif ($self->{state} == ENTITY_IN_ATTRIBUTE_VALUE_STATE) {  
       my $token = $self->_tokenize_attempt_to_consume_an_entity  
           (1,  
            $self->{last_attribute_value_state}  
              == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE ? 0x0022 : # "  
            $self->{last_attribute_value_state}  
              == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE ? 0x0027 : # '  
            -1);  
   
       unless (defined $token) {  
         !!!cp (117);  
         $self->{current_attribute}->{value} .= '&';  
       } else {  
         !!!cp (118);  
         $self->{current_attribute}->{value} .= $token->{data};  
         $self->{current_attribute}->{has_reference} = $token->{has_reference};  
         ## ISSUE: spec says "append the returned character token to the current attribute's value"  
       }  
   
       $self->{state} = $self->{last_attribute_value_state};  
       # next-input-character is already done  
       redo A;  
1859      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {
1860        if ($self->{next_char} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
1861            $self->{next_char} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
# Line 1810  sub _get_next_token ($) { Line 1893  sub _get_next_token ($) {
1893          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1894          !!!next-input-character;          !!!next-input-character;
1895          redo A;          redo A;
1896          } elsif ($self->{next_char} == -1) {
1897            !!!parse-error (type => 'unclosed tag');
1898            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1899              !!!cp (122.3);
1900              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1901            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1902              if ($self->{current_token}->{attributes}) {
1903                !!!cp (122.1);
1904                !!!parse-error (type => 'end tag attribute');
1905              } else {
1906                ## NOTE: This state should never be reached.
1907                !!!cp (122.2);
1908              }
1909            } else {
1910              die "$0: $self->{current_token}->{type}: Unknown token type";
1911            }
1912            $self->{state} = DATA_STATE;
1913            ## Reconsume.
1914            !!!emit ($self->{current_token}); # start tag or end tag
1915            redo A;
1916        } else {        } else {
1917          !!!cp ('124.1');          !!!cp ('124.1');
1918          !!!parse-error (type => 'no space between attributes');          !!!parse-error (type => 'no space between attributes');
# Line 1842  sub _get_next_token ($) { Line 1945  sub _get_next_token ($) {
1945          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
1946    
1947          redo A;          redo A;
1948          } elsif ($self->{next_char} == -1) {
1949            !!!parse-error (type => 'unclosed tag');
1950            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1951              !!!cp (124.7);
1952              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1953            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1954              if ($self->{current_token}->{attributes}) {
1955                !!!cp (124.5);
1956                !!!parse-error (type => 'end tag attribute');
1957              } else {
1958                ## NOTE: This state should never be reached.
1959                !!!cp (124.6);
1960              }
1961            } else {
1962              die "$0: $self->{current_token}->{type}: Unknown token type";
1963            }
1964            $self->{state} = DATA_STATE;
1965            ## Reconsume.
1966            !!!emit ($self->{current_token}); # start tag or end tag
1967            redo A;
1968        } else {        } else {
1969          !!!cp ('124.4');          !!!cp ('124.4');
1970          !!!parse-error (type => 'nestc');          !!!parse-error (type => 'nestc');
# Line 1852  sub _get_next_token ($) { Line 1975  sub _get_next_token ($) {
1975        }        }
1976      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {
1977        ## (only happen if PCDATA state)        ## (only happen if PCDATA state)
         
       ## NOTE: Set by the previous state  
       #my $token = {type => COMMENT_TOKEN, data => ''};  
   
       BC: {  
         if ($self->{next_char} == 0x003E) { # >  
           !!!cp (124);  
           $self->{state} = DATA_STATE;  
           !!!next-input-character;  
   
           !!!emit ($self->{current_token}); # comment  
1978    
1979            redo A;        ## NOTE: Unlike spec's "bogus comment state", this implementation
1980          } elsif ($self->{next_char} == -1) {        ## consumes characters one-by-one basis.
1981            !!!cp (125);        
1982            $self->{state} = DATA_STATE;        if ($self->{next_char} == 0x003E) { # >
1983            ## reconsume          !!!cp (124);
1984            $self->{state} = DATA_STATE;
1985            !!!emit ($self->{current_token}); # comment          !!!next-input-character;
1986    
1987            redo A;          !!!emit ($self->{current_token}); # comment
1988          } else {          redo A;
1989            !!!cp (126);        } elsif ($self->{next_char} == -1) {
1990            $self->{current_token}->{data} .= chr ($self->{next_char}); # comment          !!!cp (125);
1991            !!!next-input-character;          $self->{state} = DATA_STATE;
1992            redo BC;          ## reconsume
         }  
       } # BC  
1993    
1994        die "$0: _get_next_token: unexpected case [BC]";          !!!emit ($self->{current_token}); # comment
1995            redo A;
1996          } else {
1997            !!!cp (126);
1998            $self->{current_token}->{data} .= chr ($self->{next_char}); # comment
1999            ## Stay in the state.
2000            !!!next-input-character;
2001            redo A;
2002          }
2003      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {
2004        ## (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};  
2005                
2006        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
2007            !!!cp (133);
2008            $self->{state} = MD_HYPHEN_STATE;
2009          !!!next-input-character;          !!!next-input-character;
2010          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);  
         }  
2011        } elsif ($self->{next_char} == 0x0044 or # D        } elsif ($self->{next_char} == 0x0044 or # D
2012                 $self->{next_char} == 0x0064) { # d                 $self->{next_char} == 0x0064) { # d
2013            ## ASCII case-insensitive.
2014            !!!cp (130);
2015            $self->{state} = MD_DOCTYPE_STATE;
2016            $self->{state_keyword} = chr $self->{next_char};
2017          !!!next-input-character;          !!!next-input-character;
2018          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);  
         }  
2019        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and
2020                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and
2021                 $self->{next_char} == 0x005B) { # [                 $self->{next_char} == 0x005B) { # [
2022            !!!cp (135.4);                
2023            $self->{state} = MD_CDATA_STATE;
2024            $self->{state_keyword} = '[';
2025          !!!next-input-character;          !!!next-input-character;
2026          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);  
         }  
2027        } else {        } else {
2028          !!!cp (136);          !!!cp (136);
2029        }        }
2030    
2031        !!!parse-error (type => 'bogus comment');        !!!parse-error (type => 'bogus comment',
2032        $self->{next_char} = shift @next_char;                        line => $self->{line_prev},
2033        !!!back-next-input-character (@next_char);                        column => $self->{column_prev} - 1);
2034          ## Reconsume.
2035        $self->{state} = BOGUS_COMMENT_STATE;        $self->{state} = BOGUS_COMMENT_STATE;
2036        $self->{current_token} = {type => COMMENT_TOKEN, data => '',        $self->{current_token} = {type => COMMENT_TOKEN, data => '',
2037                                  line => $l, column => $c,                                  line => $self->{line_prev},
2038                                    column => $self->{column_prev} - 1,
2039                                 };                                 };
2040        redo A;        redo A;
2041              } elsif ($self->{state} == MD_HYPHEN_STATE) {
2042        ## ISSUE: typos in spec: chacacters, is is a parse error        if ($self->{next_char} == 0x002D) { # -
2043        ## 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);
2044            $self->{current_token} = {type => COMMENT_TOKEN, data => '',
2045                                      line => $self->{line_prev},
2046                                      column => $self->{column_prev} - 2,
2047                                     };
2048            $self->{state} = COMMENT_START_STATE;
2049            !!!next-input-character;
2050            redo A;
2051          } else {
2052            !!!cp (128);
2053            !!!parse-error (type => 'bogus comment',
2054                            line => $self->{line_prev},
2055                            column => $self->{column_prev} - 2);
2056            $self->{state} = BOGUS_COMMENT_STATE;
2057            ## Reconsume.
2058            $self->{current_token} = {type => COMMENT_TOKEN,
2059                                      data => '-',
2060                                      line => $self->{line_prev},
2061                                      column => $self->{column_prev} - 2,
2062                                     };
2063            redo A;
2064          }
2065        } elsif ($self->{state} == MD_DOCTYPE_STATE) {
2066          ## ASCII case-insensitive.
2067          if ($self->{next_char} == [
2068                undef,
2069                0x004F, # O
2070                0x0043, # C
2071                0x0054, # T
2072                0x0059, # Y
2073                0x0050, # P
2074              ]->[length $self->{state_keyword}] or
2075              $self->{next_char} == [
2076                undef,
2077                0x006F, # o
2078                0x0063, # c
2079                0x0074, # t
2080                0x0079, # y
2081                0x0070, # p
2082              ]->[length $self->{state_keyword}]) {
2083            !!!cp (131);
2084            ## Stay in the state.
2085            $self->{state_keyword} .= chr $self->{next_char};
2086            !!!next-input-character;
2087            redo A;
2088          } elsif ((length $self->{state_keyword}) == 6 and
2089                   ($self->{next_char} == 0x0045 or # E
2090                    $self->{next_char} == 0x0065)) { # e
2091            !!!cp (129);
2092            $self->{state} = DOCTYPE_STATE;
2093            $self->{current_token} = {type => DOCTYPE_TOKEN,
2094                                      quirks => 1,
2095                                      line => $self->{line_prev},
2096                                      column => $self->{column_prev} - 7,
2097                                     };
2098            !!!next-input-character;
2099            redo A;
2100          } else {
2101            !!!cp (132);        
2102            !!!parse-error (type => 'bogus comment',
2103                            line => $self->{line_prev},
2104                            column => $self->{column_prev} - 1 - length $self->{state_keyword});
2105            $self->{state} = BOGUS_COMMENT_STATE;
2106            ## Reconsume.
2107            $self->{current_token} = {type => COMMENT_TOKEN,
2108                                      data => $self->{state_keyword},
2109                                      line => $self->{line_prev},
2110                                      column => $self->{column_prev} - 1 - length $self->{state_keyword},
2111                                     };
2112            redo A;
2113          }
2114        } elsif ($self->{state} == MD_CDATA_STATE) {
2115          if ($self->{next_char} == {
2116                '[' => 0x0043, # C
2117                '[C' => 0x0044, # D
2118                '[CD' => 0x0041, # A
2119                '[CDA' => 0x0054, # T
2120                '[CDAT' => 0x0041, # A
2121              }->{$self->{state_keyword}}) {
2122            !!!cp (135.1);
2123            ## Stay in the state.
2124            $self->{state_keyword} .= chr $self->{next_char};
2125            !!!next-input-character;
2126            redo A;
2127          } elsif ($self->{state_keyword} eq '[CDATA' and
2128                   $self->{next_char} == 0x005B) { # [
2129            !!!cp (135.2);
2130            $self->{current_token} = {type => CHARACTER_TOKEN,
2131                                      data => '',
2132                                      line => $self->{line_prev},
2133                                      column => $self->{column_prev} - 7};
2134            $self->{state} = CDATA_SECTION_STATE;
2135            !!!next-input-character;
2136            redo A;
2137          } else {
2138            !!!cp (135.3);
2139            !!!parse-error (type => 'bogus comment',
2140                            line => $self->{line_prev},
2141                            column => $self->{column_prev} - 1 - length $self->{state_keyword});
2142            $self->{state} = BOGUS_COMMENT_STATE;
2143            ## Reconsume.
2144            $self->{current_token} = {type => COMMENT_TOKEN,
2145                                      data => $self->{state_keyword},
2146                                      line => $self->{line_prev},
2147                                      column => $self->{column_prev} - 1 - length $self->{state_keyword},
2148                                     };
2149            redo A;
2150          }
2151      } elsif ($self->{state} == COMMENT_START_STATE) {      } elsif ($self->{state} == COMMENT_START_STATE) {
2152        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
2153          !!!cp (137);          !!!cp (137);
# Line 2281  sub _get_next_token ($) { Line 2414  sub _get_next_token ($) {
2414          redo A;          redo A;
2415        } elsif ($self->{next_char} == 0x0050 or # P        } elsif ($self->{next_char} == 0x0050 or # P
2416                 $self->{next_char} == 0x0070) { # p                 $self->{next_char} == 0x0070) { # p
2417            $self->{state} = PUBLIC_STATE;
2418            $self->{state_keyword} = chr $self->{next_char};
2419          !!!next-input-character;          !!!next-input-character;
2420          if ($self->{next_char} == 0x0055 or # U          redo A;
             $self->{next_char} == 0x0075) { # u  
           !!!next-input-character;  
           if ($self->{next_char} == 0x0042 or # B  
               $self->{next_char} == 0x0062) { # b  
             !!!next-input-character;  
             if ($self->{next_char} == 0x004C or # L  
                 $self->{next_char} == 0x006C) { # l  
               !!!next-input-character;  
               if ($self->{next_char} == 0x0049 or # I  
                   $self->{next_char} == 0x0069) { # i  
                 !!!next-input-character;  
                 if ($self->{next_char} == 0x0043 or # C  
                     $self->{next_char} == 0x0063) { # c  
                   !!!cp (168);  
                   $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;  
                   !!!next-input-character;  
                   redo A;  
                 } else {  
                   !!!cp (169);  
                 }  
               } else {  
                 !!!cp (170);  
               }  
             } else {  
               !!!cp (171);  
             }  
           } else {  
             !!!cp (172);  
           }  
         } else {  
           !!!cp (173);  
         }  
   
         #  
2421        } elsif ($self->{next_char} == 0x0053 or # S        } elsif ($self->{next_char} == 0x0053 or # S
2422                 $self->{next_char} == 0x0073) { # s                 $self->{next_char} == 0x0073) { # s
2423            $self->{state} = SYSTEM_STATE;
2424            $self->{state_keyword} = chr $self->{next_char};
2425          !!!next-input-character;          !!!next-input-character;
2426          if ($self->{next_char} == 0x0059 or # Y          redo A;
             $self->{next_char} == 0x0079) { # y  
           !!!next-input-character;  
           if ($self->{next_char} == 0x0053 or # S  
               $self->{next_char} == 0x0073) { # s  
             !!!next-input-character;  
             if ($self->{next_char} == 0x0054 or # T  
                 $self->{next_char} == 0x0074) { # t  
               !!!next-input-character;  
               if ($self->{next_char} == 0x0045 or # E  
                   $self->{next_char} == 0x0065) { # e  
                 !!!next-input-character;  
                 if ($self->{next_char} == 0x004D or # M  
                     $self->{next_char} == 0x006D) { # m  
                   !!!cp (174);  
                   $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;  
                   !!!next-input-character;  
                   redo A;  
                 } else {  
                   !!!cp (175);  
                 }  
               } else {  
                 !!!cp (176);  
               }  
             } else {  
               !!!cp (177);  
             }  
           } else {  
             !!!cp (178);  
           }  
         } else {  
           !!!cp (179);  
         }  
   
         #  
2427        } else {        } else {
2428          !!!cp (180);          !!!cp (180);
2429            !!!parse-error (type => 'string after DOCTYPE name');
2430            $self->{current_token}->{quirks} = 1;
2431    
2432            $self->{state} = BOGUS_DOCTYPE_STATE;
2433          !!!next-input-character;          !!!next-input-character;
2434          #          redo A;
2435        }        }
2436        } elsif ($self->{state} == PUBLIC_STATE) {
2437          ## ASCII case-insensitive
2438          if ($self->{next_char} == [
2439                undef,
2440                0x0055, # U
2441                0x0042, # B
2442                0x004C, # L
2443                0x0049, # I
2444              ]->[length $self->{state_keyword}] or
2445              $self->{next_char} == [
2446                undef,
2447                0x0075, # u
2448                0x0062, # b
2449                0x006C, # l
2450                0x0069, # i
2451              ]->[length $self->{state_keyword}]) {
2452            !!!cp (175);
2453            ## Stay in the state.
2454            $self->{state_keyword} .= chr $self->{next_char};
2455            !!!next-input-character;
2456            redo A;
2457          } elsif ((length $self->{state_keyword}) == 5 and
2458                   ($self->{next_char} == 0x0043 or # C
2459                    $self->{next_char} == 0x0063)) { # c
2460            !!!cp (168);
2461            $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
2462            !!!next-input-character;
2463            redo A;
2464          } else {
2465            !!!cp (169);
2466            !!!parse-error (type => 'string after DOCTYPE name',
2467                            line => $self->{line_prev},
2468                            column => $self->{column_prev} + 1 - length $self->{state_keyword});
2469            $self->{current_token}->{quirks} = 1;
2470    
2471        !!!parse-error (type => 'string after DOCTYPE name');          $self->{state} = BOGUS_DOCTYPE_STATE;
2472        $self->{current_token}->{quirks} = 1;          ## Reconsume.
2473            redo A;
2474          }
2475        } elsif ($self->{state} == SYSTEM_STATE) {
2476          ## ASCII case-insensitive
2477          if ($self->{next_char} == [
2478                undef,
2479                0x0059, # Y
2480                0x0053, # S
2481                0x0054, # T
2482                0x0045, # E
2483              ]->[length $self->{state_keyword}] or
2484              $self->{next_char} == [
2485                undef,
2486                0x0079, # y
2487                0x0073, # s
2488                0x0074, # t
2489                0x0065, # e
2490              ]->[length $self->{state_keyword}]) {
2491            !!!cp (170);
2492            ## Stay in the state.
2493            $self->{state_keyword} .= chr $self->{next_char};
2494            !!!next-input-character;
2495            redo A;
2496          } elsif ((length $self->{state_keyword}) == 5 and
2497                   ($self->{next_char} == 0x004D or # M
2498                    $self->{next_char} == 0x006D)) { # m
2499            !!!cp (171);
2500            $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2501            !!!next-input-character;
2502            redo A;
2503          } else {
2504            !!!cp (172);
2505            !!!parse-error (type => 'string after DOCTYPE name',
2506                            line => $self->{line_prev},
2507                            column => $self->{column_prev} + 1 - length $self->{state_keyword});
2508            $self->{current_token}->{quirks} = 1;
2509    
2510        $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2511        # next-input-character is already done          ## Reconsume.
2512        redo A;          redo A;
2513          }
2514      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {
2515        if ({        if ({
2516              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
# Line 2599  sub _get_next_token ($) { Line 2743  sub _get_next_token ($) {
2743          redo A;          redo A;
2744        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2745          !!!cp (208);          !!!cp (208);
2746          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2747    
2748          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2749          !!!next-input-character;          !!!next-input-character;
# Line 2635  sub _get_next_token ($) { Line 2779  sub _get_next_token ($) {
2779          redo A;          redo A;
2780        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2781          !!!cp (212);          !!!cp (212);
2782          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2783    
2784          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2785          !!!next-input-character;          !!!next-input-character;
# Line 2683  sub _get_next_token ($) { Line 2827  sub _get_next_token ($) {
2827        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
2828          !!!cp (217);          !!!cp (217);
2829          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
   
2830          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2831          ## reconsume          ## reconsume
2832    
# Line 2724  sub _get_next_token ($) { Line 2867  sub _get_next_token ($) {
2867          !!!next-input-character;          !!!next-input-character;
2868          redo A;          redo A;
2869        }        }
2870      } elsif ($self->{state} == CDATA_BLOCK_STATE) {      } elsif ($self->{state} == CDATA_SECTION_STATE) {
2871        my $s = '';        ## NOTE: "CDATA section state" in the state is jointly implemented
2872          ## by three states, |CDATA_SECTION_STATE|, |CDATA_SECTION_MSE1_STATE|,
2873          ## and |CDATA_SECTION_MSE2_STATE|.
2874                
2875        my ($l, $c) = ($self->{line}, $self->{column});        if ($self->{next_char} == 0x005D) { # ]
2876            !!!cp (221.1);
2877            $self->{state} = CDATA_SECTION_MSE1_STATE;
2878            !!!next-input-character;
2879            redo A;
2880          } elsif ($self->{next_char} == -1) {
2881            $self->{state} = DATA_STATE;
2882            !!!next-input-character;
2883            if (length $self->{current_token}->{data}) { # character
2884              !!!cp (221.2);
2885              !!!emit ($self->{current_token}); # character
2886            } else {
2887              !!!cp (221.3);
2888              ## No token to emit. $self->{current_token} is discarded.
2889            }        
2890            redo A;
2891          } else {
2892            !!!cp (221.4);
2893            $self->{current_token}->{data} .= chr $self->{next_char};
2894            ## Stay in the state.
2895            !!!next-input-character;
2896            redo A;
2897          }
2898    
2899        CS: while ($self->{next_char} != -1) {        ## ISSUE: "text tokens" in spec.
2900          if ($self->{next_char} == 0x005D) { # ]      } elsif ($self->{state} == CDATA_SECTION_MSE1_STATE) {
2901            !!!next-input-character;        if ($self->{next_char} == 0x005D) { # ]
2902            if ($self->{next_char} == 0x005D) { # ]          !!!cp (221.5);
2903              !!!next-input-character;          $self->{state} = CDATA_SECTION_MSE2_STATE;
2904              MDC: {          !!!next-input-character;
2905                if ($self->{next_char} == 0x003E) { # >          redo A;
2906                  !!!cp (221.1);        } else {
2907                  !!!next-input-character;          !!!cp (221.6);
2908                  last CS;          $self->{current_token}->{data} .= ']';
2909                } elsif ($self->{next_char} == 0x005D) { # ]          $self->{state} = CDATA_SECTION_STATE;
2910                  !!!cp (221.2);          ## Reconsume.
2911                  $s .= ']';          redo A;
2912                  !!!next-input-character;        }
2913                  redo MDC;      } elsif ($self->{state} == CDATA_SECTION_MSE2_STATE) {
2914                } else {        if ($self->{next_char} == 0x003E) { # >
2915                  !!!cp (221.3);          $self->{state} = DATA_STATE;
2916                  $s .= ']]';          !!!next-input-character;
2917                  #          if (length $self->{current_token}->{data}) { # character
2918                }            !!!cp (221.7);
2919              } # MDC            !!!emit ($self->{current_token}); # character
           } else {  
             !!!cp (221.4);  
             $s .= ']';  
             #  
           }  
2920          } else {          } else {
2921            !!!cp (221.5);            !!!cp (221.8);
2922            #            ## No token to emit. $self->{current_token} is discarded.
2923          }          }
2924          $s .= chr $self->{next_char};          redo A;
2925          } elsif ($self->{next_char} == 0x005D) { # ]
2926            !!!cp (221.9); # character
2927            $self->{current_token}->{data} .= ']'; ## Add first "]" of "]]]".
2928            ## Stay in the state.
2929          !!!next-input-character;          !!!next-input-character;
2930        } # 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});  
2931        } else {        } else {
2932          !!!cp (221.7);          !!!cp (221.11);
2933            $self->{current_token}->{data} .= ']]'; # character
2934            $self->{state} = CDATA_SECTION_STATE;
2935            ## Reconsume.
2936            redo A;
2937          }
2938        } elsif ($self->{state} == ENTITY_STATE) {
2939          if ({
2940            0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,
2941            0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, &
2942            $self->{entity_additional} => 1,
2943          }->{$self->{next_char}}) {
2944            !!!cp (1001);
2945            ## Don't consume
2946            ## No error
2947            ## Return nothing.
2948            #
2949          } elsif ($self->{next_char} == 0x0023) { # #
2950            !!!cp (999);
2951            $self->{state} = ENTITY_HASH_STATE;
2952            $self->{state_keyword} = '#';
2953            !!!next-input-character;
2954            redo A;
2955          } elsif ((0x0041 <= $self->{next_char} and
2956                    $self->{next_char} <= 0x005A) or # A..Z
2957                   (0x0061 <= $self->{next_char} and
2958                    $self->{next_char} <= 0x007A)) { # a..z
2959            !!!cp (998);
2960            require Whatpm::_NamedEntityList;
2961            $self->{state} = ENTITY_NAME_STATE;
2962            $self->{state_keyword} = chr $self->{next_char};
2963            $self->{entity__value} = $self->{state_keyword};
2964            $self->{entity__match} = 0;
2965            !!!next-input-character;
2966            redo A;
2967          } else {
2968            !!!cp (1027);
2969            !!!parse-error (type => 'bare ero');
2970            ## Return nothing.
2971            #
2972        }        }
2973    
2974        redo A;        ## NOTE: No character is consumed by the "consume a character
2975          ## reference" algorithm.  In other word, there is an "&" character
2976        ## ISSUE: "text tokens" in spec.        ## that does not introduce a character reference, which would be
2977        ## TODO: Streaming support        ## appended to the parent element or the attribute value in later
2978      } else {        ## process of the tokenizer.
2979        die "$0: $self->{state}: Unknown state";  
2980      }        if ($self->{prev_state} == DATA_STATE) {
2981    } # A            !!!cp (997);
2982            $self->{state} = $self->{prev_state};
2983    die "$0: _get_next_token: unexpected case";          ## Reconsume.
2984  } # _get_next_token          !!!emit ({type => CHARACTER_TOKEN, data => '&',
2985                      line => $self->{line_prev},
2986  sub _tokenize_attempt_to_consume_an_entity ($$$) {                    column => $self->{column_prev},
2987    my ($self, $in_attr, $additional) = @_;                   });
2988            redo A;
2989    my ($l, $c) = ($self->{line_prev}, $self->{column_prev});        } else {
2990            !!!cp (996);
2991            $self->{current_attribute}->{value} .= '&';
2992            $self->{state} = $self->{prev_state};
2993            ## Reconsume.
2994            redo A;
2995          }
2996        } elsif ($self->{state} == ENTITY_HASH_STATE) {
2997          if ($self->{next_char} == 0x0078 or # x
2998              $self->{next_char} == 0x0058) { # X
2999            !!!cp (995);
3000            $self->{state} = HEXREF_X_STATE;
3001            $self->{state_keyword} .= chr $self->{next_char};
3002            !!!next-input-character;
3003            redo A;
3004          } elsif (0x0030 <= $self->{next_char} and
3005                   $self->{next_char} <= 0x0039) { # 0..9
3006            !!!cp (994);
3007            $self->{state} = NCR_NUM_STATE;
3008            $self->{state_keyword} = $self->{next_char} - 0x0030;
3009            !!!next-input-character;
3010            redo A;
3011          } else {
3012            !!!parse-error (type => 'bare nero',
3013                            line => $self->{line_prev},
3014                            column => $self->{column_prev} - 1);
3015    
3016    if ({          ## NOTE: According to the spec algorithm, nothing is returned,
3017         0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,          ## and then "&#" is appended to the parent element or the attribute
3018         0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR          ## value in the later processing.
3019         $additional => 1,  
3020        }->{$self->{next_char}}) {          if ($self->{prev_state} == DATA_STATE) {
3021      !!!cp (1001);            !!!cp (1019);
3022      ## Don't consume            $self->{state} = $self->{prev_state};
3023      ## No error            ## Reconsume.
3024      return undef;            !!!emit ({type => CHARACTER_TOKEN,
3025    } elsif ($self->{next_char} == 0x0023) { # #                      data => '&#',
3026      !!!next-input-character;                      line => $self->{line_prev},
3027      if ($self->{next_char} == 0x0078 or # x                      column => $self->{column_prev} - 1,
3028          $self->{next_char} == 0x0058) { # X                     });
3029        my $code;            redo A;
       X: {  
         my $x_char = $self->{next_char};  
         !!!next-input-character;  
         if (0x0030 <= $self->{next_char} and  
             $self->{next_char} <= 0x0039) { # 0..9  
           !!!cp (1002);  
           $code ||= 0;  
           $code *= 0x10;  
           $code += $self->{next_char} - 0x0030;  
           redo X;  
         } elsif (0x0061 <= $self->{next_char} and  
                  $self->{next_char} <= 0x0066) { # a..f  
           !!!cp (1003);  
           $code ||= 0;  
           $code *= 0x10;  
           $code += $self->{next_char} - 0x0060 + 9;  
           redo X;  
         } elsif (0x0041 <= $self->{next_char} and  
                  $self->{next_char} <= 0x0046) { # A..F  
           !!!cp (1004);  
           $code ||= 0;  
           $code *= 0x10;  
           $code += $self->{next_char} - 0x0040 + 9;  
           redo X;  
         } elsif (not defined $code) { # no hexadecimal digit  
           !!!cp (1005);  
           !!!parse-error (type => 'bare hcro', line => $l, column => $c);  
           !!!back-next-input-character ($x_char, $self->{next_char});  
           $self->{next_char} = 0x0023; # #  
           return undef;  
         } elsif ($self->{next_char} == 0x003B) { # ;  
           !!!cp (1006);  
           !!!next-input-character;  
3030          } else {          } else {
3031            !!!cp (1007);            !!!cp (993);
3032            !!!parse-error (type => 'no refc', line => $l, column => $c);            $self->{current_attribute}->{value} .= '&#';
3033              $self->{state} = $self->{prev_state};
3034              ## Reconsume.
3035              redo A;
3036          }          }
3037          }
3038          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {      } elsif ($self->{state} == NCR_NUM_STATE) {
3039            !!!cp (1008);        if (0x0030 <= $self->{next_char} and
3040            !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);            $self->{next_char} <= 0x0039) { # 0..9
           $code = 0xFFFD;  
         } elsif ($code > 0x10FFFF) {  
           !!!cp (1009);  
           !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);  
           $code = 0xFFFD;  
         } elsif ($code == 0x000D) {  
           !!!cp (1010);  
           !!!parse-error (type => 'CR character reference', line => $l, column => $c);  
           $code = 0x000A;  
         } elsif (0x80 <= $code and $code <= 0x9F) {  
           !!!cp (1011);  
           !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);  
           $code = $c1_entity_char->{$code};  
         }  
   
         return {type => CHARACTER_TOKEN, data => chr $code,  
                 has_reference => 1,  
                 line => $l, column => $c,  
                };  
       } # X  
     } elsif (0x0030 <= $self->{next_char} and  
              $self->{next_char} <= 0x0039) { # 0..9  
       my $code = $self->{next_char} - 0x0030;  
       !!!next-input-character;  
         
       while (0x0030 <= $self->{next_char} and  
                 $self->{next_char} <= 0x0039) { # 0..9  
3041          !!!cp (1012);          !!!cp (1012);
3042          $code *= 10;          $self->{state_keyword} *= 10;
3043          $code += $self->{next_char} - 0x0030;          $self->{state_keyword} += $self->{next_char} - 0x0030;
3044                    
3045            ## Stay in the state.
3046          !!!next-input-character;          !!!next-input-character;
3047        }          redo A;
3048          } elsif ($self->{next_char} == 0x003B) { # ;
       if ($self->{next_char} == 0x003B) { # ;  
3049          !!!cp (1013);          !!!cp (1013);
3050          !!!next-input-character;          !!!next-input-character;
3051            #
3052        } else {        } else {
3053          !!!cp (1014);          !!!cp (1014);
3054          !!!parse-error (type => 'no refc', line => $l, column => $c);          !!!parse-error (type => 'no refc');
3055            ## Reconsume.
3056            #
3057        }        }
3058    
3059          my $code = $self->{state_keyword};
3060          my $l = $self->{line_prev};
3061          my $c = $self->{column_prev};
3062        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3063          !!!cp (1015);          !!!cp (1015);
3064          !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3065                            text => (sprintf 'U+%04X', $code),
3066                            line => $l, column => $c);
3067          $code = 0xFFFD;          $code = 0xFFFD;
3068        } elsif ($code > 0x10FFFF) {        } elsif ($code > 0x10FFFF) {
3069          !!!cp (1016);          !!!cp (1016);
3070          !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3071                            text => (sprintf 'U-%08X', $code),
3072                            line => $l, column => $c);
3073          $code = 0xFFFD;          $code = 0xFFFD;
3074        } elsif ($code == 0x000D) {        } elsif ($code == 0x000D) {
3075          !!!cp (1017);          !!!cp (1017);
3076          !!!parse-error (type => 'CR character reference', line => $l, column => $c);          !!!parse-error (type => 'CR character reference',
3077                            line => $l, column => $c);
3078          $code = 0x000A;          $code = 0x000A;
3079        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
3080          !!!cp (1018);          !!!cp (1018);
3081          !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'C1 character reference',
3082                            text => (sprintf 'U+%04X', $code),
3083                            line => $l, column => $c);
3084          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
3085        }        }
3086          
3087        return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1,        if ($self->{prev_state} == DATA_STATE) {
3088                line => $l, column => $c,          !!!cp (992);
3089               };          $self->{state} = $self->{prev_state};
3090      } else {          ## Reconsume.
3091        !!!cp (1019);          !!!emit ({type => CHARACTER_TOKEN, data => chr $code,
3092        !!!parse-error (type => 'bare nero', line => $l, column => $c);                    line => $l, column => $c,
3093        !!!back-next-input-character ($self->{next_char});                   });
3094        $self->{next_char} = 0x0023; # #          redo A;
3095        return undef;        } else {
3096      }          !!!cp (991);
3097    } elsif ((0x0041 <= $self->{next_char} and          $self->{current_attribute}->{value} .= chr $code;
3098              $self->{next_char} <= 0x005A) or          $self->{current_attribute}->{has_reference} = 1;
3099             (0x0061 <= $self->{next_char} and          $self->{state} = $self->{prev_state};
3100              $self->{next_char} <= 0x007A)) {          ## Reconsume.
3101      my $entity_name = chr $self->{next_char};          redo A;
3102      !!!next-input-character;        }
3103        } elsif ($self->{state} == HEXREF_X_STATE) {
3104      my $value = $entity_name;        if ((0x0030 <= $self->{next_char} and $self->{next_char} <= 0x0039) or
3105      my $match = 0;            (0x0041 <= $self->{next_char} and $self->{next_char} <= 0x0046) or
3106      require Whatpm::_NamedEntityList;            (0x0061 <= $self->{next_char} and $self->{next_char} <= 0x0066)) {
3107      our $EntityChar;          # 0..9, A..F, a..f
3108            !!!cp (990);
3109      while (length $entity_name < 30 and          $self->{state} = HEXREF_HEX_STATE;
3110             ## NOTE: Some number greater than the maximum length of entity name          $self->{state_keyword} = 0;
3111             ((0x0041 <= $self->{next_char} and # a          ## Reconsume.
3112               $self->{next_char} <= 0x005A) or # x          redo A;
3113              (0x0061 <= $self->{next_char} and # a        } else {
3114               $self->{next_char} <= 0x007A) or # z          !!!parse-error (type => 'bare hcro',
3115              (0x0030 <= $self->{next_char} and # 0                          line => $self->{line_prev},
3116               $self->{next_char} <= 0x0039) or # 9                          column => $self->{column_prev} - 2);
3117              $self->{next_char} == 0x003B)) { # ;  
3118        $entity_name .= chr $self->{next_char};          ## NOTE: According to the spec algorithm, nothing is returned,
3119        if (defined $EntityChar->{$entity_name}) {          ## and then "&#" followed by "X" or "x" is appended to the parent
3120          if ($self->{next_char} == 0x003B) { # ;          ## element or the attribute value in the later processing.
3121            !!!cp (1020);  
3122            $value = $EntityChar->{$entity_name};          if ($self->{prev_state} == DATA_STATE) {
3123            $match = 1;            !!!cp (1005);
3124            !!!next-input-character;            $self->{state} = $self->{prev_state};
3125            last;            ## Reconsume.
3126              !!!emit ({type => CHARACTER_TOKEN,
3127                        data => '&' . $self->{state_keyword},
3128                        line => $self->{line_prev},
3129                        column => $self->{column_prev} - length $self->{state_keyword},
3130                       });
3131              redo A;
3132            } else {
3133              !!!cp (989);
3134              $self->{current_attribute}->{value} .= '&' . $self->{state_keyword};
3135              $self->{state} = $self->{prev_state};
3136              ## Reconsume.
3137              redo A;
3138            }
3139          }
3140        } elsif ($self->{state} == HEXREF_HEX_STATE) {
3141          if (0x0030 <= $self->{next_char} and $self->{next_char} <= 0x0039) {
3142            # 0..9
3143            !!!cp (1002);
3144            $self->{state_keyword} *= 0x10;
3145            $self->{state_keyword} += $self->{next_char} - 0x0030;
3146            ## Stay in the state.
3147            !!!next-input-character;
3148            redo A;
3149          } elsif (0x0061 <= $self->{next_char} and
3150                   $self->{next_char} <= 0x0066) { # a..f
3151            !!!cp (1003);
3152            $self->{state_keyword} *= 0x10;
3153            $self->{state_keyword} += $self->{next_char} - 0x0060 + 9;
3154            ## Stay in the state.
3155            !!!next-input-character;
3156            redo A;
3157          } elsif (0x0041 <= $self->{next_char} and
3158                   $self->{next_char} <= 0x0046) { # A..F
3159            !!!cp (1004);
3160            $self->{state_keyword} *= 0x10;
3161            $self->{state_keyword} += $self->{next_char} - 0x0040 + 9;
3162            ## Stay in the state.
3163            !!!next-input-character;
3164            redo A;
3165          } elsif ($self->{next_char} == 0x003B) { # ;
3166            !!!cp (1006);
3167            !!!next-input-character;
3168            #
3169          } else {
3170            !!!cp (1007);
3171            !!!parse-error (type => 'no refc',
3172                            line => $self->{line},
3173                            column => $self->{column});
3174            ## Reconsume.
3175            #
3176          }
3177    
3178          my $code = $self->{state_keyword};
3179          my $l = $self->{line_prev};
3180          my $c = $self->{column_prev};
3181          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3182            !!!cp (1008);
3183            !!!parse-error (type => 'invalid character reference',
3184                            text => (sprintf 'U+%04X', $code),
3185                            line => $l, column => $c);
3186            $code = 0xFFFD;
3187          } elsif ($code > 0x10FFFF) {
3188            !!!cp (1009);
3189            !!!parse-error (type => 'invalid character reference',
3190                            text => (sprintf 'U-%08X', $code),
3191                            line => $l, column => $c);
3192            $code = 0xFFFD;
3193          } elsif ($code == 0x000D) {
3194            !!!cp (1010);
3195            !!!parse-error (type => 'CR character reference', line => $l, column => $c);
3196            $code = 0x000A;
3197          } elsif (0x80 <= $code and $code <= 0x9F) {
3198            !!!cp (1011);
3199            !!!parse-error (type => 'C1 character reference', text => (sprintf 'U+%04X', $code), line => $l, column => $c);
3200            $code = $c1_entity_char->{$code};
3201          }
3202    
3203          if ($self->{prev_state} == DATA_STATE) {
3204            !!!cp (988);
3205            $self->{state} = $self->{prev_state};
3206            ## Reconsume.
3207            !!!emit ({type => CHARACTER_TOKEN, data => chr $code,
3208                      line => $l, column => $c,
3209                     });
3210            redo A;
3211          } else {
3212            !!!cp (987);
3213            $self->{current_attribute}->{value} .= chr $code;
3214            $self->{current_attribute}->{has_reference} = 1;
3215            $self->{state} = $self->{prev_state};
3216            ## Reconsume.
3217            redo A;
3218          }
3219        } elsif ($self->{state} == ENTITY_NAME_STATE) {
3220          if (length $self->{state_keyword} < 30 and
3221              ## NOTE: Some number greater than the maximum length of entity name
3222              ((0x0041 <= $self->{next_char} and # a
3223                $self->{next_char} <= 0x005A) or # x
3224               (0x0061 <= $self->{next_char} and # a
3225                $self->{next_char} <= 0x007A) or # z
3226               (0x0030 <= $self->{next_char} and # 0
3227                $self->{next_char} <= 0x0039) or # 9
3228               $self->{next_char} == 0x003B)) { # ;
3229            our $EntityChar;
3230            $self->{state_keyword} .= chr $self->{next_char};
3231            if (defined $EntityChar->{$self->{state_keyword}}) {
3232              if ($self->{next_char} == 0x003B) { # ;
3233                !!!cp (1020);
3234                $self->{entity__value} = $EntityChar->{$self->{state_keyword}};
3235                $self->{entity__match} = 1;
3236                !!!next-input-character;
3237                #
3238              } else {
3239                !!!cp (1021);
3240                $self->{entity__value} = $EntityChar->{$self->{state_keyword}};
3241                $self->{entity__match} = -1;
3242                ## Stay in the state.
3243                !!!next-input-character;
3244                redo A;
3245              }
3246          } else {          } else {
3247            !!!cp (1021);            !!!cp (1022);
3248            $value = $EntityChar->{$entity_name};            $self->{entity__value} .= chr $self->{next_char};
3249            $match = -1;            $self->{entity__match} *= 2;
3250              ## Stay in the state.
3251            !!!next-input-character;            !!!next-input-character;
3252              redo A;
3253            }
3254          }
3255    
3256          my $data;
3257          my $has_ref;
3258          if ($self->{entity__match} > 0) {
3259            !!!cp (1023);
3260            $data = $self->{entity__value};
3261            $has_ref = 1;
3262            #
3263          } elsif ($self->{entity__match} < 0) {
3264            !!!parse-error (type => 'no refc');
3265            if ($self->{prev_state} != DATA_STATE and # in attribute
3266                $self->{entity__match} < -1) {
3267              !!!cp (1024);
3268              $data = '&' . $self->{state_keyword};
3269              #
3270            } else {
3271              !!!cp (1025);
3272              $data = $self->{entity__value};
3273              $has_ref = 1;
3274              #
3275          }          }
3276        } else {        } else {
3277          !!!cp (1022);          !!!cp (1026);
3278          $value .= chr $self->{next_char};          !!!parse-error (type => 'bare ero',
3279          $match *= 2;                          line => $self->{line_prev},
3280          !!!next-input-character;                          column => $self->{column_prev});
3281            $data = '&' . $self->{state_keyword};
3282            #
3283        }        }
3284      }    
3285              ## NOTE: In these cases, when a character reference is found,
3286      if ($match > 0) {        ## it is consumed and a character token is returned, or, otherwise,
3287        !!!cp (1023);        ## nothing is consumed and returned, according to the spec algorithm.
3288        return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,        ## In this implementation, anything that has been examined by the
3289                line => $l, column => $c,        ## tokenizer is appended to the parent element or the attribute value
3290               };        ## as string, either literal string when no character reference or
3291      } elsif ($match < 0) {        ## entity-replaced string otherwise, in this stage, since any characters
3292        !!!parse-error (type => 'no refc', line => $l, column => $c);        ## that would not be consumed are appended in the data state or in an
3293        if ($in_attr and $match < -1) {        ## appropriate attribute value state anyway.
3294          !!!cp (1024);  
3295          return {type => CHARACTER_TOKEN, data => '&'.$entity_name,        if ($self->{prev_state} == DATA_STATE) {
3296                  line => $l, column => $c,          !!!cp (986);
3297                 };          $self->{state} = $self->{prev_state};
3298        } else {          ## Reconsume.
3299          !!!cp (1025);          !!!emit ({type => CHARACTER_TOKEN,
3300          return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,                    data => $data,
3301                  line => $l, column => $c,                    line => $self->{line_prev},
3302                 };                    column => $self->{column_prev} + 1 - length $self->{state_keyword},
3303                     });
3304            redo A;
3305          } else {
3306            !!!cp (985);
3307            $self->{current_attribute}->{value} .= $data;
3308            $self->{current_attribute}->{has_reference} = 1 if $has_ref;
3309            $self->{state} = $self->{prev_state};
3310            ## Reconsume.
3311            redo A;
3312        }        }
3313      } else {      } else {
3314        !!!cp (1026);        die "$0: $self->{state}: Unknown state";
       !!!parse-error (type => 'bare ero', line => $l, column => $c);  
       ## NOTE: "No characters are consumed" in the spec.  
       return {type => CHARACTER_TOKEN, data => '&'.$value,  
               line => $l, column => $c,  
              };  
3315      }      }
3316    } else {    } # A  
3317      !!!cp (1027);  
3318      ## no characters are consumed    die "$0: _get_next_token: unexpected case";
3319      !!!parse-error (type => 'bare ero', line => $l, column => $c);  } # _get_next_token
     return undef;  
   }  
 } # _tokenize_attempt_to_consume_an_entity  
3320    
3321  sub _initialize_tree_constructor ($) {  sub _initialize_tree_constructor ($) {
3322    my $self = shift;    my $self = shift;
# Line 3000  sub _initialize_tree_constructor ($) { Line 3325  sub _initialize_tree_constructor ($) {
3325    ## TODO: Turn mutation events off # MUST    ## TODO: Turn mutation events off # MUST
3326    ## TODO: Turn loose Document option (manakai extension) on    ## TODO: Turn loose Document option (manakai extension) on
3327    $self->{document}->manakai_is_html (1); # MUST    $self->{document}->manakai_is_html (1); # MUST
3328      $self->{document}->set_user_data (manakai_source_line => 1);
3329      $self->{document}->set_user_data (manakai_source_column => 1);
3330  } # _initialize_tree_constructor  } # _initialize_tree_constructor
3331    
3332  sub _terminate_tree_constructor ($) {  sub _terminate_tree_constructor ($) {
# Line 3054  sub _tree_construction_initial ($) { Line 3381  sub _tree_construction_initial ($) {
3381        ## language.        ## language.
3382        my $doctype_name = $token->{name};        my $doctype_name = $token->{name};
3383        $doctype_name = '' unless defined $doctype_name;        $doctype_name = '' unless defined $doctype_name;
3384        $doctype_name =~ tr/a-z/A-Z/;        $doctype_name =~ tr/a-z/A-Z/; # ASCII case-insensitive
3385        if (not defined $token->{name} or # <!DOCTYPE>        if (not defined $token->{name} or # <!DOCTYPE>
           defined $token->{public_identifier} or  
3386            defined $token->{system_identifier}) {            defined $token->{system_identifier}) {
3387          !!!cp ('t1');          !!!cp ('t1');
3388          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3389        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
3390          !!!cp ('t2');          !!!cp ('t2');
         ## ISSUE: ASCII case-insensitive? (in fact it does not matter)  
3391          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3392          } elsif (defined $token->{public_identifier}) {
3393            if ($token->{public_identifier} eq 'XSLT-compat') {
3394              !!!cp ('t1.2');
3395              !!!parse-error (type => 'XSLT-compat', token => $token,
3396                              level => $self->{level}->{should});
3397            } else {
3398              !!!parse-error (type => 'not HTML5', token => $token);
3399            }
3400        } else {        } else {
3401          !!!cp ('t3');          !!!cp ('t3');
3402            #
3403        }        }
3404                
3405        my $doctype = $self->{document}->create_document_type_definition        my $doctype = $self->{document}->create_document_type_definition
# Line 3086  sub _tree_construction_initial ($) { Line 3420  sub _tree_construction_initial ($) {
3420        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{public_identifier}) {
3421          my $pubid = $token->{public_identifier};          my $pubid = $token->{public_identifier};
3422          $pubid =~ tr/a-z/A-z/;          $pubid =~ tr/a-z/A-z/;
3423          if ({          my $prefix = [
3424            "+//SILMARIL//DTD HTML PRO V0R11 19970101//EN" => 1,            "+//SILMARIL//DTD HTML PRO V0R11 19970101//",
3425            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3426            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3427            "-//IETF//DTD HTML 2.0 LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 1//",
3428            "-//IETF//DTD HTML 2.0 LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 2//",
3429            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//",
3430            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//",
3431            "-//IETF//DTD HTML 2.0 STRICT//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT//",
3432            "-//IETF//DTD HTML 2.0//EN" => 1,            "-//IETF//DTD HTML 2.0//",
3433            "-//IETF//DTD HTML 2.1E//EN" => 1,            "-//IETF//DTD HTML 2.1E//",
3434            "-//IETF//DTD HTML 3.0//EN" => 1,            "-//IETF//DTD HTML 3.0//",
3435            "-//IETF//DTD HTML 3.0//EN//" => 1,            "-//IETF//DTD HTML 3.2 FINAL//",
3436            "-//IETF//DTD HTML 3.2 FINAL//EN" => 1,            "-//IETF//DTD HTML 3.2//",
3437            "-//IETF//DTD HTML 3.2//EN" => 1,            "-//IETF//DTD HTML 3//",
3438            "-//IETF//DTD HTML 3//EN" => 1,            "-//IETF//DTD HTML LEVEL 0//",
3439            "-//IETF//DTD HTML LEVEL 0//EN" => 1,            "-//IETF//DTD HTML LEVEL 1//",
3440            "-//IETF//DTD HTML LEVEL 0//EN//2.0" => 1,            "-//IETF//DTD HTML LEVEL 2//",
3441            "-//IETF//DTD HTML LEVEL 1//EN" => 1,            "-//IETF//DTD HTML LEVEL 3//",
3442            "-//IETF//DTD HTML LEVEL 1//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 0//",
3443            "-//IETF//DTD HTML LEVEL 2//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 1//",
3444            "-//IETF//DTD HTML LEVEL 2//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 2//",
3445            "-//IETF//DTD HTML LEVEL 3//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 3//",
3446            "-//IETF//DTD HTML LEVEL 3//EN//3.0" => 1,            "-//IETF//DTD HTML STRICT//",
3447            "-//IETF//DTD HTML STRICT LEVEL 0//EN" => 1,            "-//IETF//DTD HTML//",
3448            "-//IETF//DTD HTML STRICT LEVEL 0//EN//2.0" => 1,            "-//METRIUS//DTD METRIUS PRESENTATIONAL//",
3449            "-//IETF//DTD HTML STRICT LEVEL 1//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//",
3450            "-//IETF//DTD HTML STRICT LEVEL 1//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//",
3451            "-//IETF//DTD HTML STRICT LEVEL 2//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//",
3452            "-//IETF//DTD HTML STRICT LEVEL 2//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//",
3453            "-//IETF//DTD HTML STRICT LEVEL 3//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//",
3454            "-//IETF//DTD HTML STRICT LEVEL 3//EN//3.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//",
3455            "-//IETF//DTD HTML STRICT//EN" => 1,            "-//NETSCAPE COMM. CORP.//DTD HTML//",
3456            "-//IETF//DTD HTML STRICT//EN//2.0" => 1,            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//",
3457            "-//IETF//DTD HTML STRICT//EN//3.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//",
3458            "-//IETF//DTD HTML//EN" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//",
3459            "-//IETF//DTD HTML//EN//2.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//",
3460            "-//IETF//DTD HTML//EN//3.0" => 1,            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//",
3461            "-//METRIUS//DTD METRIUS PRESENTATIONAL//EN" => 1,            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//",
3462            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//EN" => 1,            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//",
3463            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//EN" => 1,            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//",
3464            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//",
3465            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//",
3466            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//EN" => 1,            "-//W3C//DTD HTML 3 1995-03-24//",
3467            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//EN" => 1,            "-//W3C//DTD HTML 3.2 DRAFT//",
3468            "-//NETSCAPE COMM. CORP.//DTD HTML//EN" => 1,            "-//W3C//DTD HTML 3.2 FINAL//",
3469            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//EN" => 1,            "-//W3C//DTD HTML 3.2//",
3470            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//EN" => 1,            "-//W3C//DTD HTML 3.2S DRAFT//",
3471            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 FRAMESET//",
3472            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 TRANSITIONAL//",
3473            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMETNAL 19960712//",
3474            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMENTAL 970421//",
3475            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//EN" => 1,            "-//W3C//DTD W3 HTML//",
3476            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//EN" => 1,            "-//W3O//DTD W3 HTML 3.0//",
3477            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML 2.0//",
3478            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML//",
3479            "-//W3C//DTD HTML 3 1995-03-24//EN" => 1,          ]; # $prefix
3480            "-//W3C//DTD HTML 3.2 DRAFT//EN" => 1,          my $match;
3481            "-//W3C//DTD HTML 3.2 FINAL//EN" => 1,          for (@$prefix) {
3482            "-//W3C//DTD HTML 3.2//EN" => 1,            if (substr ($prefix, 0, length $_) eq $_) {
3483            "-//W3C//DTD HTML 3.2S DRAFT//EN" => 1,              $match = 1;
3484            "-//W3C//DTD HTML 4.0 FRAMESET//EN" => 1,              last;
3485            "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN" => 1,            }
3486            "-//W3C//DTD HTML EXPERIMETNAL 19960712//EN" => 1,          }
3487            "-//W3C//DTD HTML EXPERIMENTAL 970421//EN" => 1,          if ($match or
3488            "-//W3C//DTD W3 HTML//EN" => 1,              $pubid eq "-//W3O//DTD W3 HTML STRICT 3.0//EN//" or
3489            "-//W3O//DTD W3 HTML 3.0//EN" => 1,              $pubid eq "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" or
3490            "-//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}) {  
3491            !!!cp ('t5');            !!!cp ('t5');
3492            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3493          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD HTML 4.01 FRAMESET//] or
3494                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD HTML 4.01 TRANSITIONAL//]) {
3495            if (defined $token->{system_identifier}) {            if (defined $token->{system_identifier}) {
3496              !!!cp ('t6');              !!!cp ('t6');
3497              $self->{document}->manakai_compat_mode ('quirks');              $self->{document}->manakai_compat_mode ('quirks');
# Line 3171  sub _tree_construction_initial ($) { Line 3499  sub _tree_construction_initial ($) {
3499              !!!cp ('t7');              !!!cp ('t7');
3500              $self->{document}->manakai_compat_mode ('limited quirks');              $self->{document}->manakai_compat_mode ('limited quirks');
3501            }            }
3502          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD XHTML 1.0 FRAMESET//] or
3503                   $pubid eq "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD XHTML 1.0 TRANSITIONAL//]) {
3504            !!!cp ('t8');            !!!cp ('t8');
3505            $self->{document}->manakai_compat_mode ('limited quirks');            $self->{document}->manakai_compat_mode ('limited quirks');
3506          } else {          } else {
# Line 3185  sub _tree_construction_initial ($) { Line 3513  sub _tree_construction_initial ($) {
3513          my $sysid = $token->{system_identifier};          my $sysid = $token->{system_identifier};
3514          $sysid =~ tr/A-Z/a-z/;          $sysid =~ tr/A-Z/a-z/;
3515          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") {
3516            ## TODO: Check the spec: PUBLIC "(limited quirks)" "(quirks)"            ## NOTE: Ensure that |PUBLIC "(limited quirks)" "(quirks)"| is
3517              ## marked as quirks.
3518            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3519            !!!cp ('t11');            !!!cp ('t11');
3520          } else {          } else {
# Line 3357  sub _reset_insertion_mode ($) { Line 3686  sub _reset_insertion_mode ($) {
3686        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
3687          $last = 1;          $last = 1;
3688          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
3689            if ($self->{inner_html_node}->[1] & TABLE_CELL_EL) {            !!!cp ('t28');
3690              !!!cp ('t27');            $node = $self->{inner_html_node};
3691              #          } else {
3692            } else {            die "_reset_insertion_mode: t27";
             !!!cp ('t28');  
             $node = $self->{inner_html_node};  
           }  
3693          }          }
3694        }        }
3695              
3696      ## Step 4..14        ## Step 4..14
3697      my $new_mode;        my $new_mode;
3698      if ($node->[1] & FOREIGN_EL) {        if ($node->[1] & FOREIGN_EL) {
3699        ## NOTE: Strictly spaking, the line below only applies to MathML and          !!!cp ('t28.1');
3700        ## SVG elements.  Currently the HTML syntax supports only MathML and          ## NOTE: Strictly spaking, the line below only applies to MathML and
3701        ## SVG elements as foreigners.          ## SVG elements.  Currently the HTML syntax supports only MathML and
3702        $new_mode = $self->{insertion_mode} | IN_FOREIGN_CONTENT_IM;          ## SVG elements as foreigners.
3703        ## ISSUE: What is set as the secondary insertion mode?          $new_mode = IN_BODY_IM | IN_FOREIGN_CONTENT_IM;
3704      } else {        } elsif ($node->[1] & TABLE_CELL_EL) {
3705        $new_mode = {          if ($last) {
3706              !!!cp ('t28.2');
3707              #
3708            } else {
3709              !!!cp ('t28.3');
3710              $new_mode = IN_CELL_IM;
3711            }
3712          } else {
3713            !!!cp ('t28.4');
3714            $new_mode = {
3715                        select => IN_SELECT_IM,                        select => IN_SELECT_IM,
3716                        ## NOTE: |option| and |optgroup| do not set                        ## NOTE: |option| and |optgroup| do not set
3717                        ## insertion mode to "in select" by themselves.                        ## insertion mode to "in select" by themselves.
                       td => IN_CELL_IM,  
                       th => IN_CELL_IM,  
3718                        tr => IN_ROW_IM,                        tr => IN_ROW_IM,
3719                        tbody => IN_TABLE_BODY_IM,                        tbody => IN_TABLE_BODY_IM,
3720                        thead => IN_TABLE_BODY_IM,                        thead => IN_TABLE_BODY_IM,
# Line 3393  sub _reset_insertion_mode ($) { Line 3726  sub _reset_insertion_mode ($) {
3726                        body => IN_BODY_IM,                        body => IN_BODY_IM,
3727                        frameset => IN_FRAMESET_IM,                        frameset => IN_FRAMESET_IM,
3728                       }->{$node->[0]->manakai_local_name};                       }->{$node->[0]->manakai_local_name};
3729      }        }
3730      $self->{insertion_mode} = $new_mode and return if defined $new_mode;        $self->{insertion_mode} = $new_mode and return if defined $new_mode;
3731                
3732        ## Step 15        ## Step 15
3733        if ($node->[1] & HTML_EL) {        if ($node->[1] & HTML_EL) {
# Line 3568  sub _tree_construction_main ($) { Line 3901  sub _tree_construction_main ($) {
3901        ## NOTE: An end-of-file token.        ## NOTE: An end-of-file token.
3902        if ($content_model_flag == CDATA_CONTENT_MODEL) {        if ($content_model_flag == CDATA_CONTENT_MODEL) {
3903          !!!cp ('t43');          !!!cp ('t43');
3904          !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in CDATA:#eof', token => $token);
3905        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
3906          !!!cp ('t44');          !!!cp ('t44');
3907          !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in RCDATA:#eof', token => $token);
3908        } else {        } else {
3909          die "$0: $content_model_flag in parse_rcdata";          die "$0: $content_model_flag in parse_rcdata";
3910        }        }
# Line 3608  sub _tree_construction_main ($) { Line 3941  sub _tree_construction_main ($) {
3941        ## Ignore the token        ## Ignore the token
3942      } else {      } else {
3943        !!!cp ('t48');        !!!cp ('t48');
3944        !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);        !!!parse-error (type => 'in CDATA:#eof', token => $token);
3945        ## ISSUE: And ignore?        ## ISSUE: And ignore?
3946        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
3947      }      }
# Line 3659  sub _tree_construction_main ($) { Line 3992  sub _tree_construction_main ($) {
3992        } # AFE        } # AFE
3993        unless (defined $formatting_element) {        unless (defined $formatting_element) {
3994          !!!cp ('t53');          !!!cp ('t53');
3995          !!!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);
3996          ## Ignore the token          ## Ignore the token
3997          !!!next-token;          !!!next-token;
3998          return;          return;
# Line 3676  sub _tree_construction_main ($) { Line 4009  sub _tree_construction_main ($) {
4009              last INSCOPE;              last INSCOPE;
4010            } else { # in open elements but not in scope            } else { # in open elements but not in scope
4011              !!!cp ('t55');              !!!cp ('t55');
4012              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},              !!!parse-error (type => 'unmatched end tag',
4013                                text => $token->{tag_name},
4014                              token => $end_tag_token);                              token => $end_tag_token);
4015              ## Ignore the token              ## Ignore the token
4016              !!!next-token;              !!!next-token;
# Line 3689  sub _tree_construction_main ($) { Line 4023  sub _tree_construction_main ($) {
4023        } # INSCOPE        } # INSCOPE
4024        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
4025          !!!cp ('t57');          !!!cp ('t57');
4026          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},          !!!parse-error (type => 'unmatched end tag',
4027                            text => $token->{tag_name},
4028                          token => $end_tag_token);                          token => $end_tag_token);
4029          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
4030          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
# Line 3698  sub _tree_construction_main ($) { Line 4033  sub _tree_construction_main ($) {
4033        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
4034          !!!cp ('t58');          !!!cp ('t58');
4035          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
4036                          value => $self->{open_elements}->[-1]->[0]                          text => $self->{open_elements}->[-1]->[0]
4037                              ->manakai_local_name,                              ->manakai_local_name,
4038                          token => $end_tag_token);                          token => $end_tag_token);
4039        }        }
# Line 3907  sub _tree_construction_main ($) { Line 4242  sub _tree_construction_main ($) {
4242    B: while (1) {    B: while (1) {
4243      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
4244        !!!cp ('t73');        !!!cp ('t73');
4245        !!!parse-error (type => 'DOCTYPE in the middle', token => $token);        !!!parse-error (type => 'in html:#DOCTYPE', token => $token);
4246        ## Ignore the token        ## Ignore the token
4247        ## Stay in the phase        ## Stay in the phase
4248        !!!next-token;        !!!next-token;
# Line 3916  sub _tree_construction_main ($) { Line 4251  sub _tree_construction_main ($) {
4251               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
4252        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
4253          !!!cp ('t79');          !!!cp ('t79');
4254          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4255          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
4256        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
4257          !!!cp ('t80');          !!!cp ('t80');
4258          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4259          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
4260        } else {        } else {
4261          !!!cp ('t81');          !!!cp ('t81');
# Line 3971  sub _tree_construction_main ($) { Line 4306  sub _tree_construction_main ($) {
4306            #            #
4307          } elsif ({          } elsif ({
4308                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,
4309                    center => 1, code => 1, dd => 1, div => 1, dl => 1, em => 1,                    center => 1, code => 1, dd => 1, div => 1, dl => 1, dt => 1,
4310                    embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1, ## No h4!                    em => 1, embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1,
4311                    h5 => 1, h6 => 1, head => 1, hr => 1, i => 1, img => 1,                    h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, i => 1,
4312                    li => 1, menu => 1, meta => 1, nobr => 1, p => 1, pre => 1,                    img => 1, li => 1, listing => 1, menu => 1, meta => 1,
4313                    ruby => 1, s => 1, small => 1, span => 1, strong => 1,                    nobr => 1, ol => 1, p => 1, pre => 1, ruby => 1, s => 1,
4314                    sub => 1, sup => 1, table => 1, tt => 1, u => 1, ul => 1,                    small => 1, span => 1, strong => 1, strike => 1, sub => 1,
4315                    var => 1,                    sup => 1, table => 1, tt => 1, u => 1, ul => 1, var => 1,
4316                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
4317            !!!cp ('t87.2');            !!!cp ('t87.2');
4318            !!!parse-error (type => 'not closed',            !!!parse-error (type => 'not closed',
4319                            value => $self->{open_elements}->[-1]->[0]                            text => $self->{open_elements}->[-1]->[0]
4320                                ->manakai_local_name,                                ->manakai_local_name,
4321                            token => $token);                            token => $token);
4322    
# Line 4057  sub _tree_construction_main ($) { Line 4392  sub _tree_construction_main ($) {
4392          !!!cp ('t87.5');          !!!cp ('t87.5');
4393          #          #
4394        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
         ## NOTE: "using the rules for secondary insertion mode" then "continue"  
4395          !!!cp ('t87.6');          !!!cp ('t87.6');
4396          #          !!!parse-error (type => 'not closed',
4397          ## TODO: ...                          text => $self->{open_elements}->[-1]->[0]
4398                                ->manakai_local_name,
4399                            token => $token);
4400    
4401            pop @{$self->{open_elements}}
4402                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;
4403    
4404            $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
4405            ## Reprocess.
4406            next B;
4407        } else {        } else {
4408          die "$0: $token->{type}: Unknown token type";                  die "$0: $token->{type}: Unknown token type";        
4409        }        }
# Line 4101  sub _tree_construction_main ($) { Line 4444  sub _tree_construction_main ($) {
4444            !!!cp ('t90');            !!!cp ('t90');
4445            ## As if </noscript>            ## As if </noscript>
4446            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
4447            !!!parse-error (type => 'in noscript:#character', token => $token);            !!!parse-error (type => 'in noscript:#text', token => $token);
4448                        
4449            ## Reprocess in the "in head" insertion mode...            ## Reprocess in the "in head" insertion mode...
4450            ## As if </head>            ## As if </head>
# Line 4137  sub _tree_construction_main ($) { Line 4480  sub _tree_construction_main ($) {
4480              !!!next-token;              !!!next-token;
4481              next B;              next B;
4482            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4483              !!!cp ('t94');              !!!cp ('t93.2');
4484              #              !!!parse-error (type => 'after head', text => 'head',
4485                                token => $token);
4486                ## Ignore the token
4487                !!!nack ('t93.3');
4488                !!!next-token;
4489                next B;
4490            } else {            } else {
4491              !!!cp ('t95');              !!!cp ('t95');
4492              !!!parse-error (type => 'in head:head', token => $token); # or in head noscript              !!!parse-error (type => 'in head:head',
4493                                token => $token); # or in head noscript
4494              ## Ignore the token              ## Ignore the token
4495              !!!nack ('t95.1');              !!!nack ('t95.1');
4496              !!!next-token;              !!!next-token;
# Line 4166  sub _tree_construction_main ($) { Line 4515  sub _tree_construction_main ($) {
4515                  !!!cp ('t98');                  !!!cp ('t98');
4516                  ## As if </noscript>                  ## As if </noscript>
4517                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4518                  !!!parse-error (type => 'in noscript:base', token => $token);                  !!!parse-error (type => 'in noscript', text => 'base',
4519                                    token => $token);
4520                                
4521                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4522                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
# Line 4177  sub _tree_construction_main ($) { Line 4527  sub _tree_construction_main ($) {
4527                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4528                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4529                  !!!cp ('t100');                  !!!cp ('t100');
4530                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4531                                    text => $token->{tag_name}, token => $token);
4532                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4533                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4534                } else {                } else {
# Line 4194  sub _tree_construction_main ($) { Line 4545  sub _tree_construction_main ($) {
4545                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4546                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4547                  !!!cp ('t102');                  !!!cp ('t102');
4548                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4549                                    text => $token->{tag_name}, token => $token);
4550                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4551                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4552                } else {                } else {
# Line 4211  sub _tree_construction_main ($) { Line 4563  sub _tree_construction_main ($) {
4563                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4564                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4565                  !!!cp ('t104');                  !!!cp ('t104');
4566                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4567                                    text => $token->{tag_name}, token => $token);
4568                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4569                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4570                } else {                } else {
# Line 4235  sub _tree_construction_main ($) { Line 4588  sub _tree_construction_main ($) {
4588                                                 ->{has_reference});                                                 ->{has_reference});
4589                  } elsif ($token->{attributes}->{content}) {                  } elsif ($token->{attributes}->{content}) {
4590                    if ($token->{attributes}->{content}->{value}                    if ($token->{attributes}->{content}->{value}
4591                        =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                        =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
4592                            [\x09-\x0D\x20]*=                            [\x09-\x0D\x20]*=
4593                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
4594                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
4595                      !!!cp ('t107');                      !!!cp ('t107');
4596                      ## NOTE: Whether the encoding is supported or not is handled                      ## NOTE: Whether the encoding is supported or not is handled
4597                      ## in the {change_encoding} callback.                      ## in the {change_encoding} callback.
# Line 4280  sub _tree_construction_main ($) { Line 4633  sub _tree_construction_main ($) {
4633                  !!!cp ('t111');                  !!!cp ('t111');
4634                  ## As if </noscript>                  ## As if </noscript>
4635                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4636                  !!!parse-error (type => 'in noscript:title', token => $token);                  !!!parse-error (type => 'in noscript', text => 'title',
4637                                    token => $token);
4638                                
4639                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4640                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4641                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4642                  !!!cp ('t112');                  !!!cp ('t112');
4643                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4644                                    text => $token->{tag_name}, token => $token);
4645                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4646                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4647                } else {                } else {
# Line 4300  sub _tree_construction_main ($) { Line 4655  sub _tree_construction_main ($) {
4655                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4656                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4657                next B;                next B;
4658              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style' or
4659                         $token->{tag_name} eq 'noframes') {
4660                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and
4661                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
4662                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4663                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4664                  !!!cp ('t114');                  !!!cp ('t114');
4665                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4666                                    text => $token->{tag_name}, token => $token);
4667                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4668                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4669                } else {                } else {
# Line 4327  sub _tree_construction_main ($) { Line 4684  sub _tree_construction_main ($) {
4684                  next B;                  next B;
4685                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4686                  !!!cp ('t117');                  !!!cp ('t117');
4687                  !!!parse-error (type => 'in noscript:noscript', token => $token);                  !!!parse-error (type => 'in noscript', text => 'noscript',
4688                                    token => $token);
4689                  ## Ignore the token                  ## Ignore the token
4690                  !!!nack ('t117.1');                  !!!nack ('t117.1');
4691                  !!!next-token;                  !!!next-token;
# Line 4341  sub _tree_construction_main ($) { Line 4699  sub _tree_construction_main ($) {
4699                  !!!cp ('t119');                  !!!cp ('t119');
4700                  ## As if </noscript>                  ## As if </noscript>
4701                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4702                  !!!parse-error (type => 'in noscript:script', token => $token);                  !!!parse-error (type => 'in noscript', text => 'script',
4703                                    token => $token);
4704                                
4705                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4706                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4707                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4708                  !!!cp ('t120');                  !!!cp ('t120');
4709                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4710                                    text => $token->{tag_name}, token => $token);
4711                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4712                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4713                } else {                } else {
# Line 4365  sub _tree_construction_main ($) { Line 4725  sub _tree_construction_main ($) {
4725                  !!!cp ('t122');                  !!!cp ('t122');
4726                  ## As if </noscript>                  ## As if </noscript>
4727                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4728                  !!!parse-error (type => 'in noscript:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in noscript',
4729                                    text => $token->{tag_name}, token => $token);
4730                                    
4731                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4732                  ## As if </head>                  ## As if </head>
# Line 4404  sub _tree_construction_main ($) { Line 4765  sub _tree_construction_main ($) {
4765                !!!cp ('t129');                !!!cp ('t129');
4766                ## As if </noscript>                ## As if </noscript>
4767                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4768                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4769                                  text => $token->{tag_name}, token => $token);
4770                                
4771                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4772                ## As if </head>                ## As if </head>
# Line 4447  sub _tree_construction_main ($) { Line 4809  sub _tree_construction_main ($) {
4809                  !!!cp ('t133');                  !!!cp ('t133');
4810                  ## As if </noscript>                  ## As if </noscript>
4811                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4812                  !!!parse-error (type => 'in noscript:/head', token => $token);                  !!!parse-error (type => 'in noscript:/',
4813                                    text => 'head', token => $token);
4814                                    
4815                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4816                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 4460  sub _tree_construction_main ($) { Line 4823  sub _tree_construction_main ($) {
4823                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
4824                  !!!next-token;                  !!!next-token;
4825                  next B;                  next B;
4826                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4827                    !!!cp ('t134.1');
4828                    !!!parse-error (type => 'unmatched end tag', text => 'head',
4829                                    token => $token);
4830                    ## Ignore the token
4831                    !!!next-token;
4832                    next B;
4833                } else {                } else {
4834                  !!!cp ('t135');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
                 #  
4835                }                }
4836              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
4837                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
# Line 4471  sub _tree_construction_main ($) { Line 4840  sub _tree_construction_main ($) {
4840                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4841                  !!!next-token;                  !!!next-token;
4842                  next B;                  next B;
4843                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or
4844                           $self->{insertion_mode} == AFTER_HEAD_IM) {
4845                  !!!cp ('t137');                  !!!cp ('t137');
4846                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4847                                    text => 'noscript', token => $token);
4848                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
4849                  !!!next-token;                  !!!next-token;
4850                  next B;                  next B;
# Line 4484  sub _tree_construction_main ($) { Line 4855  sub _tree_construction_main ($) {
4855              } elsif ({              } elsif ({
4856                        body => 1, html => 1,                        body => 1, html => 1,
4857                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4858                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM or
4859                  !!!cp ('t139');                    $self->{insertion_mode} == IN_HEAD_IM or
4860                  ## 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) {  
4861                  !!!cp ('t140');                  !!!cp ('t140');
4862                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4863                                    text => $token->{tag_name}, token => $token);
4864                    ## Ignore the token
4865                    !!!next-token;
4866                    next B;
4867                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4868                    !!!cp ('t140.1');
4869                    !!!parse-error (type => 'unmatched end tag',
4870                                    text => $token->{tag_name}, token => $token);
4871                  ## Ignore the token                  ## Ignore the token
4872                  !!!next-token;                  !!!next-token;
4873                  next B;                  next B;
4874                } else {                } else {
4875                  !!!cp ('t141');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
4876                }                }
4877                              } elsif ($token->{tag_name} eq 'p') {
4878                #                !!!cp ('t142');
4879              } elsif ({                !!!parse-error (type => 'unmatched end tag',
4880                        p => 1, br => 1,                                text => $token->{tag_name}, token => $token);
4881                       }->{$token->{tag_name}}) {                ## Ignore the token
4882                  !!!next-token;
4883                  next B;
4884                } elsif ($token->{tag_name} eq 'br') {
4885                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4886                  !!!cp ('t142');                  !!!cp ('t142.2');
4887                  ## As if <head>                  ## (before head) as if <head>, (in head) as if </head>
4888                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
4889                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
4890                  push @{$self->{open_elements}},                  $self->{insertion_mode} = AFTER_HEAD_IM;
4891                      [$self->{head_element}, $el_category->{head}];    
4892                    ## Reprocess in the "after head" insertion mode...
4893                  } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
4894                    !!!cp ('t143.2');
4895                    ## As if </head>
4896                    pop @{$self->{open_elements}};
4897                    $self->{insertion_mode} = AFTER_HEAD_IM;
4898      
4899                    ## Reprocess in the "after head" insertion mode...
4900                  } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4901                    !!!cp ('t143.3');
4902                    ## ISSUE: Two parse errors for <head><noscript></br>
4903                    !!!parse-error (type => 'unmatched end tag',
4904                                    text => 'br', token => $token);
4905                    ## As if </noscript>
4906                    pop @{$self->{open_elements}};
4907                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4908    
4909                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4910                } else {                  ## As if </head>
4911                  !!!cp ('t143');                  pop @{$self->{open_elements}};
4912                }                  $self->{insertion_mode} = AFTER_HEAD_IM;
4913    
4914                #                  ## Reprocess in the "after head" insertion mode...
4915              } else {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4916                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                  !!!cp ('t143.4');
                 !!!cp ('t144');  
4917                  #                  #
4918                } else {                } else {
4919                  !!!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;  
4920                }                }
4921    
4922                  ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.
4923                  !!!parse-error (type => 'unmatched end tag',
4924                                  text => 'br', token => $token);
4925                  ## Ignore the token
4926                  !!!next-token;
4927                  next B;
4928                } else {
4929                  !!!cp ('t145');
4930                  !!!parse-error (type => 'unmatched end tag',
4931                                  text => $token->{tag_name}, token => $token);
4932                  ## Ignore the token
4933                  !!!next-token;
4934                  next B;
4935              }              }
4936    
4937              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4938                !!!cp ('t146');                !!!cp ('t146');
4939                ## As if </noscript>                ## As if </noscript>
4940                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4941                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4942                                  text => $token->{tag_name}, token => $token);
4943                                
4944                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4945                ## As if </head>                ## As if </head>
# Line 4556  sub _tree_construction_main ($) { Line 4955  sub _tree_construction_main ($) {
4955              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4956  ## ISSUE: This case cannot be reached?  ## ISSUE: This case cannot be reached?
4957                !!!cp ('t148');                !!!cp ('t148');
4958                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
4959                                  text => $token->{tag_name}, token => $token);
4960                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
4961                !!!next-token;                !!!next-token;
4962                next B;                next B;
# Line 4667  sub _tree_construction_main ($) { Line 5067  sub _tree_construction_main ($) {
5067    
5068                  !!!cp ('t153');                  !!!cp ('t153');
5069                  !!!parse-error (type => 'start tag not allowed',                  !!!parse-error (type => 'start tag not allowed',
5070                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
5071                  ## Ignore the token                  ## Ignore the token
5072                  !!!nack ('t153.1');                  !!!nack ('t153.1');
5073                  !!!next-token;                  !!!next-token;
5074                  next B;                  next B;
5075                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
5076                  !!!parse-error (type => 'not closed:caption', token => $token);                  !!!parse-error (type => 'not closed', text => 'caption',
5077                                    token => $token);
5078                                    
5079                  ## NOTE: As if </caption>.                  ## NOTE: As if </caption>.
5080                  ## have a table element in table scope                  ## have a table element in table scope
# Line 4693  sub _tree_construction_main ($) { Line 5094  sub _tree_construction_main ($) {
5094    
5095                    !!!cp ('t157');                    !!!cp ('t157');
5096                    !!!parse-error (type => 'start tag not allowed',                    !!!parse-error (type => 'start tag not allowed',
5097                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
5098                    ## Ignore the token                    ## Ignore the token
5099                    !!!nack ('t157.1');                    !!!nack ('t157.1');
5100                    !!!next-token;                    !!!next-token;
# Line 4710  sub _tree_construction_main ($) { Line 5111  sub _tree_construction_main ($) {
5111                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5112                    !!!cp ('t159');                    !!!cp ('t159');
5113                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5114                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5115                                        ->manakai_local_name,                                        ->manakai_local_name,
5116                                    token => $token);                                    token => $token);
5117                  } else {                  } else {
# Line 4752  sub _tree_construction_main ($) { Line 5153  sub _tree_construction_main ($) {
5153                  } # INSCOPE                  } # INSCOPE
5154                    unless (defined $i) {                    unless (defined $i) {
5155                      !!!cp ('t165');                      !!!cp ('t165');
5156                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5157                                        text => $token->{tag_name},
5158                                        token => $token);
5159                      ## Ignore the token                      ## Ignore the token
5160                      !!!next-token;                      !!!next-token;
5161                      next B;                      next B;
# Line 4769  sub _tree_construction_main ($) { Line 5172  sub _tree_construction_main ($) {
5172                          ne $token->{tag_name}) {                          ne $token->{tag_name}) {
5173                    !!!cp ('t167');                    !!!cp ('t167');
5174                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5175                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5176                                        ->manakai_local_name,                                        ->manakai_local_name,
5177                                    token => $token);                                    token => $token);
5178                  } else {                  } else {
# Line 4786  sub _tree_construction_main ($) { Line 5189  sub _tree_construction_main ($) {
5189                  next B;                  next B;
5190                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
5191                  !!!cp ('t169');                  !!!cp ('t169');
5192                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5193                                    text => $token->{tag_name}, token => $token);
5194                  ## Ignore the token                  ## Ignore the token
5195                  !!!next-token;                  !!!next-token;
5196                  next B;                  next B;
# Line 4813  sub _tree_construction_main ($) { Line 5217  sub _tree_construction_main ($) {
5217    
5218                    !!!cp ('t173');                    !!!cp ('t173');
5219                    !!!parse-error (type => 'unmatched end tag',                    !!!parse-error (type => 'unmatched end tag',
5220                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
5221                    ## Ignore the token                    ## Ignore the token
5222                    !!!next-token;                    !!!next-token;
5223                    next B;                    next B;
# Line 4829  sub _tree_construction_main ($) { Line 5233  sub _tree_construction_main ($) {
5233                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5234                    !!!cp ('t175');                    !!!cp ('t175');
5235                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5236                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5237                                        ->manakai_local_name,                                        ->manakai_local_name,
5238                                    token => $token);                                    token => $token);
5239                  } else {                  } else {
# Line 4846  sub _tree_construction_main ($) { Line 5250  sub _tree_construction_main ($) {
5250                  next B;                  next B;
5251                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
5252                  !!!cp ('t177');                  !!!cp ('t177');
5253                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5254                                    text => $token->{tag_name}, token => $token);
5255                  ## Ignore the token                  ## Ignore the token
5256                  !!!next-token;                  !!!next-token;
5257                  next B;                  next B;
# Line 4889  sub _tree_construction_main ($) { Line 5294  sub _tree_construction_main ($) {
5294    
5295                  !!!cp ('t182');                  !!!cp ('t182');
5296                  !!!parse-error (type => 'unmatched end tag',                  !!!parse-error (type => 'unmatched end tag',
5297                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
5298                  ## Ignore the token                  ## Ignore the token
5299                  !!!next-token;                  !!!next-token;
5300                  next B;                  next B;
5301                } # INSCOPE                } # INSCOPE
5302              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
5303                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5304                !!!parse-error (type => 'not closed:caption', token => $token);                !!!parse-error (type => 'not closed', text => 'caption',
5305                                  token => $token);
5306    
5307                ## As if </caption>                ## As if </caption>
5308                ## have a table element in table scope                ## have a table element in table scope
# Line 4914  sub _tree_construction_main ($) { Line 5320  sub _tree_construction_main ($) {
5320                } # INSCOPE                } # INSCOPE
5321                unless (defined $i) {                unless (defined $i) {
5322                  !!!cp ('t186');                  !!!cp ('t186');
5323                  !!!parse-error (type => 'unmatched end tag:caption', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5324                                    text => 'caption', token => $token);
5325                  ## Ignore the token                  ## Ignore the token
5326                  !!!next-token;                  !!!next-token;
5327                  next B;                  next B;
# Line 4929  sub _tree_construction_main ($) { Line 5336  sub _tree_construction_main ($) {
5336                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5337                  !!!cp ('t188');                  !!!cp ('t188');
5338                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5339                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5340                                      ->manakai_local_name,                                      ->manakai_local_name,
5341                                  token => $token);                                  token => $token);
5342                } else {                } else {
# Line 4949  sub _tree_construction_main ($) { Line 5356  sub _tree_construction_main ($) {
5356                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5357                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
5358                  !!!cp ('t190');                  !!!cp ('t190');
5359                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5360                                    text => $token->{tag_name}, token => $token);
5361                  ## Ignore the token                  ## Ignore the token
5362                  !!!next-token;                  !!!next-token;
5363                  next B;                  next B;
# Line 4963  sub _tree_construction_main ($) { Line 5371  sub _tree_construction_main ($) {
5371                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
5372                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5373                !!!cp ('t192');                !!!cp ('t192');
5374                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
5375                                  text => $token->{tag_name}, token => $token);
5376                ## Ignore the token                ## Ignore the token
5377                !!!next-token;                !!!next-token;
5378                next B;                next B;
# Line 5003  sub _tree_construction_main ($) { Line 5412  sub _tree_construction_main ($) {
5412            }            }
5413          }          }
5414    
5415              !!!parse-error (type => 'in table:#character', token => $token);          !!!parse-error (type => 'in table:#text', token => $token);
5416    
5417              ## As if in body, but insert into foster parent element              ## As if in body, but insert into foster parent element
5418              ## ISSUE: Spec says that "whenever a node would be inserted              ## ISSUE: Spec says that "whenever a node would be inserted
# Line 5054  sub _tree_construction_main ($) { Line 5463  sub _tree_construction_main ($) {
5463          !!!next-token;          !!!next-token;
5464          next B;          next B;
5465        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5466              if ({          if ({
5467                   tr => ($self->{insertion_mode} != IN_ROW_IM),               tr => ($self->{insertion_mode} != IN_ROW_IM),
5468                   th => 1, td => 1,               th => 1, td => 1,
5469                  }->{$token->{tag_name}}) {              }->{$token->{tag_name}}) {
5470                if ($self->{insertion_mode} == IN_TABLE_IM) {            if ($self->{insertion_mode} == IN_TABLE_IM) {
5471                  ## Clear back to table context              ## Clear back to table context
5472                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5473                                  & TABLE_SCOPING_EL)) {                              & TABLE_SCOPING_EL)) {
5474                    !!!cp ('t201');                !!!cp ('t201');
5475                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5476                  }              }
5477                                
5478                  !!!insert-element ('tbody',, $token);              !!!insert-element ('tbody',, $token);
5479                  $self->{insertion_mode} = IN_TABLE_BODY_IM;              $self->{insertion_mode} = IN_TABLE_BODY_IM;
5480                  ## reprocess in the "in table body" insertion mode...              ## reprocess in the "in table body" insertion mode...
5481                }            }
5482              
5483                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {            if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
5484                  unless ($token->{tag_name} eq 'tr') {              unless ($token->{tag_name} eq 'tr') {
5485                    !!!cp ('t202');                !!!cp ('t202');
5486                    !!!parse-error (type => 'missing start tag:tr', token => $token);                !!!parse-error (type => 'missing start tag:tr', token => $token);
5487                  }              }
5488                                    
5489                  ## Clear back to table body context              ## Clear back to table body context
5490                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5491                                  & TABLE_ROWS_SCOPING_EL)) {                              & TABLE_ROWS_SCOPING_EL)) {
5492                    !!!cp ('t203');                !!!cp ('t203');
5493                    ## ISSUE: Can this case be reached?                ## ISSUE: Can this case be reached?
5494                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5495                  }              }
5496                                    
5497                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
5498                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
# Line 5139  sub _tree_construction_main ($) { Line 5548  sub _tree_construction_main ($) {
5548                  unless (defined $i) {                  unless (defined $i) {
5549                    !!!cp ('t210');                    !!!cp ('t210');
5550  ## TODO: This type is wrong.  ## TODO: This type is wrong.
5551                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmacthed end tag',
5552                                      text => $token->{tag_name}, token => $token);
5553                    ## Ignore the token                    ## Ignore the token
5554                    !!!nack ('t210.1');                    !!!nack ('t210.1');
5555                    !!!next-token;                    !!!next-token;
# Line 5183  sub _tree_construction_main ($) { Line 5593  sub _tree_construction_main ($) {
5593                  } # INSCOPE                  } # INSCOPE
5594                  unless (defined $i) {                  unless (defined $i) {
5595                    !!!cp ('t216');                    !!!cp ('t216');
5596  ## TODO: This erorr type ios wrong.  ## TODO: This erorr type is wrong.
5597                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5598                                      text => $token->{tag_name}, token => $token);
5599                    ## Ignore the token                    ## Ignore the token
5600                    !!!nack ('t216.1');                    !!!nack ('t216.1');
5601                    !!!next-token;                    !!!next-token;
# Line 5259  sub _tree_construction_main ($) { Line 5670  sub _tree_construction_main ($) {
5670                }                }
5671              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
5672                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
5673                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
5674                                    ->manakai_local_name,                                    ->manakai_local_name,
5675                                token => $token);                                token => $token);
5676    
# Line 5280  sub _tree_construction_main ($) { Line 5691  sub _tree_construction_main ($) {
5691                unless (defined $i) {                unless (defined $i) {
5692                  !!!cp ('t223');                  !!!cp ('t223');
5693  ## TODO: The following is wrong, maybe.  ## TODO: The following is wrong, maybe.
5694                  !!!parse-error (type => 'unmatched end tag:table', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'table',
5695                                    token => $token);
5696                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
5697                  !!!nack ('t223.1');                  !!!nack ('t223.1');
5698                  !!!next-token;                  !!!next-token;
5699                  next B;                  next B;
5700                }                }
5701                                
5702  ## TODO: Followings are removed from the latest spec.  ## TODO: Followings are removed from the latest spec.
5703                ## generate implied end tags                ## generate implied end tags
5704                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
5705                  !!!cp ('t224');                  !!!cp ('t224');
# Line 5298  sub _tree_construction_main ($) { Line 5710  sub _tree_construction_main ($) {
5710                  !!!cp ('t225');                  !!!cp ('t225');
5711                  ## NOTE: |<table><tr><table>|                  ## NOTE: |<table><tr><table>|
5712                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5713                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5714                                      ->manakai_local_name,                                      ->manakai_local_name,
5715                                  token => $token);                                  token => $token);
5716                } else {                } else {
# Line 5339  sub _tree_construction_main ($) { Line 5751  sub _tree_construction_main ($) {
5751                my $type = lc $token->{attributes}->{type}->{value};                my $type = lc $token->{attributes}->{type}->{value};
5752                if ($type eq 'hidden') {                if ($type eq 'hidden') {
5753                  !!!cp ('t227.3');                  !!!cp ('t227.3');
5754                  !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in table',
5755                                    text => $token->{tag_name}, token => $token);
5756    
5757                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5758    
# Line 5367  sub _tree_construction_main ($) { Line 5780  sub _tree_construction_main ($) {
5780            #            #
5781          }          }
5782    
5783          !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in table', text => $token->{tag_name},
5784                            token => $token);
5785    
5786          $insert = $insert_to_foster;          $insert = $insert_to_foster;
5787          #          #
# Line 5389  sub _tree_construction_main ($) { Line 5803  sub _tree_construction_main ($) {
5803                } # INSCOPE                } # INSCOPE
5804                unless (defined $i) {                unless (defined $i) {
5805                  !!!cp ('t230');                  !!!cp ('t230');
5806                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5807                                    text => $token->{tag_name}, token => $token);
5808                  ## Ignore the token                  ## Ignore the token
5809                  !!!nack ('t230.1');                  !!!nack ('t230.1');
5810                  !!!next-token;                  !!!next-token;
# Line 5430  sub _tree_construction_main ($) { Line 5845  sub _tree_construction_main ($) {
5845                  unless (defined $i) {                  unless (defined $i) {
5846                    !!!cp ('t235');                    !!!cp ('t235');
5847  ## TODO: The following is wrong.  ## TODO: The following is wrong.
5848                    !!!parse-error (type => 'unmatched end tag:'.$token->{type}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5849                                      text => $token->{type}, token => $token);
5850                    ## Ignore the token                    ## Ignore the token
5851                    !!!nack ('t236.1');                    !!!nack ('t236.1');
5852                    !!!next-token;                    !!!next-token;
# Line 5466  sub _tree_construction_main ($) { Line 5882  sub _tree_construction_main ($) {
5882                  } # INSCOPE                  } # INSCOPE
5883                  unless (defined $i) {                  unless (defined $i) {
5884                    !!!cp ('t239');                    !!!cp ('t239');
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 ('t239.1');                    !!!nack ('t239.1');
5889                    !!!next-token;                    !!!next-token;
# Line 5512  sub _tree_construction_main ($) { Line 5929  sub _tree_construction_main ($) {
5929                } # INSCOPE                } # INSCOPE
5930                unless (defined $i) {                unless (defined $i) {
5931                  !!!cp ('t243');                  !!!cp ('t243');
5932                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5933                                    text => $token->{tag_name}, token => $token);
5934                  ## Ignore the token                  ## Ignore the token
5935                  !!!nack ('t243.1');                  !!!nack ('t243.1');
5936                  !!!next-token;                  !!!next-token;
# Line 5546  sub _tree_construction_main ($) { Line 5964  sub _tree_construction_main ($) {
5964                  } # INSCOPE                  } # INSCOPE
5965                    unless (defined $i) {                    unless (defined $i) {
5966                      !!!cp ('t249');                      !!!cp ('t249');
5967                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5968                                        text => $token->{tag_name}, token => $token);
5969                      ## Ignore the token                      ## Ignore the token
5970                      !!!nack ('t249.1');                      !!!nack ('t249.1');
5971                      !!!next-token;                      !!!next-token;
# Line 5569  sub _tree_construction_main ($) { Line 5988  sub _tree_construction_main ($) {
5988                  } # INSCOPE                  } # INSCOPE
5989                    unless (defined $i) {                    unless (defined $i) {
5990                      !!!cp ('t252');                      !!!cp ('t252');
5991                      !!!parse-error (type => 'unmatched end tag:tr', token => $token);                      !!!parse-error (type => 'unmatched end tag',
5992                                        text => 'tr', token => $token);
5993                      ## Ignore the token                      ## Ignore the token
5994                      !!!nack ('t252.1');                      !!!nack ('t252.1');
5995                      !!!next-token;                      !!!next-token;
# Line 5604  sub _tree_construction_main ($) { Line 6024  sub _tree_construction_main ($) {
6024                } # INSCOPE                } # INSCOPE
6025                unless (defined $i) {                unless (defined $i) {
6026                  !!!cp ('t256');                  !!!cp ('t256');
6027                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
6028                                    text => $token->{tag_name}, token => $token);
6029                  ## Ignore the token                  ## Ignore the token
6030                  !!!nack ('t256.1');                  !!!nack ('t256.1');
6031                  !!!next-token;                  !!!next-token;
# Line 5631  sub _tree_construction_main ($) { Line 6052  sub _tree_construction_main ($) {
6052                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
6053                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
6054            !!!cp ('t258');            !!!cp ('t258');
6055            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
6056                              text => $token->{tag_name}, token => $token);
6057            ## Ignore the token            ## Ignore the token
6058            !!!nack ('t258.1');            !!!nack ('t258.1');
6059             !!!next-token;             !!!next-token;
6060            next B;            next B;
6061          } else {          } else {
6062            !!!cp ('t259');            !!!cp ('t259');
6063            !!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in table:/',
6064                              text => $token->{tag_name}, token => $token);
6065    
6066            $insert = $insert_to_foster;            $insert = $insert_to_foster;
6067            #            #
# Line 5688  sub _tree_construction_main ($) { Line 6111  sub _tree_construction_main ($) {
6111              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
6112                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
6113                  !!!cp ('t264');                  !!!cp ('t264');
6114                  !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);                  !!!parse-error (type => 'unmatched end tag',
6115                                    text => 'colgroup', token => $token);
6116                  ## Ignore the token                  ## Ignore the token
6117                  !!!next-token;                  !!!next-token;
6118                  next B;                  next B;
# Line 5701  sub _tree_construction_main ($) { Line 6125  sub _tree_construction_main ($) {
6125                }                }
6126              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
6127                !!!cp ('t266');                !!!cp ('t266');
6128                !!!parse-error (type => 'unmatched end tag:col', token => $token);                !!!parse-error (type => 'unmatched end tag',
6129                                  text => 'col', token => $token);
6130                ## Ignore the token                ## Ignore the token
6131                !!!next-token;                !!!next-token;
6132                next B;                next B;
# Line 5731  sub _tree_construction_main ($) { Line 6156  sub _tree_construction_main ($) {
6156            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
6157              !!!cp ('t269');              !!!cp ('t269');
6158  ## TODO: Wrong error type?  ## TODO: Wrong error type?
6159              !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);              !!!parse-error (type => 'unmatched end tag',
6160                                text => 'colgroup', token => $token);
6161              ## Ignore the token              ## Ignore the token
6162              !!!nack ('t269.1');              !!!nack ('t269.1');
6163              !!!next-token;              !!!next-token;
# Line 5785  sub _tree_construction_main ($) { Line 6211  sub _tree_construction_main ($) {
6211            !!!nack ('t277.1');            !!!nack ('t277.1');
6212            !!!next-token;            !!!next-token;
6213            next B;            next B;
6214          } elsif ($token->{tag_name} eq 'select' or          } elsif ({
6215                   $token->{tag_name} eq 'input' or                     select => 1, input => 1, textarea => 1,
6216                     }->{$token->{tag_name}} or
6217                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
6218                    {                    {
6219                     caption => 1, table => 1,                     caption => 1, table => 1,
# Line 5794  sub _tree_construction_main ($) { Line 6221  sub _tree_construction_main ($) {
6221                     tr => 1, td => 1, th => 1,                     tr => 1, td => 1, th => 1,
6222                    }->{$token->{tag_name}})) {                    }->{$token->{tag_name}})) {
6223            ## TODO: The type below is not good - <select> is replaced by </select>            ## TODO: The type below is not good - <select> is replaced by </select>
6224            !!!parse-error (type => 'not closed:select', token => $token);            !!!parse-error (type => 'not closed', text => 'select',
6225                              token => $token);
6226            ## NOTE: As if the token were </select> (<select> case) or            ## NOTE: As if the token were </select> (<select> case) or
6227            ## as if there were </select> (otherwise).            ## as if there were </select> (otherwise).
6228            ## have an element in table scope            ## have an element in table scope
# Line 5812  sub _tree_construction_main ($) { Line 6240  sub _tree_construction_main ($) {
6240            } # INSCOPE            } # INSCOPE
6241            unless (defined $i) {            unless (defined $i) {
6242              !!!cp ('t280');              !!!cp ('t280');
6243              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6244                                text => 'select', token => $token);
6245              ## Ignore the token              ## Ignore the token
6246              !!!nack ('t280.1');              !!!nack ('t280.1');
6247              !!!next-token;              !!!next-token;
# Line 5836  sub _tree_construction_main ($) { Line 6265  sub _tree_construction_main ($) {
6265            }            }
6266          } else {          } else {
6267            !!!cp ('t282');            !!!cp ('t282');
6268            !!!parse-error (type => 'in select:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select',
6269                              text => $token->{tag_name}, token => $token);
6270            ## Ignore the token            ## Ignore the token
6271            !!!nack ('t282.1');            !!!nack ('t282.1');
6272            !!!next-token;            !!!next-token;
# Line 5854  sub _tree_construction_main ($) { Line 6284  sub _tree_construction_main ($) {
6284              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6285            } else {            } else {
6286              !!!cp ('t285');              !!!cp ('t285');
6287              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6288                                text => $token->{tag_name}, token => $token);
6289              ## Ignore the token              ## Ignore the token
6290            }            }
6291            !!!nack ('t285.1');            !!!nack ('t285.1');
# Line 5866  sub _tree_construction_main ($) { Line 6297  sub _tree_construction_main ($) {
6297              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6298            } else {            } else {
6299              !!!cp ('t287');              !!!cp ('t287');
6300              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6301                                text => $token->{tag_name}, token => $token);
6302              ## Ignore the token              ## Ignore the token
6303            }            }
6304            !!!nack ('t287.1');            !!!nack ('t287.1');
# Line 5888  sub _tree_construction_main ($) { Line 6320  sub _tree_construction_main ($) {
6320            } # INSCOPE            } # INSCOPE
6321            unless (defined $i) {            unless (defined $i) {
6322              !!!cp ('t290');              !!!cp ('t290');
6323              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6324                                text => $token->{tag_name}, token => $token);
6325              ## Ignore the token              ## Ignore the token
6326              !!!nack ('t290.1');              !!!nack ('t290.1');
6327              !!!next-token;              !!!next-token;
# Line 5909  sub _tree_construction_main ($) { Line 6342  sub _tree_construction_main ($) {
6342                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
6343                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
6344  ## TODO: The following is wrong?  ## TODO: The following is wrong?
6345            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
6346                              text => $token->{tag_name}, token => $token);
6347                                
6348            ## have an element in table scope            ## have an element in table scope
6349            my $i;            my $i;
# Line 5950  sub _tree_construction_main ($) { Line 6384  sub _tree_construction_main ($) {
6384            unless (defined $i) {            unless (defined $i) {
6385              !!!cp ('t297');              !!!cp ('t297');
6386  ## TODO: The following error type is correct?  ## TODO: The following error type is correct?
6387              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6388                                text => 'select', token => $token);
6389              ## Ignore the </select> token              ## Ignore the </select> token
6390              !!!nack ('t297.1');              !!!nack ('t297.1');
6391              !!!next-token; ## TODO: ok?              !!!next-token; ## TODO: ok?
# Line 5967  sub _tree_construction_main ($) { Line 6402  sub _tree_construction_main ($) {
6402            next B;            next B;
6403          } else {          } else {
6404            !!!cp ('t299');            !!!cp ('t299');
6405            !!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select:/',
6406                              text => $token->{tag_name}, token => $token);
6407            ## Ignore the token            ## Ignore the token
6408            !!!nack ('t299.3');            !!!nack ('t299.3');
6409            !!!next-token;            !!!next-token;
# Line 6005  sub _tree_construction_main ($) { Line 6441  sub _tree_construction_main ($) {
6441                    
6442          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6443            !!!cp ('t301');            !!!cp ('t301');
6444            !!!parse-error (type => 'after html:#character', token => $token);            !!!parse-error (type => 'after html:#text', token => $token);
6445    
6446            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6447          } else {          } else {
# Line 6013  sub _tree_construction_main ($) { Line 6449  sub _tree_construction_main ($) {
6449          }          }
6450                    
6451          ## "after body" insertion mode          ## "after body" insertion mode
6452          !!!parse-error (type => 'after body:#character', token => $token);          !!!parse-error (type => 'after body:#text', token => $token);
6453    
6454          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6455          ## reprocess          ## reprocess
# Line 6021  sub _tree_construction_main ($) { Line 6457  sub _tree_construction_main ($) {
6457        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
6458          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6459            !!!cp ('t303');            !!!cp ('t303');
6460            !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html',
6461                              text => $token->{tag_name}, token => $token);
6462                        
6463            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6464          } else {          } else {
# Line 6029  sub _tree_construction_main ($) { Line 6466  sub _tree_construction_main ($) {
6466          }          }
6467    
6468          ## "after body" insertion mode          ## "after body" insertion mode
6469          !!!parse-error (type => 'after body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'after body',
6470                            text => $token->{tag_name}, token => $token);
6471    
6472          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6473          !!!ack-later;          !!!ack-later;
# Line 6038  sub _tree_construction_main ($) { Line 6476  sub _tree_construction_main ($) {
6476        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6477          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6478            !!!cp ('t305');            !!!cp ('t305');
6479            !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html:/',
6480                              text => $token->{tag_name}, token => $token);
6481                        
6482            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6483            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
# Line 6050  sub _tree_construction_main ($) { Line 6489  sub _tree_construction_main ($) {
6489          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
6490            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
6491              !!!cp ('t307');              !!!cp ('t307');
6492              !!!parse-error (type => 'unmatched end tag:html', token => $token);              !!!parse-error (type => 'unmatched end tag',
6493                                text => 'html', token => $token);
6494              ## Ignore the token              ## Ignore the token
6495              !!!next-token;              !!!next-token;
6496              next B;              next B;
# Line 6062  sub _tree_construction_main ($) { Line 6502  sub _tree_construction_main ($) {
6502            }            }
6503          } else {          } else {
6504            !!!cp ('t309');            !!!cp ('t309');
6505            !!!parse-error (type => 'after body:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after body:/',
6506                              text => $token->{tag_name}, token => $token);
6507    
6508            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
6509            ## reprocess            ## reprocess
# Line 6090  sub _tree_construction_main ($) { Line 6531  sub _tree_construction_main ($) {
6531          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
6532            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6533              !!!cp ('t311');              !!!cp ('t311');
6534              !!!parse-error (type => 'in frameset:#character', token => $token);              !!!parse-error (type => 'in frameset:#text', token => $token);
6535            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6536              !!!cp ('t312');              !!!cp ('t312');
6537              !!!parse-error (type => 'after frameset:#character', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6538            } else { # "after html frameset"            } else { # "after after frameset"
6539              !!!cp ('t313');              !!!cp ('t313');
6540              !!!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);  
6541            }            }
6542                        
6543            ## Ignore the token.            ## Ignore the token.
# Line 6116  sub _tree_construction_main ($) { Line 6553  sub _tree_construction_main ($) {
6553                    
6554          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
6555        } 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');  
         }  
   
6556          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6557              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6558            !!!cp ('t318');            !!!cp ('t318');
# Line 6143  sub _tree_construction_main ($) { Line 6570  sub _tree_construction_main ($) {
6570            next B;            next B;
6571          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
6572            !!!cp ('t320');            !!!cp ('t320');
6573            ## NOTE: As if in body.            ## NOTE: As if in head.
6574            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
6575            next B;            next B;
6576    
6577              ## NOTE: |<!DOCTYPE HTML><frameset></frameset></html><noframes></noframes>|
6578              ## has no parse error.
6579          } else {          } else {
6580            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6581              !!!cp ('t321');              !!!cp ('t321');
6582              !!!parse-error (type => 'in frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset',
6583            } else {                              text => $token->{tag_name}, token => $token);
6584              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6585              !!!cp ('t322');              !!!cp ('t322');
6586              !!!parse-error (type => 'after frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after frameset',
6587                                text => $token->{tag_name}, token => $token);
6588              } else { # "after after frameset"
6589                !!!cp ('t322.2');
6590                !!!parse-error (type => 'after after frameset',
6591                                text => $token->{tag_name}, token => $token);
6592            }            }
6593            ## Ignore the token            ## Ignore the token
6594            !!!nack ('t322.1');            !!!nack ('t322.1');
# Line 6160  sub _tree_construction_main ($) { Line 6596  sub _tree_construction_main ($) {
6596            next B;            next B;
6597          }          }
6598        } 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');  
         }  
   
6599          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6600              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6601            if ($self->{open_elements}->[-1]->[1] & HTML_EL and            if ($self->{open_elements}->[-1]->[1] & HTML_EL and
6602                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
6603              !!!cp ('t325');              !!!cp ('t325');
6604              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6605                                text => $token->{tag_name}, token => $token);
6606              ## Ignore the token              ## Ignore the token
6607              !!!next-token;              !!!next-token;
6608            } else {            } else {
# Line 6201  sub _tree_construction_main ($) { Line 6628  sub _tree_construction_main ($) {
6628          } else {          } else {
6629            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6630              !!!cp ('t330');              !!!cp ('t330');
6631              !!!parse-error (type => 'in frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset:/',
6632            } else {                              text => $token->{tag_name}, token => $token);
6633              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6634                !!!cp ('t330.1');
6635                !!!parse-error (type => 'after frameset:/',
6636                                text => $token->{tag_name}, token => $token);
6637              } else { # "after after html"
6638              !!!cp ('t331');              !!!cp ('t331');
6639              !!!parse-error (type => 'after frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after after frameset:/',
6640                                text => $token->{tag_name}, token => $token);
6641            }            }
6642            ## Ignore the token            ## Ignore the token
6643            !!!next-token;            !!!next-token;
# Line 6271  sub _tree_construction_main ($) { Line 6704  sub _tree_construction_main ($) {
6704                                           ->{has_reference});                                           ->{has_reference});
6705            } elsif ($token->{attributes}->{content}) {            } elsif ($token->{attributes}->{content}) {
6706              if ($token->{attributes}->{content}->{value}              if ($token->{attributes}->{content}->{value}
6707                  =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                  =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
6708                      [\x09-\x0D\x20]*=                      [\x09-\x0D\x20]*=
6709                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
6710                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
6711                !!!cp ('t336');                !!!cp ('t336');
6712                ## NOTE: Whether the encoding is supported or not is handled                ## NOTE: Whether the encoding is supported or not is handled
6713                ## in the {change_encoding} callback.                ## in the {change_encoding} callback.
# Line 6312  sub _tree_construction_main ($) { Line 6745  sub _tree_construction_main ($) {
6745          $parse_rcdata->(RCDATA_CONTENT_MODEL);          $parse_rcdata->(RCDATA_CONTENT_MODEL);
6746          next B;          next B;
6747        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
6748          !!!parse-error (type => 'in body:body', token => $token);          !!!parse-error (type => 'in body', text => 'body', token => $token);
6749                                
6750          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
6751              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {
# Line 6432  sub _tree_construction_main ($) { Line 6865  sub _tree_construction_main ($) {
6865              if ($i != -1) {              if ($i != -1) {
6866                !!!cp ('t355');                !!!cp ('t355');
6867                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
6868                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
6869                                    ->manakai_local_name,                                    ->manakai_local_name,
6870                                token => $token);                                token => $token);
6871              } else {              } else {
# Line 6586  sub _tree_construction_main ($) { Line 7019  sub _tree_construction_main ($) {
7019                  xmp => 1,                  xmp => 1,
7020                  iframe => 1,                  iframe => 1,
7021                  noembed => 1,                  noembed => 1,
7022                  noframes => 1,                  noframes => 1, ## NOTE: This is an "as if in head" code clone.
7023                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
7024                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7025          if ($token->{tag_name} eq 'xmp') {          if ($token->{tag_name} eq 'xmp') {
# Line 6608  sub _tree_construction_main ($) { Line 7041  sub _tree_construction_main ($) {
7041            !!!next-token;            !!!next-token;
7042            next B;            next B;
7043          } else {          } else {
7044              !!!ack ('t391.1');
7045    
7046            my $at = $token->{attributes};            my $at = $token->{attributes};
7047            my $form_attrs;            my $form_attrs;
7048            $form_attrs->{action} = $at->{action} if $at->{action};            $form_attrs->{action} = $at->{action} if $at->{action};
# Line 6651  sub _tree_construction_main ($) { Line 7086  sub _tree_construction_main ($) {
7086                           line => $token->{line}, column => $token->{column}},                           line => $token->{line}, column => $token->{column}},
7087                          {type => END_TAG_TOKEN, tag_name => 'form',                          {type => END_TAG_TOKEN, tag_name => 'form',
7088                           line => $token->{line}, column => $token->{column}};                           line => $token->{line}, column => $token->{column}};
           !!!nack ('t391.1'); ## NOTE: Not acknowledged.  
7089            !!!back-token (@tokens);            !!!back-token (@tokens);
7090            !!!next-token;            !!!next-token;
7091            next B;            next B;
# Line 6699  sub _tree_construction_main ($) { Line 7133  sub _tree_construction_main ($) {
7133            ## Ignore the token            ## Ignore the token
7134          } else {          } else {
7135            !!!cp ('t398');            !!!cp ('t398');
7136            !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);            !!!parse-error (type => 'in RCDATA:#eof', token => $token);
7137          }          }
7138          !!!next-token;          !!!next-token;
7139          next B;          next B;
7140          } elsif ($token->{tag_name} eq 'rt' or
7141                   $token->{tag_name} eq 'rp') {
7142            ## has a |ruby| element in scope
7143            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
7144              my $node = $self->{open_elements}->[$_];
7145              if ($node->[1] & RUBY_EL) {
7146                !!!cp ('t398.1');
7147                ## generate implied end tags
7148                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7149                  !!!cp ('t398.2');
7150                  pop @{$self->{open_elements}};
7151                }
7152                unless ($self->{open_elements}->[-1]->[1] & RUBY_EL) {
7153                  !!!cp ('t398.3');
7154                  !!!parse-error (type => 'not closed',
7155                                  text => $self->{open_elements}->[-1]->[0]
7156                                      ->manakai_local_name,
7157                                  token => $token);
7158                  pop @{$self->{open_elements}}
7159                      while not $self->{open_elements}->[-1]->[1] & RUBY_EL;
7160                }
7161                last INSCOPE;
7162              } elsif ($node->[1] & SCOPING_EL) {
7163                !!!cp ('t398.4');
7164                last INSCOPE;
7165              }
7166            } # INSCOPE
7167    
7168            !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
7169    
7170            !!!nack ('t398.5');
7171            !!!next-token;
7172            redo B;
7173        } elsif ($token->{tag_name} eq 'math' or        } elsif ($token->{tag_name} eq 'math' or
7174                 $token->{tag_name} eq 'svg') {                 $token->{tag_name} eq 'svg') {
7175          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
7176    
7177            ## "Adjust MathML attributes" ('math' only) - done in insert-element-f
7178    
7179          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f
7180    
7181          ## "adjust foreign attributes" - done in insert-element-f          ## "adjust foreign attributes" - done in insert-element-f
# Line 6733  sub _tree_construction_main ($) { Line 7202  sub _tree_construction_main ($) {
7202                  thead => 1, tr => 1,                  thead => 1, tr => 1,
7203                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7204          !!!cp ('t401');          !!!cp ('t401');
7205          !!!parse-error (type => 'in body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in body',
7206                            text => $token->{tag_name}, token => $token);
7207          ## Ignore the token          ## Ignore the token
7208          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.
7209          !!!next-token;          !!!next-token;
# Line 6818  sub _tree_construction_main ($) { Line 7288  sub _tree_construction_main ($) {
7288            }            }
7289    
7290            !!!parse-error (type => 'start tag not allowed',            !!!parse-error (type => 'start tag not allowed',
7291                            value => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7292            ## NOTE: Ignore the token.            ## NOTE: Ignore the token.
7293            !!!next-token;            !!!next-token;
7294            next B;            next B;
# Line 6828  sub _tree_construction_main ($) { Line 7298  sub _tree_construction_main ($) {
7298            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {
7299              !!!cp ('t403');              !!!cp ('t403');
7300              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7301                              value => $_->[0]->manakai_local_name,                              text => $_->[0]->manakai_local_name,
7302                              token => $token);                              token => $token);
7303              last;              last;
7304            } else {            } else {
# Line 6848  sub _tree_construction_main ($) { Line 7318  sub _tree_construction_main ($) {
7318            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {
7319              !!!cp ('t406');              !!!cp ('t406');
7320              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7321                              value => $self->{open_elements}->[1]->[0]                              text => $self->{open_elements}->[1]->[0]
7322                                  ->manakai_local_name,                                  ->manakai_local_name,
7323                              token => $token);                              token => $token);
7324            } else {            } else {
# Line 6859  sub _tree_construction_main ($) { Line 7329  sub _tree_construction_main ($) {
7329            next B;            next B;
7330          } else {          } else {
7331            !!!cp ('t408');            !!!cp ('t408');
7332            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7333                              text => $token->{tag_name}, token => $token);
7334            ## Ignore the token            ## Ignore the token
7335            !!!next-token;            !!!next-token;
7336            next B;            next B;
# Line 6887  sub _tree_construction_main ($) { Line 7358  sub _tree_construction_main ($) {
7358    
7359          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7360            !!!cp ('t413');            !!!cp ('t413');
7361            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7362                              text => $token->{tag_name}, token => $token);
7363              ## NOTE: Ignore the token.
7364          } else {          } else {
7365            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7366            while ({            while ({
7367                      ## END_TAG_OPTIONAL_EL
7368                    dd => ($token->{tag_name} ne 'dd'),                    dd => ($token->{tag_name} ne 'dd'),
7369                    dt => ($token->{tag_name} ne 'dt'),                    dt => ($token->{tag_name} ne 'dt'),
7370                    li => ($token->{tag_name} ne 'li'),                    li => ($token->{tag_name} ne 'li'),
7371                    p => 1,                    p => 1,
7372                      rt => 1,
7373                      rp => 1,
7374                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {
7375              !!!cp ('t409');              !!!cp ('t409');
7376              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
# Line 6905  sub _tree_construction_main ($) { Line 7381  sub _tree_construction_main ($) {
7381                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7382              !!!cp ('t412');              !!!cp ('t412');
7383              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7384                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7385                                  ->manakai_local_name,                                  ->manakai_local_name,
7386                              token => $token);                              token => $token);
7387            } else {            } else {
# Line 6942  sub _tree_construction_main ($) { Line 7418  sub _tree_construction_main ($) {
7418    
7419          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7420            !!!cp ('t421');            !!!cp ('t421');
7421            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7422                              text => $token->{tag_name}, token => $token);
7423              ## NOTE: Ignore the token.
7424          } else {          } else {
7425            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7426            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 6955  sub _tree_construction_main ($) { Line 7433  sub _tree_construction_main ($) {
7433                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7434              !!!cp ('t417.1');              !!!cp ('t417.1');
7435              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7436                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7437                                  ->manakai_local_name,                                  ->manakai_local_name,
7438                              token => $token);                              token => $token);
7439            } else {            } else {
# Line 6987  sub _tree_construction_main ($) { Line 7465  sub _tree_construction_main ($) {
7465    
7466          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7467            !!!cp ('t425.1');            !!!cp ('t425.1');
7468            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7469                              text => $token->{tag_name}, token => $token);
7470              ## NOTE: Ignore the token.
7471          } else {          } else {
7472            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7473            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 6999  sub _tree_construction_main ($) { Line 7479  sub _tree_construction_main ($) {
7479            if ($self->{open_elements}->[-1]->[0]->manakai_local_name            if ($self->{open_elements}->[-1]->[0]->manakai_local_name
7480                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7481              !!!cp ('t425');              !!!cp ('t425');
7482              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
7483                                text => $token->{tag_name}, token => $token);
7484            } else {            } else {
7485              !!!cp ('t426');              !!!cp ('t426');
7486            }            }
# Line 7030  sub _tree_construction_main ($) { Line 7511  sub _tree_construction_main ($) {
7511                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7512              !!!cp ('t412.1');              !!!cp ('t412.1');
7513              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7514                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7515                                  ->manakai_local_name,                                  ->manakai_local_name,
7516                              token => $token);                              token => $token);
7517            } else {            } else {
# Line 7040  sub _tree_construction_main ($) { Line 7521  sub _tree_construction_main ($) {
7521            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
7522          } else {          } else {
7523            !!!cp ('t413.1');            !!!cp ('t413.1');
7524            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7525                              text => $token->{tag_name}, token => $token);
7526    
7527            !!!cp ('t415.1');            !!!cp ('t415.1');
7528            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
# Line 7063  sub _tree_construction_main ($) { Line 7545  sub _tree_construction_main ($) {
7545          next B;          next B;
7546        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
7547          !!!cp ('t428');          !!!cp ('t428');
7548          !!!parse-error (type => 'unmatched end tag:br', token => $token);          !!!parse-error (type => 'unmatched end tag',
7549                            text => 'br', token => $token);
7550    
7551          ## As if <br>          ## As if <br>
7552          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
# Line 7088  sub _tree_construction_main ($) { Line 7571  sub _tree_construction_main ($) {
7571                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
7572                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7573          !!!cp ('t429');          !!!cp ('t429');
7574          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'unmatched end tag',
7575                            text => $token->{tag_name}, token => $token);
7576          ## Ignore the token          ## Ignore the token
7577          !!!next-token;          !!!next-token;
7578          next B;          next B;
# Line 7107  sub _tree_construction_main ($) { Line 7591  sub _tree_construction_main ($) {
7591              ## generate implied end tags              ## generate implied end tags
7592              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7593                !!!cp ('t430');                !!!cp ('t430');
7594                ## ISSUE: Can this case be reached?                ## NOTE: |<ruby><rt></ruby>|.
7595                  ## ISSUE: <ruby><rt></rt> will also take this code path,
7596                  ## which seems wrong.
7597                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
7598                  $node_i++;
7599              }              }
7600                    
7601              ## Step 2              ## Step 2
# Line 7117  sub _tree_construction_main ($) { Line 7604  sub _tree_construction_main ($) {
7604                !!!cp ('t431');                !!!cp ('t431');
7605                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
7606                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
7607                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
7608                                    ->manakai_local_name,                                    ->manakai_local_name,
7609                                token => $token);                                token => $token);
7610              } else {              } else {
# Line 7125  sub _tree_construction_main ($) { Line 7612  sub _tree_construction_main ($) {
7612              }              }
7613                            
7614              ## Step 3              ## Step 3
7615              splice @{$self->{open_elements}}, $node_i;              splice @{$self->{open_elements}}, $node_i if $node_i < 0;
7616    
7617              !!!next-token;              !!!next-token;
7618              last S2;              last S2;
# Line 7136  sub _tree_construction_main ($) { Line 7623  sub _tree_construction_main ($) {
7623                  ($node->[1] & SPECIAL_EL or                  ($node->[1] & SPECIAL_EL or
7624                   $node->[1] & SCOPING_EL)) {                   $node->[1] & SCOPING_EL)) {
7625                !!!cp ('t433');                !!!cp ('t433');
7626                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
7627                                  text => $token->{tag_name}, token => $token);
7628                ## Ignore the token                ## Ignore the token
7629                !!!next-token;                !!!next-token;
7630                last S2;                last S2;
# Line 7182  sub _tree_construction_main ($) { Line 7670  sub _tree_construction_main ($) {
7670    ## TODO: script stuffs    ## TODO: script stuffs
7671  } # _tree_construct_main  } # _tree_construct_main
7672    
7673  sub set_inner_html ($$$) {  sub set_inner_html ($$$;$) {
7674    my $class = shift;    my $class = shift;
7675    my $node = shift;    my $node = shift;
7676    my $s = \$_[0];    my $s = \$_[0];
7677    my $onerror = $_[1];    my $onerror = $_[1];
7678      my $get_wrapper = $_[2] || sub ($) { return $_[0] };
7679    
7680    ## ISSUE: Should {confident} be true?    ## ISSUE: Should {confident} be true?
7681    
# Line 7205  sub set_inner_html ($$$) { Line 7694  sub set_inner_html ($$$) {
7694      }      }
7695    
7696      ## Step 3, 4, 5 # MUST      ## Step 3, 4, 5 # MUST
7697      $class->parse_string ($$s => $node, $onerror);      $class->parse_char_string ($$s => $node, $onerror, $get_wrapper);
7698    } elsif ($nt == 1) {    } elsif ($nt == 1) {
7699      ## TODO: If non-html element      ## TODO: If non-html element
7700    
7701      ## NOTE: Most of this code is copied from |parse_string|      ## NOTE: Most of this code is copied from |parse_string|
7702    
7703    ## TODO: Support for $get_wrapper
7704    
7705      ## Step 1 # MUST      ## Step 1 # MUST
7706      my $this_doc = $node->owner_document;      my $this_doc = $node->owner_document;
7707      my $doc = $this_doc->implementation->create_document;      my $doc = $this_doc->implementation->create_document;
# Line 7272  sub set_inner_html ($$$) { Line 7763  sub set_inner_html ($$$) {
7763                  0x10FFFE => 1, 0x10FFFF => 1,                  0x10FFFE => 1, 0x10FFFF => 1,
7764                 }->{$self->{next_char}}) {                 }->{$self->{next_char}}) {
7765          !!!cp ('i4.1');          !!!cp ('i4.1');
7766          !!!parse-error (type => 'control char', level => $self->{must_level});          if ($self->{next_char} < 0x10000) {
7767  ## TODO: error type documentation            !!!parse-error (type => 'control char',
7768                              text => (sprintf 'U+%04X', $self->{next_char}));
7769            } else {
7770              !!!parse-error (type => 'control char',
7771                              text => (sprintf 'U-%08X', $self->{next_char}));
7772            }
7773        }        }
7774      };      };
7775      $p->{prev_char} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];

Legend:
Removed from v.1.137  
changed lines
  Added in v.1.170

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24