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
36 public $dataLength = null;
78 public $smarty = null;
83 * @var Smarty_Internal_Config_File_Compiler
85 private $compiler = null;
88 * copy of config_booleanize
92 private $configBooleanize = false;
106 public $yyTracePrompt;
113 public $state_name = array(1 => 'START', 2 => 'VALUE', 3 => 'NAKED_STRING_VALUE', 4 => 'COMMENT', 5 => 'SECTION',
117 * storage for assembled token patterns
121 private $yy_global_pattern1 = null;
123 private $yy_global_pattern2 = null;
125 private $yy_global_pattern3 = null;
127 private $yy_global_pattern4 = null;
129 private $yy_global_pattern5 = null;
131 private $yy_global_pattern6 = null;
138 public $smarty_token_names = array( // Text for parser error messages
144 * @param string $data template source
145 * @param Smarty_Internal_Config_File_Compiler $compiler
147 function __construct($data, Smarty_Internal_Config_File_Compiler $compiler)
149 $this->data = $data . "\n"; //now all lines are \n-terminated
150 $this->dataLength = strlen($data);
152 if (preg_match('/^\xEF\xBB\xBF/', $this->data, $match)) {
153 $this->counter += strlen($match[ 0 ]);
156 $this->compiler = $compiler;
157 $this->smarty = $compiler->smarty;
158 $this->configBooleanize = $this->smarty->config_booleanize;
161 public function PrintTrace()
163 $this->yyTraceFILE = fopen('php://output', 'w');
164 $this->yyTracePrompt = '<br>';
167 private $_yy_state = 1;
169 private $_yy_stack = array();
171 public function yylex()
173 return $this->{'yylex' . $this->_yy_state}();
176 public function yypushstate($state)
178 if ($this->yyTraceFILE) {
179 fprintf($this->yyTraceFILE, "%sState push %s\n", $this->yyTracePrompt,
180 isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
183 array_push($this->_yy_stack, $this->_yy_state);
184 $this->_yy_state = $state;
185 if ($this->yyTraceFILE) {
186 fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt,
187 isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
192 public function yypopstate()
194 if ($this->yyTraceFILE) {
195 fprintf($this->yyTraceFILE, "%sState pop %s\n", $this->yyTracePrompt,
196 isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
199 $this->_yy_state = array_pop($this->_yy_stack);
200 if ($this->yyTraceFILE) {
201 fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt,
202 isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
207 public function yybegin($state)
209 $this->_yy_state = $state;
210 if ($this->yyTraceFILE) {
211 fprintf($this->yyTraceFILE, "%sState set %s\n", $this->yyTracePrompt,
212 isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
217 public function yylex1()
219 if (!isset($this->yy_global_pattern1)) {
220 $this->yy_global_pattern1 =
221 "/\G(#|;)|\G(\\[)|\G(\\])|\G(=)|\G([ \t\r]+)|\G(\n)|\G([0-9]*[a-zA-Z_]\\w*)|\G([\S\s])/isS";
223 if (!isset($this->dataLength)) {
224 $this->dataLength = strlen($this->data);
226 if ($this->counter >= $this->dataLength) {
227 return false; // end of input
231 if (preg_match($this->yy_global_pattern1, $this->data, $yymatches, null, $this->counter)) {
232 if (!isset($yymatches[ 0 ][ 1 ])) {
233 $yymatches = preg_grep("/(.|\s)+/", $yymatches);
235 $yymatches = array_filter($yymatches);
237 if (empty($yymatches)) {
238 throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' .
239 substr($this->data, $this->counter, 5) . '... state START');
241 next($yymatches); // skip global match
242 $this->token = key($yymatches); // token number
243 $this->value = current($yymatches); // token value
244 $r = $this->{'yy_r1_' . $this->token}();
246 $this->counter += strlen($this->value);
247 $this->line += substr_count($this->value, "\n");
250 } elseif ($r === true) {
251 // we have changed state
252 // process this token in the new state
253 return $this->yylex();
254 } elseif ($r === false) {
255 $this->counter += strlen($this->value);
256 $this->line += substr_count($this->value, "\n");
257 if ($this->counter >= $this->dataLength) {
258 return false; // end of input
264 throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
276 $this->token = Smarty_Internal_Configfileparser::TPC_COMMENTSTART;
277 $this->yypushstate(self::COMMENT);
283 $this->token = Smarty_Internal_Configfileparser::TPC_OPENB;
284 $this->yypushstate(self::SECTION);
290 $this->token = Smarty_Internal_Configfileparser::TPC_CLOSEB;
296 $this->token = Smarty_Internal_Configfileparser::TPC_EQUAL;
297 $this->yypushstate(self::VALUE);
309 $this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
315 $this->token = Smarty_Internal_Configfileparser::TPC_ID;
321 $this->token = Smarty_Internal_Configfileparser::TPC_OTHER;
324 public function yylex2()
326 if (!isset($this->yy_global_pattern2)) {
327 $this->yy_global_pattern2 =
328 "/\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";
330 if (!isset($this->dataLength)) {
331 $this->dataLength = strlen($this->data);
333 if ($this->counter >= $this->dataLength) {
334 return false; // end of input
338 if (preg_match($this->yy_global_pattern2, $this->data, $yymatches, null, $this->counter)) {
339 if (!isset($yymatches[ 0 ][ 1 ])) {
340 $yymatches = preg_grep("/(.|\s)+/", $yymatches);
342 $yymatches = array_filter($yymatches);
344 if (empty($yymatches)) {
345 throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' .
346 substr($this->data, $this->counter, 5) . '... state VALUE');
348 next($yymatches); // skip global match
349 $this->token = key($yymatches); // token number
350 $this->value = current($yymatches); // token value
351 $r = $this->{'yy_r2_' . $this->token}();
353 $this->counter += strlen($this->value);
354 $this->line += substr_count($this->value, "\n");
357 } elseif ($r === true) {
358 // we have changed state
359 // process this token in the new state
360 return $this->yylex();
361 } elseif ($r === false) {
362 $this->counter += strlen($this->value);
363 $this->line += substr_count($this->value, "\n");
364 if ($this->counter >= $this->dataLength) {
365 return false; // end of input
371 throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
389 $this->token = Smarty_Internal_Configfileparser::TPC_FLOAT;
396 $this->token = Smarty_Internal_Configfileparser::TPC_INT;
403 $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES;
404 $this->yypushstate(self::TRIPPLE);
410 $this->token = Smarty_Internal_Configfileparser::TPC_SINGLE_QUOTED_STRING;
417 $this->token = Smarty_Internal_Configfileparser::TPC_DOUBLE_QUOTED_STRING;
424 if (!$this->configBooleanize ||
425 !in_array(strtolower($this->value), Array("true", "false", "on", "off", "yes", "no"))
428 $this->yypushstate(self::NAKED_STRING_VALUE);
429 return true; //reprocess in new state
431 $this->token = Smarty_Internal_Configfileparser::TPC_BOOL;
439 $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
446 $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
451 public function yylex3()
453 if (!isset($this->yy_global_pattern3)) {
454 $this->yy_global_pattern3 = "/\G([^\n]+?(?=[ \t\r]*\n))/isS";
456 if (!isset($this->dataLength)) {
457 $this->dataLength = strlen($this->data);
459 if ($this->counter >= $this->dataLength) {
460 return false; // end of input
464 if (preg_match($this->yy_global_pattern3, $this->data, $yymatches, null, $this->counter)) {
465 if (!isset($yymatches[ 0 ][ 1 ])) {
466 $yymatches = preg_grep("/(.|\s)+/", $yymatches);
468 $yymatches = array_filter($yymatches);
470 if (empty($yymatches)) {
471 throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' .
472 substr($this->data, $this->counter, 5) . '... state NAKED_STRING_VALUE');
474 next($yymatches); // skip global match
475 $this->token = key($yymatches); // token number
476 $this->value = current($yymatches); // token value
477 $r = $this->{'yy_r3_' . $this->token}();
479 $this->counter += strlen($this->value);
480 $this->line += substr_count($this->value, "\n");
483 } elseif ($r === true) {
484 // we have changed state
485 // process this token in the new state
486 return $this->yylex();
487 } elseif ($r === false) {
488 $this->counter += strlen($this->value);
489 $this->line += substr_count($this->value, "\n");
490 if ($this->counter >= $this->dataLength) {
491 return false; // end of input
497 throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
504 const NAKED_STRING_VALUE = 3;
509 $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
513 public function yylex4()
515 if (!isset($this->yy_global_pattern4)) {
516 $this->yy_global_pattern4 = "/\G([ \t\r]+)|\G([^\n]+?(?=[ \t\r]*\n))|\G(\n)/isS";
518 if (!isset($this->dataLength)) {
519 $this->dataLength = strlen($this->data);
521 if ($this->counter >= $this->dataLength) {
522 return false; // end of input
526 if (preg_match($this->yy_global_pattern4, $this->data, $yymatches, null, $this->counter)) {
527 if (!isset($yymatches[ 0 ][ 1 ])) {
528 $yymatches = preg_grep("/(.|\s)+/", $yymatches);
530 $yymatches = array_filter($yymatches);
532 if (empty($yymatches)) {
533 throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' .
534 substr($this->data, $this->counter, 5) . '... state COMMENT');
536 next($yymatches); // skip global match
537 $this->token = key($yymatches); // token number
538 $this->value = current($yymatches); // token value
539 $r = $this->{'yy_r4_' . $this->token}();
541 $this->counter += strlen($this->value);
542 $this->line += substr_count($this->value, "\n");
545 } elseif ($r === true) {
546 // we have changed state
547 // process this token in the new state
548 return $this->yylex();
549 } elseif ($r === false) {
550 $this->counter += strlen($this->value);
551 $this->line += substr_count($this->value, "\n");
552 if ($this->counter >= $this->dataLength) {
553 return false; // end of input
559 throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
577 $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
583 $this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
587 public function yylex5()
589 if (!isset($this->yy_global_pattern5)) {
590 $this->yy_global_pattern5 = "/\G(\\.)|\G(.*?(?=[\.=[\]\r\n]))/isS";
592 if (!isset($this->dataLength)) {
593 $this->dataLength = strlen($this->data);
595 if ($this->counter >= $this->dataLength) {
596 return false; // end of input
600 if (preg_match($this->yy_global_pattern5, $this->data, $yymatches, null, $this->counter)) {
601 if (!isset($yymatches[ 0 ][ 1 ])) {
602 $yymatches = preg_grep("/(.|\s)+/", $yymatches);
604 $yymatches = array_filter($yymatches);
606 if (empty($yymatches)) {
607 throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' .
608 substr($this->data, $this->counter, 5) . '... state SECTION');
610 next($yymatches); // skip global match
611 $this->token = key($yymatches); // token number
612 $this->value = current($yymatches); // token value
613 $r = $this->{'yy_r5_' . $this->token}();
615 $this->counter += strlen($this->value);
616 $this->line += substr_count($this->value, "\n");
619 } elseif ($r === true) {
620 // we have changed state
621 // process this token in the new state
622 return $this->yylex();
623 } elseif ($r === false) {
624 $this->counter += strlen($this->value);
625 $this->line += substr_count($this->value, "\n");
626 if ($this->counter >= $this->dataLength) {
627 return false; // end of input
633 throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
645 $this->token = Smarty_Internal_Configfileparser::TPC_DOT;
651 $this->token = Smarty_Internal_Configfileparser::TPC_SECTION;
655 public function yylex6()
657 if (!isset($this->yy_global_pattern6)) {
658 $this->yy_global_pattern6 = "/\G(\"\"\"(?=[ \t\r]*[\n#;]))|\G([\S\s])/isS";
660 if (!isset($this->dataLength)) {
661 $this->dataLength = strlen($this->data);
663 if ($this->counter >= $this->dataLength) {
664 return false; // end of input
668 if (preg_match($this->yy_global_pattern6, $this->data, $yymatches, null, $this->counter)) {
669 if (!isset($yymatches[ 0 ][ 1 ])) {
670 $yymatches = preg_grep("/(.|\s)+/", $yymatches);
672 $yymatches = array_filter($yymatches);
674 if (empty($yymatches)) {
675 throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' .
676 substr($this->data, $this->counter, 5) . '... state TRIPPLE');
678 next($yymatches); // skip global match
679 $this->token = key($yymatches); // token number
680 $this->value = current($yymatches); // token value
681 $r = $this->{'yy_r6_' . $this->token}();
683 $this->counter += strlen($this->value);
684 $this->line += substr_count($this->value, "\n");
687 } elseif ($r === true) {
688 // we have changed state
689 // process this token in the new state
690 return $this->yylex();
691 } elseif ($r === false) {
692 $this->counter += strlen($this->value);
693 $this->line += substr_count($this->value, "\n");
694 if ($this->counter >= $this->dataLength) {
695 return false; // end of input
701 throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
713 $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES_END;
715 $this->yypushstate(self::START);
721 $to = strlen($this->data);
722 preg_match("/\"\"\"[ \t\r]*[\n#;]/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter);
723 if (isset($match[ 0 ][ 1 ])) {
724 $to = $match[ 0 ][ 1 ];
726 $this->compiler->trigger_template_error("missing or misspelled literal closing tag");
728 $this->value = substr($this->data, $this->counter, $to - $this->counter);
729 $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_TEXT;