/[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.156 by wakaba, Sat Aug 30 13:43:50 2008 UTC revision 1.174 by wakaba, Sun Sep 14 06:32:49 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  sub parse_char_stream ($$$;$) {  sub parse_char_stream ($$$;$) {
632    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
# Line 641  sub parse_char_stream ($$$;$) { Line 669  sub parse_char_stream ($$$;$) {
669        $self->{column} = 0;        $self->{column} = 0;
670      } elsif ($self->{next_char} == 0x000D) { # CR      } elsif ($self->{next_char} == 0x000D) { # CR
671        !!!cp ('j2');        !!!cp ('j2');
672    ## TODO: support for abort/streaming
673        my $next = $input->getc;        my $next = $input->getc;
674        if (defined $next and $next ne "\x0A") {        if (defined $next and $next ne "\x0A") {
675          $self->{next_next_char} = $next;          $self->{next_next_char} = $next;
# Line 660  sub parse_char_stream ($$$;$) { Line 689  sub parse_char_stream ($$$;$) {
689               (0x007F <= $self->{next_char} and $self->{next_char} <= 0x009F) or               (0x007F <= $self->{next_char} and $self->{next_char} <= 0x009F) or
690               (0xD800 <= $self->{next_char} and $self->{next_char} <= 0xDFFF) or               (0xD800 <= $self->{next_char} and $self->{next_char} <= 0xDFFF) or
691               (0xFDD0 <= $self->{next_char} and $self->{next_char} <= 0xFDDF) or               (0xFDD0 <= $self->{next_char} and $self->{next_char} <= 0xFDDF) or
692    ## ISSUE: U+FDE0-U+FDEF are not excluded
693               {               {
694                0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,                0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,
695                0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,                0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,
# Line 684  sub parse_char_stream ($$$;$) { Line 714  sub parse_char_stream ($$$;$) {
714    $self->{prev_char} = [-1, -1, -1];    $self->{prev_char} = [-1, -1, -1];
715    $self->{next_char} = -1;    $self->{next_char} = -1;
716    
717      $self->{read_until} = sub {
718        #my ($scalar, $specials_range, $offset) = @_;
719        my $specials_range = $_[1];
720        return 0 if defined $self->{next_next_char};
721        my $count = $input->manakai_read_until
722           ($_[0],
723            qr/(?![$specials_range\x{FDD0}-\x{FDDF}\x{FFFD}-\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}]/,
724            $_[2]);
725            ## NOTE: We need to exclude U+FFFD, otherwise reported line/column
726            ## of unassigned/illegal code point error would be wrong.
727        if ($count) {
728          $self->{column} += $count;
729          $self->{column_prev} += $count;
730          $self->{prev_char} = [-1, -1, -1];
731          $self->{next_char} = -1;
732        }
733        return $count;
734      }; # $self->{read_until}
735    
736    my $onerror = $_[2] || sub {    my $onerror = $_[2] || sub {
737      my (%opt) = @_;      my (%opt) = @_;
738      my $line = $opt{token} ? $opt{token}->{line} : $opt{line};      my $line = $opt{token} ? $opt{token}->{line} : $opt{line};
# Line 708  sub new ($) { Line 757  sub new ($) {
757    my $class = shift;    my $class = shift;
758    my $self = bless {    my $self = bless {
759      level => {must => 'm',      level => {must => 'm',
760                  should => 's',
761                warn => 'w',                warn => 'w',
762                info => 'i',                info => 'i',
763                uncertain => 'u'},                uncertain => 'u'},
# Line 740  sub RCDATA_CONTENT_MODEL () { CM_ENTITY Line 790  sub RCDATA_CONTENT_MODEL () { CM_ENTITY
790  sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }  sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }
791    
792  sub DATA_STATE () { 0 }  sub DATA_STATE () { 0 }
793  sub ENTITY_DATA_STATE () { 1 }  #sub ENTITY_DATA_STATE () { 1 }
794  sub TAG_OPEN_STATE () { 2 }  sub TAG_OPEN_STATE () { 2 }
795  sub CLOSE_TAG_OPEN_STATE () { 3 }  sub CLOSE_TAG_OPEN_STATE () { 3 }
796  sub TAG_NAME_STATE () { 4 }  sub TAG_NAME_STATE () { 4 }
# Line 751  sub BEFORE_ATTRIBUTE_VALUE_STATE () { 8 Line 801  sub BEFORE_ATTRIBUTE_VALUE_STATE () { 8
801  sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 }  sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 }
802  sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 }  sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 }
803  sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 }  sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 }
804  sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 }  #sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 }
805  sub MARKUP_DECLARATION_OPEN_STATE () { 13 }  sub MARKUP_DECLARATION_OPEN_STATE () { 13 }
806  sub COMMENT_START_STATE () { 14 }  sub COMMENT_START_STATE () { 14 }
807  sub COMMENT_START_DASH_STATE () { 15 }  sub COMMENT_START_DASH_STATE () { 15 }
# Line 774  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STAT Line 824  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STAT
824  sub BOGUS_DOCTYPE_STATE () { 32 }  sub BOGUS_DOCTYPE_STATE () { 32 }
825  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }
826  sub SELF_CLOSING_START_TAG_STATE () { 34 }  sub SELF_CLOSING_START_TAG_STATE () { 34 }
827  sub CDATA_BLOCK_STATE () { 35 }  sub CDATA_SECTION_STATE () { 35 }
828    sub MD_HYPHEN_STATE () { 36 } # "markup declaration open state" in the spec
829    sub MD_DOCTYPE_STATE () { 37 } # "markup declaration open state" in the spec
830    sub MD_CDATA_STATE () { 38 } # "markup declaration open state" in the spec
831    sub CDATA_PCDATA_CLOSE_TAG_STATE () { 39 } # "close tag open state" in the spec
832    sub CDATA_SECTION_MSE1_STATE () { 40 } # "CDATA section state" in the spec
833    sub CDATA_SECTION_MSE2_STATE () { 41 } # "CDATA section state" in the spec
834    sub PUBLIC_STATE () { 42 } # "after DOCTYPE name state" in the spec
835    sub SYSTEM_STATE () { 43 } # "after DOCTYPE name state" in the spec
836    ## NOTE: "Entity data state", "entity in attribute value state", and
837    ## "consume a character reference" algorithm are jointly implemented
838    ## using the following six states:
839    sub ENTITY_STATE () { 44 }
840    sub ENTITY_HASH_STATE () { 45 }
841    sub NCR_NUM_STATE () { 46 }
842    sub HEXREF_X_STATE () { 47 }
843    sub HEXREF_HEX_STATE () { 48 }
844    sub ENTITY_NAME_STATE () { 49 }
845    
846  sub DOCTYPE_TOKEN () { 1 }  sub DOCTYPE_TOKEN () { 1 }
847  sub COMMENT_TOKEN () { 2 }  sub COMMENT_TOKEN () { 2 }
# Line 827  sub IN_COLUMN_GROUP_IM () { 0b10 } Line 894  sub IN_COLUMN_GROUP_IM () { 0b10 }
894  sub _initialize_tokenizer ($) {  sub _initialize_tokenizer ($) {
895    my $self = shift;    my $self = shift;
896    $self->{state} = DATA_STATE; # MUST    $self->{state} = DATA_STATE; # MUST
897      #$self->{state_keyword}; # initialized when used
898      #$self->{entity__value}; # initialized when used
899      #$self->{entity__match}; # initialized when used
900    $self->{content_model} = PCDATA_CONTENT_MODEL; # be    $self->{content_model} = PCDATA_CONTENT_MODEL; # be
901    undef $self->{current_token}; # start tag, end tag, comment, or DOCTYPE    undef $self->{current_token};
902    undef $self->{current_attribute};    undef $self->{current_attribute};
903    undef $self->{last_emitted_start_tag_name};    undef $self->{last_emitted_start_tag_name};
904    undef $self->{last_attribute_value_state};    #$self->{prev_state}; # initialized when used
905    delete $self->{self_closing};    delete $self->{self_closing};
   $self->{char} = [];  
906    # $self->{next_char}    # $self->{next_char}
907    !!!next-input-character;    !!!next-input-character;
908    $self->{token} = [];    $self->{token} = [];
# Line 865  sub _initialize_tokenizer ($) { Line 934  sub _initialize_tokenizer ($) {
934  ## has completed loading.  If one has, then it MUST be executed  ## has completed loading.  If one has, then it MUST be executed
935  ## and removed from the list.  ## and removed from the list.
936    
937  ## NOTE: HTML5 "Writing HTML documents" section, applied to  ## TODO: Polytheistic slash SHOULD NOT be used. (Applied only to atheists.)
938  ## 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,  
939    
940  sub _get_next_token ($) {  sub _get_next_token ($) {
941    my $self = shift;    my $self = shift;
# Line 902  sub _get_next_token ($) { Line 959  sub _get_next_token ($) {
959          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA
960              not $self->{escape}) {              not $self->{escape}) {
961            !!!cp (1);            !!!cp (1);
962            $self->{state} = ENTITY_DATA_STATE;            ## NOTE: In the spec, the tokenizer is switched to the
963              ## "entity data state".  In this implementation, the tokenizer
964              ## is switched to the |ENTITY_STATE|, which is an implementation
965              ## of the "consume a character reference" algorithm.
966              $self->{entity_additional} = -1;
967              $self->{prev_state} = DATA_STATE;
968              $self->{state} = ENTITY_STATE;
969            !!!next-input-character;            !!!next-input-character;
970            redo A;            redo A;
971          } else {          } else {
# Line 966  sub _get_next_token ($) { Line 1029  sub _get_next_token ($) {
1029                     data => chr $self->{next_char},                     data => chr $self->{next_char},
1030                     line => $self->{line}, column => $self->{column},                     line => $self->{line}, column => $self->{column},
1031                    };                    };
1032          $self->{read_until}->($token->{data}, q[-!<>&], length $token->{data});
1033    
1034        ## Stay in the data state        ## Stay in the data state
1035        !!!next-input-character;        !!!next-input-character;
1036    
1037        !!!emit ($token);        !!!emit ($token);
1038    
1039        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;  
1040      } elsif ($self->{state} == TAG_OPEN_STATE) {      } elsif ($self->{state} == TAG_OPEN_STATE) {
1041        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1042          if ($self->{next_char} == 0x002F) { # /          if ($self->{next_char} == 0x002F) { # /
# Line 1089  sub _get_next_token ($) { Line 1133  sub _get_next_token ($) {
1133          die "$0: $self->{content_model} in tag open";          die "$0: $self->{content_model} in tag open";
1134        }        }
1135      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {
1136          ## NOTE: The "close tag open state" in the spec is implemented as
1137          ## |CLOSE_TAG_OPEN_STATE| and |CDATA_PCDATA_CLOSE_TAG_STATE|.
1138    
1139        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"
1140        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1141          if (defined $self->{last_emitted_start_tag_name}) {          if (defined $self->{last_emitted_start_tag_name}) {
1142              $self->{state} = CDATA_PCDATA_CLOSE_TAG_STATE;
1143            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>            $self->{state_keyword} = '';
1144            my @next_char;            ## Reconsume.
1145            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...  
           }  
1146          } else {          } else {
1147            ## No start tag token has ever been emitted            ## No start tag token has ever been emitted
1148              ## NOTE: See <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>.
1149            !!!cp (28);            !!!cp (28);
           # next-input-character is already done  
1150            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1151              ## Reconsume.
1152            !!!emit ({type => CHARACTER_TOKEN, data => '</',            !!!emit ({type => CHARACTER_TOKEN, data => '</',
1153                      line => $l, column => $c,                      line => $l, column => $c,
1154                     });                     });
1155            redo A;            redo A;
1156          }          }
1157        }        }
1158          
1159        if (0x0041 <= $self->{next_char} and        if (0x0041 <= $self->{next_char} and
1160            $self->{next_char} <= 0x005A) { # A..Z            $self->{next_char} <= 0x005A) { # A..Z
1161          !!!cp (29);          !!!cp (29);
# Line 1198  sub _get_next_token ($) { Line 1202  sub _get_next_token ($) {
1202                                    line => $self->{line_prev}, # "<" of "</"                                    line => $self->{line_prev}, # "<" of "</"
1203                                    column => $self->{column_prev} - 1,                                    column => $self->{column_prev} - 1,
1204                                   };                                   };
1205          ## $self->{next_char} is intentionally left as is          ## NOTE: $self->{next_char} is intentionally left as is.
1206          redo A;          ## Although the "anything else" case of the spec not explicitly
1207            ## states that the next input character is to be reconsumed,
1208            ## it will be included to the |data| of the comment token
1209            ## generated from the bogus end tag, as defined in the
1210            ## "bogus comment state" entry.
1211            redo A;
1212          }
1213        } elsif ($self->{state} == CDATA_PCDATA_CLOSE_TAG_STATE) {
1214          my $ch = substr $self->{last_emitted_start_tag_name}, length $self->{state_keyword}, 1;
1215          if (length $ch) {
1216            my $CH = $ch;
1217            $ch =~ tr/a-z/A-Z/;
1218            my $nch = chr $self->{next_char};
1219            if ($nch eq $ch or $nch eq $CH) {
1220              !!!cp (24);
1221              ## Stay in the state.
1222              $self->{state_keyword} .= $nch;
1223              !!!next-input-character;
1224              redo A;
1225            } else {
1226              !!!cp (25);
1227              $self->{state} = DATA_STATE;
1228              ## Reconsume.
1229              !!!emit ({type => CHARACTER_TOKEN,
1230                        data => '</' . $self->{state_keyword},
1231                        line => $self->{line_prev},
1232                        column => $self->{column_prev} - 1 - length $self->{state_keyword},
1233                       });
1234              redo A;
1235            }
1236          } else { # after "<{tag-name}"
1237            unless ({
1238                     0x0009 => 1, # HT
1239                     0x000A => 1, # LF
1240                     0x000B => 1, # VT
1241                     0x000C => 1, # FF
1242                     0x0020 => 1, # SP
1243                     0x003E => 1, # >
1244                     0x002F => 1, # /
1245                     -1 => 1, # EOF
1246                    }->{$self->{next_char}}) {
1247              !!!cp (26);
1248              ## Reconsume.
1249              $self->{state} = DATA_STATE;
1250              !!!emit ({type => CHARACTER_TOKEN,
1251                        data => '</' . $self->{state_keyword},
1252                        line => $self->{line_prev},
1253                        column => $self->{column_prev} - 1 - length $self->{state_keyword},
1254                       });
1255              redo A;
1256            } else {
1257              !!!cp (27);
1258              $self->{current_token}
1259                  = {type => END_TAG_TOKEN,
1260                     tag_name => $self->{last_emitted_start_tag_name},
1261                     line => $self->{line_prev},
1262                     column => $self->{column_prev} - 1 - length $self->{state_keyword}};
1263              $self->{state} = TAG_NAME_STATE;
1264              ## Reconsume.
1265              redo A;
1266            }
1267        }        }
1268      } elsif ($self->{state} == TAG_NAME_STATE) {      } elsif ($self->{state} == TAG_NAME_STATE) {
1269        if ($self->{next_char} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
# Line 1646  sub _get_next_token ($) { Line 1710  sub _get_next_token ($) {
1710          redo A;          redo A;
1711        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1712          !!!cp (96);          !!!cp (96);
1713          $self->{last_attribute_value_state} = $self->{state};          ## NOTE: In the spec, the tokenizer is switched to the
1714          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## "entity in attribute value state".  In this implementation, the
1715            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1716            ## implementation of the "consume a character reference" algorithm.
1717            $self->{prev_state} = $self->{state};
1718            $self->{entity_additional} = 0x0022; # "
1719            $self->{state} = ENTITY_STATE;
1720          !!!next-input-character;          !!!next-input-character;
1721          redo A;          redo A;
1722        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
# Line 1676  sub _get_next_token ($) { Line 1745  sub _get_next_token ($) {
1745        } else {        } else {
1746          !!!cp (100);          !!!cp (100);
1747          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{current_attribute}->{value} .= chr ($self->{next_char});
1748            $self->{read_until}->($self->{current_attribute}->{value},
1749                                  q["&],
1750                                  length $self->{current_attribute}->{value});
1751    
1752          ## Stay in the state          ## Stay in the state
1753          !!!next-input-character;          !!!next-input-character;
1754          redo A;          redo A;
# Line 1688  sub _get_next_token ($) { Line 1761  sub _get_next_token ($) {
1761          redo A;          redo A;
1762        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1763          !!!cp (102);          !!!cp (102);
1764          $self->{last_attribute_value_state} = $self->{state};          ## NOTE: In the spec, the tokenizer is switched to the
1765          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## "entity in attribute value state".  In this implementation, the
1766            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1767            ## implementation of the "consume a character reference" algorithm.
1768            $self->{entity_additional} = 0x0027; # '
1769            $self->{prev_state} = $self->{state};
1770            $self->{state} = ENTITY_STATE;
1771          !!!next-input-character;          !!!next-input-character;
1772          redo A;          redo A;
1773        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
# Line 1718  sub _get_next_token ($) { Line 1796  sub _get_next_token ($) {
1796        } else {        } else {
1797          !!!cp (106);          !!!cp (106);
1798          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{current_attribute}->{value} .= chr ($self->{next_char});
1799            $self->{read_until}->($self->{current_attribute}->{value},
1800                                  q['&],
1801                                  length $self->{current_attribute}->{value});
1802    
1803          ## Stay in the state          ## Stay in the state
1804          !!!next-input-character;          !!!next-input-character;
1805          redo A;          redo A;
# Line 1734  sub _get_next_token ($) { Line 1816  sub _get_next_token ($) {
1816          redo A;          redo A;
1817        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1818          !!!cp (108);          !!!cp (108);
1819          $self->{last_attribute_value_state} = $self->{state};          ## NOTE: In the spec, the tokenizer is switched to the
1820          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## "entity in attribute value state".  In this implementation, the
1821            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1822            ## implementation of the "consume a character reference" algorithm.
1823            $self->{entity_additional} = -1;
1824            $self->{prev_state} = $self->{state};
1825            $self->{state} = ENTITY_STATE;
1826          !!!next-input-character;          !!!next-input-character;
1827          redo A;          redo A;
1828        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
# Line 1795  sub _get_next_token ($) { Line 1882  sub _get_next_token ($) {
1882            !!!cp (116);            !!!cp (116);
1883          }          }
1884          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{current_attribute}->{value} .= chr ($self->{next_char});
1885            $self->{read_until}->($self->{current_attribute}->{value},
1886                                  q["'=& >],
1887                                  length $self->{current_attribute}->{value});
1888    
1889          ## Stay in the state          ## Stay in the state
1890          !!!next-input-character;          !!!next-input-character;
1891          redo A;          redo A;
1892        }        }
     } 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;  
