/[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.146 by wakaba, Sat May 24 14:19:55 2008 UTC revision 1.168 by wakaba, Sat Sep 13 10:49:21 2008 UTC
# Line 45  sub MISC_SPECIAL_EL () { 0b1000000000000 Line 45  sub MISC_SPECIAL_EL () { 0b1000000000000
45  sub FOREIGN_EL () { 0b10000000000000000000000000 }  sub FOREIGN_EL () { 0b10000000000000000000000000 }
46  sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 }  sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 }
47  sub MML_AXML_EL () { 0b1000000000000000000000000000 }  sub MML_AXML_EL () { 0b1000000000000000000000000000 }
48    sub RUBY_EL () { 0b10000000000000000000000000000 }
49    sub RUBY_COMPONENT_EL () { 0b100000000000000000000000000000 }
50    
51  sub TABLE_ROWS_EL () {  sub TABLE_ROWS_EL () {
52    TABLE_EL |    TABLE_EL |
# Line 52  sub TABLE_ROWS_EL () { Line 54  sub TABLE_ROWS_EL () {
54    TABLE_ROW_GROUP_EL    TABLE_ROW_GROUP_EL
55  }  }
56    
57    ## NOTE: Used in "generate implied end tags" algorithm.
58    ## NOTE: There is a code where a modified version of END_TAG_OPTIONAL_EL
59    ## is used in "generate implied end tags" implementation (search for the
60    ## function mae).
61  sub END_TAG_OPTIONAL_EL () {  sub END_TAG_OPTIONAL_EL () {
62    DD_EL |    DD_EL |
63    DT_EL |    DT_EL |
64    LI_EL |    LI_EL |
65    P_EL    P_EL |
66      RUBY_COMPONENT_EL
67  }  }
68    
69    ## NOTE: Used in </body> and EOF algorithms.
70  sub ALL_END_TAG_OPTIONAL_EL () {  sub ALL_END_TAG_OPTIONAL_EL () {
71    END_TAG_OPTIONAL_EL |    DD_EL |
72      DT_EL |
73      LI_EL |
74      P_EL |
75    
76    BODY_EL |    BODY_EL |
77    HTML_EL |    HTML_EL |
78    TABLE_CELL_EL |    TABLE_CELL_EL |
# Line 96  sub SPECIAL_EL () { Line 108  sub SPECIAL_EL () {
108    ADDRESS_EL |    ADDRESS_EL |
109    BODY_EL |    BODY_EL |
110    DIV_EL |    DIV_EL |
111    END_TAG_OPTIONAL_EL |  
112      DD_EL |
113      DT_EL |
114      LI_EL |
115      P_EL |
116    
117    FORM_EL |    FORM_EL |
118    FRAMESET_EL |    FRAMESET_EL |
119    HEADING_EL |    HEADING_EL |
# Line 170  my $el_category = { Line 187  my $el_category = {
187    param => MISC_SPECIAL_EL,    param => MISC_SPECIAL_EL,
188    plaintext => MISC_SPECIAL_EL,    plaintext => MISC_SPECIAL_EL,
189    pre => MISC_SPECIAL_EL,    pre => MISC_SPECIAL_EL,
190      rp => RUBY_COMPONENT_EL,
191      rt => RUBY_COMPONENT_EL,
192      ruby => RUBY_EL,
193    s => FORMATTING_EL,    s => FORMATTING_EL,
194    script => MISC_SPECIAL_EL,    script => MISC_SPECIAL_EL,
195    select => SELECT_EL,    select => SELECT_EL,
# Line 334  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 345  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 352  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 379  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 412  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 423  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 434  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 446  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 472  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 481  sub parse_byte_stream ($$$$;$) { Line 521  sub parse_byte_stream ($$$$;$) {
521        ## "Change the encoding" algorithm:        ## "Change the encoding" algorithm:
522    
523        ## Step 1            ## Step 1    
524        if ($charset->{iana_names}->{'utf-16'}) { ## ISSUE: UTF-16BE -> UTF-8? UTF-16LE -> UTF-8?        if ($charset->{category} &
525          $charset = Message::Charset::Info->get_by_iana_name ('utf-8');            Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) {
526            $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 492  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 516  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 560  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 641  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 671  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 706  sub RCDATA_CONTENT_MODEL () { CM_ENTITY Line 769  sub RCDATA_CONTENT_MODEL () { CM_ENTITY
769  sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }  sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }
770    
771  sub DATA_STATE () { 0 }  sub DATA_STATE () { 0 }
772  sub ENTITY_DATA_STATE () { 1 }  #sub ENTITY_DATA_STATE () { 1 }
773  sub TAG_OPEN_STATE () { 2 }  sub TAG_OPEN_STATE () { 2 }
774  sub CLOSE_TAG_OPEN_STATE () { 3 }  sub CLOSE_TAG_OPEN_STATE () { 3 }
775  sub TAG_NAME_STATE () { 4 }  sub TAG_NAME_STATE () { 4 }
# Line 717  sub BEFORE_ATTRIBUTE_VALUE_STATE () { 8 Line 780  sub BEFORE_ATTRIBUTE_VALUE_STATE () { 8
780  sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 }  sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 }
781  sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 }  sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 }
782  sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 }  sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 }
783  sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 }  #sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 }
784  sub MARKUP_DECLARATION_OPEN_STATE () { 13 }  sub MARKUP_DECLARATION_OPEN_STATE () { 13 }
785  sub COMMENT_START_STATE () { 14 }  sub COMMENT_START_STATE () { 14 }
786  sub COMMENT_START_DASH_STATE () { 15 }  sub COMMENT_START_DASH_STATE () { 15 }
# Line 740  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    ## NOTE: "Entity data state", "entity in attribute value state", and
816    ## "consume a character reference" algorithm are jointly implemented
817    ## using the following six states:
818    sub ENTITY_STATE () { 44 }
819    sub ENTITY_HASH_STATE () { 45 }
820    sub NCR_NUM_STATE () { 46 }
821    sub HEXREF_X_STATE () { 47 }
822    sub HEXREF_HEX_STATE () { 48 }
823    sub ENTITY_NAME_STATE () { 49 }
824    
825  sub DOCTYPE_TOKEN () { 1 }  sub DOCTYPE_TOKEN () { 1 }
826  sub COMMENT_TOKEN () { 2 }  sub COMMENT_TOKEN () { 2 }
# Line 793  sub IN_COLUMN_GROUP_IM () { 0b10 } Line 873  sub IN_COLUMN_GROUP_IM () { 0b10 }
873  sub _initialize_tokenizer ($) {  sub _initialize_tokenizer ($) {
874    my $self = shift;    my $self = shift;
875    $self->{state} = DATA_STATE; # MUST    $self->{state} = DATA_STATE; # MUST
876      #$self->{state_keyword}; # initialized when used
877    $self->{content_model} = PCDATA_CONTENT_MODEL; # be    $self->{content_model} = PCDATA_CONTENT_MODEL; # be
878    undef $self->{current_token}; # start tag, end tag, comment, or DOCTYPE    undef $self->{current_token};
879    undef $self->{current_attribute};    undef $self->{current_attribute};
880    undef $self->{last_emitted_start_tag_name};    undef $self->{last_emitted_start_tag_name};
881    undef $self->{last_attribute_value_state};    undef $self->{last_attribute_value_state};
# Line 823  sub _initialize_tokenizer ($) { Line 904  sub _initialize_tokenizer ($) {
904  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|
905  ##     while the token is pushed back to the stack.  ##     while the token is pushed back to the stack.
906    
 ## ISSUE: "When a DOCTYPE token is created, its  
 ## <i>self-closing flag</i> must be unset (its other state is that it  
 ## be set), and its attributes list must be empty.": Wrong subject?  
   
907  ## Emitted token MUST immediately be handled by the tree construction state.  ## Emitted token MUST immediately be handled by the tree construction state.
908    
909  ## Before each step, UA MAY check to see if either one of the scripts in  ## Before each step, UA MAY check to see if either one of the scripts in
# Line 872  sub _get_next_token ($) { Line 949  sub _get_next_token ($) {
949          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA
950              not $self->{escape}) {              not $self->{escape}) {
951            !!!cp (1);            !!!cp (1);
952            $self->{state} = ENTITY_DATA_STATE;            ## NOTE: In the spec, the tokenizer is switched to the
953              ## "entity data state".  In this implementation, the tokenizer
954              ## is switched to the |ENTITY_STATE|, which is an implementation
955              ## of the "consume a character reference" algorithm.
956              $self->{entity_in_attr} = 0;
957              $self->{entity_additional} = -1;
958              $self->{state} = ENTITY_STATE;
959            !!!next-input-character;            !!!next-input-character;
960            redo A;            redo A;
961          } else {          } else {
# Line 942  sub _get_next_token ($) { Line 1025  sub _get_next_token ($) {
1025        !!!emit ($token);        !!!emit ($token);
1026    
1027        redo A;        redo A;
     } elsif ($self->{state} == ENTITY_DATA_STATE) {  
       ## (cannot happen in CDATA state)  
   
       my ($l, $c) = ($self->{line_prev}, $self->{column_prev});  
         
       my $token = $self->_tokenize_attempt_to_consume_an_entity (0, -1);  
   
       $self->{state} = DATA_STATE;  
       # next-input-character is already done  
   
       unless (defined $token) {  
         !!!cp (13);  
         !!!emit ({type => CHARACTER_TOKEN, data => '&',  
                   line => $l, column => $c,  
                  });  
       } else {  
         !!!cp (14);  
         !!!emit ($token);  
       }  
   
       redo A;  
1028      } elsif ($self->{state} == TAG_OPEN_STATE) {      } elsif ($self->{state} == TAG_OPEN_STATE) {
1029        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1030          if ($self->{next_char} == 0x002F) { # /          if ($self->{next_char} == 0x002F) { # /
# Line 1059  sub _get_next_token ($) { Line 1121  sub _get_next_token ($) {
1121          die "$0: $self->{content_model} in tag open";          die "$0: $self->{content_model} in tag open";
1122        }        }
1123      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {
1124          ## NOTE: The "close tag open state" in the spec is implemented as
1125          ## |CLOSE_TAG_OPEN_STATE| and |CDATA_PCDATA_CLOSE_TAG_STATE|.
1126    
1127        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"
1128        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1129          if (defined $self->{last_emitted_start_tag_name}) {          if (defined $self->{last_emitted_start_tag_name}) {
1130              $self->{state} = CDATA_PCDATA_CLOSE_TAG_STATE;
1131            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>            $self->{state_keyword} = '';
1132            my @next_char;            ## Reconsume.
1133            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...  
           }  
1134          } else {          } else {
1135            ## No start tag token has ever been emitted            ## No start tag token has ever been emitted
1136              ## NOTE: See <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>.
1137            !!!cp (28);            !!!cp (28);
           # next-input-character is already done  
1138            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1139              ## Reconsume.
1140            !!!emit ({type => CHARACTER_TOKEN, data => '</',            !!!emit ({type => CHARACTER_TOKEN, data => '</',
1141                      line => $l, column => $c,                      line => $l, column => $c,
1142                     });                     });
1143            redo A;            redo A;
1144          }          }
1145        }        }
1146          
1147        if (0x0041 <= $self->{next_char} and        if (0x0041 <= $self->{next_char} and
1148            $self->{next_char} <= 0x005A) { # A..Z            $self->{next_char} <= 0x005A) { # A..Z
1149          !!!cp (29);          !!!cp (29);
# Line 1168  sub _get_next_token ($) { Line 1190  sub _get_next_token ($) {
1190                                    line => $self->{line_prev}, # "<" of "</"                                    line => $self->{line_prev}, # "<" of "</"
1191                                    column => $self->{column_prev} - 1,                                    column => $self->{column_prev} - 1,
1192                                   };                                   };
1193          ## $self->{next_char} is intentionally left as is          ## NOTE: $self->{next_char} is intentionally left as is.
1194          redo A;          ## Although the "anything else" case of the spec not explicitly
1195            ## states that the next input character is to be reconsumed,
1196            ## it will be included to the |data| of the comment token
1197            ## generated from the bogus end tag, as defined in the
1198            ## "bogus comment state" entry.
1199            redo A;
1200          }
1201        } elsif ($self->{state} == CDATA_PCDATA_CLOSE_TAG_STATE) {
1202          my $ch = substr $self->{last_emitted_start_tag_name}, length $self->{state_keyword}, 1;
1203          if (length $ch) {
1204            my $CH = $ch;
1205            $ch =~ tr/a-z/A-Z/;
1206            my $nch = chr $self->{next_char};
1207            if ($nch eq $ch or $nch eq $CH) {
1208              !!!cp (24);
1209              ## Stay in the state.
1210              $self->{state_keyword} .= $nch;
1211              !!!next-input-character;
1212              redo A;
1213            } else {
1214              !!!cp (25);
1215              $self->{state} = DATA_STATE;
1216              ## Reconsume.
1217              !!!emit ({type => CHARACTER_TOKEN,
1218                        data => '</' . $self->{state_keyword},
1219                        line => $self->{line_prev},
1220                        column => $self->{column_prev} - 1 - length $self->{state_keyword},
1221                       });
1222              redo A;
1223            }
1224          } else { # after "<{tag-name}"
1225            unless ({
1226                     0x0009 => 1, # HT
1227                     0x000A => 1, # LF
1228                     0x000B => 1, # VT
1229                     0x000C => 1, # FF
1230                     0x0020 => 1, # SP
1231                     0x003E => 1, # >
1232                     0x002F => 1, # /
1233                     -1 => 1, # EOF
1234                    }->{$self->{next_char}}) {
1235              !!!cp (26);
1236              ## Reconsume.
1237              $self->{state} = DATA_STATE;
1238              !!!emit ({type => CHARACTER_TOKEN,
1239                        data => '</' . $self->{state_keyword},
1240                        line => $self->{line_prev},
1241                        column => $self->{column_prev} - 1 - length $self->{state_keyword},
1242                       });
1243              redo A;
1244            } else {
1245              !!!cp (27);
1246              $self->{current_token}
1247                  = {type => END_TAG_TOKEN,
1248                     tag_name => $self->{last_emitted_start_tag_name},
1249                     line => $self->{line_prev},
1250                     column => $self->{column_prev} - 1 - length $self->{state_keyword}};
1251              $self->{state} = TAG_NAME_STATE;
1252              ## Reconsume.
1253              redo A;
1254            }
1255        }        }
1256      } elsif ($self->{state} == TAG_NAME_STATE) {      } elsif ($self->{state} == TAG_NAME_STATE) {
1257        if ($self->{next_char} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
# Line 1339  sub _get_next_token ($) { Line 1421  sub _get_next_token ($) {
1421          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
1422              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
1423            !!!cp (57);            !!!cp (57);
1424            !!!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});
1425            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{current_attribute} # MUST
1426          } else {          } else {
1427            !!!cp (58);            !!!cp (58);
# Line 1510  sub _get_next_token ($) { Line 1592  sub _get_next_token ($) {
1592    
1593          redo A;          redo A;
1594        } else {        } else {
1595          !!!cp (82);          if ($self->{next_char} == 0x0022 or # "
1596                $self->{next_char} == 0x0027) { # '
1597              !!!cp (78);
1598              !!!parse-error (type => 'bad attribute name');
1599            } else {
1600              !!!cp (82);
1601            }
1602          $self->{current_attribute}          $self->{current_attribute}
1603              = {name => chr ($self->{next_char}),              = {name => chr ($self->{next_char}),
1604                 value => '',                 value => '',
# Line 1545  sub _get_next_token ($) { Line 1633  sub _get_next_token ($) {
1633          !!!next-input-character;          !!!next-input-character;
1634          redo A;          redo A;
1635        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1636            !!!parse-error (type => 'empty unquoted attribute value');
1637          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1638            !!!cp (87);            !!!cp (87);
1639            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
# Line 1610  sub _get_next_token ($) { Line 1699  sub _get_next_token ($) {
1699        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1700          !!!cp (96);          !!!cp (96);
1701          $self->{last_attribute_value_state} = $self->{state};          $self->{last_attribute_value_state} = $self->{state};
1702          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## NOTE: In the spec, the tokenizer is switched to the
1703            ## "entity in attribute value state".  In this implementation, the
1704            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1705            ## implementation of the "consume a character reference" algorithm.
1706            $self->{entity_in_attr} = 1;
1707            $self->{entity_additional} = 0x0022; # "
1708            $self->{state} = ENTITY_STATE;
1709          !!!next-input-character;          !!!next-input-character;
1710          redo A;          redo A;
1711        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
# Line 1652  sub _get_next_token ($) { Line 1747  sub _get_next_token ($) {
1747        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1748          !!!cp (102);          !!!cp (102);
1749          $self->{last_attribute_value_state} = $self->{state};          $self->{last_attribute_value_state} = $self->{state};
1750          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## NOTE: In the spec, the tokenizer is switched to the
1751            ## "entity in attribute value state".  In this implementation, the
1752            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1753            ## implementation of the "consume a character reference" algorithm.
1754            $self->{entity_in_attr} = 1;
1755            $self->{entity_additional} = 0x0027; # '
1756            $self->{state} = ENTITY_STATE;
1757          !!!next-input-character;          !!!next-input-character;
1758          redo A;          redo A;
1759        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
# Line 1698  sub _get_next_token ($) { Line 1799  sub _get_next_token ($) {
1799        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1800          !!!cp (108);          !!!cp (108);
1801          $self->{last_attribute_value_state} = $self->{state};          $self->{last_attribute_value_state} = $self->{state};
1802          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          ## NOTE: In the spec, the tokenizer is switched to the
1803            ## "entity in attribute value state".  In this implementation, the
1804            ## tokenizer is switched to the |ENTITY_STATE|, which is an
1805            ## implementation of the "consume a character reference" algorithm.
1806            $self->{entity_in_attr} = 1;
1807            $self->{entity_additional} = -1;
1808            $self->{state} = ENTITY_STATE;
1809          !!!next-input-character;          !!!next-input-character;
1810          redo A;          redo A;
1811        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
# Line 1762  sub _get_next_token ($) { Line 1869  sub _get_next_token ($) {
1869          !!!next-input-character;          !!!next-input-character;
1870          redo A;          redo A;
1871        }        }
     } elsif ($self->{state} == ENTITY_IN_ATTRIBUTE_VALUE_STATE) {  
       my $token = $self->_tokenize_attempt_to_consume_an_entity  
           (1,  
            $self->{last_attribute_value_state}  
              == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE ? 0x0022 : # "  
            $self->{last_attribute_value_state}  
              == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE ? 0x0027 : # '  
            -1);  
   
       unless (defined $token) {  
         !!!cp (117);  
         $self->{current_attribute}->{value} .= '&';  
       } else {  
         !!!cp (118);  
         $self->{current_attribute}->{value} .= $token->{data};  
         $self->{current_attribute}->{has_reference} = $token->{has_reference};  
         ## ISSUE: spec says "append the returned character token to the current attribute's value"  
       }  
   
       $self->{state} = $self->{last_attribute_value_state};  
       # next-input-character is already done  
       redo A;  
1872      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {
1873        if ($self->{next_char} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
1874            $self->{next_char} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
# Line 1903  sub _get_next_token ($) { Line 1988  sub _get_next_token ($) {
1988        }        }
1989      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {
1990        ## (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  
   
           redo A;  
         } elsif ($self->{next_char} == -1) {  
           !!!cp (125);  
           $self->{state} = DATA_STATE;  
           ## reconsume  
1991    
1992            !!!emit ($self->{current_token}); # comment        ## NOTE: Unlike spec's "bogus comment state", this implementation
1993          ## consumes characters one-by-one basis.
1994          
1995          if ($self->{next_char} == 0x003E) { # >
1996            !!!cp (124);
1997            $self->{state} = DATA_STATE;
1998            !!!next-input-character;
1999    
2000            redo A;          !!!emit ($self->{current_token}); # comment
2001          } else {          redo A;
2002            !!!cp (126);        } elsif ($self->{next_char} == -1) {
2003            $self->{current_token}->{data} .= chr ($self->{next_char}); # comment          !!!cp (125);
2004            !!!next-input-character;          $self->{state} = DATA_STATE;
2005            redo BC;          ## reconsume
         }  
       } # BC  
2006    
2007        die "$0: _get_next_token: unexpected case [BC]";          !!!emit ($self->{current_token}); # comment
2008            redo A;
2009          } else {
2010            !!!cp (126);
2011            $self->{current_token}->{data} .= chr ($self->{next_char}); # comment
2012            ## Stay in the state.
2013            !!!next-input-character;
2014            redo A;
2015          }
2016      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {
2017        ## (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};  
2018                
2019        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
2020            !!!cp (133);
2021            $self->{state} = MD_HYPHEN_STATE;
2022          !!!next-input-character;          !!!next-input-character;
2023          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);  
         }  
