/[suikacvs]/markup/html/whatpm/Whatpm/HTML.pm.src
Suika

Diff of /markup/html/whatpm/Whatpm/HTML.pm.src

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.132 by wakaba, Sun Apr 13 10:36:40 2008 UTC revision 1.190 by wakaba, Sun Sep 21 05:08:16 2008 UTC
# Line 3  use strict; Line 3  use strict;
3  our $VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};  our $VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
4  use Error qw(:try);  use Error qw(:try);
5    
6    ## NOTE: This module don't check all HTML5 parse errors; character
7    ## encoding related parse errors are expected to be handled by relevant
8    ## modules.
9    ## Parse errors for control characters that are not allowed in HTML5
10    ## documents, for surrogate code points, and for noncharacter code
11    ## points, as well as U+FFFD substitions for characters whose code points
12    ## is higher than U+10FFFF may be detected by combining the parser with
13    ## the checker implemented by Whatpm::Charset::UnicodeChecker (for its
14    ## usage example, see |t/HTML-tree.t| in the Whatpm package or the
15    ## WebHACC::Language::HTML module in the WebHACC package).
16    
17  ## ISSUE:  ## ISSUE:
18  ## var doc = implementation.createDocument (null, null, null);  ## var doc = implementation.createDocument (null, null, null);
19  ## doc.write ('');  ## doc.write ('');
20  ## alert (doc.compatMode);  ## alert (doc.compatMode);
21    
22  ## TODO: 1252 parse error (revision 1264)  require IO::Handle;
 ## TODO: 8859-11 = 874 (revision 1271)  
23    
24  my $HTML_NS = q<http://www.w3.org/1999/xhtml>;  my $HTML_NS = q<http://www.w3.org/1999/xhtml>;
25  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 56  sub MISC_SPECIAL_EL () { 0b1000000000000
56  sub FOREIGN_EL () { 0b10000000000000000000000000 }  sub FOREIGN_EL () { 0b10000000000000000000000000 }
57  sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 }  sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 }
58  sub MML_AXML_EL () { 0b1000000000000000000000000000 }  sub MML_AXML_EL () { 0b1000000000000000000000000000 }
59    sub RUBY_EL () { 0b10000000000000000000000000000 }
60    sub RUBY_COMPONENT_EL () { 0b100000000000000000000000000000 }
61    
62  sub TABLE_ROWS_EL () {  sub TABLE_ROWS_EL () {
63    TABLE_EL |    TABLE_EL |
# Line 53  sub TABLE_ROWS_EL () { Line 65  sub TABLE_ROWS_EL () {
65    TABLE_ROW_GROUP_EL    TABLE_ROW_GROUP_EL
66  }  }
67    
68    ## NOTE: Used in "generate implied end tags" algorithm.
69    ## NOTE: There is a code where a modified version of END_TAG_OPTIONAL_EL
70    ## is used in "generate implied end tags" implementation (search for the
71    ## function mae).
72  sub END_TAG_OPTIONAL_EL () {  sub END_TAG_OPTIONAL_EL () {
73    DD_EL |    DD_EL |
74    DT_EL |    DT_EL |
75    LI_EL |    LI_EL |
76    P_EL    P_EL |
77      RUBY_COMPONENT_EL
78  }  }
79    
80    ## NOTE: Used in </body> and EOF algorithms.
81  sub ALL_END_TAG_OPTIONAL_EL () {  sub ALL_END_TAG_OPTIONAL_EL () {
82    END_TAG_OPTIONAL_EL |    DD_EL |
83      DT_EL |
84      LI_EL |
85      P_EL |
86    
87    BODY_EL |    BODY_EL |
88    HTML_EL |    HTML_EL |
89    TABLE_CELL_EL |    TABLE_CELL_EL |
# Line 97  sub SPECIAL_EL () { Line 119  sub SPECIAL_EL () {
119    ADDRESS_EL |    ADDRESS_EL |
120    BODY_EL |    BODY_EL |
121    DIV_EL |    DIV_EL |
122    END_TAG_OPTIONAL_EL |  
123      DD_EL |
124      DT_EL |
125      LI_EL |
126      P_EL |
127    
128    FORM_EL |    FORM_EL |
129    FRAMESET_EL |    FRAMESET_EL |
130    HEADING_EL |    HEADING_EL |
# Line 171  my $el_category = { Line 198  my $el_category = {
198    param => MISC_SPECIAL_EL,    param => MISC_SPECIAL_EL,
199    plaintext => MISC_SPECIAL_EL,    plaintext => MISC_SPECIAL_EL,
200    pre => MISC_SPECIAL_EL,    pre => MISC_SPECIAL_EL,
201      rp => RUBY_COMPONENT_EL,
202      rt => RUBY_COMPONENT_EL,
203      ruby => RUBY_EL,
204    s => FORMATTING_EL,    s => FORMATTING_EL,
205    script => MISC_SPECIAL_EL,    script => MISC_SPECIAL_EL,
206    select => SELECT_EL,    select => SELECT_EL,
# Line 212  my $el_category_f = { Line 242  my $el_category_f = {
242  };  };
243    
244  my $svg_attr_name = {  my $svg_attr_name = {
245      attributename => 'attributeName',
246    attributetype => 'attributeType',    attributetype => 'attributeType',
247    basefrequency => 'baseFrequency',    basefrequency => 'baseFrequency',
248    baseprofile => 'baseProfile',    baseprofile => 'baseProfile',
# Line 222  my $svg_attr_name = { Line 253  my $svg_attr_name = {
253    diffuseconstant => 'diffuseConstant',    diffuseconstant => 'diffuseConstant',
254    edgemode => 'edgeMode',    edgemode => 'edgeMode',
255    externalresourcesrequired => 'externalResourcesRequired',    externalresourcesrequired => 'externalResourcesRequired',
   fecolormatrix => 'feColorMatrix',  
   fecomposite => 'feComposite',  
   fegaussianblur => 'feGaussianBlur',  
   femorphology => 'feMorphology',  
   fetile => 'feTile',  
256    filterres => 'filterRes',    filterres => 'filterRes',
257    filterunits => 'filterUnits',    filterunits => 'filterUnits',
258    glyphref => 'glyphRef',    glyphref => 'glyphRef',
# Line 260  my $svg_attr_name = { Line 286  my $svg_attr_name = {
286    repeatcount => 'repeatCount',    repeatcount => 'repeatCount',
287    repeatdur => 'repeatDur',    repeatdur => 'repeatDur',
288    requiredextensions => 'requiredExtensions',    requiredextensions => 'requiredExtensions',
289      requiredfeatures => 'requiredFeatures',
290    specularconstant => 'specularConstant',    specularconstant => 'specularConstant',
291    specularexponent => 'specularExponent',    specularexponent => 'specularExponent',
292    spreadmethod => 'spreadMethod',    spreadmethod => 'spreadMethod',
# Line 332  my $c1_entity_char = { Line 359  my $c1_entity_char = {
359  }; # $c1_entity_char  }; # $c1_entity_char
360    
361  sub parse_byte_string ($$$$;$) {  sub parse_byte_string ($$$$;$) {
362      my $self = shift;
363      my $charset_name = shift;
364      open my $input, '<', ref $_[0] ? $_[0] : \($_[0]);
365      return $self->parse_byte_stream ($charset_name, $input, @_[1..$#_]);
366    } # parse_byte_string
367    
368    sub parse_byte_stream ($$$$;$$) {
369      # my ($self, $charset_name, $byte_stream, $doc, $onerror, $get_wrapper) = @_;
370    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
371    my $charset = shift;    my $charset_name = shift;
372    my $bytes_s = ref $_[0] ? $_[0] : \($_[0]);    my $byte_stream = $_[0];
373    my $s;  
374        my $onerror = $_[2] || sub {
375    if (defined $charset) {      my (%opt) = @_;
376      require Encode; ## TODO: decode(utf8) don't delete BOM      warn "Parse error ($opt{type})\n";
377      $s = \ (Encode::decode ($charset, $$bytes_s));    };
378      $self->{input_encoding} = lc $charset; ## TODO: normalize name    $self->{parse_error} = $onerror; # updated later by parse_char_string
379      $self->{confident} = 1;  
380    } else {    my $get_wrapper = $_[3] || sub ($) {
381      ## TODO: Implement HTML5 detection algorithm      return $_[0]; # $_[0] = byte stream handle, returned = arg to char handle
382      };
383    
384      ## HTML5 encoding sniffing algorithm
385      require Message::Charset::Info;
386      my $charset;
387      my $buffer;
388      my ($char_stream, $e_status);
389    
390      SNIFFING: {
391        ## NOTE: By setting |allow_fallback| option true when the
392        ## |get_decode_handle| method is invoked, we ignore what the HTML5
393        ## spec requires, i.e. unsupported encoding should be ignored.
394          ## TODO: We should not do this unless the parser is invoked
395          ## in the conformance checking mode, in which this behavior
396          ## would be useful.
397    
398        ## Step 1
399        if (defined $charset_name) {
400          $charset = Message::Charset::Info->get_by_html_name ($charset_name);
401              ## TODO: Is this ok?  Transfer protocol's parameter should be
402              ## interpreted in its semantics?
403    
404          ($char_stream, $e_status) = $charset->get_decode_handle
405              ($byte_stream, allow_error_reporting => 1,
406               allow_fallback => 1);
407          if ($char_stream) {
408            $self->{confident} = 1;
409            last SNIFFING;
410          } else {
411            !!!parse-error (type => 'charset:not supported',
412                            layer => 'encode',
413                            line => 1, column => 1,
414                            value => $charset_name,
415                            level => $self->{level}->{uncertain});
416          }
417        }
418    
419        ## Step 2
420        my $byte_buffer = '';
421        for (1..1024) {
422          my $char = $byte_stream->getc;
423          last unless defined $char;
424          $byte_buffer .= $char;
425        } ## TODO: timeout
426    
427        ## Step 3
428        if ($byte_buffer =~ /^\xFE\xFF/) {
429          $charset = Message::Charset::Info->get_by_html_name ('utf-16be');
430          ($char_stream, $e_status) = $charset->get_decode_handle
431              ($byte_stream, allow_error_reporting => 1,
432               allow_fallback => 1, byte_buffer => \$byte_buffer);
433          $self->{confident} = 1;
434          last SNIFFING;
435        } elsif ($byte_buffer =~ /^\xFF\xFE/) {
436          $charset = Message::Charset::Info->get_by_html_name ('utf-16le');
437          ($char_stream, $e_status) = $charset->get_decode_handle
438              ($byte_stream, allow_error_reporting => 1,
439               allow_fallback => 1, byte_buffer => \$byte_buffer);
440          $self->{confident} = 1;
441          last SNIFFING;
442        } elsif ($byte_buffer =~ /^\xEF\xBB\xBF/) {
443          $charset = Message::Charset::Info->get_by_html_name ('utf-8');
444          ($char_stream, $e_status) = $charset->get_decode_handle
445              ($byte_stream, allow_error_reporting => 1,
446               allow_fallback => 1, byte_buffer => \$byte_buffer);
447          $self->{confident} = 1;
448          last SNIFFING;
449        }
450    
451        ## Step 4
452        ## TODO: <meta charset>
453    
454        ## Step 5
455        ## TODO: from history
456    
457        ## Step 6
458      require Whatpm::Charset::UniversalCharDet;      require Whatpm::Charset::UniversalCharDet;
459      $charset = Whatpm::Charset::UniversalCharDet->detect_byte_string      $charset_name = Whatpm::Charset::UniversalCharDet->detect_byte_string
460          (substr ($$bytes_s, 0, 1024));          ($byte_buffer);
461      $charset ||= 'windows-1252';      if (defined $charset_name) {
462      $s = \ (Encode::decode ($charset, $$bytes_s));        $charset = Message::Charset::Info->get_by_html_name ($charset_name);
463      $self->{input_encoding} = $charset;  
464          ## ISSUE: Unsupported encoding is not ignored according to the spec.
465          require Whatpm::Charset::DecodeHandle;
466          $buffer = Whatpm::Charset::DecodeHandle::ByteBuffer->new
467              ($byte_stream);
468          ($char_stream, $e_status) = $charset->get_decode_handle
469              ($buffer, allow_error_reporting => 1,
470               allow_fallback => 1, byte_buffer => \$byte_buffer);
471          if ($char_stream) {
472            $buffer->{buffer} = $byte_buffer;
473            !!!parse-error (type => 'sniffing:chardet',
474                            text => $charset_name,
475                            level => $self->{level}->{info},
476                            layer => 'encode',
477                            line => 1, column => 1);
478            $self->{confident} = 0;
479            last SNIFFING;
480          }
481        }
482    
483        ## Step 7: default
484        ## TODO: Make this configurable.
485        $charset = Message::Charset::Info->get_by_html_name ('windows-1252');
486            ## NOTE: We choose |windows-1252| here, since |utf-8| should be
487            ## detectable in the step 6.
488        require Whatpm::Charset::DecodeHandle;
489        $buffer = Whatpm::Charset::DecodeHandle::ByteBuffer->new
490            ($byte_stream);
491        ($char_stream, $e_status)
492            = $charset->get_decode_handle ($buffer,
493                                           allow_error_reporting => 1,
494                                           allow_fallback => 1,
495                                           byte_buffer => \$byte_buffer);
496        $buffer->{buffer} = $byte_buffer;
497        !!!parse-error (type => 'sniffing:default',
498                        text => 'windows-1252',
499                        level => $self->{level}->{info},
500                        line => 1, column => 1,
501                        layer => 'encode');
502      $self->{confident} = 0;      $self->{confident} = 0;
503      } # SNIFFING
504    
505      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
506        $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name?
507        !!!parse-error (type => 'chardecode:fallback',
508                        #text => $self->{input_encoding},
509                        level => $self->{level}->{uncertain},
510                        line => 1, column => 1,
511                        layer => 'encode');
512      } elsif (not ($e_status &
513                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL ())) {
514        $self->{input_encoding} = $charset->get_iana_name;
515        !!!parse-error (type => 'chardecode:no error',
516                        text => $self->{input_encoding},
517                        level => $self->{level}->{uncertain},
518                        line => 1, column => 1,
519                        layer => 'encode');
520      } else {
521        $self->{input_encoding} = $charset->get_iana_name;
522    }    }
523    
524    $self->{change_encoding} = sub {    $self->{change_encoding} = sub {
525      my $self = shift;      my $self = shift;
526      my $charset = lc shift;      $charset_name = shift;
527      my $token = shift;      my $token = shift;
     ## TODO: if $charset is supported  
     ## TODO: normalize charset name  
528    
529      ## "Change the encoding" algorithm:      $charset = Message::Charset::Info->get_by_html_name ($charset_name);
530        ($char_stream, $e_status) = $charset->get_decode_handle
531            ($byte_stream, allow_error_reporting => 1, allow_fallback => 1,
532             byte_buffer => \ $buffer->{buffer});
533        
534        if ($char_stream) { # if supported
535          ## "Change the encoding" algorithm:
536    
537      ## Step 1            ## Step 1    
538      if ($charset eq 'utf-16') { ## ISSUE: UTF-16BE -> UTF-8? UTF-16LE -> UTF-8?        if ($charset->{category} &
539        $charset = 'utf-8';            Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) {
540      }          $charset = Message::Charset::Info->get_by_html_name ('utf-8');
541            ($char_stream, $e_status) = $charset->get_decode_handle
542                ($byte_stream,
543                 byte_buffer => \ $buffer->{buffer});
544          }
545          $charset_name = $charset->get_iana_name;
546          
547          ## Step 2
548          if (defined $self->{input_encoding} and
549              $self->{input_encoding} eq $charset_name) {
550            !!!parse-error (type => 'charset label:matching',
551                            text => $charset_name,
552                            level => $self->{level}->{info});
553            $self->{confident} = 1;
554            return;
555          }
556    
557      ## Step 2        !!!parse-error (type => 'charset label detected',
558      if (defined $self->{input_encoding} and                        text => $self->{input_encoding},
559          $self->{input_encoding} eq $charset) {                        value => $charset_name,
560        $self->{confident} = 1;                        level => $self->{level}->{warn},
561        return;                        token => $token);
562          
563          ## Step 3
564          # if (can) {
565            ## change the encoding on the fly.
566            #$self->{confident} = 1;
567            #return;
568          # }
569          
570          ## Step 4
571          throw Whatpm::HTML::RestartParser ();
572      }      }
573      }; # $self->{change_encoding}
574    
575      !!!parse-error (type => 'charset label detected:'.$self->{input_encoding}.    my $char_onerror = sub {
576          ':'.$charset, level => 'w', token => $token);      my (undef, $type, %opt) = @_;
577        !!!parse-error (layer => 'encode',
578      ## Step 3                      line => $self->{line}, column => $self->{column} + 1,
579      # if (can) {                      %opt, type => $type);
580        ## change the encoding on the fly.      if ($opt{octets}) {
581        #$self->{confident} = 1;        ${$opt{octets}} = "\x{FFFD}"; # relacement character
582        #return;      }
583      # }    };
584    
585      ## Step 4    my $wrapped_char_stream = $get_wrapper->($char_stream);
586      throw Whatpm::HTML::RestartParser (charset => $charset);    $wrapped_char_stream->onerror ($char_onerror);
   }; # $self->{change_encoding}  
587    
588    my @args = @_; shift @args; # $s    my @args = ($_[1], $_[2]); # $doc, $onerror - $get_wrapper = undef;
589    my $return;    my $return;
590    try {    try {
591      $return = $self->parse_char_string ($s, @args);        $return = $self->parse_char_stream ($wrapped_char_stream, @args);  
592    } catch Whatpm::HTML::RestartParser with {    } catch Whatpm::HTML::RestartParser with {
593      my $charset = shift->{charset};      ## NOTE: Invoked after {change_encoding}.
594      $s = \ (Encode::decode ($charset, $$bytes_s));      
595      $self->{input_encoding} = $charset; ## TODO: normalize      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
596          $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name?
597          !!!parse-error (type => 'chardecode:fallback',
598                          level => $self->{level}->{uncertain},
599                          #text => $self->{input_encoding},
600                          line => 1, column => 1,
601                          layer => 'encode');
602        } elsif (not ($e_status &
603                      Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL ())) {
604          $self->{input_encoding} = $charset->get_iana_name;
605          !!!parse-error (type => 'chardecode:no error',
606                          text => $self->{input_encoding},
607                          level => $self->{level}->{uncertain},
608                          line => 1, column => 1,
609                          layer => 'encode');
610        } else {
611          $self->{input_encoding} = $charset->get_iana_name;
612        }
613      $self->{confident} = 1;      $self->{confident} = 1;
614      $return = $self->parse_char_string ($s, @args);  
615        $wrapped_char_stream = $get_wrapper->($char_stream);
616        $wrapped_char_stream->onerror ($char_onerror);
617    
618        $return = $self->parse_char_stream ($wrapped_char_stream, @args);
619    };    };
620    return $return;    return $return;
621  } # parse_byte_string  } # parse_byte_stream
622    
623  ## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM  ## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM
624  ## and the HTML layer MUST ignore it.  However, we does strip BOM in  ## and the HTML layer MUST ignore it.  However, we does strip BOM in
# Line 411  sub parse_byte_string ($$$$;$) { Line 629  sub parse_byte_string ($$$$;$) {
629  ## 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
630  ## strip the BOM and never strip any ZWNBSP.  ## strip the BOM and never strip any ZWNBSP.
631    
632  *parse_char_string = \&parse_string;  sub parse_char_string ($$$;$$) {
633      #my ($self, $s, $doc, $onerror, $get_wrapper) = @_;
634      my $self = shift;
635      my $s = ref $_[0] ? $_[0] : \($_[0]);
636      require Whatpm::Charset::DecodeHandle;
637      my $input = Whatpm::Charset::DecodeHandle::CharString->new ($s);
638      return $self->parse_char_stream ($input, @_[1..$#_]);
639    } # parse_char_string
640    *parse_string = \&parse_char_string; ## NOTE: Alias for backward compatibility.
641    
642  sub parse_string ($$$;$) {  sub parse_char_stream ($$$;$$) {
643    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
644    my $s = ref $_[0] ? $_[0] : \($_[0]);    my $input = $_[0];
645    $self->{document} = $_[1];    $self->{document} = $_[1];
646    @{$self->{document}->child_nodes} = ();    @{$self->{document}->child_nodes} = ();
647    
# Line 424  sub parse_string ($$$;$) { Line 650  sub parse_string ($$$;$) {
650    $self->{confident} = 1 unless exists $self->{confident};    $self->{confident} = 1 unless exists $self->{confident};
651    $self->{document}->input_encoding ($self->{input_encoding})    $self->{document}->input_encoding ($self->{input_encoding})
652        if defined $self->{input_encoding};        if defined $self->{input_encoding};
653    ## TODO: |{input_encoding}| is needless?
654    
   my $i = 0;  
655    $self->{line_prev} = $self->{line} = 1;    $self->{line_prev} = $self->{line} = 1;
656    $self->{column_prev} = $self->{column} = 0;    $self->{column_prev} = -1;
657    $self->{set_next_char} = sub {    $self->{column} = 0;
658      $self->{set_nc} = sub {
659      my $self = shift;      my $self = shift;
660    
661      pop @{$self->{prev_char}};      my $char = '';
662      unshift @{$self->{prev_char}}, $self->{next_char};      if (defined $self->{next_nc}) {
663          $char = $self->{next_nc};
664          delete $self->{next_nc};
665          $self->{nc} = ord $char;
666        } else {
667          $self->{char_buffer} = '';
668          $self->{char_buffer_pos} = 0;
669    
670          my $count = $input->manakai_read_until
671             ($self->{char_buffer}, qr/[^\x00\x0A\x0D]/, $self->{char_buffer_pos});
672          if ($count) {
673            $self->{line_prev} = $self->{line};
674            $self->{column_prev} = $self->{column};
675            $self->{column}++;
676            $self->{nc}
677                = ord substr ($self->{char_buffer}, $self->{char_buffer_pos}++, 1);
678            return;
679          }
680    
681      $self->{next_char} = -1 and return if $i >= length $$s;        if ($input->read ($char, 1)) {
682      $self->{next_char} = ord substr $$s, $i++, 1;          $self->{nc} = ord $char;
683          } else {
684            $self->{nc} = -1;
685            return;
686          }
687        }
688    
689      ($self->{line_prev}, $self->{column_prev})      ($self->{line_prev}, $self->{column_prev})
690          = ($self->{line}, $self->{column});          = ($self->{line}, $self->{column});
691      $self->{column}++;      $self->{column}++;
692            
693      if ($self->{next_char} == 0x000A) { # LF      if ($self->{nc} == 0x000A) { # LF
694        !!!cp ('j1');        !!!cp ('j1');
695        $self->{line}++;        $self->{line}++;
696        $self->{column} = 0;        $self->{column} = 0;
697      } elsif ($self->{next_char} == 0x000D) { # CR      } elsif ($self->{nc} == 0x000D) { # CR
698        !!!cp ('j2');        !!!cp ('j2');
699        $i++ if substr ($$s, $i, 1) eq "\x0A";  ## TODO: support for abort/streaming
700        $self->{next_char} = 0x000A; # LF # MUST        my $next = '';
701          if ($input->read ($next, 1) and $next ne "\x0A") {
702            $self->{next_nc} = $next;
703          }
704          $self->{nc} = 0x000A; # LF # MUST
705        $self->{line}++;        $self->{line}++;
706        $self->{column} = 0;        $self->{column} = 0;
707      } elsif ($self->{next_char} > 0x10FFFF) {      } elsif ($self->{nc} == 0x0000) { # NULL
       !!!cp ('j3');  
       $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST  
     } elsif ($self->{next_char} == 0x0000) { # NULL  
708        !!!cp ('j4');        !!!cp ('j4');
709        !!!parse-error (type => 'NULL');        !!!parse-error (type => 'NULL');
710        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{nc} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
     } elsif ($self->{next_char} <= 0x0008 or  
              (0x000E <= $self->{next_char} and $self->{next_char} <= 0x001F) or  
              (0x007F <= $self->{next_char} and $self->{next_char} <= 0x009F) or  
              (0xD800 <= $self->{next_char} and $self->{next_char} <= 0xDFFF) or  
              (0xFDD0 <= $self->{next_char} and $self->{next_char} <= 0xFDDF) or  
              {  
               0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,  
               0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,  
               0x4FFFE => 1, 0x4FFFF => 1, 0x5FFFE => 1, 0x5FFFF => 1,  
               0x6FFFE => 1, 0x6FFFF => 1, 0x7FFFE => 1, 0x7FFFF => 1,  
               0x8FFFE => 1, 0x8FFFF => 1, 0x9FFFE => 1, 0x9FFFF => 1,  
               0xAFFFE => 1, 0xAFFFF => 1, 0xBFFFE => 1, 0xBFFFF => 1,  
               0xCFFFE => 1, 0xCFFFF => 1, 0xDFFFE => 1, 0xDFFFF => 1,  
               0xEFFFE => 1, 0xEFFFF => 1, 0xFFFFE => 1, 0xFFFFF => 1,  
               0x10FFFE => 1, 0x10FFFF => 1,  
              }->{$self->{next_char}}) {  
       !!!cp ('j5');  
       !!!parse-error (type => 'control char', level => $self->{must_level});  
 ## TODO: error type documentation  
711      }      }
712    };    };
713    $self->{prev_char} = [-1, -1, -1];  
714    $self->{next_char} = -1;    $self->{read_until} = sub {
715        #my ($scalar, $specials_range, $offset) = @_;
716        return 0 if defined $self->{next_nc};
717    
718        my $pattern = qr/[^$_[1]\x00\x0A\x0D]/;
719        my $offset = $_[2] || 0;
720    
721        if ($self->{char_buffer_pos} < length $self->{char_buffer}) {
722          pos ($self->{char_buffer}) = $self->{char_buffer_pos};
723          if ($self->{char_buffer} =~ /\G(?>$pattern)+/) {
724            substr ($_[0], $offset)
725                = substr ($self->{char_buffer}, $-[0], $+[0] - $-[0]);
726            my $count = $+[0] - $-[0];
727            if ($count) {
728              $self->{column} += $count;
729              $self->{char_buffer_pos} += $count;
730              $self->{line_prev} = $self->{line};
731              $self->{column_prev} = $self->{column} - 1;
732              $self->{nc} = -1;
733            }
734            return $count;
735          } else {
736            return 0;
737          }
738        } else {
739          my $count = $input->manakai_read_until ($_[0], $pattern, $_[2]);
740          if ($count) {
741            $self->{column} += $count;
742            $self->{line_prev} = $self->{line};
743            $self->{column_prev} = $self->{column} - 1;
744            $self->{nc} = -1;
745          }
746          return $count;
747        }
748      }; # $self->{read_until}
749    
750    my $onerror = $_[2] || sub {    my $onerror = $_[2] || sub {
751      my (%opt) = @_;      my (%opt) = @_;
# Line 492  sub parse_string ($$$;$) { Line 757  sub parse_string ($$$;$) {
757      $onerror->(line => $self->{line}, column => $self->{column}, @_);      $onerror->(line => $self->{line}, column => $self->{column}, @_);
758    };    };
759    
760      my $char_onerror = sub {
761        my (undef, $type, %opt) = @_;
762        !!!parse-error (layer => 'encode',
763                        line => $self->{line}, column => $self->{column} + 1,
764                        %opt, type => $type);
765      }; # $char_onerror
766    
767      if ($_[3]) {
768        $input = $_[3]->($input);
769        $input->onerror ($char_onerror);
770      } else {
771        $input->onerror ($char_onerror) unless defined $input->onerror;
772      }
773    
774    $self->_initialize_tokenizer;    $self->_initialize_tokenizer;
775    $self->_initialize_tree_constructor;    $self->_initialize_tree_constructor;
776    $self->_construct_tree;    $self->_construct_tree;
# Line 500  sub parse_string ($$$;$) { Line 779  sub parse_string ($$$;$) {
779    delete $self->{parse_error}; # remove loop    delete $self->{parse_error}; # remove loop
780    
781    return $self->{document};    return $self->{document};
782  } # parse_string  } # parse_char_stream
783    
784  sub new ($) {  sub new ($) {
785    my $class = shift;    my $class = shift;
786    my $self = bless {}, $class;    my $self = bless {
787    $self->{set_next_char} = sub {      level => {must => 'm',
788      $self->{next_char} = -1;                should => 's',
789                  warn => 'w',
790                  info => 'i',
791                  uncertain => 'u'},
792      }, $class;
793      $self->{set_nc} = sub {
794        $self->{nc} = -1;
795    };    };
796    $self->{parse_error} = sub {    $self->{parse_error} = sub {
797      #      #
# Line 533  sub RCDATA_CONTENT_MODEL () { CM_ENTITY Line 818  sub RCDATA_CONTENT_MODEL () { CM_ENTITY
818  sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }  sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }
819    
820  sub DATA_STATE () { 0 }  sub DATA_STATE () { 0 }
821  sub ENTITY_DATA_STATE () { 1 }  #sub ENTITY_DATA_STATE () { 1 }
822  sub TAG_OPEN_STATE () { 2 }  sub TAG_OPEN_STATE () { 2 }
823  sub CLOSE_TAG_OPEN_STATE () { 3 }  sub CLOSE_TAG_OPEN_STATE () { 3 }
824  sub TAG_NAME_STATE () { 4 }  sub TAG_NAME_STATE () { 4 }
# Line 544  sub BEFORE_ATTRIBUTE_VALUE_STATE () { 8 Line 829  sub BEFORE_ATTRIBUTE_VALUE_STATE () { 8
829  sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 }  sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 }
830  sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 }  sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 }
831  sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 }  sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 }
832  sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 }  #sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 }
833  sub MARKUP_DECLARATION_OPEN_STATE () { 13 }  sub MARKUP_DECLARATION_OPEN_STATE () { 13 }
834  sub COMMENT_START_STATE () { 14 }  sub COMMENT_START_STATE () { 14 }
835  sub COMMENT_START_DASH_STATE () { 15 }  sub COMMENT_START_DASH_STATE () { 15 }
# Line 567  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STAT Line 852  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STAT
852  sub BOGUS_DOCTYPE_STATE () { 32 }  sub BOGUS_DOCTYPE_STATE () { 32 }
853  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }
854  sub SELF_CLOSING_START_TAG_STATE () { 34 }  sub SELF_CLOSING_START_TAG_STATE () { 34 }
855  sub CDATA_BLOCK_STATE () { 35 }  sub CDATA_SECTION_STATE () { 35 }
856    sub MD_HYPHEN_STATE () { 36 } # "markup declaration open state" in the spec
857    sub MD_DOCTYPE_STATE () { 37 } # "markup declaration open state" in the spec
858    sub MD_CDATA_STATE () { 38 } # "markup declaration open state" in the spec
859    sub CDATA_RCDATA_CLOSE_TAG_STATE () { 39 } # "close tag open state" in the spec
860    sub CDATA_SECTION_MSE1_STATE () { 40 } # "CDATA section state" in the spec
861    sub CDATA_SECTION_MSE2_STATE () { 41 } # "CDATA section state" in the spec
862    sub PUBLIC_STATE () { 42 } # "after DOCTYPE name state" in the spec
863    sub SYSTEM_STATE () { 43 } # "after DOCTYPE name state" in the spec
864    ## NOTE: "Entity data state", "entity in attribute value state", and
865    ## "consume a character reference" algorithm are jointly implemented
866    ## using the following six states:
867    sub ENTITY_STATE () { 44 }
868    sub ENTITY_HASH_STATE () { 45 }
869    sub NCR_NUM_STATE () { 46 }
870    sub HEXREF_X_STATE () { 47 }
871    sub HEXREF_HEX_STATE () { 48 }
872    sub ENTITY_NAME_STATE () { 49 }
873    sub PCDATA_STATE () { 50 } # "data state" in the spec
874    
875  sub DOCTYPE_TOKEN () { 1 }  sub DOCTYPE_TOKEN () { 1 }
876  sub COMMENT_TOKEN () { 2 }  sub COMMENT_TOKEN () { 2 }
# Line 620  sub IN_COLUMN_GROUP_IM () { 0b10 } Line 923  sub IN_COLUMN_GROUP_IM () { 0b10 }
923  sub _initialize_tokenizer ($) {  sub _initialize_tokenizer ($) {
924    my $self = shift;    my $self = shift;
925    $self->{state} = DATA_STATE; # MUST    $self->{state} = DATA_STATE; # MUST
926      #$self->{s_kwd}; # state keyword - initialized when used
927      #$self->{entity__value}; # initialized when used
928      #$self->{entity__match}; # initialized when used
929    $self->{content_model} = PCDATA_CONTENT_MODEL; # be    $self->{content_model} = PCDATA_CONTENT_MODEL; # be
930    undef $self->{current_token}; # start tag, end tag, comment, or DOCTYPE    undef $self->{ct}; # current token
931    undef $self->{current_attribute};    undef $self->{ca}; # current attribute
932    undef $self->{last_emitted_start_tag_name};    undef $self->{last_stag_name}; # last emitted start tag name
933    undef $self->{last_attribute_value_state};    #$self->{prev_state}; # initialized when used
934    delete $self->{self_closing};    delete $self->{self_closing};
935    $self->{char} = [];    $self->{char_buffer} = '';
936    # $self->{next_char}    $self->{char_buffer_pos} = 0;
937      $self->{nc} = -1; # next input character
938      #$self->{next_nc}
939    !!!next-input-character;    !!!next-input-character;
940    $self->{token} = [];    $self->{token} = [];
941    # $self->{escape}    # $self->{escape}
# Line 638  sub _initialize_tokenizer ($) { Line 946  sub _initialize_tokenizer ($) {
946  ##       CHARACTER_TOKEN, or END_OF_FILE_TOKEN  ##       CHARACTER_TOKEN, or END_OF_FILE_TOKEN
947  ##   ->{name} (DOCTYPE_TOKEN)  ##   ->{name} (DOCTYPE_TOKEN)
948  ##   ->{tag_name} (START_TAG_TOKEN, END_TAG_TOKEN)  ##   ->{tag_name} (START_TAG_TOKEN, END_TAG_TOKEN)
949  ##   ->{public_identifier} (DOCTYPE_TOKEN)  ##   ->{pubid} (DOCTYPE_TOKEN)
950  ##   ->{system_identifier} (DOCTYPE_TOKEN)  ##   ->{sysid} (DOCTYPE_TOKEN)
951  ##   ->{quirks} == 1 or 0 (DOCTYPE_TOKEN): "force-quirks" flag  ##   ->{quirks} == 1 or 0 (DOCTYPE_TOKEN): "force-quirks" flag
952  ##   ->{attributes} isa HASH (START_TAG_TOKEN, END_TAG_TOKEN)  ##   ->{attributes} isa HASH (START_TAG_TOKEN, END_TAG_TOKEN)
953  ##        ->{name}  ##        ->{name}
# Line 650  sub _initialize_tokenizer ($) { Line 958  sub _initialize_tokenizer ($) {
958  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|
959  ##     while the token is pushed back to the stack.  ##     while the token is pushed back to the stack.
960    
 ## 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?  
   
961  ## Emitted token MUST immediately be handled by the tree construction state.  ## Emitted token MUST immediately be handled by the tree construction state.
962    
963  ## 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 662  sub _initialize_tokenizer ($) { Line 966  sub _initialize_tokenizer ($) {
966  ## has completed loading.  If one has, then it MUST be executed  ## has completed loading.  If one has, then it MUST be executed
967  ## and removed from the list.  ## and removed from the list.
968    
969  ## NOTE: HTML5 "Writing HTML documents" section, applied to  ## TODO: Polytheistic slash SHOULD NOT be used. (Applied only to atheists.)
970  ## documents and not to user agents and conformance checkers,  ## (This requirement was dropped from HTML5 spec, unfortunately.)
971  ## contains some requirements that are not detected by the  
972  ## parsing algorithm:  my $is_space = {
973  ## - Some requirements on character encoding declarations. ## TODO    0x0009 => 1, # CHARACTER TABULATION (HT)
974  ## - "Elements MUST NOT contain content that their content model disallows."    0x000A => 1, # LINE FEED (LF)
975  ##   ... Some are parse error, some are not (will be reported by c.c.).    #0x000B => 0, # LINE TABULATION (VT)
976  ## - Polytheistic slash SHOULD NOT be used. (Applied only to atheists.) ## TODO    0x000C => 1, # FORM FEED (FF)
977  ## - Text (in elements, attributes, and comments) SHOULD NOT contain    #0x000D => 1, # CARRIAGE RETURN (CR)
978  ##   control characters other than space characters. ## TODO: (what is control character? C0, C1 and DEL?  Unicode control character?)    0x0020 => 1, # SPACE (SP)
979    };
 ## TODO: HTML5 poses authors two SHOULD-level requirements that cannot  
 ## be detected by the HTML5 parsing algorithm:  
 ## - Text,  
980    
981  sub _get_next_token ($) {  sub _get_next_token ($) {
982    my $self = shift;    my $self = shift;
983    
984    if ($self->{self_closing}) {    if ($self->{self_closing}) {
985      !!!parse-error (type => 'nestc', token => $self->{current_token});      !!!parse-error (type => 'nestc', token => $self->{ct});
986      ## NOTE: The |self_closing| flag is only set by start tag token.      ## NOTE: The |self_closing| flag is only set by start tag token.
987      ## In addition, when a start tag token is emitted, it is always set to      ## In addition, when a start tag token is emitted, it is always set to
988      ## |current_token|.      ## |ct|.
989      delete $self->{self_closing};      delete $self->{self_closing};
990    }    }
991    
# Line 694  sub _get_next_token ($) { Line 995  sub _get_next_token ($) {
995    }    }
996    
997    A: {    A: {
998      if ($self->{state} == DATA_STATE) {      if ($self->{state} == PCDATA_STATE) {
999        if ($self->{next_char} == 0x0026) { # &        ## NOTE: Same as |DATA_STATE|, but only for |PCDATA| content model.
1000    
1001          if ($self->{nc} == 0x0026) { # &
1002            !!!cp (0.1);
1003            ## NOTE: In the spec, the tokenizer is switched to the
1004            ## "entity data state".  In this implementation, the tokenizer
1005            ## is switched to the |ENTITY_STATE|, which is an implementation
1006            ## of the "consume a character reference" algorithm.
1007            $self->{entity_add} = -1;
1008            $self->{prev_state} = DATA_STATE;
1009            $self->{state} = ENTITY_STATE;
1010            !!!next-input-character;
1011            redo A;
1012          } elsif ($self->{nc} == 0x003C) { # <
1013            !!!cp (0.2);
1014            $self->{state} = TAG_OPEN_STATE;
1015            !!!next-input-character;
1016            redo A;
1017          } elsif ($self->{nc} == -1) {
1018            !!!cp (0.3);
1019            !!!emit ({type => END_OF_FILE_TOKEN,
1020                      line => $self->{line}, column => $self->{column}});
1021            last A; ## TODO: ok?
1022          } else {
1023            !!!cp (0.4);
1024            #
1025          }
1026    
1027          # Anything else
1028          my $token = {type => CHARACTER_TOKEN,
1029                       data => chr $self->{nc},
1030                       line => $self->{line}, column => $self->{column},
1031                      };
1032          $self->{read_until}->($token->{data}, q[<&], length $token->{data});
1033    
1034          ## Stay in the state.
1035          !!!next-input-character;
1036          !!!emit ($token);
1037          redo A;
1038        } elsif ($self->{state} == DATA_STATE) {
1039          $self->{s_kwd} = '' unless defined $self->{s_kwd};
1040          if ($self->{nc} == 0x0026) { # &
1041            $self->{s_kwd} = '';
1042          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA
1043              not $self->{escape}) {              not $self->{escape}) {
1044            !!!cp (1);            !!!cp (1);
1045            $self->{state} = ENTITY_DATA_STATE;            ## NOTE: In the spec, the tokenizer is switched to the
1046              ## "entity data state".  In this implementation, the tokenizer
1047              ## is switched to the |ENTITY_STATE|, which is an implementation
1048              ## of the "consume a character reference" algorithm.
1049              $self->{entity_add} = -1;
1050              $self->{prev_state} = DATA_STATE;
1051              $self->{state} = ENTITY_STATE;
1052            !!!next-input-character;            !!!next-input-character;
1053            redo A;            redo A;
1054          } else {          } else {
1055            !!!cp (2);            !!!cp (2);
1056            #            #
1057          }          }
1058        } elsif ($self->{next_char} == 0x002D) { # -        } elsif ($self->{nc} == 0x002D) { # -
1059          if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA          if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1060            unless ($self->{escape}) {            $self->{s_kwd} .= '-';
1061              if ($self->{prev_char}->[0] == 0x002D and # -            
1062                  $self->{prev_char}->[1] == 0x0021 and # !            if ($self->{s_kwd} eq '<!--') {
1063                  $self->{prev_char}->[2] == 0x003C) { # <              !!!cp (3);
1064                !!!cp (3);              $self->{escape} = 1; # unless $self->{escape};
1065                $self->{escape} = 1;              $self->{s_kwd} = '--';
1066              } else {              #
1067                !!!cp (4);            } elsif ($self->{s_kwd} eq '---') {
1068              }              !!!cp (4);
1069                $self->{s_kwd} = '--';
1070                #
1071            } else {            } else {
1072              !!!cp (5);              !!!cp (5);
1073                #
1074            }            }
1075          }          }
1076                    
1077          #          #
1078        } elsif ($self->{next_char} == 0x003C) { # <        } elsif ($self->{nc} == 0x0021) { # !
1079            if (length $self->{s_kwd}) {
1080              !!!cp (5.1);
1081              $self->{s_kwd} .= '!';
1082              #
1083            } else {
1084              !!!cp (5.2);
1085              #$self->{s_kwd} = '';
1086              #
1087            }
1088            #
1089          } elsif ($self->{nc} == 0x003C) { # <
1090          if ($self->{content_model} & CM_FULL_MARKUP or # PCDATA          if ($self->{content_model} & CM_FULL_MARKUP or # PCDATA
1091              (($self->{content_model} & CM_LIMITED_MARKUP) and # CDATA | RCDATA              (($self->{content_model} & CM_LIMITED_MARKUP) and # CDATA | RCDATA
1092               not $self->{escape})) {               not $self->{escape})) {
# Line 733  sub _get_next_token ($) { Line 1096  sub _get_next_token ($) {
1096            redo A;            redo A;
1097          } else {          } else {
1098            !!!cp (7);            !!!cp (7);
1099              $self->{s_kwd} = '';
1100            #            #
1101          }          }
1102        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1103          if ($self->{escape} and          if ($self->{escape} and
1104              ($self->{content_model} & CM_LIMITED_MARKUP)) { # RCDATA | CDATA              ($self->{content_model} & CM_LIMITED_MARKUP)) { # RCDATA | CDATA
1105            if ($self->{prev_char}->[0] == 0x002D and # -            if ($self->{s_kwd} eq '--') {
               $self->{prev_char}->[1] == 0x002D) { # -  
1106              !!!cp (8);              !!!cp (8);
1107              delete $self->{escape};              delete $self->{escape};
1108            } else {            } else {
# Line 749  sub _get_next_token ($) { Line 1112  sub _get_next_token ($) {
1112            !!!cp (10);            !!!cp (10);
1113          }          }
1114                    
1115            $self->{s_kwd} = '';
1116          #          #
1117        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1118          !!!cp (11);          !!!cp (11);
1119            $self->{s_kwd} = '';
1120          !!!emit ({type => END_OF_FILE_TOKEN,          !!!emit ({type => END_OF_FILE_TOKEN,
1121                    line => $self->{line}, column => $self->{column}});                    line => $self->{line}, column => $self->{column}});
1122          last A; ## TODO: ok?          last A; ## TODO: ok?
1123        } else {        } else {
1124          !!!cp (12);          !!!cp (12);
1125            $self->{s_kwd} = '';
1126            #
1127        }        }
1128    
1129        # Anything else        # Anything else
1130        my $token = {type => CHARACTER_TOKEN,        my $token = {type => CHARACTER_TOKEN,
1131                     data => chr $self->{next_char},                     data => chr $self->{nc},
1132                     line => $self->{line}, column => $self->{column},                     line => $self->{line}, column => $self->{column},
1133                    };                    };
1134        ## Stay in the data state        if ($self->{read_until}->($token->{data}, q[-!<>&],
1135        !!!next-input-character;                                  length $token->{data})) {
1136            $self->{s_kwd} = '';
1137        !!!emit ($token);        }
   
       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  
