/[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.72 by wakaba, Sun Mar 2 14:32:26 2008 UTC revision 1.83 by wakaba, Wed Mar 5 13:07:02 2008 UTC
# Line 179  sub parse_string ($$$;$) { Line 179  sub parse_string ($$$;$) {
179    my $i = 0;    my $i = 0;
180    my $line = 1;    my $line = 1;
181    my $column = 0;    my $column = 0;
182    $self->{set_next_input_character} = sub {    $self->{set_next_char} = sub {
183      my $self = shift;      my $self = shift;
184    
185      pop @{$self->{prev_input_character}};      pop @{$self->{prev_char}};
186      unshift @{$self->{prev_input_character}}, $self->{next_input_character};      unshift @{$self->{prev_char}}, $self->{next_char};
187    
188      $self->{next_input_character} = -1 and return if $i >= length $$s;      $self->{next_char} = -1 and return if $i >= length $$s;
189      $self->{next_input_character} = ord substr $$s, $i++, 1;      $self->{next_char} = ord substr $$s, $i++, 1;
190      $column++;      $column++;
191            
192      if ($self->{next_input_character} == 0x000A) { # LF      if ($self->{next_char} == 0x000A) { # LF
193        $line++;        $line++;
194        $column = 0;        $column = 0;
195      } elsif ($self->{next_input_character} == 0x000D) { # CR      } elsif ($self->{next_char} == 0x000D) { # CR
196        $i++ if substr ($$s, $i, 1) eq "\x0A";        $i++ if substr ($$s, $i, 1) eq "\x0A";
197        $self->{next_input_character} = 0x000A; # LF # MUST        $self->{next_char} = 0x000A; # LF # MUST
198        $line++;        $line++;
199        $column = 0;        $column = 0;
200      } elsif ($self->{next_input_character} > 0x10FFFF) {      } elsif ($self->{next_char} > 0x10FFFF) {
201        $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
202      } elsif ($self->{next_input_character} == 0x0000) { # NULL      } elsif ($self->{next_char} == 0x0000) { # NULL
203        !!!parse-error (type => 'NULL');        !!!parse-error (type => 'NULL');
204        $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
205      }      }
206    };    };
207    $self->{prev_input_character} = [-1, -1, -1];    $self->{prev_char} = [-1, -1, -1];
208    $self->{next_input_character} = -1;    $self->{next_char} = -1;
209    
210    my $onerror = $_[2] || sub {    my $onerror = $_[2] || sub {
211      my (%opt) = @_;      my (%opt) = @_;
# Line 226  sub parse_string ($$$;$) { Line 226  sub parse_string ($$$;$) {
226  sub new ($) {  sub new ($) {
227    my $class = shift;    my $class = shift;
228    my $self = bless {}, $class;    my $self = bless {}, $class;
229    $self->{set_next_input_character} = sub {    $self->{set_next_char} = sub {
230      $self->{next_input_character} = -1;      $self->{next_char} = -1;
231    };    };
232    $self->{parse_error} = sub {    $self->{parse_error} = sub {
233      #      #
# Line 333  sub _initialize_tokenizer ($) { Line 333  sub _initialize_tokenizer ($) {
333    undef $self->{last_emitted_start_tag_name};    undef $self->{last_emitted_start_tag_name};
334    undef $self->{last_attribute_value_state};    undef $self->{last_attribute_value_state};
335    $self->{char} = [];    $self->{char} = [];
336    # $self->{next_input_character}    # $self->{next_char}
337    !!!next-input-character;    !!!next-input-character;
338    $self->{token} = [];    $self->{token} = [];
339    # $self->{escape}    # $self->{escape}
# Line 346  sub _initialize_tokenizer ($) { Line 346  sub _initialize_tokenizer ($) {
346  ##   ->{tag_name} (START_TAG_TOKEN, END_TAG_TOKEN)  ##   ->{tag_name} (START_TAG_TOKEN, END_TAG_TOKEN)
347  ##   ->{public_identifier} (DOCTYPE_TOKEN)  ##   ->{public_identifier} (DOCTYPE_TOKEN)
348  ##   ->{system_identifier} (DOCTYPE_TOKEN)  ##   ->{system_identifier} (DOCTYPE_TOKEN)
349  ##   ->{correct} == 1 or 0 (DOCTYPE_TOKEN)  ##   ->{quirks} == 1 or 0 (DOCTYPE_TOKEN): "force-quirks" flag
350  ##   ->{attributes} isa HASH (START_TAG_TOKEN, END_TAG_TOKEN)  ##   ->{attributes} isa HASH (START_TAG_TOKEN, END_TAG_TOKEN)
351  ##        ->{name}  ##        ->{name}
352  ##        ->{value}  ##        ->{value}
# Line 384  sub _get_next_token ($) { Line 384  sub _get_next_token ($) {
384    
385    A: {    A: {
386      if ($self->{state} == DATA_STATE) {      if ($self->{state} == DATA_STATE) {
387        if ($self->{next_input_character} == 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_input_character} == 0x002D) { # -        } elsif ($self->{next_char} == 0x002D) { # -
399          if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA          if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
400            unless ($self->{escape}) {            unless ($self->{escape}) {
401              if ($self->{prev_input_character}->[0] == 0x002D and # -              if ($self->{prev_char}->[0] == 0x002D and # -
402                  $self->{prev_input_character}->[1] == 0x0021 and # !                  $self->{prev_char}->[1] == 0x0021 and # !
403                  $self->{prev_input_character}->[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                    
414          #          #
415        } elsif ($self->{next_input_character} == 0x003C) { # <        } elsif ($self->{next_char} == 0x003C) { # <
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_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
428          if ($self->{escape} and          if ($self->{escape} and
429              ($self->{content_model} & CM_LIMITED_MARKUP)) { # RCDATA | CDATA              ($self->{content_model} & CM_LIMITED_MARKUP)) { # RCDATA | CDATA
430            if ($self->{prev_input_character}->[0] == 0x002D and # -            if ($self->{prev_char}->[0] == 0x002D and # -
431                $self->{prev_input_character}->[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_input_character} == -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,
451                     data => chr $self->{next_input_character}};                     data => chr $self->{next_char}};
452        ## Stay in the data state        ## Stay in the data state
453        !!!next-input-character;        !!!next-input-character;
454    
# 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    
474        redo A;        redo A;
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_input_character} == 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 468  sub _get_next_token ($) { Line 489  sub _get_next_token ($) {
489            redo A;            redo A;
490          }          }
491        } elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA        } elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA
492          if ($self->{next_input_character} == 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_input_character} == 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_input_character} and          } elsif (0x0041 <= $self->{next_char} and
503                   $self->{next_input_character} <= 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_input_character} + 0x0020)};                 tag_name => chr ($self->{next_char} + 0x0020)};
508            $self->{state} = TAG_NAME_STATE;            $self->{state} = TAG_NAME_STATE;
509            !!!next-input-character;            !!!next-input-character;
510            redo A;            redo A;
511          } elsif (0x0061 <= $self->{next_input_character} and          } elsif (0x0061 <= $self->{next_char} and
512                   $self->{next_input_character} <= 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_input_character})};                              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_input_character} == 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 499  sub _get_next_token ($) { Line 525  sub _get_next_token ($) {
525            !!!emit ({type => CHARACTER_TOKEN, data => '<>'});            !!!emit ({type => CHARACTER_TOKEN, data => '<>'});
526    
527            redo A;            redo A;
528          } elsif ($self->{next_input_character} == 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_input_character} 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 522  sub _get_next_token ($) { Line 550  sub _get_next_token ($) {
550            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>
551            my @next_char;            my @next_char;
552            TAGNAME: for (my $i = 0; $i < length $self->{last_emitted_start_tag_name}; $i++) {            TAGNAME: for (my $i = 0; $i < length $self->{last_emitted_start_tag_name}; $i++) {
553              push @next_char, $self->{next_input_character};              push @next_char, $self->{next_char};
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_input_character} == $c or $self->{next_input_character} == $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                $self->{next_input_character} = shift @next_char; # reconsume                !!!cp (25);
562                  $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;
565    
# Line 538  sub _get_next_token ($) { Line 568  sub _get_next_token ($) {
568                redo A;                redo A;
569              }              }
570            }            }
571            push @next_char, $self->{next_input_character};            push @next_char, $self->{next_char};
572                
573            unless ($self->{next_input_character} == 0x0009 or # HT            unless ($self->{next_char} == 0x0009 or # HT
574                    $self->{next_input_character} == 0x000A or # LF                    $self->{next_char} == 0x000A or # LF
575                    $self->{next_input_character} == 0x000B or # VT                    $self->{next_char} == 0x000B or # VT
576                    $self->{next_input_character} == 0x000C or # FF                    $self->{next_char} == 0x000C or # FF
577                    $self->{next_input_character} == 0x0020 or # SP                    $self->{next_char} == 0x0020 or # SP
578                    $self->{next_input_character} == 0x003E or # >                    $self->{next_char} == 0x003E or # >
579                    $self->{next_input_character} == 0x002F or # /                    $self->{next_char} == 0x002F or # /
580                    $self->{next_input_character} == -1) {                    $self->{next_char} == -1) {
581              $self->{next_input_character} = shift @next_char; # reconsume              !!!cp (26);
582                $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              $self->{next_input_character} = shift @next_char;              !!!cp (27);
589                $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 567  sub _get_next_token ($) { Line 600  sub _get_next_token ($) {
600          }          }
601        }        }
602                
603        if (0x0041 <= $self->{next_input_character} and        if (0x0041 <= $self->{next_char} and
604            $self->{next_input_character} <= 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_input_character} + 0x0020)};                            tag_name => chr ($self->{next_char} + 0x0020)};
608          $self->{state} = TAG_NAME_STATE;          $self->{state} = TAG_NAME_STATE;
609          !!!next-input-character;          !!!next-input-character;
610          redo A;          redo A;
611        } elsif (0x0061 <= $self->{next_input_character} and        } elsif (0x0061 <= $self->{next_char} and
612                 $self->{next_input_character} <= 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_input_character})};                            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_input_character} == 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_input_character} == -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_input_character} is intentionally left as is          ## $self->{next_char} is intentionally left as is
639          redo A;          redo A;
640        }        }
641      } elsif ($self->{state} == TAG_NAME_STATE) {      } elsif ($self->{state} == TAG_NAME_STATE) {
642        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
643            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
644            $self->{next_input_character} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
645            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
646            $self->{next_input_character} == 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_input_character} == 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 628  sub _get_next_token ($) { Line 672  sub _get_next_token ($) {
672          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
673    
674          redo A;          redo A;
675        } elsif (0x0041 <= $self->{next_input_character} and        } elsif (0x0041 <= $self->{next_char} and
676                 $self->{next_input_character} <= 0x005A) { # A..Z                 $self->{next_char} <= 0x005A) { # A..Z
677          $self->{current_token}->{tag_name} .= chr ($self->{next_input_character} + 0x0020);          !!!cp (38);
678            $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
681          !!!next-input-character;          !!!next-input-character;
682          redo A;          redo A;
683        } elsif ($self->{next_input_character} == -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 655  sub _get_next_token ($) { Line 705  sub _get_next_token ($) {
705          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
706    
707          redo A;          redo A;
708        } elsif ($self->{next_input_character} == 0x002F) { # /        } elsif ($self->{next_char} == 0x002F) { # /
709          !!!next-input-character;          !!!next-input-character;
710          if ($self->{next_input_character} == 0x003E and # >          if ($self->{next_char} == 0x003E and # >
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          $self->{current_token}->{tag_name} .= chr $self->{next_input_character};          !!!cp (44);
725            $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
728          !!!next-input-character;          !!!next-input-character;
729          redo A;          redo A;
730        }        }
731      } elsif ($self->{state} == BEFORE_ATTRIBUTE_NAME_STATE) {      } elsif ($self->{state} == BEFORE_ATTRIBUTE_NAME_STATE) {
732        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
733            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
734            $self->{next_input_character} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
735            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
736            $self->{next_input_character} == 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_input_character} == 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 703  sub _get_next_token ($) { Line 761  sub _get_next_token ($) {
761          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
762    
763          redo A;          redo A;
764        } elsif (0x0041 <= $self->{next_input_character} and        } elsif (0x0041 <= $self->{next_char} and
765                 $self->{next_input_character} <= 0x005A) { # A..Z                 $self->{next_char} <= 0x005A) { # A..Z
766          $self->{current_attribute} = {name => chr ($self->{next_input_character} + 0x0020),          !!!cp (49);
767            $self->{current_attribute} = {name => chr ($self->{next_char} + 0x0020),
768                                value => ''};                                value => ''};
769          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
770          !!!next-input-character;          !!!next-input-character;
771          redo A;          redo A;
772        } elsif ($self->{next_input_character} == 0x002F) { # /        } elsif ($self->{next_char} == 0x002F) { # /
773          !!!next-input-character;          !!!next-input-character;
774          if ($self->{next_input_character} == 0x003E and # >          if ($self->{next_char} == 0x003E and # >
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
785          # next-input-character is already done          # next-input-character is already done
786          redo A;          redo A;
787        } elsif ($self->{next_input_character} == -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 748  sub _get_next_token ($) { Line 813  sub _get_next_token ($) {
813               0x0022 => 1, # "               0x0022 => 1, # "
814               0x0027 => 1, # '               0x0027 => 1, # '
815               0x003D => 1, # =               0x003D => 1, # =
816              }->{$self->{next_input_character}}) {              }->{$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_input_character}),          $self->{current_attribute} = {name => chr ($self->{next_char}),
823                                value => ''};                                value => ''};
824          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
825          !!!next-input-character;          !!!next-input-character;
# 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          }          }
840        }; # $before_leave        }; # $before_leave
841    
842        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
843            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
844            $self->{next_input_character} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
845            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
846            $self->{next_input_character} == 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_input_character} == 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;
857          redo A;          redo A;
858        } elsif ($self->{next_input_character} == 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 803  sub _get_next_token ($) { Line 877  sub _get_next_token ($) {
877          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
878    
879          redo A;          redo A;
880        } elsif (0x0041 <= $self->{next_input_character} and        } elsif (0x0041 <= $self->{next_char} and
881                 $self->{next_input_character} <= 0x005A) { # A..Z                 $self->{next_char} <= 0x005A) { # A..Z
882          $self->{current_attribute}->{name} .= chr ($self->{next_input_character} + 0x0020);          !!!cp (63);
883            $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;
886          redo A;          redo A;
887        } elsif ($self->{next_input_character} == 0x002F) { # /        } elsif ($self->{next_char} == 0x002F) { # /
888          $before_leave->();          $before_leave->();
889          !!!next-input-character;          !!!next-input-character;
890          if ($self->{next_input_character} == 0x003E and # >          if ($self->{next_char} == 0x003E and # >
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;
901          # next-input-character is already done          # next-input-character is already done
902          redo A;          redo A;
903        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
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 845  sub _get_next_token ($) { Line 927  sub _get_next_token ($) {
927    
928          redo A;          redo A;
929        } else {        } else {
930          if ($self->{next_input_character} == 0x0022 or # "          if ($self->{next_char} == 0x0022 or # "
931              $self->{next_input_character} == 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_input_character});          $self->{current_attribute}->{name} .= chr ($self->{next_char});
938          ## Stay in the state          ## Stay in the state
939          !!!next-input-character;          !!!next-input-character;
940          redo A;          redo A;
941        }        }
942      } elsif ($self->{state} == AFTER_ATTRIBUTE_NAME_STATE) {      } elsif ($self->{state} == AFTER_ATTRIBUTE_NAME_STATE) {
943        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
944            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
945            $self->{next_input_character} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
946            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
947            $self->{next_input_character} == 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_input_character} == 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_input_character} == 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 886  sub _get_next_token ($) { Line 978  sub _get_next_token ($) {
978          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
979    
980          redo A;          redo A;
981        } elsif (0x0041 <= $self->{next_input_character} and        } elsif (0x0041 <= $self->{next_char} and
982                 $self->{next_input_character} <= 0x005A) { # A..Z                 $self->{next_char} <= 0x005A) { # A..Z
983          $self->{current_attribute} = {name => chr ($self->{next_input_character} + 0x0020),          !!!cp (76);
984            $self->{current_attribute} = {name => chr ($self->{next_char} + 0x0020),
985                                value => ''};                                value => ''};
986          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
987          !!!next-input-character;          !!!next-input-character;
988          redo A;          redo A;
989        } elsif ($self->{next_input_character} == 0x002F) { # /        } elsif ($self->{next_char} == 0x002F) { # /
990          !!!next-input-character;          !!!next-input-character;
991          if ($self->{next_input_character} == 0x003E and # >          if ($self->{next_char} == 0x003E and # >
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          }          }
1002          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1003          # next-input-character is already done          # next-input-character is already done
1004          redo A;          redo A;
1005        } elsif ($self->{next_input_character} == -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          $self->{current_attribute} = {name => chr ($self->{next_input_character}),          !!!cp (82);
1032            $self->{current_attribute} = {name => chr ($self->{next_char}),
1033                                value => ''};                                value => ''};
1034          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
1035          !!!next-input-character;          !!!next-input-character;
1036          redo A;                  redo A;        
1037        }        }
1038      } elsif ($self->{state} == BEFORE_ATTRIBUTE_VALUE_STATE) {      } elsif ($self->{state} == BEFORE_ATTRIBUTE_VALUE_STATE) {
1039        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
1040            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
1041            $self->{next_input_character} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
1042            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
1043            $self->{next_input_character} == 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_input_character} == 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_input_character} == 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_input_character} == 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_input_character} == 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 974  sub _get_next_token ($) { Line 1084  sub _get_next_token ($) {
1084          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
1085    
1086          redo A;          redo A;
1087        } elsif ($self->{next_input_character} == -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 995  sub _get_next_token ($) { Line 1110  sub _get_next_token ($) {
1110    
1111          redo A;          redo A;
1112        } else {        } else {
1113          if ($self->{next_input_character} == 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_input_character});          $self->{current_attribute}->{value} .= chr ($self->{next_char});
1120          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
1121          !!!next-input-character;          !!!next-input-character;
1122          redo A;          redo A;
1123        }        }
1124      } elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) {
1125        if ($self->{next_input_character} == 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_input_character} == 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;
1135          redo A;          redo A;
1136        } elsif ($self->{next_input_character} == -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          $self->{current_attribute}->{value} .= chr ($self->{next_input_character});          !!!cp (100);
1163            $self->{current_attribute}->{value} .= chr ($self->{next_char});
1164          ## Stay in the state          ## Stay in the state
1165          !!!next-input-character;          !!!next-input-character;
1166          redo A;          redo A;
1167        }        }
1168      } elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) {
1169        if ($self->{next_input_character} == 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_input_character} == 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;
1179          redo A;          redo A;
1180        } elsif ($self->{next_input_character} == -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          $self->{current_attribute}->{value} .= chr ($self->{next_input_character});          !!!cp (106);
1207            $self->{current_attribute}->{value} .= chr ($self->{next_char});
1208          ## Stay in the state          ## Stay in the state
1209          !!!next-input-character;          !!!next-input-character;
1210          redo A;          redo A;
1211        }        }
1212      } elsif ($self->{state} == ATTRIBUTE_VALUE_UNQUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_UNQUOTED_STATE) {
1213        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
1214            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
1215            $self->{next_input_character} == 0x000B or # HT            $self->{next_char} == 0x000B or # HT
1216            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
1217            $self->{next_input_character} == 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_input_character} == 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_input_character} == 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 1108  sub _get_next_token ($) { Line 1249  sub _get_next_token ($) {
1249          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
1250    
1251          redo A;          redo A;
1252        } elsif ($self->{next_input_character} == -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 1133  sub _get_next_token ($) { Line 1279  sub _get_next_token ($) {
1279               0x0022 => 1, # "               0x0022 => 1, # "
1280               0x0027 => 1, # '               0x0027 => 1, # '
1281               0x003D => 1, # =               0x003D => 1, # =
1282              }->{$self->{next_input_character}}) {              }->{$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_input_character});          $self->{current_attribute}->{value} .= chr ($self->{next_char});
1289          ## Stay in the state          ## Stay in the state
1290          !!!next-input-character;          !!!next-input-character;
1291          redo A;          redo A;
# 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 1162  sub _get_next_token ($) { Line 1313  sub _get_next_token ($) {
1313        # next-input-character is already done        # next-input-character is already done
1314        redo A;        redo A;
1315      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {
1316        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
1317            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
1318            $self->{next_input_character} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
1319            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
1320            $self->{next_input_character} == 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_input_character} == 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 1189  sub _get_next_token ($) { Line 1346  sub _get_next_token ($) {
1346          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
1347    
1348          redo A;          redo A;
1349        } elsif ($self->{next_input_character} == 0x002F) { # /        } elsif ($self->{next_char} == 0x002F) { # /
1350          !!!next-input-character;          !!!next-input-character;
1351          if ($self->{next_input_character} == 0x003E and # >          if ($self->{next_char} == 0x003E and # >
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 1214  sub _get_next_token ($) { Line 1374  sub _get_next_token ($) {
1374        my $token = {type => COMMENT_TOKEN, data => ''};        my $token = {type => COMMENT_TOKEN, data => ''};
1375    
1376        BC: {        BC: {
1377          if ($self->{next_input_character} == 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    
1382            !!!emit ($token);            !!!emit ($token);
1383    
1384            redo A;            redo A;
1385          } elsif ($self->{next_input_character} == -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            $token->{data} .= chr ($self->{next_input_character});            !!!cp (126);
1395              $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    
1405        my @next_char;        my @next_char;
1406        push @next_char, $self->{next_input_character};        push @next_char, $self->{next_char};
1407                
1408        if ($self->{next_input_character} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
1409          !!!next-input-character;          !!!next-input-character;
1410          push @next_char, $self->{next_input_character};          push @next_char, $self->{next_char};
1411          if ($self->{next_input_character} == 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_input_character} == 0x0044 or # D        } elsif ($self->{next_char} == 0x0044 or # D
1421                 $self->{next_input_character} == 0x0064) { # d                 $self->{next_char} == 0x0064) { # d
1422          !!!next-input-character;          !!!next-input-character;
1423          push @next_char, $self->{next_input_character};          push @next_char, $self->{next_char};
1424          if ($self->{next_input_character} == 0x004F or # O          if ($self->{next_char} == 0x004F or # O
1425              $self->{next_input_character} == 0x006F) { # o              $self->{next_char} == 0x006F) { # o
1426            !!!next-input-character;            !!!next-input-character;
1427            push @next_char, $self->{next_input_character};            push @next_char, $self->{next_char};
1428            if ($self->{next_input_character} == 0x0043 or # C            if ($self->{next_char} == 0x0043 or # C
1429                $self->{next_input_character} == 0x0063) { # c                $self->{next_char} == 0x0063) { # c
1430              !!!next-input-character;              !!!next-input-character;
1431              push @next_char, $self->{next_input_character};              push @next_char, $self->{next_char};
1432              if ($self->{next_input_character} == 0x0054 or # T              if ($self->{next_char} == 0x0054 or # T
1433                  $self->{next_input_character} == 0x0074) { # t                  $self->{next_char} == 0x0074) { # t
1434                !!!next-input-character;                !!!next-input-character;
1435                push @next_char, $self->{next_input_character};                push @next_char, $self->{next_char};
1436                if ($self->{next_input_character} == 0x0059 or # Y                if ($self->{next_char} == 0x0059 or # Y
1437                    $self->{next_input_character} == 0x0079) { # y                    $self->{next_char} == 0x0079) { # y
1438                  !!!next-input-character;                  !!!next-input-character;
1439                  push @next_char, $self->{next_input_character};                  push @next_char, $self->{next_char};
1440                  if ($self->{next_input_character} == 0x0050 or # P                  if ($self->{next_char} == 0x0050 or # P
1441                      $self->{next_input_character} == 0x0070) { # p                      $self->{next_char} == 0x0070) { # p
1442                    !!!next-input-character;                    !!!next-input-character;
1443                    push @next_char, $self->{next_input_character};                    push @next_char, $self->{next_char};
1444                    if ($self->{next_input_character} == 0x0045 or # E                    if ($self->{next_char} == 0x0045 or # E
1445                        $self->{next_input_character} == 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');
1474        $self->{next_input_character} = shift @next_char;        $self->{next_char} = shift @next_char;
1475        !!!back-next-input-character (@next_char);        !!!back-next-input-character (@next_char);
1476        $self->{state} = BOGUS_COMMENT_STATE;        $self->{state} = BOGUS_COMMENT_STATE;
1477        redo A;        redo A;
# Line 1296  sub _get_next_token ($) { Line 1479  sub _get_next_token ($) {
1479        ## ISSUE: typos in spec: chacacters, is is a parse error        ## ISSUE: typos in spec: chacacters, is is a parse error
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_input_character} == 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_input_character} == 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 1308  sub _get_next_token ($) { Line 1493  sub _get_next_token ($) {
1493          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
1494    
1495          redo A;          redo A;
1496        } elsif ($self->{next_input_character} == -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_input_character});              .= chr ($self->{next_char});
1509          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
1510          !!!next-input-character;          !!!next-input-character;
1511          redo A;          redo A;
1512        }        }
1513      } elsif ($self->{state} == COMMENT_START_DASH_STATE) {      } elsif ($self->{state} == COMMENT_START_DASH_STATE) {
1514        if ($self->{next_input_character} == 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_input_character} == 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 1336  sub _get_next_token ($) { Line 1525  sub _get_next_token ($) {
1525          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
1526    
1527          redo A;          redo A;
1528        } elsif ($self->{next_input_character} == -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_input_character});              .= '-' . chr ($self->{next_char});
1541          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
1542          !!!next-input-character;          !!!next-input-character;
1543          redo A;          redo A;
1544        }        }
1545      } elsif ($self->{state} == COMMENT_STATE) {      } elsif ($self->{state} == COMMENT_STATE) {
1546        if ($self->{next_input_character} == 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_input_character} == -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          $self->{current_token}->{data} .= chr ($self->{next_input_character}); # comment          !!!cp (147);
1562            $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;
1565          redo A;          redo A;
1566        }        }
1567      } elsif ($self->{state} == COMMENT_END_DASH_STATE) {      } elsif ($self->{state} == COMMENT_END_DASH_STATE) {
1568        if ($self->{next_input_character} == 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_input_character} == -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          $self->{current_token}->{data} .= '-' . chr ($self->{next_input_character}); # comment          !!!cp (150);
1584            $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;
1587          redo A;          redo A;
1588        }        }
1589      } elsif ($self->{state} == COMMENT_END_STATE) {      } elsif ($self->{state} == COMMENT_END_STATE) {
1590        if ($self->{next_input_character} == 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    
1595          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
1596    
1597          redo A;          redo A;
1598        } elsif ($self->{next_input_character} == 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_input_character} == -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_input_character}); # comment          $self->{current_token}->{data} .= '--' . chr ($self->{next_char}); # comment
1618          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
1619          !!!next-input-character;          !!!next-input-character;
1620          redo A;          redo A;
1621        }        }
1622      } elsif ($self->{state} == DOCTYPE_STATE) {      } elsif ($self->{state} == DOCTYPE_STATE) {
1623        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
1624            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
1625            $self->{next_input_character} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
1626            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
1627            $self->{next_input_character} == 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
1637          redo A;          redo A;
1638        }        }
1639      } elsif ($self->{state} == BEFORE_DOCTYPE_NAME_STATE) {      } elsif ($self->{state} == BEFORE_DOCTYPE_NAME_STATE) {
1640        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
1641            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
1642            $self->{next_input_character} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
1643            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
1644            $self->{next_input_character} == 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_input_character} == 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;
1654    
1655          !!!emit ({type => DOCTYPE_TOKEN}); # incorrect          !!!emit ({type => DOCTYPE_TOKEN, quirks => 1});
1656    
1657          redo A;          redo A;
1658        } elsif ($self->{next_input_character} == -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
1663    
1664          !!!emit ({type => DOCTYPE_TOKEN}); # incorrect          !!!emit ({type => DOCTYPE_TOKEN, quirks => 1});
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_input_character}),                 name => chr ($self->{next_char}),
1672                 correct => 1};                 #quirks => 0,
1673                  };
1674  ## ISSUE: "Set the token's name name to the" in the spec  ## ISSUE: "Set the token's name name to the" in the spec
1675          $self->{state} = DOCTYPE_NAME_STATE;          $self->{state} = DOCTYPE_NAME_STATE;
1676          !!!next-input-character;          !!!next-input-character;
# Line 1470  sub _get_next_token ($) { Line 1678  sub _get_next_token ($) {
1678        }        }
1679      } elsif ($self->{state} == DOCTYPE_NAME_STATE) {      } elsif ($self->{state} == DOCTYPE_NAME_STATE) {
1680  ## ISSUE: Redundant "First," in the spec.  ## ISSUE: Redundant "First," in the spec.
1681        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
1682            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
1683            $self->{next_input_character} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
1684            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
1685            $self->{next_input_character} == 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_input_character} == 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    
1695          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
1696    
1697          redo A;          redo A;
1698        } elsif ($self->{next_input_character} == -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
1703    
1704          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
1705          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
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_input_character}); # DOCTYPE            .= chr ($self->{next_char}); # DOCTYPE
1712          ## Stay in the state          ## Stay in the state
1713          !!!next-input-character;          !!!next-input-character;
1714          redo A;          redo A;
1715        }        }
1716      } elsif ($self->{state} == AFTER_DOCTYPE_NAME_STATE) {      } elsif ($self->{state} == AFTER_DOCTYPE_NAME_STATE) {
1717        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
1718            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
1719            $self->{next_input_character} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
1720            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
1721            $self->{next_input_character} == 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_input_character} == 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    
1731          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
1732    
1733          redo A;          redo A;
1734        } elsif ($self->{next_input_character} == -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
1739    
1740          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
1741          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
1742    
1743          redo A;          redo A;
1744        } elsif ($self->{next_input_character} == 0x0050 or # P        } elsif ($self->{next_char} == 0x0050 or # P
1745                 $self->{next_input_character} == 0x0070) { # p                 $self->{next_char} == 0x0070) { # p
1746          !!!next-input-character;          !!!next-input-character;
1747          if ($self->{next_input_character} == 0x0055 or # U          if ($self->{next_char} == 0x0055 or # U
1748              $self->{next_input_character} == 0x0075) { # u              $self->{next_char} == 0x0075) { # u
1749            !!!next-input-character;            !!!next-input-character;
1750            if ($self->{next_input_character} == 0x0042 or # B            if ($self->{next_char} == 0x0042 or # B
1751                $self->{next_input_character} == 0x0062) { # b                $self->{next_char} == 0x0062) { # b
1752              !!!next-input-character;              !!!next-input-character;
1753              if ($self->{next_input_character} == 0x004C or # L              if ($self->{next_char} == 0x004C or # L
1754                  $self->{next_input_character} == 0x006C) { # l                  $self->{next_char} == 0x006C) { # l
1755                !!!next-input-character;                !!!next-input-character;
1756                if ($self->{next_input_character} == 0x0049 or # I                if ($self->{next_char} == 0x0049 or # I
1757                    $self->{next_input_character} == 0x0069) { # i                    $self->{next_char} == 0x0069) { # i
1758                  !!!next-input-character;                  !!!next-input-character;
1759                  if ($self->{next_input_character} == 0x0043 or # C                  if ($self->{next_char} == 0x0043 or # C
1760                      $self->{next_input_character} == 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          #          #
1782        } elsif ($self->{next_input_character} == 0x0053 or # S        } elsif ($self->{next_char} == 0x0053 or # S
1783                 $self->{next_input_character} == 0x0073) { # s                 $self->{next_char} == 0x0073) { # s
1784          !!!next-input-character;          !!!next-input-character;
1785          if ($self->{next_input_character} == 0x0059 or # Y          if ($self->{next_char} == 0x0059 or # Y
1786              $self->{next_input_character} == 0x0079) { # y              $self->{next_char} == 0x0079) { # y
1787            !!!next-input-character;            !!!next-input-character;
1788            if ($self->{next_input_character} == 0x0053 or # S            if ($self->{next_char} == 0x0053 or # S
1789                $self->{next_input_character} == 0x0073) { # s                $self->{next_char} == 0x0073) { # s
1790              !!!next-input-character;              !!!next-input-character;
1791              if ($self->{next_input_character} == 0x0054 or # T              if ($self->{next_char} == 0x0054 or # T
1792                  $self->{next_input_character} == 0x0074) { # t                  $self->{next_char} == 0x0074) { # t
1793                !!!next-input-character;                !!!next-input-character;
1794                if ($self->{next_input_character} == 0x0045 or # E                if ($self->{next_char} == 0x0045 or # E
1795                    $self->{next_input_character} == 0x0065) { # e                    $self->{next_char} == 0x0065) { # e
1796                  !!!next-input-character;                  !!!next-input-character;
1797                  if ($self->{next_input_character} == 0x004D or # M                  if ($self->{next_char} == 0x004D or # M
1798                      $self->{next_input_character} == 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        }        }
1825    
1826        !!!parse-error (type => 'string after DOCTYPE name');        !!!parse-error (type => 'string after DOCTYPE name');
1827          $self->{current_token}->{quirks} = 1;
1828    
1829        $self->{state} = BOGUS_DOCTYPE_STATE;        $self->{state} = BOGUS_DOCTYPE_STATE;
1830        # next-input-character is already done        # next-input-character is already done
1831        redo A;        redo A;
# Line 1593  sub _get_next_token ($) { Line 1833  sub _get_next_token ($) {
1833        if ({        if ({
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_input_character}}) {            }->{$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_input_character} 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_input_character} 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_input_character} 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;
1858          !!!next-input-character;          !!!next-input-character;
1859    
1860          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
1861          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
1862    
1863          redo A;          redo A;
1864        } elsif ($self->{next_input_character} == -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;
1869          ## reconsume          ## reconsume
1870    
1871          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
1872          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
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;
1879    
1880          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
1881          !!!next-input-character;          !!!next-input-character;
1882          redo A;          redo A;
1883        }        }
1884      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE) {
1885        if ($self->{next_input_character} == 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_input_character} == 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;
1895          !!!next-input-character;          !!!next-input-character;
1896    
1897          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
1898          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
1899    
1900          redo A;          redo A;
1901        } elsif ($self->{next_input_character} == -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;
1906          ## reconsume          ## reconsume
1907    
1908          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
1909          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
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_input_character};              .= chr $self->{next_char};
1916          ## Stay in the state          ## Stay in the state
1917          !!!next-input-character;          !!!next-input-character;
1918          redo A;          redo A;
1919        }        }
1920      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE) {
1921        if ($self->{next_input_character} == 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_input_character} == 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;
1931          !!!next-input-character;          !!!next-input-character;
1932    
1933          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
1934          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
1935    
1936          redo A;          redo A;
1937        } elsif ($self->{next_input_character} == -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;
1942          ## reconsume          ## reconsume
1943    
1944          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
1945          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
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_input_character};              .= chr $self->{next_char};
1952          ## Stay in the state          ## Stay in the state
1953          !!!next-input-character;          !!!next-input-character;
1954          redo A;          redo A;
# Line 1701  sub _get_next_token ($) { Line 1957  sub _get_next_token ($) {
1957        if ({        if ({
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_input_character}}) {            }->{$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_input_character} == 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_input_character} == 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_input_character} == 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    
1982          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
1983    
1984          redo A;          redo A;
1985        } elsif ($self->{next_input_character} == -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;
1990          ## reconsume          ## reconsume
1991    
1992          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
1993          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
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;
2000    
2001          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2002          !!!next-input-character;          !!!next-input-character;
2003          redo A;          redo A;
# Line 1742  sub _get_next_token ($) { Line 2006  sub _get_next_token ($) {
2006        if ({        if ({
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_input_character}}) {            }->{$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_input_character} == 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_input_character} == 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_input_character} == 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;
2031    
2032          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
2033          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
2034    
2035          redo A;          redo A;
2036        } elsif ($self->{next_input_character} == -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;
2041          ## reconsume          ## reconsume
2042    
2043          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
2044          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
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;
2051    
2052          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2053          !!!next-input-character;          !!!next-input-character;
2054          redo A;          redo A;
2055        }        }
2056      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE) {
2057        if ($self->{next_input_character} == 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_input_character} == 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;
2067          !!!next-input-character;          !!!next-input-character;
2068    
2069          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
2070          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
2071    
2072          redo A;          redo A;
2073        } elsif ($self->{next_input_character} == -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;
2078          ## reconsume          ## reconsume
2079    
2080          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
2081          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
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_input_character};              .= chr $self->{next_char};
2088          ## Stay in the state          ## Stay in the state
2089          !!!next-input-character;          !!!next-input-character;
2090          redo A;          redo A;
2091        }        }
2092      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE) {
2093        if ($self->{next_input_character} == 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_input_character} == 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;
2103          !!!next-input-character;          !!!next-input-character;
2104    
2105          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
2106          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
2107    
2108          redo A;          redo A;
2109        } elsif ($self->{next_input_character} == -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;
2114          ## reconsume          ## reconsume
2115    
2116          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
2117          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
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_input_character};              .= chr $self->{next_char};
2124          ## Stay in the state          ## Stay in the state
2125          !!!next-input-character;          !!!next-input-character;
2126          redo A;          redo A;
# Line 1849  sub _get_next_token ($) { Line 2129  sub _get_next_token ($) {
2129        if ({        if ({
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_input_character}}) {            }->{$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_input_character} == 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    
2142          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
2143    
2144          redo A;          redo A;
2145        } elsif ($self->{next_input_character} == -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;
2150          ## reconsume          ## reconsume
2151    
2152          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
2153          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
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;
2160    
2161          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2162          !!!next-input-character;          !!!next-input-character;
2163          redo A;          redo A;
2164        }        }
2165      } elsif ($self->{state} == BOGUS_DOCTYPE_STATE) {      } elsif ($self->{state} == BOGUS_DOCTYPE_STATE) {
2166        if ($self->{next_input_character} == 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    
         delete $self->{current_token}->{correct};  
2171          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
2172    
2173          redo A;          redo A;
2174        } elsif ($self->{next_input_character} == -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
2179    
         delete $self->{current_token}->{correct};  
2180          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
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 1914  sub _tokenize_attempt_to_consume_an_enti Line 2201  sub _tokenize_attempt_to_consume_an_enti
2201         0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,         0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,
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_input_character}}) {        }->{$self->{next_char}}) {
2205        !!!cp (1001);
2206      ## Don't consume      ## Don't consume
2207      ## No error      ## No error
2208      return undef;      return undef;
2209    } elsif ($self->{next_input_character} == 0x0023) { # #    } elsif ($self->{next_char} == 0x0023) { # #
2210      !!!next-input-character;      !!!next-input-character;
2211      if ($self->{next_input_character} == 0x0078 or # x      if ($self->{next_char} == 0x0078 or # x
2212          $self->{next_input_character} == 0x0058) { # X          $self->{next_char} == 0x0058) { # X
2213        my $code;        my $code;
2214        X: {        X: {
2215          my $x_char = $self->{next_input_character};          my $x_char = $self->{next_char};
2216          !!!next-input-character;          !!!next-input-character;
2217          if (0x0030 <= $self->{next_input_character} and          if (0x0030 <= $self->{next_char} and
2218              $self->{next_input_character} <= 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_input_character} - 0x0030;            $code += $self->{next_char} - 0x0030;
2223            redo X;            redo X;
2224          } elsif (0x0061 <= $self->{next_input_character} and          } elsif (0x0061 <= $self->{next_char} and
2225                   $self->{next_input_character} <= 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_input_character} - 0x0060 + 9;            $code += $self->{next_char} - 0x0060 + 9;
2230            redo X;            redo X;
2231          } elsif (0x0041 <= $self->{next_input_character} and          } elsif (0x0041 <= $self->{next_char} and
2232                   $self->{next_input_character} <= 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_input_character} - 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_input_character});            !!!back-next-input-character ($x_char, $self->{next_char});
2242            $self->{next_input_character} = 0x0023; # #            $self->{next_char} = 0x0023; # #
2243            return undef;            return undef;
2244          } elsif ($self->{next_input_character} == 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 1972  sub _tokenize_attempt_to_consume_an_enti Line 2270  sub _tokenize_attempt_to_consume_an_enti
2270          return {type => CHARACTER_TOKEN, data => chr $code,          return {type => CHARACTER_TOKEN, data => chr $code,
2271                  has_reference => 1};                  has_reference => 1};
2272        } # X        } # X
2273      } elsif (0x0030 <= $self->{next_input_character} and      } elsif (0x0030 <= $self->{next_char} and
2274               $self->{next_input_character} <= 0x0039) { # 0..9               $self->{next_char} <= 0x0039) { # 0..9
2275        my $code = $self->{next_input_character} - 0x0030;        my $code = $self->{next_char} - 0x0030;
2276        !!!next-input-character;        !!!next-input-character;
2277                
2278        while (0x0030 <= $self->{next_input_character} and        while (0x0030 <= $self->{next_char} and
2279                  $self->{next_input_character} <= 0x0039) { # 0..9                  $self->{next_char} <= 0x0039) { # 0..9
2280            !!!cp (1012);
2281          $code *= 10;          $code *= 10;
2282          $code += $self->{next_input_character} - 0x0030;          $code += $self->{next_char} - 0x0030;
2283                    
2284          !!!next-input-character;          !!!next-input-character;
2285        }        }
2286    
2287        if ($self->{next_input_character} == 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_input_character});        !!!back-next-input-character ($self->{next_char});
2318        $self->{next_input_character} = 0x0023; # #        $self->{next_char} = 0x0023; # #
2319        return undef;        return undef;
2320      }      }
2321    } elsif ((0x0041 <= $self->{next_input_character} and    } elsif ((0x0041 <= $self->{next_char} and
2322              $self->{next_input_character} <= 0x005A) or              $self->{next_char} <= 0x005A) or
2323             (0x0061 <= $self->{next_input_character} and             (0x0061 <= $self->{next_char} and
2324              $self->{next_input_character} <= 0x007A)) {              $self->{next_char} <= 0x007A)) {
2325      my $entity_name = chr $self->{next_input_character};      my $entity_name = chr $self->{next_char};
2326      !!!next-input-character;      !!!next-input-character;
2327    
2328      my $value = $entity_name;      my $value = $entity_name;
# Line 2026  sub _tokenize_attempt_to_consume_an_enti Line 2332  sub _tokenize_attempt_to_consume_an_enti
2332    
2333      while (length $entity_name < 10 and      while (length $entity_name < 10 and
2334             ## NOTE: Some number greater than the maximum length of entity name             ## NOTE: Some number greater than the maximum length of entity name
2335             ((0x0041 <= $self->{next_input_character} and # a             ((0x0041 <= $self->{next_char} and # a
2336               $self->{next_input_character} <= 0x005A) or # x               $self->{next_char} <= 0x005A) or # x
2337              (0x0061 <= $self->{next_input_character} and # a              (0x0061 <= $self->{next_char} and # a
2338               $self->{next_input_character} <= 0x007A) or # z               $self->{next_char} <= 0x007A) or # z
2339              (0x0030 <= $self->{next_input_character} and # 0              (0x0030 <= $self->{next_char} and # 0
2340               $self->{next_input_character} <= 0x0039) or # 9               $self->{next_char} <= 0x0039) or # 9
2341              $self->{next_input_character} == 0x003B)) { # ;              $self->{next_char} == 0x003B)) { # ;
2342        $entity_name .= chr $self->{next_input_character};        $entity_name .= chr $self->{next_char};
2343        if (defined $EntityChar->{$entity_name}) {        if (defined $EntityChar->{$entity_name}) {
2344          if ($self->{next_input_character} == 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          $value .= chr $self->{next_input_character};          !!!cp (1022);
2358            $value .= chr $self->{next_char};
2359          $match *= 2;          $match *= 2;
2360          !!!next-input-character;          !!!next-input-character;
2361        }        }
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 2130  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 2146  sub _tree_construction_initial ($) { Line 2464  sub _tree_construction_initial ($) {
2464        ## ISSUE: internalSubset = null??        ## ISSUE: internalSubset = null??
2465        $self->{document}->append_child ($doctype);        $self->{document}->append_child ($doctype);
2466                
2467        if (not $token->{correct} 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 2225  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 2254  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 2264  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 2276  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 2286  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 2293  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 2309  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 2321  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 2334  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 2349  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 2373  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 2383  sub _reset_insertion_mode ($) { Line 2739  sub _reset_insertion_mode ($) {
2739        ## Step 4..13        ## Step 4..13
2740        my $new_mode = {        my $new_mode = {
2741                        select => IN_SELECT_IM,                        select => IN_SELECT_IM,
2742                          ## NOTE: |option| and |optgroup| do not set
2743                          ## insertion mode to "in select" by themselves.
2744                        td => IN_CELL_IM,                        td => IN_CELL_IM,
2745                        th => IN_CELL_IM,                        th => IN_CELL_IM,
2746                        tr => IN_ROW_IM,                        tr => IN_ROW_IM,
# Line 2401  sub _reset_insertion_mode ($) { Line 2759  sub _reset_insertion_mode ($) {
2759        ## Step 14        ## Step 14
2760        if ($node->[1] eq 'html') {        if ($node->[1] eq 'html') {
2761          unless (defined $self->{head_element}) {          unless (defined $self->{head_element}) {
2762              !!!cp ('t29');
2763            $self->{insertion_mode} = BEFORE_HEAD_IM;            $self->{insertion_mode} = BEFORE_HEAD_IM;
2764          } else {          } else {
2765              ## ISSUE: Can this state be reached?
2766              !!!cp ('t30');
2767            $self->{insertion_mode} = AFTER_HEAD_IM;            $self->{insertion_mode} = AFTER_HEAD_IM;
2768          }          }
2769          return;          return;
2770          } else {
2771            !!!cp ('t31');
2772        }        }
2773                
2774        ## Step 15        ## Step 15
# Line 2418  sub _reset_insertion_mode ($) { Line 2781  sub _reset_insertion_mode ($) {
2781        ## Step 17        ## Step 17
2782        redo S3;        redo S3;
2783      } # S3      } # S3
2784    
2785      die "$0: _reset_insertion_mode: This line should never be reached";
2786  } # _reset_insertion_mode  } # _reset_insertion_mode
2787    
2788  sub _tree_construction_main ($) {  sub _tree_construction_main ($) {
# Line 2439  sub _tree_construction_main ($) { Line 2804  sub _tree_construction_main ($) {
2804      return if $entry->[0] eq '#marker';      return if $entry->[0] eq '#marker';
2805      for (@{$self->{open_elements}}) {      for (@{$self->{open_elements}}) {
2806        if ($entry->[0] eq $_->[0]) {        if ($entry->[0] eq $_->[0]) {
2807            !!!cp ('t32');
2808          return;          return;
2809        }        }
2810      }      }
# Line 2453  sub _tree_construction_main ($) { Line 2819  sub _tree_construction_main ($) {
2819    
2820        ## Step 6        ## Step 6
2821        if ($entry->[0] eq '#marker') {        if ($entry->[0] eq '#marker') {
2822            !!!cp ('t33_1');
2823          #          #
2824        } else {        } else {
2825          my $in_open_elements;          my $in_open_elements;
2826          OE: for (@{$self->{open_elements}}) {          OE: for (@{$self->{open_elements}}) {
2827            if ($entry->[0] eq $_->[0]) {            if ($entry->[0] eq $_->[0]) {
2828                !!!cp ('t33');
2829              $in_open_elements = 1;              $in_open_elements = 1;
2830              last OE;              last OE;
2831            }            }
2832          }          }
2833          if ($in_open_elements) {          if ($in_open_elements) {
2834              !!!cp ('t34');
2835            #            #
2836          } else {          } else {
2837              ## NOTE: <!DOCTYPE HTML><p><b><i><u></p> <p>X
2838              !!!cp ('t35');
2839            redo S4;            redo S4;
2840          }          }
2841        }        }
# Line 2487  sub _tree_construction_main ($) { Line 2858  sub _tree_construction_main ($) {
2858    
2859        ## Step 11        ## Step 11
2860        unless ($clone->[0] eq $active_formatting_elements->[-1]->[0]) {        unless ($clone->[0] eq $active_formatting_elements->[-1]->[0]) {
2861            !!!cp ('t36');
2862          ## Step 7'          ## Step 7'
2863          $i++;          $i++;
2864          $entry = $active_formatting_elements->[$i];          $entry = $active_formatting_elements->[$i];
2865                    
2866          redo S7;          redo S7;
2867        }        }
2868    
2869          !!!cp ('t37');
2870      } # S7      } # S7
2871    }; # $reconstruct_active_formatting_elements    }; # $reconstruct_active_formatting_elements
2872    
2873    my $clear_up_to_marker = sub {    my $clear_up_to_marker = sub {
2874      for (reverse 0..$#$active_formatting_elements) {      for (reverse 0..$#$active_formatting_elements) {
2875        if ($active_formatting_elements->[$_]->[0] eq '#marker') {        if ($active_formatting_elements->[$_]->[0] eq '#marker') {
2876            !!!cp ('t38');
2877          splice @$active_formatting_elements, $_;          splice @$active_formatting_elements, $_;
2878          return;          return;
2879        }        }
2880      }      }
2881    
2882        !!!cp ('t39');
2883    }; # $clear_up_to_marker    }; # $clear_up_to_marker
2884    
2885    my $parse_rcdata = sub ($$) {    my $parse_rcdata = sub ($$) {
# Line 2524  sub _tree_construction_main ($) { Line 2901  sub _tree_construction_main ($) {
2901      my $text = '';      my $text = '';
2902      !!!next-token;      !!!next-token;
2903      while ($token->{type} == CHARACTER_TOKEN) { # or until stop tokenizing      while ($token->{type} == CHARACTER_TOKEN) { # or until stop tokenizing
2904          !!!cp ('t40');
2905        $text .= $token->{data};        $text .= $token->{data};
2906        !!!next-token;        !!!next-token;
2907      }      }
2908    
2909      ## Step 5      ## Step 5
2910      if (length $text) {      if (length $text) {
2911          !!!cp ('t41');
2912        my $text = $self->{document}->create_text_node ($text);        my $text = $self->{document}->create_text_node ($text);
2913        $el->append_child ($text);        $el->append_child ($text);
2914      }      }
# Line 2538  sub _tree_construction_main ($) { Line 2917  sub _tree_construction_main ($) {
2917      $self->{content_model} = PCDATA_CONTENT_MODEL;      $self->{content_model} = PCDATA_CONTENT_MODEL;
2918    
2919      ## Step 7      ## Step 7
2920      if ($token->{type} == END_TAG_TOKEN and $token->{tag_name} eq $start_tag_name) {      if ($token->{type} == END_TAG_TOKEN and
2921            $token->{tag_name} eq $start_tag_name) {
2922          !!!cp ('t42');
2923        ## Ignore the token        ## Ignore the token
2924      } elsif ($content_model_flag == CDATA_CONTENT_MODEL) {      } elsif ($content_model_flag == CDATA_CONTENT_MODEL) {
2925          !!!cp ('t43');
2926        !!!parse-error (type => 'in CDATA:#'.$token->{type});        !!!parse-error (type => 'in CDATA:#'.$token->{type});
2927      } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {      } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
2928          !!!cp ('t44');
2929        !!!parse-error (type => 'in RCDATA:#'.$token->{type});        !!!parse-error (type => 'in RCDATA:#'.$token->{type});
2930      } else {      } else {
2931        die "$0: $content_model_flag in parse_rcdata";        die "$0: $content_model_flag in parse_rcdata";
# Line 2562  sub _tree_construction_main ($) { Line 2945  sub _tree_construction_main ($) {
2945      my $text = '';      my $text = '';
2946      !!!next-token;      !!!next-token;
2947      while ($token->{type} == CHARACTER_TOKEN) {      while ($token->{type} == CHARACTER_TOKEN) {
2948          !!!cp ('t45');
2949        $text .= $token->{data};        $text .= $token->{data};
2950        !!!next-token;        !!!next-token;
2951      } # stop if non-character token or tokenizer stops tokenising      } # stop if non-character token or tokenizer stops tokenising
2952      if (length $text) {      if (length $text) {
2953          !!!cp ('t46');
2954        $script_el->manakai_append_text ($text);        $script_el->manakai_append_text ($text);
2955      }      }
2956                                
# Line 2573  sub _tree_construction_main ($) { Line 2958  sub _tree_construction_main ($) {
2958    
2959      if ($token->{type} == END_TAG_TOKEN and      if ($token->{type} == END_TAG_TOKEN and
2960          $token->{tag_name} eq 'script') {          $token->{tag_name} eq 'script') {
2961          !!!cp ('t47');
2962        ## Ignore the token        ## Ignore the token
2963      } else {      } else {
2964          !!!cp ('t48');
2965        !!!parse-error (type => 'in CDATA:#'.$token->{type});        !!!parse-error (type => 'in CDATA:#'.$token->{type});
2966        ## ISSUE: And ignore?        ## ISSUE: And ignore?
2967        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
2968      }      }
2969            
2970      if (defined $self->{inner_html_node}) {      if (defined $self->{inner_html_node}) {
2971          !!!cp ('t49');
2972        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
2973      } else {      } else {
2974          !!!cp ('t50');
2975        ## TODO: $old_insertion_point = current insertion point        ## TODO: $old_insertion_point = current insertion point
2976        ## TODO: insertion point = just before the next input character        ## TODO: insertion point = just before the next input character
2977    
# Line 2605  sub _tree_construction_main ($) { Line 2994  sub _tree_construction_main ($) {
2994        my $formatting_element_i_in_active;        my $formatting_element_i_in_active;
2995        AFE: for (reverse 0..$#$active_formatting_elements) {        AFE: for (reverse 0..$#$active_formatting_elements) {
2996          if ($active_formatting_elements->[$_]->[1] eq $tag_name) {          if ($active_formatting_elements->[$_]->[1] eq $tag_name) {
2997              !!!cp ('t51');
2998            $formatting_element = $active_formatting_elements->[$_];            $formatting_element = $active_formatting_elements->[$_];
2999            $formatting_element_i_in_active = $_;            $formatting_element_i_in_active = $_;
3000            last AFE;            last AFE;
3001          } elsif ($active_formatting_elements->[$_]->[0] eq '#marker') {          } elsif ($active_formatting_elements->[$_]->[0] eq '#marker') {
3002              !!!cp ('t52');
3003            last AFE;            last AFE;
3004          }          }
3005        } # AFE        } # AFE
3006        unless (defined $formatting_element) {        unless (defined $formatting_element) {
3007            !!!cp ('t53');
3008          !!!parse-error (type => 'unmatched end tag:'.$tag_name);          !!!parse-error (type => 'unmatched end tag:'.$tag_name);
3009          ## Ignore the token          ## Ignore the token
3010          !!!next-token;          !!!next-token;
# Line 2625  sub _tree_construction_main ($) { Line 3017  sub _tree_construction_main ($) {
3017          my $node = $self->{open_elements}->[$_];          my $node = $self->{open_elements}->[$_];
3018          if ($node->[0] eq $formatting_element->[0]) {          if ($node->[0] eq $formatting_element->[0]) {
3019            if ($in_scope) {            if ($in_scope) {
3020                !!!cp ('t54');
3021              $formatting_element_i_in_open = $_;              $formatting_element_i_in_open = $_;
3022              last INSCOPE;              last INSCOPE;
3023            } else { # in open elements but not in scope            } else { # in open elements but not in scope
3024                !!!cp ('t55');
3025              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3026              ## Ignore the token              ## Ignore the token
3027              !!!next-token;              !!!next-token;
# Line 2637  sub _tree_construction_main ($) { Line 3031  sub _tree_construction_main ($) {
3031                    table => 1, caption => 1, td => 1, th => 1,                    table => 1, caption => 1, td => 1, th => 1,
3032                    button => 1, marquee => 1, object => 1, html => 1,                    button => 1, marquee => 1, object => 1, html => 1,
3033                   }->{$node->[1]}) {                   }->{$node->[1]}) {
3034              !!!cp ('t56');
3035            $in_scope = 0;            $in_scope = 0;
3036          }          }
3037        } # INSCOPE        } # INSCOPE
3038        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
3039            !!!cp ('t57');
3040          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3041          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
3042          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
3043          return;          return;
3044        }        }
3045        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
3046            !!!cp ('t58');
3047          !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);          !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3048        }        }
3049                
# Line 2659  sub _tree_construction_main ($) { Line 3056  sub _tree_construction_main ($) {
3056              #not $phrasing_category->{$node->[1]} and              #not $phrasing_category->{$node->[1]} and
3057              ($special_category->{$node->[1]} or              ($special_category->{$node->[1]} or
3058               $scoping_category->{$node->[1]})) {               $scoping_category->{$node->[1]})) {
3059              !!!cp ('t59');
3060            $furthest_block = $node;            $furthest_block = $node;
3061            $furthest_block_i_in_open = $_;            $furthest_block_i_in_open = $_;
3062          } elsif ($node->[0] eq $formatting_element->[0]) {          } elsif ($node->[0] eq $formatting_element->[0]) {
3063              !!!cp ('t60');
3064            last OE;            last OE;
3065          }          }
3066        } # OE        } # OE
3067                
3068        ## Step 3        ## Step 3
3069        unless (defined $furthest_block) { # MUST        unless (defined $furthest_block) { # MUST
3070            !!!cp ('t61');
3071          splice @{$self->{open_elements}}, $formatting_element_i_in_open;          splice @{$self->{open_elements}}, $formatting_element_i_in_open;
3072          splice @$active_formatting_elements, $formatting_element_i_in_active, 1;          splice @$active_formatting_elements, $formatting_element_i_in_active, 1;
3073          !!!next-token;          !!!next-token;
# Line 2680  sub _tree_construction_main ($) { Line 3080  sub _tree_construction_main ($) {
3080        ## Step 5        ## Step 5
3081        my $furthest_block_parent = $furthest_block->[0]->parent_node;        my $furthest_block_parent = $furthest_block->[0]->parent_node;
3082        if (defined $furthest_block_parent) {        if (defined $furthest_block_parent) {
3083            !!!cp ('t62');
3084          $furthest_block_parent->remove_child ($furthest_block->[0]);          $furthest_block_parent->remove_child ($furthest_block->[0]);
3085        }        }
3086                
# Line 2702  sub _tree_construction_main ($) { Line 3103  sub _tree_construction_main ($) {
3103          S7S2: {          S7S2: {
3104            for (reverse 0..$#$active_formatting_elements) {            for (reverse 0..$#$active_formatting_elements) {
3105              if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {              if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {
3106                  !!!cp ('t63');
3107                $node_i_in_active = $_;                $node_i_in_active = $_;
3108                last S7S2;                last S7S2;
3109              }              }
# Line 2715  sub _tree_construction_main ($) { Line 3117  sub _tree_construction_main ($) {
3117                    
3118          ## Step 4          ## Step 4
3119          if ($last_node->[0] eq $furthest_block->[0]) {          if ($last_node->[0] eq $furthest_block->[0]) {
3120              !!!cp ('t64');
3121            $bookmark_prev_el = $node->[0];            $bookmark_prev_el = $node->[0];
3122          }          }
3123                    
3124          ## Step 5          ## Step 5
3125          if ($node->[0]->has_child_nodes ()) {          if ($node->[0]->has_child_nodes ()) {
3126              !!!cp ('t65');
3127            my $clone = [$node->[0]->clone_node (0), $node->[1]];            my $clone = [$node->[0]->clone_node (0), $node->[1]];
3128            $active_formatting_elements->[$node_i_in_active] = $clone;            $active_formatting_elements->[$node_i_in_active] = $clone;
3129            $self->{open_elements}->[$node_i_in_open] = $clone;            $self->{open_elements}->[$node_i_in_open] = $clone;
# Line 2754  sub _tree_construction_main ($) { Line 3158  sub _tree_construction_main ($) {
3158        my $i;        my $i;
3159        AFE: for (reverse 0..$#$active_formatting_elements) {        AFE: for (reverse 0..$#$active_formatting_elements) {
3160          if ($active_formatting_elements->[$_]->[0] eq $formatting_element->[0]) {          if ($active_formatting_elements->[$_]->[0] eq $formatting_element->[0]) {
3161              !!!cp ('t66');
3162            splice @$active_formatting_elements, $_, 1;            splice @$active_formatting_elements, $_, 1;
3163            $i-- and last AFE if defined $i;            $i-- and last AFE if defined $i;
3164          } elsif ($active_formatting_elements->[$_]->[0] eq $bookmark_prev_el) {          } elsif ($active_formatting_elements->[$_]->[0] eq $bookmark_prev_el) {
3165              !!!cp ('t67');
3166            $i = $_;            $i = $_;
3167          }          }
3168        } # AFE        } # AFE
# Line 2766  sub _tree_construction_main ($) { Line 3172  sub _tree_construction_main ($) {
3172        undef $i;        undef $i;
3173        OE: for (reverse 0..$#{$self->{open_elements}}) {        OE: for (reverse 0..$#{$self->{open_elements}}) {
3174          if ($self->{open_elements}->[$_]->[0] eq $formatting_element->[0]) {          if ($self->{open_elements}->[$_]->[0] eq $formatting_element->[0]) {
3175              !!!cp ('t68');
3176            splice @{$self->{open_elements}}, $_, 1;            splice @{$self->{open_elements}}, $_, 1;
3177            $i-- and last OE if defined $i;            $i-- and last OE if defined $i;
3178          } elsif ($self->{open_elements}->[$_]->[0] eq $furthest_block->[0]) {          } elsif ($self->{open_elements}->[$_]->[0] eq $furthest_block->[0]) {
3179              !!!cp ('t69');
3180            $i = $_;            $i = $_;
3181          }          }
3182        } # OE        } # OE
# Line 2796  sub _tree_construction_main ($) { Line 3204  sub _tree_construction_main ($) {
3204                             if ($self->{open_elements}->[$_]->[1] eq 'table') {                             if ($self->{open_elements}->[$_]->[1] eq 'table') {
3205                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
3206                               if (defined $parent and $parent->node_type == 1) {                               if (defined $parent and $parent->node_type == 1) {
3207                                   !!!cp ('t70');
3208                                 $foster_parent_element = $parent;                                 $foster_parent_element = $parent;
3209                                 $next_sibling = $self->{open_elements}->[$_]->[0];                                 $next_sibling = $self->{open_elements}->[$_]->[0];
3210                               } else {                               } else {
3211                                   !!!cp ('t71');
3212                                 $foster_parent_element                                 $foster_parent_element
3213                                   = $self->{open_elements}->[$_ - 1]->[0];                                   = $self->{open_elements}->[$_ - 1]->[0];
3214                               }                               }
# Line 2810  sub _tree_construction_main ($) { Line 3220  sub _tree_construction_main ($) {
3220                           $foster_parent_element->insert_before                           $foster_parent_element->insert_before
3221                             ($child, $next_sibling);                             ($child, $next_sibling);
3222                         } else {                         } else {
3223                             !!!cp ('t72');
3224                           $self->{open_elements}->[-1]->[0]->append_child ($child);                           $self->{open_elements}->[-1]->[0]->append_child ($child);
3225                         }                         }
3226    }; # $insert_to_foster    }; # $insert_to_foster
# Line 2818  sub _tree_construction_main ($) { Line 3229  sub _tree_construction_main ($) {
3229    
3230    B: {    B: {
3231      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
3232          !!!cp ('t73');
3233        !!!parse-error (type => 'DOCTYPE in the middle');        !!!parse-error (type => 'DOCTYPE in the middle');
3234        ## Ignore the token        ## Ignore the token
3235        ## Stay in the phase        ## Stay in the phase
# Line 2825  sub _tree_construction_main ($) { Line 3237  sub _tree_construction_main ($) {
3237        redo B;        redo B;
3238      } elsif ($token->{type} == END_OF_FILE_TOKEN) {      } elsif ($token->{type} == END_OF_FILE_TOKEN) {
3239        if ($self->{insertion_mode} & AFTER_HTML_IMS) {        if ($self->{insertion_mode} & AFTER_HTML_IMS) {
3240            !!!cp ('t74');
3241          #          #
3242        } else {        } else {
3243          ## Generate implied end tags          ## Generate implied end tags
# Line 2832  sub _tree_construction_main ($) { Line 3245  sub _tree_construction_main ($) {
3245               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,
3246               tbody => 1, tfoot=> 1, thead => 1,               tbody => 1, tfoot=> 1, thead => 1,
3247              }->{$self->{open_elements}->[-1]->[1]}) {              }->{$self->{open_elements}->[-1]->[1]}) {
3248              !!!cp ('t75');
3249            !!!back-token;            !!!back-token;
3250            $token = {type => END_TAG_TOKEN, tag_name => $self->{open_elements}->[-1]->[1]};            $token = {type => END_TAG_TOKEN, tag_name => $self->{open_elements}->[-1]->[1]};
3251            redo B;            redo B;
# Line 2839  sub _tree_construction_main ($) { Line 3253  sub _tree_construction_main ($) {
3253                    
3254          if (@{$self->{open_elements}} > 2 or          if (@{$self->{open_elements}} > 2 or
3255              (@{$self->{open_elements}} == 2 and $self->{open_elements}->[1]->[1] ne 'body')) {              (@{$self->{open_elements}} == 2 and $self->{open_elements}->[1]->[1] ne 'body')) {
3256              !!!cp ('t76');
3257            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3258          } elsif (defined $self->{inner_html_node} and          } elsif (defined $self->{inner_html_node} and
3259                   @{$self->{open_elements}} > 1 and                   @{$self->{open_elements}} > 1 and
3260                   $self->{open_elements}->[1]->[1] ne 'body') {                   $self->{open_elements}->[1]->[1] ne 'body') {
3261    ## ISSUE: This case is never reached.
3262              !!!cp ('t77');
3263            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3264            } else {
3265              !!!cp ('t78');
3266          }          }
3267    
3268          ## ISSUE: There is an issue in the spec.          ## ISSUE: There is an issue in the spec.
# Line 2854  sub _tree_construction_main ($) { Line 3273  sub _tree_construction_main ($) {
3273      } elsif ($token->{type} == START_TAG_TOKEN and      } elsif ($token->{type} == START_TAG_TOKEN and
3274               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
3275        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
3276            !!!cp ('t79');
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_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
3280        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
3281            !!!cp ('t80');
3282          ## Turn into the main phase          ## Turn into the main phase
3283          !!!parse-error (type => 'after html:html');          !!!parse-error (type => 'after html:html');
3284          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
3285          } else {
3286            !!!cp ('t81');
3287        }        }
3288    
3289  ## ISSUE: "aa<html>" is not a parse error.  ## ISSUE: "aa<html>" is not a parse error.
3290  ## ISSUE: "<html>" in fragment is not a parse error.  ## ISSUE: "<html>" in fragment is not a parse error.
3291        unless ($token->{first_start_tag}) {        unless ($token->{first_start_tag}) {
3292            !!!cp ('t82');
3293          !!!parse-error (type => 'not first start tag');          !!!parse-error (type => 'not first start tag');
3294          } else {
3295            !!!cp ('t83');
3296        }        }
3297        my $top_el = $self->{open_elements}->[0]->[0];        my $top_el = $self->{open_elements}->[0]->[0];
3298        for my $attr_name (keys %{$token->{attributes}}) {        for my $attr_name (keys %{$token->{attributes}}) {
3299          unless ($top_el->has_attribute_ns (undef, $attr_name)) {          unless ($top_el->has_attribute_ns (undef, $attr_name)) {
3300              !!!cp ('t84');
3301            $top_el->set_attribute_ns            $top_el->set_attribute_ns
3302              (undef, [undef, $attr_name],              (undef, [undef, $attr_name],
3303               $token->{attributes}->{$attr_name}->{value});               $token->{attributes}->{$attr_name}->{value});
# Line 2881  sub _tree_construction_main ($) { Line 3308  sub _tree_construction_main ($) {
3308      } elsif ($token->{type} == COMMENT_TOKEN) {      } elsif ($token->{type} == COMMENT_TOKEN) {
3309        my $comment = $self->{document}->create_comment ($token->{data});        my $comment = $self->{document}->create_comment ($token->{data});
3310        if ($self->{insertion_mode} & AFTER_HTML_IMS) {        if ($self->{insertion_mode} & AFTER_HTML_IMS) {
3311            !!!cp ('t85');
3312          $self->{document}->append_child ($comment);          $self->{document}->append_child ($comment);
3313        } elsif ($self->{insertion_mode} == AFTER_BODY_IM) {        } elsif ($self->{insertion_mode} == AFTER_BODY_IM) {
3314            !!!cp ('t86');
3315          $self->{open_elements}->[0]->[0]->append_child ($comment);          $self->{open_elements}->[0]->[0]->append_child ($comment);
3316        } else {        } else {
3317            !!!cp ('t87');
3318          $self->{open_elements}->[-1]->[0]->append_child ($comment);          $self->{open_elements}->[-1]->[0]->append_child ($comment);
3319        }        }
3320        !!!next-token;        !!!next-token;
# Line 2894  sub _tree_construction_main ($) { Line 3324  sub _tree_construction_main ($) {
3324          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3325            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
3326            unless (length $token->{data}) {            unless (length $token->{data}) {
3327                !!!cp ('t88');
3328              !!!next-token;              !!!next-token;
3329              redo B;              redo B;
3330            }            }
3331          }          }
3332    
3333          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3334              !!!cp ('t89');
3335            ## As if <head>            ## As if <head>
3336            !!!create-element ($self->{head_element}, 'head');            !!!create-element ($self->{head_element}, 'head');
3337            $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});            $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 2910  sub _tree_construction_main ($) { Line 3342  sub _tree_construction_main ($) {
3342    
3343            ## Reprocess in the "after head" insertion mode...            ## Reprocess in the "after head" insertion mode...
3344          } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {          } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3345              !!!cp ('t90');
3346            ## As if </noscript>            ## As if </noscript>
3347            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
3348            !!!parse-error (type => 'in noscript:#character');            !!!parse-error (type => 'in noscript:#character');
# Line 2920  sub _tree_construction_main ($) { Line 3353  sub _tree_construction_main ($) {
3353    
3354            ## Reprocess in the "after head" insertion mode...            ## Reprocess in the "after head" insertion mode...
3355          } elsif ($self->{insertion_mode} == IN_HEAD_IM) {          } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3356              !!!cp ('t91');
3357            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
3358    
3359            ## Reprocess in the "after head" insertion mode...            ## Reprocess in the "after head" insertion mode...
3360            } else {
3361              !!!cp ('t92');
3362          }          }
3363    
3364              ## "after head" insertion mode              ## "after head" insertion mode
# Line 2934  sub _tree_construction_main ($) { Line 3370  sub _tree_construction_main ($) {
3370            } elsif ($token->{type} == START_TAG_TOKEN) {            } elsif ($token->{type} == START_TAG_TOKEN) {
3371              if ($token->{tag_name} eq 'head') {              if ($token->{tag_name} eq 'head') {
3372                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3373                    !!!cp ('t93');
3374                  !!!create-element ($self->{head_element}, $token->{tag_name}, $token->{attributes});                  !!!create-element ($self->{head_element}, $token->{tag_name}, $token->{attributes});
3375                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
3376                  push @{$self->{open_elements}}, [$self->{head_element}, $token->{tag_name}];                  push @{$self->{open_elements}}, [$self->{head_element}, $token->{tag_name}];
# Line 2941  sub _tree_construction_main ($) { Line 3378  sub _tree_construction_main ($) {
3378                  !!!next-token;                  !!!next-token;
3379                  redo B;                  redo B;
3380                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
3381                    !!!cp ('t94');
3382                  #                  #
3383                } else {                } else {
3384                    !!!cp ('t95');
3385                  !!!parse-error (type => 'in head:head'); # or in head noscript                  !!!parse-error (type => 'in head:head'); # or in head noscript
3386                  ## Ignore the token                  ## Ignore the token
3387                  !!!next-token;                  !!!next-token;
3388                  redo B;                  redo B;
3389                }                }
3390              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3391                  !!!cp ('t96');
3392                ## As if <head>                ## As if <head>
3393                !!!create-element ($self->{head_element}, 'head');                !!!create-element ($self->{head_element}, 'head');
3394                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 2956  sub _tree_construction_main ($) { Line 3396  sub _tree_construction_main ($) {
3396    
3397                $self->{insertion_mode} = IN_HEAD_IM;                $self->{insertion_mode} = IN_HEAD_IM;
3398                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
3399                } else {
3400                  !!!cp ('t97');
3401              }              }
3402    
3403              if ($token->{tag_name} eq 'base') {              if ($token->{tag_name} eq 'base') {
3404                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3405                    !!!cp ('t98');
3406                  ## As if </noscript>                  ## As if </noscript>
3407                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3408                  !!!parse-error (type => 'in noscript:base');                  !!!parse-error (type => 'in noscript:base');
3409                                
3410                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3411                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3412                  } else {
3413                    !!!cp ('t99');
3414                }                }
3415    
3416                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3417                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3418                    !!!cp ('t100');
3419                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3420                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3421                  } else {
3422                    !!!cp ('t101');
3423                }                }
3424                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3425                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 2982  sub _tree_construction_main ($) { Line 3430  sub _tree_construction_main ($) {
3430              } elsif ($token->{tag_name} eq 'link') {              } elsif ($token->{tag_name} eq 'link') {
3431                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3432                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3433                    !!!cp ('t102');
3434                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3435                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3436                  } else {
3437                    !!!cp ('t103');
3438                }                }
3439                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3440                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 2994  sub _tree_construction_main ($) { Line 3445  sub _tree_construction_main ($) {
3445              } elsif ($token->{tag_name} eq 'meta') {              } elsif ($token->{tag_name} eq 'meta') {
3446                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3447                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3448                    !!!cp ('t104');
3449                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3450                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3451                  } else {
3452                    !!!cp ('t105');
3453                }                }
3454                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3455                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.
3456    
3457                unless ($self->{confident}) {                unless ($self->{confident}) {
3458                  if ($token->{attributes}->{charset}) { ## TODO: And if supported                  if ($token->{attributes}->{charset}) { ## TODO: And if supported
3459                      !!!cp ('t106');
3460                    $self->{change_encoding}                    $self->{change_encoding}
3461                        ->($self, $token->{attributes}->{charset}->{value});                        ->($self, $token->{attributes}->{charset}->{value});
3462                                        
# Line 3016  sub _tree_construction_main ($) { Line 3471  sub _tree_construction_main ($) {
3471                            [\x09-\x0D\x20]*=                            [\x09-\x0D\x20]*=
3472                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
3473                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
3474                        !!!cp ('t107');
3475                      $self->{change_encoding}                      $self->{change_encoding}
3476                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);
3477                      $meta_el->[0]->get_attribute_node_ns (undef, 'content')                      $meta_el->[0]->get_attribute_node_ns (undef, 'content')
3478                          ->set_user_data (manakai_has_reference =>                          ->set_user_data (manakai_has_reference =>
3479                                               $token->{attributes}->{content}                                               $token->{attributes}->{content}
3480                                                     ->{has_reference});                                                     ->{has_reference});
3481                      } else {
3482                        !!!cp ('t108');
3483                    }                    }
3484                  }                  }
3485                } else {                } else {
3486                  if ($token->{attributes}->{charset}) {                  if ($token->{attributes}->{charset}) {
3487                      !!!cp ('t109');
3488                    $meta_el->[0]->get_attribute_node_ns (undef, 'charset')                    $meta_el->[0]->get_attribute_node_ns (undef, 'charset')
3489                        ->set_user_data (manakai_has_reference =>                        ->set_user_data (manakai_has_reference =>
3490                                             $token->{attributes}->{charset}                                             $token->{attributes}->{charset}
3491                                                 ->{has_reference});                                                 ->{has_reference});
3492                  }                  }
3493                  if ($token->{attributes}->{content}) {                  if ($token->{attributes}->{content}) {
3494                      !!!cp ('t110');
3495                    $meta_el->[0]->get_attribute_node_ns (undef, 'content')                    $meta_el->[0]->get_attribute_node_ns (undef, 'content')
3496                        ->set_user_data (manakai_has_reference =>                        ->set_user_data (manakai_has_reference =>
3497                                             $token->{attributes}->{content}                                             $token->{attributes}->{content}
# Line 3045  sub _tree_construction_main ($) { Line 3505  sub _tree_construction_main ($) {
3505                redo B;                redo B;
3506              } elsif ($token->{tag_name} eq 'title') {              } elsif ($token->{tag_name} eq 'title') {
3507                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3508                    !!!cp ('t111');
3509                  ## As if </noscript>                  ## As if </noscript>
3510                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3511                  !!!parse-error (type => 'in noscript:title');                  !!!parse-error (type => 'in noscript:title');
# Line 3052  sub _tree_construction_main ($) { Line 3513  sub _tree_construction_main ($) {
3513                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3514                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3515                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
3516                    !!!cp ('t112');
3517                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3518                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3519                  } else {
3520                    !!!cp ('t113');
3521                }                }
3522    
3523                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
# Line 3069  sub _tree_construction_main ($) { Line 3533  sub _tree_construction_main ($) {
3533                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
3534                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3535                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3536                    !!!cp ('t114');
3537                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3538                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3539                  } else {
3540                    !!!cp ('t115');
3541                }                }
3542                $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);                $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);
3543                pop @{$self->{open_elements}}                pop @{$self->{open_elements}}
# Line 3078  sub _tree_construction_main ($) { Line 3545  sub _tree_construction_main ($) {
3545                redo B;                redo B;
3546              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
3547                if ($self->{insertion_mode} == IN_HEAD_IM) {                if ($self->{insertion_mode} == IN_HEAD_IM) {
3548                    !!!cp ('t116');
3549                  ## NOTE: and scripting is disalbed                  ## NOTE: and scripting is disalbed
3550                  !!!insert-element ($token->{tag_name}, $token->{attributes});                  !!!insert-element ($token->{tag_name}, $token->{attributes});
3551                  $self->{insertion_mode} = IN_HEAD_NOSCRIPT_IM;                  $self->{insertion_mode} = IN_HEAD_NOSCRIPT_IM;
3552                  !!!next-token;                  !!!next-token;
3553                  redo B;                  redo B;
3554                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3555                    !!!cp ('t117');
3556                  !!!parse-error (type => 'in noscript:noscript');                  !!!parse-error (type => 'in noscript:noscript');
3557                  ## Ignore the token                  ## Ignore the token
3558                  !!!next-token;                  !!!next-token;
3559                  redo B;                  redo B;
3560                } else {                } else {
3561                    !!!cp ('t118');
3562                  #                  #
3563                }                }
3564              } elsif ($token->{tag_name} eq 'script') {              } elsif ($token->{tag_name} eq 'script') {
3565                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3566                    !!!cp ('t119');
3567                  ## As if </noscript>                  ## As if </noscript>
3568                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3569                  !!!parse-error (type => 'in noscript:script');                  !!!parse-error (type => 'in noscript:script');
# Line 3100  sub _tree_construction_main ($) { Line 3571  sub _tree_construction_main ($) {
3571                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3572                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3573                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
3574                    !!!cp ('t120');
3575                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3576                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3577                  } else {
3578                    !!!cp ('t121');
3579                }                }
3580    
3581                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
# Line 3112  sub _tree_construction_main ($) { Line 3586  sub _tree_construction_main ($) {
3586              } elsif ($token->{tag_name} eq 'body' or              } elsif ($token->{tag_name} eq 'body' or
3587                       $token->{tag_name} eq 'frameset') {                       $token->{tag_name} eq 'frameset') {
3588                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3589                    !!!cp ('t122');
3590                  ## As if </noscript>                  ## As if </noscript>
3591                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3592                  !!!parse-error (type => 'in noscript:'.$token->{tag_name});                  !!!parse-error (type => 'in noscript:'.$token->{tag_name});
# Line 3122  sub _tree_construction_main ($) { Line 3597  sub _tree_construction_main ($) {
3597                                    
3598                  ## Reprocess in the "after head" insertion mode...                  ## Reprocess in the "after head" insertion mode...
3599                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3600                    !!!cp ('t124');
3601                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3602                                    
3603                  ## Reprocess in the "after head" insertion mode...                  ## Reprocess in the "after head" insertion mode...
3604                  } else {
3605                    !!!cp ('t125');
3606                }                }
3607    
3608                ## "after head" insertion mode                ## "after head" insertion mode
3609                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3610                if ($token->{tag_name} eq 'body') {                if ($token->{tag_name} eq 'body') {
3611                    !!!cp ('t126');
3612                  $self->{insertion_mode} = IN_BODY_IM;                  $self->{insertion_mode} = IN_BODY_IM;
3613                } elsif ($token->{tag_name} eq 'frameset') {                } elsif ($token->{tag_name} eq 'frameset') {
3614                    !!!cp ('t127');
3615                  $self->{insertion_mode} = IN_FRAMESET_IM;                  $self->{insertion_mode} = IN_FRAMESET_IM;
3616                } else {                } else {
3617                  die "$0: tag name: $self->{tag_name}";                  die "$0: tag name: $self->{tag_name}";
# Line 3139  sub _tree_construction_main ($) { Line 3619  sub _tree_construction_main ($) {
3619                !!!next-token;                !!!next-token;
3620                redo B;                redo B;
3621              } else {              } else {
3622                  !!!cp ('t128');
3623                #                #
3624              }              }
3625    
3626              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3627                  !!!cp ('t129');
3628                ## As if </noscript>                ## As if </noscript>
3629                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3630                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});
# Line 3153  sub _tree_construction_main ($) { Line 3635  sub _tree_construction_main ($) {
3635    
3636                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3637              } elsif ($self->{insertion_mode} == IN_HEAD_IM) {              } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3638                  !!!cp ('t130');
3639                ## As if </head>                ## As if </head>
3640                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3641    
3642                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3643                } else {
3644                  !!!cp ('t131');
3645              }              }
3646    
3647              ## "after head" insertion mode              ## "after head" insertion mode
# Line 3168  sub _tree_construction_main ($) { Line 3653  sub _tree_construction_main ($) {
3653            } elsif ($token->{type} == END_TAG_TOKEN) {            } elsif ($token->{type} == END_TAG_TOKEN) {
3654              if ($token->{tag_name} eq 'head') {              if ($token->{tag_name} eq 'head') {
3655                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3656                    !!!cp ('t132');
3657                  ## As if <head>                  ## As if <head>
3658                  !!!create-element ($self->{head_element}, 'head');                  !!!create-element ($self->{head_element}, 'head');
3659                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3179  sub _tree_construction_main ($) { Line 3665  sub _tree_construction_main ($) {
3665                  !!!next-token;                  !!!next-token;
3666                  redo B;                  redo B;
3667                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3668                    !!!cp ('t133');
3669                  ## As if </noscript>                  ## As if </noscript>
3670                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3671                  !!!parse-error (type => 'in noscript:script');                  !!!parse-error (type => 'in noscript:/head');
3672                                    
3673                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3674                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 3189  sub _tree_construction_main ($) { Line 3676  sub _tree_construction_main ($) {
3676                  !!!next-token;                  !!!next-token;
3677                  redo B;                  redo B;
3678                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3679                    !!!cp ('t134');
3680                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3681                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
3682                  !!!next-token;                  !!!next-token;
3683                  redo B;                  redo B;
3684                } else {                } else {
3685                    !!!cp ('t135');
3686                  #                  #
3687                }                }
3688              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
3689                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3690                    !!!cp ('t136');
3691                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3692                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3693                  !!!next-token;                  !!!next-token;
3694                  redo B;                  redo B;
3695                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3696                    !!!cp ('t137');
3697                  !!!parse-error (type => 'unmatched end tag:noscript');                  !!!parse-error (type => 'unmatched end tag:noscript');
3698                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
3699                  !!!next-token;                  !!!next-token;
3700                  redo B;                  redo B;
3701                } else {                } else {
3702                    !!!cp ('t138');
3703                  #                  #
3704                }                }
3705              } elsif ({              } elsif ({
3706                        body => 1, html => 1,                        body => 1, html => 1,
3707                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
3708                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3709                    !!!cp ('t139');
3710                  ## As if <head>                  ## As if <head>
3711                  !!!create-element ($self->{head_element}, 'head');                  !!!create-element ($self->{head_element}, 'head');
3712                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3222  sub _tree_construction_main ($) { Line 3715  sub _tree_construction_main ($) {
3715                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3716                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3717                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3718                    !!!cp ('t140');
3719                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3720                  ## Ignore the token                  ## Ignore the token
3721                  !!!next-token;                  !!!next-token;
3722                  redo B;                  redo B;
3723                  } else {
3724                    !!!cp ('t141');
3725                }                }
3726                                
3727                #                #
# Line 3233  sub _tree_construction_main ($) { Line 3729  sub _tree_construction_main ($) {
3729                        p => 1, br => 1,                        p => 1, br => 1,
3730                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
3731                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3732                    !!!cp ('t142');
3733                  ## As if <head>                  ## As if <head>
3734                  !!!create-element ($self->{head_element}, 'head');                  !!!create-element ($self->{head_element}, 'head');
3735                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3240  sub _tree_construction_main ($) { Line 3737  sub _tree_construction_main ($) {
3737    
3738                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3739                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3740                  } else {
3741                    !!!cp ('t143');
3742                }                }
3743    
3744                #                #
3745              } else {              } else {
3746                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3747                    !!!cp ('t144');
3748                  #                  #
3749                } else {                } else {
3750                    !!!cp ('t145');
3751                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3752                  ## Ignore the token                  ## Ignore the token
3753                  !!!next-token;                  !!!next-token;
# Line 3255  sub _tree_construction_main ($) { Line 3756  sub _tree_construction_main ($) {
3756              }              }
3757    
3758              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3759                  !!!cp ('t146');
3760                ## As if </noscript>                ## As if </noscript>
3761                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3762                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});
# Line 3265  sub _tree_construction_main ($) { Line 3767  sub _tree_construction_main ($) {
3767    
3768                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3769              } elsif ($self->{insertion_mode} == IN_HEAD_IM) {              } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3770                  !!!cp ('t147');
3771                ## As if </head>                ## As if </head>
3772                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3773    
3774                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3775              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3776    ## ISSUE: This case cannot be reached?
3777                  !!!cp ('t148');
3778                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3779                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
3780                !!!next-token;                !!!next-token;
3781                redo B;                redo B;
3782                } else {
3783                  !!!cp ('t149');
3784              }              }
3785    
3786              ## "after head" insertion mode              ## "after head" insertion mode
# Line 3289  sub _tree_construction_main ($) { Line 3796  sub _tree_construction_main ($) {
3796            ## ISSUE: An issue in the spec.            ## ISSUE: An issue in the spec.
3797      } elsif ($self->{insertion_mode} & BODY_IMS) {      } elsif ($self->{insertion_mode} & BODY_IMS) {
3798            if ($token->{type} == CHARACTER_TOKEN) {            if ($token->{type} == CHARACTER_TOKEN) {
3799                !!!cp ('t150');
3800              ## NOTE: There is a code clone of "character in body".              ## NOTE: There is a code clone of "character in body".
3801              $reconstruct_active_formatting_elements->($insert_to_current);              $reconstruct_active_formatting_elements->($insert_to_current);
3802                            
# Line 3307  sub _tree_construction_main ($) { Line 3815  sub _tree_construction_main ($) {
3815                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3816                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
3817                    if ($node->[1] eq 'td' or $node->[1] eq 'th') {                    if ($node->[1] eq 'td' or $node->[1] eq 'th') {
3818                        !!!cp ('t151');
3819                      $tn = $node->[1];                      $tn = $node->[1];
3820                      last INSCOPE;                      last INSCOPE;
3821                    } elsif ({                    } elsif ({
3822                              table => 1, html => 1,                              table => 1, html => 1,
3823                             }->{$node->[1]}) {                             }->{$node->[1]}) {
3824                        !!!cp ('t152');
3825                      last INSCOPE;                      last INSCOPE;
3826                    }                    }
3827                  } # INSCOPE                  } # INSCOPE
3828                    unless (defined $tn) {                    unless (defined $tn) {
3829                        !!!cp ('t153');
3830    ## TODO: This error type is wrong.
3831                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3832                      ## Ignore the token                      ## Ignore the token
3833                      !!!next-token;                      !!!next-token;
3834                      redo B;                      redo B;
3835                    }                    }
3836                                    
3837                    !!!cp ('t154');
3838                  ## Close the cell                  ## Close the cell
3839                  !!!back-token; # <?>                  !!!back-token; # <?>
3840                  $token = {type => END_TAG_TOKEN, tag_name => $tn};                  $token = {type => END_TAG_TOKEN, tag_name => $tn};
# Line 3335  sub _tree_construction_main ($) { Line 3848  sub _tree_construction_main ($) {
3848                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3849                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
3850                    if ($node->[1] eq 'caption') {                    if ($node->[1] eq 'caption') {
3851                        !!!cp ('t155');
3852                      $i = $_;                      $i = $_;
3853                      last INSCOPE;                      last INSCOPE;
3854                    } elsif ({                    } elsif ({
3855                              table => 1, html => 1,                              table => 1, html => 1,
3856                             }->{$node->[1]}) {                             }->{$node->[1]}) {
3857                        !!!cp ('t156');
3858                      last INSCOPE;                      last INSCOPE;
3859                    }                    }
3860                  } # INSCOPE                  } # INSCOPE
3861                    unless (defined $i) {                    unless (defined $i) {
3862                        !!!cp ('t157');
3863    ## TODO: this type is wrong.
3864                      !!!parse-error (type => 'unmatched end tag:caption');                      !!!parse-error (type => 'unmatched end tag:caption');
3865                      ## Ignore the token                      ## Ignore the token
3866                      !!!next-token;                      !!!next-token;
# Line 3353  sub _tree_construction_main ($) { Line 3870  sub _tree_construction_main ($) {
3870                  ## generate implied end tags                  ## generate implied end tags
3871                  if ({                  if ({
3872                       dd => 1, dt => 1, li => 1, p => 1,                       dd => 1, dt => 1, li => 1, p => 1,
3873    
3874                         ## NOTE: Maybe the following elements never appear here.
3875                       td => 1, th => 1, tr => 1,                       td => 1, th => 1, tr => 1,
3876                       tbody => 1, tfoot=> 1, thead => 1,                       tbody => 1, tfoot => 1, thead => 1,
3877                      }->{$self->{open_elements}->[-1]->[1]}) {                      }->{$self->{open_elements}->[-1]->[1]}) {
3878                      !!!cp ('t158');
3879                    !!!back-token; # <?>                    !!!back-token; # <?>
3880                    $token = {type => END_TAG_TOKEN, tag_name => 'caption'};                    $token = {type => END_TAG_TOKEN, tag_name => 'caption'};
3881                    !!!back-token;                    !!!back-token;
# Line 3365  sub _tree_construction_main ($) { Line 3885  sub _tree_construction_main ($) {
3885                  }                  }
3886    
3887                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
3888                      !!!cp ('t159');
3889                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3890                    } else {
3891                      !!!cp ('t160');
3892                  }                  }
3893                                    
3894                  splice @{$self->{open_elements}}, $i;                  splice @{$self->{open_elements}}, $i;
# Line 3377  sub _tree_construction_main ($) { Line 3900  sub _tree_construction_main ($) {
3900                  ## reprocess                  ## reprocess
3901                  redo B;                  redo B;
3902                } else {                } else {
3903                    !!!cp ('t161');
3904                  #                  #
3905                }                }
3906              } else {              } else {
3907                  !!!cp ('t162');
3908                #                #
3909              }              }
3910            } elsif ($token->{type} == END_TAG_TOKEN) {            } elsif ($token->{type} == END_TAG_TOKEN) {
# Line 3390  sub _tree_construction_main ($) { Line 3915  sub _tree_construction_main ($) {
3915                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3916                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
3917                    if ($node->[1] eq $token->{tag_name}) {                    if ($node->[1] eq $token->{tag_name}) {
3918                        !!!cp ('t163');
3919                      $i = $_;                      $i = $_;
3920                      last INSCOPE;                      last INSCOPE;
3921                    } elsif ({                    } elsif ({
3922                              table => 1, html => 1,                              table => 1, html => 1,
3923                             }->{$node->[1]}) {                             }->{$node->[1]}) {
3924                        !!!cp ('t164');
3925                      last INSCOPE;                      last INSCOPE;
3926                    }                    }
3927                  } # INSCOPE                  } # INSCOPE
3928                    unless (defined $i) {                    unless (defined $i) {
3929                        !!!cp ('t165');
3930                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3931                      ## Ignore the token                      ## Ignore the token
3932                      !!!next-token;                      !!!next-token;
# Line 3410  sub _tree_construction_main ($) { Line 3938  sub _tree_construction_main ($) {
3938                       dd => 1, dt => 1, li => 1, p => 1,                       dd => 1, dt => 1, li => 1, p => 1,
3939                       td => ($token->{tag_name} eq 'th'),                       td => ($token->{tag_name} eq 'th'),
3940                       th => ($token->{tag_name} eq 'td'),                       th => ($token->{tag_name} eq 'td'),
3941    
3942                         ## NOTE: Maybe the following elements never appear here.
3943                       tr => 1,                       tr => 1,
3944                       tbody => 1, tfoot=> 1, thead => 1,                       tbody => 1, tfoot => 1, thead => 1,
3945                      }->{$self->{open_elements}->[-1]->[1]}) {                      }->{$self->{open_elements}->[-1]->[1]}) {
3946                      !!!cp ('t166');
3947                    !!!back-token;                    !!!back-token;
3948                    $token = {type => END_TAG_TOKEN,                    $token = {type => END_TAG_TOKEN,
3949                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
# Line 3420  sub _tree_construction_main ($) { Line 3951  sub _tree_construction_main ($) {
3951                  }                  }
3952                                    
3953                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
3954                      !!!cp ('t167');
3955                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3956                    } else {
3957                      !!!cp ('t168');
3958                  }                  }
3959                                    
3960                  splice @{$self->{open_elements}}, $i;                  splice @{$self->{open_elements}}, $i;
# Line 3432  sub _tree_construction_main ($) { Line 3966  sub _tree_construction_main ($) {
3966                  !!!next-token;                  !!!next-token;
3967                  redo B;                  redo B;
3968                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
3969                    !!!cp ('t169');
3970                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3971                  ## Ignore the token                  ## Ignore the token
3972                  !!!next-token;                  !!!next-token;
3973                  redo B;                  redo B;
3974                } else {                } else {
3975                    !!!cp ('t170');
3976                  #                  #
3977                }                }
3978              } elsif ($token->{tag_name} eq 'caption') {              } elsif ($token->{tag_name} eq 'caption') {
# Line 3446  sub _tree_construction_main ($) { Line 3982  sub _tree_construction_main ($) {
3982                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3983                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
3984                    if ($node->[1] eq $token->{tag_name}) {                    if ($node->[1] eq $token->{tag_name}) {
3985                        !!!cp ('t171');
3986                      $i = $_;                      $i = $_;
3987                      last INSCOPE;                      last INSCOPE;
3988                    } elsif ({                    } elsif ({
3989                              table => 1, html => 1,                              table => 1, html => 1,
3990                             }->{$node->[1]}) {                             }->{$node->[1]}) {
3991                        !!!cp ('t172');
3992                      last INSCOPE;                      last INSCOPE;
3993                    }                    }
3994                  } # INSCOPE                  } # INSCOPE
3995                    unless (defined $i) {                    unless (defined $i) {
3996                        !!!cp ('t173');
3997                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3998                      ## Ignore the token                      ## Ignore the token
3999                      !!!next-token;                      !!!next-token;
# Line 3464  sub _tree_construction_main ($) { Line 4003  sub _tree_construction_main ($) {
4003                  ## generate implied end tags                  ## generate implied end tags
4004                  if ({                  if ({
4005                       dd => 1, dt => 1, li => 1, p => 1,                       dd => 1, dt => 1, li => 1, p => 1,
4006    
4007                         ## NOTE: The following elements never appear here, maybe.
4008                       td => 1, th => 1, tr => 1,                       td => 1, th => 1, tr => 1,
4009                       tbody => 1, tfoot=> 1, thead => 1,                       tbody => 1, tfoot => 1, thead => 1,
4010                      }->{$self->{open_elements}->[-1]->[1]}) {                      }->{$self->{open_elements}->[-1]->[1]}) {
4011                      !!!cp ('t174');
4012                    !!!back-token;                    !!!back-token;
4013                    $token = {type => END_TAG_TOKEN,                    $token = {type => END_TAG_TOKEN,
4014                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
# Line 3474  sub _tree_construction_main ($) { Line 4016  sub _tree_construction_main ($) {
4016                  }                  }
4017                                    
4018                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
4019                      !!!cp ('t175');
4020                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4021                    } else {
4022                      !!!cp ('t176');
4023                  }                  }
4024                                    
4025                  splice @{$self->{open_elements}}, $i;                  splice @{$self->{open_elements}}, $i;
# Line 3486  sub _tree_construction_main ($) { Line 4031  sub _tree_construction_main ($) {
4031                  !!!next-token;                  !!!next-token;
4032                  redo B;                  redo B;
4033                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
4034                    !!!cp ('t177');
4035                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4036                  ## Ignore the token                  ## Ignore the token
4037                  !!!next-token;                  !!!next-token;
4038                  redo B;                  redo B;
4039                } else {                } else {
4040                    !!!cp ('t178');
4041                  #                  #
4042                }                }
4043              } elsif ({              } elsif ({
# Line 3504  sub _tree_construction_main ($) { Line 4051  sub _tree_construction_main ($) {
4051                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4052                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4053                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4054                      !!!cp ('t179');
4055                    $i = $_;                    $i = $_;
4056                    last INSCOPE;                    last INSCOPE;
4057                  } elsif ($node->[1] eq 'td' or $node->[1] eq 'th') {                  } elsif ($node->[1] eq 'td' or $node->[1] eq 'th') {
4058                      !!!cp ('t180');
4059                    $tn = $node->[1];                    $tn = $node->[1];
4060                    ## NOTE: There is exactly one |td| or |th| element                    ## NOTE: There is exactly one |td| or |th| element
4061                    ## in scope in the stack of open elements by definition.                    ## in scope in the stack of open elements by definition.
4062                  } elsif ({                  } elsif ({
4063                            table => 1, html => 1,                            table => 1, html => 1,
4064                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4065                      !!!cp ('t181');
4066                    last INSCOPE;                    last INSCOPE;
4067                  }                  }
4068                } # INSCOPE                } # INSCOPE
4069                unless (defined $i) {                unless (defined $i) {
4070                    !!!cp ('t182');
4071                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4072                  ## Ignore the token                  ## Ignore the token
4073                  !!!next-token;                  !!!next-token;
4074                  redo B;                  redo B;
4075                  } else {
4076                    !!!cp ('t183');
4077                }                }
4078    
4079                ## Close the cell                ## Close the cell
# Line 3537  sub _tree_construction_main ($) { Line 4090  sub _tree_construction_main ($) {
4090                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4091                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4092                  if ($node->[1] eq 'caption') {                  if ($node->[1] eq 'caption') {
4093                      !!!cp ('t184');
4094                    $i = $_;                    $i = $_;
4095                    last INSCOPE;                    last INSCOPE;
4096                  } elsif ({                  } elsif ({
4097                            table => 1, html => 1,                            table => 1, html => 1,
4098                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4099                      !!!cp ('t185');
4100                    last INSCOPE;                    last INSCOPE;
4101                  }                  }
4102                } # INSCOPE                } # INSCOPE
4103                unless (defined $i) {                unless (defined $i) {
4104                    !!!cp ('t186');
4105                  !!!parse-error (type => 'unmatched end tag:caption');                  !!!parse-error (type => 'unmatched end tag:caption');
4106                  ## Ignore the token                  ## Ignore the token
4107                  !!!next-token;                  !!!next-token;
# Line 3555  sub _tree_construction_main ($) { Line 4111  sub _tree_construction_main ($) {
4111                ## generate implied end tags                ## generate implied end tags
4112                if ({                if ({
4113                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
4114    
4115                       ## NOTE: The following elements never appear, maybe.
4116                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4117                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot => 1, thead => 1,
4118                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4119                    !!!cp ('t187');
4120                  !!!back-token; # </table>                  !!!back-token; # </table>
4121                  $token = {type => END_TAG_TOKEN, tag_name => 'caption'};                  $token = {type => END_TAG_TOKEN, tag_name => 'caption'};
4122                  !!!back-token;                  !!!back-token;
# Line 3567  sub _tree_construction_main ($) { Line 4126  sub _tree_construction_main ($) {
4126                }                }
4127    
4128                if ($self->{open_elements}->[-1]->[1] ne 'caption') {                if ($self->{open_elements}->[-1]->[1] ne 'caption') {
4129                    !!!cp ('t188');
4130                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4131                  } else {
4132                    !!!cp ('t189');
4133                }                }
4134    
4135                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
# Line 3582  sub _tree_construction_main ($) { Line 4144  sub _tree_construction_main ($) {
4144                        body => 1, col => 1, colgroup => 1, html => 1,                        body => 1, col => 1, colgroup => 1, html => 1,
4145                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4146                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
4147                    !!!cp ('t190');
4148                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4149                  ## Ignore the token                  ## Ignore the token
4150                  !!!next-token;                  !!!next-token;
4151                  redo B;                  redo B;
4152                } else {                } else {
4153                    !!!cp ('t191');
4154                  #                  #
4155                }                }
4156              } elsif ({              } elsif ({
# Line 3594  sub _tree_construction_main ($) { Line 4158  sub _tree_construction_main ($) {
4158                        thead => 1, tr => 1,                        thead => 1, tr => 1,
4159                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
4160                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
4161                  !!!cp ('t192');
4162                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4163                ## Ignore the token                ## Ignore the token
4164                !!!next-token;                !!!next-token;
4165                redo B;                redo B;
4166              } else {              } else {
4167                  !!!cp ('t193');
4168                #                #
4169              }              }
4170        } else {        } else {
# Line 3613  sub _tree_construction_main ($) { Line 4179  sub _tree_construction_main ($) {
4179                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4180                                
4181                unless (length $token->{data}) {                unless (length $token->{data}) {
4182                    !!!cp ('t194');
4183                  !!!next-token;                  !!!next-token;
4184                  redo B;                  redo B;
4185                  } else {
4186                    !!!cp ('t195');
4187                }                }
4188              }              }
4189    
# Line 3638  sub _tree_construction_main ($) { Line 4207  sub _tree_construction_main ($) {
4207                  if ($self->{open_elements}->[$_]->[1] eq 'table') {                  if ($self->{open_elements}->[$_]->[1] eq 'table') {
4208                    my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                    my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
4209                    if (defined $parent and $parent->node_type == 1) {                    if (defined $parent and $parent->node_type == 1) {
4210                        !!!cp ('t196');
4211                      $foster_parent_element = $parent;                      $foster_parent_element = $parent;
4212                      $next_sibling = $self->{open_elements}->[$_]->[0];                      $next_sibling = $self->{open_elements}->[$_]->[0];
4213                      $prev_sibling = $next_sibling->previous_sibling;                      $prev_sibling = $next_sibling->previous_sibling;
4214                    } else {                    } else {
4215                        !!!cp ('t197');
4216                      $foster_parent_element = $self->{open_elements}->[$_ - 1]->[0];                      $foster_parent_element = $self->{open_elements}->[$_ - 1]->[0];
4217                      $prev_sibling = $foster_parent_element->last_child;                      $prev_sibling = $foster_parent_element->last_child;
4218                    }                    }
# Line 3653  sub _tree_construction_main ($) { Line 4224  sub _tree_construction_main ($) {
4224                  unless defined $foster_parent_element;                  unless defined $foster_parent_element;
4225                if (defined $prev_sibling and                if (defined $prev_sibling and
4226                    $prev_sibling->node_type == 3) {                    $prev_sibling->node_type == 3) {
4227                    !!!cp ('t198');
4228                  $prev_sibling->manakai_append_text ($token->{data});                  $prev_sibling->manakai_append_text ($token->{data});
4229                } else {                } else {
4230                    !!!cp ('t199');
4231                  $foster_parent_element->insert_before                  $foster_parent_element->insert_before
4232                    ($self->{document}->create_text_node ($token->{data}),                    ($self->{document}->create_text_node ($token->{data}),
4233                     $next_sibling);                     $next_sibling);
4234                }                }
4235              } else {              } else {
4236                  !!!cp ('t200');
4237                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4238              }              }
4239                            
# Line 3674  sub _tree_construction_main ($) { Line 4248  sub _tree_construction_main ($) {
4248                  ## Clear back to table context                  ## Clear back to table context
4249                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4250                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4251                      !!!cp ('t201');
4252                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4253                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4254                  }                  }
# Line 3685  sub _tree_construction_main ($) { Line 4260  sub _tree_construction_main ($) {
4260    
4261                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
4262                  unless ($token->{tag_name} eq 'tr') {                  unless ($token->{tag_name} eq 'tr') {
4263                      !!!cp ('t202');
4264                    !!!parse-error (type => 'missing start tag:tr');                    !!!parse-error (type => 'missing start tag:tr');
4265                  }                  }
4266                                    
# Line 3692  sub _tree_construction_main ($) { Line 4268  sub _tree_construction_main ($) {
4268                  while (not {                  while (not {
4269                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4270                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4271                      !!!cp ('t203');
4272                      ## ISSUE: Can this case be reached?
4273                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4274                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4275                  }                  }
4276                                    
4277                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
4278                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
4279                      !!!cp ('t204');
4280                    !!!insert-element ($token->{tag_name}, $token->{attributes});                    !!!insert-element ($token->{tag_name}, $token->{attributes});
4281                    !!!next-token;                    !!!next-token;
4282                    redo B;                    redo B;
4283                  } else {                  } else {
4284                      !!!cp ('t205');
4285                    !!!insert-element ('tr');                    !!!insert-element ('tr');
4286                    ## reprocess in the "in row" insertion mode                    ## reprocess in the "in row" insertion mode
4287                  }                  }
4288                  } else {
4289                    !!!cp ('t206');
4290                }                }
4291    
4292                ## Clear back to table row context                ## Clear back to table row context
4293                while (not {                while (not {
4294                  tr => 1, html => 1,                  tr => 1, html => 1,
4295                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4296                    !!!cp ('t207');
4297                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4298                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4299                }                }
# Line 3734  sub _tree_construction_main ($) { Line 4317  sub _tree_construction_main ($) {
4317                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4318                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4319                    if ($node->[1] eq 'tr') {                    if ($node->[1] eq 'tr') {
4320                        !!!cp ('t208');
4321                      $i = $_;                      $i = $_;
4322                      last INSCOPE;                      last INSCOPE;
4323                    } elsif ({                    } elsif ({
4324                              table => 1, html => 1,                              html => 1,
4325    
4326                                ## NOTE: This element does not appear here, maybe.
4327                                table => 1,
4328                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4329                        !!!cp ('t209');
4330                      last INSCOPE;                      last INSCOPE;
4331                    }                    }
4332                  } # INSCOPE                  } # INSCOPE
4333                  unless (defined $i) {                  unless (defined $i) {
4334                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});                   !!!cp ('t210');
4335    ## TODO: This type is wrong.
4336                     !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});
4337                    ## Ignore the token                    ## Ignore the token
4338                    !!!next-token;                    !!!next-token;
4339                    redo B;                    redo B;
# Line 3753  sub _tree_construction_main ($) { Line 4343  sub _tree_construction_main ($) {
4343                  while (not {                  while (not {
4344                    tr => 1, html => 1,                    tr => 1, html => 1,
4345                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4346                      !!!cp ('t211');
4347                      ## ISSUE: Can this case be reached?
4348                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4349                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4350                  }                  }
# Line 3760  sub _tree_construction_main ($) { Line 4352  sub _tree_construction_main ($) {
4352                  pop @{$self->{open_elements}}; # tr                  pop @{$self->{open_elements}}; # tr
4353                  $self->{insertion_mode} = IN_TABLE_BODY_IM;                  $self->{insertion_mode} = IN_TABLE_BODY_IM;
4354                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
4355                      !!!cp ('t212');
4356                    ## reprocess                    ## reprocess
4357                    redo B;                    redo B;
4358                  } else {                  } else {
4359                      !!!cp ('t213');
4360                    ## reprocess in the "in table body" insertion mode...                    ## reprocess in the "in table body" insertion mode...
4361                  }                  }
4362                }                }
# Line 3775  sub _tree_construction_main ($) { Line 4369  sub _tree_construction_main ($) {
4369                    if ({                    if ({
4370                         tbody => 1, thead => 1, tfoot => 1,                         tbody => 1, thead => 1, tfoot => 1,
4371                        }->{$node->[1]}) {                        }->{$node->[1]}) {
4372                        !!!cp ('t214');
4373                      $i = $_;                      $i = $_;
4374                      last INSCOPE;                      last INSCOPE;
4375                    } elsif ({                    } elsif ({
4376                              table => 1, html => 1,                              table => 1, html => 1,
4377                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4378                        !!!cp ('t215');
4379                      last INSCOPE;                      last INSCOPE;
4380                    }                    }
4381                  } # INSCOPE                  } # INSCOPE
4382                  unless (defined $i) {                  unless (defined $i) {
4383                      !!!cp ('t216');
4384    ## TODO: This erorr type ios wrong.
4385                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4386                    ## Ignore the token                    ## Ignore the token
4387                    !!!next-token;                    !!!next-token;
# Line 3794  sub _tree_construction_main ($) { Line 4392  sub _tree_construction_main ($) {
4392                  while (not {                  while (not {
4393                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4394                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4395                      !!!cp ('t217');
4396                      ## ISSUE: Can this state be reached?
4397                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4398                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4399                  }                  }
# Line 3808  sub _tree_construction_main ($) { Line 4408  sub _tree_construction_main ($) {
4408                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4409                  $self->{insertion_mode} = IN_TABLE_IM;                  $self->{insertion_mode} = IN_TABLE_IM;
4410                  ## reprocess in "in table" insertion mode...                  ## reprocess in "in table" insertion mode...
4411                  } else {
4412                    !!!cp ('t218');
4413                }                }
4414    
4415                if ($token->{tag_name} eq 'col') {                if ($token->{tag_name} eq 'col') {
4416                  ## Clear back to table context                  ## Clear back to table context
4417                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4418                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4419                      !!!cp ('t219');
4420                      ## ISSUE: Can this state be reached?
4421                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4422                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4423                  }                  }
# Line 3830  sub _tree_construction_main ($) { Line 4434  sub _tree_construction_main ($) {
4434                  ## Clear back to table context                  ## Clear back to table context
4435                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4436                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4437                      !!!cp ('t220');
4438                      ## ISSUE: Can this state be reached?
4439                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4440                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4441                  }                  }
# Line 3859  sub _tree_construction_main ($) { Line 4465  sub _tree_construction_main ($) {
4465                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4466                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4467                  if ($node->[1] eq 'table') {                  if ($node->[1] eq 'table') {
4468                      !!!cp ('t221');
4469                    $i = $_;                    $i = $_;
4470                    last INSCOPE;                    last INSCOPE;
4471                  } elsif ({                  } elsif ({
4472                            table => 1, html => 1,                            #table => 1,
4473                              html => 1,
4474                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4475                      !!!cp ('t222');
4476                    last INSCOPE;                    last INSCOPE;
4477                  }                  }
4478                } # INSCOPE                } # INSCOPE
4479                unless (defined $i) {                unless (defined $i) {
4480                    !!!cp ('t223');
4481    ## TODO: The following is wrong, maybe.
4482                  !!!parse-error (type => 'unmatched end tag:table');                  !!!parse-error (type => 'unmatched end tag:table');
4483                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
4484                  !!!next-token;                  !!!next-token;
# Line 3880  sub _tree_construction_main ($) { Line 4491  sub _tree_construction_main ($) {
4491                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4492                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
4493                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4494                    !!!cp ('t224');
4495                  !!!back-token; # <table>                  !!!back-token; # <table>
4496                  $token = {type => END_TAG_TOKEN, tag_name => 'table'};                  $token = {type => END_TAG_TOKEN, tag_name => 'table'};
4497                  !!!back-token;                  !!!back-token;
# Line 3889  sub _tree_construction_main ($) { Line 4501  sub _tree_construction_main ($) {
4501                }                }
4502    
4503                if ($self->{open_elements}->[-1]->[1] ne 'table') {                if ($self->{open_elements}->[-1]->[1] ne 'table') {
4504                    !!!cp ('t225');
4505    ## ISSUE: Can this case be reached?
4506                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4507                  } else {
4508                    !!!cp ('t226');
4509                }                }
4510    
4511                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
# Line 3899  sub _tree_construction_main ($) { Line 4515  sub _tree_construction_main ($) {
4515                ## reprocess                ## reprocess
4516                redo B;                redo B;
4517          } else {          } else {
4518              !!!cp ('t227');
4519            !!!parse-error (type => 'in table:'.$token->{tag_name});            !!!parse-error (type => 'in table:'.$token->{tag_name});
4520    
4521            $insert = $insert_to_foster;            $insert = $insert_to_foster;
# Line 3912  sub _tree_construction_main ($) { Line 4529  sub _tree_construction_main ($) {
4529                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4530                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4531                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4532                      !!!cp ('t228');
4533                    $i = $_;                    $i = $_;
4534                    last INSCOPE;                    last INSCOPE;
4535                  } elsif ({                  } elsif ({
4536                            table => 1, html => 1,                            table => 1, html => 1,
4537                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4538                      !!!cp ('t229');
4539                    last INSCOPE;                    last INSCOPE;
4540                  }                  }
4541                } # INSCOPE                } # INSCOPE
4542                unless (defined $i) {                unless (defined $i) {
4543                    !!!cp ('t230');
4544                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4545                  ## Ignore the token                  ## Ignore the token
4546                  !!!next-token;                  !!!next-token;
4547                  redo B;                  redo B;
4548                  } else {
4549                    !!!cp ('t232');
4550                }                }
4551    
4552                ## Clear back to table row context                ## Clear back to table row context
4553                while (not {                while (not {
4554                  tr => 1, html => 1,                  tr => 1, html => 1,
4555                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4556                    !!!cp ('t231');
4557    ## ISSUE: Can this state be reached?
4558                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4559                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4560                }                }
# Line 3947  sub _tree_construction_main ($) { Line 4571  sub _tree_construction_main ($) {
4571                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4572                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4573                    if ($node->[1] eq 'tr') {                    if ($node->[1] eq 'tr') {
4574                        !!!cp ('t233');
4575                      $i = $_;                      $i = $_;
4576                      last INSCOPE;                      last INSCOPE;
4577                    } elsif ({                    } elsif ({
4578                              table => 1, html => 1,                              table => 1, html => 1,
4579                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4580                        !!!cp ('t234');
4581                      last INSCOPE;                      last INSCOPE;
4582                    }                    }
4583                  } # INSCOPE                  } # INSCOPE
4584                  unless (defined $i) {                  unless (defined $i) {
4585                      !!!cp ('t235');
4586    ## TODO: The following is wrong.
4587                    !!!parse-error (type => 'unmatched end tag:'.$token->{type});                    !!!parse-error (type => 'unmatched end tag:'.$token->{type});
4588                    ## Ignore the token                    ## Ignore the token
4589                    !!!next-token;                    !!!next-token;
# Line 3966  sub _tree_construction_main ($) { Line 4594  sub _tree_construction_main ($) {
4594                  while (not {                  while (not {
4595                    tr => 1, html => 1,                    tr => 1, html => 1,
4596                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4597                      !!!cp ('t236');
4598    ## ISSUE: Can this state be reached?
4599                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4600                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4601                  }                  }
# Line 3983  sub _tree_construction_main ($) { Line 4613  sub _tree_construction_main ($) {
4613                    if ({                    if ({
4614                         tbody => 1, thead => 1, tfoot => 1,                         tbody => 1, thead => 1, tfoot => 1,
4615                        }->{$node->[1]}) {                        }->{$node->[1]}) {
4616                        !!!cp ('t237');
4617                      $i = $_;                      $i = $_;
4618                      last INSCOPE;                      last INSCOPE;
4619                    } elsif ({                    } elsif ({
4620                              table => 1, html => 1,                              table => 1, html => 1,
4621                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4622                        !!!cp ('t238');
4623                      last INSCOPE;                      last INSCOPE;
4624                    }                    }
4625                  } # INSCOPE                  } # INSCOPE
4626                  unless (defined $i) {                  unless (defined $i) {
4627                      !!!cp ('t239');
4628                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4629                    ## Ignore the token                    ## Ignore the token
4630                    !!!next-token;                    !!!next-token;
# Line 4002  sub _tree_construction_main ($) { Line 4635  sub _tree_construction_main ($) {
4635                  while (not {                  while (not {
4636                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4637                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4638                      !!!cp ('t240');
4639                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4640                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4641                  }                  }
# Line 4023  sub _tree_construction_main ($) { Line 4657  sub _tree_construction_main ($) {
4657                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4658                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4659                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4660                      !!!cp ('t241');
4661                    $i = $_;                    $i = $_;
4662                    last INSCOPE;                    last INSCOPE;
4663                  } elsif ({                  } elsif ({
4664                            table => 1, html => 1,                            table => 1, html => 1,
4665                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4666                      !!!cp ('t242');
4667                    last INSCOPE;                    last INSCOPE;
4668                  }                  }
4669                } # INSCOPE                } # INSCOPE
4670                unless (defined $i) {                unless (defined $i) {
4671                    !!!cp ('t243');
4672                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4673                  ## Ignore the token                  ## Ignore the token
4674                  !!!next-token;                  !!!next-token;
# Line 4044  sub _tree_construction_main ($) { Line 4681  sub _tree_construction_main ($) {
4681                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4682                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
4683                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4684                    !!!cp ('t244');
4685    ## ISSUE: Can this case be reached?
4686                  !!!back-token;                  !!!back-token;
4687                  $token = {type => END_TAG_TOKEN,                  $token = {type => END_TAG_TOKEN,
4688                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
# Line 4051  sub _tree_construction_main ($) { Line 4690  sub _tree_construction_main ($) {
4690                }                }
4691                                
4692                if ($self->{open_elements}->[-1]->[1] ne 'table') {                if ($self->{open_elements}->[-1]->[1] ne 'table') {
4693                    !!!cp ('t245');
4694                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4695                  } else {
4696                    !!!cp ('t246');
4697                }                }
4698                                    
4699                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
# Line 4070  sub _tree_construction_main ($) { Line 4712  sub _tree_construction_main ($) {
4712                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4713                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4714                    if ($node->[1] eq $token->{tag_name}) {                    if ($node->[1] eq $token->{tag_name}) {
4715                        !!!cp ('t247');
4716                      $i = $_;                      $i = $_;
4717                      last INSCOPE;                      last INSCOPE;
4718                    } elsif ({                    } elsif ({
4719                              table => 1, html => 1,                              table => 1, html => 1,
4720                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4721                        !!!cp ('t248');
4722                      last INSCOPE;                      last INSCOPE;
4723                    }                    }
4724                  } # INSCOPE                  } # INSCOPE
4725                    unless (defined $i) {                    unless (defined $i) {
4726                        !!!cp ('t249');
4727                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4728                      ## Ignore the token                      ## Ignore the token
4729                      !!!next-token;                      !!!next-token;
# Line 4091  sub _tree_construction_main ($) { Line 4736  sub _tree_construction_main ($) {
4736                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4737                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4738                    if ($node->[1] eq 'tr') {                    if ($node->[1] eq 'tr') {
4739                        !!!cp ('t250');
4740                      $i = $_;                      $i = $_;
4741                      last INSCOPE;                      last INSCOPE;
4742                    } elsif ({                    } elsif ({
4743                              table => 1, html => 1,                              table => 1, html => 1,
4744                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4745                        !!!cp ('t251');
4746                      last INSCOPE;                      last INSCOPE;
4747                    }                    }
4748                  } # INSCOPE                  } # INSCOPE
4749                    unless (defined $i) {                    unless (defined $i) {
4750                        !!!cp ('t252');
4751                      !!!parse-error (type => 'unmatched end tag:tr');                      !!!parse-error (type => 'unmatched end tag:tr');
4752                      ## Ignore the token                      ## Ignore the token
4753                      !!!next-token;                      !!!next-token;
# Line 4110  sub _tree_construction_main ($) { Line 4758  sub _tree_construction_main ($) {
4758                  while (not {                  while (not {
4759                    tr => 1, html => 1,                    tr => 1, html => 1,
4760                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4761                      !!!cp ('t253');
4762    ## ISSUE: Can this case be reached?
4763                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4764                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4765                  }                  }
# Line 4124  sub _tree_construction_main ($) { Line 4774  sub _tree_construction_main ($) {
4774                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4775                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4776                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4777                      !!!cp ('t254');
4778                    $i = $_;                    $i = $_;
4779                    last INSCOPE;                    last INSCOPE;
4780                  } elsif ({                  } elsif ({
4781                            table => 1, html => 1,                            table => 1, html => 1,
4782                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4783                      !!!cp ('t255');
4784                    last INSCOPE;                    last INSCOPE;
4785                  }                  }
4786                } # INSCOPE                } # INSCOPE
4787                unless (defined $i) {                unless (defined $i) {
4788                    !!!cp ('t256');
4789                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4790                  ## Ignore the token                  ## Ignore the token
4791                  !!!next-token;                  !!!next-token;
# Line 4143  sub _tree_construction_main ($) { Line 4796  sub _tree_construction_main ($) {
4796                while (not {                while (not {
4797                  tbody => 1, tfoot => 1, thead => 1, html => 1,                  tbody => 1, tfoot => 1, thead => 1, html => 1,
4798                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4799                    !!!cp ('t257');
4800    ## ISSUE: Can this case be reached?
4801                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4802                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4803                }                }
# Line 4157  sub _tree_construction_main ($) { Line 4812  sub _tree_construction_main ($) {
4812                        tr => 1, # $self->{insertion_mode} == IN_ROW_IM                        tr => 1, # $self->{insertion_mode} == IN_ROW_IM
4813                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
4814                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4815                  !!!cp ('t258');
4816                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4817                ## Ignore the token                ## Ignore the token
4818                !!!next-token;                !!!next-token;
4819                redo B;                redo B;
4820          } else {          } else {
4821              !!!cp ('t259');
4822            !!!parse-error (type => 'in table:/'.$token->{tag_name});            !!!parse-error (type => 'in table:/'.$token->{tag_name});
4823    
4824            $insert = $insert_to_foster;            $insert = $insert_to_foster;
# Line 4175  sub _tree_construction_main ($) { Line 4832  sub _tree_construction_main ($) {
4832              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4833                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4834                unless (length $token->{data}) {                unless (length $token->{data}) {
4835                    !!!cp ('t260');
4836                  !!!next-token;                  !!!next-token;
4837                  redo B;                  redo B;
4838                }                }
4839              }              }
4840                            
4841                !!!cp ('t261');
4842              #              #
4843            } elsif ($token->{type} == START_TAG_TOKEN) {            } elsif ($token->{type} == START_TAG_TOKEN) {
4844              if ($token->{tag_name} eq 'col') {              if ($token->{tag_name} eq 'col') {
4845                  !!!cp ('t262');
4846                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
4847                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4848                !!!next-token;                !!!next-token;
4849                redo B;                redo B;
4850              } else {              } else {
4851                  !!!cp ('t263');
4852                #                #
4853              }              }
4854            } elsif ($token->{type} == END_TAG_TOKEN) {            } elsif ($token->{type} == END_TAG_TOKEN) {
4855              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
4856                if ($self->{open_elements}->[-1]->[1] eq 'html') {                if ($self->{open_elements}->[-1]->[1] eq 'html') {
4857                    !!!cp ('t264');
4858                  !!!parse-error (type => 'unmatched end tag:colgroup');                  !!!parse-error (type => 'unmatched end tag:colgroup');
4859                  ## Ignore the token                  ## Ignore the token
4860                  !!!next-token;                  !!!next-token;
4861                  redo B;                  redo B;
4862                } else {                } else {
4863                    !!!cp ('t265');
4864                  pop @{$self->{open_elements}}; # colgroup                  pop @{$self->{open_elements}}; # colgroup
4865                  $self->{insertion_mode} = IN_TABLE_IM;                  $self->{insertion_mode} = IN_TABLE_IM;
4866                  !!!next-token;                  !!!next-token;
4867                  redo B;                              redo B;            
4868                }                }
4869              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
4870                  !!!cp ('t266');
4871                !!!parse-error (type => 'unmatched end tag:col');                !!!parse-error (type => 'unmatched end tag:col');
4872                ## Ignore the token                ## Ignore the token
4873                !!!next-token;                !!!next-token;
4874                redo B;                redo B;
4875              } else {              } else {
4876                  !!!cp ('t267');
4877                #                #
4878              }              }
4879            } else {            } else {
4880              #              die "$0: $token->{type}: Unknown token type";
4881            }            }
4882    
4883            ## As if </colgroup>            ## As if </colgroup>
4884            if ($self->{open_elements}->[-1]->[1] eq 'html') {            if ($self->{open_elements}->[-1]->[1] eq 'html') {
4885                !!!cp ('t269');
4886              !!!parse-error (type => 'unmatched end tag:colgroup');              !!!parse-error (type => 'unmatched end tag:colgroup');
4887              ## Ignore the token              ## Ignore the token
4888              !!!next-token;              !!!next-token;
4889              redo B;              redo B;
4890            } else {            } else {
4891                !!!cp ('t270');
4892              pop @{$self->{open_elements}}; # colgroup              pop @{$self->{open_elements}}; # colgroup
4893              $self->{insertion_mode} = IN_TABLE_IM;              $self->{insertion_mode} = IN_TABLE_IM;
4894              ## reprocess              ## reprocess
# Line 4229  sub _tree_construction_main ($) { Line 4896  sub _tree_construction_main ($) {
4896            }            }
4897      } elsif ($self->{insertion_mode} == IN_SELECT_IM) {      } elsif ($self->{insertion_mode} == IN_SELECT_IM) {
4898        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
4899            !!!cp ('t271');
4900          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4901          !!!next-token;          !!!next-token;
4902          redo B;          redo B;
4903        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
4904              if ($token->{tag_name} eq 'option') {              if ($token->{tag_name} eq 'option') {
4905                if ($self->{open_elements}->[-1]->[1] eq 'option') {                if ($self->{open_elements}->[-1]->[1] eq 'option') {
4906                    !!!cp ('t272');
4907                  ## As if </option>                  ## As if </option>
4908                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4909                  } else {
4910                    !!!cp ('t273');
4911                }                }
4912    
4913                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
# Line 4244  sub _tree_construction_main ($) { Line 4915  sub _tree_construction_main ($) {
4915                redo B;                redo B;
4916              } elsif ($token->{tag_name} eq 'optgroup') {              } elsif ($token->{tag_name} eq 'optgroup') {
4917                if ($self->{open_elements}->[-1]->[1] eq 'option') {                if ($self->{open_elements}->[-1]->[1] eq 'option') {
4918                    !!!cp ('t274');
4919                  ## As if </option>                  ## As if </option>
4920                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4921                  } else {
4922                    !!!cp ('t275');
4923                }                }
4924    
4925                if ($self->{open_elements}->[-1]->[1] eq 'optgroup') {                if ($self->{open_elements}->[-1]->[1] eq 'optgroup') {
4926                    !!!cp ('t276');
4927                  ## As if </optgroup>                  ## As if </optgroup>
4928                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4929                  } else {
4930                    !!!cp ('t277');
4931                }                }
4932    
4933                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
4934                !!!next-token;                !!!next-token;
4935                redo B;                redo B;
4936              } elsif ($token->{tag_name} eq 'select') {              } elsif ($token->{tag_name} eq 'select') {
4937    ## TODO: The type below is not good - <select> is replaced by </select>
4938                !!!parse-error (type => 'not closed:select');                !!!parse-error (type => 'not closed:select');
4939                ## As if </select> instead                ## As if </select> instead
4940                ## have an element in table scope                ## have an element in table scope
# Line 4264  sub _tree_construction_main ($) { Line 4942  sub _tree_construction_main ($) {
4942                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4943                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4944                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4945                      !!!cp ('t278');
4946                    $i = $_;                    $i = $_;
4947                    last INSCOPE;                    last INSCOPE;
4948                  } elsif ({                  } elsif ({
4949                            table => 1, html => 1,                            table => 1, html => 1,
4950                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4951                      !!!cp ('t279');
4952                    last INSCOPE;                    last INSCOPE;
4953                  }                  }
4954                } # INSCOPE                } # INSCOPE
4955                unless (defined $i) {                unless (defined $i) {
4956                    !!!cp ('t280');
4957                  !!!parse-error (type => 'unmatched end tag:select');                  !!!parse-error (type => 'unmatched end tag:select');
4958                  ## Ignore the token                  ## Ignore the token
4959                  !!!next-token;                  !!!next-token;
4960                  redo B;                  redo B;
4961                }                }
4962                                
4963                  !!!cp ('t281');
4964                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4965    
4966                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
# Line 4286  sub _tree_construction_main ($) { Line 4968  sub _tree_construction_main ($) {
4968                !!!next-token;                !!!next-token;
4969                redo B;                redo B;
4970          } else {          } else {
4971              !!!cp ('t282');
4972            !!!parse-error (type => 'in select:'.$token->{tag_name});            !!!parse-error (type => 'in select:'.$token->{tag_name});
4973            ## Ignore the token            ## Ignore the token
4974            !!!next-token;            !!!next-token;
# Line 4295  sub _tree_construction_main ($) { Line 4978  sub _tree_construction_main ($) {
4978              if ($token->{tag_name} eq 'optgroup') {              if ($token->{tag_name} eq 'optgroup') {
4979                if ($self->{open_elements}->[-1]->[1] eq 'option' and                if ($self->{open_elements}->[-1]->[1] eq 'option' and
4980                    $self->{open_elements}->[-2]->[1] eq 'optgroup') {                    $self->{open_elements}->[-2]->[1] eq 'optgroup') {
4981                    !!!cp ('t283');
4982                  ## As if </option>                  ## As if </option>
4983                  splice @{$self->{open_elements}}, -2;                  splice @{$self->{open_elements}}, -2;
4984                } elsif ($self->{open_elements}->[-1]->[1] eq 'optgroup') {                } elsif ($self->{open_elements}->[-1]->[1] eq 'optgroup') {
4985                    !!!cp ('t284');
4986                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4987                } else {                } else {
4988                    !!!cp ('t285');
4989                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4990                  ## Ignore the token                  ## Ignore the token
4991                }                }
# Line 4307  sub _tree_construction_main ($) { Line 4993  sub _tree_construction_main ($) {
4993                redo B;                redo B;
4994              } elsif ($token->{tag_name} eq 'option') {              } elsif ($token->{tag_name} eq 'option') {
4995                if ($self->{open_elements}->[-1]->[1] eq 'option') {                if ($self->{open_elements}->[-1]->[1] eq 'option') {
4996                    !!!cp ('t286');
4997                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4998                } else {                } else {
4999                    !!!cp ('t287');
5000                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5001                  ## Ignore the token                  ## Ignore the token
5002                }                }
# Line 4320  sub _tree_construction_main ($) { Line 5008  sub _tree_construction_main ($) {
5008                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5009                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5010                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
5011                      !!!cp ('t288');
5012                    $i = $_;                    $i = $_;
5013                    last INSCOPE;                    last INSCOPE;
5014                  } elsif ({                  } elsif ({
5015                            table => 1, html => 1,                            table => 1, html => 1,
5016                           }->{$node->[1]}) {                           }->{$node->[1]}) {
5017                      !!!cp ('t289');
5018                    last INSCOPE;                    last INSCOPE;
5019                  }                  }
5020                } # INSCOPE                } # INSCOPE
5021                unless (defined $i) {                unless (defined $i) {
5022                    !!!cp ('t290');
5023                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5024                  ## Ignore the token                  ## Ignore the token
5025                  !!!next-token;                  !!!next-token;
5026                  redo B;                  redo B;
5027                }                }
5028                                
5029                  !!!cp ('t291');
5030                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
5031    
5032                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
# Line 4345  sub _tree_construction_main ($) { Line 5037  sub _tree_construction_main ($) {
5037                        caption => 1, table => 1, tbody => 1,                        caption => 1, table => 1, tbody => 1,
5038                        tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                        tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
5039                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5040    ## TODO: The following is wrong?
5041                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5042                                
5043                ## have an element in table scope                ## have an element in table scope
# Line 4352  sub _tree_construction_main ($) { Line 5045  sub _tree_construction_main ($) {
5045                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5046                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5047                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
5048                      !!!cp ('t292');
5049                    $i = $_;                    $i = $_;
5050                    last INSCOPE;                    last INSCOPE;
5051                  } elsif ({                  } elsif ({
5052                            table => 1, html => 1,                            table => 1, html => 1,
5053                           }->{$node->[1]}) {                           }->{$node->[1]}) {
5054                      !!!cp ('t293');
5055                    last INSCOPE;                    last INSCOPE;
5056                  }                  }
5057                } # INSCOPE                } # INSCOPE
5058                unless (defined $i) {                unless (defined $i) {
5059                    !!!cp ('t294');
5060                  ## Ignore the token                  ## Ignore the token
5061                  !!!next-token;                  !!!next-token;
5062                  redo B;                  redo B;
# Line 4372  sub _tree_construction_main ($) { Line 5068  sub _tree_construction_main ($) {
5068                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5069                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5070                  if ($node->[1] eq 'select') {                  if ($node->[1] eq 'select') {
5071                      !!!cp ('t295');
5072                    $i = $_;                    $i = $_;
5073                    last INSCOPE;                    last INSCOPE;
5074                  } elsif ({                  } elsif ({
5075                            table => 1, html => 1,                            table => 1, html => 1,
5076                           }->{$node->[1]}) {                           }->{$node->[1]}) {
5077    ## ISSUE: Can this state be reached?
5078                      !!!cp ('t296');
5079                    last INSCOPE;                    last INSCOPE;
5080                  }                  }
5081                } # INSCOPE                } # INSCOPE
5082                unless (defined $i) {                unless (defined $i) {
5083                    !!!cp ('t297');
5084    ## TODO: The following error type is correct?
5085                  !!!parse-error (type => 'unmatched end tag:select');                  !!!parse-error (type => 'unmatched end tag:select');
5086                  ## Ignore the </select> token                  ## Ignore the </select> token
5087                  !!!next-token; ## TODO: ok?                  !!!next-token; ## TODO: ok?
5088                  redo B;                  redo B;
5089                }                }
5090                                
5091                  !!!cp ('t298');
5092                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
5093    
5094                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
# Line 4394  sub _tree_construction_main ($) { Line 5096  sub _tree_construction_main ($) {
5096                ## reprocess                ## reprocess
5097                redo B;                redo B;
5098          } else {          } else {
5099              !!!cp ('t299');
5100            !!!parse-error (type => 'in select:/'.$token->{tag_name});            !!!parse-error (type => 'in select:/'.$token->{tag_name});
5101            ## Ignore the token            ## Ignore the token
5102            !!!next-token;            !!!next-token;
# Line 4412  sub _tree_construction_main ($) { Line 5115  sub _tree_construction_main ($) {
5115            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
5116                        
5117            unless (length $token->{data}) {            unless (length $token->{data}) {
5118                !!!cp ('t300');
5119              !!!next-token;              !!!next-token;
5120              redo B;              redo B;
5121            }            }
5122          }          }
5123                    
5124          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
5125              !!!cp ('t301');
5126            !!!parse-error (type => 'after html:#character');            !!!parse-error (type => 'after html:#character');
5127    
5128            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "main" phase, "after body" insertion mode...
5129            } else {
5130              !!!cp ('t302');
5131          }          }
5132                    
5133          ## "after body" insertion mode          ## "after body" insertion mode
# Line 4431  sub _tree_construction_main ($) { Line 5138  sub _tree_construction_main ($) {
5138          redo B;          redo B;
5139        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5140          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
5141              !!!cp ('t303');
5142            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
5143                        
5144            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "main" phase, "after body" insertion mode...
5145            } else {
5146              !!!cp ('t304');
5147          }          }
5148    
5149          ## "after body" insertion mode          ## "after body" insertion mode
# Line 4444  sub _tree_construction_main ($) { Line 5154  sub _tree_construction_main ($) {
5154          redo B;          redo B;
5155        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
5156          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
5157              !!!cp ('t305');
5158            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
5159                        
5160            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
5161            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "main" phase, "after body" insertion mode...
5162            } else {
5163              !!!cp ('t306');
5164          }          }
5165    
5166          ## "after body" insertion mode          ## "after body" insertion mode
5167          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
5168            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
5169                !!!cp ('t307');
5170              !!!parse-error (type => 'unmatched end tag:html');              !!!parse-error (type => 'unmatched end tag:html');
5171              ## Ignore the token              ## Ignore the token
5172              !!!next-token;              !!!next-token;
5173              redo B;              redo B;
5174            } else {            } else {
5175                !!!cp ('t308');
5176              $self->{insertion_mode} = AFTER_HTML_BODY_IM;              $self->{insertion_mode} = AFTER_HTML_BODY_IM;
5177              !!!next-token;              !!!next-token;
5178              redo B;              redo B;
5179            }            }
5180          } else {          } else {
5181              !!!cp ('t309');
5182            !!!parse-error (type => 'after body:/'.$token->{tag_name});            !!!parse-error (type => 'after body:/'.$token->{tag_name});
5183    
5184            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
# Line 4478  sub _tree_construction_main ($) { Line 5194  sub _tree_construction_main ($) {
5194            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
5195                        
5196            unless (length $token->{data}) {            unless (length $token->{data}) {
5197                !!!cp ('t310');
5198              !!!next-token;              !!!next-token;
5199              redo B;              redo B;
5200            }            }
# Line 4485  sub _tree_construction_main ($) { Line 5202  sub _tree_construction_main ($) {
5202                    
5203          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
5204            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
5205                !!!cp ('t311');
5206              !!!parse-error (type => 'in frameset:#character');              !!!parse-error (type => 'in frameset:#character');
5207            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
5208                !!!cp ('t312');
5209              !!!parse-error (type => 'after frameset:#character');              !!!parse-error (type => 'after frameset:#character');
5210            } else { # "after html frameset"            } else { # "after html frameset"
5211                !!!cp ('t313');
5212              !!!parse-error (type => 'after html:#character');              !!!parse-error (type => 'after html:#character');
5213    
5214              $self->{insertion_mode} = AFTER_FRAMESET_IM;              $self->{insertion_mode} = AFTER_FRAMESET_IM;
# Line 4498  sub _tree_construction_main ($) { Line 5218  sub _tree_construction_main ($) {
5218                        
5219            ## Ignore the token.            ## Ignore the token.
5220            if (length $token->{data}) {            if (length $token->{data}) {
5221                !!!cp ('t314');
5222              ## reprocess the rest of characters              ## reprocess the rest of characters
5223            } else {            } else {
5224                !!!cp ('t315');
5225              !!!next-token;              !!!next-token;
5226            }            }
5227            redo B;            redo B;
# Line 4508  sub _tree_construction_main ($) { Line 5230  sub _tree_construction_main ($) {
5230          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
5231        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5232          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
5233              !!!cp ('t316');
5234            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
5235    
5236            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
5237            ## Process in the "main" phase, "after frameset" insertion mode...            ## Process in the "main" phase, "after frameset" insertion mode...
5238          }          } else {
5239              !!!cp ('t317');
5240            }
5241    
5242          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
5243              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
5244              !!!cp ('t318');
5245            !!!insert-element ($token->{tag_name}, $token->{attributes});            !!!insert-element ($token->{tag_name}, $token->{attributes});
5246            !!!next-token;            !!!next-token;
5247            redo B;            redo B;
5248          } elsif ($token->{tag_name} eq 'frame' and          } elsif ($token->{tag_name} eq 'frame' and
5249                   $self->{insertion_mode} == IN_FRAMESET_IM) {                   $self->{insertion_mode} == IN_FRAMESET_IM) {
5250              !!!cp ('t319');
5251            !!!insert-element ($token->{tag_name}, $token->{attributes});            !!!insert-element ($token->{tag_name}, $token->{attributes});
5252            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
5253            !!!next-token;            !!!next-token;
5254            redo B;            redo B;
5255          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
5256              !!!cp ('t320');
5257            ## NOTE: As if in body.            ## NOTE: As if in body.
5258            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);
5259            redo B;            redo B;
5260          } else {          } else {
5261            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
5262                !!!cp ('t321');
5263              !!!parse-error (type => 'in frameset:'.$token->{tag_name});              !!!parse-error (type => 'in frameset:'.$token->{tag_name});
5264            } else {            } else {
5265                !!!cp ('t322');
5266              !!!parse-error (type => 'after frameset:'.$token->{tag_name});              !!!parse-error (type => 'after frameset:'.$token->{tag_name});
5267            }            }
5268            ## Ignore the token            ## Ignore the token
# Line 4541  sub _tree_construction_main ($) { Line 5271  sub _tree_construction_main ($) {
5271          }          }
5272        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
5273          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
5274              !!!cp ('t323');
5275            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
5276    
5277            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
5278            ## Process in the "main" phase, "after frameset" insertion mode...            ## Process in the "main" phase, "after frameset" insertion mode...
5279            } else {
5280              !!!cp ('t324');
5281          }          }
5282    
5283          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
5284              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
5285            if ($self->{open_elements}->[-1]->[1] eq 'html' and            if ($self->{open_elements}->[-1]->[1] eq 'html' and
5286                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
5287                !!!cp ('t325');
5288              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5289              ## Ignore the token              ## Ignore the token
5290              !!!next-token;              !!!next-token;
5291            } else {            } else {
5292                !!!cp ('t326');
5293              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
5294              !!!next-token;              !!!next-token;
5295            }            }
5296    
5297            if (not defined $self->{inner_html_node} and            if (not defined $self->{inner_html_node} and
5298                $self->{open_elements}->[-1]->[1] ne 'frameset') {                $self->{open_elements}->[-1]->[1] ne 'frameset') {
5299                !!!cp ('t327');
5300              $self->{insertion_mode} = AFTER_FRAMESET_IM;              $self->{insertion_mode} = AFTER_FRAMESET_IM;
5301              } else {
5302                !!!cp ('t328');
5303            }            }
5304            redo B;            redo B;
5305          } elsif ($token->{tag_name} eq 'html' and          } elsif ($token->{tag_name} eq 'html' and
5306                   $self->{insertion_mode} == AFTER_FRAMESET_IM) {                   $self->{insertion_mode} == AFTER_FRAMESET_IM) {
5307              !!!cp ('t329');
5308            $self->{insertion_mode} = AFTER_HTML_FRAMESET_IM;            $self->{insertion_mode} = AFTER_HTML_FRAMESET_IM;
5309            !!!next-token;            !!!next-token;
5310            redo B;            redo B;
5311          } else {          } else {
5312            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
5313                !!!cp ('t330');
5314              !!!parse-error (type => 'in frameset:/'.$token->{tag_name});              !!!parse-error (type => 'in frameset:/'.$token->{tag_name});
5315            } else {            } else {
5316                !!!cp ('t331');
5317              !!!parse-error (type => 'after frameset:/'.$token->{tag_name});              !!!parse-error (type => 'after frameset:/'.$token->{tag_name});
5318            }            }
5319            ## Ignore the token            ## Ignore the token
# Line 4591  sub _tree_construction_main ($) { Line 5332  sub _tree_construction_main ($) {
5332      ## "in body" insertion mode      ## "in body" insertion mode
5333      if ($token->{type} == START_TAG_TOKEN) {      if ($token->{type} == START_TAG_TOKEN) {
5334        if ($token->{tag_name} eq 'script') {        if ($token->{tag_name} eq 'script') {
5335            !!!cp ('t332');
5336          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5337          $script_start_tag->($insert);          $script_start_tag->($insert);
5338          redo B;          redo B;
5339        } elsif ($token->{tag_name} eq 'style') {        } elsif ($token->{tag_name} eq 'style') {
5340            !!!cp ('t333');
5341          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5342          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
5343          redo B;          redo B;
5344        } elsif ({        } elsif ({
5345                  base => 1, link => 1,                  base => 1, link => 1,
5346                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5347            !!!cp ('t334');
5348          ## 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
5349          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5350          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 4613  sub _tree_construction_main ($) { Line 5357  sub _tree_construction_main ($) {
5357    
5358          unless ($self->{confident}) {          unless ($self->{confident}) {
5359            if ($token->{attributes}->{charset}) { ## TODO: And if supported            if ($token->{attributes}->{charset}) { ## TODO: And if supported
5360                !!!cp ('t335');
5361              $self->{change_encoding}              $self->{change_encoding}
5362                  ->($self, $token->{attributes}->{charset}->{value});                  ->($self, $token->{attributes}->{charset}->{value});
5363                            
# Line 4627  sub _tree_construction_main ($) { Line 5372  sub _tree_construction_main ($) {
5372                      [\x09-\x0D\x20]*=                      [\x09-\x0D\x20]*=
5373                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
5374                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
5375                  !!!cp ('t336');
5376                $self->{change_encoding}                $self->{change_encoding}
5377                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);
5378                $meta_el->[0]->get_attribute_node_ns (undef, 'content')                $meta_el->[0]->get_attribute_node_ns (undef, 'content')
# Line 4637  sub _tree_construction_main ($) { Line 5383  sub _tree_construction_main ($) {
5383            }            }
5384          } else {          } else {
5385            if ($token->{attributes}->{charset}) {            if ($token->{attributes}->{charset}) {
5386                !!!cp ('t337');
5387              $meta_el->[0]->get_attribute_node_ns (undef, 'charset')              $meta_el->[0]->get_attribute_node_ns (undef, 'charset')
5388                  ->set_user_data (manakai_has_reference =>                  ->set_user_data (manakai_has_reference =>
5389                                       $token->{attributes}->{charset}                                       $token->{attributes}->{charset}
5390                                           ->{has_reference});                                           ->{has_reference});
5391            }            }
5392            if ($token->{attributes}->{content}) {            if ($token->{attributes}->{content}) {
5393                !!!cp ('t338');
5394              $meta_el->[0]->get_attribute_node_ns (undef, 'content')              $meta_el->[0]->get_attribute_node_ns (undef, 'content')
5395                  ->set_user_data (manakai_has_reference =>                  ->set_user_data (manakai_has_reference =>
5396                                       $token->{attributes}->{content}                                       $token->{attributes}->{content}
# Line 4653  sub _tree_construction_main ($) { Line 5401  sub _tree_construction_main ($) {
5401          !!!next-token;          !!!next-token;
5402          redo B;          redo B;
5403        } elsif ($token->{tag_name} eq 'title') {        } elsif ($token->{tag_name} eq 'title') {
5404            !!!cp ('t341');
5405          !!!parse-error (type => 'in body:title');          !!!parse-error (type => 'in body:title');
5406          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5407          $parse_rcdata->(RCDATA_CONTENT_MODEL, sub {          $parse_rcdata->(RCDATA_CONTENT_MODEL, sub {
5408            if (defined $self->{head_element}) {            if (defined $self->{head_element}) {
5409                !!!cp ('t339');
5410              $self->{head_element}->append_child ($_[0]);              $self->{head_element}->append_child ($_[0]);
5411            } else {            } else {
5412                !!!cp ('t340');
5413              $insert->($_[0]);              $insert->($_[0]);
5414            }            }
5415          });          });
# Line 4668  sub _tree_construction_main ($) { Line 5419  sub _tree_construction_main ($) {
5419                                
5420          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
5421              $self->{open_elements}->[1]->[1] ne 'body') {              $self->{open_elements}->[1]->[1] ne 'body') {
5422              !!!cp ('t342');
5423            ## Ignore the token            ## Ignore the token
5424          } else {          } else {
5425            my $body_el = $self->{open_elements}->[1]->[0];            my $body_el = $self->{open_elements}->[1]->[0];
5426            for my $attr_name (keys %{$token->{attributes}}) {            for my $attr_name (keys %{$token->{attributes}}) {
5427              unless ($body_el->has_attribute_ns (undef, $attr_name)) {              unless ($body_el->has_attribute_ns (undef, $attr_name)) {
5428                  !!!cp ('t343');
5429                $body_el->set_attribute_ns                $body_el->set_attribute_ns
5430                  (undef, [undef, $attr_name],                  (undef, [undef, $attr_name],
5431                   $token->{attributes}->{$attr_name}->{value});                   $token->{attributes}->{$attr_name}->{value});
# Line 4690  sub _tree_construction_main ($) { Line 5443  sub _tree_construction_main ($) {
5443          ## has a p element in scope          ## has a p element in scope
5444          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5445            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5446                !!!cp ('t344');
5447              !!!back-token;              !!!back-token;
5448              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5449              redo B;              redo B;
# Line 4697  sub _tree_construction_main ($) { Line 5451  sub _tree_construction_main ($) {
5451                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5452                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5453                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5454                !!!cp ('t345');
5455              last INSCOPE;              last INSCOPE;
5456            }            }
5457          } # INSCOPE          } # INSCOPE
# Line 4707  sub _tree_construction_main ($) { Line 5462  sub _tree_construction_main ($) {
5462            if ($token->{type} == CHARACTER_TOKEN) {            if ($token->{type} == CHARACTER_TOKEN) {
5463              $token->{data} =~ s/^\x0A//;              $token->{data} =~ s/^\x0A//;
5464              unless (length $token->{data}) {              unless (length $token->{data}) {
5465                  !!!cp ('t346');
5466                !!!next-token;                !!!next-token;
5467                } else {
5468                  !!!cp ('t349');
5469              }              }
5470              } else {
5471                !!!cp ('t348');
5472            }            }
5473          } else {          } else {
5474              !!!cp ('t347');
5475            !!!next-token;            !!!next-token;
5476          }          }
5477          redo B;          redo B;
5478        } elsif ($token->{tag_name} eq 'form') {        } elsif ($token->{tag_name} eq 'form') {
5479          if (defined $self->{form_element}) {          if (defined $self->{form_element}) {
5480              !!!cp ('t350');
5481            !!!parse-error (type => 'in form:form');            !!!parse-error (type => 'in form:form');
5482            ## Ignore the token            ## Ignore the token
5483            !!!next-token;            !!!next-token;
# Line 4724  sub _tree_construction_main ($) { Line 5486  sub _tree_construction_main ($) {
5486            ## has a p element in scope            ## has a p element in scope
5487            INSCOPE: for (reverse @{$self->{open_elements}}) {            INSCOPE: for (reverse @{$self->{open_elements}}) {
5488              if ($_->[1] eq 'p') {              if ($_->[1] eq 'p') {
5489                  !!!cp ('t351');
5490                !!!back-token;                !!!back-token;
5491                $token = {type => END_TAG_TOKEN, tag_name => 'p'};                $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5492                redo B;                redo B;
# Line 4731  sub _tree_construction_main ($) { Line 5494  sub _tree_construction_main ($) {
5494                        table => 1, caption => 1, td => 1, th => 1,                        table => 1, caption => 1, td => 1, th => 1,
5495                        button => 1, marquee => 1, object => 1, html => 1,                        button => 1, marquee => 1, object => 1, html => 1,
5496                       }->{$_->[1]}) {                       }->{$_->[1]}) {
5497                  !!!cp ('t352');
5498                last INSCOPE;                last INSCOPE;
5499              }              }
5500            } # INSCOPE            } # INSCOPE
# Line 4744  sub _tree_construction_main ($) { Line 5508  sub _tree_construction_main ($) {
5508          ## has a p element in scope          ## has a p element in scope
5509          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5510            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5511                !!!cp ('t353');
5512              !!!back-token;              !!!back-token;
5513              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5514              redo B;              redo B;
# Line 4751  sub _tree_construction_main ($) { Line 5516  sub _tree_construction_main ($) {
5516                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5517                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5518                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5519                !!!cp ('t354');
5520              last INSCOPE;              last INSCOPE;
5521            }            }
5522          } # INSCOPE          } # INSCOPE
# Line 4762  sub _tree_construction_main ($) { Line 5528  sub _tree_construction_main ($) {
5528            ## Step 2            ## Step 2
5529            if ($node->[1] eq 'li') {            if ($node->[1] eq 'li') {
5530              if ($i != -1) {              if ($i != -1) {
5531                  !!!cp ('t355');
5532                !!!parse-error (type => 'end tag missing:'.                !!!parse-error (type => 'end tag missing:'.
5533                                $self->{open_elements}->[-1]->[1]);                                $self->{open_elements}->[-1]->[1]);
5534                } else {
5535                  !!!cp ('t356');
5536              }              }
5537              splice @{$self->{open_elements}}, $i;              splice @{$self->{open_elements}}, $i;
5538              last LI;              last LI;
5539              } else {
5540                !!!cp ('t357');
5541            }            }
5542                        
5543            ## Step 3            ## Step 3
# Line 4775  sub _tree_construction_main ($) { Line 5546  sub _tree_construction_main ($) {
5546                ($special_category->{$node->[1]} or                ($special_category->{$node->[1]} or
5547                 $scoping_category->{$node->[1]}) and                 $scoping_category->{$node->[1]}) and
5548                $node->[1] ne 'address' and $node->[1] ne 'div') {                $node->[1] ne 'address' and $node->[1] ne 'div') {
5549                !!!cp ('t358');
5550              last LI;              last LI;
5551            }            }
5552                        
5553              !!!cp ('t359');
5554            ## Step 4            ## Step 4
5555            $i--;            $i--;
5556            $node = $self->{open_elements}->[$i];            $node = $self->{open_elements}->[$i];
# Line 4791  sub _tree_construction_main ($) { Line 5564  sub _tree_construction_main ($) {
5564          ## has a p element in scope          ## has a p element in scope
5565          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5566            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5567                !!!cp ('t360');
5568              !!!back-token;              !!!back-token;
5569              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5570              redo B;              redo B;
# Line 4798  sub _tree_construction_main ($) { Line 5572  sub _tree_construction_main ($) {
5572                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5573                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5574                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5575                !!!cp ('t361');
5576              last INSCOPE;              last INSCOPE;
5577            }            }
5578          } # INSCOPE          } # INSCOPE
# Line 4809  sub _tree_construction_main ($) { Line 5584  sub _tree_construction_main ($) {
5584            ## Step 2            ## Step 2
5585            if ($node->[1] eq 'dt' or $node->[1] eq 'dd') {            if ($node->[1] eq 'dt' or $node->[1] eq 'dd') {
5586              if ($i != -1) {              if ($i != -1) {
5587                  !!!cp ('t362');
5588                !!!parse-error (type => 'end tag missing:'.                !!!parse-error (type => 'end tag missing:'.
5589                                $self->{open_elements}->[-1]->[1]);                                $self->{open_elements}->[-1]->[1]);
5590                } else {
5591                  !!!cp ('t363');
5592              }              }
5593              splice @{$self->{open_elements}}, $i;              splice @{$self->{open_elements}}, $i;
5594              last LI;              last LI;
5595              } else {
5596                !!!cp ('t364');
5597            }            }
5598                        
5599            ## Step 3            ## Step 3
# Line 4822  sub _tree_construction_main ($) { Line 5602  sub _tree_construction_main ($) {
5602                ($special_category->{$node->[1]} or                ($special_category->{$node->[1]} or
5603                 $scoping_category->{$node->[1]}) and                 $scoping_category->{$node->[1]}) and
5604                $node->[1] ne 'address' and $node->[1] ne 'div') {                $node->[1] ne 'address' and $node->[1] ne 'div') {
5605                !!!cp ('t365');
5606              last LI;              last LI;
5607            }            }
5608                        
5609              !!!cp ('t366');
5610            ## Step 4            ## Step 4
5611            $i--;            $i--;
5612            $node = $self->{open_elements}->[$i];            $node = $self->{open_elements}->[$i];
# Line 4838  sub _tree_construction_main ($) { Line 5620  sub _tree_construction_main ($) {
5620          ## has a p element in scope          ## has a p element in scope
5621          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5622            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5623                !!!cp ('t367');
5624              !!!back-token;              !!!back-token;
5625              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5626              redo B;              redo B;
# Line 4845  sub _tree_construction_main ($) { Line 5628  sub _tree_construction_main ($) {
5628                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5629                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5630                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5631                !!!cp ('t368');
5632              last INSCOPE;              last INSCOPE;
5633            }            }
5634          } # INSCOPE          } # INSCOPE
# Line 4862  sub _tree_construction_main ($) { Line 5646  sub _tree_construction_main ($) {
5646          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5647            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
5648            if ($node->[1] eq 'p') {            if ($node->[1] eq 'p') {
5649                !!!cp ('t369');
5650              !!!back-token;              !!!back-token;
5651              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5652              redo B;              redo B;
# Line 4869  sub _tree_construction_main ($) { Line 5654  sub _tree_construction_main ($) {
5654                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5655                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5656                     }->{$node->[1]}) {                     }->{$node->[1]}) {
5657                !!!cp ('t370');
5658              last INSCOPE;              last INSCOPE;
5659            }            }
5660          } # INSCOPE          } # INSCOPE
# Line 4904  sub _tree_construction_main ($) { Line 5690  sub _tree_construction_main ($) {
5690          AFE: for my $i (reverse 0..$#$active_formatting_elements) {          AFE: for my $i (reverse 0..$#$active_formatting_elements) {
5691            my $node = $active_formatting_elements->[$i];            my $node = $active_formatting_elements->[$i];
5692            if ($node->[1] eq 'a') {            if ($node->[1] eq 'a') {
5693                !!!cp ('t371');
5694              !!!parse-error (type => 'in a:a');              !!!parse-error (type => 'in a:a');
5695                            
5696              !!!back-token;              !!!back-token;
# Line 4912  sub _tree_construction_main ($) { Line 5699  sub _tree_construction_main ($) {
5699                            
5700              AFE2: for (reverse 0..$#$active_formatting_elements) {              AFE2: for (reverse 0..$#$active_formatting_elements) {
5701                if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {                if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {
5702                    !!!cp ('t372');
5703                  splice @$active_formatting_elements, $_, 1;                  splice @$active_formatting_elements, $_, 1;
5704                  last AFE2;                  last AFE2;
5705                }                }
5706              } # AFE2              } # AFE2
5707              OE: for (reverse 0..$#{$self->{open_elements}}) {              OE: for (reverse 0..$#{$self->{open_elements}}) {
5708                if ($self->{open_elements}->[$_]->[0] eq $node->[0]) {                if ($self->{open_elements}->[$_]->[0] eq $node->[0]) {
5709                    !!!cp ('t373');
5710                  splice @{$self->{open_elements}}, $_, 1;                  splice @{$self->{open_elements}}, $_, 1;
5711                  last OE;                  last OE;
5712                }                }
5713              } # OE              } # OE
5714              last AFE;              last AFE;
5715            } elsif ($node->[0] eq '#marker') {            } elsif ($node->[0] eq '#marker') {
5716                !!!cp ('t374');
5717              last AFE;              last AFE;
5718            }            }
5719          } # AFE          } # AFE
# Line 4940  sub _tree_construction_main ($) { Line 5730  sub _tree_construction_main ($) {
5730                  s => 1, small => 1, strile => 1,                  s => 1, small => 1, strile => 1,
5731                  strong => 1, tt => 1, u => 1,                  strong => 1, tt => 1, u => 1,
5732                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5733            !!!cp ('t375');
5734          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5735                    
5736          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 4954  sub _tree_construction_main ($) { Line 5745  sub _tree_construction_main ($) {
5745          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5746            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
5747            if ($node->[1] eq 'nobr') {            if ($node->[1] eq 'nobr') {
5748                !!!cp ('t376');
5749              !!!parse-error (type => 'in nobr:nobr');              !!!parse-error (type => 'in nobr:nobr');
5750              !!!back-token;              !!!back-token;
5751              $token = {type => END_TAG_TOKEN, tag_name => 'nobr'};              $token = {type => END_TAG_TOKEN, tag_name => 'nobr'};
# Line 4962  sub _tree_construction_main ($) { Line 5754  sub _tree_construction_main ($) {
5754                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5755                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5756                     }->{$node->[1]}) {                     }->{$node->[1]}) {
5757                !!!cp ('t377');
5758              last INSCOPE;              last INSCOPE;
5759            }            }
5760          } # INSCOPE          } # INSCOPE
# Line 4976  sub _tree_construction_main ($) { Line 5769  sub _tree_construction_main ($) {
5769          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5770            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
5771            if ($node->[1] eq 'button') {            if ($node->[1] eq 'button') {
5772                !!!cp ('t378');
5773              !!!parse-error (type => 'in button:button');              !!!parse-error (type => 'in button:button');
5774              !!!back-token;              !!!back-token;
5775              $token = {type => END_TAG_TOKEN, tag_name => 'button'};              $token = {type => END_TAG_TOKEN, tag_name => 'button'};
# Line 4984  sub _tree_construction_main ($) { Line 5778  sub _tree_construction_main ($) {
5778                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5779                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5780                     }->{$node->[1]}) {                     }->{$node->[1]}) {
5781                !!!cp ('t379');
5782              last INSCOPE;              last INSCOPE;
5783            }            }
5784          } # INSCOPE          } # INSCOPE
# Line 4997  sub _tree_construction_main ($) { Line 5792  sub _tree_construction_main ($) {
5792          redo B;          redo B;
5793        } elsif ($token->{tag_name} eq 'marquee' or        } elsif ($token->{tag_name} eq 'marquee' or
5794                 $token->{tag_name} eq 'object') {                 $token->{tag_name} eq 'object') {
5795            !!!cp ('t380');
5796          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5797                    
5798          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 5005  sub _tree_construction_main ($) { Line 5801  sub _tree_construction_main ($) {
5801          !!!next-token;          !!!next-token;
5802          redo B;          redo B;
5803        } elsif ($token->{tag_name} eq 'xmp') {        } elsif ($token->{tag_name} eq 'xmp') {
5804            !!!cp ('t381');
5805          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5806          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
5807          redo B;          redo B;
# Line 5012  sub _tree_construction_main ($) { Line 5809  sub _tree_construction_main ($) {
5809          ## has a p element in scope          ## has a p element in scope
5810          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5811            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5812                !!!cp ('t382');
5813              !!!back-token;              !!!back-token;
5814              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5815              redo B;              redo B;
# Line 5019  sub _tree_construction_main ($) { Line 5817  sub _tree_construction_main ($) {
5817                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5818                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5819                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5820                !!!cp ('t383');
5821              last INSCOPE;              last INSCOPE;
5822            }            }
5823          } # INSCOPE          } # INSCOPE
# Line 5035  sub _tree_construction_main ($) { Line 5834  sub _tree_construction_main ($) {
5834                  image => 1,                  image => 1,
5835                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5836          if ($token->{tag_name} eq 'image') {          if ($token->{tag_name} eq 'image') {
5837              !!!cp ('t384');
5838            !!!parse-error (type => 'image');            !!!parse-error (type => 'image');
5839            $token->{tag_name} = 'img';            $token->{tag_name} = 'img';
5840            } else {
5841              !!!cp ('t385');
5842          }          }
5843    
5844          ## NOTE: There is an "as if <br>" code clone.          ## NOTE: There is an "as if <br>" code clone.
# Line 5051  sub _tree_construction_main ($) { Line 5853  sub _tree_construction_main ($) {
5853          ## has a p element in scope          ## has a p element in scope
5854          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5855            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5856                !!!cp ('t386');
5857              !!!back-token;              !!!back-token;
5858              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5859              redo B;              redo B;
# Line 5058  sub _tree_construction_main ($) { Line 5861  sub _tree_construction_main ($) {
5861                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5862                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5863                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5864                !!!cp ('t387');
5865              last INSCOPE;              last INSCOPE;
5866            }            }
5867          } # INSCOPE          } # INSCOPE
# Line 5068  sub _tree_construction_main ($) { Line 5872  sub _tree_construction_main ($) {
5872          !!!next-token;          !!!next-token;
5873          redo B;          redo B;
5874        } elsif ($token->{tag_name} eq 'input') {        } elsif ($token->{tag_name} eq 'input') {
5875            !!!cp ('t388');
5876          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5877                    
5878          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 5080  sub _tree_construction_main ($) { Line 5885  sub _tree_construction_main ($) {
5885          !!!parse-error (type => 'isindex');          !!!parse-error (type => 'isindex');
5886                    
5887          if (defined $self->{form_element}) {          if (defined $self->{form_element}) {
5888              !!!cp ('t389');
5889            ## Ignore the token            ## Ignore the token
5890            !!!next-token;            !!!next-token;
5891            redo B;            redo B;
# Line 5099  sub _tree_construction_main ($) { Line 5905  sub _tree_construction_main ($) {
5905                          {type => START_TAG_TOKEN, tag_name => 'label'},                          {type => START_TAG_TOKEN, tag_name => 'label'},
5906                         );                         );
5907            if ($prompt_attr) {            if ($prompt_attr) {
5908                !!!cp ('t390');
5909              push @tokens, {type => CHARACTER_TOKEN, data => $prompt_attr->{value}};              push @tokens, {type => CHARACTER_TOKEN, data => $prompt_attr->{value}};
5910            } else {            } else {
5911                !!!cp ('t391');
5912              push @tokens, {type => CHARACTER_TOKEN,              push @tokens, {type => CHARACTER_TOKEN,
5913                             data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD                             data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD
5914              ## TODO: make this configurable              ## TODO: make this configurable
# Line 5132  sub _tree_construction_main ($) { Line 5940  sub _tree_construction_main ($) {
5940          if ($token->{type} == CHARACTER_TOKEN) {          if ($token->{type} == CHARACTER_TOKEN) {
5941            $token->{data} =~ s/^\x0A//;            $token->{data} =~ s/^\x0A//;
5942            unless (length $token->{data}) {            unless (length $token->{data}) {
5943                !!!cp ('t392');
5944              !!!next-token;              !!!next-token;
5945              } else {
5946                !!!cp ('t393');
5947            }            }
5948            } else {
5949              !!!cp ('t394');
5950          }          }
5951          while ($token->{type} == CHARACTER_TOKEN) {          while ($token->{type} == CHARACTER_TOKEN) {
5952              !!!cp ('t395');
5953            $text .= $token->{data};            $text .= $token->{data};
5954            !!!next-token;            !!!next-token;
5955          }          }
5956          if (length $text) {          if (length $text) {
5957              !!!cp ('t396');
5958            $el->manakai_append_text ($text);            $el->manakai_append_text ($text);
5959          }          }
5960                    
# Line 5147  sub _tree_construction_main ($) { Line 5962  sub _tree_construction_main ($) {
5962                    
5963          if ($token->{type} == END_TAG_TOKEN and          if ($token->{type} == END_TAG_TOKEN and
5964              $token->{tag_name} eq $tag_name) {              $token->{tag_name} eq $tag_name) {
5965              !!!cp ('t397');
5966            ## Ignore the token            ## Ignore the token
5967          } else {          } else {
5968              !!!cp ('t398');
5969            !!!parse-error (type => 'in RCDATA:#'.$token->{type});            !!!parse-error (type => 'in RCDATA:#'.$token->{type});
5970          }          }
5971          !!!next-token;          !!!next-token;
# Line 5159  sub _tree_construction_main ($) { Line 5976  sub _tree_construction_main ($) {
5976                  noframes => 1,                  noframes => 1,
5977                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
5978                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5979            !!!cp ('t399');
5980          ## NOTE: There is an "as if in body" code clone.          ## NOTE: There is an "as if in body" code clone.
5981          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
5982          redo B;          redo B;
5983        } elsif ($token->{tag_name} eq 'select') {        } elsif ($token->{tag_name} eq 'select') {
5984            !!!cp ('t400');
5985          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5986                    
5987          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 5176  sub _tree_construction_main ($) { Line 5995  sub _tree_construction_main ($) {
5995                  tbody => 1, td => 1, tfoot => 1, th => 1,                  tbody => 1, td => 1, tfoot => 1, th => 1,
5996                  thead => 1, tr => 1,                  thead => 1, tr => 1,
5997                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5998            !!!cp ('t401');
5999          !!!parse-error (type => 'in body:'.$token->{tag_name});          !!!parse-error (type => 'in body:'.$token->{tag_name});
6000          ## Ignore the token          ## Ignore the token
6001          !!!next-token;          !!!next-token;
# Line 5183  sub _tree_construction_main ($) { Line 6003  sub _tree_construction_main ($) {
6003                    
6004          ## ISSUE: An issue on HTML5 new elements in the spec.          ## ISSUE: An issue on HTML5 new elements in the spec.
6005        } else {        } else {
6006            !!!cp ('t402');
6007          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
6008                    
6009          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 5200  sub _tree_construction_main ($) { Line 6021  sub _tree_construction_main ($) {
6021                         th => 1, tr => 1, body => 1, html => 1,                         th => 1, tr => 1, body => 1, html => 1,
6022                       tbody => 1, tfoot => 1, thead => 1,                       tbody => 1, tfoot => 1, thead => 1,
6023                      }->{$_->[1]}) {                      }->{$_->[1]}) {
6024                  !!!cp ('t403');
6025                !!!parse-error (type => 'not closed:'.$_->[1]);                !!!parse-error (type => 'not closed:'.$_->[1]);
6026                } else {
6027                  !!!cp ('t404');
6028              }              }
6029            }            }
6030    
# Line 5208  sub _tree_construction_main ($) { Line 6032  sub _tree_construction_main ($) {
6032            !!!next-token;            !!!next-token;
6033            redo B;            redo B;
6034          } else {          } else {
6035              !!!cp ('t405');
6036            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6037            ## Ignore the token            ## Ignore the token
6038            !!!next-token;            !!!next-token;
# Line 5217  sub _tree_construction_main ($) { Line 6042  sub _tree_construction_main ($) {
6042          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') {
6043            ## ISSUE: There is an issue in the spec.            ## ISSUE: There is an issue in the spec.
6044            if ($self->{open_elements}->[-1]->[1] ne 'body') {            if ($self->{open_elements}->[-1]->[1] ne 'body') {
6045                !!!cp ('t406');
6046              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[1]->[1]);              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[1]->[1]);
6047              } else {
6048                !!!cp ('t407');
6049            }            }
6050            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6051            ## reprocess            ## reprocess
6052            redo B;            redo B;
6053          } else {          } else {
6054              !!!cp ('t408');
6055            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6056            ## Ignore the token            ## Ignore the token
6057            !!!next-token;            !!!next-token;
# Line 5250  sub _tree_construction_main ($) { Line 6079  sub _tree_construction_main ($) {
6079                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
6080                   tbody => 1, tfoot=> 1, thead => 1,                   tbody => 1, tfoot=> 1, thead => 1,
6081                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
6082                  !!!cp ('t409');
6083                !!!back-token;                !!!back-token;
6084                $token = {type => END_TAG_TOKEN,                $token = {type => END_TAG_TOKEN,
6085                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
6086                redo B;                redo B;
6087              }              }
6088                
6089                !!!cp ('t410');
6090              $i = $_;              $i = $_;
6091              last INSCOPE unless $token->{tag_name} eq 'p';              last INSCOPE unless $token->{tag_name} eq 'p';
6092            } elsif ({            } elsif ({
6093                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
6094                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6095                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6096                !!!cp ('t411');
6097              last INSCOPE;              last INSCOPE;
6098            }            }
6099          } # INSCOPE          } # INSCOPE
6100                    
6101          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6102            if (defined $i) {            if (defined $i) {
6103                !!!cp ('t412');
6104              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6105            } else {            } else {
6106                !!!cp ('t413');
6107              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6108            }            }
6109          }          }
6110                    
6111          if (defined $i) {          if (defined $i) {
6112              !!!cp ('t414');
6113            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
6114          } elsif ($token->{tag_name} eq 'p') {          } elsif ($token->{tag_name} eq 'p') {
6115              !!!cp ('t415');
6116            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
6117            my $el;            my $el;
6118            !!!create-element ($el, 'p');            !!!create-element ($el, 'p');
6119            $insert->($el);            $insert->($el);
6120            } else {
6121              !!!cp ('t416');
6122          }          }
6123          $clear_up_to_marker->()          $clear_up_to_marker->()
6124            if {            if {
# Line 5295  sub _tree_construction_main ($) { Line 6134  sub _tree_construction_main ($) {
6134              ## generate implied end tags              ## generate implied end tags
6135              if ({              if ({
6136                   dd => 1, dt => 1, li => 1, p => 1,                   dd => 1, dt => 1, li => 1, p => 1,
6137    
6138                     ## NOTE: The following elements never appear here, maybe.
6139                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
6140                   tbody => 1, tfoot=> 1, thead => 1,                   tbody => 1, tfoot => 1, thead => 1,
6141                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
6142                  !!!cp ('t417');
6143                !!!back-token;                !!!back-token;
6144                $token = {type => END_TAG_TOKEN,                $token = {type => END_TAG_TOKEN,
6145                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
6146                redo B;                redo B;
6147              }              }
6148                
6149                !!!cp ('t418');
6150              last INSCOPE;              last INSCOPE;
6151            } elsif ({            } elsif ({
6152                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
6153                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6154                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6155                !!!cp ('t419');
6156              last INSCOPE;              last INSCOPE;
6157            }            }
6158          } # INSCOPE          } # INSCOPE
6159                    
6160          if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) {          if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) {
6161              !!!cp ('t420');
6162            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
6163          } else {          } else {
6164              !!!cp ('t421');
6165            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6166          }          }
6167    
# Line 5337  sub _tree_construction_main ($) { Line 6184  sub _tree_construction_main ($) {
6184                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
6185                   tbody => 1, tfoot=> 1, thead => 1,                   tbody => 1, tfoot=> 1, thead => 1,
6186                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
6187                  !!!cp ('t422');
6188                !!!back-token;                !!!back-token;
6189                $token = {type => END_TAG_TOKEN,                $token = {type => END_TAG_TOKEN,
6190                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
6191                redo B;                redo B;
6192              }              }
6193    
6194                !!!cp ('t423');
6195              $i = $_;              $i = $_;
6196              last INSCOPE;              last INSCOPE;
6197            } elsif ({            } elsif ({
6198                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
6199                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6200                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6201                !!!cp ('t424');
6202              last INSCOPE;              last INSCOPE;
6203            }            }
6204          } # INSCOPE          } # INSCOPE
6205                    
6206          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6207              !!!cp ('t425');
6208            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6209            } else {
6210              !!!cp ('t426');
6211          }          }
6212                    
6213          splice @{$self->{open_elements}}, $i if defined $i;          splice @{$self->{open_elements}}, $i if defined $i;
# Line 5365  sub _tree_construction_main ($) { Line 6219  sub _tree_construction_main ($) {
6219                  nobr => 1, s => 1, small => 1, strile => 1,                  nobr => 1, s => 1, small => 1, strile => 1,
6220                  strong => 1, tt => 1, u => 1,                  strong => 1, tt => 1, u => 1,
6221                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6222            !!!cp ('t427');
6223          $formatting_end_tag->($token->{tag_name});          $formatting_end_tag->($token->{tag_name});
6224          redo B;          redo B;
6225        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
6226            !!!cp ('t428');
6227          !!!parse-error (type => 'unmatched end tag:br');          !!!parse-error (type => 'unmatched end tag:br');
6228    
6229          ## As if <br>          ## As if <br>
# Line 5392  sub _tree_construction_main ($) { Line 6248  sub _tree_construction_main ($) {
6248                  table => 1, textarea => 1, wbr => 1,                  table => 1, textarea => 1, wbr => 1,
6249                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
6250                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6251            !!!cp ('t429');
6252          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6253          ## Ignore the token          ## Ignore the token
6254          !!!next-token;          !!!next-token;
# Line 5414  sub _tree_construction_main ($) { Line 6271  sub _tree_construction_main ($) {
6271                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
6272                   tbody => 1, tfoot => 1, thead => 1,                   tbody => 1, tfoot => 1, thead => 1,
6273                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
6274                  !!!cp ('t430');
6275                  ## ISSUE: Can this case be reached?
6276                !!!back-token;                !!!back-token;
6277                $token = {type => END_TAG_TOKEN,                $token = {type => END_TAG_TOKEN,
6278                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
# Line 5422  sub _tree_construction_main ($) { Line 6281  sub _tree_construction_main ($) {
6281                    
6282              ## Step 2              ## Step 2
6283              if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) {              if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) {
6284                  !!!cp ('t431');
6285                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
6286                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6287                } else {
6288                  !!!cp ('t432');
6289              }              }
6290                            
6291              ## Step 3              ## Step 3
# Line 5437  sub _tree_construction_main ($) { Line 6299  sub _tree_construction_main ($) {
6299                  #not $phrasing_category->{$node->[1]} and                  #not $phrasing_category->{$node->[1]} and
6300                  ($special_category->{$node->[1]} or                  ($special_category->{$node->[1]} or
6301                   $scoping_category->{$node->[1]})) {                   $scoping_category->{$node->[1]})) {
6302                  !!!cp ('t433');
6303                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6304                ## Ignore the token                ## Ignore the token
6305                !!!next-token;                !!!next-token;
6306                last S2;                last S2;
6307              }              }
6308    
6309                !!!cp ('t434');
6310            }            }
6311                        
6312            ## Step 4            ## Step 4
# Line 5507  sub set_inner_html ($$$) { Line 6372  sub set_inner_html ($$$) {
6372      my $i = 0;      my $i = 0;
6373      my $line = 1;      my $line = 1;
6374      my $column = 0;      my $column = 0;
6375      $p->{set_next_input_character} = sub {      $p->{set_next_char} = sub {
6376        my $self = shift;        my $self = shift;
6377    
6378        pop @{$self->{prev_input_character}};        pop @{$self->{prev_char}};
6379        unshift @{$self->{prev_input_character}}, $self->{next_input_character};        unshift @{$self->{prev_char}}, $self->{next_char};
6380    
6381        $self->{next_input_character} = -1 and return if $i >= length $$s;        $self->{next_char} = -1 and return if $i >= length $$s;
6382        $self->{next_input_character} = ord substr $$s, $i++, 1;        $self->{next_char} = ord substr $$s, $i++, 1;
6383        $column++;        $column++;
6384    
6385        if ($self->{next_input_character} == 0x000A) { # LF        if ($self->{next_char} == 0x000A) { # LF
6386          $line++;          $line++;
6387          $column = 0;          $column = 0;
6388        } elsif ($self->{next_input_character} == 0x000D) { # CR          !!!cp ('i1');
6389          } elsif ($self->{next_char} == 0x000D) { # CR
6390          $i++ if substr ($$s, $i, 1) eq "\x0A";          $i++ if substr ($$s, $i, 1) eq "\x0A";
6391          $self->{next_input_character} = 0x000A; # LF # MUST          $self->{next_char} = 0x000A; # LF # MUST
6392          $line++;          $line++;
6393          $column = 0;          $column = 0;
6394        } elsif ($self->{next_input_character} > 0x10FFFF) {          !!!cp ('i2');
6395          $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        } elsif ($self->{next_char} > 0x10FFFF) {
6396        } elsif ($self->{next_input_character} == 0x0000) { # NULL          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
6397            !!!cp ('i3');
6398          } elsif ($self->{next_char} == 0x0000) { # NULL
6399            !!!cp ('i4');
6400          !!!parse-error (type => 'NULL');          !!!parse-error (type => 'NULL');
6401          $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
6402        }        }
6403      };      };
6404      $p->{prev_input_character} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];
6405      $p->{next_input_character} = -1;      $p->{next_char} = -1;
6406            
6407      my $ponerror = $onerror || sub {      my $ponerror = $onerror || sub {
6408        my (%opt) = @_;        my (%opt) = @_;
# Line 5588  sub set_inner_html ($$$) { Line 6457  sub set_inner_html ($$$) {
6457          my $nsuri = $anode->namespace_uri;          my $nsuri = $anode->namespace_uri;
6458          if (defined $nsuri and $nsuri eq 'http://www.w3.org/1999/xhtml') {          if (defined $nsuri and $nsuri eq 'http://www.w3.org/1999/xhtml') {
6459            if ($anode->manakai_local_name eq 'form') {            if ($anode->manakai_local_name eq 'form') {
6460                !!!cp ('i5');
6461              $p->{form_element} = $anode;              $p->{form_element} = $anode;
6462              last AN;              last AN;
6463            }            }

Legend:
Removed from v.1.72  
changed lines
  Added in v.1.83

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24