/[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.103 by wakaba, Sun Mar 9 07:57:29 2008 UTC revision 1.112 by wakaba, Sun Mar 16 06:39:57 2008 UTC
# 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 449  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 465  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 473  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 492  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 512  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 520  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 530  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 545  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 553  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});
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 571  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 590  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 603  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 611  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 620  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 636  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 1379  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 1387  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 1395  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 1410  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 1418  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 1454  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 1482  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 1660  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 1669  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 2205  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 2245  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 2254  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 2297  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 2371  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 3293  sub _tree_construction_main ($) { Line 3343  sub _tree_construction_main ($) {
3343        ## Stay in the phase        ## Stay in the phase
3344        !!!next-token;        !!!next-token;
3345        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;  
3346      } elsif ($token->{type} == START_TAG_TOKEN and      } elsif ($token->{type} == START_TAG_TOKEN and
3347               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
3348        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
# Line 3843  sub _tree_construction_main ($) { Line 3861  sub _tree_construction_main ($) {
3861              $self->{insertion_mode} = IN_BODY_IM;              $self->{insertion_mode} = IN_BODY_IM;
3862              ## reprocess              ## reprocess
3863              redo B;              redo B;
3864            } else {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
3865              die "$0: $token->{type}: Unknown token type";          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3866            }            !!!cp ('t149.1');
3867    
3868              ## NOTE: As if <head>
3869              !!!create-element ($self->{head_element}, 'head');
3870              $self->{open_elements}->[-1]->[0]->append_child
3871                  ($self->{head_element});
3872              #push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3873              #$self->{insertion_mode} = IN_HEAD_IM;
3874              ## NOTE: Reprocess.
3875    
3876              ## NOTE: As if </head>
3877              #pop @{$self->{open_elements}};
3878              #$self->{insertion_mode} = IN_AFTER_HEAD_IM;
3879              ## NOTE: Reprocess.
3880              
3881              #
3882            } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3883              !!!cp ('t149.2');
3884    
3885              ## NOTE: As if </head>
3886              pop @{$self->{open_elements}};
3887              #$self->{insertion_mode} = IN_AFTER_HEAD_IM;
3888              ## NOTE: Reprocess.
3889    
3890              #
3891            } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3892              !!!cp ('t149.3');
3893    
3894              !!!parse-error (type => 'in noscript:#eof');
3895    
3896              ## As if </noscript>
3897              pop @{$self->{open_elements}};
3898              #$self->{insertion_mode} = IN_HEAD_IM;
3899              ## NOTE: Reprocess.
3900    
3901              ## NOTE: As if </head>
3902              pop @{$self->{open_elements}};
3903              #$self->{insertion_mode} = IN_AFTER_HEAD_IM;
3904              ## NOTE: Reprocess.
3905    
3906              #
3907            } else {
3908              !!!cp ('t149.4');
3909              #
3910            }
3911    
3912            ## NOTE: As if <body>
3913            !!!insert-element ('body');
3914            $self->{insertion_mode} = IN_BODY_IM;
3915            ## NOTE: Reprocess.
3916            redo B;
3917          } else {
3918            die "$0: $token->{type}: Unknown token type";
3919          }
3920    
3921            ## ISSUE: An issue in the spec.            ## ISSUE: An issue in the spec.
3922      } elsif ($self->{insertion_mode} & BODY_IMS) {      } elsif ($self->{insertion_mode} & BODY_IMS) {
# Line 3865  sub _tree_construction_main ($) { Line 3936  sub _tree_construction_main ($) {
3936                  }->{$token->{tag_name}}) {                  }->{$token->{tag_name}}) {
3937                if ($self->{insertion_mode} == IN_CELL_IM) {                if ($self->{insertion_mode} == IN_CELL_IM) {
3938                  ## have an element in table scope                  ## have an element in table scope
3939                  my $tn;                  for (reverse 0..$#{$self->{open_elements}}) {
                 INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
3940                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
3941                    if ($node->[1] eq 'td' or $node->[1] eq 'th') {                    if ($node->[1] eq 'td' or $node->[1] eq 'th') {
3942                      !!!cp ('t151');                      !!!cp ('t151');
3943                      $tn = $node->[1];  
3944                      last INSCOPE;                      ## Close the cell
3945                        !!!back-token; # <?>
3946                        $token = {type => END_TAG_TOKEN, tag_name => $node->[1]};
3947                        redo B;
3948                    } elsif ({                    } elsif ({
3949                              table => 1, html => 1,                              table => 1, html => 1,
3950                             }->{$node->[1]}) {                             }->{$node->[1]}) {
3951                      !!!cp ('t152');                      !!!cp ('t152');
3952                      last INSCOPE;                      ## ISSUE: This case can never be reached, maybe.
3953                    }                      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;  
3954                    }                    }
3955                                    }
3956                  !!!cp ('t154');  
3957                  ## Close the cell                  !!!cp ('t153');
3958                  !!!back-token; # <?>                  !!!parse-error (type => 'start tag not allowed',
3959                  $token = {type => END_TAG_TOKEN, tag_name => $tn};                      value => $token->{tag_name});
3960                    ## Ignore the token
3961                    !!!next-token;
3962                  redo B;                  redo B;
3963                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
3964                  !!!parse-error (type => 'not closed:caption');                  !!!parse-error (type => 'not closed:caption');
3965                                    
3966                  ## As if </caption>                  ## NOTE: As if </caption>.
3967                  ## have a table element in table scope                  ## have a table element in table scope
3968                  my $i;                  my $i;
3969                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: {
3970                    my $node = $self->{open_elements}->[$_];                    for (reverse 0..$#{$self->{open_elements}}) {
3971                    if ($node->[1] eq 'caption') {                      my $node = $self->{open_elements}->[$_];
3972                      !!!cp ('t155');                      if ($node->[1] eq 'caption') {
3973                      $i = $_;                        !!!cp ('t155');
3974                      last INSCOPE;                        $i = $_;
3975                    } elsif ({                        last INSCOPE;
3976                              table => 1, html => 1,                      } elsif ({
3977                             }->{$node->[1]}) {                                table => 1, html => 1,
3978                      !!!cp ('t156');                               }->{$node->[1]}) {
3979                      last INSCOPE;                        !!!cp ('t156');
3980                          last;
3981                        }
3982                    }                    }
3983    
3984                      !!!cp ('t157');
3985                      !!!parse-error (type => 'start tag not allowed',
3986                                      value => $token->{tag_name});
3987                      ## Ignore the token
3988                      !!!next-token;
3989                      redo B;
3990                  } # 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;  
                   }  
