/[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.155 by wakaba, Sat Aug 30 12:57:05 2008 UTC revision 1.183 by wakaba, Mon Sep 15 08:09:39 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 ('');
# Line 354  sub parse_byte_string ($$$$;$) { Line 365  sub parse_byte_string ($$$$;$) {
365    return $self->parse_byte_stream ($charset_name, $input, @_[1..$#_]);    return $self->parse_byte_stream ($charset_name, $input, @_[1..$#_]);
366  } # parse_byte_string  } # parse_byte_string
367    
368  sub parse_byte_stream ($$$$;$) {  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_name = shift;    my $charset_name = shift;
372    my $byte_stream = $_[0];    my $byte_stream = $_[0];
# Line 365  sub parse_byte_stream ($$$$;$) { Line 377  sub parse_byte_stream ($$$$;$) {
377    };    };
378    $self->{parse_error} = $onerror; # updated later by parse_char_string    $self->{parse_error} = $onerror; # updated later by parse_char_string
379    
380      my $get_wrapper = $_[3] || sub ($) {
381        return $_[0]; # $_[0] = byte stream handle, returned = arg to char handle
382      };
383    
384    ## HTML5 encoding sniffing algorithm    ## HTML5 encoding sniffing algorithm
385    require Message::Charset::Info;    require Message::Charset::Info;
386    my $charset;    my $charset;
# Line 372  sub parse_byte_stream ($$$$;$) { Line 388  sub parse_byte_stream ($$$$;$) {
388    my ($char_stream, $e_status);    my ($char_stream, $e_status);
389    
390    SNIFFING: {    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      ## Step 1
399      if (defined $charset_name) {      if (defined $charset_name) {
400        $charset = Message::Charset::Info->get_by_iana_name ($charset_name);        $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        ## ISSUE: Unsupported encoding is not ignored according to the spec.        ## ISSUE: Unsupported encoding is not ignored according to the spec.
405        ($char_stream, $e_status) = $charset->get_decode_handle        ($char_stream, $e_status) = $charset->get_decode_handle
# Line 399  sub parse_byte_stream ($$$$;$) { Line 423  sub parse_byte_stream ($$$$;$) {
423    
424      ## Step 3      ## Step 3
425      if ($byte_buffer =~ /^\xFE\xFF/) {      if ($byte_buffer =~ /^\xFE\xFF/) {
426        $charset = Message::Charset::Info->get_by_iana_name ('utf-16be');        $charset = Message::Charset::Info->get_by_html_name ('utf-16be');
427        ($char_stream, $e_status) = $charset->get_decode_handle        ($char_stream, $e_status) = $charset->get_decode_handle
428            ($byte_stream, allow_error_reporting => 1,            ($byte_stream, allow_error_reporting => 1,
429             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
430        $self->{confident} = 1;        $self->{confident} = 1;
431        last SNIFFING;        last SNIFFING;
432      } elsif ($byte_buffer =~ /^\xFF\xFE/) {      } elsif ($byte_buffer =~ /^\xFF\xFE/) {
433        $charset = Message::Charset::Info->get_by_iana_name ('utf-16le');        $charset = Message::Charset::Info->get_by_html_name ('utf-16le');
434        ($char_stream, $e_status) = $charset->get_decode_handle        ($char_stream, $e_status) = $charset->get_decode_handle
435            ($byte_stream, allow_error_reporting => 1,            ($byte_stream, allow_error_reporting => 1,
436             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
437        $self->{confident} = 1;        $self->{confident} = 1;
438        last SNIFFING;        last SNIFFING;
439      } elsif ($byte_buffer =~ /^\xEF\xBB\xBF/) {      } elsif ($byte_buffer =~ /^\xEF\xBB\xBF/) {
440        $charset = Message::Charset::Info->get_by_iana_name ('utf-8');        $charset = Message::Charset::Info->get_by_html_name ('utf-8');
441        ($char_stream, $e_status) = $charset->get_decode_handle        ($char_stream, $e_status) = $charset->get_decode_handle
442            ($byte_stream, allow_error_reporting => 1,            ($byte_stream, allow_error_reporting => 1,
443             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
# Line 432  sub parse_byte_stream ($$$$;$) { Line 456  sub parse_byte_stream ($$$$;$) {
456      $charset_name = Whatpm::Charset::UniversalCharDet->detect_byte_string      $charset_name = Whatpm::Charset::UniversalCharDet->detect_byte_string
457          ($byte_buffer);          ($byte_buffer);
458      if (defined $charset_name) {      if (defined $charset_name) {
459        $charset = Message::Charset::Info->get_by_iana_name ($charset_name);        $charset = Message::Charset::Info->get_by_html_name ($charset_name);
460    
461        ## ISSUE: Unsupported encoding is not ignored according to the spec.        ## ISSUE: Unsupported encoding is not ignored according to the spec.
462        require Whatpm::Charset::DecodeHandle;        require Whatpm::Charset::DecodeHandle;
# Line 455  sub parse_byte_stream ($$$$;$) { Line 479  sub parse_byte_stream ($$$$;$) {
479    
480      ## Step 7: default      ## Step 7: default
481      ## TODO: Make this configurable.      ## TODO: Make this configurable.
482      $charset = Message::Charset::Info->get_by_iana_name ('windows-1252');      $charset = Message::Charset::Info->get_by_html_name ('windows-1252');
483          ## NOTE: We choose |windows-1252| here, since |utf-8| should be          ## NOTE: We choose |windows-1252| here, since |utf-8| should be
484          ## detectable in the step 6.          ## detectable in the step 6.
485      require Whatpm::Charset::DecodeHandle;      require Whatpm::Charset::DecodeHandle;
# Line 475  sub parse_byte_stream ($$$$;$) { Line 499  sub parse_byte_stream ($$$$;$) {
499      $self->{confident} = 0;      $self->{confident} = 0;
500    } # SNIFFING    } # SNIFFING
501    
   $self->{input_encoding} = $charset->get_iana_name;  
502    if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {    if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
503        $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name?
504      !!!parse-error (type => 'chardecode:fallback',      !!!parse-error (type => 'chardecode:fallback',
505                      text => $self->{input_encoding},                      #text => $self->{input_encoding},
506                      level => $self->{level}->{uncertain},                      level => $self->{level}->{uncertain},
507                      line => 1, column => 1,                      line => 1, column => 1,
508                      layer => 'encode');                      layer => 'encode');
509    } elsif (not ($e_status &    } elsif (not ($e_status &
510                  Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {                  Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL ())) {
511        $self->{input_encoding} = $charset->get_iana_name;
512      !!!parse-error (type => 'chardecode:no error',      !!!parse-error (type => 'chardecode:no error',
513                      text => $self->{input_encoding},                      text => $self->{input_encoding},
514                      level => $self->{level}->{uncertain},                      level => $self->{level}->{uncertain},
515                      line => 1, column => 1,                      line => 1, column => 1,
516                      layer => 'encode');                      layer => 'encode');
517      } else {
518        $self->{input_encoding} = $charset->get_iana_name;
519    }    }
520    
521    $self->{change_encoding} = sub {    $self->{change_encoding} = sub {
# Line 496  sub parse_byte_stream ($$$$;$) { Line 523  sub parse_byte_stream ($$$$;$) {
523      $charset_name = shift;      $charset_name = shift;
524      my $token = shift;      my $token = shift;
525    
526      $charset = Message::Charset::Info->get_by_iana_name ($charset_name);      $charset = Message::Charset::Info->get_by_html_name ($charset_name);
527      ($char_stream, $e_status) = $charset->get_decode_handle      ($char_stream, $e_status) = $charset->get_decode_handle
528          ($byte_stream, allow_error_reporting => 1, allow_fallback => 1,          ($byte_stream, allow_error_reporting => 1, allow_fallback => 1,
529           byte_buffer => \ $buffer->{buffer});           byte_buffer => \ $buffer->{buffer});
# Line 507  sub parse_byte_stream ($$$$;$) { Line 534  sub parse_byte_stream ($$$$;$) {
534        ## Step 1            ## Step 1    
535        if ($charset->{category} &        if ($charset->{category} &
536            Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) {            Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) {
537          $charset = Message::Charset::Info->get_by_iana_name ('utf-8');          $charset = Message::Charset::Info->get_by_html_name ('utf-8');
538          ($char_stream, $e_status) = $charset->get_decode_handle          ($char_stream, $e_status) = $charset->get_decode_handle
539              ($byte_stream,              ($byte_stream,
540               byte_buffer => \ $buffer->{buffer});               byte_buffer => \ $buffer->{buffer});
# Line 545  sub parse_byte_stream ($$$$;$) { Line 572  sub parse_byte_stream ($$$$;$) {
572    my $char_onerror = sub {    my $char_onerror = sub {
573      my (undef, $type, %opt) = @_;      my (undef, $type, %opt) = @_;
574      !!!parse-error (layer => 'encode',      !!!parse-error (layer => 'encode',
575                      %opt, type => $type,                      line => $self->{line}, column => $self->{column} + 1,
576                      line => $self->{line}, column => $self->{column} + 1);                      %opt, type => $type);
577      if ($opt{octets}) {      if ($opt{octets}) {
578        ${$opt{octets}} = "\x{FFFD}"; # relacement character        ${$opt{octets}} = "\x{FFFD}"; # relacement character
579      }      }
580    };    };
   $char_stream->onerror ($char_onerror);  
581    
582    my @args = @_; shift @args; # $s    my $wrapped_char_stream = $get_wrapper->($char_stream);
583      $wrapped_char_stream->onerror ($char_onerror);
584    
585      my @args = ($_[1], $_[2]); # $doc, $onerror - $get_wrapper = undef;
586    my $return;    my $return;
587    try {    try {
588      $return = $self->parse_char_stream ($char_stream, @args);        $return = $self->parse_char_stream ($wrapped_char_stream, @args);  
589    } catch Whatpm::HTML::RestartParser with {    } catch Whatpm::HTML::RestartParser with {
590      ## NOTE: Invoked after {change_encoding}.      ## NOTE: Invoked after {change_encoding}.
591    
     $self->{input_encoding} = $charset->get_iana_name;  
592      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
593          $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name?
594        !!!parse-error (type => 'chardecode:fallback',        !!!parse-error (type => 'chardecode:fallback',
                       text => $self->{input_encoding},  
595                        level => $self->{level}->{uncertain},                        level => $self->{level}->{uncertain},
596                          #text => $self->{input_encoding},
597                        line => 1, column => 1,                        line => 1, column => 1,
598                        layer => 'encode');                        layer => 'encode');
599      } elsif (not ($e_status &      } elsif (not ($e_status &
600                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL ())) {
601          $self->{input_encoding} = $charset->get_iana_name;
602        !!!parse-error (type => 'chardecode:no error',        !!!parse-error (type => 'chardecode:no error',
603                        text => $self->{input_encoding},                        text => $self->{input_encoding},
604                        level => $self->{level}->{uncertain},                        level => $self->{level}->{uncertain},
605                        line => 1, column => 1,                        line => 1, column => 1,
606                        layer => 'encode');                        layer => 'encode');
607        } else {
608          $self->{input_encoding} = $charset->get_iana_name;
609      }      }
610      $self->{confident} = 1;      $self->{confident} = 1;
611      $char_stream->onerror ($char_onerror);  
612      $return = $self->parse_char_stream ($char_stream, @args);      $wrapped_char_stream = $get_wrapper->($char_stream);
613        $wrapped_char_stream->onerror ($char_onerror);
614    
615        $return = $self->parse_char_stream ($wrapped_char_stream, @args);
616    };    };
617    return $return;    return $return;
618  } # parse_byte_stream  } # parse_byte_stream
# Line 591  sub parse_byte_stream ($$$$;$) { Line 626  sub parse_byte_stream ($$$$;$) {
626  ## 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
627  ## strip the BOM and never strip any ZWNBSP.  ## strip the BOM and never strip any ZWNBSP.
628    
629  sub parse_char_string ($$$;$) {  sub parse_char_string ($$$;$$) {
630      #my ($self, $s, $doc, $onerror, $get_wrapper) = @_;
631    my $self = shift;    my $self = shift;
   require utf8;  
632    my $s = ref $_[0] ? $_[0] : \($_[0]);    my $s = ref $_[0] ? $_[0] : \($_[0]);
633    open my $input, '<' . (utf8::is_utf8 ($$s) ? ':utf8' : ''), $s;    require Whatpm::Charset::DecodeHandle;
634      my $input = Whatpm::Charset::DecodeHandle::CharString->new ($s);
635    return $self->parse_char_stream ($input, @_[1..$#_]);    return $self->parse_char_stream ($input, @_[1..$#_]);
636  } # parse_char_string  } # parse_char_string
637  *parse_string = \&parse_char_string;  *parse_string = \&parse_char_string; ## NOTE: Alias for backward compatibility.
638    
639  sub parse_char_stream ($$$;$) {  sub parse_char_stream ($$$;$$) {
640    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
641    my $input = $_[0];    my $input = $_[0];
642    $self->{document} = $_[1];    $self->{document} = $_[1];
# Line 611  sub parse_char_stream ($$$;$) { Line 647  sub parse_char_stream ($$$;$) {
647    $self->{confident} = 1 unless exists $self->{confident};    $self->{confident} = 1 unless exists $self->{confident};
648    $self->{document}->input_encoding ($self->{input_encoding})    $self->{document}->input_encoding ($self->{input_encoding})
649        if defined $self->{input_encoding};        if defined $self->{input_encoding};
650    ## TODO: |{input_encoding}| is needless?
651    
   my $i = 0;  
652    $self->{line_prev} = $self->{line} = 1;    $self->{line_prev} = $self->{line} = 1;
653    $self->{column_prev} = $self->{column} = 0;    $self->{column_prev} = -1;
654    $self->{set_next_char} = sub {    $self->{column} = 0;
655      $self->{set_nc} = sub {
656      my $self = shift;      my $self = shift;
657    
658      pop @{$self->{prev_char}};      my $char = '';
659      unshift @{$self->{prev_char}}, $self->{next_char};      if (defined $self->{next_nc}) {
660          $char = $self->{next_nc};
661      my $char;        delete $self->{next_nc};
662      if (defined $self->{next_next_char}) {        $self->{nc} = ord $char;
       $char = $self->{next_next_char};  
       delete $self->{next_next_char};  
663      } else {      } else {
664        $char = $input->getc;        $self->{char_buffer} = '';
665          $self->{char_buffer_pos} = 0;
666    
667          my $count = $input->manakai_read_until
668             ($self->{char_buffer}, qr/[^\x00\x0A\x0D]/, $self->{char_buffer_pos});
669          if ($count) {
670            $self->{line_prev} = $self->{line};
671            $self->{column_prev} = $self->{column};
672            $self->{column}++;
673            $self->{nc}
674                = ord substr ($self->{char_buffer}, $self->{char_buffer_pos}++, 1);
675            return;
676          }
677    
678          if ($input->read ($char, 1)) {
679            $self->{nc} = ord $char;
680          } else {
681            $self->{nc} = -1;
682            return;
683          }
684      }      }
     $self->{next_char} = -1 and return unless defined $char;  
     $self->{next_char} = ord $char;  
685    
686      ($self->{line_prev}, $self->{column_prev})      ($self->{line_prev}, $self->{column_prev})
687          = ($self->{line}, $self->{column});          = ($self->{line}, $self->{column});
688      $self->{column}++;      $self->{column}++;
689            
690      if ($self->{next_char} == 0x000A) { # LF      if ($self->{nc} == 0x000A) { # LF
691        !!!cp ('j1');        !!!cp ('j1');
692        $self->{line}++;        $self->{line}++;
693        $self->{column} = 0;        $self->{column} = 0;
694      } elsif ($self->{next_char} == 0x000D) { # CR      } elsif ($self->{nc} == 0x000D) { # CR
695        !!!cp ('j2');        !!!cp ('j2');
696        my $next = $input->getc;  ## TODO: support for abort/streaming
697        if (defined $next and $next ne "\x0A") {        my $next = '';
698          $self->{next_next_char} = $next;        if ($input->read ($next, 1) and $next ne "\x0A") {
699            $self->{next_nc} = $next;
700        }        }
701        $self->{next_char} = 0x000A; # LF # MUST        $self->{nc} = 0x000A; # LF # MUST
702        $self->{line}++;        $self->{line}++;
703        $self->{column} = 0;        $self->{column} = 0;
704      } 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  
705        !!!cp ('j4');        !!!cp ('j4');
706        !!!parse-error (type => 'NULL');        !!!parse-error (type => 'NULL');
707        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{nc} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
708      } elsif ($self->{next_char} <= 0x0008 or      }
709               (0x000E <= $self->{next_char} and $self->{next_char} <= 0x001F) or    };
710               (0x007F <= $self->{next_char} and $self->{next_char} <= 0x009F) or  
711               (0xD800 <= $self->{next_char} and $self->{next_char} <= 0xDFFF) or    $self->{read_until} = sub {
712               (0xFDD0 <= $self->{next_char} and $self->{next_char} <= 0xFDDF) or      #my ($scalar, $specials_range, $offset) = @_;
713               {      return 0 if defined $self->{next_nc};
714                0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,  
715                0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,      my $pattern = qr/[^$_[1]\x00\x0A\x0D]/;
716                0x4FFFE => 1, 0x4FFFF => 1, 0x5FFFE => 1, 0x5FFFF => 1,      my $offset = $_[2] || 0;
717                0x6FFFE => 1, 0x6FFFF => 1, 0x7FFFE => 1, 0x7FFFF => 1,  
718                0x8FFFE => 1, 0x8FFFF => 1, 0x9FFFE => 1, 0x9FFFF => 1,      if ($self->{char_buffer_pos} < length $self->{char_buffer}) {
719                0xAFFFE => 1, 0xAFFFF => 1, 0xBFFFE => 1, 0xBFFFF => 1,        pos ($self->{char_buffer}) = $self->{char_buffer_pos};
720                0xCFFFE => 1, 0xCFFFF => 1, 0xDFFFE => 1, 0xDFFFF => 1,        if ($self->{char_buffer} =~ /\G(?>$pattern)+/) {
721                0xEFFFE => 1, 0xEFFFF => 1, 0xFFFFE => 1, 0xFFFFF => 1,          substr ($_[0], $offset)
722                0x10FFFE => 1, 0x10FFFF => 1,              = substr ($self->{char_buffer}, $-[0], $+[0] - $-[0]);
723               }->{$self->{next_char}}) {          my $count = $+[0] - $-[0];
724        !!!cp ('j5');          if ($count) {
725        if ($self->{next_char} < 0x10000) {            $self->{column} += $count;
726          !!!parse-error (type => 'control char',            $self->{char_buffer_pos} += $count;
727                          text => (sprintf 'U+%04X', $self->{next_char}));            $self->{line_prev} = $self->{line};
728              $self->{column_prev} = $self->{column} - 1;
729              $self->{prev_char} = [-1, -1, -1];
730              $self->{nc} = -1;
731            }
732            return $count;
733        } else {        } else {
734          !!!parse-error (type => 'control char',          return 0;
735                          text => (sprintf 'U-%08X', $self->{next_char}));        }
736        } else {
737          my $count = $input->manakai_read_until ($_[0], $pattern, $_[2]);
738          if ($count) {
739            $self->{column} += $count;
740            $self->{line_prev} = $self->{line};
741            $self->{column_prev} = $self->{column} - 1;
742            $self->{prev_char} = [-1, -1, -1];
743            $self->{nc} = -1;
744        }        }
745          return $count;
746      }      }
747    };    }; # $self->{read_until}
   $self->{prev_char} = [-1, -1, -1];  
   $self->{next_char} = -1;  
748    
749    my $onerror = $_[2] || sub {    my $onerror = $_[2] || sub {
750      my (%opt) = @_;      my (%opt) = @_;
# Line 694  sub parse_char_stream ($$$;$) { Line 756  sub parse_char_stream ($$$;$) {
756      $onerror->(line => $self->{line}, column => $self->{column}, @_);      $onerror->(line => $self->{line}, column => $self->{column}, @_);
757    };    };
758    
759      my $char_onerror = sub {
760        my (undef, $type, %opt) = @_;
761        !!!parse-error (layer => 'encode',
762                        line => $self->{line}, column => $self->{column} + 1,
763                        %opt, type => $type);
764      }; # $char_onerror
765    
766      if ($_[3]) {
767        $input = $_[3]->($input);
768        $input->onerror ($char_onerror);
769      } else {
770        $input->onerror ($char_onerror) unless defined $input->onerror;
771      }
772    
773    $self->_initialize_tokenizer;    $self->_initialize_tokenizer;
774    $self->_initialize_tree_constructor;    $self->_initialize_tree_constructor;
775    $self->_construct_tree;    $self->_construct_tree;
# Line 708  sub new ($) { Line 784  sub new ($) {
784    my $class = shift;    my $class = shift;
785    my $self = bless {    my $self = bless {
786      level => {must => 'm',      level => {must => 'm',
787                  should => 's',
788                warn => 'w',                warn => 'w',
789                info => 'i',                info => 'i',
790                uncertain => 'u'},                uncertain => 'u'},
791    }, $class;    }, $class;
792    $self->{set_next_char} = sub {    $self->{set_nc} = sub {
793      $self->{next_char} = -1;      $self->{nc} = -1;
794    };    };
795    $self->{parse_error} = sub {    $self->{parse_error} = sub {
796      #      #
# Line 740  sub RCDATA_CONTENT_MODEL () { CM_ENTITY Line 817  sub RCDATA_CONTENT_MODEL () { CM_ENTITY
817  sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }  sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }
818    
819  sub DATA_STATE () { 0 }  sub DATA_STATE () { 0 }
820  sub ENTITY_DATA_STATE () { 1 }  #sub ENTITY_DATA_STATE () { 1 }
821  sub TAG_OPEN_STATE () { 2 }  sub TAG_OPEN_STATE () { 2 }
822  sub CLOSE_TAG_OPEN_STATE () { 3 }  sub CLOSE_TAG_OPEN_STATE () { 3 }
823  sub TAG_NAME_STATE () { 4 }  sub TAG_NAME_STATE () { 4 }
# Line 751  sub BEFORE_ATTRIBUTE_VALUE_STATE () { 8 Line 828  sub BEFORE_ATTRIBUTE_VALUE_STATE () { 8
828  sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 }  sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 }
829  sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 }  sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 }
830  sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 }  sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 }
831  sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 }  #sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 }
832  sub MARKUP_DECLARATION_OPEN_STATE () { 13 }  sub MARKUP_DECLARATION_OPEN_STATE () { 13 }
833  sub COMMENT_START_STATE () { 14 }  sub COMMENT_START_STATE () { 14 }
834  sub COMMENT_START_DASH_STATE () { 15 }  sub COMMENT_START_DASH_STATE () { 15 }
# Line 774  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STAT Line 851  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STAT
851  sub BOGUS_DOCTYPE_STATE () { 32 }  sub BOGUS_DOCTYPE_STATE () { 32 }
852  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }
853  sub SELF_CLOSING_START_TAG_STATE () { 34 }  sub SELF_CLOSING_START_TAG_STATE () { 34 }
854  sub CDATA_BLOCK_STATE () { 35 }  sub CDATA_SECTION_STATE () { 35 }
855    sub MD_HYPHEN_STATE () { 36 } # "markup declaration open state" in the spec
856    sub MD_DOCTYPE_STATE () { 37 } # "markup declaration open state" in the spec
857    sub MD_CDATA_STATE () { 38 } # "markup declaration open state" in the spec
858    sub CDATA_PCDATA_CLOSE_TAG_STATE () { 39 } # "close tag open state" in the spec
859    sub CDATA_SECTION_MSE1_STATE () { 40 } # "CDATA section state" in the spec
860    sub CDATA_SECTION_MSE2_STATE () { 41 } # "CDATA section state" in the spec
861    sub PUBLIC_STATE () { 42 } # "after DOCTYPE name state" in the spec
862    sub SYSTEM_STATE () { 43 } # "after DOCTYPE name state" in the spec
863    ## NOTE: "Entity data state", "entity in attribute value state", and
864    ## "consume a character reference" algorithm are jointly implemented
865    ## using the following six states:
866    sub ENTITY_STATE () { 44 }
867    sub ENTITY_HASH_STATE () { 45 }
868    sub NCR_NUM_STATE () { 46 }
869    sub HEXREF_X_STATE () { 47 }
870    sub HEXREF_HEX_STATE () { 48 }
871    sub ENTITY_NAME_STATE () { 49 }
872    
873  sub DOCTYPE_TOKEN () { 1 }  sub DOCTYPE_TOKEN () { 1 }
874  sub COMMENT_TOKEN () { 2 }  sub COMMENT_TOKEN () { 2 }
# Line 827  sub IN_COLUMN_GROUP_IM () { 0b10 } Line 921  sub IN_COLUMN_GROUP_IM () { 0b10 }
921  sub _initialize_tokenizer ($) {  sub _initialize_tokenizer ($) {
922    my $self = shift;    my $self = shift;
923    $self->{state} = DATA_STATE; # MUST    $self->{state} = DATA_STATE; # MUST
924      #$self->{s_kwd}; # state keyword - initialized when used
925      #$self->{entity__value}; # initialized when used
926      #$self->{entity__match}; # initialized when used
927    $self->{content_model} = PCDATA_CONTENT_MODEL; # be    $self->{content_model} = PCDATA_CONTENT_MODEL; # be
928    undef $self->{current_token}; # start tag, end tag, comment, or DOCTYPE    undef $self->{ct}; # current token
929    undef $self->{current_attribute};    undef $self->{ca}; # current attribute
930    undef $self->{last_emitted_start_tag_name};    undef $self->{last_stag_name}; # last emitted start tag name
931    undef $self->{last_attribute_value_state};    #$self->{prev_state}; # initialized when used
932    delete $self->{self_closing};    delete $self->{self_closing};
933    $self->{char} = [];    $self->{char_buffer} = '';
934    # $self->{next_char}    $self->{char_buffer_pos} = 0;
935      $self->{prev_char} = [-1, -1, -1];
936      $self->{nc} = -1; # next input character
937      #$self->{next_nc}
938    !!!next-input-character;    !!!next-input-character;
939    $self->{token} = [];    $self->{token} = [];
940    # $self->{escape}    # $self->{escape}
# Line 845  sub _initialize_tokenizer ($) { Line 945  sub _initialize_tokenizer ($) {
945  ##       CHARACTER_TOKEN, or END_OF_FILE_TOKEN  ##       CHARACTER_TOKEN, or END_OF_FILE_TOKEN
946  ##   ->{name} (DOCTYPE_TOKEN)  ##   ->{name} (DOCTYPE_TOKEN)
947  ##   ->{tag_name} (START_TAG_TOKEN, END_TAG_TOKEN)  ##   ->{tag_name} (START_TAG_TOKEN, END_TAG_TOKEN)
948  ##   ->{public_identifier} (DOCTYPE_TOKEN)  ##   ->{pubid} (DOCTYPE_TOKEN)
949  ##   ->{system_identifier} (DOCTYPE_TOKEN)  ##   ->{sysid} (DOCTYPE_TOKEN)
950  ##   ->{quirks} == 1 or 0 (DOCTYPE_TOKEN): "force-quirks" flag  ##   ->{quirks} == 1 or 0 (DOCTYPE_TOKEN): "force-quirks" flag
951  ##   ->{attributes} isa HASH (START_TAG_TOKEN, END_TAG_TOKEN)  ##   ->{attributes} isa HASH (START_TAG_TOKEN, END_TAG_TOKEN)
952  ##        ->{name}  ##        ->{name}
# Line 865  sub _initialize_tokenizer ($) { Line 965  sub _initialize_tokenizer ($) {
965  ## has completed loading.  If one has, then it MUST be executed  ## has completed loading.  If one has, then it MUST be executed
966  ## and removed from the list.  ## and removed from the list.
967    
968  ## NOTE: HTML5 "Writing HTML documents" section, applied to  ## TODO: Polytheistic slash SHOULD NOT be used. (Applied only to atheists.)
969  ## documents and not to user agents and conformance checkers,  ## (This requirement was dropped from HTML5 spec, unfortunately.)
 ## contains some requirements that are not detected by the  
 ## parsing algorithm:  
 ## - Some requirements on character encoding declarations. ## TODO  
 ## - "Elements MUST NOT contain content that their content model disallows."  
 ##   ... Some are parse error, some are not (will be reported by c.c.).  
 ## - Polytheistic slash SHOULD NOT be used. (Applied only to atheists.) ## TODO  
 ## - Text (in elements, attributes, and comments) SHOULD NOT contain  
 ##   control characters other than space characters. ## TODO: (what is control character? C0, C1 and DEL?  Unicode control character?)  
   
 ## TODO: HTML5 poses authors two SHOULD-level requirements that cannot  
 ## be detected by the HTML5 parsing algorithm:  
 ## - Text,  
970    
971  sub _get_next_token ($) {  sub _get_next_token ($) {
972    my $self = shift;    my $self = shift;
973    
974    if ($self->{self_closing}) {    if ($self->{self_closing}) {
975      !!!parse-error (type => 'nestc', token => $self->{current_token});      !!!parse-error (type => 'nestc', token => $self->{ct});
976      ## NOTE: The |self_closing| flag is only set by start tag token.      ## NOTE: The |self_closing| flag is only set by start tag token.
977      ## 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
978      ## |current_token|.      ## |ct|.
979      delete $self->{self_closing};      delete $self->{self_closing};
980    }    }
981    
# Line 898  sub _get_next_token ($) { Line 986  sub _get_next_token ($) {
986    
987    A: {    A: {
988      if ($self->{state} == DATA_STATE) {      if ($self->{state} == DATA_STATE) {
989        if ($self->{next_char} == 0x0026) { # &        if ($self->{nc} == 0x0026) { # &
990          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA
991              not $self->{escape}) {              not $self->{escape}) {
992            !!!cp (1);            !!!cp (1);
993            $self->{state} = ENTITY_DATA_STATE;            ## NOTE: In the spec, the tokenizer is switched to the
994              ## "entity data state".  In this implementation, the tokenizer
995              ## is switched to the |ENTITY_STATE|, which is an implementation
996              ## of the "consume a character reference" algorithm.
997              $self->{entity_add} = -1;
998              $self->{prev_state} = DATA_STATE;
999              $self->{state} = ENTITY_STATE;
1000            !!!next-input-character;            !!!next-input-character;
1001            redo A;            redo A;
1002          } else {          } else {
1003            !!!cp (2);            !!!cp (2);
1004            #            #
1005          }          }
1006        } elsif ($self->{next_char} == 0x002D) { # -        } elsif ($self->{nc} == 0x002D) { # -
1007          if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA          if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1008            unless ($self->{escape}) {            unless ($self->{escape}) {
1009              if ($self->{prev_char}->[0] == 0x002D and # -              if ($self->{prev_char}->[0] == 0x002D and # -
# Line 926  sub _get_next_token ($) { Line 1020  sub _get_next_token ($) {
1020          }          }
1021                    
1022          #          #
1023        } elsif ($self->{next_char} == 0x003C) { # <        } elsif ($self->{nc} == 0x003C) { # <
1024          if ($self->{content_model} & CM_FULL_MARKUP or # PCDATA          if ($self->{content_model} & CM_FULL_MARKUP or # PCDATA
1025              (($self->{content_model} & CM_LIMITED_MARKUP) and # CDATA | RCDATA              (($self->{content_model} & CM_LIMITED_MARKUP) and # CDATA | RCDATA
1026               not $self->{escape})) {               not $self->{escape})) {
# Line 938  sub _get_next_token ($) { Line 1032  sub _get_next_token ($) {
1032            !!!cp (7);            !!!cp (7);
1033            #            #
1034          }          }
1035        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1036          if ($self->{escape} and          if ($self->{escape} and
1037              ($self->{content_model} & CM_LIMITED_MARKUP)) { # RCDATA | CDATA              ($self->{content_model} & CM_LIMITED_MARKUP)) { # RCDATA | CDATA
1038            if ($self->{prev_char}->[0] == 0x002D and # -            if ($self->{prev_char}->[0] == 0x002D and # -
# Line 953  sub _get_next_token ($) { Line 1047  sub _get_next_token ($) {
1047          }          }
1048                    
1049          #          #
1050        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1051          !!!cp (11);          !!!cp (11);
1052          !!!emit ({type => END_OF_FILE_TOKEN,          !!!emit ({type => END_OF_FILE_TOKEN,
1053                    line => $self->{line}, column => $self->{column}});                    line => $self->{line}, column => $self->{column}});
# Line 963  sub _get_next_token ($) { Line 1057  sub _get_next_token ($) {
1057        }        }
1058        # Anything else        # Anything else
1059        my $token = {type => CHARACTER_TOKEN,        my $token = {type => CHARACTER_TOKEN,
1060                     data => chr $self->{next_char},                     data => chr $self->{nc},
1061                     line => $self->{line}, column => $self->{column},                     line => $self->{line}, column => $self->{column},
1062                    };                    };
1063          $self->{read_until}->($token->{data}, q[-!<>&], length $token->{data});
1064    
1065        ## Stay in the data state        ## Stay in the data state
1066        !!!next-input-character;        !!!next-input-character;
1067    
1068        !!!emit ($token);        !!!emit ($token);
1069    
1070        redo A;        redo A;
     } elsif ($self->{state} == ENTITY_DATA_STATE) {  
       ## (cannot happen in CDATA state)  
   
       my ($l, $c) = ($self->{line_prev}, $self->{column_prev});  
         
       my $token = $self->_tokenize_attempt_to_consume_an_entity (0, -1);  
   
       $self->{state} = DATA_STATE;  
       # next-input-character is already done  
   
       unless (defined $token) {  
         !!!cp (13);  
         !!!emit ({type => CHARACTER_TOKEN, data => '&',  
                   line => $l, column => $c,  
                  });  
       } else {  
         !!!cp (14);  
         !!!emit ($token);  
       }  
   
       redo A;  
1071      } elsif ($self->{state} == TAG_OPEN_STATE) {      } elsif ($self->{state} == TAG_OPEN_STATE) {
1072        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1073          if ($self->{next_char} == 0x002F) { # /          if ($self->{nc} == 0x002F) { # /
1074            !!!cp (15);            !!!cp (15);
1075            !!!next-input-character;            !!!next-input-character;
1076            $self->{state} = CLOSE_TAG_OPEN_STATE;            $self->{state} = CLOSE_TAG_OPEN_STATE;
# Line 1013  sub _get_next_token ($) { Line 1088  sub _get_next_token ($) {
1088            redo A;            redo A;
1089          }          }
1090        } elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA        } elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA
1091          if ($self->{next_char} == 0x0021) { # !          if ($self->{nc} == 0x0021) { # !
1092            !!!cp (17);            !!!cp (17);
1093            $self->{state} = MARKUP_DECLARATION_OPEN_STATE;            $self->{state} = MARKUP_DECLARATION_OPEN_STATE;
1094            !!!next-input-character;            !!!next-input-character;
1095            redo A;            redo A;
1096          } elsif ($self->{next_char} == 0x002F) { # /          } elsif ($self->{nc} == 0x002F) { # /
1097            !!!cp (18);            !!!cp (18);
1098            $self->{state} = CLOSE_TAG_OPEN_STATE;            $self->{state} = CLOSE_TAG_OPEN_STATE;
1099            !!!next-input-character;            !!!next-input-character;
1100            redo A;            redo A;
1101          } elsif (0x0041 <= $self->{next_char} and          } elsif (0x0041 <= $self->{nc} and
1102                   $self->{next_char} <= 0x005A) { # A..Z                   $self->{nc} <= 0x005A) { # A..Z
1103            !!!cp (19);            !!!cp (19);
1104            $self->{current_token}            $self->{ct}
1105              = {type => START_TAG_TOKEN,              = {type => START_TAG_TOKEN,
1106                 tag_name => chr ($self->{next_char} + 0x0020),                 tag_name => chr ($self->{nc} + 0x0020),
1107                 line => $self->{line_prev},                 line => $self->{line_prev},
1108                 column => $self->{column_prev}};                 column => $self->{column_prev}};
1109            $self->{state} = TAG_NAME_STATE;            $self->{state} = TAG_NAME_STATE;
1110            !!!next-input-character;            !!!next-input-character;
1111            redo A;            redo A;
1112          } elsif (0x0061 <= $self->{next_char} and          } elsif (0x0061 <= $self->{nc} and
1113                   $self->{next_char} <= 0x007A) { # a..z                   $self->{nc} <= 0x007A) { # a..z
1114            !!!cp (20);            !!!cp (20);
1115            $self->{current_token} = {type => START_TAG_TOKEN,            $self->{ct} = {type => START_TAG_TOKEN,
1116                                      tag_name => chr ($self->{next_char}),                                      tag_name => chr ($self->{nc}),
1117                                      line => $self->{line_prev},                                      line => $self->{line_prev},
1118                                      column => $self->{column_prev}};                                      column => $self->{column_prev}};
1119            $self->{state} = TAG_NAME_STATE;            $self->{state} = TAG_NAME_STATE;
1120            !!!next-input-character;            !!!next-input-character;
1121            redo A;            redo A;
1122          } elsif ($self->{next_char} == 0x003E) { # >          } elsif ($self->{nc} == 0x003E) { # >
1123            !!!cp (21);            !!!cp (21);
1124            !!!parse-error (type => 'empty start tag',            !!!parse-error (type => 'empty start tag',
1125                            line => $self->{line_prev},                            line => $self->{line_prev},
# Line 1058  sub _get_next_token ($) { Line 1133  sub _get_next_token ($) {
1133                     });                     });
1134    
1135            redo A;            redo A;
1136          } elsif ($self->{next_char} == 0x003F) { # ?          } elsif ($self->{nc} == 0x003F) { # ?
1137            !!!cp (22);            !!!cp (22);
1138            !!!parse-error (type => 'pio',            !!!parse-error (type => 'pio',
1139                            line => $self->{line_prev},                            line => $self->{line_prev},
1140                            column => $self->{column_prev});                            column => $self->{column_prev});
1141            $self->{state} = BOGUS_COMMENT_STATE;            $self->{state} = BOGUS_COMMENT_STATE;
1142            $self->{current_token} = {type => COMMENT_TOKEN, data => '',            $self->{ct} = {type => COMMENT_TOKEN, data => '',
1143                                      line => $self->{line_prev},                                      line => $self->{line_prev},
1144                                      column => $self->{column_prev},                                      column => $self->{column_prev},
1145                                     };                                     };
1146            ## $self->{next_char} is intentionally left as is            ## $self->{nc} is intentionally left as is
1147            redo A;            redo A;
1148          } else {          } else {
1149            !!!cp (23);            !!!cp (23);
# Line 1089  sub _get_next_token ($) { Line 1164  sub _get_next_token ($) {
1164          die "$0: $self->{content_model} in tag open";          die "$0: $self->{content_model} in tag open";
1165        }        }
1166      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {
1167          ## NOTE: The "close tag open state" in the spec is implemented as
1168          ## |CLOSE_TAG_OPEN_STATE| and |CDATA_PCDATA_CLOSE_TAG_STATE|.
1169    
1170        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"
1171        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1172          if (defined $self->{last_emitted_start_tag_name}) {          if (defined $self->{last_stag_name}) {
1173              $self->{state} = CDATA_PCDATA_CLOSE_TAG_STATE;
1174            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>            $self->{s_kwd} = '';
1175            my @next_char;            ## Reconsume.
1176            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...  
           }  
1177          } else {          } else {
1178            ## No start tag token has ever been emitted            ## No start tag token has ever been emitted
1179              ## NOTE: See <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>.
1180            !!!cp (28);            !!!cp (28);
           # next-input-character is already done  
1181            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1182              ## Reconsume.
1183            !!!emit ({type => CHARACTER_TOKEN, data => '</',            !!!emit ({type => CHARACTER_TOKEN, data => '</',
1184                      line => $l, column => $c,                      line => $l, column => $c,
1185                     });                     });
1186            redo A;            redo A;
1187          }          }
1188        }        }
1189          
1190        if (0x0041 <= $self->{next_char} and        if (0x0041 <= $self->{nc} and
1191            $self->{next_char} <= 0x005A) { # A..Z            $self->{nc} <= 0x005A) { # A..Z
1192          !!!cp (29);          !!!cp (29);
1193          $self->{current_token}          $self->{ct}
1194              = {type => END_TAG_TOKEN,              = {type => END_TAG_TOKEN,
1195                 tag_name => chr ($self->{next_char} + 0x0020),                 tag_name => chr ($self->{nc} + 0x0020),
1196                 line => $l, column => $c};                 line => $l, column => $c};
1197          $self->{state} = TAG_NAME_STATE;          $self->{state} = TAG_NAME_STATE;
1198          !!!next-input-character;          !!!next-input-character;
1199          redo A;          redo A;
1200        } elsif (0x0061 <= $self->{next_char} and        } elsif (0x0061 <= $self->{nc} and
1201                 $self->{next_char} <= 0x007A) { # a..z                 $self->{nc} <= 0x007A) { # a..z
1202          !!!cp (30);          !!!cp (30);
1203          $self->{current_token} = {type => END_TAG_TOKEN,          $self->{ct} = {type => END_TAG_TOKEN,
1204                                    tag_name => chr ($self->{next_char}),                                    tag_name => chr ($self->{nc}),
1205                                    line => $l, column => $c};                                    line => $l, column => $c};
1206          $self->{state} = TAG_NAME_STATE;          $self->{state} = TAG_NAME_STATE;
1207          !!!next-input-character;          !!!next-input-character;
1208          redo A;          redo A;
1209        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1210          !!!cp (31);          !!!cp (31);
1211          !!!parse-error (type => 'empty end tag',          !!!parse-error (type => 'empty end tag',
1212                          line => $self->{line_prev}, ## "<" in "</>"                          line => $self->{line_prev}, ## "<" in "</>"
# Line 1179  sub _get_next_token ($) { Line 1214  sub _get_next_token ($) {
1214          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1215          !!!next-input-character;          !!!next-input-character;
1216          redo A;          redo A;
1217        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1218          !!!cp (32);          !!!cp (32);
1219          !!!parse-error (type => 'bare etago');          !!!parse-error (type => 'bare etago');
1220          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
# Line 1194  sub _get_next_token ($) { Line 1229  sub _get_next_token ($) {
1229          !!!cp (33);          !!!cp (33);
1230          !!!parse-error (type => 'bogus end tag');          !!!parse-error (type => 'bogus end tag');
1231          $self->{state} = BOGUS_COMMENT_STATE;          $self->{state} = BOGUS_COMMENT_STATE;
1232          $self->{current_token} = {type => COMMENT_TOKEN, data => '',          $self->{ct} = {type => COMMENT_TOKEN, data => '',
1233                                    line => $self->{line_prev}, # "<" of "</"                                    line => $self->{line_prev}, # "<" of "</"
1234                                    column => $self->{column_prev} - 1,                                    column => $self->{column_prev} - 1,
1235                                   };                                   };
1236          ## $self->{next_char} is intentionally left as is          ## NOTE: $self->{nc} is intentionally left as is.
1237          redo A;          ## Although the "anything else" case of the spec not explicitly
1238            ## states that the next input character is to be reconsumed,
1239            ## it will be included to the |data| of the comment token
1240            ## generated from the bogus end tag, as defined in the
1241            ## "bogus comment state" entry.
1242            redo A;
1243          }
1244        } elsif ($self->{state} == CDATA_PCDATA_CLOSE_TAG_STATE) {
1245          my $ch = substr $self->{last_stag_name}, length $self->{s_kwd}, 1;
1246          if (length $ch) {
1247            my $CH = $ch;
1248            $ch =~ tr/a-z/A-Z/;
1249            my $nch = chr $self->{nc};
1250            if ($nch eq $ch or $nch eq $CH) {
1251              !!!cp (24);
1252              ## Stay in the state.
1253              $self->{s_kwd} .= $nch;
1254              !!!next-input-character;
1255              redo A;
1256            } else {
1257              !!!cp (25);
1258              $self->{state} = DATA_STATE;
1259              ## Reconsume.
1260              !!!emit ({type => CHARACTER_TOKEN,
1261                        data => '</' . $self->{s_kwd},
1262                        line => $self->{line_prev},
1263                        column => $self->{column_prev} - 1 - length $self->{s_kwd},
1264                       });
1265              redo A;
1266            }
1267          } else { # after "<{tag-name}"
1268            unless ({
1269                     0x0009 => 1, # HT
1270                     0x000A => 1, # LF
1271                     0x000B => 1, # VT
1272                     0x000C => 1, # FF
1273                     0x0020 => 1, # SP
1274                     0x003E => 1, # >
1275                     0x002F => 1, # /
1276                     -1 => 1, # EOF
1277                    }->{$self->{nc}}) {
1278              !!!cp (26);
1279              ## Reconsume.
1280              $self->{state} = DATA_STATE;
1281              !!!emit ({type => CHARACTER_TOKEN,
1282                        data => '</' . $self->{s_kwd},
1283                        line => $self->{line_prev},
1284                        column => $self->{column_prev} - 1 - length $self->{s_kwd},
1285                       });
1286              redo A;
1287            } else {
1288              !!!cp (27);
1289              $self->{ct}
1290                  = {type => END_TAG_TOKEN,
1291                     tag_name => $self->{last_stag_name},
1292                     line => $self->{line_prev},
1293                     column => $self->{column_prev} - 1 - length $self->{s_kwd}};
1294              $self->{state} = TAG_NAME_STATE;
1295              ## Reconsume.
1296              redo A;
1297            }
1298        }        }
1299      } elsif ($self->{state} == TAG_NAME_STATE) {      } elsif ($self->{state} == TAG_NAME_STATE) {
1300        if ($self->{next_char} == 0x0009 or # HT        if ($self->{nc} == 0x0009 or # HT
1301            $self->{next_char} == 0x000A or # LF            $self->{nc} == 0x000A or # LF
1302            $self->{next_char} == 0x000B or # VT            $self->{nc} == 0x000B or # VT
1303            $self->{next_char} == 0x000C or # FF            $self->{nc} == 0x000C or # FF
1304            $self->{next_char} == 0x0020) { # SP            $self->{nc} == 0x0020) { # SP
1305          !!!cp (34);          !!!cp (34);
1306          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1307          !!!next-input-character;          !!!next-input-character;
1308          redo A;          redo A;
1309        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1310          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1311            !!!cp (35);            !!!cp (35);
1312            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1313          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1314            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1315            #if ($self->{current_token}->{attributes}) {            #if ($self->{ct}->{attributes}) {
1316            #  ## NOTE: This should never be reached.            #  ## NOTE: This should never be reached.
1317            #  !!! cp (36);            #  !!! cp (36);
1318            #  !!! parse-error (type => 'end tag attribute');            #  !!! parse-error (type => 'end tag attribute');
# Line 1225  sub _get_next_token ($) { Line 1320  sub _get_next_token ($) {
1320              !!!cp (37);              !!!cp (37);
1321            #}            #}
1322          } else {          } else {
1323            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1324          }          }
1325          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1326          !!!next-input-character;          !!!next-input-character;
1327    
1328          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1329    
1330          redo A;          redo A;
1331        } elsif (0x0041 <= $self->{next_char} and        } elsif (0x0041 <= $self->{nc} and
1332                 $self->{next_char} <= 0x005A) { # A..Z                 $self->{nc} <= 0x005A) { # A..Z
1333          !!!cp (38);          !!!cp (38);
1334          $self->{current_token}->{tag_name} .= chr ($self->{next_char} + 0x0020);          $self->{ct}->{tag_name} .= chr ($self->{nc} + 0x0020);
1335            # start tag or end tag            # start tag or end tag
1336          ## Stay in this state          ## Stay in this state
1337          !!!next-input-character;          !!!next-input-character;
1338          redo A;          redo A;
1339        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1340          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1341          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1342            !!!cp (39);            !!!cp (39);
1343            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1344          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1345            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1346            #if ($self->{current_token}->{attributes}) {            #if ($self->{ct}->{attributes}) {
1347            #  ## NOTE: This state should never be reached.            #  ## NOTE: This state should never be reached.
1348            #  !!! cp (40);            #  !!! cp (40);
1349            #  !!! parse-error (type => 'end tag attribute');            #  !!! parse-error (type => 'end tag attribute');
# Line 1256  sub _get_next_token ($) { Line 1351  sub _get_next_token ($) {
1351              !!!cp (41);              !!!cp (41);
1352            #}            #}
1353          } else {          } else {
1354            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1355          }          }
1356          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1357          # reconsume          # reconsume
1358    
1359          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1360    
1361          redo A;          redo A;
1362        } elsif ($self->{next_char} == 0x002F) { # /        } elsif ($self->{nc} == 0x002F) { # /
1363          !!!cp (42);          !!!cp (42);
1364          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1365          !!!next-input-character;          !!!next-input-character;
1366          redo A;          redo A;
1367        } else {        } else {
1368          !!!cp (44);          !!!cp (44);
1369          $self->{current_token}->{tag_name} .= chr $self->{next_char};          $self->{ct}->{tag_name} .= chr $self->{nc};
1370            # start tag or end tag            # start tag or end tag
1371          ## Stay in the state          ## Stay in the state
1372          !!!next-input-character;          !!!next-input-character;
1373          redo A;          redo A;
1374        }        }
1375      } elsif ($self->{state} == BEFORE_ATTRIBUTE_NAME_STATE) {      } elsif ($self->{state} == BEFORE_ATTRIBUTE_NAME_STATE) {
1376        if ($self->{next_char} == 0x0009 or # HT        if ($self->{nc} == 0x0009 or # HT
1377            $self->{next_char} == 0x000A or # LF            $self->{nc} == 0x000A or # LF
1378            $self->{next_char} == 0x000B or # VT            $self->{nc} == 0x000B or # VT
1379            $self->{next_char} == 0x000C or # FF            $self->{nc} == 0x000C or # FF
1380            $self->{next_char} == 0x0020) { # SP            $self->{nc} == 0x0020) { # SP
1381          !!!cp (45);          !!!cp (45);
1382          ## Stay in the state          ## Stay in the state
1383          !!!next-input-character;          !!!next-input-character;
1384          redo A;          redo A;
1385        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1386          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1387            !!!cp (46);            !!!cp (46);
1388            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1389          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1390            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1391            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1392              !!!cp (47);              !!!cp (47);
1393              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1394            } else {            } else {
1395              !!!cp (48);              !!!cp (48);
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 (49);          !!!cp (49);
1409          $self->{current_attribute}          $self->{ca}
1410              = {name => chr ($self->{next_char} + 0x0020),              = {name => chr ($self->{nc} + 0x0020),
1411                 value => '',                 value => '',
1412                 line => $self->{line}, column => $self->{column}};                 line => $self->{line}, column => $self->{column}};
1413          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
1414          !!!next-input-character;          !!!next-input-character;
1415          redo A;          redo A;
1416        } elsif ($self->{next_char} == 0x002F) { # /        } elsif ($self->{nc} == 0x002F) { # /
1417          !!!cp (50);          !!!cp (50);
1418          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1419          !!!next-input-character;          !!!next-input-character;
1420          redo A;          redo A;
1421        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1422          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1423          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1424            !!!cp (52);            !!!cp (52);
1425            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1426          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1427            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1428            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1429              !!!cp (53);              !!!cp (53);
1430              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1431            } else {            } else {
1432              !!!cp (54);              !!!cp (54);
1433            }            }
1434          } else {          } else {
1435            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1436          }          }
1437          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1438          # reconsume          # reconsume
1439    
1440          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1441    
1442          redo A;          redo A;
1443        } else {        } else {
# Line 1350  sub _get_next_token ($) { Line 1445  sub _get_next_token ($) {
1445               0x0022 => 1, # "               0x0022 => 1, # "
1446               0x0027 => 1, # '               0x0027 => 1, # '
1447               0x003D => 1, # =               0x003D => 1, # =
1448              }->{$self->{next_char}}) {              }->{$self->{nc}}) {
1449            !!!cp (55);            !!!cp (55);
1450            !!!parse-error (type => 'bad attribute name');            !!!parse-error (type => 'bad attribute name');
1451          } else {          } else {
1452            !!!cp (56);            !!!cp (56);
1453          }          }
1454          $self->{current_attribute}          $self->{ca}
1455              = {name => chr ($self->{next_char}),              = {name => chr ($self->{nc}),
1456                 value => '',                 value => '',
1457                 line => $self->{line}, column => $self->{column}};                 line => $self->{line}, column => $self->{column}};
1458          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
# Line 1366  sub _get_next_token ($) { Line 1461  sub _get_next_token ($) {
1461        }        }
1462      } elsif ($self->{state} == ATTRIBUTE_NAME_STATE) {      } elsif ($self->{state} == ATTRIBUTE_NAME_STATE) {
1463        my $before_leave = sub {        my $before_leave = sub {
1464          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{ct}->{attributes} # start tag or end tag
1465              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{ca}->{name}}) { # MUST
1466            !!!cp (57);            !!!cp (57);
1467            !!!parse-error (type => 'duplicate attribute', text => $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});
1468            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{ca} # MUST
1469          } else {          } else {
1470            !!!cp (58);            !!!cp (58);
1471            $self->{current_token}->{attributes}->{$self->{current_attribute}->{name}}            $self->{ct}->{attributes}->{$self->{ca}->{name}}
1472              = $self->{current_attribute};              = $self->{ca};
1473          }          }
1474        }; # $before_leave        }; # $before_leave
1475    
1476        if ($self->{next_char} == 0x0009 or # HT        if ($self->{nc} == 0x0009 or # HT
1477            $self->{next_char} == 0x000A or # LF            $self->{nc} == 0x000A or # LF
1478            $self->{next_char} == 0x000B or # VT            $self->{nc} == 0x000B or # VT
1479            $self->{next_char} == 0x000C or # FF            $self->{nc} == 0x000C or # FF
1480            $self->{next_char} == 0x0020) { # SP            $self->{nc} == 0x0020) { # SP
1481          !!!cp (59);          !!!cp (59);
1482          $before_leave->();          $before_leave->();
1483          $self->{state} = AFTER_ATTRIBUTE_NAME_STATE;          $self->{state} = AFTER_ATTRIBUTE_NAME_STATE;
1484          !!!next-input-character;          !!!next-input-character;
1485          redo A;          redo A;
1486        } elsif ($self->{next_char} == 0x003D) { # =        } elsif ($self->{nc} == 0x003D) { # =
1487          !!!cp (60);          !!!cp (60);
1488          $before_leave->();          $before_leave->();
1489          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;
1490          !!!next-input-character;          !!!next-input-character;
1491          redo A;          redo A;
1492        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1493          $before_leave->();          $before_leave->();
1494          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1495            !!!cp (61);            !!!cp (61);
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            !!!cp (62);            !!!cp (62);
1499            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1500            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1501              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1502            }            }
1503          } else {          } else {
1504            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1505          }          }
1506          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1507          !!!next-input-character;          !!!next-input-character;
1508    
1509          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1510    
1511          redo A;          redo A;
1512        } elsif (0x0041 <= $self->{next_char} and        } elsif (0x0041 <= $self->{nc} and
1513                 $self->{next_char} <= 0x005A) { # A..Z                 $self->{nc} <= 0x005A) { # A..Z
1514          !!!cp (63);          !!!cp (63);
1515          $self->{current_attribute}->{name} .= chr ($self->{next_char} + 0x0020);          $self->{ca}->{name} .= chr ($self->{nc} + 0x0020);
1516          ## Stay in the state          ## Stay in the state
1517          !!!next-input-character;          !!!next-input-character;
1518          redo A;          redo A;
1519        } elsif ($self->{next_char} == 0x002F) { # /        } elsif ($self->{nc} == 0x002F) { # /
1520          !!!cp (64);          !!!cp (64);
1521          $before_leave->();          $before_leave->();
1522          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1523          !!!next-input-character;          !!!next-input-character;
1524          redo A;          redo A;
1525        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1526          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1527          $before_leave->();          $before_leave->();
1528          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1529            !!!cp (66);            !!!cp (66);
1530            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1531          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1532            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1533            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1534              !!!cp (67);              !!!cp (67);
1535              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1536            } else {            } else {
# Line 1443  sub _get_next_token ($) { Line 1538  sub _get_next_token ($) {
1538              !!!cp (68);              !!!cp (68);
1539            }            }
1540          } else {          } else {
1541            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1542          }          }
1543          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1544          # reconsume          # reconsume
1545    
1546          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1547    
1548          redo A;          redo A;
1549        } else {        } else {
1550          if ($self->{next_char} == 0x0022 or # "          if ($self->{nc} == 0x0022 or # "
1551              $self->{next_char} == 0x0027) { # '              $self->{nc} == 0x0027) { # '
1552            !!!cp (69);            !!!cp (69);
1553            !!!parse-error (type => 'bad attribute name');            !!!parse-error (type => 'bad attribute name');
1554          } else {          } else {
1555            !!!cp (70);            !!!cp (70);
1556          }          }
1557          $self->{current_attribute}->{name} .= chr ($self->{next_char});          $self->{ca}->{name} .= chr ($self->{nc});
1558          ## Stay in the state          ## Stay in the state
1559          !!!next-input-character;          !!!next-input-character;
1560          redo A;          redo A;
1561        }        }
1562      } elsif ($self->{state} == AFTER_ATTRIBUTE_NAME_STATE) {      } elsif ($self->{state} == AFTER_ATTRIBUTE_NAME_STATE) {
1563        if ($self->{next_char} == 0x0009 or # HT        if ($self->{nc} == 0x0009 or # HT
1564            $self->{next_char} == 0x000A or # LF            $self->{nc} == 0x000A or # LF
1565            $self->{next_char} == 0x000B or # VT            $self->{nc} == 0x000B or # VT
1566            $self->{next_char} == 0x000C or # FF            $self->{nc} == 0x000C or # FF
1567            $self->{next_char} == 0x0020) { # SP            $self->{nc} == 0x0020) { # SP
1568          !!!cp (71);          !!!cp (71);
1569          ## Stay in the state          ## Stay in the state
1570          !!!next-input-character;          !!!next-input-character;
1571          redo A;          redo A;
1572        } elsif ($self->{next_char} == 0x003D) { # =        } elsif ($self->{nc} == 0x003D) { # =
1573          !!!cp (72);          !!!cp (72);
1574          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;
1575          !!!next-input-character;          !!!next-input-character;
1576          redo A;          redo A;
1577        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1578          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1579            !!!cp (73);            !!!cp (73);
1580            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1581          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1582            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1583            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1584              !!!cp (74);              !!!cp (74);
1585              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1586            } else {            } else {
# Line 1493  sub _get_next_token ($) { Line 1588  sub _get_next_token ($) {
1588              !!!cp (75);              !!!cp (75);
1589            }            }
1590          } else {          } else {
1591            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1592          }          }
1593          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1594          !!!next-input-character;          !!!next-input-character;
1595    
1596          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1597    
1598          redo A;          redo A;
1599        } elsif (0x0041 <= $self->{next_char} and        } elsif (0x0041 <= $self->{nc} and
1600                 $self->{next_char} <= 0x005A) { # A..Z                 $self->{nc} <= 0x005A) { # A..Z
1601          !!!cp (76);          !!!cp (76);
1602          $self->{current_attribute}          $self->{ca}
1603              = {name => chr ($self->{next_char} + 0x0020),              = {name => chr ($self->{nc} + 0x0020),
1604                 value => '',                 value => '',
1605                 line => $self->{line}, column => $self->{column}};                 line => $self->{line}, column => $self->{column}};
1606          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
1607          !!!next-input-character;          !!!next-input-character;
1608          redo A;          redo A;
1609        } elsif ($self->{next_char} == 0x002F) { # /        } elsif ($self->{nc} == 0x002F) { # /
1610          !!!cp (77);          !!!cp (77);
1611          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1612          !!!next-input-character;          !!!next-input-character;
1613          redo A;          redo A;
1614        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1615          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1616          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1617            !!!cp (79);            !!!cp (79);
1618            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1619          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1620            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1621            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1622              !!!cp (80);              !!!cp (80);
1623              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1624            } else {            } else {
# Line 1531  sub _get_next_token ($) { Line 1626  sub _get_next_token ($) {
1626              !!!cp (81);              !!!cp (81);
1627            }            }
1628          } else {          } else {
1629            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1630          }          }
1631          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1632          # reconsume          # reconsume
1633    
1634          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1635    
1636          redo A;          redo A;
1637        } else {        } else {
1638          !!!cp (82);          if ($self->{nc} == 0x0022 or # "
1639          $self->{current_attribute}              $self->{nc} == 0x0027) { # '
1640              = {name => chr ($self->{next_char}),            !!!cp (78);
1641              !!!parse-error (type => 'bad attribute name');
1642            } else {
1643              !!!cp (82);
1644            }
1645            $self->{ca}
1646                = {name => chr ($self->{nc}),
1647                 value => '',                 value => '',
1648                 line => $self->{line}, column => $self->{column}};                 line => $self->{line}, column => $self->{column}};
1649          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
# Line 1550  sub _get_next_token ($) { Line 1651  sub _get_next_token ($) {
1651          redo A;                  redo A;        
1652        }        }
1653      } elsif ($self->{state} == BEFORE_ATTRIBUTE_VALUE_STATE) {      } elsif ($self->{state} == BEFORE_ATTRIBUTE_VALUE_STATE) {
1654        if ($self->{next_char} == 0x0009 or # HT        if ($self->{nc} == 0x0009 or # HT
1655            $self->{next_char} == 0x000A or # LF            $self->{nc} == 0x000A or # LF
1656            $self->{next_char} == 0x000B or # VT            $self->{nc} == 0x000B or # VT
1657            $self->{next_char} == 0x000C or # FF            $self->{nc} == 0x000C or # FF
1658            $self->{next_char} == 0x0020) { # SP                  $self->{nc} == 0x0020) { # SP      
1659          !!!cp (83);          !!!cp (83);
1660          ## Stay in the state          ## Stay in the state
1661          !!!next-input-character;          !!!next-input-character;
1662          redo A;          redo A;
1663        } elsif ($self->{next_char} == 0x0022) { # "        } elsif ($self->{nc} == 0x0022) { # "
1664          !!!cp (84);          !!!cp (84);
1665          $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;          $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
1666          !!!next-input-character;          !!!next-input-character;
1667          redo A;          redo A;
1668        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{nc} == 0x0026) { # &
1669          !!!cp (85);          !!!cp (85);
1670          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
1671          ## reconsume          ## reconsume
1672          redo A;          redo A;
1673        } elsif ($self->{next_char} == 0x0027) { # '        } elsif ($self->{nc} == 0x0027) { # '
1674          !!!cp (86);          !!!cp (86);
1675          $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;          $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
1676          !!!next-input-character;          !!!next-input-character;
1677          redo A;          redo A;
1678        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1679          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          !!!parse-error (type => 'empty unquoted attribute value');
1680            if ($self->{ct}->{type} == START_TAG_TOKEN) {
1681            !!!cp (87);            !!!cp (87);
1682            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1683          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1684            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1685            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1686              !!!cp (88);              !!!cp (88);
1687              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1688            } else {            } else {
# Line 1588  sub _get_next_token ($) { Line 1690  sub _get_next_token ($) {
1690              !!!cp (89);              !!!cp (89);
1691            }            }
1692          } else {          } else {
1693            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1694          }          }
1695          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1696          !!!next-input-character;          !!!next-input-character;
1697    
1698          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1699    
1700          redo A;          redo A;
1701        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1702          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1703          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1704            !!!cp (90);            !!!cp (90);
1705            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1706          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1707            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1708            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1709              !!!cp (91);              !!!cp (91);
1710              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1711            } else {            } else {
# Line 1611  sub _get_next_token ($) { Line 1713  sub _get_next_token ($) {
1713              !!!cp (92);              !!!cp (92);
1714            }            }
1715          } else {          } else {
1716            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1717          }          }
1718          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1719          ## reconsume          ## reconsume
1720    
1721          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1722    
1723          redo A;          redo A;
1724        } else {        } else {
1725          if ($self->{next_char} == 0x003D) { # =          if ($self->{nc} == 0x003D) { # =
1726            !!!cp (93);            !!!cp (93);
1727            !!!parse-error (type => 'bad attribute value');            !!!parse-error (type => 'bad attribute value');
1728          } else {          } else {
1729            !!!cp (94);            !!!cp (94);
1730          }          }
1731          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{ca}->{value} .= chr ($self->{nc});
1732          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
1733          !!!next-input-character;          !!!next-input-character;
1734          redo A;          redo A;
1735        }        }
1736      } elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) {
1737        if ($self->{next_char} == 0x0022) { # "        if ($self->{nc} == 0x0022) { # "
1738          !!!cp (95);          !!!cp (95);
1739          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;
1740          !!!next-input-character;          !!!next-input-character;
1741          redo A;          redo A;
1742        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{nc} == 0x0026) { # &
1743          !!!cp (96);          !!!cp (96);
1744          $self->{last_attribute_value_state} = $self->{state};          ## NOTE: In the spec, the tokenizer is switched to the
1745          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## "entity in attribute value state".  In this implementation, the
1746            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1747            ## implementation of the "consume a character reference" algorithm.
1748            $self->{prev_state} = $self->{state};
1749            $self->{entity_add} = 0x0022; # "
1750            $self->{state} = ENTITY_STATE;
1751          !!!next-input-character;          !!!next-input-character;
1752          redo A;          redo A;
1753        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1754          !!!parse-error (type => 'unclosed attribute value');          !!!parse-error (type => 'unclosed attribute value');
1755          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1756            !!!cp (97);            !!!cp (97);
1757            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1758          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1759            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1760            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1761              !!!cp (98);              !!!cp (98);
1762              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1763            } else {            } else {
# Line 1658  sub _get_next_token ($) { Line 1765  sub _get_next_token ($) {
1765              !!!cp (99);              !!!cp (99);
1766            }            }
1767          } else {          } else {
1768            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1769          }          }
1770          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1771          ## reconsume          ## reconsume
1772    
1773          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1774    
1775          redo A;          redo A;
1776        } else {        } else {
1777          !!!cp (100);          !!!cp (100);
1778          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{ca}->{value} .= chr ($self->{nc});
1779            $self->{read_until}->($self->{ca}->{value},
1780                                  q["&],
1781                                  length $self->{ca}->{value});
1782    
1783          ## Stay in the state          ## Stay in the state
1784          !!!next-input-character;          !!!next-input-character;
1785          redo A;          redo A;
1786        }        }
1787      } elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) {
1788        if ($self->{next_char} == 0x0027) { # '        if ($self->{nc} == 0x0027) { # '
1789          !!!cp (101);          !!!cp (101);
1790          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;
1791          !!!next-input-character;          !!!next-input-character;
1792          redo A;          redo A;
1793        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{nc} == 0x0026) { # &
1794          !!!cp (102);          !!!cp (102);
1795          $self->{last_attribute_value_state} = $self->{state};          ## NOTE: In the spec, the tokenizer is switched to the
1796          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## "entity in attribute value state".  In this implementation, the
1797            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1798            ## implementation of the "consume a character reference" algorithm.
1799            $self->{entity_add} = 0x0027; # '
1800            $self->{prev_state} = $self->{state};
1801            $self->{state} = ENTITY_STATE;
1802          !!!next-input-character;          !!!next-input-character;
1803          redo A;          redo A;
1804        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1805          !!!parse-error (type => 'unclosed attribute value');          !!!parse-error (type => 'unclosed attribute value');
1806          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1807            !!!cp (103);            !!!cp (103);
1808            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1809          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1810            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1811            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1812              !!!cp (104);              !!!cp (104);
1813              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1814            } else {            } else {
# Line 1700  sub _get_next_token ($) { Line 1816  sub _get_next_token ($) {
1816              !!!cp (105);              !!!cp (105);
1817            }            }
1818          } else {          } else {
1819            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1820          }          }
1821          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1822          ## reconsume          ## reconsume
1823    
1824          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1825    
1826          redo A;          redo A;
1827        } else {        } else {
1828          !!!cp (106);          !!!cp (106);
1829          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{ca}->{value} .= chr ($self->{nc});
1830            $self->{read_until}->($self->{ca}->{value},
1831                                  q['&],
1832                                  length $self->{ca}->{value});
1833    
1834          ## Stay in the state          ## Stay in the state
1835          !!!next-input-character;          !!!next-input-character;
1836          redo A;          redo A;
1837        }        }
1838      } elsif ($self->{state} == ATTRIBUTE_VALUE_UNQUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_UNQUOTED_STATE) {
1839        if ($self->{next_char} == 0x0009 or # HT        if ($self->{nc} == 0x0009 or # HT
1840            $self->{next_char} == 0x000A or # LF            $self->{nc} == 0x000A or # LF
1841            $self->{next_char} == 0x000B or # HT            $self->{nc} == 0x000B or # HT
1842            $self->{next_char} == 0x000C or # FF            $self->{nc} == 0x000C or # FF
1843            $self->{next_char} == 0x0020) { # SP            $self->{nc} == 0x0020) { # SP
1844          !!!cp (107);          !!!cp (107);
1845          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1846          !!!next-input-character;          !!!next-input-character;
1847          redo A;          redo A;
1848        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{nc} == 0x0026) { # &
1849          !!!cp (108);          !!!cp (108);
1850          $self->{last_attribute_value_state} = $self->{state};          ## NOTE: In the spec, the tokenizer is switched to the
1851          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## "entity in attribute value state".  In this implementation, the
1852            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1853            ## implementation of the "consume a character reference" algorithm.
1854            $self->{entity_add} = -1;
1855            $self->{prev_state} = $self->{state};
1856            $self->{state} = ENTITY_STATE;
1857          !!!next-input-character;          !!!next-input-character;
1858          redo A;          redo A;
1859        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1860          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1861            !!!cp (109);            !!!cp (109);
1862            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1863          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1864            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1865            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1866              !!!cp (110);              !!!cp (110);
1867              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1868            } else {            } else {
# Line 1745  sub _get_next_token ($) { Line 1870  sub _get_next_token ($) {
1870              !!!cp (111);              !!!cp (111);
1871            }            }
1872          } else {          } else {
1873            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1874          }          }
1875          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1876          !!!next-input-character;          !!!next-input-character;
1877    
1878          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1879    
1880          redo A;          redo A;
1881        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1882          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1883          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1884            !!!cp (112);            !!!cp (112);
1885            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1886          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1887            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1888            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1889              !!!cp (113);              !!!cp (113);
1890              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1891            } else {            } else {
# Line 1768  sub _get_next_token ($) { Line 1893  sub _get_next_token ($) {
1893              !!!cp (114);              !!!cp (114);
1894            }            }
1895          } else {          } else {
1896            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1897          }          }
1898          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1899          ## reconsume          ## reconsume
1900    
1901          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1902    
1903          redo A;          redo A;
1904        } else {        } else {
# Line 1781  sub _get_next_token ($) { Line 1906  sub _get_next_token ($) {
1906               0x0022 => 1, # "               0x0022 => 1, # "
1907               0x0027 => 1, # '               0x0027 => 1, # '
1908               0x003D => 1, # =               0x003D => 1, # =
1909              }->{$self->{next_char}}) {              }->{$self->{nc}}) {
1910            !!!cp (115);            !!!cp (115);
1911            !!!parse-error (type => 'bad attribute value');            !!!parse-error (type => 'bad attribute value');
1912          } else {          } else {
1913            !!!cp (116);            !!!cp (116);
1914          }          }
1915          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{ca}->{value} .= chr ($self->{nc});
1916            $self->{read_until}->($self->{ca}->{value},
1917                                  q["'=& >],
1918                                  length $self->{ca}->{value});
1919    
1920          ## Stay in the state          ## Stay in the state
1921          !!!next-input-character;          !!!next-input-character;
1922          redo A;          redo A;
1923        }        }
     } 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;  