2024        } elsif ($self->{next_char} == 0x0044 or # D        } elsif ($self->{next_char} == 0x0044 or # D
2025                 $self->{next_char} == 0x0064) { # d                 $self->{next_char} == 0x0064) { # d
2026            ## ASCII case-insensitive.
2027            !!!cp (130);
2028            $self->{state} = MD_DOCTYPE_STATE;
2029            $self->{state_keyword} = chr $self->{next_char};
2030          !!!next-input-character;          !!!next-input-character;
2031          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);  
         }  
2032        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and
2033                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and
2034                 $self->{next_char} == 0x005B) { # [                 $self->{next_char} == 0x005B) { # [
2035            !!!cp (135.4);                
2036            $self->{state} = MD_CDATA_STATE;
2037            $self->{state_keyword} = '[';
2038          !!!next-input-character;          !!!next-input-character;
2039          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);  
         }  
2040        } else {        } else {
2041          !!!cp (136);          !!!cp (136);
2042        }        }
2043    
2044        !!!parse-error (type => 'bogus comment');        !!!parse-error (type => 'bogus comment',
2045        $self->{next_char} = shift @next_char;                        line => $self->{line_prev},
2046        !!!back-next-input-character (@next_char);                        column => $self->{column_prev} - 1);
2047          ## Reconsume.
2048        $self->{state} = BOGUS_COMMENT_STATE;        $self->{state} = BOGUS_COMMENT_STATE;
2049        $self->{current_token} = {type => COMMENT_TOKEN, data => '',        $self->{current_token} = {type => COMMENT_TOKEN, data => '',
2050                                  line => $l, column => $c,                                  line => $self->{line_prev},
2051                                    column => $self->{column_prev} - 1,
2052                                 };                                 };
2053        redo A;        redo A;
2054              } elsif ($self->{state} == MD_HYPHEN_STATE) {
2055        ## ISSUE: typos in spec: chacacters, is is a parse error        if ($self->{next_char} == 0x002D) { # -
2056        ## 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);
2057            $self->{current_token} = {type => COMMENT_TOKEN, data => '',
2058                                      line => $self->{line_prev},
2059                                      column => $self->{column_prev} - 2,
2060                                     };
2061            $self->{state} = COMMENT_START_STATE;
2062            !!!next-input-character;
2063            redo A;
2064          } else {
2065            !!!cp (128);
2066            !!!parse-error (type => 'bogus comment',
2067                            line => $self->{line_prev},
2068                            column => $self->{column_prev} - 2);
2069            $self->{state} = BOGUS_COMMENT_STATE;
2070            ## Reconsume.
2071            $self->{current_token} = {type => COMMENT_TOKEN,
2072                                      data => '-',
2073                                      line => $self->{line_prev},
2074                                      column => $self->{column_prev} - 2,
2075                                     };
2076            redo A;
2077          }
2078        } elsif ($self->{state} == MD_DOCTYPE_STATE) {
2079          ## ASCII case-insensitive.
2080          if ($self->{next_char} == [
2081                undef,
2082                0x004F, # O
2083                0x0043, # C
2084                0x0054, # T
2085                0x0059, # Y
2086                0x0050, # P
2087              ]->[length $self->{state_keyword}] or
2088              $self->{next_char} == [
2089                undef,
2090                0x006F, # o
2091                0x0063, # c
2092                0x0074, # t
2093                0x0079, # y
2094                0x0070, # p
2095              ]->[length $self->{state_keyword}]) {
2096            !!!cp (131);
2097            ## Stay in the state.
2098            $self->{state_keyword} .= chr $self->{next_char};
2099            !!!next-input-character;
2100            redo A;
2101          } elsif ((length $self->{state_keyword}) == 6 and
2102                   ($self->{next_char} == 0x0045 or # E
2103                    $self->{next_char} == 0x0065)) { # e
2104            !!!cp (129);
2105            $self->{state} = DOCTYPE_STATE;
2106            $self->{current_token} = {type => DOCTYPE_TOKEN,
2107                                      quirks => 1,
2108                                      line => $self->{line_prev},
2109                                      column => $self->{column_prev} - 7,
2110                                     };
2111            !!!next-input-character;
2112            redo A;
2113          } else {
2114            !!!cp (132);        
2115            !!!parse-error (type => 'bogus comment',
2116                            line => $self->{line_prev},
2117                            column => $self->{column_prev} - 1 - length $self->{state_keyword});
2118            $self->{state} = BOGUS_COMMENT_STATE;
2119            ## Reconsume.
2120            $self->{current_token} = {type => COMMENT_TOKEN,
2121                                      data => $self->{state_keyword},
2122                                      line => $self->{line_prev},
2123                                      column => $self->{column_prev} - 1 - length $self->{state_keyword},
2124                                     };
2125            redo A;
2126          }
2127        } elsif ($self->{state} == MD_CDATA_STATE) {
2128          if ($self->{next_char} == {
2129                '[' => 0x0043, # C
2130                '[C' => 0x0044, # D
2131                '[CD' => 0x0041, # A
2132                '[CDA' => 0x0054, # T
2133                '[CDAT' => 0x0041, # A
2134              }->{$self->{state_keyword}}) {
2135            !!!cp (135.1);
2136            ## Stay in the state.
2137            $self->{state_keyword} .= chr $self->{next_char};
2138            !!!next-input-character;
2139            redo A;
2140          } elsif ($self->{state_keyword} eq '[CDATA' and
2141                   $self->{next_char} == 0x005B) { # [
2142            !!!cp (135.2);
2143            $self->{current_token} = {type => CHARACTER_TOKEN,
2144                                      data => '',
2145                                      line => $self->{line_prev},
2146                                      column => $self->{column_prev} - 7};
2147            $self->{state} = CDATA_SECTION_STATE;
2148            !!!next-input-character;
2149            redo A;
2150          } else {
2151            !!!cp (135.3);
2152            !!!parse-error (type => 'bogus comment',
2153                            line => $self->{line_prev},
2154                            column => $self->{column_prev} - 1 - length $self->{state_keyword});
2155            $self->{state} = BOGUS_COMMENT_STATE;
2156            ## Reconsume.
2157            $self->{current_token} = {type => COMMENT_TOKEN,
2158                                      data => $self->{state_keyword},
2159                                      line => $self->{line_prev},
2160                                      column => $self->{column_prev} - 1 - length $self->{state_keyword},
2161                                     };
2162            redo A;
2163          }
2164      } elsif ($self->{state} == COMMENT_START_STATE) {      } elsif ($self->{state} == COMMENT_START_STATE) {
2165        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
2166          !!!cp (137);          !!!cp (137);
# Line 2332  sub _get_next_token ($) { Line 2427  sub _get_next_token ($) {
2427          redo A;          redo A;
2428        } elsif ($self->{next_char} == 0x0050 or # P        } elsif ($self->{next_char} == 0x0050 or # P
2429                 $self->{next_char} == 0x0070) { # p                 $self->{next_char} == 0x0070) { # p
2430            $self->{state} = PUBLIC_STATE;
2431            $self->{state_keyword} = chr $self->{next_char};
2432          !!!next-input-character;          !!!next-input-character;
2433          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);  
         }  
   
         #  
2434        } elsif ($self->{next_char} == 0x0053 or # S        } elsif ($self->{next_char} == 0x0053 or # S
2435                 $self->{next_char} == 0x0073) { # s                 $self->{next_char} == 0x0073) { # s
2436            $self->{state} = SYSTEM_STATE;
2437            $self->{state_keyword} = chr $self->{next_char};
2438          !!!next-input-character;          !!!next-input-character;
2439          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);  
         }  
   
         #  
