/[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.73 by wakaba, Sun Mar 2 23:38:37 2008 UTC revision 1.102 by wakaba, Sun Mar 9 06:29:25 2008 UTC
# Line 179  sub parse_string ($$$;$) { Line 179  sub parse_string ($$$;$) {
179    my $i = 0;    my $i = 0;
180    my $line = 1;    my $line = 1;
181    my $column = 0;    my $column = 0;
182    $self->{set_next_input_character} = sub {    $self->{set_next_char} = sub {
183      my $self = shift;      my $self = shift;
184    
185      pop @{$self->{prev_input_character}};      pop @{$self->{prev_char}};
186      unshift @{$self->{prev_input_character}}, $self->{next_input_character};      unshift @{$self->{prev_char}}, $self->{next_char};
187    
188      $self->{next_input_character} = -1 and return if $i >= length $$s;      $self->{next_char} = -1 and return if $i >= length $$s;
189      $self->{next_input_character} = ord substr $$s, $i++, 1;      $self->{next_char} = ord substr $$s, $i++, 1;
190      $column++;      $column++;
191            
192      if ($self->{next_input_character} == 0x000A) { # LF      if ($self->{next_char} == 0x000A) { # LF
193        $line++;        $line++;
194        $column = 0;        $column = 0;
195      } elsif ($self->{next_input_character} == 0x000D) { # CR      } elsif ($self->{next_char} == 0x000D) { # CR
196        $i++ if substr ($$s, $i, 1) eq "\x0A";        $i++ if substr ($$s, $i, 1) eq "\x0A";
197        $self->{next_input_character} = 0x000A; # LF # MUST        $self->{next_char} = 0x000A; # LF # MUST
198        $line++;        $line++;
199        $column = 0;        $column = 0;
200      } elsif ($self->{next_input_character} > 0x10FFFF) {      } elsif ($self->{next_char} > 0x10FFFF) {
201        $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
202      } elsif ($self->{next_input_character} == 0x0000) { # NULL      } elsif ($self->{next_char} == 0x0000) { # NULL
203        !!!parse-error (type => 'NULL');        !!!parse-error (type => 'NULL');
204        $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
205      }      }
206    };    };
207    $self->{prev_input_character} = [-1, -1, -1];    $self->{prev_char} = [-1, -1, -1];
208    $self->{next_input_character} = -1;    $self->{next_char} = -1;
209    
210    my $onerror = $_[2] || sub {    my $onerror = $_[2] || sub {
211      my (%opt) = @_;      my (%opt) = @_;
# Line 226  sub parse_string ($$$;$) { Line 226  sub parse_string ($$$;$) {
226  sub new ($) {  sub new ($) {
227    my $class = shift;    my $class = shift;
228    my $self = bless {}, $class;    my $self = bless {}, $class;
229    $self->{set_next_input_character} = sub {    $self->{set_next_char} = sub {
230      $self->{next_input_character} = -1;      $self->{next_char} = -1;
231    };    };
232    $self->{parse_error} = sub {    $self->{parse_error} = sub {
233      #      #
# Line 303  sub TABLE_IMS ()      { 0b1000000 } Line 303  sub TABLE_IMS ()      { 0b1000000 }
303  sub ROW_IMS ()        { 0b10000000 }  sub ROW_IMS ()        { 0b10000000 }
304  sub BODY_AFTER_IMS () { 0b100000000 }  sub BODY_AFTER_IMS () { 0b100000000 }
305  sub FRAME_IMS ()      { 0b1000000000 }  sub FRAME_IMS ()      { 0b1000000000 }
306    sub SELECT_IMS ()     { 0b10000000000 }
307    
308    ## NOTE: "initial" and "before html" insertion modes have no constants.
309    
310    ## NOTE: "after after body" insertion mode.
311  sub AFTER_HTML_BODY_IM () { AFTER_HTML_IMS | BODY_AFTER_IMS }  sub AFTER_HTML_BODY_IM () { AFTER_HTML_IMS | BODY_AFTER_IMS }
312    
313    ## NOTE: "after after frameset" insertion mode.
314  sub AFTER_HTML_FRAMESET_IM () { AFTER_HTML_IMS | FRAME_IMS }  sub AFTER_HTML_FRAMESET_IM () { AFTER_HTML_IMS | FRAME_IMS }
315    
316  sub IN_HEAD_IM () { HEAD_IMS | 0b00 }  sub IN_HEAD_IM () { HEAD_IMS | 0b00 }
317  sub IN_HEAD_NOSCRIPT_IM () { HEAD_IMS | 0b01 }  sub IN_HEAD_NOSCRIPT_IM () { HEAD_IMS | 0b01 }
318  sub AFTER_HEAD_IM () { HEAD_IMS | 0b10 }  sub AFTER_HEAD_IM () { HEAD_IMS | 0b10 }
# Line 319  sub IN_TABLE_IM () { TABLE_IMS } Line 326  sub IN_TABLE_IM () { TABLE_IMS }
326  sub AFTER_BODY_IM () { BODY_AFTER_IMS }  sub AFTER_BODY_IM () { BODY_AFTER_IMS }
327  sub IN_FRAMESET_IM () { FRAME_IMS | 0b01 }  sub IN_FRAMESET_IM () { FRAME_IMS | 0b01 }
328  sub AFTER_FRAMESET_IM () { FRAME_IMS | 0b10 }  sub AFTER_FRAMESET_IM () { FRAME_IMS | 0b10 }
329  sub IN_SELECT_IM () { 0b01 }  sub IN_SELECT_IM () { SELECT_IMS | 0b01 }
330    sub IN_SELECT_IN_TABLE_IM () { SELECT_IMS | 0b10 }
331  sub IN_COLUMN_GROUP_IM () { 0b10 }  sub IN_COLUMN_GROUP_IM () { 0b10 }
332    
333  ## Implementations MUST act as if state machine in the spec  ## Implementations MUST act as if state machine in the spec
# Line 333  sub _initialize_tokenizer ($) { Line 341  sub _initialize_tokenizer ($) {
341    undef $self->{last_emitted_start_tag_name};    undef $self->{last_emitted_start_tag_name};
342    undef $self->{last_attribute_value_state};    undef $self->{last_attribute_value_state};
343    $self->{char} = [];    $self->{char} = [];
344    # $self->{next_input_character}    # $self->{next_char}
345    !!!next-input-character;    !!!next-input-character;
346    $self->{token} = [];    $self->{token} = [];
347    # $self->{escape}    # $self->{escape}
# Line 346  sub _initialize_tokenizer ($) { Line 354  sub _initialize_tokenizer ($) {
354  ##   ->{tag_name} (START_TAG_TOKEN, END_TAG_TOKEN)  ##   ->{tag_name} (START_TAG_TOKEN, END_TAG_TOKEN)
355  ##   ->{public_identifier} (DOCTYPE_TOKEN)  ##   ->{public_identifier} (DOCTYPE_TOKEN)
356  ##   ->{system_identifier} (DOCTYPE_TOKEN)  ##   ->{system_identifier} (DOCTYPE_TOKEN)
357  ##   ->{correct} == 1 or 0 (DOCTYPE_TOKEN)  ##   ->{quirks} == 1 or 0 (DOCTYPE_TOKEN): "force-quirks" flag
358  ##   ->{attributes} isa HASH (START_TAG_TOKEN, END_TAG_TOKEN)  ##   ->{attributes} isa HASH (START_TAG_TOKEN, END_TAG_TOKEN)
359  ##        ->{name}  ##        ->{name}
360  ##        ->{value}  ##        ->{value}
# Line 384  sub _get_next_token ($) { Line 392  sub _get_next_token ($) {
392    
393    A: {    A: {
394      if ($self->{state} == DATA_STATE) {      if ($self->{state} == DATA_STATE) {
395        if ($self->{next_input_character} == 0x0026) { # &        if ($self->{next_char} == 0x0026) { # &
396          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA
397              not $self->{escape}) {              not $self->{escape}) {
398              !!!cp (1);
399            $self->{state} = ENTITY_DATA_STATE;            $self->{state} = ENTITY_DATA_STATE;
400            !!!next-input-character;            !!!next-input-character;
401            redo A;            redo A;
402          } else {          } else {
403              !!!cp (2);
404            #            #
405          }          }
406        } elsif ($self->{next_input_character} == 0x002D) { # -        } elsif ($self->{next_char} == 0x002D) { # -
407          if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA          if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
408            unless ($self->{escape}) {            unless ($self->{escape}) {
409              if ($self->{prev_input_character}->[0] == 0x002D and # -              if ($self->{prev_char}->[0] == 0x002D and # -
410                  $self->{prev_input_character}->[1] == 0x0021 and # !                  $self->{prev_char}->[1] == 0x0021 and # !
411                  $self->{prev_input_character}->[2] == 0x003C) { # <                  $self->{prev_char}->[2] == 0x003C) { # <
412                  !!!cp (3);
413                $self->{escape} = 1;                $self->{escape} = 1;
414                } else {
415                  !!!cp (4);
416              }              }
417              } else {
418                !!!cp (5);
419            }            }
420          }          }
421                    
422          #          #
423        } elsif ($self->{next_input_character} == 0x003C) { # <        } elsif ($self->{next_char} == 0x003C) { # <
424          if ($self->{content_model} & CM_FULL_MARKUP or # PCDATA          if ($self->{content_model} & CM_FULL_MARKUP or # PCDATA
425              (($self->{content_model} & CM_LIMITED_MARKUP) and # CDATA | RCDATA              (($self->{content_model} & CM_LIMITED_MARKUP) and # CDATA | RCDATA
426               not $self->{escape})) {               not $self->{escape})) {
427              !!!cp (6);
428            $self->{state} = TAG_OPEN_STATE;            $self->{state} = TAG_OPEN_STATE;
429            !!!next-input-character;            !!!next-input-character;
430            redo A;            redo A;
431          } else {          } else {
432              !!!cp (7);
433            #            #
434          }          }
435        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
436          if ($self->{escape} and          if ($self->{escape} and
437              ($self->{content_model} & CM_LIMITED_MARKUP)) { # RCDATA | CDATA              ($self->{content_model} & CM_LIMITED_MARKUP)) { # RCDATA | CDATA
438            if ($self->{prev_input_character}->[0] == 0x002D and # -            if ($self->{prev_char}->[0] == 0x002D and # -
439                $self->{prev_input_character}->[1] == 0x002D) { # -                $self->{prev_char}->[1] == 0x002D) { # -
440                !!!cp (8);
441              delete $self->{escape};              delete $self->{escape};
442              } else {
443                !!!cp (9);
444            }            }
445            } else {
446              !!!cp (10);
447          }          }
448                    
449          #          #
450        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
451            !!!cp (11);
452          !!!emit ({type => END_OF_FILE_TOKEN});          !!!emit ({type => END_OF_FILE_TOKEN});
453          last A; ## TODO: ok?          last A; ## TODO: ok?
454          } else {
455            !!!cp (12);
456        }        }
457        # Anything else        # Anything else
458        my $token = {type => CHARACTER_TOKEN,        my $token = {type => CHARACTER_TOKEN,
459                     data => chr $self->{next_input_character}};                     data => chr $self->{next_char}};
460        ## Stay in the data state        ## Stay in the data state
461        !!!next-input-character;        !!!next-input-character;
462    
# Line 447  sub _get_next_token ($) { Line 472  sub _get_next_token ($) {
472        # next-input-character is already done        # next-input-character is already done
473    
474        unless (defined $token) {        unless (defined $token) {
475            !!!cp (13);
476          !!!emit ({type => CHARACTER_TOKEN, data => '&'});          !!!emit ({type => CHARACTER_TOKEN, data => '&'});
477        } else {        } else {
478            !!!cp (14);
479          !!!emit ($token);          !!!emit ($token);
480        }        }
481    
482        redo A;        redo A;
483      } elsif ($self->{state} == TAG_OPEN_STATE) {      } elsif ($self->{state} == TAG_OPEN_STATE) {
484        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
485          if ($self->{next_input_character} == 0x002F) { # /          if ($self->{next_char} == 0x002F) { # /
486              !!!cp (15);
487            !!!next-input-character;            !!!next-input-character;
488            $self->{state} = CLOSE_TAG_OPEN_STATE;            $self->{state} = CLOSE_TAG_OPEN_STATE;
489            redo A;            redo A;
490          } else {          } else {
491              !!!cp (16);
492            ## reconsume            ## reconsume
493            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
494    
# Line 468  sub _get_next_token ($) { Line 497  sub _get_next_token ($) {
497            redo A;            redo A;
498          }          }
499        } elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA        } elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA
500          if ($self->{next_input_character} == 0x0021) { # !          if ($self->{next_char} == 0x0021) { # !
501              !!!cp (17);
502            $self->{state} = MARKUP_DECLARATION_OPEN_STATE;            $self->{state} = MARKUP_DECLARATION_OPEN_STATE;
503            !!!next-input-character;            !!!next-input-character;
504            redo A;            redo A;
505          } elsif ($self->{next_input_character} == 0x002F) { # /          } elsif ($self->{next_char} == 0x002F) { # /
506              !!!cp (18);
507            $self->{state} = CLOSE_TAG_OPEN_STATE;            $self->{state} = CLOSE_TAG_OPEN_STATE;
508            !!!next-input-character;            !!!next-input-character;
509            redo A;            redo A;
510          } elsif (0x0041 <= $self->{next_input_character} and          } elsif (0x0041 <= $self->{next_char} and
511                   $self->{next_input_character} <= 0x005A) { # A..Z                   $self->{next_char} <= 0x005A) { # A..Z
512              !!!cp (19);
513            $self->{current_token}            $self->{current_token}
514              = {type => START_TAG_TOKEN,              = {type => START_TAG_TOKEN,
515                 tag_name => chr ($self->{next_input_character} + 0x0020)};                 tag_name => chr ($self->{next_char} + 0x0020)};
516            $self->{state} = TAG_NAME_STATE;            $self->{state} = TAG_NAME_STATE;
517            !!!next-input-character;            !!!next-input-character;
518            redo A;            redo A;
519          } elsif (0x0061 <= $self->{next_input_character} and          } elsif (0x0061 <= $self->{next_char} and
520                   $self->{next_input_character} <= 0x007A) { # a..z                   $self->{next_char} <= 0x007A) { # a..z
521              !!!cp (20);
522            $self->{current_token} = {type => START_TAG_TOKEN,            $self->{current_token} = {type => START_TAG_TOKEN,
523                              tag_name => chr ($self->{next_input_character})};                              tag_name => chr ($self->{next_char})};
524            $self->{state} = TAG_NAME_STATE;            $self->{state} = TAG_NAME_STATE;
525            !!!next-input-character;            !!!next-input-character;
526            redo A;            redo A;
527          } elsif ($self->{next_input_character} == 0x003E) { # >          } elsif ($self->{next_char} == 0x003E) { # >
528              !!!cp (21);
529            !!!parse-error (type => 'empty start tag');            !!!parse-error (type => 'empty start tag');
530            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
531            !!!next-input-character;            !!!next-input-character;
# Line 499  sub _get_next_token ($) { Line 533  sub _get_next_token ($) {
533            !!!emit ({type => CHARACTER_TOKEN, data => '<>'});            !!!emit ({type => CHARACTER_TOKEN, data => '<>'});
534    
535            redo A;            redo A;
536          } elsif ($self->{next_input_character} == 0x003F) { # ?          } elsif ($self->{next_char} == 0x003F) { # ?
537              !!!cp (22);
538            !!!parse-error (type => 'pio');            !!!parse-error (type => 'pio');
539            $self->{state} = BOGUS_COMMENT_STATE;            $self->{state} = BOGUS_COMMENT_STATE;
540            ## $self->{next_input_character} is intentionally left as is            ## $self->{next_char} is intentionally left as is
541            redo A;            redo A;
542          } else {          } else {
543              !!!cp (23);
544            !!!parse-error (type => 'bare stago');            !!!parse-error (type => 'bare stago');
545            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
546            ## reconsume            ## reconsume
# Line 522  sub _get_next_token ($) { Line 558  sub _get_next_token ($) {
558            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>
559            my @next_char;            my @next_char;
560            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++) {
561              push @next_char, $self->{next_input_character};              push @next_char, $self->{next_char};
562              my $c = ord substr ($self->{last_emitted_start_tag_name}, $i, 1);              my $c = ord substr ($self->{last_emitted_start_tag_name}, $i, 1);
563              my $C = 0x0061 <= $c && $c <= 0x007A ? $c - 0x0020 : $c;              my $C = 0x0061 <= $c && $c <= 0x007A ? $c - 0x0020 : $c;
564              if ($self->{next_input_character} == $c or $self->{next_input_character} == $C) {              if ($self->{next_char} == $c or $self->{next_char} == $C) {
565                  !!!cp (24);
566                !!!next-input-character;                !!!next-input-character;
567                next TAGNAME;                next TAGNAME;
568              } else {              } else {
569                $self->{next_input_character} = shift @next_char; # reconsume                !!!cp (25);
570                  $self->{next_char} = shift @next_char; # reconsume
571                !!!back-next-input-character (@next_char);                !!!back-next-input-character (@next_char);
572                $self->{state} = DATA_STATE;                $self->{state} = DATA_STATE;
573    
# Line 538  sub _get_next_token ($) { Line 576  sub _get_next_token ($) {
576                redo A;                redo A;
577              }              }
578            }            }
579            push @next_char, $self->{next_input_character};            push @next_char, $self->{next_char};
580                
581            unless ($self->{next_input_character} == 0x0009 or # HT            unless ($self->{next_char} == 0x0009 or # HT
582                    $self->{next_input_character} == 0x000A or # LF                    $self->{next_char} == 0x000A or # LF
583                    $self->{next_input_character} == 0x000B or # VT                    $self->{next_char} == 0x000B or # VT
584                    $self->{next_input_character} == 0x000C or # FF                    $self->{next_char} == 0x000C or # FF
585                    $self->{next_input_character} == 0x0020 or # SP                    $self->{next_char} == 0x0020 or # SP
586                    $self->{next_input_character} == 0x003E or # >                    $self->{next_char} == 0x003E or # >
587                    $self->{next_input_character} == 0x002F or # /                    $self->{next_char} == 0x002F or # /
588                    $self->{next_input_character} == -1) {                    $self->{next_char} == -1) {
589              $self->{next_input_character} = shift @next_char; # reconsume              !!!cp (26);
590                $self->{next_char} = shift @next_char; # reconsume
591              !!!back-next-input-character (@next_char);              !!!back-next-input-character (@next_char);
592              $self->{state} = DATA_STATE;              $self->{state} = DATA_STATE;
593              !!!emit ({type => CHARACTER_TOKEN, data => '</'});              !!!emit ({type => CHARACTER_TOKEN, data => '</'});
594              redo A;              redo A;
595            } else {            } else {
596              $self->{next_input_character} = shift @next_char;              !!!cp (27);
597                $self->{next_char} = shift @next_char;
598              !!!back-next-input-character (@next_char);              !!!back-next-input-character (@next_char);
599              # and consume...              # and consume...
600            }            }
601          } else {          } else {
602            ## No start tag token has ever been emitted            ## No start tag token has ever been emitted
603              !!!cp (28);
604            # next-input-character is already done            # next-input-character is already done
605            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
606            !!!emit ({type => CHARACTER_TOKEN, data => '</'});            !!!emit ({type => CHARACTER_TOKEN, data => '</'});
# Line 567  sub _get_next_token ($) { Line 608  sub _get_next_token ($) {
608          }          }
609        }        }
610                
611        if (0x0041 <= $self->{next_input_character} and        if (0x0041 <= $self->{next_char} and
612            $self->{next_input_character} <= 0x005A) { # A..Z            $self->{next_char} <= 0x005A) { # A..Z
613            !!!cp (29);
614          $self->{current_token} = {type => END_TAG_TOKEN,          $self->{current_token} = {type => END_TAG_TOKEN,
615                            tag_name => chr ($self->{next_input_character} + 0x0020)};                            tag_name => chr ($self->{next_char} + 0x0020)};
616          $self->{state} = TAG_NAME_STATE;          $self->{state} = TAG_NAME_STATE;
617          !!!next-input-character;          !!!next-input-character;
618          redo A;          redo A;
619        } elsif (0x0061 <= $self->{next_input_character} and        } elsif (0x0061 <= $self->{next_char} and
620                 $self->{next_input_character} <= 0x007A) { # a..z                 $self->{next_char} <= 0x007A) { # a..z
621            !!!cp (30);
622          $self->{current_token} = {type => END_TAG_TOKEN,          $self->{current_token} = {type => END_TAG_TOKEN,
623                            tag_name => chr ($self->{next_input_character})};                            tag_name => chr ($self->{next_char})};
624          $self->{state} = TAG_NAME_STATE;          $self->{state} = TAG_NAME_STATE;
625          !!!next-input-character;          !!!next-input-character;
626          redo A;          redo A;
627        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
628            !!!cp (31);
629          !!!parse-error (type => 'empty end tag');          !!!parse-error (type => 'empty end tag');
630          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
631          !!!next-input-character;          !!!next-input-character;
632          redo A;          redo A;
633        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
634            !!!cp (32);
635          !!!parse-error (type => 'bare etago');          !!!parse-error (type => 'bare etago');
636          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
637          # reconsume          # reconsume
# Line 595  sub _get_next_token ($) { Line 640  sub _get_next_token ($) {
640    
641          redo A;          redo A;
642        } else {        } else {
643            !!!cp (33);
644          !!!parse-error (type => 'bogus end tag');          !!!parse-error (type => 'bogus end tag');
645          $self->{state} = BOGUS_COMMENT_STATE;          $self->{state} = BOGUS_COMMENT_STATE;
646          ## $self->{next_input_character} is intentionally left as is          ## $self->{next_char} is intentionally left as is
647          redo A;          redo A;
648        }        }
649      } elsif ($self->{state} == TAG_NAME_STATE) {      } elsif ($self->{state} == TAG_NAME_STATE) {
650        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
651            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
652            $self->{next_input_character} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
653            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
654            $self->{next_input_character} == 0x0020) { # SP            $self->{next_char} == 0x0020) { # SP
655            !!!cp (34);
656          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
657          !!!next-input-character;          !!!next-input-character;
658          redo A;          redo A;
659        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
660          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
661              !!!cp (35);
662            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
663                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
664            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
665          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
666            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
667            if ($self->{current_token}->{attributes}) {            #if ($self->{current_token}->{attributes}) {
668              !!!parse-error (type => 'end tag attribute');            #  ## NOTE: This should never be reached.
669            }            #  !!! cp (36);
670              #  !!! parse-error (type => 'end tag attribute');
671              #} else {
672                !!!cp (37);
673              #}
674          } else {          } else {
675            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
676          }          }
# Line 628  sub _get_next_token ($) { Line 680  sub _get_next_token ($) {
680          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
681    
682          redo A;          redo A;
683        } elsif (0x0041 <= $self->{next_input_character} and        } elsif (0x0041 <= $self->{next_char} and
684                 $self->{next_input_character} <= 0x005A) { # A..Z                 $self->{next_char} <= 0x005A) { # A..Z
685          $self->{current_token}->{tag_name} .= chr ($self->{next_input_character} + 0x0020);          !!!cp (38);
686            $self->{current_token}->{tag_name} .= chr ($self->{next_char} + 0x0020);
687            # start tag or end tag            # start tag or end tag
688          ## Stay in this state          ## Stay in this state
689          !!!next-input-character;          !!!next-input-character;
690          redo A;          redo A;
691        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
692          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
693          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
694              !!!cp (39);
695            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
696                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
697            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
698          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
699            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
700            if ($self->{current_token}->{attributes}) {            #if ($self->{current_token}->{attributes}) {
701              !!!parse-error (type => 'end tag attribute');            #  ## NOTE: This state should never be reached.
702            }            #  !!! cp (40);
703              #  !!! parse-error (type => 'end tag attribute');
704              #} else {
705                !!!cp (41);
706              #}
707          } else {          } else {
708            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
709          }          }
# Line 655  sub _get_next_token ($) { Line 713  sub _get_next_token ($) {
713          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
714    
715          redo A;          redo A;
716        } elsif ($self->{next_input_character} == 0x002F) { # /        } elsif ($self->{next_char} == 0x002F) { # /
717          !!!next-input-character;          !!!next-input-character;
718          if ($self->{next_input_character} == 0x003E and # >          if ($self->{next_char} == 0x003E and # >
719              $self->{current_token}->{type} == START_TAG_TOKEN and              $self->{current_token}->{type} == START_TAG_TOKEN and
720              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {
721            # permitted slash            # permitted slash
722              !!!cp (42);
723            #            #
724          } else {          } else {
725              !!!cp (43);
726            !!!parse-error (type => 'nestc');            !!!parse-error (type => 'nestc');
727          }          }
728          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
729          # next-input-character is already done          # next-input-character is already done
730          redo A;          redo A;
731        } else {        } else {
732          $self->{current_token}->{tag_name} .= chr $self->{next_input_character};          !!!cp (44);
733            $self->{current_token}->{tag_name} .= chr $self->{next_char};
734            # start tag or end tag            # start tag or end tag
735          ## Stay in the state          ## Stay in the state
736          !!!next-input-character;          !!!next-input-character;
737          redo A;          redo A;
738        }        }
739      } elsif ($self->{state} == BEFORE_ATTRIBUTE_NAME_STATE) {      } elsif ($self->{state} == BEFORE_ATTRIBUTE_NAME_STATE) {
740        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
741            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
742            $self->{next_input_character} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
743            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
744            $self->{next_input_character} == 0x0020) { # SP            $self->{next_char} == 0x0020) { # SP
745            !!!cp (45);
746          ## Stay in the state          ## Stay in the state
747          !!!next-input-character;          !!!next-input-character;
748          redo A;          redo A;
749        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
750          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
751              !!!cp (46);
752            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
753                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
754            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
755          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
756            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
757            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
758                !!!cp (47);
759              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
760              } else {
761                !!!cp (48);
762            }            }
763          } else {          } else {
764            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 703  sub _get_next_token ($) { Line 769  sub _get_next_token ($) {
769          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
770    
771          redo A;          redo A;
772        } elsif (0x0041 <= $self->{next_input_character} and        } elsif (0x0041 <= $self->{next_char} and
773                 $self->{next_input_character} <= 0x005A) { # A..Z                 $self->{next_char} <= 0x005A) { # A..Z
774          $self->{current_attribute} = {name => chr ($self->{next_input_character} + 0x0020),          !!!cp (49);
775            $self->{current_attribute} = {name => chr ($self->{next_char} + 0x0020),
776                                value => ''};                                value => ''};
777          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
778          !!!next-input-character;          !!!next-input-character;
779          redo A;          redo A;
780        } elsif ($self->{next_input_character} == 0x002F) { # /        } elsif ($self->{next_char} == 0x002F) { # /
781          !!!next-input-character;          !!!next-input-character;
782          if ($self->{next_input_character} == 0x003E and # >          if ($self->{next_char} == 0x003E and # >
783              $self->{current_token}->{type} == START_TAG_TOKEN and              $self->{current_token}->{type} == START_TAG_TOKEN and
784              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {
785            # permitted slash            # permitted slash
786              !!!cp (50);
787            #            #
788          } else {          } else {
789              !!!cp (51);
790            !!!parse-error (type => 'nestc');            !!!parse-error (type => 'nestc');
791          }          }
792          ## Stay in the state          ## Stay in the state
793          # next-input-character is already done          # next-input-character is already done
794          redo A;          redo A;
795        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
796          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
797          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
798              !!!cp (52);
799            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
800                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
801            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
802          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
803            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
804            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
805                !!!cp (53);
806              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
807              } else {
808                !!!cp (54);
809            }            }
810          } else {          } else {
811            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 748  sub _get_next_token ($) { Line 821  sub _get_next_token ($) {
821               0x0022 => 1, # "               0x0022 => 1, # "
822               0x0027 => 1, # '               0x0027 => 1, # '
823               0x003D => 1, # =               0x003D => 1, # =
824              }->{$self->{next_input_character}}) {              }->{$self->{next_char}}) {
825              !!!cp (55);
826            !!!parse-error (type => 'bad attribute name');            !!!parse-error (type => 'bad attribute name');
827            } else {
828              !!!cp (56);
829          }          }
830          $self->{current_attribute} = {name => chr ($self->{next_input_character}),          $self->{current_attribute} = {name => chr ($self->{next_char}),
831                                value => ''};                                value => ''};
832          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
833          !!!next-input-character;          !!!next-input-character;
# Line 761  sub _get_next_token ($) { Line 837  sub _get_next_token ($) {
837        my $before_leave = sub {        my $before_leave = sub {
838          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
839              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
840              !!!cp (57);
841            !!!parse-error (type => 'duplicate attribute:'.$self->{current_attribute}->{name});            !!!parse-error (type => 'duplicate attribute:'.$self->{current_attribute}->{name});
842            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{current_attribute} # MUST
843          } else {          } else {
844              !!!cp (58);
845            $self->{current_token}->{attributes}->{$self->{current_attribute}->{name}}            $self->{current_token}->{attributes}->{$self->{current_attribute}->{name}}
846              = $self->{current_attribute};              = $self->{current_attribute};
847          }          }
848        }; # $before_leave        }; # $before_leave
849    
850        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
851            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
852            $self->{next_input_character} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
853            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
854            $self->{next_input_character} == 0x0020) { # SP            $self->{next_char} == 0x0020) { # SP
855            !!!cp (59);
856          $before_leave->();          $before_leave->();
857          $self->{state} = AFTER_ATTRIBUTE_NAME_STATE;          $self->{state} = AFTER_ATTRIBUTE_NAME_STATE;
858          !!!next-input-character;          !!!next-input-character;
859          redo A;          redo A;
860        } elsif ($self->{next_input_character} == 0x003D) { # =        } elsif ($self->{next_char} == 0x003D) { # =
861            !!!cp (60);
862          $before_leave->();          $before_leave->();
863          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;
864          !!!next-input-character;          !!!next-input-character;
865          redo A;          redo A;
866        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
867          $before_leave->();          $before_leave->();
868          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
869              !!!cp (61);
870            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
871                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
872            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
873          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
874              !!!cp (62);
875            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
876            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
877              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 803  sub _get_next_token ($) { Line 885  sub _get_next_token ($) {
885          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
886    
887          redo A;          redo A;
888        } elsif (0x0041 <= $self->{next_input_character} and        } elsif (0x0041 <= $self->{next_char} and
889                 $self->{next_input_character} <= 0x005A) { # A..Z                 $self->{next_char} <= 0x005A) { # A..Z
890          $self->{current_attribute}->{name} .= chr ($self->{next_input_character} + 0x0020);          !!!cp (63);
891            $self->{current_attribute}->{name} .= chr ($self->{next_char} + 0x0020);
892          ## Stay in the state          ## Stay in the state
893          !!!next-input-character;          !!!next-input-character;
894          redo A;          redo A;
895        } elsif ($self->{next_input_character} == 0x002F) { # /        } elsif ($self->{next_char} == 0x002F) { # /
896          $before_leave->();          $before_leave->();
897          !!!next-input-character;          !!!next-input-character;
898          if ($self->{next_input_character} == 0x003E and # >          if ($self->{next_char} == 0x003E and # >
899              $self->{current_token}->{type} == START_TAG_TOKEN and              $self->{current_token}->{type} == START_TAG_TOKEN and
900              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {
901            # permitted slash            # permitted slash
902              !!!cp (64);
903            #            #
904          } else {          } else {
905              !!!cp (65);
906            !!!parse-error (type => 'nestc');            !!!parse-error (type => 'nestc');
907          }          }
908          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
909          # next-input-character is already done          # next-input-character is already done
910          redo A;          redo A;
911        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
912          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
913          $before_leave->();          $before_leave->();
914          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
915              !!!cp (66);
916            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
917                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
918            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
919          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
920            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
921            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
922                !!!cp (67);
923              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
924              } else {
925                ## NOTE: This state should never be reached.
926                !!!cp (68);
927            }            }
928          } else {          } else {
929            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 845  sub _get_next_token ($) { Line 935  sub _get_next_token ($) {
935    
936          redo A;          redo A;
937        } else {        } else {
938          if ($self->{next_input_character} == 0x0022 or # "          if ($self->{next_char} == 0x0022 or # "
939              $self->{next_input_character} == 0x0027) { # '              $self->{next_char} == 0x0027) { # '
940              !!!cp (69);
941            !!!parse-error (type => 'bad attribute name');            !!!parse-error (type => 'bad attribute name');
942            } else {
943              !!!cp (70);
944          }          }
945          $self->{current_attribute}->{name} .= chr ($self->{next_input_character});          $self->{current_attribute}->{name} .= chr ($self->{next_char});
946          ## Stay in the state          ## Stay in the state
947          !!!next-input-character;          !!!next-input-character;
948          redo A;          redo A;
949        }        }
950      } elsif ($self->{state} == AFTER_ATTRIBUTE_NAME_STATE) {      } elsif ($self->{state} == AFTER_ATTRIBUTE_NAME_STATE) {
951        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
952            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
953            $self->{next_input_character} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
954            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
955            $self->{next_input_character} == 0x0020) { # SP            $self->{next_char} == 0x0020) { # SP
956            !!!cp (71);
957          ## Stay in the state          ## Stay in the state
958          !!!next-input-character;          !!!next-input-character;
959          redo A;          redo A;
960        } elsif ($self->{next_input_character} == 0x003D) { # =        } elsif ($self->{next_char} == 0x003D) { # =
961            !!!cp (72);
962          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;
963          !!!next-input-character;          !!!next-input-character;
964          redo A;          redo A;
965        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
966          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
967              !!!cp (73);
968            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
969                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
970            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
971          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
972            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
973            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
974                !!!cp (74);
975              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
976              } else {
977                ## NOTE: This state should never be reached.
978                !!!cp (75);
979            }            }
980          } else {          } else {
981            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 886  sub _get_next_token ($) { Line 986  sub _get_next_token ($) {
986          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
987    
988          redo A;          redo A;
989        } elsif (0x0041 <= $self->{next_input_character} and        } elsif (0x0041 <= $self->{next_char} and
990                 $self->{next_input_character} <= 0x005A) { # A..Z                 $self->{next_char} <= 0x005A) { # A..Z
991          $self->{current_attribute} = {name => chr ($self->{next_input_character} + 0x0020),          !!!cp (76);
992            $self->{current_attribute} = {name => chr ($self->{next_char} + 0x0020),
993                                value => ''};                                value => ''};
994          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
995          !!!next-input-character;          !!!next-input-character;
996          redo A;          redo A;
997        } elsif ($self->{next_input_character} == 0x002F) { # /        } elsif ($self->{next_char} == 0x002F) { # /
998          !!!next-input-character;          !!!next-input-character;
999          if ($self->{next_input_character} == 0x003E and # >          if ($self->{next_char} == 0x003E and # >
1000              $self->{current_token}->{type} == START_TAG_TOKEN and              $self->{current_token}->{type} == START_TAG_TOKEN and
1001              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {
1002            # permitted slash            # permitted slash
1003              !!!cp (77);
1004            #            #
1005          } else {          } else {
1006              !!!cp (78);
1007            !!!parse-error (type => 'nestc');            !!!parse-error (type => 'nestc');
1008            ## TODO: Different error type for <aa / bb> than <aa/>            ## TODO: Different error type for <aa / bb> than <aa/>
1009          }          }
1010          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1011          # next-input-character is already done          # next-input-character is already done
1012          redo A;          redo A;
1013        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
1014          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1015          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1016              !!!cp (79);
1017            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
1018                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
1019            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1020          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1021            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1022            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
1023                !!!cp (80);
1024              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1025              } else {
1026                ## NOTE: This state should never be reached.
1027                !!!cp (81);
1028            }            }
1029          } else {          } else {
1030            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 928  sub _get_next_token ($) { Line 1036  sub _get_next_token ($) {
1036    
1037          redo A;          redo A;
1038        } else {        } else {
1039          $self->{current_attribute} = {name => chr ($self->{next_input_character}),          !!!cp (82);
1040            $self->{current_attribute} = {name => chr ($self->{next_char}),
1041                                value => ''};                                value => ''};
1042          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
1043          !!!next-input-character;          !!!next-input-character;
1044          redo A;                  redo A;        
1045        }        }
1046      } elsif ($self->{state} == BEFORE_ATTRIBUTE_VALUE_STATE) {      } elsif ($self->{state} == BEFORE_ATTRIBUTE_VALUE_STATE) {
1047        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
1048            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
1049            $self->{next_input_character} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
1050            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
1051            $self->{next_input_character} == 0x0020) { # SP                  $self->{next_char} == 0x0020) { # SP      
1052            !!!cp (83);
1053          ## Stay in the state          ## Stay in the state
1054          !!!next-input-character;          !!!next-input-character;
1055          redo A;          redo A;
1056        } elsif ($self->{next_input_character} == 0x0022) { # "        } elsif ($self->{next_char} == 0x0022) { # "
1057            !!!cp (84);
1058          $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;          $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
1059          !!!next-input-character;          !!!next-input-character;
1060          redo A;          redo A;
1061        } elsif ($self->{next_input_character} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1062            !!!cp (85);
1063          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
1064          ## reconsume          ## reconsume
1065          redo A;          redo A;
1066        } elsif ($self->{next_input_character} == 0x0027) { # '        } elsif ($self->{next_char} == 0x0027) { # '
1067            !!!cp (86);
1068          $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;          $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
1069          !!!next-input-character;          !!!next-input-character;
1070          redo A;          redo A;
1071        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1072          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1073              !!!cp (87);
1074            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
1075                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
1076            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1077          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1078            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1079            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
1080                !!!cp (88);
1081              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1082              } else {
1083                ## NOTE: This state should never be reached.
1084                !!!cp (89);
1085            }            }
1086          } else {          } else {
1087            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 974  sub _get_next_token ($) { Line 1092  sub _get_next_token ($) {
1092          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
1093    
1094          redo A;          redo A;
1095        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
1096          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1097          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1098              !!!cp (90);
1099            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
1100                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
1101            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1102          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1103            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1104            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
1105                !!!cp (91);
1106              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1107              } else {
1108                ## NOTE: This state should never be reached.
1109                !!!cp (92);
1110            }            }
1111          } else {          } else {
1112            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 995  sub _get_next_token ($) { Line 1118  sub _get_next_token ($) {
1118    
1119          redo A;          redo A;
1120        } else {        } else {
1121          if ($self->{next_input_character} == 0x003D) { # =          if ($self->{next_char} == 0x003D) { # =
1122              !!!cp (93);
1123            !!!parse-error (type => 'bad attribute value');            !!!parse-error (type => 'bad attribute value');
1124            } else {
1125              !!!cp (94);
1126          }          }
1127          $self->{current_attribute}->{value} .= chr ($self->{next_input_character});          $self->{current_attribute}->{value} .= chr ($self->{next_char});
1128          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
1129          !!!next-input-character;          !!!next-input-character;
1130          redo A;          redo A;
1131        }        }
1132      } elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) {
1133        if ($self->{next_input_character} == 0x0022) { # "        if ($self->{next_char} == 0x0022) { # "
1134            !!!cp (95);
1135          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;
1136          !!!next-input-character;          !!!next-input-character;
1137          redo A;          redo A;
1138        } elsif ($self->{next_input_character} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1139            !!!cp (96);
1140          $self->{last_attribute_value_state} = $self->{state};          $self->{last_attribute_value_state} = $self->{state};
1141          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;
1142          !!!next-input-character;          !!!next-input-character;
1143          redo A;          redo A;
1144        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
1145          !!!parse-error (type => 'unclosed attribute value');          !!!parse-error (type => 'unclosed attribute value');
1146          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1147              !!!cp (97);
1148            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
1149                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
1150            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1151          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1152            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1153            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
1154                !!!cp (98);
1155              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1156              } else {
1157                ## NOTE: This state should never be reached.
1158                !!!cp (99);
1159            }            }
1160          } else {          } else {
1161            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 1034  sub _get_next_token ($) { Line 1167  sub _get_next_token ($) {
1167    
1168          redo A;          redo A;
1169        } else {        } else {
1170          $self->{current_attribute}->{value} .= chr ($self->{next_input_character});          !!!cp (100);
1171            $self->{current_attribute}->{value} .= chr ($self->{next_char});
1172          ## Stay in the state          ## Stay in the state
1173          !!!next-input-character;          !!!next-input-character;
1174          redo A;          redo A;
1175        }        }
1176      } elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) {
1177        if ($self->{next_input_character} == 0x0027) { # '        if ($self->{next_char} == 0x0027) { # '
1178            !!!cp (101);
1179          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;
1180          !!!next-input-character;          !!!next-input-character;
1181          redo A;          redo A;
1182        } elsif ($self->{next_input_character} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1183            !!!cp (102);
1184          $self->{last_attribute_value_state} = $self->{state};          $self->{last_attribute_value_state} = $self->{state};
1185          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;
1186          !!!next-input-character;          !!!next-input-character;
1187          redo A;          redo A;
1188        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
1189          !!!parse-error (type => 'unclosed attribute value');          !!!parse-error (type => 'unclosed attribute value');
1190          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1191              !!!cp (103);
1192            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
1193                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
1194            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1195          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1196            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1197            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
1198                !!!cp (104);
1199              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1200              } else {
1201                ## NOTE: This state should never be reached.
1202                !!!cp (105);
1203            }            }
1204          } else {          } else {
1205            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 1070  sub _get_next_token ($) { Line 1211  sub _get_next_token ($) {
1211    
1212          redo A;          redo A;
1213        } else {        } else {
1214          $self->{current_attribute}->{value} .= chr ($self->{next_input_character});          !!!cp (106);
1215            $self->{current_attribute}->{value} .= chr ($self->{next_char});
1216          ## Stay in the state          ## Stay in the state
1217          !!!next-input-character;          !!!next-input-character;
1218          redo A;          redo A;
1219        }        }
1220      } elsif ($self->{state} == ATTRIBUTE_VALUE_UNQUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_UNQUOTED_STATE) {
1221        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
1222            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
1223            $self->{next_input_character} == 0x000B or # HT            $self->{next_char} == 0x000B or # HT
1224            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
1225            $self->{next_input_character} == 0x0020) { # SP            $self->{next_char} == 0x0020) { # SP
1226            !!!cp (107);
1227          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1228          !!!next-input-character;          !!!next-input-character;
1229          redo A;          redo A;
1230        } elsif ($self->{next_input_character} == 0x0026) { # &        } elsif ($self->{next_char} == 0x0026) { # &
1231            !!!cp (108);
1232          $self->{last_attribute_value_state} = $self->{state};          $self->{last_attribute_value_state} = $self->{state};
1233          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;
1234          !!!next-input-character;          !!!next-input-character;
1235          redo A;          redo A;
1236        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1237          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1238              !!!cp (109);
1239            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
1240                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
1241            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1242          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1243            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1244            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
1245                !!!cp (110);
1246              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1247              } else {
1248                ## NOTE: This state should never be reached.
1249                !!!cp (111);
1250            }            }
1251          } else {          } else {
1252            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 1108  sub _get_next_token ($) { Line 1257  sub _get_next_token ($) {
1257          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
1258    
1259          redo A;          redo A;
1260        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
1261          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1262          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1263              !!!cp (112);
1264            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
1265                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
1266            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1267          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1268            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1269            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
1270                !!!cp (113);
1271              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1272              } else {
1273                ## NOTE: This state should never be reached.
1274                !!!cp (114);
1275            }            }
1276          } else {          } else {
1277            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 1133  sub _get_next_token ($) { Line 1287  sub _get_next_token ($) {
1287               0x0022 => 1, # "               0x0022 => 1, # "
1288               0x0027 => 1, # '               0x0027 => 1, # '
1289               0x003D => 1, # =               0x003D => 1, # =
1290              }->{$self->{next_input_character}}) {              }->{$self->{next_char}}) {
1291              !!!cp (115);
1292            !!!parse-error (type => 'bad attribute value');            !!!parse-error (type => 'bad attribute value');
1293            } else {
1294              !!!cp (116);
1295          }          }
1296          $self->{current_attribute}->{value} .= chr ($self->{next_input_character});          $self->{current_attribute}->{value} .= chr ($self->{next_char});
1297          ## Stay in the state          ## Stay in the state
1298          !!!next-input-character;          !!!next-input-character;
1299          redo A;          redo A;
# Line 1151  sub _get_next_token ($) { Line 1308  sub _get_next_token ($) {
1308             -1);             -1);
1309    
1310        unless (defined $token) {        unless (defined $token) {
1311            !!!cp (117);
1312          $self->{current_attribute}->{value} .= '&';          $self->{current_attribute}->{value} .= '&';
1313        } else {        } else {
1314            !!!cp (118);
1315          $self->{current_attribute}->{value} .= $token->{data};          $self->{current_attribute}->{value} .= $token->{data};
1316          $self->{current_attribute}->{has_reference} = $token->{has_reference};          $self->{current_attribute}->{has_reference} = $token->{has_reference};
1317          ## ISSUE: spec says "append the returned character token to the current attribute's value"          ## ISSUE: spec says "append the returned character token to the current attribute's value"
# Line 1162  sub _get_next_token ($) { Line 1321  sub _get_next_token ($) {
1321        # next-input-character is already done        # next-input-character is already done
1322        redo A;        redo A;
1323      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {
1324        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
1325            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
1326            $self->{next_input_character} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
1327            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
1328            $self->{next_input_character} == 0x0020) { # SP            $self->{next_char} == 0x0020) { # SP
1329            !!!cp (118);
1330          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1331          !!!next-input-character;          !!!next-input-character;
1332          redo A;          redo A;
1333        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1334          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1335              !!!cp (119);
1336            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
1337                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
1338            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1339          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1340            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1341            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
1342                !!!cp (120);
1343              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1344              } else {
1345                ## NOTE: This state should never be reached.
1346                !!!cp (121);
1347            }            }
1348          } else {          } else {
1349            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
# Line 1189  sub _get_next_token ($) { Line 1354  sub _get_next_token ($) {
1354          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
1355    
1356          redo A;          redo A;
1357        } elsif ($self->{next_input_character} == 0x002F) { # /        } elsif ($self->{next_char} == 0x002F) { # /
1358          !!!next-input-character;          !!!next-input-character;
1359          if ($self->{next_input_character} == 0x003E and # >          if ($self->{next_char} == 0x003E and # >
1360              $self->{current_token}->{type} == START_TAG_TOKEN and              $self->{current_token}->{type} == START_TAG_TOKEN and
1361              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {
1362            # permitted slash            # permitted slash
1363              !!!cp (122);
1364            #            #
1365          } else {          } else {
1366              !!!cp (123);
1367            !!!parse-error (type => 'nestc');            !!!parse-error (type => 'nestc');
1368          }          }
1369          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1370          # next-input-character is already done          # next-input-character is already done
1371          redo A;          redo A;
1372        } else {        } else {
1373            !!!cp (124);
1374          !!!parse-error (type => 'no space between attributes');          !!!parse-error (type => 'no space between attributes');
1375          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1376          ## reconsume          ## reconsume
# Line 1214  sub _get_next_token ($) { Line 1382  sub _get_next_token ($) {
1382        my $token = {type => COMMENT_TOKEN, data => ''};        my $token = {type => COMMENT_TOKEN, data => ''};
1383    
1384        BC: {        BC: {
1385          if ($self->{next_input_character} == 0x003E) { # >          if ($self->{next_char} == 0x003E) { # >
1386              !!!cp (124);
1387            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1388            !!!next-input-character;            !!!next-input-character;
1389    
1390            !!!emit ($token);            !!!emit ($token);
1391    
1392            redo A;            redo A;
1393          } elsif ($self->{next_input_character} == -1) {          } elsif ($self->{next_char} == -1) {
1394              !!!cp (125);
1395            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1396            ## reconsume            ## reconsume
1397    
# Line 1229  sub _get_next_token ($) { Line 1399  sub _get_next_token ($) {
1399    
1400            redo A;            redo A;
1401          } else {          } else {
1402            $token->{data} .= chr ($self->{next_input_character});            !!!cp (126);
1403              $token->{data} .= chr ($self->{next_char});
1404            !!!next-input-character;            !!!next-input-character;
1405            redo BC;            redo BC;
1406          }          }
1407        } # BC        } # BC
1408    
1409          die "$0: _get_next_token: unexpected case [BC]";
1410      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {
1411        ## (only happen if PCDATA state)        ## (only happen if PCDATA state)
1412    
1413        my @next_char;        my @next_char;
1414        push @next_char, $self->{next_input_character};        push @next_char, $self->{next_char};
1415                
1416        if ($self->{next_input_character} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
1417          !!!next-input-character;          !!!next-input-character;
1418          push @next_char, $self->{next_input_character};          push @next_char, $self->{next_char};
1419          if ($self->{next_input_character} == 0x002D) { # -          if ($self->{next_char} == 0x002D) { # -
1420              !!!cp (127);
1421            $self->{current_token} = {type => COMMENT_TOKEN, data => ''};            $self->{current_token} = {type => COMMENT_TOKEN, data => ''};
1422            $self->{state} = COMMENT_START_STATE;            $self->{state} = COMMENT_START_STATE;
1423            !!!next-input-character;            !!!next-input-character;
1424            redo A;            redo A;
1425            } else {
1426              !!!cp (128);
1427          }          }
1428        } elsif ($self->{next_input_character} == 0x0044 or # D        } elsif ($self->{next_char} == 0x0044 or # D
1429                 $self->{next_input_character} == 0x0064) { # d                 $self->{next_char} == 0x0064) { # d
1430          !!!next-input-character;          !!!next-input-character;
1431          push @next_char, $self->{next_input_character};          push @next_char, $self->{next_char};
1432          if ($self->{next_input_character} == 0x004F or # O          if ($self->{next_char} == 0x004F or # O
1433              $self->{next_input_character} == 0x006F) { # o              $self->{next_char} == 0x006F) { # o
1434            !!!next-input-character;            !!!next-input-character;
1435            push @next_char, $self->{next_input_character};            push @next_char, $self->{next_char};
1436            if ($self->{next_input_character} == 0x0043 or # C            if ($self->{next_char} == 0x0043 or # C
1437                $self->{next_input_character} == 0x0063) { # c                $self->{next_char} == 0x0063) { # c
1438              !!!next-input-character;              !!!next-input-character;
1439              push @next_char, $self->{next_input_character};              push @next_char, $self->{next_char};
1440              if ($self->{next_input_character} == 0x0054 or # T              if ($self->{next_char} == 0x0054 or # T
1441                  $self->{next_input_character} == 0x0074) { # t                  $self->{next_char} == 0x0074) { # t
1442                !!!next-input-character;                !!!next-input-character;
1443                push @next_char, $self->{next_input_character};                push @next_char, $self->{next_char};
1444                if ($self->{next_input_character} == 0x0059 or # Y                if ($self->{next_char} == 0x0059 or # Y
1445                    $self->{next_input_character} == 0x0079) { # y                    $self->{next_char} == 0x0079) { # y
1446                  !!!next-input-character;                  !!!next-input-character;
1447                  push @next_char, $self->{next_input_character};                  push @next_char, $self->{next_char};
1448                  if ($self->{next_input_character} == 0x0050 or # P                  if ($self->{next_char} == 0x0050 or # P
1449                      $self->{next_input_character} == 0x0070) { # p                      $self->{next_char} == 0x0070) { # p
1450                    !!!next-input-character;                    !!!next-input-character;
1451                    push @next_char, $self->{next_input_character};                    push @next_char, $self->{next_char};
1452                    if ($self->{next_input_character} == 0x0045 or # E                    if ($self->{next_char} == 0x0045 or # E
1453                        $self->{next_input_character} == 0x0065) { # e                        $self->{next_char} == 0x0065) { # e
1454                      ## ISSUE: What a stupid code this is!                      !!!cp (129);
1455                        ## TODO: What a stupid code this is!
1456                      $self->{state} = DOCTYPE_STATE;                      $self->{state} = DOCTYPE_STATE;
1457                      !!!next-input-character;                      !!!next-input-character;
1458                      redo A;                      redo A;
1459                      } else {
1460                        !!!cp (130);
1461                    }                    }
1462                    } else {
1463                      !!!cp (131);
1464                  }                  }
1465                  } else {
1466                    !!!cp (132);
1467                }                }
1468                } else {
1469                  !!!cp (133);
1470              }              }
1471              } else {
1472                !!!cp (134);
1473            }            }
1474            } else {
1475              !!!cp (135);
1476          }          }
1477          } else {
1478            !!!cp (136);
1479        }        }
1480    
1481        !!!parse-error (type => 'bogus comment');        !!!parse-error (type => 'bogus comment');
1482        $self->{next_input_character} = shift @next_char;        $self->{next_char} = shift @next_char;
1483        !!!back-next-input-character (@next_char);        !!!back-next-input-character (@next_char);
1484        $self->{state} = BOGUS_COMMENT_STATE;        $self->{state} = BOGUS_COMMENT_STATE;
1485        redo A;        redo A;
# Line 1296  sub _get_next_token ($) { Line 1487  sub _get_next_token ($) {
1487        ## ISSUE: typos in spec: chacacters, is is a parse error        ## ISSUE: typos in spec: chacacters, is is a parse error
1488        ## ISSUE: spec is somewhat unclear on "is the first character that will be in the comment"; what is "that will be in the comment" is what the algorithm defines, isn't it?        ## ISSUE: spec is somewhat unclear on "is the first character that will be in the comment"; what is "that will be in the comment" is what the algorithm defines, isn't it?
1489      } elsif ($self->{state} == COMMENT_START_STATE) {      } elsif ($self->{state} == COMMENT_START_STATE) {
1490        if ($self->{next_input_character} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
1491            !!!cp (137);
1492          $self->{state} = COMMENT_START_DASH_STATE;          $self->{state} = COMMENT_START_DASH_STATE;
1493          !!!next-input-character;          !!!next-input-character;
1494          redo A;          redo A;
1495        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1496            !!!cp (138);
1497          !!!parse-error (type => 'bogus comment');          !!!parse-error (type => 'bogus comment');
1498          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1499          !!!next-input-character;          !!!next-input-character;
# Line 1308  sub _get_next_token ($) { Line 1501  sub _get_next_token ($) {
1501          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
1502    
1503          redo A;          redo A;
1504        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
1505            !!!cp (139);
1506          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
1507          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1508          ## reconsume          ## reconsume
# Line 1317  sub _get_next_token ($) { Line 1511  sub _get_next_token ($) {
1511    
1512          redo A;          redo A;
1513        } else {        } else {
1514            !!!cp (140);
1515          $self->{current_token}->{data} # comment          $self->{current_token}->{data} # comment
1516              .= chr ($self->{next_input_character});              .= chr ($self->{next_char});
1517          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
1518          !!!next-input-character;          !!!next-input-character;
1519          redo A;          redo A;
1520        }        }
1521      } elsif ($self->{state} == COMMENT_START_DASH_STATE) {      } elsif ($self->{state} == COMMENT_START_DASH_STATE) {
1522        if ($self->{next_input_character} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
1523            !!!cp (141);
1524          $self->{state} = COMMENT_END_STATE;          $self->{state} = COMMENT_END_STATE;
1525          !!!next-input-character;          !!!next-input-character;
1526          redo A;          redo A;
1527        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1528            !!!cp (142);
1529          !!!parse-error (type => 'bogus comment');          !!!parse-error (type => 'bogus comment');
1530          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1531          !!!next-input-character;          !!!next-input-character;
# Line 1336  sub _get_next_token ($) { Line 1533  sub _get_next_token ($) {
1533          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
1534    
1535          redo A;          redo A;
1536        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
1537            !!!cp (143);
1538          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
1539          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1540          ## reconsume          ## reconsume
# Line 1345  sub _get_next_token ($) { Line 1543  sub _get_next_token ($) {
1543    
1544          redo A;          redo A;
1545        } else {        } else {
1546            !!!cp (144);
1547          $self->{current_token}->{data} # comment          $self->{current_token}->{data} # comment
1548              .= '-' . chr ($self->{next_input_character});              .= '-' . chr ($self->{next_char});
1549          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
1550          !!!next-input-character;          !!!next-input-character;
1551          redo A;          redo A;
1552        }        }
1553      } elsif ($self->{state} == COMMENT_STATE) {      } elsif ($self->{state} == COMMENT_STATE) {
1554        if ($self->{next_input_character} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
1555            !!!cp (145);
1556          $self->{state} = COMMENT_END_DASH_STATE;          $self->{state} = COMMENT_END_DASH_STATE;
1557          !!!next-input-character;          !!!next-input-character;
1558          redo A;          redo A;
1559        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
1560            !!!cp (146);
1561          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
1562          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1563          ## reconsume          ## reconsume
# Line 1365  sub _get_next_token ($) { Line 1566  sub _get_next_token ($) {
1566    
1567          redo A;          redo A;
1568        } else {        } else {
1569          $self->{current_token}->{data} .= chr ($self->{next_input_character}); # comment          !!!cp (147);
1570            $self->{current_token}->{data} .= chr ($self->{next_char}); # comment
1571          ## Stay in the state          ## Stay in the state
1572          !!!next-input-character;          !!!next-input-character;
1573          redo A;          redo A;
1574        }        }
1575      } elsif ($self->{state} == COMMENT_END_DASH_STATE) {      } elsif ($self->{state} == COMMENT_END_DASH_STATE) {
1576        if ($self->{next_input_character} == 0x002D) { # -        if ($self->{next_char} == 0x002D) { # -
1577            !!!cp (148);
1578          $self->{state} = COMMENT_END_STATE;          $self->{state} = COMMENT_END_STATE;
1579          !!!next-input-character;          !!!next-input-character;
1580          redo A;          redo A;
1581        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
1582            !!!cp (149);
1583          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
1584          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1585          ## reconsume          ## reconsume
# Line 1384  sub _get_next_token ($) { Line 1588  sub _get_next_token ($) {
1588    
1589          redo A;          redo A;
1590        } else {        } else {
1591          $self->{current_token}->{data} .= '-' . chr ($self->{next_input_character}); # comment          !!!cp (150);
1592            $self->{current_token}->{data} .= '-' . chr ($self->{next_char}); # comment
1593          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
1594          !!!next-input-character;          !!!next-input-character;
1595          redo A;          redo A;
1596        }        }
1597      } elsif ($self->{state} == COMMENT_END_STATE) {      } elsif ($self->{state} == COMMENT_END_STATE) {
1598        if ($self->{next_input_character} == 0x003E) { # >        if ($self->{next_char} == 0x003E) { # >
1599            !!!cp (151);
1600          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1601          !!!next-input-character;          !!!next-input-character;
1602    
1603          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
1604    
1605          redo A;          redo A;
1606        } elsif ($self->{next_input_character} == 0x002D) { # -        } elsif ($self->{next_char} == 0x002D) { # -
1607            !!!cp (152);
1608          !!!parse-error (type => 'dash in comment');          !!!parse-error (type => 'dash in comment');
1609          $self->{current_token}->{data} .= '-'; # comment          $self->{current_token}->{data} .= '-'; # comment
1610          ## Stay in the state          ## Stay in the state
1611          !!!next-input-character;          !!!next-input-character;
1612          redo A;          redo A;
1613        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
1614            !!!cp (153);
1615          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
1616          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1617          ## reconsume          ## reconsume
# Line 1412  sub _get_next_token ($) { Line 1620  sub _get_next_token ($) {
1620    
1621          redo A;          redo A;
1622        } else {        } else {
1623            !!!cp (154);
1624          !!!parse-error (type => 'dash in comment');          !!!parse-error (type => 'dash in comment');
1625          $self->{current_token}->{data} .= '--' . chr ($self->{next_input_character}); # comment          $self->{current_token}->{data} .= '--' . chr ($self->{next_char}); # comment
1626          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
1627          !!!next-input-character;          !!!next-input-character;
1628          redo A;          redo A;
1629        }        }
1630      } elsif ($self->{state} == DOCTYPE_STATE) {      } elsif ($self->{state} == DOCTYPE_STATE) {
1631        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
1632            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
1633            $self->{next_input_character} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
1634            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
1635            $self->{next_input_character} == 0x0020) { # SP            $self->{next_char} == 0x0020) { # SP
1636            !!!cp (155);
1637          $self->{state} = BEFORE_DOCTYPE_NAME_STATE;          $self->{state} = BEFORE_DOCTYPE_NAME_STATE;
1638          !!!next-input-character;          !!!next-input-character;
1639          redo A;          redo A;
1640        } else {        } else {
1641            !!!cp (156);
1642          !!!parse-error (type => 'no space before DOCTYPE name');          !!!parse-error (type => 'no space before DOCTYPE name');
1643          $self->{state} = BEFORE_DOCTYPE_NAME_STATE;          $self->{state} = BEFORE_DOCTYPE_NAME_STATE;
1644          ## reconsume          ## reconsume
1645          redo A;          redo A;
1646        }        }
1647      } elsif ($self->{state} == BEFORE_DOCTYPE_NAME_STATE) {      } elsif ($self->{state} == BEFORE_DOCTYPE_NAME_STATE) {
1648        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
1649            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
1650            $self->{next_input_character} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
1651            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
1652            $self->{next_input_character} == 0x0020) { # SP            $self->{next_char} == 0x0020) { # SP
1653            !!!cp (157);
1654          ## Stay in the state          ## Stay in the state
1655          !!!next-input-character;          !!!next-input-character;
1656          redo A;          redo A;
1657        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1658            !!!cp (158);
1659          !!!parse-error (type => 'no DOCTYPE name');          !!!parse-error (type => 'no DOCTYPE name');
1660          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1661          !!!next-input-character;          !!!next-input-character;
1662    
1663          !!!emit ({type => DOCTYPE_TOKEN}); # incorrect          !!!emit ({type => DOCTYPE_TOKEN, quirks => 1});
1664    
1665          redo A;          redo A;
1666        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
1667            !!!cp (159);
1668          !!!parse-error (type => 'no DOCTYPE name');          !!!parse-error (type => 'no DOCTYPE name');
1669          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1670          ## reconsume          ## reconsume
1671    
1672          !!!emit ({type => DOCTYPE_TOKEN}); # incorrect          !!!emit ({type => DOCTYPE_TOKEN, quirks => 1});
1673    
1674          redo A;          redo A;
1675        } else {        } else {
1676            !!!cp (160);
1677          $self->{current_token}          $self->{current_token}
1678              = {type => DOCTYPE_TOKEN,              = {type => DOCTYPE_TOKEN,
1679                 name => chr ($self->{next_input_character}),                 name => chr ($self->{next_char}),
1680                 correct => 1};                 #quirks => 0,
1681                  };
1682  ## ISSUE: "Set the token's name name to the" in the spec  ## ISSUE: "Set the token's name name to the" in the spec
1683          $self->{state} = DOCTYPE_NAME_STATE;          $self->{state} = DOCTYPE_NAME_STATE;
1684          !!!next-input-character;          !!!next-input-character;
# Line 1470  sub _get_next_token ($) { Line 1686  sub _get_next_token ($) {
1686        }        }
1687      } elsif ($self->{state} == DOCTYPE_NAME_STATE) {      } elsif ($self->{state} == DOCTYPE_NAME_STATE) {
1688  ## ISSUE: Redundant "First," in the spec.  ## ISSUE: Redundant "First," in the spec.
1689        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
1690            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
1691            $self->{next_input_character} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
1692            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
1693            $self->{next_input_character} == 0x0020) { # SP            $self->{next_char} == 0x0020) { # SP
1694            !!!cp (161);
1695          $self->{state} = AFTER_DOCTYPE_NAME_STATE;          $self->{state} = AFTER_DOCTYPE_NAME_STATE;
1696          !!!next-input-character;          !!!next-input-character;
1697          redo A;          redo A;
1698        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1699            !!!cp (162);
1700          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1701          !!!next-input-character;          !!!next-input-character;
1702    
1703          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
1704    
1705          redo A;          redo A;
1706        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
1707            !!!cp (163);
1708          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
1709          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1710          ## reconsume          ## reconsume
1711    
1712          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
1713          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
1714    
1715          redo A;          redo A;
1716        } else {        } else {
1717            !!!cp (164);
1718          $self->{current_token}->{name}          $self->{current_token}->{name}
1719            .= chr ($self->{next_input_character}); # DOCTYPE            .= chr ($self->{next_char}); # DOCTYPE
1720          ## Stay in the state          ## Stay in the state
1721          !!!next-input-character;          !!!next-input-character;
1722          redo A;          redo A;
1723        }        }
1724      } elsif ($self->{state} == AFTER_DOCTYPE_NAME_STATE) {      } elsif ($self->{state} == AFTER_DOCTYPE_NAME_STATE) {
1725        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_char} == 0x0009 or # HT
1726            $self->{next_input_character} == 0x000A or # LF            $self->{next_char} == 0x000A or # LF
1727            $self->{next_input_character} == 0x000B or # VT            $self->{next_char} == 0x000B or # VT
1728            $self->{next_input_character} == 0x000C or # FF            $self->{next_char} == 0x000C or # FF
1729            $self->{next_input_character} == 0x0020) { # SP            $self->{next_char} == 0x0020) { # SP
1730            !!!cp (165);
1731          ## Stay in the state          ## Stay in the state
1732          !!!next-input-character;          !!!next-input-character;
1733          redo A;          redo A;
1734        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1735            !!!cp (166);
1736          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1737          !!!next-input-character;          !!!next-input-character;
1738    
1739          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
1740    
1741          redo A;          redo A;
1742        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
1743            !!!cp (167);
1744          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
1745          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1746          ## reconsume          ## reconsume
1747    
1748          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
1749          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
1750    
1751          redo A;          redo A;
1752        } elsif ($self->{next_input_character} == 0x0050 or # P        } elsif ($self->{next_char} == 0x0050 or # P
1753                 $self->{next_input_character} == 0x0070) { # p                 $self->{next_char} == 0x0070) { # p
1754          !!!next-input-character;          !!!next-input-character;
1755          if ($self->{next_input_character} == 0x0055 or # U          if ($self->{next_char} == 0x0055 or # U
1756              $self->{next_input_character} == 0x0075) { # u              $self->{next_char} == 0x0075) { # u
1757            !!!next-input-character;            !!!next-input-character;
1758            if ($self->{next_input_character} == 0x0042 or # B            if ($self->{next_char} == 0x0042 or # B
1759                $self->{next_input_character} == 0x0062) { # b                $self->{next_char} == 0x0062) { # b
1760              !!!next-input-character;              !!!next-input-character;
1761              if ($self->{next_input_character} == 0x004C or # L              if ($self->{next_char} == 0x004C or # L
1762                  $self->{next_input_character} == 0x006C) { # l                  $self->{next_char} == 0x006C) { # l
1763                !!!next-input-character;                !!!next-input-character;
1764                if ($self->{next_input_character} == 0x0049 or # I                if ($self->{next_char} == 0x0049 or # I
1765                    $self->{next_input_character} == 0x0069) { # i                    $self->{next_char} == 0x0069) { # i
1766                  !!!next-input-character;                  !!!next-input-character;
1767                  if ($self->{next_input_character} == 0x0043 or # C                  if ($self->{next_char} == 0x0043 or # C
1768                      $self->{next_input_character} == 0x0063) { # c                      $self->{next_char} == 0x0063) { # c
1769                      !!!cp (168);
1770                    $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;                    $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
1771                    !!!next-input-character;                    !!!next-input-character;
1772                    redo A;                    redo A;
1773                    } else {
1774                      !!!cp (169);
1775                  }                  }
1776                  } else {
1777                    !!!cp (170);
1778                }                }
1779                } else {
1780                  !!!cp (171);
1781              }              }
1782              } else {
1783                !!!cp (172);
1784            }            }
1785            } else {
1786              !!!cp (173);
1787          }          }
1788    
1789          #          #
1790        } elsif ($self->{next_input_character} == 0x0053 or # S        } elsif ($self->{next_char} == 0x0053 or # S
1791                 $self->{next_input_character} == 0x0073) { # s                 $self->{next_char} == 0x0073) { # s
1792          !!!next-input-character;          !!!next-input-character;
1793          if ($self->{next_input_character} == 0x0059 or # Y          if ($self->{next_char} == 0x0059 or # Y
1794              $self->{next_input_character} == 0x0079) { # y              $self->{next_char} == 0x0079) { # y
1795            !!!next-input-character;            !!!next-input-character;
1796            if ($self->{next_input_character} == 0x0053 or # S            if ($self->{next_char} == 0x0053 or # S
1797                $self->{next_input_character} == 0x0073) { # s                $self->{next_char} == 0x0073) { # s
1798              !!!next-input-character;              !!!next-input-character;
1799              if ($self->{next_input_character} == 0x0054 or # T              if ($self->{next_char} == 0x0054 or # T
1800                  $self->{next_input_character} == 0x0074) { # t                  $self->{next_char} == 0x0074) { # t
1801                !!!next-input-character;                !!!next-input-character;
1802                if ($self->{next_input_character} == 0x0045 or # E                if ($self->{next_char} == 0x0045 or # E
1803                    $self->{next_input_character} == 0x0065) { # e                    $self->{next_char} == 0x0065) { # e
1804                  !!!next-input-character;                  !!!next-input-character;
1805                  if ($self->{next_input_character} == 0x004D or # M                  if ($self->{next_char} == 0x004D or # M
1806                      $self->{next_input_character} == 0x006D) { # m                      $self->{next_char} == 0x006D) { # m
1807                      !!!cp (174);
1808                    $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;                    $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
1809                    !!!next-input-character;                    !!!next-input-character;
1810                    redo A;                    redo A;
1811                    } else {
1812                      !!!cp (175);
1813                  }                  }
1814                  } else {
1815                    !!!cp (176);
1816                }                }
1817                } else {
1818                  !!!cp (177);
1819              }              }
1820              } else {
1821                !!!cp (178);
1822            }            }
1823            } else {
1824              !!!cp (179);
1825          }          }
1826    
1827          #          #
1828        } else {        } else {
1829            !!!cp (180);
1830          !!!next-input-character;          !!!next-input-character;
1831          #          #
1832        }        }
1833    
1834        !!!parse-error (type => 'string after DOCTYPE name');        !!!parse-error (type => 'string after DOCTYPE name');
1835        delete $self->{current_token}->{correct};        $self->{current_token}->{quirks} = 1;
1836    
1837        $self->{state} = BOGUS_DOCTYPE_STATE;        $self->{state} = BOGUS_DOCTYPE_STATE;
1838        # next-input-character is already done        # next-input-character is already done
# Line 1595  sub _get_next_token ($) { Line 1841  sub _get_next_token ($) {
1841        if ({        if ({
1842              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
1843              #0x000D => 1, # HT, LF, VT, FF, SP, CR              #0x000D => 1, # HT, LF, VT, FF, SP, CR
1844            }->{$self->{next_input_character}}) {            }->{$self->{next_char}}) {
1845            !!!cp (181);
1846          ## Stay in the state          ## Stay in the state
1847          !!!next-input-character;          !!!next-input-character;
1848          redo A;          redo A;
1849        } elsif ($self->{next_input_character} eq 0x0022) { # "        } elsif ($self->{next_char} eq 0x0022) { # "
1850            !!!cp (182);
1851          $self->{current_token}->{public_identifier} = ''; # DOCTYPE          $self->{current_token}->{public_identifier} = ''; # DOCTYPE
1852          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE;          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE;
1853          !!!next-input-character;          !!!next-input-character;
1854          redo A;          redo A;
1855        } elsif ($self->{next_input_character} eq 0x0027) { # '        } elsif ($self->{next_char} eq 0x0027) { # '
1856            !!!cp (183);
1857          $self->{current_token}->{public_identifier} = ''; # DOCTYPE          $self->{current_token}->{public_identifier} = ''; # DOCTYPE
1858          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE;          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE;
1859          !!!next-input-character;          !!!next-input-character;
1860          redo A;          redo A;
1861        } elsif ($self->{next_input_character} eq 0x003E) { # >        } elsif ($self->{next_char} eq 0x003E) { # >
1862            !!!cp (184);
1863          !!!parse-error (type => 'no PUBLIC literal');          !!!parse-error (type => 'no PUBLIC literal');
1864    
1865          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1866          !!!next-input-character;          !!!next-input-character;
1867    
1868          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
1869          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
1870    
1871          redo A;          redo A;
1872        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
1873            !!!cp (185);
1874          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
1875    
1876          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1877          ## reconsume          ## reconsume
1878    
1879          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
1880          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
1881    
1882          redo A;          redo A;
1883        } else {        } else {
1884            !!!cp (186);
1885          !!!parse-error (type => 'string after PUBLIC');          !!!parse-error (type => 'string after PUBLIC');
1886          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
1887    
1888          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
1889          !!!next-input-character;          !!!next-input-character;
1890          redo A;          redo A;
1891        }        }
1892      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE) {
1893        if ($self->{next_input_character} == 0x0022) { # "        if ($self->{next_char} == 0x0022) { # "
1894            !!!cp (187);
1895          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
1896          !!!next-input-character;          !!!next-input-character;
1897          redo A;          redo A;
1898        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1899            !!!cp (188);
1900          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
1901    
1902          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1903          !!!next-input-character;          !!!next-input-character;
1904    
1905          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
1906          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
1907    
1908          redo A;          redo A;
1909        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
1910            !!!cp (189);
1911          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
1912    
1913          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1914          ## reconsume          ## reconsume
1915    
1916          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
1917          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
1918    
1919          redo A;          redo A;
1920        } else {        } else {
1921            !!!cp (190);
1922          $self->{current_token}->{public_identifier} # DOCTYPE          $self->{current_token}->{public_identifier} # DOCTYPE
1923              .= chr $self->{next_input_character};              .= chr $self->{next_char};
1924          ## Stay in the state          ## Stay in the state
1925          !!!next-input-character;          !!!next-input-character;
1926          redo A;          redo A;
1927        }        }
1928      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE) {
1929        if ($self->{next_input_character} == 0x0027) { # '        if ($self->{next_char} == 0x0027) { # '
1930            !!!cp (191);
1931          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
1932          !!!next-input-character;          !!!next-input-character;
1933          redo A;          redo A;
1934        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1935            !!!cp (192);
1936          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
1937    
1938          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1939          !!!next-input-character;          !!!next-input-character;
1940    
1941          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
1942          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
1943    
1944          redo A;          redo A;
1945        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
1946            !!!cp (193);
1947          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
1948    
1949          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1950          ## reconsume          ## reconsume
1951    
1952          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
1953          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
1954    
1955          redo A;          redo A;
1956        } else {        } else {
1957            !!!cp (194);
1958          $self->{current_token}->{public_identifier} # DOCTYPE          $self->{current_token}->{public_identifier} # DOCTYPE
1959              .= chr $self->{next_input_character};              .= chr $self->{next_char};
1960          ## Stay in the state          ## Stay in the state
1961          !!!next-input-character;          !!!next-input-character;
1962          redo A;          redo A;
# Line 1705  sub _get_next_token ($) { Line 1965  sub _get_next_token ($) {
1965        if ({        if ({
1966              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
1967              #0x000D => 1, # HT, LF, VT, FF, SP, CR              #0x000D => 1, # HT, LF, VT, FF, SP, CR
1968            }->{$self->{next_input_character}}) {            }->{$self->{next_char}}) {
1969            !!!cp (195);
1970          ## Stay in the state          ## Stay in the state
1971          !!!next-input-character;          !!!next-input-character;
1972          redo A;          redo A;
1973        } elsif ($self->{next_input_character} == 0x0022) { # "        } elsif ($self->{next_char} == 0x0022) { # "
1974            !!!cp (196);
1975          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{current_token}->{system_identifier} = ''; # DOCTYPE
1976          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;
1977          !!!next-input-character;          !!!next-input-character;
1978          redo A;          redo A;
1979        } elsif ($self->{next_input_character} == 0x0027) { # '        } elsif ($self->{next_char} == 0x0027) { # '
1980            !!!cp (197);
1981          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{current_token}->{system_identifier} = ''; # DOCTYPE
1982          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;
1983          !!!next-input-character;          !!!next-input-character;
1984          redo A;          redo A;
1985        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1986            !!!cp (198);
1987          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1988          !!!next-input-character;          !!!next-input-character;
1989    
1990          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
1991    
1992          redo A;          redo A;
1993        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
1994            !!!cp (199);
1995          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
1996    
1997          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1998          ## reconsume          ## reconsume
1999    
2000          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
2001          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
2002    
2003          redo A;          redo A;
2004        } else {        } else {
2005            !!!cp (200);
2006          !!!parse-error (type => 'string after PUBLIC literal');          !!!parse-error (type => 'string after PUBLIC literal');
2007          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
2008    
2009          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2010          !!!next-input-character;          !!!next-input-character;
# Line 1748  sub _get_next_token ($) { Line 2014  sub _get_next_token ($) {
2014        if ({        if ({
2015              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
2016              #0x000D => 1, # HT, LF, VT, FF, SP, CR              #0x000D => 1, # HT, LF, VT, FF, SP, CR
2017            }->{$self->{next_input_character}}) {            }->{$self->{next_char}}) {
2018            !!!cp (201);
2019          ## Stay in the state          ## Stay in the state
2020          !!!next-input-character;          !!!next-input-character;
2021          redo A;          redo A;
2022        } elsif ($self->{next_input_character} == 0x0022) { # "        } elsif ($self->{next_char} == 0x0022) { # "
2023            !!!cp (202);
2024          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{current_token}->{system_identifier} = ''; # DOCTYPE
2025          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;
2026          !!!next-input-character;          !!!next-input-character;
2027          redo A;          redo A;
2028        } elsif ($self->{next_input_character} == 0x0027) { # '        } elsif ($self->{next_char} == 0x0027) { # '
2029            !!!cp (203);
2030          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{current_token}->{system_identifier} = ''; # DOCTYPE
2031          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;
2032          !!!next-input-character;          !!!next-input-character;
2033          redo A;          redo A;
2034        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2035            !!!cp (204);
2036          !!!parse-error (type => 'no SYSTEM literal');          !!!parse-error (type => 'no SYSTEM literal');
2037          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2038          !!!next-input-character;          !!!next-input-character;
2039    
2040          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
2041          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
2042    
2043          redo A;          redo A;
2044        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
2045            !!!cp (205);
2046          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2047    
2048          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2049          ## reconsume          ## reconsume
2050    
2051          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
2052          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
2053    
2054          redo A;          redo A;
2055        } else {        } else {
2056            !!!cp (206);
2057          !!!parse-error (type => 'string after SYSTEM');          !!!parse-error (type => 'string after SYSTEM');
2058          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
2059    
2060          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2061          !!!next-input-character;          !!!next-input-character;
2062          redo A;          redo A;
2063        }        }
2064      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE) {
2065        if ($self->{next_input_character} == 0x0022) { # "        if ($self->{next_char} == 0x0022) { # "
2066            !!!cp (207);
2067          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2068          !!!next-input-character;          !!!next-input-character;
2069          redo A;          redo A;
2070        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2071            !!!cp (208);
2072          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2073    
2074          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2075          !!!next-input-character;          !!!next-input-character;
2076    
2077          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
2078          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
2079    
2080          redo A;          redo A;
2081        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
2082            !!!cp (209);
2083          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2084    
2085          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2086          ## reconsume          ## reconsume
2087    
2088          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
2089          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
2090    
2091          redo A;          redo A;
2092        } else {        } else {
2093            !!!cp (210);
2094          $self->{current_token}->{system_identifier} # DOCTYPE          $self->{current_token}->{system_identifier} # DOCTYPE
2095              .= chr $self->{next_input_character};              .= chr $self->{next_char};
2096          ## Stay in the state          ## Stay in the state
2097          !!!next-input-character;          !!!next-input-character;
2098          redo A;          redo A;
2099        }        }
2100      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE) {
2101        if ($self->{next_input_character} == 0x0027) { # '        if ($self->{next_char} == 0x0027) { # '
2102            !!!cp (211);
2103          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2104          !!!next-input-character;          !!!next-input-character;
2105          redo A;          redo A;
2106        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2107            !!!cp (212);
2108          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2109    
2110          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2111          !!!next-input-character;          !!!next-input-character;
2112    
2113          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
2114          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
2115    
2116          redo A;          redo A;
2117        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
2118            !!!cp (213);
2119          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2120    
2121          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2122          ## reconsume          ## reconsume
2123    
2124          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
2125          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
2126    
2127          redo A;          redo A;
2128        } else {        } else {
2129            !!!cp (214);
2130          $self->{current_token}->{system_identifier} # DOCTYPE          $self->{current_token}->{system_identifier} # DOCTYPE
2131              .= chr $self->{next_input_character};              .= chr $self->{next_char};
2132          ## Stay in the state          ## Stay in the state
2133          !!!next-input-character;          !!!next-input-character;
2134          redo A;          redo A;
# Line 1857  sub _get_next_token ($) { Line 2137  sub _get_next_token ($) {
2137        if ({        if ({
2138              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
2139              #0x000D => 1, # HT, LF, VT, FF, SP, CR              #0x000D => 1, # HT, LF, VT, FF, SP, CR
2140            }->{$self->{next_input_character}}) {            }->{$self->{next_char}}) {
2141            !!!cp (215);
2142          ## Stay in the state          ## Stay in the state
2143          !!!next-input-character;          !!!next-input-character;
2144          redo A;          redo A;
2145        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2146            !!!cp (216);
2147          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2148          !!!next-input-character;          !!!next-input-character;
2149    
2150          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
2151    
2152          redo A;          redo A;
2153        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
2154            !!!cp (217);
2155          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2156    
2157          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2158          ## reconsume          ## reconsume
2159    
2160          delete $self->{current_token}->{correct};          $self->{current_token}->{quirks} = 1;
2161          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
2162    
2163          redo A;          redo A;
2164        } else {        } else {
2165            !!!cp (218);
2166          !!!parse-error (type => 'string after SYSTEM literal');          !!!parse-error (type => 'string after SYSTEM literal');
2167          delete $self->{current_token}->{correct};          #$self->{current_token}->{quirks} = 1;
2168    
2169          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2170          !!!next-input-character;          !!!next-input-character;
2171          redo A;          redo A;
2172        }        }
2173      } elsif ($self->{state} == BOGUS_DOCTYPE_STATE) {      } elsif ($self->{state} == BOGUS_DOCTYPE_STATE) {
2174        if ($self->{next_input_character} == 0x003E) { # >        if ($self->{next_char} == 0x003E) { # >
2175            !!!cp (219);
2176          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2177          !!!next-input-character;          !!!next-input-character;
2178    
2179          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
2180    
2181          redo A;          redo A;
2182        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_char} == -1) {
2183            !!!cp (220);
2184          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2185          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2186          ## reconsume          ## reconsume
# Line 1903  sub _get_next_token ($) { Line 2189  sub _get_next_token ($) {
2189    
2190          redo A;          redo A;
2191        } else {        } else {
2192            !!!cp (221);
2193          ## Stay in the state          ## Stay in the state
2194          !!!next-input-character;          !!!next-input-character;
2195          redo A;          redo A;
# Line 1922  sub _tokenize_attempt_to_consume_an_enti Line 2209  sub _tokenize_attempt_to_consume_an_enti
2209         0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,         0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,
2210         0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR         0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR
2211         $additional => 1,         $additional => 1,
2212        }->{$self->{next_input_character}}) {        }->{$self->{next_char}}) {
2213        !!!cp (1001);
2214      ## Don't consume      ## Don't consume
2215      ## No error      ## No error
2216      return undef;      return undef;
2217    } elsif ($self->{next_input_character} == 0x0023) { # #    } elsif ($self->{next_char} == 0x0023) { # #
2218      !!!next-input-character;      !!!next-input-character;
2219      if ($self->{next_input_character} == 0x0078 or # x      if ($self->{next_char} == 0x0078 or # x
2220          $self->{next_input_character} == 0x0058) { # X          $self->{next_char} == 0x0058) { # X
2221        my $code;        my $code;
2222        X: {        X: {
2223          my $x_char = $self->{next_input_character};          my $x_char = $self->{next_char};
2224          !!!next-input-character;          !!!next-input-character;
2225          if (0x0030 <= $self->{next_input_character} and          if (0x0030 <= $self->{next_char} and
2226              $self->{next_input_character} <= 0x0039) { # 0..9              $self->{next_char} <= 0x0039) { # 0..9
2227              !!!cp (1002);
2228            $code ||= 0;            $code ||= 0;
2229            $code *= 0x10;            $code *= 0x10;
2230            $code += $self->{next_input_character} - 0x0030;            $code += $self->{next_char} - 0x0030;
2231            redo X;            redo X;
2232          } elsif (0x0061 <= $self->{next_input_character} and          } elsif (0x0061 <= $self->{next_char} and
2233                   $self->{next_input_character} <= 0x0066) { # a..f                   $self->{next_char} <= 0x0066) { # a..f
2234              !!!cp (1003);
2235            $code ||= 0;            $code ||= 0;
2236            $code *= 0x10;            $code *= 0x10;
2237            $code += $self->{next_input_character} - 0x0060 + 9;            $code += $self->{next_char} - 0x0060 + 9;
2238            redo X;            redo X;
2239          } elsif (0x0041 <= $self->{next_input_character} and          } elsif (0x0041 <= $self->{next_char} and
2240                   $self->{next_input_character} <= 0x0046) { # A..F                   $self->{next_char} <= 0x0046) { # A..F
2241              !!!cp (1004);
2242            $code ||= 0;            $code ||= 0;
2243            $code *= 0x10;            $code *= 0x10;
2244            $code += $self->{next_input_character} - 0x0040 + 9;            $code += $self->{next_char} - 0x0040 + 9;
2245            redo X;            redo X;
2246          } elsif (not defined $code) { # no hexadecimal digit          } elsif (not defined $code) { # no hexadecimal digit
2247              !!!cp (1005);
2248            !!!parse-error (type => 'bare hcro');            !!!parse-error (type => 'bare hcro');
2249            !!!back-next-input-character ($x_char, $self->{next_input_character});            !!!back-next-input-character ($x_char, $self->{next_char});
2250            $self->{next_input_character} = 0x0023; # #            $self->{next_char} = 0x0023; # #
2251            return undef;            return undef;
2252          } elsif ($self->{next_input_character} == 0x003B) { # ;          } elsif ($self->{next_char} == 0x003B) { # ;
2253              !!!cp (1006);
2254            !!!next-input-character;            !!!next-input-character;
2255          } else {          } else {
2256              !!!cp (1007);
2257            !!!parse-error (type => 'no refc');            !!!parse-error (type => 'no refc');
2258          }          }
2259    
2260          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2261              !!!cp (1008);
2262            !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code);            !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code);
2263            $code = 0xFFFD;            $code = 0xFFFD;
2264          } elsif ($code > 0x10FFFF) {          } elsif ($code > 0x10FFFF) {
2265              !!!cp (1009);
2266            !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code);            !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code);
2267            $code = 0xFFFD;            $code = 0xFFFD;
2268          } elsif ($code == 0x000D) {          } elsif ($code == 0x000D) {
2269              !!!cp (1010);
2270            !!!parse-error (type => 'CR character reference');            !!!parse-error (type => 'CR character reference');
2271            $code = 0x000A;            $code = 0x000A;
2272          } elsif (0x80 <= $code and $code <= 0x9F) {          } elsif (0x80 <= $code and $code <= 0x9F) {
2273              !!!cp (1011);
2274            !!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code);            !!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code);
2275            $code = $c1_entity_char->{$code};            $code = $c1_entity_char->{$code};
2276          }          }
# Line 1980  sub _tokenize_attempt_to_consume_an_enti Line 2278  sub _tokenize_attempt_to_consume_an_enti
2278          return {type => CHARACTER_TOKEN, data => chr $code,          return {type => CHARACTER_TOKEN, data => chr $code,
2279                  has_reference => 1};                  has_reference => 1};
2280        } # X        } # X
2281      } elsif (0x0030 <= $self->{next_input_character} and      } elsif (0x0030 <= $self->{next_char} and
2282               $self->{next_input_character} <= 0x0039) { # 0..9               $self->{next_char} <= 0x0039) { # 0..9
2283        my $code = $self->{next_input_character} - 0x0030;        my $code = $self->{next_char} - 0x0030;
2284        !!!next-input-character;        !!!next-input-character;
2285                
2286        while (0x0030 <= $self->{next_input_character} and        while (0x0030 <= $self->{next_char} and
2287                  $self->{next_input_character} <= 0x0039) { # 0..9                  $self->{next_char} <= 0x0039) { # 0..9
2288            !!!cp (1012);
2289          $code *= 10;          $code *= 10;
2290          $code += $self->{next_input_character} - 0x0030;          $code += $self->{next_char} - 0x0030;
2291                    
2292          !!!next-input-character;          !!!next-input-character;
2293        }        }
2294    
2295        if ($self->{next_input_character} == 0x003B) { # ;        if ($self->{next_char} == 0x003B) { # ;
2296            !!!cp (1013);
2297          !!!next-input-character;          !!!next-input-character;
2298        } else {        } else {
2299            !!!cp (1014);
2300          !!!parse-error (type => 'no refc');          !!!parse-error (type => 'no refc');
2301        }        }
2302    
2303        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2304            !!!cp (1015);
2305          !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code);          !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code);
2306          $code = 0xFFFD;          $code = 0xFFFD;
2307        } elsif ($code > 0x10FFFF) {        } elsif ($code > 0x10FFFF) {
2308            !!!cp (1016);
2309          !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code);          !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code);
2310          $code = 0xFFFD;          $code = 0xFFFD;
2311        } elsif ($code == 0x000D) {        } elsif ($code == 0x000D) {
2312            !!!cp (1017);
2313          !!!parse-error (type => 'CR character reference');          !!!parse-error (type => 'CR character reference');
2314          $code = 0x000A;          $code = 0x000A;
2315        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
2316            !!!cp (1018);
2317          !!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code);          !!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code);
2318          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
2319        }        }
2320                
2321        return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1};        return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1};
2322      } else {      } else {
2323          !!!cp (1019);
2324        !!!parse-error (type => 'bare nero');        !!!parse-error (type => 'bare nero');
2325        !!!back-next-input-character ($self->{next_input_character});        !!!back-next-input-character ($self->{next_char});
2326        $self->{next_input_character} = 0x0023; # #        $self->{next_char} = 0x0023; # #
2327        return undef;        return undef;
2328      }      }
2329    } elsif ((0x0041 <= $self->{next_input_character} and    } elsif ((0x0041 <= $self->{next_char} and
2330              $self->{next_input_character} <= 0x005A) or              $self->{next_char} <= 0x005A) or
2331             (0x0061 <= $self->{next_input_character} and             (0x0061 <= $self->{next_char} and
2332              $self->{next_input_character} <= 0x007A)) {              $self->{next_char} <= 0x007A)) {
2333      my $entity_name = chr $self->{next_input_character};      my $entity_name = chr $self->{next_char};
2334      !!!next-input-character;      !!!next-input-character;
2335    
2336      my $value = $entity_name;      my $value = $entity_name;
# Line 2034  sub _tokenize_attempt_to_consume_an_enti Line 2340  sub _tokenize_attempt_to_consume_an_enti
2340    
2341      while (length $entity_name < 10 and      while (length $entity_name < 10 and
2342             ## NOTE: Some number greater than the maximum length of entity name             ## NOTE: Some number greater than the maximum length of entity name
2343             ((0x0041 <= $self->{next_input_character} and # a             ((0x0041 <= $self->{next_char} and # a
2344               $self->{next_input_character} <= 0x005A) or # x               $self->{next_char} <= 0x005A) or # x
2345              (0x0061 <= $self->{next_input_character} and # a              (0x0061 <= $self->{next_char} and # a
2346               $self->{next_input_character} <= 0x007A) or # z               $self->{next_char} <= 0x007A) or # z
2347              (0x0030 <= $self->{next_input_character} and # 0              (0x0030 <= $self->{next_char} and # 0
2348               $self->{next_input_character} <= 0x0039) or # 9               $self->{next_char} <= 0x0039) or # 9
2349              $self->{next_input_character} == 0x003B)) { # ;              $self->{next_char} == 0x003B)) { # ;
2350        $entity_name .= chr $self->{next_input_character};        $entity_name .= chr $self->{next_char};
2351        if (defined $EntityChar->{$entity_name}) {        if (defined $EntityChar->{$entity_name}) {
2352          if ($self->{next_input_character} == 0x003B) { # ;          if ($self->{next_char} == 0x003B) { # ;
2353              !!!cp (1020);
2354            $value = $EntityChar->{$entity_name};            $value = $EntityChar->{$entity_name};
2355            $match = 1;            $match = 1;
2356            !!!next-input-character;            !!!next-input-character;
2357            last;            last;
2358          } else {          } else {
2359              !!!cp (1021);
2360            $value = $EntityChar->{$entity_name};            $value = $EntityChar->{$entity_name};
2361            $match = -1;            $match = -1;
2362            !!!next-input-character;            !!!next-input-character;
2363          }          }
2364        } else {        } else {
2365          $value .= chr $self->{next_input_character};          !!!cp (1022);
2366            $value .= chr $self->{next_char};
2367          $match *= 2;          $match *= 2;
2368          !!!next-input-character;          !!!next-input-character;
2369        }        }
2370      }      }
2371            
2372      if ($match > 0) {      if ($match > 0) {
2373          !!!cp (1023);
2374        return {type => CHARACTER_TOKEN, data => $value, has_reference => 1};        return {type => CHARACTER_TOKEN, data => $value, has_reference => 1};
2375      } elsif ($match < 0) {      } elsif ($match < 0) {
2376        !!!parse-error (type => 'no refc');        !!!parse-error (type => 'no refc');
2377        if ($in_attr and $match < -1) {        if ($in_attr and $match < -1) {
2378            !!!cp (1024);
2379          return {type => CHARACTER_TOKEN, data => '&'.$entity_name};          return {type => CHARACTER_TOKEN, data => '&'.$entity_name};
2380        } else {        } else {
2381            !!!cp (1025);
2382          return {type => CHARACTER_TOKEN, data => $value, has_reference => 1};          return {type => CHARACTER_TOKEN, data => $value, has_reference => 1};
2383        }        }
2384      } else {      } else {
2385          !!!cp (1026);
2386        !!!parse-error (type => 'bare ero');        !!!parse-error (type => 'bare ero');
2387        ## NOTE: "No characters are consumed" in the spec.        ## NOTE: "No characters are consumed" in the spec.
2388        return {type => CHARACTER_TOKEN, data => '&'.$value};        return {type => CHARACTER_TOKEN, data => '&'.$value};
2389      }      }
2390    } else {    } else {
2391        !!!cp (1027);
2392      ## no characters are consumed      ## no characters are consumed
2393      !!!parse-error (type => 'bare ero');      !!!parse-error (type => 'bare ero');
2394      return undef;      return undef;
# Line 2114  sub _construct_tree ($) { Line 2428  sub _construct_tree ($) {
2428        
2429    !!!next-token;    !!!next-token;
2430    
   $self->{insertion_mode} = BEFORE_HEAD_IM;  
2431    undef $self->{form_element};    undef $self->{form_element};
2432    undef $self->{head_element};    undef $self->{head_element};
2433    $self->{open_elements} = [];    $self->{open_elements} = [];
2434    undef $self->{inner_html_node};    undef $self->{inner_html_node};
2435    
2436      ## NOTE: The "initial" insertion mode.
2437    $self->_tree_construction_initial; # MUST    $self->_tree_construction_initial; # MUST
2438    
2439      ## NOTE: The "before html" insertion mode.
2440    $self->_tree_construction_root_element;    $self->_tree_construction_root_element;
2441      $self->{insertion_mode} = BEFORE_HEAD_IM;
2442    
2443      ## NOTE: The "before head" insertion mode and so on.
2444    $self->_tree_construction_main;    $self->_tree_construction_main;
2445  } # _construct_tree  } # _construct_tree
2446    
2447  sub _tree_construction_initial ($) {  sub _tree_construction_initial ($) {
2448    my $self = shift;    my $self = shift;
2449    
2450      ## NOTE: "initial" insertion mode
2451    
2452    INITIAL: {    INITIAL: {
2453      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
2454        ## NOTE: Conformance checkers MAY, instead of reporting "not HTML5"        ## NOTE: Conformance checkers MAY, instead of reporting "not HTML5"
# Line 2138  sub _tree_construction_initial ($) { Line 2460  sub _tree_construction_initial ($) {
2460        if (not defined $token->{name} or # <!DOCTYPE>        if (not defined $token->{name} or # <!DOCTYPE>
2461            defined $token->{public_identifier} or            defined $token->{public_identifier} or
2462            defined $token->{system_identifier}) {            defined $token->{system_identifier}) {
2463            !!!cp ('t1');
2464          !!!parse-error (type => 'not HTML5');          !!!parse-error (type => 'not HTML5');
2465        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
2466            !!!cp ('t2');
2467          ## ISSUE: ASCII case-insensitive? (in fact it does not matter)          ## ISSUE: ASCII case-insensitive? (in fact it does not matter)
2468          !!!parse-error (type => 'not HTML5');          !!!parse-error (type => 'not HTML5');
2469          } else {
2470            !!!cp ('t3');
2471        }        }
2472                
2473        my $doctype = $self->{document}->create_document_type_definition        my $doctype = $self->{document}->create_document_type_definition
# Line 2154  sub _tree_construction_initial ($) { Line 2480  sub _tree_construction_initial ($) {
2480        ## ISSUE: internalSubset = null??        ## ISSUE: internalSubset = null??
2481        $self->{document}->append_child ($doctype);        $self->{document}->append_child ($doctype);
2482                
2483        if (not $token->{correct} or $doctype_name ne 'HTML') {        if ($token->{quirks} or $doctype_name ne 'HTML') {
2484            !!!cp ('t4');
2485          $self->{document}->manakai_compat_mode ('quirks');          $self->{document}->manakai_compat_mode ('quirks');
2486        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{public_identifier}) {
2487          my $pubid = $token->{public_identifier};          my $pubid = $token->{public_identifier};
# Line 2233  sub _tree_construction_initial ($) { Line 2560  sub _tree_construction_initial ($) {
2560            "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" => 1,            "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" => 1,
2561            "HTML" => 1,            "HTML" => 1,
2562          }->{$pubid}) {          }->{$pubid}) {
2563              !!!cp ('t5');
2564            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
2565          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or
2566                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {
2567            if (defined $token->{system_identifier}) {            if (defined $token->{system_identifier}) {
2568                !!!cp ('t6');
2569              $self->{document}->manakai_compat_mode ('quirks');              $self->{document}->manakai_compat_mode ('quirks');
2570            } else {            } else {
2571                !!!cp ('t7');
2572              $self->{document}->manakai_compat_mode ('limited quirks');              $self->{document}->manakai_compat_mode ('limited quirks');
2573            }            }
2574          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 Frameset//EN" or          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 FRAMESET//EN" or
2575                   $pubid eq "-//W3C//DTD XHTML 1.0 Transitional//EN") {                   $pubid eq "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN") {
2576              !!!cp ('t8');
2577            $self->{document}->manakai_compat_mode ('limited quirks');            $self->{document}->manakai_compat_mode ('limited quirks');
2578            } else {
2579              !!!cp ('t9');
2580          }          }
2581          } else {
2582            !!!cp ('t10');
2583        }        }
2584        if (defined $token->{system_identifier}) {        if (defined $token->{system_identifier}) {
2585          my $sysid = $token->{system_identifier};          my $sysid = $token->{system_identifier};
2586          $sysid =~ tr/A-Z/a-z/;          $sysid =~ tr/A-Z/a-z/;
2587          if ($sysid eq "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") {          if ($sysid eq "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") {
2588              ## TODO: Check the spec: PUBLIC "(limited quirks)" "(quirks)"
2589            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
2590              !!!cp ('t11');
2591            } else {
2592              !!!cp ('t12');
2593          }          }
2594          } else {
2595            !!!cp ('t13');
2596        }        }
2597                
2598        ## Go to the root element phase.        ## Go to the "before html" insertion mode.
2599        !!!next-token;        !!!next-token;
2600        return;        return;
2601      } elsif ({      } elsif ({
# Line 2262  sub _tree_construction_initial ($) { Line 2603  sub _tree_construction_initial ($) {
2603                END_TAG_TOKEN, 1,                END_TAG_TOKEN, 1,
2604                END_OF_FILE_TOKEN, 1,                END_OF_FILE_TOKEN, 1,
2605               }->{$token->{type}}) {               }->{$token->{type}}) {
2606          !!!cp ('t14');
2607        !!!parse-error (type => 'no DOCTYPE');        !!!parse-error (type => 'no DOCTYPE');
2608        $self->{document}->manakai_compat_mode ('quirks');        $self->{document}->manakai_compat_mode ('quirks');
2609        ## Go to the root element phase        ## Go to the "before html" insertion mode.
2610        ## reprocess        ## reprocess
2611        return;        return;
2612      } elsif ($token->{type} == CHARACTER_TOKEN) {      } elsif ($token->{type} == CHARACTER_TOKEN) {
# Line 2272  sub _tree_construction_initial ($) { Line 2614  sub _tree_construction_initial ($) {
2614          ## Ignore the token          ## Ignore the token
2615    
2616          unless (length $token->{data}) {          unless (length $token->{data}) {
2617            ## Stay in the phase            !!!cp ('t15');
2618              ## Stay in the insertion mode.
2619            !!!next-token;            !!!next-token;
2620            redo INITIAL;            redo INITIAL;
2621            } else {
2622              !!!cp ('t16');
2623          }          }
2624          } else {
2625            !!!cp ('t17');
2626        }        }
2627    
2628        !!!parse-error (type => 'no DOCTYPE');        !!!parse-error (type => 'no DOCTYPE');
2629        $self->{document}->manakai_compat_mode ('quirks');        $self->{document}->manakai_compat_mode ('quirks');
2630        ## Go to the root element phase        ## Go to the "before html" insertion mode.
2631        ## reprocess        ## reprocess
2632        return;        return;
2633      } elsif ($token->{type} == COMMENT_TOKEN) {      } elsif ($token->{type} == COMMENT_TOKEN) {
2634          !!!cp ('t18');
2635        my $comment = $self->{document}->create_comment ($token->{data});        my $comment = $self->{document}->create_comment ($token->{data});
2636        $self->{document}->append_child ($comment);        $self->{document}->append_child ($comment);
2637                
2638        ## Stay in the phase.        ## Stay in the insertion mode.
2639        !!!next-token;        !!!next-token;
2640        redo INITIAL;        redo INITIAL;
2641      } else {      } else {
2642        die "$0: $token->{type}: Unknown token type";        die "$0: $token->{type}: Unknown token type";
2643      }      }
2644    } # INITIAL    } # INITIAL
2645    
2646      die "$0: _tree_construction_initial: This should be never reached";
2647  } # _tree_construction_initial  } # _tree_construction_initial
2648    
2649  sub _tree_construction_root_element ($) {  sub _tree_construction_root_element ($) {
2650    my $self = shift;    my $self = shift;
2651    
2652      ## NOTE: "before html" insertion mode.
2653        
2654    B: {    B: {
2655        if ($token->{type} == DOCTYPE_TOKEN) {        if ($token->{type} == DOCTYPE_TOKEN) {
2656            !!!cp ('t19');
2657          !!!parse-error (type => 'in html:#DOCTYPE');          !!!parse-error (type => 'in html:#DOCTYPE');
2658          ## Ignore the token          ## Ignore the token
2659          ## Stay in the phase          ## Stay in the insertion mode.
2660          !!!next-token;          !!!next-token;
2661          redo B;          redo B;
2662        } elsif ($token->{type} == COMMENT_TOKEN) {        } elsif ($token->{type} == COMMENT_TOKEN) {
2663            !!!cp ('t20');
2664          my $comment = $self->{document}->create_comment ($token->{data});          my $comment = $self->{document}->create_comment ($token->{data});
2665          $self->{document}->append_child ($comment);          $self->{document}->append_child ($comment);
2666          ## Stay in the phase          ## Stay in the insertion mode.
2667          !!!next-token;          !!!next-token;
2668          redo B;          redo B;
2669        } elsif ($token->{type} == CHARACTER_TOKEN) {        } elsif ($token->{type} == CHARACTER_TOKEN) {
# Line 2317  sub _tree_construction_root_element ($) Line 2671  sub _tree_construction_root_element ($)
2671            ## Ignore the token.            ## Ignore the token.
2672    
2673            unless (length $token->{data}) {            unless (length $token->{data}) {
2674              ## Stay in the phase              !!!cp ('t21');
2675                ## Stay in the insertion mode.
2676              !!!next-token;              !!!next-token;
2677              redo B;              redo B;
2678              } else {
2679                !!!cp ('t22');
2680            }            }
2681            } else {
2682              !!!cp ('t23');
2683          }          }
2684    
2685          $self->{application_cache_selection}->(undef);          $self->{application_cache_selection}->(undef);
2686    
2687          #          #
2688        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
2689          if ($token->{tag_name} eq 'html' and          if ($token->{tag_name} eq 'html') {
2690              $token->{attributes}->{manifest}) {            my $root_element;
2691            $self->{application_cache_selection}            !!!create-element ($root_element, $token->{tag_name}, $token->{attributes});
2692                 ->($token->{attributes}->{manifest}->{value});            $self->{document}->append_child ($root_element);
2693            ## ISSUE: No relative reference resolution?            push @{$self->{open_elements}}, [$root_element, 'html'];
2694    
2695              if ($token->{attributes}->{manifest}) {
2696                !!!cp ('t24');
2697                $self->{application_cache_selection}
2698                    ->($token->{attributes}->{manifest}->{value});
2699                ## ISSUE: No relative reference resolution?
2700              } else {
2701                !!!cp ('t25');
2702                $self->{application_cache_selection}->(undef);
2703              }
2704    
2705              !!!next-token;
2706              return; ## Go to the "before head" insertion mode.
2707          } else {          } else {
2708            $self->{application_cache_selection}->(undef);            !!!cp ('t25.1');
2709              #
2710          }          }
   
         ## ISSUE: There is an issue in the spec  
         #  
2711        } elsif ({        } elsif ({
2712                  END_TAG_TOKEN, 1,                  END_TAG_TOKEN, 1,
2713                  END_OF_FILE_TOKEN, 1,                  END_OF_FILE_TOKEN, 1,
2714                 }->{$token->{type}}) {                 }->{$token->{type}}) {
2715          $self->{application_cache_selection}->(undef);          !!!cp ('t26');
   
         ## ISSUE: There is an issue in the spec  
2716          #          #
2717        } else {        } else {
2718          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
2719        }        }
2720    
2721        my $root_element; !!!create-element ($root_element, 'html');      my $root_element; !!!create-element ($root_element, 'html');
2722        $self->{document}->append_child ($root_element);      $self->{document}->append_child ($root_element);
2723        push @{$self->{open_elements}}, [$root_element, 'html'];      push @{$self->{open_elements}}, [$root_element, 'html'];
2724        ## reprocess  
2725        #redo B;      $self->{application_cache_selection}->(undef);
2726        return; ## Go to the main phase.  
2727        ## NOTE: Reprocess the token.
2728        return; ## Go to the "before head" insertion mode.
2729    
2730        ## ISSUE: There is an issue in the spec
2731    } # B    } # B
2732    
2733      die "$0: _tree_construction_root_element: This should never be reached";
2734  } # _tree_construction_root_element  } # _tree_construction_root_element
2735    
2736  sub _reset_insertion_mode ($) {  sub _reset_insertion_mode ($) {
# Line 2371  sub _reset_insertion_mode ($) { Line 2745  sub _reset_insertion_mode ($) {
2745            
2746      ## Step 3      ## Step 3
2747      S3: {      S3: {
       ## ISSUE: Oops! "If node is the first node in the stack of open  
       ## elements, then set last to true. If the context element of the  
       ## HTML fragment parsing algorithm is neither a td element nor a  
       ## th element, then set node to the context element. (fragment case)":  
       ## The second "if" is in the scope of the first "if"!?  
2748        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
2749          $last = 1;          $last = 1;
2750          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
2751            if ($self->{inner_html_node}->[1] eq 'td' or            if ($self->{inner_html_node}->[1] eq 'td' or
2752                $self->{inner_html_node}->[1] eq 'th') {                $self->{inner_html_node}->[1] eq 'th') {
2753                !!!cp ('t27');
2754              #              #
2755            } else {            } else {
2756                !!!cp ('t28');
2757              $node = $self->{inner_html_node};              $node = $self->{inner_html_node};
2758            }            }
2759          }          }
# Line 2391  sub _reset_insertion_mode ($) { Line 2762  sub _reset_insertion_mode ($) {
2762        ## Step 4..13        ## Step 4..13
2763        my $new_mode = {        my $new_mode = {
2764                        select => IN_SELECT_IM,                        select => IN_SELECT_IM,
2765                          ## NOTE: |option| and |optgroup| do not set
2766                          ## insertion mode to "in select" by themselves.
2767                        td => IN_CELL_IM,                        td => IN_CELL_IM,
2768                        th => IN_CELL_IM,                        th => IN_CELL_IM,
2769                        tr => IN_ROW_IM,                        tr => IN_ROW_IM,
# Line 2409  sub _reset_insertion_mode ($) { Line 2782  sub _reset_insertion_mode ($) {
2782        ## Step 14        ## Step 14
2783        if ($node->[1] eq 'html') {        if ($node->[1] eq 'html') {
2784          unless (defined $self->{head_element}) {          unless (defined $self->{head_element}) {
2785              !!!cp ('t29');
2786            $self->{insertion_mode} = BEFORE_HEAD_IM;            $self->{insertion_mode} = BEFORE_HEAD_IM;
2787          } else {          } else {
2788              ## ISSUE: Can this state be reached?
2789              !!!cp ('t30');
2790            $self->{insertion_mode} = AFTER_HEAD_IM;            $self->{insertion_mode} = AFTER_HEAD_IM;
2791          }          }
2792          return;          return;
2793          } else {
2794            !!!cp ('t31');
2795        }        }
2796                
2797        ## Step 15        ## Step 15
# Line 2426  sub _reset_insertion_mode ($) { Line 2804  sub _reset_insertion_mode ($) {
2804        ## Step 17        ## Step 17
2805        redo S3;        redo S3;
2806      } # S3      } # S3
2807    
2808      die "$0: _reset_insertion_mode: This line should never be reached";
2809  } # _reset_insertion_mode  } # _reset_insertion_mode
2810    
2811  sub _tree_construction_main ($) {  sub _tree_construction_main ($) {
# Line 2447  sub _tree_construction_main ($) { Line 2827  sub _tree_construction_main ($) {
2827      return if $entry->[0] eq '#marker';      return if $entry->[0] eq '#marker';
2828      for (@{$self->{open_elements}}) {      for (@{$self->{open_elements}}) {
2829        if ($entry->[0] eq $_->[0]) {        if ($entry->[0] eq $_->[0]) {
2830            !!!cp ('t32');
2831          return;          return;
2832        }        }
2833      }      }
# Line 2461  sub _tree_construction_main ($) { Line 2842  sub _tree_construction_main ($) {
2842    
2843        ## Step 6        ## Step 6
2844        if ($entry->[0] eq '#marker') {        if ($entry->[0] eq '#marker') {
2845            !!!cp ('t33_1');
2846          #          #
2847        } else {        } else {
2848          my $in_open_elements;          my $in_open_elements;
2849          OE: for (@{$self->{open_elements}}) {          OE: for (@{$self->{open_elements}}) {
2850            if ($entry->[0] eq $_->[0]) {            if ($entry->[0] eq $_->[0]) {
2851                !!!cp ('t33');
2852              $in_open_elements = 1;              $in_open_elements = 1;
2853              last OE;              last OE;
2854            }            }
2855          }          }
2856          if ($in_open_elements) {          if ($in_open_elements) {
2857              !!!cp ('t34');
2858            #            #
2859          } else {          } else {
2860              ## NOTE: <!DOCTYPE HTML><p><b><i><u></p> <p>X
2861              !!!cp ('t35');
2862            redo S4;            redo S4;
2863          }          }
2864        }        }
# Line 2495  sub _tree_construction_main ($) { Line 2881  sub _tree_construction_main ($) {
2881    
2882        ## Step 11        ## Step 11
2883        unless ($clone->[0] eq $active_formatting_elements->[-1]->[0]) {        unless ($clone->[0] eq $active_formatting_elements->[-1]->[0]) {
2884            !!!cp ('t36');
2885          ## Step 7'          ## Step 7'
2886          $i++;          $i++;
2887          $entry = $active_formatting_elements->[$i];          $entry = $active_formatting_elements->[$i];
2888                    
2889          redo S7;          redo S7;
2890        }        }
2891    
2892          !!!cp ('t37');
2893      } # S7      } # S7
2894    }; # $reconstruct_active_formatting_elements    }; # $reconstruct_active_formatting_elements
2895    
2896    my $clear_up_to_marker = sub {    my $clear_up_to_marker = sub {
2897      for (reverse 0..$#$active_formatting_elements) {      for (reverse 0..$#$active_formatting_elements) {
2898        if ($active_formatting_elements->[$_]->[0] eq '#marker') {        if ($active_formatting_elements->[$_]->[0] eq '#marker') {
2899            !!!cp ('t38');
2900          splice @$active_formatting_elements, $_;          splice @$active_formatting_elements, $_;
2901          return;          return;
2902        }        }
2903      }      }
2904    
2905        !!!cp ('t39');
2906    }; # $clear_up_to_marker    }; # $clear_up_to_marker
2907    
2908    my $parse_rcdata = sub ($$) {    my $insert;
2909      my ($content_model_flag, $insert) = @_;  
2910      my $parse_rcdata = sub ($) {
2911        my ($content_model_flag) = @_;
2912    
2913      ## Step 1      ## Step 1
2914      my $start_tag_name = $token->{tag_name};      my $start_tag_name = $token->{tag_name};
# Line 2522  sub _tree_construction_main ($) { Line 2916  sub _tree_construction_main ($) {
2916      !!!create-element ($el, $start_tag_name, $token->{attributes});      !!!create-element ($el, $start_tag_name, $token->{attributes});
2917    
2918      ## Step 2      ## Step 2
2919      $insert->($el); # /context node/->append_child ($el)      $insert->($el);
2920    
2921      ## Step 3      ## Step 3
2922      $self->{content_model} = $content_model_flag; # CDATA or RCDATA      $self->{content_model} = $content_model_flag; # CDATA or RCDATA
# Line 2532  sub _tree_construction_main ($) { Line 2926  sub _tree_construction_main ($) {
2926      my $text = '';      my $text = '';
2927      !!!next-token;      !!!next-token;
2928      while ($token->{type} == CHARACTER_TOKEN) { # or until stop tokenizing      while ($token->{type} == CHARACTER_TOKEN) { # or until stop tokenizing
2929          !!!cp ('t40');
2930        $text .= $token->{data};        $text .= $token->{data};
2931        !!!next-token;        !!!next-token;
2932      }      }
2933    
2934      ## Step 5      ## Step 5
2935      if (length $text) {      if (length $text) {
2936          !!!cp ('t41');
2937        my $text = $self->{document}->create_text_node ($text);        my $text = $self->{document}->create_text_node ($text);
2938        $el->append_child ($text);        $el->append_child ($text);
2939      }      }
# Line 2546  sub _tree_construction_main ($) { Line 2942  sub _tree_construction_main ($) {
2942      $self->{content_model} = PCDATA_CONTENT_MODEL;      $self->{content_model} = PCDATA_CONTENT_MODEL;
2943    
2944      ## Step 7      ## Step 7
2945      if ($token->{type} == END_TAG_TOKEN and $token->{tag_name} eq $start_tag_name) {      if ($token->{type} == END_TAG_TOKEN and
2946            $token->{tag_name} eq $start_tag_name) {
2947          !!!cp ('t42');
2948        ## Ignore the token        ## Ignore the token
     } elsif ($content_model_flag == CDATA_CONTENT_MODEL) {  
       !!!parse-error (type => 'in CDATA:#'.$token->{type});  
     } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {  
       !!!parse-error (type => 'in RCDATA:#'.$token->{type});  
2949      } else {      } else {
2950        die "$0: $content_model_flag in parse_rcdata";        ## NOTE: An end-of-file token.
2951          if ($content_model_flag == CDATA_CONTENT_MODEL) {
2952            !!!cp ('t43');
2953            !!!parse-error (type => 'in CDATA:#'.$token->{type});
2954          } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
2955            !!!cp ('t44');
2956            !!!parse-error (type => 'in RCDATA:#'.$token->{type});
2957          } else {
2958            die "$0: $content_model_flag in parse_rcdata";
2959          }
2960      }      }
2961      !!!next-token;      !!!next-token;
2962    }; # $parse_rcdata    }; # $parse_rcdata
2963    
2964    my $script_start_tag = sub ($) {    my $script_start_tag = sub () {
     my $insert = $_[0];  
2965      my $script_el;      my $script_el;
2966      !!!create-element ($script_el, 'script', $token->{attributes});      !!!create-element ($script_el, 'script', $token->{attributes});
2967      ## TODO: mark as "parser-inserted"      ## TODO: mark as "parser-inserted"
# Line 2570  sub _tree_construction_main ($) { Line 2972  sub _tree_construction_main ($) {
2972      my $text = '';      my $text = '';
2973      !!!next-token;      !!!next-token;
2974      while ($token->{type} == CHARACTER_TOKEN) {      while ($token->{type} == CHARACTER_TOKEN) {
2975          !!!cp ('t45');
2976        $text .= $token->{data};        $text .= $token->{data};
2977        !!!next-token;        !!!next-token;
2978      } # stop if non-character token or tokenizer stops tokenising      } # stop if non-character token or tokenizer stops tokenising
2979      if (length $text) {      if (length $text) {
2980          !!!cp ('t46');
2981        $script_el->manakai_append_text ($text);        $script_el->manakai_append_text ($text);
2982      }      }
2983                                
# Line 2581  sub _tree_construction_main ($) { Line 2985  sub _tree_construction_main ($) {
2985    
2986      if ($token->{type} == END_TAG_TOKEN and      if ($token->{type} == END_TAG_TOKEN and
2987          $token->{tag_name} eq 'script') {          $token->{tag_name} eq 'script') {
2988          !!!cp ('t47');
2989        ## Ignore the token        ## Ignore the token
2990      } else {      } else {
2991          !!!cp ('t48');
2992        !!!parse-error (type => 'in CDATA:#'.$token->{type});        !!!parse-error (type => 'in CDATA:#'.$token->{type});
2993        ## ISSUE: And ignore?        ## ISSUE: And ignore?
2994        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
2995      }      }
2996            
2997      if (defined $self->{inner_html_node}) {      if (defined $self->{inner_html_node}) {
2998          !!!cp ('t49');
2999        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
3000      } else {      } else {
3001          !!!cp ('t50');
3002        ## TODO: $old_insertion_point = current insertion point        ## TODO: $old_insertion_point = current insertion point
3003        ## TODO: insertion point = just before the next input character        ## TODO: insertion point = just before the next input character
3004    
# Line 2604  sub _tree_construction_main ($) { Line 3012  sub _tree_construction_main ($) {
3012      !!!next-token;      !!!next-token;
3013    }; # $script_start_tag    }; # $script_start_tag
3014    
3015      ## NOTE: $open_tables->[-1]->[0] is the "current table" element node.
3016      ## NOTE: $open_tables->[-1]->[1] is the "tainted" flag.
3017      my $open_tables = [[$self->{open_elements}->[0]->[0]]];
3018    
3019    my $formatting_end_tag = sub {    my $formatting_end_tag = sub {
3020      my $tag_name = shift;      my $tag_name = shift;
3021    
3022        ## NOTE: The adoptioon agency algorithm (AAA).
3023    
3024      FET: {      FET: {
3025        ## Step 1        ## Step 1
3026        my $formatting_element;        my $formatting_element;
3027        my $formatting_element_i_in_active;        my $formatting_element_i_in_active;
3028        AFE: for (reverse 0..$#$active_formatting_elements) {        AFE: for (reverse 0..$#$active_formatting_elements) {
3029          if ($active_formatting_elements->[$_]->[1] eq $tag_name) {          if ($active_formatting_elements->[$_]->[1] eq $tag_name) {
3030              !!!cp ('t51');
3031            $formatting_element = $active_formatting_elements->[$_];            $formatting_element = $active_formatting_elements->[$_];
3032            $formatting_element_i_in_active = $_;            $formatting_element_i_in_active = $_;
3033            last AFE;            last AFE;
3034          } elsif ($active_formatting_elements->[$_]->[0] eq '#marker') {          } elsif ($active_formatting_elements->[$_]->[0] eq '#marker') {
3035              !!!cp ('t52');
3036            last AFE;            last AFE;
3037          }          }
3038        } # AFE        } # AFE
3039        unless (defined $formatting_element) {        unless (defined $formatting_element) {
3040            !!!cp ('t53');
3041          !!!parse-error (type => 'unmatched end tag:'.$tag_name);          !!!parse-error (type => 'unmatched end tag:'.$tag_name);
3042          ## Ignore the token          ## Ignore the token
3043          !!!next-token;          !!!next-token;
# Line 2633  sub _tree_construction_main ($) { Line 3050  sub _tree_construction_main ($) {
3050          my $node = $self->{open_elements}->[$_];          my $node = $self->{open_elements}->[$_];
3051          if ($node->[0] eq $formatting_element->[0]) {          if ($node->[0] eq $formatting_element->[0]) {
3052            if ($in_scope) {            if ($in_scope) {
3053                !!!cp ('t54');
3054              $formatting_element_i_in_open = $_;              $formatting_element_i_in_open = $_;
3055              last INSCOPE;              last INSCOPE;
3056            } else { # in open elements but not in scope            } else { # in open elements but not in scope
3057                !!!cp ('t55');
3058              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3059              ## Ignore the token              ## Ignore the token
3060              !!!next-token;              !!!next-token;
# Line 2645  sub _tree_construction_main ($) { Line 3064  sub _tree_construction_main ($) {
3064                    table => 1, caption => 1, td => 1, th => 1,                    table => 1, caption => 1, td => 1, th => 1,
3065                    button => 1, marquee => 1, object => 1, html => 1,                    button => 1, marquee => 1, object => 1, html => 1,
3066                   }->{$node->[1]}) {                   }->{$node->[1]}) {
3067              !!!cp ('t56');
3068            $in_scope = 0;            $in_scope = 0;
3069          }          }
3070        } # INSCOPE        } # INSCOPE
3071        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
3072            !!!cp ('t57');
3073          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3074          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
3075          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
3076          return;          return;
3077        }        }
3078        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
3079            !!!cp ('t58');
3080          !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);          !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3081        }        }
3082                
# Line 2667  sub _tree_construction_main ($) { Line 3089  sub _tree_construction_main ($) {
3089              #not $phrasing_category->{$node->[1]} and              #not $phrasing_category->{$node->[1]} and
3090              ($special_category->{$node->[1]} or              ($special_category->{$node->[1]} or
3091               $scoping_category->{$node->[1]})) {               $scoping_category->{$node->[1]})) {
3092              !!!cp ('t59');
3093            $furthest_block = $node;            $furthest_block = $node;
3094            $furthest_block_i_in_open = $_;            $furthest_block_i_in_open = $_;
3095          } elsif ($node->[0] eq $formatting_element->[0]) {          } elsif ($node->[0] eq $formatting_element->[0]) {
3096              !!!cp ('t60');
3097            last OE;            last OE;
3098          }          }
3099        } # OE        } # OE
3100                
3101        ## Step 3        ## Step 3
3102        unless (defined $furthest_block) { # MUST        unless (defined $furthest_block) { # MUST
3103            !!!cp ('t61');
3104          splice @{$self->{open_elements}}, $formatting_element_i_in_open;          splice @{$self->{open_elements}}, $formatting_element_i_in_open;
3105          splice @$active_formatting_elements, $formatting_element_i_in_active, 1;          splice @$active_formatting_elements, $formatting_element_i_in_active, 1;
3106          !!!next-token;          !!!next-token;
# Line 2688  sub _tree_construction_main ($) { Line 3113  sub _tree_construction_main ($) {
3113        ## Step 5        ## Step 5
3114        my $furthest_block_parent = $furthest_block->[0]->parent_node;        my $furthest_block_parent = $furthest_block->[0]->parent_node;
3115        if (defined $furthest_block_parent) {        if (defined $furthest_block_parent) {
3116            !!!cp ('t62');
3117          $furthest_block_parent->remove_child ($furthest_block->[0]);          $furthest_block_parent->remove_child ($furthest_block->[0]);
3118        }        }
3119                
# Line 2710  sub _tree_construction_main ($) { Line 3136  sub _tree_construction_main ($) {
3136          S7S2: {          S7S2: {
3137            for (reverse 0..$#$active_formatting_elements) {            for (reverse 0..$#$active_formatting_elements) {
3138              if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {              if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {
3139                  !!!cp ('t63');
3140                $node_i_in_active = $_;                $node_i_in_active = $_;
3141                last S7S2;                last S7S2;
3142              }              }
# Line 2723  sub _tree_construction_main ($) { Line 3150  sub _tree_construction_main ($) {
3150                    
3151          ## Step 4          ## Step 4
3152          if ($last_node->[0] eq $furthest_block->[0]) {          if ($last_node->[0] eq $furthest_block->[0]) {
3153              !!!cp ('t64');
3154            $bookmark_prev_el = $node->[0];            $bookmark_prev_el = $node->[0];
3155          }          }
3156                    
3157          ## Step 5          ## Step 5
3158          if ($node->[0]->has_child_nodes ()) {          if ($node->[0]->has_child_nodes ()) {
3159              !!!cp ('t65');
3160            my $clone = [$node->[0]->clone_node (0), $node->[1]];            my $clone = [$node->[0]->clone_node (0), $node->[1]];
3161            $active_formatting_elements->[$node_i_in_active] = $clone;            $active_formatting_elements->[$node_i_in_active] = $clone;
3162            $self->{open_elements}->[$node_i_in_open] = $clone;            $self->{open_elements}->[$node_i_in_open] = $clone;
# Line 2745  sub _tree_construction_main ($) { Line 3174  sub _tree_construction_main ($) {
3174        } # S7          } # S7  
3175                
3176        ## Step 8        ## Step 8
3177        $common_ancestor_node->[0]->append_child ($last_node->[0]);        if ({
3178               table => 1, tbody => 1, tfoot => 1, thead => 1, tr => 1,
3179              }->{$common_ancestor_node->[1]}) {
3180            my $foster_parent_element;
3181            my $next_sibling;
3182                             OE: for (reverse 0..$#{$self->{open_elements}}) {
3183                               if ($self->{open_elements}->[$_]->[1] eq 'table') {
3184                                 my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
3185                                 if (defined $parent and $parent->node_type == 1) {
3186                                   !!!cp ('t65.1');
3187                                   $foster_parent_element = $parent;
3188                                   $next_sibling = $self->{open_elements}->[$_]->[0];
3189                                 } else {
3190                                   !!!cp ('t65.2');
3191                                   $foster_parent_element
3192                                     = $self->{open_elements}->[$_ - 1]->[0];
3193                                 }
3194                                 last OE;
3195                               }
3196                             } # OE
3197                             $foster_parent_element = $self->{open_elements}->[0]->[0]
3198                               unless defined $foster_parent_element;
3199            $foster_parent_element->insert_before ($last_node->[0], $next_sibling);
3200            $open_tables->[-1]->[1] = 1; # tainted
3201          } else {
3202            !!!cp ('t65.3');
3203            $common_ancestor_node->[0]->append_child ($last_node->[0]);
3204          }
3205                
3206        ## Step 9        ## Step 9
3207        my $clone = [$formatting_element->[0]->clone_node (0),        my $clone = [$formatting_element->[0]->clone_node (0),
# Line 2762  sub _tree_construction_main ($) { Line 3218  sub _tree_construction_main ($) {
3218        my $i;        my $i;
3219        AFE: for (reverse 0..$#$active_formatting_elements) {        AFE: for (reverse 0..$#$active_formatting_elements) {
3220          if ($active_formatting_elements->[$_]->[0] eq $formatting_element->[0]) {          if ($active_formatting_elements->[$_]->[0] eq $formatting_element->[0]) {
3221              !!!cp ('t66');
3222            splice @$active_formatting_elements, $_, 1;            splice @$active_formatting_elements, $_, 1;
3223            $i-- and last AFE if defined $i;            $i-- and last AFE if defined $i;
3224          } elsif ($active_formatting_elements->[$_]->[0] eq $bookmark_prev_el) {          } elsif ($active_formatting_elements->[$_]->[0] eq $bookmark_prev_el) {
3225              !!!cp ('t67');
3226            $i = $_;            $i = $_;
3227          }          }
3228        } # AFE        } # AFE
# Line 2774  sub _tree_construction_main ($) { Line 3232  sub _tree_construction_main ($) {
3232        undef $i;        undef $i;
3233        OE: for (reverse 0..$#{$self->{open_elements}}) {        OE: for (reverse 0..$#{$self->{open_elements}}) {
3234          if ($self->{open_elements}->[$_]->[0] eq $formatting_element->[0]) {          if ($self->{open_elements}->[$_]->[0] eq $formatting_element->[0]) {
3235              !!!cp ('t68');
3236            splice @{$self->{open_elements}}, $_, 1;            splice @{$self->{open_elements}}, $_, 1;
3237            $i-- and last OE if defined $i;            $i-- and last OE if defined $i;
3238          } elsif ($self->{open_elements}->[$_]->[0] eq $furthest_block->[0]) {          } elsif ($self->{open_elements}->[$_]->[0] eq $furthest_block->[0]) {
3239              !!!cp ('t69');
3240            $i = $_;            $i = $_;
3241          }          }
3242        } # OE        } # OE
# Line 2787  sub _tree_construction_main ($) { Line 3247  sub _tree_construction_main ($) {
3247      } # FET      } # FET
3248    }; # $formatting_end_tag    }; # $formatting_end_tag
3249    
3250    my $insert_to_current = sub {    $insert = my $insert_to_current = sub {
3251      $self->{open_elements}->[-1]->[0]->append_child ($_[0]);      $self->{open_elements}->[-1]->[0]->append_child ($_[0]);
3252    }; # $insert_to_current    }; # $insert_to_current
3253    
3254    my $insert_to_foster = sub {    my $insert_to_foster = sub {
3255                         my $child = shift;      my $child = shift;
3256                         if ({      if ({
3257                              table => 1, tbody => 1, tfoot => 1,           table => 1, tbody => 1, tfoot => 1, thead => 1, tr => 1,
3258                              thead => 1, tr => 1,          }->{$self->{open_elements}->[-1]->[1]}) {
3259                             }->{$self->{open_elements}->[-1]->[1]}) {        # MUST
3260                           # MUST        my $foster_parent_element;
3261                           my $foster_parent_element;        my $next_sibling;
                          my $next_sibling;  
3262                           OE: for (reverse 0..$#{$self->{open_elements}}) {                           OE: for (reverse 0..$#{$self->{open_elements}}) {
3263                             if ($self->{open_elements}->[$_]->[1] eq 'table') {                             if ($self->{open_elements}->[$_]->[1] eq 'table') {
3264                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
3265                               if (defined $parent and $parent->node_type == 1) {                               if (defined $parent and $parent->node_type == 1) {
3266                                   !!!cp ('t70');
3267                                 $foster_parent_element = $parent;                                 $foster_parent_element = $parent;
3268                                 $next_sibling = $self->{open_elements}->[$_]->[0];                                 $next_sibling = $self->{open_elements}->[$_]->[0];
3269                               } else {                               } else {
3270                                   !!!cp ('t71');
3271                                 $foster_parent_element                                 $foster_parent_element
3272                                   = $self->{open_elements}->[$_ - 1]->[0];                                   = $self->{open_elements}->[$_ - 1]->[0];
3273                               }                               }
# Line 2817  sub _tree_construction_main ($) { Line 3278  sub _tree_construction_main ($) {
3278                             unless defined $foster_parent_element;                             unless defined $foster_parent_element;
3279                           $foster_parent_element->insert_before                           $foster_parent_element->insert_before
3280                             ($child, $next_sibling);                             ($child, $next_sibling);
3281                         } else {        $open_tables->[-1]->[1] = 1; # tainted
3282                           $self->{open_elements}->[-1]->[0]->append_child ($child);      } else {
3283                         }        !!!cp ('t72');
3284          $self->{open_elements}->[-1]->[0]->append_child ($child);
3285        }
3286    }; # $insert_to_foster    }; # $insert_to_foster
3287    
   my $insert;  
   
3288    B: {    B: {
3289      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
3290          !!!cp ('t73');
3291        !!!parse-error (type => 'DOCTYPE in the middle');        !!!parse-error (type => 'DOCTYPE in the middle');
3292        ## Ignore the token        ## Ignore the token
3293        ## Stay in the phase        ## Stay in the phase
# Line 2833  sub _tree_construction_main ($) { Line 3295  sub _tree_construction_main ($) {
3295        redo B;        redo B;
3296      } elsif ($token->{type} == END_OF_FILE_TOKEN) {      } elsif ($token->{type} == END_OF_FILE_TOKEN) {
3297        if ($self->{insertion_mode} & AFTER_HTML_IMS) {        if ($self->{insertion_mode} & AFTER_HTML_IMS) {
3298            !!!cp ('t74');
3299          #          #
3300        } else {        } else {
3301          ## Generate implied end tags          ## Generate implied end tags
3302          if ({          while ({
3303               dd => 1, dt => 1, li => 1, p => 1, td => 1, th => 1, tr => 1,                  dd => 1, dt => 1, li => 1, p => 1,
3304               tbody => 1, tfoot=> 1, thead => 1,                 }->{$self->{open_elements}->[-1]->[1]}) {
3305              }->{$self->{open_elements}->[-1]->[1]}) {            !!!cp ('t75');
3306            !!!back-token;            pop @{$self->{open_elements}};
           $token = {type => END_TAG_TOKEN, tag_name => $self->{open_elements}->[-1]->[1]};  
           redo B;  
3307          }          }
3308                    
3309          if (@{$self->{open_elements}} > 2 or          if (@{$self->{open_elements}} > 2 or
3310              (@{$self->{open_elements}} == 2 and $self->{open_elements}->[1]->[1] ne 'body')) {              (@{$self->{open_elements}} == 2 and $self->{open_elements}->[1]->[1] ne 'body')) {
3311              !!!cp ('t76');
3312            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3313          } elsif (defined $self->{inner_html_node} and          } elsif (defined $self->{inner_html_node} and
3314                   @{$self->{open_elements}} > 1 and                   @{$self->{open_elements}} > 1 and
3315                   $self->{open_elements}->[1]->[1] ne 'body') {                   $self->{open_elements}->[1]->[1] ne 'body') {
3316    ## ISSUE: This case is never reached.
3317              !!!cp ('t77');
3318            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3319            } else {
3320              !!!cp ('t78');
3321          }          }
3322    
3323          ## ISSUE: There is an issue in the spec.          ## ISSUE: There is an issue in the spec.
# Line 2862  sub _tree_construction_main ($) { Line 3328  sub _tree_construction_main ($) {
3328      } elsif ($token->{type} == START_TAG_TOKEN and      } elsif ($token->{type} == START_TAG_TOKEN and
3329               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
3330        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
3331          ## Turn into the main phase          !!!cp ('t79');
3332          !!!parse-error (type => 'after html:html');          !!!parse-error (type => 'after html:html');
3333          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
3334        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
3335          ## Turn into the main phase          !!!cp ('t80');
3336          !!!parse-error (type => 'after html:html');          !!!parse-error (type => 'after html:html');
3337          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
3338          } else {
3339            !!!cp ('t81');
3340        }        }
3341    
3342  ## ISSUE: "aa<html>" is not a parse error.        !!!cp ('t82');
3343  ## ISSUE: "<html>" in fragment is not a parse error.        !!!parse-error (type => 'not first start tag');
       unless ($token->{first_start_tag}) {  
         !!!parse-error (type => 'not first start tag');  
       }  
3344        my $top_el = $self->{open_elements}->[0]->[0];        my $top_el = $self->{open_elements}->[0]->[0];
3345        for my $attr_name (keys %{$token->{attributes}}) {        for my $attr_name (keys %{$token->{attributes}}) {
3346          unless ($top_el->has_attribute_ns (undef, $attr_name)) {          unless ($top_el->has_attribute_ns (undef, $attr_name)) {
3347              !!!cp ('t84');
3348            $top_el->set_attribute_ns            $top_el->set_attribute_ns
3349              (undef, [undef, $attr_name],              (undef, [undef, $attr_name],
3350               $token->{attributes}->{$attr_name}->{value});               $token->{attributes}->{$attr_name}->{value});
# Line 2889  sub _tree_construction_main ($) { Line 3355  sub _tree_construction_main ($) {
3355      } elsif ($token->{type} == COMMENT_TOKEN) {      } elsif ($token->{type} == COMMENT_TOKEN) {
3356        my $comment = $self->{document}->create_comment ($token->{data});        my $comment = $self->{document}->create_comment ($token->{data});
3357        if ($self->{insertion_mode} & AFTER_HTML_IMS) {        if ($self->{insertion_mode} & AFTER_HTML_IMS) {
3358            !!!cp ('t85');
3359          $self->{document}->append_child ($comment);          $self->{document}->append_child ($comment);
3360        } elsif ($self->{insertion_mode} == AFTER_BODY_IM) {        } elsif ($self->{insertion_mode} == AFTER_BODY_IM) {
3361            !!!cp ('t86');
3362          $self->{open_elements}->[0]->[0]->append_child ($comment);          $self->{open_elements}->[0]->[0]->append_child ($comment);
3363        } else {        } else {
3364            !!!cp ('t87');
3365          $self->{open_elements}->[-1]->[0]->append_child ($comment);          $self->{open_elements}->[-1]->[0]->append_child ($comment);
3366        }        }
3367        !!!next-token;        !!!next-token;
# Line 2900  sub _tree_construction_main ($) { Line 3369  sub _tree_construction_main ($) {
3369      } elsif ($self->{insertion_mode} & HEAD_IMS) {      } elsif ($self->{insertion_mode} & HEAD_IMS) {
3370        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
3371          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3372            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            unless ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3373                !!!cp ('t88.2');
3374                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
3375              } else {
3376                !!!cp ('t88.1');
3377                ## Ignore the token.
3378                !!!next-token;
3379                redo B;
3380              }
3381            unless (length $token->{data}) {            unless (length $token->{data}) {
3382                !!!cp ('t88');
3383              !!!next-token;              !!!next-token;
3384              redo B;              redo B;
3385            }            }
3386          }          }
3387    
3388          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3389              !!!cp ('t89');
3390            ## As if <head>            ## As if <head>
3391            !!!create-element ($self->{head_element}, 'head');            !!!create-element ($self->{head_element}, 'head');
3392            $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});            $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 2918  sub _tree_construction_main ($) { Line 3397  sub _tree_construction_main ($) {
3397    
3398            ## Reprocess in the "after head" insertion mode...            ## Reprocess in the "after head" insertion mode...
3399          } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {          } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3400              !!!cp ('t90');
3401            ## As if </noscript>            ## As if </noscript>
3402            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
3403            !!!parse-error (type => 'in noscript:#character');            !!!parse-error (type => 'in noscript:#character');
# Line 2928  sub _tree_construction_main ($) { Line 3408  sub _tree_construction_main ($) {
3408    
3409            ## Reprocess in the "after head" insertion mode...            ## Reprocess in the "after head" insertion mode...
3410          } elsif ($self->{insertion_mode} == IN_HEAD_IM) {          } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3411              !!!cp ('t91');
3412            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
3413    
3414            ## Reprocess in the "after head" insertion mode...            ## Reprocess in the "after head" insertion mode...
3415            } else {
3416              !!!cp ('t92');
3417          }          }
3418    
3419              ## "after head" insertion mode              ## "after head" insertion mode
# Line 2942  sub _tree_construction_main ($) { Line 3425  sub _tree_construction_main ($) {
3425            } elsif ($token->{type} == START_TAG_TOKEN) {            } elsif ($token->{type} == START_TAG_TOKEN) {
3426              if ($token->{tag_name} eq 'head') {              if ($token->{tag_name} eq 'head') {
3427                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3428                    !!!cp ('t93');
3429                  !!!create-element ($self->{head_element}, $token->{tag_name}, $token->{attributes});                  !!!create-element ($self->{head_element}, $token->{tag_name}, $token->{attributes});
3430                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
3431                  push @{$self->{open_elements}}, [$self->{head_element}, $token->{tag_name}];                  push @{$self->{open_elements}}, [$self->{head_element}, $token->{tag_name}];
# Line 2949  sub _tree_construction_main ($) { Line 3433  sub _tree_construction_main ($) {
3433                  !!!next-token;                  !!!next-token;
3434                  redo B;                  redo B;
3435                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
3436                    !!!cp ('t94');
3437                  #                  #
3438                } else {                } else {
3439                    !!!cp ('t95');
3440                  !!!parse-error (type => 'in head:head'); # or in head noscript                  !!!parse-error (type => 'in head:head'); # or in head noscript
3441                  ## Ignore the token                  ## Ignore the token
3442                  !!!next-token;                  !!!next-token;
3443                  redo B;                  redo B;
3444                }                }
3445              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3446                  !!!cp ('t96');
3447                ## As if <head>                ## As if <head>
3448                !!!create-element ($self->{head_element}, 'head');                !!!create-element ($self->{head_element}, 'head');
3449                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 2964  sub _tree_construction_main ($) { Line 3451  sub _tree_construction_main ($) {
3451    
3452                $self->{insertion_mode} = IN_HEAD_IM;                $self->{insertion_mode} = IN_HEAD_IM;
3453                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
3454                } else {
3455                  !!!cp ('t97');
3456              }              }
3457    
3458              if ($token->{tag_name} eq 'base') {              if ($token->{tag_name} eq 'base') {
3459                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3460                    !!!cp ('t98');
3461                  ## As if </noscript>                  ## As if </noscript>
3462                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3463                  !!!parse-error (type => 'in noscript:base');                  !!!parse-error (type => 'in noscript:base');
3464                                
3465                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3466                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3467                  } else {
3468                    !!!cp ('t99');
3469                }                }
3470    
3471                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3472                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3473                    !!!cp ('t100');
3474                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3475                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3476                  } else {
3477                    !!!cp ('t101');
3478                }                }
3479                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3480                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3481                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3482                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3483                !!!next-token;                !!!next-token;
3484                redo B;                redo B;
3485              } elsif ($token->{tag_name} eq 'link') {              } elsif ($token->{tag_name} eq 'link') {
3486                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3487                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3488                    !!!cp ('t102');
3489                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3490                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3491                  } else {
3492                    !!!cp ('t103');
3493                }                }
3494                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3495                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3496                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3497                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3498                !!!next-token;                !!!next-token;
3499                redo B;                redo B;
3500              } elsif ($token->{tag_name} eq 'meta') {              } elsif ($token->{tag_name} eq 'meta') {
3501                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3502                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3503                    !!!cp ('t104');
3504                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3505                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3506                  } else {
3507                    !!!cp ('t105');
3508                }                }
3509                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3510                my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3511    
3512                unless ($self->{confident}) {                unless ($self->{confident}) {
3513                  if ($token->{attributes}->{charset}) { ## TODO: And if supported                  if ($token->{attributes}->{charset}) { ## TODO: And if supported
3514                      !!!cp ('t106');
3515                    $self->{change_encoding}                    $self->{change_encoding}
3516                        ->($self, $token->{attributes}->{charset}->{value});                        ->($self, $token->{attributes}->{charset}->{value});
3517                                        
# Line 3024  sub _tree_construction_main ($) { Line 3526  sub _tree_construction_main ($) {
3526                            [\x09-\x0D\x20]*=                            [\x09-\x0D\x20]*=
3527                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
3528                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
3529                        !!!cp ('t107');
3530                      $self->{change_encoding}                      $self->{change_encoding}
3531                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);
3532                      $meta_el->[0]->get_attribute_node_ns (undef, 'content')                      $meta_el->[0]->get_attribute_node_ns (undef, 'content')
3533                          ->set_user_data (manakai_has_reference =>                          ->set_user_data (manakai_has_reference =>
3534                                               $token->{attributes}->{content}                                               $token->{attributes}->{content}
3535                                                     ->{has_reference});                                                     ->{has_reference});
3536                      } else {
3537                        !!!cp ('t108');
3538                    }                    }
3539                  }                  }
3540                } else {                } else {
3541                  if ($token->{attributes}->{charset}) {                  if ($token->{attributes}->{charset}) {
3542                      !!!cp ('t109');
3543                    $meta_el->[0]->get_attribute_node_ns (undef, 'charset')                    $meta_el->[0]->get_attribute_node_ns (undef, 'charset')
3544                        ->set_user_data (manakai_has_reference =>                        ->set_user_data (manakai_has_reference =>
3545                                             $token->{attributes}->{charset}                                             $token->{attributes}->{charset}
3546                                                 ->{has_reference});                                                 ->{has_reference});
3547                  }                  }
3548                  if ($token->{attributes}->{content}) {                  if ($token->{attributes}->{content}) {
3549                      !!!cp ('t110');
3550                    $meta_el->[0]->get_attribute_node_ns (undef, 'content')                    $meta_el->[0]->get_attribute_node_ns (undef, 'content')
3551                        ->set_user_data (manakai_has_reference =>                        ->set_user_data (manakai_has_reference =>
3552                                             $token->{attributes}->{content}                                             $token->{attributes}->{content}
# Line 3047  sub _tree_construction_main ($) { Line 3554  sub _tree_construction_main ($) {
3554                  }                  }
3555                }                }
3556    
3557                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3558                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3559                !!!next-token;                !!!next-token;
3560                redo B;                redo B;
3561              } elsif ($token->{tag_name} eq 'title') {              } elsif ($token->{tag_name} eq 'title') {
3562                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3563                    !!!cp ('t111');
3564                  ## As if </noscript>                  ## As if </noscript>
3565                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3566                  !!!parse-error (type => 'in noscript:title');                  !!!parse-error (type => 'in noscript:title');
# Line 3060  sub _tree_construction_main ($) { Line 3568  sub _tree_construction_main ($) {
3568                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3569                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3570                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
3571                    !!!cp ('t112');
3572                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3573                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3574                  } else {
3575                    !!!cp ('t113');
3576                }                }
3577    
3578                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3579                my $parent = defined $self->{head_element} ? $self->{head_element}                my $parent = defined $self->{head_element} ? $self->{head_element}
3580                    : $self->{open_elements}->[-1]->[0];                    : $self->{open_elements}->[-1]->[0];
3581                $parse_rcdata->(RCDATA_CONTENT_MODEL,                $parse_rcdata->(RCDATA_CONTENT_MODEL);
3582                                sub { $parent->append_child ($_[0]) });                pop @{$self->{open_elements}} # <head>
               pop @{$self->{open_elements}}  
3583                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3584                redo B;                redo B;
3585              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style') {
# Line 3077  sub _tree_construction_main ($) { Line 3587  sub _tree_construction_main ($) {
3587                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
3588                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3589                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3590                    !!!cp ('t114');
3591                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3592                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3593                  } else {
3594                    !!!cp ('t115');
3595                }                }
3596                $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);                $parse_rcdata->(CDATA_CONTENT_MODEL);
3597                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3598                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3599                redo B;                redo B;
3600              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
3601                if ($self->{insertion_mode} == IN_HEAD_IM) {                if ($self->{insertion_mode} == IN_HEAD_IM) {
3602                    !!!cp ('t116');
3603                  ## NOTE: and scripting is disalbed                  ## NOTE: and scripting is disalbed
3604                  !!!insert-element ($token->{tag_name}, $token->{attributes});                  !!!insert-element ($token->{tag_name}, $token->{attributes});
3605                  $self->{insertion_mode} = IN_HEAD_NOSCRIPT_IM;                  $self->{insertion_mode} = IN_HEAD_NOSCRIPT_IM;
3606                  !!!next-token;                  !!!next-token;
3607                  redo B;                  redo B;
3608                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3609                    !!!cp ('t117');
3610                  !!!parse-error (type => 'in noscript:noscript');                  !!!parse-error (type => 'in noscript:noscript');
3611                  ## Ignore the token                  ## Ignore the token
3612                  !!!next-token;                  !!!next-token;
3613                  redo B;                  redo B;
3614                } else {                } else {
3615                    !!!cp ('t118');
3616                  #                  #
3617                }                }
3618              } elsif ($token->{tag_name} eq 'script') {              } elsif ($token->{tag_name} eq 'script') {
3619                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3620                    !!!cp ('t119');
3621                  ## As if </noscript>                  ## As if </noscript>
3622                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3623                  !!!parse-error (type => 'in noscript:script');                  !!!parse-error (type => 'in noscript:script');
# Line 3108  sub _tree_construction_main ($) { Line 3625  sub _tree_construction_main ($) {
3625                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3626                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3627                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
3628                    !!!cp ('t120');
3629                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3630                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3631                  } else {
3632                    !!!cp ('t121');
3633                }                }
3634    
3635                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3636                $script_start_tag->($insert_to_current);                $script_start_tag->();
3637                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3638                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3639                redo B;                redo B;
3640              } elsif ($token->{tag_name} eq 'body' or              } elsif ($token->{tag_name} eq 'body' or
3641                       $token->{tag_name} eq 'frameset') {                       $token->{tag_name} eq 'frameset') {
3642                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3643                    !!!cp ('t122');
3644                  ## As if </noscript>                  ## As if </noscript>
3645                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3646                  !!!parse-error (type => 'in noscript:'.$token->{tag_name});                  !!!parse-error (type => 'in noscript:'.$token->{tag_name});
# Line 3130  sub _tree_construction_main ($) { Line 3651  sub _tree_construction_main ($) {
3651                                    
3652                  ## Reprocess in the "after head" insertion mode...                  ## Reprocess in the "after head" insertion mode...
3653                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3654                    !!!cp ('t124');
3655                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3656                                    
3657                  ## Reprocess in the "after head" insertion mode...                  ## Reprocess in the "after head" insertion mode...
3658                  } else {
3659                    !!!cp ('t125');
3660                }                }
3661    
3662                ## "after head" insertion mode                ## "after head" insertion mode
3663                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3664                if ($token->{tag_name} eq 'body') {                if ($token->{tag_name} eq 'body') {
3665                    !!!cp ('t126');
3666                  $self->{insertion_mode} = IN_BODY_IM;                  $self->{insertion_mode} = IN_BODY_IM;
3667                } elsif ($token->{tag_name} eq 'frameset') {                } elsif ($token->{tag_name} eq 'frameset') {
3668                    !!!cp ('t127');
3669                  $self->{insertion_mode} = IN_FRAMESET_IM;                  $self->{insertion_mode} = IN_FRAMESET_IM;
3670                } else {                } else {
3671                  die "$0: tag name: $self->{tag_name}";                  die "$0: tag name: $self->{tag_name}";
# Line 3147  sub _tree_construction_main ($) { Line 3673  sub _tree_construction_main ($) {
3673                !!!next-token;                !!!next-token;
3674                redo B;                redo B;
3675              } else {              } else {
3676                  !!!cp ('t128');
3677                #                #
3678              }              }
3679    
3680              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3681                  !!!cp ('t129');
3682                ## As if </noscript>                ## As if </noscript>
3683                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3684                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});
# Line 3161  sub _tree_construction_main ($) { Line 3689  sub _tree_construction_main ($) {
3689    
3690                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3691              } elsif ($self->{insertion_mode} == IN_HEAD_IM) {              } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3692                  !!!cp ('t130');
3693                ## As if </head>                ## As if </head>
3694                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3695    
3696                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3697                } else {
3698                  !!!cp ('t131');
3699              }              }
3700    
3701              ## "after head" insertion mode              ## "after head" insertion mode
# Line 3176  sub _tree_construction_main ($) { Line 3707  sub _tree_construction_main ($) {
3707            } elsif ($token->{type} == END_TAG_TOKEN) {            } elsif ($token->{type} == END_TAG_TOKEN) {
3708              if ($token->{tag_name} eq 'head') {              if ($token->{tag_name} eq 'head') {
3709                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3710                    !!!cp ('t132');
3711                  ## As if <head>                  ## As if <head>
3712                  !!!create-element ($self->{head_element}, 'head');                  !!!create-element ($self->{head_element}, 'head');
3713                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3187  sub _tree_construction_main ($) { Line 3719  sub _tree_construction_main ($) {
3719                  !!!next-token;                  !!!next-token;
3720                  redo B;                  redo B;
3721                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3722                    !!!cp ('t133');
3723                  ## As if </noscript>                  ## As if </noscript>
3724                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3725                  !!!parse-error (type => 'in noscript:script');                  !!!parse-error (type => 'in noscript:/head');
3726                                    
3727                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3728                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 3197  sub _tree_construction_main ($) { Line 3730  sub _tree_construction_main ($) {
3730                  !!!next-token;                  !!!next-token;
3731                  redo B;                  redo B;
3732                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3733                    !!!cp ('t134');
3734                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3735                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
3736                  !!!next-token;                  !!!next-token;
3737                  redo B;                  redo B;
3738                } else {                } else {
3739                    !!!cp ('t135');
3740                  #                  #
3741                }                }
3742              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
3743                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3744                    !!!cp ('t136');
3745                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3746                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3747                  !!!next-token;                  !!!next-token;
3748                  redo B;                  redo B;
3749                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3750                    !!!cp ('t137');
3751                  !!!parse-error (type => 'unmatched end tag:noscript');                  !!!parse-error (type => 'unmatched end tag:noscript');
3752                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
3753                  !!!next-token;                  !!!next-token;
3754                  redo B;                  redo B;
3755                } else {                } else {
3756                    !!!cp ('t138');
3757                  #                  #
3758                }                }
3759              } elsif ({              } elsif ({
3760                        body => 1, html => 1,                        body => 1, html => 1,
3761                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
3762                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3763                    !!!cp ('t139');
3764                  ## As if <head>                  ## As if <head>
3765                  !!!create-element ($self->{head_element}, 'head');                  !!!create-element ($self->{head_element}, 'head');
3766                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3230  sub _tree_construction_main ($) { Line 3769  sub _tree_construction_main ($) {
3769                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3770                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3771                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3772                    !!!cp ('t140');
3773                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3774                  ## Ignore the token                  ## Ignore the token
3775                  !!!next-token;                  !!!next-token;
3776                  redo B;                  redo B;
3777                  } else {
3778                    !!!cp ('t141');
3779                }                }
3780                                
3781                #                #
# Line 3241  sub _tree_construction_main ($) { Line 3783  sub _tree_construction_main ($) {
3783                        p => 1, br => 1,                        p => 1, br => 1,
3784                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
3785                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3786                    !!!cp ('t142');
3787                  ## As if <head>                  ## As if <head>
3788                  !!!create-element ($self->{head_element}, 'head');                  !!!create-element ($self->{head_element}, 'head');
3789                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3248  sub _tree_construction_main ($) { Line 3791  sub _tree_construction_main ($) {
3791    
3792                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3793                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3794                  } else {
3795                    !!!cp ('t143');
3796                }                }
3797    
3798                #                #
3799              } else {              } else {
3800                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3801                    !!!cp ('t144');
3802                  #                  #
3803                } else {                } else {
3804                    !!!cp ('t145');
3805                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3806                  ## Ignore the token                  ## Ignore the token
3807                  !!!next-token;                  !!!next-token;
# Line 3263  sub _tree_construction_main ($) { Line 3810  sub _tree_construction_main ($) {
3810              }              }
3811    
3812              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3813                  !!!cp ('t146');
3814                ## As if </noscript>                ## As if </noscript>
3815                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3816                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});
# Line 3273  sub _tree_construction_main ($) { Line 3821  sub _tree_construction_main ($) {
3821    
3822                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3823              } elsif ($self->{insertion_mode} == IN_HEAD_IM) {              } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3824                  !!!cp ('t147');
3825                ## As if </head>                ## As if </head>
3826                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3827    
3828                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3829              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3830    ## ISSUE: This case cannot be reached?
3831                  !!!cp ('t148');
3832                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3833                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
3834                !!!next-token;                !!!next-token;
3835                redo B;                redo B;
3836                } else {
3837                  !!!cp ('t149');
3838              }              }
3839    
3840              ## "after head" insertion mode              ## "after head" insertion mode
# Line 3297  sub _tree_construction_main ($) { Line 3850  sub _tree_construction_main ($) {
3850            ## ISSUE: An issue in the spec.            ## ISSUE: An issue in the spec.
3851      } elsif ($self->{insertion_mode} & BODY_IMS) {      } elsif ($self->{insertion_mode} & BODY_IMS) {
3852            if ($token->{type} == CHARACTER_TOKEN) {            if ($token->{type} == CHARACTER_TOKEN) {
3853                !!!cp ('t150');
3854              ## NOTE: There is a code clone of "character in body".              ## NOTE: There is a code clone of "character in body".
3855              $reconstruct_active_formatting_elements->($insert_to_current);              $reconstruct_active_formatting_elements->($insert_to_current);
3856                            
# Line 3315  sub _tree_construction_main ($) { Line 3869  sub _tree_construction_main ($) {
3869                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3870                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
3871                    if ($node->[1] eq 'td' or $node->[1] eq 'th') {                    if ($node->[1] eq 'td' or $node->[1] eq 'th') {
3872                        !!!cp ('t151');
3873                      $tn = $node->[1];                      $tn = $node->[1];
3874                      last INSCOPE;                      last INSCOPE;
3875                    } elsif ({                    } elsif ({
3876                              table => 1, html => 1,                              table => 1, html => 1,
3877                             }->{$node->[1]}) {                             }->{$node->[1]}) {
3878                        !!!cp ('t152');
3879                      last INSCOPE;                      last INSCOPE;
3880                    }                    }
3881                  } # INSCOPE                  } # INSCOPE
3882                    unless (defined $tn) {                    unless (defined $tn) {
3883                        !!!cp ('t153');
3884    ## TODO: This error type is wrong.
3885                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3886                      ## Ignore the token                      ## Ignore the token
3887                      !!!next-token;                      !!!next-token;
3888                      redo B;                      redo B;
3889                    }                    }
3890                                    
3891                    !!!cp ('t154');
3892                  ## Close the cell                  ## Close the cell
3893                  !!!back-token; # <?>                  !!!back-token; # <?>
3894                  $token = {type => END_TAG_TOKEN, tag_name => $tn};                  $token = {type => END_TAG_TOKEN, tag_name => $tn};
# Line 3343  sub _tree_construction_main ($) { Line 3902  sub _tree_construction_main ($) {
3902                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3903                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
3904                    if ($node->[1] eq 'caption') {                    if ($node->[1] eq 'caption') {
3905                        !!!cp ('t155');
3906                      $i = $_;                      $i = $_;
3907                      last INSCOPE;                      last INSCOPE;
3908                    } elsif ({                    } elsif ({
3909                              table => 1, html => 1,                              table => 1, html => 1,
3910                             }->{$node->[1]}) {                             }->{$node->[1]}) {
3911                        !!!cp ('t156');
3912                      last INSCOPE;                      last INSCOPE;
3913                    }                    }
3914                  } # INSCOPE                  } # INSCOPE
3915                    unless (defined $i) {                    unless (defined $i) {
3916                        !!!cp ('t157');
3917    ## TODO: this type is wrong.
3918                      !!!parse-error (type => 'unmatched end tag:caption');                      !!!parse-error (type => 'unmatched end tag:caption');
3919                      ## Ignore the token                      ## Ignore the token
3920                      !!!next-token;                      !!!next-token;
# Line 3359  sub _tree_construction_main ($) { Line 3922  sub _tree_construction_main ($) {
3922                    }                    }
3923                                    
3924                  ## generate implied end tags                  ## generate implied end tags
3925                  if ({                  while ({
3926                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
3927                       td => 1, th => 1, tr => 1,                         }->{$self->{open_elements}->[-1]->[1]}) {
3928                       tbody => 1, tfoot=> 1, thead => 1,                    !!!cp ('t158');
3929                      }->{$self->{open_elements}->[-1]->[1]}) {                    pop @{$self->{open_elements}};
                   !!!back-token; # <?>  
                   $token = {type => END_TAG_TOKEN, tag_name => 'caption'};  
                   !!!back-token;  
                   $token = {type => END_TAG_TOKEN,  
                             tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                   redo B;  
3930                  }                  }
3931    
3932                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
3933                      !!!cp ('t159');
3934                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3935                    } else {
3936                      !!!cp ('t160');
3937                  }                  }
3938                                    
3939                  splice @{$self->{open_elements}}, $i;                  splice @{$self->{open_elements}}, $i;
# Line 3385  sub _tree_construction_main ($) { Line 3945  sub _tree_construction_main ($) {
3945                  ## reprocess                  ## reprocess
3946                  redo B;                  redo B;
3947                } else {                } else {
3948                    !!!cp ('t161');
3949                  #                  #
3950                }                }
3951              } else {              } else {
3952                  !!!cp ('t162');
3953                #                #
3954              }              }
3955            } elsif ($token->{type} == END_TAG_TOKEN) {            } elsif ($token->{type} == END_TAG_TOKEN) {
# Line 3398  sub _tree_construction_main ($) { Line 3960  sub _tree_construction_main ($) {
3960                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3961                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
3962                    if ($node->[1] eq $token->{tag_name}) {                    if ($node->[1] eq $token->{tag_name}) {
3963                        !!!cp ('t163');
3964                      $i = $_;                      $i = $_;
3965                      last INSCOPE;                      last INSCOPE;
3966                    } elsif ({                    } elsif ({
3967                              table => 1, html => 1,                              table => 1, html => 1,
3968                             }->{$node->[1]}) {                             }->{$node->[1]}) {
3969                        !!!cp ('t164');
3970                      last INSCOPE;                      last INSCOPE;
3971                    }                    }
3972                  } # INSCOPE                  } # INSCOPE
3973                    unless (defined $i) {                    unless (defined $i) {
3974                        !!!cp ('t165');
3975                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3976                      ## Ignore the token                      ## Ignore the token
3977                      !!!next-token;                      !!!next-token;
# Line 3414  sub _tree_construction_main ($) { Line 3979  sub _tree_construction_main ($) {
3979                    }                    }
3980                                    
3981                  ## generate implied end tags                  ## generate implied end tags
3982                  if ({                  while ({
3983                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
3984                       td => ($token->{tag_name} eq 'th'),                         }->{$self->{open_elements}->[-1]->[1]}) {
3985                       th => ($token->{tag_name} eq 'td'),                    !!!cp ('t166');
3986                       tr => 1,                    pop @{$self->{open_elements}};
                      tbody => 1, tfoot=> 1, thead => 1,  
                     }->{$self->{open_elements}->[-1]->[1]}) {  
                   !!!back-token;  
                   $token = {type => END_TAG_TOKEN,  
                             tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                   redo B;  
3987                  }                  }
3988                    
3989                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
3990                      !!!cp ('t167');
3991                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3992                    } else {
3993                      !!!cp ('t168');
3994                  }                  }
3995                                    
3996                  splice @{$self->{open_elements}}, $i;                  splice @{$self->{open_elements}}, $i;
# Line 3440  sub _tree_construction_main ($) { Line 4002  sub _tree_construction_main ($) {
4002                  !!!next-token;                  !!!next-token;
4003                  redo B;                  redo B;
4004                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4005                    !!!cp ('t169');
4006                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4007                  ## Ignore the token                  ## Ignore the token
4008                  !!!next-token;                  !!!next-token;
4009                  redo B;                  redo B;
4010                } else {                } else {
4011                    !!!cp ('t170');
4012                  #                  #
4013                }                }
4014              } elsif ($token->{tag_name} eq 'caption') {              } elsif ($token->{tag_name} eq 'caption') {
# Line 3454  sub _tree_construction_main ($) { Line 4018  sub _tree_construction_main ($) {
4018                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4019                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4020                    if ($node->[1] eq $token->{tag_name}) {                    if ($node->[1] eq $token->{tag_name}) {
4021                        !!!cp ('t171');
4022                      $i = $_;                      $i = $_;
4023                      last INSCOPE;                      last INSCOPE;
4024                    } elsif ({                    } elsif ({
4025                              table => 1, html => 1,                              table => 1, html => 1,
4026                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4027                        !!!cp ('t172');
4028                      last INSCOPE;                      last INSCOPE;
4029                    }                    }
4030                  } # INSCOPE                  } # INSCOPE
4031                    unless (defined $i) {                    unless (defined $i) {
4032                        !!!cp ('t173');
4033                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4034                      ## Ignore the token                      ## Ignore the token
4035                      !!!next-token;                      !!!next-token;
# Line 3470  sub _tree_construction_main ($) { Line 4037  sub _tree_construction_main ($) {
4037                    }                    }
4038                                    
4039                  ## generate implied end tags                  ## generate implied end tags
4040                  if ({                  while ({
4041                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
4042                       td => 1, th => 1, tr => 1,                         }->{$self->{open_elements}->[-1]->[1]}) {
4043                       tbody => 1, tfoot=> 1, thead => 1,                    !!!cp ('t174');
4044                      }->{$self->{open_elements}->[-1]->[1]}) {                    pop @{$self->{open_elements}};
                   !!!back-token;  
                   $token = {type => END_TAG_TOKEN,  
                             tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                   redo B;  
4045                  }                  }
4046                                    
4047                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
4048                      !!!cp ('t175');
4049                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4050                    } else {
4051                      !!!cp ('t176');
4052                  }                  }
4053                                    
4054                  splice @{$self->{open_elements}}, $i;                  splice @{$self->{open_elements}}, $i;
# Line 3494  sub _tree_construction_main ($) { Line 4060  sub _tree_construction_main ($) {
4060                  !!!next-token;                  !!!next-token;
4061                  redo B;                  redo B;
4062                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
4063                    !!!cp ('t177');
4064                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4065                  ## Ignore the token                  ## Ignore the token
4066                  !!!next-token;                  !!!next-token;
4067                  redo B;                  redo B;
4068                } else {                } else {
4069                    !!!cp ('t178');
4070                  #                  #
4071                }                }
4072              } elsif ({              } elsif ({
# Line 3512  sub _tree_construction_main ($) { Line 4080  sub _tree_construction_main ($) {
4080                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4081                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4082                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4083                      !!!cp ('t179');
4084                    $i = $_;                    $i = $_;
4085                    last INSCOPE;                    last INSCOPE;
4086                  } elsif ($node->[1] eq 'td' or $node->[1] eq 'th') {                  } elsif ($node->[1] eq 'td' or $node->[1] eq 'th') {
4087                      !!!cp ('t180');
4088                    $tn = $node->[1];                    $tn = $node->[1];
4089                    ## NOTE: There is exactly one |td| or |th| element                    ## NOTE: There is exactly one |td| or |th| element
4090                    ## in scope in the stack of open elements by definition.                    ## in scope in the stack of open elements by definition.
4091                  } elsif ({                  } elsif ({
4092                            table => 1, html => 1,                            table => 1, html => 1,
4093                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4094                      !!!cp ('t181');
4095                    last INSCOPE;                    last INSCOPE;
4096                  }                  }
4097                } # INSCOPE                } # INSCOPE
4098                unless (defined $i) {                unless (defined $i) {
4099                    !!!cp ('t182');
4100                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4101                  ## Ignore the token                  ## Ignore the token
4102                  !!!next-token;                  !!!next-token;
4103                  redo B;                  redo B;
4104                  } else {
4105                    !!!cp ('t183');
4106                }                }
4107    
4108                ## Close the cell                ## Close the cell
# Line 3545  sub _tree_construction_main ($) { Line 4119  sub _tree_construction_main ($) {
4119                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4120                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4121                  if ($node->[1] eq 'caption') {                  if ($node->[1] eq 'caption') {
4122                      !!!cp ('t184');
4123                    $i = $_;                    $i = $_;
4124                    last INSCOPE;                    last INSCOPE;
4125                  } elsif ({                  } elsif ({
4126                            table => 1, html => 1,                            table => 1, html => 1,
4127                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4128                      !!!cp ('t185');
4129                    last INSCOPE;                    last INSCOPE;
4130                  }                  }
4131                } # INSCOPE                } # INSCOPE
4132                unless (defined $i) {                unless (defined $i) {
4133                    !!!cp ('t186');
4134                  !!!parse-error (type => 'unmatched end tag:caption');                  !!!parse-error (type => 'unmatched end tag:caption');
4135                  ## Ignore the token                  ## Ignore the token
4136                  !!!next-token;                  !!!next-token;
# Line 3561  sub _tree_construction_main ($) { Line 4138  sub _tree_construction_main ($) {
4138                }                }
4139                                
4140                ## generate implied end tags                ## generate implied end tags
4141                if ({                while ({
4142                     dd => 1, dt => 1, li => 1, p => 1,                        dd => 1, dt => 1, li => 1, p => 1,
4143                     td => 1, th => 1, tr => 1,                       }->{$self->{open_elements}->[-1]->[1]}) {
4144                     tbody => 1, tfoot=> 1, thead => 1,                  !!!cp ('t187');
4145                    }->{$self->{open_elements}->[-1]->[1]}) {                  pop @{$self->{open_elements}};
                 !!!back-token; # </table>  
                 $token = {type => END_TAG_TOKEN, tag_name => 'caption'};  
                 !!!back-token;  
                 $token = {type => END_TAG_TOKEN,  
                           tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                 redo B;  
4146                }                }
4147    
4148                if ($self->{open_elements}->[-1]->[1] ne 'caption') {                if ($self->{open_elements}->[-1]->[1] ne 'caption') {
4149                    !!!cp ('t188');
4150                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4151                  } else {
4152                    !!!cp ('t189');
4153                }                }
4154    
4155                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
# Line 3590  sub _tree_construction_main ($) { Line 4164  sub _tree_construction_main ($) {
4164                        body => 1, col => 1, colgroup => 1, html => 1,                        body => 1, col => 1, colgroup => 1, html => 1,
4165                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4166                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
4167                    !!!cp ('t190');
4168                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4169                  ## Ignore the token                  ## Ignore the token
4170                  !!!next-token;                  !!!next-token;
4171                  redo B;                  redo B;
4172                } else {                } else {
4173                    !!!cp ('t191');
4174                  #                  #
4175                }                }
4176              } elsif ({              } elsif ({
# Line 3602  sub _tree_construction_main ($) { Line 4178  sub _tree_construction_main ($) {
4178                        thead => 1, tr => 1,                        thead => 1, tr => 1,
4179                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
4180                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
4181                  !!!cp ('t192');
4182                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4183                ## Ignore the token                ## Ignore the token
4184                !!!next-token;                !!!next-token;
4185                redo B;                redo B;
4186              } else {              } else {
4187                  !!!cp ('t193');
4188                #                #
4189              }              }
4190        } else {        } else {
# Line 3617  sub _tree_construction_main ($) { Line 4195  sub _tree_construction_main ($) {
4195        #        #
4196      } elsif ($self->{insertion_mode} & TABLE_IMS) {      } elsif ($self->{insertion_mode} & TABLE_IMS) {
4197        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
4198              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if (not $open_tables->[-1]->[1] and # tainted
4199                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);              $token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4200              $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4201                                
4202                unless (length $token->{data}) {            unless (length $token->{data}) {
4203                  !!!next-token;              !!!cp ('t194');
4204                  redo B;              !!!next-token;
4205                }              redo B;
4206              }            } else {
4207                !!!cp ('t195');
4208              }
4209            }
4210    
4211              !!!parse-error (type => 'in table:#character');              !!!parse-error (type => 'in table:#character');
4212    
# Line 3646  sub _tree_construction_main ($) { Line 4228  sub _tree_construction_main ($) {
4228                  if ($self->{open_elements}->[$_]->[1] eq 'table') {                  if ($self->{open_elements}->[$_]->[1] eq 'table') {
4229                    my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                    my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
4230                    if (defined $parent and $parent->node_type == 1) {                    if (defined $parent and $parent->node_type == 1) {
4231                        !!!cp ('t196');
4232                      $foster_parent_element = $parent;                      $foster_parent_element = $parent;
4233                      $next_sibling = $self->{open_elements}->[$_]->[0];                      $next_sibling = $self->{open_elements}->[$_]->[0];
4234                      $prev_sibling = $next_sibling->previous_sibling;                      $prev_sibling = $next_sibling->previous_sibling;
4235                    } else {                    } else {
4236                        !!!cp ('t197');
4237                      $foster_parent_element = $self->{open_elements}->[$_ - 1]->[0];                      $foster_parent_element = $self->{open_elements}->[$_ - 1]->[0];
4238                      $prev_sibling = $foster_parent_element->last_child;                      $prev_sibling = $foster_parent_element->last_child;
4239                    }                    }
# Line 3661  sub _tree_construction_main ($) { Line 4245  sub _tree_construction_main ($) {
4245                  unless defined $foster_parent_element;                  unless defined $foster_parent_element;
4246                if (defined $prev_sibling and                if (defined $prev_sibling and
4247                    $prev_sibling->node_type == 3) {                    $prev_sibling->node_type == 3) {
4248                    !!!cp ('t198');
4249                  $prev_sibling->manakai_append_text ($token->{data});                  $prev_sibling->manakai_append_text ($token->{data});
4250                } else {                } else {
4251                    !!!cp ('t199');
4252                  $foster_parent_element->insert_before                  $foster_parent_element->insert_before
4253                    ($self->{document}->create_text_node ($token->{data}),                    ($self->{document}->create_text_node ($token->{data}),
4254                     $next_sibling);                     $next_sibling);
4255                }                }
4256              } else {            $open_tables->[-1]->[1] = 1; # tainted
4257                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});          } else {
4258              }            !!!cp ('t200');
4259              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4260            }
4261                            
4262              !!!next-token;          !!!next-token;
4263              redo B;          redo B;
4264        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
4265              if ({              if ({
4266                   tr => ($self->{insertion_mode} != IN_ROW_IM),                   tr => ($self->{insertion_mode} != IN_ROW_IM),
# Line 3682  sub _tree_construction_main ($) { Line 4270  sub _tree_construction_main ($) {
4270                  ## Clear back to table context                  ## Clear back to table context
4271                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4272                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4273                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!cp ('t201');
4274                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4275                  }                  }
4276                                    
# Line 3693  sub _tree_construction_main ($) { Line 4281  sub _tree_construction_main ($) {
4281    
4282                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
4283                  unless ($token->{tag_name} eq 'tr') {                  unless ($token->{tag_name} eq 'tr') {
4284                      !!!cp ('t202');
4285                    !!!parse-error (type => 'missing start tag:tr');                    !!!parse-error (type => 'missing start tag:tr');
4286                  }                  }
4287                                    
# Line 3700  sub _tree_construction_main ($) { Line 4289  sub _tree_construction_main ($) {
4289                  while (not {                  while (not {
4290                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4291                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4292                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!cp ('t203');
4293                      ## ISSUE: Can this case be reached?
4294                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4295                  }                  }
4296                                    
4297                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
4298                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
4299                      !!!cp ('t204');
4300                    !!!insert-element ($token->{tag_name}, $token->{attributes});                    !!!insert-element ($token->{tag_name}, $token->{attributes});
4301                    !!!next-token;                    !!!next-token;
4302                    redo B;                    redo B;
4303                  } else {                  } else {
4304                      !!!cp ('t205');
4305                    !!!insert-element ('tr');                    !!!insert-element ('tr');
4306                    ## reprocess in the "in row" insertion mode                    ## reprocess in the "in row" insertion mode
4307                  }                  }
4308                  } else {
4309                    !!!cp ('t206');
4310                }                }
4311    
4312                ## Clear back to table row context                ## Clear back to table row context
4313                while (not {                while (not {
4314                  tr => 1, html => 1,                  tr => 1, html => 1,
4315                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4316                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!cp ('t207');
4317                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4318                }                }
4319                                
# Line 3742  sub _tree_construction_main ($) { Line 4336  sub _tree_construction_main ($) {
4336                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4337                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4338                    if ($node->[1] eq 'tr') {                    if ($node->[1] eq 'tr') {
4339                        !!!cp ('t208');
4340                      $i = $_;                      $i = $_;
4341                      last INSCOPE;                      last INSCOPE;
4342                    } elsif ({                    } elsif ({
4343                              table => 1, html => 1,                              html => 1,
4344    
4345                                ## NOTE: This element does not appear here, maybe.
4346                                table => 1,
4347                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4348                        !!!cp ('t209');
4349                      last INSCOPE;                      last INSCOPE;
4350                    }                    }
4351                  } # INSCOPE                  } # INSCOPE
4352                  unless (defined $i) {                  unless (defined $i) {
4353                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});                   !!!cp ('t210');
4354    ## TODO: This type is wrong.
4355                     !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});
4356                    ## Ignore the token                    ## Ignore the token
4357                    !!!next-token;                    !!!next-token;
4358                    redo B;                    redo B;
# Line 3761  sub _tree_construction_main ($) { Line 4362  sub _tree_construction_main ($) {
4362                  while (not {                  while (not {
4363                    tr => 1, html => 1,                    tr => 1, html => 1,
4364                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4365                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!cp ('t211');
4366                      ## ISSUE: Can this case be reached?
4367                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4368                  }                  }
4369                                    
4370                  pop @{$self->{open_elements}}; # tr                  pop @{$self->{open_elements}}; # tr
4371                  $self->{insertion_mode} = IN_TABLE_BODY_IM;                  $self->{insertion_mode} = IN_TABLE_BODY_IM;
4372                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
4373                      !!!cp ('t212');
4374                    ## reprocess                    ## reprocess
4375                    redo B;                    redo B;
4376                  } else {                  } else {
4377                      !!!cp ('t213');
4378                    ## reprocess in the "in table body" insertion mode...                    ## reprocess in the "in table body" insertion mode...
4379                  }                  }
4380                }                }
# Line 3783  sub _tree_construction_main ($) { Line 4387  sub _tree_construction_main ($) {
4387                    if ({                    if ({
4388                         tbody => 1, thead => 1, tfoot => 1,                         tbody => 1, thead => 1, tfoot => 1,
4389                        }->{$node->[1]}) {                        }->{$node->[1]}) {
4390                        !!!cp ('t214');
4391                      $i = $_;                      $i = $_;
4392                      last INSCOPE;                      last INSCOPE;
4393                    } elsif ({                    } elsif ({
4394                              table => 1, html => 1,                              table => 1, html => 1,
4395                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4396                        !!!cp ('t215');
4397                      last INSCOPE;                      last INSCOPE;
4398                    }                    }
4399                  } # INSCOPE                  } # INSCOPE
4400                  unless (defined $i) {                  unless (defined $i) {
4401                      !!!cp ('t216');
4402    ## TODO: This erorr type ios wrong.
4403                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4404                    ## Ignore the token                    ## Ignore the token
4405                    !!!next-token;                    !!!next-token;
# Line 3802  sub _tree_construction_main ($) { Line 4410  sub _tree_construction_main ($) {
4410                  while (not {                  while (not {
4411                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4412                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4413                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!cp ('t217');
4414                      ## ISSUE: Can this state be reached?
4415                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4416                  }                  }
4417                                    
# Line 3816  sub _tree_construction_main ($) { Line 4425  sub _tree_construction_main ($) {
4425                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4426                  $self->{insertion_mode} = IN_TABLE_IM;                  $self->{insertion_mode} = IN_TABLE_IM;
4427                  ## reprocess in "in table" insertion mode...                  ## reprocess in "in table" insertion mode...
4428                  } else {
4429                    !!!cp ('t218');
4430                }                }
4431    
4432                if ($token->{tag_name} eq 'col') {                if ($token->{tag_name} eq 'col') {
4433                  ## Clear back to table context                  ## Clear back to table context
4434                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4435                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4436                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!cp ('t219');
4437                      ## ISSUE: Can this state be reached?
4438                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4439                  }                  }
4440                                    
# Line 3838  sub _tree_construction_main ($) { Line 4450  sub _tree_construction_main ($) {
4450                  ## Clear back to table context                  ## Clear back to table context
4451                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4452                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4453                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!cp ('t220');
4454                      ## ISSUE: Can this state be reached?
4455                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4456                  }                  }
4457                                    
# Line 3867  sub _tree_construction_main ($) { Line 4480  sub _tree_construction_main ($) {
4480                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4481                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4482                  if ($node->[1] eq 'table') {                  if ($node->[1] eq 'table') {
4483                      !!!cp ('t221');
4484                    $i = $_;                    $i = $_;
4485                    last INSCOPE;                    last INSCOPE;
4486                  } elsif ({                  } elsif ({
4487                            table => 1, html => 1,                            #table => 1,
4488                              html => 1,
4489                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4490                      !!!cp ('t222');
4491                    last INSCOPE;                    last INSCOPE;
4492                  }                  }
4493                } # INSCOPE                } # INSCOPE
4494                unless (defined $i) {                unless (defined $i) {
4495                    !!!cp ('t223');
4496    ## TODO: The following is wrong, maybe.
4497                  !!!parse-error (type => 'unmatched end tag:table');                  !!!parse-error (type => 'unmatched end tag:table');
4498                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
4499                  !!!next-token;                  !!!next-token;
# Line 3883  sub _tree_construction_main ($) { Line 4501  sub _tree_construction_main ($) {
4501                }                }
4502                                
4503                ## generate implied end tags                ## generate implied end tags
4504                if ({                while ({
4505                     dd => 1, dt => 1, li => 1, p => 1,                        dd => 1, dt => 1, li => 1, p => 1,
4506                     td => 1, th => 1, tr => 1,                       }->{$self->{open_elements}->[-1]->[1]}) {
4507                     tbody => 1, tfoot=> 1, thead => 1,                  !!!cp ('t224');
4508                    }->{$self->{open_elements}->[-1]->[1]}) {                  pop @{$self->{open_elements}};
                 !!!back-token; # <table>  
                 $token = {type => END_TAG_TOKEN, tag_name => 'table'};  
                 !!!back-token;  
                 $token = {type => END_TAG_TOKEN,  
                           tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                 redo B;  
4509                }                }
4510    
4511                if ($self->{open_elements}->[-1]->[1] ne 'table') {                if ($self->{open_elements}->[-1]->[1] ne 'table') {
4512                    !!!cp ('t225');
4513    ## ISSUE: Can this case be reached?
4514                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4515                  } else {
4516                    !!!cp ('t226');
4517                }                }
4518    
4519                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4520                  pop @{$open_tables};
4521    
4522                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
4523    
4524                ## reprocess                ## reprocess
4525                redo B;                redo B;
4526          } else {          } elsif ($token->{tag_name} eq 'style') {
4527            !!!parse-error (type => 'in table:'.$token->{tag_name});            if (not $open_tables->[-1]->[1]) { # tainted
4528                !!!cp ('t227.8');
4529                ## NOTE: This is a "as if in head" code clone.
4530                $parse_rcdata->(CDATA_CONTENT_MODEL);
4531                redo B;
4532              } else {
4533                !!!cp ('t227.7');
4534                #
4535              }
4536            } elsif ($token->{tag_name} eq 'script') {
4537              if (not $open_tables->[-1]->[1]) { # tainted
4538                !!!cp ('t227.6');
4539                ## NOTE: This is a "as if in head" code clone.
4540                $script_start_tag->();
4541                redo B;
4542              } else {
4543                !!!cp ('t227.5');
4544                #
4545              }
4546            } elsif ($token->{tag_name} eq 'input') {
4547              if (not $open_tables->[-1]->[1]) { # tainted
4548                if ($token->{attributes}->{type}) { ## TODO: case
4549                  my $type = lc $token->{attributes}->{type}->{value};
4550                  if ($type eq 'hidden') {
4551                    !!!cp ('t227.3');
4552                    !!!parse-error (type => 'in table:'.$token->{tag_name});
4553    
4554            $insert = $insert_to_foster;                  !!!insert-element ($token->{tag_name}, $token->{attributes});
4555    
4556                    ## TODO: form element pointer
4557    
4558                    pop @{$self->{open_elements}};
4559    
4560                    !!!next-token;
4561                    redo B;
4562                  } else {
4563                    !!!cp ('t227.2');
4564                    #
4565                  }
4566                } else {
4567                  !!!cp ('t227.1');
4568                  #
4569                }
4570              } else {
4571                !!!cp ('t227.4');
4572                #
4573              }
4574            } else {
4575              !!!cp ('t227');
4576            #            #
4577          }          }
4578    
4579            !!!parse-error (type => 'in table:'.$token->{tag_name});
4580    
4581            $insert = $insert_to_foster;
4582            #
4583        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
4584              if ($token->{tag_name} eq 'tr' and              if ($token->{tag_name} eq 'tr' and
4585                  $self->{insertion_mode} == IN_ROW_IM) {                  $self->{insertion_mode} == IN_ROW_IM) {
# Line 3920  sub _tree_construction_main ($) { Line 4588  sub _tree_construction_main ($) {
4588                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4589                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4590                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4591                      !!!cp ('t228');
4592                    $i = $_;                    $i = $_;
4593                    last INSCOPE;                    last INSCOPE;
4594                  } elsif ({                  } elsif ({
4595                            table => 1, html => 1,                            table => 1, html => 1,
4596                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4597                      !!!cp ('t229');
4598                    last INSCOPE;                    last INSCOPE;
4599                  }                  }
4600                } # INSCOPE                } # INSCOPE
4601                unless (defined $i) {                unless (defined $i) {
4602                    !!!cp ('t230');
4603                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4604                  ## Ignore the token                  ## Ignore the token
4605                  !!!next-token;                  !!!next-token;
4606                  redo B;                  redo B;
4607                  } else {
4608                    !!!cp ('t232');
4609                }                }
4610    
4611                ## Clear back to table row context                ## Clear back to table row context
4612                while (not {                while (not {
4613                  tr => 1, html => 1,                  tr => 1, html => 1,
4614                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4615                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!cp ('t231');
4616    ## ISSUE: Can this state be reached?
4617                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4618                }                }
4619    
# Line 3955  sub _tree_construction_main ($) { Line 4629  sub _tree_construction_main ($) {
4629                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4630                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4631                    if ($node->[1] eq 'tr') {                    if ($node->[1] eq 'tr') {
4632                        !!!cp ('t233');
4633                      $i = $_;                      $i = $_;
4634                      last INSCOPE;                      last INSCOPE;
4635                    } elsif ({                    } elsif ({
4636                              table => 1, html => 1,                              table => 1, html => 1,
4637                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4638                        !!!cp ('t234');
4639                      last INSCOPE;                      last INSCOPE;
4640                    }                    }
4641                  } # INSCOPE                  } # INSCOPE
4642                  unless (defined $i) {                  unless (defined $i) {
4643                      !!!cp ('t235');
4644    ## TODO: The following is wrong.
4645                    !!!parse-error (type => 'unmatched end tag:'.$token->{type});                    !!!parse-error (type => 'unmatched end tag:'.$token->{type});
4646                    ## Ignore the token                    ## Ignore the token
4647                    !!!next-token;                    !!!next-token;
# Line 3974  sub _tree_construction_main ($) { Line 4652  sub _tree_construction_main ($) {
4652                  while (not {                  while (not {
4653                    tr => 1, html => 1,                    tr => 1, html => 1,
4654                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4655                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!cp ('t236');
4656    ## ISSUE: Can this state be reached?
4657                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4658                  }                  }
4659                                    
# Line 3991  sub _tree_construction_main ($) { Line 4670  sub _tree_construction_main ($) {
4670                    if ({                    if ({
4671                         tbody => 1, thead => 1, tfoot => 1,                         tbody => 1, thead => 1, tfoot => 1,
4672                        }->{$node->[1]}) {                        }->{$node->[1]}) {
4673                        !!!cp ('t237');
4674                      $i = $_;                      $i = $_;
4675                      last INSCOPE;                      last INSCOPE;
4676                    } elsif ({                    } elsif ({
4677                              table => 1, html => 1,                              table => 1, html => 1,
4678                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4679                        !!!cp ('t238');
4680                      last INSCOPE;                      last INSCOPE;
4681                    }                    }
4682                  } # INSCOPE                  } # INSCOPE
4683                  unless (defined $i) {                  unless (defined $i) {
4684                      !!!cp ('t239');
4685                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4686                    ## Ignore the token                    ## Ignore the token
4687                    !!!next-token;                    !!!next-token;
# Line 4010  sub _tree_construction_main ($) { Line 4692  sub _tree_construction_main ($) {
4692                  while (not {                  while (not {
4693                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4694                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4695                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!cp ('t240');
4696                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4697                  }                  }
4698                                    
# Line 4026  sub _tree_construction_main ($) { Line 4708  sub _tree_construction_main ($) {
4708                  ## reprocess in the "in table" insertion mode...                  ## reprocess in the "in table" insertion mode...
4709                }                }
4710    
4711                  ## NOTE: </table> in the "in table" insertion mode.
4712                  ## When you edit the code fragment below, please ensure that
4713                  ## the code for <table> in the "in table" insertion mode
4714                  ## is synced with it.
4715    
4716                ## have a table element in table scope                ## have a table element in table scope
4717                my $i;                my $i;
4718                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4719                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4720                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4721                      !!!cp ('t241');
4722                    $i = $_;                    $i = $_;
4723                    last INSCOPE;                    last INSCOPE;
4724                  } elsif ({                  } elsif ({
4725                            table => 1, html => 1,                            table => 1, html => 1,
4726                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4727                      !!!cp ('t242');
4728                    last INSCOPE;                    last INSCOPE;
4729                  }                  }
4730                } # INSCOPE                } # INSCOPE
4731                unless (defined $i) {                unless (defined $i) {
4732                    !!!cp ('t243');
4733                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4734                  ## Ignore the token                  ## Ignore the token
4735                  !!!next-token;                  !!!next-token;
4736                  redo B;                  redo B;
4737                }                }
   
               ## generate implied end tags  
               if ({  
                    dd => 1, dt => 1, li => 1, p => 1,  
                    td => 1, th => 1, tr => 1,  
                    tbody => 1, tfoot=> 1, thead => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
                 !!!back-token;  
                 $token = {type => END_TAG_TOKEN,  
                           tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                 redo B;  
               }  
                 
               if ($self->{open_elements}->[-1]->[1] ne 'table') {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
               }  
4738                                    
4739                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4740                  pop @{$open_tables};
4741                                
4742                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
4743                                
# Line 4078  sub _tree_construction_main ($) { Line 4753  sub _tree_construction_main ($) {
4753                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4754                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4755                    if ($node->[1] eq $token->{tag_name}) {                    if ($node->[1] eq $token->{tag_name}) {
4756                        !!!cp ('t247');
4757                      $i = $_;                      $i = $_;
4758                      last INSCOPE;                      last INSCOPE;
4759                    } elsif ({                    } elsif ({
4760                              table => 1, html => 1,                              table => 1, html => 1,
4761                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4762                        !!!cp ('t248');
4763                      last INSCOPE;                      last INSCOPE;
4764                    }                    }
4765                  } # INSCOPE                  } # INSCOPE
4766                    unless (defined $i) {                    unless (defined $i) {
4767                        !!!cp ('t249');
4768                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4769                      ## Ignore the token                      ## Ignore the token
4770                      !!!next-token;                      !!!next-token;
# Line 4099  sub _tree_construction_main ($) { Line 4777  sub _tree_construction_main ($) {
4777                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4778                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4779                    if ($node->[1] eq 'tr') {                    if ($node->[1] eq 'tr') {
4780                        !!!cp ('t250');
4781                      $i = $_;                      $i = $_;
4782                      last INSCOPE;                      last INSCOPE;
4783                    } elsif ({                    } elsif ({
4784                              table => 1, html => 1,                              table => 1, html => 1,
4785                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4786                        !!!cp ('t251');
4787                      last INSCOPE;                      last INSCOPE;
4788                    }                    }
4789                  } # INSCOPE                  } # INSCOPE
4790                    unless (defined $i) {                    unless (defined $i) {
4791                        !!!cp ('t252');
4792                      !!!parse-error (type => 'unmatched end tag:tr');                      !!!parse-error (type => 'unmatched end tag:tr');
4793                      ## Ignore the token                      ## Ignore the token
4794                      !!!next-token;                      !!!next-token;
# Line 4118  sub _tree_construction_main ($) { Line 4799  sub _tree_construction_main ($) {
4799                  while (not {                  while (not {
4800                    tr => 1, html => 1,                    tr => 1, html => 1,
4801                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4802                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!cp ('t253');
4803    ## ISSUE: Can this case be reached?
4804                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4805                  }                  }
4806                                    
# Line 4132  sub _tree_construction_main ($) { Line 4814  sub _tree_construction_main ($) {
4814                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4815                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4816                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4817                      !!!cp ('t254');
4818                    $i = $_;                    $i = $_;
4819                    last INSCOPE;                    last INSCOPE;
4820                  } elsif ({                  } elsif ({
4821                            table => 1, html => 1,                            table => 1, html => 1,
4822                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4823                      !!!cp ('t255');
4824                    last INSCOPE;                    last INSCOPE;
4825                  }                  }
4826                } # INSCOPE                } # INSCOPE
4827                unless (defined $i) {                unless (defined $i) {
4828                    !!!cp ('t256');
4829                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4830                  ## Ignore the token                  ## Ignore the token
4831                  !!!next-token;                  !!!next-token;
# Line 4151  sub _tree_construction_main ($) { Line 4836  sub _tree_construction_main ($) {
4836                while (not {                while (not {
4837                  tbody => 1, tfoot => 1, thead => 1, html => 1,                  tbody => 1, tfoot => 1, thead => 1, html => 1,
4838                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4839                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!cp ('t257');
4840    ## ISSUE: Can this case be reached?
4841                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4842                }                }
4843    
# Line 4165  sub _tree_construction_main ($) { Line 4851  sub _tree_construction_main ($) {
4851                        tr => 1, # $self->{insertion_mode} == IN_ROW_IM                        tr => 1, # $self->{insertion_mode} == IN_ROW_IM
4852                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
4853                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4854                  !!!cp ('t258');
4855                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4856                ## Ignore the token                ## Ignore the token
4857                !!!next-token;                !!!next-token;
4858                redo B;                redo B;
4859          } else {          } else {
4860              !!!cp ('t259');
4861            !!!parse-error (type => 'in table:/'.$token->{tag_name});            !!!parse-error (type => 'in table:/'.$token->{tag_name});
4862    
4863            $insert = $insert_to_foster;            $insert = $insert_to_foster;
# Line 4183  sub _tree_construction_main ($) { Line 4871  sub _tree_construction_main ($) {
4871              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4872                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4873                unless (length $token->{data}) {                unless (length $token->{data}) {
4874                    !!!cp ('t260');
4875                  !!!next-token;                  !!!next-token;
4876                  redo B;                  redo B;
4877                }                }
4878              }              }
4879                            
4880                !!!cp ('t261');
4881              #              #
4882            } elsif ($token->{type} == START_TAG_TOKEN) {            } elsif ($token->{type} == START_TAG_TOKEN) {
4883              if ($token->{tag_name} eq 'col') {              if ($token->{tag_name} eq 'col') {
4884                  !!!cp ('t262');
4885                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
4886                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4887                !!!next-token;                !!!next-token;
4888                redo B;                redo B;
4889              } else {              } else {
4890                  !!!cp ('t263');
4891                #                #
4892              }              }
4893            } elsif ($token->{type} == END_TAG_TOKEN) {            } elsif ($token->{type} == END_TAG_TOKEN) {
4894              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
4895                if ($self->{open_elements}->[-1]->[1] eq 'html') {                if ($self->{open_elements}->[-1]->[1] eq 'html') {
4896                    !!!cp ('t264');
4897                  !!!parse-error (type => 'unmatched end tag:colgroup');                  !!!parse-error (type => 'unmatched end tag:colgroup');
4898                  ## Ignore the token                  ## Ignore the token
4899                  !!!next-token;                  !!!next-token;
4900                  redo B;                  redo B;
4901                } else {                } else {
4902                    !!!cp ('t265');
4903                  pop @{$self->{open_elements}}; # colgroup                  pop @{$self->{open_elements}}; # colgroup
4904                  $self->{insertion_mode} = IN_TABLE_IM;                  $self->{insertion_mode} = IN_TABLE_IM;
4905                  !!!next-token;                  !!!next-token;
4906                  redo B;                              redo B;            
4907                }                }
4908              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
4909                  !!!cp ('t266');
4910                !!!parse-error (type => 'unmatched end tag:col');                !!!parse-error (type => 'unmatched end tag:col');
4911                ## Ignore the token                ## Ignore the token
4912                !!!next-token;                !!!next-token;
4913                redo B;                redo B;
4914              } else {              } else {
4915                  !!!cp ('t267');
4916                #                #
4917              }              }
4918            } else {            } else {
4919              #              die "$0: $token->{type}: Unknown token type";
4920            }            }
4921    
4922            ## As if </colgroup>            ## As if </colgroup>
4923            if ($self->{open_elements}->[-1]->[1] eq 'html') {            if ($self->{open_elements}->[-1]->[1] eq 'html') {
4924                !!!cp ('t269');
4925              !!!parse-error (type => 'unmatched end tag:colgroup');              !!!parse-error (type => 'unmatched end tag:colgroup');
4926              ## Ignore the token              ## Ignore the token
4927              !!!next-token;              !!!next-token;
4928              redo B;              redo B;
4929            } else {            } else {
4930                !!!cp ('t270');
4931              pop @{$self->{open_elements}}; # colgroup              pop @{$self->{open_elements}}; # colgroup
4932              $self->{insertion_mode} = IN_TABLE_IM;              $self->{insertion_mode} = IN_TABLE_IM;
4933              ## reprocess              ## reprocess
4934              redo B;              redo B;
4935            }            }
4936      } elsif ($self->{insertion_mode} == IN_SELECT_IM) {      } elsif ($self->{insertion_mode} & SELECT_IMS) {
4937        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
4938            !!!cp ('t271');
4939          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4940          !!!next-token;          !!!next-token;
4941          redo B;          redo B;
4942        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
4943              if ($token->{tag_name} eq 'option') {              if ($token->{tag_name} eq 'option') {
4944                if ($self->{open_elements}->[-1]->[1] eq 'option') {                if ($self->{open_elements}->[-1]->[1] eq 'option') {
4945                    !!!cp ('t272');
4946                  ## As if </option>                  ## As if </option>
4947                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4948                  } else {
4949                    !!!cp ('t273');
4950                }                }
4951    
4952                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
# Line 4252  sub _tree_construction_main ($) { Line 4954  sub _tree_construction_main ($) {
4954                redo B;                redo B;
4955              } elsif ($token->{tag_name} eq 'optgroup') {              } elsif ($token->{tag_name} eq 'optgroup') {
4956                if ($self->{open_elements}->[-1]->[1] eq 'option') {                if ($self->{open_elements}->[-1]->[1] eq 'option') {
4957                    !!!cp ('t274');
4958                  ## As if </option>                  ## As if </option>
4959                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4960                  } else {
4961                    !!!cp ('t275');
4962                }                }
4963    
4964                if ($self->{open_elements}->[-1]->[1] eq 'optgroup') {                if ($self->{open_elements}->[-1]->[1] eq 'optgroup') {
4965                    !!!cp ('t276');
4966                  ## As if </optgroup>                  ## As if </optgroup>
4967                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4968                  } else {
4969                    !!!cp ('t277');
4970                }                }
4971    
4972                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
4973                !!!next-token;                !!!next-token;
4974                redo B;                redo B;
4975              } elsif ($token->{tag_name} eq 'select') {          } elsif ($token->{tag_name} eq 'select' or
4976                !!!parse-error (type => 'not closed:select');                   $token->{tag_name} eq 'input' or
4977                ## As if </select> instead                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
4978                      {
4979                       caption => 1, table => 1,
4980                       tbody => 1, tfoot => 1, thead => 1,
4981                       tr => 1, td => 1, th => 1,
4982                      }->{$token->{tag_name}})) {
4983              ## TODO: The type below is not good - <select> is replaced by </select>
4984              !!!parse-error (type => 'not closed:select');
4985              ## NOTE: As if the token were </select> (<select> case) or
4986              ## as if there were </select> (otherwise).
4987                ## have an element in table scope                ## have an element in table scope
4988                my $i;                my $i;
4989                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4990                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4991                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq 'select') {
4992                      !!!cp ('t278');
4993                    $i = $_;                    $i = $_;
4994                    last INSCOPE;                    last INSCOPE;
4995                  } elsif ({                  } elsif ({
4996                            table => 1, html => 1,                            table => 1, html => 1,
4997                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4998                      !!!cp ('t279');
4999                    last INSCOPE;                    last INSCOPE;
5000                  }                  }
5001                } # INSCOPE                } # INSCOPE
5002                unless (defined $i) {                unless (defined $i) {
5003                    !!!cp ('t280');
5004                  !!!parse-error (type => 'unmatched end tag:select');                  !!!parse-error (type => 'unmatched end tag:select');
5005                  ## Ignore the token                  ## Ignore the token
5006                  !!!next-token;                  !!!next-token;
5007                  redo B;                  redo B;
5008                }                }
5009                                
5010                  !!!cp ('t281');
5011                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
5012    
5013                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
5014    
5015                !!!next-token;            if ($token->{tag_name} eq 'select') {
5016                redo B;              !!!cp ('t281.2');
5017                !!!next-token;
5018                redo B;
5019              } else {
5020                !!!cp ('t281.1');
5021                ## Reprocess the token.
5022                redo B;
5023              }
5024          } else {          } else {
5025              !!!cp ('t282');
5026            !!!parse-error (type => 'in select:'.$token->{tag_name});            !!!parse-error (type => 'in select:'.$token->{tag_name});
5027            ## Ignore the token            ## Ignore the token
5028            !!!next-token;            !!!next-token;
# Line 4303  sub _tree_construction_main ($) { Line 5032  sub _tree_construction_main ($) {
5032              if ($token->{tag_name} eq 'optgroup') {              if ($token->{tag_name} eq 'optgroup') {
5033                if ($self->{open_elements}->[-1]->[1] eq 'option' and                if ($self->{open_elements}->[-1]->[1] eq 'option' and
5034                    $self->{open_elements}->[-2]->[1] eq 'optgroup') {                    $self->{open_elements}->[-2]->[1] eq 'optgroup') {
5035                    !!!cp ('t283');
5036                  ## As if </option>                  ## As if </option>
5037                  splice @{$self->{open_elements}}, -2;                  splice @{$self->{open_elements}}, -2;
5038                } elsif ($self->{open_elements}->[-1]->[1] eq 'optgroup') {                } elsif ($self->{open_elements}->[-1]->[1] eq 'optgroup') {
5039                    !!!cp ('t284');
5040                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
5041                } else {                } else {
5042                    !!!cp ('t285');
5043                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5044                  ## Ignore the token                  ## Ignore the token
5045                }                }
# Line 4315  sub _tree_construction_main ($) { Line 5047  sub _tree_construction_main ($) {
5047                redo B;                redo B;
5048              } elsif ($token->{tag_name} eq 'option') {              } elsif ($token->{tag_name} eq 'option') {
5049                if ($self->{open_elements}->[-1]->[1] eq 'option') {                if ($self->{open_elements}->[-1]->[1] eq 'option') {
5050                    !!!cp ('t286');
5051                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
5052                } else {                } else {
5053                    !!!cp ('t287');
5054                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5055                  ## Ignore the token                  ## Ignore the token
5056                }                }
# Line 4328  sub _tree_construction_main ($) { Line 5062  sub _tree_construction_main ($) {
5062                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5063                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5064                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
5065                      !!!cp ('t288');
5066                    $i = $_;                    $i = $_;
5067                    last INSCOPE;                    last INSCOPE;
5068                  } elsif ({                  } elsif ({
5069                            table => 1, html => 1,                            table => 1, html => 1,
5070                           }->{$node->[1]}) {                           }->{$node->[1]}) {
5071                      !!!cp ('t289');
5072                    last INSCOPE;                    last INSCOPE;
5073                  }                  }
5074                } # INSCOPE                } # INSCOPE
5075                unless (defined $i) {                unless (defined $i) {
5076                    !!!cp ('t290');
5077                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5078                  ## Ignore the token                  ## Ignore the token
5079                  !!!next-token;                  !!!next-token;
5080                  redo B;                  redo B;
5081                }                }
5082                                
5083                  !!!cp ('t291');
5084                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
5085    
5086                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
5087    
5088                !!!next-token;                !!!next-token;
5089                redo B;                redo B;
5090              } elsif ({          } elsif ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
5091                        caption => 1, table => 1, tbody => 1,                   {
5092                        tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    caption => 1, table => 1, tbody => 1,
5093                       }->{$token->{tag_name}}) {                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
5094                     }->{$token->{tag_name}}) {
5095    ## TODO: The following is wrong?
5096                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5097                                
5098                ## have an element in table scope                ## have an element in table scope
# Line 4360  sub _tree_construction_main ($) { Line 5100  sub _tree_construction_main ($) {
5100                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5101                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5102                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
5103                      !!!cp ('t292');
5104                    $i = $_;                    $i = $_;
5105                    last INSCOPE;                    last INSCOPE;
5106                  } elsif ({                  } elsif ({
5107                            table => 1, html => 1,                            table => 1, html => 1,
5108                           }->{$node->[1]}) {                           }->{$node->[1]}) {
5109                      !!!cp ('t293');
5110                    last INSCOPE;                    last INSCOPE;
5111                  }                  }
5112                } # INSCOPE                } # INSCOPE
5113                unless (defined $i) {                unless (defined $i) {
5114                    !!!cp ('t294');
5115                  ## Ignore the token                  ## Ignore the token
5116                  !!!next-token;                  !!!next-token;
5117                  redo B;                  redo B;
# Line 4380  sub _tree_construction_main ($) { Line 5123  sub _tree_construction_main ($) {
5123                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5124                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5125                  if ($node->[1] eq 'select') {                  if ($node->[1] eq 'select') {
5126                      !!!cp ('t295');
5127                    $i = $_;                    $i = $_;
5128                    last INSCOPE;                    last INSCOPE;
5129                  } elsif ({                  } elsif ({
5130                            table => 1, html => 1,                            table => 1, html => 1,
5131                           }->{$node->[1]}) {                           }->{$node->[1]}) {
5132    ## ISSUE: Can this state be reached?
5133                      !!!cp ('t296');
5134                    last INSCOPE;                    last INSCOPE;
5135                  }                  }
5136                } # INSCOPE                } # INSCOPE
5137                unless (defined $i) {                unless (defined $i) {
5138                    !!!cp ('t297');
5139    ## TODO: The following error type is correct?
5140                  !!!parse-error (type => 'unmatched end tag:select');                  !!!parse-error (type => 'unmatched end tag:select');
5141                  ## Ignore the </select> token                  ## Ignore the </select> token
5142                  !!!next-token; ## TODO: ok?                  !!!next-token; ## TODO: ok?
5143                  redo B;                  redo B;
5144                }                }
5145                                
5146                  !!!cp ('t298');
5147                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
5148    
5149                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
# Line 4402  sub _tree_construction_main ($) { Line 5151  sub _tree_construction_main ($) {
5151                ## reprocess                ## reprocess
5152                redo B;                redo B;
5153          } else {          } else {
5154              !!!cp ('t299');
5155            !!!parse-error (type => 'in select:/'.$token->{tag_name});            !!!parse-error (type => 'in select:/'.$token->{tag_name});
5156            ## Ignore the token            ## Ignore the token
5157            !!!next-token;            !!!next-token;
# Line 4420  sub _tree_construction_main ($) { Line 5170  sub _tree_construction_main ($) {
5170            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
5171                        
5172            unless (length $token->{data}) {            unless (length $token->{data}) {
5173                !!!cp ('t300');
5174              !!!next-token;              !!!next-token;
5175              redo B;              redo B;
5176            }            }
5177          }          }
5178                    
5179          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
5180              !!!cp ('t301');
5181            !!!parse-error (type => 'after html:#character');            !!!parse-error (type => 'after html:#character');
5182    
5183            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "after body" insertion mode.
5184            } else {
5185              !!!cp ('t302');
5186          }          }
5187                    
5188          ## "after body" insertion mode          ## "after body" insertion mode
# Line 4439  sub _tree_construction_main ($) { Line 5193  sub _tree_construction_main ($) {
5193          redo B;          redo B;
5194        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5195          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
5196              !!!cp ('t303');
5197            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
5198                        
5199            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "after body" insertion mode.
5200            } else {
5201              !!!cp ('t304');
5202          }          }
5203    
5204          ## "after body" insertion mode          ## "after body" insertion mode
# Line 4452  sub _tree_construction_main ($) { Line 5209  sub _tree_construction_main ($) {
5209          redo B;          redo B;
5210        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
5211          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
5212              !!!cp ('t305');
5213            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
5214                        
5215            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
5216            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "after body" insertion mode.
5217            } else {
5218              !!!cp ('t306');
5219          }          }
5220    
5221          ## "after body" insertion mode          ## "after body" insertion mode
5222          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
5223            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
5224                !!!cp ('t307');
5225              !!!parse-error (type => 'unmatched end tag:html');              !!!parse-error (type => 'unmatched end tag:html');
5226              ## Ignore the token              ## Ignore the token
5227              !!!next-token;              !!!next-token;
5228              redo B;              redo B;
5229            } else {            } else {
5230                !!!cp ('t308');
5231              $self->{insertion_mode} = AFTER_HTML_BODY_IM;              $self->{insertion_mode} = AFTER_HTML_BODY_IM;
5232              !!!next-token;              !!!next-token;
5233              redo B;              redo B;
5234            }            }
5235          } else {          } else {
5236              !!!cp ('t309');
5237            !!!parse-error (type => 'after body:/'.$token->{tag_name});            !!!parse-error (type => 'after body:/'.$token->{tag_name});
5238    
5239            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
# Line 4486  sub _tree_construction_main ($) { Line 5249  sub _tree_construction_main ($) {
5249            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
5250                        
5251            unless (length $token->{data}) {            unless (length $token->{data}) {
5252                !!!cp ('t310');
5253              !!!next-token;              !!!next-token;
5254              redo B;              redo B;
5255            }            }
# Line 4493  sub _tree_construction_main ($) { Line 5257  sub _tree_construction_main ($) {
5257                    
5258          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
5259            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
5260                !!!cp ('t311');
5261              !!!parse-error (type => 'in frameset:#character');              !!!parse-error (type => 'in frameset:#character');
5262            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
5263                !!!cp ('t312');
5264              !!!parse-error (type => 'after frameset:#character');              !!!parse-error (type => 'after frameset:#character');
5265            } else { # "after html frameset"            } else { # "after html frameset"
5266                !!!cp ('t313');
5267              !!!parse-error (type => 'after html:#character');              !!!parse-error (type => 'after html:#character');
5268    
5269              $self->{insertion_mode} = AFTER_FRAMESET_IM;              $self->{insertion_mode} = AFTER_FRAMESET_IM;
5270              ## Reprocess in the "main" phase, "after frameset"...              ## Reprocess in the "after frameset" insertion mode.
5271              !!!parse-error (type => 'after frameset:#character');              !!!parse-error (type => 'after frameset:#character');
5272            }            }
5273                        
5274            ## Ignore the token.            ## Ignore the token.
5275            if (length $token->{data}) {            if (length $token->{data}) {
5276                !!!cp ('t314');
5277              ## reprocess the rest of characters              ## reprocess the rest of characters
5278            } else {            } else {
5279                !!!cp ('t315');
5280              !!!next-token;              !!!next-token;
5281            }            }
5282            redo B;            redo B;
# Line 4516  sub _tree_construction_main ($) { Line 5285  sub _tree_construction_main ($) {
5285          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
5286        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5287          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
5288              !!!cp ('t316');
5289            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
5290    
5291            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
5292            ## Process in the "main" phase, "after frameset" insertion mode...            ## Process in the "after frameset" insertion mode.
5293          }          } else {
5294              !!!cp ('t317');
5295            }
5296    
5297          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
5298              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
5299              !!!cp ('t318');
5300            !!!insert-element ($token->{tag_name}, $token->{attributes});            !!!insert-element ($token->{tag_name}, $token->{attributes});
5301            !!!next-token;            !!!next-token;
5302            redo B;            redo B;
5303          } elsif ($token->{tag_name} eq 'frame' and          } elsif ($token->{tag_name} eq 'frame' and
5304                   $self->{insertion_mode} == IN_FRAMESET_IM) {                   $self->{insertion_mode} == IN_FRAMESET_IM) {
5305              !!!cp ('t319');
5306            !!!insert-element ($token->{tag_name}, $token->{attributes});            !!!insert-element ($token->{tag_name}, $token->{attributes});
5307            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
5308            !!!next-token;            !!!next-token;
5309            redo B;            redo B;
5310          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
5311              !!!cp ('t320');
5312            ## NOTE: As if in body.            ## NOTE: As if in body.
5313            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);            $parse_rcdata->(CDATA_CONTENT_MODEL);
5314            redo B;            redo B;
5315          } else {          } else {
5316            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
5317                !!!cp ('t321');
5318              !!!parse-error (type => 'in frameset:'.$token->{tag_name});              !!!parse-error (type => 'in frameset:'.$token->{tag_name});
5319            } else {            } else {
5320                !!!cp ('t322');
5321              !!!parse-error (type => 'after frameset:'.$token->{tag_name});              !!!parse-error (type => 'after frameset:'.$token->{tag_name});
5322            }            }
5323            ## Ignore the token            ## Ignore the token
# Line 4549  sub _tree_construction_main ($) { Line 5326  sub _tree_construction_main ($) {
5326          }          }
5327        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
5328          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
5329              !!!cp ('t323');
5330            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
5331    
5332            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
5333            ## Process in the "main" phase, "after frameset" insertion mode...            ## Process in the "after frameset" insertion mode.
5334            } else {
5335              !!!cp ('t324');
5336          }          }
5337    
5338          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
5339              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
5340            if ($self->{open_elements}->[-1]->[1] eq 'html' and            if ($self->{open_elements}->[-1]->[1] eq 'html' and
5341                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
5342                !!!cp ('t325');
5343              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5344              ## Ignore the token              ## Ignore the token
5345              !!!next-token;              !!!next-token;
5346            } else {            } else {
5347                !!!cp ('t326');
5348              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
5349              !!!next-token;              !!!next-token;
5350            }            }
5351    
5352            if (not defined $self->{inner_html_node} and            if (not defined $self->{inner_html_node} and
5353                $self->{open_elements}->[-1]->[1] ne 'frameset') {                $self->{open_elements}->[-1]->[1] ne 'frameset') {
5354                !!!cp ('t327');
5355              $self->{insertion_mode} = AFTER_FRAMESET_IM;              $self->{insertion_mode} = AFTER_FRAMESET_IM;
5356              } else {
5357                !!!cp ('t328');
5358            }            }
5359            redo B;            redo B;
5360          } elsif ($token->{tag_name} eq 'html' and          } elsif ($token->{tag_name} eq 'html' and
5361                   $self->{insertion_mode} == AFTER_FRAMESET_IM) {                   $self->{insertion_mode} == AFTER_FRAMESET_IM) {
5362              !!!cp ('t329');
5363            $self->{insertion_mode} = AFTER_HTML_FRAMESET_IM;            $self->{insertion_mode} = AFTER_HTML_FRAMESET_IM;
5364            !!!next-token;            !!!next-token;
5365            redo B;            redo B;
5366          } else {          } else {
5367            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
5368                !!!cp ('t330');
5369              !!!parse-error (type => 'in frameset:/'.$token->{tag_name});              !!!parse-error (type => 'in frameset:/'.$token->{tag_name});
5370            } else {            } else {
5371                !!!cp ('t331');
5372              !!!parse-error (type => 'after frameset:/'.$token->{tag_name});              !!!parse-error (type => 'after frameset:/'.$token->{tag_name});
5373            }            }
5374            ## Ignore the token            ## Ignore the token
# Line 4599  sub _tree_construction_main ($) { Line 5387  sub _tree_construction_main ($) {
5387      ## "in body" insertion mode      ## "in body" insertion mode
5388      if ($token->{type} == START_TAG_TOKEN) {      if ($token->{type} == START_TAG_TOKEN) {
5389        if ($token->{tag_name} eq 'script') {        if ($token->{tag_name} eq 'script') {
5390            !!!cp ('t332');
5391          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5392          $script_start_tag->($insert);          $script_start_tag->();
5393          redo B;          redo B;
5394        } elsif ($token->{tag_name} eq 'style') {        } elsif ($token->{tag_name} eq 'style') {
5395            !!!cp ('t333');
5396          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5397          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL);
5398          redo B;          redo B;
5399        } elsif ({        } elsif ({
5400                  base => 1, link => 1,                  base => 1, link => 1,
5401                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5402            !!!cp ('t334');
5403          ## NOTE: This is an "as if in head" code clone, only "-t" differs          ## NOTE: This is an "as if in head" code clone, only "-t" differs
5404          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5405          pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.          pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
# Line 4621  sub _tree_construction_main ($) { Line 5412  sub _tree_construction_main ($) {
5412    
5413          unless ($self->{confident}) {          unless ($self->{confident}) {
5414            if ($token->{attributes}->{charset}) { ## TODO: And if supported            if ($token->{attributes}->{charset}) { ## TODO: And if supported
5415                !!!cp ('t335');
5416              $self->{change_encoding}              $self->{change_encoding}
5417                  ->($self, $token->{attributes}->{charset}->{value});                  ->($self, $token->{attributes}->{charset}->{value});
5418                            
# Line 4635  sub _tree_construction_main ($) { Line 5427  sub _tree_construction_main ($) {
5427                      [\x09-\x0D\x20]*=                      [\x09-\x0D\x20]*=
5428                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
5429                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
5430                  !!!cp ('t336');
5431                $self->{change_encoding}                $self->{change_encoding}
5432                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);
5433                $meta_el->[0]->get_attribute_node_ns (undef, 'content')                $meta_el->[0]->get_attribute_node_ns (undef, 'content')
# Line 4645  sub _tree_construction_main ($) { Line 5438  sub _tree_construction_main ($) {
5438            }            }
5439          } else {          } else {
5440            if ($token->{attributes}->{charset}) {            if ($token->{attributes}->{charset}) {
5441                !!!cp ('t337');
5442              $meta_el->[0]->get_attribute_node_ns (undef, 'charset')              $meta_el->[0]->get_attribute_node_ns (undef, 'charset')
5443                  ->set_user_data (manakai_has_reference =>                  ->set_user_data (manakai_has_reference =>
5444                                       $token->{attributes}->{charset}                                       $token->{attributes}->{charset}
5445                                           ->{has_reference});                                           ->{has_reference});
5446            }            }
5447            if ($token->{attributes}->{content}) {            if ($token->{attributes}->{content}) {
5448                !!!cp ('t338');
5449              $meta_el->[0]->get_attribute_node_ns (undef, 'content')              $meta_el->[0]->get_attribute_node_ns (undef, 'content')
5450                  ->set_user_data (manakai_has_reference =>                  ->set_user_data (manakai_has_reference =>
5451                                       $token->{attributes}->{content}                                       $token->{attributes}->{content}
# Line 4661  sub _tree_construction_main ($) { Line 5456  sub _tree_construction_main ($) {
5456          !!!next-token;          !!!next-token;
5457          redo B;          redo B;
5458        } elsif ($token->{tag_name} eq 'title') {        } elsif ($token->{tag_name} eq 'title') {
5459          !!!parse-error (type => 'in body:title');          !!!cp ('t341');
5460          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5461          $parse_rcdata->(RCDATA_CONTENT_MODEL, sub {          $parse_rcdata->(RCDATA_CONTENT_MODEL);
           if (defined $self->{head_element}) {  
             $self->{head_element}->append_child ($_[0]);  
           } else {  
             $insert->($_[0]);  
           }  
         });  
5462          redo B;          redo B;
5463        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
5464          !!!parse-error (type => 'in body:body');          !!!parse-error (type => 'in body:body');
5465                                
5466          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
5467              $self->{open_elements}->[1]->[1] ne 'body') {              $self->{open_elements}->[1]->[1] ne 'body') {
5468              !!!cp ('t342');
5469            ## Ignore the token            ## Ignore the token
5470          } else {          } else {
5471            my $body_el = $self->{open_elements}->[1]->[0];            my $body_el = $self->{open_elements}->[1]->[0];
5472            for my $attr_name (keys %{$token->{attributes}}) {            for my $attr_name (keys %{$token->{attributes}}) {
5473              unless ($body_el->has_attribute_ns (undef, $attr_name)) {              unless ($body_el->has_attribute_ns (undef, $attr_name)) {
5474                  !!!cp ('t343');
5475                $body_el->set_attribute_ns                $body_el->set_attribute_ns
5476                  (undef, [undef, $attr_name],                  (undef, [undef, $attr_name],
5477                   $token->{attributes}->{$attr_name}->{value});                   $token->{attributes}->{$attr_name}->{value});
# Line 4691  sub _tree_construction_main ($) { Line 5482  sub _tree_construction_main ($) {
5482          redo B;          redo B;
5483        } elsif ({        } elsif ({
5484                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
5485                  div => 1, dl => 1, fieldset => 1, listing => 1,                  div => 1, dl => 1, fieldset => 1,
5486                    h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
5487                  menu => 1, ol => 1, p => 1, ul => 1,                  menu => 1, ol => 1, p => 1, ul => 1,
5488                  pre => 1,                  pre => 1, listing => 1,
5489                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5490          ## has a p element in scope          ## has a p element in scope
5491          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5492            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5493                !!!cp ('t344');
5494              !!!back-token;              !!!back-token;
5495              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5496              redo B;              redo B;
# Line 4705  sub _tree_construction_main ($) { Line 5498  sub _tree_construction_main ($) {
5498                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5499                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5500                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5501                !!!cp ('t345');
5502              last INSCOPE;              last INSCOPE;
5503            }            }
5504          } # INSCOPE          } # INSCOPE
5505                        
5506          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5507          if ($token->{tag_name} eq 'pre') {          if ($token->{tag_name} eq 'pre' or $token->{tag_name} eq 'listing') {
5508            !!!next-token;            !!!next-token;
5509            if ($token->{type} == CHARACTER_TOKEN) {            if ($token->{type} == CHARACTER_TOKEN) {
5510              $token->{data} =~ s/^\x0A//;              $token->{data} =~ s/^\x0A//;
5511              unless (length $token->{data}) {              unless (length $token->{data}) {
5512                  !!!cp ('t346');
5513                !!!next-token;                !!!next-token;
5514                } else {
5515                  !!!cp ('t349');
5516              }              }
5517              } else {
5518                !!!cp ('t348');
5519            }            }
5520          } else {          } else {
5521              !!!cp ('t347');
5522            !!!next-token;            !!!next-token;
5523          }          }
5524          redo B;          redo B;
5525        } elsif ($token->{tag_name} eq 'form') {        } elsif ($token->{tag_name} eq 'form') {
5526          if (defined $self->{form_element}) {          if (defined $self->{form_element}) {
5527              !!!cp ('t350');
5528            !!!parse-error (type => 'in form:form');            !!!parse-error (type => 'in form:form');
5529            ## Ignore the token            ## Ignore the token
5530            !!!next-token;            !!!next-token;
# Line 4732  sub _tree_construction_main ($) { Line 5533  sub _tree_construction_main ($) {
5533            ## has a p element in scope            ## has a p element in scope
5534            INSCOPE: for (reverse @{$self->{open_elements}}) {            INSCOPE: for (reverse @{$self->{open_elements}}) {
5535              if ($_->[1] eq 'p') {              if ($_->[1] eq 'p') {
5536                  !!!cp ('t351');
5537                !!!back-token;                !!!back-token;
5538                $token = {type => END_TAG_TOKEN, tag_name => 'p'};                $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5539                redo B;                redo B;
# Line 4739  sub _tree_construction_main ($) { Line 5541  sub _tree_construction_main ($) {
5541                        table => 1, caption => 1, td => 1, th => 1,                        table => 1, caption => 1, td => 1, th => 1,
5542                        button => 1, marquee => 1, object => 1, html => 1,                        button => 1, marquee => 1, object => 1, html => 1,
5543                       }->{$_->[1]}) {                       }->{$_->[1]}) {
5544                  !!!cp ('t352');
5545                last INSCOPE;                last INSCOPE;
5546              }              }
5547            } # INSCOPE            } # INSCOPE
# Line 4752  sub _tree_construction_main ($) { Line 5555  sub _tree_construction_main ($) {
5555          ## has a p element in scope          ## has a p element in scope
5556          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5557            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5558                !!!cp ('t353');
5559              !!!back-token;              !!!back-token;
5560              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5561              redo B;              redo B;
# Line 4759  sub _tree_construction_main ($) { Line 5563  sub _tree_construction_main ($) {
5563                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5564                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5565                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5566                !!!cp ('t354');
5567              last INSCOPE;              last INSCOPE;
5568            }            }
5569          } # INSCOPE          } # INSCOPE
# Line 4770  sub _tree_construction_main ($) { Line 5575  sub _tree_construction_main ($) {
5575            ## Step 2            ## Step 2
5576            if ($node->[1] eq 'li') {            if ($node->[1] eq 'li') {
5577              if ($i != -1) {              if ($i != -1) {
5578                  !!!cp ('t355');
5579                !!!parse-error (type => 'end tag missing:'.                !!!parse-error (type => 'end tag missing:'.
5580                                $self->{open_elements}->[-1]->[1]);                                $self->{open_elements}->[-1]->[1]);
5581                } else {
5582                  !!!cp ('t356');
5583              }              }
5584              splice @{$self->{open_elements}}, $i;              splice @{$self->{open_elements}}, $i;
5585              last LI;              last LI;
5586              } else {
5587                !!!cp ('t357');
5588            }            }
5589                        
5590            ## Step 3            ## Step 3
# Line 4783  sub _tree_construction_main ($) { Line 5593  sub _tree_construction_main ($) {
5593                ($special_category->{$node->[1]} or                ($special_category->{$node->[1]} or
5594                 $scoping_category->{$node->[1]}) and                 $scoping_category->{$node->[1]}) and
5595                $node->[1] ne 'address' and $node->[1] ne 'div') {                $node->[1] ne 'address' and $node->[1] ne 'div') {
5596                !!!cp ('t358');
5597              last LI;              last LI;
5598            }            }
5599                        
5600              !!!cp ('t359');
5601            ## Step 4            ## Step 4
5602            $i--;            $i--;
5603            $node = $self->{open_elements}->[$i];            $node = $self->{open_elements}->[$i];
# Line 4799  sub _tree_construction_main ($) { Line 5611  sub _tree_construction_main ($) {
5611          ## has a p element in scope          ## has a p element in scope
5612          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5613            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5614                !!!cp ('t360');
5615              !!!back-token;              !!!back-token;
5616              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5617              redo B;              redo B;
# Line 4806  sub _tree_construction_main ($) { Line 5619  sub _tree_construction_main ($) {
5619                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5620                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5621                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5622                !!!cp ('t361');
5623              last INSCOPE;              last INSCOPE;
5624            }            }
5625          } # INSCOPE          } # INSCOPE
# Line 4817  sub _tree_construction_main ($) { Line 5631  sub _tree_construction_main ($) {
5631            ## Step 2            ## Step 2
5632            if ($node->[1] eq 'dt' or $node->[1] eq 'dd') {            if ($node->[1] eq 'dt' or $node->[1] eq 'dd') {
5633              if ($i != -1) {              if ($i != -1) {
5634                  !!!cp ('t362');
5635                !!!parse-error (type => 'end tag missing:'.                !!!parse-error (type => 'end tag missing:'.
5636                                $self->{open_elements}->[-1]->[1]);                                $self->{open_elements}->[-1]->[1]);
5637                } else {
5638                  !!!cp ('t363');
5639              }              }
5640              splice @{$self->{open_elements}}, $i;              splice @{$self->{open_elements}}, $i;
5641              last LI;              last LI;
5642              } else {
5643                !!!cp ('t364');
5644            }            }
5645                        
5646            ## Step 3            ## Step 3
# Line 4830  sub _tree_construction_main ($) { Line 5649  sub _tree_construction_main ($) {
5649                ($special_category->{$node->[1]} or                ($special_category->{$node->[1]} or
5650                 $scoping_category->{$node->[1]}) and                 $scoping_category->{$node->[1]}) and
5651                $node->[1] ne 'address' and $node->[1] ne 'div') {                $node->[1] ne 'address' and $node->[1] ne 'div') {
5652                !!!cp ('t365');
5653              last LI;              last LI;
5654            }            }
5655                        
5656              !!!cp ('t366');
5657            ## Step 4            ## Step 4
5658            $i--;            $i--;
5659            $node = $self->{open_elements}->[$i];            $node = $self->{open_elements}->[$i];
# Line 4846  sub _tree_construction_main ($) { Line 5667  sub _tree_construction_main ($) {
5667          ## has a p element in scope          ## has a p element in scope
5668          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5669            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5670                !!!cp ('t367');
5671              !!!back-token;              !!!back-token;
5672              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5673              redo B;              redo B;
# Line 4853  sub _tree_construction_main ($) { Line 5675  sub _tree_construction_main ($) {
5675                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5676                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5677                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5678                !!!cp ('t368');
5679              last INSCOPE;              last INSCOPE;
5680            }            }
5681          } # INSCOPE          } # INSCOPE
# Line 4863  sub _tree_construction_main ($) { Line 5686  sub _tree_construction_main ($) {
5686                        
5687          !!!next-token;          !!!next-token;
5688          redo B;          redo B;
       } elsif ({  
                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,  
                }->{$token->{tag_name}}) {  
         ## has a p element in scope  
         INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
           my $node = $self->{open_elements}->[$_];  
           if ($node->[1] eq 'p') {  
             !!!back-token;  
             $token = {type => END_TAG_TOKEN, tag_name => 'p'};  
             redo B;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         ## NOTE: See <http://html5.org/tools/web-apps-tracker?from=925&to=926>  
         ## has an element in scope  
         #my $i;  
         #INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
         #  my $node = $self->{open_elements}->[$_];  
         #  if ({  
         #       h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,  
         #      }->{$node->[1]}) {  
         #    $i = $_;  
         #    last INSCOPE;  
         #  } elsif ({  
         #            table => 1, caption => 1, td => 1, th => 1,  
         #            button => 1, marquee => 1, object => 1, html => 1,  
         #           }->{$node->[1]}) {  
         #    last INSCOPE;  
         #  }  
         #} # INSCOPE  
         #    
         #if (defined $i) {  
         #  !!! parse-error (type => 'in hn:hn');  
         #  splice @{$self->{open_elements}}, $i;  
         #}  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
             
         !!!next-token;  
         redo B;  
5689        } elsif ($token->{tag_name} eq 'a') {        } elsif ($token->{tag_name} eq 'a') {
5690          AFE: for my $i (reverse 0..$#$active_formatting_elements) {          AFE: for my $i (reverse 0..$#$active_formatting_elements) {
5691            my $node = $active_formatting_elements->[$i];            my $node = $active_formatting_elements->[$i];
5692            if ($node->[1] eq 'a') {            if ($node->[1] eq 'a') {
5693                !!!cp ('t371');
5694              !!!parse-error (type => 'in a:a');              !!!parse-error (type => 'in a:a');
5695                            
5696              !!!back-token;              !!!back-token;
# Line 4920  sub _tree_construction_main ($) { Line 5699  sub _tree_construction_main ($) {
5699                            
5700              AFE2: for (reverse 0..$#$active_formatting_elements) {              AFE2: for (reverse 0..$#$active_formatting_elements) {
5701                if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {                if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {
5702                    !!!cp ('t372');
5703                  splice @$active_formatting_elements, $_, 1;                  splice @$active_formatting_elements, $_, 1;
5704                  last AFE2;                  last AFE2;
5705                }                }
5706              } # AFE2              } # AFE2
5707              OE: for (reverse 0..$#{$self->{open_elements}}) {              OE: for (reverse 0..$#{$self->{open_elements}}) {
5708                if ($self->{open_elements}->[$_]->[0] eq $node->[0]) {                if ($self->{open_elements}->[$_]->[0] eq $node->[0]) {
5709                    !!!cp ('t373');
5710                  splice @{$self->{open_elements}}, $_, 1;                  splice @{$self->{open_elements}}, $_, 1;
5711                  last OE;                  last OE;
5712                }                }
5713              } # OE              } # OE
5714              last AFE;              last AFE;
5715            } elsif ($node->[0] eq '#marker') {            } elsif ($node->[0] eq '#marker') {
5716                !!!cp ('t374');
5717              last AFE;              last AFE;
5718            }            }
5719          } # AFE          } # AFE
# Line 4948  sub _tree_construction_main ($) { Line 5730  sub _tree_construction_main ($) {
5730                  s => 1, small => 1, strile => 1,                  s => 1, small => 1, strile => 1,
5731                  strong => 1, tt => 1, u => 1,                  strong => 1, tt => 1, u => 1,
5732                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5733            !!!cp ('t375');
5734          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5735                    
5736          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 4962  sub _tree_construction_main ($) { Line 5745  sub _tree_construction_main ($) {
5745          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5746            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
5747            if ($node->[1] eq 'nobr') {            if ($node->[1] eq 'nobr') {
5748                !!!cp ('t376');
5749              !!!parse-error (type => 'in nobr:nobr');              !!!parse-error (type => 'in nobr:nobr');
5750              !!!back-token;              !!!back-token;
5751              $token = {type => END_TAG_TOKEN, tag_name => 'nobr'};              $token = {type => END_TAG_TOKEN, tag_name => 'nobr'};
# Line 4970  sub _tree_construction_main ($) { Line 5754  sub _tree_construction_main ($) {
5754                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5755                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5756                     }->{$node->[1]}) {                     }->{$node->[1]}) {
5757                !!!cp ('t377');
5758              last INSCOPE;              last INSCOPE;
5759            }            }
5760          } # INSCOPE          } # INSCOPE
# Line 4984  sub _tree_construction_main ($) { Line 5769  sub _tree_construction_main ($) {
5769          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5770            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
5771            if ($node->[1] eq 'button') {            if ($node->[1] eq 'button') {
5772                !!!cp ('t378');
5773              !!!parse-error (type => 'in button:button');              !!!parse-error (type => 'in button:button');
5774              !!!back-token;              !!!back-token;
5775              $token = {type => END_TAG_TOKEN, tag_name => 'button'};              $token = {type => END_TAG_TOKEN, tag_name => 'button'};
# Line 4992  sub _tree_construction_main ($) { Line 5778  sub _tree_construction_main ($) {
5778                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5779                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5780                     }->{$node->[1]}) {                     }->{$node->[1]}) {
5781                !!!cp ('t379');
5782              last INSCOPE;              last INSCOPE;
5783            }            }
5784          } # INSCOPE          } # INSCOPE
# Line 4999  sub _tree_construction_main ($) { Line 5786  sub _tree_construction_main ($) {
5786          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5787                        
5788          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5789    
5790            ## TODO: associate with $self->{form_element} if defined
5791    
5792          push @$active_formatting_elements, ['#marker', ''];          push @$active_formatting_elements, ['#marker', ''];
5793    
5794          !!!next-token;          !!!next-token;
5795          redo B;          redo B;
5796        } elsif ($token->{tag_name} eq 'marquee' or        } elsif ($token->{tag_name} eq 'marquee' or
5797                 $token->{tag_name} eq 'object') {                 $token->{tag_name} eq 'object') {
5798            !!!cp ('t380');
5799          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5800                    
5801          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 5013  sub _tree_construction_main ($) { Line 5804  sub _tree_construction_main ($) {
5804          !!!next-token;          !!!next-token;
5805          redo B;          redo B;
5806        } elsif ($token->{tag_name} eq 'xmp') {        } elsif ($token->{tag_name} eq 'xmp') {
5807            !!!cp ('t381');
5808          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5809          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL);
5810          redo B;          redo B;
5811        } elsif ($token->{tag_name} eq 'table') {        } elsif ($token->{tag_name} eq 'table') {
5812          ## has a p element in scope          ## has a p element in scope
5813          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5814            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5815                !!!cp ('t382');
5816              !!!back-token;              !!!back-token;
5817              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5818              redo B;              redo B;
# Line 5027  sub _tree_construction_main ($) { Line 5820  sub _tree_construction_main ($) {
5820                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5821                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5822                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5823                !!!cp ('t383');
5824              last INSCOPE;              last INSCOPE;
5825            }            }
5826          } # INSCOPE          } # INSCOPE
5827                        
5828          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5829                      push @{$open_tables}, [$self->{open_elements}->[-1]->[0]];
5830    
5831          $self->{insertion_mode} = IN_TABLE_IM;          $self->{insertion_mode} = IN_TABLE_IM;
5832                        
5833          !!!next-token;          !!!next-token;
# Line 5043  sub _tree_construction_main ($) { Line 5838  sub _tree_construction_main ($) {
5838                  image => 1,                  image => 1,
5839                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5840          if ($token->{tag_name} eq 'image') {          if ($token->{tag_name} eq 'image') {
5841              !!!cp ('t384');
5842            !!!parse-error (type => 'image');            !!!parse-error (type => 'image');
5843            $token->{tag_name} = 'img';            $token->{tag_name} = 'img';
5844            } else {
5845              !!!cp ('t385');
5846          }          }
5847    
5848          ## NOTE: There is an "as if <br>" code clone.          ## NOTE: There is an "as if <br>" code clone.
# Line 5059  sub _tree_construction_main ($) { Line 5857  sub _tree_construction_main ($) {
5857          ## has a p element in scope          ## has a p element in scope
5858          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5859            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5860                !!!cp ('t386');
5861              !!!back-token;              !!!back-token;
5862              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5863              redo B;              redo B;
# Line 5066  sub _tree_construction_main ($) { Line 5865  sub _tree_construction_main ($) {
5865                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5866                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5867                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5868                !!!cp ('t387');
5869              last INSCOPE;              last INSCOPE;
5870            }            }
5871          } # INSCOPE          } # INSCOPE
# Line 5076  sub _tree_construction_main ($) { Line 5876  sub _tree_construction_main ($) {
5876          !!!next-token;          !!!next-token;
5877          redo B;          redo B;
5878        } elsif ($token->{tag_name} eq 'input') {        } elsif ($token->{tag_name} eq 'input') {
5879            !!!cp ('t388');
5880          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5881                    
5882          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 5088  sub _tree_construction_main ($) { Line 5889  sub _tree_construction_main ($) {
5889          !!!parse-error (type => 'isindex');          !!!parse-error (type => 'isindex');
5890                    
5891          if (defined $self->{form_element}) {          if (defined $self->{form_element}) {
5892              !!!cp ('t389');
5893            ## Ignore the token            ## Ignore the token
5894            !!!next-token;            !!!next-token;
5895            redo B;            redo B;
# Line 5107  sub _tree_construction_main ($) { Line 5909  sub _tree_construction_main ($) {
5909                          {type => START_TAG_TOKEN, tag_name => 'label'},                          {type => START_TAG_TOKEN, tag_name => 'label'},
5910                         );                         );
5911            if ($prompt_attr) {            if ($prompt_attr) {
5912                !!!cp ('t390');
5913              push @tokens, {type => CHARACTER_TOKEN, data => $prompt_attr->{value}};              push @tokens, {type => CHARACTER_TOKEN, data => $prompt_attr->{value}};
5914            } else {            } else {
5915                !!!cp ('t391');
5916              push @tokens, {type => CHARACTER_TOKEN,              push @tokens, {type => CHARACTER_TOKEN,
5917                             data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD                             data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD
5918              ## TODO: make this configurable              ## TODO: make this configurable
# Line 5140  sub _tree_construction_main ($) { Line 5944  sub _tree_construction_main ($) {
5944          if ($token->{type} == CHARACTER_TOKEN) {          if ($token->{type} == CHARACTER_TOKEN) {
5945            $token->{data} =~ s/^\x0A//;            $token->{data} =~ s/^\x0A//;
5946            unless (length $token->{data}) {            unless (length $token->{data}) {
5947                !!!cp ('t392');
5948              !!!next-token;              !!!next-token;
5949              } else {
5950                !!!cp ('t393');
5951            }            }
5952            } else {
5953              !!!cp ('t394');
5954          }          }
5955          while ($token->{type} == CHARACTER_TOKEN) {          while ($token->{type} == CHARACTER_TOKEN) {
5956              !!!cp ('t395');
5957            $text .= $token->{data};            $text .= $token->{data};
5958            !!!next-token;            !!!next-token;
5959          }          }
5960          if (length $text) {          if (length $text) {
5961              !!!cp ('t396');
5962            $el->manakai_append_text ($text);            $el->manakai_append_text ($text);
5963          }          }
5964                    
# Line 5155  sub _tree_construction_main ($) { Line 5966  sub _tree_construction_main ($) {
5966                    
5967          if ($token->{type} == END_TAG_TOKEN and          if ($token->{type} == END_TAG_TOKEN and
5968              $token->{tag_name} eq $tag_name) {              $token->{tag_name} eq $tag_name) {
5969              !!!cp ('t397');
5970            ## Ignore the token            ## Ignore the token
5971          } else {          } else {
5972              !!!cp ('t398');
5973            !!!parse-error (type => 'in RCDATA:#'.$token->{type});            !!!parse-error (type => 'in RCDATA:#'.$token->{type});
5974          }          }
5975          !!!next-token;          !!!next-token;
# Line 5167  sub _tree_construction_main ($) { Line 5980  sub _tree_construction_main ($) {
5980                  noframes => 1,                  noframes => 1,
5981                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
5982                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5983            !!!cp ('t399');
5984          ## NOTE: There is an "as if in body" code clone.          ## NOTE: There is an "as if in body" code clone.
5985          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL);
5986          redo B;          redo B;
5987        } elsif ($token->{tag_name} eq 'select') {        } elsif ($token->{tag_name} eq 'select') {
5988            !!!cp ('t400');
5989          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5990                    
5991          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5992    
5993            ## TODO: associate with $self->{form_element} if defined
5994                    
5995          $self->{insertion_mode} = IN_SELECT_IM;          if ($self->{insertion_mode} & TABLE_IMS or
5996                $self->{insertion_mode} & BODY_TABLE_IMS or
5997                $self->{insertion_mode} == IN_COLUMN_GROUP_IM) {
5998              !!!cp ('t400.1');
5999              $self->{insertion_mode} = IN_SELECT_IN_TABLE_IM;
6000            } else {
6001              !!!cp ('t400.2');
6002              $self->{insertion_mode} = IN_SELECT_IM;
6003            }
6004          !!!next-token;          !!!next-token;
6005          redo B;          redo B;
6006        } elsif ({        } elsif ({
# Line 5184  sub _tree_construction_main ($) { Line 6009  sub _tree_construction_main ($) {
6009                  tbody => 1, td => 1, tfoot => 1, th => 1,                  tbody => 1, td => 1, tfoot => 1, th => 1,
6010                  thead => 1, tr => 1,                  thead => 1, tr => 1,
6011                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6012            !!!cp ('t401');
6013          !!!parse-error (type => 'in body:'.$token->{tag_name});          !!!parse-error (type => 'in body:'.$token->{tag_name});
6014          ## Ignore the token          ## Ignore the token
6015          !!!next-token;          !!!next-token;
# Line 5191  sub _tree_construction_main ($) { Line 6017  sub _tree_construction_main ($) {
6017                    
6018          ## ISSUE: An issue on HTML5 new elements in the spec.          ## ISSUE: An issue on HTML5 new elements in the spec.
6019        } else {        } else {
6020            !!!cp ('t402');
6021          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
6022                    
6023          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 5208  sub _tree_construction_main ($) { Line 6035  sub _tree_construction_main ($) {
6035                         th => 1, tr => 1, body => 1, html => 1,                         th => 1, tr => 1, body => 1, html => 1,
6036                       tbody => 1, tfoot => 1, thead => 1,                       tbody => 1, tfoot => 1, thead => 1,
6037                      }->{$_->[1]}) {                      }->{$_->[1]}) {
6038                  !!!cp ('t403');
6039                !!!parse-error (type => 'not closed:'.$_->[1]);                !!!parse-error (type => 'not closed:'.$_->[1]);
6040                } else {
6041                  !!!cp ('t404');
6042              }              }
6043            }            }
6044    
# Line 5216  sub _tree_construction_main ($) { Line 6046  sub _tree_construction_main ($) {
6046            !!!next-token;            !!!next-token;
6047            redo B;            redo B;
6048          } else {          } else {
6049              !!!cp ('t405');
6050            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6051            ## Ignore the token            ## Ignore the token
6052            !!!next-token;            !!!next-token;
# Line 5225  sub _tree_construction_main ($) { Line 6056  sub _tree_construction_main ($) {
6056          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') {
6057            ## ISSUE: There is an issue in the spec.            ## ISSUE: There is an issue in the spec.
6058            if ($self->{open_elements}->[-1]->[1] ne 'body') {            if ($self->{open_elements}->[-1]->[1] ne 'body') {
6059                !!!cp ('t406');
6060              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[1]->[1]);              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[1]->[1]);
6061              } else {
6062                !!!cp ('t407');
6063            }            }
6064            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6065            ## reprocess            ## reprocess
6066            redo B;            redo B;
6067          } else {          } else {
6068              !!!cp ('t408');
6069            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6070            ## Ignore the token            ## Ignore the token
6071            !!!next-token;            !!!next-token;
# Line 5240  sub _tree_construction_main ($) { Line 6075  sub _tree_construction_main ($) {
6075                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
6076                  div => 1, dl => 1, fieldset => 1, listing => 1,                  div => 1, dl => 1, fieldset => 1, listing => 1,
6077                  menu => 1, ol => 1, pre => 1, ul => 1,                  menu => 1, ol => 1, pre => 1, ul => 1,
                 p => 1,  
6078                  dd => 1, dt => 1, li => 1,                  dd => 1, dt => 1, li => 1,
6079                  button => 1, marquee => 1, object => 1,                  button => 1, marquee => 1, object => 1,
6080                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
# Line 5249  sub _tree_construction_main ($) { Line 6083  sub _tree_construction_main ($) {
6083          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6084            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
6085            if ($node->[1] eq $token->{tag_name}) {            if ($node->[1] eq $token->{tag_name}) {
6086              ## generate implied end tags              !!!cp ('t410');
             if ({  
                  dd => ($token->{tag_name} ne 'dd'),  
                  dt => ($token->{tag_name} ne 'dt'),  
                  li => ($token->{tag_name} ne 'li'),  
                  p => ($token->{tag_name} ne 'p'),  
                  td => 1, th => 1, tr => 1,  
                  tbody => 1, tfoot=> 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
               !!!back-token;  
               $token = {type => END_TAG_TOKEN,  
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               redo B;  
             }  
6087              $i = $_;              $i = $_;
6088              last INSCOPE unless $token->{tag_name} eq 'p';              last INSCOPE;
6089            } elsif ({            } elsif ({
6090                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
6091                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6092                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6093                !!!cp ('t411');
6094              last INSCOPE;              last INSCOPE;
6095            }            }
6096          } # INSCOPE          } # INSCOPE
6097            
6098          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          unless (defined $i) { # has an element in scope
6099            if (defined $i) {            !!!cp ('t413');
6100              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6101            } else {
6102              ## Step 1. generate implied end tags
6103              while ({
6104                      dd => ($token->{tag_name} ne 'dd'),
6105                      dt => ($token->{tag_name} ne 'dt'),
6106                      li => ($token->{tag_name} ne 'li'),
6107                      p => 1,
6108                     }->{$self->{open_elements}->[-1]->[1]}) {
6109                !!!cp ('t409');
6110                pop @{$self->{open_elements}};
6111              }
6112    
6113              ## Step 2.
6114              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6115                !!!cp ('t412');
6116              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6117            } else {            } else {
6118              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});              !!!cp ('t414');
6119            }            }
6120          }  
6121                      ## Step 3.
         if (defined $i) {  
6122            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
6123          } elsif ($token->{tag_name} eq 'p') {  
6124            ## As if <p>, then reprocess the current token            ## Step 4.
6125            my $el;            $clear_up_to_marker->()
6126            !!!create-element ($el, 'p');                if {
6127            $insert->($el);                  button => 1, marquee => 1, object => 1,
6128                  }->{$token->{tag_name}};
6129          }          }
         $clear_up_to_marker->()  
           if {  
             button => 1, marquee => 1, object => 1,  
           }->{$token->{tag_name}};  
6130          !!!next-token;          !!!next-token;
6131          redo B;          redo B;
6132        } elsif ($token->{tag_name} eq 'form') {        } elsif ($token->{tag_name} eq 'form') {
6133            undef $self->{form_element};
6134    
6135          ## has an element in scope          ## has an element in scope
6136            my $i;
6137          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6138            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
6139            if ($node->[1] eq $token->{tag_name}) {            if ($node->[1] eq $token->{tag_name}) {
6140              ## generate implied end tags              !!!cp ('t418');
6141              if ({              $i = $_;
                  dd => 1, dt => 1, li => 1, p => 1,  
                  td => 1, th => 1, tr => 1,  
                  tbody => 1, tfoot=> 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
               !!!back-token;  
               $token = {type => END_TAG_TOKEN,  
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               redo B;  
             }  
6142              last INSCOPE;              last INSCOPE;
6143            } elsif ({            } elsif ({
6144                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
6145                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6146                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6147                !!!cp ('t419');
6148              last INSCOPE;              last INSCOPE;
6149            }            }
6150          } # INSCOPE          } # INSCOPE
6151            
6152          if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) {          unless (defined $i) { # has an element in scope
6153            pop @{$self->{open_elements}};            !!!cp ('t421');
         } else {  
6154            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6155            } else {
6156              ## Step 1. generate implied end tags
6157              while ({
6158                      dd => 1, dt => 1, li => 1, p => 1,
6159                     }->{$self->{open_elements}->[-1]->[1]}) {
6160                !!!cp ('t417');
6161                pop @{$self->{open_elements}};
6162              }
6163              
6164              ## Step 2.
6165              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6166                !!!cp ('t417.1');
6167                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6168              } else {
6169                !!!cp ('t420');
6170              }  
6171              
6172              ## Step 3.
6173              splice @{$self->{open_elements}}, $i;
6174          }          }
6175    
         undef $self->{form_element};  
6176          !!!next-token;          !!!next-token;
6177          redo B;          redo B;
6178        } elsif ({        } elsif ({
# Line 5339  sub _tree_construction_main ($) { Line 6185  sub _tree_construction_main ($) {
6185            if ({            if ({
6186                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
6187                }->{$node->[1]}) {                }->{$node->[1]}) {
6188              ## generate implied end tags              !!!cp ('t423');
             if ({  
                  dd => 1, dt => 1, li => 1, p => 1,  
                  td => 1, th => 1, tr => 1,  
                  tbody => 1, tfoot=> 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
               !!!back-token;  
               $token = {type => END_TAG_TOKEN,  
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               redo B;  
             }  
6189              $i = $_;              $i = $_;
6190              last INSCOPE;              last INSCOPE;
6191            } elsif ({            } elsif ({
6192                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
6193                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6194                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6195                !!!cp ('t424');
6196              last INSCOPE;              last INSCOPE;
6197            }            }
6198          } # INSCOPE          } # INSCOPE
6199            
6200          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          unless (defined $i) { # has an element in scope
6201              !!!cp ('t425.1');
6202            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6203            } else {
6204              ## Step 1. generate implied end tags
6205              while ({
6206                      dd => 1, dt => 1, li => 1, p => 1,
6207                     }->{$self->{open_elements}->[-1]->[1]}) {
6208                !!!cp ('t422');
6209                pop @{$self->{open_elements}};
6210              }
6211              
6212              ## Step 2.
6213              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6214                !!!cp ('t425');
6215                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6216              } else {
6217                !!!cp ('t426');
6218              }
6219    
6220              ## Step 3.
6221              splice @{$self->{open_elements}}, $i;
6222          }          }
6223                    
6224          splice @{$self->{open_elements}}, $i if defined $i;          !!!next-token;
6225            redo B;
6226          } elsif ($token->{tag_name} eq 'p') {
6227            ## has an element in scope
6228            my $i;
6229            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6230              my $node = $self->{open_elements}->[$_];
6231              if ($node->[1] eq $token->{tag_name}) {
6232                !!!cp ('t410.1');
6233                $i = $_;
6234                last INSCOPE;
6235              } elsif ({
6236                        table => 1, caption => 1, td => 1, th => 1,
6237                        button => 1, marquee => 1, object => 1, html => 1,
6238                       }->{$node->[1]}) {
6239                !!!cp ('t411.1');
6240                last INSCOPE;
6241              }
6242            } # INSCOPE
6243    
6244            if (defined $i) {
6245              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6246                !!!cp ('t412.1');
6247                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6248              } else {
6249                !!!cp ('t414.1');
6250              }
6251    
6252              splice @{$self->{open_elements}}, $i;
6253            } else {
6254              !!!cp ('t413.1');
6255              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6256    
6257              !!!cp ('t415.1');
6258              ## As if <p>, then reprocess the current token
6259              my $el;
6260              !!!create-element ($el, 'p');
6261              $insert->($el);
6262              ## NOTE: Not inserted into |$self->{open_elements}|.
6263            }
6264    
6265          !!!next-token;          !!!next-token;
6266          redo B;          redo B;
6267        } elsif ({        } elsif ({
# Line 5373  sub _tree_construction_main ($) { Line 6270  sub _tree_construction_main ($) {
6270                  nobr => 1, s => 1, small => 1, strile => 1,                  nobr => 1, s => 1, small => 1, strile => 1,
6271                  strong => 1, tt => 1, u => 1,                  strong => 1, tt => 1, u => 1,
6272                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6273            !!!cp ('t427');
6274          $formatting_end_tag->($token->{tag_name});          $formatting_end_tag->($token->{tag_name});
6275          redo B;          redo B;
6276        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
6277            !!!cp ('t428');
6278          !!!parse-error (type => 'unmatched end tag:br');          !!!parse-error (type => 'unmatched end tag:br');
6279    
6280          ## As if <br>          ## As if <br>
# Line 5400  sub _tree_construction_main ($) { Line 6299  sub _tree_construction_main ($) {
6299                  table => 1, textarea => 1, wbr => 1,                  table => 1, textarea => 1, wbr => 1,
6300                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
6301                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6302            !!!cp ('t429');
6303          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6304          ## Ignore the token          ## Ignore the token
6305          !!!next-token;          !!!next-token;
# Line 5417  sub _tree_construction_main ($) { Line 6317  sub _tree_construction_main ($) {
6317            if ($node->[1] eq $token->{tag_name}) {            if ($node->[1] eq $token->{tag_name}) {
6318              ## Step 1              ## Step 1
6319              ## generate implied end tags              ## generate implied end tags
6320              if ({              while ({
6321                   dd => 1, dt => 1, li => 1, p => 1,                      dd => 1, dt => 1, li => 1, p => 1,
6322                   td => 1, th => 1, tr => 1,                     }->{$self->{open_elements}->[-1]->[1]}) {
6323                   tbody => 1, tfoot => 1, thead => 1,                !!!cp ('t430');
6324                  }->{$self->{open_elements}->[-1]->[1]}) {                ## ISSUE: Can this case be reached?
6325                !!!back-token;                pop @{$self->{open_elements}};
               $token = {type => END_TAG_TOKEN,  
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               redo B;  
6326              }              }
6327                    
6328              ## Step 2              ## Step 2
6329              if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) {              if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) {
6330                  !!!cp ('t431');
6331                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
6332                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6333                } else {
6334                  !!!cp ('t432');
6335              }              }
6336                            
6337              ## Step 3              ## Step 3
# Line 5445  sub _tree_construction_main ($) { Line 6345  sub _tree_construction_main ($) {
6345                  #not $phrasing_category->{$node->[1]} and                  #not $phrasing_category->{$node->[1]} and
6346                  ($special_category->{$node->[1]} or                  ($special_category->{$node->[1]} or
6347                   $scoping_category->{$node->[1]})) {                   $scoping_category->{$node->[1]})) {
6348                  !!!cp ('t433');
6349                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6350                ## Ignore the token                ## Ignore the token
6351                !!!next-token;                !!!next-token;
6352                last S2;                last S2;
6353              }              }
6354    
6355                !!!cp ('t434');
6356            }            }
6357                        
6358            ## Step 4            ## Step 4
# Line 5465  sub _tree_construction_main ($) { Line 6368  sub _tree_construction_main ($) {
6368      redo B;      redo B;
6369    } # B    } # B
6370    
   ## NOTE: The "trailing end" phase in HTML5 is split into  
   ## two insertion modes: "after html body" and "after html frameset".  
   ## NOTE: States in the main stage is preserved while  
   ## the parser stays in the trailing end phase. # MUST  
   
6371    ## Stop parsing # MUST    ## Stop parsing # MUST
6372        
6373    ## TODO: script stuffs    ## TODO: script stuffs
# Line 5511  sub set_inner_html ($$$) { Line 6409  sub set_inner_html ($$$) {
6409      my $p = $class->new;      my $p = $class->new;
6410      $p->{document} = $doc;      $p->{document} = $doc;
6411    
6412      ## Step 9 # MUST      ## Step 8 # MUST
6413      my $i = 0;      my $i = 0;
6414      my $line = 1;      my $line = 1;
6415      my $column = 0;      my $column = 0;
6416      $p->{set_next_input_character} = sub {      $p->{set_next_char} = sub {
6417        my $self = shift;        my $self = shift;
6418    
6419        pop @{$self->{prev_input_character}};        pop @{$self->{prev_char}};
6420        unshift @{$self->{prev_input_character}}, $self->{next_input_character};        unshift @{$self->{prev_char}}, $self->{next_char};
6421    
6422        $self->{next_input_character} = -1 and return if $i >= length $$s;        $self->{next_char} = -1 and return if $i >= length $$s;
6423        $self->{next_input_character} = ord substr $$s, $i++, 1;        $self->{next_char} = ord substr $$s, $i++, 1;
6424        $column++;        $column++;
6425    
6426        if ($self->{next_input_character} == 0x000A) { # LF        if ($self->{next_char} == 0x000A) { # LF
6427          $line++;          $line++;
6428          $column = 0;          $column = 0;
6429        } elsif ($self->{next_input_character} == 0x000D) { # CR          !!!cp ('i1');
6430          } elsif ($self->{next_char} == 0x000D) { # CR
6431          $i++ if substr ($$s, $i, 1) eq "\x0A";          $i++ if substr ($$s, $i, 1) eq "\x0A";
6432          $self->{next_input_character} = 0x000A; # LF # MUST          $self->{next_char} = 0x000A; # LF # MUST
6433          $line++;          $line++;
6434          $column = 0;          $column = 0;
6435        } elsif ($self->{next_input_character} > 0x10FFFF) {          !!!cp ('i2');
6436          $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        } elsif ($self->{next_char} > 0x10FFFF) {
6437        } elsif ($self->{next_input_character} == 0x0000) { # NULL          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
6438            !!!cp ('i3');
6439          } elsif ($self->{next_char} == 0x0000) { # NULL
6440            !!!cp ('i4');
6441          !!!parse-error (type => 'NULL');          !!!parse-error (type => 'NULL');
6442          $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
6443        }        }
6444      };      };
6445      $p->{prev_input_character} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];
6446      $p->{next_input_character} = -1;      $p->{next_char} = -1;
6447            
6448      my $ponerror = $onerror || sub {      my $ponerror = $onerror || sub {
6449        my (%opt) = @_;        my (%opt) = @_;
# Line 5574  sub set_inner_html ($$$) { Line 6476  sub set_inner_html ($$$) {
6476    
6477      $p->{inner_html_node} = [$node, $node_ln];      $p->{inner_html_node} = [$node, $node_ln];
6478    
6479      ## Step 4      ## Step 3
6480      my $root = $doc->create_element_ns      my $root = $doc->create_element_ns
6481        ('http://www.w3.org/1999/xhtml', [undef, 'html']);        ('http://www.w3.org/1999/xhtml', [undef, 'html']);
6482    
6483      ## Step 5 # MUST      ## Step 4 # MUST
6484      $doc->append_child ($root);      $doc->append_child ($root);
6485    
6486      ## Step 6 # MUST      ## Step 5 # MUST
6487      push @{$p->{open_elements}}, [$root, 'html'];      push @{$p->{open_elements}}, [$root, 'html'];
6488    
6489      undef $p->{head_element};      undef $p->{head_element};
6490    
6491      ## Step 7 # MUST      ## Step 6 # MUST
6492      $p->_reset_insertion_mode;      $p->_reset_insertion_mode;
6493    
6494      ## Step 8 # MUST      ## Step 7 # MUST
6495      my $anode = $node;      my $anode = $node;
6496      AN: while (defined $anode) {      AN: while (defined $anode) {
6497        if ($anode->node_type == 1) {        if ($anode->node_type == 1) {
6498          my $nsuri = $anode->namespace_uri;          my $nsuri = $anode->namespace_uri;
6499          if (defined $nsuri and $nsuri eq 'http://www.w3.org/1999/xhtml') {          if (defined $nsuri and $nsuri eq 'http://www.w3.org/1999/xhtml') {
6500            if ($anode->manakai_local_name eq 'form') {            if ($anode->manakai_local_name eq 'form') {
6501                !!!cp ('i5');
6502              $p->{form_element} = $anode;              $p->{form_element} = $anode;
6503              last AN;              last AN;
6504            }            }
# Line 5604  sub set_inner_html ($$$) { Line 6507  sub set_inner_html ($$$) {
6507        $anode = $anode->parent_node;        $anode = $anode->parent_node;
6508      } # AN      } # AN
6509            
6510      ## Step 3 # MUST      ## Step 9 # MUST
     ## Step 10 # MUST  
6511      {      {
6512        my $self = $p;        my $self = $p;
6513        !!!next-token;        !!!next-token;
6514      }      }
6515      $p->_tree_construction_main;      $p->_tree_construction_main;
6516    
6517      ## Step 11 # MUST      ## Step 10 # MUST
6518      my @cn = @{$node->child_nodes};      my @cn = @{$node->child_nodes};
6519      for (@cn) {      for (@cn) {
6520        $node->remove_child ($_);        $node->remove_child ($_);
6521      }      }
6522      ## ISSUE: mutation events? read-only?      ## ISSUE: mutation events? read-only?
6523    
6524      ## Step 12 # MUST      ## Step 11 # MUST
6525      @cn = @{$root->child_nodes};      @cn = @{$root->child_nodes};
6526      for (@cn) {      for (@cn) {
6527        $this_doc->adopt_node ($_);        $this_doc->adopt_node ($_);

Legend:
Removed from v.1.73  
changed lines
  Added in v.1.102

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24