1138    
1139        unless (defined $token) {        ## Stay in the data state.
1140          if ($self->{content_model} == PCDATA_CONTENT_MODEL) {
1141          !!!cp (13);          !!!cp (13);
1142          !!!emit ({type => CHARACTER_TOKEN, data => '&',          $self->{state} = PCDATA_STATE;
                   line => $l, column => $c,  
                  });  
1143        } else {        } else {
1144          !!!cp (14);          !!!cp (14);
1145          !!!emit ($token);          ## Stay in the state.
1146        }        }
1147          !!!next-input-character;
1148          !!!emit ($token);
1149        redo A;        redo A;
1150      } elsif ($self->{state} == TAG_OPEN_STATE) {      } elsif ($self->{state} == TAG_OPEN_STATE) {
1151        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1152          if ($self->{next_char} == 0x002F) { # /          if ($self->{nc} == 0x002F) { # /
1153            !!!cp (15);            !!!cp (15);
1154            !!!next-input-character;            !!!next-input-character;
1155            $self->{state} = CLOSE_TAG_OPEN_STATE;            $self->{state} = CLOSE_TAG_OPEN_STATE;
1156            redo A;            redo A;
1157            } elsif ($self->{nc} == 0x0021) { # !
1158              !!!cp (15.1);
1159              $self->{s_kwd} = '<' unless $self->{escape};
1160              #
1161          } else {          } else {
1162            !!!cp (16);            !!!cp (16);
1163            ## reconsume            #
           $self->{state} = DATA_STATE;  
   
           !!!emit ({type => CHARACTER_TOKEN, data => '<',  
                     line => $self->{line_prev},  
                     column => $self->{column_prev},  
                    });  
   
           redo A;  
1164          }          }
1165    
1166            ## reconsume
1167            $self->{state} = DATA_STATE;
1168            !!!emit ({type => CHARACTER_TOKEN, data => '<',
1169                      line => $self->{line_prev},
1170                      column => $self->{column_prev},
1171                     });
1172            redo A;
1173        } elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA        } elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA
1174          if ($self->{next_char} == 0x0021) { # !          if ($self->{nc} == 0x0021) { # !
1175            !!!cp (17);            !!!cp (17);
1176            $self->{state} = MARKUP_DECLARATION_OPEN_STATE;            $self->{state} = MARKUP_DECLARATION_OPEN_STATE;
1177            !!!next-input-character;            !!!next-input-character;
1178            redo A;            redo A;
1179          } elsif ($self->{next_char} == 0x002F) { # /          } elsif ($self->{nc} == 0x002F) { # /
1180            !!!cp (18);            !!!cp (18);
1181            $self->{state} = CLOSE_TAG_OPEN_STATE;            $self->{state} = CLOSE_TAG_OPEN_STATE;
1182            !!!next-input-character;            !!!next-input-character;
1183            redo A;            redo A;
1184          } elsif (0x0041 <= $self->{next_char} and          } elsif (0x0041 <= $self->{nc} and
1185                   $self->{next_char} <= 0x005A) { # A..Z                   $self->{nc} <= 0x005A) { # A..Z
1186            !!!cp (19);            !!!cp (19);
1187            $self->{current_token}            $self->{ct}
1188              = {type => START_TAG_TOKEN,              = {type => START_TAG_TOKEN,
1189                 tag_name => chr ($self->{next_char} + 0x0020),                 tag_name => chr ($self->{nc} + 0x0020),
1190                 line => $self->{line_prev},                 line => $self->{line_prev},
1191                 column => $self->{column_prev}};                 column => $self->{column_prev}};
1192            $self->{state} = TAG_NAME_STATE;            $self->{state} = TAG_NAME_STATE;
1193            !!!next-input-character;            !!!next-input-character;
1194            redo A;            redo A;
1195          } elsif (0x0061 <= $self->{next_char} and          } elsif (0x0061 <= $self->{nc} and
1196                   $self->{next_char} <= 0x007A) { # a..z                   $self->{nc} <= 0x007A) { # a..z
1197            !!!cp (20);            !!!cp (20);
1198            $self->{current_token} = {type => START_TAG_TOKEN,            $self->{ct} = {type => START_TAG_TOKEN,
1199                                      tag_name => chr ($self->{next_char}),                                      tag_name => chr ($self->{nc}),
1200                                      line => $self->{line_prev},                                      line => $self->{line_prev},
1201                                      column => $self->{column_prev}};                                      column => $self->{column_prev}};
1202            $self->{state} = TAG_NAME_STATE;            $self->{state} = TAG_NAME_STATE;
1203            !!!next-input-character;            !!!next-input-character;
1204            redo A;            redo A;
1205          } elsif ($self->{next_char} == 0x003E) { # >          } elsif ($self->{nc} == 0x003E) { # >
1206            !!!cp (21);            !!!cp (21);
1207            !!!parse-error (type => 'empty start tag',            !!!parse-error (type => 'empty start tag',
1208                            line => $self->{line_prev},                            line => $self->{line_prev},
# Line 855  sub _get_next_token ($) { Line 1216  sub _get_next_token ($) {
1216                     });                     });
1217    
1218            redo A;            redo A;
1219          } elsif ($self->{next_char} == 0x003F) { # ?          } elsif ($self->{nc} == 0x003F) { # ?
1220            !!!cp (22);            !!!cp (22);
1221            !!!parse-error (type => 'pio',            !!!parse-error (type => 'pio',
1222                            line => $self->{line_prev},                            line => $self->{line_prev},
1223                            column => $self->{column_prev});                            column => $self->{column_prev});
1224            $self->{state} = BOGUS_COMMENT_STATE;            $self->{state} = BOGUS_COMMENT_STATE;
1225            $self->{current_token} = {type => COMMENT_TOKEN, data => '',            $self->{ct} = {type => COMMENT_TOKEN, data => '',
1226                                      line => $self->{line_prev},                                      line => $self->{line_prev},
1227                                      column => $self->{column_prev},                                      column => $self->{column_prev},
1228                                     };                                     };
1229            ## $self->{next_char} is intentionally left as is            ## $self->{nc} is intentionally left as is
1230            redo A;            redo A;
1231          } else {          } else {
1232            !!!cp (23);            !!!cp (23);
1233            !!!parse-error (type => 'bare stago');            !!!parse-error (type => 'bare stago',
1234                              line => $self->{line_prev},
1235                              column => $self->{column_prev});
1236            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1237            ## reconsume            ## reconsume
1238    
# Line 884  sub _get_next_token ($) { Line 1247  sub _get_next_token ($) {
1247          die "$0: $self->{content_model} in tag open";          die "$0: $self->{content_model} in tag open";
1248        }        }
1249      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {
1250          ## NOTE: The "close tag open state" in the spec is implemented as
1251          ## |CLOSE_TAG_OPEN_STATE| and |CDATA_RCDATA_CLOSE_TAG_STATE|.
1252    
1253        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"
1254        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1255          if (defined $self->{last_emitted_start_tag_name}) {          if (defined $self->{last_stag_name}) {
1256              $self->{state} = CDATA_RCDATA_CLOSE_TAG_STATE;
1257            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>            $self->{s_kwd} = '';
1258            my @next_char;            ## Reconsume.
1259            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...  
           }  
1260          } else {          } else {
1261            ## No start tag token has ever been emitted            ## No start tag token has ever been emitted
1262              ## NOTE: See <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>.
1263            !!!cp (28);            !!!cp (28);
           # next-input-character is already done  
1264            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1265              ## Reconsume.
1266            !!!emit ({type => CHARACTER_TOKEN, data => '</',            !!!emit ({type => CHARACTER_TOKEN, data => '</',
1267                      line => $l, column => $c,                      line => $l, column => $c,
1268                     });                     });
1269            redo A;            redo A;
1270          }          }
1271        }        }
1272          
1273        if (0x0041 <= $self->{next_char} and        if (0x0041 <= $self->{nc} and
1274            $self->{next_char} <= 0x005A) { # A..Z            $self->{nc} <= 0x005A) { # A..Z
1275          !!!cp (29);          !!!cp (29);
1276          $self->{current_token}          $self->{ct}
1277              = {type => END_TAG_TOKEN,              = {type => END_TAG_TOKEN,
1278                 tag_name => chr ($self->{next_char} + 0x0020),                 tag_name => chr ($self->{nc} + 0x0020),
1279                 line => $l, column => $c};                 line => $l, column => $c};
1280          $self->{state} = TAG_NAME_STATE;          $self->{state} = TAG_NAME_STATE;
1281          !!!next-input-character;          !!!next-input-character;
1282          redo A;          redo A;
1283        } elsif (0x0061 <= $self->{next_char} and        } elsif (0x0061 <= $self->{nc} and
1284                 $self->{next_char} <= 0x007A) { # a..z                 $self->{nc} <= 0x007A) { # a..z
1285          !!!cp (30);          !!!cp (30);
1286          $self->{current_token} = {type => END_TAG_TOKEN,          $self->{ct} = {type => END_TAG_TOKEN,
1287                                    tag_name => chr ($self->{next_char}),                                    tag_name => chr ($self->{nc}),
1288                                    line => $l, column => $c};                                    line => $l, column => $c};
1289          $self->{state} = TAG_NAME_STATE;          $self->{state} = TAG_NAME_STATE;
1290          !!!next-input-character;          !!!next-input-character;
1291          redo A;          redo A;
1292        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1293          !!!cp (31);          !!!cp (31);
1294          !!!parse-error (type => 'empty end tag',          !!!parse-error (type => 'empty end tag',
1295                          line => $self->{line_prev}, ## "<" in "</>"                          line => $self->{line_prev}, ## "<" in "</>"
# Line 974  sub _get_next_token ($) { Line 1297  sub _get_next_token ($) {
1297          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1298          !!!next-input-character;          !!!next-input-character;
1299          redo A;          redo A;
1300        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1301          !!!cp (32);          !!!cp (32);
1302          !!!parse-error (type => 'bare etago');          !!!parse-error (type => 'bare etago');
1303          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
# Line 989  sub _get_next_token ($) { Line 1312  sub _get_next_token ($) {
1312          !!!cp (33);          !!!cp (33);
1313          !!!parse-error (type => 'bogus end tag');          !!!parse-error (type => 'bogus end tag');
1314          $self->{state} = BOGUS_COMMENT_STATE;          $self->{state} = BOGUS_COMMENT_STATE;
1315          $self->{current_token} = {type => COMMENT_TOKEN, data => '',          $self->{ct} = {type => COMMENT_TOKEN, data => '',
1316                                    line => $self->{line_prev}, # "<" of "</"                                    line => $self->{line_prev}, # "<" of "</"
1317                                    column => $self->{column_prev} - 1,                                    column => $self->{column_prev} - 1,
1318                                   };                                   };
1319          ## $self->{next_char} is intentionally left as is          ## NOTE: $self->{nc} is intentionally left as is.
1320          redo A;          ## Although the "anything else" case of the spec not explicitly
1321            ## states that the next input character is to be reconsumed,
1322            ## it will be included to the |data| of the comment token
1323            ## generated from the bogus end tag, as defined in the
1324            ## "bogus comment state" entry.
1325            redo A;
1326          }
1327        } elsif ($self->{state} == CDATA_RCDATA_CLOSE_TAG_STATE) {
1328          my $ch = substr $self->{last_stag_name}, length $self->{s_kwd}, 1;
1329          if (length $ch) {
1330            my $CH = $ch;
1331            $ch =~ tr/a-z/A-Z/;
1332            my $nch = chr $self->{nc};
1333            if ($nch eq $ch or $nch eq $CH) {
1334              !!!cp (24);
1335              ## Stay in the state.
1336              $self->{s_kwd} .= $nch;
1337              !!!next-input-character;
1338              redo A;
1339            } else {
1340              !!!cp (25);
1341              $self->{state} = DATA_STATE;
1342              ## Reconsume.
1343              !!!emit ({type => CHARACTER_TOKEN,
1344                        data => '</' . $self->{s_kwd},
1345                        line => $self->{line_prev},
1346                        column => $self->{column_prev} - 1 - length $self->{s_kwd},
1347                       });
1348              redo A;
1349            }
1350          } else { # after "<{tag-name}"
1351            unless ($is_space->{$self->{nc}} or
1352                    {
1353                     0x003E => 1, # >
1354                     0x002F => 1, # /
1355                     -1 => 1, # EOF
1356                    }->{$self->{nc}}) {
1357              !!!cp (26);
1358              ## Reconsume.
1359              $self->{state} = DATA_STATE;
1360              !!!emit ({type => CHARACTER_TOKEN,
1361                        data => '</' . $self->{s_kwd},
1362                        line => $self->{line_prev},
1363                        column => $self->{column_prev} - 1 - length $self->{s_kwd},
1364                       });
1365              redo A;
1366            } else {
1367              !!!cp (27);
1368              $self->{ct}
1369                  = {type => END_TAG_TOKEN,
1370                     tag_name => $self->{last_stag_name},
1371                     line => $self->{line_prev},
1372                     column => $self->{column_prev} - 1 - length $self->{s_kwd}};
1373              $self->{state} = TAG_NAME_STATE;
1374              ## Reconsume.
1375              redo A;
1376            }
1377        }        }
1378      } elsif ($self->{state} == TAG_NAME_STATE) {      } elsif ($self->{state} == TAG_NAME_STATE) {
1379        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # VT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP  
1380          !!!cp (34);          !!!cp (34);
1381          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1382          !!!next-input-character;          !!!next-input-character;
1383          redo A;          redo A;
1384        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1385          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1386            !!!cp (35);            !!!cp (35);
1387            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1388          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1389            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1390            #if ($self->{current_token}->{attributes}) {            #if ($self->{ct}->{attributes}) {
1391            #  ## NOTE: This should never be reached.            #  ## NOTE: This should never be reached.
1392            #  !!! cp (36);            #  !!! cp (36);
1393            #  !!! parse-error (type => 'end tag attribute');            #  !!! parse-error (type => 'end tag attribute');
# Line 1020  sub _get_next_token ($) { Line 1395  sub _get_next_token ($) {
1395              !!!cp (37);              !!!cp (37);
1396            #}            #}
1397          } else {          } else {
1398            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1399          }          }
1400          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1401          !!!next-input-character;          !!!next-input-character;
1402    
1403          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1404    
1405          redo A;          redo A;
1406        } elsif (0x0041 <= $self->{next_char} and        } elsif (0x0041 <= $self->{nc} and
1407                 $self->{next_char} <= 0x005A) { # A..Z                 $self->{nc} <= 0x005A) { # A..Z
1408          !!!cp (38);          !!!cp (38);
1409          $self->{current_token}->{tag_name} .= chr ($self->{next_char} + 0x0020);          $self->{ct}->{tag_name} .= chr ($self->{nc} + 0x0020);
1410            # start tag or end tag            # start tag or end tag
1411          ## Stay in this state          ## Stay in this state
1412          !!!next-input-character;          !!!next-input-character;
1413          redo A;          redo A;
1414        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1415          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1416          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1417            !!!cp (39);            !!!cp (39);
1418            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1419          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1420            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1421            #if ($self->{current_token}->{attributes}) {            #if ($self->{ct}->{attributes}) {
1422            #  ## NOTE: This state should never be reached.            #  ## NOTE: This state should never be reached.
1423            #  !!! cp (40);            #  !!! cp (40);
1424            #  !!! parse-error (type => 'end tag attribute');            #  !!! parse-error (type => 'end tag attribute');
# Line 1051  sub _get_next_token ($) { Line 1426  sub _get_next_token ($) {
1426              !!!cp (41);              !!!cp (41);
1427            #}            #}
1428          } else {          } else {
1429            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1430          }          }
1431          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1432          # reconsume          # reconsume
1433    
1434          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1435    
1436          redo A;          redo A;
1437        } elsif ($self->{next_char} == 0x002F) { # /        } elsif ($self->{nc} == 0x002F) { # /
1438          !!!cp (42);          !!!cp (42);
1439          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1440          !!!next-input-character;          !!!next-input-character;
1441          redo A;          redo A;
1442        } else {        } else {
1443          !!!cp (44);          !!!cp (44);
1444          $self->{current_token}->{tag_name} .= chr $self->{next_char};          $self->{ct}->{tag_name} .= chr $self->{nc};
1445            # start tag or end tag            # start tag or end tag
1446          ## Stay in the state          ## Stay in the state
1447          !!!next-input-character;          !!!next-input-character;
1448          redo A;          redo A;
1449        }        }
1450      } elsif ($self->{state} == BEFORE_ATTRIBUTE_NAME_STATE) {      } elsif ($self->{state} == BEFORE_ATTRIBUTE_NAME_STATE) {
1451        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # VT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP  
1452          !!!cp (45);          !!!cp (45);
1453          ## Stay in the state          ## Stay in the state
1454          !!!next-input-character;          !!!next-input-character;
1455          redo A;          redo A;
1456        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1457          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1458            !!!cp (46);            !!!cp (46);
1459            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1460          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1461            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1462            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1463              !!!cp (47);              !!!cp (47);
1464              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1465            } else {            } else {
1466              !!!cp (48);              !!!cp (48);
1467            }            }
1468          } else {          } else {
1469            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1470          }          }
1471          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1472          !!!next-input-character;          !!!next-input-character;
1473    
1474          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1475    
1476          redo A;          redo A;
1477        } elsif (0x0041 <= $self->{next_char} and        } elsif (0x0041 <= $self->{nc} and
1478                 $self->{next_char} <= 0x005A) { # A..Z                 $self->{nc} <= 0x005A) { # A..Z
1479          !!!cp (49);          !!!cp (49);
1480          $self->{current_attribute}          $self->{ca}
1481              = {name => chr ($self->{next_char} + 0x0020),              = {name => chr ($self->{nc} + 0x0020),
1482                 value => '',                 value => '',
1483                 line => $self->{line}, column => $self->{column}};                 line => $self->{line}, column => $self->{column}};
1484          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
1485          !!!next-input-character;          !!!next-input-character;
1486          redo A;          redo A;
1487        } elsif ($self->{next_char} == 0x002F) { # /        } elsif ($self->{nc} == 0x002F) { # /
1488          !!!cp (50);          !!!cp (50);
1489          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1490          !!!next-input-character;          !!!next-input-character;
1491          redo A;          redo A;
1492        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1493          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1494          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1495            !!!cp (52);            !!!cp (52);
1496            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1497          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1498            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1499            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1500              !!!cp (53);              !!!cp (53);
1501              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1502            } else {            } else {
1503              !!!cp (54);              !!!cp (54);
1504            }            }
1505          } else {          } else {
1506            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1507          }          }
1508          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1509          # reconsume          # reconsume
1510    
1511          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1512    
1513          redo A;          redo A;
1514        } else {        } else {
# Line 1145  sub _get_next_token ($) { Line 1516  sub _get_next_token ($) {
1516               0x0022 => 1, # "               0x0022 => 1, # "
1517               0x0027 => 1, # '               0x0027 => 1, # '
1518               0x003D => 1, # =               0x003D => 1, # =
1519              }->{$self->{next_char}}) {              }->{$self->{nc}}) {
1520            !!!cp (55);            !!!cp (55);
1521            !!!parse-error (type => 'bad attribute name');            !!!parse-error (type => 'bad attribute name');
1522          } else {          } else {
1523            !!!cp (56);            !!!cp (56);
1524          }          }
1525          $self->{current_attribute}          $self->{ca}
1526              = {name => chr ($self->{next_char}),              = {name => chr ($self->{nc}),
1527                 value => '',                 value => '',
1528                 line => $self->{line}, column => $self->{column}};                 line => $self->{line}, column => $self->{column}};
1529          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
# Line 1161  sub _get_next_token ($) { Line 1532  sub _get_next_token ($) {
1532        }        }
1533      } elsif ($self->{state} == ATTRIBUTE_NAME_STATE) {      } elsif ($self->{state} == ATTRIBUTE_NAME_STATE) {
1534        my $before_leave = sub {        my $before_leave = sub {
1535          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{ct}->{attributes} # start tag or end tag
1536              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{ca}->{name}}) { # MUST
1537            !!!cp (57);            !!!cp (57);
1538            !!!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->{ca}->{name}, line => $self->{ca}->{line}, column => $self->{ca}->{column});
1539            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{ca} # MUST
1540          } else {          } else {
1541            !!!cp (58);            !!!cp (58);
1542            $self->{current_token}->{attributes}->{$self->{current_attribute}->{name}}            $self->{ct}->{attributes}->{$self->{ca}->{name}}
1543              = $self->{current_attribute};              = $self->{ca};
1544          }          }
1545        }; # $before_leave        }; # $before_leave
1546    
1547        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # VT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP  
1548          !!!cp (59);          !!!cp (59);
1549          $before_leave->();          $before_leave->();
1550          $self->{state} = AFTER_ATTRIBUTE_NAME_STATE;          $self->{state} = AFTER_ATTRIBUTE_NAME_STATE;
1551          !!!next-input-character;          !!!next-input-character;
1552          redo A;          redo A;
1553        } elsif ($self->{next_char} == 0x003D) { # =        } elsif ($self->{nc} == 0x003D) { # =
1554          !!!cp (60);          !!!cp (60);
1555          $before_leave->();          $before_leave->();
1556          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;
1557          !!!next-input-character;          !!!next-input-character;
1558          redo A;          redo A;
1559        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1560          $before_leave->();          $before_leave->();
1561          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1562            !!!cp (61);            !!!cp (61);
1563            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1564          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1565            !!!cp (62);            !!!cp (62);
1566            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1567            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1568              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1569            }            }
1570          } else {          } else {
1571            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1572          }          }
1573          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1574          !!!next-input-character;          !!!next-input-character;
1575    
1576          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1577    
1578          redo A;          redo A;
1579        } elsif (0x0041 <= $self->{next_char} and        } elsif (0x0041 <= $self->{nc} and
1580                 $self->{next_char} <= 0x005A) { # A..Z                 $self->{nc} <= 0x005A) { # A..Z
1581          !!!cp (63);          !!!cp (63);
1582          $self->{current_attribute}->{name} .= chr ($self->{next_char} + 0x0020);          $self->{ca}->{name} .= chr ($self->{nc} + 0x0020);
1583          ## Stay in the state          ## Stay in the state
1584          !!!next-input-character;          !!!next-input-character;
1585          redo A;          redo A;
1586        } elsif ($self->{next_char} == 0x002F) { # /        } elsif ($self->{nc} == 0x002F) { # /
1587          !!!cp (64);          !!!cp (64);
1588          $before_leave->();          $before_leave->();
1589          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1590          !!!next-input-character;          !!!next-input-character;
1591          redo A;          redo A;
1592        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1593          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1594          $before_leave->();          $before_leave->();
1595          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1596            !!!cp (66);            !!!cp (66);
1597            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1598          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1599            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1600            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1601              !!!cp (67);              !!!cp (67);
1602              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1603            } else {            } else {
# Line 1238  sub _get_next_token ($) { Line 1605  sub _get_next_token ($) {
1605              !!!cp (68);              !!!cp (68);
1606            }            }
1607          } else {          } else {
1608            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1609          }          }
1610          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1611          # reconsume          # reconsume
1612    
1613          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1614    
1615          redo A;          redo A;
1616        } else {        } else {
1617          if ($self->{next_char} == 0x0022 or # "          if ($self->{nc} == 0x0022 or # "
1618              $self->{next_char} == 0x0027) { # '              $self->{nc} == 0x0027) { # '
1619            !!!cp (69);            !!!cp (69);
1620            !!!parse-error (type => 'bad attribute name');            !!!parse-error (type => 'bad attribute name');
1621          } else {          } else {
1622            !!!cp (70);            !!!cp (70);
1623          }          }
1624          $self->{current_attribute}->{name} .= chr ($self->{next_char});          $self->{ca}->{name} .= chr ($self->{nc});
1625          ## Stay in the state          ## Stay in the state
1626          !!!next-input-character;          !!!next-input-character;
1627          redo A;          redo A;
1628        }        }
1629      } elsif ($self->{state} == AFTER_ATTRIBUTE_NAME_STATE) {      } elsif ($self->{state} == AFTER_ATTRIBUTE_NAME_STATE) {
1630        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # VT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP  
1631          !!!cp (71);          !!!cp (71);
1632          ## Stay in the state          ## Stay in the state
1633          !!!next-input-character;          !!!next-input-character;
1634          redo A;          redo A;
1635        } elsif ($self->{next_char} == 0x003D) { # =        } elsif ($self->{nc} == 0x003D) { # =
1636          !!!cp (72);          !!!cp (72);
1637          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;
1638          !!!next-input-character;          !!!next-input-character;
1639          redo A;          redo A;
1640        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1641          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1642            !!!cp (73);            !!!cp (73);
1643            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1644          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1645            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1646            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1647              !!!cp (74);              !!!cp (74);
1648              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1649            } else {            } else {
# Line 1288  sub _get_next_token ($) { Line 1651  sub _get_next_token ($) {
1651              !!!cp (75);              !!!cp (75);
1652            }            }
1653          } else {          } else {
1654            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1655          }          }
1656          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1657          !!!next-input-character;          !!!next-input-character;
1658    
1659          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1660    
1661          redo A;          redo A;
1662        } elsif (0x0041 <= $self->{next_char} and        } elsif (0x0041 <= $self->{nc} and
1663                 $self->{next_char} <= 0x005A) { # A..Z                 $self->{nc} <= 0x005A) { # A..Z
1664          !!!cp (76);          !!!cp (76);
1665          $self->{current_attribute}          $self->{ca}
1666              = {name => chr ($self->{next_char} + 0x0020),              = {name => chr ($self->{nc} + 0x0020),
1667                 value => '',                 value => '',
1668                 line => $self->{line}, column => $self->{column}};                 line => $self->{line}, column => $self->{column}};
1669          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
1670          !!!next-input-character;          !!!next-input-character;
1671          redo A;          redo A;
1672        } elsif ($self->{next_char} == 0x002F) { # /        } elsif ($self->{nc} == 0x002F) { # /
1673          !!!cp (77);          !!!cp (77);
1674          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1675          !!!next-input-character;          !!!next-input-character;
1676          redo A;          redo A;
1677        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1678          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1679          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1680            !!!cp (79);            !!!cp (79);
1681            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1682          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1683            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1684            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1685              !!!cp (80);              !!!cp (80);
1686              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1687            } else {            } else {
# Line 1326  sub _get_next_token ($) { Line 1689  sub _get_next_token ($) {
1689              !!!cp (81);              !!!cp (81);
1690            }            }
1691          } else {          } else {
1692            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1693          }          }
1694          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1695          # reconsume          # reconsume
1696    
1697          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1698    
1699          redo A;          redo A;
1700        } else {        } else {
1701          !!!cp (82);          if ($self->{nc} == 0x0022 or # "
1702          $self->{current_attribute}              $self->{nc} == 0x0027) { # '
1703              = {name => chr ($self->{next_char}),            !!!cp (78);
1704              !!!parse-error (type => 'bad attribute name');
1705            } else {
1706              !!!cp (82);
1707            }
1708            $self->{ca}
1709                = {name => chr ($self->{nc}),
1710                 value => '',                 value => '',
1711                 line => $self->{line}, column => $self->{column}};                 line => $self->{line}, column => $self->{column}};
1712          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
# Line 1345  sub _get_next_token ($) { Line 1714  sub _get_next_token ($) {
1714          redo A;                  redo A;        
1715        }        }
1716      } elsif ($self->{state} == BEFORE_ATTRIBUTE_VALUE_STATE) {      } elsif ($self->{state} == BEFORE_ATTRIBUTE_VALUE_STATE) {
1717        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # VT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP        
1718          !!!cp (83);          !!!cp (83);
1719          ## Stay in the state          ## Stay in the state
1720          !!!next-input-character;          !!!next-input-character;
1721          redo A;          redo A;
1722        } elsif ($self->{next_char} == 0x0022) { # "        } elsif ($self->{nc} == 0x0022) { # "
1723          !!!cp (84);          !!!cp (84);
1724          $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;          $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
1725          !!!next-input-character;          !!!next-input-character;
1726          redo A;          redo A;
1727        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{nc} == 0x0026) { # &
1728          !!!cp (85);          !!!cp (85);
1729          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
1730          ## reconsume          ## reconsume
1731          redo A;          redo A;
1732        } elsif ($self->{next_char} == 0x0027) { # '        } elsif ($self->{nc} == 0x0027) { # '
1733          !!!cp (86);          !!!cp (86);
1734          $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;          $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
1735          !!!next-input-character;          !!!next-input-character;
1736          redo A;          redo A;
1737        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1738          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          !!!parse-error (type => 'empty unquoted attribute value');
1739            if ($self->{ct}->{type} == START_TAG_TOKEN) {
1740            !!!cp (87);            !!!cp (87);
1741            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1742          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1743            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1744            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1745              !!!cp (88);              !!!cp (88);
1746              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1747            } else {            } else {
# Line 1383  sub _get_next_token ($) { Line 1749  sub _get_next_token ($) {
1749              !!!cp (89);              !!!cp (89);
1750            }            }
1751          } else {          } else {
1752            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1753          }          }
1754          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1755          !!!next-input-character;          !!!next-input-character;
1756    
1757          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1758    
1759          redo A;          redo A;
1760        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1761          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1762          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1763            !!!cp (90);            !!!cp (90);
1764            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1765          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1766            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1767            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1768              !!!cp (91);              !!!cp (91);
1769              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1770            } else {            } else {
# Line 1406  sub _get_next_token ($) { Line 1772  sub _get_next_token ($) {
1772              !!!cp (92);              !!!cp (92);
1773            }            }
1774          } else {          } else {
1775            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1776          }          }
1777          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1778          ## reconsume          ## reconsume
1779    
1780          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1781    
1782          redo A;          redo A;
1783        } else {        } else {
1784          if ($self->{next_char} == 0x003D) { # =          if ($self->{nc} == 0x003D) { # =
1785            !!!cp (93);            !!!cp (93);
1786            !!!parse-error (type => 'bad attribute value');            !!!parse-error (type => 'bad attribute value');
1787          } else {          } else {
1788            !!!cp (94);            !!!cp (94);
1789          }          }
1790          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{ca}->{value} .= chr ($self->{nc});
1791          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
1792          !!!next-input-character;          !!!next-input-character;
1793          redo A;          redo A;
1794        }        }
1795      } elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) {
1796        if ($self->{next_char} == 0x0022) { # "        if ($self->{nc} == 0x0022) { # "
1797          !!!cp (95);          !!!cp (95);
1798          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;
1799          !!!next-input-character;          !!!next-input-character;
1800          redo A;          redo A;
1801        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{nc} == 0x0026) { # &
1802          !!!cp (96);          !!!cp (96);
1803          $self->{last_attribute_value_state} = $self->{state};          ## NOTE: In the spec, the tokenizer is switched to the
1804          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## "entity in attribute value state".  In this implementation, the
1805            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1806            ## implementation of the "consume a character reference" algorithm.
1807            $self->{prev_state} = $self->{state};
1808            $self->{entity_add} = 0x0022; # "
1809            $self->{state} = ENTITY_STATE;
1810          !!!next-input-character;          !!!next-input-character;
1811          redo A;          redo A;
1812        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1813          !!!parse-error (type => 'unclosed attribute value');          !!!parse-error (type => 'unclosed attribute value');
1814          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1815            !!!cp (97);            !!!cp (97);
1816            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1817          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1818            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1819            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1820              !!!cp (98);              !!!cp (98);
1821              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1822            } else {            } else {
# Line 1453  sub _get_next_token ($) { Line 1824  sub _get_next_token ($) {
1824              !!!cp (99);              !!!cp (99);
1825            }            }
1826          } else {          } else {
1827            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1828          }          }
1829          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1830          ## reconsume          ## reconsume
1831    
1832          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1833    
1834          redo A;          redo A;
1835        } else {        } else {
1836          !!!cp (100);          !!!cp (100);
1837          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{ca}->{value} .= chr ($self->{nc});
1838            $self->{read_until}->($self->{ca}->{value},
1839                                  q["&],
1840                                  length $self->{ca}->{value});
1841    
1842          ## Stay in the state          ## Stay in the state
1843          !!!next-input-character;          !!!next-input-character;
1844          redo A;          redo A;
1845        }        }
1846      } elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) {
1847        if ($self->{next_char} == 0x0027) { # '        if ($self->{nc} == 0x0027) { # '
1848          !!!cp (101);          !!!cp (101);
1849          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;
1850          !!!next-input-character;          !!!next-input-character;
1851          redo A;          redo A;
1852        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{nc} == 0x0026) { # &
1853          !!!cp (102);          !!!cp (102);
1854          $self->{last_attribute_value_state} = $self->{state};          ## NOTE: In the spec, the tokenizer is switched to the
1855          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## "entity in attribute value state".  In this implementation, the
1856            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1857            ## implementation of the "consume a character reference" algorithm.
1858            $self->{entity_add} = 0x0027; # '
1859            $self->{prev_state} = $self->{state};
1860            $self->{state} = ENTITY_STATE;
1861          !!!next-input-character;          !!!next-input-character;
1862          redo A;          redo A;
1863        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1864          !!!parse-error (type => 'unclosed attribute value');          !!!parse-error (type => 'unclosed attribute value');
1865          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1866            !!!cp (103);            !!!cp (103);
1867            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1868          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1869            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1870            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1871              !!!cp (104);              !!!cp (104);
1872              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1873            } else {            } else {
# Line 1495  sub _get_next_token ($) { Line 1875  sub _get_next_token ($) {
1875              !!!cp (105);              !!!cp (105);
1876            }            }
1877          } else {          } else {
1878            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1879          }          }
1880          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1881          ## reconsume          ## reconsume
1882    
1883          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1884    
1885          redo A;          redo A;
1886        } else {        } else {
1887          !!!cp (106);          !!!cp (106);
1888          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{ca}->{value} .= chr ($self->{nc});
1889            $self->{read_until}->($self->{ca}->{value},
1890                                  q['&],
1891                                  length $self->{ca}->{value});
1892    
1893          ## Stay in the state          ## Stay in the state
1894          !!!next-input-character;          !!!next-input-character;
1895          redo A;          redo A;
1896        }        }
1897      } elsif ($self->{state} == ATTRIBUTE_VALUE_UNQUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_UNQUOTED_STATE) {
1898        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # HT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP  
1899          !!!cp (107);          !!!cp (107);
1900          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1901          !!!next-input-character;          !!!next-input-character;
1902          redo A;          redo A;
1903        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{nc} == 0x0026) { # &
1904          !!!cp (108);          !!!cp (108);
1905          $self->{last_attribute_value_state} = $self->{state};          ## NOTE: In the spec, the tokenizer is switched to the
1906          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## "entity in attribute value state".  In this implementation, the
1907            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1908            ## implementation of the "consume a character reference" algorithm.
1909            $self->{entity_add} = -1;
1910            $self->{prev_state} = $self->{state};
1911            $self->{state} = ENTITY_STATE;
1912          !!!next-input-character;          !!!next-input-character;
1913          redo A;          redo A;
1914        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1915          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1916            !!!cp (109);            !!!cp (109);
1917            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1918          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1919            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1920            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1921              !!!cp (110);              !!!cp (110);
1922              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1923            } else {            } else {
# Line 1540  sub _get_next_token ($) { Line 1925  sub _get_next_token ($) {
1925              !!!cp (111);              !!!cp (111);
1926            }            }
1927          } else {          } else {
1928            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1929          }          }
1930          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1931          !!!next-input-character;          !!!next-input-character;
1932    
1933          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1934    
1935          redo A;          redo A;
1936        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1937          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1938          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1939            !!!cp (112);            !!!cp (112);
1940            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1941          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1942            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1943            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1944              !!!cp (113);              !!!cp (113);
1945              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1946            } else {            } else {
# Line 1563  sub _get_next_token ($) { Line 1948  sub _get_next_token ($) {
1948              !!!cp (114);              !!!cp (114);
1949            }            }
1950          } else {          } else {
1951            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1952          }          }
1953          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1954          ## reconsume          ## reconsume
1955    
1956          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1957    
1958          redo A;          redo A;
1959        } else {        } else {
# Line 1576  sub _get_next_token ($) { Line 1961  sub _get_next_token ($) {
1961               0x0022 => 1, # "               0x0022 => 1, # "
1962               0x0027 => 1, # '               0x0027 => 1, # '
1963               0x003D => 1, # =               0x003D => 1, # =
1964              }->{$self->{next_char}}) {              }->{$self->{nc}}) {
1965            !!!cp (115);            !!!cp (115);
1966            !!!parse-error (type => 'bad attribute value');            !!!parse-error (type => 'bad attribute value');
1967          } else {          } else {
1968            !!!cp (116);            !!!cp (116);
1969          }          }
1970          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{ca}->{value} .= chr ($self->{nc});
1971            $self->{read_until}->($self->{ca}->{value},
1972                                  q["'=& >],
1973                                  length $self->{ca}->{value});
1974    
1975          ## Stay in the state          ## Stay in the state
1976          !!!next-input-character;          !!!next-input-character;
1977          redo A;          redo A;
1978        }        }
     } 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;  