2440        } else {        } else {
2441          !!!cp (180);          !!!cp (180);
2442            !!!parse-error (type => 'string after DOCTYPE name');
2443            $self->{current_token}->{quirks} = 1;
2444    
2445            $self->{state} = BOGUS_DOCTYPE_STATE;
2446          !!!next-input-character;          !!!next-input-character;
2447          #          redo A;
2448        }        }
2449        } elsif ($self->{state} == PUBLIC_STATE) {
2450          ## ASCII case-insensitive
2451          if ($self->{next_char} == [
2452                undef,
2453                0x0055, # U
2454                0x0042, # B
2455                0x004C, # L
2456                0x0049, # I
2457              ]->[length $self->{state_keyword}] or
2458              $self->{next_char} == [
2459                undef,
2460                0x0075, # u
2461                0x0062, # b
2462                0x006C, # l
2463                0x0069, # i
2464              ]->[length $self->{state_keyword}]) {
2465            !!!cp (175);
2466            ## Stay in the state.
2467            $self->{state_keyword} .= chr $self->{next_char};
2468            !!!next-input-character;
2469            redo A;
2470          } elsif ((length $self->{state_keyword}) == 5 and
2471                   ($self->{next_char} == 0x0043 or # C
2472                    $self->{next_char} == 0x0063)) { # c
2473            !!!cp (168);
2474            $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
2475            !!!next-input-character;
2476            redo A;
2477          } else {
2478            !!!cp (169);
2479            !!!parse-error (type => 'string after DOCTYPE name',
2480                            line => $self->{line_prev},
2481                            column => $self->{column_prev} + 1 - length $self->{state_keyword});
2482            $self->{current_token}->{quirks} = 1;
2483    
2484        !!!parse-error (type => 'string after DOCTYPE name');          $self->{state} = BOGUS_DOCTYPE_STATE;
2485        $self->{current_token}->{quirks} = 1;          ## Reconsume.
2486            redo A;
2487          }
2488        } elsif ($self->{state} == SYSTEM_STATE) {
2489          ## ASCII case-insensitive
2490          if ($self->{next_char} == [
2491                undef,
2492                0x0059, # Y
2493                0x0053, # S
2494                0x0054, # T
2495                0x0045, # E
2496              ]->[length $self->{state_keyword}] or
2497              $self->{next_char} == [
2498                undef,
2499                0x0079, # y
2500                0x0073, # s
2501                0x0074, # t
2502                0x0065, # e
2503              ]->[length $self->{state_keyword}]) {
2504            !!!cp (170);
2505            ## Stay in the state.
2506            $self->{state_keyword} .= chr $self->{next_char};
2507            !!!next-input-character;
2508            redo A;
2509          } elsif ((length $self->{state_keyword}) == 5 and
2510                   ($self->{next_char} == 0x004D or # M
2511                    $self->{next_char} == 0x006D)) { # m
2512            !!!cp (171);
2513            $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2514            !!!next-input-character;
2515            redo A;
2516          } else {
2517            !!!cp (172);
2518            !!!parse-error (type => 'string after DOCTYPE name',
2519                            line => $self->{line_prev},
2520                            column => $self->{column_prev} + 1 - length $self->{state_keyword});
2521            $self->{current_token}->{quirks} = 1;
2522    
2523        $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2524        # next-input-character is already done          ## Reconsume.
2525        redo A;          redo A;
2526          }
2527      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {
2528        if ({        if ({
2529              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
# Line 2650  sub _get_next_token ($) { Line 2756  sub _get_next_token ($) {
2756          redo A;          redo A;
2757        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2758          !!!cp (208);          !!!cp (208);
2759          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2760    
2761          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2762          !!!next-input-character;          !!!next-input-character;
# Line 2686  sub _get_next_token ($) { Line 2792  sub _get_next_token ($) {
2792          redo A;          redo A;
2793        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2794          !!!cp (212);          !!!cp (212);
2795          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2796    
2797          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2798          !!!next-input-character;          !!!next-input-character;
# Line 2733  sub _get_next_token ($) { Line 2839  sub _get_next_token ($) {
2839          redo A;          redo A;
2840        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
2841          !!!cp (217);          !!!cp (217);
2842            !!!parse-error (type => 'unclosed DOCTYPE');
2843          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2844          ## reconsume          ## reconsume
2845    
# Line 2774  sub _get_next_token ($) { Line 2880  sub _get_next_token ($) {
2880          !!!next-input-character;          !!!next-input-character;
2881          redo A;          redo A;
2882        }        }
2883      } elsif ($self->{state} == CDATA_BLOCK_STATE) {      } elsif ($self->{state} == CDATA_SECTION_STATE) {
2884        my $s = '';        ## NOTE: "CDATA section state" in the state is jointly implemented
2885          ## by three states, |CDATA_SECTION_STATE|, |CDATA_SECTION_MSE1_STATE|,
2886          ## and |CDATA_SECTION_MSE2_STATE|.
2887                
2888        my ($l, $c) = ($self->{line}, $self->{column});        if ($self->{next_char} == 0x005D) { # ]
2889            !!!cp (221.1);
2890            $self->{state} = CDATA_SECTION_MSE1_STATE;
2891            !!!next-input-character;
2892            redo A;
2893          } elsif ($self->{next_char} == -1) {
2894            $self->{state} = DATA_STATE;
2895            !!!next-input-character;
2896            if (length $self->{current_token}->{data}) { # character
2897              !!!cp (221.2);
2898              !!!emit ($self->{current_token}); # character
2899            } else {
2900              !!!cp (221.3);
2901              ## No token to emit. $self->{current_token} is discarded.
2902            }        
2903            redo A;
2904          } else {
2905            !!!cp (221.4);
2906            $self->{current_token}->{data} .= chr $self->{next_char};
2907            ## Stay in the state.
2908            !!!next-input-character;
2909            redo A;
2910          }
2911    
2912        CS: while ($self->{next_char} != -1) {        ## ISSUE: "text tokens" in spec.
2913          if ($self->{next_char} == 0x005D) { # ]      } elsif ($self->{state} == CDATA_SECTION_MSE1_STATE) {
2914            !!!next-input-character;        if ($self->{next_char} == 0x005D) { # ]
2915            if ($self->{next_char} == 0x005D) { # ]          !!!cp (221.5);
2916              !!!next-input-character;          $self->{state} = CDATA_SECTION_MSE2_STATE;
2917              MDC: {          !!!next-input-character;
2918                if ($self->{next_char} == 0x003E) { # >          redo A;
2919                  !!!cp (221.1);        } else {
2920                  !!!next-input-character;          !!!cp (221.6);
2921                  last CS;          $self->{current_token}->{data} .= ']';
2922                } elsif ($self->{next_char} == 0x005D) { # ]          $self->{state} = CDATA_SECTION_STATE;
2923                  !!!cp (221.2);          ## Reconsume.
2924                  $s .= ']';          redo A;
2925                  !!!next-input-character;        }
2926                  redo MDC;      } elsif ($self->{state} == CDATA_SECTION_MSE2_STATE) {
2927                } else {        if ($self->{next_char} == 0x003E) { # >
2928                  !!!cp (221.3);          $self->{state} = DATA_STATE;
2929                  $s .= ']]';          !!!next-input-character;
2930                  #          if (length $self->{current_token}->{data}) { # character
2931                }            !!!cp (221.7);
2932              } # MDC            !!!emit ($self->{current_token}); # character
           } else {  
             !!!cp (221.4);  
             $s .= ']';  
             #  
           }  
2933          } else {          } else {
2934            !!!cp (221.5);            !!!cp (221.8);
2935            #            ## No token to emit. $self->{current_token} is discarded.
2936          }          }
2937          $s .= chr $self->{next_char};          redo A;
2938          } elsif ($self->{next_char} == 0x005D) { # ]
2939            !!!cp (221.9); # character
2940            $self->{current_token}->{data} .= ']'; ## Add first "]" of "]]]".
2941            ## Stay in the state.
2942          !!!next-input-character;          !!!next-input-character;
2943        } # 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});  
2944        } else {        } else {
2945          !!!cp (221.7);          !!!cp (221.11);
2946            $self->{current_token}->{data} .= ']]'; # character
2947            $self->{state} = CDATA_SECTION_STATE;
2948            ## Reconsume.
2949            redo A;
2950          }
2951        } elsif ($self->{state} == ENTITY_STATE) {
2952          if ({
2953            0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,
2954            0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, &
2955            $self->{entity_additional} => 1,
2956          }->{$self->{next_char}}) {
2957            !!!cp (1001);
2958            ## Don't consume
2959            ## No error
2960            ## Return nothing.
2961            #
2962          } elsif ($self->{next_char} == 0x0023) { # #
2963            $self->{state} = ENTITY_HASH_STATE;
2964            $self->{state_keyword} = '#';
2965            !!!next-input-character;
2966            redo A;
2967          } elsif ((0x0041 <= $self->{next_char} and
2968                    $self->{next_char} <= 0x005A) or # A..Z
2969                   (0x0061 <= $self->{next_char} and
2970                    $self->{next_char} <= 0x007A)) { # a..z
2971            require Whatpm::_NamedEntityList;
2972            $self->{state} = ENTITY_NAME_STATE;
2973            $self->{state_keyword} = chr $self->{next_char};
2974            $self->{entity__value} = $self->{state_keyword};
2975            $self->{entity__match} = 0;
2976            !!!next-input-character;
2977            redo A;
2978          } else {
2979            !!!cp (1027);
2980            !!!parse-error (type => 'bare ero');
2981            ## Return nothing.
2982            #
2983        }        }
2984    
2985        redo A;        ## NOTE: No character is consumed by the "consume a character
2986          ## reference" algorithm.  In other word, there is an "&" character
2987        ## ISSUE: "text tokens" in spec.        ## that does not introduce a character reference, which would be
2988        ## TODO: Streaming support        ## appended to the parent element or the attribute value in later
2989      } else {        ## process of the tokenizer.
       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) = @_;  
2990    
2991    my ($l, $c) = ($self->{line_prev}, $self->{column_prev});        if ($self->{entity_in_attr}) {
2992            $self->{current_attribute}->{value} .= '&';
2993            $self->{state} = $self->{last_attribute_value_state};
2994            ## Reconsume.
2995            redo A;
2996          } else {
2997            $self->{state} = DATA_STATE;
2998            ## Reconsume.
2999            !!!emit ({type => CHARACTER_TOKEN, data => '&',
3000                      line => $self->{line_prev},
3001                      column => $self->{column_prev},
3002                     });
3003            redo A;
3004          }
3005        } elsif ($self->{state} == ENTITY_HASH_STATE) {
3006          if ($self->{next_char} == 0x0078 or # x
3007              $self->{next_char} == 0x0058) { # X
3008            $self->{state} = HEXREF_X_STATE;
3009            $self->{state_keyword} .= chr $self->{next_char};
3010            !!!next-input-character;
3011            redo A;
3012          } elsif (0x0030 <= $self->{next_char} and
3013                   $self->{next_char} <= 0x0039) { # 0..9
3014            $self->{state} = NCR_NUM_STATE;
3015            $self->{state_keyword} = $self->{next_char} - 0x0030;
3016            !!!next-input-character;
3017            redo A;
3018          } else {
3019            !!!cp (1019);
3020            !!!parse-error (type => 'bare nero',
3021                            line => $self->{line_prev},
3022                            column => $self->{column_prev} - 1);
3023    
3024    if ({          ## NOTE: According to the spec algorithm, nothing is returned,
3025         0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,          ## and then "&#" is appended to the parent element or the attribute
3026         0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR          ## value in the later processing.
3027         $additional => 1,  
3028        }->{$self->{next_char}}) {          if ($self->{entity_in_attr}) {
3029      !!!cp (1001);            $self->{current_attribute}->{value} .= '&#';
3030      ## Don't consume            $self->{state} = $self->{last_attribute_value_state};
3031      ## No error            ## Reconsume.
3032      return undef;            redo A;
   } elsif ($self->{next_char} == 0x0023) { # #  
     !!!next-input-character;  
     if ($self->{next_char} == 0x0078 or # x  
         $self->{next_char} == 0x0058) { # X  
       my $code;  
       X: {  
         my $x_char = $self->{next_char};  
         !!!next-input-character;  
         if (0x0030 <= $self->{next_char} and  
             $self->{next_char} <= 0x0039) { # 0..9  
           !!!cp (1002);  
           $code ||= 0;  
           $code *= 0x10;  
           $code += $self->{next_char} - 0x0030;  
           redo X;  
         } elsif (0x0061 <= $self->{next_char} and  
                  $self->{next_char} <= 0x0066) { # a..f  
           !!!cp (1003);  
           $code ||= 0;  
           $code *= 0x10;  
           $code += $self->{next_char} - 0x0060 + 9;  
           redo X;  
         } elsif (0x0041 <= $self->{next_char} and  
                  $self->{next_char} <= 0x0046) { # A..F  
           !!!cp (1004);  
           $code ||= 0;  
           $code *= 0x10;  
           $code += $self->{next_char} - 0x0040 + 9;  
           redo X;  
         } elsif (not defined $code) { # no hexadecimal digit  
           !!!cp (1005);  
           !!!parse-error (type => 'bare hcro', line => $l, column => $c);  
           !!!back-next-input-character ($x_char, $self->{next_char});  
           $self->{next_char} = 0x0023; # #  
           return undef;  
         } elsif ($self->{next_char} == 0x003B) { # ;  
           !!!cp (1006);  
           !!!next-input-character;  
3033          } else {          } else {
3034            !!!cp (1007);            $self->{state} = DATA_STATE;
3035            !!!parse-error (type => 'no refc', line => $l, column => $c);            ## Reconsume.
3036              !!!emit ({type => CHARACTER_TOKEN,
3037                        data => '&#',
3038                        line => $self->{line_prev},
3039                        column => $self->{column_prev} - 1,
3040                       });
3041              redo A;
3042          }          }
3043          }
3044          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {      } elsif ($self->{state} == NCR_NUM_STATE) {
3045            !!!cp (1008);        if (0x0030 <= $self->{next_char} and
3046            !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);            $self->{next_char} <= 0x0039) { # 0..9
           $code = 0xFFFD;  
         } elsif ($code > 0x10FFFF) {  
           !!!cp (1009);  
           !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);  
           $code = 0xFFFD;  
         } elsif ($code == 0x000D) {  
           !!!cp (1010);  
           !!!parse-error (type => 'CR character reference', line => $l, column => $c);  
           $code = 0x000A;  
         } elsif (0x80 <= $code and $code <= 0x9F) {  
           !!!cp (1011);  
           !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);  
           $code = $c1_entity_char->{$code};  
         }  
   
         return {type => CHARACTER_TOKEN, data => chr $code,  
                 has_reference => 1,  
                 line => $l, column => $c,  
                };  
       } # X  
     } elsif (0x0030 <= $self->{next_char} and  
              $self->{next_char} <= 0x0039) { # 0..9  
       my $code = $self->{next_char} - 0x0030;  
       !!!next-input-character;  
         
       while (0x0030 <= $self->{next_char} and  
                 $self->{next_char} <= 0x0039) { # 0..9  
3047          !!!cp (1012);          !!!cp (1012);
3048          $code *= 10;          $self->{state_keyword} *= 10;
3049          $code += $self->{next_char} - 0x0030;          $self->{state_keyword} += $self->{next_char} - 0x0030;
3050                    
3051            ## Stay in the state.
3052          !!!next-input-character;          !!!next-input-character;
3053        }          redo A;
3054          } elsif ($self->{next_char} == 0x003B) { # ;
       if ($self->{next_char} == 0x003B) { # ;  
3055          !!!cp (1013);          !!!cp (1013);
3056          !!!next-input-character;          !!!next-input-character;
3057            #
3058        } else {        } else {
3059          !!!cp (1014);          !!!cp (1014);
3060          !!!parse-error (type => 'no refc', line => $l, column => $c);          !!!parse-error (type => 'no refc');
3061            ## Reconsume.
3062            #
3063        }        }
3064    
3065          my $code = $self->{state_keyword};
3066          my $l = $self->{line_prev};
3067          my $c = $self->{column_prev};
3068        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3069          !!!cp (1015);          !!!cp (1015);
3070          !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3071                            text => (sprintf 'U+%04X', $code),
3072                            line => $l, column => $c);
3073          $code = 0xFFFD;          $code = 0xFFFD;
3074        } elsif ($code > 0x10FFFF) {        } elsif ($code > 0x10FFFF) {
3075          !!!cp (1016);          !!!cp (1016);
3076          !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3077                            text => (sprintf 'U-%08X', $code),
3078                            line => $l, column => $c);
3079          $code = 0xFFFD;          $code = 0xFFFD;
3080        } elsif ($code == 0x000D) {        } elsif ($code == 0x000D) {
3081          !!!cp (1017);          !!!cp (1017);
3082          !!!parse-error (type => 'CR character reference', line => $l, column => $c);          !!!parse-error (type => 'CR character reference',
3083                            line => $l, column => $c);
3084          $code = 0x000A;          $code = 0x000A;
3085        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
3086          !!!cp (1018);          !!!cp (1018);
3087          !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'C1 character reference',
3088                            text => (sprintf 'U+%04X', $code),
3089                            line => $l, column => $c);
3090          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
3091        }        }
3092          
3093        return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1,        if ($self->{entity_in_attr}) {
3094                line => $l, column => $c,          $self->{current_attribute}->{value} .= chr $code;
3095               };          $self->{current_attribute}->{has_reference} = 1;
3096      } else {          $self->{state} = $self->{last_attribute_value_state};
3097        !!!cp (1019);          ## Reconsume.
3098        !!!parse-error (type => 'bare nero', line => $l, column => $c);          redo A;
3099        !!!back-next-input-character ($self->{next_char});        } else {
3100        $self->{next_char} = 0x0023; # #          $self->{state} = DATA_STATE;
3101        return undef;          ## Reconsume.
3102      }          !!!emit ({type => CHARACTER_TOKEN, data => chr $code,
3103    } elsif ((0x0041 <= $self->{next_char} and                    has_reference => 1,
3104              $self->{next_char} <= 0x005A) or                    line => $l, column => $c,
3105             (0x0061 <= $self->{next_char} and                   });
3106              $self->{next_char} <= 0x007A)) {          redo A;
3107      my $entity_name = chr $self->{next_char};        }
3108      !!!next-input-character;      } elsif ($self->{state} == HEXREF_X_STATE) {
3109          if ((0x0030 <= $self->{next_char} and $self->{next_char} <= 0x0039) or
3110      my $value = $entity_name;            (0x0041 <= $self->{next_char} and $self->{next_char} <= 0x0046) or
3111      my $match = 0;            (0x0061 <= $self->{next_char} and $self->{next_char} <= 0x0066)) {
3112      require Whatpm::_NamedEntityList;          # 0..9, A..F, a..f
3113      our $EntityChar;          $self->{state} = HEXREF_HEX_STATE;
3114            $self->{state_keyword} = 0;
3115      while (length $entity_name < 30 and          ## Reconsume.
3116             ## NOTE: Some number greater than the maximum length of entity name          redo A;
3117             ((0x0041 <= $self->{next_char} and # a        } else {
3118               $self->{next_char} <= 0x005A) or # x          !!!cp (1005);
3119              (0x0061 <= $self->{next_char} and # a          !!!parse-error (type => 'bare hcro',
3120               $self->{next_char} <= 0x007A) or # z                          line => $self->{line_prev},
3121              (0x0030 <= $self->{next_char} and # 0                          column => $self->{column_prev} - 2);
3122               $self->{next_char} <= 0x0039) or # 9  
3123              $self->{next_char} == 0x003B)) { # ;          ## NOTE: According to the spec algorithm, nothing is returned,
3124        $entity_name .= chr $self->{next_char};          ## and then "&#" followed by "X" or "x" is appended to the parent
3125        if (defined $EntityChar->{$entity_name}) {          ## element or the attribute value in the later processing.
3126          if ($self->{next_char} == 0x003B) { # ;  
3127            !!!cp (1020);          if ($self->{entity_in_attr}) {
3128            $value = $EntityChar->{$entity_name};            $self->{current_attribute}->{value} .= '&' . $self->{state_keyword};
3129            $match = 1;            $self->{state} = $self->{last_attribute_value_state};
3130            !!!next-input-character;            ## Reconsume.
3131            last;            redo A;
3132            } else {
3133              $self->{state} = DATA_STATE;
3134              ## Reconsume.
3135              !!!emit ({type => CHARACTER_TOKEN,
3136                        data => '&' . $self->{state_keyword},
3137                        line => $self->{line_prev},
3138                        column => $self->{column_prev} - length $self->{state_keyword},
3139                       });
3140              redo A;
3141            }
3142          }
3143        } elsif ($self->{state} == HEXREF_HEX_STATE) {
3144          if (0x0030 <= $self->{next_char} and $self->{next_char} <= 0x0039) {
3145            # 0..9
3146            !!!cp (1002);
3147            $self->{state_keyword} *= 0x10;
3148            $self->{state_keyword} += $self->{next_char} - 0x0030;
3149            ## Stay in the state.
3150            !!!next-input-character;
3151            redo A;
3152          } elsif (0x0061 <= $self->{next_char} and
3153                   $self->{next_char} <= 0x0066) { # a..f
3154            !!!cp (1003);
3155            $self->{state_keyword} *= 0x10;
3156            $self->{state_keyword} += $self->{next_char} - 0x0060 + 9;
3157            ## Stay in the state.
3158            !!!next-input-character;
3159            redo A;
3160          } elsif (0x0041 <= $self->{next_char} and
3161                   $self->{next_char} <= 0x0046) { # A..F
3162            !!!cp (1004);
3163            $self->{state_keyword} *= 0x10;
3164            $self->{state_keyword} += $self->{next_char} - 0x0040 + 9;
3165            ## Stay in the state.
3166            !!!next-input-character;
3167            redo A;
3168          } elsif ($self->{next_char} == 0x003B) { # ;
3169            !!!cp (1006);
3170            !!!next-input-character;
3171            #
3172          } else {
3173            !!!cp (1007);
3174            !!!parse-error (type => 'no refc',
3175                            line => $self->{line},
3176                            column => $self->{column});
3177            ## Reconsume.
3178            #
3179          }
3180    
3181          my $code = $self->{state_keyword};
3182          my $l = $self->{line_prev};
3183          my $c = $self->{column_prev};
3184          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3185            !!!cp (1008);
3186            !!!parse-error (type => 'invalid character reference',
3187                            text => (sprintf 'U+%04X', $code),
3188                            line => $l, column => $c);
3189            $code = 0xFFFD;
3190          } elsif ($code > 0x10FFFF) {
3191            !!!cp (1009);
3192            !!!parse-error (type => 'invalid character reference',
3193                            text => (sprintf 'U-%08X', $code),
3194                            line => $l, column => $c);
3195            $code = 0xFFFD;
3196          } elsif ($code == 0x000D) {
3197            !!!cp (1010);
3198            !!!parse-error (type => 'CR character reference', line => $l, column => $c);
3199            $code = 0x000A;
3200          } elsif (0x80 <= $code and $code <= 0x9F) {
3201            !!!cp (1011);
3202            !!!parse-error (type => 'C1 character reference', text => (sprintf 'U+%04X', $code), line => $l, column => $c);
3203            $code = $c1_entity_char->{$code};
3204          }
3205    
3206          if ($self->{entity_in_attr}) {
3207            $self->{current_attribute}->{value} .= chr $code;
3208            $self->{current_attribute}->{has_reference} = 1;
3209            $self->{state} = $self->{last_attribute_value_state};
3210            ## Reconsume.
3211            redo A;
3212          } else {
3213            $self->{state} = DATA_STATE;
3214            ## Reconsume.
3215            !!!emit ({type => CHARACTER_TOKEN, data => chr $code,
3216                      has_reference => 1,
3217                      line => $l, column => $c,
3218                     });
3219            redo A;
3220          }
3221        } elsif ($self->{state} == ENTITY_NAME_STATE) {
3222          if (length $self->{state_keyword} < 30 and
3223              ## NOTE: Some number greater than the maximum length of entity name
3224              ((0x0041 <= $self->{next_char} and # a
3225                $self->{next_char} <= 0x005A) or # x
3226               (0x0061 <= $self->{next_char} and # a
3227                $self->{next_char} <= 0x007A) or # z
3228               (0x0030 <= $self->{next_char} and # 0
3229                $self->{next_char} <= 0x0039) or # 9
3230               $self->{next_char} == 0x003B)) { # ;
3231            our $EntityChar;
3232            $self->{state_keyword} .= chr $self->{next_char};
3233            if (defined $EntityChar->{$self->{state_keyword}}) {
3234              if ($self->{next_char} == 0x003B) { # ;
3235                !!!cp (1020);
3236                $self->{entity__value} = $EntityChar->{$self->{state_keyword}};
3237                $self->{entity__match} = 1;
3238                !!!next-input-character;
3239                #
3240              } else {
3241                !!!cp (1021);
3242                $self->{entity__value} = $EntityChar->{$self->{state_keyword}};
3243                $self->{entity__match} = -1;
3244                ## Stay in the state.
3245                !!!next-input-character;
3246                redo A;
3247              }
3248          } else {          } else {
3249            !!!cp (1021);            !!!cp (1022);
3250            $value = $EntityChar->{$entity_name};            $self->{entity__value} .= chr $self->{next_char};
3251            $match = -1;            $self->{entity__match} *= 2;
3252              ## Stay in the state.
3253            !!!next-input-character;            !!!next-input-character;
3254              redo A;
3255            }
3256          }
3257    
3258          my $data;
3259          my $has_ref;
3260          if ($self->{entity__match} > 0) {
3261            !!!cp (1023);
3262            $data = $self->{entity__value};
3263            $has_ref = 1;
3264            #
3265          } elsif ($self->{entity__match} < 0) {
3266            !!!parse-error (type => 'no refc');
3267            if ($self->{entity_in_attr} and $self->{entity__match} < -1) {
3268              !!!cp (1024);
3269              $data = '&' . $self->{state_keyword};
3270              #
3271            } else {
3272              !!!cp (1025);
3273              $data = $self->{entity__value};
3274              $has_ref = 1;
3275              #
3276          }          }
3277        } else {        } else {
3278          !!!cp (1022);          !!!cp (1026);
3279          $value .= chr $self->{next_char};          !!!parse-error (type => 'bare ero',
3280          $match *= 2;                          line => $self->{line_prev},
3281          !!!next-input-character;                          column => $self->{column_prev});
3282            $data = '&' . $self->{state_keyword};
3283            #
3284        }        }
3285      }    
3286              ## NOTE: In these cases, when a character reference is found,
3287      if ($match > 0) {        ## it is consumed and a character token is returned, or, otherwise,
3288        !!!cp (1023);        ## nothing is consumed and returned, according to the spec algorithm.
3289        return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,        ## In this implementation, anything that has been examined by the
3290                line => $l, column => $c,        ## tokenizer is appended to the parent element or the attribute value
3291               };        ## as string, either literal string when no character reference or
3292      } elsif ($match < 0) {        ## entity-replaced string otherwise, in this stage, since any characters
3293        !!!parse-error (type => 'no refc', line => $l, column => $c);        ## that would not be consumed are appended in the data state or in an
3294        if ($in_attr and $match < -1) {        ## appropriate attribute value state anyway.
3295          !!!cp (1024);  
3296          return {type => CHARACTER_TOKEN, data => '&'.$entity_name,        if ($self->{entity_in_attr}) {
3297                  line => $l, column => $c,          $self->{current_attribute}->{value} .= $data;
3298                 };          $self->{current_attribute}->{has_reference} = 1 if $has_ref;
3299        } else {          $self->{state} = $self->{last_attribute_value_state};
3300          !!!cp (1025);          ## Reconsume.
3301          return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,          redo A;
3302                  line => $l, column => $c,        } else {
3303                 };          $self->{state} = DATA_STATE;
3304            ## Reconsume.
3305            !!!emit ({type => CHARACTER_TOKEN,
3306                      data => $data, has_reference => $has_ref,
3307                      line => $self->{line_prev},
3308                      column => $self->{column_prev} + 1 - length $self->{state_keyword},
3309                     });
3310            redo A;
3311        }        }
3312      } else {      } else {
3313        !!!cp (1026);        die "$0: $self->{state}: Unknown state";
       !!!parse-error (type => 'bare ero', line => $l, column => $c);  
       ## NOTE: "No characters are consumed" in the spec.  
       return {type => CHARACTER_TOKEN, data => '&'.$value,  
               line => $l, column => $c,  
              };  
3314      }      }
3315    } else {    } # A  
3316      !!!cp (1027);  
3317      ## no characters are consumed    die "$0: _get_next_token: unexpected case";
3318      !!!parse-error (type => 'bare ero', line => $l, column => $c);  } # _get_next_token
     return undef;  
   }  
 } # _tokenize_attempt_to_consume_an_entity  
