3 * Smarty Internal Plugin Configfilelexer
5 * This is the lexer to break the config file source into tokens
13 * Smarty_Internal_Configfilelexer
15 * This is the config file lexer.
16 * It is generated from the smarty_internal_configfilelexer.plex file
19 * @subpackage Compiler
22 class Smarty_Internal_Configfilelexer
72 public $smarty = null;
77 * @var Smarty_Internal_Config_File_Compiler
79 private $compiler = null;
82 * copy of config_booleanize
86 private $configBooleanize = false;
100 public $yyTracePrompt;
107 public $state_name = array(1 => 'START', 2 => 'VALUE', 3 => 'NAKED_STRING_VALUE', 4 => 'COMMENT', 5 => 'SECTION', 6 => 'TRIPPLE');
110 * storage for assembled token patterns
114 private $yy_global_pattern1 = null;
116 private $yy_global_pattern2 = null;
118 private $yy_global_pattern3 = null;
120 private $yy_global_pattern4 = null;
122 private $yy_global_pattern5 = null;
124 private $yy_global_pattern6 = null;
131 public $smarty_token_names = array( // Text for parser error messages
137 * @param string $data template source
138 * @param Smarty_Internal_Config_File_Compiler $compiler
140 function __construct($data, Smarty_Internal_Config_File_Compiler
$compiler)
142 // set instance object
143 self
::instance($this);
144 $this->data
= $data . "\n"; //now all lines are \n-terminated
146 if (preg_match('/^\xEF\xBB\xBF/', $this->data
, $match)) {
147 $this->counter +
= strlen($match[0]);
150 $this->compiler
= $compiler;
151 $this->smarty
= $compiler->smarty
;
152 $this->configBooleanize
= $this->smarty
->config_booleanize
;
155 public static function &instance($new_instance = null)
157 static $instance = null;
158 if (isset($new_instance) && is_object($new_instance)) {
159 $instance = $new_instance;
164 public function PrintTrace()
166 $this->yyTraceFILE
= fopen('php://output', 'w');
167 $this->yyTracePrompt
= '<br>';
170 private $_yy_state = 1;
172 private $_yy_stack = array();
174 public function yylex()
176 return $this->{'yylex' . $this->_yy_state
}();
179 public function yypushstate($state)
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
);
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
);
191 public function yypopstate()
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
);
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
);
202 public function yybegin($state)
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
);
210 public function yylex1()
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])/iS";
215 if ($this->counter
>= strlen($this->data
)) {
216 return false; // end of input
220 if (preg_match($this->yy_global_pattern1
, $this->data
, $yymatches, null, $this->counter
)) {
221 $yysubmatches = $yymatches;
222 $yymatches = preg_grep("/(.|\s)+/", $yysubmatches);
223 if (empty($yymatches)) {
224 throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data
, $this->counter
, 5) . '... state START');
226 next($yymatches); // skip global match
227 $this->token
= key($yymatches); // token number
228 $this->value
= current($yymatches); // token value
229 $r = $this->{'yy_r1_' . $this->token
}();
231 $this->counter +
= strlen($this->value
);
232 $this->line +
= substr_count($this->value
, "\n");
235 } elseif ($r === true) {
236 // we have changed state
237 // process this token in the new state
238 return $this->yylex();
239 } elseif ($r === false) {
240 $this->counter +
= strlen($this->value
);
241 $this->line +
= substr_count($this->value
, "\n");
242 if ($this->counter
>= strlen($this->data
)) {
243 return false; // end of input
249 throw new Exception('Unexpected input at line' . $this->line
. ': ' . $this->data
[$this->counter
]);
260 $this->token
= Smarty_Internal_Configfileparser
::TPC_COMMENTSTART
;
261 $this->yypushstate(self
::COMMENT
);
267 $this->token
= Smarty_Internal_Configfileparser
::TPC_OPENB
;
268 $this->yypushstate(self
::SECTION
);
274 $this->token
= Smarty_Internal_Configfileparser
::TPC_CLOSEB
;
280 $this->token
= Smarty_Internal_Configfileparser
::TPC_EQUAL
;
281 $this->yypushstate(self
::VALUE
);
293 $this->token
= Smarty_Internal_Configfileparser
::TPC_NEWLINE
;
299 $this->token
= Smarty_Internal_Configfileparser
::TPC_ID
;
305 $this->token
= Smarty_Internal_Configfileparser
::TPC_OTHER
;
308 public function yylex2()
310 if (!isset($this->yy_global_pattern2
)) {
311 $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)/iS";
313 if ($this->counter
>= strlen($this->data
)) {
314 return false; // end of input
318 if (preg_match($this->yy_global_pattern2
, $this->data
, $yymatches, null, $this->counter
)) {
319 $yysubmatches = $yymatches;
320 $yymatches = preg_grep("/(.|\s)+/", $yysubmatches);
321 if (empty($yymatches)) {
322 throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data
, $this->counter
, 5) . '... state VALUE');
324 next($yymatches); // skip global match
325 $this->token
= key($yymatches); // token number
326 $this->value
= current($yymatches); // token value
327 $r = $this->{'yy_r2_' . $this->token
}();
329 $this->counter +
= strlen($this->value
);
330 $this->line +
= substr_count($this->value
, "\n");
333 } elseif ($r === true) {
334 // we have changed state
335 // process this token in the new state
336 return $this->yylex();
337 } elseif ($r === false) {
338 $this->counter +
= strlen($this->value
);
339 $this->line +
= substr_count($this->value
, "\n");
340 if ($this->counter
>= strlen($this->data
)) {
341 return false; // end of input
347 throw new Exception('Unexpected input at line' . $this->line
. ': ' . $this->data
[$this->counter
]);
364 $this->token
= Smarty_Internal_Configfileparser
::TPC_FLOAT
;
371 $this->token
= Smarty_Internal_Configfileparser
::TPC_INT
;
378 $this->token
= Smarty_Internal_Configfileparser
::TPC_TRIPPLE_QUOTES
;
379 $this->yypushstate(self
::TRIPPLE
);
385 $this->token
= Smarty_Internal_Configfileparser
::TPC_SINGLE_QUOTED_STRING
;
392 $this->token
= Smarty_Internal_Configfileparser
::TPC_DOUBLE_QUOTED_STRING
;
399 if (!$this->configBooleanize ||
!in_array(strtolower($this->value
), Array("true", "false", "on", "off", "yes", "no"))) {
401 $this->yypushstate(self
::NAKED_STRING_VALUE
);
402 return true; //reprocess in new state
404 $this->token
= Smarty_Internal_Configfileparser
::TPC_BOOL
;
412 $this->token
= Smarty_Internal_Configfileparser
::TPC_NAKED_STRING
;
419 $this->token
= Smarty_Internal_Configfileparser
::TPC_NAKED_STRING
;
424 public function yylex3()
426 if (!isset($this->yy_global_pattern3
)) {
427 $this->yy_global_pattern3
= "/\G([^\n]+?(?=[ \t\r]*\n))/iS";
429 if ($this->counter
>= strlen($this->data
)) {
430 return false; // end of input
434 if (preg_match($this->yy_global_pattern3
, $this->data
, $yymatches, null, $this->counter
)) {
435 $yysubmatches = $yymatches;
436 $yymatches = preg_grep("/(.|\s)+/", $yysubmatches);
437 if (empty($yymatches)) {
438 throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data
, $this->counter
, 5) . '... state NAKED_STRING_VALUE');
440 next($yymatches); // skip global match
441 $this->token
= key($yymatches); // token number
442 $this->value
= current($yymatches); // token value
443 $r = $this->{'yy_r3_' . $this->token
}();
445 $this->counter +
= strlen($this->value
);
446 $this->line +
= substr_count($this->value
, "\n");
449 } elseif ($r === true) {
450 // we have changed state
451 // process this token in the new state
452 return $this->yylex();
453 } elseif ($r === false) {
454 $this->counter +
= strlen($this->value
);
455 $this->line +
= substr_count($this->value
, "\n");
456 if ($this->counter
>= strlen($this->data
)) {
457 return false; // end of input
463 throw new Exception('Unexpected input at line' . $this->line
. ': ' . $this->data
[$this->counter
]);
469 const NAKED_STRING_VALUE
= 3;
474 $this->token
= Smarty_Internal_Configfileparser
::TPC_NAKED_STRING
;
478 public function yylex4()
480 if (!isset($this->yy_global_pattern4
)) {
481 $this->yy_global_pattern4
= "/\G([ \t\r]+)|\G([^\n]+?(?=[ \t\r]*\n))|\G(\n)/iS";
483 if ($this->counter
>= strlen($this->data
)) {
484 return false; // end of input
488 if (preg_match($this->yy_global_pattern4
, $this->data
, $yymatches, null, $this->counter
)) {
489 $yysubmatches = $yymatches;
490 $yymatches = preg_grep("/(.|\s)+/", $yysubmatches);
491 if (empty($yymatches)) {
492 throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data
, $this->counter
, 5) . '... state COMMENT');
494 next($yymatches); // skip global match
495 $this->token
= key($yymatches); // token number
496 $this->value
= current($yymatches); // token value
497 $r = $this->{'yy_r4_' . $this->token
}();
499 $this->counter +
= strlen($this->value
);
500 $this->line +
= substr_count($this->value
, "\n");
503 } elseif ($r === true) {
504 // we have changed state
505 // process this token in the new state
506 return $this->yylex();
507 } elseif ($r === false) {
508 $this->counter +
= strlen($this->value
);
509 $this->line +
= substr_count($this->value
, "\n");
510 if ($this->counter
>= strlen($this->data
)) {
511 return false; // end of input
517 throw new Exception('Unexpected input at line' . $this->line
. ': ' . $this->data
[$this->counter
]);
534 $this->token
= Smarty_Internal_Configfileparser
::TPC_NAKED_STRING
;
540 $this->token
= Smarty_Internal_Configfileparser
::TPC_NEWLINE
;
544 public function yylex5()
546 if (!isset($this->yy_global_pattern5
)) {
547 $this->yy_global_pattern5
= "/\G(\\.)|\G(.*?(?=[\.=[\]\r\n]))/iS";
549 if ($this->counter
>= strlen($this->data
)) {
550 return false; // end of input
554 if (preg_match($this->yy_global_pattern5
, $this->data
, $yymatches, null, $this->counter
)) {
555 $yysubmatches = $yymatches;
556 $yymatches = preg_grep("/(.|\s)+/", $yysubmatches);
557 if (empty($yymatches)) {
558 throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data
, $this->counter
, 5) . '... state SECTION');
560 next($yymatches); // skip global match
561 $this->token
= key($yymatches); // token number
562 $this->value
= current($yymatches); // token value
563 $r = $this->{'yy_r5_' . $this->token
}();
565 $this->counter +
= strlen($this->value
);
566 $this->line +
= substr_count($this->value
, "\n");
569 } elseif ($r === true) {
570 // we have changed state
571 // process this token in the new state
572 return $this->yylex();
573 } elseif ($r === false) {
574 $this->counter +
= strlen($this->value
);
575 $this->line +
= substr_count($this->value
, "\n");
576 if ($this->counter
>= strlen($this->data
)) {
577 return false; // end of input
583 throw new Exception('Unexpected input at line' . $this->line
. ': ' . $this->data
[$this->counter
]);
594 $this->token
= Smarty_Internal_Configfileparser
::TPC_DOT
;
600 $this->token
= Smarty_Internal_Configfileparser
::TPC_SECTION
;
604 public function yylex6()
606 if (!isset($this->yy_global_pattern6
)) {
607 $this->yy_global_pattern6
= "/\G(\"\"\"(?=[ \t\r]*[\n#;]))|\G([\S\s])/iS";
609 if ($this->counter
>= strlen($this->data
)) {
610 return false; // end of input
614 if (preg_match($this->yy_global_pattern6
, $this->data
, $yymatches, null, $this->counter
)) {
615 $yysubmatches = $yymatches;
616 $yymatches = preg_grep("/(.|\s)+/", $yysubmatches);
617 if (empty($yymatches)) {
618 throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data
, $this->counter
, 5) . '... state TRIPPLE');
620 next($yymatches); // skip global match
621 $this->token
= key($yymatches); // token number
622 $this->value
= current($yymatches); // token value
623 $r = $this->{'yy_r6_' . $this->token
}();
625 $this->counter +
= strlen($this->value
);
626 $this->line +
= substr_count($this->value
, "\n");
629 } elseif ($r === true) {
630 // we have changed state
631 // process this token in the new state
632 return $this->yylex();
633 } elseif ($r === false) {
634 $this->counter +
= strlen($this->value
);
635 $this->line +
= substr_count($this->value
, "\n");
636 if ($this->counter
>= strlen($this->data
)) {
637 return false; // end of input
643 throw new Exception('Unexpected input at line' . $this->line
. ': ' . $this->data
[$this->counter
]);
654 $this->token
= Smarty_Internal_Configfileparser
::TPC_TRIPPLE_QUOTES_END
;
656 $this->yypushstate(self
::START
);
662 $to = strlen($this->data
);
663 preg_match("/\"\"\"[ \t\r]*[\n#;]/", $this->data
, $match, PREG_OFFSET_CAPTURE
, $this->counter
);
664 if (isset($match[0][1])) {
667 $this->compiler
->trigger_template_error("missing or misspelled literal closing tag");
669 $this->value
= substr($this->data
, $this->counter
, $to - $this->counter
);
670 $this->token
= Smarty_Internal_Configfileparser
::TPC_TRIPPLE_TEXT
;