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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.21 - (show annotations) (download) (as text)
Sun Oct 19 09:25:21 2008 UTC (16 years ago) by wakaba
Branch: MAIN
Changes since 1.20: +53 -16 lines
File MIME type: application/x-wais-source
++ whatpm/t/ChangeLog	19 Oct 2008 09:24:46 -0000
	* XML-Parser.t: "xml/entrefs-1.dat" added.

2008-10-19  Wakaba  <wakaba@suika.fam.cx>

++ whatpm/t/xml/ChangeLog	19 Oct 2008 09:25:15 -0000
	* charrefs-1.dat: New test data added.

	* entrefs-1.dat: New test data file.

	* attlists-1.dat: Test results updated.

2008-10-19  Wakaba  <wakaba@suika.fam.cx>

++ whatpm/Whatpm/HTML/ChangeLog	19 Oct 2008 09:23:24 -0000
	* Tokenizer.pm.src: Make uppercase "&#X" in XML a parse error.
	Remove the limitation of entity name length.  Enable replacement
	of text-only general entities.  Raise a parse error for an
	unparsed entity reference.  Raise a parse error for a general
	entity reference to an undefined entity.

2008-10-19  Wakaba  <wakaba@suika.fam.cx>

++ whatpm/Whatpm/XML/ChangeLog	19 Oct 2008 09:24:32 -0000
	* Parser.pm.src: Define predefined general entities for the
	control of "undeclared entity" error raised by the tokenizer.  Set
	text-only flag to general entities appropriately.

2008-10-19  Wakaba  <wakaba@suika.fam.cx>

