]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_configfilelexer.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_configfilelexer.php
1 <?php
2 /**
3  * Smarty Internal Plugin Configfilelexer
4  *
5  * This is the lexer to break the config file source into tokens
6  *
7  * @package    Smarty
8  * @subpackage Config
9  * @author     Uwe Tews
10  */
11
12 /**
13  * Smarty_Internal_Configfilelexer
14  *
15  * This is the config file lexer.
16  * It is generated from the smarty_internal_configfilelexer.plex file
17  *
18  * @package    Smarty
19  * @subpackage Compiler
20  * @author     Uwe Tews
21  */
22 class Smarty_Internal_Configfilelexer
23 {
24     /**
25      * Source
26      *
27      * @var string
28      */
29     public $data;
30
31     /**
32      * Source length
33      *
34      * @var int
35      */
36     public $dataLength = null;
37
38     /**
39      * byte counter
40      *
41      * @var int
42      */
43     public $counter;
44
45     /**
46      * token number
47      *
48      * @var int
49      */
50     public $token;
51
52     /**
53      * token value
54      *
55      * @var string
56      */
57     public $value;
58
59     /**
60      * current line
61      *
62      * @var int
63      */
64     public $line;
65
66     /**
67      * state number
68      *
69      * @var int
70      */
71     public $state = 1;
72
73     /**
74      * Smarty object
75      *
76      * @var Smarty
77      */
78     public $smarty = null;
79
80     /**
81      * compiler object
82      *
83      * @var Smarty_Internal_Config_File_Compiler
84      */
85     private $compiler = null;
86
87     /**
88      * copy of config_booleanize
89      *
90      * @var bool
91      */
92     private $configBooleanize = false;
93
94     /**
95      * trace file
96      *
97      * @var resource
98      */
99     public $yyTraceFILE;
100
101     /**
102      * trace prompt
103      *
104      * @var string
105      */
106     public $yyTracePrompt;
107
108     /**
109      * state names
110      *
111      * @var array
112      */
113     public $state_name = array(1 => 'START', 2 => 'VALUE', 3 => 'NAKED_STRING_VALUE', 4 => 'COMMENT', 5 => 'SECTION',
114                                6 => 'TRIPPLE');
115
116     /**
117      * storage for assembled token patterns
118      *
119      * @var string
120      */
121     private $yy_global_pattern1 = null;
122
123     private $yy_global_pattern2 = null;
124
125     private $yy_global_pattern3 = null;
126
127     private $yy_global_pattern4 = null;
128
129     private $yy_global_pattern5 = null;
130
131     private $yy_global_pattern6 = null;
132
133     /**
134      * token names
135      *
136      * @var array
137      */
138     public $smarty_token_names = array(        // Text for parser error messages
139     );
140
141     /**
142      * constructor
143      *
144      * @param   string                             $data template source
145      * @param Smarty_Internal_Config_File_Compiler $compiler
146      */
147     function __construct($data, Smarty_Internal_Config_File_Compiler $compiler)
148     {
149         $this->data = $data . "\n"; //now all lines are \n-terminated
150         $this->dataLength = strlen($data);
151         $this->counter = 0;
152         if (preg_match('/^\xEF\xBB\xBF/', $this->data, $match)) {
153             $this->counter += strlen($match[ 0 ]);
154         }
155         $this->line = 1;
156         $this->compiler = $compiler;
157         $this->smarty = $compiler->smarty;
158         $this->configBooleanize = $this->smarty->config_booleanize;
159     }
160
161     public function PrintTrace()
162     {
163         $this->yyTraceFILE = fopen('php://output', 'w');
164         $this->yyTracePrompt = '<br>';
165     }
166
167     private $_yy_state = 1;
168
169     private $_yy_stack = array();
170
171     public function yylex()
172     {
173         return $this->{'yylex' . $this->_yy_state}();
174     }
175
176     public function yypushstate($state)
177     {
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 ] :
181                         $this->_yy_state);
182         }
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 ] :
188                         $this->_yy_state);
189         }
190     }
191
192     public function yypopstate()
193     {
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 ] :
197                         $this->_yy_state);
198         }
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 ] :
203                         $this->_yy_state);
204         }
205     }
206
207     public function yybegin($state)
208     {
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 ] :
213                         $this->_yy_state);
214         }
215     }
216
217     public function yylex1()
218     {
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";
222         }
223         if (!isset($this->dataLength)) {
224             $this->dataLength = strlen($this->data);
225         }
226         if ($this->counter >= $this->dataLength) {
227             return false; // end of input
228         }
229
230         do {
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);
234                 } else {
235                     $yymatches = array_filter($yymatches);
236                 }
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');
240                 }
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}();
245                 if ($r === null) {
246                     $this->counter += strlen($this->value);
247                     $this->line += substr_count($this->value, "\n");
248                     // accept this token
249                     return true;
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
259                     }
260                     // skip this token
261                     continue;
262                 }
263             } else {
264                 throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
265             }
266             break;
267         }
268         while (true);
269     } // end function
270
271     const START = 1;
272
273     function yy_r1_1()
274     {
275
276         $this->token = Smarty_Internal_Configfileparser::TPC_COMMENTSTART;
277         $this->yypushstate(self::COMMENT);
278     }
279
280     function yy_r1_2()
281     {
282
283         $this->token = Smarty_Internal_Configfileparser::TPC_OPENB;
284         $this->yypushstate(self::SECTION);
285     }
286
287     function yy_r1_3()
288     {
289
290         $this->token = Smarty_Internal_Configfileparser::TPC_CLOSEB;
291     }
292
293     function yy_r1_4()
294     {
295
296         $this->token = Smarty_Internal_Configfileparser::TPC_EQUAL;
297         $this->yypushstate(self::VALUE);
298     }
299
300     function yy_r1_5()
301     {
302
303         return false;
304     }
305
306     function yy_r1_6()
307     {
308
309         $this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
310     }
311
312     function yy_r1_7()
313     {
314
315         $this->token = Smarty_Internal_Configfileparser::TPC_ID;
316     }
317
318     function yy_r1_8()
319     {
320
321         $this->token = Smarty_Internal_Configfileparser::TPC_OTHER;
322     }
323
324     public function yylex2()
325     {
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";
329         }
330         if (!isset($this->dataLength)) {
331             $this->dataLength = strlen($this->data);
332         }
333         if ($this->counter >= $this->dataLength) {
334             return false; // end of input
335         }
336
337         do {
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);
341                 } else {
342                     $yymatches = array_filter($yymatches);
343                 }
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');
347                 }
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}();
352                 if ($r === null) {
353                     $this->counter += strlen($this->value);
354                     $this->line += substr_count($this->value, "\n");
355                     // accept this token
356                     return true;
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
366                     }
367                     // skip this token
368                     continue;
369                 }
370             } else {
371                 throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
372             }
373             break;
374         }
375         while (true);
376     } // end function
377
378     const VALUE = 2;
379
380     function yy_r2_1()
381     {
382
383         return false;
384     }
385
386     function yy_r2_2()
387     {
388
389         $this->token = Smarty_Internal_Configfileparser::TPC_FLOAT;
390         $this->yypopstate();
391     }
392
393     function yy_r2_3()
394     {
395
396         $this->token = Smarty_Internal_Configfileparser::TPC_INT;
397         $this->yypopstate();
398     }
399
400     function yy_r2_4()
401     {
402
403         $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES;
404         $this->yypushstate(self::TRIPPLE);
405     }
406
407     function yy_r2_5()
408     {
409
410         $this->token = Smarty_Internal_Configfileparser::TPC_SINGLE_QUOTED_STRING;
411         $this->yypopstate();
412     }
413
414     function yy_r2_6()
415     {
416
417         $this->token = Smarty_Internal_Configfileparser::TPC_DOUBLE_QUOTED_STRING;
418         $this->yypopstate();
419     }
420
421     function yy_r2_7()
422     {
423
424         if (!$this->configBooleanize ||
425             !in_array(strtolower($this->value), Array("true", "false", "on", "off", "yes", "no"))
426         ) {
427             $this->yypopstate();
428             $this->yypushstate(self::NAKED_STRING_VALUE);
429             return true; //reprocess in new state
430         } else {
431             $this->token = Smarty_Internal_Configfileparser::TPC_BOOL;
432             $this->yypopstate();
433         }
434     }
435
436     function yy_r2_8()
437     {
438
439         $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
440         $this->yypopstate();
441     }
442
443     function yy_r2_9()
444     {
445
446         $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
447         $this->value = "";
448         $this->yypopstate();
449     }
450
451     public function yylex3()
452     {
453         if (!isset($this->yy_global_pattern3)) {
454             $this->yy_global_pattern3 = "/\G([^\n]+?(?=[ \t\r]*\n))/isS";
455         }
456         if (!isset($this->dataLength)) {
457             $this->dataLength = strlen($this->data);
458         }
459         if ($this->counter >= $this->dataLength) {
460             return false; // end of input
461         }
462
463         do {
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);
467                 } else {
468                     $yymatches = array_filter($yymatches);
469                 }
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');
473                 }
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}();
478                 if ($r === null) {
479                     $this->counter += strlen($this->value);
480                     $this->line += substr_count($this->value, "\n");
481                     // accept this token
482                     return true;
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
492                     }
493                     // skip this token
494                     continue;
495                 }
496             } else {
497                 throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
498             }
499             break;
500         }
501         while (true);
502     } // end function
503
504     const NAKED_STRING_VALUE = 3;
505
506     function yy_r3_1()
507     {
508
509         $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
510         $this->yypopstate();
511     }
512
513     public function yylex4()
514     {
515         if (!isset($this->yy_global_pattern4)) {
516             $this->yy_global_pattern4 = "/\G([ \t\r]+)|\G([^\n]+?(?=[ \t\r]*\n))|\G(\n)/isS";
517         }
518         if (!isset($this->dataLength)) {
519             $this->dataLength = strlen($this->data);
520         }
521         if ($this->counter >= $this->dataLength) {
522             return false; // end of input
523         }
524
525         do {
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);
529                 } else {
530                     $yymatches = array_filter($yymatches);
531                 }
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');
535                 }
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}();
540                 if ($r === null) {
541                     $this->counter += strlen($this->value);
542                     $this->line += substr_count($this->value, "\n");
543                     // accept this token
544                     return true;
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
554                     }
555                     // skip this token
556                     continue;
557                 }
558             } else {
559                 throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
560             }
561             break;
562         }
563         while (true);
564     } // end function
565
566     const COMMENT = 4;
567
568     function yy_r4_1()
569     {
570
571         return false;
572     }
573
574     function yy_r4_2()
575     {
576
577         $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
578     }
579
580     function yy_r4_3()
581     {
582
583         $this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
584         $this->yypopstate();
585     }
586
587     public function yylex5()
588     {
589         if (!isset($this->yy_global_pattern5)) {
590             $this->yy_global_pattern5 = "/\G(\\.)|\G(.*?(?=[\.=[\]\r\n]))/isS";
591         }
592         if (!isset($this->dataLength)) {
593             $this->dataLength = strlen($this->data);
594         }
595         if ($this->counter >= $this->dataLength) {
596             return false; // end of input
597         }
598
599         do {
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);
603                 } else {
604                     $yymatches = array_filter($yymatches);
605                 }
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');
609                 }
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}();
614                 if ($r === null) {
615                     $this->counter += strlen($this->value);
616                     $this->line += substr_count($this->value, "\n");
617                     // accept this token
618                     return true;
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
628                     }
629                     // skip this token
630                     continue;
631                 }
632             } else {
633                 throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
634             }
635             break;
636         }
637         while (true);
638     } // end function
639
640     const SECTION = 5;
641
642     function yy_r5_1()
643     {
644
645         $this->token = Smarty_Internal_Configfileparser::TPC_DOT;
646     }
647
648     function yy_r5_2()
649     {
650
651         $this->token = Smarty_Internal_Configfileparser::TPC_SECTION;
652         $this->yypopstate();
653     }
654
655     public function yylex6()
656     {
657         if (!isset($this->yy_global_pattern6)) {
658             $this->yy_global_pattern6 = "/\G(\"\"\"(?=[ \t\r]*[\n#;]))|\G([\S\s])/isS";
659         }
660         if (!isset($this->dataLength)) {
661             $this->dataLength = strlen($this->data);
662         }
663         if ($this->counter >= $this->dataLength) {
664             return false; // end of input
665         }
666
667         do {
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);
671                 } else {
672                     $yymatches = array_filter($yymatches);
673                 }
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');
677                 }
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}();
682                 if ($r === null) {
683                     $this->counter += strlen($this->value);
684                     $this->line += substr_count($this->value, "\n");
685                     // accept this token
686                     return true;
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
696                     }
697                     // skip this token
698                     continue;
699                 }
700             } else {
701                 throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
702             }
703             break;
704         }
705         while (true);
706     } // end function
707
708     const TRIPPLE = 6;
709
710     function yy_r6_1()
711     {
712
713         $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES_END;
714         $this->yypopstate();
715         $this->yypushstate(self::START);
716     }
717
718     function yy_r6_2()
719     {
720
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 ];
725         } else {
726             $this->compiler->trigger_template_error("missing or misspelled literal closing tag");
727         }
728         $this->value = substr($this->data, $this->counter, $to - $this->counter);
729         $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_TEXT;
730     }
731
732 }