1893      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {
1894        if ($self->{next_char} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
1895            $self->{next_char} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
# Line 1940  sub _get_next_token ($) { Line 2009  sub _get_next_token ($) {
2009        }        }
2010      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {
2011        ## (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;  
2012    
2013            !!!emit ($self->{current_token}); # comment        ## NOTE: Unlike spec's "bogus comment state", this implementation
2014          ## consumes characters one-by-one basis.
2015            redo A;        
2016          } elsif ($self->{next_char} == -1) {        if ($self->{next_char} == 0x003E) { # >
2017            !!!cp (125);          !!!cp (124);
2018            $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2019            ## reconsume          !!!next-input-character;
2020    
2021            !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
2022            redo A;
2023          } elsif ($self->{next_char} == -1) {
2024            !!!cp (125);
2025            $self->{state} = DATA_STATE;
2026            ## reconsume
2027    
2028            redo A;          !!!emit ($self->{current_token}); # comment
2029          } else {          redo A;
2030            !!!cp (126);        } else {
2031            $self->{current_token}->{data} .= chr ($self->{next_char}); # comment          !!!cp (126);
2032            !!!next-input-character;          $self->{current_token}->{data} .= chr ($self->{next_char}); # comment
2033            redo BC;          $self->{read_until}->($self->{current_token}->{data},
2034          }                                q[>],
2035        } # BC                                length $self->{current_token}->{data});
2036    
2037        die "$0: _get_next_token: unexpected case [BC]";          ## Stay in the state.
2038            !!!next-input-character;
2039            redo A;
2040          }
2041      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {
2042        ## (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};  
2043                
2044        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
2045            !!!cp (133);
2046            $self->{state} = MD_HYPHEN_STATE;
2047          !!!next-input-character;          !!!next-input-character;
2048          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);  
         }  
