/[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.151 by wakaba, Sun Jun 8 05:08:42 2008 UTC revision 1.167 by wakaba, Sat Sep 13 09:02:28 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 443  sub parse_byte_stream ($$$$;$) { Line 456  sub parse_byte_stream ($$$$;$) {
456             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
457        if ($char_stream) {        if ($char_stream) {
458          $buffer->{buffer} = $byte_buffer;          $buffer->{buffer} = $byte_buffer;
459          !!!parse-error (type => 'sniffing:chardet', ## TODO: type name          !!!parse-error (type => 'sniffing:chardet',
460                          value => $charset_name,                          text => $charset_name,
461                          level => $self->{info_level},                          level => $self->{level}->{info},
462                            layer => 'encode',
463                          line => 1, column => 1);                          line => 1, column => 1);
464          $self->{confident} = 0;          $self->{confident} = 0;
465          last SNIFFING;          last SNIFFING;
# Line 454  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 466  sub parse_byte_stream ($$$$;$) { Line 480  sub parse_byte_stream ($$$$;$) {
480                                         allow_fallback => 1,                                         allow_fallback => 1,
481                                         byte_buffer => \$byte_buffer);                                         byte_buffer => \$byte_buffer);
482      $buffer->{buffer} = $byte_buffer;      $buffer->{buffer} = $byte_buffer;
483      !!!parse-error (type => 'sniffing:default', ## TODO: type name      !!!parse-error (type => 'sniffing:default',
484                      value => 'windows-1252',                      text => 'windows-1252',
485                      level => $self->{info_level},                      level => $self->{level}->{info},
486                      line => 1, column => 1);                      line => 1, column => 1,
487                        layer => 'encode');
488      $self->{confident} = 0;      $self->{confident} = 0;
489    } # SNIFFING    } # SNIFFING
490    
   $self->{input_encoding} = $charset->get_iana_name;  
