/[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.54 by wakaba, Sat Aug 11 06:37:12 2007 UTC revision 1.56 by wakaba, Sat Aug 11 07:19:18 2007 UTC
# Line 159  sub CDATA_CONTENT_MODEL () { CM_LIMITED_ Line 159  sub CDATA_CONTENT_MODEL () { CM_LIMITED_
159  sub RCDATA_CONTENT_MODEL () { CM_ENTITY | CM_LIMITED_MARKUP }  sub RCDATA_CONTENT_MODEL () { CM_ENTITY | CM_LIMITED_MARKUP }
160  sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }  sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }
161    
162    sub DOCTYPE_TOKEN () { 1 }
163    sub COMMENT_TOKEN () { 2 }
164    sub START_TAG_TOKEN () { 3 }
165    sub END_TAG_TOKEN () { 4 }
166    sub END_OF_FILE_TOKEN () { 5 }
167    sub CHARACTER_TOKEN () { 6 }
168    
169  sub AFTER_HTML_IMS () { 0b100 }  sub AFTER_HTML_IMS () { 0b100 }
170  sub HEAD_IMS ()       { 0b1000 }  sub HEAD_IMS ()       { 0b1000 }
171  sub BODY_IMS ()       { 0b10000 }  sub BODY_IMS ()       { 0b10000 }
172  sub BODY_TABLE_IMS () { 0b100000 | BODY_IMS }  sub BODY_TABLE_IMS () { 0b100000 }
173  sub TABLE_IMS ()      { 0b1000000 }  sub TABLE_IMS ()      { 0b1000000 }
174  sub ROW_IMS ()        { 0b10000000 | TABLE_IMS }  sub ROW_IMS ()        { 0b10000000 }
175  sub BODY_AFTER_IMS () { 0b100000000 }  sub BODY_AFTER_IMS () { 0b100000000 }
176  sub FRAME_IMS ()      { 0b1000000000 }  sub FRAME_IMS ()      { 0b1000000000 }
177    
# Line 175  sub IN_HEAD_NOSCRIPT_IM () { HEAD_IMS | Line 182  sub IN_HEAD_NOSCRIPT_IM () { HEAD_IMS |
182  sub AFTER_HEAD_IM () { HEAD_IMS | 0b10 }  sub AFTER_HEAD_IM () { HEAD_IMS | 0b10 }
183  sub BEFORE_HEAD_IM () { HEAD_IMS | 0b11 }  sub BEFORE_HEAD_IM () { HEAD_IMS | 0b11 }
184  sub IN_BODY_IM () { BODY_IMS }  sub IN_BODY_IM () { BODY_IMS }
185  sub IN_CELL_IM () { BODY_TABLE_IMS | 0b01 }  sub IN_CELL_IM () { BODY_IMS | BODY_TABLE_IMS | 0b01 }
186  sub IN_CAPTION_IM () { BODY_TABLE_IMS | 0b10 }  sub IN_CAPTION_IM () { BODY_IMS | BODY_TABLE_IMS | 0b10 }
187  sub IN_ROW_IM () { ROW_IMS | 0b01 }  sub IN_ROW_IM () { TABLE_IMS | ROW_IMS | 0b01 }
188  sub IN_TABLE_BODY_IM () { ROW_IMS | 0b10 }  sub IN_TABLE_BODY_IM () { TABLE_IMS | ROW_IMS | 0b10 }
189  sub IN_TABLE_IM () { TABLE_IMS }  sub IN_TABLE_IM () { TABLE_IMS }
190  sub AFTER_BODY_IM () { BODY_AFTER_IMS }  sub AFTER_BODY_IM () { BODY_AFTER_IMS }
191  sub IN_FRAMESET_IM () { FRAME_IMS | 0b01 }  sub IN_FRAMESET_IM () { FRAME_IMS | 0b01 }
# Line 204  sub _initialize_tokenizer ($) { Line 211  sub _initialize_tokenizer ($) {
211  } # _initialize_tokenizer  } # _initialize_tokenizer
212    
213  ## A token has:  ## A token has:
214  ##   ->{type} eq 'DOCTYPE', 'start tag', 'end tag', 'comment',  ##   ->{type} == DOCTYPE_TOKEN, START_TAG_TOKEN, END_TAG_TOKEN, COMMENT_TOKEN,
215  ##       'character', or 'end-of-file'  ##       CHARACTER_TOKEN, or END_OF_FILE_TOKEN
216  ##   ->{name} (DOCTYPE, start tag (tag name), end tag (tag name))  ##   ->{name} (DOCTYPE_TOKEN)
217  ##   ->{public_identifier} (DOCTYPE)  ##   ->{tag_name} (START_TAG_TOKEN, END_TAG_TOKEN)
218  ##   ->{system_identifier} (DOCTYPE)  ##   ->{public_identifier} (DOCTYPE_TOKEN)
219  ##   ->{correct} == 1 or 0 (DOCTYPE)  ##   ->{system_identifier} (DOCTYPE_TOKEN)
220  ##   ->{attributes} isa HASH (start tag, end tag)  ##   ->{correct} == 1 or 0 (DOCTYPE_TOKEN)
221  ##   ->{data} (comment, character)  ##   ->{attributes} isa HASH (START_TAG_TOKEN, END_TAG_TOKEN)
222    ##   ->{data} (COMMENT_TOKEN, CHARACTER_TOKEN)
223    
224  ## Emitted token MUST immediately be handled by the tree construction state.  ## Emitted token MUST immediately be handled by the tree construction state.
225    
# Line 270  sub _get_next_token ($) { Line 278  sub _get_next_token ($) {
278                    
279          #          #
280        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
281          !!!emit ({type => 'end-of-file'});          !!!emit ({type => END_OF_FILE_TOKEN});
282          last A; ## TODO: ok?          last A; ## TODO: ok?
283        }        }
284        # Anything else        # Anything else
285        my $token = {type => 'character',        my $token = {type => CHARACTER_TOKEN,
286                     data => chr $self->{next_input_character}};                     data => chr $self->{next_input_character}};
287        ## Stay in the data state        ## Stay in the data state
288        !!!next-input-character;        !!!next-input-character;
# Line 291  sub _get_next_token ($) { Line 299  sub _get_next_token ($) {
299        # next-input-character is already done        # next-input-character is already done
300    
301        unless (defined $token) {        unless (defined $token) {
302          !!!emit ({type => 'character', data => '&'});          !!!emit ({type => CHARACTER_TOKEN, data => '&'});
303        } else {        } else {
304          !!!emit ($token);          !!!emit ($token);
305        }        }
# Line 307  sub _get_next_token ($) { Line 315  sub _get_next_token ($) {
315            ## reconsume            ## reconsume
316            $self->{state} = 'data';            $self->{state} = 'data';
317    
318            !!!emit ({type => 'character', data => '<'});            !!!emit ({type => CHARACTER_TOKEN, data => '<'});
319    
320            redo A;            redo A;
321          }          }
# Line 323  sub _get_next_token ($) { Line 331  sub _get_next_token ($) {
331          } elsif (0x0041 <= $self->{next_input_character} and          } elsif (0x0041 <= $self->{next_input_character} and
332                   $self->{next_input_character} <= 0x005A) { # A..Z                   $self->{next_input_character} <= 0x005A) { # A..Z
333            $self->{current_token}            $self->{current_token}
334              = {type => 'start tag',              = {type => START_TAG_TOKEN,
335                 tag_name => chr ($self->{next_input_character} + 0x0020)};                 tag_name => chr ($self->{next_input_character} + 0x0020)};
336            $self->{state} = 'tag name';            $self->{state} = 'tag name';
337            !!!next-input-character;            !!!next-input-character;
338            redo A;            redo A;
339          } elsif (0x0061 <= $self->{next_input_character} and          } elsif (0x0061 <= $self->{next_input_character} and
340                   $self->{next_input_character} <= 0x007A) { # a..z                   $self->{next_input_character} <= 0x007A) { # a..z
341            $self->{current_token} = {type => 'start tag',            $self->{current_token} = {type => START_TAG_TOKEN,
342                              tag_name => chr ($self->{next_input_character})};                              tag_name => chr ($self->{next_input_character})};
343            $self->{state} = 'tag name';            $self->{state} = 'tag name';
344            !!!next-input-character;            !!!next-input-character;
# Line 340  sub _get_next_token ($) { Line 348  sub _get_next_token ($) {
348            $self->{state} = 'data';            $self->{state} = 'data';
349            !!!next-input-character;            !!!next-input-character;
350    
351            !!!emit ({type => 'character', data => '<>'});            !!!emit ({type => CHARACTER_TOKEN, data => '<>'});
352    
353            redo A;            redo A;
354          } elsif ($self->{next_input_character} == 0x003F) { # ?          } elsif ($self->{next_input_character} == 0x003F) { # ?
# Line 353  sub _get_next_token ($) { Line 361  sub _get_next_token ($) {
361            $self->{state} = 'data';            $self->{state} = 'data';
362            ## reconsume            ## reconsume
363    
364            !!!emit ({type => 'character', data => '<'});            !!!emit ({type => CHARACTER_TOKEN, data => '<'});
365    
366            redo A;            redo A;
367          }          }
# Line 377  sub _get_next_token ($) { Line 385  sub _get_next_token ($) {
385                !!!back-next-input-character (@next_char);                !!!back-next-input-character (@next_char);
386                $self->{state} = 'data';                $self->{state} = 'data';
387    
388                !!!emit ({type => 'character', data => '</'});                !!!emit ({type => CHARACTER_TOKEN, data => '</'});
389        
390                redo A;                redo A;
391              }              }
# Line 395  sub _get_next_token ($) { Line 403  sub _get_next_token ($) {
403              $self->{next_input_character} = shift @next_char; # reconsume              $self->{next_input_character} = shift @next_char; # reconsume
404              !!!back-next-input-character (@next_char);              !!!back-next-input-character (@next_char);
405              $self->{state} = 'data';              $self->{state} = 'data';
406              !!!emit ({type => 'character', data => '</'});              !!!emit ({type => CHARACTER_TOKEN, data => '</'});
407              redo A;              redo A;
408            } else {            } else {
409              $self->{next_input_character} = shift @next_char;              $self->{next_input_character} = shift @next_char;
# Line 406  sub _get_next_token ($) { Line 414  sub _get_next_token ($) {
414            ## No start tag token has ever been emitted            ## No start tag token has ever been emitted
415            # next-input-character is already done            # next-input-character is already done
416            $self->{state} = 'data';            $self->{state} = 'data';
417            !!!emit ({type => 'character', data => '</'});            !!!emit ({type => CHARACTER_TOKEN, data => '</'});
418            redo A;            redo A;
419          }          }
420        }        }
421                
422        if (0x0041 <= $self->{next_input_character} and        if (0x0041 <= $self->{next_input_character} and
423            $self->{next_input_character} <= 0x005A) { # A..Z            $self->{next_input_character} <= 0x005A) { # A..Z
424          $self->{current_token} = {type => 'end tag',          $self->{current_token} = {type => END_TAG_TOKEN,
425                            tag_name => chr ($self->{next_input_character} + 0x0020)};                            tag_name => chr ($self->{next_input_character} + 0x0020)};
426          $self->{state} = 'tag name';          $self->{state} = 'tag name';
427          !!!next-input-character;          !!!next-input-character;
428          redo A;          redo A;
429        } elsif (0x0061 <= $self->{next_input_character} and        } elsif (0x0061 <= $self->{next_input_character} and
430                 $self->{next_input_character} <= 0x007A) { # a..z                 $self->{next_input_character} <= 0x007A) { # a..z
431          $self->{current_token} = {type => 'end tag',          $self->{current_token} = {type => END_TAG_TOKEN,
432                            tag_name => chr ($self->{next_input_character})};                            tag_name => chr ($self->{next_input_character})};
433          $self->{state} = 'tag name';          $self->{state} = 'tag name';
434          !!!next-input-character;          !!!next-input-character;
# Line 435  sub _get_next_token ($) { Line 443  sub _get_next_token ($) {
443          $self->{state} = 'data';          $self->{state} = 'data';
444          # reconsume          # reconsume
445    
446          !!!emit ({type => 'character', data => '</'});          !!!emit ({type => CHARACTER_TOKEN, data => '</'});
447    
448          redo A;          redo A;
449        } else {        } else {
# Line 454  sub _get_next_token ($) { Line 462  sub _get_next_token ($) {
462          !!!next-input-character;          !!!next-input-character;
463          redo A;          redo A;
464        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
465          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
466            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
467                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
468            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
469          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
470            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
471            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
472              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 481  sub _get_next_token ($) { Line 489  sub _get_next_token ($) {
489          redo A;          redo A;
490        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
491          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
492          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
493            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
494                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
495            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
496          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
497            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
498            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
499              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 502  sub _get_next_token ($) { Line 510  sub _get_next_token ($) {
510        } elsif ($self->{next_input_character} == 0x002F) { # /        } elsif ($self->{next_input_character} == 0x002F) { # /
511          !!!next-input-character;          !!!next-input-character;
512          if ($self->{next_input_character} == 0x003E and # >          if ($self->{next_input_character} == 0x003E and # >
513              $self->{current_token}->{type} eq 'start tag' and              $self->{current_token}->{type} == START_TAG_TOKEN and
514              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {
515            # permitted slash            # permitted slash
516            #            #
# Line 529  sub _get_next_token ($) { Line 537  sub _get_next_token ($) {
537          !!!next-input-character;          !!!next-input-character;
538          redo A;          redo A;
539        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
540          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
541            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
542                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
543            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
544          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
545            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
546            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
547              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 557  sub _get_next_token ($) { Line 565  sub _get_next_token ($) {
565        } elsif ($self->{next_input_character} == 0x002F) { # /        } elsif ($self->{next_input_character} == 0x002F) { # /
566          !!!next-input-character;          !!!next-input-character;
567          if ($self->{next_input_character} == 0x003E and # >          if ($self->{next_input_character} == 0x003E and # >
568              $self->{current_token}->{type} eq 'start tag' and              $self->{current_token}->{type} == START_TAG_TOKEN and
569              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {
570            # permitted slash            # permitted slash
571            #            #
# Line 569  sub _get_next_token ($) { Line 577  sub _get_next_token ($) {
577          redo A;          redo A;
578        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
579          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
580          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
581            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
582                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
583            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
584          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
585            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
586            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
587              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 622  sub _get_next_token ($) { Line 630  sub _get_next_token ($) {
630          redo A;          redo A;
631        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
632          $before_leave->();          $before_leave->();
633          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
634            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
635                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
636            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
637          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
638            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
639            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
640              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 650  sub _get_next_token ($) { Line 658  sub _get_next_token ($) {
658          $before_leave->();          $before_leave->();
659          !!!next-input-character;          !!!next-input-character;
660          if ($self->{next_input_character} == 0x003E and # >          if ($self->{next_input_character} == 0x003E and # >
661              $self->{current_token}->{type} eq 'start tag' and              $self->{current_token}->{type} == START_TAG_TOKEN and
662              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {
663            # permitted slash            # permitted slash
664            #            #
# Line 663  sub _get_next_token ($) { Line 671  sub _get_next_token ($) {
671        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
672          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
673          $before_leave->();          $before_leave->();
674          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
675            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
676                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
677            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
678          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
679            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
680            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
681              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 701  sub _get_next_token ($) { Line 709  sub _get_next_token ($) {
709          !!!next-input-character;          !!!next-input-character;
710          redo A;          redo A;
711        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
712          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
713            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
714                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
715            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
716          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
717            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
718            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
719              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 729  sub _get_next_token ($) { Line 737  sub _get_next_token ($) {
737        } elsif ($self->{next_input_character} == 0x002F) { # /        } elsif ($self->{next_input_character} == 0x002F) { # /
738          !!!next-input-character;          !!!next-input-character;
739          if ($self->{next_input_character} == 0x003E and # >          if ($self->{next_input_character} == 0x003E and # >
740              $self->{current_token}->{type} eq 'start tag' and              $self->{current_token}->{type} == START_TAG_TOKEN and
741              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {
742            # permitted slash            # permitted slash
743            #            #
# Line 742  sub _get_next_token ($) { Line 750  sub _get_next_token ($) {
750          redo A;          redo A;
751        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
752          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
753          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
754            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
755                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
756            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
757          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
758            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
759            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
760              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 789  sub _get_next_token ($) { Line 797  sub _get_next_token ($) {
797          !!!next-input-character;          !!!next-input-character;
798          redo A;          redo A;
799        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
800          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
801            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
802                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
803            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
804          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
805            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
806            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
807              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 809  sub _get_next_token ($) { Line 817  sub _get_next_token ($) {
817          redo A;          redo A;
818        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
819          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
820          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
821            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
822                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
823            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
824          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
825            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
826            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
827              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 845  sub _get_next_token ($) { Line 853  sub _get_next_token ($) {
853          redo A;          redo A;
854        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
855          !!!parse-error (type => 'unclosed attribute value');          !!!parse-error (type => 'unclosed attribute value');
856          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
857            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
858                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
859            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
860          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
861            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
862            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
863              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 881  sub _get_next_token ($) { Line 889  sub _get_next_token ($) {
889          redo A;          redo A;
890        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
891          !!!parse-error (type => 'unclosed attribute value');          !!!parse-error (type => 'unclosed attribute value');
892          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
893            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
894                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
895            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
896          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
897            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
898            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
899              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 920  sub _get_next_token ($) { Line 928  sub _get_next_token ($) {
928          !!!next-input-character;          !!!next-input-character;
929          redo A;          redo A;
930        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
931          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
932            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
933                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
934            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
935          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
936            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
937            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
938              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 940  sub _get_next_token ($) { Line 948  sub _get_next_token ($) {
948          redo A;          redo A;
949        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
950          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
951          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
952            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
953                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
954            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
955          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
956            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
957            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
958              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 980  sub _get_next_token ($) { Line 988  sub _get_next_token ($) {
988      } elsif ($self->{state} eq 'bogus comment') {      } elsif ($self->{state} eq 'bogus comment') {
989        ## (only happen if PCDATA state)        ## (only happen if PCDATA state)
990                
991        my $token = {type => 'comment', data => ''};        my $token = {type => COMMENT_TOKEN, data => ''};
992    
993        BC: {        BC: {
994          if ($self->{next_input_character} == 0x003E) { # >          if ($self->{next_input_character} == 0x003E) { # >
# Line 1013  sub _get_next_token ($) { Line 1021  sub _get_next_token ($) {
1021          !!!next-input-character;          !!!next-input-character;
1022          push @next_char, $self->{next_input_character};          push @next_char, $self->{next_input_character};
1023          if ($self->{next_input_character} == 0x002D) { # -          if ($self->{next_input_character} == 0x002D) { # -
1024            $self->{current_token} = {type => 'comment', data => ''};            $self->{current_token} = {type => COMMENT_TOKEN, data => ''};
1025            $self->{state} = 'comment start';            $self->{state} = 'comment start';
1026            !!!next-input-character;            !!!next-input-character;
1027            redo A;            redo A;
# Line 1216  sub _get_next_token ($) { Line 1224  sub _get_next_token ($) {
1224          $self->{state} = 'data';          $self->{state} = 'data';
1225          !!!next-input-character;          !!!next-input-character;
1226    
1227          !!!emit ({type => 'DOCTYPE'}); # incorrect          !!!emit ({type => DOCTYPE_TOKEN}); # incorrect
1228    
1229          redo A;          redo A;
1230        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
# Line 1224  sub _get_next_token ($) { Line 1232  sub _get_next_token ($) {
1232          $self->{state} = 'data';          $self->{state} = 'data';
1233          ## reconsume          ## reconsume
1234    
1235          !!!emit ({type => 'DOCTYPE'}); # incorrect          !!!emit ({type => DOCTYPE_TOKEN}); # incorrect
1236    
1237          redo A;          redo A;
1238        } else {        } else {
1239          $self->{current_token}          $self->{current_token}
1240              = {type => 'DOCTYPE',              = {type => DOCTYPE_TOKEN,
1241                 name => chr ($self->{next_input_character}),                 name => chr ($self->{next_input_character}),
1242                 correct => 1};                 correct => 1};
1243  ## ISSUE: "Set the token's name name to the" in the spec  ## ISSUE: "Set the token's name name to the" in the spec
# Line 1697  sub _tokenize_attempt_to_consume_an_enti Line 1705  sub _tokenize_attempt_to_consume_an_enti
1705            $code = $c1_entity_char->{$code};            $code = $c1_entity_char->{$code};
1706          }          }
1707    
1708          return {type => 'character', data => chr $code};          return {type => CHARACTER_TOKEN, data => chr $code};
1709        } # X        } # X
1710      } elsif (0x0030 <= $self->{next_input_character} and      } elsif (0x0030 <= $self->{next_input_character} and
1711               $self->{next_input_character} <= 0x0039) { # 0..9               $self->{next_input_character} <= 0x0039) { # 0..9
# Line 1732  sub _tokenize_attempt_to_consume_an_enti Line 1740  sub _tokenize_attempt_to_consume_an_enti
1740          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
1741        }        }
1742                
1743        return {type => 'character', data => chr $code};        return {type => CHARACTER_TOKEN, data => chr $code};
1744      } else {      } else {
1745        !!!parse-error (type => 'bare nero');        !!!parse-error (type => 'bare nero');
1746        !!!back-next-input-character ($self->{next_input_character});        !!!back-next-input-character ($self->{next_input_character});
# Line 1780  sub _tokenize_attempt_to_consume_an_enti Line 1788  sub _tokenize_attempt_to_consume_an_enti
1788      }      }
1789            
1790      if ($match > 0) {      if ($match > 0) {
1791        return {type => 'character', data => $value};        return {type => CHARACTER_TOKEN, data => $value};
1792      } elsif ($match < 0) {      } elsif ($match < 0) {
1793        !!!parse-error (type => 'no refc');        !!!parse-error (type => 'no refc');
1794        if ($in_attr and $match < -1) {        if ($in_attr and $match < -1) {
1795          return {type => 'character', data => '&'.$entity_name};          return {type => CHARACTER_TOKEN, data => '&'.$entity_name};
1796        } else {        } else {
1797          return {type => 'character', data => $value};          return {type => CHARACTER_TOKEN, data => $value};
1798        }        }
1799      } else {      } else {
1800        !!!parse-error (type => 'bare ero');        !!!parse-error (type => 'bare ero');
1801        ## NOTE: No characters are consumed in the spec.        ## NOTE: No characters are consumed in the spec.
1802        return {type => 'character', data => '&'.$value};        return {type => CHARACTER_TOKEN, data => '&'.$value};
1803      }      }
1804    } else {    } else {
1805      ## no characters are consumed      ## no characters are consumed
# Line 1847  sub _construct_tree ($) { Line 1855  sub _construct_tree ($) {
1855  sub _tree_construction_initial ($) {  sub _tree_construction_initial ($) {
1856    my $self = shift;    my $self = shift;
1857    INITIAL: {    INITIAL: {
1858      if ($token->{type} eq 'DOCTYPE') {      if ($token->{type} == DOCTYPE_TOKEN) {
1859        ## NOTE: Conformance checkers MAY, instead of reporting "not HTML5"        ## NOTE: Conformance checkers MAY, instead of reporting "not HTML5"
1860        ## error, switch to a conformance checking mode for another        ## error, switch to a conformance checking mode for another
1861        ## language.        ## language.
# Line 1974  sub _tree_construction_initial ($) { Line 1982  sub _tree_construction_initial ($) {
1982        !!!next-token;        !!!next-token;
1983        return;        return;
1984      } elsif ({      } elsif ({
1985                'start tag' => 1,                START_TAG_TOKEN, 1,
1986                'end tag' => 1,                END_TAG_TOKEN, 1,
1987                'end-of-file' => 1,                END_OF_FILE_TOKEN, 1,
1988               }->{$token->{type}}) {               }->{$token->{type}}) {
1989        !!!parse-error (type => 'no DOCTYPE');        !!!parse-error (type => 'no DOCTYPE');
1990        $self->{document}->manakai_compat_mode ('quirks');        $self->{document}->manakai_compat_mode ('quirks');
1991        ## Go to the root element phase        ## Go to the root element phase
1992        ## reprocess        ## reprocess
1993        return;        return;
1994      } elsif ($token->{type} eq 'character') {      } elsif ($token->{type} == CHARACTER_TOKEN) {
1995        if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D        if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D
1996          ## Ignore the token          ## Ignore the token
1997    
# Line 1999  sub _tree_construction_initial ($) { Line 2007  sub _tree_construction_initial ($) {
2007        ## Go to the root element phase        ## Go to the root element phase
2008        ## reprocess        ## reprocess
2009        return;        return;
2010      } elsif ($token->{type} eq 'comment') {      } elsif ($token->{type} == COMMENT_TOKEN) {
2011        my $comment = $self->{document}->create_comment ($token->{data});        my $comment = $self->{document}->create_comment ($token->{data});
2012        $self->{document}->append_child ($comment);        $self->{document}->append_child ($comment);
2013                
# Line 2007  sub _tree_construction_initial ($) { Line 2015  sub _tree_construction_initial ($) {
2015        !!!next-token;        !!!next-token;
2016        redo INITIAL;        redo INITIAL;
2017      } else {      } else {
2018        die "$0: $token->{type}: Unknown token";        die "$0: $token->{type}: Unknown token type";
2019      }      }
2020    } # INITIAL    } # INITIAL
2021  } # _tree_construction_initial  } # _tree_construction_initial
# Line 2016  sub _tree_construction_root_element ($) Line 2024  sub _tree_construction_root_element ($)
2024    my $self = shift;    my $self = shift;
2025        
2026    B: {    B: {
2027        if ($token->{type} eq 'DOCTYPE') {        if ($token->{type} == DOCTYPE_TOKEN) {
2028          !!!parse-error (type => 'in html:#DOCTYPE');          !!!parse-error (type => 'in html:#DOCTYPE');
2029          ## Ignore the token          ## Ignore the token
2030          ## Stay in the phase          ## Stay in the phase
2031          !!!next-token;          !!!next-token;
2032          redo B;          redo B;
2033        } elsif ($token->{type} eq 'comment') {        } elsif ($token->{type} == COMMENT_TOKEN) {
2034          my $comment = $self->{document}->create_comment ($token->{data});          my $comment = $self->{document}->create_comment ($token->{data});
2035          $self->{document}->append_child ($comment);          $self->{document}->append_child ($comment);
2036          ## Stay in the phase          ## Stay in the phase
2037          !!!next-token;          !!!next-token;
2038          redo B;          redo B;
2039        } elsif ($token->{type} eq 'character') {        } elsif ($token->{type} == CHARACTER_TOKEN) {
2040          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D
2041            ## Ignore the token.            ## Ignore the token.
2042    
# Line 2040  sub _tree_construction_root_element ($) Line 2048  sub _tree_construction_root_element ($)
2048          }          }
2049          #          #
2050        } elsif ({        } elsif ({
2051                  'start tag' => 1,                  START_TAG_TOKEN, 1,
2052                  'end tag' => 1,                  END_TAG_TOKEN, 1,
2053                  'end-of-file' => 1,                  END_OF_FILE_TOKEN, 1,
2054                 }->{$token->{type}}) {                 }->{$token->{type}}) {
2055          ## ISSUE: There is an issue in the spec          ## ISSUE: There is an issue in the spec
2056          #          #
2057        } else {        } else {
2058          die "$0: $token->{type}: Unknown token";          die "$0: $token->{type}: Unknown token type";
2059        }        }
2060        my $root_element; !!!create-element ($root_element, 'html');        my $root_element; !!!create-element ($root_element, 'html');
2061        $self->{document}->append_child ($root_element);        $self->{document}->append_child ($root_element);
# Line 2230  sub _tree_construction_main ($) { Line 2238  sub _tree_construction_main ($) {
2238      ## Step 4      ## Step 4
2239      my $text = '';      my $text = '';
2240      !!!next-token;      !!!next-token;
2241      while ($token->{type} eq 'character') { # or until stop tokenizing      while ($token->{type} == CHARACTER_TOKEN) { # or until stop tokenizing
2242        $text .= $token->{data};        $text .= $token->{data};
2243        !!!next-token;        !!!next-token;
2244      }      }
# Line 2245  sub _tree_construction_main ($) { Line 2253  sub _tree_construction_main ($) {
2253      $self->{content_model} = PCDATA_CONTENT_MODEL;      $self->{content_model} = PCDATA_CONTENT_MODEL;
2254    
2255      ## Step 7      ## Step 7
2256      if ($token->{type} eq 'end tag' and $token->{tag_name} eq $start_tag_name) {      if ($token->{type} == END_TAG_TOKEN and $token->{tag_name} eq $start_tag_name) {
2257        ## Ignore the token        ## Ignore the token
2258      } elsif ($content_model_flag == CDATA_CONTENT_MODEL) {      } elsif ($content_model_flag == CDATA_CONTENT_MODEL) {
2259        !!!parse-error (type => 'in CDATA:#'.$token->{type});        !!!parse-error (type => 'in CDATA:#'.$token->{type});
# Line 2268  sub _tree_construction_main ($) { Line 2276  sub _tree_construction_main ($) {
2276            
2277      my $text = '';      my $text = '';
2278      !!!next-token;      !!!next-token;
2279      while ($token->{type} eq 'character') {      while ($token->{type} == CHARACTER_TOKEN) {
2280        $text .= $token->{data};        $text .= $token->{data};
2281        !!!next-token;        !!!next-token;
2282      } # stop if non-character token or tokenizer stops tokenising      } # stop if non-character token or tokenizer stops tokenising
# Line 2278  sub _tree_construction_main ($) { Line 2286  sub _tree_construction_main ($) {
2286                                
2287      $self->{content_model} = PCDATA_CONTENT_MODEL;      $self->{content_model} = PCDATA_CONTENT_MODEL;
2288    
2289      if ($token->{type} eq 'end tag' and      if ($token->{type} == END_TAG_TOKEN and
2290          $token->{tag_name} eq 'script') {          $token->{tag_name} eq 'script') {
2291        ## Ignore the token        ## Ignore the token
2292      } else {      } else {
# Line 2524  sub _tree_construction_main ($) { Line 2532  sub _tree_construction_main ($) {
2532    my $insert;    my $insert;
2533    
2534    B: {    B: {
2535      if ($token->{type} eq 'DOCTYPE') {      if ($token->{type} == DOCTYPE_TOKEN) {
2536        !!!parse-error (type => 'DOCTYPE in the middle');        !!!parse-error (type => 'DOCTYPE in the middle');
2537        ## Ignore the token        ## Ignore the token
2538        ## Stay in the phase        ## Stay in the phase
2539        !!!next-token;        !!!next-token;
2540        redo B;        redo B;
2541      } elsif ($token->{type} eq 'end-of-file') {      } elsif ($token->{type} == END_OF_FILE_TOKEN) {
2542        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM or        if ($self->{insertion_mode} & AFTER_HTML_IMS) {
           $self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {  
2543          #          #
2544        } else {        } else {
2545          ## Generate implied end tags          ## Generate implied end tags
# Line 2541  sub _tree_construction_main ($) { Line 2548  sub _tree_construction_main ($) {
2548               tbody => 1, tfoot=> 1, thead => 1,               tbody => 1, tfoot=> 1, thead => 1,
2549              }->{$self->{open_elements}->[-1]->[1]}) {              }->{$self->{open_elements}->[-1]->[1]}) {
2550            !!!back-token;            !!!back-token;
2551            $token = {type => 'end tag', tag_name => $self->{open_elements}->[-1]->[1]};            $token = {type => END_TAG_TOKEN, tag_name => $self->{open_elements}->[-1]->[1]};
2552            redo B;            redo B;
2553          }          }
2554                    
# Line 2559  sub _tree_construction_main ($) { Line 2566  sub _tree_construction_main ($) {
2566    
2567        ## Stop parsing        ## Stop parsing
2568        last B;        last B;
2569      } elsif ($token->{type} eq 'start tag' and      } elsif ($token->{type} == START_TAG_TOKEN and
2570               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
2571        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
2572          ## Turn into the main phase          ## Turn into the main phase
# Line 2586  sub _tree_construction_main ($) { Line 2593  sub _tree_construction_main ($) {
2593        }        }
2594        !!!next-token;        !!!next-token;
2595        redo B;        redo B;
2596      } elsif ($token->{type} eq 'comment') {      } elsif ($token->{type} == COMMENT_TOKEN) {
2597        my $comment = $self->{document}->create_comment ($token->{data});        my $comment = $self->{document}->create_comment ($token->{data});
2598        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM or        if ($self->{insertion_mode} & AFTER_HTML_IMS) {
           $self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {  
2599          $self->{document}->append_child ($comment);          $self->{document}->append_child ($comment);
2600        } elsif ($self->{insertion_mode} == AFTER_BODY_IM) {        } elsif ($self->{insertion_mode} == AFTER_BODY_IM) {
2601          $self->{open_elements}->[0]->[0]->append_child ($comment);          $self->{open_elements}->[0]->[0]->append_child ($comment);
# Line 2598  sub _tree_construction_main ($) { Line 2604  sub _tree_construction_main ($) {
2604        }        }
2605        !!!next-token;        !!!next-token;
2606        redo B;        redo B;
2607      } elsif ($self->{insertion_mode} == IN_HEAD_IM or      } elsif ($self->{insertion_mode} & HEAD_IMS) {
2608               $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM or        if ($token->{type} == CHARACTER_TOKEN) {
              $self->{insertion_mode} == AFTER_HEAD_IM or  
              $self->{insertion_mode} == BEFORE_HEAD_IM) {  
       if ($token->{type} eq 'character') {  
2609          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
2610            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
2611            unless (length $token->{data}) {            unless (length $token->{data}) {
# Line 2643  sub _tree_construction_main ($) { Line 2646  sub _tree_construction_main ($) {
2646              $self->{insertion_mode} = IN_BODY_IM;              $self->{insertion_mode} = IN_BODY_IM;
2647              ## reprocess              ## reprocess
2648              redo B;              redo B;
2649            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} == START_TAG_TOKEN) {
2650              if ($token->{tag_name} eq 'head') {              if ($token->{tag_name} eq 'head') {
2651                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
2652                  !!!create-element ($self->{head_element}, $token->{tag_name}, $token->{attributes});                  !!!create-element ($self->{head_element}, $token->{tag_name}, $token->{attributes});
# Line 2856  sub _tree_construction_main ($) { Line 2859  sub _tree_construction_main ($) {
2859              $self->{insertion_mode} = IN_BODY_IM;              $self->{insertion_mode} = IN_BODY_IM;
2860              ## reprocess              ## reprocess
2861              redo B;              redo B;
2862            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} == END_TAG_TOKEN) {
2863              if ($token->{tag_name} eq 'head') {              if ($token->{tag_name} eq 'head') {
2864                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
2865                  ## As if <head>                  ## As if <head>
# Line 2978  sub _tree_construction_main ($) { Line 2981  sub _tree_construction_main ($) {
2981            }            }
2982    
2983            ## ISSUE: An issue in the spec.            ## ISSUE: An issue in the spec.
2984      } elsif ($self->{insertion_mode} == IN_BODY_IM or      } elsif ($self->{insertion_mode} & BODY_IMS) {
2985               $self->{insertion_mode} == IN_CELL_IM or            if ($token->{type} == CHARACTER_TOKEN) {
              $self->{insertion_mode} == IN_CAPTION_IM) {  
           if ($token->{type} eq 'character') {  
2986              ## NOTE: There is a code clone of "character in body".              ## NOTE: There is a code clone of "character in body".
2987              $reconstruct_active_formatting_elements->($insert_to_current);              $reconstruct_active_formatting_elements->($insert_to_current);
2988                            
# Line 2989  sub _tree_construction_main ($) { Line 2990  sub _tree_construction_main ($) {
2990    
2991              !!!next-token;              !!!next-token;
2992              redo B;              redo B;
2993            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} == START_TAG_TOKEN) {
2994              if ({              if ({
2995                   caption => 1, col => 1, colgroup => 1, tbody => 1,                   caption => 1, col => 1, colgroup => 1, tbody => 1,
2996                   td => 1, tfoot => 1, th => 1, thead => 1, tr => 1,                   td => 1, tfoot => 1, th => 1, thead => 1, tr => 1,
# Line 3017  sub _tree_construction_main ($) { Line 3018  sub _tree_construction_main ($) {
3018                                    
3019                  ## Close the cell                  ## Close the cell
3020                  !!!back-token; # <?>                  !!!back-token; # <?>
3021                  $token = {type => 'end tag', tag_name => $tn};                  $token = {type => END_TAG_TOKEN, tag_name => $tn};
3022                  redo B;                  redo B;
3023                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
3024                  !!!parse-error (type => 'not closed:caption');                  !!!parse-error (type => 'not closed:caption');
# Line 3050  sub _tree_construction_main ($) { Line 3051  sub _tree_construction_main ($) {
3051                       tbody => 1, tfoot=> 1, thead => 1,                       tbody => 1, tfoot=> 1, thead => 1,
3052                      }->{$self->{open_elements}->[-1]->[1]}) {                      }->{$self->{open_elements}->[-1]->[1]}) {
3053                    !!!back-token; # <?>                    !!!back-token; # <?>
3054                    $token = {type => 'end tag', tag_name => 'caption'};                    $token = {type => END_TAG_TOKEN, tag_name => 'caption'};
3055                    !!!back-token;                    !!!back-token;
3056                    $token = {type => 'end tag',                    $token = {type => END_TAG_TOKEN,
3057                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3058                    redo B;                    redo B;
3059                  }                  }
# Line 3075  sub _tree_construction_main ($) { Line 3076  sub _tree_construction_main ($) {
3076              } else {              } else {
3077                #                #
3078              }              }
3079            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} == END_TAG_TOKEN) {
3080              if ($token->{tag_name} eq 'td' or $token->{tag_name} eq 'th') {              if ($token->{tag_name} eq 'td' or $token->{tag_name} eq 'th') {
3081                if ($self->{insertion_mode} == IN_CELL_IM) {                if ($self->{insertion_mode} == IN_CELL_IM) {
3082                  ## have an element in table scope                  ## have an element in table scope
# Line 3107  sub _tree_construction_main ($) { Line 3108  sub _tree_construction_main ($) {
3108                       tbody => 1, tfoot=> 1, thead => 1,                       tbody => 1, tfoot=> 1, thead => 1,
3109                      }->{$self->{open_elements}->[-1]->[1]}) {                      }->{$self->{open_elements}->[-1]->[1]}) {
3110                    !!!back-token;                    !!!back-token;
3111                    $token = {type => 'end tag',                    $token = {type => END_TAG_TOKEN,
3112                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3113                    redo B;                    redo B;
3114                  }                  }
# Line 3161  sub _tree_construction_main ($) { Line 3162  sub _tree_construction_main ($) {
3162                       tbody => 1, tfoot=> 1, thead => 1,                       tbody => 1, tfoot=> 1, thead => 1,
3163                      }->{$self->{open_elements}->[-1]->[1]}) {                      }->{$self->{open_elements}->[-1]->[1]}) {
3164                    !!!back-token;                    !!!back-token;
3165                    $token = {type => 'end tag',                    $token = {type => END_TAG_TOKEN,
3166                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3167                    redo B;                    redo B;
3168                  }                  }
# Line 3218  sub _tree_construction_main ($) { Line 3219  sub _tree_construction_main ($) {
3219    
3220                ## Close the cell                ## Close the cell
3221                !!!back-token; # </?>                !!!back-token; # </?>
3222                $token = {type => 'end tag', tag_name => $tn};                $token = {type => END_TAG_TOKEN, tag_name => $tn};
3223                redo B;                redo B;
3224              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
3225                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
# Line 3252  sub _tree_construction_main ($) { Line 3253  sub _tree_construction_main ($) {
3253                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
3254                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
3255                  !!!back-token; # </table>                  !!!back-token; # </table>
3256                  $token = {type => 'end tag', tag_name => 'caption'};                  $token = {type => END_TAG_TOKEN, tag_name => 'caption'};
3257                  !!!back-token;                  !!!back-token;
3258                  $token = {type => 'end tag',                  $token = {type => END_TAG_TOKEN,
3259                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3260                  redo B;                  redo B;
3261                }                }
# Line 3274  sub _tree_construction_main ($) { Line 3275  sub _tree_construction_main ($) {
3275              } elsif ({              } elsif ({
3276                        body => 1, col => 1, colgroup => 1, html => 1,                        body => 1, col => 1, colgroup => 1, html => 1,
3277                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
3278                if ($self->{insertion_mode} == IN_CELL_IM or                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
                   $self->{insertion_mode} == IN_CAPTION_IM) {  
3279                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3280                  ## Ignore the token                  ## Ignore the token
3281                  !!!next-token;                  !!!next-token;
# Line 3301  sub _tree_construction_main ($) { Line 3301  sub _tree_construction_main ($) {
3301    
3302        $insert = $insert_to_current;        $insert = $insert_to_current;
3303        #        #
3304      } elsif ($self->{insertion_mode} == IN_ROW_IM or      } elsif ($self->{insertion_mode} & TABLE_IMS) {
3305               $self->{insertion_mode} == IN_TABLE_BODY_IM or            if ($token->{type} == CHARACTER_TOKEN) {
              $self->{insertion_mode} == IN_TABLE_IM) {  
           if ($token->{type} eq 'character') {  
3306              ## NOTE: There are "character in table" code clones.              ## NOTE: There are "character in table" code clones.
3307              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3308                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
# Line 3362  sub _tree_construction_main ($) { Line 3360  sub _tree_construction_main ($) {
3360                            
3361              !!!next-token;              !!!next-token;
3362              redo B;              redo B;
3363            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} == START_TAG_TOKEN) {
3364              if ({              if ({
3365                   tr => ($self->{insertion_mode} != IN_ROW_IM),                   tr => ($self->{insertion_mode} != IN_ROW_IM),
3366                   th => 1, td => 1,                   th => 1, td => 1,
# Line 3579  sub _tree_construction_main ($) { Line 3577  sub _tree_construction_main ($) {
3577                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
3578                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
3579                  !!!back-token; # <table>                  !!!back-token; # <table>
3580                  $token = {type => 'end tag', tag_name => 'table'};                  $token = {type => END_TAG_TOKEN, tag_name => 'table'};
3581                  !!!back-token;                  !!!back-token;
3582                  $token = {type => 'end tag',                  $token = {type => END_TAG_TOKEN,
3583                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3584                  redo B;                  redo B;
3585                }                }
# Line 3599  sub _tree_construction_main ($) { Line 3597  sub _tree_construction_main ($) {
3597              } else {              } else {
3598                #                #
3599              }              }
3600            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} == END_TAG_TOKEN) {
3601              if ($token->{tag_name} eq 'tr' and              if ($token->{tag_name} eq 'tr' and
3602                  $self->{insertion_mode} == IN_ROW_IM) {                  $self->{insertion_mode} == IN_ROW_IM) {
3603                ## have an element in table scope                ## have an element in table scope
# Line 3740  sub _tree_construction_main ($) { Line 3738  sub _tree_construction_main ($) {
3738                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
3739                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
3740                  !!!back-token;                  !!!back-token;
3741                  $token = {type => 'end tag',                  $token = {type => END_TAG_TOKEN,
3742                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3743                  redo B;                  redo B;
3744                }                }
# Line 3758  sub _tree_construction_main ($) { Line 3756  sub _tree_construction_main ($) {
3756              } elsif ({              } elsif ({
3757                        tbody => 1, tfoot => 1, thead => 1,                        tbody => 1, tfoot => 1, thead => 1,
3758                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
3759                       ($self->{insertion_mode} == IN_ROW_IM or                       $self->{insertion_mode} & ROW_IMS) {
                       $self->{insertion_mode} == IN_TABLE_BODY_IM)) {  
3760                if ($self->{insertion_mode} == IN_ROW_IM) {                if ($self->{insertion_mode} == IN_ROW_IM) {
3761                  ## have an element in table scope                  ## have an element in table scope
3762                  my $i;                  my $i;
# Line 3869  sub _tree_construction_main ($) { Line 3866  sub _tree_construction_main ($) {
3866        $insert = $insert_to_foster;        $insert = $insert_to_foster;
3867        #        #
3868      } elsif ($self->{insertion_mode} == IN_COLUMN_GROUP_IM) {      } elsif ($self->{insertion_mode} == IN_COLUMN_GROUP_IM) {
3869            if ($token->{type} eq 'character') {            if ($token->{type} == CHARACTER_TOKEN) {
3870              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3871                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
3872                unless (length $token->{data}) {                unless (length $token->{data}) {
# Line 3879  sub _tree_construction_main ($) { Line 3876  sub _tree_construction_main ($) {
3876              }              }
3877                            
3878              #              #
3879            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} == START_TAG_TOKEN) {
3880              if ($token->{tag_name} eq 'col') {              if ($token->{tag_name} eq 'col') {
3881                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3882                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
# Line 3888  sub _tree_construction_main ($) { Line 3885  sub _tree_construction_main ($) {
3885              } else {              } else {
3886                #                #
3887              }              }
3888            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} == END_TAG_TOKEN) {
3889              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
3890                if ($self->{open_elements}->[-1]->[1] eq 'html') {                if ($self->{open_elements}->[-1]->[1] eq 'html') {
3891                  !!!parse-error (type => 'unmatched end tag:colgroup');                  !!!parse-error (type => 'unmatched end tag:colgroup');
# Line 3926  sub _tree_construction_main ($) { Line 3923  sub _tree_construction_main ($) {
3923              redo B;              redo B;
3924            }            }
3925      } elsif ($self->{insertion_mode} == IN_SELECT_IM) {      } elsif ($self->{insertion_mode} == IN_SELECT_IM) {
3926            if ($token->{type} eq 'character') {            if ($token->{type} == CHARACTER_TOKEN) {
3927              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
3928              !!!next-token;              !!!next-token;
3929              redo B;              redo B;
3930            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} == START_TAG_TOKEN) {
3931              if ($token->{tag_name} eq 'option') {              if ($token->{tag_name} eq 'option') {
3932                if ($self->{open_elements}->[-1]->[1] eq 'option') {                if ($self->{open_elements}->[-1]->[1] eq 'option') {
3933                  ## As if </option>                  ## As if </option>
# Line 3986  sub _tree_construction_main ($) { Line 3983  sub _tree_construction_main ($) {
3983              } else {              } else {
3984                #                #
3985              }              }
3986            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} == END_TAG_TOKEN) {
3987              if ($token->{tag_name} eq 'optgroup') {              if ($token->{tag_name} eq 'optgroup') {
3988                if ($self->{open_elements}->[-1]->[1] eq 'option' and                if ($self->{open_elements}->[-1]->[1] eq 'option' and
3989                    $self->{open_elements}->[-2]->[1] eq 'optgroup') {                    $self->{open_elements}->[-2]->[1] eq 'optgroup') {
# Line 4099  sub _tree_construction_main ($) { Line 4096  sub _tree_construction_main ($) {
4096            ## Ignore the token            ## Ignore the token
4097            !!!next-token;            !!!next-token;
4098            redo B;            redo B;
4099      } elsif ($self->{insertion_mode} == AFTER_BODY_IM or      } elsif ($self->{insertion_mode} & BODY_AFTER_IMS) {
4100               $self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($token->{type} == CHARACTER_TOKEN) {
       if ($token->{type} eq 'character') {  
4101          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4102            my $data = $1;            my $data = $1;
4103            ## As if in body            ## As if in body
# Line 4127  sub _tree_construction_main ($) { Line 4123  sub _tree_construction_main ($) {
4123          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
4124          ## reprocess          ## reprocess
4125          redo B;          redo B;
4126        } elsif ($token->{type} eq 'start tag') {        } elsif ($token->{type} == START_TAG_TOKEN) {
4127          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
4128            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
4129                        
# Line 4140  sub _tree_construction_main ($) { Line 4136  sub _tree_construction_main ($) {
4136          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
4137          ## reprocess          ## reprocess
4138          redo B;          redo B;
4139        } elsif ($token->{type} eq 'end tag') {        } elsif ($token->{type} == END_TAG_TOKEN) {
4140          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
4141            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
4142                        
# Line 4170  sub _tree_construction_main ($) { Line 4166  sub _tree_construction_main ($) {
4166        } else {        } else {
4167          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
4168        }        }
4169      } elsif ($self->{insertion_mode} == IN_FRAMESET_IM or      } elsif ($self->{insertion_mode} & FRAME_IMS) {
4170               $self->{insertion_mode} == AFTER_FRAMESET_IM or        if ($token->{type} == CHARACTER_TOKEN) {
              $self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {  
       if ($token->{type} eq 'character') {  
4171          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4172            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4173                        
# Line 4206  sub _tree_construction_main ($) { Line 4200  sub _tree_construction_main ($) {
4200          }          }
4201                    
4202          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
4203        } elsif ($token->{type} eq 'start tag') {        } elsif ($token->{type} == START_TAG_TOKEN) {
4204          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
4205            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
4206    
# Line 4239  sub _tree_construction_main ($) { Line 4233  sub _tree_construction_main ($) {
4233            !!!next-token;            !!!next-token;
4234            redo B;            redo B;
4235          }          }
4236        } elsif ($token->{type} eq 'end tag') {        } elsif ($token->{type} == END_TAG_TOKEN) {
4237          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
4238            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
4239    
# Line 4289  sub _tree_construction_main ($) { Line 4283  sub _tree_construction_main ($) {
4283      }      }
4284    
4285      ## "in body" insertion mode      ## "in body" insertion mode
4286      if ($token->{type} eq 'start tag') {      if ($token->{type} == START_TAG_TOKEN) {
4287        if ($token->{tag_name} eq 'script') {        if ($token->{tag_name} eq 'script') {
4288          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
4289          $script_start_tag->($insert);          $script_start_tag->($insert);
# Line 4369  sub _tree_construction_main ($) { Line 4363  sub _tree_construction_main ($) {
4363          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
4364            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
4365              !!!back-token;              !!!back-token;
4366              $token = {type => 'end tag', tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
4367              redo B;              redo B;
4368            } elsif ({            } elsif ({
4369                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 4382  sub _tree_construction_main ($) { Line 4376  sub _tree_construction_main ($) {
4376          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4377          if ($token->{tag_name} eq 'pre') {          if ($token->{tag_name} eq 'pre') {
4378            !!!next-token;            !!!next-token;
4379            if ($token->{type} eq 'character') {            if ($token->{type} == CHARACTER_TOKEN) {
4380              $token->{data} =~ s/^\x0A//;              $token->{data} =~ s/^\x0A//;
4381              unless (length $token->{data}) {              unless (length $token->{data}) {
4382                !!!next-token;                !!!next-token;
# Line 4403  sub _tree_construction_main ($) { Line 4397  sub _tree_construction_main ($) {
4397            INSCOPE: for (reverse @{$self->{open_elements}}) {            INSCOPE: for (reverse @{$self->{open_elements}}) {
4398              if ($_->[1] eq 'p') {              if ($_->[1] eq 'p') {
4399                !!!back-token;                !!!back-token;
4400                $token = {type => 'end tag', tag_name => 'p'};                $token = {type => END_TAG_TOKEN, tag_name => 'p'};
4401                redo B;                redo B;
4402              } elsif ({              } elsif ({
4403                        table => 1, caption => 1, td => 1, th => 1,                        table => 1, caption => 1, td => 1, th => 1,
# Line 4423  sub _tree_construction_main ($) { Line 4417  sub _tree_construction_main ($) {
4417          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
4418            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
4419              !!!back-token;              !!!back-token;
4420              $token = {type => 'end tag', tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
4421              redo B;              redo B;
4422            } elsif ({            } elsif ({
4423                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 4470  sub _tree_construction_main ($) { Line 4464  sub _tree_construction_main ($) {
4464          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
4465            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
4466              !!!back-token;              !!!back-token;
4467              $token = {type => 'end tag', tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
4468              redo B;              redo B;
4469            } elsif ({            } elsif ({
4470                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 4517  sub _tree_construction_main ($) { Line 4511  sub _tree_construction_main ($) {
4511          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
4512            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
4513              !!!back-token;              !!!back-token;
4514              $token = {type => 'end tag', tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
4515              redo B;              redo B;
4516            } elsif ({            } elsif ({
4517                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 4541  sub _tree_construction_main ($) { Line 4535  sub _tree_construction_main ($) {
4535            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
4536            if ($node->[1] eq 'p') {            if ($node->[1] eq 'p') {
4537              !!!back-token;              !!!back-token;
4538              $token = {type => 'end tag', tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
4539              redo B;              redo B;
4540            } elsif ({            } elsif ({
4541                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 4585  sub _tree_construction_main ($) { Line 4579  sub _tree_construction_main ($) {
4579              !!!parse-error (type => 'in a:a');              !!!parse-error (type => 'in a:a');
4580                            
4581              !!!back-token;              !!!back-token;
4582              $token = {type => 'end tag', tag_name => 'a'};              $token = {type => END_TAG_TOKEN, tag_name => 'a'};
4583              $formatting_end_tag->($token->{tag_name});              $formatting_end_tag->($token->{tag_name});
4584                            
4585              AFE2: for (reverse 0..$#$active_formatting_elements) {              AFE2: for (reverse 0..$#$active_formatting_elements) {
# Line 4634  sub _tree_construction_main ($) { Line 4628  sub _tree_construction_main ($) {
4628            if ($node->[1] eq 'nobr') {            if ($node->[1] eq 'nobr') {
4629              !!!parse-error (type => 'not closed:nobr');              !!!parse-error (type => 'not closed:nobr');
4630              !!!back-token;              !!!back-token;
4631              $token = {type => 'end tag', tag_name => 'nobr'};              $token = {type => END_TAG_TOKEN, tag_name => 'nobr'};
4632              redo B;              redo B;
4633            } elsif ({            } elsif ({
4634                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 4656  sub _tree_construction_main ($) { Line 4650  sub _tree_construction_main ($) {
4650            if ($node->[1] eq 'button') {            if ($node->[1] eq 'button') {
4651              !!!parse-error (type => 'in button:button');              !!!parse-error (type => 'in button:button');
4652              !!!back-token;              !!!back-token;
4653              $token = {type => 'end tag', tag_name => 'button'};              $token = {type => END_TAG_TOKEN, tag_name => 'button'};
4654              redo B;              redo B;
4655            } elsif ({            } elsif ({
4656                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 4691  sub _tree_construction_main ($) { Line 4685  sub _tree_construction_main ($) {
4685          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
4686            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
4687              !!!back-token;              !!!back-token;
4688              $token = {type => 'end tag', tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
4689              redo B;              redo B;
4690            } elsif ({            } elsif ({
4691                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 4730  sub _tree_construction_main ($) { Line 4724  sub _tree_construction_main ($) {
4724          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
4725            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
4726              !!!back-token;              !!!back-token;
4727              $token = {type => 'end tag', tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
4728              redo B;              redo B;
4729            } elsif ({            } elsif ({
4730                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 4770  sub _tree_construction_main ($) { Line 4764  sub _tree_construction_main ($) {
4764            delete $at->{action};            delete $at->{action};
4765            delete $at->{prompt};            delete $at->{prompt};
4766            my @tokens = (            my @tokens = (
4767                          {type => 'start tag', tag_name => 'form',                          {type => START_TAG_TOKEN, tag_name => 'form',
4768                           attributes => $form_attrs},                           attributes => $form_attrs},
4769                          {type => 'start tag', tag_name => 'hr'},                          {type => START_TAG_TOKEN, tag_name => 'hr'},
4770                          {type => 'start tag', tag_name => 'p'},                          {type => START_TAG_TOKEN, tag_name => 'p'},
4771                          {type => 'start tag', tag_name => 'label'},                          {type => START_TAG_TOKEN, tag_name => 'label'},
4772                         );                         );
4773            if ($prompt_attr) {            if ($prompt_attr) {
4774              push @tokens, {type => 'character', data => $prompt_attr->{value}};              push @tokens, {type => CHARACTER_TOKEN, data => $prompt_attr->{value}};
4775            } else {            } else {
4776              push @tokens, {type => 'character',              push @tokens, {type => CHARACTER_TOKEN,
4777                             data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD                             data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD
4778              ## TODO: make this configurable              ## TODO: make this configurable
4779            }            }
4780            push @tokens,            push @tokens,
4781                          {type => 'start tag', tag_name => 'input', attributes => $at},                          {type => START_TAG_TOKEN, tag_name => 'input', attributes => $at},
4782                          #{type => 'character', data => ''}, # SHOULD                          #{type => CHARACTER_TOKEN, data => ''}, # SHOULD
4783                          {type => 'end tag', tag_name => 'label'},                          {type => END_TAG_TOKEN, tag_name => 'label'},
4784                          {type => 'end tag', tag_name => 'p'},                          {type => END_TAG_TOKEN, tag_name => 'p'},
4785                          {type => 'start tag', tag_name => 'hr'},                          {type => START_TAG_TOKEN, tag_name => 'hr'},
4786                          {type => 'end tag', tag_name => 'form'};                          {type => END_TAG_TOKEN, tag_name => 'form'};
4787            $token = shift @tokens;            $token = shift @tokens;
4788            !!!back-token (@tokens);            !!!back-token (@tokens);
4789            redo B;            redo B;
# Line 4807  sub _tree_construction_main ($) { Line 4801  sub _tree_construction_main ($) {
4801                    
4802          my $text = '';          my $text = '';
4803          !!!next-token;          !!!next-token;
4804          if ($token->{type} eq 'character') {          if ($token->{type} == CHARACTER_TOKEN) {
4805            $token->{data} =~ s/^\x0A//;            $token->{data} =~ s/^\x0A//;
4806            unless (length $token->{data}) {            unless (length $token->{data}) {
4807              !!!next-token;              !!!next-token;
4808            }            }
4809          }          }
4810          while ($token->{type} eq 'character') {          while ($token->{type} == CHARACTER_TOKEN) {
4811            $text .= $token->{data};            $text .= $token->{data};
4812            !!!next-token;            !!!next-token;
4813          }          }
# Line 4823  sub _tree_construction_main ($) { Line 4817  sub _tree_construction_main ($) {
4817                    
4818          $self->{content_model} = PCDATA_CONTENT_MODEL;          $self->{content_model} = PCDATA_CONTENT_MODEL;
4819                    
4820          if ($token->{type} eq 'end tag' and          if ($token->{type} == END_TAG_TOKEN and
4821              $token->{tag_name} eq $tag_name) {              $token->{tag_name} eq $tag_name) {
4822            ## Ignore the token            ## Ignore the token
4823          } else {          } else {
# Line 4868  sub _tree_construction_main ($) { Line 4862  sub _tree_construction_main ($) {
4862          !!!next-token;          !!!next-token;
4863          redo B;          redo B;
4864        }        }
4865      } elsif ($token->{type} eq 'end tag') {      } elsif ($token->{type} == END_TAG_TOKEN) {
4866        if ($token->{tag_name} eq 'body') {        if ($token->{tag_name} eq 'body') {
4867          if (@{$self->{open_elements}} > 1 and          if (@{$self->{open_elements}} > 1 and
4868              $self->{open_elements}->[1]->[1] eq 'body') {              $self->{open_elements}->[1]->[1] eq 'body') {
# Line 4929  sub _tree_construction_main ($) { Line 4923  sub _tree_construction_main ($) {
4923                   tbody => 1, tfoot=> 1, thead => 1,                   tbody => 1, tfoot=> 1, thead => 1,
4924                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4925                !!!back-token;                !!!back-token;
4926                $token = {type => 'end tag',                $token = {type => END_TAG_TOKEN,
4927                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
4928                redo B;                redo B;
4929              }              }
# Line 4977  sub _tree_construction_main ($) { Line 4971  sub _tree_construction_main ($) {
4971                   tbody => 1, tfoot=> 1, thead => 1,                   tbody => 1, tfoot=> 1, thead => 1,
4972                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4973                !!!back-token;                !!!back-token;
4974                $token = {type => 'end tag',                $token = {type => END_TAG_TOKEN,
4975                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
4976                redo B;                redo B;
4977              }              }
# Line 5016  sub _tree_construction_main ($) { Line 5010  sub _tree_construction_main ($) {
5010                   tbody => 1, tfoot=> 1, thead => 1,                   tbody => 1, tfoot=> 1, thead => 1,
5011                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
5012                !!!back-token;                !!!back-token;
5013                $token = {type => 'end tag',                $token = {type => END_TAG_TOKEN,
5014                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
5015                redo B;                redo B;
5016              }              }
# Line 5090  sub _tree_construction_main ($) { Line 5084  sub _tree_construction_main ($) {
5084              if ({              if ({
5085                   dd => 1, dt => 1, li => 1, p => 1,                   dd => 1, dt => 1, li => 1, p => 1,
5086                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
5087                   tbody => 1, tfoot=> 1, thead => 1,                   tbody => 1, tfoot => 1, thead => 1,
5088                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
5089                !!!back-token;                !!!back-token;
5090                $token = {type => 'end tag',                $token = {type => END_TAG_TOKEN,
5091                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
5092                redo B;                redo B;
5093              }              }

Legend:
Removed from v.1.54  
changed lines
  Added in v.1.56

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24