2049        } elsif ($self->{next_char} == 0x0044 or # D        } elsif ($self->{next_char} == 0x0044 or # D
2050                 $self->{next_char} == 0x0064) { # d                 $self->{next_char} == 0x0064) { # d
2051            ## ASCII case-insensitive.
2052            !!!cp (130);
2053            $self->{state} = MD_DOCTYPE_STATE;
2054            $self->{state_keyword} = chr $self->{next_char};
2055          !!!next-input-character;          !!!next-input-character;
2056          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);  
         }  
2057        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and
2058                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and
2059                 $self->{next_char} == 0x005B) { # [                 $self->{next_char} == 0x005B) { # [
2060            !!!cp (135.4);                
2061            $self->{state} = MD_CDATA_STATE;
2062            $self->{state_keyword} = '[';
2063          !!!next-input-character;          !!!next-input-character;
2064          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);  
         }  
2065        } else {        } else {
2066          !!!cp (136);          !!!cp (136);
2067        }        }
2068    
2069        !!!parse-error (type => 'bogus comment');        !!!parse-error (type => 'bogus comment',
2070        $self->{next_char} = shift @next_char;                        line => $self->{line_prev},
2071        !!!back-next-input-character (@next_char);                        column => $self->{column_prev} - 1);
2072          ## Reconsume.
2073        $self->{state} = BOGUS_COMMENT_STATE;        $self->{state} = BOGUS_COMMENT_STATE;
2074        $self->{current_token} = {type => COMMENT_TOKEN, data => '',        $self->{current_token} = {type => COMMENT_TOKEN, data => '',
2075                                  line => $l, column => $c,                                  line => $self->{line_prev},
2076                                    column => $self->{column_prev} - 1,
2077                                 };                                 };
2078        redo A;        redo A;
2079              } elsif ($self->{state} == MD_HYPHEN_STATE) {
2080        ## ISSUE: typos in spec: chacacters, is is a parse error        if ($self->{next_char} == 0x002D) { # -
2081        ## 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);
2082            $self->{current_token} = {type => COMMENT_TOKEN, data => '',
2083                                      line => $self->{line_prev},
2084                                      column => $self->{column_prev} - 2,
2085                                     };
2086            $self->{state} = COMMENT_START_STATE;
2087            !!!next-input-character;
2088            redo A;
2089          } else {
2090            !!!cp (128);
2091            !!!parse-error (type => 'bogus comment',
2092                            line => $self->{line_prev},
2093                            column => $self->{column_prev} - 2);
2094            $self->{state} = BOGUS_COMMENT_STATE;
2095            ## Reconsume.
2096            $self->{current_token} = {type => COMMENT_TOKEN,
2097                                      data => '-',
2098                                      line => $self->{line_prev},
2099                                      column => $self->{column_prev} - 2,
2100                                     };
2101            redo A;
2102          }
2103        } elsif ($self->{state} == MD_DOCTYPE_STATE) {
2104          ## ASCII case-insensitive.
2105          if ($self->{next_char} == [
2106                undef,
2107                0x004F, # O
2108                0x0043, # C
2109                0x0054, # T
2110                0x0059, # Y
2111                0x0050, # P
2112              ]->[length $self->{state_keyword}] or
2113              $self->{next_char} == [
2114                undef,
2115                0x006F, # o
2116                0x0063, # c
2117                0x0074, # t
2118                0x0079, # y
2119                0x0070, # p
2120              ]->[length $self->{state_keyword}]) {
2121            !!!cp (131);
2122            ## Stay in the state.
2123            $self->{state_keyword} .= chr $self->{next_char};
2124            !!!next-input-character;
2125            redo A;
2126          } elsif ((length $self->{state_keyword}) == 6 and
2127                   ($self->{next_char} == 0x0045 or # E
2128                    $self->{next_char} == 0x0065)) { # e
2129            !!!cp (129);
2130            $self->{state} = DOCTYPE_STATE;
2131            $self->{current_token} = {type => DOCTYPE_TOKEN,
2132                                      quirks => 1,
2133                                      line => $self->{line_prev},
2134                                      column => $self->{column_prev} - 7,
2135                                     };
2136            !!!next-input-character;
2137            redo A;
2138          } else {
2139            !!!cp (132);        
2140            !!!parse-error (type => 'bogus comment',
2141                            line => $self->{line_prev},
2142                            column => $self->{column_prev} - 1 - length $self->{state_keyword});
2143            $self->{state} = BOGUS_COMMENT_STATE;
2144            ## Reconsume.
2145            $self->{current_token} = {type => COMMENT_TOKEN,
2146                                      data => $self->{state_keyword},
2147                                      line => $self->{line_prev},
2148                                      column => $self->{column_prev} - 1 - length $self->{state_keyword},
2149                                     };
2150            redo A;
2151          }
2152        } elsif ($self->{state} == MD_CDATA_STATE) {
2153          if ($self->{next_char} == {
2154                '[' => 0x0043, # C
2155                '[C' => 0x0044, # D
2156                '[CD' => 0x0041, # A
2157                '[CDA' => 0x0054, # T
2158                '[CDAT' => 0x0041, # A
2159              }->{$self->{state_keyword}}) {
2160            !!!cp (135.1);
2161            ## Stay in the state.
2162            $self->{state_keyword} .= chr $self->{next_char};
2163            !!!next-input-character;
2164            redo A;
2165          } elsif ($self->{state_keyword} eq '[CDATA' and
2166                   $self->{next_char} == 0x005B) { # [
2167            !!!cp (135.2);
2168            $self->{current_token} = {type => CHARACTER_TOKEN,
2169                                      data => '',
2170                                      line => $self->{line_prev},
2171                                      column => $self->{column_prev} - 7};
2172            $self->{state} = CDATA_SECTION_STATE;
2173            !!!next-input-character;
2174            redo A;
2175          } else {
2176            !!!cp (135.3);
2177            !!!parse-error (type => 'bogus comment',
2178                            line => $self->{line_prev},
2179                            column => $self->{column_prev} - 1 - length $self->{state_keyword});
2180            $self->{state} = BOGUS_COMMENT_STATE;
2181            ## Reconsume.
2182            $self->{current_token} = {type => COMMENT_TOKEN,
2183                                      data => $self->{state_keyword},
2184                                      line => $self->{line_prev},
2185                                      column => $self->{column_prev} - 1 - length $self->{state_keyword},
2186                                     };
2187            redo A;
2188          }
2189      } elsif ($self->{state} == COMMENT_START_STATE) {      } elsif ($self->{state} == COMMENT_START_STATE) {
2190        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
2191          !!!cp (137);          !!!cp (137);
# Line 2185  sub _get_next_token ($) { Line 2268  sub _get_next_token ($) {
2268        } else {        } else {
2269          !!!cp (147);          !!!cp (147);
2270          $self->{current_token}->{data} .= chr ($self->{next_char}); # comment          $self->{current_token}->{data} .= chr ($self->{next_char}); # comment
2271            $self->{read_until}->($self->{current_token}->{data},
2272                                  q[-],
2273                                  length $self->{current_token}->{data});
2274    
2275          ## Stay in the state          ## Stay in the state
2276          !!!next-input-character;          !!!next-input-character;
2277          redo A;          redo A;
# Line 2369  sub _get_next_token ($) { Line 2456  sub _get_next_token ($) {
2456          redo A;          redo A;
2457        } elsif ($self->{next_char} == 0x0050 or # P        } elsif ($self->{next_char} == 0x0050 or # P
2458                 $self->{next_char} == 0x0070) { # p                 $self->{next_char} == 0x0070) { # p
2459            $self->{state} = PUBLIC_STATE;
2460            $self->{state_keyword} = chr $self->{next_char};
2461          !!!next-input-character;          !!!next-input-character;
2462          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);  
         }  
   
         #  