1924      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {
1925        if ($self->{next_char} == 0x0009 or # HT        if ($self->{nc} == 0x0009 or # HT
1926            $self->{next_char} == 0x000A or # LF            $self->{nc} == 0x000A or # LF
1927            $self->{next_char} == 0x000B or # VT            $self->{nc} == 0x000B or # VT
1928            $self->{next_char} == 0x000C or # FF            $self->{nc} == 0x000C or # FF
1929            $self->{next_char} == 0x0020) { # SP            $self->{nc} == 0x0020) { # SP
1930          !!!cp (118);          !!!cp (118);
1931          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1932          !!!next-input-character;          !!!next-input-character;
1933          redo A;          redo A;
1934        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1935          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1936            !!!cp (119);            !!!cp (119);
1937            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1938          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1939            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1940            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1941              !!!cp (120);              !!!cp (120);
1942              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1943            } else {            } else {
# Line 1838  sub _get_next_token ($) { Line 1945  sub _get_next_token ($) {
1945              !!!cp (121);              !!!cp (121);
1946            }            }
1947          } else {          } else {
1948            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1949          }          }
1950          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1951          !!!next-input-character;          !!!next-input-character;
1952    
1953          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1954    
1955          redo A;          redo A;
1956        } elsif ($self->{next_char} == 0x002F) { # /        } elsif ($self->{nc} == 0x002F) { # /
1957          !!!cp (122);          !!!cp (122);
1958          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1959          !!!next-input-character;          !!!next-input-character;
1960          redo A;          redo A;
1961        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1962          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1963          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1964            !!!cp (122.3);            !!!cp (122.3);
1965            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1966          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1967            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1968              !!!cp (122.1);              !!!cp (122.1);
1969              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1970            } else {            } else {
# Line 1865  sub _get_next_token ($) { Line 1972  sub _get_next_token ($) {
1972              !!!cp (122.2);              !!!cp (122.2);
1973            }            }
1974          } else {          } else {
1975            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1976          }          }
1977          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1978          ## Reconsume.          ## Reconsume.
1979          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1980          redo A;          redo A;
1981        } else {        } else {
1982          !!!cp ('124.1');          !!!cp ('124.1');
# Line 1879  sub _get_next_token ($) { Line 1986  sub _get_next_token ($) {
1986          redo A;          redo A;
1987        }        }
1988      } elsif ($self->{state} == SELF_CLOSING_START_TAG_STATE) {      } elsif ($self->{state} == SELF_CLOSING_START_TAG_STATE) {
1989        if ($self->{next_char} == 0x003E) { # >        if ($self->{nc} == 0x003E) { # >
1990          if ($self->{current_token}->{type} == END_TAG_TOKEN) {          if ($self->{ct}->{type} == END_TAG_TOKEN) {
1991            !!!cp ('124.2');            !!!cp ('124.2');
1992            !!!parse-error (type => 'nestc', token => $self->{current_token});            !!!parse-error (type => 'nestc', token => $self->{ct});
1993            ## TODO: Different type than slash in start tag            ## TODO: Different type than slash in start tag
1994            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1995            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1996              !!!cp ('124.4');              !!!cp ('124.4');
1997              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1998            } else {            } else {
# Line 1900  sub _get_next_token ($) { Line 2007  sub _get_next_token ($) {
2007          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2008          !!!next-input-character;          !!!next-input-character;
2009    
2010          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
2011    
2012          redo A;          redo A;
2013        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2014          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
2015          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
2016            !!!cp (124.7);            !!!cp (124.7);
2017            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
2018          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
2019            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
2020              !!!cp (124.5);              !!!cp (124.5);
2021              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
2022            } else {            } else {
# Line 1917  sub _get_next_token ($) { Line 2024  sub _get_next_token ($) {
2024              !!!cp (124.6);              !!!cp (124.6);
2025            }            }
2026          } else {          } else {
2027            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
2028          }          }
2029          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2030          ## Reconsume.          ## Reconsume.
2031          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
2032          redo A;          redo A;
2033        } else {        } else {
2034          !!!cp ('124.4');          !!!cp ('124.4');
# Line 1933  sub _get_next_token ($) { Line 2040  sub _get_next_token ($) {
2040        }        }
2041      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {
2042        ## (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;  
2043    
2044            !!!emit ($self->{current_token}); # comment        ## NOTE: Unlike spec's "bogus comment state", this implementation
2045          ## consumes characters one-by-one basis.
2046            redo A;        
2047          } elsif ($self->{next_char} == -1) {        if ($self->{nc} == 0x003E) { # >
2048            !!!cp (125);          !!!cp (124);
2049            $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2050            ## reconsume          !!!next-input-character;
2051    
2052            !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2053            redo A;
2054          } elsif ($self->{nc} == -1) {
2055            !!!cp (125);
2056            $self->{state} = DATA_STATE;
2057            ## reconsume
2058    
2059            redo A;          !!!emit ($self->{ct}); # comment
2060          } else {          redo A;
2061            !!!cp (126);        } else {
2062            $self->{current_token}->{data} .= chr ($self->{next_char}); # comment          !!!cp (126);
2063            !!!next-input-character;          $self->{ct}->{data} .= chr ($self->{nc}); # comment
2064            redo BC;          $self->{read_until}->($self->{ct}->{data},
2065          }                                q[>],
2066        } # BC                                length $self->{ct}->{data});
2067    
2068        die "$0: _get_next_token: unexpected case [BC]";          ## Stay in the state.
2069            !!!next-input-character;
2070            redo A;
2071          }
2072      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {
2073        ## (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};  
2074                
2075        if ($self->{next_char} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
2076            !!!cp (133);
2077            $self->{state} = MD_HYPHEN_STATE;
2078          !!!next-input-character;          !!!next-input-character;
2079          push @next_char, $self->{next_char};          redo A;
2080          if ($self->{next_char} == 0x002D) { # -        } elsif ($self->{nc} == 0x0044 or # D
2081            !!!cp (127);                 $self->{nc} == 0x0064) { # d
2082            $self->{current_token} = {type => COMMENT_TOKEN, data => '',          ## ASCII case-insensitive.
2083                                      line => $l, column => $c,          !!!cp (130);
2084                                     };          $self->{state} = MD_DOCTYPE_STATE;
2085            $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  
2086          !!!next-input-character;          !!!next-input-character;
2087          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);  
         }  
2088        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and
2089                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and
2090                 $self->{next_char} == 0x005B) { # [                 $self->{nc} == 0x005B) { # [
2091            !!!cp (135.4);                
2092            $self->{state} = MD_CDATA_STATE;
2093            $self->{s_kwd} = '[';
2094          !!!next-input-character;          !!!next-input-character;
2095          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);  
         }  