3991                                    
3992                  ## generate implied end tags                  ## generate implied end tags
3993                  while ({                  while ({
# Line 4015  sub _tree_construction_main ($) { Line 4083  sub _tree_construction_main ($) {
4083                if ($self->{insertion_mode} == IN_CAPTION_IM) {                if ($self->{insertion_mode} == IN_CAPTION_IM) {
4084                  ## have a table element in table scope                  ## have a table element in table scope
4085                  my $i;                  my $i;
4086                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: {
4087                    my $node = $self->{open_elements}->[$_];                    for (reverse 0..$#{$self->{open_elements}}) {
4088                    if ($node->[1] eq $token->{tag_name}) {                      my $node = $self->{open_elements}->[$_];
4089                      !!!cp ('t171');                      if ($node->[1] eq $token->{tag_name}) {
4090                      $i = $_;                        !!!cp ('t171');
4091                      last INSCOPE;                        $i = $_;
4092                    } elsif ({                        last INSCOPE;
4093                              table => 1, html => 1,                      } elsif ({
4094                             }->{$node->[1]}) {                                table => 1, html => 1,
4095                      !!!cp ('t172');                               }->{$node->[1]}) {
4096                      last INSCOPE;                        !!!cp ('t172');
4097                          last;
4098                        }
4099                    }                    }
4100    
4101                      !!!cp ('t173');
4102                      !!!parse-error (type => 'unmatched end tag',
4103                                      value => $token->{tag_name});
4104                      ## Ignore the token
4105                      !!!next-token;
4106                      redo B;
4107                  } # INSCOPE                  } # INSCOPE
                   unless (defined $i) {  
                     !!!cp ('t173');  
                     !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
                     ## Ignore the token  
                     !!!next-token;  
                     redo B;  
                   }  
4108                                    
4109                  ## generate implied end tags                  ## generate implied end tags
4110                  while ({                  while ({
# Line 4077  sub _tree_construction_main ($) { Line 4147  sub _tree_construction_main ($) {
4147                ## have an element in table scope                ## have an element in table scope
4148                my $i;                my $i;
4149                my $tn;                my $tn;
4150                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: {
4151                  my $node = $self->{open_elements}->[$_];                  for (reverse 0..$#{$self->{open_elements}}) {
4152                  if ($node->[1] eq $token->{tag_name}) {                    my $node = $self->{open_elements}->[$_];
4153                    !!!cp ('t179');                    if ($node->[1] eq $token->{tag_name}) {
4154                    $i = $_;                      !!!cp ('t179');
4155                    last INSCOPE;                      $i = $_;
4156                  } elsif ($node->[1] eq 'td' or $node->[1] eq 'th') {  
4157                    !!!cp ('t180');                      ## Close the cell
4158                    $tn = $node->[1];                      !!!back-token; # </?>
4159                    ## NOTE: There is exactly one |td| or |th| element                      $token = {type => END_TAG_TOKEN, tag_name => $tn};
4160                    ## in scope in the stack of open elements by definition.                      redo B;
4161                  } elsif ({                    } elsif ($node->[1] eq 'td' or $node->[1] eq 'th') {
4162                            table => 1, html => 1,                      !!!cp ('t180');
4163                           }->{$node->[1]}) {                      $tn = $node->[1];
4164                    !!!cp ('t181');                      ## NOTE: There is exactly one |td| or |th| element
4165                    last INSCOPE;                      ## in scope in the stack of open elements by definition.
4166                      } elsif ({
4167                                table => 1, html => 1,
4168                               }->{$node->[1]}) {
4169                        ## ISSUE: Can this be reached?
4170                        !!!cp ('t181');
4171                        last;
4172                      }
4173                  }                  }
4174                } # INSCOPE  
               unless (defined $i) {  
4175                  !!!cp ('t182');                  !!!cp ('t182');
4176                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag',
4177                        value => $token->{tag_name});
4178                  ## Ignore the token                  ## Ignore the token
4179                  !!!next-token;                  !!!next-token;
4180                  redo B;                  redo B;
4181                } else {                } # INSCOPE
                 !!!cp ('t183');  
               }  
   
               ## Close the cell  
               !!!back-token; # </?>  
               $token = {type => END_TAG_TOKEN, tag_name => $tn};  
               redo B;  
4182              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
4183                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
4184                !!!parse-error (type => 'not closed:caption');                !!!parse-error (type => 'not closed:caption');
# Line 4187  sub _tree_construction_main ($) { Line 4257  sub _tree_construction_main ($) {
4257                !!!cp ('t193');                !!!cp ('t193');
4258                #                #
4259              }              }
4260          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
4261            for my $entry (@{$self->{open_elements}}) {
4262              if (not {
4263                dd => 1, dt => 1, li => 1, p => 1, tbody => 1, td => 1, tfoot => 1,
4264                th => 1, thead => 1, tr => 1, body => 1, html => 1,
4265              }->{$entry->[1]}) {
4266                !!!cp ('t75');
4267                !!!parse-error (type => 'in body:#eof');
4268                last;
4269              }
4270            }
4271    
4272            ## Stop parsing.
4273            last B;
4274        } else {        } else {
4275          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
4276        }        }
# Line 4500  sub _tree_construction_main ($) { Line 4584  sub _tree_construction_main ($) {
4584                  redo B;                  redo B;
4585                }                }
4586                                
4587    ## TODO: Followings are removed from the latest spec.
4588                ## generate implied end tags                ## generate implied end tags
4589                while ({                while ({
4590                        dd => 1, dt => 1, li => 1, p => 1,                        dd => 1, dt => 1, li => 1, p => 1,
# Line 4863  sub _tree_construction_main ($) { Line 4948  sub _tree_construction_main ($) {
4948            $insert = $insert_to_foster;            $insert = $insert_to_foster;
4949            #            #
4950          }          }
4951          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
4952            unless ($self->{open_elements}->[-1]->[1] eq 'html' and
4953                    @{$self->{open_elements}} == 1) { # redundant, maybe
4954              !!!parse-error (type => 'in body:#eof');
4955              !!!cp ('t259.1');
4956              #
4957            } else {
4958              !!!cp ('t259.2');
4959              #
4960            }
4961    
4962            ## Stop parsing
4963            last B;
4964        } else {        } else {
4965          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
4966        }        }
# Line 4915  sub _tree_construction_main ($) { Line 5013  sub _tree_construction_main ($) {
5013                !!!cp ('t267');                !!!cp ('t267');
5014                #                #
5015              }              }
5016            } else {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
5017              die "$0: $token->{type}: Unknown token type";          if ($self->{open_elements}->[-1]->[1] eq 'html' or
5018            }              @{$self->{open_elements}} == 1) { # redundant, maybe
5019              !!!cp ('t270.2');
5020              ## Stop parsing.
5021              last B;
5022            } else {
5023              ## NOTE: As if </colgroup>.
5024              !!!cp ('t270.1');
5025              pop @{$self->{open_elements}}; # colgroup
5026              $self->{insertion_mode} = IN_TABLE_IM;
5027              ## Reprocess.
5028              redo B;
5029            }
5030          } else {
5031            die "$0: $token->{type}: Unknown token type";
5032          }
5033    
5034            ## As if </colgroup>            ## As if </colgroup>
5035            if ($self->{open_elements}->[-1]->[1] eq 'html') {            if ($self->{open_elements}->[-1]->[1] eq 'html') {
5036              !!!cp ('t269');              !!!cp ('t269');
5037    ## TODO: Wrong error type?
5038              !!!parse-error (type => 'unmatched end tag:colgroup');              !!!parse-error (type => 'unmatched end tag:colgroup');
5039              ## Ignore the token              ## Ignore the token
5040              !!!next-token;              !!!next-token;
# Line 5157  sub _tree_construction_main ($) { Line 5270  sub _tree_construction_main ($) {
5270            !!!next-token;            !!!next-token;
5271            redo B;            redo B;
5272          }          }
5273          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
5274            unless ($self->{open_elements}->[-1]->[1] eq 'html' and
5275                    @{$self->{open_elements}} == 1) { # redundant, maybe
5276              !!!cp ('t299.1');
5277              !!!parse-error (type => 'in body:#eof');
5278            } else {
5279              !!!cp ('t299.2');
5280            }
5281    
5282            ## Stop parsing.
5283            last B;
5284        } else {        } else {
5285          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
5286        }        }
# Line 5240  sub _tree_construction_main ($) { Line 5364  sub _tree_construction_main ($) {
5364            ## reprocess            ## reprocess
5365            redo B;            redo B;
5366          }          }
5367          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
5368            !!!cp ('t309.2');
5369            ## Stop parsing
5370            last B;
5371        } else {        } else {
5372          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
5373        }        }
# Line 5375  sub _tree_construction_main ($) { Line 5503  sub _tree_construction_main ($) {
5503            !!!next-token;            !!!next-token;
5504            redo B;            redo B;
5505          }          }
5506          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
5507            unless ($self->{open_elements}->[-1]->[1] eq 'html' and
5508                    @{$self->{open_elements}} == 1) { # redundant, maybe
5509              !!!cp ('t331.1');
5510              !!!parse-error (type => 'in body:#eof');
5511            } else {
5512              !!!cp ('t331.2');
5513            }
5514            
5515            ## Stop parsing
5516            last B;
5517        } else {        } else {
5518          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
5519        }        }
# Line 5486  sub _tree_construction_main ($) { Line 5625  sub _tree_construction_main ($) {
5625                  h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,                  h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
5626                  menu => 1, ol => 1, p => 1, ul => 1,                  menu => 1, ol => 1, p => 1, ul => 1,
5627                  pre => 1, listing => 1,                  pre => 1, listing => 1,
5628                    form => 1,
5629                    table => 1,
5630                    hr => 1,
5631                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5632            if ($token->{tag_name} eq 'form' and defined $self->{form_element}) {
5633              !!!cp ('t350');
5634              !!!parse-error (type => 'in form:form');
5635              ## Ignore the token
5636              !!!next-token;
5637              redo B;
5638            }
5639    
5640          ## has a p element in scope          ## has a p element in scope
5641          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5642            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
# Line 5517  sub _tree_construction_main ($) { Line 5667  sub _tree_construction_main ($) {
5667            } else {            } else {
5668              !!!cp ('t348');              !!!cp ('t348');
5669            }            }
5670          } else {          } elsif ($token->{tag_name} eq 'form') {
5671            !!!cp ('t347');            !!!cp ('t347.1');
5672              $self->{form_element} = $self->{open_elements}->[-1]->[0];
5673    
5674            !!!next-token;            !!!next-token;
5675          }          } elsif ($token->{tag_name} eq 'table') {
5676          redo B;            !!!cp ('t382');
5677        } elsif ($token->{tag_name} eq 'form') {            push @{$open_tables}, [$self->{open_elements}->[-1]->[0]];
5678          if (defined $self->{form_element}) {            
5679            !!!cp ('t350');            $self->{insertion_mode} = IN_TABLE_IM;
5680            !!!parse-error (type => 'in form:form');  
5681            ## Ignore the token            !!!next-token;
5682            } elsif ($token->{tag_name} eq 'hr') {
5683              !!!cp ('t386');
5684              pop @{$self->{open_elements}};
5685            
5686            !!!next-token;            !!!next-token;
           redo B;  
5687          } else {          } else {
5688            ## 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 ({  
                       applet => 1, 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];  
5689            !!!next-token;            !!!next-token;
           redo B;  
5690          }          }
5691        } elsif ($token->{tag_name} eq 'li') {          redo B;
5692          } elsif ({li => 1, dt => 1, dd => 1}->{$token->{tag_name}}) {
5693          ## has a p element in scope          ## has a p element in scope
5694          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5695            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
# Line 5571  sub _tree_construction_main ($) { Line 5709  sub _tree_construction_main ($) {
5709          ## Step 1          ## Step 1
5710          my $i = -1;          my $i = -1;
5711          my $node = $self->{open_elements}->[$i];          my $node = $self->{open_elements}->[$i];
5712            my $li_or_dtdd = {li => {li => 1},
5713                              dt => {dt => 1, dd => 1},
5714                              dd => {dt => 1, dd => 1}}->{$token->{tag_name}};
5715          LI: {          LI: {
5716            ## Step 2            ## Step 2
5717            if ($node->[1] eq 'li') {            if ($li_or_dtdd->{$node->[1]}) {
5718              if ($i != -1) {              if ($i != -1) {
5719                !!!cp ('t355');                !!!cp ('t355');
5720                !!!parse-error (type => 'end tag missing:'.                !!!parse-error (type => 'end tag missing:'.
# Line 5607  sub _tree_construction_main ($) { Line 5748  sub _tree_construction_main ($) {
5748          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5749          !!!next-token;          !!!next-token;
5750          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 ({  
                     applet => 1, 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;  
5751        } elsif ($token->{tag_name} eq 'plaintext') {        } elsif ($token->{tag_name} eq 'plaintext') {
5752          ## has a p element in scope          ## has a p element in scope
5753          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
# Line 5725  sub _tree_construction_main ($) { Line 5810  sub _tree_construction_main ($) {
5810    
5811          !!!next-token;          !!!next-token;
5812          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;  
5813        } elsif ($token->{tag_name} eq 'nobr') {        } elsif ($token->{tag_name} eq 'nobr') {
5814          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5815    
# Line 5794  sub _tree_construction_main ($) { Line 5866  sub _tree_construction_main ($) {
5866          !!!next-token;          !!!next-token;
5867          redo B;          redo B;
5868        } elsif ({        } elsif ({
5869                  applet => 1, marquee => 1, object => 1,                  xmp => 1,
5870                 }->{$token->{tag_name}}) {                  iframe => 1,
5871          !!!cp ('t380');                  noembed => 1,
5872          $reconstruct_active_formatting_elements->($insert_to_current);                  noframes => 1,
5873                            noscript => 0, ## TODO: 1 if scripting is enabled
         !!!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 ({  
                     applet => 1, 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;  
       } elsif ({  
                 area => 1, basefont => 1, bgsound => 1, br => 1,  
                 embed => 1, img => 1, param => 1, spacer => 1, wbr => 1,  
                 image => 1,  
5874                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5875          if ($token->{tag_name} eq 'image') {          if ($token->{tag_name} eq 'xmp') {
5876            !!!cp ('t384');            !!!cp ('t381');
5877            !!!parse-error (type => 'image');            $reconstruct_active_formatting_elements->($insert_to_current);
           $token->{tag_name} = 'img';  
5878          } else {          } else {
5879            !!!cp ('t385');            !!!cp ('t399');
5880          }          }
5881            ## NOTE: There is an "as if in body" code clone.
5882          ## 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 ({  
                     applet => 1, 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;  
5883          redo B;          redo B;
5884        } elsif ($token->{tag_name} eq 'isindex') {        } elsif ($token->{tag_name} eq 'isindex') {
5885          !!!parse-error (type => 'isindex');          !!!parse-error (type => 'isindex');
# Line 5976  sub _tree_construction_main ($) { Line 5971  sub _tree_construction_main ($) {
5971          !!!next-token;          !!!next-token;
5972          redo B;          redo B;
5973        } 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  
           
         if ($self->{insertion_mode} & TABLE_IMS or  
             $self->{insertion_mode} & BODY_TABLE_IMS or  
             $self->{insertion_mode} == IN_COLUMN_GROUP_IM) {  
           !!!cp ('t400.1');  
           $self->{insertion_mode} = IN_SELECT_IN_TABLE_IM;  
         } else {  
           !!!cp ('t400.2');  
           $self->{insertion_mode} = IN_SELECT_IM;  
         }  
         !!!next-token;  
         redo B;  
       } elsif ({  
5974                  caption => 1, col => 1, colgroup => 1, frame => 1,                  caption => 1, col => 1, colgroup => 1, frame => 1,
5975                  frameset => 1, head => 1, option => 1, optgroup => 1,                  frameset => 1, head => 1, option => 1, optgroup => 1,
5976                  tbody => 1, td => 1, tfoot => 1, th => 1,                  tbody => 1, td => 1, tfoot => 1, th => 1,
# Line 6018  sub _tree_construction_main ($) { Line 5984  sub _tree_construction_main ($) {
5984                    
5985          ## ISSUE: An issue on HTML5 new elements in the spec.          ## ISSUE: An issue on HTML5 new elements in the spec.
5986        } else {        } else {
5987          !!!cp ('t402');          if ($token->{tag_name} eq 'image') {
5988              !!!cp ('t384');
5989              !!!parse-error (type => 'image');
5990              $token->{tag_name} = 'img';
5991            } else {
5992              !!!cp ('t385');
5993            }
5994    
5995            ## NOTE: There is an "as if <br>" code clone.
5996          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5997                    
5998          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5999    
6000            if ({
6001                 applet => 1, marquee => 1, object => 1,
6002                }->{$token->{tag_name}}) {
6003              !!!cp ('t380');
6004              push @$active_formatting_elements, ['#marker', ''];
6005            } elsif ({
6006                      b => 1, big => 1, em => 1, font => 1, i => 1,
6007                      s => 1, small => 1, strile => 1,
6008                      strong => 1, tt => 1, u => 1,
6009                     }->{$token->{tag_name}}) {
6010              !!!cp ('t375');
6011              push @$active_formatting_elements, $self->{open_elements}->[-1];
6012            } elsif ($token->{tag_name} eq 'input') {
6013              !!!cp ('t388');
6014              ## TODO: associate with $self->{form_element} if defined
6015              pop @{$self->{open_elements}};
6016            } elsif ({
6017                      area => 1, basefont => 1, bgsound => 1, br => 1,
6018                      embed => 1, img => 1, param => 1, spacer => 1, wbr => 1,
6019                      #image => 1,
6020                     }->{$token->{tag_name}}) {
6021              !!!cp ('t388.1');
6022              pop @{$self->{open_elements}};
6023            } elsif ($token->{tag_name} eq 'select') {
6024              ## TODO: associate with $self->{form_element} if defined
6025            
6026              if ($self->{insertion_mode} & TABLE_IMS or
6027                  $self->{insertion_mode} & BODY_TABLE_IMS or
6028                  $self->{insertion_mode} == IN_COLUMN_GROUP_IM) {
6029                !!!cp ('t400.1');
6030                $self->{insertion_mode} = IN_SELECT_IN_TABLE_IM;
6031              } else {
6032                !!!cp ('t400.2');
6033                $self->{insertion_mode} = IN_SELECT_IM;
6034              }
6035            } else {
6036              !!!cp ('t402');
6037            }
6038                    
6039          !!!next-token;          !!!next-token;
6040          redo B;          redo B;
6041        }        }
6042      } elsif ($token->{type} == END_TAG_TOKEN) {      } elsif ($token->{type} == END_TAG_TOKEN) {
6043        if ($token->{tag_name} eq 'body') {        if ($token->{tag_name} eq 'body') {
6044          if (@{$self->{open_elements}} > 1 and          ## has a |body| element in scope
6045              $self->{open_elements}->[1]->[1] eq 'body') {          my $i;
6046            for (@{$self->{open_elements}}) {          INSCOPE: {
6047              unless ({            for (reverse @{$self->{open_elements}}) {
6048                         dd => 1, dt => 1, li => 1, p => 1, td => 1,              if ($_->[1] eq 'body') {
6049                         th => 1, tr => 1, body => 1, html => 1,                !!!cp ('t405');
6050                       tbody => 1, tfoot => 1, thead => 1,                $i = $_;
6051                      }->{$_->[1]}) {                last INSCOPE;
6052                !!!cp ('t403');              } elsif ({
6053                !!!parse-error (type => 'not closed:'.$_->[1]);                        applet => 1, table => 1, caption => 1, td => 1, th => 1,
6054              } else {                        button => 1, marquee => 1, object => 1, html => 1,
6055                !!!cp ('t404');                       }->{$_->[1]}) {
6056                  !!!cp ('t405.1');
6057                  last;
6058              }              }
6059            }            }
6060    
6061            $self->{insertion_mode} = AFTER_BODY_IM;            !!!parse-error (type => 'start tag not allowed',
6062            !!!next-token;                            value => $token->{tag_name});
6063            redo B;            ## NOTE: Ignore the token.
         } else {  
           !!!cp ('t405');  
           !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
           ## Ignore the token  
6064            !!!next-token;            !!!next-token;
6065            redo B;            redo B;
6066            } # INSCOPE
6067    
6068            for (@{$self->{open_elements}}) {
6069              unless ({
6070                       dd => 1, dt => 1, li => 1, p => 1, td => 1,
6071                       th => 1, tr => 1, body => 1, html => 1,
6072                       tbody => 1, tfoot => 1, thead => 1,
6073                      }->{$_->[1]}) {
6074                !!!cp ('t403');
6075                !!!parse-error (type => 'not closed:'.$_->[1]);
6076                last;
6077              } else {
6078                !!!cp ('t404');
6079              }
6080          }          }
6081    
6082            $self->{insertion_mode} = AFTER_BODY_IM;
6083            !!!next-token;
6084            redo B;
6085        } elsif ($token->{tag_name} eq 'html') {        } elsif ($token->{tag_name} eq 'html') {
6086          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') {
6087            ## ISSUE: There is an issue in the spec.            ## ISSUE: There is an issue in the spec.

Legend:
Removed from v.1.103  
changed lines
  Added in v.1.112

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24