/[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.153 by wakaba, Fri Aug 15 08:32:41 2008 UTC revision 1.181 by wakaba, Mon Sep 15 02:54:12 2008 UTC
# Line 354  sub parse_byte_string ($$$$;$) { Line 354  sub parse_byte_string ($$$$;$) {
354    return $self->parse_byte_stream ($charset_name, $input, @_[1..$#_]);    return $self->parse_byte_stream ($charset_name, $input, @_[1..$#_]);
355  } # parse_byte_string  } # parse_byte_string
356    
357  sub parse_byte_stream ($$$$;$) {  sub parse_byte_stream ($$$$;$$) {
358      # my ($self, $charset_name, $byte_stream, $doc, $onerror, $get_wrapper) = @_;
359    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
360    my $charset_name = shift;    my $charset_name = shift;
361    my $byte_stream = $_[0];    my $byte_stream = $_[0];
# Line 365  sub parse_byte_stream ($$$$;$) { Line 366  sub parse_byte_stream ($$$$;$) {
366    };    };
367    $self->{parse_error} = $onerror; # updated later by parse_char_string    $self->{parse_error} = $onerror; # updated later by parse_char_string
368    
369      my $get_wrapper = $_[3] || sub ($) {
370        return $_[0]; # $_[0] = byte stream handle, returned = arg to char handle
371      };
372    
373    ## HTML5 encoding sniffing algorithm    ## HTML5 encoding sniffing algorithm
374    require Message::Charset::Info;    require Message::Charset::Info;
375    my $charset;    my $charset;
# Line 372  sub parse_byte_stream ($$$$;$) { Line 377  sub parse_byte_stream ($$$$;$) {
377    my ($char_stream, $e_status);    my ($char_stream, $e_status);
378    
379    SNIFFING: {    SNIFFING: {
380        ## NOTE: By setting |allow_fallback| option true when the
381        ## |get_decode_handle| method is invoked, we ignore what the HTML5
382        ## spec requires, i.e. unsupported encoding should be ignored.
383          ## TODO: We should not do this unless the parser is invoked
384          ## in the conformance checking mode, in which this behavior
385          ## would be useful.
386    
387      ## Step 1      ## Step 1
388      if (defined $charset_name) {      if (defined $charset_name) {
389        $charset = Message::Charset::Info->get_by_iana_name ($charset_name);        $charset = Message::Charset::Info->get_by_html_name ($charset_name);
390              ## TODO: Is this ok?  Transfer protocol's parameter should be
391              ## interpreted in its semantics?
392    
393        ## ISSUE: Unsupported encoding is not ignored according to the spec.        ## ISSUE: Unsupported encoding is not ignored according to the spec.
394        ($char_stream, $e_status) = $charset->get_decode_handle        ($char_stream, $e_status) = $charset->get_decode_handle
# Line 399  sub parse_byte_stream ($$$$;$) { Line 412  sub parse_byte_stream ($$$$;$) {
412    
413      ## Step 3      ## Step 3
414      if ($byte_buffer =~ /^\xFE\xFF/) {      if ($byte_buffer =~ /^\xFE\xFF/) {
415        $charset = Message::Charset::Info->get_by_iana_name ('utf-16be');        $charset = Message::Charset::Info->get_by_html_name ('utf-16be');
416        ($char_stream, $e_status) = $charset->get_decode_handle        ($char_stream, $e_status) = $charset->get_decode_handle
417            ($byte_stream, allow_error_reporting => 1,            ($byte_stream, allow_error_reporting => 1,
418             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
419        $self->{confident} = 1;        $self->{confident} = 1;
420        last SNIFFING;        last SNIFFING;
421      } elsif ($byte_buffer =~ /^\xFF\xFE/) {      } elsif ($byte_buffer =~ /^\xFF\xFE/) {
422        $charset = Message::Charset::Info->get_by_iana_name ('utf-16le');        $charset = Message::Charset::Info->get_by_html_name ('utf-16le');
423        ($char_stream, $e_status) = $charset->get_decode_handle        ($char_stream, $e_status) = $charset->get_decode_handle
424            ($byte_stream, allow_error_reporting => 1,            ($byte_stream, allow_error_reporting => 1,
425             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
426        $self->{confident} = 1;        $self->{confident} = 1;
427        last SNIFFING;        last SNIFFING;
428      } elsif ($byte_buffer =~ /^\xEF\xBB\xBF/) {      } elsif ($byte_buffer =~ /^\xEF\xBB\xBF/) {
429        $charset = Message::Charset::Info->get_by_iana_name ('utf-8');        $charset = Message::Charset::Info->get_by_html_name ('utf-8');
430        ($char_stream, $e_status) = $charset->get_decode_handle        ($char_stream, $e_status) = $charset->get_decode_handle
431            ($byte_stream, allow_error_reporting => 1,            ($byte_stream, allow_error_reporting => 1,
432             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
# Line 432  sub parse_byte_stream ($$$$;$) { Line 445  sub parse_byte_stream ($$$$;$) {
445      $charset_name = Whatpm::Charset::UniversalCharDet->detect_byte_string      $charset_name = Whatpm::Charset::UniversalCharDet->detect_byte_string
446          ($byte_buffer);          ($byte_buffer);
447      if (defined $charset_name) {      if (defined $charset_name) {
448        $charset = Message::Charset::Info->get_by_iana_name ($charset_name);        $charset = Message::Charset::Info->get_by_html_name ($charset_name);
449    
450        ## ISSUE: Unsupported encoding is not ignored according to the spec.        ## ISSUE: Unsupported encoding is not ignored according to the spec.
451        require Whatpm::Charset::DecodeHandle;        require Whatpm::Charset::DecodeHandle;
# Line 455  sub parse_byte_stream ($$$$;$) { Line 468  sub parse_byte_stream ($$$$;$) {
468    
469      ## Step 7: default      ## Step 7: default
470      ## TODO: Make this configurable.      ## TODO: Make this configurable.
471      $charset = Message::Charset::Info->get_by_iana_name ('windows-1252');      $charset = Message::Charset::Info->get_by_html_name ('windows-1252');
472          ## NOTE: We choose |windows-1252| here, since |utf-8| should be          ## NOTE: We choose |windows-1252| here, since |utf-8| should be
473          ## detectable in the step 6.          ## detectable in the step 6.
474      require Whatpm::Charset::DecodeHandle;      require Whatpm::Charset::DecodeHandle;
# Line 475  sub parse_byte_stream ($$$$;$) { Line 488  sub parse_byte_stream ($$$$;$) {
488      $self->{confident} = 0;      $self->{confident} = 0;
489    } # SNIFFING    } # SNIFFING
490    
   $self->{input_encoding} = $charset->get_iana_name;  
491    if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {    if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
492        $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name?
493      !!!parse-error (type => 'chardecode:fallback',      !!!parse-error (type => 'chardecode:fallback',
494                      text => $self->{input_encoding},                      #text => $self->{input_encoding},
495                      level => $self->{level}->{uncertain},                      level => $self->{level}->{uncertain},
496                      line => 1, column => 1,                      line => 1, column => 1,
497                      layer => 'encode');                      layer => 'encode');
498    } elsif (not ($e_status &    } elsif (not ($e_status &
499                  Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {                  Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL ())) {
500        $self->{input_encoding} = $charset->get_iana_name;
501      !!!parse-error (type => 'chardecode:no error',      !!!parse-error (type => 'chardecode:no error',
502                      text => $self->{input_encoding},                      text => $self->{input_encoding},
503                      level => $self->{level}->{uncertain},                      level => $self->{level}->{uncertain},
504                      line => 1, column => 1,                      line => 1, column => 1,
505                      layer => 'encode');                      layer => 'encode');
506      } else {
507        $self->{input_encoding} = $charset->get_iana_name;
508    }    }
509    
510    $self->{change_encoding} = sub {    $self->{change_encoding} = sub {
# Line 496  sub parse_byte_stream ($$$$;$) { Line 512  sub parse_byte_stream ($$$$;$) {
512      $charset_name = shift;      $charset_name = shift;
513      my $token = shift;      my $token = shift;
514    
515      $charset = Message::Charset::Info->get_by_iana_name ($charset_name);      $charset = Message::Charset::Info->get_by_html_name ($charset_name);
516      ($char_stream, $e_status) = $charset->get_decode_handle      ($char_stream, $e_status) = $charset->get_decode_handle
517          ($byte_stream, allow_error_reporting => 1, allow_fallback => 1,          ($byte_stream, allow_error_reporting => 1, allow_fallback => 1,
518           byte_buffer => \ $buffer->{buffer});           byte_buffer => \ $buffer->{buffer});
# Line 507  sub parse_byte_stream ($$$$;$) { Line 523  sub parse_byte_stream ($$$$;$) {
523        ## Step 1            ## Step 1    
524        if ($charset->{category} &        if ($charset->{category} &
525            Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) {            Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) {
526          $charset = Message::Charset::Info->get_by_iana_name ('utf-8');          $charset = Message::Charset::Info->get_by_html_name ('utf-8');
527          ($char_stream, $e_status) = $charset->get_decode_handle          ($char_stream, $e_status) = $charset->get_decode_handle
528              ($byte_stream,              ($byte_stream,
529               byte_buffer => \ $buffer->{buffer});               byte_buffer => \ $buffer->{buffer});
# Line 545  sub parse_byte_stream ($$$$;$) { Line 561  sub parse_byte_stream ($$$$;$) {
561    my $char_onerror = sub {    my $char_onerror = sub {
562      my (undef, $type, %opt) = @_;      my (undef, $type, %opt) = @_;
563      !!!parse-error (layer => 'encode',      !!!parse-error (layer => 'encode',
564                      %opt, type => $type,                      line => $self->{line}, column => $self->{column} + 1,
565                      line => $self->{line}, column => $self->{column} + 1);                      %opt, type => $type);
566      if ($opt{octets}) {      if ($opt{octets}) {
567        ${$opt{octets}} = "\x{FFFD}"; # relacement character        ${$opt{octets}} = "\x{FFFD}"; # relacement character
568      }      }
569    };    };
570    $char_stream->onerror ($char_onerror);  
571      my $wrapped_char_stream = $get_wrapper->($char_stream);
572      $wrapped_char_stream->onerror ($char_onerror);
573    
574    my @args = @_; shift @args; # $s    my @args = @_; shift @args; # $s
575    my $return;    my $return;
576    try {    try {
577      $return = $self->parse_char_stream ($char_stream, @args);        $return = $self->parse_char_stream ($wrapped_char_stream, @args);  
578    } catch Whatpm::HTML::RestartParser with {    } catch Whatpm::HTML::RestartParser with {
579      ## NOTE: Invoked after {change_encoding}.      ## NOTE: Invoked after {change_encoding}.
580    
     $self->{input_encoding} = $charset->get_iana_name;  
581      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
582          $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name?
583        !!!parse-error (type => 'chardecode:fallback',        !!!parse-error (type => 'chardecode:fallback',
                       text => $self->{input_encoding},  
584                        level => $self->{level}->{uncertain},                        level => $self->{level}->{uncertain},
585                          #text => $self->{input_encoding},
586                        line => 1, column => 1,                        line => 1, column => 1,
587                        layer => 'encode');                        layer => 'encode');
588      } elsif (not ($e_status &      } elsif (not ($e_status &
589                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL ())) {
590          $self->{input_encoding} = $charset->get_iana_name;
591        !!!parse-error (type => 'chardecode:no error',        !!!parse-error (type => 'chardecode:no error',
592                        text => $self->{input_encoding},                        text => $self->{input_encoding},
593                        level => $self->{level}->{uncertain},                        level => $self->{level}->{uncertain},
594                        line => 1, column => 1,                        line => 1, column => 1,
595                        layer => 'encode');                        layer => 'encode');
596        } else {
597          $self->{input_encoding} = $charset->get_iana_name;
598      }      }
599      $self->{confident} = 1;      $self->{confident} = 1;
600      $char_stream->onerror ($char_onerror);  
601      $return = $self->parse_char_stream ($char_stream, @args);      $wrapped_char_stream = $get_wrapper->($char_stream);
602        $wrapped_char_stream->onerror ($char_onerror);
603    
604        $return = $self->parse_char_stream ($wrapped_char_stream, @args);
605    };    };
606    return $return;    return $return;
607  } # parse_byte_stream  } # parse_byte_stream
# Line 591  sub parse_byte_stream ($$$$;$) { Line 615  sub parse_byte_stream ($$$$;$) {
615  ## such as |parse_byte_string| in this module, must ensure that it does  ## such as |parse_byte_string| in this module, must ensure that it does
616  ## strip the BOM and never strip any ZWNBSP.  ## strip the BOM and never strip any ZWNBSP.
617    
618  sub parse_char_string ($$$;$) {  sub parse_char_string ($$$;$$) {
619      #my ($self, $s, $doc, $onerror, $get_wrapper) = @_;
620    my $self = shift;    my $self = shift;
   require utf8;  
621    my $s = ref $_[0] ? $_[0] : \($_[0]);    my $s = ref $_[0] ? $_[0] : \($_[0]);
622    open my $input, '<' . (utf8::is_utf8 ($$s) ? ':utf8' : ''), $s;    require Whatpm::Charset::DecodeHandle;
623      my $input = Whatpm::Charset::DecodeHandle::CharString->new ($s);
624      if ($_[3]) {
625        $input = $_[3]->($input);
626      }
627    return $self->parse_char_stream ($input, @_[1..$#_]);    return $self->parse_char_stream ($input, @_[1..$#_]);
628  } # parse_char_string  } # parse_char_string
629  *parse_string = \&parse_char_string;  *parse_string = \&parse_char_string; ## NOTE: Alias for backward compatibility.
630    
631    my $disallowed_control_chars =
632    {
633     0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,
634     0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,
635     0x4FFFE => 1, 0x4FFFF => 1, 0x5FFFE => 1, 0x5FFFF => 1,
636     0x6FFFE => 1, 0x6FFFF => 1, 0x7FFFE => 1, 0x7FFFF => 1,
637     0x8FFFE => 1, 0x8FFFF => 1, 0x9FFFE => 1, 0x9FFFF => 1,
638     0xAFFFE => 1, 0xAFFFF => 1, 0xBFFFE => 1, 0xBFFFF => 1,
639     0xCFFFE => 1, 0xCFFFF => 1, 0xDFFFE => 1, 0xDFFFF => 1,
640     0xEFFFE => 1, 0xEFFFF => 1, 0xFFFFE => 1, 0xFFFFF => 1,
641     0x10FFFE => 1, 0x10FFFF => 1,
642    };
643    $disallowed_control_chars->{$_} = 1
644        for 0x0001 .. 0x0008, 0x000E .. 0x001F, 0x007F .. 0x009F,
645            0xD800 .. 0xDFFF, 0xFDD0 .. 0xFDDF;
646    ## ISSUE: U+FDE0-U+FDEF are not excluded
647    
648  sub parse_char_stream ($$$;$) {  sub parse_char_stream ($$$;$) {
649    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
# Line 611  sub parse_char_stream ($$$;$) { Line 656  sub parse_char_stream ($$$;$) {
656    $self->{confident} = 1 unless exists $self->{confident};    $self->{confident} = 1 unless exists $self->{confident};
657    $self->{document}->input_encoding ($self->{input_encoding})    $self->{document}->input_encoding ($self->{input_encoding})
658        if defined $self->{input_encoding};        if defined $self->{input_encoding};
659    ## TODO: |{input_encoding}| is needless?
660    
661    my $i = 0;    my $i = 0;
662    $self->{line_prev} = $self->{line} = 1;    $self->{line_prev} = $self->{line} = 1;
663    $self->{column_prev} = $self->{column} = 0;    $self->{column_prev} = -1;
664      $self->{column} = 0;
665    $self->{set_next_char} = sub {    $self->{set_next_char} = sub {
666      my $self = shift;      my $self = shift;
667    
668      pop @{$self->{prev_char}};      my $char = '';
     unshift @{$self->{prev_char}}, $self->{next_char};  
   
     my $char;  
669      if (defined $self->{next_next_char}) {      if (defined $self->{next_next_char}) {
670        $char = $self->{next_next_char};        $char = $self->{next_next_char};
671        delete $self->{next_next_char};        delete $self->{next_next_char};
672          $self->{next_char} = ord $char;
673      } else {      } else {
674        $char = $input->getc;        $self->{char_buffer} = '';
675          $self->{char_buffer_pos} = 0;
676    
677          my $count = $input->manakai_read_until
678             ($self->{char_buffer},
679              qr/(?![\x{FDD0}-\x{FDDF}\x{FFFE}\x{FFFF}\x{1FFFE}\x{1FFFF}\x{2FFFE}\x{2FFFF}\x{3FFFE}\x{3FFFF}\x{4FFFE}\x{4FFFF}\x{5FFFE}\x{5FFFF}\x{6FFFE}\x{6FFFF}\x{7FFFE}\x{7FFFF}\x{8FFFE}\x{8FFFF}\x{9FFFE}\x{9FFFF}\x{AFFFE}\x{AFFFF}\x{BFFFE}\x{BFFFF}\x{CFFFE}\x{CFFFF}\x{DFFFE}\x{DFFFF}\x{EFFFE}\x{EFFFF}\x{FFFFE}\x{FFFFF}])[\x20-\x7E\xA0-\x{D7FF}\x{E000}-\x{10FFFD}]/,
680              $self->{char_buffer_pos});
681          if ($count) {
682            $self->{line_prev} = $self->{line};
683            $self->{column_prev} = $self->{column};
684            $self->{column}++;
685            $self->{next_char}
686                = ord substr ($self->{char_buffer}, $self->{char_buffer_pos}++, 1);
687            return;
688          }
689    
690          if ($input->read ($char, 1)) {
691            $self->{next_char} = ord $char;
692          } else {
693            $self->{next_char} = -1;
694            return;
695          }
696      }      }
     $self->{next_char} = -1 and return unless defined $char;  
     $self->{next_char} = ord $char;  
697    
698      ($self->{line_prev}, $self->{column_prev})      ($self->{line_prev}, $self->{column_prev})
699          = ($self->{line}, $self->{column});          = ($self->{line}, $self->{column});
# Line 641  sub parse_char_stream ($$$;$) { Line 705  sub parse_char_stream ($$$;$) {
705        $self->{column} = 0;        $self->{column} = 0;
706      } elsif ($self->{next_char} == 0x000D) { # CR      } elsif ($self->{next_char} == 0x000D) { # CR
707        !!!cp ('j2');        !!!cp ('j2');
708        my $next = $input->getc;  ## TODO: support for abort/streaming
709        if (defined $next and $next ne "\x0A") {        my $next = '';
710          if ($input->read ($next, 1) and $next ne "\x0A") {
711          $self->{next_next_char} = $next;          $self->{next_next_char} = $next;
712        }        }
713        $self->{next_char} = 0x000A; # LF # MUST        $self->{next_char} = 0x000A; # LF # MUST
# Line 655  sub parse_char_stream ($$$;$) { Line 720  sub parse_char_stream ($$$;$) {
720        !!!cp ('j4');        !!!cp ('j4');
721        !!!parse-error (type => 'NULL');        !!!parse-error (type => 'NULL');
722        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
723      } elsif ($self->{next_char} <= 0x0008 or      } elsif ($disallowed_control_chars->{$self->{next_char}}) {
              (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}}) {  
724        !!!cp ('j5');        !!!cp ('j5');
725        if ($self->{next_char} < 0x10000) {        if ($self->{next_char} < 0x10000) {
726          !!!parse-error (type => 'control char',          !!!parse-error (type => 'control char',
# Line 681  sub parse_char_stream ($$$;$) { Line 731  sub parse_char_stream ($$$;$) {
731        }        }
732      }      }
733    };    };
734    $self->{prev_char} = [-1, -1, -1];  
735    $self->{next_char} = -1;    $self->{read_until} = sub {
736        #my ($scalar, $specials_range, $offset) = @_;
737        return 0 if defined $self->{next_next_char};
738    
739        my $pattern = qr/(?![$_[1]\x{FDD0}-\x{FDDF}\x{FFFE}\x{FFFF}\x{1FFFE}\x{1FFFF}\x{2FFFE}\x{2FFFF}\x{3FFFE}\x{3FFFF}\x{4FFFE}\x{4FFFF}\x{5FFFE}\x{5FFFF}\x{6FFFE}\x{6FFFF}\x{7FFFE}\x{7FFFF}\x{8FFFE}\x{8FFFF}\x{9FFFE}\x{9FFFF}\x{AFFFE}\x{AFFFF}\x{BFFFE}\x{BFFFF}\x{CFFFE}\x{CFFFF}\x{DFFFE}\x{DFFFF}\x{EFFFE}\x{EFFFF}\x{FFFFE}\x{FFFFF}])[\x20-\x7E\xA0-\x{D7FF}\x{E000}-\x{10FFFD}]/;
740        my $offset = $_[2] || 0;
741    
742        if ($self->{char_buffer_pos} < length $self->{char_buffer}) {
743          pos ($self->{char_buffer}) = $self->{char_buffer_pos};
744          if ($self->{char_buffer} =~ /\G(?>$pattern)+/) {
745            substr ($_[0], $offset)
746                = substr ($self->{char_buffer}, $-[0], $+[0] - $-[0]);
747            my $count = $+[0] - $-[0];
748            if ($count) {
749              $self->{column} += $count;
750              $self->{char_buffer_pos} += $count;
751              $self->{line_prev} = $self->{line};
752              $self->{column_prev} = $self->{column} - 1;
753              $self->{prev_char} = [-1, -1, -1];
754              $self->{next_char} = -1;
755            }
756            return $count;
757          } else {
758            return 0;
759          }
760        } else {
761          my $count = $input->manakai_read_until ($_[0], $pattern, $_[2]);
762          if ($count) {
763            $self->{column} += $count;
764            $self->{line_prev} = $self->{line};
765            $self->{column_prev} = $self->{column} - 1;
766            $self->{prev_char} = [-1, -1, -1];
767            $self->{next_char} = -1;
768          }
769          return $count;
770        }
771      }; # $self->{read_until}
772    
773    my $onerror = $_[2] || sub {    my $onerror = $_[2] || sub {
774      my (%opt) = @_;      my (%opt) = @_;
# Line 708  sub new ($) { Line 794  sub new ($) {
794    my $class = shift;    my $class = shift;
795    my $self = bless {    my $self = bless {
796      level => {must => 'm',      level => {must => 'm',
797                  should => 's',
798                warn => 'w',                warn => 'w',
799                info => 'i',                info => 'i',
800                uncertain => 'u'},                uncertain => 'u'},
# Line 740  sub RCDATA_CONTENT_MODEL () { CM_ENTITY Line 827  sub RCDATA_CONTENT_MODEL () { CM_ENTITY
827  sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }  sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }
828    
829  sub DATA_STATE () { 0 }  sub DATA_STATE () { 0 }
830  sub ENTITY_DATA_STATE () { 1 }  #sub ENTITY_DATA_STATE () { 1 }
831  sub TAG_OPEN_STATE () { 2 }  sub TAG_OPEN_STATE () { 2 }
832  sub CLOSE_TAG_OPEN_STATE () { 3 }  sub CLOSE_TAG_OPEN_STATE () { 3 }
833  sub TAG_NAME_STATE () { 4 }  sub TAG_NAME_STATE () { 4 }
# Line 751  sub BEFORE_ATTRIBUTE_VALUE_STATE () { 8 Line 838  sub BEFORE_ATTRIBUTE_VALUE_STATE () { 8
838  sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 }  sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 }
839  sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 }  sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 }
840  sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 }  sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 }
841  sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 }  #sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 }
842  sub MARKUP_DECLARATION_OPEN_STATE () { 13 }  sub MARKUP_DECLARATION_OPEN_STATE () { 13 }
843  sub COMMENT_START_STATE () { 14 }  sub COMMENT_START_STATE () { 14 }
844  sub COMMENT_START_DASH_STATE () { 15 }  sub COMMENT_START_DASH_STATE () { 15 }
# Line 774  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STAT Line 861  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STAT
861  sub BOGUS_DOCTYPE_STATE () { 32 }  sub BOGUS_DOCTYPE_STATE () { 32 }
862  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }
863  sub SELF_CLOSING_START_TAG_STATE () { 34 }  sub SELF_CLOSING_START_TAG_STATE () { 34 }
864  sub CDATA_BLOCK_STATE () { 35 }  sub CDATA_SECTION_STATE () { 35 }
865    sub MD_HYPHEN_STATE () { 36 } # "markup declaration open state" in the spec
866    sub MD_DOCTYPE_STATE () { 37 } # "markup declaration open state" in the spec
867    sub MD_CDATA_STATE () { 38 } # "markup declaration open state" in the spec
868    sub CDATA_PCDATA_CLOSE_TAG_STATE () { 39 } # "close tag open state" in the spec
869    sub CDATA_SECTION_MSE1_STATE () { 40 } # "CDATA section state" in the spec
870    sub CDATA_SECTION_MSE2_STATE () { 41 } # "CDATA section state" in the spec
871    sub PUBLIC_STATE () { 42 } # "after DOCTYPE name state" in the spec
872    sub SYSTEM_STATE () { 43 } # "after DOCTYPE name state" in the spec
873    ## NOTE: "Entity data state", "entity in attribute value state", and
874    ## "consume a character reference" algorithm are jointly implemented
875    ## using the following six states:
876    sub ENTITY_STATE () { 44 }
877    sub ENTITY_HASH_STATE () { 45 }
878    sub NCR_NUM_STATE () { 46 }
879    sub HEXREF_X_STATE () { 47 }
880    sub HEXREF_HEX_STATE () { 48 }
881    sub ENTITY_NAME_STATE () { 49 }
882    
883  sub DOCTYPE_TOKEN () { 1 }  sub DOCTYPE_TOKEN () { 1 }
884  sub COMMENT_TOKEN () { 2 }  sub COMMENT_TOKEN () { 2 }
# Line 827  sub IN_COLUMN_GROUP_IM () { 0b10 } Line 931  sub IN_COLUMN_GROUP_IM () { 0b10 }
931  sub _initialize_tokenizer ($) {  sub _initialize_tokenizer ($) {
932    my $self = shift;    my $self = shift;
933    $self->{state} = DATA_STATE; # MUST    $self->{state} = DATA_STATE; # MUST
934      #$self->{state_keyword}; # initialized when used
935      #$self->{entity__value}; # initialized when used
936      #$self->{entity__match}; # initialized when used
937    $self->{content_model} = PCDATA_CONTENT_MODEL; # be    $self->{content_model} = PCDATA_CONTENT_MODEL; # be
938    undef $self->{current_token}; # start tag, end tag, comment, or DOCTYPE    undef $self->{current_token};
939    undef $self->{current_attribute};    undef $self->{current_attribute};
940    undef $self->{last_emitted_start_tag_name};    undef $self->{last_emitted_start_tag_name};
941    undef $self->{last_attribute_value_state};    #$self->{prev_state}; # initialized when used
942    delete $self->{self_closing};    delete $self->{self_closing};
943    $self->{char} = [];    $self->{char_buffer} = '';
944    # $self->{next_char}    $self->{char_buffer_pos} = 0;
945      $self->{prev_char} = [-1, -1, -1];
946      $self->{next_char} = -1;
947    !!!next-input-character;    !!!next-input-character;
948    $self->{token} = [];    $self->{token} = [];
949    # $self->{escape}    # $self->{escape}
# Line 865  sub _initialize_tokenizer ($) { Line 974  sub _initialize_tokenizer ($) {
974  ## has completed loading.  If one has, then it MUST be executed  ## has completed loading.  If one has, then it MUST be executed
975  ## and removed from the list.  ## and removed from the list.
976    
977  ## NOTE: HTML5 "Writing HTML documents" section, applied to  ## TODO: Polytheistic slash SHOULD NOT be used. (Applied only to atheists.)
978  ## 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,  
979    
980  sub _get_next_token ($) {  sub _get_next_token ($) {
981    my $self = shift;    my $self = shift;
# Line 902  sub _get_next_token ($) { Line 999  sub _get_next_token ($) {
999          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA
1000              not $self->{escape}) {              not $self->{escape}) {
1001            !!!cp (1);            !!!cp (1);
1002            $self->{state} = ENTITY_DATA_STATE;            ## NOTE: In the spec, the tokenizer is switched to the
1003              ## "entity data state".  In this implementation, the tokenizer
1004              ## is switched to the |ENTITY_STATE|, which is an implementation
1005              ## of the "consume a character reference" algorithm.
1006              $self->{entity_additional} = -1;
1007              $self->{prev_state} = DATA_STATE;
1008              $self->{state} = ENTITY_STATE;
1009            !!!next-input-character;            !!!next-input-character;
1010            redo A;            redo A;
1011          } else {          } else {
# Line 966  sub _get_next_token ($) { Line 1069  sub _get_next_token ($) {
1069                     data => chr $self->{next_char},                     data => chr $self->{next_char},
1070                     line => $self->{line}, column => $self->{column},                     line => $self->{line}, column => $self->{column},
1071                    };                    };
1072          $self->{read_until}->($token->{data}, q[-!<>&], length $token->{data});
1073    
1074        ## Stay in the data state        ## Stay in the data state
1075        !!!next-input-character;        !!!next-input-character;
1076    
1077        !!!emit ($token);        !!!emit ($token);
1078    
1079        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;  
1080      } elsif ($self->{state} == TAG_OPEN_STATE) {      } elsif ($self->{state} == TAG_OPEN_STATE) {
1081        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1082          if ($self->{next_char} == 0x002F) { # /          if ($self->{next_char} == 0x002F) { # /
# Line 1089  sub _get_next_token ($) { Line 1173  sub _get_next_token ($) {
1173          die "$0: $self->{content_model} in tag open";          die "$0: $self->{content_model} in tag open";
1174        }        }
1175      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {
1176          ## NOTE: The "close tag open state" in the spec is implemented as
1177          ## |CLOSE_TAG_OPEN_STATE| and |CDATA_PCDATA_CLOSE_TAG_STATE|.
1178    
1179        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"
1180        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1181          if (defined $self->{last_emitted_start_tag_name}) {          if (defined $self->{last_emitted_start_tag_name}) {
1182              $self->{state} = CDATA_PCDATA_CLOSE_TAG_STATE;
1183            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>            $self->{state_keyword} = '';
1184            my @next_char;            ## Reconsume.
1185            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...  
           }  
1186          } else {          } else {
1187            ## No start tag token has ever been emitted            ## No start tag token has ever been emitted
1188              ## NOTE: See <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>.
1189            !!!cp (28);            !!!cp (28);
           # next-input-character is already done  
1190            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1191              ## Reconsume.
1192            !!!emit ({type => CHARACTER_TOKEN, data => '</',            !!!emit ({type => CHARACTER_TOKEN, data => '</',
1193                      line => $l, column => $c,                      line => $l, column => $c,
1194                     });                     });
1195            redo A;            redo A;
1196          }          }
1197        }        }
1198          
1199        if (0x0041 <= $self->{next_char} and        if (0x0041 <= $self->{next_char} and
1200            $self->{next_char} <= 0x005A) { # A..Z            $self->{next_char} <= 0x005A) { # A..Z
1201          !!!cp (29);          !!!cp (29);
# Line 1198  sub _get_next_token ($) { Line 1242  sub _get_next_token ($) {
1242                                    line => $self->{line_prev}, # "<" of "</"                                    line => $self->{line_prev}, # "<" of "</"
1243                                    column => $self->{column_prev} - 1,                                    column => $self->{column_prev} - 1,
1244                                   };                                   };
1245          ## $self->{next_char} is intentionally left as is          ## NOTE: $self->{next_char} is intentionally left as is.
1246          redo A;          ## Although the "anything else" case of the spec not explicitly
1247            ## states that the next input character is to be reconsumed,
1248            ## it will be included to the |data| of the comment token
1249            ## generated from the bogus end tag, as defined in the
1250            ## "bogus comment state" entry.
1251            redo A;
1252          }
1253        } elsif ($self->{state} == CDATA_PCDATA_CLOSE_TAG_STATE) {
1254          my $ch = substr $self->{last_emitted_start_tag_name}, length $self->{state_keyword}, 1;
1255          if (length $ch) {
1256            my $CH = $ch;
1257            $ch =~ tr/a-z/A-Z/;
1258            my $nch = chr $self->{next_char};
1259            if ($nch eq $ch or $nch eq $CH) {
1260              !!!cp (24);
1261              ## Stay in the state.
1262              $self->{state_keyword} .= $nch;
1263              !!!next-input-character;
1264              redo A;
1265            } else {
1266              !!!cp (25);
1267              $self->{state} = DATA_STATE;
1268              ## Reconsume.
1269              !!!emit ({type => CHARACTER_TOKEN,
1270                        data => '</' . $self->{state_keyword},
1271                        line => $self->{line_prev},
1272                        column => $self->{column_prev} - 1 - length $self->{state_keyword},
1273                       });
1274              redo A;
1275            }
1276          } else { # after "<{tag-name}"
1277            unless ({
1278                     0x0009 => 1, # HT
1279                     0x000A => 1, # LF
1280                     0x000B => 1, # VT
1281                     0x000C => 1, # FF
1282                     0x0020 => 1, # SP
1283                     0x003E => 1, # >
1284                     0x002F => 1, # /
1285                     -1 => 1, # EOF
1286                    }->{$self->{next_char}}) {
1287              !!!cp (26);
1288              ## Reconsume.
1289              $self->{state} = DATA_STATE;
1290              !!!emit ({type => CHARACTER_TOKEN,
1291                        data => '</' . $self->{state_keyword},
1292                        line => $self->{line_prev},
1293                        column => $self->{column_prev} - 1 - length $self->{state_keyword},
1294                       });
1295              redo A;
1296            } else {
1297              !!!cp (27);
1298              $self->{current_token}
1299                  = {type => END_TAG_TOKEN,
1300                     tag_name => $self->{last_emitted_start_tag_name},
1301                     line => $self->{line_prev},
1302                     column => $self->{column_prev} - 1 - length $self->{state_keyword}};
1303              $self->{state} = TAG_NAME_STATE;
1304              ## Reconsume.
1305              redo A;
1306            }
1307        }        }
1308      } elsif ($self->{state} == TAG_NAME_STATE) {      } elsif ($self->{state} == TAG_NAME_STATE) {
1309        if ($self->{next_char} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
# Line 1540  sub _get_next_token ($) { Line 1644  sub _get_next_token ($) {
1644    
1645          redo A;          redo A;
1646        } else {        } else {
1647          !!!cp (82);          if ($self->{next_char} == 0x0022 or # "
1648                $self->{next_char} == 0x0027) { # '
1649              !!!cp (78);
1650              !!!parse-error (type => 'bad attribute name');
1651            } else {
1652              !!!cp (82);
1653            }
1654          $self->{current_attribute}          $self->{current_attribute}
1655              = {name => chr ($self->{next_char}),              = {name => chr ($self->{next_char}),
1656                 value => '',                 value => '',
# Line 1575  sub _get_next_token ($) { Line 1685  sub _get_next_token ($) {
1685          !!!next-input-character;          !!!next-input-character;
1686          redo A;          redo A;
1687        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1688            !!!parse-error (type => 'empty unquoted attribute value');
1689          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1690            !!!cp (87);            !!!cp (87);
1691            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
# Line 1639  sub _get_next_token ($) { Line 1750  sub _get_next_token ($) {
1750          redo A;          redo A;
1751        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1752          !!!cp (96);          !!!cp (96);
1753          $self->{last_attribute_value_state} = $self->{state};          ## NOTE: In the spec, the tokenizer is switched to the
1754          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## "entity in attribute value state".  In this implementation, the
1755            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1756            ## implementation of the "consume a character reference" algorithm.
1757            $self->{prev_state} = $self->{state};
1758            $self->{entity_additional} = 0x0022; # "
1759            $self->{state} = ENTITY_STATE;
1760          !!!next-input-character;          !!!next-input-character;
1761          redo A;          redo A;
1762        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
# Line 1669  sub _get_next_token ($) { Line 1785  sub _get_next_token ($) {
1785        } else {        } else {
1786          !!!cp (100);          !!!cp (100);
1787          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{current_attribute}->{value} .= chr ($self->{next_char});
1788            $self->{read_until}->($self->{current_attribute}->{value},
1789                                  q["&],
1790                                  length $self->{current_attribute}->{value});
1791    
1792          ## Stay in the state          ## Stay in the state
1793          !!!next-input-character;          !!!next-input-character;
1794          redo A;          redo A;
# Line 1681  sub _get_next_token ($) { Line 1801  sub _get_next_token ($) {
1801          redo A;          redo A;
1802        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1803          !!!cp (102);          !!!cp (102);
1804          $self->{last_attribute_value_state} = $self->{state};          ## NOTE: In the spec, the tokenizer is switched to the
1805          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## "entity in attribute value state".  In this implementation, the
1806            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1807            ## implementation of the "consume a character reference" algorithm.
1808            $self->{entity_additional} = 0x0027; # '
1809            $self->{prev_state} = $self->{state};
1810            $self->{state} = ENTITY_STATE;
1811          !!!next-input-character;          !!!next-input-character;
1812          redo A;          redo A;
1813        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
# Line 1711  sub _get_next_token ($) { Line 1836  sub _get_next_token ($) {
1836        } else {        } else {
1837          !!!cp (106);          !!!cp (106);
1838          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{current_attribute}->{value} .= chr ($self->{next_char});
1839            $self->{read_until}->($self->{current_attribute}->{value},
1840                                  q['&],
1841                                  length $self->{current_attribute}->{value});
1842    
1843          ## Stay in the state          ## Stay in the state
1844          !!!next-input-character;          !!!next-input-character;
1845          redo A;          redo A;
# Line 1727  sub _get_next_token ($) { Line 1856  sub _get_next_token ($) {
1856          redo A;          redo A;
1857        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1858          !!!cp (108);          !!!cp (108);
1859          $self->{last_attribute_value_state} = $self->{state};          ## NOTE: In the spec, the tokenizer is switched to the
1860          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## "entity in attribute value state".  In this implementation, the
1861            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1862            ## implementation of the "consume a character reference" algorithm.
1863            $self->{entity_additional} = -1;
1864            $self->{prev_state} = $self->{state};
1865            $self->{state} = ENTITY_STATE;
1866          !!!next-input-character;          !!!next-input-character;
1867          redo A;          redo A;
1868        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
# Line 1788  sub _get_next_token ($) { Line 1922  sub _get_next_token ($) {
1922            !!!cp (116);            !!!cp (116);
1923          }          }
1924          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{current_attribute}->{value} .= chr ($self->{next_char});
1925            $self->{read_until}->($self->{current_attribute}->{value},
1926                                  q["'=& >],
1927                                  length $self->{current_attribute}->{value});
1928    
1929          ## Stay in the state          ## Stay in the state
1930          !!!next-input-character;          !!!next-input-character;
1931          redo A;          redo A;
1932        }        }
     } 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;  
1933      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {
1934        if ($self->{next_char} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
1935            $self->{next_char} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
# Line 1933  sub _get_next_token ($) { Line 2049  sub _get_next_token ($) {
2049        }        }
2050      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {
2051        ## (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;  
2052    
2053            !!!emit ($self->{current_token}); # comment        ## NOTE: Unlike spec's "bogus comment state", this implementation
2054          ## consumes characters one-by-one basis.
2055            redo A;        
2056          } elsif ($self->{next_char} == -1) {        if ($self->{next_char} == 0x003E) { # >
2057            !!!cp (125);          !!!cp (124);
2058            $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2059            ## reconsume          !!!next-input-character;
2060    
2061            !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
2062            redo A;
2063          } elsif ($self->{next_char} == -1) {
2064            !!!cp (125);
2065            $self->{state} = DATA_STATE;
2066            ## reconsume
2067    
2068            redo A;          !!!emit ($self->{current_token}); # comment
2069          } else {          redo A;
2070            !!!cp (126);        } else {
2071            $self->{current_token}->{data} .= chr ($self->{next_char}); # comment          !!!cp (126);
2072            !!!next-input-character;          $self->{current_token}->{data} .= chr ($self->{next_char}); # comment
2073            redo BC;          $self->{read_until}->($self->{current_token}->{data},
2074          }                                q[>],
2075        } # BC                                length $self->{current_token}->{data});
2076    
2077        die "$0: _get_next_token: unexpected case [BC]";          ## Stay in the state.
2078            !!!next-input-character;
2079            redo A;
2080          }
2081      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {
2082        ## (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};  
2083                
2084        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
2085            !!!cp (133);
2086            $self->{state} = MD_HYPHEN_STATE;
2087          !!!next-input-character;          !!!next-input-character;
2088          push @next_char, $self->{next_char};          redo A;
         if ($self->{next_char} == 0x002D) { # -  
           !!!cp (127);  
           $self->{current_token} = {type => COMMENT_TOKEN, data => '',  
                                     line => $l, column => $c,  
                                    };  
           $self->{state} = COMMENT_START_STATE;  
           !!!next-input-character;  
           redo A;  
         } else {  
           !!!cp (128);  
         }  
2089        } elsif ($self->{next_char} == 0x0044 or # D        } elsif ($self->{next_char} == 0x0044 or # D
2090                 $self->{next_char} == 0x0064) { # d                 $self->{next_char} == 0x0064) { # d
2091            ## ASCII case-insensitive.
2092            !!!cp (130);
2093            $self->{state} = MD_DOCTYPE_STATE;
2094            $self->{state_keyword} = chr $self->{next_char};
2095          !!!next-input-character;          !!!next-input-character;
2096          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);  
         }  
2097        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and
2098                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and
2099                 $self->{next_char} == 0x005B) { # [                 $self->{next_char} == 0x005B) { # [
2100            !!!cp (135.4);                
2101            $self->{state} = MD_CDATA_STATE;
2102            $self->{state_keyword} = '[';
2103          !!!next-input-character;          !!!next-input-character;
2104          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);  
         }  
2105        } else {        } else {
2106          !!!cp (136);          !!!cp (136);
2107        }        }
2108    
2109        !!!parse-error (type => 'bogus comment');        !!!parse-error (type => 'bogus comment',
2110        $self->{next_char} = shift @next_char;                        line => $self->{line_prev},
2111        !!!back-next-input-character (@next_char);                        column => $self->{column_prev} - 1);
2112          ## Reconsume.
2113        $self->{state} = BOGUS_COMMENT_STATE;        $self->{state} = BOGUS_COMMENT_STATE;
2114        $self->{current_token} = {type => COMMENT_TOKEN, data => '',        $self->{current_token} = {type => COMMENT_TOKEN, data => '',
2115                                  line => $l, column => $c,                                  line => $self->{line_prev},
2116                                    column => $self->{column_prev} - 1,
2117                                 };                                 };
2118        redo A;        redo A;
2119              } elsif ($self->{state} == MD_HYPHEN_STATE) {
2120        ## ISSUE: typos in spec: chacacters, is is a parse error        if ($self->{next_char} == 0x002D) { # -
2121        ## 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);
2122            $self->{current_token} = {type => COMMENT_TOKEN, data => '',
2123                                      line => $self->{line_prev},
2124                                      column => $self->{column_prev} - 2,
2125                                     };
2126            $self->{state} = COMMENT_START_STATE;
2127            !!!next-input-character;
2128            redo A;
2129          } else {
2130            !!!cp (128);
2131            !!!parse-error (type => 'bogus comment',
2132                            line => $self->{line_prev},
2133                            column => $self->{column_prev} - 2);
2134            $self->{state} = BOGUS_COMMENT_STATE;
2135            ## Reconsume.
2136            $self->{current_token} = {type => COMMENT_TOKEN,
2137                                      data => '-',
2138                                      line => $self->{line_prev},
2139                                      column => $self->{column_prev} - 2,
2140                                     };
2141            redo A;
2142          }
2143        } elsif ($self->{state} == MD_DOCTYPE_STATE) {
2144          ## ASCII case-insensitive.
2145          if ($self->{next_char} == [
2146                undef,
2147                0x004F, # O
2148                0x0043, # C
2149                0x0054, # T
2150                0x0059, # Y
2151                0x0050, # P
2152              ]->[length $self->{state_keyword}] or
2153              $self->{next_char} == [
2154                undef,
2155                0x006F, # o
2156                0x0063, # c
2157                0x0074, # t
2158                0x0079, # y
2159                0x0070, # p
2160              ]->[length $self->{state_keyword}]) {
2161            !!!cp (131);
2162            ## Stay in the state.
2163            $self->{state_keyword} .= chr $self->{next_char};
2164            !!!next-input-character;
2165            redo A;
2166          } elsif ((length $self->{state_keyword}) == 6 and
2167                   ($self->{next_char} == 0x0045 or # E
2168                    $self->{next_char} == 0x0065)) { # e
2169            !!!cp (129);
2170            $self->{state} = DOCTYPE_STATE;
2171            $self->{current_token} = {type => DOCTYPE_TOKEN,
2172                                      quirks => 1,
2173                                      line => $self->{line_prev},
2174                                      column => $self->{column_prev} - 7,
2175                                     };
2176            !!!next-input-character;
2177            redo A;
2178          } else {
2179            !!!cp (132);        
2180            !!!parse-error (type => 'bogus comment',
2181                            line => $self->{line_prev},
2182                            column => $self->{column_prev} - 1 - length $self->{state_keyword});
2183            $self->{state} = BOGUS_COMMENT_STATE;
2184            ## Reconsume.
2185            $self->{current_token} = {type => COMMENT_TOKEN,
2186                                      data => $self->{state_keyword},
2187                                      line => $self->{line_prev},
2188                                      column => $self->{column_prev} - 1 - length $self->{state_keyword},
2189                                     };
2190            redo A;
2191          }
2192        } elsif ($self->{state} == MD_CDATA_STATE) {
2193          if ($self->{next_char} == {
2194                '[' => 0x0043, # C
2195                '[C' => 0x0044, # D
2196                '[CD' => 0x0041, # A
2197                '[CDA' => 0x0054, # T
2198                '[CDAT' => 0x0041, # A
2199              }->{$self->{state_keyword}}) {
2200            !!!cp (135.1);
2201            ## Stay in the state.
2202            $self->{state_keyword} .= chr $self->{next_char};
2203            !!!next-input-character;
2204            redo A;
2205          } elsif ($self->{state_keyword} eq '[CDATA' and
2206                   $self->{next_char} == 0x005B) { # [
2207            !!!cp (135.2);
2208            $self->{current_token} = {type => CHARACTER_TOKEN,
2209                                      data => '',
2210                                      line => $self->{line_prev},
2211                                      column => $self->{column_prev} - 7};
2212            $self->{state} = CDATA_SECTION_STATE;
2213            !!!next-input-character;
2214            redo A;
2215          } else {
2216            !!!cp (135.3);
2217            !!!parse-error (type => 'bogus comment',
2218                            line => $self->{line_prev},
2219                            column => $self->{column_prev} - 1 - length $self->{state_keyword});
2220            $self->{state} = BOGUS_COMMENT_STATE;
2221            ## Reconsume.
2222            $self->{current_token} = {type => COMMENT_TOKEN,
2223                                      data => $self->{state_keyword},
2224                                      line => $self->{line_prev},
2225                                      column => $self->{column_prev} - 1 - length $self->{state_keyword},
2226                                     };
2227            redo A;
2228          }
2229      } elsif ($self->{state} == COMMENT_START_STATE) {      } elsif ($self->{state} == COMMENT_START_STATE) {
2230        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
2231          !!!cp (137);          !!!cp (137);
# Line 2178  sub _get_next_token ($) { Line 2308  sub _get_next_token ($) {
2308        } else {        } else {
2309          !!!cp (147);          !!!cp (147);
2310          $self->{current_token}->{data} .= chr ($self->{next_char}); # comment          $self->{current_token}->{data} .= chr ($self->{next_char}); # comment
2311            $self->{read_until}->($self->{current_token}->{data},
2312                                  q[-],
2313                                  length $self->{current_token}->{data});
2314    
2315          ## Stay in the state          ## Stay in the state
2316          !!!next-input-character;          !!!next-input-character;
2317          redo A;          redo A;
# Line 2362  sub _get_next_token ($) { Line 2496  sub _get_next_token ($) {
2496          redo A;          redo A;
2497        } elsif ($self->{next_char} == 0x0050 or # P        } elsif ($self->{next_char} == 0x0050 or # P
2498                 $self->{next_char} == 0x0070) { # p                 $self->{next_char} == 0x0070) { # p
2499            $self->{state} = PUBLIC_STATE;
2500            $self->{state_keyword} = chr $self->{next_char};
2501          !!!next-input-character;          !!!next-input-character;
2502          if ($self->{next_char} == 0x0055 or # U          redo A;
             $self->{next_char} == 0x0075) { # u  
           !!!next-input-character;  
           if ($self->{next_char} == 0x0042 or # B  
               $self->{next_char} == 0x0062) { # b  
             !!!next-input-character;  
             if ($self->{next_char} == 0x004C or # L  
                 $self->{next_char} == 0x006C) { # l  
               !!!next-input-character;  
               if ($self->{next_char} == 0x0049 or # I  
                   $self->{next_char} == 0x0069) { # i  
                 !!!next-input-character;  
                 if ($self->{next_char} == 0x0043 or # C  
                     $self->{next_char} == 0x0063) { # c  
                   !!!cp (168);  
                   $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;  
                   !!!next-input-character;  
                   redo A;  
                 } else {  
                   !!!cp (169);  
                 }  
               } else {  
                 !!!cp (170);  
               }  
             } else {  
               !!!cp (171);  
             }  
           } else {  
             !!!cp (172);  
           }  
         } else {  
           !!!cp (173);  
         }  
   
         #  
2503        } elsif ($self->{next_char} == 0x0053 or # S        } elsif ($self->{next_char} == 0x0053 or # S
2504                 $self->{next_char} == 0x0073) { # s                 $self->{next_char} == 0x0073) { # s
2505            $self->{state} = SYSTEM_STATE;
2506            $self->{state_keyword} = chr $self->{next_char};
2507          !!!next-input-character;          !!!next-input-character;
2508          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);  
         }  
   
         #  
2509        } else {        } else {
2510          !!!cp (180);          !!!cp (180);
2511            !!!parse-error (type => 'string after DOCTYPE name');
2512            $self->{current_token}->{quirks} = 1;
2513    
2514            $self->{state} = BOGUS_DOCTYPE_STATE;
2515          !!!next-input-character;          !!!next-input-character;
2516          #          redo A;
2517        }        }
2518        } elsif ($self->{state} == PUBLIC_STATE) {
2519          ## ASCII case-insensitive
2520          if ($self->{next_char} == [
2521                undef,
2522                0x0055, # U
2523                0x0042, # B
2524                0x004C, # L
2525                0x0049, # I
2526              ]->[length $self->{state_keyword}] or
2527              $self->{next_char} == [
2528                undef,
2529                0x0075, # u
2530                0x0062, # b
2531                0x006C, # l
2532                0x0069, # i
2533              ]->[length $self->{state_keyword}]) {
2534            !!!cp (175);
2535            ## Stay in the state.
2536            $self->{state_keyword} .= chr $self->{next_char};
2537            !!!next-input-character;
2538            redo A;
2539          } elsif ((length $self->{state_keyword}) == 5 and
2540                   ($self->{next_char} == 0x0043 or # C
2541                    $self->{next_char} == 0x0063)) { # c
2542            !!!cp (168);
2543            $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
2544            !!!next-input-character;
2545            redo A;
2546          } else {
2547            !!!cp (169);
2548            !!!parse-error (type => 'string after DOCTYPE name',
2549                            line => $self->{line_prev},
2550                            column => $self->{column_prev} + 1 - length $self->{state_keyword});
2551            $self->{current_token}->{quirks} = 1;
2552    
2553        !!!parse-error (type => 'string after DOCTYPE name');          $self->{state} = BOGUS_DOCTYPE_STATE;
2554        $self->{current_token}->{quirks} = 1;          ## Reconsume.
2555            redo A;
2556          }
2557        } elsif ($self->{state} == SYSTEM_STATE) {
2558          ## ASCII case-insensitive
2559          if ($self->{next_char} == [
2560                undef,
2561                0x0059, # Y
2562                0x0053, # S
2563                0x0054, # T
2564                0x0045, # E
2565              ]->[length $self->{state_keyword}] or
2566              $self->{next_char} == [
2567                undef,
2568                0x0079, # y
2569                0x0073, # s
2570                0x0074, # t
2571                0x0065, # e
2572              ]->[length $self->{state_keyword}]) {
2573            !!!cp (170);
2574            ## Stay in the state.
2575            $self->{state_keyword} .= chr $self->{next_char};
2576            !!!next-input-character;
2577            redo A;
2578          } elsif ((length $self->{state_keyword}) == 5 and
2579                   ($self->{next_char} == 0x004D or # M
2580                    $self->{next_char} == 0x006D)) { # m
2581            !!!cp (171);
2582            $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2583            !!!next-input-character;
2584            redo A;
2585          } else {
2586            !!!cp (172);
2587            !!!parse-error (type => 'string after DOCTYPE name',
2588                            line => $self->{line_prev},
2589                            column => $self->{column_prev} + 1 - length $self->{state_keyword});
2590            $self->{current_token}->{quirks} = 1;
2591    
2592        $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2593        # next-input-character is already done          ## Reconsume.
2594        redo A;          redo A;
2595          }
2596      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {
2597        if ({        if ({
2598              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
# Line 2532  sub _get_next_token ($) { Line 2677  sub _get_next_token ($) {
2677          !!!cp (190);          !!!cp (190);
2678          $self->{current_token}->{public_identifier} # DOCTYPE          $self->{current_token}->{public_identifier} # DOCTYPE
2679              .= chr $self->{next_char};              .= chr $self->{next_char};
2680            $self->{read_until}->($self->{current_token}->{public_identifier},
2681                                  q[">],
2682                                  length $self->{current_token}->{public_identifier});
2683    
2684          ## Stay in the state          ## Stay in the state
2685          !!!next-input-character;          !!!next-input-character;
2686          redo A;          redo A;
# Line 2568  sub _get_next_token ($) { Line 2717  sub _get_next_token ($) {
2717          !!!cp (194);          !!!cp (194);
2718          $self->{current_token}->{public_identifier} # DOCTYPE          $self->{current_token}->{public_identifier} # DOCTYPE
2719              .= chr $self->{next_char};              .= chr $self->{next_char};
2720            $self->{read_until}->($self->{current_token}->{public_identifier},
2721                                  q['>],
2722                                  length $self->{current_token}->{public_identifier});
2723    
2724          ## Stay in the state          ## Stay in the state
2725          !!!next-input-character;          !!!next-input-character;
2726          redo A;          redo A;
# Line 2704  sub _get_next_token ($) { Line 2857  sub _get_next_token ($) {
2857          !!!cp (210);          !!!cp (210);
2858          $self->{current_token}->{system_identifier} # DOCTYPE          $self->{current_token}->{system_identifier} # DOCTYPE
2859              .= chr $self->{next_char};              .= chr $self->{next_char};
2860            $self->{read_until}->($self->{current_token}->{system_identifier},
2861                                  q[">],
2862                                  length $self->{current_token}->{system_identifier});
2863    
2864          ## Stay in the state          ## Stay in the state
2865          !!!next-input-character;          !!!next-input-character;
2866          redo A;          redo A;
# Line 2740  sub _get_next_token ($) { Line 2897  sub _get_next_token ($) {
2897          !!!cp (214);          !!!cp (214);
2898          $self->{current_token}->{system_identifier} # DOCTYPE          $self->{current_token}->{system_identifier} # DOCTYPE
2899              .= chr $self->{next_char};              .= chr $self->{next_char};
2900            $self->{read_until}->($self->{current_token}->{system_identifier},
2901                                  q['>],
2902                                  length $self->{current_token}->{system_identifier});
2903    
2904          ## Stay in the state          ## Stay in the state
2905          !!!next-input-character;          !!!next-input-character;
2906          redo A;          redo A;
# Line 2800  sub _get_next_token ($) { Line 2961  sub _get_next_token ($) {
2961          redo A;          redo A;
2962        } else {        } else {
2963          !!!cp (221);          !!!cp (221);
2964            my $s = '';
2965            $self->{read_until}->($s, q[>], 0);
2966    
2967          ## Stay in the state          ## Stay in the state
2968          !!!next-input-character;          !!!next-input-character;
2969          redo A;          redo A;
2970        }        }
2971      } elsif ($self->{state} == CDATA_BLOCK_STATE) {      } elsif ($self->{state} == CDATA_SECTION_STATE) {
2972        my $s = '';        ## NOTE: "CDATA section state" in the state is jointly implemented
2973          ## by three states, |CDATA_SECTION_STATE|, |CDATA_SECTION_MSE1_STATE|,
2974          ## and |CDATA_SECTION_MSE2_STATE|.
2975                
2976        my ($l, $c) = ($self->{line}, $self->{column});        if ($self->{next_char} == 0x005D) { # ]
2977            !!!cp (221.1);
2978        CS: while ($self->{next_char} != -1) {          $self->{state} = CDATA_SECTION_MSE1_STATE;
         if ($self->{next_char} == 0x005D) { # ]  
           !!!next-input-character;  
           if ($self->{next_char} == 0x005D) { # ]  
             !!!next-input-character;  
             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};  
2979          !!!next-input-character;          !!!next-input-character;
2980        } # CS          redo A;
2981          } elsif ($self->{next_char} == -1) {
2982            $self->{state} = DATA_STATE;
2983            !!!next-input-character;
2984            if (length $self->{current_token}->{data}) { # character
2985              !!!cp (221.2);
2986              !!!emit ($self->{current_token}); # character
2987            } else {
2988              !!!cp (221.3);
2989              ## No token to emit. $self->{current_token} is discarded.
2990            }        
2991            redo A;
2992          } else {
2993            !!!cp (221.4);
2994            $self->{current_token}->{data} .= chr $self->{next_char};
2995            $self->{read_until}->($self->{current_token}->{data},
2996                                  q<]>,
2997                                  length $self->{current_token}->{data});
2998    
2999        $self->{state} = DATA_STATE;          ## Stay in the state.
3000        ## next-input-character done or EOF, which is reconsumed.          !!!next-input-character;
3001            redo A;
3002          }
3003    
3004        if (length $s) {        ## ISSUE: "text tokens" in spec.
3005        } elsif ($self->{state} == CDATA_SECTION_MSE1_STATE) {
3006          if ($self->{next_char} == 0x005D) { # ]
3007            !!!cp (221.5);
3008            $self->{state} = CDATA_SECTION_MSE2_STATE;
3009            !!!next-input-character;
3010            redo A;
3011          } else {
3012          !!!cp (221.6);          !!!cp (221.6);
3013          !!!emit ({type => CHARACTER_TOKEN, data => $s,          $self->{current_token}->{data} .= ']';
3014                    line => $l, column => $c});          $self->{state} = CDATA_SECTION_STATE;
3015            ## Reconsume.
3016            redo A;
3017          }
3018        } elsif ($self->{state} == CDATA_SECTION_MSE2_STATE) {
3019          if ($self->{next_char} == 0x003E) { # >
3020            $self->{state} = DATA_STATE;
3021            !!!next-input-character;
3022            if (length $self->{current_token}->{data}) { # character
3023              !!!cp (221.7);
3024              !!!emit ($self->{current_token}); # character
3025            } else {
3026              !!!cp (221.8);
3027              ## No token to emit. $self->{current_token} is discarded.
3028            }
3029            redo A;
3030          } elsif ($self->{next_char} == 0x005D) { # ]
3031            !!!cp (221.9); # character
3032            $self->{current_token}->{data} .= ']'; ## Add first "]" of "]]]".
3033            ## Stay in the state.
3034            !!!next-input-character;
3035            redo A;
3036        } else {        } else {
3037          !!!cp (221.7);          !!!cp (221.11);
3038            $self->{current_token}->{data} .= ']]'; # character
3039            $self->{state} = CDATA_SECTION_STATE;
3040            ## Reconsume.
3041            redo A;
3042          }
3043        } elsif ($self->{state} == ENTITY_STATE) {
3044          if ({
3045            0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,
3046            0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, &
3047            $self->{entity_additional} => 1,
3048          }->{$self->{next_char}}) {
3049            !!!cp (1001);
3050            ## Don't consume
3051            ## No error
3052            ## Return nothing.
3053            #
3054          } elsif ($self->{next_char} == 0x0023) { # #
3055            !!!cp (999);
3056            $self->{state} = ENTITY_HASH_STATE;
3057            $self->{state_keyword} = '#';
3058            !!!next-input-character;
3059            redo A;
3060          } elsif ((0x0041 <= $self->{next_char} and
3061                    $self->{next_char} <= 0x005A) or # A..Z
3062                   (0x0061 <= $self->{next_char} and
3063                    $self->{next_char} <= 0x007A)) { # a..z
3064            !!!cp (998);
3065            require Whatpm::_NamedEntityList;
3066            $self->{state} = ENTITY_NAME_STATE;
3067            $self->{state_keyword} = chr $self->{next_char};
3068            $self->{entity__value} = $self->{state_keyword};
3069            $self->{entity__match} = 0;
3070            !!!next-input-character;
3071            redo A;
3072          } else {
3073            !!!cp (1027);
3074            !!!parse-error (type => 'bare ero');
3075            ## Return nothing.
3076            #
3077        }        }
3078    
3079        redo A;        ## NOTE: No character is consumed by the "consume a character
3080          ## reference" algorithm.  In other word, there is an "&" character
3081        ## ISSUE: "text tokens" in spec.        ## that does not introduce a character reference, which would be
3082        ## TODO: Streaming support        ## appended to the parent element or the attribute value in later
3083      } else {        ## process of the tokenizer.
3084        die "$0: $self->{state}: Unknown state";  
3085      }        if ($self->{prev_state} == DATA_STATE) {
3086    } # A            !!!cp (997);
3087            $self->{state} = $self->{prev_state};
3088    die "$0: _get_next_token: unexpected case";          ## Reconsume.
3089  } # _get_next_token          !!!emit ({type => CHARACTER_TOKEN, data => '&',
3090                      line => $self->{line_prev},
3091  sub _tokenize_attempt_to_consume_an_entity ($$$) {                    column => $self->{column_prev},
3092    my ($self, $in_attr, $additional) = @_;                   });
3093            redo A;
3094    my ($l, $c) = ($self->{line_prev}, $self->{column_prev});        } else {
3095            !!!cp (996);
3096            $self->{current_attribute}->{value} .= '&';
3097            $self->{state} = $self->{prev_state};
3098            ## Reconsume.
3099            redo A;
3100          }
3101        } elsif ($self->{state} == ENTITY_HASH_STATE) {
3102          if ($self->{next_char} == 0x0078 or # x
3103              $self->{next_char} == 0x0058) { # X
3104            !!!cp (995);
3105            $self->{state} = HEXREF_X_STATE;
3106            $self->{state_keyword} .= chr $self->{next_char};
3107            !!!next-input-character;
3108            redo A;
3109          } elsif (0x0030 <= $self->{next_char} and
3110                   $self->{next_char} <= 0x0039) { # 0..9
3111            !!!cp (994);
3112            $self->{state} = NCR_NUM_STATE;
3113            $self->{state_keyword} = $self->{next_char} - 0x0030;
3114            !!!next-input-character;
3115            redo A;
3116          } else {
3117            !!!parse-error (type => 'bare nero',
3118                            line => $self->{line_prev},
3119                            column => $self->{column_prev} - 1);
3120    
3121    if ({          ## NOTE: According to the spec algorithm, nothing is returned,
3122         0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,          ## and then "&#" is appended to the parent element or the attribute
3123         0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR          ## value in the later processing.
3124         $additional => 1,  
3125        }->{$self->{next_char}}) {          if ($self->{prev_state} == DATA_STATE) {
3126      !!!cp (1001);            !!!cp (1019);
3127      ## Don't consume            $self->{state} = $self->{prev_state};
3128      ## No error            ## Reconsume.
3129      return undef;            !!!emit ({type => CHARACTER_TOKEN,
3130    } elsif ($self->{next_char} == 0x0023) { # #                      data => '&#',
3131      !!!next-input-character;                      line => $self->{line_prev},
3132      if ($self->{next_char} == 0x0078 or # x                      column => $self->{column_prev} - 1,
3133          $self->{next_char} == 0x0058) { # X                     });
3134        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;  
3135          } else {          } else {
3136            !!!cp (1007);            !!!cp (993);
3137            !!!parse-error (type => 'no refc', line => $l, column => $c);            $self->{current_attribute}->{value} .= '&#';
3138              $self->{state} = $self->{prev_state};
3139              ## Reconsume.
3140              redo A;
3141          }          }
3142          }
3143          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {      } elsif ($self->{state} == NCR_NUM_STATE) {
3144            !!!cp (1008);        if (0x0030 <= $self->{next_char} and
3145            !!!parse-error (type => 'invalid character reference',            $self->{next_char} <= 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  
3146          !!!cp (1012);          !!!cp (1012);
3147          $code *= 10;          $self->{state_keyword} *= 10;
3148          $code += $self->{next_char} - 0x0030;          $self->{state_keyword} += $self->{next_char} - 0x0030;
3149                    
3150            ## Stay in the state.
3151          !!!next-input-character;          !!!next-input-character;
3152        }          redo A;
3153          } elsif ($self->{next_char} == 0x003B) { # ;
       if ($self->{next_char} == 0x003B) { # ;  
3154          !!!cp (1013);          !!!cp (1013);
3155          !!!next-input-character;          !!!next-input-character;
3156            #
3157        } else {        } else {
3158          !!!cp (1014);          !!!cp (1014);
3159          !!!parse-error (type => 'no refc', line => $l, column => $c);          !!!parse-error (type => 'no refc');
3160            ## Reconsume.
3161            #
3162        }        }
3163    
3164          my $code = $self->{state_keyword};
3165          my $l = $self->{line_prev};
3166          my $c = $self->{column_prev};
3167        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3168          !!!cp (1015);          !!!cp (1015);
3169          !!!parse-error (type => 'invalid character reference',          !!!parse-error (type => 'invalid character reference',
# Line 2996  sub _tokenize_attempt_to_consume_an_enti Line 3188  sub _tokenize_attempt_to_consume_an_enti
3188                          line => $l, column => $c);                          line => $l, column => $c);
3189          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
3190        }        }
3191          
3192        return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1,        if ($self->{prev_state} == DATA_STATE) {
3193                line => $l, column => $c,          !!!cp (992);
3194               };          $self->{state} = $self->{prev_state};
3195      } else {          ## Reconsume.
3196        !!!cp (1019);          !!!emit ({type => CHARACTER_TOKEN, data => chr $code,
3197        !!!parse-error (type => 'bare nero', line => $l, column => $c);                    line => $l, column => $c,
3198        !!!back-next-input-character ($self->{next_char});                   });
3199        $self->{next_char} = 0x0023; # #          redo A;
3200        return undef;        } else {
3201      }          !!!cp (991);
3202    } elsif ((0x0041 <= $self->{next_char} and          $self->{current_attribute}->{value} .= chr $code;
3203              $self->{next_char} <= 0x005A) or          $self->{current_attribute}->{has_reference} = 1;
3204             (0x0061 <= $self->{next_char} and          $self->{state} = $self->{prev_state};
3205              $self->{next_char} <= 0x007A)) {          ## Reconsume.
3206      my $entity_name = chr $self->{next_char};          redo A;
3207      !!!next-input-character;        }
3208        } elsif ($self->{state} == HEXREF_X_STATE) {
3209      my $value = $entity_name;        if ((0x0030 <= $self->{next_char} and $self->{next_char} <= 0x0039) or
3210      my $match = 0;            (0x0041 <= $self->{next_char} and $self->{next_char} <= 0x0046) or
3211      require Whatpm::_NamedEntityList;            (0x0061 <= $self->{next_char} and $self->{next_char} <= 0x0066)) {
3212      our $EntityChar;          # 0..9, A..F, a..f
3213            !!!cp (990);
3214      while (length $entity_name < 30 and          $self->{state} = HEXREF_HEX_STATE;
3215             ## NOTE: Some number greater than the maximum length of entity name          $self->{state_keyword} = 0;
3216             ((0x0041 <= $self->{next_char} and # a          ## Reconsume.
3217               $self->{next_char} <= 0x005A) or # x          redo A;
3218              (0x0061 <= $self->{next_char} and # a        } else {
3219               $self->{next_char} <= 0x007A) or # z          !!!parse-error (type => 'bare hcro',
3220              (0x0030 <= $self->{next_char} and # 0                          line => $self->{line_prev},
3221               $self->{next_char} <= 0x0039) or # 9                          column => $self->{column_prev} - 2);
3222              $self->{next_char} == 0x003B)) { # ;  
3223        $entity_name .= chr $self->{next_char};          ## NOTE: According to the spec algorithm, nothing is returned,
3224        if (defined $EntityChar->{$entity_name}) {          ## and then "&#" followed by "X" or "x" is appended to the parent
3225          if ($self->{next_char} == 0x003B) { # ;          ## element or the attribute value in the later processing.
3226            !!!cp (1020);  
3227            $value = $EntityChar->{$entity_name};          if ($self->{prev_state} == DATA_STATE) {
3228            $match = 1;            !!!cp (1005);
3229            !!!next-input-character;            $self->{state} = $self->{prev_state};
3230            last;            ## Reconsume.
3231              !!!emit ({type => CHARACTER_TOKEN,
3232                        data => '&' . $self->{state_keyword},
3233                        line => $self->{line_prev},
3234                        column => $self->{column_prev} - length $self->{state_keyword},
3235                       });
3236              redo A;
3237            } else {
3238              !!!cp (989);
3239              $self->{current_attribute}->{value} .= '&' . $self->{state_keyword};
3240              $self->{state} = $self->{prev_state};
3241              ## Reconsume.
3242              redo A;
3243            }
3244          }
3245        } elsif ($self->{state} == HEXREF_HEX_STATE) {
3246          if (0x0030 <= $self->{next_char} and $self->{next_char} <= 0x0039) {
3247            # 0..9
3248            !!!cp (1002);
3249            $self->{state_keyword} *= 0x10;
3250            $self->{state_keyword} += $self->{next_char} - 0x0030;
3251            ## Stay in the state.
3252            !!!next-input-character;
3253            redo A;
3254          } elsif (0x0061 <= $self->{next_char} and
3255                   $self->{next_char} <= 0x0066) { # a..f
3256            !!!cp (1003);
3257            $self->{state_keyword} *= 0x10;
3258            $self->{state_keyword} += $self->{next_char} - 0x0060 + 9;
3259            ## Stay in the state.
3260            !!!next-input-character;
3261            redo A;
3262          } elsif (0x0041 <= $self->{next_char} and
3263                   $self->{next_char} <= 0x0046) { # A..F
3264            !!!cp (1004);
3265            $self->{state_keyword} *= 0x10;
3266            $self->{state_keyword} += $self->{next_char} - 0x0040 + 9;
3267            ## Stay in the state.
3268            !!!next-input-character;
3269            redo A;
3270          } elsif ($self->{next_char} == 0x003B) { # ;
3271            !!!cp (1006);
3272            !!!next-input-character;
3273            #
3274          } else {
3275            !!!cp (1007);
3276            !!!parse-error (type => 'no refc',
3277                            line => $self->{line},
3278                            column => $self->{column});
3279            ## Reconsume.
3280            #
3281          }
3282    
3283          my $code = $self->{state_keyword};
3284          my $l = $self->{line_prev};
3285          my $c = $self->{column_prev};
3286          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3287            !!!cp (1008);
3288            !!!parse-error (type => 'invalid character reference',
3289                            text => (sprintf 'U+%04X', $code),
3290                            line => $l, column => $c);
3291            $code = 0xFFFD;
3292          } elsif ($code > 0x10FFFF) {
3293            !!!cp (1009);
3294            !!!parse-error (type => 'invalid character reference',
3295                            text => (sprintf 'U-%08X', $code),
3296                            line => $l, column => $c);
3297            $code = 0xFFFD;
3298          } elsif ($code == 0x000D) {
3299            !!!cp (1010);
3300            !!!parse-error (type => 'CR character reference', line => $l, column => $c);
3301            $code = 0x000A;
3302          } elsif (0x80 <= $code and $code <= 0x9F) {
3303            !!!cp (1011);
3304            !!!parse-error (type => 'C1 character reference', text => (sprintf 'U+%04X', $code), line => $l, column => $c);
3305            $code = $c1_entity_char->{$code};
3306          }
3307    
3308          if ($self->{prev_state} == DATA_STATE) {
3309            !!!cp (988);
3310            $self->{state} = $self->{prev_state};
3311            ## Reconsume.
3312            !!!emit ({type => CHARACTER_TOKEN, data => chr $code,
3313                      line => $l, column => $c,
3314                     });
3315            redo A;
3316          } else {
3317            !!!cp (987);
3318            $self->{current_attribute}->{value} .= chr $code;
3319            $self->{current_attribute}->{has_reference} = 1;
3320            $self->{state} = $self->{prev_state};
3321            ## Reconsume.
3322            redo A;
3323          }
3324        } elsif ($self->{state} == ENTITY_NAME_STATE) {
3325          if (length $self->{state_keyword} < 30 and
3326              ## NOTE: Some number greater than the maximum length of entity name
3327              ((0x0041 <= $self->{next_char} and # a
3328                $self->{next_char} <= 0x005A) or # x
3329               (0x0061 <= $self->{next_char} and # a
3330                $self->{next_char} <= 0x007A) or # z
3331               (0x0030 <= $self->{next_char} and # 0
3332                $self->{next_char} <= 0x0039) or # 9
3333               $self->{next_char} == 0x003B)) { # ;
3334            our $EntityChar;
3335            $self->{state_keyword} .= chr $self->{next_char};
3336            if (defined $EntityChar->{$self->{state_keyword}}) {
3337              if ($self->{next_char} == 0x003B) { # ;
3338                !!!cp (1020);
3339                $self->{entity__value} = $EntityChar->{$self->{state_keyword}};
3340                $self->{entity__match} = 1;
3341                !!!next-input-character;
3342                #
3343              } else {
3344                !!!cp (1021);
3345                $self->{entity__value} = $EntityChar->{$self->{state_keyword}};
3346                $self->{entity__match} = -1;
3347                ## Stay in the state.
3348                !!!next-input-character;
3349                redo A;
3350              }
3351          } else {          } else {
3352            !!!cp (1021);            !!!cp (1022);
3353            $value = $EntityChar->{$entity_name};            $self->{entity__value} .= chr $self->{next_char};
3354            $match = -1;            $self->{entity__match} *= 2;
3355              ## Stay in the state.
3356            !!!next-input-character;            !!!next-input-character;
3357              redo A;
3358            }
3359          }
3360    
3361          my $data;
3362          my $has_ref;
3363          if ($self->{entity__match} > 0) {
3364            !!!cp (1023);
3365            $data = $self->{entity__value};
3366            $has_ref = 1;
3367            #
3368          } elsif ($self->{entity__match} < 0) {
3369            !!!parse-error (type => 'no refc');
3370            if ($self->{prev_state} != DATA_STATE and # in attribute
3371                $self->{entity__match} < -1) {
3372              !!!cp (1024);
3373              $data = '&' . $self->{state_keyword};
3374              #
3375            } else {
3376              !!!cp (1025);
3377              $data = $self->{entity__value};
3378              $has_ref = 1;
3379              #
3380          }          }
3381        } else {        } else {
3382          !!!cp (1022);          !!!cp (1026);
3383          $value .= chr $self->{next_char};          !!!parse-error (type => 'bare ero',
3384          $match *= 2;                          line => $self->{line_prev},
3385          !!!next-input-character;                          column => $self->{column_prev} - length $self->{state_keyword});
3386            $data = '&' . $self->{state_keyword};
3387            #
3388        }        }
3389      }    
3390              ## NOTE: In these cases, when a character reference is found,
3391      if ($match > 0) {        ## it is consumed and a character token is returned, or, otherwise,
3392        !!!cp (1023);        ## nothing is consumed and returned, according to the spec algorithm.
3393        return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,        ## In this implementation, anything that has been examined by the
3394                line => $l, column => $c,        ## tokenizer is appended to the parent element or the attribute value
3395               };        ## as string, either literal string when no character reference or
3396      } elsif ($match < 0) {        ## entity-replaced string otherwise, in this stage, since any characters
3397        !!!parse-error (type => 'no refc', line => $l, column => $c);        ## that would not be consumed are appended in the data state or in an
3398        if ($in_attr and $match < -1) {        ## appropriate attribute value state anyway.
3399          !!!cp (1024);  
3400          return {type => CHARACTER_TOKEN, data => '&'.$entity_name,        if ($self->{prev_state} == DATA_STATE) {
3401                  line => $l, column => $c,          !!!cp (986);
3402                 };          $self->{state} = $self->{prev_state};
3403        } else {          ## Reconsume.
3404          !!!cp (1025);          !!!emit ({type => CHARACTER_TOKEN,
3405          return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,                    data => $data,
3406                  line => $l, column => $c,                    line => $self->{line_prev},
3407                 };                    column => $self->{column_prev} + 1 - length $self->{state_keyword},
3408                     });
3409            redo A;
3410          } else {
3411            !!!cp (985);
3412            $self->{current_attribute}->{value} .= $data;
3413            $self->{current_attribute}->{has_reference} = 1 if $has_ref;
3414            $self->{state} = $self->{prev_state};
3415            ## Reconsume.
3416            redo A;
3417        }        }
3418      } else {      } else {
3419        !!!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,  
              };  
3420      }      }
3421    } else {    } # A  
3422      !!!cp (1027);  
3423      ## no characters are consumed    die "$0: _get_next_token: unexpected case";
3424      !!!parse-error (type => 'bare ero', line => $l, column => $c);  } # _get_next_token
     return undef;  
   }  
 } # _tokenize_attempt_to_consume_an_entity  
