/[suikacvs]/markup/html/whatpm/Whatpm/HTML.pm.src
Suika

Diff of /markup/html/whatpm/Whatpm/HTML.pm.src

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.54 by wakaba, Sat Aug 11 06:37:12 2007 UTC revision 1.62 by wakaba, Sun Nov 11 04:59:35 2007 UTC
# Line 147  sub new ($) { Line 147  sub new ($) {
147    $self->{parse_error} = sub {    $self->{parse_error} = sub {
148      #      #
149    };    };
150      $self->{application_cache_selection} = sub {
151        #
152      };
153    return $self;    return $self;
154  } # new  } # new
155    
# Line 159  sub CDATA_CONTENT_MODEL () { CM_LIMITED_ Line 162  sub CDATA_CONTENT_MODEL () { CM_LIMITED_
162  sub RCDATA_CONTENT_MODEL () { CM_ENTITY | CM_LIMITED_MARKUP }  sub RCDATA_CONTENT_MODEL () { CM_ENTITY | CM_LIMITED_MARKUP }
163  sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }  sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }
164    
165    sub DATA_STATE () { 0 }
166    sub ENTITY_DATA_STATE () { 1 }
167    sub TAG_OPEN_STATE () { 2 }
168    sub CLOSE_TAG_OPEN_STATE () { 3 }
169    sub TAG_NAME_STATE () { 4 }
170    sub BEFORE_ATTRIBUTE_NAME_STATE () { 5 }
171    sub ATTRIBUTE_NAME_STATE () { 6 }
172    sub AFTER_ATTRIBUTE_NAME_STATE () { 7 }
173    sub BEFORE_ATTRIBUTE_VALUE_STATE () { 8 }
174    sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 }
175    sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 }
176    sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 }
177    sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 }
178    sub MARKUP_DECLARATION_OPEN_STATE () { 13 }
179    sub COMMENT_START_STATE () { 14 }
180    sub COMMENT_START_DASH_STATE () { 15 }
181    sub COMMENT_STATE () { 16 }
182    sub COMMENT_END_STATE () { 17 }
183    sub COMMENT_END_DASH_STATE () { 18 }
184    sub BOGUS_COMMENT_STATE () { 19 }
185    sub DOCTYPE_STATE () { 20 }
186    sub BEFORE_DOCTYPE_NAME_STATE () { 21 }
187    sub DOCTYPE_NAME_STATE () { 22 }
188    sub AFTER_DOCTYPE_NAME_STATE () { 23 }
189    sub BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE () { 24 }
190    sub DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE () { 25 }
191    sub DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE () { 26 }
192    sub AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE () { 27 }
193    sub BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE () { 28 }
194    sub DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE () { 29 }
195    sub DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE () { 30 }
196    sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE () { 31 }
197    sub BOGUS_DOCTYPE_STATE () { 32 }
198    
199    sub DOCTYPE_TOKEN () { 1 }
200    sub COMMENT_TOKEN () { 2 }
201    sub START_TAG_TOKEN () { 3 }
202    sub END_TAG_TOKEN () { 4 }
203    sub END_OF_FILE_TOKEN () { 5 }
204    sub CHARACTER_TOKEN () { 6 }
205    
206  sub AFTER_HTML_IMS () { 0b100 }  sub AFTER_HTML_IMS () { 0b100 }
207  sub HEAD_IMS ()       { 0b1000 }  sub HEAD_IMS ()       { 0b1000 }
208  sub BODY_IMS ()       { 0b10000 }  sub BODY_IMS ()       { 0b10000 }
209  sub BODY_TABLE_IMS () { 0b100000 | BODY_IMS }  sub BODY_TABLE_IMS () { 0b100000 }
210  sub TABLE_IMS ()      { 0b1000000 }  sub TABLE_IMS ()      { 0b1000000 }
211  sub ROW_IMS ()        { 0b10000000 | TABLE_IMS }  sub ROW_IMS ()        { 0b10000000 }
212  sub BODY_AFTER_IMS () { 0b100000000 }  sub BODY_AFTER_IMS () { 0b100000000 }
213  sub FRAME_IMS ()      { 0b1000000000 }  sub FRAME_IMS ()      { 0b1000000000 }
214    
# Line 175  sub IN_HEAD_NOSCRIPT_IM () { HEAD_IMS | Line 219  sub IN_HEAD_NOSCRIPT_IM () { HEAD_IMS |
219  sub AFTER_HEAD_IM () { HEAD_IMS | 0b10 }  sub AFTER_HEAD_IM () { HEAD_IMS | 0b10 }
220  sub BEFORE_HEAD_IM () { HEAD_IMS | 0b11 }  sub BEFORE_HEAD_IM () { HEAD_IMS | 0b11 }
221  sub IN_BODY_IM () { BODY_IMS }  sub IN_BODY_IM () { BODY_IMS }
222  sub IN_CELL_IM () { BODY_TABLE_IMS | 0b01 }  sub IN_CELL_IM () { BODY_IMS | BODY_TABLE_IMS | 0b01 }
223  sub IN_CAPTION_IM () { BODY_TABLE_IMS | 0b10 }  sub IN_CAPTION_IM () { BODY_IMS | BODY_TABLE_IMS | 0b10 }
224  sub IN_ROW_IM () { ROW_IMS | 0b01 }  sub IN_ROW_IM () { TABLE_IMS | ROW_IMS | 0b01 }
225  sub IN_TABLE_BODY_IM () { ROW_IMS | 0b10 }  sub IN_TABLE_BODY_IM () { TABLE_IMS | ROW_IMS | 0b10 }
226  sub IN_TABLE_IM () { TABLE_IMS }  sub IN_TABLE_IM () { TABLE_IMS }
227  sub AFTER_BODY_IM () { BODY_AFTER_IMS }  sub AFTER_BODY_IM () { BODY_AFTER_IMS }
228  sub IN_FRAMESET_IM () { FRAME_IMS | 0b01 }  sub IN_FRAMESET_IM () { FRAME_IMS | 0b01 }
# Line 190  sub IN_COLUMN_GROUP_IM () { 0b10 } Line 234  sub IN_COLUMN_GROUP_IM () { 0b10 }
234    
235  sub _initialize_tokenizer ($) {  sub _initialize_tokenizer ($) {
236    my $self = shift;    my $self = shift;
237    $self->{state} = 'data'; # MUST    $self->{state} = DATA_STATE; # MUST
238    $self->{content_model} = PCDATA_CONTENT_MODEL; # be    $self->{content_model} = PCDATA_CONTENT_MODEL; # be
239    undef $self->{current_token}; # start tag, end tag, comment, or DOCTYPE    undef $self->{current_token}; # start tag, end tag, comment, or DOCTYPE
240    undef $self->{current_attribute};    undef $self->{current_attribute};
# Line 204  sub _initialize_tokenizer ($) { Line 248  sub _initialize_tokenizer ($) {
248  } # _initialize_tokenizer  } # _initialize_tokenizer
249    
250  ## A token has:  ## A token has:
251  ##   ->{type} eq 'DOCTYPE', 'start tag', 'end tag', 'comment',  ##   ->{type} == DOCTYPE_TOKEN, START_TAG_TOKEN, END_TAG_TOKEN, COMMENT_TOKEN,
252  ##       'character', or 'end-of-file'  ##       CHARACTER_TOKEN, or END_OF_FILE_TOKEN
253  ##   ->{name} (DOCTYPE, start tag (tag name), end tag (tag name))  ##   ->{name} (DOCTYPE_TOKEN)
254  ##   ->{public_identifier} (DOCTYPE)  ##   ->{tag_name} (START_TAG_TOKEN, END_TAG_TOKEN)
255  ##   ->{system_identifier} (DOCTYPE)  ##   ->{public_identifier} (DOCTYPE_TOKEN)
256  ##   ->{correct} == 1 or 0 (DOCTYPE)  ##   ->{system_identifier} (DOCTYPE_TOKEN)
257  ##   ->{attributes} isa HASH (start tag, end tag)  ##   ->{correct} == 1 or 0 (DOCTYPE_TOKEN)
258  ##   ->{data} (comment, character)  ##   ->{attributes} isa HASH (START_TAG_TOKEN, END_TAG_TOKEN)
259    ##   ->{data} (COMMENT_TOKEN, CHARACTER_TOKEN)
260    
261  ## Emitted token MUST immediately be handled by the tree construction state.  ## Emitted token MUST immediately be handled by the tree construction state.
262    
# Line 221  sub _initialize_tokenizer ($) { Line 266  sub _initialize_tokenizer ($) {
266  ## has completed loading.  If one has, then it MUST be executed  ## has completed loading.  If one has, then it MUST be executed
267  ## and removed from the list.  ## and removed from the list.
268    
269    ## NOTE: HTML5 "Writing HTML documents" section, applied to
270    ## documents and not to user agents and conformance checkers,
271    ## contains some requirements that are not detected by the
272    ## parsing algorithm:
273    ## - Some requirements on character encoding declarations. ## TODO
274    ## - "Elements MUST NOT contain content that their content model disallows."
275    ##   ... Some are parse error, some are not (will be reported by c.c.).
276    ## - Polytheistic slash SHOULD NOT be used. (Applied only to atheists.) ## TODO
277    ## - Text (in elements, attributes, and comments) SHOULD NOT contain
278    ##   control characters other than space characters. ## TODO: (what is control character? C0, C1 and DEL?  Unicode control character?)
279    
280    ## TODO: HTML5 poses authors two SHOULD-level requirements that cannot
281    ## be detected by the HTML5 parsing algorithm:
282    ## - Text,
283    
284  sub _get_next_token ($) {  sub _get_next_token ($) {
285    my $self = shift;    my $self = shift;
286    if (@{$self->{token}}) {    if (@{$self->{token}}) {
# Line 228  sub _get_next_token ($) { Line 288  sub _get_next_token ($) {
288    }    }
289    
290    A: {    A: {
291      if ($self->{state} eq 'data') {      if ($self->{state} == DATA_STATE) {
292        if ($self->{next_input_character} == 0x0026) { # &        if ($self->{next_input_character} == 0x0026) { # &
293          if ($self->{content_model} & CM_ENTITY) { # PCDATA | RCDATA          if ($self->{content_model} & CM_ENTITY) { # PCDATA | RCDATA
294            $self->{state} = 'entity data';            $self->{state} = ENTITY_DATA_STATE;
295            !!!next-input-character;            !!!next-input-character;
296            redo A;            redo A;
297          } else {          } else {
# Line 253  sub _get_next_token ($) { Line 313  sub _get_next_token ($) {
313          if ($self->{content_model} & CM_FULL_MARKUP or # PCDATA          if ($self->{content_model} & CM_FULL_MARKUP or # PCDATA
314              (($self->{content_model} & CM_LIMITED_MARKUP) and # CDATA | RCDATA              (($self->{content_model} & CM_LIMITED_MARKUP) and # CDATA | RCDATA
315               not $self->{escape})) {               not $self->{escape})) {
316            $self->{state} = 'tag open';            $self->{state} = TAG_OPEN_STATE;
317            !!!next-input-character;            !!!next-input-character;
318            redo A;            redo A;
319          } else {          } else {
# Line 270  sub _get_next_token ($) { Line 330  sub _get_next_token ($) {
330                    
331          #          #
332        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
333          !!!emit ({type => 'end-of-file'});          !!!emit ({type => END_OF_FILE_TOKEN});
334          last A; ## TODO: ok?          last A; ## TODO: ok?
335        }        }
336        # Anything else        # Anything else
337        my $token = {type => 'character',        my $token = {type => CHARACTER_TOKEN,
338                     data => chr $self->{next_input_character}};                     data => chr $self->{next_input_character}};
339        ## Stay in the data state        ## Stay in the data state
340        !!!next-input-character;        !!!next-input-character;
# Line 282  sub _get_next_token ($) { Line 342  sub _get_next_token ($) {
342        !!!emit ($token);        !!!emit ($token);
343    
344        redo A;        redo A;
345      } elsif ($self->{state} eq 'entity data') {      } elsif ($self->{state} == ENTITY_DATA_STATE) {
346        ## (cannot happen in CDATA state)        ## (cannot happen in CDATA state)
347                
348        my $token = $self->_tokenize_attempt_to_consume_an_entity (0);        my $token = $self->_tokenize_attempt_to_consume_an_entity (0);
349    
350        $self->{state} = 'data';        $self->{state} = DATA_STATE;
351        # next-input-character is already done        # next-input-character is already done
352    
353        unless (defined $token) {        unless (defined $token) {
354          !!!emit ({type => 'character', data => '&'});          !!!emit ({type => CHARACTER_TOKEN, data => '&'});
355        } else {        } else {
356          !!!emit ($token);          !!!emit ($token);
357        }        }
358    
359        redo A;        redo A;
360      } elsif ($self->{state} eq 'tag open') {      } elsif ($self->{state} == TAG_OPEN_STATE) {
361        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
362          if ($self->{next_input_character} == 0x002F) { # /          if ($self->{next_input_character} == 0x002F) { # /
363            !!!next-input-character;            !!!next-input-character;
364            $self->{state} = 'close tag open';            $self->{state} = CLOSE_TAG_OPEN_STATE;
365            redo A;            redo A;
366          } else {          } else {
367            ## reconsume            ## reconsume
368            $self->{state} = 'data';            $self->{state} = DATA_STATE;
369    
370            !!!emit ({type => 'character', data => '<'});            !!!emit ({type => CHARACTER_TOKEN, data => '<'});
371    
372            redo A;            redo A;
373          }          }
374        } elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA        } elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA
375          if ($self->{next_input_character} == 0x0021) { # !          if ($self->{next_input_character} == 0x0021) { # !
376            $self->{state} = 'markup declaration open';            $self->{state} = MARKUP_DECLARATION_OPEN_STATE;
377            !!!next-input-character;            !!!next-input-character;
378            redo A;            redo A;
379          } elsif ($self->{next_input_character} == 0x002F) { # /          } elsif ($self->{next_input_character} == 0x002F) { # /
380            $self->{state} = 'close tag open';            $self->{state} = CLOSE_TAG_OPEN_STATE;
381            !!!next-input-character;            !!!next-input-character;
382            redo A;            redo A;
383          } elsif (0x0041 <= $self->{next_input_character} and          } elsif (0x0041 <= $self->{next_input_character} and
384                   $self->{next_input_character} <= 0x005A) { # A..Z                   $self->{next_input_character} <= 0x005A) { # A..Z
385            $self->{current_token}            $self->{current_token}
386              = {type => 'start tag',              = {type => START_TAG_TOKEN,
387                 tag_name => chr ($self->{next_input_character} + 0x0020)};                 tag_name => chr ($self->{next_input_character} + 0x0020)};
388            $self->{state} = 'tag name';            $self->{state} = TAG_NAME_STATE;
389            !!!next-input-character;            !!!next-input-character;
390            redo A;            redo A;
391          } elsif (0x0061 <= $self->{next_input_character} and          } elsif (0x0061 <= $self->{next_input_character} and
392                   $self->{next_input_character} <= 0x007A) { # a..z                   $self->{next_input_character} <= 0x007A) { # a..z
393            $self->{current_token} = {type => 'start tag',            $self->{current_token} = {type => START_TAG_TOKEN,
394                              tag_name => chr ($self->{next_input_character})};                              tag_name => chr ($self->{next_input_character})};
395            $self->{state} = 'tag name';            $self->{state} = TAG_NAME_STATE;
396            !!!next-input-character;            !!!next-input-character;
397            redo A;            redo A;
398          } elsif ($self->{next_input_character} == 0x003E) { # >          } elsif ($self->{next_input_character} == 0x003E) { # >
399            !!!parse-error (type => 'empty start tag');            !!!parse-error (type => 'empty start tag');
400            $self->{state} = 'data';            $self->{state} = DATA_STATE;
401            !!!next-input-character;            !!!next-input-character;
402    
403            !!!emit ({type => 'character', data => '<>'});            !!!emit ({type => CHARACTER_TOKEN, data => '<>'});
404    
405            redo A;            redo A;
406          } elsif ($self->{next_input_character} == 0x003F) { # ?          } elsif ($self->{next_input_character} == 0x003F) { # ?
407            !!!parse-error (type => 'pio');            !!!parse-error (type => 'pio');
408            $self->{state} = 'bogus comment';            $self->{state} = BOGUS_COMMENT_STATE;
409            ## $self->{next_input_character} is intentionally left as is            ## $self->{next_input_character} is intentionally left as is
410            redo A;            redo A;
411          } else {          } else {
412            !!!parse-error (type => 'bare stago');            !!!parse-error (type => 'bare stago');
413            $self->{state} = 'data';            $self->{state} = DATA_STATE;
414            ## reconsume            ## reconsume
415    
416            !!!emit ({type => 'character', data => '<'});            !!!emit ({type => CHARACTER_TOKEN, data => '<'});
417    
418            redo A;            redo A;
419          }          }
420        } else {        } else {
421          die "$0: $self->{content_model} in tag open";          die "$0: $self->{content_model} in tag open";
422        }        }
423      } elsif ($self->{state} eq 'close tag open') {      } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {
424        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
425          if (defined $self->{last_emitted_start_tag_name}) {          if (defined $self->{last_emitted_start_tag_name}) {
426            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>
# Line 375  sub _get_next_token ($) { Line 435  sub _get_next_token ($) {
435              } else {              } else {
436                $self->{next_input_character} = shift @next_char; # reconsume                $self->{next_input_character} = shift @next_char; # reconsume
437                !!!back-next-input-character (@next_char);                !!!back-next-input-character (@next_char);
438                $self->{state} = 'data';                $self->{state} = DATA_STATE;
439    
440                !!!emit ({type => 'character', data => '</'});                !!!emit ({type => CHARACTER_TOKEN, data => '</'});
441        
442                redo A;                redo A;
443              }              }
# Line 394  sub _get_next_token ($) { Line 454  sub _get_next_token ($) {
454                    $self->{next_input_character} == -1) {                    $self->{next_input_character} == -1) {
455              $self->{next_input_character} = shift @next_char; # reconsume              $self->{next_input_character} = shift @next_char; # reconsume
456              !!!back-next-input-character (@next_char);              !!!back-next-input-character (@next_char);
457              $self->{state} = 'data';              $self->{state} = DATA_STATE;
458              !!!emit ({type => 'character', data => '</'});              !!!emit ({type => CHARACTER_TOKEN, data => '</'});
459              redo A;              redo A;
460            } else {            } else {
461              $self->{next_input_character} = shift @next_char;              $self->{next_input_character} = shift @next_char;
# Line 405  sub _get_next_token ($) { Line 465  sub _get_next_token ($) {
465          } else {          } else {
466            ## No start tag token has ever been emitted            ## No start tag token has ever been emitted
467            # next-input-character is already done            # next-input-character is already done
468            $self->{state} = 'data';            $self->{state} = DATA_STATE;
469            !!!emit ({type => 'character', data => '</'});            !!!emit ({type => CHARACTER_TOKEN, data => '</'});
470            redo A;            redo A;
471          }          }
472        }        }
473                
474        if (0x0041 <= $self->{next_input_character} and        if (0x0041 <= $self->{next_input_character} and
475            $self->{next_input_character} <= 0x005A) { # A..Z            $self->{next_input_character} <= 0x005A) { # A..Z
476          $self->{current_token} = {type => 'end tag',          $self->{current_token} = {type => END_TAG_TOKEN,
477                            tag_name => chr ($self->{next_input_character} + 0x0020)};                            tag_name => chr ($self->{next_input_character} + 0x0020)};
478          $self->{state} = 'tag name';          $self->{state} = TAG_NAME_STATE;
479          !!!next-input-character;          !!!next-input-character;
480          redo A;          redo A;
481        } elsif (0x0061 <= $self->{next_input_character} and        } elsif (0x0061 <= $self->{next_input_character} and
482                 $self->{next_input_character} <= 0x007A) { # a..z                 $self->{next_input_character} <= 0x007A) { # a..z
483          $self->{current_token} = {type => 'end tag',          $self->{current_token} = {type => END_TAG_TOKEN,
484                            tag_name => chr ($self->{next_input_character})};                            tag_name => chr ($self->{next_input_character})};
485          $self->{state} = 'tag name';          $self->{state} = TAG_NAME_STATE;
486          !!!next-input-character;          !!!next-input-character;
487          redo A;          redo A;
488        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
489          !!!parse-error (type => 'empty end tag');          !!!parse-error (type => 'empty end tag');
490          $self->{state} = 'data';          $self->{state} = DATA_STATE;
491          !!!next-input-character;          !!!next-input-character;
492          redo A;          redo A;
493        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
494          !!!parse-error (type => 'bare etago');          !!!parse-error (type => 'bare etago');
495          $self->{state} = 'data';          $self->{state} = DATA_STATE;
496          # reconsume          # reconsume
497    
498          !!!emit ({type => 'character', data => '</'});          !!!emit ({type => CHARACTER_TOKEN, data => '</'});
499    
500          redo A;          redo A;
501        } else {        } else {
502          !!!parse-error (type => 'bogus end tag');          !!!parse-error (type => 'bogus end tag');
503          $self->{state} = 'bogus comment';          $self->{state} = BOGUS_COMMENT_STATE;
504          ## $self->{next_input_character} is intentionally left as is          ## $self->{next_input_character} is intentionally left as is
505          redo A;          redo A;
506        }        }
507      } elsif ($self->{state} eq 'tag name') {      } elsif ($self->{state} == TAG_NAME_STATE) {
508        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_input_character} == 0x0009 or # HT
509            $self->{next_input_character} == 0x000A or # LF            $self->{next_input_character} == 0x000A or # LF
510            $self->{next_input_character} == 0x000B or # VT            $self->{next_input_character} == 0x000B or # VT
511            $self->{next_input_character} == 0x000C or # FF            $self->{next_input_character} == 0x000C or # FF
512            $self->{next_input_character} == 0x0020) { # SP            $self->{next_input_character} == 0x0020) { # SP
513          $self->{state} = 'before attribute name';          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
514          !!!next-input-character;          !!!next-input-character;
515          redo A;          redo A;
516        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
517          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
518            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
519                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
520            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
521          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
522            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
523            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
524              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 466  sub _get_next_token ($) { Line 526  sub _get_next_token ($) {
526          } else {          } else {
527            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
528          }          }
529          $self->{state} = 'data';          $self->{state} = DATA_STATE;
530          !!!next-input-character;          !!!next-input-character;
531    
532          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
# Line 481  sub _get_next_token ($) { Line 541  sub _get_next_token ($) {
541          redo A;          redo A;
542        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
543          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
544          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
545            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
546                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
547            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
548          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
549            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
550            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
551              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 493  sub _get_next_token ($) { Line 553  sub _get_next_token ($) {
553          } else {          } else {
554            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
555          }          }
556          $self->{state} = 'data';          $self->{state} = DATA_STATE;
557          # reconsume          # reconsume
558    
559          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
# Line 502  sub _get_next_token ($) { Line 562  sub _get_next_token ($) {
562        } elsif ($self->{next_input_character} == 0x002F) { # /        } elsif ($self->{next_input_character} == 0x002F) { # /
563          !!!next-input-character;          !!!next-input-character;
564          if ($self->{next_input_character} == 0x003E and # >          if ($self->{next_input_character} == 0x003E and # >
565              $self->{current_token}->{type} eq 'start tag' and              $self->{current_token}->{type} == START_TAG_TOKEN and
566              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {
567            # permitted slash            # permitted slash
568            #            #
569          } else {          } else {
570            !!!parse-error (type => 'nestc');            !!!parse-error (type => 'nestc');
571          }          }
572          $self->{state} = 'before attribute name';          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
573          # next-input-character is already done          # next-input-character is already done
574          redo A;          redo A;
575        } else {        } else {
# Line 519  sub _get_next_token ($) { Line 579  sub _get_next_token ($) {
579          !!!next-input-character;          !!!next-input-character;
580          redo A;          redo A;
581        }        }
582      } elsif ($self->{state} eq 'before attribute name') {      } elsif ($self->{state} == BEFORE_ATTRIBUTE_NAME_STATE) {
583        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_input_character} == 0x0009 or # HT
584            $self->{next_input_character} == 0x000A or # LF            $self->{next_input_character} == 0x000A or # LF
585            $self->{next_input_character} == 0x000B or # VT            $self->{next_input_character} == 0x000B or # VT
# Line 529  sub _get_next_token ($) { Line 589  sub _get_next_token ($) {
589          !!!next-input-character;          !!!next-input-character;
590          redo A;          redo A;
591        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
592          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
593            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
594                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
595            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
596          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
597            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
598            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
599              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 541  sub _get_next_token ($) { Line 601  sub _get_next_token ($) {
601          } else {          } else {
602            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
603          }          }
604          $self->{state} = 'data';          $self->{state} = DATA_STATE;
605          !!!next-input-character;          !!!next-input-character;
606    
607          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
# Line 551  sub _get_next_token ($) { Line 611  sub _get_next_token ($) {
611                 $self->{next_input_character} <= 0x005A) { # A..Z                 $self->{next_input_character} <= 0x005A) { # A..Z
612          $self->{current_attribute} = {name => chr ($self->{next_input_character} + 0x0020),          $self->{current_attribute} = {name => chr ($self->{next_input_character} + 0x0020),
613                                value => ''};                                value => ''};
614          $self->{state} = 'attribute name';          $self->{state} = ATTRIBUTE_NAME_STATE;
615          !!!next-input-character;          !!!next-input-character;
616          redo A;          redo A;
617        } elsif ($self->{next_input_character} == 0x002F) { # /        } elsif ($self->{next_input_character} == 0x002F) { # /
618          !!!next-input-character;          !!!next-input-character;
619          if ($self->{next_input_character} == 0x003E and # >          if ($self->{next_input_character} == 0x003E and # >
620              $self->{current_token}->{type} eq 'start tag' and              $self->{current_token}->{type} == START_TAG_TOKEN and
621              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {
622            # permitted slash            # permitted slash
623            #            #
# Line 569  sub _get_next_token ($) { Line 629  sub _get_next_token ($) {
629          redo A;          redo A;
630        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
631          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
632          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
633            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
634                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
635            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
636          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
637            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
638            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
639              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 581  sub _get_next_token ($) { Line 641  sub _get_next_token ($) {
641          } else {          } else {
642            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
643          }          }
644          $self->{state} = 'data';          $self->{state} = DATA_STATE;
645          # reconsume          # reconsume
646    
647          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
# Line 590  sub _get_next_token ($) { Line 650  sub _get_next_token ($) {
650        } else {        } else {
651          $self->{current_attribute} = {name => chr ($self->{next_input_character}),          $self->{current_attribute} = {name => chr ($self->{next_input_character}),
652                                value => ''};                                value => ''};
653          $self->{state} = 'attribute name';          $self->{state} = ATTRIBUTE_NAME_STATE;
654          !!!next-input-character;          !!!next-input-character;
655          redo A;          redo A;
656        }        }
657      } elsif ($self->{state} eq 'attribute name') {      } elsif ($self->{state} == ATTRIBUTE_NAME_STATE) {
658        my $before_leave = sub {        my $before_leave = sub {
659          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
660              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
# Line 612  sub _get_next_token ($) { Line 672  sub _get_next_token ($) {
672            $self->{next_input_character} == 0x000C or # FF            $self->{next_input_character} == 0x000C or # FF
673            $self->{next_input_character} == 0x0020) { # SP            $self->{next_input_character} == 0x0020) { # SP
674          $before_leave->();          $before_leave->();
675          $self->{state} = 'after attribute name';          $self->{state} = AFTER_ATTRIBUTE_NAME_STATE;
676          !!!next-input-character;          !!!next-input-character;
677          redo A;          redo A;
678        } elsif ($self->{next_input_character} == 0x003D) { # =        } elsif ($self->{next_input_character} == 0x003D) { # =
679          $before_leave->();          $before_leave->();
680          $self->{state} = 'before attribute value';          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;
681          !!!next-input-character;          !!!next-input-character;
682          redo A;          redo A;
683        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
684          $before_leave->();          $before_leave->();
685          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
686            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
687                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
688            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
689          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
690            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
691            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
692              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 634  sub _get_next_token ($) { Line 694  sub _get_next_token ($) {
694          } else {          } else {
695            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
696          }          }
697          $self->{state} = 'data';          $self->{state} = DATA_STATE;
698          !!!next-input-character;          !!!next-input-character;
699    
700          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
# Line 650  sub _get_next_token ($) { Line 710  sub _get_next_token ($) {
710          $before_leave->();          $before_leave->();
711          !!!next-input-character;          !!!next-input-character;
712          if ($self->{next_input_character} == 0x003E and # >          if ($self->{next_input_character} == 0x003E and # >
713              $self->{current_token}->{type} eq 'start tag' and              $self->{current_token}->{type} == START_TAG_TOKEN and
714              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {
715            # permitted slash            # permitted slash
716            #            #
717          } else {          } else {
718            !!!parse-error (type => 'nestc');            !!!parse-error (type => 'nestc');
719          }          }
720          $self->{state} = 'before attribute name';          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
721          # next-input-character is already done          # next-input-character is already done
722          redo A;          redo A;
723        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
724          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
725          $before_leave->();          $before_leave->();
726          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
727            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
728                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
729            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
730          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
731            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
732            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
733              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 675  sub _get_next_token ($) { Line 735  sub _get_next_token ($) {
735          } else {          } else {
736            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
737          }          }
738          $self->{state} = 'data';          $self->{state} = DATA_STATE;
739          # reconsume          # reconsume
740    
741          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
# Line 687  sub _get_next_token ($) { Line 747  sub _get_next_token ($) {
747          !!!next-input-character;          !!!next-input-character;
748          redo A;          redo A;
749        }        }
750      } elsif ($self->{state} eq 'after attribute name') {      } elsif ($self->{state} == AFTER_ATTRIBUTE_NAME_STATE) {
751        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_input_character} == 0x0009 or # HT
752            $self->{next_input_character} == 0x000A or # LF            $self->{next_input_character} == 0x000A or # LF
753            $self->{next_input_character} == 0x000B or # VT            $self->{next_input_character} == 0x000B or # VT
# Line 697  sub _get_next_token ($) { Line 757  sub _get_next_token ($) {
757          !!!next-input-character;          !!!next-input-character;
758          redo A;          redo A;
759        } elsif ($self->{next_input_character} == 0x003D) { # =        } elsif ($self->{next_input_character} == 0x003D) { # =
760          $self->{state} = 'before attribute value';          $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;
761          !!!next-input-character;          !!!next-input-character;
762          redo A;          redo A;
763        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
764          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
765            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
766                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
767            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
768          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
769            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
770            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
771              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 713  sub _get_next_token ($) { Line 773  sub _get_next_token ($) {
773          } else {          } else {
774            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
775          }          }
776          $self->{state} = 'data';          $self->{state} = DATA_STATE;
777          !!!next-input-character;          !!!next-input-character;
778    
779          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
# Line 723  sub _get_next_token ($) { Line 783  sub _get_next_token ($) {
783                 $self->{next_input_character} <= 0x005A) { # A..Z                 $self->{next_input_character} <= 0x005A) { # A..Z
784          $self->{current_attribute} = {name => chr ($self->{next_input_character} + 0x0020),          $self->{current_attribute} = {name => chr ($self->{next_input_character} + 0x0020),
785                                value => ''};                                value => ''};
786          $self->{state} = 'attribute name';          $self->{state} = ATTRIBUTE_NAME_STATE;
787          !!!next-input-character;          !!!next-input-character;
788          redo A;          redo A;
789        } elsif ($self->{next_input_character} == 0x002F) { # /        } elsif ($self->{next_input_character} == 0x002F) { # /
790          !!!next-input-character;          !!!next-input-character;
791          if ($self->{next_input_character} == 0x003E and # >          if ($self->{next_input_character} == 0x003E and # >
792              $self->{current_token}->{type} eq 'start tag' and              $self->{current_token}->{type} == START_TAG_TOKEN and
793              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {              $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {
794            # permitted slash            # permitted slash
795            #            #
# Line 737  sub _get_next_token ($) { Line 797  sub _get_next_token ($) {
797            !!!parse-error (type => 'nestc');            !!!parse-error (type => 'nestc');
798            ## TODO: Different error type for <aa / bb> than <aa/>            ## TODO: Different error type for <aa / bb> than <aa/>
799          }          }
800          $self->{state} = 'before attribute name';          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
801          # next-input-character is already done          # next-input-character is already done
802          redo A;          redo A;
803        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
804          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
805          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
806            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
807                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
808            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
809          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
810            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
811            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
812              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 754  sub _get_next_token ($) { Line 814  sub _get_next_token ($) {
814          } else {          } else {
815            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
816          }          }
817          $self->{state} = 'data';          $self->{state} = DATA_STATE;
818          # reconsume          # reconsume
819    
820          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
# Line 763  sub _get_next_token ($) { Line 823  sub _get_next_token ($) {
823        } else {        } else {
824          $self->{current_attribute} = {name => chr ($self->{next_input_character}),          $self->{current_attribute} = {name => chr ($self->{next_input_character}),
825                                value => ''};                                value => ''};
826          $self->{state} = 'attribute name';          $self->{state} = ATTRIBUTE_NAME_STATE;
827          !!!next-input-character;          !!!next-input-character;
828          redo A;                  redo A;        
829        }        }
830      } elsif ($self->{state} eq 'before attribute value') {      } elsif ($self->{state} == BEFORE_ATTRIBUTE_VALUE_STATE) {
831        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_input_character} == 0x0009 or # HT
832            $self->{next_input_character} == 0x000A or # LF            $self->{next_input_character} == 0x000A or # LF
833            $self->{next_input_character} == 0x000B or # VT            $self->{next_input_character} == 0x000B or # VT
# Line 777  sub _get_next_token ($) { Line 837  sub _get_next_token ($) {
837          !!!next-input-character;          !!!next-input-character;
838          redo A;          redo A;
839        } elsif ($self->{next_input_character} == 0x0022) { # "        } elsif ($self->{next_input_character} == 0x0022) { # "
840          $self->{state} = 'attribute value (double-quoted)';          $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
841          !!!next-input-character;          !!!next-input-character;
842          redo A;          redo A;
843        } elsif ($self->{next_input_character} == 0x0026) { # &        } elsif ($self->{next_input_character} == 0x0026) { # &
844          $self->{state} = 'attribute value (unquoted)';          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
845          ## reconsume          ## reconsume
846          redo A;          redo A;
847        } elsif ($self->{next_input_character} == 0x0027) { # '        } elsif ($self->{next_input_character} == 0x0027) { # '
848          $self->{state} = 'attribute value (single-quoted)';          $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
849          !!!next-input-character;          !!!next-input-character;
850          redo A;          redo A;
851        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
852          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
853            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
854                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
855            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
856          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
857            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
858            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
859              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 801  sub _get_next_token ($) { Line 861  sub _get_next_token ($) {
861          } else {          } else {
862            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
863          }          }
864          $self->{state} = 'data';          $self->{state} = DATA_STATE;
865          !!!next-input-character;          !!!next-input-character;
866    
867          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
# Line 809  sub _get_next_token ($) { Line 869  sub _get_next_token ($) {
869          redo A;          redo A;
870        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
871          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
872          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
873            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
874                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
875            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
876          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
877            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
878            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
879              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 821  sub _get_next_token ($) { Line 881  sub _get_next_token ($) {
881          } else {          } else {
882            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
883          }          }
884          $self->{state} = 'data';          $self->{state} = DATA_STATE;
885          ## reconsume          ## reconsume
886    
887          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
# Line 829  sub _get_next_token ($) { Line 889  sub _get_next_token ($) {
889          redo A;          redo A;
890        } else {        } else {
891          $self->{current_attribute}->{value} .= chr ($self->{next_input_character});          $self->{current_attribute}->{value} .= chr ($self->{next_input_character});
892          $self->{state} = 'attribute value (unquoted)';          $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
893          !!!next-input-character;          !!!next-input-character;
894          redo A;          redo A;
895        }        }
896      } elsif ($self->{state} eq 'attribute value (double-quoted)') {      } elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) {
897        if ($self->{next_input_character} == 0x0022) { # "        if ($self->{next_input_character} == 0x0022) { # "
898          $self->{state} = 'before attribute name';          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
899          !!!next-input-character;          !!!next-input-character;
900          redo A;          redo A;
901        } elsif ($self->{next_input_character} == 0x0026) { # &        } elsif ($self->{next_input_character} == 0x0026) { # &
902          $self->{last_attribute_value_state} = 'attribute value (double-quoted)';          $self->{last_attribute_value_state} = $self->{state};
903          $self->{state} = 'entity in attribute value';          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;
904          !!!next-input-character;          !!!next-input-character;
905          redo A;          redo A;
906        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
907          !!!parse-error (type => 'unclosed attribute value');          !!!parse-error (type => 'unclosed attribute value');
908          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
909            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
910                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
911            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
912          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
913            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
914            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
915              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 857  sub _get_next_token ($) { Line 917  sub _get_next_token ($) {
917          } else {          } else {
918            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
919          }          }
920          $self->{state} = 'data';          $self->{state} = DATA_STATE;
921          ## reconsume          ## reconsume
922    
923          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
# Line 869  sub _get_next_token ($) { Line 929  sub _get_next_token ($) {
929          !!!next-input-character;          !!!next-input-character;
930          redo A;          redo A;
931        }        }
932      } elsif ($self->{state} eq 'attribute value (single-quoted)') {      } elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) {
933        if ($self->{next_input_character} == 0x0027) { # '        if ($self->{next_input_character} == 0x0027) { # '
934          $self->{state} = 'before attribute name';          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
935          !!!next-input-character;          !!!next-input-character;
936          redo A;          redo A;
937        } elsif ($self->{next_input_character} == 0x0026) { # &        } elsif ($self->{next_input_character} == 0x0026) { # &
938          $self->{last_attribute_value_state} = 'attribute value (single-quoted)';          $self->{last_attribute_value_state} = $self->{state};
939          $self->{state} = 'entity in attribute value';          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;
940          !!!next-input-character;          !!!next-input-character;
941          redo A;          redo A;
942        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
943          !!!parse-error (type => 'unclosed attribute value');          !!!parse-error (type => 'unclosed attribute value');
944          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
945            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
946                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
947            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
948          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
949            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
950            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
951              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 893  sub _get_next_token ($) { Line 953  sub _get_next_token ($) {
953          } else {          } else {
954            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
955          }          }
956          $self->{state} = 'data';          $self->{state} = DATA_STATE;
957          ## reconsume          ## reconsume
958    
959          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
# Line 905  sub _get_next_token ($) { Line 965  sub _get_next_token ($) {
965          !!!next-input-character;          !!!next-input-character;
966          redo A;          redo A;
967        }        }
968      } elsif ($self->{state} eq 'attribute value (unquoted)') {      } elsif ($self->{state} == ATTRIBUTE_VALUE_UNQUOTED_STATE) {
969        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_input_character} == 0x0009 or # HT
970            $self->{next_input_character} == 0x000A or # LF            $self->{next_input_character} == 0x000A or # LF
971            $self->{next_input_character} == 0x000B or # HT            $self->{next_input_character} == 0x000B or # HT
972            $self->{next_input_character} == 0x000C or # FF            $self->{next_input_character} == 0x000C or # FF
973            $self->{next_input_character} == 0x0020) { # SP            $self->{next_input_character} == 0x0020) { # SP
974          $self->{state} = 'before attribute name';          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
975          !!!next-input-character;          !!!next-input-character;
976          redo A;          redo A;
977        } elsif ($self->{next_input_character} == 0x0026) { # &        } elsif ($self->{next_input_character} == 0x0026) { # &
978          $self->{last_attribute_value_state} = 'attribute value (unquoted)';          $self->{last_attribute_value_state} = $self->{state};
979          $self->{state} = 'entity in attribute value';          $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE;
980          !!!next-input-character;          !!!next-input-character;
981          redo A;          redo A;
982        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
983          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
984            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
985                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
986            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
987          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
988            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
989            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
990              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 932  sub _get_next_token ($) { Line 992  sub _get_next_token ($) {
992          } else {          } else {
993            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
994          }          }
995          $self->{state} = 'data';          $self->{state} = DATA_STATE;
996          !!!next-input-character;          !!!next-input-character;
997    
998          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
# Line 940  sub _get_next_token ($) { Line 1000  sub _get_next_token ($) {
1000          redo A;          redo A;
1001        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1002          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1003          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1004            $self->{current_token}->{first_start_tag}            $self->{current_token}->{first_start_tag}
1005                = not defined $self->{last_emitted_start_tag_name};                = not defined $self->{last_emitted_start_tag_name};
1006            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1007          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1008            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1009            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
1010              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
# Line 952  sub _get_next_token ($) { Line 1012  sub _get_next_token ($) {
1012          } else {          } else {
1013            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
1014          }          }
1015          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1016          ## reconsume          ## reconsume
1017    
1018          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
# Line 964  sub _get_next_token ($) { Line 1024  sub _get_next_token ($) {
1024          !!!next-input-character;          !!!next-input-character;
1025          redo A;          redo A;
1026        }        }
1027      } elsif ($self->{state} eq 'entity in attribute value') {      } elsif ($self->{state} == ENTITY_IN_ATTRIBUTE_VALUE_STATE) {
1028        my $token = $self->_tokenize_attempt_to_consume_an_entity (1);        my $token = $self->_tokenize_attempt_to_consume_an_entity (1);
1029    
1030        unless (defined $token) {        unless (defined $token) {
# Line 977  sub _get_next_token ($) { Line 1037  sub _get_next_token ($) {
1037        $self->{state} = $self->{last_attribute_value_state};        $self->{state} = $self->{last_attribute_value_state};
1038        # next-input-character is already done        # next-input-character is already done
1039        redo A;        redo A;
1040      } elsif ($self->{state} eq 'bogus comment') {      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {
1041        ## (only happen if PCDATA state)        ## (only happen if PCDATA state)
1042                
1043        my $token = {type => 'comment', data => ''};        my $token = {type => COMMENT_TOKEN, data => ''};
1044    
1045        BC: {        BC: {
1046          if ($self->{next_input_character} == 0x003E) { # >          if ($self->{next_input_character} == 0x003E) { # >
1047            $self->{state} = 'data';            $self->{state} = DATA_STATE;
1048            !!!next-input-character;            !!!next-input-character;
1049    
1050            !!!emit ($token);            !!!emit ($token);
1051    
1052            redo A;            redo A;
1053          } elsif ($self->{next_input_character} == -1) {          } elsif ($self->{next_input_character} == -1) {
1054            $self->{state} = 'data';            $self->{state} = DATA_STATE;
1055            ## reconsume            ## reconsume
1056    
1057            !!!emit ($token);            !!!emit ($token);
# Line 1003  sub _get_next_token ($) { Line 1063  sub _get_next_token ($) {
1063            redo BC;            redo BC;
1064          }          }
1065        } # BC        } # BC
1066      } elsif ($self->{state} eq 'markup declaration open') {      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {
1067        ## (only happen if PCDATA state)        ## (only happen if PCDATA state)
1068    
1069        my @next_char;        my @next_char;
# Line 1013  sub _get_next_token ($) { Line 1073  sub _get_next_token ($) {
1073          !!!next-input-character;          !!!next-input-character;
1074          push @next_char, $self->{next_input_character};          push @next_char, $self->{next_input_character};
1075          if ($self->{next_input_character} == 0x002D) { # -          if ($self->{next_input_character} == 0x002D) { # -
1076            $self->{current_token} = {type => 'comment', data => ''};            $self->{current_token} = {type => COMMENT_TOKEN, data => ''};
1077            $self->{state} = 'comment start';            $self->{state} = COMMENT_START_STATE;
1078            !!!next-input-character;            !!!next-input-character;
1079            redo A;            redo A;
1080          }          }
# Line 1045  sub _get_next_token ($) { Line 1105  sub _get_next_token ($) {
1105                    if ($self->{next_input_character} == 0x0045 or # E                    if ($self->{next_input_character} == 0x0045 or # E
1106                        $self->{next_input_character} == 0x0065) { # e                        $self->{next_input_character} == 0x0065) { # e
1107                      ## ISSUE: What a stupid code this is!                      ## ISSUE: What a stupid code this is!
1108                      $self->{state} = 'DOCTYPE';                      $self->{state} = DOCTYPE_STATE;
1109                      !!!next-input-character;                      !!!next-input-character;
1110                      redo A;                      redo A;
1111                    }                    }
# Line 1059  sub _get_next_token ($) { Line 1119  sub _get_next_token ($) {
1119        !!!parse-error (type => 'bogus comment');        !!!parse-error (type => 'bogus comment');
1120        $self->{next_input_character} = shift @next_char;        $self->{next_input_character} = shift @next_char;
1121        !!!back-next-input-character (@next_char);        !!!back-next-input-character (@next_char);
1122        $self->{state} = 'bogus comment';        $self->{state} = BOGUS_COMMENT_STATE;
1123        redo A;        redo A;
1124                
1125        ## ISSUE: typos in spec: chacacters, is is a parse error        ## ISSUE: typos in spec: chacacters, is is a parse error
1126        ## ISSUE: spec is somewhat unclear on "is the first character that will be in the comment"; what is "that will be in the comment" is what the algorithm defines, isn't it?        ## ISSUE: spec is somewhat unclear on "is the first character that will be in the comment"; what is "that will be in the comment" is what the algorithm defines, isn't it?
1127      } elsif ($self->{state} eq 'comment start') {      } elsif ($self->{state} == COMMENT_START_STATE) {
1128        if ($self->{next_input_character} == 0x002D) { # -        if ($self->{next_input_character} == 0x002D) { # -
1129          $self->{state} = 'comment start dash';          $self->{state} = COMMENT_START_DASH_STATE;
1130          !!!next-input-character;          !!!next-input-character;
1131          redo A;          redo A;
1132        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
1133          !!!parse-error (type => 'bogus comment');          !!!parse-error (type => 'bogus comment');
1134          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1135          !!!next-input-character;          !!!next-input-character;
1136    
1137          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
# Line 1079  sub _get_next_token ($) { Line 1139  sub _get_next_token ($) {
1139          redo A;          redo A;
1140        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1141          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
1142          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1143          ## reconsume          ## reconsume
1144    
1145          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
# Line 1088  sub _get_next_token ($) { Line 1148  sub _get_next_token ($) {
1148        } else {        } else {
1149          $self->{current_token}->{data} # comment          $self->{current_token}->{data} # comment
1150              .= chr ($self->{next_input_character});              .= chr ($self->{next_input_character});
1151          $self->{state} = 'comment';          $self->{state} = COMMENT_STATE;
1152          !!!next-input-character;          !!!next-input-character;
1153          redo A;          redo A;
1154        }        }
1155      } elsif ($self->{state} eq 'comment start dash') {      } elsif ($self->{state} == COMMENT_START_DASH_STATE) {
1156        if ($self->{next_input_character} == 0x002D) { # -        if ($self->{next_input_character} == 0x002D) { # -
1157          $self->{state} = 'comment end';          $self->{state} = COMMENT_END_STATE;
1158          !!!next-input-character;          !!!next-input-character;
1159          redo A;          redo A;
1160        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
1161          !!!parse-error (type => 'bogus comment');          !!!parse-error (type => 'bogus comment');
1162          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1163          !!!next-input-character;          !!!next-input-character;
1164    
1165          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
# Line 1107  sub _get_next_token ($) { Line 1167  sub _get_next_token ($) {
1167          redo A;          redo A;
1168        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1169          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
1170          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1171          ## reconsume          ## reconsume
1172    
1173          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
# Line 1116  sub _get_next_token ($) { Line 1176  sub _get_next_token ($) {
1176        } else {        } else {
1177          $self->{current_token}->{data} # comment          $self->{current_token}->{data} # comment
1178              .= '-' . chr ($self->{next_input_character});              .= '-' . chr ($self->{next_input_character});
1179          $self->{state} = 'comment';          $self->{state} = COMMENT_STATE;
1180          !!!next-input-character;          !!!next-input-character;
1181          redo A;          redo A;
1182        }        }
1183      } elsif ($self->{state} eq 'comment') {      } elsif ($self->{state} == COMMENT_STATE) {
1184        if ($self->{next_input_character} == 0x002D) { # -        if ($self->{next_input_character} == 0x002D) { # -
1185          $self->{state} = 'comment end dash';          $self->{state} = COMMENT_END_DASH_STATE;
1186          !!!next-input-character;          !!!next-input-character;
1187          redo A;          redo A;
1188        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1189          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
1190          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1191          ## reconsume          ## reconsume
1192    
1193          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
# Line 1139  sub _get_next_token ($) { Line 1199  sub _get_next_token ($) {
1199          !!!next-input-character;          !!!next-input-character;
1200          redo A;          redo A;
1201        }        }
1202      } elsif ($self->{state} eq 'comment end dash') {      } elsif ($self->{state} == COMMENT_END_DASH_STATE) {
1203        if ($self->{next_input_character} == 0x002D) { # -        if ($self->{next_input_character} == 0x002D) { # -
1204          $self->{state} = 'comment end';          $self->{state} = COMMENT_END_STATE;
1205          !!!next-input-character;          !!!next-input-character;
1206          redo A;          redo A;
1207        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1208          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
1209          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1210          ## reconsume          ## reconsume
1211    
1212          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
# Line 1154  sub _get_next_token ($) { Line 1214  sub _get_next_token ($) {
1214          redo A;          redo A;
1215        } else {        } else {
1216          $self->{current_token}->{data} .= '-' . chr ($self->{next_input_character}); # comment          $self->{current_token}->{data} .= '-' . chr ($self->{next_input_character}); # comment
1217          $self->{state} = 'comment';          $self->{state} = COMMENT_STATE;
1218          !!!next-input-character;          !!!next-input-character;
1219          redo A;          redo A;
1220        }        }
1221      } elsif ($self->{state} eq 'comment end') {      } elsif ($self->{state} == COMMENT_END_STATE) {
1222        if ($self->{next_input_character} == 0x003E) { # >        if ($self->{next_input_character} == 0x003E) { # >
1223          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1224          !!!next-input-character;          !!!next-input-character;
1225    
1226          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
# Line 1174  sub _get_next_token ($) { Line 1234  sub _get_next_token ($) {
1234          redo A;          redo A;
1235        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1236          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
1237          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1238          ## reconsume          ## reconsume
1239    
1240          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
# Line 1183  sub _get_next_token ($) { Line 1243  sub _get_next_token ($) {
1243        } else {        } else {
1244          !!!parse-error (type => 'dash in comment');          !!!parse-error (type => 'dash in comment');
1245          $self->{current_token}->{data} .= '--' . chr ($self->{next_input_character}); # comment          $self->{current_token}->{data} .= '--' . chr ($self->{next_input_character}); # comment
1246          $self->{state} = 'comment';          $self->{state} = COMMENT_STATE;
1247          !!!next-input-character;          !!!next-input-character;
1248          redo A;          redo A;
1249        }        }
1250      } elsif ($self->{state} eq 'DOCTYPE') {      } elsif ($self->{state} == DOCTYPE_STATE) {
1251        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_input_character} == 0x0009 or # HT
1252            $self->{next_input_character} == 0x000A or # LF            $self->{next_input_character} == 0x000A or # LF
1253            $self->{next_input_character} == 0x000B or # VT            $self->{next_input_character} == 0x000B or # VT
1254            $self->{next_input_character} == 0x000C or # FF            $self->{next_input_character} == 0x000C or # FF
1255            $self->{next_input_character} == 0x0020) { # SP            $self->{next_input_character} == 0x0020) { # SP
1256          $self->{state} = 'before DOCTYPE name';          $self->{state} = BEFORE_DOCTYPE_NAME_STATE;
1257          !!!next-input-character;          !!!next-input-character;
1258          redo A;          redo A;
1259        } else {        } else {
1260          !!!parse-error (type => 'no space before DOCTYPE name');          !!!parse-error (type => 'no space before DOCTYPE name');
1261          $self->{state} = 'before DOCTYPE name';          $self->{state} = BEFORE_DOCTYPE_NAME_STATE;
1262          ## reconsume          ## reconsume
1263          redo A;          redo A;
1264        }        }
1265      } elsif ($self->{state} eq 'before DOCTYPE name') {      } elsif ($self->{state} == BEFORE_DOCTYPE_NAME_STATE) {
1266        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_input_character} == 0x0009 or # HT
1267            $self->{next_input_character} == 0x000A or # LF            $self->{next_input_character} == 0x000A or # LF
1268            $self->{next_input_character} == 0x000B or # VT            $self->{next_input_character} == 0x000B or # VT
# Line 1213  sub _get_next_token ($) { Line 1273  sub _get_next_token ($) {
1273          redo A;          redo A;
1274        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
1275          !!!parse-error (type => 'no DOCTYPE name');          !!!parse-error (type => 'no DOCTYPE name');
1276          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1277          !!!next-input-character;          !!!next-input-character;
1278    
1279          !!!emit ({type => 'DOCTYPE'}); # incorrect          !!!emit ({type => DOCTYPE_TOKEN}); # incorrect
1280    
1281          redo A;          redo A;
1282        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1283          !!!parse-error (type => 'no DOCTYPE name');          !!!parse-error (type => 'no DOCTYPE name');
1284          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1285          ## reconsume          ## reconsume
1286    
1287          !!!emit ({type => 'DOCTYPE'}); # incorrect          !!!emit ({type => DOCTYPE_TOKEN}); # incorrect
1288    
1289          redo A;          redo A;
1290        } else {        } else {
1291          $self->{current_token}          $self->{current_token}
1292              = {type => 'DOCTYPE',              = {type => DOCTYPE_TOKEN,
1293                 name => chr ($self->{next_input_character}),                 name => chr ($self->{next_input_character}),
1294                 correct => 1};                 correct => 1};
1295  ## ISSUE: "Set the token's name name to the" in the spec  ## ISSUE: "Set the token's name name to the" in the spec
1296          $self->{state} = 'DOCTYPE name';          $self->{state} = DOCTYPE_NAME_STATE;
1297          !!!next-input-character;          !!!next-input-character;
1298          redo A;          redo A;
1299        }        }
1300      } elsif ($self->{state} eq 'DOCTYPE name') {      } elsif ($self->{state} == DOCTYPE_NAME_STATE) {
1301  ## ISSUE: Redundant "First," in the spec.  ## ISSUE: Redundant "First," in the spec.
1302        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_input_character} == 0x0009 or # HT
1303            $self->{next_input_character} == 0x000A or # LF            $self->{next_input_character} == 0x000A or # LF
1304            $self->{next_input_character} == 0x000B or # VT            $self->{next_input_character} == 0x000B or # VT
1305            $self->{next_input_character} == 0x000C or # FF            $self->{next_input_character} == 0x000C or # FF
1306            $self->{next_input_character} == 0x0020) { # SP            $self->{next_input_character} == 0x0020) { # SP
1307          $self->{state} = 'after DOCTYPE name';          $self->{state} = AFTER_DOCTYPE_NAME_STATE;
1308          !!!next-input-character;          !!!next-input-character;
1309          redo A;          redo A;
1310        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
1311          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1312          !!!next-input-character;          !!!next-input-character;
1313    
1314          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
# Line 1256  sub _get_next_token ($) { Line 1316  sub _get_next_token ($) {
1316          redo A;          redo A;
1317        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1318          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
1319          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1320          ## reconsume          ## reconsume
1321    
1322          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
# Line 1270  sub _get_next_token ($) { Line 1330  sub _get_next_token ($) {
1330          !!!next-input-character;          !!!next-input-character;
1331          redo A;          redo A;
1332        }        }
1333      } elsif ($self->{state} eq 'after DOCTYPE name') {      } elsif ($self->{state} == AFTER_DOCTYPE_NAME_STATE) {
1334        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_input_character} == 0x0009 or # HT
1335            $self->{next_input_character} == 0x000A or # LF            $self->{next_input_character} == 0x000A or # LF
1336            $self->{next_input_character} == 0x000B or # VT            $self->{next_input_character} == 0x000B or # VT
# Line 1280  sub _get_next_token ($) { Line 1340  sub _get_next_token ($) {
1340          !!!next-input-character;          !!!next-input-character;
1341          redo A;          redo A;
1342        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
1343          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1344          !!!next-input-character;          !!!next-input-character;
1345    
1346          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
# Line 1288  sub _get_next_token ($) { Line 1348  sub _get_next_token ($) {
1348          redo A;          redo A;
1349        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1350          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
1351          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1352          ## reconsume          ## reconsume
1353    
1354          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
# Line 1312  sub _get_next_token ($) { Line 1372  sub _get_next_token ($) {
1372                  !!!next-input-character;                  !!!next-input-character;
1373                  if ($self->{next_input_character} == 0x0043 or # C                  if ($self->{next_input_character} == 0x0043 or # C
1374                      $self->{next_input_character} == 0x0063) { # c                      $self->{next_input_character} == 0x0063) { # c
1375                    $self->{state} = 'before DOCTYPE public identifier';                    $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
1376                    !!!next-input-character;                    !!!next-input-character;
1377                    redo A;                    redo A;
1378                  }                  }
# Line 1339  sub _get_next_token ($) { Line 1399  sub _get_next_token ($) {
1399                  !!!next-input-character;                  !!!next-input-character;
1400                  if ($self->{next_input_character} == 0x004D or # M                  if ($self->{next_input_character} == 0x004D or # M
1401                      $self->{next_input_character} == 0x006D) { # m                      $self->{next_input_character} == 0x006D) { # m
1402                    $self->{state} = 'before DOCTYPE system identifier';                    $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
1403                    !!!next-input-character;                    !!!next-input-character;
1404                    redo A;                    redo A;
1405                  }                  }
# Line 1355  sub _get_next_token ($) { Line 1415  sub _get_next_token ($) {
1415        }        }
1416    
1417        !!!parse-error (type => 'string after DOCTYPE name');        !!!parse-error (type => 'string after DOCTYPE name');
1418        $self->{state} = 'bogus DOCTYPE';        $self->{state} = BOGUS_DOCTYPE_STATE;
1419        # next-input-character is already done        # next-input-character is already done
1420        redo A;        redo A;
1421      } elsif ($self->{state} eq 'before DOCTYPE public identifier') {      } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {
1422        if ({        if ({
1423              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
1424              #0x000D => 1, # HT, LF, VT, FF, SP, CR              #0x000D => 1, # HT, LF, VT, FF, SP, CR
# Line 1368  sub _get_next_token ($) { Line 1428  sub _get_next_token ($) {
1428          redo A;          redo A;
1429        } elsif ($self->{next_input_character} eq 0x0022) { # "        } elsif ($self->{next_input_character} eq 0x0022) { # "
1430          $self->{current_token}->{public_identifier} = ''; # DOCTYPE          $self->{current_token}->{public_identifier} = ''; # DOCTYPE
1431          $self->{state} = 'DOCTYPE public identifier (double-quoted)';          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE;
1432          !!!next-input-character;          !!!next-input-character;
1433          redo A;          redo A;
1434        } elsif ($self->{next_input_character} eq 0x0027) { # '        } elsif ($self->{next_input_character} eq 0x0027) { # '
1435          $self->{current_token}->{public_identifier} = ''; # DOCTYPE          $self->{current_token}->{public_identifier} = ''; # DOCTYPE
1436          $self->{state} = 'DOCTYPE public identifier (single-quoted)';          $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE;
1437          !!!next-input-character;          !!!next-input-character;
1438          redo A;          redo A;
1439        } elsif ($self->{next_input_character} eq 0x003E) { # >        } elsif ($self->{next_input_character} eq 0x003E) { # >
1440          !!!parse-error (type => 'no PUBLIC literal');          !!!parse-error (type => 'no PUBLIC literal');
1441    
1442          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1443          !!!next-input-character;          !!!next-input-character;
1444    
1445          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
# Line 1389  sub _get_next_token ($) { Line 1449  sub _get_next_token ($) {
1449        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1450          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
1451    
1452          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1453          ## reconsume          ## reconsume
1454    
1455          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
# Line 1398  sub _get_next_token ($) { Line 1458  sub _get_next_token ($) {
1458          redo A;          redo A;
1459        } else {        } else {
1460          !!!parse-error (type => 'string after PUBLIC');          !!!parse-error (type => 'string after PUBLIC');
1461          $self->{state} = 'bogus DOCTYPE';          $self->{state} = BOGUS_DOCTYPE_STATE;
1462          !!!next-input-character;          !!!next-input-character;
1463          redo A;          redo A;
1464        }        }
1465      } elsif ($self->{state} eq 'DOCTYPE public identifier (double-quoted)') {      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE) {
1466        if ($self->{next_input_character} == 0x0022) { # "        if ($self->{next_input_character} == 0x0022) { # "
1467          $self->{state} = 'after DOCTYPE public identifier';          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
1468          !!!next-input-character;          !!!next-input-character;
1469          redo A;          redo A;
1470        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1471          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
1472    
1473          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1474          ## reconsume          ## reconsume
1475    
1476          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
# Line 1424  sub _get_next_token ($) { Line 1484  sub _get_next_token ($) {
1484          !!!next-input-character;          !!!next-input-character;
1485          redo A;          redo A;
1486        }        }
1487      } elsif ($self->{state} eq 'DOCTYPE public identifier (single-quoted)') {      } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE) {
1488        if ($self->{next_input_character} == 0x0027) { # '        if ($self->{next_input_character} == 0x0027) { # '
1489          $self->{state} = 'after DOCTYPE public identifier';          $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
1490          !!!next-input-character;          !!!next-input-character;
1491          redo A;          redo A;
1492        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1493          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
1494    
1495          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1496          ## reconsume          ## reconsume
1497    
1498          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
# Line 1446  sub _get_next_token ($) { Line 1506  sub _get_next_token ($) {
1506          !!!next-input-character;          !!!next-input-character;
1507          redo A;          redo A;
1508        }        }
1509      } elsif ($self->{state} eq 'after DOCTYPE public identifier') {      } elsif ($self->{state} == AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {
1510        if ({        if ({
1511              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
1512              #0x000D => 1, # HT, LF, VT, FF, SP, CR              #0x000D => 1, # HT, LF, VT, FF, SP, CR
# Line 1456  sub _get_next_token ($) { Line 1516  sub _get_next_token ($) {
1516          redo A;          redo A;
1517        } elsif ($self->{next_input_character} == 0x0022) { # "        } elsif ($self->{next_input_character} == 0x0022) { # "
1518          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{current_token}->{system_identifier} = ''; # DOCTYPE
1519          $self->{state} = 'DOCTYPE system identifier (double-quoted)';          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;
1520          !!!next-input-character;          !!!next-input-character;
1521          redo A;          redo A;
1522        } elsif ($self->{next_input_character} == 0x0027) { # '        } elsif ($self->{next_input_character} == 0x0027) { # '
1523          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{current_token}->{system_identifier} = ''; # DOCTYPE
1524          $self->{state} = 'DOCTYPE system identifier (single-quoted)';          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;
1525          !!!next-input-character;          !!!next-input-character;
1526          redo A;          redo A;
1527        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
1528          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1529          !!!next-input-character;          !!!next-input-character;
1530    
1531          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
# Line 1474  sub _get_next_token ($) { Line 1534  sub _get_next_token ($) {
1534        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1535          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
1536    
1537          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1538          ## reconsume          ## reconsume
1539    
1540          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
# Line 1483  sub _get_next_token ($) { Line 1543  sub _get_next_token ($) {
1543          redo A;          redo A;
1544        } else {        } else {
1545          !!!parse-error (type => 'string after PUBLIC literal');          !!!parse-error (type => 'string after PUBLIC literal');
1546          $self->{state} = 'bogus DOCTYPE';          $self->{state} = BOGUS_DOCTYPE_STATE;
1547          !!!next-input-character;          !!!next-input-character;
1548          redo A;          redo A;
1549        }        }
1550      } elsif ($self->{state} eq 'before DOCTYPE system identifier') {      } elsif ($self->{state} == BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE) {
1551        if ({        if ({
1552              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
1553              #0x000D => 1, # HT, LF, VT, FF, SP, CR              #0x000D => 1, # HT, LF, VT, FF, SP, CR
# Line 1497  sub _get_next_token ($) { Line 1557  sub _get_next_token ($) {
1557          redo A;          redo A;
1558        } elsif ($self->{next_input_character} == 0x0022) { # "        } elsif ($self->{next_input_character} == 0x0022) { # "
1559          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{current_token}->{system_identifier} = ''; # DOCTYPE
1560          $self->{state} = 'DOCTYPE system identifier (double-quoted)';          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;
1561          !!!next-input-character;          !!!next-input-character;
1562          redo A;          redo A;
1563        } elsif ($self->{next_input_character} == 0x0027) { # '        } elsif ($self->{next_input_character} == 0x0027) { # '
1564          $self->{current_token}->{system_identifier} = ''; # DOCTYPE          $self->{current_token}->{system_identifier} = ''; # DOCTYPE
1565          $self->{state} = 'DOCTYPE system identifier (single-quoted)';          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;
1566          !!!next-input-character;          !!!next-input-character;
1567          redo A;          redo A;
1568        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
1569          !!!parse-error (type => 'no SYSTEM literal');          !!!parse-error (type => 'no SYSTEM literal');
1570          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1571          !!!next-input-character;          !!!next-input-character;
1572    
1573          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
# Line 1517  sub _get_next_token ($) { Line 1577  sub _get_next_token ($) {
1577        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1578          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
1579    
1580          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1581          ## reconsume          ## reconsume
1582    
1583          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
# Line 1526  sub _get_next_token ($) { Line 1586  sub _get_next_token ($) {
1586          redo A;          redo A;
1587        } else {        } else {
1588          !!!parse-error (type => 'string after SYSTEM');          !!!parse-error (type => 'string after SYSTEM');
1589          $self->{state} = 'bogus DOCTYPE';          $self->{state} = BOGUS_DOCTYPE_STATE;
1590          !!!next-input-character;          !!!next-input-character;
1591          redo A;          redo A;
1592        }        }
1593      } elsif ($self->{state} eq 'DOCTYPE system identifier (double-quoted)') {      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE) {
1594        if ($self->{next_input_character} == 0x0022) { # "        if ($self->{next_input_character} == 0x0022) { # "
1595          $self->{state} = 'after DOCTYPE system identifier';          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
1596          !!!next-input-character;          !!!next-input-character;
1597          redo A;          redo A;
1598        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1599          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
1600    
1601          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1602          ## reconsume          ## reconsume
1603    
1604          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
# Line 1552  sub _get_next_token ($) { Line 1612  sub _get_next_token ($) {
1612          !!!next-input-character;          !!!next-input-character;
1613          redo A;          redo A;
1614        }        }
1615      } elsif ($self->{state} eq 'DOCTYPE system identifier (single-quoted)') {      } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE) {
1616        if ($self->{next_input_character} == 0x0027) { # '        if ($self->{next_input_character} == 0x0027) { # '
1617          $self->{state} = 'after DOCTYPE system identifier';          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
1618          !!!next-input-character;          !!!next-input-character;
1619          redo A;          redo A;
1620        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1621          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
1622    
1623          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1624          ## reconsume          ## reconsume
1625    
1626          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
# Line 1574  sub _get_next_token ($) { Line 1634  sub _get_next_token ($) {
1634          !!!next-input-character;          !!!next-input-character;
1635          redo A;          redo A;
1636        }        }
1637      } elsif ($self->{state} eq 'after DOCTYPE system identifier') {      } elsif ($self->{state} == AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE) {
1638        if ({        if ({
1639              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,              0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
1640              #0x000D => 1, # HT, LF, VT, FF, SP, CR              #0x000D => 1, # HT, LF, VT, FF, SP, CR
# Line 1583  sub _get_next_token ($) { Line 1643  sub _get_next_token ($) {
1643          !!!next-input-character;          !!!next-input-character;
1644          redo A;          redo A;
1645        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
1646          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1647          !!!next-input-character;          !!!next-input-character;
1648    
1649          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
# Line 1592  sub _get_next_token ($) { Line 1652  sub _get_next_token ($) {
1652        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1653          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
1654    
1655          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1656          ## reconsume          ## reconsume
1657    
1658          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
# Line 1601  sub _get_next_token ($) { Line 1661  sub _get_next_token ($) {
1661          redo A;          redo A;
1662        } else {        } else {
1663          !!!parse-error (type => 'string after SYSTEM literal');          !!!parse-error (type => 'string after SYSTEM literal');
1664          $self->{state} = 'bogus DOCTYPE';          $self->{state} = BOGUS_DOCTYPE_STATE;
1665          !!!next-input-character;          !!!next-input-character;
1666          redo A;          redo A;
1667        }        }
1668      } elsif ($self->{state} eq 'bogus DOCTYPE') {      } elsif ($self->{state} == BOGUS_DOCTYPE_STATE) {
1669        if ($self->{next_input_character} == 0x003E) { # >        if ($self->{next_input_character} == 0x003E) { # >
1670          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1671          !!!next-input-character;          !!!next-input-character;
1672    
1673          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
# Line 1616  sub _get_next_token ($) { Line 1676  sub _get_next_token ($) {
1676          redo A;          redo A;
1677        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1678          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
1679          $self->{state} = 'data';          $self->{state} = DATA_STATE;
1680          ## reconsume          ## reconsume
1681    
1682          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
# Line 1697  sub _tokenize_attempt_to_consume_an_enti Line 1757  sub _tokenize_attempt_to_consume_an_enti
1757            $code = $c1_entity_char->{$code};            $code = $c1_entity_char->{$code};
1758          }          }
1759    
1760          return {type => 'character', data => chr $code};          return {type => CHARACTER_TOKEN, data => chr $code};
1761        } # X        } # X
1762      } elsif (0x0030 <= $self->{next_input_character} and      } elsif (0x0030 <= $self->{next_input_character} and
1763               $self->{next_input_character} <= 0x0039) { # 0..9               $self->{next_input_character} <= 0x0039) { # 0..9
# Line 1732  sub _tokenize_attempt_to_consume_an_enti Line 1792  sub _tokenize_attempt_to_consume_an_enti
1792          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
1793        }        }
1794                
1795        return {type => 'character', data => chr $code};        return {type => CHARACTER_TOKEN, data => chr $code};
1796      } else {      } else {
1797        !!!parse-error (type => 'bare nero');        !!!parse-error (type => 'bare nero');
1798        !!!back-next-input-character ($self->{next_input_character});        !!!back-next-input-character ($self->{next_input_character});
# Line 1780  sub _tokenize_attempt_to_consume_an_enti Line 1840  sub _tokenize_attempt_to_consume_an_enti
1840      }      }
1841            
1842      if ($match > 0) {      if ($match > 0) {
1843        return {type => 'character', data => $value};        return {type => CHARACTER_TOKEN, data => $value};
1844      } elsif ($match < 0) {      } elsif ($match < 0) {
1845        !!!parse-error (type => 'no refc');        !!!parse-error (type => 'no refc');
1846        if ($in_attr and $match < -1) {        if ($in_attr and $match < -1) {
1847          return {type => 'character', data => '&'.$entity_name};          return {type => CHARACTER_TOKEN, data => '&'.$entity_name};
1848        } else {        } else {
1849          return {type => 'character', data => $value};          return {type => CHARACTER_TOKEN, data => $value};
1850        }        }
1851      } else {      } else {
1852        !!!parse-error (type => 'bare ero');        !!!parse-error (type => 'bare ero');
1853        ## NOTE: No characters are consumed in the spec.        ## NOTE: No characters are consumed in the spec.
1854        return {type => 'character', data => '&'.$value};        return {type => CHARACTER_TOKEN, data => '&'.$value};
1855      }      }
1856    } else {    } else {
1857      ## no characters are consumed      ## no characters are consumed
# Line 1847  sub _construct_tree ($) { Line 1907  sub _construct_tree ($) {
1907  sub _tree_construction_initial ($) {  sub _tree_construction_initial ($) {
1908    my $self = shift;    my $self = shift;
1909    INITIAL: {    INITIAL: {
1910      if ($token->{type} eq 'DOCTYPE') {      if ($token->{type} == DOCTYPE_TOKEN) {
1911        ## NOTE: Conformance checkers MAY, instead of reporting "not HTML5"        ## NOTE: Conformance checkers MAY, instead of reporting "not HTML5"
1912        ## error, switch to a conformance checking mode for another        ## error, switch to a conformance checking mode for another
1913        ## language.        ## language.
# Line 1974  sub _tree_construction_initial ($) { Line 2034  sub _tree_construction_initial ($) {
2034        !!!next-token;        !!!next-token;
2035        return;        return;
2036      } elsif ({      } elsif ({
2037                'start tag' => 1,                START_TAG_TOKEN, 1,
2038                'end tag' => 1,                END_TAG_TOKEN, 1,
2039                'end-of-file' => 1,                END_OF_FILE_TOKEN, 1,
2040               }->{$token->{type}}) {               }->{$token->{type}}) {
2041        !!!parse-error (type => 'no DOCTYPE');        !!!parse-error (type => 'no DOCTYPE');
2042        $self->{document}->manakai_compat_mode ('quirks');        $self->{document}->manakai_compat_mode ('quirks');
2043        ## Go to the root element phase        ## Go to the root element phase
2044        ## reprocess        ## reprocess
2045        return;        return;
2046      } elsif ($token->{type} eq 'character') {      } elsif ($token->{type} == CHARACTER_TOKEN) {
2047        if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D        if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D
2048          ## Ignore the token          ## Ignore the token
2049    
# Line 1999  sub _tree_construction_initial ($) { Line 2059  sub _tree_construction_initial ($) {
2059        ## Go to the root element phase        ## Go to the root element phase
2060        ## reprocess        ## reprocess
2061        return;        return;
2062      } elsif ($token->{type} eq 'comment') {      } elsif ($token->{type} == COMMENT_TOKEN) {
2063        my $comment = $self->{document}->create_comment ($token->{data});        my $comment = $self->{document}->create_comment ($token->{data});
2064        $self->{document}->append_child ($comment);        $self->{document}->append_child ($comment);
2065                
# Line 2007  sub _tree_construction_initial ($) { Line 2067  sub _tree_construction_initial ($) {
2067        !!!next-token;        !!!next-token;
2068        redo INITIAL;        redo INITIAL;
2069      } else {      } else {
2070        die "$0: $token->{type}: Unknown token";        die "$0: $token->{type}: Unknown token type";
2071      }      }
2072    } # INITIAL    } # INITIAL
2073  } # _tree_construction_initial  } # _tree_construction_initial
# Line 2016  sub _tree_construction_root_element ($) Line 2076  sub _tree_construction_root_element ($)
2076    my $self = shift;    my $self = shift;
2077        
2078    B: {    B: {
2079        if ($token->{type} eq 'DOCTYPE') {        if ($token->{type} == DOCTYPE_TOKEN) {
2080          !!!parse-error (type => 'in html:#DOCTYPE');          !!!parse-error (type => 'in html:#DOCTYPE');
2081          ## Ignore the token          ## Ignore the token
2082          ## Stay in the phase          ## Stay in the phase
2083          !!!next-token;          !!!next-token;
2084          redo B;          redo B;
2085        } elsif ($token->{type} eq 'comment') {        } elsif ($token->{type} == COMMENT_TOKEN) {
2086          my $comment = $self->{document}->create_comment ($token->{data});          my $comment = $self->{document}->create_comment ($token->{data});
2087          $self->{document}->append_child ($comment);          $self->{document}->append_child ($comment);
2088          ## Stay in the phase          ## Stay in the phase
2089          !!!next-token;          !!!next-token;
2090          redo B;          redo B;
2091        } elsif ($token->{type} eq 'character') {        } elsif ($token->{type} == CHARACTER_TOKEN) {
2092          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D
2093            ## Ignore the token.            ## Ignore the token.
2094    
# Line 2038  sub _tree_construction_root_element ($) Line 2098  sub _tree_construction_root_element ($)
2098              redo B;              redo B;
2099            }            }
2100          }          }
2101    
2102            $self->{application_cache_selection}->(undef);
2103    
2104            #
2105          } elsif ($token->{type} == START_TAG_TOKEN) {
2106            if ($token->{tag_name} eq 'html' and
2107                $token->{attributes}->{manifest}) { ## ISSUE: Spec spells as "application"
2108              $self->{application_cache_selection}
2109                   ->($token->{attributes}->{manifest}->{value});
2110              ## ISSUE: No relative reference resolution?
2111            } else {
2112              $self->{application_cache_selection}->(undef);
2113            }
2114    
2115            ## ISSUE: There is an issue in the spec
2116          #          #
2117        } elsif ({        } elsif ({
2118                  'start tag' => 1,                  END_TAG_TOKEN, 1,
2119                  'end tag' => 1,                  END_OF_FILE_TOKEN, 1,
                 'end-of-file' => 1,  
2120                 }->{$token->{type}}) {                 }->{$token->{type}}) {
2121            $self->{application_cache_selection}->(undef);
2122    
2123          ## ISSUE: There is an issue in the spec          ## ISSUE: There is an issue in the spec
2124          #          #
2125        } else {        } else {
2126          die "$0: $token->{type}: Unknown token";          die "$0: $token->{type}: Unknown token type";
2127        }        }
2128    
2129        my $root_element; !!!create-element ($root_element, 'html');        my $root_element; !!!create-element ($root_element, 'html');
2130        $self->{document}->append_child ($root_element);        $self->{document}->append_child ($root_element);
2131        push @{$self->{open_elements}}, [$root_element, 'html'];        push @{$self->{open_elements}}, [$root_element, 'html'];
# Line 2230  sub _tree_construction_main ($) { Line 2307  sub _tree_construction_main ($) {
2307      ## Step 4      ## Step 4
2308      my $text = '';      my $text = '';
2309      !!!next-token;      !!!next-token;
2310      while ($token->{type} eq 'character') { # or until stop tokenizing      while ($token->{type} == CHARACTER_TOKEN) { # or until stop tokenizing
2311        $text .= $token->{data};        $text .= $token->{data};
2312        !!!next-token;        !!!next-token;
2313      }      }
# Line 2245  sub _tree_construction_main ($) { Line 2322  sub _tree_construction_main ($) {
2322      $self->{content_model} = PCDATA_CONTENT_MODEL;      $self->{content_model} = PCDATA_CONTENT_MODEL;
2323    
2324      ## Step 7      ## Step 7
2325      if ($token->{type} eq 'end tag' and $token->{tag_name} eq $start_tag_name) {      if ($token->{type} == END_TAG_TOKEN and $token->{tag_name} eq $start_tag_name) {
2326        ## Ignore the token        ## Ignore the token
2327      } elsif ($content_model_flag == CDATA_CONTENT_MODEL) {      } elsif ($content_model_flag == CDATA_CONTENT_MODEL) {
2328        !!!parse-error (type => 'in CDATA:#'.$token->{type});        !!!parse-error (type => 'in CDATA:#'.$token->{type});
# Line 2268  sub _tree_construction_main ($) { Line 2345  sub _tree_construction_main ($) {
2345            
2346      my $text = '';      my $text = '';
2347      !!!next-token;      !!!next-token;
2348      while ($token->{type} eq 'character') {      while ($token->{type} == CHARACTER_TOKEN) {
2349        $text .= $token->{data};        $text .= $token->{data};
2350        !!!next-token;        !!!next-token;
2351      } # stop if non-character token or tokenizer stops tokenising      } # stop if non-character token or tokenizer stops tokenising
# Line 2278  sub _tree_construction_main ($) { Line 2355  sub _tree_construction_main ($) {
2355                                
2356      $self->{content_model} = PCDATA_CONTENT_MODEL;      $self->{content_model} = PCDATA_CONTENT_MODEL;
2357    
2358      if ($token->{type} eq 'end tag' and      if ($token->{type} == END_TAG_TOKEN and
2359          $token->{tag_name} eq 'script') {          $token->{tag_name} eq 'script') {
2360        ## Ignore the token        ## Ignore the token
2361      } else {      } else {
# Line 2524  sub _tree_construction_main ($) { Line 2601  sub _tree_construction_main ($) {
2601    my $insert;    my $insert;
2602    
2603    B: {    B: {
2604      if ($token->{type} eq 'DOCTYPE') {      if ($token->{type} == DOCTYPE_TOKEN) {
2605        !!!parse-error (type => 'DOCTYPE in the middle');        !!!parse-error (type => 'DOCTYPE in the middle');
2606        ## Ignore the token        ## Ignore the token
2607        ## Stay in the phase        ## Stay in the phase
2608        !!!next-token;        !!!next-token;
2609        redo B;        redo B;
2610      } elsif ($token->{type} eq 'end-of-file') {      } elsif ($token->{type} == END_OF_FILE_TOKEN) {
2611        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM or        if ($self->{insertion_mode} & AFTER_HTML_IMS) {
           $self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {  
2612          #          #
2613        } else {        } else {
2614          ## Generate implied end tags          ## Generate implied end tags
# Line 2541  sub _tree_construction_main ($) { Line 2617  sub _tree_construction_main ($) {
2617               tbody => 1, tfoot=> 1, thead => 1,               tbody => 1, tfoot=> 1, thead => 1,
2618              }->{$self->{open_elements}->[-1]->[1]}) {              }->{$self->{open_elements}->[-1]->[1]}) {
2619            !!!back-token;            !!!back-token;
2620            $token = {type => 'end tag', tag_name => $self->{open_elements}->[-1]->[1]};            $token = {type => END_TAG_TOKEN, tag_name => $self->{open_elements}->[-1]->[1]};
2621            redo B;            redo B;
2622          }          }
2623                    
# Line 2559  sub _tree_construction_main ($) { Line 2635  sub _tree_construction_main ($) {
2635    
2636        ## Stop parsing        ## Stop parsing
2637        last B;        last B;
2638      } elsif ($token->{type} eq 'start tag' and      } elsif ($token->{type} == START_TAG_TOKEN and
2639               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
2640        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
2641          ## Turn into the main phase          ## Turn into the main phase
# Line 2586  sub _tree_construction_main ($) { Line 2662  sub _tree_construction_main ($) {
2662        }        }
2663        !!!next-token;        !!!next-token;
2664        redo B;        redo B;
2665      } elsif ($token->{type} eq 'comment') {      } elsif ($token->{type} == COMMENT_TOKEN) {
2666        my $comment = $self->{document}->create_comment ($token->{data});        my $comment = $self->{document}->create_comment ($token->{data});
2667        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM or        if ($self->{insertion_mode} & AFTER_HTML_IMS) {
           $self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {  
2668          $self->{document}->append_child ($comment);          $self->{document}->append_child ($comment);
2669        } elsif ($self->{insertion_mode} == AFTER_BODY_IM) {        } elsif ($self->{insertion_mode} == AFTER_BODY_IM) {
2670          $self->{open_elements}->[0]->[0]->append_child ($comment);          $self->{open_elements}->[0]->[0]->append_child ($comment);
# Line 2598  sub _tree_construction_main ($) { Line 2673  sub _tree_construction_main ($) {
2673        }        }
2674        !!!next-token;        !!!next-token;
2675        redo B;        redo B;
2676      } elsif ($self->{insertion_mode} == IN_HEAD_IM or      } elsif ($self->{insertion_mode} & HEAD_IMS) {
2677               $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM or        if ($token->{type} == CHARACTER_TOKEN) {
              $self->{insertion_mode} == AFTER_HEAD_IM or  
              $self->{insertion_mode} == BEFORE_HEAD_IM) {  
       if ($token->{type} eq 'character') {  
2678          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
2679            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
2680            unless (length $token->{data}) {            unless (length $token->{data}) {
# Line 2643  sub _tree_construction_main ($) { Line 2715  sub _tree_construction_main ($) {
2715              $self->{insertion_mode} = IN_BODY_IM;              $self->{insertion_mode} = IN_BODY_IM;
2716              ## reprocess              ## reprocess
2717              redo B;              redo B;
2718            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} == START_TAG_TOKEN) {
2719              if ($token->{tag_name} eq 'head') {              if ($token->{tag_name} eq 'head') {
2720                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
2721                  !!!create-element ($self->{head_element}, $token->{tag_name}, $token->{attributes});                  !!!create-element ($self->{head_element}, $token->{tag_name}, $token->{attributes});
# Line 2856  sub _tree_construction_main ($) { Line 2928  sub _tree_construction_main ($) {
2928              $self->{insertion_mode} = IN_BODY_IM;              $self->{insertion_mode} = IN_BODY_IM;
2929              ## reprocess              ## reprocess
2930              redo B;              redo B;
2931            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} == END_TAG_TOKEN) {
2932              if ($token->{tag_name} eq 'head') {              if ($token->{tag_name} eq 'head') {
2933                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
2934                  ## As if <head>                  ## As if <head>
# Line 2978  sub _tree_construction_main ($) { Line 3050  sub _tree_construction_main ($) {
3050            }            }
3051    
3052            ## ISSUE: An issue in the spec.            ## ISSUE: An issue in the spec.
3053      } elsif ($self->{insertion_mode} == IN_BODY_IM or      } elsif ($self->{insertion_mode} & BODY_IMS) {
3054               $self->{insertion_mode} == IN_CELL_IM or            if ($token->{type} == CHARACTER_TOKEN) {
              $self->{insertion_mode} == IN_CAPTION_IM) {  
           if ($token->{type} eq 'character') {  
3055              ## NOTE: There is a code clone of "character in body".              ## NOTE: There is a code clone of "character in body".
3056              $reconstruct_active_formatting_elements->($insert_to_current);              $reconstruct_active_formatting_elements->($insert_to_current);
3057                            
# Line 2989  sub _tree_construction_main ($) { Line 3059  sub _tree_construction_main ($) {
3059    
3060              !!!next-token;              !!!next-token;
3061              redo B;              redo B;
3062            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} == START_TAG_TOKEN) {
3063              if ({              if ({
3064                   caption => 1, col => 1, colgroup => 1, tbody => 1,                   caption => 1, col => 1, colgroup => 1, tbody => 1,
3065                   td => 1, tfoot => 1, th => 1, thead => 1, tr => 1,                   td => 1, tfoot => 1, th => 1, thead => 1, tr => 1,
# Line 3017  sub _tree_construction_main ($) { Line 3087  sub _tree_construction_main ($) {
3087                                    
3088                  ## Close the cell                  ## Close the cell
3089                  !!!back-token; # <?>                  !!!back-token; # <?>
3090                  $token = {type => 'end tag', tag_name => $tn};                  $token = {type => END_TAG_TOKEN, tag_name => $tn};
3091                  redo B;                  redo B;
3092                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
3093                  !!!parse-error (type => 'not closed:caption');                  !!!parse-error (type => 'not closed:caption');
# Line 3050  sub _tree_construction_main ($) { Line 3120  sub _tree_construction_main ($) {
3120                       tbody => 1, tfoot=> 1, thead => 1,                       tbody => 1, tfoot=> 1, thead => 1,
3121                      }->{$self->{open_elements}->[-1]->[1]}) {                      }->{$self->{open_elements}->[-1]->[1]}) {
3122                    !!!back-token; # <?>                    !!!back-token; # <?>
3123                    $token = {type => 'end tag', tag_name => 'caption'};                    $token = {type => END_TAG_TOKEN, tag_name => 'caption'};
3124                    !!!back-token;                    !!!back-token;
3125                    $token = {type => 'end tag',                    $token = {type => END_TAG_TOKEN,
3126                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3127                    redo B;                    redo B;
3128                  }                  }
# Line 3075  sub _tree_construction_main ($) { Line 3145  sub _tree_construction_main ($) {
3145              } else {              } else {
3146                #                #
3147              }              }
3148            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} == END_TAG_TOKEN) {
3149              if ($token->{tag_name} eq 'td' or $token->{tag_name} eq 'th') {              if ($token->{tag_name} eq 'td' or $token->{tag_name} eq 'th') {
3150                if ($self->{insertion_mode} == IN_CELL_IM) {                if ($self->{insertion_mode} == IN_CELL_IM) {
3151                  ## have an element in table scope                  ## have an element in table scope
# Line 3107  sub _tree_construction_main ($) { Line 3177  sub _tree_construction_main ($) {
3177                       tbody => 1, tfoot=> 1, thead => 1,                       tbody => 1, tfoot=> 1, thead => 1,
3178                      }->{$self->{open_elements}->[-1]->[1]}) {                      }->{$self->{open_elements}->[-1]->[1]}) {
3179                    !!!back-token;                    !!!back-token;
3180                    $token = {type => 'end tag',                    $token = {type => END_TAG_TOKEN,
3181                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3182                    redo B;                    redo B;
3183                  }                  }
# Line 3161  sub _tree_construction_main ($) { Line 3231  sub _tree_construction_main ($) {
3231                       tbody => 1, tfoot=> 1, thead => 1,                       tbody => 1, tfoot=> 1, thead => 1,
3232                      }->{$self->{open_elements}->[-1]->[1]}) {                      }->{$self->{open_elements}->[-1]->[1]}) {
3233                    !!!back-token;                    !!!back-token;
3234                    $token = {type => 'end tag',                    $token = {type => END_TAG_TOKEN,
3235                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3236                    redo B;                    redo B;
3237                  }                  }
# Line 3218  sub _tree_construction_main ($) { Line 3288  sub _tree_construction_main ($) {
3288    
3289                ## Close the cell                ## Close the cell
3290                !!!back-token; # </?>                !!!back-token; # </?>
3291                $token = {type => 'end tag', tag_name => $tn};                $token = {type => END_TAG_TOKEN, tag_name => $tn};
3292                redo B;                redo B;
3293              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
3294                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
# Line 3252  sub _tree_construction_main ($) { Line 3322  sub _tree_construction_main ($) {
3322                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
3323                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
3324                  !!!back-token; # </table>                  !!!back-token; # </table>
3325                  $token = {type => 'end tag', tag_name => 'caption'};                  $token = {type => END_TAG_TOKEN, tag_name => 'caption'};
3326                  !!!back-token;                  !!!back-token;
3327                  $token = {type => 'end tag',                  $token = {type => END_TAG_TOKEN,
3328                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3329                  redo B;                  redo B;
3330                }                }
# Line 3274  sub _tree_construction_main ($) { Line 3344  sub _tree_construction_main ($) {
3344              } elsif ({              } elsif ({
3345                        body => 1, col => 1, colgroup => 1, html => 1,                        body => 1, col => 1, colgroup => 1, html => 1,
3346                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
3347                if ($self->{insertion_mode} == IN_CELL_IM or                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
                   $self->{insertion_mode} == IN_CAPTION_IM) {  
3348                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3349                  ## Ignore the token                  ## Ignore the token
3350                  !!!next-token;                  !!!next-token;
# Line 3301  sub _tree_construction_main ($) { Line 3370  sub _tree_construction_main ($) {
3370    
3371        $insert = $insert_to_current;        $insert = $insert_to_current;
3372        #        #
3373      } elsif ($self->{insertion_mode} == IN_ROW_IM or      } elsif ($self->{insertion_mode} & TABLE_IMS) {
3374               $self->{insertion_mode} == IN_TABLE_BODY_IM or        if ($token->{type} == CHARACTER_TOKEN) {
              $self->{insertion_mode} == IN_TABLE_IM) {  
           if ($token->{type} eq 'character') {  
             ## NOTE: There are "character in table" code clones.  
3375              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3376                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
3377                                
# Line 3362  sub _tree_construction_main ($) { Line 3428  sub _tree_construction_main ($) {
3428                            
3429              !!!next-token;              !!!next-token;
3430              redo B;              redo B;
3431            } elsif ($token->{type} eq 'start tag') {        } elsif ($token->{type} == START_TAG_TOKEN) {
3432              if ({              if ({
3433                   tr => ($self->{insertion_mode} != IN_ROW_IM),                   tr => ($self->{insertion_mode} != IN_ROW_IM),
3434                   th => 1, td => 1,                   th => 1, td => 1,
# Line 3548  sub _tree_construction_main ($) { Line 3614  sub _tree_construction_main ($) {
3614                  die "$0: in table: <>: $token->{tag_name}";                  die "$0: in table: <>: $token->{tag_name}";
3615                }                }
3616              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
               ## NOTE: There are code clones for this "table in table"  
3617                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3618    
3619                ## As if </table>                ## As if </table>
# Line 3579  sub _tree_construction_main ($) { Line 3644  sub _tree_construction_main ($) {
3644                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
3645                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
3646                  !!!back-token; # <table>                  !!!back-token; # <table>
3647                  $token = {type => 'end tag', tag_name => 'table'};                  $token = {type => END_TAG_TOKEN, tag_name => 'table'};
3648                  !!!back-token;                  !!!back-token;
3649                  $token = {type => 'end tag',                  $token = {type => END_TAG_TOKEN,
3650                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3651                  redo B;                  redo B;
3652                }                }
# Line 3596  sub _tree_construction_main ($) { Line 3661  sub _tree_construction_main ($) {
3661    
3662                ## reprocess                ## reprocess
3663                redo B;                redo B;
3664              } else {          } else {
3665                #            !!!parse-error (type => 'in table:'.$token->{tag_name});
3666              }  
3667            } elsif ($token->{type} eq 'end tag') {            $insert = $insert_to_foster;
3668              #
3669            }
3670          } elsif ($token->{type} == END_TAG_TOKEN) {
3671              if ($token->{tag_name} eq 'tr' and              if ($token->{tag_name} eq 'tr' and
3672                  $self->{insertion_mode} == IN_ROW_IM) {                  $self->{insertion_mode} == IN_ROW_IM) {
3673                ## have an element in table scope                ## have an element in table scope
# Line 3740  sub _tree_construction_main ($) { Line 3808  sub _tree_construction_main ($) {
3808                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
3809                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
3810                  !!!back-token;                  !!!back-token;
3811                  $token = {type => 'end tag',                  $token = {type => END_TAG_TOKEN,
3812                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3813                  redo B;                  redo B;
3814                }                }
# Line 3758  sub _tree_construction_main ($) { Line 3826  sub _tree_construction_main ($) {
3826              } elsif ({              } elsif ({
3827                        tbody => 1, tfoot => 1, thead => 1,                        tbody => 1, tfoot => 1, thead => 1,
3828                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
3829                       ($self->{insertion_mode} == IN_ROW_IM or                       $self->{insertion_mode} & ROW_IMS) {
                       $self->{insertion_mode} == IN_TABLE_BODY_IM)) {  
3830                if ($self->{insertion_mode} == IN_ROW_IM) {                if ($self->{insertion_mode} == IN_ROW_IM) {
3831                  ## have an element in table scope                  ## have an element in table scope
3832                  my $i;                  my $i;
# Line 3857  sub _tree_construction_main ($) { Line 3924  sub _tree_construction_main ($) {
3924                ## Ignore the token                ## Ignore the token
3925                !!!next-token;                !!!next-token;
3926                redo B;                redo B;
3927              } else {          } else {
3928                #            !!!parse-error (type => 'in table:/'.$token->{tag_name});
             }  
           } else {  
             die "$0: $token->{type}: Unknown token type";  
           }  
   
       !!!parse-error (type => 'in table:'.$token->{tag_name});  
3929    
3930        $insert = $insert_to_foster;            $insert = $insert_to_foster;
3931        #            #
3932            }
3933          } else {
3934            die "$0: $token->{type}: Unknown token type";
3935          }
3936      } elsif ($self->{insertion_mode} == IN_COLUMN_GROUP_IM) {      } elsif ($self->{insertion_mode} == IN_COLUMN_GROUP_IM) {
3937            if ($token->{type} eq 'character') {            if ($token->{type} == CHARACTER_TOKEN) {
3938              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3939                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
3940                unless (length $token->{data}) {                unless (length $token->{data}) {
# Line 3879  sub _tree_construction_main ($) { Line 3944  sub _tree_construction_main ($) {
3944              }              }
3945                            
3946              #              #
3947            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} == START_TAG_TOKEN) {
3948              if ($token->{tag_name} eq 'col') {              if ($token->{tag_name} eq 'col') {
3949                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3950                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
# Line 3888  sub _tree_construction_main ($) { Line 3953  sub _tree_construction_main ($) {
3953              } else {              } else {
3954                #                #
3955              }              }
3956            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} == END_TAG_TOKEN) {
3957              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
3958                if ($self->{open_elements}->[-1]->[1] eq 'html') {                if ($self->{open_elements}->[-1]->[1] eq 'html') {
3959                  !!!parse-error (type => 'unmatched end tag:colgroup');                  !!!parse-error (type => 'unmatched end tag:colgroup');
# Line 3926  sub _tree_construction_main ($) { Line 3991  sub _tree_construction_main ($) {
3991              redo B;              redo B;
3992            }            }
3993      } elsif ($self->{insertion_mode} == IN_SELECT_IM) {      } elsif ($self->{insertion_mode} == IN_SELECT_IM) {
3994            if ($token->{type} eq 'character') {        if ($token->{type} == CHARACTER_TOKEN) {
3995              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
3996              !!!next-token;          !!!next-token;
3997              redo B;          redo B;
3998            } elsif ($token->{type} eq 'start tag') {        } elsif ($token->{type} == START_TAG_TOKEN) {
3999              if ($token->{tag_name} eq 'option') {              if ($token->{tag_name} eq 'option') {
4000                if ($self->{open_elements}->[-1]->[1] eq 'option') {                if ($self->{open_elements}->[-1]->[1] eq 'option') {
4001                  ## As if </option>                  ## As if </option>
# Line 3983  sub _tree_construction_main ($) { Line 4048  sub _tree_construction_main ($) {
4048    
4049                !!!next-token;                !!!next-token;
4050                redo B;                redo B;
4051              } else {          } else {
4052                #            !!!parse-error (type => 'in select:'.$token->{tag_name});
4053              }            ## Ignore the token
4054            } elsif ($token->{type} eq 'end tag') {            !!!next-token;
4055              redo B;
4056            }
4057          } elsif ($token->{type} == END_TAG_TOKEN) {
4058              if ($token->{tag_name} eq 'optgroup') {              if ($token->{tag_name} eq 'optgroup') {
4059                if ($self->{open_elements}->[-1]->[1] eq 'option' and                if ($self->{open_elements}->[-1]->[1] eq 'option' and
4060                    $self->{open_elements}->[-2]->[1] eq 'optgroup') {                    $self->{open_elements}->[-2]->[1] eq 'optgroup') {
# Line 4088  sub _tree_construction_main ($) { Line 4156  sub _tree_construction_main ($) {
4156    
4157                ## reprocess                ## reprocess
4158                redo B;                redo B;
4159              } else {          } else {
4160                #            !!!parse-error (type => 'in select:/'.$token->{tag_name});
             }  
           } else {  
             #  
           }  
   
           !!!parse-error (type => 'in select:'.$token->{tag_name});  
4161            ## Ignore the token            ## Ignore the token
4162            !!!next-token;            !!!next-token;
4163            redo B;            redo B;
4164      } elsif ($self->{insertion_mode} == AFTER_BODY_IM or          }
4165               $self->{insertion_mode} == AFTER_HTML_BODY_IM) {        } else {
4166        if ($token->{type} eq 'character') {          die "$0: $token->{type}: Unknown token type";
4167          }
4168        } elsif ($self->{insertion_mode} & BODY_AFTER_IMS) {
4169          if ($token->{type} == CHARACTER_TOKEN) {
4170          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4171            my $data = $1;            my $data = $1;
4172            ## As if in body            ## As if in body
# Line 4127  sub _tree_construction_main ($) { Line 4192  sub _tree_construction_main ($) {
4192          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
4193          ## reprocess          ## reprocess
4194          redo B;          redo B;
4195        } elsif ($token->{type} eq 'start tag') {        } elsif ($token->{type} == START_TAG_TOKEN) {
4196          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
4197            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
4198                        
# Line 4140  sub _tree_construction_main ($) { Line 4205  sub _tree_construction_main ($) {
4205          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
4206          ## reprocess          ## reprocess
4207          redo B;          redo B;
4208        } elsif ($token->{type} eq 'end tag') {        } elsif ($token->{type} == END_TAG_TOKEN) {
4209          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
4210            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
4211                        
# Line 4170  sub _tree_construction_main ($) { Line 4235  sub _tree_construction_main ($) {
4235        } else {        } else {
4236          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
4237        }        }
4238      } elsif ($self->{insertion_mode} == IN_FRAMESET_IM or      } elsif ($self->{insertion_mode} & FRAME_IMS) {
4239               $self->{insertion_mode} == AFTER_FRAMESET_IM or        if ($token->{type} == CHARACTER_TOKEN) {
              $self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {  
       if ($token->{type} eq 'character') {  
4240          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4241            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4242                        
# Line 4206  sub _tree_construction_main ($) { Line 4269  sub _tree_construction_main ($) {
4269          }          }
4270                    
4271          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
4272        } elsif ($token->{type} eq 'start tag') {        } elsif ($token->{type} == START_TAG_TOKEN) {
4273          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
4274            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
4275    
# Line 4239  sub _tree_construction_main ($) { Line 4302  sub _tree_construction_main ($) {
4302            !!!next-token;            !!!next-token;
4303            redo B;            redo B;
4304          }          }
4305        } elsif ($token->{type} eq 'end tag') {        } elsif ($token->{type} == END_TAG_TOKEN) {
4306          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
4307            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
4308    
# Line 4289  sub _tree_construction_main ($) { Line 4352  sub _tree_construction_main ($) {
4352      }      }
4353    
4354      ## "in body" insertion mode      ## "in body" insertion mode
4355      if ($token->{type} eq 'start tag') {      if ($token->{type} == START_TAG_TOKEN) {
4356        if ($token->{tag_name} eq 'script') {        if ($token->{tag_name} eq 'script') {
4357          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
4358          $script_start_tag->($insert);          $script_start_tag->($insert);
# Line 4369  sub _tree_construction_main ($) { Line 4432  sub _tree_construction_main ($) {
4432          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
4433            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
4434              !!!back-token;              !!!back-token;
4435              $token = {type => 'end tag', tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
4436              redo B;              redo B;
4437            } elsif ({            } elsif ({
4438                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 4382  sub _tree_construction_main ($) { Line 4445  sub _tree_construction_main ($) {
4445          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4446          if ($token->{tag_name} eq 'pre') {          if ($token->{tag_name} eq 'pre') {
4447            !!!next-token;            !!!next-token;
4448            if ($token->{type} eq 'character') {            if ($token->{type} == CHARACTER_TOKEN) {
4449              $token->{data} =~ s/^\x0A//;              $token->{data} =~ s/^\x0A//;
4450              unless (length $token->{data}) {              unless (length $token->{data}) {
4451                !!!next-token;                !!!next-token;
# Line 4403  sub _tree_construction_main ($) { Line 4466  sub _tree_construction_main ($) {
4466            INSCOPE: for (reverse @{$self->{open_elements}}) {            INSCOPE: for (reverse @{$self->{open_elements}}) {
4467              if ($_->[1] eq 'p') {              if ($_->[1] eq 'p') {
4468                !!!back-token;                !!!back-token;
4469                $token = {type => 'end tag', tag_name => 'p'};                $token = {type => END_TAG_TOKEN, tag_name => 'p'};
4470                redo B;                redo B;
4471              } elsif ({              } elsif ({
4472                        table => 1, caption => 1, td => 1, th => 1,                        table => 1, caption => 1, td => 1, th => 1,
# Line 4423  sub _tree_construction_main ($) { Line 4486  sub _tree_construction_main ($) {
4486          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
4487            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
4488              !!!back-token;              !!!back-token;
4489              $token = {type => 'end tag', tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
4490              redo B;              redo B;
4491            } elsif ({            } elsif ({
4492                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 4470  sub _tree_construction_main ($) { Line 4533  sub _tree_construction_main ($) {
4533          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
4534            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
4535              !!!back-token;              !!!back-token;
4536              $token = {type => 'end tag', tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
4537              redo B;              redo B;
4538            } elsif ({            } elsif ({
4539                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 4517  sub _tree_construction_main ($) { Line 4580  sub _tree_construction_main ($) {
4580          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
4581            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
4582              !!!back-token;              !!!back-token;
4583              $token = {type => 'end tag', tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
4584              redo B;              redo B;
4585            } elsif ({            } elsif ({
4586                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 4541  sub _tree_construction_main ($) { Line 4604  sub _tree_construction_main ($) {
4604            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
4605            if ($node->[1] eq 'p') {            if ($node->[1] eq 'p') {
4606              !!!back-token;              !!!back-token;
4607              $token = {type => 'end tag', tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
4608              redo B;              redo B;
4609            } elsif ({            } elsif ({
4610                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 4585  sub _tree_construction_main ($) { Line 4648  sub _tree_construction_main ($) {
4648              !!!parse-error (type => 'in a:a');              !!!parse-error (type => 'in a:a');
4649                            
4650              !!!back-token;              !!!back-token;
4651              $token = {type => 'end tag', tag_name => 'a'};              $token = {type => END_TAG_TOKEN, tag_name => 'a'};
4652              $formatting_end_tag->($token->{tag_name});              $formatting_end_tag->($token->{tag_name});
4653                            
4654              AFE2: for (reverse 0..$#$active_formatting_elements) {              AFE2: for (reverse 0..$#$active_formatting_elements) {
# Line 4632  sub _tree_construction_main ($) { Line 4695  sub _tree_construction_main ($) {
4695          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4696            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
4697            if ($node->[1] eq 'nobr') {            if ($node->[1] eq 'nobr') {
4698              !!!parse-error (type => 'not closed:nobr');              !!!parse-error (type => 'in nobr:nobr');
4699              !!!back-token;              !!!back-token;
4700              $token = {type => 'end tag', tag_name => 'nobr'};              $token = {type => END_TAG_TOKEN, tag_name => 'nobr'};
4701              redo B;              redo B;
4702            } elsif ({            } elsif ({
4703                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 4656  sub _tree_construction_main ($) { Line 4719  sub _tree_construction_main ($) {
4719            if ($node->[1] eq 'button') {            if ($node->[1] eq 'button') {
4720              !!!parse-error (type => 'in button:button');              !!!parse-error (type => 'in button:button');
4721              !!!back-token;              !!!back-token;
4722              $token = {type => 'end tag', tag_name => 'button'};              $token = {type => END_TAG_TOKEN, tag_name => 'button'};
4723              redo B;              redo B;
4724            } elsif ({            } elsif ({
4725                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 4691  sub _tree_construction_main ($) { Line 4754  sub _tree_construction_main ($) {
4754          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
4755            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
4756              !!!back-token;              !!!back-token;
4757              $token = {type => 'end tag', tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
4758              redo B;              redo B;
4759            } elsif ({            } elsif ({
4760                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 4730  sub _tree_construction_main ($) { Line 4793  sub _tree_construction_main ($) {
4793          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
4794            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
4795              !!!back-token;              !!!back-token;
4796              $token = {type => 'end tag', tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
4797              redo B;              redo B;
4798            } elsif ({            } elsif ({
4799                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 4770  sub _tree_construction_main ($) { Line 4833  sub _tree_construction_main ($) {
4833            delete $at->{action};            delete $at->{action};
4834            delete $at->{prompt};            delete $at->{prompt};
4835            my @tokens = (            my @tokens = (
4836                          {type => 'start tag', tag_name => 'form',                          {type => START_TAG_TOKEN, tag_name => 'form',
4837                           attributes => $form_attrs},                           attributes => $form_attrs},
4838                          {type => 'start tag', tag_name => 'hr'},                          {type => START_TAG_TOKEN, tag_name => 'hr'},
4839                          {type => 'start tag', tag_name => 'p'},                          {type => START_TAG_TOKEN, tag_name => 'p'},
4840                          {type => 'start tag', tag_name => 'label'},                          {type => START_TAG_TOKEN, tag_name => 'label'},
4841                         );                         );
4842            if ($prompt_attr) {            if ($prompt_attr) {
4843              push @tokens, {type => 'character', data => $prompt_attr->{value}};              push @tokens, {type => CHARACTER_TOKEN, data => $prompt_attr->{value}};
4844            } else {            } else {
4845              push @tokens, {type => 'character',              push @tokens, {type => CHARACTER_TOKEN,
4846                             data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD                             data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD
4847              ## TODO: make this configurable              ## TODO: make this configurable
4848            }            }
4849            push @tokens,            push @tokens,
4850                          {type => 'start tag', tag_name => 'input', attributes => $at},                          {type => START_TAG_TOKEN, tag_name => 'input', attributes => $at},
4851                          #{type => 'character', data => ''}, # SHOULD                          #{type => CHARACTER_TOKEN, data => ''}, # SHOULD
4852                          {type => 'end tag', tag_name => 'label'},                          {type => END_TAG_TOKEN, tag_name => 'label'},
4853                          {type => 'end tag', tag_name => 'p'},                          {type => END_TAG_TOKEN, tag_name => 'p'},
4854                          {type => 'start tag', tag_name => 'hr'},                          {type => START_TAG_TOKEN, tag_name => 'hr'},
4855                          {type => 'end tag', tag_name => 'form'};                          {type => END_TAG_TOKEN, tag_name => 'form'};
4856            $token = shift @tokens;            $token = shift @tokens;
4857            !!!back-token (@tokens);            !!!back-token (@tokens);
4858            redo B;            redo B;
# Line 4807  sub _tree_construction_main ($) { Line 4870  sub _tree_construction_main ($) {
4870                    
4871          my $text = '';          my $text = '';
4872          !!!next-token;          !!!next-token;
4873          if ($token->{type} eq 'character') {          if ($token->{type} == CHARACTER_TOKEN) {
4874            $token->{data} =~ s/^\x0A//;            $token->{data} =~ s/^\x0A//;
4875            unless (length $token->{data}) {            unless (length $token->{data}) {
4876              !!!next-token;              !!!next-token;
4877            }            }
4878          }          }
4879          while ($token->{type} eq 'character') {          while ($token->{type} == CHARACTER_TOKEN) {
4880            $text .= $token->{data};            $text .= $token->{data};
4881            !!!next-token;            !!!next-token;
4882          }          }
# Line 4823  sub _tree_construction_main ($) { Line 4886  sub _tree_construction_main ($) {
4886                    
4887          $self->{content_model} = PCDATA_CONTENT_MODEL;          $self->{content_model} = PCDATA_CONTENT_MODEL;
4888                    
4889          if ($token->{type} eq 'end tag' and          if ($token->{type} == END_TAG_TOKEN and
4890              $token->{tag_name} eq $tag_name) {              $token->{tag_name} eq $tag_name) {
4891            ## Ignore the token            ## Ignore the token
4892          } else {          } else {
# Line 4837  sub _tree_construction_main ($) { Line 4900  sub _tree_construction_main ($) {
4900                  noframes => 1,                  noframes => 1,
4901                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
4902                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
4903          ## NOTE: There are two "as if in body" code clones.          ## NOTE: There is an "as if in body" code clone.
4904          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
4905          redo B;          redo B;
4906        } elsif ($token->{tag_name} eq 'select') {        } elsif ($token->{tag_name} eq 'select') {
# Line 4868  sub _tree_construction_main ($) { Line 4931  sub _tree_construction_main ($) {
4931          !!!next-token;          !!!next-token;
4932          redo B;          redo B;
4933        }        }
4934      } elsif ($token->{type} eq 'end tag') {      } elsif ($token->{type} == END_TAG_TOKEN) {
4935        if ($token->{tag_name} eq 'body') {        if ($token->{tag_name} eq 'body') {
4936          if (@{$self->{open_elements}} > 1 and          if (@{$self->{open_elements}} > 1 and
4937              $self->{open_elements}->[1]->[1] eq 'body') {              $self->{open_elements}->[1]->[1] eq 'body') {
# Line 4929  sub _tree_construction_main ($) { Line 4992  sub _tree_construction_main ($) {
4992                   tbody => 1, tfoot=> 1, thead => 1,                   tbody => 1, tfoot=> 1, thead => 1,
4993                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4994                !!!back-token;                !!!back-token;
4995                $token = {type => 'end tag',                $token = {type => END_TAG_TOKEN,
4996                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
4997                redo B;                redo B;
4998              }              }
# Line 4977  sub _tree_construction_main ($) { Line 5040  sub _tree_construction_main ($) {
5040                   tbody => 1, tfoot=> 1, thead => 1,                   tbody => 1, tfoot=> 1, thead => 1,
5041                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
5042                !!!back-token;                !!!back-token;
5043                $token = {type => 'end tag',                $token = {type => END_TAG_TOKEN,
5044                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
5045                redo B;                redo B;
5046              }              }
# Line 4993  sub _tree_construction_main ($) { Line 5056  sub _tree_construction_main ($) {
5056          if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) {          if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) {
5057            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
5058          } else {          } else {
5059            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5060          }          }
5061    
5062          undef $self->{form_element};          undef $self->{form_element};
# Line 5016  sub _tree_construction_main ($) { Line 5079  sub _tree_construction_main ($) {
5079                   tbody => 1, tfoot=> 1, thead => 1,                   tbody => 1, tfoot=> 1, thead => 1,
5080                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
5081                !!!back-token;                !!!back-token;
5082                $token = {type => 'end tag',                $token = {type => END_TAG_TOKEN,
5083                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
5084                redo B;                redo B;
5085              }              }
# Line 5031  sub _tree_construction_main ($) { Line 5094  sub _tree_construction_main ($) {
5094          } # INSCOPE          } # INSCOPE
5095                    
5096          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
5097            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5098          }          }
5099                    
5100          splice @{$self->{open_elements}}, $i if defined $i;          splice @{$self->{open_elements}}, $i if defined $i;
# Line 5090  sub _tree_construction_main ($) { Line 5153  sub _tree_construction_main ($) {
5153              if ({              if ({
5154                   dd => 1, dt => 1, li => 1, p => 1,                   dd => 1, dt => 1, li => 1, p => 1,
5155                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
5156                   tbody => 1, tfoot=> 1, thead => 1,                   tbody => 1, tfoot => 1, thead => 1,
5157                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
5158                !!!back-token;                !!!back-token;
5159                $token = {type => 'end tag',                $token = {type => END_TAG_TOKEN,
5160                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
5161                redo B;                redo B;
5162              }              }
5163                    
5164              ## Step 2              ## Step 2
5165              if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) {              if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) {
5166                  ## NOTE: <x><y></x>
5167                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
5168              }              }
5169                            
# Line 5302  sub set_inner_html ($$$) { Line 5366  sub set_inner_html ($$$) {
5366    
5367  } # tree construction stage  } # tree construction stage
5368    
 sub get_inner_html ($$$) {  
   my (undef, $node, $on_error) = @_;  
   
   ## Step 1  
   my $s = '';  
   
   my $in_cdata;  
   my $parent = $node;  
   while (defined $parent) {  
     if ($parent->node_type == 1 and  
         $parent->namespace_uri eq 'http://www.w3.org/1999/xhtml' and  
         {  
           style => 1, script => 1, xmp => 1, iframe => 1,  
           noembed => 1, noframes => 1, noscript => 1,  
         }->{$parent->local_name}) { ## TODO: case thingy  
       $in_cdata = 1;  
     }  
     $parent = $parent->parent_node;  
   }  
   
   ## Step 2  
   my @node = @{$node->child_nodes};  
   C: while (@node) {  
     my $child = shift @node;  
     unless (ref $child) {  
       if ($child eq 'cdata-out') {  
         $in_cdata = 0;  
       } else {  
         $s .= $child; # end tag  
       }  
       next C;  
     }  
       
     my $nt = $child->node_type;  
     if ($nt == 1) { # Element  
       my $tag_name = $child->tag_name; ## TODO: manakai_tag_name  
       $s .= '<' . $tag_name;  
       ## NOTE: Non-HTML case:  
       ## <http://permalink.gmane.org/gmane.org.w3c.whatwg.discuss/11191>  
   
       my @attrs = @{$child->attributes}; # sort order MUST be stable  
       for my $attr (@attrs) { # order is implementation dependent  
         my $attr_name = $attr->name; ## TODO: manakai_name  
         $s .= ' ' . $attr_name . '="';  
         my $attr_value = $attr->value;  
         ## escape  
         $attr_value =~ s/&/&amp;/g;  
         $attr_value =~ s/</&lt;/g;  
         $attr_value =~ s/>/&gt;/g;  
         $attr_value =~ s/"/&quot;/g;  
         $s .= $attr_value . '"';  
       }  
       $s .= '>';  
         
       next C if {  
         area => 1, base => 1, basefont => 1, bgsound => 1,  
         br => 1, col => 1, embed => 1, frame => 1, hr => 1,  
         img => 1, input => 1, link => 1, meta => 1, param => 1,  
         spacer => 1, wbr => 1,  
       }->{$tag_name};  
   
       $s .= "\x0A" if $tag_name eq 'pre' or $tag_name eq 'textarea';  
   
       if (not $in_cdata and {  
         style => 1, script => 1, xmp => 1, iframe => 1,  
         noembed => 1, noframes => 1, noscript => 1,  
         plaintext => 1,  
       }->{$tag_name}) {  
         unshift @node, 'cdata-out';  
         $in_cdata = 1;  
       }  
   
       unshift @node, @{$child->child_nodes}, '</' . $tag_name . '>';  
     } elsif ($nt == 3 or $nt == 4) {  
       if ($in_cdata) {  
         $s .= $child->data;  
       } else {  
         my $value = $child->data;  
         $value =~ s/&/&amp;/g;  
         $value =~ s/</&lt;/g;  
         $value =~ s/>/&gt;/g;  
         $value =~ s/"/&quot;/g;  
         $s .= $value;  
       }  
     } elsif ($nt == 8) {  
       $s .= '<!--' . $child->data . '-->';  
     } elsif ($nt == 10) {  
       $s .= '<!DOCTYPE ' . $child->name . '>';  
     } elsif ($nt == 5) { # entrefs  
       push @node, @{$child->child_nodes};  
     } else {  
       $on_error->($child) if defined $on_error;  
     }  
     ## ISSUE: This code does not support PIs.  
   } # C  
     
   ## Step 3  
   return \$s;  
 } # get_inner_html  
   
5369  1;  1;
5370  # $Date$  # $Date$

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24