1979      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {
1980        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # VT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP  
1981          !!!cp (118);          !!!cp (118);
1982          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1983          !!!next-input-character;          !!!next-input-character;
1984          redo A;          redo A;
1985        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1986          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1987            !!!cp (119);            !!!cp (119);
1988            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1989          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1990            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1991            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1992              !!!cp (120);              !!!cp (120);
1993              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1994            } else {            } else {
# Line 1633  sub _get_next_token ($) { Line 1996  sub _get_next_token ($) {
1996              !!!cp (121);              !!!cp (121);
1997            }            }
1998          } else {          } else {
1999            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
2000          }          }
2001          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2002          !!!next-input-character;          !!!next-input-character;
2003    
2004          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
2005    
2006          redo A;          redo A;
2007        } elsif ($self->{next_char} == 0x002F) { # /        } elsif ($self->{nc} == 0x002F) { # /
2008          !!!cp (122);          !!!cp (122);
2009          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
2010          !!!next-input-character;          !!!next-input-character;
2011          redo A;          redo A;
2012          } elsif ($self->{nc} == -1) {
2013            !!!parse-error (type => 'unclosed tag');
2014            if ($self->{ct}->{type} == START_TAG_TOKEN) {
2015              !!!cp (122.3);
2016              $self->{last_stag_name} = $self->{ct}->{tag_name};
2017            } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
2018              if ($self->{ct}->{attributes}) {
2019                !!!cp (122.1);
2020                !!!parse-error (type => 'end tag attribute');
2021              } else {
2022                ## NOTE: This state should never be reached.
2023                !!!cp (122.2);
2024              }
2025            } else {
2026              die "$0: $self->{ct}->{type}: Unknown token type";
2027            }
2028            $self->{state} = DATA_STATE;
2029            ## Reconsume.
2030            !!!emit ($self->{ct}); # start tag or end tag
2031            redo A;
2032        } else {        } else {
2033          !!!cp ('124.1');          !!!cp ('124.1');
2034          !!!parse-error (type => 'no space between attributes');          !!!parse-error (type => 'no space between attributes');
# Line 1654  sub _get_next_token ($) { Line 2037  sub _get_next_token ($) {
2037          redo A;          redo A;
2038        }        }
2039      } elsif ($self->{state} == SELF_CLOSING_START_TAG_STATE) {      } elsif ($self->{state} == SELF_CLOSING_START_TAG_STATE) {
2040        if ($self->{next_char} == 0x003E) { # >        if ($self->{nc} == 0x003E) { # >
2041          if ($self->{current_token}->{type} == END_TAG_TOKEN) {          if ($self->{ct}->{type} == END_TAG_TOKEN) {
2042            !!!cp ('124.2');            !!!cp ('124.2');
2043            !!!parse-error (type => 'nestc', token => $self->{current_token});            !!!parse-error (type => 'nestc', token => $self->{ct});
2044            ## TODO: Different type than slash in start tag            ## TODO: Different type than slash in start tag
2045            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
2046            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
2047              !!!cp ('124.4');              !!!cp ('124.4');
2048              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
2049            } else {            } else {
# Line 1675  sub _get_next_token ($) { Line 2058  sub _get_next_token ($) {
2058          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2059          !!!next-input-character;          !!!next-input-character;
2060    
2061          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
2062    
2063          redo A;          redo A;
2064          } elsif ($self->{nc} == -1) {
2065            !!!parse-error (type => 'unclosed tag');
2066            if ($self->{ct}->{type} == START_TAG_TOKEN) {
2067              !!!cp (124.7);
2068              $self->{last_stag_name} = $self->{ct}->{tag_name};
2069            } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
2070              if ($self->{ct}->{attributes}) {
2071                !!!cp (124.5);
2072                !!!parse-error (type => 'end tag attribute');
2073              } else {
2074                ## NOTE: This state should never be reached.
2075                !!!cp (124.6);
2076              }
2077            } else {
2078              die "$0: $self->{ct}->{type}: Unknown token type";
2079            }
2080            $self->{state} = DATA_STATE;
2081            ## Reconsume.
2082            !!!emit ($self->{ct}); # start tag or end tag
2083            redo A;
2084        } else {        } else {
2085          !!!cp ('124.4');          !!!cp ('124.4');
2086          !!!parse-error (type => 'nestc');          !!!parse-error (type => 'nestc');
# Line 1688  sub _get_next_token ($) { Line 2091  sub _get_next_token ($) {
2091        }        }
2092      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {
2093        ## (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;  
2094    
2095            !!!emit ($self->{current_token}); # comment        ## NOTE: Unlike spec's "bogus comment state", this implementation
2096          ## consumes characters one-by-one basis.
2097            redo A;        
2098          } elsif ($self->{next_char} == -1) {        if ($self->{nc} == 0x003E) { # >
2099            !!!cp (125);          !!!cp (124);
2100            $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2101            ## reconsume          !!!next-input-character;
2102    
2103            !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2104            redo A;
2105          } elsif ($self->{nc} == -1) {
2106            !!!cp (125);
2107            $self->{state} = DATA_STATE;
2108            ## reconsume
2109    
2110            redo A;          !!!emit ($self->{ct}); # comment
2111          } else {          redo A;
2112            !!!cp (126);        } else {
2113            $self->{current_token}->{data} .= chr ($self->{next_char}); # comment          !!!cp (126);
2114            !!!next-input-character;          $self->{ct}->{data} .= chr ($self->{nc}); # comment
2115            redo BC;          $self->{read_until}->($self->{ct}->{data},
2116          }                                q[>],
2117        } # BC                                length $self->{ct}->{data});
2118    
2119        die "$0: _get_next_token: unexpected case [BC]";          ## Stay in the state.
2120            !!!next-input-character;
2121            redo A;
2122          }
2123      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {
2124        ## (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};  
2125                
2126        if ($self->{next_char} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
2127            !!!cp (133);
2128            $self->{state} = MD_HYPHEN_STATE;
2129          !!!next-input-character;          !!!next-input-character;
2130          push @next_char, $self->{next_char};          redo A;
2131          if ($self->{next_char} == 0x002D) { # -        } elsif ($self->{nc} == 0x0044 or # D
2132            !!!cp (127);                 $self->{nc} == 0x0064) { # d
2133            $self->{current_token} = {type => COMMENT_TOKEN, data => '',          ## ASCII case-insensitive.
2134                                      line => $l, column => $c,          !!!cp (130);
2135                                     };          $self->{state} = MD_DOCTYPE_STATE;
2136            $self->{state} = COMMENT_START_STATE;          $self->{s_kwd} = chr $self->{nc};
           !!!next-input-character;  
           redo A;  
         } else {  
           !!!cp (128);  
         }  
       } elsif ($self->{next_char} == 0x0044 or # D  
                $self->{next_char} == 0x0064) { # d  
2137          !!!next-input-character;          !!!next-input-character;
2138          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);  
         }  
2139        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and
2140                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and
2141                 $self->{next_char} == 0x005B) { # [                 $self->{nc} == 0x005B) { # [
2142            !!!cp (135.4);                
2143            $self->{state} = MD_CDATA_STATE;
2144            $self->{s_kwd} = '[';
2145          !!!next-input-character;          !!!next-input-character;
2146          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);  
         }  
