/[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.82 by wakaba, Wed Mar 5 02:55:08 2008 UTC revision 1.94 by wakaba, Sat Mar 8 04:13:10 2008 UTC
# Line 304  sub ROW_IMS ()        { 0b10000000 } Line 304  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    
307    ## NOTE: "initial" and "before html" insertion modes have no constants.
308    
309    ## NOTE: "after after body" insertion mode.
310  sub AFTER_HTML_BODY_IM () { AFTER_HTML_IMS | BODY_AFTER_IMS }  sub AFTER_HTML_BODY_IM () { AFTER_HTML_IMS | BODY_AFTER_IMS }
311    
312    ## NOTE: "after after frameset" insertion mode.
313  sub AFTER_HTML_FRAMESET_IM () { AFTER_HTML_IMS | FRAME_IMS }  sub AFTER_HTML_FRAMESET_IM () { AFTER_HTML_IMS | FRAME_IMS }
314    
315  sub IN_HEAD_IM () { HEAD_IMS | 0b00 }  sub IN_HEAD_IM () { HEAD_IMS | 0b00 }
316  sub IN_HEAD_NOSCRIPT_IM () { HEAD_IMS | 0b01 }  sub IN_HEAD_NOSCRIPT_IM () { HEAD_IMS | 0b01 }
317  sub AFTER_HEAD_IM () { HEAD_IMS | 0b10 }  sub AFTER_HEAD_IM () { HEAD_IMS | 0b10 }
# Line 2420  sub _construct_tree ($) { Line 2426  sub _construct_tree ($) {
2426        
2427    !!!next-token;    !!!next-token;
2428    
   $self->{insertion_mode} = BEFORE_HEAD_IM;  
2429    undef $self->{form_element};    undef $self->{form_element};
2430    undef $self->{head_element};    undef $self->{head_element};
2431    $self->{open_elements} = [];    $self->{open_elements} = [];
2432    undef $self->{inner_html_node};    undef $self->{inner_html_node};
2433    
2434      ## NOTE: The "initial" insertion mode.
2435    $self->_tree_construction_initial; # MUST    $self->_tree_construction_initial; # MUST
2436    
2437      ## NOTE: The "before html" insertion mode.
2438    $self->_tree_construction_root_element;    $self->_tree_construction_root_element;
2439      $self->{insertion_mode} = BEFORE_HEAD_IM;
2440    
2441      ## NOTE: The "before head" insertion mode and so on.
2442    $self->_tree_construction_main;    $self->_tree_construction_main;
2443  } # _construct_tree  } # _construct_tree
2444    
2445  sub _tree_construction_initial ($) {  sub _tree_construction_initial ($) {
2446    my $self = shift;    my $self = shift;
2447    
2448      ## NOTE: "initial" insertion mode
2449    
2450    INITIAL: {    INITIAL: {
2451      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
2452        ## NOTE: Conformance checkers MAY, instead of reporting "not HTML5"        ## NOTE: Conformance checkers MAY, instead of reporting "not HTML5"
# Line 2579  sub _tree_construction_initial ($) { Line 2593  sub _tree_construction_initial ($) {
2593          !!!cp ('t13');          !!!cp ('t13');
2594        }        }
2595                
2596        ## Go to the root element phase.        ## Go to the "before html" insertion mode.
2597        !!!next-token;        !!!next-token;
2598        return;        return;
2599      } elsif ({      } elsif ({
# Line 2590  sub _tree_construction_initial ($) { Line 2604  sub _tree_construction_initial ($) {
2604        !!!cp ('t14');        !!!cp ('t14');
2605        !!!parse-error (type => 'no DOCTYPE');        !!!parse-error (type => 'no DOCTYPE');
2606        $self->{document}->manakai_compat_mode ('quirks');        $self->{document}->manakai_compat_mode ('quirks');
2607        ## Go to the root element phase        ## Go to the "before html" insertion mode.
2608        ## reprocess        ## reprocess
2609        return;        return;
2610      } elsif ($token->{type} == CHARACTER_TOKEN) {      } elsif ($token->{type} == CHARACTER_TOKEN) {
# Line 2599  sub _tree_construction_initial ($) { Line 2613  sub _tree_construction_initial ($) {
2613    
2614          unless (length $token->{data}) {          unless (length $token->{data}) {
2615            !!!cp ('t15');            !!!cp ('t15');
2616            ## Stay in the phase            ## Stay in the insertion mode.
2617            !!!next-token;            !!!next-token;
2618            redo INITIAL;            redo INITIAL;
2619          } else {          } else {
# Line 2611  sub _tree_construction_initial ($) { Line 2625  sub _tree_construction_initial ($) {
2625    
2626        !!!parse-error (type => 'no DOCTYPE');        !!!parse-error (type => 'no DOCTYPE');
2627        $self->{document}->manakai_compat_mode ('quirks');        $self->{document}->manakai_compat_mode ('quirks');
2628        ## Go to the root element phase        ## Go to the "before html" insertion mode.
2629        ## reprocess        ## reprocess
2630        return;        return;
2631      } elsif ($token->{type} == COMMENT_TOKEN) {      } elsif ($token->{type} == COMMENT_TOKEN) {
# Line 2619  sub _tree_construction_initial ($) { Line 2633  sub _tree_construction_initial ($) {
2633        my $comment = $self->{document}->create_comment ($token->{data});        my $comment = $self->{document}->create_comment ($token->{data});
2634        $self->{document}->append_child ($comment);        $self->{document}->append_child ($comment);
2635                
2636        ## Stay in the phase.        ## Stay in the insertion mode.
2637        !!!next-token;        !!!next-token;
2638        redo INITIAL;        redo INITIAL;
2639      } else {      } else {
# Line 2632  sub _tree_construction_initial ($) { Line 2646  sub _tree_construction_initial ($) {
2646    
2647  sub _tree_construction_root_element ($) {  sub _tree_construction_root_element ($) {
2648    my $self = shift;    my $self = shift;
2649    
2650      ## NOTE: "before html" insertion mode.
2651        
2652    B: {    B: {
2653        if ($token->{type} == DOCTYPE_TOKEN) {        if ($token->{type} == DOCTYPE_TOKEN) {
2654          !!!cp ('t19');          !!!cp ('t19');
2655          !!!parse-error (type => 'in html:#DOCTYPE');          !!!parse-error (type => 'in html:#DOCTYPE');
2656          ## Ignore the token          ## Ignore the token
2657          ## Stay in the phase          ## Stay in the insertion mode.
2658          !!!next-token;          !!!next-token;
2659          redo B;          redo B;
2660        } elsif ($token->{type} == COMMENT_TOKEN) {        } elsif ($token->{type} == COMMENT_TOKEN) {
2661          !!!cp ('t20');          !!!cp ('t20');
2662          my $comment = $self->{document}->create_comment ($token->{data});          my $comment = $self->{document}->create_comment ($token->{data});
2663          $self->{document}->append_child ($comment);          $self->{document}->append_child ($comment);
2664          ## Stay in the phase          ## Stay in the insertion mode.
2665          !!!next-token;          !!!next-token;
2666          redo B;          redo B;
2667        } elsif ($token->{type} == CHARACTER_TOKEN) {        } elsif ($token->{type} == CHARACTER_TOKEN) {
# Line 2654  sub _tree_construction_root_element ($) Line 2670  sub _tree_construction_root_element ($)
2670    
2671            unless (length $token->{data}) {            unless (length $token->{data}) {
2672              !!!cp ('t21');              !!!cp ('t21');
2673              ## Stay in the phase              ## Stay in the insertion mode.
2674              !!!next-token;              !!!next-token;
2675              redo B;              redo B;
2676            } else {            } else {
# Line 2668  sub _tree_construction_root_element ($) Line 2684  sub _tree_construction_root_element ($)
2684    
2685          #          #
2686        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
2687          if ($token->{tag_name} eq 'html' and          if ($token->{tag_name} eq 'html') {
2688              $token->{attributes}->{manifest}) {            my $root_element;
2689            !!!cp ('t24');            !!!create-element ($root_element, $token->{tag_name}, $token->{attributes});
2690            $self->{application_cache_selection}            $self->{document}->append_child ($root_element);
2691                 ->($token->{attributes}->{manifest}->{value});            push @{$self->{open_elements}}, [$root_element, 'html'];
2692            ## ISSUE: No relative reference resolution?  
2693              if ($token->{attributes}->{manifest}) {
2694                !!!cp ('t24');
2695                $self->{application_cache_selection}
2696                    ->($token->{attributes}->{manifest}->{value});
2697                ## ISSUE: No relative reference resolution?
2698              } else {
2699                !!!cp ('t25');
2700                $self->{application_cache_selection}->(undef);
2701              }
2702    
2703              !!!next-token;
2704              return; ## Go to the "before head" insertion mode.
2705          } else {          } else {
2706            !!!cp ('t25');            !!!cp ('t25.1');
2707            $self->{application_cache_selection}->(undef);            #
2708          }          }
   
         ## ISSUE: There is an issue in the spec  
         #  
2709        } elsif ({        } elsif ({
2710                  END_TAG_TOKEN, 1,                  END_TAG_TOKEN, 1,
2711                  END_OF_FILE_TOKEN, 1,                  END_OF_FILE_TOKEN, 1,
2712                 }->{$token->{type}}) {                 }->{$token->{type}}) {
2713          !!!cp ('t26');          !!!cp ('t26');
         $self->{application_cache_selection}->(undef);  
   
         ## ISSUE: There is an issue in the spec  
2714          #          #
2715        } else {        } else {
2716          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
2717        }        }
2718    
2719        my $root_element; !!!create-element ($root_element, 'html');      my $root_element; !!!create-element ($root_element, 'html');
2720        $self->{document}->append_child ($root_element);      $self->{document}->append_child ($root_element);
2721        push @{$self->{open_elements}}, [$root_element, 'html'];      push @{$self->{open_elements}}, [$root_element, 'html'];
2722        ## reprocess  
2723        #redo B;      $self->{application_cache_selection}->(undef);
2724        return; ## Go to the main phase.  
2725        ## NOTE: Reprocess the token.
2726        return; ## Go to the "before head" insertion mode.
2727    
2728        ## ISSUE: There is an issue in the spec
2729    } # B    } # B
2730    
2731    die "$0: _tree_construction_root_element: This should never be reached";    die "$0: _tree_construction_root_element: This should never be reached";
# Line 2739  sub _reset_insertion_mode ($) { Line 2765  sub _reset_insertion_mode ($) {
2765        ## Step 4..13        ## Step 4..13
2766        my $new_mode = {        my $new_mode = {
2767                        select => IN_SELECT_IM,                        select => IN_SELECT_IM,
2768                          ## NOTE: |option| and |optgroup| do not set
2769                          ## insertion mode to "in select" by themselves.
2770                        td => IN_CELL_IM,                        td => IN_CELL_IM,
2771                        th => IN_CELL_IM,                        th => IN_CELL_IM,
2772                        tr => IN_ROW_IM,                        tr => IN_ROW_IM,
# Line 3239  sub _tree_construction_main ($) { Line 3267  sub _tree_construction_main ($) {
3267          #          #
3268        } else {        } else {
3269          ## Generate implied end tags          ## Generate implied end tags
3270          if ({          while ({
3271               dd => 1, dt => 1, li => 1, p => 1, td => 1, th => 1, tr => 1,                  dd => 1, dt => 1, li => 1, p => 1,
3272               tbody => 1, tfoot=> 1, thead => 1,                 }->{$self->{open_elements}->[-1]->[1]}) {
             }->{$self->{open_elements}->[-1]->[1]}) {  
3273            !!!cp ('t75');            !!!cp ('t75');
3274            !!!back-token;            pop @{$self->{open_elements}};
           $token = {type => END_TAG_TOKEN, tag_name => $self->{open_elements}->[-1]->[1]};  
           redo B;  
3275          }          }
3276                    
3277          if (@{$self->{open_elements}} > 2 or          if (@{$self->{open_elements}} > 2 or
# Line 3272  sub _tree_construction_main ($) { Line 3297  sub _tree_construction_main ($) {
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) {
3299          !!!cp ('t79');          !!!cp ('t79');
         ## Turn into the main phase  
3300          !!!parse-error (type => 'after html:html');          !!!parse-error (type => 'after html:html');
3301          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
3302        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
3303          !!!cp ('t80');          !!!cp ('t80');
         ## Turn into the main phase  
3304          !!!parse-error (type => 'after html:html');          !!!parse-error (type => 'after html:html');
3305          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
3306        } else {        } else {
3307          !!!cp ('t81');          !!!cp ('t81');
3308        }        }
3309    
3310  ## ISSUE: "aa<html>" is not a parse error.        !!!cp ('t82');
3311  ## ISSUE: "<html>" in fragment is not a parse error.        !!!parse-error (type => 'not first start tag');
       unless ($token->{first_start_tag}) {  
         !!!cp ('t82');  
         !!!parse-error (type => 'not first start tag');  
       } else {  
         !!!cp ('t83');  
       }  
3312        my $top_el = $self->{open_elements}->[0]->[0];        my $top_el = $self->{open_elements}->[0]->[0];
3313        for my $attr_name (keys %{$token->{attributes}}) {        for my $attr_name (keys %{$token->{attributes}}) {
3314          unless ($top_el->has_attribute_ns (undef, $attr_name)) {          unless ($top_el->has_attribute_ns (undef, $attr_name)) {
# Line 3858  sub _tree_construction_main ($) { Line 3875  sub _tree_construction_main ($) {
3875                  } # INSCOPE                  } # INSCOPE
3876                    unless (defined $i) {                    unless (defined $i) {
3877                      !!!cp ('t157');                      !!!cp ('t157');
3878    ## TODO: this type is wrong.
3879                      !!!parse-error (type => 'unmatched end tag:caption');                      !!!parse-error (type => 'unmatched end tag:caption');
3880                      ## Ignore the token                      ## Ignore the token
3881                      !!!next-token;                      !!!next-token;
# Line 3865  sub _tree_construction_main ($) { Line 3883  sub _tree_construction_main ($) {
3883                    }                    }
3884                                    
3885                  ## generate implied end tags                  ## generate implied end tags
3886                  if ({                  while ({
3887                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
3888                       td => 1, th => 1, tr => 1,                         }->{$self->{open_elements}->[-1]->[1]}) {
                      tbody => 1, tfoot=> 1, thead => 1,  
                     }->{$self->{open_elements}->[-1]->[1]}) {  
3889                    !!!cp ('t158');                    !!!cp ('t158');
3890                    !!!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;  
3891                  }                  }
3892    
3893                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
# Line 3929  sub _tree_construction_main ($) { Line 3940  sub _tree_construction_main ($) {
3940                    }                    }
3941                                    
3942                  ## generate implied end tags                  ## generate implied end tags
3943                  if ({                  while ({
3944                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
3945                       td => ($token->{tag_name} eq 'th'),                         }->{$self->{open_elements}->[-1]->[1]}) {
                      th => ($token->{tag_name} eq 'td'),  
                      tr => 1,  
                      tbody => 1, tfoot=> 1, thead => 1,  
                     }->{$self->{open_elements}->[-1]->[1]}) {  
3946                    !!!cp ('t166');                    !!!cp ('t166');
3947                    !!!back-token;                    pop @{$self->{open_elements}};
                   $token = {type => END_TAG_TOKEN,  
                             tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                   redo B;  
3948                  }                  }
3949                    
3950                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
3951                    !!!cp ('t167');                    !!!cp ('t167');
3952                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
# Line 3994  sub _tree_construction_main ($) { Line 3998  sub _tree_construction_main ($) {
3998                    }                    }
3999                                    
4000                  ## generate implied end tags                  ## generate implied end tags
4001                  if ({                  while ({
4002                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
4003                       td => 1, th => 1, tr => 1,                         }->{$self->{open_elements}->[-1]->[1]}) {
                      tbody => 1, tfoot=> 1, thead => 1,  
                     }->{$self->{open_elements}->[-1]->[1]}) {  
4004                    !!!cp ('t174');                    !!!cp ('t174');
4005                    !!!back-token;                    pop @{$self->{open_elements}};
                   $token = {type => END_TAG_TOKEN,  
                             tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                   redo B;  
4006                  }                  }
4007                                    
4008                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
# Line 4100  sub _tree_construction_main ($) { Line 4099  sub _tree_construction_main ($) {
4099                }                }
4100                                
4101                ## generate implied end tags                ## generate implied end tags
4102                if ({                while ({
4103                     dd => 1, dt => 1, li => 1, p => 1,                        dd => 1, dt => 1, li => 1, p => 1,
4104                     td => 1, th => 1, tr => 1,                       }->{$self->{open_elements}->[-1]->[1]}) {
                    tbody => 1, tfoot=> 1, thead => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
4105                  !!!cp ('t187');                  !!!cp ('t187');
4106                  !!!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;  
4107                }                }
4108    
4109                if ($self->{open_elements}->[-1]->[1] ne 'caption') {                if ($self->{open_elements}->[-1]->[1] ne 'caption') {
# Line 4238  sub _tree_construction_main ($) { Line 4230  sub _tree_construction_main ($) {
4230                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4231                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4232                    !!!cp ('t201');                    !!!cp ('t201');
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4233                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4234                  }                  }
4235                                    
# Line 4258  sub _tree_construction_main ($) { Line 4249  sub _tree_construction_main ($) {
4249                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4250                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4251                    !!!cp ('t203');                    !!!cp ('t203');
4252                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    ## ISSUE: Can this case be reached?
4253                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4254                  }                  }
4255                                    
# Line 4282  sub _tree_construction_main ($) { Line 4273  sub _tree_construction_main ($) {
4273                  tr => 1, html => 1,                  tr => 1, html => 1,
4274                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4275                  !!!cp ('t207');                  !!!cp ('t207');
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4276                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4277                }                }
4278                                
# Line 4309  sub _tree_construction_main ($) { Line 4299  sub _tree_construction_main ($) {
4299                      $i = $_;                      $i = $_;
4300                      last INSCOPE;                      last INSCOPE;
4301                    } elsif ({                    } elsif ({
4302                              table => 1, html => 1,                              html => 1,
4303    
4304                                ## NOTE: This element does not appear here, maybe.
4305                                table => 1,
4306                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4307                      !!!cp ('t209');                      !!!cp ('t209');
4308                      last INSCOPE;                      last INSCOPE;
# Line 4317  sub _tree_construction_main ($) { Line 4310  sub _tree_construction_main ($) {
4310                  } # INSCOPE                  } # INSCOPE
4311                  unless (defined $i) {                  unless (defined $i) {
4312                   !!!cp ('t210');                   !!!cp ('t210');
4313    ## TODO: This type is wrong.
4314                   !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});                   !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});
4315                    ## Ignore the token                    ## Ignore the token
4316                    !!!next-token;                    !!!next-token;
# Line 4328  sub _tree_construction_main ($) { Line 4322  sub _tree_construction_main ($) {
4322                    tr => 1, html => 1,                    tr => 1, html => 1,
4323                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4324                    !!!cp ('t211');                    !!!cp ('t211');
4325                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    ## ISSUE: Can this case be reached?
4326                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4327                  }                  }
4328                                    
# Line 4376  sub _tree_construction_main ($) { Line 4370  sub _tree_construction_main ($) {
4370                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4371                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4372                    !!!cp ('t217');                    !!!cp ('t217');
4373                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    ## ISSUE: Can this state be reached?
4374                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4375                  }                  }
4376                                    
# Line 4399  sub _tree_construction_main ($) { Line 4393  sub _tree_construction_main ($) {
4393                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4394                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4395                    !!!cp ('t219');                    !!!cp ('t219');
4396                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    ## ISSUE: Can this state be reached?
4397                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4398                  }                  }
4399                                    
# Line 4416  sub _tree_construction_main ($) { Line 4410  sub _tree_construction_main ($) {
4410                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4411                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4412                    !!!cp ('t220');                    !!!cp ('t220');
4413                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    ## ISSUE: Can this state be reached?
4414                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4415                  }                  }
4416                                    
# Line 4449  sub _tree_construction_main ($) { Line 4443  sub _tree_construction_main ($) {
4443                    $i = $_;                    $i = $_;
4444                    last INSCOPE;                    last INSCOPE;
4445                  } elsif ({                  } elsif ({
4446                            table => 1, html => 1,                            #table => 1,
4447                              html => 1,
4448                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4449                    !!!cp ('t222');                    !!!cp ('t222');
4450                    last INSCOPE;                    last INSCOPE;
# Line 4457  sub _tree_construction_main ($) { Line 4452  sub _tree_construction_main ($) {
4452                } # INSCOPE                } # INSCOPE
4453                unless (defined $i) {                unless (defined $i) {
4454                  !!!cp ('t223');                  !!!cp ('t223');
4455    ## TODO: The following is wrong, maybe.
4456                  !!!parse-error (type => 'unmatched end tag:table');                  !!!parse-error (type => 'unmatched end tag:table');
4457                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
4458                  !!!next-token;                  !!!next-token;
# Line 4464  sub _tree_construction_main ($) { Line 4460  sub _tree_construction_main ($) {
4460                }                }
4461                                
4462                ## generate implied end tags                ## generate implied end tags
4463                if ({                while ({
4464                     dd => 1, dt => 1, li => 1, p => 1,                        dd => 1, dt => 1, li => 1, p => 1,
4465                     td => 1, th => 1, tr => 1,                       }->{$self->{open_elements}->[-1]->[1]}) {
                    tbody => 1, tfoot=> 1, thead => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
4466                  !!!cp ('t224');                  !!!cp ('t224');
4467                  !!!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;  
4468                }                }
4469    
4470                if ($self->{open_elements}->[-1]->[1] ne 'table') {                if ($self->{open_elements}->[-1]->[1] ne 'table') {
4471                  !!!cp ('t225');                  !!!cp ('t225');
4472    ## ISSUE: Can this case be reached?
4473                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4474                } else {                } else {
4475                  !!!cp ('t226');                  !!!cp ('t226');
# Line 4531  sub _tree_construction_main ($) { Line 4521  sub _tree_construction_main ($) {
4521                  tr => 1, html => 1,                  tr => 1, html => 1,
4522                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4523                  !!!cp ('t231');                  !!!cp ('t231');
4524                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  ## ISSUE: Can this state be reached?
4525                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4526                }                }
4527    
# Line 4559  sub _tree_construction_main ($) { Line 4549  sub _tree_construction_main ($) {
4549                  } # INSCOPE                  } # INSCOPE
4550                  unless (defined $i) {                  unless (defined $i) {
4551                    !!!cp ('t235');                    !!!cp ('t235');
4552    ## TODO: The following is wrong.
4553                    !!!parse-error (type => 'unmatched end tag:'.$token->{type});                    !!!parse-error (type => 'unmatched end tag:'.$token->{type});
4554                    ## Ignore the token                    ## Ignore the token
4555                    !!!next-token;                    !!!next-token;
# Line 4570  sub _tree_construction_main ($) { Line 4561  sub _tree_construction_main ($) {
4561                    tr => 1, html => 1,                    tr => 1, html => 1,
4562                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4563                    !!!cp ('t236');                    !!!cp ('t236');
4564                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  ## ISSUE: Can this state be reached?
4565                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4566                  }                  }
4567                                    
# Line 4610  sub _tree_construction_main ($) { Line 4601  sub _tree_construction_main ($) {
4601                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4602                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4603                    !!!cp ('t240');                    !!!cp ('t240');
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4604                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4605                  }                  }
4606                                    
# Line 4626  sub _tree_construction_main ($) { Line 4616  sub _tree_construction_main ($) {
4616                  ## reprocess in the "in table" insertion mode...                  ## reprocess in the "in table" insertion mode...
4617                }                }
4618    
4619                  ## NOTE: </table> in the "in table" insertion mode.
4620                  ## When you edit the code fragment below, please ensure that
4621                  ## the code for <table> in the "in table" insertion mode
4622                  ## is synced with it.
4623    
4624                ## have a table element in table scope                ## have a table element in table scope
4625                my $i;                my $i;
4626                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
# Line 4648  sub _tree_construction_main ($) { Line 4643  sub _tree_construction_main ($) {
4643                  !!!next-token;                  !!!next-token;
4644                  redo B;                  redo B;
4645                }                }
   
               ## 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');  
                 !!!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');  
               }  
