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

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

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

revision 1.10 by wakaba, Wed Oct 15 08:51:02 2008 UTC revision 1.20 by wakaba, Sun Oct 19 08:20:29 2008 UTC
# Line 15  BEGIN { Line 15  BEGIN {
15      CHARACTER_TOKEN      CHARACTER_TOKEN
16      PI_TOKEN      PI_TOKEN
17      ABORT_TOKEN      ABORT_TOKEN
18        END_OF_DOCTYPE_TOKEN
19        ATTLIST_TOKEN
20        ELEMENT_TOKEN
21        GENERAL_ENTITY_TOKEN
22        PARAMETER_ENTITY_TOKEN
23        NOTATION_TOKEN
24    );    );
25        
26    our %EXPORT_TAGS = (    our %EXPORT_TAGS = (
# Line 27  BEGIN { Line 33  BEGIN {
33        CHARACTER_TOKEN        CHARACTER_TOKEN
34        PI_TOKEN        PI_TOKEN
35        ABORT_TOKEN        ABORT_TOKEN
36          END_OF_DOCTYPE_TOKEN
37          ATTLIST_TOKEN
38          ELEMENT_TOKEN
39          GENERAL_ENTITY_TOKEN
40          PARAMETER_ENTITY_TOKEN
41          NOTATION_TOKEN
42      )],      )],
43    );    );
44  }  }
45    
46    ## NOTE: Differences from the XML5 draft are marked as "XML5:".
47    
48  ## Token types  ## Token types
49    
50  sub DOCTYPE_TOKEN () { 1 }  sub DOCTYPE_TOKEN () { 1 } ## XML5: No DOCTYPE token.
51  sub COMMENT_TOKEN () { 2 }  sub COMMENT_TOKEN () { 2 }
52  sub START_TAG_TOKEN () { 3 }  sub START_TAG_TOKEN () { 3 }
53  sub END_TAG_TOKEN () { 4 }  sub END_TAG_TOKEN () { 4 }
54  sub END_OF_FILE_TOKEN () { 5 }  sub END_OF_FILE_TOKEN () { 5 }
55  sub CHARACTER_TOKEN () { 6 }  sub CHARACTER_TOKEN () { 6 }
56  sub PI_TOKEN () { 7 } # XML5  sub PI_TOKEN () { 7 } ## NOTE: XML only.
57  sub ABORT_TOKEN () { 8 } # Not a token actually  sub ABORT_TOKEN () { 8 } ## NOTE: For internal processing.
58    sub END_OF_DOCTYPE_TOKEN () { 9 } ## NOTE: XML only.
59    sub ATTLIST_TOKEN () { 10 } ## NOTE: XML only.
60    sub ELEMENT_TOKEN () { 11 } ## NOTE: XML only.
61    sub GENERAL_ENTITY_TOKEN () { 12 } ## NOTE: XML only.
62    sub PARAMETER_ENTITY_TOKEN () { 13 } ## NOTE: XML only.
63    sub NOTATION_TOKEN () { 14 } ## NOTE: XML only.
64    
65    ## XML5: XML5 has "empty tag token".  In this implementation, it is
66    ## represented as a start tag token with $self->{self_closing} flag
67    ## set to true.
68    
69    ## XML5: XML5 has "short end tag token".  In this implementation, it
70    ## is represented as an end tag token with $token->{tag_name} flag set
71    ## to an empty string.
72    
73  package Whatpm::HTML;  package Whatpm::HTML;
74    
# Line 114  sub HEXREF_HEX_STATE () { 48 } Line 142  sub HEXREF_HEX_STATE () { 48 }
142  sub ENTITY_NAME_STATE () { 49 }  sub ENTITY_NAME_STATE () { 49 }
143  sub PCDATA_STATE () { 50 } # "data state" in the spec  sub PCDATA_STATE () { 50 } # "data state" in the spec
144    
145  ## XML states  ## XML-only states
146  sub PI_STATE () { 51 }  sub PI_STATE () { 51 }
147  sub PI_TARGET_STATE () { 52 }  sub PI_TARGET_STATE () { 52 }
148  sub PI_TARGET_AFTER_STATE () { 53 }  sub PI_TARGET_AFTER_STATE () { 53 }
149  sub PI_DATA_STATE () { 54 }  sub PI_DATA_STATE () { 54 }
150  sub PI_AFTER_STATE () { 55 }  sub PI_AFTER_STATE () { 55 }
151  sub PI_DATA_AFTER_STATE () { 56 }  sub PI_DATA_AFTER_STATE () { 56 }
152    sub DOCTYPE_INTERNAL_SUBSET_STATE () { 57 }
153    sub DOCTYPE_INTERNAL_SUBSET_AFTER_STATE () { 58 }
154    sub BOGUS_DOCTYPE_INTERNAL_SUBSET_AFTER_STATE () { 59 }
155    sub DOCTYPE_TAG_STATE () { 60 }
156    sub DOCTYPE_MARKUP_DECLARATION_OPEN_STATE () { 61 }
157    sub MD_ATTLIST_STATE () { 62 }
158    sub MD_E_STATE () { 63 }
159    sub MD_ELEMENT_STATE () { 64 }
160    sub MD_ENTITY_STATE () { 65 }
161    sub MD_NOTATION_STATE () { 66 }
162    sub DOCTYPE_MD_STATE () { 67 }
163    sub BEFORE_MD_NAME_STATE () { 68 }
164    sub MD_NAME_STATE () { 69 }
165    sub DOCTYPE_ENTITY_PARAMETER_BEFORE_STATE () { 70 }
166    sub DOCTYPE_ATTLIST_NAME_AFTER_STATE () { 71 }
167    sub DOCTYPE_ATTLIST_ATTRIBUTE_NAME_STATE () { 72 }
168    sub DOCTYPE_ATTLIST_ATTRIBUTE_NAME_AFTER_STATE () { 73 }
169    sub DOCTYPE_ATTLIST_ATTRIBUTE_TYPE_STATE () { 74 }
170    sub DOCTYPE_ATTLIST_ATTRIBUTE_TYPE_AFTER_STATE () { 75 }
171    sub BEFORE_ALLOWED_TOKEN_STATE () { 76 }
172    sub ALLOWED_TOKEN_STATE () { 77 }
173    sub AFTER_ALLOWED_TOKEN_STATE () { 78 }
174    sub AFTER_ALLOWED_TOKENS_STATE () { 79 }
175    sub BEFORE_ATTR_DEFAULT_STATE () { 80 }
176    sub DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE () { 81 }
177    sub DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_STATE () { 82 }
178    sub DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_AFTER_STATE () { 83 }
179    sub AFTER_ATTLIST_ATTR_VALUE_QUOTED_STATE () { 84 }
180    sub BEFORE_NDATA_STATE () { 85 }
181    sub NDATA_STATE () { 86 }
182    sub AFTER_NDATA_STATE () { 87 }
183    sub BEFORE_NOTATION_NAME_STATE () { 88 }
184    sub NOTATION_NAME_STATE () { 89 }
185    sub DOCTYPE_ENTITY_VALUE_DOUBLE_QUOTED_STATE () { 90 }
186    sub DOCTYPE_ENTITY_VALUE_SINGLE_QUOTED_STATE () { 91 }
187    sub ENTITY_VALUE_ENTITY_STATE () { 92 }
188    sub AFTER_ELEMENT_NAME_STATE () { 93 }
189    sub BEFORE_ELEMENT_CONTENT_STATE () { 94 }
190    sub CONTENT_KEYWORD_STATE () { 95 }
191    sub AFTER_CM_GROUP_OPEN_STATE () { 96 }
192    sub CM_ELEMENT_NAME_STATE () { 97 }
193    sub AFTER_CM_ELEMENT_NAME_STATE () { 98 }
194    sub AFTER_CM_GROUP_CLOSE_STATE () { 99 }
195    sub AFTER_MD_DEF_STATE () { 100 }
196    sub BOGUS_MD_STATE () { 101 }
197    
198  ## Tree constructor state constants (see Whatpm::HTML for the full  ## Tree constructor state constants (see Whatpm::HTML for the full
199  ## list and descriptions)  ## list and descriptions)
# Line 186  sub _initialize_tokenizer ($) { Line 259  sub _initialize_tokenizer ($) {
259    #$self->{is_xml} (if XML)    #$self->{is_xml} (if XML)
260    
261    $self->{state} = DATA_STATE; # MUST    $self->{state} = DATA_STATE; # MUST
262    $self->{s_kwd} = ''; # state keyword    $self->{s_kwd} = ''; # Data state keyword
263      #$self->{kwd} = ''; # State-dependent keyword; initialized when used
264    #$self->{entity__value}; # initialized when used    #$self->{entity__value}; # initialized when used
265    #$self->{entity__match}; # initialized when used    #$self->{entity__match}; # initialized when used
266    $self->{content_model} = PCDATA_CONTENT_MODEL; # be    $self->{content_model} = PCDATA_CONTENT_MODEL; # be
# Line 206  sub _initialize_tokenizer ($) { Line 280  sub _initialize_tokenizer ($) {
280    
281  ## A token has:  ## A token has:
282  ##   ->{type} == DOCTYPE_TOKEN, START_TAG_TOKEN, END_TAG_TOKEN, COMMENT_TOKEN,  ##   ->{type} == DOCTYPE_TOKEN, START_TAG_TOKEN, END_TAG_TOKEN, COMMENT_TOKEN,
283  ##       CHARACTER_TOKEN, or END_OF_FILE_TOKEN  ##       CHARACTER_TOKEN, END_OF_FILE_TOKEN, PI_TOKEN, or ABORT_TOKEN
284  ##   ->{name} (DOCTYPE_TOKEN)  ##   ->{name} (DOCTYPE_TOKEN)
285  ##   ->{tag_name} (START_TAG_TOKEN, END_TAG_TOKEN)  ##   ->{tag_name} (START_TAG_TOKEN, END_TAG_TOKEN)
286    ##   ->{target} (PI_TOKEN)
287  ##   ->{pubid} (DOCTYPE_TOKEN)  ##   ->{pubid} (DOCTYPE_TOKEN)
288  ##   ->{sysid} (DOCTYPE_TOKEN)  ##   ->{sysid} (DOCTYPE_TOKEN)
289  ##   ->{quirks} == 1 or 0 (DOCTYPE_TOKEN): "force-quirks" flag  ##   ->{quirks} == 1 or 0 (DOCTYPE_TOKEN): "force-quirks" flag
# Line 216  sub _initialize_tokenizer ($) { Line 291  sub _initialize_tokenizer ($) {
291  ##        ->{name}  ##        ->{name}
292  ##        ->{value}  ##        ->{value}
293  ##        ->{has_reference} == 1 or 0  ##        ->{has_reference} == 1 or 0
294  ##   ->{data} (COMMENT_TOKEN, CHARACTER_TOKEN)  ##        ->{index}: Index of the attribute in a tag.
295    ##   ->{data} (COMMENT_TOKEN, CHARACTER_TOKEN, PI_TOKEN)
296  ##   ->{has_reference} == 1 or 0 (CHARACTER_TOKEN)  ##   ->{has_reference} == 1 or 0 (CHARACTER_TOKEN)
297    ##   ->{last_index} (ELEMENT_TOKEN): Next attribute's index - 1.
298    ##   ->{has_internal_subset} = 1 or 0 (DOCTYPE_TOKEN)
299    
300  ## NOTE: The "self-closing flag" is hold as |$self->{self_closing}|.  ## NOTE: The "self-closing flag" is hold as |$self->{self_closing}|.
301  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|
302  ##     while the token is pushed back to the stack.  ##     while the token is pushed back to the stack.
# Line 237  my $is_space = { Line 316  my $is_space = {
316    0x0009 => 1, # CHARACTER TABULATION (HT)    0x0009 => 1, # CHARACTER TABULATION (HT)
317    0x000A => 1, # LINE FEED (LF)    0x000A => 1, # LINE FEED (LF)
318    #0x000B => 0, # LINE TABULATION (VT)    #0x000B => 0, # LINE TABULATION (VT)
319    0x000C => 1, # FORM FEED (FF)    0x000C => 1, # FORM FEED (FF) ## XML5: Not a space character.
320    #0x000D => 1, # CARRIAGE RETURN (CR)    #0x000D => 1, # CARRIAGE RETURN (CR)
321    0x0020 => 1, # SPACE (SP)    0x0020 => 1, # SPACE (SP)
322  };  };
# Line 447  sub _get_next_token ($) { Line 526  sub _get_next_token ($) {
526            redo A;            redo A;
527          } elsif ($self->{nc} == 0x0021) { # !          } elsif ($self->{nc} == 0x0021) { # !
528            !!!cp (15.1);            !!!cp (15.1);
529            $self->{s_kwd} = '<' unless $self->{escape};            $self->{s_kwd} = $self->{escaped} ? '' : '<';
530            #            #
531          } else {          } else {
532            !!!cp (16);            !!!cp (16);
533              $self->{s_kwd} = '';
534            #            #
535          }          }
536    
537          ## reconsume          ## reconsume
538          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
         $self->{s_kwd} = '';  