2096        } else {        } else {
2097          !!!cp (136);          !!!cp (136);
2098        }        }
2099    
2100        !!!parse-error (type => 'bogus comment');        !!!parse-error (type => 'bogus comment',
2101        $self->{next_char} = shift @next_char;                        line => $self->{line_prev},
2102        !!!back-next-input-character (@next_char);                        column => $self->{column_prev} - 1);
2103          ## Reconsume.
2104        $self->{state} = BOGUS_COMMENT_STATE;        $self->{state} = BOGUS_COMMENT_STATE;
2105        $self->{current_token} = {type => COMMENT_TOKEN, data => '',        $self->{ct} = {type => COMMENT_TOKEN, data => '',
2106                                  line => $l, column => $c,                                  line => $self->{line_prev},
2107                                    column => $self->{column_prev} - 1,
2108                                 };                                 };
2109        redo A;        redo A;
2110              } elsif ($self->{state} == MD_HYPHEN_STATE) {
2111        ## ISSUE: typos in spec: chacacters, is is a parse error        if ($self->{nc} == 0x002D) { # -
2112        ## 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);
2113            $self->{ct} = {type => COMMENT_TOKEN, data => '',
2114                                      line => $self->{line_prev},
2115                                      column => $self->{column_prev} - 2,
2116                                     };
2117            $self->{state} = COMMENT_START_STATE;
2118            !!!next-input-character;
2119            redo A;
2120          } else {
2121            !!!cp (128);
2122            !!!parse-error (type => 'bogus comment',
2123                            line => $self->{line_prev},
2124                            column => $self->{column_prev} - 2);
2125            $self->{state} = BOGUS_COMMENT_STATE;
2126            ## Reconsume.
2127            $self->{ct} = {type => COMMENT_TOKEN,
2128                                      data => '-',
2129                                      line => $self->{line_prev},
2130                                      column => $self->{column_prev} - 2,
2131                                     };
2132            redo A;
2133          }
2134        } elsif ($self->{state} == MD_DOCTYPE_STATE) {
2135          ## ASCII case-insensitive.
2136          if ($self->{nc} == [
2137                undef,
2138                0x004F, # O
2139                0x0043, # C
2140                0x0054, # T
2141                0x0059, # Y
2142                0x0050, # P
2143              ]->[length $self->{s_kwd}] or
2144              $self->{nc} == [
2145                undef,
2146                0x006F, # o
2147                0x0063, # c
2148                0x0074, # t
2149                0x0079, # y
2150                0x0070, # p
2151              ]->[length $self->{s_kwd}]) {
2152            !!!cp (131);
2153            ## Stay in the state.
2154            $self->{s_kwd} .= chr $self->{nc};
2155            !!!next-input-character;
2156            redo A;
2157          } elsif ((length $self->{s_kwd}) == 6 and
2158                   ($self->{nc} == 0x0045 or # E
2159                    $self->{nc} == 0x0065)) { # e
2160            !!!cp (129);
2161            $self->{state} = DOCTYPE_STATE;
2162            $self->{ct} = {type => DOCTYPE_TOKEN,
2163                                      quirks => 1,
2164                                      line => $self->{line_prev},
2165                                      column => $self->{column_prev} - 7,
2166                                     };
2167            !!!next-input-character;
2168            redo A;
2169          } else {
2170            !!!cp (132);        
2171            !!!parse-error (type => 'bogus comment',
2172                            line => $self->{line_prev},
2173                            column => $self->{column_prev} - 1 - length $self->{s_kwd});
2174            $self->{state} = BOGUS_COMMENT_STATE;
2175            ## Reconsume.
2176            $self->{ct} = {type => COMMENT_TOKEN,
2177                                      data => $self->{s_kwd},
2178                                      line => $self->{line_prev},
2179                                      column => $self->{column_prev} - 1 - length $self->{s_kwd},
2180                                     };
2181            redo A;
2182          }
2183        } elsif ($self->{state} == MD_CDATA_STATE) {
2184          if ($self->{nc} == {
2185                '[' => 0x0043, # C
2186                '[C' => 0x0044, # D
2187                '[CD' => 0x0041, # A
2188                '[CDA' => 0x0054, # T
2189                '[CDAT' => 0x0041, # A
2190              }->{$self->{s_kwd}}) {
2191            !!!cp (135.1);
2192            ## Stay in the state.
2193            $self->{s_kwd} .= chr $self->{nc};
2194            !!!next-input-character;
2195            redo A;
2196          } elsif ($self->{s_kwd} eq '[CDATA' and
2197                   $self->{nc} == 0x005B) { # [
2198            !!!cp (135.2);
2199            $self->{ct} = {type => CHARACTER_TOKEN,
2200                                      data => '',
2201                                      line => $self->{line_prev},
2202                                      column => $self->{column_prev} - 7};
2203            $self->{state} = CDATA_SECTION_STATE;
2204            !!!next-input-character;
2205            redo A;
2206          } else {
2207            !!!cp (135.3);
2208            !!!parse-error (type => 'bogus comment',
2209                            line => $self->{line_prev},
2210                            column => $self->{column_prev} - 1 - length $self->{s_kwd});
2211            $self->{state} = BOGUS_COMMENT_STATE;
2212            ## Reconsume.
2213            $self->{ct} = {type => COMMENT_TOKEN,
2214                                      data => $self->{s_kwd},
2215                                      line => $self->{line_prev},
2216                                      column => $self->{column_prev} - 1 - length $self->{s_kwd},
2217                                     };
2218            redo A;
2219          }
2220      } elsif ($self->{state} == COMMENT_START_STATE) {      } elsif ($self->{state} == COMMENT_START_STATE) {
2221        if ($self->{next_char} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
2222          !!!cp (137);          !!!cp (137);
2223          $self->{state} = COMMENT_START_DASH_STATE;          $self->{state} = COMMENT_START_DASH_STATE;
2224          !!!next-input-character;          !!!next-input-character;
2225          redo A;          redo A;
2226        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2227          !!!cp (138);          !!!cp (138);
2228          !!!parse-error (type => 'bogus comment');          !!!parse-error (type => 'bogus comment');
2229          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2230          !!!next-input-character;          !!!next-input-character;
2231    
2232          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2233    
2234          redo A;          redo A;
2235        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2236          !!!cp (139);          !!!cp (139);
2237          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
2238          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2239          ## reconsume          ## reconsume
2240    
2241          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2242    
2243          redo A;          redo A;
2244        } else {        } else {
2245          !!!cp (140);          !!!cp (140);
2246          $self->{current_token}->{data} # comment          $self->{ct}->{data} # comment
2247              .= chr ($self->{next_char});              .= chr ($self->{nc});
2248          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
2249          !!!next-input-character;          !!!next-input-character;
2250          redo A;          redo A;
2251        }        }
2252      } elsif ($self->{state} == COMMENT_START_DASH_STATE) {      } elsif ($self->{state} == COMMENT_START_DASH_STATE) {
2253        if ($self->{next_char} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
2254          !!!cp (141);          !!!cp (141);
2255          $self->{state} = COMMENT_END_STATE;          $self->{state} = COMMENT_END_STATE;
2256          !!!next-input-character;          !!!next-input-character;
2257          redo A;          redo A;
2258        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2259          !!!cp (142);          !!!cp (142);
2260          !!!parse-error (type => 'bogus comment');          !!!parse-error (type => 'bogus comment');
2261          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2262          !!!next-input-character;          !!!next-input-character;
2263    
2264          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2265    
2266          redo A;          redo A;
2267        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2268          !!!cp (143);          !!!cp (143);
2269          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
2270          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2271          ## reconsume          ## reconsume
2272    
2273          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2274    
2275          redo A;          redo A;
2276        } else {        } else {
2277          !!!cp (144);          !!!cp (144);
2278          $self->{current_token}->{data} # comment          $self->{ct}->{data} # comment
2279              .= '-' . chr ($self->{next_char});              .= '-' . chr ($self->{nc});
2280          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
2281          !!!next-input-character;          !!!next-input-character;
2282          redo A;          redo A;
2283        }        }
2284      } elsif ($self->{state} == COMMENT_STATE) {      } elsif ($self->{state} == COMMENT_STATE) {
2285        if ($self->{next_char} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
2286          !!!cp (145);          !!!cp (145);
2287          $self->{state} = COMMENT_END_DASH_STATE;          $self->{state} = COMMENT_END_DASH_STATE;
2288          !!!next-input-character;          !!!next-input-character;
2289          redo A;          redo A;
2290        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2291          !!!cp (146);          !!!cp (146);
2292          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
2293          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2294          ## reconsume          ## reconsume
2295    
2296          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2297    
2298          redo A;          redo A;
2299        } else {        } else {
2300          !!!cp (147);          !!!cp (147);
2301          $self->{current_token}->{data} .= chr ($self->{next_char}); # comment          $self->{ct}->{data} .= chr ($self->{nc}); # comment
2302            $self->{read_until}->($self->{ct}->{data},
2303                                  q[-],
2304                                  length $self->{ct}->{data});
2305    
2306          ## Stay in the state          ## Stay in the state
2307          !!!next-input-character;          !!!next-input-character;
2308          redo A;          redo A;
2309        }        }
2310      } elsif ($self->{state} == COMMENT_END_DASH_STATE) {      } elsif ($self->{state} == COMMENT_END_DASH_STATE) {
2311        if ($self->{next_char} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
2312          !!!cp (148);          !!!cp (148);
2313          $self->{state} = COMMENT_END_STATE;          $self->{state} = COMMENT_END_STATE;
2314          !!!next-input-character;          !!!next-input-character;
2315          redo A;          redo A;
2316        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2317          !!!cp (149);          !!!cp (149);
2318          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
2319          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2320          ## reconsume          ## reconsume
2321    
2322          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2323    
2324          redo A;          redo A;
2325        } else {        } else {
2326          !!!cp (150);          !!!cp (150);
2327          $self->{current_token}->{data} .= '-' . chr ($self->{next_char}); # comment          $self->{ct}->{data} .= '-' . chr ($self->{nc}); # comment
2328          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
2329          !!!next-input-character;          !!!next-input-character;
2330          redo A;          redo A;
2331        }        }
2332      } elsif ($self->{state} == COMMENT_END_STATE) {      } elsif ($self->{state} == COMMENT_END_STATE) {
2333        if ($self->{next_char} == 0x003E) { # >        if ($self->{nc} == 0x003E) { # >
2334          !!!cp (151);          !!!cp (151);
2335          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2336          !!!next-input-character;          !!!next-input-character;
2337    
2338          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2339    
2340          redo A;          redo A;
2341        } elsif ($self->{next_char} == 0x002D) { # -        } elsif ($self->{nc} == 0x002D) { # -
2342          !!!cp (152);          !!!cp (152);
2343          !!!parse-error (type => 'dash in comment',          !!!parse-error (type => 'dash in comment',
2344                          line => $self->{line_prev},                          line => $self->{line_prev},
2345                          column => $self->{column_prev});                          column => $self->{column_prev});
2346          $self->{current_token}->{data} .= '-'; # comment          $self->{ct}->{data} .= '-'; # comment
2347          ## Stay in the state          ## Stay in the state
2348          !!!next-input-character;          !!!next-input-character;
2349          redo A;          redo A;
2350        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2351          !!!cp (153);          !!!cp (153);
2352          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
2353          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2354          ## reconsume          ## reconsume
2355    
2356          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2357    
2358          redo A;          redo A;
2359        } else {        } else {
# Line 2236  sub _get_next_token ($) { Line 2361  sub _get_next_token ($) {
2361          !!!parse-error (type => 'dash in comment',          !!!parse-error (type => 'dash in comment',
2362                          line => $self->{line_prev},                          line => $self->{line_prev},
2363                          column => $self->{column_prev});                          column => $self->{column_prev});
2364          $self->{current_token}->{data} .= '--' . chr ($self->{next_char}); # comment          $self->{ct}->{data} .= '--' . chr ($self->{nc}); # comment
2365          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
2366          !!!next-input-character;          !!!next-input-character;
2367          redo A;          redo A;
2368        }        }
2369      } elsif ($self->{state} == DOCTYPE_STATE) {      } elsif ($self->{state} == DOCTYPE_STATE) {
2370        if ($self->{next_char} == 0x0009 or # HT        if ($self->{nc} == 0x0009 or # HT
2371            $self->{next_char} == 0x000A or # LF            $self->{nc} == 0x000A or # LF
2372            $self->{next_char} == 0x000B or # VT            $self->{nc} == 0x000B or # VT
2373            $self->{next_char} == 0x000C or # FF            $self->{nc} == 0x000C or # FF
2374            $self->{next_char} == 0x0020) { # SP            $self->{nc} == 0x0020) { # SP
2375          !!!cp (155);          !!!cp (155);
2376          $self->{state} = BEFORE_DOCTYPE_NAME_STATE;          $self->{state} = BEFORE_DOCTYPE_NAME_STATE;
2377          !!!next-input-character;          !!!next-input-character;
# Line 2259  sub _get_next_token ($) { Line 2384  sub _get_next_token ($) {
2384          redo A;          redo A;
2385        }        }
2386      } elsif ($self->{state} == BEFORE_DOCTYPE_NAME_STATE) {      } elsif ($self->{state} == BEFORE_DOCTYPE_NAME_STATE) {
2387        if ($self->{next_char} == 0x0009 or # HT        if ($self->{nc} == 0x0009 or # HT
2388            $self->{next_char} == 0x000A or # LF            $self->{nc} == 0x000A or # LF
2389            $self->{next_char} == 0x000B or # VT            $self->{nc} == 0x000B or # VT
2390            $self->{next_char} == 0x000C or # FF            $self->{nc} == 0x000C or # FF
2391            $self->{next_char} == 0x0020) { # SP            $self->{nc} == 0x0020) { # SP
2392          !!!cp (157);          !!!cp (157);
2393          ## Stay in the state          ## Stay in the state
2394          !!!next-input-character;          !!!next-input-character;
2395          redo A;          redo A;
2396        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2397          !!!cp (158);          !!!cp (158);
2398          !!!parse-error (type => 'no DOCTYPE name');          !!!parse-error (type => 'no DOCTYPE name');
2399          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2400          !!!next-input-character;          !!!next-input-character;
2401    
2402          !!!emit ($self->{current_token}); # DOCTYPE (quirks)          !!!emit ($self->{ct}); # DOCTYPE (quirks)
2403    
2404          redo A;          redo A;
2405        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2406          !!!cp (159);          !!!cp (159);
2407          !!!parse-error (type => 'no DOCTYPE name');          !!!parse-error (type => 'no DOCTYPE name');
2408          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2409          ## reconsume          ## reconsume
2410    
2411          !!!emit ($self->{current_token}); # DOCTYPE (quirks)          !!!emit ($self->{ct}); # DOCTYPE (quirks)
2412    
2413          redo A;          redo A;
2414        } else {        } else {
2415          !!!cp (160);          !!!cp (160);
2416          $self->{current_token}->{name} = chr $self->{next_char};          $self->{ct}->{name} = chr $self->{nc};
2417          delete $self->{current_token}->{quirks};          delete $self->{ct}->{quirks};
2418  ## ISSUE: "Set the token's name name to the" in the spec  ## ISSUE: "Set the token's name name to the" in the spec
2419          $self->{state} = DOCTYPE_NAME_STATE;          $self->{state} = DOCTYPE_NAME_STATE;
2420          !!!next-input-character;          !!!next-input-character;
# Line 2297  sub _get_next_token ($) { Line 2422  sub _get_next_token ($) {
2422        }        }
2423      } elsif ($self->{state} == DOCTYPE_NAME_STATE) {      } elsif ($self->{state} == DOCTYPE_NAME_STATE) {
2424  ## ISSUE: Redundant "First," in the spec.  ## ISSUE: Redundant "First," in the spec.
2425        if ($self->{next_char} == 0x0009 or # HT        if ($self->{nc} == 0x0009 or # HT
2426            $self->{next_char} == 0x000A or # LF            $self->{nc} == 0x000A or # LF
2427            $self->{next_char} == 0x000B or # VT            $self->{nc} == 0x000B or # VT
2428            $self->{next_char} == 0x000C or # FF            $self->{nc} == 0x000C or # FF
2429            $self->{next_char} == 0x0020) { # SP            $self->{nc} == 0x0020) { # SP
2430          !!!cp (161);          !!!cp (161);
2431          $self->{state} = AFTER_DOCTYPE_NAME_STATE;          $self->{state} = AFTER_DOCTYPE_NAME_STATE;
2432          !!!next-input-character;          !!!next-input-character;
2433          redo A;          redo A;
2434        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2435          !!!cp (162);          !!!cp (162);
2436          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2437          !!!next-input-character;          !!!next-input-character;
2438    
2439          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2440    
2441          redo A;          redo A;
2442        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2443          !!!cp (163);          !!!cp (163);
2444          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2445          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2446          ## reconsume          ## reconsume
2447    
2448          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2449          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2450    
2451          redo A;          redo A;
2452        } else {        } else {
2453          !!!cp (164);          !!!cp (164);
2454          $self->{current_token}->{name}          $self->{ct}->{name}
2455            .= chr ($self->{next_char}); # DOCTYPE            .= chr ($self->{nc}); # DOCTYPE
2456          ## Stay in the state          ## Stay in the state
2457          !!!next-input-character;          !!!next-input-character;
2458          redo A;          redo A;
2459        }        }
2460      } elsif ($self->{state} == AFTER_DOCTYPE_NAME_STATE) {      } elsif ($self->{state} == AFTER_DOCTYPE_NAME_STATE) {
2461        if ($self->{next_char} == 0x0009 or # HT        if ($self->{nc} == 0x0009 or # HT
2462            $self->{next_char} == 0x000A or # LF            $self->{nc} == 0x000A or # LF
2463            $self->{next_char} == 0x000B or # VT            $self->{nc} == 0x000B or # VT
2464            $self->{next_char} == 0x000C or # FF            $self->{nc} == 0x000C or # FF
2465            $self->{next_char} == 0x0020) { # SP            $self->{nc} == 0x0020) { # SP
2466          !!!cp (165);          !!!cp (165);
2467          ## Stay in the state          ## Stay in the state
2468          !!!next-input-character;          !!!next-input-character;
2469          redo A;          redo A;
2470        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2471          !!!cp (166);          !!!cp (166);
2472          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2473          !!!next-input-character;          !!!next-input-character;
2474    
2475          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2476    
2477          redo A;          redo A;
2478        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2479          !!!cp (167);          !!!cp (167);
2480          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2481          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2482          ## reconsume          ## reconsume
2483    
2484          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2485          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2486    
2487          redo A;          redo A;
2488        } elsif ($self->{next_char} == 0x0050 or # P        } elsif ($self->{nc} == 0x0050 or # P
2489                 $self->{next_char} == 0x0070) { # p                 $self->{nc} == 0x0070) { # p
2490            $self->{state} = PUBLIC_STATE;
2491            $self->{s_kwd} = chr $self->{nc};
2492          !!!next-input-character;          !!!next-input-character;
2493          if ($self->{next_char} == 0x0055 or # U          redo A;
2494              $self->{next_char} == 0x0075) { # u        } elsif ($self->{nc} == 0x0053 or # S
2495            !!!next-input-character;                 $self->{nc} == 0x0073) { # s
2496            if ($self->{next_char} == 0x0042 or # B          $self->{state} = SYSTEM_STATE;
2497                $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  
2498          !!!next-input-character;          !!!next-input-character;
2499          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);  
         }  
   
         #  
2500        } else {        } else {
2501          !!!cp (180);          !!!cp (180);
2502            !!!parse-error (type => 'string after DOCTYPE name');
2503            $self->{ct}->{quirks} = 1;
2504    
2505            $self->{state} = BOGUS_DOCTYPE_STATE;
2506          !!!next-input-character;          !!!next-input-character;
2507          #          redo A;
2508        }        }
2509        } elsif ($self->{state} == PUBLIC_STATE) {
2510          ## ASCII case-insensitive
2511          if ($self->{nc} == [
2512                undef,
2513                0x0055, # U
2514                0x0042, # B
2515                0x004C, # L
2516                0x0049, # I
2517              ]->[length $self->{s_kwd}] or
2518              $self->{nc} == [
2519                undef,
2520                0x0075, # u
2521                0x0062, # b
2522                0x006C, # l
2523                0x0069, # i
2524              ]->[length $self->{s_kwd}]) {
2525            !!!cp (175);
2526            ## Stay in the state.
2527            $self->{s_kwd} .= chr $self->{nc};
2528            !!!next-input-character;
2529            redo A;
2530          } elsif ((length $self->{s_kwd}) == 5 and
2531                   ($self->{nc} == 0x0043 or # C
2532                    $self->{nc} == 0x0063)) { # c
2533            !!!cp (168);
2534            $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
2535            !!!next-input-character;
2536            redo A;
2537          } else {
2538            !!!cp (169);
2539            !!!parse-error (type => 'string after DOCTYPE name',
2540                            line => $self->{line_prev},
2541                            column => $self->{column_prev} + 1 - length $self->{s_kwd});
2542            $self->{ct}->{quirks} = 1;
2543    
2544        !!!parse-error (type => 'string after DOCTYPE name');          $self->{state} = BOGUS_DOCTYPE_STATE;
2545        $self->{current_token}->{quirks} = 1;          ## Reconsume.
2546            redo A;
2547          }
2548        } elsif ($self->{state} == SYSTEM_STATE) {
2549          ## ASCII case-insensitive
2550          if ($self->{nc} == [
2551                undef,
2552                0x0059, # Y
2553                0x0053, # S
2554                0x0054, # T
2555                0x0045, # E
2556              ]->[length $self->{s_kwd}] or
2557              $self->{nc} == [
2558                undef,
2559                0x0079, # y
2560                0x0073, # s
2561                0x0074, # t
2562                0x0065, # e
2563              ]->[length $self->{s_kwd}]) {
2564            !!!cp (170);
2565            ## Stay in the state.
2566            $self->{s_kwd} .= chr $self->{nc};
2567            !!!next-input-character;
2568            redo A;
2569          } elsif ((length $self->{s_kwd}) == 5 and
2570                   ($self->{nc} == 0x004D or # M
2571                    $self->{nc} == 0x006D)) { # m
2572            !!!cp (171);
2573            $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2574            !!!next-input-character;
2575            redo A;
2576          } else {
2577            !!!cp (172);
2578            !!!parse-error (type => 'string after DOCTYPE name',
2579                            line => $self->{line_prev},
2580                            column => $self->{column_prev} + 1 - length $self->{s_kwd});
2581            $self->{ct}->{quirks} = 1;
2582    
2583        $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2584        # next-input-character is already done          ## Reconsume.
2585        redo A;          redo A;
2586          }
2587      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {
2588        if ({        if ({
2589              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
2590              #0x000D => 1, # HT, LF, VT, FF, SP, CR              #0x000D => 1, # HT, LF, VT, FF, SP, CR
2591            }->{$self->{next_char}}) {            }->{$self->{nc}}) {
2592          !!!cp (181);          !!!cp (181);
2593          ## Stay in the state          ## Stay in the state
2594          !!!next-input-character;          !!!next-input-character;
2595          redo A;          redo A;
2596        } elsif ($self->{next_char} eq 0x0022) { # "        } elsif ($self->{nc} eq 0x0022) { # "
2597          !!!cp (182);          !!!cp (182);
2598          $self->{current_token}->{public_identifier} = ''; # DOCTYPE          $self->{ct}->{pubid} = ''; # DOCTYPE
2599          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE;          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE;
2600          !!!next-input-character;          !!!next-input-character;
2601          redo A;          redo A;
2602        } elsif ($self->{next_char} eq 0x0027) { # '        } elsif ($self->{nc} eq 0x0027) { # '
2603          !!!cp (183);          !!!cp (183);
2604          $self->{current_token}->{public_identifier} = ''; # DOCTYPE          $self->{ct}->{pubid} = ''; # DOCTYPE
2605          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE;          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE;
2606          !!!next-input-character;          !!!next-input-character;
2607          redo A;          redo A;
2608        } elsif ($self->{next_char} eq 0x003E) { # >        } elsif ($self->{nc} eq 0x003E) { # >
2609          !!!cp (184);          !!!cp (184);
2610          !!!parse-error (type => 'no PUBLIC literal');          !!!parse-error (type => 'no PUBLIC literal');
2611    
2612          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2613          !!!next-input-character;          !!!next-input-character;
2614    
2615          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2616          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2617    
2618          redo A;          redo A;
2619        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2620          !!!cp (185);          !!!cp (185);
2621          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2622    
2623          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2624          ## reconsume          ## reconsume
2625    
2626          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2627          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2628    
2629          redo A;          redo A;
2630        } else {        } else {
2631          !!!cp (186);          !!!cp (186);
2632          !!!parse-error (type => 'string after PUBLIC');          !!!parse-error (type => 'string after PUBLIC');
2633          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2634    
2635          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2636          !!!next-input-character;          !!!next-input-character;
2637          redo A;          redo A;
2638        }        }
2639      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE) {
2640        if ($self->{next_char} == 0x0022) { # "        if ($self->{nc} == 0x0022) { # "
2641          !!!cp (187);          !!!cp (187);
2642          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
2643          !!!next-input-character;          !!!next-input-character;
2644          redo A;          redo A;
2645        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2646          !!!cp (188);          !!!cp (188);
2647          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2648    
2649          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2650          !!!next-input-character;          !!!next-input-character;
2651    
2652          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2653          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2654    
2655          redo A;          redo A;
2656        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2657          !!!cp (189);          !!!cp (189);
2658          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2659    
2660          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2661          ## reconsume          ## reconsume
2662    
2663          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2664          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2665    
2666          redo A;          redo A;
2667        } else {        } else {
2668          !!!cp (190);          !!!cp (190);
2669          $self->{current_token}->{public_identifier} # DOCTYPE          $self->{ct}->{pubid} # DOCTYPE
2670              .= chr $self->{next_char};              .= chr $self->{nc};
2671            $self->{read_until}->($self->{ct}->{pubid}, q[">],
2672                                  length $self->{ct}->{pubid});
2673    
2674          ## Stay in the state          ## Stay in the state
2675          !!!next-input-character;          !!!next-input-character;
2676          redo A;          redo A;
2677        }        }
2678      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE) {
2679        if ($self->{next_char} == 0x0027) { # '        if ($self->{nc} == 0x0027) { # '
2680          !!!cp (191);          !!!cp (191);
2681          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
2682          !!!next-input-character;          !!!next-input-character;
2683          redo A;          redo A;
2684        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2685          !!!cp (192);          !!!cp (192);
2686          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2687    
2688          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2689          !!!next-input-character;          !!!next-input-character;
2690    
2691          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2692          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2693    
2694          redo A;          redo A;
2695        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2696          !!!cp (193);          !!!cp (193);
2697          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2698    
2699          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2700          ## reconsume          ## reconsume
2701    
2702          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2703          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2704    
2705          redo A;          redo A;
2706        } else {        } else {
2707          !!!cp (194);          !!!cp (194);
2708          $self->{current_token}->{public_identifier} # DOCTYPE          $self->{ct}->{pubid} # DOCTYPE
2709              .= chr $self->{next_char};              .= chr $self->{nc};
2710            $self->{read_until}->($self->{ct}->{pubid}, q['>],
2711                                  length $self->{ct}->{pubid});
2712    
2713          ## Stay in the state          ## Stay in the state
2714          !!!next-input-character;          !!!next-input-character;
2715          redo A;          redo A;
# Line 2576  sub _get_next_token ($) { Line 2718  sub _get_next_token ($) {
2718        if ({        if ({
2719              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
2720              #0x000D => 1, # HT, LF, VT, FF, SP, CR              #0x000D => 1, # HT, LF, VT, FF, SP, CR
2721            }->{$self->{next_char}}) {            }->{$self->{nc}}) {
2722          !!!cp (195);          !!!cp (195);
2723          ## Stay in the state          ## Stay in the state
2724          !!!next-input-character;          !!!next-input-character;
2725          redo A;          redo A;
2726        } elsif ($self->{next_char} == 0x0022) { # "        } elsif ($self->{nc} == 0x0022) { # "
2727          !!!cp (196);          !!!cp (196);
2728          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{ct}->{sysid} = ''; # DOCTYPE
2729          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;
2730          !!!next-input-character;          !!!next-input-character;
2731          redo A;          redo A;
2732        } elsif ($self->{next_char} == 0x0027) { # '        } elsif ($self->{nc} == 0x0027) { # '
2733          !!!cp (197);          !!!cp (197);
2734          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{ct}->{sysid} = ''; # DOCTYPE
2735          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;
2736          !!!next-input-character;          !!!next-input-character;
2737          redo A;          redo A;
2738        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2739          !!!cp (198);          !!!cp (198);
2740          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2741          !!!next-input-character;          !!!next-input-character;
2742    
2743          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2744    
2745          redo A;          redo A;
2746        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2747          !!!cp (199);          !!!cp (199);
2748          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2749    
2750          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2751          ## reconsume          ## reconsume
2752    
2753          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2754          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2755    
2756          redo A;          redo A;
2757        } else {        } else {
2758          !!!cp (200);          !!!cp (200);
2759          !!!parse-error (type => 'string after PUBLIC literal');          !!!parse-error (type => 'string after PUBLIC literal');
2760          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2761    
2762          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2763          !!!next-input-character;          !!!next-input-character;
# Line 2625  sub _get_next_token ($) { Line 2767  sub _get_next_token ($) {
2767        if ({        if ({
2768              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
2769              #0x000D => 1, # HT, LF, VT, FF, SP, CR              #0x000D => 1, # HT, LF, VT, FF, SP, CR
2770            }->{$self->{next_char}}) {            }->{$self->{nc}}) {
2771          !!!cp (201);          !!!cp (201);
2772          ## Stay in the state          ## Stay in the state
2773          !!!next-input-character;          !!!next-input-character;
2774          redo A;          redo A;
2775        } elsif ($self->{next_char} == 0x0022) { # "        } elsif ($self->{nc} == 0x0022) { # "
2776          !!!cp (202);          !!!cp (202);
2777          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{ct}->{sysid} = ''; # DOCTYPE
2778          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;
2779          !!!next-input-character;          !!!next-input-character;
2780          redo A;          redo A;
2781        } elsif ($self->{next_char} == 0x0027) { # '        } elsif ($self->{nc} == 0x0027) { # '
2782          !!!cp (203);          !!!cp (203);
2783          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{ct}->{sysid} = ''; # DOCTYPE
2784          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;
2785          !!!next-input-character;          !!!next-input-character;
2786          redo A;          redo A;
2787        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2788          !!!cp (204);          !!!cp (204);
2789          !!!parse-error (type => 'no SYSTEM literal');          !!!parse-error (type => 'no SYSTEM literal');
2790          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2791          !!!next-input-character;          !!!next-input-character;
2792    
2793          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2794          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2795    
2796          redo A;          redo A;
2797        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2798          !!!cp (205);          !!!cp (205);
2799          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2800    
2801          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2802          ## reconsume          ## reconsume
2803    
2804          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2805          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2806    
2807          redo A;          redo A;
2808        } else {        } else {
2809          !!!cp (206);          !!!cp (206);
2810          !!!parse-error (type => 'string after SYSTEM');          !!!parse-error (type => 'string after SYSTEM');
2811          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2812    
2813          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2814          !!!next-input-character;          !!!next-input-character;
2815          redo A;          redo A;
2816        }        }
2817      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE) {
2818        if ($self->{next_char} == 0x0022) { # "        if ($self->{nc} == 0x0022) { # "
2819          !!!cp (207);          !!!cp (207);
2820          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2821          !!!next-input-character;          !!!next-input-character;
2822          redo A;          redo A;
2823        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2824          !!!cp (208);          !!!cp (208);
2825          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2826    
2827          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2828          !!!next-input-character;          !!!next-input-character;
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        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2835          !!!cp (209);          !!!cp (209);
2836          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2837    
2838          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2839          ## reconsume          ## reconsume
2840    
2841          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2842          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2843    
2844          redo A;          redo A;
2845        } else {        } else {
2846          !!!cp (210);          !!!cp (210);
2847          $self->{current_token}->{system_identifier} # DOCTYPE          $self->{ct}->{sysid} # DOCTYPE
2848              .= chr $self->{next_char};              .= chr $self->{nc};
2849            $self->{read_until}->($self->{ct}->{sysid}, q[">],
2850                                  length $self->{ct}->{sysid});
2851    
2852          ## Stay in the state          ## Stay in the state
2853          !!!next-input-character;          !!!next-input-character;
2854          redo A;          redo A;
2855        }        }
2856      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE) {
2857        if ($self->{next_char} == 0x0027) { # '        if ($self->{nc} == 0x0027) { # '
2858          !!!cp (211);          !!!cp (211);
2859          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2860          !!!next-input-character;          !!!next-input-character;
2861          redo A;          redo A;
2862        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2863          !!!cp (212);          !!!cp (212);
2864          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2865    
2866          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2867          !!!next-input-character;          !!!next-input-character;
2868    
2869          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2870          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2871    
2872          redo A;          redo A;
2873        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2874          !!!cp (213);          !!!cp (213);
2875          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2876    
2877          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2878          ## reconsume          ## reconsume
2879    
2880          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2881          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2882    
2883          redo A;          redo A;
2884        } else {        } else {
2885          !!!cp (214);          !!!cp (214);
2886          $self->{current_token}->{system_identifier} # DOCTYPE          $self->{ct}->{sysid} # DOCTYPE
2887              .= chr $self->{next_char};              .= chr $self->{nc};
2888            $self->{read_until}->($self->{ct}->{sysid}, q['>],
2889                                  length $self->{ct}->{sysid});
2890    
2891          ## Stay in the state          ## Stay in the state
2892          !!!next-input-character;          !!!next-input-character;
2893          redo A;          redo A;
# Line 2748  sub _get_next_token ($) { Line 2896  sub _get_next_token ($) {
2896        if ({        if ({
2897              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
2898              #0x000D => 1, # HT, LF, VT, FF, SP, CR              #0x000D => 1, # HT, LF, VT, FF, SP, CR
2899            }->{$self->{next_char}}) {            }->{$self->{nc}}) {
2900          !!!cp (215);          !!!cp (215);
2901          ## Stay in the state          ## Stay in the state
2902          !!!next-input-character;          !!!next-input-character;
2903          redo A;          redo A;
2904        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2905          !!!cp (216);          !!!cp (216);
2906          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2907          !!!next-input-character;          !!!next-input-character;
2908    
2909          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2910    
2911          redo A;          redo A;
2912        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2913          !!!cp (217);          !!!cp (217);
2914          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2915          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2916          ## reconsume          ## reconsume
2917    
2918          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2919          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2920    
2921          redo A;          redo A;
2922        } else {        } else {
2923          !!!cp (218);          !!!cp (218);
2924          !!!parse-error (type => 'string after SYSTEM literal');          !!!parse-error (type => 'string after SYSTEM literal');
2925          #$self->{current_token}->{quirks} = 1;          #$self->{ct}->{quirks} = 1;
2926    
2927          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2928          !!!next-input-character;          !!!next-input-character;
2929          redo A;          redo A;
2930        }        }
2931      } elsif ($self->{state} == BOGUS_DOCTYPE_STATE) {      } elsif ($self->{state} == BOGUS_DOCTYPE_STATE) {
2932        if ($self->{next_char} == 0x003E) { # >        if ($self->{nc} == 0x003E) { # >
2933          !!!cp (219);          !!!cp (219);
2934          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2935          !!!next-input-character;          !!!next-input-character;
2936    
2937          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2938    
2939          redo A;          redo A;
2940        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2941          !!!cp (220);          !!!cp (220);
2942          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2943          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2944          ## reconsume          ## reconsume
2945    
2946          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2947    
2948          redo A;          redo A;
2949        } else {        } else {
2950          !!!cp (221);          !!!cp (221);
2951            my $s = '';
2952            $self->{read_until}->($s, q[>], 0);
2953    
2954          ## Stay in the state          ## Stay in the state
2955          !!!next-input-character;          !!!next-input-character;
2956          redo A;          redo A;
2957        }        }
2958      } elsif ($self->{state} == CDATA_BLOCK_STATE) {      } elsif ($self->{state} == CDATA_SECTION_STATE) {
2959        my $s = '';        ## NOTE: "CDATA section state" in the state is jointly implemented
2960          ## by three states, |CDATA_SECTION_STATE|, |CDATA_SECTION_MSE1_STATE|,
2961          ## and |CDATA_SECTION_MSE2_STATE|.
2962                
2963        my ($l, $c) = ($self->{line}, $self->{column});        if ($self->{nc} == 0x005D) { # ]
2964            !!!cp (221.1);
2965        CS: while ($self->{next_char} != -1) {          $self->{state} = CDATA_SECTION_MSE1_STATE;
2966          if ($self->{next_char} == 0x005D) { # ]          !!!next-input-character;
2967            !!!next-input-character;          redo A;
2968            if ($self->{next_char} == 0x005D) { # ]        } elsif ($self->{nc} == -1) {
2969              !!!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};  
2970          !!!next-input-character;          !!!next-input-character;
2971        } # CS          if (length $self->{ct}->{data}) { # character
2972              !!!cp (221.2);
2973              !!!emit ($self->{ct}); # character
2974            } else {
2975              !!!cp (221.3);
2976              ## No token to emit. $self->{ct} is discarded.
2977            }        
2978            redo A;
2979          } else {
2980            !!!cp (221.4);
2981            $self->{ct}->{data} .= chr $self->{nc};
2982            $self->{read_until}->($self->{ct}->{data},
2983                                  q<]>,
2984                                  length $self->{ct}->{data});
2985    
2986        $self->{state} = DATA_STATE;          ## Stay in the state.
2987        ## next-input-character done or EOF, which is reconsumed.          !!!next-input-character;
2988            redo A;
2989          }
2990    
2991        if (length $s) {        ## ISSUE: "text tokens" in spec.
2992        } elsif ($self->{state} == CDATA_SECTION_MSE1_STATE) {
2993          if ($self->{nc} == 0x005D) { # ]
2994            !!!cp (221.5);
2995            $self->{state} = CDATA_SECTION_MSE2_STATE;
2996            !!!next-input-character;
2997            redo A;
2998          } else {
2999          !!!cp (221.6);          !!!cp (221.6);
3000          !!!emit ({type => CHARACTER_TOKEN, data => $s,          $self->{ct}->{data} .= ']';
3001                    line => $l, column => $c});          $self->{state} = CDATA_SECTION_STATE;
3002            ## Reconsume.
3003            redo A;
3004          }
3005        } elsif ($self->{state} == CDATA_SECTION_MSE2_STATE) {
3006          if ($self->{nc} == 0x003E) { # >
3007            $self->{state} = DATA_STATE;
3008            !!!next-input-character;
3009            if (length $self->{ct}->{data}) { # character
3010              !!!cp (221.7);
3011              !!!emit ($self->{ct}); # character
3012            } else {
3013              !!!cp (221.8);
3014              ## No token to emit. $self->{ct} is discarded.
3015            }
3016            redo A;
3017          } elsif ($self->{nc} == 0x005D) { # ]
3018            !!!cp (221.9); # character
3019            $self->{ct}->{data} .= ']'; ## Add first "]" of "]]]".
3020            ## Stay in the state.
3021            !!!next-input-character;
3022            redo A;
3023        } else {        } else {
3024          !!!cp (221.7);          !!!cp (221.11);
3025            $self->{ct}->{data} .= ']]'; # character
3026            $self->{state} = CDATA_SECTION_STATE;
3027            ## Reconsume.
3028            redo A;
3029          }
3030        } elsif ($self->{state} == ENTITY_STATE) {
3031          if ({
3032            0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,
3033            0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, &
3034            $self->{entity_add} => 1,
3035          }->{$self->{nc}}) {
3036            !!!cp (1001);
3037            ## Don't consume
3038            ## No error
3039            ## Return nothing.
3040            #
3041          } elsif ($self->{nc} == 0x0023) { # #
3042            !!!cp (999);
3043            $self->{state} = ENTITY_HASH_STATE;
3044            $self->{s_kwd} = '#';
3045            !!!next-input-character;
3046            redo A;
3047          } elsif ((0x0041 <= $self->{nc} and
3048                    $self->{nc} <= 0x005A) or # A..Z
3049                   (0x0061 <= $self->{nc} and
3050                    $self->{nc} <= 0x007A)) { # a..z
3051            !!!cp (998);
3052            require Whatpm::_NamedEntityList;
3053            $self->{state} = ENTITY_NAME_STATE;
3054            $self->{s_kwd} = chr $self->{nc};
3055            $self->{entity__value} = $self->{s_kwd};
3056            $self->{entity__match} = 0;
3057            !!!next-input-character;
3058            redo A;
3059          } else {
3060            !!!cp (1027);
3061            !!!parse-error (type => 'bare ero');
3062            ## Return nothing.
3063            #
3064        }        }
3065    
3066        redo A;        ## NOTE: No character is consumed by the "consume a character
3067          ## reference" algorithm.  In other word, there is an "&" character
3068        ## ISSUE: "text tokens" in spec.        ## that does not introduce a character reference, which would be
3069        ## TODO: Streaming support        ## appended to the parent element or the attribute value in later
3070      } else {        ## process of the tokenizer.
3071        die "$0: $self->{state}: Unknown state";  
3072      }        if ($self->{prev_state} == DATA_STATE) {
3073    } # A            !!!cp (997);
3074            $self->{state} = $self->{prev_state};
3075    die "$0: _get_next_token: unexpected case";          ## Reconsume.
3076  } # _get_next_token          !!!emit ({type => CHARACTER_TOKEN, data => '&',
3077                      line => $self->{line_prev},
3078  sub _tokenize_attempt_to_consume_an_entity ($$$) {                    column => $self->{column_prev},
3079    my ($self, $in_attr, $additional) = @_;                   });
3080            redo A;
3081    my ($l, $c) = ($self->{line_prev}, $self->{column_prev});        } else {
3082            !!!cp (996);
3083            $self->{ca}->{value} .= '&';
3084            $self->{state} = $self->{prev_state};
3085            ## Reconsume.
3086            redo A;
3087          }
3088        } elsif ($self->{state} == ENTITY_HASH_STATE) {
3089          if ($self->{nc} == 0x0078 or # x
3090              $self->{nc} == 0x0058) { # X
3091            !!!cp (995);
3092            $self->{state} = HEXREF_X_STATE;
3093            $self->{s_kwd} .= chr $self->{nc};
3094            !!!next-input-character;
3095            redo A;
3096          } elsif (0x0030 <= $self->{nc} and
3097                   $self->{nc} <= 0x0039) { # 0..9
3098            !!!cp (994);
3099            $self->{state} = NCR_NUM_STATE;
3100            $self->{s_kwd} = $self->{nc} - 0x0030;
3101            !!!next-input-character;
3102            redo A;
3103          } else {
3104            !!!parse-error (type => 'bare nero',
3105                            line => $self->{line_prev},
3106                            column => $self->{column_prev} - 1);
3107    
3108    if ({          ## NOTE: According to the spec algorithm, nothing is returned,
3109         0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,          ## and then "&#" is appended to the parent element or the attribute
3110         0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR          ## value in the later processing.
3111         $additional => 1,  
3112        }->{$self->{next_char}}) {          if ($self->{prev_state} == DATA_STATE) {
3113      !!!cp (1001);            !!!cp (1019);
3114      ## Don't consume            $self->{state} = $self->{prev_state};
3115      ## No error            ## Reconsume.
3116      return undef;            !!!emit ({type => CHARACTER_TOKEN,
3117    } elsif ($self->{next_char} == 0x0023) { # #                      data => '&#',
3118      !!!next-input-character;                      line => $self->{line_prev},
3119      if ($self->{next_char} == 0x0078 or # x                      column => $self->{column_prev} - 1,
3120          $self->{next_char} == 0x0058) { # X                     });
3121        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;  
3122          } else {          } else {
3123            !!!cp (1007);            !!!cp (993);
3124            !!!parse-error (type => 'no refc', line => $l, column => $c);            $self->{ca}->{value} .= '&#';
3125              $self->{state} = $self->{prev_state};
3126              ## Reconsume.
3127              redo A;
3128          }          }
3129          }
3130          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {      } elsif ($self->{state} == NCR_NUM_STATE) {
3131            !!!cp (1008);        if (0x0030 <= $self->{nc} and
3132            !!!parse-error (type => 'invalid character reference',            $self->{nc} <= 0x0039) { # 0..9
                           text => (sprintf 'U+%04X', $code),  
                           line => $l, column => $c);  
           $code = 0xFFFD;  
         } elsif ($code > 0x10FFFF) {  
           !!!cp (1009);  
           !!!parse-error (type => 'invalid character reference',  
                           text => (sprintf '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 => 'C1 character reference', text => (sprintf '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  
3133          !!!cp (1012);          !!!cp (1012);
3134          $code *= 10;          $self->{s_kwd} *= 10;
3135          $code += $self->{next_char} - 0x0030;          $self->{s_kwd} += $self->{nc} - 0x0030;
3136                    
3137            ## Stay in the state.
3138          !!!next-input-character;          !!!next-input-character;
3139        }          redo A;
3140          } elsif ($self->{nc} == 0x003B) { # ;
       if ($self->{next_char} == 0x003B) { # ;  
3141          !!!cp (1013);          !!!cp (1013);
3142          !!!next-input-character;          !!!next-input-character;
3143            #
3144        } else {        } else {
3145          !!!cp (1014);          !!!cp (1014);
3146          !!!parse-error (type => 'no refc', line => $l, column => $c);          !!!parse-error (type => 'no refc');
3147            ## Reconsume.
3148            #
3149        }        }
3150    
3151          my $code = $self->{s_kwd};
3152          my $l = $self->{line_prev};
3153          my $c = $self->{column_prev};
3154        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3155          !!!cp (1015);          !!!cp (1015);
3156          !!!parse-error (type => 'invalid character reference',          !!!parse-error (type => 'invalid character reference',
# Line 2996  sub _tokenize_attempt_to_consume_an_enti Line 3175  sub _tokenize_attempt_to_consume_an_enti
3175                          line => $l, column => $c);                          line => $l, column => $c);
3176          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
3177        }        }
3178          
3179        return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1,        if ($self->{prev_state} == DATA_STATE) {
3180                line => $l, column => $c,          !!!cp (992);
3181               };          $self->{state} = $self->{prev_state};
3182      } else {          ## Reconsume.
3183        !!!cp (1019);          !!!emit ({type => CHARACTER_TOKEN, data => chr $code,
3184        !!!parse-error (type => 'bare nero', line => $l, column => $c);                    line => $l, column => $c,
3185        !!!back-next-input-character ($self->{next_char});                   });
3186        $self->{next_char} = 0x0023; # #          redo A;
3187        return undef;        } else {
3188      }          !!!cp (991);
3189    } elsif ((0x0041 <= $self->{next_char} and          $self->{ca}->{value} .= chr $code;
3190              $self->{next_char} <= 0x005A) or          $self->{ca}->{has_reference} = 1;
3191             (0x0061 <= $self->{next_char} and          $self->{state} = $self->{prev_state};
3192              $self->{next_char} <= 0x007A)) {          ## Reconsume.
3193      my $entity_name = chr $self->{next_char};          redo A;
3194      !!!next-input-character;        }
3195        } elsif ($self->{state} == HEXREF_X_STATE) {
3196      my $value = $entity_name;        if ((0x0030 <= $self->{nc} and $self->{nc} <= 0x0039) or
3197      my $match = 0;            (0x0041 <= $self->{nc} and $self->{nc} <= 0x0046) or
3198      require Whatpm::_NamedEntityList;            (0x0061 <= $self->{nc} and $self->{nc} <= 0x0066)) {
3199      our $EntityChar;          # 0..9, A..F, a..f
3200            !!!cp (990);
3201      while (length $entity_name < 30 and          $self->{state} = HEXREF_HEX_STATE;
3202             ## NOTE: Some number greater than the maximum length of entity name          $self->{s_kwd} = 0;
3203             ((0x0041 <= $self->{next_char} and # a          ## Reconsume.
3204               $self->{next_char} <= 0x005A) or # x          redo A;
3205              (0x0061 <= $self->{next_char} and # a        } else {
3206               $self->{next_char} <= 0x007A) or # z          !!!parse-error (type => 'bare hcro',
3207              (0x0030 <= $self->{next_char} and # 0                          line => $self->{line_prev},
3208               $self->{next_char} <= 0x0039) or # 9                          column => $self->{column_prev} - 2);
3209              $self->{next_char} == 0x003B)) { # ;  
3210        $entity_name .= chr $self->{next_char};          ## NOTE: According to the spec algorithm, nothing is returned,
3211        if (defined $EntityChar->{$entity_name}) {          ## and then "&#" followed by "X" or "x" is appended to the parent
3212          if ($self->{next_char} == 0x003B) { # ;          ## element or the attribute value in the later processing.
3213            !!!cp (1020);  
3214            $value = $EntityChar->{$entity_name};          if ($self->{prev_state} == DATA_STATE) {
3215            $match = 1;            !!!cp (1005);
3216            !!!next-input-character;            $self->{state} = $self->{prev_state};
3217            last;            ## Reconsume.
3218              !!!emit ({type => CHARACTER_TOKEN,
3219                        data => '&' . $self->{s_kwd},
3220                        line => $self->{line_prev},
3221                        column => $self->{column_prev} - length $self->{s_kwd},
3222                       });
3223              redo A;
3224          } else {          } else {
3225            !!!cp (1021);            !!!cp (989);
3226            $value = $EntityChar->{$entity_name};            $self->{ca}->{value} .= '&' . $self->{s_kwd};
3227            $match = -1;            $self->{state} = $self->{prev_state};
3228              ## Reconsume.
3229              redo A;
3230            }
3231          }
3232        } elsif ($self->{state} == HEXREF_HEX_STATE) {
3233          if (0x0030 <= $self->{nc} and $self->{nc} <= 0x0039) {
3234            # 0..9
3235            !!!cp (1002);
3236            $self->{s_kwd} *= 0x10;
3237            $self->{s_kwd} += $self->{nc} - 0x0030;
3238            ## Stay in the state.
3239            !!!next-input-character;
3240            redo A;
3241          } elsif (0x0061 <= $self->{nc} and
3242                   $self->{nc} <= 0x0066) { # a..f
3243            !!!cp (1003);
3244            $self->{s_kwd} *= 0x10;
3245            $self->{s_kwd} += $self->{nc} - 0x0060 + 9;
3246            ## Stay in the state.
3247            !!!next-input-character;
3248            redo A;
3249          } elsif (0x0041 <= $self->{nc} and
3250                   $self->{nc} <= 0x0046) { # A..F
3251            !!!cp (1004);
3252            $self->{s_kwd} *= 0x10;
3253            $self->{s_kwd} += $self->{nc} - 0x0040 + 9;
3254            ## Stay in the state.
3255            !!!next-input-character;
3256            redo A;
3257          } elsif ($self->{nc} == 0x003B) { # ;
3258            !!!cp (1006);
3259            !!!next-input-character;
3260            #
3261          } else {
3262            !!!cp (1007);
3263            !!!parse-error (type => 'no refc',
3264                            line => $self->{line},
3265                            column => $self->{column});
3266            ## Reconsume.
3267            #
3268          }
3269    
3270          my $code = $self->{s_kwd};
3271          my $l = $self->{line_prev};
3272          my $c = $self->{column_prev};
3273          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3274            !!!cp (1008);
3275            !!!parse-error (type => 'invalid character reference',
3276                            text => (sprintf 'U+%04X', $code),
3277                            line => $l, column => $c);
3278            $code = 0xFFFD;
3279          } elsif ($code > 0x10FFFF) {
3280            !!!cp (1009);
3281            !!!parse-error (type => 'invalid character reference',
3282                            text => (sprintf 'U-%08X', $code),
3283                            line => $l, column => $c);
3284            $code = 0xFFFD;
3285          } elsif ($code == 0x000D) {
3286            !!!cp (1010);
3287            !!!parse-error (type => 'CR character reference', line => $l, column => $c);
3288            $code = 0x000A;
3289          } elsif (0x80 <= $code and $code <= 0x9F) {
3290            !!!cp (1011);
3291            !!!parse-error (type => 'C1 character reference', text => (sprintf 'U+%04X', $code), line => $l, column => $c);
3292            $code = $c1_entity_char->{$code};
3293          }
3294    
3295          if ($self->{prev_state} == DATA_STATE) {
3296            !!!cp (988);
3297            $self->{state} = $self->{prev_state};
3298            ## Reconsume.
3299            !!!emit ({type => CHARACTER_TOKEN, data => chr $code,
3300                      line => $l, column => $c,
3301                     });
3302            redo A;
3303          } else {
3304            !!!cp (987);
3305            $self->{ca}->{value} .= chr $code;
3306            $self->{ca}->{has_reference} = 1;
3307            $self->{state} = $self->{prev_state};
3308            ## Reconsume.
3309            redo A;
3310          }
3311        } elsif ($self->{state} == ENTITY_NAME_STATE) {
3312          if (length $self->{s_kwd} < 30 and
3313              ## NOTE: Some number greater than the maximum length of entity name
3314              ((0x0041 <= $self->{nc} and # a
3315                $self->{nc} <= 0x005A) or # x
3316               (0x0061 <= $self->{nc} and # a
3317                $self->{nc} <= 0x007A) or # z
3318               (0x0030 <= $self->{nc} and # 0
3319                $self->{nc} <= 0x0039) or # 9
3320               $self->{nc} == 0x003B)) { # ;
3321            our $EntityChar;
3322            $self->{s_kwd} .= chr $self->{nc};
3323            if (defined $EntityChar->{$self->{s_kwd}}) {
3324              if ($self->{nc} == 0x003B) { # ;
3325                !!!cp (1020);
3326                $self->{entity__value} = $EntityChar->{$self->{s_kwd}};
3327                $self->{entity__match} = 1;
3328                !!!next-input-character;
3329                #
3330              } else {
3331                !!!cp (1021);
3332                $self->{entity__value} = $EntityChar->{$self->{s_kwd}};
3333                $self->{entity__match} = -1;
3334                ## Stay in the state.
3335                !!!next-input-character;
3336                redo A;
3337              }
3338            } else {
3339              !!!cp (1022);
3340              $self->{entity__value} .= chr $self->{nc};
3341              $self->{entity__match} *= 2;
3342              ## Stay in the state.
3343            !!!next-input-character;            !!!next-input-character;
3344              redo A;
3345            }
3346          }
3347    
3348          my $data;
3349          my $has_ref;
3350          if ($self->{entity__match} > 0) {
3351            !!!cp (1023);
3352            $data = $self->{entity__value};
3353            $has_ref = 1;
3354            #
3355          } elsif ($self->{entity__match} < 0) {
3356            !!!parse-error (type => 'no refc');
3357            if ($self->{prev_state} != DATA_STATE and # in attribute
3358                $self->{entity__match} < -1) {
3359              !!!cp (1024);
3360              $data = '&' . $self->{s_kwd};
3361              #
3362            } else {
3363              !!!cp (1025);
3364              $data = $self->{entity__value};
3365              $has_ref = 1;
3366              #
3367          }          }
3368        } else {        } else {
3369          !!!cp (1022);          !!!cp (1026);
3370          $value .= chr $self->{next_char};          !!!parse-error (type => 'bare ero',
3371          $match *= 2;                          line => $self->{line_prev},
3372          !!!next-input-character;                          column => $self->{column_prev} - length $self->{s_kwd});
3373            $data = '&' . $self->{s_kwd};
3374            #
3375        }        }
3376      }    
3377              ## NOTE: In these cases, when a character reference is found,
3378      if ($match > 0) {        ## it is consumed and a character token is returned, or, otherwise,
3379        !!!cp (1023);        ## nothing is consumed and returned, according to the spec algorithm.
3380        return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,        ## In this implementation, anything that has been examined by the
3381                line => $l, column => $c,        ## tokenizer is appended to the parent element or the attribute value
3382               };        ## as string, either literal string when no character reference or
3383      } elsif ($match < 0) {        ## entity-replaced string otherwise, in this stage, since any characters
3384        !!!parse-error (type => 'no refc', line => $l, column => $c);        ## that would not be consumed are appended in the data state or in an
3385        if ($in_attr and $match < -1) {        ## appropriate attribute value state anyway.
3386          !!!cp (1024);  
3387          return {type => CHARACTER_TOKEN, data => '&'.$entity_name,        if ($self->{prev_state} == DATA_STATE) {
3388                  line => $l, column => $c,          !!!cp (986);
3389                 };          $self->{state} = $self->{prev_state};
3390        } else {          ## Reconsume.
3391          !!!cp (1025);          !!!emit ({type => CHARACTER_TOKEN,
3392          return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,                    data => $data,
3393                  line => $l, column => $c,                    line => $self->{line_prev},
3394                 };                    column => $self->{column_prev} + 1 - length $self->{s_kwd},
3395                     });
3396            redo A;
3397          } else {
3398            !!!cp (985);
3399            $self->{ca}->{value} .= $data;
3400            $self->{ca}->{has_reference} = 1 if $has_ref;
3401            $self->{state} = $self->{prev_state};
3402            ## Reconsume.
3403            redo A;
3404        }        }
3405      } else {      } else {
3406        !!!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,  
              };  
