Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Parser often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Parser, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 5 | class Parser |
||
| 6 | { |
||
| 7 | protected $string; |
||
| 8 | protected $position; |
||
| 9 | protected $value; |
||
| 10 | protected $cache; |
||
| 11 | protected $cut; |
||
| 12 | protected $errors; |
||
| 13 | protected $warnings; |
||
| 14 | |||
| 15 | protected function parseFILE() |
||
| 16 | { |
||
| 17 | $_position = $this->position; |
||
| 18 | |||
| 19 | if (isset($this->cache['FILE'][$_position])) { |
||
| 20 | $_success = $this->cache['FILE'][$_position]['success']; |
||
| 21 | $this->position = $this->cache['FILE'][$_position]['position']; |
||
| 22 | $this->value = $this->cache['FILE'][$_position]['value']; |
||
| 23 | |||
| 24 | return $_success; |
||
| 25 | } |
||
| 26 | |||
| 27 | $_value9 = array(); |
||
| 28 | |||
| 29 | $_value4 = array(); |
||
| 30 | $_cut5 = $this->cut; |
||
| 31 | |||
| 32 | while (true) { |
||
| 33 | $_position3 = $this->position; |
||
| 34 | |||
| 35 | $this->cut = false; |
||
| 36 | $_position1 = $this->position; |
||
| 37 | $_cut2 = $this->cut; |
||
| 38 | |||
| 39 | $this->cut = false; |
||
| 40 | $_success = $this->parseEXAMPLE(); |
||
| 41 | |||
| 42 | if (!$_success && !$this->cut) { |
||
| 43 | $this->position = $_position1; |
||
| 44 | |||
| 45 | $_success = $this->parseVOID_LINE(); |
||
| 46 | } |
||
| 47 | |||
| 48 | $this->cut = $_cut2; |
||
| 49 | |||
| 50 | if (!$_success) { |
||
| 51 | break; |
||
| 52 | } |
||
| 53 | |||
| 54 | $_value4[] = $this->value; |
||
| 55 | } |
||
| 56 | |||
| 57 | if (!$this->cut) { |
||
| 58 | $_success = true; |
||
| 59 | $this->position = $_position3; |
||
| 60 | $this->value = $_value4; |
||
| 61 | } |
||
| 62 | |||
| 63 | $this->cut = $_cut5; |
||
| 64 | |||
| 65 | if ($_success) { |
||
| 66 | $examples = $this->value; |
||
| 67 | } |
||
| 68 | |||
| 69 | if ($_success) { |
||
| 70 | $_value9[] = $this->value; |
||
| 71 | |||
| 72 | $_value7 = array(); |
||
| 73 | $_cut8 = $this->cut; |
||
| 74 | |||
| 75 | while (true) { |
||
| 76 | $_position6 = $this->position; |
||
| 77 | |||
| 78 | $this->cut = false; |
||
| 79 | if ($this->position < strlen($this->string)) { |
||
| 80 | $_success = true; |
||
| 81 | $this->value = substr($this->string, $this->position, 1); |
||
| 82 | $this->position += 1; |
||
| 83 | } else { |
||
| 84 | $_success = false; |
||
| 85 | } |
||
| 86 | |||
| 87 | if (!$_success) { |
||
| 88 | break; |
||
| 89 | } |
||
| 90 | |||
| 91 | $_value7[] = $this->value; |
||
| 92 | } |
||
| 93 | |||
| 94 | if (!$this->cut) { |
||
| 95 | $_success = true; |
||
| 96 | $this->position = $_position6; |
||
| 97 | $this->value = $_value7; |
||
| 98 | } |
||
| 99 | |||
| 100 | $this->cut = $_cut8; |
||
| 101 | } |
||
| 102 | |||
| 103 | if ($_success) { |
||
| 104 | $_value9[] = $this->value; |
||
| 105 | |||
| 106 | $this->value = $_value9; |
||
| 107 | } |
||
| 108 | |||
| 109 | if ($_success) { |
||
| 110 | $this->value = call_user_func(function () use (&$examples) { |
||
| 111 | return array_values(array_filter($examples)); |
||
| 112 | }); |
||
| 113 | } |
||
| 114 | |||
| 115 | $this->cache['FILE'][$_position] = array( |
||
| 116 | 'success' => $_success, |
||
| 117 | 'position' => $this->position, |
||
| 118 | 'value' => $this->value |
||
| 119 | ); |
||
| 120 | |||
| 121 | if (!$_success) { |
||
| 122 | $this->report($_position, 'FILE'); |
||
| 123 | } |
||
| 124 | |||
| 125 | return $_success; |
||
| 126 | } |
||
| 127 | |||
| 128 | protected function parseVOID_LINE() |
||
| 129 | { |
||
| 130 | $_position = $this->position; |
||
| 131 | |||
| 132 | if (isset($this->cache['VOID_LINE'][$_position])) { |
||
| 133 | $_success = $this->cache['VOID_LINE'][$_position]['success']; |
||
| 134 | $this->position = $this->cache['VOID_LINE'][$_position]['position']; |
||
| 135 | $this->value = $this->cache['VOID_LINE'][$_position]['value']; |
||
| 136 | |||
| 137 | return $_success; |
||
| 138 | } |
||
| 139 | |||
| 140 | $_value16 = array(); |
||
| 141 | |||
| 142 | $_value14 = array(); |
||
| 143 | $_cut15 = $this->cut; |
||
| 144 | |||
| 145 | while (true) { |
||
| 146 | $_position13 = $this->position; |
||
| 147 | |||
| 148 | $this->cut = false; |
||
| 149 | $_value12 = array(); |
||
| 150 | |||
| 151 | $_position10 = $this->position; |
||
| 152 | $_cut11 = $this->cut; |
||
| 153 | |||
| 154 | $this->cut = false; |
||
| 155 | $_success = $this->parseEOL(); |
||
| 156 | |||
| 157 | if (!$_success) { |
||
| 158 | $_success = true; |
||
| 159 | $this->value = null; |
||
| 160 | } else { |
||
| 161 | $_success = false; |
||
| 162 | } |
||
| 163 | |||
| 164 | $this->position = $_position10; |
||
| 165 | $this->cut = $_cut11; |
||
| 166 | |||
| 167 | if ($_success) { |
||
| 168 | $_value12[] = $this->value; |
||
| 169 | |||
| 170 | if ($this->position < strlen($this->string)) { |
||
| 171 | $_success = true; |
||
| 172 | $this->value = substr($this->string, $this->position, 1); |
||
| 173 | $this->position += 1; |
||
| 174 | } else { |
||
| 175 | $_success = false; |
||
| 176 | } |
||
| 177 | } |
||
| 178 | |||
| 179 | if ($_success) { |
||
| 180 | $_value12[] = $this->value; |
||
| 181 | |||
| 182 | $this->value = $_value12; |
||
| 183 | } |
||
| 184 | |||
| 185 | if (!$_success) { |
||
| 186 | break; |
||
| 187 | } |
||
| 188 | |||
| 189 | $_value14[] = $this->value; |
||
| 190 | } |
||
| 191 | |||
| 192 | if (!$this->cut) { |
||
| 193 | $_success = true; |
||
| 194 | $this->position = $_position13; |
||
| 195 | $this->value = $_value14; |
||
| 196 | } |
||
| 197 | |||
| 198 | $this->cut = $_cut15; |
||
| 199 | |||
| 200 | if ($_success) { |
||
| 201 | $_value16[] = $this->value; |
||
| 202 | |||
| 203 | $_success = $this->parseEOL(); |
||
| 204 | } |
||
| 205 | |||
| 206 | if ($_success) { |
||
| 207 | $_value16[] = $this->value; |
||
| 208 | |||
| 209 | $this->value = $_value16; |
||
| 210 | } |
||
| 211 | |||
| 212 | if ($_success) { |
||
| 213 | $this->value = call_user_func(function () { |
||
| 214 | return ''; |
||
| 215 | }); |
||
| 216 | } |
||
| 217 | |||
| 218 | $this->cache['VOID_LINE'][$_position] = array( |
||
| 219 | 'success' => $_success, |
||
| 220 | 'position' => $this->position, |
||
| 221 | 'value' => $this->value |
||
| 222 | ); |
||
| 223 | |||
| 224 | if (!$_success) { |
||
| 225 | $this->report($_position, 'VOID_LINE'); |
||
| 226 | } |
||
| 227 | |||
| 228 | return $_success; |
||
| 229 | } |
||
| 230 | |||
| 231 | protected function parseEXAMPLE() |
||
| 232 | { |
||
| 233 | $_position = $this->position; |
||
| 234 | |||
| 235 | if (isset($this->cache['EXAMPLE'][$_position])) { |
||
| 236 | $_success = $this->cache['EXAMPLE'][$_position]['success']; |
||
| 237 | $this->position = $this->cache['EXAMPLE'][$_position]['position']; |
||
| 238 | $this->value = $this->cache['EXAMPLE'][$_position]['value']; |
||
| 239 | |||
| 240 | return $_success; |
||
| 241 | } |
||
| 242 | |||
| 243 | $_value19 = array(); |
||
| 244 | |||
| 245 | $_position17 = $this->position; |
||
| 246 | $_cut18 = $this->cut; |
||
| 247 | |||
| 248 | $this->cut = false; |
||
| 249 | $_success = $this->parseANNOTATIONS(); |
||
| 250 | |||
| 251 | if (!$_success && !$this->cut) { |
||
| 252 | $_success = true; |
||
| 253 | $this->position = $_position17; |
||
| 254 | $this->value = null; |
||
| 255 | } |
||
| 256 | |||
| 257 | $this->cut = $_cut18; |
||
| 258 | |||
| 259 | if ($_success) { |
||
| 260 | $annotations = $this->value; |
||
| 261 | } |
||
| 262 | |||
| 263 | if ($_success) { |
||
| 264 | $_value19[] = $this->value; |
||
| 265 | |||
| 266 | $_success = $this->parseCODE(); |
||
| 267 | |||
| 268 | if ($_success) { |
||
| 269 | $code = $this->value; |
||
| 270 | } |
||
| 271 | } |
||
| 272 | |||
| 273 | if ($_success) { |
||
| 274 | $_value19[] = $this->value; |
||
| 275 | |||
| 276 | $this->value = $_value19; |
||
| 277 | } |
||
| 278 | |||
| 279 | if ($_success) { |
||
| 280 | $this->value = call_user_func(function () use (&$annotations, &$code) { |
||
| 281 | return ['annotations' => (array)$annotations, 'code' => $code]; |
||
| 282 | }); |
||
| 283 | } |
||
| 284 | |||
| 285 | $this->cache['EXAMPLE'][$_position] = array( |
||
| 286 | 'success' => $_success, |
||
| 287 | 'position' => $this->position, |
||
| 288 | 'value' => $this->value |
||
| 289 | ); |
||
| 290 | |||
| 291 | if (!$_success) { |
||
| 292 | $this->report($_position, 'EXAMPLE'); |
||
| 293 | } |
||
| 294 | |||
| 295 | return $_success; |
||
| 296 | } |
||
| 297 | |||
| 298 | protected function parseANNOTATIONS() |
||
| 299 | { |
||
| 300 | $_position = $this->position; |
||
| 301 | |||
| 302 | if (isset($this->cache['ANNOTATIONS'][$_position])) { |
||
| 303 | $_success = $this->cache['ANNOTATIONS'][$_position]['success']; |
||
| 304 | $this->position = $this->cache['ANNOTATIONS'][$_position]['position']; |
||
| 305 | $this->value = $this->cache['ANNOTATIONS'][$_position]['value']; |
||
| 306 | |||
| 307 | return $_success; |
||
| 308 | } |
||
| 309 | |||
| 310 | $_success = $this->parseANNOTATION_GROUP(); |
||
| 311 | |||
| 312 | if ($_success) { |
||
| 313 | $_value21 = array($this->value); |
||
| 314 | $_cut22 = $this->cut; |
||
| 315 | |||
| 316 | while (true) { |
||
| 317 | $_position20 = $this->position; |
||
| 318 | |||
| 319 | $this->cut = false; |
||
| 320 | $_success = $this->parseANNOTATION_GROUP(); |
||
| 321 | |||
| 322 | if (!$_success) { |
||
| 323 | break; |
||
| 324 | } |
||
| 325 | |||
| 326 | $_value21[] = $this->value; |
||
| 327 | } |
||
| 328 | |||
| 329 | if (!$this->cut) { |
||
| 330 | $_success = true; |
||
| 331 | $this->position = $_position20; |
||
| 332 | $this->value = $_value21; |
||
| 333 | } |
||
| 334 | |||
| 335 | $this->cut = $_cut22; |
||
| 336 | } |
||
| 337 | |||
| 338 | if ($_success) { |
||
| 339 | $groups = $this->value; |
||
| 340 | } |
||
| 341 | |||
| 342 | if ($_success) { |
||
| 343 | $this->value = call_user_func(function () use (&$groups) { |
||
| 344 | return call_user_func_array('array_merge', $groups); |
||
| 345 | }); |
||
| 346 | } |
||
| 347 | |||
| 348 | $this->cache['ANNOTATIONS'][$_position] = array( |
||
| 349 | 'success' => $_success, |
||
| 350 | 'position' => $this->position, |
||
| 351 | 'value' => $this->value |
||
| 352 | ); |
||
| 353 | |||
| 354 | if (!$_success) { |
||
| 355 | $this->report($_position, 'ANNOTATIONS'); |
||
| 356 | } |
||
| 357 | |||
| 358 | return $_success; |
||
| 359 | } |
||
| 360 | |||
| 361 | protected function parseANNOTATION_GROUP() |
||
| 362 | { |
||
| 363 | $_position = $this->position; |
||
| 364 | |||
| 365 | if (isset($this->cache['ANNOTATION_GROUP'][$_position])) { |
||
| 366 | $_success = $this->cache['ANNOTATION_GROUP'][$_position]['success']; |
||
| 367 | $this->position = $this->cache['ANNOTATION_GROUP'][$_position]['position']; |
||
| 368 | $this->value = $this->cache['ANNOTATION_GROUP'][$_position]['value']; |
||
| 369 | |||
| 370 | return $_success; |
||
| 371 | } |
||
| 372 | |||
| 373 | $_value26 = array(); |
||
| 374 | |||
| 375 | $_success = $this->parseANNOTATION_GROUP_START(); |
||
| 376 | |||
| 377 | if ($_success) { |
||
| 378 | $_value26[] = $this->value; |
||
| 379 | |||
| 380 | $_success = $this->parseANNOTATION(); |
||
| 381 | |||
| 382 | if ($_success) { |
||
| 383 | $_value24 = array($this->value); |
||
| 384 | $_cut25 = $this->cut; |
||
| 385 | |||
| 386 | while (true) { |
||
| 387 | $_position23 = $this->position; |
||
| 388 | |||
| 389 | $this->cut = false; |
||
| 390 | $_success = $this->parseANNOTATION(); |
||
| 391 | |||
| 392 | if (!$_success) { |
||
| 393 | break; |
||
| 394 | } |
||
| 395 | |||
| 396 | $_value24[] = $this->value; |
||
| 397 | } |
||
| 398 | |||
| 399 | if (!$this->cut) { |
||
| 400 | $_success = true; |
||
| 401 | $this->position = $_position23; |
||
| 402 | $this->value = $_value24; |
||
| 403 | } |
||
| 404 | |||
| 405 | $this->cut = $_cut25; |
||
| 406 | } |
||
| 407 | |||
| 408 | if ($_success) { |
||
| 409 | $annotations = $this->value; |
||
| 410 | } |
||
| 411 | } |
||
| 412 | |||
| 413 | if ($_success) { |
||
| 414 | $_value26[] = $this->value; |
||
| 415 | |||
| 416 | $_success = $this->parseANNOTATIONS_GROUP_END(); |
||
| 417 | } |
||
| 418 | |||
| 419 | if ($_success) { |
||
| 420 | $_value26[] = $this->value; |
||
| 421 | |||
| 422 | $this->value = $_value26; |
||
| 423 | } |
||
| 424 | |||
| 425 | if ($_success) { |
||
| 426 | $this->value = call_user_func(function () use (&$annotations) { |
||
| 427 | return $annotations; |
||
| 428 | }); |
||
| 429 | } |
||
| 430 | |||
| 431 | $this->cache['ANNOTATION_GROUP'][$_position] = array( |
||
| 432 | 'success' => $_success, |
||
| 433 | 'position' => $this->position, |
||
| 434 | 'value' => $this->value |
||
| 435 | ); |
||
| 436 | |||
| 437 | if (!$_success) { |
||
| 438 | $this->report($_position, 'ANNOTATION_GROUP'); |
||
| 439 | } |
||
| 440 | |||
| 441 | return $_success; |
||
| 442 | } |
||
| 443 | |||
| 444 | protected function parseANNOTATION_GROUP_START() |
||
| 445 | { |
||
| 446 | $_position = $this->position; |
||
| 447 | |||
| 448 | if (isset($this->cache['ANNOTATION_GROUP_START'][$_position])) { |
||
| 449 | $_success = $this->cache['ANNOTATION_GROUP_START'][$_position]['success']; |
||
| 450 | $this->position = $this->cache['ANNOTATION_GROUP_START'][$_position]['position']; |
||
| 451 | $this->value = $this->cache['ANNOTATION_GROUP_START'][$_position]['value']; |
||
| 452 | |||
| 453 | return $_success; |
||
| 454 | } |
||
| 455 | |||
| 456 | $_value31 = array(); |
||
| 457 | |||
| 458 | $_success = $this->parse_(); |
||
| 459 | |||
| 460 | if ($_success) { |
||
| 461 | $_value31[] = $this->value; |
||
| 462 | |||
| 463 | if (substr($this->string, $this->position, strlen('<!--')) === '<!--') { |
||
| 464 | $_success = true; |
||
| 465 | $this->value = substr($this->string, $this->position, strlen('<!--')); |
||
| 466 | $this->position += strlen('<!--'); |
||
| 467 | } else { |
||
| 468 | $_success = false; |
||
| 469 | |||
| 470 | $this->report($this->position, '\'<!--\''); |
||
| 471 | } |
||
| 472 | } |
||
| 473 | |||
| 474 | if ($_success) { |
||
| 475 | $_value31[] = $this->value; |
||
| 476 | |||
| 477 | $_position27 = $this->position; |
||
| 478 | $_cut28 = $this->cut; |
||
| 479 | |||
| 480 | $this->cut = false; |
||
| 481 | if (substr($this->string, $this->position, strlen('-')) === '-') { |
||
| 482 | $_success = true; |
||
| 483 | $this->value = substr($this->string, $this->position, strlen('-')); |
||
| 484 | $this->position += strlen('-'); |
||
| 485 | } else { |
||
| 486 | $_success = false; |
||
| 487 | |||
| 488 | $this->report($this->position, '\'-\''); |
||
| 489 | } |
||
| 490 | |||
| 491 | if (!$_success && !$this->cut) { |
||
| 492 | $_success = true; |
||
| 493 | $this->position = $_position27; |
||
| 494 | $this->value = null; |
||
| 495 | } |
||
| 496 | |||
| 497 | $this->cut = $_cut28; |
||
| 498 | } |
||
| 499 | |||
| 500 | if ($_success) { |
||
| 501 | $_value31[] = $this->value; |
||
| 502 | |||
| 503 | $_position29 = $this->position; |
||
| 504 | $_cut30 = $this->cut; |
||
| 505 | |||
| 506 | $this->cut = false; |
||
| 507 | $_success = $this->parseEOL(); |
||
| 508 | |||
| 509 | if (!$_success && !$this->cut) { |
||
| 510 | $_success = true; |
||
| 511 | $this->position = $_position29; |
||
| 512 | $this->value = null; |
||
| 513 | } |
||
| 514 | |||
| 515 | $this->cut = $_cut30; |
||
| 516 | } |
||
| 517 | |||
| 518 | if ($_success) { |
||
| 519 | $_value31[] = $this->value; |
||
| 520 | |||
| 521 | $this->value = $_value31; |
||
| 522 | } |
||
| 523 | |||
| 524 | $this->cache['ANNOTATION_GROUP_START'][$_position] = array( |
||
| 525 | 'success' => $_success, |
||
| 526 | 'position' => $this->position, |
||
| 527 | 'value' => $this->value |
||
| 528 | ); |
||
| 529 | |||
| 530 | if (!$_success) { |
||
| 531 | $this->report($_position, 'ANNOTATION_GROUP_START'); |
||
| 532 | } |
||
| 533 | |||
| 534 | return $_success; |
||
| 535 | } |
||
| 536 | |||
| 537 | protected function parseANNOTATIONS_GROUP_END() |
||
| 538 | { |
||
| 539 | $_position = $this->position; |
||
| 540 | |||
| 541 | if (isset($this->cache['ANNOTATIONS_GROUP_END'][$_position])) { |
||
| 542 | $_success = $this->cache['ANNOTATIONS_GROUP_END'][$_position]['success']; |
||
| 543 | $this->position = $this->cache['ANNOTATIONS_GROUP_END'][$_position]['position']; |
||
| 544 | $this->value = $this->cache['ANNOTATIONS_GROUP_END'][$_position]['value']; |
||
| 545 | |||
| 546 | return $_success; |
||
| 547 | } |
||
| 548 | |||
| 549 | $_value34 = array(); |
||
| 550 | |||
| 551 | $_success = $this->parse_(); |
||
| 552 | |||
| 553 | if ($_success) { |
||
| 554 | $_value34[] = $this->value; |
||
| 555 | |||
| 556 | if (substr($this->string, $this->position, strlen('-->')) === '-->') { |
||
| 557 | $_success = true; |
||
| 558 | $this->value = substr($this->string, $this->position, strlen('-->')); |
||
| 559 | $this->position += strlen('-->'); |
||
| 560 | } else { |
||
| 561 | $_success = false; |
||
| 562 | |||
| 563 | $this->report($this->position, '\'-->\''); |
||
| 564 | } |
||
| 565 | } |
||
| 566 | |||
| 567 | if ($_success) { |
||
| 568 | $_value34[] = $this->value; |
||
| 569 | |||
| 570 | $_position32 = $this->position; |
||
| 571 | $_cut33 = $this->cut; |
||
| 572 | |||
| 573 | $this->cut = false; |
||
| 574 | $_success = $this->parseEOL(); |
||
| 575 | |||
| 576 | if (!$_success && !$this->cut) { |
||
| 577 | $_success = true; |
||
| 578 | $this->position = $_position32; |
||
| 579 | $this->value = null; |
||
| 580 | } |
||
| 581 | |||
| 582 | $this->cut = $_cut33; |
||
| 583 | } |
||
| 584 | |||
| 585 | if ($_success) { |
||
| 586 | $_value34[] = $this->value; |
||
| 587 | |||
| 588 | $this->value = $_value34; |
||
| 589 | } |
||
| 590 | |||
| 591 | $this->cache['ANNOTATIONS_GROUP_END'][$_position] = array( |
||
| 592 | 'success' => $_success, |
||
| 593 | 'position' => $this->position, |
||
| 594 | 'value' => $this->value |
||
| 595 | ); |
||
| 596 | |||
| 597 | if (!$_success) { |
||
| 598 | $this->report($_position, 'ANNOTATIONS_GROUP_END'); |
||
| 599 | } |
||
| 600 | |||
| 601 | return $_success; |
||
| 602 | } |
||
| 603 | |||
| 604 | protected function parseANNOTATION() |
||
| 605 | { |
||
| 606 | $_position = $this->position; |
||
| 607 | |||
| 608 | if (isset($this->cache['ANNOTATION'][$_position])) { |
||
| 609 | $_success = $this->cache['ANNOTATION'][$_position]['success']; |
||
| 610 | $this->position = $this->cache['ANNOTATION'][$_position]['position']; |
||
| 611 | $this->value = $this->cache['ANNOTATION'][$_position]['value']; |
||
| 612 | |||
| 613 | return $_success; |
||
| 614 | } |
||
| 615 | |||
| 616 | $_value40 = array(); |
||
| 617 | |||
| 618 | $_success = $this->parse_(); |
||
| 619 | |||
| 620 | if ($_success) { |
||
| 621 | $_value40[] = $this->value; |
||
| 622 | |||
| 623 | if (substr($this->string, $this->position, strlen('@')) === '@') { |
||
| 624 | $_success = true; |
||
| 625 | $this->value = substr($this->string, $this->position, strlen('@')); |
||
| 626 | $this->position += strlen('@'); |
||
| 627 | } else { |
||
| 628 | $_success = false; |
||
| 629 | |||
| 630 | $this->report($this->position, '\'@\''); |
||
| 631 | } |
||
| 632 | } |
||
| 633 | |||
| 634 | if ($_success) { |
||
| 635 | $_value40[] = $this->value; |
||
| 636 | |||
| 637 | $_success = $this->parseSTRING(); |
||
| 638 | |||
| 639 | if ($_success) { |
||
| 640 | $name = $this->value; |
||
| 641 | } |
||
| 642 | } |
||
| 643 | |||
| 644 | if ($_success) { |
||
| 645 | $_value40[] = $this->value; |
||
| 646 | |||
| 647 | $_value36 = array(); |
||
| 648 | $_cut37 = $this->cut; |
||
| 649 | |||
| 650 | while (true) { |
||
| 651 | $_position35 = $this->position; |
||
| 652 | |||
| 653 | $this->cut = false; |
||
| 654 | $_success = $this->parseSTRING(); |
||
| 655 | |||
| 656 | if (!$_success) { |
||
| 657 | break; |
||
| 658 | } |
||
| 659 | |||
| 660 | $_value36[] = $this->value; |
||
| 661 | } |
||
| 662 | |||
| 663 | if (!$this->cut) { |
||
| 664 | $_success = true; |
||
| 665 | $this->position = $_position35; |
||
| 666 | $this->value = $_value36; |
||
| 667 | } |
||
| 668 | |||
| 669 | $this->cut = $_cut37; |
||
| 670 | |||
| 671 | if ($_success) { |
||
| 672 | $args = $this->value; |
||
| 673 | } |
||
| 674 | } |
||
| 675 | |||
| 676 | if ($_success) { |
||
| 677 | $_value40[] = $this->value; |
||
| 678 | |||
| 679 | $_position38 = $this->position; |
||
| 680 | $_cut39 = $this->cut; |
||
| 681 | |||
| 682 | $this->cut = false; |
||
| 683 | $_success = $this->parseEOL(); |
||
| 684 | |||
| 685 | if (!$_success && !$this->cut) { |
||
| 686 | $_success = true; |
||
| 687 | $this->position = $_position38; |
||
| 688 | $this->value = null; |
||
| 689 | } |
||
| 690 | |||
| 691 | $this->cut = $_cut39; |
||
| 692 | } |
||
| 693 | |||
| 694 | if ($_success) { |
||
| 695 | $_value40[] = $this->value; |
||
| 696 | |||
| 697 | $this->value = $_value40; |
||
| 698 | } |
||
| 699 | |||
| 700 | if ($_success) { |
||
| 701 | $this->value = call_user_func(function () use (&$name, &$args) { |
||
| 702 | return [$name, $args]; |
||
| 703 | }); |
||
| 704 | } |
||
| 705 | |||
| 706 | $this->cache['ANNOTATION'][$_position] = array( |
||
| 707 | 'success' => $_success, |
||
| 708 | 'position' => $this->position, |
||
| 709 | 'value' => $this->value |
||
| 710 | ); |
||
| 711 | |||
| 712 | if (!$_success) { |
||
| 713 | $this->report($_position, 'ANNOTATION'); |
||
| 714 | } |
||
| 715 | |||
| 716 | return $_success; |
||
| 717 | } |
||
| 718 | |||
| 719 | protected function parseSTRING() |
||
| 720 | { |
||
| 721 | $_position = $this->position; |
||
| 722 | |||
| 723 | if (isset($this->cache['STRING'][$_position])) { |
||
| 724 | $_success = $this->cache['STRING'][$_position]['success']; |
||
| 725 | $this->position = $this->cache['STRING'][$_position]['position']; |
||
| 726 | $this->value = $this->cache['STRING'][$_position]['value']; |
||
| 727 | |||
| 728 | return $_success; |
||
| 729 | } |
||
| 730 | |||
| 731 | $_value43 = array(); |
||
| 732 | |||
| 733 | $_success = $this->parse_(); |
||
| 734 | |||
| 735 | if ($_success) { |
||
| 736 | $_value43[] = $this->value; |
||
| 737 | |||
| 738 | $_position41 = $this->position; |
||
| 739 | $_cut42 = $this->cut; |
||
| 740 | |||
| 741 | $this->cut = false; |
||
| 742 | $_success = $this->parseRAW_STRING(); |
||
| 743 | |||
| 744 | if (!$_success && !$this->cut) { |
||
| 745 | $this->position = $_position41; |
||
| 746 | |||
| 747 | $_success = $this->parseQUOTED_STRING(); |
||
| 748 | } |
||
| 749 | |||
| 750 | if (!$_success && !$this->cut) { |
||
| 751 | $this->position = $_position41; |
||
| 752 | |||
| 753 | $_success = $this->parseEMPTY_STRING(); |
||
| 754 | } |
||
| 755 | |||
| 756 | $this->cut = $_cut42; |
||
| 757 | |||
| 758 | if ($_success) { |
||
| 759 | $string = $this->value; |
||
| 760 | } |
||
| 761 | } |
||
| 762 | |||
| 763 | if ($_success) { |
||
| 764 | $_value43[] = $this->value; |
||
| 765 | |||
| 766 | $_success = $this->parse_(); |
||
| 767 | } |
||
| 768 | |||
| 769 | if ($_success) { |
||
| 770 | $_value43[] = $this->value; |
||
| 771 | |||
| 772 | $this->value = $_value43; |
||
| 773 | } |
||
| 774 | |||
| 775 | if ($_success) { |
||
| 776 | $this->value = call_user_func(function () use (&$string) { |
||
| 777 | return $string; |
||
| 778 | }); |
||
| 779 | } |
||
| 780 | |||
| 781 | $this->cache['STRING'][$_position] = array( |
||
| 782 | 'success' => $_success, |
||
| 783 | 'position' => $this->position, |
||
| 784 | 'value' => $this->value |
||
| 785 | ); |
||
| 786 | |||
| 787 | if (!$_success) { |
||
| 788 | $this->report($_position, 'STRING'); |
||
| 789 | } |
||
| 790 | |||
| 791 | return $_success; |
||
| 792 | } |
||
| 793 | |||
| 794 | protected function parseEMPTY_STRING() |
||
| 795 | { |
||
| 796 | $_position = $this->position; |
||
| 797 | |||
| 798 | if (isset($this->cache['EMPTY_STRING'][$_position])) { |
||
| 799 | $_success = $this->cache['EMPTY_STRING'][$_position]['success']; |
||
| 800 | $this->position = $this->cache['EMPTY_STRING'][$_position]['position']; |
||
| 801 | $this->value = $this->cache['EMPTY_STRING'][$_position]['value']; |
||
| 802 | |||
| 803 | return $_success; |
||
| 804 | } |
||
| 805 | |||
| 806 | if (substr($this->string, $this->position, strlen('""')) === '""') { |
||
| 807 | $_success = true; |
||
| 808 | $this->value = substr($this->string, $this->position, strlen('""')); |
||
| 809 | $this->position += strlen('""'); |
||
| 810 | } else { |
||
| 811 | $_success = false; |
||
| 812 | |||
| 813 | $this->report($this->position, '\'""\''); |
||
| 814 | } |
||
| 815 | |||
| 816 | if ($_success) { |
||
| 817 | $this->value = call_user_func(function () { |
||
| 818 | return ''; |
||
| 819 | }); |
||
| 820 | } |
||
| 821 | |||
| 822 | $this->cache['EMPTY_STRING'][$_position] = array( |
||
| 823 | 'success' => $_success, |
||
| 824 | 'position' => $this->position, |
||
| 825 | 'value' => $this->value |
||
| 826 | ); |
||
| 827 | |||
| 828 | if (!$_success) { |
||
| 829 | $this->report($_position, 'EMPTY_STRING'); |
||
| 830 | } |
||
| 831 | |||
| 832 | return $_success; |
||
| 833 | } |
||
| 834 | |||
| 835 | protected function parseQUOTED_STRING() |
||
| 836 | { |
||
| 837 | $_position = $this->position; |
||
| 838 | |||
| 839 | if (isset($this->cache['QUOTED_STRING'][$_position])) { |
||
| 840 | $_success = $this->cache['QUOTED_STRING'][$_position]['success']; |
||
| 841 | $this->position = $this->cache['QUOTED_STRING'][$_position]['position']; |
||
| 842 | $this->value = $this->cache['QUOTED_STRING'][$_position]['value']; |
||
| 843 | |||
| 844 | return $_success; |
||
| 845 | } |
||
| 846 | |||
| 847 | $_value49 = array(); |
||
| 848 | |||
| 849 | if (substr($this->string, $this->position, strlen('"')) === '"') { |
||
| 850 | $_success = true; |
||
| 851 | $this->value = substr($this->string, $this->position, strlen('"')); |
||
| 852 | $this->position += strlen('"'); |
||
| 853 | } else { |
||
| 854 | $_success = false; |
||
| 855 | |||
| 856 | $this->report($this->position, '\'"\''); |
||
| 857 | } |
||
| 858 | |||
| 859 | if ($_success) { |
||
| 860 | $_value49[] = $this->value; |
||
| 861 | |||
| 862 | $_value47 = array(); |
||
| 863 | $_cut48 = $this->cut; |
||
| 864 | |||
| 865 | while (true) { |
||
| 866 | $_position46 = $this->position; |
||
| 867 | |||
| 868 | $this->cut = false; |
||
| 869 | $_position44 = $this->position; |
||
| 870 | $_cut45 = $this->cut; |
||
| 871 | |||
| 872 | $this->cut = false; |
||
| 873 | $_success = $this->parseESCAPED_QUOTE(); |
||
| 874 | |||
| 875 | if (!$_success && !$this->cut) { |
||
| 876 | $this->position = $_position44; |
||
| 877 | |||
| 878 | if (substr($this->string, $this->position, strlen(' ')) === ' ') { |
||
| 879 | $_success = true; |
||
| 880 | $this->value = substr($this->string, $this->position, strlen(' ')); |
||
| 881 | $this->position += strlen(' '); |
||
| 882 | } else { |
||
| 883 | $_success = false; |
||
| 884 | |||
| 885 | $this->report($this->position, '\' \''); |
||
| 886 | } |
||
| 887 | } |
||
| 888 | |||
| 889 | if (!$_success && !$this->cut) { |
||
| 890 | $this->position = $_position44; |
||
| 891 | |||
| 892 | $_success = $this->parseRAW_STRING(); |
||
| 893 | } |
||
| 894 | |||
| 895 | $this->cut = $_cut45; |
||
| 896 | |||
| 897 | if (!$_success) { |
||
| 898 | break; |
||
| 899 | } |
||
| 900 | |||
| 901 | $_value47[] = $this->value; |
||
| 902 | } |
||
| 903 | |||
| 904 | if (!$this->cut) { |
||
| 905 | $_success = true; |
||
| 906 | $this->position = $_position46; |
||
| 907 | $this->value = $_value47; |
||
| 908 | } |
||
| 909 | |||
| 910 | $this->cut = $_cut48; |
||
| 911 | |||
| 912 | if ($_success) { |
||
| 913 | $string = $this->value; |
||
| 914 | } |
||
| 915 | } |
||
| 916 | |||
| 917 | if ($_success) { |
||
| 918 | $_value49[] = $this->value; |
||
| 919 | |||
| 920 | if (substr($this->string, $this->position, strlen('"')) === '"') { |
||
| 921 | $_success = true; |
||
| 922 | $this->value = substr($this->string, $this->position, strlen('"')); |
||
| 923 | $this->position += strlen('"'); |
||
| 924 | } else { |
||
| 925 | $_success = false; |
||
| 926 | |||
| 927 | $this->report($this->position, '\'"\''); |
||
| 928 | } |
||
| 929 | } |
||
| 930 | |||
| 931 | if ($_success) { |
||
| 932 | $_value49[] = $this->value; |
||
| 933 | |||
| 934 | $this->value = $_value49; |
||
| 935 | } |
||
| 936 | |||
| 937 | if ($_success) { |
||
| 938 | $this->value = call_user_func(function () use (&$string) { |
||
| 939 | return implode($string); |
||
| 940 | }); |
||
| 941 | } |
||
| 942 | |||
| 943 | $this->cache['QUOTED_STRING'][$_position] = array( |
||
| 944 | 'success' => $_success, |
||
| 945 | 'position' => $this->position, |
||
| 946 | 'value' => $this->value |
||
| 947 | ); |
||
| 948 | |||
| 949 | if (!$_success) { |
||
| 950 | $this->report($_position, 'QUOTED_STRING'); |
||
| 951 | } |
||
| 952 | |||
| 953 | return $_success; |
||
| 954 | } |
||
| 955 | |||
| 956 | protected function parseESCAPED_QUOTE() |
||
| 957 | { |
||
| 958 | $_position = $this->position; |
||
| 959 | |||
| 960 | if (isset($this->cache['ESCAPED_QUOTE'][$_position])) { |
||
| 961 | $_success = $this->cache['ESCAPED_QUOTE'][$_position]['success']; |
||
| 962 | $this->position = $this->cache['ESCAPED_QUOTE'][$_position]['position']; |
||
| 963 | $this->value = $this->cache['ESCAPED_QUOTE'][$_position]['value']; |
||
| 964 | |||
| 965 | return $_success; |
||
| 966 | } |
||
| 967 | |||
| 968 | if (substr($this->string, $this->position, strlen('\"')) === '\"') { |
||
| 969 | $_success = true; |
||
| 970 | $this->value = substr($this->string, $this->position, strlen('\"')); |
||
| 971 | $this->position += strlen('\"'); |
||
| 972 | } else { |
||
| 973 | $_success = false; |
||
| 974 | |||
| 975 | $this->report($this->position, '\'\\"\''); |
||
| 976 | } |
||
| 977 | |||
| 978 | if ($_success) { |
||
| 979 | $this->value = call_user_func(function () { |
||
| 980 | return '"'; |
||
| 981 | }); |
||
| 982 | } |
||
| 983 | |||
| 984 | $this->cache['ESCAPED_QUOTE'][$_position] = array( |
||
| 985 | 'success' => $_success, |
||
| 986 | 'position' => $this->position, |
||
| 987 | 'value' => $this->value |
||
| 988 | ); |
||
| 989 | |||
| 990 | if (!$_success) { |
||
| 991 | $this->report($_position, 'ESCAPED_QUOTE'); |
||
| 992 | } |
||
| 993 | |||
| 994 | return $_success; |
||
| 995 | } |
||
| 996 | |||
| 997 | protected function parseRAW_STRING() |
||
| 998 | { |
||
| 999 | $_position = $this->position; |
||
| 1000 | |||
| 1001 | if (isset($this->cache['RAW_STRING'][$_position])) { |
||
| 1002 | $_success = $this->cache['RAW_STRING'][$_position]['success']; |
||
| 1003 | $this->position = $this->cache['RAW_STRING'][$_position]['position']; |
||
| 1004 | $this->value = $this->cache['RAW_STRING'][$_position]['value']; |
||
| 1005 | |||
| 1006 | return $_success; |
||
| 1007 | } |
||
| 1008 | |||
| 1009 | $_position58 = $this->position; |
||
| 1010 | |||
| 1011 | $_value54 = array(); |
||
| 1012 | |||
| 1013 | $_position52 = $this->position; |
||
| 1014 | $_cut53 = $this->cut; |
||
| 1015 | |||
| 1016 | $this->cut = false; |
||
| 1017 | $_position50 = $this->position; |
||
| 1018 | $_cut51 = $this->cut; |
||
| 1019 | |||
| 1020 | $this->cut = false; |
||
| 1021 | if (substr($this->string, $this->position, strlen(' ')) === ' ') { |
||
| 1022 | $_success = true; |
||
| 1023 | $this->value = substr($this->string, $this->position, strlen(' ')); |
||
| 1024 | $this->position += strlen(' '); |
||
| 1025 | } else { |
||
| 1026 | $_success = false; |
||
| 1027 | |||
| 1028 | $this->report($this->position, '\' \''); |
||
| 1029 | } |
||
| 1030 | |||
| 1031 | if (!$_success && !$this->cut) { |
||
| 1032 | $this->position = $_position50; |
||
| 1033 | |||
| 1034 | if (substr($this->string, $this->position, strlen("\r")) === "\r") { |
||
| 1035 | $_success = true; |
||
| 1036 | $this->value = substr($this->string, $this->position, strlen("\r")); |
||
| 1037 | $this->position += strlen("\r"); |
||
| 1038 | } else { |
||
| 1039 | $_success = false; |
||
| 1040 | |||
| 1041 | $this->report($this->position, '"\\r"'); |
||
| 1042 | } |
||
| 1043 | } |
||
| 1044 | |||
| 1045 | if (!$_success && !$this->cut) { |
||
| 1046 | $this->position = $_position50; |
||
| 1047 | |||
| 1048 | if (substr($this->string, $this->position, strlen("\n")) === "\n") { |
||
| 1049 | $_success = true; |
||
| 1050 | $this->value = substr($this->string, $this->position, strlen("\n")); |
||
| 1051 | $this->position += strlen("\n"); |
||
| 1052 | } else { |
||
| 1053 | $_success = false; |
||
| 1054 | |||
| 1055 | $this->report($this->position, '"\\n"'); |
||
| 1056 | } |
||
| 1057 | } |
||
| 1058 | |||
| 1059 | if (!$_success && !$this->cut) { |
||
| 1060 | $this->position = $_position50; |
||
| 1061 | |||
| 1062 | if (substr($this->string, $this->position, strlen("\t")) === "\t") { |
||
| 1063 | $_success = true; |
||
| 1064 | $this->value = substr($this->string, $this->position, strlen("\t")); |
||
| 1065 | $this->position += strlen("\t"); |
||
| 1066 | } else { |
||
| 1067 | $_success = false; |
||
| 1068 | |||
| 1069 | $this->report($this->position, '"\\t"'); |
||
| 1070 | } |
||
| 1071 | } |
||
| 1072 | |||
| 1073 | if (!$_success && !$this->cut) { |
||
| 1074 | $this->position = $_position50; |
||
| 1075 | |||
| 1076 | if (substr($this->string, $this->position, strlen('-->')) === '-->') { |
||
| 1077 | $_success = true; |
||
| 1078 | $this->value = substr($this->string, $this->position, strlen('-->')); |
||
| 1079 | $this->position += strlen('-->'); |
||
| 1080 | } else { |
||
| 1081 | $_success = false; |
||
| 1082 | |||
| 1083 | $this->report($this->position, '\'-->\''); |
||
| 1084 | } |
||
| 1085 | } |
||
| 1086 | |||
| 1087 | if (!$_success && !$this->cut) { |
||
| 1088 | $this->position = $_position50; |
||
| 1089 | |||
| 1090 | if (substr($this->string, $this->position, strlen('"')) === '"') { |
||
| 1091 | $_success = true; |
||
| 1092 | $this->value = substr($this->string, $this->position, strlen('"')); |
||
| 1093 | $this->position += strlen('"'); |
||
| 1094 | } else { |
||
| 1095 | $_success = false; |
||
| 1096 | |||
| 1097 | $this->report($this->position, '\'"\''); |
||
| 1098 | } |
||
| 1099 | } |
||
| 1100 | |||
| 1101 | $this->cut = $_cut51; |
||
| 1102 | |||
| 1103 | if (!$_success) { |
||
| 1104 | $_success = true; |
||
| 1105 | $this->value = null; |
||
| 1106 | } else { |
||
| 1107 | $_success = false; |
||
| 1108 | } |
||
| 1109 | |||
| 1110 | $this->position = $_position52; |
||
| 1111 | $this->cut = $_cut53; |
||
| 1112 | |||
| 1113 | if ($_success) { |
||
| 1114 | $_value54[] = $this->value; |
||
| 1115 | |||
| 1116 | if ($this->position < strlen($this->string)) { |
||
| 1117 | $_success = true; |
||
| 1118 | $this->value = substr($this->string, $this->position, 1); |
||
| 1119 | $this->position += 1; |
||
| 1120 | } else { |
||
| 1121 | $_success = false; |
||
| 1122 | } |
||
| 1123 | } |
||
| 1124 | |||
| 1125 | if ($_success) { |
||
| 1126 | $_value54[] = $this->value; |
||
| 1127 | |||
| 1128 | $this->value = $_value54; |
||
| 1129 | } |
||
| 1130 | |||
| 1131 | if ($_success) { |
||
| 1132 | $_value56 = array($this->value); |
||
| 1133 | $_cut57 = $this->cut; |
||
| 1134 | |||
| 1135 | while (true) { |
||
| 1136 | $_position55 = $this->position; |
||
| 1137 | |||
| 1138 | $this->cut = false; |
||
| 1139 | $_value54 = array(); |
||
| 1140 | |||
| 1141 | $_position52 = $this->position; |
||
| 1142 | $_cut53 = $this->cut; |
||
| 1143 | |||
| 1144 | $this->cut = false; |
||
| 1145 | $_position50 = $this->position; |
||
| 1146 | $_cut51 = $this->cut; |
||
| 1147 | |||
| 1148 | $this->cut = false; |
||
| 1149 | if (substr($this->string, $this->position, strlen(' ')) === ' ') { |
||
| 1150 | $_success = true; |
||
| 1151 | $this->value = substr($this->string, $this->position, strlen(' ')); |
||
| 1152 | $this->position += strlen(' '); |
||
| 1153 | } else { |
||
| 1154 | $_success = false; |
||
| 1155 | |||
| 1156 | $this->report($this->position, '\' \''); |
||
| 1157 | } |
||
| 1158 | |||
| 1159 | if (!$_success && !$this->cut) { |
||
| 1160 | $this->position = $_position50; |
||
| 1161 | |||
| 1162 | if (substr($this->string, $this->position, strlen("\r")) === "\r") { |
||
| 1163 | $_success = true; |
||
| 1164 | $this->value = substr($this->string, $this->position, strlen("\r")); |
||
| 1165 | $this->position += strlen("\r"); |
||
| 1166 | } else { |
||
| 1167 | $_success = false; |
||
| 1168 | |||
| 1169 | $this->report($this->position, '"\\r"'); |
||
| 1170 | } |
||
| 1171 | } |
||
| 1172 | |||
| 1173 | if (!$_success && !$this->cut) { |
||
| 1174 | $this->position = $_position50; |
||
| 1175 | |||
| 1176 | if (substr($this->string, $this->position, strlen("\n")) === "\n") { |
||
| 1177 | $_success = true; |
||
| 1178 | $this->value = substr($this->string, $this->position, strlen("\n")); |
||
| 1179 | $this->position += strlen("\n"); |
||
| 1180 | } else { |
||
| 1181 | $_success = false; |
||
| 1182 | |||
| 1183 | $this->report($this->position, '"\\n"'); |
||
| 1184 | } |
||
| 1185 | } |
||
| 1186 | |||
| 1187 | if (!$_success && !$this->cut) { |
||
| 1188 | $this->position = $_position50; |
||
| 1189 | |||
| 1190 | if (substr($this->string, $this->position, strlen("\t")) === "\t") { |
||
| 1191 | $_success = true; |
||
| 1192 | $this->value = substr($this->string, $this->position, strlen("\t")); |
||
| 1193 | $this->position += strlen("\t"); |
||
| 1194 | } else { |
||
| 1195 | $_success = false; |
||
| 1196 | |||
| 1197 | $this->report($this->position, '"\\t"'); |
||
| 1198 | } |
||
| 1199 | } |
||
| 1200 | |||
| 1201 | if (!$_success && !$this->cut) { |
||
| 1202 | $this->position = $_position50; |
||
| 1203 | |||
| 1204 | if (substr($this->string, $this->position, strlen('-->')) === '-->') { |
||
| 1205 | $_success = true; |
||
| 1206 | $this->value = substr($this->string, $this->position, strlen('-->')); |
||
| 1207 | $this->position += strlen('-->'); |
||
| 1208 | } else { |
||
| 1209 | $_success = false; |
||
| 1210 | |||
| 1211 | $this->report($this->position, '\'-->\''); |
||
| 1212 | } |
||
| 1213 | } |
||
| 1214 | |||
| 1215 | if (!$_success && !$this->cut) { |
||
| 1216 | $this->position = $_position50; |
||
| 1217 | |||
| 1218 | if (substr($this->string, $this->position, strlen('"')) === '"') { |
||
| 1219 | $_success = true; |
||
| 1220 | $this->value = substr($this->string, $this->position, strlen('"')); |
||
| 1221 | $this->position += strlen('"'); |
||
| 1222 | } else { |
||
| 1223 | $_success = false; |
||
| 1224 | |||
| 1225 | $this->report($this->position, '\'"\''); |
||
| 1226 | } |
||
| 1227 | } |
||
| 1228 | |||
| 1229 | $this->cut = $_cut51; |
||
| 1230 | |||
| 1231 | if (!$_success) { |
||
| 1232 | $_success = true; |
||
| 1233 | $this->value = null; |
||
| 1234 | } else { |
||
| 1235 | $_success = false; |
||
| 1236 | } |
||
| 1237 | |||
| 1238 | $this->position = $_position52; |
||
| 1239 | $this->cut = $_cut53; |
||
| 1240 | |||
| 1241 | if ($_success) { |
||
| 1242 | $_value54[] = $this->value; |
||
| 1243 | |||
| 1244 | if ($this->position < strlen($this->string)) { |
||
| 1245 | $_success = true; |
||
| 1246 | $this->value = substr($this->string, $this->position, 1); |
||
| 1247 | $this->position += 1; |
||
| 1248 | } else { |
||
| 1249 | $_success = false; |
||
| 1250 | } |
||
| 1251 | } |
||
| 1252 | |||
| 1253 | if ($_success) { |
||
| 1254 | $_value54[] = $this->value; |
||
| 1255 | |||
| 1256 | $this->value = $_value54; |
||
| 1257 | } |
||
| 1258 | |||
| 1259 | if (!$_success) { |
||
| 1260 | break; |
||
| 1261 | } |
||
| 1262 | |||
| 1263 | $_value56[] = $this->value; |
||
| 1264 | } |
||
| 1265 | |||
| 1266 | if (!$this->cut) { |
||
| 1267 | $_success = true; |
||
| 1268 | $this->position = $_position55; |
||
| 1269 | $this->value = $_value56; |
||
| 1270 | } |
||
| 1271 | |||
| 1272 | $this->cut = $_cut57; |
||
| 1273 | } |
||
| 1274 | |||
| 1275 | if ($_success) { |
||
| 1276 | $this->value = strval(substr($this->string, $_position58, $this->position - $_position58)); |
||
| 1277 | } |
||
| 1278 | |||
| 1279 | $this->cache['RAW_STRING'][$_position] = array( |
||
| 1280 | 'success' => $_success, |
||
| 1281 | 'position' => $this->position, |
||
| 1282 | 'value' => $this->value |
||
| 1283 | ); |
||
| 1284 | |||
| 1285 | if (!$_success) { |
||
| 1286 | $this->report($_position, 'RAW_STRING'); |
||
| 1287 | } |
||
| 1288 | |||
| 1289 | return $_success; |
||
| 1290 | } |
||
| 1291 | |||
| 1292 | protected function parseCODE() |
||
| 1293 | { |
||
| 1294 | $_position = $this->position; |
||
| 1295 | |||
| 1296 | if (isset($this->cache['CODE'][$_position])) { |
||
| 1297 | $_success = $this->cache['CODE'][$_position]['success']; |
||
| 1298 | $this->position = $this->cache['CODE'][$_position]['position']; |
||
| 1299 | $this->value = $this->cache['CODE'][$_position]['value']; |
||
| 1300 | |||
| 1301 | return $_success; |
||
| 1302 | } |
||
| 1303 | |||
| 1304 | $_value66 = array(); |
||
| 1305 | |||
| 1306 | $_success = $this->parseCODE_START(); |
||
| 1307 | |||
| 1308 | if ($_success) { |
||
| 1309 | $_value66[] = $this->value; |
||
| 1310 | |||
| 1311 | $_position65 = $this->position; |
||
| 1312 | |||
| 1313 | $_value63 = array(); |
||
| 1314 | $_cut64 = $this->cut; |
||
| 1315 | |||
| 1316 | while (true) { |
||
| 1317 | $_position62 = $this->position; |
||
| 1318 | |||
| 1319 | $this->cut = false; |
||
| 1320 | $_value61 = array(); |
||
| 1321 | |||
| 1322 | $_position59 = $this->position; |
||
| 1323 | $_cut60 = $this->cut; |
||
| 1324 | |||
| 1325 | $this->cut = false; |
||
| 1326 | $_success = $this->parseCODE_END(); |
||
| 1327 | |||
| 1328 | if (!$_success) { |
||
| 1329 | $_success = true; |
||
| 1330 | $this->value = null; |
||
| 1331 | } else { |
||
| 1332 | $_success = false; |
||
| 1333 | } |
||
| 1334 | |||
| 1335 | $this->position = $_position59; |
||
| 1336 | $this->cut = $_cut60; |
||
| 1337 | |||
| 1338 | if ($_success) { |
||
| 1339 | $_value61[] = $this->value; |
||
| 1340 | |||
| 1341 | if ($this->position < strlen($this->string)) { |
||
| 1342 | $_success = true; |
||
| 1343 | $this->value = substr($this->string, $this->position, 1); |
||
| 1344 | $this->position += 1; |
||
| 1345 | } else { |
||
| 1346 | $_success = false; |
||
| 1347 | } |
||
| 1348 | } |
||
| 1349 | |||
| 1350 | if ($_success) { |
||
| 1351 | $_value61[] = $this->value; |
||
| 1352 | |||
| 1353 | $this->value = $_value61; |
||
| 1354 | } |
||
| 1355 | |||
| 1356 | if (!$_success) { |
||
| 1357 | break; |
||
| 1358 | } |
||
| 1359 | |||
| 1360 | $_value63[] = $this->value; |
||
| 1361 | } |
||
| 1362 | |||
| 1363 | if (!$this->cut) { |
||
| 1364 | $_success = true; |
||
| 1365 | $this->position = $_position62; |
||
| 1366 | $this->value = $_value63; |
||
| 1367 | } |
||
| 1368 | |||
| 1369 | $this->cut = $_cut64; |
||
| 1370 | |||
| 1371 | if ($_success) { |
||
| 1372 | $this->value = strval(substr($this->string, $_position65, $this->position - $_position65)); |
||
| 1373 | } |
||
| 1374 | |||
| 1375 | if ($_success) { |
||
| 1376 | $code = $this->value; |
||
| 1377 | } |
||
| 1378 | } |
||
| 1379 | |||
| 1380 | if ($_success) { |
||
| 1381 | $_value66[] = $this->value; |
||
| 1382 | |||
| 1383 | $_success = $this->parseCODE_END(); |
||
| 1384 | } |
||
| 1385 | |||
| 1386 | if ($_success) { |
||
| 1387 | $_value66[] = $this->value; |
||
| 1388 | |||
| 1389 | $this->value = $_value66; |
||
| 1390 | } |
||
| 1391 | |||
| 1392 | if ($_success) { |
||
| 1393 | $this->value = call_user_func(function () use (&$code) { |
||
| 1394 | return $code; |
||
| 1395 | }); |
||
| 1396 | } |
||
| 1397 | |||
| 1398 | $this->cache['CODE'][$_position] = array( |
||
| 1399 | 'success' => $_success, |
||
| 1400 | 'position' => $this->position, |
||
| 1401 | 'value' => $this->value |
||
| 1402 | ); |
||
| 1403 | |||
| 1404 | if (!$_success) { |
||
| 1405 | $this->report($_position, 'CODE'); |
||
| 1406 | } |
||
| 1407 | |||
| 1408 | return $_success; |
||
| 1409 | } |
||
| 1410 | |||
| 1411 | protected function parseCODE_START() |
||
| 1412 | { |
||
| 1413 | $_position = $this->position; |
||
| 1414 | |||
| 1415 | if (isset($this->cache['CODE_START'][$_position])) { |
||
| 1416 | $_success = $this->cache['CODE_START'][$_position]['success']; |
||
| 1417 | $this->position = $this->cache['CODE_START'][$_position]['position']; |
||
| 1418 | $this->value = $this->cache['CODE_START'][$_position]['value']; |
||
| 1419 | |||
| 1420 | return $_success; |
||
| 1421 | } |
||
| 1422 | |||
| 1423 | $_value67 = array(); |
||
| 1424 | |||
| 1425 | if (strtolower(substr($this->string, $this->position, strlen('```php'))) === strtolower('```php')) { |
||
| 1426 | $_success = true; |
||
| 1427 | $this->value = substr($this->string, $this->position, strlen('```php')); |
||
| 1428 | $this->position += strlen('```php'); |
||
| 1429 | } else { |
||
| 1430 | $_success = false; |
||
| 1431 | |||
| 1432 | $this->report($this->position, '\'```php\''); |
||
| 1433 | } |
||
| 1434 | |||
| 1435 | if ($_success) { |
||
| 1436 | $_value67[] = $this->value; |
||
| 1437 | |||
| 1438 | $_success = $this->parseEOL(); |
||
| 1439 | } |
||
| 1440 | |||
| 1441 | if ($_success) { |
||
| 1442 | $_value67[] = $this->value; |
||
| 1443 | |||
| 1444 | $this->value = $_value67; |
||
| 1445 | } |
||
| 1446 | |||
| 1447 | $this->cache['CODE_START'][$_position] = array( |
||
| 1448 | 'success' => $_success, |
||
| 1449 | 'position' => $this->position, |
||
| 1450 | 'value' => $this->value |
||
| 1451 | ); |
||
| 1452 | |||
| 1453 | if (!$_success) { |
||
| 1454 | $this->report($_position, 'CODE_START'); |
||
| 1455 | } |
||
| 1456 | |||
| 1457 | return $_success; |
||
| 1458 | } |
||
| 1459 | |||
| 1460 | protected function parseCODE_END() |
||
| 1461 | { |
||
| 1462 | $_position = $this->position; |
||
| 1463 | |||
| 1464 | if (isset($this->cache['CODE_END'][$_position])) { |
||
| 1465 | $_success = $this->cache['CODE_END'][$_position]['success']; |
||
| 1466 | $this->position = $this->cache['CODE_END'][$_position]['position']; |
||
| 1467 | $this->value = $this->cache['CODE_END'][$_position]['value']; |
||
| 1468 | |||
| 1469 | return $_success; |
||
| 1470 | } |
||
| 1471 | |||
| 1472 | $_value70 = array(); |
||
| 1473 | |||
| 1474 | if (substr($this->string, $this->position, strlen('```')) === '```') { |
||
| 1475 | $_success = true; |
||
| 1476 | $this->value = substr($this->string, $this->position, strlen('```')); |
||
| 1477 | $this->position += strlen('```'); |
||
| 1478 | } else { |
||
| 1479 | $_success = false; |
||
| 1480 | |||
| 1481 | $this->report($this->position, '\'```\''); |
||
| 1482 | } |
||
| 1483 | |||
| 1484 | if ($_success) { |
||
| 1485 | $_value70[] = $this->value; |
||
| 1486 | |||
| 1487 | $_position68 = $this->position; |
||
| 1488 | $_cut69 = $this->cut; |
||
| 1489 | |||
| 1490 | $this->cut = false; |
||
| 1491 | $_success = $this->parseEOL(); |
||
| 1492 | |||
| 1493 | if (!$_success && !$this->cut) { |
||
| 1494 | $this->position = $_position68; |
||
| 1495 | |||
| 1496 | $_success = $this->parseEOF(); |
||
| 1497 | } |
||
| 1498 | |||
| 1499 | $this->cut = $_cut69; |
||
| 1500 | } |
||
| 1501 | |||
| 1502 | if ($_success) { |
||
| 1503 | $_value70[] = $this->value; |
||
| 1504 | |||
| 1505 | $this->value = $_value70; |
||
| 1506 | } |
||
| 1507 | |||
| 1508 | $this->cache['CODE_END'][$_position] = array( |
||
| 1509 | 'success' => $_success, |
||
| 1510 | 'position' => $this->position, |
||
| 1511 | 'value' => $this->value |
||
| 1512 | ); |
||
| 1513 | |||
| 1514 | if (!$_success) { |
||
| 1515 | $this->report($_position, 'CODE_END'); |
||
| 1516 | } |
||
| 1517 | |||
| 1518 | return $_success; |
||
| 1519 | } |
||
| 1520 | |||
| 1521 | protected function parseEOL() |
||
| 1522 | { |
||
| 1523 | $_position = $this->position; |
||
| 1524 | |||
| 1525 | if (isset($this->cache['EOL'][$_position])) { |
||
| 1526 | $_success = $this->cache['EOL'][$_position]['success']; |
||
| 1527 | $this->position = $this->cache['EOL'][$_position]['position']; |
||
| 1528 | $this->value = $this->cache['EOL'][$_position]['value']; |
||
| 1529 | |||
| 1530 | return $_success; |
||
| 1531 | } |
||
| 1532 | |||
| 1533 | $_value73 = array(); |
||
| 1534 | |||
| 1535 | $_success = $this->parse_(); |
||
| 1536 | |||
| 1537 | if ($_success) { |
||
| 1538 | $_value73[] = $this->value; |
||
| 1539 | |||
| 1540 | $_position71 = $this->position; |
||
| 1541 | $_cut72 = $this->cut; |
||
| 1542 | |||
| 1543 | $this->cut = false; |
||
| 1544 | if (substr($this->string, $this->position, strlen("\r")) === "\r") { |
||
| 1545 | $_success = true; |
||
| 1546 | $this->value = substr($this->string, $this->position, strlen("\r")); |
||
| 1547 | $this->position += strlen("\r"); |
||
| 1548 | } else { |
||
| 1549 | $_success = false; |
||
| 1550 | |||
| 1551 | $this->report($this->position, '"\\r"'); |
||
| 1552 | } |
||
| 1553 | |||
| 1554 | if (!$_success && !$this->cut) { |
||
| 1555 | $_success = true; |
||
| 1556 | $this->position = $_position71; |
||
| 1557 | $this->value = null; |
||
| 1558 | } |
||
| 1559 | |||
| 1560 | $this->cut = $_cut72; |
||
| 1561 | } |
||
| 1562 | |||
| 1563 | if ($_success) { |
||
| 1564 | $_value73[] = $this->value; |
||
| 1565 | |||
| 1566 | if (substr($this->string, $this->position, strlen("\n")) === "\n") { |
||
| 1567 | $_success = true; |
||
| 1568 | $this->value = substr($this->string, $this->position, strlen("\n")); |
||
| 1569 | $this->position += strlen("\n"); |
||
| 1570 | } else { |
||
| 1571 | $_success = false; |
||
| 1572 | |||
| 1573 | $this->report($this->position, '"\\n"'); |
||
| 1574 | } |
||
| 1575 | } |
||
| 1576 | |||
| 1577 | if ($_success) { |
||
| 1578 | $_value73[] = $this->value; |
||
| 1579 | |||
| 1580 | $this->value = $_value73; |
||
| 1581 | } |
||
| 1582 | |||
| 1583 | $this->cache['EOL'][$_position] = array( |
||
| 1584 | 'success' => $_success, |
||
| 1585 | 'position' => $this->position, |
||
| 1586 | 'value' => $this->value |
||
| 1587 | ); |
||
| 1588 | |||
| 1589 | if (!$_success) { |
||
| 1590 | $this->report($_position, "END_OF_LINE"); |
||
| 1591 | } |
||
| 1592 | |||
| 1593 | return $_success; |
||
| 1594 | } |
||
| 1595 | |||
| 1596 | protected function parseEOF() |
||
| 1597 | { |
||
| 1598 | $_position = $this->position; |
||
| 1599 | |||
| 1600 | if (isset($this->cache['EOF'][$_position])) { |
||
| 1601 | $_success = $this->cache['EOF'][$_position]['success']; |
||
| 1602 | $this->position = $this->cache['EOF'][$_position]['position']; |
||
| 1603 | $this->value = $this->cache['EOF'][$_position]['value']; |
||
| 1604 | |||
| 1605 | return $_success; |
||
| 1606 | } |
||
| 1607 | |||
| 1608 | $_position74 = $this->position; |
||
| 1609 | $_cut75 = $this->cut; |
||
| 1610 | |||
| 1611 | $this->cut = false; |
||
| 1612 | if ($this->position < strlen($this->string)) { |
||
| 1613 | $_success = true; |
||
| 1614 | $this->value = substr($this->string, $this->position, 1); |
||
| 1615 | $this->position += 1; |
||
| 1616 | } else { |
||
| 1617 | $_success = false; |
||
| 1618 | } |
||
| 1619 | |||
| 1620 | if (!$_success) { |
||
| 1621 | $_success = true; |
||
| 1622 | $this->value = null; |
||
| 1623 | } else { |
||
| 1624 | $_success = false; |
||
| 1625 | } |
||
| 1626 | |||
| 1627 | $this->position = $_position74; |
||
| 1628 | $this->cut = $_cut75; |
||
| 1629 | |||
| 1630 | $this->cache['EOF'][$_position] = array( |
||
| 1631 | 'success' => $_success, |
||
| 1632 | 'position' => $this->position, |
||
| 1633 | 'value' => $this->value |
||
| 1634 | ); |
||
| 1635 | |||
| 1636 | if (!$_success) { |
||
| 1637 | $this->report($_position, "END_OF_FILE"); |
||
| 1638 | } |
||
| 1639 | |||
| 1640 | return $_success; |
||
| 1641 | } |
||
| 1642 | |||
| 1643 | protected function parse_() |
||
| 1644 | { |
||
| 1645 | $_position = $this->position; |
||
| 1646 | |||
| 1647 | if (isset($this->cache['_'][$_position])) { |
||
| 1648 | $_success = $this->cache['_'][$_position]['success']; |
||
| 1649 | $this->position = $this->cache['_'][$_position]['position']; |
||
| 1650 | $this->value = $this->cache['_'][$_position]['value']; |
||
| 1651 | |||
| 1652 | return $_success; |
||
| 1653 | } |
||
| 1654 | |||
| 1655 | $_value79 = array(); |
||
| 1656 | $_cut80 = $this->cut; |
||
| 1657 | |||
| 1658 | while (true) { |
||
| 1659 | $_position78 = $this->position; |
||
| 1660 | |||
| 1661 | $this->cut = false; |
||
| 1662 | $_position76 = $this->position; |
||
| 1663 | $_cut77 = $this->cut; |
||
| 1664 | |||
| 1665 | $this->cut = false; |
||
| 1666 | if (substr($this->string, $this->position, strlen(" ")) === " ") { |
||
| 1667 | $_success = true; |
||
| 1668 | $this->value = substr($this->string, $this->position, strlen(" ")); |
||
| 1669 | $this->position += strlen(" "); |
||
| 1670 | } else { |
||
| 1671 | $_success = false; |
||
| 1672 | |||
| 1673 | $this->report($this->position, '" "'); |
||
| 1674 | } |
||
| 1675 | |||
| 1676 | if (!$_success && !$this->cut) { |
||
| 1677 | $this->position = $_position76; |
||
| 1678 | |||
| 1679 | if (substr($this->string, $this->position, strlen("\t")) === "\t") { |
||
| 1680 | $_success = true; |
||
| 1681 | $this->value = substr($this->string, $this->position, strlen("\t")); |
||
| 1682 | $this->position += strlen("\t"); |
||
| 1683 | } else { |
||
| 1684 | $_success = false; |
||
| 1685 | |||
| 1686 | $this->report($this->position, '"\\t"'); |
||
| 1687 | } |
||
| 1688 | } |
||
| 1689 | |||
| 1690 | $this->cut = $_cut77; |
||
| 1691 | |||
| 1692 | if (!$_success) { |
||
| 1693 | break; |
||
| 1694 | } |
||
| 1695 | |||
| 1696 | $_value79[] = $this->value; |
||
| 1697 | } |
||
| 1698 | |||
| 1699 | if (!$this->cut) { |
||
| 1700 | $_success = true; |
||
| 1701 | $this->position = $_position78; |
||
| 1702 | $this->value = $_value79; |
||
| 1703 | } |
||
| 1704 | |||
| 1705 | $this->cut = $_cut80; |
||
| 1706 | |||
| 1707 | $this->cache['_'][$_position] = array( |
||
| 1708 | 'success' => $_success, |
||
| 1709 | 'position' => $this->position, |
||
| 1710 | 'value' => $this->value |
||
| 1711 | ); |
||
| 1712 | |||
| 1713 | if (!$_success) { |
||
| 1714 | $this->report($_position, '_'); |
||
| 1715 | } |
||
| 1716 | |||
| 1717 | return $_success; |
||
| 1718 | } |
||
| 1719 | |||
| 1720 | private function line() |
||
| 1721 | { |
||
| 1722 | if (!empty($this->errors)) { |
||
| 1723 | $positions = array_keys($this->errors); |
||
| 1724 | } else { |
||
| 1725 | $positions = array_keys($this->warnings); |
||
| 1726 | } |
||
| 1727 | |||
| 1728 | return count(explode("\n", substr($this->string, 0, max($positions)))); |
||
| 1729 | } |
||
| 1730 | |||
| 1731 | private function rest() |
||
| 1732 | { |
||
| 1733 | return '"' . substr($this->string, $this->position) . '"'; |
||
| 1734 | } |
||
| 1735 | |||
| 1736 | protected function report($position, $expecting) |
||
| 1737 | { |
||
| 1738 | if ($this->cut) { |
||
| 1739 | $this->errors[$position][] = $expecting; |
||
| 1740 | } else { |
||
| 1741 | $this->warnings[$position][] = $expecting; |
||
| 1742 | } |
||
| 1743 | } |
||
| 1744 | |||
| 1745 | private function expecting() |
||
| 1746 | { |
||
| 1747 | if (!empty($this->errors)) { |
||
| 1748 | ksort($this->errors); |
||
| 1749 | |||
| 1750 | return end($this->errors)[0]; |
||
| 1751 | } |
||
| 1752 | |||
| 1753 | ksort($this->warnings); |
||
| 1754 | |||
| 1755 | return implode(', ', end($this->warnings)); |
||
| 1756 | } |
||
| 1757 | |||
| 1758 | public function parse($_string) |
||
| 1759 | { |
||
| 1760 | $this->string = $_string; |
||
| 1761 | $this->position = 0; |
||
| 1762 | $this->value = null; |
||
| 1763 | $this->cache = array(); |
||
| 1764 | $this->cut = false; |
||
| 1765 | $this->errors = array(); |
||
| 1766 | $this->warnings = array(); |
||
| 1767 | |||
| 1768 | $_success = $this->parseFILE(); |
||
| 1769 | |||
| 1770 | if ($_success && $this->position < strlen($this->string)) { |
||
| 1771 | $_success = false; |
||
| 1772 | |||
| 1773 | $this->report($this->position, "end of file"); |
||
| 1774 | } |
||
| 1775 | |||
| 1776 | if (!$_success) { |
||
| 1777 | throw new \InvalidArgumentException("Syntax error, expecting {$this->expecting()} on line {$this->line()}"); |
||
| 1778 | } |
||
| 1779 | |||
| 1780 | return $this->value; |
||
| 1781 | } |
||
| 1782 | } |