539          !!!emit ({type => CHARACTER_TOKEN, data => '<',          !!!emit ({type => CHARACTER_TOKEN, data => '<',
540                    line => $self->{line_prev},                    line => $self->{line_prev},
541                    column => $self->{column_prev},                    column => $self->{column_prev},
# Line 567  sub _get_next_token ($) { Line 646  sub _get_next_token ($) {
646        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
647          if (defined $self->{last_stag_name}) {          if (defined $self->{last_stag_name}) {
648            $self->{state} = CDATA_RCDATA_CLOSE_TAG_STATE;            $self->{state} = CDATA_RCDATA_CLOSE_TAG_STATE;
649            $self->{s_kwd} = '';            $self->{kwd} = '';
650            ## Reconsume.            ## Reconsume.
651            redo A;            redo A;
652          } else {          } else {
# Line 670  sub _get_next_token ($) { Line 749  sub _get_next_token ($) {
749          redo A;          redo A;
750        }        }
751      } elsif ($self->{state} == CDATA_RCDATA_CLOSE_TAG_STATE) {      } elsif ($self->{state} == CDATA_RCDATA_CLOSE_TAG_STATE) {
752        my $ch = substr $self->{last_stag_name}, length $self->{s_kwd}, 1;        my $ch = substr $self->{last_stag_name}, length $self->{kwd}, 1;
753        if (length $ch) {        if (length $ch) {
754          my $CH = $ch;          my $CH = $ch;
755          $ch =~ tr/a-z/A-Z/;          $ch =~ tr/a-z/A-Z/;
# Line 678  sub _get_next_token ($) { Line 757  sub _get_next_token ($) {
757          if ($nch eq $ch or $nch eq $CH) {          if ($nch eq $ch or $nch eq $CH) {
758            !!!cp (24);            !!!cp (24);
759            ## Stay in the state.            ## Stay in the state.
760            $self->{s_kwd} .= $nch;            $self->{kwd} .= $nch;
761            !!!next-input-character;            !!!next-input-character;
762            redo A;            redo A;
763          } else {          } else {
# Line 687  sub _get_next_token ($) { Line 766  sub _get_next_token ($) {
766            $self->{s_kwd} = '';            $self->{s_kwd} = '';
767            ## Reconsume.            ## Reconsume.
768            !!!emit ({type => CHARACTER_TOKEN,            !!!emit ({type => CHARACTER_TOKEN,
769                      data => '</' . $self->{s_kwd},                      data => '</' . $self->{kwd},
770                      line => $self->{line_prev},                      line => $self->{line_prev},
771                      column => $self->{column_prev} - 1 - length $self->{s_kwd},                      column => $self->{column_prev} - 1 - length $self->{kwd},
772                     });                     });
773            redo A;            redo A;
774          }          }
# Line 705  sub _get_next_token ($) { Line 784  sub _get_next_token ($) {
784            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
785            $self->{s_kwd} = '';            $self->{s_kwd} = '';
786            !!!emit ({type => CHARACTER_TOKEN,            !!!emit ({type => CHARACTER_TOKEN,
787                      data => '</' . $self->{s_kwd},                      data => '</' . $self->{kwd},
788                      line => $self->{line_prev},                      line => $self->{line_prev},
789                      column => $self->{column_prev} - 1 - length $self->{s_kwd},                      column => $self->{column_prev} - 1 - length $self->{kwd},
790                     });                     });
791            redo A;            redo A;
792          } else {          } else {
# Line 716  sub _get_next_token ($) { Line 795  sub _get_next_token ($) {
795                = {type => END_TAG_TOKEN,                = {type => END_TAG_TOKEN,
796                   tag_name => $self->{last_stag_name},                   tag_name => $self->{last_stag_name},
797                   line => $self->{line_prev},                   line => $self->{line_prev},
798                   column => $self->{column_prev} - 1 - length $self->{s_kwd}};                   column => $self->{column_prev} - 1 - length $self->{kwd}};
799            $self->{state} = TAG_NAME_STATE;            $self->{state} = TAG_NAME_STATE;
800            ## Reconsume.            ## Reconsume.
801            redo A;            redo A;
# Line 798  sub _get_next_token ($) { Line 877  sub _get_next_token ($) {
877          redo A;          redo A;
878        }        }
879      } elsif ($self->{state} == BEFORE_ATTRIBUTE_NAME_STATE) {      } elsif ($self->{state} == BEFORE_ATTRIBUTE_NAME_STATE) {
880          ## XML5: "Tag attribute name before state".
881    
882        if ($is_space->{$self->{nc}}) {        if ($is_space->{$self->{nc}}) {
883          !!!cp (45);          !!!cp (45);
884          ## Stay in the state          ## Stay in the state
# Line 870  sub _get_next_token ($) { Line 951  sub _get_next_token ($) {
951               0x003D => 1, # =               0x003D => 1, # =
952              }->{$self->{nc}}) {              }->{$self->{nc}}) {
953            !!!cp (55);            !!!cp (55);
954              ## XML5: Not a parse error.
955            !!!parse-error (type => 'bad attribute name');            !!!parse-error (type => 'bad attribute name');
956          } else {          } else {
957            !!!cp (56);            !!!cp (56);
958              ## XML5: ":" raises a parse error and is ignored.
959          }          }
960          $self->{ca}          $self->{ca}
961              = {name => chr ($self->{nc}),              = {name => chr ($self->{nc}),
# Line 883  sub _get_next_token ($) { Line 966  sub _get_next_token ($) {
966          redo A;          redo A;
967        }        }
968      } elsif ($self->{state} == ATTRIBUTE_NAME_STATE) {      } elsif ($self->{state} == ATTRIBUTE_NAME_STATE) {
969          ## XML5: "Tag attribute name state".
970    
971        my $before_leave = sub {        my $before_leave = sub {
972          if (exists $self->{ct}->{attributes} # start tag or end tag          if (exists $self->{ct}->{attributes} # start tag or end tag
973              ->{$self->{ca}->{name}}) { # MUST              ->{$self->{ca}->{name}}) { # MUST
# Line 893  sub _get_next_token ($) { Line 978  sub _get_next_token ($) {
978            !!!cp (58);            !!!cp (58);
979            $self->{ct}->{attributes}->{$self->{ca}->{name}}            $self->{ct}->{attributes}->{$self->{ca}->{name}}
980              = $self->{ca};              = $self->{ca};
981              $self->{ca}->{index} = ++$self->{ct}->{last_index};
982          }          }
983        }; # $before_leave        }; # $before_leave
984    
# Line 909  sub _get_next_token ($) { Line 995  sub _get_next_token ($) {
995          !!!next-input-character;          !!!next-input-character;
996          redo A;          redo A;
997        } elsif ($self->{nc} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
998            if ($self->{is_xml}) {
999              !!!cp (60.1);
1000              ## XML5: Not a parse error.
1001              !!!parse-error (type => 'no attr value'); ## TODO: type
1002            } else {
1003              !!!cp (60.2);
1004            }
1005    
1006          $before_leave->();          $before_leave->();
1007          if ($self->{ct}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1008            !!!cp (61);            !!!cp (61);
# Line 938  sub _get_next_token ($) { Line 1032  sub _get_next_token ($) {
1032          !!!next-input-character;          !!!next-input-character;
1033          redo A;          redo A;
1034        } elsif ($self->{nc} == 0x002F) { # /        } elsif ($self->{nc} == 0x002F) { # /
1035          !!!cp (64);          if ($self->{is_xml}) {
1036              !!!cp (64);
1037              ## XML5: Not a parse error.
1038              !!!parse-error (type => 'no attr value'); ## TODO: type
1039            } else {
1040              !!!cp (64.1);
1041            }
1042            
1043          $before_leave->();          $before_leave->();
1044          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1045          !!!next-input-character;          !!!next-input-character;
# Line 972  sub _get_next_token ($) { Line 1073  sub _get_next_token ($) {
1073          if ($self->{nc} == 0x0022 or # "          if ($self->{nc} == 0x0022 or # "
1074              $self->{nc} == 0x0027) { # '              $self->{nc} == 0x0027) { # '
1075            !!!cp (69);            !!!cp (69);
1076              ## XML5: Not a parse error.
1077            !!!parse-error (type => 'bad attribute name');            !!!parse-error (type => 'bad attribute name');
1078          } else {          } else {
1079            !!!cp (70);            !!!cp (70);
# Line 982  sub _get_next_token ($) { Line 1084  sub _get_next_token ($) {
1084          redo A;          redo A;
1085        }        }
1086      } elsif ($self->{state} == AFTER_ATTRIBUTE_NAME_STATE) {      } elsif ($self->{state} == AFTER_ATTRIBUTE_NAME_STATE) {
1087          ## XML5: "Tag attribute name after state".
1088          
1089        if ($is_space->{$self->{nc}}) {        if ($is_space->{$self->{nc}}) {
1090          !!!cp (71);          !!!cp (71);
1091          ## Stay in the state          ## Stay in the state
# Line 993  sub _get_next_token ($) { Line 1097  sub _get_next_token ($) {
1097          !!!next-input-character;          !!!next-input-character;
1098          redo A;          redo A;
1099        } elsif ($self->{nc} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
1100            if ($self->{is_xml}) {
1101              !!!cp (72.1);
1102              ## XML5: Not a parse error.
1103              !!!parse-error (type => 'no attr value'); ## TODO: type
1104            } else {
1105              !!!cp (72.2);
1106            }
1107    
1108          if ($self->{ct}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1109            !!!cp (73);            !!!cp (73);
1110            $self->{last_stag_name} = $self->{ct}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
# Line 1026  sub _get_next_token ($) { Line 1138  sub _get_next_token ($) {
1138          !!!next-input-character;          !!!next-input-character;
1139          redo A;          redo A;
1140        } elsif ($self->{nc} == 0x002F) { # /        } elsif ($self->{nc} == 0x002F) { # /
1141          !!!cp (77);          if ($self->{is_xml}) {
1142              !!!cp (77);
1143              ## XML5: Not a parse error.
1144              !!!parse-error (type => 'no attr value'); ## TODO: type
1145            } else {
1146              !!!cp (77.1);
1147            }
1148            
1149          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1150          !!!next-input-character;          !!!next-input-character;
1151          redo A;          redo A;
# Line 1055  sub _get_next_token ($) { Line 1174  sub _get_next_token ($) {
1174    
1175          redo A;          redo A;
1176        } else {        } else {
1177            if ($self->{is_xml}) {
1178              !!!cp (78.1);
1179              ## XML5: Not a parse error.
1180              !!!parse-error (type => 'no attr value'); ## TODO: type
1181            } else {
1182              !!!cp (78.2);
1183            }
1184    
1185          if ($self->{nc} == 0x0022 or # "          if ($self->{nc} == 0x0022 or # "
1186              $self->{nc} == 0x0027) { # '              $self->{nc} == 0x0027) { # '
1187            !!!cp (78);            !!!cp (78);
1188              ## XML5: Not a parse error.
1189            !!!parse-error (type => 'bad attribute name');            !!!parse-error (type => 'bad attribute name');
1190          } else {          } else {
1191            !!!cp (82);            !!!cp (82);
# Line 1071  sub _get_next_token ($) { Line 1199  sub _get_next_token ($) {
1199          redo A;                  redo A;        
1200        }        }
1201      } elsif ($self->{state} == BEFORE_ATTRIBUTE_VALUE_STATE) {      } elsif ($self->{state} == BEFORE_ATTRIBUTE_VALUE_STATE) {
1202          ## XML5: "Tag attribute value before state".
1203    
1204        if ($is_space->{$self->{nc}}) {        if ($is_space->{$self->{nc}}) {
1205          !!!cp (83);          !!!cp (83);
1206          ## Stay in the state          ## Stay in the state
# Line 1142  sub _get_next_token ($) { Line 1272  sub _get_next_token ($) {
1272        } else {        } else {
1273          if ($self->{nc} == 0x003D) { # =          if ($self->{nc} == 0x003D) { # =
1274            !!!cp (93);            !!!cp (93);
1275              ## XML5: Not a parse error.
1276            !!!parse-error (type => 'bad attribute value');            !!!parse-error (type => 'bad attribute value');
1277            } elsif ($self->{is_xml}) {
1278              !!!cp (93.1);
1279              ## XML5: No parse error.
1280              !!!parse-error (type => 'unquoted attr value'); ## TODO
1281          } else {          } else {
1282            !!!cp (94);            !!!cp (94);
1283          }          }
# Line 1152  sub _get_next_token ($) { Line 1287  sub _get_next_token ($) {
1287          redo A;          redo A;
1288        }        }
1289      } elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) {
1290          ## XML5: "Tag attribute value double quoted state" and "DOCTYPE
1291          ## ATTLIST attribute value double quoted state".
1292          
1293        if ($self->{nc} == 0x0022) { # "        if ($self->{nc} == 0x0022) { # "
1294          !!!cp (95);          if ($self->{ct}->{type} == ATTLIST_TOKEN) {
1295          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;            !!!cp (95.1);
1296              ## XML5: "DOCTYPE ATTLIST name after state".
1297              push @{$self->{ct}->{attrdefs}}, $self->{ca};
1298              $self->{state} = AFTER_ATTLIST_ATTR_VALUE_QUOTED_STATE;
1299            } else {
1300              !!!cp (95);
1301              ## XML5: "Tag attribute name before state".
1302              $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;
1303            }
1304          !!!next-input-character;          !!!next-input-character;
1305          redo A;          redo A;
1306        } elsif ($self->{nc} == 0x0026) { # &        } elsif ($self->{nc} == 0x0026) { # &
1307          !!!cp (96);          !!!cp (96);
1308            ## XML5: Not defined yet.
1309    
1310          ## NOTE: In the spec, the tokenizer is switched to the          ## NOTE: In the spec, the tokenizer is switched to the
1311          ## "entity in attribute value state".  In this implementation, the          ## "entity in attribute value state".  In this implementation, the
1312          ## tokenizer is switched to the |ENTITY_STATE|, which is an          ## tokenizer is switched to the |ENTITY_STATE|, which is an
# Line 1173  sub _get_next_token ($) { Line 1321  sub _get_next_token ($) {
1321          if ($self->{ct}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1322            !!!cp (97);            !!!cp (97);
1323            $self->{last_stag_name} = $self->{ct}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1324    
1325              $self->{state} = DATA_STATE;
1326              $self->{s_kwd} = '';
1327              ## reconsume
1328              !!!emit ($self->{ct}); # start tag
1329              redo A;
1330          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1331            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1332            if ($self->{ct}->{attributes}) {            if ($self->{ct}->{attributes}) {
# Line 1182  sub _get_next_token ($) { Line 1336  sub _get_next_token ($) {
1336              ## NOTE: This state should never be reached.              ## NOTE: This state should never be reached.
1337              !!!cp (99);              !!!cp (99);
1338            }            }
1339    
1340              $self->{state} = DATA_STATE;
1341              $self->{s_kwd} = '';
1342              ## reconsume
1343              !!!emit ($self->{ct}); # end tag
1344              redo A;
1345            } elsif ($self->{ct}->{type} == ATTLIST_TOKEN) {
1346              ## XML5: No parse error above; not defined yet.
1347              push @{$self->{ct}->{attrdefs}}, $self->{ca};
1348              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1349              ## Reconsume.
1350              !!!emit ($self->{ct}); # ATTLIST
1351              redo A;
1352          } else {          } else {
1353            die "$0: $self->{ct}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1354          }          }
         $self->{state} = DATA_STATE;  
         $self->{s_kwd} = '';  
         ## reconsume  
   
         !!!emit ($self->{ct}); # start tag or end tag  
   
         redo A;  
1355        } else {        } else {
1356          !!!cp (100);          ## XML5 [ATTLIST]: Not defined yet.
1357            if ($self->{is_xml} and $self->{nc} == 0x003C) { # <
1358              !!!cp (100);
1359              ## XML5: Not a parse error.
1360              !!!parse-error (type => 'lt in attr value'); ## TODO: type
1361            } else {
1362              !!!cp (100.1);
1363            }
1364          $self->{ca}->{value} .= chr ($self->{nc});          $self->{ca}->{value} .= chr ($self->{nc});
1365          $self->{read_until}->($self->{ca}->{value},          $self->{read_until}->($self->{ca}->{value},
1366                                q["&],                                q["&<],
1367                                length $self->{ca}->{value});                                length $self->{ca}->{value});
1368    
1369          ## Stay in the state          ## Stay in the state
# Line 1204  sub _get_next_token ($) { Line 1371  sub _get_next_token ($) {
1371          redo A;          redo A;
1372        }        }
1373      } elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) {
1374          ## XML5: "Tag attribute value single quoted state" and "DOCTYPE
1375          ## ATTLIST attribute value single quoted state".
1376    
1377        if ($self->{nc} == 0x0027) { # '        if ($self->{nc} == 0x0027) { # '
1378          !!!cp (101);          if ($self->{ct}->{type} == ATTLIST_TOKEN) {
1379          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;            !!!cp (101.1);
1380              ## XML5: "DOCTYPE ATTLIST name after state".
1381              push @{$self->{ct}->{attrdefs}}, $self->{ca};
1382              $self->{state} = AFTER_ATTLIST_ATTR_VALUE_QUOTED_STATE;
1383            } else {
1384              !!!cp (101);
1385              ## XML5: "Before attribute name state" (sic).
1386              $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;
1387            }
1388          !!!next-input-character;          !!!next-input-character;
1389          redo A;          redo A;
1390        } elsif ($self->{nc} == 0x0026) { # &        } elsif ($self->{nc} == 0x0026) { # &
1391          !!!cp (102);          !!!cp (102);
1392            ## XML5: Not defined yet.
1393    
1394          ## NOTE: In the spec, the tokenizer is switched to the          ## NOTE: In the spec, the tokenizer is switched to the
1395          ## "entity in attribute value state".  In this implementation, the          ## "entity in attribute value state".  In this implementation, the
1396          ## tokenizer is switched to the |ENTITY_STATE|, which is an          ## tokenizer is switched to the |ENTITY_STATE|, which is an
# Line 1225  sub _get_next_token ($) { Line 1405  sub _get_next_token ($) {
1405          if ($self->{ct}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1406            !!!cp (103);            !!!cp (103);
1407            $self->{last_stag_name} = $self->{ct}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1408    
1409              $self->{state} = DATA_STATE;
1410              $self->{s_kwd} = '';
1411              ## reconsume
1412              !!!emit ($self->{ct}); # start tag
1413              redo A;
1414          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1415            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1416            if ($self->{ct}->{attributes}) {            if ($self->{ct}->{attributes}) {
# Line 1234  sub _get_next_token ($) { Line 1420  sub _get_next_token ($) {
1420              ## NOTE: This state should never be reached.              ## NOTE: This state should never be reached.
1421              !!!cp (105);              !!!cp (105);
1422            }            }
1423    
1424              $self->{state} = DATA_STATE;
1425              $self->{s_kwd} = '';
1426              ## reconsume
1427              !!!emit ($self->{ct}); # end tag
1428              redo A;
1429            } elsif ($self->{ct}->{type} == ATTLIST_TOKEN) {
1430              ## XML5: No parse error above; not defined yet.
1431              push @{$self->{ct}->{attrdefs}}, $self->{ca};
1432              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1433              ## Reconsume.
1434              !!!emit ($self->{ct}); # ATTLIST
1435              redo A;
1436          } else {          } else {
1437            die "$0: $self->{ct}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1438          }          }
         $self->{state} = DATA_STATE;  
         $self->{s_kwd} = '';  
         ## reconsume  
   
         !!!emit ($self->{ct}); # start tag or end tag  
   
         redo A;  
1439        } else {        } else {
1440          !!!cp (106);          ## XML5 [ATTLIST]: Not defined yet.
1441            if ($self->{is_xml} and $self->{nc} == 0x003C) { # <
1442              !!!cp (106);
1443              ## XML5: Not a parse error.
1444              !!!parse-error (type => 'lt in attr value'); ## TODO: type
1445            } else {
1446              !!!cp (106.1);
1447            }
1448          $self->{ca}->{value} .= chr ($self->{nc});          $self->{ca}->{value} .= chr ($self->{nc});
1449          $self->{read_until}->($self->{ca}->{value},          $self->{read_until}->($self->{ca}->{value},
1450                                q['&],                                q['&<],
1451                                length $self->{ca}->{value});                                length $self->{ca}->{value});
1452    
1453          ## Stay in the state          ## Stay in the state
# Line 1256  sub _get_next_token ($) { Line 1455  sub _get_next_token ($) {
1455          redo A;          redo A;
1456        }        }
1457      } elsif ($self->{state} == ATTRIBUTE_VALUE_UNQUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_UNQUOTED_STATE) {
1458          ## XML5: "Tag attribute value unquoted state".
1459    
1460        if ($is_space->{$self->{nc}}) {        if ($is_space->{$self->{nc}}) {
1461          !!!cp (107);          if ($self->{ct}->{type} == ATTLIST_TOKEN) {
1462          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;            !!!cp (107.1);
1463              push @{$self->{ct}->{attrdefs}}, $self->{ca};
1464              $self->{state} = DOCTYPE_ATTLIST_NAME_AFTER_STATE;
1465            } else {
1466              !!!cp (107);
1467              ## XML5: "Tag attribute name before state".
1468              $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1469            }
1470          !!!next-input-character;          !!!next-input-character;
1471          redo A;          redo A;
1472        } elsif ($self->{nc} == 0x0026) { # &        } elsif ($self->{nc} == 0x0026) { # &
1473          !!!cp (108);          !!!cp (108);
1474    
1475            ## XML5: Not defined yet.
1476    
1477          ## NOTE: In the spec, the tokenizer is switched to the          ## NOTE: In the spec, the tokenizer is switched to the
1478          ## "entity in attribute value state".  In this implementation, the          ## "entity in attribute value state".  In this implementation, the
1479          ## tokenizer is switched to the |ENTITY_STATE|, which is an          ## tokenizer is switched to the |ENTITY_STATE|, which is an
# Line 1276  sub _get_next_token ($) { Line 1487  sub _get_next_token ($) {
1487          if ($self->{ct}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1488            !!!cp (109);            !!!cp (109);
1489            $self->{last_stag_name} = $self->{ct}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1490    
1491              $self->{state} = DATA_STATE;
1492              $self->{s_kwd} = '';
1493              !!!next-input-character;
1494              !!!emit ($self->{ct}); # start tag
1495              redo A;
1496          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1497            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1498            if ($self->{ct}->{attributes}) {            if ($self->{ct}->{attributes}) {
# Line 1285  sub _get_next_token ($) { Line 1502  sub _get_next_token ($) {
1502              ## NOTE: This state should never be reached.              ## NOTE: This state should never be reached.
1503              !!!cp (111);              !!!cp (111);
1504            }            }
1505    
1506              $self->{state} = DATA_STATE;
1507              $self->{s_kwd} = '';
1508              !!!next-input-character;
1509              !!!emit ($self->{ct}); # end tag
1510              redo A;
1511            } elsif ($self->{ct}->{type} == ATTLIST_TOKEN) {
1512              push @{$self->{ct}->{attrdefs}}, $self->{ca};
1513              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1514              !!!next-input-character;
1515              !!!emit ($self->{ct}); # ATTLIST
1516              redo A;
1517          } else {          } else {
1518            die "$0: $self->{ct}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1519          }          }
         $self->{state} = DATA_STATE;  
         $self->{s_kwd} = '';  
         !!!next-input-character;  
   
         !!!emit ($self->{ct}); # start tag or end tag  
   
         redo A;  
1520        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
         !!!parse-error (type => 'unclosed tag');  
1521          if ($self->{ct}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1522            !!!cp (112);            !!!cp (112);
1523              !!!parse-error (type => 'unclosed tag');
1524            $self->{last_stag_name} = $self->{ct}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1525    
1526              $self->{state} = DATA_STATE;
1527              $self->{s_kwd} = '';
1528              ## reconsume
1529              !!!emit ($self->{ct}); # start tag
1530              redo A;
1531          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1532              !!!parse-error (type => 'unclosed tag');
1533            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1534            if ($self->{ct}->{attributes}) {            if ($self->{ct}->{attributes}) {
1535              !!!cp (113);              !!!cp (113);
# Line 1309  sub _get_next_token ($) { Line 1538  sub _get_next_token ($) {
1538              ## NOTE: This state should never be reached.              ## NOTE: This state should never be reached.
1539              !!!cp (114);              !!!cp (114);
1540            }            }
1541    
1542              $self->{state} = DATA_STATE;
1543              $self->{s_kwd} = '';
1544              ## reconsume
1545              !!!emit ($self->{ct}); # end tag
1546              redo A;
1547            } elsif ($self->{ct}->{type} == ATTLIST_TOKEN) {
1548              !!!parse-error (type => 'unclosed md'); ## TODO: type
1549              push @{$self->{ct}->{attrdefs}}, $self->{ca};
1550              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1551              ## Reconsume.
1552              !!!emit ($self->{ct}); # ATTLIST
1553              redo A;
1554          } else {          } else {
1555            die "$0: $self->{ct}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1556          }          }
         $self->{state} = DATA_STATE;  
         $self->{s_kwd} = '';  
         ## reconsume  
   
         !!!emit ($self->{ct}); # start tag or end tag  
   
         redo A;  
1557        } else {        } else {
1558          if ({          if ({
1559               0x0022 => 1, # "               0x0022 => 1, # "
# Line 1326  sub _get_next_token ($) { Line 1561  sub _get_next_token ($) {
1561               0x003D => 1, # =               0x003D => 1, # =
1562              }->{$self->{nc}}) {              }->{$self->{nc}}) {
1563            !!!cp (115);            !!!cp (115);
1564              ## XML5: Not a parse error.
1565            !!!parse-error (type => 'bad attribute value');            !!!parse-error (type => 'bad attribute value');
1566          } else {          } else {
1567            !!!cp (116);            !!!cp (116);
# Line 1402  sub _get_next_token ($) { Line 1638  sub _get_next_token ($) {
1638          redo A;          redo A;
1639        }        }
1640      } elsif ($self->{state} == SELF_CLOSING_START_TAG_STATE) {      } elsif ($self->{state} == SELF_CLOSING_START_TAG_STATE) {
1641          ## XML5: "Empty tag state".
1642    
1643        if ($self->{nc} == 0x003E) { # >        if ($self->{nc} == 0x003E) { # >
1644          if ($self->{ct}->{type} == END_TAG_TOKEN) {          if ($self->{ct}->{type} == END_TAG_TOKEN) {
1645            !!!cp ('124.2');            !!!cp ('124.2');
# Line 1443  sub _get_next_token ($) { Line 1681  sub _get_next_token ($) {
1681          } else {          } else {
1682            die "$0: $self->{ct}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1683          }          }
1684            ## XML5: "Tag attribute name before state".
1685          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
1686          $self->{s_kwd} = '';          $self->{s_kwd} = '';
1687          ## Reconsume.          ## Reconsume.
# Line 1457  sub _get_next_token ($) { Line 1696  sub _get_next_token ($) {
1696          redo A;          redo A;
1697        }        }
1698      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {
1699        ## (only happen if PCDATA state)        ## XML5: "Bogus comment state" and "DOCTYPE bogus comment state".
1700    
1701        ## NOTE: Unlike spec's "bogus comment state", this implementation        ## NOTE: Unlike spec's "bogus comment state", this implementation
1702        ## consumes characters one-by-one basis.        ## consumes characters one-by-one basis.
1703                
1704        if ($self->{nc} == 0x003E) { # >        if ($self->{nc} == 0x003E) { # >
1705          !!!cp (124);          if ($self->{in_subset}) {
1706          $self->{state} = DATA_STATE;            !!!cp (123);
1707          $self->{s_kwd} = '';            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1708            } else {
1709              !!!cp (124);
1710              $self->{state} = DATA_STATE;
1711              $self->{s_kwd} = '';
1712            }
1713          !!!next-input-character;          !!!next-input-character;
1714    
1715          !!!emit ($self->{ct}); # comment          !!!emit ($self->{ct}); # comment
1716          redo A;          redo A;
1717        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
1718          !!!cp (125);          if ($self->{in_subset}) {
1719          $self->{state} = DATA_STATE;            !!!cp (125.1);
1720          $self->{s_kwd} = '';            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1721            } else {
1722              !!!cp (125);
1723              $self->{state} = DATA_STATE;
1724              $self->{s_kwd} = '';
1725            }
1726          ## reconsume          ## reconsume
1727    
1728          !!!emit ($self->{ct}); # comment          !!!emit ($self->{ct}); # comment
# Line 1490  sub _get_next_token ($) { Line 1739  sub _get_next_token ($) {
1739          redo A;          redo A;
1740        }        }
1741      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {
1742        ## (only happen if PCDATA state)        ## XML5: "Markup declaration state".
1743                
1744        if ($self->{nc} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
1745          !!!cp (133);          !!!cp (133);
# Line 1502  sub _get_next_token ($) { Line 1751  sub _get_next_token ($) {
1751          ## ASCII case-insensitive.          ## ASCII case-insensitive.
1752          !!!cp (130);          !!!cp (130);
1753          $self->{state} = MD_DOCTYPE_STATE;          $self->{state} = MD_DOCTYPE_STATE;
1754          $self->{s_kwd} = chr $self->{nc};          $self->{kwd} = chr $self->{nc};
1755          !!!next-input-character;          !!!next-input-character;
1756          redo A;          redo A;
1757        } elsif ((($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and        } elsif ((($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and
# Line 1511  sub _get_next_token ($) { Line 1760  sub _get_next_token ($) {
1760                 $self->{nc} == 0x005B) { # [                 $self->{nc} == 0x005B) { # [
1761          !!!cp (135.4);                          !!!cp (135.4);                
1762          $self->{state} = MD_CDATA_STATE;          $self->{state} = MD_CDATA_STATE;
1763          $self->{s_kwd} = '[';          $self->{kwd} = '[';
1764          !!!next-input-character;          !!!next-input-character;
1765          redo A;          redo A;
1766        } else {        } else {
# Line 1561  sub _get_next_token ($) { Line 1810  sub _get_next_token ($) {
1810              0x0054, # T              0x0054, # T
1811              0x0059, # Y              0x0059, # Y
1812              0x0050, # P              0x0050, # P
1813            ]->[length $self->{s_kwd}] or            ]->[length $self->{kwd}] or
1814            $self->{nc} == [            $self->{nc} == [
1815              undef,              undef,
1816              0x006F, # o              0x006F, # o
# Line 1569  sub _get_next_token ($) { Line 1818  sub _get_next_token ($) {
1818              0x0074, # t              0x0074, # t
1819              0x0079, # y              0x0079, # y
1820              0x0070, # p              0x0070, # p
1821            ]->[length $self->{s_kwd}]) {            ]->[length $self->{kwd}]) {
1822          !!!cp (131);          !!!cp (131);
1823          ## Stay in the state.          ## Stay in the state.
1824          $self->{s_kwd} .= chr $self->{nc};          $self->{kwd} .= chr $self->{nc};
1825          !!!next-input-character;          !!!next-input-character;
1826          redo A;          redo A;
1827        } elsif ((length $self->{s_kwd}) == 6 and        } elsif ((length $self->{kwd}) == 6 and
1828                 ($self->{nc} == 0x0045 or # E                 ($self->{nc} == 0x0045 or # E
1829                  $self->{nc} == 0x0065)) { # e                  $self->{nc} == 0x0065)) { # e
1830          if ($self->{s_kwd} ne 'DOCTYP') {          if ($self->{is_xml} and
1831                ($self->{kwd} ne 'DOCTYP' or $self->{nc} == 0x0065)) {
1832            !!!cp (129);            !!!cp (129);
1833            ## XML5: case-sensitive.            ## XML5: case-sensitive.
1834            !!!parse-error (type => 'lowercase keyword', ## TODO            !!!parse-error (type => 'lowercase keyword', ## TODO
# Line 1600  sub _get_next_token ($) { Line 1850  sub _get_next_token ($) {
1850          !!!cp (132);                  !!!cp (132);        
1851          !!!parse-error (type => 'bogus comment',          !!!parse-error (type => 'bogus comment',
1852                          line => $self->{line_prev},                          line => $self->{line_prev},
1853                          column => $self->{column_prev} - 1 - length $self->{s_kwd});                          column => $self->{column_prev} - 1 - length $self->{kwd});
1854          $self->{state} = BOGUS_COMMENT_STATE;          $self->{state} = BOGUS_COMMENT_STATE;
1855          ## Reconsume.          ## Reconsume.
1856          $self->{ct} = {type => COMMENT_TOKEN,          $self->{ct} = {type => COMMENT_TOKEN,
1857                                    data => $self->{s_kwd},                                    data => $self->{kwd},
1858                                    line => $self->{line_prev},                                    line => $self->{line_prev},
1859                                    column => $self->{column_prev} - 1 - length $self->{s_kwd},                                    column => $self->{column_prev} - 1 - length $self->{kwd},
1860                                   };                                   };
1861          redo A;          redo A;
1862        }        }
# Line 1617  sub _get_next_token ($) { Line 1867  sub _get_next_token ($) {
1867              '[CD' => 0x0041, # A              '[CD' => 0x0041, # A
1868              '[CDA' => 0x0054, # T              '[CDA' => 0x0054, # T
1869              '[CDAT' => 0x0041, # A              '[CDAT' => 0x0041, # A
1870            }->{$self->{s_kwd}}) {            }->{$self->{kwd}}) {
1871          !!!cp (135.1);          !!!cp (135.1);
1872          ## Stay in the state.          ## Stay in the state.
1873          $self->{s_kwd} .= chr $self->{nc};          $self->{kwd} .= chr $self->{nc};
1874          !!!next-input-character;          !!!next-input-character;
1875          redo A;          redo A;
1876        } elsif ($self->{s_kwd} eq '[CDATA' and        } elsif ($self->{kwd} eq '[CDATA' and
1877                 $self->{nc} == 0x005B) { # [                 $self->{nc} == 0x005B) { # [
1878          if ($self->{is_xml} and          if ($self->{is_xml} and
1879              not $self->{tainted} and              not $self->{tainted} and
# Line 1648  sub _get_next_token ($) { Line 1898  sub _get_next_token ($) {
1898          !!!cp (135.3);          !!!cp (135.3);
1899          !!!parse-error (type => 'bogus comment',          !!!parse-error (type => 'bogus comment',
1900                          line => $self->{line_prev},                          line => $self->{line_prev},
1901                          column => $self->{column_prev} - 1 - length $self->{s_kwd});                          column => $self->{column_prev} - 1 - length $self->{kwd});
1902          $self->{state} = BOGUS_COMMENT_STATE;          $self->{state} = BOGUS_COMMENT_STATE;
1903          ## Reconsume.          ## Reconsume.
1904          $self->{ct} = {type => COMMENT_TOKEN,          $self->{ct} = {type => COMMENT_TOKEN,
1905                                    data => $self->{s_kwd},                                    data => $self->{kwd},
1906                                    line => $self->{line_prev},                                    line => $self->{line_prev},
1907                                    column => $self->{column_prev} - 1 - length $self->{s_kwd},                                    column => $self->{column_prev} - 1 - length $self->{kwd},
1908                                   };                                   };
1909          redo A;          redo A;
1910        }        }
# Line 1665  sub _get_next_token ($) { Line 1915  sub _get_next_token ($) {
1915          !!!next-input-character;          !!!next-input-character;
1916          redo A;          redo A;
1917        } elsif ($self->{nc} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
         !!!cp (138);  
1918          !!!parse-error (type => 'bogus comment');          !!!parse-error (type => 'bogus comment');
1919          $self->{state} = DATA_STATE;          if ($self->{in_subset}) {
1920          $self->{s_kwd} = '';            !!!cp (138.1);
1921              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1922            } else {
1923              !!!cp (138);
1924              $self->{state} = DATA_STATE;
1925              $self->{s_kwd} = '';
1926            }
1927          !!!next-input-character;          !!!next-input-character;
1928    
1929          !!!emit ($self->{ct}); # comment          !!!emit ($self->{ct}); # comment
1930    
1931          redo A;          redo A;
1932        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
         !!!cp (139);  
1933          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
1934          $self->{state} = DATA_STATE;          if ($self->{in_subset}) {
1935          $self->{s_kwd} = '';            !!!cp (139.1);
1936              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1937            } else {
1938              !!!cp (139);
1939              $self->{state} = DATA_STATE;
1940              $self->{s_kwd} = '';
1941            }
1942          ## reconsume          ## reconsume
1943    
1944          !!!emit ($self->{ct}); # comment          !!!emit ($self->{ct}); # comment
# Line 1699  sub _get_next_token ($) { Line 1959  sub _get_next_token ($) {
1959          !!!next-input-character;          !!!next-input-character;
1960          redo A;          redo A;
1961        } elsif ($self->{nc} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
         !!!cp (142);  
1962          !!!parse-error (type => 'bogus comment');          !!!parse-error (type => 'bogus comment');
1963          $self->{state} = DATA_STATE;          if ($self->{in_subset}) {
1964          $self->{s_kwd} = '';            !!!cp (142.1);
1965              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1966            } else {
1967              !!!cp (142);
1968              $self->{state} = DATA_STATE;
1969              $self->{s_kwd} = '';
1970            }
1971          !!!next-input-character;          !!!next-input-character;
1972    
1973          !!!emit ($self->{ct}); # comment          !!!emit ($self->{ct}); # comment
1974    
1975          redo A;          redo A;
1976        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
         !!!cp (143);  
1977          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
1978          $self->{state} = DATA_STATE;          if ($self->{in_subset}) {
1979          $self->{s_kwd} = '';            !!!cp (143.1);
1980              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1981            } else {
1982              !!!cp (143);
1983              $self->{state} = DATA_STATE;
1984              $self->{s_kwd} = '';
1985            }
1986          ## reconsume          ## reconsume
1987    
1988          !!!emit ($self->{ct}); # comment          !!!emit ($self->{ct}); # comment
# Line 1727  sub _get_next_token ($) { Line 1997  sub _get_next_token ($) {
1997          redo A;          redo A;
1998        }        }
1999      } elsif ($self->{state} == COMMENT_STATE) {      } elsif ($self->{state} == COMMENT_STATE) {
2000          ## XML5: "Comment state" and "DOCTYPE comment state".
2001    
2002        if ($self->{nc} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
2003          !!!cp (145);          !!!cp (145);
2004          $self->{state} = COMMENT_END_DASH_STATE;          $self->{state} = COMMENT_END_DASH_STATE;
2005          !!!next-input-character;          !!!next-input-character;
2006          redo A;          redo A;
2007        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
         !!!cp (146);  
2008          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
2009          $self->{state} = DATA_STATE;          if ($self->{in_subset}) {
2010          $self->{s_kwd} = '';            !!!cp (146.1);
2011              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2012            } else {
2013              !!!cp (146);
2014              $self->{state} = DATA_STATE;
2015              $self->{s_kwd} = '';
2016            }
2017          ## reconsume          ## reconsume
2018    
2019          !!!emit ($self->{ct}); # comment          !!!emit ($self->{ct}); # comment
# Line 1754  sub _get_next_token ($) { Line 2031  sub _get_next_token ($) {
2031          redo A;          redo A;
2032        }        }
2033      } elsif ($self->{state} == COMMENT_END_DASH_STATE) {      } elsif ($self->{state} == COMMENT_END_DASH_STATE) {
2034        ## XML5: "comment dash state".        ## XML5: "Comment dash state" and "DOCTYPE comment dash state".
2035    
2036        if ($self->{nc} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
2037          !!!cp (148);          !!!cp (148);
# Line 1762  sub _get_next_token ($) { Line 2039  sub _get_next_token ($) {
2039          !!!next-input-character;          !!!next-input-character;
2040          redo A;          redo A;
2041        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
         !!!cp (149);  
2042          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
2043          $self->{s_kwd} = '';          if ($self->{in_subset}) {
2044          $self->{state} = DATA_STATE;            !!!cp (149.1);
2045          $self->{s_kwd} = '';            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2046            } else {
2047              !!!cp (149);
2048              $self->{state} = DATA_STATE;
2049              $self->{s_kwd} = '';
2050            }
2051          ## reconsume          ## reconsume
2052    
2053          !!!emit ($self->{ct}); # comment          !!!emit ($self->{ct}); # comment
# Line 1780  sub _get_next_token ($) { Line 2061  sub _get_next_token ($) {
2061          redo A;          redo A;
2062        }        }
2063      } elsif ($self->{state} == COMMENT_END_STATE) {      } elsif ($self->{state} == COMMENT_END_STATE) {
2064          ## XML5: "Comment end state" and "DOCTYPE comment end state".
2065    
2066        if ($self->{nc} == 0x003E) { # >        if ($self->{nc} == 0x003E) { # >
2067          !!!cp (151);          if ($self->{in_subset}) {
2068          $self->{state} = DATA_STATE;            !!!cp (151.1);
2069          $self->{s_kwd} = '';            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2070            } else {
2071              !!!cp (151);
2072              $self->{state} = DATA_STATE;
2073              $self->{s_kwd} = '';
2074            }
2075          !!!next-input-character;          !!!next-input-character;
2076    
2077          !!!emit ($self->{ct}); # comment          !!!emit ($self->{ct}); # comment
# Line 1800  sub _get_next_token ($) { Line 2088  sub _get_next_token ($) {
2088          !!!next-input-character;          !!!next-input-character;
2089          redo A;          redo A;
2090        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
         !!!cp (153);  
2091          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
2092          $self->{state} = DATA_STATE;          if ($self->{in_subset}) {
2093          $self->{s_kwd} = '';            !!!cp (153.1);
2094              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2095            } else {
2096              !!!cp (153);
2097              $self->{state} = DATA_STATE;
2098              $self->{s_kwd} = '';
2099            }
2100          ## reconsume          ## reconsume
2101    
2102          !!!emit ($self->{ct}); # comment          !!!emit ($self->{ct}); # comment
# Line 1828  sub _get_next_token ($) { Line 2121  sub _get_next_token ($) {
2121          redo A;          redo A;
2122        } else {        } else {
2123          !!!cp (156);          !!!cp (156);
2124            ## XML5: Unless EOF, swith to the bogus comment state.
2125          !!!parse-error (type => 'no space before DOCTYPE name');          !!!parse-error (type => 'no space before DOCTYPE name');
2126          $self->{state} = BEFORE_DOCTYPE_NAME_STATE;          $self->{state} = BEFORE_DOCTYPE_NAME_STATE;
2127          ## reconsume          ## reconsume
2128          redo A;          redo A;
2129        }        }
2130      } elsif ($self->{state} == BEFORE_DOCTYPE_NAME_STATE) {      } elsif ($self->{state} == BEFORE_DOCTYPE_NAME_STATE) {
2131          ## XML5: "DOCTYPE root name before state".
2132    
2133        if ($is_space->{$self->{nc}}) {        if ($is_space->{$self->{nc}}) {
2134          !!!cp (157);          !!!cp (157);
2135          ## Stay in the state          ## Stay in the state
# Line 1841  sub _get_next_token ($) { Line 2137  sub _get_next_token ($) {
2137          redo A;          redo A;
2138        } elsif ($self->{nc} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2139          !!!cp (158);          !!!cp (158);
2140            ## XML5: No parse error.
2141          !!!parse-error (type => 'no DOCTYPE name');          !!!parse-error (type => 'no DOCTYPE name');
2142          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2143          $self->{s_kwd} = '';          $self->{s_kwd} = '';
# Line 1859  sub _get_next_token ($) { Line 2156  sub _get_next_token ($) {
2156          !!!emit ($self->{ct}); # DOCTYPE (quirks)          !!!emit ($self->{ct}); # DOCTYPE (quirks)
2157    
2158          redo A;          redo A;
2159          } elsif ($self->{is_xml} and $self->{nc} == 0x005B) { # [
2160            !!!cp (159.1);
2161            !!!parse-error (type => 'no DOCTYPE name');
2162            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2163            $self->{ct}->{has_internal_subset} = 1; # DOCTYPE
2164            $self->{in_subset} = 1;
2165            !!!next-input-character;
2166            !!!emit ($self->{ct}); # DOCTYPE
2167            redo A;
2168        } else {        } else {
2169          !!!cp (160);          !!!cp (160);
2170          $self->{ct}->{name} = chr $self->{nc};          $self->{ct}->{name} = chr $self->{nc};
# Line 1868  sub _get_next_token ($) { Line 2174  sub _get_next_token ($) {
2174          redo A;          redo A;
2175        }        }
2176      } elsif ($self->{state} == DOCTYPE_NAME_STATE) {      } elsif ($self->{state} == DOCTYPE_NAME_STATE) {
2177  ## ISSUE: Redundant "First," in the spec.        ## XML5: "DOCTYPE root name state".
2178    
2179          ## ISSUE: Redundant "First," in the spec.
2180    
2181        if ($is_space->{$self->{nc}}) {        if ($is_space->{$self->{nc}}) {
2182          !!!cp (161);          !!!cp (161);
2183          $self->{state} = AFTER_DOCTYPE_NAME_STATE;          $self->{state} = AFTER_DOCTYPE_NAME_STATE;
# Line 1894  sub _get_next_token ($) { Line 2203  sub _get_next_token ($) {
2203          !!!emit ($self->{ct}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2204    
2205          redo A;          redo A;
2206          } elsif ($self->{is_xml} and $self->{nc} == 0x005B) { # [
2207            !!!cp (163.1);
2208            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2209            $self->{ct}->{has_internal_subset} = 1; # DOCTYPE
2210            $self->{in_subset} = 1;
2211            !!!next-input-character;
2212            !!!emit ($self->{ct}); # DOCTYPE
2213            redo A;
2214        } else {        } else {
2215          !!!cp (164);          !!!cp (164);
2216          $self->{ct}->{name}          $self->{ct}->{name}
# Line 1903  sub _get_next_token ($) { Line 2220  sub _get_next_token ($) {
2220          redo A;          redo A;
2221        }        }
2222      } elsif ($self->{state} == AFTER_DOCTYPE_NAME_STATE) {      } elsif ($self->{state} == AFTER_DOCTYPE_NAME_STATE) {
2223          ## XML5: Corresponding to XML5's "DOCTYPE root name after
2224          ## state", but implemented differently.
2225    
2226        if ($is_space->{$self->{nc}}) {        if ($is_space->{$self->{nc}}) {
2227          !!!cp (165);          !!!cp (165);
2228          ## Stay in the state          ## Stay in the state
2229          !!!next-input-character;          !!!next-input-character;
2230          redo A;          redo A;
2231        } elsif ($self->{nc} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2232          !!!cp (166);          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2233          $self->{state} = DATA_STATE;            !!!cp (166);
2234          $self->{s_kwd} = '';            $self->{state} = DATA_STATE;
2235              $self->{s_kwd} = '';
2236            } else {
2237              !!!cp (166.1);
2238              !!!parse-error (type => 'no md def'); ## TODO: type
2239              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2240            }
2241            
2242          !!!next-input-character;          !!!next-input-character;
2243            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
         !!!emit ($self->{ct}); # DOCTYPE  
   
2244          redo A;          redo A;
2245        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
2246          !!!cp (167);          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2247          !!!parse-error (type => 'unclosed DOCTYPE');            !!!cp (167);
2248          $self->{state} = DATA_STATE;            !!!parse-error (type => 'unclosed DOCTYPE');
2249          $self->{s_kwd} = '';            $self->{state} = DATA_STATE;
2250          ## reconsume            $self->{s_kwd} = '';
2251              $self->{ct}->{quirks} = 1;
2252          $self->{ct}->{quirks} = 1;          } else {
2253          !!!emit ($self->{ct}); # DOCTYPE            !!!cp (167.12);
2254              !!!parse-error (type => 'unclosed md'); ## TODO: type
2255              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2256            }
2257            
2258            ## Reconsume.
2259            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2260          redo A;          redo A;
2261        } elsif ($self->{nc} == 0x0050 or # P        } elsif ($self->{nc} == 0x0050 or # P
2262                 $self->{nc} == 0x0070) { # p                 $self->{nc} == 0x0070) { # p
2263            !!!cp (167.1);
2264          $self->{state} = PUBLIC_STATE;          $self->{state} = PUBLIC_STATE;
2265          $self->{s_kwd} = chr $self->{nc};          $self->{kwd} = chr $self->{nc};
2266          !!!next-input-character;          !!!next-input-character;
2267          redo A;          redo A;
2268        } elsif ($self->{nc} == 0x0053 or # S        } elsif ($self->{nc} == 0x0053 or # S
2269                 $self->{nc} == 0x0073) { # s                 $self->{nc} == 0x0073) { # s
2270            !!!cp (167.2);
2271          $self->{state} = SYSTEM_STATE;          $self->{state} = SYSTEM_STATE;
2272          $self->{s_kwd} = chr $self->{nc};          $self->{kwd} = chr $self->{nc};
2273            !!!next-input-character;
2274            redo A;
2275          } elsif ($self->{nc} == 0x0022 and # "
2276                   ($self->{ct}->{type} == GENERAL_ENTITY_TOKEN or
2277                    $self->{ct}->{type} == PARAMETER_ENTITY_TOKEN)) {
2278            !!!cp (167.21);
2279            $self->{state} = DOCTYPE_ENTITY_VALUE_DOUBLE_QUOTED_STATE;
2280            $self->{ct}->{value} = ''; # ENTITY
2281          !!!next-input-character;          !!!next-input-character;
2282          redo A;          redo A;
2283          } elsif ($self->{nc} == 0x0027 and # '
2284                   ($self->{ct}->{type} == GENERAL_ENTITY_TOKEN or
2285                    $self->{ct}->{type} == PARAMETER_ENTITY_TOKEN)) {
2286            !!!cp (167.22);
2287            $self->{state} = DOCTYPE_ENTITY_VALUE_SINGLE_QUOTED_STATE;
2288            $self->{ct}->{value} = ''; # ENTITY
2289            !!!next-input-character;
2290            redo A;
2291          } elsif ($self->{is_xml} and
2292                   $self->{ct}->{type} == DOCTYPE_TOKEN and
2293                   $self->{nc} == 0x005B) { # [
2294            !!!cp (167.3);
2295            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2296            $self->{ct}->{has_internal_subset} = 1; # DOCTYPE
2297            $self->{in_subset} = 1;
2298            !!!next-input-character;
2299            !!!emit ($self->{ct}); # DOCTYPE
2300            redo A;
2301        } else {        } else {
2302          !!!cp (180);          !!!parse-error (type => 'string after DOCTYPE name'); ## TODO: type
2303          !!!parse-error (type => 'string after DOCTYPE name');  
2304          $self->{ct}->{quirks} = 1;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2305              !!!cp (180);
2306              $self->{ct}->{quirks} = 1;
2307              $self->{state} = BOGUS_DOCTYPE_STATE;
2308            } else {
2309              !!!cp (180.1);
2310              $self->{state} = BOGUS_MD_STATE;
2311            }
2312    
         $self->{state} = BOGUS_DOCTYPE_STATE;  
2313          !!!next-input-character;          !!!next-input-character;
2314          redo A;          redo A;
2315        }        }
# Line 1957  sub _get_next_token ($) { Line 2321  sub _get_next_token ($) {
2321              0x0042, # B              0x0042, # B
2322              0x004C, # L              0x004C, # L
2323              0x0049, # I              0x0049, # I
2324            ]->[length $self->{s_kwd}] or            ]->[length $self->{kwd}] or
2325            $self->{nc} == [            $self->{nc} == [
2326              undef,              undef,
2327              0x0075, # u              0x0075, # u
2328              0x0062, # b              0x0062, # b
2329              0x006C, # l              0x006C, # l
2330              0x0069, # i              0x0069, # i
2331            ]->[length $self->{s_kwd}]) {            ]->[length $self->{kwd}]) {
2332          !!!cp (175);          !!!cp (175);
2333          ## Stay in the state.          ## Stay in the state.
2334          $self->{s_kwd} .= chr $self->{nc};          $self->{kwd} .= chr $self->{nc};
2335          !!!next-input-character;          !!!next-input-character;
2336          redo A;          redo A;
2337        } elsif ((length $self->{s_kwd}) == 5 and        } elsif ((length $self->{kwd}) == 5 and
2338                 ($self->{nc} == 0x0043 or # C                 ($self->{nc} == 0x0043 or # C
2339                  $self->{nc} == 0x0063)) { # c                  $self->{nc} == 0x0063)) { # c
2340          !!!cp (168);          if ($self->{is_xml} and
2341                ($self->{kwd} ne 'PUBLI' or $self->{nc} == 0x0063)) { # c
2342              !!!cp (168.1);
2343              !!!parse-error (type => 'lowercase keyword', ## TODO: type
2344                              text => 'PUBLIC',
2345                              line => $self->{line_prev},
2346                              column => $self->{column_prev} - 4);
2347            } else {
2348              !!!cp (168);
2349            }
2350          $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;          $self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
2351          !!!next-input-character;          !!!next-input-character;
2352          redo A;          redo A;
2353        } else {        } else {
2354          !!!cp (169);          !!!parse-error (type => 'string after DOCTYPE name', ## TODO: type
         !!!parse-error (type => 'string after DOCTYPE name',  
2355                          line => $self->{line_prev},                          line => $self->{line_prev},
2356                          column => $self->{column_prev} + 1 - length $self->{s_kwd});                          column => $self->{column_prev} + 1 - length $self->{kwd});
2357          $self->{ct}->{quirks} = 1;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2358              !!!cp (169);
2359          $self->{state} = BOGUS_DOCTYPE_STATE;            $self->{ct}->{quirks} = 1;
2360              $self->{state} = BOGUS_DOCTYPE_STATE;
2361            } else {
2362              !!!cp (169.1);
2363              $self->{state} = BOGUS_MD_STATE;
2364            }
2365          ## Reconsume.          ## Reconsume.
2366          redo A;          redo A;
2367        }        }
# Line 1996  sub _get_next_token ($) { Line 2373  sub _get_next_token ($) {
2373              0x0053, # S              0x0053, # S
2374              0x0054, # T              0x0054, # T
2375              0x0045, # E              0x0045, # E
2376            ]->[length $self->{s_kwd}] or            ]->[length $self->{kwd}] or
2377            $self->{nc} == [            $self->{nc} == [
2378              undef,              undef,
2379              0x0079, # y              0x0079, # y
2380              0x0073, # s              0x0073, # s
2381              0x0074, # t              0x0074, # t
2382              0x0065, # e              0x0065, # e
2383            ]->[length $self->{s_kwd}]) {            ]->[length $self->{kwd}]) {
2384          !!!cp (170);          !!!cp (170);
2385          ## Stay in the state.          ## Stay in the state.
2386          $self->{s_kwd} .= chr $self->{nc};          $self->{kwd} .= chr $self->{nc};
2387          !!!next-input-character;          !!!next-input-character;
2388          redo A;          redo A;
2389        } elsif ((length $self->{s_kwd}) == 5 and        } elsif ((length $self->{kwd}) == 5 and
2390                 ($self->{nc} == 0x004D or # M                 ($self->{nc} == 0x004D or # M
2391                  $self->{nc} == 0x006D)) { # m                  $self->{nc} == 0x006D)) { # m
2392          !!!cp (171);          if ($self->{is_xml} and
2393                ($self->{kwd} ne 'SYSTE' or $self->{nc} == 0x006D)) { # m
2394              !!!cp (171.1);
2395              !!!parse-error (type => 'lowercase keyword', ## TODO: type
2396                              text => 'SYSTEM',
2397                              line => $self->{line_prev},
2398                              column => $self->{column_prev} - 4);
2399            } else {
2400              !!!cp (171);
2401            }
2402          $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;          $self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2403          !!!next-input-character;          !!!next-input-character;
2404          redo A;          redo A;
2405        } else {        } else {
2406          !!!cp (172);          !!!parse-error (type => 'string after DOCTYPE name', ## TODO: type
         !!!parse-error (type => 'string after DOCTYPE name',  
2407                          line => $self->{line_prev},                          line => $self->{line_prev},
2408                          column => $self->{column_prev} + 1 - length $self->{s_kwd});                          column => $self->{column_prev} + 1 - length $self->{kwd});
2409          $self->{ct}->{quirks} = 1;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2410              !!!cp (172);
2411          $self->{state} = BOGUS_DOCTYPE_STATE;            $self->{ct}->{quirks} = 1;
2412              $self->{state} = BOGUS_DOCTYPE_STATE;
2413            } else {
2414              !!!cp (172.1);
2415              $self->{state} = BOGUS_MD_STATE;
2416            }
2417          ## Reconsume.          ## Reconsume.
2418          redo A;          redo A;
2419        }        }
# Line 2046  sub _get_next_token ($) { Line 2436  sub _get_next_token ($) {
2436          !!!next-input-character;          !!!next-input-character;
2437          redo A;          redo A;
2438        } elsif ($self->{nc} eq 0x003E) { # >        } elsif ($self->{nc} eq 0x003E) { # >
         !!!cp (184);  
2439          !!!parse-error (type => 'no PUBLIC literal');          !!!parse-error (type => 'no PUBLIC literal');
2440            
2441          $self->{state} = DATA_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2442          $self->{s_kwd} = '';            !!!cp (184);
2443              $self->{state} = DATA_STATE;
2444              $self->{s_kwd} = '';
2445              $self->{ct}->{quirks} = 1;
2446            } else {
2447              !!!cp (184.1);
2448              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2449            }
2450            
2451          !!!next-input-character;          !!!next-input-character;
2452            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
         $self->{ct}->{quirks} = 1;  
         !!!emit ($self->{ct}); # DOCTYPE  
   