3425    
3426  sub _initialize_tree_constructor ($) {  sub _initialize_tree_constructor ($) {
3427    my $self = shift;    my $self = shift;
# Line 3091  sub _initialize_tree_constructor ($) { Line 3430  sub _initialize_tree_constructor ($) {
3430    ## TODO: Turn mutation events off # MUST    ## TODO: Turn mutation events off # MUST
3431    ## TODO: Turn loose Document option (manakai extension) on    ## TODO: Turn loose Document option (manakai extension) on
3432    $self->{document}->manakai_is_html (1); # MUST    $self->{document}->manakai_is_html (1); # MUST
3433      $self->{document}->set_user_data (manakai_source_line => 1);
3434      $self->{document}->set_user_data (manakai_source_column => 1);
3435  } # _initialize_tree_constructor  } # _initialize_tree_constructor
3436    
3437  sub _terminate_tree_constructor ($) {  sub _terminate_tree_constructor ($) {
# Line 3145  sub _tree_construction_initial ($) { Line 3486  sub _tree_construction_initial ($) {
3486        ## language.        ## language.
3487        my $doctype_name = $token->{name};        my $doctype_name = $token->{name};
3488        $doctype_name = '' unless defined $doctype_name;        $doctype_name = '' unless defined $doctype_name;
3489        $doctype_name =~ tr/a-z/A-Z/;        $doctype_name =~ tr/a-z/A-Z/; # ASCII case-insensitive
3490        if (not defined $token->{name} or # <!DOCTYPE>        if (not defined $token->{name} or # <!DOCTYPE>
           defined $token->{public_identifier} or  
3491            defined $token->{system_identifier}) {            defined $token->{system_identifier}) {
3492          !!!cp ('t1');          !!!cp ('t1');
3493          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3494        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
3495          !!!cp ('t2');          !!!cp ('t2');
         ## ISSUE: ASCII case-insensitive? (in fact it does not matter)  
3496          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3497          } elsif (defined $token->{public_identifier}) {
3498            if ($token->{public_identifier} eq 'XSLT-compat') {
3499              !!!cp ('t1.2');
3500              !!!parse-error (type => 'XSLT-compat', token => $token,
3501                              level => $self->{level}->{should});
3502            } else {
3503              !!!parse-error (type => 'not HTML5', token => $token);
3504            }
3505        } else {        } else {
3506          !!!cp ('t3');          !!!cp ('t3');
3507            #
3508        }        }
3509                
3510        my $doctype = $self->{document}->create_document_type_definition        my $doctype = $self->{document}->create_document_type_definition
# Line 4172  sub _tree_construction_main ($) { Line 4520  sub _tree_construction_main ($) {
4520            unless ($self->{insertion_mode} == BEFORE_HEAD_IM) {            unless ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4521              !!!cp ('t88.2');              !!!cp ('t88.2');
4522              $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);              $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4523                #
4524            } else {            } else {
4525              !!!cp ('t88.1');              !!!cp ('t88.1');
4526              ## Ignore the token.              ## Ignore the token.
4527              !!!next-token;              #
             next B;  
4528            }            }
4529            unless (length $token->{data}) {            unless (length $token->{data}) {
4530              !!!cp ('t88');              !!!cp ('t88');
4531              !!!next-token;              !!!next-token;
4532              next B;              next B;
4533            }            }
4534    ## TODO: set $token->{column} appropriately
4535          }          }
4536    
4537          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
# Line 6292  sub _tree_construction_main ($) { Line 6641  sub _tree_construction_main ($) {
6641            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6642              !!!cp ('t312');              !!!cp ('t312');
6643              !!!parse-error (type => 'after frameset:#text', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6644            } else { # "after html frameset"            } else { # "after after frameset"
6645              !!!cp ('t313');              !!!cp ('t313');
6646              !!!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);  
6647            }            }
6648                        
6649            ## Ignore the token.            ## Ignore the token.
# Line 6314  sub _tree_construction_main ($) { Line 6659  sub _tree_construction_main ($) {
6659                    
6660          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
6661        } 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');  
         }  
   
