/[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.172 by wakaba, Sun Sep 14 03:07:58 2008 UTC revision 1.190 by wakaba, Sun Sep 21 05:08:16 2008 UTC
# Line 3  use strict; Line 3  use strict;
3  our $VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};  our $VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
4  use Error qw(:try);  use Error qw(:try);
5    
6    ## NOTE: This module don't check all HTML5 parse errors; character
7    ## encoding related parse errors are expected to be handled by relevant
8    ## modules.
9    ## Parse errors for control characters that are not allowed in HTML5
10    ## documents, for surrogate code points, and for noncharacter code
11    ## points, as well as U+FFFD substitions for characters whose code points
12    ## is higher than U+10FFFF may be detected by combining the parser with
13    ## the checker implemented by Whatpm::Charset::UnicodeChecker (for its
14    ## usage example, see |t/HTML-tree.t| in the Whatpm package or the
15    ## WebHACC::Language::HTML module in the WebHACC package).
16    
17  ## ISSUE:  ## ISSUE:
18  ## var doc = implementation.createDocument (null, null, null);  ## var doc = implementation.createDocument (null, null, null);
19  ## doc.write ('');  ## doc.write ('');
# Line 390  sub parse_byte_stream ($$$$;$$) { Line 401  sub parse_byte_stream ($$$$;$$) {
401            ## TODO: Is this ok?  Transfer protocol's parameter should be            ## TODO: Is this ok?  Transfer protocol's parameter should be
402            ## interpreted in its semantics?            ## interpreted in its semantics?
403    
       ## ISSUE: Unsupported encoding is not ignored according to the spec.  
