/[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.35 by wakaba, Mon Jul 16 03:21:04 2007 UTC revision 1.45 by wakaba, Sat Jul 21 08:17:43 2007 UTC
# Line 150  sub new ($) { Line 150  sub new ($) {
150    return $self;    return $self;
151  } # new  } # new
152    
153    sub CM_ENTITY () { 0b001 } # & markup in data
154    sub CM_LIMITED_MARKUP () { 0b010 } # < markup in data (limited)
155    sub CM_FULL_MARKUP () { 0b100 } # < markup in data (any)
156    
157    sub PLAINTEXT_CONTENT_MODEL () { 0 }
158    sub CDATA_CONTENT_MODEL () { CM_LIMITED_MARKUP }
159    sub RCDATA_CONTENT_MODEL () { CM_ENTITY | CM_LIMITED_MARKUP }
160    sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }
161    
162  ## Implementations MUST act as if state machine in the spec  ## Implementations MUST act as if state machine in the spec
163    
164  sub _initialize_tokenizer ($) {  sub _initialize_tokenizer ($) {
165    my $self = shift;    my $self = shift;
166    $self->{state} = 'data'; # MUST    $self->{state} = 'data'; # MUST
167    $self->{content_model_flag} = 'PCDATA'; # be    $self->{content_model} = PCDATA_CONTENT_MODEL; # be
168    undef $self->{current_token}; # start tag, end tag, comment, or DOCTYPE    undef $self->{current_token}; # start tag, end tag, comment, or DOCTYPE
169    undef $self->{current_attribute};    undef $self->{current_attribute};
170    undef $self->{last_emitted_start_tag_name};    undef $self->{last_emitted_start_tag_name};
# Line 194  sub _get_next_token ($) { Line 203  sub _get_next_token ($) {
203    A: {    A: {
204      if ($self->{state} eq 'data') {      if ($self->{state} eq 'data') {
205        if ($self->{next_input_character} == 0x0026) { # &        if ($self->{next_input_character} == 0x0026) { # &
206          if ($self->{content_model_flag} eq 'PCDATA' or          if ($self->{content_model} & CM_ENTITY) { # PCDATA | RCDATA
             $self->{content_model_flag} eq 'RCDATA') {  
207            $self->{state} = 'entity data';            $self->{state} = 'entity data';
208            !!!next-input-character;            !!!next-input-character;
209            redo A;            redo A;
# Line 203  sub _get_next_token ($) { Line 211  sub _get_next_token ($) {
211            #            #
212          }          }
213        } elsif ($self->{next_input_character} == 0x002D) { # -        } elsif ($self->{next_input_character} == 0x002D) { # -
214          if ($self->{content_model_flag} eq 'RCDATA' or          if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
             $self->{content_model_flag} eq 'CDATA') {  
215            unless ($self->{escape}) {            unless ($self->{escape}) {
216              if ($self->{prev_input_character}->[0] == 0x002D and # -              if ($self->{prev_input_character}->[0] == 0x002D and # -
217                  $self->{prev_input_character}->[1] == 0x0021 and # !                  $self->{prev_input_character}->[1] == 0x0021 and # !
# Line 216  sub _get_next_token ($) { Line 223  sub _get_next_token ($) {
223                    
224          #          #
225        } elsif ($self->{next_input_character} == 0x003C) { # <        } elsif ($self->{next_input_character} == 0x003C) { # <
226          if ($self->{content_model_flag} eq 'PCDATA' or          if ($self->{content_model} & CM_FULL_MARKUP or # PCDATA
227              (($self->{content_model_flag} eq 'CDATA' or              (($self->{content_model} & CM_LIMITED_MARKUP) and # CDATA | RCDATA
               $self->{content_model_flag} eq 'RCDATA') and  
228               not $self->{escape})) {               not $self->{escape})) {
229            $self->{state} = 'tag open';            $self->{state} = 'tag open';
230            !!!next-input-character;            !!!next-input-character;
# Line 228  sub _get_next_token ($) { Line 234  sub _get_next_token ($) {
234          }          }
235        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
236          if ($self->{escape} and          if ($self->{escape} and
237              ($self->{content_model_flag} eq 'RCDATA' or              ($self->{content_model} & CM_LIMITED_MARKUP)) { # RCDATA | CDATA
              $self->{content_model_flag} eq 'CDATA')) {  
238            if ($self->{prev_input_character}->[0] == 0x002D and # -            if ($self->{prev_input_character}->[0] == 0x002D and # -
239                $self->{prev_input_character}->[1] == 0x002D) { # -                $self->{prev_input_character}->[1] == 0x002D) { # -
240              delete $self->{escape};              delete $self->{escape};
# Line 266  sub _get_next_token ($) { Line 271  sub _get_next_token ($) {
271    
272        redo A;        redo A;
273      } elsif ($self->{state} eq 'tag open') {      } elsif ($self->{state} eq 'tag open') {
274        if ($self->{content_model_flag} eq 'RCDATA' or        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
           $self->{content_model_flag} eq 'CDATA') {  
275          if ($self->{next_input_character} == 0x002F) { # /          if ($self->{next_input_character} == 0x002F) { # /
276            !!!next-input-character;            !!!next-input-character;
277            $self->{state} = 'close tag open';            $self->{state} = 'close tag open';
# Line 280  sub _get_next_token ($) { Line 284  sub _get_next_token ($) {
284    
285            redo A;            redo A;
286          }          }
287        } elsif ($self->{content_model_flag} eq 'PCDATA') {        } elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA
288          if ($self->{next_input_character} == 0x0021) { # !          if ($self->{next_input_character} == 0x0021) { # !
289            $self->{state} = 'markup declaration open';            $self->{state} = 'markup declaration open';
290            !!!next-input-character;            !!!next-input-character;
# Line 327  sub _get_next_token ($) { Line 331  sub _get_next_token ($) {
331            redo A;            redo A;
332          }          }
333        } else {        } else {
334          die "$0: $self->{content_model_flag}: Unknown content model flag";          die "$0: $self->{content_model} in tag open";
335        }        }
336      } elsif ($self->{state} eq 'close tag open') {      } elsif ($self->{state} eq 'close tag open') {
337        if ($self->{content_model_flag} eq 'RCDATA' or        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
           $self->{content_model_flag} eq 'CDATA') {  
338          if (defined $self->{last_emitted_start_tag_name}) {          if (defined $self->{last_emitted_start_tag_name}) {
339            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>
340            my @next_char;            my @next_char;
# Line 429  sub _get_next_token ($) { Line 432  sub _get_next_token ($) {
432                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
433            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
434          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
435            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
436            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
437              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
438            }            }
# Line 456  sub _get_next_token ($) { Line 459  sub _get_next_token ($) {
459                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
460            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
461          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
462            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
463            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
464              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
465            }            }
# Line 504  sub _get_next_token ($) { Line 507  sub _get_next_token ($) {
507                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
508            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
509          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
510            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
511            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
512              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
513            }            }
# Line 544  sub _get_next_token ($) { Line 547  sub _get_next_token ($) {
547                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
548            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
549          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
550            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
551            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
552              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
553            }            }
# Line 568  sub _get_next_token ($) { Line 571  sub _get_next_token ($) {
571        my $before_leave = sub {        my $before_leave = sub {
572          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
573              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
574            !!!parse-error (type => 'dupulicate attribute');            !!!parse-error (type => 'duplicate attribute:'.$self->{current_attribute}->{name});
575            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{current_attribute} # MUST
576          } else {          } else {
577            $self->{current_token}->{attributes}->{$self->{current_attribute}->{name}}            $self->{current_token}->{attributes}->{$self->{current_attribute}->{name}}
# Line 597  sub _get_next_token ($) { Line 600  sub _get_next_token ($) {
600                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
601            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
602          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
603            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
604            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
605              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
606            }            }
# Line 638  sub _get_next_token ($) { Line 641  sub _get_next_token ($) {
641                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
642            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
643          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
644            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
645            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
646              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
647            }            }
# Line 676  sub _get_next_token ($) { Line 679  sub _get_next_token ($) {
679                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
680            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
681          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
682            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
683            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
684              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
685            }            }
# Line 717  sub _get_next_token ($) { Line 720  sub _get_next_token ($) {
720                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
721            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
722          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
723            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
724            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
725              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
726            }            }
# Line 764  sub _get_next_token ($) { Line 767  sub _get_next_token ($) {
767                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
768            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
769          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
770            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
771            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
772              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
773            }            }
# Line 784  sub _get_next_token ($) { Line 787  sub _get_next_token ($) {
787                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
788            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
789          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
790            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
791            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
792              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
793            }            }
# Line 820  sub _get_next_token ($) { Line 823  sub _get_next_token ($) {
823                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
824            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
825          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
826            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
827            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
828              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
829            }            }
# Line 856  sub _get_next_token ($) { Line 859  sub _get_next_token ($) {
859                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
860            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
861          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
862            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
863            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
864              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
865            }            }
# Line 895  sub _get_next_token ($) { Line 898  sub _get_next_token ($) {
898                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
899            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
900          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
901            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
902            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
903              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
904            }            }
# Line 915  sub _get_next_token ($) { Line 918  sub _get_next_token ($) {
918                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
919            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
920          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
921            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
922            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
923              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
924            }            }
# Line 1644  sub _tokenize_attempt_to_consume_an_enti Line 1647  sub _tokenize_attempt_to_consume_an_enti
1647            redo X;            redo X;
1648          } elsif (not defined $code) { # no hexadecimal digit          } elsif (not defined $code) { # no hexadecimal digit
1649            !!!parse-error (type => 'bare hcro');            !!!parse-error (type => 'bare hcro');
1650              !!!back-next-input-character ($x_char, $self->{next_input_character});
1651            $self->{next_input_character} = 0x0023; # #            $self->{next_input_character} = 0x0023; # #
           !!!back-next-input-character ($x_char);  
1652            return undef;            return undef;
1653          } elsif ($self->{next_input_character} == 0x003B) { # ;          } elsif ($self->{next_input_character} == 0x003B) { # ;
1654            !!!next-input-character;            !!!next-input-character;
# Line 1717  sub _tokenize_attempt_to_consume_an_enti Line 1720  sub _tokenize_attempt_to_consume_an_enti
1720      !!!next-input-character;      !!!next-input-character;
1721    
1722      my $value = $entity_name;      my $value = $entity_name;
1723      my $match;      my $match = 0;
1724      require Whatpm::_NamedEntityList;      require Whatpm::_NamedEntityList;
1725      our $EntityChar;      our $EntityChar;
1726    
# Line 1737  sub _tokenize_attempt_to_consume_an_enti Line 1740  sub _tokenize_attempt_to_consume_an_enti
1740            $match = 1;            $match = 1;
1741            !!!next-input-character;            !!!next-input-character;
1742            last;            last;
1743          } elsif (not $in_attr) {          } else {
1744            $value = $EntityChar->{$entity_name};            $value = $EntityChar->{$entity_name};
1745            $match = -1;            $match = -1;
1746          } else {            !!!next-input-character;
           $value .= chr $self->{next_input_character};  
1747          }          }
1748        } else {        } else {
1749          $value .= chr $self->{next_input_character};          $value .= chr $self->{next_input_character};
1750            $match *= 2;
1751            !!!next-input-character;
1752        }        }
       !!!next-input-character;  
