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;
35 $this->mbstring_overload = ini_get('mbstring.func_overload') & 2;
37 public static function &instance($new_instance = null)
39 static $instance = null;
40 if (isset($new_instance) && is_object($new_instance))
41 $instance = $new_instance;
47 private $_yy_state = 1;
48 private $_yy_stack = array();
52 return $this->{'yylex' . $this->_yy_state}();
55 function yypushstate($state)
57 array_push($this->_yy_stack, $this->_yy_state);
58 $this->_yy_state = $state;
63 $this->_yy_state = array_pop($this->_yy_stack);
66 function yybegin($state)
68 $this->_yy_state = $state;
86 if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
87 return false; // end of input
89 $yy_global_pattern = "/\G(#|;)|\G(\\[)|\G(\\])|\G(=)|\G([ \t\r]+)|\G(\n)|\G([0-9]*[a-zA-Z_]\\w*)|\G([\S\s])/iS";
92 if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) {
93 $yysubmatches = $yymatches;
94 $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
95 if (!count($yymatches)) {
96 throw new Exception('Error: lexing failed because a rule matched' .
97 ' an empty string. Input "' . substr($this->data,
98 $this->counter, 5) . '... state START');
100 next($yymatches); // skip global match
101 $this->token = key($yymatches); // token number
102 if ($tokenMap[$this->token]) {
103 // extract sub-patterns for passing to lex function
104 $yysubmatches = array_slice($yysubmatches, $this->token + 1,
105 $tokenMap[$this->token]);
107 $yysubmatches = array();
109 $this->value = current($yymatches); // token value
110 $r = $this->{'yy_r1_' . $this->token}($yysubmatches);
112 $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
113 $this->line += substr_count($this->value, "\n");
116 } elseif ($r === true) {
117 // we have changed state
118 // process this token in the new state
119 return $this->yylex();
120 } elseif ($r === false) {
121 $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
122 $this->line += substr_count($this->value, "\n");
123 if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
124 return false; // end of input
129 throw new Exception('Unexpected input at line' . $this->line .
130 ': ' . $this->data[$this->counter]);
139 function yy_r1_1($yy_subpatterns)
142 $this->token = Smarty_Internal_Configfileparser::TPC_COMMENTSTART;
143 $this->yypushstate(self::COMMENT);
145 function yy_r1_2($yy_subpatterns)
148 $this->token = Smarty_Internal_Configfileparser::TPC_OPENB;
149 $this->yypushstate(self::SECTION);
151 function yy_r1_3($yy_subpatterns)
154 $this->token = Smarty_Internal_Configfileparser::TPC_CLOSEB;
156 function yy_r1_4($yy_subpatterns)
159 $this->token = Smarty_Internal_Configfileparser::TPC_EQUAL;
160 $this->yypushstate(self::VALUE);
162 function yy_r1_5($yy_subpatterns)
167 function yy_r1_6($yy_subpatterns)
170 $this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
172 function yy_r1_7($yy_subpatterns)
175 $this->token = Smarty_Internal_Configfileparser::TPC_ID;
177 function yy_r1_8($yy_subpatterns)
180 $this->token = Smarty_Internal_Configfileparser::TPC_OTHER;
198 if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
199 return false; // end of input
201 $yy_global_pattern = "/\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";
204 if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) {
205 $yysubmatches = $yymatches;
206 $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
207 if (!count($yymatches)) {
208 throw new Exception('Error: lexing failed because a rule matched' .
209 ' an empty string. Input "' . substr($this->data,
210 $this->counter, 5) . '... state VALUE');
212 next($yymatches); // skip global match
213 $this->token = key($yymatches); // token number
214 if ($tokenMap[$this->token]) {
215 // extract sub-patterns for passing to lex function
216 $yysubmatches = array_slice($yysubmatches, $this->token + 1,
217 $tokenMap[$this->token]);
219 $yysubmatches = array();
221 $this->value = current($yymatches); // token value
222 $r = $this->{'yy_r2_' . $this->token}($yysubmatches);
224 $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
225 $this->line += substr_count($this->value, "\n");
228 } elseif ($r === true) {
229 // we have changed state
230 // process this token in the new state
231 return $this->yylex();
232 } elseif ($r === false) {
233 $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
234 $this->line += substr_count($this->value, "\n");
235 if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
236 return false; // end of input
241 throw new Exception('Unexpected input at line' . $this->line .
242 ': ' . $this->data[$this->counter]);
251 function yy_r2_1($yy_subpatterns)
256 function yy_r2_2($yy_subpatterns)
259 $this->token = Smarty_Internal_Configfileparser::TPC_FLOAT;
262 function yy_r2_3($yy_subpatterns)
265 $this->token = Smarty_Internal_Configfileparser::TPC_INT;
268 function yy_r2_4($yy_subpatterns)
271 $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES;
272 $this->yypushstate(self::TRIPPLE);
274 function yy_r2_5($yy_subpatterns)
277 $this->token = Smarty_Internal_Configfileparser::TPC_SINGLE_QUOTED_STRING;
280 function yy_r2_6($yy_subpatterns)
283 $this->token = Smarty_Internal_Configfileparser::TPC_DOUBLE_QUOTED_STRING;
286 function yy_r2_7($yy_subpatterns)
289 if (!$this->smarty->config_booleanize || !in_array(strtolower($this->value), Array("true", "false", "on", "off", "yes", "no")) ) {
291 $this->yypushstate(self::NAKED_STRING_VALUE);
292 return true; //reprocess in new state
294 $this->token = Smarty_Internal_Configfileparser::TPC_BOOL;
298 function yy_r2_8($yy_subpatterns)
301 $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
304 function yy_r2_9($yy_subpatterns)
307 $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
319 if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
320 return false; // end of input
322 $yy_global_pattern = "/\G([^\n]+?(?=[ \t\r]*\n))/iS";
325 if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) {
326 $yysubmatches = $yymatches;
327 $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
328 if (!count($yymatches)) {
329 throw new Exception('Error: lexing failed because a rule matched' .
330 ' an empty string. Input "' . substr($this->data,
331 $this->counter, 5) . '... state NAKED_STRING_VALUE');
333 next($yymatches); // skip global match
334 $this->token = key($yymatches); // token number
335 if ($tokenMap[$this->token]) {
336 // extract sub-patterns for passing to lex function
337 $yysubmatches = array_slice($yysubmatches, $this->token + 1,
338 $tokenMap[$this->token]);
340 $yysubmatches = array();
342 $this->value = current($yymatches); // token value
343 $r = $this->{'yy_r3_' . $this->token}($yysubmatches);
345 $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
346 $this->line += substr_count($this->value, "\n");
349 } elseif ($r === true) {
350 // we have changed state
351 // process this token in the new state
352 return $this->yylex();
353 } elseif ($r === false) {
354 $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
355 $this->line += substr_count($this->value, "\n");
356 if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
357 return false; // end of input
362 throw new Exception('Unexpected input at line' . $this->line .
363 ': ' . $this->data[$this->counter]);
371 const NAKED_STRING_VALUE = 3;
372 function yy_r3_1($yy_subpatterns)
375 $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
388 if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
389 return false; // end of input
391 $yy_global_pattern = "/\G([ \t\r]+)|\G([^\n]+?(?=[ \t\r]*\n))|\G(\n)/iS";
394 if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) {
395 $yysubmatches = $yymatches;
396 $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
397 if (!count($yymatches)) {
398 throw new Exception('Error: lexing failed because a rule matched' .
399 ' an empty string. Input "' . substr($this->data,
400 $this->counter, 5) . '... state COMMENT');
402 next($yymatches); // skip global match
403 $this->token = key($yymatches); // token number
404 if ($tokenMap[$this->token]) {
405 // extract sub-patterns for passing to lex function
406 $yysubmatches = array_slice($yysubmatches, $this->token + 1,
407 $tokenMap[$this->token]);
409 $yysubmatches = array();
411 $this->value = current($yymatches); // token value
412 $r = $this->{'yy_r4_' . $this->token}($yysubmatches);
414 $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
415 $this->line += substr_count($this->value, "\n");
418 } elseif ($r === true) {
419 // we have changed state
420 // process this token in the new state
421 return $this->yylex();
422 } elseif ($r === false) {
423 $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
424 $this->line += substr_count($this->value, "\n");
425 if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
426 return false; // end of input
431 throw new Exception('Unexpected input at line' . $this->line .
432 ': ' . $this->data[$this->counter]);
441 function yy_r4_1($yy_subpatterns)
446 function yy_r4_2($yy_subpatterns)
449 $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
451 function yy_r4_3($yy_subpatterns)
454 $this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
466 if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
467 return false; // end of input
469 $yy_global_pattern = "/\G(\\.)|\G(.*?(?=[\.=[\]\r\n]))/iS";
472 if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) {
473 $yysubmatches = $yymatches;
474 $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
475 if (!count($yymatches)) {
476 throw new Exception('Error: lexing failed because a rule matched' .
477 ' an empty string. Input "' . substr($this->data,
478 $this->counter, 5) . '... state SECTION');
480 next($yymatches); // skip global match
481 $this->token = key($yymatches); // token number
482 if ($tokenMap[$this->token]) {
483 // extract sub-patterns for passing to lex function
484 $yysubmatches = array_slice($yysubmatches, $this->token + 1,
485 $tokenMap[$this->token]);
487 $yysubmatches = array();
489 $this->value = current($yymatches); // token value
490 $r = $this->{'yy_r5_' . $this->token}($yysubmatches);
492 $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
493 $this->line += substr_count($this->value, "\n");
496 } elseif ($r === true) {
497 // we have changed state
498 // process this token in the new state
499 return $this->yylex();
500 } elseif ($r === false) {
501 $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
502 $this->line += substr_count($this->value, "\n");
503 if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
504 return false; // end of input
509 throw new Exception('Unexpected input at line' . $this->line .
510 ': ' . $this->data[$this->counter]);
519 function yy_r5_1($yy_subpatterns)
522 $this->token = Smarty_Internal_Configfileparser::TPC_DOT;
524 function yy_r5_2($yy_subpatterns)
527 $this->token = Smarty_Internal_Configfileparser::TPC_SECTION;
538 if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
539 return false; // end of input
541 $yy_global_pattern = "/\G(\"\"\"(?=[ \t\r]*[\n#;]))|\G([\S\s])/iS";
544 if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) {
545 $yysubmatches = $yymatches;
546 $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
547 if (!count($yymatches)) {
548 throw new Exception('Error: lexing failed because a rule matched' .
549 ' an empty string. Input "' . substr($this->data,
550 $this->counter, 5) . '... state TRIPPLE');
552 next($yymatches); // skip global match
553 $this->token = key($yymatches); // token number
554 if ($tokenMap[$this->token]) {
555 // extract sub-patterns for passing to lex function
556 $yysubmatches = array_slice($yysubmatches, $this->token + 1,
557 $tokenMap[$this->token]);
559 $yysubmatches = array();
561 $this->value = current($yymatches); // token value
562 $r = $this->{'yy_r6_' . $this->token}($yysubmatches);
564 $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
565 $this->line += substr_count($this->value, "\n");
568 } elseif ($r === true) {
569 // we have changed state
570 // process this token in the new state
571 return $this->yylex();
572 } elseif ($r === false) {
573 $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
574 $this->line += substr_count($this->value, "\n");
575 if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
576 return false; // end of input
581 throw new Exception('Unexpected input at line' . $this->line .
582 ': ' . $this->data[$this->counter]);
591 function yy_r6_1($yy_subpatterns)
594 $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES_END;
596 $this->yypushstate(self::START);
598 function yy_r6_2($yy_subpatterns)
601 if ($this->mbstring_overload) {
602 $to = mb_strlen($this->data,'latin1');
604 $to = strlen($this->data);
606 preg_match("/\"\"\"[ \t\r]*[\n#;]/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
607 if (isset($match[0][1])) {
610 $this->compiler->trigger_template_error ("missing or misspelled literal closing tag");
612 if ($this->mbstring_overload) {
613 $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1');
615 $this->value = substr($this->data,$this->counter,$to-$this->counter);
617 $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_TEXT;