4646                                    
4647                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4648                                
# Line 4732  sub _tree_construction_main ($) { Line 4707  sub _tree_construction_main ($) {
4707                    tr => 1, html => 1,                    tr => 1, html => 1,
4708                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4709                    !!!cp ('t253');                    !!!cp ('t253');
4710                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  ## ISSUE: Can this case be reached?
4711                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4712                  }                  }
4713                                    
# Line 4769  sub _tree_construction_main ($) { Line 4744  sub _tree_construction_main ($) {
4744                  tbody => 1, tfoot => 1, thead => 1, html => 1,                  tbody => 1, tfoot => 1, thead => 1, html => 1,
4745                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4746                  !!!cp ('t257');                  !!!cp ('t257');
4747                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  ## ISSUE: Can this case be reached?
4748                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4749                }                }
4750    
# Line 4848  sub _tree_construction_main ($) { Line 4823  sub _tree_construction_main ($) {
4823                #                #
4824              }              }
4825            } else {            } else {
4826              !!!cp ('t268');              die "$0: $token->{type}: Unknown token type";
             #  
4827            }            }
4828    
4829            ## As if </colgroup>            ## As if </colgroup>
# Line 4906  sub _tree_construction_main ($) { Line 4880  sub _tree_construction_main ($) {
4880                !!!next-token;                !!!next-token;
4881                redo B;                redo B;
4882              } elsif ($token->{tag_name} eq 'select') {              } elsif ($token->{tag_name} eq 'select') {
4883    ## TODO: The type below is not good - <select> is replaced by </select>
4884                !!!parse-error (type => 'not closed:select');                !!!parse-error (type => 'not closed:select');
4885                ## As if </select> instead                ## As if </select> instead
4886                ## have an element in table scope                ## have an element in table scope
# Line 5008  sub _tree_construction_main ($) { Line 4983  sub _tree_construction_main ($) {
4983                        caption => 1, table => 1, tbody => 1,                        caption => 1, table => 1, tbody => 1,
4984                        tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                        tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
4985                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4986    ## TODO: The following is wrong?
4987                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4988                                
4989                ## have an element in table scope                ## have an element in table scope
# Line 5044  sub _tree_construction_main ($) { Line 5020  sub _tree_construction_main ($) {
5020                  } elsif ({                  } elsif ({
5021                            table => 1, html => 1,                            table => 1, html => 1,
5022                           }->{$node->[1]}) {                           }->{$node->[1]}) {
5023    ## ISSUE: Can this state be reached?
5024                    !!!cp ('t296');                    !!!cp ('t296');
5025                    last INSCOPE;                    last INSCOPE;
5026                  }                  }
5027                } # INSCOPE                } # INSCOPE
5028                unless (defined $i) {                unless (defined $i) {
5029                  !!!cp ('t297');                  !!!cp ('t297');
5030    ## TODO: The following error type is correct?
5031                  !!!parse-error (type => 'unmatched end tag:select');                  !!!parse-error (type => 'unmatched end tag:select');
5032                  ## Ignore the </select> token                  ## Ignore the </select> token
5033                  !!!next-token; ## TODO: ok?                  !!!next-token; ## TODO: ok?
# Line 5093  sub _tree_construction_main ($) { Line 5071  sub _tree_construction_main ($) {
5071            !!!cp ('t301');            !!!cp ('t301');
5072            !!!parse-error (type => 'after html:#character');            !!!parse-error (type => 'after html:#character');
5073    
5074            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "after body" insertion mode.
5075          } else {          } else {
5076            !!!cp ('t302');            !!!cp ('t302');
5077          }          }
# Line 5109  sub _tree_construction_main ($) { Line 5087  sub _tree_construction_main ($) {
5087            !!!cp ('t303');            !!!cp ('t303');
5088            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
5089                        
5090            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "after body" insertion mode.
5091          } else {          } else {
5092            !!!cp ('t304');            !!!cp ('t304');
5093          }          }
# Line 5126  sub _tree_construction_main ($) { Line 5104  sub _tree_construction_main ($) {
5104            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
5105                        
5106            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
5107            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "after body" insertion mode.
5108          } else {          } else {
5109            !!!cp ('t306');            !!!cp ('t306');
5110          }          }
# Line 5180  sub _tree_construction_main ($) { Line 5158  sub _tree_construction_main ($) {
5158              !!!parse-error (type => 'after html:#character');              !!!parse-error (type => 'after html:#character');
5159    
5160              $self->{insertion_mode} = AFTER_FRAMESET_IM;              $self->{insertion_mode} = AFTER_FRAMESET_IM;
5161              ## Reprocess in the "main" phase, "after frameset"...              ## Reprocess in the "after frameset" insertion mode.
5162              !!!parse-error (type => 'after frameset:#character');              !!!parse-error (type => 'after frameset:#character');
5163            }            }
5164                        
# Line 5202  sub _tree_construction_main ($) { Line 5180  sub _tree_construction_main ($) {
5180            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
5181    
5182            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
5183            ## Process in the "main" phase, "after frameset" insertion mode...            ## Process in the "after frameset" insertion mode.
5184          } else {          } else {
5185            !!!cp ('t317');            !!!cp ('t317');
5186          }          }
# Line 5243  sub _tree_construction_main ($) { Line 5221  sub _tree_construction_main ($) {
5221            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
5222    
5223            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
5224            ## Process in the "main" phase, "after frameset" insertion mode...            ## Process in the "after frameset" insertion mode.
5225          } else {          } else {
5226            !!!cp ('t324');            !!!cp ('t324');
5227          }          }
# Line 5404  sub _tree_construction_main ($) { Line 5382  sub _tree_construction_main ($) {
5382          redo B;          redo B;
5383        } elsif ({        } elsif ({
5384                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
5385                  div => 1, dl => 1, fieldset => 1, listing => 1,                  div => 1, dl => 1, fieldset => 1,
5386                  menu => 1, ol => 1, p => 1, ul => 1,                  h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
5387                    listing => 1, menu => 1, ol => 1, p => 1, ul => 1,
5388                  pre => 1,                  pre => 1,
5389                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5390          ## has a p element in scope          ## has a p element in scope
# Line 5607  sub _tree_construction_main ($) { Line 5586  sub _tree_construction_main ($) {
5586                        
5587          !!!next-token;          !!!next-token;
5588          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;  
5589        } elsif ($token->{tag_name} eq 'a') {        } elsif ($token->{tag_name} eq 'a') {
5590          AFE: for my $i (reverse 0..$#$active_formatting_elements) {          AFE: for my $i (reverse 0..$#$active_formatting_elements) {
5591            my $node = $active_formatting_elements->[$i];            my $node = $active_formatting_elements->[$i];
# Line 5754  sub _tree_construction_main ($) { Line 5686  sub _tree_construction_main ($) {
5686          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5687                        
5688          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5689    
5690            ## TODO: associate with $self->{form_element} if defined
5691    
5692          push @$active_formatting_elements, ['#marker', ''];          push @$active_formatting_elements, ['#marker', ''];
5693    
5694          !!!next-token;          !!!next-token;
# Line 5953  sub _tree_construction_main ($) { Line 5888  sub _tree_construction_main ($) {
5888          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5889                    
5890          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5891    
5892            ## TODO: associate with $self->{form_element} if defined
5893                    
5894          $self->{insertion_mode} = IN_SELECT_IM;          $self->{insertion_mode} = IN_SELECT_IM;
5895          !!!next-token;          !!!next-token;
# Line 6029  sub _tree_construction_main ($) { Line 5966  sub _tree_construction_main ($) {
5966                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
5967                  div => 1, dl => 1, fieldset => 1, listing => 1,                  div => 1, dl => 1, fieldset => 1, listing => 1,
5968                  menu => 1, ol => 1, pre => 1, ul => 1,                  menu => 1, ol => 1, pre => 1, ul => 1,
                 p => 1,  
5969                  dd => 1, dt => 1, li => 1,                  dd => 1, dt => 1, li => 1,
5970                  button => 1, marquee => 1, object => 1,                  button => 1, marquee => 1, object => 1,
5971                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
# Line 6038  sub _tree_construction_main ($) { Line 5974  sub _tree_construction_main ($) {
5974          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5975            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
5976            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;  
             }  
               
5977              !!!cp ('t410');              !!!cp ('t410');
5978              $i = $_;              $i = $_;
5979              last INSCOPE unless $token->{tag_name} eq 'p';              last INSCOPE;
5980            } elsif ({            } elsif ({
5981                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5982                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
# Line 6065  sub _tree_construction_main ($) { Line 5985  sub _tree_construction_main ($) {
5985              last INSCOPE;              last INSCOPE;
5986            }            }
5987          } # INSCOPE          } # INSCOPE
5988            
5989          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          unless (defined $i) { # has an element in scope
5990            if (defined $i) {            !!!cp ('t413');
5991              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5992            } else {
5993              ## Step 1. generate implied end tags
5994              while ({
5995                      dd => ($token->{tag_name} ne 'dd'),
5996                      dt => ($token->{tag_name} ne 'dt'),
5997                      li => ($token->{tag_name} ne 'li'),
5998                      p => 1,
5999                     }->{$self->{open_elements}->[-1]->[1]}) {
6000                !!!cp ('t409');
6001                pop @{$self->{open_elements}};
6002              }
6003    
6004              ## Step 2.
6005              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6006              !!!cp ('t412');              !!!cp ('t412');
6007              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6008            } else {            } else {
6009              !!!cp ('t413');              !!!cp ('t414');
             !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
6010            }            }
6011          }  
6012                      ## Step 3.
         if (defined $i) {  
           !!!cp ('t414');  
6013            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
6014          } elsif ($token->{tag_name} eq 'p') {  
6015            !!!cp ('t415');            ## Step 4.
6016            ## As if <p>, then reprocess the current token            $clear_up_to_marker->()
6017            my $el;                if {
6018            !!!create-element ($el, 'p');                  button => 1, marquee => 1, object => 1,
6019            $insert->($el);                }->{$token->{tag_name}};
         } else {  
           !!!cp ('t416');  
6020          }          }
         $clear_up_to_marker->()  
           if {  
             button => 1, marquee => 1, object => 1,  
           }->{$token->{tag_name}};  