2147        } else {        } else {
2148          !!!cp (136);          !!!cp (136);
2149        }        }
2150    
2151        !!!parse-error (type => 'bogus comment');        !!!parse-error (type => 'bogus comment',
2152        $self->{next_char} = shift @next_char;                        line => $self->{line_prev},
2153        !!!back-next-input-character (@next_char);                        column => $self->{column_prev} - 1);
2154          ## Reconsume.
2155        $self->{state} = BOGUS_COMMENT_STATE;        $self->{state} = BOGUS_COMMENT_STATE;
2156        $self->{current_token} = {type => COMMENT_TOKEN, data => '',        $self->{ct} = {type => COMMENT_TOKEN, data => '',
2157                                  line => $l, column => $c,                                  line => $self->{line_prev},
2158                                    column => $self->{column_prev} - 1,
2159                                 };                                 };
2160        redo A;        redo A;
2161              } elsif ($self->{state} == MD_HYPHEN_STATE) {
2162        ## ISSUE: typos in spec: chacacters, is is a parse error        if ($self->{nc} == 0x002D) { # -
2163        ## 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);
2164            $self->{ct} = {type => COMMENT_TOKEN, data => '',
2165                                      line => $self->{line_prev},
2166                                      column => $self->{column_prev} - 2,
2167                                     };
2168            $self->{state} = COMMENT_START_STATE;
2169            !!!next-input-character;
2170            redo A;
2171          } else {
2172            !!!cp (128);
2173            !!!parse-error (type => 'bogus comment',
2174                            line => $self->{line_prev},
2175                            column => $self->{column_prev} - 2);
2176            $self->{state} = BOGUS_COMMENT_STATE;
2177            ## Reconsume.
2178            $self->{ct} = {type => COMMENT_TOKEN,
2179                                      data => '-',
2180                                      line => $self->{line_prev},
2181                                      column => $self->{column_prev} - 2,
2182                                     };
2183            redo A;
2184          }
2185        } elsif ($self->{state} == MD_DOCTYPE_STATE) {
2186          ## ASCII case-insensitive.
2187          if ($self->{nc} == [
2188                undef,
2189                0x004F, # O
2190                0x0043, # C
2191                0x0054, # T
2192                0x0059, # Y
2193                0x0050, # P
2194              ]->[length $self->{s_kwd}] or
2195              $self->{nc} == [
2196                undef,
2197                0x006F, # o
2198                0x0063, # c
2199                0x0074, # t
2200                0x0079, # y
2201                0x0070, # p
2202              ]->[length $self->{s_kwd}]) {
2203            !!!cp (131);
2204            ## Stay in the state.
2205            $self->{s_kwd} .= chr $self->{nc};
2206            !!!next-input-character;
2207            redo A;
2208          } elsif ((length $self->{s_kwd}) == 6 and
2209                   ($self->{nc} == 0x0045 or # E
2210                    $self->{nc} == 0x0065)) { # e
2211            !!!cp (129);
2212            $self->{state} = DOCTYPE_STATE;
2213            $self->{ct} = {type => DOCTYPE_TOKEN,
2214                                      quirks => 1,
2215                                      line => $self->{line_prev},
2216                                      column => $self->{column_prev} - 7,
2217                                     };
2218            !!!next-input-character;
2219            redo A;
2220          } else {
2221            !!!cp (132);        
2222            !!!parse-error (type => 'bogus comment',
2223                            line => $self->{line_prev},
2224                            column => $self->{column_prev} - 1 - length $self->{s_kwd});
2225            $self->{state} = BOGUS_COMMENT_STATE;
2226            ## Reconsume.
2227            $self->{ct} = {type => COMMENT_TOKEN,
2228                                      data => $self->{s_kwd},
2229                                      line => $self->{line_prev},
2230                                      column => $self->{column_prev} - 1 - length $self->{s_kwd},
2231                                     };
2232            redo A;
2233          }
2234        } elsif ($self->{state} == MD_CDATA_STATE) {
2235          if ($self->{nc} == {
2236                '[' => 0x0043, # C
2237                '[C' => 0x0044, # D
2238                '[CD' => 0x0041, # A
2239                '[CDA' => 0x0054, # T
2240                '[CDAT' => 0x0041, # A
2241              }->{$self->{s_kwd}}) {
2242            !!!cp (135.1);
2243            ## Stay in the state.
2244            $self->{s_kwd} .= chr $self->{nc};
2245            !!!next-input-character;
2246            redo A;
2247          } elsif ($self->{s_kwd} eq '[CDATA' and
2248                   $self->{nc} == 0x005B) { # [
2249            !!!cp (135.2);
2250            $self->{ct} = {type => CHARACTER_TOKEN,
2251                                      data => '',
2252                                      line => $self->{line_prev},
2253                                      column => $self->{column_prev} - 7};
2254            $self->{state} = CDATA_SECTION_STATE;
2255            !!!next-input-character;
2256            redo A;
2257          } else {
2258            !!!cp (135.3);
2259            !!!parse-error (type => 'bogus comment',
2260                            line => $self->{line_prev},
2261                            column => $self->{column_prev} - 1 - length $self->{s_kwd});
2262            $self->{state} = BOGUS_COMMENT_STATE;
2263            ## Reconsume.
2264            $self->{ct} = {type => COMMENT_TOKEN,
2265                                      data => $self->{s_kwd},
2266                                      line => $self->{line_prev},
2267                                      column => $self->{column_prev} - 1 - length $self->{s_kwd},
2268                                     };
2269            redo A;
2270          }
2271      } elsif ($self->{state} == COMMENT_START_STATE) {      } elsif ($self->{state} == COMMENT_START_STATE) {
2272        if ($self->{next_char} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
2273          !!!cp (137);          !!!cp (137);
2274          $self->{state} = COMMENT_START_DASH_STATE;          $self->{state} = COMMENT_START_DASH_STATE;
2275          !!!next-input-character;          !!!next-input-character;
2276          redo A;          redo A;
2277        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2278          !!!cp (138);          !!!cp (138);
2279          !!!parse-error (type => 'bogus comment');          !!!parse-error (type => 'bogus comment');
2280          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2281          !!!next-input-character;          !!!next-input-character;
2282    
2283          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2284    
2285          redo A;          redo A;
2286        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2287          !!!cp (139);          !!!cp (139);
2288          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
2289          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2290          ## reconsume          ## reconsume
2291    
2292          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2293    
2294          redo A;          redo A;
2295        } else {        } else {
2296          !!!cp (140);          !!!cp (140);
2297          $self->{current_token}->{data} # comment          $self->{ct}->{data} # comment
2298              .= chr ($self->{next_char});              .= chr ($self->{nc});
2299          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
2300          !!!next-input-character;          !!!next-input-character;
2301          redo A;          redo A;
2302        }        }
2303      } elsif ($self->{state} == COMMENT_START_DASH_STATE) {      } elsif ($self->{state} == COMMENT_START_DASH_STATE) {
2304        if ($self->{next_char} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
2305          !!!cp (141);          !!!cp (141);
2306          $self->{state} = COMMENT_END_STATE;          $self->{state} = COMMENT_END_STATE;
2307          !!!next-input-character;          !!!next-input-character;
2308          redo A;          redo A;
2309        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2310          !!!cp (142);          !!!cp (142);
2311          !!!parse-error (type => 'bogus comment');          !!!parse-error (type => 'bogus comment');
2312          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2313          !!!next-input-character;          !!!next-input-character;
2314    
2315          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2316    
2317          redo A;          redo A;
2318        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2319          !!!cp (143);          !!!cp (143);
2320          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
2321          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2322          ## reconsume          ## reconsume
2323    
2324          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2325    
2326          redo A;          redo A;
2327        } else {        } else {
2328          !!!cp (144);          !!!cp (144);
2329          $self->{current_token}->{data} # comment          $self->{ct}->{data} # comment
2330              .= '-' . chr ($self->{next_char});              .= '-' . chr ($self->{nc});
2331          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
2332          !!!next-input-character;          !!!next-input-character;
2333          redo A;          redo A;
2334        }        }
2335      } elsif ($self->{state} == COMMENT_STATE) {      } elsif ($self->{state} == COMMENT_STATE) {
2336        if ($self->{next_char} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
2337          !!!cp (145);          !!!cp (145);
2338          $self->{state} = COMMENT_END_DASH_STATE;          $self->{state} = COMMENT_END_DASH_STATE;
2339          !!!next-input-character;          !!!next-input-character;
2340          redo A;          redo A;
2341        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2342          !!!cp (146);          !!!cp (146);
2343          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
2344          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2345          ## reconsume          ## reconsume
2346    
2347          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2348    
2349          redo A;          redo A;
2350        } else {        } else {
2351          !!!cp (147);          !!!cp (147);
2352          $self->{current_token}->{data} .= chr ($self->{next_char}); # comment          $self->{ct}->{data} .= chr ($self->{nc}); # comment
2353            $self->{read_until}->($self->{ct}->{data},
2354                                  q[-],
2355                                  length $self->{ct}->{data});
2356    
2357          ## Stay in the state          ## Stay in the state
2358          !!!next-input-character;          !!!next-input-character;
2359          redo A;          redo A;
2360        }        }
2361      } elsif ($self->{state} == COMMENT_END_DASH_STATE) {      } elsif ($self->{state} == COMMENT_END_DASH_STATE) {
2362        if ($self->{next_char} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
2363          !!!cp (148);          !!!cp (148);
2364          $self->{state} = COMMENT_END_STATE;          $self->{state} = COMMENT_END_STATE;
2365          !!!next-input-character;          !!!next-input-character;
2366          redo A;          redo A;
2367        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2368          !!!cp (149);          !!!cp (149);
2369          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
2370          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2371          ## reconsume          ## reconsume
2372    
2373          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2374    
2375          redo A;          redo A;
2376        } else {        } else {
2377          !!!cp (150);          !!!cp (150);
2378          $self->{current_token}->{data} .= '-' . chr ($self->{next_char}); # comment          $self->{ct}->{data} .= '-' . chr ($self->{nc}); # comment
2379          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
2380          !!!next-input-character;          !!!next-input-character;
2381          redo A;          redo A;
2382        }        }
2383      } elsif ($self->{state} == COMMENT_END_STATE) {      } elsif ($self->{state} == COMMENT_END_STATE) {
2384        if ($self->{next_char} == 0x003E) { # >        if ($self->{nc} == 0x003E) { # >
2385          !!!cp (151);          !!!cp (151);
2386          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2387          !!!next-input-character;          !!!next-input-character;
2388    
2389          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2390    
2391          redo A;          redo A;
2392        } elsif ($self->{next_char} == 0x002D) { # -        } elsif ($self->{nc} == 0x002D) { # -
2393          !!!cp (152);          !!!cp (152);
2394          !!!parse-error (type => 'dash in comment',          !!!parse-error (type => 'dash in comment',
2395                          line => $self->{line_prev},                          line => $self->{line_prev},
2396                          column => $self->{column_prev});                          column => $self->{column_prev});
2397          $self->{current_token}->{data} .= '-'; # comment          $self->{ct}->{data} .= '-'; # comment
2398          ## Stay in the state          ## Stay in the state
2399          !!!next-input-character;          !!!next-input-character;
2400          redo A;          redo A;
2401        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2402          !!!cp (153);          !!!cp (153);
2403          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
2404          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2405          ## reconsume          ## reconsume
2406    
2407          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2408    
2409          redo A;          redo A;
2410        } else {        } else {
# Line 1991  sub _get_next_token ($) { Line 2412  sub _get_next_token ($) {
2412          !!!parse-error (type => 'dash in comment',          !!!parse-error (type => 'dash in comment',
2413                          line => $self->{line_prev},                          line => $self->{line_prev},
2414                          column => $self->{column_prev});                          column => $self->{column_prev});
2415          $self->{current_token}->{data} .= '--' . chr ($self->{next_char}); # comment          $self->{ct}->{data} .= '--' . chr ($self->{nc}); # comment
2416          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
2417          !!!next-input-character;          !!!next-input-character;
2418          redo A;          redo A;
2419        }        }
2420      } elsif ($self->{state} == DOCTYPE_STATE) {      } elsif ($self->{state} == DOCTYPE_STATE) {
2421        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # VT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP  
2422          !!!cp (155);          !!!cp (155);
2423          $self->{state} = BEFORE_DOCTYPE_NAME_STATE;          $self->{state} = BEFORE_DOCTYPE_NAME_STATE;
2424          !!!next-input-character;          !!!next-input-character;
# Line 2014  sub _get_next_token ($) { Line 2431  sub _get_next_token ($) {
2431          redo A;          redo A;
2432        }        }
2433      } elsif ($self->{state} == BEFORE_DOCTYPE_NAME_STATE) {      } elsif ($self->{state} == BEFORE_DOCTYPE_NAME_STATE) {
2434        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # VT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP  
2435          !!!cp (157);          !!!cp (157);
2436          ## Stay in the state          ## Stay in the state
2437          !!!next-input-character;          !!!next-input-character;
2438          redo A;          redo A;
2439        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2440          !!!cp (158);          !!!cp (158);
2441          !!!parse-error (type => 'no DOCTYPE name');          !!!parse-error (type => 'no DOCTYPE name');
2442          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2443          !!!next-input-character;          !!!next-input-character;
2444    
2445          !!!emit ($self->{current_token}); # DOCTYPE (quirks)          !!!emit ($self->{ct}); # DOCTYPE (quirks)
2446    
2447          redo A;          redo A;
2448        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2449          !!!cp (159);          !!!cp (159);
2450          !!!parse-error (type => 'no DOCTYPE name');          !!!parse-error (type => 'no DOCTYPE name');
2451          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2452          ## reconsume          ## reconsume
2453    
2454          !!!emit ($self->{current_token}); # DOCTYPE (quirks)          !!!emit ($self->{ct}); # DOCTYPE (quirks)
2455    
2456          redo A;          redo A;
2457        } else {        } else {
2458          !!!cp (160);          !!!cp (160);
2459          $self->{current_token}->{name} = chr $self->{next_char};          $self->{ct}->{name} = chr $self->{nc};
2460          delete $self->{current_token}->{quirks};          delete $self->{ct}->{quirks};
2461  ## ISSUE: "Set the token's name name to the" in the spec  ## ISSUE: "Set the token's name name to the" in the spec
2462          $self->{state} = DOCTYPE_NAME_STATE;          $self->{state} = DOCTYPE_NAME_STATE;
2463          !!!next-input-character;          !!!next-input-character;
# Line 2052  sub _get_next_token ($) { Line 2465  sub _get_next_token ($) {
2465        }        }
2466      } elsif ($self->{state} == DOCTYPE_NAME_STATE) {      } elsif ($self->{state} == DOCTYPE_NAME_STATE) {
2467  ## ISSUE: Redundant "First," in the spec.  ## ISSUE: Redundant "First," in the spec.
2468        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # VT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP  
2469          !!!cp (161);          !!!cp (161);
2470          $self->{state} = AFTER_DOCTYPE_NAME_STATE;          $self->{state} = AFTER_DOCTYPE_NAME_STATE;
2471          !!!next-input-character;          !!!next-input-character;
2472          redo A;          redo A;
2473        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2474          !!!cp (162);          !!!cp (162);
2475          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2476          !!!next-input-character;          !!!next-input-character;
2477    
2478          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2479    
2480          redo A;          redo A;
2481        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2482          !!!cp (163);          !!!cp (163);
2483          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2484          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2485          ## reconsume          ## reconsume
2486    
2487          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2488          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2489    
2490          redo A;          redo A;
2491        } else {        } else {
2492          !!!cp (164);          !!!cp (164);
2493          $self->{current_token}->{name}          $self->{ct}->{name}
2494            .= chr ($self->{next_char}); # DOCTYPE            .= chr ($self->{nc}); # DOCTYPE
2495          ## Stay in the state          ## Stay in the state
2496          !!!next-input-character;          !!!next-input-character;
2497          redo A;          redo A;
2498        }        }
2499      } elsif ($self->{state} == AFTER_DOCTYPE_NAME_STATE) {      } elsif ($self->{state} == AFTER_DOCTYPE_NAME_STATE) {
2500        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # VT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP  
2501          !!!cp (165);          !!!cp (165);
2502          ## Stay in the state          ## Stay in the state
2503          !!!next-input-character;          !!!next-input-character;
2504          redo A;          redo A;
2505        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2506          !!!cp (166);          !!!cp (166);
2507          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2508          !!!next-input-character;          !!!next-input-character;
2509    
2510          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2511    
2512          redo A;          redo A;
2513        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2514          !!!cp (167);          !!!cp (167);
2515          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2516          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2517          ## reconsume          ## reconsume
2518    
2519          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2520          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2521    
2522          redo A;          redo A;
2523        } elsif ($self->{next_char} == 0x0050 or # P        } elsif ($self->{nc} == 0x0050 or # P
2524                 $self->{next_char} == 0x0070) { # p                 $self->{nc} == 0x0070) { # p
2525            $self->{state} = PUBLIC_STATE;
2526            $self->{s_kwd} = chr $self->{nc};
2527          !!!next-input-character;          !!!next-input-character;
2528          if ($self->{next_char} == 0x0055 or # U          redo A;
2529              $self->{next_char} == 0x0075) { # u        } elsif ($self->{nc} == 0x0053 or # S
2530            !!!next-input-character;                 $self->{nc} == 0x0073) { # s
2531            if ($self->{next_char} == 0x0042 or # B          $self->{state} = SYSTEM_STATE;
2532                $self->{next_char} == 0x0062) { # b          $self->{s_kwd} = chr $self->{nc};
             !!!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);  
         }  
   
         #  
       } elsif ($self->{next_char} == 0x0053 or # S  
                $self->{next_char} == 0x0073) { # s  
2533          !!!next-input-character;          !!!next-input-character;
2534          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);  
         }  
   
         #  