1 package Whatpm::HTML::Tokenizer;
2 use strict;
3 our $VERSION=do{my @r=(q$Revision: 1.20 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
4
5 BEGIN {
6 require Exporter;
7 push our @ISA, 'Exporter';
8
9 our @EXPORT_OK = qw(
10 DOCTYPE_TOKEN
11 COMMENT_TOKEN
12 START_TAG_TOKEN
13 END_TAG_TOKEN
14 END_OF_FILE_TOKEN
15 CHARACTER_TOKEN
16 PI_TOKEN
17 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 = (
27 token => [qw(
28 DOCTYPE_TOKEN
29 COMMENT_TOKEN
30 START_TAG_TOKEN
31 END_TAG_TOKEN
32 END_OF_FILE_TOKEN
33 CHARACTER_TOKEN
34 PI_TOKEN
35 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
49
50 sub DOCTYPE_TOKEN () { 1 } ## XML5: No DOCTYPE token.
51 sub COMMENT_TOKEN () { 2 }
52 sub START_TAG_TOKEN () { 3 }
53 sub END_TAG_TOKEN () { 4 }
54 sub END_OF_FILE_TOKEN () { 5 }
55 sub CHARACTER_TOKEN () { 6 }
56 sub PI_TOKEN () { 7 } ## NOTE: XML only.
57 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;
74
75 BEGIN { Whatpm::HTML::Tokenizer->import (':token') }
76
77 ## Content model flags
78
79 sub CM_ENTITY () { 0b001 } # & markup in data
80 sub CM_LIMITED_MARKUP () { 0b010 } # < markup in data (limited)
81 sub CM_FULL_MARKUP () { 0b100 } # < markup in data (any)
82
83 sub PLAINTEXT_CONTENT_MODEL () { 0 }
84 sub CDATA_CONTENT_MODEL () { CM_LIMITED_MARKUP }
85 sub RCDATA_CONTENT_MODEL () { CM_ENTITY | CM_LIMITED_MARKUP }
86 sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }
87
88 ## Tokenizer states
89
90 sub DATA_STATE () { 0 }
91 #sub ENTITY_DATA_STATE () { 1 }
92 sub TAG_OPEN_STATE () { 2 }
93 sub CLOSE_TAG_OPEN_STATE () { 3 }
94 sub TAG_NAME_STATE () { 4 }
95 sub BEFORE_ATTRIBUTE_NAME_STATE () { 5 }
96 sub ATTRIBUTE_NAME_STATE () { 6 }
97 sub AFTER_ATTRIBUTE_NAME_STATE () { 7 }
98 sub BEFORE_ATTRIBUTE_VALUE_STATE () { 8 }
99 sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 }
100 sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 }
101 sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 }
102 #sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 }
103 sub MARKUP_DECLARATION_OPEN_STATE () { 13 }
104 sub COMMENT_START_STATE () { 14 }
105 sub COMMENT_START_DASH_STATE () { 15 }
106 sub COMMENT_STATE () { 16 }
107 sub COMMENT_END_STATE () { 17 }
108 sub COMMENT_END_DASH_STATE () { 18 }
109 sub BOGUS_COMMENT_STATE () { 19 }
110 sub DOCTYPE_STATE () { 20 }
111 sub BEFORE_DOCTYPE_NAME_STATE () { 21 }
112 sub DOCTYPE_NAME_STATE () { 22 }
113 sub AFTER_DOCTYPE_NAME_STATE () { 23 }
114 sub BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE () { 24 }
115 sub DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE () { 25 }
116 sub DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE () { 26 }
117 sub AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE () { 27 }
118 sub BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE () { 28 }
119 sub DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE () { 29 }
120 sub DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE () { 30 }
121 sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE () { 31 }
122 sub BOGUS_DOCTYPE_STATE () { 32 }
123 sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }
124 sub SELF_CLOSING_START_TAG_STATE () { 34 }
125 sub CDATA_SECTION_STATE () { 35 }
126 sub MD_HYPHEN_STATE () { 36 } # "markup declaration open state" in the spec
127 sub MD_DOCTYPE_STATE () { 37 } # "markup declaration open state" in the spec
128 sub MD_CDATA_STATE () { 38 } # "markup declaration open state" in the spec
129 sub CDATA_RCDATA_CLOSE_TAG_STATE () { 39 } # "close tag open state" in the spec
130 sub CDATA_SECTION_MSE1_STATE () { 40 } # "CDATA section state" in the spec
131 sub CDATA_SECTION_MSE2_STATE () { 41 } # "CDATA section state" in the spec
132 sub PUBLIC_STATE () { 42 } # "after DOCTYPE name state" in the spec
133 sub SYSTEM_STATE () { 43 } # "after DOCTYPE name state" in the spec
134 ## NOTE: "Entity data state", "entity in attribute value state", and
135 ## "consume a character reference" algorithm are jointly implemented
136 ## using the following six states:
137 sub ENTITY_STATE () { 44 }
138 sub ENTITY_HASH_STATE () { 45 }
139 sub NCR_NUM_STATE () { 46 }
140 sub HEXREF_X_STATE () { 47 }
141 sub HEXREF_HEX_STATE () { 48 }
142 sub ENTITY_NAME_STATE () { 49 }
143 sub PCDATA_STATE () { 50 } # "data state" in the spec
144
145 ## XML-only states
146 sub PI_STATE () { 51 }
147 sub PI_TARGET_STATE () { 52 }
148 sub PI_TARGET_AFTER_STATE () { 53 }
149 sub PI_DATA_STATE () { 54 }
150 sub PI_AFTER_STATE () { 55 }
151 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
199 ## list and descriptions)
200
201 sub IN_FOREIGN_CONTENT_IM () { 0b100000000000 }
202 sub FOREIGN_EL () { 0b1_00000000000 }
203
204 ## Character reference mappings
205
206 my $charref_map = {
207 0x0D => 0x000A,
208 0x80 => 0x20AC,
209 0x81 => 0xFFFD,
210 0x82 => 0x201A,
211 0x83 => 0x0192,
212 0x84 => 0x201E,
213 0x85 => 0x2026,
214 0x86 => 0x2020,
215 0x87 => 0x2021,
216 0x88 => 0x02C6,
217 0x89 => 0x2030,
218 0x8A => 0x0160,
219 0x8B => 0x2039,
220 0x8C => 0x0152,
221 0x8D => 0xFFFD,
222 0x8E => 0x017D,
223 0x8F => 0xFFFD,
224 0x90 => 0xFFFD,
225 0x91 => 0x2018,
226 0x92 => 0x2019,
227 0x93 => 0x201C,
228 0x94 => 0x201D,
229 0x95 => 0x2022,
230 0x96 => 0x2013,
231 0x97 => 0x2014,
232 0x98 => 0x02DC,
233 0x99 => 0x2122,
234 0x9A => 0x0161,
235 0x9B => 0x203A,
236 0x9C => 0x0153,
237 0x9D => 0xFFFD,
238 0x9E => 0x017E,
239 0x9F => 0x0178,
240 }; # $charref_map
241 $charref_map->{$_} = 0xFFFD
242 for 0x0000..0x0008, 0x000B, 0x000E..0x001F, 0x007F,
243 0xD800..0xDFFF, 0xFDD0..0xFDDF, ## ISSUE: 0xFDEF
244 0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF, 0x2FFFE, 0x2FFFF, 0x3FFFE, 0x3FFFF,
245 0x4FFFE, 0x4FFFF, 0x5FFFE, 0x5FFFF, 0x6FFFE, 0x6FFFF, 0x7FFFE,
246 0x7FFFF, 0x8FFFE, 0x8FFFF, 0x9FFFE, 0x9FFFF, 0xAFFFE, 0xAFFFF,
247 0xBFFFE, 0xBFFFF, 0xCFFFE, 0xCFFFF, 0xDFFFE, 0xDFFFF, 0xEFFFE,
248 0xEFFFF, 0xFFFFE, 0xFFFFF, 0x10FFFE, 0x10FFFF;
249
250 ## Implementations MUST act as if state machine in the spec
251
252 sub _initialize_tokenizer ($) {
253 my $self = shift;
254
255 ## NOTE: Fields set by |new| constructor:
256 #$self->{level}
257 #$self->{set_nc}
258 #$self->{parse_error}
259 #$self->{is_xml} (if XML)
260
261 $self->{state} = DATA_STATE; # MUST
262 $self->{s_kwd} = ''; # Data state keyword
263 #$self->{kwd} = ''; # State-dependent keyword; initialized when used
264 #$self->{entity__value}; # initialized when used
265 #$self->{entity__match}; # initialized when used
266 $self->{content_model} = PCDATA_CONTENT_MODEL; # be
267 undef $self->{ct}; # current token
268 undef $self->{ca}; # current attribute
269 undef $self->{last_stag_name}; # last emitted start tag name
270 #$self->{prev_state}; # initialized when used
271 delete $self->{self_closing};
272 $self->{char_buffer} = '';
273 $self->{char_buffer_pos} = 0;
274 $self->{nc} = -1; # next input character
275 #$self->{next_nc}
276 !!!next-input-character;
277 $self->{token} = [];
278 # $self->{escape}
279 } # _initialize_tokenizer
280
281 ## A token has:
282 ## ->{type} == DOCTYPE_TOKEN, START_TAG_TOKEN, END_TAG_TOKEN, COMMENT_TOKEN,
283 ## CHARACTER_TOKEN, END_OF_FILE_TOKEN, PI_TOKEN, or ABORT_TOKEN
284 ## ->{name} (DOCTYPE_TOKEN)
285 ## ->{tag_name} (START_TAG_TOKEN, END_TAG_TOKEN)
286 ## ->{target} (PI_TOKEN)
287 ## ->{pubid} (DOCTYPE_TOKEN)
288 ## ->{sysid} (DOCTYPE_TOKEN)
289 ## ->{quirks} == 1 or 0 (DOCTYPE_TOKEN): "force-quirks" flag
290 ## ->{attributes} isa HASH (START_TAG_TOKEN, END_TAG_TOKEN)
291 ## ->{name}
292 ## ->{value}
293 ## ->{has_reference} == 1 or 0
294 ## ->{index}: Index of the attribute in a tag.
295 ## ->{data} (COMMENT_TOKEN, CHARACTER_TOKEN, PI_TOKEN)
296 ## ->{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}|.
301 ## |->{self_closing}| is used to save the value of |$self->{self_closing}|
302 ## while the token is pushed back to the stack.
303
304 ## Emitted token MUST immediately be handled by the tree construction state.
305
306 ## Before each step, UA MAY check to see if either one of the scripts in
307 ## "list of scripts that will execute as soon as possible" or the first
308 ## script in the "list of scripts that will execute asynchronously",
309 ## has completed loading. If one has, then it MUST be executed
310 ## and removed from the list.
311
312 ## TODO: Polytheistic slash SHOULD NOT be used. (Applied only to atheists.)
313 ## (This requirement was dropped from HTML5 spec, unfortunately.)
314
315 my $is_space = {
316 0x0009 => 1, # CHARACTER TABULATION (HT)
317 0x000A => 1, # LINE FEED (LF)
318 #0x000B => 0, # LINE TABULATION (VT)
319 0x000C => 1, # FORM FEED (FF) ## XML5: Not a space character.
320 #0x000D => 1, # CARRIAGE RETURN (CR)
321 0x0020 => 1, # SPACE (SP)
322 };
323
324 sub _get_next_token ($) {
325 my $self = shift;
326
327 if ($self->{self_closing}) {
328 !!!parse-error (type => 'nestc', token => $self->{ct});
329 ## NOTE: The |self_closing| flag is only set by start tag token.
330 ## In addition, when a start tag token is emitted, it is always set to
331 ## |ct|.
332 delete $self->{self_closing};
333 }
334
335 if (@{$self->{token}}) {
336 $self->{self_closing} = $self->{token}->[0]->{self_closing};
337 return shift @{$self->{token}};
338 }
339
340 A: {
341 if ($self->{state} == PCDATA_STATE) {
342 ## NOTE: Same as |DATA_STATE|, but only for |PCDATA| content model.
343
344 if ($self->{nc} == 0x0026) { # &
345 !!!cp (0.1);
346 ## NOTE: In the spec, the tokenizer is switched to the
347 ## "entity data state". In this implementation, the tokenizer
348 ## is switched to the |ENTITY_STATE|, which is an implementation
349 ## of the "consume a character reference" algorithm.
350 $self->{entity_add} = -1;
351 $self->{prev_state} = DATA_STATE;
352 $self->{state} = ENTITY_STATE;
353 !!!next-input-character;
354 redo A;
355 } elsif ($self->{nc} == 0x003C) { # <
356 !!!cp (0.2);
357 $self->{state} = TAG_OPEN_STATE;
358 !!!next-input-character;
359 redo A;
360 } elsif ($self->{nc} == -1) {
361 !!!cp (0.3);
362 !!!emit ({type => END_OF_FILE_TOKEN,
363 line => $self->{line}, column => $self->{column}});
364 last A; ## TODO: ok?
365 } else {
366 !!!cp (0.4);
367 #
368 }
369
370 # Anything else
371 my $token = {type => CHARACTER_TOKEN,
372 data => chr $self->{nc},
373 line => $self->{line}, column => $self->{column},
374 };
375 $self->{read_until}->($token->{data}, q[<&], length $token->{data});
376
377 ## Stay in the state.
378 !!!next-input-character;
379 !!!emit ($token);
380 redo A;
381 } elsif ($self->{state} == DATA_STATE) {
382 $self->{s_kwd} = '' unless defined $self->{s_kwd};
383 if ($self->{nc} == 0x0026) { # &
384 $self->{s_kwd} = '';
385 if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA
386 not $self->{escape}) {
387 !!!cp (1);
388 ## NOTE: In the spec, the tokenizer is switched to the
389 ## "entity data state". In this implementation, the tokenizer
390 ## is switched to the |ENTITY_STATE|, which is an implementation
391 ## of the "consume a character reference" algorithm.
392 $self->{entity_add} = -1;
393 $self->{prev_state} = DATA_STATE;
394 $self->{state} = ENTITY_STATE;
395 !!!next-input-character;
396 redo A;
397 } else {
398 !!!cp (2);
399 #
400 }
401 } elsif ($self->{nc} == 0x002D) { # -
402 if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
403 if ($self->{s_kwd} eq '<!-') {
404 !!!cp (3);
405 $self->{escape} = 1; # unless $self->{escape};
406 $self->{s_kwd} = '--';
407 #
408 } elsif ($self->{s_kwd} eq '-') {
409 !!!cp (4);
410 $self->{s_kwd} = '--';
411 #
412 } elsif ($self->{s_kwd} eq '<!' or $self->{s_kwd} eq '-') {
413 !!!cp (4.1);
414 $self->{s_kwd} .= '-';
415 #
416 } else {
417 !!!cp (5);
418 $self->{s_kwd} = '-';
419 #
420 }
421 }
422
423 #
424 } elsif ($self->{nc} == 0x0021) { # !
425 if (length $self->{s_kwd}) {
426 !!!cp (5.1);
427 $self->{s_kwd} .= '!';
428 #
429 } else {
430 !!!cp (5.2);
431 #$self->{s_kwd} = '';
432 #
433 }
434 #
435 } elsif ($self->{nc} == 0x003C) { # <
436 if ($self->{content_model} & CM_FULL_MARKUP or # PCDATA
437 (($self->{content_model} & CM_LIMITED_MARKUP) and # CDATA | RCDATA
438 not $self->{escape})) {
439 !!!cp (6);
440 $self->{state} = TAG_OPEN_STATE;
441 !!!next-input-character;
442 redo A;
443 } else {
444 !!!cp (7);
445 $self->{s_kwd} = '';
446 #
447 }
448 } elsif ($self->{nc} == 0x003E) { # >
449 if ($self->{escape} and
450 ($self->{content_model} & CM_LIMITED_MARKUP)) { # RCDATA | CDATA
451 if ($self->{s_kwd} eq '--') {
452 !!!cp (8);
453 delete $self->{escape};
454 #
455 } else {
456 !!!cp (9);
457 #
458 }
459 } elsif ($self->{is_xml} and $self->{s_kwd} eq ']]') {
460 !!!cp (9.1);
461 !!!parse-error (type => 'unmatched mse', ## TODO: type
462 line => $self->{line_prev},
463 column => $self->{column_prev} - 1);
464 #
465 } else {
466 !!!cp (10);
467 #
468 }
469
470 $self->{s_kwd} = '';
471 #
472 } elsif ($self->{nc} == 0x005D) { # ]
473 if ($self->{s_kwd} eq ']' or $self->{s_kwd} eq '') {
474 !!!cp (10.1);
475 $self->{s_kwd} .= ']';
476 } elsif ($self->{s_kwd} eq ']]') {
477 !!!cp (10.2);
478 #
479 } else {
480 !!!cp (10.3);
481 $self->{s_kwd} = '';
482 }
483 #
484 } elsif ($self->{nc} == -1) {
485 !!!cp (11);
486 $self->{s_kwd} = '';
487 !!!emit ({type => END_OF_FILE_TOKEN,
488 line => $self->{line}, column => $self->{column}});
489 last A; ## TODO: ok?
490 } else {
491 !!!cp (12);
492 $self->{s_kwd} = '';
493 #
494 }
495
496 # Anything else
497 my $token = {type => CHARACTER_TOKEN,
498 data => chr $self->{nc},
499 line => $self->{line}, column => $self->{column},
500 };
501 if ($self->{read_until}->($token->{data}, q{-!<>&\]},
502 length $token->{data})) {
503 $self->{s_kwd} = '';
504 }
505
506 ## Stay in the data state.
507 if (not $self->{is_xml} and
508 $self->{content_model} == PCDATA_CONTENT_MODEL) {
509 !!!cp (13);
510 $self->{state} = PCDATA_STATE;
511 } else {
512 !!!cp (14);
513 ## Stay in the state.
514 }
515 !!!next-input-character;
516 !!!emit ($token);
517 redo A;
518 } elsif ($self->{state} == TAG_OPEN_STATE) {
519 ## XML5: "tag state".
520
521 if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
522 if ($self->{nc} == 0x002F) { # /
523 !!!cp (15);
524 !!!next-input-character;
525 $self->{state} = CLOSE_TAG_OPEN_STATE;
526 redo A;
527 } elsif ($self->{nc} == 0x0021) { # !
528 !!!cp (15.1);
529 $self->{s_kwd} = $self->{escaped} ? '' : '<';
530 #
531 } else {
532 !!!cp (16);
533 $self->{s_kwd} = '';
534 #
535 }
536
537 ## reconsume
538 $self->{state} = DATA_STATE;
539 !!!emit ({type => CHARACTER_TOKEN, data => '<',
540 line => $self->{line_prev},
541 column => $self->{column_prev},
542 });
543 redo A;
544 } elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA
545 if ($self->{nc} == 0x0021) { # !
546 !!!cp (17);
547 $self->{state} = MARKUP_DECLARATION_OPEN_STATE;
548 !!!next-input-character;
549 redo A;
550 } elsif ($self->{nc} == 0x002F) { # /
551 !!!cp (18);
552 $self->{state} = CLOSE_TAG_OPEN_STATE;
553 !!!next-input-character;
554 redo A;
555 } elsif (0x0041 <= $self->{nc} and
556 $self->{nc} <= 0x005A) { # A..Z
557 !!!cp (19);
558 $self->{ct}
559 = {type => START_TAG_TOKEN,
560 tag_name => chr ($self->{nc} + ($self->{is_xml} ? 0 : 0x0020)),
561 line => $self->{line_prev},
562 column => $self->{column_prev}};
563 $self->{state} = TAG_NAME_STATE;
564 !!!next-input-character;
565 redo A;
566 } elsif (0x0061 <= $self->{nc} and
567 $self->{nc} <= 0x007A) { # a..z
568 !!!cp (20);
569 $self->{ct} = {type => START_TAG_TOKEN,
570 tag_name => chr ($self->{nc}),
571 line => $self->{line_prev},
572 column => $self->{column_prev}};
573 $self->{state} = TAG_NAME_STATE;
574 !!!next-input-character;
575 redo A;
576 } elsif ($self->{nc} == 0x003E) { # >
577 !!!cp (21);
578 !!!parse-error (type => 'empty start tag',
579 line => $self->{line_prev},
580 column => $self->{column_prev});
581 $self->{state} = DATA_STATE;
582 $self->{s_kwd} = '';
583 !!!next-input-character;
584
585 !!!emit ({type => CHARACTER_TOKEN, data => '<>',
586 line => $self->{line_prev},
587 column => $self->{column_prev},
588 });
589
590 redo A;
591 } elsif ($self->{nc} == 0x003F) { # ?
592 if ($self->{is_xml}) {
593 !!!cp (22.1);
594 $self->{state} = PI_STATE;
595 !!!next-input-character;
596 redo A;
597 } else {
598 !!!cp (22);
599 !!!parse-error (type => 'pio',
600 line => $self->{line_prev},
601 column => $self->{column_prev});
602 $self->{state} = BOGUS_COMMENT_STATE;
603 $self->{ct} = {type => COMMENT_TOKEN, data => '',
604 line => $self->{line_prev},
605 column => $self->{column_prev},
606 };
607 ## $self->{nc} is intentionally left as is
608 redo A;
609 }
610 } elsif (not $self->{is_xml} or $is_space->{$self->{nc}}) {
611 !!!cp (23);
612 !!!parse-error (type => 'bare stago',
613 line => $self->{line_prev},
614 column => $self->{column_prev});
615 $self->{state} = DATA_STATE;
616 $self->{s_kwd} = '';
617 ## reconsume
618
619 !!!emit ({type => CHARACTER_TOKEN, data => '<',
620 line => $self->{line_prev},
621 column => $self->{column_prev},
622 });
623
624 redo A;
625 } else {
626 ## XML5: "<:" is a parse error.
627 !!!cp (23.1);
628 $self->{ct} = {type => START_TAG_TOKEN,
629 tag_name => chr ($self->{nc}),
630 line => $self->{line_prev},
631 column => $self->{column_prev}};
632 $self->{state} = TAG_NAME_STATE;
633 !!!next-input-character;
634 redo A;
635 }
636 } else {
637 die "$0: $self->{content_model} in tag open";
638 }
639 } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) {
640 ## NOTE: The "close tag open state" in the spec is implemented as
641 ## |CLOSE_TAG_OPEN_STATE| and |CDATA_RCDATA_CLOSE_TAG_STATE|.
642
643 ## XML5: "end tag state".
644
645 my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</"
646 if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
647 if (defined $self->{last_stag_name}) {
648 $self->{state} = CDATA_RCDATA_CLOSE_TAG_STATE;
649 $self->{kwd} = '';
650 ## Reconsume.
651 redo A;
652 } else {
653 ## No start tag token has ever been emitted
654 ## NOTE: See <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>.
655 !!!cp (28);
656 $self->{state} = DATA_STATE;
657 $self->{s_kwd} = '';
658 ## Reconsume.
659 !!!emit ({type => CHARACTER_TOKEN, data => '</',
660 line => $l, column => $c,
661 });
662 redo A;
663 }
664 }
665
666 if (0x0041 <= $self->{nc} and
667 $self->{nc} <= 0x005A) { # A..Z
668 !!!cp (29);
669 $self->{ct}
670 = {type => END_TAG_TOKEN,
671 tag_name => chr ($self->{nc} + ($self->{is_xml} ? 0 : 0x0020)),
672 line => $l, column => $c};
673 $self->{state} = TAG_NAME_STATE;
674 !!!next-input-character;
675 redo A;
676 } elsif (0x0061 <= $self->{nc} and
677 $self->{nc} <= 0x007A) { # a..z
678 !!!cp (30);
679 $self->{ct} = {type => END_TAG_TOKEN,
680 tag_name => chr ($self->{nc}),
681 line => $l, column => $c};
682 $self->{state} = TAG_NAME_STATE;
683 !!!next-input-character;
684 redo A;
685 } elsif ($self->{nc} == 0x003E) { # >
686 !!!parse-error (type => 'empty end tag',
687 line => $self->{line_prev}, ## "<" in "</>"
688 column => $self->{column_prev} - 1);
689 $self->{state} = DATA_STATE;
690 $self->{s_kwd} = '';
691 if ($self->{is_xml}) {
692 !!!cp (31);
693 ## XML5: No parse error.
694
695 ## NOTE: This parser raises a parse error, since it supports
696 ## XML1, not XML5.
697
698 ## NOTE: A short end tag token.
699 my $ct = {type => END_TAG_TOKEN,
700 tag_name => '',
701 line => $self->{line_prev},
702 column => $self->{column_prev} - 1,
703 };
704 !!!next-input-character;
705 !!!emit ($ct);
706 } else {
707 !!!cp (31.1);
708 !!!next-input-character;
709 }
710 redo A;
711 } elsif ($self->{nc} == -1) {
712 !!!cp (32);
713 !!!parse-error (type => 'bare etago');
714 $self->{s_kwd} = '';
715 $self->{state} = DATA_STATE;
716 # reconsume
717
718 !!!emit ({type => CHARACTER_TOKEN, data => '</',
719 line => $l, column => $c,
720 });
721
722 redo A;
723 } elsif (not $self->{is_xml} or
724 $is_space->{$self->{nc}}) {
725 !!!cp (33);
726 !!!parse-error (type => 'bogus end tag',
727 line => $self->{line_prev}, # "<" of "</"
728 column => $self->{column_prev} - 1);
729 $self->{state} = BOGUS_COMMENT_STATE;
730 $self->{ct} = {type => COMMENT_TOKEN, data => '',
731 line => $self->{line_prev}, # "<" of "</"
732 column => $self->{column_prev} - 1,
733 };
734 ## NOTE: $self->{nc} is intentionally left as is.
735 ## Although the "anything else" case of the spec not explicitly
736 ## states that the next input character is to be reconsumed,
737 ## it will be included to the |data| of the comment token
738 ## generated from the bogus end tag, as defined in the
739 ## "bogus comment state" entry.
740 redo A;
741 } else {
742 ## XML5: "</:" is a parse error.
743 !!!cp (30.1);
744 $self->{ct} = {type => END_TAG_TOKEN,
745 tag_name => chr ($self->{nc}),
746 line => $l, column => $c};
747 $self->{state} = TAG_NAME_STATE; ## XML5: "end tag name state".
748 !!!next-input-character;
749 redo A;
750 }
751 } elsif ($self->{state} == CDATA_RCDATA_CLOSE_TAG_STATE) {
752 my $ch = substr $self->{last_stag_name}, length $self->{kwd}, 1;
753 if (length $ch) {
754 my $CH = $ch;
755 $ch =~ tr/a-z/A-Z/;
756 my $nch = chr $self->{nc};
757 if ($nch eq $ch or $nch eq $CH) {
758 !!!cp (24);
759 ## Stay in the state.
760 $self->{kwd} .= $nch;
761 !!!next-input-character;
762 redo A;
763 } else {
764 !!!cp (25);
765 $self->{state} = DATA_STATE;
766 $self->{s_kwd} = '';
767 ## Reconsume.
768 !!!emit ({type => CHARACTER_TOKEN,
769 data => '</' . $self->{kwd},
770 line => $self->{line_prev},
771 column => $self->{column_prev} - 1 - length $self->{kwd},
772 });
773 redo A;
774 }
775 } else { # after "<{tag-name}"
776 unless ($is_space->{$self->{nc}} or
777 {
778 0x003E => 1, # >
779 0x002F => 1, # /
780 -1 => 1, # EOF
781 }->{$self->{nc}}) {
782 !!!cp (26);
783 ## Reconsume.
784 $self->{state} = DATA_STATE;
785 $self->{s_kwd} = '';
786 !!!emit ({type => CHARACTER_TOKEN,
787 data => '</' . $self->{kwd},
788 line => $self->{line_prev},
789 column => $self->{column_prev} - 1 - length $self->{kwd},
790 });
791 redo A;
792 } else {
793 !!!cp (27);
794 $self->{ct}
795 = {type => END_TAG_TOKEN,
796 tag_name => $self->{last_stag_name},
797 line => $self->{line_prev},
798 column => $self->{column_prev} - 1 - length $self->{kwd}};
799 $self->{state} = TAG_NAME_STATE;
800 ## Reconsume.
801 redo A;
802 }
803 }
804 } elsif ($self->{state} == TAG_NAME_STATE) {
805 if ($is_space->{$self->{nc}}) {
806 !!!cp (34);
807 $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
808 !!!next-input-character;
809 redo A;
810 } elsif ($self->{nc} == 0x003E) { # >
811 if ($self->{ct}->{type} == START_TAG_TOKEN) {
812 !!!cp (35);
813 $self->{last_stag_name} = $self->{ct}->{tag_name};
814 } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
815 $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
816 #if ($self->{ct}->{attributes}) {
817 # ## NOTE: This should never be reached.
818 # !!! cp (36);
819 # !!! parse-error (type => 'end tag attribute');
820 #} else {
821 !!!cp (37);
822 #}
823 } else {
824 die "$0: $self->{ct}->{type}: Unknown token type";
825 }
826 $self->{state} = DATA_STATE;
827 $self->{s_kwd} = '';
828 !!!next-input-character;
829
830 !!!emit ($self->{ct}); # start tag or end tag
831
832 redo A;
833 } elsif (0x0041 <= $self->{nc} and
834 $self->{nc} <= 0x005A) { # A..Z
835 !!!cp (38);
836 $self->{ct}->{tag_name}
837 .= chr ($self->{nc} + ($self->{is_xml} ? 0 : 0x0020));
838 # start tag or end tag
839 ## Stay in this state
840 !!!next-input-character;
841 redo A;
842 } elsif ($self->{nc} == -1) {
843 !!!parse-error (type => 'unclosed tag');
844 if ($self->{ct}->{type} == START_TAG_TOKEN) {
845 !!!cp (39);
846 $self->{last_stag_name} = $self->{ct}->{tag_name};
847 } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
848 $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
849 #if ($self->{ct}->{attributes}) {
850 # ## NOTE: This state should never be reached.
851 # !!! cp (40);
852 # !!! parse-error (type => 'end tag attribute');
853 #} else {
854 !!!cp (41);
855 #}
856 } else {
857 die "$0: $self->{ct}->{type}: Unknown token type";
858 }
859 $self->{state} = DATA_STATE;
860 $self->{s_kwd} = '';
861 # reconsume
862
863 !!!emit ($self->{ct}); # start tag or end tag
864
865 redo A;
866 } elsif ($self->{nc} == 0x002F) { # /
867 !!!cp (42);
868 $self->{state} = SELF_CLOSING_START_TAG_STATE;
869 !!!next-input-character;
870 redo A;
871 } else {
872 !!!cp (44);
873 $self->{ct}->{tag_name} .= chr $self->{nc};
874 # start tag or end tag
875 ## Stay in the state
876 !!!next-input-character;
877 redo A;
878 }
879 } elsif ($self->{state} == BEFORE_ATTRIBUTE_NAME_STATE) {
880 ## XML5: "Tag attribute name before state".
881
882 if ($is_space->{$self->{nc}}) {
883 !!!cp (45);
884 ## Stay in the state
885 !!!next-input-character;
886 redo A;
887 } elsif ($self->{nc} == 0x003E) { # >
888 if ($self->{ct}->{type} == START_TAG_TOKEN) {
889 !!!cp (46);
890 $self->{last_stag_name} = $self->{ct}->{tag_name};
891 } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
892 $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
893 if ($self->{ct}->{attributes}) {
894 !!!cp (47);
895 !!!parse-error (type => 'end tag attribute');
896 } else {
897 !!!cp (48);
898 }
899 } else {
900 die "$0: $self->{ct}->{type}: Unknown token type";
901 }
902 $self->{state} = DATA_STATE;
903 $self->{s_kwd} = '';
904 !!!next-input-character;
905
906 !!!emit ($self->{ct}); # start tag or end tag
907
908 redo A;
909 } elsif (0x0041 <= $self->{nc} and
910 $self->{nc} <= 0x005A) { # A..Z
911 !!!cp (49);
912 $self->{ca}
913 = {name => chr ($self->{nc} + ($self->{is_xml} ? 0 : 0x0020)),
914 value => '',
915 line => $self->{line}, column => $self->{column}};
916 $self->{state} = ATTRIBUTE_NAME_STATE;
917 !!!next-input-character;
918 redo A;
919 } elsif ($self->{nc} == 0x002F) { # /
920 !!!cp (50);
921 $self->{state} = SELF_CLOSING_START_TAG_STATE;
922 !!!next-input-character;
923 redo A;
924 } elsif ($self->{nc} == -1) {
925 !!!parse-error (type => 'unclosed tag');
926 if ($self->{ct}->{type} == START_TAG_TOKEN) {
927 !!!cp (52);
928 $self->{last_stag_name} = $self->{ct}->{tag_name};
929 } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
930 $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
931 if ($self->{ct}->{attributes}) {
932 !!!cp (53);
933 !!!parse-error (type => 'end tag attribute');
934 } else {
935 !!!cp (54);
936 }
937 } else {
938 die "$0: $self->{ct}->{type}: Unknown token type";
939 }
940 $self->{state} = DATA_STATE;
941 $self->{s_kwd} = '';
942 # reconsume
943
944 !!!emit ($self->{ct}); # start tag or end tag
945
946 redo A;
947 } else {
948 if ({
949 0x0022 => 1, # "
950 0x0027 => 1, # '
951 0x003D => 1, # =
952 }->{$self->{nc}}) {
953 !!!cp (55);
954 ## XML5: Not a parse error.
955 !!!parse-error (type => 'bad attribute name');
956 } else {
957 !!!cp (56);
958 ## XML5: ":" raises a parse error and is ignored.
959 }
960 $self->{ca}
961 = {name => chr ($self->{nc}),
962 value => '',
963 line => $self->{line}, column => $self->{column}};
964 $self->{state} = ATTRIBUTE_NAME_STATE;
965 !!!next-input-character;
966 redo A;
967 }
968 } elsif ($self->{state} == ATTRIBUTE_NAME_STATE) {
969 ## XML5: "Tag attribute name state".
970
971 my $before_leave = sub {
972 if (exists $self->{ct}->{attributes} # start tag or end tag
973 ->{$self->{ca}->{name}}) { # MUST
974 !!!cp (57);
975 !!!parse-error (type => 'duplicate attribute', text => $self->{ca}->{name}, line => $self->{ca}->{line}, column => $self->{ca}->{column});
976 ## Discard $self->{ca} # MUST
977 } else {
978 !!!cp (58);
979 $self->{ct}->{attributes}->{$self->{ca}->{name}}
980 = $self->{ca};
981 $self->{ca}->{index} = ++$self->{ct}->{last_index};
982 }
983 }; # $before_leave
984
985 if ($is_space->{$self->{nc}}) {
986 !!!cp (59);
987 $before_leave->();
988 $self->{state} = AFTER_ATTRIBUTE_NAME_STATE;
989 !!!next-input-character;
990 redo A;
991 } elsif ($self->{nc} == 0x003D) { # =
992 !!!cp (60);
993 $before_leave->();
994 $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;
995 !!!next-input-character;
996 redo A;
997 } 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->();
1007 if ($self->{ct}->{type} == START_TAG_TOKEN) {
1008 !!!cp (61);
1009 $self->{last_stag_name} = $self->{ct}->{tag_name};
1010 } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1011 !!!cp (62);
1012 $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1013 if ($self->{ct}->{attributes}) {
1014 !!!parse-error (type => 'end tag attribute');
1015 }
1016 } else {
1017 die "$0: $self->{ct}->{type}: Unknown token type";
1018 }
1019 $self->{state} = DATA_STATE;
1020 $self->{s_kwd} = '';
1021 !!!next-input-character;
1022
1023 !!!emit ($self->{ct}); # start tag or end tag
1024
1025 redo A;
1026 } elsif (0x0041 <= $self->{nc} and
1027 $self->{nc} <= 0x005A) { # A..Z
1028 !!!cp (63);
1029 $self->{ca}->{name}
1030 .= chr ($self->{nc} + ($self->{is_xml} ? 0 : 0x0020));
1031 ## Stay in the state
1032 !!!next-input-character;
1033 redo A;
1034 } elsif ($self->{nc} == 0x002F) { # /
1035 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->();
1044 $self->{state} = SELF_CLOSING_START_TAG_STATE;
1045 !!!next-input-character;
1046 redo A;
1047 } elsif ($self->{nc} == -1) {
1048 !!!parse-error (type => 'unclosed tag');
1049 $before_leave->();
1050 if ($self->{ct}->{type} == START_TAG_TOKEN) {
1051 !!!cp (66);
1052 $self->{last_stag_name} = $self->{ct}->{tag_name};
1053 } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1054 $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1055 if ($self->{ct}->{attributes}) {
1056 !!!cp (67);
1057 !!!parse-error (type => 'end tag attribute');
1058 } else {
1059 ## NOTE: This state should never be reached.
1060 !!!cp (68);
1061 }
1062 } else {
1063 die "$0: $self->{ct}->{type}: Unknown token type";
1064 }
1065 $self->{state} = DATA_STATE;
1066 $self->{s_kwd} = '';
1067 # reconsume
1068
1069 !!!emit ($self->{ct}); # start tag or end tag
1070
1071 redo A;
1072 } else {
1073 if ($self->{nc} == 0x0022 or # "
1074 $self->{nc} == 0x0027) { # '
1075 !!!cp (69);
1076 ## XML5: Not a parse error.
1077 !!!parse-error (type => 'bad attribute name');
1078 } else {
1079 !!!cp (70);
1080 }
1081 $self->{ca}->{name} .= chr ($self->{nc});
1082 ## Stay in the state
1083 !!!next-input-character;
1084 redo A;
1085 }
1086 } elsif ($self->{state} == AFTER_ATTRIBUTE_NAME_STATE) {
1087 ## XML5: "Tag attribute name after state".
1088
1089 if ($is_space->{$self->{nc}}) {
1090 !!!cp (71);
1091 ## Stay in the state
1092 !!!next-input-character;
1093 redo A;
1094 } elsif ($self->{nc} == 0x003D) { # =
1095 !!!cp (72);
1096 $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE;
1097 !!!next-input-character;
1098 redo A;
1099 } 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) {
1109 !!!cp (73);
1110 $self->{last_stag_name} = $self->{ct}->{tag_name};
1111 } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1112 $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1113 if ($self->{ct}->{attributes}) {
1114 !!!cp (74);
1115 !!!parse-error (type => 'end tag attribute');
1116 } else {
1117 ## NOTE: This state should never be reached.
1118 !!!cp (75);
1119 }
1120 } else {
1121 die "$0: $self->{ct}->{type}: Unknown token type";
1122 }
1123 $self->{state} = DATA_STATE;
1124 $self->{s_kwd} = '';
1125 !!!next-input-character;
1126
1127 !!!emit ($self->{ct}); # start tag or end tag
1128
1129 redo A;
1130 } elsif (0x0041 <= $self->{nc} and
1131 $self->{nc} <= 0x005A) { # A..Z
1132 !!!cp (76);
1133 $self->{ca}
1134 = {name => chr ($self->{nc} + ($self->{is_xml} ? 0 : 0x0020)),
1135 value => '',
1136 line => $self->{line}, column => $self->{column}};
1137 $self->{state} = ATTRIBUTE_NAME_STATE;
1138 !!!next-input-character;
1139 redo A;
1140 } elsif ($self->{nc} == 0x002F) { # /
1141 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;
1150 !!!next-input-character;
1151 redo A;
1152 } elsif ($self->{nc} == -1) {
1153 !!!parse-error (type => 'unclosed tag');
1154 if ($self->{ct}->{type} == START_TAG_TOKEN) {
1155 !!!cp (79);
1156 $self->{last_stag_name} = $self->{ct}->{tag_name};
1157 } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1158 $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1159 if ($self->{ct}->{attributes}) {
1160 !!!cp (80);
1161 !!!parse-error (type => 'end tag attribute');
1162 } else {
1163 ## NOTE: This state should never be reached.
1164 !!!cp (81);
1165 }
1166 } else {
1167 die "$0: $self->{ct}->{type}: Unknown token type";
1168 }
1169 $self->{s_kwd} = '';
1170 $self->{state} = DATA_STATE;
1171 # reconsume
1172
1173 !!!emit ($self->{ct}); # start tag or end tag
1174
1175 redo A;
1176 } 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 # "
1186 $self->{nc} == 0x0027) { # '
1187 !!!cp (78);
1188 ## XML5: Not a parse error.
1189 !!!parse-error (type => 'bad attribute name');
1190 } else {
1191 !!!cp (82);
1192 }
1193 $self->{ca}
1194 = {name => chr ($self->{nc}),
1195 value => '',
1196 line => $self->{line}, column => $self->{column}};
1197 $self->{state} = ATTRIBUTE_NAME_STATE;
1198 !!!next-input-character;
1199 redo A;
1200 }
1201 } elsif ($self->{state} == BEFORE_ATTRIBUTE_VALUE_STATE) {
1202 ## XML5: "Tag attribute value before state".
1203
1204 if ($is_space->{$self->{nc}}) {
1205 !!!cp (83);
1206 ## Stay in the state
1207 !!!next-input-character;
1208 redo A;
1209 } elsif ($self->{nc} == 0x0022) { # "
1210 !!!cp (84);
1211 $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
1212 !!!next-input-character;
1213 redo A;
1214 } elsif ($self->{nc} == 0x0026) { # &
1215 !!!cp (85);
1216 $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
1217 ## reconsume
1218 redo A;
1219 } elsif ($self->{nc} == 0x0027) { # '
1220 !!!cp (86);
1221 $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
1222 !!!next-input-character;
1223 redo A;
1224 } elsif ($self->{nc} == 0x003E) { # >
1225 !!!parse-error (type => 'empty unquoted attribute value');
1226 if ($self->{ct}->{type} == START_TAG_TOKEN) {
1227 !!!cp (87);
1228 $self->{last_stag_name} = $self->{ct}->{tag_name};
1229 } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1230 $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1231 if ($self->{ct}->{attributes}) {
1232 !!!cp (88);
1233 !!!parse-error (type => 'end tag attribute');
1234 } else {
1235 ## NOTE: This state should never be reached.
1236 !!!cp (89);
1237 }
1238 } else {
1239 die "$0: $self->{ct}->{type}: Unknown token type";
1240 }
1241 $self->{state} = DATA_STATE;
1242 $self->{s_kwd} = '';
1243 !!!next-input-character;
1244
1245 !!!emit ($self->{ct}); # start tag or end tag
1246
1247 redo A;
1248 } elsif ($self->{nc} == -1) {
1249 !!!parse-error (type => 'unclosed tag');
1250 if ($self->{ct}->{type} == START_TAG_TOKEN) {
1251 !!!cp (90);
1252 $self->{last_stag_name} = $self->{ct}->{tag_name};
1253 } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1254 $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1255 if ($self->{ct}->{attributes}) {
1256 !!!cp (91);
1257 !!!parse-error (type => 'end tag attribute');
1258 } else {
1259 ## NOTE: This state should never be reached.
1260 !!!cp (92);
1261 }
1262 } else {
1263 die "$0: $self->{ct}->{type}: Unknown token type";
1264 }
1265 $self->{state} = DATA_STATE;
1266 $self->{s_kwd} = '';
1267 ## reconsume
1268
1269 !!!emit ($self->{ct}); # start tag or end tag
1270
1271 redo A;
1272 } else {
1273 if ($self->{nc} == 0x003D) { # =
1274 !!!cp (93);
1275 ## XML5: Not a parse error.
1276 !!!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 {
1282 !!!cp (94);
1283 }
1284 $self->{ca}->{value} .= chr ($self->{nc});
1285 $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
1286 !!!next-input-character;
1287 redo A;
1288 }
1289 } 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) { # "
1294 if ($self->{ct}->{type} == ATTLIST_TOKEN) {
1295 !!!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;
1305 redo A;
1306 } elsif ($self->{nc} == 0x0026) { # &
1307 !!!cp (96);
1308 ## XML5: Not defined yet.
1309
1310 ## NOTE: In the spec, the tokenizer is switched to the
1311 ## "entity in attribute value state". In this implementation, the
1312 ## tokenizer is switched to the |ENTITY_STATE|, which is an
1313 ## implementation of the "consume a character reference" algorithm.
1314 $self->{prev_state} = $self->{state};
1315 $self->{entity_add} = 0x0022; # "
1316 $self->{state} = ENTITY_STATE;
1317 !!!next-input-character;
1318 redo A;
1319 } elsif ($self->{nc} == -1) {
1320 !!!parse-error (type => 'unclosed attribute value');
1321 if ($self->{ct}->{type} == START_TAG_TOKEN) {
1322 !!!cp (97);
1323 $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) {
1331 $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1332 if ($self->{ct}->{attributes}) {
1333 !!!cp (98);
1334 !!!parse-error (type => 'end tag attribute');
1335 } else {
1336 ## NOTE: This state should never be reached.
1337 !!!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 {
1353 die "$0: $self->{ct}->{type}: Unknown token type";
1354 }
1355 } else {
1356 ## 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});
1365 $self->{read_until}->($self->{ca}->{value},
1366 q["&<],
1367 length $self->{ca}->{value});
1368
1369 ## Stay in the state
1370 !!!next-input-character;
1371 redo A;
1372 }
1373 } 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) { # '
1378 if ($self->{ct}->{type} == ATTLIST_TOKEN) {
1379 !!!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;
1389 redo A;
1390 } elsif ($self->{nc} == 0x0026) { # &
1391 !!!cp (102);
1392 ## XML5: Not defined yet.
1393
1394 ## NOTE: In the spec, the tokenizer is switched to the
1395 ## "entity in attribute value state". In this implementation, the
1396 ## tokenizer is switched to the |ENTITY_STATE|, which is an
1397 ## implementation of the "consume a character reference" algorithm.
1398 $self->{entity_add} = 0x0027; # '
1399 $self->{prev_state} = $self->{state};
1400 $self->{state} = ENTITY_STATE;
1401 !!!next-input-character;
1402 redo A;
1403 } elsif ($self->{nc} == -1) {
1404 !!!parse-error (type => 'unclosed attribute value');
1405 if ($self->{ct}->{type} == START_TAG_TOKEN) {
1406 !!!cp (103);
1407 $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) {
1415 $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1416 if ($self->{ct}->{attributes}) {
1417 !!!cp (104);
1418 !!!parse-error (type => 'end tag attribute');
1419 } else {
1420 ## NOTE: This state should never be reached.
1421 !!!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 {
1437 die "$0: $self->{ct}->{type}: Unknown token type";
1438 }
1439 } else {
1440 ## 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});
1449 $self->{read_until}->($self->{ca}->{value},
1450 q['&<],
1451 length $self->{ca}->{value});
1452
1453 ## Stay in the state
1454 !!!next-input-character;
1455 redo A;
1456 }
1457 } elsif ($self->{state} == ATTRIBUTE_VALUE_UNQUOTED_STATE) {
1458 ## XML5: "Tag attribute value unquoted state".
1459
1460 if ($is_space->{$self->{nc}}) {
1461 if ($self->{ct}->{type} == ATTLIST_TOKEN) {
1462 !!!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;
1471 redo A;
1472 } elsif ($self->{nc} == 0x0026) { # &
1473 !!!cp (108);
1474
1475 ## XML5: Not defined yet.
1476
1477 ## NOTE: In the spec, the tokenizer is switched to the
1478 ## "entity in attribute value state". In this implementation, the
1479 ## tokenizer is switched to the |ENTITY_STATE|, which is an
1480 ## implementation of the "consume a character reference" algorithm.
1481 $self->{entity_add} = -1;
1482 $self->{prev_state} = $self->{state};
1483 $self->{state} = ENTITY_STATE;
1484 !!!next-input-character;
1485 redo A;
1486 } elsif ($self->{nc} == 0x003E) { # >
1487 if ($self->{ct}->{type} == START_TAG_TOKEN) {
1488 !!!cp (109);
1489 $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) {
1497 $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1498 if ($self->{ct}->{attributes}) {
1499 !!!cp (110);
1500 !!!parse-error (type => 'end tag attribute');
1501 } else {
1502 ## NOTE: This state should never be reached.
1503 !!!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 {
1518 die "$0: $self->{ct}->{type}: Unknown token type";
1519 }
1520 } elsif ($self->{nc} == -1) {
1521 if ($self->{ct}->{type} == START_TAG_TOKEN) {
1522 !!!cp (112);
1523 !!!parse-error (type => 'unclosed tag');
1524 $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) {
1532 !!!parse-error (type => 'unclosed tag');
1533 $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1534 if ($self->{ct}->{attributes}) {
1535 !!!cp (113);
1536 !!!parse-error (type => 'end tag attribute');
1537 } else {
1538 ## NOTE: This state should never be reached.
1539 !!!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 {
1555 die "$0: $self->{ct}->{type}: Unknown token type";
1556 }
1557 } else {
1558 if ({
1559 0x0022 => 1, # "
1560 0x0027 => 1, # '
1561 0x003D => 1, # =
1562 }->{$self->{nc}}) {
1563 !!!cp (115);
1564 ## XML5: Not a parse error.
1565 !!!parse-error (type => 'bad attribute value');
1566 } else {
1567 !!!cp (116);
1568 }
1569 $self->{ca}->{value} .= chr ($self->{nc});
1570 $self->{read_until}->($self->{ca}->{value},
1571 q["'=& >],
1572 length $self->{ca}->{value});
1573
1574 ## Stay in the state
1575 !!!next-input-character;
1576 redo A;
1577 }
1578 } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) {
1579 if ($is_space->{$self->{nc}}) {
1580 !!!cp (118);
1581 $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1582 !!!next-input-character;
1583 redo A;
1584 } elsif ($self->{nc} == 0x003E) { # >
1585 if ($self->{ct}->{type} == START_TAG_TOKEN) {
1586 !!!cp (119);
1587 $self->{last_stag_name} = $self->{ct}->{tag_name};
1588 } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1589 $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1590 if ($self->{ct}->{attributes}) {
1591 !!!cp (120);
1592 !!!parse-error (type => 'end tag attribute');
1593 } else {
1594 ## NOTE: This state should never be reached.
1595 !!!cp (121);
1596 }
1597 } else {
1598 die "$0: $self->{ct}->{type}: Unknown token type";
1599 }
1600 $self->{state} = DATA_STATE;
1601 $self->{s_kwd} = '';
1602 !!!next-input-character;
1603
1604 !!!emit ($self->{ct}); # start tag or end tag
1605
1606 redo A;
1607 } elsif ($self->{nc} == 0x002F) { # /
1608 !!!cp (122);
1609 $self->{state} = SELF_CLOSING_START_TAG_STATE;
1610 !!!next-input-character;
1611 redo A;
1612 } elsif ($self->{nc} == -1) {
1613 !!!parse-error (type => 'unclosed tag');
1614 if ($self->{ct}->{type} == START_TAG_TOKEN) {
1615 !!!cp (122.3);
1616 $self->{last_stag_name} = $self->{ct}->{tag_name};
1617 } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1618 if ($self->{ct}->{attributes}) {
1619 !!!cp (122.1);
1620 !!!parse-error (type => 'end tag attribute');
1621 } else {
1622 ## NOTE: This state should never be reached.
1623 !!!cp (122.2);
1624 }
1625 } else {
1626 die "$0: $self->{ct}->{type}: Unknown token type";
1627 }
1628 $self->{state} = DATA_STATE;
1629 $self->{s_kwd} = '';
1630 ## Reconsume.
1631 !!!emit ($self->{ct}); # start tag or end tag
1632 redo A;
1633 } else {
1634 !!!cp ('124.1');
1635 !!!parse-error (type => 'no space between attributes');
1636 $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1637 ## reconsume
1638 redo A;
1639 }
1640 } elsif ($self->{state} == SELF_CLOSING_START_TAG_STATE) {
1641 ## XML5: "Empty tag state".
1642
1643 if ($self->{nc} == 0x003E) { # >
1644 if ($self->{ct}->{type} == END_TAG_TOKEN) {
1645 !!!cp ('124.2');
1646 !!!parse-error (type => 'nestc', token => $self->{ct});
1647 ## TODO: Different type than slash in start tag
1648 $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1649 if ($self->{ct}->{attributes}) {
1650 !!!cp ('124.4');
1651 !!!parse-error (type => 'end tag attribute');
1652 } else {
1653 !!!cp ('124.5');
1654 }
1655 ## TODO: Test |<title></title/>|
1656 } else {
1657 !!!cp ('124.3');
1658 $self->{self_closing} = 1;
1659 }
1660
1661 $self->{state} = DATA_STATE;
1662 $self->{s_kwd} = '';
1663 !!!next-input-character;
1664
1665 !!!emit ($self->{ct}); # start tag or end tag
1666
1667 redo A;
1668 } elsif ($self->{nc} == -1) {
1669 !!!parse-error (type => 'unclosed tag');
1670 if ($self->{ct}->{type} == START_TAG_TOKEN) {
1671 !!!cp (124.7);
1672 $self->{last_stag_name} = $self->{ct}->{tag_name};
1673 } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1674 if ($self->{ct}->{attributes}) {
1675 !!!cp (124.5);
1676 !!!parse-error (type => 'end tag attribute');
1677 } else {
1678 ## NOTE: This state should never be reached.
1679 !!!cp (124.6);
1680 }
1681 } else {
1682 die "$0: $self->{ct}->{type}: Unknown token type";
1683 }
1684 ## XML5: "Tag attribute name before state".
1685 $self->{state} = DATA_STATE;
1686 $self->{s_kwd} = '';
1687 ## Reconsume.
1688 !!!emit ($self->{ct}); # start tag or end tag
1689 redo A;
1690 } else {
1691 !!!cp ('124.4');
1692 !!!parse-error (type => 'nestc');
1693 ## TODO: This error type is wrong.
1694 $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1695 ## Reconsume.
1696 redo A;
1697 }
1698 } elsif ($self->{state} == BOGUS_COMMENT_STATE) {
1699 ## XML5: "Bogus comment state" and "DOCTYPE bogus comment state".
1700
1701 ## NOTE: Unlike spec's "bogus comment state", this implementation
1702 ## consumes characters one-by-one basis.
1703
1704 if ($self->{nc} == 0x003E) { # >
1705 if ($self->{in_subset}) {
1706 !!!cp (123);
1707 $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;
1714
1715 !!!emit ($self->{ct}); # comment
1716 redo A;
1717 } elsif ($self->{nc} == -1) {
1718 if ($self->{in_subset}) {
1719 !!!cp (125.1);
1720 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1721 } else {
1722 !!!cp (125);
1723 $self->{state} = DATA_STATE;
1724 $self->{s_kwd} = '';
1725 }
1726 ## reconsume
1727
1728 !!!emit ($self->{ct}); # comment
1729 redo A;
1730 } else {
1731 !!!cp (126);
1732 $self->{ct}->{data} .= chr ($self->{nc}); # comment
1733 $self->{read_until}->($self->{ct}->{data},
1734 q[>],
1735 length $self->{ct}->{data});
1736
1737 ## Stay in the state.
1738 !!!next-input-character;
1739 redo A;
1740 }
1741 } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {
1742 ## XML5: "Markup declaration state".
1743
1744 if ($self->{nc} == 0x002D) { # -
1745 !!!cp (133);
1746 $self->{state} = MD_HYPHEN_STATE;
1747 !!!next-input-character;
1748 redo A;
1749 } elsif ($self->{nc} == 0x0044 or # D
1750 $self->{nc} == 0x0064) { # d
1751 ## ASCII case-insensitive.
1752 !!!cp (130);
1753 $self->{state} = MD_DOCTYPE_STATE;
1754 $self->{kwd} = chr $self->{nc};
1755 !!!next-input-character;
1756 redo A;
1757 } elsif ((($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and
1758 $self->{open_elements}->[-1]->[1] & FOREIGN_EL) or
1759 $self->{is_xml}) and
1760 $self->{nc} == 0x005B) { # [
1761 !!!cp (135.4);
1762 $self->{state} = MD_CDATA_STATE;
1763 $self->{kwd} = '[';
1764 !!!next-input-character;
1765 redo A;
1766 } else {
1767 !!!cp (136);
1768 }
1769
1770 !!!parse-error (type => 'bogus comment',
1771 line => $self->{line_prev},
1772 column => $self->{column_prev} - 1);
1773 ## Reconsume.
1774 $self->{state} = BOGUS_COMMENT_STATE;
1775 $self->{ct} = {type => COMMENT_TOKEN, data => '',
1776 line => $self->{line_prev},
1777 column => $self->{column_prev} - 1,
1778 };
1779 redo A;
1780 } elsif ($self->{state} == MD_HYPHEN_STATE) {
1781 if ($self->{nc} == 0x002D) { # -
1782 !!!cp (127);
1783 $self->{ct} = {type => COMMENT_TOKEN, data => '',
1784 line => $self->{line_prev},
1785 column => $self->{column_prev} - 2,
1786 };
1787 $self->{state} = COMMENT_START_STATE; ## XML5: "comment state".
1788 !!!next-input-character;
1789 redo A;
1790 } else {
1791 !!!cp (128);
1792 !!!parse-error (type => 'bogus comment',
1793 line => $self->{line_prev},
1794 column => $self->{column_prev} - 2);
1795 $self->{state} = BOGUS_COMMENT_STATE;
1796 ## Reconsume.
1797 $self->{ct} = {type => COMMENT_TOKEN,
1798 data => '-',
1799 line => $self->{line_prev},
1800 column => $self->{column_prev} - 2,
1801 };
1802 redo A;
1803 }
1804 } elsif ($self->{state} == MD_DOCTYPE_STATE) {
1805 ## ASCII case-insensitive.
1806 if ($self->{nc} == [
1807 undef,
1808 0x004F, # O
1809 0x0043, # C
1810 0x0054, # T
1811 0x0059, # Y
1812 0x0050, # P
1813 ]->[length $self->{kwd}] or
1814 $self->{nc} == [
1815 undef,
1816 0x006F, # o
1817 0x0063, # c
1818 0x0074, # t
1819 0x0079, # y
1820 0x0070, # p
1821 ]->[length $self->{kwd}]) {
1822 !!!cp (131);
1823 ## Stay in the state.
1824 $self->{kwd} .= chr $self->{nc};
1825 !!!next-input-character;
1826 redo A;
1827 } elsif ((length $self->{kwd}) == 6 and
1828 ($self->{nc} == 0x0045 or # E
1829 $self->{nc} == 0x0065)) { # e
1830 if ($self->{is_xml} and
1831 ($self->{kwd} ne 'DOCTYP' or $self->{nc} == 0x0065)) {
1832 !!!cp (129);
1833 ## XML5: case-sensitive.
1834 !!!parse-error (type => 'lowercase keyword', ## TODO
1835 text => 'DOCTYPE',
1836 line => $self->{line_prev},
1837 column => $self->{column_prev} - 5);
1838 } else {
1839 !!!cp (129.1);
1840 }
1841 $self->{state} = DOCTYPE_STATE;
1842 $self->{ct} = {type => DOCTYPE_TOKEN,
1843 quirks => 1,
1844 line => $self->{line_prev},
1845 column => $self->{column_prev} - 7,
1846 };
1847 !!!next-input-character;
1848 redo A;
1849 } else {
1850 !!!cp (132);
1851 !!!parse-error (type => 'bogus comment',
1852 line => $self->{line_prev},
1853 column => $self->{column_prev} - 1 - length $self->{kwd});
1854 $self->{state} = BOGUS_COMMENT_STATE;
1855 ## Reconsume.
1856 $self->{ct} = {type => COMMENT_TOKEN,
1857 data => $self->{kwd},
1858 line => $self->{line_prev},
1859 column => $self->{column_prev} - 1 - length $self->{kwd},
1860 };
1861 redo A;
1862 }
1863 } elsif ($self->{state} == MD_CDATA_STATE) {
1864 if ($self->{nc} == {
1865 '[' => 0x0043, # C
1866 '[C' => 0x0044, # D
1867 '[CD' => 0x0041, # A
1868 '[CDA' => 0x0054, # T
1869 '[CDAT' => 0x0041, # A
1870 }->{$self->{kwd}}) {
1871 !!!cp (135.1);
1872 ## Stay in the state.
1873 $self->{kwd} .= chr $self->{nc};
1874 !!!next-input-character;
1875 redo A;
1876 } elsif ($self->{kwd} eq '[CDATA' and
1877 $self->{nc} == 0x005B) { # [
1878 if ($self->{is_xml} and
1879 not $self->{tainted} and
1880 @{$self->{open_elements} or []} == 0) {
1881 !!!cp (135.2);
1882 !!!parse-error (type => 'cdata outside of root element',
1883 line => $self->{line_prev},
1884 column => $self->{column_prev} - 7);
1885 $self->{tainted} = 1;
1886 } else {
1887 !!!cp (135.21);
1888 }
1889
1890 $self->{ct} = {type => CHARACTER_TOKEN,
1891 data => '',
1892 line => $self->{line_prev},
1893 column => $self->{column_prev} - 7};
1894 $self->{state} = CDATA_SECTION_STATE;
1895 !!!next-input-character;
1896 redo A;
1897 } else {
1898 !!!cp (135.3);
1899 !!!parse-error (type => 'bogus comment',
1900 line => $self->{line_prev},
1901 column => $self->{column_prev} - 1 - length $self->{kwd});
1902 $self->{state} = BOGUS_COMMENT_STATE;
1903 ## Reconsume.
1904 $self->{ct} = {type => COMMENT_TOKEN,
1905 data => $self->{kwd},
1906 line => $self->{line_prev},
1907 column => $self->{column_prev} - 1 - length $self->{kwd},
1908 };
1909 redo A;
1910 }
1911 } elsif ($self->{state} == COMMENT_START_STATE) {
1912 if ($self->{nc} == 0x002D) { # -
1913 !!!cp (137);
1914 $self->{state} = COMMENT_START_DASH_STATE;
1915 !!!next-input-character;
1916 redo A;
1917 } elsif ($self->{nc} == 0x003E) { # >
1918 !!!parse-error (type => 'bogus comment');
1919 if ($self->{in_subset}) {
1920 !!!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;
1928
1929 !!!emit ($self->{ct}); # comment
1930
1931 redo A;
1932 } elsif ($self->{nc} == -1) {
1933 !!!parse-error (type => 'unclosed comment');
1934 if ($self->{in_subset}) {
1935 !!!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
1943
1944 !!!emit ($self->{ct}); # comment
1945
1946 redo A;
1947 } else {
1948 !!!cp (140);
1949 $self->{ct}->{data} # comment
1950 .= chr ($self->{nc});
1951 $self->{state} = COMMENT_STATE;
1952 !!!next-input-character;
1953 redo A;
1954 }
1955 } elsif ($self->{state} == COMMENT_START_DASH_STATE) {
1956 if ($self->{nc} == 0x002D) { # -
1957 !!!cp (141);
1958 $self->{state} = COMMENT_END_STATE;
1959 !!!next-input-character;
1960 redo A;
1961 } elsif ($self->{nc} == 0x003E) { # >
1962 !!!parse-error (type => 'bogus comment');
1963 if ($self->{in_subset}) {
1964 !!!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;
1972
1973 !!!emit ($self->{ct}); # comment
1974
1975 redo A;
1976 } elsif ($self->{nc} == -1) {
1977 !!!parse-error (type => 'unclosed comment');
1978 if ($self->{in_subset}) {
1979 !!!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
1987
1988 !!!emit ($self->{ct}); # comment
1989
1990 redo A;
1991 } else {
1992 !!!cp (144);
1993 $self->{ct}->{data} # comment
1994 .= '-' . chr ($self->{nc});
1995 $self->{state} = COMMENT_STATE;
1996 !!!next-input-character;
1997 redo A;
1998 }
1999 } elsif ($self->{state} == COMMENT_STATE) {
2000 ## XML5: "Comment state" and "DOCTYPE comment state".
2001
2002 if ($self->{nc} == 0x002D) { # -
2003 !!!cp (145);
2004 $self->{state} = COMMENT_END_DASH_STATE;
2005 !!!next-input-character;
2006 redo A;
2007 } elsif ($self->{nc} == -1) {
2008 !!!parse-error (type => 'unclosed comment');
2009 if ($self->{in_subset}) {
2010 !!!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
2018
2019 !!!emit ($self->{ct}); # comment
2020
2021 redo A;
2022 } else {
2023 !!!cp (147);
2024 $self->{ct}->{data} .= chr ($self->{nc}); # comment
2025 $self->{read_until}->($self->{ct}->{data},
2026 q[-],
2027 length $self->{ct}->{data});
2028
2029 ## Stay in the state
2030 !!!next-input-character;
2031 redo A;
2032 }
2033 } elsif ($self->{state} == COMMENT_END_DASH_STATE) {
2034 ## XML5: "Comment dash state" and "DOCTYPE comment dash state".
2035
2036 if ($self->{nc} == 0x002D) { # -
2037 !!!cp (148);
2038 $self->{state} = COMMENT_END_STATE;
2039 !!!next-input-character;
2040 redo A;
2041 } elsif ($self->{nc} == -1) {
2042 !!!parse-error (type => 'unclosed comment');
2043 if ($self->{in_subset}) {
2044 !!!cp (149.1);
2045 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2046 } else {
2047 !!!cp (149);
2048 $self->{state} = DATA_STATE;
2049 $self->{s_kwd} = '';
2050 }
2051 ## reconsume
2052
2053 !!!emit ($self->{ct}); # comment
2054
2055 redo A;
2056 } else {
2057 !!!cp (150);
2058 $self->{ct}->{data} .= '-' . chr ($self->{nc}); # comment
2059 $self->{state} = COMMENT_STATE;
2060 !!!next-input-character;
2061 redo A;
2062 }
2063 } elsif ($self->{state} == COMMENT_END_STATE) {
2064 ## XML5: "Comment end state" and "DOCTYPE comment end state".
2065
2066 if ($self->{nc} == 0x003E) { # >
2067 if ($self->{in_subset}) {
2068 !!!cp (151.1);
2069 $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;
2076
2077 !!!emit ($self->{ct}); # comment
2078
2079 redo A;
2080 } elsif ($self->{nc} == 0x002D) { # -
2081 !!!cp (152);
2082 ## XML5: Not a parse error.
2083 !!!parse-error (type => 'dash in comment',
2084 line => $self->{line_prev},
2085 column => $self->{column_prev});
2086 $self->{ct}->{data} .= '-'; # comment
2087 ## Stay in the state
2088 !!!next-input-character;
2089 redo A;
2090 } elsif ($self->{nc} == -1) {
2091 !!!parse-error (type => 'unclosed comment');
2092 if ($self->{in_subset}) {
2093 !!!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
2101
2102 !!!emit ($self->{ct}); # comment
2103
2104 redo A;
2105 } else {
2106 !!!cp (154);
2107 ## XML5: Not a parse error.
2108 !!!parse-error (type => 'dash in comment',
2109 line => $self->{line_prev},
2110 column => $self->{column_prev});
2111 $self->{ct}->{data} .= '--' . chr ($self->{nc}); # comment
2112 $self->{state} = COMMENT_STATE;
2113 !!!next-input-character;
2114 redo A;
2115 }
2116 } elsif ($self->{state} == DOCTYPE_STATE) {
2117 if ($is_space->{$self->{nc}}) {
2118 !!!cp (155);
2119 $self->{state} = BEFORE_DOCTYPE_NAME_STATE;
2120 !!!next-input-character;
2121 redo A;
2122 } else {
2123 !!!cp (156);
2124 ## XML5: Unless EOF, swith to the bogus comment state.
2125 !!!parse-error (type => 'no space before DOCTYPE name');
2126 $self->{state} = BEFORE_DOCTYPE_NAME_STATE;
2127 ## reconsume
2128 redo A;
2129 }
2130 } elsif ($self->{state} == BEFORE_DOCTYPE_NAME_STATE) {
2131 ## XML5: "DOCTYPE root name before state".
2132
2133 if ($is_space->{$self->{nc}}) {
2134 !!!cp (157);
2135 ## Stay in the state
2136 !!!next-input-character;
2137 redo A;
2138 } elsif ($self->{nc} == 0x003E) { # >
2139 !!!cp (158);
2140 ## XML5: No parse error.
2141 !!!parse-error (type => 'no DOCTYPE name');
2142 $self->{state} = DATA_STATE;
2143 $self->{s_kwd} = '';
2144 !!!next-input-character;
2145
2146 !!!emit ($self->{ct}); # DOCTYPE (quirks)
2147
2148 redo A;
2149 } elsif ($self->{nc} == -1) {
2150 !!!cp (159);
2151 !!!parse-error (type => 'no DOCTYPE name');
2152 $self->{state} = DATA_STATE;
2153 $self->{s_kwd} = '';
2154 ## reconsume
2155
2156 !!!emit ($self->{ct}); # DOCTYPE (quirks)
2157
2158 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 {
2169 !!!cp (160);
2170 $self->{ct}->{name} = chr $self->{nc};
2171 delete $self->{ct}->{quirks};
2172 $self->{state} = DOCTYPE_NAME_STATE;
2173 !!!next-input-character;
2174 redo A;
2175 }
2176 } elsif ($self->{state} == DOCTYPE_NAME_STATE) {
2177 ## XML5: "DOCTYPE root name state".
2178
2179 ## ISSUE: Redundant "First," in the spec.
2180
2181 if ($is_space->{$self->{nc}}) {
2182 !!!cp (161);
2183 $self->{state} = AFTER_DOCTYPE_NAME_STATE;
2184 !!!next-input-character;
2185 redo A;
2186 } elsif ($self->{nc} == 0x003E) { # >
2187 !!!cp (162);
2188 $self->{state} = DATA_STATE;
2189 $self->{s_kwd} = '';
2190 !!!next-input-character;
2191
2192 !!!emit ($self->{ct}); # DOCTYPE
2193
2194 redo A;
2195 } elsif ($self->{nc} == -1) {
2196 !!!cp (163);
2197 !!!parse-error (type => 'unclosed DOCTYPE');
2198 $self->{state} = DATA_STATE;
2199 $self->{s_kwd} = '';
2200 ## reconsume
2201
2202 $self->{ct}->{quirks} = 1;
2203 !!!emit ($self->{ct}); # DOCTYPE
2204
2205 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 {
2215 !!!cp (164);
2216 $self->{ct}->{name}
2217 .= chr ($self->{nc}); # DOCTYPE
2218 ## Stay in the state
2219 !!!next-input-character;
2220 redo A;
2221 }
2222 } 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}}) {
2227 !!!cp (165);
2228 ## Stay in the state
2229 !!!next-input-character;
2230 redo A;
2231 } elsif ($self->{nc} == 0x003E) { # >
2232 if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2233 !!!cp (166);
2234 $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;
2243 !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2244 redo A;
2245 } elsif ($self->{nc} == -1) {
2246 if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2247 !!!cp (167);
2248 !!!parse-error (type => 'unclosed DOCTYPE');
2249 $self->{state} = DATA_STATE;
2250 $self->{s_kwd} = '';
2251 $self->{ct}->{quirks} = 1;
2252 } else {
2253 !!!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;
2261 } elsif ($self->{nc} == 0x0050 or # P
2262 $self->{nc} == 0x0070) { # p
2263 !!!cp (167.1);
2264 $self->{state} = PUBLIC_STATE;
2265 $self->{kwd} = chr $self->{nc};
2266 !!!next-input-character;
2267 redo A;
2268 } elsif ($self->{nc} == 0x0053 or # S
2269 $self->{nc} == 0x0073) { # s
2270 !!!cp (167.2);
2271 $self->{state} = SYSTEM_STATE;
2272 $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;
2282 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 {
2302 !!!parse-error (type => 'string after DOCTYPE name'); ## TODO: type
2303
2304 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
2313 !!!next-input-character;
2314 redo A;
2315 }
2316 } elsif ($self->{state} == PUBLIC_STATE) {
2317 ## ASCII case-insensitive
2318 if ($self->{nc} == [
2319 undef,
2320 0x0055, # U
2321 0x0042, # B
2322 0x004C, # L
2323 0x0049, # I
2324 ]->[length $self->{kwd}] or
2325 $self->{nc} == [
2326 undef,
2327 0x0075, # u
2328 0x0062, # b
2329 0x006C, # l
2330 0x0069, # i
2331 ]->[length $self->{kwd}]) {
2332 !!!cp (175);
2333 ## Stay in the state.
2334 $self->{kwd} .= chr $self->{nc};
2335 !!!next-input-character;
2336 redo A;
2337 } elsif ((length $self->{kwd}) == 5 and
2338 ($self->{nc} == 0x0043 or # C
2339 $self->{nc} == 0x0063)) { # c
2340 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;
2351 !!!next-input-character;
2352 redo A;
2353 } else {
2354 !!!parse-error (type => 'string after DOCTYPE name', ## TODO: type
2355 line => $self->{line_prev},
2356 column => $self->{column_prev} + 1 - length $self->{kwd});
2357 if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2358 !!!cp (169);
2359 $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.
2366 redo A;
2367 }
2368 } elsif ($self->{state} == SYSTEM_STATE) {
2369 ## ASCII case-insensitive
2370 if ($self->{nc} == [
2371 undef,
2372 0x0059, # Y
2373 0x0053, # S
2374 0x0054, # T
2375 0x0045, # E
2376 ]->[length $self->{kwd}] or
2377 $self->{nc} == [
2378 undef,
2379 0x0079, # y
2380 0x0073, # s
2381 0x0074, # t
2382 0x0065, # e
2383 ]->[length $self->{kwd}]) {
2384 !!!cp (170);
2385 ## Stay in the state.
2386 $self->{kwd} .= chr $self->{nc};
2387 !!!next-input-character;
2388 redo A;
2389 } elsif ((length $self->{kwd}) == 5 and
2390 ($self->{nc} == 0x004D or # M
2391 $self->{nc} == 0x006D)) { # m
2392 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;
2403 !!!next-input-character;
2404 redo A;
2405 } else {
2406 !!!parse-error (type => 'string after DOCTYPE name', ## TODO: type
2407 line => $self->{line_prev},
2408 column => $self->{column_prev} + 1 - length $self->{kwd});
2409 if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2410 !!!cp (172);
2411 $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.
2418 redo A;
2419 }
2420 } elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {
2421 if ($is_space->{$self->{nc}}) {
2422 !!!cp (181);
2423 ## Stay in the state
2424 !!!next-input-character;
2425 redo A;
2426 } elsif ($self->{nc} eq 0x0022) { # "
2427 !!!cp (182);
2428 $self->{ct}->{pubid} = ''; # DOCTYPE
2429 $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE;
2430 !!!next-input-character;
2431 redo A;
2432 } elsif ($self->{nc} eq 0x0027) { # '
2433 !!!cp (183);
2434 $self->{ct}->{pubid} = ''; # DOCTYPE
2435 $self->{state} = DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE;
2436 !!!next-input-character;
2437 redo A;
2438 } elsif ($self->{nc} eq 0x003E) { # >
2439 !!!parse-error (type => 'no PUBLIC literal');
2440
2441 if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2442 !!!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;
2452 !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2453 redo A;
2454 } elsif ($self->{nc} == -1) {
2455 if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2456 !!!cp (185);
2457 !!!parse-error (type => 'unclosed DOCTYPE');
2458 $self->{state} = DATA_STATE;
2459 $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
2468 !!!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;
2481 } else {
2482 !!!parse-error (type => 'string after PUBLIC');
2483
2484 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;
2494 redo A;
2495 }
2496 } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE) {
2497 if ($self->{nc} == 0x0022) { # "
2498 !!!cp (187);
2499 $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
2500 !!!next-input-character;
2501 redo A;
2502 } elsif ($self->{nc} == 0x003E) { # >
2503 !!!parse-error (type => 'unclosed PUBLIC literal');
2504
2505 if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2506 !!!cp (188);
2507 $self->{state} = DATA_STATE;
2508 $self->{s_kwd} = '';
2509 $self->{ct}->{quirks} = 1;
2510 } 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;
2518 } elsif ($self->{nc} == -1) {
2519 !!!parse-error (type => 'unclosed PUBLIC literal');
2520
2521 if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2522 !!!cp (189);
2523 $self->{state} = DATA_STATE;
2524 $self->{s_kwd} = '';
2525 $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
2533 redo A;
2534 } else {
2535 !!!cp (190);
2536 $self->{ct}->{pubid} .= chr $self->{nc}; # DOCTYPE/ENTITY/NOTATION
2537 $self->{read_until}->($self->{ct}->{pubid}, q[">],
2538 length $self->{ct}->{pubid});
2539
2540 ## Stay in the state
2541 !!!next-input-character;
2542 redo A;
2543 }
2544 } elsif ($self->{state} == DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE) {
2545 if ($self->{nc} == 0x0027) { # '
2546 !!!cp (191);
2547 $self->{state} = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;
2548 !!!next-input-character;
2549 redo A;
2550 } elsif ($self->{nc} == 0x003E) { # >
2551 !!!parse-error (type => 'unclosed PUBLIC literal');
2552
2553 if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2554 !!!cp (192);
2555 $self->{state} = DATA_STATE;
2556 $self->{s_kwd} = '';
2557 $self->{ct}->{quirks} = 1;
2558 } 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;
2566 } elsif ($self->{nc} == -1) {
2567 !!!parse-error (type => 'unclosed PUBLIC literal');
2568
2569 if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2570 !!!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
2580 !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2581 redo A;
2582 } else {
2583 !!!cp (194);
2584 $self->{ct}->{pubid} .= chr $self->{nc}; # DOCTYPE/ENTITY/NOTATION
2585 $self->{read_until}->($self->{ct}->{pubid}, q['>],
2586 length $self->{ct}->{pubid});
2587
2588 ## Stay in the state
2589 !!!next-input-character;
2590 redo A;
2591 }
2592 } elsif ($self->{state} == AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE) {
2593 if ($is_space->{$self->{nc}}) {
2594 !!!cp (195);
2595 ## Stay in the state
2596 !!!next-input-character;
2597 redo A;
2598 } elsif ($self->{nc} == 0x0022) { # "
2599 !!!cp (196);
2600 $self->{ct}->{sysid} = ''; # DOCTYPE/ENTITY/NOTATION
2601 $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;
2602 !!!next-input-character;
2603 redo A;
2604 } elsif ($self->{nc} == 0x0027) { # '
2605 !!!cp (197);
2606 $self->{ct}->{sysid} = ''; # DOCTYPE/ENTITY/NOTATION
2607 $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;
2608 !!!next-input-character;
2609 redo A;
2610 } elsif ($self->{nc} == 0x003E) { # >
2611 if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2612 if ($self->{is_xml}) {
2613 !!!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;
2631 !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2632 redo A;
2633 } elsif ($self->{nc} == -1) {
2634 if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2635 !!!cp (199);
2636 !!!parse-error (type => 'unclosed DOCTYPE');
2637
2638 $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
2647 !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2648 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
2659 redo A;
2660 } else {
2661 !!!parse-error (type => 'string after PUBLIC literal');
2662
2663 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;
2673 redo A;
2674 }
2675 } elsif ($self->{state} == BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE) {
2676 if ($is_space->{$self->{nc}}) {
2677 !!!cp (201);
2678 ## Stay in the state
2679 !!!next-input-character;
2680 redo A;
2681 } elsif ($self->{nc} == 0x0022) { # "
2682 !!!cp (202);
2683 $self->{ct}->{sysid} = ''; # DOCTYPE
2684 $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;
2685 !!!next-input-character;
2686 redo A;
2687 } elsif ($self->{nc} == 0x0027) { # '
2688 !!!cp (203);
2689 $self->{ct}->{sysid} = ''; # DOCTYPE
2690 $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;
2691 !!!next-input-character;
2692 redo A;
2693 } elsif ($self->{nc} == 0x003E) { # >
2694 !!!parse-error (type => 'no SYSTEM literal');
2695 !!!next-input-character;
2696
2697 if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2698 !!!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;
2709 } elsif ($self->{nc} == -1) {
2710 if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2711 !!!cp (205);
2712 !!!parse-error (type => 'unclosed DOCTYPE');
2713 $self->{state} = DATA_STATE;
2714 $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
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->{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
2736 redo A;
2737 } else {
2738 !!!parse-error (type => 'string after SYSTEM');
2739
2740 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;
2750 redo A;
2751 }
2752 } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE) {
2753 if ($self->{nc} == 0x0022) { # "
2754 !!!cp (207);
2755 $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2756 !!!next-input-character;
2757 redo A;
2758 } elsif (not $self->{is_xml} and $self->{nc} == 0x003E) { # >
2759 !!!parse-error (type => 'unclosed SYSTEM literal');
2760
2761 if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2762 !!!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;
2772 !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2773 redo A;
2774 } elsif ($self->{nc} == -1) {
2775 !!!parse-error (type => 'unclosed SYSTEM literal');
2776
2777 if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2778 !!!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
2788 !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2789 redo A;
2790 } else {
2791 !!!cp (210);
2792 $self->{ct}->{sysid} .= chr $self->{nc}; # DOCTYPE/ENTITY/NOTATION
2793 $self->{read_until}->($self->{ct}->{sysid}, q[">],
2794 length $self->{ct}->{sysid});
2795
2796 ## Stay in the state
2797 !!!next-input-character;
2798 redo A;
2799 }
2800 } elsif ($self->{state} == DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE) {
2801 if ($self->{nc} == 0x0027) { # '
2802 !!!cp (211);
2803 $self->{state} = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;
2804 !!!next-input-character;
2805 redo A;
2806 } elsif (not $self->{is_xml} and $self->{nc} == 0x003E) { # >
2807 !!!cp (212);
2808 !!!parse-error (type => 'unclosed SYSTEM literal');
2809
2810 $self->{state} = DATA_STATE;
2811 $self->{s_kwd} = '';
2812 !!!next-input-character;
2813
2814 $self->{ct}->{quirks} = 1;
2815 !!!emit ($self->{ct}); # DOCTYPE
2816
2817 redo A;
2818 } elsif ($self->{nc} == -1) {
2819 !!!parse-error (type => 'unclosed SYSTEM literal');
2820
2821 if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2822 !!!cp (213);
2823 $self->{state} = DATA_STATE;
2824 $self->{s_kwd} = '';
2825 $self->{ct}->{quirks} = 1;
2826 } 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;
2834 } else {
2835 !!!cp (214);
2836 $self->{ct}->{sysid} .= chr $self->{nc}; # DOCTYPE/ENTITY/NOTATION
2837 $self->{read_until}->($self->{ct}->{sysid}, q['>],
2838 length $self->{ct}->{sysid});
2839
2840 ## Stay in the state
2841 !!!next-input-character;
2842 redo A;
2843 }
2844 } elsif ($self->{state} == AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE) {
2845 if ($is_space->{$self->{nc}}) {
2846 if ($self->{ct}->{type} == GENERAL_ENTITY_TOKEN) {
2847 !!!cp (215.1);
2848 $self->{state} = BEFORE_NDATA_STATE;
2849 } else {
2850 !!!cp (215);
2851 ## Stay in the state
2852 }
2853 !!!next-input-character;
2854 redo A;
2855 } elsif ($self->{nc} == 0x003E) { # >
2856 if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2857 !!!cp (216);
2858 $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;
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
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;
2937 } elsif ($self->{nc} == -1) {
2938 !!!cp (218.6);
2939 !!!parse-error (type => 'unclosed md'); ## TODO: type
2940 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2941 ## reconsume
2942 !!!emit ($self->{ct}); # ENTITY
2943 redo A;
2944 } else {
2945 !!!cp (218.7);
2946 !!!parse-error (type => 'string after SYSTEM literal');
2947 $self->{state} = BOGUS_MD_STATE;
2948 !!!next-input-character;
2949 redo A;
2950 }
2951 } elsif ($self->{state} == BOGUS_DOCTYPE_STATE) {
2952 if ($self->{nc} == 0x003E) { # >
2953 !!!cp (219);
2954 $self->{state} = DATA_STATE;
2955 $self->{s_kwd} = '';
2956 !!!next-input-character;
2957
2958 !!!emit ($self->{ct}); # DOCTYPE
2959
2960 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) {
2970 !!!cp (220);
2971 $self->{state} = DATA_STATE;
2972 $self->{s_kwd} = '';
2973 ## reconsume
2974
2975 !!!emit ($self->{ct}); # DOCTYPE
2976
2977 redo A;
2978 } else {
2979 !!!cp (221);
2980 my $s = '';
2981 $self->{read_until}->($s, q{>[}, 0);
2982
2983 ## Stay in the state
2984 !!!next-input-character;
2985 redo A;
2986 }
2987 } elsif ($self->{state} == CDATA_SECTION_STATE) {
2988 ## NOTE: "CDATA section state" in the state is jointly implemented
2989 ## by three states, |CDATA_SECTION_STATE|, |CDATA_SECTION_MSE1_STATE|,
2990 ## and |CDATA_SECTION_MSE2_STATE|.
2991
2992 ## XML5: "CDATA state".
2993
2994 if ($self->{nc} == 0x005D) { # ]
2995 !!!cp (221.1);
2996 $self->{state} = CDATA_SECTION_MSE1_STATE;
2997 !!!next-input-character;
2998 redo A;
2999 } elsif ($self->{nc} == -1) {
3000 if ($self->{is_xml}) {
3001 !!!cp (221.11);
3002 !!!parse-error (type => 'no mse'); ## TODO: type
3003 } else {
3004 !!!cp (221.12);
3005 }
3006
3007 $self->{state} = DATA_STATE;
3008 $self->{s_kwd} = '';
3009 ## Reconsume.
3010 if (length $self->{ct}->{data}) { # character
3011 !!!cp (221.2);
3012 !!!emit ($self->{ct}); # character
3013 } else {
3014 !!!cp (221.3);
3015 ## No token to emit. $self->{ct} is discarded.
3016 }
3017 redo A;
3018 } else {
3019 !!!cp (221.4);
3020 $self->{ct}->{data} .= chr $self->{nc};
3021 $self->{read_until}->($self->{ct}->{data},
3022 q<]>,
3023 length $self->{ct}->{data});
3024
3025 ## Stay in the state.
3026 !!!next-input-character;
3027 redo A;
3028 }
3029
3030 ## ISSUE: "text tokens" in spec.
3031 } elsif ($self->{state} == CDATA_SECTION_MSE1_STATE) {
3032 ## XML5: "CDATA bracket state".
3033
3034 if ($self->{nc} == 0x005D) { # ]
3035 !!!cp (221.5);
3036 $self->{state} = CDATA_SECTION_MSE2_STATE;
3037 !!!next-input-character;
3038 redo A;
3039 } else {
3040 !!!cp (221.6);
3041 ## XML5: If EOF, "]" is not appended and changed to the data state.
3042 $self->{ct}->{data} .= ']';
3043 $self->{state} = CDATA_SECTION_STATE; ## XML5: Stay in the state.
3044 ## Reconsume.
3045 redo A;
3046 }
3047 } elsif ($self->{state} == CDATA_SECTION_MSE2_STATE) {
3048 ## XML5: "CDATA end state".
3049
3050 if ($self->{nc} == 0x003E) { # >
3051 $self->{state} = DATA_STATE;
3052 $self->{s_kwd} = '';
3053 !!!next-input-character;
3054 if (length $self->{ct}->{data}) { # character
3055 !!!cp (221.7);
3056 !!!emit ($self->{ct}); # character
3057 } else {
3058 !!!cp (221.8);
3059 ## No token to emit. $self->{ct} is discarded.
3060 }
3061 redo A;
3062 } elsif ($self->{nc} == 0x005D) { # ]
3063 !!!cp (221.9); # character
3064 $self->{ct}->{data} .= ']'; ## Add first "]" of "]]]".
3065 ## Stay in the state.
3066 !!!next-input-character;
3067 redo A;
3068 } else {
3069 !!!cp (221.11);
3070 $self->{ct}->{data} .= ']]'; # character
3071 $self->{state} = CDATA_SECTION_STATE;
3072 ## Reconsume. ## XML5: Emit.
3073 redo A;
3074 }
3075 } elsif ($self->{state} == ENTITY_STATE) {
3076 if ($is_space->{$self->{nc}} or
3077 {
3078 0x003C => 1, 0x0026 => 1, -1 => 1, # <, &
3079 $self->{entity_add} => 1,
3080 }->{$self->{nc}}) {
3081 !!!cp (1001);
3082 ## Don't consume
3083 ## No error
3084 ## Return nothing.
3085 #
3086 } elsif ($self->{nc} == 0x0023) { # #
3087 !!!cp (999);
3088 $self->{state} = ENTITY_HASH_STATE;
3089 $self->{kwd} = '#';
3090 !!!next-input-character;
3091 redo A;
3092 } elsif ((0x0041 <= $self->{nc} and
3093 $self->{nc} <= 0x005A) or # A..Z
3094 (0x0061 <= $self->{nc} and
3095 $self->{nc} <= 0x007A)) { # a..z
3096 !!!cp (998);
3097 require Whatpm::_NamedEntityList;
3098 $self->{state} = ENTITY_NAME_STATE;
3099 $self->{kwd} = chr $self->{nc};
3100 $self->{entity__value} = $self->{kwd};
3101 $self->{entity__match} = 0;
3102 !!!next-input-character;
3103 redo A;
3104 } else {
3105 !!!cp (1027);
3106 !!!parse-error (type => 'bare ero');
3107 ## Return nothing.
3108 #
3109 }
3110
3111 ## NOTE: No character is consumed by the "consume a character
3112 ## reference" algorithm. In other word, there is an "&" character
3113 ## that does not introduce a character reference, which would be
3114 ## appended to the parent element or the attribute value in later
3115 ## process of the tokenizer.
3116
3117 if ($self->{prev_state} == DATA_STATE) {
3118 !!!cp (997);
3119 $self->{state} = $self->{prev_state};
3120 $self->{s_kwd} = '';
3121 ## Reconsume.
3122 !!!emit ({type => CHARACTER_TOKEN, data => '&',
3123 line => $self->{line_prev},
3124 column => $self->{column_prev},
3125 });
3126 redo A;
3127 } else {
3128 !!!cp (996);
3129 $self->{ca}->{value} .= '&';
3130 $self->{state} = $self->{prev_state};
3131 $self->{s_kwd} = '';
3132 ## Reconsume.
3133 redo A;
3134 }
3135 } elsif ($self->{state} == ENTITY_HASH_STATE) {
3136 if ($self->{nc} == 0x0078) { # x
3137 !!!cp (995);
3138 $self->{state} = HEXREF_X_STATE;
3139 $self->{kwd} .= chr $self->{nc};
3140 !!!next-input-character;
3141 redo A;
3142 } elsif ($self->{nc} == 0x0058) { # X
3143 !!!cp (995.1);
3144 if ($self->{is_xml}) {
3145 !!!parse-error (type => 'uppercase hcro'); ## TODO: type
3146 }
3147 $self->{state} = HEXREF_X_STATE;
3148 $self->{kwd} .= chr $self->{nc};
3149 !!!next-input-character;
3150 redo A;
3151 } elsif (0x0030 <= $self->{nc} and
3152 $self->{nc} <= 0x0039) { # 0..9
3153 !!!cp (994);
3154 $self->{state} = NCR_NUM_STATE;
3155 $self->{kwd} = $self->{nc} - 0x0030;
3156 !!!next-input-character;
3157 redo A;
3158 } else {
3159 !!!parse-error (type => 'bare nero',
3160 line => $self->{line_prev},
3161 column => $self->{column_prev} - 1);
3162
3163 ## NOTE: According to the spec algorithm, nothing is returned,
3164 ## and then "&#" is appended to the parent element or the attribute
3165 ## value in the later processing.
3166
3167 if ($self->{prev_state} == DATA_STATE) {
3168 !!!cp (1019);
3169 $self->{state} = $self->{prev_state};
3170 $self->{s_kwd} = '';
3171 ## Reconsume.
3172 !!!emit ({type => CHARACTER_TOKEN,
3173 data => '&#',
3174 line => $self->{line_prev},
3175 column => $self->{column_prev} - 1,
3176 });
3177 redo A;
3178 } else {
3179 !!!cp (993);
3180 $self->{ca}->{value} .= '&#';
3181 $self->{state} = $self->{prev_state};
3182 $self->{s_kwd} = '';
3183 ## Reconsume.
3184 redo A;
3185 }
3186 }
3187 } elsif ($self->{state} == NCR_NUM_STATE) {
3188 if (0x0030 <= $self->{nc} and
3189 $self->{nc} <= 0x0039) { # 0..9
3190 !!!cp (1012);
3191 $self->{kwd} *= 10;
3192 $self->{kwd} += $self->{nc} - 0x0030;
3193
3194 ## Stay in the state.
3195 !!!next-input-character;
3196 redo A;
3197 } elsif ($self->{nc} == 0x003B) { # ;
3198 !!!cp (1013);
3199 !!!next-input-character;
3200 #
3201 } else {
3202 !!!cp (1014);
3203 !!!parse-error (type => 'no refc');
3204 ## Reconsume.
3205 #
3206 }
3207
3208 my $code = $self->{kwd};
3209 my $l = $self->{line_prev};
3210 my $c = $self->{column_prev};
3211 if ($charref_map->{$code}) {
3212 !!!cp (1015);
3213 !!!parse-error (type => 'invalid character reference',
3214 text => (sprintf 'U+%04X', $code),
3215 line => $l, column => $c);
3216 $code = $charref_map->{$code};
3217 } elsif ($code > 0x10FFFF) {
3218 !!!cp (1016);
3219 !!!parse-error (type => 'invalid character reference',
3220 text => (sprintf 'U-%08X', $code),
3221 line => $l, column => $c);
3222 $code = 0xFFFD;
3223 }
3224
3225 if ($self->{prev_state} == DATA_STATE) {
3226 !!!cp (992);
3227 $self->{state} = $self->{prev_state};
3228 $self->{s_kwd} = '';
3229 ## Reconsume.
3230 !!!emit ({type => CHARACTER_TOKEN, data => chr $code,
3231 has_reference => 1,
3232 line => $l, column => $c,
3233 });
3234 redo A;
3235 } else {
3236 !!!cp (991);
3237 $self->{ca}->{value} .= chr $code;
3238 $self->{ca}->{has_reference} = 1;
3239 $self->{state} = $self->{prev_state};
3240 $self->{s_kwd} = '';
3241 ## Reconsume.
3242 redo A;
3243 }
3244 } elsif ($self->{state} == HEXREF_X_STATE) {
3245 if ((0x0030 <= $self->{nc} and $self->{nc} <= 0x0039) or
3246 (0x0041 <= $self->{nc} and $self->{nc} <= 0x0046) or
3247 (0x0061 <= $self->{nc} and $self->{nc} <= 0x0066)) {
3248 # 0..9, A..F, a..f
3249 !!!cp (990);
3250 $self->{state} = HEXREF_HEX_STATE;
3251 $self->{kwd} = 0;
3252 ## Reconsume.
3253 redo A;
3254 } else {
3255 !!!parse-error (type => 'bare hcro',
3256 line => $self->{line_prev},
3257 column => $self->{column_prev} - 2);
3258
3259 ## NOTE: According to the spec algorithm, nothing is returned,
3260 ## and then "&#" followed by "X" or "x" is appended to the parent
3261 ## element or the attribute value in the later processing.
3262
3263 if ($self->{prev_state} == DATA_STATE) {
3264 !!!cp (1005);
3265 $self->{state} = $self->{prev_state};
3266 $self->{s_kwd} = '';
3267 ## Reconsume.
3268 !!!emit ({type => CHARACTER_TOKEN,
3269 data => '&' . $self->{kwd},
3270 line => $self->{line_prev},
3271 column => $self->{column_prev} - length $self->{kwd},
3272 });
3273 redo A;
3274 } else {
3275 !!!cp (989);
3276 $self->{ca}->{value} .= '&' . $self->{kwd};
3277 $self->{state} = $self->{prev_state};
3278 $self->{s_kwd} = '';
3279 ## Reconsume.
3280 redo A;
3281 }
3282 }
3283 } elsif ($self->{state} == HEXREF_HEX_STATE) {
3284 if (0x0030 <= $self->{nc} and $self->{nc} <= 0x0039) {
3285 # 0..9
3286 !!!cp (1002);
3287 $self->{kwd} *= 0x10;
3288 $self->{kwd} += $self->{nc} - 0x0030;
3289 ## Stay in the state.
3290 !!!next-input-character;
3291 redo A;
3292 } elsif (0x0061 <= $self->{nc} and
3293 $self->{nc} <= 0x0066) { # a..f
3294 !!!cp (1003);
3295 $self->{kwd} *= 0x10;
3296 $self->{kwd} += $self->{nc} - 0x0060 + 9;
3297 ## Stay in the state.
3298 !!!next-input-character;
3299 redo A;
3300 } elsif (0x0041 <= $self->{nc} and
3301 $self->{nc} <= 0x0046) { # A..F
3302 !!!cp (1004);
3303 $self->{kwd} *= 0x10;
3304 $self->{kwd} += $self->{nc} - 0x0040 + 9;
3305 ## Stay in the state.
3306 !!!next-input-character;
3307 redo A;
3308 } elsif ($self->{nc} == 0x003B) { # ;
3309 !!!cp (1006);
3310 !!!next-input-character;
3311 #
3312 } else {
3313 !!!cp (1007);
3314 !!!parse-error (type => 'no refc',
3315 line => $self->{line},
3316 column => $self->{column});
3317 ## Reconsume.
3318 #
3319 }
3320
3321 my $code = $self->{kwd};
3322 my $l = $self->{line_prev};
3323 my $c = $self->{column_prev};
3324 if ($charref_map->{$code}) {
3325 !!!cp (1008);
3326 !!!parse-error (type => 'invalid character reference',
3327 text => (sprintf 'U+%04X', $code),
3328 line => $l, column => $c);
3329 $code = $charref_map->{$code};
3330 } elsif ($code > 0x10FFFF) {
3331 !!!cp (1009);
3332 !!!parse-error (type => 'invalid character reference',
3333 text => (sprintf 'U-%08X', $code),
3334 line => $l, column => $c);
3335 $code = 0xFFFD;
3336 }
3337
3338 if ($self->{prev_state} == DATA_STATE) {
3339 !!!cp (988);
3340 $self->{state} = $self->{prev_state};
3341 $self->{s_kwd} = '';
3342 ## Reconsume.
3343 !!!emit ({type => CHARACTER_TOKEN, data => chr $code,
3344 has_reference => 1,
3345 line => $l, column => $c,
3346 });
3347 redo A;
3348 } else {
3349 !!!cp (987);
3350 $self->{ca}->{value} .= chr $code;
3351 $self->{ca}->{has_reference} = 1;
3352 $self->{state} = $self->{prev_state};
3353 $self->{s_kwd} = '';
3354 ## Reconsume.
3355 redo A;
3356 }
3357 } elsif ($self->{state} == ENTITY_NAME_STATE) {
3358 if ((0x0041 <= $self->{nc} and # a
3359 $self->{nc} <= 0x005A) or # x
3360 (0x0061 <= $self->{nc} and # a
3361 $self->{nc} <= 0x007A) or # z
3362 (0x0030 <= $self->{nc} and # 0
3363 $self->{nc} <= 0x0039) or # 9
3364 $self->{nc} == 0x003B) { # ;
3365 our $EntityChar;
3366 $self->{kwd} .= chr $self->{nc};
3367 if (defined $EntityChar->{$self->{kwd}} or
3368 $self->{ge}->{$self->{kwd}}) {
3369 if ($self->{nc} == 0x003B) { # ;
3370 if (defined $self->{ge}->{$self->{kwd}}) {
3371 if ($self->{ge}->{$self->{kwd}}->{only_text}) {
3372 !!!cp (1020.1);
3373 $self->{entity__value} = $self->{ge}->{$self->{kwd}}->{value};
3374 } else {
3375 if (defined $self->{ge}->{$self->{kwd}}->{notation}) {
3376 !!!cp (1020.2);
3377 !!!parse-error (type => 'unparsed entity', ## TODO: type
3378 value => $self->{kwd});
3379 } else {
3380 !!!cp (1020.3);
3381 }
3382 $self->{entity__value} = '&' . $self->{kwd}; ## TODO: expand
3383 }
3384 } else {
3385 if ($self->{is_xml}) {
3386 !!!cp (1020.4);
3387 !!!parse-error (type => 'entity not declared', ## TODO: type
3388 value => $self->{kwd},
3389 level => {
3390 'amp;' => $self->{level}->{warn},
3391 'quot;' => $self->{level}->{warn},
3392 'lt;' => $self->{level}->{warn},
3393 'gt;' => $self->{level}->{warn},
3394 'apos;' => $self->{level}->{warn},
3395 }->{$self->{kwd}} ||
3396 $self->{level}->{must});
3397 } else {
3398 !!!cp (1020);
3399 }
3400 $self->{entity__value} = $EntityChar->{$self->{kwd}};
3401 }
3402 $self->{entity__match} = 1;
3403 !!!next-input-character;
3404 #
3405 } else {
3406 !!!cp (1021);
3407 $self->{entity__value} = $EntityChar->{$self->{kwd}};
3408 $self->{entity__match} = -1;
3409 ## Stay in the state.
3410 !!!next-input-character;
3411 redo A;
3412 }
3413 } else {
3414 !!!cp (1022);
3415 $self->{entity__value} .= chr $self->{nc};
3416 $self->{entity__match} *= 2;
3417 ## Stay in the state.
3418 !!!next-input-character;
3419 redo A;
3420 }
3421 }
3422
3423 my $data;
3424 my $has_ref;
3425 if ($self->{entity__match} > 0) {
3426 !!!cp (1023);
3427 $data = $self->{entity__value};
3428 $has_ref = 1;
3429 #
3430 } elsif ($self->{entity__match} < 0) {
3431 !!!parse-error (type => 'no refc');
3432 if ($self->{prev_state} != DATA_STATE and # in attribute
3433 $self->{entity__match} < -1) {
3434 !!!cp (1024);
3435 $data = '&' . $self->{kwd};
3436 #
3437 } else {
3438 !!!cp (1025);
3439 $data = $self->{entity__value};
3440 $has_ref = 1;
3441 #
3442 }
3443 } else {
3444 !!!cp (1026);
3445 !!!parse-error (type => 'bare ero',
3446 line => $self->{line_prev},
3447 column => $self->{column_prev} - length $self->{kwd});
3448 $data = '&' . $self->{kwd};
3449 #
3450 }
3451
3452 ## NOTE: In these cases, when a character reference is found,
3453 ## it is consumed and a character token is returned, or, otherwise,
3454 ## nothing is consumed and returned, according to the spec algorithm.
3455 ## In this implementation, anything that has been examined by the
3456 ## tokenizer is appended to the parent element or the attribute value
3457 ## as string, either literal string when no character reference or
3458 ## entity-replaced string otherwise, in this stage, since any characters
3459 ## that would not be consumed are appended in the data state or in an
3460 ## appropriate attribute value state anyway.
3461
3462 if ($self->{prev_state} == DATA_STATE) {
3463 !!!cp (986);
3464 $self->{state} = $self->{prev_state};
3465 $self->{s_kwd} = '';
3466 ## Reconsume.
3467 !!!emit ({type => CHARACTER_TOKEN,
3468 data => $data,
3469 has_reference => $has_ref,
3470 line => $self->{line_prev},
3471 column => $self->{column_prev} + 1 - length $self->{kwd},
3472 });
3473 redo A;
3474 } else {
3475 !!!cp (985);
3476 $self->{ca}->{value} .= $data;
3477 $self->{ca}->{has_reference} = 1 if $has_ref;
3478 $self->{state} = $self->{prev_state};
3479 $self->{s_kwd} = '';
3480 ## Reconsume.
3481 redo A;
3482 }
3483
3484 ## XML-only states
3485
3486 } elsif ($self->{state} == PI_STATE) {
3487 ## XML5: "Pi state" and "DOCTYPE pi state".
3488
3489 if ($is_space->{$self->{nc}} or
3490 $self->{nc} == 0x003F or # ?
3491 $self->{nc} == -1) {
3492 ## XML5: U+003F: "pi state": Same as "Anything else"; "DOCTYPE
3493 ## pi state": Switch to the "DOCTYPE pi after state". EOF:
3494 ## "DOCTYPE pi state": Parse error, switch to the "data
3495 ## state".
3496 !!!parse-error (type => 'bare pio', ## TODO: type
3497 line => $self->{line_prev},
3498 column => $self->{column_prev}
3499 - 1 * ($self->{nc} != -1));
3500 $self->{state} = BOGUS_COMMENT_STATE;
3501 ## Reconsume.
3502 $self->{ct} = {type => COMMENT_TOKEN,
3503 data => '?',
3504 line => $self->{line_prev},
3505 column => $self->{column_prev}
3506 - 1 * ($self->{nc} != -1),
3507 };
3508 redo A;
3509 } else {
3510 ## XML5: "DOCTYPE pi state": Stay in the state.
3511 $self->{ct} = {type => PI_TOKEN,
3512 target => chr $self->{nc},
3513 data => '',
3514 line => $self->{line_prev},
3515 column => $self->{column_prev} - 1,
3516 };
3517 $self->{state} = PI_TARGET_STATE;
3518 !!!next-input-character;
3519 redo A;
3520 }
3521 } elsif ($self->{state} == PI_TARGET_STATE) {
3522 if ($is_space->{$self->{nc}}) {
3523 $self->{state} = PI_TARGET_AFTER_STATE;
3524 !!!next-input-character;
3525 redo A;
3526 } elsif ($self->{nc} == -1) {
3527 !!!parse-error (type => 'no pic'); ## TODO: type
3528 if ($self->{in_subset}) {
3529 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
3530 } else {
3531 $self->{state} = DATA_STATE;
3532 $self->{s_kwd} = '';
3533 }
3534 ## Reconsume.
3535 !!!emit ($self->{ct}); # pi
3536 redo A;
3537 } elsif ($self->{nc} == 0x003F) { # ?
3538 $self->{state} = PI_AFTER_STATE;
3539 !!!next-input-character;
3540 redo A;
3541 } else {
3542 ## XML5: typo ("tag name" -> "target")
3543 $self->{ct}->{target} .= chr $self->{nc}; # pi
3544 !!!next-input-character;
3545 redo A;
3546 }
3547 } elsif ($self->{state} == PI_TARGET_AFTER_STATE) {
3548 if ($is_space->{$self->{nc}}) {
3549 ## Stay in the state.
3550 !!!next-input-character;
3551 redo A;
3552 } else {
3553 $self->{state} = PI_DATA_STATE;
3554 ## Reprocess.
3555 redo A;
3556 }
3557 } elsif ($self->{state} == PI_DATA_STATE) {
3558 if ($self->{nc} == 0x003F) { # ?
3559 $self->{state} = PI_DATA_AFTER_STATE;
3560 !!!next-input-character;
3561 redo A;
3562 } elsif ($self->{nc} == -1) {
3563 !!!parse-error (type => 'no pic'); ## TODO: type
3564 if ($self->{in_subset}) {
3565 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state"
3566 } else {
3567 $self->{state} = DATA_STATE;
3568 $self->{s_kwd} = '';
3569 }
3570 ## Reprocess.
3571 !!!emit ($self->{ct}); # pi
3572 redo A;
3573 } else {
3574 $self->{ct}->{data} .= chr $self->{nc}; # pi
3575 $self->{read_until}->($self->{ct}->{data}, q[?],
3576 length $self->{ct}->{data});
3577 ## Stay in the state.
3578 !!!next-input-character;
3579 ## Reprocess.
3580 redo A;
3581 }
3582 } elsif ($self->{state} == PI_AFTER_STATE) {
3583 ## XML5: Part of "Pi after state".
3584
3585 if ($self->{nc} == 0x003E) { # >
3586 if ($self->{in_subset}) {
3587 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
3588 } else {
3589 $self->{state} = DATA_STATE;
3590 $self->{s_kwd} = '';
3591 }
3592 !!!next-input-character;
3593 !!!emit ($self->{ct}); # pi
3594 redo A;
3595 } elsif ($self->{nc} == 0x003F) { # ?
3596 !!!parse-error (type => 'no s after target', ## TODO: type
3597 line => $self->{line_prev},
3598 column => $self->{column_prev}); ## XML5: no error
3599 $self->{ct}->{data} .= '?';
3600 $self->{state} = PI_DATA_AFTER_STATE;
3601 !!!next-input-character;
3602 redo A;
3603 } else {
3604 !!!parse-error (type => 'no s after target', ## TODO: type
3605 line => $self->{line_prev},
3606 column => $self->{column_prev}
3607 + 1 * ($self->{nc} == -1)); ## XML5: no error
3608 $self->{ct}->{data} .= '?'; ## XML5: not appended
3609 $self->{state} = PI_DATA_STATE;
3610 ## Reprocess.
3611 redo A;
3612 }
3613 } elsif ($self->{state} == PI_DATA_AFTER_STATE) {
3614 ## XML5: Same as "pi after state" and "DOCTYPE pi after state".
3615
3616 if ($self->{nc} == 0x003E) { # >
3617 if ($self->{in_subset}) {
3618 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
3619 } else {
3620 $self->{state} = DATA_STATE;
3621 $self->{s_kwd} = '';
3622 }
3623 !!!next-input-character;
3624 !!!emit ($self->{ct}); # pi
3625 redo A;
3626 } elsif ($self->{nc} == 0x003F) { # ?
3627 $self->{ct}->{data} .= '?';
3628 ## Stay in the state.
3629 !!!next-input-character;
3630 redo A;
3631 } else {
3632 $self->{ct}->{data} .= '?'; ## XML5: not appended
3633 $self->{state} = PI_DATA_STATE;
3634 ## Reprocess.
3635 redo A;
3636 }
3637
3638 } elsif ($self->{state} == DOCTYPE_INTERNAL_SUBSET_STATE) {
3639 if ($self->{nc} == 0x003C) { # <
3640 $self->{state} = DOCTYPE_TAG_STATE;
3641 !!!next-input-character;
3642 redo A;
3643 } elsif ($self->{nc} == 0x0025) { # %
3644 ## XML5: Not defined yet.
3645
3646 ## TODO:
3647 !!!next-input-character;
3648 redo A;
3649 } elsif ($self->{nc} == 0x005D) { # ]
3650 delete $self->{in_subset};
3651 $self->{state} = DOCTYPE_INTERNAL_SUBSET_AFTER_STATE;
3652 !!!next-input-character;
3653 redo A;
3654 } elsif ($is_space->{$self->{nc}}) {
3655 ## Stay in the state.
3656 !!!next-input-character;
3657 redo A;
3658 } elsif ($self->{nc} == -1) {
3659 !!!parse-error (type => 'unclosed internal subset'); ## TODO: type
3660 delete $self->{in_subset};
3661 $self->{state} = DATA_STATE;
3662 $self->{s_kwd} = '';
3663 ## Reconsume.
3664 !!!emit ({type => END_OF_DOCTYPE_TOKEN});
3665 redo A;
3666 } else {
3667 unless ($self->{internal_subset_tainted}) {
3668 ## XML5: No parse error.
3669 !!!parse-error (type => 'string in internal subset');
3670 $self->{internal_subset_tainted} = 1;
3671 }
3672 ## Stay in the state.
3673 !!!next-input-character;
3674 redo A;
3675 }
3676 } elsif ($self->{state} == DOCTYPE_INTERNAL_SUBSET_AFTER_STATE) {
3677 if ($self->{nc} == 0x003E) { # >
3678 $self->{state} = DATA_STATE;
3679 $self->{s_kwd} = '';
3680 !!!next-input-character;
3681 !!!emit ({type => END_OF_DOCTYPE_TOKEN});
3682 redo A;
3683 } elsif ($self->{nc} == -1) {
3684 !!!parse-error (type => 'unclosed DOCTYPE');
3685 $self->{state} = DATA_STATE;
3686 $self->{s_kwd} = '';
3687 ## Reconsume.
3688 !!!emit ({type => END_OF_DOCTYPE_TOKEN});
3689 redo A;
3690 } else {
3691 ## XML5: No parse error and stay in the state.
3692 !!!parse-error (type => 'string after internal subset'); ## TODO: type
3693
3694 $self->{state} = BOGUS_DOCTYPE_INTERNAL_SUBSET_AFTER_STATE;
3695 !!!next-input-character;
3696 redo A;
3697 }
3698 } elsif ($self->{state} == BOGUS_DOCTYPE_INTERNAL_SUBSET_AFTER_STATE) {
3699 if ($self->{nc} == 0x003E) { # >
3700 $self->{state} = DATA_STATE;
3701 $self->{s_kwd} = '';
3702 !!!next-input-character;
3703 !!!emit ({type => END_OF_DOCTYPE_TOKEN});
3704 redo A;
3705 } elsif ($self->{nc} == -1) {
3706 $self->{state} = DATA_STATE;
3707 $self->{s_kwd} = '';
3708 ## Reconsume.
3709 !!!emit ({type => END_OF_DOCTYPE_TOKEN});
3710 redo A;
3711 } else {
3712 ## Stay in the state.
3713 !!!next-input-character;
3714 redo A;
3715 }
3716 } elsif ($self->{state} == DOCTYPE_TAG_STATE) {
3717 if ($self->{nc} == 0x0021) { # !
3718 $self->{state} = DOCTYPE_MARKUP_DECLARATION_OPEN_STATE;
3719 !!!next-input-character;
3720 redo A;
3721 } elsif ($self->{nc} == 0x003F) { # ?
3722 $self->{state} = PI_STATE;
3723 !!!next-input-character;
3724 redo A;
3725 } elsif ($self->{nc} == -1) {
3726 !!!parse-error (type => 'bare stago');
3727 $self->{state} = DATA_STATE;
3728 $self->{s_kwd} = '';
3729 ## Reconsume.
3730 redo A;
3731 } else {
3732 !!!parse-error (type => 'bare stago', ## XML5: Not a parse error.
3733 line => $self->{line_prev},
3734 column => $self->{column_prev});
3735 $self->{state} = BOGUS_COMMENT_STATE;
3736 $self->{ct} = {type => COMMENT_TOKEN,
3737 data => '',
3738 }; ## NOTE: Will be discarded.
3739 !!!next-input-character;
3740 redo A;
3741 }
3742 } elsif ($self->{state} == DOCTYPE_MARKUP_DECLARATION_OPEN_STATE) {
3743 ## XML5: "DOCTYPE markup declaration state".
3744
3745 if ($self->{nc} == 0x002D) { # -
3746 $self->{state} = MD_HYPHEN_STATE;
3747 !!!next-input-character;
3748 redo A;
3749 } elsif ($self->{nc} == 0x0045 or # E
3750 $self->{nc} == 0x0065) { # e
3751 $self->{state} = MD_E_STATE;
3752 $self->{kwd} = chr $self->{nc};
3753 !!!next-input-character;
3754 redo A;
3755 } elsif ($self->{nc} == 0x0041 or # A
3756 $self->{nc} == 0x0061) { # a
3757 $self->{state} = MD_ATTLIST_STATE;
3758 $self->{kwd} = chr $self->{nc};
3759 !!!next-input-character;
3760 redo A;
3761 } elsif ($self->{nc} == 0x004E or # N
3762 $self->{nc} == 0x006E) { # n
3763 $self->{state} = MD_NOTATION_STATE;
3764 $self->{kwd} = chr $self->{nc};
3765 !!!next-input-character;
3766 redo A;
3767 } else {
3768 #
3769 }
3770
3771 ## XML5: No parse error.
3772 !!!parse-error (type => 'bogus comment',
3773 line => $self->{line_prev},
3774 column => $self->{column_prev} - 1);
3775 ## Reconsume.
3776 $self->{state} = BOGUS_COMMENT_STATE;
3777 $self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded.
3778 redo A;
3779 } elsif ($self->{state} == MD_E_STATE) {
3780 if ($self->{nc} == 0x004E or # N
3781 $self->{nc} == 0x006E) { # n
3782 $self->{state} = MD_ENTITY_STATE;
3783 $self->{kwd} .= chr $self->{nc};
3784 !!!next-input-character;
3785 redo A;
3786 } elsif ($self->{nc} == 0x004C or # L
3787 $self->{nc} == 0x006C) { # l
3788 ## XML5: <!ELEMENT> not supported.
3789 $self->{state} = MD_ELEMENT_STATE;
3790 $self->{kwd} .= chr $self->{nc};
3791 !!!next-input-character;
3792 redo A;
3793 } else {
3794 ## XML5: No parse error.
3795 !!!parse-error (type => 'bogus comment',
3796 line => $self->{line_prev},
3797 column => $self->{column_prev} - 2
3798 + 1 * ($self->{nc} == -1));
3799 ## Reconsume.
3800 $self->{state} = BOGUS_COMMENT_STATE;
3801 $self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded
3802 redo A;
3803 }
3804 } elsif ($self->{state} == MD_ENTITY_STATE) {
3805 if ($self->{nc} == [
3806 undef,
3807 undef,
3808 0x0054, # T
3809 0x0049, # I
3810 0x0054, # T
3811 ]->[length $self->{kwd}] or
3812 $self->{nc} == [
3813 undef,
3814 undef,
3815 0x0074, # t
3816 0x0069, # i
3817 0x0074, # t
3818 ]->[length $self->{kwd}]) {
3819 ## Stay in the state.
3820 $self->{kwd} .= chr $self->{nc};
3821 !!!next-input-character;
3822 redo A;
3823 } elsif ((length $self->{kwd}) == 5 and
3824 ($self->{nc} == 0x0059 or # Y
3825 $self->{nc} == 0x0079)) { # y
3826 if ($self->{kwd} ne 'ENTIT' or $self->{nc} == 0x0079) {
3827 !!!parse-error (type => 'lowercase keyword', ## TODO: type
3828 text => 'ENTITY',
3829 line => $self->{line_prev},
3830 column => $self->{column_prev} - 4);
3831 }
3832 $self->{ct} = {type => GENERAL_ENTITY_TOKEN, name => '',
3833 line => $self->{line_prev},
3834 column => $self->{column_prev} - 6};
3835 $self->{state} = DOCTYPE_MD_STATE;
3836 !!!next-input-character;
3837 redo A;
3838 } else {
3839 !!!parse-error (type => 'bogus comment',
3840 line => $self->{line_prev},
3841 column => $self->{column_prev} - 1
3842 - (length $self->{kwd})
3843 + 1 * ($self->{nc} == -1));
3844 $self->{state} = BOGUS_COMMENT_STATE;
3845 ## Reconsume.
3846 $self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded
3847 redo A;
3848 }
3849 } elsif ($self->{state} == MD_ELEMENT_STATE) {
3850 if ($self->{nc} == [
3851 undef,
3852 undef,
3853 0x0045, # E
3854 0x004D, # M
3855 0x0045, # E
3856 0x004E, # N
3857 ]->[length $self->{kwd}] or
3858 $self->{nc} == [
3859 undef,
3860 undef,
3861 0x0065, # e
3862 0x006D, # m
3863 0x0065, # e
3864 0x006E, # n
3865 ]->[length $self->{kwd}]) {
3866 ## Stay in the state.
3867 $self->{kwd} .= chr $self->{nc};
3868 !!!next-input-character;
3869 redo A;
3870 } elsif ((length $self->{kwd}) == 6 and
3871 ($self->{nc} == 0x0054 or # T
3872 $self->{nc} == 0x0074)) { # t
3873 if ($self->{kwd} ne 'ELEMEN' or $self->{nc} == 0x0074) {
3874 !!!parse-error (type => 'lowercase keyword', ## TODO: type
3875 text => 'ELEMENT',
3876 line => $self->{line_prev},
3877 column => $self->{column_prev} - 5);
3878 }
3879 $self->{ct} = {type => ELEMENT_TOKEN, name => '',
3880 line => $self->{line_prev},
3881 column => $self->{column_prev} - 6};
3882 $self->{state} = DOCTYPE_MD_STATE;
3883 !!!next-input-character;
3884 redo A;
3885 } else {
3886 !!!parse-error (type => 'bogus comment',
3887 line => $self->{line_prev},
3888 column => $self->{column_prev} - 1
3889 - (length $self->{kwd})
3890 + 1 * ($self->{nc} == -1));
3891 $self->{state} = BOGUS_COMMENT_STATE;
3892 ## Reconsume.
3893 $self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded
3894 redo A;
3895 }
3896 } elsif ($self->{state} == MD_ATTLIST_STATE) {
3897 if ($self->{nc} == [
3898 undef,
3899 0x0054, # T
3900 0x0054, # T
3901 0x004C, # L
3902 0x0049, # I
3903 0x0053, # S
3904 ]->[length $self->{kwd}] or
3905 $self->{nc} == [
3906 undef,
3907 0x0074, # t
3908 0x0074, # t
3909 0x006C, # l
3910 0x0069, # i
3911 0x0073, # s
3912 ]->[length $self->{kwd}]) {
3913 ## Stay in the state.
3914 $self->{kwd} .= chr $self->{nc};
3915 !!!next-input-character;
3916 redo A;
3917 } elsif ((length $self->{kwd}) == 6 and
3918 ($self->{nc} == 0x0054 or # T
3919 $self->{nc} == 0x0074)) { # t
3920 if ($self->{kwd} ne 'ATTLIS' or $self->{nc} == 0x0074) {
3921 !!!parse-error (type => 'lowercase keyword', ## TODO: type
3922 text => 'ATTLIST',
3923 line => $self->{line_prev},
3924 column => $self->{column_prev} - 5);
3925 }
3926 $self->{ct} = {type => ATTLIST_TOKEN, name => '',
3927 attrdefs => [],
3928 line => $self->{line_prev},
3929 column => $self->{column_prev} - 6};
3930 $self->{state} = DOCTYPE_MD_STATE;
3931 !!!next-input-character;
3932 redo A;
3933 } else {
3934 !!!parse-error (type => 'bogus comment',
3935 line => $self->{line_prev},
3936 column => $self->{column_prev} - 1
3937 - (length $self->{kwd})
3938 + 1 * ($self->{nc} == -1));
3939 $self->{state} = BOGUS_COMMENT_STATE;
3940 ## Reconsume.
3941 $self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded
3942 redo A;
3943 }
3944 } elsif ($self->{state} == MD_NOTATION_STATE) {
3945 if ($self->{nc} == [
3946 undef,
3947 0x004F, # O
3948 0x0054, # T
3949 0x0041, # A
3950 0x0054, # T
3951 0x0049, # I
3952 0x004F, # O
3953 ]->[length $self->{kwd}] or
3954 $self->{nc} == [
3955 undef,
3956 0x006F, # o
3957 0x0074, # t
3958 0x0061, # a
3959 0x0074, # t
3960 0x0069, # i
3961 0x006F, # o
3962 ]->[length $self->{kwd}]) {
3963 ## Stay in the state.
3964 $self->{kwd} .= chr $self->{nc};
3965 !!!next-input-character;
3966 redo A;
3967 } elsif ((length $self->{kwd}) == 7 and
3968 ($self->{nc} == 0x004E or # N
3969 $self->{nc} == 0x006E)) { # n
3970 if ($self->{kwd} ne 'NOTATIO' or $self->{nc} == 0x006E) {
3971 !!!parse-error (type => 'lowercase keyword', ## TODO: type
3972 text => 'NOTATION',
3973 line => $self->{line_prev},
3974 column => $self->{column_prev} - 6);
3975 }
3976 $self->{ct} = {type => NOTATION_TOKEN, name => '',
3977 line => $self->{line_prev},
3978 column => $self->{column_prev} - 6};
3979 $self->{state} = DOCTYPE_MD_STATE;
3980 !!!next-input-character;
3981 redo A;
3982 } else {
3983 !!!parse-error (type => 'bogus comment',
3984 line => $self->{line_prev},
3985 column => $self->{column_prev} - 1
3986 - (length $self->{kwd})
3987 + 1 * ($self->{nc} == -1));
3988 $self->{state} = BOGUS_COMMENT_STATE;
3989 ## Reconsume.
3990 $self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded
3991 redo A;
3992 }
3993 } elsif ($self->{state} == DOCTYPE_MD_STATE) {
3994 ## XML5: "DOCTYPE ENTITY state", "DOCTYPE ATTLIST state", and
3995 ## "DOCTYPE NOTATION state".
3996
3997 if ($is_space->{$self->{nc}}) {
3998 ## XML5: [NOTATION] Switch to the "DOCTYPE NOTATION identifier state".
3999 $self->{state} = BEFORE_MD_NAME_STATE;
4000 !!!next-input-character;
4001 redo A;
4002 } elsif ($self->{ct}->{type} == GENERAL_ENTITY_TOKEN and
4003 $self->{nc} == 0x0025) { # %
4004 ## XML5: Switch to the "DOCTYPE bogus comment state".
4005 !!!parse-error (type => 'no space before md name'); ## TODO: type
4006 $self->{state} = DOCTYPE_ENTITY_PARAMETER_BEFORE_STATE;
4007 !!!next-input-character;
4008 redo A;
4009 } elsif ($self->{nc} == -1) {
4010 !!!parse-error (type => 'unclosed md'); ## TODO: type
4011 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4012 ## Reconsume.
4013 redo A;
4014 } elsif ($self->{nc} == 0x003E) { # >
4015 ## XML5: Switch to the "DOCTYPE bogus comment state".
4016 !!!parse-error (type => 'no md name'); ## TODO: type
4017 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4018 !!!next-input-character;
4019 redo A;
4020 } else {
4021 ## XML5: Switch to the "DOCTYPE bogus comment state".
4022 !!!parse-error (type => 'no space before md name'); ## TODO: type
4023 $self->{state} = BEFORE_MD_NAME_STATE;
4024 redo A;
4025 }
4026 } elsif ($self->{state} == BEFORE_MD_NAME_STATE) {
4027 ## XML5: "DOCTYPE ENTITY parameter state", "DOCTYPE ENTITY type
4028 ## before state", "DOCTYPE ATTLIST name before state".
4029
4030 if ($is_space->{$self->{nc}}) {
4031 ## Stay in the state.
4032 !!!next-input-character;
4033 redo A;
4034 } elsif ($self->{ct}->{type} == GENERAL_ENTITY_TOKEN and
4035 $self->{nc} == 0x0025) { # %
4036 $self->{state} = DOCTYPE_ENTITY_PARAMETER_BEFORE_STATE;
4037 !!!next-input-character;
4038 redo A;
4039 } elsif ($self->{nc} == 0x003E) { # >
4040 ## XML5: Same as "Anything else".
4041 !!!parse-error (type => 'no md name'); ## TODO: type
4042 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4043 !!!next-input-character;
4044 redo A;
4045 } elsif ($self->{nc} == -1) {
4046 !!!parse-error (type => 'unclosed md'); ## TODO: type
4047 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4048 ## Reconsume.
4049 redo A;
4050 } else {
4051 ## XML5: [ATTLIST] Not defined yet.
4052 $self->{ct}->{name} .= chr $self->{nc};
4053 $self->{state} = MD_NAME_STATE;
4054 !!!next-input-character;
4055 redo A;
4056 }
4057 } elsif ($self->{state} == DOCTYPE_ENTITY_PARAMETER_BEFORE_STATE) {
4058 if ($is_space->{$self->{nc}}) {
4059 ## XML5: Switch to the "DOCTYPE ENTITY parameter state".
4060 $self->{ct}->{type} = PARAMETER_ENTITY_TOKEN;
4061 $self->{state} = BEFORE_MD_NAME_STATE;
4062 !!!next-input-character;
4063 redo A;
4064 } elsif ($self->{nc} == 0x003E) { # >
4065 ## XML5: Same as "Anything else".
4066 !!!parse-error (type => 'no md name'); ## TODO: type
4067 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4068 !!!next-input-character;
4069 redo A;
4070 } elsif ($self->{nc} == -1) {
4071 !!!parse-error (type => 'unclosed md');
4072 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4073 ## Reconsume.
4074 redo A;
4075 } else {
4076 ## XML5: No parse error.
4077 !!!parse-error (type => 'no space after ENTITY percent'); ## TODO: type
4078 $self->{state} = BOGUS_COMMENT_STATE;
4079 $self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded
4080 ## Reconsume.
4081 redo A;
4082 }
4083 } elsif ($self->{state} == MD_NAME_STATE) {
4084 ## XML5: "DOCTYPE ENTITY name state" and "DOCTYPE ATTLIST name state".
4085
4086 if ($is_space->{$self->{nc}}) {
4087 if ($self->{ct}->{type} == ATTLIST_TOKEN) {
4088 $self->{state} = DOCTYPE_ATTLIST_NAME_AFTER_STATE;
4089 } elsif ($self->{ct}->{type} == ELEMENT_TOKEN) {
4090 $self->{state} = AFTER_ELEMENT_NAME_STATE;
4091 } else { # ENTITY/NOTATION
4092 $self->{state} = AFTER_DOCTYPE_NAME_STATE;
4093 }
4094 !!!next-input-character;
4095 redo A;
4096 } elsif ($self->{nc} == 0x003E) { # >
4097 if ($self->{ct}->{type} == ATTLIST_TOKEN) {
4098 #
4099 } else {
4100 !!!parse-error (type => 'no md def'); ## TODO: type
4101 }
4102 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4103 !!!next-input-character;
4104 !!!emit ($self->{ct}); # ELEMENT/ENTITY/ATTLIST/NOTATION
4105 redo A;
4106 } elsif ($self->{nc} == -1) {
4107 ## XML5: [ATTLIST] No parse error.
4108 !!!parse-error (type => 'unclosed md');
4109 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4110 ## Reconsume.
4111 !!!emit ($self->{ct}); # ELEMENT/ENTITY/ATTLIST/NOTATION
4112 redo A;
4113 } else {
4114 ## XML5: [ATTLIST] Not defined yet.
4115 $self->{ct}->{name} .= chr $self->{nc};
4116 ## Stay in the state.
4117 !!!next-input-character;
4118 redo A;
4119 }
4120 } elsif ($self->{state} == DOCTYPE_ATTLIST_NAME_AFTER_STATE) {
4121 if ($is_space->{$self->{nc}}) {
4122 ## Stay in the state.
4123 !!!next-input-character;
4124 redo A;
4125 } elsif ($self->{nc} == 0x003E) { # >
4126 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4127 !!!next-input-character;
4128 !!!emit ($self->{ct}); # ATTLIST
4129 redo A;
4130 } elsif ($self->{nc} == -1) {
4131 ## XML5: No parse error.
4132 !!!parse-error (type => 'unclosed md'); ## TODO: type
4133 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4134 !!!emit ($self->{ct});
4135 redo A;
4136 } else {
4137 ## XML5: Not defined yet.
4138 $self->{ca} = {name => chr ($self->{nc}), # attrdef
4139 tokens => [],
4140 line => $self->{line}, column => $self->{column}};
4141 $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_NAME_STATE;
4142 !!!next-input-character;
4143 redo A;
4144 }
4145 } elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_NAME_STATE) {
4146 if ($is_space->{$self->{nc}}) {
4147 $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_NAME_AFTER_STATE;
4148 !!!next-input-character;
4149 redo A;
4150 } elsif ($self->{nc} == 0x003E) { # >
4151 ## XML5: Same as "anything else".
4152 !!!parse-error (type => 'no attr type'); ## TODO: type
4153 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4154 !!!next-input-character;
4155 !!!emit ($self->{ct}); # ATTLIST
4156 redo A;
4157 } elsif ($self->{nc} == 0x0028) { # (
4158 ## XML5: Same as "anything else".
4159 !!!parse-error (type => 'no space before paren'); ## TODO: type
4160 $self->{state} = BEFORE_ALLOWED_TOKEN_STATE;
4161 !!!next-input-character;
4162 redo A;
4163 } elsif ($self->{nc} == -1) {
4164 ## XML5: No parse error.
4165 !!!parse-error (type => 'unclosed md'); ## TODO: type
4166 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4167 !!!next-input-character;
4168 !!!emit ($self->{ct}); # ATTLIST
4169 redo A;
4170 } else {
4171 ## XML5: Not defined yet.
4172 $self->{ca}->{name} .= chr $self->{nc};
4173 ## Stay in the state.
4174 !!!next-input-character;
4175 redo A;
4176 }
4177 } elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_NAME_AFTER_STATE) {
4178 if ($is_space->{$self->{nc}}) {
4179 ## Stay in the state.
4180 !!!next-input-character;
4181 redo A;
4182 } elsif ($self->{nc} == 0x003E) { # >
4183 ## XML5: Same as "anything else".
4184 !!!parse-error (type => 'no attr type'); ## TODO: type
4185 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4186 !!!next-input-character;
4187 !!!emit ($self->{ct}); # ATTLIST
4188 redo A;
4189 } elsif ($self->{nc} == 0x0028) { # (
4190 ## XML5: Same as "anything else".
4191 $self->{state} = BEFORE_ALLOWED_TOKEN_STATE;
4192 !!!next-input-character;
4193 redo A;
4194 } elsif ($self->{nc} == -1) {
4195 ## XML5: No parse error.
4196 !!!parse-error (type => 'unclosed md'); ## TODO: type
4197 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4198 !!!next-input-character;
4199 !!!emit ($self->{ct});
4200 redo A;
4201 } else {
4202 ## XML5: Not defined yet.
4203 $self->{ca}->{type} = chr $self->{nc};
4204 $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_TYPE_STATE;
4205 !!!next-input-character;
4206 redo A;
4207 }
4208 } elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_TYPE_STATE) {
4209 if ($is_space->{$self->{nc}}) {
4210 $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_TYPE_AFTER_STATE;
4211 !!!next-input-character;
4212 redo A;
4213 } elsif ($self->{nc} == 0x0023) { # #
4214 ## XML5: Same as "anything else".
4215 !!!parse-error (type => 'no space before default value'); ## TODO: type
4216 $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE;
4217 !!!next-input-character;
4218 redo A;
4219 } elsif ($self->{nc} == 0x0022) { # "
4220 ## XML5: Same as "anything else".
4221 !!!parse-error (type => 'no space before default value'); ## TODO: type
4222 $self->{ca}->{value} = '';
4223 $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
4224 !!!next-input-character;
4225 redo A;
4226 } elsif ($self->{nc} == 0x0027) { # '
4227 ## XML5: Same as "anything else".
4228 !!!parse-error (type => 'no space before default value'); ## TODO: type
4229 $self->{ca}->{value} = '';
4230 $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
4231 !!!next-input-character;
4232 redo A;
4233 } elsif ($self->{nc} == 0x003E) { # >
4234 ## XML5: Same as "anything else".
4235 !!!parse-error (type => 'no attr default'); ## TODO: type
4236 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4237 !!!next-input-character;
4238 !!!emit ($self->{ct}); # ATTLIST
4239 redo A;
4240 } elsif ($self->{nc} == 0x0028) { # (
4241 ## XML5: Same as "anything else".
4242 !!!parse-error (type => 'no space before paren'); ## TODO: type
4243 $self->{state} = BEFORE_ALLOWED_TOKEN_STATE;
4244 !!!next-input-character;
4245 redo A;
4246 } elsif ($self->{nc} == -1) {
4247 ## XML5: No parse error.
4248 !!!parse-error (type => 'unclosed md'); ## TODO: type
4249 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4250 !!!next-input-character;
4251 !!!emit ($self->{ct});
4252 redo A;
4253 } else {
4254 ## XML5: Not defined yet.
4255 $self->{ca}->{type} .= chr $self->{nc};
4256 ## Stay in the state.
4257 !!!next-input-character;
4258 redo A;
4259 }
4260 } elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_TYPE_AFTER_STATE) {
4261 if ($is_space->{$self->{nc}}) {
4262 ## Stay in the state.
4263 !!!next-input-character;
4264 redo A;
4265 } elsif ($self->{nc} == 0x0028) { # (
4266 ## XML5: Same as "anything else".
4267 $self->{state} = BEFORE_ALLOWED_TOKEN_STATE;
4268 !!!next-input-character;
4269 redo A;
4270 } elsif ($self->{nc} == 0x0023) { # #
4271 $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE;
4272 !!!next-input-character;
4273 redo A;
4274 } elsif ($self->{nc} == 0x0022) { # "
4275 ## XML5: Same as "anything else".
4276 $self->{ca}->{value} = '';
4277 $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
4278 !!!next-input-character;
4279 redo A;
4280 } elsif ($self->{nc} == 0x0027) { # '
4281 ## XML5: Same as "anything else".
4282 $self->{ca}->{value} = '';
4283 $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
4284 !!!next-input-character;
4285 redo A;
4286 } elsif ($self->{nc} == 0x003E) { # >
4287 ## XML5: Same as "anything else".
4288 !!!parse-error (type => 'no attr default'); ## TODO: type
4289 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4290 !!!next-input-character;
4291 !!!emit ($self->{ct}); # ATTLIST
4292 redo A;
4293 } elsif ($self->{nc} == -1) {
4294 ## XML5: No parse error.
4295 !!!parse-error (type => 'unclosed md'); ## TODO: type
4296 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4297 !!!next-input-character;
4298 !!!emit ($self->{ct});
4299 redo A;
4300 } else {
4301 ## XML5: Switch to the "DOCTYPE bogus comment state".
4302 !!!parse-error (type => 'unquoted attr value'); ## TODO: type
4303 $self->{ca}->{value} = '';
4304 $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
4305 ## Reconsume.
4306 redo A;
4307 }
4308 } elsif ($self->{state} == BEFORE_ALLOWED_TOKEN_STATE) {
4309 if ($is_space->{$self->{nc}}) {
4310 ## Stay in the state.
4311 !!!next-input-character;
4312 redo A;
4313 } elsif ($self->{nc} == 0x007C) { # |
4314 !!!parse-error (type => 'empty allowed token'); ## TODO: type
4315 ## Stay in the state.
4316 !!!next-input-character;
4317 redo A;
4318 } elsif ($self->{nc} == 0x0029) { # )
4319 !!!parse-error (type => 'empty allowed token'); ## TODO: type
4320 $self->{state} = AFTER_ALLOWED_TOKENS_STATE;
4321 !!!next-input-character;
4322 redo A;
4323 } elsif ($self->{nc} == 0x003E) { # >
4324 !!!parse-error (type => 'unclosed allowed tokens'); ## TODO: type
4325 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4326 !!!next-input-character;
4327 !!!emit ($self->{ct}); # ATTLIST
4328 redo A;
4329 } elsif ($self->{nc} == -1) {
4330 ## XML5: No parse error.
4331 !!!parse-error (type => 'unclosed md'); ## TODO: type
4332 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4333 !!!next-input-character;
4334 !!!emit ($self->{ct});
4335 redo A;
4336 } else {
4337 push @{$self->{ca}->{tokens}}, chr $self->{nc};
4338 $self->{state} = ALLOWED_TOKEN_STATE;
4339 !!!next-input-character;
4340 redo A;
4341 }
4342 } elsif ($self->{state} == ALLOWED_TOKEN_STATE) {
4343 if ($is_space->{$self->{nc}}) {
4344 $self->{state} = AFTER_ALLOWED_TOKEN_STATE;
4345 !!!next-input-character;
4346 redo A;
4347 } elsif ($self->{nc} == 0x007C) { # |
4348 $self->{state} = BEFORE_ALLOWED_TOKEN_STATE;
4349 !!!next-input-character;
4350 redo A;
4351 } elsif ($self->{nc} == 0x0029) { # )
4352 $self->{state} = AFTER_ALLOWED_TOKENS_STATE;
4353 !!!next-input-character;
4354 redo A;
4355 } elsif ($self->{nc} == 0x003E) { # >
4356 !!!parse-error (type => 'unclosed allowed tokens'); ## TODO: type
4357 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4358 !!!next-input-character;
4359 !!!emit ($self->{ct}); # ATTLIST
4360 redo A;
4361 } elsif ($self->{nc} == -1) {
4362 ## XML5: No parse error.
4363 !!!parse-error (type => 'unclosed md'); ## TODO: type
4364 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4365 !!!next-input-character;
4366 !!!emit ($self->{ct});
4367 redo A;
4368 } else {
4369 $self->{ca}->{tokens}->[-1] .= chr $self->{nc};
4370 ## Stay in the state.
4371 !!!next-input-character;
4372 redo A;
4373 }
4374 } elsif ($self->{state} == AFTER_ALLOWED_TOKEN_STATE) {
4375 if ($is_space->{$self->{nc}}) {
4376 ## Stay in the state.
4377 !!!next-input-character;
4378 redo A;
4379 } elsif ($self->{nc} == 0x007C) { # |
4380 $self->{state} = BEFORE_ALLOWED_TOKEN_STATE;
4381 !!!next-input-character;
4382 redo A;
4383 } elsif ($self->{nc} == 0x0029) { # )
4384 $self->{state} = AFTER_ALLOWED_TOKENS_STATE;
4385 !!!next-input-character;
4386 redo A;
4387 } elsif ($self->{nc} == 0x003E) { # >
4388 !!!parse-error (type => 'unclosed allowed tokens'); ## TODO: type
4389 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4390 !!!next-input-character;
4391 !!!emit ($self->{ct}); # ATTLIST
4392 redo A;
4393 } elsif ($self->{nc} == -1) {
4394 ## XML5: No parse error.
4395 !!!parse-error (type => 'unclosed md'); ## TODO: type
4396 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4397 !!!next-input-character;
4398 !!!emit ($self->{ct});
4399 redo A;
4400 } else {
4401 !!!parse-error (type => 'space in allowed token', ## TODO: type
4402 line => $self->{line_prev},
4403 column => $self->{column_prev});
4404 $self->{ca}->{tokens}->[-1] .= ' ' . chr $self->{nc};
4405 $self->{state} = ALLOWED_TOKEN_STATE;
4406 !!!next-input-character;
4407 redo A;
4408 }
4409 } elsif ($self->{state} == AFTER_ALLOWED_TOKENS_STATE) {
4410 if ($is_space->{$self->{nc}}) {
4411 $self->{state} = BEFORE_ATTR_DEFAULT_STATE;
4412 !!!next-input-character;
4413 redo A;
4414 } elsif ($self->{nc} == 0x0023) { # #
4415 !!!parse-error (type => 'no space before default value'); ## TODO: type
4416 $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE;
4417 !!!next-input-character;
4418 redo A;
4419 } elsif ($self->{nc} == 0x0022) { # "
4420 !!!parse-error (type => 'no space before default value'); ## TODO: type
4421 $self->{ca}->{value} = '';
4422 $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
4423 !!!next-input-character;
4424 redo A;
4425 } elsif ($self->{nc} == 0x0027) { # '
4426 !!!parse-error (type => 'no space before default value'); ## TODO: type
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} == BEFORE_ATTR_DEFAULT_STATE) {
4450 if ($is_space->{$self->{nc}}) {
4451 ## Stay in the state.
4452 !!!next-input-character;
4453 redo A;
4454 } elsif ($self->{nc} == 0x0023) { # #
4455 $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE;
4456 !!!next-input-character;
4457 redo A;
4458 } elsif ($self->{nc} == 0x0022) { # "
4459 $self->{ca}->{value} = '';
4460 $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
4461 !!!next-input-character;
4462 redo A;
4463 } elsif ($self->{nc} == 0x0027) { # '
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 !!!parse-error (type => 'no attr default'); ## TODO: type
4470 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4471 !!!next-input-character;
4472 !!!emit ($self->{ct}); # ATTLIST
4473 redo A;
4474 } elsif ($self->{nc} == -1) {
4475 !!!parse-error (type => 'unclosed md'); ## TODO: type
4476 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4477 !!!next-input-character;
4478 !!!emit ($self->{ct});
4479 redo A;
4480 } else {
4481 !!!parse-error (type => 'unquoted attr value'); ## TODO: type
4482 $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
4483 ## Reconsume.
4484 redo A;
4485 }
4486 } elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE) {
4487 if ($is_space->{$self->{nc}}) {
4488 ## XML5: No parse error.
4489 !!!parse-error (type => 'no default type'); ## TODO: type
4490 $self->{state} = BOGUS_MD_STATE;
4491 ## Reconsume.
4492 redo A;
4493 } elsif ($self->{nc} == 0x0022) { # "
4494 ## XML5: Same as "anything else".
4495 $self->{ca}->{value} = '';
4496 $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
4497 !!!next-input-character;
4498 redo A;
4499 } elsif ($self->{nc} == 0x0027) { # '
4500 ## XML5: Same as "anything else".
4501 $self->{ca}->{value} = '';
4502 $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
4503 !!!next-input-character;
4504 redo A;
4505 } elsif ($self->{nc} == 0x003E) { # >
4506 ## XML5: Same as "anything else".
4507 !!!parse-error (type => 'no attr default'); ## TODO: type
4508 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4509 !!!next-input-character;
4510 !!!emit ($self->{ct}); # ATTLIST
4511 redo A;
4512 } elsif ($self->{nc} == -1) {
4513 ## XML5: No parse error.
4514 !!!parse-error (type => 'unclosed md'); ## TODO: type
4515 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4516 !!!next-input-character;
4517 !!!emit ($self->{ct});
4518 redo A;
4519 } else {
4520 $self->{ca}->{default} = chr $self->{nc};
4521 $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_STATE;
4522 !!!next-input-character;
4523 redo A;
4524 }
4525 } elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_STATE) {
4526 if ($is_space->{$self->{nc}}) {
4527 $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_AFTER_STATE;
4528 !!!next-input-character;
4529 redo A;
4530 } elsif ($self->{nc} == 0x0022) { # "
4531 ## XML5: Same as "anything else".
4532 !!!parse-error (type => 'no space before default value'); ## TODO: type
4533 $self->{ca}->{value} = '';
4534 $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
4535 !!!next-input-character;
4536 redo A;
4537 } elsif ($self->{nc} == 0x0027) { # '
4538 ## XML5: Same as "anything else".
4539 !!!parse-error (type => 'no space before default value'); ## TODO: type
4540 $self->{ca}->{value} = '';
4541 $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
4542 !!!next-input-character;
4543 redo A;
4544 } elsif ($self->{nc} == 0x003E) { # >
4545 ## XML5: Same as "anything else".
4546 push @{$self->{ct}->{attrdefs}}, $self->{ca};
4547 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4548 !!!next-input-character;
4549 !!!emit ($self->{ct}); # ATTLIST
4550 redo A;
4551 } elsif ($self->{nc} == -1) {
4552 ## XML5: No parse error.
4553 !!!parse-error (type => 'unclosed md'); ## TODO: type
4554 push @{$self->{ct}->{attrdefs}}, $self->{ca};
4555 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4556 !!!next-input-character;
4557 !!!emit ($self->{ct});
4558 redo A;
4559 } else {
4560 $self->{ca}->{default} .= chr $self->{nc};
4561 ## Stay in the state.
4562 !!!next-input-character;
4563 redo A;
4564 }
4565 } elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_AFTER_STATE) {
4566 if ($is_space->{$self->{nc}}) {
4567 ## Stay in the state.
4568 !!!next-input-character;
4569 redo A;
4570 } elsif ($self->{nc} == 0x0022) { # "
4571 $self->{ca}->{value} = '';
4572 $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
4573 !!!next-input-character;
4574 redo A;
4575 } elsif ($self->{nc} == 0x0027) { # '
4576 $self->{ca}->{value} = '';
4577 $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
4578 !!!next-input-character;
4579 redo A;
4580 } elsif ($self->{nc} == 0x003E) { # >
4581 push @{$self->{ct}->{attrdefs}}, $self->{ca};
4582 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4583 !!!next-input-character;
4584 !!!emit ($self->{ct}); # ATTLIST
4585 redo A;
4586 } elsif ($self->{nc} == -1) {
4587 ## XML5: No parse error.
4588 !!!parse-error (type => 'unclosed md'); ## TODO: type
4589 push @{$self->{ct}->{attrdefs}}, $self->{ca};
4590 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4591 !!!next-input-character;
4592 !!!emit ($self->{ct});
4593 redo A;
4594 } else {
4595 ## XML5: Not defined yet.
4596 if ($self->{ca}->{default} eq 'FIXED') {
4597 $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
4598 } else {
4599 push @{$self->{ct}->{attrdefs}}, $self->{ca};
4600 $self->{state} = DOCTYPE_ATTLIST_NAME_AFTER_STATE;
4601 }
4602 ## Reconsume.
4603 redo A;
4604 }
4605 } elsif ($self->{state} == AFTER_ATTLIST_ATTR_VALUE_QUOTED_STATE) {
4606 if ($is_space->{$self->{nc}} or
4607 $self->{nc} == -1 or
4608 $self->{nc} == 0x003E) { # >
4609 $self->{state} = DOCTYPE_ATTLIST_NAME_AFTER_STATE;
4610 ## Reconsume.
4611 redo A;
4612 } else {
4613 !!!parse-error (type => 'no space before attr name'); ## TODO: type
4614 $self->{state} = DOCTYPE_ATTLIST_NAME_AFTER_STATE;
4615 ## Reconsume.
4616 redo A;
4617 }
4618 } elsif ($self->{state} == NDATA_STATE) {
4619 ## ASCII case-insensitive
4620 if ($self->{nc} == [
4621 undef,
4622 0x0044, # D
4623 0x0041, # A
4624 0x0054, # T
4625 ]->[length $self->{kwd}] or
4626 $self->{nc} == [
4627 undef,
4628 0x0064, # d
4629 0x0061, # a
4630 0x0074, # t
4631 ]->[length $self->{kwd}]) {
4632 !!!cp (172.2);
4633 ## Stay in the state.
4634 $self->{kwd} .= chr $self->{nc};
4635 !!!next-input-character;
4636 redo A;
4637 } elsif ((length $self->{kwd}) == 4 and
4638 ($self->{nc} == 0x0041 or # A
4639 $self->{nc} == 0x0061)) { # a
4640 if ($self->{kwd} ne 'NDAT' or $self->{nc} == 0x0061) { # a
4641 !!!cp (172.3);
4642 !!!parse-error (type => 'lowercase keyword', ## TODO: type
4643 text => 'NDATA',
4644 line => $self->{line_prev},
4645 column => $self->{column_prev} - 4);
4646 } else {
4647 !!!cp (172.4);
4648 }
4649 $self->{state} = AFTER_NDATA_STATE;
4650 !!!next-input-character;
4651 redo A;
4652 } else {
4653 !!!parse-error (type => 'string after literal', ## TODO: type
4654 line => $self->{line_prev},
4655 column => $self->{column_prev} + 1
4656 - length $self->{kwd});
4657 !!!cp (172.5);
4658 $self->{state} = BOGUS_MD_STATE;
4659 ## Reconsume.
4660 redo A;
4661 }
4662 } elsif ($self->{state} == AFTER_NDATA_STATE) {
4663 if ($is_space->{$self->{nc}}) {
4664 $self->{state} = BEFORE_NOTATION_NAME_STATE;
4665 !!!next-input-character;
4666 redo A;
4667 } elsif ($self->{nc} == 0x003E) { # >
4668 !!!parse-error (type => 'no notation name'); ## TODO: type
4669 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4670 !!!next-input-character;
4671 !!!emit ($self->{ct}); # ENTITY
4672 redo A;
4673 } elsif ($self->{nc} == -1) {
4674 !!!parse-error (type => 'unclosed md'); ## TODO: type
4675 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4676 !!!next-input-character;
4677 !!!emit ($self->{ct}); # ENTITY
4678 redo A;
4679 } else {
4680 !!!parse-error (type => 'string after literal', ## TODO: type
4681 line => $self->{line_prev},
4682 column => $self->{column_prev} + 1
4683 - length $self->{kwd});
4684 $self->{state} = BOGUS_MD_STATE;
4685 ## Reconsume.
4686 redo A;
4687 }
4688 } elsif ($self->{state} == BEFORE_NOTATION_NAME_STATE) {
4689 if ($is_space->{$self->{nc}}) {
4690 ## Stay in the state.
4691 !!!next-input-character;
4692 redo A;
4693 } elsif ($self->{nc} == 0x003E) { # >
4694 !!!parse-error (type => 'no notation name'); ## TODO: type
4695 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4696 !!!next-input-character;
4697 !!!emit ($self->{ct}); # ENTITY
4698 redo A;
4699 } elsif ($self->{nc} == -1) {
4700 !!!parse-error (type => 'unclosed md'); ## TODO: type
4701 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4702 !!!next-input-character;
4703 !!!emit ($self->{ct}); # ENTITY
4704 redo A;
4705 } else {
4706 $self->{ct}->{notation} = chr $self->{nc}; # ENTITY
4707 $self->{state} = NOTATION_NAME_STATE;
4708 !!!next-input-character;
4709 redo A;
4710 }
4711 } elsif ($self->{state} == NOTATION_NAME_STATE) {
4712 if ($is_space->{$self->{nc}}) {
4713 $self->{state} = AFTER_MD_DEF_STATE;
4714 !!!next-input-character;
4715 redo A;
4716 } elsif ($self->{nc} == 0x003E) { # >
4717 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4718 !!!next-input-character;
4719 !!!emit ($self->{ct}); # ENTITY
4720 redo A;
4721 } elsif ($self->{nc} == -1) {
4722 !!!parse-error (type => 'unclosed md'); ## TODO: type
4723 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4724 !!!next-input-character;
4725 !!!emit ($self->{ct}); # ENTITY
4726 redo A;
4727 } else {
4728 $self->{ct}->{notation} .= chr $self->{nc}; # ENTITY
4729 ## Stay in the state.
4730 !!!next-input-character;
4731 redo A;
4732 }
4733 } elsif ($self->{state} == DOCTYPE_ENTITY_VALUE_DOUBLE_QUOTED_STATE) {
4734 if ($self->{nc} == 0x0022) { # "
4735 $self->{state} = AFTER_MD_DEF_STATE;
4736 !!!next-input-character;
4737 redo A;
4738 } elsif ($self->{nc} == 0x0026) { # &
4739 $self->{prev_state} = $self->{state};
4740 $self->{state} = ENTITY_VALUE_ENTITY_STATE;
4741 $self->{entity_add} = 0x0022; # "
4742 !!!next-input-character;
4743 redo A;
4744 ## TODO: %
4745 } elsif ($self->{nc} == -1) {
4746 !!!parse-error (type => 'unclosed entity value'); ## TODO: type
4747 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4748 ## Reconsume.
4749 !!!emit ($self->{ct}); # ENTITY
4750 redo A;
4751 } else {
4752 $self->{ct}->{value} .= chr $self->{nc}; # ENTITY
4753 !!!next-input-character;
4754 redo A;
4755 }
4756 } elsif ($self->{state} == DOCTYPE_ENTITY_VALUE_SINGLE_QUOTED_STATE) {
4757 if ($self->{nc} == 0x0027) { # '
4758 $self->{state} = AFTER_MD_DEF_STATE;
4759 !!!next-input-character;
4760 redo A;
4761 } elsif ($self->{nc} == 0x0026) { # &
4762 $self->{prev_state} = $self->{state};
4763 $self->{state} = ENTITY_VALUE_ENTITY_STATE;
4764 $self->{entity_add} = 0x0027; # '
4765 !!!next-input-character;
4766 redo A;
4767 ## TODO: %
4768 } elsif ($self->{nc} == -1) {
4769 !!!parse-error (type => 'unclosed entity value'); ## TODO: type
4770 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4771 ## Reconsume.
4772 !!!emit ($self->{ct}); # ENTITY
4773 redo A;
4774 } else {
4775 $self->{ct}->{value} .= chr $self->{nc}; # ENTITY
4776 !!!next-input-character;
4777 redo A;
4778 }
4779 } elsif ($self->{state} == ENTITY_VALUE_ENTITY_STATE) {
4780 ## TODO: XMLize
4781
4782 if ($is_space->{$self->{nc}} or
4783 {
4784 0x003C => 1, 0x0026 => 1, -1 => 1, # <, &
4785 $self->{entity_add} => 1,
4786 }->{$self->{nc}}) {
4787 ## Don't consume
4788 ## No error
4789 ## Return nothing.
4790 #
4791 } elsif ($self->{nc} == 0x0023) { # #
4792 $self->{ca} = $self->{ct};
4793 $self->{state} = ENTITY_HASH_STATE;
4794 $self->{kwd} = '#';
4795 !!!next-input-character;
4796 redo A;
4797 } elsif ((0x0041 <= $self->{nc} and
4798 $self->{nc} <= 0x005A) or # A..Z
4799 (0x0061 <= $self->{nc} and
4800 $self->{nc} <= 0x007A)) { # a..z
4801 #
4802 } else {
4803 !!!parse-error (type => 'bare ero');
4804 ## Return nothing.
4805 #
4806 }
4807
4808 $self->{ct}->{value} .= '&';
4809 $self->{state} = $self->{prev_state};
4810 ## Reconsume.
4811 redo A;
4812 } elsif ($self->{state} == AFTER_ELEMENT_NAME_STATE) {
4813 if ($is_space->{$self->{nc}}) {
4814 $self->{state} = BEFORE_ELEMENT_CONTENT_STATE;
4815 !!!next-input-character;
4816 redo A;
4817 } elsif ($self->{nc} == 0x0028) { # (
4818 $self->{state} = AFTER_CM_GROUP_OPEN_STATE;
4819 $self->{ct}->{content} = ['('];
4820 $self->{group_depth} = 1;
4821 !!!next-input-character;
4822 redo A;
4823 } elsif ($self->{nc} == 0x003E) { # >
4824 !!!parse-error (type => 'no md def'); ## TODO: type
4825 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4826 !!!next-input-character;
4827 !!!emit ($self->{ct}); # ELEMENT
4828 redo A;
4829 } elsif ($self->{nc} == -1) {
4830 !!!parse-error (type => 'unclosed md'); ## TODO: type
4831 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4832 !!!next-input-character;
4833 !!!emit ($self->{ct}); # ELEMENT
4834 redo A;
4835 } else {
4836 $self->{ct}->{content} = [chr $self->{nc}];
4837 $self->{state} = CONTENT_KEYWORD_STATE;
4838 !!!next-input-character;
4839 redo A;
4840 }
4841 } elsif ($self->{state} == CONTENT_KEYWORD_STATE) {
4842 if ($is_space->{$self->{nc}}) {
4843 $self->{state} = AFTER_MD_DEF_STATE;
4844 !!!next-input-character;
4845 redo A;
4846 } elsif ($self->{nc} == 0x003E) { # >
4847 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4848 !!!next-input-character;
4849 !!!emit ($self->{ct}); # ELEMENT
4850 redo A;
4851 } elsif ($self->{nc} == -1) {
4852 !!!parse-error (type => 'unclosed md'); ## TODO: type
4853 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4854 !!!next-input-character;
4855 !!!emit ($self->{ct}); # ELEMENT
4856 redo A;
4857 } else {
4858 $self->{ct}->{content}->[-1] .= chr $self->{nc}; # ELEMENT
4859 ## Stay in the state.
4860 !!!next-input-character;
4861 redo A;
4862 }
4863 } elsif ($self->{state} == AFTER_CM_GROUP_OPEN_STATE) {
4864 if ($is_space->{$self->{nc}}) {
4865 ## Stay in the state.
4866 !!!next-input-character;
4867 redo A;
4868 } elsif ($self->{nc} == 0x0028) { # (
4869 $self->{group_depth}++;
4870 push @{$self->{ct}->{content}}, chr $self->{nc};
4871 ## Stay in the state.
4872 !!!next-input-character;
4873 redo A;
4874 } elsif ($self->{nc} == 0x007C or # |
4875 $self->{nc} == 0x002C) { # ,
4876 !!!parse-error (type => 'empty element name'); ## TODO: type
4877 ## Stay in the state.
4878 !!!next-input-character;
4879 redo A;
4880 } elsif ($self->{nc} == 0x0029) { # )
4881 !!!parse-error (type => 'empty element name'); ## TODO: type
4882 push @{$self->{ct}->{content}}, chr $self->{nc};
4883 $self->{group_depth}--;
4884 $self->{state} = AFTER_CM_GROUP_CLOSE_STATE;
4885 !!!next-input-character;
4886 redo A;
4887 } elsif ($self->{nc} == 0x003E) { # >
4888 !!!parse-error (type => 'unclosed cm group'); ## TODO: type
4889 push @{$self->{ct}->{content}}, (')') x $self->{group_depth};
4890 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4891 !!!next-input-character;
4892 !!!emit ($self->{ct}); # ELEMENT
4893 redo A;
4894 } elsif ($self->{nc} == -1) {
4895 !!!parse-error (type => 'unclosed md'); ## 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 } else {
4902 push @{$self->{ct}->{content}}, chr $self->{nc};
4903 $self->{state} = CM_ELEMENT_NAME_STATE;
4904 !!!next-input-character;
4905 redo A;
4906 }
4907 } elsif ($self->{state} == CM_ELEMENT_NAME_STATE) {
4908 if ($is_space->{$self->{nc}}) {
4909 $self->{state} = AFTER_CM_ELEMENT_NAME_STATE;
4910 !!!next-input-character;
4911 redo A;
4912 } elsif ($self->{nc} == 0x002A or # *
4913 $self->{nc} == 0x002B or # +
4914 $self->{nc} == 0x003F) { # ?
4915 push @{$self->{ct}->{content}}, chr $self->{nc};
4916 $self->{state} = AFTER_CM_ELEMENT_NAME_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 $self->{ct}->{content}->[-1] .= chr $self->{nc};
4947 ## Stay in the state.
4948 !!!next-input-character;
4949 redo A;
4950 }
4951 } elsif ($self->{state} == AFTER_CM_ELEMENT_NAME_STATE) {
4952 if ($is_space->{$self->{nc}}) {
4953 ## Stay in the state.
4954 !!!next-input-character;
4955 redo A;
4956 } elsif ($self->{nc} == 0x007C or # |
4957 $self->{nc} == 0x002C) { # ,
4958 push @{$self->{ct}->{content}}, $self->{nc} == 0x007C ? ' | ' : ', ';
4959 $self->{state} = AFTER_CM_GROUP_OPEN_STATE;
4960 !!!next-input-character;
4961 redo A;
4962 } elsif ($self->{nc} == 0x0029) { # )
4963 $self->{group_depth}--;
4964 push @{$self->{ct}->{content}}, chr $self->{nc};
4965 $self->{state} = AFTER_CM_GROUP_CLOSE_STATE;
4966 !!!next-input-character;
4967 redo A;
4968 } elsif ($self->{nc} == 0x003E) { # >
4969 !!!parse-error (type => 'unclosed cm group'); ## TODO: type
4970 push @{$self->{ct}->{content}}, (')') x $self->{group_depth};
4971 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4972 !!!next-input-character;
4973 !!!emit ($self->{ct}); # ELEMENT
4974 redo A;
4975 } elsif ($self->{nc} == -1) {
4976 !!!parse-error (type => 'unclosed md'); ## TODO: type
4977 push @{$self->{ct}->{content}}, (')') x $self->{group_depth};
4978 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4979 !!!next-input-character;
4980 !!!emit ($self->{ct}); # ELEMENT
4981 redo A;
4982 } else {
4983 !!!parse-error (type => 'after element name'); ## TODO: type
4984 push @{$self->{ct}->{content}}, (')') x $self->{group_depth};
4985 $self->{state} = BOGUS_MD_STATE;
4986 !!!next-input-character;
4987 redo A;
4988 }
4989 } elsif ($self->{state} == AFTER_CM_GROUP_CLOSE_STATE) {
4990 if ($is_space->{$self->{nc}}) {
4991 if ($self->{group_depth}) {
4992 $self->{state} = AFTER_CM_ELEMENT_NAME_STATE;
4993 } else {
4994 $self->{state} = AFTER_MD_DEF_STATE;
4995 }
4996 !!!next-input-character;
4997 redo A;
4998 } elsif ($self->{nc} == 0x002A or # *
4999 $self->{nc} == 0x002B or # +
5000 $self->{nc} == 0x003F) { # ?
5001 push @{$self->{ct}->{content}}, chr $self->{nc};
5002 if ($self->{group_depth}) {
5003 $self->{state} = AFTER_CM_ELEMENT_NAME_STATE;
5004 } else {
5005 $self->{state} = AFTER_MD_DEF_STATE;
5006 }
5007 !!!next-input-character;
5008 redo A;
5009 } elsif ($self->{nc} == 0x0029) { # )
5010 if ($self->{group_depth}) {
5011 $self->{group_depth}--;
5012 push @{$self->{ct}->{content}}, chr $self->{nc};
5013 ## Stay in the state.
5014 !!!next-input-character;
5015 redo A;
5016 } else {
5017 !!!parse-error (type => 'string after md def'); ## TODO: type
5018 $self->{state} = BOGUS_MD_STATE;
5019 ## Reconsume.
5020 redo A;
5021 }
5022 } elsif ($self->{nc} == 0x003E) { # >
5023 if ($self->{group_depth}) {
5024 !!!parse-error (type => 'unclosed cm group'); ## TODO: type
5025 push @{$self->{ct}->{content}}, (')') x $self->{group_depth};
5026 }
5027 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
5028 !!!next-input-character;
5029 !!!emit ($self->{ct}); # ELEMENT
5030 redo A;
5031 } elsif ($self->{nc} == -1) {
5032 !!!parse-error (type => 'unclosed md'); ## TODO: type
5033 push @{$self->{ct}->{content}}, (')') x $self->{group_depth};
5034 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
5035 !!!next-input-character;
5036 !!!emit ($self->{ct}); # ELEMENT
5037 redo A;
5038 } else {
5039 if ($self->{group_depth}) {
5040 $self->{state} = AFTER_CM_ELEMENT_NAME_STATE;
5041 } else {
5042 !!!parse-error (type => 'string after md def'); ## TODO: type
5043 $self->{state} = BOGUS_MD_STATE;
5044 }
5045 ## Reconsume.
5046 redo A;
5047 }
5048 } elsif ($self->{state} == AFTER_MD_DEF_STATE) {
5049 if ($is_space->{$self->{nc}}) {
5050 ## Stay in the state.
5051 !!!next-input-character;
5052 redo A;
5053 } elsif ($self->{nc} == 0x003E) { # >
5054 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
5055 !!!next-input-character;
5056 !!!emit ($self->{ct}); # ENTITY/ELEMENT
5057 redo A;
5058 } elsif ($self->{nc} == -1) {
5059 !!!parse-error (type => 'unclosed md'); ## TODO: type
5060 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
5061 !!!next-input-character;
5062 !!!emit ($self->{ct}); # ENTITY/ELEMENT
5063 redo A;
5064 } else {
5065 !!!parse-error (type => 'string after md def'); ## TODO: type
5066 $self->{state} = BOGUS_MD_STATE;
5067 ## Reconsume.
5068 redo A;
5069 }
5070 } elsif ($self->{state} == BOGUS_MD_STATE) {
5071 if ($self->{nc} == 0x003E) { # >
5072 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
5073 !!!next-input-character;
5074 !!!emit ($self->{ct}); # ATTLIST/ENTITY/NOTATION
5075 redo A;
5076 } elsif ($self->{nc} == -1) {
5077 $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
5078 ## Reconsume.
5079 !!!emit ($self->{ct}); # ATTLIST/ENTITY/NOTATION
5080 redo A;
5081 } else {
5082 ## Stay in the state.
5083 !!!next-input-character;
5084 redo A;
5085 }
5086 } else {
5087 die "$0: $self->{state}: Unknown state";
5088 }
5089 } # A
5090
5091 die "$0: _get_next_token: unexpected case";
5092 } # _get_next_token
5093
5094 1;
5095 ## $Date: 2008/10/19 08:20:29 $
5096

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24