6021          !!!next-token;          !!!next-token;
6022          redo B;          redo B;
6023        } elsif ($token->{tag_name} eq 'form') {        } elsif ($token->{tag_name} eq 'form') {
6024            undef $self->{form_element};
6025    
6026          ## has an element in scope          ## has an element in scope
6027            my $i;
6028          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6029            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
6030            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,  
                  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;  
             }  
               
6031              !!!cp ('t418');              !!!cp ('t418');
6032                $i = $_;
6033              last INSCOPE;              last INSCOPE;
6034            } elsif ({            } elsif ({
6035                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 6122  sub _tree_construction_main ($) { Line 6039  sub _tree_construction_main ($) {
6039              last INSCOPE;              last INSCOPE;
6040            }            }
6041          } # INSCOPE          } # INSCOPE
6042            
6043          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 {  
6044            !!!cp ('t421');            !!!cp ('t421');
6045            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6046            } else {
6047              ## Step 1. generate implied end tags
6048              while ({
6049                      dd => 1, dt => 1, li => 1, p => 1,
6050                     }->{$self->{open_elements}->[-1]->[1]}) {
6051                !!!cp ('t417');
6052                pop @{$self->{open_elements}};
6053              }
6054              
6055              ## Step 2.
6056              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6057                !!!cp ('t417.1');
6058                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6059              } else {
6060                !!!cp ('t420');
6061              }  
6062              
6063              ## Step 3.
6064              splice @{$self->{open_elements}}, $i;
6065          }          }
6066    
         undef $self->{form_element};  