2535        } else {        } else {
2536          !!!cp (180);          !!!cp (180);
2537            !!!parse-error (type => 'string after DOCTYPE name');
2538            $self->{ct}->{quirks} = 1;
2539    
2540            $self->{state} = BOGUS_DOCTYPE_STATE;
2541          !!!next-input-character;          !!!next-input-character;
2542          #          redo A;
2543        }        }
2544        } elsif ($self->{state} == PUBLIC_STATE) {
2545          ## ASCII case-insensitive
2546          if ($self->{nc} == [
2547                undef,
2548                0x0055, # U
2549                0x0042, # B
2550                0x004C, # L
2551                0x0049, # I
2552              ]->[length $self->{s_kwd}] or
2553              $self->{nc} == [
2554                undef,
2555                0x0075, # u
2556                0x0062, # b
2557                0x006C, # l
2558                0x0069, # i
2559              ]->[length $self->{s_kwd}]) {
2560            !!!cp (175);
2561            ## Stay in the state.
2562            $self->{s_kwd} .= chr $self->{nc};
2563            !!!next-input-character;
2564            redo A;
2565          } elsif ((length $self->{s_kwd}) == 5 and
2566                   ($self->{nc} == 0x0043 or # C
2567                    $self->{nc} == 0x0063)) { # c
2568            !!!cp (168);
2569            $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
2570            !!!next-input-character;
2571            redo A;
2572          } else {
2573            !!!cp (169);
2574            !!!parse-error (type => 'string after DOCTYPE name',
2575                            line => $self->{line_prev},
2576                            column => $self->{column_prev} + 1 - length $self->{s_kwd});
2577            $self->{ct}->{quirks} = 1;
2578    
2579        !!!parse-error (type => 'string after DOCTYPE name');          $self->{state} = BOGUS_DOCTYPE_STATE;
2580        $self->{current_token}->{quirks} = 1;          ## Reconsume.
2581            redo A;
2582          }
2583        } elsif ($self->{state} == SYSTEM_STATE) {
2584          ## ASCII case-insensitive
2585          if ($self->{nc} == [
2586                undef,
2587                0x0059, # Y
2588                0x0053, # S
2589                0x0054, # T
2590                0x0045, # E
2591              ]->[length $self->{s_kwd}] or
2592              $self->{nc} == [
2593                undef,
2594                0x0079, # y
2595                0x0073, # s
2596                0x0074, # t
2597                0x0065, # e
2598              ]->[length $self->{s_kwd}]) {
2599            !!!cp (170);
2600            ## Stay in the state.
2601            $self->{s_kwd} .= chr $self->{nc};
2602            !!!next-input-character;
2603            redo A;
2604          } elsif ((length $self->{s_kwd}) == 5 and
2605                   ($self->{nc} == 0x004D or # M
2606                    $self->{nc} == 0x006D)) { # m
2607            !!!cp (171);
2608            $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2609            !!!next-input-character;
2610            redo A;
2611          } else {
2612            !!!cp (172);
2613            !!!parse-error (type => 'string after DOCTYPE name',
2614                            line => $self->{line_prev},
2615                            column => $self->{column_prev} + 1 - length $self->{s_kwd});
2616            $self->{ct}->{quirks} = 1;
2617    
2618        $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2619        # next-input-character is already done          ## Reconsume.
2620        redo A;          redo A;
2621          }
2622      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {
2623        if ({        if ($is_space->{$self->{nc}}) {
             0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,  
             #0x000D => 1, # HT, LF, VT, FF, SP, CR  
           }->{$self->{next_char}}) {  
2624          !!!cp (181);          !!!cp (181);
2625          ## Stay in the state          ## Stay in the state
2626          !!!next-input-character;          !!!next-input-character;
2627          redo A;          redo A;
2628        } elsif ($self->{next_char} eq 0x0022) { # "        } elsif ($self->{nc} eq 0x0022) { # "
2629          !!!cp (182);          !!!cp (182);
2630          $self->{current_token}->{public_identifier} = ''; # DOCTYPE          $self->{ct}->{pubid} = ''; # DOCTYPE
2631          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE;          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE;
2632          !!!next-input-character;          !!!next-input-character;
2633          redo A;          redo A;
2634        } elsif ($self->{next_char} eq 0x0027) { # '        } elsif ($self->{nc} eq 0x0027) { # '
2635          !!!cp (183);          !!!cp (183);
2636          $self->{current_token}->{public_identifier} = ''; # DOCTYPE          $self->{ct}->{pubid} = ''; # DOCTYPE
2637          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE;          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE;
2638          !!!next-input-character;          !!!next-input-character;
2639          redo A;          redo A;
2640        } elsif ($self->{next_char} eq 0x003E) { # >        } elsif ($self->{nc} eq 0x003E) { # >
2641          !!!cp (184);          !!!cp (184);
2642          !!!parse-error (type => 'no PUBLIC literal');          !!!parse-error (type => 'no PUBLIC literal');
2643    
2644          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2645          !!!next-input-character;          !!!next-input-character;
2646    
2647          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2648          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2649    
2650          redo A;          redo A;
2651        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2652          !!!cp (185);          !!!cp (185);
2653          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2654    
2655          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2656          ## reconsume          ## reconsume
2657    
2658          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2659          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2660    
2661          redo A;          redo A;
2662        } else {        } else {
2663          !!!cp (186);          !!!cp (186);
2664          !!!parse-error (type => 'string after PUBLIC');          !!!parse-error (type => 'string after PUBLIC');
2665          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2666    
2667          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2668          !!!next-input-character;          !!!next-input-character;
2669          redo A;          redo A;
2670        }        }
2671      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE) {
2672        if ($self->{next_char} == 0x0022) { # "        if ($self->{nc} == 0x0022) { # "
2673          !!!cp (187);          !!!cp (187);
2674          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
2675          !!!next-input-character;          !!!next-input-character;
2676          redo A;          redo A;
2677        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2678          !!!cp (188);          !!!cp (188);
2679          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2680    
2681          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2682          !!!next-input-character;          !!!next-input-character;
2683    
2684          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2685          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2686    
2687          redo A;          redo A;
2688        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2689          !!!cp (189);          !!!cp (189);
2690          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2691    
2692          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2693          ## reconsume          ## reconsume
2694    
2695          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2696          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2697    
2698          redo A;          redo A;
2699        } else {        } else {
2700          !!!cp (190);          !!!cp (190);
2701          $self->{current_token}->{public_identifier} # DOCTYPE          $self->{ct}->{pubid} # DOCTYPE
2702              .= chr $self->{next_char};              .= chr $self->{nc};
2703            $self->{read_until}->($self->{ct}->{pubid}, q[">],
2704                                  length $self->{ct}->{pubid});
2705    
2706          ## Stay in the state          ## Stay in the state
2707          !!!next-input-character;          !!!next-input-character;
2708          redo A;          redo A;
2709        }        }
2710      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE) {
2711        if ($self->{next_char} == 0x0027) { # '        if ($self->{nc} == 0x0027) { # '
2712          !!!cp (191);          !!!cp (191);
2713          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
2714          !!!next-input-character;          !!!next-input-character;
2715          redo A;          redo A;
2716        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2717          !!!cp (192);          !!!cp (192);
2718          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2719    
2720          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2721          !!!next-input-character;          !!!next-input-character;
2722    
2723          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2724          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2725    
2726          redo A;          redo A;
2727        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2728          !!!cp (193);          !!!cp (193);
2729          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2730    
2731          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2732          ## reconsume          ## reconsume
2733    
2734          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2735          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2736    
2737          redo A;          redo A;
2738        } else {        } else {
2739          !!!cp (194);          !!!cp (194);
2740          $self->{current_token}->{public_identifier} # DOCTYPE          $self->{ct}->{pubid} # DOCTYPE
2741              .= chr $self->{next_char};              .= chr $self->{nc};
2742            $self->{read_until}->($self->{ct}->{pubid}, q['>],
2743                                  length $self->{ct}->{pubid});
2744    
2745          ## Stay in the state          ## Stay in the state
2746          !!!next-input-character;          !!!next-input-character;
2747          redo A;          redo A;
2748        }        }
2749      } elsif ($self->{state} == AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {      } elsif ($self->{state} == AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {
2750        if ({        if ($is_space->{$self->{nc}}) {
             0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,  
             #0x000D => 1, # HT, LF, VT, FF, SP, CR  
           }->{$self->{next_char}}) {  
2751          !!!cp (195);          !!!cp (195);
2752          ## Stay in the state          ## Stay in the state
2753          !!!next-input-character;          !!!next-input-character;
2754          redo A;          redo A;
2755        } elsif ($self->{next_char} == 0x0022) { # "        } elsif ($self->{nc} == 0x0022) { # "
2756          !!!cp (196);          !!!cp (196);
2757          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{ct}->{sysid} = ''; # DOCTYPE
2758          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;
2759          !!!next-input-character;          !!!next-input-character;
2760          redo A;          redo A;
2761        } elsif ($self->{next_char} == 0x0027) { # '        } elsif ($self->{nc} == 0x0027) { # '
2762          !!!cp (197);          !!!cp (197);
2763          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{ct}->{sysid} = ''; # DOCTYPE
2764          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;
2765          !!!next-input-character;          !!!next-input-character;
2766          redo A;          redo A;
2767        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2768          !!!cp (198);          !!!cp (198);
2769          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2770          !!!next-input-character;          !!!next-input-character;
2771    
2772          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2773    
2774          redo A;          redo A;
2775        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2776          !!!cp (199);          !!!cp (199);
2777          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2778    
2779          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2780          ## reconsume          ## reconsume
2781    
2782          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2783          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2784    
2785          redo A;          redo A;
2786        } else {        } else {
2787          !!!cp (200);          !!!cp (200);
2788          !!!parse-error (type => 'string after PUBLIC literal');          !!!parse-error (type => 'string after PUBLIC literal');
2789          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2790    
2791          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2792          !!!next-input-character;          !!!next-input-character;
2793          redo A;          redo A;
2794        }        }
2795      } elsif ($self->{state} == BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE) {      } elsif ($self->{state} == BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE) {
2796        if ({        if ($is_space->{$self->{nc}}) {
             0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,  
             #0x000D => 1, # HT, LF, VT, FF, SP, CR  
           }->{$self->{next_char}}) {  
2797          !!!cp (201);          !!!cp (201);
2798          ## Stay in the state          ## Stay in the state
2799          !!!next-input-character;          !!!next-input-character;
2800          redo A;          redo A;
2801        } elsif ($self->{next_char} == 0x0022) { # "        } elsif ($self->{nc} == 0x0022) { # "
2802          !!!cp (202);          !!!cp (202);
2803          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{ct}->{sysid} = ''; # DOCTYPE
2804          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;
2805          !!!next-input-character;          !!!next-input-character;
2806          redo A;          redo A;
2807        } elsif ($self->{next_char} == 0x0027) { # '        } elsif ($self->{nc} == 0x0027) { # '
2808          !!!cp (203);          !!!cp (203);
2809          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{ct}->{sysid} = ''; # DOCTYPE
2810          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;
2811          !!!next-input-character;          !!!next-input-character;
2812          redo A;          redo A;
2813        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2814          !!!cp (204);          !!!cp (204);
2815          !!!parse-error (type => 'no SYSTEM literal');          !!!parse-error (type => 'no SYSTEM literal');
2816          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2817          !!!next-input-character;          !!!next-input-character;
2818    
2819          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2820          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2821    
2822          redo A;          redo A;
2823        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2824          !!!cp (205);          !!!cp (205);
2825          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2826    
2827          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2828          ## reconsume          ## reconsume
2829    
2830          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2831          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2832    
2833          redo A;          redo A;
2834        } else {        } else {
2835          !!!cp (206);          !!!cp (206);
2836          !!!parse-error (type => 'string after SYSTEM');          !!!parse-error (type => 'string after SYSTEM');
2837          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2838    
2839          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2840          !!!next-input-character;          !!!next-input-character;
2841          redo A;          redo A;
2842        }        }
2843      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE) {
2844        if ($self->{next_char} == 0x0022) { # "        if ($self->{nc} == 0x0022) { # "
2845          !!!cp (207);          !!!cp (207);
2846          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2847          !!!next-input-character;          !!!next-input-character;
2848          redo A;          redo A;
2849        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2850          !!!cp (208);          !!!cp (208);
2851          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2852    
2853          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2854          !!!next-input-character;          !!!next-input-character;
2855    
2856          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2857          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2858    
2859          redo A;          redo A;
2860        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2861          !!!cp (209);          !!!cp (209);
2862          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2863    
2864          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2865          ## reconsume          ## reconsume
2866    
2867          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2868          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2869    
2870          redo A;          redo A;
2871        } else {        } else {
2872          !!!cp (210);          !!!cp (210);
2873          $self->{current_token}->{system_identifier} # DOCTYPE          $self->{ct}->{sysid} # DOCTYPE
2874              .= chr $self->{next_char};              .= chr $self->{nc};
2875            $self->{read_until}->($self->{ct}->{sysid}, q[">],
2876                                  length $self->{ct}->{sysid});
2877    
2878          ## Stay in the state          ## Stay in the state
2879          !!!next-input-character;          !!!next-input-character;
2880          redo A;          redo A;
2881        }        }
2882      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE) {
2883        if ($self->{next_char} == 0x0027) { # '        if ($self->{nc} == 0x0027) { # '
2884          !!!cp (211);          !!!cp (211);
2885          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2886          !!!next-input-character;          !!!next-input-character;
2887          redo A;          redo A;
2888        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2889          !!!cp (212);          !!!cp (212);
2890          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2891    
2892          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2893          !!!next-input-character;          !!!next-input-character;
2894    
2895          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2896          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2897    
2898          redo A;          redo A;
2899        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2900          !!!cp (213);          !!!cp (213);
2901          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2902    
2903          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2904          ## reconsume          ## reconsume
2905    
2906          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2907          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2908    
2909          redo A;          redo A;
2910        } else {        } else {
2911          !!!cp (214);          !!!cp (214);
2912          $self->{current_token}->{system_identifier} # DOCTYPE          $self->{ct}->{sysid} # DOCTYPE
2913              .= chr $self->{next_char};              .= chr $self->{nc};
2914            $self->{read_until}->($self->{ct}->{sysid}, q['>],
2915                                  length $self->{ct}->{sysid});
2916    
2917          ## Stay in the state          ## Stay in the state
2918          !!!next-input-character;          !!!next-input-character;
2919          redo A;          redo A;
2920        }        }
2921      } elsif ($self->{state} == AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE) {      } elsif ($self->{state} == AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE) {
2922        if ({        if ($is_space->{$self->{nc}}) {
             0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,  
             #0x000D => 1, # HT, LF, VT, FF, SP, CR  
           }->{$self->{next_char}}) {  
2923          !!!cp (215);          !!!cp (215);
2924          ## Stay in the state          ## Stay in the state
2925          !!!next-input-character;          !!!next-input-character;
2926          redo A;          redo A;
2927        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2928          !!!cp (216);          !!!cp (216);
2929          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2930          !!!next-input-character;          !!!next-input-character;
2931    
2932          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2933    
2934          redo A;          redo A;
2935        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2936          !!!cp (217);          !!!cp (217);
2937          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
   
2938          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2939          ## reconsume          ## reconsume
2940    
2941          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2942          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2943    
2944          redo A;          redo A;
2945        } else {        } else {
2946          !!!cp (218);          !!!cp (218);
2947          !!!parse-error (type => 'string after SYSTEM literal');          !!!parse-error (type => 'string after SYSTEM literal');
2948          #$self->{current_token}->{quirks} = 1;          #$self->{ct}->{quirks} = 1;
2949    
2950          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2951          !!!next-input-character;          !!!next-input-character;
2952          redo A;          redo A;
2953        }        }
2954      } elsif ($self->{state} == BOGUS_DOCTYPE_STATE) {      } elsif ($self->{state} == BOGUS_DOCTYPE_STATE) {
2955        if ($self->{next_char} == 0x003E) { # >        if ($self->{nc} == 0x003E) { # >
2956          !!!cp (219);          !!!cp (219);
2957          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2958          !!!next-input-character;          !!!next-input-character;
2959    
2960          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2961    
2962          redo A;          redo A;
2963        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2964          !!!cp (220);          !!!cp (220);
2965          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2966          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2967          ## reconsume          ## reconsume
2968    
2969          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2970    
2971          redo A;          redo A;
2972        } else {        } else {
2973          !!!cp (221);          !!!cp (221);
2974            my $s = '';
2975            $self->{read_until}->($s, q[>], 0);
2976    
2977          ## Stay in the state          ## Stay in the state
2978          !!!next-input-character;          !!!next-input-character;
2979          redo A;          redo A;
2980        }        }
2981      } elsif ($self->{state} == CDATA_BLOCK_STATE) {      } elsif ($self->{state} == CDATA_SECTION_STATE) {
2982        my $s = '';        ## NOTE: "CDATA section state" in the state is jointly implemented
2983          ## by three states, |CDATA_SECTION_STATE|, |CDATA_SECTION_MSE1_STATE|,
2984          ## and |CDATA_SECTION_MSE2_STATE|.
2985                
2986        my ($l, $c) = ($self->{line}, $self->{column});        if ($self->{nc} == 0x005D) { # ]
2987            !!!cp (221.1);
2988        CS: while ($self->{next_char} != -1) {          $self->{state} = CDATA_SECTION_MSE1_STATE;
2989          if ($self->{next_char} == 0x005D) { # ]          !!!next-input-character;
2990            !!!next-input-character;          redo A;
2991            if ($self->{next_char} == 0x005D) { # ]        } elsif ($self->{nc} == -1) {
2992              !!!next-input-character;          $self->{state} = DATA_STATE;
             MDC: {  
               if ($self->{next_char} == 0x003E) { # >  
                 !!!cp (221.1);  
                 !!!next-input-character;  
                 last CS;  
               } elsif ($self->{next_char} == 0x005D) { # ]  
                 !!!cp (221.2);  
                 $s .= ']';  
                 !!!next-input-character;  
                 redo MDC;  
               } else {  
                 !!!cp (221.3);  
                 $s .= ']]';  
                 #  
               }  
             } # MDC  
           } else {  
             !!!cp (221.4);  
             $s .= ']';  
             #  
           }  
         } else {  
           !!!cp (221.5);  
           #  
         }  
         $s .= chr $self->{next_char};  
2993          !!!next-input-character;          !!!next-input-character;
2994        } # CS          if (length $self->{ct}->{data}) { # character
2995              !!!cp (221.2);
2996              !!!emit ($self->{ct}); # character
2997            } else {
2998              !!!cp (221.3);
2999              ## No token to emit. $self->{ct} is discarded.
3000            }        
3001            redo A;
3002          } else {
3003            !!!cp (221.4);
3004            $self->{ct}->{data} .= chr $self->{nc};
3005            $self->{read_until}->($self->{ct}->{data},
3006                                  q<]>,
3007                                  length $self->{ct}->{data});
3008    
3009        $self->{state} = DATA_STATE;          ## Stay in the state.
3010        ## next-input-character done or EOF, which is reconsumed.          !!!next-input-character;
3011            redo A;
3012          }
3013    
3014        if (length $s) {        ## ISSUE: "text tokens" in spec.
3015        } elsif ($self->{state} == CDATA_SECTION_MSE1_STATE) {
3016          if ($self->{nc} == 0x005D) { # ]
3017            !!!cp (221.5);
3018            $self->{state} = CDATA_SECTION_MSE2_STATE;
3019            !!!next-input-character;
3020            redo A;
3021          } else {
3022          !!!cp (221.6);          !!!cp (221.6);
3023          !!!emit ({type => CHARACTER_TOKEN, data => $s,          $self->{ct}->{data} .= ']';
3024                    line => $l, column => $c});          $self->{state} = CDATA_SECTION_STATE;
3025            ## Reconsume.
3026            redo A;
3027          }
3028        } elsif ($self->{state} == CDATA_SECTION_MSE2_STATE) {
3029          if ($self->{nc} == 0x003E) { # >
3030            $self->{state} = DATA_STATE;
3031            !!!next-input-character;
3032            if (length $self->{ct}->{data}) { # character
3033              !!!cp (221.7);
3034              !!!emit ($self->{ct}); # character
3035            } else {
3036              !!!cp (221.8);
3037              ## No token to emit. $self->{ct} is discarded.
3038            }
3039            redo A;
3040          } elsif ($self->{nc} == 0x005D) { # ]
3041            !!!cp (221.9); # character
3042            $self->{ct}->{data} .= ']'; ## Add first "]" of "]]]".
3043            ## Stay in the state.
3044            !!!next-input-character;
3045            redo A;
3046        } else {        } else {
3047          !!!cp (221.7);          !!!cp (221.11);
3048            $self->{ct}->{data} .= ']]'; # character
3049            $self->{state} = CDATA_SECTION_STATE;
3050            ## Reconsume.
3051            redo A;
3052          }
3053        } elsif ($self->{state} == ENTITY_STATE) {
3054          if ($is_space->{$self->{nc}} or
3055              {
3056                0x003C => 1, 0x0026 => 1, -1 => 1, # <, &
3057                $self->{entity_add} => 1,
3058              }->{$self->{nc}}) {
3059            !!!cp (1001);
3060            ## Don't consume
3061            ## No error
3062            ## Return nothing.
3063            #
3064          } elsif ($self->{nc} == 0x0023) { # #
3065            !!!cp (999);
3066            $self->{state} = ENTITY_HASH_STATE;
3067            $self->{s_kwd} = '#';
3068            !!!next-input-character;
3069            redo A;
3070          } elsif ((0x0041 <= $self->{nc} and
3071                    $self->{nc} <= 0x005A) or # A..Z
3072                   (0x0061 <= $self->{nc} and
3073                    $self->{nc} <= 0x007A)) { # a..z
3074            !!!cp (998);
3075            require Whatpm::_NamedEntityList;
3076            $self->{state} = ENTITY_NAME_STATE;
3077            $self->{s_kwd} = chr $self->{nc};
3078            $self->{entity__value} = $self->{s_kwd};
3079            $self->{entity__match} = 0;
3080            !!!next-input-character;
3081            redo A;
3082          } else {
3083            !!!cp (1027);
3084            !!!parse-error (type => 'bare ero');
3085            ## Return nothing.
3086            #
3087        }        }
3088    
3089        redo A;        ## NOTE: No character is consumed by the "consume a character
3090          ## reference" algorithm.  In other word, there is an "&" character
3091        ## ISSUE: "text tokens" in spec.        ## that does not introduce a character reference, which would be
3092        ## TODO: Streaming support        ## appended to the parent element or the attribute value in later
3093      } else {        ## process of the tokenizer.
3094        die "$0: $self->{state}: Unknown state";  
3095      }        if ($self->{prev_state} == DATA_STATE) {
3096    } # A            !!!cp (997);
3097            $self->{state} = $self->{prev_state};
3098    die "$0: _get_next_token: unexpected case";          ## Reconsume.
3099  } # _get_next_token          !!!emit ({type => CHARACTER_TOKEN, data => '&',
3100                      line => $self->{line_prev},
3101  sub _tokenize_attempt_to_consume_an_entity ($$$) {                    column => $self->{column_prev},
3102    my ($self, $in_attr, $additional) = @_;                   });
3103            redo A;
3104    my ($l, $c) = ($self->{line_prev}, $self->{column_prev});        } else {
3105            !!!cp (996);
3106            $self->{ca}->{value} .= '&';
3107            $self->{state} = $self->{prev_state};
3108            ## Reconsume.
3109            redo A;
3110          }
3111        } elsif ($self->{state} == ENTITY_HASH_STATE) {
3112          if ($self->{nc} == 0x0078 or # x
3113              $self->{nc} == 0x0058) { # X
3114            !!!cp (995);
3115            $self->{state} = HEXREF_X_STATE;
3116            $self->{s_kwd} .= chr $self->{nc};
3117            !!!next-input-character;
3118            redo A;
3119          } elsif (0x0030 <= $self->{nc} and
3120                   $self->{nc} <= 0x0039) { # 0..9
3121            !!!cp (994);
3122            $self->{state} = NCR_NUM_STATE;
3123            $self->{s_kwd} = $self->{nc} - 0x0030;
3124            !!!next-input-character;
3125            redo A;
3126          } else {
3127            !!!parse-error (type => 'bare nero',
3128                            line => $self->{line_prev},
3129                            column => $self->{column_prev} - 1);
3130    
3131    if ({          ## NOTE: According to the spec algorithm, nothing is returned,
3132         0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,          ## and then "&#" is appended to the parent element or the attribute
3133         0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR          ## value in the later processing.
3134         $additional => 1,  
3135        }->{$self->{next_char}}) {          if ($self->{prev_state} == DATA_STATE) {
3136      !!!cp (1001);            !!!cp (1019);
3137      ## Don't consume            $self->{state} = $self->{prev_state};
3138      ## No error            ## Reconsume.
3139      return undef;            !!!emit ({type => CHARACTER_TOKEN,
3140    } elsif ($self->{next_char} == 0x0023) { # #                      data => '&#',
3141      !!!next-input-character;                      line => $self->{line_prev},
3142      if ($self->{next_char} == 0x0078 or # x                      column => $self->{column_prev} - 1,
3143          $self->{next_char} == 0x0058) { # X                     });
3144        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;  
3145          } else {          } else {
3146            !!!cp (1007);            !!!cp (993);
3147            !!!parse-error (type => 'no refc', line => $l, column => $c);            $self->{ca}->{value} .= '&#';
3148              $self->{state} = $self->{prev_state};
3149              ## Reconsume.
3150              redo A;
3151          }          }
3152          }
3153          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {      } elsif ($self->{state} == NCR_NUM_STATE) {
3154            !!!cp (1008);        if (0x0030 <= $self->{nc} and
3155            !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);            $self->{nc} <= 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  
3156          !!!cp (1012);          !!!cp (1012);
3157          $code *= 10;          $self->{s_kwd} *= 10;
3158          $code += $self->{next_char} - 0x0030;          $self->{s_kwd} += $self->{nc} - 0x0030;
3159                    
3160            ## Stay in the state.
3161          !!!next-input-character;          !!!next-input-character;
3162        }          redo A;
3163          } elsif ($self->{nc} == 0x003B) { # ;
       if ($self->{next_char} == 0x003B) { # ;  
3164          !!!cp (1013);          !!!cp (1013);
3165          !!!next-input-character;          !!!next-input-character;
3166            #
3167        } else {        } else {
3168          !!!cp (1014);          !!!cp (1014);
3169          !!!parse-error (type => 'no refc', line => $l, column => $c);          !!!parse-error (type => 'no refc');
3170            ## Reconsume.
3171            #
3172        }        }
3173    
3174          my $code = $self->{s_kwd};
3175          my $l = $self->{line_prev};
3176          my $c = $self->{column_prev};
3177        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3178          !!!cp (1015);          !!!cp (1015);
3179          !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3180                            text => (sprintf 'U+%04X', $code),
3181                            line => $l, column => $c);
3182          $code = 0xFFFD;          $code = 0xFFFD;
3183        } elsif ($code > 0x10FFFF) {        } elsif ($code > 0x10FFFF) {
3184          !!!cp (1016);          !!!cp (1016);
3185          !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3186                            text => (sprintf 'U-%08X', $code),
3187                            line => $l, column => $c);
3188          $code = 0xFFFD;          $code = 0xFFFD;
3189        } elsif ($code == 0x000D) {        } elsif ($code == 0x000D) {
3190          !!!cp (1017);          !!!cp (1017);
3191          !!!parse-error (type => 'CR character reference', line => $l, column => $c);          !!!parse-error (type => 'CR character reference',
3192                            line => $l, column => $c);
3193          $code = 0x000A;          $code = 0x000A;
3194        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
3195          !!!cp (1018);          !!!cp (1018);
3196          !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'C1 character reference',
3197                            text => (sprintf 'U+%04X', $code),
3198                            line => $l, column => $c);
3199          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
3200        }        }
3201          
3202        return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1,        if ($self->{prev_state} == DATA_STATE) {
3203                line => $l, column => $c,          !!!cp (992);
3204               };          $self->{state} = $self->{prev_state};
3205      } else {          ## Reconsume.
3206        !!!cp (1019);          !!!emit ({type => CHARACTER_TOKEN, data => chr $code,
3207        !!!parse-error (type => 'bare nero', line => $l, column => $c);                    line => $l, column => $c,
3208        !!!back-next-input-character ($self->{next_char});                   });
3209        $self->{next_char} = 0x0023; # #          redo A;
3210        return undef;        } else {
3211      }          !!!cp (991);
3212    } elsif ((0x0041 <= $self->{next_char} and          $self->{ca}->{value} .= chr $code;
3213              $self->{next_char} <= 0x005A) or          $self->{ca}->{has_reference} = 1;
3214             (0x0061 <= $self->{next_char} and          $self->{state} = $self->{prev_state};
3215              $self->{next_char} <= 0x007A)) {          ## Reconsume.
3216      my $entity_name = chr $self->{next_char};          redo A;
3217      !!!next-input-character;        }
3218        } elsif ($self->{state} == HEXREF_X_STATE) {
3219      my $value = $entity_name;        if ((0x0030 <= $self->{nc} and $self->{nc} <= 0x0039) or
3220      my $match = 0;            (0x0041 <= $self->{nc} and $self->{nc} <= 0x0046) or
3221      require Whatpm::_NamedEntityList;            (0x0061 <= $self->{nc} and $self->{nc} <= 0x0066)) {
3222      our $EntityChar;          # 0..9, A..F, a..f
3223            !!!cp (990);
3224      while (length $entity_name < 30 and          $self->{state} = HEXREF_HEX_STATE;
3225             ## NOTE: Some number greater than the maximum length of entity name          $self->{s_kwd} = 0;
3226             ((0x0041 <= $self->{next_char} and # a          ## Reconsume.
3227               $self->{next_char} <= 0x005A) or # x          redo A;
3228              (0x0061 <= $self->{next_char} and # a        } else {
3229               $self->{next_char} <= 0x007A) or # z          !!!parse-error (type => 'bare hcro',
3230              (0x0030 <= $self->{next_char} and # 0                          line => $self->{line_prev},
3231               $self->{next_char} <= 0x0039) or # 9                          column => $self->{column_prev} - 2);
3232              $self->{next_char} == 0x003B)) { # ;  
3233        $entity_name .= chr $self->{next_char};          ## NOTE: According to the spec algorithm, nothing is returned,
3234        if (defined $EntityChar->{$entity_name}) {          ## and then "&#" followed by "X" or "x" is appended to the parent
3235          if ($self->{next_char} == 0x003B) { # ;          ## element or the attribute value in the later processing.
3236            !!!cp (1020);  
3237            $value = $EntityChar->{$entity_name};          if ($self->{prev_state} == DATA_STATE) {
3238            $match = 1;            !!!cp (1005);
3239            !!!next-input-character;            $self->{state} = $self->{prev_state};
3240            last;            ## Reconsume.
3241              !!!emit ({type => CHARACTER_TOKEN,
3242                        data => '&' . $self->{s_kwd},
3243                        line => $self->{line_prev},
3244                        column => $self->{column_prev} - length $self->{s_kwd},
3245                       });
3246              redo A;
3247          } else {          } else {
3248            !!!cp (1021);            !!!cp (989);
3249            $value = $EntityChar->{$entity_name};            $self->{ca}->{value} .= '&' . $self->{s_kwd};
3250            $match = -1;            $self->{state} = $self->{prev_state};
3251              ## Reconsume.
3252              redo A;
3253            }
3254          }
3255        } elsif ($self->{state} == HEXREF_HEX_STATE) {
3256          if (0x0030 <= $self->{nc} and $self->{nc} <= 0x0039) {
3257            # 0..9
3258            !!!cp (1002);
3259            $self->{s_kwd} *= 0x10;
3260            $self->{s_kwd} += $self->{nc} - 0x0030;
3261            ## Stay in the state.
3262            !!!next-input-character;
3263            redo A;
3264          } elsif (0x0061 <= $self->{nc} and
3265                   $self->{nc} <= 0x0066) { # a..f
3266            !!!cp (1003);
3267            $self->{s_kwd} *= 0x10;
3268            $self->{s_kwd} += $self->{nc} - 0x0060 + 9;
3269            ## Stay in the state.
3270            !!!next-input-character;
3271            redo A;
3272          } elsif (0x0041 <= $self->{nc} and
3273                   $self->{nc} <= 0x0046) { # A..F
3274            !!!cp (1004);
3275            $self->{s_kwd} *= 0x10;
3276            $self->{s_kwd} += $self->{nc} - 0x0040 + 9;
3277            ## Stay in the state.
3278            !!!next-input-character;
3279            redo A;
3280          } elsif ($self->{nc} == 0x003B) { # ;
3281            !!!cp (1006);
3282            !!!next-input-character;
3283            #
3284          } else {
3285            !!!cp (1007);
3286            !!!parse-error (type => 'no refc',
3287                            line => $self->{line},
3288                            column => $self->{column});
3289            ## Reconsume.
3290            #
3291          }
3292    
3293          my $code = $self->{s_kwd};
3294          my $l = $self->{line_prev};
3295          my $c = $self->{column_prev};
3296          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3297            !!!cp (1008);
3298            !!!parse-error (type => 'invalid character reference',
3299                            text => (sprintf 'U+%04X', $code),
3300                            line => $l, column => $c);
3301            $code = 0xFFFD;
3302          } elsif ($code > 0x10FFFF) {
3303            !!!cp (1009);
3304            !!!parse-error (type => 'invalid character reference',
3305                            text => (sprintf 'U-%08X', $code),
3306                            line => $l, column => $c);
3307            $code = 0xFFFD;
3308          } elsif ($code == 0x000D) {
3309            !!!cp (1010);
3310            !!!parse-error (type => 'CR character reference', line => $l, column => $c);
3311            $code = 0x000A;
3312          } elsif (0x80 <= $code and $code <= 0x9F) {
3313            !!!cp (1011);
3314            !!!parse-error (type => 'C1 character reference', text => (sprintf 'U+%04X', $code), line => $l, column => $c);
3315            $code = $c1_entity_char->{$code};
3316          }
3317    
3318          if ($self->{prev_state} == DATA_STATE) {
3319            !!!cp (988);
3320            $self->{state} = $self->{prev_state};
3321            ## Reconsume.
3322            !!!emit ({type => CHARACTER_TOKEN, data => chr $code,
3323                      line => $l, column => $c,
3324                     });
3325            redo A;
3326          } else {
3327            !!!cp (987);
3328            $self->{ca}->{value} .= chr $code;
3329            $self->{ca}->{has_reference} = 1;
3330            $self->{state} = $self->{prev_state};
3331            ## Reconsume.
3332            redo A;
3333          }
3334        } elsif ($self->{state} == ENTITY_NAME_STATE) {
3335          if (length $self->{s_kwd} < 30 and
3336              ## NOTE: Some number greater than the maximum length of entity name
3337              ((0x0041 <= $self->{nc} and # a
3338                $self->{nc} <= 0x005A) or # x
3339               (0x0061 <= $self->{nc} and # a
3340                $self->{nc} <= 0x007A) or # z
3341               (0x0030 <= $self->{nc} and # 0
3342                $self->{nc} <= 0x0039) or # 9
3343               $self->{nc} == 0x003B)) { # ;
3344            our $EntityChar;
3345            $self->{s_kwd} .= chr $self->{nc};
3346            if (defined $EntityChar->{$self->{s_kwd}}) {
3347              if ($self->{nc} == 0x003B) { # ;
3348                !!!cp (1020);
3349                $self->{entity__value} = $EntityChar->{$self->{s_kwd}};
3350                $self->{entity__match} = 1;
3351                !!!next-input-character;
3352                #
3353              } else {
3354                !!!cp (1021);
3355                $self->{entity__value} = $EntityChar->{$self->{s_kwd}};
3356                $self->{entity__match} = -1;
3357                ## Stay in the state.
3358                !!!next-input-character;
3359                redo A;
3360              }
3361            } else {
3362              !!!cp (1022);
3363              $self->{entity__value} .= chr $self->{nc};
3364              $self->{entity__match} *= 2;
3365              ## Stay in the state.
3366            !!!next-input-character;            !!!next-input-character;
3367              redo A;
3368            }
3369          }
3370    
3371          my $data;
3372          my $has_ref;
3373          if ($self->{entity__match} > 0) {
3374            !!!cp (1023);
3375            $data = $self->{entity__value};
3376            $has_ref = 1;
3377            #
3378          } elsif ($self->{entity__match} < 0) {
3379            !!!parse-error (type => 'no refc');
3380            if ($self->{prev_state} != DATA_STATE and # in attribute
3381                $self->{entity__match} < -1) {
3382              !!!cp (1024);
3383              $data = '&' . $self->{s_kwd};
3384              #
3385            } else {
3386              !!!cp (1025);
3387              $data = $self->{entity__value};
3388              $has_ref = 1;
3389              #
3390          }          }
3391        } else {        } else {
3392          !!!cp (1022);          !!!cp (1026);
3393          $value .= chr $self->{next_char};          !!!parse-error (type => 'bare ero',
3394          $match *= 2;                          line => $self->{line_prev},
3395          !!!next-input-character;                          column => $self->{column_prev} - length $self->{s_kwd});
3396            $data = '&' . $self->{s_kwd};
3397            #
3398        }        }
3399      }    
3400              ## NOTE: In these cases, when a character reference is found,
3401      if ($match > 0) {        ## it is consumed and a character token is returned, or, otherwise,
3402        !!!cp (1023);        ## nothing is consumed and returned, according to the spec algorithm.
3403        return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,        ## In this implementation, anything that has been examined by the
3404                line => $l, column => $c,        ## tokenizer is appended to the parent element or the attribute value
3405               };        ## as string, either literal string when no character reference or
3406      } elsif ($match < 0) {        ## entity-replaced string otherwise, in this stage, since any characters
3407        !!!parse-error (type => 'no refc', line => $l, column => $c);        ## that would not be consumed are appended in the data state or in an
3408        if ($in_attr and $match < -1) {        ## appropriate attribute value state anyway.
3409          !!!cp (1024);  
3410          return {type => CHARACTER_TOKEN, data => '&'.$entity_name,        if ($self->{prev_state} == DATA_STATE) {
3411                  line => $l, column => $c,          !!!cp (986);
3412                 };          $self->{state} = $self->{prev_state};
3413        } else {          ## Reconsume.
3414          !!!cp (1025);          !!!emit ({type => CHARACTER_TOKEN,
3415          return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,                    data => $data,
3416                  line => $l, column => $c,                    line => $self->{line_prev},
3417                 };                    column => $self->{column_prev} + 1 - length $self->{s_kwd},
3418                     });
3419            redo A;
3420          } else {
3421            !!!cp (985);
3422            $self->{ca}->{value} .= $data;
3423            $self->{ca}->{has_reference} = 1 if $has_ref;
3424            $self->{state} = $self->{prev_state};
3425            ## Reconsume.
3426            redo A;
3427        }        }
3428      } else {      } else {
3429        !!!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,  
              };  
3430      }      }
3431    } else {    } # A  
3432      !!!cp (1027);  
3433      ## no characters are consumed    die "$0: _get_next_token: unexpected case";
3434      !!!parse-error (type => 'bare ero', line => $l, column => $c);  } # _get_next_token
     return undef;  
   }  
 } # _tokenize_attempt_to_consume_an_entity  
