| 1 | =head1 NAME | ||
| 2 | |||
| 3 | XML::Easy::Syntax - excruciatingly correct XML syntax | ||
| 4 | |||
| 5 | =head1 SYNOPSIS | ||
| 6 | |||
| 7 | use XML::Easy::Syntax qw($xml10_name_rx); | ||
| 8 | if($name =~ /\A$xml10_name_rx\z/o) { ... | ||
| 9 | # and many other regular expressions | ||
| 10 | |||
| 11 | =head1 DESCRIPTION | ||
| 12 | |||
| 13 | This module supplies Perl regular expressions describing the grammar of | ||
| 14 | XML 1.0. This is intended to support doing irregular things with XML, | ||
| 15 | rather than for normal parsing. | ||
| 16 | |||
| 17 | These regular expressions encompass the entire XML grammar except for | ||
| 18 | document type declarations and DTDs. | ||
| 19 | This document assumes general familiarity with XML. | ||
| 20 | |||
| 21 | =cut | ||
| 22 | |||
| 23 | package XML::Easy::Syntax; | ||
| 24 | |||
| 25 | 16 | ▶ | { use 5.008; } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 26 | 16 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 27 | 16 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 28 | |||
| 29 | 16 | our $VERSION = "0.010"; | |
| 30 | |||
| 31 | 16 | ▶ | use parent "Exporter"; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 32 | 16 | our @EXPORT_OK = qw( | |
| 33 | $xml10_char_rx $xml10_s_rx $xml10_eq_rx | ||
| 34 | $xml10_namestartchar_rx $xml10_namechar_rx | ||
| 35 | $xml10_name_rx $xml10_names_rx $xml10_nmtoken_rx $xml10_nmtokens_rx | ||
| 36 | $xml10_charref_rx $xml10_entityref_rx $xml10_reference_rx | ||
| 37 | $xml10_chardata_rx | ||
| 38 | $xml10_cdata_rx $xml10_cdstart_rx $xml10_cdend_rx $xml10_cdsect_rx | ||
| 39 | $xml10_attvalue_rx $xml10_attribute_rx | ||
| 40 | $xml10_stag_rx $xml10_etag_rx $xml10_emptyelemtag_rx | ||
| 41 | $xml10_comment_rx $xml10_pitarget_rx $xml10_pi_rx | ||
| 42 | $xml10_content_rx $xml10_element_rx | ||
| 43 | $xml10_versionnum_rx $xml10_versioninfo_rx | ||
| 44 | $xml10_encname_rx $xml10_encodingdecl_rx | ||
| 45 | $xml10_sddecl_rx $xml10_xmldecl_rx $xml10_textdecl_rx | ||
| 46 | $xml10_misc_rx $xml10_miscseq_rx | ||
| 47 | $xml10_prolog_xdtd_rx $xml10_document_xdtd_rx $xml10_extparsedent_rx | ||
| 48 | ); | ||
| 49 | |||
| 50 | sub _charclass_regexp($) { | ||
| 51 | 48 | ▶ | my($class) = @_; |
|
Subroutine
_charclass_regexp: called CC=1 SCAR=0.0
| |||
| 52 | 48 | $class =~ tr/ \t\n//d; | |
| 53 | 48 | return eval("qr/[$class]/"); | |
| 54 | } | ||
| 55 | |||
| 56 | =head1 REGULAR EXPRESSIONS | ||
| 57 | |||
| 58 | Each of these regular expressions corresponds precisely to one of | ||
| 59 | the productions in the EBNF grammar in the XML 1.0 specification. | ||
| 60 | Well-formedness constraints that are not expressed in the EBNF are | ||
| 61 | I<not> checked by the regular expressions; these are noted in the | ||
| 62 | documentation below. The regular expressions do not include any anchors, | ||
| 63 | so to check whether an entire string matches a production you must supply | ||
| 64 | the anchors yourself. | ||
| 65 | |||
| 66 | =head2 Syntax pieces | ||
| 67 | |||
| 68 | =over | ||
| 69 | |||
| 70 | =item $xml10_char_rx | ||
| 71 | |||
| 72 | Any single character that is acceptable to XML 1.0. This includes most | ||
| 73 | Unicode characters (up to codepoint 0x10ffff). The excluded codepoints | ||
| 74 | are the sentinels 0xfffe and 0xffff, the surrogate blocks, and most of | ||
| 75 | the C0 control characters (0x00 to 0x1f, except for 0x09 (tab), 0x0a | ||
| 76 | (linefeed/newline), and 0x0d (carriage return)). | ||
| 77 | |||
| 78 | It is a rule of XML that all characters making up an XML document | ||
| 79 | must be in this permitted set. The grammar productions can only match | ||
| 80 | sequences of acceptable characters. This rule is enforced by the regular | ||
| 81 | expressions in this module. | ||
| 82 | |||
| 83 | Furthermore, it is a rule that the character data in a document cannot | ||
| 84 | even I<represent> a character outside the permitted set. This is | ||
| 85 | expressed as a well-formedness constraint on character references. | ||
| 86 | |||
| 87 | =cut | ||
| 88 | |||
| 89 | 16 | our $xml10_char_rx = _charclass_regexp(q( | |
| 90 | \x{9} | ||
| 91 | \x{a} | ||
| 92 | \x{d} | ||
| 93 | \x{20}-\x{d7ff} | ||
| 94 | \x{e000}-\x{fffd} | ||
| 95 | \x{10000}-\x{10ffff} | ||
| 96 | )); | ||
| 97 | |||
| 98 | =item $xml10_s_rx | ||
| 99 | |||
| 100 | Any sequence of one or more acceptable whitespace characters. The | ||
| 101 | whitespace characters, for this purpose, are tab, linefeed/newline, | ||
| 102 | carriage return, and space. Non-ASCII whitespace characters, and the | ||
| 103 | more exotic ASCII whitespace characters, do not qualify. | ||
| 104 | |||
| 105 | =cut | ||
| 106 | |||
| 107 | 16 | our $xml10_s_rx = qr/[\x{9}\x{a}\x{d}\x{20}]+/; | |
| 108 | |||
| 109 | =item $xml10_eq_rx | ||
| 110 | |||
| 111 | Equals sign, surrounded by optional whitespace. | ||
| 112 | |||
| 113 | =cut | ||
| 114 | |||
| 115 | 16 | our $xml10_eq_rx = qr/$xml10_s_rx?=$xml10_s_rx?/o; | |
| 116 | |||
| 117 | =back | ||
| 118 | |||
| 119 | =head2 Names | ||
| 120 | |||
| 121 | =over | ||
| 122 | |||
| 123 | =item $xml10_namestartchar_rx | ||
| 124 | |||
| 125 | Any single character that is permitted at the start of a name. | ||
| 126 | The permitted characters are "B<_>", "B<:>", and letters (categorised | ||
| 127 | according to Unicode 2.0). | ||
| 128 | |||
| 129 | This production is not named in the XML specification. | ||
| 130 | |||
| 131 | =cut | ||
| 132 | |||
| 133 | 16 | our $xml10_namestartchar_rx = _charclass_regexp(q( | |
| 134 | \x{003a} | ||
| 135 | \x{0041}-\x{005a} | ||
| 136 | \x{005f} | ||
| 137 | \x{0061}-\x{007a} | ||
| 138 | \x{00c0}-\x{00d6} | ||
| 139 | \x{00d8}-\x{00f6} | ||
| 140 | \x{00f8}-\x{0131} | ||
| 141 | \x{0134}-\x{013e} | ||
| 142 | \x{0141}-\x{0148} | ||
| 143 | \x{014a}-\x{017e} | ||
| 144 | \x{0180}-\x{01c3} | ||
| 145 | \x{01cd}-\x{01f0} | ||
| 146 | \x{01f4}-\x{01f5} | ||
| 147 | \x{01fa}-\x{0217} | ||
| 148 | \x{0250}-\x{02a8} | ||
| 149 | \x{02bb}-\x{02c1} | ||
| 150 | \x{0386} | ||
| 151 | \x{0388}-\x{038a} | ||
| 152 | \x{038c} | ||
| 153 | \x{038e}-\x{03a1} | ||
| 154 | \x{03a3}-\x{03ce} | ||
| 155 | \x{03d0}-\x{03d6} | ||
| 156 | \x{03da} | ||
| 157 | \x{03dc} | ||
| 158 | \x{03de} | ||
| 159 | \x{03e0} | ||
| 160 | \x{03e2}-\x{03f3} | ||
| 161 | \x{0401}-\x{040c} | ||
| 162 | \x{040e}-\x{044f} | ||
| 163 | \x{0451}-\x{045c} | ||
| 164 | \x{045e}-\x{0481} | ||
| 165 | \x{0490}-\x{04c4} | ||
| 166 | \x{04c7}-\x{04c8} | ||
| 167 | \x{04cb}-\x{04cc} | ||
| 168 | \x{04d0}-\x{04eb} | ||
| 169 | \x{04ee}-\x{04f5} | ||
| 170 | \x{04f8}-\x{04f9} | ||
| 171 | \x{0531}-\x{0556} | ||
| 172 | \x{0559} | ||
| 173 | \x{0561}-\x{0586} | ||
| 174 | \x{05d0}-\x{05ea} | ||
| 175 | \x{05f0}-\x{05f2} | ||
| 176 | \x{0621}-\x{063a} | ||
| 177 | \x{0641}-\x{064a} | ||
| 178 | \x{0671}-\x{06b7} | ||
| 179 | \x{06ba}-\x{06be} | ||
| 180 | \x{06c0}-\x{06ce} | ||
| 181 | \x{06d0}-\x{06d3} | ||
| 182 | \x{06d5} | ||
| 183 | \x{06e5}-\x{06e6} | ||
| 184 | \x{0905}-\x{0939} | ||
| 185 | \x{093d} | ||
| 186 | \x{0958}-\x{0961} | ||
| 187 | \x{0985}-\x{098c} | ||
| 188 | \x{098f}-\x{0990} | ||
| 189 | \x{0993}-\x{09a8} | ||
| 190 | \x{09aa}-\x{09b0} | ||
| 191 | \x{09b2} | ||
| 192 | \x{09b6}-\x{09b9} | ||
| 193 | \x{09dc}-\x{09dd} | ||
| 194 | \x{09df}-\x{09e1} | ||
| 195 | \x{09f0}-\x{09f1} | ||
| 196 | \x{0a05}-\x{0a0a} | ||
| 197 | \x{0a0f}-\x{0a10} | ||
| 198 | \x{0a13}-\x{0a28} | ||
| 199 | \x{0a2a}-\x{0a30} | ||
| 200 | \x{0a32}-\x{0a33} | ||
| 201 | \x{0a35}-\x{0a36} | ||
| 202 | \x{0a38}-\x{0a39} | ||
| 203 | \x{0a59}-\x{0a5c} | ||
| 204 | \x{0a5e} | ||
| 205 | \x{0a72}-\x{0a74} | ||
| 206 | \x{0a85}-\x{0a8b} | ||
| 207 | \x{0a8d} | ||
| 208 | \x{0a8f}-\x{0a91} | ||
| 209 | \x{0a93}-\x{0aa8} | ||
| 210 | \x{0aaa}-\x{0ab0} | ||
| 211 | \x{0ab2}-\x{0ab3} | ||
| 212 | \x{0ab5}-\x{0ab9} | ||
| 213 | \x{0abd} | ||
| 214 | \x{0ae0} | ||
| 215 | \x{0b05}-\x{0b0c} | ||
| 216 | \x{0b0f}-\x{0b10} | ||
| 217 | \x{0b13}-\x{0b28} | ||
| 218 | \x{0b2a}-\x{0b30} | ||
| 219 | \x{0b32}-\x{0b33} | ||
| 220 | \x{0b36}-\x{0b39} | ||
| 221 | \x{0b3d} | ||
| 222 | \x{0b5c}-\x{0b5d} | ||
| 223 | \x{0b5f}-\x{0b61} | ||
| 224 | \x{0b85}-\x{0b8a} | ||
| 225 | \x{0b8e}-\x{0b90} | ||
| 226 | \x{0b92}-\x{0b95} | ||
| 227 | \x{0b99}-\x{0b9a} | ||
| 228 | \x{0b9c} | ||
| 229 | \x{0b9e}-\x{0b9f} | ||
| 230 | \x{0ba3}-\x{0ba4} | ||
| 231 | \x{0ba8}-\x{0baa} | ||
| 232 | \x{0bae}-\x{0bb5} | ||
| 233 | \x{0bb7}-\x{0bb9} | ||
| 234 | \x{0c05}-\x{0c0c} | ||
| 235 | \x{0c0e}-\x{0c10} | ||
| 236 | \x{0c12}-\x{0c28} | ||
| 237 | \x{0c2a}-\x{0c33} | ||
| 238 | \x{0c35}-\x{0c39} | ||
| 239 | \x{0c60}-\x{0c61} | ||
| 240 | \x{0c85}-\x{0c8c} | ||
| 241 | \x{0c8e}-\x{0c90} | ||
| 242 | \x{0c92}-\x{0ca8} | ||
| 243 | \x{0caa}-\x{0cb3} | ||
| 244 | \x{0cb5}-\x{0cb9} | ||
| 245 | \x{0cde} | ||
| 246 | \x{0ce0}-\x{0ce1} | ||
| 247 | \x{0d05}-\x{0d0c} | ||
| 248 | \x{0d0e}-\x{0d10} | ||
| 249 | \x{0d12}-\x{0d28} | ||
| 250 | \x{0d2a}-\x{0d39} | ||
| 251 | \x{0d60}-\x{0d61} | ||
| 252 | \x{0e01}-\x{0e2e} | ||
| 253 | \x{0e30} | ||
| 254 | \x{0e32}-\x{0e33} | ||
| 255 | \x{0e40}-\x{0e45} | ||
| 256 | \x{0e81}-\x{0e82} | ||
| 257 | \x{0e84} | ||
| 258 | \x{0e87}-\x{0e88} | ||
| 259 | \x{0e8a} | ||
| 260 | \x{0e8d} | ||
| 261 | \x{0e94}-\x{0e97} | ||
| 262 | \x{0e99}-\x{0e9f} | ||
| 263 | \x{0ea1}-\x{0ea3} | ||
| 264 | \x{0ea5} | ||
| 265 | \x{0ea7} | ||
| 266 | \x{0eaa}-\x{0eab} | ||
| 267 | \x{0ead}-\x{0eae} | ||
| 268 | \x{0eb0} | ||
| 269 | \x{0eb2}-\x{0eb3} | ||
| 270 | \x{0ebd} | ||
| 271 | \x{0ec0}-\x{0ec4} | ||
| 272 | \x{0f40}-\x{0f47} | ||
| 273 | \x{0f49}-\x{0f69} | ||
| 274 | \x{10a0}-\x{10c5} | ||
| 275 | \x{10d0}-\x{10f6} | ||
| 276 | \x{1100} | ||
| 277 | \x{1102}-\x{1103} | ||
| 278 | \x{1105}-\x{1107} | ||
| 279 | \x{1109} | ||
| 280 | \x{110b}-\x{110c} | ||
| 281 | \x{110e}-\x{1112} | ||
| 282 | \x{113c} | ||
| 283 | \x{113e} | ||
| 284 | \x{1140} | ||
| 285 | \x{114c} | ||
| 286 | \x{114e} | ||
| 287 | \x{1150} | ||
| 288 | \x{1154}-\x{1155} | ||
| 289 | \x{1159} | ||
| 290 | \x{115f}-\x{1161} | ||
| 291 | \x{1163} | ||
| 292 | \x{1165} | ||
| 293 | \x{1167} | ||
| 294 | \x{1169} | ||
| 295 | \x{116d}-\x{116e} | ||
| 296 | \x{1172}-\x{1173} | ||
| 297 | \x{1175} | ||
| 298 | \x{119e} | ||
| 299 | \x{11a8} | ||
| 300 | \x{11ab} | ||
| 301 | \x{11ae}-\x{11af} | ||
| 302 | \x{11b7}-\x{11b8} | ||
| 303 | \x{11ba} | ||
| 304 | \x{11bc}-\x{11c2} | ||
| 305 | \x{11eb} | ||
| 306 | \x{11f0} | ||
| 307 | \x{11f9} | ||
| 308 | \x{1e00}-\x{1e9b} | ||
| 309 | \x{1ea0}-\x{1ef9} | ||
| 310 | \x{1f00}-\x{1f15} | ||
| 311 | \x{1f18}-\x{1f1d} | ||
| 312 | \x{1f20}-\x{1f45} | ||
| 313 | \x{1f48}-\x{1f4d} | ||
| 314 | \x{1f50}-\x{1f57} | ||
| 315 | \x{1f59} | ||
| 316 | \x{1f5b} | ||
| 317 | \x{1f5d} | ||
| 318 | \x{1f5f}-\x{1f7d} | ||
| 319 | \x{1f80}-\x{1fb4} | ||
| 320 | \x{1fb6}-\x{1fbc} | ||
| 321 | \x{1fbe} | ||
| 322 | \x{1fc2}-\x{1fc4} | ||
| 323 | \x{1fc6}-\x{1fcc} | ||
| 324 | \x{1fd0}-\x{1fd3} | ||
| 325 | \x{1fd6}-\x{1fdb} | ||
| 326 | \x{1fe0}-\x{1fec} | ||
| 327 | \x{1ff2}-\x{1ff4} | ||
| 328 | \x{1ff6}-\x{1ffc} | ||
| 329 | \x{2126} | ||
| 330 | \x{212a}-\x{212b} | ||
| 331 | \x{212e} | ||
| 332 | \x{2180}-\x{2182} | ||
| 333 | \x{3007} | ||
| 334 | \x{3021}-\x{3029} | ||
| 335 | \x{3041}-\x{3094} | ||
| 336 | \x{30a1}-\x{30fa} | ||
| 337 | \x{3105}-\x{312c} | ||
| 338 | \x{4e00}-\x{9fa5} | ||
| 339 | \x{ac00}-\x{d7a3} | ||
| 340 | )); | ||
| 341 | |||
| 342 | =item $xml10_namechar_rx | ||
| 343 | |||
| 344 | Any single character that is permitted in a name other than at the start. | ||
| 345 | The permitted characters are "B<.>", "B<->", "B<_>", "B<:>", and letters, | ||
| 346 | digits, combining characters, and extenders (categorised according to | ||
| 347 | Unicode 2.0). | ||
| 348 | |||
| 349 | =cut | ||
| 350 | |||
| 351 | 16 | our $xml10_namechar_rx = _charclass_regexp(q( | |
| 352 | \x{002d}-\x{002e} | ||
| 353 | \x{0030}-\x{003a} | ||
| 354 | \x{0041}-\x{005a} | ||
| 355 | \x{005f} | ||
| 356 | \x{0061}-\x{007a} | ||
| 357 | \x{00b7} | ||
| 358 | \x{00c0}-\x{00d6} | ||
| 359 | \x{00d8}-\x{00f6} | ||
| 360 | \x{00f8}-\x{0131} | ||
| 361 | \x{0134}-\x{013e} | ||
| 362 | \x{0141}-\x{0148} | ||
| 363 | \x{014a}-\x{017e} | ||
| 364 | \x{0180}-\x{01c3} | ||
| 365 | \x{01cd}-\x{01f0} | ||
| 366 | \x{01f4}-\x{01f5} | ||
| 367 | \x{01fa}-\x{0217} | ||
| 368 | \x{0250}-\x{02a8} | ||
| 369 | \x{02bb}-\x{02c1} | ||
| 370 | \x{02d0}-\x{02d1} | ||
| 371 | \x{0300}-\x{0345} | ||
| 372 | \x{0360}-\x{0361} | ||
| 373 | \x{0387}-\x{038a} | ||
| 374 | \x{038c} | ||
| 375 | \x{038e}-\x{03a1} | ||
| 376 | \x{03a3}-\x{03ce} | ||
| 377 | \x{03d0}-\x{03d6} | ||
| 378 | \x{03da} | ||
| 379 | \x{03dc} | ||
| 380 | \x{03de} | ||
| 381 | \x{03e0} | ||
| 382 | \x{03e2}-\x{03f3} | ||
| 383 | \x{0401}-\x{040c} | ||
| 384 | \x{040e}-\x{044f} | ||
| 385 | \x{0451}-\x{045c} | ||
| 386 | \x{045e}-\x{0481} | ||
| 387 | \x{0483}-\x{0486} | ||
| 388 | \x{0490}-\x{04c4} | ||
| 389 | \x{04c7}-\x{04c8} | ||
| 390 | \x{04cb}-\x{04cc} | ||
| 391 | \x{04d0}-\x{04eb} | ||
| 392 | \x{04ee}-\x{04f5} | ||
| 393 | \x{04f8}-\x{04f9} | ||
| 394 | \x{0531}-\x{0556} | ||
| 395 | \x{0559} | ||
| 396 | \x{0561}-\x{0586} | ||
| 397 | \x{0591}-\x{05a1} | ||
| 398 | \x{05a3}-\x{05b9} | ||
| 399 | \x{05bb}-\x{05bd} | ||
| 400 | \x{05bf} | ||
| 401 | \x{05c1}-\x{05c2} | ||
| 402 | \x{05c4} | ||
| 403 | \x{05d0}-\x{05ea} | ||
| 404 | \x{05f0}-\x{05f2} | ||
| 405 | \x{0621}-\x{063a} | ||
| 406 | \x{0641}-\x{0652} | ||
| 407 | \x{0660}-\x{0669} | ||
| 408 | \x{0670}-\x{06b7} | ||
| 409 | \x{06ba}-\x{06be} | ||
| 410 | \x{06c0}-\x{06ce} | ||
| 411 | \x{06d0}-\x{06d3} | ||
| 412 | \x{06e5}-\x{06e8} | ||
| 413 | \x{06ea}-\x{06ed} | ||
| 414 | \x{06f0}-\x{06f9} | ||
| 415 | \x{0901}-\x{0903} | ||
| 416 | \x{0905}-\x{0939} | ||
| 417 | \x{093e}-\x{094d} | ||
| 418 | \x{0951}-\x{0954} | ||
| 419 | \x{0958}-\x{0963} | ||
| 420 | \x{0966}-\x{096f} | ||
| 421 | \x{0981}-\x{0983} | ||
| 422 | \x{0985}-\x{098c} | ||
| 423 | \x{098f}-\x{0990} | ||
| 424 | \x{0993}-\x{09a8} | ||
| 425 | \x{09aa}-\x{09b0} | ||
| 426 | \x{09b2} | ||
| 427 | \x{09b6}-\x{09b9} | ||
| 428 | \x{09bc} | ||
| 429 | \x{09bf}-\x{09c4} | ||
| 430 | \x{09c7}-\x{09c8} | ||
| 431 | \x{09cb}-\x{09cd} | ||
| 432 | \x{09d7} | ||
| 433 | \x{09dc}-\x{09dd} | ||
| 434 | \x{09df}-\x{09e3} | ||
| 435 | \x{09e6}-\x{09f1} | ||
| 436 | \x{0a02} | ||
| 437 | \x{0a05}-\x{0a0a} | ||
| 438 | \x{0a0f}-\x{0a10} | ||
| 439 | \x{0a13}-\x{0a28} | ||
| 440 | \x{0a2a}-\x{0a30} | ||
| 441 | \x{0a32}-\x{0a33} | ||
| 442 | \x{0a35}-\x{0a36} | ||
| 443 | \x{0a38}-\x{0a39} | ||
| 444 | \x{0a3c} | ||
| 445 | \x{0a3f}-\x{0a42} | ||
| 446 | \x{0a47}-\x{0a48} | ||
| 447 | \x{0a4b}-\x{0a4d} | ||
| 448 | \x{0a59}-\x{0a5c} | ||
| 449 | \x{0a5e} | ||
| 450 | \x{0a70}-\x{0a74} | ||
| 451 | \x{0a81}-\x{0a83} | ||
| 452 | \x{0a85}-\x{0a8b} | ||
| 453 | \x{0a8d} | ||
| 454 | \x{0a8f}-\x{0a91} | ||
| 455 | \x{0a93}-\x{0aa8} | ||
| 456 | \x{0aaa}-\x{0ab0} | ||
| 457 | \x{0ab2}-\x{0ab3} | ||
| 458 | \x{0ab5}-\x{0ab9} | ||
| 459 | \x{0abd}-\x{0ac5} | ||
| 460 | \x{0ac7}-\x{0ac9} | ||
| 461 | \x{0acb}-\x{0acd} | ||
| 462 | \x{0ae0} | ||
| 463 | \x{0ae6}-\x{0aef} | ||
| 464 | \x{0b01}-\x{0b03} | ||
| 465 | \x{0b05}-\x{0b0c} | ||
| 466 | \x{0b0f}-\x{0b10} | ||
| 467 | \x{0b13}-\x{0b28} | ||
| 468 | \x{0b2a}-\x{0b30} | ||
| 469 | \x{0b32}-\x{0b33} | ||
| 470 | \x{0b36}-\x{0b39} | ||
| 471 | \x{0b3d}-\x{0b43} | ||
| 472 | \x{0b47}-\x{0b48} | ||
| 473 | \x{0b4b}-\x{0b4d} | ||
| 474 | \x{0b56}-\x{0b57} | ||
| 475 | \x{0b5c}-\x{0b5d} | ||
| 476 | \x{0b5f}-\x{0b61} | ||
| 477 | \x{0b66}-\x{0b6f} | ||
| 478 | \x{0b82}-\x{0b83} | ||
| 479 | \x{0b85}-\x{0b8a} | ||
| 480 | \x{0b8e}-\x{0b90} | ||
| 481 | \x{0b92}-\x{0b95} | ||
| 482 | \x{0b99}-\x{0b9a} | ||
| 483 | \x{0b9c} | ||
| 484 | \x{0b9e}-\x{0b9f} | ||
| 485 | \x{0ba3}-\x{0ba4} | ||
| 486 | \x{0ba8}-\x{0baa} | ||
| 487 | \x{0bae}-\x{0bb5} | ||
| 488 | \x{0bb7}-\x{0bb9} | ||
| 489 | \x{0bbe}-\x{0bc2} | ||
| 490 | \x{0bc6}-\x{0bc8} | ||
| 491 | \x{0bca}-\x{0bcd} | ||
| 492 | \x{0bd7} | ||
| 493 | \x{0be7}-\x{0bef} | ||
| 494 | \x{0c01}-\x{0c03} | ||
| 495 | \x{0c05}-\x{0c0c} | ||
| 496 | \x{0c0e}-\x{0c10} | ||
| 497 | \x{0c12}-\x{0c28} | ||
| 498 | \x{0c2a}-\x{0c33} | ||
| 499 | \x{0c35}-\x{0c39} | ||
| 500 | \x{0c3e}-\x{0c44} | ||
| 501 | \x{0c46}-\x{0c48} | ||
| 502 | \x{0c4a}-\x{0c4d} | ||
| 503 | \x{0c55}-\x{0c56} | ||
| 504 | \x{0c60}-\x{0c61} | ||
| 505 | \x{0c66}-\x{0c6f} | ||
| 506 | \x{0c82}-\x{0c83} | ||
| 507 | \x{0c85}-\x{0c8c} | ||
| 508 | \x{0c8e}-\x{0c90} | ||
| 509 | \x{0c92}-\x{0ca8} | ||
| 510 | \x{0caa}-\x{0cb3} | ||
| 511 | \x{0cb5}-\x{0cb9} | ||
| 512 | \x{0cbe}-\x{0cc4} | ||
| 513 | \x{0cc6}-\x{0cc8} | ||
| 514 | \x{0cca}-\x{0ccd} | ||
| 515 | \x{0cd5}-\x{0cd6} | ||
| 516 | \x{0cde} | ||
| 517 | \x{0ce0}-\x{0ce1} | ||
| 518 | \x{0ce6}-\x{0cef} | ||
| 519 | \x{0d02}-\x{0d03} | ||
| 520 | \x{0d05}-\x{0d0c} | ||
| 521 | \x{0d0e}-\x{0d10} | ||
| 522 | \x{0d12}-\x{0d28} | ||
| 523 | \x{0d2a}-\x{0d39} | ||
| 524 | \x{0d3e}-\x{0d43} | ||
| 525 | \x{0d46}-\x{0d48} | ||
| 526 | \x{0d4a}-\x{0d4d} | ||
| 527 | \x{0d57} | ||
| 528 | \x{0d60}-\x{0d61} | ||
| 529 | \x{0d66}-\x{0d6f} | ||
| 530 | \x{0e01}-\x{0e2e} | ||
| 531 | \x{0e32}-\x{0e3a} | ||
| 532 | \x{0e46}-\x{0e4e} | ||
| 533 | \x{0e50}-\x{0e59} | ||
| 534 | \x{0e81}-\x{0e82} | ||
| 535 | \x{0e84} | ||
| 536 | \x{0e87}-\x{0e88} | ||
| 537 | \x{0e8a} | ||
| 538 | \x{0e8d} | ||
| 539 | \x{0e94}-\x{0e97} | ||
| 540 | \x{0e99}-\x{0e9f} | ||
| 541 | \x{0ea1}-\x{0ea3} | ||
| 542 | \x{0ea5} | ||
| 543 | \x{0ea7} | ||
| 544 | \x{0eaa}-\x{0eab} | ||
| 545 | \x{0ead}-\x{0eae} | ||
| 546 | \x{0eb2}-\x{0eb9} | ||
| 547 | \x{0ebb}-\x{0ebd} | ||
| 548 | \x{0ec0}-\x{0ec4} | ||
| 549 | \x{0ec6} | ||
| 550 | \x{0ec8}-\x{0ecd} | ||
| 551 | \x{0ed0}-\x{0ed9} | ||
| 552 | \x{0f18}-\x{0f19} | ||
| 553 | \x{0f20}-\x{0f29} | ||
| 554 | \x{0f35} | ||
| 555 | \x{0f37} | ||
| 556 | \x{0f39} | ||
| 557 | \x{0f3f}-\x{0f47} | ||
| 558 | \x{0f49}-\x{0f69} | ||
| 559 | \x{0f71}-\x{0f84} | ||
| 560 | \x{0f86}-\x{0f8b} | ||
| 561 | \x{0f90}-\x{0f95} | ||
| 562 | \x{0f97} | ||
| 563 | \x{0f99}-\x{0fad} | ||
| 564 | \x{0fb1}-\x{0fb7} | ||
| 565 | \x{0fb9} | ||
| 566 | \x{10a0}-\x{10c5} | ||
| 567 | \x{10d0}-\x{10f6} | ||
| 568 | \x{1100} | ||
| 569 | \x{1102}-\x{1103} | ||
| 570 | \x{1105}-\x{1107} | ||
| 571 | \x{1109} | ||
| 572 | \x{110b}-\x{110c} | ||
| 573 | \x{110e}-\x{1112} | ||
| 574 | \x{113c} | ||
| 575 | \x{113e} | ||
| 576 | \x{1140} | ||
| 577 | \x{114c} | ||
| 578 | \x{114e} | ||
| 579 | \x{1150} | ||
| 580 | \x{1154}-\x{1155} | ||
| 581 | \x{1159} | ||
| 582 | \x{115f}-\x{1161} | ||
| 583 | \x{1163} | ||
| 584 | \x{1165} | ||
| 585 | \x{1167} | ||
| 586 | \x{1169} | ||
| 587 | \x{116d}-\x{116e} | ||
| 588 | \x{1172}-\x{1173} | ||
| 589 | \x{1175} | ||
| 590 | \x{119e} | ||
| 591 | \x{11a8} | ||
| 592 | \x{11ab} | ||
| 593 | \x{11ae}-\x{11af} | ||
| 594 | \x{11b7}-\x{11b8} | ||
| 595 | \x{11ba} | ||
| 596 | \x{11bc}-\x{11c2} | ||
| 597 | \x{11eb} | ||
| 598 | \x{11f0} | ||
| 599 | \x{11f9} | ||
| 600 | \x{1e00}-\x{1e9b} | ||
| 601 | \x{1ea0}-\x{1ef9} | ||
| 602 | \x{1f00}-\x{1f15} | ||
| 603 | \x{1f18}-\x{1f1d} | ||
| 604 | \x{1f20}-\x{1f45} | ||
| 605 | \x{1f48}-\x{1f4d} | ||
| 606 | \x{1f50}-\x{1f57} | ||
| 607 | \x{1f59} | ||
| 608 | \x{1f5b} | ||
| 609 | \x{1f5d} | ||
| 610 | \x{1f5f}-\x{1f7d} | ||
| 611 | \x{1f80}-\x{1fb4} | ||
| 612 | \x{1fb6}-\x{1fbc} | ||
| 613 | \x{1fbe} | ||
| 614 | \x{1fc2}-\x{1fc4} | ||
| 615 | \x{1fc6}-\x{1fcc} | ||
| 616 | \x{1fd0}-\x{1fd3} | ||
| 617 | \x{1fd6}-\x{1fdb} | ||
| 618 | \x{1fe0}-\x{1fec} | ||
| 619 | \x{1ff2}-\x{1ff4} | ||
| 620 | \x{1ff6}-\x{1ffc} | ||
| 621 | \x{20d0}-\x{20dc} | ||
| 622 | \x{20e1} | ||
| 623 | \x{2126} | ||
| 624 | \x{212a}-\x{212b} | ||
| 625 | \x{212e} | ||
| 626 | \x{2180}-\x{2182} | ||
| 627 | \x{3005} | ||
| 628 | \x{3007} | ||
| 629 | \x{3021}-\x{302f} | ||
| 630 | \x{3031}-\x{3035} | ||
| 631 | \x{3041}-\x{3094} | ||
| 632 | \x{3099}-\x{309a} | ||
| 633 | \x{309d}-\x{309e} | ||
| 634 | \x{30a1}-\x{30fa} | ||
| 635 | \x{30fc}-\x{30fe} | ||
| 636 | \x{3105}-\x{312c} | ||
| 637 | \x{4e00}-\x{9fa5} | ||
| 638 | \x{ac00}-\x{d7a3} | ||
| 639 | )); | ||
| 640 | |||
| 641 | =item $xml10_name_rx | ||
| 642 | |||
| 643 | A name, of the type used to identify element types, attributes, entities, | ||
| 644 | and other things in XML. | ||
| 645 | |||
| 646 | =cut | ||
| 647 | |||
| 648 | 16 | our $xml10_name_rx = qr/$xml10_namestartchar_rx$xml10_namechar_rx*/o; | |
| 649 | |||
| 650 | =item $xml10_names_rx | ||
| 651 | |||
| 652 | A space-separated list of one or more names. | ||
| 653 | |||
| 654 | =cut | ||
| 655 | |||
| 656 | 16 | our $xml10_names_rx = qr/$xml10_name_rx(?:\x{20}$xml10_name_rx)*/o; | |
| 657 | |||
| 658 | =item $xml10_nmtoken_rx | ||
| 659 | |||
| 660 | A name-like token, much like a name except that the first character is | ||
| 661 | no more restricted than the remaining characters. These tokens play no | ||
| 662 | part in basic XML syntax, and in the specification are only used as part | ||
| 663 | of attribute typing. | ||
| 664 | |||
| 665 | =cut | ||
| 666 | |||
| 667 | 16 | our $xml10_nmtoken_rx = qr/$xml10_namechar_rx+/o; | |
| 668 | |||
| 669 | =item $xml10_nmtokens_rx | ||
| 670 | |||
| 671 | A space-separated list of one or more name-like tokens. | ||
| 672 | |||
| 673 | =cut | ||
| 674 | |||
| 675 | 16 | our $xml10_nmtokens_rx = qr/$xml10_nmtoken_rx(?:\x{20}$xml10_nmtoken_rx)*/o; | |
| 676 | |||
| 677 | =back | ||
| 678 | |||
| 679 | =head2 References | ||
| 680 | |||
| 681 | =over | ||
| 682 | |||
| 683 | =item $xml10_charref_rx | ||
| 684 | |||
| 685 | A numeric character reference (beginning with "B<&#>" and ending with | ||
| 686 | "B<;>"). There is a non-syntactic well-formedness constraint: the | ||
| 687 | codepoint is required to be within the Unicode range and to refer to an | ||
| 688 | acceptable character (as discussed at C<$xml10_char_rx>). | ||
| 689 | |||
| 690 | =cut | ||
| 691 | |||
| 692 | 16 | our $xml10_charref_rx = qr/&#(?:[0-9]+|x[0-9a-fA-F]+);/; | |
| 693 | |||
| 694 | =item $xml10_entityref_rx | ||
| 695 | |||
| 696 | A general entity reference (beginning with "B<&>" and ending with "B<;>"). | ||
| 697 | There are non-syntactic well-formedness constraints: the referenced entity | ||
| 698 | must be declared (possibly implicitly), must not be an unparsed entity, | ||
| 699 | must not contain a recursive reference to itself, and its replacement | ||
| 700 | text must itself be well-formed. | ||
| 701 | |||
| 702 | =cut | ||
| 703 | |||
| 704 | 16 | our $xml10_entityref_rx = qr/&$xml10_name_rx;/o; | |
| 705 | |||
| 706 | =item $xml10_reference_rx | ||
| 707 | |||
| 708 | Either a character reference or an entity reference. The well-formedness | ||
| 709 | constraints of both reference types (see above) apply. | ||
| 710 | |||
| 711 | =cut | ||
| 712 | |||
| 713 | 16 | our $xml10_reference_rx = qr/$xml10_entityref_rx|$xml10_charref_rx/o; | |
| 714 | |||
| 715 | =back | ||
| 716 | |||
| 717 | =head2 Character data | ||
| 718 | |||
| 719 | =over | ||
| 720 | |||
| 721 | =item $xml10_chardata_rx | ||
| 722 | |||
| 723 | Ordinary literal character data. This consists of zero or more acceptable | ||
| 724 | characters, other than the metacharacters "B<< < >>" and "B<&>", and | ||
| 725 | not including "B<< ]]> >>" as a subsequence. Such data stands for | ||
| 726 | itself when it appears between the start and end tags of an element, | ||
| 727 | where it can be interspersed with references, CDATA sections, comments, | ||
| 728 | and processing instructions. | ||
| 729 | |||
| 730 | In the XML grammar, character data is parsed, and taken literally, | ||
| 731 | I<after> line endings have been canonicalised (to the newline character). | ||
| 732 | Pre-canonicalisation character data, with variable line endings, will | ||
| 733 | still match this production but should not be interpreted literally. | ||
| 734 | |||
| 735 | Beware that a string that does not match this production might parse as | ||
| 736 | two adjacent strings each of which matches. This can happen because | ||
| 737 | of the prohibition on "B<< ]]> >>" being embedded in character data, | ||
| 738 | while the characters of that sequence are acceptable individually. | ||
| 739 | The XML grammar does not allow two instances of this production to abut. | ||
| 740 | |||
| 741 | =cut | ||
| 742 | |||
| 743 | 16 | our $xml10_chardata_rx = qr/(?: | |
| 744 | \]?(?![<&\]])$xml10_char_rx | ||
| 745 | |\]{2,}(?![<&\>\]])$xml10_char_rx | ||
| 746 | )*\]*/xo; | ||
| 747 | |||
| 748 | =item $xml10_cdata_rx | ||
| 749 | |||
| 750 | Literal character data in a CDATA section. This consists of zero or | ||
| 751 | more acceptable characters, not including "B<< ]]> >>" as a subsequence. | ||
| 752 | Unlike ordinary literal character data, the characters "B<< < >>" and | ||
| 753 | "B<&>" are not metacharacters here. Such data stands for itself when | ||
| 754 | it appears within a CDATA section. | ||
| 755 | |||
| 756 | As with ordinary literal character data (see above), this data is meant | ||
| 757 | to be taken literally only after line endings have been canonicalised. | ||
| 758 | Also, as with ordinary literal character data, two instances of this | ||
| 759 | production should not abut. | ||
| 760 | |||
| 761 | =cut | ||
| 762 | |||
| 763 | 16 | our $xml10_cdata_rx = qr/(?: | |
| 764 | \]?(?!\])$xml10_char_rx | ||
| 765 | |\]{2,}(?![\>\]])$xml10_char_rx | ||
| 766 | )*\]*/xo; | ||
| 767 | |||
| 768 | =item $xml10_cdstart_rx | ||
| 769 | |||
| 770 | =item $xml10_cdend_rx | ||
| 771 | |||
| 772 | The fixed strings "B<< <![CDATA[ >>" and "B<< ]]> >>" which begin and | ||
| 773 | finish a CDATA section. | ||
| 774 | |||
| 775 | =cut | ||
| 776 | |||
| 777 | 16 | our $xml10_cdstart_rx = qr/<!\[CDATA\[/; | |
| 778 | 16 | our $xml10_cdend_rx = qr/\]\]>/; | |
| 779 | |||
| 780 | =item $xml10_cdsect_rx | ||
| 781 | |||
| 782 | A CDATA section. This consists of "B<< <![CDATA[ >>", literal character | ||
| 783 | data with metacharacters disabled, and "B<< ]]> >>". | ||
| 784 | |||
| 785 | =cut | ||
| 786 | |||
| 787 | # Note: using the $xml10_cdata_rx regexp (from above) here would be much | ||
| 788 | # less efficient than this use of (?>...). It would also run into the | ||
| 789 | # perl bug described in L</BUGS>. | ||
| 790 | |||
| 791 | 16 | our $xml10_cdsect_rx = qr/(?><!\[CDATA\[$xml10_char_rx*?\]\]>)/o; | |
| 792 | |||
| 793 | =back | ||
| 794 | |||
| 795 | =head2 Tags | ||
| 796 | |||
| 797 | =over | ||
| 798 | |||
| 799 | =item $xml10_attvalue_rx | ||
| 800 | |||
| 801 | A quoted attribute value. This consists of acceptable characters | ||
| 802 | other than "B<< < >>", "B<&>", and the quote character, interspersed | ||
| 803 | with references, surrounded by matching "B<">" or "B<'>" quotes. | ||
| 804 | The well-formedness constraints of references apply, and additionally | ||
| 805 | the replacement text of any referenced entities must not contain any "B<< | ||
| 806 | < >>" characters, and it is not permitted to refer to external entities. | ||
| 807 | |||
| 808 | =cut | ||
| 809 | |||
| 810 | 16 | our $xml10_attvalue_rx = qr/"(?:(?![<&"])$xml10_char_rx|$xml10_reference_rx)*" | |
| 811 | |'(?:(?![<&'])$xml10_char_rx|$xml10_reference_rx)*' | ||
| 812 | /xo; | ||
| 813 | |||
| 814 | =item $xml10_attribute_rx | ||
| 815 | |||
| 816 | A complete attribute, consisting of name, equals sign, and quoted value. | ||
| 817 | The well-formedness constraints of attribute values (pertaining to | ||
| 818 | references) apply. | ||
| 819 | |||
| 820 | =cut | ||
| 821 | |||
| 822 | 16 | our $xml10_attribute_rx = qr/$xml10_name_rx$xml10_eq_rx$xml10_attvalue_rx/o; | |
| 823 | |||
| 824 | =item $xml10_stag_rx | ||
| 825 | |||
| 826 | A start-tag, used to begin an element. This consists of "B<< < >>", | ||
| 827 | the element type name, whitespace-separated list of attributes, and "B<< | ||
| 828 | > >>". The well-formedness constraints of attribute values (pertaining | ||
| 829 | to references) apply. There is also a well-formedness constraint that | ||
| 830 | attribute names must be unique within the tag. | ||
| 831 | |||
| 832 | =cut | ||
| 833 | |||
| 834 | 16 | our $xml10_stag_rx = qr#<$xml10_name_rx | |
| 835 | (?:$xml10_s_rx$xml10_attribute_rx)* | ||
| 836 | $xml10_s_rx?>#xo; | ||
| 837 | |||
| 838 | =item $xml10_etag_rx | ||
| 839 | |||
| 840 | An end-tag, used to finish an element. This consists of "B<< </ >>", | ||
| 841 | the element type name, and "B<< > >>". | ||
| 842 | |||
| 843 | =cut | ||
| 844 | |||
| 845 | 16 | our $xml10_etag_rx = qr#</$xml10_name_rx$xml10_s_rx?>#o; | |
| 846 | |||
| 847 | =item $xml10_emptyelemtag_rx | ||
| 848 | |||
| 849 | An empty-element tag, used to represent an element with no content. | ||
| 850 | This consists of "B<< < >>", the element type name, whitespace-separated | ||
| 851 | list of attributes, and "B<< /> >>". The well-formedness constraints | ||
| 852 | of attribute values (pertaining to references) apply. There is also a | ||
| 853 | well-formedness constraint that attribute names must be unique within | ||
| 854 | the tag. (These are the same constraints as for start-tags.) | ||
| 855 | |||
| 856 | =cut | ||
| 857 | |||
| 858 | 16 | our $xml10_emptyelemtag_rx = qr#<$xml10_name_rx | |
| 859 | (?:$xml10_s_rx$xml10_attribute_rx)* | ||
| 860 | $xml10_s_rx?/>#xo; | ||
| 861 | |||
| 862 | =back | ||
| 863 | |||
| 864 | =head2 Non-data content | ||
| 865 | |||
| 866 | =over | ||
| 867 | |||
| 868 | =item $xml10_comment_rx | ||
| 869 | |||
| 870 | A comment. This does not contribute to the data content of an | ||
| 871 | XML document. It consists of "B<< <!-- >>", zero or more acceptable | ||
| 872 | characters, and "B<< --> >>". It is not permitted for the content to | ||
| 873 | include "B<-->" as a subsequence, nor for it to end with "B<->". | ||
| 874 | |||
| 875 | =cut | ||
| 876 | |||
| 877 | # Note perl bug: the theoretically-cleaner way of expressing this syntax, | ||
| 878 | # /<!--(?:-?(?!-)$xml10_char_rx)*-->/, runs into a problem where the | ||
| 879 | # "*" acts as "{0,32767}", discussed in L</BUGS>, and so fails to match | ||
| 880 | # longer comments. The way that is used here, with a sufficiently simple | ||
| 881 | # expression inside the "*", doesn't run into that problem, but instead | ||
| 882 | # relies on the (?>...) together with the non-greedy quantifier for | ||
| 883 | # proper parsing. It is important for this regexp to not suffer from | ||
| 884 | # this bug, because it is used in the pure-Perl parser. | ||
| 885 | |||
| 886 | 16 | our $xml10_comment_rx = qr/<!--(?>$xml10_char_rx*?--)>/o; | |
| 887 | |||
| 888 | =item $xml10_pitarget_rx | ||
| 889 | |||
| 890 | A processing instruction target name. This can be any name (the | ||
| 891 | C<$xml10_name_rx> production) except for "B<xml>" and its case variations. | ||
| 892 | |||
| 893 | =cut | ||
| 894 | |||
| 895 | 16 | our $xml10_pitarget_rx = qr/(?![Xx])$xml10_name_rx | |
| 896 | |[Xx](?:(?![Mm])$xml10_namechar_rx+)? | ||
| 897 | |[Xx][Mm](?:(?![Ll])$xml10_namechar_rx+)? | ||
| 898 | |[Xx][Mm][Ll]$xml10_namechar_rx+ | ||
| 899 | /xo; | ||
| 900 | |||
| 901 | =item $xml10_pi_rx | ||
| 902 | |||
| 903 | A processing instruction. This consists of "B<< <? >>", a target name, | ||
| 904 | some content which can be almost any sequence of acceptable characters, | ||
| 905 | and "B<< ?> >>". A processing instruction does not contribute to the data | ||
| 906 | content of an XML document, but is intended to carry metadata regarding | ||
| 907 | how to process it. The instruction is addressed to a particular XML | ||
| 908 | processor, or type of processor, identified by the target name, and | ||
| 909 | the content of the instruction is expected to be meaningful only to | ||
| 910 | its target. | ||
| 911 | |||
| 912 | No one has ever come up with a good use for processing instructions. | ||
| 913 | They are best shunned. | ||
| 914 | |||
| 915 | =cut | ||
| 916 | |||
| 917 | 16 | our $xml10_pi_rx = qr/(?> | |
| 918 | <\? | ||
| 919 | (?![Xx][Mm][Ll](?!$xml10_namechar_rx))$xml10_name_rx | ||
| 920 | (?:$xml10_s_rx$xml10_char_rx*?)? | ||
| 921 | \?> | ||
| 922 | )/xo; | ||
| 923 | |||
| 924 | =back | ||
| 925 | |||
| 926 | =head2 Recursive structure | ||
| 927 | |||
| 928 | =over | ||
| 929 | |||
| 930 | =item $xml10_content_rx | ||
| 931 | |||
| 932 | The matter contained within an element (between its start-tag and | ||
| 933 | end-tag). This consists of stretches of ordinary literal character | ||
| 934 | data, interspersed with complete elements (recursively), references, | ||
| 935 | CDATA sections, processing instructions, and comments, in any order. | ||
| 936 | The well-formedness constraints of references and elements apply. | ||
| 937 | |||
| 938 | =cut | ||
| 939 | |||
| 940 | 16 | our $xml10_content_rx; | |
| 941 | { | ||
| 942 | 16 | ▶ | use re "eval"; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 943 | $xml10_content_rx = qr/$xml10_chardata_rx(?:(?: | ||
| 944 | (??{$XML::Easy::Syntax::xml10_element_rx}) | ||
| 945 | |$xml10_reference_rx|$xml10_cdsect_rx | ||
| 946 | |$xml10_pi_rx|$xml10_comment_rx | ||
| 947 | 16 | )$xml10_chardata_rx)*/xo; | |
| 948 | } | ||
| 949 | |||
| 950 | =item $xml10_element_rx | ||
| 951 | |||
| 952 | A complete element. This is either an empty-element tag, or a | ||
| 953 | sequence of start-tag, content, and end-tag. The well-formedness | ||
| 954 | constraints regarding references and attribute uniqueness apply in the | ||
| 955 | empty-element tag or start-tag. In the non-empty form, the content also | ||
| 956 | has well-formedness constraints regarding references and (recursively) | ||
| 957 | contained elements, and there is an additional constraint that the | ||
| 958 | element type name in the end-tag must match that in the start-tag. | ||
| 959 | |||
| 960 | =cut | ||
| 961 | |||
| 962 | 16 | our $xml10_element_rx = qr/$xml10_emptyelemtag_rx | |
| 963 | |$xml10_stag_rx$xml10_content_rx$xml10_etag_rx | ||
| 964 | /xo; | ||
| 965 | |||
| 966 | =back | ||
| 967 | |||
| 968 | =head2 XML declarations | ||
| 969 | |||
| 970 | =over | ||
| 971 | |||
| 972 | =item $xml10_versionnum_rx | ||
| 973 | |||
| 974 | The version number of the XML specification. This is the fixed string | ||
| 975 | "B<1.0>". | ||
| 976 | |||
| 977 | =cut | ||
| 978 | |||
| 979 | 16 | our $xml10_versionnum_rx = qr/1\.0/; | |
| 980 | |||
| 981 | =item $xml10_versioninfo_rx | ||
| 982 | |||
| 983 | The version declaration part of an XML declaration. | ||
| 984 | |||
| 985 | =cut | ||
| 986 | |||
| 987 | 16 | our $xml10_versioninfo_rx = qr/${xml10_s_rx}version$xml10_eq_rx | |
| 988 | (?:'$xml10_versionnum_rx'|"$xml10_versionnum_rx")/xo; | ||
| 989 | |||
| 990 | =item $xml10_encname_rx | ||
| 991 | |||
| 992 | A character encoding name. This must start with an ASCII letter, and | ||
| 993 | contain only ASCII letters and digits and "B<.>", "B<_>", and "B<->". | ||
| 994 | |||
| 995 | =cut | ||
| 996 | |||
| 997 | 16 | our $xml10_encname_rx = qr/[A-Za-z](?:[A-Za-z0-9._\-])*/; | |
| 998 | |||
| 999 | =item $xml10_encodingdecl_rx | ||
| 1000 | |||
| 1001 | The encoding declaration part of an XML declaration. | ||
| 1002 | |||
| 1003 | =cut | ||
| 1004 | |||
| 1005 | 16 | our $xml10_encodingdecl_rx = qr/${xml10_s_rx}encoding$xml10_eq_rx | |
| 1006 | (?:'$xml10_encname_rx'|"$xml10_encname_rx")/xo; | ||
| 1007 | |||
| 1008 | =item $xml10_sddecl_rx | ||
| 1009 | |||
| 1010 | The standaloneness declaration part of an XML declaration. This indicates | ||
| 1011 | whether the XML document can be correctly interpreted without examining | ||
| 1012 | the external part of the DTD. | ||
| 1013 | |||
| 1014 | =cut | ||
| 1015 | |||
| 1016 | 16 | our $xml10_sddecl_rx = qr/${xml10_s_rx}standalone$xml10_eq_rx | |
| 1017 | (?:'(?:yes|no)'|"(?:yes|no)")/xo; | ||
| 1018 | |||
| 1019 | =item $xml10_xmldecl_rx | ||
| 1020 | |||
| 1021 | An XML declaration, as used at the start of an XML document. This | ||
| 1022 | consists of "B<< <?xml >>", mandatory version declaration, optional | ||
| 1023 | encoding declaration, optional standaloneness declaration, and "B<< | ||
| 1024 | ?> >>". | ||
| 1025 | |||
| 1026 | =cut | ||
| 1027 | |||
| 1028 | 16 | our $xml10_xmldecl_rx = qr/<\?xml | |
| 1029 | $xml10_versioninfo_rx | ||
| 1030 | $xml10_encodingdecl_rx? | ||
| 1031 | $xml10_sddecl_rx? | ||
| 1032 | $xml10_s_rx? | ||
| 1033 | \?>/xo; | ||
| 1034 | |||
| 1035 | =item $xml10_textdecl_rx | ||
| 1036 | |||
| 1037 | A text declaration, as used at the start of an XML external parsed | ||
| 1038 | entity or external DTD. This consists of "B<< <?xml >>", optional | ||
| 1039 | version declaration, mandatory encoding declaration, and "B<< ?> >>". | ||
| 1040 | This is very similar to an XML declaration, but technically a different | ||
| 1041 | item and used in different situations. It is possible, and useful, to | ||
| 1042 | construct a declaration which is acceptable both as an XML declaration | ||
| 1043 | and as a text declaration. | ||
| 1044 | |||
| 1045 | =cut | ||
| 1046 | |||
| 1047 | 16 | our $xml10_textdecl_rx = qr/<\?xml | |
| 1048 | $xml10_versioninfo_rx? | ||
| 1049 | $xml10_encodingdecl_rx | ||
| 1050 | $xml10_s_rx? | ||
| 1051 | \?>/xo; | ||
| 1052 | |||
| 1053 | =back | ||
| 1054 | |||
| 1055 | =head2 Document structure | ||
| 1056 | |||
| 1057 | =over | ||
| 1058 | |||
| 1059 | =item $xml10_misc_rx | ||
| 1060 | |||
| 1061 | Non-content item permitted in the prologue and epilogue of a document. | ||
| 1062 | This is either a comment, a processing instruction, or a stretch of | ||
| 1063 | whitespace. | ||
| 1064 | |||
| 1065 | Beware in using a pattern such as C<$xml10_misc_rx*>. It could match | ||
| 1066 | a string of whitespace characters in many ways, leading to exponential | ||
| 1067 | behaviour if it becomes necessary to backtrack. This can be avoided by | ||
| 1068 | using the C<$xml10_miscseq_rx> pattern (below). | ||
| 1069 | |||
| 1070 | =cut | ||
| 1071 | |||
| 1072 | 16 | our $xml10_misc_rx = qr/$xml10_comment_rx|$xml10_pi_rx|$xml10_s_rx/o; | |
| 1073 | |||
| 1074 | =item $xml10_miscseq_rx | ||
| 1075 | |||
| 1076 | A sequence (possibly empty) of non-content matter permitted in the | ||
| 1077 | prologue and epilogue of a document. This can contain comments, | ||
| 1078 | processing instructions, and whitespace, in any order. | ||
| 1079 | |||
| 1080 | This production is not named in the XML specification. This regular | ||
| 1081 | expression should be preferred over C<$xml10_misc_rx*> (which is the | ||
| 1082 | direct translation of what appears in the XML specification), because | ||
| 1083 | this one guarantees to match a particular text in only one way, and is | ||
| 1084 | thus able to backtrack cleanly. | ||
| 1085 | |||
| 1086 | =cut | ||
| 1087 | |||
| 1088 | 16 | our $xml10_miscseq_rx = qr/$xml10_s_rx? | |
| 1089 | (?:(?:$xml10_comment_rx|$xml10_pi_rx) | ||
| 1090 | $xml10_s_rx?)*/xo; | ||
| 1091 | |||
| 1092 | =item $xml10_prolog_xdtd_rx | ||
| 1093 | |||
| 1094 | Document prologue, except for not permitting a document type declaration. | ||
| 1095 | This consists of an optional XML declaration followed by any sequence | ||
| 1096 | of comments, processing instructions, and whitespace. | ||
| 1097 | |||
| 1098 | =cut | ||
| 1099 | |||
| 1100 | 16 | our $xml10_prolog_xdtd_rx = qr/$xml10_xmldecl_rx?$xml10_miscseq_rx/o; | |
| 1101 | |||
| 1102 | =item $xml10_document_xdtd_rx | ||
| 1103 | |||
| 1104 | A complete XML document, except for not permitting a document type | ||
| 1105 | declaration. This consists of a non-content prologue, an element | ||
| 1106 | (the root element, which can recursively contain other elements), and | ||
| 1107 | a non-content epilogue. The well-formedness constraints of elements | ||
| 1108 | apply to the root element. | ||
| 1109 | |||
| 1110 | =cut | ||
| 1111 | |||
| 1112 | 16 | our $xml10_document_xdtd_rx = qr/$xml10_prolog_xdtd_rx$xml10_element_rx | |
| 1113 | $xml10_miscseq_rx/xo; | ||
| 1114 | |||
| 1115 | =item $xml10_extparsedent_rx | ||
| 1116 | |||
| 1117 | A complete external parsed entity. This consists of an optional text | ||
| 1118 | declaration followed by a sequence of content of the same type that is | ||
| 1119 | permitted within an element. The well-formedness constraints of element | ||
| 1120 | content apply. | ||
| 1121 | |||
| 1122 | =cut | ||
| 1123 | |||
| 1124 | 16 | our $xml10_extparsedent_rx = qr/$xml10_textdecl_rx?$xml10_content_rx/o; | |
| 1125 | |||
| 1126 | =back | ||
| 1127 | |||
| 1128 | =head1 BUGS | ||
| 1129 | |||
| 1130 | Many of these regular expressions are liable to tickle a serious bug in | ||
| 1131 | perl's regexp engine. The bug is that the C<*> and C<+> repeat operators | ||
| 1132 | don't always match an unlimited number of repeats: in some cases they are | ||
| 1133 | limited to 32767 iterations. Whether this bogus limit applies depends | ||
| 1134 | on the complexity of the expression being repeated, whether the string | ||
| 1135 | being examined is internally encoded in UTF-8, and the version of perl. | ||
| 1136 | In some cases, but not all, a false match failure is preceded by a warning | ||
| 1137 | "Complex regular subexpression recursion limit (32766) exceeded". | ||
| 1138 | |||
| 1139 | This bug is present, in various forms, in all perl versions up to at | ||
| 1140 | least 5.8.9 and 5.10.0. Pre-5.10 perls may also overflow their stack | ||
| 1141 | space, in similar circumstances, if a resource limit is imposed. | ||
| 1142 | |||
| 1143 | There is no known feasible workaround for this perl bug. The regular | ||
| 1144 | expressions supplied by this module will therefore, unavoidably, fail | ||
| 1145 | to accept some lengthy valid inputs. Where this occurs, though, it is | ||
| 1146 | likely that other regular expressions being applied to the same or related | ||
| 1147 | input will also suffer the same problem. It is pervasive. Do not rely | ||
| 1148 | on this module (or perl) to process long inputs on affected perl versions. | ||
| 1149 | |||
| 1150 | This bug does not affect the L<XML::Easy::Text> parser. | ||
| 1151 | |||
| 1152 | =head1 SEE ALSO | ||
| 1153 | |||
| 1154 | L<XML::Easy::Text>, | ||
| 1155 | L<http://www.w3.org/TR/REC-xml/> | ||
| 1156 | |||
| 1157 | =head1 AUTHOR | ||
| 1158 | |||
| 1159 | Andrew Main (Zefram) <zefram@fysh.org> | ||
| 1160 | |||
| 1161 | =head1 COPYRIGHT | ||
| 1162 | |||
| 1163 | Copyright (C) 2008, 2009 PhotoBox Ltd | ||
| 1164 | |||
| 1165 | Copyright (C) 2009, 2010, 2011, 2017 | ||
| 1166 | Andrew Main (Zefram) <zefram@fysh.org> | ||
| 1167 | |||
| 1168 | =head1 LICENSE | ||
| 1169 | |||
| 1170 | This module is free software; you can redistribute it and/or modify it | ||
| 1171 | under the same terms as Perl itself. | ||
| 1172 | |||
| 1173 | =cut | ||
| 1174 | |||
| 1175 | 16 | 1; | |