491    if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {    if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
492      !!!parse-error (type => 'chardecode:fallback', ## TODO: type name      $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name?
493                      value => $self->{input_encoding},      !!!parse-error (type => 'chardecode:fallback',
494                      level => $self->{unsupported_level},                      #text => $self->{input_encoding},
495                      line => 1, column => 1);                      level => $self->{level}->{uncertain},
496                        line => 1, column => 1,
497                        layer => 'encode');
498    } elsif (not ($e_status &    } elsif (not ($e_status &
499                  Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {                  Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
500      !!!parse-error (type => 'chardecode:no error', ## TODO: type name      $self->{input_encoding} = $charset->get_iana_name;
501                      value => $self->{input_encoding},      !!!parse-error (type => 'chardecode:no error',
502                      level => $self->{unsupported_level},                      text => $self->{input_encoding},
503                      line => 1, column => 1);                      level => $self->{level}->{uncertain},
504                        line => 1, column => 1,
505                        layer => 'encode');
506      } else {
507        $self->{input_encoding} = $charset->get_iana_name;
508    }    }
509    
510    $self->{change_encoding} = sub {    $self->{change_encoding} = sub {
# Line 492  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 503  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 513  sub parse_byte_stream ($$$$;$) { Line 533  sub parse_byte_stream ($$$$;$) {
533        ## Step 2        ## Step 2
534        if (defined $self->{input_encoding} and        if (defined $self->{input_encoding} and
535            $self->{input_encoding} eq $charset_name) {            $self->{input_encoding} eq $charset_name) {
536          !!!parse-error (type => 'charset label:matching', ## TODO: type          !!!parse-error (type => 'charset label:matching',
537                          value => $charset_name,                          text => $charset_name,
538                          level => $self->{info_level});                          level => $self->{level}->{info});
539          $self->{confident} = 1;          $self->{confident} = 1;
540          return;          return;
541        }        }
542    
543        !!!parse-error (type => 'charset label detected:'.$self->{input_encoding}.        !!!parse-error (type => 'charset label detected',
544            ':'.$charset_name, level => 'w', token => $token);                        text => $self->{input_encoding},
545                          value => $charset_name,
546                          level => $self->{level}->{warn},
547                          token => $token);
548                
549        ## Step 3        ## Step 3
550        # if (can) {        # if (can) {
# Line 537  sub parse_byte_stream ($$$$;$) { Line 560  sub parse_byte_stream ($$$$;$) {
560    
561    my $char_onerror = sub {    my $char_onerror = sub {
562      my (undef, $type, %opt) = @_;      my (undef, $type, %opt) = @_;
563      !!!parse-error (%opt, type => $type,      !!!parse-error (layer => 'encode',
564                        %opt, type => $type,
565                      line => $self->{line}, column => $self->{column} + 1);                      line => $self->{line}, column => $self->{column} + 1);
566      if ($opt{octets}) {      if ($opt{octets}) {
567        ${$opt{octets}} = "\x{FFFD}"; # relacement character        ${$opt{octets}} = "\x{FFFD}"; # relacement character
568      }      }
569    };    };
570    $char_stream->onerror ($char_onerror);  
571      my $wrapped_char_stream = $get_wrapper->($char_stream);
572      $wrapped_char_stream->onerror ($char_onerror);
573    
574    my @args = @_; shift @args; # $s    my @args = @_; shift @args; # $s
575    my $return;    my $return;
576    try {    try {
577      $return = $self->parse_char_stream ($char_stream, @args);        $return = $self->parse_char_stream ($wrapped_char_stream, @args);  
578    } catch Whatpm::HTML::RestartParser with {    } catch Whatpm::HTML::RestartParser with {
579      ## NOTE: Invoked after {change_encoding}.      ## NOTE: Invoked after {change_encoding}.
580    
     $self->{input_encoding} = $charset->get_iana_name;  
581      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
582        !!!parse-error (type => 'chardecode:fallback', ## TODO: type name        $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name?
583                        value => $self->{input_encoding},        !!!parse-error (type => 'chardecode:fallback',
584                        level => $self->{unsupported_level},                        level => $self->{level}->{uncertain},
585                        line => 1, column => 1);                        #text => $self->{input_encoding},
586                          line => 1, column => 1,
587                          layer => 'encode');
588      } elsif (not ($e_status &      } elsif (not ($e_status &
589                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
590        !!!parse-error (type => 'chardecode:no error', ## TODO: type name        $self->{input_encoding} = $charset->get_iana_name;
591                        value => $self->{input_encoding},        !!!parse-error (type => 'chardecode:no error',
592                        level => $self->{unsupported_level},                        text => $self->{input_encoding},
593                        line => 1, column => 1);                        level => $self->{level}->{uncertain},
594                          line => 1, column => 1,
595                          layer => 'encode');
596        } else {
597          $self->{input_encoding} = $charset->get_iana_name;
598      }      }
599      $self->{confident} = 1;      $self->{confident} = 1;
600      $char_stream->onerror ($char_onerror);  
601      $return = $self->parse_char_stream ($char_stream, @args);      $wrapped_char_stream = $get_wrapper->($char_stream);
602        $wrapped_char_stream->onerror ($char_onerror);
603    
604        $return = $self->parse_char_stream ($wrapped_char_stream, @args);
605    };    };
606    return $return;    return $return;
607  } # parse_byte_stream  } # parse_byte_stream
# Line 581  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;
621    require utf8;    require utf8;
622    my $s = ref $_[0] ? $_[0] : \($_[0]);    my $s = ref $_[0] ? $_[0] : \($_[0]);
623    open my $input, '<' . (utf8::is_utf8 ($$s) ? ':utf8' : ''), $s;    open my $input, '<' . (utf8::is_utf8 ($$s) ? ':utf8' : ''), $s;
624      if ($_[3]) {
625        $input = $_[3]->($input);
626      }
627    return $self->parse_char_stream ($input, @_[1..$#_]);    return $self->parse_char_stream ($input, @_[1..$#_]);
628  } # parse_char_string  } # parse_char_string
629  *parse_string = \&parse_char_string;  *parse_string = \&parse_char_string; ## NOTE: Alias for backward compatibility.
630    
631  sub parse_char_stream ($$$;$) {  sub parse_char_stream ($$$;$) {
632    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
# Line 662  sub parse_char_stream ($$$;$) { Line 700  sub parse_char_stream ($$$;$) {
700                0x10FFFE => 1, 0x10FFFF => 1,                0x10FFFE => 1, 0x10FFFF => 1,
701               }->{$self->{next_char}}) {               }->{$self->{next_char}}) {
702        !!!cp ('j5');        !!!cp ('j5');
703        !!!parse-error (type => 'control char', level => $self->{must_level});        if ($self->{next_char} < 0x10000) {
704  ## TODO: error type documentation          !!!parse-error (type => 'control char',
705                            text => (sprintf 'U+%04X', $self->{next_char}));
706          } else {
707            !!!parse-error (type => 'control char',
708                            text => (sprintf 'U-%08X', $self->{next_char}));
709          }
710      }      }
711    };    };
712    $self->{prev_char} = [-1, -1, -1];    $self->{prev_char} = [-1, -1, -1];
# Line 692  sub parse_char_stream ($$$;$) { Line 735  sub parse_char_stream ($$$;$) {
735  sub new ($) {  sub new ($) {
736    my $class = shift;    my $class = shift;
737    my $self = bless {    my $self = bless {
738      must_level => 'm',      level => {must => 'm',
739      should_level => 's',                should => 's',
740      good_level => 'w',                warn => 'w',
741      warn_level => 'w',                info => 'i',
742      info_level => 'i',                uncertain => 'u'},
     unsupported_level => 'u',  
743    }, $class;    }, $class;
744    $self->{set_next_char} = sub {    $self->{set_next_char} = sub {
745      $self->{next_char} = -1;      $self->{next_char} = -1;
# Line 761  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STAT Line 803  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STAT
803  sub BOGUS_DOCTYPE_STATE () { 32 }  sub BOGUS_DOCTYPE_STATE () { 32 }
804  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }
805  sub SELF_CLOSING_START_TAG_STATE () { 34 }  sub SELF_CLOSING_START_TAG_STATE () { 34 }
806  sub CDATA_BLOCK_STATE () { 35 }  sub CDATA_SECTION_STATE () { 35 }
807    sub MD_HYPHEN_STATE () { 36 } # "markup declaration open state" in the spec
808    sub MD_DOCTYPE_STATE () { 37 } # "markup declaration open state" in the spec
809    sub MD_CDATA_STATE () { 38 } # "markup declaration open state" in the spec
810    sub CDATA_PCDATA_CLOSE_TAG_STATE () { 39 } # "close tag open state" in the spec
811    sub CDATA_SECTION_MSE1_STATE () { 40 } # "CDATA section state" in the spec
812    sub CDATA_SECTION_MSE2_STATE () { 41 } # "CDATA section state" in the spec
813    sub PUBLIC_STATE () { 42 } # "after DOCTYPE name state" in the spec
814    sub SYSTEM_STATE () { 43 } # "after DOCTYPE name state" in the spec
815    sub ENTITY_STATE () { 44 } # "consume a character reference" in the spec
816    
817  sub DOCTYPE_TOKEN () { 1 }  sub DOCTYPE_TOKEN () { 1 }
818  sub COMMENT_TOKEN () { 2 }  sub COMMENT_TOKEN () { 2 }
# Line 814  sub IN_COLUMN_GROUP_IM () { 0b10 } Line 865  sub IN_COLUMN_GROUP_IM () { 0b10 }
865  sub _initialize_tokenizer ($) {  sub _initialize_tokenizer ($) {
866    my $self = shift;    my $self = shift;
867    $self->{state} = DATA_STATE; # MUST    $self->{state} = DATA_STATE; # MUST
868      #$self->{state_keyword}; # initialized when used
869    $self->{content_model} = PCDATA_CONTENT_MODEL; # be    $self->{content_model} = PCDATA_CONTENT_MODEL; # be
870    undef $self->{current_token}; # start tag, end tag, comment, or DOCTYPE    undef $self->{current_token};
871    undef $self->{current_attribute};    undef $self->{current_attribute};
872    undef $self->{last_emitted_start_tag_name};    undef $self->{last_emitted_start_tag_name};
873    undef $self->{last_attribute_value_state};    undef $self->{last_attribute_value_state};
# Line 889  sub _get_next_token ($) { Line 941  sub _get_next_token ($) {
941          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA
942              not $self->{escape}) {              not $self->{escape}) {
943            !!!cp (1);            !!!cp (1);
944            $self->{state} = ENTITY_DATA_STATE;            ## NOTE: In the spec, the tokenizer is switched to the
945              ## "entity data state".  In this implementation, the tokenizer
946              ## is switched to the |ENTITY_STATE|, which is an implementation
947              ## of the "consume a character reference" algorithm.
948              #$self->{state} = ENTITY_DATA_STATE;
949              $self->{entity_in_attr} = 0;
950              $self->{entity_additional} = -1;
951              $self->{state} = ENTITY_STATE;
952            !!!next-input-character;            !!!next-input-character;
953            redo A;            redo A;
954          } else {          } else {
# Line 960  sub _get_next_token ($) { Line 1019  sub _get_next_token ($) {
1019    
1020        redo A;        redo A;
1021      } elsif ($self->{state} == ENTITY_DATA_STATE) {      } elsif ($self->{state} == ENTITY_DATA_STATE) {
       ## (cannot happen in CDATA state)  
   
1022        my ($l, $c) = ($self->{line_prev}, $self->{column_prev});        my ($l, $c) = ($self->{line_prev}, $self->{column_prev});
1023          
1024        my $token = $self->_tokenize_attempt_to_consume_an_entity (0, -1);        my $token = $self->{entity_return};
1025    
1026        $self->{state} = DATA_STATE;        $self->{state} = DATA_STATE;
1027        # next-input-character is already done        # next-input-character is already done
# Line 1076  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 1185  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 1356  sub _get_next_token ($) { Line 1433  sub _get_next_token ($) {
1433          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
1434              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
1435            !!!cp (57);            !!!cp (57);
1436            !!!parse-error (type => 'duplicate attribute:'.$self->{current_attribute}->{name}, line => $self->{current_attribute}->{line}, column => $self->{current_attribute}->{column});            !!!parse-error (type => 'duplicate attribute', text => $self->{current_attribute}->{name}, line => $self->{current_attribute}->{line}, column => $self->{current_attribute}->{column});
1437            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{current_attribute} # MUST
1438          } else {          } else {
1439            !!!cp (58);            !!!cp (58);
# Line 1527  sub _get_next_token ($) { Line 1604  sub _get_next_token ($) {
1604    
1605          redo A;          redo A;
1606        } else {        } else {
1607          !!!cp (82);          if ($self->{next_char} == 0x0022 or # "
1608                $self->{next_char} == 0x0027) { # '
1609              !!!cp (78);
1610              !!!parse-error (type => 'bad attribute name');
1611            } else {
1612              !!!cp (82);
1613            }
1614          $self->{current_attribute}          $self->{current_attribute}
1615              = {name => chr ($self->{next_char}),              = {name => chr ($self->{next_char}),
1616                 value => '',                 value => '',
# Line 1562  sub _get_next_token ($) { Line 1645  sub _get_next_token ($) {
1645          !!!next-input-character;          !!!next-input-character;
1646          redo A;          redo A;
1647        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1648            !!!parse-error (type => 'empty unquoted attribute value');
1649          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1650            !!!cp (87);            !!!cp (87);
1651            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
# Line 1627  sub _get_next_token ($) { Line 1711  sub _get_next_token ($) {
1711        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1712          !!!cp (96);          !!!cp (96);
1713          $self->{last_attribute_value_state} = $self->{state};          $self->{last_attribute_value_state} = $self->{state};
1714          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## NOTE: In the spec, the tokenizer is switched to the
1715            ## "entity in attribute value state".  In this implementation, the
1716            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1717            ## implementation of the "consume a character reference" algorithm.
1718            #$self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;
1719            $self->{entity_in_attr} = 1;
1720            $self->{entity_additional} = 0x0022; # "
1721            $self->{state} = ENTITY_STATE;
1722          !!!next-input-character;          !!!next-input-character;
1723          redo A;          redo A;
1724        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
# Line 1669  sub _get_next_token ($) { Line 1760  sub _get_next_token ($) {
1760        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1761          !!!cp (102);          !!!cp (102);
1762          $self->{last_attribute_value_state} = $self->{state};          $self->{last_attribute_value_state} = $self->{state};
1763          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## NOTE: In the spec, the tokenizer is switched to the
1764            ## "entity in attribute value state".  In this implementation, the
1765            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1766            ## implementation of the "consume a character reference" algorithm.
1767            #$self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;
1768            $self->{entity_in_attr} = 1;
1769            $self->{entity_additional} = 0x0027; # '
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 1715  sub _get_next_token ($) { Line 1813  sub _get_next_token ($) {
1813        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1814          !!!cp (108);          !!!cp (108);
1815          $self->{last_attribute_value_state} = $self->{state};          $self->{last_attribute_value_state} = $self->{state};
1816          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## NOTE: In the spec, the tokenizer is switched to the
1817            ## "entity in attribute value state".  In this implementation, the
1818            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1819            ## implementation of the "consume a character reference" algorithm.
1820            #$self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;
1821            $self->{entity_in_attr} = 1;
1822            $self->{entity_additional} = -1;
1823            $self->{state} = ENTITY_STATE;
1824          !!!next-input-character;          !!!next-input-character;
1825          redo A;          redo A;
1826        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
# Line 1780  sub _get_next_token ($) { Line 1885  sub _get_next_token ($) {
1885          redo A;          redo A;
1886        }        }
1887      } elsif ($self->{state} == ENTITY_IN_ATTRIBUTE_VALUE_STATE) {      } elsif ($self->{state} == ENTITY_IN_ATTRIBUTE_VALUE_STATE) {
1888        my $token = $self->_tokenize_attempt_to_consume_an_entity        my $token = $self->{entity_return};
           (1,  
            $self->{last_attribute_value_state}  
              == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE ? 0x0022 : # "  
            $self->{last_attribute_value_state}  
              == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE ? 0x0027 : # '  
            -1);  
1889    
1890        unless (defined $token) {        unless (defined $token) {
1891          !!!cp (117);          !!!cp (117);
# Line 1920  sub _get_next_token ($) { Line 2019  sub _get_next_token ($) {
2019        }        }
2020      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {
2021        ## (only happen if PCDATA state)        ## (only happen if PCDATA state)
         
       ## NOTE: Set by the previous state  
       #my $token = {type => COMMENT_TOKEN, data => ''};  
   
       BC: {  
         if ($self->{next_char} == 0x003E) { # >  
           !!!cp (124);  
           $self->{state} = DATA_STATE;  
           !!!next-input-character;  
   
           !!!emit ($self->{current_token}); # comment  
2022    
2023            redo A;        ## NOTE: Unlike spec's "bogus comment state", this implementation
2024          } elsif ($self->{next_char} == -1) {        ## consumes characters one-by-one basis.
2025            !!!cp (125);        
2026            $self->{state} = DATA_STATE;        if ($self->{next_char} == 0x003E) { # >
2027            ## reconsume          !!!cp (124);
2028            $self->{state} = DATA_STATE;
2029            !!!emit ($self->{current_token}); # comment          !!!next-input-character;
2030    
2031            redo A;          !!!emit ($self->{current_token}); # comment
2032          } else {          redo A;
2033            !!!cp (126);        } elsif ($self->{next_char} == -1) {
2034            $self->{current_token}->{data} .= chr ($self->{next_char}); # comment          !!!cp (125);
2035            !!!next-input-character;          $self->{state} = DATA_STATE;
2036            redo BC;          ## reconsume
         }  
       } # BC  
2037    
2038        die "$0: _get_next_token: unexpected case [BC]";          !!!emit ($self->{current_token}); # comment
2039            redo A;
2040          } else {
2041            !!!cp (126);
2042            $self->{current_token}->{data} .= chr ($self->{next_char}); # comment
2043            ## Stay in the state.
2044            !!!next-input-character;
2045            redo A;
2046          }
2047      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {
2048        ## (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};  
2049                
2050        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
2051            !!!cp (133);
2052            $self->{state} = MD_HYPHEN_STATE;
2053          !!!next-input-character;          !!!next-input-character;
2054          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);  
         }  
2055        } elsif ($self->{next_char} == 0x0044 or # D        } elsif ($self->{next_char} == 0x0044 or # D
2056                 $self->{next_char} == 0x0064) { # d                 $self->{next_char} == 0x0064) { # d
2057            ## ASCII case-insensitive.
2058            !!!cp (130);
2059            $self->{state} = MD_DOCTYPE_STATE;
2060            $self->{state_keyword} = chr $self->{next_char};
2061          !!!next-input-character;          !!!next-input-character;
2062          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);  
         }  
2063        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and
2064                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and
2065                 $self->{next_char} == 0x005B) { # [                 $self->{next_char} == 0x005B) { # [
2066            !!!cp (135.4);                
2067            $self->{state} = MD_CDATA_STATE;
2068            $self->{state_keyword} = '[';
2069          !!!next-input-character;          !!!next-input-character;
2070          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);  
         }  
2071        } else {        } else {
2072          !!!cp (136);          !!!cp (136);
2073        }        }
2074    
2075        !!!parse-error (type => 'bogus comment');        !!!parse-error (type => 'bogus comment',
2076        $self->{next_char} = shift @next_char;                        line => $self->{line_prev},
2077        !!!back-next-input-character (@next_char);                        column => $self->{column_prev} - 1);
2078          ## Reconsume.
2079        $self->{state} = BOGUS_COMMENT_STATE;        $self->{state} = BOGUS_COMMENT_STATE;
2080        $self->{current_token} = {type => COMMENT_TOKEN, data => '',        $self->{current_token} = {type => COMMENT_TOKEN, data => '',
2081                                  line => $l, column => $c,                                  line => $self->{line_prev},
2082                                    column => $self->{column_prev} - 1,
2083                                 };                                 };
2084        redo A;        redo A;
2085              } elsif ($self->{state} == MD_HYPHEN_STATE) {
2086        ## ISSUE: typos in spec: chacacters, is is a parse error        if ($self->{next_char} == 0x002D) { # -
2087        ## 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);
2088            $self->{current_token} = {type => COMMENT_TOKEN, data => '',
2089                                      line => $self->{line_prev},
2090                                      column => $self->{column_prev} - 2,
2091                                     };
2092            $self->{state} = COMMENT_START_STATE;
2093            !!!next-input-character;
2094            redo A;
2095          } else {
2096            !!!cp (128);
2097            !!!parse-error (type => 'bogus comment',
2098                            line => $self->{line_prev},
2099                            column => $self->{column_prev} - 2);
2100            $self->{state} = BOGUS_COMMENT_STATE;
2101            ## Reconsume.
2102            $self->{current_token} = {type => COMMENT_TOKEN,
2103                                      data => '-',
2104                                      line => $self->{line_prev},
2105                                      column => $self->{column_prev} - 2,
2106                                     };
2107            redo A;
2108          }
2109        } elsif ($self->{state} == MD_DOCTYPE_STATE) {
2110          ## ASCII case-insensitive.
2111          if ($self->{next_char} == [
2112                undef,
2113                0x004F, # O
2114                0x0043, # C
2115                0x0054, # T
2116                0x0059, # Y
2117                0x0050, # P
2118              ]->[length $self->{state_keyword}] or
2119              $self->{next_char} == [
2120                undef,
2121                0x006F, # o
2122                0x0063, # c
2123                0x0074, # t
2124                0x0079, # y
2125                0x0070, # p
2126              ]->[length $self->{state_keyword}]) {
2127            !!!cp (131);
2128            ## Stay in the state.
2129            $self->{state_keyword} .= chr $self->{next_char};
2130            !!!next-input-character;
2131            redo A;
2132          } elsif ((length $self->{state_keyword}) == 6 and
2133                   ($self->{next_char} == 0x0045 or # E
2134                    $self->{next_char} == 0x0065)) { # e
2135            !!!cp (129);
2136            $self->{state} = DOCTYPE_STATE;
2137            $self->{current_token} = {type => DOCTYPE_TOKEN,
2138                                      quirks => 1,
2139                                      line => $self->{line_prev},
2140                                      column => $self->{column_prev} - 7,
2141                                     };
2142            !!!next-input-character;
2143            redo A;
2144          } else {
2145            !!!cp (132);        
2146            !!!parse-error (type => 'bogus comment',
2147                            line => $self->{line_prev},
2148                            column => $self->{column_prev} - 1 - length $self->{state_keyword});
2149            $self->{state} = BOGUS_COMMENT_STATE;
2150            ## Reconsume.
2151            $self->{current_token} = {type => COMMENT_TOKEN,
2152                                      data => $self->{state_keyword},
2153                                      line => $self->{line_prev},
2154                                      column => $self->{column_prev} - 1 - length $self->{state_keyword},
2155                                     };
2156            redo A;
2157          }
2158        } elsif ($self->{state} == MD_CDATA_STATE) {
2159          if ($self->{next_char} == {
2160                '[' => 0x0043, # C
2161                '[C' => 0x0044, # D
2162                '[CD' => 0x0041, # A
2163                '[CDA' => 0x0054, # T
2164                '[CDAT' => 0x0041, # A
2165              }->{$self->{state_keyword}}) {
2166            !!!cp (135.1);
2167            ## Stay in the state.
2168            $self->{state_keyword} .= chr $self->{next_char};
2169            !!!next-input-character;
2170            redo A;
2171          } elsif ($self->{state_keyword} eq '[CDATA' and
2172                   $self->{next_char} == 0x005B) { # [
2173            !!!cp (135.2);
2174            $self->{current_token} = {type => CHARACTER_TOKEN,
2175                                      data => '',
2176                                      line => $self->{line_prev},
2177                                      column => $self->{column_prev} - 7};
2178            $self->{state} = CDATA_SECTION_STATE;
2179            !!!next-input-character;
2180            redo A;
2181          } else {
2182            !!!cp (135.3);
2183            !!!parse-error (type => 'bogus comment',
2184                            line => $self->{line_prev},
2185                            column => $self->{column_prev} - 1 - length $self->{state_keyword});
2186            $self->{state} = BOGUS_COMMENT_STATE;
2187            ## Reconsume.
2188            $self->{current_token} = {type => COMMENT_TOKEN,
2189                                      data => $self->{state_keyword},
2190                                      line => $self->{line_prev},
2191                                      column => $self->{column_prev} - 1 - length $self->{state_keyword},
2192                                     };
2193            redo A;
2194          }
2195      } elsif ($self->{state} == COMMENT_START_STATE) {      } elsif ($self->{state} == COMMENT_START_STATE) {
2196        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
2197          !!!cp (137);          !!!cp (137);
# Line 2349  sub _get_next_token ($) { Line 2458  sub _get_next_token ($) {
2458          redo A;          redo A;
2459        } elsif ($self->{next_char} == 0x0050 or # P        } elsif ($self->{next_char} == 0x0050 or # P
2460                 $self->{next_char} == 0x0070) { # p                 $self->{next_char} == 0x0070) { # p
2461            $self->{state} = PUBLIC_STATE;
2462            $self->{state_keyword} = chr $self->{next_char};
2463          !!!next-input-character;          !!!next-input-character;
2464          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);  
         }  
   
         #  
