/[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.76 by wakaba, Mon Mar 3 09:17:10 2008 UTC revision 1.80 by wakaba, Tue Mar 4 00:03:13 2008 UTC
# Line 387  sub _get_next_token ($) { Line 387  sub _get_next_token ($) {
387        if ($self->{next_char} == 0x0026) { # &        if ($self->{next_char} == 0x0026) { # &
388          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA
389              not $self->{escape}) {              not $self->{escape}) {
390              !!!cp (1);
391            $self->{state} = ENTITY_DATA_STATE;            $self->{state} = ENTITY_DATA_STATE;
392            !!!next-input-character;            !!!next-input-character;
393            redo A;            redo A;
394          } else {          } else {
395              !!!cp (2);
396            #            #
397          }          }
398        } elsif ($self->{next_char} == 0x002D) { # -        } elsif ($self->{next_char} == 0x002D) { # -
# Line 399  sub _get_next_token ($) { Line 401  sub _get_next_token ($) {
401              if ($self->{prev_char}->[0] == 0x002D and # -              if ($self->{prev_char}->[0] == 0x002D and # -
402                  $self->{prev_char}->[1] == 0x0021 and # !                  $self->{prev_char}->[1] == 0x0021 and # !
403                  $self->{prev_char}->[2] == 0x003C) { # <                  $self->{prev_char}->[2] == 0x003C) { # <
404                  !!!cp (3);
405                $self->{escape} = 1;                $self->{escape} = 1;
406                } else {
407                  !!!cp (4);
408              }              }
409              } else {
410                !!!cp (5);
411            }            }
412          }          }
413                    
# Line 409  sub _get_next_token ($) { Line 416  sub _get_next_token ($) {
416          if ($self->{content_model} & CM_FULL_MARKUP or # PCDATA          if ($self->{content_model} & CM_FULL_MARKUP or # PCDATA
417              (($self->{content_model} & CM_LIMITED_MARKUP) and # CDATA | RCDATA              (($self->{content_model} & CM_LIMITED_MARKUP) and # CDATA | RCDATA
418               not $self->{escape})) {               not $self->{escape})) {
419              !!!cp (6);
420            $self->{state} = TAG_OPEN_STATE;            $self->{state} = TAG_OPEN_STATE;
421            !!!next-input-character;            !!!next-input-character;
422            redo A;            redo A;
423          } else {          } else {
424              !!!cp (7);
425            #            #
426          }          }
427        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
# Line 420  sub _get_next_token ($) { Line 429  sub _get_next_token ($) {
429              ($self->{content_model} & CM_LIMITED_MARKUP)) { # RCDATA | CDATA              ($self->{content_model} & CM_LIMITED_MARKUP)) { # RCDATA | CDATA
430            if ($self->{prev_char}->[0] == 0x002D and # -            if ($self->{prev_char}->[0] == 0x002D and # -
431                $self->{prev_char}->[1] == 0x002D) { # -                $self->{prev_char}->[1] == 0x002D) { # -
432                !!!cp (8);
433              delete $self->{escape};              delete $self->{escape};
434              } else {
435                !!!cp (9);
436            }            }
437            } else {
438              !!!cp (10);
439          }          }
440                    
441          #          #
442        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
443            !!!cp (11);
444          !!!emit ({type => END_OF_FILE_TOKEN});          !!!emit ({type => END_OF_FILE_TOKEN});
445          last A; ## TODO: ok?          last A; ## TODO: ok?
446          } else {
447            !!!cp (12);
448        }        }
449        # Anything else        # Anything else
450        my $token = {type => CHARACTER_TOKEN,        my $token = {type => CHARACTER_TOKEN,
# Line 447  sub _get_next_token ($) { Line 464  sub _get_next_token ($) {
464        # next-input-character is already done        # next-input-character is already done
465    
466        unless (defined $token) {        unless (defined $token) {
467            !!!cp (13);
468          !!!emit ({type => CHARACTER_TOKEN, data => '&'});          !!!emit ({type => CHARACTER_TOKEN, data => '&'});
469        } else {        } else {
470            !!!cp (14);
471          !!!emit ($token);          !!!emit ($token);
472        }        }
473    
# Line 456  sub _get_next_token ($) { Line 475  sub _get_next_token ($) {
475      } elsif ($self->{state} == TAG_OPEN_STATE) {      } elsif ($self->{state} == TAG_OPEN_STATE) {
476        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
477          if ($self->{next_char} == 0x002F) { # /          if ($self->{next_char} == 0x002F) { # /
478              !!!cp (15);
479            !!!next-input-character;            !!!next-input-character;
480            $self->{state} = CLOSE_TAG_OPEN_STATE;            $self->{state} = CLOSE_TAG_OPEN_STATE;
481            redo A;            redo A;
482          } else {          } else {
483              !!!cp (16);
484            ## reconsume            ## reconsume
485            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
486    
# Line 469  sub _get_next_token ($) { Line 490  sub _get_next_token ($) {
490          }          }
491        } elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA        } elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA
492          if ($self->{next_char} == 0x0021) { # !          if ($self->{next_char} == 0x0021) { # !
493              !!!cp (17);
494            $self->{state} = MARKUP_DECLARATION_OPEN_STATE;            $self->{state} = MARKUP_DECLARATION_OPEN_STATE;
495            !!!next-input-character;            !!!next-input-character;
496            redo A;            redo A;
497          } elsif ($self->{next_char} == 0x002F) { # /          } elsif ($self->{next_char} == 0x002F) { # /
498              !!!cp (18);
499            $self->{state} = CLOSE_TAG_OPEN_STATE;            $self->{state} = CLOSE_TAG_OPEN_STATE;
500            !!!next-input-character;            !!!next-input-character;
501            redo A;            redo A;
502          } elsif (0x0041 <= $self->{next_char} and          } elsif (0x0041 <= $self->{next_char} and
503                   $self->{next_char} <= 0x005A) { # A..Z                   $self->{next_char} <= 0x005A) { # A..Z
504              !!!cp (19);
505            $self->{current_token}            $self->{current_token}
506              = {type => START_TAG_TOKEN,              = {type => START_TAG_TOKEN,
507                 tag_name => chr ($self->{next_char} + 0x0020)};                 tag_name => chr ($self->{next_char} + 0x0020)};
# Line 486  sub _get_next_token ($) { Line 510  sub _get_next_token ($) {
510            redo A;            redo A;
511          } elsif (0x0061 <= $self->{next_char} and          } elsif (0x0061 <= $self->{next_char} and
512                   $self->{next_char} <= 0x007A) { # a..z                   $self->{next_char} <= 0x007A) { # a..z
513              !!!cp (20);
514            $self->{current_token} = {type => START_TAG_TOKEN,            $self->{current_token} = {type => START_TAG_TOKEN,
515                              tag_name => chr ($self->{next_char})};                              tag_name => chr ($self->{next_char})};
516            $self->{state} = TAG_NAME_STATE;            $self->{state} = TAG_NAME_STATE;
517            !!!next-input-character;            !!!next-input-character;
518            redo A;            redo A;
519          } elsif ($self->{next_char} == 0x003E) { # >          } elsif ($self->{next_char} == 0x003E) { # >
520              !!!cp (21);
521            !!!parse-error (type => 'empty start tag');            !!!parse-error (type => 'empty start tag');
522            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
523            !!!next-input-character;            !!!next-input-character;
# Line 500  sub _get_next_token ($) { Line 526  sub _get_next_token ($) {
526    
527            redo A;            redo A;
528          } elsif ($self->{next_char} == 0x003F) { # ?          } elsif ($self->{next_char} == 0x003F) { # ?
529              !!!cp (22);
530            !!!parse-error (type => 'pio');            !!!parse-error (type => 'pio');
531            $self->{state} = BOGUS_COMMENT_STATE;            $self->{state} = BOGUS_COMMENT_STATE;
532            ## $self->{next_char} is intentionally left as is            ## $self->{next_char} is intentionally left as is
533            redo A;            redo A;
534          } else {          } else {
535              !!!cp (23);
536            !!!parse-error (type => 'bare stago');            !!!parse-error (type => 'bare stago');
537            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
538            ## reconsume            ## reconsume
# Line 526  sub _get_next_token ($) { Line 554  sub _get_next_token ($) {
554              my $c = ord substr ($self->{last_emitted_start_tag_name}, $i, 1);              my $c = ord substr ($self->{last_emitted_start_tag_name}, $i, 1);
555              my $C = 0x0061 <= $c && $c <= 0x007A ? $c - 0x0020 : $c;              my $C = 0x0061 <= $c && $c <= 0x007A ? $c - 0x0020 : $c;
556              if ($self->{next_char} == $c or $self->{next_char} == $C) {              if ($self->{next_char} == $c or $self->{next_char} == $C) {
557                  !!!cp (24);
558                !!!next-input-character;                !!!next-input-character;
559                next TAGNAME;                next TAGNAME;
560              } else {              } else {
561                  !!!cp (25);
562                $self->{next_char} = shift @next_char; # reconsume                $self->{next_char} = shift @next_char; # reconsume
563                !!!back-next-input-character (@next_char);                !!!back-next-input-character (@next_char);
564                $self->{state} = DATA_STATE;                $self->{state} = DATA_STATE;
# Line 548  sub _get_next_token ($) { Line 578  sub _get_next_token ($) {
578                    $self->{next_char} == 0x003E or # >                    $self->{next_char} == 0x003E or # >
579                    $self->{next_char} == 0x002F or # /                    $self->{next_char} == 0x002F or # /
580                    $self->{next_char} == -1) {                    $self->{next_char} == -1) {
581                !!!cp (26);
582              $self->{next_char} = shift @next_char; # reconsume              $self->{next_char} = shift @next_char; # reconsume
583              !!!back-next-input-character (@next_char);              !!!back-next-input-character (@next_char);
584              $self->{state} = DATA_STATE;              $self->{state} = DATA_STATE;
585              !!!emit ({type => CHARACTER_TOKEN, data => '</'});              !!!emit ({type => CHARACTER_TOKEN, data => '</'});
586              redo A;              redo A;
587            } else {            } else {
588                !!!cp (27);
589              $self->{next_char} = shift @next_char;              $self->{next_char} = shift @next_char;
590              !!!back-next-input-character (@next_char);              !!!back-next-input-character (@next_char);
591              # and consume...              # and consume...
592            }            }
593          } else {          } else {
594            ## No start tag token has ever been emitted            ## No start tag token has ever been emitted
595              !!!cp (28);
596            # next-input-character is already done            # next-input-character is already done
597            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
598            !!!emit ({type => CHARACTER_TOKEN, data => '</'});            !!!emit ({type => CHARACTER_TOKEN, data => '</'});
# Line 569  sub _get_next_token ($) { Line 602  sub _get_next_token ($) {
602                
603        if (0x0041 <= $self->{next_char} and        if (0x0041 <= $self->{next_char} and
604            $self->{next_char} <= 0x005A) { # A..Z            $self->{next_char} <= 0x005A) { # A..Z
605            !!!cp (29);
606          $self->{current_token} = {type => END_TAG_TOKEN,          $self->{current_token} = {type => END_TAG_TOKEN,
607                            tag_name => chr ($self->{next_char} + 0x0020)};                            tag_name => chr ($self->{next_char} + 0x0020)};
608          $self->{state} = TAG_NAME_STATE;          $self->{state} = TAG_NAME_STATE;
# Line 576  sub _get_next_token ($) { Line 610  sub _get_next_token ($) {
610          redo A;          redo A;
611        } elsif (0x0061 <= $self->{next_char} and        } elsif (0x0061 <= $self->{next_char} and
612                 $self->{next_char} <= 0x007A) { # a..z                 $self->{next_char} <= 0x007A) { # a..z
613            !!!cp (30);
614          $self->{current_token} = {type => END_TAG_TOKEN,          $self->{current_token} = {type => END_TAG_TOKEN,
615                            tag_name => chr ($self->{next_char})};                            tag_name => chr ($self->{next_char})};
616          $self->{state} = TAG_NAME_STATE;          $self->{state} = TAG_NAME_STATE;
617          !!!next-input-character;          !!!next-input-character;
618          redo A;          redo A;
619        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
620            !!!cp (31);
621          !!!parse-error (type => 'empty end tag');          !!!parse-error (type => 'empty end tag');
622          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
623          !!!next-input-character;          !!!next-input-character;
624          redo A;          redo A;
625        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
626            !!!cp (32);
627          !!!parse-error (type => 'bare etago');          !!!parse-error (type => 'bare etago');
628          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
629          # reconsume          # reconsume
# Line 595  sub _get_next_token ($) { Line 632  sub _get_next_token ($) {
632    
633          redo A;          redo A;
634        } else {        } else {
635            !!!cp (33);
636          !!!parse-error (type => 'bogus end tag');          !!!parse-error (type => 'bogus end tag');
637          $self->{state} = BOGUS_COMMENT_STATE;          $self->{state} = BOGUS_COMMENT_STATE;
638          ## $self->{next_char} is intentionally left as is          ## $self->{next_char} is intentionally left as is
# Line 606  sub _get_next_token ($) { Line 644  sub _get_next_token ($) {
644            $self->{next_char} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
645            $self->{next_char} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
646            $self->{next_char} == 0x0020) { # SP            $self->{next_char} == 0x0020) { # SP
647            !!!cp (34);
648          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
649          !!!next-input-character;          !!!next-input-character;
650          redo A;          redo A;
651        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
652          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
653              !!!cp (35);
654            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
655                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
656            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
657          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
658            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
659            if ($self->{current_token}->{attributes}) {            #if ($self->{current_token}->{attributes}) {
660              !!!parse-error (type => 'end tag attribute');            #  ## NOTE: This should never be reached.
661            }            #  !!! cp (36);
662              #  !!! parse-error (type => 'end tag attribute');
663              #} else {
664                !!!cp (37);
665              #}
666          } else {          } else {
667            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
668          }          }
# Line 630  sub _get_next_token ($) { Line 674  sub _get_next_token ($) {
674          redo A;          redo A;
675        } elsif (0x0041 <= $self->{next_char} and        } elsif (0x0041 <= $self->{next_char} and
676                 $self->{next_char} <= 0x005A) { # A..Z                 $self->{next_char} <= 0x005A) { # A..Z
677            !!!cp (38);
678          $self->{current_token}->{tag_name} .= chr ($self->{next_char} + 0x0020);          $self->{current_token}->{tag_name} .= chr ($self->{next_char} + 0x0020);
679            # start tag or end tag            # start tag or end tag
680          ## Stay in this state          ## Stay in this state
# Line 638  sub _get_next_token ($) { Line 683  sub _get_next_token ($) {
683        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
684          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
685          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
686              !!!cp (39);
687            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
688                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
689            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
690          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
691            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
692            if ($self->{current_token}->{attributes}) {            #if ($self->{current_token}->{attributes}) {
693              !!!parse-error (type => 'end tag attribute');            #  ## NOTE: This state should never be reached.
694            }            #  !!! cp (40);
695              #  !!! parse-error (type => 'end tag attribute');
696              #} else {
697                !!!cp (41);
698              #}
699          } else {          } else {
700            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
701          }          }
# Line 661  sub _get_next_token ($) { Line 711  sub _get_next_token ($) {
711              $self->{current_token}->{type} == START_TAG_TOKEN and              $self->{current_token}->{type} == START_TAG_TOKEN and
712              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {
713            # permitted slash            # permitted slash
714              !!!cp (42);
715            #            #
716          } else {          } else {
717              !!!cp (43);
718            !!!parse-error (type => 'nestc');            !!!parse-error (type => 'nestc');
719          }          }
720          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
721          # next-input-character is already done          # next-input-character is already done
722          redo A;          redo A;
723        } else {        } else {
724            !!!cp (44);
725          $self->{current_token}->{tag_name} .= chr $self->{next_char};          $self->{current_token}->{tag_name} .= chr $self->{next_char};
726            # start tag or end tag            # start tag or end tag
727          ## Stay in the state          ## Stay in the state
# Line 681  sub _get_next_token ($) { Line 734  sub _get_next_token ($) {
734            $self->{next_char} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
735            $self->{next_char} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
736            $self->{next_char} == 0x0020) { # SP            $self->{next_char} == 0x0020) { # SP
737            !!!cp (45);
738          ## Stay in the state          ## Stay in the state
739          !!!next-input-character;          !!!next-input-character;
740          redo A;          redo A;
741        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
742          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
743              !!!cp (46);
744            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
745                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
746            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
747          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
748            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
749            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
750                !!!cp (47);
751              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
752              } else {
753                !!!cp (48);
754            }            }
755          } else {          } else {
756            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 705  sub _get_next_token ($) { Line 763  sub _get_next_token ($) {
763          redo A;          redo A;
764        } elsif (0x0041 <= $self->{next_char} and        } elsif (0x0041 <= $self->{next_char} and
765                 $self->{next_char} <= 0x005A) { # A..Z                 $self->{next_char} <= 0x005A) { # A..Z
766            !!!cp (49);
767          $self->{current_attribute} = {name => chr ($self->{next_char} + 0x0020),          $self->{current_attribute} = {name => chr ($self->{next_char} + 0x0020),
768                                value => ''};                                value => ''};
769          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
# Line 716  sub _get_next_token ($) { Line 775  sub _get_next_token ($) {
775              $self->{current_token}->{type} == START_TAG_TOKEN and              $self->{current_token}->{type} == START_TAG_TOKEN and
776              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {
777            # permitted slash            # permitted slash
778              !!!cp (50);
779            #            #
780          } else {          } else {
781              !!!cp (51);
782            !!!parse-error (type => 'nestc');            !!!parse-error (type => 'nestc');
783          }          }
784          ## Stay in the state          ## Stay in the state
# Line 726  sub _get_next_token ($) { Line 787  sub _get_next_token ($) {
787        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
788          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
789          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
790              !!!cp (52);
791            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
792                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
793            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
794          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
795            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
796            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
797                !!!cp (53);
798              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
799              } else {
800                !!!cp (54);
801            }            }
802          } else {          } else {
803            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 749  sub _get_next_token ($) { Line 814  sub _get_next_token ($) {
814               0x0027 => 1, # '               0x0027 => 1, # '
815               0x003D => 1, # =               0x003D => 1, # =
816              }->{$self->{next_char}}) {              }->{$self->{next_char}}) {
817              !!!cp (55);
818            !!!parse-error (type => 'bad attribute name');            !!!parse-error (type => 'bad attribute name');
819            } else {
820              !!!cp (56);
821          }          }
822          $self->{current_attribute} = {name => chr ($self->{next_char}),          $self->{current_attribute} = {name => chr ($self->{next_char}),
823                                value => ''};                                value => ''};
# Line 761  sub _get_next_token ($) { Line 829  sub _get_next_token ($) {
829        my $before_leave = sub {        my $before_leave = sub {
830          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
831              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
832              !!!cp (57);
833            !!!parse-error (type => 'duplicate attribute:'.$self->{current_attribute}->{name});            !!!parse-error (type => 'duplicate attribute:'.$self->{current_attribute}->{name});
834            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{current_attribute} # MUST
835          } else {          } else {
836              !!!cp (58);
837            $self->{current_token}->{attributes}->{$self->{current_attribute}->{name}}            $self->{current_token}->{attributes}->{$self->{current_attribute}->{name}}
838              = $self->{current_attribute};              = $self->{current_attribute};
839          }          }
# Line 774  sub _get_next_token ($) { Line 844  sub _get_next_token ($) {
844            $self->{next_char} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
845            $self->{next_char} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
846            $self->{next_char} == 0x0020) { # SP            $self->{next_char} == 0x0020) { # SP
847            !!!cp (59);
848          $before_leave->();          $before_leave->();
849          $self->{state} = AFTER_ATTRIBUTE_NAME_STATE;          $self->{state} = AFTER_ATTRIBUTE_NAME_STATE;
850          !!!next-input-character;          !!!next-input-character;
851          redo A;          redo A;
852        } elsif ($self->{next_char} == 0x003D) { # =        } elsif ($self->{next_char} == 0x003D) { # =
853            !!!cp (60);
854          $before_leave->();          $before_leave->();
855          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;
856          !!!next-input-character;          !!!next-input-character;
# Line 786  sub _get_next_token ($) { Line 858  sub _get_next_token ($) {
858        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
859          $before_leave->();          $before_leave->();
860          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
861              !!!cp (61);
862            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
863                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
864            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
865          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
866              !!!cp (62);
867            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
868            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
869              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 805  sub _get_next_token ($) { Line 879  sub _get_next_token ($) {
879          redo A;          redo A;
880        } elsif (0x0041 <= $self->{next_char} and        } elsif (0x0041 <= $self->{next_char} and
881                 $self->{next_char} <= 0x005A) { # A..Z                 $self->{next_char} <= 0x005A) { # A..Z
882            !!!cp (63);
883          $self->{current_attribute}->{name} .= chr ($self->{next_char} + 0x0020);          $self->{current_attribute}->{name} .= chr ($self->{next_char} + 0x0020);
884          ## Stay in the state          ## Stay in the state
885          !!!next-input-character;          !!!next-input-character;
# Line 816  sub _get_next_token ($) { Line 891  sub _get_next_token ($) {
891              $self->{current_token}->{type} == START_TAG_TOKEN and              $self->{current_token}->{type} == START_TAG_TOKEN and
892              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {
893            # permitted slash            # permitted slash
894              !!!cp (64);
895            #            #
896          } else {          } else {
897              !!!cp (65);
898            !!!parse-error (type => 'nestc');            !!!parse-error (type => 'nestc');
899          }          }
900          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
# Line 827  sub _get_next_token ($) { Line 904  sub _get_next_token ($) {
904          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
905          $before_leave->();          $before_leave->();
906          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
907              !!!cp (66);
908            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
909                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
910            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
911          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
912            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
913            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
914                !!!cp (67);
915              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
916              } else {
917                ## NOTE: This state should never be reached.
918                !!!cp (68);
919            }            }
920          } else {          } else {
921            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 847  sub _get_next_token ($) { Line 929  sub _get_next_token ($) {
929        } else {        } else {
930          if ($self->{next_char} == 0x0022 or # "          if ($self->{next_char} == 0x0022 or # "
931              $self->{next_char} == 0x0027) { # '              $self->{next_char} == 0x0027) { # '
932              !!!cp (69);
933            !!!parse-error (type => 'bad attribute name');            !!!parse-error (type => 'bad attribute name');
934            } else {
935              !!!cp (70);
936          }          }
937          $self->{current_attribute}->{name} .= chr ($self->{next_char});          $self->{current_attribute}->{name} .= chr ($self->{next_char});
938          ## Stay in the state          ## Stay in the state
# Line 860  sub _get_next_token ($) { Line 945  sub _get_next_token ($) {
945            $self->{next_char} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
946            $self->{next_char} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
947            $self->{next_char} == 0x0020) { # SP            $self->{next_char} == 0x0020) { # SP
948            !!!cp (71);
949          ## Stay in the state          ## Stay in the state
950          !!!next-input-character;          !!!next-input-character;
951          redo A;          redo A;
952        } elsif ($self->{next_char} == 0x003D) { # =        } elsif ($self->{next_char} == 0x003D) { # =
953            !!!cp (72);
954          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;
955          !!!next-input-character;          !!!next-input-character;
956          redo A;          redo A;
957        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
958          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
959              !!!cp (73);
960            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
961                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
962            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
963          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
964            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
965            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
966                !!!cp (74);
967              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
968              } else {
969                ## NOTE: This state should never be reached.
970                !!!cp (75);
971            }            }
972          } else {          } else {
973            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 888  sub _get_next_token ($) { Line 980  sub _get_next_token ($) {
980          redo A;          redo A;
981        } elsif (0x0041 <= $self->{next_char} and        } elsif (0x0041 <= $self->{next_char} and
982                 $self->{next_char} <= 0x005A) { # A..Z                 $self->{next_char} <= 0x005A) { # A..Z
983            !!!cp (76);
984          $self->{current_attribute} = {name => chr ($self->{next_char} + 0x0020),          $self->{current_attribute} = {name => chr ($self->{next_char} + 0x0020),
985                                value => ''};                                value => ''};
986          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
# Line 899  sub _get_next_token ($) { Line 992  sub _get_next_token ($) {
992              $self->{current_token}->{type} == START_TAG_TOKEN and              $self->{current_token}->{type} == START_TAG_TOKEN and
993              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {
994            # permitted slash            # permitted slash
995              !!!cp (77);
996            #            #
997          } else {          } else {
998              !!!cp (78);
999            !!!parse-error (type => 'nestc');            !!!parse-error (type => 'nestc');
1000            ## TODO: Different error type for <aa / bb> than <aa/>            ## TODO: Different error type for <aa / bb> than <aa/>
1001          }          }
# Line 910  sub _get_next_token ($) { Line 1005  sub _get_next_token ($) {
1005        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
1006          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1007          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1008              !!!cp (79);
1009            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
1010                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
1011            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1012          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1013            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1014            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
1015                !!!cp (80);
1016              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1017              } else {
1018                ## NOTE: This state should never be reached.
1019                !!!cp (81);
1020            }            }
1021          } else {          } else {
1022            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 928  sub _get_next_token ($) { Line 1028  sub _get_next_token ($) {
1028    
1029          redo A;          redo A;
1030        } else {        } else {
1031            !!!cp (82);
1032          $self->{current_attribute} = {name => chr ($self->{next_char}),          $self->{current_attribute} = {name => chr ($self->{next_char}),
1033                                value => ''};                                value => ''};
1034          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
# Line 940  sub _get_next_token ($) { Line 1041  sub _get_next_token ($) {
1041            $self->{next_char} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
1042            $self->{next_char} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
1043            $self->{next_char} == 0x0020) { # SP                  $self->{next_char} == 0x0020) { # SP      
1044            !!!cp (83);
1045          ## Stay in the state          ## Stay in the state
1046          !!!next-input-character;          !!!next-input-character;
1047          redo A;          redo A;
1048        } elsif ($self->{next_char} == 0x0022) { # "        } elsif ($self->{next_char} == 0x0022) { # "
1049            !!!cp (84);
1050          $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;          $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
1051          !!!next-input-character;          !!!next-input-character;
1052          redo A;          redo A;
1053        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1054            !!!cp (85);
1055          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
1056          ## reconsume          ## reconsume
1057          redo A;          redo A;
1058        } elsif ($self->{next_char} == 0x0027) { # '        } elsif ($self->{next_char} == 0x0027) { # '
1059            !!!cp (86);
1060          $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;          $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
1061          !!!next-input-character;          !!!next-input-character;
1062          redo A;          redo A;
1063        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1064          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1065              !!!cp (87);
1066            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
1067                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
1068            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1069          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1070            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1071            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
1072                !!!cp (88);
1073              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1074              } else {
1075                ## NOTE: This state should never be reached.
1076                !!!cp (89);
1077            }            }
1078          } else {          } else {
1079            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 977  sub _get_next_token ($) { Line 1087  sub _get_next_token ($) {
1087        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
1088          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1089          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1090              !!!cp (90);
1091            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
1092                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
1093            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1094          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1095            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1096            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
1097                !!!cp (91);
1098              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1099              } else {
1100                ## NOTE: This state should never be reached.
1101                !!!cp (92);
1102            }            }
1103          } else {          } else {
1104            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 996  sub _get_next_token ($) { Line 1111  sub _get_next_token ($) {
1111          redo A;          redo A;
1112        } else {        } else {
1113          if ($self->{next_char} == 0x003D) { # =          if ($self->{next_char} == 0x003D) { # =
1114              !!!cp (93);
1115            !!!parse-error (type => 'bad attribute value');            !!!parse-error (type => 'bad attribute value');
1116            } else {
1117              !!!cp (94);
1118          }          }
1119          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{current_attribute}->{value} .= chr ($self->{next_char});
1120          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
# Line 1005  sub _get_next_token ($) { Line 1123  sub _get_next_token ($) {
1123        }        }
1124      } elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) {
1125        if ($self->{next_char} == 0x0022) { # "        if ($self->{next_char} == 0x0022) { # "
1126            !!!cp (95);
1127          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;
1128          !!!next-input-character;          !!!next-input-character;
1129          redo A;          redo A;
1130        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1131            !!!cp (96);
1132          $self->{last_attribute_value_state} = $self->{state};          $self->{last_attribute_value_state} = $self->{state};
1133          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;
1134          !!!next-input-character;          !!!next-input-character;
# Line 1016  sub _get_next_token ($) { Line 1136  sub _get_next_token ($) {
1136        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
1137          !!!parse-error (type => 'unclosed attribute value');          !!!parse-error (type => 'unclosed attribute value');
1138          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1139              !!!cp (97);
1140            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
1141                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
1142            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1143          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1144            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1145            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
1146                !!!cp (98);
1147              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1148              } else {
1149                ## NOTE: This state should never be reached.
1150                !!!cp (99);
1151            }            }
1152          } else {          } else {
1153            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 1034  sub _get_next_token ($) { Line 1159  sub _get_next_token ($) {
1159    
1160          redo A;          redo A;
1161        } else {        } else {
1162            !!!cp (100);
1163          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{current_attribute}->{value} .= chr ($self->{next_char});
1164          ## Stay in the state          ## Stay in the state
1165          !!!next-input-character;          !!!next-input-character;
# Line 1041  sub _get_next_token ($) { Line 1167  sub _get_next_token ($) {
1167        }        }
1168      } elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) {
1169        if ($self->{next_char} == 0x0027) { # '        if ($self->{next_char} == 0x0027) { # '
1170            !!!cp (101);
1171          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;
1172          !!!next-input-character;          !!!next-input-character;
1173          redo A;          redo A;
1174        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1175            !!!cp (102);
1176          $self->{last_attribute_value_state} = $self->{state};          $self->{last_attribute_value_state} = $self->{state};
1177          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;
1178          !!!next-input-character;          !!!next-input-character;
# Line 1052  sub _get_next_token ($) { Line 1180  sub _get_next_token ($) {
1180        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
1181          !!!parse-error (type => 'unclosed attribute value');          !!!parse-error (type => 'unclosed attribute value');
1182          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1183              !!!cp (103);
1184            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
1185                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
1186            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1187          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1188            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1189            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
1190                !!!cp (104);
1191              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1192              } else {
1193                ## NOTE: This state should never be reached.
1194                !!!cp (105);
1195            }            }
1196          } else {          } else {
1197            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 1070  sub _get_next_token ($) { Line 1203  sub _get_next_token ($) {
1203    
1204          redo A;          redo A;
1205        } else {        } else {
1206            !!!cp (106);
1207          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{current_attribute}->{value} .= chr ($self->{next_char});
1208          ## Stay in the state          ## Stay in the state
1209          !!!next-input-character;          !!!next-input-character;
# Line 1081  sub _get_next_token ($) { Line 1215  sub _get_next_token ($) {
1215            $self->{next_char} == 0x000B or # HT            $self->{next_char} == 0x000B or # HT
1216            $self->{next_char} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
1217            $self->{next_char} == 0x0020) { # SP            $self->{next_char} == 0x0020) { # SP
1218            !!!cp (107);
1219          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1220          !!!next-input-character;          !!!next-input-character;
1221          redo A;          redo A;
1222        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1223            !!!cp (108);
1224          $self->{last_attribute_value_state} = $self->{state};          $self->{last_attribute_value_state} = $self->{state};
1225          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;
1226          !!!next-input-character;          !!!next-input-character;
1227          redo A;          redo A;
1228        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1229          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1230              !!!cp (109);
1231            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
1232                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
1233            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1234          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1235            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1236            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
1237                !!!cp (110);
1238              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1239              } else {
1240                ## NOTE: This state should never be reached.
1241                !!!cp (111);
1242            }            }
1243          } else {          } else {
1244            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 1111  sub _get_next_token ($) { Line 1252  sub _get_next_token ($) {
1252        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
1253          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1254          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1255              !!!cp (112);
1256            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
1257                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
1258            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1259          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1260            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1261            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
1262                !!!cp (113);
1263              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1264              } else {
1265                ## NOTE: This state should never be reached.
1266                !!!cp (114);
1267            }            }
1268          } else {          } else {
1269            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 1134  sub _get_next_token ($) { Line 1280  sub _get_next_token ($) {
1280               0x0027 => 1, # '               0x0027 => 1, # '
1281               0x003D => 1, # =               0x003D => 1, # =
1282              }->{$self->{next_char}}) {              }->{$self->{next_char}}) {
1283              !!!cp (115);
1284            !!!parse-error (type => 'bad attribute value');            !!!parse-error (type => 'bad attribute value');
1285            } else {
1286              !!!cp (116);
1287          }          }
1288          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{current_attribute}->{value} .= chr ($self->{next_char});
1289          ## Stay in the state          ## Stay in the state
# Line 1151  sub _get_next_token ($) { Line 1300  sub _get_next_token ($) {
1300             -1);             -1);
1301    
1302        unless (defined $token) {        unless (defined $token) {
1303            !!!cp (117);
1304          $self->{current_attribute}->{value} .= '&';          $self->{current_attribute}->{value} .= '&';
1305        } else {        } else {
1306            !!!cp (118);
1307          $self->{current_attribute}->{value} .= $token->{data};          $self->{current_attribute}->{value} .= $token->{data};
1308          $self->{current_attribute}->{has_reference} = $token->{has_reference};          $self->{current_attribute}->{has_reference} = $token->{has_reference};
1309          ## ISSUE: spec says "append the returned character token to the current attribute's value"          ## ISSUE: spec says "append the returned character token to the current attribute's value"
# Line 1167  sub _get_next_token ($) { Line 1318  sub _get_next_token ($) {
1318            $self->{next_char} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
1319            $self->{next_char} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
1320            $self->{next_char} == 0x0020) { # SP            $self->{next_char} == 0x0020) { # SP
1321            !!!cp (118);
1322          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1323          !!!next-input-character;          !!!next-input-character;
1324          redo A;          redo A;
1325        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1326          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1327              !!!cp (119);
1328            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
1329                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
1330            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1331          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1332            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1333            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
1334                !!!cp (120);
1335              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1336              } else {
1337                ## NOTE: This state should never be reached.
1338                !!!cp (121);
1339            }            }
1340          } else {          } else {
1341            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 1195  sub _get_next_token ($) { Line 1352  sub _get_next_token ($) {
1352              $self->{current_token}->{type} == START_TAG_TOKEN and              $self->{current_token}->{type} == START_TAG_TOKEN and
1353              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {
1354            # permitted slash            # permitted slash
1355              !!!cp (122);
1356            #            #
1357          } else {          } else {
1358              !!!cp (123);
1359            !!!parse-error (type => 'nestc');            !!!parse-error (type => 'nestc');
1360          }          }
1361          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1362          # next-input-character is already done          # next-input-character is already done
1363          redo A;          redo A;
1364        } else {        } else {
1365            !!!cp (124);
1366          !!!parse-error (type => 'no space between attributes');          !!!parse-error (type => 'no space between attributes');
1367          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1368          ## reconsume          ## reconsume
# Line 1215  sub _get_next_token ($) { Line 1375  sub _get_next_token ($) {
1375    
1376        BC: {        BC: {
1377          if ($self->{next_char} == 0x003E) { # >          if ($self->{next_char} == 0x003E) { # >
1378              !!!cp (124);
1379            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1380            !!!next-input-character;            !!!next-input-character;
1381    
# Line 1222  sub _get_next_token ($) { Line 1383  sub _get_next_token ($) {
1383    
1384            redo A;            redo A;
1385          } elsif ($self->{next_char} == -1) {          } elsif ($self->{next_char} == -1) {
1386              !!!cp (125);
1387            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1388            ## reconsume            ## reconsume
1389    
# Line 1229  sub _get_next_token ($) { Line 1391  sub _get_next_token ($) {
1391    
1392            redo A;            redo A;
1393          } else {          } else {
1394              !!!cp (126);
1395            $token->{data} .= chr ($self->{next_char});            $token->{data} .= chr ($self->{next_char});
1396            !!!next-input-character;            !!!next-input-character;
1397            redo BC;            redo BC;
1398          }          }
1399        } # BC        } # BC
1400    
1401          die "$0: _get_next_token: unexpected case [BC]";
1402      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {
1403        ## (only happen if PCDATA state)        ## (only happen if PCDATA state)
1404    
# Line 1244  sub _get_next_token ($) { Line 1409  sub _get_next_token ($) {
1409          !!!next-input-character;          !!!next-input-character;
1410          push @next_char, $self->{next_char};          push @next_char, $self->{next_char};
1411          if ($self->{next_char} == 0x002D) { # -          if ($self->{next_char} == 0x002D) { # -
1412              !!!cp (127);
1413            $self->{current_token} = {type => COMMENT_TOKEN, data => ''};            $self->{current_token} = {type => COMMENT_TOKEN, data => ''};
1414            $self->{state} = COMMENT_START_STATE;            $self->{state} = COMMENT_START_STATE;
1415            !!!next-input-character;            !!!next-input-character;
1416            redo A;            redo A;
1417            } else {
1418              !!!cp (128);
1419          }          }
1420        } elsif ($self->{next_char} == 0x0044 or # D        } elsif ($self->{next_char} == 0x0044 or # D
1421                 $self->{next_char} == 0x0064) { # d                 $self->{next_char} == 0x0064) { # d
# Line 1275  sub _get_next_token ($) { Line 1443  sub _get_next_token ($) {
1443                    push @next_char, $self->{next_char};                    push @next_char, $self->{next_char};
1444                    if ($self->{next_char} == 0x0045 or # E                    if ($self->{next_char} == 0x0045 or # E
1445                        $self->{next_char} == 0x0065) { # e                        $self->{next_char} == 0x0065) { # e
1446                      ## ISSUE: What a stupid code this is!                      !!!cp (129);
1447                        ## TODO: What a stupid code this is!
1448                      $self->{state} = DOCTYPE_STATE;                      $self->{state} = DOCTYPE_STATE;
1449                      !!!next-input-character;                      !!!next-input-character;
1450                      redo A;                      redo A;
1451                      } else {
1452                        !!!cp (130);
1453                    }                    }
1454                    } else {
1455                      !!!cp (131);
1456                  }                  }
1457                  } else {
1458                    !!!cp (132);
1459                }                }
1460                } else {
1461                  !!!cp (133);
1462              }              }
1463              } else {
1464                !!!cp (134);
1465            }            }
1466            } else {
1467              !!!cp (135);
1468          }          }
1469          } else {
1470            !!!cp (136);
1471        }        }
1472    
1473        !!!parse-error (type => 'bogus comment');        !!!parse-error (type => 'bogus comment');
# Line 1297  sub _get_next_token ($) { Line 1480  sub _get_next_token ($) {
1480        ## 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?        ## 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?
1481      } elsif ($self->{state} == COMMENT_START_STATE) {      } elsif ($self->{state} == COMMENT_START_STATE) {
1482        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
1483            !!!cp (137);
1484          $self->{state} = COMMENT_START_DASH_STATE;          $self->{state} = COMMENT_START_DASH_STATE;
1485          !!!next-input-character;          !!!next-input-character;
1486          redo A;          redo A;
1487        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1488            !!!cp (138);
1489          !!!parse-error (type => 'bogus comment');          !!!parse-error (type => 'bogus comment');
1490          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1491          !!!next-input-character;          !!!next-input-character;
# Line 1309  sub _get_next_token ($) { Line 1494  sub _get_next_token ($) {
1494    
1495          redo A;          redo A;
1496        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
1497            !!!cp (139);
1498          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
1499          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1500          ## reconsume          ## reconsume
# Line 1317  sub _get_next_token ($) { Line 1503  sub _get_next_token ($) {
1503    
1504          redo A;          redo A;
1505        } else {        } else {
1506            !!!cp (140);
1507          $self->{current_token}->{data} # comment          $self->{current_token}->{data} # comment
1508              .= chr ($self->{next_char});              .= chr ($self->{next_char});
1509          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
# Line 1325  sub _get_next_token ($) { Line 1512  sub _get_next_token ($) {
1512        }        }
1513      } elsif ($self->{state} == COMMENT_START_DASH_STATE) {      } elsif ($self->{state} == COMMENT_START_DASH_STATE) {
1514        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
1515            !!!cp (141);
1516          $self->{state} = COMMENT_END_STATE;          $self->{state} = COMMENT_END_STATE;
1517          !!!next-input-character;          !!!next-input-character;
1518          redo A;          redo A;
1519        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1520            !!!cp (142);
1521          !!!parse-error (type => 'bogus comment');          !!!parse-error (type => 'bogus comment');
1522          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1523          !!!next-input-character;          !!!next-input-character;
# Line 1337  sub _get_next_token ($) { Line 1526  sub _get_next_token ($) {
1526    
1527          redo A;          redo A;
1528        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
1529            !!!cp (143);
1530          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
1531          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1532          ## reconsume          ## reconsume
# Line 1345  sub _get_next_token ($) { Line 1535  sub _get_next_token ($) {
1535    
1536          redo A;          redo A;
1537        } else {        } else {
1538            !!!cp (144);
1539          $self->{current_token}->{data} # comment          $self->{current_token}->{data} # comment
1540              .= '-' . chr ($self->{next_char});              .= '-' . chr ($self->{next_char});
1541          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
# Line 1353  sub _get_next_token ($) { Line 1544  sub _get_next_token ($) {
1544        }        }
1545      } elsif ($self->{state} == COMMENT_STATE) {      } elsif ($self->{state} == COMMENT_STATE) {
1546        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
1547            !!!cp (145);
1548          $self->{state} = COMMENT_END_DASH_STATE;          $self->{state} = COMMENT_END_DASH_STATE;
1549          !!!next-input-character;          !!!next-input-character;
1550          redo A;          redo A;
1551        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
1552            !!!cp (146);
1553          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
1554          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1555          ## reconsume          ## reconsume
# Line 1365  sub _get_next_token ($) { Line 1558  sub _get_next_token ($) {
1558    
1559          redo A;          redo A;
1560        } else {        } else {
1561            !!!cp (147);
1562          $self->{current_token}->{data} .= chr ($self->{next_char}); # comment          $self->{current_token}->{data} .= chr ($self->{next_char}); # comment
1563          ## Stay in the state          ## Stay in the state
1564          !!!next-input-character;          !!!next-input-character;
# Line 1372  sub _get_next_token ($) { Line 1566  sub _get_next_token ($) {
1566        }        }
1567      } elsif ($self->{state} == COMMENT_END_DASH_STATE) {      } elsif ($self->{state} == COMMENT_END_DASH_STATE) {
1568        if ($self->{next_char} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
1569            !!!cp (148);
1570          $self->{state} = COMMENT_END_STATE;          $self->{state} = COMMENT_END_STATE;
1571          !!!next-input-character;          !!!next-input-character;
1572          redo A;          redo A;
1573        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
1574            !!!cp (149);
1575          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
1576          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1577          ## reconsume          ## reconsume
# Line 1384  sub _get_next_token ($) { Line 1580  sub _get_next_token ($) {
1580    
1581          redo A;          redo A;
1582        } else {        } else {
1583            !!!cp (150);
1584          $self->{current_token}->{data} .= '-' . chr ($self->{next_char}); # comment          $self->{current_token}->{data} .= '-' . chr ($self->{next_char}); # comment
1585          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
1586          !!!next-input-character;          !!!next-input-character;
# Line 1391  sub _get_next_token ($) { Line 1588  sub _get_next_token ($) {
1588        }        }
1589      } elsif ($self->{state} == COMMENT_END_STATE) {      } elsif ($self->{state} == COMMENT_END_STATE) {
1590        if ($self->{next_char} == 0x003E) { # >        if ($self->{next_char} == 0x003E) { # >
1591            !!!cp (151);
1592          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1593          !!!next-input-character;          !!!next-input-character;
1594    
# Line 1398  sub _get_next_token ($) { Line 1596  sub _get_next_token ($) {
1596    
1597          redo A;          redo A;
1598        } elsif ($self->{next_char} == 0x002D) { # -        } elsif ($self->{next_char} == 0x002D) { # -
1599            !!!cp (152);
1600          !!!parse-error (type => 'dash in comment');          !!!parse-error (type => 'dash in comment');
1601          $self->{current_token}->{data} .= '-'; # comment          $self->{current_token}->{data} .= '-'; # comment
1602          ## Stay in the state          ## Stay in the state
1603          !!!next-input-character;          !!!next-input-character;
1604          redo A;          redo A;
1605        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
1606            !!!cp (153);
1607          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
1608          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1609          ## reconsume          ## reconsume
# Line 1412  sub _get_next_token ($) { Line 1612  sub _get_next_token ($) {
1612    
1613          redo A;          redo A;
1614        } else {        } else {
1615            !!!cp (154);
1616          !!!parse-error (type => 'dash in comment');          !!!parse-error (type => 'dash in comment');
1617          $self->{current_token}->{data} .= '--' . chr ($self->{next_char}); # comment          $self->{current_token}->{data} .= '--' . chr ($self->{next_char}); # comment
1618          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
# Line 1424  sub _get_next_token ($) { Line 1625  sub _get_next_token ($) {
1625            $self->{next_char} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
1626            $self->{next_char} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
1627            $self->{next_char} == 0x0020) { # SP            $self->{next_char} == 0x0020) { # SP
1628            !!!cp (155);
1629          $self->{state} = BEFORE_DOCTYPE_NAME_STATE;          $self->{state} = BEFORE_DOCTYPE_NAME_STATE;
1630          !!!next-input-character;          !!!next-input-character;
1631          redo A;          redo A;
1632        } else {        } else {
1633            !!!cp (156);
1634          !!!parse-error (type => 'no space before DOCTYPE name');          !!!parse-error (type => 'no space before DOCTYPE name');
1635          $self->{state} = BEFORE_DOCTYPE_NAME_STATE;          $self->{state} = BEFORE_DOCTYPE_NAME_STATE;
1636          ## reconsume          ## reconsume
# Line 1439  sub _get_next_token ($) { Line 1642  sub _get_next_token ($) {
1642            $self->{next_char} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
1643            $self->{next_char} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
1644            $self->{next_char} == 0x0020) { # SP            $self->{next_char} == 0x0020) { # SP
1645            !!!cp (157);
1646          ## Stay in the state          ## Stay in the state
1647          !!!next-input-character;          !!!next-input-character;
1648          redo A;          redo A;
1649        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1650            !!!cp (158);
1651          !!!parse-error (type => 'no DOCTYPE name');          !!!parse-error (type => 'no DOCTYPE name');
1652          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1653          !!!next-input-character;          !!!next-input-character;
# Line 1450  sub _get_next_token ($) { Line 1655  sub _get_next_token ($) {
1655          !!!emit ({type => DOCTYPE_TOKEN, quirks => 1});          !!!emit ({type => DOCTYPE_TOKEN, quirks => 1});
1656    
1657          redo A;          redo A;
1658        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
1659            !!!cp (159);
1660          !!!parse-error (type => 'no DOCTYPE name');          !!!parse-error (type => 'no DOCTYPE name');
1661          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1662          ## reconsume          ## reconsume
# Line 1459  sub _get_next_token ($) { Line 1665  sub _get_next_token ($) {
1665    
1666          redo A;          redo A;
1667        } else {        } else {
1668            !!!cp (160);
1669          $self->{current_token}          $self->{current_token}
1670              = {type => DOCTYPE_TOKEN,              = {type => DOCTYPE_TOKEN,
1671                 name => chr ($self->{next_char}),                 name => chr ($self->{next_char}),
# Line 1476  sub _get_next_token ($) { Line 1683  sub _get_next_token ($) {
1683            $self->{next_char} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
1684            $self->{next_char} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
1685            $self->{next_char} == 0x0020) { # SP            $self->{next_char} == 0x0020) { # SP
1686            !!!cp (161);
1687          $self->{state} = AFTER_DOCTYPE_NAME_STATE;          $self->{state} = AFTER_DOCTYPE_NAME_STATE;
1688          !!!next-input-character;          !!!next-input-character;
1689          redo A;          redo A;
1690        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1691            !!!cp (162);
1692          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1693          !!!next-input-character;          !!!next-input-character;
1694    
# Line 1487  sub _get_next_token ($) { Line 1696  sub _get_next_token ($) {
1696    
1697          redo A;          redo A;
1698        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
1699            !!!cp (163);
1700          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
1701          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1702          ## reconsume          ## reconsume
# Line 1496  sub _get_next_token ($) { Line 1706  sub _get_next_token ($) {
1706    
1707          redo A;          redo A;
1708        } else {        } else {
1709            !!!cp (164);
1710          $self->{current_token}->{name}          $self->{current_token}->{name}
1711            .= chr ($self->{next_char}); # DOCTYPE            .= chr ($self->{next_char}); # DOCTYPE
1712          ## Stay in the state          ## Stay in the state
# Line 1508  sub _get_next_token ($) { Line 1719  sub _get_next_token ($) {
1719            $self->{next_char} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
1720            $self->{next_char} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
1721            $self->{next_char} == 0x0020) { # SP            $self->{next_char} == 0x0020) { # SP
1722            !!!cp (165);
1723          ## Stay in the state          ## Stay in the state
1724          !!!next-input-character;          !!!next-input-character;
1725          redo A;          redo A;
1726        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1727            !!!cp (166);
1728          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1729          !!!next-input-character;          !!!next-input-character;
1730    
# Line 1519  sub _get_next_token ($) { Line 1732  sub _get_next_token ($) {
1732    
1733          redo A;          redo A;
1734        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
1735            !!!cp (167);
1736          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
1737          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1738          ## reconsume          ## reconsume
# Line 1544  sub _get_next_token ($) { Line 1758  sub _get_next_token ($) {
1758                  !!!next-input-character;                  !!!next-input-character;
1759                  if ($self->{next_char} == 0x0043 or # C                  if ($self->{next_char} == 0x0043 or # C
1760                      $self->{next_char} == 0x0063) { # c                      $self->{next_char} == 0x0063) { # c
1761                      !!!cp (168);
1762                    $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;                    $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
1763                    !!!next-input-character;                    !!!next-input-character;
1764                    redo A;                    redo A;
1765                    } else {
1766                      !!!cp (169);
1767                  }                  }
1768                  } else {
1769                    !!!cp (170);
1770                }                }
1771                } else {
1772                  !!!cp (171);
1773              }              }
1774              } else {
1775                !!!cp (172);
1776            }            }
1777            } else {
1778              !!!cp (173);
1779          }          }
1780    
1781          #          #
# Line 1571  sub _get_next_token ($) { Line 1796  sub _get_next_token ($) {
1796                  !!!next-input-character;                  !!!next-input-character;
1797                  if ($self->{next_char} == 0x004D or # M                  if ($self->{next_char} == 0x004D or # M
1798                      $self->{next_char} == 0x006D) { # m                      $self->{next_char} == 0x006D) { # m
1799                      !!!cp (174);
1800                    $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;                    $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
1801                    !!!next-input-character;                    !!!next-input-character;
1802                    redo A;                    redo A;
1803                    } else {
1804                      !!!cp (175);
1805                  }                  }
1806                  } else {
1807                    !!!cp (176);
1808                }                }
1809                } else {
1810                  !!!cp (177);
1811              }              }
1812              } else {
1813                !!!cp (178);
1814            }            }
1815            } else {
1816              !!!cp (179);
1817          }          }
1818    
1819          #          #
1820        } else {        } else {
1821            !!!cp (180);
1822          !!!next-input-character;          !!!next-input-character;
1823          #          #
1824        }        }
# Line 1597  sub _get_next_token ($) { Line 1834  sub _get_next_token ($) {
1834              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
1835              #0x000D => 1, # HT, LF, VT, FF, SP, CR              #0x000D => 1, # HT, LF, VT, FF, SP, CR
1836            }->{$self->{next_char}}) {            }->{$self->{next_char}}) {
1837            !!!cp (181);
1838          ## Stay in the state          ## Stay in the state
1839          !!!next-input-character;          !!!next-input-character;
1840          redo A;          redo A;
1841        } elsif ($self->{next_char} eq 0x0022) { # "        } elsif ($self->{next_char} eq 0x0022) { # "
1842            !!!cp (182);
1843          $self->{current_token}->{public_identifier} = ''; # DOCTYPE          $self->{current_token}->{public_identifier} = ''; # DOCTYPE
1844          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE;          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE;
1845          !!!next-input-character;          !!!next-input-character;
1846          redo A;          redo A;
1847        } elsif ($self->{next_char} eq 0x0027) { # '        } elsif ($self->{next_char} eq 0x0027) { # '
1848            !!!cp (183);
1849          $self->{current_token}->{public_identifier} = ''; # DOCTYPE          $self->{current_token}->{public_identifier} = ''; # DOCTYPE
1850          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE;          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE;
1851          !!!next-input-character;          !!!next-input-character;
1852          redo A;          redo A;
1853        } elsif ($self->{next_char} eq 0x003E) { # >        } elsif ($self->{next_char} eq 0x003E) { # >
1854            !!!cp (184);
1855          !!!parse-error (type => 'no PUBLIC literal');          !!!parse-error (type => 'no PUBLIC literal');
1856    
1857          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
# Line 1621  sub _get_next_token ($) { Line 1862  sub _get_next_token ($) {
1862    
1863          redo A;          redo A;
1864        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
1865            !!!cp (185);
1866          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
1867    
1868          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
# Line 1631  sub _get_next_token ($) { Line 1873  sub _get_next_token ($) {
1873    
1874          redo A;          redo A;
1875        } else {        } else {
1876            !!!cp (186);
1877          !!!parse-error (type => 'string after PUBLIC');          !!!parse-error (type => 'string after PUBLIC');
1878          $self->{current_token}->{quirks} = 1;          $self->{current_token}->{quirks} = 1;
1879    
# Line 1640  sub _get_next_token ($) { Line 1883  sub _get_next_token ($) {
1883        }        }
1884      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE) {
1885        if ($self->{next_char} == 0x0022) { # "        if ($self->{next_char} == 0x0022) { # "
1886            !!!cp (187);
1887          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
1888          !!!next-input-character;          !!!next-input-character;
1889          redo A;          redo A;
1890        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1891            !!!cp (188);
1892          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
1893    
1894          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
# Line 1654  sub _get_next_token ($) { Line 1899  sub _get_next_token ($) {
1899    
1900          redo A;          redo A;
1901        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
1902            !!!cp (189);
1903          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
1904    
1905          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
# Line 1664  sub _get_next_token ($) { Line 1910  sub _get_next_token ($) {
1910    
1911          redo A;          redo A;
1912        } else {        } else {
1913            !!!cp (190);
1914          $self->{current_token}->{public_identifier} # DOCTYPE          $self->{current_token}->{public_identifier} # DOCTYPE
1915              .= chr $self->{next_char};              .= chr $self->{next_char};
1916          ## Stay in the state          ## Stay in the state
# Line 1672  sub _get_next_token ($) { Line 1919  sub _get_next_token ($) {
1919        }        }
1920      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE) {
1921        if ($self->{next_char} == 0x0027) { # '        if ($self->{next_char} == 0x0027) { # '
1922            !!!cp (191);
1923          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
1924          !!!next-input-character;          !!!next-input-character;
1925          redo A;          redo A;
1926        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1927            !!!cp (192);
1928          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
1929    
1930          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
# Line 1686  sub _get_next_token ($) { Line 1935  sub _get_next_token ($) {
1935    
1936          redo A;          redo A;
1937        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
1938            !!!cp (193);
1939          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
1940    
1941          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
# Line 1696  sub _get_next_token ($) { Line 1946  sub _get_next_token ($) {
1946    
1947          redo A;          redo A;
1948        } else {        } else {
1949            !!!cp (194);
1950          $self->{current_token}->{public_identifier} # DOCTYPE          $self->{current_token}->{public_identifier} # DOCTYPE
1951              .= chr $self->{next_char};              .= chr $self->{next_char};
1952          ## Stay in the state          ## Stay in the state
# Line 1707  sub _get_next_token ($) { Line 1958  sub _get_next_token ($) {
1958              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
1959              #0x000D => 1, # HT, LF, VT, FF, SP, CR              #0x000D => 1, # HT, LF, VT, FF, SP, CR
1960            }->{$self->{next_char}}) {            }->{$self->{next_char}}) {
1961            !!!cp (195);
1962          ## Stay in the state          ## Stay in the state
1963          !!!next-input-character;          !!!next-input-character;
1964          redo A;          redo A;
1965        } elsif ($self->{next_char} == 0x0022) { # "        } elsif ($self->{next_char} == 0x0022) { # "
1966            !!!cp (196);
1967          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{current_token}->{system_identifier} = ''; # DOCTYPE
1968          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;
1969          !!!next-input-character;          !!!next-input-character;
1970          redo A;          redo A;
1971        } elsif ($self->{next_char} == 0x0027) { # '        } elsif ($self->{next_char} == 0x0027) { # '
1972            !!!cp (197);
1973          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{current_token}->{system_identifier} = ''; # DOCTYPE
1974          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;
1975          !!!next-input-character;          !!!next-input-character;
1976          redo A;          redo A;
1977        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1978            !!!cp (198);
1979          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1980          !!!next-input-character;          !!!next-input-character;
1981    
# Line 1728  sub _get_next_token ($) { Line 1983  sub _get_next_token ($) {
1983    
1984          redo A;          redo A;
1985        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
1986            !!!cp (199);
1987          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
1988    
1989          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
# Line 1738  sub _get_next_token ($) { Line 1994  sub _get_next_token ($) {
1994    
1995          redo A;          redo A;
1996        } else {        } else {
1997            !!!cp (200);
1998          !!!parse-error (type => 'string after PUBLIC literal');          !!!parse-error (type => 'string after PUBLIC literal');
1999          $self->{current_token}->{quirks} = 1;          $self->{current_token}->{quirks} = 1;
2000    
# Line 1750  sub _get_next_token ($) { Line 2007  sub _get_next_token ($) {
2007              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
2008              #0x000D => 1, # HT, LF, VT, FF, SP, CR              #0x000D => 1, # HT, LF, VT, FF, SP, CR
2009            }->{$self->{next_char}}) {            }->{$self->{next_char}}) {
2010            !!!cp (201);
2011          ## Stay in the state          ## Stay in the state
2012          !!!next-input-character;          !!!next-input-character;
2013          redo A;          redo A;
2014        } elsif ($self->{next_char} == 0x0022) { # "        } elsif ($self->{next_char} == 0x0022) { # "
2015            !!!cp (202);
2016          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{current_token}->{system_identifier} = ''; # DOCTYPE
2017          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;
2018          !!!next-input-character;          !!!next-input-character;
2019          redo A;          redo A;
2020        } elsif ($self->{next_char} == 0x0027) { # '        } elsif ($self->{next_char} == 0x0027) { # '
2021            !!!cp (203);
2022          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{current_token}->{system_identifier} = ''; # DOCTYPE
2023          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;
2024          !!!next-input-character;          !!!next-input-character;
2025          redo A;          redo A;
2026        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2027            !!!cp (204);
2028          !!!parse-error (type => 'no SYSTEM literal');          !!!parse-error (type => 'no SYSTEM literal');
2029          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2030          !!!next-input-character;          !!!next-input-character;
# Line 1773  sub _get_next_token ($) { Line 2034  sub _get_next_token ($) {
2034    
2035          redo A;          redo A;
2036        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
2037            !!!cp (205);
2038          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2039    
2040          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
# Line 1783  sub _get_next_token ($) { Line 2045  sub _get_next_token ($) {
2045    
2046          redo A;          redo A;
2047        } else {        } else {
2048            !!!cp (206);
2049          !!!parse-error (type => 'string after SYSTEM');          !!!parse-error (type => 'string after SYSTEM');
2050          $self->{current_token}->{quirks} = 1;          $self->{current_token}->{quirks} = 1;
2051    
# Line 1792  sub _get_next_token ($) { Line 2055  sub _get_next_token ($) {
2055        }        }
2056      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE) {
2057        if ($self->{next_char} == 0x0022) { # "        if ($self->{next_char} == 0x0022) { # "
2058            !!!cp (207);
2059          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2060          !!!next-input-character;          !!!next-input-character;
2061          redo A;          redo A;
2062        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2063            !!!cp (208);
2064          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2065    
2066          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
# Line 1806  sub _get_next_token ($) { Line 2071  sub _get_next_token ($) {
2071    
2072          redo A;          redo A;
2073        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
2074            !!!cp (209);
2075          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2076    
2077          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
# Line 1816  sub _get_next_token ($) { Line 2082  sub _get_next_token ($) {
2082    
2083          redo A;          redo A;
2084        } else {        } else {
2085            !!!cp (210);
2086          $self->{current_token}->{system_identifier} # DOCTYPE          $self->{current_token}->{system_identifier} # DOCTYPE
2087              .= chr $self->{next_char};              .= chr $self->{next_char};
2088          ## Stay in the state          ## Stay in the state
# Line 1824  sub _get_next_token ($) { Line 2091  sub _get_next_token ($) {
2091        }        }
2092      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE) {
2093        if ($self->{next_char} == 0x0027) { # '        if ($self->{next_char} == 0x0027) { # '
2094            !!!cp (211);
2095          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2096          !!!next-input-character;          !!!next-input-character;
2097          redo A;          redo A;
2098        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2099            !!!cp (212);
2100          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2101    
2102          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
# Line 1838  sub _get_next_token ($) { Line 2107  sub _get_next_token ($) {
2107    
2108          redo A;          redo A;
2109        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
2110            !!!cp (213);
2111          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2112    
2113          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
# Line 1848  sub _get_next_token ($) { Line 2118  sub _get_next_token ($) {
2118    
2119          redo A;          redo A;
2120        } else {        } else {
2121            !!!cp (214);
2122          $self->{current_token}->{system_identifier} # DOCTYPE          $self->{current_token}->{system_identifier} # DOCTYPE
2123              .= chr $self->{next_char};              .= chr $self->{next_char};
2124          ## Stay in the state          ## Stay in the state
# Line 1859  sub _get_next_token ($) { Line 2130  sub _get_next_token ($) {
2130              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
2131              #0x000D => 1, # HT, LF, VT, FF, SP, CR              #0x000D => 1, # HT, LF, VT, FF, SP, CR
2132            }->{$self->{next_char}}) {            }->{$self->{next_char}}) {
2133            !!!cp (215);
2134          ## Stay in the state          ## Stay in the state
2135          !!!next-input-character;          !!!next-input-character;
2136          redo A;          redo A;
2137        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2138            !!!cp (216);
2139          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2140          !!!next-input-character;          !!!next-input-character;
2141    
# Line 1870  sub _get_next_token ($) { Line 2143  sub _get_next_token ($) {
2143    
2144          redo A;          redo A;
2145        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
2146            !!!cp (217);
2147          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2148    
2149          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
# Line 1880  sub _get_next_token ($) { Line 2154  sub _get_next_token ($) {
2154    
2155          redo A;          redo A;
2156        } else {        } else {
2157            !!!cp (218);
2158          !!!parse-error (type => 'string after SYSTEM literal');          !!!parse-error (type => 'string after SYSTEM literal');
2159          #$self->{current_token}->{quirks} = 1;          #$self->{current_token}->{quirks} = 1;
2160    
# Line 1889  sub _get_next_token ($) { Line 2164  sub _get_next_token ($) {
2164        }        }
2165      } elsif ($self->{state} == BOGUS_DOCTYPE_STATE) {      } elsif ($self->{state} == BOGUS_DOCTYPE_STATE) {
2166        if ($self->{next_char} == 0x003E) { # >        if ($self->{next_char} == 0x003E) { # >
2167            !!!cp (219);
2168          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2169          !!!next-input-character;          !!!next-input-character;
2170    
# Line 1896  sub _get_next_token ($) { Line 2172  sub _get_next_token ($) {
2172    
2173          redo A;          redo A;
2174        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
2175            !!!cp (220);
2176          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2177          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2178          ## reconsume          ## reconsume
# Line 1904  sub _get_next_token ($) { Line 2181  sub _get_next_token ($) {
2181    
2182          redo A;          redo A;
2183        } else {        } else {
2184            !!!cp (221);
2185          ## Stay in the state          ## Stay in the state
2186          !!!next-input-character;          !!!next-input-character;
2187          redo A;          redo A;
# Line 1924  sub _tokenize_attempt_to_consume_an_enti Line 2202  sub _tokenize_attempt_to_consume_an_enti
2202         0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR         0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR
2203         $additional => 1,         $additional => 1,
2204        }->{$self->{next_char}}) {        }->{$self->{next_char}}) {
2205        !!!cp (1001);
2206      ## Don't consume      ## Don't consume
2207      ## No error      ## No error
2208      return undef;      return undef;
# Line 1937  sub _tokenize_attempt_to_consume_an_enti Line 2216  sub _tokenize_attempt_to_consume_an_enti
2216          !!!next-input-character;          !!!next-input-character;
2217          if (0x0030 <= $self->{next_char} and          if (0x0030 <= $self->{next_char} and
2218              $self->{next_char} <= 0x0039) { # 0..9              $self->{next_char} <= 0x0039) { # 0..9
2219              !!!cp (1002);
2220            $code ||= 0;            $code ||= 0;
2221            $code *= 0x10;            $code *= 0x10;
2222            $code += $self->{next_char} - 0x0030;            $code += $self->{next_char} - 0x0030;
2223            redo X;            redo X;
2224          } elsif (0x0061 <= $self->{next_char} and          } elsif (0x0061 <= $self->{next_char} and
2225                   $self->{next_char} <= 0x0066) { # a..f                   $self->{next_char} <= 0x0066) { # a..f
2226              !!!cp (1003);
2227            $code ||= 0;            $code ||= 0;
2228            $code *= 0x10;            $code *= 0x10;
2229            $code += $self->{next_char} - 0x0060 + 9;            $code += $self->{next_char} - 0x0060 + 9;
2230            redo X;            redo X;
2231          } elsif (0x0041 <= $self->{next_char} and          } elsif (0x0041 <= $self->{next_char} and
2232                   $self->{next_char} <= 0x0046) { # A..F                   $self->{next_char} <= 0x0046) { # A..F
2233              !!!cp (1004);
2234            $code ||= 0;            $code ||= 0;
2235            $code *= 0x10;            $code *= 0x10;
2236            $code += $self->{next_char} - 0x0040 + 9;            $code += $self->{next_char} - 0x0040 + 9;
2237            redo X;            redo X;
2238          } elsif (not defined $code) { # no hexadecimal digit          } elsif (not defined $code) { # no hexadecimal digit
2239              !!!cp (1005);
2240            !!!parse-error (type => 'bare hcro');            !!!parse-error (type => 'bare hcro');
2241            !!!back-next-input-character ($x_char, $self->{next_char});            !!!back-next-input-character ($x_char, $self->{next_char});
2242            $self->{next_char} = 0x0023; # #            $self->{next_char} = 0x0023; # #
2243            return undef;            return undef;
2244          } elsif ($self->{next_char} == 0x003B) { # ;          } elsif ($self->{next_char} == 0x003B) { # ;
2245              !!!cp (1006);
2246            !!!next-input-character;            !!!next-input-character;
2247          } else {          } else {
2248              !!!cp (1007);
2249            !!!parse-error (type => 'no refc');            !!!parse-error (type => 'no refc');
2250          }          }
2251    
2252          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2253              !!!cp (1008);
2254            !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code);            !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code);
2255            $code = 0xFFFD;            $code = 0xFFFD;
2256          } elsif ($code > 0x10FFFF) {          } elsif ($code > 0x10FFFF) {
2257              !!!cp (1009);
2258            !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code);            !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code);
2259            $code = 0xFFFD;            $code = 0xFFFD;
2260          } elsif ($code == 0x000D) {          } elsif ($code == 0x000D) {
2261              !!!cp (1010);
2262            !!!parse-error (type => 'CR character reference');            !!!parse-error (type => 'CR character reference');
2263            $code = 0x000A;            $code = 0x000A;
2264          } elsif (0x80 <= $code and $code <= 0x9F) {          } elsif (0x80 <= $code and $code <= 0x9F) {
2265              !!!cp (1011);
2266            !!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code);            !!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code);
2267            $code = $c1_entity_char->{$code};            $code = $c1_entity_char->{$code};
2268          }          }
# Line 1988  sub _tokenize_attempt_to_consume_an_enti Line 2277  sub _tokenize_attempt_to_consume_an_enti
2277                
2278        while (0x0030 <= $self->{next_char} and        while (0x0030 <= $self->{next_char} and
2279                  $self->{next_char} <= 0x0039) { # 0..9                  $self->{next_char} <= 0x0039) { # 0..9
2280            !!!cp (1012);
2281          $code *= 10;          $code *= 10;
2282          $code += $self->{next_char} - 0x0030;          $code += $self->{next_char} - 0x0030;
2283                    
# Line 1995  sub _tokenize_attempt_to_consume_an_enti Line 2285  sub _tokenize_attempt_to_consume_an_enti
2285        }        }
2286    
2287        if ($self->{next_char} == 0x003B) { # ;        if ($self->{next_char} == 0x003B) { # ;
2288            !!!cp (1013);
2289          !!!next-input-character;          !!!next-input-character;
2290        } else {        } else {
2291            !!!cp (1014);
2292          !!!parse-error (type => 'no refc');          !!!parse-error (type => 'no refc');
2293        }        }
2294    
2295        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2296            !!!cp (1015);
2297          !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code);          !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code);
2298          $code = 0xFFFD;          $code = 0xFFFD;
2299        } elsif ($code > 0x10FFFF) {        } elsif ($code > 0x10FFFF) {
2300            !!!cp (1016);
2301          !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code);          !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code);
2302          $code = 0xFFFD;          $code = 0xFFFD;
2303        } elsif ($code == 0x000D) {        } elsif ($code == 0x000D) {
2304            !!!cp (1017);
2305          !!!parse-error (type => 'CR character reference');          !!!parse-error (type => 'CR character reference');
2306          $code = 0x000A;          $code = 0x000A;
2307        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
2308            !!!cp (1018);
2309          !!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code);          !!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code);
2310          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
2311        }        }
2312                
2313        return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1};        return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1};
2314      } else {      } else {
2315          !!!cp (1019);
2316        !!!parse-error (type => 'bare nero');        !!!parse-error (type => 'bare nero');
2317        !!!back-next-input-character ($self->{next_char});        !!!back-next-input-character ($self->{next_char});
2318        $self->{next_char} = 0x0023; # #        $self->{next_char} = 0x0023; # #
# Line 2045  sub _tokenize_attempt_to_consume_an_enti Line 2342  sub _tokenize_attempt_to_consume_an_enti
2342        $entity_name .= chr $self->{next_char};        $entity_name .= chr $self->{next_char};
2343        if (defined $EntityChar->{$entity_name}) {        if (defined $EntityChar->{$entity_name}) {
2344          if ($self->{next_char} == 0x003B) { # ;          if ($self->{next_char} == 0x003B) { # ;
2345              !!!cp (1020);
2346            $value = $EntityChar->{$entity_name};            $value = $EntityChar->{$entity_name};
2347            $match = 1;            $match = 1;
2348            !!!next-input-character;            !!!next-input-character;
2349            last;            last;
2350          } else {          } else {
2351              !!!cp (1021);
2352            $value = $EntityChar->{$entity_name};            $value = $EntityChar->{$entity_name};
2353            $match = -1;            $match = -1;
2354            !!!next-input-character;            !!!next-input-character;
2355          }          }
2356        } else {        } else {
2357            !!!cp (1022);
2358          $value .= chr $self->{next_char};          $value .= chr $self->{next_char};
2359          $match *= 2;          $match *= 2;
2360          !!!next-input-character;          !!!next-input-character;
# Line 2062  sub _tokenize_attempt_to_consume_an_enti Line 2362  sub _tokenize_attempt_to_consume_an_enti
2362      }      }
2363            
2364      if ($match > 0) {      if ($match > 0) {
2365          !!!cp (1023);
2366        return {type => CHARACTER_TOKEN, data => $value, has_reference => 1};        return {type => CHARACTER_TOKEN, data => $value, has_reference => 1};
2367      } elsif ($match < 0) {      } elsif ($match < 0) {
2368        !!!parse-error (type => 'no refc');        !!!parse-error (type => 'no refc');
2369        if ($in_attr and $match < -1) {        if ($in_attr and $match < -1) {
2370            !!!cp (1024);
2371          return {type => CHARACTER_TOKEN, data => '&'.$entity_name};          return {type => CHARACTER_TOKEN, data => '&'.$entity_name};
2372        } else {        } else {
2373            !!!cp (1025);
2374          return {type => CHARACTER_TOKEN, data => $value, has_reference => 1};          return {type => CHARACTER_TOKEN, data => $value, has_reference => 1};
2375        }        }
2376      } else {      } else {
2377          !!!cp (1026);
2378        !!!parse-error (type => 'bare ero');        !!!parse-error (type => 'bare ero');
2379        ## NOTE: "No characters are consumed" in the spec.        ## NOTE: "No characters are consumed" in the spec.
2380        return {type => CHARACTER_TOKEN, data => '&'.$value};        return {type => CHARACTER_TOKEN, data => '&'.$value};
2381      }      }
2382    } else {    } else {
2383        !!!cp (1027);
2384      ## no characters are consumed      ## no characters are consumed
2385      !!!parse-error (type => 'bare ero');      !!!parse-error (type => 'bare ero');
2386      return undef;      return undef;
# Line 2139  sub _tree_construction_initial ($) { Line 2444  sub _tree_construction_initial ($) {
2444        if (not defined $token->{name} or # <!DOCTYPE>        if (not defined $token->{name} or # <!DOCTYPE>
2445            defined $token->{public_identifier} or            defined $token->{public_identifier} or
2446            defined $token->{system_identifier}) {            defined $token->{system_identifier}) {
2447            !!!cp ('t1');
2448          !!!parse-error (type => 'not HTML5');          !!!parse-error (type => 'not HTML5');
2449        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
2450            !!!cp ('t2');
2451          ## ISSUE: ASCII case-insensitive? (in fact it does not matter)          ## ISSUE: ASCII case-insensitive? (in fact it does not matter)
2452          !!!parse-error (type => 'not HTML5');          !!!parse-error (type => 'not HTML5');
2453          } else {
2454            !!!cp ('t3');
2455        }        }
2456                
2457        my $doctype = $self->{document}->create_document_type_definition        my $doctype = $self->{document}->create_document_type_definition
# Line 2156  sub _tree_construction_initial ($) { Line 2465  sub _tree_construction_initial ($) {
2465        $self->{document}->append_child ($doctype);        $self->{document}->append_child ($doctype);
2466                
2467        if ($token->{quirks} or $doctype_name ne 'HTML') {        if ($token->{quirks} or $doctype_name ne 'HTML') {
2468            !!!cp ('t4');
2469          $self->{document}->manakai_compat_mode ('quirks');          $self->{document}->manakai_compat_mode ('quirks');
2470        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{public_identifier}) {
2471          my $pubid = $token->{public_identifier};          my $pubid = $token->{public_identifier};
# Line 2234  sub _tree_construction_initial ($) { Line 2544  sub _tree_construction_initial ($) {
2544            "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" => 1,            "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" => 1,
2545            "HTML" => 1,            "HTML" => 1,
2546          }->{$pubid}) {          }->{$pubid}) {
2547              !!!cp ('t5');
2548            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
2549          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or
2550                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {
2551            if (defined $token->{system_identifier}) {            if (defined $token->{system_identifier}) {
2552                !!!cp ('t6');
2553              $self->{document}->manakai_compat_mode ('quirks');              $self->{document}->manakai_compat_mode ('quirks');
2554            } else {            } else {
2555                !!!cp ('t7');
2556              $self->{document}->manakai_compat_mode ('limited quirks');              $self->{document}->manakai_compat_mode ('limited quirks');
2557            }            }
2558          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 Frameset//EN" or          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 FRAMESET//EN" or
2559                   $pubid eq "-//W3C//DTD XHTML 1.0 Transitional//EN") {                   $pubid eq "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN") {
2560              !!!cp ('t8');
2561            $self->{document}->manakai_compat_mode ('limited quirks');            $self->{document}->manakai_compat_mode ('limited quirks');
2562            } else {
2563              !!!cp ('t9');
2564          }          }
2565          } else {
2566            !!!cp ('t10');
2567        }        }
2568        if (defined $token->{system_identifier}) {        if (defined $token->{system_identifier}) {
2569          my $sysid = $token->{system_identifier};          my $sysid = $token->{system_identifier};
2570          $sysid =~ tr/A-Z/a-z/;          $sysid =~ tr/A-Z/a-z/;
2571          if ($sysid eq "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") {          if ($sysid eq "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") {
2572              ## TODO: Check the spec: PUBLIC "(limited quirks)" "(quirks)"
2573            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
2574              !!!cp ('t11');
2575            } else {
2576              !!!cp ('t12');
2577          }          }
2578          } else {
2579            !!!cp ('t13');
2580        }        }
2581                
2582        ## Go to the root element phase.        ## Go to the root element phase.
# Line 2263  sub _tree_construction_initial ($) { Line 2587  sub _tree_construction_initial ($) {
2587                END_TAG_TOKEN, 1,                END_TAG_TOKEN, 1,
2588                END_OF_FILE_TOKEN, 1,                END_OF_FILE_TOKEN, 1,
2589               }->{$token->{type}}) {               }->{$token->{type}}) {
2590          !!!cp ('t14');
2591        !!!parse-error (type => 'no DOCTYPE');        !!!parse-error (type => 'no DOCTYPE');
2592        $self->{document}->manakai_compat_mode ('quirks');        $self->{document}->manakai_compat_mode ('quirks');
2593        ## Go to the root element phase        ## Go to the root element phase
# Line 2273  sub _tree_construction_initial ($) { Line 2598  sub _tree_construction_initial ($) {
2598          ## Ignore the token          ## Ignore the token
2599    
2600          unless (length $token->{data}) {          unless (length $token->{data}) {
2601              !!!cp ('t15');
2602            ## Stay in the phase            ## Stay in the phase
2603            !!!next-token;            !!!next-token;
2604            redo INITIAL;            redo INITIAL;
2605            } else {
2606              !!!cp ('t16');
2607          }          }
2608          } else {
2609            !!!cp ('t17');
2610        }        }
2611    
2612        !!!parse-error (type => 'no DOCTYPE');        !!!parse-error (type => 'no DOCTYPE');
# Line 2285  sub _tree_construction_initial ($) { Line 2615  sub _tree_construction_initial ($) {
2615        ## reprocess        ## reprocess
2616        return;        return;
2617      } elsif ($token->{type} == COMMENT_TOKEN) {      } elsif ($token->{type} == COMMENT_TOKEN) {
2618          !!!cp ('t18');
2619        my $comment = $self->{document}->create_comment ($token->{data});        my $comment = $self->{document}->create_comment ($token->{data});
2620        $self->{document}->append_child ($comment);        $self->{document}->append_child ($comment);
2621                
# Line 2295  sub _tree_construction_initial ($) { Line 2626  sub _tree_construction_initial ($) {
2626        die "$0: $token->{type}: Unknown token type";        die "$0: $token->{type}: Unknown token type";
2627      }      }
2628    } # INITIAL    } # INITIAL
2629    
2630      die "$0: _tree_construction_initial: This should be never reached";
2631  } # _tree_construction_initial  } # _tree_construction_initial
2632    
2633  sub _tree_construction_root_element ($) {  sub _tree_construction_root_element ($) {
# Line 2302  sub _tree_construction_root_element ($) Line 2635  sub _tree_construction_root_element ($)
2635        
2636    B: {    B: {
2637        if ($token->{type} == DOCTYPE_TOKEN) {        if ($token->{type} == DOCTYPE_TOKEN) {
2638            !!!cp ('t19');
2639          !!!parse-error (type => 'in html:#DOCTYPE');          !!!parse-error (type => 'in html:#DOCTYPE');
2640          ## Ignore the token          ## Ignore the token
2641          ## Stay in the phase          ## Stay in the phase
2642          !!!next-token;          !!!next-token;
2643          redo B;          redo B;
2644        } elsif ($token->{type} == COMMENT_TOKEN) {        } elsif ($token->{type} == COMMENT_TOKEN) {
2645            !!!cp ('t20');
2646          my $comment = $self->{document}->create_comment ($token->{data});          my $comment = $self->{document}->create_comment ($token->{data});
2647          $self->{document}->append_child ($comment);          $self->{document}->append_child ($comment);
2648          ## Stay in the phase          ## Stay in the phase
# Line 2318  sub _tree_construction_root_element ($) Line 2653  sub _tree_construction_root_element ($)
2653            ## Ignore the token.            ## Ignore the token.
2654    
2655            unless (length $token->{data}) {            unless (length $token->{data}) {
2656                !!!cp ('t21');
2657              ## Stay in the phase              ## Stay in the phase
2658              !!!next-token;              !!!next-token;
2659              redo B;              redo B;
2660              } else {
2661                !!!cp ('t22');
2662            }            }
2663            } else {
2664              !!!cp ('t23');
2665          }          }
2666    
2667          $self->{application_cache_selection}->(undef);          $self->{application_cache_selection}->(undef);
# Line 2330  sub _tree_construction_root_element ($) Line 2670  sub _tree_construction_root_element ($)
2670        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
2671          if ($token->{tag_name} eq 'html' and          if ($token->{tag_name} eq 'html' and
2672              $token->{attributes}->{manifest}) {              $token->{attributes}->{manifest}) {
2673              !!!cp ('t24');
2674            $self->{application_cache_selection}            $self->{application_cache_selection}
2675                 ->($token->{attributes}->{manifest}->{value});                 ->($token->{attributes}->{manifest}->{value});
2676            ## ISSUE: No relative reference resolution?            ## ISSUE: No relative reference resolution?
2677          } else {          } else {
2678              !!!cp ('t25');
2679            $self->{application_cache_selection}->(undef);            $self->{application_cache_selection}->(undef);
2680          }          }
2681    
# Line 2343  sub _tree_construction_root_element ($) Line 2685  sub _tree_construction_root_element ($)
2685                  END_TAG_TOKEN, 1,                  END_TAG_TOKEN, 1,
2686                  END_OF_FILE_TOKEN, 1,                  END_OF_FILE_TOKEN, 1,
2687                 }->{$token->{type}}) {                 }->{$token->{type}}) {
2688            !!!cp ('t26');
2689          $self->{application_cache_selection}->(undef);          $self->{application_cache_selection}->(undef);
2690    
2691          ## ISSUE: There is an issue in the spec          ## ISSUE: There is an issue in the spec
# Line 2358  sub _tree_construction_root_element ($) Line 2701  sub _tree_construction_root_element ($)
2701        #redo B;        #redo B;
2702        return; ## Go to the main phase.        return; ## Go to the main phase.
2703    } # B    } # B
2704    
2705      die "$0: _tree_construction_root_element: This should never be reached";
2706  } # _tree_construction_root_element  } # _tree_construction_root_element
2707    
2708  sub _reset_insertion_mode ($) {  sub _reset_insertion_mode ($) {
# Line 2382  sub _reset_insertion_mode ($) { Line 2727  sub _reset_insertion_mode ($) {
2727          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
2728            if ($self->{inner_html_node}->[1] eq 'td' or            if ($self->{inner_html_node}->[1] eq 'td' or
2729                $self->{inner_html_node}->[1] eq 'th') {                $self->{inner_html_node}->[1] eq 'th') {
2730                !!!cp ('t27');
2731              #              #
2732            } else {            } else {
2733                !!!cp ('t28');
2734              $node = $self->{inner_html_node};              $node = $self->{inner_html_node};
2735            }            }
2736          }          }
# Line 2410  sub _reset_insertion_mode ($) { Line 2757  sub _reset_insertion_mode ($) {
2757        ## Step 14        ## Step 14
2758        if ($node->[1] eq 'html') {        if ($node->[1] eq 'html') {
2759          unless (defined $self->{head_element}) {          unless (defined $self->{head_element}) {
2760              !!!cp ('t29');
2761            $self->{insertion_mode} = BEFORE_HEAD_IM;            $self->{insertion_mode} = BEFORE_HEAD_IM;
2762          } else {          } else {
2763              !!!cp ('t30');
2764            $self->{insertion_mode} = AFTER_HEAD_IM;            $self->{insertion_mode} = AFTER_HEAD_IM;
2765          }          }
2766          return;          return;
2767          } else {
2768            !!!cp ('t31');
2769        }        }
2770                
2771        ## Step 15        ## Step 15
# Line 2427  sub _reset_insertion_mode ($) { Line 2778  sub _reset_insertion_mode ($) {
2778        ## Step 17        ## Step 17
2779        redo S3;        redo S3;
2780      } # S3      } # S3
2781    
2782      die "$0: _reset_insertion_mode: This line should never be reached";
2783  } # _reset_insertion_mode  } # _reset_insertion_mode
2784    
2785  sub _tree_construction_main ($) {  sub _tree_construction_main ($) {
# Line 2448  sub _tree_construction_main ($) { Line 2801  sub _tree_construction_main ($) {
2801      return if $entry->[0] eq '#marker';      return if $entry->[0] eq '#marker';
2802      for (@{$self->{open_elements}}) {      for (@{$self->{open_elements}}) {
2803        if ($entry->[0] eq $_->[0]) {        if ($entry->[0] eq $_->[0]) {
2804            !!!cp ('t32');
2805          return;          return;
2806        }        }
2807      }      }
# Line 2462  sub _tree_construction_main ($) { Line 2816  sub _tree_construction_main ($) {
2816    
2817        ## Step 6        ## Step 6
2818        if ($entry->[0] eq '#marker') {        if ($entry->[0] eq '#marker') {
2819            !!!cp ('t33');
2820          #          #
2821        } else {        } else {
2822          my $in_open_elements;          my $in_open_elements;
2823          OE: for (@{$self->{open_elements}}) {          OE: for (@{$self->{open_elements}}) {
2824            if ($entry->[0] eq $_->[0]) {            if ($entry->[0] eq $_->[0]) {
2825                !!!cp ('t33');
2826              $in_open_elements = 1;              $in_open_elements = 1;
2827              last OE;              last OE;
2828            }            }
2829          }          }
2830          if ($in_open_elements) {          if ($in_open_elements) {
2831              !!!cp ('t34');
2832            #            #
2833          } else {          } else {
2834              !!!cp ('t35');
2835            redo S4;            redo S4;
2836          }          }
2837        }        }
# Line 2496  sub _tree_construction_main ($) { Line 2854  sub _tree_construction_main ($) {
2854    
2855        ## Step 11        ## Step 11
2856        unless ($clone->[0] eq $active_formatting_elements->[-1]->[0]) {        unless ($clone->[0] eq $active_formatting_elements->[-1]->[0]) {
2857            !!!cp ('t36');
2858          ## Step 7'          ## Step 7'
2859          $i++;          $i++;
2860          $entry = $active_formatting_elements->[$i];          $entry = $active_formatting_elements->[$i];
2861                    
2862          redo S7;          redo S7;
2863        }        }
2864    
2865          !!!cp ('t37');
2866      } # S7      } # S7
2867    }; # $reconstruct_active_formatting_elements    }; # $reconstruct_active_formatting_elements
2868    
2869    my $clear_up_to_marker = sub {    my $clear_up_to_marker = sub {
2870      for (reverse 0..$#$active_formatting_elements) {      for (reverse 0..$#$active_formatting_elements) {
2871        if ($active_formatting_elements->[$_]->[0] eq '#marker') {        if ($active_formatting_elements->[$_]->[0] eq '#marker') {
2872            !!!cp ('t38');
2873          splice @$active_formatting_elements, $_;          splice @$active_formatting_elements, $_;
2874          return;          return;
2875        }        }
2876      }      }
2877    
2878        !!!cp ('t39');
2879    }; # $clear_up_to_marker    }; # $clear_up_to_marker
2880    
2881    my $parse_rcdata = sub ($$) {    my $parse_rcdata = sub ($$) {
# Line 2533  sub _tree_construction_main ($) { Line 2897  sub _tree_construction_main ($) {
2897      my $text = '';      my $text = '';
2898      !!!next-token;      !!!next-token;
2899      while ($token->{type} == CHARACTER_TOKEN) { # or until stop tokenizing      while ($token->{type} == CHARACTER_TOKEN) { # or until stop tokenizing
2900          !!!cp ('t40');
2901        $text .= $token->{data};        $text .= $token->{data};
2902        !!!next-token;        !!!next-token;
2903      }      }
2904    
2905      ## Step 5      ## Step 5
2906      if (length $text) {      if (length $text) {
2907          !!!cp ('t41');
2908        my $text = $self->{document}->create_text_node ($text);        my $text = $self->{document}->create_text_node ($text);
2909        $el->append_child ($text);        $el->append_child ($text);
2910      }      }
# Line 2547  sub _tree_construction_main ($) { Line 2913  sub _tree_construction_main ($) {
2913      $self->{content_model} = PCDATA_CONTENT_MODEL;      $self->{content_model} = PCDATA_CONTENT_MODEL;
2914    
2915      ## Step 7      ## Step 7
2916      if ($token->{type} == END_TAG_TOKEN and $token->{tag_name} eq $start_tag_name) {      if ($token->{type} == END_TAG_TOKEN and
2917            $token->{tag_name} eq $start_tag_name) {
2918          !!!cp ('t42');
2919        ## Ignore the token        ## Ignore the token
2920      } elsif ($content_model_flag == CDATA_CONTENT_MODEL) {      } elsif ($content_model_flag == CDATA_CONTENT_MODEL) {
2921          !!!cp ('t43');
2922        !!!parse-error (type => 'in CDATA:#'.$token->{type});        !!!parse-error (type => 'in CDATA:#'.$token->{type});
2923      } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {      } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
2924          !!!cp ('t44');
2925        !!!parse-error (type => 'in RCDATA:#'.$token->{type});        !!!parse-error (type => 'in RCDATA:#'.$token->{type});
2926      } else {      } else {
2927        die "$0: $content_model_flag in parse_rcdata";        die "$0: $content_model_flag in parse_rcdata";
# Line 2571  sub _tree_construction_main ($) { Line 2941  sub _tree_construction_main ($) {
2941      my $text = '';      my $text = '';
2942      !!!next-token;      !!!next-token;
2943      while ($token->{type} == CHARACTER_TOKEN) {      while ($token->{type} == CHARACTER_TOKEN) {
2944          !!!cp ('t45');
2945        $text .= $token->{data};        $text .= $token->{data};
2946        !!!next-token;        !!!next-token;
2947      } # stop if non-character token or tokenizer stops tokenising      } # stop if non-character token or tokenizer stops tokenising
2948      if (length $text) {      if (length $text) {
2949          !!!cp ('t46');
2950        $script_el->manakai_append_text ($text);        $script_el->manakai_append_text ($text);
2951      }      }
2952                                
# Line 2582  sub _tree_construction_main ($) { Line 2954  sub _tree_construction_main ($) {
2954    
2955      if ($token->{type} == END_TAG_TOKEN and      if ($token->{type} == END_TAG_TOKEN and
2956          $token->{tag_name} eq 'script') {          $token->{tag_name} eq 'script') {
2957          !!!cp ('t47');
2958        ## Ignore the token        ## Ignore the token
2959      } else {      } else {
2960          !!!cp ('t48');
2961        !!!parse-error (type => 'in CDATA:#'.$token->{type});        !!!parse-error (type => 'in CDATA:#'.$token->{type});
2962        ## ISSUE: And ignore?        ## ISSUE: And ignore?
2963        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
2964      }      }
2965            
2966      if (defined $self->{inner_html_node}) {      if (defined $self->{inner_html_node}) {
2967          !!!cp ('t49');
2968        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
2969      } else {      } else {
2970          !!!cp ('t50');
2971        ## TODO: $old_insertion_point = current insertion point        ## TODO: $old_insertion_point = current insertion point
2972        ## TODO: insertion point = just before the next input character        ## TODO: insertion point = just before the next input character
2973    
# Line 2614  sub _tree_construction_main ($) { Line 2990  sub _tree_construction_main ($) {
2990        my $formatting_element_i_in_active;        my $formatting_element_i_in_active;
2991        AFE: for (reverse 0..$#$active_formatting_elements) {        AFE: for (reverse 0..$#$active_formatting_elements) {
2992          if ($active_formatting_elements->[$_]->[1] eq $tag_name) {          if ($active_formatting_elements->[$_]->[1] eq $tag_name) {
2993              !!!cp ('t51');
2994            $formatting_element = $active_formatting_elements->[$_];            $formatting_element = $active_formatting_elements->[$_];
2995            $formatting_element_i_in_active = $_;            $formatting_element_i_in_active = $_;
2996            last AFE;            last AFE;
2997          } elsif ($active_formatting_elements->[$_]->[0] eq '#marker') {          } elsif ($active_formatting_elements->[$_]->[0] eq '#marker') {
2998              !!!cp ('t52');
2999            last AFE;            last AFE;
3000          }          }
3001        } # AFE        } # AFE
3002        unless (defined $formatting_element) {        unless (defined $formatting_element) {
3003            !!!cp ('t53');
3004          !!!parse-error (type => 'unmatched end tag:'.$tag_name);          !!!parse-error (type => 'unmatched end tag:'.$tag_name);
3005          ## Ignore the token          ## Ignore the token
3006          !!!next-token;          !!!next-token;
# Line 2634  sub _tree_construction_main ($) { Line 3013  sub _tree_construction_main ($) {
3013          my $node = $self->{open_elements}->[$_];          my $node = $self->{open_elements}->[$_];
3014          if ($node->[0] eq $formatting_element->[0]) {          if ($node->[0] eq $formatting_element->[0]) {
3015            if ($in_scope) {            if ($in_scope) {
3016                !!!cp ('t54');
3017              $formatting_element_i_in_open = $_;              $formatting_element_i_in_open = $_;
3018              last INSCOPE;              last INSCOPE;
3019            } else { # in open elements but not in scope            } else { # in open elements but not in scope
3020                !!!cp ('t55');
3021              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3022              ## Ignore the token              ## Ignore the token
3023              !!!next-token;              !!!next-token;
# Line 2646  sub _tree_construction_main ($) { Line 3027  sub _tree_construction_main ($) {
3027                    table => 1, caption => 1, td => 1, th => 1,                    table => 1, caption => 1, td => 1, th => 1,
3028                    button => 1, marquee => 1, object => 1, html => 1,                    button => 1, marquee => 1, object => 1, html => 1,
3029                   }->{$node->[1]}) {                   }->{$node->[1]}) {
3030              !!!cp ('t56');
3031            $in_scope = 0;            $in_scope = 0;
3032          }          }
3033        } # INSCOPE        } # INSCOPE
3034        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
3035            !!!cp ('t57');
3036          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3037          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
3038          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
3039          return;          return;
3040        }        }
3041        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
3042            !!!cp ('t58');
3043          !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);          !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3044        }        }
3045                
# Line 2668  sub _tree_construction_main ($) { Line 3052  sub _tree_construction_main ($) {
3052              #not $phrasing_category->{$node->[1]} and              #not $phrasing_category->{$node->[1]} and
3053              ($special_category->{$node->[1]} or              ($special_category->{$node->[1]} or
3054               $scoping_category->{$node->[1]})) {               $scoping_category->{$node->[1]})) {
3055              !!!cp ('t59');
3056            $furthest_block = $node;            $furthest_block = $node;
3057            $furthest_block_i_in_open = $_;            $furthest_block_i_in_open = $_;
3058          } elsif ($node->[0] eq $formatting_element->[0]) {          } elsif ($node->[0] eq $formatting_element->[0]) {
3059              !!!cp ('t60');
3060            last OE;            last OE;
3061          }          }
3062        } # OE        } # OE
3063                
3064        ## Step 3        ## Step 3
3065        unless (defined $furthest_block) { # MUST        unless (defined $furthest_block) { # MUST
3066            !!!cp ('t61');
3067          splice @{$self->{open_elements}}, $formatting_element_i_in_open;          splice @{$self->{open_elements}}, $formatting_element_i_in_open;
3068          splice @$active_formatting_elements, $formatting_element_i_in_active, 1;          splice @$active_formatting_elements, $formatting_element_i_in_active, 1;
3069          !!!next-token;          !!!next-token;
# Line 2689  sub _tree_construction_main ($) { Line 3076  sub _tree_construction_main ($) {
3076        ## Step 5        ## Step 5
3077        my $furthest_block_parent = $furthest_block->[0]->parent_node;        my $furthest_block_parent = $furthest_block->[0]->parent_node;
3078        if (defined $furthest_block_parent) {        if (defined $furthest_block_parent) {
3079            !!!cp ('t62');
3080          $furthest_block_parent->remove_child ($furthest_block->[0]);          $furthest_block_parent->remove_child ($furthest_block->[0]);
3081        }        }
3082                
# Line 2711  sub _tree_construction_main ($) { Line 3099  sub _tree_construction_main ($) {
3099          S7S2: {          S7S2: {
3100            for (reverse 0..$#$active_formatting_elements) {            for (reverse 0..$#$active_formatting_elements) {
3101              if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {              if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {
3102                  !!!cp ('t63');
3103                $node_i_in_active = $_;                $node_i_in_active = $_;
3104                last S7S2;                last S7S2;
3105              }              }
# Line 2724  sub _tree_construction_main ($) { Line 3113  sub _tree_construction_main ($) {
3113                    
3114          ## Step 4          ## Step 4
3115          if ($last_node->[0] eq $furthest_block->[0]) {          if ($last_node->[0] eq $furthest_block->[0]) {
3116              !!!cp ('t64');
3117            $bookmark_prev_el = $node->[0];            $bookmark_prev_el = $node->[0];
3118          }          }
3119                    
3120          ## Step 5          ## Step 5
3121          if ($node->[0]->has_child_nodes ()) {          if ($node->[0]->has_child_nodes ()) {
3122              !!!cp ('t65');
3123            my $clone = [$node->[0]->clone_node (0), $node->[1]];            my $clone = [$node->[0]->clone_node (0), $node->[1]];
3124            $active_formatting_elements->[$node_i_in_active] = $clone;            $active_formatting_elements->[$node_i_in_active] = $clone;
3125            $self->{open_elements}->[$node_i_in_open] = $clone;            $self->{open_elements}->[$node_i_in_open] = $clone;
# Line 2763  sub _tree_construction_main ($) { Line 3154  sub _tree_construction_main ($) {
3154        my $i;        my $i;
3155        AFE: for (reverse 0..$#$active_formatting_elements) {        AFE: for (reverse 0..$#$active_formatting_elements) {
3156          if ($active_formatting_elements->[$_]->[0] eq $formatting_element->[0]) {          if ($active_formatting_elements->[$_]->[0] eq $formatting_element->[0]) {
3157              !!!cp ('t66');
3158            splice @$active_formatting_elements, $_, 1;            splice @$active_formatting_elements, $_, 1;
3159            $i-- and last AFE if defined $i;            $i-- and last AFE if defined $i;
3160          } elsif ($active_formatting_elements->[$_]->[0] eq $bookmark_prev_el) {          } elsif ($active_formatting_elements->[$_]->[0] eq $bookmark_prev_el) {
3161              !!!cp ('t67');
3162            $i = $_;            $i = $_;
3163          }          }
3164        } # AFE        } # AFE
# Line 2775  sub _tree_construction_main ($) { Line 3168  sub _tree_construction_main ($) {
3168        undef $i;        undef $i;
3169        OE: for (reverse 0..$#{$self->{open_elements}}) {        OE: for (reverse 0..$#{$self->{open_elements}}) {
3170          if ($self->{open_elements}->[$_]->[0] eq $formatting_element->[0]) {          if ($self->{open_elements}->[$_]->[0] eq $formatting_element->[0]) {
3171              !!!cp ('t68');
3172            splice @{$self->{open_elements}}, $_, 1;            splice @{$self->{open_elements}}, $_, 1;
3173            $i-- and last OE if defined $i;            $i-- and last OE if defined $i;
3174          } elsif ($self->{open_elements}->[$_]->[0] eq $furthest_block->[0]) {          } elsif ($self->{open_elements}->[$_]->[0] eq $furthest_block->[0]) {
3175              !!!cp ('t69');
3176            $i = $_;            $i = $_;
3177          }          }
3178        } # OE        } # OE
# Line 2805  sub _tree_construction_main ($) { Line 3200  sub _tree_construction_main ($) {
3200                             if ($self->{open_elements}->[$_]->[1] eq 'table') {                             if ($self->{open_elements}->[$_]->[1] eq 'table') {
3201                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
3202                               if (defined $parent and $parent->node_type == 1) {                               if (defined $parent and $parent->node_type == 1) {
3203                                   !!!cp ('t70');
3204                                 $foster_parent_element = $parent;                                 $foster_parent_element = $parent;
3205                                 $next_sibling = $self->{open_elements}->[$_]->[0];                                 $next_sibling = $self->{open_elements}->[$_]->[0];
3206                               } else {                               } else {
3207                                   !!!cp ('t71');
3208                                 $foster_parent_element                                 $foster_parent_element
3209                                   = $self->{open_elements}->[$_ - 1]->[0];                                   = $self->{open_elements}->[$_ - 1]->[0];
3210                               }                               }
# Line 2819  sub _tree_construction_main ($) { Line 3216  sub _tree_construction_main ($) {
3216                           $foster_parent_element->insert_before                           $foster_parent_element->insert_before
3217                             ($child, $next_sibling);                             ($child, $next_sibling);
3218                         } else {                         } else {
3219                             !!!cp ('t72');
3220                           $self->{open_elements}->[-1]->[0]->append_child ($child);                           $self->{open_elements}->[-1]->[0]->append_child ($child);
3221                         }                         }
3222    }; # $insert_to_foster    }; # $insert_to_foster
# Line 2827  sub _tree_construction_main ($) { Line 3225  sub _tree_construction_main ($) {
3225    
3226    B: {    B: {
3227      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
3228          !!!cp ('t73');
3229        !!!parse-error (type => 'DOCTYPE in the middle');        !!!parse-error (type => 'DOCTYPE in the middle');
3230        ## Ignore the token        ## Ignore the token
3231        ## Stay in the phase        ## Stay in the phase
# Line 2834  sub _tree_construction_main ($) { Line 3233  sub _tree_construction_main ($) {
3233        redo B;        redo B;
3234      } elsif ($token->{type} == END_OF_FILE_TOKEN) {      } elsif ($token->{type} == END_OF_FILE_TOKEN) {
3235        if ($self->{insertion_mode} & AFTER_HTML_IMS) {        if ($self->{insertion_mode} & AFTER_HTML_IMS) {
3236            !!!cp ('t74');
3237          #          #
3238        } else {        } else {
3239          ## Generate implied end tags          ## Generate implied end tags
# Line 2841  sub _tree_construction_main ($) { Line 3241  sub _tree_construction_main ($) {
3241               dd => 1, dt => 1, li => 1, p => 1, td => 1, th => 1, tr => 1,               dd => 1, dt => 1, li => 1, p => 1, td => 1, th => 1, tr => 1,
3242               tbody => 1, tfoot=> 1, thead => 1,               tbody => 1, tfoot=> 1, thead => 1,
3243              }->{$self->{open_elements}->[-1]->[1]}) {              }->{$self->{open_elements}->[-1]->[1]}) {
3244              !!!cp ('t75');
3245            !!!back-token;            !!!back-token;
3246            $token = {type => END_TAG_TOKEN, tag_name => $self->{open_elements}->[-1]->[1]};            $token = {type => END_TAG_TOKEN, tag_name => $self->{open_elements}->[-1]->[1]};
3247            redo B;            redo B;
# Line 2848  sub _tree_construction_main ($) { Line 3249  sub _tree_construction_main ($) {
3249                    
3250          if (@{$self->{open_elements}} > 2 or          if (@{$self->{open_elements}} > 2 or
3251              (@{$self->{open_elements}} == 2 and $self->{open_elements}->[1]->[1] ne 'body')) {              (@{$self->{open_elements}} == 2 and $self->{open_elements}->[1]->[1] ne 'body')) {
3252              !!!cp ('t76');
3253            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3254          } elsif (defined $self->{inner_html_node} and          } elsif (defined $self->{inner_html_node} and
3255                   @{$self->{open_elements}} > 1 and                   @{$self->{open_elements}} > 1 and
3256                   $self->{open_elements}->[1]->[1] ne 'body') {                   $self->{open_elements}->[1]->[1] ne 'body') {
3257              !!!cp ('t77');
3258            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3259            } else {
3260              !!!cp ('t78');
3261          }          }
3262    
3263          ## ISSUE: There is an issue in the spec.          ## ISSUE: There is an issue in the spec.
# Line 2863  sub _tree_construction_main ($) { Line 3268  sub _tree_construction_main ($) {
3268      } elsif ($token->{type} == START_TAG_TOKEN and      } elsif ($token->{type} == START_TAG_TOKEN and
3269               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
3270        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
3271            !!!cp ('t79');
3272          ## Turn into the main phase          ## Turn into the main phase
3273          !!!parse-error (type => 'after html:html');          !!!parse-error (type => 'after html:html');
3274          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
3275        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
3276            !!!cp ('t80');
3277          ## Turn into the main phase          ## Turn into the main phase
3278          !!!parse-error (type => 'after html:html');          !!!parse-error (type => 'after html:html');
3279          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
3280          } else {
3281            !!!cp ('t81');
3282        }        }
3283    
3284  ## ISSUE: "aa<html>" is not a parse error.  ## ISSUE: "aa<html>" is not a parse error.
3285  ## ISSUE: "<html>" in fragment is not a parse error.  ## ISSUE: "<html>" in fragment is not a parse error.
3286        unless ($token->{first_start_tag}) {        unless ($token->{first_start_tag}) {
3287            !!!cp ('t82');
3288          !!!parse-error (type => 'not first start tag');          !!!parse-error (type => 'not first start tag');
3289          } else {
3290            !!!cp ('t83');
3291        }        }
3292        my $top_el = $self->{open_elements}->[0]->[0];        my $top_el = $self->{open_elements}->[0]->[0];
3293        for my $attr_name (keys %{$token->{attributes}}) {        for my $attr_name (keys %{$token->{attributes}}) {
3294          unless ($top_el->has_attribute_ns (undef, $attr_name)) {          unless ($top_el->has_attribute_ns (undef, $attr_name)) {
3295              !!!cp ('t84');
3296            $top_el->set_attribute_ns            $top_el->set_attribute_ns
3297              (undef, [undef, $attr_name],              (undef, [undef, $attr_name],
3298               $token->{attributes}->{$attr_name}->{value});               $token->{attributes}->{$attr_name}->{value});
# Line 2890  sub _tree_construction_main ($) { Line 3303  sub _tree_construction_main ($) {
3303      } elsif ($token->{type} == COMMENT_TOKEN) {      } elsif ($token->{type} == COMMENT_TOKEN) {
3304        my $comment = $self->{document}->create_comment ($token->{data});        my $comment = $self->{document}->create_comment ($token->{data});
3305        if ($self->{insertion_mode} & AFTER_HTML_IMS) {        if ($self->{insertion_mode} & AFTER_HTML_IMS) {
3306            !!!cp ('t85');
3307          $self->{document}->append_child ($comment);          $self->{document}->append_child ($comment);
3308        } elsif ($self->{insertion_mode} == AFTER_BODY_IM) {        } elsif ($self->{insertion_mode} == AFTER_BODY_IM) {
3309            !!!cp ('t86');
3310          $self->{open_elements}->[0]->[0]->append_child ($comment);          $self->{open_elements}->[0]->[0]->append_child ($comment);
3311        } else {        } else {
3312            !!!cp ('t87');
3313          $self->{open_elements}->[-1]->[0]->append_child ($comment);          $self->{open_elements}->[-1]->[0]->append_child ($comment);
3314        }        }
3315        !!!next-token;        !!!next-token;
# Line 2903  sub _tree_construction_main ($) { Line 3319  sub _tree_construction_main ($) {
3319          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3320            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
3321            unless (length $token->{data}) {            unless (length $token->{data}) {
3322                !!!cp ('t88');
3323              !!!next-token;              !!!next-token;
3324              redo B;              redo B;
3325            }            }
3326          }          }
3327    
3328          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3329              !!!cp ('t89');
3330            ## As if <head>            ## As if <head>
3331            !!!create-element ($self->{head_element}, 'head');            !!!create-element ($self->{head_element}, 'head');
3332            $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});            $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 2919  sub _tree_construction_main ($) { Line 3337  sub _tree_construction_main ($) {
3337    
3338            ## Reprocess in the "after head" insertion mode...            ## Reprocess in the "after head" insertion mode...
3339          } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {          } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3340              !!!cp ('t90');
3341            ## As if </noscript>            ## As if </noscript>
3342            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
3343            !!!parse-error (type => 'in noscript:#character');            !!!parse-error (type => 'in noscript:#character');
# Line 2929  sub _tree_construction_main ($) { Line 3348  sub _tree_construction_main ($) {
3348    
3349            ## Reprocess in the "after head" insertion mode...            ## Reprocess in the "after head" insertion mode...
3350          } elsif ($self->{insertion_mode} == IN_HEAD_IM) {          } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3351              !!!cp ('t91');
3352            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
3353    
3354            ## Reprocess in the "after head" insertion mode...            ## Reprocess in the "after head" insertion mode...
3355            } else {
3356              !!!cp ('t92');
3357          }          }
3358    
3359              ## "after head" insertion mode              ## "after head" insertion mode
# Line 2943  sub _tree_construction_main ($) { Line 3365  sub _tree_construction_main ($) {
3365            } elsif ($token->{type} == START_TAG_TOKEN) {            } elsif ($token->{type} == START_TAG_TOKEN) {
3366              if ($token->{tag_name} eq 'head') {              if ($token->{tag_name} eq 'head') {
3367                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3368                    !!!cp ('t93');
3369                  !!!create-element ($self->{head_element}, $token->{tag_name}, $token->{attributes});                  !!!create-element ($self->{head_element}, $token->{tag_name}, $token->{attributes});
3370                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
3371                  push @{$self->{open_elements}}, [$self->{head_element}, $token->{tag_name}];                  push @{$self->{open_elements}}, [$self->{head_element}, $token->{tag_name}];
# Line 2950  sub _tree_construction_main ($) { Line 3373  sub _tree_construction_main ($) {
3373                  !!!next-token;                  !!!next-token;
3374                  redo B;                  redo B;
3375                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
3376                    !!!cp ('t94');
3377                  #                  #
3378                } else {                } else {
3379                    !!!cp ('t95');
3380                  !!!parse-error (type => 'in head:head'); # or in head noscript                  !!!parse-error (type => 'in head:head'); # or in head noscript
3381                  ## Ignore the token                  ## Ignore the token
3382                  !!!next-token;                  !!!next-token;
3383                  redo B;                  redo B;
3384                }                }
3385              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3386                  !!!cp ('t96');
3387                ## As if <head>                ## As if <head>
3388                !!!create-element ($self->{head_element}, 'head');                !!!create-element ($self->{head_element}, 'head');
3389                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 2965  sub _tree_construction_main ($) { Line 3391  sub _tree_construction_main ($) {
3391    
3392                $self->{insertion_mode} = IN_HEAD_IM;                $self->{insertion_mode} = IN_HEAD_IM;
3393                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
3394                } else {
3395                  !!!cp ('t97');
3396              }              }
3397    
3398              if ($token->{tag_name} eq 'base') {              if ($token->{tag_name} eq 'base') {
3399                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3400                    !!!cp ('t98');
3401                  ## As if </noscript>                  ## As if </noscript>
3402                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3403                  !!!parse-error (type => 'in noscript:base');                  !!!parse-error (type => 'in noscript:base');
3404                                
3405                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3406                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3407                  } else {
3408                    !!!cp ('t99');
3409                }                }
3410    
3411                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3412                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3413                    !!!cp ('t100');
3414                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3415                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3416                  } else {
3417                    !!!cp ('t101');
3418                }                }
3419                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3420                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
# Line 2991  sub _tree_construction_main ($) { Line 3425  sub _tree_construction_main ($) {
3425              } elsif ($token->{tag_name} eq 'link') {              } elsif ($token->{tag_name} eq 'link') {
3426                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3427                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3428                    !!!cp ('t102');
3429                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3430                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3431                  } else {
3432                    !!!cp ('t103');
3433                }                }
3434                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3435                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
# Line 3003  sub _tree_construction_main ($) { Line 3440  sub _tree_construction_main ($) {
3440              } elsif ($token->{tag_name} eq 'meta') {              } elsif ($token->{tag_name} eq 'meta') {
3441                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3442                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3443                    !!!cp ('t104');
3444                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3445                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3446                  } else {
3447                    !!!cp ('t105');
3448                }                }
3449                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3450                my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3451    
3452                unless ($self->{confident}) {                unless ($self->{confident}) {
3453                  if ($token->{attributes}->{charset}) { ## TODO: And if supported                  if ($token->{attributes}->{charset}) { ## TODO: And if supported
3454                      !!!cp ('t106');
3455                    $self->{change_encoding}                    $self->{change_encoding}
3456                        ->($self, $token->{attributes}->{charset}->{value});                        ->($self, $token->{attributes}->{charset}->{value});
3457                                        
# Line 3025  sub _tree_construction_main ($) { Line 3466  sub _tree_construction_main ($) {
3466                            [\x09-\x0D\x20]*=                            [\x09-\x0D\x20]*=
3467                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
3468                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
3469                        !!!cp ('t107');
3470                      $self->{change_encoding}                      $self->{change_encoding}
3471                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);
3472                      $meta_el->[0]->get_attribute_node_ns (undef, 'content')                      $meta_el->[0]->get_attribute_node_ns (undef, 'content')
3473                          ->set_user_data (manakai_has_reference =>                          ->set_user_data (manakai_has_reference =>
3474                                               $token->{attributes}->{content}                                               $token->{attributes}->{content}
3475                                                     ->{has_reference});                                                     ->{has_reference});
3476                      } else {
3477                        !!!cp ('t108');
3478                    }                    }
3479                  }                  }
3480                } else {                } else {
3481                  if ($token->{attributes}->{charset}) {                  if ($token->{attributes}->{charset}) {
3482                      !!!cp ('t109');
3483                    $meta_el->[0]->get_attribute_node_ns (undef, 'charset')                    $meta_el->[0]->get_attribute_node_ns (undef, 'charset')
3484                        ->set_user_data (manakai_has_reference =>                        ->set_user_data (manakai_has_reference =>
3485                                             $token->{attributes}->{charset}                                             $token->{attributes}->{charset}
3486                                                 ->{has_reference});                                                 ->{has_reference});
3487                  }                  }
3488                  if ($token->{attributes}->{content}) {                  if ($token->{attributes}->{content}) {
3489                      !!!cp ('t110');
3490                    $meta_el->[0]->get_attribute_node_ns (undef, 'content')                    $meta_el->[0]->get_attribute_node_ns (undef, 'content')
3491                        ->set_user_data (manakai_has_reference =>                        ->set_user_data (manakai_has_reference =>
3492                                             $token->{attributes}->{content}                                             $token->{attributes}->{content}
# Line 3054  sub _tree_construction_main ($) { Line 3500  sub _tree_construction_main ($) {
3500                redo B;                redo B;
3501              } elsif ($token->{tag_name} eq 'title') {              } elsif ($token->{tag_name} eq 'title') {
3502                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3503                    !!!cp ('t111');
3504                  ## As if </noscript>                  ## As if </noscript>
3505                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3506                  !!!parse-error (type => 'in noscript:title');                  !!!parse-error (type => 'in noscript:title');
# Line 3061  sub _tree_construction_main ($) { Line 3508  sub _tree_construction_main ($) {
3508                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3509                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3510                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
3511                    !!!cp ('t112');
3512                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3513                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3514                  } else {
3515                    !!!cp ('t113');
3516                }                }
3517    
3518                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
# Line 3078  sub _tree_construction_main ($) { Line 3528  sub _tree_construction_main ($) {
3528                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
3529                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3530                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3531                    !!!cp ('t114');
3532                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3533                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3534                  } else {
3535                    !!!cp ('t115');
3536                }                }
3537                $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);                $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);
3538                pop @{$self->{open_elements}}                pop @{$self->{open_elements}}
# Line 3087  sub _tree_construction_main ($) { Line 3540  sub _tree_construction_main ($) {
3540                redo B;                redo B;
3541              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
3542                if ($self->{insertion_mode} == IN_HEAD_IM) {                if ($self->{insertion_mode} == IN_HEAD_IM) {
3543                    !!!cp ('t116');
3544                  ## NOTE: and scripting is disalbed                  ## NOTE: and scripting is disalbed
3545                  !!!insert-element ($token->{tag_name}, $token->{attributes});                  !!!insert-element ($token->{tag_name}, $token->{attributes});
3546                  $self->{insertion_mode} = IN_HEAD_NOSCRIPT_IM;                  $self->{insertion_mode} = IN_HEAD_NOSCRIPT_IM;
3547                  !!!next-token;                  !!!next-token;
3548                  redo B;                  redo B;
3549                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3550                    !!!cp ('t117');
3551                  !!!parse-error (type => 'in noscript:noscript');                  !!!parse-error (type => 'in noscript:noscript');
3552                  ## Ignore the token                  ## Ignore the token
3553                  !!!next-token;                  !!!next-token;
3554                  redo B;                  redo B;
3555                } else {                } else {
3556                    !!!cp ('t118');
3557                  #                  #
3558                }                }
3559              } elsif ($token->{tag_name} eq 'script') {              } elsif ($token->{tag_name} eq 'script') {
3560                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3561                    !!!cp ('t119');
3562                  ## As if </noscript>                  ## As if </noscript>
3563                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3564                  !!!parse-error (type => 'in noscript:script');                  !!!parse-error (type => 'in noscript:script');
# Line 3109  sub _tree_construction_main ($) { Line 3566  sub _tree_construction_main ($) {
3566                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3567                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3568                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
3569                    !!!cp ('t120');
3570                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3571                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3572                  } else {
3573                    !!!cp ('t121');
3574                }                }
3575    
3576                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
# Line 3121  sub _tree_construction_main ($) { Line 3581  sub _tree_construction_main ($) {
3581              } elsif ($token->{tag_name} eq 'body' or              } elsif ($token->{tag_name} eq 'body' or
3582                       $token->{tag_name} eq 'frameset') {                       $token->{tag_name} eq 'frameset') {
3583                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3584                    !!!cp ('t122');
3585                  ## As if </noscript>                  ## As if </noscript>
3586                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3587                  !!!parse-error (type => 'in noscript:'.$token->{tag_name});                  !!!parse-error (type => 'in noscript:'.$token->{tag_name});
# Line 3131  sub _tree_construction_main ($) { Line 3592  sub _tree_construction_main ($) {
3592                                    
3593                  ## Reprocess in the "after head" insertion mode...                  ## Reprocess in the "after head" insertion mode...
3594                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3595                    !!!cp ('t124');
3596                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3597                                    
3598                  ## Reprocess in the "after head" insertion mode...                  ## Reprocess in the "after head" insertion mode...
3599                  } else {
3600                    !!!cp ('t125');
3601                }                }
3602    
3603                ## "after head" insertion mode                ## "after head" insertion mode
3604                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3605                if ($token->{tag_name} eq 'body') {                if ($token->{tag_name} eq 'body') {
3606                    !!!cp ('t126');
3607                  $self->{insertion_mode} = IN_BODY_IM;                  $self->{insertion_mode} = IN_BODY_IM;
3608                } elsif ($token->{tag_name} eq 'frameset') {                } elsif ($token->{tag_name} eq 'frameset') {
3609                    !!!cp ('t127');
3610                  $self->{insertion_mode} = IN_FRAMESET_IM;                  $self->{insertion_mode} = IN_FRAMESET_IM;
3611                } else {                } else {
3612                  die "$0: tag name: $self->{tag_name}";                  die "$0: tag name: $self->{tag_name}";
# Line 3148  sub _tree_construction_main ($) { Line 3614  sub _tree_construction_main ($) {
3614                !!!next-token;                !!!next-token;
3615                redo B;                redo B;
3616              } else {              } else {
3617                  !!!cp ('t128');
3618                #                #
3619              }              }
3620    
3621              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3622                  !!!cp ('t129');
3623                ## As if </noscript>                ## As if </noscript>
3624                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3625                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});
# Line 3162  sub _tree_construction_main ($) { Line 3630  sub _tree_construction_main ($) {
3630    
3631                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3632              } elsif ($self->{insertion_mode} == IN_HEAD_IM) {              } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3633                  !!!cp ('t130');
3634                ## As if </head>                ## As if </head>
3635                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3636    
3637                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3638                } else {
3639                  !!!cp ('t131');
3640              }              }
3641    
3642              ## "after head" insertion mode              ## "after head" insertion mode
# Line 3177  sub _tree_construction_main ($) { Line 3648  sub _tree_construction_main ($) {
3648            } elsif ($token->{type} == END_TAG_TOKEN) {            } elsif ($token->{type} == END_TAG_TOKEN) {
3649              if ($token->{tag_name} eq 'head') {              if ($token->{tag_name} eq 'head') {
3650                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3651                    !!!cp ('t132');
3652                  ## As if <head>                  ## As if <head>
3653                  !!!create-element ($self->{head_element}, 'head');                  !!!create-element ($self->{head_element}, 'head');
3654                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3188  sub _tree_construction_main ($) { Line 3660  sub _tree_construction_main ($) {
3660                  !!!next-token;                  !!!next-token;
3661                  redo B;                  redo B;
3662                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3663                    !!!cp ('t133');
3664                  ## As if </noscript>                  ## As if </noscript>
3665                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3666                  !!!parse-error (type => 'in noscript:script');                  !!!parse-error (type => 'in noscript:script');
# Line 3198  sub _tree_construction_main ($) { Line 3671  sub _tree_construction_main ($) {
3671                  !!!next-token;                  !!!next-token;
3672                  redo B;                  redo B;
3673                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3674                    !!!cp ('t134');
3675                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3676                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
3677                  !!!next-token;                  !!!next-token;
3678                  redo B;                  redo B;
3679                } else {                } else {
3680                    !!!cp ('t135');
3681                  #                  #
3682                }                }
3683              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
3684                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3685                    !!!cp ('t136');
3686                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3687                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3688                  !!!next-token;                  !!!next-token;
3689                  redo B;                  redo B;
3690                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3691                    !!!cp ('t137');
3692                  !!!parse-error (type => 'unmatched end tag:noscript');                  !!!parse-error (type => 'unmatched end tag:noscript');
3693                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
3694                  !!!next-token;                  !!!next-token;
3695                  redo B;                  redo B;
3696                } else {                } else {
3697                    !!!cp ('t138');
3698                  #                  #
3699                }                }
3700              } elsif ({              } elsif ({
3701                        body => 1, html => 1,                        body => 1, html => 1,
3702                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
3703                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3704                    !!!cp ('t139');
3705                  ## As if <head>                  ## As if <head>
3706                  !!!create-element ($self->{head_element}, 'head');                  !!!create-element ($self->{head_element}, 'head');
3707                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3231  sub _tree_construction_main ($) { Line 3710  sub _tree_construction_main ($) {
3710                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3711                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3712                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3713                    !!!cp ('t140');
3714                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3715                  ## Ignore the token                  ## Ignore the token
3716                  !!!next-token;                  !!!next-token;
3717                  redo B;                  redo B;
3718                  } else {
3719                    !!!cp ('t141');
3720                }                }
3721                                
3722                #                #
# Line 3242  sub _tree_construction_main ($) { Line 3724  sub _tree_construction_main ($) {
3724                        p => 1, br => 1,                        p => 1, br => 1,
3725                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
3726                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3727                    !!!cp ('t142');
3728                  ## As if <head>                  ## As if <head>
3729                  !!!create-element ($self->{head_element}, 'head');                  !!!create-element ($self->{head_element}, 'head');
3730                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3249  sub _tree_construction_main ($) { Line 3732  sub _tree_construction_main ($) {
3732    
3733                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3734                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3735                  } else {
3736                    !!!cp ('t143');
3737                }                }
3738    
3739                #                #
3740              } else {              } else {
3741                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3742                    !!!cp ('t144');
3743                  #                  #
3744                } else {                } else {
3745                    !!!cp ('t145');
3746                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3747                  ## Ignore the token                  ## Ignore the token
3748                  !!!next-token;                  !!!next-token;
# Line 3264  sub _tree_construction_main ($) { Line 3751  sub _tree_construction_main ($) {
3751              }              }
3752    
3753              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3754                  !!!cp ('t146');
3755                ## As if </noscript>                ## As if </noscript>
3756                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3757                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});
# Line 3274  sub _tree_construction_main ($) { Line 3762  sub _tree_construction_main ($) {
3762    
3763                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3764              } elsif ($self->{insertion_mode} == IN_HEAD_IM) {              } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3765                  !!!cp ('t147');
3766                ## As if </head>                ## As if </head>
3767                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3768    
3769                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3770              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3771                  !!!cp ('t148');
3772                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3773                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
3774                !!!next-token;                !!!next-token;
3775                redo B;                redo B;
3776                } else {
3777                  !!!cp ('t149');
3778              }              }
3779    
3780              ## "after head" insertion mode              ## "after head" insertion mode
# Line 3298  sub _tree_construction_main ($) { Line 3790  sub _tree_construction_main ($) {
3790            ## ISSUE: An issue in the spec.            ## ISSUE: An issue in the spec.
3791      } elsif ($self->{insertion_mode} & BODY_IMS) {      } elsif ($self->{insertion_mode} & BODY_IMS) {
3792            if ($token->{type} == CHARACTER_TOKEN) {            if ($token->{type} == CHARACTER_TOKEN) {
3793                !!!cp ('t150');
3794              ## NOTE: There is a code clone of "character in body".              ## NOTE: There is a code clone of "character in body".
3795              $reconstruct_active_formatting_elements->($insert_to_current);              $reconstruct_active_formatting_elements->($insert_to_current);
3796                            
# Line 3316  sub _tree_construction_main ($) { Line 3809  sub _tree_construction_main ($) {
3809                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3810                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
3811                    if ($node->[1] eq 'td' or $node->[1] eq 'th') {                    if ($node->[1] eq 'td' or $node->[1] eq 'th') {
3812                        !!!cp ('t151');
3813                      $tn = $node->[1];                      $tn = $node->[1];
3814                      last INSCOPE;                      last INSCOPE;
3815                    } elsif ({                    } elsif ({
3816                              table => 1, html => 1,                              table => 1, html => 1,
3817                             }->{$node->[1]}) {                             }->{$node->[1]}) {
3818                        !!!cp ('t152');
3819                      last INSCOPE;                      last INSCOPE;
3820                    }                    }
3821                  } # INSCOPE                  } # INSCOPE
3822                    unless (defined $tn) {                    unless (defined $tn) {
3823                        !!!cp ('t153');
3824                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3825                      ## Ignore the token                      ## Ignore the token
3826                      !!!next-token;                      !!!next-token;
3827                      redo B;                      redo B;
3828                    }                    }
3829                                    
3830                    !!!cp ('t154');
3831                  ## Close the cell                  ## Close the cell
3832                  !!!back-token; # <?>                  !!!back-token; # <?>
3833                  $token = {type => END_TAG_TOKEN, tag_name => $tn};                  $token = {type => END_TAG_TOKEN, tag_name => $tn};
# Line 3344  sub _tree_construction_main ($) { Line 3841  sub _tree_construction_main ($) {
3841                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3842                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
3843                    if ($node->[1] eq 'caption') {                    if ($node->[1] eq 'caption') {
3844                        !!!cp ('t155');
3845                      $i = $_;                      $i = $_;
3846                      last INSCOPE;                      last INSCOPE;
3847                    } elsif ({                    } elsif ({
3848                              table => 1, html => 1,                              table => 1, html => 1,
3849                             }->{$node->[1]}) {                             }->{$node->[1]}) {
3850                        !!!cp ('t156');
3851                      last INSCOPE;                      last INSCOPE;
3852                    }                    }
3853                  } # INSCOPE                  } # INSCOPE
3854                    unless (defined $i) {                    unless (defined $i) {
3855                        !!!cp ('t157');
3856                      !!!parse-error (type => 'unmatched end tag:caption');                      !!!parse-error (type => 'unmatched end tag:caption');
3857                      ## Ignore the token                      ## Ignore the token
3858                      !!!next-token;                      !!!next-token;
# Line 3365  sub _tree_construction_main ($) { Line 3865  sub _tree_construction_main ($) {
3865                       td => 1, th => 1, tr => 1,                       td => 1, th => 1, tr => 1,
3866                       tbody => 1, tfoot=> 1, thead => 1,                       tbody => 1, tfoot=> 1, thead => 1,
3867                      }->{$self->{open_elements}->[-1]->[1]}) {                      }->{$self->{open_elements}->[-1]->[1]}) {
3868                      !!!cp ('t158');
3869                    !!!back-token; # <?>                    !!!back-token; # <?>
3870                    $token = {type => END_TAG_TOKEN, tag_name => 'caption'};                    $token = {type => END_TAG_TOKEN, tag_name => 'caption'};
3871                    !!!back-token;                    !!!back-token;
# Line 3374  sub _tree_construction_main ($) { Line 3875  sub _tree_construction_main ($) {
3875                  }                  }
3876    
3877                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
3878                      !!!cp ('t159');
3879                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3880                    } else {
3881                      !!!cp ('t160');
3882                  }                  }
3883                                    
3884                  splice @{$self->{open_elements}}, $i;                  splice @{$self->{open_elements}}, $i;
# Line 3386  sub _tree_construction_main ($) { Line 3890  sub _tree_construction_main ($) {
3890                  ## reprocess                  ## reprocess
3891                  redo B;                  redo B;
3892                } else {                } else {
3893                    !!!cp ('t161');
3894                  #                  #
3895                }                }
3896              } else {              } else {
3897                  !!!cp ('t162');
3898                #                #
3899              }              }
3900            } elsif ($token->{type} == END_TAG_TOKEN) {            } elsif ($token->{type} == END_TAG_TOKEN) {
# Line 3399  sub _tree_construction_main ($) { Line 3905  sub _tree_construction_main ($) {
3905                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3906                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
3907                    if ($node->[1] eq $token->{tag_name}) {                    if ($node->[1] eq $token->{tag_name}) {
3908                        !!!cp ('t163');
3909                      $i = $_;                      $i = $_;
3910                      last INSCOPE;                      last INSCOPE;
3911                    } elsif ({                    } elsif ({
3912                              table => 1, html => 1,                              table => 1, html => 1,
3913                             }->{$node->[1]}) {                             }->{$node->[1]}) {
3914                        !!!cp ('t164');
3915                      last INSCOPE;                      last INSCOPE;
3916                    }                    }
3917                  } # INSCOPE                  } # INSCOPE
3918                    unless (defined $i) {                    unless (defined $i) {
3919                        !!!cp ('t165');
3920                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3921                      ## Ignore the token                      ## Ignore the token
3922                      !!!next-token;                      !!!next-token;
# Line 3422  sub _tree_construction_main ($) { Line 3931  sub _tree_construction_main ($) {
3931                       tr => 1,                       tr => 1,
3932                       tbody => 1, tfoot=> 1, thead => 1,                       tbody => 1, tfoot=> 1, thead => 1,
3933                      }->{$self->{open_elements}->[-1]->[1]}) {                      }->{$self->{open_elements}->[-1]->[1]}) {
3934                      !!!cp ('t166');
3935                    !!!back-token;                    !!!back-token;
3936                    $token = {type => END_TAG_TOKEN,                    $token = {type => END_TAG_TOKEN,
3937                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
# Line 3429  sub _tree_construction_main ($) { Line 3939  sub _tree_construction_main ($) {
3939                  }                  }
3940                                    
3941                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
3942                      !!!cp ('t167');
3943                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3944                    } else {
3945                      !!!cp ('t168');
3946                  }                  }
3947                                    
3948                  splice @{$self->{open_elements}}, $i;                  splice @{$self->{open_elements}}, $i;
# Line 3441  sub _tree_construction_main ($) { Line 3954  sub _tree_construction_main ($) {
3954                  !!!next-token;                  !!!next-token;
3955                  redo B;                  redo B;
3956                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
3957                    !!!cp ('t169');
3958                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3959                  ## Ignore the token                  ## Ignore the token
3960                  !!!next-token;                  !!!next-token;
3961                  redo B;                  redo B;
3962                } else {                } else {
3963                    !!!cp ('t170');
3964                  #                  #
3965                }                }
3966              } elsif ($token->{tag_name} eq 'caption') {              } elsif ($token->{tag_name} eq 'caption') {
# Line 3455  sub _tree_construction_main ($) { Line 3970  sub _tree_construction_main ($) {
3970                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3971                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
3972                    if ($node->[1] eq $token->{tag_name}) {                    if ($node->[1] eq $token->{tag_name}) {
3973                        !!!cp ('t171');
3974                      $i = $_;                      $i = $_;
3975                      last INSCOPE;                      last INSCOPE;
3976                    } elsif ({                    } elsif ({
3977                              table => 1, html => 1,                              table => 1, html => 1,
3978                             }->{$node->[1]}) {                             }->{$node->[1]}) {
3979                        !!!cp ('t172');
3980                      last INSCOPE;                      last INSCOPE;
3981                    }                    }
3982                  } # INSCOPE                  } # INSCOPE
3983                    unless (defined $i) {                    unless (defined $i) {
3984                        !!!cp ('t173');
3985                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3986                      ## Ignore the token                      ## Ignore the token
3987                      !!!next-token;                      !!!next-token;
# Line 3476  sub _tree_construction_main ($) { Line 3994  sub _tree_construction_main ($) {
3994                       td => 1, th => 1, tr => 1,                       td => 1, th => 1, tr => 1,
3995                       tbody => 1, tfoot=> 1, thead => 1,                       tbody => 1, tfoot=> 1, thead => 1,
3996                      }->{$self->{open_elements}->[-1]->[1]}) {                      }->{$self->{open_elements}->[-1]->[1]}) {
3997                      !!!cp ('t174');
3998                    !!!back-token;                    !!!back-token;
3999                    $token = {type => END_TAG_TOKEN,                    $token = {type => END_TAG_TOKEN,
4000                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
# Line 3483  sub _tree_construction_main ($) { Line 4002  sub _tree_construction_main ($) {
4002                  }                  }
4003                                    
4004                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
4005                      !!!cp ('t175');
4006                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4007                    } else {
4008                      !!!cp ('t176');
4009                  }                  }
4010                                    
4011                  splice @{$self->{open_elements}}, $i;                  splice @{$self->{open_elements}}, $i;
# Line 3495  sub _tree_construction_main ($) { Line 4017  sub _tree_construction_main ($) {
4017                  !!!next-token;                  !!!next-token;
4018                  redo B;                  redo B;
4019                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
4020                    !!!cp ('t177');
4021                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4022                  ## Ignore the token                  ## Ignore the token
4023                  !!!next-token;                  !!!next-token;
4024                  redo B;                  redo B;
4025                } else {                } else {
4026                    !!!cp ('t178');
4027                  #                  #
4028                }                }
4029              } elsif ({              } elsif ({
# Line 3513  sub _tree_construction_main ($) { Line 4037  sub _tree_construction_main ($) {
4037                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4038                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4039                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4040                      !!!cp ('t179');
4041                    $i = $_;                    $i = $_;
4042                    last INSCOPE;                    last INSCOPE;
4043                  } elsif ($node->[1] eq 'td' or $node->[1] eq 'th') {                  } elsif ($node->[1] eq 'td' or $node->[1] eq 'th') {
4044                      !!!cp ('t180');
4045                    $tn = $node->[1];                    $tn = $node->[1];
4046                    ## NOTE: There is exactly one |td| or |th| element                    ## NOTE: There is exactly one |td| or |th| element
4047                    ## in scope in the stack of open elements by definition.                    ## in scope in the stack of open elements by definition.
4048                  } elsif ({                  } elsif ({
4049                            table => 1, html => 1,                            table => 1, html => 1,
4050                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4051                      !!!cp ('t181');
4052                    last INSCOPE;                    last INSCOPE;
4053                  }                  }
4054                } # INSCOPE                } # INSCOPE
4055                unless (defined $i) {                unless (defined $i) {
4056                    !!!cp ('t182');
4057                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4058                  ## Ignore the token                  ## Ignore the token
4059                  !!!next-token;                  !!!next-token;
4060                  redo B;                  redo B;
4061                  } else {
4062                    !!!cp ('t183');
4063                }                }
4064    
4065                ## Close the cell                ## Close the cell
# Line 3546  sub _tree_construction_main ($) { Line 4076  sub _tree_construction_main ($) {
4076                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4077                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4078                  if ($node->[1] eq 'caption') {                  if ($node->[1] eq 'caption') {
4079                      !!!cp ('t184');
4080                    $i = $_;                    $i = $_;
4081                    last INSCOPE;                    last INSCOPE;
4082                  } elsif ({                  } elsif ({
4083                            table => 1, html => 1,                            table => 1, html => 1,
4084                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4085                      !!!cp ('t185');
4086                    last INSCOPE;                    last INSCOPE;
4087                  }                  }
4088                } # INSCOPE                } # INSCOPE
4089                unless (defined $i) {                unless (defined $i) {
4090                    !!!cp ('t186');
4091                  !!!parse-error (type => 'unmatched end tag:caption');                  !!!parse-error (type => 'unmatched end tag:caption');
4092                  ## Ignore the token                  ## Ignore the token
4093                  !!!next-token;                  !!!next-token;
# Line 3567  sub _tree_construction_main ($) { Line 4100  sub _tree_construction_main ($) {
4100                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4101                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
4102                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4103                    !!!cp ('t187');
4104                  !!!back-token; # </table>                  !!!back-token; # </table>
4105                  $token = {type => END_TAG_TOKEN, tag_name => 'caption'};                  $token = {type => END_TAG_TOKEN, tag_name => 'caption'};
4106                  !!!back-token;                  !!!back-token;
# Line 3576  sub _tree_construction_main ($) { Line 4110  sub _tree_construction_main ($) {
4110                }                }
4111    
4112                if ($self->{open_elements}->[-1]->[1] ne 'caption') {                if ($self->{open_elements}->[-1]->[1] ne 'caption') {
4113                    !!!cp ('t188');
4114                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4115                  } else {
4116                    !!!cp ('t189');
4117                }                }
4118    
4119                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
# Line 3591  sub _tree_construction_main ($) { Line 4128  sub _tree_construction_main ($) {
4128                        body => 1, col => 1, colgroup => 1, html => 1,                        body => 1, col => 1, colgroup => 1, html => 1,
4129                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4130                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
4131                    !!!cp ('t190');
4132                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4133                  ## Ignore the token                  ## Ignore the token
4134                  !!!next-token;                  !!!next-token;
4135                  redo B;                  redo B;
4136                } else {                } else {
4137                    !!!cp ('t191');
4138                  #                  #
4139                }                }
4140              } elsif ({              } elsif ({
# Line 3603  sub _tree_construction_main ($) { Line 4142  sub _tree_construction_main ($) {
4142                        thead => 1, tr => 1,                        thead => 1, tr => 1,
4143                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
4144                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
4145                  !!!cp ('t192');
4146                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4147                ## Ignore the token                ## Ignore the token
4148                !!!next-token;                !!!next-token;
4149                redo B;                redo B;
4150              } else {              } else {
4151                  !!!cp ('t193');
4152                #                #
4153              }              }
4154        } else {        } else {
# Line 3622  sub _tree_construction_main ($) { Line 4163  sub _tree_construction_main ($) {
4163                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4164                                
4165                unless (length $token->{data}) {                unless (length $token->{data}) {
4166                    !!!cp ('t194');
4167                  !!!next-token;                  !!!next-token;
4168                  redo B;                  redo B;
4169                  } else {
4170                    !!!cp ('t195');
4171                }                }
4172              }              }
4173    
# Line 3647  sub _tree_construction_main ($) { Line 4191  sub _tree_construction_main ($) {
4191                  if ($self->{open_elements}->[$_]->[1] eq 'table') {                  if ($self->{open_elements}->[$_]->[1] eq 'table') {
4192                    my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                    my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
4193                    if (defined $parent and $parent->node_type == 1) {                    if (defined $parent and $parent->node_type == 1) {
4194                        !!!cp ('t196');
4195                      $foster_parent_element = $parent;                      $foster_parent_element = $parent;
4196                      $next_sibling = $self->{open_elements}->[$_]->[0];                      $next_sibling = $self->{open_elements}->[$_]->[0];
4197                      $prev_sibling = $next_sibling->previous_sibling;                      $prev_sibling = $next_sibling->previous_sibling;
4198                    } else {                    } else {
4199                        !!!cp ('t197');
4200                      $foster_parent_element = $self->{open_elements}->[$_ - 1]->[0];                      $foster_parent_element = $self->{open_elements}->[$_ - 1]->[0];
4201                      $prev_sibling = $foster_parent_element->last_child;                      $prev_sibling = $foster_parent_element->last_child;
4202                    }                    }
# Line 3662  sub _tree_construction_main ($) { Line 4208  sub _tree_construction_main ($) {
4208                  unless defined $foster_parent_element;                  unless defined $foster_parent_element;
4209                if (defined $prev_sibling and                if (defined $prev_sibling and
4210                    $prev_sibling->node_type == 3) {                    $prev_sibling->node_type == 3) {
4211                    !!!cp ('t198');
4212                  $prev_sibling->manakai_append_text ($token->{data});                  $prev_sibling->manakai_append_text ($token->{data});
4213                } else {                } else {
4214                    !!!cp ('t199');
4215                  $foster_parent_element->insert_before                  $foster_parent_element->insert_before
4216                    ($self->{document}->create_text_node ($token->{data}),                    ($self->{document}->create_text_node ($token->{data}),
4217                     $next_sibling);                     $next_sibling);
4218                }                }
4219              } else {              } else {
4220                  !!!cp ('t200');
4221                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4222              }              }
4223                            
# Line 3683  sub _tree_construction_main ($) { Line 4232  sub _tree_construction_main ($) {
4232                  ## Clear back to table context                  ## Clear back to table context
4233                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4234                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4235                      !!!cp ('t201');
4236                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4237                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4238                  }                  }
# Line 3694  sub _tree_construction_main ($) { Line 4244  sub _tree_construction_main ($) {
4244    
4245                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
4246                  unless ($token->{tag_name} eq 'tr') {                  unless ($token->{tag_name} eq 'tr') {
4247                      !!!cp ('t202');
4248                    !!!parse-error (type => 'missing start tag:tr');                    !!!parse-error (type => 'missing start tag:tr');
4249                  }                  }
4250                                    
# Line 3701  sub _tree_construction_main ($) { Line 4252  sub _tree_construction_main ($) {
4252                  while (not {                  while (not {
4253                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4254                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4255                      !!!cp ('t203');
4256                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4257                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4258                  }                  }
4259                                    
4260                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
4261                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
4262                      !!!cp ('t204');
4263                    !!!insert-element ($token->{tag_name}, $token->{attributes});                    !!!insert-element ($token->{tag_name}, $token->{attributes});
4264                    !!!next-token;                    !!!next-token;
4265                    redo B;                    redo B;
4266                  } else {                  } else {
4267                      !!!cp ('t205');
4268                    !!!insert-element ('tr');                    !!!insert-element ('tr');
4269                    ## reprocess in the "in row" insertion mode                    ## reprocess in the "in row" insertion mode
4270                  }                  }
4271                  } else {
4272                    !!!cp ('t206');
4273                }                }
4274    
4275                ## Clear back to table row context                ## Clear back to table row context
4276                while (not {                while (not {
4277                  tr => 1, html => 1,                  tr => 1, html => 1,
4278                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4279                    !!!cp ('t207');
4280                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4281                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4282                }                }
# Line 3743  sub _tree_construction_main ($) { Line 4300  sub _tree_construction_main ($) {
4300                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4301                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4302                    if ($node->[1] eq 'tr') {                    if ($node->[1] eq 'tr') {
4303                        !!!cp ('t208');
4304                      $i = $_;                      $i = $_;
4305                      last INSCOPE;                      last INSCOPE;
4306                    } elsif ({                    } elsif ({
4307                              table => 1, html => 1,                              table => 1, html => 1,
4308                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4309                        !!!cp ('t209');
4310                      last INSCOPE;                      last INSCOPE;
4311                    }                    }
4312                  } # INSCOPE                  } # INSCOPE
4313                  unless (defined $i) {                  unless (defined $i) {
4314                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});                   !!!cp ('t210');
4315                     !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});
4316                    ## Ignore the token                    ## Ignore the token
4317                    !!!next-token;                    !!!next-token;
4318                    redo B;                    redo B;
# Line 3762  sub _tree_construction_main ($) { Line 4322  sub _tree_construction_main ($) {
4322                  while (not {                  while (not {
4323                    tr => 1, html => 1,                    tr => 1, html => 1,
4324                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4325                      !!!cp ('t211');
4326                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4327                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4328                  }                  }
# Line 3769  sub _tree_construction_main ($) { Line 4330  sub _tree_construction_main ($) {
4330                  pop @{$self->{open_elements}}; # tr                  pop @{$self->{open_elements}}; # tr
4331                  $self->{insertion_mode} = IN_TABLE_BODY_IM;                  $self->{insertion_mode} = IN_TABLE_BODY_IM;
4332                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
4333                      !!!cp ('t212');
4334                    ## reprocess                    ## reprocess
4335                    redo B;                    redo B;
4336                  } else {                  } else {
4337                      !!!cp ('t213');
4338                    ## reprocess in the "in table body" insertion mode...                    ## reprocess in the "in table body" insertion mode...
4339                  }                  }
4340                }                }
# Line 3784  sub _tree_construction_main ($) { Line 4347  sub _tree_construction_main ($) {
4347                    if ({                    if ({
4348                         tbody => 1, thead => 1, tfoot => 1,                         tbody => 1, thead => 1, tfoot => 1,
4349                        }->{$node->[1]}) {                        }->{$node->[1]}) {
4350                        !!!cp ('t214');
4351                      $i = $_;                      $i = $_;
4352                      last INSCOPE;                      last INSCOPE;
4353                    } elsif ({                    } elsif ({
4354                              table => 1, html => 1,                              table => 1, html => 1,
4355                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4356                        !!!cp ('t215');
4357                      last INSCOPE;                      last INSCOPE;
4358                    }                    }
4359                  } # INSCOPE                  } # INSCOPE
4360                  unless (defined $i) {                  unless (defined $i) {
4361                      !!!cp ('t216');
4362                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4363                    ## Ignore the token                    ## Ignore the token
4364                    !!!next-token;                    !!!next-token;
# Line 3803  sub _tree_construction_main ($) { Line 4369  sub _tree_construction_main ($) {
4369                  while (not {                  while (not {
4370                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4371                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4372                      !!!cp ('t217');
4373                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4374                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4375                  }                  }
# Line 3817  sub _tree_construction_main ($) { Line 4384  sub _tree_construction_main ($) {
4384                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4385                  $self->{insertion_mode} = IN_TABLE_IM;                  $self->{insertion_mode} = IN_TABLE_IM;
4386                  ## reprocess in "in table" insertion mode...                  ## reprocess in "in table" insertion mode...
4387                  } else {
4388                    !!!cp ('t218');
4389                }                }
4390    
4391                if ($token->{tag_name} eq 'col') {                if ($token->{tag_name} eq 'col') {
4392                  ## Clear back to table context                  ## Clear back to table context
4393                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4394                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4395                      !!!cp ('t219');
4396                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4397                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4398                  }                  }
# Line 3839  sub _tree_construction_main ($) { Line 4409  sub _tree_construction_main ($) {
4409                  ## Clear back to table context                  ## Clear back to table context
4410                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4411                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4412                      !!!cp ('t220');
4413                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4414                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4415                  }                  }
# Line 3868  sub _tree_construction_main ($) { Line 4439  sub _tree_construction_main ($) {
4439                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4440                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4441                  if ($node->[1] eq 'table') {                  if ($node->[1] eq 'table') {
4442                      !!!cp ('t221');
4443                    $i = $_;                    $i = $_;
4444                    last INSCOPE;                    last INSCOPE;
4445                  } elsif ({                  } elsif ({
4446                            table => 1, html => 1,                            table => 1, html => 1,
4447                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4448                      !!!cp ('t222');
4449                    last INSCOPE;                    last INSCOPE;
4450                  }                  }
4451                } # INSCOPE                } # INSCOPE
4452                unless (defined $i) {                unless (defined $i) {
4453                    !!!cp ('t223');
4454                  !!!parse-error (type => 'unmatched end tag:table');                  !!!parse-error (type => 'unmatched end tag:table');
4455                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
4456                  !!!next-token;                  !!!next-token;
# Line 3889  sub _tree_construction_main ($) { Line 4463  sub _tree_construction_main ($) {
4463                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4464                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
4465                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4466                    !!!cp ('t224');
4467                  !!!back-token; # <table>                  !!!back-token; # <table>
4468                  $token = {type => END_TAG_TOKEN, tag_name => 'table'};                  $token = {type => END_TAG_TOKEN, tag_name => 'table'};
4469                  !!!back-token;                  !!!back-token;
# Line 3898  sub _tree_construction_main ($) { Line 4473  sub _tree_construction_main ($) {
4473                }                }
4474    
4475                if ($self->{open_elements}->[-1]->[1] ne 'table') {                if ($self->{open_elements}->[-1]->[1] ne 'table') {
4476                    !!!cp ('t225');
4477                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4478                  } else {
4479                    !!!cp ('t226');
4480                }                }
4481    
4482                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
# Line 3908  sub _tree_construction_main ($) { Line 4486  sub _tree_construction_main ($) {
4486                ## reprocess                ## reprocess
4487                redo B;                redo B;
4488          } else {          } else {
4489              !!!cp ('t227');
4490            !!!parse-error (type => 'in table:'.$token->{tag_name});            !!!parse-error (type => 'in table:'.$token->{tag_name});
4491    
4492            $insert = $insert_to_foster;            $insert = $insert_to_foster;
# Line 3921  sub _tree_construction_main ($) { Line 4500  sub _tree_construction_main ($) {
4500                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4501                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4502                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4503                      !!!cp ('t228');
4504                    $i = $_;                    $i = $_;
4505                    last INSCOPE;                    last INSCOPE;
4506                  } elsif ({                  } elsif ({
4507                            table => 1, html => 1,                            table => 1, html => 1,
4508                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4509                      !!!cp ('t229');
4510                    last INSCOPE;                    last INSCOPE;
4511                  }                  }
4512                } # INSCOPE                } # INSCOPE
4513                unless (defined $i) {                unless (defined $i) {
4514                    !!!cp ('t230');
4515                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4516                  ## Ignore the token                  ## Ignore the token
4517                  !!!next-token;                  !!!next-token;
4518                  redo B;                  redo B;
4519                  } else {
4520                    !!!cp ('t232');
4521                }                }
4522    
4523                ## Clear back to table row context                ## Clear back to table row context
4524                while (not {                while (not {
4525                  tr => 1, html => 1,                  tr => 1, html => 1,
4526                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4527                    !!!cp ('t231');
4528                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4529                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4530                }                }
# Line 3956  sub _tree_construction_main ($) { Line 4541  sub _tree_construction_main ($) {
4541                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4542                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4543                    if ($node->[1] eq 'tr') {                    if ($node->[1] eq 'tr') {
4544                        !!!cp ('t233');
4545                      $i = $_;                      $i = $_;
4546                      last INSCOPE;                      last INSCOPE;
4547                    } elsif ({                    } elsif ({
4548                              table => 1, html => 1,                              table => 1, html => 1,
4549                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4550                        !!!cp ('t234');
4551                      last INSCOPE;                      last INSCOPE;
4552                    }                    }
4553                  } # INSCOPE                  } # INSCOPE
4554                  unless (defined $i) {                  unless (defined $i) {
4555                      !!!cp ('t235');
4556                    !!!parse-error (type => 'unmatched end tag:'.$token->{type});                    !!!parse-error (type => 'unmatched end tag:'.$token->{type});
4557                    ## Ignore the token                    ## Ignore the token
4558                    !!!next-token;                    !!!next-token;
# Line 3975  sub _tree_construction_main ($) { Line 4563  sub _tree_construction_main ($) {
4563                  while (not {                  while (not {
4564                    tr => 1, html => 1,                    tr => 1, html => 1,
4565                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4566                      !!!cp ('t236');
4567                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4568                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4569                  }                  }
# Line 3992  sub _tree_construction_main ($) { Line 4581  sub _tree_construction_main ($) {
4581                    if ({                    if ({
4582                         tbody => 1, thead => 1, tfoot => 1,                         tbody => 1, thead => 1, tfoot => 1,
4583                        }->{$node->[1]}) {                        }->{$node->[1]}) {
4584                        !!!cp ('t237');
4585                      $i = $_;                      $i = $_;
4586                      last INSCOPE;                      last INSCOPE;
4587                    } elsif ({                    } elsif ({
4588                              table => 1, html => 1,                              table => 1, html => 1,
4589                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4590                        !!!cp ('t238');
4591                      last INSCOPE;                      last INSCOPE;
4592                    }                    }
4593                  } # INSCOPE                  } # INSCOPE
4594                  unless (defined $i) {                  unless (defined $i) {
4595                      !!!cp ('t239');
4596                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4597                    ## Ignore the token                    ## Ignore the token
4598                    !!!next-token;                    !!!next-token;
# Line 4011  sub _tree_construction_main ($) { Line 4603  sub _tree_construction_main ($) {
4603                  while (not {                  while (not {
4604                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4605                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4606                      !!!cp ('t240');
4607                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4608                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4609                  }                  }
# Line 4032  sub _tree_construction_main ($) { Line 4625  sub _tree_construction_main ($) {
4625                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4626                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4627                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4628                      !!!cp ('t241');
4629                    $i = $_;                    $i = $_;
4630                    last INSCOPE;                    last INSCOPE;
4631                  } elsif ({                  } elsif ({
4632                            table => 1, html => 1,                            table => 1, html => 1,
4633                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4634                      !!!cp ('t242');
4635                    last INSCOPE;                    last INSCOPE;
4636                  }                  }
4637                } # INSCOPE                } # INSCOPE
4638                unless (defined $i) {                unless (defined $i) {
4639                    !!!cp ('t243');
4640                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4641                  ## Ignore the token                  ## Ignore the token
4642                  !!!next-token;                  !!!next-token;
# Line 4053  sub _tree_construction_main ($) { Line 4649  sub _tree_construction_main ($) {
4649                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4650                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
4651                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4652                    !!!cp ('t244');
4653                  !!!back-token;                  !!!back-token;
4654                  $token = {type => END_TAG_TOKEN,                  $token = {type => END_TAG_TOKEN,
4655                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
# Line 4060  sub _tree_construction_main ($) { Line 4657  sub _tree_construction_main ($) {
4657                }                }
4658                                
4659                if ($self->{open_elements}->[-1]->[1] ne 'table') {                if ($self->{open_elements}->[-1]->[1] ne 'table') {
4660                    !!!cp ('t245');
4661                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4662                  } else {
4663                    !!!cp ('t246');
4664                }                }
4665                                    
4666                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
# Line 4079  sub _tree_construction_main ($) { Line 4679  sub _tree_construction_main ($) {
4679                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4680                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4681                    if ($node->[1] eq $token->{tag_name}) {                    if ($node->[1] eq $token->{tag_name}) {
4682                        !!!cp ('t247');
4683                      $i = $_;                      $i = $_;
4684                      last INSCOPE;                      last INSCOPE;
4685                    } elsif ({                    } elsif ({
4686                              table => 1, html => 1,                              table => 1, html => 1,
4687                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4688                        !!!cp ('t248');
4689                      last INSCOPE;                      last INSCOPE;
4690                    }                    }
4691                  } # INSCOPE                  } # INSCOPE
4692                    unless (defined $i) {                    unless (defined $i) {
4693                        !!!cp ('t249');
4694                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4695                      ## Ignore the token                      ## Ignore the token
4696                      !!!next-token;                      !!!next-token;
# Line 4100  sub _tree_construction_main ($) { Line 4703  sub _tree_construction_main ($) {
4703                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4704                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4705                    if ($node->[1] eq 'tr') {                    if ($node->[1] eq 'tr') {
4706                        !!!cp ('t250');
4707                      $i = $_;                      $i = $_;
4708                      last INSCOPE;                      last INSCOPE;
4709                    } elsif ({                    } elsif ({
4710                              table => 1, html => 1,                              table => 1, html => 1,
4711                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4712                        !!!cp ('t251');
4713                      last INSCOPE;                      last INSCOPE;
4714                    }                    }
4715                  } # INSCOPE                  } # INSCOPE
4716                    unless (defined $i) {                    unless (defined $i) {
4717                        !!!cp ('t252');
4718                      !!!parse-error (type => 'unmatched end tag:tr');                      !!!parse-error (type => 'unmatched end tag:tr');
4719                      ## Ignore the token                      ## Ignore the token
4720                      !!!next-token;                      !!!next-token;
# Line 4119  sub _tree_construction_main ($) { Line 4725  sub _tree_construction_main ($) {
4725                  while (not {                  while (not {
4726                    tr => 1, html => 1,                    tr => 1, html => 1,
4727                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4728                      !!!cp ('t253');
4729                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4730                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4731                  }                  }
# Line 4133  sub _tree_construction_main ($) { Line 4740  sub _tree_construction_main ($) {
4740                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4741                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4742                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4743                      !!!cp ('t254');
4744                    $i = $_;                    $i = $_;
4745                    last INSCOPE;                    last INSCOPE;
4746                  } elsif ({                  } elsif ({
4747                            table => 1, html => 1,                            table => 1, html => 1,
4748                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4749                      !!!cp ('t255');
4750                    last INSCOPE;                    last INSCOPE;
4751                  }                  }
4752                } # INSCOPE                } # INSCOPE
4753                unless (defined $i) {                unless (defined $i) {
4754                    !!!cp ('t256');
4755                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4756                  ## Ignore the token                  ## Ignore the token
4757                  !!!next-token;                  !!!next-token;
# Line 4152  sub _tree_construction_main ($) { Line 4762  sub _tree_construction_main ($) {
4762                while (not {                while (not {
4763                  tbody => 1, tfoot => 1, thead => 1, html => 1,                  tbody => 1, tfoot => 1, thead => 1, html => 1,
4764                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4765                    !!!cp ('t257');
4766                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4767                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4768                }                }
# Line 4166  sub _tree_construction_main ($) { Line 4777  sub _tree_construction_main ($) {
4777                        tr => 1, # $self->{insertion_mode} == IN_ROW_IM                        tr => 1, # $self->{insertion_mode} == IN_ROW_IM
4778                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
4779                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4780                  !!!cp ('t258');
4781                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4782                ## Ignore the token                ## Ignore the token
4783                !!!next-token;                !!!next-token;
4784                redo B;                redo B;
4785          } else {          } else {
4786              !!!cp ('t259');
4787            !!!parse-error (type => 'in table:/'.$token->{tag_name});            !!!parse-error (type => 'in table:/'.$token->{tag_name});
4788    
4789            $insert = $insert_to_foster;            $insert = $insert_to_foster;
# Line 4184  sub _tree_construction_main ($) { Line 4797  sub _tree_construction_main ($) {
4797              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4798                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4799                unless (length $token->{data}) {                unless (length $token->{data}) {
4800                    !!!cp ('t260');
4801                  !!!next-token;                  !!!next-token;
4802                  redo B;                  redo B;
4803                }                }
4804              }              }
4805                            
4806                !!!cp ('t261');
4807              #              #
4808            } elsif ($token->{type} == START_TAG_TOKEN) {            } elsif ($token->{type} == START_TAG_TOKEN) {
4809              if ($token->{tag_name} eq 'col') {              if ($token->{tag_name} eq 'col') {
4810                  !!!cp ('t262');
4811                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
4812                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4813                !!!next-token;                !!!next-token;
4814                redo B;                redo B;
4815              } else {              } else {
4816                  !!!cp ('t263');
4817                #                #
4818              }              }
4819            } elsif ($token->{type} == END_TAG_TOKEN) {            } elsif ($token->{type} == END_TAG_TOKEN) {
4820              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
4821                if ($self->{open_elements}->[-1]->[1] eq 'html') {                if ($self->{open_elements}->[-1]->[1] eq 'html') {
4822                    !!!cp ('t264');
4823                  !!!parse-error (type => 'unmatched end tag:colgroup');                  !!!parse-error (type => 'unmatched end tag:colgroup');
4824                  ## Ignore the token                  ## Ignore the token
4825                  !!!next-token;                  !!!next-token;
4826                  redo B;                  redo B;
4827                } else {                } else {
4828                    !!!cp ('t265');
4829                  pop @{$self->{open_elements}}; # colgroup                  pop @{$self->{open_elements}}; # colgroup
4830                  $self->{insertion_mode} = IN_TABLE_IM;                  $self->{insertion_mode} = IN_TABLE_IM;
4831                  !!!next-token;                  !!!next-token;
4832                  redo B;                              redo B;            
4833                }                }
4834              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
4835                  !!!cp ('t266');
4836                !!!parse-error (type => 'unmatched end tag:col');                !!!parse-error (type => 'unmatched end tag:col');
4837                ## Ignore the token                ## Ignore the token
4838                !!!next-token;                !!!next-token;
4839                redo B;                redo B;
4840              } else {              } else {
4841                  !!!cp ('t267');
4842                #                #
4843              }              }
4844            } else {            } else {
4845                !!!cp ('t268');
4846              #              #
4847            }            }
4848    
4849            ## As if </colgroup>            ## As if </colgroup>
4850            if ($self->{open_elements}->[-1]->[1] eq 'html') {            if ($self->{open_elements}->[-1]->[1] eq 'html') {
4851                !!!cp ('t269');
4852              !!!parse-error (type => 'unmatched end tag:colgroup');              !!!parse-error (type => 'unmatched end tag:colgroup');
4853              ## Ignore the token              ## Ignore the token
4854              !!!next-token;              !!!next-token;
4855              redo B;              redo B;
4856            } else {            } else {
4857                !!!cp ('t270');
4858              pop @{$self->{open_elements}}; # colgroup              pop @{$self->{open_elements}}; # colgroup
4859              $self->{insertion_mode} = IN_TABLE_IM;              $self->{insertion_mode} = IN_TABLE_IM;
4860              ## reprocess              ## reprocess
# Line 4238  sub _tree_construction_main ($) { Line 4862  sub _tree_construction_main ($) {
4862            }            }
4863      } elsif ($self->{insertion_mode} == IN_SELECT_IM) {      } elsif ($self->{insertion_mode} == IN_SELECT_IM) {
4864        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
4865            !!!cp ('t271');
4866          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4867          !!!next-token;          !!!next-token;
4868          redo B;          redo B;
4869        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
4870              if ($token->{tag_name} eq 'option') {              if ($token->{tag_name} eq 'option') {
4871                if ($self->{open_elements}->[-1]->[1] eq 'option') {                if ($self->{open_elements}->[-1]->[1] eq 'option') {
4872                    !!!cp ('t272');
4873                  ## As if </option>                  ## As if </option>
4874                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4875                  } else {
4876                    !!!cp ('t273');
4877                }                }
4878    
4879                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
# Line 4253  sub _tree_construction_main ($) { Line 4881  sub _tree_construction_main ($) {
4881                redo B;                redo B;
4882              } elsif ($token->{tag_name} eq 'optgroup') {              } elsif ($token->{tag_name} eq 'optgroup') {
4883                if ($self->{open_elements}->[-1]->[1] eq 'option') {                if ($self->{open_elements}->[-1]->[1] eq 'option') {
4884                    !!!cp ('t274');
4885                  ## As if </option>                  ## As if </option>
4886                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4887                  } else {
4888                    !!!cp ('t275');
4889                }                }
4890    
4891                if ($self->{open_elements}->[-1]->[1] eq 'optgroup') {                if ($self->{open_elements}->[-1]->[1] eq 'optgroup') {
4892                    !!!cp ('t276');
4893                  ## As if </optgroup>                  ## As if </optgroup>
4894                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4895                  } else {
4896                    !!!cp ('t277');
4897                }                }
4898    
4899                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
# Line 4273  sub _tree_construction_main ($) { Line 4907  sub _tree_construction_main ($) {
4907                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4908                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4909                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4910                      !!!cp ('t278');
4911                    $i = $_;                    $i = $_;
4912                    last INSCOPE;                    last INSCOPE;
4913                  } elsif ({                  } elsif ({
4914                            table => 1, html => 1,                            table => 1, html => 1,
4915                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4916                      !!!cp ('t279');
4917                    last INSCOPE;                    last INSCOPE;
4918                  }                  }
4919                } # INSCOPE                } # INSCOPE
4920                unless (defined $i) {                unless (defined $i) {
4921                    !!!cp ('t280');
4922                  !!!parse-error (type => 'unmatched end tag:select');                  !!!parse-error (type => 'unmatched end tag:select');
4923                  ## Ignore the token                  ## Ignore the token
4924                  !!!next-token;                  !!!next-token;
4925                  redo B;                  redo B;
4926                }                }
4927                                
4928                  !!!cp ('t281');
4929                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4930    
4931                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
# Line 4295  sub _tree_construction_main ($) { Line 4933  sub _tree_construction_main ($) {
4933                !!!next-token;                !!!next-token;
4934                redo B;                redo B;
4935          } else {          } else {
4936              !!!cp ('t282');
4937            !!!parse-error (type => 'in select:'.$token->{tag_name});            !!!parse-error (type => 'in select:'.$token->{tag_name});
4938            ## Ignore the token            ## Ignore the token
4939            !!!next-token;            !!!next-token;
# Line 4304  sub _tree_construction_main ($) { Line 4943  sub _tree_construction_main ($) {
4943              if ($token->{tag_name} eq 'optgroup') {              if ($token->{tag_name} eq 'optgroup') {
4944                if ($self->{open_elements}->[-1]->[1] eq 'option' and                if ($self->{open_elements}->[-1]->[1] eq 'option' and
4945                    $self->{open_elements}->[-2]->[1] eq 'optgroup') {                    $self->{open_elements}->[-2]->[1] eq 'optgroup') {
4946                    !!!cp ('t283');
4947                  ## As if </option>                  ## As if </option>
4948                  splice @{$self->{open_elements}}, -2;                  splice @{$self->{open_elements}}, -2;
4949                } elsif ($self->{open_elements}->[-1]->[1] eq 'optgroup') {                } elsif ($self->{open_elements}->[-1]->[1] eq 'optgroup') {
4950                    !!!cp ('t284');
4951                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4952                } else {                } else {
4953                    !!!cp ('t285');
4954                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4955                  ## Ignore the token                  ## Ignore the token
4956                }                }
# Line 4316  sub _tree_construction_main ($) { Line 4958  sub _tree_construction_main ($) {
4958                redo B;                redo B;
4959              } elsif ($token->{tag_name} eq 'option') {              } elsif ($token->{tag_name} eq 'option') {
4960                if ($self->{open_elements}->[-1]->[1] eq 'option') {                if ($self->{open_elements}->[-1]->[1] eq 'option') {
4961                    !!!cp ('t286');
4962                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4963                } else {                } else {
4964                    !!!cp ('t287');
4965                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4966                  ## Ignore the token                  ## Ignore the token
4967                }                }
# Line 4329  sub _tree_construction_main ($) { Line 4973  sub _tree_construction_main ($) {
4973                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4974                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4975                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4976                      !!!cp ('t288');
4977                    $i = $_;                    $i = $_;
4978                    last INSCOPE;                    last INSCOPE;
4979                  } elsif ({                  } elsif ({
4980                            table => 1, html => 1,                            table => 1, html => 1,
4981                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4982                      !!!cp ('t289');
4983                    last INSCOPE;                    last INSCOPE;
4984                  }                  }
4985                } # INSCOPE                } # INSCOPE
4986                unless (defined $i) {                unless (defined $i) {
4987                    !!!cp ('t290');
4988                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4989                  ## Ignore the token                  ## Ignore the token
4990                  !!!next-token;                  !!!next-token;
4991                  redo B;                  redo B;
4992                }                }
4993                                
4994                  !!!cp ('t291');
4995                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4996    
4997                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
# Line 4361  sub _tree_construction_main ($) { Line 5009  sub _tree_construction_main ($) {
5009                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5010                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5011                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
5012                      !!!cp ('t292');
5013                    $i = $_;                    $i = $_;
5014                    last INSCOPE;                    last INSCOPE;
5015                  } elsif ({                  } elsif ({
5016                            table => 1, html => 1,                            table => 1, html => 1,
5017                           }->{$node->[1]}) {                           }->{$node->[1]}) {
5018                      !!!cp ('t293');
5019                    last INSCOPE;                    last INSCOPE;
5020                  }                  }
5021                } # INSCOPE                } # INSCOPE
5022                unless (defined $i) {                unless (defined $i) {
5023                    !!!cp ('t294');
5024                  ## Ignore the token                  ## Ignore the token
5025                  !!!next-token;                  !!!next-token;
5026                  redo B;                  redo B;
# Line 4381  sub _tree_construction_main ($) { Line 5032  sub _tree_construction_main ($) {
5032                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5033                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5034                  if ($node->[1] eq 'select') {                  if ($node->[1] eq 'select') {
5035                      !!!cp ('t295');
5036                    $i = $_;                    $i = $_;
5037                    last INSCOPE;                    last INSCOPE;
5038                  } elsif ({                  } elsif ({
5039                            table => 1, html => 1,                            table => 1, html => 1,
5040                           }->{$node->[1]}) {                           }->{$node->[1]}) {
5041                      !!!cp ('t296');
5042                    last INSCOPE;                    last INSCOPE;
5043                  }                  }
5044                } # INSCOPE                } # INSCOPE
5045                unless (defined $i) {                unless (defined $i) {
5046                    !!!cp ('t297');
5047                  !!!parse-error (type => 'unmatched end tag:select');                  !!!parse-error (type => 'unmatched end tag:select');
5048                  ## Ignore the </select> token                  ## Ignore the </select> token
5049                  !!!next-token; ## TODO: ok?                  !!!next-token; ## TODO: ok?
5050                  redo B;                  redo B;
5051                }                }
5052                                
5053                  !!!cp ('t298');
5054                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
5055    
5056                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
# Line 4403  sub _tree_construction_main ($) { Line 5058  sub _tree_construction_main ($) {
5058                ## reprocess                ## reprocess
5059                redo B;                redo B;
5060          } else {          } else {
5061              !!!cp ('t299');
5062            !!!parse-error (type => 'in select:/'.$token->{tag_name});            !!!parse-error (type => 'in select:/'.$token->{tag_name});
5063            ## Ignore the token            ## Ignore the token
5064            !!!next-token;            !!!next-token;
# Line 4421  sub _tree_construction_main ($) { Line 5077  sub _tree_construction_main ($) {
5077            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
5078                        
5079            unless (length $token->{data}) {            unless (length $token->{data}) {
5080                !!!cp ('t300');
5081              !!!next-token;              !!!next-token;
5082              redo B;              redo B;
5083            }            }
5084          }          }
5085                    
5086          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
5087              !!!cp ('t301');
5088            !!!parse-error (type => 'after html:#character');            !!!parse-error (type => 'after html:#character');
5089    
5090            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "main" phase, "after body" insertion mode...
5091            } else {
5092              !!!cp ('t302');
5093          }          }
5094                    
5095          ## "after body" insertion mode          ## "after body" insertion mode
# Line 4440  sub _tree_construction_main ($) { Line 5100  sub _tree_construction_main ($) {
5100          redo B;          redo B;
5101        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5102          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
5103              !!!cp ('t303');
5104            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
5105                        
5106            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "main" phase, "after body" insertion mode...
5107            } else {
5108              !!!cp ('t304');
5109          }          }
5110    
5111          ## "after body" insertion mode          ## "after body" insertion mode
# Line 4453  sub _tree_construction_main ($) { Line 5116  sub _tree_construction_main ($) {
5116          redo B;          redo B;
5117        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
5118          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
5119              !!!cp ('t305');
5120            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
5121                        
5122            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
5123            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "main" phase, "after body" insertion mode...
5124            } else {
5125              !!!cp ('t306');
5126          }          }
5127    
5128          ## "after body" insertion mode          ## "after body" insertion mode
5129          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
5130            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
5131                !!!cp ('t307');
5132              !!!parse-error (type => 'unmatched end tag:html');              !!!parse-error (type => 'unmatched end tag:html');
5133              ## Ignore the token              ## Ignore the token
5134              !!!next-token;              !!!next-token;
5135              redo B;              redo B;
5136            } else {            } else {
5137                !!!cp ('t308');
5138              $self->{insertion_mode} = AFTER_HTML_BODY_IM;              $self->{insertion_mode} = AFTER_HTML_BODY_IM;
5139              !!!next-token;              !!!next-token;
5140              redo B;              redo B;
5141            }            }
5142          } else {          } else {
5143              !!!cp ('t309');
5144            !!!parse-error (type => 'after body:/'.$token->{tag_name});            !!!parse-error (type => 'after body:/'.$token->{tag_name});
5145    
5146            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
# Line 4487  sub _tree_construction_main ($) { Line 5156  sub _tree_construction_main ($) {
5156            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
5157                        
5158            unless (length $token->{data}) {            unless (length $token->{data}) {
5159                !!!cp ('t310');
5160              !!!next-token;              !!!next-token;
5161              redo B;              redo B;
5162            }            }
# Line 4494  sub _tree_construction_main ($) { Line 5164  sub _tree_construction_main ($) {
5164                    
5165          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
5166            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
5167                !!!cp ('t311');
5168              !!!parse-error (type => 'in frameset:#character');              !!!parse-error (type => 'in frameset:#character');
5169            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
5170                !!!cp ('t312');
5171              !!!parse-error (type => 'after frameset:#character');              !!!parse-error (type => 'after frameset:#character');
5172            } else { # "after html frameset"            } else { # "after html frameset"
5173                !!!cp ('t313');
5174              !!!parse-error (type => 'after html:#character');              !!!parse-error (type => 'after html:#character');
5175    
5176              $self->{insertion_mode} = AFTER_FRAMESET_IM;              $self->{insertion_mode} = AFTER_FRAMESET_IM;
# Line 4507  sub _tree_construction_main ($) { Line 5180  sub _tree_construction_main ($) {
5180                        
5181            ## Ignore the token.            ## Ignore the token.
5182            if (length $token->{data}) {            if (length $token->{data}) {
5183                !!!cp ('t314');
5184              ## reprocess the rest of characters              ## reprocess the rest of characters
5185            } else {            } else {
5186                !!!cp ('t315');
5187              !!!next-token;              !!!next-token;
5188            }            }
5189            redo B;            redo B;
# Line 4517  sub _tree_construction_main ($) { Line 5192  sub _tree_construction_main ($) {
5192          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
5193        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5194          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
5195              !!!cp ('t316');
5196            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
5197    
5198            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
5199            ## Process in the "main" phase, "after frameset" insertion mode...            ## Process in the "main" phase, "after frameset" insertion mode...
5200          }          } else {
5201              !!!cp ('t317');
5202            }
5203    
5204          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
5205              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
5206              !!!cp ('t318');
5207            !!!insert-element ($token->{tag_name}, $token->{attributes});            !!!insert-element ($token->{tag_name}, $token->{attributes});
5208            !!!next-token;            !!!next-token;
5209            redo B;            redo B;
5210          } elsif ($token->{tag_name} eq 'frame' and          } elsif ($token->{tag_name} eq 'frame' and
5211                   $self->{insertion_mode} == IN_FRAMESET_IM) {                   $self->{insertion_mode} == IN_FRAMESET_IM) {
5212              !!!cp ('t319');
5213            !!!insert-element ($token->{tag_name}, $token->{attributes});            !!!insert-element ($token->{tag_name}, $token->{attributes});
5214            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
5215            !!!next-token;            !!!next-token;
5216            redo B;            redo B;
5217          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
5218              !!!cp ('t320');
5219            ## NOTE: As if in body.            ## NOTE: As if in body.
5220            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);
5221            redo B;            redo B;
5222          } else {          } else {
5223            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
5224                !!!cp ('t321');
5225              !!!parse-error (type => 'in frameset:'.$token->{tag_name});              !!!parse-error (type => 'in frameset:'.$token->{tag_name});
5226            } else {            } else {
5227                !!!cp ('t322');
5228              !!!parse-error (type => 'after frameset:'.$token->{tag_name});              !!!parse-error (type => 'after frameset:'.$token->{tag_name});
5229            }            }
5230            ## Ignore the token            ## Ignore the token
# Line 4550  sub _tree_construction_main ($) { Line 5233  sub _tree_construction_main ($) {
5233          }          }
5234        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
5235          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
5236              !!!cp ('t323');
5237            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
5238    
5239            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
5240            ## Process in the "main" phase, "after frameset" insertion mode...            ## Process in the "main" phase, "after frameset" insertion mode...
5241            } else {
5242              !!!cp ('t324');
5243          }          }
5244    
5245          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
5246              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
5247            if ($self->{open_elements}->[-1]->[1] eq 'html' and            if ($self->{open_elements}->[-1]->[1] eq 'html' and
5248                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
5249                !!!cp ('t325');
5250              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5251              ## Ignore the token              ## Ignore the token
5252              !!!next-token;              !!!next-token;
5253            } else {            } else {
5254                !!!cp ('t326');
5255              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
5256              !!!next-token;              !!!next-token;
5257            }            }
5258    
5259            if (not defined $self->{inner_html_node} and            if (not defined $self->{inner_html_node} and
5260                $self->{open_elements}->[-1]->[1] ne 'frameset') {                $self->{open_elements}->[-1]->[1] ne 'frameset') {
5261                !!!cp ('t327');
5262              $self->{insertion_mode} = AFTER_FRAMESET_IM;              $self->{insertion_mode} = AFTER_FRAMESET_IM;
5263              } else {
5264                !!!cp ('t328');
5265            }            }
5266            redo B;            redo B;
5267          } elsif ($token->{tag_name} eq 'html' and          } elsif ($token->{tag_name} eq 'html' and
5268                   $self->{insertion_mode} == AFTER_FRAMESET_IM) {                   $self->{insertion_mode} == AFTER_FRAMESET_IM) {
5269              !!!cp ('t329');
5270            $self->{insertion_mode} = AFTER_HTML_FRAMESET_IM;            $self->{insertion_mode} = AFTER_HTML_FRAMESET_IM;
5271            !!!next-token;            !!!next-token;
5272            redo B;            redo B;
5273          } else {          } else {
5274            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
5275                !!!cp ('t330');
5276              !!!parse-error (type => 'in frameset:/'.$token->{tag_name});              !!!parse-error (type => 'in frameset:/'.$token->{tag_name});
5277            } else {            } else {
5278                !!!cp ('t331');
5279              !!!parse-error (type => 'after frameset:/'.$token->{tag_name});              !!!parse-error (type => 'after frameset:/'.$token->{tag_name});
5280            }            }
5281            ## Ignore the token            ## Ignore the token
# Line 4600  sub _tree_construction_main ($) { Line 5294  sub _tree_construction_main ($) {
5294      ## "in body" insertion mode      ## "in body" insertion mode
5295      if ($token->{type} == START_TAG_TOKEN) {      if ($token->{type} == START_TAG_TOKEN) {
5296        if ($token->{tag_name} eq 'script') {        if ($token->{tag_name} eq 'script') {
5297            !!!cp ('t332');
5298          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5299          $script_start_tag->($insert);          $script_start_tag->($insert);
5300          redo B;          redo B;
5301        } elsif ($token->{tag_name} eq 'style') {        } elsif ($token->{tag_name} eq 'style') {
5302            !!!cp ('t333');
5303          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5304          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
5305          redo B;          redo B;
5306        } elsif ({        } elsif ({
5307                  base => 1, link => 1,                  base => 1, link => 1,
5308                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5309            !!!cp ('t334');
5310          ## NOTE: This is an "as if in head" code clone, only "-t" differs          ## NOTE: This is an "as if in head" code clone, only "-t" differs
5311          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5312          pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.          pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
# Line 4622  sub _tree_construction_main ($) { Line 5319  sub _tree_construction_main ($) {
5319    
5320          unless ($self->{confident}) {          unless ($self->{confident}) {
5321            if ($token->{attributes}->{charset}) { ## TODO: And if supported            if ($token->{attributes}->{charset}) { ## TODO: And if supported
5322                !!!cp ('t335');
5323              $self->{change_encoding}              $self->{change_encoding}
5324                  ->($self, $token->{attributes}->{charset}->{value});                  ->($self, $token->{attributes}->{charset}->{value});
5325                            
# Line 4636  sub _tree_construction_main ($) { Line 5334  sub _tree_construction_main ($) {
5334                      [\x09-\x0D\x20]*=                      [\x09-\x0D\x20]*=
5335                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
5336                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
5337                  !!!cp ('t336');
5338                $self->{change_encoding}                $self->{change_encoding}
5339                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);
5340                $meta_el->[0]->get_attribute_node_ns (undef, 'content')                $meta_el->[0]->get_attribute_node_ns (undef, 'content')
# Line 4646  sub _tree_construction_main ($) { Line 5345  sub _tree_construction_main ($) {
5345            }            }
5346          } else {          } else {
5347            if ($token->{attributes}->{charset}) {            if ($token->{attributes}->{charset}) {
5348                !!!cp ('t337');
5349              $meta_el->[0]->get_attribute_node_ns (undef, 'charset')              $meta_el->[0]->get_attribute_node_ns (undef, 'charset')
5350                  ->set_user_data (manakai_has_reference =>                  ->set_user_data (manakai_has_reference =>
5351                                       $token->{attributes}->{charset}                                       $token->{attributes}->{charset}
5352                                           ->{has_reference});                                           ->{has_reference});
5353            }            }
5354            if ($token->{attributes}->{content}) {            if ($token->{attributes}->{content}) {
5355                !!!cp ('t338');
5356              $meta_el->[0]->get_attribute_node_ns (undef, 'content')              $meta_el->[0]->get_attribute_node_ns (undef, 'content')
5357                  ->set_user_data (manakai_has_reference =>                  ->set_user_data (manakai_has_reference =>
5358                                       $token->{attributes}->{content}                                       $token->{attributes}->{content}
# Line 4662  sub _tree_construction_main ($) { Line 5363  sub _tree_construction_main ($) {
5363          !!!next-token;          !!!next-token;
5364          redo B;          redo B;
5365        } elsif ($token->{tag_name} eq 'title') {        } elsif ($token->{tag_name} eq 'title') {
5366            !!!cp ('t341');
5367          !!!parse-error (type => 'in body:title');          !!!parse-error (type => 'in body:title');
5368          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5369          $parse_rcdata->(RCDATA_CONTENT_MODEL, sub {          $parse_rcdata->(RCDATA_CONTENT_MODEL, sub {
5370            if (defined $self->{head_element}) {            if (defined $self->{head_element}) {
5371                !!!cp ('t339');
5372              $self->{head_element}->append_child ($_[0]);              $self->{head_element}->append_child ($_[0]);
5373            } else {            } else {
5374                !!!cp ('t340');
5375              $insert->($_[0]);              $insert->($_[0]);
5376            }            }
5377          });          });
# Line 4677  sub _tree_construction_main ($) { Line 5381  sub _tree_construction_main ($) {
5381                                
5382          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
5383              $self->{open_elements}->[1]->[1] ne 'body') {              $self->{open_elements}->[1]->[1] ne 'body') {
5384              !!!cp ('t342');
5385            ## Ignore the token            ## Ignore the token
5386          } else {          } else {
5387            my $body_el = $self->{open_elements}->[1]->[0];            my $body_el = $self->{open_elements}->[1]->[0];
5388            for my $attr_name (keys %{$token->{attributes}}) {            for my $attr_name (keys %{$token->{attributes}}) {
5389              unless ($body_el->has_attribute_ns (undef, $attr_name)) {              unless ($body_el->has_attribute_ns (undef, $attr_name)) {
5390                  !!!cp ('t343');
5391                $body_el->set_attribute_ns                $body_el->set_attribute_ns
5392                  (undef, [undef, $attr_name],                  (undef, [undef, $attr_name],
5393                   $token->{attributes}->{$attr_name}->{value});                   $token->{attributes}->{$attr_name}->{value});
# Line 4699  sub _tree_construction_main ($) { Line 5405  sub _tree_construction_main ($) {
5405          ## has a p element in scope          ## has a p element in scope
5406          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5407            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5408                !!!cp ('t344');
5409              !!!back-token;              !!!back-token;
5410              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5411              redo B;              redo B;
# Line 4706  sub _tree_construction_main ($) { Line 5413  sub _tree_construction_main ($) {
5413                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5414                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5415                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5416                !!!cp ('t345');
5417              last INSCOPE;              last INSCOPE;
5418            }            }
5419          } # INSCOPE          } # INSCOPE
# Line 4716  sub _tree_construction_main ($) { Line 5424  sub _tree_construction_main ($) {
5424            if ($token->{type} == CHARACTER_TOKEN) {            if ($token->{type} == CHARACTER_TOKEN) {
5425              $token->{data} =~ s/^\x0A//;              $token->{data} =~ s/^\x0A//;
5426              unless (length $token->{data}) {              unless (length $token->{data}) {
5427                  !!!cp ('t346');
5428                !!!next-token;                !!!next-token;
5429                } else {
5430                  !!!cp ('t349');
5431              }              }
5432              } else {
5433                !!!cp ('t348');
5434            }            }
5435          } else {          } else {
5436              !!!cp ('t347');
5437            !!!next-token;            !!!next-token;
5438          }          }
5439          redo B;          redo B;
5440        } elsif ($token->{tag_name} eq 'form') {        } elsif ($token->{tag_name} eq 'form') {
5441          if (defined $self->{form_element}) {          if (defined $self->{form_element}) {
5442              !!!cp ('t350');
5443            !!!parse-error (type => 'in form:form');            !!!parse-error (type => 'in form:form');
5444            ## Ignore the token            ## Ignore the token
5445            !!!next-token;            !!!next-token;
# Line 4733  sub _tree_construction_main ($) { Line 5448  sub _tree_construction_main ($) {
5448            ## has a p element in scope            ## has a p element in scope
5449            INSCOPE: for (reverse @{$self->{open_elements}}) {            INSCOPE: for (reverse @{$self->{open_elements}}) {
5450              if ($_->[1] eq 'p') {              if ($_->[1] eq 'p') {
5451                  !!!cp ('t351');
5452                !!!back-token;                !!!back-token;
5453                $token = {type => END_TAG_TOKEN, tag_name => 'p'};                $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5454                redo B;                redo B;
# Line 4740  sub _tree_construction_main ($) { Line 5456  sub _tree_construction_main ($) {
5456                        table => 1, caption => 1, td => 1, th => 1,                        table => 1, caption => 1, td => 1, th => 1,
5457                        button => 1, marquee => 1, object => 1, html => 1,                        button => 1, marquee => 1, object => 1, html => 1,
5458                       }->{$_->[1]}) {                       }->{$_->[1]}) {
5459                  !!!cp ('t352');
5460                last INSCOPE;                last INSCOPE;
5461              }              }
5462            } # INSCOPE            } # INSCOPE
# Line 4753  sub _tree_construction_main ($) { Line 5470  sub _tree_construction_main ($) {
5470          ## has a p element in scope          ## has a p element in scope
5471          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5472            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5473                !!!cp ('t353');
5474              !!!back-token;              !!!back-token;
5475              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5476              redo B;              redo B;
# Line 4760  sub _tree_construction_main ($) { Line 5478  sub _tree_construction_main ($) {
5478                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5479                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5480                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5481                !!!cp ('t354');
5482              last INSCOPE;              last INSCOPE;
5483            }            }
5484          } # INSCOPE          } # INSCOPE
# Line 4771  sub _tree_construction_main ($) { Line 5490  sub _tree_construction_main ($) {
5490            ## Step 2            ## Step 2
5491            if ($node->[1] eq 'li') {            if ($node->[1] eq 'li') {
5492              if ($i != -1) {              if ($i != -1) {
5493                  !!!cp ('t355');
5494                !!!parse-error (type => 'end tag missing:'.                !!!parse-error (type => 'end tag missing:'.
5495                                $self->{open_elements}->[-1]->[1]);                                $self->{open_elements}->[-1]->[1]);
5496                } else {
5497                  !!!cp ('t356');
5498              }              }
5499              splice @{$self->{open_elements}}, $i;              splice @{$self->{open_elements}}, $i;
5500              last LI;              last LI;
5501              } else {
5502                !!!cp ('t357');
5503            }            }
5504                        
5505            ## Step 3            ## Step 3
# Line 4784  sub _tree_construction_main ($) { Line 5508  sub _tree_construction_main ($) {
5508                ($special_category->{$node->[1]} or                ($special_category->{$node->[1]} or
5509                 $scoping_category->{$node->[1]}) and                 $scoping_category->{$node->[1]}) and
5510                $node->[1] ne 'address' and $node->[1] ne 'div') {                $node->[1] ne 'address' and $node->[1] ne 'div') {
5511                !!!cp ('t358');
5512              last LI;              last LI;
5513            }            }
5514                        
5515              !!!cp ('t359');
5516            ## Step 4            ## Step 4
5517            $i--;            $i--;
5518            $node = $self->{open_elements}->[$i];            $node = $self->{open_elements}->[$i];
# Line 4800  sub _tree_construction_main ($) { Line 5526  sub _tree_construction_main ($) {
5526          ## has a p element in scope          ## has a p element in scope
5527          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5528            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5529                !!!cp ('t360');
5530              !!!back-token;              !!!back-token;
5531              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5532              redo B;              redo B;
# Line 4807  sub _tree_construction_main ($) { Line 5534  sub _tree_construction_main ($) {
5534                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5535                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5536                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5537                !!!cp ('t361');
5538              last INSCOPE;              last INSCOPE;
5539            }            }
5540          } # INSCOPE          } # INSCOPE
# Line 4818  sub _tree_construction_main ($) { Line 5546  sub _tree_construction_main ($) {
5546            ## Step 2            ## Step 2
5547            if ($node->[1] eq 'dt' or $node->[1] eq 'dd') {            if ($node->[1] eq 'dt' or $node->[1] eq 'dd') {
5548              if ($i != -1) {              if ($i != -1) {
5549                  !!!cp ('t362');
5550                !!!parse-error (type => 'end tag missing:'.                !!!parse-error (type => 'end tag missing:'.
5551                                $self->{open_elements}->[-1]->[1]);                                $self->{open_elements}->[-1]->[1]);
5552                } else {
5553                  !!!cp ('t363');
5554              }              }
5555              splice @{$self->{open_elements}}, $i;              splice @{$self->{open_elements}}, $i;
5556              last LI;              last LI;
5557              } else {
5558                !!!cp ('t364');
5559            }            }
5560                        
5561            ## Step 3            ## Step 3
# Line 4831  sub _tree_construction_main ($) { Line 5564  sub _tree_construction_main ($) {
5564                ($special_category->{$node->[1]} or                ($special_category->{$node->[1]} or
5565                 $scoping_category->{$node->[1]}) and                 $scoping_category->{$node->[1]}) and
5566                $node->[1] ne 'address' and $node->[1] ne 'div') {                $node->[1] ne 'address' and $node->[1] ne 'div') {
5567                !!!cp ('t365');
5568              last LI;              last LI;
5569            }            }
5570                        
5571              !!!cp ('t366');
5572            ## Step 4            ## Step 4
5573            $i--;            $i--;
5574            $node = $self->{open_elements}->[$i];            $node = $self->{open_elements}->[$i];
# Line 4847  sub _tree_construction_main ($) { Line 5582  sub _tree_construction_main ($) {
5582          ## has a p element in scope          ## has a p element in scope
5583          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5584            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5585                !!!cp ('t367');
5586              !!!back-token;              !!!back-token;
5587              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5588              redo B;              redo B;
# Line 4854  sub _tree_construction_main ($) { Line 5590  sub _tree_construction_main ($) {
5590                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5591                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5592                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5593                !!!cp ('t368');
5594              last INSCOPE;              last INSCOPE;
5595            }            }
5596          } # INSCOPE          } # INSCOPE
# Line 4871  sub _tree_construction_main ($) { Line 5608  sub _tree_construction_main ($) {
5608          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5609            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
5610            if ($node->[1] eq 'p') {            if ($node->[1] eq 'p') {
5611                !!!cp ('t369');
5612              !!!back-token;              !!!back-token;
5613              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5614              redo B;              redo B;
# Line 4878  sub _tree_construction_main ($) { Line 5616  sub _tree_construction_main ($) {
5616                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5617                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5618                     }->{$node->[1]}) {                     }->{$node->[1]}) {
5619                !!!cp ('t370');
5620              last INSCOPE;              last INSCOPE;
5621            }            }
5622          } # INSCOPE          } # INSCOPE
# Line 4913  sub _tree_construction_main ($) { Line 5652  sub _tree_construction_main ($) {
5652          AFE: for my $i (reverse 0..$#$active_formatting_elements) {          AFE: for my $i (reverse 0..$#$active_formatting_elements) {
5653            my $node = $active_formatting_elements->[$i];            my $node = $active_formatting_elements->[$i];
5654            if ($node->[1] eq 'a') {            if ($node->[1] eq 'a') {
5655                !!!cp ('t371');
5656              !!!parse-error (type => 'in a:a');              !!!parse-error (type => 'in a:a');
5657                            
5658              !!!back-token;              !!!back-token;
# Line 4921  sub _tree_construction_main ($) { Line 5661  sub _tree_construction_main ($) {
5661                            
5662              AFE2: for (reverse 0..$#$active_formatting_elements) {              AFE2: for (reverse 0..$#$active_formatting_elements) {
5663                if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {                if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {
5664                    !!!cp ('t372');
5665                  splice @$active_formatting_elements, $_, 1;                  splice @$active_formatting_elements, $_, 1;
5666                  last AFE2;                  last AFE2;
5667                }                }
5668              } # AFE2              } # AFE2
5669              OE: for (reverse 0..$#{$self->{open_elements}}) {              OE: for (reverse 0..$#{$self->{open_elements}}) {
5670                if ($self->{open_elements}->[$_]->[0] eq $node->[0]) {                if ($self->{open_elements}->[$_]->[0] eq $node->[0]) {
5671                    !!!cp ('t373');
5672                  splice @{$self->{open_elements}}, $_, 1;                  splice @{$self->{open_elements}}, $_, 1;
5673                  last OE;                  last OE;
5674                }                }
5675              } # OE              } # OE
5676              last AFE;              last AFE;
5677            } elsif ($node->[0] eq '#marker') {            } elsif ($node->[0] eq '#marker') {
5678                !!!cp ('t374');
5679              last AFE;              last AFE;
5680            }            }
5681          } # AFE          } # AFE
# Line 4949  sub _tree_construction_main ($) { Line 5692  sub _tree_construction_main ($) {
5692                  s => 1, small => 1, strile => 1,                  s => 1, small => 1, strile => 1,
5693                  strong => 1, tt => 1, u => 1,                  strong => 1, tt => 1, u => 1,
5694                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5695            !!!cp ('t375');
5696          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5697                    
5698          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 4963  sub _tree_construction_main ($) { Line 5707  sub _tree_construction_main ($) {
5707          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5708            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
5709            if ($node->[1] eq 'nobr') {            if ($node->[1] eq 'nobr') {
5710                !!!cp ('t376');
5711              !!!parse-error (type => 'in nobr:nobr');              !!!parse-error (type => 'in nobr:nobr');
5712              !!!back-token;              !!!back-token;
5713              $token = {type => END_TAG_TOKEN, tag_name => 'nobr'};              $token = {type => END_TAG_TOKEN, tag_name => 'nobr'};
# Line 4971  sub _tree_construction_main ($) { Line 5716  sub _tree_construction_main ($) {
5716                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5717                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5718                     }->{$node->[1]}) {                     }->{$node->[1]}) {
5719                !!!cp ('t377');
5720              last INSCOPE;              last INSCOPE;
5721            }            }
5722          } # INSCOPE          } # INSCOPE
# Line 4985  sub _tree_construction_main ($) { Line 5731  sub _tree_construction_main ($) {
5731          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5732            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
5733            if ($node->[1] eq 'button') {            if ($node->[1] eq 'button') {
5734                !!!cp ('t378');
5735              !!!parse-error (type => 'in button:button');              !!!parse-error (type => 'in button:button');
5736              !!!back-token;              !!!back-token;
5737              $token = {type => END_TAG_TOKEN, tag_name => 'button'};              $token = {type => END_TAG_TOKEN, tag_name => 'button'};
# Line 4993  sub _tree_construction_main ($) { Line 5740  sub _tree_construction_main ($) {
5740                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5741                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5742                     }->{$node->[1]}) {                     }->{$node->[1]}) {
5743                !!!cp ('t379');
5744              last INSCOPE;              last INSCOPE;
5745            }            }
5746          } # INSCOPE          } # INSCOPE
# Line 5006  sub _tree_construction_main ($) { Line 5754  sub _tree_construction_main ($) {
5754          redo B;          redo B;
5755        } elsif ($token->{tag_name} eq 'marquee' or        } elsif ($token->{tag_name} eq 'marquee' or
5756                 $token->{tag_name} eq 'object') {                 $token->{tag_name} eq 'object') {
5757            !!!cp ('t380');
5758          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5759                    
5760          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 5014  sub _tree_construction_main ($) { Line 5763  sub _tree_construction_main ($) {
5763          !!!next-token;          !!!next-token;
5764          redo B;          redo B;
5765        } elsif ($token->{tag_name} eq 'xmp') {        } elsif ($token->{tag_name} eq 'xmp') {
5766            !!!cp ('t381');
5767          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5768          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
5769          redo B;          redo B;
# Line 5021  sub _tree_construction_main ($) { Line 5771  sub _tree_construction_main ($) {
5771          ## has a p element in scope          ## has a p element in scope
5772          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5773            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5774                !!!cp ('t382');
5775              !!!back-token;              !!!back-token;
5776              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5777              redo B;              redo B;
# Line 5028  sub _tree_construction_main ($) { Line 5779  sub _tree_construction_main ($) {
5779                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5780                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5781                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5782                !!!cp ('t383');
5783              last INSCOPE;              last INSCOPE;
5784            }            }
5785          } # INSCOPE          } # INSCOPE
# Line 5044  sub _tree_construction_main ($) { Line 5796  sub _tree_construction_main ($) {
5796                  image => 1,                  image => 1,
5797                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5798          if ($token->{tag_name} eq 'image') {          if ($token->{tag_name} eq 'image') {
5799              !!!cp ('t384');
5800            !!!parse-error (type => 'image');            !!!parse-error (type => 'image');
5801            $token->{tag_name} = 'img';            $token->{tag_name} = 'img';
5802            } else {
5803              !!!cp ('t385');
5804          }          }
5805    
5806          ## NOTE: There is an "as if <br>" code clone.          ## NOTE: There is an "as if <br>" code clone.
# Line 5060  sub _tree_construction_main ($) { Line 5815  sub _tree_construction_main ($) {
5815          ## has a p element in scope          ## has a p element in scope
5816          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5817            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5818                !!!cp ('t386');
5819              !!!back-token;              !!!back-token;
5820              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5821              redo B;              redo B;
# Line 5067  sub _tree_construction_main ($) { Line 5823  sub _tree_construction_main ($) {
5823                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5824                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5825                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5826                !!!cp ('t387');
5827              last INSCOPE;              last INSCOPE;
5828            }            }
5829          } # INSCOPE          } # INSCOPE
# Line 5077  sub _tree_construction_main ($) { Line 5834  sub _tree_construction_main ($) {
5834          !!!next-token;          !!!next-token;
5835          redo B;          redo B;
5836        } elsif ($token->{tag_name} eq 'input') {        } elsif ($token->{tag_name} eq 'input') {
5837            !!!cp ('t388');
5838          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5839                    
5840          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 5089  sub _tree_construction_main ($) { Line 5847  sub _tree_construction_main ($) {
5847          !!!parse-error (type => 'isindex');          !!!parse-error (type => 'isindex');
5848                    
5849          if (defined $self->{form_element}) {          if (defined $self->{form_element}) {
5850              !!!cp ('t389');
5851            ## Ignore the token            ## Ignore the token
5852            !!!next-token;            !!!next-token;
5853            redo B;            redo B;
# Line 5108  sub _tree_construction_main ($) { Line 5867  sub _tree_construction_main ($) {
5867                          {type => START_TAG_TOKEN, tag_name => 'label'},                          {type => START_TAG_TOKEN, tag_name => 'label'},
5868                         );                         );
5869            if ($prompt_attr) {            if ($prompt_attr) {
5870                !!!cp ('t390');
5871              push @tokens, {type => CHARACTER_TOKEN, data => $prompt_attr->{value}};              push @tokens, {type => CHARACTER_TOKEN, data => $prompt_attr->{value}};
5872            } else {            } else {
5873                !!!cp ('t391');
5874              push @tokens, {type => CHARACTER_TOKEN,              push @tokens, {type => CHARACTER_TOKEN,
5875                             data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD                             data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD
5876              ## TODO: make this configurable              ## TODO: make this configurable
# Line 5141  sub _tree_construction_main ($) { Line 5902  sub _tree_construction_main ($) {
5902          if ($token->{type} == CHARACTER_TOKEN) {          if ($token->{type} == CHARACTER_TOKEN) {
5903            $token->{data} =~ s/^\x0A//;            $token->{data} =~ s/^\x0A//;
5904            unless (length $token->{data}) {            unless (length $token->{data}) {
5905                !!!cp ('t392');
5906              !!!next-token;              !!!next-token;
5907              } else {
5908                !!!cp ('t393');
5909            }            }
5910            } else {
5911              !!!cp ('t394');
5912          }          }
5913          while ($token->{type} == CHARACTER_TOKEN) {          while ($token->{type} == CHARACTER_TOKEN) {
5914              !!!cp ('t395');
5915            $text .= $token->{data};            $text .= $token->{data};
5916            !!!next-token;            !!!next-token;
5917          }          }
5918          if (length $text) {          if (length $text) {
5919              !!!cp ('t396');
5920            $el->manakai_append_text ($text);            $el->manakai_append_text ($text);
5921          }          }
5922                    
# Line 5156  sub _tree_construction_main ($) { Line 5924  sub _tree_construction_main ($) {
5924                    
5925          if ($token->{type} == END_TAG_TOKEN and          if ($token->{type} == END_TAG_TOKEN and
5926              $token->{tag_name} eq $tag_name) {              $token->{tag_name} eq $tag_name) {
5927              !!!cp ('t397');
5928            ## Ignore the token            ## Ignore the token
5929          } else {          } else {
5930              !!!cp ('t398');
5931            !!!parse-error (type => 'in RCDATA:#'.$token->{type});            !!!parse-error (type => 'in RCDATA:#'.$token->{type});
5932          }          }
5933          !!!next-token;          !!!next-token;
# Line 5168  sub _tree_construction_main ($) { Line 5938  sub _tree_construction_main ($) {
5938                  noframes => 1,                  noframes => 1,
5939                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
5940                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5941            !!!cp ('t399');
5942          ## NOTE: There is an "as if in body" code clone.          ## NOTE: There is an "as if in body" code clone.
5943          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
5944          redo B;          redo B;
5945        } elsif ($token->{tag_name} eq 'select') {        } elsif ($token->{tag_name} eq 'select') {
5946            !!!cp ('t400');
5947          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5948                    
5949          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 5185  sub _tree_construction_main ($) { Line 5957  sub _tree_construction_main ($) {
5957                  tbody => 1, td => 1, tfoot => 1, th => 1,                  tbody => 1, td => 1, tfoot => 1, th => 1,
5958                  thead => 1, tr => 1,                  thead => 1, tr => 1,
5959                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5960            !!!cp ('t401');
5961          !!!parse-error (type => 'in body:'.$token->{tag_name});          !!!parse-error (type => 'in body:'.$token->{tag_name});
5962          ## Ignore the token          ## Ignore the token
5963          !!!next-token;          !!!next-token;
# Line 5192  sub _tree_construction_main ($) { Line 5965  sub _tree_construction_main ($) {
5965                    
5966          ## ISSUE: An issue on HTML5 new elements in the spec.          ## ISSUE: An issue on HTML5 new elements in the spec.
5967        } else {        } else {
5968            !!!cp ('t402');
5969          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5970                    
5971          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 5209  sub _tree_construction_main ($) { Line 5983  sub _tree_construction_main ($) {
5983                         th => 1, tr => 1, body => 1, html => 1,                         th => 1, tr => 1, body => 1, html => 1,
5984                       tbody => 1, tfoot => 1, thead => 1,                       tbody => 1, tfoot => 1, thead => 1,
5985                      }->{$_->[1]}) {                      }->{$_->[1]}) {
5986                  !!!cp ('t403');
5987                !!!parse-error (type => 'not closed:'.$_->[1]);                !!!parse-error (type => 'not closed:'.$_->[1]);
5988                } else {
5989                  !!!cp ('t404');
5990              }              }
5991            }            }
5992    
# Line 5217  sub _tree_construction_main ($) { Line 5994  sub _tree_construction_main ($) {
5994            !!!next-token;            !!!next-token;
5995            redo B;            redo B;
5996          } else {          } else {
5997              !!!cp ('t405');
5998            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5999            ## Ignore the token            ## Ignore the token
6000            !!!next-token;            !!!next-token;
# Line 5226  sub _tree_construction_main ($) { Line 6004  sub _tree_construction_main ($) {
6004          if (@{$self->{open_elements}} > 1 and $self->{open_elements}->[1]->[1] eq 'body') {          if (@{$self->{open_elements}} > 1 and $self->{open_elements}->[1]->[1] eq 'body') {
6005            ## ISSUE: There is an issue in the spec.            ## ISSUE: There is an issue in the spec.
6006            if ($self->{open_elements}->[-1]->[1] ne 'body') {            if ($self->{open_elements}->[-1]->[1] ne 'body') {
6007                !!!cp ('t406');
6008              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[1]->[1]);              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[1]->[1]);
6009              } else {
6010                !!!cp ('t407');
6011            }            }
6012            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6013            ## reprocess            ## reprocess
6014            redo B;            redo B;
6015          } else {          } else {
6016              !!!cp ('t408');
6017            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6018            ## Ignore the token            ## Ignore the token
6019            !!!next-token;            !!!next-token;
# Line 5259  sub _tree_construction_main ($) { Line 6041  sub _tree_construction_main ($) {
6041                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
6042                   tbody => 1, tfoot=> 1, thead => 1,                   tbody => 1, tfoot=> 1, thead => 1,
6043                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
6044                  !!!cp ('t409');
6045                !!!back-token;                !!!back-token;
6046                $token = {type => END_TAG_TOKEN,                $token = {type => END_TAG_TOKEN,
6047                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
6048                redo B;                redo B;
6049              }              }
6050                
6051                !!!cp ('t410');
6052              $i = $_;              $i = $_;
6053              last INSCOPE unless $token->{tag_name} eq 'p';              last INSCOPE unless $token->{tag_name} eq 'p';
6054            } elsif ({            } elsif ({
6055                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
6056                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6057                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6058                !!!cp ('t411');
6059              last INSCOPE;              last INSCOPE;
6060            }            }
6061          } # INSCOPE          } # INSCOPE
6062                    
6063          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6064            if (defined $i) {            if (defined $i) {
6065                !!!cp ('t412');
6066              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6067            } else {            } else {
6068                !!!cp ('t413');
6069              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6070            }            }
6071          }          }
6072                    
6073          if (defined $i) {          if (defined $i) {
6074              !!!cp ('t414');
6075            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
6076          } elsif ($token->{tag_name} eq 'p') {          } elsif ($token->{tag_name} eq 'p') {
6077              !!!cp ('t415');
6078            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
6079            my $el;            my $el;
6080            !!!create-element ($el, 'p');            !!!create-element ($el, 'p');
6081            $insert->($el);            $insert->($el);
6082            } else {
6083              !!!cp ('t416');
6084          }          }
6085          $clear_up_to_marker->()          $clear_up_to_marker->()
6086            if {            if {
# Line 5307  sub _tree_construction_main ($) { Line 6099  sub _tree_construction_main ($) {
6099                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
6100                   tbody => 1, tfoot=> 1, thead => 1,                   tbody => 1, tfoot=> 1, thead => 1,
6101                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
6102                  !!!cp ('t417');
6103                !!!back-token;                !!!back-token;
6104                $token = {type => END_TAG_TOKEN,                $token = {type => END_TAG_TOKEN,
6105                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
6106                redo B;                redo B;
6107              }              }
6108                
6109                !!!cp ('t418');
6110              last INSCOPE;              last INSCOPE;
6111            } elsif ({            } elsif ({
6112                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
6113                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6114                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6115                !!!cp ('t419');
6116              last INSCOPE;              last INSCOPE;
6117            }            }
6118          } # INSCOPE          } # INSCOPE
6119                    
6120          if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) {          if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) {
6121              !!!cp ('t420');
6122            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
6123          } else {          } else {
6124              !!!cp ('t421');
6125            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6126          }          }
6127    
# Line 5346  sub _tree_construction_main ($) { Line 6144  sub _tree_construction_main ($) {
6144                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
6145                   tbody => 1, tfoot=> 1, thead => 1,                   tbody => 1, tfoot=> 1, thead => 1,
6146                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
6147                  !!!cp ('t422');
6148                !!!back-token;                !!!back-token;
6149                $token = {type => END_TAG_TOKEN,                $token = {type => END_TAG_TOKEN,
6150                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
6151                redo B;                redo B;
6152              }              }
6153    
6154                !!!cp ('t423');
6155              $i = $_;              $i = $_;
6156              last INSCOPE;              last INSCOPE;
6157            } elsif ({            } elsif ({
6158                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
6159                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6160                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6161                !!!cp ('t424');
6162              last INSCOPE;              last INSCOPE;
6163            }            }
6164          } # INSCOPE          } # INSCOPE
6165                    
6166          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6167              !!!cp ('t425');
6168            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6169            } else {
6170              !!!cp ('t426');
6171          }          }
6172                    
6173          splice @{$self->{open_elements}}, $i if defined $i;          splice @{$self->{open_elements}}, $i if defined $i;
# Line 5374  sub _tree_construction_main ($) { Line 6179  sub _tree_construction_main ($) {
6179                  nobr => 1, s => 1, small => 1, strile => 1,                  nobr => 1, s => 1, small => 1, strile => 1,
6180                  strong => 1, tt => 1, u => 1,                  strong => 1, tt => 1, u => 1,
6181                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6182            !!!cp ('t427');
6183          $formatting_end_tag->($token->{tag_name});          $formatting_end_tag->($token->{tag_name});
6184          redo B;          redo B;
6185        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
6186            !!!cp ('t428');
6187          !!!parse-error (type => 'unmatched end tag:br');          !!!parse-error (type => 'unmatched end tag:br');
6188    
6189          ## As if <br>          ## As if <br>
# Line 5401  sub _tree_construction_main ($) { Line 6208  sub _tree_construction_main ($) {
6208                  table => 1, textarea => 1, wbr => 1,                  table => 1, textarea => 1, wbr => 1,
6209                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
6210                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6211            !!!cp ('t429');
6212          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6213          ## Ignore the token          ## Ignore the token
6214          !!!next-token;          !!!next-token;
# Line 5423  sub _tree_construction_main ($) { Line 6231  sub _tree_construction_main ($) {
6231                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
6232                   tbody => 1, tfoot => 1, thead => 1,                   tbody => 1, tfoot => 1, thead => 1,
6233                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
6234                  !!!cp ('t430');
6235                !!!back-token;                !!!back-token;
6236                $token = {type => END_TAG_TOKEN,                $token = {type => END_TAG_TOKEN,
6237                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
# Line 5431  sub _tree_construction_main ($) { Line 6240  sub _tree_construction_main ($) {
6240                    
6241              ## Step 2              ## Step 2
6242              if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) {              if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) {
6243                  !!!cp ('t431');
6244                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
6245                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6246                } else {
6247                  !!!cp ('t432');
6248              }              }
6249                            
6250              ## Step 3              ## Step 3
# Line 5446  sub _tree_construction_main ($) { Line 6258  sub _tree_construction_main ($) {
6258                  #not $phrasing_category->{$node->[1]} and                  #not $phrasing_category->{$node->[1]} and
6259                  ($special_category->{$node->[1]} or                  ($special_category->{$node->[1]} or
6260                   $scoping_category->{$node->[1]})) {                   $scoping_category->{$node->[1]})) {
6261                  !!!cp ('t433');
6262                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6263                ## Ignore the token                ## Ignore the token
6264                !!!next-token;                !!!next-token;
6265                last S2;                last S2;
6266              }              }
6267    
6268                !!!cp ('t434');
6269            }            }
6270                        
6271            ## Step 4            ## Step 4
# Line 5529  sub set_inner_html ($$$) { Line 6344  sub set_inner_html ($$$) {
6344        if ($self->{next_char} == 0x000A) { # LF        if ($self->{next_char} == 0x000A) { # LF
6345          $line++;          $line++;
6346          $column = 0;          $column = 0;
6347            !!!cp ('i1');
6348        } elsif ($self->{next_char} == 0x000D) { # CR        } elsif ($self->{next_char} == 0x000D) { # CR
6349          $i++ if substr ($$s, $i, 1) eq "\x0A";          $i++ if substr ($$s, $i, 1) eq "\x0A";
6350          $self->{next_char} = 0x000A; # LF # MUST          $self->{next_char} = 0x000A; # LF # MUST
6351          $line++;          $line++;
6352          $column = 0;          $column = 0;
6353            !!!cp ('i2');
6354        } elsif ($self->{next_char} > 0x10FFFF) {        } elsif ($self->{next_char} > 0x10FFFF) {
6355          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
6356            !!!cp ('i3');
6357        } elsif ($self->{next_char} == 0x0000) { # NULL        } elsif ($self->{next_char} == 0x0000) { # NULL
6358            !!!cp ('i4');
6359          !!!parse-error (type => 'NULL');          !!!parse-error (type => 'NULL');
6360          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
6361        }        }
# Line 5597  sub set_inner_html ($$$) { Line 6416  sub set_inner_html ($$$) {
6416          my $nsuri = $anode->namespace_uri;          my $nsuri = $anode->namespace_uri;
6417          if (defined $nsuri and $nsuri eq 'http://www.w3.org/1999/xhtml') {          if (defined $nsuri and $nsuri eq 'http://www.w3.org/1999/xhtml') {
6418            if ($anode->manakai_local_name eq 'form') {            if ($anode->manakai_local_name eq 'form') {
6419                !!!cp ('i5');
6420              $p->{form_element} = $anode;              $p->{form_element} = $anode;
6421              last AN;              last AN;
6422            }            }

Legend:
Removed from v.1.76  
changed lines
  Added in v.1.80

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24