6662          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6663              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6664            !!!cp ('t318');            !!!cp ('t318');
# Line 6345  sub _tree_construction_main ($) { Line 6679  sub _tree_construction_main ($) {
6679            ## NOTE: As if in head.            ## NOTE: As if in head.
6680            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
6681            next B;            next B;
6682    
6683              ## NOTE: |<!DOCTYPE HTML><frameset></frameset></html><noframes></noframes>|
6684              ## has no parse error.
6685          } else {          } else {
6686            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6687              !!!cp ('t321');              !!!cp ('t321');
6688              !!!parse-error (type => 'in frameset',              !!!parse-error (type => 'in frameset',
6689                              text => $token->{tag_name}, token => $token);                              text => $token->{tag_name}, token => $token);
6690            } else {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6691              !!!cp ('t322');              !!!cp ('t322');
6692              !!!parse-error (type => 'after frameset',              !!!parse-error (type => 'after frameset',
6693                              text => $token->{tag_name}, token => $token);                              text => $token->{tag_name}, token => $token);
6694              } else { # "after after frameset"
6695                !!!cp ('t322.2');
6696                !!!parse-error (type => 'after after frameset',
6697                                text => $token->{tag_name}, token => $token);
6698            }            }
6699            ## Ignore the token            ## Ignore the token
6700            !!!nack ('t322.1');            !!!nack ('t322.1');
# Line 6361  sub _tree_construction_main ($) { Line 6702  sub _tree_construction_main ($) {
6702            next B;            next B;
6703          }          }
6704        } 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');  
         }  
   