3435    
3436  sub _initialize_tree_constructor ($) {  sub _initialize_tree_constructor ($) {
3437    my $self = shift;    my $self = shift;
# Line 2836  sub _initialize_tree_constructor ($) { Line 3440  sub _initialize_tree_constructor ($) {
3440    ## TODO: Turn mutation events off # MUST    ## TODO: Turn mutation events off # MUST
3441    ## TODO: Turn loose Document option (manakai extension) on    ## TODO: Turn loose Document option (manakai extension) on
3442    $self->{document}->manakai_is_html (1); # MUST    $self->{document}->manakai_is_html (1); # MUST
3443      $self->{document}->set_user_data (manakai_source_line => 1);
3444      $self->{document}->set_user_data (manakai_source_column => 1);
3445  } # _initialize_tree_constructor  } # _initialize_tree_constructor
3446    
3447  sub _terminate_tree_constructor ($) {  sub _terminate_tree_constructor ($) {
# Line 2890  sub _tree_construction_initial ($) { Line 3496  sub _tree_construction_initial ($) {
3496        ## language.        ## language.
3497        my $doctype_name = $token->{name};        my $doctype_name = $token->{name};
3498        $doctype_name = '' unless defined $doctype_name;        $doctype_name = '' unless defined $doctype_name;
3499        $doctype_name =~ tr/a-z/A-Z/;        $doctype_name =~ tr/a-z/A-Z/; # ASCII case-insensitive
3500        if (not defined $token->{name} or # <!DOCTYPE>        if (not defined $token->{name} or # <!DOCTYPE>
3501            defined $token->{public_identifier} or            defined $token->{sysid}) {
           defined $token->{system_identifier}) {  
3502          !!!cp ('t1');          !!!cp ('t1');
3503          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3504        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
3505          !!!cp ('t2');          !!!cp ('t2');
         ## ISSUE: ASCII case-insensitive? (in fact it does not matter)  
3506          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3507          } elsif (defined $token->{pubid}) {
3508            if ($token->{pubid} eq 'XSLT-compat') {
3509              !!!cp ('t1.2');
3510              !!!parse-error (type => 'XSLT-compat', token => $token,
3511                              level => $self->{level}->{should});
3512            } else {
3513              !!!parse-error (type => 'not HTML5', token => $token);
3514            }
3515        } else {        } else {
3516          !!!cp ('t3');          !!!cp ('t3');
3517            #
3518        }        }
3519                
3520        my $doctype = $self->{document}->create_document_type_definition        my $doctype = $self->{document}->create_document_type_definition
3521          ($token->{name}); ## ISSUE: If name is missing (e.g. <!DOCTYPE>)?          ($token->{name}); ## ISSUE: If name is missing (e.g. <!DOCTYPE>)?
3522        ## NOTE: Default value for both |public_id| and |system_id| attributes        ## NOTE: Default value for both |public_id| and |system_id| attributes
3523        ## are empty strings, so that we don't set any value in missing cases.        ## are empty strings, so that we don't set any value in missing cases.
3524        $doctype->public_id ($token->{public_identifier})        $doctype->public_id ($token->{pubid}) if defined $token->{pubid};
3525            if defined $token->{public_identifier};        $doctype->system_id ($token->{sysid}) if defined $token->{sysid};
       $doctype->system_id ($token->{system_identifier})  
           if defined $token->{system_identifier};  
3526        ## NOTE: Other DocumentType attributes are null or empty lists.        ## NOTE: Other DocumentType attributes are null or empty lists.
3527        ## ISSUE: internalSubset = null??        ## ISSUE: internalSubset = null??
3528        $self->{document}->append_child ($doctype);        $self->{document}->append_child ($doctype);
# Line 2919  sub _tree_construction_initial ($) { Line 3530  sub _tree_construction_initial ($) {
3530        if ($token->{quirks} or $doctype_name ne 'HTML') {        if ($token->{quirks} or $doctype_name ne 'HTML') {
3531          !!!cp ('t4');          !!!cp ('t4');
3532          $self->{document}->manakai_compat_mode ('quirks');          $self->{document}->manakai_compat_mode ('quirks');
3533        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{pubid}) {
3534          my $pubid = $token->{public_identifier};          my $pubid = $token->{pubid};
3535          $pubid =~ tr/a-z/A-z/;          $pubid =~ tr/a-z/A-z/;
3536          if ({          my $prefix = [
3537            "+//SILMARIL//DTD HTML PRO V0R11 19970101//EN" => 1,            "+//SILMARIL//DTD HTML PRO V0R11 19970101//",
3538            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3539            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3540            "-//IETF//DTD HTML 2.0 LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 1//",
3541            "-//IETF//DTD HTML 2.0 LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 2//",
3542            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//",
3543            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//",
3544            "-//IETF//DTD HTML 2.0 STRICT//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT//",
3545            "-//IETF//DTD HTML 2.0//EN" => 1,            "-//IETF//DTD HTML 2.0//",
3546            "-//IETF//DTD HTML 2.1E//EN" => 1,            "-//IETF//DTD HTML 2.1E//",
3547            "-//IETF//DTD HTML 3.0//EN" => 1,            "-//IETF//DTD HTML 3.0//",
3548            "-//IETF//DTD HTML 3.0//EN//" => 1,            "-//IETF//DTD HTML 3.2 FINAL//",
3549            "-//IETF//DTD HTML 3.2 FINAL//EN" => 1,            "-//IETF//DTD HTML 3.2//",
3550            "-//IETF//DTD HTML 3.2//EN" => 1,            "-//IETF//DTD HTML 3//",
3551            "-//IETF//DTD HTML 3//EN" => 1,            "-//IETF//DTD HTML LEVEL 0//",
3552            "-//IETF//DTD HTML LEVEL 0//EN" => 1,            "-//IETF//DTD HTML LEVEL 1//",
3553            "-//IETF//DTD HTML LEVEL 0//EN//2.0" => 1,            "-//IETF//DTD HTML LEVEL 2//",
3554            "-//IETF//DTD HTML LEVEL 1//EN" => 1,            "-//IETF//DTD HTML LEVEL 3//",
3555            "-//IETF//DTD HTML LEVEL 1//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 0//",
3556            "-//IETF//DTD HTML LEVEL 2//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 1//",
3557            "-//IETF//DTD HTML LEVEL 2//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 2//",
3558            "-//IETF//DTD HTML LEVEL 3//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 3//",
3559            "-//IETF//DTD HTML LEVEL 3//EN//3.0" => 1,            "-//IETF//DTD HTML STRICT//",
3560            "-//IETF//DTD HTML STRICT LEVEL 0//EN" => 1,            "-//IETF//DTD HTML//",
3561            "-//IETF//DTD HTML STRICT LEVEL 0//EN//2.0" => 1,            "-//METRIUS//DTD METRIUS PRESENTATIONAL//",
3562            "-//IETF//DTD HTML STRICT LEVEL 1//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//",
3563            "-//IETF//DTD HTML STRICT LEVEL 1//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//",
3564            "-//IETF//DTD HTML STRICT LEVEL 2//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//",
3565            "-//IETF//DTD HTML STRICT LEVEL 2//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//",
3566            "-//IETF//DTD HTML STRICT LEVEL 3//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//",
3567            "-//IETF//DTD HTML STRICT LEVEL 3//EN//3.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//",
3568            "-//IETF//DTD HTML STRICT//EN" => 1,            "-//NETSCAPE COMM. CORP.//DTD HTML//",
3569            "-//IETF//DTD HTML STRICT//EN//2.0" => 1,            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//",
3570            "-//IETF//DTD HTML STRICT//EN//3.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//",
3571            "-//IETF//DTD HTML//EN" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//",
3572            "-//IETF//DTD HTML//EN//2.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//",
3573            "-//IETF//DTD HTML//EN//3.0" => 1,            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//",
3574            "-//METRIUS//DTD METRIUS PRESENTATIONAL//EN" => 1,            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//",
3575            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//EN" => 1,            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//",
3576            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//EN" => 1,            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//",
3577            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//",
3578            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//",
3579            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//EN" => 1,            "-//W3C//DTD HTML 3 1995-03-24//",
3580            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//EN" => 1,            "-//W3C//DTD HTML 3.2 DRAFT//",
3581            "-//NETSCAPE COMM. CORP.//DTD HTML//EN" => 1,            "-//W3C//DTD HTML 3.2 FINAL//",
3582            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//EN" => 1,            "-//W3C//DTD HTML 3.2//",
3583            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//EN" => 1,            "-//W3C//DTD HTML 3.2S DRAFT//",
3584            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 FRAMESET//",
3585            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 TRANSITIONAL//",
3586            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMETNAL 19960712//",
3587            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMENTAL 970421//",
3588            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//EN" => 1,            "-//W3C//DTD W3 HTML//",
3589            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//EN" => 1,            "-//W3O//DTD W3 HTML 3.0//",
3590            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML 2.0//",
3591            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML//",
3592            "-//W3C//DTD HTML 3 1995-03-24//EN" => 1,          ]; # $prefix
3593            "-//W3C//DTD HTML 3.2 DRAFT//EN" => 1,          my $match;
3594            "-//W3C//DTD HTML 3.2 FINAL//EN" => 1,          for (@$prefix) {
3595            "-//W3C//DTD HTML 3.2//EN" => 1,            if (substr ($prefix, 0, length $_) eq $_) {
3596            "-//W3C//DTD HTML 3.2S DRAFT//EN" => 1,              $match = 1;
3597            "-//W3C//DTD HTML 4.0 FRAMESET//EN" => 1,              last;
3598            "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN" => 1,            }
3599            "-//W3C//DTD HTML EXPERIMETNAL 19960712//EN" => 1,          }
3600            "-//W3C//DTD HTML EXPERIMENTAL 970421//EN" => 1,          if ($match or
3601            "-//W3C//DTD W3 HTML//EN" => 1,              $pubid eq "-//W3O//DTD W3 HTML STRICT 3.0//EN//" or
3602            "-//W3O//DTD W3 HTML 3.0//EN" => 1,              $pubid eq "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" or
3603            "-//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}) {  
3604            !!!cp ('t5');            !!!cp ('t5');
3605            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3606          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD HTML 4.01 FRAMESET//] or
3607                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD HTML 4.01 TRANSITIONAL//]) {
3608            if (defined $token->{system_identifier}) {            if (defined $token->{sysid}) {
3609              !!!cp ('t6');              !!!cp ('t6');
3610              $self->{document}->manakai_compat_mode ('quirks');              $self->{document}->manakai_compat_mode ('quirks');
3611            } else {            } else {
3612              !!!cp ('t7');              !!!cp ('t7');
3613              $self->{document}->manakai_compat_mode ('limited quirks');              $self->{document}->manakai_compat_mode ('limited quirks');
3614            }            }
3615          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD XHTML 1.0 FRAMESET//] or
3616                   $pubid eq "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD XHTML 1.0 TRANSITIONAL//]) {
3617            !!!cp ('t8');            !!!cp ('t8');
3618            $self->{document}->manakai_compat_mode ('limited quirks');            $self->{document}->manakai_compat_mode ('limited quirks');
3619          } else {          } else {
# Line 3017  sub _tree_construction_initial ($) { Line 3622  sub _tree_construction_initial ($) {
3622        } else {        } else {
3623          !!!cp ('t10');          !!!cp ('t10');
3624        }        }
3625        if (defined $token->{system_identifier}) {        if (defined $token->{sysid}) {
3626          my $sysid = $token->{system_identifier};          my $sysid = $token->{sysid};
3627          $sysid =~ tr/A-Z/a-z/;          $sysid =~ tr/A-Z/a-z/;
3628          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") {
3629            ## TODO: Check the spec: PUBLIC "(limited quirks)" "(quirks)"            ## NOTE: Ensure that |PUBLIC "(limited quirks)" "(quirks)"| is
3630              ## marked as quirks.
3631            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3632            !!!cp ('t11');            !!!cp ('t11');
3633          } else {          } else {
# Line 3047  sub _tree_construction_initial ($) { Line 3653  sub _tree_construction_initial ($) {
3653        !!!ack-later;        !!!ack-later;
3654        return;        return;
3655      } elsif ($token->{type} == CHARACTER_TOKEN) {      } elsif ($token->{type} == CHARACTER_TOKEN) {
3656        if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D        if ($token->{data} =~ s/^([\x09\x0A\x0C\x20]+)//) {
3657          ## Ignore the token          ## Ignore the token
3658    
3659          unless (length $token->{data}) {          unless (length $token->{data}) {
# Line 3104  sub _tree_construction_root_element ($) Line 3710  sub _tree_construction_root_element ($)
3710          !!!next-token;          !!!next-token;
3711          redo B;          redo B;
3712        } elsif ($token->{type} == CHARACTER_TOKEN) {        } elsif ($token->{type} == CHARACTER_TOKEN) {
3713          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D          if ($token->{data} =~ s/^([\x09\x0A\x0C\x20]+)//) {
3714            ## Ignore the token.            ## Ignore the token.
3715    
3716            unless (length $token->{data}) {            unless (length $token->{data}) {
# Line 3193  sub _reset_insertion_mode ($) { Line 3799  sub _reset_insertion_mode ($) {
3799        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
3800          $last = 1;          $last = 1;
3801          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
3802            if ($self->{inner_html_node}->[1] & TABLE_CELL_EL) {            !!!cp ('t28');
3803              !!!cp ('t27');            $node = $self->{inner_html_node};
3804              #          } else {
3805            } else {            die "_reset_insertion_mode: t27";
             !!!cp ('t28');  
             $node = $self->{inner_html_node};  
           }  
3806          }          }
3807        }        }
3808              
3809      ## Step 4..14        ## Step 4..14
3810      my $new_mode;        my $new_mode;
3811      if ($node->[1] & FOREIGN_EL) {        if ($node->[1] & FOREIGN_EL) {
3812        ## NOTE: Strictly spaking, the line below only applies to MathML and          !!!cp ('t28.1');
3813        ## SVG elements.  Currently the HTML syntax supports only MathML and          ## NOTE: Strictly spaking, the line below only applies to MathML and
3814        ## SVG elements as foreigners.          ## SVG elements.  Currently the HTML syntax supports only MathML and
3815        $new_mode = $self->{insertion_mode} | IN_FOREIGN_CONTENT_IM;          ## SVG elements as foreigners.
3816        ## ISSUE: What is set as the secondary insertion mode?          $new_mode = IN_BODY_IM | IN_FOREIGN_CONTENT_IM;
3817      } else {        } elsif ($node->[1] & TABLE_CELL_EL) {
3818        $new_mode = {          if ($last) {
3819              !!!cp ('t28.2');
3820              #
3821            } else {
3822              !!!cp ('t28.3');
3823              $new_mode = IN_CELL_IM;
3824            }
3825          } else {
3826            !!!cp ('t28.4');
3827            $new_mode = {
3828                        select => IN_SELECT_IM,                        select => IN_SELECT_IM,
3829                        ## NOTE: |option| and |optgroup| do not set                        ## NOTE: |option| and |optgroup| do not set
3830                        ## insertion mode to "in select" by themselves.                        ## insertion mode to "in select" by themselves.
                       td => IN_CELL_IM,  
                       th => IN_CELL_IM,  
3831                        tr => IN_ROW_IM,                        tr => IN_ROW_IM,
3832                        tbody => IN_TABLE_BODY_IM,                        tbody => IN_TABLE_BODY_IM,
3833                        thead => IN_TABLE_BODY_IM,                        thead => IN_TABLE_BODY_IM,
# Line 3229  sub _reset_insertion_mode ($) { Line 3839  sub _reset_insertion_mode ($) {
3839                        body => IN_BODY_IM,                        body => IN_BODY_IM,
3840                        frameset => IN_FRAMESET_IM,                        frameset => IN_FRAMESET_IM,
3841                       }->{$node->[0]->manakai_local_name};                       }->{$node->[0]->manakai_local_name};
3842      }        }
3843      $self->{insertion_mode} = $new_mode and return if defined $new_mode;        $self->{insertion_mode} = $new_mode and return if defined $new_mode;
3844                
3845        ## Step 15        ## Step 15
3846        if ($node->[1] & HTML_EL) {        if ($node->[1] & HTML_EL) {
# Line 3404  sub _tree_construction_main ($) { Line 4014  sub _tree_construction_main ($) {
4014        ## NOTE: An end-of-file token.        ## NOTE: An end-of-file token.
4015        if ($content_model_flag == CDATA_CONTENT_MODEL) {        if ($content_model_flag == CDATA_CONTENT_MODEL) {
4016          !!!cp ('t43');          !!!cp ('t43');
4017          !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in CDATA:#eof', token => $token);
4018        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
4019          !!!cp ('t44');          !!!cp ('t44');
4020          !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in RCDATA:#eof', token => $token);
4021        } else {        } else {
4022          die "$0: $content_model_flag in parse_rcdata";          die "$0: $content_model_flag in parse_rcdata";
4023        }        }
# Line 3444  sub _tree_construction_main ($) { Line 4054  sub _tree_construction_main ($) {
4054        ## Ignore the token        ## Ignore the token
4055      } else {      } else {
4056        !!!cp ('t48');        !!!cp ('t48');
4057        !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);        !!!parse-error (type => 'in CDATA:#eof', token => $token);
4058        ## ISSUE: And ignore?        ## ISSUE: And ignore?
4059        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
4060      }      }
# Line 3495  sub _tree_construction_main ($) { Line 4105  sub _tree_construction_main ($) {
4105        } # AFE        } # AFE
4106        unless (defined $formatting_element) {        unless (defined $formatting_element) {
4107          !!!cp ('t53');          !!!cp ('t53');
4108          !!!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);
4109          ## Ignore the token          ## Ignore the token
4110          !!!next-token;          !!!next-token;
4111          return;          return;
# Line 3512  sub _tree_construction_main ($) { Line 4122  sub _tree_construction_main ($) {
4122              last INSCOPE;              last INSCOPE;
4123            } else { # in open elements but not in scope            } else { # in open elements but not in scope
4124              !!!cp ('t55');              !!!cp ('t55');
4125              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},              !!!parse-error (type => 'unmatched end tag',
4126                                text => $token->{tag_name},
4127                              token => $end_tag_token);                              token => $end_tag_token);
4128              ## Ignore the token              ## Ignore the token
4129              !!!next-token;              !!!next-token;
# Line 3525  sub _tree_construction_main ($) { Line 4136  sub _tree_construction_main ($) {
4136        } # INSCOPE        } # INSCOPE
4137        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
4138          !!!cp ('t57');          !!!cp ('t57');
4139          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},          !!!parse-error (type => 'unmatched end tag',
4140                            text => $token->{tag_name},
4141                          token => $end_tag_token);                          token => $end_tag_token);
4142          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
4143          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
# Line 3534  sub _tree_construction_main ($) { Line 4146  sub _tree_construction_main ($) {
4146        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
4147          !!!cp ('t58');          !!!cp ('t58');
4148          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
4149                          value => $self->{open_elements}->[-1]->[0]                          text => $self->{open_elements}->[-1]->[0]
4150                              ->manakai_local_name,                              ->manakai_local_name,
4151                          token => $end_tag_token);                          token => $end_tag_token);
4152        }        }
# Line 3743  sub _tree_construction_main ($) { Line 4355  sub _tree_construction_main ($) {
4355    B: while (1) {    B: while (1) {
4356      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
4357        !!!cp ('t73');        !!!cp ('t73');
4358        !!!parse-error (type => 'DOCTYPE in the middle', token => $token);        !!!parse-error (type => 'in html:#DOCTYPE', token => $token);
4359        ## Ignore the token        ## Ignore the token
4360        ## Stay in the phase        ## Stay in the phase
4361        !!!next-token;        !!!next-token;
# Line 3752  sub _tree_construction_main ($) { Line 4364  sub _tree_construction_main ($) {
4364               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
4365        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
4366          !!!cp ('t79');          !!!cp ('t79');
4367          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4368          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
4369        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
4370          !!!cp ('t80');          !!!cp ('t80');
4371          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4372          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
4373        } else {        } else {
4374          !!!cp ('t81');          !!!cp ('t81');
# Line 3807  sub _tree_construction_main ($) { Line 4419  sub _tree_construction_main ($) {
4419            #            #
4420          } elsif ({          } elsif ({
4421                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,
4422                    center => 1, code => 1, dd => 1, div => 1, dl => 1, em => 1,                    center => 1, code => 1, dd => 1, div => 1, dl => 1, dt => 1,
4423                    embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1, ## No h4!                    em => 1, embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1,
4424                    h5 => 1, h6 => 1, head => 1, hr => 1, i => 1, img => 1,                    h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, i => 1,
4425                    li => 1, menu => 1, meta => 1, nobr => 1, p => 1, pre => 1,                    img => 1, li => 1, listing => 1, menu => 1, meta => 1,
4426                    ruby => 1, s => 1, small => 1, span => 1, strong => 1,                    nobr => 1, ol => 1, p => 1, pre => 1, ruby => 1, s => 1,
4427                    sub => 1, sup => 1, table => 1, tt => 1, u => 1, ul => 1,                    small => 1, span => 1, strong => 1, strike => 1, sub => 1,
4428                    var => 1,                    sup => 1, table => 1, tt => 1, u => 1, ul => 1, var => 1,
4429                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
4430            !!!cp ('t87.2');            !!!cp ('t87.2');
4431            !!!parse-error (type => 'not closed',            !!!parse-error (type => 'not closed',
4432                            value => $self->{open_elements}->[-1]->[0]                            text => $self->{open_elements}->[-1]->[0]
4433                                ->manakai_local_name,                                ->manakai_local_name,
4434                            token => $token);                            token => $token);
4435    
# Line 3893  sub _tree_construction_main ($) { Line 4505  sub _tree_construction_main ($) {
4505          !!!cp ('t87.5');          !!!cp ('t87.5');
4506          #          #
4507        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
         ## NOTE: "using the rules for secondary insertion mode" then "continue"  
4508          !!!cp ('t87.6');          !!!cp ('t87.6');
4509          #          !!!parse-error (type => 'not closed',
4510          ## TODO: ...                          text => $self->{open_elements}->[-1]->[0]
4511                                ->manakai_local_name,
4512                            token => $token);
4513    
4514            pop @{$self->{open_elements}}
4515                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;
4516    
4517            $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
4518            ## Reprocess.
4519            next B;
4520        } else {        } else {
4521          die "$0: $token->{type}: Unknown token type";                  die "$0: $token->{type}: Unknown token type";        
4522        }        }
# Line 3904  sub _tree_construction_main ($) { Line 4524  sub _tree_construction_main ($) {
4524    
4525      if ($self->{insertion_mode} & HEAD_IMS) {      if ($self->{insertion_mode} & HEAD_IMS) {
4526        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
4527          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0C\x20]+)//) {
4528            unless ($self->{insertion_mode} == BEFORE_HEAD_IM) {            unless ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4529              !!!cp ('t88.2');              !!!cp ('t88.2');
4530              $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);              $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4531                #
4532            } else {            } else {
4533              !!!cp ('t88.1');              !!!cp ('t88.1');
4534              ## Ignore the token.              ## Ignore the token.
4535              !!!next-token;              #
             next B;  
4536            }            }
4537            unless (length $token->{data}) {            unless (length $token->{data}) {
4538              !!!cp ('t88');              !!!cp ('t88');
4539              !!!next-token;              !!!next-token;
4540              next B;              next B;
4541            }            }
4542    ## TODO: set $token->{column} appropriately
4543          }          }
4544    
4545          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
# Line 3937  sub _tree_construction_main ($) { Line 4558  sub _tree_construction_main ($) {
4558            !!!cp ('t90');            !!!cp ('t90');
4559            ## As if </noscript>            ## As if </noscript>
4560            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
4561            !!!parse-error (type => 'in noscript:#character', token => $token);            !!!parse-error (type => 'in noscript:#text', token => $token);
4562                        
4563            ## Reprocess in the "in head" insertion mode...            ## Reprocess in the "in head" insertion mode...
4564            ## As if </head>            ## As if </head>
# Line 3973  sub _tree_construction_main ($) { Line 4594  sub _tree_construction_main ($) {
4594              !!!next-token;              !!!next-token;
4595              next B;              next B;
4596            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4597              !!!cp ('t94');              !!!cp ('t93.2');
4598              #              !!!parse-error (type => 'after head', text => 'head',
4599                                token => $token);
4600                ## Ignore the token
4601                !!!nack ('t93.3');
4602                !!!next-token;
4603                next B;
4604            } else {            } else {
4605              !!!cp ('t95');              !!!cp ('t95');
4606              !!!parse-error (type => 'in head:head', token => $token); # or in head noscript              !!!parse-error (type => 'in head:head',
4607                                token => $token); # or in head noscript
4608              ## Ignore the token              ## Ignore the token
4609              !!!nack ('t95.1');              !!!nack ('t95.1');
4610              !!!next-token;              !!!next-token;
# Line 4002  sub _tree_construction_main ($) { Line 4629  sub _tree_construction_main ($) {
4629                  !!!cp ('t98');                  !!!cp ('t98');
4630                  ## As if </noscript>                  ## As if </noscript>
4631                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4632                  !!!parse-error (type => 'in noscript:base', token => $token);                  !!!parse-error (type => 'in noscript', text => 'base',
4633                                    token => $token);
4634                                
4635                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4636                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
# Line 4013  sub _tree_construction_main ($) { Line 4641  sub _tree_construction_main ($) {
4641                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4642                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4643                  !!!cp ('t100');                  !!!cp ('t100');
4644                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4645                                    text => $token->{tag_name}, token => $token);
4646                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4647                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4648                } else {                } else {
# Line 4030  sub _tree_construction_main ($) { Line 4659  sub _tree_construction_main ($) {
4659                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4660                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4661                  !!!cp ('t102');                  !!!cp ('t102');
4662                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4663                                    text => $token->{tag_name}, token => $token);
4664                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4665                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4666                } else {                } else {
# Line 4047  sub _tree_construction_main ($) { Line 4677  sub _tree_construction_main ($) {
4677                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4678                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4679                  !!!cp ('t104');                  !!!cp ('t104');
4680                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4681                                    text => $token->{tag_name}, token => $token);
4682                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4683                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4684                } else {                } else {
# Line 4057  sub _tree_construction_main ($) { Line 4688  sub _tree_construction_main ($) {
4688                my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
4689    
4690                unless ($self->{confident}) {                unless ($self->{confident}) {
4691                  if ($token->{attributes}->{charset}) { ## TODO: And if supported                  if ($token->{attributes}->{charset}) {
4692                    !!!cp ('t106');                    !!!cp ('t106');
4693                      ## NOTE: Whether the encoding is supported or not is handled
4694                      ## in the {change_encoding} callback.
4695                    $self->{change_encoding}                    $self->{change_encoding}
4696                        ->($self, $token->{attributes}->{charset}->{value},                        ->($self, $token->{attributes}->{charset}->{value},
4697                           $token);                           $token);
# Line 4068  sub _tree_construction_main ($) { Line 4701  sub _tree_construction_main ($) {
4701                                             $token->{attributes}->{charset}                                             $token->{attributes}->{charset}
4702                                                 ->{has_reference});                                                 ->{has_reference});
4703                  } elsif ($token->{attributes}->{content}) {                  } elsif ($token->{attributes}->{content}) {
                   ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.  
4704                    if ($token->{attributes}->{content}->{value}                    if ($token->{attributes}->{content}->{value}
4705                        =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                        =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
4706                            [\x09-\x0D\x20]*=                            [\x09\x0A\x0C\x0D\x20]*=
4707                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                            [\x09\x0A\x0C\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
4708                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                            ([^"'\x09\x0A\x0C\x0D\x20]
4709                               [^\x09\x0A\x0C\x0D\x20\x3B]*))/x) {
4710                      !!!cp ('t107');                      !!!cp ('t107');
4711                        ## NOTE: Whether the encoding is supported or not is handled
4712                        ## in the {change_encoding} callback.
4713                      $self->{change_encoding}                      $self->{change_encoding}
4714                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3,                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3,
4715                             $token);                             $token);
# Line 4113  sub _tree_construction_main ($) { Line 4748  sub _tree_construction_main ($) {
4748                  !!!cp ('t111');                  !!!cp ('t111');
4749                  ## As if </noscript>                  ## As if </noscript>
4750                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4751                  !!!parse-error (type => 'in noscript:title', token => $token);                  !!!parse-error (type => 'in noscript', text => 'title',
4752                                    token => $token);
4753                                
4754                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4755                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4756                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4757                  !!!cp ('t112');                  !!!cp ('t112');
4758                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4759                                    text => $token->{tag_name}, token => $token);
4760                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4761                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4762                } else {                } else {
# Line 4133  sub _tree_construction_main ($) { Line 4770  sub _tree_construction_main ($) {
4770                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4771                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4772                next B;                next B;
4773              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style' or
4774                         $token->{tag_name} eq 'noframes') {
4775                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and
4776                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
4777                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4778                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4779                  !!!cp ('t114');                  !!!cp ('t114');
4780                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4781                                    text => $token->{tag_name}, token => $token);
4782                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4783                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4784                } else {                } else {
# Line 4160  sub _tree_construction_main ($) { Line 4799  sub _tree_construction_main ($) {
4799                  next B;                  next B;
4800                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4801                  !!!cp ('t117');                  !!!cp ('t117');
4802                  !!!parse-error (type => 'in noscript:noscript', token => $token);                  !!!parse-error (type => 'in noscript', text => 'noscript',
4803                                    token => $token);
4804                  ## Ignore the token                  ## Ignore the token
4805                  !!!nack ('t117.1');                  !!!nack ('t117.1');
4806                  !!!next-token;                  !!!next-token;
# Line 4174  sub _tree_construction_main ($) { Line 4814  sub _tree_construction_main ($) {
4814                  !!!cp ('t119');                  !!!cp ('t119');
4815                  ## As if </noscript>                  ## As if </noscript>
4816                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4817                  !!!parse-error (type => 'in noscript:script', token => $token);                  !!!parse-error (type => 'in noscript', text => 'script',
4818                                    token => $token);
4819                                
4820                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4821                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4822                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4823                  !!!cp ('t120');                  !!!cp ('t120');
4824                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4825                                    text => $token->{tag_name}, token => $token);
4826                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4827                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4828                } else {                } else {
# Line 4198  sub _tree_construction_main ($) { Line 4840  sub _tree_construction_main ($) {
4840                  !!!cp ('t122');                  !!!cp ('t122');
4841                  ## As if </noscript>                  ## As if </noscript>
4842                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4843                  !!!parse-error (type => 'in noscript:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in noscript',
4844                                    text => $token->{tag_name}, token => $token);
4845                                    
4846                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4847                  ## As if </head>                  ## As if </head>
# Line 4237  sub _tree_construction_main ($) { Line 4880  sub _tree_construction_main ($) {
4880                !!!cp ('t129');                !!!cp ('t129');
4881                ## As if </noscript>                ## As if </noscript>
4882                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4883                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4884                                  text => $token->{tag_name}, token => $token);
4885                                
4886                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4887                ## As if </head>                ## As if </head>
# Line 4280  sub _tree_construction_main ($) { Line 4924  sub _tree_construction_main ($) {
4924                  !!!cp ('t133');                  !!!cp ('t133');
4925                  ## As if </noscript>                  ## As if </noscript>
4926                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4927                  !!!parse-error (type => 'in noscript:/head', token => $token);                  !!!parse-error (type => 'in noscript:/',
4928                                    text => 'head', token => $token);
4929                                    
4930                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4931                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 4293  sub _tree_construction_main ($) { Line 4938  sub _tree_construction_main ($) {
4938                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
4939                  !!!next-token;                  !!!next-token;
4940                  next B;                  next B;
4941                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4942                    !!!cp ('t134.1');
4943                    !!!parse-error (type => 'unmatched end tag', text => 'head',
4944                                    token => $token);
4945                    ## Ignore the token
4946                    !!!next-token;
4947                    next B;
4948                } else {                } else {
4949                  !!!cp ('t135');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
                 #  
4950                }                }
4951              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
4952                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
# Line 4304  sub _tree_construction_main ($) { Line 4955  sub _tree_construction_main ($) {
4955                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4956                  !!!next-token;                  !!!next-token;
4957                  next B;                  next B;
4958                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or
4959                           $self->{insertion_mode} == AFTER_HEAD_IM) {
4960                  !!!cp ('t137');                  !!!cp ('t137');
4961                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4962                                    text => 'noscript', token => $token);
4963                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
4964                  !!!next-token;                  !!!next-token;
4965                  next B;                  next B;
# Line 4317  sub _tree_construction_main ($) { Line 4970  sub _tree_construction_main ($) {
4970              } elsif ({              } elsif ({
4971                        body => 1, html => 1,                        body => 1, html => 1,
4972                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4973                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM or
4974                  !!!cp ('t139');                    $self->{insertion_mode} == IN_HEAD_IM or
4975                  ## 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) {  
4976                  !!!cp ('t140');                  !!!cp ('t140');
4977                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4978                                    text => $token->{tag_name}, token => $token);
4979                    ## Ignore the token
4980                    !!!next-token;
4981                    next B;
4982                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4983                    !!!cp ('t140.1');
4984                    !!!parse-error (type => 'unmatched end tag',
4985                                    text => $token->{tag_name}, token => $token);
4986                  ## Ignore the token                  ## Ignore the token
4987                  !!!next-token;                  !!!next-token;
4988                  next B;                  next B;
4989                } else {                } else {
4990                  !!!cp ('t141');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
4991                }                }
4992                              } elsif ($token->{tag_name} eq 'p') {
4993                #                !!!cp ('t142');
4994              } elsif ({                !!!parse-error (type => 'unmatched end tag',
4995                        p => 1, br => 1,                                text => $token->{tag_name}, token => $token);
4996                       }->{$token->{tag_name}}) {                ## Ignore the token
4997                  !!!next-token;
4998                  next B;
4999                } elsif ($token->{tag_name} eq 'br') {
5000                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
5001                  !!!cp ('t142');                  !!!cp ('t142.2');
5002                  ## As if <head>                  ## (before head) as if <head>, (in head) as if </head>
5003                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
5004                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
5005                  push @{$self->{open_elements}},                  $self->{insertion_mode} = AFTER_HEAD_IM;
5006                      [$self->{head_element}, $el_category->{head}];    
5007                    ## Reprocess in the "after head" insertion mode...
5008                  } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
5009                    !!!cp ('t143.2');
5010                    ## As if </head>
5011                    pop @{$self->{open_elements}};
5012                    $self->{insertion_mode} = AFTER_HEAD_IM;
5013      
5014                    ## Reprocess in the "after head" insertion mode...
5015                  } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
5016                    !!!cp ('t143.3');
5017                    ## ISSUE: Two parse errors for <head><noscript></br>
5018                    !!!parse-error (type => 'unmatched end tag',
5019                                    text => 'br', token => $token);
5020                    ## As if </noscript>
5021                    pop @{$self->{open_elements}};
5022                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
5023    
5024                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
5025                } else {                  ## As if </head>
5026                  !!!cp ('t143');                  pop @{$self->{open_elements}};
5027                }                  $self->{insertion_mode} = AFTER_HEAD_IM;
5028    
5029                #                  ## Reprocess in the "after head" insertion mode...
5030              } else {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
5031                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                  !!!cp ('t143.4');
                 !!!cp ('t144');  
5032                  #                  #
5033                } else {                } else {
5034                  !!!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;  
5035                }                }
5036    
5037                  ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.
5038                  !!!parse-error (type => 'unmatched end tag',
5039                                  text => 'br', token => $token);
5040                  ## Ignore the token
5041                  !!!next-token;
5042                  next B;
5043                } else {
5044                  !!!cp ('t145');
5045                  !!!parse-error (type => 'unmatched end tag',
5046                                  text => $token->{tag_name}, token => $token);
5047                  ## Ignore the token
5048                  !!!next-token;
5049                  next B;
5050              }              }
5051    
5052              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
5053                !!!cp ('t146');                !!!cp ('t146');
5054                ## As if </noscript>                ## As if </noscript>
5055                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5056                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
5057                                  text => $token->{tag_name}, token => $token);
5058                                
5059                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
5060                ## As if </head>                ## As if </head>
# Line 4389  sub _tree_construction_main ($) { Line 5070  sub _tree_construction_main ($) {
5070              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
5071  ## ISSUE: This case cannot be reached?  ## ISSUE: This case cannot be reached?
5072                !!!cp ('t148');                !!!cp ('t148');
5073                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
5074                                  text => $token->{tag_name}, token => $token);
5075                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
5076                !!!next-token;                !!!next-token;
5077                next B;                next B;
# Line 4500  sub _tree_construction_main ($) { Line 5182  sub _tree_construction_main ($) {
5182    
5183                  !!!cp ('t153');                  !!!cp ('t153');
5184                  !!!parse-error (type => 'start tag not allowed',                  !!!parse-error (type => 'start tag not allowed',
5185                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
5186                  ## Ignore the token                  ## Ignore the token
5187                  !!!nack ('t153.1');                  !!!nack ('t153.1');
5188                  !!!next-token;                  !!!next-token;
5189                  next B;                  next B;
5190                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
5191                  !!!parse-error (type => 'not closed:caption', token => $token);                  !!!parse-error (type => 'not closed', text => 'caption',
5192                                    token => $token);
5193                                    
5194                  ## NOTE: As if </caption>.                  ## NOTE: As if </caption>.
5195                  ## have a table element in table scope                  ## have a table element in table scope
# Line 4526  sub _tree_construction_main ($) { Line 5209  sub _tree_construction_main ($) {
5209    
5210                    !!!cp ('t157');                    !!!cp ('t157');
5211                    !!!parse-error (type => 'start tag not allowed',                    !!!parse-error (type => 'start tag not allowed',
5212                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
5213                    ## Ignore the token                    ## Ignore the token
5214                    !!!nack ('t157.1');                    !!!nack ('t157.1');
5215                    !!!next-token;                    !!!next-token;
# Line 4543  sub _tree_construction_main ($) { Line 5226  sub _tree_construction_main ($) {
5226                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5227                    !!!cp ('t159');                    !!!cp ('t159');
5228                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5229                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5230                                        ->manakai_local_name,                                        ->manakai_local_name,
5231                                    token => $token);                                    token => $token);
5232                  } else {                  } else {
# Line 4585  sub _tree_construction_main ($) { Line 5268  sub _tree_construction_main ($) {
5268                  } # INSCOPE                  } # INSCOPE
5269                    unless (defined $i) {                    unless (defined $i) {
5270                      !!!cp ('t165');                      !!!cp ('t165');
5271                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5272                                        text => $token->{tag_name},
5273                                        token => $token);
5274                      ## Ignore the token                      ## Ignore the token
5275                      !!!next-token;                      !!!next-token;
5276                      next B;                      next B;
# Line 4602  sub _tree_construction_main ($) { Line 5287  sub _tree_construction_main ($) {
5287                          ne $token->{tag_name}) {                          ne $token->{tag_name}) {
5288                    !!!cp ('t167');                    !!!cp ('t167');
5289                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5290                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5291                                        ->manakai_local_name,                                        ->manakai_local_name,
5292                                    token => $token);                                    token => $token);
5293                  } else {                  } else {
# Line 4619  sub _tree_construction_main ($) { Line 5304  sub _tree_construction_main ($) {
5304                  next B;                  next B;
5305                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
5306                  !!!cp ('t169');                  !!!cp ('t169');
5307                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5308                                    text => $token->{tag_name}, token => $token);
5309                  ## Ignore the token                  ## Ignore the token
5310                  !!!next-token;                  !!!next-token;
5311                  next B;                  next B;
# Line 4646  sub _tree_construction_main ($) { Line 5332  sub _tree_construction_main ($) {
5332    
5333                    !!!cp ('t173');                    !!!cp ('t173');
5334                    !!!parse-error (type => 'unmatched end tag',                    !!!parse-error (type => 'unmatched end tag',
5335                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
5336                    ## Ignore the token                    ## Ignore the token
5337                    !!!next-token;                    !!!next-token;
5338                    next B;                    next B;
# Line 4662  sub _tree_construction_main ($) { Line 5348  sub _tree_construction_main ($) {
5348                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5349                    !!!cp ('t175');                    !!!cp ('t175');
5350                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5351                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5352                                        ->manakai_local_name,                                        ->manakai_local_name,
5353                                    token => $token);                                    token => $token);
5354                  } else {                  } else {
# Line 4679  sub _tree_construction_main ($) { Line 5365  sub _tree_construction_main ($) {
5365                  next B;                  next B;
5366                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
5367                  !!!cp ('t177');                  !!!cp ('t177');
5368                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5369                                    text => $token->{tag_name}, token => $token);
5370                  ## Ignore the token                  ## Ignore the token
5371                  !!!next-token;                  !!!next-token;
5372                  next B;                  next B;
# Line 4722  sub _tree_construction_main ($) { Line 5409  sub _tree_construction_main ($) {
5409    
5410                  !!!cp ('t182');                  !!!cp ('t182');
5411                  !!!parse-error (type => 'unmatched end tag',                  !!!parse-error (type => 'unmatched end tag',
5412                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
5413                  ## Ignore the token                  ## Ignore the token
5414                  !!!next-token;                  !!!next-token;
5415                  next B;                  next B;
5416                } # INSCOPE                } # INSCOPE
5417              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
5418                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5419                !!!parse-error (type => 'not closed:caption', token => $token);                !!!parse-error (type => 'not closed', text => 'caption',
5420                                  token => $token);
5421    
5422                ## As if </caption>                ## As if </caption>
5423                ## have a table element in table scope                ## have a table element in table scope
# Line 4747  sub _tree_construction_main ($) { Line 5435  sub _tree_construction_main ($) {
5435                } # INSCOPE                } # INSCOPE
5436                unless (defined $i) {                unless (defined $i) {
5437                  !!!cp ('t186');                  !!!cp ('t186');
5438                  !!!parse-error (type => 'unmatched end tag:caption', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5439                                    text => 'caption', token => $token);
5440                  ## Ignore the token                  ## Ignore the token
5441                  !!!next-token;                  !!!next-token;
5442                  next B;                  next B;
# Line 4762  sub _tree_construction_main ($) { Line 5451  sub _tree_construction_main ($) {
5451                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5452                  !!!cp ('t188');                  !!!cp ('t188');
5453                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5454                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5455                                      ->manakai_local_name,                                      ->manakai_local_name,
5456                                  token => $token);                                  token => $token);
5457                } else {                } else {
# Line 4782  sub _tree_construction_main ($) { Line 5471  sub _tree_construction_main ($) {
5471                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5472                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
5473                  !!!cp ('t190');                  !!!cp ('t190');
5474                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5475                                    text => $token->{tag_name}, token => $token);
5476                  ## Ignore the token                  ## Ignore the token
5477                  !!!next-token;                  !!!next-token;
5478                  next B;                  next B;
# Line 4796  sub _tree_construction_main ($) { Line 5486  sub _tree_construction_main ($) {
5486                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
5487                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5488                !!!cp ('t192');                !!!cp ('t192');
5489                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
5490                                  text => $token->{tag_name}, token => $token);
5491                ## Ignore the token                ## Ignore the token
5492                !!!next-token;                !!!next-token;
5493                next B;                next B;
# Line 4824  sub _tree_construction_main ($) { Line 5515  sub _tree_construction_main ($) {
5515      } elsif ($self->{insertion_mode} & TABLE_IMS) {      } elsif ($self->{insertion_mode} & TABLE_IMS) {
5516        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
5517          if (not $open_tables->[-1]->[1] and # tainted          if (not $open_tables->[-1]->[1] and # tainted
5518              $token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              $token->{data} =~ s/^([\x09\x0A\x0C\x20]+)//) {
5519            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
5520                                
5521            unless (length $token->{data}) {            unless (length $token->{data}) {
# Line 4836  sub _tree_construction_main ($) { Line 5527  sub _tree_construction_main ($) {
5527            }            }
5528          }          }
5529    
5530              !!!parse-error (type => 'in table:#character', token => $token);          !!!parse-error (type => 'in table:#text', token => $token);
5531    
5532              ## As if in body, but insert into foster parent element              ## As if in body, but insert into foster parent element
5533              ## ISSUE: Spec says that "whenever a node would be inserted              ## ISSUE: Spec says that "whenever a node would be inserted
# Line 4887  sub _tree_construction_main ($) { Line 5578  sub _tree_construction_main ($) {
5578          !!!next-token;          !!!next-token;
5579          next B;          next B;
5580        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5581              if ({          if ({
5582                   tr => ($self->{insertion_mode} != IN_ROW_IM),               tr => ($self->{insertion_mode} != IN_ROW_IM),
5583                   th => 1, td => 1,               th => 1, td => 1,
5584                  }->{$token->{tag_name}}) {              }->{$token->{tag_name}}) {
5585                if ($self->{insertion_mode} == IN_TABLE_IM) {            if ($self->{insertion_mode} == IN_TABLE_IM) {
5586                  ## Clear back to table context              ## Clear back to table context
5587                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5588                                  & TABLE_SCOPING_EL)) {                              & TABLE_SCOPING_EL)) {
5589                    !!!cp ('t201');                !!!cp ('t201');
5590                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5591                  }              }
5592                                
5593                  !!!insert-element ('tbody',, $token);              !!!insert-element ('tbody',, $token);
5594                  $self->{insertion_mode} = IN_TABLE_BODY_IM;              $self->{insertion_mode} = IN_TABLE_BODY_IM;
5595                  ## reprocess in the "in table body" insertion mode...              ## reprocess in the "in table body" insertion mode...
5596                }            }
5597              
5598                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {            if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
5599                  unless ($token->{tag_name} eq 'tr') {              unless ($token->{tag_name} eq 'tr') {
5600                    !!!cp ('t202');                !!!cp ('t202');
5601                    !!!parse-error (type => 'missing start tag:tr', token => $token);                !!!parse-error (type => 'missing start tag:tr', token => $token);
5602                  }              }
5603                                    
5604                  ## Clear back to table body context              ## Clear back to table body context
5605                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5606                                  & TABLE_ROWS_SCOPING_EL)) {                              & TABLE_ROWS_SCOPING_EL)) {
5607                    !!!cp ('t203');                !!!cp ('t203');
5608                    ## ISSUE: Can this case be reached?                ## ISSUE: Can this case be reached?
5609                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5610                  }              }
5611                                    
5612                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
5613                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
# Line 4972  sub _tree_construction_main ($) { Line 5663  sub _tree_construction_main ($) {
5663                  unless (defined $i) {                  unless (defined $i) {
5664                    !!!cp ('t210');                    !!!cp ('t210');
5665  ## TODO: This type is wrong.  ## TODO: This type is wrong.
5666                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmacthed end tag',
5667                                      text => $token->{tag_name}, token => $token);
5668                    ## Ignore the token                    ## Ignore the token
5669                    !!!nack ('t210.1');                    !!!nack ('t210.1');
5670                    !!!next-token;                    !!!next-token;
# Line 5016  sub _tree_construction_main ($) { Line 5708  sub _tree_construction_main ($) {
5708                  } # INSCOPE                  } # INSCOPE
5709                  unless (defined $i) {                  unless (defined $i) {
5710                    !!!cp ('t216');                    !!!cp ('t216');
5711  ## TODO: This erorr type ios wrong.  ## TODO: This erorr type is wrong.
5712                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5713                                      text => $token->{tag_name}, token => $token);
5714                    ## Ignore the token                    ## Ignore the token
5715                    !!!nack ('t216.1');                    !!!nack ('t216.1');
5716                    !!!next-token;                    !!!next-token;
# Line 5092  sub _tree_construction_main ($) { Line 5785  sub _tree_construction_main ($) {
5785                }                }
5786              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
5787                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
5788                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
5789                                    ->manakai_local_name,                                    ->manakai_local_name,
5790                                token => $token);                                token => $token);
5791    
# Line 5113  sub _tree_construction_main ($) { Line 5806  sub _tree_construction_main ($) {
5806                unless (defined $i) {                unless (defined $i) {
5807                  !!!cp ('t223');                  !!!cp ('t223');
5808  ## TODO: The following is wrong, maybe.  ## TODO: The following is wrong, maybe.
5809                  !!!parse-error (type => 'unmatched end tag:table', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'table',
5810                                    token => $token);
5811                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
5812                  !!!nack ('t223.1');                  !!!nack ('t223.1');
5813                  !!!next-token;                  !!!next-token;
5814                  next B;                  next B;
5815                }                }
5816                                
5817  ## TODO: Followings are removed from the latest spec.  ## TODO: Followings are removed from the latest spec.
5818                ## generate implied end tags                ## generate implied end tags
5819                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
5820                  !!!cp ('t224');                  !!!cp ('t224');
# Line 5131  sub _tree_construction_main ($) { Line 5825  sub _tree_construction_main ($) {
5825                  !!!cp ('t225');                  !!!cp ('t225');
5826                  ## NOTE: |<table><tr><table>|                  ## NOTE: |<table><tr><table>|
5827                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5828                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5829                                      ->manakai_local_name,                                      ->manakai_local_name,
5830                                  token => $token);                                  token => $token);
5831                } else {                } else {
# Line 5172  sub _tree_construction_main ($) { Line 5866  sub _tree_construction_main ($) {
5866                my $type = lc $token->{attributes}->{type}->{value};                my $type = lc $token->{attributes}->{type}->{value};
5867                if ($type eq 'hidden') {                if ($type eq 'hidden') {
5868                  !!!cp ('t227.3');                  !!!cp ('t227.3');
5869                  !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in table',
5870                                    text => $token->{tag_name}, token => $token);
5871    
5872                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5873    
# Line 5200  sub _tree_construction_main ($) { Line 5895  sub _tree_construction_main ($) {
5895            #            #
5896          }          }
5897    
5898          !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in table', text => $token->{tag_name},
5899                            token => $token);
5900    
5901          $insert = $insert_to_foster;          $insert = $insert_to_foster;
5902          #          #
# Line 5222  sub _tree_construction_main ($) { Line 5918  sub _tree_construction_main ($) {
5918                } # INSCOPE                } # INSCOPE
5919                unless (defined $i) {                unless (defined $i) {
5920                  !!!cp ('t230');                  !!!cp ('t230');
5921                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5922                                    text => $token->{tag_name}, token => $token);
5923                  ## Ignore the token                  ## Ignore the token
5924                  !!!nack ('t230.1');                  !!!nack ('t230.1');
5925                  !!!next-token;                  !!!next-token;
# Line 5263  sub _tree_construction_main ($) { Line 5960  sub _tree_construction_main ($) {
5960                  unless (defined $i) {                  unless (defined $i) {
5961                    !!!cp ('t235');                    !!!cp ('t235');
5962  ## TODO: The following is wrong.  ## TODO: The following is wrong.
5963                    !!!parse-error (type => 'unmatched end tag:'.$token->{type}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5964                                      text => $token->{type}, token => $token);
5965                    ## Ignore the token                    ## Ignore the token
5966                    !!!nack ('t236.1');                    !!!nack ('t236.1');
5967                    !!!next-token;                    !!!next-token;
# Line 5299  sub _tree_construction_main ($) { Line 5997  sub _tree_construction_main ($) {
5997                  } # INSCOPE                  } # INSCOPE
5998                  unless (defined $i) {                  unless (defined $i) {
5999                    !!!cp ('t239');                    !!!cp ('t239');
6000                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
6001                                      text => $token->{tag_name}, token => $token);
6002                    ## Ignore the token                    ## Ignore the token
6003                    !!!nack ('t239.1');                    !!!nack ('t239.1');
6004                    !!!next-token;                    !!!next-token;
# Line 5345  sub _tree_construction_main ($) { Line 6044  sub _tree_construction_main ($) {
6044                } # INSCOPE                } # INSCOPE
6045                unless (defined $i) {                unless (defined $i) {
6046                  !!!cp ('t243');                  !!!cp ('t243');
6047                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
6048                                    text => $token->{tag_name}, token => $token);
6049                  ## Ignore the token                  ## Ignore the token
6050                  !!!nack ('t243.1');                  !!!nack ('t243.1');
6051                  !!!next-token;                  !!!next-token;
# Line 5379  sub _tree_construction_main ($) { Line 6079  sub _tree_construction_main ($) {
6079                  } # INSCOPE                  } # INSCOPE
6080                    unless (defined $i) {                    unless (defined $i) {
6081                      !!!cp ('t249');                      !!!cp ('t249');
6082                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
6083                                        text => $token->{tag_name}, token => $token);
6084                      ## Ignore the token                      ## Ignore the token
6085                      !!!nack ('t249.1');                      !!!nack ('t249.1');
6086                      !!!next-token;                      !!!next-token;
# Line 5402  sub _tree_construction_main ($) { Line 6103  sub _tree_construction_main ($) {
6103                  } # INSCOPE                  } # INSCOPE
6104                    unless (defined $i) {                    unless (defined $i) {
6105                      !!!cp ('t252');                      !!!cp ('t252');
6106                      !!!parse-error (type => 'unmatched end tag:tr', token => $token);                      !!!parse-error (type => 'unmatched end tag',
6107                                        text => 'tr', token => $token);
6108                      ## Ignore the token                      ## Ignore the token
6109                      !!!nack ('t252.1');                      !!!nack ('t252.1');
6110                      !!!next-token;                      !!!next-token;
# Line 5437  sub _tree_construction_main ($) { Line 6139  sub _tree_construction_main ($) {
6139                } # INSCOPE                } # INSCOPE
6140                unless (defined $i) {                unless (defined $i) {
6141                  !!!cp ('t256');                  !!!cp ('t256');
6142                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
6143                                    text => $token->{tag_name}, token => $token);
6144                  ## Ignore the token                  ## Ignore the token
6145                  !!!nack ('t256.1');                  !!!nack ('t256.1');
6146                  !!!next-token;                  !!!next-token;
# Line 5464  sub _tree_construction_main ($) { Line 6167  sub _tree_construction_main ($) {
6167                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
6168                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
6169            !!!cp ('t258');            !!!cp ('t258');
6170            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
6171                              text => $token->{tag_name}, token => $token);
6172            ## Ignore the token            ## Ignore the token
6173            !!!nack ('t258.1');            !!!nack ('t258.1');
6174             !!!next-token;             !!!next-token;
6175            next B;            next B;
6176          } else {          } else {
6177            !!!cp ('t259');            !!!cp ('t259');
6178            !!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in table:/',
6179                              text => $token->{tag_name}, token => $token);
6180    
6181            $insert = $insert_to_foster;            $insert = $insert_to_foster;
6182            #            #
# Line 5494  sub _tree_construction_main ($) { Line 6199  sub _tree_construction_main ($) {
6199        }        }
6200      } elsif ($self->{insertion_mode} == IN_COLUMN_GROUP_IM) {      } elsif ($self->{insertion_mode} == IN_COLUMN_GROUP_IM) {
6201            if ($token->{type} == CHARACTER_TOKEN) {            if ($token->{type} == CHARACTER_TOKEN) {
6202              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0C\x20]+)//) {
6203                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
6204                unless (length $token->{data}) {                unless (length $token->{data}) {
6205                  !!!cp ('t260');                  !!!cp ('t260');
# Line 5521  sub _tree_construction_main ($) { Line 6226  sub _tree_construction_main ($) {
6226              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
6227                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
6228                  !!!cp ('t264');                  !!!cp ('t264');
6229                  !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);                  !!!parse-error (type => 'unmatched end tag',
6230                                    text => 'colgroup', token => $token);
6231                  ## Ignore the token                  ## Ignore the token
6232                  !!!next-token;                  !!!next-token;
6233                  next B;                  next B;
# Line 5534  sub _tree_construction_main ($) { Line 6240  sub _tree_construction_main ($) {
6240                }                }
6241              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
6242                !!!cp ('t266');                !!!cp ('t266');
6243                !!!parse-error (type => 'unmatched end tag:col', token => $token);                !!!parse-error (type => 'unmatched end tag',
6244                                  text => 'col', token => $token);
6245                ## Ignore the token                ## Ignore the token
6246                !!!next-token;                !!!next-token;
6247                next B;                next B;
# Line 5564  sub _tree_construction_main ($) { Line 6271  sub _tree_construction_main ($) {
6271            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
6272              !!!cp ('t269');              !!!cp ('t269');
6273  ## TODO: Wrong error type?  ## TODO: Wrong error type?
6274              !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);              !!!parse-error (type => 'unmatched end tag',
6275                                text => 'colgroup', token => $token);
6276              ## Ignore the token              ## Ignore the token
6277              !!!nack ('t269.1');              !!!nack ('t269.1');
6278              !!!next-token;              !!!next-token;
# Line 5618  sub _tree_construction_main ($) { Line 6326  sub _tree_construction_main ($) {
6326            !!!nack ('t277.1');            !!!nack ('t277.1');
6327            !!!next-token;            !!!next-token;
6328            next B;            next B;
6329          } elsif ($token->{tag_name} eq 'select' or          } elsif ({
6330                   $token->{tag_name} eq 'input' or                     select => 1, input => 1, textarea => 1,
6331                     }->{$token->{tag_name}} or
6332                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
6333                    {                    {
6334                     caption => 1, table => 1,                     caption => 1, table => 1,
# Line 5627  sub _tree_construction_main ($) { Line 6336  sub _tree_construction_main ($) {
6336                     tr => 1, td => 1, th => 1,                     tr => 1, td => 1, th => 1,
6337                    }->{$token->{tag_name}})) {                    }->{$token->{tag_name}})) {
6338            ## TODO: The type below is not good - <select> is replaced by </select>            ## TODO: The type below is not good - <select> is replaced by </select>
6339            !!!parse-error (type => 'not closed:select', token => $token);            !!!parse-error (type => 'not closed', text => 'select',
6340                              token => $token);
6341            ## NOTE: As if the token were </select> (<select> case) or            ## NOTE: As if the token were </select> (<select> case) or
6342            ## as if there were </select> (otherwise).            ## as if there were </select> (otherwise).
6343            ## have an element in table scope            ## have an element in table scope
# Line 5645  sub _tree_construction_main ($) { Line 6355  sub _tree_construction_main ($) {
6355            } # INSCOPE            } # INSCOPE
6356            unless (defined $i) {            unless (defined $i) {
6357              !!!cp ('t280');              !!!cp ('t280');
6358              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6359                                text => 'select', token => $token);
6360              ## Ignore the token              ## Ignore the token
6361              !!!nack ('t280.1');              !!!nack ('t280.1');
6362              !!!next-token;              !!!next-token;
# Line 5669  sub _tree_construction_main ($) { Line 6380  sub _tree_construction_main ($) {
6380            }            }
6381          } else {          } else {
6382            !!!cp ('t282');            !!!cp ('t282');
6383            !!!parse-error (type => 'in select:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select',
6384                              text => $token->{tag_name}, token => $token);
6385            ## Ignore the token            ## Ignore the token
6386            !!!nack ('t282.1');            !!!nack ('t282.1');
6387            !!!next-token;            !!!next-token;
# Line 5687  sub _tree_construction_main ($) { Line 6399  sub _tree_construction_main ($) {
6399              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6400            } else {            } else {
6401              !!!cp ('t285');              !!!cp ('t285');
6402              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6403                                text => $token->{tag_name}, token => $token);
6404              ## Ignore the token              ## Ignore the token
6405            }            }
6406            !!!nack ('t285.1');            !!!nack ('t285.1');
# Line 5699  sub _tree_construction_main ($) { Line 6412  sub _tree_construction_main ($) {
6412              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6413            } else {            } else {
6414              !!!cp ('t287');              !!!cp ('t287');
6415              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6416                                text => $token->{tag_name}, token => $token);
6417              ## Ignore the token              ## Ignore the token
6418            }            }
6419            !!!nack ('t287.1');            !!!nack ('t287.1');
# Line 5721  sub _tree_construction_main ($) { Line 6435  sub _tree_construction_main ($) {
6435            } # INSCOPE            } # INSCOPE
6436            unless (defined $i) {            unless (defined $i) {
6437              !!!cp ('t290');              !!!cp ('t290');
6438              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6439                                text => $token->{tag_name}, token => $token);
6440              ## Ignore the token              ## Ignore the token
6441              !!!nack ('t290.1');              !!!nack ('t290.1');
6442              !!!next-token;              !!!next-token;
# Line 5742  sub _tree_construction_main ($) { Line 6457  sub _tree_construction_main ($) {
6457                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
6458                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
6459  ## TODO: The following is wrong?  ## TODO: The following is wrong?
6460            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
6461                              text => $token->{tag_name}, token => $token);
6462                                
6463            ## have an element in table scope            ## have an element in table scope
6464            my $i;            my $i;
# Line 5783  sub _tree_construction_main ($) { Line 6499  sub _tree_construction_main ($) {
6499            unless (defined $i) {            unless (defined $i) {
6500              !!!cp ('t297');              !!!cp ('t297');
6501  ## TODO: The following error type is correct?  ## TODO: The following error type is correct?
6502              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6503                                text => 'select', token => $token);
6504              ## Ignore the </select> token              ## Ignore the </select> token
6505              !!!nack ('t297.1');              !!!nack ('t297.1');
6506              !!!next-token; ## TODO: ok?              !!!next-token; ## TODO: ok?
# Line 5800  sub _tree_construction_main ($) { Line 6517  sub _tree_construction_main ($) {
6517            next B;            next B;
6518          } else {          } else {
6519            !!!cp ('t299');            !!!cp ('t299');
6520            !!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select:/',
6521                              text => $token->{tag_name}, token => $token);
6522            ## Ignore the token            ## Ignore the token
6523            !!!nack ('t299.3');            !!!nack ('t299.3');
6524            !!!next-token;            !!!next-token;
# Line 5822  sub _tree_construction_main ($) { Line 6540  sub _tree_construction_main ($) {
6540        }        }
6541      } elsif ($self->{insertion_mode} & BODY_AFTER_IMS) {      } elsif ($self->{insertion_mode} & BODY_AFTER_IMS) {
6542        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
6543          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0C\x20]+)//) {
6544            my $data = $1;            my $data = $1;
6545            ## As if in body            ## As if in body
6546            $reconstruct_active_formatting_elements->($insert_to_current);            $reconstruct_active_formatting_elements->($insert_to_current);
# Line 5838  sub _tree_construction_main ($) { Line 6556  sub _tree_construction_main ($) {
6556                    
6557          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6558            !!!cp ('t301');            !!!cp ('t301');
6559            !!!parse-error (type => 'after html:#character', token => $token);            !!!parse-error (type => 'after html:#text', token => $token);
6560              #
           ## Reprocess in the "after body" insertion mode.  
