/[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.98 by wakaba, Sun Mar 9 03:23:43 2008 UTC revision 1.113 by wakaba, Sun Mar 16 07:07:59 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 177  sub parse_string ($$$;$) { Line 177  sub parse_string ($$$;$) {
177        if defined $self->{input_encoding};        if defined $self->{input_encoding};
178    
179    my $i = 0;    my $i = 0;
180    my $line = 1;    $self->{line_prev} = $self->{line} = 1;
181    my $column = 0;    $self->{column_prev} = $self->{column} = 0;
182    $self->{set_next_char} = sub {    $self->{set_next_char} = sub {
183      my $self = shift;      my $self = shift;
184    
# Line 187  sub parse_string ($$$;$) { Line 187  sub parse_string ($$$;$) {
187    
188      $self->{next_char} = -1 and return if $i >= length $$s;      $self->{next_char} = -1 and return if $i >= length $$s;
189      $self->{next_char} = ord substr $$s, $i++, 1;      $self->{next_char} = ord substr $$s, $i++, 1;
190      $column++;  
191        ($self->{line_prev}, $self->{column_prev})
192            = ($self->{line}, $self->{column});
193        $self->{column}++;
194            
195      if ($self->{next_char} == 0x000A) { # LF      if ($self->{next_char} == 0x000A) { # LF
196        $line++;        $self->{line}++;
197        $column = 0;        $self->{column} = 0;
198      } elsif ($self->{next_char} == 0x000D) { # CR      } elsif ($self->{next_char} == 0x000D) { # CR
199        $i++ if substr ($$s, $i, 1) eq "\x0A";        $i++ if substr ($$s, $i, 1) eq "\x0A";
200        $self->{next_char} = 0x000A; # LF # MUST        $self->{next_char} = 0x000A; # LF # MUST
201        $line++;        $self->{line}++;
202        $column = 0;        $self->{column} = 0;
203      } elsif ($self->{next_char} > 0x10FFFF) {      } elsif ($self->{next_char} > 0x10FFFF) {
204        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
205      } elsif ($self->{next_char} == 0x0000) { # NULL      } elsif ($self->{next_char} == 0x0000) { # NULL
# Line 209  sub parse_string ($$$;$) { Line 212  sub parse_string ($$$;$) {
212    
213    my $onerror = $_[2] || sub {    my $onerror = $_[2] || sub {
214      my (%opt) = @_;      my (%opt) = @_;
215      warn "Parse error ($opt{type}) at line $opt{line} column $opt{column}\n";      my $line = $opt{token} ? $opt{token}->{line} : $opt{line};
216        my $column = $opt{token} ? $opt{token}->{column} : $opt{column};
217        warn "Parse error ($opt{type}) at line $line column $column\n";
218    };    };
219    $self->{parse_error} = sub {    $self->{parse_error} = sub {
220      $onerror->(@_, line => $line, column => $column);      $onerror->(line => $self->{line}, column => $self->{column}, @_);
221    };    };
222    
223    $self->_initialize_tokenizer;    $self->_initialize_tokenizer;
# Line 220  sub parse_string ($$$;$) { Line 225  sub parse_string ($$$;$) {
225    $self->_construct_tree;    $self->_construct_tree;
226    $self->_terminate_tree_constructor;    $self->_terminate_tree_constructor;
227    
228      delete $self->{parse_error}; # remove loop
229    
230    return $self->{document};    return $self->{document};
231  } # parse_string  } # parse_string
232    
# Line 303  sub TABLE_IMS ()      { 0b1000000 } Line 310  sub TABLE_IMS ()      { 0b1000000 }
310  sub ROW_IMS ()        { 0b10000000 }  sub ROW_IMS ()        { 0b10000000 }
311  sub BODY_AFTER_IMS () { 0b100000000 }  sub BODY_AFTER_IMS () { 0b100000000 }
312  sub FRAME_IMS ()      { 0b1000000000 }  sub FRAME_IMS ()      { 0b1000000000 }
313    sub SELECT_IMS ()     { 0b10000000000 }
314    
315  ## NOTE: "initial" and "before html" insertion modes have no constants.  ## NOTE: "initial" and "before html" insertion modes have no constants.
316    
# Line 325  sub IN_TABLE_IM () { TABLE_IMS } Line 333  sub IN_TABLE_IM () { TABLE_IMS }
333  sub AFTER_BODY_IM () { BODY_AFTER_IMS }  sub AFTER_BODY_IM () { BODY_AFTER_IMS }
334  sub IN_FRAMESET_IM () { FRAME_IMS | 0b01 }  sub IN_FRAMESET_IM () { FRAME_IMS | 0b01 }
335  sub AFTER_FRAMESET_IM () { FRAME_IMS | 0b10 }  sub AFTER_FRAMESET_IM () { FRAME_IMS | 0b10 }
336  sub IN_SELECT_IM () { 0b01 }  sub IN_SELECT_IM () { SELECT_IMS | 0b01 }
337    sub IN_SELECT_IN_TABLE_IM () { SELECT_IMS | 0b10 }
338  sub IN_COLUMN_GROUP_IM () { 0b10 }  sub IN_COLUMN_GROUP_IM () { 0b10 }
339    
340  ## Implementations MUST act as if state machine in the spec  ## Implementations MUST act as if state machine in the spec
# Line 447  sub _get_next_token ($) { Line 456  sub _get_next_token ($) {
456          #          #
457        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
458          !!!cp (11);          !!!cp (11);
459          !!!emit ({type => END_OF_FILE_TOKEN});          !!!emit ({type => END_OF_FILE_TOKEN,
460                      line => $self->{line}, column => $self->{column}});
461          last A; ## TODO: ok?          last A; ## TODO: ok?
462        } else {        } else {
463          !!!cp (12);          !!!cp (12);
464        }        }
465        # Anything else        # Anything else
466        my $token = {type => CHARACTER_TOKEN,        my $token = {type => CHARACTER_TOKEN,
467                     data => chr $self->{next_char}};                     data => chr $self->{next_char},
468                       line => $self->{line}, column => $self->{column}};
469        ## Stay in the data state        ## Stay in the data state
470        !!!next-input-character;        !!!next-input-character;
471    
# Line 463  sub _get_next_token ($) { Line 474  sub _get_next_token ($) {
474        redo A;        redo A;
475      } elsif ($self->{state} == ENTITY_DATA_STATE) {      } elsif ($self->{state} == ENTITY_DATA_STATE) {
476        ## (cannot happen in CDATA state)        ## (cannot happen in CDATA state)
477    
478          my ($l, $c) = ($self->{line_prev}, $self->{column_prev});
479                
480        my $token = $self->_tokenize_attempt_to_consume_an_entity (0, -1);        my $token = $self->_tokenize_attempt_to_consume_an_entity (0, -1);
481    
# Line 471  sub _get_next_token ($) { Line 484  sub _get_next_token ($) {
484    
485        unless (defined $token) {        unless (defined $token) {
486          !!!cp (13);          !!!cp (13);
487          !!!emit ({type => CHARACTER_TOKEN, data => '&'});          !!!emit ({type => CHARACTER_TOKEN, data => '&',
488                      line => $l, column => $c});
489        } else {        } else {
490          !!!cp (14);          !!!cp (14);
491          !!!emit ($token);          !!!emit ($token);
# Line 490  sub _get_next_token ($) { Line 504  sub _get_next_token ($) {
504            ## reconsume            ## reconsume
505            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
506    
507            !!!emit ({type => CHARACTER_TOKEN, data => '<'});            !!!emit ({type => CHARACTER_TOKEN, data => '<',
508                        line => $self->{line_prev},
509                        column => $self->{column_prev}});
510    
511            redo A;            redo A;
512          }          }
# Line 510  sub _get_next_token ($) { Line 526  sub _get_next_token ($) {
526            !!!cp (19);            !!!cp (19);
527            $self->{current_token}            $self->{current_token}
528              = {type => START_TAG_TOKEN,              = {type => START_TAG_TOKEN,
529                 tag_name => chr ($self->{next_char} + 0x0020)};                 tag_name => chr ($self->{next_char} + 0x0020),
530                   line => $self->{line_prev},
531                   column => $self->{column_prev}};
532            $self->{state} = TAG_NAME_STATE;            $self->{state} = TAG_NAME_STATE;
533            !!!next-input-character;            !!!next-input-character;
534            redo A;            redo A;
# Line 518  sub _get_next_token ($) { Line 536  sub _get_next_token ($) {
536                   $self->{next_char} <= 0x007A) { # a..z                   $self->{next_char} <= 0x007A) { # a..z
537            !!!cp (20);            !!!cp (20);
538            $self->{current_token} = {type => START_TAG_TOKEN,            $self->{current_token} = {type => START_TAG_TOKEN,
539                              tag_name => chr ($self->{next_char})};                                      tag_name => chr ($self->{next_char}),
540                                        line => $self->{line_prev},
541                                        column => $self->{column_prev}};
542            $self->{state} = TAG_NAME_STATE;            $self->{state} = TAG_NAME_STATE;
543            !!!next-input-character;            !!!next-input-character;
544            redo A;            redo A;
# Line 528  sub _get_next_token ($) { Line 548  sub _get_next_token ($) {
548            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
549            !!!next-input-character;            !!!next-input-character;
550    
551            !!!emit ({type => CHARACTER_TOKEN, data => '<>'});            !!!emit ({type => CHARACTER_TOKEN, data => '<>',
552                        line => $self->{line_prev},
553                        column => $self->{column_prev}});
554    
555            redo A;            redo A;
556          } elsif ($self->{next_char} == 0x003F) { # ?          } elsif ($self->{next_char} == 0x003F) { # ?
557            !!!cp (22);            !!!cp (22);
558            !!!parse-error (type => 'pio');            !!!parse-error (type => 'pio');
559            $self->{state} = BOGUS_COMMENT_STATE;            $self->{state} = BOGUS_COMMENT_STATE;
560              $self->{current_token} = {type => COMMENT_TOKEN, data => '',
561                                        line => $self->{line_prev},
562                                        column => $self->{column_prev}};
563            ## $self->{next_char} is intentionally left as is            ## $self->{next_char} is intentionally left as is
564            redo A;            redo A;
565          } else {          } else {
# Line 543  sub _get_next_token ($) { Line 568  sub _get_next_token ($) {
568            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
569            ## reconsume            ## reconsume
570    
571            !!!emit ({type => CHARACTER_TOKEN, data => '<'});            !!!emit ({type => CHARACTER_TOKEN, data => '<',
572                        line => $self->{line_prev},
573                        column => $self->{column_prev}});
574    
575            redo A;            redo A;
576          }          }
# Line 551  sub _get_next_token ($) { Line 578  sub _get_next_token ($) {
578          die "$0: $self->{content_model} in tag open";          die "$0: $self->{content_model} in tag open";
579        }        }
580      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {
581          my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"
582        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
583          if (defined $self->{last_emitted_start_tag_name}) {          if (defined $self->{last_emitted_start_tag_name}) {
584    
585            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>
586            my @next_char;            my @next_char;
587            TAGNAME: for (my $i = 0; $i < length $self->{last_emitted_start_tag_name}; $i++) {            TAGNAME: for (my $i = 0; $i < length $self->{last_emitted_start_tag_name}; $i++) {
# Line 569  sub _get_next_token ($) { Line 598  sub _get_next_token ($) {
598                !!!back-next-input-character (@next_char);                !!!back-next-input-character (@next_char);
599                $self->{state} = DATA_STATE;                $self->{state} = DATA_STATE;
600    
601                !!!emit ({type => CHARACTER_TOKEN, data => '</'});                !!!emit ({type => CHARACTER_TOKEN, data => '</',
602                            line => $l, column => $c});
603        
604                redo A;                redo A;
605              }              }
# Line 588  sub _get_next_token ($) { Line 618  sub _get_next_token ($) {
618              $self->{next_char} = shift @next_char; # reconsume              $self->{next_char} = shift @next_char; # reconsume
619              !!!back-next-input-character (@next_char);              !!!back-next-input-character (@next_char);
620              $self->{state} = DATA_STATE;              $self->{state} = DATA_STATE;
621              !!!emit ({type => CHARACTER_TOKEN, data => '</'});              !!!emit ({type => CHARACTER_TOKEN, data => '</',
622                          line => $l, column => $c});
623              redo A;              redo A;
624            } else {            } else {
625              !!!cp (27);              !!!cp (27);
# Line 601  sub _get_next_token ($) { Line 632  sub _get_next_token ($) {
632            !!!cp (28);            !!!cp (28);
633            # next-input-character is already done            # next-input-character is already done
634            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
635            !!!emit ({type => CHARACTER_TOKEN, data => '</'});            !!!emit ({type => CHARACTER_TOKEN, data => '</',
636                        line => $l, column => $c});
637            redo A;            redo A;
638          }          }
639        }        }
# Line 609  sub _get_next_token ($) { Line 641  sub _get_next_token ($) {
641        if (0x0041 <= $self->{next_char} and        if (0x0041 <= $self->{next_char} and
642            $self->{next_char} <= 0x005A) { # A..Z            $self->{next_char} <= 0x005A) { # A..Z
643          !!!cp (29);          !!!cp (29);
644          $self->{current_token} = {type => END_TAG_TOKEN,          $self->{current_token}
645                            tag_name => chr ($self->{next_char} + 0x0020)};              = {type => END_TAG_TOKEN,
646                   tag_name => chr ($self->{next_char} + 0x0020),
647                   line => $l, column => $c};
648          $self->{state} = TAG_NAME_STATE;          $self->{state} = TAG_NAME_STATE;
649          !!!next-input-character;          !!!next-input-character;
650          redo A;          redo A;
# Line 618  sub _get_next_token ($) { Line 652  sub _get_next_token ($) {
652                 $self->{next_char} <= 0x007A) { # a..z                 $self->{next_char} <= 0x007A) { # a..z
653          !!!cp (30);          !!!cp (30);
654          $self->{current_token} = {type => END_TAG_TOKEN,          $self->{current_token} = {type => END_TAG_TOKEN,
655                            tag_name => chr ($self->{next_char})};                                    tag_name => chr ($self->{next_char}),
656                                      line => $l, column => $c};
657          $self->{state} = TAG_NAME_STATE;          $self->{state} = TAG_NAME_STATE;
658          !!!next-input-character;          !!!next-input-character;
659          redo A;          redo A;
# Line 634  sub _get_next_token ($) { Line 669  sub _get_next_token ($) {
669          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
670          # reconsume          # reconsume
671    
672          !!!emit ({type => CHARACTER_TOKEN, data => '</'});          !!!emit ({type => CHARACTER_TOKEN, data => '</',
673                      line => $l, column => $c});
674    
675          redo A;          redo A;
676        } else {        } else {
677          !!!cp (33);          !!!cp (33);
678          !!!parse-error (type => 'bogus end tag');          !!!parse-error (type => 'bogus end tag');
679          $self->{state} = BOGUS_COMMENT_STATE;          $self->{state} = BOGUS_COMMENT_STATE;
680            $self->{current_token} = {type => COMMENT_TOKEN, data => '',
681                                      line => $self->{line_prev}, # "<" of "</"
682                                      column => $self->{column_prev} - 1};
683          ## $self->{next_char} is intentionally left as is          ## $self->{next_char} is intentionally left as is
684          redo A;          redo A;
685        }        }
# Line 1377  sub _get_next_token ($) { Line 1416  sub _get_next_token ($) {
1416      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {
1417        ## (only happen if PCDATA state)        ## (only happen if PCDATA state)
1418                
1419        my $token = {type => COMMENT_TOKEN, data => ''};        ## NOTE: Set by the previous state
1420          #my $token = {type => COMMENT_TOKEN, data => ''};
1421    
1422        BC: {        BC: {
1423          if ($self->{next_char} == 0x003E) { # >          if ($self->{next_char} == 0x003E) { # >
# Line 1385  sub _get_next_token ($) { Line 1425  sub _get_next_token ($) {
1425            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1426            !!!next-input-character;            !!!next-input-character;
1427    
1428            !!!emit ($token);            !!!emit ($self->{current_token}); # comment
1429    
1430            redo A;            redo A;
1431          } elsif ($self->{next_char} == -1) {          } elsif ($self->{next_char} == -1) {
# Line 1393  sub _get_next_token ($) { Line 1433  sub _get_next_token ($) {
1433            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1434            ## reconsume            ## reconsume
1435    
1436            !!!emit ($token);            !!!emit ($self->{current_token}); # comment
1437    
1438            redo A;            redo A;
1439          } else {          } else {
1440            !!!cp (126);            !!!cp (126);
1441            $token->{data} .= chr ($self->{next_char});            $self->{current_token}->{data} .= chr ($self->{next_char}); # comment
1442            !!!next-input-character;            !!!next-input-character;
1443            redo BC;            redo BC;
1444          }          }
# Line 1408  sub _get_next_token ($) { Line 1448  sub _get_next_token ($) {
1448      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {
1449        ## (only happen if PCDATA state)        ## (only happen if PCDATA state)
1450    
1451          my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1);
1452    
1453        my @next_char;        my @next_char;
1454        push @next_char, $self->{next_char};        push @next_char, $self->{next_char};
1455                
# Line 1416  sub _get_next_token ($) { Line 1458  sub _get_next_token ($) {
1458          push @next_char, $self->{next_char};          push @next_char, $self->{next_char};
1459          if ($self->{next_char} == 0x002D) { # -          if ($self->{next_char} == 0x002D) { # -
1460            !!!cp (127);            !!!cp (127);
1461            $self->{current_token} = {type => COMMENT_TOKEN, data => ''};            $self->{current_token} = {type => COMMENT_TOKEN, data => '',
1462                                        line => $l, column => $c};
1463            $self->{state} = COMMENT_START_STATE;            $self->{state} = COMMENT_START_STATE;
1464            !!!next-input-character;            !!!next-input-character;
1465            redo A;            redo A;
# Line 1452  sub _get_next_token ($) { Line 1495  sub _get_next_token ($) {
1495                      !!!cp (129);                      !!!cp (129);
1496                      ## TODO: What a stupid code this is!                      ## TODO: What a stupid code this is!
1497                      $self->{state} = DOCTYPE_STATE;                      $self->{state} = DOCTYPE_STATE;
1498                        $self->{current_token} = {type => DOCTYPE_TOKEN,
1499                                                  quirks => 1,
1500                                                  line => $l, column => $c};
1501                      !!!next-input-character;                      !!!next-input-character;
1502                      redo A;                      redo A;
1503                    } else {                    } else {
# Line 1480  sub _get_next_token ($) { Line 1526  sub _get_next_token ($) {
1526        $self->{next_char} = shift @next_char;        $self->{next_char} = shift @next_char;
1527        !!!back-next-input-character (@next_char);        !!!back-next-input-character (@next_char);
1528        $self->{state} = BOGUS_COMMENT_STATE;        $self->{state} = BOGUS_COMMENT_STATE;
1529          $self->{current_token} = {type => COMMENT_TOKEN, data => '',
1530                                    line => $l, column => $c};
1531        redo A;        redo A;
1532                
1533        ## ISSUE: typos in spec: chacacters, is is a parse error        ## ISSUE: typos in spec: chacacters, is is a parse error
# Line 1658  sub _get_next_token ($) { Line 1706  sub _get_next_token ($) {
1706          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1707          !!!next-input-character;          !!!next-input-character;
1708    
1709          !!!emit ({type => DOCTYPE_TOKEN, quirks => 1});          !!!emit ($self->{current_token}); # DOCTYPE (quirks)
1710    
1711          redo A;          redo A;
1712        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
# Line 1667  sub _get_next_token ($) { Line 1715  sub _get_next_token ($) {
1715          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1716          ## reconsume          ## reconsume
1717    
1718          !!!emit ({type => DOCTYPE_TOKEN, quirks => 1});          !!!emit ($self->{current_token}); # DOCTYPE (quirks)
1719    
1720          redo A;          redo A;
1721        } else {        } else {
1722          !!!cp (160);          !!!cp (160);
1723          $self->{current_token}          $self->{current_token}->{name} = chr $self->{next_char};
1724              = {type => DOCTYPE_TOKEN,          delete $self->{current_token}->{quirks};
                name => chr ($self->{next_char}),  
                #quirks => 0,  
               };  
1725  ## ISSUE: "Set the token's name name to the" in the spec  ## ISSUE: "Set the token's name name to the" in the spec
1726          $self->{state} = DOCTYPE_NAME_STATE;          $self->{state} = DOCTYPE_NAME_STATE;
1727          !!!next-input-character;          !!!next-input-character;
# Line 2203  sub _get_next_token ($) { Line 2248  sub _get_next_token ($) {
2248  sub _tokenize_attempt_to_consume_an_entity ($$$) {  sub _tokenize_attempt_to_consume_an_entity ($$$) {
2249    my ($self, $in_attr, $additional) = @_;    my ($self, $in_attr, $additional) = @_;
2250    
2251      my ($l, $c) = ($self->{line_prev}, $self->{column_prev});
2252    
2253    if ({    if ({
2254         0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,         0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,
2255         0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR         0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR
# Line 2243  sub _tokenize_attempt_to_consume_an_enti Line 2290  sub _tokenize_attempt_to_consume_an_enti
2290            redo X;            redo X;
2291          } elsif (not defined $code) { # no hexadecimal digit          } elsif (not defined $code) { # no hexadecimal digit
2292            !!!cp (1005);            !!!cp (1005);
2293            !!!parse-error (type => 'bare hcro');            !!!parse-error (type => 'bare hcro', line => $l, column => $c);
2294            !!!back-next-input-character ($x_char, $self->{next_char});            !!!back-next-input-character ($x_char, $self->{next_char});
2295            $self->{next_char} = 0x0023; # #            $self->{next_char} = 0x0023; # #
2296            return undef;            return undef;
# Line 2252  sub _tokenize_attempt_to_consume_an_enti Line 2299  sub _tokenize_attempt_to_consume_an_enti
2299            !!!next-input-character;            !!!next-input-character;
2300          } else {          } else {
2301            !!!cp (1007);            !!!cp (1007);
2302            !!!parse-error (type => 'no refc');            !!!parse-error (type => 'no refc', line => $l, column => $c);
2303          }          }
2304    
2305          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2306            !!!cp (1008);            !!!cp (1008);
2307            !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code);            !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);
2308            $code = 0xFFFD;            $code = 0xFFFD;
2309          } elsif ($code > 0x10FFFF) {          } elsif ($code > 0x10FFFF) {
2310            !!!cp (1009);            !!!cp (1009);
2311            !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code);            !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);
2312            $code = 0xFFFD;            $code = 0xFFFD;
2313          } elsif ($code == 0x000D) {          } elsif ($code == 0x000D) {
2314            !!!cp (1010);            !!!cp (1010);
2315            !!!parse-error (type => 'CR character reference');            !!!parse-error (type => 'CR character reference', line => $l, column => $c);
2316            $code = 0x000A;            $code = 0x000A;
2317          } elsif (0x80 <= $code and $code <= 0x9F) {          } elsif (0x80 <= $code and $code <= 0x9F) {
2318            !!!cp (1011);            !!!cp (1011);
2319            !!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code);            !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);
2320            $code = $c1_entity_char->{$code};            $code = $c1_entity_char->{$code};
2321          }          }
2322    
2323          return {type => CHARACTER_TOKEN, data => chr $code,          return {type => CHARACTER_TOKEN, data => chr $code,
2324                  has_reference => 1};                  has_reference => 1, line => $l, column => $c};
2325        } # X        } # X
2326      } elsif (0x0030 <= $self->{next_char} and      } elsif (0x0030 <= $self->{next_char} and
2327               $self->{next_char} <= 0x0039) { # 0..9               $self->{next_char} <= 0x0039) { # 0..9
# Line 2295  sub _tokenize_attempt_to_consume_an_enti Line 2342  sub _tokenize_attempt_to_consume_an_enti
2342          !!!next-input-character;          !!!next-input-character;
2343        } else {        } else {
2344          !!!cp (1014);          !!!cp (1014);
2345          !!!parse-error (type => 'no refc');          !!!parse-error (type => 'no refc', line => $l, column => $c);
2346        }        }
2347    
2348        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2349          !!!cp (1015);          !!!cp (1015);
2350          !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code);          !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);
2351          $code = 0xFFFD;          $code = 0xFFFD;
2352        } elsif ($code > 0x10FFFF) {        } elsif ($code > 0x10FFFF) {
2353          !!!cp (1016);          !!!cp (1016);
2354          !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code);          !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);
2355          $code = 0xFFFD;          $code = 0xFFFD;
2356        } elsif ($code == 0x000D) {        } elsif ($code == 0x000D) {
2357          !!!cp (1017);          !!!cp (1017);
2358          !!!parse-error (type => 'CR character reference');          !!!parse-error (type => 'CR character reference', line => $l, column => $c);
2359          $code = 0x000A;          $code = 0x000A;
2360        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
2361          !!!cp (1018);          !!!cp (1018);
2362          !!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code);          !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);
2363          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
2364        }        }
2365                
2366        return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1};        return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1,
2367                  line => $l, column => $c};
2368      } else {      } else {
2369        !!!cp (1019);        !!!cp (1019);
2370        !!!parse-error (type => 'bare nero');        !!!parse-error (type => 'bare nero', line => $l, column => $c);
2371        !!!back-next-input-character ($self->{next_char});        !!!back-next-input-character ($self->{next_char});
2372        $self->{next_char} = 0x0023; # #        $self->{next_char} = 0x0023; # #
2373        return undef;        return undef;
# Line 2369  sub _tokenize_attempt_to_consume_an_enti Line 2417  sub _tokenize_attempt_to_consume_an_enti
2417            
2418      if ($match > 0) {      if ($match > 0) {
2419        !!!cp (1023);        !!!cp (1023);
2420        return {type => CHARACTER_TOKEN, data => $value, has_reference => 1};        return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,
2421                  line => $l, column => $c};
2422      } elsif ($match < 0) {      } elsif ($match < 0) {
2423        !!!parse-error (type => 'no refc');        !!!parse-error (type => 'no refc', line => $l, column => $c);
2424        if ($in_attr and $match < -1) {        if ($in_attr and $match < -1) {
2425          !!!cp (1024);          !!!cp (1024);
2426          return {type => CHARACTER_TOKEN, data => '&'.$entity_name};          return {type => CHARACTER_TOKEN, data => '&'.$entity_name,
2427                    line => $l, column => $c};
2428        } else {        } else {
2429          !!!cp (1025);          !!!cp (1025);
2430          return {type => CHARACTER_TOKEN, data => $value, has_reference => 1};          return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,
2431                    line => $l, column => $c};
2432        }        }
2433      } else {      } else {
2434        !!!cp (1026);        !!!cp (1026);
2435        !!!parse-error (type => 'bare ero');        !!!parse-error (type => 'bare ero', line => $l, column => $c);
2436        ## NOTE: "No characters are consumed" in the spec.        ## NOTE: "No characters are consumed" in the spec.
2437        return {type => CHARACTER_TOKEN, data => '&'.$value};        return {type => CHARACTER_TOKEN, data => '&'.$value,
2438                  line => $l, column => $c};
2439      }      }
2440    } else {    } else {
2441      !!!cp (1027);      !!!cp (1027);
2442      ## no characters are consumed      ## no characters are consumed
2443      !!!parse-error (type => 'bare ero');      !!!parse-error (type => 'bare ero', line => $l, column => $c);
2444      return undef;      return undef;
2445    }    }
2446  } # _tokenize_attempt_to_consume_an_entity  } # _tokenize_attempt_to_consume_an_entity
# Line 2459  sub _tree_construction_initial ($) { Line 2511  sub _tree_construction_initial ($) {
2511            defined $token->{public_identifier} or            defined $token->{public_identifier} or
2512            defined $token->{system_identifier}) {            defined $token->{system_identifier}) {
2513          !!!cp ('t1');          !!!cp ('t1');
2514          !!!parse-error (type => 'not HTML5');          !!!parse-error (type => 'not HTML5', token => $token);
2515        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
2516          !!!cp ('t2');          !!!cp ('t2');
2517          ## ISSUE: ASCII case-insensitive? (in fact it does not matter)          ## ISSUE: ASCII case-insensitive? (in fact it does not matter)
2518          !!!parse-error (type => 'not HTML5');          !!!parse-error (type => 'not HTML5', token => $token);
2519        } else {        } else {
2520          !!!cp ('t3');          !!!cp ('t3');
2521        }        }
# Line 2602  sub _tree_construction_initial ($) { Line 2654  sub _tree_construction_initial ($) {
2654                END_OF_FILE_TOKEN, 1,                END_OF_FILE_TOKEN, 1,
2655               }->{$token->{type}}) {               }->{$token->{type}}) {
2656        !!!cp ('t14');        !!!cp ('t14');
2657        !!!parse-error (type => 'no DOCTYPE');        !!!parse-error (type => 'no DOCTYPE', token => $token);
2658        $self->{document}->manakai_compat_mode ('quirks');        $self->{document}->manakai_compat_mode ('quirks');
2659        ## Go to the "before html" insertion mode.        ## Go to the "before html" insertion mode.
2660        ## reprocess        ## reprocess
# Line 2623  sub _tree_construction_initial ($) { Line 2675  sub _tree_construction_initial ($) {
2675          !!!cp ('t17');          !!!cp ('t17');
2676        }        }
2677    
2678        !!!parse-error (type => 'no DOCTYPE');        !!!parse-error (type => 'no DOCTYPE', token => $token);
2679        $self->{document}->manakai_compat_mode ('quirks');        $self->{document}->manakai_compat_mode ('quirks');
2680        ## Go to the "before html" insertion mode.        ## Go to the "before html" insertion mode.
2681        ## reprocess        ## reprocess
# Line 2652  sub _tree_construction_root_element ($) Line 2704  sub _tree_construction_root_element ($)
2704    B: {    B: {
2705        if ($token->{type} == DOCTYPE_TOKEN) {        if ($token->{type} == DOCTYPE_TOKEN) {
2706          !!!cp ('t19');          !!!cp ('t19');
2707          !!!parse-error (type => 'in html:#DOCTYPE');          !!!parse-error (type => 'in html:#DOCTYPE', token => $token);
2708          ## Ignore the token          ## Ignore the token
2709          ## Stay in the insertion mode.          ## Stay in the insertion mode.
2710          !!!next-token;          !!!next-token;
# Line 2948  sub _tree_construction_main ($) { Line 3000  sub _tree_construction_main ($) {
3000        ## NOTE: An end-of-file token.        ## NOTE: An end-of-file token.
3001        if ($content_model_flag == CDATA_CONTENT_MODEL) {        if ($content_model_flag == CDATA_CONTENT_MODEL) {
3002          !!!cp ('t43');          !!!cp ('t43');
3003          !!!parse-error (type => 'in CDATA:#'.$token->{type});          !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);
3004        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
3005          !!!cp ('t44');          !!!cp ('t44');
3006          !!!parse-error (type => 'in RCDATA:#'.$token->{type});          !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);
3007        } else {        } else {
3008          die "$0: $content_model_flag in parse_rcdata";          die "$0: $content_model_flag in parse_rcdata";
3009        }        }
# Line 2987  sub _tree_construction_main ($) { Line 3039  sub _tree_construction_main ($) {
3039        ## Ignore the token        ## Ignore the token
3040      } else {      } else {
3041        !!!cp ('t48');        !!!cp ('t48');
3042        !!!parse-error (type => 'in CDATA:#'.$token->{type});        !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);
3043        ## ISSUE: And ignore?        ## ISSUE: And ignore?
3044        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
3045      }      }
# Line 3010  sub _tree_construction_main ($) { Line 3062  sub _tree_construction_main ($) {
3062      !!!next-token;      !!!next-token;
3063    }; # $script_start_tag    }; # $script_start_tag
3064    
3065      ## NOTE: $open_tables->[-1]->[0] is the "current table" element node.
3066      ## NOTE: $open_tables->[-1]->[1] is the "tainted" flag.
3067      my $open_tables = [[$self->{open_elements}->[0]->[0]]];
3068    
3069    my $formatting_end_tag = sub {    my $formatting_end_tag = sub {
3070      my $tag_name = shift;      my $end_tag_token = shift;
3071        my $tag_name = $end_tag_token->{tag_name};
3072    
3073        ## NOTE: The adoption agency algorithm (AAA).
3074    
3075      FET: {      FET: {
3076        ## Step 1        ## Step 1
# Line 3030  sub _tree_construction_main ($) { Line 3089  sub _tree_construction_main ($) {
3089        } # AFE        } # AFE
3090        unless (defined $formatting_element) {        unless (defined $formatting_element) {
3091          !!!cp ('t53');          !!!cp ('t53');
3092          !!!parse-error (type => 'unmatched end tag:'.$tag_name);          !!!parse-error (type => 'unmatched end tag:'.$tag_name, token => $end_tag_token);
3093          ## Ignore the token          ## Ignore the token
3094          !!!next-token;          !!!next-token;
3095          return;          return;
# Line 3047  sub _tree_construction_main ($) { Line 3106  sub _tree_construction_main ($) {
3106              last INSCOPE;              last INSCOPE;
3107            } else { # in open elements but not in scope            } else { # in open elements but not in scope
3108              !!!cp ('t55');              !!!cp ('t55');
3109              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},
3110                                token => $end_tag_token);
3111              ## Ignore the token              ## Ignore the token
3112              !!!next-token;              !!!next-token;
3113              return;              return;
3114            }            }
3115          } elsif ({          } elsif ({
3116                    table => 1, caption => 1, td => 1, th => 1,                    applet => 1, table => 1, caption => 1, td => 1, th => 1,
3117                    button => 1, marquee => 1, object => 1, html => 1,                    button => 1, marquee => 1, object => 1, html => 1,
3118                   }->{$node->[1]}) {                   }->{$node->[1]}) {
3119            !!!cp ('t56');            !!!cp ('t56');
# Line 3062  sub _tree_construction_main ($) { Line 3122  sub _tree_construction_main ($) {
3122        } # INSCOPE        } # INSCOPE
3123        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
3124          !!!cp ('t57');          !!!cp ('t57');
3125          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},
3126                            token => $end_tag_token);
3127          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
3128          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
3129          return;          return;
3130        }        }
3131        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
3132          !!!cp ('t58');          !!!cp ('t58');
3133          !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);          !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1],
3134                            token => $end_tag_token);
3135        }        }
3136                
3137        ## Step 2        ## Step 2
# Line 3080  sub _tree_construction_main ($) { Line 3142  sub _tree_construction_main ($) {
3142          if (not $formatting_category->{$node->[1]} and          if (not $formatting_category->{$node->[1]} and
3143              #not $phrasing_category->{$node->[1]} and              #not $phrasing_category->{$node->[1]} and
3144              ($special_category->{$node->[1]} or              ($special_category->{$node->[1]} or
3145               $scoping_category->{$node->[1]})) {               $scoping_category->{$node->[1]})) { ## Scoping is redundant, maybe
3146            !!!cp ('t59');            !!!cp ('t59');
3147            $furthest_block = $node;            $furthest_block = $node;
3148            $furthest_block_i_in_open = $_;            $furthest_block_i_in_open = $_;
# Line 3166  sub _tree_construction_main ($) { Line 3228  sub _tree_construction_main ($) {
3228        } # S7          } # S7  
3229                
3230        ## Step 8        ## Step 8
3231        $common_ancestor_node->[0]->append_child ($last_node->[0]);        if ({
3232               table => 1, tbody => 1, tfoot => 1, thead => 1, tr => 1,
3233              }->{$common_ancestor_node->[1]}) {
3234            my $foster_parent_element;
3235            my $next_sibling;
3236                             OE: for (reverse 0..$#{$self->{open_elements}}) {
3237                               if ($self->{open_elements}->[$_]->[1] eq 'table') {
3238                                 my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
3239                                 if (defined $parent and $parent->node_type == 1) {
3240                                   !!!cp ('t65.1');
3241                                   $foster_parent_element = $parent;
3242                                   $next_sibling = $self->{open_elements}->[$_]->[0];
3243                                 } else {
3244                                   !!!cp ('t65.2');
3245                                   $foster_parent_element
3246                                     = $self->{open_elements}->[$_ - 1]->[0];
3247                                 }
3248                                 last OE;
3249                               }
3250                             } # OE
3251                             $foster_parent_element = $self->{open_elements}->[0]->[0]
3252                               unless defined $foster_parent_element;
3253            $foster_parent_element->insert_before ($last_node->[0], $next_sibling);
3254            $open_tables->[-1]->[1] = 1; # tainted
3255          } else {
3256            !!!cp ('t65.3');
3257            $common_ancestor_node->[0]->append_child ($last_node->[0]);
3258          }
3259                
3260        ## Step 9        ## Step 9
3261        my $clone = [$formatting_element->[0]->clone_node (0),        my $clone = [$formatting_element->[0]->clone_node (0),
# Line 3212  sub _tree_construction_main ($) { Line 3301  sub _tree_construction_main ($) {
3301      } # FET      } # FET
3302    }; # $formatting_end_tag    }; # $formatting_end_tag
3303    
   ## NOTE: $open_tables->[-1]->[0] is the "current table".  
   ## NOTE: $open_tables->[-1]->[1] is the "tainted" flag.  
   my $open_tables = [[$self->{open_elements}->[0]->[0]]];  
   
3304    $insert = my $insert_to_current = sub {    $insert = my $insert_to_current = sub {
3305      $self->{open_elements}->[-1]->[0]->append_child ($_[0]);      $self->{open_elements}->[-1]->[0]->append_child ($_[0]);
3306    }; # $insert_to_current    }; # $insert_to_current
# Line 3257  sub _tree_construction_main ($) { Line 3342  sub _tree_construction_main ($) {
3342    B: {    B: {
3343      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
3344        !!!cp ('t73');        !!!cp ('t73');
3345        !!!parse-error (type => 'DOCTYPE in the middle');        !!!parse-error (type => 'DOCTYPE in the middle', token => $token);
3346        ## Ignore the token        ## Ignore the token
3347        ## Stay in the phase        ## Stay in the phase
3348        !!!next-token;        !!!next-token;
3349        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  
         while ({  
                 dd => 1, dt => 1, li => 1, p => 1,  
                }->{$self->{open_elements}->[-1]->[1]}) {  
           !!!cp ('t75');  
           pop @{$self->{open_elements}};  
         }  
           
         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;  
3350      } elsif ($token->{type} == START_TAG_TOKEN and      } elsif ($token->{type} == START_TAG_TOKEN and
3351               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
3352        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
3353          !!!cp ('t79');          !!!cp ('t79');
3354          !!!parse-error (type => 'after html:html');          !!!parse-error (type => 'after html:html', token => $token);
3355          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
3356        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
3357          !!!cp ('t80');          !!!cp ('t80');
3358          !!!parse-error (type => 'after html:html');          !!!parse-error (type => 'after html:html', token => $token);
3359          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
3360        } else {        } else {
3361          !!!cp ('t81');          !!!cp ('t81');
3362        }        }
3363    
3364        !!!cp ('t82');        !!!cp ('t82');
3365        !!!parse-error (type => 'not first start tag');        !!!parse-error (type => 'not first start tag', token => $token);
3366        my $top_el = $self->{open_elements}->[0]->[0];        my $top_el = $self->{open_elements}->[0]->[0];
3367        for my $attr_name (keys %{$token->{attributes}}) {        for my $attr_name (keys %{$token->{attributes}}) {
3368          unless ($top_el->has_attribute_ns (undef, $attr_name)) {          unless ($top_el->has_attribute_ns (undef, $attr_name)) {
# Line 3338  sub _tree_construction_main ($) { Line 3391  sub _tree_construction_main ($) {
3391      } elsif ($self->{insertion_mode} & HEAD_IMS) {      } elsif ($self->{insertion_mode} & HEAD_IMS) {
3392        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
3393          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3394            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            unless ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3395                !!!cp ('t88.2');
3396                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
3397              } else {
3398                !!!cp ('t88.1');
3399                ## Ignore the token.
3400                !!!next-token;
3401                redo B;
3402              }
3403            unless (length $token->{data}) {            unless (length $token->{data}) {
3404              !!!cp ('t88');              !!!cp ('t88');
3405              !!!next-token;              !!!next-token;
# Line 3361  sub _tree_construction_main ($) { Line 3422  sub _tree_construction_main ($) {
3422            !!!cp ('t90');            !!!cp ('t90');
3423            ## As if </noscript>            ## As if </noscript>
3424            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
3425            !!!parse-error (type => 'in noscript:#character');            !!!parse-error (type => 'in noscript:#character', token => $token);
3426                        
3427            ## Reprocess in the "in head" insertion mode...            ## Reprocess in the "in head" insertion mode...
3428            ## As if </head>            ## As if </head>
# Line 3398  sub _tree_construction_main ($) { Line 3459  sub _tree_construction_main ($) {
3459                  #                  #
3460                } else {                } else {
3461                  !!!cp ('t95');                  !!!cp ('t95');
3462                  !!!parse-error (type => 'in head:head'); # or in head noscript                  !!!parse-error (type => 'in head:head', token => $token); # or in head noscript
3463                  ## Ignore the token                  ## Ignore the token
3464                  !!!next-token;                  !!!next-token;
3465                  redo B;                  redo B;
# Line 3421  sub _tree_construction_main ($) { Line 3482  sub _tree_construction_main ($) {
3482                  !!!cp ('t98');                  !!!cp ('t98');
3483                  ## As if </noscript>                  ## As if </noscript>
3484                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3485                  !!!parse-error (type => 'in noscript:base');                  !!!parse-error (type => 'in noscript:base', token => $token);
3486                                
3487                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3488                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
# Line 3432  sub _tree_construction_main ($) { Line 3493  sub _tree_construction_main ($) {
3493                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3494                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3495                  !!!cp ('t100');                  !!!cp ('t100');
3496                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);
3497                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3498                } else {                } else {
3499                  !!!cp ('t101');                  !!!cp ('t101');
3500                }                }
3501                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3502                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3503                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3504                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3505                !!!next-token;                !!!next-token;
3506                redo B;                redo B;
# Line 3447  sub _tree_construction_main ($) { Line 3508  sub _tree_construction_main ($) {
3508                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3509                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3510                  !!!cp ('t102');                  !!!cp ('t102');
3511                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);
3512                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3513                } else {                } else {
3514                  !!!cp ('t103');                  !!!cp ('t103');
3515                }                }
3516                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3517                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3518                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3519                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3520                !!!next-token;                !!!next-token;
3521                redo B;                redo B;
# Line 3462  sub _tree_construction_main ($) { Line 3523  sub _tree_construction_main ($) {
3523                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3524                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3525                  !!!cp ('t104');                  !!!cp ('t104');
3526                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);
3527                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3528                } else {                } else {
3529                  !!!cp ('t105');                  !!!cp ('t105');
# Line 3515  sub _tree_construction_main ($) { Line 3576  sub _tree_construction_main ($) {
3576                  }                  }
3577                }                }
3578    
3579                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3580                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3581                !!!next-token;                !!!next-token;
3582                redo B;                redo B;
# Line 3524  sub _tree_construction_main ($) { Line 3585  sub _tree_construction_main ($) {
3585                  !!!cp ('t111');                  !!!cp ('t111');
3586                  ## As if </noscript>                  ## As if </noscript>
3587                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3588                  !!!parse-error (type => 'in noscript:title');                  !!!parse-error (type => 'in noscript:title', token => $token);
3589                                
3590                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3591                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3592                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
3593                  !!!cp ('t112');                  !!!cp ('t112');
3594                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);
3595                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3596                } else {                } else {
3597                  !!!cp ('t113');                  !!!cp ('t113');
# Line 3540  sub _tree_construction_main ($) { Line 3601  sub _tree_construction_main ($) {
3601                my $parent = defined $self->{head_element} ? $self->{head_element}                my $parent = defined $self->{head_element} ? $self->{head_element}
3602                    : $self->{open_elements}->[-1]->[0];                    : $self->{open_elements}->[-1]->[0];
3603                $parse_rcdata->(RCDATA_CONTENT_MODEL);                $parse_rcdata->(RCDATA_CONTENT_MODEL);
3604                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3605                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3606                redo B;                redo B;
3607              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style') {
# Line 3549  sub _tree_construction_main ($) { Line 3610  sub _tree_construction_main ($) {
3610                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3611                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3612                  !!!cp ('t114');                  !!!cp ('t114');
3613                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);
3614                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3615                } else {                } else {
3616                  !!!cp ('t115');                  !!!cp ('t115');
3617                }                }
3618                $parse_rcdata->(CDATA_CONTENT_MODEL);                $parse_rcdata->(CDATA_CONTENT_MODEL);
3619                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3620                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3621                redo B;                redo B;
3622              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
# Line 3568  sub _tree_construction_main ($) { Line 3629  sub _tree_construction_main ($) {
3629                  redo B;                  redo B;
3630                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3631                  !!!cp ('t117');                  !!!cp ('t117');
3632                  !!!parse-error (type => 'in noscript:noscript');                  !!!parse-error (type => 'in noscript:noscript', token => $token);
3633                  ## Ignore the token                  ## Ignore the token
3634                  !!!next-token;                  !!!next-token;
3635                  redo B;                  redo B;
# Line 3581  sub _tree_construction_main ($) { Line 3642  sub _tree_construction_main ($) {
3642                  !!!cp ('t119');                  !!!cp ('t119');
3643                  ## As if </noscript>                  ## As if </noscript>
3644                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3645                  !!!parse-error (type => 'in noscript:script');                  !!!parse-error (type => 'in noscript:script', token => $token);
3646                                
3647                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3648                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3649                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
3650                  !!!cp ('t120');                  !!!cp ('t120');
3651                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);
3652                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3653                } else {                } else {
3654                  !!!cp ('t121');                  !!!cp ('t121');
3655                }                }
3656    
3657                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3658                $script_start_tag->($insert_to_current);                $script_start_tag->();
3659                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3660                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3661                redo B;                redo B;
3662              } elsif ($token->{tag_name} eq 'body' or              } elsif ($token->{tag_name} eq 'body' or
# Line 3604  sub _tree_construction_main ($) { Line 3665  sub _tree_construction_main ($) {
3665                  !!!cp ('t122');                  !!!cp ('t122');
3666                  ## As if </noscript>                  ## As if </noscript>
3667                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3668                  !!!parse-error (type => 'in noscript:'.$token->{tag_name});                  !!!parse-error (type => 'in noscript:'.$token->{tag_name}, token => $token);
3669                                    
3670                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3671                  ## As if </head>                  ## As if </head>
# Line 3642  sub _tree_construction_main ($) { Line 3703  sub _tree_construction_main ($) {
3703                !!!cp ('t129');                !!!cp ('t129');
3704                ## As if </noscript>                ## As if </noscript>
3705                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3706                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);
3707                                
3708                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
3709                ## As if </head>                ## As if </head>
# Line 3683  sub _tree_construction_main ($) { Line 3744  sub _tree_construction_main ($) {
3744                  !!!cp ('t133');                  !!!cp ('t133');
3745                  ## As if </noscript>                  ## As if </noscript>
3746                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3747                  !!!parse-error (type => 'in noscript:/head');                  !!!parse-error (type => 'in noscript:/head', token => $token);
3748                                    
3749                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3750                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 3709  sub _tree_construction_main ($) { Line 3770  sub _tree_construction_main ($) {
3770                  redo B;                  redo B;
3771                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3772                  !!!cp ('t137');                  !!!cp ('t137');
3773                  !!!parse-error (type => 'unmatched end tag:noscript');                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);
3774                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
3775                  !!!next-token;                  !!!next-token;
3776                  redo B;                  redo B;
# Line 3731  sub _tree_construction_main ($) { Line 3792  sub _tree_construction_main ($) {
3792                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3793                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3794                  !!!cp ('t140');                  !!!cp ('t140');
3795                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
3796                  ## Ignore the token                  ## Ignore the token
3797                  !!!next-token;                  !!!next-token;
3798                  redo B;                  redo B;
# Line 3763  sub _tree_construction_main ($) { Line 3824  sub _tree_construction_main ($) {
3824                  #                  #
3825                } else {                } else {
3826                  !!!cp ('t145');                  !!!cp ('t145');
3827                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
3828                  ## Ignore the token                  ## Ignore the token
3829                  !!!next-token;                  !!!next-token;
3830                  redo B;                  redo B;
# Line 3774  sub _tree_construction_main ($) { Line 3835  sub _tree_construction_main ($) {
3835                !!!cp ('t146');                !!!cp ('t146');
3836                ## As if </noscript>                ## As if </noscript>
3837                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3838                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);
3839                                
3840                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
3841                ## As if </head>                ## As if </head>
# Line 3790  sub _tree_construction_main ($) { Line 3851  sub _tree_construction_main ($) {
3851              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3852  ## ISSUE: This case cannot be reached?  ## ISSUE: This case cannot be reached?
3853                !!!cp ('t148');                !!!cp ('t148');
3854                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
3855                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
3856                !!!next-token;                !!!next-token;
3857                redo B;                redo B;
# Line 3804  sub _tree_construction_main ($) { Line 3865  sub _tree_construction_main ($) {
3865              $self->{insertion_mode} = IN_BODY_IM;              $self->{insertion_mode} = IN_BODY_IM;
3866              ## reprocess              ## reprocess
3867              redo B;              redo B;
3868            } else {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
3869              die "$0: $token->{type}: Unknown token type";          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3870            }            !!!cp ('t149.1');
3871    
3872              ## NOTE: As if <head>
3873              !!!create-element ($self->{head_element}, 'head');
3874              $self->{open_elements}->[-1]->[0]->append_child
3875                  ($self->{head_element});
3876              #push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3877              #$self->{insertion_mode} = IN_HEAD_IM;
3878              ## NOTE: Reprocess.
3879    
3880              ## NOTE: As if </head>
3881              #pop @{$self->{open_elements}};
3882              #$self->{insertion_mode} = IN_AFTER_HEAD_IM;
3883              ## NOTE: Reprocess.
3884              
3885              #
3886            } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3887              !!!cp ('t149.2');
3888    
3889              ## NOTE: As if </head>
3890              pop @{$self->{open_elements}};
3891              #$self->{insertion_mode} = IN_AFTER_HEAD_IM;
3892              ## NOTE: Reprocess.
3893    
3894              #
3895            } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3896              !!!cp ('t149.3');
3897    
3898              !!!parse-error (type => 'in noscript:#eof', token => $token);
3899    
3900              ## As if </noscript>
3901              pop @{$self->{open_elements}};
3902              #$self->{insertion_mode} = IN_HEAD_IM;
3903              ## NOTE: Reprocess.
3904    
3905              ## NOTE: As if </head>
3906              pop @{$self->{open_elements}};
3907              #$self->{insertion_mode} = IN_AFTER_HEAD_IM;
3908              ## NOTE: Reprocess.
3909    
3910              #
3911            } else {
3912              !!!cp ('t149.4');
3913              #
3914            }
3915    
3916            ## NOTE: As if <body>
3917            !!!insert-element ('body');
3918            $self->{insertion_mode} = IN_BODY_IM;
3919            ## NOTE: Reprocess.
3920            redo B;
3921          } else {
3922            die "$0: $token->{type}: Unknown token type";
3923          }
3924    
3925            ## ISSUE: An issue in the spec.            ## ISSUE: An issue in the spec.
3926      } elsif ($self->{insertion_mode} & BODY_IMS) {      } elsif ($self->{insertion_mode} & BODY_IMS) {
# Line 3826  sub _tree_construction_main ($) { Line 3940  sub _tree_construction_main ($) {
3940                  }->{$token->{tag_name}}) {                  }->{$token->{tag_name}}) {
3941                if ($self->{insertion_mode} == IN_CELL_IM) {                if ($self->{insertion_mode} == IN_CELL_IM) {
3942                  ## have an element in table scope                  ## have an element in table scope
3943                  my $tn;                  for (reverse 0..$#{$self->{open_elements}}) {
                 INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
3944                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
3945                    if ($node->[1] eq 'td' or $node->[1] eq 'th') {                    if ($node->[1] eq 'td' or $node->[1] eq 'th') {
3946                      !!!cp ('t151');                      !!!cp ('t151');
3947                      $tn = $node->[1];  
3948                      last INSCOPE;                      ## Close the cell
3949                        !!!back-token; # <?>
3950                        $token = {type => END_TAG_TOKEN, tag_name => $node->[1]};
3951                        redo B;
3952                    } elsif ({                    } elsif ({
3953                              table => 1, html => 1,                              table => 1, html => 1,
3954                             }->{$node->[1]}) {                             }->{$node->[1]}) {
3955                      !!!cp ('t152');                      !!!cp ('t152');
3956                      last INSCOPE;                      ## ISSUE: This case can never be reached, maybe.
3957                    }                      last;
                 } # INSCOPE  
                   unless (defined $tn) {  
                     !!!cp ('t153');  
 ## TODO: This error type is wrong.  
                     !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
                     ## Ignore the token  
                     !!!next-token;  
                     redo B;  
3958                    }                    }
3959                                    }
3960                  !!!cp ('t154');  
3961                  ## Close the cell                  !!!cp ('t153');
3962                  !!!back-token; # <?>                  !!!parse-error (type => 'start tag not allowed',
3963                  $token = {type => END_TAG_TOKEN, tag_name => $tn};                      value => $token->{tag_name}, token => $token);
3964                    ## Ignore the token
3965                    !!!next-token;
3966                  redo B;                  redo B;
3967                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
3968                  !!!parse-error (type => 'not closed:caption');                  !!!parse-error (type => 'not closed:caption', token => $token);
3969                                    
3970                  ## As if </caption>                  ## NOTE: As if </caption>.
3971                  ## have a table element in table scope                  ## have a table element in table scope
3972                  my $i;                  my $i;
3973                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: {
3974                    my $node = $self->{open_elements}->[$_];                    for (reverse 0..$#{$self->{open_elements}}) {
3975                    if ($node->[1] eq 'caption') {                      my $node = $self->{open_elements}->[$_];
3976                      !!!cp ('t155');                      if ($node->[1] eq 'caption') {
3977                      $i = $_;                        !!!cp ('t155');
3978                      last INSCOPE;                        $i = $_;
3979                    } elsif ({                        last INSCOPE;
3980                              table => 1, html => 1,                      } elsif ({
3981                             }->{$node->[1]}) {                                table => 1, html => 1,
3982                      !!!cp ('t156');                               }->{$node->[1]}) {
3983                      last INSCOPE;                        !!!cp ('t156');
3984                          last;
3985                        }
3986                    }                    }
3987    
3988                      !!!cp ('t157');
3989                      !!!parse-error (type => 'start tag not allowed',
3990                                      value => $token->{tag_name}, token => $token);
3991                      ## Ignore the token
3992                      !!!next-token;
3993                      redo B;
3994                  } # INSCOPE                  } # INSCOPE
                   unless (defined $i) {  
                     !!!cp ('t157');  
 ## TODO: this type is wrong.  
                     !!!parse-error (type => 'unmatched end tag:caption');  
                     ## Ignore the token  
                     !!!next-token;  
                     redo B;  
                   }  
3995                                    
3996                  ## generate implied end tags                  ## generate implied end tags
3997                  while ({                  while ({
# Line 3892  sub _tree_construction_main ($) { Line 4003  sub _tree_construction_main ($) {
4003    
4004                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
4005                    !!!cp ('t159');                    !!!cp ('t159');
4006                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token);
4007                  } else {                  } else {
4008                    !!!cp ('t160');                    !!!cp ('t160');
4009                  }                  }
# Line 3933  sub _tree_construction_main ($) { Line 4044  sub _tree_construction_main ($) {
4044                  } # INSCOPE                  } # INSCOPE
4045                    unless (defined $i) {                    unless (defined $i) {
4046                      !!!cp ('t165');                      !!!cp ('t165');
4047                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4048                      ## Ignore the token                      ## Ignore the token
4049                      !!!next-token;                      !!!next-token;
4050                      redo B;                      redo B;
# Line 3949  sub _tree_construction_main ($) { Line 4060  sub _tree_construction_main ($) {
4060    
4061                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
4062                    !!!cp ('t167');                    !!!cp ('t167');
4063                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token);
4064                  } else {                  } else {
4065                    !!!cp ('t168');                    !!!cp ('t168');
4066                  }                  }
# Line 3964  sub _tree_construction_main ($) { Line 4075  sub _tree_construction_main ($) {
4075                  redo B;                  redo B;
4076                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4077                  !!!cp ('t169');                  !!!cp ('t169');
4078                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4079                  ## Ignore the token                  ## Ignore the token
4080                  !!!next-token;                  !!!next-token;
4081                  redo B;                  redo B;
# Line 3976  sub _tree_construction_main ($) { Line 4087  sub _tree_construction_main ($) {
4087                if ($self->{insertion_mode} == IN_CAPTION_IM) {                if ($self->{insertion_mode} == IN_CAPTION_IM) {
4088                  ## have a table element in table scope                  ## have a table element in table scope
4089                  my $i;                  my $i;
4090                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: {
4091                    my $node = $self->{open_elements}->[$_];                    for (reverse 0..$#{$self->{open_elements}}) {
4092                    if ($node->[1] eq $token->{tag_name}) {                      my $node = $self->{open_elements}->[$_];
4093                      !!!cp ('t171');                      if ($node->[1] eq $token->{tag_name}) {
4094                      $i = $_;                        !!!cp ('t171');
4095                      last INSCOPE;                        $i = $_;
4096                    } elsif ({                        last INSCOPE;
4097                              table => 1, html => 1,                      } elsif ({
4098                             }->{$node->[1]}) {                                table => 1, html => 1,
4099                      !!!cp ('t172');                               }->{$node->[1]}) {
4100                      last INSCOPE;                        !!!cp ('t172');
4101                          last;
4102                        }
4103                    }                    }
4104    
4105                      !!!cp ('t173');
4106                      !!!parse-error (type => 'unmatched end tag',
4107                                      value => $token->{tag_name}, token => $token);
4108                      ## Ignore the token
4109                      !!!next-token;
4110                      redo B;
4111                  } # INSCOPE                  } # INSCOPE
                   unless (defined $i) {  
                     !!!cp ('t173');  
                     !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
                     ## Ignore the token  
                     !!!next-token;  
                     redo B;  
                   }  
4112                                    
4113                  ## generate implied end tags                  ## generate implied end tags
4114                  while ({                  while ({
# Line 4007  sub _tree_construction_main ($) { Line 4120  sub _tree_construction_main ($) {
4120                                    
4121                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
4122                    !!!cp ('t175');                    !!!cp ('t175');
4123                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token);
4124                  } else {                  } else {
4125                    !!!cp ('t176');                    !!!cp ('t176');
4126                  }                  }
# Line 4022  sub _tree_construction_main ($) { Line 4135  sub _tree_construction_main ($) {
4135                  redo B;                  redo B;
4136                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
4137                  !!!cp ('t177');                  !!!cp ('t177');
4138                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4139                  ## Ignore the token                  ## Ignore the token
4140                  !!!next-token;                  !!!next-token;
4141                  redo B;                  redo B;
# Line 4038  sub _tree_construction_main ($) { Line 4151  sub _tree_construction_main ($) {
4151                ## have an element in table scope                ## have an element in table scope
4152                my $i;                my $i;
4153                my $tn;                my $tn;
4154                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: {
4155                  my $node = $self->{open_elements}->[$_];                  for (reverse 0..$#{$self->{open_elements}}) {
4156                  if ($node->[1] eq $token->{tag_name}) {                    my $node = $self->{open_elements}->[$_];
4157                    !!!cp ('t179');                    if ($node->[1] eq $token->{tag_name}) {
4158                    $i = $_;                      !!!cp ('t179');
4159                    last INSCOPE;                      $i = $_;
4160                  } elsif ($node->[1] eq 'td' or $node->[1] eq 'th') {  
4161                    !!!cp ('t180');                      ## Close the cell
4162                    $tn = $node->[1];                      !!!back-token; # </?>
4163                    ## NOTE: There is exactly one |td| or |th| element                      $token = {type => END_TAG_TOKEN, tag_name => $tn};
4164                    ## in scope in the stack of open elements by definition.                      redo B;
4165                  } elsif ({                    } elsif ($node->[1] eq 'td' or $node->[1] eq 'th') {
4166                            table => 1, html => 1,                      !!!cp ('t180');
4167                           }->{$node->[1]}) {                      $tn = $node->[1];
4168                    !!!cp ('t181');                      ## NOTE: There is exactly one |td| or |th| element
4169                    last INSCOPE;                      ## in scope in the stack of open elements by definition.
4170                      } elsif ({
4171                                table => 1, html => 1,
4172                               }->{$node->[1]}) {
4173                        ## ISSUE: Can this be reached?
4174                        !!!cp ('t181');
4175                        last;
4176                      }
4177                  }                  }
4178                } # INSCOPE  
               unless (defined $i) {  
4179                  !!!cp ('t182');                  !!!cp ('t182');
4180                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag',
4181                        value => $token->{tag_name}, token => $token);
4182                  ## Ignore the token                  ## Ignore the token
4183                  !!!next-token;                  !!!next-token;
4184                  redo B;                  redo B;
4185                } else {                } # INSCOPE
                 !!!cp ('t183');  
               }  
   
               ## Close the cell  
               !!!back-token; # </?>  
               $token = {type => END_TAG_TOKEN, tag_name => $tn};  
               redo B;  
4186              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
4187                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
4188                !!!parse-error (type => 'not closed:caption');                !!!parse-error (type => 'not closed:caption', token => $token);
4189    
4190                ## As if </caption>                ## As if </caption>
4191                ## have a table element in table scope                ## have a table element in table scope
# Line 4092  sub _tree_construction_main ($) { Line 4205  sub _tree_construction_main ($) {
4205                } # INSCOPE                } # INSCOPE
4206                unless (defined $i) {                unless (defined $i) {
4207                  !!!cp ('t186');                  !!!cp ('t186');
4208                  !!!parse-error (type => 'unmatched end tag:caption');                  !!!parse-error (type => 'unmatched end tag:caption', token => $token);
4209                  ## Ignore the token                  ## Ignore the token
4210                  !!!next-token;                  !!!next-token;
4211                  redo B;                  redo B;
# Line 4108  sub _tree_construction_main ($) { Line 4221  sub _tree_construction_main ($) {
4221    
4222                if ($self->{open_elements}->[-1]->[1] ne 'caption') {                if ($self->{open_elements}->[-1]->[1] ne 'caption') {
4223                  !!!cp ('t188');                  !!!cp ('t188');
4224                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token);
4225                } else {                } else {
4226                  !!!cp ('t189');                  !!!cp ('t189');
4227                }                }
# Line 4126  sub _tree_construction_main ($) { Line 4239  sub _tree_construction_main ($) {
4239                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4240                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
4241                  !!!cp ('t190');                  !!!cp ('t190');
4242                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4243                  ## Ignore the token                  ## Ignore the token
4244                  !!!next-token;                  !!!next-token;
4245                  redo B;                  redo B;
# Line 4140  sub _tree_construction_main ($) { Line 4253  sub _tree_construction_main ($) {
4253                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
4254                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
4255                !!!cp ('t192');                !!!cp ('t192');
4256                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4257                ## Ignore the token                ## Ignore the token
4258                !!!next-token;                !!!next-token;
4259                redo B;                redo B;
# Line 4148  sub _tree_construction_main ($) { Line 4261  sub _tree_construction_main ($) {
4261                !!!cp ('t193');                !!!cp ('t193');
4262                #                #
4263              }              }
4264          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
4265            for my $entry (@{$self->{open_elements}}) {
4266              if (not {
4267                dd => 1, dt => 1, li => 1, p => 1, tbody => 1, td => 1, tfoot => 1,
4268                th => 1, thead => 1, tr => 1, body => 1, html => 1,
4269              }->{$entry->[1]}) {
4270                !!!cp ('t75');
4271                !!!parse-error (type => 'in body:#eof', token => $token);
4272                last;
4273              }
4274            }
4275    
4276            ## Stop parsing.
4277            last B;
4278        } else {        } else {
4279          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
4280        }        }
# Line 4169  sub _tree_construction_main ($) { Line 4296  sub _tree_construction_main ($) {
4296            }            }
4297          }          }
4298    
4299              !!!parse-error (type => 'in table:#character');              !!!parse-error (type => 'in table:#character', token => $token);
4300    
4301              ## As if in body, but insert into foster parent element              ## As if in body, but insert into foster parent element
4302              ## ISSUE: Spec says that "whenever a node would be inserted              ## ISSUE: Spec says that "whenever a node would be inserted
# Line 4243  sub _tree_construction_main ($) { Line 4370  sub _tree_construction_main ($) {
4370                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
4371                  unless ($token->{tag_name} eq 'tr') {                  unless ($token->{tag_name} eq 'tr') {
4372                    !!!cp ('t202');                    !!!cp ('t202');
4373                    !!!parse-error (type => 'missing start tag:tr');                    !!!parse-error (type => 'missing start tag:tr', token => $token);
4374                  }                  }
4375                                    
4376                  ## Clear back to table body context                  ## Clear back to table body context
# Line 4313  sub _tree_construction_main ($) { Line 4440  sub _tree_construction_main ($) {
4440                  unless (defined $i) {                  unless (defined $i) {
4441                   !!!cp ('t210');                   !!!cp ('t210');
4442  ## TODO: This type is wrong.  ## TODO: This type is wrong.
4443                   !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});                   !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name}, token => $token);
4444                    ## Ignore the token                    ## Ignore the token
4445                    !!!next-token;                    !!!next-token;
4446                    redo B;                    redo B;
# Line 4361  sub _tree_construction_main ($) { Line 4488  sub _tree_construction_main ($) {
4488                  unless (defined $i) {                  unless (defined $i) {
4489                    !!!cp ('t216');                    !!!cp ('t216');
4490  ## TODO: This erorr type ios wrong.  ## TODO: This erorr type ios wrong.
4491                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4492                    ## Ignore the token                    ## Ignore the token
4493                    !!!next-token;                    !!!next-token;
4494                    redo B;                    redo B;
# Line 4433  sub _tree_construction_main ($) { Line 4560  sub _tree_construction_main ($) {
4560                  die "$0: in table: <>: $token->{tag_name}";                  die "$0: in table: <>: $token->{tag_name}";
4561                }                }
4562              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
4563                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token);
4564    
4565                ## As if </table>                ## As if </table>
4566                ## have a table element in table scope                ## have a table element in table scope
# Line 4455  sub _tree_construction_main ($) { Line 4582  sub _tree_construction_main ($) {
4582                unless (defined $i) {                unless (defined $i) {
4583                  !!!cp ('t223');                  !!!cp ('t223');
4584  ## TODO: The following is wrong, maybe.  ## TODO: The following is wrong, maybe.
4585                  !!!parse-error (type => 'unmatched end tag:table');                  !!!parse-error (type => 'unmatched end tag:table', token => $token);
4586                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
4587                  !!!next-token;                  !!!next-token;
4588                  redo B;                  redo B;
4589                }                }
4590                                
4591    ## TODO: Followings are removed from the latest spec.
4592                ## generate implied end tags                ## generate implied end tags
4593                while ({                while ({
4594                        dd => 1, dt => 1, li => 1, p => 1,                        dd => 1, dt => 1, li => 1, p => 1,
# Line 4472  sub _tree_construction_main ($) { Line 4600  sub _tree_construction_main ($) {
4600                if ($self->{open_elements}->[-1]->[1] ne 'table') {                if ($self->{open_elements}->[-1]->[1] ne 'table') {
4601                  !!!cp ('t225');                  !!!cp ('t225');
4602  ## ISSUE: Can this case be reached?  ## ISSUE: Can this case be reached?
4603                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token);
4604                } else {                } else {
4605                  !!!cp ('t226');                  !!!cp ('t226');
4606                }                }
# Line 4484  sub _tree_construction_main ($) { Line 4612  sub _tree_construction_main ($) {
4612    
4613                ## reprocess                ## reprocess
4614                redo B;                redo B;
4615            } elsif ($token->{tag_name} eq 'style') {
4616              if (not $open_tables->[-1]->[1]) { # tainted
4617                !!!cp ('t227.8');
4618                ## NOTE: This is a "as if in head" code clone.
4619                $parse_rcdata->(CDATA_CONTENT_MODEL);
4620                redo B;
4621              } else {
4622                !!!cp ('t227.7');
4623                #
4624              }
4625            } elsif ($token->{tag_name} eq 'script') {
4626              if (not $open_tables->[-1]->[1]) { # tainted
4627                !!!cp ('t227.6');
4628                ## NOTE: This is a "as if in head" code clone.
4629                $script_start_tag->();
4630                redo B;
4631              } else {
4632                !!!cp ('t227.5');
4633                #
4634              }
4635          } elsif ($token->{tag_name} eq 'input') {          } elsif ($token->{tag_name} eq 'input') {
4636            if (not $open_tables->[-1]->[1]) { # tainted            if (not $open_tables->[-1]->[1]) { # tainted
4637              if ($token->{attributes}->{type}) { ## TODO: case              if ($token->{attributes}->{type}) { ## TODO: case
4638                my $type = lc $token->{attributes}->{type}->{value};                my $type = lc $token->{attributes}->{type}->{value};
4639                if ($type eq 'hidden') {                if ($type eq 'hidden') {
4640                  !!!cp ('t227.3');                  !!!cp ('t227.3');
4641                  !!!parse-error (type => 'in table:'.$token->{tag_name});                  !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);
4642    
4643                  !!!insert-element ($token->{tag_name}, $token->{attributes});                  !!!insert-element ($token->{tag_name}, $token->{attributes});
4644    
# Line 4517  sub _tree_construction_main ($) { Line 4665  sub _tree_construction_main ($) {
4665            #            #
4666          }          }
4667    
4668          !!!parse-error (type => 'in table:'.$token->{tag_name});          !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);
4669    
4670          $insert = $insert_to_foster;          $insert = $insert_to_foster;
4671          #          #
# Line 4541  sub _tree_construction_main ($) { Line 4689  sub _tree_construction_main ($) {
4689                } # INSCOPE                } # INSCOPE
4690                unless (defined $i) {                unless (defined $i) {
4691                  !!!cp ('t230');                  !!!cp ('t230');
4692                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4693                  ## Ignore the token                  ## Ignore the token
4694                  !!!next-token;                  !!!next-token;
4695                  redo B;                  redo B;
# Line 4583  sub _tree_construction_main ($) { Line 4731  sub _tree_construction_main ($) {
4731                  unless (defined $i) {                  unless (defined $i) {
4732                    !!!cp ('t235');                    !!!cp ('t235');
4733  ## TODO: The following is wrong.  ## TODO: The following is wrong.
4734                    !!!parse-error (type => 'unmatched end tag:'.$token->{type});                    !!!parse-error (type => 'unmatched end tag:'.$token->{type}, token => $token);
4735                    ## Ignore the token                    ## Ignore the token
4736                    !!!next-token;                    !!!next-token;
4737                    redo B;                    redo B;
# Line 4623  sub _tree_construction_main ($) { Line 4771  sub _tree_construction_main ($) {
4771                  } # INSCOPE                  } # INSCOPE
4772                  unless (defined $i) {                  unless (defined $i) {
4773                    !!!cp ('t239');                    !!!cp ('t239');
4774                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4775                    ## Ignore the token                    ## Ignore the token
4776                    !!!next-token;                    !!!next-token;
4777                    redo B;                    redo B;
# Line 4671  sub _tree_construction_main ($) { Line 4819  sub _tree_construction_main ($) {
4819                } # INSCOPE                } # INSCOPE
4820                unless (defined $i) {                unless (defined $i) {
4821                  !!!cp ('t243');                  !!!cp ('t243');
4822                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4823                  ## Ignore the token                  ## Ignore the token
4824                  !!!next-token;                  !!!next-token;
4825                  redo B;                  redo B;
# Line 4706  sub _tree_construction_main ($) { Line 4854  sub _tree_construction_main ($) {
4854                  } # INSCOPE                  } # INSCOPE
4855                    unless (defined $i) {                    unless (defined $i) {
4856                      !!!cp ('t249');                      !!!cp ('t249');
4857                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4858                      ## Ignore the token                      ## Ignore the token
4859                      !!!next-token;                      !!!next-token;
4860                      redo B;                      redo B;
# Line 4730  sub _tree_construction_main ($) { Line 4878  sub _tree_construction_main ($) {
4878                  } # INSCOPE                  } # INSCOPE
4879                    unless (defined $i) {                    unless (defined $i) {
4880                      !!!cp ('t252');                      !!!cp ('t252');
4881                      !!!parse-error (type => 'unmatched end tag:tr');                      !!!parse-error (type => 'unmatched end tag:tr', token => $token);
4882                      ## Ignore the token                      ## Ignore the token
4883                      !!!next-token;                      !!!next-token;
4884                      redo B;                      redo B;
# Line 4767  sub _tree_construction_main ($) { Line 4915  sub _tree_construction_main ($) {
4915                } # INSCOPE                } # INSCOPE
4916                unless (defined $i) {                unless (defined $i) {
4917                  !!!cp ('t256');                  !!!cp ('t256');
4918                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4919                  ## Ignore the token                  ## Ignore the token
4920                  !!!next-token;                  !!!next-token;
4921                  redo B;                  redo B;
# Line 4793  sub _tree_construction_main ($) { Line 4941  sub _tree_construction_main ($) {
4941                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
4942                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4943                !!!cp ('t258');                !!!cp ('t258');
4944                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4945                ## Ignore the token                ## Ignore the token
4946                !!!next-token;                !!!next-token;
4947                redo B;                redo B;
4948          } else {          } else {
4949            !!!cp ('t259');            !!!cp ('t259');
4950            !!!parse-error (type => 'in table:/'.$token->{tag_name});            !!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token);
4951    
4952            $insert = $insert_to_foster;            $insert = $insert_to_foster;
4953            #            #
4954          }          }
4955          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
4956            unless ($self->{open_elements}->[-1]->[1] eq 'html' and
4957                    @{$self->{open_elements}} == 1) { # redundant, maybe
4958              !!!parse-error (type => 'in body:#eof', token => $token);
4959              !!!cp ('t259.1');
4960              #
4961            } else {
4962              !!!cp ('t259.2');
4963              #
4964            }
4965    
4966            ## Stop parsing
4967            last B;
4968        } else {        } else {
4969          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
4970        }        }
# Line 4835  sub _tree_construction_main ($) { Line 4996  sub _tree_construction_main ($) {
4996              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
4997                if ($self->{open_elements}->[-1]->[1] eq 'html') {                if ($self->{open_elements}->[-1]->[1] eq 'html') {
4998                  !!!cp ('t264');                  !!!cp ('t264');
4999                  !!!parse-error (type => 'unmatched end tag:colgroup');                  !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);
5000                  ## Ignore the token                  ## Ignore the token
5001                  !!!next-token;                  !!!next-token;
5002                  redo B;                  redo B;
# Line 4848  sub _tree_construction_main ($) { Line 5009  sub _tree_construction_main ($) {
5009                }                }
5010              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
5011                !!!cp ('t266');                !!!cp ('t266');
5012                !!!parse-error (type => 'unmatched end tag:col');                !!!parse-error (type => 'unmatched end tag:col', token => $token);
5013                ## Ignore the token                ## Ignore the token
5014                !!!next-token;                !!!next-token;
5015                redo B;                redo B;
# Line 4856  sub _tree_construction_main ($) { Line 5017  sub _tree_construction_main ($) {
5017                !!!cp ('t267');                !!!cp ('t267');
5018                #                #
5019              }              }
5020            } else {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
5021              die "$0: $token->{type}: Unknown token type";          if ($self->{open_elements}->[-1]->[1] eq 'html' or
5022            }              @{$self->{open_elements}} == 1) { # redundant, maybe
5023              !!!cp ('t270.2');
5024              ## Stop parsing.
5025              last B;
5026            } else {
5027              ## NOTE: As if </colgroup>.
5028              !!!cp ('t270.1');
5029              pop @{$self->{open_elements}}; # colgroup
5030              $self->{insertion_mode} = IN_TABLE_IM;
5031              ## Reprocess.
5032              redo B;
5033            }
5034          } else {
5035            die "$0: $token->{type}: Unknown token type";
5036          }
5037    
5038            ## As if </colgroup>            ## As if </colgroup>
5039            if ($self->{open_elements}->[-1]->[1] eq 'html') {            if ($self->{open_elements}->[-1]->[1] eq 'html') {
5040              !!!cp ('t269');              !!!cp ('t269');
5041              !!!parse-error (type => 'unmatched end tag:colgroup');  ## TODO: Wrong error type?
5042                !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);
5043              ## Ignore the token              ## Ignore the token
5044              !!!next-token;              !!!next-token;
5045              redo B;              redo B;
# Line 4874  sub _tree_construction_main ($) { Line 5050  sub _tree_construction_main ($) {
5050              ## reprocess              ## reprocess
5051              redo B;              redo B;
5052            }            }
5053      } elsif ($self->{insertion_mode} == IN_SELECT_IM) {      } elsif ($self->{insertion_mode} & SELECT_IMS) {
5054        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
5055          !!!cp ('t271');          !!!cp ('t271');
5056          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
# Line 4913  sub _tree_construction_main ($) { Line 5089  sub _tree_construction_main ($) {
5089                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
5090                !!!next-token;                !!!next-token;
5091                redo B;                redo B;
5092              } elsif ($token->{tag_name} eq 'select') {          } elsif ($token->{tag_name} eq 'select' or
5093  ## TODO: The type below is not good - <select> is replaced by </select>                   $token->{tag_name} eq 'input' or
5094                !!!parse-error (type => 'not closed:select');                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
5095                ## As if </select> instead                    {
5096                       caption => 1, table => 1,
5097                       tbody => 1, tfoot => 1, thead => 1,
5098                       tr => 1, td => 1, th => 1,
5099                      }->{$token->{tag_name}})) {
5100              ## TODO: The type below is not good - <select> is replaced by </select>
5101              !!!parse-error (type => 'not closed:select', token => $token);
5102              ## NOTE: As if the token were </select> (<select> case) or
5103              ## as if there were </select> (otherwise).
5104                ## have an element in table scope                ## have an element in table scope
5105                my $i;                my $i;
5106                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5107                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5108                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq 'select') {
5109                    !!!cp ('t278');                    !!!cp ('t278');
5110                    $i = $_;                    $i = $_;
5111                    last INSCOPE;                    last INSCOPE;
# Line 4934  sub _tree_construction_main ($) { Line 5118  sub _tree_construction_main ($) {
5118                } # INSCOPE                } # INSCOPE
5119                unless (defined $i) {                unless (defined $i) {
5120                  !!!cp ('t280');                  !!!cp ('t280');
5121                  !!!parse-error (type => 'unmatched end tag:select');                  !!!parse-error (type => 'unmatched end tag:select', token => $token);
5122                  ## Ignore the token                  ## Ignore the token
5123                  !!!next-token;                  !!!next-token;
5124                  redo B;                  redo B;
# Line 4945  sub _tree_construction_main ($) { Line 5129  sub _tree_construction_main ($) {
5129    
5130                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
5131    
5132                !!!next-token;            if ($token->{tag_name} eq 'select') {
5133                redo B;              !!!cp ('t281.2');
5134                !!!next-token;
5135                redo B;
5136              } else {
5137                !!!cp ('t281.1');
5138                ## Reprocess the token.
5139                redo B;
5140              }
5141          } else {          } else {
5142            !!!cp ('t282');            !!!cp ('t282');
5143            !!!parse-error (type => 'in select:'.$token->{tag_name});            !!!parse-error (type => 'in select:'.$token->{tag_name}, token => $token);
5144            ## Ignore the token            ## Ignore the token
5145            !!!next-token;            !!!next-token;
5146            redo B;            redo B;
# Line 4966  sub _tree_construction_main ($) { Line 5157  sub _tree_construction_main ($) {
5157                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
5158                } else {                } else {
5159                  !!!cp ('t285');                  !!!cp ('t285');
5160                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
5161                  ## Ignore the token                  ## Ignore the token
5162                }                }
5163                !!!next-token;                !!!next-token;
# Line 4977  sub _tree_construction_main ($) { Line 5168  sub _tree_construction_main ($) {
5168                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
5169                } else {                } else {
5170                  !!!cp ('t287');                  !!!cp ('t287');
5171                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
5172                  ## Ignore the token                  ## Ignore the token
5173                }                }
5174                !!!next-token;                !!!next-token;
# Line 5000  sub _tree_construction_main ($) { Line 5191  sub _tree_construction_main ($) {
5191                } # INSCOPE                } # INSCOPE
5192                unless (defined $i) {                unless (defined $i) {
5193                  !!!cp ('t290');                  !!!cp ('t290');
5194                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
5195                  ## Ignore the token                  ## Ignore the token
5196                  !!!next-token;                  !!!next-token;
5197                  redo B;                  redo B;
# Line 5013  sub _tree_construction_main ($) { Line 5204  sub _tree_construction_main ($) {
5204    
5205                !!!next-token;                !!!next-token;
5206                redo B;                redo B;
5207              } elsif ({          } elsif ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
5208                        caption => 1, table => 1, tbody => 1,                   {
5209                        tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    caption => 1, table => 1, tbody => 1,
5210                       }->{$token->{tag_name}}) {                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
5211                     }->{$token->{tag_name}}) {
5212  ## TODO: The following is wrong?  ## TODO: The following is wrong?
5213                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
5214                                
5215                ## have an element in table scope                ## have an element in table scope
5216                my $i;                my $i;
# Line 5062  sub _tree_construction_main ($) { Line 5254  sub _tree_construction_main ($) {
5254                unless (defined $i) {                unless (defined $i) {
5255                  !!!cp ('t297');                  !!!cp ('t297');
5256  ## TODO: The following error type is correct?  ## TODO: The following error type is correct?
5257                  !!!parse-error (type => 'unmatched end tag:select');                  !!!parse-error (type => 'unmatched end tag:select', token => $token);
5258                  ## Ignore the </select> token                  ## Ignore the </select> token
5259                  !!!next-token; ## TODO: ok?                  !!!next-token; ## TODO: ok?
5260                  redo B;                  redo B;
# Line 5077  sub _tree_construction_main ($) { Line 5269  sub _tree_construction_main ($) {
5269                redo B;                redo B;
5270          } else {          } else {
5271            !!!cp ('t299');            !!!cp ('t299');
5272            !!!parse-error (type => 'in select:/'.$token->{tag_name});            !!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token);
5273            ## Ignore the token            ## Ignore the token
5274            !!!next-token;            !!!next-token;
5275            redo B;            redo B;
5276          }          }
5277          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
5278            unless ($self->{open_elements}->[-1]->[1] eq 'html' and
5279                    @{$self->{open_elements}} == 1) { # redundant, maybe
5280              !!!cp ('t299.1');
5281              !!!parse-error (type => 'in body:#eof', token => $token);
5282            } else {
5283              !!!cp ('t299.2');
5284            }
5285    
5286            ## Stop parsing.
5287            last B;
5288        } else {        } else {
5289          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
5290        }        }
# Line 5103  sub _tree_construction_main ($) { Line 5306  sub _tree_construction_main ($) {
5306                    
5307          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
5308            !!!cp ('t301');            !!!cp ('t301');
5309            !!!parse-error (type => 'after html:#character');            !!!parse-error (type => 'after html:#character', token => $token);
5310    
5311            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
5312          } else {          } else {
# Line 5111  sub _tree_construction_main ($) { Line 5314  sub _tree_construction_main ($) {
5314          }          }
5315                    
5316          ## "after body" insertion mode          ## "after body" insertion mode
5317          !!!parse-error (type => 'after body:#character');          !!!parse-error (type => 'after body:#character', token => $token);
5318    
5319          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
5320          ## reprocess          ## reprocess
# Line 5119  sub _tree_construction_main ($) { Line 5322  sub _tree_construction_main ($) {
5322        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5323          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
5324            !!!cp ('t303');            !!!cp ('t303');
5325            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);
5326                        
5327            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
5328          } else {          } else {
# Line 5127  sub _tree_construction_main ($) { Line 5330  sub _tree_construction_main ($) {
5330          }          }
5331    
5332          ## "after body" insertion mode          ## "after body" insertion mode
5333          !!!parse-error (type => 'after body:'.$token->{tag_name});          !!!parse-error (type => 'after body:'.$token->{tag_name}, token => $token);
5334    
5335          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
5336          ## reprocess          ## reprocess
# Line 5135  sub _tree_construction_main ($) { Line 5338  sub _tree_construction_main ($) {
5338        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
5339          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
5340            !!!cp ('t305');            !!!cp ('t305');
5341            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);
5342                        
5343            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
5344            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
# Line 5147  sub _tree_construction_main ($) { Line 5350  sub _tree_construction_main ($) {
5350          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
5351            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
5352              !!!cp ('t307');              !!!cp ('t307');
5353              !!!parse-error (type => 'unmatched end tag:html');              !!!parse-error (type => 'unmatched end tag:html', token => $token);
5354              ## Ignore the token              ## Ignore the token
5355              !!!next-token;              !!!next-token;
5356              redo B;              redo B;
# Line 5159  sub _tree_construction_main ($) { Line 5362  sub _tree_construction_main ($) {
5362            }            }
5363          } else {          } else {
5364            !!!cp ('t309');            !!!cp ('t309');
5365            !!!parse-error (type => 'after body:/'.$token->{tag_name});            !!!parse-error (type => 'after body:/'.$token->{tag_name}, token => $token);
5366    
5367            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
5368            ## reprocess            ## reprocess
5369            redo B;            redo B;
5370          }          }
5371          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
5372            !!!cp ('t309.2');
5373            ## Stop parsing
5374            last B;
5375        } else {        } else {
5376          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
5377        }        }
# Line 5183  sub _tree_construction_main ($) { Line 5390  sub _tree_construction_main ($) {
5390          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
5391            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
5392              !!!cp ('t311');              !!!cp ('t311');
5393              !!!parse-error (type => 'in frameset:#character');              !!!parse-error (type => 'in frameset:#character', token => $token);
5394            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
5395              !!!cp ('t312');              !!!cp ('t312');
5396              !!!parse-error (type => 'after frameset:#character');              !!!parse-error (type => 'after frameset:#character', token => $token);
5397            } else { # "after html frameset"            } else { # "after html frameset"
5398              !!!cp ('t313');              !!!cp ('t313');
5399              !!!parse-error (type => 'after html:#character');              !!!parse-error (type => 'after html:#character', token => $token);
5400    
5401              $self->{insertion_mode} = AFTER_FRAMESET_IM;              $self->{insertion_mode} = AFTER_FRAMESET_IM;
5402              ## Reprocess in the "after frameset" insertion mode.              ## Reprocess in the "after frameset" insertion mode.
5403              !!!parse-error (type => 'after frameset:#character');              !!!parse-error (type => 'after frameset:#character', token => $token);
5404            }            }
5405                        
5406            ## Ignore the token.            ## Ignore the token.
# Line 5211  sub _tree_construction_main ($) { Line 5418  sub _tree_construction_main ($) {
5418        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5419          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
5420            !!!cp ('t316');            !!!cp ('t316');
5421            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);
5422    
5423            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
5424            ## Process in the "after frameset" insertion mode.            ## Process in the "after frameset" insertion mode.
# Line 5240  sub _tree_construction_main ($) { Line 5447  sub _tree_construction_main ($) {
5447          } else {          } else {
5448            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
5449              !!!cp ('t321');              !!!cp ('t321');
5450              !!!parse-error (type => 'in frameset:'.$token->{tag_name});              !!!parse-error (type => 'in frameset:'.$token->{tag_name}, token => $token);
5451            } else {            } else {
5452              !!!cp ('t322');              !!!cp ('t322');
5453              !!!parse-error (type => 'after frameset:'.$token->{tag_name});              !!!parse-error (type => 'after frameset:'.$token->{tag_name}, token => $token);
5454            }            }
5455            ## Ignore the token            ## Ignore the token
5456            !!!next-token;            !!!next-token;
# Line 5252  sub _tree_construction_main ($) { Line 5459  sub _tree_construction_main ($) {
5459        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
5460          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
5461            !!!cp ('t323');            !!!cp ('t323');
5462            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);
5463    
5464            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
5465            ## Process in the "after frameset" insertion mode.            ## Process in the "after frameset" insertion mode.
# Line 5265  sub _tree_construction_main ($) { Line 5472  sub _tree_construction_main ($) {
5472            if ($self->{open_elements}->[-1]->[1] eq 'html' and            if ($self->{open_elements}->[-1]->[1] eq 'html' and
5473                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
5474              !!!cp ('t325');              !!!cp ('t325');
5475              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
5476              ## Ignore the token              ## Ignore the token
5477              !!!next-token;              !!!next-token;
5478            } else {            } else {
# Line 5291  sub _tree_construction_main ($) { Line 5498  sub _tree_construction_main ($) {
5498          } else {          } else {
5499            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
5500              !!!cp ('t330');              !!!cp ('t330');
5501              !!!parse-error (type => 'in frameset:/'.$token->{tag_name});              !!!parse-error (type => 'in frameset:/'.$token->{tag_name}, token => $token);
5502            } else {            } else {
5503              !!!cp ('t331');              !!!cp ('t331');
5504              !!!parse-error (type => 'after frameset:/'.$token->{tag_name});              !!!parse-error (type => 'after frameset:/'.$token->{tag_name}, token => $token);
5505            }            }
5506            ## Ignore the token            ## Ignore the token
5507            !!!next-token;            !!!next-token;
5508            redo B;            redo B;
5509          }          }
5510          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
5511            unless ($self->{open_elements}->[-1]->[1] eq 'html' and
5512                    @{$self->{open_elements}} == 1) { # redundant, maybe
5513              !!!cp ('t331.1');
5514              !!!parse-error (type => 'in body:#eof', token => $token);
5515            } else {
5516              !!!cp ('t331.2');
5517            }
5518            
5519            ## Stop parsing
5520            last B;
5521        } else {        } else {
5522          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
5523        }        }
# Line 5314  sub _tree_construction_main ($) { Line 5532  sub _tree_construction_main ($) {
5532        if ($token->{tag_name} eq 'script') {        if ($token->{tag_name} eq 'script') {
5533          !!!cp ('t332');          !!!cp ('t332');
5534          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5535          $script_start_tag->($insert);          $script_start_tag->();
5536          redo B;          redo B;
5537        } elsif ($token->{tag_name} eq 'style') {        } elsif ($token->{tag_name} eq 'style') {
5538          !!!cp ('t333');          !!!cp ('t333');
# Line 5386  sub _tree_construction_main ($) { Line 5604  sub _tree_construction_main ($) {
5604          $parse_rcdata->(RCDATA_CONTENT_MODEL);          $parse_rcdata->(RCDATA_CONTENT_MODEL);
5605          redo B;          redo B;
5606        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
5607          !!!parse-error (type => 'in body:body');          !!!parse-error (type => 'in body:body', token => $token);
5608                                
5609          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
5610              $self->{open_elements}->[1]->[1] ne 'body') {              $self->{open_elements}->[1]->[1] ne 'body') {
# Line 5411  sub _tree_construction_main ($) { Line 5629  sub _tree_construction_main ($) {
5629                  h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,                  h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
5630                  menu => 1, ol => 1, p => 1, ul => 1,                  menu => 1, ol => 1, p => 1, ul => 1,
5631                  pre => 1, listing => 1,                  pre => 1, listing => 1,
5632                    form => 1,
5633                    table => 1,
5634                    hr => 1,
5635                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5636            if ($token->{tag_name} eq 'form' and defined $self->{form_element}) {
5637              !!!cp ('t350');
5638              !!!parse-error (type => 'in form:form', token => $token);
5639              ## Ignore the token
5640              !!!next-token;
5641              redo B;
5642            }
5643    
5644          ## has a p element in scope          ## has a p element in scope
5645          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5646            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
# Line 5420  sub _tree_construction_main ($) { Line 5649  sub _tree_construction_main ($) {
5649              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5650              redo B;              redo B;
5651            } elsif ({            } elsif ({
5652                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5653                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5654                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5655              !!!cp ('t345');              !!!cp ('t345');
# Line 5442  sub _tree_construction_main ($) { Line 5671  sub _tree_construction_main ($) {
5671            } else {            } else {
5672              !!!cp ('t348');              !!!cp ('t348');
5673            }            }
5674          } else {          } elsif ($token->{tag_name} eq 'form') {
5675            !!!cp ('t347');            !!!cp ('t347.1');
5676              $self->{form_element} = $self->{open_elements}->[-1]->[0];
5677    
5678            !!!next-token;            !!!next-token;
5679          }          } elsif ($token->{tag_name} eq 'table') {
5680          redo B;            !!!cp ('t382');
5681        } elsif ($token->{tag_name} eq 'form') {            push @{$open_tables}, [$self->{open_elements}->[-1]->[0]];
5682          if (defined $self->{form_element}) {            
5683            !!!cp ('t350');            $self->{insertion_mode} = IN_TABLE_IM;
5684            !!!parse-error (type => 'in form:form');  
5685            ## Ignore the token            !!!next-token;
5686            } elsif ($token->{tag_name} eq 'hr') {
5687              !!!cp ('t386');
5688              pop @{$self->{open_elements}};
5689            
5690            !!!next-token;            !!!next-token;
           redo B;  
5691          } else {          } else {
5692            ## has a p element in scope            !!!cp ('t347');
           INSCOPE: for (reverse @{$self->{open_elements}}) {  
             if ($_->[1] eq 'p') {  
               !!!cp ('t351');  
               !!!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,  
                      }->{$_->[1]}) {  
               !!!cp ('t352');  
               last INSCOPE;  
             }  
           } # INSCOPE  
               
           !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
           $self->{form_element} = $self->{open_elements}->[-1]->[0];  
5693            !!!next-token;            !!!next-token;
           redo B;  
5694          }          }
5695        } elsif ($token->{tag_name} eq 'li') {          redo B;
5696          } elsif ({li => 1, dt => 1, dd => 1}->{$token->{tag_name}}) {
5697          ## has a p element in scope          ## has a p element in scope
5698          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5699            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
# Line 5485  sub _tree_construction_main ($) { Line 5702  sub _tree_construction_main ($) {
5702              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5703              redo B;              redo B;
5704            } elsif ({            } elsif ({
5705                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5706                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5707                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5708              !!!cp ('t354');              !!!cp ('t354');
# Line 5496  sub _tree_construction_main ($) { Line 5713  sub _tree_construction_main ($) {
5713          ## Step 1          ## Step 1
5714          my $i = -1;          my $i = -1;
5715          my $node = $self->{open_elements}->[$i];          my $node = $self->{open_elements}->[$i];
5716            my $li_or_dtdd = {li => {li => 1},
5717                              dt => {dt => 1, dd => 1},
5718                              dd => {dt => 1, dd => 1}}->{$token->{tag_name}};
5719          LI: {          LI: {
5720            ## Step 2            ## Step 2
5721            if ($node->[1] eq 'li') {            if ($li_or_dtdd->{$node->[1]}) {
5722              if ($i != -1) {              if ($i != -1) {
5723                !!!cp ('t355');                !!!cp ('t355');
5724                !!!parse-error (type => 'end tag missing:'.                !!!parse-error (type => 'end tag missing:'.
5725                                $self->{open_elements}->[-1]->[1]);                                $self->{open_elements}->[-1]->[1], token => $token);
5726              } else {              } else {
5727                !!!cp ('t356');                !!!cp ('t356');
5728              }              }
# Line 5532  sub _tree_construction_main ($) { Line 5752  sub _tree_construction_main ($) {
5752          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5753          !!!next-token;          !!!next-token;
5754          redo B;          redo B;
       } elsif ($token->{tag_name} eq 'dd' or $token->{tag_name} eq 'dt') {  
         ## has a p element in scope  
         INSCOPE: for (reverse @{$self->{open_elements}}) {  
           if ($_->[1] eq 'p') {  
             !!!cp ('t360');  
             !!!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,  
                    }->{$_->[1]}) {  
             !!!cp ('t361');  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         ## Step 1  
         my $i = -1;  
         my $node = $self->{open_elements}->[$i];  
         LI: {  
           ## Step 2  
           if ($node->[1] eq 'dt' or $node->[1] eq 'dd') {  
             if ($i != -1) {  
               !!!cp ('t362');  
               !!!parse-error (type => 'end tag missing:'.  
                               $self->{open_elements}->[-1]->[1]);  
             } else {  
               !!!cp ('t363');  
             }  
             splice @{$self->{open_elements}}, $i;  
             last LI;  
           } else {  
             !!!cp ('t364');  
           }  
             
           ## Step 3  
           if (not $formatting_category->{$node->[1]} and  
               #not $phrasing_category->{$node->[1]} and  
               ($special_category->{$node->[1]} or  
                $scoping_category->{$node->[1]}) and  
               $node->[1] ne 'address' and $node->[1] ne 'div') {  
             !!!cp ('t365');  
             last LI;  
           }  
             
           !!!cp ('t366');  
           ## Step 4  
           $i--;  
           $node = $self->{open_elements}->[$i];  
           redo LI;  
         } # LI  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         !!!next-token;  
         redo B;  
5755        } elsif ($token->{tag_name} eq 'plaintext') {        } elsif ($token->{tag_name} eq 'plaintext') {
5756          ## has a p element in scope          ## has a p element in scope
5757          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
# Line 5597  sub _tree_construction_main ($) { Line 5761  sub _tree_construction_main ($) {
5761              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5762              redo B;              redo B;
5763            } elsif ({            } elsif ({
5764                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5765                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5766                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5767              !!!cp ('t368');              !!!cp ('t368');
# Line 5616  sub _tree_construction_main ($) { Line 5780  sub _tree_construction_main ($) {
5780            my $node = $active_formatting_elements->[$i];            my $node = $active_formatting_elements->[$i];
5781            if ($node->[1] eq 'a') {            if ($node->[1] eq 'a') {
5782              !!!cp ('t371');              !!!cp ('t371');
5783              !!!parse-error (type => 'in a:a');              !!!parse-error (type => 'in a:a', token => $token);
5784                            
5785              !!!back-token;              !!!back-token;
5786              $token = {type => END_TAG_TOKEN, tag_name => 'a'};              $token = {type => END_TAG_TOKEN, tag_name => 'a'};
5787              $formatting_end_tag->($token->{tag_name});              $formatting_end_tag->($token);
5788                            
5789              AFE2: for (reverse 0..$#$active_formatting_elements) {              AFE2: for (reverse 0..$#$active_formatting_elements) {
5790                if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {                if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {
# Line 5650  sub _tree_construction_main ($) { Line 5814  sub _tree_construction_main ($) {
5814    
5815          !!!next-token;          !!!next-token;
5816          redo B;          redo B;
       } elsif ({  
                 b => 1, big => 1, em => 1, font => 1, i => 1,  
                 s => 1, small => 1, strile => 1,  
                 strong => 1, tt => 1, u => 1,  
                }->{$token->{tag_name}}) {  
         !!!cp ('t375');  
         $reconstruct_active_formatting_elements->($insert_to_current);  
           
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         push @$active_formatting_elements, $self->{open_elements}->[-1];  
           
         !!!next-token;  
         redo B;  
5817        } elsif ($token->{tag_name} eq 'nobr') {        } elsif ($token->{tag_name} eq 'nobr') {
5818          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5819    
# Line 5671  sub _tree_construction_main ($) { Line 5822  sub _tree_construction_main ($) {
5822            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
5823            if ($node->[1] eq 'nobr') {            if ($node->[1] eq 'nobr') {
5824              !!!cp ('t376');              !!!cp ('t376');
5825              !!!parse-error (type => 'in nobr:nobr');              !!!parse-error (type => 'in nobr:nobr', token => $token);
5826              !!!back-token;              !!!back-token;
5827              $token = {type => END_TAG_TOKEN, tag_name => 'nobr'};              $token = {type => END_TAG_TOKEN, tag_name => 'nobr'};
5828              redo B;              redo B;
5829            } elsif ({            } elsif ({
5830                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5831                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5832                     }->{$node->[1]}) {                     }->{$node->[1]}) {
5833              !!!cp ('t377');              !!!cp ('t377');
# Line 5695  sub _tree_construction_main ($) { Line 5846  sub _tree_construction_main ($) {
5846            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
5847            if ($node->[1] eq 'button') {            if ($node->[1] eq 'button') {
5848              !!!cp ('t378');              !!!cp ('t378');
5849              !!!parse-error (type => 'in button:button');              !!!parse-error (type => 'in button:button', token => $token);
5850              !!!back-token;              !!!back-token;
5851              $token = {type => END_TAG_TOKEN, tag_name => 'button'};              $token = {type => END_TAG_TOKEN, tag_name => 'button'};
5852              redo B;              redo B;
5853            } elsif ({            } elsif ({
5854                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5855                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5856                     }->{$node->[1]}) {                     }->{$node->[1]}) {
5857              !!!cp ('t379');              !!!cp ('t379');
# Line 5718  sub _tree_construction_main ($) { Line 5869  sub _tree_construction_main ($) {
5869    
5870          !!!next-token;          !!!next-token;
5871          redo B;          redo B;
       } elsif ($token->{tag_name} eq 'marquee' or  
                $token->{tag_name} eq 'object') {  
         !!!cp ('t380');  
         $reconstruct_active_formatting_elements->($insert_to_current);  
           
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         push @$active_formatting_elements, ['#marker', ''];  
           
         !!!next-token;  
         redo B;  
       } elsif ($token->{tag_name} eq 'xmp') {  
         !!!cp ('t381');  
         $reconstruct_active_formatting_elements->($insert_to_current);  
         $parse_rcdata->(CDATA_CONTENT_MODEL);  
         redo B;  
       } elsif ($token->{tag_name} eq 'table') {  
         ## has a p element in scope  
         INSCOPE: for (reverse @{$self->{open_elements}}) {  
           if ($_->[1] eq 'p') {  
             !!!cp ('t382');  
             !!!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,  
                    }->{$_->[1]}) {  
             !!!cp ('t383');  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         push @{$open_tables}, [$self->{open_elements}->[-1]->[0]];  
   
         $self->{insertion_mode} = IN_TABLE_IM;  
             
         !!!next-token;  
         redo B;  
5872        } elsif ({        } elsif ({
5873                  area => 1, basefont => 1, bgsound => 1, br => 1,                  xmp => 1,
5874                  embed => 1, img => 1, param => 1, spacer => 1, wbr => 1,                  iframe => 1,
5875                  image => 1,                  noembed => 1,
5876                    noframes => 1,
5877                    noscript => 0, ## TODO: 1 if scripting is enabled
5878                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5879          if ($token->{tag_name} eq 'image') {          if ($token->{tag_name} eq 'xmp') {
5880            !!!cp ('t384');            !!!cp ('t381');
5881            !!!parse-error (type => 'image');            $reconstruct_active_formatting_elements->($insert_to_current);
           $token->{tag_name} = 'img';  
5882          } else {          } else {
5883            !!!cp ('t385');            !!!cp ('t399');
5884          }          }
5885            ## NOTE: There is an "as if in body" code clone.
5886          ## NOTE: There is an "as if <br>" code clone.          $parse_rcdata->(CDATA_CONTENT_MODEL);
         $reconstruct_active_formatting_elements->($insert_to_current);  
           
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         pop @{$self->{open_elements}};  
           
         !!!next-token;  
         redo B;  
       } elsif ($token->{tag_name} eq 'hr') {  
         ## has a p element in scope  
         INSCOPE: for (reverse @{$self->{open_elements}}) {  
           if ($_->[1] eq 'p') {  
             !!!cp ('t386');  
             !!!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,  
                    }->{$_->[1]}) {  
             !!!cp ('t387');  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         pop @{$self->{open_elements}};  
             
         !!!next-token;  
         redo B;  
       } elsif ($token->{tag_name} eq 'input') {  
         !!!cp ('t388');  
         $reconstruct_active_formatting_elements->($insert_to_current);  
           
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         ## TODO: associate with $self->{form_element} if defined  
         pop @{$self->{open_elements}};  
           
         !!!next-token;  
5887          redo B;          redo B;
5888        } elsif ($token->{tag_name} eq 'isindex') {        } elsif ($token->{tag_name} eq 'isindex') {
5889          !!!parse-error (type => 'isindex');          !!!parse-error (type => 'isindex', token => $token);
5890                    
5891          if (defined $self->{form_element}) {          if (defined $self->{form_element}) {
5892            !!!cp ('t389');            !!!cp ('t389');
# Line 5895  sub _tree_construction_main ($) { Line 5970  sub _tree_construction_main ($) {
5970            ## Ignore the token            ## Ignore the token
5971          } else {          } else {
5972            !!!cp ('t398');            !!!cp ('t398');
5973            !!!parse-error (type => 'in RCDATA:#'.$token->{type});            !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);
5974          }          }
5975          !!!next-token;          !!!next-token;
5976          redo B;          redo B;
5977        } elsif ({        } elsif ({
                 iframe => 1,  
                 noembed => 1,  
                 noframes => 1,  
                 noscript => 0, ## TODO: 1 if scripting is enabled  
                }->{$token->{tag_name}}) {  
         !!!cp ('t399');  
         ## NOTE: There is an "as if in body" code clone.  
         $parse_rcdata->(CDATA_CONTENT_MODEL);  
         redo B;  
       } elsif ($token->{tag_name} eq 'select') {  
         !!!cp ('t400');  
         $reconstruct_active_formatting_elements->($insert_to_current);  
           
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
   
         ## TODO: associate with $self->{form_element} if defined  
           
         $self->{insertion_mode} = IN_SELECT_IM;  
         !!!next-token;  
         redo B;  
       } elsif ({  
5978                  caption => 1, col => 1, colgroup => 1, frame => 1,                  caption => 1, col => 1, colgroup => 1, frame => 1,
5979                  frameset => 1, head => 1, option => 1, optgroup => 1,                  frameset => 1, head => 1, option => 1, optgroup => 1,
5980                  tbody => 1, td => 1, tfoot => 1, th => 1,                  tbody => 1, td => 1, tfoot => 1, th => 1,
5981                  thead => 1, tr => 1,                  thead => 1, tr => 1,
5982                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5983          !!!cp ('t401');          !!!cp ('t401');
5984          !!!parse-error (type => 'in body:'.$token->{tag_name});          !!!parse-error (type => 'in body:'.$token->{tag_name}, token => $token);
5985          ## Ignore the token          ## Ignore the token
5986          !!!next-token;          !!!next-token;
5987          redo B;          redo B;
5988                    
5989          ## ISSUE: An issue on HTML5 new elements in the spec.          ## ISSUE: An issue on HTML5 new elements in the spec.
5990        } else {        } else {
5991          !!!cp ('t402');          if ($token->{tag_name} eq 'image') {
5992              !!!cp ('t384');
5993              !!!parse-error (type => 'image', token => $token);
5994              $token->{tag_name} = 'img';
5995            } else {
5996              !!!cp ('t385');
5997            }
5998    
5999            ## NOTE: There is an "as if <br>" code clone.
6000          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
6001                    
6002          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
6003    
6004            if ({
6005                 applet => 1, marquee => 1, object => 1,
6006                }->{$token->{tag_name}}) {
6007              !!!cp ('t380');
6008              push @$active_formatting_elements, ['#marker', ''];
6009            } elsif ({
6010                      b => 1, big => 1, em => 1, font => 1, i => 1,
6011                      s => 1, small => 1, strile => 1,
6012                      strong => 1, tt => 1, u => 1,
6013                     }->{$token->{tag_name}}) {
6014              !!!cp ('t375');
6015              push @$active_formatting_elements, $self->{open_elements}->[-1];
6016            } elsif ($token->{tag_name} eq 'input') {
6017              !!!cp ('t388');
6018              ## TODO: associate with $self->{form_element} if defined
6019              pop @{$self->{open_elements}};
6020            } elsif ({
6021                      area => 1, basefont => 1, bgsound => 1, br => 1,
6022                      embed => 1, img => 1, param => 1, spacer => 1, wbr => 1,
6023                      #image => 1,
6024                     }->{$token->{tag_name}}) {
6025              !!!cp ('t388.1');
6026              pop @{$self->{open_elements}};
6027            } elsif ($token->{tag_name} eq 'select') {
6028              ## TODO: associate with $self->{form_element} if defined
6029            
6030              if ($self->{insertion_mode} & TABLE_IMS or
6031                  $self->{insertion_mode} & BODY_TABLE_IMS or
6032                  $self->{insertion_mode} == IN_COLUMN_GROUP_IM) {
6033                !!!cp ('t400.1');
6034                $self->{insertion_mode} = IN_SELECT_IN_TABLE_IM;
6035              } else {
6036                !!!cp ('t400.2');
6037                $self->{insertion_mode} = IN_SELECT_IM;
6038              }
6039            } else {
6040              !!!cp ('t402');
6041            }
6042                    
6043          !!!next-token;          !!!next-token;
6044          redo B;          redo B;
6045        }        }
6046      } elsif ($token->{type} == END_TAG_TOKEN) {      } elsif ($token->{type} == END_TAG_TOKEN) {
6047        if ($token->{tag_name} eq 'body') {        if ($token->{tag_name} eq 'body') {
6048          if (@{$self->{open_elements}} > 1 and          ## has a |body| element in scope
6049              $self->{open_elements}->[1]->[1] eq 'body') {          my $i;
6050            for (@{$self->{open_elements}}) {          INSCOPE: {
6051              unless ({            for (reverse @{$self->{open_elements}}) {
6052                         dd => 1, dt => 1, li => 1, p => 1, td => 1,              if ($_->[1] eq 'body') {
6053                         th => 1, tr => 1, body => 1, html => 1,                !!!cp ('t405');
6054                       tbody => 1, tfoot => 1, thead => 1,                $i = $_;
6055                      }->{$_->[1]}) {                last INSCOPE;
6056                !!!cp ('t403');              } elsif ({
6057                !!!parse-error (type => 'not closed:'.$_->[1]);                        applet => 1, table => 1, caption => 1, td => 1, th => 1,
6058              } else {                        button => 1, marquee => 1, object => 1, html => 1,
6059                !!!cp ('t404');                       }->{$_->[1]}) {
6060                  !!!cp ('t405.1');
6061                  last;
6062              }              }
6063            }            }
6064    
6065            $self->{insertion_mode} = AFTER_BODY_IM;            !!!parse-error (type => 'start tag not allowed',
6066            !!!next-token;                            value => $token->{tag_name}, token => $token);
6067            redo B;            ## NOTE: Ignore the token.
         } else {  
           !!!cp ('t405');  
           !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
           ## Ignore the token  
6068            !!!next-token;            !!!next-token;
6069            redo B;            redo B;
6070            } # INSCOPE
6071    
6072            for (@{$self->{open_elements}}) {
6073              unless ({
6074                       dd => 1, dt => 1, li => 1, p => 1, td => 1,
6075                       th => 1, tr => 1, body => 1, html => 1,
6076                       tbody => 1, tfoot => 1, thead => 1,
6077                      }->{$_->[1]}) {
6078                !!!cp ('t403');
6079                !!!parse-error (type => 'not closed:'.$_->[1], token => $token);
6080                last;
6081              } else {
6082                !!!cp ('t404');
6083              }
6084          }          }
6085    
6086            $self->{insertion_mode} = AFTER_BODY_IM;
6087            !!!next-token;
6088            redo B;
6089        } elsif ($token->{tag_name} eq 'html') {        } elsif ($token->{tag_name} eq 'html') {
6090          if (@{$self->{open_elements}} > 1 and $self->{open_elements}->[1]->[1] eq 'body') {          if (@{$self->{open_elements}} > 1 and $self->{open_elements}->[1]->[1] eq 'body') {
6091            ## ISSUE: There is an issue in the spec.            ## ISSUE: There is an issue in the spec.
6092            if ($self->{open_elements}->[-1]->[1] ne 'body') {            if ($self->{open_elements}->[-1]->[1] ne 'body') {
6093              !!!cp ('t406');              !!!cp ('t406');
6094              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[1]->[1]);              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[1]->[1], token => $token);
6095            } else {            } else {
6096              !!!cp ('t407');              !!!cp ('t407');
6097            }            }
# Line 5983  sub _tree_construction_main ($) { Line 6100  sub _tree_construction_main ($) {
6100            redo B;            redo B;
6101          } else {          } else {
6102            !!!cp ('t408');            !!!cp ('t408');
6103            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
6104            ## Ignore the token            ## Ignore the token
6105            !!!next-token;            !!!next-token;
6106            redo B;            redo B;
# Line 5993  sub _tree_construction_main ($) { Line 6110  sub _tree_construction_main ($) {
6110                  div => 1, dl => 1, fieldset => 1, listing => 1,                  div => 1, dl => 1, fieldset => 1, listing => 1,
6111                  menu => 1, ol => 1, pre => 1, ul => 1,                  menu => 1, ol => 1, pre => 1, ul => 1,
6112                  dd => 1, dt => 1, li => 1,                  dd => 1, dt => 1, li => 1,
6113                  button => 1, marquee => 1, object => 1,                  applet => 1, button => 1, marquee => 1, object => 1,
6114                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6115          ## has an element in scope          ## has an element in scope
6116          my $i;          my $i;
# Line 6004  sub _tree_construction_main ($) { Line 6121  sub _tree_construction_main ($) {
6121              $i = $_;              $i = $_;
6122              last INSCOPE;              last INSCOPE;
6123            } elsif ({            } elsif ({
6124                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
6125                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6126                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6127              !!!cp ('t411');              !!!cp ('t411');
# Line 6014  sub _tree_construction_main ($) { Line 6131  sub _tree_construction_main ($) {
6131    
6132          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
6133            !!!cp ('t413');            !!!cp ('t413');
6134            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
6135          } else {          } else {
6136            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
6137            while ({            while ({
# Line 6030  sub _tree_construction_main ($) { Line 6147  sub _tree_construction_main ($) {
6147            ## Step 2.            ## Step 2.
6148            if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {            if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6149              !!!cp ('t412');              !!!cp ('t412');
6150              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token);
6151            } else {            } else {
6152              !!!cp ('t414');              !!!cp ('t414');
6153            }            }
# Line 6041  sub _tree_construction_main ($) { Line 6158  sub _tree_construction_main ($) {
6158            ## Step 4.            ## Step 4.
6159            $clear_up_to_marker->()            $clear_up_to_marker->()
6160                if {                if {
6161                  button => 1, marquee => 1, object => 1,                  applet => 1, button => 1, marquee => 1, object => 1,
6162                }->{$token->{tag_name}};                }->{$token->{tag_name}};
6163          }          }
6164          !!!next-token;          !!!next-token;
# Line 6058  sub _tree_construction_main ($) { Line 6175  sub _tree_construction_main ($) {
6175              $i = $_;              $i = $_;
6176              last INSCOPE;              last INSCOPE;
6177            } elsif ({            } elsif ({
6178                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
6179                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6180                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6181              !!!cp ('t419');              !!!cp ('t419');
# Line 6068  sub _tree_construction_main ($) { Line 6185  sub _tree_construction_main ($) {
6185    
6186          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
6187            !!!cp ('t421');            !!!cp ('t421');
6188            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
6189          } else {          } else {
6190            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
6191            while ({            while ({
# Line 6081  sub _tree_construction_main ($) { Line 6198  sub _tree_construction_main ($) {
6198            ## Step 2.            ## Step 2.
6199            if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {            if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6200              !!!cp ('t417.1');              !!!cp ('t417.1');
6201              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token);
6202            } else {            } else {
6203              !!!cp ('t420');              !!!cp ('t420');
6204            }              }  
# Line 6106  sub _tree_construction_main ($) { Line 6223  sub _tree_construction_main ($) {
6223              $i = $_;              $i = $_;
6224              last INSCOPE;              last INSCOPE;
6225            } elsif ({            } elsif ({
6226                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
6227                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6228                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6229              !!!cp ('t424');              !!!cp ('t424');
# Line 6116  sub _tree_construction_main ($) { Line 6233  sub _tree_construction_main ($) {
6233    
6234          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
6235            !!!cp ('t425.1');            !!!cp ('t425.1');
6236            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
6237          } else {          } else {
6238            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
6239            while ({            while ({
# Line 6129  sub _tree_construction_main ($) { Line 6246  sub _tree_construction_main ($) {
6246            ## Step 2.            ## Step 2.
6247            if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {            if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6248              !!!cp ('t425');              !!!cp ('t425');
6249              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
6250            } else {            } else {
6251              !!!cp ('t426');              !!!cp ('t426');
6252            }            }
# Line 6150  sub _tree_construction_main ($) { Line 6267  sub _tree_construction_main ($) {
6267              $i = $_;              $i = $_;
6268              last INSCOPE;              last INSCOPE;
6269            } elsif ({            } elsif ({
6270                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
6271                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6272                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6273              !!!cp ('t411.1');              !!!cp ('t411.1');
# Line 6161  sub _tree_construction_main ($) { Line 6278  sub _tree_construction_main ($) {
6278          if (defined $i) {          if (defined $i) {
6279            if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {            if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6280              !!!cp ('t412.1');              !!!cp ('t412.1');
6281              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token);
6282            } else {            } else {
6283              !!!cp ('t414.1');              !!!cp ('t414.1');
6284            }            }
# Line 6169  sub _tree_construction_main ($) { Line 6286  sub _tree_construction_main ($) {
6286            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
6287          } else {          } else {
6288            !!!cp ('t413.1');            !!!cp ('t413.1');
6289            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
6290    
6291            !!!cp ('t415.1');            !!!cp ('t415.1');
6292            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
# Line 6188  sub _tree_construction_main ($) { Line 6305  sub _tree_construction_main ($) {
6305                  strong => 1, tt => 1, u => 1,                  strong => 1, tt => 1, u => 1,
6306                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6307          !!!cp ('t427');          !!!cp ('t427');
6308          $formatting_end_tag->($token->{tag_name});          $formatting_end_tag->($token);
6309          redo B;          redo B;
6310        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
6311          !!!cp ('t428');          !!!cp ('t428');
6312          !!!parse-error (type => 'unmatched end tag:br');          !!!parse-error (type => 'unmatched end tag:br', token => $token);
6313    
6314          ## As if <br>          ## As if <br>
6315          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
# Line 6217  sub _tree_construction_main ($) { Line 6334  sub _tree_construction_main ($) {
6334                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
6335                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6336          !!!cp ('t429');          !!!cp ('t429');
6337          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
6338          ## Ignore the token          ## Ignore the token
6339          !!!next-token;          !!!next-token;
6340          redo B;          redo B;
# Line 6246  sub _tree_construction_main ($) { Line 6363  sub _tree_construction_main ($) {
6363              if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) {              if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) {
6364                !!!cp ('t431');                !!!cp ('t431');
6365                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
6366                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token);
6367              } else {              } else {
6368                !!!cp ('t432');                !!!cp ('t432');
6369              }              }
# Line 6263  sub _tree_construction_main ($) { Line 6380  sub _tree_construction_main ($) {
6380                  ($special_category->{$node->[1]} or                  ($special_category->{$node->[1]} or
6381                   $scoping_category->{$node->[1]})) {                   $scoping_category->{$node->[1]})) {
6382                !!!cp ('t433');                !!!cp ('t433');
6383                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
6384                ## Ignore the token                ## Ignore the token
6385                !!!next-token;                !!!next-token;
6386                last S2;                last S2;

Legend:
Removed from v.1.98  
changed lines
  Added in v.1.113

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24