1753      }      }
1754            
1755      if ($match > 0) {      if ($match > 0) {
1756        return {type => 'character', data => $value};        return {type => 'character', data => $value};
1757      } elsif ($match < 0) {      } elsif ($match < 0) {
1758        !!!parse-error (type => 'no refc');        !!!parse-error (type => 'no refc');
1759        return {type => 'character', data => $value};        if ($in_attr and $match < -1) {
1760            return {type => 'character', data => '&'.$entity_name};
1761          } else {
1762            return {type => 'character', data => $value};
1763          }
1764      } else {      } else {
1765        !!!parse-error (type => 'bare ero');        !!!parse-error (type => 'bare ero');
1766        ## NOTE: No characters are consumed in the spec.        ## NOTE: No characters are consumed in the spec.
# Line 2060  sub _reset_insertion_mode ($) { Line 2067  sub _reset_insertion_mode ($) {
2067                        th => 'in cell',                        th => 'in cell',
2068                        tr => 'in row',                        tr => 'in row',
2069                        tbody => 'in table body',                        tbody => 'in table body',
2070                        thead => 'in table head',                        thead => 'in table body',
2071                        tfoot => 'in table foot',                        tfoot => 'in table body',
2072                        caption => 'in caption',                        caption => 'in caption',
2073                        colgroup => 'in column group',                        colgroup => 'in column group',
2074                        table => 'in table',                        table => 'in table',
# Line 2192  sub _tree_construction_main ($) { Line 2199  sub _tree_construction_main ($) {
2199      $insert->($el); # /context node/->append_child ($el)      $insert->($el); # /context node/->append_child ($el)
2200    
2201      ## Step 3      ## Step 3
2202      $self->{content_model_flag} = $content_model_flag; # CDATA or RCDATA      $self->{content_model} = $content_model_flag; # CDATA or RCDATA
2203      delete $self->{escape}; # MUST      delete $self->{escape}; # MUST
2204    
2205      ## Step 4      ## Step 4
# Line 2210  sub _tree_construction_main ($) { Line 2217  sub _tree_construction_main ($) {
2217      }      }
2218    
2219      ## Step 6      ## Step 6
2220      $self->{content_model_flag} = 'PCDATA';      $self->{content_model} = PCDATA_CONTENT_MODEL;
2221    
2222      ## Step 7      ## Step 7
2223      if ($token->{type} eq 'end tag' and $token->{tag_name} eq $start_tag_name) {      if ($token->{type} eq 'end tag' and $token->{tag_name} eq $start_tag_name) {
2224        ## Ignore the token        ## Ignore the token
2225        } elsif ($content_model_flag == CDATA_CONTENT_MODEL) {
2226          !!!parse-error (type => 'in CDATA:#'.$token->{type});
2227        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
2228          !!!parse-error (type => 'in RCDATA:#'.$token->{type});
2229      } else {      } else {
2230        !!!parse-error (type => 'in '.$content_model_flag.':#'.$token->{type});        die "$0: $content_model_flag in parse_rcdata";
2231      }      }
2232      !!!next-token;      !!!next-token;
2233    }; # $parse_rcdata    }; # $parse_rcdata
# Line 2227  sub _tree_construction_main ($) { Line 2238  sub _tree_construction_main ($) {
2238      !!!create-element ($script_el, 'script', $token->{attributes});      !!!create-element ($script_el, 'script', $token->{attributes});
2239      ## TODO: mark as "parser-inserted"      ## TODO: mark as "parser-inserted"
2240    
2241      $self->{content_model_flag} = 'CDATA';      $self->{content_model} = CDATA_CONTENT_MODEL;
2242      delete $self->{escape}; # MUST      delete $self->{escape}; # MUST
2243            
2244      my $text = '';      my $text = '';
# Line 2240  sub _tree_construction_main ($) { Line 2251  sub _tree_construction_main ($) {
2251        $script_el->manakai_append_text ($text);        $script_el->manakai_append_text ($text);
2252      }      }
2253                                
2254      $self->{content_model_flag} = 'PCDATA';      $self->{content_model} = PCDATA_CONTENT_MODEL;
2255    
2256      if ($token->{type} eq 'end tag' and      if ($token->{type} eq 'end tag' and
2257          $token->{tag_name} eq 'script') {          $token->{tag_name} eq 'script') {
# Line 2494  sub _tree_construction_main ($) { Line 2505  sub _tree_construction_main ($) {
2505          return;          return;
2506        } elsif ($token->{tag_name} eq 'style') {        } elsif ($token->{tag_name} eq 'style') {
2507          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
2508          $parse_rcdata->('CDATA', $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
2509          return;          return;
2510        } elsif ({        } elsif ({
2511                  base => 1, link => 1,                  base => 1, link => 1,
# Line 2531  sub _tree_construction_main ($) { Line 2542  sub _tree_construction_main ($) {
2542        } elsif ($token->{tag_name} eq 'title') {        } elsif ($token->{tag_name} eq 'title') {
2543          !!!parse-error (type => 'in body:title');          !!!parse-error (type => 'in body:title');
2544          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
2545          $parse_rcdata->('RCDATA', sub {          $parse_rcdata->(RCDATA_CONTENT_MODEL, sub {
2546            if (defined $self->{head_element}) {            if (defined $self->{head_element}) {
2547              $self->{head_element}->append_child ($_[0]);              $self->{head_element}->append_child ($_[0]);
2548            } else {            } else {
# Line 2727  sub _tree_construction_main ($) { Line 2738  sub _tree_construction_main ($) {
2738                        
2739          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
2740                        
2741          $self->{content_model_flag} = 'PLAINTEXT';          $self->{content_model} = PLAINTEXT_CONTENT_MODEL;
2742                        
2743          !!!next-token;          !!!next-token;
2744          return;          return;
# Line 2882  sub _tree_construction_main ($) { Line 2893  sub _tree_construction_main ($) {
2893          return;          return;
2894        } elsif ($token->{tag_name} eq 'xmp') {        } elsif ($token->{tag_name} eq 'xmp') {
2895          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
2896          $parse_rcdata->('CDATA', $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
2897          return;          return;
2898        } elsif ($token->{tag_name} eq 'table') {        } elsif ($token->{tag_name} eq 'table') {
2899          ## has a p element in scope          ## has a p element in scope
# Line 2998  sub _tree_construction_main ($) { Line 3009  sub _tree_construction_main ($) {
3009          !!!create-element ($el, $token->{tag_name}, $token->{attributes});          !!!create-element ($el, $token->{tag_name}, $token->{attributes});
3010                    
3011          ## TODO: $self->{form_element} if defined          ## TODO: $self->{form_element} if defined
3012          $self->{content_model_flag} = 'RCDATA';          $self->{content_model} = RCDATA_CONTENT_MODEL;
3013          delete $self->{escape}; # MUST          delete $self->{escape}; # MUST
3014                    
3015          $insert->($el);          $insert->($el);
# Line 3019  sub _tree_construction_main ($) { Line 3030  sub _tree_construction_main ($) {
3030            $el->manakai_append_text ($text);            $el->manakai_append_text ($text);
3031          }          }
3032                    
3033          $self->{content_model_flag} = 'PCDATA';          $self->{content_model} = PCDATA_CONTENT_MODEL;
3034                    
3035          if ($token->{type} eq 'end tag' and          if ($token->{type} eq 'end tag' and
3036              $token->{tag_name} eq $tag_name) {              $token->{tag_name} eq $tag_name) {
# Line 3035  sub _tree_construction_main ($) { Line 3046  sub _tree_construction_main ($) {
3046                  noframes => 1,                  noframes => 1,
3047                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
3048                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
3049          $parse_rcdata->('CDATA', $insert);          ## NOTE: There are two "as if in body" code clones.
3050            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
3051          return;          return;
3052        } elsif ($token->{tag_name} eq 'select') {        } elsif ($token->{tag_name} eq 'select') {
3053          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
# Line 3331  sub _tree_construction_main ($) { Line 3343  sub _tree_construction_main ($) {
3343    }; # $in_body    }; # $in_body
3344    
3345    B: {    B: {
3346      if ($self->{insertion_mode} ne 'trailing end') {      if ($token->{type} eq 'DOCTYPE') {
3347        if ($token->{type} eq 'DOCTYPE') {        !!!parse-error (type => 'DOCTYPE in the middle');
3348          !!!parse-error (type => 'in html:#DOCTYPE');        ## Ignore the token
3349          ## Ignore the token        ## Stay in the phase
3350          ## Stay in the phase        !!!next-token;
3351          !!!next-token;        redo B;
3352          redo B;      } elsif ($token->{type} eq 'end-of-file') {
3353        } elsif ($token->{type} eq 'start tag' and        if ($token->{insertion_mode} ne 'trailing end') {
                $token->{tag_name} eq 'html') {  
 ## ISSUE: "aa<html>" is not a parse error.  
 ## ISSUE: "<html>" in fragment is not a parse error.  
         unless ($token->{first_start_tag}) {  
           !!!parse-error (type => 'not first start tag');  
         }  
         my $top_el = $self->{open_elements}->[0]->[0];  
         for my $attr_name (keys %{$token->{attributes}}) {  
           unless ($top_el->has_attribute_ns (undef, $attr_name)) {  
             $top_el->set_attribute_ns  
               (undef, [undef, $attr_name],  
                $token->{attributes}->{$attr_name}->{value});  
           }  
         }  
         !!!next-token;  
         redo B;  
       } elsif ($token->{type} eq 'end-of-file') {  
3354          ## Generate implied end tags          ## Generate implied end tags
3355          if ({          if ({
3356               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,
# Line 3375  sub _tree_construction_main ($) { Line 3370  sub _tree_construction_main ($) {
3370            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3371          }          }
3372    
         ## Stop parsing  
         last B;  
   
3373          ## ISSUE: There is an issue in the spec.          ## ISSUE: There is an issue in the spec.
3374          }
3375    
3376          ## Stop parsing
3377          last B;
3378        } elsif ($token->{type} eq 'start tag' and
3379                 $token->{tag_name} eq 'html') {
3380          if ($self->{insertion_mode} eq 'trailing end') {
3381            ## Turn into the main phase
3382            !!!parse-error (type => 'after html:html');
3383            $self->{insertion_mode} = $previous_insertion_mode;
3384          }
3385    
3386    ## ISSUE: "aa<html>" is not a parse error.
3387    ## ISSUE: "<html>" in fragment is not a parse error.
3388          unless ($token->{first_start_tag}) {
3389            !!!parse-error (type => 'not first start tag');
3390          }
3391          my $top_el = $self->{open_elements}->[0]->[0];
3392          for my $attr_name (keys %{$token->{attributes}}) {
3393            unless ($top_el->has_attribute_ns (undef, $attr_name)) {
3394              $top_el->set_attribute_ns
3395                (undef, [undef, $attr_name],
3396                 $token->{attributes}->{$attr_name}->{value});
3397            }
3398          }
3399          !!!next-token;
3400          redo B;
3401        } elsif ($token->{type} eq 'comment') {
3402          my $comment = $self->{document}->create_comment ($token->{data});
3403          if ($self->{insertion_mode} eq 'trailing end') {
3404            $self->{document}->append_child ($comment);
3405          } elsif ($self->{insertion_mode} eq 'after body') {
3406            $self->{open_elements}->[0]->[0]->append_child ($comment);
3407        } else {        } else {
3408          if ($self->{insertion_mode} eq 'before head') {          $self->{open_elements}->[-1]->[0]->append_child ($comment);
3409          }
3410          !!!next-token;
3411          redo B;
3412        } elsif ($self->{insertion_mode} eq 'before head') {
3413            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
3414              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3415                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
# Line 3396  sub _tree_construction_main ($) { Line 3425  sub _tree_construction_main ($) {
3425              $self->{insertion_mode} = 'in head';              $self->{insertion_mode} = 'in head';
3426              ## reprocess              ## reprocess
3427              redo B;              redo B;
           } elsif ($token->{type} eq 'comment') {  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
3428            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
3429              my $attr = $token->{tag_name} eq 'head' ? $token->{attributes} : {};              my $attr = $token->{tag_name} eq 'head' ? $token->{attributes} : {};
3430              !!!create-element ($self->{head_element}, 'head', $attr);              !!!create-element ($self->{head_element}, 'head', $attr);
# Line 3452  sub _tree_construction_main ($) { Line 3476  sub _tree_construction_main ($) {
3476              }              }
3477                            
3478              #              #
           } elsif ($token->{type} eq 'comment') {  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
3479            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
3480              if ({base => ($self->{insertion_mode} eq 'in head' or              if ({base => ($self->{insertion_mode} eq 'in head' or
3481                            $self->{insertion_mode} eq 'after head'),                            $self->{insertion_mode} eq 'after head'),
# Line 3512  sub _tree_construction_main ($) { Line 3531  sub _tree_construction_main ($) {
3531                }                }
3532                my $parent = defined $self->{head_element} ? $self->{head_element}                my $parent = defined $self->{head_element} ? $self->{head_element}
3533                    : $self->{open_elements}->[-1]->[0];                    : $self->{open_elements}->[-1]->[0];
3534                $parse_rcdata->('RCDATA', sub { $parent->append_child ($_[0]) });                $parse_rcdata->(RCDATA_CONTENT_MODEL,
3535                                  sub { $parent->append_child ($_[0]) });
3536                pop @{$self->{open_elements}}                pop @{$self->{open_elements}}
3537                    if $self->{insertion_mode} eq 'after head';                    if $self->{insertion_mode} eq 'after head';
3538                redo B;                redo B;
# Line 3524  sub _tree_construction_main ($) { Line 3544  sub _tree_construction_main ($) {
3544                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3545                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3546                }                }
3547                $parse_rcdata->('CDATA', $insert_to_current);                $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);
3548                pop @{$self->{open_elements}}                pop @{$self->{open_elements}}
3549                    if $self->{insertion_mode} eq 'after head';                    if $self->{insertion_mode} eq 'after head';
3550                redo B;                redo B;
# Line 3538  sub _tree_construction_main ($) { Line 3558  sub _tree_construction_main ($) {
3558                } elsif ($self->{insertion_mode} eq 'in head noscript') {                } elsif ($self->{insertion_mode} eq 'in head noscript') {
3559                  !!!parse-error (type => 'in noscript:noscript');                  !!!parse-error (type => 'in noscript:noscript');
3560                  ## Ignore the token                  ## Ignore the token
3561                    !!!next-token;
3562                  redo B;                  redo B;
3563                } else {                } else {
3564                  #                  #
# Line 3626  sub _tree_construction_main ($) { Line 3647  sub _tree_construction_main ($) {
3647            redo B;            redo B;
3648    
3649            ## ISSUE: An issue in the spec.            ## ISSUE: An issue in the spec.
3650          } elsif ($self->{insertion_mode} eq 'in body') {          } elsif ($self->{insertion_mode} eq 'in body' or
3651                     $self->{insertion_mode} eq 'in cell' or
3652                     $self->{insertion_mode} eq 'in caption') {
3653            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
3654              ## NOTE: There is a code clone of "character in body".              ## NOTE: There is a code clone of "character in body".
3655              $reconstruct_active_formatting_elements->($insert_to_current);              $reconstruct_active_formatting_elements->($insert_to_current);
# Line 3635  sub _tree_construction_main ($) { Line 3658  sub _tree_construction_main ($) {
3658    
3659              !!!next-token;              !!!next-token;
3660              redo B;              redo B;
3661            } elsif ($token->{type} eq 'comment') {            } elsif ($token->{type} eq 'start tag') {
3662              ## NOTE: There is a code clone of "comment in body".              if ({
3663              my $comment = $self->{document}->create_comment ($token->{data});                   caption => 1, col => 1, colgroup => 1, tbody => 1,
3664              $self->{open_elements}->[-1]->[0]->append_child ($comment);                   td => 1, tfoot => 1, th => 1, thead => 1, tr => 1,
3665              !!!next-token;                  }->{$token->{tag_name}}) {
3666              redo B;                if ($self->{insertion_mode} eq 'in cell') {
3667                    ## have an element in table scope
3668                    my $tn;
3669                    INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3670                      my $node = $self->{open_elements}->[$_];
3671                      if ($node->[1] eq 'td' or $node->[1] eq 'th') {
3672                        $tn = $node->[1];
3673                        last INSCOPE;
3674                      } elsif ({
3675                                table => 1, html => 1,
3676                               }->{$node->[1]}) {
3677                        last INSCOPE;
3678                      }
3679                    } # INSCOPE
3680                      unless (defined $tn) {
3681                        !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3682                        ## Ignore the token
3683                        !!!next-token;
3684                        redo B;
3685                      }
3686                    
3687                    ## Close the cell
3688                    !!!back-token; # <?>
3689                    $token = {type => 'end tag', tag_name => $tn};
3690                    redo B;
3691                  } elsif ($self->{insertion_mode} eq 'in caption') {
3692                    !!!parse-error (type => 'not closed:caption');
3693                    
3694                    ## As if </caption>
3695                    ## have a table element in table scope
3696                    my $i;
3697                    INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3698                      my $node = $self->{open_elements}->[$_];
3699                      if ($node->[1] eq 'caption') {
3700                        $i = $_;
3701                        last INSCOPE;
3702                      } elsif ({
3703                                table => 1, html => 1,
3704                               }->{$node->[1]}) {
3705                        last INSCOPE;
3706                      }
3707                    } # INSCOPE
3708                      unless (defined $i) {
3709                        !!!parse-error (type => 'unmatched end tag:caption');
3710                        ## Ignore the token
3711                        !!!next-token;
3712                        redo B;
3713                      }
3714                    
3715                    ## generate implied end tags
3716                    if ({
3717                         dd => 1, dt => 1, li => 1, p => 1,
3718                         td => 1, th => 1, tr => 1,
3719                         tbody => 1, tfoot=> 1, thead => 1,
3720                        }->{$self->{open_elements}->[-1]->[1]}) {
3721                      !!!back-token; # <?>
3722                      $token = {type => 'end tag', tag_name => 'caption'};
3723                      !!!back-token;
3724                      $token = {type => 'end tag',
3725                                tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3726                      redo B;
3727                    }
3728    
3729                    if ($self->{open_elements}->[-1]->[1] ne 'caption') {
3730                      !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3731                    }
3732                    
3733                    splice @{$self->{open_elements}}, $i;
3734                    
3735                    $clear_up_to_marker->();
3736                    
3737                    $self->{insertion_mode} = 'in table';
3738                    
3739                    ## reprocess
3740                    redo B;
3741                  } else {
3742                    #
3743                  }
3744                } else {
3745                  #
3746                }
3747              } elsif ($token->{type} eq 'end tag') {
3748                if ($token->{tag_name} eq 'td' or $token->{tag_name} eq 'th') {
3749                  if ($self->{insertion_mode} eq 'in cell') {
3750                    ## have an element in table scope
3751                    my $i;
3752                    INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3753                      my $node = $self->{open_elements}->[$_];
3754                      if ($node->[1] eq $token->{tag_name}) {
3755                        $i = $_;
3756                        last INSCOPE;
3757                      } elsif ({
3758                                table => 1, html => 1,
3759                               }->{$node->[1]}) {
3760                        last INSCOPE;
3761                      }
3762                    } # INSCOPE
3763                      unless (defined $i) {
3764                        !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3765                        ## Ignore the token
3766                        !!!next-token;
3767                        redo B;
3768                      }
3769                    
3770                    ## generate implied end tags
3771                    if ({
3772                         dd => 1, dt => 1, li => 1, p => 1,
3773                         td => ($token->{tag_name} eq 'th'),
3774                         th => ($token->{tag_name} eq 'td'),
3775                         tr => 1,
3776                         tbody => 1, tfoot=> 1, thead => 1,
3777                        }->{$self->{open_elements}->[-1]->[1]}) {
3778                      !!!back-token;
3779                      $token = {type => 'end tag',
3780                                tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3781                      redo B;
3782                    }
3783                    
3784                    if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
3785                      !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3786                    }
3787                    
3788                    splice @{$self->{open_elements}}, $i;
3789                    
3790                    $clear_up_to_marker->();
3791                    
3792                    $self->{insertion_mode} = 'in row';
3793                    
3794                    !!!next-token;
3795                    redo B;
3796                  } elsif ($self->{insertion_mode} eq 'in caption') {
3797                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3798                    ## Ignore the token
3799                    !!!next-token;
3800                    redo B;
3801                  } else {
3802                    #
3803                  }
3804                } elsif ($token->{tag_name} eq 'caption') {
3805                  if ($self->{insertion_mode} eq 'in caption') {
3806                    ## have a table element in table scope
3807                    my $i;
3808                    INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3809                      my $node = $self->{open_elements}->[$_];
3810                      if ($node->[1] eq $token->{tag_name}) {
3811                        $i = $_;
3812                        last INSCOPE;
3813                      } elsif ({
3814                                table => 1, html => 1,
3815                               }->{$node->[1]}) {
3816                        last INSCOPE;
3817                      }
3818                    } # INSCOPE
3819                      unless (defined $i) {
3820                        !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3821                        ## Ignore the token
3822                        !!!next-token;
3823                        redo B;
3824                      }
3825                    
3826                    ## generate implied end tags
3827                    if ({
3828                         dd => 1, dt => 1, li => 1, p => 1,
3829                         td => 1, th => 1, tr => 1,
3830                         tbody => 1, tfoot=> 1, thead => 1,
3831                        }->{$self->{open_elements}->[-1]->[1]}) {
3832                      !!!back-token;
3833                      $token = {type => 'end tag',
3834                                tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3835                      redo B;
3836                    }
3837                    
3838                    if ($self->{open_elements}->[-1]->[1] ne 'caption') {
3839                      !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3840                    }
3841                    
3842                    splice @{$self->{open_elements}}, $i;
3843                    
3844                    $clear_up_to_marker->();
3845                    
3846                    $self->{insertion_mode} = 'in table';
3847                    
3848                    !!!next-token;
3849                    redo B;
3850                  } elsif ($self->{insertion_mode} eq 'in cell') {
3851                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3852                    ## Ignore the token
3853                    !!!next-token;
3854                    redo B;
3855                  } else {
3856                    #
3857                  }
3858                } elsif ({
3859                          table => 1, tbody => 1, tfoot => 1,
3860                          thead => 1, tr => 1,
3861                         }->{$token->{tag_name}} and
3862                         $self->{insertion_mode} eq 'in cell') {
3863                  ## have an element in table scope
3864                  my $i;
3865                  my $tn;
3866                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3867                    my $node = $self->{open_elements}->[$_];
3868                    if ($node->[1] eq $token->{tag_name}) {
3869                      $i = $_;
3870                      last INSCOPE;
3871                    } elsif ($node->[1] eq 'td' or $node->[1] eq 'th') {
3872                      $tn = $node->[1];
3873                      ## NOTE: There is exactly one |td| or |th| element
3874                      ## in scope in the stack of open elements by definition.
3875                    } elsif ({
3876                              table => 1, html => 1,
3877                             }->{$node->[1]}) {
3878                      last INSCOPE;
3879                    }
3880                  } # INSCOPE
3881                  unless (defined $i) {
3882                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3883                    ## Ignore the token
3884                    !!!next-token;
3885                    redo B;
3886                  }
3887    
3888                  ## Close the cell
3889                  !!!back-token; # </?>
3890                  $token = {type => 'end tag', tag_name => $tn};
3891                  redo B;
3892                } elsif ($token->{tag_name} eq 'table' and
3893                         $self->{insertion_mode} eq 'in caption') {
3894                  !!!parse-error (type => 'not closed:caption');
3895    
3896                  ## As if </caption>
3897                  ## have a table element in table scope
3898                  my $i;
3899                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3900                    my $node = $self->{open_elements}->[$_];
3901                    if ($node->[1] eq 'caption') {
3902                      $i = $_;
3903                      last INSCOPE;
3904                    } elsif ({
3905                              table => 1, html => 1,
3906                             }->{$node->[1]}) {
3907                      last INSCOPE;
3908                    }
3909                  } # INSCOPE
3910                  unless (defined $i) {
3911                    !!!parse-error (type => 'unmatched end tag:caption');
3912                    ## Ignore the token
3913                    !!!next-token;
3914                    redo B;
3915                  }
3916                  
3917                  ## generate implied end tags
3918                  if ({
3919                       dd => 1, dt => 1, li => 1, p => 1,
3920                       td => 1, th => 1, tr => 1,
3921                       tbody => 1, tfoot=> 1, thead => 1,
3922                      }->{$self->{open_elements}->[-1]->[1]}) {
3923                    !!!back-token; # </table>
3924                    $token = {type => 'end tag', tag_name => 'caption'};
3925                    !!!back-token;
3926                    $token = {type => 'end tag',
3927                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3928                    redo B;
3929                  }
3930    
3931                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
3932                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3933                  }
3934    
3935                  splice @{$self->{open_elements}}, $i;
3936    
3937                  $clear_up_to_marker->();
3938    
3939                  $self->{insertion_mode} = 'in table';
3940    
3941                  ## reprocess
3942                  redo B;
3943                } elsif ({
3944                          body => 1, col => 1, colgroup => 1, html => 1,
3945                         }->{$token->{tag_name}}) {
3946                  if ($self->{insertion_mode} eq 'in cell' or
3947                      $self->{insertion_mode} eq 'in caption') {
3948                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3949                    ## Ignore the token
3950                    !!!next-token;
3951                    redo B;
3952                  } else {
3953                    #
3954                  }
3955                } elsif ({
3956                          tbody => 1, tfoot => 1,
3957                          thead => 1, tr => 1,
3958                         }->{$token->{tag_name}} and
3959                         $self->{insertion_mode} eq 'in caption') {
3960                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3961                  ## Ignore the token
3962                  !!!next-token;
3963                  redo B;
3964                } else {
3965                  #
3966                }
3967            } else {            } else {
3968              $in_body->($insert_to_current);              #
             redo B;  
3969            }            }
3970              
3971              $in_body->($insert_to_current);
3972              redo B;
3973          } elsif ($self->{insertion_mode} eq 'in table') {          } elsif ($self->{insertion_mode} eq 'in table') {
3974            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
3975              ## NOTE: There are "character in table" code clones.              ## NOTE: There are "character in table" code clones.
# Line 3704  sub _tree_construction_main ($) { Line 4029  sub _tree_construction_main ($) {
4029                            
4030              !!!next-token;              !!!next-token;
4031              redo B;              redo B;
           } elsif ($token->{type} eq 'comment') {  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
4032            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
4033              if ({              if ({
4034                   caption => 1,                   caption => 1,
# Line 3866  sub _tree_construction_main ($) { Line 4186  sub _tree_construction_main ($) {
4186            !!!parse-error (type => 'in table:'.$token->{tag_name});            !!!parse-error (type => 'in table:'.$token->{tag_name});
4187            $in_body->($insert_to_foster);            $in_body->($insert_to_foster);
4188            redo B;            redo B;
         } elsif ($self->{insertion_mode} eq 'in caption') {  
           if ($token->{type} eq 'character') {  
             ## NOTE: This is a code clone of "character in body".  
             $reconstruct_active_formatting_elements->($insert_to_current);  
               
             $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});  
   
             !!!next-token;  
             redo B;  
           } elsif ($token->{type} eq 'comment') {  
             ## NOTE: This is a code clone of "comment in body".  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
           } elsif ($token->{type} eq 'start tag') {  
             if ({  
                  caption => 1, col => 1, colgroup => 1, tbody => 1,  
                  td => 1, tfoot => 1, th => 1, thead => 1, tr => 1,  
                 }->{$token->{tag_name}}) {  
               !!!parse-error (type => 'not closed:caption');  
   
               ## As if </caption>  
               ## have a table element in table scope  
               my $i;  
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ($node->[1] eq 'caption') {  
                   $i = $_;  
                   last INSCOPE;  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
                 }  
               } # INSCOPE  
               unless (defined $i) {  
                 !!!parse-error (type => 'unmatched end tag:caption');  
                 ## Ignore the token  
                 !!!next-token;  
                 redo B;  
               }  
                 
               ## generate implied end tags  
               if ({  
                    dd => 1, dt => 1, li => 1, p => 1,  
                    td => 1, th => 1, tr => 1,  
                    tbody => 1, tfoot=> 1, thead => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
                 !!!back-token; # <?>  
                 $token = {type => 'end tag', tag_name => 'caption'};  
                 !!!back-token;  
                 $token = {type => 'end tag',  
                           tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                 redo B;  
               }  
   
               if ($self->{open_elements}->[-1]->[1] ne 'caption') {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
               }  
   
               splice @{$self->{open_elements}}, $i;  
   
               $clear_up_to_marker->();  
   
               $self->{insertion_mode} = 'in table';  
   
               ## reprocess  
               redo B;  
             } else {  
               #  
             }  
           } elsif ($token->{type} eq 'end tag') {  
             if ($token->{tag_name} eq 'caption') {  
               ## have a table element in table scope  
               my $i;  
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ($node->[1] eq $token->{tag_name}) {  
                   $i = $_;  
                   last INSCOPE;  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
                 }  
               } # INSCOPE  
               unless (defined $i) {  
                 !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
                 ## Ignore the token  
                 !!!next-token;  
                 redo B;  
               }  
                 
               ## generate implied end tags  
               if ({  
                    dd => 1, dt => 1, li => 1, p => 1,  
                    td => 1, th => 1, tr => 1,  
                    tbody => 1, tfoot=> 1, thead => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
                 !!!back-token;  
                 $token = {type => 'end tag',  
                           tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                 redo B;  
               }  
   
               if ($self->{open_elements}->[-1]->[1] ne 'caption') {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
               }  
   
               splice @{$self->{open_elements}}, $i;  
   
               $clear_up_to_marker->();  
   
               $self->{insertion_mode} = 'in table';  
   
               !!!next-token;  
               redo B;  
             } elsif ($token->{tag_name} eq 'table') {  
               !!!parse-error (type => 'not closed:caption');  
   
               ## As if </caption>  
               ## have a table element in table scope  
               my $i;  
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ($node->[1] eq 'caption') {  
                   $i = $_;  
                   last INSCOPE;  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
                 }  
               } # INSCOPE  
               unless (defined $i) {  
                 !!!parse-error (type => 'unmatched end tag:caption');  
                 ## Ignore the token  
                 !!!next-token;  
                 redo B;  
               }  
                 
               ## generate implied end tags  
               if ({  
                    dd => 1, dt => 1, li => 1, p => 1,  
                    td => 1, th => 1, tr => 1,  
                    tbody => 1, tfoot=> 1, thead => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
                 !!!back-token; # </table>  
                 $token = {type => 'end tag', tag_name => 'caption'};  
                 !!!back-token;  
                 $token = {type => 'end tag',  
                           tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                 redo B;  
               }  
   
               if ($self->{open_elements}->[-1]->[1] ne 'caption') {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
               }  
   
               splice @{$self->{open_elements}}, $i;  
   
               $clear_up_to_marker->();  
   
               $self->{insertion_mode} = 'in table';  
   
               ## reprocess  
               redo B;  
             } elsif ({  
                       body => 1, col => 1, colgroup => 1,  
                       html => 1, tbody => 1, td => 1, tfoot => 1,  
                       th => 1, thead => 1, tr => 1,  
                      }->{$token->{tag_name}}) {  
               !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
               ## Ignore the token  
               redo B;  
             } else {  
               #  
             }  
           } else {  
             #  
           }  
                 
           $in_body->($insert_to_current);  
           redo B;  
4189          } elsif ($self->{insertion_mode} eq 'in column group') {          } elsif ($self->{insertion_mode} eq 'in column group') {
4190            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
4191              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
# Line 4062  sub _tree_construction_main ($) { Line 4197  sub _tree_construction_main ($) {
4197              }              }
4198                            
4199              #              #
           } elsif ($token->{type} eq 'comment') {  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
4200            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
4201              if ($token->{tag_name} eq 'col') {              if ($token->{tag_name} eq 'col') {
4202                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
# Line 4172  sub _tree_construction_main ($) { Line 4302  sub _tree_construction_main ($) {
4302                            
4303              !!!next-token;              !!!next-token;
4304              redo B;              redo B;
           } elsif ($token->{type} eq 'comment') {  
             ## Copied from 'in table'  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
4305            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
4306              if ({              if ({
4307                   tr => 1,                   tr => 1,
# Line 4457  sub _tree_construction_main ($) { Line 4581  sub _tree_construction_main ($) {
4581                            
4582              !!!next-token;              !!!next-token;
4583              redo B;              redo B;
           } elsif ($token->{type} eq 'comment') {  
             ## Copied from 'in table'  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
4584            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
4585              if ($token->{tag_name} eq 'th' or              if ($token->{tag_name} eq 'th' or
4586                  $token->{tag_name} eq 'td') {                  $token->{tag_name} eq 'td') {
# Line 4713  sub _tree_construction_main ($) { Line 4831  sub _tree_construction_main ($) {
4831            !!!parse-error (type => 'in table:'.$token->{tag_name});            !!!parse-error (type => 'in table:'.$token->{tag_name});
4832            $in_body->($insert_to_foster);            $in_body->($insert_to_foster);
4833            redo B;            redo B;
         } elsif ($self->{insertion_mode} eq 'in cell') {  
           if ($token->{type} eq 'character') {  
             ## NOTE: This is a code clone of "character in body".  
             $reconstruct_active_formatting_elements->($insert_to_current);  
               
             $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});  
   
             !!!next-token;  
             redo B;  
           } elsif ($token->{type} eq 'comment') {  
             ## NOTE: This is a code clone of "comment in body".  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
           } elsif ($token->{type} eq 'start tag') {  
             if ({  
                  caption => 1, col => 1, colgroup => 1,  
                  tbody => 1, td => 1, tfoot => 1, th => 1,  
                  thead => 1, tr => 1,  
                 }->{$token->{tag_name}}) {  
               ## have an element in table scope  
               my $tn;  
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ($node->[1] eq 'td' or $node->[1] eq 'th') {  
                   $tn = $node->[1];  
                   last INSCOPE;  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
                 }  
               } # INSCOPE  
               unless (defined $tn) {  
                 !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
                 ## Ignore the token  
                 !!!next-token;  
                 redo B;  
               }  
   
               ## Close the cell  
               !!!back-token; # <?>  
               $token = {type => 'end tag', tag_name => $tn};  
               redo B;  
             } else {  
               #  
             }  
           } elsif ($token->{type} eq 'end tag') {  
             if ($token->{tag_name} eq 'td' or $token->{tag_name} eq 'th') {  
               ## have an element in table scope  
               my $i;  
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ($node->[1] eq $token->{tag_name}) {  
                   $i = $_;  
                   last INSCOPE;  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
                 }  
               } # INSCOPE  
               unless (defined $i) {  
                 !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
                 ## Ignore the token  
                 !!!next-token;  
                 redo B;  
               }  
                 
               ## generate implied end tags  
               if ({  
                    dd => 1, dt => 1, li => 1, p => 1,  
                    td => ($token->{tag_name} eq 'th'),  
                    th => ($token->{tag_name} eq 'td'),  
                    tr => 1,  
                    tbody => 1, tfoot=> 1, thead => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
                 !!!back-token;  
                 $token = {type => 'end tag',  
                           tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                 redo B;  
               }  
   
               if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
               }  
   
               splice @{$self->{open_elements}}, $i;  
   
               $clear_up_to_marker->();  
   
               $self->{insertion_mode} = 'in row';  
   
               !!!next-token;  
               redo B;  
             } elsif ({  
                       body => 1, caption => 1, col => 1,  
                       colgroup => 1, html => 1,  
                      }->{$token->{tag_name}}) {  
               !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
               ## Ignore the token  
               !!!next-token;  
               redo B;  
             } elsif ({  
                       table => 1, tbody => 1, tfoot => 1,  
                       thead => 1, tr => 1,  
                      }->{$token->{tag_name}}) {  
               ## have an element in table scope  
               my $i;  
               my $tn;  
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ($node->[1] eq $token->{tag_name}) {  
                   $i = $_;  
                   last INSCOPE;  
                 } elsif ($node->[1] eq 'td' or $node->[1] eq 'th') {  
                   $tn = $node->[1];  
                   ## NOTE: There is exactly one |td| or |th| element  
                   ## in scope in the stack of open elements by definition.  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
                 }  
               } # INSCOPE  
               unless (defined $i) {  
                 !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
                 ## Ignore the token  
                 !!!next-token;  
                 redo B;  
               }  
   
               ## Close the cell  
               !!!back-token; # </?>  
               $token = {type => 'end tag', tag_name => $tn};  
               redo B;  
             } else {  
               #  
             }  
           } else {  
             #  
           }  
             
           $in_body->($insert_to_current);  
           redo B;  
4834          } elsif ($self->{insertion_mode} eq 'in select') {          } elsif ($self->{insertion_mode} eq 'in select') {
4835            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
4836              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4837              !!!next-token;              !!!next-token;
4838              redo B;              redo B;
           } elsif ($token->{type} eq 'comment') {  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
4839            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
4840              if ($token->{tag_name} eq 'option') {              if ($token->{tag_name} eq 'option') {
4841                if ($self->{open_elements}->[-1]->[1] eq 'option') {                if ($self->{open_elements}->[-1]->[1] eq 'option') {
# Line 5054  sub _tree_construction_main ($) { Line 5021  sub _tree_construction_main ($) {
5021              }              }
5022                            
5023              #              #
5024              !!!parse-error (type => 'after body:#'.$token->{type});              !!!parse-error (type => 'after body:#character');
           } elsif ($token->{type} eq 'comment') {  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[0]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
5025            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
5026              !!!parse-error (type => 'after body:'.$token->{tag_name});              !!!parse-error (type => 'after body:'.$token->{tag_name});
5027              #              #
# Line 5080  sub _tree_construction_main ($) { Line 5042  sub _tree_construction_main ($) {
5042                !!!parse-error (type => 'after body:/'.$token->{tag_name});                !!!parse-error (type => 'after body:/'.$token->{tag_name});
5043              }              }
5044            } else {            } else {
5045              !!!parse-error (type => 'after body:#'.$token->{type});              die "$0: $token->{type}: Unknown token type";
5046            }            }
5047    
5048            $self->{insertion_mode} = 'in body';            $self->{insertion_mode} = 'in body';
5049            ## reprocess            ## reprocess
5050            redo B;            redo B;
5051          } elsif ($self->{insertion_mode} eq 'in frameset') {      } elsif ($self->{insertion_mode} eq 'in frameset') {
5052            if ($token->{type} eq 'character') {        if ($token->{type} eq 'character') {
5053              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
5054                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
   
               unless (length $token->{data}) {  
                 !!!next-token;  
                 redo B;  
               }  
             }  
5055    
5056              #            unless (length $token->{data}) {
           } elsif ($token->{type} eq 'comment') {  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
5057              !!!next-token;              !!!next-token;
5058              redo B;              redo B;
           } elsif ($token->{type} eq 'start tag') {  
             if ($token->{tag_name} eq 'frameset') {  
               !!!insert-element ($token->{tag_name}, $token->{attributes});  
               !!!next-token;  
               redo B;  
             } elsif ($token->{tag_name} eq 'frame') {  
               !!!insert-element ($token->{tag_name}, $token->{attributes});  
               pop @{$self->{open_elements}};  
               !!!next-token;  
               redo B;  
             } elsif ($token->{tag_name} eq 'noframes') {  
               $in_body->($insert_to_current);  
               redo B;  
             } else {  
               #  
             }  
           } elsif ($token->{type} eq 'end tag') {  
             if ($token->{tag_name} eq 'frameset') {  
               if ($self->{open_elements}->[-1]->[1] eq 'html' and  
                   @{$self->{open_elements}} == 1) {  
                 !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
                 ## Ignore the token  
                 !!!next-token;  
               } else {  
                 pop @{$self->{open_elements}};  
                 !!!next-token;  
               }  
                 
               ## if not inner_html and  
               if ($self->{open_elements}->[-1]->[1] ne 'frameset') {  
                 $self->{insertion_mode} = 'after frameset';  
               }  
               redo B;  
             } else {  
               #  
             }  
           } else {  
             #  
5059            }            }
5060                      }
5061            if (defined $token->{tag_name}) {  
5062              !!!parse-error (type => 'in frameset:'.($token->{type} eq 'end tag' ? '/' : '').$token->{tag_name});          !!!parse-error (type => 'in frameset:#character');
5063            ## Ignore the token
5064            !!!next-token;
5065            redo B;
5066          } elsif ($token->{type} eq 'start tag') {
5067            if ($token->{tag_name} eq 'frameset') {
5068              !!!insert-element ($token->{tag_name}, $token->{attributes});
5069              !!!next-token;
5070              redo B;
5071            } elsif ($token->{tag_name} eq 'frame') {
5072              !!!insert-element ($token->{tag_name}, $token->{attributes});
5073              pop @{$self->{open_elements}};
5074              !!!next-token;
5075              redo B;
5076            } elsif ($token->{tag_name} eq 'noframes') {
5077              ## NOTE: As if in body.
5078              $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);
5079              redo B;
5080            } else {
5081              !!!parse-error (type => 'in frameset:'.$token->{tag_name});
5082              ## Ignore the token
5083              !!!next-token;
5084              redo B;
5085            }
5086          } elsif ($token->{type} eq 'end tag') {
5087            if ($token->{tag_name} eq 'frameset') {
5088              if ($self->{open_elements}->[-1]->[1] eq 'html' and
5089                  @{$self->{open_elements}} == 1) {
5090                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5091                ## Ignore the token
5092                !!!next-token;
5093            } else {            } else {
5094              !!!parse-error (type => 'in frameset:#'.$token->{type});              pop @{$self->{open_elements}};
5095                !!!next-token;
5096              }
5097    
5098              if (not defined $self->{inner_html_node} and
5099                  $self->{open_elements}->[-1]->[1] ne 'frameset') {
5100                $self->{insertion_mode} = 'after frameset';
5101            }            }
5102              redo B;
5103            } else {
5104              !!!parse-error (type => 'in frameset:/'.$token->{tag_name});
5105            ## Ignore the token            ## Ignore the token
5106            !!!next-token;            !!!next-token;
5107            redo B;            redo B;
5108          } elsif ($self->{insertion_mode} eq 'after frameset') {          }
5109            if ($token->{type} eq 'character') {        } else {
5110            die "$0: $token->{type}: Unknown token type";
5111          }
5112        } elsif ($self->{insertion_mode} eq 'after frameset') {
5113          if ($token->{type} eq 'character') {
5114              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
5115                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
5116    
# Line 5173  sub _tree_construction_main ($) { Line 5131  sub _tree_construction_main ($) {
5131                }                }
5132                redo B;                redo B;
5133              }              }
5134            } elsif ($token->{type} eq 'comment') {  
5135              my $comment = $self->{document}->create_comment ($token->{data});          die qq[$0: Character "$token->{data}"];
5136              $self->{open_elements}->[-1]->[0]->append_child ($comment);        } elsif ($token->{type} eq 'start tag') {
5137              !!!next-token;          if ($token->{tag_name} eq 'noframes') {
5138              redo B;            ## NOTE: As if in body.
5139            } elsif ($token->{type} eq 'start tag') {            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);
5140              if ($token->{tag_name} eq 'noframes') {            redo B;
5141                $in_body->($insert_to_current);          } else {
5142                redo B;            !!!parse-error (type => 'after frameset:'.$token->{tag_name});
             } else {  
               #  
             }  
           } elsif ($token->{type} eq 'end tag') {  
             if ($token->{tag_name} eq 'html') {  
               $previous_insertion_mode = $self->{insertion_mode};  
               $self->{insertion_mode} = 'trailing end';  
               !!!next-token;  
               redo B;  
             } else {  
               #  
             }  
           } else {  
             die "$0: $token->{type}: Unknown token type";  
           }  
             
           !!!parse-error (type => 'after frameset:'.($token->{tag_name} eq 'end tag' ? '/' : '').$token->{tag_name});  
5143            ## Ignore the token            ## Ignore the token
5144            !!!next-token;            !!!next-token;
5145            redo B;            redo B;
5146            }
5147            ## ISSUE: An issue in spec there        } elsif ($token->{type} eq 'end tag') {
5148            if ($token->{tag_name} eq 'html') {
5149              $previous_insertion_mode = $self->{insertion_mode};
5150              $self->{insertion_mode} = 'trailing end';
5151              !!!next-token;
5152              redo B;
5153          } else {          } else {
5154            die "$0: $self->{insertion_mode}: Unknown insertion mode";            !!!parse-error (type => 'after frameset:/'.$token->{tag_name});
5155              ## Ignore the token
5156              !!!next-token;
5157              redo B;
5158          }          }
5159          } else {
5160            die "$0: $token->{type}: Unknown token type";
5161        }        }
5162    
5163          ## ISSUE: An issue in spec here
5164      } elsif ($self->{insertion_mode} eq 'trailing end') {      } elsif ($self->{insertion_mode} eq 'trailing end') {
5165        ## states in the main stage is preserved yet # MUST        ## states in the main stage is preserved yet # MUST
5166                
5167        if ($token->{type} eq 'DOCTYPE') {        if ($token->{type} eq 'character') {
         !!!parse-error (type => 'after html:#DOCTYPE');  
         ## Ignore the token  
         !!!next-token;  
         redo B;  
       } elsif ($token->{type} eq 'comment') {  
         my $comment = $self->{document}->create_comment ($token->{data});  
         $self->{document}->append_child ($comment);  
         !!!next-token;  
         redo B;  
       } elsif ($token->{type} eq 'character') {  
5168          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
5169            my $data = $1;            my $data = $1;
5170            ## As if in the main phase.            ## As if in the main phase.
# Line 5242  sub _tree_construction_main ($) { Line 5185  sub _tree_construction_main ($) {
5185          $self->{insertion_mode} = $previous_insertion_mode;          $self->{insertion_mode} = $previous_insertion_mode;
5186          ## reprocess          ## reprocess
5187          redo B;          redo B;
5188        } elsif ($token->{type} eq 'start tag' or        } elsif ($token->{type} eq 'start tag') {
5189                 $token->{type} eq 'end tag') {          !!!parse-error (type => 'after html:'.$token->{tag_name});
5190          !!!parse-error (type => 'after html:'.($token->{type} eq 'end tag' ? '/' : '').$token->{tag_name});          $self->{insertion_mode} = $previous_insertion_mode;
5191            ## reprocess
5192            redo B;
5193          } elsif ($token->{type} eq 'end tag') {
5194            !!!parse-error (type => 'after html:/'.$token->{tag_name});
5195          $self->{insertion_mode} = $previous_insertion_mode;          $self->{insertion_mode} = $previous_insertion_mode;
5196          ## reprocess          ## reprocess
5197          redo B;          redo B;
       } elsif ($token->{type} eq 'end-of-file') {  
         ## Stop parsing  
         last B;  
5198        } else {        } else {
5199          die "$0: $token->{type}: Unknown token";          die "$0: $token->{type}: Unknown token";
5200        }        }
5201        } else {
5202          die "$0: $self->{insertion_mode}: Unknown insertion mode";
5203      }      }
5204    } # B    } # B
5205    
# Line 5341  sub set_inner_html ($$$) { Line 5287  sub set_inner_html ($$$) {
5287    
5288      ## Step 2      ## Step 2
5289      my $node_ln = $node->local_name;      my $node_ln = $node->local_name;
5290      $p->{content_model_flag} = {      $p->{content_model} = {
5291        title => 'RCDATA',        title => RCDATA_CONTENT_MODEL,
5292        textarea => 'RCDATA',        textarea => RCDATA_CONTENT_MODEL,
5293        style => 'CDATA',        style => CDATA_CONTENT_MODEL,
5294        script => 'CDATA',        script => CDATA_CONTENT_MODEL,
5295        xmp => 'CDATA',        xmp => CDATA_CONTENT_MODEL,
5296        iframe => 'CDATA',        iframe => CDATA_CONTENT_MODEL,
5297        noembed => 'CDATA',        noembed => CDATA_CONTENT_MODEL,
5298        noframes => 'CDATA',        noframes => CDATA_CONTENT_MODEL,
5299        noscript => 'CDATA',        noscript => CDATA_CONTENT_MODEL,
5300        plaintext => 'PLAINTEXT',        plaintext => PLAINTEXT_CONTENT_MODEL,
5301      }->{$node_ln} || 'PCDATA';      }->{$node_ln};
5302         ## ISSUE: What is "the name of the element"? local name?      $p->{content_model} = PCDATA_CONTENT_MODEL
5303            unless defined $p->{content_model};
5304            ## ISSUE: What is "the name of the element"? local name?
5305    
5306      $p->{inner_html_node} = [$node, $node_ln];      $p->{inner_html_node} = [$node, $node_ln];
5307    

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.45

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24