6067          !!!next-token;          !!!next-token;
6068          redo B;          redo B;
6069        } elsif ({        } elsif ({
# Line 6144  sub _tree_construction_main ($) { Line 6076  sub _tree_construction_main ($) {
6076            if ({            if ({
6077                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
6078                }->{$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;  
             }  
   
6079              !!!cp ('t423');              !!!cp ('t423');
6080              $i = $_;              $i = $_;
6081              last INSCOPE;              last INSCOPE;
# Line 6168  sub _tree_construction_main ($) { Line 6087  sub _tree_construction_main ($) {
6087              last INSCOPE;              last INSCOPE;
6088            }            }
6089          } # INSCOPE          } # INSCOPE
6090            
6091          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          unless (defined $i) { # has an element in scope
6092            !!!cp ('t425');            !!!cp ('t425.1');
6093            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6094          } else {          } else {
6095            !!!cp ('t426');            ## Step 1. generate implied end tags
6096              while ({
6097                      dd => 1, dt => 1, li => 1, p => 1,
6098                     }->{$self->{open_elements}->[-1]->[1]}) {
6099                !!!cp ('t422');
6100                pop @{$self->{open_elements}};
6101              }
6102              
6103              ## Step 2.
6104              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6105                !!!cp ('t425');
6106                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6107              } else {
6108                !!!cp ('t426');
6109              }
6110    
6111              ## Step 3.
6112              splice @{$self->{open_elements}}, $i;
6113          }          }
6114                    
6115          splice @{$self->{open_elements}}, $i if defined $i;          !!!next-token;
6116            redo B;
6117          } elsif ($token->{tag_name} eq 'p') {
6118            ## has an element in scope
6119            my $i;
6120            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6121              my $node = $self->{open_elements}->[$_];
6122              if ($node->[1] eq $token->{tag_name}) {
6123                !!!cp ('t410.1');
6124                $i = $_;
6125                last INSCOPE;
6126              } elsif ({
6127                        table => 1, caption => 1, td => 1, th => 1,
6128                        button => 1, marquee => 1, object => 1, html => 1,
6129                       }->{$node->[1]}) {
6130                !!!cp ('t411.1');
6131                last INSCOPE;
6132              }
6133            } # INSCOPE
6134    
6135            if (defined $i) {
6136              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6137                !!!cp ('t412.1');
6138                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6139              } else {
6140                !!!cp ('t414.1');
6141              }
6142    
6143              splice @{$self->{open_elements}}, $i;
6144            } else {
6145              !!!cp ('t413.1');
6146              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6147    
6148              !!!cp ('t415.1');
6149              ## As if <p>, then reprocess the current token
6150              my $el;
6151              !!!create-element ($el, 'p');
6152              $insert->($el);
6153              ## NOTE: Not inserted into |$self->{open_elements}|.
6154            }
6155    
6156          !!!next-token;          !!!next-token;
6157          redo B;          redo B;
6158        } elsif ({        } elsif ({
# Line 6232  sub _tree_construction_main ($) { Line 6208  sub _tree_construction_main ($) {
6208            if ($node->[1] eq $token->{tag_name}) {            if ($node->[1] eq $token->{tag_name}) {
6209              ## Step 1              ## Step 1
6210              ## generate implied end tags              ## generate implied end tags
6211              if ({              while ({
6212                   dd => 1, dt => 1, li => 1, p => 1,                      dd => 1, dt => 1, li => 1, p => 1,
6213                   td => 1, th => 1, tr => 1,                     }->{$self->{open_elements}->[-1]->[1]}) {
                  tbody => 1, tfoot => 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
6214                !!!cp ('t430');                !!!cp ('t430');
6215                !!!back-token;                ## ISSUE: Can this case be reached?
6216                $token = {type => END_TAG_TOKEN,                pop @{$self->{open_elements}};
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               redo B;  
6217              }              }
6218                    
6219              ## Step 2              ## Step 2
# Line 6287  sub _tree_construction_main ($) { Line 6259  sub _tree_construction_main ($) {
6259      redo B;      redo B;
6260    } # B    } # B
6261    
   ## NOTE: The "trailing end" phase in HTML5 is split into  
   ## two insertion modes: "after html body" and "after html frameset".  
   ## NOTE: States in the main stage is preserved while  
   ## the parser stays in the trailing end phase. # MUST  
   
6262    ## Stop parsing # MUST    ## Stop parsing # MUST
6263        
6264    ## TODO: script stuffs    ## TODO: script stuffs
# Line 6333  sub set_inner_html ($$$) { Line 6300  sub set_inner_html ($$$) {
6300      my $p = $class->new;      my $p = $class->new;
6301      $p->{document} = $doc;      $p->{document} = $doc;
6302    
6303      ## Step 9 # MUST      ## Step 8 # MUST
6304      my $i = 0;      my $i = 0;
6305      my $line = 1;      my $line = 1;
6306      my $column = 0;      my $column = 0;
# Line 6400  sub set_inner_html ($$$) { Line 6367  sub set_inner_html ($$$) {
6367    
6368      $p->{inner_html_node} = [$node, $node_ln];      $p->{inner_html_node} = [$node, $node_ln];
6369    
6370      ## Step 4      ## Step 3
6371      my $root = $doc->create_element_ns      my $root = $doc->create_element_ns
6372        ('http://www.w3.org/1999/xhtml', [undef, 'html']);        ('http://www.w3.org/1999/xhtml', [undef, 'html']);
6373    
6374      ## Step 5 # MUST      ## Step 4 # MUST
6375      $doc->append_child ($root);      $doc->append_child ($root);
6376    
6377      ## Step 6 # MUST      ## Step 5 # MUST
6378      push @{$p->{open_elements}}, [$root, 'html'];      push @{$p->{open_elements}}, [$root, 'html'];
6379    
6380      undef $p->{head_element};      undef $p->{head_element};
6381    
6382      ## Step 7 # MUST      ## Step 6 # MUST
6383      $p->_reset_insertion_mode;      $p->_reset_insertion_mode;
6384    
6385      ## Step 8 # MUST      ## Step 7 # MUST
6386      my $anode = $node;      my $anode = $node;
6387      AN: while (defined $anode) {      AN: while (defined $anode) {
6388        if ($anode->node_type == 1) {        if ($anode->node_type == 1) {
# Line 6431  sub set_inner_html ($$$) { Line 6398  sub set_inner_html ($$$) {
6398        $anode = $anode->parent_node;        $anode = $anode->parent_node;
6399      } # AN      } # AN
6400            
6401      ## Step 3 # MUST      ## Step 9 # MUST
     ## Step 10 # MUST  
6402      {      {
6403        my $self = $p;        my $self = $p;
6404        !!!next-token;        !!!next-token;
6405      }      }
6406      $p->_tree_construction_main;      $p->_tree_construction_main;
6407    
6408      ## Step 11 # MUST      ## Step 10 # MUST
6409      my @cn = @{$node->child_nodes};      my @cn = @{$node->child_nodes};
6410      for (@cn) {      for (@cn) {
6411        $node->remove_child ($_);        $node->remove_child ($_);
6412      }      }
6413      ## ISSUE: mutation events? read-only?      ## ISSUE: mutation events? read-only?
6414    
6415      ## Step 12 # MUST      ## Step 11 # MUST
6416      @cn = @{$root->child_nodes};      @cn = @{$root->child_nodes};
6417      for (@cn) {      for (@cn) {
6418        $this_doc->adopt_node ($_);        $this_doc->adopt_node ($_);

Legend:
Removed from v.1.82  
changed lines
  Added in v.1.94

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24