2463        } elsif ($self->{next_char} == 0x0053 or # S        } elsif ($self->{next_char} == 0x0053 or # S
2464                 $self->{next_char} == 0x0073) { # s                 $self->{next_char} == 0x0073) { # s
2465            $self->{state} = SYSTEM_STATE;
2466            $self->{state_keyword} = chr $self->{next_char};
2467          !!!next-input-character;          !!!next-input-character;
2468          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);  
         }  
   
         #  
2469        } else {        } else {
2470          !!!cp (180);          !!!cp (180);
2471            !!!parse-error (type => 'string after DOCTYPE name');
2472            $self->{current_token}->{quirks} = 1;
2473    
2474            $self->{state} = BOGUS_DOCTYPE_STATE;
2475          !!!next-input-character;          !!!next-input-character;
2476          #          redo A;
2477        }        }
2478        } elsif ($self->{state} == PUBLIC_STATE) {
2479          ## ASCII case-insensitive
2480          if ($self->{next_char} == [
2481                undef,
2482                0x0055, # U
2483                0x0042, # B
2484                0x004C, # L
2485                0x0049, # I
2486              ]->[length $self->{state_keyword}] or
2487              $self->{next_char} == [
2488                undef,
2489                0x0075, # u
2490                0x0062, # b
2491                0x006C, # l
2492                0x0069, # i
2493              ]->[length $self->{state_keyword}]) {
2494            !!!cp (175);
2495            ## Stay in the state.
2496            $self->{state_keyword} .= chr $self->{next_char};
2497            !!!next-input-character;
2498            redo A;
2499          } elsif ((length $self->{state_keyword}) == 5 and
2500                   ($self->{next_char} == 0x0043 or # C
2501                    $self->{next_char} == 0x0063)) { # c
2502            !!!cp (168);
2503            $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
2504            !!!next-input-character;
2505            redo A;
2506          } else {
2507            !!!cp (169);
2508            !!!parse-error (type => 'string after DOCTYPE name',
2509                            line => $self->{line_prev},
2510                            column => $self->{column_prev} + 1 - length $self->{state_keyword});
2511            $self->{current_token}->{quirks} = 1;
2512    
2513        !!!parse-error (type => 'string after DOCTYPE name');          $self->{state} = BOGUS_DOCTYPE_STATE;
2514        $self->{current_token}->{quirks} = 1;          ## Reconsume.
2515            redo A;
2516          }
2517        } elsif ($self->{state} == SYSTEM_STATE) {
2518          ## ASCII case-insensitive
2519          if ($self->{next_char} == [
2520                undef,
2521                0x0059, # Y
2522                0x0053, # S
2523                0x0054, # T
2524                0x0045, # E
2525              ]->[length $self->{state_keyword}] or
2526              $self->{next_char} == [
2527                undef,
2528                0x0079, # y
2529                0x0073, # s
2530                0x0074, # t
2531                0x0065, # e
2532              ]->[length $self->{state_keyword}]) {
2533            !!!cp (170);
2534            ## Stay in the state.
2535            $self->{state_keyword} .= chr $self->{next_char};
2536            !!!next-input-character;
2537            redo A;
2538          } elsif ((length $self->{state_keyword}) == 5 and
2539                   ($self->{next_char} == 0x004D or # M
2540                    $self->{next_char} == 0x006D)) { # m
2541            !!!cp (171);
2542            $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2543            !!!next-input-character;
2544            redo A;
2545          } else {
2546            !!!cp (172);
2547            !!!parse-error (type => 'string after DOCTYPE name',
2548                            line => $self->{line_prev},
2549                            column => $self->{column_prev} + 1 - length $self->{state_keyword});
2550            $self->{current_token}->{quirks} = 1;
2551    
2552        $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2553        # next-input-character is already done          ## Reconsume.
2554        redo A;          redo A;
2555          }
2556      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {
2557        if ({        if ({
2558              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
# Line 2539  sub _get_next_token ($) { Line 2637  sub _get_next_token ($) {
2637          !!!cp (190);          !!!cp (190);
2638          $self->{current_token}->{public_identifier} # DOCTYPE          $self->{current_token}->{public_identifier} # DOCTYPE
2639              .= chr $self->{next_char};              .= chr $self->{next_char};
2640            $self->{read_until}->($self->{current_token}->{public_identifier},
2641                                  q[">],
2642                                  length $self->{current_token}->{public_identifier});
2643    
2644          ## Stay in the state          ## Stay in the state
2645          !!!next-input-character;          !!!next-input-character;
2646          redo A;          redo A;
# Line 2575  sub _get_next_token ($) { Line 2677  sub _get_next_token ($) {
2677          !!!cp (194);          !!!cp (194);
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 2711  sub _get_next_token ($) { Line 2817  sub _get_next_token ($) {
2817          !!!cp (210);          !!!cp (210);
2818          $self->{current_token}->{system_identifier} # DOCTYPE          $self->{current_token}->{system_identifier} # DOCTYPE
2819              .= chr $self->{next_char};              .= chr $self->{next_char};
2820            $self->{read_until}->($self->{current_token}->{system_identifier},
2821                                  q[">],
2822                                  length $self->{current_token}->{system_identifier});
2823    
2824          ## Stay in the state          ## Stay in the state
2825          !!!next-input-character;          !!!next-input-character;
2826          redo A;          redo A;
# Line 2747  sub _get_next_token ($) { Line 2857  sub _get_next_token ($) {
2857          !!!cp (214);          !!!cp (214);
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 2807  sub _get_next_token ($) { Line 2921  sub _get_next_token ($) {
2921          redo A;          redo A;
2922        } else {        } else {
2923          !!!cp (221);          !!!cp (221);
2924            my $s = '';
2925            $self->{read_until}->($s, q[>], 0);
2926    
2927          ## Stay in the state          ## Stay in the state
2928          !!!next-input-character;          !!!next-input-character;
2929          redo A;          redo A;
2930        }        }
2931      } elsif ($self->{state} == CDATA_BLOCK_STATE) {      } elsif ($self->{state} == CDATA_SECTION_STATE) {
2932        my $s = '';        ## NOTE: "CDATA section state" in the state is jointly implemented
2933          ## by three states, |CDATA_SECTION_STATE|, |CDATA_SECTION_MSE1_STATE|,
2934          ## and |CDATA_SECTION_MSE2_STATE|.
2935                
2936        my ($l, $c) = ($self->{line}, $self->{column});        if ($self->{next_char} == 0x005D) { # ]
2937            !!!cp (221.1);
2938        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};  
2939          !!!next-input-character;          !!!next-input-character;
2940        } # CS          redo A;
2941          } elsif ($self->{next_char} == -1) {
2942            $self->{state} = DATA_STATE;
2943            !!!next-input-character;
2944            if (length $self->{current_token}->{data}) { # character
2945              !!!cp (221.2);
2946              !!!emit ($self->{current_token}); # character
2947            } else {
2948              !!!cp (221.3);
2949              ## No token to emit. $self->{current_token} is discarded.
2950            }        
2951            redo A;
2952          } else {
2953            !!!cp (221.4);
2954            $self->{current_token}->{data} .= chr $self->{next_char};
2955            $self->{read_until}->($self->{current_token}->{data},
2956                                  q<]>,
2957                                  length $self->{current_token}->{data});
2958    
2959        $self->{state} = DATA_STATE;          ## Stay in the state.
2960        ## next-input-character done or EOF, which is reconsumed.          !!!next-input-character;
2961            redo A;
2962          }
2963    
2964        if (length $s) {        ## ISSUE: "text tokens" in spec.
2965        } elsif ($self->{state} == CDATA_SECTION_MSE1_STATE) {
2966          if ($self->{next_char} == 0x005D) { # ]
2967            !!!cp (221.5);
2968            $self->{state} = CDATA_SECTION_MSE2_STATE;
2969            !!!next-input-character;
2970            redo A;
2971          } else {
2972          !!!cp (221.6);          !!!cp (221.6);
2973          !!!emit ({type => CHARACTER_TOKEN, data => $s,          $self->{current_token}->{data} .= ']';
2974                    line => $l, column => $c});          $self->{state} = CDATA_SECTION_STATE;
2975            ## Reconsume.
2976            redo A;
2977          }
2978        } elsif ($self->{state} == CDATA_SECTION_MSE2_STATE) {
2979          if ($self->{next_char} == 0x003E) { # >
2980            $self->{state} = DATA_STATE;
2981            !!!next-input-character;
2982            if (length $self->{current_token}->{data}) { # character
2983              !!!cp (221.7);
2984              !!!emit ($self->{current_token}); # character
2985            } else {
2986              !!!cp (221.8);
2987              ## No token to emit. $self->{current_token} is discarded.
2988            }
2989            redo A;
2990          } elsif ($self->{next_char} == 0x005D) { # ]
2991            !!!cp (221.9); # character
2992            $self->{current_token}->{data} .= ']'; ## Add first "]" of "]]]".
2993            ## Stay in the state.
2994            !!!next-input-character;
2995            redo A;
2996        } else {        } else {
2997          !!!cp (221.7);          !!!cp (221.11);
2998            $self->{current_token}->{data} .= ']]'; # character
2999            $self->{state} = CDATA_SECTION_STATE;
3000            ## Reconsume.
3001            redo A;
3002          }
3003        } elsif ($self->{state} == ENTITY_STATE) {
3004          if ({
3005            0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,
3006            0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, &
3007            $self->{entity_additional} => 1,
3008          }->{$self->{next_char}}) {
3009            !!!cp (1001);
3010            ## Don't consume
3011            ## No error
3012            ## Return nothing.
3013            #
3014          } elsif ($self->{next_char} == 0x0023) { # #
3015            !!!cp (999);
3016            $self->{state} = ENTITY_HASH_STATE;
3017            $self->{state_keyword} = '#';
3018            !!!next-input-character;
3019            redo A;
3020          } elsif ((0x0041 <= $self->{next_char} and
3021                    $self->{next_char} <= 0x005A) or # A..Z
3022                   (0x0061 <= $self->{next_char} and
3023                    $self->{next_char} <= 0x007A)) { # a..z
3024            !!!cp (998);
3025            require Whatpm::_NamedEntityList;
3026            $self->{state} = ENTITY_NAME_STATE;
3027            $self->{state_keyword} = chr $self->{next_char};
3028            $self->{entity__value} = $self->{state_keyword};
3029            $self->{entity__match} = 0;
3030            !!!next-input-character;
3031            redo A;
3032          } else {
3033            !!!cp (1027);
3034            !!!parse-error (type => 'bare ero');
3035            ## Return nothing.
3036            #
3037        }        }
3038    
3039        redo A;        ## NOTE: No character is consumed by the "consume a character
3040          ## reference" algorithm.  In other word, there is an "&" character
3041        ## ISSUE: "text tokens" in spec.        ## that does not introduce a character reference, which would be
3042        ## TODO: Streaming support        ## appended to the parent element or the attribute value in later
3043      } else {        ## process of the tokenizer.
3044        die "$0: $self->{state}: Unknown state";  
3045      }        if ($self->{prev_state} == DATA_STATE) {
3046    } # A            !!!cp (997);
3047            $self->{state} = $self->{prev_state};
3048    die "$0: _get_next_token: unexpected case";          ## Reconsume.
3049  } # _get_next_token          !!!emit ({type => CHARACTER_TOKEN, data => '&',
3050                      line => $self->{line_prev},
3051  sub _tokenize_attempt_to_consume_an_entity ($$$) {                    column => $self->{column_prev},
3052    my ($self, $in_attr, $additional) = @_;                   });
3053            redo A;
3054    my ($l, $c) = ($self->{line_prev}, $self->{column_prev});        } else {
3055            !!!cp (996);
3056            $self->{current_attribute}->{value} .= '&';
3057            $self->{state} = $self->{prev_state};
3058            ## Reconsume.
3059            redo A;
3060          }
3061        } elsif ($self->{state} == ENTITY_HASH_STATE) {
3062          if ($self->{next_char} == 0x0078 or # x
3063              $self->{next_char} == 0x0058) { # X
3064            !!!cp (995);
3065            $self->{state} = HEXREF_X_STATE;
3066            $self->{state_keyword} .= chr $self->{next_char};
3067            !!!next-input-character;
3068            redo A;
3069          } elsif (0x0030 <= $self->{next_char} and
3070                   $self->{next_char} <= 0x0039) { # 0..9
3071            !!!cp (994);
3072            $self->{state} = NCR_NUM_STATE;
3073            $self->{state_keyword} = $self->{next_char} - 0x0030;
3074            !!!next-input-character;
3075            redo A;
3076          } else {
3077            !!!parse-error (type => 'bare nero',
3078                            line => $self->{line_prev},
3079                            column => $self->{column_prev} - 1);
3080    
3081    if ({          ## NOTE: According to the spec algorithm, nothing is returned,
3082         0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,          ## and then "&#" is appended to the parent element or the attribute
3083         0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR          ## value in the later processing.
3084         $additional => 1,  
3085        }->{$self->{next_char}}) {          if ($self->{prev_state} == DATA_STATE) {
3086      !!!cp (1001);            !!!cp (1019);
3087      ## Don't consume            $self->{state} = $self->{prev_state};
3088      ## No error            ## Reconsume.
3089      return undef;            !!!emit ({type => CHARACTER_TOKEN,
3090    } elsif ($self->{next_char} == 0x0023) { # #                      data => '&#',
3091      !!!next-input-character;                      line => $self->{line_prev},
3092      if ($self->{next_char} == 0x0078 or # x                      column => $self->{column_prev} - 1,
3093          $self->{next_char} == 0x0058) { # X                     });
3094        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;  
3095          } else {          } else {
3096            !!!cp (1007);            !!!cp (993);
3097            !!!parse-error (type => 'no refc', line => $l, column => $c);            $self->{current_attribute}->{value} .= '&#';
3098              $self->{state} = $self->{prev_state};
3099              ## Reconsume.
3100              redo A;
3101          }          }
3102          }
3103          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {      } elsif ($self->{state} == NCR_NUM_STATE) {
3104            !!!cp (1008);        if (0x0030 <= $self->{next_char} and
3105            !!!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  
3106          !!!cp (1012);          !!!cp (1012);
3107          $code *= 10;          $self->{state_keyword} *= 10;
3108          $code += $self->{next_char} - 0x0030;          $self->{state_keyword} += $self->{next_char} - 0x0030;
3109                    
3110            ## Stay in the state.
3111          !!!next-input-character;          !!!next-input-character;
3112        }          redo A;
3113          } elsif ($self->{next_char} == 0x003B) { # ;
       if ($self->{next_char} == 0x003B) { # ;  
3114          !!!cp (1013);          !!!cp (1013);
3115          !!!next-input-character;          !!!next-input-character;
3116            #
3117        } else {        } else {
3118          !!!cp (1014);          !!!cp (1014);
3119          !!!parse-error (type => 'no refc', line => $l, column => $c);          !!!parse-error (type => 'no refc');
3120            ## Reconsume.
3121            #
3122        }        }
3123    
3124          my $code = $self->{state_keyword};
3125          my $l = $self->{line_prev};
3126          my $c = $self->{column_prev};
3127        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3128          !!!cp (1015);          !!!cp (1015);
3129          !!!parse-error (type => 'invalid character reference',          !!!parse-error (type => 'invalid character reference',
# Line 3003  sub _tokenize_attempt_to_consume_an_enti Line 3148  sub _tokenize_attempt_to_consume_an_enti
3148                          line => $l, column => $c);                          line => $l, column => $c);
3149          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
3150        }        }
3151          
3152        return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1,        if ($self->{prev_state} == DATA_STATE) {
3153                line => $l, column => $c,          !!!cp (992);
3154               };          $self->{state} = $self->{prev_state};
3155      } else {          ## Reconsume.
3156        !!!cp (1019);          !!!emit ({type => CHARACTER_TOKEN, data => chr $code,
3157        !!!parse-error (type => 'bare nero', line => $l, column => $c);                    line => $l, column => $c,
3158        !!!back-next-input-character ($self->{next_char});                   });
3159        $self->{next_char} = 0x0023; # #          redo A;
3160        return undef;        } else {
3161      }          !!!cp (991);
3162    } elsif ((0x0041 <= $self->{next_char} and          $self->{current_attribute}->{value} .= chr $code;
3163              $self->{next_char} <= 0x005A) or          $self->{current_attribute}->{has_reference} = 1;
3164             (0x0061 <= $self->{next_char} and          $self->{state} = $self->{prev_state};
3165              $self->{next_char} <= 0x007A)) {          ## Reconsume.
3166      my $entity_name = chr $self->{next_char};          redo A;
3167      !!!next-input-character;        }
3168        } elsif ($self->{state} == HEXREF_X_STATE) {
3169      my $value = $entity_name;        if ((0x0030 <= $self->{next_char} and $self->{next_char} <= 0x0039) or
3170      my $match = 0;            (0x0041 <= $self->{next_char} and $self->{next_char} <= 0x0046) or
3171      require Whatpm::_NamedEntityList;            (0x0061 <= $self->{next_char} and $self->{next_char} <= 0x0066)) {
3172      our $EntityChar;          # 0..9, A..F, a..f
3173            !!!cp (990);
3174      while (length $entity_name < 30 and          $self->{state} = HEXREF_HEX_STATE;
3175             ## NOTE: Some number greater than the maximum length of entity name          $self->{state_keyword} = 0;
3176             ((0x0041 <= $self->{next_char} and # a          ## Reconsume.
3177               $self->{next_char} <= 0x005A) or # x          redo A;
3178              (0x0061 <= $self->{next_char} and # a        } else {
3179               $self->{next_char} <= 0x007A) or # z          !!!parse-error (type => 'bare hcro',
3180              (0x0030 <= $self->{next_char} and # 0                          line => $self->{line_prev},
3181               $self->{next_char} <= 0x0039) or # 9                          column => $self->{column_prev} - 2);
3182              $self->{next_char} == 0x003B)) { # ;  
3183        $entity_name .= chr $self->{next_char};          ## NOTE: According to the spec algorithm, nothing is returned,
3184        if (defined $EntityChar->{$entity_name}) {          ## and then "&#" followed by "X" or "x" is appended to the parent
3185          if ($self->{next_char} == 0x003B) { # ;          ## element or the attribute value in the later processing.
3186            !!!cp (1020);  
3187            $value = $EntityChar->{$entity_name};          if ($self->{prev_state} == DATA_STATE) {
3188            $match = 1;            !!!cp (1005);
3189            !!!next-input-character;            $self->{state} = $self->{prev_state};
3190            last;            ## Reconsume.
3191              !!!emit ({type => CHARACTER_TOKEN,
3192                        data => '&' . $self->{state_keyword},
3193                        line => $self->{line_prev},
3194                        column => $self->{column_prev} - length $self->{state_keyword},
3195                       });
3196              redo A;
3197          } else {          } else {
3198            !!!cp (1021);            !!!cp (989);
3199            $value = $EntityChar->{$entity_name};            $self->{current_attribute}->{value} .= '&' . $self->{state_keyword};
3200            $match = -1;            $self->{state} = $self->{prev_state};
3201              ## Reconsume.
3202              redo A;
3203            }
3204          }
3205        } elsif ($self->{state} == HEXREF_HEX_STATE) {
3206          if (0x0030 <= $self->{next_char} and $self->{next_char} <= 0x0039) {
3207            # 0..9
3208            !!!cp (1002);
3209            $self->{state_keyword} *= 0x10;
3210            $self->{state_keyword} += $self->{next_char} - 0x0030;
3211            ## Stay in the state.
3212            !!!next-input-character;
3213            redo A;
3214          } elsif (0x0061 <= $self->{next_char} and
3215                   $self->{next_char} <= 0x0066) { # a..f
3216            !!!cp (1003);
3217            $self->{state_keyword} *= 0x10;
3218            $self->{state_keyword} += $self->{next_char} - 0x0060 + 9;
3219            ## Stay in the state.
3220            !!!next-input-character;
3221            redo A;
3222          } elsif (0x0041 <= $self->{next_char} and
3223                   $self->{next_char} <= 0x0046) { # A..F
3224            !!!cp (1004);
3225            $self->{state_keyword} *= 0x10;
3226            $self->{state_keyword} += $self->{next_char} - 0x0040 + 9;
3227            ## Stay in the state.
3228            !!!next-input-character;
3229            redo A;
3230          } elsif ($self->{next_char} == 0x003B) { # ;
3231            !!!cp (1006);
3232            !!!next-input-character;
3233            #
3234          } else {
3235            !!!cp (1007);
3236            !!!parse-error (type => 'no refc',
3237                            line => $self->{line},
3238                            column => $self->{column});
3239            ## Reconsume.
3240            #
3241          }
3242    
3243          my $code = $self->{state_keyword};
3244          my $l = $self->{line_prev};
3245          my $c = $self->{column_prev};
3246          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3247            !!!cp (1008);
3248            !!!parse-error (type => 'invalid character reference',
3249                            text => (sprintf 'U+%04X', $code),
3250                            line => $l, column => $c);
3251            $code = 0xFFFD;
3252          } elsif ($code > 0x10FFFF) {
3253            !!!cp (1009);
3254            !!!parse-error (type => 'invalid character reference',
3255                            text => (sprintf 'U-%08X', $code),
3256                            line => $l, column => $c);
3257            $code = 0xFFFD;
3258          } elsif ($code == 0x000D) {
3259            !!!cp (1010);
3260            !!!parse-error (type => 'CR character reference', line => $l, column => $c);
3261            $code = 0x000A;
3262          } elsif (0x80 <= $code and $code <= 0x9F) {
3263            !!!cp (1011);
3264            !!!parse-error (type => 'C1 character reference', text => (sprintf 'U+%04X', $code), line => $l, column => $c);
3265            $code = $c1_entity_char->{$code};
3266          }
3267    
3268          if ($self->{prev_state} == DATA_STATE) {
3269            !!!cp (988);
3270            $self->{state} = $self->{prev_state};
3271            ## Reconsume.
3272            !!!emit ({type => CHARACTER_TOKEN, data => chr $code,
3273                      line => $l, column => $c,
3274                     });
3275            redo A;
3276          } else {
3277            !!!cp (987);
3278            $self->{current_attribute}->{value} .= chr $code;
3279            $self->{current_attribute}->{has_reference} = 1;
3280            $self->{state} = $self->{prev_state};
3281            ## Reconsume.
3282            redo A;
3283          }
3284        } elsif ($self->{state} == ENTITY_NAME_STATE) {
3285          if (length $self->{state_keyword} < 30 and
3286              ## NOTE: Some number greater than the maximum length of entity name
3287              ((0x0041 <= $self->{next_char} and # a
3288                $self->{next_char} <= 0x005A) or # x
3289               (0x0061 <= $self->{next_char} and # a
3290                $self->{next_char} <= 0x007A) or # z
3291               (0x0030 <= $self->{next_char} and # 0
3292                $self->{next_char} <= 0x0039) or # 9
3293               $self->{next_char} == 0x003B)) { # ;
3294            our $EntityChar;
3295            $self->{state_keyword} .= chr $self->{next_char};
3296            if (defined $EntityChar->{$self->{state_keyword}}) {
3297              if ($self->{next_char} == 0x003B) { # ;
3298                !!!cp (1020);
3299                $self->{entity__value} = $EntityChar->{$self->{state_keyword}};
3300                $self->{entity__match} = 1;
3301                !!!next-input-character;
3302                #
3303              } else {
3304                !!!cp (1021);
3305                $self->{entity__value} = $EntityChar->{$self->{state_keyword}};
3306                $self->{entity__match} = -1;
3307                ## Stay in the state.
3308                !!!next-input-character;
3309                redo A;
3310              }
3311            } else {
3312              !!!cp (1022);
3313              $self->{entity__value} .= chr $self->{next_char};
3314              $self->{entity__match} *= 2;
3315              ## Stay in the state.
3316            !!!next-input-character;            !!!next-input-character;
3317              redo A;
3318            }
3319          }
3320    
3321          my $data;
3322          my $has_ref;
3323          if ($self->{entity__match} > 0) {
3324            !!!cp (1023);
3325            $data = $self->{entity__value};
3326            $has_ref = 1;
3327            #
3328          } elsif ($self->{entity__match} < 0) {
3329            !!!parse-error (type => 'no refc');
3330            if ($self->{prev_state} != DATA_STATE and # in attribute
3331                $self->{entity__match} < -1) {
3332              !!!cp (1024);
3333              $data = '&' . $self->{state_keyword};
3334              #
3335            } else {
3336              !!!cp (1025);
3337              $data = $self->{entity__value};
3338              $has_ref = 1;
3339              #
3340          }          }
3341        } else {        } else {
3342          !!!cp (1022);          !!!cp (1026);
3343          $value .= chr $self->{next_char};          !!!parse-error (type => 'bare ero',
3344          $match *= 2;                          line => $self->{line_prev},
3345          !!!next-input-character;                          column => $self->{column_prev});
3346            $data = '&' . $self->{state_keyword};
3347            #
3348        }        }
3349      }    
3350              ## NOTE: In these cases, when a character reference is found,
3351      if ($match > 0) {        ## it is consumed and a character token is returned, or, otherwise,
3352        !!!cp (1023);        ## nothing is consumed and returned, according to the spec algorithm.
3353        return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,        ## In this implementation, anything that has been examined by the
3354                line => $l, column => $c,        ## tokenizer is appended to the parent element or the attribute value
3355               };        ## as string, either literal string when no character reference or
3356      } elsif ($match < 0) {        ## entity-replaced string otherwise, in this stage, since any characters
3357        !!!parse-error (type => 'no refc', line => $l, column => $c);        ## that would not be consumed are appended in the data state or in an
3358        if ($in_attr and $match < -1) {        ## appropriate attribute value state anyway.
3359          !!!cp (1024);  
3360          return {type => CHARACTER_TOKEN, data => '&'.$entity_name,        if ($self->{prev_state} == DATA_STATE) {
3361                  line => $l, column => $c,          !!!cp (986);
3362                 };          $self->{state} = $self->{prev_state};
3363        } else {          ## Reconsume.
3364          !!!cp (1025);          !!!emit ({type => CHARACTER_TOKEN,
3365          return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,                    data => $data,
3366                  line => $l, column => $c,                    line => $self->{line_prev},
3367                 };                    column => $self->{column_prev} + 1 - length $self->{state_keyword},
3368                     });
3369            redo A;
3370          } else {
3371            !!!cp (985);
3372            $self->{current_attribute}->{value} .= $data;
3373            $self->{current_attribute}->{has_reference} = 1 if $has_ref;
3374            $self->{state} = $self->{prev_state};
3375            ## Reconsume.
3376            redo A;
3377        }        }
3378      } else {      } else {
3379        !!!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,  
              };  