2465        } elsif ($self->{next_char} == 0x0053 or # S        } elsif ($self->{next_char} == 0x0053 or # S
2466                 $self->{next_char} == 0x0073) { # s                 $self->{next_char} == 0x0073) { # s
2467            $self->{state} = SYSTEM_STATE;
2468            $self->{state_keyword} = chr $self->{next_char};
2469          !!!next-input-character;          !!!next-input-character;
2470          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);  
         }  
   
         #  
2471        } else {        } else {
2472          !!!cp (180);          !!!cp (180);
2473            !!!parse-error (type => 'string after DOCTYPE name');
2474            $self->{current_token}->{quirks} = 1;
2475    
2476            $self->{state} = BOGUS_DOCTYPE_STATE;
2477          !!!next-input-character;          !!!next-input-character;
2478          #          redo A;
2479        }        }
2480        } elsif ($self->{state} == PUBLIC_STATE) {
2481          ## ASCII case-insensitive
2482          if ($self->{next_char} == [
2483                undef,
2484                0x0055, # U
2485                0x0042, # B
2486                0x004C, # L
2487                0x0049, # I
2488              ]->[length $self->{state_keyword}] or
2489              $self->{next_char} == [
2490                undef,
2491                0x0075, # u
2492                0x0062, # b
2493                0x006C, # l
2494                0x0069, # i
2495              ]->[length $self->{state_keyword}]) {
2496            !!!cp (175);
2497            ## Stay in the state.
2498            $self->{state_keyword} .= chr $self->{next_char};
2499            !!!next-input-character;
2500            redo A;
2501          } elsif ((length $self->{state_keyword}) == 5 and
2502                   ($self->{next_char} == 0x0043 or # C
2503                    $self->{next_char} == 0x0063)) { # c
2504            !!!cp (168);
2505            $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
2506            !!!next-input-character;
2507            redo A;
2508          } else {
2509            !!!cp (169);
2510            !!!parse-error (type => 'string after DOCTYPE name',
2511                            line => $self->{line_prev},
2512                            column => $self->{column_prev} + 1 - length $self->{state_keyword});
2513            $self->{current_token}->{quirks} = 1;
2514    
2515        !!!parse-error (type => 'string after DOCTYPE name');          $self->{state} = BOGUS_DOCTYPE_STATE;
2516        $self->{current_token}->{quirks} = 1;          ## Reconsume.
2517            redo A;
2518          }
2519        } elsif ($self->{state} == SYSTEM_STATE) {
2520          ## ASCII case-insensitive
2521          if ($self->{next_char} == [
2522                undef,
2523                0x0059, # Y
2524                0x0053, # S
2525                0x0054, # T
2526                0x0045, # E
2527              ]->[length $self->{state_keyword}] or
2528              $self->{next_char} == [
2529                undef,
2530                0x0079, # y
2531                0x0073, # s
2532                0x0074, # t
2533                0x0065, # e
2534              ]->[length $self->{state_keyword}]) {
2535            !!!cp (170);
2536            ## Stay in the state.
2537            $self->{state_keyword} .= chr $self->{next_char};
2538            !!!next-input-character;
2539            redo A;
2540          } elsif ((length $self->{state_keyword}) == 5 and
2541                   ($self->{next_char} == 0x004D or # M
2542                    $self->{next_char} == 0x006D)) { # m
2543            !!!cp (171);
2544            $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2545            !!!next-input-character;
2546            redo A;
2547          } else {
2548            !!!cp (172);
2549            !!!parse-error (type => 'string after DOCTYPE name',
2550                            line => $self->{line_prev},
2551                            column => $self->{column_prev} + 1 - length $self->{state_keyword});
2552            $self->{current_token}->{quirks} = 1;
2553    
2554        $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2555        # next-input-character is already done          ## Reconsume.
2556        redo A;          redo A;
2557          }
2558      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {
2559        if ({        if ({
2560              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
# Line 2667  sub _get_next_token ($) { Line 2787  sub _get_next_token ($) {
2787          redo A;          redo A;
2788        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2789          !!!cp (208);          !!!cp (208);
2790          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2791    
2792          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2793          !!!next-input-character;          !!!next-input-character;
# Line 2703  sub _get_next_token ($) { Line 2823  sub _get_next_token ($) {
2823          redo A;          redo A;
2824        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2825          !!!cp (212);          !!!cp (212);
2826          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2827    
2828          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2829          !!!next-input-character;          !!!next-input-character;
# Line 2791  sub _get_next_token ($) { Line 2911  sub _get_next_token ($) {
2911          !!!next-input-character;          !!!next-input-character;
2912          redo A;          redo A;
2913        }        }
2914      } elsif ($self->{state} == CDATA_BLOCK_STATE) {      } elsif ($self->{state} == CDATA_SECTION_STATE) {
2915        my $s = '';        ## NOTE: "CDATA section state" in the state is jointly implemented
2916          ## by three states, |CDATA_SECTION_STATE|, |CDATA_SECTION_MSE1_STATE|,
2917          ## and |CDATA_SECTION_MSE2_STATE|.
2918                
2919        my ($l, $c) = ($self->{line}, $self->{column});        if ($self->{next_char} == 0x005D) { # ]
2920            !!!cp (221.1);
2921            $self->{state} = CDATA_SECTION_MSE1_STATE;
2922            !!!next-input-character;
2923            redo A;
2924          } elsif ($self->{next_char} == -1) {
2925            $self->{state} = DATA_STATE;
2926            !!!next-input-character;
2927            if (length $self->{current_token}->{data}) { # character
2928              !!!cp (221.2);
2929              !!!emit ($self->{current_token}); # character
2930            } else {
2931              !!!cp (221.3);
2932              ## No token to emit. $self->{current_token} is discarded.
2933            }        
2934            redo A;
2935          } else {
2936            !!!cp (221.4);
2937            $self->{current_token}->{data} .= chr $self->{next_char};
2938            ## Stay in the state.
2939            !!!next-input-character;
2940            redo A;
2941          }
2942    
2943        CS: while ($self->{next_char} != -1) {        ## ISSUE: "text tokens" in spec.
2944          if ($self->{next_char} == 0x005D) { # ]      } elsif ($self->{state} == CDATA_SECTION_MSE1_STATE) {
2945            !!!next-input-character;        if ($self->{next_char} == 0x005D) { # ]
2946            if ($self->{next_char} == 0x005D) { # ]          !!!cp (221.5);
2947              !!!next-input-character;          $self->{state} = CDATA_SECTION_MSE2_STATE;
2948              MDC: {          !!!next-input-character;
2949                if ($self->{next_char} == 0x003E) { # >          redo A;
2950                  !!!cp (221.1);        } else {
2951                  !!!next-input-character;          !!!cp (221.6);
2952                  last CS;          $self->{current_token}->{data} .= ']';
2953                } elsif ($self->{next_char} == 0x005D) { # ]          $self->{state} = CDATA_SECTION_STATE;
2954                  !!!cp (221.2);          ## Reconsume.
2955                  $s .= ']';          redo A;
2956                  !!!next-input-character;        }
2957                  redo MDC;      } elsif ($self->{state} == CDATA_SECTION_MSE2_STATE) {
2958                } else {        if ($self->{next_char} == 0x003E) { # >
2959                  !!!cp (221.3);          $self->{state} = DATA_STATE;
2960                  $s .= ']]';          !!!next-input-character;
2961                  #          if (length $self->{current_token}->{data}) { # character
2962                }            !!!cp (221.7);
2963              } # MDC            !!!emit ($self->{current_token}); # character
           } else {  
             !!!cp (221.4);  
             $s .= ']';  
             #  
           }  
2964          } else {          } else {
2965            !!!cp (221.5);            !!!cp (221.8);
2966            #            ## No token to emit. $self->{current_token} is discarded.
2967          }          }
2968          $s .= chr $self->{next_char};          redo A;
2969          } elsif ($self->{next_char} == 0x005D) { # ]
2970            !!!cp (221.9); # character
2971            $self->{current_token}->{data} .= ']'; ## Add first "]" of "]]]".
2972            ## Stay in the state.
2973          !!!next-input-character;          !!!next-input-character;
2974        } # CS          redo A;
   
       $self->{state} = DATA_STATE;  
       ## next-input-character done or EOF, which is reconsumed.  
   
       if (length $s) {  
         !!!cp (221.6);  
         !!!emit ({type => CHARACTER_TOKEN, data => $s,  
                   line => $l, column => $c});  
2975        } else {        } else {
2976          !!!cp (221.7);          !!!cp (221.11);
2977            $self->{current_token}->{data} .= ']]'; # character
2978            $self->{state} = CDATA_SECTION_STATE;
2979            ## Reconsume.
2980            redo A;
2981        }        }
2982    
2983        redo A;      } elsif ($self->{state} == ENTITY_STATE) {
2984          my $in_attr = $self->{entity_in_attr};
2985        ## ISSUE: "text tokens" in spec.        my $additional = $self->{entity_additional};
       ## TODO: Streaming support  
     } else {  
       die "$0: $self->{state}: Unknown state";  
     }  
   } # A    
   
   die "$0: _get_next_token: unexpected case";  
 } # _get_next_token  
   
 sub _tokenize_attempt_to_consume_an_entity ($$$) {  
   my ($self, $in_attr, $additional) = @_;  
2986    
2987    my ($l, $c) = ($self->{line_prev}, $self->{column_prev});    my ($l, $c) = ($self->{line_prev}, $self->{column_prev});
2988    
# Line 2866  sub _tokenize_attempt_to_consume_an_enti Line 2994  sub _tokenize_attempt_to_consume_an_enti
2994      !!!cp (1001);      !!!cp (1001);
2995      ## Don't consume      ## Don't consume
2996      ## No error      ## No error
2997      return undef;      $self->{entity_return} = undef;
2998        $self->{state} = $self->{entity_in_attr} ? ENTITY_IN_ATTRIBUTE_VALUE_STATE : ENTITY_DATA_STATE;
2999        redo A;
3000    } elsif ($self->{next_char} == 0x0023) { # #    } elsif ($self->{next_char} == 0x0023) { # #
3001      !!!next-input-character;      !!!next-input-character;
3002      if ($self->{next_char} == 0x0078 or # x      if ($self->{next_char} == 0x0078 or # x
# Line 2901  sub _tokenize_attempt_to_consume_an_enti Line 3031  sub _tokenize_attempt_to_consume_an_enti
3031            !!!parse-error (type => 'bare hcro', line => $l, column => $c);            !!!parse-error (type => 'bare hcro', line => $l, column => $c);
3032            !!!back-next-input-character ($x_char, $self->{next_char});            !!!back-next-input-character ($x_char, $self->{next_char});
3033            $self->{next_char} = 0x0023; # #            $self->{next_char} = 0x0023; # #
3034            return undef;            $self->{entity_return} = undef;
3035              $self->{state} = $self->{entity_in_attr} ? ENTITY_IN_ATTRIBUTE_VALUE_STATE : ENTITY_DATA_STATE;
3036              redo A;
3037          } elsif ($self->{next_char} == 0x003B) { # ;          } elsif ($self->{next_char} == 0x003B) { # ;
3038            !!!cp (1006);            !!!cp (1006);
3039            !!!next-input-character;            !!!next-input-character;
# Line 2912  sub _tokenize_attempt_to_consume_an_enti Line 3044  sub _tokenize_attempt_to_consume_an_enti
3044    
3045          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3046            !!!cp (1008);            !!!cp (1008);
3047            !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
3048                              text => (sprintf 'U+%04X', $code),
3049                              line => $l, column => $c);
3050            $code = 0xFFFD;            $code = 0xFFFD;
3051          } elsif ($code > 0x10FFFF) {          } elsif ($code > 0x10FFFF) {
3052            !!!cp (1009);            !!!cp (1009);
3053            !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
3054                              text => (sprintf 'U-%08X', $code),
3055                              line => $l, column => $c);
3056            $code = 0xFFFD;            $code = 0xFFFD;
3057          } elsif ($code == 0x000D) {          } elsif ($code == 0x000D) {
3058            !!!cp (1010);            !!!cp (1010);
# Line 2924  sub _tokenize_attempt_to_consume_an_enti Line 3060  sub _tokenize_attempt_to_consume_an_enti
3060            $code = 0x000A;            $code = 0x000A;
3061          } elsif (0x80 <= $code and $code <= 0x9F) {          } elsif (0x80 <= $code and $code <= 0x9F) {
3062            !!!cp (1011);            !!!cp (1011);
3063            !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);            !!!parse-error (type => 'C1 character reference', text => (sprintf 'U+%04X', $code), line => $l, column => $c);
3064            $code = $c1_entity_char->{$code};            $code = $c1_entity_char->{$code};
3065          }          }
3066    
3067          return {type => CHARACTER_TOKEN, data => chr $code,          $self->{entity_return} = {type => CHARACTER_TOKEN, data => chr $code,
3068                  has_reference => 1,                  has_reference => 1,
3069                  line => $l, column => $c,                  line => $l, column => $c,
3070                 };                 };
3071            $self->{state} = $self->{entity_in_attr} ? ENTITY_IN_ATTRIBUTE_VALUE_STATE : ENTITY_DATA_STATE;
3072            redo A;
3073        } # X        } # X
3074      } elsif (0x0030 <= $self->{next_char} and      } elsif (0x0030 <= $self->{next_char} and
3075               $self->{next_char} <= 0x0039) { # 0..9               $self->{next_char} <= 0x0039) { # 0..9
# Line 2957  sub _tokenize_attempt_to_consume_an_enti Line 3095  sub _tokenize_attempt_to_consume_an_enti
3095    
3096        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3097          !!!cp (1015);          !!!cp (1015);
3098          !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3099                            text => (sprintf 'U+%04X', $code),
3100                            line => $l, column => $c);
3101          $code = 0xFFFD;          $code = 0xFFFD;
3102        } elsif ($code > 0x10FFFF) {        } elsif ($code > 0x10FFFF) {
3103          !!!cp (1016);          !!!cp (1016);
3104          !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3105                            text => (sprintf 'U-%08X', $code),
3106                            line => $l, column => $c);
3107          $code = 0xFFFD;          $code = 0xFFFD;
3108        } elsif ($code == 0x000D) {        } elsif ($code == 0x000D) {
3109          !!!cp (1017);          !!!cp (1017);
3110          !!!parse-error (type => 'CR character reference', line => $l, column => $c);          !!!parse-error (type => 'CR character reference',
3111                            line => $l, column => $c);
3112          $code = 0x000A;          $code = 0x000A;
3113        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
3114          !!!cp (1018);          !!!cp (1018);
3115          !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'C1 character reference',
3116                            text => (sprintf 'U+%04X', $code),
3117                            line => $l, column => $c);
3118          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
3119        }        }
3120                
3121        return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1,        $self->{entity_return} = {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1,
3122                line => $l, column => $c,                line => $l, column => $c,
3123               };               };
3124          $self->{state} = $self->{entity_in_attr} ? ENTITY_IN_ATTRIBUTE_VALUE_STATE : ENTITY_DATA_STATE;
3125          redo A;
3126      } else {      } else {
3127        !!!cp (1019);        !!!cp (1019);
3128        !!!parse-error (type => 'bare nero', line => $l, column => $c);        !!!parse-error (type => 'bare nero', line => $l, column => $c);
3129        !!!back-next-input-character ($self->{next_char});        !!!back-next-input-character ($self->{next_char});
3130        $self->{next_char} = 0x0023; # #        $self->{next_char} = 0x0023; # #
3131        return undef;        $self->{entity_return} = undef;
3132          $self->{state} = $self->{entity_in_attr} ? ENTITY_IN_ATTRIBUTE_VALUE_STATE : ENTITY_DATA_STATE;
3133          redo A;
3134      }      }
3135    } elsif ((0x0041 <= $self->{next_char} and    } elsif ((0x0041 <= $self->{next_char} and
3136              $self->{next_char} <= 0x005A) or              $self->{next_char} <= 0x005A) or
# Line 3028  sub _tokenize_attempt_to_consume_an_enti Line 3177  sub _tokenize_attempt_to_consume_an_enti
3177            
3178      if ($match > 0) {      if ($match > 0) {
3179        !!!cp (1023);        !!!cp (1023);
3180        return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,        $self->{entity_return} = {type => CHARACTER_TOKEN, data => $value, has_reference => 1,
3181                line => $l, column => $c,                line => $l, column => $c,
3182               };               };
3183          $self->{state} = $self->{entity_in_attr} ? ENTITY_IN_ATTRIBUTE_VALUE_STATE : ENTITY_DATA_STATE;
3184          redo A;
3185      } elsif ($match < 0) {      } elsif ($match < 0) {
3186        !!!parse-error (type => 'no refc', line => $l, column => $c);        !!!parse-error (type => 'no refc', line => $l, column => $c);
3187        if ($in_attr and $match < -1) {        if ($in_attr and $match < -1) {
3188          !!!cp (1024);          !!!cp (1024);
3189          return {type => CHARACTER_TOKEN, data => '&'.$entity_name,          $self->{entity_return} = {type => CHARACTER_TOKEN, data => '&'.$entity_name,
3190                  line => $l, column => $c,                  line => $l, column => $c,
3191                 };                 };
3192            $self->{state} = $self->{entity_in_attr} ? ENTITY_IN_ATTRIBUTE_VALUE_STATE : ENTITY_DATA_STATE;
3193            redo A;
3194        } else {        } else {
3195          !!!cp (1025);          !!!cp (1025);
3196          return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,          $self->{entity_return} = {type => CHARACTER_TOKEN, data => $value, has_reference => 1,
3197                  line => $l, column => $c,                  line => $l, column => $c,
3198                 };                 };
3199            $self->{state} = $self->{entity_in_attr} ? ENTITY_IN_ATTRIBUTE_VALUE_STATE : ENTITY_DATA_STATE;
3200            redo A;
3201        }        }
3202      } else {      } else {
3203        !!!cp (1026);        !!!cp (1026);
3204        !!!parse-error (type => 'bare ero', line => $l, column => $c);        !!!parse-error (type => 'bare ero', line => $l, column => $c);
3205        ## NOTE: "No characters are consumed" in the spec.        ## NOTE: "No characters are consumed" in the spec.
3206        return {type => CHARACTER_TOKEN, data => '&'.$value,        $self->{entity_return} = {type => CHARACTER_TOKEN, data => '&'.$value,
3207                line => $l, column => $c,                line => $l, column => $c,
3208               };               };
3209          $self->{state} = $self->{entity_in_attr} ? ENTITY_IN_ATTRIBUTE_VALUE_STATE : ENTITY_DATA_STATE;
3210          redo A;
3211      }      }
3212    } else {    } else {
3213      !!!cp (1027);      !!!cp (1027);
3214      ## no characters are consumed      ## no characters are consumed
3215      !!!parse-error (type => 'bare ero', line => $l, column => $c);      !!!parse-error (type => 'bare ero', line => $l, column => $c);
3216      return undef;      $self->{entity_return} = undef;
3217        $self->{state} = $self->{entity_in_attr} ? ENTITY_IN_ATTRIBUTE_VALUE_STATE : ENTITY_DATA_STATE;
3218        redo A;
3219    }    }
3220  } # _tokenize_attempt_to_consume_an_entity  
3221        } else {
3222          die "$0: $self->{state}: Unknown state";
3223        }
3224      } # A  
3225    
3226      die "$0: _get_next_token: unexpected case";
3227    } # _get_next_token
3228    
3229  sub _initialize_tree_constructor ($) {  sub _initialize_tree_constructor ($) {
3230    my $self = shift;    my $self = shift;
# Line 3067  sub _initialize_tree_constructor ($) { Line 3233  sub _initialize_tree_constructor ($) {
3233    ## TODO: Turn mutation events off # MUST    ## TODO: Turn mutation events off # MUST
3234    ## TODO: Turn loose Document option (manakai extension) on    ## TODO: Turn loose Document option (manakai extension) on
3235    $self->{document}->manakai_is_html (1); # MUST    $self->{document}->manakai_is_html (1); # MUST
3236      $self->{document}->set_user_data (manakai_source_line => 1);
3237      $self->{document}->set_user_data (manakai_source_column => 1);
3238  } # _initialize_tree_constructor  } # _initialize_tree_constructor
3239    
3240  sub _terminate_tree_constructor ($) {  sub _terminate_tree_constructor ($) {
# Line 3121  sub _tree_construction_initial ($) { Line 3289  sub _tree_construction_initial ($) {
3289        ## language.        ## language.
3290        my $doctype_name = $token->{name};        my $doctype_name = $token->{name};
3291        $doctype_name = '' unless defined $doctype_name;        $doctype_name = '' unless defined $doctype_name;
3292        $doctype_name =~ tr/a-z/A-Z/;        $doctype_name =~ tr/a-z/A-Z/; # ASCII case-insensitive
3293        if (not defined $token->{name} or # <!DOCTYPE>        if (not defined $token->{name} or # <!DOCTYPE>
           defined $token->{public_identifier} or  
3294            defined $token->{system_identifier}) {            defined $token->{system_identifier}) {
3295          !!!cp ('t1');          !!!cp ('t1');
3296          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3297        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
3298          !!!cp ('t2');          !!!cp ('t2');
         ## ISSUE: ASCII case-insensitive? (in fact it does not matter)  
3299          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3300          } elsif (defined $token->{public_identifier}) {
3301            if ($token->{public_identifier} eq 'XSLT-compat') {
3302              !!!cp ('t1.2');
3303              !!!parse-error (type => 'XSLT-compat', token => $token,
3304                              level => $self->{level}->{should});
3305            } else {
3306              !!!parse-error (type => 'not HTML5', token => $token);
3307            }
3308        } else {        } else {
3309          !!!cp ('t3');          !!!cp ('t3');
3310            #
3311        }        }
3312                
3313        my $doctype = $self->{document}->create_document_type_definition        my $doctype = $self->{document}->create_document_type_definition
# Line 3634  sub _tree_construction_main ($) { Line 3809  sub _tree_construction_main ($) {
3809        ## NOTE: An end-of-file token.        ## NOTE: An end-of-file token.
3810        if ($content_model_flag == CDATA_CONTENT_MODEL) {        if ($content_model_flag == CDATA_CONTENT_MODEL) {
3811          !!!cp ('t43');          !!!cp ('t43');
3812          !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in CDATA:#eof', token => $token);
3813        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
3814          !!!cp ('t44');          !!!cp ('t44');
3815          !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in RCDATA:#eof', token => $token);
3816        } else {        } else {
3817          die "$0: $content_model_flag in parse_rcdata";          die "$0: $content_model_flag in parse_rcdata";
3818        }        }
# Line 3674  sub _tree_construction_main ($) { Line 3849  sub _tree_construction_main ($) {
3849        ## Ignore the token        ## Ignore the token
3850      } else {      } else {
3851        !!!cp ('t48');        !!!cp ('t48');
3852        !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);        !!!parse-error (type => 'in CDATA:#eof', token => $token);
3853        ## ISSUE: And ignore?        ## ISSUE: And ignore?
3854        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
3855      }      }
# Line 3725  sub _tree_construction_main ($) { Line 3900  sub _tree_construction_main ($) {
3900        } # AFE        } # AFE
3901        unless (defined $formatting_element) {        unless (defined $formatting_element) {
3902          !!!cp ('t53');          !!!cp ('t53');
3903          !!!parse-error (type => 'unmatched end tag:'.$tag_name, token => $end_tag_token);          !!!parse-error (type => 'unmatched end tag', text => $tag_name, token => $end_tag_token);
3904          ## Ignore the token          ## Ignore the token
3905          !!!next-token;          !!!next-token;
3906          return;          return;
# Line 3742  sub _tree_construction_main ($) { Line 3917  sub _tree_construction_main ($) {
3917              last INSCOPE;              last INSCOPE;
3918            } else { # in open elements but not in scope            } else { # in open elements but not in scope
3919              !!!cp ('t55');              !!!cp ('t55');
3920              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},              !!!parse-error (type => 'unmatched end tag',
3921                                text => $token->{tag_name},
3922                              token => $end_tag_token);                              token => $end_tag_token);
3923              ## Ignore the token              ## Ignore the token
3924              !!!next-token;              !!!next-token;
# Line 3755  sub _tree_construction_main ($) { Line 3931  sub _tree_construction_main ($) {
3931        } # INSCOPE        } # INSCOPE
3932        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
3933          !!!cp ('t57');          !!!cp ('t57');
3934          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},          !!!parse-error (type => 'unmatched end tag',
3935                            text => $token->{tag_name},
3936                          token => $end_tag_token);                          token => $end_tag_token);
3937          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
3938          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
# Line 3764  sub _tree_construction_main ($) { Line 3941  sub _tree_construction_main ($) {
3941        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
3942          !!!cp ('t58');          !!!cp ('t58');
3943          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
3944                          value => $self->{open_elements}->[-1]->[0]                          text => $self->{open_elements}->[-1]->[0]
3945                              ->manakai_local_name,                              ->manakai_local_name,
3946                          token => $end_tag_token);                          token => $end_tag_token);
3947        }        }
# Line 3973  sub _tree_construction_main ($) { Line 4150  sub _tree_construction_main ($) {
4150    B: while (1) {    B: while (1) {
4151      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
4152        !!!cp ('t73');        !!!cp ('t73');
4153        !!!parse-error (type => 'DOCTYPE in the middle', token => $token);        !!!parse-error (type => 'in html:#DOCTYPE', token => $token);
4154        ## Ignore the token        ## Ignore the token
4155        ## Stay in the phase        ## Stay in the phase
4156        !!!next-token;        !!!next-token;
# Line 3982  sub _tree_construction_main ($) { Line 4159  sub _tree_construction_main ($) {
4159               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
4160        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
4161          !!!cp ('t79');          !!!cp ('t79');
4162          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4163          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
4164        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
4165          !!!cp ('t80');          !!!cp ('t80');
4166          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4167          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
4168        } else {        } else {
4169          !!!cp ('t81');          !!!cp ('t81');
# Line 4047  sub _tree_construction_main ($) { Line 4224  sub _tree_construction_main ($) {
4224                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
4225            !!!cp ('t87.2');            !!!cp ('t87.2');
4226            !!!parse-error (type => 'not closed',            !!!parse-error (type => 'not closed',
4227                            value => $self->{open_elements}->[-1]->[0]                            text => $self->{open_elements}->[-1]->[0]
4228                                ->manakai_local_name,                                ->manakai_local_name,
4229                            token => $token);                            token => $token);
4230    
# Line 4125  sub _tree_construction_main ($) { Line 4302  sub _tree_construction_main ($) {
4302        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
4303          !!!cp ('t87.6');          !!!cp ('t87.6');
4304          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
4305                          value => $self->{open_elements}->[-1]->[0]                          text => $self->{open_elements}->[-1]->[0]
4306                              ->manakai_local_name,                              ->manakai_local_name,
4307                          token => $token);                          token => $token);
4308    
# Line 4175  sub _tree_construction_main ($) { Line 4352  sub _tree_construction_main ($) {
4352            !!!cp ('t90');            !!!cp ('t90');
4353            ## As if </noscript>            ## As if </noscript>
4354            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
4355            !!!parse-error (type => 'in noscript:#character', token => $token);            !!!parse-error (type => 'in noscript:#text', token => $token);
4356                        
4357            ## Reprocess in the "in head" insertion mode...            ## Reprocess in the "in head" insertion mode...
4358            ## As if </head>            ## As if </head>
# Line 4212  sub _tree_construction_main ($) { Line 4389  sub _tree_construction_main ($) {
4389              next B;              next B;
4390            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4391              !!!cp ('t93.2');              !!!cp ('t93.2');
4392              !!!parse-error (type => 'after head:head', token => $token); ## TODO: error type              !!!parse-error (type => 'after head', text => 'head',
4393                                token => $token);
4394              ## Ignore the token              ## Ignore the token
4395              !!!nack ('t93.3');              !!!nack ('t93.3');
4396              !!!next-token;              !!!next-token;
4397              next B;              next B;
4398            } else {            } else {
4399              !!!cp ('t95');              !!!cp ('t95');
4400              !!!parse-error (type => 'in head:head', token => $token); # or in head noscript              !!!parse-error (type => 'in head:head',
4401                                token => $token); # or in head noscript
4402              ## Ignore the token              ## Ignore the token
4403              !!!nack ('t95.1');              !!!nack ('t95.1');
4404              !!!next-token;              !!!next-token;
# Line 4244  sub _tree_construction_main ($) { Line 4423  sub _tree_construction_main ($) {
4423                  !!!cp ('t98');                  !!!cp ('t98');
4424                  ## As if </noscript>                  ## As if </noscript>
4425                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4426                  !!!parse-error (type => 'in noscript:base', token => $token);                  !!!parse-error (type => 'in noscript', text => 'base',
4427                                    token => $token);
4428                                
4429                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4430                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
# Line 4255  sub _tree_construction_main ($) { Line 4435  sub _tree_construction_main ($) {
4435                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4436                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4437                  !!!cp ('t100');                  !!!cp ('t100');
4438                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4439                                    text => $token->{tag_name}, token => $token);
4440                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4441                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4442                } else {                } else {
# Line 4272  sub _tree_construction_main ($) { Line 4453  sub _tree_construction_main ($) {
4453                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4454                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4455                  !!!cp ('t102');                  !!!cp ('t102');
4456                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4457                                    text => $token->{tag_name}, token => $token);
4458                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4459                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4460                } else {                } else {
# Line 4289  sub _tree_construction_main ($) { Line 4471  sub _tree_construction_main ($) {
4471                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4472                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4473                  !!!cp ('t104');                  !!!cp ('t104');
4474                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4475                                    text => $token->{tag_name}, token => $token);
4476                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4477                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4478                } else {                } else {
# Line 4358  sub _tree_construction_main ($) { Line 4541  sub _tree_construction_main ($) {
4541                  !!!cp ('t111');                  !!!cp ('t111');
4542                  ## As if </noscript>                  ## As if </noscript>
4543                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4544                  !!!parse-error (type => 'in noscript:title', token => $token);                  !!!parse-error (type => 'in noscript', text => 'title',
4545                                    token => $token);
4546                                
4547                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4548                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4549                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4550                  !!!cp ('t112');                  !!!cp ('t112');
4551                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4552                                    text => $token->{tag_name}, token => $token);
4553                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4554                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4555                } else {                } else {
# Line 4385  sub _tree_construction_main ($) { Line 4570  sub _tree_construction_main ($) {
4570                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4571                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4572                  !!!cp ('t114');                  !!!cp ('t114');
4573                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4574                                    text => $token->{tag_name}, token => $token);
4575                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4576                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4577                } else {                } else {
# Line 4406  sub _tree_construction_main ($) { Line 4592  sub _tree_construction_main ($) {
4592                  next B;                  next B;
4593                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4594                  !!!cp ('t117');                  !!!cp ('t117');
4595                  !!!parse-error (type => 'in noscript:noscript', token => $token);                  !!!parse-error (type => 'in noscript', text => 'noscript',
4596                                    token => $token);
4597                  ## Ignore the token                  ## Ignore the token
4598                  !!!nack ('t117.1');                  !!!nack ('t117.1');
4599                  !!!next-token;                  !!!next-token;
# Line 4420  sub _tree_construction_main ($) { Line 4607  sub _tree_construction_main ($) {
4607                  !!!cp ('t119');                  !!!cp ('t119');
4608                  ## As if </noscript>                  ## As if </noscript>
4609                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4610                  !!!parse-error (type => 'in noscript:script', token => $token);                  !!!parse-error (type => 'in noscript', text => 'script',
4611                                    token => $token);
4612                                
4613                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4614                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4615                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4616                  !!!cp ('t120');                  !!!cp ('t120');
4617                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4618                                    text => $token->{tag_name}, token => $token);
4619                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4620                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4621                } else {                } else {
# Line 4444  sub _tree_construction_main ($) { Line 4633  sub _tree_construction_main ($) {
4633                  !!!cp ('t122');                  !!!cp ('t122');
4634                  ## As if </noscript>                  ## As if </noscript>
4635                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4636                  !!!parse-error (type => 'in noscript:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in noscript',
4637                                    text => $token->{tag_name}, token => $token);
4638                                    
4639                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4640                  ## As if </head>                  ## As if </head>
# Line 4483  sub _tree_construction_main ($) { Line 4673  sub _tree_construction_main ($) {
4673                !!!cp ('t129');                !!!cp ('t129');
4674                ## As if </noscript>                ## As if </noscript>
4675                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4676                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4677                                  text => $token->{tag_name}, token => $token);
4678                                
4679                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4680                ## As if </head>                ## As if </head>
# Line 4526  sub _tree_construction_main ($) { Line 4717  sub _tree_construction_main ($) {
4717                  !!!cp ('t133');                  !!!cp ('t133');
4718                  ## As if </noscript>                  ## As if </noscript>
4719                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4720                  !!!parse-error (type => 'in noscript:/head', token => $token);                  !!!parse-error (type => 'in noscript:/',
4721                                    text => 'head', token => $token);
4722                                    
4723                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4724                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 4541  sub _tree_construction_main ($) { Line 4733  sub _tree_construction_main ($) {
4733                  next B;                  next B;
4734                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4735                  !!!cp ('t134.1');                  !!!cp ('t134.1');
4736                  !!!parse-error (type => 'unmatched end tag:head', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'head',
4737                                    token => $token);
4738                  ## Ignore the token                  ## Ignore the token
4739                  !!!next-token;                  !!!next-token;
4740                  next B;                  next B;
# Line 4558  sub _tree_construction_main ($) { Line 4751  sub _tree_construction_main ($) {
4751                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or
4752                         $self->{insertion_mode} == AFTER_HEAD_IM) {                         $self->{insertion_mode} == AFTER_HEAD_IM) {
4753                  !!!cp ('t137');                  !!!cp ('t137');
4754                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4755                                    text => 'noscript', token => $token);
4756                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
4757                  !!!next-token;                  !!!next-token;
4758                  next B;                  next B;
# Line 4573  sub _tree_construction_main ($) { Line 4767  sub _tree_construction_main ($) {
4767                    $self->{insertion_mode} == IN_HEAD_IM or                    $self->{insertion_mode} == IN_HEAD_IM or
4768                    $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                    $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4769                  !!!cp ('t140');                  !!!cp ('t140');
4770                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4771                                    text => $token->{tag_name}, token => $token);
4772                  ## Ignore the token                  ## Ignore the token
4773                  !!!next-token;                  !!!next-token;
4774                  next B;                  next B;
4775                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4776                  !!!cp ('t140.1');                  !!!cp ('t140.1');
4777                  !!!parse-error (type => 'unmatched end tag:' . $token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4778                                    text => $token->{tag_name}, token => $token);
4779                  ## Ignore the token                  ## Ignore the token
4780                  !!!next-token;                  !!!next-token;
4781                  next B;                  next B;
# Line 4588  sub _tree_construction_main ($) { Line 4784  sub _tree_construction_main ($) {
4784                }                }
4785              } elsif ($token->{tag_name} eq 'p') {              } elsif ($token->{tag_name} eq 'p') {
4786                !!!cp ('t142');                !!!cp ('t142');
4787                !!!parse-error (type => 'unmatched end tag:p', token => $token);                !!!parse-error (type => 'unmatched end tag',
4788                                  text => $token->{tag_name}, token => $token);
4789                ## Ignore the token                ## Ignore the token
4790                !!!next-token;                !!!next-token;
4791                next B;                next B;
# Line 4611  sub _tree_construction_main ($) { Line 4808  sub _tree_construction_main ($) {
4808                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4809                  !!!cp ('t143.3');                  !!!cp ('t143.3');
4810                  ## ISSUE: Two parse errors for <head><noscript></br>                  ## ISSUE: Two parse errors for <head><noscript></br>
4811                  !!!parse-error (type => 'unmatched end tag:br', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4812                                    text => 'br', token => $token);
4813                  ## As if </noscript>                  ## As if </noscript>
4814                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4815                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
# Line 4630  sub _tree_construction_main ($) { Line 4828  sub _tree_construction_main ($) {
4828                }                }
4829    
4830                ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.                ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.
4831                !!!parse-error (type => 'unmatched end tag:br', token => $token);                !!!parse-error (type => 'unmatched end tag',
4832                                  text => 'br', token => $token);
4833                ## Ignore the token                ## Ignore the token
4834                !!!next-token;                !!!next-token;
4835                next B;                next B;
4836              } else {              } else {
4837                !!!cp ('t145');                !!!cp ('t145');
4838                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
4839                                  text => $token->{tag_name}, token => $token);
4840                ## Ignore the token                ## Ignore the token
4841                !!!next-token;                !!!next-token;
4842                next B;                next B;
# Line 4646  sub _tree_construction_main ($) { Line 4846  sub _tree_construction_main ($) {
4846                !!!cp ('t146');                !!!cp ('t146');
4847                ## As if </noscript>                ## As if </noscript>
4848                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4849                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4850                                  text => $token->{tag_name}, token => $token);
4851                                
4852                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4853                ## As if </head>                ## As if </head>
# Line 4662  sub _tree_construction_main ($) { Line 4863  sub _tree_construction_main ($) {
4863              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4864  ## ISSUE: This case cannot be reached?  ## ISSUE: This case cannot be reached?
4865                !!!cp ('t148');                !!!cp ('t148');
4866                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
4867                                  text => $token->{tag_name}, token => $token);
4868                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
4869                !!!next-token;                !!!next-token;
4870                next B;                next B;
# Line 4773  sub _tree_construction_main ($) { Line 4975  sub _tree_construction_main ($) {
4975    
4976                  !!!cp ('t153');                  !!!cp ('t153');
4977                  !!!parse-error (type => 'start tag not allowed',                  !!!parse-error (type => 'start tag not allowed',
4978                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
4979                  ## Ignore the token                  ## Ignore the token
4980                  !!!nack ('t153.1');                  !!!nack ('t153.1');
4981                  !!!next-token;                  !!!next-token;
4982                  next B;                  next B;
4983                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4984                  !!!parse-error (type => 'not closed:caption', token => $token);                  !!!parse-error (type => 'not closed', text => 'caption',
4985                                    token => $token);
4986                                    
4987                  ## NOTE: As if </caption>.                  ## NOTE: As if </caption>.
4988                  ## have a table element in table scope                  ## have a table element in table scope
# Line 4799  sub _tree_construction_main ($) { Line 5002  sub _tree_construction_main ($) {
5002    
5003                    !!!cp ('t157');                    !!!cp ('t157');
5004                    !!!parse-error (type => 'start tag not allowed',                    !!!parse-error (type => 'start tag not allowed',
5005                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
5006                    ## Ignore the token                    ## Ignore the token
5007                    !!!nack ('t157.1');                    !!!nack ('t157.1');
5008                    !!!next-token;                    !!!next-token;
# Line 4816  sub _tree_construction_main ($) { Line 5019  sub _tree_construction_main ($) {
5019                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5020                    !!!cp ('t159');                    !!!cp ('t159');
5021                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5022                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5023                                        ->manakai_local_name,                                        ->manakai_local_name,
5024                                    token => $token);                                    token => $token);
5025                  } else {                  } else {
# Line 4858  sub _tree_construction_main ($) { Line 5061  sub _tree_construction_main ($) {
5061                  } # INSCOPE                  } # INSCOPE
5062                    unless (defined $i) {                    unless (defined $i) {
5063                      !!!cp ('t165');                      !!!cp ('t165');
5064                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5065                                        text => $token->{tag_name},
5066                                        token => $token);
5067                      ## Ignore the token                      ## Ignore the token
5068                      !!!next-token;                      !!!next-token;
5069                      next B;                      next B;
# Line 4875  sub _tree_construction_main ($) { Line 5080  sub _tree_construction_main ($) {
5080                          ne $token->{tag_name}) {                          ne $token->{tag_name}) {
5081                    !!!cp ('t167');                    !!!cp ('t167');
5082                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5083                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5084                                        ->manakai_local_name,                                        ->manakai_local_name,
5085                                    token => $token);                                    token => $token);
5086                  } else {                  } else {
# Line 4892  sub _tree_construction_main ($) { Line 5097  sub _tree_construction_main ($) {
5097                  next B;                  next B;
5098                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
5099                  !!!cp ('t169');                  !!!cp ('t169');
5100                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5101                                    text => $token->{tag_name}, token => $token);
5102                  ## Ignore the token                  ## Ignore the token
5103                  !!!next-token;                  !!!next-token;
5104                  next B;                  next B;
# Line 4919  sub _tree_construction_main ($) { Line 5125  sub _tree_construction_main ($) {
5125    
5126                    !!!cp ('t173');                    !!!cp ('t173');
5127                    !!!parse-error (type => 'unmatched end tag',                    !!!parse-error (type => 'unmatched end tag',
5128                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
5129                    ## Ignore the token                    ## Ignore the token
5130                    !!!next-token;                    !!!next-token;
5131                    next B;                    next B;
# Line 4935  sub _tree_construction_main ($) { Line 5141  sub _tree_construction_main ($) {
5141                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5142                    !!!cp ('t175');                    !!!cp ('t175');
5143                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5144                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5145                                        ->manakai_local_name,                                        ->manakai_local_name,
5146                                    token => $token);                                    token => $token);
5147                  } else {                  } else {
# Line 4952  sub _tree_construction_main ($) { Line 5158  sub _tree_construction_main ($) {
5158                  next B;                  next B;
5159                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
5160                  !!!cp ('t177');                  !!!cp ('t177');
5161                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5162                                    text => $token->{tag_name}, token => $token);
5163                  ## Ignore the token                  ## Ignore the token
5164                  !!!next-token;                  !!!next-token;
5165                  next B;                  next B;
# Line 4995  sub _tree_construction_main ($) { Line 5202  sub _tree_construction_main ($) {
5202    
5203                  !!!cp ('t182');                  !!!cp ('t182');
5204                  !!!parse-error (type => 'unmatched end tag',                  !!!parse-error (type => 'unmatched end tag',
5205                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
5206                  ## Ignore the token                  ## Ignore the token
5207                  !!!next-token;                  !!!next-token;
5208                  next B;                  next B;
5209                } # INSCOPE                } # INSCOPE
5210              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
5211                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5212                !!!parse-error (type => 'not closed:caption', token => $token);                !!!parse-error (type => 'not closed', text => 'caption',
5213                                  token => $token);
5214    
5215                ## As if </caption>                ## As if </caption>
5216                ## have a table element in table scope                ## have a table element in table scope
# Line 5020  sub _tree_construction_main ($) { Line 5228  sub _tree_construction_main ($) {
5228                } # INSCOPE                } # INSCOPE
5229                unless (defined $i) {                unless (defined $i) {
5230                  !!!cp ('t186');                  !!!cp ('t186');
5231                  !!!parse-error (type => 'unmatched end tag:caption', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5232                                    text => 'caption', token => $token);
5233                  ## Ignore the token                  ## Ignore the token
5234                  !!!next-token;                  !!!next-token;
5235                  next B;                  next B;
# Line 5035  sub _tree_construction_main ($) { Line 5244  sub _tree_construction_main ($) {
5244                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5245                  !!!cp ('t188');                  !!!cp ('t188');
5246                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5247                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5248                                      ->manakai_local_name,                                      ->manakai_local_name,
5249                                  token => $token);                                  token => $token);
5250                } else {                } else {
# Line 5055  sub _tree_construction_main ($) { Line 5264  sub _tree_construction_main ($) {
5264                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5265                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
5266                  !!!cp ('t190');                  !!!cp ('t190');
5267                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5268                                    text => $token->{tag_name}, token => $token);
5269                  ## Ignore the token                  ## Ignore the token
5270                  !!!next-token;                  !!!next-token;
5271                  next B;                  next B;
# Line 5069  sub _tree_construction_main ($) { Line 5279  sub _tree_construction_main ($) {
5279                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
5280                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5281                !!!cp ('t192');                !!!cp ('t192');
5282                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
5283                                  text => $token->{tag_name}, token => $token);
5284                ## Ignore the token                ## Ignore the token
5285                !!!next-token;                !!!next-token;
5286                next B;                next B;
# Line 5109  sub _tree_construction_main ($) { Line 5320  sub _tree_construction_main ($) {
5320            }            }
5321          }          }
5322    
5323              !!!parse-error (type => 'in table:#character', token => $token);          !!!parse-error (type => 'in table:#text', token => $token);
5324    
5325              ## As if in body, but insert into foster parent element              ## As if in body, but insert into foster parent element
5326              ## ISSUE: Spec says that "whenever a node would be inserted              ## ISSUE: Spec says that "whenever a node would be inserted
# Line 5160  sub _tree_construction_main ($) { Line 5371  sub _tree_construction_main ($) {
5371          !!!next-token;          !!!next-token;
5372          next B;          next B;
5373        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5374              if ({          if ({
5375                   tr => ($self->{insertion_mode} != IN_ROW_IM),               tr => ($self->{insertion_mode} != IN_ROW_IM),
5376                   th => 1, td => 1,               th => 1, td => 1,
5377                  }->{$token->{tag_name}}) {              }->{$token->{tag_name}}) {
5378                if ($self->{insertion_mode} == IN_TABLE_IM) {            if ($self->{insertion_mode} == IN_TABLE_IM) {
5379                  ## Clear back to table context              ## Clear back to table context
5380                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5381                                  & TABLE_SCOPING_EL)) {                              & TABLE_SCOPING_EL)) {
5382                    !!!cp ('t201');                !!!cp ('t201');
5383                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5384                  }              }
5385                                
5386                  !!!insert-element ('tbody',, $token);              !!!insert-element ('tbody',, $token);
5387                  $self->{insertion_mode} = IN_TABLE_BODY_IM;              $self->{insertion_mode} = IN_TABLE_BODY_IM;
5388                  ## reprocess in the "in table body" insertion mode...              ## reprocess in the "in table body" insertion mode...
5389                }            }
5390              
5391                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {            if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
5392                  unless ($token->{tag_name} eq 'tr') {              unless ($token->{tag_name} eq 'tr') {
5393                    !!!cp ('t202');                !!!cp ('t202');
5394                    !!!parse-error (type => 'missing start tag:tr', token => $token);                !!!parse-error (type => 'missing start tag:tr', token => $token);
5395                  }              }
5396                                    
5397                  ## Clear back to table body context              ## Clear back to table body context
5398                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5399                                  & TABLE_ROWS_SCOPING_EL)) {                              & TABLE_ROWS_SCOPING_EL)) {
5400                    !!!cp ('t203');                !!!cp ('t203');
5401                    ## ISSUE: Can this case be reached?                ## ISSUE: Can this case be reached?
5402                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5403                  }              }
5404                                    
5405                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
5406                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
# Line 5245  sub _tree_construction_main ($) { Line 5456  sub _tree_construction_main ($) {
5456                  unless (defined $i) {                  unless (defined $i) {
5457                    !!!cp ('t210');                    !!!cp ('t210');
5458  ## TODO: This type is wrong.  ## TODO: This type is wrong.
5459                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmacthed end tag',
5460                                      text => $token->{tag_name}, token => $token);
5461                    ## Ignore the token                    ## Ignore the token
5462                    !!!nack ('t210.1');                    !!!nack ('t210.1');
5463                    !!!next-token;                    !!!next-token;
# Line 5289  sub _tree_construction_main ($) { Line 5501  sub _tree_construction_main ($) {
5501                  } # INSCOPE                  } # INSCOPE
5502                  unless (defined $i) {                  unless (defined $i) {
5503                    !!!cp ('t216');                    !!!cp ('t216');
5504  ## TODO: This erorr type ios wrong.  ## TODO: This erorr type is wrong.
5505                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5506                                      text => $token->{tag_name}, token => $token);
5507                    ## Ignore the token                    ## Ignore the token
5508                    !!!nack ('t216.1');                    !!!nack ('t216.1');
5509                    !!!next-token;                    !!!next-token;
# Line 5365  sub _tree_construction_main ($) { Line 5578  sub _tree_construction_main ($) {
5578                }                }
5579              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
5580                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
5581                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
5582                                    ->manakai_local_name,                                    ->manakai_local_name,
5583                                token => $token);                                token => $token);
5584    
# Line 5386  sub _tree_construction_main ($) { Line 5599  sub _tree_construction_main ($) {
5599                unless (defined $i) {                unless (defined $i) {
5600                  !!!cp ('t223');                  !!!cp ('t223');
5601  ## TODO: The following is wrong, maybe.  ## TODO: The following is wrong, maybe.
5602                  !!!parse-error (type => 'unmatched end tag:table', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'table',
5603                                    token => $token);
5604                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
5605                  !!!nack ('t223.1');                  !!!nack ('t223.1');
5606                  !!!next-token;                  !!!next-token;
# Line 5404  sub _tree_construction_main ($) { Line 5618  sub _tree_construction_main ($) {
5618                  !!!cp ('t225');                  !!!cp ('t225');
5619                  ## NOTE: |<table><tr><table>|                  ## NOTE: |<table><tr><table>|
5620                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5621                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5622                                      ->manakai_local_name,                                      ->manakai_local_name,
5623                                  token => $token);                                  token => $token);
5624                } else {                } else {
# Line 5445  sub _tree_construction_main ($) { Line 5659  sub _tree_construction_main ($) {
5659                my $type = lc $token->{attributes}->{type}->{value};                my $type = lc $token->{attributes}->{type}->{value};
5660                if ($type eq 'hidden') {                if ($type eq 'hidden') {
5661                  !!!cp ('t227.3');                  !!!cp ('t227.3');
5662                  !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in table',
5663                                    text => $token->{tag_name}, token => $token);
5664    
5665                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5666    
# Line 5473  sub _tree_construction_main ($) { Line 5688  sub _tree_construction_main ($) {
5688            #            #
5689          }          }
5690    
5691          !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in table', text => $token->{tag_name},
5692                            token => $token);
5693    
5694          $insert = $insert_to_foster;          $insert = $insert_to_foster;
5695          #          #
# Line 5495  sub _tree_construction_main ($) { Line 5711  sub _tree_construction_main ($) {
5711                } # INSCOPE                } # INSCOPE
5712                unless (defined $i) {                unless (defined $i) {
5713                  !!!cp ('t230');                  !!!cp ('t230');
5714                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5715                                    text => $token->{tag_name}, token => $token);
5716                  ## Ignore the token                  ## Ignore the token
5717                  !!!nack ('t230.1');                  !!!nack ('t230.1');
5718                  !!!next-token;                  !!!next-token;
# Line 5536  sub _tree_construction_main ($) { Line 5753  sub _tree_construction_main ($) {
5753                  unless (defined $i) {                  unless (defined $i) {
5754                    !!!cp ('t235');                    !!!cp ('t235');
5755  ## TODO: The following is wrong.  ## TODO: The following is wrong.
5756                    !!!parse-error (type => 'unmatched end tag:'.$token->{type}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5757                                      text => $token->{type}, token => $token);
5758                    ## Ignore the token                    ## Ignore the token
5759                    !!!nack ('t236.1');                    !!!nack ('t236.1');
5760                    !!!next-token;                    !!!next-token;
# Line 5572  sub _tree_construction_main ($) { Line 5790  sub _tree_construction_main ($) {
5790                  } # INSCOPE                  } # INSCOPE
5791                  unless (defined $i) {                  unless (defined $i) {
5792                    !!!cp ('t239');                    !!!cp ('t239');
5793                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5794                                      text => $token->{tag_name}, token => $token);
5795                    ## Ignore the token                    ## Ignore the token
5796                    !!!nack ('t239.1');                    !!!nack ('t239.1');
5797                    !!!next-token;                    !!!next-token;
# Line 5618  sub _tree_construction_main ($) { Line 5837  sub _tree_construction_main ($) {
5837                } # INSCOPE                } # INSCOPE
5838                unless (defined $i) {                unless (defined $i) {
5839                  !!!cp ('t243');                  !!!cp ('t243');
5840                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5841                                    text => $token->{tag_name}, token => $token);
5842                  ## Ignore the token                  ## Ignore the token
5843                  !!!nack ('t243.1');                  !!!nack ('t243.1');
5844                  !!!next-token;                  !!!next-token;
# Line 5652  sub _tree_construction_main ($) { Line 5872  sub _tree_construction_main ($) {
5872                  } # INSCOPE                  } # INSCOPE
5873                    unless (defined $i) {                    unless (defined $i) {
5874                      !!!cp ('t249');                      !!!cp ('t249');
5875                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5876                                        text => $token->{tag_name}, token => $token);
5877                      ## Ignore the token                      ## Ignore the token
5878                      !!!nack ('t249.1');                      !!!nack ('t249.1');
5879                      !!!next-token;                      !!!next-token;
# Line 5675  sub _tree_construction_main ($) { Line 5896  sub _tree_construction_main ($) {
5896                  } # INSCOPE                  } # INSCOPE
5897                    unless (defined $i) {                    unless (defined $i) {
5898                      !!!cp ('t252');                      !!!cp ('t252');
5899                      !!!parse-error (type => 'unmatched end tag:tr', token => $token);                      !!!parse-error (type => 'unmatched end tag',
5900                                        text => 'tr', token => $token);
5901                      ## Ignore the token                      ## Ignore the token
5902                      !!!nack ('t252.1');                      !!!nack ('t252.1');
5903                      !!!next-token;                      !!!next-token;
# Line 5710  sub _tree_construction_main ($) { Line 5932  sub _tree_construction_main ($) {
5932                } # INSCOPE                } # INSCOPE
5933                unless (defined $i) {                unless (defined $i) {
5934                  !!!cp ('t256');                  !!!cp ('t256');
5935                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5936                                    text => $token->{tag_name}, token => $token);
5937                  ## Ignore the token                  ## Ignore the token
5938                  !!!nack ('t256.1');                  !!!nack ('t256.1');
5939                  !!!next-token;                  !!!next-token;
# Line 5737  sub _tree_construction_main ($) { Line 5960  sub _tree_construction_main ($) {
5960                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
5961                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5962            !!!cp ('t258');            !!!cp ('t258');
5963            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
5964                              text => $token->{tag_name}, token => $token);
5965            ## Ignore the token            ## Ignore the token
5966            !!!nack ('t258.1');            !!!nack ('t258.1');
5967             !!!next-token;             !!!next-token;
5968            next B;            next B;
5969          } else {          } else {
5970            !!!cp ('t259');            !!!cp ('t259');
5971            !!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in table:/',
5972                              text => $token->{tag_name}, token => $token);
5973    
5974            $insert = $insert_to_foster;            $insert = $insert_to_foster;
5975            #            #
# Line 5794  sub _tree_construction_main ($) { Line 6019  sub _tree_construction_main ($) {
6019              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
6020                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
6021                  !!!cp ('t264');                  !!!cp ('t264');
6022                  !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);                  !!!parse-error (type => 'unmatched end tag',
6023                                    text => 'colgroup', token => $token);
6024                  ## Ignore the token                  ## Ignore the token
6025                  !!!next-token;                  !!!next-token;
6026                  next B;                  next B;
# Line 5807  sub _tree_construction_main ($) { Line 6033  sub _tree_construction_main ($) {
6033                }                }
6034              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
6035                !!!cp ('t266');                !!!cp ('t266');
6036                !!!parse-error (type => 'unmatched end tag:col', token => $token);                !!!parse-error (type => 'unmatched end tag',
6037                                  text => 'col', token => $token);
6038                ## Ignore the token                ## Ignore the token
6039                !!!next-token;                !!!next-token;
6040                next B;                next B;
# Line 5837  sub _tree_construction_main ($) { Line 6064  sub _tree_construction_main ($) {
6064            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
6065              !!!cp ('t269');              !!!cp ('t269');
6066  ## TODO: Wrong error type?  ## TODO: Wrong error type?
6067              !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);              !!!parse-error (type => 'unmatched end tag',
6068                                text => 'colgroup', token => $token);
6069              ## Ignore the token              ## Ignore the token
6070              !!!nack ('t269.1');              !!!nack ('t269.1');
6071              !!!next-token;              !!!next-token;
# Line 5901  sub _tree_construction_main ($) { Line 6129  sub _tree_construction_main ($) {
6129                     tr => 1, td => 1, th => 1,                     tr => 1, td => 1, th => 1,
6130                    }->{$token->{tag_name}})) {                    }->{$token->{tag_name}})) {
6131            ## TODO: The type below is not good - <select> is replaced by </select>            ## TODO: The type below is not good - <select> is replaced by </select>
6132            !!!parse-error (type => 'not closed:select', token => $token);            !!!parse-error (type => 'not closed', text => 'select',
6133                              token => $token);
6134            ## NOTE: As if the token were </select> (<select> case) or            ## NOTE: As if the token were </select> (<select> case) or
6135            ## as if there were </select> (otherwise).            ## as if there were </select> (otherwise).
6136            ## have an element in table scope            ## have an element in table scope
# Line 5919  sub _tree_construction_main ($) { Line 6148  sub _tree_construction_main ($) {
6148            } # INSCOPE            } # INSCOPE
6149            unless (defined $i) {            unless (defined $i) {
6150              !!!cp ('t280');              !!!cp ('t280');
6151              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6152                                text => 'select', token => $token);
6153              ## Ignore the token              ## Ignore the token
6154              !!!nack ('t280.1');              !!!nack ('t280.1');
6155              !!!next-token;              !!!next-token;
# Line 5943  sub _tree_construction_main ($) { Line 6173  sub _tree_construction_main ($) {
6173            }            }
6174          } else {          } else {
6175            !!!cp ('t282');            !!!cp ('t282');
6176            !!!parse-error (type => 'in select:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select',
6177                              text => $token->{tag_name}, token => $token);
6178            ## Ignore the token            ## Ignore the token
6179            !!!nack ('t282.1');            !!!nack ('t282.1');
6180            !!!next-token;            !!!next-token;
# Line 5961  sub _tree_construction_main ($) { Line 6192  sub _tree_construction_main ($) {
6192              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6193            } else {            } else {
6194              !!!cp ('t285');              !!!cp ('t285');
6195              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6196                                text => $token->{tag_name}, token => $token);
6197              ## Ignore the token              ## Ignore the token
6198            }            }
6199            !!!nack ('t285.1');            !!!nack ('t285.1');
# Line 5973  sub _tree_construction_main ($) { Line 6205  sub _tree_construction_main ($) {
6205              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6206            } else {            } else {
6207              !!!cp ('t287');              !!!cp ('t287');
6208              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6209                                text => $token->{tag_name}, token => $token);
6210              ## Ignore the token              ## Ignore the token
6211            }            }
6212            !!!nack ('t287.1');            !!!nack ('t287.1');
# Line 5995  sub _tree_construction_main ($) { Line 6228  sub _tree_construction_main ($) {
6228            } # INSCOPE            } # INSCOPE
6229            unless (defined $i) {            unless (defined $i) {
6230              !!!cp ('t290');              !!!cp ('t290');
6231              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6232                                text => $token->{tag_name}, token => $token);
6233              ## Ignore the token              ## Ignore the token
6234              !!!nack ('t290.1');              !!!nack ('t290.1');
6235              !!!next-token;              !!!next-token;
# Line 6016  sub _tree_construction_main ($) { Line 6250  sub _tree_construction_main ($) {
6250                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
6251                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
6252  ## TODO: The following is wrong?  ## TODO: The following is wrong?
6253            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
6254                              text => $token->{tag_name}, token => $token);
6255                                
6256            ## have an element in table scope            ## have an element in table scope
6257            my $i;            my $i;
# Line 6057  sub _tree_construction_main ($) { Line 6292  sub _tree_construction_main ($) {
6292            unless (defined $i) {            unless (defined $i) {
6293              !!!cp ('t297');              !!!cp ('t297');
6294  ## TODO: The following error type is correct?  ## TODO: The following error type is correct?
6295              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6296                                text => 'select', token => $token);
6297              ## Ignore the </select> token              ## Ignore the </select> token
6298              !!!nack ('t297.1');              !!!nack ('t297.1');
6299              !!!next-token; ## TODO: ok?              !!!next-token; ## TODO: ok?
# Line 6074  sub _tree_construction_main ($) { Line 6310  sub _tree_construction_main ($) {
6310            next B;            next B;
6311          } else {          } else {
6312            !!!cp ('t299');            !!!cp ('t299');
6313            !!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select:/',
6314                              text => $token->{tag_name}, token => $token);
6315            ## Ignore the token            ## Ignore the token
6316            !!!nack ('t299.3');            !!!nack ('t299.3');
6317            !!!next-token;            !!!next-token;
# Line 6112  sub _tree_construction_main ($) { Line 6349  sub _tree_construction_main ($) {
6349                    
6350          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6351            !!!cp ('t301');            !!!cp ('t301');
6352            !!!parse-error (type => 'after html:#character', token => $token);            !!!parse-error (type => 'after html:#text', token => $token);
6353    
6354            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6355          } else {          } else {
# Line 6120  sub _tree_construction_main ($) { Line 6357  sub _tree_construction_main ($) {
6357          }          }
6358                    
6359          ## "after body" insertion mode          ## "after body" insertion mode
6360          !!!parse-error (type => 'after body:#character', token => $token);          !!!parse-error (type => 'after body:#text', token => $token);
6361    
6362          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6363          ## reprocess          ## reprocess
# Line 6128  sub _tree_construction_main ($) { Line 6365  sub _tree_construction_main ($) {
6365        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
6366          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6367            !!!cp ('t303');            !!!cp ('t303');
6368            !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html',
6369                              text => $token->{tag_name}, token => $token);
6370                        
6371            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6372          } else {          } else {
# Line 6136  sub _tree_construction_main ($) { Line 6374  sub _tree_construction_main ($) {
6374          }          }
6375    
6376          ## "after body" insertion mode          ## "after body" insertion mode
6377          !!!parse-error (type => 'after body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'after body',
6378                            text => $token->{tag_name}, token => $token);
6379    
6380          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6381          !!!ack-later;          !!!ack-later;
# Line 6145  sub _tree_construction_main ($) { Line 6384  sub _tree_construction_main ($) {
6384        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6385          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6386            !!!cp ('t305');            !!!cp ('t305');
6387            !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html:/',
6388                              text => $token->{tag_name}, token => $token);
6389                        
6390            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6391            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
# Line 6157  sub _tree_construction_main ($) { Line 6397  sub _tree_construction_main ($) {
6397          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
6398            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
6399              !!!cp ('t307');              !!!cp ('t307');
6400              !!!parse-error (type => 'unmatched end tag:html', token => $token);              !!!parse-error (type => 'unmatched end tag',
6401                                text => 'html', token => $token);
6402              ## Ignore the token              ## Ignore the token
6403              !!!next-token;              !!!next-token;
6404              next B;              next B;
# Line 6169  sub _tree_construction_main ($) { Line 6410  sub _tree_construction_main ($) {
6410            }            }
6411          } else {          } else {
6412            !!!cp ('t309');            !!!cp ('t309');
6413            !!!parse-error (type => 'after body:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after body:/',
6414                              text => $token->{tag_name}, token => $token);
6415    
6416            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
6417            ## reprocess            ## reprocess
# Line 6197  sub _tree_construction_main ($) { Line 6439  sub _tree_construction_main ($) {
6439          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
6440            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6441              !!!cp ('t311');              !!!cp ('t311');
6442              !!!parse-error (type => 'in frameset:#character', token => $token);              !!!parse-error (type => 'in frameset:#text', token => $token);
6443            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6444              !!!cp ('t312');              !!!cp ('t312');
6445              !!!parse-error (type => 'after frameset:#character', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6446            } else { # "after html frameset"            } else { # "after after frameset"
6447              !!!cp ('t313');              !!!cp ('t313');
6448              !!!parse-error (type => 'after html:#character', token => $token);              !!!parse-error (type => 'after html:#text', token => $token);
   
             $self->{insertion_mode} = AFTER_FRAMESET_IM;  
             ## Reprocess in the "after frameset" insertion mode.  
             !!!parse-error (type => 'after frameset:#character', token => $token);  
6449            }            }
6450                        
6451            ## Ignore the token.            ## Ignore the token.
# Line 6223  sub _tree_construction_main ($) { Line 6461  sub _tree_construction_main ($) {
6461                    
6462          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
6463        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
         if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {  
           !!!cp ('t316');  
           !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);  
   
           $self->{insertion_mode} = AFTER_FRAMESET_IM;  
           ## Process in the "after frameset" insertion mode.  
         } else {  
           !!!cp ('t317');  
         }  
   