3407      }      }
3408    } else {    } # A  
3409      !!!cp (1027);  
3410      ## no characters are consumed    die "$0: _get_next_token: unexpected case";
3411      !!!parse-error (type => 'bare ero', line => $l, column => $c);  } # _get_next_token
     return undef;  
   }  
 } # _tokenize_attempt_to_consume_an_entity  
3412    
3413  sub _initialize_tree_constructor ($) {  sub _initialize_tree_constructor ($) {
3414    my $self = shift;    my $self = shift;
# Line 3147  sub _tree_construction_initial ($) { Line 3473  sub _tree_construction_initial ($) {
3473        ## language.        ## language.
3474        my $doctype_name = $token->{name};        my $doctype_name = $token->{name};
3475        $doctype_name = '' unless defined $doctype_name;        $doctype_name = '' unless defined $doctype_name;
3476        $doctype_name =~ tr/a-z/A-Z/;        $doctype_name =~ tr/a-z/A-Z/; # ASCII case-insensitive
3477        if (not defined $token->{name} or # <!DOCTYPE>        if (not defined $token->{name} or # <!DOCTYPE>
3478            defined $token->{public_identifier} or            defined $token->{sysid}) {
           defined $token->{system_identifier}) {  
3479          !!!cp ('t1');          !!!cp ('t1');
3480          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3481        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
3482          !!!cp ('t2');          !!!cp ('t2');
         ## ISSUE: ASCII case-insensitive? (in fact it does not matter)  
3483          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3484          } elsif (defined $token->{pubid}) {
3485            if ($token->{pubid} eq 'XSLT-compat') {
3486              !!!cp ('t1.2');
3487              !!!parse-error (type => 'XSLT-compat', token => $token,
3488                              level => $self->{level}->{should});
3489            } else {
3490              !!!parse-error (type => 'not HTML5', token => $token);
3491            }
3492        } else {        } else {
3493          !!!cp ('t3');          !!!cp ('t3');
3494            #
3495        }        }
3496                
3497        my $doctype = $self->{document}->create_document_type_definition        my $doctype = $self->{document}->create_document_type_definition
3498          ($token->{name}); ## ISSUE: If name is missing (e.g. <!DOCTYPE>)?          ($token->{name}); ## ISSUE: If name is missing (e.g. <!DOCTYPE>)?
3499        ## NOTE: Default value for both |public_id| and |system_id| attributes        ## NOTE: Default value for both |public_id| and |system_id| attributes
3500        ## 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.
3501        $doctype->public_id ($token->{public_identifier})        $doctype->public_id ($token->{pubid}) if defined $token->{pubid};
3502            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};  
3503        ## NOTE: Other DocumentType attributes are null or empty lists.        ## NOTE: Other DocumentType attributes are null or empty lists.
3504        ## ISSUE: internalSubset = null??        ## ISSUE: internalSubset = null??
3505        $self->{document}->append_child ($doctype);        $self->{document}->append_child ($doctype);
# Line 3176  sub _tree_construction_initial ($) { Line 3507  sub _tree_construction_initial ($) {
3507        if ($token->{quirks} or $doctype_name ne 'HTML') {        if ($token->{quirks} or $doctype_name ne 'HTML') {
3508          !!!cp ('t4');          !!!cp ('t4');
3509          $self->{document}->manakai_compat_mode ('quirks');          $self->{document}->manakai_compat_mode ('quirks');
3510        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{pubid}) {
3511          my $pubid = $token->{public_identifier};          my $pubid = $token->{pubid};
3512          $pubid =~ tr/a-z/A-z/;          $pubid =~ tr/a-z/A-z/;
3513          my $prefix = [          my $prefix = [
3514            "+//SILMARIL//DTD HTML PRO V0R11 19970101//",            "+//SILMARIL//DTD HTML PRO V0R11 19970101//",
# Line 3251  sub _tree_construction_initial ($) { Line 3582  sub _tree_construction_initial ($) {
3582            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3583          } elsif ($pubid =~ m[^-//W3C//DTD HTML 4.01 FRAMESET//] or          } elsif ($pubid =~ m[^-//W3C//DTD HTML 4.01 FRAMESET//] or
3584                   $pubid =~ m[^-//W3C//DTD HTML 4.01 TRANSITIONAL//]) {                   $pubid =~ m[^-//W3C//DTD HTML 4.01 TRANSITIONAL//]) {
3585            if (defined $token->{system_identifier}) {            if (defined $token->{sysid}) {
3586              !!!cp ('t6');              !!!cp ('t6');
3587              $self->{document}->manakai_compat_mode ('quirks');              $self->{document}->manakai_compat_mode ('quirks');
3588            } else {            } else {
# Line 3268  sub _tree_construction_initial ($) { Line 3599  sub _tree_construction_initial ($) {
3599        } else {        } else {
3600          !!!cp ('t10');          !!!cp ('t10');
3601        }        }
3602        if (defined $token->{system_identifier}) {        if (defined $token->{sysid}) {
3603          my $sysid = $token->{system_identifier};          my $sysid = $token->{sysid};
3604          $sysid =~ tr/A-Z/a-z/;          $sysid =~ tr/A-Z/a-z/;
3605          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") {
3606            ## NOTE: Ensure that |PUBLIC "(limited quirks)" "(quirks)"| is            ## NOTE: Ensure that |PUBLIC "(limited quirks)" "(quirks)"| is
# Line 4174  sub _tree_construction_main ($) { Line 4505  sub _tree_construction_main ($) {
4505            unless ($self->{insertion_mode} == BEFORE_HEAD_IM) {            unless ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4506              !!!cp ('t88.2');              !!!cp ('t88.2');
4507              $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);              $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4508                #
4509            } else {            } else {
4510              !!!cp ('t88.1');              !!!cp ('t88.1');
4511              ## Ignore the token.              ## Ignore the token.
4512              !!!next-token;              #
             next B;  
4513            }            }
4514            unless (length $token->{data}) {            unless (length $token->{data}) {
4515              !!!cp ('t88');              !!!cp ('t88');
4516              !!!next-token;              !!!next-token;
4517              next B;              next B;
4518            }            }
4519    ## TODO: set $token->{column} appropriately
4520          }          }
4521    
4522          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
# Line 6294  sub _tree_construction_main ($) { Line 6626  sub _tree_construction_main ($) {
6626            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6627              !!!cp ('t312');              !!!cp ('t312');
6628              !!!parse-error (type => 'after frameset:#text', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6629            } else { # "after html frameset"            } else { # "after after frameset"
6630              !!!cp ('t313');              !!!cp ('t313');
6631              !!!parse-error (type => 'after html:#text', 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:#text', token => $token);  
6632            }            }
6633                        
6634            ## Ignore the token.            ## Ignore the token.
# Line 6316  sub _tree_construction_main ($) { Line 6644  sub _tree_construction_main ($) {
6644                    
6645          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
6646        } 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',  
                           text => $token->{tag_name}, token => $token);  
   
           $self->{insertion_mode} = AFTER_FRAMESET_IM;  
           ## Process in the "after frameset" insertion mode.  
         } else {  
           !!!cp ('t317');  
         }  
   
6647          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6648              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6649            !!!cp ('t318');            !!!cp ('t318');
# Line 6347  sub _tree_construction_main ($) { Line 6664  sub _tree_construction_main ($) {
6664            ## NOTE: As if in head.            ## NOTE: As if in head.
6665            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
6666            next B;            next B;
6667    
6668              ## NOTE: |<!DOCTYPE HTML><frameset></frameset></html><noframes></noframes>|
6669              ## has no parse error.
6670          } else {          } else {
6671            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6672              !!!cp ('t321');              !!!cp ('t321');
6673              !!!parse-error (type => 'in frameset',              !!!parse-error (type => 'in frameset',
6674                              text => $token->{tag_name}, token => $token);                              text => $token->{tag_name}, token => $token);
6675            } else {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6676              !!!cp ('t322');              !!!cp ('t322');
6677              !!!parse-error (type => 'after frameset',              !!!parse-error (type => 'after frameset',
6678                              text => $token->{tag_name}, token => $token);                              text => $token->{tag_name}, token => $token);
6679              } else { # "after after frameset"
6680                !!!cp ('t322.2');
6681                !!!parse-error (type => 'after after frameset',
6682                                text => $token->{tag_name}, token => $token);
6683            }            }
6684            ## Ignore the token            ## Ignore the token
6685            !!!nack ('t322.1');            !!!nack ('t322.1');
# Line 6363  sub _tree_construction_main ($) { Line 6687  sub _tree_construction_main ($) {
6687            next B;            next B;
6688          }          }
6689        } 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:/',  
                           text => $token->{tag_name}, token => $token);  
   
           $self->{insertion_mode} = AFTER_FRAMESET_IM;  
           ## Process in the "after frameset" insertion mode.  
         } else {  
           !!!cp ('t324');  
         }  
   