2453          redo A;          redo A;
2454        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
2455          !!!cp (185);          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2456          !!!parse-error (type => 'unclosed DOCTYPE');            !!!cp (185);
2457              !!!parse-error (type => 'unclosed DOCTYPE');
2458          $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
2459          $self->{s_kwd} = '';            $self->{s_kwd} = '';
2460              $self->{ct}->{quirks} = 1;
2461            } else {
2462              !!!cp (185.1);
2463              !!!parse-error (type => 'unclosed md'); ## TODO: type
2464              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2465            }
2466            
2467          ## reconsume          ## reconsume
   
         $self->{ct}->{quirks} = 1;  
2468          !!!emit ($self->{ct}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2469            redo A;
2470          } elsif ($self->{is_xml} and
2471                   $self->{ct}->{type} == DOCTYPE_TOKEN and
2472                   $self->{nc} == 0x005B) { # [
2473            !!!cp (186.1);
2474            !!!parse-error (type => 'no PUBLIC literal');
2475            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2476            $self->{ct}->{has_internal_subset} = 1; # DOCTYPE
2477            $self->{in_subset} = 1;
2478            !!!next-input-character;
2479            !!!emit ($self->{ct}); # DOCTYPE
2480          redo A;          redo A;
2481        } else {        } else {
         !!!cp (186);  
2482          !!!parse-error (type => 'string after PUBLIC');          !!!parse-error (type => 'string after PUBLIC');
         $self->{ct}->{quirks} = 1;  
2483    
2484          $self->{state} = BOGUS_DOCTYPE_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2485              !!!cp (186);
2486              $self->{ct}->{quirks} = 1;
2487              $self->{state} = BOGUS_DOCTYPE_STATE;
2488            } else {
2489              !!!cp (186.2);
2490              $self->{state} = BOGUS_MD_STATE;
2491            }
2492    
2493          !!!next-input-character;          !!!next-input-character;
2494          redo A;          redo A;
2495        }        }
# Line 2085  sub _get_next_token ($) { Line 2500  sub _get_next_token ($) {
2500          !!!next-input-character;          !!!next-input-character;
2501          redo A;          redo A;
2502        } elsif ($self->{nc} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
         !!!cp (188);  
2503          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2504    
2505          $self->{state} = DATA_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2506          $self->{s_kwd} = '';            !!!cp (188);
2507          !!!next-input-character;            $self->{state} = DATA_STATE;
2508              $self->{s_kwd} = '';
2509          $self->{ct}->{quirks} = 1;            $self->{ct}->{quirks} = 1;
2510          !!!emit ($self->{ct}); # DOCTYPE          } else {
2511              !!!cp (188.1);
2512              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2513            }
2514    
2515            !!!next-input-character;
2516            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2517          redo A;          redo A;
2518        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
         !!!cp (189);  