6561          } else {          } else {
6562            !!!cp ('t302');            !!!cp ('t302');
6563              ## "after body" insertion mode
6564              !!!parse-error (type => 'after body:#text', token => $token);
6565              #
6566          }          }
           
         ## "after body" insertion mode  
         !!!parse-error (type => 'after body:#character', token => $token);  
6567    
6568          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6569          ## reprocess          ## reprocess
# Line 5854  sub _tree_construction_main ($) { Line 6571  sub _tree_construction_main ($) {
6571        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
6572          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6573            !!!cp ('t303');            !!!cp ('t303');
6574            !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html',
6575                                        text => $token->{tag_name}, token => $token);
6576            ## Reprocess in the "after body" insertion mode.            #
6577          } else {          } else {
6578            !!!cp ('t304');            !!!cp ('t304');
6579              ## "after body" insertion mode
6580              !!!parse-error (type => 'after body',
6581                              text => $token->{tag_name}, token => $token);
6582              #
6583          }          }
6584    
         ## "after body" insertion mode  
         !!!parse-error (type => 'after body:'.$token->{tag_name}, token => $token);  
   
6585          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6586          !!!ack-later;          !!!ack-later;
6587          ## reprocess          ## reprocess
# Line 5871  sub _tree_construction_main ($) { Line 6589  sub _tree_construction_main ($) {
6589        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6590          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6591            !!!cp ('t305');            !!!cp ('t305');
6592            !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html:/',
6593                              text => $token->{tag_name}, token => $token);
6594                        
6595            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
6596            ## Reprocess in the "after body" insertion mode.            ## Reprocess.
6597              next B;
6598          } else {          } else {
6599            !!!cp ('t306');            !!!cp ('t306');
6600          }          }
# Line 5883  sub _tree_construction_main ($) { Line 6603  sub _tree_construction_main ($) {
6603          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
6604            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
6605              !!!cp ('t307');              !!!cp ('t307');
6606              !!!parse-error (type => 'unmatched end tag:html', token => $token);              !!!parse-error (type => 'unmatched end tag',
6607                                text => 'html', token => $token);
6608              ## Ignore the token              ## Ignore the token
6609              !!!next-token;              !!!next-token;
6610              next B;              next B;
# Line 5895  sub _tree_construction_main ($) { Line 6616  sub _tree_construction_main ($) {
6616            }            }
6617          } else {          } else {
6618            !!!cp ('t309');            !!!cp ('t309');
6619            !!!parse-error (type => 'after body:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after body:/',
6620                              text => $token->{tag_name}, token => $token);
6621    
6622            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
6623            ## reprocess            ## reprocess
# Line 5910  sub _tree_construction_main ($) { Line 6632  sub _tree_construction_main ($) {
6632        }        }
6633      } elsif ($self->{insertion_mode} & FRAME_IMS) {      } elsif ($self->{insertion_mode} & FRAME_IMS) {
6634        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
6635          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0C\x20]+)//) {
6636            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
6637                        
6638            unless (length $token->{data}) {            unless (length $token->{data}) {
# Line 5920  sub _tree_construction_main ($) { Line 6642  sub _tree_construction_main ($) {
6642            }            }
6643          }          }
6644                    
6645          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0C\x20]+//) {
6646            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6647              !!!cp ('t311');              !!!cp ('t311');
6648              !!!parse-error (type => 'in frameset:#character', token => $token);              !!!parse-error (type => 'in frameset:#text', token => $token);
6649            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6650              !!!cp ('t312');              !!!cp ('t312');
6651              !!!parse-error (type => 'after frameset:#character', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6652            } else { # "after html frameset"            } else { # "after after frameset"
6653              !!!cp ('t313');              !!!cp ('t313');
6654              !!!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);  
6655            }            }
6656                        
6657            ## Ignore the token.            ## Ignore the token.
# Line 5949  sub _tree_construction_main ($) { Line 6667  sub _tree_construction_main ($) {
6667                    
6668          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
6669        } 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');  
         }  
   