6690          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6691              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6692            if ($self->{open_elements}->[-1]->[1] & HTML_EL and            if ($self->{open_elements}->[-1]->[1] & HTML_EL and
# Line 6408  sub _tree_construction_main ($) { Line 6721  sub _tree_construction_main ($) {
6721              !!!cp ('t330');              !!!cp ('t330');
6722              !!!parse-error (type => 'in frameset:/',              !!!parse-error (type => 'in frameset:/',
6723                              text => $token->{tag_name}, token => $token);                              text => $token->{tag_name}, token => $token);
6724            } else {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6725              !!!cp ('t331');              !!!cp ('t330.1');
6726              !!!parse-error (type => 'after frameset:/',              !!!parse-error (type => 'after frameset:/',
6727                              text => $token->{tag_name}, token => $token);                              text => $token->{tag_name}, token => $token);
6728              } else { # "after after html"
6729                !!!cp ('t331');
6730                !!!parse-error (type => 'after after frameset:/',
6731                                text => $token->{tag_name}, token => $token);
6732            }            }
6733            ## Ignore the token            ## Ignore the token
6734            !!!next-token;            !!!next-token;
# Line 7134  sub _tree_construction_main ($) { Line 7451  sub _tree_construction_main ($) {
7451            !!!cp ('t413');            !!!cp ('t413');
7452            !!!parse-error (type => 'unmatched end tag',            !!!parse-error (type => 'unmatched end tag',
7453                            text => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7454              ## NOTE: Ignore the token.
7455          } else {          } else {
7456            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7457            while ({            while ({
# Line 7193  sub _tree_construction_main ($) { Line 7511  sub _tree_construction_main ($) {
7511            !!!cp ('t421');            !!!cp ('t421');
7512            !!!parse-error (type => 'unmatched end tag',            !!!parse-error (type => 'unmatched end tag',
7513                            text => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7514              ## NOTE: Ignore the token.
7515          } else {          } else {
7516            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7517            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7239  sub _tree_construction_main ($) { Line 7558  sub _tree_construction_main ($) {
7558            !!!cp ('t425.1');            !!!cp ('t425.1');
7559            !!!parse-error (type => 'unmatched end tag',            !!!parse-error (type => 'unmatched end tag',
7560                            text => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7561              ## NOTE: Ignore the token.
7562          } else {          } else {
7563            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7564            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7441  sub _tree_construction_main ($) { Line 7761  sub _tree_construction_main ($) {
7761    ## TODO: script stuffs    ## TODO: script stuffs
7762  } # _tree_construct_main  } # _tree_construct_main
7763    
7764  sub set_inner_html ($$$) {  sub set_inner_html ($$$$;$) {
7765    my $class = shift;    my $class = shift;
7766    my $node = shift;    my $node = shift;
7767    my $s = \$_[0];    #my $s = \$_[0];
7768    my $onerror = $_[1];    my $onerror = $_[1];
7769      my $get_wrapper = $_[2] || sub ($) { return $_[0] };
7770    
7771    ## ISSUE: Should {confident} be true?    ## ISSUE: Should {confident} be true?
7772    
# Line 7464  sub set_inner_html ($$$) { Line 7785  sub set_inner_html ($$$) {
7785      }      }
7786    
7787      ## Step 3, 4, 5 # MUST      ## Step 3, 4, 5 # MUST
7788      $class->parse_string ($$s => $node, $onerror);      $class->parse_char_string ($_[0] => $node, $onerror, $get_wrapper);
7789    } elsif ($nt == 1) {    } elsif ($nt == 1) {
7790      ## TODO: If non-html element      ## TODO: If non-html element
7791    
7792      ## NOTE: Most of this code is copied from |parse_string|      ## NOTE: Most of this code is copied from |parse_string|
7793    
7794    ## TODO: Support for $get_wrapper
7795    
7796      ## Step 1 # MUST      ## Step 1 # MUST
7797      my $this_doc = $node->owner_document;      my $this_doc = $node->owner_document;
7798      my $doc = $this_doc->implementation->create_document;      my $doc = $this_doc->implementation->create_document;
# Line 7481  sub set_inner_html ($$$) { Line 7804  sub set_inner_html ($$$) {
7804      my $i = 0;      my $i = 0;
7805      $p->{line_prev} = $p->{line} = 1;      $p->{line_prev} = $p->{line} = 1;
7806      $p->{column_prev} = $p->{column} = 0;      $p->{column_prev} = $p->{column} = 0;
7807      $p->{set_next_char} = sub {      require Whatpm::Charset::DecodeHandle;
7808        my $input = Whatpm::Charset::DecodeHandle::CharString->new (\($_[0]));
7809        $input = $get_wrapper->($input);
7810        $p->{set_nc} = sub {
7811        my $self = shift;        my $self = shift;
7812    
7813        pop @{$self->{prev_char}};        my $char = '';
7814        unshift @{$self->{prev_char}}, $self->{next_char};        if (defined $self->{next_nc}) {
7815            $char = $self->{next_nc};
7816        $self->{next_char} = -1 and return if $i >= length $$s;          delete $self->{next_nc};
7817        $self->{next_char} = ord substr $$s, $i++, 1;          $self->{nc} = ord $char;
7818          } else {
7819            $self->{char_buffer} = '';
7820            $self->{char_buffer_pos} = 0;
7821            
7822            my $count = $input->manakai_read_until
7823                ($self->{char_buffer}, qr/[^\x00\x0A\x0D]/,
7824                 $self->{char_buffer_pos});
7825            if ($count) {
7826              $self->{line_prev} = $self->{line};
7827              $self->{column_prev} = $self->{column};
7828              $self->{column}++;
7829              $self->{nc}
7830                  = ord substr ($self->{char_buffer},
7831                                $self->{char_buffer_pos}++, 1);
7832              return;
7833            }
7834            
7835            if ($input->read ($char, 1)) {
7836              $self->{nc} = ord $char;
7837            } else {
7838              $self->{nc} = -1;
7839              return;
7840            }
7841          }
7842    
7843        ($p->{line_prev}, $p->{column_prev}) = ($p->{line}, $p->{column});        ($p->{line_prev}, $p->{column_prev}) = ($p->{line}, $p->{column});
7844        $p->{column}++;        $p->{column}++;
7845    
7846        if ($self->{next_char} == 0x000A) { # LF        if ($self->{nc} == 0x000A) { # LF
7847          $p->{line}++;          $p->{line}++;
7848          $p->{column} = 0;          $p->{column} = 0;
7849          !!!cp ('i1');          !!!cp ('i1');
7850        } elsif ($self->{next_char} == 0x000D) { # CR        } elsif ($self->{nc} == 0x000D) { # CR
7851          $i++ if substr ($$s, $i, 1) eq "\x0A";  ## TODO: support for abort/streaming
7852          $self->{next_char} = 0x000A; # LF # MUST          my $next = '';
7853            if ($input->read ($next, 1) and $next ne "\x0A") {
7854              $self->{next_nc} = $next;
7855            }
7856            $self->{nc} = 0x000A; # LF # MUST
7857          $p->{line}++;          $p->{line}++;
7858          $p->{column} = 0;          $p->{column} = 0;
7859          !!!cp ('i2');          !!!cp ('i2');
7860        } 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  
7861          !!!cp ('i4');          !!!cp ('i4');
7862          !!!parse-error (type => 'NULL');          !!!parse-error (type => 'NULL');
7863          $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');  
         if ($self->{next_char} < 0x10000) {  
           !!!parse-error (type => 'control char',  
                           text => (sprintf 'U+%04X', $self->{next_char}));  
         } else {  
           !!!parse-error (type => 'control char',  
                           text => (sprintf 'U-%08X', $self->{next_char}));  
         }  
7864        }        }
7865      };      };
7866      $p->{prev_char} = [-1, -1, -1];  
7867      $p->{next_char} = -1;      $p->{read_until} = sub {
7868              #my ($scalar, $specials_range, $offset) = @_;
7869          return 0 if defined $p->{next_nc};
7870    
7871          my $pattern = qr/[^$_[1]\x00\x0A\x0D]/;
7872          my $offset = $_[2] || 0;
7873          
7874          if ($p->{char_buffer_pos} < length $p->{char_buffer}) {
7875            pos ($p->{char_buffer}) = $p->{char_buffer_pos};
7876            if ($p->{char_buffer} =~ /\G(?>$pattern)+/) {
7877              substr ($_[0], $offset)
7878                  = substr ($p->{char_buffer}, $-[0], $+[0] - $-[0]);
7879              my $count = $+[0] - $-[0];
7880              if ($count) {
7881                $p->{column} += $count;
7882                $p->{char_buffer_pos} += $count;
7883                $p->{line_prev} = $p->{line};
7884                $p->{column_prev} = $p->{column} - 1;
7885                $p->{prev_char} = [-1, -1, -1];
7886                $p->{nc} = -1;
7887              }
7888              return $count;
7889            } else {
7890              return 0;
7891            }
7892          } else {
7893            my $count = $input->manakai_read_until ($_[0], $pattern, $_[2]);
7894            if ($count) {
7895              $p->{column} += $count;
7896              $p->{column_prev} += $count;
7897              $p->{prev_char} = [-1, -1, -1];
7898              $p->{nc} = -1;
7899            }
7900            return $count;
7901          }
7902        }; # $p->{read_until}
7903    
7904      my $ponerror = $onerror || sub {      my $ponerror = $onerror || sub {
7905        my (%opt) = @_;        my (%opt) = @_;
7906        my $line = $opt{line};        my $line = $opt{line};
# Line 7557  sub set_inner_html ($$$) { Line 7915  sub set_inner_html ($$$) {
7915        $ponerror->(line => $p->{line}, column => $p->{column}, @_);        $ponerror->(line => $p->{line}, column => $p->{column}, @_);
7916      };      };
7917            
7918        my $char_onerror = sub {
7919          my (undef, $type, %opt) = @_;
7920          $ponerror->(layer => 'encode',
7921                      line => $p->{line}, column => $p->{column} + 1,
7922                      %opt, type => $type);
7923        }; # $char_onerror
7924        $input->onerror ($char_onerror);
7925    
7926      $p->_initialize_tokenizer;      $p->_initialize_tokenizer;
7927      $p->_initialize_tree_constructor;      $p->_initialize_tree_constructor;
7928    

Legend:
Removed from v.1.155  
changed lines
  Added in v.1.183

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24