6464          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6465              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6466            !!!cp ('t318');            !!!cp ('t318');
# Line 6253  sub _tree_construction_main ($) { Line 6481  sub _tree_construction_main ($) {
6481            ## NOTE: As if in head.            ## NOTE: As if in head.
6482            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
6483            next B;            next B;
6484    
6485              ## NOTE: |<!DOCTYPE HTML><frameset></frameset></html><noframes></noframes>|
6486              ## has no parse error.
6487          } else {          } else {
6488            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6489              !!!cp ('t321');              !!!cp ('t321');
6490              !!!parse-error (type => 'in frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset',
6491            } else {                              text => $token->{tag_name}, token => $token);
6492              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6493              !!!cp ('t322');              !!!cp ('t322');
6494              !!!parse-error (type => 'after frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after frameset',
6495                                text => $token->{tag_name}, token => $token);
6496              } else { # "after after frameset"
6497                !!!cp ('t322.2');
6498                !!!parse-error (type => 'after after frameset',
6499                                text => $token->{tag_name}, token => $token);
6500            }            }
6501            ## Ignore the token            ## Ignore the token
6502            !!!nack ('t322.1');            !!!nack ('t322.1');
# Line 6267  sub _tree_construction_main ($) { Line 6504  sub _tree_construction_main ($) {
6504            next B;            next B;
6505          }          }
6506        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
         if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {  
           !!!cp ('t323');  
           !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);  
   
           $self->{insertion_mode} = AFTER_FRAMESET_IM;  
           ## Process in the "after frameset" insertion mode.  
         } else {  
           !!!cp ('t324');  
         }  
   
