3 * Smarty Internal Plugin Configfilelexer
 
   5 * This is the lexer to break the config file source into tokens 
 
  11 * Smarty Internal Plugin Configfilelexer
 
  13 class Smarty_Internal_Configfilelexer
 
  23     public $smarty_token_names = array (                // Text for parser error messages
 
  27     function __construct($data, $smarty)
 
  29         // set instance object
 
  30         self::instance($this); 
 
  31         $this->data = $data . "\n"; //now all lines are \n-terminated
 
  34         $this->smarty = $smarty; 
 
  36     public static function &instance($new_instance = null)
 
  38         static $instance = null;
 
  39         if (isset($new_instance) && is_object($new_instance))
 
  40             $instance = $new_instance;
 
  46     private $_yy_state = 1;
 
  47     private $_yy_stack = array();
 
  51         return $this->{'yylex' . $this->_yy_state}();
 
  54     function yypushstate($state)
 
  56         array_push($this->_yy_stack, $this->_yy_state);
 
  57         $this->_yy_state = $state;
 
  62         $this->_yy_state = array_pop($this->_yy_stack);
 
  65     function yybegin($state)
 
  67         $this->_yy_state = $state;
 
  84         if ($this->counter >= strlen($this->data)) {
 
  85             return false; // end of input
 
  87         $yy_global_pattern = "/^(#)|^(\\[)|^(\\])|^(=)|^([ \t\r]+)|^(\n)|^([0-9]*[a-zA-Z_]\\w*)/iS";
 
  90             if (preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches)) {
 
  91                 $yysubmatches = $yymatches;
 
  92                 $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
 
  93                 if (!count($yymatches)) {
 
  94                     throw new Exception('Error: lexing failed because a rule matched' .
 
  95                         'an empty string.  Input "' . substr($this->data,
 
  96                         $this->counter, 5) . '... state START');
 
  98                 next($yymatches); // skip global match
 
  99                 $this->token = key($yymatches); // token number
 
 100                 if ($tokenMap[$this->token]) {
 
 101                     // extract sub-patterns for passing to lex function
 
 102                     $yysubmatches = array_slice($yysubmatches, $this->token + 1,
 
 103                         $tokenMap[$this->token]);
 
 105                     $yysubmatches = array();
 
 107                 $this->value = current($yymatches); // token value
 
 108                 $r = $this->{'yy_r1_' . $this->token}($yysubmatches);
 
 110                     $this->counter += strlen($this->value);
 
 111                     $this->line += substr_count($this->value, "\n");
 
 114                 } elseif ($r === true) {
 
 115                     // we have changed state
 
 116                     // process this token in the new state
 
 117                     return $this->yylex();
 
 118                 } elseif ($r === false) {
 
 119                     $this->counter += strlen($this->value);
 
 120                     $this->line += substr_count($this->value, "\n");
 
 121                     if ($this->counter >= strlen($this->data)) {
 
 122                         return false; // end of input
 
 127                 throw new Exception('Unexpected input at line' . $this->line .
 
 128                     ': ' . $this->data[$this->counter]);
 
 137     function yy_r1_1($yy_subpatterns)
 
 140     $this->token = Smarty_Internal_Configfileparser::TPC_COMMENTSTART;
 
 141     $this->yypushstate(self::COMMENT);
 
 143     function yy_r1_2($yy_subpatterns)
 
 146     $this->token = Smarty_Internal_Configfileparser::TPC_OPENB;
 
 147     $this->yypushstate(self::SECTION);
 
 149     function yy_r1_3($yy_subpatterns)
 
 152     $this->token = Smarty_Internal_Configfileparser::TPC_CLOSEB;
 
 154     function yy_r1_4($yy_subpatterns)
 
 157     $this->token = Smarty_Internal_Configfileparser::TPC_EQUAL;
 
 158     $this->yypushstate(self::VALUE);
 
 160     function yy_r1_5($yy_subpatterns)
 
 165     function yy_r1_6($yy_subpatterns)
 
 168     $this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
 
 170     function yy_r1_7($yy_subpatterns)
 
 173     $this->token = Smarty_Internal_Configfileparser::TPC_ID;
 
 191         if ($this->counter >= strlen($this->data)) {
 
 192             return false; // end of input
 
 194         $yy_global_pattern = "/^([ \t\r]+)|^(\\d+\\.\\d+(?=[ \t\r]*[\n#]))|^(\\d+(?=[ \t\r]*[\n#]))|^('[^'\\\\]*(?:\\\\.[^'\\\\]*)*'(?=[ \t\r]*[\n#]))|^(\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"(?=[ \t\r]*[\n#]))|^(\"\"\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"\"\"(?=[ \t\r]*[\n#]))|^([a-zA-Z]+(?=[ \t\r]*[\n#]))|^([^\n]+?(?=[ \t\r]*\n))|^(\n)/iS";
 
 197             if (preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches)) {
 
 198                 $yysubmatches = $yymatches;
 
 199                 $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
 
 200                 if (!count($yymatches)) {
 
 201                     throw new Exception('Error: lexing failed because a rule matched' .
 
 202                         'an empty string.  Input "' . substr($this->data,
 
 203                         $this->counter, 5) . '... state VALUE');
 
 205                 next($yymatches); // skip global match
 
 206                 $this->token = key($yymatches); // token number
 
 207                 if ($tokenMap[$this->token]) {
 
 208                     // extract sub-patterns for passing to lex function
 
 209                     $yysubmatches = array_slice($yysubmatches, $this->token + 1,
 
 210                         $tokenMap[$this->token]);
 
 212                     $yysubmatches = array();
 
 214                 $this->value = current($yymatches); // token value
 
 215                 $r = $this->{'yy_r2_' . $this->token}($yysubmatches);
 
 217                     $this->counter += strlen($this->value);
 
 218                     $this->line += substr_count($this->value, "\n");
 
 221                 } elseif ($r === true) {
 
 222                     // we have changed state
 
 223                     // process this token in the new state
 
 224                     return $this->yylex();
 
 225                 } elseif ($r === false) {
 
 226                     $this->counter += strlen($this->value);
 
 227                     $this->line += substr_count($this->value, "\n");
 
 228                     if ($this->counter >= strlen($this->data)) {
 
 229                         return false; // end of input
 
 234                 throw new Exception('Unexpected input at line' . $this->line .
 
 235                     ': ' . $this->data[$this->counter]);
 
 244     function yy_r2_1($yy_subpatterns)
 
 249     function yy_r2_2($yy_subpatterns)
 
 252     $this->token = Smarty_Internal_Configfileparser::TPC_FLOAT;
 
 255     function yy_r2_3($yy_subpatterns)
 
 258     $this->token = Smarty_Internal_Configfileparser::TPC_INT;
 
 261     function yy_r2_4($yy_subpatterns)
 
 264     $this->token = Smarty_Internal_Configfileparser::TPC_SINGLE_QUOTED_STRING;
 
 267     function yy_r2_5($yy_subpatterns)
 
 270     $this->token = Smarty_Internal_Configfileparser::TPC_DOUBLE_QUOTED_STRING;
 
 273     function yy_r2_6($yy_subpatterns)
 
 276     $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_DOUBLE_QUOTED_STRING;
 
 279     function yy_r2_7($yy_subpatterns)
 
 282     if (!$this->smarty->config_booleanize || !in_array(strtolower($this->value), Array("true", "false", "on", "off", "yes", "no")) ) {
 
 284         $this->yypushstate(self::NAKED_STRING_VALUE);
 
 285         return true; //reprocess in new state
 
 287         $this->token = Smarty_Internal_Configfileparser::TPC_BOOL;
 
 291     function yy_r2_8($yy_subpatterns)
 
 294     $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
 
 297     function yy_r2_9($yy_subpatterns)
 
 300     $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
 
 312         if ($this->counter >= strlen($this->data)) {
 
 313             return false; // end of input
 
 315         $yy_global_pattern = "/^([^\n]+?(?=[ \t\r]*\n))/iS";
 
 318             if (preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches)) {
 
 319                 $yysubmatches = $yymatches;
 
 320                 $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
 
 321                 if (!count($yymatches)) {
 
 322                     throw new Exception('Error: lexing failed because a rule matched' .
 
 323                         'an empty string.  Input "' . substr($this->data,
 
 324                         $this->counter, 5) . '... state NAKED_STRING_VALUE');
 
 326                 next($yymatches); // skip global match
 
 327                 $this->token = key($yymatches); // token number
 
 328                 if ($tokenMap[$this->token]) {
 
 329                     // extract sub-patterns for passing to lex function
 
 330                     $yysubmatches = array_slice($yysubmatches, $this->token + 1,
 
 331                         $tokenMap[$this->token]);
 
 333                     $yysubmatches = array();
 
 335                 $this->value = current($yymatches); // token value
 
 336                 $r = $this->{'yy_r3_' . $this->token}($yysubmatches);
 
 338                     $this->counter += strlen($this->value);
 
 339                     $this->line += substr_count($this->value, "\n");
 
 342                 } elseif ($r === true) {
 
 343                     // we have changed state
 
 344                     // process this token in the new state
 
 345                     return $this->yylex();
 
 346                 } elseif ($r === false) {
 
 347                     $this->counter += strlen($this->value);
 
 348                     $this->line += substr_count($this->value, "\n");
 
 349                     if ($this->counter >= strlen($this->data)) {
 
 350                         return false; // end of input
 
 355                 throw new Exception('Unexpected input at line' . $this->line .
 
 356                     ': ' . $this->data[$this->counter]);
 
 364     const NAKED_STRING_VALUE = 3;
 
 365     function yy_r3_1($yy_subpatterns)
 
 368     $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
 
 381         if ($this->counter >= strlen($this->data)) {
 
 382             return false; // end of input
 
 384         $yy_global_pattern = "/^([ \t\r]+)|^([^\n]+?(?=[ \t\r]*\n))|^(\n)/iS";
 
 387             if (preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches)) {
 
 388                 $yysubmatches = $yymatches;
 
 389                 $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
 
 390                 if (!count($yymatches)) {
 
 391                     throw new Exception('Error: lexing failed because a rule matched' .
 
 392                         'an empty string.  Input "' . substr($this->data,
 
 393                         $this->counter, 5) . '... state COMMENT');
 
 395                 next($yymatches); // skip global match
 
 396                 $this->token = key($yymatches); // token number
 
 397                 if ($tokenMap[$this->token]) {
 
 398                     // extract sub-patterns for passing to lex function
 
 399                     $yysubmatches = array_slice($yysubmatches, $this->token + 1,
 
 400                         $tokenMap[$this->token]);
 
 402                     $yysubmatches = array();
 
 404                 $this->value = current($yymatches); // token value
 
 405                 $r = $this->{'yy_r4_' . $this->token}($yysubmatches);
 
 407                     $this->counter += strlen($this->value);
 
 408                     $this->line += substr_count($this->value, "\n");
 
 411                 } elseif ($r === true) {
 
 412                     // we have changed state
 
 413                     // process this token in the new state
 
 414                     return $this->yylex();
 
 415                 } elseif ($r === false) {
 
 416                     $this->counter += strlen($this->value);
 
 417                     $this->line += substr_count($this->value, "\n");
 
 418                     if ($this->counter >= strlen($this->data)) {
 
 419                         return false; // end of input
 
 424                 throw new Exception('Unexpected input at line' . $this->line .
 
 425                     ': ' . $this->data[$this->counter]);
 
 434     function yy_r4_1($yy_subpatterns)
 
 439     function yy_r4_2($yy_subpatterns)
 
 442     $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
 
 444     function yy_r4_3($yy_subpatterns)
 
 447     $this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
 
 459         if ($this->counter >= strlen($this->data)) {
 
 460             return false; // end of input
 
 462         $yy_global_pattern = "/^(\\.)|^(.*?(?=[\.=[\]\r\n]))/iS";
 
 465             if (preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches)) {
 
 466                 $yysubmatches = $yymatches;
 
 467                 $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
 
 468                 if (!count($yymatches)) {
 
 469                     throw new Exception('Error: lexing failed because a rule matched' .
 
 470                         'an empty string.  Input "' . substr($this->data,
 
 471                         $this->counter, 5) . '... state SECTION');
 
 473                 next($yymatches); // skip global match
 
 474                 $this->token = key($yymatches); // token number
 
 475                 if ($tokenMap[$this->token]) {
 
 476                     // extract sub-patterns for passing to lex function
 
 477                     $yysubmatches = array_slice($yysubmatches, $this->token + 1,
 
 478                         $tokenMap[$this->token]);
 
 480                     $yysubmatches = array();
 
 482                 $this->value = current($yymatches); // token value
 
 483                 $r = $this->{'yy_r5_' . $this->token}($yysubmatches);
 
 485                     $this->counter += strlen($this->value);
 
 486                     $this->line += substr_count($this->value, "\n");
 
 489                 } elseif ($r === true) {
 
 490                     // we have changed state
 
 491                     // process this token in the new state
 
 492                     return $this->yylex();
 
 493                 } elseif ($r === false) {
 
 494                     $this->counter += strlen($this->value);
 
 495                     $this->line += substr_count($this->value, "\n");
 
 496                     if ($this->counter >= strlen($this->data)) {
 
 497                         return false; // end of input
 
 502                 throw new Exception('Unexpected input at line' . $this->line .
 
 503                     ': ' . $this->data[$this->counter]);
 
 512     function yy_r5_1($yy_subpatterns)
 
 515     $this->token = Smarty_Internal_Configfileparser::TPC_DOT;
 
 517     function yy_r5_2($yy_subpatterns)
 
 520     $this->token = Smarty_Internal_Configfileparser::TPC_SECTION;