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