Parent Directory
|
Revision Log
|
Patch
| revision 1.73 by wakaba, Sun Mar 2 23:38:37 2008 UTC | revision 1.162 by wakaba, Thu Sep 11 09:12:27 2008 UTC | |
|---|---|---|
| # | Line 8 use Error qw(:try); | Line 8 use Error qw(:try); |
| 8 | ## doc.write (''); | ## doc.write (''); |
| 9 | ## alert (doc.compatMode); | ## alert (doc.compatMode); |
| 10 | ||
| 11 | ## TODO: Control charcters and noncharacters are not allowed (HTML5 revision 1263) | require IO::Handle; |
| 12 | ## TODO: 1252 parse error (revision 1264) | |
| 13 | ## TODO: 8859-11 = 874 (revision 1271) | my $HTML_NS = q<http://www.w3.org/1999/xhtml>; |
| 14 | my $MML_NS = q<http://www.w3.org/1998/Math/MathML>; | |
| 15 | my $permitted_slash_tag_name = { | my $SVG_NS = q<http://www.w3.org/2000/svg>; |
| 16 | base => 1, | my $XLINK_NS = q<http://www.w3.org/1999/xlink>; |
| 17 | link => 1, | my $XML_NS = q<http://www.w3.org/XML/1998/namespace>; |
| 18 | meta => 1, | my $XMLNS_NS = q<http://www.w3.org/2000/xmlns/>; |
| 19 | hr => 1, | |
| 20 | br => 1, | sub A_EL () { 0b1 } |
| 21 | img => 1, | sub ADDRESS_EL () { 0b10 } |
| 22 | embed => 1, | sub BODY_EL () { 0b100 } |
| 23 | param => 1, | sub BUTTON_EL () { 0b1000 } |
| 24 | area => 1, | sub CAPTION_EL () { 0b10000 } |
| 25 | col => 1, | sub DD_EL () { 0b100000 } |
| 26 | input => 1, | sub DIV_EL () { 0b1000000 } |
| 27 | sub DT_EL () { 0b10000000 } | |
| 28 | sub FORM_EL () { 0b100000000 } | |
| 29 | sub FORMATTING_EL () { 0b1000000000 } | |
| 30 | sub FRAMESET_EL () { 0b10000000000 } | |
| 31 | sub HEADING_EL () { 0b100000000000 } | |
| 32 | sub HTML_EL () { 0b1000000000000 } | |
| 33 | sub LI_EL () { 0b10000000000000 } | |
| 34 | sub NOBR_EL () { 0b100000000000000 } | |
| 35 | sub OPTION_EL () { 0b1000000000000000 } | |
| 36 | sub OPTGROUP_EL () { 0b10000000000000000 } | |
| 37 | sub P_EL () { 0b100000000000000000 } | |
| 38 | sub SELECT_EL () { 0b1000000000000000000 } | |
| 39 | sub TABLE_EL () { 0b10000000000000000000 } | |
| 40 | sub TABLE_CELL_EL () { 0b100000000000000000000 } | |
| 41 | sub TABLE_ROW_EL () { 0b1000000000000000000000 } | |
| 42 | sub TABLE_ROW_GROUP_EL () { 0b10000000000000000000000 } | |
| 43 | sub MISC_SCOPING_EL () { 0b100000000000000000000000 } | |
| 44 | sub MISC_SPECIAL_EL () { 0b1000000000000000000000000 } | |
| 45 | sub FOREIGN_EL () { 0b10000000000000000000000000 } | |
| 46 | sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 } | |
| 47 | sub MML_AXML_EL () { 0b1000000000000000000000000000 } | |
| 48 | sub RUBY_EL () { 0b10000000000000000000000000000 } | |
| 49 | sub RUBY_COMPONENT_EL () { 0b100000000000000000000000000000 } | |
| 50 | ||
| 51 | sub TABLE_ROWS_EL () { | |
| 52 | TABLE_EL | | |
| 53 | TABLE_ROW_EL | | |
| 54 | TABLE_ROW_GROUP_EL | |
| 55 | } | |
| 56 | ||
| 57 | ## NOTE: Used in "generate implied end tags" algorithm. | |
| 58 | ## NOTE: There is a code where a modified version of END_TAG_OPTIONAL_EL | |
| 59 | ## is used in "generate implied end tags" implementation (search for the | |
| 60 | ## function mae). | |
| 61 | sub END_TAG_OPTIONAL_EL () { | |
| 62 | DD_EL | | |
| 63 | DT_EL | | |
| 64 | LI_EL | | |
| 65 | P_EL | | |
| 66 | RUBY_COMPONENT_EL | |
| 67 | } | |
| 68 | ||
| 69 | ## NOTE: Used in </body> and EOF algorithms. | |
| 70 | sub ALL_END_TAG_OPTIONAL_EL () { | |
| 71 | DD_EL | | |
| 72 | DT_EL | | |
| 73 | LI_EL | | |
| 74 | P_EL | | |
| 75 | ||
| 76 | BODY_EL | | |
| 77 | HTML_EL | | |
| 78 | TABLE_CELL_EL | | |
| 79 | TABLE_ROW_EL | | |
| 80 | TABLE_ROW_GROUP_EL | |
| 81 | } | |
| 82 | ||
| 83 | sub SCOPING_EL () { | |
| 84 | BUTTON_EL | | |
| 85 | CAPTION_EL | | |
| 86 | HTML_EL | | |
| 87 | TABLE_EL | | |
| 88 | TABLE_CELL_EL | | |
| 89 | MISC_SCOPING_EL | |
| 90 | } | |
| 91 | ||
| 92 | sub TABLE_SCOPING_EL () { | |
| 93 | HTML_EL | | |
| 94 | TABLE_EL | |
| 95 | } | |
| 96 | ||
| 97 | sub TABLE_ROWS_SCOPING_EL () { | |
| 98 | HTML_EL | | |
| 99 | TABLE_ROW_GROUP_EL | |
| 100 | } | |
| 101 | ||
| 102 | sub TABLE_ROW_SCOPING_EL () { | |
| 103 | HTML_EL | | |
| 104 | TABLE_ROW_EL | |
| 105 | } | |
| 106 | ||
| 107 | sub SPECIAL_EL () { | |
| 108 | ADDRESS_EL | | |
| 109 | BODY_EL | | |
| 110 | DIV_EL | | |
| 111 | ||
| 112 | DD_EL | | |
| 113 | DT_EL | | |
| 114 | LI_EL | | |
| 115 | P_EL | | |
| 116 | ||
| 117 | FORM_EL | | |
| 118 | FRAMESET_EL | | |
| 119 | HEADING_EL | | |
| 120 | OPTION_EL | | |
| 121 | OPTGROUP_EL | | |
| 122 | SELECT_EL | | |
| 123 | TABLE_ROW_EL | | |
| 124 | TABLE_ROW_GROUP_EL | | |
| 125 | MISC_SPECIAL_EL | |
| 126 | } | |
| 127 | ||
| 128 | my $el_category = { | |
| 129 | a => A_EL | FORMATTING_EL, | |
| 130 | address => ADDRESS_EL, | |
| 131 | applet => MISC_SCOPING_EL, | |
| 132 | area => MISC_SPECIAL_EL, | |
| 133 | b => FORMATTING_EL, | |
| 134 | base => MISC_SPECIAL_EL, | |
| 135 | basefont => MISC_SPECIAL_EL, | |
| 136 | bgsound => MISC_SPECIAL_EL, | |
| 137 | big => FORMATTING_EL, | |
| 138 | blockquote => MISC_SPECIAL_EL, | |
| 139 | body => BODY_EL, | |
| 140 | br => MISC_SPECIAL_EL, | |
| 141 | button => BUTTON_EL, | |
| 142 | caption => CAPTION_EL, | |
| 143 | center => MISC_SPECIAL_EL, | |
| 144 | col => MISC_SPECIAL_EL, | |
| 145 | colgroup => MISC_SPECIAL_EL, | |
| 146 | dd => DD_EL, | |
| 147 | dir => MISC_SPECIAL_EL, | |
| 148 | div => DIV_EL, | |
| 149 | dl => MISC_SPECIAL_EL, | |
| 150 | dt => DT_EL, | |
| 151 | em => FORMATTING_EL, | |
| 152 | embed => MISC_SPECIAL_EL, | |
| 153 | fieldset => MISC_SPECIAL_EL, | |
| 154 | font => FORMATTING_EL, | |
| 155 | form => FORM_EL, | |
| 156 | frame => MISC_SPECIAL_EL, | |
| 157 | frameset => FRAMESET_EL, | |
| 158 | h1 => HEADING_EL, | |
| 159 | h2 => HEADING_EL, | |
| 160 | h3 => HEADING_EL, | |
| 161 | h4 => HEADING_EL, | |
| 162 | h5 => HEADING_EL, | |
| 163 | h6 => HEADING_EL, | |
| 164 | head => MISC_SPECIAL_EL, | |
| 165 | hr => MISC_SPECIAL_EL, | |
| 166 | html => HTML_EL, | |
| 167 | i => FORMATTING_EL, | |
| 168 | iframe => MISC_SPECIAL_EL, | |
| 169 | img => MISC_SPECIAL_EL, | |
| 170 | input => MISC_SPECIAL_EL, | |
| 171 | isindex => MISC_SPECIAL_EL, | |
| 172 | li => LI_EL, | |
| 173 | link => MISC_SPECIAL_EL, | |
| 174 | listing => MISC_SPECIAL_EL, | |
| 175 | marquee => MISC_SCOPING_EL, | |
| 176 | menu => MISC_SPECIAL_EL, | |
| 177 | meta => MISC_SPECIAL_EL, | |
| 178 | nobr => NOBR_EL | FORMATTING_EL, | |
| 179 | noembed => MISC_SPECIAL_EL, | |
| 180 | noframes => MISC_SPECIAL_EL, | |
| 181 | noscript => MISC_SPECIAL_EL, | |
| 182 | object => MISC_SCOPING_EL, | |
| 183 | ol => MISC_SPECIAL_EL, | |
| 184 | optgroup => OPTGROUP_EL, | |
| 185 | option => OPTION_EL, | |
| 186 | p => P_EL, | |
| 187 | param => MISC_SPECIAL_EL, | |
| 188 | plaintext => MISC_SPECIAL_EL, | |
| 189 | pre => MISC_SPECIAL_EL, | |
| 190 | rp => RUBY_COMPONENT_EL, | |
| 191 | rt => RUBY_COMPONENT_EL, | |
| 192 | ruby => RUBY_EL, | |
| 193 | s => FORMATTING_EL, | |
| 194 | script => MISC_SPECIAL_EL, | |
| 195 | select => SELECT_EL, | |
| 196 | small => FORMATTING_EL, | |
| 197 | spacer => MISC_SPECIAL_EL, | |
| 198 | strike => FORMATTING_EL, | |
| 199 | strong => FORMATTING_EL, | |
| 200 | style => MISC_SPECIAL_EL, | |
| 201 | table => TABLE_EL, | |
| 202 | tbody => TABLE_ROW_GROUP_EL, | |
| 203 | td => TABLE_CELL_EL, | |
| 204 | textarea => MISC_SPECIAL_EL, | |
| 205 | tfoot => TABLE_ROW_GROUP_EL, | |
| 206 | th => TABLE_CELL_EL, | |
| 207 | thead => TABLE_ROW_GROUP_EL, | |
| 208 | title => MISC_SPECIAL_EL, | |
| 209 | tr => TABLE_ROW_EL, | |
| 210 | tt => FORMATTING_EL, | |
| 211 | u => FORMATTING_EL, | |
| 212 | ul => MISC_SPECIAL_EL, | |
| 213 | wbr => MISC_SPECIAL_EL, | |
| 214 | }; | |
| 215 | ||
| 216 | my $el_category_f = { | |
| 217 | $MML_NS => { | |
| 218 | 'annotation-xml' => MML_AXML_EL, | |
| 219 | mi => FOREIGN_FLOW_CONTENT_EL, | |
| 220 | mo => FOREIGN_FLOW_CONTENT_EL, | |
| 221 | mn => FOREIGN_FLOW_CONTENT_EL, | |
| 222 | ms => FOREIGN_FLOW_CONTENT_EL, | |
| 223 | mtext => FOREIGN_FLOW_CONTENT_EL, | |
| 224 | }, | |
| 225 | $SVG_NS => { | |
| 226 | foreignObject => FOREIGN_FLOW_CONTENT_EL, | |
| 227 | desc => FOREIGN_FLOW_CONTENT_EL, | |
| 228 | title => FOREIGN_FLOW_CONTENT_EL, | |
| 229 | }, | |
| 230 | ## NOTE: In addition, FOREIGN_EL is set to non-HTML elements. | |
| 231 | }; | |
| 232 | ||
| 233 | my $svg_attr_name = { | |
| 234 | attributename => 'attributeName', | |
| 235 | attributetype => 'attributeType', | |
| 236 | basefrequency => 'baseFrequency', | |
| 237 | baseprofile => 'baseProfile', | |
| 238 | calcmode => 'calcMode', | |
| 239 | clippathunits => 'clipPathUnits', | |
| 240 | contentscripttype => 'contentScriptType', | |
| 241 | contentstyletype => 'contentStyleType', | |
| 242 | diffuseconstant => 'diffuseConstant', | |
| 243 | edgemode => 'edgeMode', | |
| 244 | externalresourcesrequired => 'externalResourcesRequired', | |
| 245 | filterres => 'filterRes', | |
| 246 | filterunits => 'filterUnits', | |
| 247 | glyphref => 'glyphRef', | |
| 248 | gradienttransform => 'gradientTransform', | |
| 249 | gradientunits => 'gradientUnits', | |
| 250 | kernelmatrix => 'kernelMatrix', | |
| 251 | kernelunitlength => 'kernelUnitLength', | |
| 252 | keypoints => 'keyPoints', | |
| 253 | keysplines => 'keySplines', | |
| 254 | keytimes => 'keyTimes', | |
| 255 | lengthadjust => 'lengthAdjust', | |
| 256 | limitingconeangle => 'limitingConeAngle', | |
| 257 | markerheight => 'markerHeight', | |
| 258 | markerunits => 'markerUnits', | |
| 259 | markerwidth => 'markerWidth', | |
| 260 | maskcontentunits => 'maskContentUnits', | |
| 261 | maskunits => 'maskUnits', | |
| 262 | numoctaves => 'numOctaves', | |
| 263 | pathlength => 'pathLength', | |
| 264 | patterncontentunits => 'patternContentUnits', | |
| 265 | patterntransform => 'patternTransform', | |
| 266 | patternunits => 'patternUnits', | |
| 267 | pointsatx => 'pointsAtX', | |
| 268 | pointsaty => 'pointsAtY', | |
| 269 | pointsatz => 'pointsAtZ', | |
| 270 | preservealpha => 'preserveAlpha', | |
| 271 | preserveaspectratio => 'preserveAspectRatio', | |
| 272 | primitiveunits => 'primitiveUnits', | |
| 273 | refx => 'refX', | |
| 274 | refy => 'refY', | |
| 275 | repeatcount => 'repeatCount', | |
| 276 | repeatdur => 'repeatDur', | |
| 277 | requiredextensions => 'requiredExtensions', | |
| 278 | requiredfeatures => 'requiredFeatures', | |
| 279 | specularconstant => 'specularConstant', | |
| 280 | specularexponent => 'specularExponent', | |
| 281 | spreadmethod => 'spreadMethod', | |
| 282 | startoffset => 'startOffset', | |
| 283 | stddeviation => 'stdDeviation', | |
| 284 | stitchtiles => 'stitchTiles', | |
| 285 | surfacescale => 'surfaceScale', | |
| 286 | systemlanguage => 'systemLanguage', | |
| 287 | tablevalues => 'tableValues', | |
| 288 | targetx => 'targetX', | |
| 289 | targety => 'targetY', | |
| 290 | textlength => 'textLength', | |
| 291 | viewbox => 'viewBox', | |
| 292 | viewtarget => 'viewTarget', | |
| 293 | xchannelselector => 'xChannelSelector', | |
| 294 | ychannelselector => 'yChannelSelector', | |
| 295 | zoomandpan => 'zoomAndPan', | |
| 296 | }; | }; |
| 297 | ||
| 298 | my $foreign_attr_xname = { | |
| 299 | 'xlink:actuate' => [$XLINK_NS, ['xlink', 'actuate']], | |
| 300 | 'xlink:arcrole' => [$XLINK_NS, ['xlink', 'arcrole']], | |
| 301 | 'xlink:href' => [$XLINK_NS, ['xlink', 'href']], | |
| 302 | 'xlink:role' => [$XLINK_NS, ['xlink', 'role']], | |
| 303 | 'xlink:show' => [$XLINK_NS, ['xlink', 'show']], | |
| 304 | 'xlink:title' => [$XLINK_NS, ['xlink', 'title']], | |
| 305 | 'xlink:type' => [$XLINK_NS, ['xlink', 'type']], | |
| 306 | 'xml:base' => [$XML_NS, ['xml', 'base']], | |
| 307 | 'xml:lang' => [$XML_NS, ['xml', 'lang']], | |
| 308 | 'xml:space' => [$XML_NS, ['xml', 'space']], | |
| 309 | 'xmlns' => [$XMLNS_NS, [undef, 'xmlns']], | |
| 310 | 'xmlns:xlink' => [$XMLNS_NS, ['xmlns', 'xlink']], | |
| 311 | }; | |
| 312 | ||
| 313 | ## ISSUE: xmlns:xlink="non-xlink-ns" is not an error. | |
| 314 | ||
| 315 | my $c1_entity_char = { | my $c1_entity_char = { |
| 316 | 0x80 => 0x20AC, | 0x80 => 0x20AC, |
| 317 | 0x81 => 0xFFFD, | 0x81 => 0xFFFD, |
| # | Line 61 my $c1_entity_char = { | Line 347 my $c1_entity_char = { |
| 347 | 0x9F => 0x0178, | 0x9F => 0x0178, |
| 348 | }; # $c1_entity_char | }; # $c1_entity_char |
| 349 | ||
| my $special_category = { | ||
| address => 1, area => 1, base => 1, basefont => 1, bgsound => 1, | ||
| blockquote => 1, body => 1, br => 1, center => 1, col => 1, colgroup => 1, | ||
| dd => 1, dir => 1, div => 1, dl => 1, dt => 1, embed => 1, fieldset => 1, | ||
| form => 1, frame => 1, frameset => 1, h1 => 1, h2 => 1, h3 => 1, | ||
| h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, iframe => 1, image => 1, | ||
| img => 1, input => 1, isindex => 1, li => 1, link => 1, listing => 1, | ||
| menu => 1, meta => 1, noembed => 1, noframes => 1, noscript => 1, | ||
| ol => 1, optgroup => 1, option => 1, p => 1, param => 1, plaintext => 1, | ||
| pre => 1, script => 1, select => 1, spacer => 1, style => 1, tbody => 1, | ||
| textarea => 1, tfoot => 1, thead => 1, title => 1, tr => 1, ul => 1, wbr => 1, | ||
| }; | ||
| my $scoping_category = { | ||
| button => 1, caption => 1, html => 1, marquee => 1, object => 1, | ||
| table => 1, td => 1, th => 1, | ||
| }; | ||
| my $formatting_category = { | ||
| a => 1, b => 1, big => 1, em => 1, font => 1, i => 1, nobr => 1, | ||
| s => 1, small => 1, strile => 1, strong => 1, tt => 1, u => 1, | ||
| }; | ||
| # $phrasing_category: all other elements | ||
| 350 | sub parse_byte_string ($$$$;$) { | sub parse_byte_string ($$$$;$) { |
| 351 | my $self = shift; | |
| 352 | my $charset_name = shift; | |
| 353 | open my $input, '<', ref $_[0] ? $_[0] : \($_[0]); | |
| 354 | return $self->parse_byte_stream ($charset_name, $input, @_[1..$#_]); | |
| 355 | } # parse_byte_string | |
| 356 | ||
| 357 | sub parse_byte_stream ($$$$;$$) { | |
| 358 | # my ($self, $charset_name, $byte_stream, $doc, $onerror, $get_wrapper) = @_; | |
| 359 | my $self = ref $_[0] ? shift : shift->new; | my $self = ref $_[0] ? shift : shift->new; |
| 360 | my $charset = shift; | my $charset_name = shift; |
| 361 | my $bytes_s = ref $_[0] ? $_[0] : \($_[0]); | my $byte_stream = $_[0]; |
| my $s; | ||
| if (defined $charset) { | ||
| require Encode; ## TODO: decode(utf8) don't delete BOM | ||
| $s = \ (Encode::decode ($charset, $$bytes_s)); | ||
| $self->{input_encoding} = lc $charset; ## TODO: normalize name | ||
| $self->{confident} = 1; | ||
| } else { | ||
| ## TODO: Implement HTML5 detection algorithm | ||
| require Whatpm::Charset::UniversalCharDet; | ||
| $charset = Whatpm::Charset::UniversalCharDet->detect_byte_string | ||
| (substr ($$bytes_s, 0, 1024)); | ||
| $charset ||= 'windows-1252'; | ||
| $s = \ (Encode::decode ($charset, $$bytes_s)); | ||
| $self->{input_encoding} = $charset; | ||
| $self->{confident} = 0; | ||
| } | ||
| 362 | ||
| 363 | $self->{change_encoding} = sub { | my $onerror = $_[2] || sub { |
| 364 | my $self = shift; | my (%opt) = @_; |
| 365 | my $charset = lc shift; | warn "Parse error ($opt{type})\n"; |
| 366 | ## TODO: if $charset is supported | }; |
| 367 | ## TODO: normalize charset name | $self->{parse_error} = $onerror; # updated later by parse_char_string |
| 368 | ||
| 369 | ## "Change the encoding" algorithm: | my $get_wrapper = $_[3] || sub ($) { |
| 370 | return $_[0]; # $_[0] = byte stream handle, returned = arg to char handle | |
| 371 | ## Step 1 | }; |
| 372 | if ($charset eq 'utf-16') { ## ISSUE: UTF-16BE -> UTF-8? UTF-16LE -> UTF-8? | |
| 373 | $charset = 'utf-8'; | ## HTML5 encoding sniffing algorithm |
| 374 | require Message::Charset::Info; | |
| 375 | my $charset; | |
| 376 | my $buffer; | |
| 377 | my ($char_stream, $e_status); | |
| 378 | ||
| 379 | SNIFFING: { | |
| 380 | ## NOTE: By setting |allow_fallback| option true when the | |
| 381 | ## |get_decode_handle| method is invoked, we ignore what the HTML5 | |
| 382 | ## spec requires, i.e. unsupported encoding should be ignored. | |
| 383 | ## TODO: We should not do this unless the parser is invoked | |
| 384 | ## in the conformance checking mode, in which this behavior | |
| 385 | ## would be useful. | |
| 386 | ||
| 387 | ## Step 1 | |
| 388 | if (defined $charset_name) { | |
| 389 | $charset = Message::Charset::Info->get_by_html_name ($charset_name); | |
| 390 | ## TODO: Is this ok? Transfer protocol's parameter should be | |
| 391 | ## interpreted in its semantics? | |
| 392 | ||
| 393 | ## ISSUE: Unsupported encoding is not ignored according to the spec. | |
| 394 | ($char_stream, $e_status) = $charset->get_decode_handle | |
| 395 | ($byte_stream, allow_error_reporting => 1, | |
| 396 | allow_fallback => 1); | |
| 397 | if ($char_stream) { | |
| 398 | $self->{confident} = 1; | |
| 399 | last SNIFFING; | |
| 400 | } else { | |
| 401 | ## TODO: unsupported error | |
| 402 | } | |
| 403 | } | } |
| 404 | ||
| 405 | ## Step 2 | ## Step 2 |
| 406 | if (defined $self->{input_encoding} and | my $byte_buffer = ''; |
| 407 | $self->{input_encoding} eq $charset) { | for (1..1024) { |
| 408 | my $char = $byte_stream->getc; | |
| 409 | last unless defined $char; | |
| 410 | $byte_buffer .= $char; | |
| 411 | } ## TODO: timeout | |
| 412 | ||
| 413 | ## Step 3 | |
| 414 | if ($byte_buffer =~ /^\xFE\xFF/) { | |
| 415 | $charset = Message::Charset::Info->get_by_html_name ('utf-16be'); | |
| 416 | ($char_stream, $e_status) = $charset->get_decode_handle | |
| 417 | ($byte_stream, allow_error_reporting => 1, | |
| 418 | allow_fallback => 1, byte_buffer => \$byte_buffer); | |
| 419 | $self->{confident} = 1; | $self->{confident} = 1; |
| 420 | return; | last SNIFFING; |
| 421 | } elsif ($byte_buffer =~ /^\xFF\xFE/) { | |
| 422 | $charset = Message::Charset::Info->get_by_html_name ('utf-16le'); | |
| 423 | ($char_stream, $e_status) = $charset->get_decode_handle | |
| 424 | ($byte_stream, allow_error_reporting => 1, | |
| 425 | allow_fallback => 1, byte_buffer => \$byte_buffer); | |
| 426 | $self->{confident} = 1; | |
| 427 | last SNIFFING; | |
| 428 | } elsif ($byte_buffer =~ /^\xEF\xBB\xBF/) { | |
| 429 | $charset = Message::Charset::Info->get_by_html_name ('utf-8'); | |
| 430 | ($char_stream, $e_status) = $charset->get_decode_handle | |
| 431 | ($byte_stream, allow_error_reporting => 1, | |
| 432 | allow_fallback => 1, byte_buffer => \$byte_buffer); | |
| 433 | $self->{confident} = 1; | |
| 434 | last SNIFFING; | |
| 435 | } | } |
| 436 | ||
| 437 | !!!parse-error (type => 'charset label detected:'.$self->{input_encoding}. | ## Step 4 |
| 438 | ':'.$charset, level => 'w'); | ## TODO: <meta charset> |
| 439 | ||
| 440 | ## Step 3 | ## Step 5 |
| 441 | # if (can) { | ## TODO: from history |
| ## change the encoding on the fly. | ||
| #$self->{confident} = 1; | ||
| #return; | ||
| # } | ||
| 442 | ||
| 443 | ## Step 4 | ## Step 6 |
| 444 | throw Whatpm::HTML::RestartParser (charset => $charset); | require Whatpm::Charset::UniversalCharDet; |
| 445 | $charset_name = Whatpm::Charset::UniversalCharDet->detect_byte_string | |
| 446 | ($byte_buffer); | |
| 447 | if (defined $charset_name) { | |
| 448 | $charset = Message::Charset::Info->get_by_html_name ($charset_name); | |
| 449 | ||
| 450 | ## ISSUE: Unsupported encoding is not ignored according to the spec. | |
| 451 | require Whatpm::Charset::DecodeHandle; | |
| 452 | $buffer = Whatpm::Charset::DecodeHandle::ByteBuffer->new | |
| 453 | ($byte_stream); | |
| 454 | ($char_stream, $e_status) = $charset->get_decode_handle | |
| 455 | ($buffer, allow_error_reporting => 1, | |
| 456 | allow_fallback => 1, byte_buffer => \$byte_buffer); | |
| 457 | if ($char_stream) { | |
| 458 | $buffer->{buffer} = $byte_buffer; | |
| 459 | !!!parse-error (type => 'sniffing:chardet', | |
| 460 | text => $charset_name, | |
| 461 | level => $self->{level}->{info}, | |
| 462 | layer => 'encode', | |
| 463 | line => 1, column => 1); | |
| 464 | $self->{confident} = 0; | |
| 465 | last SNIFFING; | |
| 466 | } | |
| 467 | } | |
| 468 | ||
| 469 | ## Step 7: default | |
| 470 | ## TODO: Make this configurable. | |
| 471 | $charset = Message::Charset::Info->get_by_html_name ('windows-1252'); | |
| 472 | ## NOTE: We choose |windows-1252| here, since |utf-8| should be | |
| 473 | ## detectable in the step 6. | |
| 474 | require Whatpm::Charset::DecodeHandle; | |
| 475 | $buffer = Whatpm::Charset::DecodeHandle::ByteBuffer->new | |
| 476 | ($byte_stream); | |
| 477 | ($char_stream, $e_status) | |
| 478 | = $charset->get_decode_handle ($buffer, | |
| 479 | allow_error_reporting => 1, | |
| 480 | allow_fallback => 1, | |
| 481 | byte_buffer => \$byte_buffer); | |
| 482 | $buffer->{buffer} = $byte_buffer; | |
| 483 | !!!parse-error (type => 'sniffing:default', | |
| 484 | text => 'windows-1252', | |
| 485 | level => $self->{level}->{info}, | |
| 486 | line => 1, column => 1, | |
| 487 | layer => 'encode'); | |
| 488 | $self->{confident} = 0; | |
| 489 | } # SNIFFING | |
| 490 | ||
| 491 | if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) { | |
| 492 | $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name? | |
| 493 | !!!parse-error (type => 'chardecode:fallback', | |
| 494 | #text => $self->{input_encoding}, | |
| 495 | level => $self->{level}->{uncertain}, | |
| 496 | line => 1, column => 1, | |
| 497 | layer => 'encode'); | |
| 498 | } elsif (not ($e_status & | |
| 499 | Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) { | |
| 500 | $self->{input_encoding} = $charset->get_iana_name; | |
| 501 | !!!parse-error (type => 'chardecode:no error', | |
| 502 | text => $self->{input_encoding}, | |
| 503 | level => $self->{level}->{uncertain}, | |
| 504 | line => 1, column => 1, | |
| 505 | layer => 'encode'); | |
| 506 | } else { | |
| 507 | $self->{input_encoding} = $charset->get_iana_name; | |
| 508 | } | |
| 509 | ||
| 510 | $self->{change_encoding} = sub { | |
| 511 | my $self = shift; | |
| 512 | $charset_name = shift; | |
| 513 | my $token = shift; | |
| 514 | ||
| 515 | $charset = Message::Charset::Info->get_by_html_name ($charset_name); | |
| 516 | ($char_stream, $e_status) = $charset->get_decode_handle | |
| 517 | ($byte_stream, allow_error_reporting => 1, allow_fallback => 1, | |
| 518 | byte_buffer => \ $buffer->{buffer}); | |
| 519 | ||
| 520 | if ($char_stream) { # if supported | |
| 521 | ## "Change the encoding" algorithm: | |
| 522 | ||
| 523 | ## Step 1 | |
| 524 | if ($charset->{category} & | |
| 525 | Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) { | |
| 526 | $charset = Message::Charset::Info->get_by_html_name ('utf-8'); | |
| 527 | ($char_stream, $e_status) = $charset->get_decode_handle | |
| 528 | ($byte_stream, | |
| 529 | byte_buffer => \ $buffer->{buffer}); | |
| 530 | } | |
| 531 | $charset_name = $charset->get_iana_name; | |
| 532 | ||
| 533 | ## Step 2 | |
| 534 | if (defined $self->{input_encoding} and | |
| 535 | $self->{input_encoding} eq $charset_name) { | |
| 536 | !!!parse-error (type => 'charset label:matching', | |
| 537 | text => $charset_name, | |
| 538 | level => $self->{level}->{info}); | |
| 539 | $self->{confident} = 1; | |
| 540 | return; | |
| 541 | } | |
| 542 | ||
| 543 | !!!parse-error (type => 'charset label detected', | |
| 544 | text => $self->{input_encoding}, | |
| 545 | value => $charset_name, | |
| 546 | level => $self->{level}->{warn}, | |
| 547 | token => $token); | |
| 548 | ||
| 549 | ## Step 3 | |
| 550 | # if (can) { | |
| 551 | ## change the encoding on the fly. | |
| 552 | #$self->{confident} = 1; | |
| 553 | #return; | |
| 554 | # } | |
| 555 | ||
| 556 | ## Step 4 | |
| 557 | throw Whatpm::HTML::RestartParser (); | |
| 558 | } | |
| 559 | }; # $self->{change_encoding} | }; # $self->{change_encoding} |
| 560 | ||
| 561 | my $char_onerror = sub { | |
| 562 | my (undef, $type, %opt) = @_; | |
| 563 | !!!parse-error (layer => 'encode', | |
| 564 | %opt, type => $type, | |
| 565 | line => $self->{line}, column => $self->{column} + 1); | |
| 566 | if ($opt{octets}) { | |
| 567 | ${$opt{octets}} = "\x{FFFD}"; # relacement character | |
| 568 | } | |
| 569 | }; | |
| 570 | ||
| 571 | my $wrapped_char_stream = $get_wrapper->($char_stream); | |
| 572 | $wrapped_char_stream->onerror ($char_onerror); | |
| 573 | ||
| 574 | my @args = @_; shift @args; # $s | my @args = @_; shift @args; # $s |
| 575 | my $return; | my $return; |
| 576 | try { | try { |
| 577 | $return = $self->parse_char_string ($s, @args); | $return = $self->parse_char_stream ($wrapped_char_stream, @args); |
| 578 | } catch Whatpm::HTML::RestartParser with { | } catch Whatpm::HTML::RestartParser with { |
| 579 | my $charset = shift->{charset}; | ## NOTE: Invoked after {change_encoding}. |
| 580 | $s = \ (Encode::decode ($charset, $$bytes_s)); | |
| 581 | $self->{input_encoding} = $charset; ## TODO: normalize | if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) { |
| 582 | $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name? | |
| 583 | !!!parse-error (type => 'chardecode:fallback', | |
| 584 | level => $self->{level}->{uncertain}, | |
| 585 | #text => $self->{input_encoding}, | |
| 586 | line => 1, column => 1, | |
| 587 | layer => 'encode'); | |
| 588 | } elsif (not ($e_status & | |
| 589 | Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) { | |
| 590 | $self->{input_encoding} = $charset->get_iana_name; | |
| 591 | !!!parse-error (type => 'chardecode:no error', | |
| 592 | text => $self->{input_encoding}, | |
| 593 | level => $self->{level}->{uncertain}, | |
| 594 | line => 1, column => 1, | |
| 595 | layer => 'encode'); | |
| 596 | } else { | |
| 597 | $self->{input_encoding} = $charset->get_iana_name; | |
| 598 | } | |
| 599 | $self->{confident} = 1; | $self->{confident} = 1; |
| 600 | $return = $self->parse_char_string ($s, @args); | |
| 601 | $wrapped_char_stream = $get_wrapper->($char_stream); | |
| 602 | $wrapped_char_stream->onerror ($char_onerror); | |
| 603 | ||
| 604 | $return = $self->parse_char_stream ($wrapped_char_stream, @args); | |
| 605 | }; | }; |
| 606 | return $return; | return $return; |
| 607 | } # parse_byte_string | } # parse_byte_stream |
| 608 | ||
| 609 | ## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM | ## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM |
| 610 | ## and the HTML layer MUST ignore it. However, we does strip BOM in | ## and the HTML layer MUST ignore it. However, we does strip BOM in |
| # | Line 162 sub parse_byte_string ($$$$;$) { | Line 615 sub parse_byte_string ($$$$;$) { |
| 615 | ## such as |parse_byte_string| in this module, must ensure that it does | ## such as |parse_byte_string| in this module, must ensure that it does |
| 616 | ## strip the BOM and never strip any ZWNBSP. | ## strip the BOM and never strip any ZWNBSP. |
| 617 | ||
| 618 | *parse_char_string = \&parse_string; | sub parse_char_string ($$$;$$) { |
| 619 | #my ($self, $s, $doc, $onerror, $get_wrapper) = @_; | |
| 620 | my $self = shift; | |
| 621 | require utf8; | |
| 622 | my $s = ref $_[0] ? $_[0] : \($_[0]); | |
| 623 | open my $input, '<' . (utf8::is_utf8 ($$s) ? ':utf8' : ''), $s; | |
| 624 | if ($_[3]) { | |
| 625 | $input = $_[3]->($input); | |
| 626 | } | |
| 627 | return $self->parse_char_stream ($input, @_[1..$#_]); | |
| 628 | } # parse_char_string | |
| 629 | *parse_string = \&parse_char_string; ## NOTE: Alias for backward compatibility. | |
| 630 | ||
| 631 | sub parse_string ($$$;$) { | sub parse_char_stream ($$$;$) { |
| 632 | my $self = ref $_[0] ? shift : shift->new; | my $self = ref $_[0] ? shift : shift->new; |
| 633 | my $s = ref $_[0] ? $_[0] : \($_[0]); | my $input = $_[0]; |
| 634 | $self->{document} = $_[1]; | $self->{document} = $_[1]; |
| 635 | @{$self->{document}->child_nodes} = (); | @{$self->{document}->child_nodes} = (); |
| 636 | ||
| # | Line 177 sub parse_string ($$$;$) { | Line 641 sub parse_string ($$$;$) { |
| 641 | if defined $self->{input_encoding}; | if defined $self->{input_encoding}; |
| 642 | ||
| 643 | my $i = 0; | my $i = 0; |
| 644 | my $line = 1; | $self->{line_prev} = $self->{line} = 1; |
| 645 | my $column = 0; | $self->{column_prev} = $self->{column} = 0; |
| 646 | $self->{set_next_input_character} = sub { | $self->{set_next_char} = sub { |
| 647 | my $self = shift; | my $self = shift; |
| 648 | ||
| 649 | pop @{$self->{prev_input_character}}; | pop @{$self->{prev_char}}; |
| 650 | unshift @{$self->{prev_input_character}}, $self->{next_input_character}; | unshift @{$self->{prev_char}}, $self->{next_char}; |
| 651 | ||
| 652 | $self->{next_input_character} = -1 and return if $i >= length $$s; | my $char; |
| 653 | $self->{next_input_character} = ord substr $$s, $i++, 1; | if (defined $self->{next_next_char}) { |
| 654 | $column++; | $char = $self->{next_next_char}; |
| 655 | delete $self->{next_next_char}; | |
| 656 | } else { | |
| 657 | $char = $input->getc; | |
| 658 | } | |
| 659 | $self->{next_char} = -1 and return unless defined $char; | |
| 660 | $self->{next_char} = ord $char; | |
| 661 | ||
| 662 | ($self->{line_prev}, $self->{column_prev}) | |
| 663 | = ($self->{line}, $self->{column}); | |
| 664 | $self->{column}++; | |
| 665 | ||
| 666 | if ($self->{next_input_character} == 0x000A) { # LF | if ($self->{next_char} == 0x000A) { # LF |
| 667 | $line++; | !!!cp ('j1'); |
| 668 | $column = 0; | $self->{line}++; |
| 669 | } elsif ($self->{next_input_character} == 0x000D) { # CR | $self->{column} = 0; |
| 670 | $i++ if substr ($$s, $i, 1) eq "\x0A"; | } elsif ($self->{next_char} == 0x000D) { # CR |
| 671 | $self->{next_input_character} = 0x000A; # LF # MUST | !!!cp ('j2'); |
| 672 | $line++; | my $next = $input->getc; |
| 673 | $column = 0; | if (defined $next and $next ne "\x0A") { |
| 674 | } elsif ($self->{next_input_character} > 0x10FFFF) { | $self->{next_next_char} = $next; |
| 675 | $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST | } |
| 676 | } elsif ($self->{next_input_character} == 0x0000) { # NULL | $self->{next_char} = 0x000A; # LF # MUST |
| 677 | $self->{line}++; | |
| 678 | $self->{column} = 0; | |
| 679 | } elsif ($self->{next_char} > 0x10FFFF) { | |
| 680 | !!!cp ('j3'); | |
| 681 | $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST | |
| 682 | } elsif ($self->{next_char} == 0x0000) { # NULL | |
| 683 | !!!cp ('j4'); | |
| 684 | !!!parse-error (type => 'NULL'); | !!!parse-error (type => 'NULL'); |
| 685 | $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST | $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST |
| 686 | } elsif ($self->{next_char} <= 0x0008 or | |
| 687 | (0x000E <= $self->{next_char} and $self->{next_char} <= 0x001F) or | |
| 688 | (0x007F <= $self->{next_char} and $self->{next_char} <= 0x009F) or | |
| 689 | (0xD800 <= $self->{next_char} and $self->{next_char} <= 0xDFFF) or | |
| 690 | (0xFDD0 <= $self->{next_char} and $self->{next_char} <= 0xFDDF) or | |
| 691 | { | |
| 692 | 0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1, | |
| 693 | 0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1, | |
| 694 | 0x4FFFE => 1, 0x4FFFF => 1, 0x5FFFE => 1, 0x5FFFF => 1, | |
| 695 | 0x6FFFE => 1, 0x6FFFF => 1, 0x7FFFE => 1, 0x7FFFF => 1, | |
| 696 | 0x8FFFE => 1, 0x8FFFF => 1, 0x9FFFE => 1, 0x9FFFF => 1, | |
| 697 | 0xAFFFE => 1, 0xAFFFF => 1, 0xBFFFE => 1, 0xBFFFF => 1, | |
| 698 | 0xCFFFE => 1, 0xCFFFF => 1, 0xDFFFE => 1, 0xDFFFF => 1, | |
| 699 | 0xEFFFE => 1, 0xEFFFF => 1, 0xFFFFE => 1, 0xFFFFF => 1, | |
| 700 | 0x10FFFE => 1, 0x10FFFF => 1, | |
| 701 | }->{$self->{next_char}}) { | |
| 702 | !!!cp ('j5'); | |
| 703 | if ($self->{next_char} < 0x10000) { | |
| 704 | !!!parse-error (type => 'control char', | |
| 705 | text => (sprintf 'U+%04X', $self->{next_char})); | |
| 706 | } else { | |
| 707 | !!!parse-error (type => 'control char', | |
| 708 | text => (sprintf 'U-%08X', $self->{next_char})); | |
| 709 | } | |
| 710 | } | } |
| 711 | }; | }; |
| 712 | $self->{prev_input_character} = [-1, -1, -1]; | $self->{prev_char} = [-1, -1, -1]; |
| 713 | $self->{next_input_character} = -1; | $self->{next_char} = -1; |
| 714 | ||
| 715 | my $onerror = $_[2] || sub { | my $onerror = $_[2] || sub { |
| 716 | my (%opt) = @_; | my (%opt) = @_; |
| 717 | warn "Parse error ($opt{type}) at line $opt{line} column $opt{column}\n"; | my $line = $opt{token} ? $opt{token}->{line} : $opt{line}; |
| 718 | my $column = $opt{token} ? $opt{token}->{column} : $opt{column}; | |
| 719 | warn "Parse error ($opt{type}) at line $line column $column\n"; | |
| 720 | }; | }; |
| 721 | $self->{parse_error} = sub { | $self->{parse_error} = sub { |
| 722 | $onerror->(@_, line => $line, column => $column); | $onerror->(line => $self->{line}, column => $self->{column}, @_); |
| 723 | }; | }; |
| 724 | ||
| 725 | $self->_initialize_tokenizer; | $self->_initialize_tokenizer; |
| # | Line 220 sub parse_string ($$$;$) { | Line 727 sub parse_string ($$$;$) { |
| 727 | $self->_construct_tree; | $self->_construct_tree; |
| 728 | $self->_terminate_tree_constructor; | $self->_terminate_tree_constructor; |
| 729 | ||
| 730 | delete $self->{parse_error}; # remove loop | |
| 731 | ||
| 732 | return $self->{document}; | return $self->{document}; |
| 733 | } # parse_string | } # parse_char_stream |
| 734 | ||
| 735 | sub new ($) { | sub new ($) { |
| 736 | my $class = shift; | my $class = shift; |
| 737 | my $self = bless {}, $class; | my $self = bless { |
| 738 | $self->{set_next_input_character} = sub { | level => {must => 'm', |
| 739 | $self->{next_input_character} = -1; | should => 's', |
| 740 | warn => 'w', | |
| 741 | info => 'i', | |
| 742 | uncertain => 'u'}, | |
| 743 | }, $class; | |
| 744 | $self->{set_next_char} = sub { | |
| 745 | $self->{next_char} = -1; | |
| 746 | }; | }; |
| 747 | $self->{parse_error} = sub { | $self->{parse_error} = sub { |
| 748 | # | # |
| # | Line 287 sub DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUO | Line 802 sub DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUO |
| 802 | sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE () { 31 } | sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE () { 31 } |
| 803 | sub BOGUS_DOCTYPE_STATE () { 32 } | sub BOGUS_DOCTYPE_STATE () { 32 } |
| 804 | sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 } | sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 } |
| 805 | sub SELF_CLOSING_START_TAG_STATE () { 34 } | |
| 806 | sub CDATA_BLOCK_STATE () { 35 } | |
| 807 | ||
| 808 | sub DOCTYPE_TOKEN () { 1 } | sub DOCTYPE_TOKEN () { 1 } |
| 809 | sub COMMENT_TOKEN () { 2 } | sub COMMENT_TOKEN () { 2 } |
| # | Line 303 sub TABLE_IMS () { 0b1000000 } | Line 820 sub TABLE_IMS () { 0b1000000 } |
| 820 | sub ROW_IMS () { 0b10000000 } | sub ROW_IMS () { 0b10000000 } |
| 821 | sub BODY_AFTER_IMS () { 0b100000000 } | sub BODY_AFTER_IMS () { 0b100000000 } |
| 822 | sub FRAME_IMS () { 0b1000000000 } | sub FRAME_IMS () { 0b1000000000 } |
| 823 | sub SELECT_IMS () { 0b10000000000 } | |
| 824 | sub IN_FOREIGN_CONTENT_IM () { 0b100000000000 } | |
| 825 | ## NOTE: "in foreign content" insertion mode is special; it is combined | |
| 826 | ## with the secondary insertion mode. In this parser, they are stored | |
| 827 | ## together in the bit-or'ed form. | |
| 828 | ||
| 829 | ## NOTE: "initial" and "before html" insertion modes have no constants. | |
| 830 | ||
| 831 | ## NOTE: "after after body" insertion mode. | |
| 832 | sub AFTER_HTML_BODY_IM () { AFTER_HTML_IMS | BODY_AFTER_IMS } | sub AFTER_HTML_BODY_IM () { AFTER_HTML_IMS | BODY_AFTER_IMS } |
| 833 | ||
| 834 | ## NOTE: "after after frameset" insertion mode. | |
| 835 | sub AFTER_HTML_FRAMESET_IM () { AFTER_HTML_IMS | FRAME_IMS } | sub AFTER_HTML_FRAMESET_IM () { AFTER_HTML_IMS | FRAME_IMS } |
| 836 | ||
| 837 | sub IN_HEAD_IM () { HEAD_IMS | 0b00 } | sub IN_HEAD_IM () { HEAD_IMS | 0b00 } |
| 838 | sub IN_HEAD_NOSCRIPT_IM () { HEAD_IMS | 0b01 } | sub IN_HEAD_NOSCRIPT_IM () { HEAD_IMS | 0b01 } |
| 839 | sub AFTER_HEAD_IM () { HEAD_IMS | 0b10 } | sub AFTER_HEAD_IM () { HEAD_IMS | 0b10 } |
| # | Line 319 sub IN_TABLE_IM () { TABLE_IMS } | Line 847 sub IN_TABLE_IM () { TABLE_IMS } |
| 847 | sub AFTER_BODY_IM () { BODY_AFTER_IMS } | sub AFTER_BODY_IM () { BODY_AFTER_IMS } |
| 848 | sub IN_FRAMESET_IM () { FRAME_IMS | 0b01 } | sub IN_FRAMESET_IM () { FRAME_IMS | 0b01 } |
| 849 | sub AFTER_FRAMESET_IM () { FRAME_IMS | 0b10 } | sub AFTER_FRAMESET_IM () { FRAME_IMS | 0b10 } |
| 850 | sub IN_SELECT_IM () { 0b01 } | sub IN_SELECT_IM () { SELECT_IMS | 0b01 } |
| 851 | sub IN_SELECT_IN_TABLE_IM () { SELECT_IMS | 0b10 } | |
| 852 | sub IN_COLUMN_GROUP_IM () { 0b10 } | sub IN_COLUMN_GROUP_IM () { 0b10 } |
| 853 | ||
| 854 | ## Implementations MUST act as if state machine in the spec | ## Implementations MUST act as if state machine in the spec |
| # | Line 332 sub _initialize_tokenizer ($) { | Line 861 sub _initialize_tokenizer ($) { |
| 861 | undef $self->{current_attribute}; | undef $self->{current_attribute}; |
| 862 | undef $self->{last_emitted_start_tag_name}; | undef $self->{last_emitted_start_tag_name}; |
| 863 | undef $self->{last_attribute_value_state}; | undef $self->{last_attribute_value_state}; |
| 864 | delete $self->{self_closing}; | |
| 865 | $self->{char} = []; | $self->{char} = []; |
| 866 | # $self->{next_input_character} | # $self->{next_char} |
| 867 | !!!next-input-character; | !!!next-input-character; |
| 868 | $self->{token} = []; | $self->{token} = []; |
| 869 | # $self->{escape} | # $self->{escape} |
| # | Line 346 sub _initialize_tokenizer ($) { | Line 876 sub _initialize_tokenizer ($) { |
| 876 | ## ->{tag_name} (START_TAG_TOKEN, END_TAG_TOKEN) | ## ->{tag_name} (START_TAG_TOKEN, END_TAG_TOKEN) |
| 877 | ## ->{public_identifier} (DOCTYPE_TOKEN) | ## ->{public_identifier} (DOCTYPE_TOKEN) |
| 878 | ## ->{system_identifier} (DOCTYPE_TOKEN) | ## ->{system_identifier} (DOCTYPE_TOKEN) |
| 879 | ## ->{correct} == 1 or 0 (DOCTYPE_TOKEN) | ## ->{quirks} == 1 or 0 (DOCTYPE_TOKEN): "force-quirks" flag |
| 880 | ## ->{attributes} isa HASH (START_TAG_TOKEN, END_TAG_TOKEN) | ## ->{attributes} isa HASH (START_TAG_TOKEN, END_TAG_TOKEN) |
| 881 | ## ->{name} | ## ->{name} |
| 882 | ## ->{value} | ## ->{value} |
| 883 | ## ->{has_reference} == 1 or 0 | ## ->{has_reference} == 1 or 0 |
| 884 | ## ->{data} (COMMENT_TOKEN, CHARACTER_TOKEN) | ## ->{data} (COMMENT_TOKEN, CHARACTER_TOKEN) |
| 885 | ## NOTE: The "self-closing flag" is hold as |$self->{self_closing}|. | |
| 886 | ## |->{self_closing}| is used to save the value of |$self->{self_closing}| | |
| 887 | ## while the token is pushed back to the stack. | |
| 888 | ||
| 889 | ## Emitted token MUST immediately be handled by the tree construction state. | ## Emitted token MUST immediately be handled by the tree construction state. |
| 890 | ||
| # | Line 378 sub _initialize_tokenizer ($) { | Line 911 sub _initialize_tokenizer ($) { |
| 911 | ||
| 912 | sub _get_next_token ($) { | sub _get_next_token ($) { |
| 913 | my $self = shift; | my $self = shift; |
| 914 | ||
| 915 | if ($self->{self_closing}) { | |
| 916 | !!!parse-error (type => 'nestc', token => $self->{current_token}); | |
| 917 | ## NOTE: The |self_closing| flag is only set by start tag token. | |
| 918 | ## In addition, when a start tag token is emitted, it is always set to | |
| 919 | ## |current_token|. | |
| 920 | delete $self->{self_closing}; | |
| 921 | } | |
| 922 | ||
| 923 | if (@{$self->{token}}) { | if (@{$self->{token}}) { |
| 924 | $self->{self_closing} = $self->{token}->[0]->{self_closing}; | |
| 925 | return shift @{$self->{token}}; | return shift @{$self->{token}}; |
| 926 | } | } |
| 927 | ||
| 928 | A: { | A: { |
| 929 | if ($self->{state} == DATA_STATE) { | if ($self->{state} == DATA_STATE) { |
| 930 | if ($self->{next_input_character} == 0x0026) { # & | if ($self->{next_char} == 0x0026) { # & |
| 931 | if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA | if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA |
| 932 | not $self->{escape}) { | not $self->{escape}) { |
| 933 | !!!cp (1); | |
| 934 | $self->{state} = ENTITY_DATA_STATE; | $self->{state} = ENTITY_DATA_STATE; |
| 935 | !!!next-input-character; | !!!next-input-character; |
| 936 | redo A; | redo A; |
| 937 | } else { | } else { |
| 938 | !!!cp (2); | |
| 939 | # | # |
| 940 | } | } |
| 941 | } elsif ($self->{next_input_character} == 0x002D) { # - | } elsif ($self->{next_char} == 0x002D) { # - |
| 942 | if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA | if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA |
| 943 | unless ($self->{escape}) { | unless ($self->{escape}) { |
| 944 | if ($self->{prev_input_character}->[0] == 0x002D and # - | if ($self->{prev_char}->[0] == 0x002D and # - |
| 945 | $self->{prev_input_character}->[1] == 0x0021 and # ! | $self->{prev_char}->[1] == 0x0021 and # ! |
| 946 | $self->{prev_input_character}->[2] == 0x003C) { # < | $self->{prev_char}->[2] == 0x003C) { # < |
| 947 | !!!cp (3); | |
| 948 | $self->{escape} = 1; | $self->{escape} = 1; |
| 949 | } else { | |
| 950 | !!!cp (4); | |
| 951 | } | } |
| 952 | } else { | |
| 953 | !!!cp (5); | |
| 954 | } | } |
| 955 | } | } |
| 956 | ||
| 957 | # | # |
| 958 | } elsif ($self->{next_input_character} == 0x003C) { # < | } elsif ($self->{next_char} == 0x003C) { # < |
| 959 | if ($self->{content_model} & CM_FULL_MARKUP or # PCDATA | if ($self->{content_model} & CM_FULL_MARKUP or # PCDATA |
| 960 | (($self->{content_model} & CM_LIMITED_MARKUP) and # CDATA | RCDATA | (($self->{content_model} & CM_LIMITED_MARKUP) and # CDATA | RCDATA |
| 961 | not $self->{escape})) { | not $self->{escape})) { |
| 962 | !!!cp (6); | |
| 963 | $self->{state} = TAG_OPEN_STATE; | $self->{state} = TAG_OPEN_STATE; |
| 964 | !!!next-input-character; | !!!next-input-character; |
| 965 | redo A; | redo A; |
| 966 | } else { | } else { |
| 967 | !!!cp (7); | |
| 968 | # | # |
| 969 | } | } |
| 970 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 971 | if ($self->{escape} and | if ($self->{escape} and |
| 972 | ($self->{content_model} & CM_LIMITED_MARKUP)) { # RCDATA | CDATA | ($self->{content_model} & CM_LIMITED_MARKUP)) { # RCDATA | CDATA |
| 973 | if ($self->{prev_input_character}->[0] == 0x002D and # - | if ($self->{prev_char}->[0] == 0x002D and # - |
| 974 | $self->{prev_input_character}->[1] == 0x002D) { # - | $self->{prev_char}->[1] == 0x002D) { # - |
| 975 | !!!cp (8); | |
| 976 | delete $self->{escape}; | delete $self->{escape}; |
| 977 | } else { | |
| 978 | !!!cp (9); | |
| 979 | } | } |
| 980 | } else { | |
| 981 | !!!cp (10); | |
| 982 | } | } |
| 983 | ||
| 984 | # | # |
| 985 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 986 | !!!emit ({type => END_OF_FILE_TOKEN}); | !!!cp (11); |
| 987 | !!!emit ({type => END_OF_FILE_TOKEN, | |
| 988 | line => $self->{line}, column => $self->{column}}); | |
| 989 | last A; ## TODO: ok? | last A; ## TODO: ok? |
| 990 | } else { | |
| 991 | !!!cp (12); | |
| 992 | } | } |
| 993 | # Anything else | # Anything else |
| 994 | my $token = {type => CHARACTER_TOKEN, | my $token = {type => CHARACTER_TOKEN, |
| 995 | data => chr $self->{next_input_character}}; | data => chr $self->{next_char}, |
| 996 | line => $self->{line}, column => $self->{column}, | |
| 997 | }; | |
| 998 | ## Stay in the data state | ## Stay in the data state |
| 999 | !!!next-input-character; | !!!next-input-character; |
| 1000 | ||
| # | Line 440 sub _get_next_token ($) { | Line 1003 sub _get_next_token ($) { |
| 1003 | redo A; | redo A; |
| 1004 | } elsif ($self->{state} == ENTITY_DATA_STATE) { | } elsif ($self->{state} == ENTITY_DATA_STATE) { |
| 1005 | ## (cannot happen in CDATA state) | ## (cannot happen in CDATA state) |
| 1006 | ||
| 1007 | my ($l, $c) = ($self->{line_prev}, $self->{column_prev}); | |
| 1008 | ||
| 1009 | my $token = $self->_tokenize_attempt_to_consume_an_entity (0, -1); | my $token = $self->_tokenize_attempt_to_consume_an_entity (0, -1); |
| 1010 | ||
| # | Line 447 sub _get_next_token ($) { | Line 1012 sub _get_next_token ($) { |
| 1012 | # next-input-character is already done | # next-input-character is already done |
| 1013 | ||
| 1014 | unless (defined $token) { | unless (defined $token) { |
| 1015 | !!!emit ({type => CHARACTER_TOKEN, data => '&'}); | !!!cp (13); |
| 1016 | !!!emit ({type => CHARACTER_TOKEN, data => '&', | |
| 1017 | line => $l, column => $c, | |
| 1018 | }); | |
| 1019 | } else { | } else { |
| 1020 | !!!cp (14); | |
| 1021 | !!!emit ($token); | !!!emit ($token); |
| 1022 | } | } |
| 1023 | ||
| 1024 | redo A; | redo A; |
| 1025 | } elsif ($self->{state} == TAG_OPEN_STATE) { | } elsif ($self->{state} == TAG_OPEN_STATE) { |
| 1026 | if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA | if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA |
| 1027 | if ($self->{next_input_character} == 0x002F) { # / | if ($self->{next_char} == 0x002F) { # / |
| 1028 | !!!cp (15); | |
| 1029 | !!!next-input-character; | !!!next-input-character; |
| 1030 | $self->{state} = CLOSE_TAG_OPEN_STATE; | $self->{state} = CLOSE_TAG_OPEN_STATE; |
| 1031 | redo A; | redo A; |
| 1032 | } else { | } else { |
| 1033 | !!!cp (16); | |
| 1034 | ## reconsume | ## reconsume |
| 1035 | $self->{state} = DATA_STATE; | $self->{state} = DATA_STATE; |
| 1036 | ||
| 1037 | !!!emit ({type => CHARACTER_TOKEN, data => '<'}); | !!!emit ({type => CHARACTER_TOKEN, data => '<', |
| 1038 | line => $self->{line_prev}, | |
| 1039 | column => $self->{column_prev}, | |
| 1040 | }); | |
| 1041 | ||
| 1042 | redo A; | redo A; |
| 1043 | } | } |
| 1044 | } elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA | } elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA |
| 1045 | if ($self->{next_input_character} == 0x0021) { # ! | if ($self->{next_char} == 0x0021) { # ! |
| 1046 | !!!cp (17); | |
| 1047 | $self->{state} = MARKUP_DECLARATION_OPEN_STATE; | $self->{state} = MARKUP_DECLARATION_OPEN_STATE; |
| 1048 | !!!next-input-character; | !!!next-input-character; |
| 1049 | redo A; | redo A; |
| 1050 | } elsif ($self->{next_input_character} == 0x002F) { # / | } elsif ($self->{next_char} == 0x002F) { # / |
| 1051 | !!!cp (18); | |
| 1052 | $self->{state} = CLOSE_TAG_OPEN_STATE; | $self->{state} = CLOSE_TAG_OPEN_STATE; |
| 1053 | !!!next-input-character; | !!!next-input-character; |
| 1054 | redo A; | redo A; |
| 1055 | } elsif (0x0041 <= $self->{next_input_character} and | } elsif (0x0041 <= $self->{next_char} and |
| 1056 | $self->{next_input_character} <= 0x005A) { # A..Z | $self->{next_char} <= 0x005A) { # A..Z |
| 1057 | !!!cp (19); | |
| 1058 | $self->{current_token} | $self->{current_token} |
| 1059 | = {type => START_TAG_TOKEN, | = {type => START_TAG_TOKEN, |
| 1060 | tag_name => chr ($self->{next_input_character} + 0x0020)}; | tag_name => chr ($self->{next_char} + 0x0020), |
| 1061 | line => $self->{line_prev}, | |
| 1062 | column => $self->{column_prev}}; | |
| 1063 | $self->{state} = TAG_NAME_STATE; | $self->{state} = TAG_NAME_STATE; |
| 1064 | !!!next-input-character; | !!!next-input-character; |
| 1065 | redo A; | redo A; |
| 1066 | } elsif (0x0061 <= $self->{next_input_character} and | } elsif (0x0061 <= $self->{next_char} and |
| 1067 | $self->{next_input_character} <= 0x007A) { # a..z | $self->{next_char} <= 0x007A) { # a..z |
| 1068 | !!!cp (20); | |
| 1069 | $self->{current_token} = {type => START_TAG_TOKEN, | $self->{current_token} = {type => START_TAG_TOKEN, |
| 1070 | tag_name => chr ($self->{next_input_character})}; | tag_name => chr ($self->{next_char}), |
| 1071 | line => $self->{line_prev}, | |
| 1072 | column => $self->{column_prev}}; | |
| 1073 | $self->{state} = TAG_NAME_STATE; | $self->{state} = TAG_NAME_STATE; |
| 1074 | !!!next-input-character; | !!!next-input-character; |
| 1075 | redo A; | redo A; |
| 1076 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 1077 | !!!parse-error (type => 'empty start tag'); | !!!cp (21); |
| 1078 | !!!parse-error (type => 'empty start tag', | |
| 1079 | line => $self->{line_prev}, | |
| 1080 | column => $self->{column_prev}); | |
| 1081 | $self->{state} = DATA_STATE; | $self->{state} = DATA_STATE; |
| 1082 | !!!next-input-character; | !!!next-input-character; |
| 1083 | ||
| 1084 | !!!emit ({type => CHARACTER_TOKEN, data => '<>'}); | !!!emit ({type => CHARACTER_TOKEN, data => '<>', |
| 1085 | line => $self->{line_prev}, | |
| 1086 | column => $self->{column_prev}, | |
| 1087 | }); | |
| 1088 | ||
| 1089 | redo A; | redo A; |
| 1090 | } elsif ($self->{next_input_character} == 0x003F) { # ? | } elsif ($self->{next_char} == 0x003F) { # ? |
| 1091 | !!!parse-error (type => 'pio'); | !!!cp (22); |
| 1092 | !!!parse-error (type => 'pio', | |
| 1093 | line => $self->{line_prev}, | |
| 1094 | column => $self->{column_prev}); | |
| 1095 | $self->{state} = BOGUS_COMMENT_STATE; | $self->{state} = BOGUS_COMMENT_STATE; |
| 1096 | ## $self->{next_input_character} is intentionally left as is | $self->{current_token} = {type => COMMENT_TOKEN, data => '', |
| 1097 | line => $self->{line_prev}, | |
| 1098 | column => $self->{column_prev}, | |
| 1099 | }; | |
| 1100 | ## $self->{next_char} is intentionally left as is | |
| 1101 | redo A; | redo A; |
| 1102 | } else { | } else { |
| 1103 | !!!parse-error (type => 'bare stago'); | !!!cp (23); |
| 1104 | !!!parse-error (type => 'bare stago', | |
| 1105 | line => $self->{line_prev}, | |
| 1106 | column => $self->{column_prev}); | |
| 1107 | $self->{state} = DATA_STATE; | $self->{state} = DATA_STATE; |
| 1108 | ## reconsume | ## reconsume |
| 1109 | ||
| 1110 | !!!emit ({type => CHARACTER_TOKEN, data => '<'}); | !!!emit ({type => CHARACTER_TOKEN, data => '<', |
| 1111 | line => $self->{line_prev}, | |
| 1112 | column => $self->{column_prev}, | |
| 1113 | }); | |
| 1114 | ||
| 1115 | redo A; | redo A; |
| 1116 | } | } |
| # | Line 517 sub _get_next_token ($) { | Line 1118 sub _get_next_token ($) { |
| 1118 | die "$0: $self->{content_model} in tag open"; | die "$0: $self->{content_model} in tag open"; |
| 1119 | } | } |
| 1120 | } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) { | } elsif ($self->{state} == CLOSE_TAG_OPEN_STATE) { |
| 1121 | my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); # "<"of"</" | |
| 1122 | if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA | if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA |
| 1123 | if (defined $self->{last_emitted_start_tag_name}) { | if (defined $self->{last_emitted_start_tag_name}) { |
| 1124 | ||
| 1125 | ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564> | ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564> |
| 1126 | my @next_char; | my @next_char; |
| 1127 | TAGNAME: for (my $i = 0; $i < length $self->{last_emitted_start_tag_name}; $i++) { | TAGNAME: for (my $i = 0; $i < length $self->{last_emitted_start_tag_name}; $i++) { |
| 1128 | push @next_char, $self->{next_input_character}; | push @next_char, $self->{next_char}; |
| 1129 | my $c = ord substr ($self->{last_emitted_start_tag_name}, $i, 1); | my $c = ord substr ($self->{last_emitted_start_tag_name}, $i, 1); |
| 1130 | my $C = 0x0061 <= $c && $c <= 0x007A ? $c - 0x0020 : $c; | my $C = 0x0061 <= $c && $c <= 0x007A ? $c - 0x0020 : $c; |
| 1131 | if ($self->{next_input_character} == $c or $self->{next_input_character} == $C) { | if ($self->{next_char} == $c or $self->{next_char} == $C) { |
| 1132 | !!!cp (24); | |
| 1133 | !!!next-input-character; | !!!next-input-character; |
| 1134 | next TAGNAME; | next TAGNAME; |
| 1135 | } else { | } else { |
| 1136 | $self->{next_input_character} = shift @next_char; # reconsume | !!!cp (25); |
| 1137 | $self->{next_char} = shift @next_char; # reconsume | |
| 1138 | !!!back-next-input-character (@next_char); | !!!back-next-input-character (@next_char); |
| 1139 | $self->{state} = DATA_STATE; | $self->{state} = DATA_STATE; |
| 1140 | ||
| 1141 | !!!emit ({type => CHARACTER_TOKEN, data => '</'}); | !!!emit ({type => CHARACTER_TOKEN, data => '</', |
| 1142 | line => $l, column => $c, | |
| 1143 | }); | |
| 1144 | ||
| 1145 | redo A; | redo A; |
| 1146 | } | } |
| 1147 | } | } |
| 1148 | push @next_char, $self->{next_input_character}; | push @next_char, $self->{next_char}; |
| 1149 | ||
| 1150 | unless ($self->{next_input_character} == 0x0009 or # HT | unless ($self->{next_char} == 0x0009 or # HT |
| 1151 | $self->{next_input_character} == 0x000A or # LF | $self->{next_char} == 0x000A or # LF |
| 1152 | $self->{next_input_character} == 0x000B or # VT | $self->{next_char} == 0x000B or # VT |
| 1153 | $self->{next_input_character} == 0x000C or # FF | $self->{next_char} == 0x000C or # FF |
| 1154 | $self->{next_input_character} == 0x0020 or # SP | $self->{next_char} == 0x0020 or # SP |
| 1155 | $self->{next_input_character} == 0x003E or # > | $self->{next_char} == 0x003E or # > |
| 1156 | $self->{next_input_character} == 0x002F or # / | $self->{next_char} == 0x002F or # / |
| 1157 | $self->{next_input_character} == -1) { | $self->{next_char} == -1) { |
| 1158 | $self->{next_input_character} = shift @next_char; # reconsume | !!!cp (26); |
| 1159 | $self->{next_char} = shift @next_char; # reconsume | |
| 1160 | !!!back-next-input-character (@next_char); | !!!back-next-input-character (@next_char); |
| 1161 | $self->{state} = DATA_STATE; | $self->{state} = DATA_STATE; |
| 1162 | !!!emit ({type => CHARACTER_TOKEN, data => '</'}); | !!!emit ({type => CHARACTER_TOKEN, data => '</', |
| 1163 | line => $l, column => $c, | |
| 1164 | }); | |
| 1165 | redo A; | redo A; |
| 1166 | } else { | } else { |
| 1167 | $self->{next_input_character} = shift @next_char; | !!!cp (27); |
| 1168 | $self->{next_char} = shift @next_char; | |
| 1169 | !!!back-next-input-character (@next_char); | !!!back-next-input-character (@next_char); |
| 1170 | # and consume... | # and consume... |
| 1171 | } | } |
| 1172 | } else { | } else { |
| 1173 | ## No start tag token has ever been emitted | ## No start tag token has ever been emitted |
| 1174 | !!!cp (28); | |
| 1175 | # next-input-character is already done | # next-input-character is already done |
| 1176 | $self->{state} = DATA_STATE; | $self->{state} = DATA_STATE; |
| 1177 | !!!emit ({type => CHARACTER_TOKEN, data => '</'}); | !!!emit ({type => CHARACTER_TOKEN, data => '</', |
| 1178 | line => $l, column => $c, | |
| 1179 | }); | |
| 1180 | redo A; | redo A; |
| 1181 | } | } |
| 1182 | } | } |
| 1183 | ||
| 1184 | if (0x0041 <= $self->{next_input_character} and | if (0x0041 <= $self->{next_char} and |
| 1185 | $self->{next_input_character} <= 0x005A) { # A..Z | $self->{next_char} <= 0x005A) { # A..Z |
| 1186 | $self->{current_token} = {type => END_TAG_TOKEN, | !!!cp (29); |
| 1187 | tag_name => chr ($self->{next_input_character} + 0x0020)}; | $self->{current_token} |
| 1188 | = {type => END_TAG_TOKEN, | |
| 1189 | tag_name => chr ($self->{next_char} + 0x0020), | |
| 1190 | line => $l, column => $c}; | |
| 1191 | $self->{state} = TAG_NAME_STATE; | $self->{state} = TAG_NAME_STATE; |
| 1192 | !!!next-input-character; | !!!next-input-character; |
| 1193 | redo A; | redo A; |
| 1194 | } elsif (0x0061 <= $self->{next_input_character} and | } elsif (0x0061 <= $self->{next_char} and |
| 1195 | $self->{next_input_character} <= 0x007A) { # a..z | $self->{next_char} <= 0x007A) { # a..z |
| 1196 | !!!cp (30); | |
| 1197 | $self->{current_token} = {type => END_TAG_TOKEN, | $self->{current_token} = {type => END_TAG_TOKEN, |
| 1198 | tag_name => chr ($self->{next_input_character})}; | tag_name => chr ($self->{next_char}), |
| 1199 | line => $l, column => $c}; | |
| 1200 | $self->{state} = TAG_NAME_STATE; | $self->{state} = TAG_NAME_STATE; |
| 1201 | !!!next-input-character; | !!!next-input-character; |
| 1202 | redo A; | redo A; |
| 1203 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 1204 | !!!parse-error (type => 'empty end tag'); | !!!cp (31); |
| 1205 | !!!parse-error (type => 'empty end tag', | |
| 1206 | line => $self->{line_prev}, ## "<" in "</>" | |
| 1207 | column => $self->{column_prev} - 1); | |
| 1208 | $self->{state} = DATA_STATE; | $self->{state} = DATA_STATE; |
| 1209 | !!!next-input-character; | !!!next-input-character; |
| 1210 | redo A; | redo A; |
| 1211 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1212 | !!!cp (32); | |
| 1213 | !!!parse-error (type => 'bare etago'); | !!!parse-error (type => 'bare etago'); |
| 1214 | $self->{state} = DATA_STATE; | $self->{state} = DATA_STATE; |
| 1215 | # reconsume | # reconsume |
| 1216 | ||
| 1217 | !!!emit ({type => CHARACTER_TOKEN, data => '</'}); | !!!emit ({type => CHARACTER_TOKEN, data => '</', |
| 1218 | line => $l, column => $c, | |
| 1219 | }); | |
| 1220 | ||
| 1221 | redo A; | redo A; |
| 1222 | } else { | } else { |
| 1223 | !!!cp (33); | |
| 1224 | !!!parse-error (type => 'bogus end tag'); | !!!parse-error (type => 'bogus end tag'); |
| 1225 | $self->{state} = BOGUS_COMMENT_STATE; | $self->{state} = BOGUS_COMMENT_STATE; |
| 1226 | ## $self->{next_input_character} is intentionally left as is | $self->{current_token} = {type => COMMENT_TOKEN, data => '', |
| 1227 | line => $self->{line_prev}, # "<" of "</" | |
| 1228 | column => $self->{column_prev} - 1, | |
| 1229 | }; | |
| 1230 | ## $self->{next_char} is intentionally left as is | |
| 1231 | redo A; | redo A; |
| 1232 | } | } |
| 1233 | } elsif ($self->{state} == TAG_NAME_STATE) { | } elsif ($self->{state} == TAG_NAME_STATE) { |
| 1234 | if ($self->{next_input_character} == 0x0009 or # HT | if ($self->{next_char} == 0x0009 or # HT |
| 1235 | $self->{next_input_character} == 0x000A or # LF | $self->{next_char} == 0x000A or # LF |
| 1236 | $self->{next_input_character} == 0x000B or # VT | $self->{next_char} == 0x000B or # VT |
| 1237 | $self->{next_input_character} == 0x000C or # FF | $self->{next_char} == 0x000C or # FF |
| 1238 | $self->{next_input_character} == 0x0020) { # SP | $self->{next_char} == 0x0020) { # SP |
| 1239 | !!!cp (34); | |
| 1240 | $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; | $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
| 1241 | !!!next-input-character; | !!!next-input-character; |
| 1242 | redo A; | redo A; |
| 1243 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 1244 | if ($self->{current_token}->{type} == START_TAG_TOKEN) { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1245 | $self->{current_token}->{first_start_tag} | !!!cp (35); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1246 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1247 | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1248 | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1249 | if ($self->{current_token}->{attributes}) { | #if ($self->{current_token}->{attributes}) { |
| 1250 | !!!parse-error (type => 'end tag attribute'); | # ## NOTE: This should never be reached. |
| 1251 | } | # !!! cp (36); |
| 1252 | # !!! parse-error (type => 'end tag attribute'); | |
| 1253 | #} else { | |
| 1254 | !!!cp (37); | |
| 1255 | #} | |
| 1256 | } else { | } else { |
| 1257 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| 1258 | } | } |
| # | Line 628 sub _get_next_token ($) { | Line 1262 sub _get_next_token ($) { |
| 1262 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 1263 | ||
| 1264 | redo A; | redo A; |
| 1265 | } elsif (0x0041 <= $self->{next_input_character} and | } elsif (0x0041 <= $self->{next_char} and |
| 1266 | $self->{next_input_character} <= 0x005A) { # A..Z | $self->{next_char} <= 0x005A) { # A..Z |
| 1267 | $self->{current_token}->{tag_name} .= chr ($self->{next_input_character} + 0x0020); | !!!cp (38); |
| 1268 | $self->{current_token}->{tag_name} .= chr ($self->{next_char} + 0x0020); | |
| 1269 | # start tag or end tag | # start tag or end tag |
| 1270 | ## Stay in this state | ## Stay in this state |
| 1271 | !!!next-input-character; | !!!next-input-character; |
| 1272 | redo A; | redo A; |
| 1273 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1274 | !!!parse-error (type => 'unclosed tag'); | !!!parse-error (type => 'unclosed tag'); |
| 1275 | if ($self->{current_token}->{type} == START_TAG_TOKEN) { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1276 | $self->{current_token}->{first_start_tag} | !!!cp (39); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1277 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1278 | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1279 | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1280 | if ($self->{current_token}->{attributes}) { | #if ($self->{current_token}->{attributes}) { |
| 1281 | !!!parse-error (type => 'end tag attribute'); | # ## NOTE: This state should never be reached. |
| 1282 | } | # !!! cp (40); |
| 1283 | # !!! parse-error (type => 'end tag attribute'); | |
| 1284 | #} else { | |
| 1285 | !!!cp (41); | |
| 1286 | #} | |
| 1287 | } else { | } else { |
| 1288 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| 1289 | } | } |
| # | Line 655 sub _get_next_token ($) { | Line 1293 sub _get_next_token ($) { |
| 1293 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 1294 | ||
| 1295 | redo A; | redo A; |
| 1296 | } elsif ($self->{next_input_character} == 0x002F) { # / | } elsif ($self->{next_char} == 0x002F) { # / |
| 1297 | !!!cp (42); | |
| 1298 | $self->{state} = SELF_CLOSING_START_TAG_STATE; | |
| 1299 | !!!next-input-character; | !!!next-input-character; |
| if ($self->{next_input_character} == 0x003E and # > | ||
| $self->{current_token}->{type} == START_TAG_TOKEN and | ||
| $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) { | ||
| # permitted slash | ||
| # | ||
| } else { | ||
| !!!parse-error (type => 'nestc'); | ||
| } | ||
| $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; | ||
| # next-input-character is already done | ||
| 1300 | redo A; | redo A; |
| 1301 | } else { | } else { |
| 1302 | $self->{current_token}->{tag_name} .= chr $self->{next_input_character}; | !!!cp (44); |
| 1303 | $self->{current_token}->{tag_name} .= chr $self->{next_char}; | |
| 1304 | # start tag or end tag | # start tag or end tag |
| 1305 | ## Stay in the state | ## Stay in the state |
| 1306 | !!!next-input-character; | !!!next-input-character; |
| 1307 | redo A; | redo A; |
| 1308 | } | } |
| 1309 | } elsif ($self->{state} == BEFORE_ATTRIBUTE_NAME_STATE) { | } elsif ($self->{state} == BEFORE_ATTRIBUTE_NAME_STATE) { |
| 1310 | if ($self->{next_input_character} == 0x0009 or # HT | if ($self->{next_char} == 0x0009 or # HT |
| 1311 | $self->{next_input_character} == 0x000A or # LF | $self->{next_char} == 0x000A or # LF |
| 1312 | $self->{next_input_character} == 0x000B or # VT | $self->{next_char} == 0x000B or # VT |
| 1313 | $self->{next_input_character} == 0x000C or # FF | $self->{next_char} == 0x000C or # FF |
| 1314 | $self->{next_input_character} == 0x0020) { # SP | $self->{next_char} == 0x0020) { # SP |
| 1315 | !!!cp (45); | |
| 1316 | ## Stay in the state | ## Stay in the state |
| 1317 | !!!next-input-character; | !!!next-input-character; |
| 1318 | redo A; | redo A; |
| 1319 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 1320 | if ($self->{current_token}->{type} == START_TAG_TOKEN) { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1321 | $self->{current_token}->{first_start_tag} | !!!cp (46); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1322 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1323 | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1324 | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1325 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1326 | !!!cp (47); | |
| 1327 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1328 | } else { | |
| 1329 | !!!cp (48); | |
| 1330 | } | } |
| 1331 | } else { | } else { |
| 1332 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| # | Line 703 sub _get_next_token ($) { | Line 1337 sub _get_next_token ($) { |
| 1337 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 1338 | ||
| 1339 | redo A; | redo A; |
| 1340 | } elsif (0x0041 <= $self->{next_input_character} and | } elsif (0x0041 <= $self->{next_char} and |
| 1341 | $self->{next_input_character} <= 0x005A) { # A..Z | $self->{next_char} <= 0x005A) { # A..Z |
| 1342 | $self->{current_attribute} = {name => chr ($self->{next_input_character} + 0x0020), | !!!cp (49); |
| 1343 | value => ''}; | $self->{current_attribute} |
| 1344 | = {name => chr ($self->{next_char} + 0x0020), | |
| 1345 | value => '', | |
| 1346 | line => $self->{line}, column => $self->{column}}; | |
| 1347 | $self->{state} = ATTRIBUTE_NAME_STATE; | $self->{state} = ATTRIBUTE_NAME_STATE; |
| 1348 | !!!next-input-character; | !!!next-input-character; |
| 1349 | redo A; | redo A; |
| 1350 | } elsif ($self->{next_input_character} == 0x002F) { # / | } elsif ($self->{next_char} == 0x002F) { # / |
| 1351 | !!!cp (50); | |
| 1352 | $self->{state} = SELF_CLOSING_START_TAG_STATE; | |
| 1353 | !!!next-input-character; | !!!next-input-character; |
| if ($self->{next_input_character} == 0x003E and # > | ||
| $self->{current_token}->{type} == START_TAG_TOKEN and | ||
| $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) { | ||
| # permitted slash | ||
| # | ||
| } else { | ||
| !!!parse-error (type => 'nestc'); | ||
| } | ||
| ## Stay in the state | ||
| # next-input-character is already done | ||
| 1354 | redo A; | redo A; |
| 1355 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1356 | !!!parse-error (type => 'unclosed tag'); | !!!parse-error (type => 'unclosed tag'); |
| 1357 | if ($self->{current_token}->{type} == START_TAG_TOKEN) { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1358 | $self->{current_token}->{first_start_tag} | !!!cp (52); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1359 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1360 | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1361 | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1362 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1363 | !!!cp (53); | |
| 1364 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1365 | } else { | |
| 1366 | !!!cp (54); | |
| 1367 | } | } |
| 1368 | } else { | } else { |
| 1369 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| # | Line 748 sub _get_next_token ($) { | Line 1379 sub _get_next_token ($) { |
| 1379 | 0x0022 => 1, # " | 0x0022 => 1, # " |
| 1380 | 0x0027 => 1, # ' | 0x0027 => 1, # ' |
| 1381 | 0x003D => 1, # = | 0x003D => 1, # = |
| 1382 | }->{$self->{next_input_character}}) { | }->{$self->{next_char}}) { |
| 1383 | !!!cp (55); | |
| 1384 | !!!parse-error (type => 'bad attribute name'); | !!!parse-error (type => 'bad attribute name'); |
| 1385 | } else { | |
| 1386 | !!!cp (56); | |
| 1387 | } | } |
| 1388 | $self->{current_attribute} = {name => chr ($self->{next_input_character}), | $self->{current_attribute} |
| 1389 | value => ''}; | = {name => chr ($self->{next_char}), |
| 1390 | value => '', | |
| 1391 | line => $self->{line}, column => $self->{column}}; | |
| 1392 | $self->{state} = ATTRIBUTE_NAME_STATE; | $self->{state} = ATTRIBUTE_NAME_STATE; |
| 1393 | !!!next-input-character; | !!!next-input-character; |
| 1394 | redo A; | redo A; |
| # | Line 761 sub _get_next_token ($) { | Line 1397 sub _get_next_token ($) { |
| 1397 | my $before_leave = sub { | my $before_leave = sub { |
| 1398 | if (exists $self->{current_token}->{attributes} # start tag or end tag | if (exists $self->{current_token}->{attributes} # start tag or end tag |
| 1399 | ->{$self->{current_attribute}->{name}}) { # MUST | ->{$self->{current_attribute}->{name}}) { # MUST |
| 1400 | !!!parse-error (type => 'duplicate attribute:'.$self->{current_attribute}->{name}); | !!!cp (57); |
| 1401 | !!!parse-error (type => 'duplicate attribute', text => $self->{current_attribute}->{name}, line => $self->{current_attribute}->{line}, column => $self->{current_attribute}->{column}); | |
| 1402 | ## Discard $self->{current_attribute} # MUST | ## Discard $self->{current_attribute} # MUST |
| 1403 | } else { | } else { |
| 1404 | !!!cp (58); | |
| 1405 | $self->{current_token}->{attributes}->{$self->{current_attribute}->{name}} | $self->{current_token}->{attributes}->{$self->{current_attribute}->{name}} |
| 1406 | = $self->{current_attribute}; | = $self->{current_attribute}; |
| 1407 | } | } |
| 1408 | }; # $before_leave | }; # $before_leave |
| 1409 | ||
| 1410 | if ($self->{next_input_character} == 0x0009 or # HT | if ($self->{next_char} == 0x0009 or # HT |
| 1411 | $self->{next_input_character} == 0x000A or # LF | $self->{next_char} == 0x000A or # LF |
| 1412 | $self->{next_input_character} == 0x000B or # VT | $self->{next_char} == 0x000B or # VT |
| 1413 | $self->{next_input_character} == 0x000C or # FF | $self->{next_char} == 0x000C or # FF |
| 1414 | $self->{next_input_character} == 0x0020) { # SP | $self->{next_char} == 0x0020) { # SP |
| 1415 | !!!cp (59); | |
| 1416 | $before_leave->(); | $before_leave->(); |
| 1417 | $self->{state} = AFTER_ATTRIBUTE_NAME_STATE; | $self->{state} = AFTER_ATTRIBUTE_NAME_STATE; |
| 1418 | !!!next-input-character; | !!!next-input-character; |
| 1419 | redo A; | redo A; |
| 1420 | } elsif ($self->{next_input_character} == 0x003D) { # = | } elsif ($self->{next_char} == 0x003D) { # = |
| 1421 | !!!cp (60); | |
| 1422 | $before_leave->(); | $before_leave->(); |
| 1423 | $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE; | $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE; |
| 1424 | !!!next-input-character; | !!!next-input-character; |
| 1425 | redo A; | redo A; |
| 1426 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 1427 | $before_leave->(); | $before_leave->(); |
| 1428 | if ($self->{current_token}->{type} == START_TAG_TOKEN) { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1429 | $self->{current_token}->{first_start_tag} | !!!cp (61); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1430 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1431 | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1432 | !!!cp (62); | |
| 1433 | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1434 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1435 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| # | Line 803 sub _get_next_token ($) { | Line 1443 sub _get_next_token ($) { |
| 1443 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 1444 | ||
| 1445 | redo A; | redo A; |
| 1446 | } elsif (0x0041 <= $self->{next_input_character} and | } elsif (0x0041 <= $self->{next_char} and |
| 1447 | $self->{next_input_character} <= 0x005A) { # A..Z | $self->{next_char} <= 0x005A) { # A..Z |
| 1448 | $self->{current_attribute}->{name} .= chr ($self->{next_input_character} + 0x0020); | !!!cp (63); |
| 1449 | $self->{current_attribute}->{name} .= chr ($self->{next_char} + 0x0020); | |
| 1450 | ## Stay in the state | ## Stay in the state |
| 1451 | !!!next-input-character; | !!!next-input-character; |
| 1452 | redo A; | redo A; |
| 1453 | } elsif ($self->{next_input_character} == 0x002F) { # / | } elsif ($self->{next_char} == 0x002F) { # / |
| 1454 | !!!cp (64); | |
| 1455 | $before_leave->(); | $before_leave->(); |
| 1456 | $self->{state} = SELF_CLOSING_START_TAG_STATE; | |
| 1457 | !!!next-input-character; | !!!next-input-character; |
| if ($self->{next_input_character} == 0x003E and # > | ||
| $self->{current_token}->{type} == START_TAG_TOKEN and | ||
| $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) { | ||
| # permitted slash | ||
| # | ||
| } else { | ||
| !!!parse-error (type => 'nestc'); | ||
| } | ||
| $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; | ||
| # next-input-character is already done | ||
| 1458 | redo A; | redo A; |
| 1459 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1460 | !!!parse-error (type => 'unclosed tag'); | !!!parse-error (type => 'unclosed tag'); |
| 1461 | $before_leave->(); | $before_leave->(); |
| 1462 | if ($self->{current_token}->{type} == START_TAG_TOKEN) { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1463 | $self->{current_token}->{first_start_tag} | !!!cp (66); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1464 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1465 | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1466 | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1467 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1468 | !!!cp (67); | |
| 1469 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1470 | } else { | |
| 1471 | ## NOTE: This state should never be reached. | |
| 1472 | !!!cp (68); | |
| 1473 | } | } |
| 1474 | } else { | } else { |
| 1475 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| # | Line 845 sub _get_next_token ($) { | Line 1481 sub _get_next_token ($) { |
| 1481 | ||
| 1482 | redo A; | redo A; |
| 1483 | } else { | } else { |
| 1484 | if ($self->{next_input_character} == 0x0022 or # " | if ($self->{next_char} == 0x0022 or # " |
| 1485 | $self->{next_input_character} == 0x0027) { # ' | $self->{next_char} == 0x0027) { # ' |
| 1486 | !!!cp (69); | |
| 1487 | !!!parse-error (type => 'bad attribute name'); | !!!parse-error (type => 'bad attribute name'); |
| 1488 | } else { | |
| 1489 | !!!cp (70); | |
| 1490 | } | } |
| 1491 | $self->{current_attribute}->{name} .= chr ($self->{next_input_character}); | $self->{current_attribute}->{name} .= chr ($self->{next_char}); |
| 1492 | ## Stay in the state | ## Stay in the state |
| 1493 | !!!next-input-character; | !!!next-input-character; |
| 1494 | redo A; | redo A; |
| 1495 | } | } |
| 1496 | } elsif ($self->{state} == AFTER_ATTRIBUTE_NAME_STATE) { | } elsif ($self->{state} == AFTER_ATTRIBUTE_NAME_STATE) { |
| 1497 | if ($self->{next_input_character} == 0x0009 or # HT | if ($self->{next_char} == 0x0009 or # HT |
| 1498 | $self->{next_input_character} == 0x000A or # LF | $self->{next_char} == 0x000A or # LF |
| 1499 | $self->{next_input_character} == 0x000B or # VT | $self->{next_char} == 0x000B or # VT |
| 1500 | $self->{next_input_character} == 0x000C or # FF | $self->{next_char} == 0x000C or # FF |
| 1501 | $self->{next_input_character} == 0x0020) { # SP | $self->{next_char} == 0x0020) { # SP |
| 1502 | !!!cp (71); | |
| 1503 | ## Stay in the state | ## Stay in the state |
| 1504 | !!!next-input-character; | !!!next-input-character; |
| 1505 | redo A; | redo A; |
| 1506 | } elsif ($self->{next_input_character} == 0x003D) { # = | } elsif ($self->{next_char} == 0x003D) { # = |
| 1507 | !!!cp (72); | |
| 1508 | $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE; | $self->{state} = BEFORE_ATTRIBUTE_VALUE_STATE; |
| 1509 | !!!next-input-character; | !!!next-input-character; |
| 1510 | redo A; | redo A; |
| 1511 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 1512 | if ($self->{current_token}->{type} == START_TAG_TOKEN) { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1513 | $self->{current_token}->{first_start_tag} | !!!cp (73); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1514 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1515 | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1516 | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1517 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1518 | !!!cp (74); | |
| 1519 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1520 | } else { | |
| 1521 | ## NOTE: This state should never be reached. | |
| 1522 | !!!cp (75); | |
| 1523 | } | } |
| 1524 | } else { | } else { |
| 1525 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| # | Line 886 sub _get_next_token ($) { | Line 1530 sub _get_next_token ($) { |
| 1530 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 1531 | ||
| 1532 | redo A; | redo A; |
| 1533 | } elsif (0x0041 <= $self->{next_input_character} and | } elsif (0x0041 <= $self->{next_char} and |
| 1534 | $self->{next_input_character} <= 0x005A) { # A..Z | $self->{next_char} <= 0x005A) { # A..Z |
| 1535 | $self->{current_attribute} = {name => chr ($self->{next_input_character} + 0x0020), | !!!cp (76); |
| 1536 | value => ''}; | $self->{current_attribute} |
| 1537 | = {name => chr ($self->{next_char} + 0x0020), | |
| 1538 | value => '', | |
| 1539 | line => $self->{line}, column => $self->{column}}; | |
| 1540 | $self->{state} = ATTRIBUTE_NAME_STATE; | $self->{state} = ATTRIBUTE_NAME_STATE; |
| 1541 | !!!next-input-character; | !!!next-input-character; |
| 1542 | redo A; | redo A; |
| 1543 | } elsif ($self->{next_input_character} == 0x002F) { # / | } elsif ($self->{next_char} == 0x002F) { # / |
| 1544 | !!!cp (77); | |
| 1545 | $self->{state} = SELF_CLOSING_START_TAG_STATE; | |
| 1546 | !!!next-input-character; | !!!next-input-character; |
| if ($self->{next_input_character} == 0x003E and # > | ||
| $self->{current_token}->{type} == START_TAG_TOKEN and | ||
| $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) { | ||
| # permitted slash | ||
| # | ||
| } else { | ||
| !!!parse-error (type => 'nestc'); | ||
| ## TODO: Different error type for <aa / bb> than <aa/> | ||
| } | ||
| $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; | ||
| # next-input-character is already done | ||
| 1547 | redo A; | redo A; |
| 1548 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1549 | !!!parse-error (type => 'unclosed tag'); | !!!parse-error (type => 'unclosed tag'); |
| 1550 | if ($self->{current_token}->{type} == START_TAG_TOKEN) { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1551 | $self->{current_token}->{first_start_tag} | !!!cp (79); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1552 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1553 | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1554 | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1555 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1556 | !!!cp (80); | |
| 1557 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1558 | } else { | |
| 1559 | ## NOTE: This state should never be reached. | |
| 1560 | !!!cp (81); | |
| 1561 | } | } |
| 1562 | } else { | } else { |
| 1563 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| # | Line 928 sub _get_next_token ($) { | Line 1569 sub _get_next_token ($) { |
| 1569 | ||
| 1570 | redo A; | redo A; |
| 1571 | } else { | } else { |
| 1572 | $self->{current_attribute} = {name => chr ($self->{next_input_character}), | if ($self->{next_char} == 0x0022 or # " |
| 1573 | value => ''}; | $self->{next_char} == 0x0027) { # ' |
| 1574 | !!!cp (78); | |
| 1575 | !!!parse-error (type => 'bad attribute name'); | |
| 1576 | } else { | |
| 1577 | !!!cp (82); | |
| 1578 | } | |
| 1579 | $self->{current_attribute} | |
| 1580 | = {name => chr ($self->{next_char}), | |
| 1581 | value => '', | |
| 1582 | line => $self->{line}, column => $self->{column}}; | |
| 1583 | $self->{state} = ATTRIBUTE_NAME_STATE; | $self->{state} = ATTRIBUTE_NAME_STATE; |
| 1584 | !!!next-input-character; | !!!next-input-character; |
| 1585 | redo A; | redo A; |
| 1586 | } | } |
| 1587 | } elsif ($self->{state} == BEFORE_ATTRIBUTE_VALUE_STATE) { | } elsif ($self->{state} == BEFORE_ATTRIBUTE_VALUE_STATE) { |
| 1588 | if ($self->{next_input_character} == 0x0009 or # HT | if ($self->{next_char} == 0x0009 or # HT |
| 1589 | $self->{next_input_character} == 0x000A or # LF | $self->{next_char} == 0x000A or # LF |
| 1590 | $self->{next_input_character} == 0x000B or # VT | $self->{next_char} == 0x000B or # VT |
| 1591 | $self->{next_input_character} == 0x000C or # FF | $self->{next_char} == 0x000C or # FF |
| 1592 | $self->{next_input_character} == 0x0020) { # SP | $self->{next_char} == 0x0020) { # SP |
| 1593 | !!!cp (83); | |
| 1594 | ## Stay in the state | ## Stay in the state |
| 1595 | !!!next-input-character; | !!!next-input-character; |
| 1596 | redo A; | redo A; |
| 1597 | } elsif ($self->{next_input_character} == 0x0022) { # " | } elsif ($self->{next_char} == 0x0022) { # " |
| 1598 | !!!cp (84); | |
| 1599 | $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE; | $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE; |
| 1600 | !!!next-input-character; | !!!next-input-character; |
| 1601 | redo A; | redo A; |
| 1602 | } elsif ($self->{next_input_character} == 0x0026) { # & | } elsif ($self->{next_char} == 0x0026) { # & |
| 1603 | !!!cp (85); | |
| 1604 | $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE; | $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE; |
| 1605 | ## reconsume | ## reconsume |
| 1606 | redo A; | redo A; |
| 1607 | } elsif ($self->{next_input_character} == 0x0027) { # ' | } elsif ($self->{next_char} == 0x0027) { # ' |
| 1608 | !!!cp (86); | |
| 1609 | $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE; | $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE; |
| 1610 | !!!next-input-character; | !!!next-input-character; |
| 1611 | redo A; | redo A; |
| 1612 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 1613 | !!!parse-error (type => 'empty unquoted attribute value'); | |
| 1614 | if ($self->{current_token}->{type} == START_TAG_TOKEN) { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1615 | $self->{current_token}->{first_start_tag} | !!!cp (87); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1616 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1617 | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1618 | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1619 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1620 | !!!cp (88); | |
| 1621 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1622 | } else { | |
| 1623 | ## NOTE: This state should never be reached. | |
| 1624 | !!!cp (89); | |
| 1625 | } | } |
| 1626 | } else { | } else { |
| 1627 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| # | Line 974 sub _get_next_token ($) { | Line 1632 sub _get_next_token ($) { |
| 1632 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 1633 | ||
| 1634 | redo A; | redo A; |
| 1635 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1636 | !!!parse-error (type => 'unclosed tag'); | !!!parse-error (type => 'unclosed tag'); |
| 1637 | if ($self->{current_token}->{type} == START_TAG_TOKEN) { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1638 | $self->{current_token}->{first_start_tag} | !!!cp (90); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1639 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1640 | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1641 | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1642 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1643 | !!!cp (91); | |
| 1644 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1645 | } else { | |
| 1646 | ## NOTE: This state should never be reached. | |
| 1647 | !!!cp (92); | |
| 1648 | } | } |
| 1649 | } else { | } else { |
| 1650 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| # | Line 995 sub _get_next_token ($) { | Line 1656 sub _get_next_token ($) { |
| 1656 | ||
| 1657 | redo A; | redo A; |
| 1658 | } else { | } else { |
| 1659 | if ($self->{next_input_character} == 0x003D) { # = | if ($self->{next_char} == 0x003D) { # = |
| 1660 | !!!cp (93); | |
| 1661 | !!!parse-error (type => 'bad attribute value'); | !!!parse-error (type => 'bad attribute value'); |
| 1662 | } else { | |
| 1663 | !!!cp (94); | |
| 1664 | } | } |
| 1665 | $self->{current_attribute}->{value} .= chr ($self->{next_input_character}); | $self->{current_attribute}->{value} .= chr ($self->{next_char}); |
| 1666 | $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE; | $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE; |
| 1667 | !!!next-input-character; | !!!next-input-character; |
| 1668 | redo A; | redo A; |
| 1669 | } | } |
| 1670 | } elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) { | } elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) { |
| 1671 | if ($self->{next_input_character} == 0x0022) { # " | if ($self->{next_char} == 0x0022) { # " |
| 1672 | !!!cp (95); | |
| 1673 | $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE; | $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE; |
| 1674 | !!!next-input-character; | !!!next-input-character; |
| 1675 | redo A; | redo A; |
| 1676 | } elsif ($self->{next_input_character} == 0x0026) { # & | } elsif ($self->{next_char} == 0x0026) { # & |
| 1677 | !!!cp (96); | |
| 1678 | $self->{last_attribute_value_state} = $self->{state}; | $self->{last_attribute_value_state} = $self->{state}; |
| 1679 | $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE; | $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE; |
| 1680 | !!!next-input-character; | !!!next-input-character; |
| 1681 | redo A; | redo A; |
| 1682 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1683 | !!!parse-error (type => 'unclosed attribute value'); | !!!parse-error (type => 'unclosed attribute value'); |
| 1684 | if ($self->{current_token}->{type} == START_TAG_TOKEN) { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1685 | $self->{current_token}->{first_start_tag} | !!!cp (97); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1686 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1687 | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1688 | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1689 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1690 | !!!cp (98); | |
| 1691 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1692 | } else { | |
| 1693 | ## NOTE: This state should never be reached. | |
| 1694 | !!!cp (99); | |
| 1695 | } | } |
| 1696 | } else { | } else { |
| 1697 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| # | Line 1034 sub _get_next_token ($) { | Line 1703 sub _get_next_token ($) { |
| 1703 | ||
| 1704 | redo A; | redo A; |
| 1705 | } else { | } else { |
| 1706 | $self->{current_attribute}->{value} .= chr ($self->{next_input_character}); | !!!cp (100); |
| 1707 | $self->{current_attribute}->{value} .= chr ($self->{next_char}); | |
| 1708 | ## Stay in the state | ## Stay in the state |
| 1709 | !!!next-input-character; | !!!next-input-character; |
| 1710 | redo A; | redo A; |
| 1711 | } | } |
| 1712 | } elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) { | } elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) { |
| 1713 | if ($self->{next_input_character} == 0x0027) { # ' | if ($self->{next_char} == 0x0027) { # ' |
| 1714 | !!!cp (101); | |
| 1715 | $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE; | $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE; |
| 1716 | !!!next-input-character; | !!!next-input-character; |
| 1717 | redo A; | redo A; |
| 1718 | } elsif ($self->{next_input_character} == 0x0026) { # & | } elsif ($self->{next_char} == 0x0026) { # & |
| 1719 | !!!cp (102); | |
| 1720 | $self->{last_attribute_value_state} = $self->{state}; | $self->{last_attribute_value_state} = $self->{state}; |
| 1721 | $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE; | $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE; |
| 1722 | !!!next-input-character; | !!!next-input-character; |
| 1723 | redo A; | redo A; |
| 1724 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1725 | !!!parse-error (type => 'unclosed attribute value'); | !!!parse-error (type => 'unclosed attribute value'); |
| 1726 | if ($self->{current_token}->{type} == START_TAG_TOKEN) { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1727 | $self->{current_token}->{first_start_tag} | !!!cp (103); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1728 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1729 | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1730 | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1731 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1732 | !!!cp (104); | |
| 1733 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1734 | } else { | |
| 1735 | ## NOTE: This state should never be reached. | |
| 1736 | !!!cp (105); | |
| 1737 | } | } |
| 1738 | } else { | } else { |
| 1739 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| # | Line 1070 sub _get_next_token ($) { | Line 1745 sub _get_next_token ($) { |
| 1745 | ||
| 1746 | redo A; | redo A; |
| 1747 | } else { | } else { |
| 1748 | $self->{current_attribute}->{value} .= chr ($self->{next_input_character}); | !!!cp (106); |
| 1749 | $self->{current_attribute}->{value} .= chr ($self->{next_char}); | |
| 1750 | ## Stay in the state | ## Stay in the state |
| 1751 | !!!next-input-character; | !!!next-input-character; |
| 1752 | redo A; | redo A; |
| 1753 | } | } |
| 1754 | } elsif ($self->{state} == ATTRIBUTE_VALUE_UNQUOTED_STATE) { | } elsif ($self->{state} == ATTRIBUTE_VALUE_UNQUOTED_STATE) { |
| 1755 | if ($self->{next_input_character} == 0x0009 or # HT | if ($self->{next_char} == 0x0009 or # HT |
| 1756 | $self->{next_input_character} == 0x000A or # LF | $self->{next_char} == 0x000A or # LF |
| 1757 | $self->{next_input_character} == 0x000B or # HT | $self->{next_char} == 0x000B or # HT |
| 1758 | $self->{next_input_character} == 0x000C or # FF | $self->{next_char} == 0x000C or # FF |
| 1759 | $self->{next_input_character} == 0x0020) { # SP | $self->{next_char} == 0x0020) { # SP |
| 1760 | !!!cp (107); | |
| 1761 | $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; | $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
| 1762 | !!!next-input-character; | !!!next-input-character; |
| 1763 | redo A; | redo A; |
| 1764 | } elsif ($self->{next_input_character} == 0x0026) { # & | } elsif ($self->{next_char} == 0x0026) { # & |
| 1765 | !!!cp (108); | |
| 1766 | $self->{last_attribute_value_state} = $self->{state}; | $self->{last_attribute_value_state} = $self->{state}; |
| 1767 | $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE; | $self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE; |
| 1768 | !!!next-input-character; | !!!next-input-character; |
| 1769 | redo A; | redo A; |
| 1770 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 1771 | if ($self->{current_token}->{type} == START_TAG_TOKEN) { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1772 | $self->{current_token}->{first_start_tag} | !!!cp (109); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1773 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1774 | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1775 | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1776 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1777 | !!!cp (110); | |
| 1778 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1779 | } else { | |
| 1780 | ## NOTE: This state should never be reached. | |
| 1781 | !!!cp (111); | |
| 1782 | } | } |
| 1783 | } else { | } else { |
| 1784 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| # | Line 1108 sub _get_next_token ($) { | Line 1789 sub _get_next_token ($) { |
| 1789 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 1790 | ||
| 1791 | redo A; | redo A; |
| 1792 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1793 | !!!parse-error (type => 'unclosed tag'); | !!!parse-error (type => 'unclosed tag'); |
| 1794 | if ($self->{current_token}->{type} == START_TAG_TOKEN) { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1795 | $self->{current_token}->{first_start_tag} | !!!cp (112); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1796 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1797 | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1798 | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1799 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1800 | !!!cp (113); | |
| 1801 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1802 | } else { | |
| 1803 | ## NOTE: This state should never be reached. | |
| 1804 | !!!cp (114); | |
| 1805 | } | } |
| 1806 | } else { | } else { |
| 1807 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| # | Line 1133 sub _get_next_token ($) { | Line 1817 sub _get_next_token ($) { |
| 1817 | 0x0022 => 1, # " | 0x0022 => 1, # " |
| 1818 | 0x0027 => 1, # ' | 0x0027 => 1, # ' |
| 1819 | 0x003D => 1, # = | 0x003D => 1, # = |
| 1820 | }->{$self->{next_input_character}}) { | }->{$self->{next_char}}) { |
| 1821 | !!!cp (115); | |
| 1822 | !!!parse-error (type => 'bad attribute value'); | !!!parse-error (type => 'bad attribute value'); |
| 1823 | } else { | |
| 1824 | !!!cp (116); | |
| 1825 | } | } |
| 1826 | $self->{current_attribute}->{value} .= chr ($self->{next_input_character}); | $self->{current_attribute}->{value} .= chr ($self->{next_char}); |
| 1827 | ## Stay in the state | ## Stay in the state |
| 1828 | !!!next-input-character; | !!!next-input-character; |
| 1829 | redo A; | redo A; |
| # | Line 1151 sub _get_next_token ($) { | Line 1838 sub _get_next_token ($) { |
| 1838 | -1); | -1); |
| 1839 | ||
| 1840 | unless (defined $token) { | unless (defined $token) { |
| 1841 | !!!cp (117); | |
| 1842 | $self->{current_attribute}->{value} .= '&'; | $self->{current_attribute}->{value} .= '&'; |
| 1843 | } else { | } else { |
| 1844 | !!!cp (118); | |
| 1845 | $self->{current_attribute}->{value} .= $token->{data}; | $self->{current_attribute}->{value} .= $token->{data}; |
| 1846 | $self->{current_attribute}->{has_reference} = $token->{has_reference}; | $self->{current_attribute}->{has_reference} = $token->{has_reference}; |
| 1847 | ## ISSUE: spec says "append the returned character token to the current attribute's value" | ## ISSUE: spec says "append the returned character token to the current attribute's value" |
| # | Line 1162 sub _get_next_token ($) { | Line 1851 sub _get_next_token ($) { |
| 1851 | # next-input-character is already done | # next-input-character is already done |
| 1852 | redo A; | redo A; |
| 1853 | } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) { | } elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) { |
| 1854 | if ($self->{next_input_character} == 0x0009 or # HT | if ($self->{next_char} == 0x0009 or # HT |
| 1855 | $self->{next_input_character} == 0x000A or # LF | $self->{next_char} == 0x000A or # LF |
| 1856 | $self->{next_input_character} == 0x000B or # VT | $self->{next_char} == 0x000B or # VT |
| 1857 | $self->{next_input_character} == 0x000C or # FF | $self->{next_char} == 0x000C or # FF |
| 1858 | $self->{next_input_character} == 0x0020) { # SP | $self->{next_char} == 0x0020) { # SP |
| 1859 | !!!cp (118); | |
| 1860 | $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; | $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
| 1861 | !!!next-input-character; | !!!next-input-character; |
| 1862 | redo A; | redo A; |
| 1863 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 1864 | if ($self->{current_token}->{type} == START_TAG_TOKEN) { | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1865 | $self->{current_token}->{first_start_tag} | !!!cp (119); |
| = not defined $self->{last_emitted_start_tag_name}; | ||
| 1866 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1867 | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { |
| 1868 | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST |
| 1869 | if ($self->{current_token}->{attributes}) { | if ($self->{current_token}->{attributes}) { |
| 1870 | !!!cp (120); | |
| 1871 | !!!parse-error (type => 'end tag attribute'); | !!!parse-error (type => 'end tag attribute'); |
| 1872 | } else { | |
| 1873 | ## NOTE: This state should never be reached. | |
| 1874 | !!!cp (121); | |
| 1875 | } | } |
| 1876 | } else { | } else { |
| 1877 | die "$0: $self->{current_token}->{type}: Unknown token type"; | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| # | Line 1189 sub _get_next_token ($) { | Line 1882 sub _get_next_token ($) { |
| 1882 | !!!emit ($self->{current_token}); # start tag or end tag | !!!emit ($self->{current_token}); # start tag or end tag |
| 1883 | ||
| 1884 | redo A; | redo A; |
| 1885 | } elsif ($self->{next_input_character} == 0x002F) { # / | } elsif ($self->{next_char} == 0x002F) { # / |
| 1886 | !!!cp (122); | |
| 1887 | $self->{state} = SELF_CLOSING_START_TAG_STATE; | |
| 1888 | !!!next-input-character; | !!!next-input-character; |
| 1889 | if ($self->{next_input_character} == 0x003E and # > | redo A; |
| 1890 | $self->{current_token}->{type} == START_TAG_TOKEN and | } elsif ($self->{next_char} == -1) { |
| 1891 | $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) { | !!!parse-error (type => 'unclosed tag'); |
| 1892 | # permitted slash | if ($self->{current_token}->{type} == START_TAG_TOKEN) { |
| 1893 | # | !!!cp (122.3); |
| 1894 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | |
| 1895 | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { | |
| 1896 | if ($self->{current_token}->{attributes}) { | |
| 1897 | !!!cp (122.1); | |
| 1898 | !!!parse-error (type => 'end tag attribute'); | |
| 1899 | } else { | |
| 1900 | ## NOTE: This state should never be reached. | |
| 1901 | !!!cp (122.2); | |
| 1902 | } | |
| 1903 | } else { | } else { |
| 1904 | !!!parse-error (type => 'nestc'); | die "$0: $self->{current_token}->{type}: Unknown token type"; |
| 1905 | } | } |
| 1906 | $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; | $self->{state} = DATA_STATE; |
| 1907 | # next-input-character is already done | ## Reconsume. |
| 1908 | !!!emit ($self->{current_token}); # start tag or end tag | |
| 1909 | redo A; | redo A; |
| 1910 | } else { | } else { |
| 1911 | !!!cp ('124.1'); | |
| 1912 | !!!parse-error (type => 'no space between attributes'); | !!!parse-error (type => 'no space between attributes'); |
| 1913 | $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; | $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; |
| 1914 | ## reconsume | ## reconsume |
| 1915 | redo A; | redo A; |
| 1916 | } | } |
| 1917 | } elsif ($self->{state} == SELF_CLOSING_START_TAG_STATE) { | |
| 1918 | if ($self->{next_char} == 0x003E) { # > | |
| 1919 | if ($self->{current_token}->{type} == END_TAG_TOKEN) { | |
| 1920 | !!!cp ('124.2'); | |
| 1921 | !!!parse-error (type => 'nestc', token => $self->{current_token}); | |
| 1922 | ## TODO: Different type than slash in start tag | |
| 1923 | $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST | |
| 1924 | if ($self->{current_token}->{attributes}) { | |
| 1925 | !!!cp ('124.4'); | |
| 1926 | !!!parse-error (type => 'end tag attribute'); | |
| 1927 | } else { | |
| 1928 | !!!cp ('124.5'); | |
| 1929 | } | |
| 1930 | ## TODO: Test |<title></title/>| | |
| 1931 | } else { | |
| 1932 | !!!cp ('124.3'); | |
| 1933 | $self->{self_closing} = 1; | |
| 1934 | } | |
| 1935 | ||
| 1936 | $self->{state} = DATA_STATE; | |
| 1937 | !!!next-input-character; | |
| 1938 | ||
| 1939 | !!!emit ($self->{current_token}); # start tag or end tag | |
| 1940 | ||
| 1941 | redo A; | |
| 1942 | } elsif ($self->{next_char} == -1) { | |
| 1943 | !!!parse-error (type => 'unclosed tag'); | |
| 1944 | if ($self->{current_token}->{type} == START_TAG_TOKEN) { | |
| 1945 | !!!cp (124.7); | |
| 1946 | $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; | |
| 1947 | } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) { | |
| 1948 | if ($self->{current_token}->{attributes}) { | |
| 1949 | !!!cp (124.5); | |
| 1950 | !!!parse-error (type => 'end tag attribute'); | |
| 1951 | } else { | |
| 1952 | ## NOTE: This state should never be reached. | |
| 1953 | !!!cp (124.6); | |
| 1954 | } | |
| 1955 | } else { | |
| 1956 | die "$0: $self->{current_token}->{type}: Unknown token type"; | |
| 1957 | } | |
| 1958 | $self->{state} = DATA_STATE; | |
| 1959 | ## Reconsume. | |
| 1960 | !!!emit ($self->{current_token}); # start tag or end tag | |
| 1961 | redo A; | |
| 1962 | } else { | |
| 1963 | !!!cp ('124.4'); | |
| 1964 | !!!parse-error (type => 'nestc'); | |
| 1965 | ## TODO: This error type is wrong. | |
| 1966 | $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE; | |
| 1967 | ## Reconsume. | |
| 1968 | redo A; | |
| 1969 | } | |
| 1970 | } elsif ($self->{state} == BOGUS_COMMENT_STATE) { | } elsif ($self->{state} == BOGUS_COMMENT_STATE) { |
| 1971 | ## (only happen if PCDATA state) | ## (only happen if PCDATA state) |
| 1972 | ||
| 1973 | my $token = {type => COMMENT_TOKEN, data => ''}; | ## NOTE: Set by the previous state |
| 1974 | #my $token = {type => COMMENT_TOKEN, data => ''}; | |
| 1975 | ||
| 1976 | BC: { | BC: { |
| 1977 | if ($self->{next_input_character} == 0x003E) { # > | if ($self->{next_char} == 0x003E) { # > |
| 1978 | !!!cp (124); | |
| 1979 | $self->{state} = DATA_STATE; | $self->{state} = DATA_STATE; |
| 1980 | !!!next-input-character; | !!!next-input-character; |
| 1981 | ||
| 1982 | !!!emit ($token); | !!!emit ($self->{current_token}); # comment |
| 1983 | ||
| 1984 | redo A; | redo A; |
| 1985 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 1986 | !!!cp (125); | |
| 1987 | $self->{state} = DATA_STATE; | $self->{state} = DATA_STATE; |
| 1988 | ## reconsume | ## reconsume |
| 1989 | ||
| 1990 | !!!emit ($token); | !!!emit ($self->{current_token}); # comment |
| 1991 | ||
| 1992 | redo A; | redo A; |
| 1993 | } else { | } else { |
| 1994 | $token->{data} .= chr ($self->{next_input_character}); | !!!cp (126); |
| 1995 | $self->{current_token}->{data} .= chr ($self->{next_char}); # comment | |
| 1996 | !!!next-input-character; | !!!next-input-character; |
| 1997 | redo BC; | redo BC; |
| 1998 | } | } |
| 1999 | } # BC | } # BC |
| 2000 | ||
| 2001 | die "$0: _get_next_token: unexpected case [BC]"; | |
| 2002 | } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) { | } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) { |
| 2003 | ## (only happen if PCDATA state) | ## (only happen if PCDATA state) |
| 2004 | ||
| 2005 | my ($l, $c) = ($self->{line_prev}, $self->{column_prev} - 1); | |
| 2006 | ||
| 2007 | my @next_char; | my @next_char; |
| 2008 | push @next_char, $self->{next_input_character}; | push @next_char, $self->{next_char}; |
| 2009 | ||
| 2010 | if ($self->{next_input_character} == 0x002D) { # - | if ($self->{next_char} == 0x002D) { # - |
| 2011 | !!!next-input-character; | !!!next-input-character; |
| 2012 | push @next_char, $self->{next_input_character}; | push @next_char, $self->{next_char}; |
| 2013 | if ($self->{next_input_character} == 0x002D) { # - | if ($self->{next_char} == 0x002D) { # - |
| 2014 | $self->{current_token} = {type => COMMENT_TOKEN, data => ''}; | !!!cp (127); |
| 2015 | $self->{current_token} = {type => COMMENT_TOKEN, data => '', | |
| 2016 | line => $l, column => $c, | |
| 2017 | }; | |
| 2018 | $self->{state} = COMMENT_START_STATE; | $self->{state} = COMMENT_START_STATE; |
| 2019 | !!!next-input-character; | !!!next-input-character; |
| 2020 | redo A; | redo A; |
| 2021 | } else { | |
| 2022 | !!!cp (128); | |
| 2023 | } | } |
| 2024 | } elsif ($self->{next_input_character} == 0x0044 or # D | } elsif ($self->{next_char} == 0x0044 or # D |
| 2025 | $self->{next_input_character} == 0x0064) { # d | $self->{next_char} == 0x0064) { # d |
| 2026 | !!!next-input-character; | !!!next-input-character; |
| 2027 | push @next_char, $self->{next_input_character}; | push @next_char, $self->{next_char}; |
| 2028 | if ($self->{next_input_character} == 0x004F or # O | if ($self->{next_char} == 0x004F or # O |
| 2029 | $self->{next_input_character} == 0x006F) { # o | $self->{next_char} == 0x006F) { # o |
| 2030 | !!!next-input-character; | !!!next-input-character; |
| 2031 | push @next_char, $self->{next_input_character}; | push @next_char, $self->{next_char}; |
| 2032 | if ($self->{next_input_character} == 0x0043 or # C | if ($self->{next_char} == 0x0043 or # C |
| 2033 | $self->{next_input_character} == 0x0063) { # c | $self->{next_char} == 0x0063) { # c |
| 2034 | !!!next-input-character; | !!!next-input-character; |
| 2035 | push @next_char, $self->{next_input_character}; | push @next_char, $self->{next_char}; |
| 2036 | if ($self->{next_input_character} == 0x0054 or # T | if ($self->{next_char} == 0x0054 or # T |
| 2037 | $self->{next_input_character} == 0x0074) { # t | $self->{next_char} == 0x0074) { # t |
| 2038 | !!!next-input-character; | !!!next-input-character; |
| 2039 | push @next_char, $self->{next_input_character}; | push @next_char, $self->{next_char}; |
| 2040 | if ($self->{next_input_character} == 0x0059 or # Y | if ($self->{next_char} == 0x0059 or # Y |
| 2041 | $self->{next_input_character} == 0x0079) { # y | $self->{next_char} == 0x0079) { # y |
| 2042 | !!!next-input-character; | !!!next-input-character; |
| 2043 | push @next_char, $self->{next_input_character}; | push @next_char, $self->{next_char}; |
| 2044 | if ($self->{next_input_character} == 0x0050 or # P | if ($self->{next_char} == 0x0050 or # P |
| 2045 | $self->{next_input_character} == 0x0070) { # p | $self->{next_char} == 0x0070) { # p |
| 2046 | !!!next-input-character; | !!!next-input-character; |
| 2047 | push @next_char, $self->{next_input_character}; | push @next_char, $self->{next_char}; |
| 2048 | if ($self->{next_input_character} == 0x0045 or # E | if ($self->{next_char} == 0x0045 or # E |
| 2049 | $self->{next_input_character} == 0x0065) { # e | $self->{next_char} == 0x0065) { # e |
| 2050 | ## ISSUE: What a stupid code this is! | !!!cp (129); |
| 2051 | ## TODO: What a stupid code this is! | |
| 2052 | $self->{state} = DOCTYPE_STATE; | $self->{state} = DOCTYPE_STATE; |
| 2053 | $self->{current_token} = {type => DOCTYPE_TOKEN, | |
| 2054 | quirks => 1, | |
| 2055 | line => $l, column => $c, | |
| 2056 | }; | |
| 2057 | !!!next-input-character; | !!!next-input-character; |
| 2058 | redo A; | redo A; |
| 2059 | } else { | |
| 2060 | !!!cp (130); | |
| 2061 | } | } |
| 2062 | } else { | |
| 2063 | !!!cp (131); | |
| 2064 | } | } |
| 2065 | } else { | |
| 2066 | !!!cp (132); | |
| 2067 | } | } |
| 2068 | } else { | |
| 2069 | !!!cp (133); | |
| 2070 | } | } |
| 2071 | } else { | |
| 2072 | !!!cp (134); | |
| 2073 | } | } |
| 2074 | } else { | |
| 2075 | !!!cp (135); | |
| 2076 | } | } |
| 2077 | } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and | |
| 2078 | $self->{open_elements}->[-1]->[1] & FOREIGN_EL and | |
| 2079 | $self->{next_char} == 0x005B) { # [ | |
| 2080 | !!!next-input-character; | |
| 2081 | push @next_char, $self->{next_char}; | |
| 2082 | if ($self->{next_char} == 0x0043) { # C | |
| 2083 | !!!next-input-character; | |
| 2084 | push @next_char, $self->{next_char}; | |
| 2085 | if ($self->{next_char} == 0x0044) { # D | |
| 2086 | !!!next-input-character; | |
| 2087 | push @next_char, $self->{next_char}; | |
| 2088 | if ($self->{next_char} == 0x0041) { # A | |
| 2089 | !!!next-input-character; | |
| 2090 | push @next_char, $self->{next_char}; | |
| 2091 | if ($self->{next_char} == 0x0054) { # T | |
| 2092 | !!!next-input-character; | |
| 2093 | push @next_char, $self->{next_char}; | |
| 2094 | if ($self->{next_char} == 0x0041) { # A | |
| 2095 | !!!next-input-character; | |
| 2096 | push @next_char, $self->{next_char}; | |
| 2097 | if ($self->{next_char} == 0x005B) { # [ | |
| 2098 | !!!cp (135.1); | |
| 2099 | $self->{state} = CDATA_BLOCK_STATE; | |
| 2100 | !!!next-input-character; | |
| 2101 | redo A; | |
| 2102 | } else { | |
| 2103 | !!!cp (135.2); | |
| 2104 | } | |
| 2105 | } else { | |
| 2106 | !!!cp (135.3); | |
| 2107 | } | |
| 2108 | } else { | |
| 2109 | !!!cp (135.4); | |
| 2110 | } | |
| 2111 | } else { | |
| 2112 | !!!cp (135.5); | |
| 2113 | } | |
| 2114 | } else { | |
| 2115 | !!!cp (135.6); | |
| 2116 | } | |
| 2117 | } else { | |
| 2118 | !!!cp (135.7); | |
| 2119 | } | |
| 2120 | } else { | |
| 2121 | !!!cp (136); | |
| 2122 | } | } |
| 2123 | ||
| 2124 | !!!parse-error (type => 'bogus comment'); | !!!parse-error (type => 'bogus comment'); |
| 2125 | $self->{next_input_character} = shift @next_char; | $self->{next_char} = shift @next_char; |
| 2126 | !!!back-next-input-character (@next_char); | !!!back-next-input-character (@next_char); |
| 2127 | $self->{state} = BOGUS_COMMENT_STATE; | $self->{state} = BOGUS_COMMENT_STATE; |
| 2128 | $self->{current_token} = {type => COMMENT_TOKEN, data => '', | |
| 2129 | line => $l, column => $c, | |
| 2130 | }; | |
| 2131 | redo A; | redo A; |
| 2132 | ||
| 2133 | ## ISSUE: typos in spec: chacacters, is is a parse error | ## ISSUE: typos in spec: chacacters, is is a parse error |
| 2134 | ## ISSUE: spec is somewhat unclear on "is the first character that will be in the comment"; what is "that will be in the comment" is what the algorithm defines, isn't it? | ## ISSUE: spec is somewhat unclear on "is the first character that will be in the comment"; what is "that will be in the comment" is what the algorithm defines, isn't it? |
| 2135 | } elsif ($self->{state} == COMMENT_START_STATE) { | } elsif ($self->{state} == COMMENT_START_STATE) { |
| 2136 | if ($self->{next_input_character} == 0x002D) { # - | if ($self->{next_char} == 0x002D) { # - |
| 2137 | !!!cp (137); | |
| 2138 | $self->{state} = COMMENT_START_DASH_STATE; | $self->{state} = COMMENT_START_DASH_STATE; |
| 2139 | !!!next-input-character; | !!!next-input-character; |
| 2140 | redo A; | redo A; |
| 2141 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 2142 | !!!cp (138); | |
| 2143 | !!!parse-error (type => 'bogus comment'); | !!!parse-error (type => 'bogus comment'); |
| 2144 | $self->{state} = DATA_STATE; | $self->{state} = DATA_STATE; |
| 2145 | !!!next-input-character; | !!!next-input-character; |
| # | Line 1308 sub _get_next_token ($) { | Line 2147 sub _get_next_token ($) { |
| 2147 | !!!emit ($self->{current_token}); # comment | !!!emit ($self->{current_token}); # comment |
| 2148 | ||
| 2149 | redo A; | redo A; |
| 2150 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 2151 | !!!cp (139); | |
| 2152 | !!!parse-error (type => 'unclosed comment'); | !!!parse-error (type => 'unclosed comment'); |
| 2153 | $self->{state} = DATA_STATE; | $self->{state} = DATA_STATE; |
| 2154 | ## reconsume | ## reconsume |
| # | Line 1317 sub _get_next_token ($) { | Line 2157 sub _get_next_token ($) { |
| 2157 | ||
| 2158 | redo A; | redo A; |
| 2159 | } else { | } else { |
| 2160 | !!!cp (140); | |
| 2161 | $self->{current_token}->{data} # comment | $self->{current_token}->{data} # comment |
| 2162 | .= chr ($self->{next_input_character}); | .= chr ($self->{next_char}); |
| 2163 | $self->{state} = COMMENT_STATE; | $self->{state} = COMMENT_STATE; |
| 2164 | !!!next-input-character; | !!!next-input-character; |
| 2165 | redo A; | redo A; |
| 2166 | } | } |
| 2167 | } elsif ($self->{state} == COMMENT_START_DASH_STATE) { | } elsif ($self->{state} == COMMENT_START_DASH_STATE) { |
| 2168 | if ($self->{next_input_character} == 0x002D) { # - | if ($self->{next_char} == 0x002D) { # - |
| 2169 | !!!cp (141); | |
| 2170 | $self->{state} = COMMENT_END_STATE; | $self->{state} = COMMENT_END_STATE; |
| 2171 | !!!next-input-character; | !!!next-input-character; |
| 2172 | redo A; | redo A; |
| 2173 | } elsif ($self->{next_input_character} == 0x003E) { # > | } elsif ($self->{next_char} == 0x003E) { # > |
| 2174 | !!!cp (142); | |
| 2175 | !!!parse-error (type => 'bogus comment'); | !!!parse-error (type => 'bogus comment'); |
| 2176 | $self->{state} = DATA_STATE; | $self->{state} = DATA_STATE; |
| 2177 | !!!next-input-character; | !!!next-input-character; |
| # | Line 1336 sub _get_next_token ($) { | Line 2179 sub _get_next_token ($) { |
| 2179 | !!!emit ($self->{current_token}); # comment | !!!emit ($self->{current_token}); # comment |
| 2180 | ||
| 2181 | redo A; | redo A; |
| 2182 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 2183 | !!!cp (143); | |
| 2184 | !!!parse-error (type => 'unclosed comment'); | !!!parse-error (type => 'unclosed comment'); |
| 2185 | $self->{state} = DATA_STATE; | $self->{state} = DATA_STATE; |
| 2186 | ## reconsume | ## reconsume |
| # | Line 1345 sub _get_next_token ($) { | Line 2189 sub _get_next_token ($) { |
| 2189 | ||
| 2190 | redo A; | redo A; |
| 2191 | } else { | } else { |
| 2192 | !!!cp (144); | |
| 2193 | $self->{current_token}->{data} # comment | $self->{current_token}->{data} # comment |
| 2194 | .= '-' . chr ($self->{next_input_character}); | .= '-' . chr ($self->{next_char}); |
| 2195 | $self->{state} = COMMENT_STATE; | $self->{state} = COMMENT_STATE; |
| 2196 | !!!next-input-character; | !!!next-input-character; |
| 2197 | redo A; | redo A; |
| 2198 | } | } |
| 2199 | } elsif ($self->{state} == COMMENT_STATE) { | } elsif ($self->{state} == COMMENT_STATE) { |
| 2200 | if ($self->{next_input_character} == 0x002D) { # - | if ($self->{next_char} == 0x002D) { # - |
| 2201 | !!!cp (145); | |
| 2202 | $self->{state} = COMMENT_END_DASH_STATE; | $self->{state} = COMMENT_END_DASH_STATE; |
| 2203 | !!!next-input-character; | !!!next-input-character; |
| 2204 | redo A; | redo A; |
| 2205 | } elsif ($self->{next_input_character} == -1) { | } elsif ($self->{next_char} == -1) { |
| 2206 | !!!cp (146); | |
| 2207 | !!!parse-error (type => 'unclosed comment'); | !!!parse-error (type => 'unclosed comment'); |
| 2208 | $self->{state} = DATA_STATE; | $self->{state} = DATA_STATE; |
| 2209 | ## reconsume | ## reconsume |
| # | Line 1365 |