6670          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6671              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6672            !!!cp ('t318');            !!!cp ('t318');
# Line 5976  sub _tree_construction_main ($) { Line 6684  sub _tree_construction_main ($) {
6684            next B;            next B;
6685          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
6686            !!!cp ('t320');            !!!cp ('t320');
6687            ## NOTE: As if in body.            ## NOTE: As if in head.
6688            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
6689            next B;            next B;
6690    
6691              ## NOTE: |<!DOCTYPE HTML><frameset></frameset></html><noframes></noframes>|
6692              ## has no parse error.
6693          } else {          } else {
6694            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6695              !!!cp ('t321');              !!!cp ('t321');
6696              !!!parse-error (type => 'in frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset',
6697            } else {                              text => $token->{tag_name}, token => $token);
6698              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6699              !!!cp ('t322');              !!!cp ('t322');
6700              !!!parse-error (type => 'after frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after frameset',
6701                                text => $token->{tag_name}, token => $token);
6702              } else { # "after after frameset"
6703                !!!cp ('t322.2');
6704                !!!parse-error (type => 'after after frameset',
6705                                text => $token->{tag_name}, token => $token);
6706            }            }
6707            ## Ignore the token            ## Ignore the token
6708            !!!nack ('t322.1');            !!!nack ('t322.1');
# Line 5993  sub _tree_construction_main ($) { Line 6710  sub _tree_construction_main ($) {
6710            next B;            next B;
6711          }          }
6712        } 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');  
         }  
   
6713          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6714              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6715            if ($self->{open_elements}->[-1]->[1] & HTML_EL and            if ($self->{open_elements}->[-1]->[1] & HTML_EL and
6716                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
6717              !!!cp ('t325');              !!!cp ('t325');
6718              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6719                                text => $token->{tag_name}, token => $token);
6720              ## Ignore the token              ## Ignore the token
6721              !!!next-token;              !!!next-token;
6722            } else {            } else {
# Line 6034  sub _tree_construction_main ($) { Line 6742  sub _tree_construction_main ($) {
6742          } else {          } else {
6743            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6744              !!!cp ('t330');              !!!cp ('t330');
6745              !!!parse-error (type => 'in frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset:/',
6746            } else {                              text => $token->{tag_name}, token => $token);
6747              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6748                !!!cp ('t330.1');
6749                !!!parse-error (type => 'after frameset:/',
6750                                text => $token->{tag_name}, token => $token);
6751              } else { # "after after html"
6752              !!!cp ('t331');              !!!cp ('t331');
6753              !!!parse-error (type => 'after frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after after frameset:/',
6754                                text => $token->{tag_name}, token => $token);
6755            }            }
6756            ## Ignore the token            ## Ignore the token
6757            !!!next-token;            !!!next-token;
# Line 6091  sub _tree_construction_main ($) { Line 6805  sub _tree_construction_main ($) {
6805          my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.          my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
6806    
6807          unless ($self->{confident}) {          unless ($self->{confident}) {
6808            if ($token->{attributes}->{charset}) { ## TODO: And if supported            if ($token->{attributes}->{charset}) {
6809              !!!cp ('t335');              !!!cp ('t335');
6810                ## NOTE: Whether the encoding is supported or not is handled
6811                ## in the {change_encoding} callback.
6812              $self->{change_encoding}              $self->{change_encoding}
6813                  ->($self, $token->{attributes}->{charset}->{value}, $token);                  ->($self, $token->{attributes}->{charset}->{value}, $token);
6814                            
# Line 6101  sub _tree_construction_main ($) { Line 6817  sub _tree_construction_main ($) {
6817                                       $token->{attributes}->{charset}                                       $token->{attributes}->{charset}
6818                                           ->{has_reference});                                           ->{has_reference});
6819            } elsif ($token->{attributes}->{content}) {            } elsif ($token->{attributes}->{content}) {
             ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.  
6820              if ($token->{attributes}->{content}->{value}              if ($token->{attributes}->{content}->{value}
6821                  =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                  =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
6822                      [\x09-\x0D\x20]*=                      [\x09\x0A\x0C\x0D\x20]*=
6823                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                      [\x09\x0A\x0C\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
6824                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                      ([^"'\x09\x0A\x0C\x0D\x20][^\x09\x0A\x0C\x0D\x20\x3B]*))
6825                       /x) {
6826                !!!cp ('t336');                !!!cp ('t336');
6827                  ## NOTE: Whether the encoding is supported or not is handled
6828                  ## in the {change_encoding} callback.
6829                $self->{change_encoding}                $self->{change_encoding}
6830                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3, $token);                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3, $token);
6831                $meta_el->[0]->get_attribute_node_ns (undef, 'content')                $meta_el->[0]->get_attribute_node_ns (undef, 'content')
# Line 6142  sub _tree_construction_main ($) { Line 6860  sub _tree_construction_main ($) {
6860          $parse_rcdata->(RCDATA_CONTENT_MODEL);          $parse_rcdata->(RCDATA_CONTENT_MODEL);
6861          next B;          next B;
6862        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
6863          !!!parse-error (type => 'in body:body', token => $token);          !!!parse-error (type => 'in body', text => 'body', token => $token);
6864                                
6865          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
6866              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {
# Line 6262  sub _tree_construction_main ($) { Line 6980  sub _tree_construction_main ($) {
6980              if ($i != -1) {              if ($i != -1) {
6981                !!!cp ('t355');                !!!cp ('t355');
6982                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
6983                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
6984                                    ->manakai_local_name,                                    ->manakai_local_name,
6985                                token => $token);                                token => $token);
6986              } else {              } else {
# Line 6416  sub _tree_construction_main ($) { Line 7134  sub _tree_construction_main ($) {
7134                  xmp => 1,                  xmp => 1,
7135                  iframe => 1,                  iframe => 1,
7136                  noembed => 1,                  noembed => 1,
7137                  noframes => 1,                  noframes => 1, ## NOTE: This is an "as if in head" code clone.
7138                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
7139                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7140          if ($token->{tag_name} eq 'xmp') {          if ($token->{tag_name} eq 'xmp') {
# Line 6438  sub _tree_construction_main ($) { Line 7156  sub _tree_construction_main ($) {
7156            !!!next-token;            !!!next-token;
7157            next B;            next B;
7158          } else {          } else {
7159              !!!ack ('t391.1');
7160    
7161            my $at = $token->{attributes};            my $at = $token->{attributes};
7162            my $form_attrs;            my $form_attrs;
7163            $form_attrs->{action} = $at->{action} if $at->{action};            $form_attrs->{action} = $at->{action} if $at->{action};
# Line 6481  sub _tree_construction_main ($) { Line 7201  sub _tree_construction_main ($) {
7201                           line => $token->{line}, column => $token->{column}},                           line => $token->{line}, column => $token->{column}},
7202                          {type => END_TAG_TOKEN, tag_name => 'form',                          {type => END_TAG_TOKEN, tag_name => 'form',
7203                           line => $token->{line}, column => $token->{column}};                           line => $token->{line}, column => $token->{column}};
           !!!nack ('t391.1'); ## NOTE: Not acknowledged.  
7204            !!!back-token (@tokens);            !!!back-token (@tokens);
7205            !!!next-token;            !!!next-token;
7206            next B;            next B;
# Line 6529  sub _tree_construction_main ($) { Line 7248  sub _tree_construction_main ($) {
7248            ## Ignore the token            ## Ignore the token
7249          } else {          } else {
7250            !!!cp ('t398');            !!!cp ('t398');
7251            !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);            !!!parse-error (type => 'in RCDATA:#eof', token => $token);
7252          }          }
7253          !!!next-token;          !!!next-token;
7254          next B;          next B;
7255          } elsif ($token->{tag_name} eq 'rt' or
7256                   $token->{tag_name} eq 'rp') {
7257            ## has a |ruby| element in scope
7258            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
7259              my $node = $self->{open_elements}->[$_];
7260              if ($node->[1] & RUBY_EL) {
7261                !!!cp ('t398.1');
7262                ## generate implied end tags
7263                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7264                  !!!cp ('t398.2');
7265                  pop @{$self->{open_elements}};
7266                }
7267                unless ($self->{open_elements}->[-1]->[1] & RUBY_EL) {
7268                  !!!cp ('t398.3');
7269                  !!!parse-error (type => 'not closed',
7270                                  text => $self->{open_elements}->[-1]->[0]
7271                                      ->manakai_local_name,
7272                                  token => $token);
7273                  pop @{$self->{open_elements}}
7274                      while not $self->{open_elements}->[-1]->[1] & RUBY_EL;
7275                }
7276                last INSCOPE;
7277              } elsif ($node->[1] & SCOPING_EL) {
7278                !!!cp ('t398.4');
7279                last INSCOPE;
7280              }
7281            } # INSCOPE
7282    
7283            !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
7284    
7285            !!!nack ('t398.5');
7286            !!!next-token;
7287            redo B;
7288        } elsif ($token->{tag_name} eq 'math' or        } elsif ($token->{tag_name} eq 'math' or
7289                 $token->{tag_name} eq 'svg') {                 $token->{tag_name} eq 'svg') {
7290          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
7291    
7292            ## "Adjust MathML attributes" ('math' only) - done in insert-element-f
7293    
7294          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f
7295    
7296          ## "adjust foreign attributes" - done in insert-element-f          ## "adjust foreign attributes" - done in insert-element-f
# Line 6563  sub _tree_construction_main ($) { Line 7317  sub _tree_construction_main ($) {
7317                  thead => 1, tr => 1,                  thead => 1, tr => 1,
7318                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7319          !!!cp ('t401');          !!!cp ('t401');
7320          !!!parse-error (type => 'in body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in body',
7321                            text => $token->{tag_name}, token => $token);
7322          ## Ignore the token          ## Ignore the token
7323          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.
7324          !!!next-token;          !!!next-token;
# Line 6648  sub _tree_construction_main ($) { Line 7403  sub _tree_construction_main ($) {
7403            }            }
7404    
7405            !!!parse-error (type => 'start tag not allowed',            !!!parse-error (type => 'start tag not allowed',
7406                            value => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7407            ## NOTE: Ignore the token.            ## NOTE: Ignore the token.
7408            !!!next-token;            !!!next-token;
7409            next B;            next B;
# Line 6658  sub _tree_construction_main ($) { Line 7413  sub _tree_construction_main ($) {
7413            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {
7414              !!!cp ('t403');              !!!cp ('t403');
7415              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7416                              value => $_->[0]->manakai_local_name,                              text => $_->[0]->manakai_local_name,
7417                              token => $token);                              token => $token);
7418              last;              last;
7419            } else {            } else {
# Line 6678  sub _tree_construction_main ($) { Line 7433  sub _tree_construction_main ($) {
7433            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {
7434              !!!cp ('t406');              !!!cp ('t406');
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 6689  sub _tree_construction_main ($) { Line 7444  sub _tree_construction_main ($) {
7444            next B;            next B;
7445          } else {          } else {
7446            !!!cp ('t408');            !!!cp ('t408');
7447            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7448                              text => $token->{tag_name}, token => $token);
7449            ## Ignore the token            ## Ignore the token
7450            !!!next-token;            !!!next-token;
7451            next B;            next B;
# Line 6717  sub _tree_construction_main ($) { Line 7473  sub _tree_construction_main ($) {
7473    
7474          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7475            !!!cp ('t413');            !!!cp ('t413');
7476            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7477                              text => $token->{tag_name}, token => $token);
7478              ## NOTE: Ignore the token.
7479          } else {          } else {
7480            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7481            while ({            while ({
7482                      ## END_TAG_OPTIONAL_EL
7483                    dd => ($token->{tag_name} ne 'dd'),                    dd => ($token->{tag_name} ne 'dd'),
7484                    dt => ($token->{tag_name} ne 'dt'),                    dt => ($token->{tag_name} ne 'dt'),
7485                    li => ($token->{tag_name} ne 'li'),                    li => ($token->{tag_name} ne 'li'),
7486                    p => 1,                    p => 1,
7487                      rt => 1,
7488                      rp => 1,
7489                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {
7490              !!!cp ('t409');              !!!cp ('t409');
7491              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
# Line 6735  sub _tree_construction_main ($) { Line 7496  sub _tree_construction_main ($) {
7496                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7497              !!!cp ('t412');              !!!cp ('t412');
7498              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7499                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7500                                  ->manakai_local_name,                                  ->manakai_local_name,
7501                              token => $token);                              token => $token);
7502            } else {            } else {
# Line 6772  sub _tree_construction_main ($) { Line 7533  sub _tree_construction_main ($) {
7533    
7534          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7535            !!!cp ('t421');            !!!cp ('t421');
7536            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7537                              text => $token->{tag_name}, token => $token);
7538              ## NOTE: Ignore the token.
7539          } else {          } else {
7540            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7541            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 6785  sub _tree_construction_main ($) { Line 7548  sub _tree_construction_main ($) {
7548                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7549              !!!cp ('t417.1');              !!!cp ('t417.1');
7550              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7551                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7552                                  ->manakai_local_name,                                  ->manakai_local_name,
7553                              token => $token);                              token => $token);
7554            } else {            } else {
# Line 6817  sub _tree_construction_main ($) { Line 7580  sub _tree_construction_main ($) {
7580    
7581          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7582            !!!cp ('t425.1');            !!!cp ('t425.1');
7583            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7584                              text => $token->{tag_name}, token => $token);
7585              ## NOTE: Ignore the token.
7586          } else {          } else {
7587            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7588            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 6829  sub _tree_construction_main ($) { Line 7594  sub _tree_construction_main ($) {
7594            if ($self->{open_elements}->[-1]->[0]->manakai_local_name            if ($self->{open_elements}->[-1]->[0]->manakai_local_name
7595                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7596              !!!cp ('t425');              !!!cp ('t425');
7597              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
7598                                text => $token->{tag_name}, token => $token);
7599            } else {            } else {
7600              !!!cp ('t426');              !!!cp ('t426');
7601            }            }
# Line 6860  sub _tree_construction_main ($) { Line 7626  sub _tree_construction_main ($) {
7626                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7627              !!!cp ('t412.1');              !!!cp ('t412.1');
7628              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7629                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7630                                  ->manakai_local_name,                                  ->manakai_local_name,
7631                              token => $token);                              token => $token);
7632            } else {            } else {
# Line 6870  sub _tree_construction_main ($) { Line 7636  sub _tree_construction_main ($) {
7636            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
7637          } else {          } else {
7638            !!!cp ('t413.1');            !!!cp ('t413.1');
7639            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7640                              text => $token->{tag_name}, token => $token);
7641    
7642            !!!cp ('t415.1');            !!!cp ('t415.1');
7643            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
# Line 6893  sub _tree_construction_main ($) { Line 7660  sub _tree_construction_main ($) {
7660          next B;          next B;
7661        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
7662          !!!cp ('t428');          !!!cp ('t428');
7663          !!!parse-error (type => 'unmatched end tag:br', token => $token);          !!!parse-error (type => 'unmatched end tag',
7664                            text => 'br', token => $token);
7665    
7666          ## As if <br>          ## As if <br>
7667          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
# Line 6918  sub _tree_construction_main ($) { Line 7686  sub _tree_construction_main ($) {
7686                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
7687                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7688          !!!cp ('t429');          !!!cp ('t429');
7689          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'unmatched end tag',
7690                            text => $token->{tag_name}, token => $token);
7691          ## Ignore the token          ## Ignore the token
7692          !!!next-token;          !!!next-token;
7693          next B;          next B;
# Line 6937  sub _tree_construction_main ($) { Line 7706  sub _tree_construction_main ($) {
7706              ## generate implied end tags              ## generate implied end tags
7707              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7708                !!!cp ('t430');                !!!cp ('t430');
7709                ## ISSUE: Can this case be reached?                ## NOTE: |<ruby><rt></ruby>|.
7710                  ## ISSUE: <ruby><rt></rt> will also take this code path,
7711                  ## which seems wrong.
7712                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
7713                  $node_i++;
7714              }              }
7715                    
7716              ## Step 2              ## Step 2
# Line 6947  sub _tree_construction_main ($) { Line 7719  sub _tree_construction_main ($) {
7719                !!!cp ('t431');                !!!cp ('t431');
7720                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
7721                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
7722                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
7723                                    ->manakai_local_name,                                    ->manakai_local_name,
7724                                token => $token);                                token => $token);
7725              } else {              } else {
# Line 6955  sub _tree_construction_main ($) { Line 7727  sub _tree_construction_main ($) {
7727              }              }
7728                            
7729              ## Step 3              ## Step 3
7730              splice @{$self->{open_elements}}, $node_i;              splice @{$self->{open_elements}}, $node_i if $node_i < 0;
7731    
7732              !!!next-token;              !!!next-token;
7733              last S2;              last S2;
# Line 6966  sub _tree_construction_main ($) { Line 7738  sub _tree_construction_main ($) {
7738                  ($node->[1] & SPECIAL_EL or                  ($node->[1] & SPECIAL_EL or
7739                   $node->[1] & SCOPING_EL)) {                   $node->[1] & SCOPING_EL)) {
7740                !!!cp ('t433');                !!!cp ('t433');
7741                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
7742                                  text => $token->{tag_name}, token => $token);
7743                ## Ignore the token                ## Ignore the token
7744                !!!next-token;                !!!next-token;
7745                last S2;                last S2;
# Line 7012  sub _tree_construction_main ($) { Line 7785  sub _tree_construction_main ($) {
7785    ## TODO: script stuffs    ## TODO: script stuffs
7786  } # _tree_construct_main  } # _tree_construct_main
7787    
7788  sub set_inner_html ($$$) {  sub set_inner_html ($$$$;$) {
7789    my $class = shift;    my $class = shift;
7790    my $node = shift;    my $node = shift;
7791    my $s = \$_[0];    #my $s = \$_[0];
7792    my $onerror = $_[1];    my $onerror = $_[1];
7793      my $get_wrapper = $_[2] || sub ($) { return $_[0] };
7794    
7795    ## ISSUE: Should {confident} be true?    ## ISSUE: Should {confident} be true?
7796    
# Line 7035  sub set_inner_html ($$$) { Line 7809  sub set_inner_html ($$$) {
7809      }      }
7810    
7811      ## Step 3, 4, 5 # MUST      ## Step 3, 4, 5 # MUST
7812      $class->parse_string ($$s => $node, $onerror);      $class->parse_char_string ($_[0] => $node, $onerror, $get_wrapper);
7813    } elsif ($nt == 1) {    } elsif ($nt == 1) {
7814      ## TODO: If non-html element      ## TODO: If non-html element
7815    
7816      ## NOTE: Most of this code is copied from |parse_string|      ## NOTE: Most of this code is copied from |parse_string|
7817    
7818    ## TODO: Support for $get_wrapper
7819    
7820      ## Step 1 # MUST      ## Step 1 # MUST
7821      my $this_doc = $node->owner_document;      my $this_doc = $node->owner_document;
7822      my $doc = $this_doc->implementation->create_document;      my $doc = $this_doc->implementation->create_document;
# Line 7052  sub set_inner_html ($$$) { Line 7828  sub set_inner_html ($$$) {
7828      my $i = 0;      my $i = 0;
7829      $p->{line_prev} = $p->{line} = 1;      $p->{line_prev} = $p->{line} = 1;
7830      $p->{column_prev} = $p->{column} = 0;      $p->{column_prev} = $p->{column} = 0;
7831      $p->{set_next_char} = sub {      require Whatpm::Charset::DecodeHandle;
7832        my $input = Whatpm::Charset::DecodeHandle::CharString->new (\($_[0]));
7833        $input = $get_wrapper->($input);
7834        $p->{set_nc} = sub {
7835        my $self = shift;        my $self = shift;
7836    
7837        pop @{$self->{prev_char}};        my $char = '';
7838        unshift @{$self->{prev_char}}, $self->{next_char};        if (defined $self->{next_nc}) {
7839            $char = $self->{next_nc};
7840        $self->{next_char} = -1 and return if $i >= length $$s;          delete $self->{next_nc};
7841        $self->{next_char} = ord substr $$s, $i++, 1;          $self->{nc} = ord $char;
7842          } else {
7843            $self->{char_buffer} = '';
7844            $self->{char_buffer_pos} = 0;
7845            
7846            my $count = $input->manakai_read_until
7847                ($self->{char_buffer}, qr/[^\x00\x0A\x0D]/,
7848                 $self->{char_buffer_pos});
7849            if ($count) {
7850              $self->{line_prev} = $self->{line};
7851              $self->{column_prev} = $self->{column};
7852              $self->{column}++;
7853              $self->{nc}
7854                  = ord substr ($self->{char_buffer},
7855                                $self->{char_buffer_pos}++, 1);
7856              return;
7857            }
7858            
7859            if ($input->read ($char, 1)) {
7860              $self->{nc} = ord $char;
7861            } else {
7862              $self->{nc} = -1;
7863              return;
7864            }
7865          }
7866    
7867        ($p->{line_prev}, $p->{column_prev}) = ($p->{line}, $p->{column});        ($p->{line_prev}, $p->{column_prev}) = ($p->{line}, $p->{column});
7868        $p->{column}++;        $p->{column}++;
7869    
7870        if ($self->{next_char} == 0x000A) { # LF        if ($self->{nc} == 0x000A) { # LF
7871          $p->{line}++;          $p->{line}++;
7872          $p->{column} = 0;          $p->{column} = 0;
7873          !!!cp ('i1');          !!!cp ('i1');
7874        } elsif ($self->{next_char} == 0x000D) { # CR        } elsif ($self->{nc} == 0x000D) { # CR
7875          $i++ if substr ($$s, $i, 1) eq "\x0A";  ## TODO: support for abort/streaming
7876          $self->{next_char} = 0x000A; # LF # MUST          my $next = '';
7877            if ($input->read ($next, 1) and $next ne "\x0A") {
7878              $self->{next_nc} = $next;
7879            }
7880            $self->{nc} = 0x000A; # LF # MUST
7881          $p->{line}++;          $p->{line}++;
7882          $p->{column} = 0;          $p->{column} = 0;
7883          !!!cp ('i2');          !!!cp ('i2');
7884        } elsif ($self->{next_char} > 0x10FFFF) {        } elsif ($self->{nc} == 0x0000) { # NULL
         $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST  
         !!!cp ('i3');  
       } elsif ($self->{next_char} == 0x0000) { # NULL  
7885          !!!cp ('i4');          !!!cp ('i4');
7886          !!!parse-error (type => 'NULL');          !!!parse-error (type => 'NULL');
7887          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{nc} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
       } elsif ($self->{next_char} <= 0x0008 or  
                (0x000E <= $self->{next_char} and  
                 $self->{next_char} <= 0x001F) or  
                (0x007F <= $self->{next_char} and  
                 $self->{next_char} <= 0x009F) or  
                (0xD800 <= $self->{next_char} and  
                 $self->{next_char} <= 0xDFFF) or  
                (0xFDD0 <= $self->{next_char} and  
                 $self->{next_char} <= 0xFDDF) or  
                {  
                 0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,  
                 0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,  
                 0x4FFFE => 1, 0x4FFFF => 1, 0x5FFFE => 1, 0x5FFFF => 1,  
                 0x6FFFE => 1, 0x6FFFF => 1, 0x7FFFE => 1, 0x7FFFF => 1,  
                 0x8FFFE => 1, 0x8FFFF => 1, 0x9FFFE => 1, 0x9FFFF => 1,  
                 0xAFFFE => 1, 0xAFFFF => 1, 0xBFFFE => 1, 0xBFFFF => 1,  
                 0xCFFFE => 1, 0xCFFFF => 1, 0xDFFFE => 1, 0xDFFFF => 1,  
                 0xEFFFE => 1, 0xEFFFF => 1, 0xFFFFE => 1, 0xFFFFF => 1,  
                 0x10FFFE => 1, 0x10FFFF => 1,  
                }->{$self->{next_char}}) {  
         !!!cp ('i4.1');  
         !!!parse-error (type => 'control char', level => $self->{must_level});  
 ## TODO: error type documentation  
7888        }        }
7889      };      };
7890      $p->{prev_char} = [-1, -1, -1];  
7891      $p->{next_char} = -1;      $p->{read_until} = sub {
7892              #my ($scalar, $specials_range, $offset) = @_;
7893          return 0 if defined $p->{next_nc};
7894    
7895          my $pattern = qr/[^$_[1]\x00\x0A\x0D]/;
7896          my $offset = $_[2] || 0;
7897          
7898          if ($p->{char_buffer_pos} < length $p->{char_buffer}) {
7899            pos ($p->{char_buffer}) = $p->{char_buffer_pos};
7900            if ($p->{char_buffer} =~ /\G(?>$pattern)+/) {
7901              substr ($_[0], $offset)
7902                  = substr ($p->{char_buffer}, $-[0], $+[0] - $-[0]);
7903              my $count = $+[0] - $-[0];
7904              if ($count) {
7905                $p->{column} += $count;
7906                $p->{char_buffer_pos} += $count;
7907                $p->{line_prev} = $p->{line};
7908                $p->{column_prev} = $p->{column} - 1;
7909                $p->{nc} = -1;
7910              }
7911              return $count;
7912            } else {
7913              return 0;
7914            }
7915          } else {
7916            my $count = $input->manakai_read_until ($_[0], $pattern, $_[2]);
7917            if ($count) {
7918              $p->{column} += $count;
7919              $p->{column_prev} += $count;
7920              $p->{nc} = -1;
7921            }
7922            return $count;
7923          }
7924        }; # $p->{read_until}
7925    
7926      my $ponerror = $onerror || sub {      my $ponerror = $onerror || sub {
7927        my (%opt) = @_;        my (%opt) = @_;
7928        my $line = $opt{line};        my $line = $opt{line};
# Line 7123  sub set_inner_html ($$$) { Line 7937  sub set_inner_html ($$$) {
7937        $ponerror->(line => $p->{line}, column => $p->{column}, @_);        $ponerror->(line => $p->{line}, column => $p->{column}, @_);
7938      };      };
7939            
7940        my $char_onerror = sub {
7941          my (undef, $type, %opt) = @_;
7942          $ponerror->(layer => 'encode',
7943                      line => $p->{line}, column => $p->{column} + 1,
7944                      %opt, type => $type);
7945        }; # $char_onerror
7946        $input->onerror ($char_onerror);
7947    
7948      $p->_initialize_tokenizer;      $p->_initialize_tokenizer;
7949      $p->_initialize_tree_constructor;      $p->_initialize_tree_constructor;
7950    

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24