1 |
wakaba |
1.1 |
package Whatpm::HTML::Tokenizer; |
2 |
|
|
use strict; |
3 |
wakaba |
1.20 |
our $VERSION=do{my @r=(q$Revision: 1.19 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
4 |
wakaba |
1.2 |
|
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 |
wakaba |
1.13 |
END_OF_DOCTYPE_TOKEN |
19 |
wakaba |
1.14 |
ATTLIST_TOKEN |
20 |
|
|
ELEMENT_TOKEN |
21 |
|
|
GENERAL_ENTITY_TOKEN |
22 |
|
|
PARAMETER_ENTITY_TOKEN |
23 |
|
|
NOTATION_TOKEN |
24 |
wakaba |
1.2 |
); |
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 |
wakaba |
1.13 |
END_OF_DOCTYPE_TOKEN |
37 |
wakaba |
1.14 |
ATTLIST_TOKEN |
38 |
|
|
ELEMENT_TOKEN |
39 |
|
|
GENERAL_ENTITY_TOKEN |
40 |
|
|
PARAMETER_ENTITY_TOKEN |
41 |
|
|
NOTATION_TOKEN |
42 |
wakaba |
1.2 |
)], |
43 |
|
|
); |
44 |
|
|
} |
45 |
|
|
|
46 |
wakaba |
1.12 |
## NOTE: Differences from the XML5 draft are marked as "XML5:". |
47 |
|
|
|
48 |
wakaba |
1.2 |
## Token types |
49 |
|
|
|
50 |
wakaba |
1.12 |
sub DOCTYPE_TOKEN () { 1 } ## XML5: No DOCTYPE token. |
51 |
wakaba |
1.2 |
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 |
wakaba |
1.12 |
sub PI_TOKEN () { 7 } ## NOTE: XML only. |
57 |
|
|
sub ABORT_TOKEN () { 8 } ## NOTE: For internal processing. |
58 |
wakaba |
1.14 |
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 |
wakaba |
1.12 |
|
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 |
wakaba |
1.1 |
|
73 |
|
|
package Whatpm::HTML; |
74 |
|
|
|
75 |
wakaba |
1.2 |
BEGIN { Whatpm::HTML::Tokenizer->import (':token') } |
76 |
|
|
|
77 |
wakaba |
1.1 |
## 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 |
wakaba |
1.12 |
## XML-only states |
146 |
wakaba |
1.8 |
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 |
wakaba |
1.12 |
sub DOCTYPE_INTERNAL_SUBSET_STATE () { 57 } |
153 |
|
|
sub DOCTYPE_INTERNAL_SUBSET_AFTER_STATE () { 58 } |
154 |
wakaba |
1.14 |
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 |
wakaba |
1.15 |
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 |
wakaba |
1.18 |
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 |
wakaba |
1.20 |
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 |
wakaba |
1.8 |
|
198 |
wakaba |
1.1 |
## 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 |
wakaba |
1.3 |
#$self->{is_xml} (if XML) |
260 |
wakaba |
1.1 |
|
261 |
|
|
$self->{state} = DATA_STATE; # MUST |
262 |
wakaba |
1.12 |
$self->{s_kwd} = ''; # Data state keyword |
263 |
|
|
#$self->{kwd} = ''; # State-dependent keyword; initialized when used |
264 |
wakaba |
1.1 |
#$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 |
wakaba |
1.11 |
## CHARACTER_TOKEN, END_OF_FILE_TOKEN, PI_TOKEN, or ABORT_TOKEN |
284 |
wakaba |
1.1 |
## ->{name} (DOCTYPE_TOKEN) |
285 |
|
|
## ->{tag_name} (START_TAG_TOKEN, END_TAG_TOKEN) |
286 |
wakaba |
1.11 |
## ->{target} (PI_TOKEN) |
287 |
wakaba |
1.1 |
## ->{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 |
wakaba |
1.11 |
## ->{index}: Index of the attribute in a tag. |
295 |
|
|
## ->{data} (COMMENT_TOKEN, CHARACTER_TOKEN, PI_TOKEN) |
296 |
wakaba |
1.7 |
## ->{has_reference} == 1 or 0 (CHARACTER_TOKEN) |
297 |
wakaba |
1.11 |
## ->{last_index} (ELEMENT_TOKEN): Next attribute's index - 1. |
298 |
wakaba |
1.12 |
## ->{has_internal_subset} = 1 or 0 (DOCTYPE_TOKEN) |
299 |
|
|
|
300 |
wakaba |
1.1 |
## 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 |
wakaba |
1.12 |
0x000C => 1, # FORM FEED (FF) ## XML5: Not a space character. |
320 |
wakaba |
1.1 |
#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 |
wakaba |
1.5 |
if ($self->{s_kwd} eq '<!-') { |
404 |
wakaba |
1.1 |
!!!cp (3); |
405 |
|
|
$self->{escape} = 1; # unless $self->{escape}; |
406 |
|
|
$self->{s_kwd} = '--'; |
407 |
|
|
# |
408 |
wakaba |
1.5 |
} elsif ($self->{s_kwd} eq '-') { |
409 |
wakaba |
1.1 |
!!!cp (4); |
410 |
|
|
$self->{s_kwd} = '--'; |
411 |
|
|
# |
412 |
wakaba |
1.5 |
} elsif ($self->{s_kwd} eq '<!' or $self->{s_kwd} eq '-') { |
413 |
|
|
!!!cp (4.1); |
414 |
|
|
$self->{s_kwd} .= '-'; |
415 |
|
|
# |
416 |
wakaba |
1.1 |
} else { |
417 |
|
|
!!!cp (5); |
418 |
wakaba |
1.5 |
$self->{s_kwd} = '-'; |
419 |
wakaba |
1.1 |
# |
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 |
wakaba |
1.5 |
# |
455 |
wakaba |
1.1 |
} else { |
456 |
|
|
!!!cp (9); |
457 |
wakaba |
1.5 |
# |
458 |
wakaba |
1.1 |
} |
459 |
wakaba |
1.5 |
} 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 |
wakaba |
1.1 |
} else { |
466 |
|
|
!!!cp (10); |
467 |
wakaba |
1.5 |
# |
468 |
wakaba |
1.1 |
} |
469 |
|
|
|
470 |
|
|
$self->{s_kwd} = ''; |
471 |
|
|
# |
472 |
wakaba |
1.5 |
} 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 |
wakaba |
1.1 |
} 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 |
wakaba |
1.5 |
if ($self->{read_until}->($token->{data}, q{-!<>&\]}, |
502 |
wakaba |
1.1 |
length $token->{data})) { |
503 |
|
|
$self->{s_kwd} = ''; |
504 |
|
|
} |
505 |
|
|
|
506 |
|
|
## Stay in the data state. |
507 |
wakaba |
1.5 |
if (not $self->{is_xml} and |
508 |
|
|
$self->{content_model} == PCDATA_CONTENT_MODEL) { |
509 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.10 |
## XML5: "tag state". |
520 |
|
|
|
521 |
wakaba |
1.1 |
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 |
wakaba |
1.12 |
$self->{s_kwd} = $self->{escaped} ? '' : '<'; |
530 |
wakaba |
1.1 |
# |
531 |
|
|
} else { |
532 |
|
|
!!!cp (16); |
533 |
wakaba |
1.12 |
$self->{s_kwd} = ''; |
534 |
wakaba |
1.1 |
# |
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 |
wakaba |
1.4 |
tag_name => chr ($self->{nc} + ($self->{is_xml} ? 0 : 0x0020)), |
561 |
wakaba |
1.1 |
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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
583 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.8 |
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 |
wakaba |
1.9 |
} elsif (not $self->{is_xml} or $is_space->{$self->{nc}}) { |
611 |
wakaba |
1.1 |
!!!cp (23); |
612 |
|
|
!!!parse-error (type => 'bare stago', |
613 |
|
|
line => $self->{line_prev}, |
614 |
|
|
column => $self->{column_prev}); |
615 |
|
|
$self->{state} = DATA_STATE; |
616 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
617 |
wakaba |
1.1 |
## reconsume |
618 |
|
|
|
619 |
|
|
!!!emit ({type => CHARACTER_TOKEN, data => '<', |
620 |
|
|
line => $self->{line_prev}, |
621 |
|
|
column => $self->{column_prev}, |
622 |
|
|
}); |
623 |
|
|
|
624 |
|
|
redo A; |
625 |
wakaba |
1.9 |
} 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 |
wakaba |
1.1 |
} |
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 |
wakaba |
1.10 |
## XML5: "end tag state". |
644 |
|
|
|
645 |
wakaba |
1.1 |
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 |
wakaba |
1.12 |
$self->{kwd} = ''; |
650 |
wakaba |
1.1 |
## 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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
658 |
wakaba |
1.1 |
## 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 |
wakaba |
1.4 |
tag_name => chr ($self->{nc} + ($self->{is_xml} ? 0 : 0x0020)), |
672 |
wakaba |
1.1 |
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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
691 |
wakaba |
1.10 |
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 |
wakaba |
1.1 |
redo A; |
711 |
|
|
} elsif ($self->{nc} == -1) { |
712 |
|
|
!!!cp (32); |
713 |
|
|
!!!parse-error (type => 'bare etago'); |
714 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
715 |
wakaba |
1.1 |
$self->{state} = DATA_STATE; |
716 |
|
|
# reconsume |
717 |
|
|
|
718 |
|
|
!!!emit ({type => CHARACTER_TOKEN, data => '</', |
719 |
|
|
line => $l, column => $c, |
720 |
|
|
}); |
721 |
|
|
|
722 |
|
|
redo A; |
723 |
wakaba |
1.10 |
} elsif (not $self->{is_xml} or |
724 |
|
|
$is_space->{$self->{nc}}) { |
725 |
wakaba |
1.1 |
!!!cp (33); |
726 |
wakaba |
1.10 |
!!!parse-error (type => 'bogus end tag', |
727 |
|
|
line => $self->{line_prev}, # "<" of "</" |
728 |
|
|
column => $self->{column_prev} - 1); |
729 |
wakaba |
1.1 |
$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 |
wakaba |
1.10 |
} 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 |
wakaba |
1.1 |
} |
751 |
|
|
} elsif ($self->{state} == CDATA_RCDATA_CLOSE_TAG_STATE) { |
752 |
wakaba |
1.12 |
my $ch = substr $self->{last_stag_name}, length $self->{kwd}, 1; |
753 |
wakaba |
1.1 |
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 |
wakaba |
1.12 |
$self->{kwd} .= $nch; |
761 |
wakaba |
1.1 |
!!!next-input-character; |
762 |
|
|
redo A; |
763 |
|
|
} else { |
764 |
|
|
!!!cp (25); |
765 |
|
|
$self->{state} = DATA_STATE; |
766 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
767 |
wakaba |
1.1 |
## Reconsume. |
768 |
|
|
!!!emit ({type => CHARACTER_TOKEN, |
769 |
wakaba |
1.12 |
data => '</' . $self->{kwd}, |
770 |
wakaba |
1.1 |
line => $self->{line_prev}, |
771 |
wakaba |
1.12 |
column => $self->{column_prev} - 1 - length $self->{kwd}, |
772 |
wakaba |
1.1 |
}); |
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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
786 |
wakaba |
1.1 |
!!!emit ({type => CHARACTER_TOKEN, |
787 |
wakaba |
1.12 |
data => '</' . $self->{kwd}, |
788 |
wakaba |
1.1 |
line => $self->{line_prev}, |
789 |
wakaba |
1.12 |
column => $self->{column_prev} - 1 - length $self->{kwd}, |
790 |
wakaba |
1.1 |
}); |
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 |
wakaba |
1.12 |
column => $self->{column_prev} - 1 - length $self->{kwd}}; |
799 |
wakaba |
1.1 |
$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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
828 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.4 |
$self->{ct}->{tag_name} |
837 |
|
|
.= chr ($self->{nc} + ($self->{is_xml} ? 0 : 0x0020)); |
838 |
wakaba |
1.1 |
# 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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
861 |
wakaba |
1.1 |
# 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 |
wakaba |
1.11 |
## XML5: "Tag attribute name before state". |
881 |
|
|
|
882 |
wakaba |
1.1 |
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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
904 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.4 |
= {name => chr ($self->{nc} + ($self->{is_xml} ? 0 : 0x0020)), |
914 |
wakaba |
1.1 |
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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
942 |
wakaba |
1.1 |
# 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 |
wakaba |
1.11 |
## XML5: Not a parse error. |
955 |
wakaba |
1.1 |
!!!parse-error (type => 'bad attribute name'); |
956 |
|
|
} else { |
957 |
|
|
!!!cp (56); |
958 |
wakaba |
1.11 |
## XML5: ":" raises a parse error and is ignored. |
959 |
wakaba |
1.1 |
} |
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 |
wakaba |
1.11 |
## XML5: "Tag attribute name state". |
970 |
|
|
|
971 |
wakaba |
1.1 |
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 |
wakaba |
1.11 |
$self->{ca}->{index} = ++$self->{ct}->{last_index}; |
982 |
wakaba |
1.1 |
} |
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 |
wakaba |
1.11 |
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 |
wakaba |
1.1 |
$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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
1021 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.4 |
$self->{ca}->{name} |
1030 |
|
|
.= chr ($self->{nc} + ($self->{is_xml} ? 0 : 0x0020)); |
1031 |
wakaba |
1.1 |
## Stay in the state |
1032 |
|
|
!!!next-input-character; |
1033 |
|
|
redo A; |
1034 |
|
|
} elsif ($self->{nc} == 0x002F) { # / |
1035 |
wakaba |
1.11 |
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 |
wakaba |
1.1 |
$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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
1067 |
wakaba |
1.1 |
# 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 |
wakaba |
1.11 |
## XML5: Not a parse error. |
1077 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.11 |
## XML5: "Tag attribute name after state". |
1088 |
|
|
|
1089 |
wakaba |
1.1 |
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 |
wakaba |
1.11 |
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 |
wakaba |
1.1 |
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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
1125 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.4 |
= {name => chr ($self->{nc} + ($self->{is_xml} ? 0 : 0x0020)), |
1135 |
wakaba |
1.1 |
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 |
wakaba |
1.11 |
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 |
wakaba |
1.1 |
$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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
1170 |
wakaba |
1.1 |
$self->{state} = DATA_STATE; |
1171 |
|
|
# reconsume |
1172 |
|
|
|
1173 |
|
|
!!!emit ($self->{ct}); # start tag or end tag |
1174 |
|
|
|
1175 |
|
|
redo A; |
1176 |
|
|
} else { |
1177 |
wakaba |
1.11 |
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 |
wakaba |
1.1 |
if ($self->{nc} == 0x0022 or # " |
1186 |
|
|
$self->{nc} == 0x0027) { # ' |
1187 |
|
|
!!!cp (78); |
1188 |
wakaba |
1.11 |
## XML5: Not a parse error. |
1189 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.11 |
## XML5: "Tag attribute value before state". |
1203 |
|
|
|
1204 |
wakaba |
1.1 |
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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
1243 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
1267 |
wakaba |
1.1 |
## 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 |
wakaba |
1.11 |
## XML5: Not a parse error. |
1276 |
wakaba |
1.1 |
!!!parse-error (type => 'bad attribute value'); |
1277 |
wakaba |
1.11 |
} elsif ($self->{is_xml}) { |
1278 |
|
|
!!!cp (93.1); |
1279 |
|
|
## XML5: No parse error. |
1280 |
|
|
!!!parse-error (type => 'unquoted attr value'); ## TODO |
1281 |
wakaba |
1.1 |
} 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 |
wakaba |
1.15 |
## XML5: "Tag attribute value double quoted state" and "DOCTYPE |
1291 |
|
|
## ATTLIST attribute value double quoted state". |
1292 |
wakaba |
1.11 |
|
1293 |
wakaba |
1.1 |
if ($self->{nc} == 0x0022) { # " |
1294 |
wakaba |
1.15 |
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 |
wakaba |
1.1 |
!!!next-input-character; |
1305 |
|
|
redo A; |
1306 |
|
|
} elsif ($self->{nc} == 0x0026) { # & |
1307 |
|
|
!!!cp (96); |
1308 |
wakaba |
1.11 |
## XML5: Not defined yet. |
1309 |
|
|
|
1310 |
wakaba |
1.1 |
## 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 |
wakaba |
1.15 |
|
1325 |
|
|
$self->{state} = DATA_STATE; |
1326 |
|
|
$self->{s_kwd} = ''; |
1327 |
|
|
## reconsume |
1328 |
|
|
!!!emit ($self->{ct}); # start tag |
1329 |
|
|
redo A; |
1330 |
wakaba |
1.1 |
} 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 |
wakaba |
1.15 |
|
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 |
wakaba |
1.1 |
} else { |
1353 |
|
|
die "$0: $self->{ct}->{type}: Unknown token type"; |
1354 |
|
|
} |
1355 |
|
|
} else { |
1356 |
wakaba |
1.15 |
## XML5 [ATTLIST]: Not defined yet. |
1357 |
wakaba |
1.11 |
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 |
wakaba |
1.1 |
$self->{ca}->{value} .= chr ($self->{nc}); |
1365 |
|
|
$self->{read_until}->($self->{ca}->{value}, |
1366 |
wakaba |
1.11 |
q["&<], |
1367 |
wakaba |
1.1 |
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 |
wakaba |
1.15 |
## XML5: "Tag attribute value single quoted state" and "DOCTYPE |
1375 |
|
|
## ATTLIST attribute value single quoted state". |
1376 |
wakaba |
1.11 |
|
1377 |
wakaba |
1.1 |
if ($self->{nc} == 0x0027) { # ' |
1378 |
wakaba |
1.15 |
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 |
wakaba |
1.1 |
!!!next-input-character; |
1389 |
|
|
redo A; |
1390 |
|
|
} elsif ($self->{nc} == 0x0026) { # & |
1391 |
|
|
!!!cp (102); |
1392 |
wakaba |
1.11 |
## XML5: Not defined yet. |
1393 |
|
|
|
1394 |
wakaba |
1.1 |
## 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 |
wakaba |
1.15 |
|
1409 |
|
|
$self->{state} = DATA_STATE; |
1410 |
|
|
$self->{s_kwd} = ''; |
1411 |
|
|
## reconsume |
1412 |
|
|
!!!emit ($self->{ct}); # start tag |
1413 |
|
|
redo A; |
1414 |
wakaba |
1.1 |
} 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 |
wakaba |
1.15 |
|
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 |
wakaba |
1.1 |
} else { |
1437 |
|
|
die "$0: $self->{ct}->{type}: Unknown token type"; |
1438 |
|
|
} |
1439 |
|
|
} else { |
1440 |
wakaba |
1.15 |
## XML5 [ATTLIST]: Not defined yet. |
1441 |
wakaba |
1.11 |
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 |
wakaba |
1.1 |
$self->{ca}->{value} .= chr ($self->{nc}); |
1449 |
|
|
$self->{read_until}->($self->{ca}->{value}, |
1450 |
wakaba |
1.11 |
q['&<], |
1451 |
wakaba |
1.1 |
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 |
wakaba |
1.11 |
## XML5: "Tag attribute value unquoted state". |
1459 |
|
|
|
1460 |
wakaba |
1.1 |
if ($is_space->{$self->{nc}}) { |
1461 |
wakaba |
1.15 |
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 |
wakaba |
1.1 |
!!!next-input-character; |
1471 |
|
|
redo A; |
1472 |
|
|
} elsif ($self->{nc} == 0x0026) { # & |
1473 |
|
|
!!!cp (108); |
1474 |
wakaba |
1.11 |
|
1475 |
|
|
## XML5: Not defined yet. |
1476 |
|
|
|
1477 |
wakaba |
1.1 |
## 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 |
wakaba |
1.15 |
|
1491 |
|
|
$self->{state} = DATA_STATE; |
1492 |
|
|
$self->{s_kwd} = ''; |
1493 |
|
|
!!!next-input-character; |
1494 |
|
|
!!!emit ($self->{ct}); # start tag |
1495 |
|
|
redo A; |
1496 |
wakaba |
1.1 |
} 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 |
wakaba |
1.15 |
|
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 |
wakaba |
1.1 |
} 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 |
wakaba |
1.15 |
!!!parse-error (type => 'unclosed tag'); |
1524 |
wakaba |
1.1 |
$self->{last_stag_name} = $self->{ct}->{tag_name}; |
1525 |
wakaba |
1.15 |
|
1526 |
|
|
$self->{state} = DATA_STATE; |
1527 |
|
|
$self->{s_kwd} = ''; |
1528 |
|
|
## reconsume |
1529 |
|
|
!!!emit ($self->{ct}); # start tag |
1530 |
|
|
redo A; |
1531 |
wakaba |
1.1 |
} elsif ($self->{ct}->{type} == END_TAG_TOKEN) { |
1532 |
wakaba |
1.15 |
!!!parse-error (type => 'unclosed tag'); |
1533 |
wakaba |
1.1 |
$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 |
wakaba |
1.15 |
|
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 |
wakaba |
1.1 |
} 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 |
wakaba |
1.11 |
## XML5: Not a parse error. |
1565 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
1602 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
1630 |
wakaba |
1.1 |
## 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 |
wakaba |
1.11 |
## XML5: "Empty tag state". |
1642 |
|
|
|
1643 |
wakaba |
1.1 |
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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
1663 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.11 |
## XML5: "Tag attribute name before state". |
1685 |
wakaba |
1.1 |
$self->{state} = DATA_STATE; |
1686 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
1687 |
wakaba |
1.1 |
## 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 |
wakaba |
1.14 |
## XML5: "Bogus comment state" and "DOCTYPE bogus comment state". |
1700 |
|
|
|
1701 |
wakaba |
1.1 |
## NOTE: Unlike spec's "bogus comment state", this implementation |
1702 |
|
|
## consumes characters one-by-one basis. |
1703 |
|
|
|
1704 |
|
|
if ($self->{nc} == 0x003E) { # > |
1705 |
wakaba |
1.13 |
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 |
wakaba |
1.1 |
!!!next-input-character; |
1714 |
|
|
|
1715 |
|
|
!!!emit ($self->{ct}); # comment |
1716 |
|
|
redo A; |
1717 |
|
|
} elsif ($self->{nc} == -1) { |
1718 |
wakaba |
1.13 |
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 |
wakaba |
1.1 |
## 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 |
wakaba |
1.14 |
## XML5: "Markup declaration state". |
1743 |
wakaba |
1.1 |
|
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 |
wakaba |
1.12 |
$self->{kwd} = chr $self->{nc}; |
1755 |
wakaba |
1.1 |
!!!next-input-character; |
1756 |
|
|
redo A; |
1757 |
wakaba |
1.3 |
} elsif ((($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and |
1758 |
|
|
$self->{open_elements}->[-1]->[1] & FOREIGN_EL) or |
1759 |
|
|
$self->{is_xml}) and |
1760 |
wakaba |
1.1 |
$self->{nc} == 0x005B) { # [ |
1761 |
|
|
!!!cp (135.4); |
1762 |
|
|
$self->{state} = MD_CDATA_STATE; |
1763 |
wakaba |
1.12 |
$self->{kwd} = '['; |
1764 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.10 |
$self->{state} = COMMENT_START_STATE; ## XML5: "comment state". |
1788 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.12 |
]->[length $self->{kwd}] or |
1814 |
wakaba |
1.1 |
$self->{nc} == [ |
1815 |
|
|
undef, |
1816 |
|
|
0x006F, # o |
1817 |
|
|
0x0063, # c |
1818 |
|
|
0x0074, # t |
1819 |
|
|
0x0079, # y |
1820 |
|
|
0x0070, # p |
1821 |
wakaba |
1.12 |
]->[length $self->{kwd}]) { |
1822 |
wakaba |
1.1 |
!!!cp (131); |
1823 |
|
|
## Stay in the state. |
1824 |
wakaba |
1.12 |
$self->{kwd} .= chr $self->{nc}; |
1825 |
wakaba |
1.1 |
!!!next-input-character; |
1826 |
|
|
redo A; |
1827 |
wakaba |
1.12 |
} elsif ((length $self->{kwd}) == 6 and |
1828 |
wakaba |
1.1 |
($self->{nc} == 0x0045 or # E |
1829 |
|
|
$self->{nc} == 0x0065)) { # e |
1830 |
wakaba |
1.12 |
if ($self->{is_xml} and |
1831 |
|
|
($self->{kwd} ne 'DOCTYP' or $self->{nc} == 0x0065)) { |
1832 |
wakaba |
1.10 |
!!!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 |
wakaba |
1.1 |
$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 |
wakaba |
1.12 |
column => $self->{column_prev} - 1 - length $self->{kwd}); |
1854 |
wakaba |
1.1 |
$self->{state} = BOGUS_COMMENT_STATE; |
1855 |
|
|
## Reconsume. |
1856 |
|
|
$self->{ct} = {type => COMMENT_TOKEN, |
1857 |
wakaba |
1.12 |
data => $self->{kwd}, |
1858 |
wakaba |
1.1 |
line => $self->{line_prev}, |
1859 |
wakaba |
1.12 |
column => $self->{column_prev} - 1 - length $self->{kwd}, |
1860 |
wakaba |
1.1 |
}; |
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 |
wakaba |
1.12 |
}->{$self->{kwd}}) { |
1871 |
wakaba |
1.1 |
!!!cp (135.1); |
1872 |
|
|
## Stay in the state. |
1873 |
wakaba |
1.12 |
$self->{kwd} .= chr $self->{nc}; |
1874 |
wakaba |
1.1 |
!!!next-input-character; |
1875 |
|
|
redo A; |
1876 |
wakaba |
1.12 |
} elsif ($self->{kwd} eq '[CDATA' and |
1877 |
wakaba |
1.1 |
$self->{nc} == 0x005B) { # [ |
1878 |
wakaba |
1.6 |
if ($self->{is_xml} and |
1879 |
|
|
not $self->{tainted} and |
1880 |
|
|
@{$self->{open_elements} or []} == 0) { |
1881 |
wakaba |
1.8 |
!!!cp (135.2); |
1882 |
wakaba |
1.6 |
!!!parse-error (type => 'cdata outside of root element', |
1883 |
|
|
line => $self->{line_prev}, |
1884 |
|
|
column => $self->{column_prev} - 7); |
1885 |
|
|
$self->{tainted} = 1; |
1886 |
wakaba |
1.8 |
} else { |
1887 |
|
|
!!!cp (135.21); |
1888 |
wakaba |
1.6 |
} |
1889 |
|
|
|
1890 |
wakaba |
1.1 |
$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 |
wakaba |
1.12 |
column => $self->{column_prev} - 1 - length $self->{kwd}); |
1902 |
wakaba |
1.1 |
$self->{state} = BOGUS_COMMENT_STATE; |
1903 |
|
|
## Reconsume. |
1904 |
|
|
$self->{ct} = {type => COMMENT_TOKEN, |
1905 |
wakaba |
1.12 |
data => $self->{kwd}, |
1906 |
wakaba |
1.1 |
line => $self->{line_prev}, |
1907 |
wakaba |
1.12 |
column => $self->{column_prev} - 1 - length $self->{kwd}, |
1908 |
wakaba |
1.1 |
}; |
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 |
wakaba |
1.13 |
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 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.13 |
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 |
wakaba |
1.1 |
## 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 |
wakaba |
1.13 |
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 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.13 |
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 |
wakaba |
1.1 |
## 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 |
wakaba |
1.14 |
## XML5: "Comment state" and "DOCTYPE comment state". |
2001 |
|
|
|
2002 |
wakaba |
1.1 |
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 |
wakaba |
1.13 |
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 |
wakaba |
1.1 |
## 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 |
wakaba |
1.14 |
## XML5: "Comment dash state" and "DOCTYPE comment dash state". |
2035 |
wakaba |
1.10 |
|
2036 |
wakaba |
1.1 |
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 |
wakaba |
1.13 |
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 |
wakaba |
1.1 |
## 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 |
wakaba |
1.14 |
## XML5: "Comment end state" and "DOCTYPE comment end state". |
2065 |
|
|
|
2066 |
wakaba |
1.1 |
if ($self->{nc} == 0x003E) { # > |
2067 |
wakaba |
1.13 |
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 |
wakaba |
1.1 |
!!!next-input-character; |
2076 |
|
|
|
2077 |
|
|
!!!emit ($self->{ct}); # comment |
2078 |
|
|
|
2079 |
|
|
redo A; |
2080 |
|
|
} elsif ($self->{nc} == 0x002D) { # - |
2081 |
|
|
!!!cp (152); |
2082 |
wakaba |
1.10 |
## XML5: Not a parse error. |
2083 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.13 |
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 |
wakaba |
1.1 |
## reconsume |
2101 |
|
|
|
2102 |
|
|
!!!emit ($self->{ct}); # comment |
2103 |
|
|
|
2104 |
|
|
redo A; |
2105 |
|
|
} else { |
2106 |
|
|
!!!cp (154); |
2107 |
wakaba |
1.10 |
## XML5: Not a parse error. |
2108 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.12 |
## XML5: Unless EOF, swith to the bogus comment state. |
2125 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.12 |
## XML5: "DOCTYPE root name before state". |
2132 |
|
|
|
2133 |
wakaba |
1.1 |
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 |
wakaba |
1.12 |
## XML5: No parse error. |
2141 |
wakaba |
1.1 |
!!!parse-error (type => 'no DOCTYPE name'); |
2142 |
|
|
$self->{state} = DATA_STATE; |
2143 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
2144 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
2154 |
wakaba |
1.1 |
## reconsume |
2155 |
|
|
|
2156 |
|
|
!!!emit ($self->{ct}); # DOCTYPE (quirks) |
2157 |
|
|
|
2158 |
|
|
redo A; |
2159 |
wakaba |
1.12 |
} 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 |
wakaba |
1.13 |
$self->{ct}->{has_internal_subset} = 1; # DOCTYPE |
2164 |
|
|
$self->{in_subset} = 1; |
2165 |
wakaba |
1.12 |
!!!next-input-character; |
2166 |
wakaba |
1.13 |
!!!emit ($self->{ct}); # DOCTYPE |
2167 |
wakaba |
1.12 |
redo A; |
2168 |
wakaba |
1.1 |
} 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 |
wakaba |
1.12 |
## XML5: "DOCTYPE root name state". |
2178 |
|
|
|
2179 |
|
|
## ISSUE: Redundant "First," in the spec. |
2180 |
|
|
|
2181 |
wakaba |
1.1 |
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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
2190 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
2200 |
wakaba |
1.1 |
## reconsume |
2201 |
|
|
|
2202 |
|
|
$self->{ct}->{quirks} = 1; |
2203 |
|
|
!!!emit ($self->{ct}); # DOCTYPE |
2204 |
|
|
|
2205 |
|
|
redo A; |
2206 |
wakaba |
1.12 |
} elsif ($self->{is_xml} and $self->{nc} == 0x005B) { # [ |
2207 |
|
|
!!!cp (163.1); |
2208 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
2209 |
wakaba |
1.13 |
$self->{ct}->{has_internal_subset} = 1; # DOCTYPE |
2210 |
|
|
$self->{in_subset} = 1; |
2211 |
wakaba |
1.12 |
!!!next-input-character; |
2212 |
wakaba |
1.13 |
!!!emit ($self->{ct}); # DOCTYPE |
2213 |
wakaba |
1.12 |
redo A; |
2214 |
wakaba |
1.1 |
} 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 |
wakaba |
1.12 |
## XML5: Corresponding to XML5's "DOCTYPE root name after |
2224 |
|
|
## state", but implemented differently. |
2225 |
|
|
|
2226 |
wakaba |
1.1 |
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 |
wakaba |
1.16 |
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 |
wakaba |
1.1 |
!!!next-input-character; |
2243 |
wakaba |
1.16 |
!!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION |
2244 |
wakaba |
1.1 |
redo A; |
2245 |
|
|
} elsif ($self->{nc} == -1) { |
2246 |
wakaba |
1.16 |
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 |
wakaba |
1.1 |
redo A; |
2261 |
|
|
} elsif ($self->{nc} == 0x0050 or # P |
2262 |
|
|
$self->{nc} == 0x0070) { # p |
2263 |
wakaba |
1.12 |
!!!cp (167.1); |
2264 |
wakaba |
1.1 |
$self->{state} = PUBLIC_STATE; |
2265 |
wakaba |
1.12 |
$self->{kwd} = chr $self->{nc}; |
2266 |
wakaba |
1.1 |
!!!next-input-character; |
2267 |
|
|
redo A; |
2268 |
|
|
} elsif ($self->{nc} == 0x0053 or # S |
2269 |
|
|
$self->{nc} == 0x0073) { # s |
2270 |
wakaba |
1.12 |
!!!cp (167.2); |
2271 |
wakaba |
1.1 |
$self->{state} = SYSTEM_STATE; |
2272 |
wakaba |
1.12 |
$self->{kwd} = chr $self->{nc}; |
2273 |
|
|
!!!next-input-character; |
2274 |
|
|
redo A; |
2275 |
wakaba |
1.19 |
} 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 |
wakaba |
1.16 |
} elsif ($self->{is_xml} and |
2292 |
|
|
$self->{ct}->{type} == DOCTYPE_TOKEN and |
2293 |
|
|
$self->{nc} == 0x005B) { # [ |
2294 |
wakaba |
1.12 |
!!!cp (167.3); |
2295 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
2296 |
|
|
$self->{ct}->{has_internal_subset} = 1; # DOCTYPE |
2297 |
wakaba |
1.13 |
$self->{in_subset} = 1; |
2298 |
wakaba |
1.1 |
!!!next-input-character; |
2299 |
wakaba |
1.13 |
!!!emit ($self->{ct}); # DOCTYPE |
2300 |
wakaba |
1.1 |
redo A; |
2301 |
|
|
} else { |
2302 |
wakaba |
1.16 |
!!!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 |
wakaba |
1.1 |
|
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 |
wakaba |
1.12 |
]->[length $self->{kwd}] or |
2325 |
wakaba |
1.1 |
$self->{nc} == [ |
2326 |
|
|
undef, |
2327 |
|
|
0x0075, # u |
2328 |
|
|
0x0062, # b |
2329 |
|
|
0x006C, # l |
2330 |
|
|
0x0069, # i |
2331 |
wakaba |
1.12 |
]->[length $self->{kwd}]) { |
2332 |
wakaba |
1.1 |
!!!cp (175); |
2333 |
|
|
## Stay in the state. |
2334 |
wakaba |
1.12 |
$self->{kwd} .= chr $self->{nc}; |
2335 |
wakaba |
1.1 |
!!!next-input-character; |
2336 |
|
|
redo A; |
2337 |
wakaba |
1.12 |
} elsif ((length $self->{kwd}) == 5 and |
2338 |
wakaba |
1.1 |
($self->{nc} == 0x0043 or # C |
2339 |
|
|
$self->{nc} == 0x0063)) { # c |
2340 |
wakaba |
1.12 |
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 |
wakaba |
1.1 |
$self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE; |
2351 |
|
|
!!!next-input-character; |
2352 |
|
|
redo A; |
2353 |
|
|
} else { |
2354 |
wakaba |
1.16 |
!!!parse-error (type => 'string after DOCTYPE name', ## TODO: type |
2355 |
wakaba |
1.1 |
line => $self->{line_prev}, |
2356 |
wakaba |
1.12 |
column => $self->{column_prev} + 1 - length $self->{kwd}); |
2357 |
wakaba |
1.16 |
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 |
wakaba |
1.1 |
## 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 |
wakaba |
1.12 |
]->[length $self->{kwd}] or |
2377 |
wakaba |
1.1 |
$self->{nc} == [ |
2378 |
|
|
undef, |
2379 |
|
|
0x0079, # y |
2380 |
|
|
0x0073, # s |
2381 |
|
|
0x0074, # t |
2382 |
|
|
0x0065, # e |
2383 |
wakaba |
1.12 |
]->[length $self->{kwd}]) { |
2384 |
wakaba |
1.1 |
!!!cp (170); |
2385 |
|
|
## Stay in the state. |
2386 |
wakaba |
1.12 |
$self->{kwd} .= chr $self->{nc}; |
2387 |
wakaba |
1.1 |
!!!next-input-character; |
2388 |
|
|
redo A; |
2389 |
wakaba |
1.12 |
} elsif ((length $self->{kwd}) == 5 and |
2390 |
wakaba |
1.1 |
($self->{nc} == 0x004D or # M |
2391 |
|
|
$self->{nc} == 0x006D)) { # m |
2392 |
wakaba |
1.12 |
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 |
wakaba |
1.1 |
$self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE; |
2403 |
|
|
!!!next-input-character; |
2404 |
|
|
redo A; |
2405 |
|
|
} else { |
2406 |
wakaba |
1.16 |
!!!parse-error (type => 'string after DOCTYPE name', ## TODO: type |
2407 |
wakaba |
1.1 |
line => $self->{line_prev}, |
2408 |
wakaba |
1.12 |
column => $self->{column_prev} + 1 - length $self->{kwd}); |
2409 |
wakaba |
1.16 |
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 |
wakaba |
1.1 |
## 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 |
wakaba |
1.16 |
|
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 |
wakaba |
1.1 |
!!!next-input-character; |
2452 |
wakaba |
1.16 |
!!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION |
2453 |
wakaba |
1.1 |
redo A; |
2454 |
|
|
} elsif ($self->{nc} == -1) { |
2455 |
wakaba |
1.16 |
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 |
wakaba |
1.1 |
## reconsume |
2468 |
|
|
!!!emit ($self->{ct}); # DOCTYPE |
2469 |
|
|
redo A; |
2470 |
wakaba |
1.16 |
} elsif ($self->{is_xml} and |
2471 |
|
|
$self->{ct}->{type} == DOCTYPE_TOKEN and |
2472 |
|
|
$self->{nc} == 0x005B) { # [ |
2473 |
wakaba |
1.12 |
!!!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 |
wakaba |
1.13 |
$self->{in_subset} = 1; |
2478 |
wakaba |
1.12 |
!!!next-input-character; |
2479 |
wakaba |
1.13 |
!!!emit ($self->{ct}); # DOCTYPE |
2480 |
wakaba |
1.12 |
redo A; |
2481 |
wakaba |
1.1 |
} else { |
2482 |
|
|
!!!parse-error (type => 'string after PUBLIC'); |
2483 |
|
|
|
2484 |
wakaba |
1.16 |
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 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.16 |
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 |
wakaba |
1.1 |
!!!next-input-character; |
2516 |
wakaba |
1.16 |
!!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION |
2517 |
wakaba |
1.1 |
redo A; |
2518 |
|
|
} elsif ($self->{nc} == -1) { |
2519 |
|
|
!!!parse-error (type => 'unclosed PUBLIC literal'); |
2520 |
|
|
|
2521 |
wakaba |
1.16 |
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 |
wakaba |
1.1 |
!!!emit ($self->{ct}); # DOCTYPE |
2533 |
|
|
redo A; |
2534 |
|
|
} else { |
2535 |
|
|
!!!cp (190); |
2536 |
wakaba |
1.16 |
$self->{ct}->{pubid} .= chr $self->{nc}; # DOCTYPE/ENTITY/NOTATION |
2537 |
wakaba |
1.1 |
$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 |
wakaba |
1.16 |
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 |
wakaba |
1.1 |
!!!next-input-character; |
2564 |
wakaba |
1.16 |
!!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION |
2565 |
wakaba |
1.1 |
redo A; |
2566 |
|
|
} elsif ($self->{nc} == -1) { |
2567 |
|
|
!!!parse-error (type => 'unclosed PUBLIC literal'); |
2568 |
|
|
|
2569 |
wakaba |
1.16 |
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 |
wakaba |
1.1 |
## reconsume |
2580 |
wakaba |
1.16 |
!!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION |
2581 |
wakaba |
1.1 |
redo A; |
2582 |
|
|
} else { |
2583 |
|
|
!!!cp (194); |
2584 |
wakaba |
1.16 |
$self->{ct}->{pubid} .= chr $self->{nc}; # DOCTYPE/ENTITY/NOTATION |
2585 |
wakaba |
1.1 |
$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 |
wakaba |
1.16 |
$self->{ct}->{sysid} = ''; # DOCTYPE/ENTITY/NOTATION |
2601 |
wakaba |
1.1 |
$self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE; |
2602 |
|
|
!!!next-input-character; |
2603 |
|
|
redo A; |
2604 |
|
|
} elsif ($self->{nc} == 0x0027) { # ' |
2605 |
|
|
!!!cp (197); |
2606 |
wakaba |
1.16 |
$self->{ct}->{sysid} = ''; # DOCTYPE/ENTITY/NOTATION |
2607 |
wakaba |
1.1 |
$self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE; |
2608 |
|
|
!!!next-input-character; |
2609 |
|
|
redo A; |
2610 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
2611 |
wakaba |
1.16 |
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 |
wakaba |
1.12 |
} else { |
2621 |
wakaba |
1.16 |
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 |
wakaba |
1.12 |
} |
2629 |
wakaba |
1.16 |
|
2630 |
wakaba |
1.1 |
!!!next-input-character; |
2631 |
wakaba |
1.16 |
!!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION |
2632 |
wakaba |
1.1 |
redo A; |
2633 |
|
|
} elsif ($self->{nc} == -1) { |
2634 |
wakaba |
1.16 |
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 |
wakaba |
1.1 |
## reconsume |
2647 |
wakaba |
1.16 |
!!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION |
2648 |
wakaba |
1.1 |
redo A; |
2649 |
wakaba |
1.16 |
} elsif ($self->{is_xml} and |
2650 |
|
|
$self->{ct}->{type} == DOCTYPE_TOKEN and |
2651 |
|
|
$self->{nc} == 0x005B) { # [ |
2652 |
wakaba |
1.12 |
!!!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 |
wakaba |
1.13 |
$self->{in_subset} = 1; |
2657 |
wakaba |
1.12 |
!!!next-input-character; |
2658 |
wakaba |
1.13 |
!!!emit ($self->{ct}); # DOCTYPE |
2659 |
wakaba |
1.12 |
redo A; |
2660 |
wakaba |
1.1 |
} else { |
2661 |
|
|
!!!parse-error (type => 'string after PUBLIC literal'); |
2662 |
|
|
|
2663 |
wakaba |
1.16 |
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 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.16 |
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 |
wakaba |
1.1 |
|
2707 |
wakaba |
1.16 |
!!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION |
2708 |
wakaba |
1.1 |
redo A; |
2709 |
|
|
} elsif ($self->{nc} == -1) { |
2710 |
wakaba |
1.16 |
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 |
wakaba |
1.1 |
## reconsume |
2723 |
wakaba |
1.16 |
!!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION |
2724 |
wakaba |
1.1 |
redo A; |
2725 |
wakaba |
1.16 |
} elsif ($self->{is_xml} and |
2726 |
|
|
$self->{ct}->{type} == DOCTYPE_TOKEN and |
2727 |
|
|
$self->{nc} == 0x005B) { # [ |
2728 |
wakaba |
1.12 |
!!!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 |
wakaba |
1.13 |
$self->{in_subset} = 1; |
2734 |
wakaba |
1.12 |
!!!next-input-character; |
2735 |
wakaba |
1.13 |
!!!emit ($self->{ct}); # DOCTYPE |
2736 |
wakaba |
1.12 |
redo A; |
2737 |
wakaba |
1.1 |
} else { |
2738 |
|
|
!!!parse-error (type => 'string after SYSTEM'); |
2739 |
|
|
|
2740 |
wakaba |
1.16 |
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 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.12 |
} elsif (not $self->{is_xml} and $self->{nc} == 0x003E) { # > |
2759 |
wakaba |
1.1 |
!!!parse-error (type => 'unclosed SYSTEM literal'); |
2760 |
|
|
|
2761 |
wakaba |
1.16 |
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 |
wakaba |
1.1 |
!!!next-input-character; |
2772 |
wakaba |
1.16 |
!!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION |
2773 |
wakaba |
1.1 |
redo A; |
2774 |
|
|
} elsif ($self->{nc} == -1) { |
2775 |
|
|
!!!parse-error (type => 'unclosed SYSTEM literal'); |
2776 |
|
|
|
2777 |
wakaba |
1.16 |
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 |
wakaba |
1.1 |
## reconsume |
2788 |
wakaba |
1.16 |
!!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION |
2789 |
wakaba |
1.1 |
redo A; |
2790 |
|
|
} else { |
2791 |
|
|
!!!cp (210); |
2792 |
wakaba |
1.16 |
$self->{ct}->{sysid} .= chr $self->{nc}; # DOCTYPE/ENTITY/NOTATION |
2793 |
wakaba |
1.1 |
$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 |
wakaba |
1.12 |
} elsif (not $self->{is_xml} and $self->{nc} == 0x003E) { # > |
2807 |
wakaba |
1.1 |
!!!cp (212); |
2808 |
|
|
!!!parse-error (type => 'unclosed SYSTEM literal'); |
2809 |
|
|
|
2810 |
|
|
$self->{state} = DATA_STATE; |
2811 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
2812 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.16 |
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 |
wakaba |
1.1 |
## reconsume |
2832 |
wakaba |
1.16 |
!!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION |
2833 |
wakaba |
1.1 |
redo A; |
2834 |
|
|
} else { |
2835 |
|
|
!!!cp (214); |
2836 |
wakaba |
1.16 |
$self->{ct}->{sysid} .= chr $self->{nc}; # DOCTYPE/ENTITY/NOTATION |
2837 |
wakaba |
1.1 |
$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 |
wakaba |
1.18 |
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 |
wakaba |
1.1 |
!!!next-input-character; |
2854 |
|
|
redo A; |
2855 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
2856 |
wakaba |
1.16 |
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 |
wakaba |
1.1 |
!!!next-input-character; |
2866 |
wakaba |
1.16 |
!!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION |
2867 |
wakaba |
1.1 |
redo A; |
2868 |
wakaba |
1.18 |
} 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 |
wakaba |
1.1 |
} elsif ($self->{nc} == -1) { |
2878 |
wakaba |
1.16 |
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 |
wakaba |
1.1 |
## reconsume |
2891 |
wakaba |
1.16 |
!!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION |
2892 |
wakaba |
1.1 |
redo A; |
2893 |
wakaba |
1.16 |
} elsif ($self->{is_xml} and |
2894 |
|
|
$self->{ct}->{type} == DOCTYPE_TOKEN and |
2895 |
|
|
$self->{nc} == 0x005B) { # [ |
2896 |
wakaba |
1.12 |
!!!cp (218.1); |
2897 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
2898 |
|
|
$self->{ct}->{has_internal_subset} = 1; # DOCTYPE |
2899 |
wakaba |
1.13 |
$self->{in_subset} = 1; |
2900 |
wakaba |
1.12 |
!!!next-input-character; |
2901 |
wakaba |
1.13 |
!!!emit ($self->{ct}); # DOCTYPE |
2902 |
wakaba |
1.12 |
redo A; |
2903 |
wakaba |
1.1 |
} else { |
2904 |
|
|
!!!parse-error (type => 'string after SYSTEM literal'); |
2905 |
|
|
|
2906 |
wakaba |
1.16 |
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 |
wakaba |
1.1 |
!!!next-input-character; |
2916 |
|
|
redo A; |
2917 |
|
|
} |
2918 |
wakaba |
1.18 |
} 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 |
wakaba |
1.1 |
} elsif ($self->{state} == BOGUS_DOCTYPE_STATE) { |
2952 |
|
|
if ($self->{nc} == 0x003E) { # > |
2953 |
|
|
!!!cp (219); |
2954 |
|
|
$self->{state} = DATA_STATE; |
2955 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
2956 |
wakaba |
1.1 |
!!!next-input-character; |
2957 |
|
|
|
2958 |
|
|
!!!emit ($self->{ct}); # DOCTYPE |
2959 |
|
|
|
2960 |
|
|
redo A; |
2961 |
wakaba |
1.12 |
} elsif ($self->{is_xml} and $self->{nc} == 0x005B) { # [ |
2962 |
wakaba |
1.13 |
!!!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 |
wakaba |
1.1 |
} elsif ($self->{nc} == -1) { |
2970 |
|
|
!!!cp (220); |
2971 |
|
|
$self->{state} = DATA_STATE; |
2972 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
2973 |
wakaba |
1.1 |
## reconsume |
2974 |
|
|
|
2975 |
|
|
!!!emit ($self->{ct}); # DOCTYPE |
2976 |
|
|
|
2977 |
|
|
redo A; |
2978 |
|
|
} else { |
2979 |
|
|
!!!cp (221); |
2980 |
|
|
my $s = ''; |
2981 |
wakaba |
1.12 |
$self->{read_until}->($s, q{>[}, 0); |
2982 |
wakaba |
1.1 |
|
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 |
wakaba |
1.10 |
|
2992 |
|
|
## XML5: "CDATA state". |
2993 |
wakaba |
1.1 |
|
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 |
wakaba |
1.6 |
if ($self->{is_xml}) { |
3001 |
wakaba |
1.8 |
!!!cp (221.11); |
3002 |
wakaba |
1.6 |
!!!parse-error (type => 'no mse'); ## TODO: type |
3003 |
wakaba |
1.8 |
} else { |
3004 |
|
|
!!!cp (221.12); |
3005 |
wakaba |
1.6 |
} |
3006 |
|
|
|
3007 |
wakaba |
1.1 |
$self->{state} = DATA_STATE; |
3008 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
3009 |
wakaba |
1.10 |
## Reconsume. |
3010 |
wakaba |
1.1 |
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 |
wakaba |
1.10 |
## XML5: "CDATA bracket state". |
3033 |
|
|
|
3034 |
wakaba |
1.1 |
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 |
wakaba |
1.10 |
## XML5: If EOF, "]" is not appended and changed to the data state. |
3042 |
wakaba |
1.1 |
$self->{ct}->{data} .= ']'; |
3043 |
wakaba |
1.10 |
$self->{state} = CDATA_SECTION_STATE; ## XML5: Stay in the state. |
3044 |
wakaba |
1.1 |
## Reconsume. |
3045 |
|
|
redo A; |
3046 |
|
|
} |
3047 |
|
|
} elsif ($self->{state} == CDATA_SECTION_MSE2_STATE) { |
3048 |
wakaba |
1.10 |
## XML5: "CDATA end state". |
3049 |
|
|
|
3050 |
wakaba |
1.1 |
if ($self->{nc} == 0x003E) { # > |
3051 |
|
|
$self->{state} = DATA_STATE; |
3052 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
3053 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.10 |
## Reconsume. ## XML5: Emit. |
3073 |
wakaba |
1.1 |
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 |
wakaba |
1.12 |
$self->{kwd} = '#'; |
3090 |
wakaba |
1.1 |
!!!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 |
wakaba |
1.12 |
$self->{kwd} = chr $self->{nc}; |
3100 |
|
|
$self->{entity__value} = $self->{kwd}; |
3101 |
wakaba |
1.1 |
$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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
3121 |
wakaba |
1.1 |
## 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 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
3132 |
wakaba |
1.1 |
## Reconsume. |
3133 |
|
|
redo A; |
3134 |
|
|
} |
3135 |
|
|
} elsif ($self->{state} == ENTITY_HASH_STATE) { |
3136 |
|
|
if ($self->{nc} == 0x0078 or # x |
3137 |
|
|
$self->{nc} == 0x0058) { # X |
3138 |
|
|
!!!cp (995); |
3139 |
|
|
$self->{state} = HEXREF_X_STATE; |
3140 |
wakaba |
1.12 |
$self->{kwd} .= chr $self->{nc}; |
3141 |
wakaba |
1.1 |
!!!next-input-character; |
3142 |
|
|
redo A; |
3143 |
|
|
} elsif (0x0030 <= $self->{nc} and |
3144 |
|
|
$self->{nc} <= 0x0039) { # 0..9 |
3145 |
|
|
!!!cp (994); |
3146 |
|
|
$self->{state} = NCR_NUM_STATE; |
3147 |
wakaba |
1.12 |
$self->{kwd} = $self->{nc} - 0x0030; |
3148 |
wakaba |
1.1 |
!!!next-input-character; |
3149 |
|
|
redo A; |
3150 |
|
|
} else { |
3151 |
|
|
!!!parse-error (type => 'bare nero', |
3152 |
|
|
line => $self->{line_prev}, |
3153 |
|
|
column => $self->{column_prev} - 1); |
3154 |
|
|
|
3155 |
|
|
## NOTE: According to the spec algorithm, nothing is returned, |
3156 |
|
|
## and then "&#" is appended to the parent element or the attribute |
3157 |
|
|
## value in the later processing. |
3158 |
|
|
|
3159 |
|
|
if ($self->{prev_state} == DATA_STATE) { |
3160 |
|
|
!!!cp (1019); |
3161 |
|
|
$self->{state} = $self->{prev_state}; |
3162 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
3163 |
wakaba |
1.1 |
## Reconsume. |
3164 |
|
|
!!!emit ({type => CHARACTER_TOKEN, |
3165 |
|
|
data => '&#', |
3166 |
|
|
line => $self->{line_prev}, |
3167 |
|
|
column => $self->{column_prev} - 1, |
3168 |
|
|
}); |
3169 |
|
|
redo A; |
3170 |
|
|
} else { |
3171 |
|
|
!!!cp (993); |
3172 |
|
|
$self->{ca}->{value} .= '&#'; |
3173 |
|
|
$self->{state} = $self->{prev_state}; |
3174 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
3175 |
wakaba |
1.1 |
## Reconsume. |
3176 |
|
|
redo A; |
3177 |
|
|
} |
3178 |
|
|
} |
3179 |
|
|
} elsif ($self->{state} == NCR_NUM_STATE) { |
3180 |
|
|
if (0x0030 <= $self->{nc} and |
3181 |
|
|
$self->{nc} <= 0x0039) { # 0..9 |
3182 |
|
|
!!!cp (1012); |
3183 |
wakaba |
1.12 |
$self->{kwd} *= 10; |
3184 |
|
|
$self->{kwd} += $self->{nc} - 0x0030; |
3185 |
wakaba |
1.1 |
|
3186 |
|
|
## Stay in the state. |
3187 |
|
|
!!!next-input-character; |
3188 |
|
|
redo A; |
3189 |
|
|
} elsif ($self->{nc} == 0x003B) { # ; |
3190 |
|
|
!!!cp (1013); |
3191 |
|
|
!!!next-input-character; |
3192 |
|
|
# |
3193 |
|
|
} else { |
3194 |
|
|
!!!cp (1014); |
3195 |
|
|
!!!parse-error (type => 'no refc'); |
3196 |
|
|
## Reconsume. |
3197 |
|
|
# |
3198 |
|
|
} |
3199 |
|
|
|
3200 |
wakaba |
1.12 |
my $code = $self->{kwd}; |
3201 |
wakaba |
1.1 |
my $l = $self->{line_prev}; |
3202 |
|
|
my $c = $self->{column_prev}; |
3203 |
|
|
if ($charref_map->{$code}) { |
3204 |
|
|
!!!cp (1015); |
3205 |
|
|
!!!parse-error (type => 'invalid character reference', |
3206 |
|
|
text => (sprintf 'U+%04X', $code), |
3207 |
|
|
line => $l, column => $c); |
3208 |
|
|
$code = $charref_map->{$code}; |
3209 |
|
|
} elsif ($code > 0x10FFFF) { |
3210 |
|
|
!!!cp (1016); |
3211 |
|
|
!!!parse-error (type => 'invalid character reference', |
3212 |
|
|
text => (sprintf 'U-%08X', $code), |
3213 |
|
|
line => $l, column => $c); |
3214 |
|
|
$code = 0xFFFD; |
3215 |
|
|
} |
3216 |
|
|
|
3217 |
|
|
if ($self->{prev_state} == DATA_STATE) { |
3218 |
|
|
!!!cp (992); |
3219 |
|
|
$self->{state} = $self->{prev_state}; |
3220 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
3221 |
wakaba |
1.1 |
## Reconsume. |
3222 |
|
|
!!!emit ({type => CHARACTER_TOKEN, data => chr $code, |
3223 |
wakaba |
1.7 |
has_reference => 1, |
3224 |
wakaba |
1.1 |
line => $l, column => $c, |
3225 |
|
|
}); |
3226 |
|
|
redo A; |
3227 |
|
|
} else { |
3228 |
|
|
!!!cp (991); |
3229 |
|
|
$self->{ca}->{value} .= chr $code; |
3230 |
|
|
$self->{ca}->{has_reference} = 1; |
3231 |
|
|
$self->{state} = $self->{prev_state}; |
3232 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
3233 |
wakaba |
1.1 |
## Reconsume. |
3234 |
|
|
redo A; |
3235 |
|
|
} |
3236 |
|
|
} elsif ($self->{state} == HEXREF_X_STATE) { |
3237 |
|
|
if ((0x0030 <= $self->{nc} and $self->{nc} <= 0x0039) or |
3238 |
|
|
(0x0041 <= $self->{nc} and $self->{nc} <= 0x0046) or |
3239 |
|
|
(0x0061 <= $self->{nc} and $self->{nc} <= 0x0066)) { |
3240 |
|
|
# 0..9, A..F, a..f |
3241 |
|
|
!!!cp (990); |
3242 |
|
|
$self->{state} = HEXREF_HEX_STATE; |
3243 |
wakaba |
1.12 |
$self->{kwd} = 0; |
3244 |
wakaba |
1.1 |
## Reconsume. |
3245 |
|
|
redo A; |
3246 |
|
|
} else { |
3247 |
|
|
!!!parse-error (type => 'bare hcro', |
3248 |
|
|
line => $self->{line_prev}, |
3249 |
|
|
column => $self->{column_prev} - 2); |
3250 |
|
|
|
3251 |
|
|
## NOTE: According to the spec algorithm, nothing is returned, |
3252 |
|
|
## and then "&#" followed by "X" or "x" is appended to the parent |
3253 |
|
|
## element or the attribute value in the later processing. |
3254 |
|
|
|
3255 |
|
|
if ($self->{prev_state} == DATA_STATE) { |
3256 |
|
|
!!!cp (1005); |
3257 |
|
|
$self->{state} = $self->{prev_state}; |
3258 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
3259 |
wakaba |
1.1 |
## Reconsume. |
3260 |
|
|
!!!emit ({type => CHARACTER_TOKEN, |
3261 |
wakaba |
1.12 |
data => '&' . $self->{kwd}, |
3262 |
wakaba |
1.1 |
line => $self->{line_prev}, |
3263 |
wakaba |
1.12 |
column => $self->{column_prev} - length $self->{kwd}, |
3264 |
wakaba |
1.1 |
}); |
3265 |
|
|
redo A; |
3266 |
|
|
} else { |
3267 |
|
|
!!!cp (989); |
3268 |
wakaba |
1.12 |
$self->{ca}->{value} .= '&' . $self->{kwd}; |
3269 |
wakaba |
1.1 |
$self->{state} = $self->{prev_state}; |
3270 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
3271 |
wakaba |
1.1 |
## Reconsume. |
3272 |
|
|
redo A; |
3273 |
|
|
} |
3274 |
|
|
} |
3275 |
|
|
} elsif ($self->{state} == HEXREF_HEX_STATE) { |
3276 |
|
|
if (0x0030 <= $self->{nc} and $self->{nc} <= 0x0039) { |
3277 |
|
|
# 0..9 |
3278 |
|
|
!!!cp (1002); |
3279 |
wakaba |
1.12 |
$self->{kwd} *= 0x10; |
3280 |
|
|
$self->{kwd} += $self->{nc} - 0x0030; |
3281 |
wakaba |
1.1 |
## Stay in the state. |
3282 |
|
|
!!!next-input-character; |
3283 |
|
|
redo A; |
3284 |
|
|
} elsif (0x0061 <= $self->{nc} and |
3285 |
|
|
$self->{nc} <= 0x0066) { # a..f |
3286 |
|
|
!!!cp (1003); |
3287 |
wakaba |
1.12 |
$self->{kwd} *= 0x10; |
3288 |
|
|
$self->{kwd} += $self->{nc} - 0x0060 + 9; |
3289 |
wakaba |
1.1 |
## Stay in the state. |
3290 |
|
|
!!!next-input-character; |
3291 |
|
|
redo A; |
3292 |
|
|
} elsif (0x0041 <= $self->{nc} and |
3293 |
|
|
$self->{nc} <= 0x0046) { # A..F |
3294 |
|
|
!!!cp (1004); |
3295 |
wakaba |
1.12 |
$self->{kwd} *= 0x10; |
3296 |
|
|
$self->{kwd} += $self->{nc} - 0x0040 + 9; |
3297 |
wakaba |
1.1 |
## Stay in the state. |
3298 |
|
|
!!!next-input-character; |
3299 |
|
|
redo A; |
3300 |
|
|
} elsif ($self->{nc} == 0x003B) { # ; |
3301 |
|
|
!!!cp (1006); |
3302 |
|
|
!!!next-input-character; |
3303 |
|
|
# |
3304 |
|
|
} else { |
3305 |
|
|
!!!cp (1007); |
3306 |
|
|
!!!parse-error (type => 'no refc', |
3307 |
|
|
line => $self->{line}, |
3308 |
|
|
column => $self->{column}); |
3309 |
|
|
## Reconsume. |
3310 |
|
|
# |
3311 |
|
|
} |
3312 |
|
|
|
3313 |
wakaba |
1.12 |
my $code = $self->{kwd}; |
3314 |
wakaba |
1.1 |
my $l = $self->{line_prev}; |
3315 |
|
|
my $c = $self->{column_prev}; |
3316 |
|
|
if ($charref_map->{$code}) { |
3317 |
|
|
!!!cp (1008); |
3318 |
|
|
!!!parse-error (type => 'invalid character reference', |
3319 |
|
|
text => (sprintf 'U+%04X', $code), |
3320 |
|
|
line => $l, column => $c); |
3321 |
|
|
$code = $charref_map->{$code}; |
3322 |
|
|
} elsif ($code > 0x10FFFF) { |
3323 |
|
|
!!!cp (1009); |
3324 |
|
|
!!!parse-error (type => 'invalid character reference', |
3325 |
|
|
text => (sprintf 'U-%08X', $code), |
3326 |
|
|
line => $l, column => $c); |
3327 |
|
|
$code = 0xFFFD; |
3328 |
|
|
} |
3329 |
|
|
|
3330 |
|
|
if ($self->{prev_state} == DATA_STATE) { |
3331 |
|
|
!!!cp (988); |
3332 |
|
|
$self->{state} = $self->{prev_state}; |
3333 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
3334 |
wakaba |
1.1 |
## Reconsume. |
3335 |
|
|
!!!emit ({type => CHARACTER_TOKEN, data => chr $code, |
3336 |
wakaba |
1.7 |
has_reference => 1, |
3337 |
wakaba |
1.1 |
line => $l, column => $c, |
3338 |
|
|
}); |
3339 |
|
|
redo A; |
3340 |
|
|
} else { |
3341 |
|
|
!!!cp (987); |
3342 |
|
|
$self->{ca}->{value} .= chr $code; |
3343 |
|
|
$self->{ca}->{has_reference} = 1; |
3344 |
|
|
$self->{state} = $self->{prev_state}; |
3345 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
3346 |
wakaba |
1.1 |
## Reconsume. |
3347 |
|
|
redo A; |
3348 |
|
|
} |
3349 |
|
|
} elsif ($self->{state} == ENTITY_NAME_STATE) { |
3350 |
wakaba |
1.12 |
if (length $self->{kwd} < 30 and |
3351 |
wakaba |
1.1 |
## NOTE: Some number greater than the maximum length of entity name |
3352 |
|
|
((0x0041 <= $self->{nc} and # a |
3353 |
|
|
$self->{nc} <= 0x005A) or # x |
3354 |
|
|
(0x0061 <= $self->{nc} and # a |
3355 |
|
|
$self->{nc} <= 0x007A) or # z |
3356 |
|
|
(0x0030 <= $self->{nc} and # 0 |
3357 |
|
|
$self->{nc} <= 0x0039) or # 9 |
3358 |
|
|
$self->{nc} == 0x003B)) { # ; |
3359 |
|
|
our $EntityChar; |
3360 |
wakaba |
1.12 |
$self->{kwd} .= chr $self->{nc}; |
3361 |
|
|
if (defined $EntityChar->{$self->{kwd}}) { |
3362 |
wakaba |
1.1 |
if ($self->{nc} == 0x003B) { # ; |
3363 |
|
|
!!!cp (1020); |
3364 |
wakaba |
1.12 |
$self->{entity__value} = $EntityChar->{$self->{kwd}}; |
3365 |
wakaba |
1.1 |
$self->{entity__match} = 1; |
3366 |
|
|
!!!next-input-character; |
3367 |
|
|
# |
3368 |
|
|
} else { |
3369 |
|
|
!!!cp (1021); |
3370 |
wakaba |
1.12 |
$self->{entity__value} = $EntityChar->{$self->{kwd}}; |
3371 |
wakaba |
1.1 |
$self->{entity__match} = -1; |
3372 |
|
|
## Stay in the state. |
3373 |
|
|
!!!next-input-character; |
3374 |
|
|
redo A; |
3375 |
|
|
} |
3376 |
|
|
} else { |
3377 |
|
|
!!!cp (1022); |
3378 |
|
|
$self->{entity__value} .= chr $self->{nc}; |
3379 |
|
|
$self->{entity__match} *= 2; |
3380 |
|
|
## Stay in the state. |
3381 |
|
|
!!!next-input-character; |
3382 |
|
|
redo A; |
3383 |
|
|
} |
3384 |
|
|
} |
3385 |
|
|
|
3386 |
|
|
my $data; |
3387 |
|
|
my $has_ref; |
3388 |
|
|
if ($self->{entity__match} > 0) { |
3389 |
|
|
!!!cp (1023); |
3390 |
|
|
$data = $self->{entity__value}; |
3391 |
|
|
$has_ref = 1; |
3392 |
|
|
# |
3393 |
|
|
} elsif ($self->{entity__match} < 0) { |
3394 |
|
|
!!!parse-error (type => 'no refc'); |
3395 |
|
|
if ($self->{prev_state} != DATA_STATE and # in attribute |
3396 |
|
|
$self->{entity__match} < -1) { |
3397 |
|
|
!!!cp (1024); |
3398 |
wakaba |
1.12 |
$data = '&' . $self->{kwd}; |
3399 |
wakaba |
1.1 |
# |
3400 |
|
|
} else { |
3401 |
|
|
!!!cp (1025); |
3402 |
|
|
$data = $self->{entity__value}; |
3403 |
|
|
$has_ref = 1; |
3404 |
|
|
# |
3405 |
|
|
} |
3406 |
|
|
} else { |
3407 |
|
|
!!!cp (1026); |
3408 |
|
|
!!!parse-error (type => 'bare ero', |
3409 |
|
|
line => $self->{line_prev}, |
3410 |
wakaba |
1.12 |
column => $self->{column_prev} - length $self->{kwd}); |
3411 |
|
|
$data = '&' . $self->{kwd}; |
3412 |
wakaba |
1.1 |
# |
3413 |
|
|
} |
3414 |
|
|
|
3415 |
|
|
## NOTE: In these cases, when a character reference is found, |
3416 |
|
|
## it is consumed and a character token is returned, or, otherwise, |
3417 |
|
|
## nothing is consumed and returned, according to the spec algorithm. |
3418 |
|
|
## In this implementation, anything that has been examined by the |
3419 |
|
|
## tokenizer is appended to the parent element or the attribute value |
3420 |
|
|
## as string, either literal string when no character reference or |
3421 |
|
|
## entity-replaced string otherwise, in this stage, since any characters |
3422 |
|
|
## that would not be consumed are appended in the data state or in an |
3423 |
|
|
## appropriate attribute value state anyway. |
3424 |
|
|
|
3425 |
|
|
if ($self->{prev_state} == DATA_STATE) { |
3426 |
|
|
!!!cp (986); |
3427 |
|
|
$self->{state} = $self->{prev_state}; |
3428 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
3429 |
wakaba |
1.1 |
## Reconsume. |
3430 |
|
|
!!!emit ({type => CHARACTER_TOKEN, |
3431 |
|
|
data => $data, |
3432 |
wakaba |
1.7 |
has_reference => $has_ref, |
3433 |
wakaba |
1.1 |
line => $self->{line_prev}, |
3434 |
wakaba |
1.12 |
column => $self->{column_prev} + 1 - length $self->{kwd}, |
3435 |
wakaba |
1.1 |
}); |
3436 |
|
|
redo A; |
3437 |
|
|
} else { |
3438 |
|
|
!!!cp (985); |
3439 |
|
|
$self->{ca}->{value} .= $data; |
3440 |
|
|
$self->{ca}->{has_reference} = 1 if $has_ref; |
3441 |
|
|
$self->{state} = $self->{prev_state}; |
3442 |
wakaba |
1.5 |
$self->{s_kwd} = ''; |
3443 |
wakaba |
1.1 |
## Reconsume. |
3444 |
|
|
redo A; |
3445 |
|
|
} |
3446 |
wakaba |
1.8 |
|
3447 |
|
|
## XML-only states |
3448 |
|
|
|
3449 |
|
|
} elsif ($self->{state} == PI_STATE) { |
3450 |
wakaba |
1.14 |
## XML5: "Pi state" and "DOCTYPE pi state". |
3451 |
|
|
|
3452 |
wakaba |
1.8 |
if ($is_space->{$self->{nc}} or |
3453 |
wakaba |
1.14 |
$self->{nc} == 0x003F or # ? |
3454 |
wakaba |
1.8 |
$self->{nc} == -1) { |
3455 |
wakaba |
1.14 |
## XML5: U+003F: "pi state": Same as "Anything else"; "DOCTYPE |
3456 |
|
|
## pi state": Switch to the "DOCTYPE pi after state". EOF: |
3457 |
|
|
## "DOCTYPE pi state": Parse error, switch to the "data |
3458 |
|
|
## state". |
3459 |
wakaba |
1.8 |
!!!parse-error (type => 'bare pio', ## TODO: type |
3460 |
|
|
line => $self->{line_prev}, |
3461 |
|
|
column => $self->{column_prev} |
3462 |
|
|
- 1 * ($self->{nc} != -1)); |
3463 |
|
|
$self->{state} = BOGUS_COMMENT_STATE; |
3464 |
|
|
## Reconsume. |
3465 |
|
|
$self->{ct} = {type => COMMENT_TOKEN, |
3466 |
|
|
data => '?', |
3467 |
|
|
line => $self->{line_prev}, |
3468 |
|
|
column => $self->{column_prev} |
3469 |
|
|
- 1 * ($self->{nc} != -1), |
3470 |
|
|
}; |
3471 |
|
|
redo A; |
3472 |
|
|
} else { |
3473 |
wakaba |
1.14 |
## XML5: "DOCTYPE pi state": Stay in the state. |
3474 |
wakaba |
1.8 |
$self->{ct} = {type => PI_TOKEN, |
3475 |
|
|
target => chr $self->{nc}, |
3476 |
|
|
data => '', |
3477 |
|
|
line => $self->{line_prev}, |
3478 |
|
|
column => $self->{column_prev} - 1, |
3479 |
|
|
}; |
3480 |
|
|
$self->{state} = PI_TARGET_STATE; |
3481 |
|
|
!!!next-input-character; |
3482 |
|
|
redo A; |
3483 |
|
|
} |
3484 |
|
|
} elsif ($self->{state} == PI_TARGET_STATE) { |
3485 |
|
|
if ($is_space->{$self->{nc}}) { |
3486 |
|
|
$self->{state} = PI_TARGET_AFTER_STATE; |
3487 |
|
|
!!!next-input-character; |
3488 |
|
|
redo A; |
3489 |
|
|
} elsif ($self->{nc} == -1) { |
3490 |
|
|
!!!parse-error (type => 'no pic'); ## TODO: type |
3491 |
wakaba |
1.13 |
if ($self->{in_subset}) { |
3492 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
3493 |
|
|
} else { |
3494 |
|
|
$self->{state} = DATA_STATE; |
3495 |
|
|
$self->{s_kwd} = ''; |
3496 |
|
|
} |
3497 |
wakaba |
1.8 |
## Reconsume. |
3498 |
|
|
!!!emit ($self->{ct}); # pi |
3499 |
|
|
redo A; |
3500 |
|
|
} elsif ($self->{nc} == 0x003F) { # ? |
3501 |
|
|
$self->{state} = PI_AFTER_STATE; |
3502 |
|
|
!!!next-input-character; |
3503 |
|
|
redo A; |
3504 |
|
|
} else { |
3505 |
|
|
## XML5: typo ("tag name" -> "target") |
3506 |
|
|
$self->{ct}->{target} .= chr $self->{nc}; # pi |
3507 |
|
|
!!!next-input-character; |
3508 |
|
|
redo A; |
3509 |
|
|
} |
3510 |
|
|
} elsif ($self->{state} == PI_TARGET_AFTER_STATE) { |
3511 |
|
|
if ($is_space->{$self->{nc}}) { |
3512 |
|
|
## Stay in the state. |
3513 |
|
|
!!!next-input-character; |
3514 |
|
|
redo A; |
3515 |
|
|
} else { |
3516 |
|
|
$self->{state} = PI_DATA_STATE; |
3517 |
|
|
## Reprocess. |
3518 |
|
|
redo A; |
3519 |
|
|
} |
3520 |
|
|
} elsif ($self->{state} == PI_DATA_STATE) { |
3521 |
|
|
if ($self->{nc} == 0x003F) { # ? |
3522 |
|
|
$self->{state} = PI_DATA_AFTER_STATE; |
3523 |
|
|
!!!next-input-character; |
3524 |
|
|
redo A; |
3525 |
|
|
} elsif ($self->{nc} == -1) { |
3526 |
|
|
!!!parse-error (type => 'no pic'); ## TODO: type |
3527 |
wakaba |
1.13 |
if ($self->{in_subset}) { |
3528 |
wakaba |
1.14 |
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state" |
3529 |
wakaba |
1.13 |
} else { |
3530 |
|
|
$self->{state} = DATA_STATE; |
3531 |
|
|
$self->{s_kwd} = ''; |
3532 |
|
|
} |
3533 |
wakaba |
1.8 |
## Reprocess. |
3534 |
|
|
!!!emit ($self->{ct}); # pi |
3535 |
|
|
redo A; |
3536 |
|
|
} else { |
3537 |
|
|
$self->{ct}->{data} .= chr $self->{nc}; # pi |
3538 |
|
|
$self->{read_until}->($self->{ct}->{data}, q[?], |
3539 |
|
|
length $self->{ct}->{data}); |
3540 |
|
|
## Stay in the state. |
3541 |
|
|
!!!next-input-character; |
3542 |
|
|
## Reprocess. |
3543 |
|
|
redo A; |
3544 |
|
|
} |
3545 |
|
|
} elsif ($self->{state} == PI_AFTER_STATE) { |
3546 |
wakaba |
1.14 |
## XML5: Part of "Pi after state". |
3547 |
|
|
|
3548 |
wakaba |
1.8 |
if ($self->{nc} == 0x003E) { # > |
3549 |
wakaba |
1.13 |
if ($self->{in_subset}) { |
3550 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
3551 |
|
|
} else { |
3552 |
|
|
$self->{state} = DATA_STATE; |
3553 |
|
|
$self->{s_kwd} = ''; |
3554 |
|
|
} |
3555 |
wakaba |
1.8 |
!!!next-input-character; |
3556 |
|
|
!!!emit ($self->{ct}); # pi |
3557 |
|
|
redo A; |
3558 |
|
|
} elsif ($self->{nc} == 0x003F) { # ? |
3559 |
|
|
!!!parse-error (type => 'no s after target', ## TODO: type |
3560 |
|
|
line => $self->{line_prev}, |
3561 |
|
|
column => $self->{column_prev}); ## XML5: no error |
3562 |
|
|
$self->{ct}->{data} .= '?'; |
3563 |
|
|
$self->{state} = PI_DATA_AFTER_STATE; |
3564 |
|
|
!!!next-input-character; |
3565 |
|
|
redo A; |
3566 |
|
|
} else { |
3567 |
|
|
!!!parse-error (type => 'no s after target', ## TODO: type |
3568 |
|
|
line => $self->{line_prev}, |
3569 |
|
|
column => $self->{column_prev} |
3570 |
|
|
+ 1 * ($self->{nc} == -1)); ## XML5: no error |
3571 |
|
|
$self->{ct}->{data} .= '?'; ## XML5: not appended |
3572 |
|
|
$self->{state} = PI_DATA_STATE; |
3573 |
|
|
## Reprocess. |
3574 |
|
|
redo A; |
3575 |
|
|
} |
3576 |
|
|
} elsif ($self->{state} == PI_DATA_AFTER_STATE) { |
3577 |
wakaba |
1.14 |
## XML5: Same as "pi after state" and "DOCTYPE pi after state". |
3578 |
|
|
|
3579 |
wakaba |
1.8 |
if ($self->{nc} == 0x003E) { # > |
3580 |
wakaba |
1.13 |
if ($self->{in_subset}) { |
3581 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
3582 |
|
|
} else { |
3583 |
|
|
$self->{state} = DATA_STATE; |
3584 |
|
|
$self->{s_kwd} = ''; |
3585 |
|
|
} |
3586 |
wakaba |
1.8 |
!!!next-input-character; |
3587 |
|
|
!!!emit ($self->{ct}); # pi |
3588 |
|
|
redo A; |
3589 |
|
|
} elsif ($self->{nc} == 0x003F) { # ? |
3590 |
|
|
$self->{ct}->{data} .= '?'; |
3591 |
|
|
## Stay in the state. |
3592 |
|
|
!!!next-input-character; |
3593 |
|
|
redo A; |
3594 |
|
|
} else { |
3595 |
|
|
$self->{ct}->{data} .= '?'; ## XML5: not appended |
3596 |
|
|
$self->{state} = PI_DATA_STATE; |
3597 |
|
|
## Reprocess. |
3598 |
|
|
redo A; |
3599 |
|
|
} |
3600 |
wakaba |
1.12 |
|
3601 |
|
|
} elsif ($self->{state} == DOCTYPE_INTERNAL_SUBSET_STATE) { |
3602 |
|
|
if ($self->{nc} == 0x003C) { # < |
3603 |
wakaba |
1.13 |
$self->{state} = DOCTYPE_TAG_STATE; |
3604 |
wakaba |
1.12 |
!!!next-input-character; |
3605 |
|
|
redo A; |
3606 |
|
|
} elsif ($self->{nc} == 0x0025) { # % |
3607 |
|
|
## XML5: Not defined yet. |
3608 |
|
|
|
3609 |
|
|
## TODO: |
3610 |
|
|
!!!next-input-character; |
3611 |
|
|
redo A; |
3612 |
|
|
} elsif ($self->{nc} == 0x005D) { # ] |
3613 |
wakaba |
1.13 |
delete $self->{in_subset}; |
3614 |
wakaba |
1.12 |
$self->{state} = DOCTYPE_INTERNAL_SUBSET_AFTER_STATE; |
3615 |
|
|
!!!next-input-character; |
3616 |
|
|
redo A; |
3617 |
|
|
} elsif ($is_space->{$self->{nc}}) { |
3618 |
|
|
## Stay in the state. |
3619 |
|
|
!!!next-input-character; |
3620 |
|
|
redo A; |
3621 |
|
|
} elsif ($self->{nc} == -1) { |
3622 |
|
|
!!!parse-error (type => 'unclosed internal subset'); ## TODO: type |
3623 |
wakaba |
1.13 |
delete $self->{in_subset}; |
3624 |
wakaba |
1.12 |
$self->{state} = DATA_STATE; |
3625 |
|
|
$self->{s_kwd} = ''; |
3626 |
|
|
## Reconsume. |
3627 |
wakaba |
1.13 |
!!!emit ({type => END_OF_DOCTYPE_TOKEN}); |
3628 |
wakaba |
1.12 |
redo A; |
3629 |
|
|
} else { |
3630 |
|
|
unless ($self->{internal_subset_tainted}) { |
3631 |
|
|
## XML5: No parse error. |
3632 |
|
|
!!!parse-error (type => 'string in internal subset'); |
3633 |
|
|
$self->{internal_subset_tainted} = 1; |
3634 |
|
|
} |
3635 |
|
|
## Stay in the state. |
3636 |
|
|
!!!next-input-character; |
3637 |
|
|
redo A; |
3638 |
|
|
} |
3639 |
|
|
} elsif ($self->{state} == DOCTYPE_INTERNAL_SUBSET_AFTER_STATE) { |
3640 |
|
|
if ($self->{nc} == 0x003E) { # > |
3641 |
|
|
$self->{state} = DATA_STATE; |
3642 |
|
|
$self->{s_kwd} = ''; |
3643 |
|
|
!!!next-input-character; |
3644 |
wakaba |
1.13 |
!!!emit ({type => END_OF_DOCTYPE_TOKEN}); |
3645 |
wakaba |
1.12 |
redo A; |
3646 |
|
|
} elsif ($self->{nc} == -1) { |
3647 |
|
|
!!!parse-error (type => 'unclosed DOCTYPE'); |
3648 |
|
|
$self->{state} = DATA_STATE; |
3649 |
|
|
$self->{s_kwd} = ''; |
3650 |
|
|
## Reconsume. |
3651 |
wakaba |
1.13 |
!!!emit ({type => END_OF_DOCTYPE_TOKEN}); |
3652 |
wakaba |
1.12 |
redo A; |
3653 |
|
|
} else { |
3654 |
|
|
## XML5: No parse error and stay in the state. |
3655 |
|
|
!!!parse-error (type => 'string after internal subset'); ## TODO: type |
3656 |
|
|
|
3657 |
wakaba |
1.13 |
$self->{state} = BOGUS_DOCTYPE_INTERNAL_SUBSET_AFTER_STATE; |
3658 |
|
|
!!!next-input-character; |
3659 |
|
|
redo A; |
3660 |
|
|
} |
3661 |
|
|
} elsif ($self->{state} == BOGUS_DOCTYPE_INTERNAL_SUBSET_AFTER_STATE) { |
3662 |
|
|
if ($self->{nc} == 0x003E) { # > |
3663 |
|
|
$self->{state} = DATA_STATE; |
3664 |
|
|
$self->{s_kwd} = ''; |
3665 |
|
|
!!!next-input-character; |
3666 |
|
|
!!!emit ({type => END_OF_DOCTYPE_TOKEN}); |
3667 |
|
|
redo A; |
3668 |
|
|
} elsif ($self->{nc} == -1) { |
3669 |
|
|
$self->{state} = DATA_STATE; |
3670 |
|
|
$self->{s_kwd} = ''; |
3671 |
|
|
## Reconsume. |
3672 |
|
|
!!!emit ({type => END_OF_DOCTYPE_TOKEN}); |
3673 |
|
|
redo A; |
3674 |
|
|
} else { |
3675 |
|
|
## Stay in the state. |
3676 |
|
|
!!!next-input-character; |
3677 |
|
|
redo A; |
3678 |
|
|
} |
3679 |
|
|
} elsif ($self->{state} == DOCTYPE_TAG_STATE) { |
3680 |
|
|
if ($self->{nc} == 0x0021) { # ! |
3681 |
wakaba |
1.14 |
$self->{state} = DOCTYPE_MARKUP_DECLARATION_OPEN_STATE; |
3682 |
wakaba |
1.13 |
!!!next-input-character; |
3683 |
|
|
redo A; |
3684 |
|
|
} elsif ($self->{nc} == 0x003F) { # ? |
3685 |
|
|
$self->{state} = PI_STATE; |
3686 |
|
|
!!!next-input-character; |
3687 |
|
|
redo A; |
3688 |
|
|
} elsif ($self->{nc} == -1) { |
3689 |
|
|
!!!parse-error (type => 'bare stago'); |
3690 |
|
|
$self->{state} = DATA_STATE; |
3691 |
|
|
$self->{s_kwd} = ''; |
3692 |
|
|
## Reconsume. |
3693 |
|
|
redo A; |
3694 |
|
|
} else { |
3695 |
|
|
!!!parse-error (type => 'bare stago', ## XML5: Not a parse error. |
3696 |
|
|
line => $self->{line_prev}, |
3697 |
|
|
column => $self->{column_prev}); |
3698 |
|
|
$self->{state} = BOGUS_COMMENT_STATE; |
3699 |
|
|
$self->{ct} = {type => COMMENT_TOKEN, |
3700 |
|
|
data => '', |
3701 |
|
|
}; ## NOTE: Will be discarded. |
3702 |
wakaba |
1.12 |
!!!next-input-character; |
3703 |
|
|
redo A; |
3704 |
|
|
} |
3705 |
wakaba |
1.14 |
} elsif ($self->{state} == DOCTYPE_MARKUP_DECLARATION_OPEN_STATE) { |
3706 |
|
|
## XML5: "DOCTYPE markup declaration state". |
3707 |
|
|
|
3708 |
|
|
if ($self->{nc} == 0x002D) { # - |
3709 |
|
|
$self->{state} = MD_HYPHEN_STATE; |
3710 |
|
|
!!!next-input-character; |
3711 |
|
|
redo A; |
3712 |
wakaba |
1.17 |
} elsif ($self->{nc} == 0x0045 or # E |
3713 |
|
|
$self->{nc} == 0x0065) { # e |
3714 |
wakaba |
1.14 |
$self->{state} = MD_E_STATE; |
3715 |
|
|
$self->{kwd} = chr $self->{nc}; |
3716 |
|
|
!!!next-input-character; |
3717 |
|
|
redo A; |
3718 |
wakaba |
1.17 |
} elsif ($self->{nc} == 0x0041 or # A |
3719 |
|
|
$self->{nc} == 0x0061) { # a |
3720 |
wakaba |
1.14 |
$self->{state} = MD_ATTLIST_STATE; |
3721 |
|
|
$self->{kwd} = chr $self->{nc}; |
3722 |
|
|
!!!next-input-character; |
3723 |
|
|
redo A; |
3724 |
wakaba |
1.17 |
} elsif ($self->{nc} == 0x004E or # N |
3725 |
|
|
$self->{nc} == 0x006E) { # n |
3726 |
wakaba |
1.14 |
$self->{state} = MD_NOTATION_STATE; |
3727 |
|
|
$self->{kwd} = chr $self->{nc}; |
3728 |
|
|
!!!next-input-character; |
3729 |
|
|
redo A; |
3730 |
|
|
} else { |
3731 |
|
|
# |
3732 |
|
|
} |
3733 |
|
|
|
3734 |
|
|
## XML5: No parse error. |
3735 |
|
|
!!!parse-error (type => 'bogus comment', |
3736 |
|
|
line => $self->{line_prev}, |
3737 |
|
|
column => $self->{column_prev} - 1); |
3738 |
|
|
## Reconsume. |
3739 |
|
|
$self->{state} = BOGUS_COMMENT_STATE; |
3740 |
|
|
$self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded. |
3741 |
|
|
redo A; |
3742 |
|
|
} elsif ($self->{state} == MD_E_STATE) { |
3743 |
wakaba |
1.17 |
if ($self->{nc} == 0x004E or # N |
3744 |
|
|
$self->{nc} == 0x006E) { # n |
3745 |
wakaba |
1.14 |
$self->{state} = MD_ENTITY_STATE; |
3746 |
|
|
$self->{kwd} .= chr $self->{nc}; |
3747 |
|
|
!!!next-input-character; |
3748 |
|
|
redo A; |
3749 |
wakaba |
1.17 |
} elsif ($self->{nc} == 0x004C or # L |
3750 |
|
|
$self->{nc} == 0x006C) { # l |
3751 |
wakaba |
1.14 |
## XML5: <!ELEMENT> not supported. |
3752 |
|
|
$self->{state} = MD_ELEMENT_STATE; |
3753 |
|
|
$self->{kwd} .= chr $self->{nc}; |
3754 |
|
|
!!!next-input-character; |
3755 |
|
|
redo A; |
3756 |
|
|
} else { |
3757 |
|
|
## XML5: No parse error. |
3758 |
|
|
!!!parse-error (type => 'bogus comment', |
3759 |
|
|
line => $self->{line_prev}, |
3760 |
|
|
column => $self->{column_prev} - 2 |
3761 |
|
|
+ 1 * ($self->{nc} == -1)); |
3762 |
|
|
## Reconsume. |
3763 |
|
|
$self->{state} = BOGUS_COMMENT_STATE; |
3764 |
|
|
$self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded |
3765 |
|
|
redo A; |
3766 |
|
|
} |
3767 |
|
|
} elsif ($self->{state} == MD_ENTITY_STATE) { |
3768 |
wakaba |
1.17 |
if ($self->{nc} == [ |
3769 |
|
|
undef, |
3770 |
|
|
undef, |
3771 |
|
|
0x0054, # T |
3772 |
|
|
0x0049, # I |
3773 |
|
|
0x0054, # T |
3774 |
|
|
]->[length $self->{kwd}] or |
3775 |
|
|
$self->{nc} == [ |
3776 |
|
|
undef, |
3777 |
|
|
undef, |
3778 |
|
|
0x0074, # t |
3779 |
|
|
0x0069, # i |
3780 |
|
|
0x0074, # t |
3781 |
|
|
]->[length $self->{kwd}]) { |
3782 |
wakaba |
1.14 |
## Stay in the state. |
3783 |
|
|
$self->{kwd} .= chr $self->{nc}; |
3784 |
|
|
!!!next-input-character; |
3785 |
|
|
redo A; |
3786 |
wakaba |
1.17 |
} elsif ((length $self->{kwd}) == 5 and |
3787 |
|
|
($self->{nc} == 0x0059 or # Y |
3788 |
|
|
$self->{nc} == 0x0079)) { # y |
3789 |
|
|
if ($self->{kwd} ne 'ENTIT' or $self->{nc} == 0x0079) { |
3790 |
|
|
!!!parse-error (type => 'lowercase keyword', ## TODO: type |
3791 |
|
|
text => 'ENTITY', |
3792 |
|
|
line => $self->{line_prev}, |
3793 |
|
|
column => $self->{column_prev} - 4); |
3794 |
|
|
} |
3795 |
|
|
$self->{ct} = {type => GENERAL_ENTITY_TOKEN, name => '', |
3796 |
wakaba |
1.14 |
line => $self->{line_prev}, |
3797 |
|
|
column => $self->{column_prev} - 6}; |
3798 |
|
|
$self->{state} = DOCTYPE_MD_STATE; |
3799 |
|
|
!!!next-input-character; |
3800 |
|
|
redo A; |
3801 |
|
|
} else { |
3802 |
|
|
!!!parse-error (type => 'bogus comment', |
3803 |
|
|
line => $self->{line_prev}, |
3804 |
|
|
column => $self->{column_prev} - 1 |
3805 |
|
|
- (length $self->{kwd}) |
3806 |
|
|
+ 1 * ($self->{nc} == -1)); |
3807 |
|
|
$self->{state} = BOGUS_COMMENT_STATE; |
3808 |
|
|
## Reconsume. |
3809 |
|
|
$self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded |
3810 |
|
|
redo A; |
3811 |
|
|
} |
3812 |
|
|
} elsif ($self->{state} == MD_ELEMENT_STATE) { |
3813 |
wakaba |
1.17 |
if ($self->{nc} == [ |
3814 |
|
|
undef, |
3815 |
|
|
undef, |
3816 |
|
|
0x0045, # E |
3817 |
|
|
0x004D, # M |
3818 |
|
|
0x0045, # E |
3819 |
|
|
0x004E, # N |
3820 |
|
|
]->[length $self->{kwd}] or |
3821 |
|
|
$self->{nc} == [ |
3822 |
|
|
undef, |
3823 |
|
|
undef, |
3824 |
|
|
0x0065, # e |
3825 |
|
|
0x006D, # m |
3826 |
|
|
0x0065, # e |
3827 |
|
|
0x006E, # n |
3828 |
|
|
]->[length $self->{kwd}]) { |
3829 |
wakaba |
1.14 |
## Stay in the state. |
3830 |
|
|
$self->{kwd} .= chr $self->{nc}; |
3831 |
|
|
!!!next-input-character; |
3832 |
|
|
redo A; |
3833 |
wakaba |
1.17 |
} elsif ((length $self->{kwd}) == 6 and |
3834 |
|
|
($self->{nc} == 0x0054 or # T |
3835 |
|
|
$self->{nc} == 0x0074)) { # t |
3836 |
|
|
if ($self->{kwd} ne 'ELEMEN' or $self->{nc} == 0x0074) { |
3837 |
|
|
!!!parse-error (type => 'lowercase keyword', ## TODO: type |
3838 |
|
|
text => 'ELEMENT', |
3839 |
|
|
line => $self->{line_prev}, |
3840 |
|
|
column => $self->{column_prev} - 5); |
3841 |
|
|
} |
3842 |
wakaba |
1.14 |
$self->{ct} = {type => ELEMENT_TOKEN, name => '', |
3843 |
|
|
line => $self->{line_prev}, |
3844 |
|
|
column => $self->{column_prev} - 6}; |
3845 |
|
|
$self->{state} = DOCTYPE_MD_STATE; |
3846 |
|
|
!!!next-input-character; |
3847 |
|
|
redo A; |
3848 |
|
|
} else { |
3849 |
|
|
!!!parse-error (type => 'bogus comment', |
3850 |
|
|
line => $self->{line_prev}, |
3851 |
|
|
column => $self->{column_prev} - 1 |
3852 |
|
|
- (length $self->{kwd}) |
3853 |
|
|
+ 1 * ($self->{nc} == -1)); |
3854 |
|
|
$self->{state} = BOGUS_COMMENT_STATE; |
3855 |
|
|
## Reconsume. |
3856 |
|
|
$self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded |
3857 |
|
|
redo A; |
3858 |
|
|
} |
3859 |
|
|
} elsif ($self->{state} == MD_ATTLIST_STATE) { |
3860 |
wakaba |
1.17 |
if ($self->{nc} == [ |
3861 |
|
|
undef, |
3862 |
|
|
0x0054, # T |
3863 |
|
|
0x0054, # T |
3864 |
|
|
0x004C, # L |
3865 |
|
|
0x0049, # I |
3866 |
|
|
0x0053, # S |
3867 |
|
|
]->[length $self->{kwd}] or |
3868 |
|
|
$self->{nc} == [ |
3869 |
|
|
undef, |
3870 |
|
|
0x0074, # t |
3871 |
|
|
0x0074, # t |
3872 |
|
|
0x006C, # l |
3873 |
|
|
0x0069, # i |
3874 |
|
|
0x0073, # s |
3875 |
|
|
]->[length $self->{kwd}]) { |
3876 |
wakaba |
1.14 |
## Stay in the state. |
3877 |
|
|
$self->{kwd} .= chr $self->{nc}; |
3878 |
|
|
!!!next-input-character; |
3879 |
|
|
redo A; |
3880 |
wakaba |
1.17 |
} elsif ((length $self->{kwd}) == 6 and |
3881 |
|
|
($self->{nc} == 0x0054 or # T |
3882 |
|
|
$self->{nc} == 0x0074)) { # t |
3883 |
|
|
if ($self->{kwd} ne 'ATTLIS' or $self->{nc} == 0x0074) { |
3884 |
|
|
!!!parse-error (type => 'lowercase keyword', ## TODO: type |
3885 |
|
|
text => 'ATTLIST', |
3886 |
|
|
line => $self->{line_prev}, |
3887 |
|
|
column => $self->{column_prev} - 5); |
3888 |
|
|
} |
3889 |
wakaba |
1.14 |
$self->{ct} = {type => ATTLIST_TOKEN, name => '', |
3890 |
wakaba |
1.15 |
attrdefs => [], |
3891 |
wakaba |
1.14 |
line => $self->{line_prev}, |
3892 |
|
|
column => $self->{column_prev} - 6}; |
3893 |
|
|
$self->{state} = DOCTYPE_MD_STATE; |
3894 |
|
|
!!!next-input-character; |
3895 |
|
|
redo A; |
3896 |
|
|
} else { |
3897 |
|
|
!!!parse-error (type => 'bogus comment', |
3898 |
|
|
line => $self->{line_prev}, |
3899 |
|
|
column => $self->{column_prev} - 1 |
3900 |
|
|
- (length $self->{kwd}) |
3901 |
|
|
+ 1 * ($self->{nc} == -1)); |
3902 |
|
|
$self->{state} = BOGUS_COMMENT_STATE; |
3903 |
|
|
## Reconsume. |
3904 |
|
|
$self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded |
3905 |
|
|
redo A; |
3906 |
|
|
} |
3907 |
|
|
} elsif ($self->{state} == MD_NOTATION_STATE) { |
3908 |
wakaba |
1.17 |
if ($self->{nc} == [ |
3909 |
|
|
undef, |
3910 |
|
|
0x004F, # O |
3911 |
|
|
0x0054, # T |
3912 |
|
|
0x0041, # A |
3913 |
|
|
0x0054, # T |
3914 |
|
|
0x0049, # I |
3915 |
|
|
0x004F, # O |
3916 |
|
|
]->[length $self->{kwd}] or |
3917 |
|
|
$self->{nc} == [ |
3918 |
|
|
undef, |
3919 |
|
|
0x006F, # o |
3920 |
|
|
0x0074, # t |
3921 |
|
|
0x0061, # a |
3922 |
|
|
0x0074, # t |
3923 |
|
|
0x0069, # i |
3924 |
|
|
0x006F, # o |
3925 |
|
|
]->[length $self->{kwd}]) { |
3926 |
wakaba |
1.14 |
## Stay in the state. |
3927 |
|
|
$self->{kwd} .= chr $self->{nc}; |
3928 |
|
|
!!!next-input-character; |
3929 |
|
|
redo A; |
3930 |
wakaba |
1.17 |
} elsif ((length $self->{kwd}) == 7 and |
3931 |
|
|
($self->{nc} == 0x004E or # N |
3932 |
|
|
$self->{nc} == 0x006E)) { # n |
3933 |
|
|
if ($self->{kwd} ne 'NOTATIO' or $self->{nc} == 0x006E) { |
3934 |
|
|
!!!parse-error (type => 'lowercase keyword', ## TODO: type |
3935 |
|
|
text => 'NOTATION', |
3936 |
|
|
line => $self->{line_prev}, |
3937 |
|
|
column => $self->{column_prev} - 6); |
3938 |
|
|
} |
3939 |
wakaba |
1.14 |
$self->{ct} = {type => NOTATION_TOKEN, name => '', |
3940 |
|
|
line => $self->{line_prev}, |
3941 |
|
|
column => $self->{column_prev} - 6}; |
3942 |
|
|
$self->{state} = DOCTYPE_MD_STATE; |
3943 |
|
|
!!!next-input-character; |
3944 |
|
|
redo A; |
3945 |
|
|
} else { |
3946 |
|
|
!!!parse-error (type => 'bogus comment', |
3947 |
|
|
line => $self->{line_prev}, |
3948 |
|
|
column => $self->{column_prev} - 1 |
3949 |
|
|
- (length $self->{kwd}) |
3950 |
|
|
+ 1 * ($self->{nc} == -1)); |
3951 |
|
|
$self->{state} = BOGUS_COMMENT_STATE; |
3952 |
|
|
## Reconsume. |
3953 |
|
|
$self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded |
3954 |
|
|
redo A; |
3955 |
|
|
} |
3956 |
|
|
} elsif ($self->{state} == DOCTYPE_MD_STATE) { |
3957 |
|
|
## XML5: "DOCTYPE ENTITY state", "DOCTYPE ATTLIST state", and |
3958 |
|
|
## "DOCTYPE NOTATION state". |
3959 |
|
|
|
3960 |
|
|
if ($is_space->{$self->{nc}}) { |
3961 |
|
|
## XML5: [NOTATION] Switch to the "DOCTYPE NOTATION identifier state". |
3962 |
|
|
$self->{state} = BEFORE_MD_NAME_STATE; |
3963 |
|
|
!!!next-input-character; |
3964 |
|
|
redo A; |
3965 |
|
|
} elsif ($self->{ct}->{type} == GENERAL_ENTITY_TOKEN and |
3966 |
|
|
$self->{nc} == 0x0025) { # % |
3967 |
|
|
## XML5: Switch to the "DOCTYPE bogus comment state". |
3968 |
|
|
!!!parse-error (type => 'no space before md name'); ## TODO: type |
3969 |
|
|
$self->{state} = DOCTYPE_ENTITY_PARAMETER_BEFORE_STATE; |
3970 |
|
|
!!!next-input-character; |
3971 |
|
|
redo A; |
3972 |
|
|
} elsif ($self->{nc} == -1) { |
3973 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
3974 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state". |
3975 |
|
|
## Reconsume. |
3976 |
|
|
redo A; |
3977 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
3978 |
|
|
## XML5: Switch to the "DOCTYPE bogus comment state". |
3979 |
|
|
!!!parse-error (type => 'no md name'); ## TODO: type |
3980 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
3981 |
|
|
!!!next-input-character; |
3982 |
|
|
redo A; |
3983 |
|
|
} else { |
3984 |
|
|
## XML5: Switch to the "DOCTYPE bogus comment state". |
3985 |
|
|
!!!parse-error (type => 'no space before md name'); ## TODO: type |
3986 |
|
|
$self->{state} = BEFORE_MD_NAME_STATE; |
3987 |
|
|
redo A; |
3988 |
|
|
} |
3989 |
|
|
} elsif ($self->{state} == BEFORE_MD_NAME_STATE) { |
3990 |
|
|
## XML5: "DOCTYPE ENTITY parameter state", "DOCTYPE ENTITY type |
3991 |
|
|
## before state", "DOCTYPE ATTLIST name before state". |
3992 |
|
|
|
3993 |
|
|
if ($is_space->{$self->{nc}}) { |
3994 |
|
|
## Stay in the state. |
3995 |
|
|
!!!next-input-character; |
3996 |
|
|
redo A; |
3997 |
|
|
} elsif ($self->{ct}->{type} == GENERAL_ENTITY_TOKEN and |
3998 |
|
|
$self->{nc} == 0x0025) { # % |
3999 |
|
|
$self->{state} = DOCTYPE_ENTITY_PARAMETER_BEFORE_STATE; |
4000 |
|
|
!!!next-input-character; |
4001 |
|
|
redo A; |
4002 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4003 |
|
|
## XML5: Same as "Anything else". |
4004 |
|
|
!!!parse-error (type => 'no md name'); ## TODO: type |
4005 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4006 |
|
|
!!!next-input-character; |
4007 |
|
|
redo A; |
4008 |
|
|
} elsif ($self->{nc} == -1) { |
4009 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4010 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state". |
4011 |
|
|
## Reconsume. |
4012 |
|
|
redo A; |
4013 |
|
|
} else { |
4014 |
|
|
## XML5: [ATTLIST] Not defined yet. |
4015 |
|
|
$self->{ct}->{name} .= chr $self->{nc}; |
4016 |
|
|
$self->{state} = MD_NAME_STATE; |
4017 |
|
|
!!!next-input-character; |
4018 |
|
|
redo A; |
4019 |
|
|
} |
4020 |
|
|
} elsif ($self->{state} == DOCTYPE_ENTITY_PARAMETER_BEFORE_STATE) { |
4021 |
|
|
if ($is_space->{$self->{nc}}) { |
4022 |
|
|
## XML5: Switch to the "DOCTYPE ENTITY parameter state". |
4023 |
|
|
$self->{ct}->{type} = PARAMETER_ENTITY_TOKEN; |
4024 |
|
|
$self->{state} = BEFORE_MD_NAME_STATE; |
4025 |
|
|
!!!next-input-character; |
4026 |
|
|
redo A; |
4027 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4028 |
|
|
## XML5: Same as "Anything else". |
4029 |
|
|
!!!parse-error (type => 'no md name'); ## TODO: type |
4030 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4031 |
|
|
!!!next-input-character; |
4032 |
|
|
redo A; |
4033 |
|
|
} elsif ($self->{nc} == -1) { |
4034 |
|
|
!!!parse-error (type => 'unclosed md'); |
4035 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state". |
4036 |
|
|
## Reconsume. |
4037 |
|
|
redo A; |
4038 |
|
|
} else { |
4039 |
|
|
## XML5: No parse error. |
4040 |
|
|
!!!parse-error (type => 'no space after ENTITY percent'); ## TODO: type |
4041 |
|
|
$self->{state} = BOGUS_COMMENT_STATE; |
4042 |
|
|
$self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded |
4043 |
|
|
## Reconsume. |
4044 |
|
|
redo A; |
4045 |
|
|
} |
4046 |
|
|
} elsif ($self->{state} == MD_NAME_STATE) { |
4047 |
|
|
## XML5: "DOCTYPE ENTITY name state" and "DOCTYPE ATTLIST name state". |
4048 |
|
|
|
4049 |
|
|
if ($is_space->{$self->{nc}}) { |
4050 |
wakaba |
1.16 |
if ($self->{ct}->{type} == ATTLIST_TOKEN) { |
4051 |
|
|
$self->{state} = DOCTYPE_ATTLIST_NAME_AFTER_STATE; |
4052 |
|
|
} elsif ($self->{ct}->{type} == ELEMENT_TOKEN) { |
4053 |
wakaba |
1.20 |
$self->{state} = AFTER_ELEMENT_NAME_STATE; |
4054 |
wakaba |
1.16 |
} else { # ENTITY/NOTATION |
4055 |
|
|
$self->{state} = AFTER_DOCTYPE_NAME_STATE; |
4056 |
|
|
} |
4057 |
wakaba |
1.14 |
!!!next-input-character; |
4058 |
|
|
redo A; |
4059 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4060 |
|
|
if ($self->{ct}->{type} == ATTLIST_TOKEN) { |
4061 |
|
|
# |
4062 |
|
|
} else { |
4063 |
wakaba |
1.16 |
!!!parse-error (type => 'no md def'); ## TODO: type |
4064 |
wakaba |
1.14 |
} |
4065 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4066 |
|
|
!!!next-input-character; |
4067 |
|
|
!!!emit ($self->{ct}); # ELEMENT/ENTITY/ATTLIST/NOTATION |
4068 |
|
|
redo A; |
4069 |
|
|
} elsif ($self->{nc} == -1) { |
4070 |
|
|
## XML5: [ATTLIST] No parse error. |
4071 |
|
|
!!!parse-error (type => 'unclosed md'); |
4072 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state". |
4073 |
|
|
## Reconsume. |
4074 |
|
|
!!!emit ($self->{ct}); # ELEMENT/ENTITY/ATTLIST/NOTATION |
4075 |
|
|
redo A; |
4076 |
|
|
} else { |
4077 |
|
|
## XML5: [ATTLIST] Not defined yet. |
4078 |
|
|
$self->{ct}->{name} .= chr $self->{nc}; |
4079 |
|
|
## Stay in the state. |
4080 |
|
|
!!!next-input-character; |
4081 |
|
|
redo A; |
4082 |
|
|
} |
4083 |
|
|
} elsif ($self->{state} == DOCTYPE_ATTLIST_NAME_AFTER_STATE) { |
4084 |
|
|
if ($is_space->{$self->{nc}}) { |
4085 |
|
|
## Stay in the state. |
4086 |
|
|
!!!next-input-character; |
4087 |
|
|
redo A; |
4088 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4089 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4090 |
|
|
!!!next-input-character; |
4091 |
|
|
!!!emit ($self->{ct}); # ATTLIST |
4092 |
|
|
redo A; |
4093 |
|
|
} elsif ($self->{nc} == -1) { |
4094 |
|
|
## XML5: No parse error. |
4095 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4096 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state". |
4097 |
wakaba |
1.15 |
!!!emit ($self->{ct}); |
4098 |
|
|
redo A; |
4099 |
|
|
} else { |
4100 |
|
|
## XML5: Not defined yet. |
4101 |
|
|
$self->{ca} = {name => chr ($self->{nc}), # attrdef |
4102 |
|
|
tokens => [], |
4103 |
|
|
line => $self->{line}, column => $self->{column}}; |
4104 |
|
|
$self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_NAME_STATE; |
4105 |
|
|
!!!next-input-character; |
4106 |
|
|
redo A; |
4107 |
|
|
} |
4108 |
|
|
} elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_NAME_STATE) { |
4109 |
|
|
if ($is_space->{$self->{nc}}) { |
4110 |
|
|
$self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_NAME_AFTER_STATE; |
4111 |
|
|
!!!next-input-character; |
4112 |
|
|
redo A; |
4113 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4114 |
|
|
## XML5: Same as "anything else". |
4115 |
|
|
!!!parse-error (type => 'no attr type'); ## TODO: type |
4116 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4117 |
|
|
!!!next-input-character; |
4118 |
|
|
!!!emit ($self->{ct}); # ATTLIST |
4119 |
|
|
redo A; |
4120 |
|
|
} elsif ($self->{nc} == 0x0028) { # ( |
4121 |
|
|
## XML5: Same as "anything else". |
4122 |
|
|
!!!parse-error (type => 'no space before paren'); ## TODO: type |
4123 |
|
|
$self->{state} = BEFORE_ALLOWED_TOKEN_STATE; |
4124 |
|
|
!!!next-input-character; |
4125 |
|
|
redo A; |
4126 |
|
|
} elsif ($self->{nc} == -1) { |
4127 |
|
|
## XML5: No parse error. |
4128 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4129 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state". |
4130 |
|
|
!!!next-input-character; |
4131 |
|
|
!!!emit ($self->{ct}); # ATTLIST |
4132 |
|
|
redo A; |
4133 |
|
|
} else { |
4134 |
|
|
## XML5: Not defined yet. |
4135 |
|
|
$self->{ca}->{name} .= chr $self->{nc}; |
4136 |
|
|
## Stay in the state. |
4137 |
|
|
!!!next-input-character; |
4138 |
|
|
redo A; |
4139 |
|
|
} |
4140 |
|
|
} elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_NAME_AFTER_STATE) { |
4141 |
|
|
if ($is_space->{$self->{nc}}) { |
4142 |
|
|
## Stay in the state. |
4143 |
|
|
!!!next-input-character; |
4144 |
|
|
redo A; |
4145 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4146 |
|
|
## XML5: Same as "anything else". |
4147 |
|
|
!!!parse-error (type => 'no attr type'); ## TODO: type |
4148 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4149 |
|
|
!!!next-input-character; |
4150 |
|
|
!!!emit ($self->{ct}); # ATTLIST |
4151 |
|
|
redo A; |
4152 |
|
|
} elsif ($self->{nc} == 0x0028) { # ( |
4153 |
|
|
## XML5: Same as "anything else". |
4154 |
|
|
$self->{state} = BEFORE_ALLOWED_TOKEN_STATE; |
4155 |
|
|
!!!next-input-character; |
4156 |
|
|
redo A; |
4157 |
|
|
} elsif ($self->{nc} == -1) { |
4158 |
|
|
## XML5: No parse error. |
4159 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4160 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state". |
4161 |
|
|
!!!next-input-character; |
4162 |
|
|
!!!emit ($self->{ct}); |
4163 |
wakaba |
1.14 |
redo A; |
4164 |
|
|
} else { |
4165 |
|
|
## XML5: Not defined yet. |
4166 |
wakaba |
1.15 |
$self->{ca}->{type} = chr $self->{nc}; |
4167 |
|
|
$self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_TYPE_STATE; |
4168 |
|
|
!!!next-input-character; |
4169 |
|
|
redo A; |
4170 |
|
|
} |
4171 |
|
|
} elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_TYPE_STATE) { |
4172 |
|
|
if ($is_space->{$self->{nc}}) { |
4173 |
|
|
$self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_TYPE_AFTER_STATE; |
4174 |
|
|
!!!next-input-character; |
4175 |
|
|
redo A; |
4176 |
|
|
} elsif ($self->{nc} == 0x0023) { # # |
4177 |
|
|
## XML5: Same as "anything else". |
4178 |
|
|
!!!parse-error (type => 'no space before default value'); ## TODO: type |
4179 |
|
|
$self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE; |
4180 |
|
|
!!!next-input-character; |
4181 |
|
|
redo A; |
4182 |
|
|
} elsif ($self->{nc} == 0x0022) { # " |
4183 |
|
|
## XML5: Same as "anything else". |
4184 |
|
|
!!!parse-error (type => 'no space before default value'); ## TODO: type |
4185 |
|
|
$self->{ca}->{value} = ''; |
4186 |
|
|
$self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE; |
4187 |
|
|
!!!next-input-character; |
4188 |
|
|
redo A; |
4189 |
|
|
} elsif ($self->{nc} == 0x0027) { # ' |
4190 |
|
|
## XML5: Same as "anything else". |
4191 |
|
|
!!!parse-error (type => 'no space before default value'); ## TODO: type |
4192 |
|
|
$self->{ca}->{value} = ''; |
4193 |
|
|
$self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE; |
4194 |
|
|
!!!next-input-character; |
4195 |
|
|
redo A; |
4196 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4197 |
|
|
## XML5: Same as "anything else". |
4198 |
|
|
!!!parse-error (type => 'no attr default'); ## TODO: type |
4199 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4200 |
|
|
!!!next-input-character; |
4201 |
|
|
!!!emit ($self->{ct}); # ATTLIST |
4202 |
|
|
redo A; |
4203 |
|
|
} elsif ($self->{nc} == 0x0028) { # ( |
4204 |
|
|
## XML5: Same as "anything else". |
4205 |
|
|
!!!parse-error (type => 'no space before paren'); ## TODO: type |
4206 |
|
|
$self->{state} = BEFORE_ALLOWED_TOKEN_STATE; |
4207 |
|
|
!!!next-input-character; |
4208 |
|
|
redo A; |
4209 |
|
|
} elsif ($self->{nc} == -1) { |
4210 |
|
|
## XML5: No parse error. |
4211 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4212 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state". |
4213 |
|
|
!!!next-input-character; |
4214 |
|
|
!!!emit ($self->{ct}); |
4215 |
|
|
redo A; |
4216 |
|
|
} else { |
4217 |
|
|
## XML5: Not defined yet. |
4218 |
|
|
$self->{ca}->{type} .= chr $self->{nc}; |
4219 |
|
|
## Stay in the state. |
4220 |
|
|
!!!next-input-character; |
4221 |
|
|
redo A; |
4222 |
|
|
} |
4223 |
|
|
} elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_TYPE_AFTER_STATE) { |
4224 |
|
|
if ($is_space->{$self->{nc}}) { |
4225 |
|
|
## Stay in the state. |
4226 |
|
|
!!!next-input-character; |
4227 |
|
|
redo A; |
4228 |
|
|
} elsif ($self->{nc} == 0x0028) { # ( |
4229 |
|
|
## XML5: Same as "anything else". |
4230 |
|
|
$self->{state} = BEFORE_ALLOWED_TOKEN_STATE; |
4231 |
|
|
!!!next-input-character; |
4232 |
|
|
redo A; |
4233 |
|
|
} elsif ($self->{nc} == 0x0023) { # # |
4234 |
|
|
$self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE; |
4235 |
|
|
!!!next-input-character; |
4236 |
|
|
redo A; |
4237 |
|
|
} elsif ($self->{nc} == 0x0022) { # " |
4238 |
|
|
## XML5: Same as "anything else". |
4239 |
|
|
$self->{ca}->{value} = ''; |
4240 |
|
|
$self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE; |
4241 |
|
|
!!!next-input-character; |
4242 |
|
|
redo A; |
4243 |
|
|
} elsif ($self->{nc} == 0x0027) { # ' |
4244 |
|
|
## XML5: Same as "anything else". |
4245 |
|
|
$self->{ca}->{value} = ''; |
4246 |
|
|
$self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE; |
4247 |
|
|
!!!next-input-character; |
4248 |
|
|
redo A; |
4249 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4250 |
|
|
## XML5: Same as "anything else". |
4251 |
|
|
!!!parse-error (type => 'no attr default'); ## TODO: type |
4252 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4253 |
|
|
!!!next-input-character; |
4254 |
|
|
!!!emit ($self->{ct}); # ATTLIST |
4255 |
|
|
redo A; |
4256 |
|
|
} elsif ($self->{nc} == -1) { |
4257 |
|
|
## XML5: No parse error. |
4258 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4259 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state". |
4260 |
|
|
!!!next-input-character; |
4261 |
|
|
!!!emit ($self->{ct}); |
4262 |
|
|
redo A; |
4263 |
|
|
} else { |
4264 |
|
|
## XML5: Switch to the "DOCTYPE bogus comment state". |
4265 |
|
|
!!!parse-error (type => 'unquoted attr value'); ## TODO: type |
4266 |
|
|
$self->{ca}->{value} = ''; |
4267 |
|
|
$self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE; |
4268 |
|
|
## Reconsume. |
4269 |
|
|
redo A; |
4270 |
|
|
} |
4271 |
|
|
} elsif ($self->{state} == BEFORE_ALLOWED_TOKEN_STATE) { |
4272 |
|
|
if ($is_space->{$self->{nc}}) { |
4273 |
|
|
## Stay in the state. |
4274 |
|
|
!!!next-input-character; |
4275 |
|
|
redo A; |
4276 |
|
|
} elsif ($self->{nc} == 0x007C) { # | |
4277 |
|
|
!!!parse-error (type => 'empty allowed token'); ## TODO: type |
4278 |
|
|
## Stay in the state. |
4279 |
|
|
!!!next-input-character; |
4280 |
|
|
redo A; |
4281 |
|
|
} elsif ($self->{nc} == 0x0029) { # ) |
4282 |
|
|
!!!parse-error (type => 'empty allowed token'); ## TODO: type |
4283 |
|
|
$self->{state} = AFTER_ALLOWED_TOKENS_STATE; |
4284 |
|
|
!!!next-input-character; |
4285 |
|
|
redo A; |
4286 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4287 |
|
|
!!!parse-error (type => 'unclosed allowed tokens'); ## TODO: type |
4288 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4289 |
|
|
!!!next-input-character; |
4290 |
|
|
!!!emit ($self->{ct}); # ATTLIST |
4291 |
|
|
redo A; |
4292 |
|
|
} elsif ($self->{nc} == -1) { |
4293 |
|
|
## XML5: No parse error. |
4294 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4295 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state". |
4296 |
|
|
!!!next-input-character; |
4297 |
|
|
!!!emit ($self->{ct}); |
4298 |
|
|
redo A; |
4299 |
|
|
} else { |
4300 |
|
|
push @{$self->{ca}->{tokens}}, chr $self->{nc}; |
4301 |
|
|
$self->{state} = ALLOWED_TOKEN_STATE; |
4302 |
|
|
!!!next-input-character; |
4303 |
|
|
redo A; |
4304 |
|
|
} |
4305 |
|
|
} elsif ($self->{state} == ALLOWED_TOKEN_STATE) { |
4306 |
|
|
if ($is_space->{$self->{nc}}) { |
4307 |
|
|
$self->{state} = AFTER_ALLOWED_TOKEN_STATE; |
4308 |
|
|
!!!next-input-character; |
4309 |
|
|
redo A; |
4310 |
|
|
} elsif ($self->{nc} == 0x007C) { # | |
4311 |
|
|
$self->{state} = BEFORE_ALLOWED_TOKEN_STATE; |
4312 |
|
|
!!!next-input-character; |
4313 |
|
|
redo A; |
4314 |
|
|
} elsif ($self->{nc} == 0x0029) { # ) |
4315 |
|
|
$self->{state} = AFTER_ALLOWED_TOKENS_STATE; |
4316 |
|
|
!!!next-input-character; |
4317 |
|
|
redo A; |
4318 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4319 |
|
|
!!!parse-error (type => 'unclosed allowed tokens'); ## TODO: type |
4320 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4321 |
|
|
!!!next-input-character; |
4322 |
|
|
!!!emit ($self->{ct}); # ATTLIST |
4323 |
|
|
redo A; |
4324 |
|
|
} elsif ($self->{nc} == -1) { |
4325 |
|
|
## XML5: No parse error. |
4326 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4327 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state". |
4328 |
|
|
!!!next-input-character; |
4329 |
|
|
!!!emit ($self->{ct}); |
4330 |
|
|
redo A; |
4331 |
|
|
} else { |
4332 |
|
|
$self->{ca}->{tokens}->[-1] .= chr $self->{nc}; |
4333 |
|
|
## Stay in the state. |
4334 |
|
|
!!!next-input-character; |
4335 |
|
|
redo A; |
4336 |
|
|
} |
4337 |
|
|
} elsif ($self->{state} == AFTER_ALLOWED_TOKEN_STATE) { |
4338 |
|
|
if ($is_space->{$self->{nc}}) { |
4339 |
|
|
## Stay in the state. |
4340 |
|
|
!!!next-input-character; |
4341 |
|
|
redo A; |
4342 |
|
|
} elsif ($self->{nc} == 0x007C) { # | |
4343 |
|
|
$self->{state} = BEFORE_ALLOWED_TOKEN_STATE; |
4344 |
|
|
!!!next-input-character; |
4345 |
|
|
redo A; |
4346 |
|
|
} elsif ($self->{nc} == 0x0029) { # ) |
4347 |
|
|
$self->{state} = AFTER_ALLOWED_TOKENS_STATE; |
4348 |
|
|
!!!next-input-character; |
4349 |
|
|
redo A; |
4350 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4351 |
|
|
!!!parse-error (type => 'unclosed allowed tokens'); ## TODO: type |
4352 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4353 |
|
|
!!!next-input-character; |
4354 |
|
|
!!!emit ($self->{ct}); # ATTLIST |
4355 |
|
|
redo A; |
4356 |
|
|
} elsif ($self->{nc} == -1) { |
4357 |
|
|
## XML5: No parse error. |
4358 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4359 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state". |
4360 |
|
|
!!!next-input-character; |
4361 |
|
|
!!!emit ($self->{ct}); |
4362 |
|
|
redo A; |
4363 |
|
|
} else { |
4364 |
|
|
!!!parse-error (type => 'space in allowed token', ## TODO: type |
4365 |
|
|
line => $self->{line_prev}, |
4366 |
|
|
column => $self->{column_prev}); |
4367 |
|
|
$self->{ca}->{tokens}->[-1] .= ' ' . chr $self->{nc}; |
4368 |
|
|
$self->{state} = ALLOWED_TOKEN_STATE; |
4369 |
|
|
!!!next-input-character; |
4370 |
|
|
redo A; |
4371 |
|
|
} |
4372 |
|
|
} elsif ($self->{state} == AFTER_ALLOWED_TOKENS_STATE) { |
4373 |
|
|
if ($is_space->{$self->{nc}}) { |
4374 |
|
|
$self->{state} = BEFORE_ATTR_DEFAULT_STATE; |
4375 |
|
|
!!!next-input-character; |
4376 |
|
|
redo A; |
4377 |
|
|
} elsif ($self->{nc} == 0x0023) { # # |
4378 |
|
|
!!!parse-error (type => 'no space before default value'); ## TODO: type |
4379 |
|
|
$self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE; |
4380 |
|
|
!!!next-input-character; |
4381 |
|
|
redo A; |
4382 |
|
|
} elsif ($self->{nc} == 0x0022) { # " |
4383 |
|
|
!!!parse-error (type => 'no space before default value'); ## TODO: type |
4384 |
|
|
$self->{ca}->{value} = ''; |
4385 |
|
|
$self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE; |
4386 |
|
|
!!!next-input-character; |
4387 |
|
|
redo A; |
4388 |
|
|
} elsif ($self->{nc} == 0x0027) { # ' |
4389 |
|
|
!!!parse-error (type => 'no space before default value'); ## TODO: type |
4390 |
|
|
$self->{ca}->{value} = ''; |
4391 |
|
|
$self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE; |
4392 |
|
|
!!!next-input-character; |
4393 |
|
|
redo A; |
4394 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4395 |
|
|
!!!parse-error (type => 'no attr default'); ## TODO: type |
4396 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4397 |
|
|
!!!next-input-character; |
4398 |
|
|
!!!emit ($self->{ct}); # ATTLIST |
4399 |
|
|
redo A; |
4400 |
|
|
} elsif ($self->{nc} == -1) { |
4401 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4402 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4403 |
|
|
!!!next-input-character; |
4404 |
|
|
!!!emit ($self->{ct}); |
4405 |
|
|
redo A; |
4406 |
|
|
} else { |
4407 |
|
|
!!!parse-error (type => 'unquoted attr value'); ## TODO: type |
4408 |
|
|
$self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE; |
4409 |
|
|
## Reconsume. |
4410 |
|
|
redo A; |
4411 |
|
|
} |
4412 |
|
|
} elsif ($self->{state} == BEFORE_ATTR_DEFAULT_STATE) { |
4413 |
|
|
if ($is_space->{$self->{nc}}) { |
4414 |
|
|
## Stay in the state. |
4415 |
|
|
!!!next-input-character; |
4416 |
|
|
redo A; |
4417 |
|
|
} elsif ($self->{nc} == 0x0023) { # # |
4418 |
|
|
$self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE; |
4419 |
|
|
!!!next-input-character; |
4420 |
|
|
redo A; |
4421 |
|
|
} elsif ($self->{nc} == 0x0022) { # " |
4422 |
|
|
$self->{ca}->{value} = ''; |
4423 |
|
|
$self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE; |
4424 |
|
|
!!!next-input-character; |
4425 |
|
|
redo A; |
4426 |
|
|
} elsif ($self->{nc} == 0x0027) { # ' |
4427 |
|
|
$self->{ca}->{value} = ''; |
4428 |
|
|
$self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE; |
4429 |
|
|
!!!next-input-character; |
4430 |
|
|
redo A; |
4431 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4432 |
|
|
!!!parse-error (type => 'no attr default'); ## TODO: type |
4433 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4434 |
|
|
!!!next-input-character; |
4435 |
|
|
!!!emit ($self->{ct}); # ATTLIST |
4436 |
|
|
redo A; |
4437 |
|
|
} elsif ($self->{nc} == -1) { |
4438 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4439 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4440 |
|
|
!!!next-input-character; |
4441 |
|
|
!!!emit ($self->{ct}); |
4442 |
|
|
redo A; |
4443 |
|
|
} else { |
4444 |
|
|
!!!parse-error (type => 'unquoted attr value'); ## TODO: type |
4445 |
|
|
$self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE; |
4446 |
|
|
## Reconsume. |
4447 |
|
|
redo A; |
4448 |
|
|
} |
4449 |
|
|
} elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE) { |
4450 |
|
|
if ($is_space->{$self->{nc}}) { |
4451 |
|
|
## XML5: No parse error. |
4452 |
|
|
!!!parse-error (type => 'no default type'); ## TODO: type |
4453 |
wakaba |
1.16 |
$self->{state} = BOGUS_MD_STATE; |
4454 |
wakaba |
1.14 |
## Reconsume. |
4455 |
|
|
redo A; |
4456 |
wakaba |
1.15 |
} elsif ($self->{nc} == 0x0022) { # " |
4457 |
|
|
## XML5: Same as "anything else". |
4458 |
|
|
$self->{ca}->{value} = ''; |
4459 |
|
|
$self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE; |
4460 |
|
|
!!!next-input-character; |
4461 |
|
|
redo A; |
4462 |
|
|
} elsif ($self->{nc} == 0x0027) { # ' |
4463 |
|
|
## XML5: Same as "anything else". |
4464 |
|
|
$self->{ca}->{value} = ''; |
4465 |
|
|
$self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE; |
4466 |
|
|
!!!next-input-character; |
4467 |
|
|
redo A; |
4468 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4469 |
|
|
## XML5: Same as "anything else". |
4470 |
|
|
!!!parse-error (type => 'no attr default'); ## TODO: type |
4471 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4472 |
|
|
!!!next-input-character; |
4473 |
|
|
!!!emit ($self->{ct}); # ATTLIST |
4474 |
|
|
redo A; |
4475 |
|
|
} elsif ($self->{nc} == -1) { |
4476 |
|
|
## XML5: No parse error. |
4477 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4478 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state". |
4479 |
|
|
!!!next-input-character; |
4480 |
|
|
!!!emit ($self->{ct}); |
4481 |
|
|
redo A; |
4482 |
|
|
} else { |
4483 |
|
|
$self->{ca}->{default} = chr $self->{nc}; |
4484 |
|
|
$self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_STATE; |
4485 |
|
|
!!!next-input-character; |
4486 |
|
|
redo A; |
4487 |
wakaba |
1.14 |
} |
4488 |
wakaba |
1.15 |
} elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_STATE) { |
4489 |
|
|
if ($is_space->{$self->{nc}}) { |
4490 |
|
|
$self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_AFTER_STATE; |
4491 |
|
|
!!!next-input-character; |
4492 |
|
|
redo A; |
4493 |
|
|
} elsif ($self->{nc} == 0x0022) { # " |
4494 |
|
|
## XML5: Same as "anything else". |
4495 |
|
|
!!!parse-error (type => 'no space before default value'); ## TODO: type |
4496 |
|
|
$self->{ca}->{value} = ''; |
4497 |
|
|
$self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE; |
4498 |
|
|
!!!next-input-character; |
4499 |
|
|
redo A; |
4500 |
|
|
} elsif ($self->{nc} == 0x0027) { # ' |
4501 |
|
|
## XML5: Same as "anything else". |
4502 |
|
|
!!!parse-error (type => 'no space before default value'); ## TODO: type |
4503 |
|
|
$self->{ca}->{value} = ''; |
4504 |
|
|
$self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE; |
4505 |
|
|
!!!next-input-character; |
4506 |
|
|
redo A; |
4507 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4508 |
|
|
## XML5: Same as "anything else". |
4509 |
|
|
push @{$self->{ct}->{attrdefs}}, $self->{ca}; |
4510 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4511 |
|
|
!!!next-input-character; |
4512 |
|
|
!!!emit ($self->{ct}); # ATTLIST |
4513 |
|
|
redo A; |
4514 |
|
|
} elsif ($self->{nc} == -1) { |
4515 |
|
|
## XML5: No parse error. |
4516 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4517 |
|
|
push @{$self->{ct}->{attrdefs}}, $self->{ca}; |
4518 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state". |
4519 |
|
|
!!!next-input-character; |
4520 |
|
|
!!!emit ($self->{ct}); |
4521 |
|
|
redo A; |
4522 |
|
|
} else { |
4523 |
|
|
$self->{ca}->{default} .= chr $self->{nc}; |
4524 |
|
|
## Stay in the state. |
4525 |
|
|
!!!next-input-character; |
4526 |
|
|
redo A; |
4527 |
|
|
} |
4528 |
|
|
} elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_AFTER_STATE) { |
4529 |
|
|
if ($is_space->{$self->{nc}}) { |
4530 |
|
|
## Stay in the state. |
4531 |
|
|
!!!next-input-character; |
4532 |
|
|
redo A; |
4533 |
|
|
} elsif ($self->{nc} == 0x0022) { # " |
4534 |
|
|
$self->{ca}->{value} = ''; |
4535 |
|
|
$self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE; |
4536 |
|
|
!!!next-input-character; |
4537 |
|
|
redo A; |
4538 |
|
|
} elsif ($self->{nc} == 0x0027) { # ' |
4539 |
|
|
$self->{ca}->{value} = ''; |
4540 |
|
|
$self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE; |
4541 |
|
|
!!!next-input-character; |
4542 |
|
|
redo A; |
4543 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4544 |
|
|
push @{$self->{ct}->{attrdefs}}, $self->{ca}; |
4545 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4546 |
|
|
!!!next-input-character; |
4547 |
|
|
!!!emit ($self->{ct}); # ATTLIST |
4548 |
|
|
redo A; |
4549 |
|
|
} elsif ($self->{nc} == -1) { |
4550 |
|
|
## XML5: No parse error. |
4551 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4552 |
|
|
push @{$self->{ct}->{attrdefs}}, $self->{ca}; |
4553 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state". |
4554 |
|
|
!!!next-input-character; |
4555 |
|
|
!!!emit ($self->{ct}); |
4556 |
|
|
redo A; |
4557 |
|
|
} else { |
4558 |
|
|
## XML5: Not defined yet. |
4559 |
|
|
if ($self->{ca}->{default} eq 'FIXED') { |
4560 |
|
|
$self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE; |
4561 |
|
|
} else { |
4562 |
|
|
push @{$self->{ct}->{attrdefs}}, $self->{ca}; |
4563 |
|
|
$self->{state} = DOCTYPE_ATTLIST_NAME_AFTER_STATE; |
4564 |
|
|
} |
4565 |
|
|
## Reconsume. |
4566 |
|
|
redo A; |
4567 |
|
|
} |
4568 |
|
|
} elsif ($self->{state} == AFTER_ATTLIST_ATTR_VALUE_QUOTED_STATE) { |
4569 |
|
|
if ($is_space->{$self->{nc}} or |
4570 |
|
|
$self->{nc} == -1 or |
4571 |
|
|
$self->{nc} == 0x003E) { # > |
4572 |
|
|
$self->{state} = DOCTYPE_ATTLIST_NAME_AFTER_STATE; |
4573 |
|
|
## Reconsume. |
4574 |
|
|
redo A; |
4575 |
|
|
} else { |
4576 |
|
|
!!!parse-error (type => 'no space before attr name'); ## TODO: type |
4577 |
|
|
$self->{state} = DOCTYPE_ATTLIST_NAME_AFTER_STATE; |
4578 |
|
|
## Reconsume. |
4579 |
|
|
redo A; |
4580 |
wakaba |
1.16 |
} |
4581 |
wakaba |
1.18 |
} elsif ($self->{state} == NDATA_STATE) { |
4582 |
|
|
## ASCII case-insensitive |
4583 |
|
|
if ($self->{nc} == [ |
4584 |
|
|
undef, |
4585 |
|
|
0x0044, # D |
4586 |
|
|
0x0041, # A |
4587 |
|
|
0x0054, # T |
4588 |
|
|
]->[length $self->{kwd}] or |
4589 |
|
|
$self->{nc} == [ |
4590 |
|
|
undef, |
4591 |
|
|
0x0064, # d |
4592 |
|
|
0x0061, # a |
4593 |
|
|
0x0074, # t |
4594 |
|
|
]->[length $self->{kwd}]) { |
4595 |
|
|
!!!cp (172.2); |
4596 |
|
|
## Stay in the state. |
4597 |
|
|
$self->{kwd} .= chr $self->{nc}; |
4598 |
|
|
!!!next-input-character; |
4599 |
|
|
redo A; |
4600 |
|
|
} elsif ((length $self->{kwd}) == 4 and |
4601 |
|
|
($self->{nc} == 0x0041 or # A |
4602 |
|
|
$self->{nc} == 0x0061)) { # a |
4603 |
|
|
if ($self->{kwd} ne 'NDAT' or $self->{nc} == 0x0061) { # a |
4604 |
|
|
!!!cp (172.3); |
4605 |
|
|
!!!parse-error (type => 'lowercase keyword', ## TODO: type |
4606 |
|
|
text => 'NDATA', |
4607 |
|
|
line => $self->{line_prev}, |
4608 |
|
|
column => $self->{column_prev} - 4); |
4609 |
|
|
} else { |
4610 |
|
|
!!!cp (172.4); |
4611 |
|
|
} |
4612 |
|
|
$self->{state} = AFTER_NDATA_STATE; |
4613 |
|
|
!!!next-input-character; |
4614 |
|
|
redo A; |
4615 |
|
|
} else { |
4616 |
|
|
!!!parse-error (type => 'string after literal', ## TODO: type |
4617 |
|
|
line => $self->{line_prev}, |
4618 |
|
|
column => $self->{column_prev} + 1 |
4619 |
|
|
- length $self->{kwd}); |
4620 |
|
|
!!!cp (172.5); |
4621 |
|
|
$self->{state} = BOGUS_MD_STATE; |
4622 |
|
|
## Reconsume. |
4623 |
|
|
redo A; |
4624 |
|
|
} |
4625 |
|
|
} elsif ($self->{state} == AFTER_NDATA_STATE) { |
4626 |
|
|
if ($is_space->{$self->{nc}}) { |
4627 |
|
|
$self->{state} = BEFORE_NOTATION_NAME_STATE; |
4628 |
|
|
!!!next-input-character; |
4629 |
|
|
redo A; |
4630 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4631 |
|
|
!!!parse-error (type => 'no notation name'); ## TODO: type |
4632 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4633 |
|
|
!!!next-input-character; |
4634 |
|
|
!!!emit ($self->{ct}); # ENTITY |
4635 |
|
|
redo A; |
4636 |
|
|
} elsif ($self->{nc} == -1) { |
4637 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4638 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4639 |
|
|
!!!next-input-character; |
4640 |
|
|
!!!emit ($self->{ct}); # ENTITY |
4641 |
|
|
redo A; |
4642 |
|
|
} else { |
4643 |
|
|
!!!parse-error (type => 'string after literal', ## TODO: type |
4644 |
|
|
line => $self->{line_prev}, |
4645 |
|
|
column => $self->{column_prev} + 1 |
4646 |
|
|
- length $self->{kwd}); |
4647 |
|
|
$self->{state} = BOGUS_MD_STATE; |
4648 |
|
|
## Reconsume. |
4649 |
|
|
redo A; |
4650 |
|
|
} |
4651 |
|
|
} elsif ($self->{state} == BEFORE_NOTATION_NAME_STATE) { |
4652 |
|
|
if ($is_space->{$self->{nc}}) { |
4653 |
|
|
## Stay in the state. |
4654 |
|
|
!!!next-input-character; |
4655 |
|
|
redo A; |
4656 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4657 |
|
|
!!!parse-error (type => 'no notation name'); ## TODO: type |
4658 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4659 |
|
|
!!!next-input-character; |
4660 |
|
|
!!!emit ($self->{ct}); # ENTITY |
4661 |
|
|
redo A; |
4662 |
|
|
} elsif ($self->{nc} == -1) { |
4663 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4664 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4665 |
|
|
!!!next-input-character; |
4666 |
|
|
!!!emit ($self->{ct}); # ENTITY |
4667 |
|
|
redo A; |
4668 |
|
|
} else { |
4669 |
|
|
$self->{ct}->{notation} = chr $self->{nc}; # ENTITY |
4670 |
|
|
$self->{state} = NOTATION_NAME_STATE; |
4671 |
|
|
!!!next-input-character; |
4672 |
|
|
redo A; |
4673 |
|
|
} |
4674 |
|
|
} elsif ($self->{state} == NOTATION_NAME_STATE) { |
4675 |
|
|
if ($is_space->{$self->{nc}}) { |
4676 |
wakaba |
1.20 |
$self->{state} = AFTER_MD_DEF_STATE; |
4677 |
wakaba |
1.18 |
!!!next-input-character; |
4678 |
|
|
redo A; |
4679 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4680 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4681 |
|
|
!!!next-input-character; |
4682 |
|
|
!!!emit ($self->{ct}); # ENTITY |
4683 |
|
|
redo A; |
4684 |
|
|
} elsif ($self->{nc} == -1) { |
4685 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4686 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4687 |
|
|
!!!next-input-character; |
4688 |
|
|
!!!emit ($self->{ct}); # ENTITY |
4689 |
|
|
redo A; |
4690 |
|
|
} else { |
4691 |
|
|
$self->{ct}->{notation} .= chr $self->{nc}; # ENTITY |
4692 |
|
|
## Stay in the state. |
4693 |
|
|
!!!next-input-character; |
4694 |
|
|
redo A; |
4695 |
|
|
} |
4696 |
wakaba |
1.19 |
} elsif ($self->{state} == DOCTYPE_ENTITY_VALUE_DOUBLE_QUOTED_STATE) { |
4697 |
|
|
if ($self->{nc} == 0x0022) { # " |
4698 |
wakaba |
1.20 |
$self->{state} = AFTER_MD_DEF_STATE; |
4699 |
wakaba |
1.19 |
!!!next-input-character; |
4700 |
|
|
redo A; |
4701 |
|
|
} elsif ($self->{nc} == 0x0026) { # & |
4702 |
|
|
$self->{prev_state} = $self->{state}; |
4703 |
|
|
$self->{state} = ENTITY_VALUE_ENTITY_STATE; |
4704 |
|
|
$self->{entity_add} = 0x0022; # " |
4705 |
|
|
!!!next-input-character; |
4706 |
|
|
redo A; |
4707 |
|
|
## TODO: % |
4708 |
|
|
} elsif ($self->{nc} == -1) { |
4709 |
|
|
!!!parse-error (type => 'unclosed entity value'); ## TODO: type |
4710 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4711 |
|
|
## Reconsume. |
4712 |
|
|
!!!emit ($self->{ct}); # ENTITY |
4713 |
|
|
redo A; |
4714 |
|
|
} else { |
4715 |
|
|
$self->{ct}->{value} .= chr $self->{nc}; # ENTITY |
4716 |
|
|
!!!next-input-character; |
4717 |
|
|
redo A; |
4718 |
|
|
} |
4719 |
|
|
} elsif ($self->{state} == DOCTYPE_ENTITY_VALUE_SINGLE_QUOTED_STATE) { |
4720 |
|
|
if ($self->{nc} == 0x0027) { # ' |
4721 |
wakaba |
1.20 |
$self->{state} = AFTER_MD_DEF_STATE; |
4722 |
wakaba |
1.19 |
!!!next-input-character; |
4723 |
|
|
redo A; |
4724 |
|
|
} elsif ($self->{nc} == 0x0026) { # & |
4725 |
|
|
$self->{prev_state} = $self->{state}; |
4726 |
|
|
$self->{state} = ENTITY_VALUE_ENTITY_STATE; |
4727 |
|
|
$self->{entity_add} = 0x0027; # ' |
4728 |
|
|
!!!next-input-character; |
4729 |
|
|
redo A; |
4730 |
|
|
## TODO: % |
4731 |
|
|
} elsif ($self->{nc} == -1) { |
4732 |
|
|
!!!parse-error (type => 'unclosed entity value'); ## TODO: type |
4733 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4734 |
|
|
## Reconsume. |
4735 |
|
|
!!!emit ($self->{ct}); # ENTITY |
4736 |
|
|
redo A; |
4737 |
|
|
} else { |
4738 |
|
|
$self->{ct}->{value} .= chr $self->{nc}; # ENTITY |
4739 |
|
|
!!!next-input-character; |
4740 |
|
|
redo A; |
4741 |
|
|
} |
4742 |
|
|
} elsif ($self->{state} == ENTITY_VALUE_ENTITY_STATE) { |
4743 |
|
|
## TODO: XMLize |
4744 |
|
|
|
4745 |
|
|
if ($is_space->{$self->{nc}} or |
4746 |
|
|
{ |
4747 |
|
|
0x003C => 1, 0x0026 => 1, -1 => 1, # <, & |
4748 |
|
|
$self->{entity_add} => 1, |
4749 |
|
|
}->{$self->{nc}}) { |
4750 |
|
|
## Don't consume |
4751 |
|
|
## No error |
4752 |
|
|
## Return nothing. |
4753 |
|
|
# |
4754 |
|
|
} elsif ($self->{nc} == 0x0023) { # # |
4755 |
|
|
$self->{ca} = $self->{ct}; |
4756 |
|
|
$self->{state} = ENTITY_HASH_STATE; |
4757 |
|
|
$self->{kwd} = '#'; |
4758 |
|
|
!!!next-input-character; |
4759 |
|
|
redo A; |
4760 |
|
|
} elsif ((0x0041 <= $self->{nc} and |
4761 |
|
|
$self->{nc} <= 0x005A) or # A..Z |
4762 |
|
|
(0x0061 <= $self->{nc} and |
4763 |
|
|
$self->{nc} <= 0x007A)) { # a..z |
4764 |
|
|
# |
4765 |
|
|
} else { |
4766 |
|
|
!!!parse-error (type => 'bare ero'); |
4767 |
|
|
## Return nothing. |
4768 |
|
|
# |
4769 |
|
|
} |
4770 |
|
|
|
4771 |
|
|
$self->{ct}->{value} .= '&'; |
4772 |
|
|
$self->{state} = $self->{prev_state}; |
4773 |
|
|
## Reconsume. |
4774 |
|
|
redo A; |
4775 |
wakaba |
1.20 |
} elsif ($self->{state} == AFTER_ELEMENT_NAME_STATE) { |
4776 |
|
|
if ($is_space->{$self->{nc}}) { |
4777 |
|
|
$self->{state} = BEFORE_ELEMENT_CONTENT_STATE; |
4778 |
|
|
!!!next-input-character; |
4779 |
|
|
redo A; |
4780 |
|
|
} elsif ($self->{nc} == 0x0028) { # ( |
4781 |
|
|
$self->{state} = AFTER_CM_GROUP_OPEN_STATE; |
4782 |
|
|
$self->{ct}->{content} = ['(']; |
4783 |
|
|
$self->{group_depth} = 1; |
4784 |
|
|
!!!next-input-character; |
4785 |
|
|
redo A; |
4786 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4787 |
|
|
!!!parse-error (type => 'no md def'); ## TODO: type |
4788 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4789 |
|
|
!!!next-input-character; |
4790 |
|
|
!!!emit ($self->{ct}); # ELEMENT |
4791 |
|
|
redo A; |
4792 |
|
|
} elsif ($self->{nc} == -1) { |
4793 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4794 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4795 |
|
|
!!!next-input-character; |
4796 |
|
|
!!!emit ($self->{ct}); # ELEMENT |
4797 |
|
|
redo A; |
4798 |
|
|
} else { |
4799 |
|
|
$self->{ct}->{content} = [chr $self->{nc}]; |
4800 |
|
|
$self->{state} = CONTENT_KEYWORD_STATE; |
4801 |
|
|
!!!next-input-character; |
4802 |
|
|
redo A; |
4803 |
|
|
} |
4804 |
|
|
} elsif ($self->{state} == CONTENT_KEYWORD_STATE) { |
4805 |
|
|
if ($is_space->{$self->{nc}}) { |
4806 |
|
|
$self->{state} = AFTER_MD_DEF_STATE; |
4807 |
|
|
!!!next-input-character; |
4808 |
|
|
redo A; |
4809 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4810 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4811 |
|
|
!!!next-input-character; |
4812 |
|
|
!!!emit ($self->{ct}); # ELEMENT |
4813 |
|
|
redo A; |
4814 |
|
|
} elsif ($self->{nc} == -1) { |
4815 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4816 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4817 |
|
|
!!!next-input-character; |
4818 |
|
|
!!!emit ($self->{ct}); # ELEMENT |
4819 |
|
|
redo A; |
4820 |
|
|
} else { |
4821 |
|
|
$self->{ct}->{content}->[-1] .= chr $self->{nc}; # ELEMENT |
4822 |
|
|
## Stay in the state. |
4823 |
|
|
!!!next-input-character; |
4824 |
|
|
redo A; |
4825 |
|
|
} |
4826 |
|
|
} elsif ($self->{state} == AFTER_CM_GROUP_OPEN_STATE) { |
4827 |
|
|
if ($is_space->{$self->{nc}}) { |
4828 |
|
|
## Stay in the state. |
4829 |
|
|
!!!next-input-character; |
4830 |
|
|
redo A; |
4831 |
|
|
} elsif ($self->{nc} == 0x0028) { # ( |
4832 |
|
|
$self->{group_depth}++; |
4833 |
|
|
push @{$self->{ct}->{content}}, chr $self->{nc}; |
4834 |
|
|
## Stay in the state. |
4835 |
|
|
!!!next-input-character; |
4836 |
|
|
redo A; |
4837 |
|
|
} elsif ($self->{nc} == 0x007C or # | |
4838 |
|
|
$self->{nc} == 0x002C) { # , |
4839 |
|
|
!!!parse-error (type => 'empty element name'); ## TODO: type |
4840 |
|
|
## Stay in the state. |
4841 |
|
|
!!!next-input-character; |
4842 |
|
|
redo A; |
4843 |
|
|
} elsif ($self->{nc} == 0x0029) { # ) |
4844 |
|
|
!!!parse-error (type => 'empty element name'); ## TODO: type |
4845 |
|
|
push @{$self->{ct}->{content}}, chr $self->{nc}; |
4846 |
|
|
$self->{group_depth}--; |
4847 |
|
|
$self->{state} = AFTER_CM_GROUP_CLOSE_STATE; |
4848 |
|
|
!!!next-input-character; |
4849 |
|
|
redo A; |
4850 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4851 |
|
|
!!!parse-error (type => 'unclosed cm group'); ## TODO: type |
4852 |
|
|
push @{$self->{ct}->{content}}, (')') x $self->{group_depth}; |
4853 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4854 |
|
|
!!!next-input-character; |
4855 |
|
|
!!!emit ($self->{ct}); # ELEMENT |
4856 |
|
|
redo A; |
4857 |
|
|
} elsif ($self->{nc} == -1) { |
4858 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4859 |
|
|
push @{$self->{ct}->{content}}, (')') x $self->{group_depth}; |
4860 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4861 |
|
|
!!!next-input-character; |
4862 |
|
|
!!!emit ($self->{ct}); # ELEMENT |
4863 |
|
|
redo A; |
4864 |
|
|
} else { |
4865 |
|
|
push @{$self->{ct}->{content}}, chr $self->{nc}; |
4866 |
|
|
$self->{state} = CM_ELEMENT_NAME_STATE; |
4867 |
|
|
!!!next-input-character; |
4868 |
|
|
redo A; |
4869 |
|
|
} |
4870 |
|
|
} elsif ($self->{state} == CM_ELEMENT_NAME_STATE) { |
4871 |
|
|
if ($is_space->{$self->{nc}}) { |
4872 |
|
|
$self->{state} = AFTER_CM_ELEMENT_NAME_STATE; |
4873 |
|
|
!!!next-input-character; |
4874 |
|
|
redo A; |
4875 |
|
|
} elsif ($self->{nc} == 0x002A or # * |
4876 |
|
|
$self->{nc} == 0x002B or # + |
4877 |
|
|
$self->{nc} == 0x003F) { # ? |
4878 |
|
|
push @{$self->{ct}->{content}}, chr $self->{nc}; |
4879 |
|
|
$self->{state} = AFTER_CM_ELEMENT_NAME_STATE; |
4880 |
|
|
!!!next-input-character; |
4881 |
|
|
redo A; |
4882 |
|
|
} elsif ($self->{nc} == 0x007C or # | |
4883 |
|
|
$self->{nc} == 0x002C) { # , |
4884 |
|
|
push @{$self->{ct}->{content}}, $self->{nc} == 0x007C ? ' | ' : ', '; |
4885 |
|
|
$self->{state} = AFTER_CM_GROUP_OPEN_STATE; |
4886 |
|
|
!!!next-input-character; |
4887 |
|
|
redo A; |
4888 |
|
|
} elsif ($self->{nc} == 0x0029) { # ) |
4889 |
|
|
$self->{group_depth}--; |
4890 |
|
|
push @{$self->{ct}->{content}}, chr $self->{nc}; |
4891 |
|
|
$self->{state} = AFTER_CM_GROUP_CLOSE_STATE; |
4892 |
|
|
!!!next-input-character; |
4893 |
|
|
redo A; |
4894 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4895 |
|
|
!!!parse-error (type => 'unclosed cm group'); ## TODO: type |
4896 |
|
|
push @{$self->{ct}->{content}}, (')') x $self->{group_depth}; |
4897 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4898 |
|
|
!!!next-input-character; |
4899 |
|
|
!!!emit ($self->{ct}); # ELEMENT |
4900 |
|
|
redo A; |
4901 |
|
|
} elsif ($self->{nc} == -1) { |
4902 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4903 |
|
|
push @{$self->{ct}->{content}}, (')') x $self->{group_depth}; |
4904 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4905 |
|
|
!!!next-input-character; |
4906 |
|
|
!!!emit ($self->{ct}); # ELEMENT |
4907 |
|
|
redo A; |
4908 |
|
|
} else { |
4909 |
|
|
$self->{ct}->{content}->[-1] .= chr $self->{nc}; |
4910 |
|
|
## Stay in the state. |
4911 |
|
|
!!!next-input-character; |
4912 |
|
|
redo A; |
4913 |
|
|
} |
4914 |
|
|
} elsif ($self->{state} == AFTER_CM_ELEMENT_NAME_STATE) { |
4915 |
|
|
if ($is_space->{$self->{nc}}) { |
4916 |
|
|
## Stay in the state. |
4917 |
|
|
!!!next-input-character; |
4918 |
|
|
redo A; |
4919 |
|
|
} elsif ($self->{nc} == 0x007C or # | |
4920 |
|
|
$self->{nc} == 0x002C) { # , |
4921 |
|
|
push @{$self->{ct}->{content}}, $self->{nc} == 0x007C ? ' | ' : ', '; |
4922 |
|
|
$self->{state} = AFTER_CM_GROUP_OPEN_STATE; |
4923 |
|
|
!!!next-input-character; |
4924 |
|
|
redo A; |
4925 |
|
|
} elsif ($self->{nc} == 0x0029) { # ) |
4926 |
|
|
$self->{group_depth}--; |
4927 |
|
|
push @{$self->{ct}->{content}}, chr $self->{nc}; |
4928 |
|
|
$self->{state} = AFTER_CM_GROUP_CLOSE_STATE; |
4929 |
|
|
!!!next-input-character; |
4930 |
|
|
redo A; |
4931 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4932 |
|
|
!!!parse-error (type => 'unclosed cm group'); ## TODO: type |
4933 |
|
|
push @{$self->{ct}->{content}}, (')') x $self->{group_depth}; |
4934 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4935 |
|
|
!!!next-input-character; |
4936 |
|
|
!!!emit ($self->{ct}); # ELEMENT |
4937 |
|
|
redo A; |
4938 |
|
|
} elsif ($self->{nc} == -1) { |
4939 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4940 |
|
|
push @{$self->{ct}->{content}}, (')') x $self->{group_depth}; |
4941 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4942 |
|
|
!!!next-input-character; |
4943 |
|
|
!!!emit ($self->{ct}); # ELEMENT |
4944 |
|
|
redo A; |
4945 |
|
|
} else { |
4946 |
|
|
!!!parse-error (type => 'after element name'); ## TODO: type |
4947 |
|
|
push @{$self->{ct}->{content}}, (')') x $self->{group_depth}; |
4948 |
|
|
$self->{state} = BOGUS_MD_STATE; |
4949 |
|
|
!!!next-input-character; |
4950 |
|
|
redo A; |
4951 |
|
|
} |
4952 |
|
|
} elsif ($self->{state} == AFTER_CM_GROUP_CLOSE_STATE) { |
4953 |
|
|
if ($is_space->{$self->{nc}}) { |
4954 |
|
|
if ($self->{group_depth}) { |
4955 |
|
|
$self->{state} = AFTER_CM_ELEMENT_NAME_STATE; |
4956 |
|
|
} else { |
4957 |
|
|
$self->{state} = AFTER_MD_DEF_STATE; |
4958 |
|
|
} |
4959 |
|
|
!!!next-input-character; |
4960 |
|
|
redo A; |
4961 |
|
|
} elsif ($self->{nc} == 0x002A or # * |
4962 |
|
|
$self->{nc} == 0x002B or # + |
4963 |
|
|
$self->{nc} == 0x003F) { # ? |
4964 |
|
|
push @{$self->{ct}->{content}}, chr $self->{nc}; |
4965 |
|
|
if ($self->{group_depth}) { |
4966 |
|
|
$self->{state} = AFTER_CM_ELEMENT_NAME_STATE; |
4967 |
|
|
} else { |
4968 |
|
|
$self->{state} = AFTER_MD_DEF_STATE; |
4969 |
|
|
} |
4970 |
|
|
!!!next-input-character; |
4971 |
|
|
redo A; |
4972 |
|
|
} elsif ($self->{nc} == 0x0029) { # ) |
4973 |
|
|
if ($self->{group_depth}) { |
4974 |
|
|
$self->{group_depth}--; |
4975 |
|
|
push @{$self->{ct}->{content}}, chr $self->{nc}; |
4976 |
|
|
## Stay in the state. |
4977 |
|
|
!!!next-input-character; |
4978 |
|
|
redo A; |
4979 |
|
|
} else { |
4980 |
|
|
!!!parse-error (type => 'string after md def'); ## TODO: type |
4981 |
|
|
$self->{state} = BOGUS_MD_STATE; |
4982 |
|
|
## Reconsume. |
4983 |
|
|
redo A; |
4984 |
|
|
} |
4985 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
4986 |
|
|
if ($self->{group_depth}) { |
4987 |
|
|
!!!parse-error (type => 'unclosed cm group'); ## TODO: type |
4988 |
|
|
push @{$self->{ct}->{content}}, (')') x $self->{group_depth}; |
4989 |
|
|
} |
4990 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4991 |
|
|
!!!next-input-character; |
4992 |
|
|
!!!emit ($self->{ct}); # ELEMENT |
4993 |
|
|
redo A; |
4994 |
|
|
} elsif ($self->{nc} == -1) { |
4995 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
4996 |
|
|
push @{$self->{ct}->{content}}, (')') x $self->{group_depth}; |
4997 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
4998 |
|
|
!!!next-input-character; |
4999 |
|
|
!!!emit ($self->{ct}); # ELEMENT |
5000 |
|
|
redo A; |
5001 |
|
|
} else { |
5002 |
|
|
if ($self->{group_depth}) { |
5003 |
|
|
$self->{state} = AFTER_CM_ELEMENT_NAME_STATE; |
5004 |
|
|
} else { |
5005 |
|
|
!!!parse-error (type => 'string after md def'); ## TODO: type |
5006 |
|
|
$self->{state} = BOGUS_MD_STATE; |
5007 |
|
|
} |
5008 |
|
|
## Reconsume. |
5009 |
|
|
redo A; |
5010 |
|
|
} |
5011 |
|
|
} elsif ($self->{state} == AFTER_MD_DEF_STATE) { |
5012 |
wakaba |
1.18 |
if ($is_space->{$self->{nc}}) { |
5013 |
|
|
## Stay in the state. |
5014 |
|
|
!!!next-input-character; |
5015 |
|
|
redo A; |
5016 |
|
|
} elsif ($self->{nc} == 0x003E) { # > |
5017 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
5018 |
|
|
!!!next-input-character; |
5019 |
wakaba |
1.20 |
!!!emit ($self->{ct}); # ENTITY/ELEMENT |
5020 |
wakaba |
1.18 |
redo A; |
5021 |
|
|
} elsif ($self->{nc} == -1) { |
5022 |
|
|
!!!parse-error (type => 'unclosed md'); ## TODO: type |
5023 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
5024 |
|
|
!!!next-input-character; |
5025 |
wakaba |
1.20 |
!!!emit ($self->{ct}); # ENTITY/ELEMENT |
5026 |
wakaba |
1.18 |
redo A; |
5027 |
|
|
} else { |
5028 |
wakaba |
1.20 |
!!!parse-error (type => 'string after md def'); ## TODO: type |
5029 |
wakaba |
1.18 |
$self->{state} = BOGUS_MD_STATE; |
5030 |
|
|
## Reconsume. |
5031 |
|
|
redo A; |
5032 |
|
|
} |
5033 |
wakaba |
1.16 |
} elsif ($self->{state} == BOGUS_MD_STATE) { |
5034 |
|
|
if ($self->{nc} == 0x003E) { # > |
5035 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
5036 |
|
|
!!!next-input-character; |
5037 |
|
|
!!!emit ($self->{ct}); # ATTLIST/ENTITY/NOTATION |
5038 |
|
|
redo A; |
5039 |
|
|
} elsif ($self->{nc} == -1) { |
5040 |
|
|
$self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; |
5041 |
|
|
## Reconsume. |
5042 |
|
|
!!!emit ($self->{ct}); # ATTLIST/ENTITY/NOTATION |
5043 |
|
|
redo A; |
5044 |
|
|
} else { |
5045 |
|
|
## Stay in the state. |
5046 |
|
|
!!!next-input-character; |
5047 |
|
|
redo A; |
5048 |
|
|
} |
5049 |
wakaba |
1.1 |
} else { |
5050 |
|
|
die "$0: $self->{state}: Unknown state"; |
5051 |
|
|
} |
5052 |
|
|
} # A |
5053 |
|
|
|
5054 |
|
|
die "$0: _get_next_token: unexpected case"; |
5055 |
|
|
} # _get_next_token |
5056 |
|
|
|
5057 |
|
|
1; |
5058 |
wakaba |
1.20 |
## $Date: 2008/10/19 07:19:00 $ |
5059 |
wakaba |
1.15 |
|