smarty_internal_configfilelexer.php (22461B)
1 <?php 2 /** 3 * Smarty Internal Plugin Configfilelexer 4 * 5 * This is the lexer to break the config file source into tokens 6 * 7 * @package Smarty 8 * @subpackage Config 9 * @author Uwe Tews 10 */ 11 12 /** 13 * Smarty_Internal_Configfilelexer 14 * 15 * This is the config file lexer. 16 * It is generated from the smarty_internal_configfilelexer.plex file 17 * 18 * @package Smarty 19 * @subpackage Compiler 20 * @author Uwe Tews 21 */ 22 class Smarty_Internal_Configfilelexer 23 { 24 /** 25 * Source 26 * 27 * @var string 28 */ 29 public $data; 30 31 /** 32 * byte counter 33 * 34 * @var int 35 */ 36 public $counter; 37 38 /** 39 * token number 40 * 41 * @var int 42 */ 43 public $token; 44 45 /** 46 * token value 47 * 48 * @var string 49 */ 50 public $value; 51 52 /** 53 * current line 54 * 55 * @var int 56 */ 57 public $line; 58 59 /** 60 * state number 61 * 62 * @var int 63 */ 64 public $state = 1; 65 66 /** 67 * Smarty object 68 * 69 * @var Smarty 70 */ 71 public $smarty = null; 72 73 /** 74 * compiler object 75 * 76 * @var Smarty_Internal_Config_File_Compiler 77 */ 78 private $compiler = null; 79 80 /** 81 * copy of config_booleanize 82 * 83 * @var bool 84 */ 85 private $configBooleanize = false; 86 87 /** 88 * trace file 89 * 90 * @var resource 91 */ 92 public $yyTraceFILE; 93 94 /** 95 * trace prompt 96 * 97 * @var string 98 */ 99 public $yyTracePrompt; 100 101 /** 102 * state names 103 * 104 * @var array 105 */ 106 public $state_name = array(1 => 'START', 2 => 'VALUE', 3 => 'NAKED_STRING_VALUE', 4 => 'COMMENT', 5 => 'SECTION', 107 6 => 'TRIPPLE'); 108 109 /** 110 * storage for assembled token patterns 111 * 112 * @var sring 113 */ 114 private $yy_global_pattern1 = null; 115 116 private $yy_global_pattern2 = null; 117 118 private $yy_global_pattern3 = null; 119 120 private $yy_global_pattern4 = null; 121 122 private $yy_global_pattern5 = null; 123 124 private $yy_global_pattern6 = null; 125 126 /** 127 * token names 128 * 129 * @var array 130 */ 131 public $smarty_token_names = array( // Text for parser error messages 132 ); 133 134 /** 135 * constructor 136 * 137 * @param string $data template source 138 * @param Smarty_Internal_Config_File_Compiler $compiler 139 */ 140 function __construct($data, Smarty_Internal_Config_File_Compiler $compiler) 141 { 142 // set instance object 143 self::instance($this); 144 $this->data = $data . "\n"; //now all lines are \n-terminated 145 $this->counter = 0; 146 if (preg_match('/^\xEF\xBB\xBF/', $this->data, $match)) { 147 $this->counter += strlen($match[0]); 148 } 149 $this->line = 1; 150 $this->compiler = $compiler; 151 $this->smarty = $compiler->smarty; 152 $this->configBooleanize = $this->smarty->config_booleanize; 153 } 154 155 public static function &instance($new_instance = null) 156 { 157 static $instance = null; 158 if (isset($new_instance) && is_object($new_instance)) { 159 $instance = $new_instance; 160 } 161 return $instance; 162 } 163 164 public function PrintTrace() 165 { 166 $this->yyTraceFILE = fopen('php://output', 'w'); 167 $this->yyTracePrompt = '<br>'; 168 } 169 170 private $_yy_state = 1; 171 172 private $_yy_stack = array(); 173 174 public function yylex() 175 { 176 return $this->{'yylex' . $this->_yy_state}(); 177 } 178 179 public function yypushstate($state) 180 { 181 if ($this->yyTraceFILE) { 182 fprintf($this->yyTraceFILE, "%sState push %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); 183 } 184 array_push($this->_yy_stack, $this->_yy_state); 185 $this->_yy_state = $state; 186 if ($this->yyTraceFILE) { 187 fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); 188 } 189 } 190 191 public function yypopstate() 192 { 193 if ($this->yyTraceFILE) { 194 fprintf($this->yyTraceFILE, "%sState pop %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); 195 } 196 $this->_yy_state = array_pop($this->_yy_stack); 197 if ($this->yyTraceFILE) { 198 fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); 199 } 200 } 201 202 public function yybegin($state) 203 { 204 $this->_yy_state = $state; 205 if ($this->yyTraceFILE) { 206 fprintf($this->yyTraceFILE, "%sState set %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); 207 } 208 } 209 210 public function yylex1() 211 { 212 if (!isset($this->yy_global_pattern1)) { 213 $this->yy_global_pattern1 = "/\G(#|;)|\G(\\[)|\G(\\])|\G(=)|\G([ \t\r]+)|\G(\n)|\G([0-9]*[a-zA-Z_]\\w*)|\G([\S\s])/isS"; 214 } 215 if ($this->counter >= strlen($this->data)) { 216 return false; // end of input 217 } 218 219 do { 220 if (preg_match($this->yy_global_pattern1, $this->data, $yymatches, null, $this->counter)) { 221 $yysubmatches = $yymatches; 222 if (strlen($yysubmatches[0]) < 200) { 223 $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); 224 } else { 225 $yymatches = array_filter($yymatches, 'strlen'); 226 } 227 if (empty($yymatches)) { 228 throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data, $this->counter, 5) . '... state START'); 229 } 230 next($yymatches); // skip global match 231 $this->token = key($yymatches); // token number 232 $this->value = current($yymatches); // token value 233 $r = $this->{'yy_r1_' . $this->token}(); 234 if ($r === null) { 235 $this->counter += strlen($this->value); 236 $this->line += substr_count($this->value, "\n"); 237 // accept this token 238 return true; 239 } elseif ($r === true) { 240 // we have changed state 241 // process this token in the new state 242 return $this->yylex(); 243 } elseif ($r === false) { 244 $this->counter += strlen($this->value); 245 $this->line += substr_count($this->value, "\n"); 246 if ($this->counter >= strlen($this->data)) { 247 return false; // end of input 248 } 249 // skip this token 250 continue; 251 } 252 } else { 253 throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[$this->counter]); 254 } 255 break; 256 } while (true); 257 } // end function 258 259 const START = 1; 260 261 function yy_r1_1() 262 { 263 264 $this->token = Smarty_Internal_Configfileparser::TPC_COMMENTSTART; 265 $this->yypushstate(self::COMMENT); 266 } 267 268 function yy_r1_2() 269 { 270 271 $this->token = Smarty_Internal_Configfileparser::TPC_OPENB; 272 $this->yypushstate(self::SECTION); 273 } 274 275 function yy_r1_3() 276 { 277 278 $this->token = Smarty_Internal_Configfileparser::TPC_CLOSEB; 279 } 280 281 function yy_r1_4() 282 { 283 284 $this->token = Smarty_Internal_Configfileparser::TPC_EQUAL; 285 $this->yypushstate(self::VALUE); 286 } 287 288 function yy_r1_5() 289 { 290 291 return false; 292 } 293 294 function yy_r1_6() 295 { 296 297 $this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE; 298 } 299 300 function yy_r1_7() 301 { 302 303 $this->token = Smarty_Internal_Configfileparser::TPC_ID; 304 } 305 306 function yy_r1_8() 307 { 308 309 $this->token = Smarty_Internal_Configfileparser::TPC_OTHER; 310 } 311 312 public function yylex2() 313 { 314 if (!isset($this->yy_global_pattern2)) { 315 $this->yy_global_pattern2 = "/\G([ \t\r]+)|\G(\\d+\\.\\d+(?=[ \t\r]*[\n#;]))|\G(\\d+(?=[ \t\r]*[\n#;]))|\G(\"\"\")|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*'(?=[ \t\r]*[\n#;]))|\G(\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"(?=[ \t\r]*[\n#;]))|\G([a-zA-Z]+(?=[ \t\r]*[\n#;]))|\G([^\n]+?(?=[ \t\r]*\n))|\G(\n)/isS"; 316 } 317 if ($this->counter >= strlen($this->data)) { 318 return false; // end of input 319 } 320 321 do { 322 if (preg_match($this->yy_global_pattern2, $this->data, $yymatches, null, $this->counter)) { 323 $yysubmatches = $yymatches; 324 if (strlen($yysubmatches[0]) < 200) { 325 $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); 326 } else { 327 $yymatches = array_filter($yymatches, 'strlen'); 328 } 329 if (empty($yymatches)) { 330 throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data, $this->counter, 5) . '... state VALUE'); 331 } 332 next($yymatches); // skip global match 333 $this->token = key($yymatches); // token number 334 $this->value = current($yymatches); // token value 335 $r = $this->{'yy_r2_' . $this->token}(); 336 if ($r === null) { 337 $this->counter += strlen($this->value); 338 $this->line += substr_count($this->value, "\n"); 339 // accept this token 340 return true; 341 } elseif ($r === true) { 342 // we have changed state 343 // process this token in the new state 344 return $this->yylex(); 345 } elseif ($r === false) { 346 $this->counter += strlen($this->value); 347 $this->line += substr_count($this->value, "\n"); 348 if ($this->counter >= strlen($this->data)) { 349 return false; // end of input 350 } 351 // skip this token 352 continue; 353 } 354 } else { 355 throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[$this->counter]); 356 } 357 break; 358 } while (true); 359 } // end function 360 361 const VALUE = 2; 362 363 function yy_r2_1() 364 { 365 366 return false; 367 } 368 369 function yy_r2_2() 370 { 371 372 $this->token = Smarty_Internal_Configfileparser::TPC_FLOAT; 373 $this->yypopstate(); 374 } 375 376 function yy_r2_3() 377 { 378 379 $this->token = Smarty_Internal_Configfileparser::TPC_INT; 380 $this->yypopstate(); 381 } 382 383 function yy_r2_4() 384 { 385 386 $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES; 387 $this->yypushstate(self::TRIPPLE); 388 } 389 390 function yy_r2_5() 391 { 392 393 $this->token = Smarty_Internal_Configfileparser::TPC_SINGLE_QUOTED_STRING; 394 $this->yypopstate(); 395 } 396 397 function yy_r2_6() 398 { 399 400 $this->token = Smarty_Internal_Configfileparser::TPC_DOUBLE_QUOTED_STRING; 401 $this->yypopstate(); 402 } 403 404 function yy_r2_7() 405 { 406 407 if (!$this->configBooleanize || !in_array(strtolower($this->value), Array("true", "false", "on", "off", "yes", 408 "no")) 409 ) { 410 $this->yypopstate(); 411 $this->yypushstate(self::NAKED_STRING_VALUE); 412 return true; //reprocess in new state 413 } else { 414 $this->token = Smarty_Internal_Configfileparser::TPC_BOOL; 415 $this->yypopstate(); 416 } 417 } 418 419 function yy_r2_8() 420 { 421 422 $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING; 423 $this->yypopstate(); 424 } 425 426 function yy_r2_9() 427 { 428 429 $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING; 430 $this->value = ""; 431 $this->yypopstate(); 432 } 433 434 public function yylex3() 435 { 436 if (!isset($this->yy_global_pattern3)) { 437 $this->yy_global_pattern3 = "/\G([^\n]+?(?=[ \t\r]*\n))/isS"; 438 } 439 if ($this->counter >= strlen($this->data)) { 440 return false; // end of input 441 } 442 443 do { 444 if (preg_match($this->yy_global_pattern3, $this->data, $yymatches, null, $this->counter)) { 445 $yysubmatches = $yymatches; 446 if (strlen($yysubmatches[0]) < 200) { 447 $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); 448 } else { 449 $yymatches = array_filter($yymatches, 'strlen'); 450 } 451 if (empty($yymatches)) { 452 throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data, $this->counter, 5) . '... state NAKED_STRING_VALUE'); 453 } 454 next($yymatches); // skip global match 455 $this->token = key($yymatches); // token number 456 $this->value = current($yymatches); // token value 457 $r = $this->{'yy_r3_' . $this->token}(); 458 if ($r === null) { 459 $this->counter += strlen($this->value); 460 $this->line += substr_count($this->value, "\n"); 461 // accept this token 462 return true; 463 } elseif ($r === true) { 464 // we have changed state 465 // process this token in the new state 466 return $this->yylex(); 467 } elseif ($r === false) { 468 $this->counter += strlen($this->value); 469 $this->line += substr_count($this->value, "\n"); 470 if ($this->counter >= strlen($this->data)) { 471 return false; // end of input 472 } 473 // skip this token 474 continue; 475 } 476 } else { 477 throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[$this->counter]); 478 } 479 break; 480 } while (true); 481 } // end function 482 483 const NAKED_STRING_VALUE = 3; 484 485 function yy_r3_1() 486 { 487 488 $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING; 489 $this->yypopstate(); 490 } 491 492 public function yylex4() 493 { 494 if (!isset($this->yy_global_pattern4)) { 495 $this->yy_global_pattern4 = "/\G([ \t\r]+)|\G([^\n]+?(?=[ \t\r]*\n))|\G(\n)/isS"; 496 } 497 if ($this->counter >= strlen($this->data)) { 498 return false; // end of input 499 } 500 501 do { 502 if (preg_match($this->yy_global_pattern4, $this->data, $yymatches, null, $this->counter)) { 503 $yysubmatches = $yymatches; 504 if (strlen($yysubmatches[0]) < 200) { 505 $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); 506 } else { 507 $yymatches = array_filter($yymatches, 'strlen'); 508 } 509 if (empty($yymatches)) { 510 throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data, $this->counter, 5) . '... state COMMENT'); 511 } 512 next($yymatches); // skip global match 513 $this->token = key($yymatches); // token number 514 $this->value = current($yymatches); // token value 515 $r = $this->{'yy_r4_' . $this->token}(); 516 if ($r === null) { 517 $this->counter += strlen($this->value); 518 $this->line += substr_count($this->value, "\n"); 519 // accept this token 520 return true; 521 } elseif ($r === true) { 522 // we have changed state 523 // process this token in the new state 524 return $this->yylex(); 525 } elseif ($r === false) { 526 $this->counter += strlen($this->value); 527 $this->line += substr_count($this->value, "\n"); 528 if ($this->counter >= strlen($this->data)) { 529 return false; // end of input 530 } 531 // skip this token 532 continue; 533 } 534 } else { 535 throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[$this->counter]); 536 } 537 break; 538 } while (true); 539 } // end function 540 541 const COMMENT = 4; 542 543 function yy_r4_1() 544 { 545 546 return false; 547 } 548 549 function yy_r4_2() 550 { 551 552 $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING; 553 } 554 555 function yy_r4_3() 556 { 557 558 $this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE; 559 $this->yypopstate(); 560 } 561 562 public function yylex5() 563 { 564 if (!isset($this->yy_global_pattern5)) { 565 $this->yy_global_pattern5 = "/\G(\\.)|\G(.*?(?=[\.=[\]\r\n]))/isS"; 566 } 567 if ($this->counter >= strlen($this->data)) { 568 return false; // end of input 569 } 570 571 do { 572 if (preg_match($this->yy_global_pattern5, $this->data, $yymatches, null, $this->counter)) { 573 $yysubmatches = $yymatches; 574 if (strlen($yysubmatches[0]) < 200) { 575 $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); 576 } else { 577 $yymatches = array_filter($yymatches, 'strlen'); 578 } 579 if (empty($yymatches)) { 580 throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data, $this->counter, 5) . '... state SECTION'); 581 } 582 next($yymatches); // skip global match 583 $this->token = key($yymatches); // token number 584 $this->value = current($yymatches); // token value 585 $r = $this->{'yy_r5_' . $this->token}(); 586 if ($r === null) { 587 $this->counter += strlen($this->value); 588 $this->line += substr_count($this->value, "\n"); 589 // accept this token 590 return true; 591 } elseif ($r === true) { 592 // we have changed state 593 // process this token in the new state 594 return $this->yylex(); 595 } elseif ($r === false) { 596 $this->counter += strlen($this->value); 597 $this->line += substr_count($this->value, "\n"); 598 if ($this->counter >= strlen($this->data)) { 599 return false; // end of input 600 } 601 // skip this token 602 continue; 603 } 604 } else { 605 throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[$this->counter]); 606 } 607 break; 608 } while (true); 609 } // end function 610 611 const SECTION = 5; 612 613 function yy_r5_1() 614 { 615 616 $this->token = Smarty_Internal_Configfileparser::TPC_DOT; 617 } 618 619 function yy_r5_2() 620 { 621 622 $this->token = Smarty_Internal_Configfileparser::TPC_SECTION; 623 $this->yypopstate(); 624 } 625 626 public function yylex6() 627 { 628 if (!isset($this->yy_global_pattern6)) { 629 $this->yy_global_pattern6 = "/\G(\"\"\"(?=[ \t\r]*[\n#;]))|\G([\S\s])/isS"; 630 } 631 if ($this->counter >= strlen($this->data)) { 632 return false; // end of input 633 } 634 635 do { 636 if (preg_match($this->yy_global_pattern6, $this->data, $yymatches, null, $this->counter)) { 637 $yysubmatches = $yymatches; 638 if (strlen($yysubmatches[0]) < 200) { 639 $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); 640 } else { 641 $yymatches = array_filter($yymatches, 'strlen'); 642 } 643 if (empty($yymatches)) { 644 throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data, $this->counter, 5) . '... state TRIPPLE'); 645 } 646 next($yymatches); // skip global match 647 $this->token = key($yymatches); // token number 648 $this->value = current($yymatches); // token value 649 $r = $this->{'yy_r6_' . $this->token}(); 650 if ($r === null) { 651 $this->counter += strlen($this->value); 652 $this->line += substr_count($this->value, "\n"); 653 // accept this token 654 return true; 655 } elseif ($r === true) { 656 // we have changed state 657 // process this token in the new state 658 return $this->yylex(); 659 } elseif ($r === false) { 660 $this->counter += strlen($this->value); 661 $this->line += substr_count($this->value, "\n"); 662 if ($this->counter >= strlen($this->data)) { 663 return false; // end of input 664 } 665 // skip this token 666 continue; 667 } 668 } else { 669 throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[$this->counter]); 670 } 671 break; 672 } while (true); 673 } // end function 674 675 const TRIPPLE = 6; 676 677 function yy_r6_1() 678 { 679 680 $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES_END; 681 $this->yypopstate(); 682 $this->yypushstate(self::START); 683 } 684 685 function yy_r6_2() 686 { 687 688 $to = strlen($this->data); 689 preg_match("/\"\"\"[ \t\r]*[\n#;]/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); 690 if (isset($match[0][1])) { 691 $to = $match[0][1]; 692 } else { 693 $this->compiler->trigger_template_error("missing or misspelled literal closing tag"); 694 } 695 $this->value = substr($this->data, $this->counter, $to - $this->counter); 696 $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_TEXT; 697 } 698 699 }