6705          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6706              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6707            if ($self->{open_elements}->[-1]->[1] & HTML_EL and            if ($self->{open_elements}->[-1]->[1] & HTML_EL and
# Line 6406  sub _tree_construction_main ($) { Line 6736  sub _tree_construction_main ($) {
6736              !!!cp ('t330');              !!!cp ('t330');
6737              !!!parse-error (type => 'in frameset:/',              !!!parse-error (type => 'in frameset:/',
6738                              text => $token->{tag_name}, token => $token);                              text => $token->{tag_name}, token => $token);
6739            } else {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6740              !!!cp ('t331');              !!!cp ('t330.1');
6741              !!!parse-error (type => 'after frameset:/',              !!!parse-error (type => 'after frameset:/',
6742                              text => $token->{tag_name}, token => $token);                              text => $token->{tag_name}, token => $token);
6743              } else { # "after after html"
6744                !!!cp ('t331');
6745                !!!parse-error (type => 'after after frameset:/',
6746                                text => $token->{tag_name}, token => $token);
6747            }            }
6748            ## Ignore the token            ## Ignore the token
6749            !!!next-token;            !!!next-token;
# Line 6946  sub _tree_construction_main ($) { Line 7280  sub _tree_construction_main ($) {
7280                 $token->{tag_name} eq 'svg') {                 $token->{tag_name} eq 'svg') {
7281          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
7282    
7283            ## "Adjust MathML attributes" ('math' only) - done in insert-element-f
7284    
7285          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f
7286    
7287          ## "adjust foreign attributes" - done in insert-element-f          ## "adjust foreign attributes" - done in insert-element-f
# Line 7130  sub _tree_construction_main ($) { Line 7466  sub _tree_construction_main ($) {
7466            !!!cp ('t413');            !!!cp ('t413');
7467            !!!parse-error (type => 'unmatched end tag',            !!!parse-error (type => 'unmatched end tag',
7468                            text => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7469              ## NOTE: Ignore the token.
7470          } else {          } else {
7471            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7472            while ({            while ({
# Line 7189  sub _tree_construction_main ($) { Line 7526  sub _tree_construction_main ($) {
7526            !!!cp ('t421');            !!!cp ('t421');
7527            !!!parse-error (type => 'unmatched end tag',            !!!parse-error (type => 'unmatched end tag',
7528                            text => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7529              ## NOTE: Ignore the token.
7530          } else {          } else {
7531            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7532            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7235  sub _tree_construction_main ($) { Line 7573  sub _tree_construction_main ($) {
7573            !!!cp ('t425.1');            !!!cp ('t425.1');
7574            !!!parse-error (type => 'unmatched end tag',            !!!parse-error (type => 'unmatched end tag',
7575                            text => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7576              ## NOTE: Ignore the token.
7577          } else {          } else {
7578            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7579            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7437  sub _tree_construction_main ($) { Line 7776  sub _tree_construction_main ($) {
7776    ## TODO: script stuffs    ## TODO: script stuffs
7777  } # _tree_construct_main  } # _tree_construct_main
7778    
7779  sub set_inner_html ($$$) {  sub set_inner_html ($$$$;$) {
7780    my $class = shift;    my $class = shift;
7781    my $node = shift;    my $node = shift;
7782    my $s = \$_[0];    #my $s = \$_[0];
7783    my $onerror = $_[1];    my $onerror = $_[1];
7784      my $get_wrapper = $_[2] || sub ($) { return $_[0] };
7785    
7786    ## ISSUE: Should {confident} be true?    ## ISSUE: Should {confident} be true?
7787    
# Line 7460  sub set_inner_html ($$$) { Line 7800  sub set_inner_html ($$$) {
7800      }      }
7801    
7802      ## Step 3, 4, 5 # MUST      ## Step 3, 4, 5 # MUST
7803      $class->parse_string ($$s => $node, $onerror);      $class->parse_char_string ($_[0] => $node, $onerror, $get_wrapper);
7804    } elsif ($nt == 1) {    } elsif ($nt == 1) {
7805      ## TODO: If non-html element      ## TODO: If non-html element
7806    
7807      ## NOTE: Most of this code is copied from |parse_string|      ## NOTE: Most of this code is copied from |parse_string|
7808    
7809    ## TODO: Support for $get_wrapper
7810    
7811      ## Step 1 # MUST      ## Step 1 # MUST
7812      my $this_doc = $node->owner_document;      my $this_doc = $node->owner_document;
7813      my $doc = $this_doc->implementation->create_document;      my $doc = $this_doc->implementation->create_document;
# Line 7477  sub set_inner_html ($$$) { Line 7819  sub set_inner_html ($$$) {
7819      my $i = 0;      my $i = 0;
7820      $p->{line_prev} = $p->{line} = 1;      $p->{line_prev} = $p->{line} = 1;
7821      $p->{column_prev} = $p->{column} = 0;      $p->{column_prev} = $p->{column} = 0;
7822        require Whatpm::Charset::DecodeHandle;
7823        my $input = Whatpm::Charset::DecodeHandle::CharString->new (\($_[0]));
7824        $input = $get_wrapper->($input);
7825      $p->{set_next_char} = sub {      $p->{set_next_char} = sub {
7826        my $self = shift;        my $self = shift;
7827    
7828        pop @{$self->{prev_char}};        my $char = '';
7829        unshift @{$self->{prev_char}}, $self->{next_char};        if (defined $self->{next_next_char}) {
7830            $char = $self->{next_next_char};
7831        $self->{next_char} = -1 and return if $i >= length $$s;          delete $self->{next_next_char};
7832        $self->{next_char} = ord substr $$s, $i++, 1;          $self->{next_char} = ord $char;
7833          } else {
7834            $self->{char_buffer} = '';
7835            $self->{char_buffer_pos} = 0;
7836            
7837            my $count = $input->manakai_read_until
7838                ($self->{char_buffer},
7839                 qr/(?![\x{FDD0}-\x{FDDF}\x{FFFE}\x{FFFF}\x{1FFFE}\x{1FFFF}\x{2FFFE}\x{2FFFF}\x{3FFFE}\x{3FFFF}\x{4FFFE}\x{4FFFF}\x{5FFFE}\x{5FFFF}\x{6FFFE}\x{6FFFF}\x{7FFFE}\x{7FFFF}\x{8FFFE}\x{8FFFF}\x{9FFFE}\x{9FFFF}\x{AFFFE}\x{AFFFF}\x{BFFFE}\x{BFFFF}\x{CFFFE}\x{CFFFF}\x{DFFFE}\x{DFFFF}\x{EFFFE}\x{EFFFF}\x{FFFFE}\x{FFFFF}])[\x20-\x7E\xA0-\x{D7FF}\x{E000}-\x{10FFFD}]/,
7840                   $self->{char_buffer_pos});
7841            if ($count) {
7842              $self->{line_prev} = $self->{line};
7843              $self->{column_prev} = $self->{column};
7844              $self->{column}++;
7845              $self->{next_char}
7846                  = ord substr ($self->{char_buffer},
7847                                $self->{char_buffer_pos}++, 1);
7848              return;
7849            }
7850            
7851            if ($input->read ($char, 1)) {
7852              $self->{next_char} = ord $char;
7853            } else {
7854              $self->{next_char} = -1;
7855              return;
7856            }
7857          }
7858    
7859        ($p->{line_prev}, $p->{column_prev}) = ($p->{line}, $p->{column});        ($p->{line_prev}, $p->{column_prev}) = ($p->{line}, $p->{column});
7860        $p->{column}++;        $p->{column}++;
# Line 7494  sub set_inner_html ($$$) { Line 7864  sub set_inner_html ($$$) {
7864          $p->{column} = 0;          $p->{column} = 0;
7865          !!!cp ('i1');          !!!cp ('i1');
7866        } elsif ($self->{next_char} == 0x000D) { # CR        } elsif ($self->{next_char} == 0x000D) { # CR
7867          $i++ if substr ($$s, $i, 1) eq "\x0A";  ## TODO: support for abort/streaming
7868            my $next = '';
7869            if ($input->read ($next, 1) and $next ne "\x0A") {
7870              $self->{next_next_char} = $next;
7871            }
7872          $self->{next_char} = 0x000A; # LF # MUST          $self->{next_char} = 0x000A; # LF # MUST
7873          $p->{line}++;          $p->{line}++;
7874          $p->{column} = 0;          $p->{column} = 0;
# Line 7506  sub set_inner_html ($$$) { Line 7880  sub set_inner_html ($$$) {
7880          !!!cp ('i4');          !!!cp ('i4');
7881          !!!parse-error (type => 'NULL');          !!!parse-error (type => 'NULL');
7882          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
7883        } elsif ($self->{next_char} <= 0x0008 or        } elsif ($disallowed_control_chars->{$self->{next_char}}) {
                (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}}) {  
7884          !!!cp ('i4.1');          !!!cp ('i4.1');
7885          if ($self->{next_char} < 0x10000) {          if ($self->{next_char} < 0x10000) {
7886            !!!parse-error (type => 'control char',            !!!parse-error (type => 'control char',
# Line 7536  sub set_inner_html ($$$) { Line 7891  sub set_inner_html ($$$) {
7891          }          }
7892        }        }
7893      };      };
7894      $p->{prev_char} = [-1, -1, -1];  
7895      $p->{next_char} = -1;      $p->{read_until} = sub {
7896              #my ($scalar, $specials_range, $offset) = @_;
7897          return 0 if defined $p->{next_next_char};
7898    
7899          my $pattern = qr/(?![$_[1]\x{FDD0}-\x{FDDF}\x{FFFE}\x{FFFF}\x{1FFFE}\x{1FFFF}\x{2FFFE}\x{2FFFF}\x{3FFFE}\x{3FFFF}\x{4FFFE}\x{4FFFF}\x{5FFFE}\x{5FFFF}\x{6FFFE}\x{6FFFF}\x{7FFFE}\x{7FFFF}\x{8FFFE}\x{8FFFF}\x{9FFFE}\x{9FFFF}\x{AFFFE}\x{AFFFF}\x{BFFFE}\x{BFFFF}\x{CFFFE}\x{CFFFF}\x{DFFFE}\x{DFFFF}\x{EFFFE}\x{EFFFF}\x{FFFFE}\x{FFFFF}])[\x20-\x7E\xA0-\x{D7FF}\x{E000}-\x{10FFFD}]/;
7900          my $offset = $_[2] || 0;
7901          
7902          if ($p->{char_buffer_pos} < length $p->{char_buffer}) {
7903            pos ($p->{char_buffer}) = $p->{char_buffer_pos};
7904            if ($p->{char_buffer} =~ /\G(?>$pattern)+/) {
7905              substr ($_[0], $offset)
7906                  = substr ($p->{char_buffer}, $-[0], $+[0] - $-[0]);
7907              my $count = $+[0] - $-[0];
7908              if ($count) {
7909                $p->{column} += $count;
7910                $p->{char_buffer_pos} += $count;
7911                $p->{line_prev} = $p->{line};
7912                $p->{column_prev} = $p->{column} - 1;
7913                $p->{prev_char} = [-1, -1, -1];
7914                $p->{next_char} = -1;
7915              }
7916              return $count;
7917            } else {
7918              return 0;
7919            }
7920          } else {
7921            my $count = $input->manakai_read_until ($_[0], $pattern, $_[2]);
7922            if ($count) {
7923              $p->{column} += $count;
7924              $p->{column_prev} += $count;
7925              $p->{prev_char} = [-1, -1, -1];
7926              $p->{next_char} = -1;
7927            }
7928            return $count;
7929          }
7930        }; # $p->{read_until}
7931    
7932      my $ponerror = $onerror || sub {      my $ponerror = $onerror || sub {
7933        my (%opt) = @_;        my (%opt) = @_;
7934        my $line = $opt{line};        my $line = $opt{line};
# Line 7553  sub set_inner_html ($$$) { Line 7943  sub set_inner_html ($$$) {
7943        $ponerror->(line => $p->{line}, column => $p->{column}, @_);        $ponerror->(line => $p->{line}, column => $p->{column}, @_);
7944      };      };
7945            
7946        my $char_onerror = sub {
7947          my (undef, $type, %opt) = @_;
7948          $ponerror->(layer => 'encode',
7949                      line => $p->{line}, column => $p->{column} + 1,
7950                      %opt, type => $type);
7951        }; # $char_onerror
7952        $input->onerror ($char_onerror);
7953    
7954      $p->_initialize_tokenizer;      $p->_initialize_tokenizer;
7955      $p->_initialize_tree_constructor;      $p->_initialize_tree_constructor;
7956    

Legend:
Removed from v.1.153  
changed lines
  Added in v.1.181

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24