3319    
3320  sub _initialize_tree_constructor ($) {  sub _initialize_tree_constructor ($) {
3321    my $self = shift;    my $self = shift;
# Line 3050  sub _initialize_tree_constructor ($) { Line 3324  sub _initialize_tree_constructor ($) {
3324    ## TODO: Turn mutation events off # MUST    ## TODO: Turn mutation events off # MUST
3325    ## TODO: Turn loose Document option (manakai extension) on    ## TODO: Turn loose Document option (manakai extension) on
3326    $self->{document}->manakai_is_html (1); # MUST    $self->{document}->manakai_is_html (1); # MUST
3327      $self->{document}->set_user_data (manakai_source_line => 1);
3328      $self->{document}->set_user_data (manakai_source_column => 1);
3329  } # _initialize_tree_constructor  } # _initialize_tree_constructor
3330    
3331  sub _terminate_tree_constructor ($) {  sub _terminate_tree_constructor ($) {
# Line 3104  sub _tree_construction_initial ($) { Line 3380  sub _tree_construction_initial ($) {
3380        ## language.        ## language.
3381        my $doctype_name = $token->{name};        my $doctype_name = $token->{name};
3382        $doctype_name = '' unless defined $doctype_name;        $doctype_name = '' unless defined $doctype_name;
3383        $doctype_name =~ tr/a-z/A-Z/;        $doctype_name =~ tr/a-z/A-Z/; # ASCII case-insensitive
3384        if (not defined $token->{name} or # <!DOCTYPE>        if (not defined $token->{name} or # <!DOCTYPE>
           defined $token->{public_identifier} or  
3385            defined $token->{system_identifier}) {            defined $token->{system_identifier}) {
3386          !!!cp ('t1');          !!!cp ('t1');
3387          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3388        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
3389          !!!cp ('t2');          !!!cp ('t2');
         ## ISSUE: ASCII case-insensitive? (in fact it does not matter)  
3390          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3391          } elsif (defined $token->{public_identifier}) {
3392            if ($token->{public_identifier} eq 'XSLT-compat') {
3393              !!!cp ('t1.2');
3394              !!!parse-error (type => 'XSLT-compat', token => $token,
3395                              level => $self->{level}->{should});
3396            } else {
3397              !!!parse-error (type => 'not HTML5', token => $token);
3398            }
3399        } else {        } else {
3400          !!!cp ('t3');          !!!cp ('t3');
3401            #
3402        }        }
3403                
3404        my $doctype = $self->{document}->create_document_type_definition        my $doctype = $self->{document}->create_document_type_definition
# Line 3416  sub _reset_insertion_mode ($) { Line 3699  sub _reset_insertion_mode ($) {
3699          ## NOTE: Strictly spaking, the line below only applies to MathML and          ## NOTE: Strictly spaking, the line below only applies to MathML and
3700          ## SVG elements.  Currently the HTML syntax supports only MathML and          ## SVG elements.  Currently the HTML syntax supports only MathML and
3701          ## SVG elements as foreigners.          ## SVG elements as foreigners.
3702          $new_mode = $self->{insertion_mode} | IN_FOREIGN_CONTENT_IM;          $new_mode = IN_BODY_IM | IN_FOREIGN_CONTENT_IM;
         ## ISSUE: What is set as the secondary insertion mode?  
3703        } elsif ($node->[1] & TABLE_CELL_EL) {        } elsif ($node->[1] & TABLE_CELL_EL) {
3704          if ($last) {          if ($last) {
3705            !!!cp ('t28.2');            !!!cp ('t28.2');
# Line 3618  sub _tree_construction_main ($) { Line 3900  sub _tree_construction_main ($) {
3900        ## NOTE: An end-of-file token.        ## NOTE: An end-of-file token.
3901        if ($content_model_flag == CDATA_CONTENT_MODEL) {        if ($content_model_flag == CDATA_CONTENT_MODEL) {
3902          !!!cp ('t43');          !!!cp ('t43');
3903          !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in CDATA:#eof', token => $token);
3904        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
3905          !!!cp ('t44');          !!!cp ('t44');
3906          !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in RCDATA:#eof', token => $token);
3907        } else {        } else {
3908          die "$0: $content_model_flag in parse_rcdata";          die "$0: $content_model_flag in parse_rcdata";
3909        }        }
# Line 3658  sub _tree_construction_main ($) { Line 3940  sub _tree_construction_main ($) {
3940        ## Ignore the token        ## Ignore the token
3941      } else {      } else {
3942        !!!cp ('t48');        !!!cp ('t48');
3943        !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);        !!!parse-error (type => 'in CDATA:#eof', token => $token);
3944        ## ISSUE: And ignore?        ## ISSUE: And ignore?
3945        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
3946      }      }
# Line 3709  sub _tree_construction_main ($) { Line 3991  sub _tree_construction_main ($) {
3991        } # AFE        } # AFE
3992        unless (defined $formatting_element) {        unless (defined $formatting_element) {
3993          !!!cp ('t53');          !!!cp ('t53');
3994          !!!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);
3995          ## Ignore the token          ## Ignore the token
3996          !!!next-token;          !!!next-token;
3997          return;          return;
# Line 3726  sub _tree_construction_main ($) { Line 4008  sub _tree_construction_main ($) {
4008              last INSCOPE;              last INSCOPE;
4009            } else { # in open elements but not in scope            } else { # in open elements but not in scope
4010              !!!cp ('t55');              !!!cp ('t55');
4011              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},              !!!parse-error (type => 'unmatched end tag',
4012                                text => $token->{tag_name},
4013                              token => $end_tag_token);                              token => $end_tag_token);
4014              ## Ignore the token              ## Ignore the token
4015              !!!next-token;              !!!next-token;
# Line 3739  sub _tree_construction_main ($) { Line 4022  sub _tree_construction_main ($) {
4022        } # INSCOPE        } # INSCOPE
4023        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
4024          !!!cp ('t57');          !!!cp ('t57');
4025          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},          !!!parse-error (type => 'unmatched end tag',
4026                            text => $token->{tag_name},
4027                          token => $end_tag_token);                          token => $end_tag_token);
4028          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
4029          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
# Line 3748  sub _tree_construction_main ($) { Line 4032  sub _tree_construction_main ($) {
4032        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
4033          !!!cp ('t58');          !!!cp ('t58');
4034          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
4035                          value => $self->{open_elements}->[-1]->[0]                          text => $self->{open_elements}->[-1]->[0]
4036                              ->manakai_local_name,                              ->manakai_local_name,
4037                          token => $end_tag_token);                          token => $end_tag_token);
4038        }        }
# Line 3957  sub _tree_construction_main ($) { Line 4241  sub _tree_construction_main ($) {
4241    B: while (1) {    B: while (1) {
4242      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
4243        !!!cp ('t73');        !!!cp ('t73');
4244        !!!parse-error (type => 'DOCTYPE in the middle', token => $token);        !!!parse-error (type => 'in html:#DOCTYPE', token => $token);
4245        ## Ignore the token        ## Ignore the token
4246        ## Stay in the phase        ## Stay in the phase
4247        !!!next-token;        !!!next-token;
# Line 3966  sub _tree_construction_main ($) { Line 4250  sub _tree_construction_main ($) {
4250               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
4251        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
4252          !!!cp ('t79');          !!!cp ('t79');
4253          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4254          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
4255        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
4256          !!!cp ('t80');          !!!cp ('t80');
4257          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4258          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
4259        } else {        } else {
4260          !!!cp ('t81');          !!!cp ('t81');
# Line 4031  sub _tree_construction_main ($) { Line 4315  sub _tree_construction_main ($) {
4315                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
4316            !!!cp ('t87.2');            !!!cp ('t87.2');
4317            !!!parse-error (type => 'not closed',            !!!parse-error (type => 'not closed',
4318                            value => $self->{open_elements}->[-1]->[0]                            text => $self->{open_elements}->[-1]->[0]
4319                                ->manakai_local_name,                                ->manakai_local_name,
4320                            token => $token);                            token => $token);
4321    
# Line 4109  sub _tree_construction_main ($) { Line 4393  sub _tree_construction_main ($) {
4393        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
4394          !!!cp ('t87.6');          !!!cp ('t87.6');
4395          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
4396                          value => $self->{open_elements}->[-1]->[0]                          text => $self->{open_elements}->[-1]->[0]
4397                              ->manakai_local_name,                              ->manakai_local_name,
4398                          token => $token);                          token => $token);
4399    
# Line 4159  sub _tree_construction_main ($) { Line 4443  sub _tree_construction_main ($) {
4443            !!!cp ('t90');            !!!cp ('t90');
4444            ## As if </noscript>            ## As if </noscript>
4445            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
4446            !!!parse-error (type => 'in noscript:#character', token => $token);            !!!parse-error (type => 'in noscript:#text', token => $token);
4447                        
4448            ## Reprocess in the "in head" insertion mode...            ## Reprocess in the "in head" insertion mode...
4449            ## As if </head>            ## As if </head>
# Line 4196  sub _tree_construction_main ($) { Line 4480  sub _tree_construction_main ($) {
4480              next B;              next B;
4481            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4482              !!!cp ('t93.2');              !!!cp ('t93.2');
4483              !!!parse-error (type => 'after head:head', token => $token); ## TODO: error type              !!!parse-error (type => 'after head', text => 'head',
4484                                token => $token);
4485              ## Ignore the token              ## Ignore the token
4486              !!!nack ('t93.3');              !!!nack ('t93.3');
4487              !!!next-token;              !!!next-token;
4488              next B;              next B;
4489            } else {            } else {
4490              !!!cp ('t95');              !!!cp ('t95');
4491              !!!parse-error (type => 'in head:head', token => $token); # or in head noscript              !!!parse-error (type => 'in head:head',
4492                                token => $token); # or in head noscript
4493              ## Ignore the token              ## Ignore the token
4494              !!!nack ('t95.1');              !!!nack ('t95.1');
4495              !!!next-token;              !!!next-token;
# Line 4228  sub _tree_construction_main ($) { Line 4514  sub _tree_construction_main ($) {
4514                  !!!cp ('t98');                  !!!cp ('t98');
4515                  ## As if </noscript>                  ## As if </noscript>
4516                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4517                  !!!parse-error (type => 'in noscript:base', token => $token);                  !!!parse-error (type => 'in noscript', text => 'base',
4518                                    token => $token);
4519                                
4520                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4521                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
# Line 4239  sub _tree_construction_main ($) { Line 4526  sub _tree_construction_main ($) {
4526                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4527                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4528                  !!!cp ('t100');                  !!!cp ('t100');
4529                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4530                                    text => $token->{tag_name}, token => $token);
4531                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4532                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4533                } else {                } else {
# Line 4256  sub _tree_construction_main ($) { Line 4544  sub _tree_construction_main ($) {
4544                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4545                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4546                  !!!cp ('t102');                  !!!cp ('t102');
4547                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4548                                    text => $token->{tag_name}, token => $token);
4549                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4550                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4551                } else {                } else {
# Line 4273  sub _tree_construction_main ($) { Line 4562  sub _tree_construction_main ($) {
4562                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4563                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4564                  !!!cp ('t104');                  !!!cp ('t104');
4565                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4566                                    text => $token->{tag_name}, token => $token);
4567                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4568                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4569                } else {                } else {
# Line 4342  sub _tree_construction_main ($) { Line 4632  sub _tree_construction_main ($) {
4632                  !!!cp ('t111');                  !!!cp ('t111');
4633                  ## As if </noscript>                  ## As if </noscript>
4634                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4635                  !!!parse-error (type => 'in noscript:title', token => $token);                  !!!parse-error (type => 'in noscript', text => 'title',
4636                                    token => $token);
4637                                
4638                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4639                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4640                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4641                  !!!cp ('t112');                  !!!cp ('t112');
4642                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4643                                    text => $token->{tag_name}, token => $token);
4644                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4645                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4646                } else {                } else {
# Line 4362  sub _tree_construction_main ($) { Line 4654  sub _tree_construction_main ($) {
4654                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4655                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4656                next B;                next B;
4657              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style' or
4658                         $token->{tag_name} eq 'noframes') {
4659                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and
4660                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
4661                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4662                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4663                  !!!cp ('t114');                  !!!cp ('t114');
4664                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4665                                    text => $token->{tag_name}, token => $token);
4666                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4667                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4668                } else {                } else {
# Line 4389  sub _tree_construction_main ($) { Line 4683  sub _tree_construction_main ($) {
4683                  next B;                  next B;
4684                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4685                  !!!cp ('t117');                  !!!cp ('t117');
4686                  !!!parse-error (type => 'in noscript:noscript', token => $token);                  !!!parse-error (type => 'in noscript', text => 'noscript',
4687                                    token => $token);
4688                  ## Ignore the token                  ## Ignore the token
4689                  !!!nack ('t117.1');                  !!!nack ('t117.1');
4690                  !!!next-token;                  !!!next-token;
# Line 4403  sub _tree_construction_main ($) { Line 4698  sub _tree_construction_main ($) {
4698                  !!!cp ('t119');                  !!!cp ('t119');
4699                  ## As if </noscript>                  ## As if </noscript>
4700                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4701                  !!!parse-error (type => 'in noscript:script', token => $token);                  !!!parse-error (type => 'in noscript', text => 'script',
4702                                    token => $token);
4703                                
4704                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4705                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4706                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4707                  !!!cp ('t120');                  !!!cp ('t120');
4708                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4709                                    text => $token->{tag_name}, token => $token);
4710                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4711                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4712                } else {                } else {
# Line 4427  sub _tree_construction_main ($) { Line 4724  sub _tree_construction_main ($) {
4724                  !!!cp ('t122');                  !!!cp ('t122');
4725                  ## As if </noscript>                  ## As if </noscript>
4726                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4727                  !!!parse-error (type => 'in noscript:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in noscript',
4728                                    text => $token->{tag_name}, token => $token);
4729                                    
4730                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4731                  ## As if </head>                  ## As if </head>
# Line 4466  sub _tree_construction_main ($) { Line 4764  sub _tree_construction_main ($) {
4764                !!!cp ('t129');                !!!cp ('t129');
4765                ## As if </noscript>                ## As if </noscript>
4766                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4767                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4768                                  text => $token->{tag_name}, token => $token);
4769                                
4770                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4771                ## As if </head>                ## As if </head>
# Line 4509  sub _tree_construction_main ($) { Line 4808  sub _tree_construction_main ($) {
4808                  !!!cp ('t133');                  !!!cp ('t133');
4809                  ## As if </noscript>                  ## As if </noscript>
4810                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4811                  !!!parse-error (type => 'in noscript:/head', token => $token);                  !!!parse-error (type => 'in noscript:/',
4812                                    text => 'head', token => $token);
4813                                    
4814                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4815                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 4524  sub _tree_construction_main ($) { Line 4824  sub _tree_construction_main ($) {
4824                  next B;                  next B;
4825                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4826                  !!!cp ('t134.1');                  !!!cp ('t134.1');
4827                  !!!parse-error (type => 'unmatched end tag:head', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'head',
4828                                    token => $token);
4829                  ## Ignore the token                  ## Ignore the token
4830                  !!!next-token;                  !!!next-token;
4831                  next B;                  next B;
# Line 4541  sub _tree_construction_main ($) { Line 4842  sub _tree_construction_main ($) {
4842                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or
4843                         $self->{insertion_mode} == AFTER_HEAD_IM) {                         $self->{insertion_mode} == AFTER_HEAD_IM) {
4844                  !!!cp ('t137');                  !!!cp ('t137');
4845                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4846                                    text => 'noscript', token => $token);
4847                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
4848                  !!!next-token;                  !!!next-token;
4849                  next B;                  next B;
# Line 4556  sub _tree_construction_main ($) { Line 4858  sub _tree_construction_main ($) {
4858                    $self->{insertion_mode} == IN_HEAD_IM or                    $self->{insertion_mode} == IN_HEAD_IM or
4859                    $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                    $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4860                  !!!cp ('t140');                  !!!cp ('t140');
4861                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4862                                    text => $token->{tag_name}, token => $token);
4863                  ## Ignore the token                  ## Ignore the token
4864                  !!!next-token;                  !!!next-token;
4865                  next B;                  next B;
4866                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4867                  !!!cp ('t140.1');                  !!!cp ('t140.1');
4868                  !!!parse-error (type => 'unmatched end tag:' . $token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4869                                    text => $token->{tag_name}, token => $token);
4870                  ## Ignore the token                  ## Ignore the token
4871                  !!!next-token;                  !!!next-token;
4872                  next B;                  next B;
# Line 4571  sub _tree_construction_main ($) { Line 4875  sub _tree_construction_main ($) {
4875                }                }
4876              } elsif ($token->{tag_name} eq 'p') {              } elsif ($token->{tag_name} eq 'p') {
4877                !!!cp ('t142');                !!!cp ('t142');
4878                !!!parse-error (type => 'unmatched end tag:p', token => $token);                !!!parse-error (type => 'unmatched end tag',
4879                                  text => $token->{tag_name}, token => $token);
4880                ## Ignore the token                ## Ignore the token
4881                !!!next-token;                !!!next-token;
4882                next B;                next B;
# Line 4594  sub _tree_construction_main ($) { Line 4899  sub _tree_construction_main ($) {
4899                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4900                  !!!cp ('t143.3');                  !!!cp ('t143.3');
4901                  ## ISSUE: Two parse errors for <head><noscript></br>                  ## ISSUE: Two parse errors for <head><noscript></br>
4902                  !!!parse-error (type => 'unmatched end tag:br', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4903                                    text => 'br', token => $token);
4904                  ## As if </noscript>                  ## As if </noscript>
4905                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4906                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
# Line 4613  sub _tree_construction_main ($) { Line 4919  sub _tree_construction_main ($) {
4919                }                }
4920    
4921                ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.                ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.
4922                !!!parse-error (type => 'unmatched end tag:br', token => $token);                !!!parse-error (type => 'unmatched end tag',
4923                                  text => 'br', token => $token);
4924                ## Ignore the token                ## Ignore the token
4925                !!!next-token;                !!!next-token;
4926                next B;                next B;
4927              } else {              } else {
4928                !!!cp ('t145');                !!!cp ('t145');
4929                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
4930                                  text => $token->{tag_name}, token => $token);
4931                ## Ignore the token                ## Ignore the token
4932                !!!next-token;                !!!next-token;
4933                next B;                next B;
# Line 4629  sub _tree_construction_main ($) { Line 4937  sub _tree_construction_main ($) {
4937                !!!cp ('t146');                !!!cp ('t146');
4938                ## As if </noscript>                ## As if </noscript>
4939                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4940                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4941                                  text => $token->{tag_name}, token => $token);
4942                                
4943                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4944                ## As if </head>                ## As if </head>
# Line 4645  sub _tree_construction_main ($) { Line 4954  sub _tree_construction_main ($) {
4954              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4955  ## ISSUE: This case cannot be reached?  ## ISSUE: This case cannot be reached?
4956                !!!cp ('t148');                !!!cp ('t148');
4957                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
4958                                  text => $token->{tag_name}, token => $token);
4959                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
4960                !!!next-token;                !!!next-token;
4961                next B;                next B;
# Line 4756  sub _tree_construction_main ($) { Line 5066  sub _tree_construction_main ($) {
5066    
5067                  !!!cp ('t153');                  !!!cp ('t153');
5068                  !!!parse-error (type => 'start tag not allowed',                  !!!parse-error (type => 'start tag not allowed',
5069                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
5070                  ## Ignore the token                  ## Ignore the token
5071                  !!!nack ('t153.1');                  !!!nack ('t153.1');
5072                  !!!next-token;                  !!!next-token;
5073                  next B;                  next B;
5074                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
5075                  !!!parse-error (type => 'not closed:caption', token => $token);                  !!!parse-error (type => 'not closed', text => 'caption',
5076                                    token => $token);
5077                                    
5078                  ## NOTE: As if </caption>.                  ## NOTE: As if </caption>.
5079                  ## have a table element in table scope                  ## have a table element in table scope
# Line 4782  sub _tree_construction_main ($) { Line 5093  sub _tree_construction_main ($) {
5093    
5094                    !!!cp ('t157');                    !!!cp ('t157');
5095                    !!!parse-error (type => 'start tag not allowed',                    !!!parse-error (type => 'start tag not allowed',
5096                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
5097                    ## Ignore the token                    ## Ignore the token
5098                    !!!nack ('t157.1');                    !!!nack ('t157.1');
5099                    !!!next-token;                    !!!next-token;
# Line 4799  sub _tree_construction_main ($) { Line 5110  sub _tree_construction_main ($) {
5110                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5111                    !!!cp ('t159');                    !!!cp ('t159');
5112                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5113                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5114                                        ->manakai_local_name,                                        ->manakai_local_name,
5115                                    token => $token);                                    token => $token);
5116                  } else {                  } else {
# Line 4841  sub _tree_construction_main ($) { Line 5152  sub _tree_construction_main ($) {
5152                  } # INSCOPE                  } # INSCOPE
5153                    unless (defined $i) {                    unless (defined $i) {
5154                      !!!cp ('t165');                      !!!cp ('t165');
5155                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5156                                        text => $token->{tag_name},
5157                                        token => $token);
5158                      ## Ignore the token                      ## Ignore the token
5159                      !!!next-token;                      !!!next-token;
5160                      next B;                      next B;
# Line 4858  sub _tree_construction_main ($) { Line 5171  sub _tree_construction_main ($) {
5171                          ne $token->{tag_name}) {                          ne $token->{tag_name}) {
5172                    !!!cp ('t167');                    !!!cp ('t167');
5173                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5174                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5175                                        ->manakai_local_name,                                        ->manakai_local_name,
5176                                    token => $token);                                    token => $token);
5177                  } else {                  } else {
# Line 4875  sub _tree_construction_main ($) { Line 5188  sub _tree_construction_main ($) {
5188                  next B;                  next B;
5189                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
5190                  !!!cp ('t169');                  !!!cp ('t169');
5191                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5192                                    text => $token->{tag_name}, token => $token);
5193                  ## Ignore the token                  ## Ignore the token
5194                  !!!next-token;                  !!!next-token;
5195                  next B;                  next B;
# Line 4902  sub _tree_construction_main ($) { Line 5216  sub _tree_construction_main ($) {
5216    
5217                    !!!cp ('t173');                    !!!cp ('t173');
5218                    !!!parse-error (type => 'unmatched end tag',                    !!!parse-error (type => 'unmatched end tag',
5219                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
5220                    ## Ignore the token                    ## Ignore the token
5221                    !!!next-token;                    !!!next-token;
5222                    next B;                    next B;
# Line 4918  sub _tree_construction_main ($) { Line 5232  sub _tree_construction_main ($) {
5232                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5233                    !!!cp ('t175');                    !!!cp ('t175');
5234                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5235                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5236                                        ->manakai_local_name,                                        ->manakai_local_name,
5237                                    token => $token);                                    token => $token);
5238                  } else {                  } else {
# Line 4935  sub _tree_construction_main ($) { Line 5249  sub _tree_construction_main ($) {
5249                  next B;                  next B;
5250                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
5251                  !!!cp ('t177');                  !!!cp ('t177');
5252                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5253                                    text => $token->{tag_name}, token => $token);
5254                  ## Ignore the token                  ## Ignore the token
5255                  !!!next-token;                  !!!next-token;
5256                  next B;                  next B;
# Line 4978  sub _tree_construction_main ($) { Line 5293  sub _tree_construction_main ($) {
5293    
5294                  !!!cp ('t182');                  !!!cp ('t182');
5295                  !!!parse-error (type => 'unmatched end tag',                  !!!parse-error (type => 'unmatched end tag',
5296                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
5297                  ## Ignore the token                  ## Ignore the token
5298                  !!!next-token;                  !!!next-token;
5299                  next B;                  next B;
5300                } # INSCOPE                } # INSCOPE
5301              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
5302                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5303                !!!parse-error (type => 'not closed:caption', token => $token);                !!!parse-error (type => 'not closed', text => 'caption',
5304                                  token => $token);
5305    
5306                ## As if </caption>                ## As if </caption>
5307                ## have a table element in table scope                ## have a table element in table scope
# Line 5003  sub _tree_construction_main ($) { Line 5319  sub _tree_construction_main ($) {
5319                } # INSCOPE                } # INSCOPE
5320                unless (defined $i) {                unless (defined $i) {
5321                  !!!cp ('t186');                  !!!cp ('t186');
5322                  !!!parse-error (type => 'unmatched end tag:caption', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5323                                    text => 'caption', token => $token);
5324                  ## Ignore the token                  ## Ignore the token
5325                  !!!next-token;                  !!!next-token;
5326                  next B;                  next B;
# Line 5018  sub _tree_construction_main ($) { Line 5335  sub _tree_construction_main ($) {
5335                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5336                  !!!cp ('t188');                  !!!cp ('t188');
5337                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5338                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5339                                      ->manakai_local_name,                                      ->manakai_local_name,
5340                                  token => $token);                                  token => $token);
5341                } else {                } else {
# Line 5038  sub _tree_construction_main ($) { Line 5355  sub _tree_construction_main ($) {
5355                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5356                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
5357                  !!!cp ('t190');                  !!!cp ('t190');
5358                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5359                                    text => $token->{tag_name}, token => $token);
5360                  ## Ignore the token                  ## Ignore the token
5361                  !!!next-token;                  !!!next-token;
5362                  next B;                  next B;
# Line 5052  sub _tree_construction_main ($) { Line 5370  sub _tree_construction_main ($) {
5370                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
5371                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5372                !!!cp ('t192');                !!!cp ('t192');
5373                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
5374                                  text => $token->{tag_name}, token => $token);
5375                ## Ignore the token                ## Ignore the token
5376                !!!next-token;                !!!next-token;
5377                next B;                next B;
# Line 5092  sub _tree_construction_main ($) { Line 5411  sub _tree_construction_main ($) {
5411            }            }
5412          }          }
5413    
5414              !!!parse-error (type => 'in table:#character', token => $token);          !!!parse-error (type => 'in table:#text', token => $token);
5415    
5416              ## As if in body, but insert into foster parent element              ## As if in body, but insert into foster parent element
5417              ## ISSUE: Spec says that "whenever a node would be inserted              ## ISSUE: Spec says that "whenever a node would be inserted
# Line 5143  sub _tree_construction_main ($) { Line 5462  sub _tree_construction_main ($) {
5462          !!!next-token;          !!!next-token;
5463          next B;          next B;
5464        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5465              if ({          if ({
5466                   tr => ($self->{insertion_mode} != IN_ROW_IM),               tr => ($self->{insertion_mode} != IN_ROW_IM),
5467                   th => 1, td => 1,               th => 1, td => 1,
5468                  }->{$token->{tag_name}}) {              }->{$token->{tag_name}}) {
5469                if ($self->{insertion_mode} == IN_TABLE_IM) {            if ($self->{insertion_mode} == IN_TABLE_IM) {
5470                  ## Clear back to table context              ## Clear back to table context
5471                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5472                                  & TABLE_SCOPING_EL)) {                              & TABLE_SCOPING_EL)) {
5473                    !!!cp ('t201');                !!!cp ('t201');
5474                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5475                  }              }
5476                                
5477                  !!!insert-element ('tbody',, $token);              !!!insert-element ('tbody',, $token);
5478                  $self->{insertion_mode} = IN_TABLE_BODY_IM;              $self->{insertion_mode} = IN_TABLE_BODY_IM;
5479                  ## reprocess in the "in table body" insertion mode...              ## reprocess in the "in table body" insertion mode...
5480                }            }
5481              
5482                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {            if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
5483                  unless ($token->{tag_name} eq 'tr') {              unless ($token->{tag_name} eq 'tr') {
5484                    !!!cp ('t202');                !!!cp ('t202');
5485                    !!!parse-error (type => 'missing start tag:tr', token => $token);                !!!parse-error (type => 'missing start tag:tr', token => $token);
5486                  }              }
5487                                    
5488                  ## Clear back to table body context              ## Clear back to table body context
5489                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5490                                  & TABLE_ROWS_SCOPING_EL)) {                              & TABLE_ROWS_SCOPING_EL)) {
5491                    !!!cp ('t203');                !!!cp ('t203');
5492                    ## ISSUE: Can this case be reached?                ## ISSUE: Can this case be reached?
5493                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5494                  }              }
5495                                    
5496                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
5497                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
# Line 5228  sub _tree_construction_main ($) { Line 5547  sub _tree_construction_main ($) {
5547                  unless (defined $i) {                  unless (defined $i) {
5548                    !!!cp ('t210');                    !!!cp ('t210');
5549  ## TODO: This type is wrong.  ## TODO: This type is wrong.
5550                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmacthed end tag',
5551                                      text => $token->{tag_name}, token => $token);
5552                    ## Ignore the token                    ## Ignore the token
5553                    !!!nack ('t210.1');                    !!!nack ('t210.1');
5554                    !!!next-token;                    !!!next-token;
# Line 5272  sub _tree_construction_main ($) { Line 5592  sub _tree_construction_main ($) {
5592                  } # INSCOPE                  } # INSCOPE
5593                  unless (defined $i) {                  unless (defined $i) {
5594                    !!!cp ('t216');                    !!!cp ('t216');
5595  ## TODO: This erorr type ios wrong.  ## TODO: This erorr type is wrong.
5596                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5597                                      text => $token->{tag_name}, token => $token);
5598                    ## Ignore the token                    ## Ignore the token
5599                    !!!nack ('t216.1');                    !!!nack ('t216.1');
5600                    !!!next-token;                    !!!next-token;
# Line 5348  sub _tree_construction_main ($) { Line 5669  sub _tree_construction_main ($) {
5669                }                }
5670              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
5671                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
5672                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
5673                                    ->manakai_local_name,                                    ->manakai_local_name,
5674                                token => $token);                                token => $token);
5675    
# Line 5369  sub _tree_construction_main ($) { Line 5690  sub _tree_construction_main ($) {
5690                unless (defined $i) {                unless (defined $i) {
5691                  !!!cp ('t223');                  !!!cp ('t223');
5692  ## TODO: The following is wrong, maybe.  ## TODO: The following is wrong, maybe.
5693                  !!!parse-error (type => 'unmatched end tag:table', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'table',
5694                                    token => $token);
5695                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
5696                  !!!nack ('t223.1');                  !!!nack ('t223.1');
5697                  !!!next-token;                  !!!next-token;
5698                  next B;                  next B;
5699                }                }
5700                                
5701  ## TODO: Followings are removed from the latest spec.  ## TODO: Followings are removed from the latest spec.
5702                ## generate implied end tags                ## generate implied end tags
5703                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
5704                  !!!cp ('t224');                  !!!cp ('t224');
# Line 5387  sub _tree_construction_main ($) { Line 5709  sub _tree_construction_main ($) {
5709                  !!!cp ('t225');                  !!!cp ('t225');
5710                  ## NOTE: |<table><tr><table>|                  ## NOTE: |<table><tr><table>|
5711                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5712                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5713                                      ->manakai_local_name,                                      ->manakai_local_name,
5714                                  token => $token);                                  token => $token);
5715                } else {                } else {
# Line 5428  sub _tree_construction_main ($) { Line 5750  sub _tree_construction_main ($) {
5750                my $type = lc $token->{attributes}->{type}->{value};                my $type = lc $token->{attributes}->{type}->{value};
5751                if ($type eq 'hidden') {                if ($type eq 'hidden') {
5752                  !!!cp ('t227.3');                  !!!cp ('t227.3');
5753                  !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in table',
5754                                    text => $token->{tag_name}, token => $token);
5755    
5756                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5757    
# Line 5456  sub _tree_construction_main ($) { Line 5779  sub _tree_construction_main ($) {
5779            #            #
5780          }          }
5781    
5782          !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in table', text => $token->{tag_name},
5783                            token => $token);
5784    
5785          $insert = $insert_to_foster;          $insert = $insert_to_foster;
5786          #          #
# Line 5478  sub _tree_construction_main ($) { Line 5802  sub _tree_construction_main ($) {
5802                } # INSCOPE                } # INSCOPE
5803                unless (defined $i) {                unless (defined $i) {
5804                  !!!cp ('t230');                  !!!cp ('t230');
5805                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5806                                    text => $token->{tag_name}, token => $token);
5807                  ## Ignore the token                  ## Ignore the token
5808                  !!!nack ('t230.1');                  !!!nack ('t230.1');
5809                  !!!next-token;                  !!!next-token;
# Line 5519  sub _tree_construction_main ($) { Line 5844  sub _tree_construction_main ($) {
5844                  unless (defined $i) {                  unless (defined $i) {
5845                    !!!cp ('t235');                    !!!cp ('t235');
5846  ## TODO: The following is wrong.  ## TODO: The following is wrong.
5847                    !!!parse-error (type => 'unmatched end tag:'.$token->{type}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5848                                      text => $token->{type}, token => $token);
5849                    ## Ignore the token                    ## Ignore the token
5850                    !!!nack ('t236.1');                    !!!nack ('t236.1');
5851                    !!!next-token;                    !!!next-token;
# Line 5555  sub _tree_construction_main ($) { Line 5881  sub _tree_construction_main ($) {
5881                  } # INSCOPE                  } # INSCOPE
5882                  unless (defined $i) {                  unless (defined $i) {
5883                    !!!cp ('t239');                    !!!cp ('t239');
5884                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5885                                      text => $token->{tag_name}, token => $token);
5886                    ## Ignore the token                    ## Ignore the token
5887                    !!!nack ('t239.1');                    !!!nack ('t239.1');
5888                    !!!next-token;                    !!!next-token;
# Line 5601  sub _tree_construction_main ($) { Line 5928  sub _tree_construction_main ($) {
5928                } # INSCOPE                } # INSCOPE
5929                unless (defined $i) {                unless (defined $i) {
5930                  !!!cp ('t243');                  !!!cp ('t243');
5931                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5932                                    text => $token->{tag_name}, token => $token);
5933                  ## Ignore the token                  ## Ignore the token
5934                  !!!nack ('t243.1');                  !!!nack ('t243.1');
5935                  !!!next-token;                  !!!next-token;
# Line 5635  sub _tree_construction_main ($) { Line 5963  sub _tree_construction_main ($) {
5963                  } # INSCOPE                  } # INSCOPE
5964                    unless (defined $i) {                    unless (defined $i) {
5965                      !!!cp ('t249');                      !!!cp ('t249');
5966                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5967                                        text => $token->{tag_name}, token => $token);
5968                      ## Ignore the token                      ## Ignore the token
5969                      !!!nack ('t249.1');                      !!!nack ('t249.1');
5970                      !!!next-token;                      !!!next-token;
# Line 5658  sub _tree_construction_main ($) { Line 5987  sub _tree_construction_main ($) {
5987                  } # INSCOPE                  } # INSCOPE
5988                    unless (defined $i) {                    unless (defined $i) {
5989                      !!!cp ('t252');                      !!!cp ('t252');
5990                      !!!parse-error (type => 'unmatched end tag:tr', token => $token);                      !!!parse-error (type => 'unmatched end tag',
5991                                        text => 'tr', token => $token);
5992                      ## Ignore the token                      ## Ignore the token
5993                      !!!nack ('t252.1');                      !!!nack ('t252.1');
5994                      !!!next-token;                      !!!next-token;
# Line 5693  sub _tree_construction_main ($) { Line 6023  sub _tree_construction_main ($) {
6023                } # INSCOPE                } # INSCOPE
6024                unless (defined $i) {                unless (defined $i) {
6025                  !!!cp ('t256');                  !!!cp ('t256');
6026                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
6027                                    text => $token->{tag_name}, token => $token);
6028                  ## Ignore the token                  ## Ignore the token
6029                  !!!nack ('t256.1');                  !!!nack ('t256.1');
6030                  !!!next-token;                  !!!next-token;
# Line 5720  sub _tree_construction_main ($) { Line 6051  sub _tree_construction_main ($) {
6051                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
6052                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
6053            !!!cp ('t258');            !!!cp ('t258');
6054            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
6055                              text => $token->{tag_name}, token => $token);
6056            ## Ignore the token            ## Ignore the token
6057            !!!nack ('t258.1');            !!!nack ('t258.1');
6058             !!!next-token;             !!!next-token;
6059            next B;            next B;
6060          } else {          } else {
6061            !!!cp ('t259');            !!!cp ('t259');
6062            !!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in table:/',
6063                              text => $token->{tag_name}, token => $token);
6064    
6065            $insert = $insert_to_foster;            $insert = $insert_to_foster;
6066            #            #
# Line 5777  sub _tree_construction_main ($) { Line 6110  sub _tree_construction_main ($) {
6110              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
6111                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
6112                  !!!cp ('t264');                  !!!cp ('t264');
6113                  !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);                  !!!parse-error (type => 'unmatched end tag',
6114                                    text => 'colgroup', token => $token);
6115                  ## Ignore the token                  ## Ignore the token
6116                  !!!next-token;                  !!!next-token;
6117                  next B;                  next B;
# Line 5790  sub _tree_construction_main ($) { Line 6124  sub _tree_construction_main ($) {
6124                }                }
6125              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
6126                !!!cp ('t266');                !!!cp ('t266');
6127                !!!parse-error (type => 'unmatched end tag:col', token => $token);                !!!parse-error (type => 'unmatched end tag',
6128                                  text => 'col', token => $token);
6129                ## Ignore the token                ## Ignore the token
6130                !!!next-token;                !!!next-token;
6131                next B;                next B;
# Line 5820  sub _tree_construction_main ($) { Line 6155  sub _tree_construction_main ($) {
6155            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
6156              !!!cp ('t269');              !!!cp ('t269');
6157  ## TODO: Wrong error type?  ## TODO: Wrong error type?
6158              !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);              !!!parse-error (type => 'unmatched end tag',
6159                                text => 'colgroup', token => $token);
6160              ## Ignore the token              ## Ignore the token
6161              !!!nack ('t269.1');              !!!nack ('t269.1');
6162              !!!next-token;              !!!next-token;
# Line 5884  sub _tree_construction_main ($) { Line 6220  sub _tree_construction_main ($) {
6220                     tr => 1, td => 1, th => 1,                     tr => 1, td => 1, th => 1,
6221                    }->{$token->{tag_name}})) {                    }->{$token->{tag_name}})) {
6222            ## TODO: The type below is not good - <select> is replaced by </select>            ## TODO: The type below is not good - <select> is replaced by </select>
6223            !!!parse-error (type => 'not closed:select', token => $token);            !!!parse-error (type => 'not closed', text => 'select',
6224                              token => $token);
6225            ## NOTE: As if the token were </select> (<select> case) or            ## NOTE: As if the token were </select> (<select> case) or
6226            ## as if there were </select> (otherwise).            ## as if there were </select> (otherwise).
6227            ## have an element in table scope            ## have an element in table scope
# Line 5902  sub _tree_construction_main ($) { Line 6239  sub _tree_construction_main ($) {
6239            } # INSCOPE            } # INSCOPE
6240            unless (defined $i) {            unless (defined $i) {
6241              !!!cp ('t280');              !!!cp ('t280');
6242              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6243                                text => 'select', token => $token);
6244              ## Ignore the token              ## Ignore the token
6245              !!!nack ('t280.1');              !!!nack ('t280.1');
6246              !!!next-token;              !!!next-token;
# Line 5926  sub _tree_construction_main ($) { Line 6264  sub _tree_construction_main ($) {
6264            }            }
6265          } else {          } else {
6266            !!!cp ('t282');            !!!cp ('t282');
6267            !!!parse-error (type => 'in select:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select',
6268                              text => $token->{tag_name}, token => $token);
6269            ## Ignore the token            ## Ignore the token
6270            !!!nack ('t282.1');            !!!nack ('t282.1');
6271            !!!next-token;            !!!next-token;
# Line 5944  sub _tree_construction_main ($) { Line 6283  sub _tree_construction_main ($) {
6283              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6284            } else {            } else {
6285              !!!cp ('t285');              !!!cp ('t285');
6286              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6287                                text => $token->{tag_name}, token => $token);
6288              ## Ignore the token              ## Ignore the token
6289            }            }
6290            !!!nack ('t285.1');            !!!nack ('t285.1');
# Line 5956  sub _tree_construction_main ($) { Line 6296  sub _tree_construction_main ($) {
6296              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6297            } else {            } else {
6298              !!!cp ('t287');              !!!cp ('t287');
6299              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6300                                text => $token->{tag_name}, token => $token);
6301              ## Ignore the token              ## Ignore the token
6302            }            }
6303            !!!nack ('t287.1');            !!!nack ('t287.1');
# Line 5978  sub _tree_construction_main ($) { Line 6319  sub _tree_construction_main ($) {
6319            } # INSCOPE            } # INSCOPE
6320            unless (defined $i) {            unless (defined $i) {
6321              !!!cp ('t290');              !!!cp ('t290');
6322              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6323                                text => $token->{tag_name}, token => $token);
6324              ## Ignore the token              ## Ignore the token
6325              !!!nack ('t290.1');              !!!nack ('t290.1');
6326              !!!next-token;              !!!next-token;
# Line 5999  sub _tree_construction_main ($) { Line 6341  sub _tree_construction_main ($) {
6341                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
6342                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
6343  ## TODO: The following is wrong?  ## TODO: The following is wrong?
6344            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
6345                              text => $token->{tag_name}, token => $token);
6346                                
6347            ## have an element in table scope            ## have an element in table scope
6348            my $i;            my $i;
# Line 6040  sub _tree_construction_main ($) { Line 6383  sub _tree_construction_main ($) {
6383            unless (defined $i) {            unless (defined $i) {
6384              !!!cp ('t297');              !!!cp ('t297');
6385  ## TODO: The following error type is correct?  ## TODO: The following error type is correct?
6386              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6387                                text => 'select', token => $token);
6388              ## Ignore the </select> token              ## Ignore the </select> token
6389              !!!nack ('t297.1');              !!!nack ('t297.1');
6390              !!!next-token; ## TODO: ok?              !!!next-token; ## TODO: ok?
# Line 6057  sub _tree_construction_main ($) { Line 6401  sub _tree_construction_main ($) {
6401            next B;            next B;
6402          } else {          } else {
6403            !!!cp ('t299');            !!!cp ('t299');
6404            !!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select:/',
6405                              text => $token->{tag_name}, token => $token);
6406            ## Ignore the token            ## Ignore the token
6407            !!!nack ('t299.3');            !!!nack ('t299.3');
6408            !!!next-token;            !!!next-token;
# Line 6095  sub _tree_construction_main ($) { Line 6440  sub _tree_construction_main ($) {
6440                    
6441          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6442            !!!cp ('t301');            !!!cp ('t301');
6443            !!!parse-error (type => 'after html:#character', token => $token);            !!!parse-error (type => 'after html:#text', token => $token);
6444    
6445            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6446          } else {          } else {
# Line 6103  sub _tree_construction_main ($) { Line 6448  sub _tree_construction_main ($) {
6448          }          }
6449                    
6450          ## "after body" insertion mode          ## "after body" insertion mode
6451          !!!parse-error (type => 'after body:#character', token => $token);          !!!parse-error (type => 'after body:#text', token => $token);
6452    
6453          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6454          ## reprocess          ## reprocess
# Line 6111  sub _tree_construction_main ($) { Line 6456  sub _tree_construction_main ($) {
6456        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
6457          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6458            !!!cp ('t303');            !!!cp ('t303');
6459            !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html',
6460                              text => $token->{tag_name}, token => $token);
6461                        
6462            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6463          } else {          } else {
# Line 6119  sub _tree_construction_main ($) { Line 6465  sub _tree_construction_main ($) {
6465          }          }
6466    
6467          ## "after body" insertion mode          ## "after body" insertion mode
6468          !!!parse-error (type => 'after body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'after body',
6469                            text => $token->{tag_name}, token => $token);
6470    
6471          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6472          !!!ack-later;          !!!ack-later;
# Line 6128  sub _tree_construction_main ($) { Line 6475  sub _tree_construction_main ($) {
6475        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6476          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6477            !!!cp ('t305');            !!!cp ('t305');
6478            !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html:/',
6479                              text => $token->{tag_name}, token => $token);
6480                        
6481            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6482            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
# Line 6140  sub _tree_construction_main ($) { Line 6488  sub _tree_construction_main ($) {
6488          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
6489            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
6490              !!!cp ('t307');              !!!cp ('t307');
6491              !!!parse-error (type => 'unmatched end tag:html', token => $token);              !!!parse-error (type => 'unmatched end tag',
6492                                text => 'html', token => $token);
6493              ## Ignore the token              ## Ignore the token
6494              !!!next-token;              !!!next-token;
6495              next B;              next B;
# Line 6152  sub _tree_construction_main ($) { Line 6501  sub _tree_construction_main ($) {
6501            }            }
6502          } else {          } else {
6503            !!!cp ('t309');            !!!cp ('t309');
6504            !!!parse-error (type => 'after body:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after body:/',
6505                              text => $token->{tag_name}, token => $token);
6506    
6507            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
6508            ## reprocess            ## reprocess
# Line 6180  sub _tree_construction_main ($) { Line 6530  sub _tree_construction_main ($) {
6530          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
6531            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6532              !!!cp ('t311');              !!!cp ('t311');
6533              !!!parse-error (type => 'in frameset:#character', token => $token);              !!!parse-error (type => 'in frameset:#text', token => $token);
6534            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6535              !!!cp ('t312');              !!!cp ('t312');
6536              !!!parse-error (type => 'after frameset:#character', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6537            } else { # "after html frameset"            } else { # "after after frameset"
6538              !!!cp ('t313');              !!!cp ('t313');
6539              !!!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);  
6540            }            }
6541                        
6542            ## Ignore the token.            ## Ignore the token.
# Line 6206  sub _tree_construction_main ($) { Line 6552  sub _tree_construction_main ($) {
6552                    
6553          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
6554        } 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');  
         }  
   