3380      }      }
3381    } else {    } # A  
3382      !!!cp (1027);  
3383      ## no characters are consumed    die "$0: _get_next_token: unexpected case";
3384      !!!parse-error (type => 'bare ero', line => $l, column => $c);  } # _get_next_token
     return undef;  
   }  
 } # _tokenize_attempt_to_consume_an_entity  
3385    
3386  sub _initialize_tree_constructor ($) {  sub _initialize_tree_constructor ($) {
3387    my $self = shift;    my $self = shift;
# Line 3154  sub _tree_construction_initial ($) { Line 3446  sub _tree_construction_initial ($) {
3446        ## language.        ## language.
3447        my $doctype_name = $token->{name};        my $doctype_name = $token->{name};
3448        $doctype_name = '' unless defined $doctype_name;        $doctype_name = '' unless defined $doctype_name;
3449        $doctype_name =~ tr/a-z/A-Z/;        $doctype_name =~ tr/a-z/A-Z/; # ASCII case-insensitive
3450        if (not defined $token->{name} or # <!DOCTYPE>        if (not defined $token->{name} or # <!DOCTYPE>
           defined $token->{public_identifier} or  
3451            defined $token->{system_identifier}) {            defined $token->{system_identifier}) {
3452          !!!cp ('t1');          !!!cp ('t1');
3453          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3454        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
3455          !!!cp ('t2');          !!!cp ('t2');
         ## ISSUE: ASCII case-insensitive? (in fact it does not matter)  
3456          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3457          } elsif (defined $token->{public_identifier}) {
3458            if ($token->{public_identifier} eq 'XSLT-compat') {
3459              !!!cp ('t1.2');
3460              !!!parse-error (type => 'XSLT-compat', token => $token,
3461                              level => $self->{level}->{should});
3462            } else {
3463              !!!parse-error (type => 'not HTML5', token => $token);
3464            }
3465        } else {        } else {
3466          !!!cp ('t3');          !!!cp ('t3');
3467            #
3468        }        }
3469                
3470        my $doctype = $self->{document}->create_document_type_definition        my $doctype = $self->{document}->create_document_type_definition
# Line 6301  sub _tree_construction_main ($) { Line 6600  sub _tree_construction_main ($) {
6600            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6601              !!!cp ('t312');              !!!cp ('t312');
6602              !!!parse-error (type => 'after frameset:#text', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6603            } else { # "after html frameset"            } else { # "after after frameset"
6604              !!!cp ('t313');              !!!cp ('t313');
6605              !!!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);  
6606            }            }
6607                        
6608            ## Ignore the token.            ## Ignore the token.
# Line 6323  sub _tree_construction_main ($) { Line 6618  sub _tree_construction_main ($) {
6618                    
6619          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
6620        } 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');  
         }  
   
