/[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.84 by wakaba, Thu Mar 6 15:23:17 2008 UTC revision 1.106 by wakaba, Sun Mar 9 10:31:19 2008 UTC
# Line 74  my $special_category = { Line 74  my $special_category = {
74    textarea => 1, tfoot => 1, thead => 1, title => 1, tr => 1, ul => 1, wbr => 1,    textarea => 1, tfoot => 1, thead => 1, title => 1, tr => 1, ul => 1, wbr => 1,
75  };  };
76  my $scoping_category = {  my $scoping_category = {
77    button => 1, caption => 1, html => 1, marquee => 1, object => 1,    applet => 1, button => 1, caption => 1, html => 1, marquee => 1, object => 1,
78    table => 1, td => 1, th => 1,    table => 1, td => 1, th => 1,
79  };  };
80  my $formatting_category = {  my $formatting_category = {
# Line 303  sub TABLE_IMS ()      { 0b1000000 } Line 303  sub TABLE_IMS ()      { 0b1000000 }
303  sub ROW_IMS ()        { 0b10000000 }  sub ROW_IMS ()        { 0b10000000 }
304  sub BODY_AFTER_IMS () { 0b100000000 }  sub BODY_AFTER_IMS () { 0b100000000 }
305  sub FRAME_IMS ()      { 0b1000000000 }  sub FRAME_IMS ()      { 0b1000000000 }
306    sub SELECT_IMS ()     { 0b10000000000 }
307    
308  ## NOTE: "initial" and "before html" insertion modes have no constants.  ## NOTE: "initial" and "before html" insertion modes have no constants.
309    
# Line 325  sub IN_TABLE_IM () { TABLE_IMS } Line 326  sub IN_TABLE_IM () { TABLE_IMS }
326  sub AFTER_BODY_IM () { BODY_AFTER_IMS }  sub AFTER_BODY_IM () { BODY_AFTER_IMS }
327  sub IN_FRAMESET_IM () { FRAME_IMS | 0b01 }  sub IN_FRAMESET_IM () { FRAME_IMS | 0b01 }
328  sub AFTER_FRAMESET_IM () { FRAME_IMS | 0b10 }  sub AFTER_FRAMESET_IM () { FRAME_IMS | 0b10 }
329  sub IN_SELECT_IM () { 0b01 }  sub IN_SELECT_IM () { SELECT_IMS | 0b01 }
330    sub IN_SELECT_IN_TABLE_IM () { SELECT_IMS | 0b10 }
331  sub IN_COLUMN_GROUP_IM () { 0b10 }  sub IN_COLUMN_GROUP_IM () { 0b10 }
332    
333  ## Implementations MUST act as if state machine in the spec  ## Implementations MUST act as if state machine in the spec
# Line 2743  sub _reset_insertion_mode ($) { Line 2745  sub _reset_insertion_mode ($) {
2745            
2746      ## Step 3      ## Step 3
2747      S3: {      S3: {
       ## ISSUE: Oops! "If node is the first node in the stack of open  
       ## elements, then set last to true. If the context element of the  
       ## HTML fragment parsing algorithm is neither a td element nor a  
       ## th element, then set node to the context element. (fragment case)":  
       ## The second "if" is in the scope of the first "if"!?  
2748        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
2749          $last = 1;          $last = 1;
2750          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
# Line 2908  sub _tree_construction_main ($) { Line 2905  sub _tree_construction_main ($) {
2905      !!!cp ('t39');      !!!cp ('t39');
2906    }; # $clear_up_to_marker    }; # $clear_up_to_marker
2907    
2908    my $parse_rcdata = sub ($$) {    my $insert;
2909      my ($content_model_flag, $insert) = @_;  
2910      my $parse_rcdata = sub ($) {
2911        my ($content_model_flag) = @_;
2912    
2913      ## Step 1      ## Step 1
2914      my $start_tag_name = $token->{tag_name};      my $start_tag_name = $token->{tag_name};
# Line 2917  sub _tree_construction_main ($) { Line 2916  sub _tree_construction_main ($) {
2916      !!!create-element ($el, $start_tag_name, $token->{attributes});      !!!create-element ($el, $start_tag_name, $token->{attributes});
2917    
2918      ## Step 2      ## Step 2
2919      $insert->($el); # /context node/->append_child ($el)      $insert->($el);
2920    
2921      ## Step 3      ## Step 3
2922      $self->{content_model} = $content_model_flag; # CDATA or RCDATA      $self->{content_model} = $content_model_flag; # CDATA or RCDATA
# Line 2947  sub _tree_construction_main ($) { Line 2946  sub _tree_construction_main ($) {
2946          $token->{tag_name} eq $start_tag_name) {          $token->{tag_name} eq $start_tag_name) {
2947        !!!cp ('t42');        !!!cp ('t42');
2948        ## Ignore the token        ## Ignore the token
     } elsif ($content_model_flag == CDATA_CONTENT_MODEL) {  
       !!!cp ('t43');  
       !!!parse-error (type => 'in CDATA:#'.$token->{type});  
     } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {  
       !!!cp ('t44');  
       !!!parse-error (type => 'in RCDATA:#'.$token->{type});  
2949      } else {      } else {
2950        die "$0: $content_model_flag in parse_rcdata";        ## NOTE: An end-of-file token.
2951          if ($content_model_flag == CDATA_CONTENT_MODEL) {
2952            !!!cp ('t43');
2953            !!!parse-error (type => 'in CDATA:#'.$token->{type});
2954          } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
2955            !!!cp ('t44');
2956            !!!parse-error (type => 'in RCDATA:#'.$token->{type});
2957          } else {
2958            die "$0: $content_model_flag in parse_rcdata";
2959          }
2960      }      }
2961      !!!next-token;      !!!next-token;
2962    }; # $parse_rcdata    }; # $parse_rcdata
2963    
2964    my $script_start_tag = sub ($) {    my $script_start_tag = sub () {
     my $insert = $_[0];  
2965      my $script_el;      my $script_el;
2966      !!!create-element ($script_el, 'script', $token->{attributes});      !!!create-element ($script_el, 'script', $token->{attributes});
2967      ## TODO: mark as "parser-inserted"      ## TODO: mark as "parser-inserted"
# Line 3011  sub _tree_construction_main ($) { Line 3012  sub _tree_construction_main ($) {
3012      !!!next-token;      !!!next-token;
3013    }; # $script_start_tag    }; # $script_start_tag
3014    
3015      ## NOTE: $open_tables->[-1]->[0] is the "current table" element node.
3016      ## NOTE: $open_tables->[-1]->[1] is the "tainted" flag.
3017      my $open_tables = [[$self->{open_elements}->[0]->[0]]];
3018    
3019    my $formatting_end_tag = sub {    my $formatting_end_tag = sub {
3020      my $tag_name = shift;      my $tag_name = shift;
3021    
3022        ## NOTE: The adoption agency algorithm (AAA).
3023    
3024      FET: {      FET: {
3025        ## Step 1        ## Step 1
3026        my $formatting_element;        my $formatting_element;
# Line 3054  sub _tree_construction_main ($) { Line 3061  sub _tree_construction_main ($) {
3061              return;              return;
3062            }            }
3063          } elsif ({          } elsif ({
3064                    table => 1, caption => 1, td => 1, th => 1,                    applet => 1, table => 1, caption => 1, td => 1, th => 1,
3065                    button => 1, marquee => 1, object => 1, html => 1,                    button => 1, marquee => 1, object => 1, html => 1,
3066                   }->{$node->[1]}) {                   }->{$node->[1]}) {
3067            !!!cp ('t56');            !!!cp ('t56');
# Line 3081  sub _tree_construction_main ($) { Line 3088  sub _tree_construction_main ($) {
3088          if (not $formatting_category->{$node->[1]} and          if (not $formatting_category->{$node->[1]} and
3089              #not $phrasing_category->{$node->[1]} and              #not $phrasing_category->{$node->[1]} and
3090              ($special_category->{$node->[1]} or              ($special_category->{$node->[1]} or
3091               $scoping_category->{$node->[1]})) {               $scoping_category->{$node->[1]})) { ## Scoping is redundant, maybe
3092            !!!cp ('t59');            !!!cp ('t59');
3093            $furthest_block = $node;            $furthest_block = $node;
3094            $furthest_block_i_in_open = $_;            $furthest_block_i_in_open = $_;
# Line 3167  sub _tree_construction_main ($) { Line 3174  sub _tree_construction_main ($) {
3174        } # S7          } # S7  
3175                
3176        ## Step 8        ## Step 8
3177        $common_ancestor_node->[0]->append_child ($last_node->[0]);        if ({
3178               table => 1, tbody => 1, tfoot => 1, thead => 1, tr => 1,
3179              }->{$common_ancestor_node->[1]}) {
3180            my $foster_parent_element;
3181            my $next_sibling;
3182                             OE: for (reverse 0..$#{$self->{open_elements}}) {
3183                               if ($self->{open_elements}->[$_]->[1] eq 'table') {
3184                                 my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
3185                                 if (defined $parent and $parent->node_type == 1) {
3186                                   !!!cp ('t65.1');
3187                                   $foster_parent_element = $parent;
3188                                   $next_sibling = $self->{open_elements}->[$_]->[0];
3189                                 } else {
3190                                   !!!cp ('t65.2');
3191                                   $foster_parent_element
3192                                     = $self->{open_elements}->[$_ - 1]->[0];
3193                                 }
3194                                 last OE;
3195                               }
3196                             } # OE
3197                             $foster_parent_element = $self->{open_elements}->[0]->[0]
3198                               unless defined $foster_parent_element;
3199            $foster_parent_element->insert_before ($last_node->[0], $next_sibling);
3200            $open_tables->[-1]->[1] = 1; # tainted
3201          } else {
3202            !!!cp ('t65.3');
3203            $common_ancestor_node->[0]->append_child ($last_node->[0]);
3204          }
3205                
3206        ## Step 9        ## Step 9
3207        my $clone = [$formatting_element->[0]->clone_node (0),        my $clone = [$formatting_element->[0]->clone_node (0),
# Line 3213  sub _tree_construction_main ($) { Line 3247  sub _tree_construction_main ($) {
3247      } # FET      } # FET
3248    }; # $formatting_end_tag    }; # $formatting_end_tag
3249    
3250    my $insert_to_current = sub {    $insert = my $insert_to_current = sub {
3251      $self->{open_elements}->[-1]->[0]->append_child ($_[0]);      $self->{open_elements}->[-1]->[0]->append_child ($_[0]);
3252    }; # $insert_to_current    }; # $insert_to_current
3253    
3254    my $insert_to_foster = sub {    my $insert_to_foster = sub {
3255                         my $child = shift;      my $child = shift;
3256                         if ({      if ({
3257                              table => 1, tbody => 1, tfoot => 1,           table => 1, tbody => 1, tfoot => 1, thead => 1, tr => 1,
3258                              thead => 1, tr => 1,          }->{$self->{open_elements}->[-1]->[1]}) {
3259                             }->{$self->{open_elements}->[-1]->[1]}) {        # MUST
3260                           # MUST        my $foster_parent_element;
3261                           my $foster_parent_element;        my $next_sibling;
                          my $next_sibling;  
3262                           OE: for (reverse 0..$#{$self->{open_elements}}) {                           OE: for (reverse 0..$#{$self->{open_elements}}) {
3263                             if ($self->{open_elements}->[$_]->[1] eq 'table') {                             if ($self->{open_elements}->[$_]->[1] eq 'table') {
3264                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
# Line 3245  sub _tree_construction_main ($) { Line 3278  sub _tree_construction_main ($) {
3278                             unless defined $foster_parent_element;                             unless defined $foster_parent_element;
3279                           $foster_parent_element->insert_before                           $foster_parent_element->insert_before
3280                             ($child, $next_sibling);                             ($child, $next_sibling);
3281                         } else {        $open_tables->[-1]->[1] = 1; # tainted
3282                           !!!cp ('t72');      } else {
3283                           $self->{open_elements}->[-1]->[0]->append_child ($child);        !!!cp ('t72');
3284                         }        $self->{open_elements}->[-1]->[0]->append_child ($child);
3285        }
3286    }; # $insert_to_foster    }; # $insert_to_foster
3287    
   my $insert;  
   
3288    B: {    B: {
3289      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
3290        !!!cp ('t73');        !!!cp ('t73');
# Line 3261  sub _tree_construction_main ($) { Line 3293  sub _tree_construction_main ($) {
3293        ## Stay in the phase        ## Stay in the phase
3294        !!!next-token;        !!!next-token;
3295        redo B;        redo B;
     } elsif ($token->{type} == END_OF_FILE_TOKEN) {  
       if ($self->{insertion_mode} & AFTER_HTML_IMS) {  
         !!!cp ('t74');  
         #  
       } else {  
         ## 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]}) {  
           !!!cp ('t75');  
           !!!back-token;  
           $token = {type => END_TAG_TOKEN, tag_name => $self->{open_elements}->[-1]->[1]};  
           redo B;  
         }  
           
         if (@{$self->{open_elements}} > 2 or  
             (@{$self->{open_elements}} == 2 and $self->{open_elements}->[1]->[1] ne 'body')) {  
           !!!cp ('t76');  
           !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
         } elsif (defined $self->{inner_html_node} and  
                  @{$self->{open_elements}} > 1 and  
                  $self->{open_elements}->[1]->[1] ne 'body') {  
 ## ISSUE: This case is never reached.  
           !!!cp ('t77');  
           !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
         } else {  
           !!!cp ('t78');  
         }  
   
         ## ISSUE: There is an issue in the spec.  
       }  
   
       ## Stop parsing  
       last B;  
3296      } elsif ($token->{type} == START_TAG_TOKEN and      } elsif ($token->{type} == START_TAG_TOKEN and
3297               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
3298        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
# Line 3340  sub _tree_construction_main ($) { Line 3337  sub _tree_construction_main ($) {
3337      } elsif ($self->{insertion_mode} & HEAD_IMS) {      } elsif ($self->{insertion_mode} & HEAD_IMS) {
3338        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
3339          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3340            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            unless ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3341                !!!cp ('t88.2');
3342                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
3343              } else {
3344                !!!cp ('t88.1');
3345                ## Ignore the token.
3346                !!!next-token;
3347                redo B;
3348              }
3349            unless (length $token->{data}) {            unless (length $token->{data}) {
3350              !!!cp ('t88');              !!!cp ('t88');
3351              !!!next-token;              !!!next-token;
# Line 3441  sub _tree_construction_main ($) { Line 3446  sub _tree_construction_main ($) {
3446                }                }
3447                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3448                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3449                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3450                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3451                !!!next-token;                !!!next-token;
3452                redo B;                redo B;
# Line 3456  sub _tree_construction_main ($) { Line 3461  sub _tree_construction_main ($) {
3461                }                }
3462                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3463                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3464                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3465                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3466                !!!next-token;                !!!next-token;
3467                redo B;                redo B;
# Line 3517  sub _tree_construction_main ($) { Line 3522  sub _tree_construction_main ($) {
3522                  }                  }
3523                }                }
3524    
3525                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3526                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3527                !!!next-token;                !!!next-token;
3528                redo B;                redo B;
# Line 3541  sub _tree_construction_main ($) { Line 3546  sub _tree_construction_main ($) {
3546                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3547                my $parent = defined $self->{head_element} ? $self->{head_element}                my $parent = defined $self->{head_element} ? $self->{head_element}
3548                    : $self->{open_elements}->[-1]->[0];                    : $self->{open_elements}->[-1]->[0];
3549                $parse_rcdata->(RCDATA_CONTENT_MODEL,                $parse_rcdata->(RCDATA_CONTENT_MODEL);
3550                                sub { $parent->append_child ($_[0]) });                pop @{$self->{open_elements}} # <head>
               pop @{$self->{open_elements}}  
3551                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3552                redo B;                redo B;
3553              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style') {
# Line 3557  sub _tree_construction_main ($) { Line 3561  sub _tree_construction_main ($) {
3561                } else {                } else {
3562                  !!!cp ('t115');                  !!!cp ('t115');
3563                }                }
3564                $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);                $parse_rcdata->(CDATA_CONTENT_MODEL);
3565                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3566                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3567                redo B;                redo B;
3568              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
# Line 3597  sub _tree_construction_main ($) { Line 3601  sub _tree_construction_main ($) {
3601                }                }
3602    
3603                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3604                $script_start_tag->($insert_to_current);                $script_start_tag->();
3605                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3606                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3607                redo B;                redo B;
3608              } elsif ($token->{tag_name} eq 'body' or              } elsif ($token->{tag_name} eq 'body' or
# Line 3807  sub _tree_construction_main ($) { Line 3811  sub _tree_construction_main ($) {
3811              $self->{insertion_mode} = IN_BODY_IM;              $self->{insertion_mode} = IN_BODY_IM;
3812              ## reprocess              ## reprocess
3813              redo B;              redo B;
3814            } else {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
3815              die "$0: $token->{type}: Unknown token type";          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3816            }            !!!cp ('t149.1');
3817    
3818              ## NOTE: As if <head>
3819              !!!create-element ($self->{head_element}, 'head');
3820              $self->{open_elements}->[-1]->[0]->append_child
3821                  ($self->{head_element});
3822              #push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3823              #$self->{insertion_mode} = IN_HEAD_IM;
3824              ## NOTE: Reprocess.
3825    
3826              ## NOTE: As if </head>
3827              #pop @{$self->{open_elements}};
3828              #$self->{insertion_mode} = IN_AFTER_HEAD_IM;
3829              ## NOTE: Reprocess.
3830              
3831              #
3832            } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3833              !!!cp ('t149.2');
3834    
3835              ## NOTE: As if </head>
3836              pop @{$self->{open_elements}};
3837              #$self->{insertion_mode} = IN_AFTER_HEAD_IM;
3838              ## NOTE: Reprocess.
3839    
3840              #
3841            } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3842              !!!cp ('t149.3');
3843    
3844              !!!parse-error (type => 'in noscript:#eof');
3845    
3846              ## As if </noscript>
3847              pop @{$self->{open_elements}};
3848              #$self->{insertion_mode} = IN_HEAD_IM;
3849              ## NOTE: Reprocess.
3850    
3851              ## NOTE: As if </head>
3852              pop @{$self->{open_elements}};
3853              #$self->{insertion_mode} = IN_AFTER_HEAD_IM;
3854              ## NOTE: Reprocess.
3855    
3856              #
3857            } else {
3858              !!!cp ('t149.4');
3859              #
3860            }
3861    
3862            ## NOTE: As if <body>
3863            !!!insert-element ('body');
3864            $self->{insertion_mode} = IN_BODY_IM;
3865            ## NOTE: Reprocess.
3866            redo B;
3867          } else {
3868            die "$0: $token->{type}: Unknown token type";
3869          }
3870    
3871            ## ISSUE: An issue in the spec.            ## ISSUE: An issue in the spec.
3872      } elsif ($self->{insertion_mode} & BODY_IMS) {      } elsif ($self->{insertion_mode} & BODY_IMS) {
# Line 3886  sub _tree_construction_main ($) { Line 3943  sub _tree_construction_main ($) {
3943                    }                    }
3944                                    
3945                  ## generate implied end tags                  ## generate implied end tags
3946                  if ({                  while ({
3947                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
3948                           }->{$self->{open_elements}->[-1]->[1]}) {
                      ## NOTE: Maybe the following elements never appear here.  
                      td => 1, th => 1, tr => 1,  
                      tbody => 1, tfoot => 1, thead => 1,  
                     }->{$self->{open_elements}->[-1]->[1]}) {  
3949                    !!!cp ('t158');                    !!!cp ('t158');
3950                    !!!back-token; # <?>                    pop @{$self->{open_elements}};
                   $token = {type => END_TAG_TOKEN, tag_name => 'caption'};  
                   !!!back-token;  
                   $token = {type => END_TAG_TOKEN,  
                             tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                   redo B;  
3951                  }                  }
3952    
3953                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
# Line 3952  sub _tree_construction_main ($) { Line 4000  sub _tree_construction_main ($) {
4000                    }                    }
4001                                    
4002                  ## generate implied end tags                  ## generate implied end tags
4003                  if ({                  while ({
4004                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
4005                       td => ($token->{tag_name} eq 'th'),                         }->{$self->{open_elements}->[-1]->[1]}) {
                      th => ($token->{tag_name} eq 'td'),  
   
                      ## NOTE: Maybe the following elements never appear here.  
                      tr => 1,  
                      tbody => 1, tfoot => 1, thead => 1,  
                     }->{$self->{open_elements}->[-1]->[1]}) {  
4006                    !!!cp ('t166');                    !!!cp ('t166');
4007                    !!!back-token;                    pop @{$self->{open_elements}};
                   $token = {type => END_TAG_TOKEN,  
                             tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                   redo B;  
4008                  }                  }
4009                    
4010                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
4011                    !!!cp ('t167');                    !!!cp ('t167');
4012                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
# Line 4019  sub _tree_construction_main ($) { Line 4058  sub _tree_construction_main ($) {
4058                    }                    }
4059                                    
4060                  ## generate implied end tags                  ## generate implied end tags
4061                  if ({                  while ({
4062                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
4063                           }->{$self->{open_elements}->[-1]->[1]}) {
                      ## NOTE: The following elements never appear here, maybe.  
                      td => 1, th => 1, tr => 1,  
                      tbody => 1, tfoot => 1, thead => 1,  
                     }->{$self->{open_elements}->[-1]->[1]}) {  
4064                    !!!cp ('t174');                    !!!cp ('t174');
4065                    !!!back-token;                    pop @{$self->{open_elements}};
                   $token = {type => END_TAG_TOKEN,  
                             tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                   redo B;  
4066                  }                  }
4067                                    
4068                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
# Line 4127  sub _tree_construction_main ($) { Line 4159  sub _tree_construction_main ($) {
4159                }                }
4160                                
4161                ## generate implied end tags                ## generate implied end tags
4162                if ({                while ({
4163                     dd => 1, dt => 1, li => 1, p => 1,                        dd => 1, dt => 1, li => 1, p => 1,
4164                         }->{$self->{open_elements}->[-1]->[1]}) {
                    ## NOTE: The following elements never appear, maybe.  
                    td => 1, th => 1, tr => 1,  
                    tbody => 1, tfoot => 1, thead => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
4165                  !!!cp ('t187');                  !!!cp ('t187');
4166                  !!!back-token; # </table>                  pop @{$self->{open_elements}};
                 $token = {type => END_TAG_TOKEN, tag_name => 'caption'};  
                 !!!back-token;  
                 $token = {type => END_TAG_TOKEN,  
                           tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                 redo B;  
4167                }                }
4168    
4169                if ($self->{open_elements}->[-1]->[1] ne 'caption') {                if ($self->{open_elements}->[-1]->[1] ne 'caption') {
# Line 4185  sub _tree_construction_main ($) { Line 4208  sub _tree_construction_main ($) {
4208                !!!cp ('t193');                !!!cp ('t193');
4209                #                #
4210              }              }
4211          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
4212            for my $entry (@{$self->{open_elements}}) {
4213              if (not {
4214                dd => 1, dt => 1, li => 1, p => 1, tbody => 1, td => 1, tfoot => 1,
4215                th => 1, thead => 1, tr => 1, body => 1, html => 1,
4216              }->{$entry->[1]}) {
4217                !!!cp ('t75');
4218                !!!parse-error (type => 'in body:#eof');
4219                last;
4220              }
4221            }
4222    
4223            ## Stop parsing.
4224            last B;
4225        } else {        } else {
4226          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
4227        }        }
# Line 4193  sub _tree_construction_main ($) { Line 4230  sub _tree_construction_main ($) {
4230        #        #
4231      } elsif ($self->{insertion_mode} & TABLE_IMS) {      } elsif ($self->{insertion_mode} & TABLE_IMS) {
4232        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
4233              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if (not $open_tables->[-1]->[1] and # tainted
4234                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);              $token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4235              $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4236                                
4237                unless (length $token->{data}) {            unless (length $token->{data}) {
4238                  !!!cp ('t194');              !!!cp ('t194');
4239                  !!!next-token;              !!!next-token;
4240                  redo B;              redo B;
4241                } else {            } else {
4242                  !!!cp ('t195');              !!!cp ('t195');
4243                }            }
4244              }          }
4245    
4246              !!!parse-error (type => 'in table:#character');              !!!parse-error (type => 'in table:#character');
4247    
# Line 4250  sub _tree_construction_main ($) { Line 4288  sub _tree_construction_main ($) {
4288                    ($self->{document}->create_text_node ($token->{data}),                    ($self->{document}->create_text_node ($token->{data}),
4289                     $next_sibling);                     $next_sibling);
4290                }                }
4291              } else {            $open_tables->[-1]->[1] = 1; # tainted
4292                !!!cp ('t200');          } else {
4293                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});            !!!cp ('t200');
4294              }            $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4295            }
4296                            
4297              !!!next-token;          !!!next-token;
4298              redo B;          redo B;
4299        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
4300              if ({              if ({
4301                   tr => ($self->{insertion_mode} != IN_ROW_IM),                   tr => ($self->{insertion_mode} != IN_ROW_IM),
# Line 4267  sub _tree_construction_main ($) { Line 4306  sub _tree_construction_main ($) {
4306                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4307                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4308                    !!!cp ('t201');                    !!!cp ('t201');
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4309                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4310                  }                  }
4311                                    
# Line 4288  sub _tree_construction_main ($) { Line 4326  sub _tree_construction_main ($) {
4326                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4327                    !!!cp ('t203');                    !!!cp ('t203');
4328                    ## ISSUE: Can this case be reached?                    ## ISSUE: Can this case be reached?
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4329                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4330                  }                  }
4331                                    
# Line 4312  sub _tree_construction_main ($) { Line 4349  sub _tree_construction_main ($) {
4349                  tr => 1, html => 1,                  tr => 1, html => 1,
4350                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4351                  !!!cp ('t207');                  !!!cp ('t207');
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4352                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4353                }                }
4354                                
# Line 4363  sub _tree_construction_main ($) { Line 4399  sub _tree_construction_main ($) {
4399                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4400                    !!!cp ('t211');                    !!!cp ('t211');
4401                    ## ISSUE: Can this case be reached?                    ## ISSUE: Can this case be reached?
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4402                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4403                  }                  }
4404                                    
# Line 4412  sub _tree_construction_main ($) { Line 4447  sub _tree_construction_main ($) {
4447                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4448                    !!!cp ('t217');                    !!!cp ('t217');
4449                    ## ISSUE: Can this state be reached?                    ## ISSUE: Can this state be reached?
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4450                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4451                  }                  }
4452                                    
# Line 4436  sub _tree_construction_main ($) { Line 4470  sub _tree_construction_main ($) {
4470                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4471                    !!!cp ('t219');                    !!!cp ('t219');
4472                    ## ISSUE: Can this state be reached?                    ## ISSUE: Can this state be reached?
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4473                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4474                  }                  }
4475                                    
# Line 4454  sub _tree_construction_main ($) { Line 4487  sub _tree_construction_main ($) {
4487                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4488                    !!!cp ('t220');                    !!!cp ('t220');
4489                    ## ISSUE: Can this state be reached?                    ## ISSUE: Can this state be reached?
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4490                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4491                  }                  }
4492                                    
# Line 4503  sub _tree_construction_main ($) { Line 4535  sub _tree_construction_main ($) {
4535                  redo B;                  redo B;
4536                }                }
4537                                
4538    ## TODO: Followings are removed from the latest spec.
4539                ## generate implied end tags                ## generate implied end tags
4540                if ({                while ({
4541                     dd => 1, dt => 1, li => 1, p => 1,                        dd => 1, dt => 1, li => 1, p => 1,
4542                     td => 1, th => 1, tr => 1,                       }->{$self->{open_elements}->[-1]->[1]}) {
                    tbody => 1, tfoot=> 1, thead => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
4543                  !!!cp ('t224');                  !!!cp ('t224');
4544                  !!!back-token; # <table>                  pop @{$self->{open_elements}};
                 $token = {type => END_TAG_TOKEN, tag_name => 'table'};  
                 !!!back-token;  
                 $token = {type => END_TAG_TOKEN,  
                           tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                 redo B;  
4545                }                }
4546    
4547                if ($self->{open_elements}->[-1]->[1] ne 'table') {                if ($self->{open_elements}->[-1]->[1] ne 'table') {
# Line 4527  sub _tree_construction_main ($) { Line 4553  sub _tree_construction_main ($) {
4553                }                }
4554    
4555                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4556                  pop @{$open_tables};
4557    
4558                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
4559    
4560                ## reprocess                ## reprocess
4561                redo B;                redo B;
4562            } elsif ($token->{tag_name} eq 'style') {
4563              if (not $open_tables->[-1]->[1]) { # tainted
4564                !!!cp ('t227.8');
4565                ## NOTE: This is a "as if in head" code clone.
4566                $parse_rcdata->(CDATA_CONTENT_MODEL);
4567                redo B;
4568              } else {
4569                !!!cp ('t227.7');
4570                #
4571              }
4572            } elsif ($token->{tag_name} eq 'script') {
4573              if (not $open_tables->[-1]->[1]) { # tainted
4574                !!!cp ('t227.6');
4575                ## NOTE: This is a "as if in head" code clone.
4576                $script_start_tag->();
4577                redo B;
4578              } else {
4579                !!!cp ('t227.5');
4580                #
4581              }
4582            } elsif ($token->{tag_name} eq 'input') {
4583              if (not $open_tables->[-1]->[1]) { # tainted
4584                if ($token->{attributes}->{type}) { ## TODO: case
4585                  my $type = lc $token->{attributes}->{type}->{value};
4586                  if ($type eq 'hidden') {
4587                    !!!cp ('t227.3');
4588                    !!!parse-error (type => 'in table:'.$token->{tag_name});
4589    
4590                    !!!insert-element ($token->{tag_name}, $token->{attributes});
4591    
4592                    ## TODO: form element pointer
4593    
4594                    pop @{$self->{open_elements}};
4595    
4596                    !!!next-token;
4597                    redo B;
4598                  } else {
4599                    !!!cp ('t227.2');
4600                    #
4601                  }
4602                } else {
4603                  !!!cp ('t227.1');
4604                  #
4605                }
4606              } else {
4607                !!!cp ('t227.4');
4608                #
4609              }
4610          } else {          } else {
4611            !!!cp ('t227');            !!!cp ('t227');
           !!!parse-error (type => 'in table:'.$token->{tag_name});  
   
           $insert = $insert_to_foster;  
4612            #            #
4613          }          }
4614    
4615            !!!parse-error (type => 'in table:'.$token->{tag_name});
4616    
4617            $insert = $insert_to_foster;
4618            #
4619        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
4620              if ($token->{tag_name} eq 'tr' and              if ($token->{tag_name} eq 'tr' and
4621                  $self->{insertion_mode} == IN_ROW_IM) {                  $self->{insertion_mode} == IN_ROW_IM) {
# Line 4573  sub _tree_construction_main ($) { Line 4650  sub _tree_construction_main ($) {
4650                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4651                  !!!cp ('t231');                  !!!cp ('t231');
4652  ## ISSUE: Can this state be reached?  ## ISSUE: Can this state be reached?
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4653                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4654                }                }
4655    
# Line 4614  sub _tree_construction_main ($) { Line 4690  sub _tree_construction_main ($) {
4690                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4691                    !!!cp ('t236');                    !!!cp ('t236');
4692  ## ISSUE: Can this state be reached?  ## ISSUE: Can this state be reached?
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4693                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4694                  }                  }
4695                                    
# Line 4654  sub _tree_construction_main ($) { Line 4729  sub _tree_construction_main ($) {
4729                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4730                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4731                    !!!cp ('t240');                    !!!cp ('t240');
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4732                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4733                  }                  }
4734                                    
# Line 4670  sub _tree_construction_main ($) { Line 4744  sub _tree_construction_main ($) {
4744                  ## reprocess in the "in table" insertion mode...                  ## reprocess in the "in table" insertion mode...
4745                }                }
4746    
4747                  ## NOTE: </table> in the "in table" insertion mode.
4748                  ## When you edit the code fragment below, please ensure that
4749                  ## the code for <table> in the "in table" insertion mode
4750                  ## is synced with it.
4751    
4752                ## have a table element in table scope                ## have a table element in table scope
4753                my $i;                my $i;
4754                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
# Line 4692  sub _tree_construction_main ($) { Line 4771  sub _tree_construction_main ($) {
4771                  !!!next-token;                  !!!next-token;
4772                  redo B;                  redo B;
4773                }                }
   
               ## 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]}) {  
                 !!!cp ('t244');  
 ## ISSUE: Can this case be reached?  
                 !!!back-token;  
                 $token = {type => END_TAG_TOKEN,  
                           tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                 redo B;  
               }  
                 
               if ($self->{open_elements}->[-1]->[1] ne 'table') {  
                 !!!cp ('t245');  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
               } else {  
                 !!!cp ('t246');  
               }  