2519          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2520    
2521          $self->{state} = DATA_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2522          $self->{s_kwd} = '';            !!!cp (189);
2523          ## reconsume            $self->{state} = DATA_STATE;
2524              $self->{s_kwd} = '';
2525          $self->{ct}->{quirks} = 1;            $self->{ct}->{quirks} = 1;
2526            } else {
2527              !!!cp (189.1);
2528              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2529            }
2530            
2531            ## Reconsume.
2532          !!!emit ($self->{ct}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
   
2533          redo A;          redo A;
2534        } else {        } else {
2535          !!!cp (190);          !!!cp (190);
2536          $self->{ct}->{pubid} # DOCTYPE          $self->{ct}->{pubid} .= chr $self->{nc}; # DOCTYPE/ENTITY/NOTATION
             .= chr $self->{nc};  
2537          $self->{read_until}->($self->{ct}->{pubid}, q[">],          $self->{read_until}->($self->{ct}->{pubid}, q[">],
2538                                length $self->{ct}->{pubid});                                length $self->{ct}->{pubid});
2539    
# Line 2126  sub _get_next_token ($) { Line 2548  sub _get_next_token ($) {
2548          !!!next-input-character;          !!!next-input-character;
2549          redo A;          redo A;
2550        } elsif ($self->{nc} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
         !!!cp (192);  
2551          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2552    
2553          $self->{state} = DATA_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2554          $self->{s_kwd} = '';            !!!cp (192);
2555          !!!next-input-character;            $self->{state} = DATA_STATE;
2556              $self->{s_kwd} = '';
2557          $self->{ct}->{quirks} = 1;            $self->{ct}->{quirks} = 1;
2558          !!!emit ($self->{ct}); # DOCTYPE          } else {
2559              !!!cp (192.1);
2560              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2561            }
2562    
2563            !!!next-input-character;
2564            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2565          redo A;          redo A;
2566        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
         !!!cp (193);  
2567          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2568    
2569          $self->{state} = DATA_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2570          $self->{s_kwd} = '';            !!!cp (193);
2571              $self->{state} = DATA_STATE;
2572              $self->{s_kwd} = '';
2573              $self->{ct}->{quirks} = 1;
2574            } else {
2575              !!!cp (193.1);
2576              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2577            }
2578          
2579          ## reconsume          ## reconsume
2580            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
         $self->{ct}->{quirks} = 1;  
         !!!emit ($self->{ct}); # DOCTYPE  
   
2581          redo A;          redo A;
2582        } else {        } else {
2583          !!!cp (194);          !!!cp (194);
2584          $self->{ct}->{pubid} # DOCTYPE          $self->{ct}->{pubid} .= chr $self->{nc}; # DOCTYPE/ENTITY/NOTATION
             .= chr $self->{nc};  
2585          $self->{read_until}->($self->{ct}->{pubid}, q['>],          $self->{read_until}->($self->{ct}->{pubid}, q['>],
2586                                length $self->{ct}->{pubid});                                length $self->{ct}->{pubid});
2587    
# Line 2168  sub _get_next_token ($) { Line 2597  sub _get_next_token ($) {
2597          redo A;          redo A;
2598        } elsif ($self->{nc} == 0x0022) { # "        } elsif ($self->{nc} == 0x0022) { # "
2599          !!!cp (196);          !!!cp (196);
2600          $self->{ct}->{sysid} = ''; # DOCTYPE          $self->{ct}->{sysid} = ''; # DOCTYPE/ENTITY/NOTATION
2601          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;
2602          !!!next-input-character;          !!!next-input-character;
2603          redo A;          redo A;
2604        } elsif ($self->{nc} == 0x0027) { # '        } elsif ($self->{nc} == 0x0027) { # '
2605          !!!cp (197);          !!!cp (197);
2606          $self->{ct}->{sysid} = ''; # DOCTYPE          $self->{ct}->{sysid} = ''; # DOCTYPE/ENTITY/NOTATION
2607          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;
2608          !!!next-input-character;          !!!next-input-character;
2609          redo A;          redo A;
2610        } elsif ($self->{nc} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2611          !!!cp (198);          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2612          $self->{state} = DATA_STATE;            if ($self->{is_xml}) {
2613          $self->{s_kwd} = '';              !!!cp (198.1);
2614                !!!parse-error (type => 'no SYSTEM literal');
2615              } else {
2616                !!!cp (198);
2617              }
2618              $self->{state} = DATA_STATE;
2619              $self->{s_kwd} = '';
2620            } else {
2621              if ($self->{ct}->{type} == NOTATION_TOKEN) {
2622                !!!cp (198.2);
2623              } else {
2624                !!!cp (198.3);
2625                !!!parse-error (type => 'no SYSTEM literal');            
2626              }
2627              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2628            }
2629            
2630          !!!next-input-character;          !!!next-input-character;
2631            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
         !!!emit ($self->{ct}); # DOCTYPE  
   
2632          redo A;          redo A;
2633        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
2634          !!!cp (199);          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2635          !!!parse-error (type => 'unclosed DOCTYPE');            !!!cp (199);
2636              !!!parse-error (type => 'unclosed DOCTYPE');
2637          $self->{state} = DATA_STATE;            
2638          $self->{s_kwd} = '';            $self->{state} = DATA_STATE;
2639              $self->{s_kwd} = '';
2640              $self->{ct}->{quirks} = 1;
2641            } else {
2642              !!!parse-error (type => 'unclosed md'); ## TODO: type
2643              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2644            }
2645            
2646          ## reconsume          ## reconsume
2647            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2648          $self->{ct}->{quirks} = 1;          redo A;
2649          } elsif ($self->{is_xml} and
2650                   $self->{ct}->{type} == DOCTYPE_TOKEN and
2651                   $self->{nc} == 0x005B) { # [
2652            !!!cp (200.1);
2653            !!!parse-error (type => 'no SYSTEM literal');
2654            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2655            $self->{ct}->{has_internal_subset} = 1; # DOCTYPE
2656            $self->{in_subset} = 1;
2657            !!!next-input-character;
2658          !!!emit ($self->{ct}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
   
2659          redo A;          redo A;
2660        } else {        } else {
         !!!cp (200);  
2661          !!!parse-error (type => 'string after PUBLIC literal');          !!!parse-error (type => 'string after PUBLIC literal');
         $self->{ct}->{quirks} = 1;  
2662    
2663          $self->{state} = BOGUS_DOCTYPE_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2664              !!!cp (200);
2665              $self->{ct}->{quirks} = 1;
2666              $self->{state} = BOGUS_DOCTYPE_STATE;
2667            } else {
2668              !!!cp (200.2);
2669              $self->{state} = BOGUS_MD_STATE;
2670            }
2671    
2672          !!!next-input-character;          !!!next-input-character;
2673          redo A;          redo A;
2674        }        }
# Line 2227  sub _get_next_token ($) { Line 2691  sub _get_next_token ($) {
2691          !!!next-input-character;          !!!next-input-character;
2692          redo A;          redo A;
2693        } elsif ($self->{nc} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
         !!!cp (204);  
2694          !!!parse-error (type => 'no SYSTEM literal');          !!!parse-error (type => 'no SYSTEM literal');
         $self->{state} = DATA_STATE;  
         $self->{s_kwd} = '';  
2695          !!!next-input-character;          !!!next-input-character;
2696    
2697          $self->{ct}->{quirks} = 1;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2698          !!!emit ($self->{ct}); # DOCTYPE            !!!cp (204);
2699              $self->{state} = DATA_STATE;
2700              $self->{s_kwd} = '';
2701              $self->{ct}->{quirks} = 1;
2702            } else {
2703              !!!cp (204.1);
2704              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2705            }
2706    
2707            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2708          redo A;          redo A;
2709        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
2710          !!!cp (205);          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2711          !!!parse-error (type => 'unclosed DOCTYPE');            !!!cp (205);
2712              !!!parse-error (type => 'unclosed DOCTYPE');
2713          $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
2714          $self->{s_kwd} = '';            $self->{s_kwd} = '';
2715              $self->{ct}->{quirks} = 1;
2716            } else {
2717              !!!cp (205.1);
2718              !!!parse-error (type => 'unclosed md'); ## TODO: type
2719              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2720            }
2721            
2722          ## reconsume          ## reconsume
2723            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2724            redo A;
2725          } elsif ($self->{is_xml} and
2726                   $self->{ct}->{type} == DOCTYPE_TOKEN and
2727                   $self->{nc} == 0x005B) { # [
2728            !!!cp (206.1);
2729            !!!parse-error (type => 'no SYSTEM literal');
2730    
2731          $self->{ct}->{quirks} = 1;          $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2732            $self->{ct}->{has_internal_subset} = 1; # DOCTYPE
2733            $self->{in_subset} = 1;
2734            !!!next-input-character;
2735          !!!emit ($self->{ct}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
   
2736          redo A;          redo A;
2737        } else {        } else {
         !!!cp (206);  
2738          !!!parse-error (type => 'string after SYSTEM');          !!!parse-error (type => 'string after SYSTEM');
         $self->{ct}->{quirks} = 1;  
2739    
2740          $self->{state} = BOGUS_DOCTYPE_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2741              !!!cp (206);          
2742              $self->{ct}->{quirks} = 1;
2743              $self->{state} = BOGUS_DOCTYPE_STATE;
2744            } else {
2745              !!!cp (206.2);
2746              $self->{state} = BOGUS_MD_STATE;
2747            }
2748    
2749          !!!next-input-character;          !!!next-input-character;
2750          redo A;          redo A;
2751        }        }
# Line 2264  sub _get_next_token ($) { Line 2755  sub _get_next_token ($) {
2755          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2756          !!!next-input-character;          !!!next-input-character;
2757          redo A;          redo A;
2758        } elsif ($self->{nc} == 0x003E) { # >        } elsif (not $self->{is_xml} and $self->{nc} == 0x003E) { # >
         !!!cp (208);  
2759          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2760    
2761          $self->{state} = DATA_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2762          $self->{s_kwd} = '';            !!!cp (208);
2763              $self->{state} = DATA_STATE;
2764              $self->{s_kwd} = '';
2765              $self->{ct}->{quirks} = 1;
2766            } else {
2767              !!!cp (208.1);
2768              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2769            }
2770            
2771          !!!next-input-character;          !!!next-input-character;
2772            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
         $self->{ct}->{quirks} = 1;  
         !!!emit ($self->{ct}); # DOCTYPE  
   
2773          redo A;          redo A;
2774        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
         !!!cp (209);  
2775          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2776    
2777          $self->{state} = DATA_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2778          $self->{s_kwd} = '';            !!!cp (209);
2779              $self->{state} = DATA_STATE;
2780              $self->{s_kwd} = '';
2781              $self->{ct}->{quirks} = 1;
2782            } else {
2783              !!!cp (209.1);
2784              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2785            }
2786            
2787          ## reconsume          ## reconsume
2788            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
         $self->{ct}->{quirks} = 1;  
         !!!emit ($self->{ct}); # DOCTYPE  
   