6507          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6508              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6509            if ($self->{open_elements}->[-1]->[1] & HTML_EL and            if ($self->{open_elements}->[-1]->[1] & HTML_EL and
6510                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
6511              !!!cp ('t325');              !!!cp ('t325');
6512              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6513                                text => $token->{tag_name}, token => $token);
6514              ## Ignore the token              ## Ignore the token
6515              !!!next-token;              !!!next-token;
6516            } else {            } else {
# Line 6308  sub _tree_construction_main ($) { Line 6536  sub _tree_construction_main ($) {
6536          } else {          } else {
6537            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6538              !!!cp ('t330');              !!!cp ('t330');
6539              !!!parse-error (type => 'in frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset:/',
6540            } else {                              text => $token->{tag_name}, token => $token);
6541              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6542                !!!cp ('t330.1');
6543                !!!parse-error (type => 'after frameset:/',
6544                                text => $token->{tag_name}, token => $token);
6545              } else { # "after after html"
6546              !!!cp ('t331');              !!!cp ('t331');
6547              !!!parse-error (type => 'after frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after after frameset:/',
6548                                text => $token->{tag_name}, token => $token);
6549            }            }
6550            ## Ignore the token            ## Ignore the token
6551            !!!next-token;            !!!next-token;
# Line 6419  sub _tree_construction_main ($) { Line 6653  sub _tree_construction_main ($) {
6653          $parse_rcdata->(RCDATA_CONTENT_MODEL);          $parse_rcdata->(RCDATA_CONTENT_MODEL);
6654          next B;          next B;
6655        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
6656          !!!parse-error (type => 'in body:body', token => $token);          !!!parse-error (type => 'in body', text => 'body', token => $token);
6657                                
6658          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
6659              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {
# Line 6539  sub _tree_construction_main ($) { Line 6773  sub _tree_construction_main ($) {
6773              if ($i != -1) {              if ($i != -1) {
6774                !!!cp ('t355');                !!!cp ('t355');
6775                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
6776                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
6777                                    ->manakai_local_name,                                    ->manakai_local_name,
6778                                token => $token);                                token => $token);
6779              } else {              } else {
# Line 6807  sub _tree_construction_main ($) { Line 7041  sub _tree_construction_main ($) {
7041            ## Ignore the token            ## Ignore the token
7042          } else {          } else {
7043            !!!cp ('t398');            !!!cp ('t398');
7044            !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);            !!!parse-error (type => 'in RCDATA:#eof', token => $token);
7045          }          }
7046          !!!next-token;          !!!next-token;
7047          next B;          next B;
# Line 6826  sub _tree_construction_main ($) { Line 7060  sub _tree_construction_main ($) {
7060              unless ($self->{open_elements}->[-1]->[1] & RUBY_EL) {              unless ($self->{open_elements}->[-1]->[1] & RUBY_EL) {
7061                !!!cp ('t398.3');                !!!cp ('t398.3');
7062                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
7063                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
7064                                    ->manakai_local_name,                                    ->manakai_local_name,
7065                                token => $token);                                token => $token);
7066                pop @{$self->{open_elements}}                pop @{$self->{open_elements}}
# Line 6848  sub _tree_construction_main ($) { Line 7082  sub _tree_construction_main ($) {
7082                 $token->{tag_name} eq 'svg') {                 $token->{tag_name} eq 'svg') {
7083          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
7084    
7085            ## "Adjust MathML attributes" ('math' only) - done in insert-element-f
7086    
7087          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f
7088    
7089          ## "adjust foreign attributes" - done in insert-element-f          ## "adjust foreign attributes" - done in insert-element-f
# Line 6874  sub _tree_construction_main ($) { Line 7110  sub _tree_construction_main ($) {
7110                  thead => 1, tr => 1,                  thead => 1, tr => 1,
7111                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7112          !!!cp ('t401');          !!!cp ('t401');
7113          !!!parse-error (type => 'in body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in body',
7114                            text => $token->{tag_name}, token => $token);
7115          ## Ignore the token          ## Ignore the token
7116          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.
7117          !!!next-token;          !!!next-token;
# Line 6959  sub _tree_construction_main ($) { Line 7196  sub _tree_construction_main ($) {
7196            }            }
7197    
7198            !!!parse-error (type => 'start tag not allowed',            !!!parse-error (type => 'start tag not allowed',
7199                            value => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7200            ## NOTE: Ignore the token.            ## NOTE: Ignore the token.
7201            !!!next-token;            !!!next-token;
7202            next B;            next B;
# Line 6969  sub _tree_construction_main ($) { Line 7206  sub _tree_construction_main ($) {
7206            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {
7207              !!!cp ('t403');              !!!cp ('t403');
7208              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7209                              value => $_->[0]->manakai_local_name,                              text => $_->[0]->manakai_local_name,
7210                              token => $token);                              token => $token);
7211              last;              last;
7212            } else {            } else {
# Line 6989  sub _tree_construction_main ($) { Line 7226  sub _tree_construction_main ($) {
7226            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {
7227              !!!cp ('t406');              !!!cp ('t406');
7228              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7229                              value => $self->{open_elements}->[1]->[0]                              text => $self->{open_elements}->[1]->[0]
7230                                  ->manakai_local_name,                                  ->manakai_local_name,
7231                              token => $token);                              token => $token);
7232            } else {            } else {
# Line 7000  sub _tree_construction_main ($) { Line 7237  sub _tree_construction_main ($) {
7237            next B;            next B;
7238          } else {          } else {
7239            !!!cp ('t408');            !!!cp ('t408');
7240            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7241                              text => $token->{tag_name}, token => $token);
7242            ## Ignore the token            ## Ignore the token
7243            !!!next-token;            !!!next-token;
7244            next B;            next B;
# Line 7028  sub _tree_construction_main ($) { Line 7266  sub _tree_construction_main ($) {
7266    
7267          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7268            !!!cp ('t413');            !!!cp ('t413');
7269            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7270                              text => $token->{tag_name}, token => $token);
7271              ## NOTE: Ignore the token.
7272          } else {          } else {
7273            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7274            while ({            while ({
# Line 7049  sub _tree_construction_main ($) { Line 7289  sub _tree_construction_main ($) {
7289                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7290              !!!cp ('t412');              !!!cp ('t412');
7291              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7292                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7293                                  ->manakai_local_name,                                  ->manakai_local_name,
7294                              token => $token);                              token => $token);
7295            } else {            } else {
# Line 7086  sub _tree_construction_main ($) { Line 7326  sub _tree_construction_main ($) {
7326    
7327          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7328            !!!cp ('t421');            !!!cp ('t421');
7329            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7330                              text => $token->{tag_name}, token => $token);
7331              ## NOTE: Ignore the token.
7332          } else {          } else {
7333            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7334            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7099  sub _tree_construction_main ($) { Line 7341  sub _tree_construction_main ($) {
7341                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7342              !!!cp ('t417.1');              !!!cp ('t417.1');
7343              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7344                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7345                                  ->manakai_local_name,                                  ->manakai_local_name,
7346                              token => $token);                              token => $token);
7347            } else {            } else {
# Line 7131  sub _tree_construction_main ($) { Line 7373  sub _tree_construction_main ($) {
7373    
7374          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7375            !!!cp ('t425.1');            !!!cp ('t425.1');
7376            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7377                              text => $token->{tag_name}, token => $token);
7378              ## NOTE: Ignore the token.
7379          } else {          } else {
7380            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7381            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7143  sub _tree_construction_main ($) { Line 7387  sub _tree_construction_main ($) {
7387            if ($self->{open_elements}->[-1]->[0]->manakai_local_name            if ($self->{open_elements}->[-1]->[0]->manakai_local_name
7388                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7389              !!!cp ('t425');              !!!cp ('t425');
7390              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
7391                                text => $token->{tag_name}, token => $token);
7392            } else {            } else {
7393              !!!cp ('t426');              !!!cp ('t426');
7394            }            }
# Line 7174  sub _tree_construction_main ($) { Line 7419  sub _tree_construction_main ($) {
7419                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7420              !!!cp ('t412.1');              !!!cp ('t412.1');
7421              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7422                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7423                                  ->manakai_local_name,                                  ->manakai_local_name,
7424                              token => $token);                              token => $token);
7425            } else {            } else {
# Line 7184  sub _tree_construction_main ($) { Line 7429  sub _tree_construction_main ($) {
7429            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
7430          } else {          } else {
7431            !!!cp ('t413.1');            !!!cp ('t413.1');
7432            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7433                              text => $token->{tag_name}, token => $token);
7434    
7435            !!!cp ('t415.1');            !!!cp ('t415.1');
7436            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
# Line 7207  sub _tree_construction_main ($) { Line 7453  sub _tree_construction_main ($) {
7453          next B;          next B;
7454        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
7455          !!!cp ('t428');          !!!cp ('t428');
7456          !!!parse-error (type => 'unmatched end tag:br', token => $token);          !!!parse-error (type => 'unmatched end tag',
7457                            text => 'br', token => $token);
7458    
7459          ## As if <br>          ## As if <br>
7460          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
# Line 7232  sub _tree_construction_main ($) { Line 7479  sub _tree_construction_main ($) {
7479                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
7480                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7481          !!!cp ('t429');          !!!cp ('t429');
7482          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'unmatched end tag',
7483                            text => $token->{tag_name}, token => $token);
7484          ## Ignore the token          ## Ignore the token
7485          !!!next-token;          !!!next-token;
7486          next B;          next B;
# Line 7264  sub _tree_construction_main ($) { Line 7512  sub _tree_construction_main ($) {
7512                !!!cp ('t431');                !!!cp ('t431');
7513                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
7514                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
7515                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
7516                                    ->manakai_local_name,                                    ->manakai_local_name,
7517                                token => $token);                                token => $token);
7518              } else {              } else {
# Line 7283  sub _tree_construction_main ($) { Line 7531  sub _tree_construction_main ($) {
7531                  ($node->[1] & SPECIAL_EL or                  ($node->[1] & SPECIAL_EL or
7532                   $node->[1] & SCOPING_EL)) {                   $node->[1] & SCOPING_EL)) {
7533                !!!cp ('t433');                !!!cp ('t433');
7534                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
7535                                  text => $token->{tag_name}, token => $token);
7536                ## Ignore the token                ## Ignore the token
7537                !!!next-token;                !!!next-token;
7538                last S2;                last S2;
# Line 7329  sub _tree_construction_main ($) { Line 7578  sub _tree_construction_main ($) {
7578    ## TODO: script stuffs    ## TODO: script stuffs
7579  } # _tree_construct_main  } # _tree_construct_main
7580    
7581  sub set_inner_html ($$$) {  sub set_inner_html ($$$;$) {
7582    my $class = shift;    my $class = shift;
7583    my $node = shift;    my $node = shift;
7584    my $s = \$_[0];    my $s = \$_[0];
7585    my $onerror = $_[1];    my $onerror = $_[1];
7586      my $get_wrapper = $_[2] || sub ($) { return $_[0] };
7587    
7588    ## ISSUE: Should {confident} be true?    ## ISSUE: Should {confident} be true?
7589    
# Line 7352  sub set_inner_html ($$$) { Line 7602  sub set_inner_html ($$$) {
7602      }      }
7603    
7604      ## Step 3, 4, 5 # MUST      ## Step 3, 4, 5 # MUST
7605      $class->parse_string ($$s => $node, $onerror);      $class->parse_char_string ($$s => $node, $onerror, $get_wrapper);
7606    } elsif ($nt == 1) {    } elsif ($nt == 1) {
7607      ## TODO: If non-html element      ## TODO: If non-html element
7608    
7609      ## NOTE: Most of this code is copied from |parse_string|      ## NOTE: Most of this code is copied from |parse_string|
7610    
7611    ## TODO: Support for $get_wrapper
7612    
7613      ## Step 1 # MUST      ## Step 1 # MUST
7614      my $this_doc = $node->owner_document;      my $this_doc = $node->owner_document;
7615      my $doc = $this_doc->implementation->create_document;      my $doc = $this_doc->implementation->create_document;
# Line 7419  sub set_inner_html ($$$) { Line 7671  sub set_inner_html ($$$) {
7671                  0x10FFFE => 1, 0x10FFFF => 1,                  0x10FFFE => 1, 0x10FFFF => 1,
7672                 }->{$self->{next_char}}) {                 }->{$self->{next_char}}) {
7673          !!!cp ('i4.1');          !!!cp ('i4.1');
7674          !!!parse-error (type => 'control char', level => $self->{must_level});          if ($self->{next_char} < 0x10000) {
7675  ## TODO: error type documentation            !!!parse-error (type => 'control char',
7676                              text => (sprintf 'U+%04X', $self->{next_char}));
7677            } else {
7678              !!!parse-error (type => 'control char',
7679                              text => (sprintf 'U-%08X', $self->{next_char}));
7680            }
7681        }        }
7682      };      };
7683      $p->{prev_char} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];

Legend:
Removed from v.1.151  
changed lines
  Added in v.1.167

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24