4774                                    
4775                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4776                  pop @{$open_tables};
4777                                
4778                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
4779                                
# Line 4778  sub _tree_construction_main ($) { Line 4837  sub _tree_construction_main ($) {
4837                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4838                    !!!cp ('t253');                    !!!cp ('t253');
4839  ## ISSUE: Can this case be reached?  ## ISSUE: Can this case be reached?
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4840                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4841                  }                  }
4842                                    
# Line 4816  sub _tree_construction_main ($) { Line 4874  sub _tree_construction_main ($) {
4874                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4875                  !!!cp ('t257');                  !!!cp ('t257');
4876  ## ISSUE: Can this case be reached?  ## ISSUE: Can this case be reached?
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4877                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4878                }                }
4879    
# Line 4842  sub _tree_construction_main ($) { Line 4899  sub _tree_construction_main ($) {
4899            $insert = $insert_to_foster;            $insert = $insert_to_foster;
4900            #            #
4901          }          }
4902          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
4903            unless ($self->{open_elements}->[-1]->[1] eq 'html' and
4904                    @{$self->{open_elements}} == 1) { # redundant, maybe
4905              !!!parse-error (type => 'in body:#eof');
4906              !!!cp ('t259.1');
4907              #
4908            } else {
4909              !!!cp ('t259.2');
4910              #
4911            }
4912    
4913            ## Stop parsing
4914            last B;
4915        } else {        } else {
4916          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
4917        }        }
# Line 4894  sub _tree_construction_main ($) { Line 4964  sub _tree_construction_main ($) {
4964                !!!cp ('t267');                !!!cp ('t267');
4965                #                #
4966              }              }
4967            } else {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
4968              die "$0: $token->{type}: Unknown token type";          if ($self->{open_elements}->[-1]->[1] eq 'html' or
4969            }              @{$self->{open_elements}} == 1) { # redundant, maybe
4970              !!!cp ('t270.2');
4971              ## Stop parsing.
4972              last B;
4973            } else {
4974              ## NOTE: As if </colgroup>.
4975              !!!cp ('t270.1');
4976              pop @{$self->{open_elements}}; # colgroup
4977              $self->{insertion_mode} = IN_TABLE_IM;
4978              ## Reprocess.
4979              redo B;
4980            }
4981          } else {
4982            die "$0: $token->{type}: Unknown token type";
4983          }
4984    
4985            ## As if </colgroup>            ## As if </colgroup>
4986            if ($self->{open_elements}->[-1]->[1] eq 'html') {            if ($self->{open_elements}->[-1]->[1] eq 'html') {
4987              !!!cp ('t269');              !!!cp ('t269');
4988    ## TODO: Wrong error type?
4989              !!!parse-error (type => 'unmatched end tag:colgroup');              !!!parse-error (type => 'unmatched end tag:colgroup');
4990              ## Ignore the token              ## Ignore the token
4991              !!!next-token;              !!!next-token;
# Line 4912  sub _tree_construction_main ($) { Line 4997  sub _tree_construction_main ($) {
4997              ## reprocess              ## reprocess
4998              redo B;              redo B;
4999            }            }
5000      } elsif ($self->{insertion_mode} == IN_SELECT_IM) {      } elsif ($self->{insertion_mode} & SELECT_IMS) {
5001        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
5002          !!!cp ('t271');          !!!cp ('t271');
5003          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
# Line 4951  sub _tree_construction_main ($) { Line 5036  sub _tree_construction_main ($) {
5036                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
5037                !!!next-token;                !!!next-token;
5038                redo B;                redo B;
5039              } elsif ($token->{tag_name} eq 'select') {          } elsif ($token->{tag_name} eq 'select' or
5040  ## TODO: The type below is not good - <select> is replaced by </select>                   $token->{tag_name} eq 'input' or
5041                !!!parse-error (type => 'not closed:select');                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
5042                ## As if </select> instead                    {
5043                       caption => 1, table => 1,
5044                       tbody => 1, tfoot => 1, thead => 1,
5045                       tr => 1, td => 1, th => 1,
5046                      }->{$token->{tag_name}})) {
5047              ## TODO: The type below is not good - <select> is replaced by </select>
5048              !!!parse-error (type => 'not closed:select');
5049              ## NOTE: As if the token were </select> (<select> case) or
5050              ## as if there were </select> (otherwise).
5051                ## have an element in table scope                ## have an element in table scope
5052                my $i;                my $i;
5053                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5054                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5055                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq 'select') {
5056                    !!!cp ('t278');                    !!!cp ('t278');
5057                    $i = $_;                    $i = $_;
5058                    last INSCOPE;                    last INSCOPE;
# Line 4983  sub _tree_construction_main ($) { Line 5076  sub _tree_construction_main ($) {
5076    
5077                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
5078    
5079                !!!next-token;            if ($token->{tag_name} eq 'select') {
5080                redo B;              !!!cp ('t281.2');
5081                !!!next-token;
5082                redo B;
5083              } else {
5084                !!!cp ('t281.1');
5085                ## Reprocess the token.
5086                redo B;
5087              }
5088          } else {          } else {
5089            !!!cp ('t282');            !!!cp ('t282');
5090            !!!parse-error (type => 'in select:'.$token->{tag_name});            !!!parse-error (type => 'in select:'.$token->{tag_name});
# Line 5051  sub _tree_construction_main ($) { Line 5151  sub _tree_construction_main ($) {
5151    
5152                !!!next-token;                !!!next-token;
5153                redo B;                redo B;
5154              } elsif ({          } elsif ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
5155                        caption => 1, table => 1, tbody => 1,                   {
5156                        tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    caption => 1, table => 1, tbody => 1,
5157                       }->{$token->{tag_name}}) {                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
5158                     }->{$token->{tag_name}}) {
5159  ## TODO: The following is wrong?  ## TODO: The following is wrong?
5160                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5161                                
# Line 5120  sub _tree_construction_main ($) { Line 5221  sub _tree_construction_main ($) {
5221            !!!next-token;            !!!next-token;
5222            redo B;            redo B;
5223          }          }
5224          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
5225            unless ($self->{open_elements}->[-1]->[1] eq 'html' and
5226                    @{$self->{open_elements}} == 1) { # redundant, maybe
5227              !!!cp ('t299.1');
5228              !!!parse-error (type => 'in body:#eof');
5229            } else {
5230              !!!cp ('t299.2');
5231            }
5232    
5233            ## Stop parsing.
5234            last B;
5235        } else {        } else {
5236          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
5237        }        }
# Line 5203  sub _tree_construction_main ($) { Line 5315  sub _tree_construction_main ($) {
5315            ## reprocess            ## reprocess
5316            redo B;            redo B;
5317          }          }
5318          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
5319            !!!cp ('t309.2');
5320            ## Stop parsing
5321            last B;
5322        } else {        } else {
5323          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
5324        }        }
# Line 5273  sub _tree_construction_main ($) { Line 5389  sub _tree_construction_main ($) {
5389          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
5390            !!!cp ('t320');            !!!cp ('t320');
5391            ## NOTE: As if in body.            ## NOTE: As if in body.
5392            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);            $parse_rcdata->(CDATA_CONTENT_MODEL);
5393            redo B;            redo B;
5394          } else {          } else {
5395            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
# Line 5338  sub _tree_construction_main ($) { Line 5454  sub _tree_construction_main ($) {
5454            !!!next-token;            !!!next-token;
5455            redo B;            redo B;
5456          }          }
5457          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
5458            unless ($self->{open_elements}->[-1]->[1] eq 'html' and
5459                    @{$self->{open_elements}} == 1) { # redundant, maybe
5460              !!!cp ('t331.1');
5461              !!!parse-error (type => 'in body:#eof');
5462            } else {
5463              !!!cp ('t331.2');
5464            }
5465            
5466            ## Stop parsing
5467            last B;
5468        } else {        } else {
5469          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
5470        }        }
# Line 5352  sub _tree_construction_main ($) { Line 5479  sub _tree_construction_main ($) {
5479        if ($token->{tag_name} eq 'script') {        if ($token->{tag_name} eq 'script') {
5480          !!!cp ('t332');          !!!cp ('t332');
5481          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5482          $script_start_tag->($insert);          $script_start_tag->();
5483          redo B;          redo B;
5484        } elsif ($token->{tag_name} eq 'style') {        } elsif ($token->{tag_name} eq 'style') {
5485          !!!cp ('t333');          !!!cp ('t333');
5486          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5487          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL);
5488          redo B;          redo B;
5489        } elsif ({        } elsif ({
5490                  base => 1, link => 1,                  base => 1, link => 1,
# Line 5420  sub _tree_construction_main ($) { Line 5547  sub _tree_construction_main ($) {
5547          redo B;          redo B;
5548        } elsif ($token->{tag_name} eq 'title') {        } elsif ($token->{tag_name} eq 'title') {
5549          !!!cp ('t341');          !!!cp ('t341');
         !!!parse-error (type => 'in body:title');  
5550          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5551          $parse_rcdata->(RCDATA_CONTENT_MODEL, sub {          $parse_rcdata->(RCDATA_CONTENT_MODEL);
           if (defined $self->{head_element}) {  
             !!!cp ('t339');  
             $self->{head_element}->append_child ($_[0]);  
           } else {  
             !!!cp ('t340');  
             $insert->($_[0]);  
           }  
         });  
5552          redo B;          redo B;
5553        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
5554          !!!parse-error (type => 'in body:body');          !!!parse-error (type => 'in body:body');
# Line 5454  sub _tree_construction_main ($) { Line 5572  sub _tree_construction_main ($) {
5572          redo B;          redo B;
5573        } elsif ({        } elsif ({
5574                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
5575                  div => 1, dl => 1, fieldset => 1, listing => 1,                  div => 1, dl => 1, fieldset => 1,
5576                    h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
5577                  menu => 1, ol => 1, p => 1, ul => 1,                  menu => 1, ol => 1, p => 1, ul => 1,
5578                  pre => 1,                  pre => 1, listing => 1,
5579                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5580          ## has a p element in scope          ## has a p element in scope
5581          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
# Line 5466  sub _tree_construction_main ($) { Line 5585  sub _tree_construction_main ($) {
5585              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5586              redo B;              redo B;
5587            } elsif ({            } elsif ({
5588                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5589                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5590                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5591              !!!cp ('t345');              !!!cp ('t345');
# Line 5475  sub _tree_construction_main ($) { Line 5594  sub _tree_construction_main ($) {
5594          } # INSCOPE          } # INSCOPE
5595                        
5596          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5597          if ($token->{tag_name} eq 'pre') {          if ($token->{tag_name} eq 'pre' or $token->{tag_name} eq 'listing') {
5598            !!!next-token;            !!!next-token;
5599            if ($token->{type} == CHARACTER_TOKEN) {            if ($token->{type} == CHARACTER_TOKEN) {
5600              $token->{data} =~ s/^\x0A//;              $token->{data} =~ s/^\x0A//;
# Line 5509  sub _tree_construction_main ($) { Line 5628  sub _tree_construction_main ($) {
5628                $token = {type => END_TAG_TOKEN, tag_name => 'p'};                $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5629                redo B;                redo B;
5630              } elsif ({              } elsif ({
5631                        table => 1, caption => 1, td => 1, th => 1,                        applet => 1, table => 1, caption => 1, td => 1, th => 1,
5632                        button => 1, marquee => 1, object => 1, html => 1,                        button => 1, marquee => 1, object => 1, html => 1,
5633                       }->{$_->[1]}) {                       }->{$_->[1]}) {
5634                !!!cp ('t352');                !!!cp ('t352');
# Line 5531  sub _tree_construction_main ($) { Line 5650  sub _tree_construction_main ($) {
5650              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5651              redo B;              redo B;
5652            } elsif ({            } elsif ({
5653                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5654                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5655                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5656              !!!cp ('t354');              !!!cp ('t354');
# Line 5587  sub _tree_construction_main ($) { Line 5706  sub _tree_construction_main ($) {
5706              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5707              redo B;              redo B;
5708            } elsif ({            } elsif ({
5709                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5710                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5711                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5712              !!!cp ('t361');              !!!cp ('t361');
# Line 5643  sub _tree_construction_main ($) { Line 5762  sub _tree_construction_main ($) {
5762              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5763              redo B;              redo B;
5764            } elsif ({            } elsif ({
5765                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5766                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5767                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5768              !!!cp ('t368');              !!!cp ('t368');
# Line 5657  sub _tree_construction_main ($) { Line 5776  sub _tree_construction_main ($) {
5776                        
5777          !!!next-token;          !!!next-token;
5778          redo B;          redo B;
       } elsif ({  
                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,  
                }->{$token->{tag_name}}) {  
         ## has a p element in scope  
         INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
           my $node = $self->{open_elements}->[$_];  
           if ($node->[1] eq 'p') {  
             !!!cp ('t369');  
             !!!back-token;  
             $token = {type => END_TAG_TOKEN, tag_name => 'p'};  
             redo B;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
             !!!cp ('t370');  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         ## NOTE: See <http://html5.org/tools/web-apps-tracker?from=925&to=926>  
         ## has an element in scope  
         #my $i;  
         #INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
         #  my $node = $self->{open_elements}->[$_];  
         #  if ({  
         #       h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,  
         #      }->{$node->[1]}) {  
         #    $i = $_;  
         #    last INSCOPE;  
         #  } elsif ({  
         #            table => 1, caption => 1, td => 1, th => 1,  
         #            button => 1, marquee => 1, object => 1, html => 1,  
         #           }->{$node->[1]}) {  
         #    last INSCOPE;  
         #  }  
         #} # INSCOPE  
         #    
         #if (defined $i) {  
         #  !!! parse-error (type => 'in hn:hn');  
         #  splice @{$self->{open_elements}}, $i;  
         #}  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
             
         !!!next-token;  
         redo B;  
5779        } elsif ($token->{tag_name} eq 'a') {        } elsif ($token->{tag_name} eq 'a') {
5780          AFE: for my $i (reverse 0..$#$active_formatting_elements) {          AFE: for my $i (reverse 0..$#$active_formatting_elements) {
5781            my $node = $active_formatting_elements->[$i];            my $node = $active_formatting_elements->[$i];
# Line 5769  sub _tree_construction_main ($) { Line 5841  sub _tree_construction_main ($) {
5841              $token = {type => END_TAG_TOKEN, tag_name => 'nobr'};              $token = {type => END_TAG_TOKEN, tag_name => 'nobr'};
5842              redo B;              redo B;
5843            } elsif ({            } elsif ({
5844                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5845                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5846                     }->{$node->[1]}) {                     }->{$node->[1]}) {
5847              !!!cp ('t377');              !!!cp ('t377');
# Line 5793  sub _tree_construction_main ($) { Line 5865  sub _tree_construction_main ($) {
5865              $token = {type => END_TAG_TOKEN, tag_name => 'button'};              $token = {type => END_TAG_TOKEN, tag_name => 'button'};
5866              redo B;              redo B;
5867            } elsif ({            } elsif ({
5868                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5869                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5870                     }->{$node->[1]}) {                     }->{$node->[1]}) {
5871              !!!cp ('t379');              !!!cp ('t379');
# Line 5804  sub _tree_construction_main ($) { Line 5876  sub _tree_construction_main ($) {
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});
5879    
5880            ## TODO: associate with $self->{form_element} if defined
5881    
5882          push @$active_formatting_elements, ['#marker', ''];          push @$active_formatting_elements, ['#marker', ''];
5883    
5884          !!!next-token;          !!!next-token;
5885          redo B;          redo B;
5886        } elsif ($token->{tag_name} eq 'marquee' or        } elsif ({
5887                 $token->{tag_name} eq 'object') {                  applet => 1, marquee => 1, object => 1,
5888                   }->{$token->{tag_name}}) {
5889          !!!cp ('t380');          !!!cp ('t380');
5890          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5891                    
# Line 5821  sub _tree_construction_main ($) { Line 5897  sub _tree_construction_main ($) {
5897        } elsif ($token->{tag_name} eq 'xmp') {        } elsif ($token->{tag_name} eq 'xmp') {
5898          !!!cp ('t381');          !!!cp ('t381');
5899          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5900          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL);
5901          redo B;          redo B;
5902        } elsif ($token->{tag_name} eq 'table') {        } elsif ($token->{tag_name} eq 'table') {
5903          ## has a p element in scope          ## has a p element in scope
# Line 5832  sub _tree_construction_main ($) { Line 5908  sub _tree_construction_main ($) {
5908              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5909              redo B;              redo B;
5910            } elsif ({            } elsif ({
5911                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5912                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5913                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5914              !!!cp ('t383');              !!!cp ('t383');
# Line 5841  sub _tree_construction_main ($) { Line 5917  sub _tree_construction_main ($) {
5917          } # INSCOPE          } # INSCOPE
5918                        
5919          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5920                      push @{$open_tables}, [$self->{open_elements}->[-1]->[0]];
5921    
5922          $self->{insertion_mode} = IN_TABLE_IM;          $self->{insertion_mode} = IN_TABLE_IM;
5923                        
5924          !!!next-token;          !!!next-token;
# Line 5876  sub _tree_construction_main ($) { Line 5953  sub _tree_construction_main ($) {
5953              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5954              redo B;              redo B;
5955            } elsif ({            } elsif ({
5956                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5957                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5958                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5959              !!!cp ('t387');              !!!cp ('t387');
# Line 5996  sub _tree_construction_main ($) { Line 6073  sub _tree_construction_main ($) {
6073                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6074          !!!cp ('t399');          !!!cp ('t399');
6075          ## NOTE: There is an "as if in body" code clone.          ## NOTE: There is an "as if in body" code clone.
6076          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL);
6077          redo B;          redo B;
6078        } elsif ($token->{tag_name} eq 'select') {        } elsif ($token->{tag_name} eq 'select') {
6079          !!!cp ('t400');          !!!cp ('t400');
6080          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
6081                    
6082          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
6083    
6084            ## TODO: associate with $self->{form_element} if defined
6085                    
6086          $self->{insertion_mode} = IN_SELECT_IM;          if ($self->{insertion_mode} & TABLE_IMS or
6087                $self->{insertion_mode} & BODY_TABLE_IMS or
6088                $self->{insertion_mode} == IN_COLUMN_GROUP_IM) {
6089              !!!cp ('t400.1');
6090              $self->{insertion_mode} = IN_SELECT_IN_TABLE_IM;
6091            } else {
6092              !!!cp ('t400.2');
6093              $self->{insertion_mode} = IN_SELECT_IM;
6094            }
6095          !!!next-token;          !!!next-token;
6096          redo B;          redo B;
6097        } elsif ({        } elsif ({
# Line 6079  sub _tree_construction_main ($) { Line 6166  sub _tree_construction_main ($) {
6166                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
6167                  div => 1, dl => 1, fieldset => 1, listing => 1,                  div => 1, dl => 1, fieldset => 1, listing => 1,
6168                  menu => 1, ol => 1, pre => 1, ul => 1,                  menu => 1, ol => 1, pre => 1, ul => 1,
                 p => 1,  
6169                  dd => 1, dt => 1, li => 1,                  dd => 1, dt => 1, li => 1,
6170                  button => 1, marquee => 1, object => 1,                  applet => 1, button => 1, marquee => 1, object => 1,
6171                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6172          ## has an element in scope          ## has an element in scope
6173          my $i;          my $i;
6174          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6175            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
6176            if ($node->[1] eq $token->{tag_name}) {            if ($node->[1] eq $token->{tag_name}) {
             ## generate implied end tags  
             if ({  
                  dd => ($token->{tag_name} ne 'dd'),  
                  dt => ($token->{tag_name} ne 'dt'),  
                  li => ($token->{tag_name} ne 'li'),  
                  p => ($token->{tag_name} ne 'p'),  
                  td => 1, th => 1, tr => 1,  
                  tbody => 1, tfoot=> 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
               !!!cp ('t409');  
               !!!back-token;  
               $token = {type => END_TAG_TOKEN,  
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               redo B;  
             }  
               
6177              !!!cp ('t410');              !!!cp ('t410');
6178              $i = $_;              $i = $_;
6179              last INSCOPE unless $token->{tag_name} eq 'p';              last INSCOPE;
6180            } elsif ({            } elsif ({
6181                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
6182                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6183                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6184              !!!cp ('t411');              !!!cp ('t411');
6185              last INSCOPE;              last INSCOPE;
6186            }            }
6187          } # INSCOPE          } # INSCOPE
6188            
6189          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          unless (defined $i) { # has an element in scope
6190            if (defined $i) {            !!!cp ('t413');
6191              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6192            } else {
6193              ## Step 1. generate implied end tags
6194              while ({
6195                      dd => ($token->{tag_name} ne 'dd'),
6196                      dt => ($token->{tag_name} ne 'dt'),
6197                      li => ($token->{tag_name} ne 'li'),
6198                      p => 1,
6199                     }->{$self->{open_elements}->[-1]->[1]}) {
6200                !!!cp ('t409');
6201                pop @{$self->{open_elements}};
6202              }
6203    
6204              ## Step 2.
6205              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6206              !!!cp ('t412');              !!!cp ('t412');
6207              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6208            } else {            } else {
6209              !!!cp ('t413');              !!!cp ('t414');
             !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
6210            }            }
6211          }  
6212                      ## Step 3.
         if (defined $i) {  
           !!!cp ('t414');  
6213            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
6214          } elsif ($token->{tag_name} eq 'p') {  
6215            !!!cp ('t415');            ## Step 4.
6216            ## As if <p>, then reprocess the current token            $clear_up_to_marker->()
6217            my $el;                if {
6218            !!!create-element ($el, 'p');                  applet => 1, button => 1, marquee => 1, object => 1,
6219            $insert->($el);                }->{$token->{tag_name}};
         } else {  
           !!!cp ('t416');  
6220          }          }
         $clear_up_to_marker->()  
           if {  
             button => 1, marquee => 1, object => 1,  
           }->{$token->{tag_name}};  
6221          !!!next-token;          !!!next-token;
6222          redo B;          redo B;
6223        } elsif ($token->{tag_name} eq 'form') {        } elsif ($token->{tag_name} eq 'form') {
6224            undef $self->{form_element};
6225    
6226          ## has an element in scope          ## has an element in scope
6227            my $i;
6228          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6229            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
6230            if ($node->[1] eq $token->{tag_name}) {            if ($node->[1] eq $token->{tag_name}) {
             ## generate implied end tags  
             if ({  
                  dd => 1, dt => 1, li => 1, p => 1,  
   
                  ## NOTE: The following elements never appear here, maybe.  
                  td => 1, th => 1, tr => 1,  
                  tbody => 1, tfoot => 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
               !!!cp ('t417');  
               !!!back-token;  
               $token = {type => END_TAG_TOKEN,  
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               redo B;  
             }  
               
6231              !!!cp ('t418');              !!!cp ('t418');
6232                $i = $_;
6233              last INSCOPE;              last INSCOPE;
6234            } elsif ({            } elsif ({
6235                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
6236                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6237                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6238              !!!cp ('t419');              !!!cp ('t419');
6239              last INSCOPE;              last INSCOPE;
6240            }            }
6241          } # INSCOPE          } # INSCOPE
6242            
6243          if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) {          unless (defined $i) { # has an element in scope
           !!!cp ('t420');  
           pop @{$self->{open_elements}};  
         } else {  
6244            !!!cp ('t421');            !!!cp ('t421');
6245            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6246            } else {
6247              ## Step 1. generate implied end tags
6248              while ({
6249                      dd => 1, dt => 1, li => 1, p => 1,
6250                     }->{$self->{open_elements}->[-1]->[1]}) {
6251                !!!cp ('t417');
6252                pop @{$self->{open_elements}};
6253              }
6254              
6255              ## Step 2.
6256              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6257                !!!cp ('t417.1');
6258                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6259              } else {
6260                !!!cp ('t420');
6261              }  
6262              
6263              ## Step 3.
6264              splice @{$self->{open_elements}}, $i;
6265          }          }
6266    
         undef $self->{form_element};  
6267          !!!next-token;          !!!next-token;
6268          redo B;          redo B;
6269        } elsif ({        } elsif ({
# Line 6196  sub _tree_construction_main ($) { Line 6276  sub _tree_construction_main ($) {
6276            if ({            if ({
6277                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
6278                }->{$node->[1]}) {                }->{$node->[1]}) {
             ## 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]}) {  
               !!!cp ('t422');  
               !!!back-token;  
               $token = {type => END_TAG_TOKEN,  
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               redo B;  
             }  
   
6279              !!!cp ('t423');              !!!cp ('t423');
6280              $i = $_;              $i = $_;
6281              last INSCOPE;              last INSCOPE;
6282            } elsif ({            } elsif ({
6283                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
6284                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6285                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6286              !!!cp ('t424');              !!!cp ('t424');
6287              last INSCOPE;              last INSCOPE;
6288            }            }
6289          } # INSCOPE          } # INSCOPE
6290            
6291          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          unless (defined $i) { # has an element in scope
6292            !!!cp ('t425');            !!!cp ('t425.1');
6293            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6294          } else {          } else {
6295            !!!cp ('t426');            ## Step 1. generate implied end tags
6296              while ({
6297                      dd => 1, dt => 1, li => 1, p => 1,
6298                     }->{$self->{open_elements}->[-1]->[1]}) {
6299                !!!cp ('t422');
6300                pop @{$self->{open_elements}};
6301              }
6302              
6303              ## Step 2.
6304              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6305                !!!cp ('t425');
6306                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6307              } else {
6308                !!!cp ('t426');
6309              }
6310    
6311              ## Step 3.
6312              splice @{$self->{open_elements}}, $i;
6313          }          }
6314                    
6315          splice @{$self->{open_elements}}, $i if defined $i;          !!!next-token;
6316            redo B;
6317          } elsif ($token->{tag_name} eq 'p') {
6318            ## has an element in scope
6319            my $i;
6320            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6321              my $node = $self->{open_elements}->[$_];
6322              if ($node->[1] eq $token->{tag_name}) {
6323                !!!cp ('t410.1');
6324                $i = $_;
6325                last INSCOPE;
6326              } elsif ({
6327                        applet => 1, table => 1, caption => 1, td => 1, th => 1,
6328                        button => 1, marquee => 1, object => 1, html => 1,
6329                       }->{$node->[1]}) {
6330                !!!cp ('t411.1');
6331                last INSCOPE;
6332              }
6333            } # INSCOPE
6334    
6335            if (defined $i) {
6336              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6337                !!!cp ('t412.1');
6338                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6339              } else {
6340                !!!cp ('t414.1');
6341              }
6342    
6343              splice @{$self->{open_elements}}, $i;
6344            } else {
6345              !!!cp ('t413.1');
6346              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6347    
6348              !!!cp ('t415.1');
6349              ## As if <p>, then reprocess the current token
6350              my $el;
6351              !!!create-element ($el, 'p');
6352              $insert->($el);
6353              ## NOTE: Not inserted into |$self->{open_elements}|.
6354            }
6355    
6356          !!!next-token;          !!!next-token;
6357          redo B;          redo B;
6358        } elsif ({        } elsif ({
# Line 6284  sub _tree_construction_main ($) { Line 6408  sub _tree_construction_main ($) {
6408            if ($node->[1] eq $token->{tag_name}) {            if ($node->[1] eq $token->{tag_name}) {
6409              ## Step 1              ## Step 1
6410              ## generate implied end tags              ## generate implied end tags
6411              if ({              while ({
6412                   dd => 1, dt => 1, li => 1, p => 1,                      dd => 1, dt => 1, li => 1, p => 1,
6413                   td => 1, th => 1, tr => 1,                     }->{$self->{open_elements}->[-1]->[1]}) {
                  tbody => 1, tfoot => 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
6414                !!!cp ('t430');                !!!cp ('t430');
6415                ## ISSUE: Can this case be reached?                ## ISSUE: Can this case be reached?
6416                !!!back-token;                pop @{$self->{open_elements}};
               $token = {type => END_TAG_TOKEN,  
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               redo B;  
6417              }              }
6418                    
6419              ## Step 2              ## Step 2

Legend:
Removed from v.1.84  
changed lines
  Added in v.1.106

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24