404        ($char_stream, $e_status) = $charset->get_decode_handle        ($char_stream, $e_status) = $charset->get_decode_handle
405            ($byte_stream, allow_error_reporting => 1,            ($byte_stream, allow_error_reporting => 1,
406             allow_fallback => 1);             allow_fallback => 1);
# Line 398  sub parse_byte_stream ($$$$;$$) { Line 408  sub parse_byte_stream ($$$$;$$) {
408          $self->{confident} = 1;          $self->{confident} = 1;
409          last SNIFFING;          last SNIFFING;
410        } else {        } else {
411          ## TODO: unsupported error          !!!parse-error (type => 'charset:not supported',
412                            layer => 'encode',
413                            line => 1, column => 1,
414                            value => $charset_name,
415                            level => $self->{level}->{uncertain});
416        }        }
417      }      }
418    
# Line 496  sub parse_byte_stream ($$$$;$$) { Line 510  sub parse_byte_stream ($$$$;$$) {
510                      line => 1, column => 1,                      line => 1, column => 1,
511                      layer => 'encode');                      layer => 'encode');
512    } elsif (not ($e_status &    } elsif (not ($e_status &
513                  Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {                  Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL ())) {
514      $self->{input_encoding} = $charset->get_iana_name;      $self->{input_encoding} = $charset->get_iana_name;
515      !!!parse-error (type => 'chardecode:no error',      !!!parse-error (type => 'chardecode:no error',
516                      text => $self->{input_encoding},                      text => $self->{input_encoding},
# Line 561  sub parse_byte_stream ($$$$;$$) { Line 575  sub parse_byte_stream ($$$$;$$) {
575    my $char_onerror = sub {    my $char_onerror = sub {
576      my (undef, $type, %opt) = @_;      my (undef, $type, %opt) = @_;
577      !!!parse-error (layer => 'encode',      !!!parse-error (layer => 'encode',
578                      %opt, type => $type,                      line => $self->{line}, column => $self->{column} + 1,
579                      line => $self->{line}, column => $self->{column} + 1);                      %opt, type => $type);
580      if ($opt{octets}) {      if ($opt{octets}) {
581        ${$opt{octets}} = "\x{FFFD}"; # relacement character        ${$opt{octets}} = "\x{FFFD}"; # relacement character
582      }      }
# Line 571  sub parse_byte_stream ($$$$;$$) { Line 585  sub parse_byte_stream ($$$$;$$) {
585    my $wrapped_char_stream = $get_wrapper->($char_stream);    my $wrapped_char_stream = $get_wrapper->($char_stream);
586    $wrapped_char_stream->onerror ($char_onerror);    $wrapped_char_stream->onerror ($char_onerror);
587    
588    my @args = @_; shift @args; # $s    my @args = ($_[1], $_[2]); # $doc, $onerror - $get_wrapper = undef;
589    my $return;    my $return;
590    try {    try {
591      $return = $self->parse_char_stream ($wrapped_char_stream, @args);        $return = $self->parse_char_stream ($wrapped_char_stream, @args);  
# Line 586  sub parse_byte_stream ($$$$;$$) { Line 600  sub parse_byte_stream ($$$$;$$) {
600                        line => 1, column => 1,                        line => 1, column => 1,
601                        layer => 'encode');                        layer => 'encode');
602      } elsif (not ($e_status &      } elsif (not ($e_status &
603                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL ())) {
604        $self->{input_encoding} = $charset->get_iana_name;        $self->{input_encoding} = $charset->get_iana_name;
605        !!!parse-error (type => 'chardecode:no error',        !!!parse-error (type => 'chardecode:no error',
606                        text => $self->{input_encoding},                        text => $self->{input_encoding},
# Line 621  sub parse_char_string ($$$;$$) { Line 635  sub parse_char_string ($$$;$$) {
635    my $s = ref $_[0] ? $_[0] : \($_[0]);    my $s = ref $_[0] ? $_[0] : \($_[0]);
636    require Whatpm::Charset::DecodeHandle;    require Whatpm::Charset::DecodeHandle;
637    my $input = Whatpm::Charset::DecodeHandle::CharString->new ($s);    my $input = Whatpm::Charset::DecodeHandle::CharString->new ($s);
   if ($_[3]) {  
     $input = $_[3]->($input);  
   }  
638    return $self->parse_char_stream ($input, @_[1..$#_]);    return $self->parse_char_stream ($input, @_[1..$#_]);
639  } # parse_char_string  } # parse_char_string
640  *parse_string = \&parse_char_string; ## NOTE: Alias for backward compatibility.  *parse_string = \&parse_char_string; ## NOTE: Alias for backward compatibility.
641    
642  sub parse_char_stream ($$$;$) {  sub parse_char_stream ($$$;$$) {
643    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
644    my $input = $_[0];    my $input = $_[0];
645    $self->{document} = $_[1];    $self->{document} = $_[1];
# Line 639  sub parse_char_stream ($$$;$) { Line 650  sub parse_char_stream ($$$;$) {
650    $self->{confident} = 1 unless exists $self->{confident};    $self->{confident} = 1 unless exists $self->{confident};
651    $self->{document}->input_encoding ($self->{input_encoding})    $self->{document}->input_encoding ($self->{input_encoding})
652        if defined $self->{input_encoding};        if defined $self->{input_encoding};
653    ## TODO: |{input_encoding}| is needless?
654    
   my $i = 0;  
655    $self->{line_prev} = $self->{line} = 1;    $self->{line_prev} = $self->{line} = 1;
656    $self->{column_prev} = $self->{column} = 0;    $self->{column_prev} = -1;
657    $self->{set_next_char} = sub {    $self->{column} = 0;
658      $self->{set_nc} = sub {
659      my $self = shift;      my $self = shift;
660    
661      pop @{$self->{prev_char}};      my $char = '';
662      unshift @{$self->{prev_char}}, $self->{next_char};      if (defined $self->{next_nc}) {
663          $char = $self->{next_nc};
664      my $char;        delete $self->{next_nc};
665      if (defined $self->{next_next_char}) {        $self->{nc} = ord $char;
       $char = $self->{next_next_char};  
       delete $self->{next_next_char};  
666      } else {      } else {
667        $char = $input->getc;        $self->{char_buffer} = '';
668          $self->{char_buffer_pos} = 0;
669    
670          my $count = $input->manakai_read_until
671             ($self->{char_buffer}, qr/[^\x00\x0A\x0D]/, $self->{char_buffer_pos});
672          if ($count) {
673            $self->{line_prev} = $self->{line};
674            $self->{column_prev} = $self->{column};
675            $self->{column}++;
676            $self->{nc}
677                = ord substr ($self->{char_buffer}, $self->{char_buffer_pos}++, 1);
678            return;
679          }
680    
681          if ($input->read ($char, 1)) {
682            $self->{nc} = ord $char;
683          } else {
684            $self->{nc} = -1;
685            return;
686          }
687      }      }
     $self->{next_char} = -1 and return unless defined $char;  
     $self->{next_char} = ord $char;  
688    
689      ($self->{line_prev}, $self->{column_prev})      ($self->{line_prev}, $self->{column_prev})
690          = ($self->{line}, $self->{column});          = ($self->{line}, $self->{column});
691      $self->{column}++;      $self->{column}++;
692            
693      if ($self->{next_char} == 0x000A) { # LF      if ($self->{nc} == 0x000A) { # LF
694        !!!cp ('j1');        !!!cp ('j1');
695        $self->{line}++;        $self->{line}++;
696        $self->{column} = 0;        $self->{column} = 0;
697      } elsif ($self->{next_char} == 0x000D) { # CR      } elsif ($self->{nc} == 0x000D) { # CR
698        !!!cp ('j2');        !!!cp ('j2');
699  ## TODO: support for abort/streaming  ## TODO: support for abort/streaming
700        my $next = $input->getc;        my $next = '';
701        if (defined $next and $next ne "\x0A") {        if ($input->read ($next, 1) and $next ne "\x0A") {
702          $self->{next_next_char} = $next;          $self->{next_nc} = $next;
703        }        }
704        $self->{next_char} = 0x000A; # LF # MUST        $self->{nc} = 0x000A; # LF # MUST
705        $self->{line}++;        $self->{line}++;
706        $self->{column} = 0;        $self->{column} = 0;
707      } elsif ($self->{next_char} > 0x10FFFF) {      } elsif ($self->{nc} == 0x0000) { # NULL
       !!!cp ('j3');  
       $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST  
     } elsif ($self->{next_char} == 0x0000) { # NULL  
708        !!!cp ('j4');        !!!cp ('j4');
709        !!!parse-error (type => 'NULL');        !!!parse-error (type => 'NULL');
710        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{nc} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
     } elsif ($self->{next_char} <= 0x0008 or  
              (0x000E <= $self->{next_char} and $self->{next_char} <= 0x001F) or  
              (0x007F <= $self->{next_char} and $self->{next_char} <= 0x009F) or  
              (0xD800 <= $self->{next_char} and $self->{next_char} <= 0xDFFF) or  
              (0xFDD0 <= $self->{next_char} and $self->{next_char} <= 0xFDDF) or  
 ## ISSUE: U+FDE0-U+FDEF are not excluded  
              {  
               0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,  
               0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,  
               0x4FFFE => 1, 0x4FFFF => 1, 0x5FFFE => 1, 0x5FFFF => 1,  
               0x6FFFE => 1, 0x6FFFF => 1, 0x7FFFE => 1, 0x7FFFF => 1,  
               0x8FFFE => 1, 0x8FFFF => 1, 0x9FFFE => 1, 0x9FFFF => 1,  
               0xAFFFE => 1, 0xAFFFF => 1, 0xBFFFE => 1, 0xBFFFF => 1,  
               0xCFFFE => 1, 0xCFFFF => 1, 0xDFFFE => 1, 0xDFFFF => 1,  
               0xEFFFE => 1, 0xEFFFF => 1, 0xFFFFE => 1, 0xFFFFF => 1,  
               0x10FFFE => 1, 0x10FFFF => 1,  
              }->{$self->{next_char}}) {  
       !!!cp ('j5');  
       if ($self->{next_char} < 0x10000) {  
         !!!parse-error (type => 'control char',  
                         text => (sprintf 'U+%04X', $self->{next_char}));  
       } else {  
         !!!parse-error (type => 'control char',  
                         text => (sprintf 'U-%08X', $self->{next_char}));  
       }  
711      }      }
712    };    };
   $self->{prev_char} = [-1, -1, -1];  
   $self->{next_char} = -1;  
713    
714    $self->{read_until} = sub {    $self->{read_until} = sub {
715      #my ($scalar, $specials_range, $offset) = @_;      #my ($scalar, $specials_range, $offset) = @_;
716      my $specials_range = $_[1];      return 0 if defined $self->{next_nc};
717      return 0 if defined $self->{next_next_char};  
718      my $count = $input->manakai_read_until      my $pattern = qr/[^$_[1]\x00\x0A\x0D]/;
719         ($_[0],      my $offset = $_[2] || 0;
720          qr/(?![$specials_range\x{FDD0}-\x{FDDF}\x{FFFE}\x{FFFF}\x{1FFFE}\x{1FFFF}\x{2FFFE}\x{2FFFF}\x{3FFFE}\x{3FFFF}\x{4FFFE}\x{4FFFF}\x{5FFFE}\x{5FFFF}\x{6FFFE}\x{6FFFF}\x{7FFFE}\x{7FFFF}\x{8FFFE}\x{8FFFF}\x{9FFFE}\x{9FFFF}\x{AFFFE}\x{AFFFF}\x{BFFFE}\x{BFFFF}\x{CFFFE}\x{CFFFF}\x{DFFFE}\x{DFFFF}\x{EFFFE}\x{EFFFF}\x{FFFFE}\x{FFFFF}])[\x20-\x7E\xA0-\x{D7FF}\x{E000}-\x{10FFFD}]/,  
721          $_[2]);      if ($self->{char_buffer_pos} < length $self->{char_buffer}) {
722      if ($count) {        pos ($self->{char_buffer}) = $self->{char_buffer_pos};
723        $self->{column} += $count;        if ($self->{char_buffer} =~ /\G(?>$pattern)+/) {
724        $self->{column_prev} += $count;          substr ($_[0], $offset)
725        $self->{prev_char} = [-1, -1, -1];              = substr ($self->{char_buffer}, $-[0], $+[0] - $-[0]);
726        $self->{next_char} = -1;          my $count = $+[0] - $-[0];
727            if ($count) {
728              $self->{column} += $count;
729              $self->{char_buffer_pos} += $count;
730              $self->{line_prev} = $self->{line};
731              $self->{column_prev} = $self->{column} - 1;
732              $self->{nc} = -1;
733            }
734            return $count;
735          } else {
736            return 0;
737          }
738        } else {
739          my $count = $input->manakai_read_until ($_[0], $pattern, $_[2]);
740          if ($count) {
741            $self->{column} += $count;
742            $self->{line_prev} = $self->{line};
743            $self->{column_prev} = $self->{column} - 1;
744            $self->{nc} = -1;
745          }
746          return $count;
747      }      }
     return $count;  
748    }; # $self->{read_until}    }; # $self->{read_until}
749    
750    my $onerror = $_[2] || sub {    my $onerror = $_[2] || sub {
# Line 741  sub parse_char_stream ($$$;$) { Line 757  sub parse_char_stream ($$$;$) {
757      $onerror->(line => $self->{line}, column => $self->{column}, @_);      $onerror->(line => $self->{line}, column => $self->{column}, @_);
758    };    };
759    
760      my $char_onerror = sub {
761        my (undef, $type, %opt) = @_;
762        !!!parse-error (layer => 'encode',
763                        line => $self->{line}, column => $self->{column} + 1,
764                        %opt, type => $type);
765      }; # $char_onerror
766    
767      if ($_[3]) {
768        $input = $_[3]->($input);
769        $input->onerror ($char_onerror);
770      } else {
771        $input->onerror ($char_onerror) unless defined $input->onerror;
772      }
773    
774    $self->_initialize_tokenizer;    $self->_initialize_tokenizer;
775    $self->_initialize_tree_constructor;    $self->_initialize_tree_constructor;
776    $self->_construct_tree;    $self->_construct_tree;
# Line 760  sub new ($) { Line 790  sub new ($) {
790                info => 'i',                info => 'i',
791                uncertain => 'u'},                uncertain => 'u'},
792    }, $class;    }, $class;
793    $self->{set_next_char} = sub {    $self->{set_nc} = sub {
794      $self->{next_char} = -1;      $self->{nc} = -1;
795    };    };
796    $self->{parse_error} = sub {    $self->{parse_error} = sub {
797      #      #
# Line 826  sub CDATA_SECTION_STATE () { 35 } Line 856  sub CDATA_SECTION_STATE () { 35 }
856  sub MD_HYPHEN_STATE () { 36 } # "markup declaration open state" in the spec  sub MD_HYPHEN_STATE () { 36 } # "markup declaration open state" in the spec
857  sub MD_DOCTYPE_STATE () { 37 } # "markup declaration open state" in the spec  sub MD_DOCTYPE_STATE () { 37 } # "markup declaration open state" in the spec
858  sub MD_CDATA_STATE () { 38 } # "markup declaration open state" in the spec  sub MD_CDATA_STATE () { 38 } # "markup declaration open state" in the spec
859  sub CDATA_PCDATA_CLOSE_TAG_STATE () { 39 } # "close tag open state" in the spec  sub CDATA_RCDATA_CLOSE_TAG_STATE () { 39 } # "close tag open state" in the spec
860  sub CDATA_SECTION_MSE1_STATE () { 40 } # "CDATA section state" in the spec  sub CDATA_SECTION_MSE1_STATE () { 40 } # "CDATA section state" in the spec
861  sub CDATA_SECTION_MSE2_STATE () { 41 } # "CDATA section state" in the spec  sub CDATA_SECTION_MSE2_STATE () { 41 } # "CDATA section state" in the spec
862  sub PUBLIC_STATE () { 42 } # "after DOCTYPE name state" in the spec  sub PUBLIC_STATE () { 42 } # "after DOCTYPE name state" in the spec
# Line 840  sub NCR_NUM_STATE () { 46 } Line 870  sub NCR_NUM_STATE () { 46 }
870  sub HEXREF_X_STATE () { 47 }  sub HEXREF_X_STATE () { 47 }
871  sub HEXREF_HEX_STATE () { 48 }  sub HEXREF_HEX_STATE () { 48 }
872  sub ENTITY_NAME_STATE () { 49 }  sub ENTITY_NAME_STATE () { 49 }
873    sub PCDATA_STATE () { 50 } # "data state" in the spec
874    
875  sub DOCTYPE_TOKEN () { 1 }  sub DOCTYPE_TOKEN () { 1 }
876  sub COMMENT_TOKEN () { 2 }  sub COMMENT_TOKEN () { 2 }
# Line 892  sub IN_COLUMN_GROUP_IM () { 0b10 } Line 923  sub IN_COLUMN_GROUP_IM () { 0b10 }
923  sub _initialize_tokenizer ($) {  sub _initialize_tokenizer ($) {
924    my $self = shift;    my $self = shift;
925    $self->{state} = DATA_STATE; # MUST    $self->{state} = DATA_STATE; # MUST
926    #$self->{state_keyword}; # initialized when used    #$self->{s_kwd}; # state keyword - initialized when used
927    #$self->{entity__value}; # initialized when used    #$self->{entity__value}; # initialized when used
928    #$self->{entity__match}; # initialized when used    #$self->{entity__match}; # initialized when used
929    $self->{content_model} = PCDATA_CONTENT_MODEL; # be    $self->{content_model} = PCDATA_CONTENT_MODEL; # be
930    undef $self->{current_token};    undef $self->{ct}; # current token
931    undef $self->{current_attribute};    undef $self->{ca}; # current attribute
932    undef $self->{last_emitted_start_tag_name};    undef $self->{last_stag_name}; # last emitted start tag name
933    #$self->{prev_state}; # initialized when used    #$self->{prev_state}; # initialized when used
934    delete $self->{self_closing};    delete $self->{self_closing};
935    # $self->{next_char}    $self->{char_buffer} = '';
936      $self->{char_buffer_pos} = 0;
937      $self->{nc} = -1; # next input character
938      #$self->{next_nc}
939    !!!next-input-character;    !!!next-input-character;
940    $self->{token} = [];    $self->{token} = [];
941    # $self->{escape}    # $self->{escape}
# Line 912  sub _initialize_tokenizer ($) { Line 946  sub _initialize_tokenizer ($) {
946  ##       CHARACTER_TOKEN, or END_OF_FILE_TOKEN  ##       CHARACTER_TOKEN, or END_OF_FILE_TOKEN
947  ##   ->{name} (DOCTYPE_TOKEN)  ##   ->{name} (DOCTYPE_TOKEN)
948  ##   ->{tag_name} (START_TAG_TOKEN, END_TAG_TOKEN)  ##   ->{tag_name} (START_TAG_TOKEN, END_TAG_TOKEN)
949  ##   ->{public_identifier} (DOCTYPE_TOKEN)  ##   ->{pubid} (DOCTYPE_TOKEN)
950  ##   ->{system_identifier} (DOCTYPE_TOKEN)  ##   ->{sysid} (DOCTYPE_TOKEN)
951  ##   ->{quirks} == 1 or 0 (DOCTYPE_TOKEN): "force-quirks" flag  ##   ->{quirks} == 1 or 0 (DOCTYPE_TOKEN): "force-quirks" flag
952  ##   ->{attributes} isa HASH (START_TAG_TOKEN, END_TAG_TOKEN)  ##   ->{attributes} isa HASH (START_TAG_TOKEN, END_TAG_TOKEN)
953  ##        ->{name}  ##        ->{name}
# Line 935  sub _initialize_tokenizer ($) { Line 969  sub _initialize_tokenizer ($) {
969  ## TODO: Polytheistic slash SHOULD NOT be used. (Applied only to atheists.)  ## TODO: Polytheistic slash SHOULD NOT be used. (Applied only to atheists.)
970  ## (This requirement was dropped from HTML5 spec, unfortunately.)  ## (This requirement was dropped from HTML5 spec, unfortunately.)
971    
972    my $is_space = {
973      0x0009 => 1, # CHARACTER TABULATION (HT)
974      0x000A => 1, # LINE FEED (LF)
975      #0x000B => 0, # LINE TABULATION (VT)
976      0x000C => 1, # FORM FEED (FF)
977      #0x000D => 1, # CARRIAGE RETURN (CR)
978      0x0020 => 1, # SPACE (SP)
979    };
980    
981  sub _get_next_token ($) {  sub _get_next_token ($) {
982    my $self = shift;    my $self = shift;
983    
984    if ($self->{self_closing}) {    if ($self->{self_closing}) {
985      !!!parse-error (type => 'nestc', token => $self->{current_token});      !!!parse-error (type => 'nestc', token => $self->{ct});
986      ## NOTE: The |self_closing| flag is only set by start tag token.      ## NOTE: The |self_closing| flag is only set by start tag token.
987      ## In addition, when a start tag token is emitted, it is always set to      ## In addition, when a start tag token is emitted, it is always set to
988      ## |current_token|.      ## |ct|.
989      delete $self->{self_closing};      delete $self->{self_closing};
990    }    }
991    
# Line 952  sub _get_next_token ($) { Line 995  sub _get_next_token ($) {
995    }    }
996    
997    A: {    A: {
998      if ($self->{state} == DATA_STATE) {      if ($self->{state} == PCDATA_STATE) {
999        if ($self->{next_char} == 0x0026) { # &        ## NOTE: Same as |DATA_STATE|, but only for |PCDATA| content model.
1000    
1001          if ($self->{nc} == 0x0026) { # &
1002            !!!cp (0.1);
1003            ## NOTE: In the spec, the tokenizer is switched to the
1004            ## "entity data state".  In this implementation, the tokenizer
1005            ## is switched to the |ENTITY_STATE|, which is an implementation
1006            ## of the "consume a character reference" algorithm.
1007            $self->{entity_add} = -1;
1008            $self->{prev_state} = DATA_STATE;
1009            $self->{state} = ENTITY_STATE;
1010            !!!next-input-character;
1011            redo A;
1012          } elsif ($self->{nc} == 0x003C) { # <
1013            !!!cp (0.2);
1014            $self->{state} = TAG_OPEN_STATE;
1015            !!!next-input-character;
1016            redo A;
1017          } elsif ($self->{nc} == -1) {
1018            !!!cp (0.3);
1019            !!!emit ({type => END_OF_FILE_TOKEN,
1020                      line => $self->{line}, column => $self->{column}});
1021            last A; ## TODO: ok?
1022          } else {
1023            !!!cp (0.4);
1024            #
1025          }
1026    
1027          # Anything else
1028          my $token = {type => CHARACTER_TOKEN,
1029                       data => chr $self->{nc},
1030                       line => $self->{line}, column => $self->{column},
1031                      };
1032          $self->{read_until}->($token->{data}, q[<&], length $token->{data});
1033    
1034          ## Stay in the state.
1035          !!!next-input-character;
1036          !!!emit ($token);
1037          redo A;
1038        } elsif ($self->{state} == DATA_STATE) {
1039          $self->{s_kwd} = '' unless defined $self->{s_kwd};
1040          if ($self->{nc} == 0x0026) { # &
1041            $self->{s_kwd} = '';
1042          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA          if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA
1043              not $self->{escape}) {              not $self->{escape}) {
1044            !!!cp (1);            !!!cp (1);
# Line 961  sub _get_next_token ($) { Line 1046  sub _get_next_token ($) {
1046            ## "entity data state".  In this implementation, the tokenizer            ## "entity data state".  In this implementation, the tokenizer
1047            ## is switched to the |ENTITY_STATE|, which is an implementation            ## is switched to the |ENTITY_STATE|, which is an implementation
1048            ## of the "consume a character reference" algorithm.            ## of the "consume a character reference" algorithm.
1049            $self->{entity_additional} = -1;            $self->{entity_add} = -1;
1050            $self->{prev_state} = DATA_STATE;            $self->{prev_state} = DATA_STATE;
1051            $self->{state} = ENTITY_STATE;            $self->{state} = ENTITY_STATE;
1052            !!!next-input-character;            !!!next-input-character;
# Line 970  sub _get_next_token ($) { Line 1055  sub _get_next_token ($) {
1055            !!!cp (2);            !!!cp (2);
1056            #            #
1057          }          }
1058        } elsif ($self->{next_char} == 0x002D) { # -        } elsif ($self->{nc} == 0x002D) { # -
1059          if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA          if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1060            unless ($self->{escape}) {            $self->{s_kwd} .= '-';
1061              if ($self->{prev_char}->[0] == 0x002D and # -            
1062                  $self->{prev_char}->[1] == 0x0021 and # !            if ($self->{s_kwd} eq '<!--') {
1063                  $self->{prev_char}->[2] == 0x003C) { # <              !!!cp (3);
1064                !!!cp (3);              $self->{escape} = 1; # unless $self->{escape};
1065                $self->{escape} = 1;              $self->{s_kwd} = '--';
1066              } else {              #
1067                !!!cp (4);            } elsif ($self->{s_kwd} eq '---') {
1068              }              !!!cp (4);
1069                $self->{s_kwd} = '--';
1070                #
1071            } else {            } else {
1072              !!!cp (5);              !!!cp (5);
1073                #
1074            }            }
1075          }          }
1076                    
1077          #          #
1078        } elsif ($self->{next_char} == 0x003C) { # <        } elsif ($self->{nc} == 0x0021) { # !
1079            if (length $self->{s_kwd}) {
1080              !!!cp (5.1);
1081              $self->{s_kwd} .= '!';
1082              #
1083            } else {
1084              !!!cp (5.2);
1085              #$self->{s_kwd} = '';
1086              #
1087            }
1088            #
1089          } elsif ($self->{nc} == 0x003C) { # <
1090          if ($self->{content_model} & CM_FULL_MARKUP or # PCDATA          if ($self->{content_model} & CM_FULL_MARKUP or # PCDATA
1091              (($self->{content_model} & CM_LIMITED_MARKUP) and # CDATA | RCDATA              (($self->{content_model} & CM_LIMITED_MARKUP) and # CDATA | RCDATA
1092               not $self->{escape})) {               not $self->{escape})) {
# Line 997  sub _get_next_token ($) { Line 1096  sub _get_next_token ($) {
1096            redo A;            redo A;
1097          } else {          } else {
1098            !!!cp (7);            !!!cp (7);
1099              $self->{s_kwd} = '';
1100            #            #
1101          }          }
1102        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1103          if ($self->{escape} and          if ($self->{escape} and
1104              ($self->{content_model} & CM_LIMITED_MARKUP)) { # RCDATA | CDATA              ($self->{content_model} & CM_LIMITED_MARKUP)) { # RCDATA | CDATA
1105            if ($self->{prev_char}->[0] == 0x002D and # -            if ($self->{s_kwd} eq '--') {
               $self->{prev_char}->[1] == 0x002D) { # -  
1106              !!!cp (8);              !!!cp (8);
1107              delete $self->{escape};              delete $self->{escape};
1108            } else {            } else {
# Line 1013  sub _get_next_token ($) { Line 1112  sub _get_next_token ($) {
1112            !!!cp (10);            !!!cp (10);
1113          }          }
1114                    
1115            $self->{s_kwd} = '';
1116          #          #
1117        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1118          !!!cp (11);          !!!cp (11);
1119            $self->{s_kwd} = '';
1120          !!!emit ({type => END_OF_FILE_TOKEN,          !!!emit ({type => END_OF_FILE_TOKEN,
1121                    line => $self->{line}, column => $self->{column}});                    line => $self->{line}, column => $self->{column}});
1122          last A; ## TODO: ok?          last A; ## TODO: ok?
1123        } else {        } else {
1124          !!!cp (12);          !!!cp (12);
1125            $self->{s_kwd} = '';
1126            #
1127        }        }
1128    
1129        # Anything else        # Anything else
1130        my $token = {type => CHARACTER_TOKEN,        my $token = {type => CHARACTER_TOKEN,
1131                     data => chr $self->{next_char},                     data => chr $self->{nc},
1132                     line => $self->{line}, column => $self->{column},                     line => $self->{line}, column => $self->{column},
1133                    };                    };
1134        $self->{read_until}->($token->{data}, q[-!<>&], length $token->{data});        if ($self->{read_until}->($token->{data}, q[-!<>&],
1135                                    length $token->{data})) {
1136            $self->{s_kwd} = '';
1137          }
1138    
1139        ## Stay in the data state        ## Stay in the data state.
1140          if ($self->{content_model} == PCDATA_CONTENT_MODEL) {
1141            !!!cp (13);
1142            $self->{state} = PCDATA_STATE;
1143          } else {
1144            !!!cp (14);
1145            ## Stay in the state.
1146          }
1147        !!!next-input-character;        !!!next-input-character;
   
1148        !!!emit ($token);        !!!emit ($token);
   
1149        redo A;        redo A;
1150      } elsif ($self->{state} == TAG_OPEN_STATE) {      } elsif ($self->{state} == TAG_OPEN_STATE) {
1151        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1152          if ($self->{next_char} == 0x002F) { # /          if ($self->{nc} == 0x002F) { # /
1153            !!!cp (15);            !!!cp (15);
1154            !!!next-input-character;            !!!next-input-character;
1155            $self->{state} = CLOSE_TAG_OPEN_STATE;            $self->{state} = CLOSE_TAG_OPEN_STATE;
1156            redo A;            redo A;
1157            } elsif ($self->{nc} == 0x0021) { # !
1158              !!!cp (15.1);
1159              $self->{s_kwd} = '<' unless $self->{escape};
1160              #
1161          } else {          } else {
1162            !!!cp (16);            !!!cp (16);
1163            ## reconsume            #
           $self->{state} = DATA_STATE;  
   
           !!!emit ({type => CHARACTER_TOKEN, data => '<',  
                     line => $self->{line_prev},  
                     column => $self->{column_prev},  
                    });  
   
           redo A;  
1164          }          }
1165    
1166            ## reconsume
1167            $self->{state} = DATA_STATE;
1168            !!!emit ({type => CHARACTER_TOKEN, data => '<',
1169                      line => $self->{line_prev},
1170                      column => $self->{column_prev},
1171                     });
1172            redo A;
1173        } elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA        } elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA
1174          if ($self->{next_char} == 0x0021) { # !          if ($self->{nc} == 0x0021) { # !
1175            !!!cp (17);            !!!cp (17);
1176            $self->{state} = MARKUP_DECLARATION_OPEN_STATE;            $self->{state} = MARKUP_DECLARATION_OPEN_STATE;
1177            !!!next-input-character;            !!!next-input-character;
1178            redo A;            redo A;
1179          } elsif ($self->{next_char} == 0x002F) { # /          } elsif ($self->{nc} == 0x002F) { # /
1180            !!!cp (18);            !!!cp (18);
1181            $self->{state} = CLOSE_TAG_OPEN_STATE;            $self->{state} = CLOSE_TAG_OPEN_STATE;
1182            !!!next-input-character;            !!!next-input-character;
1183            redo A;            redo A;
1184          } elsif (0x0041 <= $self->{next_char} and          } elsif (0x0041 <= $self->{nc} and
1185                   $self->{next_char} <= 0x005A) { # A..Z                   $self->{nc} <= 0x005A) { # A..Z
1186            !!!cp (19);            !!!cp (19);
1187            $self->{current_token}            $self->{ct}
1188              = {type => START_TAG_TOKEN,              = {type => START_TAG_TOKEN,
1189                 tag_name => chr ($self->{next_char} + 0x0020),                 tag_name => chr ($self->{nc} + 0x0020),
1190                 line => $self->{line_prev},                 line => $self->{line_prev},
1191                 column => $self->{column_prev}};                 column => $self->{column_prev}};
1192            $self->{state} = TAG_NAME_STATE;            $self->{state} = TAG_NAME_STATE;
1193            !!!next-input-character;            !!!next-input-character;
1194            redo A;            redo A;
1195          } elsif (0x0061 <= $self->{next_char} and          } elsif (0x0061 <= $self->{nc} and
1196                   $self->{next_char} <= 0x007A) { # a..z                   $self->{nc} <= 0x007A) { # a..z
1197            !!!cp (20);            !!!cp (20);
1198            $self->{current_token} = {type => START_TAG_TOKEN,            $self->{ct} = {type => START_TAG_TOKEN,
1199                                      tag_name => chr ($self->{next_char}),                                      tag_name => chr ($self->{nc}),
1200                                      line => $self->{line_prev},                                      line => $self->{line_prev},
1201                                      column => $self->{column_prev}};                                      column => $self->{column_prev}};
1202            $self->{state} = TAG_NAME_STATE;            $self->{state} = TAG_NAME_STATE;
1203            !!!next-input-character;            !!!next-input-character;
1204            redo A;            redo A;
1205          } elsif ($self->{next_char} == 0x003E) { # >          } elsif ($self->{nc} == 0x003E) { # >
1206            !!!cp (21);            !!!cp (21);
1207            !!!parse-error (type => 'empty start tag',            !!!parse-error (type => 'empty start tag',
1208                            line => $self->{line_prev},                            line => $self->{line_prev},
# Line 1100  sub _get_next_token ($) { Line 1216  sub _get_next_token ($) {
1216                     });                     });
1217    
1218            redo A;            redo A;
1219          } elsif ($self->{next_char} == 0x003F) { # ?          } elsif ($self->{nc} == 0x003F) { # ?
1220            !!!cp (22);            !!!cp (22);
1221            !!!parse-error (type => 'pio',            !!!parse-error (type => 'pio',
1222                            line => $self->{line_prev},                            line => $self->{line_prev},
1223                            column => $self->{column_prev});                            column => $self->{column_prev});
1224            $self->{state} = BOGUS_COMMENT_STATE;            $self->{state} = BOGUS_COMMENT_STATE;
1225            $self->{current_token} = {type => COMMENT_TOKEN, data => '',            $self->{ct} = {type => COMMENT_TOKEN, data => '',
1226                                      line => $self->{line_prev},                                      line => $self->{line_prev},
1227                                      column => $self->{column_prev},                                      column => $self->{column_prev},
1228                                     };                                     };
1229            ## $self->{next_char} is intentionally left as is            ## $self->{nc} is intentionally left as is
1230            redo A;            redo A;
1231          } else {          } else {
1232            !!!cp (23);            !!!cp (23);
# Line 1132  sub _get_next_token ($) { Line 1248  sub _get_next_token ($) {
1248        }        }
1249      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {
1250        ## NOTE: The "close tag open state" in the spec is implemented as        ## NOTE: The "close tag open state" in the spec is implemented as
1251        ## |CLOSE_TAG_OPEN_STATE| and |CDATA_PCDATA_CLOSE_TAG_STATE|.        ## |CLOSE_TAG_OPEN_STATE| and |CDATA_RCDATA_CLOSE_TAG_STATE|.
1252    
1253        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"        my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"
1254        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
1255          if (defined $self->{last_emitted_start_tag_name}) {          if (defined $self->{last_stag_name}) {
1256            $self->{state} = CDATA_PCDATA_CLOSE_TAG_STATE;            $self->{state} = CDATA_RCDATA_CLOSE_TAG_STATE;
1257            $self->{state_keyword} = '';            $self->{s_kwd} = '';
1258            ## Reconsume.            ## Reconsume.
1259            redo A;            redo A;
1260          } else {          } else {
# Line 1154  sub _get_next_token ($) { Line 1270  sub _get_next_token ($) {
1270          }          }
1271        }        }
1272    
1273        if (0x0041 <= $self->{next_char} and        if (0x0041 <= $self->{nc} and
1274            $self->{next_char} <= 0x005A) { # A..Z            $self->{nc} <= 0x005A) { # A..Z
1275          !!!cp (29);          !!!cp (29);
1276          $self->{current_token}          $self->{ct}
1277              = {type => END_TAG_TOKEN,              = {type => END_TAG_TOKEN,
1278                 tag_name => chr ($self->{next_char} + 0x0020),                 tag_name => chr ($self->{nc} + 0x0020),
1279                 line => $l, column => $c};                 line => $l, column => $c};
1280          $self->{state} = TAG_NAME_STATE;          $self->{state} = TAG_NAME_STATE;
1281          !!!next-input-character;          !!!next-input-character;
1282          redo A;          redo A;
1283        } elsif (0x0061 <= $self->{next_char} and        } elsif (0x0061 <= $self->{nc} and
1284                 $self->{next_char} <= 0x007A) { # a..z                 $self->{nc} <= 0x007A) { # a..z
1285          !!!cp (30);          !!!cp (30);
1286          $self->{current_token} = {type => END_TAG_TOKEN,          $self->{ct} = {type => END_TAG_TOKEN,
1287                                    tag_name => chr ($self->{next_char}),                                    tag_name => chr ($self->{nc}),
1288                                    line => $l, column => $c};                                    line => $l, column => $c};
1289          $self->{state} = TAG_NAME_STATE;          $self->{state} = TAG_NAME_STATE;
1290          !!!next-input-character;          !!!next-input-character;
1291          redo A;          redo A;
1292        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1293          !!!cp (31);          !!!cp (31);
1294          !!!parse-error (type => 'empty end tag',          !!!parse-error (type => 'empty end tag',
1295                          line => $self->{line_prev}, ## "<" in "</>"                          line => $self->{line_prev}, ## "<" in "</>"
# Line 1181  sub _get_next_token ($) { Line 1297  sub _get_next_token ($) {
1297          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1298          !!!next-input-character;          !!!next-input-character;
1299          redo A;          redo A;
1300        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1301          !!!cp (32);          !!!cp (32);
1302          !!!parse-error (type => 'bare etago');          !!!parse-error (type => 'bare etago');
1303          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
# Line 1196  sub _get_next_token ($) { Line 1312  sub _get_next_token ($) {
1312          !!!cp (33);          !!!cp (33);
1313          !!!parse-error (type => 'bogus end tag');          !!!parse-error (type => 'bogus end tag');
1314          $self->{state} = BOGUS_COMMENT_STATE;          $self->{state} = BOGUS_COMMENT_STATE;
1315          $self->{current_token} = {type => COMMENT_TOKEN, data => '',          $self->{ct} = {type => COMMENT_TOKEN, data => '',
1316                                    line => $self->{line_prev}, # "<" of "</"                                    line => $self->{line_prev}, # "<" of "</"
1317                                    column => $self->{column_prev} - 1,                                    column => $self->{column_prev} - 1,
1318                                   };                                   };
1319          ## NOTE: $self->{next_char} is intentionally left as is.          ## NOTE: $self->{nc} is intentionally left as is.
1320          ## Although the "anything else" case of the spec not explicitly          ## Although the "anything else" case of the spec not explicitly
1321          ## states that the next input character is to be reconsumed,          ## states that the next input character is to be reconsumed,
1322          ## it will be included to the |data| of the comment token          ## it will be included to the |data| of the comment token
# Line 1208  sub _get_next_token ($) { Line 1324  sub _get_next_token ($) {
1324          ## "bogus comment state" entry.          ## "bogus comment state" entry.
1325          redo A;          redo A;
1326        }        }
1327      } elsif ($self->{state} == CDATA_PCDATA_CLOSE_TAG_STATE) {      } elsif ($self->{state} == CDATA_RCDATA_CLOSE_TAG_STATE) {
1328        my $ch = substr $self->{last_emitted_start_tag_name}, length $self->{state_keyword}, 1;        my $ch = substr $self->{last_stag_name}, length $self->{s_kwd}, 1;
1329        if (length $ch) {        if (length $ch) {
1330          my $CH = $ch;          my $CH = $ch;
1331          $ch =~ tr/a-z/A-Z/;          $ch =~ tr/a-z/A-Z/;
1332          my $nch = chr $self->{next_char};          my $nch = chr $self->{nc};
1333          if ($nch eq $ch or $nch eq $CH) {          if ($nch eq $ch or $nch eq $CH) {
1334            !!!cp (24);            !!!cp (24);
1335            ## Stay in the state.            ## Stay in the state.
1336            $self->{state_keyword} .= $nch;            $self->{s_kwd} .= $nch;
1337            !!!next-input-character;            !!!next-input-character;
1338            redo A;            redo A;
1339          } else {          } else {
# Line 1225  sub _get_next_token ($) { Line 1341  sub _get_next_token ($) {
1341            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1342            ## Reconsume.            ## Reconsume.
1343            !!!emit ({type => CHARACTER_TOKEN,            !!!emit ({type => CHARACTER_TOKEN,
1344                      data => '</' . $self->{state_keyword},                      data => '</' . $self->{s_kwd},
1345                      line => $self->{line_prev},                      line => $self->{line_prev},
1346                      column => $self->{column_prev} - 1 - length $self->{state_keyword},                      column => $self->{column_prev} - 1 - length $self->{s_kwd},
1347                     });                     });
1348            redo A;            redo A;
1349          }          }
1350        } else { # after "<{tag-name}"        } else { # after "<{tag-name}"
1351          unless ({          unless ($is_space->{$self->{nc}} or
1352                   0x0009 => 1, # HT                  {
                  0x000A => 1, # LF  
                  0x000B => 1, # VT  
                  0x000C => 1, # FF  
                  0x0020 => 1, # SP  
1353                   0x003E => 1, # >                   0x003E => 1, # >
1354                   0x002F => 1, # /                   0x002F => 1, # /
1355                   -1 => 1, # EOF                   -1 => 1, # EOF
1356                  }->{$self->{next_char}}) {                  }->{$self->{nc}}) {
1357            !!!cp (26);            !!!cp (26);
1358            ## Reconsume.            ## Reconsume.
1359            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1360            !!!emit ({type => CHARACTER_TOKEN,            !!!emit ({type => CHARACTER_TOKEN,
1361                      data => '</' . $self->{state_keyword},                      data => '</' . $self->{s_kwd},
1362                      line => $self->{line_prev},                      line => $self->{line_prev},
1363                      column => $self->{column_prev} - 1 - length $self->{state_keyword},                      column => $self->{column_prev} - 1 - length $self->{s_kwd},
1364                     });                     });
1365            redo A;            redo A;
1366          } else {          } else {
1367            !!!cp (27);            !!!cp (27);
1368            $self->{current_token}            $self->{ct}
1369                = {type => END_TAG_TOKEN,                = {type => END_TAG_TOKEN,
1370                   tag_name => $self->{last_emitted_start_tag_name},                   tag_name => $self->{last_stag_name},
1371                   line => $self->{line_prev},                   line => $self->{line_prev},
1372                   column => $self->{column_prev} - 1 - length $self->{state_keyword}};                   column => $self->{column_prev} - 1 - length $self->{s_kwd}};
1373            $self->{state} = TAG_NAME_STATE;            $self->{state} = TAG_NAME_STATE;
1374            ## Reconsume.            ## Reconsume.
1375            redo A;            redo A;
1376          }          }
1377        }        }
1378      } elsif ($self->{state} == TAG_NAME_STATE) {      } elsif ($self->{state} == TAG_NAME_STATE) {
1379        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # VT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP  
1380          !!!cp (34);          !!!cp (34);
1381          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1382          !!!next-input-character;          !!!next-input-character;
1383          redo A;          redo A;
1384        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1385          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1386            !!!cp (35);            !!!cp (35);
1387            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1388          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1389            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1390            #if ($self->{current_token}->{attributes}) {            #if ($self->{ct}->{attributes}) {
1391            #  ## NOTE: This should never be reached.            #  ## NOTE: This should never be reached.
1392            #  !!! cp (36);            #  !!! cp (36);
1393            #  !!! parse-error (type => 'end tag attribute');            #  !!! parse-error (type => 'end tag attribute');
# Line 1287  sub _get_next_token ($) { Line 1395  sub _get_next_token ($) {
1395              !!!cp (37);              !!!cp (37);
1396            #}            #}
1397          } else {          } else {
1398            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1399          }          }
1400          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1401          !!!next-input-character;          !!!next-input-character;
1402    
1403          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1404    
1405          redo A;          redo A;
1406        } elsif (0x0041 <= $self->{next_char} and        } elsif (0x0041 <= $self->{nc} and
1407                 $self->{next_char} <= 0x005A) { # A..Z                 $self->{nc} <= 0x005A) { # A..Z
1408          !!!cp (38);          !!!cp (38);
1409          $self->{current_token}->{tag_name} .= chr ($self->{next_char} + 0x0020);          $self->{ct}->{tag_name} .= chr ($self->{nc} + 0x0020);
1410            # start tag or end tag            # start tag or end tag
1411          ## Stay in this state          ## Stay in this state
1412          !!!next-input-character;          !!!next-input-character;
1413          redo A;          redo A;
1414        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1415          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1416          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1417            !!!cp (39);            !!!cp (39);
1418            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1419          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1420            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1421            #if ($self->{current_token}->{attributes}) {            #if ($self->{ct}->{attributes}) {
1422            #  ## NOTE: This state should never be reached.            #  ## NOTE: This state should never be reached.
1423            #  !!! cp (40);            #  !!! cp (40);
1424            #  !!! parse-error (type => 'end tag attribute');            #  !!! parse-error (type => 'end tag attribute');
# Line 1318  sub _get_next_token ($) { Line 1426  sub _get_next_token ($) {
1426              !!!cp (41);              !!!cp (41);
1427            #}            #}
1428          } else {          } else {
1429            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1430          }          }
1431          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1432          # reconsume          # reconsume
1433    
1434          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1435    
1436          redo A;          redo A;
1437        } elsif ($self->{next_char} == 0x002F) { # /        } elsif ($self->{nc} == 0x002F) { # /
1438          !!!cp (42);          !!!cp (42);
1439          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1440          !!!next-input-character;          !!!next-input-character;
1441          redo A;          redo A;
1442        } else {        } else {
1443          !!!cp (44);          !!!cp (44);
1444          $self->{current_token}->{tag_name} .= chr $self->{next_char};          $self->{ct}->{tag_name} .= chr $self->{nc};
1445            # start tag or end tag            # start tag or end tag
1446          ## Stay in the state          ## Stay in the state
1447          !!!next-input-character;          !!!next-input-character;
1448          redo A;          redo A;
1449        }        }
1450      } elsif ($self->{state} == BEFORE_ATTRIBUTE_NAME_STATE) {      } elsif ($self->{state} == BEFORE_ATTRIBUTE_NAME_STATE) {
1451        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # VT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP  
1452          !!!cp (45);          !!!cp (45);
1453          ## Stay in the state          ## Stay in the state
1454          !!!next-input-character;          !!!next-input-character;
1455          redo A;          redo A;
1456        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1457          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1458            !!!cp (46);            !!!cp (46);
1459            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1460          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1461            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1462            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1463              !!!cp (47);              !!!cp (47);
1464              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1465            } else {            } else {
1466              !!!cp (48);              !!!cp (48);
1467            }            }
1468          } else {          } else {
1469            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1470          }          }
1471          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1472          !!!next-input-character;          !!!next-input-character;
1473    
1474          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1475    
1476          redo A;          redo A;
1477        } elsif (0x0041 <= $self->{next_char} and        } elsif (0x0041 <= $self->{nc} and
1478                 $self->{next_char} <= 0x005A) { # A..Z                 $self->{nc} <= 0x005A) { # A..Z
1479          !!!cp (49);          !!!cp (49);
1480          $self->{current_attribute}          $self->{ca}
1481              = {name => chr ($self->{next_char} + 0x0020),              = {name => chr ($self->{nc} + 0x0020),
1482                 value => '',                 value => '',
1483                 line => $self->{line}, column => $self->{column}};                 line => $self->{line}, column => $self->{column}};
1484          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
1485          !!!next-input-character;          !!!next-input-character;
1486          redo A;          redo A;
1487        } elsif ($self->{next_char} == 0x002F) { # /        } elsif ($self->{nc} == 0x002F) { # /
1488          !!!cp (50);          !!!cp (50);
1489          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1490          !!!next-input-character;          !!!next-input-character;
1491          redo A;          redo A;
1492        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1493          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1494          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1495            !!!cp (52);            !!!cp (52);
1496            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1497          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1498            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1499            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1500              !!!cp (53);              !!!cp (53);
1501              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1502            } else {            } else {
1503              !!!cp (54);              !!!cp (54);
1504            }            }
1505          } else {          } else {
1506            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1507          }          }
1508          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1509          # reconsume          # reconsume
1510    
1511          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1512    
1513          redo A;          redo A;
1514        } else {        } else {
# Line 1412  sub _get_next_token ($) { Line 1516  sub _get_next_token ($) {
1516               0x0022 => 1, # "               0x0022 => 1, # "
1517               0x0027 => 1, # '               0x0027 => 1, # '
1518               0x003D => 1, # =               0x003D => 1, # =
1519              }->{$self->{next_char}}) {              }->{$self->{nc}}) {
1520            !!!cp (55);            !!!cp (55);
1521            !!!parse-error (type => 'bad attribute name');            !!!parse-error (type => 'bad attribute name');
1522          } else {          } else {
1523            !!!cp (56);            !!!cp (56);
1524          }          }
1525          $self->{current_attribute}          $self->{ca}
1526              = {name => chr ($self->{next_char}),              = {name => chr ($self->{nc}),
1527                 value => '',                 value => '',
1528                 line => $self->{line}, column => $self->{column}};                 line => $self->{line}, column => $self->{column}};
1529          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
# Line 1428  sub _get_next_token ($) { Line 1532  sub _get_next_token ($) {
1532        }        }
1533      } elsif ($self->{state} == ATTRIBUTE_NAME_STATE) {      } elsif ($self->{state} == ATTRIBUTE_NAME_STATE) {
1534        my $before_leave = sub {        my $before_leave = sub {
1535          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{ct}->{attributes} # start tag or end tag
1536              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{ca}->{name}}) { # MUST
1537            !!!cp (57);            !!!cp (57);
1538            !!!parse-error (type => 'duplicate attribute', text => $self->{current_attribute}->{name}, line => $self->{current_attribute}->{line}, column => $self->{current_attribute}->{column});            !!!parse-error (type => 'duplicate attribute', text => $self->{ca}->{name}, line => $self->{ca}->{line}, column => $self->{ca}->{column});
1539            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{ca} # MUST
1540          } else {          } else {
1541            !!!cp (58);            !!!cp (58);
1542            $self->{current_token}->{attributes}->{$self->{current_attribute}->{name}}            $self->{ct}->{attributes}->{$self->{ca}->{name}}
1543              = $self->{current_attribute};              = $self->{ca};
1544          }          }
1545        }; # $before_leave        }; # $before_leave
1546    
1547        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # VT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP  
1548          !!!cp (59);          !!!cp (59);
1549          $before_leave->();          $before_leave->();
1550          $self->{state} = AFTER_ATTRIBUTE_NAME_STATE;          $self->{state} = AFTER_ATTRIBUTE_NAME_STATE;
1551          !!!next-input-character;          !!!next-input-character;
1552          redo A;          redo A;
1553        } elsif ($self->{next_char} == 0x003D) { # =        } elsif ($self->{nc} == 0x003D) { # =
1554          !!!cp (60);          !!!cp (60);
1555          $before_leave->();          $before_leave->();
1556          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;
1557          !!!next-input-character;          !!!next-input-character;
1558          redo A;          redo A;
1559        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1560          $before_leave->();          $before_leave->();
1561          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1562            !!!cp (61);            !!!cp (61);
1563            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1564          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1565            !!!cp (62);            !!!cp (62);
1566            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1567            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1568              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1569            }            }
1570          } else {          } else {
1571            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1572          }          }
1573          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1574          !!!next-input-character;          !!!next-input-character;
1575    
1576          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1577    
1578          redo A;          redo A;
1579        } elsif (0x0041 <= $self->{next_char} and        } elsif (0x0041 <= $self->{nc} and
1580                 $self->{next_char} <= 0x005A) { # A..Z                 $self->{nc} <= 0x005A) { # A..Z
1581          !!!cp (63);          !!!cp (63);
1582          $self->{current_attribute}->{name} .= chr ($self->{next_char} + 0x0020);          $self->{ca}->{name} .= chr ($self->{nc} + 0x0020);
1583          ## Stay in the state          ## Stay in the state
1584          !!!next-input-character;          !!!next-input-character;
1585          redo A;          redo A;
1586        } elsif ($self->{next_char} == 0x002F) { # /        } elsif ($self->{nc} == 0x002F) { # /
1587          !!!cp (64);          !!!cp (64);
1588          $before_leave->();          $before_leave->();
1589          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1590          !!!next-input-character;          !!!next-input-character;
1591          redo A;          redo A;
1592        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1593          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1594          $before_leave->();          $before_leave->();
1595          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1596            !!!cp (66);            !!!cp (66);
1597            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1598          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1599            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1600            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1601              !!!cp (67);              !!!cp (67);
1602              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1603            } else {            } else {
# Line 1505  sub _get_next_token ($) { Line 1605  sub _get_next_token ($) {
1605              !!!cp (68);              !!!cp (68);
1606            }            }
1607          } else {          } else {
1608            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1609          }          }
1610          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1611          # reconsume          # reconsume
1612    
1613          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1614    
1615          redo A;          redo A;
1616        } else {        } else {
1617          if ($self->{next_char} == 0x0022 or # "          if ($self->{nc} == 0x0022 or # "
1618              $self->{next_char} == 0x0027) { # '              $self->{nc} == 0x0027) { # '
1619            !!!cp (69);            !!!cp (69);
1620            !!!parse-error (type => 'bad attribute name');            !!!parse-error (type => 'bad attribute name');
1621          } else {          } else {
1622            !!!cp (70);            !!!cp (70);
1623          }          }
1624          $self->{current_attribute}->{name} .= chr ($self->{next_char});          $self->{ca}->{name} .= chr ($self->{nc});
1625          ## Stay in the state          ## Stay in the state
1626          !!!next-input-character;          !!!next-input-character;
1627          redo A;          redo A;
1628        }        }
1629      } elsif ($self->{state} == AFTER_ATTRIBUTE_NAME_STATE) {      } elsif ($self->{state} == AFTER_ATTRIBUTE_NAME_STATE) {
1630        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # VT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP  
1631          !!!cp (71);          !!!cp (71);
1632          ## Stay in the state          ## Stay in the state
1633          !!!next-input-character;          !!!next-input-character;
1634          redo A;          redo A;
1635        } elsif ($self->{next_char} == 0x003D) { # =        } elsif ($self->{nc} == 0x003D) { # =
1636          !!!cp (72);          !!!cp (72);
1637          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;
1638          !!!next-input-character;          !!!next-input-character;
1639          redo A;          redo A;
1640        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1641          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1642            !!!cp (73);            !!!cp (73);
1643            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1644          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1645            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1646            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1647              !!!cp (74);              !!!cp (74);
1648              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1649            } else {            } else {
# Line 1555  sub _get_next_token ($) { Line 1651  sub _get_next_token ($) {
1651              !!!cp (75);              !!!cp (75);
1652            }            }
1653          } else {          } else {
1654            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1655          }          }
1656          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1657          !!!next-input-character;          !!!next-input-character;
1658    
1659          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1660    
1661          redo A;          redo A;
1662        } elsif (0x0041 <= $self->{next_char} and        } elsif (0x0041 <= $self->{nc} and
1663                 $self->{next_char} <= 0x005A) { # A..Z                 $self->{nc} <= 0x005A) { # A..Z
1664          !!!cp (76);          !!!cp (76);
1665          $self->{current_attribute}          $self->{ca}
1666              = {name => chr ($self->{next_char} + 0x0020),              = {name => chr ($self->{nc} + 0x0020),
1667                 value => '',                 value => '',
1668                 line => $self->{line}, column => $self->{column}};                 line => $self->{line}, column => $self->{column}};
1669          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
1670          !!!next-input-character;          !!!next-input-character;
1671          redo A;          redo A;
1672        } elsif ($self->{next_char} == 0x002F) { # /        } elsif ($self->{nc} == 0x002F) { # /
1673          !!!cp (77);          !!!cp (77);
1674          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1675          !!!next-input-character;          !!!next-input-character;
1676          redo A;          redo A;
1677        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1678          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1679          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1680            !!!cp (79);            !!!cp (79);
1681            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1682          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1683            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1684            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1685              !!!cp (80);              !!!cp (80);
1686              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1687            } else {            } else {
# Line 1593  sub _get_next_token ($) { Line 1689  sub _get_next_token ($) {
1689              !!!cp (81);              !!!cp (81);
1690            }            }
1691          } else {          } else {
1692            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1693          }          }
1694          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1695          # reconsume          # reconsume
1696    
1697          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1698    
1699          redo A;          redo A;
1700        } else {        } else {
1701          if ($self->{next_char} == 0x0022 or # "          if ($self->{nc} == 0x0022 or # "
1702              $self->{next_char} == 0x0027) { # '              $self->{nc} == 0x0027) { # '
1703            !!!cp (78);            !!!cp (78);
1704            !!!parse-error (type => 'bad attribute name');            !!!parse-error (type => 'bad attribute name');
1705          } else {          } else {
1706            !!!cp (82);            !!!cp (82);
1707          }          }
1708          $self->{current_attribute}          $self->{ca}
1709              = {name => chr ($self->{next_char}),              = {name => chr ($self->{nc}),
1710                 value => '',                 value => '',
1711                 line => $self->{line}, column => $self->{column}};                 line => $self->{line}, column => $self->{column}};
1712          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
# Line 1618  sub _get_next_token ($) { Line 1714  sub _get_next_token ($) {
1714          redo A;                  redo A;        
1715        }        }
1716      } elsif ($self->{state} == BEFORE_ATTRIBUTE_VALUE_STATE) {      } elsif ($self->{state} == BEFORE_ATTRIBUTE_VALUE_STATE) {
1717        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # VT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP        
1718          !!!cp (83);          !!!cp (83);
1719          ## Stay in the state          ## Stay in the state
1720          !!!next-input-character;          !!!next-input-character;
1721          redo A;          redo A;
1722        } elsif ($self->{next_char} == 0x0022) { # "        } elsif ($self->{nc} == 0x0022) { # "
1723          !!!cp (84);          !!!cp (84);
1724          $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;          $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
1725          !!!next-input-character;          !!!next-input-character;
1726          redo A;          redo A;
1727        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{nc} == 0x0026) { # &
1728          !!!cp (85);          !!!cp (85);
1729          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
1730          ## reconsume          ## reconsume
1731          redo A;          redo A;
1732        } elsif ($self->{next_char} == 0x0027) { # '        } elsif ($self->{nc} == 0x0027) { # '
1733          !!!cp (86);          !!!cp (86);
1734          $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;          $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
1735          !!!next-input-character;          !!!next-input-character;
1736          redo A;          redo A;
1737        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1738          !!!parse-error (type => 'empty unquoted attribute value');          !!!parse-error (type => 'empty unquoted attribute value');
1739          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1740            !!!cp (87);            !!!cp (87);
1741            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1742          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1743            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1744            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1745              !!!cp (88);              !!!cp (88);
1746              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1747            } else {            } else {
# Line 1657  sub _get_next_token ($) { Line 1749  sub _get_next_token ($) {
1749              !!!cp (89);              !!!cp (89);
1750            }            }
1751          } else {          } else {
1752            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1753          }          }
1754          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1755          !!!next-input-character;          !!!next-input-character;
1756    
1757          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1758    
1759          redo A;          redo A;
1760        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1761          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1762          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1763            !!!cp (90);            !!!cp (90);
1764            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1765          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1766            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1767            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1768              !!!cp (91);              !!!cp (91);
1769              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1770            } else {            } else {
# Line 1680  sub _get_next_token ($) { Line 1772  sub _get_next_token ($) {
1772              !!!cp (92);              !!!cp (92);
1773            }            }
1774          } else {          } else {
1775            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1776          }          }
1777          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1778          ## reconsume          ## reconsume
1779    
1780          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1781    
1782          redo A;          redo A;
1783        } else {        } else {
1784          if ($self->{next_char} == 0x003D) { # =          if ($self->{nc} == 0x003D) { # =
1785            !!!cp (93);            !!!cp (93);
1786            !!!parse-error (type => 'bad attribute value');            !!!parse-error (type => 'bad attribute value');
1787          } else {          } else {
1788            !!!cp (94);            !!!cp (94);
1789          }          }
1790          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{ca}->{value} .= chr ($self->{nc});
1791          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
1792          !!!next-input-character;          !!!next-input-character;
1793          redo A;          redo A;
1794        }        }
1795      } elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) {
1796        if ($self->{next_char} == 0x0022) { # "        if ($self->{nc} == 0x0022) { # "
1797          !!!cp (95);          !!!cp (95);
1798          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;
1799          !!!next-input-character;          !!!next-input-character;
1800          redo A;          redo A;
1801        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{nc} == 0x0026) { # &
1802          !!!cp (96);          !!!cp (96);
1803          ## NOTE: In the spec, the tokenizer is switched to the          ## NOTE: In the spec, the tokenizer is switched to the
1804          ## "entity in attribute value state".  In this implementation, the          ## "entity in attribute value state".  In this implementation, the
1805          ## tokenizer is switched to the |ENTITY_STATE|, which is an          ## tokenizer is switched to the |ENTITY_STATE|, which is an
1806          ## implementation of the "consume a character reference" algorithm.          ## implementation of the "consume a character reference" algorithm.
1807          $self->{prev_state} = $self->{state};          $self->{prev_state} = $self->{state};
1808          $self->{entity_additional} = 0x0022; # "          $self->{entity_add} = 0x0022; # "
1809          $self->{state} = ENTITY_STATE;          $self->{state} = ENTITY_STATE;
1810          !!!next-input-character;          !!!next-input-character;
1811          redo A;          redo A;
1812        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1813          !!!parse-error (type => 'unclosed attribute value');          !!!parse-error (type => 'unclosed attribute value');
1814          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1815            !!!cp (97);            !!!cp (97);
1816            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1817          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1818            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1819            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1820              !!!cp (98);              !!!cp (98);
1821              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1822            } else {            } else {
# Line 1732  sub _get_next_token ($) { Line 1824  sub _get_next_token ($) {
1824              !!!cp (99);              !!!cp (99);
1825            }            }
1826          } else {          } else {
1827            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1828          }          }
1829          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1830          ## reconsume          ## reconsume
1831    
1832          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1833    
1834          redo A;          redo A;
1835        } else {        } else {
1836          !!!cp (100);          !!!cp (100);
1837          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{ca}->{value} .= chr ($self->{nc});
1838            $self->{read_until}->($self->{ca}->{value},
1839                                  q["&],
1840                                  length $self->{ca}->{value});
1841    
1842          ## Stay in the state          ## Stay in the state
1843          !!!next-input-character;          !!!next-input-character;
1844          redo A;          redo A;
1845        }        }
1846      } elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) {
1847        if ($self->{next_char} == 0x0027) { # '        if ($self->{nc} == 0x0027) { # '
1848          !!!cp (101);          !!!cp (101);
1849          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;
1850          !!!next-input-character;          !!!next-input-character;
1851          redo A;          redo A;
1852        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{nc} == 0x0026) { # &
1853          !!!cp (102);          !!!cp (102);
1854          ## NOTE: In the spec, the tokenizer is switched to the          ## NOTE: In the spec, the tokenizer is switched to the
1855          ## "entity in attribute value state".  In this implementation, the          ## "entity in attribute value state".  In this implementation, the
1856          ## tokenizer is switched to the |ENTITY_STATE|, which is an          ## tokenizer is switched to the |ENTITY_STATE|, which is an
1857          ## implementation of the "consume a character reference" algorithm.          ## implementation of the "consume a character reference" algorithm.
1858          $self->{entity_additional} = 0x0027; # '          $self->{entity_add} = 0x0027; # '
1859          $self->{prev_state} = $self->{state};          $self->{prev_state} = $self->{state};
1860          $self->{state} = ENTITY_STATE;          $self->{state} = ENTITY_STATE;
1861          !!!next-input-character;          !!!next-input-character;
1862          redo A;          redo A;
1863        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1864          !!!parse-error (type => 'unclosed attribute value');          !!!parse-error (type => 'unclosed attribute value');
1865          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1866            !!!cp (103);            !!!cp (103);
1867            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1868          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1869            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1870            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1871              !!!cp (104);              !!!cp (104);
1872              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1873            } else {            } else {
# Line 1779  sub _get_next_token ($) { Line 1875  sub _get_next_token ($) {
1875              !!!cp (105);              !!!cp (105);
1876            }            }
1877          } else {          } else {
1878            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1879          }          }
1880          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1881          ## reconsume          ## reconsume
1882    
1883          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1884    
1885          redo A;          redo A;
1886        } else {        } else {
1887          !!!cp (106);          !!!cp (106);
1888          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{ca}->{value} .= chr ($self->{nc});
1889            $self->{read_until}->($self->{ca}->{value},
1890                                  q['&],
1891                                  length $self->{ca}->{value});
1892    
1893          ## Stay in the state          ## Stay in the state
1894          !!!next-input-character;          !!!next-input-character;
1895          redo A;          redo A;
1896        }        }
1897      } elsif ($self->{state} == ATTRIBUTE_VALUE_UNQUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_UNQUOTED_STATE) {
1898        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # HT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP  
1899          !!!cp (107);          !!!cp (107);
1900          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1901          !!!next-input-character;          !!!next-input-character;
1902          redo A;          redo A;
1903        } elsif ($self->{next_char} == 0x0026) { # &        } elsif ($self->{nc} == 0x0026) { # &
1904          !!!cp (108);          !!!cp (108);
1905          ## NOTE: In the spec, the tokenizer is switched to the          ## NOTE: In the spec, the tokenizer is switched to the
1906          ## "entity in attribute value state".  In this implementation, the          ## "entity in attribute value state".  In this implementation, the
1907          ## tokenizer is switched to the |ENTITY_STATE|, which is an          ## tokenizer is switched to the |ENTITY_STATE|, which is an
1908          ## implementation of the "consume a character reference" algorithm.          ## implementation of the "consume a character reference" algorithm.
1909          $self->{entity_additional} = -1;          $self->{entity_add} = -1;
1910          $self->{prev_state} = $self->{state};          $self->{prev_state} = $self->{state};
1911          $self->{state} = ENTITY_STATE;          $self->{state} = ENTITY_STATE;
1912          !!!next-input-character;          !!!next-input-character;
1913          redo A;          redo A;
1914        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1915          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1916            !!!cp (109);            !!!cp (109);
1917            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1918          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1919            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1920            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1921              !!!cp (110);              !!!cp (110);
1922              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1923            } else {            } else {
# Line 1829  sub _get_next_token ($) { Line 1925  sub _get_next_token ($) {
1925              !!!cp (111);              !!!cp (111);
1926            }            }
1927          } else {          } else {
1928            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1929          }          }
1930          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1931          !!!next-input-character;          !!!next-input-character;
1932    
1933          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1934    
1935          redo A;          redo A;
1936        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
1937          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1938          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1939            !!!cp (112);            !!!cp (112);
1940            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1941          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1942            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1943            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1944              !!!cp (113);              !!!cp (113);
1945              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1946            } else {            } else {
# Line 1852  sub _get_next_token ($) { Line 1948  sub _get_next_token ($) {
1948              !!!cp (114);              !!!cp (114);
1949            }            }
1950          } else {          } else {
1951            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1952          }          }
1953          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1954          ## reconsume          ## reconsume
1955    
1956          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
1957    
1958          redo A;          redo A;
1959        } else {        } else {
# Line 1865  sub _get_next_token ($) { Line 1961  sub _get_next_token ($) {
1961               0x0022 => 1, # "               0x0022 => 1, # "
1962               0x0027 => 1, # '               0x0027 => 1, # '
1963               0x003D => 1, # =               0x003D => 1, # =
1964              }->{$self->{next_char}}) {              }->{$self->{nc}}) {
1965            !!!cp (115);            !!!cp (115);
1966            !!!parse-error (type => 'bad attribute value');            !!!parse-error (type => 'bad attribute value');
1967          } else {          } else {
1968            !!!cp (116);            !!!cp (116);
1969          }          }
1970          $self->{current_attribute}->{value} .= chr ($self->{next_char});          $self->{ca}->{value} .= chr ($self->{nc});
1971            $self->{read_until}->($self->{ca}->{value},
1972                                  q["'=& >],
1973                                  length $self->{ca}->{value});
1974    
1975          ## Stay in the state          ## Stay in the state
1976          !!!next-input-character;          !!!next-input-character;
1977          redo A;          redo A;
1978        }        }
1979      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {      } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {
1980        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # VT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP  
1981          !!!cp (118);          !!!cp (118);
1982          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1983          !!!next-input-character;          !!!next-input-character;
1984          redo A;          redo A;
1985        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1986          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1987            !!!cp (119);            !!!cp (119);
1988            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1989          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1990            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1991            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
1992              !!!cp (120);              !!!cp (120);
1993              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1994            } else {            } else {
# Line 1900  sub _get_next_token ($) { Line 1996  sub _get_next_token ($) {
1996              !!!cp (121);              !!!cp (121);
1997            }            }
1998          } else {          } else {
1999            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
2000          }          }
2001          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2002          !!!next-input-character;          !!!next-input-character;
2003    
2004          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
2005    
2006          redo A;          redo A;
2007        } elsif ($self->{next_char} == 0x002F) { # /        } elsif ($self->{nc} == 0x002F) { # /
2008          !!!cp (122);          !!!cp (122);
2009          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
2010          !!!next-input-character;          !!!next-input-character;
2011          redo A;          redo A;
2012        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2013          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
2014          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
2015            !!!cp (122.3);            !!!cp (122.3);
2016            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
2017          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
2018            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
2019              !!!cp (122.1);              !!!cp (122.1);
2020              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
2021            } else {            } else {
# Line 1927  sub _get_next_token ($) { Line 2023  sub _get_next_token ($) {
2023              !!!cp (122.2);              !!!cp (122.2);
2024            }            }
2025          } else {          } else {
2026            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
2027          }          }
2028          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2029          ## Reconsume.          ## Reconsume.
2030          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
2031          redo A;          redo A;
2032        } else {        } else {
2033          !!!cp ('124.1');          !!!cp ('124.1');
# Line 1941  sub _get_next_token ($) { Line 2037  sub _get_next_token ($) {
2037          redo A;          redo A;
2038        }        }
2039      } elsif ($self->{state} == SELF_CLOSING_START_TAG_STATE) {      } elsif ($self->{state} == SELF_CLOSING_START_TAG_STATE) {
2040        if ($self->{next_char} == 0x003E) { # >        if ($self->{nc} == 0x003E) { # >
2041          if ($self->{current_token}->{type} == END_TAG_TOKEN) {          if ($self->{ct}->{type} == END_TAG_TOKEN) {
2042            !!!cp ('124.2');            !!!cp ('124.2');
2043            !!!parse-error (type => 'nestc', token => $self->{current_token});            !!!parse-error (type => 'nestc', token => $self->{ct});
2044            ## TODO: Different type than slash in start tag            ## TODO: Different type than slash in start tag
2045            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
2046            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
2047              !!!cp ('124.4');              !!!cp ('124.4');
2048              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
2049            } else {            } else {
# Line 1962  sub _get_next_token ($) { Line 2058  sub _get_next_token ($) {
2058          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2059          !!!next-input-character;          !!!next-input-character;
2060    
2061          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
2062    
2063          redo A;          redo A;
2064        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2065          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
2066          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
2067            !!!cp (124.7);            !!!cp (124.7);
2068            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
2069          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
2070            if ($self->{current_token}->{attributes}) {            if ($self->{ct}->{attributes}) {
2071              !!!cp (124.5);              !!!cp (124.5);
2072              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
2073            } else {            } else {
# Line 1979  sub _get_next_token ($) { Line 2075  sub _get_next_token ($) {
2075              !!!cp (124.6);              !!!cp (124.6);
2076            }            }
2077          } else {          } else {
2078            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
2079          }          }
2080          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2081          ## Reconsume.          ## Reconsume.
2082          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{ct}); # start tag or end tag
2083          redo A;          redo A;
2084        } else {        } else {
2085          !!!cp ('124.4');          !!!cp ('124.4');
# Line 1999  sub _get_next_token ($) { Line 2095  sub _get_next_token ($) {
2095        ## NOTE: Unlike spec's "bogus comment state", this implementation        ## NOTE: Unlike spec's "bogus comment state", this implementation
2096        ## consumes characters one-by-one basis.        ## consumes characters one-by-one basis.
2097                
2098        if ($self->{next_char} == 0x003E) { # >        if ($self->{nc} == 0x003E) { # >
2099          !!!cp (124);          !!!cp (124);
2100          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2101          !!!next-input-character;          !!!next-input-character;
2102    
2103          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2104          redo A;          redo A;
2105        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2106          !!!cp (125);          !!!cp (125);
2107          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2108          ## reconsume          ## reconsume
2109    
2110          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2111          redo A;          redo A;
2112        } else {        } else {
2113          !!!cp (126);          !!!cp (126);
2114          $self->{current_token}->{data} .= chr ($self->{next_char}); # comment          $self->{ct}->{data} .= chr ($self->{nc}); # comment
2115            $self->{read_until}->($self->{ct}->{data},
2116                                  q[>],
2117                                  length $self->{ct}->{data});
2118    
2119          ## Stay in the state.          ## Stay in the state.
2120          !!!next-input-character;          !!!next-input-character;
2121          redo A;          redo A;
# Line 2023  sub _get_next_token ($) { Line 2123  sub _get_next_token ($) {
2123      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {
2124        ## (only happen if PCDATA state)        ## (only happen if PCDATA state)
2125                
2126        if ($self->{next_char} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
2127          !!!cp (133);          !!!cp (133);
2128          $self->{state} = MD_HYPHEN_STATE;          $self->{state} = MD_HYPHEN_STATE;
2129          !!!next-input-character;          !!!next-input-character;
2130          redo A;          redo A;
2131        } elsif ($self->{next_char} == 0x0044 or # D        } elsif ($self->{nc} == 0x0044 or # D
2132                 $self->{next_char} == 0x0064) { # d                 $self->{nc} == 0x0064) { # d
2133          ## ASCII case-insensitive.          ## ASCII case-insensitive.
2134          !!!cp (130);          !!!cp (130);
2135          $self->{state} = MD_DOCTYPE_STATE;          $self->{state} = MD_DOCTYPE_STATE;
2136          $self->{state_keyword} = chr $self->{next_char};          $self->{s_kwd} = chr $self->{nc};
2137          !!!next-input-character;          !!!next-input-character;
2138          redo A;          redo A;
2139        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and        } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and
2140                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and                 $self->{open_elements}->[-1]->[1] & FOREIGN_EL and
2141                 $self->{next_char} == 0x005B) { # [                 $self->{nc} == 0x005B) { # [
2142          !!!cp (135.4);                          !!!cp (135.4);                
2143          $self->{state} = MD_CDATA_STATE;          $self->{state} = MD_CDATA_STATE;
2144          $self->{state_keyword} = '[';          $self->{s_kwd} = '[';
2145          !!!next-input-character;          !!!next-input-character;
2146          redo A;          redo A;
2147        } else {        } else {
# Line 2053  sub _get_next_token ($) { Line 2153  sub _get_next_token ($) {
2153                        column => $self->{column_prev} - 1);                        column => $self->{column_prev} - 1);
2154        ## Reconsume.        ## Reconsume.
2155        $self->{state} = BOGUS_COMMENT_STATE;        $self->{state} = BOGUS_COMMENT_STATE;
2156        $self->{current_token} = {type => COMMENT_TOKEN, data => '',        $self->{ct} = {type => COMMENT_TOKEN, data => '',
2157                                  line => $self->{line_prev},                                  line => $self->{line_prev},
2158                                  column => $self->{column_prev} - 1,                                  column => $self->{column_prev} - 1,
2159                                 };                                 };
2160        redo A;        redo A;
2161      } elsif ($self->{state} == MD_HYPHEN_STATE) {      } elsif ($self->{state} == MD_HYPHEN_STATE) {
2162        if ($self->{next_char} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
2163          !!!cp (127);          !!!cp (127);
2164          $self->{current_token} = {type => COMMENT_TOKEN, data => '',          $self->{ct} = {type => COMMENT_TOKEN, data => '',
2165                                    line => $self->{line_prev},                                    line => $self->{line_prev},
2166                                    column => $self->{column_prev} - 2,                                    column => $self->{column_prev} - 2,
2167                                   };                                   };
# Line 2075  sub _get_next_token ($) { Line 2175  sub _get_next_token ($) {
2175                          column => $self->{column_prev} - 2);                          column => $self->{column_prev} - 2);
2176          $self->{state} = BOGUS_COMMENT_STATE;          $self->{state} = BOGUS_COMMENT_STATE;
2177          ## Reconsume.          ## Reconsume.
2178          $self->{current_token} = {type => COMMENT_TOKEN,          $self->{ct} = {type => COMMENT_TOKEN,
2179                                    data => '-',                                    data => '-',
2180                                    line => $self->{line_prev},                                    line => $self->{line_prev},
2181                                    column => $self->{column_prev} - 2,                                    column => $self->{column_prev} - 2,
# Line 2084  sub _get_next_token ($) { Line 2184  sub _get_next_token ($) {
2184        }        }
2185      } elsif ($self->{state} == MD_DOCTYPE_STATE) {      } elsif ($self->{state} == MD_DOCTYPE_STATE) {
2186        ## ASCII case-insensitive.        ## ASCII case-insensitive.
2187        if ($self->{next_char} == [        if ($self->{nc} == [
2188              undef,              undef,
2189              0x004F, # O              0x004F, # O
2190              0x0043, # C              0x0043, # C
2191              0x0054, # T              0x0054, # T
2192              0x0059, # Y              0x0059, # Y
2193              0x0050, # P              0x0050, # P
2194            ]->[length $self->{state_keyword}] or            ]->[length $self->{s_kwd}] or
2195            $self->{next_char} == [            $self->{nc} == [
2196              undef,              undef,
2197              0x006F, # o              0x006F, # o
2198              0x0063, # c              0x0063, # c
2199              0x0074, # t              0x0074, # t
2200              0x0079, # y              0x0079, # y
2201              0x0070, # p              0x0070, # p
2202            ]->[length $self->{state_keyword}]) {            ]->[length $self->{s_kwd}]) {
2203          !!!cp (131);          !!!cp (131);
2204          ## Stay in the state.          ## Stay in the state.
2205          $self->{state_keyword} .= chr $self->{next_char};          $self->{s_kwd} .= chr $self->{nc};
2206          !!!next-input-character;          !!!next-input-character;
2207          redo A;          redo A;
2208        } elsif ((length $self->{state_keyword}) == 6 and        } elsif ((length $self->{s_kwd}) == 6 and
2209                 ($self->{next_char} == 0x0045 or # E                 ($self->{nc} == 0x0045 or # E
2210                  $self->{next_char} == 0x0065)) { # e                  $self->{nc} == 0x0065)) { # e
2211          !!!cp (129);          !!!cp (129);
2212          $self->{state} = DOCTYPE_STATE;          $self->{state} = DOCTYPE_STATE;
2213          $self->{current_token} = {type => DOCTYPE_TOKEN,          $self->{ct} = {type => DOCTYPE_TOKEN,
2214                                    quirks => 1,                                    quirks => 1,
2215                                    line => $self->{line_prev},                                    line => $self->{line_prev},
2216                                    column => $self->{column_prev} - 7,                                    column => $self->{column_prev} - 7,
# Line 2121  sub _get_next_token ($) { Line 2221  sub _get_next_token ($) {
2221          !!!cp (132);                  !!!cp (132);        
2222          !!!parse-error (type => 'bogus comment',          !!!parse-error (type => 'bogus comment',
2223                          line => $self->{line_prev},                          line => $self->{line_prev},
2224                          column => $self->{column_prev} - 1 - length $self->{state_keyword});                          column => $self->{column_prev} - 1 - length $self->{s_kwd});
2225          $self->{state} = BOGUS_COMMENT_STATE;          $self->{state} = BOGUS_COMMENT_STATE;
2226          ## Reconsume.          ## Reconsume.
2227          $self->{current_token} = {type => COMMENT_TOKEN,          $self->{ct} = {type => COMMENT_TOKEN,
2228                                    data => $self->{state_keyword},                                    data => $self->{s_kwd},
2229                                    line => $self->{line_prev},                                    line => $self->{line_prev},
2230                                    column => $self->{column_prev} - 1 - length $self->{state_keyword},                                    column => $self->{column_prev} - 1 - length $self->{s_kwd},
2231                                   };                                   };
2232          redo A;          redo A;
2233        }        }
2234      } elsif ($self->{state} == MD_CDATA_STATE) {      } elsif ($self->{state} == MD_CDATA_STATE) {
2235        if ($self->{next_char} == {        if ($self->{nc} == {
2236              '[' => 0x0043, # C              '[' => 0x0043, # C
2237              '[C' => 0x0044, # D              '[C' => 0x0044, # D
2238              '[CD' => 0x0041, # A              '[CD' => 0x0041, # A
2239              '[CDA' => 0x0054, # T              '[CDA' => 0x0054, # T
2240              '[CDAT' => 0x0041, # A              '[CDAT' => 0x0041, # A
2241            }->{$self->{state_keyword}}) {            }->{$self->{s_kwd}}) {
2242          !!!cp (135.1);          !!!cp (135.1);
2243          ## Stay in the state.          ## Stay in the state.
2244          $self->{state_keyword} .= chr $self->{next_char};          $self->{s_kwd} .= chr $self->{nc};
2245          !!!next-input-character;          !!!next-input-character;
2246          redo A;          redo A;
2247        } elsif ($self->{state_keyword} eq '[CDATA' and        } elsif ($self->{s_kwd} eq '[CDATA' and
2248                 $self->{next_char} == 0x005B) { # [                 $self->{nc} == 0x005B) { # [
2249          !!!cp (135.2);          !!!cp (135.2);
2250          $self->{current_token} = {type => CHARACTER_TOKEN,          $self->{ct} = {type => CHARACTER_TOKEN,
2251                                    data => '',                                    data => '',
2252                                    line => $self->{line_prev},                                    line => $self->{line_prev},
2253                                    column => $self->{column_prev} - 7};                                    column => $self->{column_prev} - 7};
# Line 2158  sub _get_next_token ($) { Line 2258  sub _get_next_token ($) {
2258          !!!cp (135.3);          !!!cp (135.3);
2259          !!!parse-error (type => 'bogus comment',          !!!parse-error (type => 'bogus comment',
2260                          line => $self->{line_prev},                          line => $self->{line_prev},
2261                          column => $self->{column_prev} - 1 - length $self->{state_keyword});                          column => $self->{column_prev} - 1 - length $self->{s_kwd});
2262          $self->{state} = BOGUS_COMMENT_STATE;          $self->{state} = BOGUS_COMMENT_STATE;
2263          ## Reconsume.          ## Reconsume.
2264          $self->{current_token} = {type => COMMENT_TOKEN,          $self->{ct} = {type => COMMENT_TOKEN,
2265                                    data => $self->{state_keyword},                                    data => $self->{s_kwd},
2266                                    line => $self->{line_prev},                                    line => $self->{line_prev},
2267                                    column => $self->{column_prev} - 1 - length $self->{state_keyword},                                    column => $self->{column_prev} - 1 - length $self->{s_kwd},
2268                                   };                                   };
2269          redo A;          redo A;
2270        }        }
2271      } elsif ($self->{state} == COMMENT_START_STATE) {      } elsif ($self->{state} == COMMENT_START_STATE) {
2272        if ($self->{next_char} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
2273          !!!cp (137);          !!!cp (137);
2274          $self->{state} = COMMENT_START_DASH_STATE;          $self->{state} = COMMENT_START_DASH_STATE;
2275          !!!next-input-character;          !!!next-input-character;
2276          redo A;          redo A;
2277        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2278          !!!cp (138);          !!!cp (138);
2279          !!!parse-error (type => 'bogus comment');          !!!parse-error (type => 'bogus comment');
2280          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2281          !!!next-input-character;          !!!next-input-character;
2282    
2283          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2284    
2285          redo A;          redo A;
2286        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2287          !!!cp (139);          !!!cp (139);
2288          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
2289          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2290          ## reconsume          ## reconsume
2291    
2292          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2293    
2294          redo A;          redo A;
2295        } else {        } else {
2296          !!!cp (140);          !!!cp (140);
2297          $self->{current_token}->{data} # comment          $self->{ct}->{data} # comment
2298              .= chr ($self->{next_char});              .= chr ($self->{nc});
2299          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
2300          !!!next-input-character;          !!!next-input-character;
2301          redo A;          redo A;
2302        }        }
2303      } elsif ($self->{state} == COMMENT_START_DASH_STATE) {      } elsif ($self->{state} == COMMENT_START_DASH_STATE) {
2304        if ($self->{next_char} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
2305          !!!cp (141);          !!!cp (141);
2306          $self->{state} = COMMENT_END_STATE;          $self->{state} = COMMENT_END_STATE;
2307          !!!next-input-character;          !!!next-input-character;
2308          redo A;          redo A;
2309        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2310          !!!cp (142);          !!!cp (142);
2311          !!!parse-error (type => 'bogus comment');          !!!parse-error (type => 'bogus comment');
2312          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2313          !!!next-input-character;          !!!next-input-character;
2314    
2315          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2316    
2317          redo A;          redo A;
2318        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2319          !!!cp (143);          !!!cp (143);
2320          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
2321          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2322          ## reconsume          ## reconsume
2323    
2324          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2325    
2326          redo A;          redo A;
2327        } else {        } else {
2328          !!!cp (144);          !!!cp (144);
2329          $self->{current_token}->{data} # comment          $self->{ct}->{data} # comment
2330              .= '-' . chr ($self->{next_char});              .= '-' . chr ($self->{nc});
2331          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
2332          !!!next-input-character;          !!!next-input-character;
2333          redo A;          redo A;
2334        }        }
2335      } elsif ($self->{state} == COMMENT_STATE) {      } elsif ($self->{state} == COMMENT_STATE) {
2336        if ($self->{next_char} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
2337          !!!cp (145);          !!!cp (145);
2338          $self->{state} = COMMENT_END_DASH_STATE;          $self->{state} = COMMENT_END_DASH_STATE;
2339          !!!next-input-character;          !!!next-input-character;
2340          redo A;          redo A;
2341        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2342          !!!cp (146);          !!!cp (146);
2343          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
2344          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2345          ## reconsume          ## reconsume
2346    
2347          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2348    
2349          redo A;          redo A;
2350        } else {        } else {
2351          !!!cp (147);          !!!cp (147);
2352          $self->{current_token}->{data} .= chr ($self->{next_char}); # comment          $self->{ct}->{data} .= chr ($self->{nc}); # comment
2353            $self->{read_until}->($self->{ct}->{data},
2354                                  q[-],
2355                                  length $self->{ct}->{data});
2356    
2357          ## Stay in the state          ## Stay in the state
2358          !!!next-input-character;          !!!next-input-character;
2359          redo A;          redo A;
2360        }        }
2361      } elsif ($self->{state} == COMMENT_END_DASH_STATE) {      } elsif ($self->{state} == COMMENT_END_DASH_STATE) {
2362        if ($self->{next_char} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
2363          !!!cp (148);          !!!cp (148);
2364          $self->{state} = COMMENT_END_STATE;          $self->{state} = COMMENT_END_STATE;
2365          !!!next-input-character;          !!!next-input-character;
2366          redo A;          redo A;
2367        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2368          !!!cp (149);          !!!cp (149);
2369          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
2370          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2371          ## reconsume          ## reconsume
2372    
2373          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2374    
2375          redo A;          redo A;
2376        } else {        } else {
2377          !!!cp (150);          !!!cp (150);
2378          $self->{current_token}->{data} .= '-' . chr ($self->{next_char}); # comment          $self->{ct}->{data} .= '-' . chr ($self->{nc}); # comment
2379          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
2380          !!!next-input-character;          !!!next-input-character;
2381          redo A;          redo A;
2382        }        }
2383      } elsif ($self->{state} == COMMENT_END_STATE) {      } elsif ($self->{state} == COMMENT_END_STATE) {
2384        if ($self->{next_char} == 0x003E) { # >        if ($self->{nc} == 0x003E) { # >
2385          !!!cp (151);          !!!cp (151);
2386          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2387          !!!next-input-character;          !!!next-input-character;
2388    
2389          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2390    
2391          redo A;          redo A;
2392        } elsif ($self->{next_char} == 0x002D) { # -        } elsif ($self->{nc} == 0x002D) { # -
2393          !!!cp (152);          !!!cp (152);
2394          !!!parse-error (type => 'dash in comment',          !!!parse-error (type => 'dash in comment',
2395                          line => $self->{line_prev},                          line => $self->{line_prev},
2396                          column => $self->{column_prev});                          column => $self->{column_prev});
2397          $self->{current_token}->{data} .= '-'; # comment          $self->{ct}->{data} .= '-'; # comment
2398          ## Stay in the state          ## Stay in the state
2399          !!!next-input-character;          !!!next-input-character;
2400          redo A;          redo A;
2401        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2402          !!!cp (153);          !!!cp (153);
2403          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
2404          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2405          ## reconsume          ## reconsume
2406    
2407          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{ct}); # comment
2408    
2409          redo A;          redo A;
2410        } else {        } else {
# Line 2308  sub _get_next_token ($) { Line 2412  sub _get_next_token ($) {
2412          !!!parse-error (type => 'dash in comment',          !!!parse-error (type => 'dash in comment',
2413                          line => $self->{line_prev},                          line => $self->{line_prev},
2414                          column => $self->{column_prev});                          column => $self->{column_prev});
2415          $self->{current_token}->{data} .= '--' . chr ($self->{next_char}); # comment          $self->{ct}->{data} .= '--' . chr ($self->{nc}); # comment
2416          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
2417          !!!next-input-character;          !!!next-input-character;
2418          redo A;          redo A;
2419        }        }
2420      } elsif ($self->{state} == DOCTYPE_STATE) {      } elsif ($self->{state} == DOCTYPE_STATE) {
2421        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # VT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP  
2422          !!!cp (155);          !!!cp (155);
2423          $self->{state} = BEFORE_DOCTYPE_NAME_STATE;          $self->{state} = BEFORE_DOCTYPE_NAME_STATE;
2424          !!!next-input-character;          !!!next-input-character;
# Line 2331  sub _get_next_token ($) { Line 2431  sub _get_next_token ($) {
2431          redo A;          redo A;
2432        }        }
2433      } elsif ($self->{state} == BEFORE_DOCTYPE_NAME_STATE) {      } elsif ($self->{state} == BEFORE_DOCTYPE_NAME_STATE) {
2434        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # VT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP  
2435          !!!cp (157);          !!!cp (157);
2436          ## Stay in the state          ## Stay in the state
2437          !!!next-input-character;          !!!next-input-character;
2438          redo A;          redo A;
2439        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2440          !!!cp (158);          !!!cp (158);
2441          !!!parse-error (type => 'no DOCTYPE name');          !!!parse-error (type => 'no DOCTYPE name');
2442          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2443          !!!next-input-character;          !!!next-input-character;
2444    
2445          !!!emit ($self->{current_token}); # DOCTYPE (quirks)          !!!emit ($self->{ct}); # DOCTYPE (quirks)
2446    
2447          redo A;          redo A;
2448        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2449          !!!cp (159);          !!!cp (159);
2450          !!!parse-error (type => 'no DOCTYPE name');          !!!parse-error (type => 'no DOCTYPE name');
2451          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2452          ## reconsume          ## reconsume
2453    
2454          !!!emit ($self->{current_token}); # DOCTYPE (quirks)          !!!emit ($self->{ct}); # DOCTYPE (quirks)
2455    
2456          redo A;          redo A;
2457        } else {        } else {
2458          !!!cp (160);          !!!cp (160);
2459          $self->{current_token}->{name} = chr $self->{next_char};          $self->{ct}->{name} = chr $self->{nc};
2460          delete $self->{current_token}->{quirks};          delete $self->{ct}->{quirks};
2461  ## ISSUE: "Set the token's name name to the" in the spec  ## ISSUE: "Set the token's name name to the" in the spec
2462          $self->{state} = DOCTYPE_NAME_STATE;          $self->{state} = DOCTYPE_NAME_STATE;
2463          !!!next-input-character;          !!!next-input-character;
# Line 2369  sub _get_next_token ($) { Line 2465  sub _get_next_token ($) {
2465        }        }
2466      } elsif ($self->{state} == DOCTYPE_NAME_STATE) {      } elsif ($self->{state} == DOCTYPE_NAME_STATE) {
2467  ## ISSUE: Redundant "First," in the spec.  ## ISSUE: Redundant "First," in the spec.
2468        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # VT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP  
2469          !!!cp (161);          !!!cp (161);
2470          $self->{state} = AFTER_DOCTYPE_NAME_STATE;          $self->{state} = AFTER_DOCTYPE_NAME_STATE;
2471          !!!next-input-character;          !!!next-input-character;
2472          redo A;          redo A;
2473        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2474          !!!cp (162);          !!!cp (162);
2475          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2476          !!!next-input-character;          !!!next-input-character;
2477    
2478          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2479    
2480          redo A;          redo A;
2481        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2482          !!!cp (163);          !!!cp (163);
2483          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2484          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2485          ## reconsume          ## reconsume
2486    
2487          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2488          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2489    
2490          redo A;          redo A;
2491        } else {        } else {
2492          !!!cp (164);          !!!cp (164);
2493          $self->{current_token}->{name}          $self->{ct}->{name}
2494            .= chr ($self->{next_char}); # DOCTYPE            .= chr ($self->{nc}); # DOCTYPE
2495          ## Stay in the state          ## Stay in the state
2496          !!!next-input-character;          !!!next-input-character;
2497          redo A;          redo A;
2498        }        }
2499      } elsif ($self->{state} == AFTER_DOCTYPE_NAME_STATE) {      } elsif ($self->{state} == AFTER_DOCTYPE_NAME_STATE) {
2500        if ($self->{next_char} == 0x0009 or # HT        if ($is_space->{$self->{nc}}) {
           $self->{next_char} == 0x000A or # LF  
           $self->{next_char} == 0x000B or # VT  
           $self->{next_char} == 0x000C or # FF  
           $self->{next_char} == 0x0020) { # SP  
2501          !!!cp (165);          !!!cp (165);
2502          ## Stay in the state          ## Stay in the state
2503          !!!next-input-character;          !!!next-input-character;
2504          redo A;          redo A;
2505        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2506          !!!cp (166);          !!!cp (166);
2507          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2508          !!!next-input-character;          !!!next-input-character;
2509    
2510          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2511    
2512          redo A;          redo A;
2513        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2514          !!!cp (167);          !!!cp (167);
2515          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2516          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2517          ## reconsume          ## reconsume
2518    
2519          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2520          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2521    
2522          redo A;          redo A;
2523        } elsif ($self->{next_char} == 0x0050 or # P        } elsif ($self->{nc} == 0x0050 or # P
2524                 $self->{next_char} == 0x0070) { # p                 $self->{nc} == 0x0070) { # p
2525          $self->{state} = PUBLIC_STATE;          $self->{state} = PUBLIC_STATE;
2526          $self->{state_keyword} = chr $self->{next_char};          $self->{s_kwd} = chr $self->{nc};
2527          !!!next-input-character;          !!!next-input-character;
2528          redo A;          redo A;
2529        } elsif ($self->{next_char} == 0x0053 or # S        } elsif ($self->{nc} == 0x0053 or # S
2530                 $self->{next_char} == 0x0073) { # s                 $self->{nc} == 0x0073) { # s
2531          $self->{state} = SYSTEM_STATE;          $self->{state} = SYSTEM_STATE;
2532          $self->{state_keyword} = chr $self->{next_char};          $self->{s_kwd} = chr $self->{nc};
2533          !!!next-input-character;          !!!next-input-character;
2534          redo A;          redo A;
2535        } else {        } else {
2536          !!!cp (180);          !!!cp (180);
2537          !!!parse-error (type => 'string after DOCTYPE name');          !!!parse-error (type => 'string after DOCTYPE name');
2538          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2539    
2540          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2541          !!!next-input-character;          !!!next-input-character;
# Line 2455  sub _get_next_token ($) { Line 2543  sub _get_next_token ($) {
2543        }        }
2544      } elsif ($self->{state} == PUBLIC_STATE) {      } elsif ($self->{state} == PUBLIC_STATE) {
2545        ## ASCII case-insensitive        ## ASCII case-insensitive
2546        if ($self->{next_char} == [        if ($self->{nc} == [
2547              undef,              undef,
2548              0x0055, # U              0x0055, # U
2549              0x0042, # B              0x0042, # B
2550              0x004C, # L              0x004C, # L
2551              0x0049, # I              0x0049, # I
2552            ]->[length $self->{state_keyword}] or            ]->[length $self->{s_kwd}] or
2553            $self->{next_char} == [            $self->{nc} == [
2554              undef,              undef,
2555              0x0075, # u              0x0075, # u
2556              0x0062, # b              0x0062, # b
2557              0x006C, # l              0x006C, # l
2558              0x0069, # i              0x0069, # i
2559            ]->[length $self->{state_keyword}]) {            ]->[length $self->{s_kwd}]) {
2560          !!!cp (175);          !!!cp (175);
2561          ## Stay in the state.          ## Stay in the state.
2562          $self->{state_keyword} .= chr $self->{next_char};          $self->{s_kwd} .= chr $self->{nc};
2563          !!!next-input-character;          !!!next-input-character;
2564          redo A;          redo A;
2565        } elsif ((length $self->{state_keyword}) == 5 and        } elsif ((length $self->{s_kwd}) == 5 and
2566                 ($self->{next_char} == 0x0043 or # C                 ($self->{nc} == 0x0043 or # C
2567                  $self->{next_char} == 0x0063)) { # c                  $self->{nc} == 0x0063)) { # c
2568          !!!cp (168);          !!!cp (168);
2569          $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;          $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
2570          !!!next-input-character;          !!!next-input-character;
# Line 2485  sub _get_next_token ($) { Line 2573  sub _get_next_token ($) {
2573          !!!cp (169);          !!!cp (169);
2574          !!!parse-error (type => 'string after DOCTYPE name',          !!!parse-error (type => 'string after DOCTYPE name',
2575                          line => $self->{line_prev},                          line => $self->{line_prev},
2576                          column => $self->{column_prev} + 1 - length $self->{state_keyword});                          column => $self->{column_prev} + 1 - length $self->{s_kwd});
2577          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2578    
2579          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2580          ## Reconsume.          ## Reconsume.
# Line 2494  sub _get_next_token ($) { Line 2582  sub _get_next_token ($) {
2582        }        }
2583      } elsif ($self->{state} == SYSTEM_STATE) {      } elsif ($self->{state} == SYSTEM_STATE) {
2584        ## ASCII case-insensitive        ## ASCII case-insensitive
2585        if ($self->{next_char} == [        if ($self->{nc} == [
2586              undef,              undef,
2587              0x0059, # Y              0x0059, # Y
2588              0x0053, # S              0x0053, # S
2589              0x0054, # T              0x0054, # T
2590              0x0045, # E              0x0045, # E
2591            ]->[length $self->{state_keyword}] or            ]->[length $self->{s_kwd}] or
2592            $self->{next_char} == [            $self->{nc} == [
2593              undef,              undef,
2594              0x0079, # y              0x0079, # y
2595              0x0073, # s              0x0073, # s
2596              0x0074, # t              0x0074, # t
2597              0x0065, # e              0x0065, # e
2598            ]->[length $self->{state_keyword}]) {            ]->[length $self->{s_kwd}]) {
2599          !!!cp (170);          !!!cp (170);
2600          ## Stay in the state.          ## Stay in the state.
2601          $self->{state_keyword} .= chr $self->{next_char};          $self->{s_kwd} .= chr $self->{nc};
2602          !!!next-input-character;          !!!next-input-character;
2603          redo A;          redo A;
2604        } elsif ((length $self->{state_keyword}) == 5 and        } elsif ((length $self->{s_kwd}) == 5 and
2605                 ($self->{next_char} == 0x004D or # M                 ($self->{nc} == 0x004D or # M
2606                  $self->{next_char} == 0x006D)) { # m                  $self->{nc} == 0x006D)) { # m
2607          !!!cp (171);          !!!cp (171);
2608          $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;          $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2609          !!!next-input-character;          !!!next-input-character;
# Line 2524  sub _get_next_token ($) { Line 2612  sub _get_next_token ($) {
2612          !!!cp (172);          !!!cp (172);
2613          !!!parse-error (type => 'string after DOCTYPE name',          !!!parse-error (type => 'string after DOCTYPE name',
2614                          line => $self->{line_prev},                          line => $self->{line_prev},
2615                          column => $self->{column_prev} + 1 - length $self->{state_keyword});                          column => $self->{column_prev} + 1 - length $self->{s_kwd});
2616          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2617    
2618          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2619          ## Reconsume.          ## Reconsume.
2620          redo A;          redo A;
2621        }        }
2622      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {
2623        if ({        if ($is_space->{$self->{nc}}) {
             0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,  
             #0x000D => 1, # HT, LF, VT, FF, SP, CR  
           }->{$self->{next_char}}) {  
2624          !!!cp (181);          !!!cp (181);
2625          ## Stay in the state          ## Stay in the state
2626          !!!next-input-character;          !!!next-input-character;
2627          redo A;          redo A;
2628        } elsif ($self->{next_char} eq 0x0022) { # "        } elsif ($self->{nc} eq 0x0022) { # "
2629          !!!cp (182);          !!!cp (182);
2630          $self->{current_token}->{public_identifier} = ''; # DOCTYPE          $self->{ct}->{pubid} = ''; # DOCTYPE
2631          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE;          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE;
2632          !!!next-input-character;          !!!next-input-character;
2633          redo A;          redo A;
2634        } elsif ($self->{next_char} eq 0x0027) { # '        } elsif ($self->{nc} eq 0x0027) { # '
2635          !!!cp (183);          !!!cp (183);
2636          $self->{current_token}->{public_identifier} = ''; # DOCTYPE          $self->{ct}->{pubid} = ''; # DOCTYPE
2637          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE;          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE;
2638          !!!next-input-character;          !!!next-input-character;
2639          redo A;          redo A;
2640        } elsif ($self->{next_char} eq 0x003E) { # >        } elsif ($self->{nc} eq 0x003E) { # >
2641          !!!cp (184);          !!!cp (184);
2642          !!!parse-error (type => 'no PUBLIC literal');          !!!parse-error (type => 'no PUBLIC literal');
2643    
2644          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2645          !!!next-input-character;          !!!next-input-character;
2646    
2647          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2648          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2649    
2650          redo A;          redo A;
2651        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2652          !!!cp (185);          !!!cp (185);
2653          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2654    
2655          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2656          ## reconsume          ## reconsume
2657    
2658          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2659          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2660    
2661          redo A;          redo A;
2662        } else {        } else {
2663          !!!cp (186);          !!!cp (186);
2664          !!!parse-error (type => 'string after PUBLIC');          !!!parse-error (type => 'string after PUBLIC');
2665          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2666    
2667          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2668          !!!next-input-character;          !!!next-input-character;
2669          redo A;          redo A;
2670        }        }
2671      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE) {
2672        if ($self->{next_char} == 0x0022) { # "        if ($self->{nc} == 0x0022) { # "
2673          !!!cp (187);          !!!cp (187);
2674          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
2675          !!!next-input-character;          !!!next-input-character;
2676          redo A;          redo A;
2677        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2678          !!!cp (188);          !!!cp (188);
2679          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2680    
2681          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2682          !!!next-input-character;          !!!next-input-character;
2683    
2684          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2685          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2686    
2687          redo A;          redo A;
2688        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2689          !!!cp (189);          !!!cp (189);
2690          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2691    
2692          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2693          ## reconsume          ## reconsume
2694    
2695          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2696          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2697    
2698          redo A;          redo A;
2699        } else {        } else {
2700          !!!cp (190);          !!!cp (190);
2701          $self->{current_token}->{public_identifier} # DOCTYPE          $self->{ct}->{pubid} # DOCTYPE
2702              .= chr $self->{next_char};              .= chr $self->{nc};
2703            $self->{read_until}->($self->{ct}->{pubid}, q[">],
2704                                  length $self->{ct}->{pubid});
2705    
2706          ## Stay in the state          ## Stay in the state
2707          !!!next-input-character;          !!!next-input-character;
2708          redo A;          redo A;
2709        }        }
2710      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE) {
2711        if ($self->{next_char} == 0x0027) { # '        if ($self->{nc} == 0x0027) { # '
2712          !!!cp (191);          !!!cp (191);
2713          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
2714          !!!next-input-character;          !!!next-input-character;
2715          redo A;          redo A;
2716        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2717          !!!cp (192);          !!!cp (192);
2718          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2719    
2720          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2721          !!!next-input-character;          !!!next-input-character;
2722    
2723          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2724          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2725    
2726          redo A;          redo A;
2727        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2728          !!!cp (193);          !!!cp (193);
2729          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2730    
2731          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2732          ## reconsume          ## reconsume
2733    
2734          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2735          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2736    
2737          redo A;          redo A;
2738        } else {        } else {
2739          !!!cp (194);          !!!cp (194);
2740          $self->{current_token}->{public_identifier} # DOCTYPE          $self->{ct}->{pubid} # DOCTYPE
2741              .= chr $self->{next_char};              .= chr $self->{nc};
2742            $self->{read_until}->($self->{ct}->{pubid}, q['>],
2743                                  length $self->{ct}->{pubid});
2744    
2745          ## Stay in the state          ## Stay in the state
2746          !!!next-input-character;          !!!next-input-character;
2747          redo A;          redo A;
2748        }        }
2749      } elsif ($self->{state} == AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {      } elsif ($self->{state} == AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {
2750        if ({        if ($is_space->{$self->{nc}}) {
             0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,  
             #0x000D => 1, # HT, LF, VT, FF, SP, CR  
           }->{$self->{next_char}}) {  
2751          !!!cp (195);          !!!cp (195);
2752          ## Stay in the state          ## Stay in the state
2753          !!!next-input-character;          !!!next-input-character;
2754          redo A;          redo A;
2755        } elsif ($self->{next_char} == 0x0022) { # "        } elsif ($self->{nc} == 0x0022) { # "
2756          !!!cp (196);          !!!cp (196);
2757          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{ct}->{sysid} = ''; # DOCTYPE
2758          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;
2759          !!!next-input-character;          !!!next-input-character;
2760          redo A;          redo A;
2761        } elsif ($self->{next_char} == 0x0027) { # '        } elsif ($self->{nc} == 0x0027) { # '
2762          !!!cp (197);          !!!cp (197);
2763          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{ct}->{sysid} = ''; # DOCTYPE
2764          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;
2765          !!!next-input-character;          !!!next-input-character;
2766          redo A;          redo A;
2767        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2768          !!!cp (198);          !!!cp (198);
2769          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2770          !!!next-input-character;          !!!next-input-character;
2771    
2772          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2773    
2774          redo A;          redo A;
2775        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2776          !!!cp (199);          !!!cp (199);
2777          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2778    
2779          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2780          ## reconsume          ## reconsume
2781    
2782          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2783          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2784    
2785          redo A;          redo A;
2786        } else {        } else {
2787          !!!cp (200);          !!!cp (200);
2788          !!!parse-error (type => 'string after PUBLIC literal');          !!!parse-error (type => 'string after PUBLIC literal');
2789          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2790    
2791          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2792          !!!next-input-character;          !!!next-input-character;
2793          redo A;          redo A;
2794        }        }
2795      } elsif ($self->{state} == BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE) {      } elsif ($self->{state} == BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE) {
2796        if ({        if ($is_space->{$self->{nc}}) {
             0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,  
             #0x000D => 1, # HT, LF, VT, FF, SP, CR  
           }->{$self->{next_char}}) {  
2797          !!!cp (201);          !!!cp (201);
2798          ## Stay in the state          ## Stay in the state
2799          !!!next-input-character;          !!!next-input-character;
2800          redo A;          redo A;
2801        } elsif ($self->{next_char} == 0x0022) { # "        } elsif ($self->{nc} == 0x0022) { # "
2802          !!!cp (202);          !!!cp (202);
2803          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{ct}->{sysid} = ''; # DOCTYPE
2804          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;
2805          !!!next-input-character;          !!!next-input-character;
2806          redo A;          redo A;
2807        } elsif ($self->{next_char} == 0x0027) { # '        } elsif ($self->{nc} == 0x0027) { # '
2808          !!!cp (203);          !!!cp (203);
2809          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{ct}->{sysid} = ''; # DOCTYPE
2810          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;
2811          !!!next-input-character;          !!!next-input-character;
2812          redo A;          redo A;
2813        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2814          !!!cp (204);          !!!cp (204);
2815          !!!parse-error (type => 'no SYSTEM literal');          !!!parse-error (type => 'no SYSTEM literal');
2816          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2817          !!!next-input-character;          !!!next-input-character;
2818    
2819          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2820          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2821    
2822          redo A;          redo A;
2823        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2824          !!!cp (205);          !!!cp (205);
2825          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2826    
2827          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2828          ## reconsume          ## reconsume
2829    
2830          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2831          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2832    
2833          redo A;          redo A;
2834        } else {        } else {
2835          !!!cp (206);          !!!cp (206);
2836          !!!parse-error (type => 'string after SYSTEM');          !!!parse-error (type => 'string after SYSTEM');
2837          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2838    
2839          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2840          !!!next-input-character;          !!!next-input-character;
2841          redo A;          redo A;
2842        }        }
2843      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE) {
2844        if ($self->{next_char} == 0x0022) { # "        if ($self->{nc} == 0x0022) { # "
2845          !!!cp (207);          !!!cp (207);
2846          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2847          !!!next-input-character;          !!!next-input-character;
2848          redo A;          redo A;
2849        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2850          !!!cp (208);          !!!cp (208);
2851          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2852    
2853          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2854          !!!next-input-character;          !!!next-input-character;
2855    
2856          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2857          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2858    
2859          redo A;          redo A;
2860        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2861          !!!cp (209);          !!!cp (209);
2862          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2863    
2864          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2865          ## reconsume          ## reconsume
2866    
2867          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2868          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2869    
2870          redo A;          redo A;
2871        } else {        } else {
2872          !!!cp (210);          !!!cp (210);
2873          $self->{current_token}->{system_identifier} # DOCTYPE          $self->{ct}->{sysid} # DOCTYPE
2874              .= chr $self->{next_char};              .= chr $self->{nc};
2875            $self->{read_until}->($self->{ct}->{sysid}, q[">],
2876                                  length $self->{ct}->{sysid});
2877    
2878          ## Stay in the state          ## Stay in the state
2879          !!!next-input-character;          !!!next-input-character;
2880          redo A;          redo A;
2881        }        }
2882      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE) {      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE) {
2883        if ($self->{next_char} == 0x0027) { # '        if ($self->{nc} == 0x0027) { # '
2884          !!!cp (211);          !!!cp (211);
2885          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2886          !!!next-input-character;          !!!next-input-character;
2887          redo A;          redo A;
2888        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2889          !!!cp (212);          !!!cp (212);
2890          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2891    
2892          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2893          !!!next-input-character;          !!!next-input-character;
2894    
2895          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2896          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2897    
2898          redo A;          redo A;
2899        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2900          !!!cp (213);          !!!cp (213);
2901          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2902    
2903          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2904          ## reconsume          ## reconsume
2905    
2906          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2907          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2908    
2909          redo A;          redo A;
2910        } else {        } else {
2911          !!!cp (214);          !!!cp (214);
2912          $self->{current_token}->{system_identifier} # DOCTYPE          $self->{ct}->{sysid} # DOCTYPE
2913              .= chr $self->{next_char};              .= chr $self->{nc};
2914            $self->{read_until}->($self->{ct}->{sysid}, q['>],
2915                                  length $self->{ct}->{sysid});
2916    
2917          ## Stay in the state          ## Stay in the state
2918          !!!next-input-character;          !!!next-input-character;
2919          redo A;          redo A;
2920        }        }
2921      } elsif ($self->{state} == AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE) {      } elsif ($self->{state} == AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE) {
2922        if ({        if ($is_space->{$self->{nc}}) {
             0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,  
             #0x000D => 1, # HT, LF, VT, FF, SP, CR  
           }->{$self->{next_char}}) {  
2923          !!!cp (215);          !!!cp (215);
2924          ## Stay in the state          ## Stay in the state
2925          !!!next-input-character;          !!!next-input-character;
2926          redo A;          redo A;
2927        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2928          !!!cp (216);          !!!cp (216);
2929          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2930          !!!next-input-character;          !!!next-input-character;
2931    
2932          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2933    
2934          redo A;          redo A;
2935        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2936          !!!cp (217);          !!!cp (217);
2937          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2938          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2939          ## reconsume          ## reconsume
2940    
2941          $self->{current_token}->{quirks} = 1;          $self->{ct}->{quirks} = 1;
2942          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2943    
2944          redo A;          redo A;
2945        } else {        } else {
2946          !!!cp (218);          !!!cp (218);
2947          !!!parse-error (type => 'string after SYSTEM literal');          !!!parse-error (type => 'string after SYSTEM literal');
2948          #$self->{current_token}->{quirks} = 1;          #$self->{ct}->{quirks} = 1;
2949    
2950          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_STATE;
2951          !!!next-input-character;          !!!next-input-character;
2952          redo A;          redo A;
2953        }        }
2954      } elsif ($self->{state} == BOGUS_DOCTYPE_STATE) {      } elsif ($self->{state} == BOGUS_DOCTYPE_STATE) {
2955        if ($self->{next_char} == 0x003E) { # >        if ($self->{nc} == 0x003E) { # >
2956          !!!cp (219);          !!!cp (219);
2957          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2958          !!!next-input-character;          !!!next-input-character;
2959    
2960          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2961    
2962          redo A;          redo A;
2963        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2964          !!!cp (220);          !!!cp (220);
2965          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
2966          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2967          ## reconsume          ## reconsume
2968    
2969          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2970    
2971          redo A;          redo A;
2972        } else {        } else {
2973          !!!cp (221);          !!!cp (221);
2974            my $s = '';
2975            $self->{read_until}->($s, q[>], 0);
2976    
2977          ## Stay in the state          ## Stay in the state
2978          !!!next-input-character;          !!!next-input-character;
2979          redo A;          redo A;
# Line 2892  sub _get_next_token ($) { Line 2983  sub _get_next_token ($) {
2983        ## by three states, |CDATA_SECTION_STATE|, |CDATA_SECTION_MSE1_STATE|,        ## by three states, |CDATA_SECTION_STATE|, |CDATA_SECTION_MSE1_STATE|,
2984        ## and |CDATA_SECTION_MSE2_STATE|.        ## and |CDATA_SECTION_MSE2_STATE|.
2985                
2986        if ($self->{next_char} == 0x005D) { # ]        if ($self->{nc} == 0x005D) { # ]
2987          !!!cp (221.1);          !!!cp (221.1);
2988          $self->{state} = CDATA_SECTION_MSE1_STATE;          $self->{state} = CDATA_SECTION_MSE1_STATE;
2989          !!!next-input-character;          !!!next-input-character;
2990          redo A;          redo A;
2991        } elsif ($self->{next_char} == -1) {        } elsif ($self->{nc} == -1) {
2992          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2993          !!!next-input-character;          !!!next-input-character;
2994          if (length $self->{current_token}->{data}) { # character          if (length $self->{ct}->{data}) { # character
2995            !!!cp (221.2);            !!!cp (221.2);
2996            !!!emit ($self->{current_token}); # character            !!!emit ($self->{ct}); # character
2997          } else {          } else {
2998            !!!cp (221.3);            !!!cp (221.3);
2999            ## No token to emit. $self->{current_token} is discarded.            ## No token to emit. $self->{ct} is discarded.
3000          }                  }        
3001          redo A;          redo A;
3002        } else {        } else {
3003          !!!cp (221.4);          !!!cp (221.4);
3004          $self->{current_token}->{data} .= chr $self->{next_char};          $self->{ct}->{data} .= chr $self->{nc};
3005            $self->{read_until}->($self->{ct}->{data},
3006                                  q<]>,
3007                                  length $self->{ct}->{data});
3008    
3009          ## Stay in the state.          ## Stay in the state.
3010          !!!next-input-character;          !!!next-input-character;
3011          redo A;          redo A;
# Line 2918  sub _get_next_token ($) { Line 3013  sub _get_next_token ($) {
3013    
3014        ## ISSUE: "text tokens" in spec.        ## ISSUE: "text tokens" in spec.
3015      } elsif ($self->{state} == CDATA_SECTION_MSE1_STATE) {      } elsif ($self->{state} == CDATA_SECTION_MSE1_STATE) {
3016        if ($self->{next_char} == 0x005D) { # ]        if ($self->{nc} == 0x005D) { # ]
3017          !!!cp (221.5);          !!!cp (221.5);
3018          $self->{state} = CDATA_SECTION_MSE2_STATE;          $self->{state} = CDATA_SECTION_MSE2_STATE;
3019          !!!next-input-character;          !!!next-input-character;
3020          redo A;          redo A;
3021        } else {        } else {
3022          !!!cp (221.6);          !!!cp (221.6);
3023          $self->{current_token}->{data} .= ']';          $self->{ct}->{data} .= ']';
3024          $self->{state} = CDATA_SECTION_STATE;          $self->{state} = CDATA_SECTION_STATE;
3025          ## Reconsume.          ## Reconsume.
3026          redo A;          redo A;
3027        }        }
3028      } elsif ($self->{state} == CDATA_SECTION_MSE2_STATE) {      } elsif ($self->{state} == CDATA_SECTION_MSE2_STATE) {
3029        if ($self->{next_char} == 0x003E) { # >        if ($self->{nc} == 0x003E) { # >
3030          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
3031          !!!next-input-character;          !!!next-input-character;
3032          if (length $self->{current_token}->{data}) { # character          if (length $self->{ct}->{data}) { # character
3033            !!!cp (221.7);            !!!cp (221.7);
3034            !!!emit ($self->{current_token}); # character            !!!emit ($self->{ct}); # character
3035          } else {          } else {
3036            !!!cp (221.8);            !!!cp (221.8);
3037            ## No token to emit. $self->{current_token} is discarded.            ## No token to emit. $self->{ct} is discarded.
3038          }          }
3039          redo A;          redo A;
3040        } elsif ($self->{next_char} == 0x005D) { # ]        } elsif ($self->{nc} == 0x005D) { # ]
3041          !!!cp (221.9); # character          !!!cp (221.9); # character
3042          $self->{current_token}->{data} .= ']'; ## Add first "]" of "]]]".          $self->{ct}->{data} .= ']'; ## Add first "]" of "]]]".
3043          ## Stay in the state.          ## Stay in the state.
3044          !!!next-input-character;          !!!next-input-character;
3045          redo A;          redo A;
3046        } else {        } else {
3047          !!!cp (221.11);          !!!cp (221.11);
3048          $self->{current_token}->{data} .= ']]'; # character          $self->{ct}->{data} .= ']]'; # character
3049          $self->{state} = CDATA_SECTION_STATE;          $self->{state} = CDATA_SECTION_STATE;
3050          ## Reconsume.          ## Reconsume.
3051          redo A;          redo A;
3052        }        }
3053      } elsif ($self->{state} == ENTITY_STATE) {      } elsif ($self->{state} == ENTITY_STATE) {
3054        if ({        if ($is_space->{$self->{nc}} or
3055          0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,            {
3056          0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, &              0x003C => 1, 0x0026 => 1, -1 => 1, # <, &
3057          $self->{entity_additional} => 1,              $self->{entity_add} => 1,
3058        }->{$self->{next_char}}) {            }->{$self->{nc}}) {
3059          !!!cp (1001);          !!!cp (1001);
3060          ## Don't consume          ## Don't consume
3061          ## No error          ## No error
3062          ## Return nothing.          ## Return nothing.
3063          #          #
3064        } elsif ($self->{next_char} == 0x0023) { # #        } elsif ($self->{nc} == 0x0023) { # #
3065          !!!cp (999);          !!!cp (999);
3066          $self->{state} = ENTITY_HASH_STATE;          $self->{state} = ENTITY_HASH_STATE;
3067          $self->{state_keyword} = '#';          $self->{s_kwd} = '#';
3068          !!!next-input-character;          !!!next-input-character;
3069          redo A;          redo A;
3070        } elsif ((0x0041 <= $self->{next_char} and        } elsif ((0x0041 <= $self->{nc} and
3071                  $self->{next_char} <= 0x005A) or # A..Z                  $self->{nc} <= 0x005A) or # A..Z
3072                 (0x0061 <= $self->{next_char} and                 (0x0061 <= $self->{nc} and
3073                  $self->{next_char} <= 0x007A)) { # a..z                  $self->{nc} <= 0x007A)) { # a..z
3074          !!!cp (998);          !!!cp (998);
3075          require Whatpm::_NamedEntityList;          require Whatpm::_NamedEntityList;
3076          $self->{state} = ENTITY_NAME_STATE;          $self->{state} = ENTITY_NAME_STATE;
3077          $self->{state_keyword} = chr $self->{next_char};          $self->{s_kwd} = chr $self->{nc};
3078          $self->{entity__value} = $self->{state_keyword};          $self->{entity__value} = $self->{s_kwd};
3079          $self->{entity__match} = 0;          $self->{entity__match} = 0;
3080          !!!next-input-character;          !!!next-input-character;
3081          redo A;          redo A;
# Line 3008  sub _get_next_token ($) { Line 3103  sub _get_next_token ($) {
3103          redo A;          redo A;
3104        } else {        } else {
3105          !!!cp (996);          !!!cp (996);
3106          $self->{current_attribute}->{value} .= '&';          $self->{ca}->{value} .= '&';
3107          $self->{state} = $self->{prev_state};          $self->{state} = $self->{prev_state};
3108          ## Reconsume.          ## Reconsume.
3109          redo A;          redo A;
3110        }        }
3111      } elsif ($self->{state} == ENTITY_HASH_STATE) {      } elsif ($self->{state} == ENTITY_HASH_STATE) {
3112        if ($self->{next_char} == 0x0078 or # x        if ($self->{nc} == 0x0078 or # x
3113            $self->{next_char} == 0x0058) { # X            $self->{nc} == 0x0058) { # X
3114          !!!cp (995);          !!!cp (995);
3115          $self->{state} = HEXREF_X_STATE;          $self->{state} = HEXREF_X_STATE;
3116          $self->{state_keyword} .= chr $self->{next_char};          $self->{s_kwd} .= chr $self->{nc};
3117          !!!next-input-character;          !!!next-input-character;
3118          redo A;          redo A;
3119        } elsif (0x0030 <= $self->{next_char} and        } elsif (0x0030 <= $self->{nc} and
3120                 $self->{next_char} <= 0x0039) { # 0..9                 $self->{nc} <= 0x0039) { # 0..9
3121          !!!cp (994);          !!!cp (994);
3122          $self->{state} = NCR_NUM_STATE;          $self->{state} = NCR_NUM_STATE;
3123          $self->{state_keyword} = $self->{next_char} - 0x0030;          $self->{s_kwd} = $self->{nc} - 0x0030;
3124          !!!next-input-character;          !!!next-input-character;
3125          redo A;          redo A;
3126        } else {        } else {
# Line 3049  sub _get_next_token ($) { Line 3144  sub _get_next_token ($) {
3144            redo A;            redo A;
3145          } else {          } else {
3146            !!!cp (993);            !!!cp (993);
3147            $self->{current_attribute}->{value} .= '&#';            $self->{ca}->{value} .= '&#';
3148            $self->{state} = $self->{prev_state};            $self->{state} = $self->{prev_state};
3149            ## Reconsume.            ## Reconsume.
3150            redo A;            redo A;
3151          }          }
3152        }        }
3153      } elsif ($self->{state} == NCR_NUM_STATE) {      } elsif ($self->{state} == NCR_NUM_STATE) {
3154        if (0x0030 <= $self->{next_char} and        if (0x0030 <= $self->{nc} and
3155            $self->{next_char} <= 0x0039) { # 0..9            $self->{nc} <= 0x0039) { # 0..9
3156          !!!cp (1012);          !!!cp (1012);
3157          $self->{state_keyword} *= 10;          $self->{s_kwd} *= 10;
3158          $self->{state_keyword} += $self->{next_char} - 0x0030;          $self->{s_kwd} += $self->{nc} - 0x0030;
3159                    
3160          ## Stay in the state.          ## Stay in the state.
3161          !!!next-input-character;          !!!next-input-character;
3162          redo A;          redo A;
3163        } elsif ($self->{next_char} == 0x003B) { # ;        } elsif ($self->{nc} == 0x003B) { # ;
3164          !!!cp (1013);          !!!cp (1013);
3165          !!!next-input-character;          !!!next-input-character;
3166          #          #
# Line 3076  sub _get_next_token ($) { Line 3171  sub _get_next_token ($) {
3171          #          #
3172        }        }
3173    
3174        my $code = $self->{state_keyword};        my $code = $self->{s_kwd};
3175        my $l = $self->{line_prev};        my $l = $self->{line_prev};
3176        my $c = $self->{column_prev};        my $c = $self->{column_prev};
3177        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
# Line 3114  sub _get_next_token ($) { Line 3209  sub _get_next_token ($) {
3209          redo A;          redo A;
3210        } else {        } else {
3211          !!!cp (991);          !!!cp (991);
3212          $self->{current_attribute}->{value} .= chr $code;          $self->{ca}->{value} .= chr $code;
3213          $self->{current_attribute}->{has_reference} = 1;          $self->{ca}->{has_reference} = 1;
3214          $self->{state} = $self->{prev_state};          $self->{state} = $self->{prev_state};
3215          ## Reconsume.          ## Reconsume.
3216          redo A;          redo A;
3217        }        }
3218      } elsif ($self->{state} == HEXREF_X_STATE) {      } elsif ($self->{state} == HEXREF_X_STATE) {
3219        if ((0x0030 <= $self->{next_char} and $self->{next_char} <= 0x0039) or        if ((0x0030 <= $self->{nc} and $self->{nc} <= 0x0039) or
3220            (0x0041 <= $self->{next_char} and $self->{next_char} <= 0x0046) or            (0x0041 <= $self->{nc} and $self->{nc} <= 0x0046) or
3221            (0x0061 <= $self->{next_char} and $self->{next_char} <= 0x0066)) {            (0x0061 <= $self->{nc} and $self->{nc} <= 0x0066)) {
3222          # 0..9, A..F, a..f          # 0..9, A..F, a..f
3223          !!!cp (990);          !!!cp (990);
3224          $self->{state} = HEXREF_HEX_STATE;          $self->{state} = HEXREF_HEX_STATE;
3225          $self->{state_keyword} = 0;          $self->{s_kwd} = 0;
3226          ## Reconsume.          ## Reconsume.
3227          redo A;          redo A;
3228        } else {        } else {
# Line 3144  sub _get_next_token ($) { Line 3239  sub _get_next_token ($) {
3239            $self->{state} = $self->{prev_state};            $self->{state} = $self->{prev_state};
3240            ## Reconsume.            ## Reconsume.
3241            !!!emit ({type => CHARACTER_TOKEN,            !!!emit ({type => CHARACTER_TOKEN,
3242                      data => '&' . $self->{state_keyword},                      data => '&' . $self->{s_kwd},
3243                      line => $self->{line_prev},                      line => $self->{line_prev},
3244                      column => $self->{column_prev} - length $self->{state_keyword},                      column => $self->{column_prev} - length $self->{s_kwd},
3245                     });                     });
3246            redo A;            redo A;
3247          } else {          } else {
3248            !!!cp (989);            !!!cp (989);
3249            $self->{current_attribute}->{value} .= '&' . $self->{state_keyword};            $self->{ca}->{value} .= '&' . $self->{s_kwd};
3250            $self->{state} = $self->{prev_state};            $self->{state} = $self->{prev_state};
3251            ## Reconsume.            ## Reconsume.
3252            redo A;            redo A;
3253          }          }
3254        }        }
3255      } elsif ($self->{state} == HEXREF_HEX_STATE) {      } elsif ($self->{state} == HEXREF_HEX_STATE) {
3256        if (0x0030 <= $self->{next_char} and $self->{next_char} <= 0x0039) {        if (0x0030 <= $self->{nc} and $self->{nc} <= 0x0039) {
3257          # 0..9          # 0..9
3258          !!!cp (1002);          !!!cp (1002);
3259          $self->{state_keyword} *= 0x10;          $self->{s_kwd} *= 0x10;
3260          $self->{state_keyword} += $self->{next_char} - 0x0030;          $self->{s_kwd} += $self->{nc} - 0x0030;
3261          ## Stay in the state.          ## Stay in the state.
3262          !!!next-input-character;          !!!next-input-character;
3263          redo A;          redo A;
3264        } elsif (0x0061 <= $self->{next_char} and        } elsif (0x0061 <= $self->{nc} and
3265                 $self->{next_char} <= 0x0066) { # a..f                 $self->{nc} <= 0x0066) { # a..f
3266          !!!cp (1003);          !!!cp (1003);
3267          $self->{state_keyword} *= 0x10;          $self->{s_kwd} *= 0x10;
3268          $self->{state_keyword} += $self->{next_char} - 0x0060 + 9;          $self->{s_kwd} += $self->{nc} - 0x0060 + 9;
3269          ## Stay in the state.          ## Stay in the state.
3270          !!!next-input-character;          !!!next-input-character;
3271          redo A;          redo A;
3272        } elsif (0x0041 <= $self->{next_char} and        } elsif (0x0041 <= $self->{nc} and
3273                 $self->{next_char} <= 0x0046) { # A..F                 $self->{nc} <= 0x0046) { # A..F
3274          !!!cp (1004);          !!!cp (1004);
3275          $self->{state_keyword} *= 0x10;          $self->{s_kwd} *= 0x10;
3276          $self->{state_keyword} += $self->{next_char} - 0x0040 + 9;          $self->{s_kwd} += $self->{nc} - 0x0040 + 9;
3277          ## Stay in the state.          ## Stay in the state.
3278          !!!next-input-character;          !!!next-input-character;
3279          redo A;          redo A;
3280        } elsif ($self->{next_char} == 0x003B) { # ;        } elsif ($self->{nc} == 0x003B) { # ;
3281          !!!cp (1006);          !!!cp (1006);
3282          !!!next-input-character;          !!!next-input-character;
3283          #          #
# Line 3195  sub _get_next_token ($) { Line 3290  sub _get_next_token ($) {
3290          #          #
3291        }        }
3292    
3293        my $code = $self->{state_keyword};        my $code = $self->{s_kwd};
3294        my $l = $self->{line_prev};        my $l = $self->{line_prev};
3295        my $c = $self->{column_prev};        my $c = $self->{column_prev};
3296        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
# Line 3230  sub _get_next_token ($) { Line 3325  sub _get_next_token ($) {
3325          redo A;          redo A;
3326        } else {        } else {
3327          !!!cp (987);          !!!cp (987);
3328          $self->{current_attribute}->{value} .= chr $code;          $self->{ca}->{value} .= chr $code;
3329          $self->{current_attribute}->{has_reference} = 1;          $self->{ca}->{has_reference} = 1;
3330          $self->{state} = $self->{prev_state};          $self->{state} = $self->{prev_state};
3331          ## Reconsume.          ## Reconsume.
3332          redo A;          redo A;
3333        }        }
3334      } elsif ($self->{state} == ENTITY_NAME_STATE) {      } elsif ($self->{state} == ENTITY_NAME_STATE) {
3335        if (length $self->{state_keyword} < 30 and        if (length $self->{s_kwd} < 30 and
3336            ## NOTE: Some number greater than the maximum length of entity name            ## NOTE: Some number greater than the maximum length of entity name
3337            ((0x0041 <= $self->{next_char} and # a            ((0x0041 <= $self->{nc} and # a
3338              $self->{next_char} <= 0x005A) or # x              $self->{nc} <= 0x005A) or # x
3339             (0x0061 <= $self->{next_char} and # a             (0x0061 <= $self->{nc} and # a
3340              $self->{next_char} <= 0x007A) or # z              $self->{nc} <= 0x007A) or # z
3341             (0x0030 <= $self->{next_char} and # 0             (0x0030 <= $self->{nc} and # 0
3342              $self->{next_char} <= 0x0039) or # 9              $self->{nc} <= 0x0039) or # 9
3343             $self->{next_char} == 0x003B)) { # ;             $self->{nc} == 0x003B)) { # ;
3344          our $EntityChar;          our $EntityChar;
3345          $self->{state_keyword} .= chr $self->{next_char};          $self->{s_kwd} .= chr $self->{nc};
3346          if (defined $EntityChar->{$self->{state_keyword}}) {          if (defined $EntityChar->{$self->{s_kwd}}) {
3347            if ($self->{next_char} == 0x003B) { # ;            if ($self->{nc} == 0x003B) { # ;
3348              !!!cp (1020);              !!!cp (1020);
3349              $self->{entity__value} = $EntityChar->{$self->{state_keyword}};              $self->{entity__value} = $EntityChar->{$self->{s_kwd}};
3350              $self->{entity__match} = 1;              $self->{entity__match} = 1;
3351              !!!next-input-character;              !!!next-input-character;
3352              #              #
3353            } else {            } else {
3354              !!!cp (1021);              !!!cp (1021);
3355              $self->{entity__value} = $EntityChar->{$self->{state_keyword}};              $self->{entity__value} = $EntityChar->{$self->{s_kwd}};
3356              $self->{entity__match} = -1;              $self->{entity__match} = -1;
3357              ## Stay in the state.              ## Stay in the state.
3358              !!!next-input-character;              !!!next-input-character;
# Line 3265  sub _get_next_token ($) { Line 3360  sub _get_next_token ($) {
3360            }            }
3361          } else {          } else {
3362            !!!cp (1022);            !!!cp (1022);
3363            $self->{entity__value} .= chr $self->{next_char};            $self->{entity__value} .= chr $self->{nc};
3364            $self->{entity__match} *= 2;            $self->{entity__match} *= 2;
3365            ## Stay in the state.            ## Stay in the state.
3366            !!!next-input-character;            !!!next-input-character;
# Line 3285  sub _get_next_token ($) { Line 3380  sub _get_next_token ($) {
3380          if ($self->{prev_state} != DATA_STATE and # in attribute          if ($self->{prev_state} != DATA_STATE and # in attribute
3381              $self->{entity__match} < -1) {              $self->{entity__match} < -1) {
3382            !!!cp (1024);            !!!cp (1024);
3383            $data = '&' . $self->{state_keyword};            $data = '&' . $self->{s_kwd};
3384            #            #
3385          } else {          } else {
3386            !!!cp (1025);            !!!cp (1025);
# Line 3297  sub _get_next_token ($) { Line 3392  sub _get_next_token ($) {
3392          !!!cp (1026);          !!!cp (1026);
3393          !!!parse-error (type => 'bare ero',          !!!parse-error (type => 'bare ero',
3394                          line => $self->{line_prev},                          line => $self->{line_prev},
3395                          column => $self->{column_prev});                          column => $self->{column_prev} - length $self->{s_kwd});
3396          $data = '&' . $self->{state_keyword};          $data = '&' . $self->{s_kwd};
3397          #          #
3398        }        }
3399        
# Line 3319  sub _get_next_token ($) { Line 3414  sub _get_next_token ($) {
3414          !!!emit ({type => CHARACTER_TOKEN,          !!!emit ({type => CHARACTER_TOKEN,
3415                    data => $data,                    data => $data,
3416                    line => $self->{line_prev},                    line => $self->{line_prev},
3417                    column => $self->{column_prev} + 1 - length $self->{state_keyword},                    column => $self->{column_prev} + 1 - length $self->{s_kwd},
3418                   });                   });
3419          redo A;          redo A;
3420        } else {        } else {
3421          !!!cp (985);          !!!cp (985);
3422          $self->{current_attribute}->{value} .= $data;          $self->{ca}->{value} .= $data;
3423          $self->{current_attribute}->{has_reference} = 1 if $has_ref;          $self->{ca}->{has_reference} = 1 if $has_ref;
3424          $self->{state} = $self->{prev_state};          $self->{state} = $self->{prev_state};
3425          ## Reconsume.          ## Reconsume.
3426          redo A;          redo A;
# Line 3403  sub _tree_construction_initial ($) { Line 3498  sub _tree_construction_initial ($) {
3498        $doctype_name = '' unless defined $doctype_name;        $doctype_name = '' unless defined $doctype_name;
3499        $doctype_name =~ tr/a-z/A-Z/; # ASCII case-insensitive        $doctype_name =~ tr/a-z/A-Z/; # ASCII case-insensitive
3500        if (not defined $token->{name} or # <!DOCTYPE>        if (not defined $token->{name} or # <!DOCTYPE>
3501            defined $token->{system_identifier}) {            defined $token->{sysid}) {
3502          !!!cp ('t1');          !!!cp ('t1');
3503          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3504        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
3505          !!!cp ('t2');          !!!cp ('t2');
3506          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3507        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{pubid}) {
3508          if ($token->{public_identifier} eq 'XSLT-compat') {          if ($token->{pubid} eq 'XSLT-compat') {
3509            !!!cp ('t1.2');            !!!cp ('t1.2');
3510            !!!parse-error (type => 'XSLT-compat', token => $token,            !!!parse-error (type => 'XSLT-compat', token => $token,
3511                            level => $self->{level}->{should});                            level => $self->{level}->{should});
# Line 3426  sub _tree_construction_initial ($) { Line 3521  sub _tree_construction_initial ($) {
3521          ($token->{name}); ## ISSUE: If name is missing (e.g. <!DOCTYPE>)?          ($token->{name}); ## ISSUE: If name is missing (e.g. <!DOCTYPE>)?
3522        ## NOTE: Default value for both |public_id| and |system_id| attributes        ## NOTE: Default value for both |public_id| and |system_id| attributes
3523        ## are empty strings, so that we don't set any value in missing cases.        ## are empty strings, so that we don't set any value in missing cases.
3524        $doctype->public_id ($token->{public_identifier})        $doctype->public_id ($token->{pubid}) if defined $token->{pubid};
3525            if defined $token->{public_identifier};        $doctype->system_id ($token->{sysid}) if defined $token->{sysid};
       $doctype->system_id ($token->{system_identifier})  
           if defined $token->{system_identifier};  
3526        ## NOTE: Other DocumentType attributes are null or empty lists.        ## NOTE: Other DocumentType attributes are null or empty lists.
3527        ## ISSUE: internalSubset = null??        ## ISSUE: internalSubset = null??
3528        $self->{document}->append_child ($doctype);        $self->{document}->append_child ($doctype);
# Line 3437  sub _tree_construction_initial ($) { Line 3530  sub _tree_construction_initial ($) {
3530        if ($token->{quirks} or $doctype_name ne 'HTML') {        if ($token->{quirks} or $doctype_name ne 'HTML') {
3531          !!!cp ('t4');          !!!cp ('t4');
3532          $self->{document}->manakai_compat_mode ('quirks');          $self->{document}->manakai_compat_mode ('quirks');
3533        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{pubid}) {
3534          my $pubid = $token->{public_identifier};          my $pubid = $token->{pubid};
3535          $pubid =~ tr/a-z/A-z/;          $pubid =~ tr/a-z/A-z/;
3536          my $prefix = [          my $prefix = [
3537            "+//SILMARIL//DTD HTML PRO V0R11 19970101//",            "+//SILMARIL//DTD HTML PRO V0R11 19970101//",
# Line 3512  sub _tree_construction_initial ($) { Line 3605  sub _tree_construction_initial ($) {
3605            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3606          } elsif ($pubid =~ m[^-//W3C//DTD HTML 4.01 FRAMESET//] or          } elsif ($pubid =~ m[^-//W3C//DTD HTML 4.01 FRAMESET//] or
3607                   $pubid =~ m[^-//W3C//DTD HTML 4.01 TRANSITIONAL//]) {                   $pubid =~ m[^-//W3C//DTD HTML 4.01 TRANSITIONAL//]) {
3608            if (defined $token->{system_identifier}) {            if (defined $token->{sysid}) {
3609              !!!cp ('t6');              !!!cp ('t6');
3610              $self->{document}->manakai_compat_mode ('quirks');              $self->{document}->manakai_compat_mode ('quirks');
3611            } else {            } else {
# Line 3529  sub _tree_construction_initial ($) { Line 3622  sub _tree_construction_initial ($) {
3622        } else {        } else {
3623          !!!cp ('t10');          !!!cp ('t10');
3624        }        }
3625        if (defined $token->{system_identifier}) {        if (defined $token->{sysid}) {
3626          my $sysid = $token->{system_identifier};          my $sysid = $token->{sysid};
3627          $sysid =~ tr/A-Z/a-z/;          $sysid =~ tr/A-Z/a-z/;
3628          if ($sysid eq "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") {          if ($sysid eq "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") {
3629            ## NOTE: Ensure that |PUBLIC "(limited quirks)" "(quirks)"| is            ## NOTE: Ensure that |PUBLIC "(limited quirks)" "(quirks)"| is
# Line 3560  sub _tree_construction_initial ($) { Line 3653  sub _tree_construction_initial ($) {
3653        !!!ack-later;        !!!ack-later;
3654        return;        return;
3655      } elsif ($token->{type} == CHARACTER_TOKEN) {      } elsif ($token->{type} == CHARACTER_TOKEN) {
3656        if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D        if ($token->{data} =~ s/^([\x09\x0A\x0C\x20]+)//) {
3657          ## Ignore the token          ## Ignore the token
3658    
3659          unless (length $token->{data}) {          unless (length $token->{data}) {
# Line 3617  sub _tree_construction_root_element ($) Line 3710  sub _tree_construction_root_element ($)
3710          !!!next-token;          !!!next-token;
3711          redo B;          redo B;
3712        } elsif ($token->{type} == CHARACTER_TOKEN) {        } elsif ($token->{type} == CHARACTER_TOKEN) {
3713          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D          if ($token->{data} =~ s/^([\x09\x0A\x0C\x20]+)//) {
3714            ## Ignore the token.            ## Ignore the token.
3715    
3716            unless (length $token->{data}) {            unless (length $token->{data}) {
# Line 4431  sub _tree_construction_main ($) { Line 4524  sub _tree_construction_main ($) {
4524    
4525      if ($self->{insertion_mode} & HEAD_IMS) {      if ($self->{insertion_mode} & HEAD_IMS) {
4526        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
4527          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0C\x20]+)//) {
4528            unless ($self->{insertion_mode} == BEFORE_HEAD_IM) {            unless ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4529              !!!cp ('t88.2');              !!!cp ('t88.2');
4530              $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);              $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4531                #
4532            } else {            } else {
4533              !!!cp ('t88.1');              !!!cp ('t88.1');
4534              ## Ignore the token.              ## Ignore the token.
4535              !!!next-token;              #
             next B;  
4536            }            }
4537            unless (length $token->{data}) {            unless (length $token->{data}) {
4538              !!!cp ('t88');              !!!cp ('t88');
4539              !!!next-token;              !!!next-token;
4540              next B;              next B;
4541            }            }
4542    ## TODO: set $token->{column} appropriately
4543          }          }
4544    
4545          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
# Line 4609  sub _tree_construction_main ($) { Line 4703  sub _tree_construction_main ($) {
4703                  } elsif ($token->{attributes}->{content}) {                  } elsif ($token->{attributes}->{content}) {
4704                    if ($token->{attributes}->{content}->{value}                    if ($token->{attributes}->{content}->{value}
4705                        =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                        =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
4706                            [\x09-\x0D\x20]*=                            [\x09\x0A\x0C\x0D\x20]*=
4707                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                            [\x09\x0A\x0C\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
4708                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {                            ([^"'\x09\x0A\x0C\x0D\x20]
4709                               [^\x09\x0A\x0C\x0D\x20\x3B]*))/x) {
4710                      !!!cp ('t107');                      !!!cp ('t107');
4711                      ## NOTE: Whether the encoding is supported or not is handled                      ## NOTE: Whether the encoding is supported or not is handled
4712                      ## in the {change_encoding} callback.                      ## in the {change_encoding} callback.
# Line 5420  sub _tree_construction_main ($) { Line 5515  sub _tree_construction_main ($) {
5515      } elsif ($self->{insertion_mode} & TABLE_IMS) {      } elsif ($self->{insertion_mode} & TABLE_IMS) {
5516        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
5517          if (not $open_tables->[-1]->[1] and # tainted          if (not $open_tables->[-1]->[1] and # tainted
5518              $token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              $token->{data} =~ s/^([\x09\x0A\x0C\x20]+)//) {
5519            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
5520                                
5521            unless (length $token->{data}) {            unless (length $token->{data}) {
# Line 6104  sub _tree_construction_main ($) { Line 6199  sub _tree_construction_main ($) {
6199        }        }
6200      } elsif ($self->{insertion_mode} == IN_COLUMN_GROUP_IM) {      } elsif ($self->{insertion_mode} == IN_COLUMN_GROUP_IM) {
6201            if ($token->{type} == CHARACTER_TOKEN) {            if ($token->{type} == CHARACTER_TOKEN) {
6202              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0C\x20]+)//) {
6203                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
6204                unless (length $token->{data}) {                unless (length $token->{data}) {
6205                  !!!cp ('t260');                  !!!cp ('t260');
# Line 6445  sub _tree_construction_main ($) { Line 6540  sub _tree_construction_main ($) {
6540        }        }
6541      } elsif ($self->{insertion_mode} & BODY_AFTER_IMS) {      } elsif ($self->{insertion_mode} & BODY_AFTER_IMS) {
6542        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
6543          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0C\x20]+)//) {
6544            my $data = $1;            my $data = $1;
6545            ## As if in body            ## As if in body
6546            $reconstruct_active_formatting_elements->($insert_to_current);            $reconstruct_active_formatting_elements->($insert_to_current);
# Line 6462  sub _tree_construction_main ($) { Line 6557  sub _tree_construction_main ($) {
6557          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6558            !!!cp ('t301');            !!!cp ('t301');
6559            !!!parse-error (type => 'after html:#text', token => $token);            !!!parse-error (type => 'after html:#text', token => $token);
6560              #
           ## Reprocess in the "after body" insertion mode.  
6561          } else {          } else {
6562            !!!cp ('t302');            !!!cp ('t302');
6563              ## "after body" insertion mode
6564              !!!parse-error (type => 'after body:#text', token => $token);
6565              #
6566          }          }
           
         ## "after body" insertion mode  
         !!!parse-error (type => 'after body:#text', token => $token);  
6567    
6568          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6569          ## reprocess          ## reprocess
# Line 6479  sub _tree_construction_main ($) { Line 6573  sub _tree_construction_main ($) {
6573            !!!cp ('t303');            !!!cp ('t303');
6574            !!!parse-error (type => 'after html',            !!!parse-error (type => 'after html',
6575                            text => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
6576                        #
           ## Reprocess in the "after body" insertion mode.  
6577          } else {          } else {
6578            !!!cp ('t304');            !!!cp ('t304');
6579              ## "after body" insertion mode
6580              !!!parse-error (type => 'after body',
6581                              text => $token->{tag_name}, token => $token);
6582              #
6583          }          }
6584    
         ## "after body" insertion mode  
         !!!parse-error (type => 'after body',  
                         text => $token->{tag_name}, token => $token);  
   
6585          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6586          !!!ack-later;          !!!ack-later;
6587          ## reprocess          ## reprocess
# Line 6499  sub _tree_construction_main ($) { Line 6592  sub _tree_construction_main ($) {
6592            !!!parse-error (type => 'after html:/',            !!!parse-error (type => 'after html:/',
6593                            text => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
6594                        
6595            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
6596            ## Reprocess in the "after body" insertion mode.            ## Reprocess.
6597              next B;
6598          } else {          } else {
6599            !!!cp ('t306');            !!!cp ('t306');
6600          }          }
# Line 6538  sub _tree_construction_main ($) { Line 6632  sub _tree_construction_main ($) {
6632        }        }
6633      } elsif ($self->{insertion_mode} & FRAME_IMS) {      } elsif ($self->{insertion_mode} & FRAME_IMS) {
6634        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
6635          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0C\x20]+)//) {
6636            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
6637                        
6638            unless (length $token->{data}) {            unless (length $token->{data}) {
# Line 6548  sub _tree_construction_main ($) { Line 6642  sub _tree_construction_main ($) {
6642            }            }
6643          }          }
6644                    
6645          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0C\x20]+//) {
6646            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6647              !!!cp ('t311');              !!!cp ('t311');
6648              !!!parse-error (type => 'in frameset:#text', token => $token);              !!!parse-error (type => 'in frameset:#text', token => $token);
# Line 6725  sub _tree_construction_main ($) { Line 6819  sub _tree_construction_main ($) {
6819            } elsif ($token->{attributes}->{content}) {            } elsif ($token->{attributes}->{content}) {
6820              if ($token->{attributes}->{content}->{value}              if ($token->{attributes}->{content}->{value}
6821                  =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                  =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
6822                      [\x09-\x0D\x20]*=                      [\x09\x0A\x0C\x0D\x20]*=
6823                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                      [\x09\x0A\x0C\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
6824                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {                      ([^"'\x09\x0A\x0C\x0D\x20][^\x09\x0A\x0C\x0D\x20\x3B]*))
6825                       /x) {
6826                !!!cp ('t336');                !!!cp ('t336');
6827                ## NOTE: Whether the encoding is supported or not is handled                ## NOTE: Whether the encoding is supported or not is handled
6828                ## in the {change_encoding} callback.                ## in the {change_encoding} callback.
# Line 7690  sub _tree_construction_main ($) { Line 7785  sub _tree_construction_main ($) {
7785    ## TODO: script stuffs    ## TODO: script stuffs
7786  } # _tree_construct_main  } # _tree_construct_main
7787    
7788  sub set_inner_html ($$$;$) {  sub set_inner_html ($$$$;$) {
7789    my $class = shift;    my $class = shift;
7790    my $node = shift;    my $node = shift;
7791    my $s = \$_[0];    #my $s = \$_[0];
7792    my $onerror = $_[1];    my $onerror = $_[1];
7793    my $get_wrapper = $_[2] || sub ($) { return $_[0] };    my $get_wrapper = $_[2] || sub ($) { return $_[0] };
7794    
# Line 7714  sub set_inner_html ($$$;$) { Line 7809  sub set_inner_html ($$$;$) {
7809      }      }
7810    
7811      ## Step 3, 4, 5 # MUST      ## Step 3, 4, 5 # MUST
7812      $class->parse_char_string ($$s => $node, $onerror, $get_wrapper);      $class->parse_char_string ($_[0] => $node, $onerror, $get_wrapper);
7813    } elsif ($nt == 1) {    } elsif ($nt == 1) {
7814      ## TODO: If non-html element      ## TODO: If non-html element
7815    
# Line 7733  sub set_inner_html ($$$;$) { Line 7828  sub set_inner_html ($$$;$) {
7828      my $i = 0;      my $i = 0;
7829      $p->{line_prev} = $p->{line} = 1;      $p->{line_prev} = $p->{line} = 1;
7830      $p->{column_prev} = $p->{column} = 0;      $p->{column_prev} = $p->{column} = 0;
7831      $p->{set_next_char} = sub {      require Whatpm::Charset::DecodeHandle;
7832        my $input = Whatpm::Charset::DecodeHandle::CharString->new (\($_[0]));
7833        $input = $get_wrapper->($input);
7834        $p->{set_nc} = sub {
7835        my $self = shift;        my $self = shift;
7836    
7837        pop @{$self->{prev_char}};        my $char = '';
7838        unshift @{$self->{prev_char}}, $self->{next_char};        if (defined $self->{next_nc}) {
7839            $char = $self->{next_nc};
7840        $self->{next_char} = -1 and return if $i >= length $$s;          delete $self->{next_nc};
7841        $self->{next_char} = ord substr $$s, $i++, 1;          $self->{nc} = ord $char;
7842          } else {
7843            $self->{char_buffer} = '';
7844            $self->{char_buffer_pos} = 0;
7845            
7846            my $count = $input->manakai_read_until
7847                ($self->{char_buffer}, qr/[^\x00\x0A\x0D]/,
7848                 $self->{char_buffer_pos});
7849            if ($count) {
7850              $self->{line_prev} = $self->{line};
7851              $self->{column_prev} = $self->{column};
7852              $self->{column}++;
7853              $self->{nc}
7854                  = ord substr ($self->{char_buffer},
7855                                $self->{char_buffer_pos}++, 1);
7856              return;
7857            }
7858            
7859            if ($input->read ($char, 1)) {
7860              $self->{nc} = ord $char;
7861            } else {
7862              $self->{nc} = -1;
7863              return;
7864            }
7865          }
7866    
7867        ($p->{line_prev}, $p->{column_prev}) = ($p->{line}, $p->{column});        ($p->{line_prev}, $p->{column_prev}) = ($p->{line}, $p->{column});
7868        $p->{column}++;        $p->{column}++;
7869    
7870        if ($self->{next_char} == 0x000A) { # LF        if ($self->{nc} == 0x000A) { # LF
7871          $p->{line}++;          $p->{line}++;
7872          $p->{column} = 0;          $p->{column} = 0;
7873          !!!cp ('i1');          !!!cp ('i1');
7874        } elsif ($self->{next_char} == 0x000D) { # CR        } elsif ($self->{nc} == 0x000D) { # CR
7875          $i++ if substr ($$s, $i, 1) eq "\x0A";  ## TODO: support for abort/streaming
7876          $self->{next_char} = 0x000A; # LF # MUST          my $next = '';
7877            if ($input->read ($next, 1) and $next ne "\x0A") {
7878              $self->{next_nc} = $next;
7879            }
7880            $self->{nc} = 0x000A; # LF # MUST
7881          $p->{line}++;          $p->{line}++;
7882          $p->{column} = 0;          $p->{column} = 0;
7883          !!!cp ('i2');          !!!cp ('i2');
7884        } elsif ($self->{next_char} > 0x10FFFF) {        } elsif ($self->{nc} == 0x0000) { # NULL
         $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST  
         !!!cp ('i3');  
       } elsif ($self->{next_char} == 0x0000) { # NULL  
7885          !!!cp ('i4');          !!!cp ('i4');
7886          !!!parse-error (type => 'NULL');          !!!parse-error (type => 'NULL');
7887          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{nc} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
       } elsif ($self->{next_char} <= 0x0008 or  
                (0x000E <= $self->{next_char} and  
                 $self->{next_char} <= 0x001F) or  
                (0x007F <= $self->{next_char} and  
                 $self->{next_char} <= 0x009F) or  
                (0xD800 <= $self->{next_char} and  
                 $self->{next_char} <= 0xDFFF) or  
                (0xFDD0 <= $self->{next_char} and  
                 $self->{next_char} <= 0xFDDF) or  
                {  
                 0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,  
                 0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,  
                 0x4FFFE => 1, 0x4FFFF => 1, 0x5FFFE => 1, 0x5FFFF => 1,  
                 0x6FFFE => 1, 0x6FFFF => 1, 0x7FFFE => 1, 0x7FFFF => 1,  
                 0x8FFFE => 1, 0x8FFFF => 1, 0x9FFFE => 1, 0x9FFFF => 1,  
                 0xAFFFE => 1, 0xAFFFF => 1, 0xBFFFE => 1, 0xBFFFF => 1,  
                 0xCFFFE => 1, 0xCFFFF => 1, 0xDFFFE => 1, 0xDFFFF => 1,  
                 0xEFFFE => 1, 0xEFFFF => 1, 0xFFFFE => 1, 0xFFFFF => 1,  
                 0x10FFFE => 1, 0x10FFFF => 1,  
                }->{$self->{next_char}}) {  
         !!!cp ('i4.1');  
         if ($self->{next_char} < 0x10000) {  
           !!!parse-error (type => 'control char',  
                           text => (sprintf 'U+%04X', $self->{next_char}));  
         } else {  
           !!!parse-error (type => 'control char',  
                           text => (sprintf 'U-%08X', $self->{next_char}));  
         }  
7888        }        }
7889      };      };
     $p->{prev_char} = [-1, -1, -1];  
     $p->{next_char} = -1;  
7890    
7891      $p->{read_until} = sub {      $p->{read_until} = sub {
7892        ## TODO: ...        #my ($scalar, $specials_range, $offset) = @_;
7893        return 0;        return 0 if defined $p->{next_nc};
7894      }; # $p->{read_until};  
7895          my $pattern = qr/[^$_[1]\x00\x0A\x0D]/;
7896          my $offset = $_[2] || 0;
7897          
7898          if ($p->{char_buffer_pos} < length $p->{char_buffer}) {
7899            pos ($p->{char_buffer}) = $p->{char_buffer_pos};
7900            if ($p->{char_buffer} =~ /\G(?>$pattern)+/) {
7901              substr ($_[0], $offset)
7902                  = substr ($p->{char_buffer}, $-[0], $+[0] - $-[0]);
7903              my $count = $+[0] - $-[0];
7904              if ($count) {
7905                $p->{column} += $count;
7906                $p->{char_buffer_pos} += $count;
7907                $p->{line_prev} = $p->{line};
7908                $p->{column_prev} = $p->{column} - 1;
7909                $p->{nc} = -1;
7910              }
7911              return $count;
7912            } else {
7913              return 0;
7914            }
7915          } else {
7916            my $count = $input->manakai_read_until ($_[0], $pattern, $_[2]);
7917            if ($count) {
7918              $p->{column} += $count;
7919              $p->{column_prev} += $count;
7920              $p->{nc} = -1;
7921            }
7922            return $count;
7923          }
7924        }; # $p->{read_until}
7925    
7926      my $ponerror = $onerror || sub {      my $ponerror = $onerror || sub {
7927        my (%opt) = @_;        my (%opt) = @_;
# Line 7814  sub set_inner_html ($$$;$) { Line 7937  sub set_inner_html ($$$;$) {
7937        $ponerror->(line => $p->{line}, column => $p->{column}, @_);        $ponerror->(line => $p->{line}, column => $p->{column}, @_);
7938      };      };
7939            
7940        my $char_onerror = sub {
7941          my (undef, $type, %opt) = @_;
7942          $ponerror->(layer => 'encode',
7943                      line => $p->{line}, column => $p->{column} + 1,
7944                      %opt, type => $type);
7945        }; # $char_onerror
7946        $input->onerror ($char_onerror);
7947    
7948      $p->_initialize_tokenizer;      $p->_initialize_tokenizer;
7949      $p->_initialize_tree_constructor;      $p->_initialize_tree_constructor;
7950    

Legend:
Removed from v.1.172  
changed lines
  Added in v.1.190

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24