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