6555          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6556              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6557            !!!cp ('t318');            !!!cp ('t318');
# Line 6233  sub _tree_construction_main ($) { Line 6569  sub _tree_construction_main ($) {
6569            next B;            next B;
6570          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
6571            !!!cp ('t320');            !!!cp ('t320');
6572            ## NOTE: As if in body.            ## NOTE: As if in head.
6573            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
6574            next B;            next B;
6575    
6576              ## NOTE: |<!DOCTYPE HTML><frameset></frameset></html><noframes></noframes>|
6577              ## has no parse error.
6578          } else {          } else {
6579            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6580              !!!cp ('t321');              !!!cp ('t321');
6581              !!!parse-error (type => 'in frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset',
6582            } else {                              text => $token->{tag_name}, token => $token);
6583              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6584              !!!cp ('t322');              !!!cp ('t322');
6585              !!!parse-error (type => 'after frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after frameset',
6586                                text => $token->{tag_name}, token => $token);
6587              } else { # "after after frameset"
6588                !!!cp ('t322.2');
6589                !!!parse-error (type => 'after after frameset',
6590                                text => $token->{tag_name}, token => $token);
6591            }            }
6592            ## Ignore the token            ## Ignore the token
6593            !!!nack ('t322.1');            !!!nack ('t322.1');
# Line 6250  sub _tree_construction_main ($) { Line 6595  sub _tree_construction_main ($) {
6595            next B;            next B;
6596          }          }
6597        } 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');  
         }  
   