6621          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6622              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6623            !!!cp ('t318');            !!!cp ('t318');
# Line 6354  sub _tree_construction_main ($) { Line 6638  sub _tree_construction_main ($) {
6638            ## NOTE: As if in head.            ## NOTE: As if in head.
6639            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
6640            next B;            next B;
6641    
6642              ## NOTE: |<!DOCTYPE HTML><frameset></frameset></html><noframes></noframes>|
6643              ## has no parse error.
6644          } else {          } else {
6645            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6646              !!!cp ('t321');              !!!cp ('t321');
6647              !!!parse-error (type => 'in frameset',              !!!parse-error (type => 'in frameset',
6648                              text => $token->{tag_name}, token => $token);                              text => $token->{tag_name}, token => $token);
6649            } else {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6650              !!!cp ('t322');              !!!cp ('t322');
6651              !!!parse-error (type => 'after frameset',              !!!parse-error (type => 'after frameset',
6652                              text => $token->{tag_name}, token => $token);                              text => $token->{tag_name}, token => $token);
6653              } else { # "after after frameset"
6654                !!!cp ('t322.2');
6655                !!!parse-error (type => 'after after frameset',
6656                                text => $token->{tag_name}, token => $token);
6657            }            }
6658            ## Ignore the token            ## Ignore the token
6659            !!!nack ('t322.1');            !!!nack ('t322.1');
# Line 6370  sub _tree_construction_main ($) { Line 6661  sub _tree_construction_main ($) {
6661            next B;            next B;
6662          }          }
6663        } 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');  
         }  
   