2789          redo A;          redo A;
2790        } else {        } else {
2791          !!!cp (210);          !!!cp (210);
2792          $self->{ct}->{sysid} # DOCTYPE          $self->{ct}->{sysid} .= chr $self->{nc}; # DOCTYPE/ENTITY/NOTATION
             .= chr $self->{nc};  
2793          $self->{read_until}->($self->{ct}->{sysid}, q[">],          $self->{read_until}->($self->{ct}->{sysid}, q[">],
2794                                length $self->{ct}->{sysid});                                length $self->{ct}->{sysid});
2795    
# Line 2305  sub _get_next_token ($) { Line 2803  sub _get_next_token ($) {
2803          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;          $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2804          !!!next-input-character;          !!!next-input-character;
2805          redo A;          redo A;
2806        } elsif ($self->{nc} == 0x003E) { # >        } elsif (not $self->{is_xml} and $self->{nc} == 0x003E) { # >
2807          !!!cp (212);          !!!cp (212);
2808          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2809    
# Line 2318  sub _get_next_token ($) { Line 2816  sub _get_next_token ($) {
2816    
2817          redo A;          redo A;
2818        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
         !!!cp (213);  
2819          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2820    
2821          $self->{state} = DATA_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2822          $self->{s_kwd} = '';            !!!cp (213);
2823          ## reconsume            $self->{state} = DATA_STATE;
2824              $self->{s_kwd} = '';
2825          $self->{ct}->{quirks} = 1;            $self->{ct}->{quirks} = 1;
2826          !!!emit ($self->{ct}); # DOCTYPE          } else {
2827              !!!cp (213.1);
2828              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2829            }
2830    
2831            ## reconsume
2832            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2833          redo A;          redo A;
2834        } else {        } else {
2835          !!!cp (214);          !!!cp (214);
2836          $self->{ct}->{sysid} # DOCTYPE          $self->{ct}->{sysid} .= chr $self->{nc}; # DOCTYPE/ENTITY/NOTATION
             .= chr $self->{nc};  
2837          $self->{read_until}->($self->{ct}->{sysid}, q['>],          $self->{read_until}->($self->{ct}->{sysid}, q['>],
2838                                length $self->{ct}->{sysid});                                length $self->{ct}->{sysid});
2839    
# Line 2342  sub _get_next_token ($) { Line 2843  sub _get_next_token ($) {
2843        }        }
2844      } elsif ($self->{state} == AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE) {      } elsif ($self->{state} == AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE) {
2845        if ($is_space->{$self->{nc}}) {        if ($is_space->{$self->{nc}}) {
2846          !!!cp (215);          if ($self->{ct}->{type} == GENERAL_ENTITY_TOKEN) {
2847          ## Stay in the state            !!!cp (215.1);
2848              $self->{state} = BEFORE_NDATA_STATE;
2849            } else {
2850              !!!cp (215);
2851              ## Stay in the state
2852            }
2853          !!!next-input-character;          !!!next-input-character;
2854          redo A;          redo A;
2855        } elsif ($self->{nc} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2856          !!!cp (216);          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2857          $self->{state} = DATA_STATE;            !!!cp (216);
2858          $self->{s_kwd} = '';            $self->{state} = DATA_STATE;
2859              $self->{s_kwd} = '';
2860            } else {
2861              !!!cp (216.1);
2862              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2863            }
2864    
2865          !!!next-input-character;          !!!next-input-character;
2866            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2867            redo A;
2868          } elsif ($self->{ct}->{type} == GENERAL_ENTITY_TOKEN and
2869                   ($self->{nc} == 0x004E or # N
2870                    $self->{nc} == 0x006E)) { # n
2871            !!!cp (216.2);
2872            !!!parse-error (type => 'no space before NDATA'); ## TODO: type
2873            $self->{state} = NDATA_STATE;
2874            $self->{kwd} = chr $self->{nc};
2875            !!!next-input-character;
2876            redo A;
2877          } elsif ($self->{nc} == -1) {
2878            if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2879              !!!cp (217);
2880              !!!parse-error (type => 'unclosed DOCTYPE');
2881              $self->{state} = DATA_STATE;
2882              $self->{s_kwd} = '';
2883              $self->{ct}->{quirks} = 1;
2884            } else {
2885              !!!cp (217.1);
2886              !!!parse-error (type => 'unclosed md'); ## TODO: type
2887              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2888            }
2889    
2890            ## reconsume
2891            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2892            redo A;
2893          } elsif ($self->{is_xml} and
2894                   $self->{ct}->{type} == DOCTYPE_TOKEN and
2895                   $self->{nc} == 0x005B) { # [
2896            !!!cp (218.1);
2897            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2898            $self->{ct}->{has_internal_subset} = 1; # DOCTYPE
2899            $self->{in_subset} = 1;
2900            !!!next-input-character;
2901          !!!emit ($self->{ct}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2902            redo A;
2903          } else {
2904            !!!parse-error (type => 'string after SYSTEM literal');
2905    
2906            if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2907              !!!cp (218);
2908              #$self->{ct}->{quirks} = 1;
2909              $self->{state} = BOGUS_DOCTYPE_STATE;
2910            } else {
2911              !!!cp (218.2);
2912              $self->{state} = BOGUS_MD_STATE;
2913            }
2914    
2915            !!!next-input-character;
2916            redo A;
2917          }
2918        } elsif ($self->{state} == BEFORE_NDATA_STATE) {
2919          if ($is_space->{$self->{nc}}) {
2920            !!!cp (218.3);
2921            ## Stay in the state.
2922            !!!next-input-character;
2923            redo A;
2924          } elsif ($self->{nc} == 0x003E) { # >
2925            !!!cp (218.4);
2926            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2927            !!!next-input-character;
2928            !!!emit ($self->{ct}); # ENTITY
2929            redo A;
2930          } elsif ($self->{nc} == 0x004E or # N
2931                   $self->{nc} == 0x006E) { # n
2932            !!!cp (218.5);
2933            $self->{state} = NDATA_STATE;
2934            $self->{kwd} = chr $self->{nc};
2935            !!!next-input-character;
2936          redo A;          redo A;
2937        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
2938          !!!cp (217);          !!!cp (218.6);
2939          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed md'); ## TODO: type
2940          $self->{state} = DATA_STATE;          $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
         $self->{s_kwd} = '';  
2941          ## reconsume          ## reconsume
2942            !!!emit ($self->{ct}); # ENTITY
         $self->{ct}->{quirks} = 1;  
         !!!emit ($self->{ct}); # DOCTYPE  
   
2943          redo A;          redo A;
2944        } else {        } else {
2945          !!!cp (218);          !!!cp (218.7);
2946          !!!parse-error (type => 'string after SYSTEM literal');          !!!parse-error (type => 'string after SYSTEM literal');
2947          #$self->{ct}->{quirks} = 1;          $self->{state} = BOGUS_MD_STATE;
   
         $self->{state} = BOGUS_DOCTYPE_STATE;  
2948          !!!next-input-character;          !!!next-input-character;
2949          redo A;          redo A;
2950        }        }
# Line 2385  sub _get_next_token ($) { Line 2958  sub _get_next_token ($) {
2958          !!!emit ($self->{ct}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
2959    
2960          redo A;          redo A;
2961          } elsif ($self->{is_xml} and $self->{nc} == 0x005B) { # [
2962            !!!cp (220.1);
2963            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2964            $self->{ct}->{has_internal_subset} = 1; # DOCTYPE
2965            $self->{in_subset} = 1;
2966            !!!next-input-character;
2967            !!!emit ($self->{ct}); # DOCTYPE
2968            redo A;
2969        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
2970          !!!cp (220);          !!!cp (220);
2971          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
# Line 2397  sub _get_next_token ($) { Line 2978  sub _get_next_token ($) {
2978        } else {        } else {
2979          !!!cp (221);          !!!cp (221);
2980          my $s = '';          my $s = '';
2981          $self->{read_until}->($s, q[>], 0);          $self->{read_until}->($s, q{>[}, 0);
2982    
2983          ## Stay in the state          ## Stay in the state
2984          !!!next-input-character;          !!!next-input-character;
# Line 2505  sub _get_next_token ($) { Line 3086  sub _get_next_token ($) {
3086        } elsif ($self->{nc} == 0x0023) { # #        } elsif ($self->{nc} == 0x0023) { # #
3087          !!!cp (999);          !!!cp (999);
3088          $self->{state} = ENTITY_HASH_STATE;          $self->{state} = ENTITY_HASH_STATE;
3089          $self->{s_kwd} = '#';          $self->{kwd} = '#';
3090          !!!next-input-character;          !!!next-input-character;
3091          redo A;          redo A;
3092        } elsif ((0x0041 <= $self->{nc} and        } elsif ((0x0041 <= $self->{nc} and
# Line 2515  sub _get_next_token ($) { Line 3096  sub _get_next_token ($) {
3096          !!!cp (998);          !!!cp (998);
3097          require Whatpm::_NamedEntityList;          require Whatpm::_NamedEntityList;
3098          $self->{state} = ENTITY_NAME_STATE;          $self->{state} = ENTITY_NAME_STATE;
3099          $self->{s_kwd} = chr $self->{nc};          $self->{kwd} = chr $self->{nc};
3100          $self->{entity__value} = $self->{s_kwd};          $self->{entity__value} = $self->{kwd};
3101          $self->{entity__match} = 0;          $self->{entity__match} = 0;
3102          !!!next-input-character;          !!!next-input-character;
3103          redo A;          redo A;
# Line 2556  sub _get_next_token ($) { Line 3137  sub _get_next_token ($) {
3137            $self->{nc} == 0x0058) { # X            $self->{nc} == 0x0058) { # X
3138          !!!cp (995);          !!!cp (995);
3139          $self->{state} = HEXREF_X_STATE;          $self->{state} = HEXREF_X_STATE;
3140          $self->{s_kwd} .= chr $self->{nc};          $self->{kwd} .= chr $self->{nc};
3141          !!!next-input-character;          !!!next-input-character;
3142          redo A;          redo A;
3143        } elsif (0x0030 <= $self->{nc} and        } elsif (0x0030 <= $self->{nc} and
3144                 $self->{nc} <= 0x0039) { # 0..9                 $self->{nc} <= 0x0039) { # 0..9
3145          !!!cp (994);          !!!cp (994);
3146          $self->{state} = NCR_NUM_STATE;          $self->{state} = NCR_NUM_STATE;
3147          $self->{s_kwd} = $self->{nc} - 0x0030;          $self->{kwd} = $self->{nc} - 0x0030;
3148          !!!next-input-character;          !!!next-input-character;
3149          redo A;          redo A;
3150        } else {        } else {
# Line 2599  sub _get_next_token ($) { Line 3180  sub _get_next_token ($) {
3180        if (0x0030 <= $self->{nc} and        if (0x0030 <= $self->{nc} and
3181            $self->{nc} <= 0x0039) { # 0..9            $self->{nc} <= 0x0039) { # 0..9
3182          !!!cp (1012);          !!!cp (1012);
3183          $self->{s_kwd} *= 10;          $self->{kwd} *= 10;
3184          $self->{s_kwd} += $self->{nc} - 0x0030;          $self->{kwd} += $self->{nc} - 0x0030;
3185                    
3186          ## Stay in the state.          ## Stay in the state.
3187          !!!next-input-character;          !!!next-input-character;
# Line 2616  sub _get_next_token ($) { Line 3197  sub _get_next_token ($) {
3197          #          #
3198        }        }
3199    
3200        my $code = $self->{s_kwd};        my $code = $self->{kwd};
3201        my $l = $self->{line_prev};        my $l = $self->{line_prev};
3202        my $c = $self->{column_prev};        my $c = $self->{column_prev};
3203        if ($charref_map->{$code}) {        if ($charref_map->{$code}) {
# Line 2659  sub _get_next_token ($) { Line 3240  sub _get_next_token ($) {
3240          # 0..9, A..F, a..f          # 0..9, A..F, a..f
3241          !!!cp (990);          !!!cp (990);
3242          $self->{state} = HEXREF_HEX_STATE;          $self->{state} = HEXREF_HEX_STATE;
3243          $self->{s_kwd} = 0;          $self->{kwd} = 0;
3244          ## Reconsume.          ## Reconsume.
3245          redo A;          redo A;
3246        } else {        } else {
# Line 2677  sub _get_next_token ($) { Line 3258  sub _get_next_token ($) {
3258            $self->{s_kwd} = '';            $self->{s_kwd} = '';
3259            ## Reconsume.            ## Reconsume.
3260            !!!emit ({type => CHARACTER_TOKEN,            !!!emit ({type => CHARACTER_TOKEN,
3261                      data => '&' . $self->{s_kwd},                      data => '&' . $self->{kwd},
3262                      line => $self->{line_prev},                      line => $self->{line_prev},
3263                      column => $self->{column_prev} - length $self->{s_kwd},                      column => $self->{column_prev} - length $self->{kwd},
3264                     });                     });
3265            redo A;            redo A;
3266          } else {          } else {
3267            !!!cp (989);            !!!cp (989);
3268            $self->{ca}->{value} .= '&' . $self->{s_kwd};            $self->{ca}->{value} .= '&' . $self->{kwd};
3269            $self->{state} = $self->{prev_state};            $self->{state} = $self->{prev_state};
3270            $self->{s_kwd} = '';            $self->{s_kwd} = '';
3271            ## Reconsume.            ## Reconsume.
# Line 2695  sub _get_next_token ($) { Line 3276  sub _get_next_token ($) {
3276        if (0x0030 <= $self->{nc} and $self->{nc} <= 0x0039) {        if (0x0030 <= $self->{nc} and $self->{nc} <= 0x0039) {
3277          # 0..9          # 0..9
3278          !!!cp (1002);          !!!cp (1002);
3279          $self->{s_kwd} *= 0x10;          $self->{kwd} *= 0x10;
3280          $self->{s_kwd} += $self->{nc} - 0x0030;          $self->{kwd} += $self->{nc} - 0x0030;
3281          ## Stay in the state.          ## Stay in the state.
3282          !!!next-input-character;          !!!next-input-character;
3283          redo A;          redo A;
3284        } elsif (0x0061 <= $self->{nc} and        } elsif (0x0061 <= $self->{nc} and
3285                 $self->{nc} <= 0x0066) { # a..f                 $self->{nc} <= 0x0066) { # a..f
3286          !!!cp (1003);          !!!cp (1003);
3287          $self->{s_kwd} *= 0x10;          $self->{kwd} *= 0x10;
3288          $self->{s_kwd} += $self->{nc} - 0x0060 + 9;          $self->{kwd} += $self->{nc} - 0x0060 + 9;
3289          ## Stay in the state.          ## Stay in the state.
3290          !!!next-input-character;          !!!next-input-character;
3291          redo A;          redo A;
3292        } elsif (0x0041 <= $self->{nc} and        } elsif (0x0041 <= $self->{nc} and
3293                 $self->{nc} <= 0x0046) { # A..F                 $self->{nc} <= 0x0046) { # A..F
3294          !!!cp (1004);          !!!cp (1004);
3295          $self->{s_kwd} *= 0x10;          $self->{kwd} *= 0x10;
3296          $self->{s_kwd} += $self->{nc} - 0x0040 + 9;          $self->{kwd} += $self->{nc} - 0x0040 + 9;
3297          ## Stay in the state.          ## Stay in the state.
3298          !!!next-input-character;          !!!next-input-character;
3299          redo A;          redo A;
# Line 2729  sub _get_next_token ($) { Line 3310  sub _get_next_token ($) {
3310          #          #
3311        }        }
3312    
3313        my $code = $self->{s_kwd};        my $code = $self->{kwd};
3314        my $l = $self->{line_prev};        my $l = $self->{line_prev};
3315        my $c = $self->{column_prev};        my $c = $self->{column_prev};
3316        if ($charref_map->{$code}) {        if ($charref_map->{$code}) {
# Line 2766  sub _get_next_token ($) { Line 3347  sub _get_next_token ($) {
3347          redo A;          redo A;
3348        }        }
3349      } elsif ($self->{state} == ENTITY_NAME_STATE) {      } elsif ($self->{state} == ENTITY_NAME_STATE) {
3350        if (length $self->{s_kwd} < 30 and        if (length $self->{kwd} < 30 and
3351            ## NOTE: Some number greater than the maximum length of entity name            ## NOTE: Some number greater than the maximum length of entity name
3352            ((0x0041 <= $self->{nc} and # a            ((0x0041 <= $self->{nc} and # a
3353              $self->{nc} <= 0x005A) or # x              $self->{nc} <= 0x005A) or # x
# Line 2776  sub _get_next_token ($) { Line 3357  sub _get_next_token ($) {
3357              $self->{nc} <= 0x0039) or # 9              $self->{nc} <= 0x0039) or # 9
3358             $self->{nc} == 0x003B)) { # ;             $self->{nc} == 0x003B)) { # ;
3359          our $EntityChar;          our $EntityChar;
3360          $self->{s_kwd} .= chr $self->{nc};          $self->{kwd} .= chr $self->{nc};
3361          if (defined $EntityChar->{$self->{s_kwd}}) {          if (defined $EntityChar->{$self->{kwd}}) {
3362            if ($self->{nc} == 0x003B) { # ;            if ($self->{nc} == 0x003B) { # ;
3363              !!!cp (1020);              !!!cp (1020);
3364              $self->{entity__value} = $EntityChar->{$self->{s_kwd}};              $self->{entity__value} = $EntityChar->{$self->{kwd}};
3365              $self->{entity__match} = 1;              $self->{entity__match} = 1;
3366              !!!next-input-character;              !!!next-input-character;
3367              #              #
3368            } else {            } else {
3369              !!!cp (1021);              !!!cp (1021);
3370              $self->{entity__value} = $EntityChar->{$self->{s_kwd}};              $self->{entity__value} = $EntityChar->{$self->{kwd}};
3371              $self->{entity__match} = -1;              $self->{entity__match} = -1;
3372              ## Stay in the state.              ## Stay in the state.
3373              !!!next-input-character;              !!!next-input-character;
# Line 2814  sub _get_next_token ($) { Line 3395  sub _get_next_token ($) {
3395          if ($self->{prev_state} != DATA_STATE and # in attribute          if ($self->{prev_state} != DATA_STATE and # in attribute
3396              $self->{entity__match} < -1) {              $self->{entity__match} < -1) {
3397            !!!cp (1024);            !!!cp (1024);
3398            $data = '&' . $self->{s_kwd};            $data = '&' . $self->{kwd};
3399            #            #
3400          } else {          } else {
3401            !!!cp (1025);            !!!cp (1025);
# Line 2826  sub _get_next_token ($) { Line 3407  sub _get_next_token ($) {
3407          !!!cp (1026);          !!!cp (1026);
3408          !!!parse-error (type => 'bare ero',          !!!parse-error (type => 'bare ero',
3409                          line => $self->{line_prev},                          line => $self->{line_prev},
3410                          column => $self->{column_prev} - length $self->{s_kwd});                          column => $self->{column_prev} - length $self->{kwd});
3411          $data = '&' . $self->{s_kwd};          $data = '&' . $self->{kwd};
3412          #          #
3413        }        }
3414        
# Line 2850  sub _get_next_token ($) { Line 3431  sub _get_next_token ($) {
3431                    data => $data,                    data => $data,
3432                    has_reference => $has_ref,                    has_reference => $has_ref,
3433                    line => $self->{line_prev},                    line => $self->{line_prev},
3434                    column => $self->{column_prev} + 1 - length $self->{s_kwd},                    column => $self->{column_prev} + 1 - length $self->{kwd},
3435                   });                   });
3436          redo A;          redo A;
3437        } else {        } else {
# Line 2866  sub _get_next_token ($) { Line 3447  sub _get_next_token ($) {
3447      ## XML-only states      ## XML-only states
3448    
3449      } elsif ($self->{state} == PI_STATE) {      } elsif ($self->{state} == PI_STATE) {
3450          ## XML5: "Pi state" and "DOCTYPE pi state".
3451    
3452        if ($is_space->{$self->{nc}} or        if ($is_space->{$self->{nc}} or
3453            $self->{nc} == 0x003F or # ? ## XML5: Same as "Anything else"            $self->{nc} == 0x003F or # ?
3454            $self->{nc} == -1) {            $self->{nc} == -1) {
3455            ## XML5: U+003F: "pi state": Same as "Anything else"; "DOCTYPE
3456            ## pi state": Switch to the "DOCTYPE pi after state".  EOF:
3457            ## "DOCTYPE pi state": Parse error, switch to the "data
3458            ## state".
3459          !!!parse-error (type => 'bare pio', ## TODO: type          !!!parse-error (type => 'bare pio', ## TODO: type
3460                          line => $self->{line_prev},                          line => $self->{line_prev},
3461                          column => $self->{column_prev}                          column => $self->{column_prev}
# Line 2883  sub _get_next_token ($) { Line 3470  sub _get_next_token ($) {
3470                        };                        };
3471          redo A;          redo A;
3472        } else {        } else {
3473            ## XML5: "DOCTYPE pi state": Stay in the state.
3474          $self->{ct} = {type => PI_TOKEN,          $self->{ct} = {type => PI_TOKEN,
3475                         target => chr $self->{nc},                         target => chr $self->{nc},
3476                         data => '',                         data => '',
# Line 2900  sub _get_next_token ($) { Line 3488  sub _get_next_token ($) {
3488          redo A;          redo A;
3489        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
3490          !!!parse-error (type => 'no pic'); ## TODO: type          !!!parse-error (type => 'no pic'); ## TODO: type
3491          $self->{state} = DATA_STATE;          if ($self->{in_subset}) {
3492          $self->{s_kwd} = '';            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
3493            } else {
3494              $self->{state} = DATA_STATE;
3495              $self->{s_kwd} = '';
3496            }
3497          ## Reconsume.          ## Reconsume.
3498          !!!emit ($self->{ct}); # pi          !!!emit ($self->{ct}); # pi
3499          redo A;          redo A;
# Line 2932  sub _get_next_token ($) { Line 3524  sub _get_next_token ($) {
3524          redo A;          redo A;
3525        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
3526          !!!parse-error (type => 'no pic'); ## TODO: type          !!!parse-error (type => 'no pic'); ## TODO: type
3527          $self->{state} = DATA_STATE;          if ($self->{in_subset}) {
3528          $self->{s_kwd} = '';            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state"
3529            } else {
3530              $self->{state} = DATA_STATE;
3531              $self->{s_kwd} = '';
3532            }
3533          ## Reprocess.          ## Reprocess.
3534          !!!emit ($self->{ct}); # pi          !!!emit ($self->{ct}); # pi
3535          redo A;          redo A;
# Line 2947  sub _get_next_token ($) { Line 3543  sub _get_next_token ($) {
3543          redo A;          redo A;
3544        }        }
3545      } elsif ($self->{state} == PI_AFTER_STATE) {      } elsif ($self->{state} == PI_AFTER_STATE) {
3546          ## XML5: Part of "Pi after state".
3547    
3548        if ($self->{nc} == 0x003E) { # >        if ($self->{nc} == 0x003E) { # >
3549          $self->{state} = DATA_STATE;          if ($self->{in_subset}) {
3550          $self->{s_kwd} = '';            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
3551            } else {
3552              $self->{state} = DATA_STATE;
3553              $self->{s_kwd} = '';
3554            }
3555          !!!next-input-character;          !!!next-input-character;
3556          !!!emit ($self->{ct}); # pi          !!!emit ($self->{ct}); # pi
3557          redo A;          redo A;
# Line 2972  sub _get_next_token ($) { Line 3574  sub _get_next_token ($) {
3574          redo A;          redo A;
3575        }        }
3576      } elsif ($self->{state} == PI_DATA_AFTER_STATE) {      } elsif ($self->{state} == PI_DATA_AFTER_STATE) {
3577        ## XML5: Same as "pi after state" in XML5        ## XML5: Same as "pi after state" and "DOCTYPE pi after state".
3578    
3579        if ($self->{nc} == 0x003E) { # >        if ($self->{nc} == 0x003E) { # >
3580          $self->{state} = DATA_STATE;          if ($self->{in_subset}) {
3581          $self->{s_kwd} = '';            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
3582            } else {
3583              $self->{state} = DATA_STATE;
3584              $self->{s_kwd} = '';
3585            }
3586          !!!next-input-character;          !!!next-input-character;
3587          !!!emit ($self->{ct}); # pi          !!!emit ($self->{ct}); # pi
3588          redo A;          redo A;
# Line 2990  sub _get_next_token ($) { Line 3597  sub _get_next_token ($) {
3597          ## Reprocess.          ## Reprocess.
3598          redo A;          redo A;
3599        }        }
3600            
3601        } elsif ($self->{state} == DOCTYPE_INTERNAL_SUBSET_STATE) {
3602          if ($self->{nc} == 0x003C) { # <
3603            $self->{state} = DOCTYPE_TAG_STATE;
3604            !!!next-input-character;
3605            redo A;
3606          } elsif ($self->{nc} == 0x0025) { # %
3607            ## XML5: Not defined yet.
3608    
3609            ## TODO:
3610            !!!next-input-character;
3611            redo A;
3612          } elsif ($self->{nc} == 0x005D) { # ]
3613            delete $self->{in_subset};
3614            $self->{state} = DOCTYPE_INTERNAL_SUBSET_AFTER_STATE;
3615            !!!next-input-character;
3616            redo A;
3617          } elsif ($is_space->{$self->{nc}}) {
3618            ## Stay in the state.
3619            !!!next-input-character;
3620            redo A;
3621          } elsif ($self->{nc} == -1) {
3622            !!!parse-error (type => 'unclosed internal subset'); ## TODO: type
3623            delete $self->{in_subset};
3624            $self->{state} = DATA_STATE;
3625            $self->{s_kwd} = '';
3626            ## Reconsume.
3627            !!!emit ({type => END_OF_DOCTYPE_TOKEN});
3628            redo A;
3629          } else {
3630            unless ($self->{internal_subset_tainted}) {
3631              ## XML5: No parse error.
3632              !!!parse-error (type => 'string in internal subset');
3633              $self->{internal_subset_tainted} = 1;
3634            }
3635            ## Stay in the state.
3636            !!!next-input-character;
3637            redo A;
3638          }
3639        } elsif ($self->{state} == DOCTYPE_INTERNAL_SUBSET_AFTER_STATE) {
3640          if ($self->{nc} == 0x003E) { # >
3641            $self->{state} = DATA_STATE;
3642            $self->{s_kwd} = '';
3643            !!!next-input-character;
3644            !!!emit ({type => END_OF_DOCTYPE_TOKEN});
3645            redo A;
3646          } elsif ($self->{nc} == -1) {
3647            !!!parse-error (type => 'unclosed DOCTYPE');
3648            $self->{state} = DATA_STATE;
3649            $self->{s_kwd} = '';
3650            ## Reconsume.
3651            !!!emit ({type => END_OF_DOCTYPE_TOKEN});
3652            redo A;
3653          } else {
3654            ## XML5: No parse error and stay in the state.
3655            !!!parse-error (type => 'string after internal subset'); ## TODO: type
3656    
3657            $self->{state} = BOGUS_DOCTYPE_INTERNAL_SUBSET_AFTER_STATE;
3658            !!!next-input-character;
3659            redo A;
3660          }
3661        } elsif ($self->{state} == BOGUS_DOCTYPE_INTERNAL_SUBSET_AFTER_STATE) {
3662          if ($self->{nc} == 0x003E) { # >
3663            $self->{state} = DATA_STATE;
3664            $self->{s_kwd} = '';
3665            !!!next-input-character;
3666            !!!emit ({type => END_OF_DOCTYPE_TOKEN});
3667            redo A;
3668          } elsif ($self->{nc} == -1) {
3669            $self->{state} = DATA_STATE;
3670            $self->{s_kwd} = '';
3671            ## Reconsume.
3672            !!!emit ({type => END_OF_DOCTYPE_TOKEN});
3673            redo A;
3674          } else {
3675            ## Stay in the state.
3676            !!!next-input-character;
3677            redo A;
3678          }
3679        } elsif ($self->{state} == DOCTYPE_TAG_STATE) {
3680          if ($self->{nc} == 0x0021) { # !
3681            $self->{state} = DOCTYPE_MARKUP_DECLARATION_OPEN_STATE;
3682            !!!next-input-character;
3683            redo A;
3684          } elsif ($self->{nc} == 0x003F) { # ?
3685            $self->{state} = PI_STATE;
3686            !!!next-input-character;
3687            redo A;
3688          } elsif ($self->{nc} == -1) {
3689            !!!parse-error (type => 'bare stago');
3690            $self->{state} = DATA_STATE;
3691            $self->{s_kwd} = '';
3692            ## Reconsume.
3693            redo A;
3694          } else {
3695            !!!parse-error (type => 'bare stago', ## XML5: Not a parse error.
3696                            line => $self->{line_prev},
3697                            column => $self->{column_prev});
3698            $self->{state} = BOGUS_COMMENT_STATE;
3699            $self->{ct} = {type => COMMENT_TOKEN,
3700                           data => '',
3701                          }; ## NOTE: Will be discarded.
3702            !!!next-input-character;
3703            redo A;
3704          }
3705        } elsif ($self->{state} == DOCTYPE_MARKUP_DECLARATION_OPEN_STATE) {
3706          ## XML5: "DOCTYPE markup declaration state".
3707          
3708          if ($self->{nc} == 0x002D) { # -
3709            $self->{state} = MD_HYPHEN_STATE;
3710            !!!next-input-character;
3711            redo A;
3712          } elsif ($self->{nc} == 0x0045 or # E
3713                   $self->{nc} == 0x0065) { # e
3714            $self->{state} = MD_E_STATE;
3715            $self->{kwd} = chr $self->{nc};
3716            !!!next-input-character;
3717            redo A;
3718          } elsif ($self->{nc} == 0x0041 or # A
3719                   $self->{nc} == 0x0061) { # a
3720            $self->{state} = MD_ATTLIST_STATE;
3721            $self->{kwd} = chr $self->{nc};
3722            !!!next-input-character;
3723            redo A;
3724          } elsif ($self->{nc} == 0x004E or # N
3725                   $self->{nc} == 0x006E) { # n
3726            $self->{state} = MD_NOTATION_STATE;
3727            $self->{kwd} = chr $self->{nc};
3728            !!!next-input-character;
3729            redo A;
3730          } else {
3731            #
3732          }
3733          
3734          ## XML5: No parse error.
3735          !!!parse-error (type => 'bogus comment',
3736                          line => $self->{line_prev},
3737                          column => $self->{column_prev} - 1);
3738          ## Reconsume.
3739          $self->{state} = BOGUS_COMMENT_STATE;
3740          $self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded.
3741          redo A;
3742        } elsif ($self->{state} == MD_E_STATE) {
3743          if ($self->{nc} == 0x004E or # N
3744              $self->{nc} == 0x006E) { # n
3745            $self->{state} = MD_ENTITY_STATE;
3746            $self->{kwd} .= chr $self->{nc};
3747            !!!next-input-character;
3748            redo A;
3749          } elsif ($self->{nc} == 0x004C or # L
3750                   $self->{nc} == 0x006C) { # l
3751            ## XML5: <!ELEMENT> not supported.
3752            $self->{state} = MD_ELEMENT_STATE;
3753            $self->{kwd} .= chr $self->{nc};
3754            !!!next-input-character;
3755            redo A;
3756          } else {
3757            ## XML5: No parse error.
3758            !!!parse-error (type => 'bogus comment',
3759                            line => $self->{line_prev},
3760                            column => $self->{column_prev} - 2
3761                                + 1 * ($self->{nc} == -1));
3762            ## Reconsume.
3763            $self->{state} = BOGUS_COMMENT_STATE;
3764            $self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded
3765            redo A;
3766          }
3767        } elsif ($self->{state} == MD_ENTITY_STATE) {
3768          if ($self->{nc} == [
3769                undef,
3770                undef,
3771                0x0054, # T
3772                0x0049, # I
3773                0x0054, # T
3774              ]->[length $self->{kwd}] or
3775              $self->{nc} == [
3776                undef,
3777                undef,
3778                0x0074, # t
3779                0x0069, # i
3780                0x0074, # t
3781              ]->[length $self->{kwd}]) {
3782            ## Stay in the state.
3783            $self->{kwd} .= chr $self->{nc};
3784            !!!next-input-character;
3785            redo A;
3786          } elsif ((length $self->{kwd}) == 5 and
3787                   ($self->{nc} == 0x0059 or # Y
3788                    $self->{nc} == 0x0079)) { # y
3789            if ($self->{kwd} ne 'ENTIT' or $self->{nc} == 0x0079) {
3790              !!!parse-error (type => 'lowercase keyword', ## TODO: type
3791                              text => 'ENTITY',
3792                              line => $self->{line_prev},
3793                              column => $self->{column_prev} - 4);
3794            }
3795            $self->{ct} = {type => GENERAL_ENTITY_TOKEN, name => '',
3796                           line => $self->{line_prev},
3797                           column => $self->{column_prev} - 6};
3798            $self->{state} = DOCTYPE_MD_STATE;
3799            !!!next-input-character;
3800            redo A;
3801          } else {
3802            !!!parse-error (type => 'bogus comment',
3803                            line => $self->{line_prev},
3804                            column => $self->{column_prev} - 1
3805                                - (length $self->{kwd})
3806                                + 1 * ($self->{nc} == -1));
3807            $self->{state} = BOGUS_COMMENT_STATE;
3808            ## Reconsume.
3809            $self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded
3810            redo A;
3811          }
3812        } elsif ($self->{state} == MD_ELEMENT_STATE) {
3813          if ($self->{nc} == [
3814               undef,
3815               undef,
3816               0x0045, # E
3817               0x004D, # M
3818               0x0045, # E
3819               0x004E, # N
3820              ]->[length $self->{kwd}] or
3821              $self->{nc} == [
3822               undef,
3823               undef,
3824               0x0065, # e
3825               0x006D, # m
3826               0x0065, # e
3827               0x006E, # n
3828              ]->[length $self->{kwd}]) {
3829            ## Stay in the state.
3830            $self->{kwd} .= chr $self->{nc};
3831            !!!next-input-character;
3832            redo A;
3833          } elsif ((length $self->{kwd}) == 6 and
3834                   ($self->{nc} == 0x0054 or # T
3835                    $self->{nc} == 0x0074)) { # t
3836            if ($self->{kwd} ne 'ELEMEN' or $self->{nc} == 0x0074) {
3837              !!!parse-error (type => 'lowercase keyword', ## TODO: type
3838                              text => 'ELEMENT',
3839                              line => $self->{line_prev},
3840                              column => $self->{column_prev} - 5);
3841            }
3842            $self->{ct} = {type => ELEMENT_TOKEN, name => '',
3843                           line => $self->{line_prev},
3844                           column => $self->{column_prev} - 6};
3845            $self->{state} = DOCTYPE_MD_STATE;
3846            !!!next-input-character;
3847            redo A;
3848          } else {
3849            !!!parse-error (type => 'bogus comment',
3850                            line => $self->{line_prev},
3851                            column => $self->{column_prev} - 1
3852                                - (length $self->{kwd})
3853                                + 1 * ($self->{nc} == -1));
3854            $self->{state} = BOGUS_COMMENT_STATE;
3855            ## Reconsume.
3856            $self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded
3857            redo A;
3858          }
3859        } elsif ($self->{state} == MD_ATTLIST_STATE) {
3860          if ($self->{nc} == [
3861               undef,
3862               0x0054, # T
3863               0x0054, # T
3864               0x004C, # L
3865               0x0049, # I
3866               0x0053, # S
3867              ]->[length $self->{kwd}] or
3868              $self->{nc} == [
3869               undef,
3870               0x0074, # t
3871               0x0074, # t
3872               0x006C, # l
3873               0x0069, # i
3874               0x0073, # s
3875              ]->[length $self->{kwd}]) {
3876            ## Stay in the state.
3877            $self->{kwd} .= chr $self->{nc};
3878            !!!next-input-character;
3879            redo A;
3880          } elsif ((length $self->{kwd}) == 6 and
3881                   ($self->{nc} == 0x0054 or # T
3882                    $self->{nc} == 0x0074)) { # t
3883            if ($self->{kwd} ne 'ATTLIS' or $self->{nc} == 0x0074) {
3884              !!!parse-error (type => 'lowercase keyword', ## TODO: type
3885                              text => 'ATTLIST',
3886                              line => $self->{line_prev},
3887                              column => $self->{column_prev} - 5);
3888            }
3889            $self->{ct} = {type => ATTLIST_TOKEN, name => '',
3890                           attrdefs => [],
3891                           line => $self->{line_prev},
3892                           column => $self->{column_prev} - 6};
3893            $self->{state} = DOCTYPE_MD_STATE;
3894            !!!next-input-character;
3895            redo A;
3896          } else {
3897            !!!parse-error (type => 'bogus comment',
3898                            line => $self->{line_prev},
3899                            column => $self->{column_prev} - 1
3900                                 - (length $self->{kwd})
3901                                 + 1 * ($self->{nc} == -1));
3902            $self->{state} = BOGUS_COMMENT_STATE;
3903            ## Reconsume.
3904            $self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded
3905            redo A;
3906          }
3907        } elsif ($self->{state} == MD_NOTATION_STATE) {
3908          if ($self->{nc} == [
3909               undef,
3910               0x004F, # O
3911               0x0054, # T
3912               0x0041, # A
3913               0x0054, # T
3914               0x0049, # I
3915               0x004F, # O
3916              ]->[length $self->{kwd}] or
3917              $self->{nc} == [
3918               undef,
3919               0x006F, # o
3920               0x0074, # t
3921               0x0061, # a
3922               0x0074, # t
3923               0x0069, # i
3924               0x006F, # o
3925              ]->[length $self->{kwd}]) {
3926            ## Stay in the state.
3927            $self->{kwd} .= chr $self->{nc};
3928            !!!next-input-character;
3929            redo A;
3930          } elsif ((length $self->{kwd}) == 7 and
3931                   ($self->{nc} == 0x004E or # N
3932                    $self->{nc} == 0x006E)) { # n
3933            if ($self->{kwd} ne 'NOTATIO' or $self->{nc} == 0x006E) {
3934              !!!parse-error (type => 'lowercase keyword', ## TODO: type
3935                              text => 'NOTATION',
3936                              line => $self->{line_prev},
3937                              column => $self->{column_prev} - 6);
3938            }
3939            $self->{ct} = {type => NOTATION_TOKEN, name => '',
3940                           line => $self->{line_prev},
3941                           column => $self->{column_prev} - 6};
3942            $self->{state} = DOCTYPE_MD_STATE;
3943            !!!next-input-character;
3944            redo A;
3945          } else {
3946            !!!parse-error (type => 'bogus comment',
3947                            line => $self->{line_prev},
3948                            column => $self->{column_prev} - 1
3949                                - (length $self->{kwd})
3950                                + 1 * ($self->{nc} == -1));
3951            $self->{state} = BOGUS_COMMENT_STATE;
3952            ## Reconsume.
3953            $self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded
3954            redo A;
3955          }
3956        } elsif ($self->{state} == DOCTYPE_MD_STATE) {
3957          ## XML5: "DOCTYPE ENTITY state", "DOCTYPE ATTLIST state", and
3958          ## "DOCTYPE NOTATION state".
3959    
3960          if ($is_space->{$self->{nc}}) {
3961            ## XML5: [NOTATION] Switch to the "DOCTYPE NOTATION identifier state".
3962            $self->{state} = BEFORE_MD_NAME_STATE;
3963            !!!next-input-character;
3964            redo A;
3965          } elsif ($self->{ct}->{type} == GENERAL_ENTITY_TOKEN and
3966                   $self->{nc} == 0x0025) { # %
3967            ## XML5: Switch to the "DOCTYPE bogus comment state".
3968            !!!parse-error (type => 'no space before md name'); ## TODO: type
3969            $self->{state} = DOCTYPE_ENTITY_PARAMETER_BEFORE_STATE;
3970            !!!next-input-character;
3971            redo A;
3972          } elsif ($self->{nc} == -1) {
3973            !!!parse-error (type => 'unclosed md'); ## TODO: type
3974            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
3975            ## Reconsume.
3976            redo A;
3977          } elsif ($self->{nc} == 0x003E) { # >
3978            ## XML5: Switch to the "DOCTYPE bogus comment state".
3979            !!!parse-error (type => 'no md name'); ## TODO: type
3980            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
3981            !!!next-input-character;
3982            redo A;
3983          } else {
3984            ## XML5: Switch to the "DOCTYPE bogus comment state".
3985            !!!parse-error (type => 'no space before md name'); ## TODO: type
3986            $self->{state} = BEFORE_MD_NAME_STATE;
3987            redo A;
3988          }
3989        } elsif ($self->{state} == BEFORE_MD_NAME_STATE) {
3990          ## XML5: "DOCTYPE ENTITY parameter state", "DOCTYPE ENTITY type
3991          ## before state", "DOCTYPE ATTLIST name before state".
3992    
3993          if ($is_space->{$self->{nc}}) {
3994            ## Stay in the state.
3995            !!!next-input-character;
3996            redo A;
3997          } elsif ($self->{ct}->{type} == GENERAL_ENTITY_TOKEN and
3998                   $self->{nc} == 0x0025) { # %
3999            $self->{state} = DOCTYPE_ENTITY_PARAMETER_BEFORE_STATE;
4000            !!!next-input-character;
4001            redo A;
4002          } elsif ($self->{nc} == 0x003E) { # >
4003            ## XML5: Same as "Anything else".
4004            !!!parse-error (type => 'no md name'); ## TODO: type
4005            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4006            !!!next-input-character;
4007            redo A;
4008          } elsif ($self->{nc} == -1) {
4009            !!!parse-error (type => 'unclosed md'); ## TODO: type
4010            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4011            ## Reconsume.
4012            redo A;
4013          } else {
4014            ## XML5: [ATTLIST] Not defined yet.
4015            $self->{ct}->{name} .= chr $self->{nc};
4016            $self->{state} = MD_NAME_STATE;
4017            !!!next-input-character;
4018            redo A;
4019          }
4020        } elsif ($self->{state} == DOCTYPE_ENTITY_PARAMETER_BEFORE_STATE) {
4021          if ($is_space->{$self->{nc}}) {
4022            ## XML5: Switch to the "DOCTYPE ENTITY parameter state".
4023            $self->{ct}->{type} = PARAMETER_ENTITY_TOKEN;
4024            $self->{state} = BEFORE_MD_NAME_STATE;
4025            !!!next-input-character;
4026            redo A;
4027          } elsif ($self->{nc} == 0x003E) { # >
4028            ## XML5: Same as "Anything else".
4029            !!!parse-error (type => 'no md name'); ## TODO: type
4030            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4031            !!!next-input-character;
4032            redo A;
4033          } elsif ($self->{nc} == -1) {
4034            !!!parse-error (type => 'unclosed md');
4035            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4036            ## Reconsume.
4037            redo A;
4038          } else {
4039            ## XML5: No parse error.
4040            !!!parse-error (type => 'no space after ENTITY percent'); ## TODO: type
4041            $self->{state} = BOGUS_COMMENT_STATE;
4042            $self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded
4043            ## Reconsume.
4044            redo A;
4045          }
4046        } elsif ($self->{state} == MD_NAME_STATE) {
4047          ## XML5: "DOCTYPE ENTITY name state" and "DOCTYPE ATTLIST name state".
4048          
4049          if ($is_space->{$self->{nc}}) {
4050            if ($self->{ct}->{type} == ATTLIST_TOKEN) {
4051              $self->{state} = DOCTYPE_ATTLIST_NAME_AFTER_STATE;
4052            } elsif ($self->{ct}->{type} == ELEMENT_TOKEN) {
4053              $self->{state} = AFTER_ELEMENT_NAME_STATE;
4054            } else { # ENTITY/NOTATION
4055              $self->{state} = AFTER_DOCTYPE_NAME_STATE;
4056            }
4057            !!!next-input-character;
4058            redo A;
4059          } elsif ($self->{nc} == 0x003E) { # >
4060            if ($self->{ct}->{type} == ATTLIST_TOKEN) {
4061              #
4062            } else {
4063              !!!parse-error (type => 'no md def'); ## TODO: type
4064            }
4065            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4066            !!!next-input-character;
4067            !!!emit ($self->{ct}); # ELEMENT/ENTITY/ATTLIST/NOTATION
4068            redo A;
4069          } elsif ($self->{nc} == -1) {
4070            ## XML5: [ATTLIST] No parse error.
4071            !!!parse-error (type => 'unclosed md');
4072            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4073            ## Reconsume.
4074            !!!emit ($self->{ct}); # ELEMENT/ENTITY/ATTLIST/NOTATION
4075            redo A;
4076          } else {
4077            ## XML5: [ATTLIST] Not defined yet.
4078            $self->{ct}->{name} .= chr $self->{nc};
4079            ## Stay in the state.
4080            !!!next-input-character;
4081            redo A;
4082          }
4083        } elsif ($self->{state} == DOCTYPE_ATTLIST_NAME_AFTER_STATE) {
4084          if ($is_space->{$self->{nc}}) {
4085            ## Stay in the state.
4086            !!!next-input-character;
4087            redo A;
4088          } elsif ($self->{nc} == 0x003E) { # >
4089            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4090            !!!next-input-character;
4091            !!!emit ($self->{ct}); # ATTLIST
4092            redo A;
4093          } elsif ($self->{nc} == -1) {
4094            ## XML5: No parse error.
4095            !!!parse-error (type => 'unclosed md'); ## TODO: type
4096            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4097            !!!emit ($self->{ct});
4098            redo A;
4099          } else {
4100            ## XML5: Not defined yet.
4101            $self->{ca} = {name => chr ($self->{nc}), # attrdef
4102                           tokens => [],
4103                           line => $self->{line}, column => $self->{column}};
4104            $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_NAME_STATE;
4105            !!!next-input-character;
4106            redo A;
4107          }
4108        } elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_NAME_STATE) {
4109          if ($is_space->{$self->{nc}}) {
4110            $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_NAME_AFTER_STATE;
4111            !!!next-input-character;
4112            redo A;
4113          } elsif ($self->{nc} == 0x003E) { # >
4114            ## XML5: Same as "anything else".
4115            !!!parse-error (type => 'no attr type'); ## TODO: type
4116            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4117            !!!next-input-character;
4118            !!!emit ($self->{ct}); # ATTLIST
4119            redo A;
4120          } elsif ($self->{nc} == 0x0028) { # (
4121            ## XML5: Same as "anything else".
4122            !!!parse-error (type => 'no space before paren'); ## TODO: type
4123            $self->{state} = BEFORE_ALLOWED_TOKEN_STATE;
4124            !!!next-input-character;
4125            redo A;
4126          } elsif ($self->{nc} == -1) {
4127            ## XML5: No parse error.
4128            !!!parse-error (type => 'unclosed md'); ## TODO: type
4129            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4130            !!!next-input-character;
4131            !!!emit ($self->{ct}); # ATTLIST
4132            redo A;
4133          } else {
4134            ## XML5: Not defined yet.
4135            $self->{ca}->{name} .= chr $self->{nc};
4136            ## Stay in the state.
4137            !!!next-input-character;
4138            redo A;
4139          }
4140        } elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_NAME_AFTER_STATE) {
4141          if ($is_space->{$self->{nc}}) {
4142            ## Stay in the state.
4143            !!!next-input-character;
4144            redo A;
4145          } elsif ($self->{nc} == 0x003E) { # >
4146            ## XML5: Same as "anything else".
4147            !!!parse-error (type => 'no attr type'); ## TODO: type
4148            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4149            !!!next-input-character;
4150            !!!emit ($self->{ct}); # ATTLIST
4151            redo A;
4152          } elsif ($self->{nc} == 0x0028) { # (
4153            ## XML5: Same as "anything else".
4154            $self->{state} = BEFORE_ALLOWED_TOKEN_STATE;
4155            !!!next-input-character;
4156            redo A;
4157          } elsif ($self->{nc} == -1) {
4158            ## XML5: No parse error.
4159            !!!parse-error (type => 'unclosed md'); ## TODO: type
4160            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4161            !!!next-input-character;
4162            !!!emit ($self->{ct});
4163            redo A;
4164          } else {
4165            ## XML5: Not defined yet.
4166            $self->{ca}->{type} = chr $self->{nc};
4167            $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_TYPE_STATE;
4168            !!!next-input-character;
4169            redo A;
4170          }
4171        } elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_TYPE_STATE) {
4172          if ($is_space->{$self->{nc}}) {
4173            $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_TYPE_AFTER_STATE;
4174            !!!next-input-character;
4175            redo A;
4176          } elsif ($self->{nc} == 0x0023) { # #
4177            ## XML5: Same as "anything else".
4178            !!!parse-error (type => 'no space before default value'); ## TODO: type
4179            $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE;
4180            !!!next-input-character;
4181            redo A;
4182          } elsif ($self->{nc} == 0x0022) { # "
4183            ## XML5: Same as "anything else".
4184            !!!parse-error (type => 'no space before default value'); ## TODO: type
4185            $self->{ca}->{value} = '';
4186            $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
4187            !!!next-input-character;
4188            redo A;
4189          } elsif ($self->{nc} == 0x0027) { # '
4190            ## XML5: Same as "anything else".
4191            !!!parse-error (type => 'no space before default value'); ## TODO: type
4192            $self->{ca}->{value} = '';
4193            $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
4194            !!!next-input-character;
4195            redo A;
4196          } elsif ($self->{nc} == 0x003E) { # >
4197            ## XML5: Same as "anything else".
4198            !!!parse-error (type => 'no attr default'); ## TODO: type
4199            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4200            !!!next-input-character;
4201            !!!emit ($self->{ct}); # ATTLIST
4202            redo A;
4203          } elsif ($self->{nc} == 0x0028) { # (
4204            ## XML5: Same as "anything else".
4205            !!!parse-error (type => 'no space before paren'); ## TODO: type
4206            $self->{state} = BEFORE_ALLOWED_TOKEN_STATE;
4207            !!!next-input-character;
4208            redo A;
4209          } elsif ($self->{nc} == -1) {
4210            ## XML5: No parse error.
4211            !!!parse-error (type => 'unclosed md'); ## TODO: type
4212            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4213            !!!next-input-character;
4214            !!!emit ($self->{ct});
4215            redo A;
4216          } else {
4217            ## XML5: Not defined yet.
4218            $self->{ca}->{type} .= chr $self->{nc};
4219            ## Stay in the state.
4220            !!!next-input-character;
4221            redo A;
4222          }
4223        } elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_TYPE_AFTER_STATE) {
4224          if ($is_space->{$self->{nc}}) {
4225            ## Stay in the state.
4226            !!!next-input-character;
4227            redo A;
4228          } elsif ($self->{nc} == 0x0028) { # (
4229            ## XML5: Same as "anything else".
4230            $self->{state} = BEFORE_ALLOWED_TOKEN_STATE;
4231            !!!next-input-character;
4232            redo A;
4233          } elsif ($self->{nc} == 0x0023) { # #
4234            $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE;
4235            !!!next-input-character;
4236            redo A;
4237          } elsif ($self->{nc} == 0x0022) { # "
4238            ## XML5: Same as "anything else".
4239            $self->{ca}->{value} = '';
4240            $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
4241            !!!next-input-character;
4242            redo A;
4243          } elsif ($self->{nc} == 0x0027) { # '
4244            ## XML5: Same as "anything else".
4245            $self->{ca}->{value} = '';
4246            $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
4247            !!!next-input-character;
4248            redo A;
4249          } elsif ($self->{nc} == 0x003E) { # >
4250            ## XML5: Same as "anything else".
4251            !!!parse-error (type => 'no attr default'); ## TODO: type
4252            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4253            !!!next-input-character;
4254            !!!emit ($self->{ct}); # ATTLIST
4255            redo A;
4256          } elsif ($self->{nc} == -1) {
4257            ## XML5: No parse error.
4258            !!!parse-error (type => 'unclosed md'); ## TODO: type
4259            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4260            !!!next-input-character;
4261            !!!emit ($self->{ct});
4262            redo A;
4263          } else {
4264            ## XML5: Switch to the "DOCTYPE bogus comment state".
4265            !!!parse-error (type => 'unquoted attr value'); ## TODO: type
4266            $self->{ca}->{value} = '';
4267            $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
4268            ## Reconsume.
4269            redo A;
4270          }
4271        } elsif ($self->{state} == BEFORE_ALLOWED_TOKEN_STATE) {
4272          if ($is_space->{$self->{nc}}) {
4273            ## Stay in the state.
4274            !!!next-input-character;
4275            redo A;
4276          } elsif ($self->{nc} == 0x007C) { # |
4277            !!!parse-error (type => 'empty allowed token'); ## TODO: type
4278            ## Stay in the state.
4279            !!!next-input-character;
4280            redo A;
4281          } elsif ($self->{nc} == 0x0029) { # )
4282            !!!parse-error (type => 'empty allowed token'); ## TODO: type
4283            $self->{state} = AFTER_ALLOWED_TOKENS_STATE;
4284            !!!next-input-character;
4285            redo A;
4286          } elsif ($self->{nc} == 0x003E) { # >
4287            !!!parse-error (type => 'unclosed allowed tokens'); ## TODO: type
4288            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4289            !!!next-input-character;
4290            !!!emit ($self->{ct}); # ATTLIST
4291            redo A;
4292          } elsif ($self->{nc} == -1) {
4293            ## XML5: No parse error.
4294            !!!parse-error (type => 'unclosed md'); ## TODO: type
4295            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4296            !!!next-input-character;
4297            !!!emit ($self->{ct});
4298            redo A;
4299          } else {
4300            push @{$self->{ca}->{tokens}}, chr $self->{nc};
4301            $self->{state} = ALLOWED_TOKEN_STATE;
4302            !!!next-input-character;
4303            redo A;
4304          }
4305        } elsif ($self->{state} == ALLOWED_TOKEN_STATE) {
4306          if ($is_space->{$self->{nc}}) {
4307            $self->{state} = AFTER_ALLOWED_TOKEN_STATE;
4308            !!!next-input-character;
4309            redo A;
4310          } elsif ($self->{nc} == 0x007C) { # |
4311            $self->{state} = BEFORE_ALLOWED_TOKEN_STATE;
4312            !!!next-input-character;
4313            redo A;
4314          } elsif ($self->{nc} == 0x0029) { # )
4315            $self->{state} = AFTER_ALLOWED_TOKENS_STATE;
4316            !!!next-input-character;
4317            redo A;
4318          } elsif ($self->{nc} == 0x003E) { # >
4319            !!!parse-error (type => 'unclosed allowed tokens'); ## TODO: type
4320            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4321            !!!next-input-character;
4322            !!!emit ($self->{ct}); # ATTLIST
4323            redo A;
4324          } elsif ($self->{nc} == -1) {
4325            ## XML5: No parse error.
4326            !!!parse-error (type => 'unclosed md'); ## TODO: type
4327            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4328            !!!next-input-character;
4329            !!!emit ($self->{ct});
4330            redo A;
4331          } else {
4332            $self->{ca}->{tokens}->[-1] .= chr $self->{nc};
4333            ## Stay in the state.
4334            !!!next-input-character;
4335            redo A;
4336          }
4337        } elsif ($self->{state} == AFTER_ALLOWED_TOKEN_STATE) {
4338          if ($is_space->{$self->{nc}}) {
4339            ## Stay in the state.
4340            !!!next-input-character;
4341            redo A;
4342          } elsif ($self->{nc} == 0x007C) { # |
4343            $self->{state} = BEFORE_ALLOWED_TOKEN_STATE;
4344            !!!next-input-character;
4345            redo A;
4346          } elsif ($self->{nc} == 0x0029) { # )
4347            $self->{state} = AFTER_ALLOWED_TOKENS_STATE;
4348            !!!next-input-character;
4349            redo A;
4350          } elsif ($self->{nc} == 0x003E) { # >
4351            !!!parse-error (type => 'unclosed allowed tokens'); ## TODO: type
4352            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4353            !!!next-input-character;
4354            !!!emit ($self->{ct}); # ATTLIST
4355            redo A;
4356          } elsif ($self->{nc} == -1) {
4357            ## XML5: No parse error.
4358            !!!parse-error (type => 'unclosed md'); ## TODO: type
4359            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4360            !!!next-input-character;
4361            !!!emit ($self->{ct});
4362            redo A;
4363          } else {
4364            !!!parse-error (type => 'space in allowed token', ## TODO: type
4365                            line => $self->{line_prev},
4366                            column => $self->{column_prev});
4367            $self->{ca}->{tokens}->[-1] .= ' ' . chr $self->{nc};
4368            $self->{state} = ALLOWED_TOKEN_STATE;
4369            !!!next-input-character;
4370            redo A;
4371          }
4372        } elsif ($self->{state} == AFTER_ALLOWED_TOKENS_STATE) {
4373          if ($is_space->{$self->{nc}}) {
4374            $self->{state} = BEFORE_ATTR_DEFAULT_STATE;
4375            !!!next-input-character;
4376            redo A;
4377          } elsif ($self->{nc} == 0x0023) { # #
4378            !!!parse-error (type => 'no space before default value'); ## TODO: type
4379            $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE;
4380            !!!next-input-character;
4381            redo A;
4382          } elsif ($self->{nc} == 0x0022) { # "
4383            !!!parse-error (type => 'no space before default value'); ## TODO: type
4384            $self->{ca}->{value} = '';
4385            $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
4386            !!!next-input-character;
4387            redo A;
4388          } elsif ($self->{nc} == 0x0027) { # '
4389            !!!parse-error (type => 'no space before default value'); ## TODO: type
4390            $self->{ca}->{value} = '';
4391            $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
4392            !!!next-input-character;
4393            redo A;
4394          } elsif ($self->{nc} == 0x003E) { # >
4395            !!!parse-error (type => 'no attr default'); ## TODO: type
4396            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4397            !!!next-input-character;
4398            !!!emit ($self->{ct}); # ATTLIST
4399            redo A;
4400          } elsif ($self->{nc} == -1) {
4401            !!!parse-error (type => 'unclosed md'); ## TODO: type
4402            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4403            !!!next-input-character;
4404            !!!emit ($self->{ct});
4405            redo A;
4406          } else {
4407            !!!parse-error (type => 'unquoted attr value'); ## TODO: type
4408            $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
4409            ## Reconsume.
4410            redo A;
4411          }
4412        } elsif ($self->{state} == BEFORE_ATTR_DEFAULT_STATE) {
4413          if ($is_space->{$self->{nc}}) {
4414            ## Stay in the state.
4415            !!!next-input-character;
4416            redo A;
4417          } elsif ($self->{nc} == 0x0023) { # #
4418            $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE;
4419            !!!next-input-character;
4420            redo A;
4421          } elsif ($self->{nc} == 0x0022) { # "
4422            $self->{ca}->{value} = '';
4423            $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
4424            !!!next-input-character;
4425            redo A;
4426          } elsif ($self->{nc} == 0x0027) { # '
4427            $self->{ca}->{value} = '';
4428            $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
4429            !!!next-input-character;
4430            redo A;
4431          } elsif ($self->{nc} == 0x003E) { # >
4432            !!!parse-error (type => 'no attr default'); ## TODO: type
4433            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4434            !!!next-input-character;
4435            !!!emit ($self->{ct}); # ATTLIST
4436            redo A;
4437          } elsif ($self->{nc} == -1) {
4438            !!!parse-error (type => 'unclosed md'); ## TODO: type
4439            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4440            !!!next-input-character;
4441            !!!emit ($self->{ct});
4442            redo A;
4443          } else {
4444            !!!parse-error (type => 'unquoted attr value'); ## TODO: type
4445            $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
4446            ## Reconsume.
4447            redo A;
4448          }
4449        } elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE) {
4450          if ($is_space->{$self->{nc}}) {
4451            ## XML5: No parse error.
4452            !!!parse-error (type => 'no default type'); ## TODO: type
4453            $self->{state} = BOGUS_MD_STATE;
4454            ## Reconsume.
4455            redo A;
4456          } elsif ($self->{nc} == 0x0022) { # "
4457            ## XML5: Same as "anything else".
4458            $self->{ca}->{value} = '';
4459            $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
4460            !!!next-input-character;
4461            redo A;
4462          } elsif ($self->{nc} == 0x0027) { # '
4463            ## XML5: Same as "anything else".
4464            $self->{ca}->{value} = '';
4465            $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
4466            !!!next-input-character;
4467            redo A;
4468          } elsif ($self->{nc} == 0x003E) { # >
4469            ## XML5: Same as "anything else".
4470            !!!parse-error (type => 'no attr default'); ## TODO: type
4471            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4472            !!!next-input-character;
4473            !!!emit ($self->{ct}); # ATTLIST
4474            redo A;
4475          } elsif ($self->{nc} == -1) {
4476            ## XML5: No parse error.
4477            !!!parse-error (type => 'unclosed md'); ## TODO: type
4478            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4479            !!!next-input-character;
4480            !!!emit ($self->{ct});
4481            redo A;
4482          } else {
4483            $self->{ca}->{default} = chr $self->{nc};
4484            $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_STATE;
4485            !!!next-input-character;
4486            redo A;
4487          }
4488        } elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_STATE) {
4489          if ($is_space->{$self->{nc}}) {
4490            $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_AFTER_STATE;
4491            !!!next-input-character;
4492            redo A;
4493          } elsif ($self->{nc} == 0x0022) { # "
4494            ## XML5: Same as "anything else".
4495            !!!parse-error (type => 'no space before default value'); ## TODO: type
4496            $self->{ca}->{value} = '';
4497            $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
4498            !!!next-input-character;
4499            redo A;
4500          } elsif ($self->{nc} == 0x0027) { # '
4501            ## XML5: Same as "anything else".
4502            !!!parse-error (type => 'no space before default value'); ## TODO: type
4503            $self->{ca}->{value} = '';
4504            $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
4505            !!!next-input-character;
4506            redo A;
4507          } elsif ($self->{nc} == 0x003E) { # >
4508            ## XML5: Same as "anything else".
4509            push @{$self->{ct}->{attrdefs}}, $self->{ca};
4510            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4511            !!!next-input-character;
4512            !!!emit ($self->{ct}); # ATTLIST
4513            redo A;
4514          } elsif ($self->{nc} == -1) {
4515            ## XML5: No parse error.
4516            !!!parse-error (type => 'unclosed md'); ## TODO: type
4517            push @{$self->{ct}->{attrdefs}}, $self->{ca};
4518            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4519            !!!next-input-character;
4520            !!!emit ($self->{ct});
4521            redo A;
4522          } else {
4523            $self->{ca}->{default} .= chr $self->{nc};
4524            ## Stay in the state.
4525            !!!next-input-character;
4526            redo A;
4527          }
4528        } elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_AFTER_STATE) {
4529          if ($is_space->{$self->{nc}}) {
4530            ## Stay in the state.
4531            !!!next-input-character;
4532            redo A;
4533          } elsif ($self->{nc} == 0x0022) { # "
4534            $self->{ca}->{value} = '';
4535            $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
4536            !!!next-input-character;
4537            redo A;
4538          } elsif ($self->{nc} == 0x0027) { # '
4539            $self->{ca}->{value} = '';
4540            $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
4541            !!!next-input-character;
4542            redo A;
4543          } elsif ($self->{nc} == 0x003E) { # >
4544            push @{$self->{ct}->{attrdefs}}, $self->{ca};
4545            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4546            !!!next-input-character;
4547            !!!emit ($self->{ct}); # ATTLIST
4548            redo A;
4549          } elsif ($self->{nc} == -1) {
4550            ## XML5: No parse error.
4551            !!!parse-error (type => 'unclosed md'); ## TODO: type
4552            push @{$self->{ct}->{attrdefs}}, $self->{ca};
4553            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4554            !!!next-input-character;
4555            !!!emit ($self->{ct});
4556            redo A;
4557          } else {
4558            ## XML5: Not defined yet.
4559            if ($self->{ca}->{default} eq 'FIXED') {
4560              $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
4561            } else {
4562              push @{$self->{ct}->{attrdefs}}, $self->{ca};
4563              $self->{state} = DOCTYPE_ATTLIST_NAME_AFTER_STATE;
4564            }
4565            ## Reconsume.
4566            redo A;
4567          }
4568        } elsif ($self->{state} == AFTER_ATTLIST_ATTR_VALUE_QUOTED_STATE) {
4569          if ($is_space->{$self->{nc}} or
4570              $self->{nc} == -1 or
4571              $self->{nc} == 0x003E) { # >
4572            $self->{state} = DOCTYPE_ATTLIST_NAME_AFTER_STATE;
4573            ## Reconsume.
4574            redo A;
4575          } else {
4576            !!!parse-error (type => 'no space before attr name'); ## TODO: type
4577            $self->{state} = DOCTYPE_ATTLIST_NAME_AFTER_STATE;
4578            ## Reconsume.
4579            redo A;
4580          }
4581        } elsif ($self->{state} == NDATA_STATE) {
4582          ## ASCII case-insensitive
4583          if ($self->{nc} == [
4584                undef,
4585                0x0044, # D
4586                0x0041, # A
4587                0x0054, # T
4588              ]->[length $self->{kwd}] or
4589              $self->{nc} == [
4590                undef,
4591                0x0064, # d
4592                0x0061, # a
4593                0x0074, # t
4594              ]->[length $self->{kwd}]) {
4595            !!!cp (172.2);
4596            ## Stay in the state.
4597            $self->{kwd} .= chr $self->{nc};
4598            !!!next-input-character;
4599            redo A;
4600          } elsif ((length $self->{kwd}) == 4 and
4601                   ($self->{nc} == 0x0041 or # A
4602                    $self->{nc} == 0x0061)) { # a
4603            if ($self->{kwd} ne 'NDAT' or $self->{nc} == 0x0061) { # a
4604              !!!cp (172.3);
4605              !!!parse-error (type => 'lowercase keyword', ## TODO: type
4606                              text => 'NDATA',
4607                              line => $self->{line_prev},
4608                              column => $self->{column_prev} - 4);
4609            } else {
4610              !!!cp (172.4);
4611            }
4612            $self->{state} = AFTER_NDATA_STATE;
4613            !!!next-input-character;
4614            redo A;
4615          } else {
4616            !!!parse-error (type => 'string after literal', ## TODO: type
4617                            line => $self->{line_prev},
4618                            column => $self->{column_prev} + 1
4619                                - length $self->{kwd});
4620            !!!cp (172.5);
4621            $self->{state} = BOGUS_MD_STATE;
4622            ## Reconsume.
4623            redo A;
4624          }
4625        } elsif ($self->{state} == AFTER_NDATA_STATE) {
4626          if ($is_space->{$self->{nc}}) {
4627            $self->{state} = BEFORE_NOTATION_NAME_STATE;
4628            !!!next-input-character;
4629            redo A;
4630          } elsif ($self->{nc} == 0x003E) { # >
4631            !!!parse-error (type => 'no notation name'); ## TODO: type
4632            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4633            !!!next-input-character;
4634            !!!emit ($self->{ct}); # ENTITY
4635            redo A;
4636          } elsif ($self->{nc} == -1) {
4637            !!!parse-error (type => 'unclosed md'); ## TODO: type
4638            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4639            !!!next-input-character;
4640            !!!emit ($self->{ct}); # ENTITY
4641            redo A;
4642          } else {
4643            !!!parse-error (type => 'string after literal', ## TODO: type
4644                            line => $self->{line_prev},
4645                            column => $self->{column_prev} + 1
4646                                - length $self->{kwd});
4647            $self->{state} = BOGUS_MD_STATE;
4648            ## Reconsume.
4649            redo A;
4650          }
4651        } elsif ($self->{state} == BEFORE_NOTATION_NAME_STATE) {
4652          if ($is_space->{$self->{nc}}) {
4653            ## Stay in the state.
4654            !!!next-input-character;
4655            redo A;
4656          } elsif ($self->{nc} == 0x003E) { # >
4657            !!!parse-error (type => 'no notation name'); ## TODO: type
4658            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4659            !!!next-input-character;
4660            !!!emit ($self->{ct}); # ENTITY
4661            redo A;
4662          } elsif ($self->{nc} == -1) {
4663            !!!parse-error (type => 'unclosed md'); ## TODO: type
4664            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4665            !!!next-input-character;
4666            !!!emit ($self->{ct}); # ENTITY
4667            redo A;
4668          } else {
4669            $self->{ct}->{notation} = chr $self->{nc}; # ENTITY
4670            $self->{state} = NOTATION_NAME_STATE;
4671            !!!next-input-character;
4672            redo A;
4673          }
4674        } elsif ($self->{state} == NOTATION_NAME_STATE) {
4675          if ($is_space->{$self->{nc}}) {
4676            $self->{state} = AFTER_MD_DEF_STATE;
4677            !!!next-input-character;
4678            redo A;
4679          } elsif ($self->{nc} == 0x003E) { # >
4680            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4681            !!!next-input-character;
4682            !!!emit ($self->{ct}); # ENTITY
4683            redo A;
4684          } elsif ($self->{nc} == -1) {
4685            !!!parse-error (type => 'unclosed md'); ## TODO: type
4686            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4687            !!!next-input-character;
4688            !!!emit ($self->{ct}); # ENTITY
4689            redo A;
4690          } else {
4691            $self->{ct}->{notation} .= chr $self->{nc}; # ENTITY
4692            ## Stay in the state.
4693            !!!next-input-character;
4694            redo A;
4695          }
4696        } elsif ($self->{state} == DOCTYPE_ENTITY_VALUE_DOUBLE_QUOTED_STATE) {
4697          if ($self->{nc} == 0x0022) { # "
4698            $self->{state} = AFTER_MD_DEF_STATE;
4699            !!!next-input-character;
4700            redo A;
4701          } elsif ($self->{nc} == 0x0026) { # &
4702            $self->{prev_state} = $self->{state};
4703            $self->{state} = ENTITY_VALUE_ENTITY_STATE;
4704            $self->{entity_add} = 0x0022; # "
4705            !!!next-input-character;
4706            redo A;
4707    ## TODO: %
4708          } elsif ($self->{nc} == -1) {
4709            !!!parse-error (type => 'unclosed entity value'); ## TODO: type
4710            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4711            ## Reconsume.
4712            !!!emit ($self->{ct}); # ENTITY
4713            redo A;
4714          } else {
4715            $self->{ct}->{value} .= chr $self->{nc}; # ENTITY
4716            !!!next-input-character;
4717            redo A;
4718          }
4719        } elsif ($self->{state} == DOCTYPE_ENTITY_VALUE_SINGLE_QUOTED_STATE) {
4720          if ($self->{nc} == 0x0027) { # '
4721            $self->{state} = AFTER_MD_DEF_STATE;
4722            !!!next-input-character;
4723            redo A;
4724          } elsif ($self->{nc} == 0x0026) { # &
4725            $self->{prev_state} = $self->{state};
4726            $self->{state} = ENTITY_VALUE_ENTITY_STATE;
4727            $self->{entity_add} = 0x0027; # '
4728            !!!next-input-character;
4729            redo A;
4730    ## TODO: %
4731          } elsif ($self->{nc} == -1) {
4732            !!!parse-error (type => 'unclosed entity value'); ## TODO: type
4733            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4734            ## Reconsume.
4735            !!!emit ($self->{ct}); # ENTITY
4736            redo A;
4737          } else {
4738            $self->{ct}->{value} .= chr $self->{nc}; # ENTITY
4739            !!!next-input-character;
4740            redo A;
4741          }
4742        } elsif ($self->{state} == ENTITY_VALUE_ENTITY_STATE) {
4743          ## TODO: XMLize
4744    
4745          if ($is_space->{$self->{nc}} or
4746              {
4747                0x003C => 1, 0x0026 => 1, -1 => 1, # <, &
4748                $self->{entity_add} => 1,
4749              }->{$self->{nc}}) {
4750            ## Don't consume
4751            ## No error
4752            ## Return nothing.
4753            #
4754          } elsif ($self->{nc} == 0x0023) { # #
4755            $self->{ca} = $self->{ct};
4756            $self->{state} = ENTITY_HASH_STATE;
4757            $self->{kwd} = '#';
4758            !!!next-input-character;
4759            redo A;
4760          } elsif ((0x0041 <= $self->{nc} and
4761                    $self->{nc} <= 0x005A) or # A..Z
4762                   (0x0061 <= $self->{nc} and
4763                    $self->{nc} <= 0x007A)) { # a..z
4764            #
4765          } else {
4766            !!!parse-error (type => 'bare ero');
4767            ## Return nothing.
4768            #
4769          }
4770    
4771          $self->{ct}->{value} .= '&';
4772          $self->{state} = $self->{prev_state};
4773          ## Reconsume.
4774          redo A;
4775        } elsif ($self->{state} == AFTER_ELEMENT_NAME_STATE) {
4776          if ($is_space->{$self->{nc}}) {
4777            $self->{state} = BEFORE_ELEMENT_CONTENT_STATE;
4778            !!!next-input-character;
4779            redo A;
4780          } elsif ($self->{nc} == 0x0028) { # (
4781            $self->{state} = AFTER_CM_GROUP_OPEN_STATE;
4782            $self->{ct}->{content} = ['('];
4783            $self->{group_depth} = 1;
4784            !!!next-input-character;
4785            redo A;
4786          } elsif ($self->{nc} == 0x003E) { # >
4787            !!!parse-error (type => 'no md def'); ## TODO: type
4788            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4789            !!!next-input-character;
4790            !!!emit ($self->{ct}); # ELEMENT
4791            redo A;
4792          } elsif ($self->{nc} == -1) {
4793            !!!parse-error (type => 'unclosed md'); ## TODO: type
4794            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4795            !!!next-input-character;
4796            !!!emit ($self->{ct}); # ELEMENT
4797            redo A;
4798          } else {
4799            $self->{ct}->{content} = [chr $self->{nc}];
4800            $self->{state} = CONTENT_KEYWORD_STATE;
4801            !!!next-input-character;
4802            redo A;
4803          }
4804        } elsif ($self->{state} == CONTENT_KEYWORD_STATE) {
4805          if ($is_space->{$self->{nc}}) {
4806            $self->{state} = AFTER_MD_DEF_STATE;
4807            !!!next-input-character;
4808            redo A;
4809          } elsif ($self->{nc} == 0x003E) { # >
4810            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4811            !!!next-input-character;
4812            !!!emit ($self->{ct}); # ELEMENT
4813            redo A;
4814          } elsif ($self->{nc} == -1) {
4815            !!!parse-error (type => 'unclosed md'); ## TODO: type
4816            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4817            !!!next-input-character;
4818            !!!emit ($self->{ct}); # ELEMENT
4819            redo A;
4820          } else {
4821            $self->{ct}->{content}->[-1] .= chr $self->{nc}; # ELEMENT
4822            ## Stay in the state.
4823            !!!next-input-character;
4824            redo A;
4825          }
4826        } elsif ($self->{state} == AFTER_CM_GROUP_OPEN_STATE) {
4827          if ($is_space->{$self->{nc}}) {
4828            ## Stay in the state.
4829            !!!next-input-character;
4830            redo A;
4831          } elsif ($self->{nc} == 0x0028) { # (
4832            $self->{group_depth}++;
4833            push @{$self->{ct}->{content}}, chr $self->{nc};
4834            ## Stay in the state.
4835            !!!next-input-character;
4836            redo A;
4837          } elsif ($self->{nc} == 0x007C or # |
4838                   $self->{nc} == 0x002C) { # ,
4839            !!!parse-error (type => 'empty element name'); ## TODO: type
4840            ## Stay in the state.
4841            !!!next-input-character;
4842            redo A;
4843          } elsif ($self->{nc} == 0x0029) { # )
4844            !!!parse-error (type => 'empty element name'); ## TODO: type
4845            push @{$self->{ct}->{content}}, chr $self->{nc};
4846            $self->{group_depth}--;
4847            $self->{state} = AFTER_CM_GROUP_CLOSE_STATE;
4848            !!!next-input-character;
4849            redo A;
4850          } elsif ($self->{nc} == 0x003E) { # >
4851            !!!parse-error (type => 'unclosed cm group'); ## TODO: type
4852            push @{$self->{ct}->{content}}, (')') x $self->{group_depth};
4853            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4854            !!!next-input-character;
4855            !!!emit ($self->{ct}); # ELEMENT
4856            redo A;
4857          } elsif ($self->{nc} == -1) {
4858            !!!parse-error (type => 'unclosed md'); ## TODO: type
4859            push @{$self->{ct}->{content}}, (')') x $self->{group_depth};
4860            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4861            !!!next-input-character;
4862            !!!emit ($self->{ct}); # ELEMENT
4863            redo A;
4864          } else {
4865            push @{$self->{ct}->{content}}, chr $self->{nc};
4866            $self->{state} = CM_ELEMENT_NAME_STATE;
4867            !!!next-input-character;
4868            redo A;
4869          }
4870        } elsif ($self->{state} == CM_ELEMENT_NAME_STATE) {
4871          if ($is_space->{$self->{nc}}) {
4872            $self->{state} = AFTER_CM_ELEMENT_NAME_STATE;
4873            !!!next-input-character;
4874            redo A;
4875          } elsif ($self->{nc} == 0x002A or # *
4876                   $self->{nc} == 0x002B or # +
4877                   $self->{nc} == 0x003F) { # ?
4878            push @{$self->{ct}->{content}}, chr $self->{nc};
4879            $self->{state} = AFTER_CM_ELEMENT_NAME_STATE;
4880            !!!next-input-character;
4881            redo A;
4882          } elsif ($self->{nc} == 0x007C or # |
4883                   $self->{nc} == 0x002C) { # ,
4884            push @{$self->{ct}->{content}}, $self->{nc} == 0x007C ? ' | ' : ', ';
4885            $self->{state} = AFTER_CM_GROUP_OPEN_STATE;
4886            !!!next-input-character;
4887            redo A;
4888          } elsif ($self->{nc} == 0x0029) { # )
4889            $self->{group_depth}--;
4890            push @{$self->{ct}->{content}}, chr $self->{nc};
4891            $self->{state} = AFTER_CM_GROUP_CLOSE_STATE;
4892            !!!next-input-character;
4893            redo A;
4894          } elsif ($self->{nc} == 0x003E) { # >
4895            !!!parse-error (type => 'unclosed cm group'); ## TODO: type
4896            push @{$self->{ct}->{content}}, (')') x $self->{group_depth};
4897            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4898            !!!next-input-character;
4899            !!!emit ($self->{ct}); # ELEMENT
4900            redo A;
4901          } elsif ($self->{nc} == -1) {
4902            !!!parse-error (type => 'unclosed md'); ## TODO: type
4903            push @{$self->{ct}->{content}}, (')') x $self->{group_depth};
4904            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4905            !!!next-input-character;
4906            !!!emit ($self->{ct}); # ELEMENT
4907            redo A;
4908          } else {
4909            $self->{ct}->{content}->[-1] .= chr $self->{nc};
4910            ## Stay in the state.
4911            !!!next-input-character;
4912            redo A;
4913          }
4914        } elsif ($self->{state} == AFTER_CM_ELEMENT_NAME_STATE) {
4915          if ($is_space->{$self->{nc}}) {
4916            ## Stay in the state.
4917            !!!next-input-character;
4918            redo A;
4919          } elsif ($self->{nc} == 0x007C or # |
4920                   $self->{nc} == 0x002C) { # ,
4921            push @{$self->{ct}->{content}}, $self->{nc} == 0x007C ? ' | ' : ', ';
4922            $self->{state} = AFTER_CM_GROUP_OPEN_STATE;
4923            !!!next-input-character;
4924            redo A;
4925          } elsif ($self->{nc} == 0x0029) { # )
4926            $self->{group_depth}--;
4927            push @{$self->{ct}->{content}}, chr $self->{nc};
4928            $self->{state} = AFTER_CM_GROUP_CLOSE_STATE;
4929            !!!next-input-character;
4930            redo A;
4931          } elsif ($self->{nc} == 0x003E) { # >
4932            !!!parse-error (type => 'unclosed cm group'); ## TODO: type
4933            push @{$self->{ct}->{content}}, (')') x $self->{group_depth};
4934            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4935            !!!next-input-character;
4936            !!!emit ($self->{ct}); # ELEMENT
4937            redo A;
4938          } elsif ($self->{nc} == -1) {
4939            !!!parse-error (type => 'unclosed md'); ## TODO: type
4940            push @{$self->{ct}->{content}}, (')') x $self->{group_depth};
4941            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4942            !!!next-input-character;
4943            !!!emit ($self->{ct}); # ELEMENT
4944            redo A;
4945          } else {
4946            !!!parse-error (type => 'after element name'); ## TODO: type
4947            push @{$self->{ct}->{content}}, (')') x $self->{group_depth};
4948            $self->{state} = BOGUS_MD_STATE;
4949            !!!next-input-character;
4950            redo A;
4951          }
4952        } elsif ($self->{state} == AFTER_CM_GROUP_CLOSE_STATE) {
4953          if ($is_space->{$self->{nc}}) {
4954            if ($self->{group_depth}) {
4955              $self->{state} = AFTER_CM_ELEMENT_NAME_STATE;
4956            } else {
4957              $self->{state} = AFTER_MD_DEF_STATE;
4958            }
4959            !!!next-input-character;
4960            redo A;
4961          } elsif ($self->{nc} == 0x002A or # *
4962                   $self->{nc} == 0x002B or # +
4963                   $self->{nc} == 0x003F) { # ?
4964            push @{$self->{ct}->{content}}, chr $self->{nc};
4965            if ($self->{group_depth}) {
4966              $self->{state} = AFTER_CM_ELEMENT_NAME_STATE;
4967            } else {
4968              $self->{state} = AFTER_MD_DEF_STATE;
4969            }
4970            !!!next-input-character;
4971            redo A;
4972          } elsif ($self->{nc} == 0x0029) { # )
4973            if ($self->{group_depth}) {
4974              $self->{group_depth}--;
4975              push @{$self->{ct}->{content}}, chr $self->{nc};
4976              ## Stay in the state.
4977              !!!next-input-character;
4978              redo A;
4979            } else {
4980              !!!parse-error (type => 'string after md def'); ## TODO: type
4981              $self->{state} = BOGUS_MD_STATE;
4982              ## Reconsume.
4983              redo A;
4984            }
4985          } elsif ($self->{nc} == 0x003E) { # >
4986            if ($self->{group_depth}) {
4987              !!!parse-error (type => 'unclosed cm group'); ## TODO: type
4988              push @{$self->{ct}->{content}}, (')') x $self->{group_depth};
4989            }
4990            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4991            !!!next-input-character;
4992            !!!emit ($self->{ct}); # ELEMENT
4993            redo A;
4994          } elsif ($self->{nc} == -1) {
4995            !!!parse-error (type => 'unclosed md'); ## TODO: type
4996            push @{$self->{ct}->{content}}, (')') x $self->{group_depth};
4997            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4998            !!!next-input-character;
4999            !!!emit ($self->{ct}); # ELEMENT
5000            redo A;
5001          } else {
5002            if ($self->{group_depth}) {
5003              $self->{state} = AFTER_CM_ELEMENT_NAME_STATE;
5004            } else {
5005              !!!parse-error (type => 'string after md def'); ## TODO: type
5006              $self->{state} = BOGUS_MD_STATE;
5007            }
5008            ## Reconsume.
5009            redo A;
5010          }
5011        } elsif ($self->{state} == AFTER_MD_DEF_STATE) {
5012          if ($is_space->{$self->{nc}}) {
5013            ## Stay in the state.
5014            !!!next-input-character;
5015            redo A;
5016          } elsif ($self->{nc} == 0x003E) { # >
5017            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
5018            !!!next-input-character;
5019            !!!emit ($self->{ct}); # ENTITY/ELEMENT
5020            redo A;
5021          } elsif ($self->{nc} == -1) {
5022            !!!parse-error (type => 'unclosed md'); ## TODO: type
5023            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
5024            !!!next-input-character;
5025            !!!emit ($self->{ct}); # ENTITY/ELEMENT
5026            redo A;
5027          } else {
5028            !!!parse-error (type => 'string after md def'); ## TODO: type
5029            $self->{state} = BOGUS_MD_STATE;
5030            ## Reconsume.
5031            redo A;
5032          }
5033        } elsif ($self->{state} == BOGUS_MD_STATE) {
5034          if ($self->{nc} == 0x003E) { # >
5035            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
5036            !!!next-input-character;
5037            !!!emit ($self->{ct}); # ATTLIST/ENTITY/NOTATION
5038            redo A;
5039          } elsif ($self->{nc} == -1) {
5040            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
5041            ## Reconsume.
5042            !!!emit ($self->{ct}); # ATTLIST/ENTITY/NOTATION
5043            redo A;
5044          } else {
5045            ## Stay in the state.
5046            !!!next-input-character;
5047            redo A;
5048          }
5049      } else {      } else {
5050        die "$0: $self->{state}: Unknown state";        die "$0: $self->{state}: Unknown state";
5051      }      }
# Line 3001  sub _get_next_token ($) { Line 5056  sub _get_next_token ($) {
5056    
5057  1;  1;
5058  ## $Date$  ## $Date$
5059                                    

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.20

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24