6598          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6599              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6600            if ($self->{open_elements}->[-1]->[1] & HTML_EL and            if ($self->{open_elements}->[-1]->[1] & HTML_EL and
6601                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
6602              !!!cp ('t325');              !!!cp ('t325');
6603              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6604                                text => $token->{tag_name}, token => $token);
6605              ## Ignore the token              ## Ignore the token
6606              !!!next-token;              !!!next-token;
6607            } else {            } else {
# Line 6291  sub _tree_construction_main ($) { Line 6627  sub _tree_construction_main ($) {
6627          } else {          } else {
6628            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6629              !!!cp ('t330');              !!!cp ('t330');
6630              !!!parse-error (type => 'in frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset:/',
6631            } else {                              text => $token->{tag_name}, token => $token);
6632              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6633                !!!cp ('t330.1');
6634                !!!parse-error (type => 'after frameset:/',
6635                                text => $token->{tag_name}, token => $token);
6636              } else { # "after after html"
6637              !!!cp ('t331');              !!!cp ('t331');
6638              !!!parse-error (type => 'after frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after after frameset:/',
6639                                text => $token->{tag_name}, token => $token);
6640            }            }
6641            ## Ignore the token            ## Ignore the token
6642            !!!next-token;            !!!next-token;
# Line 6402  sub _tree_construction_main ($) { Line 6744  sub _tree_construction_main ($) {
6744          $parse_rcdata->(RCDATA_CONTENT_MODEL);          $parse_rcdata->(RCDATA_CONTENT_MODEL);
6745          next B;          next B;
6746        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
6747          !!!parse-error (type => 'in body:body', token => $token);          !!!parse-error (type => 'in body', text => 'body', token => $token);
6748                                
6749          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
6750              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {
# Line 6522  sub _tree_construction_main ($) { Line 6864  sub _tree_construction_main ($) {
6864              if ($i != -1) {              if ($i != -1) {
6865                !!!cp ('t355');                !!!cp ('t355');
6866                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
6867                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
6868                                    ->manakai_local_name,                                    ->manakai_local_name,
6869                                token => $token);                                token => $token);
6870              } else {              } else {
# Line 6676  sub _tree_construction_main ($) { Line 7018  sub _tree_construction_main ($) {
7018                  xmp => 1,                  xmp => 1,
7019                  iframe => 1,                  iframe => 1,
7020                  noembed => 1,                  noembed => 1,
7021                  noframes => 1,                  noframes => 1, ## NOTE: This is an "as if in head" code clone.
7022                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
7023                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7024          if ($token->{tag_name} eq 'xmp') {          if ($token->{tag_name} eq 'xmp') {
# Line 6698  sub _tree_construction_main ($) { Line 7040  sub _tree_construction_main ($) {
7040            !!!next-token;            !!!next-token;
7041            next B;            next B;
7042          } else {          } else {
7043              !!!ack ('t391.1');
7044    
7045            my $at = $token->{attributes};            my $at = $token->{attributes};
7046            my $form_attrs;            my $form_attrs;
7047            $form_attrs->{action} = $at->{action} if $at->{action};            $form_attrs->{action} = $at->{action} if $at->{action};
# Line 6741  sub _tree_construction_main ($) { Line 7085  sub _tree_construction_main ($) {
7085                           line => $token->{line}, column => $token->{column}},                           line => $token->{line}, column => $token->{column}},
7086                          {type => END_TAG_TOKEN, tag_name => 'form',                          {type => END_TAG_TOKEN, tag_name => 'form',
7087                           line => $token->{line}, column => $token->{column}};                           line => $token->{line}, column => $token->{column}};
           !!!nack ('t391.1'); ## NOTE: Not acknowledged.  
7088            !!!back-token (@tokens);            !!!back-token (@tokens);
7089            !!!next-token;            !!!next-token;
7090            next B;            next B;
# Line 6789  sub _tree_construction_main ($) { Line 7132  sub _tree_construction_main ($) {
7132            ## Ignore the token            ## Ignore the token
7133          } else {          } else {
7134            !!!cp ('t398');            !!!cp ('t398');
7135            !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);            !!!parse-error (type => 'in RCDATA:#eof', token => $token);
7136          }          }
7137          !!!next-token;          !!!next-token;
7138          next B;          next B;
7139          } elsif ($token->{tag_name} eq 'rt' or
7140                   $token->{tag_name} eq 'rp') {
7141            ## has a |ruby| element in scope
7142            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
7143              my $node = $self->{open_elements}->[$_];
7144              if ($node->[1] & RUBY_EL) {
7145                !!!cp ('t398.1');
7146                ## generate implied end tags
7147                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7148                  !!!cp ('t398.2');
7149                  pop @{$self->{open_elements}};
7150                }
7151                unless ($self->{open_elements}->[-1]->[1] & RUBY_EL) {
7152                  !!!cp ('t398.3');
7153                  !!!parse-error (type => 'not closed',
7154                                  text => $self->{open_elements}->[-1]->[0]
7155                                      ->manakai_local_name,
7156                                  token => $token);
7157                  pop @{$self->{open_elements}}
7158                      while not $self->{open_elements}->[-1]->[1] & RUBY_EL;
7159                }
7160                last INSCOPE;
7161              } elsif ($node->[1] & SCOPING_EL) {
7162                !!!cp ('t398.4');
7163                last INSCOPE;
7164              }
7165            } # INSCOPE
7166    
7167            !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
7168    
7169            !!!nack ('t398.5');
7170            !!!next-token;
7171            redo B;
7172        } elsif ($token->{tag_name} eq 'math' or        } elsif ($token->{tag_name} eq 'math' or
7173                 $token->{tag_name} eq 'svg') {                 $token->{tag_name} eq 'svg') {
7174          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
7175    
7176            ## "Adjust MathML attributes" ('math' only) - done in insert-element-f
7177    
7178          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f
7179    
7180          ## "adjust foreign attributes" - done in insert-element-f          ## "adjust foreign attributes" - done in insert-element-f
# Line 6823  sub _tree_construction_main ($) { Line 7201  sub _tree_construction_main ($) {
7201                  thead => 1, tr => 1,                  thead => 1, tr => 1,
7202                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7203          !!!cp ('t401');          !!!cp ('t401');
7204          !!!parse-error (type => 'in body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in body',
7205                            text => $token->{tag_name}, token => $token);
7206          ## Ignore the token          ## Ignore the token
7207          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.
7208          !!!next-token;          !!!next-token;
# Line 6908  sub _tree_construction_main ($) { Line 7287  sub _tree_construction_main ($) {
7287            }            }
7288    
7289            !!!parse-error (type => 'start tag not allowed',            !!!parse-error (type => 'start tag not allowed',
7290                            value => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7291            ## NOTE: Ignore the token.            ## NOTE: Ignore the token.
7292            !!!next-token;            !!!next-token;
7293            next B;            next B;
# Line 6918  sub _tree_construction_main ($) { Line 7297  sub _tree_construction_main ($) {
7297            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {
7298              !!!cp ('t403');              !!!cp ('t403');
7299              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7300                              value => $_->[0]->manakai_local_name,                              text => $_->[0]->manakai_local_name,
7301                              token => $token);                              token => $token);
7302              last;              last;
7303            } else {            } else {
# Line 6938  sub _tree_construction_main ($) { Line 7317  sub _tree_construction_main ($) {
7317            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {
7318              !!!cp ('t406');              !!!cp ('t406');
7319              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7320                              value => $self->{open_elements}->[1]->[0]                              text => $self->{open_elements}->[1]->[0]
7321                                  ->manakai_local_name,                                  ->manakai_local_name,
7322                              token => $token);                              token => $token);
7323            } else {            } else {
# Line 6949  sub _tree_construction_main ($) { Line 7328  sub _tree_construction_main ($) {
7328            next B;            next B;
7329          } else {          } else {
7330            !!!cp ('t408');            !!!cp ('t408');
7331            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7332                              text => $token->{tag_name}, token => $token);
7333            ## Ignore the token            ## Ignore the token
7334            !!!next-token;            !!!next-token;
7335            next B;            next B;
# Line 6977  sub _tree_construction_main ($) { Line 7357  sub _tree_construction_main ($) {
7357    
7358          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7359            !!!cp ('t413');            !!!cp ('t413');
7360            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7361                              text => $token->{tag_name}, token => $token);
7362              ## NOTE: Ignore the token.
7363          } else {          } else {
7364            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7365            while ({            while ({
7366                      ## END_TAG_OPTIONAL_EL
7367                    dd => ($token->{tag_name} ne 'dd'),                    dd => ($token->{tag_name} ne 'dd'),
7368                    dt => ($token->{tag_name} ne 'dt'),                    dt => ($token->{tag_name} ne 'dt'),
7369                    li => ($token->{tag_name} ne 'li'),                    li => ($token->{tag_name} ne 'li'),
7370                    p => 1,                    p => 1,
7371                      rt => 1,
7372                      rp => 1,
7373                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {
7374              !!!cp ('t409');              !!!cp ('t409');
7375              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
# Line 6995  sub _tree_construction_main ($) { Line 7380  sub _tree_construction_main ($) {
7380                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7381              !!!cp ('t412');              !!!cp ('t412');
7382              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7383                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7384                                  ->manakai_local_name,                                  ->manakai_local_name,
7385                              token => $token);                              token => $token);
7386            } else {            } else {
# Line 7032  sub _tree_construction_main ($) { Line 7417  sub _tree_construction_main ($) {
7417    
7418          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7419            !!!cp ('t421');            !!!cp ('t421');
7420            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7421                              text => $token->{tag_name}, token => $token);
7422              ## NOTE: Ignore the token.
7423          } else {          } else {
7424            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7425            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7045  sub _tree_construction_main ($) { Line 7432  sub _tree_construction_main ($) {
7432                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7433              !!!cp ('t417.1');              !!!cp ('t417.1');
7434              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7435                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7436                                  ->manakai_local_name,                                  ->manakai_local_name,
7437                              token => $token);                              token => $token);
7438            } else {            } else {
# Line 7077  sub _tree_construction_main ($) { Line 7464  sub _tree_construction_main ($) {
7464    
7465          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7466            !!!cp ('t425.1');            !!!cp ('t425.1');
7467            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7468                              text => $token->{tag_name}, token => $token);
7469              ## NOTE: Ignore the token.
7470          } else {          } else {
7471            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7472            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7089  sub _tree_construction_main ($) { Line 7478  sub _tree_construction_main ($) {
7478            if ($self->{open_elements}->[-1]->[0]->manakai_local_name            if ($self->{open_elements}->[-1]->[0]->manakai_local_name
7479                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7480              !!!cp ('t425');              !!!cp ('t425');
7481              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
7482                                text => $token->{tag_name}, token => $token);
7483            } else {            } else {
7484              !!!cp ('t426');              !!!cp ('t426');
7485            }            }
# Line 7120  sub _tree_construction_main ($) { Line 7510  sub _tree_construction_main ($) {
7510                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7511              !!!cp ('t412.1');              !!!cp ('t412.1');
7512              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7513                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7514                                  ->manakai_local_name,                                  ->manakai_local_name,
7515                              token => $token);                              token => $token);
7516            } else {            } else {
# Line 7130  sub _tree_construction_main ($) { Line 7520  sub _tree_construction_main ($) {
7520            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
7521          } else {          } else {
7522            !!!cp ('t413.1');            !!!cp ('t413.1');
7523            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7524                              text => $token->{tag_name}, token => $token);
7525    
7526            !!!cp ('t415.1');            !!!cp ('t415.1');
7527            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
# Line 7153  sub _tree_construction_main ($) { Line 7544  sub _tree_construction_main ($) {
7544          next B;          next B;
7545        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
7546          !!!cp ('t428');          !!!cp ('t428');
7547          !!!parse-error (type => 'unmatched end tag:br', token => $token);          !!!parse-error (type => 'unmatched end tag',
7548                            text => 'br', token => $token);
7549    
7550          ## As if <br>          ## As if <br>
7551          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
# Line 7178  sub _tree_construction_main ($) { Line 7570  sub _tree_construction_main ($) {
7570                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
7571                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7572          !!!cp ('t429');          !!!cp ('t429');
7573          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'unmatched end tag',
7574                            text => $token->{tag_name}, token => $token);
7575          ## Ignore the token          ## Ignore the token
7576          !!!next-token;          !!!next-token;
7577          next B;          next B;
# Line 7197  sub _tree_construction_main ($) { Line 7590  sub _tree_construction_main ($) {
7590              ## generate implied end tags              ## generate implied end tags
7591              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7592                !!!cp ('t430');                !!!cp ('t430');
7593                ## ISSUE: Can this case be reached?                ## NOTE: |<ruby><rt></ruby>|.
7594                  ## ISSUE: <ruby><rt></rt> will also take this code path,
7595                  ## which seems wrong.
7596                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
7597                  $node_i++;
7598              }              }
7599                    
7600              ## Step 2              ## Step 2
# Line 7207  sub _tree_construction_main ($) { Line 7603  sub _tree_construction_main ($) {
7603                !!!cp ('t431');                !!!cp ('t431');
7604                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
7605                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
7606                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
7607                                    ->manakai_local_name,                                    ->manakai_local_name,
7608                                token => $token);                                token => $token);
7609              } else {              } else {
# Line 7215  sub _tree_construction_main ($) { Line 7611  sub _tree_construction_main ($) {
7611              }              }
7612                            
7613              ## Step 3              ## Step 3
7614              splice @{$self->{open_elements}}, $node_i;              splice @{$self->{open_elements}}, $node_i if $node_i < 0;
7615    
7616              !!!next-token;              !!!next-token;
7617              last S2;              last S2;
# Line 7226  sub _tree_construction_main ($) { Line 7622  sub _tree_construction_main ($) {
7622                  ($node->[1] & SPECIAL_EL or                  ($node->[1] & SPECIAL_EL or
7623                   $node->[1] & SCOPING_EL)) {                   $node->[1] & SCOPING_EL)) {
7624                !!!cp ('t433');                !!!cp ('t433');
7625                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
7626                                  text => $token->{tag_name}, token => $token);
7627                ## Ignore the token                ## Ignore the token
7628                !!!next-token;                !!!next-token;
7629                last S2;                last S2;
# Line 7272  sub _tree_construction_main ($) { Line 7669  sub _tree_construction_main ($) {
7669    ## TODO: script stuffs    ## TODO: script stuffs
7670  } # _tree_construct_main  } # _tree_construct_main
7671    
7672  sub set_inner_html ($$$) {  sub set_inner_html ($$$;$) {
7673    my $class = shift;    my $class = shift;
7674    my $node = shift;    my $node = shift;
7675    my $s = \$_[0];    my $s = \$_[0];
7676    my $onerror = $_[1];    my $onerror = $_[1];
7677      my $get_wrapper = $_[2] || sub ($) { return $_[0] };
7678    
7679    ## ISSUE: Should {confident} be true?    ## ISSUE: Should {confident} be true?
7680    
# Line 7295  sub set_inner_html ($$$) { Line 7693  sub set_inner_html ($$$) {
7693      }      }
7694    
7695      ## Step 3, 4, 5 # MUST      ## Step 3, 4, 5 # MUST
7696      $class->parse_string ($$s => $node, $onerror);      $class->parse_char_string ($$s => $node, $onerror, $get_wrapper);
7697    } elsif ($nt == 1) {    } elsif ($nt == 1) {
7698      ## TODO: If non-html element      ## TODO: If non-html element
7699    
7700      ## NOTE: Most of this code is copied from |parse_string|      ## NOTE: Most of this code is copied from |parse_string|
7701    
7702    ## TODO: Support for $get_wrapper
7703    
7704      ## Step 1 # MUST      ## Step 1 # MUST
7705      my $this_doc = $node->owner_document;      my $this_doc = $node->owner_document;
7706      my $doc = $this_doc->implementation->create_document;      my $doc = $this_doc->implementation->create_document;
# Line 7362  sub set_inner_html ($$$) { Line 7762  sub set_inner_html ($$$) {
7762                  0x10FFFE => 1, 0x10FFFF => 1,                  0x10FFFE => 1, 0x10FFFF => 1,
7763                 }->{$self->{next_char}}) {                 }->{$self->{next_char}}) {
7764          !!!cp ('i4.1');          !!!cp ('i4.1');
7765          !!!parse-error (type => 'control char', level => $self->{must_level});          if ($self->{next_char} < 0x10000) {
7766  ## TODO: error type documentation            !!!parse-error (type => 'control char',
7767                              text => (sprintf 'U+%04X', $self->{next_char}));
7768            } else {
7769              !!!parse-error (type => 'control char',
7770                              text => (sprintf 'U-%08X', $self->{next_char}));
7771            }
7772        }        }
7773      };      };
7774      $p->{prev_char} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];

Legend:
Removed from v.1.146  
changed lines
  Added in v.1.168

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24