6664          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6665              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6666            if ($self->{open_elements}->[-1]->[1] & HTML_EL and            if ($self->{open_elements}->[-1]->[1] & HTML_EL and
# Line 6415  sub _tree_construction_main ($) { Line 6695  sub _tree_construction_main ($) {
6695              !!!cp ('t330');              !!!cp ('t330');
6696              !!!parse-error (type => 'in frameset:/',              !!!parse-error (type => 'in frameset:/',
6697                              text => $token->{tag_name}, token => $token);                              text => $token->{tag_name}, token => $token);
6698            } else {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6699              !!!cp ('t331');              !!!cp ('t330.1');
6700              !!!parse-error (type => 'after frameset:/',              !!!parse-error (type => 'after frameset:/',
6701                              text => $token->{tag_name}, token => $token);                              text => $token->{tag_name}, token => $token);
6702              } else { # "after after html"
6703                !!!cp ('t331');
6704                !!!parse-error (type => 'after after frameset:/',
6705                                text => $token->{tag_name}, token => $token);
6706            }            }
6707            ## Ignore the token            ## Ignore the token
6708            !!!next-token;            !!!next-token;
# Line 7141  sub _tree_construction_main ($) { Line 7425  sub _tree_construction_main ($) {
7425            !!!cp ('t413');            !!!cp ('t413');
7426            !!!parse-error (type => 'unmatched end tag',            !!!parse-error (type => 'unmatched end tag',
7427                            text => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7428              ## NOTE: Ignore the token.
7429          } else {          } else {
7430            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7431            while ({            while ({
# Line 7200  sub _tree_construction_main ($) { Line 7485  sub _tree_construction_main ($) {
7485            !!!cp ('t421');            !!!cp ('t421');
7486            !!!parse-error (type => 'unmatched end tag',            !!!parse-error (type => 'unmatched end tag',
7487                            text => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7488              ## NOTE: Ignore the token.
7489          } else {          } else {
7490            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7491            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7246  sub _tree_construction_main ($) { Line 7532  sub _tree_construction_main ($) {
7532            !!!cp ('t425.1');            !!!cp ('t425.1');
7533            !!!parse-error (type => 'unmatched end tag',            !!!parse-error (type => 'unmatched end tag',
7534                            text => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7535              ## NOTE: Ignore the token.
7536          } else {          } else {
7537            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7538            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7448  sub _tree_construction_main ($) { Line 7735  sub _tree_construction_main ($) {
7735    ## TODO: script stuffs    ## TODO: script stuffs
7736  } # _tree_construct_main  } # _tree_construct_main
7737    
7738  sub set_inner_html ($$$) {  sub set_inner_html ($$$;$) {
7739    my $class = shift;    my $class = shift;
7740    my $node = shift;    my $node = shift;
7741    my $s = \$_[0];    my $s = \$_[0];
7742    my $onerror = $_[1];    my $onerror = $_[1];
7743      my $get_wrapper = $_[2] || sub ($) { return $_[0] };
7744    
7745    ## ISSUE: Should {confident} be true?    ## ISSUE: Should {confident} be true?
7746    
# Line 7471  sub set_inner_html ($$$) { Line 7759  sub set_inner_html ($$$) {
7759      }      }
7760    
7761      ## Step 3, 4, 5 # MUST      ## Step 3, 4, 5 # MUST
7762      $class->parse_string ($$s => $node, $onerror);      $class->parse_char_string ($$s => $node, $onerror, $get_wrapper);
7763    } elsif ($nt == 1) {    } elsif ($nt == 1) {
7764      ## TODO: If non-html element      ## TODO: If non-html element
7765    
7766      ## NOTE: Most of this code is copied from |parse_string|      ## NOTE: Most of this code is copied from |parse_string|
7767    
7768    ## TODO: Support for $get_wrapper
7769    
7770      ## Step 1 # MUST      ## Step 1 # MUST
7771      my $this_doc = $node->owner_document;      my $this_doc = $node->owner_document;
7772      my $doc = $this_doc->implementation->create_document;      my $doc = $this_doc->implementation->create_document;
# Line 7549  sub set_inner_html ($$$) { Line 7839  sub set_inner_html ($$$) {
7839      };      };
7840      $p->{prev_char} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];
7841      $p->{next_char} = -1;      $p->{next_char} = -1;
7842        
7843        $p->{read_until} = sub {
7844          ## TODO: ...
7845          return 0;
7846        }; # $p->{read_until};
7847    
7848      my $ponerror = $onerror || sub {      my $ponerror = $onerror || sub {
7849        my (%opt) = @_;        my (%opt) = @_;
7850        my $line = $opt{line};        my $line = $opt{line};

Legend:
Removed from v.1.156  
changed lines
  Added in v.1.174

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24