source: trunk/include/smarty/libs/sysplugins/smarty_internal_templatelexer.php @ 23485

Last change on this file since 23485 was 23485, checked in by rvelices, 11 years ago

Smarty EOL style LF svn property

  • Property svn:eol-style set to LF
File size: 38.2 KB
Line 
1<?php
2/**
3* Smarty Internal Plugin Templatelexer
4*
5* This is the lexer to break the template source into tokens
6* @package Smarty
7* @subpackage Compiler
8* @author Uwe Tews
9*/
10/**
11* Smarty Internal Plugin Templatelexer
12*/
13class Smarty_Internal_Templatelexer
14{
15    public $data;
16    public $counter;
17    public $token;
18    public $value;
19    public $node;
20    public $line;
21    public $taglineno;
22    public $state = 1;
23    private $heredoc_id_stack = Array();
24    public $smarty_token_names = array (                // Text for parser error messages
25                                'IDENTITY'      => '===',
26                                'NONEIDENTITY'  => '!==',
27                                'EQUALS'        => '==',
28                                'NOTEQUALS'     => '!=',
29                                'GREATEREQUAL' => '(>=,ge)',
30                                'LESSEQUAL' => '(<=,le)',
31                                'GREATERTHAN' => '(>,gt)',
32                                'LESSTHAN' => '(<,lt)',
33                                'MOD' => '(%,mod)',
34                                'NOT'                   => '(!,not)',
35                                'LAND'          => '(&&,and)',
36                                'LOR'                   => '(||,or)',
37                                'LXOR'                  => 'xor',
38                                'OPENP'         => '(',
39                                'CLOSEP'        => ')',
40                                'OPENB'         => '[',
41                                'CLOSEB'        => ']',
42                                'PTR'                   => '->',
43                                'APTR'          => '=>',
44                                'EQUAL'         => '=',
45                                'NUMBER'        => 'number',
46                                'UNIMATH'       => '+" , "-',
47                                'MATH'          => '*" , "/" , "%',
48                                'INCDEC'        => '++" , "--',
49                                'SPACE'         => ' ',
50                                'DOLLAR'        => '$',
51                                'SEMICOLON' => ';',
52                                'COLON'         => ':',
53                                'DOUBLECOLON'           => '::',
54                                'AT'            => '@',
55                                'HATCH'         => '#',
56                                'QUOTE'         => '"',
57                                'BACKTICK'              => '`',
58                                'VERT'          => '|',
59                                'DOT'                   => '.',
60                                'COMMA'         => '","',
61                                'ANDSYM'                => '"&"',
62                                'QMARK'         => '"?"',
63                                'ID'                    => 'identifier',
64                                'TEXT'          => 'text',
65                                'FAKEPHPSTARTTAG'       => 'Fake PHP start tag',
66                                'PHPSTARTTAG'   => 'PHP start tag',
67                                'PHPENDTAG'     => 'PHP end tag',
68                                                'LITERALSTART'  => 'Literal start',
69                                                'LITERALEND'    => 'Literal end',
70                                'LDELSLASH' => 'closing tag',
71                                'COMMENT' => 'comment',
72                                'AS' => 'as',
73                                'TO' => 'to',
74                                );
75
76
77    function __construct($data,$compiler)
78    {
79//        $this->data = preg_replace("/(\r\n|\r|\n)/", "\n", $data);
80        $this->data = $data;
81        $this->counter = 0;
82        $this->line = 1;
83        $this->smarty = $compiler->smarty;
84        $this->compiler = $compiler;
85        $this->ldel = preg_quote($this->smarty->left_delimiter,'/');
86        $this->ldel_length = strlen($this->smarty->left_delimiter);
87        $this->rdel = preg_quote($this->smarty->right_delimiter,'/');
88        $this->rdel_length = strlen($this->smarty->right_delimiter);
89        $this->smarty_token_names['LDEL'] =     $this->smarty->left_delimiter;
90        $this->smarty_token_names['RDEL'] =     $this->smarty->right_delimiter;
91        $this->mbstring_overload = ini_get('mbstring.func_overload') & 2;
92     }
93
94
95    private $_yy_state = 1;
96    private $_yy_stack = array();
97
98    function yylex()
99    {
100        return $this->{'yylex' . $this->_yy_state}();
101    }
102
103    function yypushstate($state)
104    {
105        array_push($this->_yy_stack, $this->_yy_state);
106        $this->_yy_state = $state;
107    }
108
109    function yypopstate()
110    {
111        $this->_yy_state = array_pop($this->_yy_stack);
112    }
113
114    function yybegin($state)
115    {
116        $this->_yy_state = $state;
117    }
118
119
120
121    function yylex1()
122    {
123        $tokenMap = array (
124              1 => 0,
125              2 => 0,
126              3 => 1,
127              5 => 0,
128              6 => 0,
129              7 => 0,
130              8 => 0,
131              9 => 0,
132              10 => 0,
133              11 => 1,
134              13 => 0,
135              14 => 0,
136              15 => 0,
137              16 => 0,
138              17 => 0,
139              18 => 0,
140              19 => 0,
141              20 => 0,
142              21 => 0,
143              22 => 0,
144              23 => 0,
145              24 => 0,
146            );
147        if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
148            return false; // end of input
149        }
150        $yy_global_pattern = "/\G(".$this->ldel."[$]smarty\\.block\\.child".$this->rdel.")|\G(\\{\\})|\G(".$this->ldel."\\*([\S\s]*?)\\*".$this->rdel.")|\G(".$this->ldel."strip".$this->rdel.")|\G(".$this->ldel."\\s{1,}strip\\s{1,}".$this->rdel.")|\G(".$this->ldel."\/strip".$this->rdel.")|\G(".$this->ldel."\\s{1,}\/strip\\s{1,}".$this->rdel.")|\G(".$this->ldel."\\s*literal\\s*".$this->rdel.")|\G(".$this->ldel."\\s{1,}\/)|\G(".$this->ldel."\\s*(if|elseif|else if|while)\\s+)|\G(".$this->ldel."\\s*for\\s+)|\G(".$this->ldel."\\s*foreach(?![^\s]))|\G(".$this->ldel."\\s*setfilter\\s+)|\G(".$this->ldel."\\s{1,})|\G(".$this->ldel."\/)|\G(".$this->ldel.")|\G(<\\?(?:php\\w+|=|[a-zA-Z]+)?)|\G(\\?>)|\G(".$this->rdel.")|\G(<%)|\G(%>)|\G([\S\s])/iS";
151
152        do {
153            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)) {
154                $yysubmatches = $yymatches;
155                $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
156                if (!count($yymatches)) {
157                    throw new Exception('Error: lexing failed because a rule matched' .
158                        ' an empty string.  Input "' . substr($this->data,
159                        $this->counter, 5) . '... state TEXT');
160                }
161                next($yymatches); // skip global match
162                $this->token = key($yymatches); // token number
163                if ($tokenMap[$this->token]) {
164                    // extract sub-patterns for passing to lex function
165                    $yysubmatches = array_slice($yysubmatches, $this->token + 1,
166                        $tokenMap[$this->token]);
167                } else {
168                    $yysubmatches = array();
169                }
170                $this->value = current($yymatches); // token value
171                $r = $this->{'yy_r1_' . $this->token}($yysubmatches);
172                if ($r === null) {
173                    $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
174                    $this->line += substr_count($this->value, "\n");
175                    // accept this token
176                    return true;
177                } elseif ($r === true) {
178                    // we have changed state
179                    // process this token in the new state
180                    return $this->yylex();
181                } elseif ($r === false) {
182                    $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
183                    $this->line += substr_count($this->value, "\n");
184                    if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
185                        return false; // end of input
186                    }
187                    // skip this token
188                    continue;
189                }            } else {
190                throw new Exception('Unexpected input at line' . $this->line .
191                    ': ' . $this->data[$this->counter]);
192            }
193            break;
194        } while (true);
195
196    } // end function
197
198
199    const TEXT = 1;
200    function yy_r1_1($yy_subpatterns)
201    {
202
203  $this->token = Smarty_Internal_Templateparser::TP_SMARTYBLOCKCHILD;
204    }
205    function yy_r1_2($yy_subpatterns)
206    {
207
208  $this->token = Smarty_Internal_Templateparser::TP_TEXT;
209    }
210    function yy_r1_3($yy_subpatterns)
211    {
212
213  $this->token = Smarty_Internal_Templateparser::TP_COMMENT;
214    }
215    function yy_r1_5($yy_subpatterns)
216    {
217
218    $this->token = Smarty_Internal_Templateparser::TP_STRIPON;
219    }
220    function yy_r1_6($yy_subpatterns)
221    {
222
223  if ($this->smarty->auto_literal) {
224    $this->token = Smarty_Internal_Templateparser::TP_TEXT;
225  } else {
226    $this->token = Smarty_Internal_Templateparser::TP_STRIPON;
227  }
228    }
229    function yy_r1_7($yy_subpatterns)
230    {
231
232    $this->token = Smarty_Internal_Templateparser::TP_STRIPOFF;
233    }
234    function yy_r1_8($yy_subpatterns)
235    {
236
237  if ($this->smarty->auto_literal) {
238     $this->token = Smarty_Internal_Templateparser::TP_TEXT;
239  } else {
240    $this->token = Smarty_Internal_Templateparser::TP_STRIPOFF;
241  }
242    }
243    function yy_r1_9($yy_subpatterns)
244    {
245
246   $this->token = Smarty_Internal_Templateparser::TP_LITERALSTART;
247   $this->yypushstate(self::LITERAL);
248    }
249    function yy_r1_10($yy_subpatterns)
250    {
251
252  if ($this->smarty->auto_literal) {
253     $this->token = Smarty_Internal_Templateparser::TP_TEXT;
254  } else {
255     $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH;
256     $this->yypushstate(self::SMARTY);
257     $this->taglineno = $this->line;
258  }
259    }
260    function yy_r1_11($yy_subpatterns)
261    {
262
263  if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
264     $this->token = Smarty_Internal_Templateparser::TP_TEXT;
265  } else {
266     $this->token = Smarty_Internal_Templateparser::TP_LDELIF;
267     $this->yypushstate(self::SMARTY);
268     $this->taglineno = $this->line;
269  }
270    }
271    function yy_r1_13($yy_subpatterns)
272    {
273
274  if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
275     $this->token = Smarty_Internal_Templateparser::TP_TEXT;
276  } else {
277     $this->token = Smarty_Internal_Templateparser::TP_LDELFOR;
278     $this->yypushstate(self::SMARTY);
279     $this->taglineno = $this->line;
280  }
281    }
282    function yy_r1_14($yy_subpatterns)
283    {
284
285  if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
286     $this->token = Smarty_Internal_Templateparser::TP_TEXT;
287  } else {
288     $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH;
289     $this->yypushstate(self::SMARTY);
290     $this->taglineno = $this->line;
291  }
292    }
293    function yy_r1_15($yy_subpatterns)
294    {
295
296  if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
297     $this->token = Smarty_Internal_Templateparser::TP_TEXT;
298  } else {
299     $this->token = Smarty_Internal_Templateparser::TP_LDELSETFILTER;
300     $this->yypushstate(self::SMARTY);
301     $this->taglineno = $this->line;
302  }
303    }
304    function yy_r1_16($yy_subpatterns)
305    {
306
307  if ($this->smarty->auto_literal) {
308     $this->token = Smarty_Internal_Templateparser::TP_TEXT;
309  } else {
310     $this->token = Smarty_Internal_Templateparser::TP_LDEL;
311     $this->yypushstate(self::SMARTY);
312     $this->taglineno = $this->line;
313  }
314    }
315    function yy_r1_17($yy_subpatterns)
316    {
317
318  $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH;
319     $this->yypushstate(self::SMARTY);
320     $this->taglineno = $this->line;
321    }
322    function yy_r1_18($yy_subpatterns)
323    {
324
325  $this->token = Smarty_Internal_Templateparser::TP_LDEL;
326     $this->yypushstate(self::SMARTY);
327     $this->taglineno = $this->line;
328    }
329    function yy_r1_19($yy_subpatterns)
330    {
331
332  if (in_array($this->value, Array('<?', '<?=', '<?php'))) {
333    $this->token = Smarty_Internal_Templateparser::TP_PHPSTARTTAG;
334  } elseif ($this->value == '<?xml') {
335      $this->token = Smarty_Internal_Templateparser::TP_XMLTAG;
336  } else {
337    $this->token = Smarty_Internal_Templateparser::TP_FAKEPHPSTARTTAG;
338    $this->value = substr($this->value, 0, 2);
339  }
340     }
341    function yy_r1_20($yy_subpatterns)
342    {
343
344  $this->token = Smarty_Internal_Templateparser::TP_PHPENDTAG;
345    }
346    function yy_r1_21($yy_subpatterns)
347    {
348
349  $this->token = Smarty_Internal_Templateparser::TP_TEXT;
350    }
351    function yy_r1_22($yy_subpatterns)
352    {
353
354  $this->token = Smarty_Internal_Templateparser::TP_ASPSTARTTAG;
355    }
356    function yy_r1_23($yy_subpatterns)
357    {
358
359  $this->token = Smarty_Internal_Templateparser::TP_ASPENDTAG;
360    }
361    function yy_r1_24($yy_subpatterns)
362    {
363
364  if ($this->mbstring_overload) {
365    $to = mb_strlen($this->data,'latin1');
366  } else {
367    $to = strlen($this->data);
368  }
369  preg_match("/{$this->ldel}|<\?|\?>|<%|%>/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
370  if (isset($match[0][1])) {
371    $to = $match[0][1];
372  }
373  if ($this->mbstring_overload) {
374    $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1');
375  } else {
376    $this->value = substr($this->data,$this->counter,$to-$this->counter);
377  }
378  $this->token = Smarty_Internal_Templateparser::TP_TEXT;
379    }
380
381
382    function yylex2()
383    {
384        $tokenMap = array (
385              1 => 0,
386              2 => 0,
387              3 => 1,
388              5 => 0,
389              6 => 0,
390              7 => 0,
391              8 => 0,
392              9 => 0,
393              10 => 0,
394              11 => 0,
395              12 => 0,
396              13 => 0,
397              14 => 0,
398              15 => 0,
399              16 => 0,
400              17 => 0,
401              18 => 0,
402              19 => 0,
403              20 => 1,
404              22 => 1,
405              24 => 1,
406              26 => 0,
407              27 => 0,
408              28 => 0,
409              29 => 0,
410              30 => 0,
411              31 => 0,
412              32 => 0,
413              33 => 0,
414              34 => 0,
415              35 => 0,
416              36 => 0,
417              37 => 0,
418              38 => 0,
419              39 => 0,
420              40 => 0,
421              41 => 0,
422              42 => 0,
423              43 => 3,
424              47 => 0,
425              48 => 0,
426              49 => 0,
427              50 => 0,
428              51 => 0,
429              52 => 0,
430              53 => 0,
431              54 => 0,
432              55 => 1,
433              57 => 1,
434              59 => 0,
435              60 => 0,
436              61 => 0,
437              62 => 0,
438              63 => 0,
439              64 => 0,
440              65 => 0,
441              66 => 0,
442              67 => 0,
443              68 => 0,
444              69 => 0,
445              70 => 0,
446              71 => 0,
447              72 => 0,
448              73 => 0,
449              74 => 0,
450              75 => 0,
451              76 => 0,
452              77 => 0,
453            );
454        if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
455            return false; // end of input
456        }
457        $yy_global_pattern = "/\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|\G(".$this->ldel."\\s{1,}\/)|\G(".$this->ldel."\\s*(if|elseif|else if|while)\\s+)|\G(".$this->ldel."\\s*for\\s+)|\G(".$this->ldel."\\s*foreach(?![^\s]))|\G(".$this->ldel."\\s{1,})|\G(\\s{1,}".$this->rdel.")|\G(".$this->ldel."\/)|\G(".$this->ldel.")|\G(".$this->rdel.")|\G(\\s+is\\s+in\\s+)|\G(\\s+as\\s+)|\G(\\s+to\\s+)|\G(\\s+step\\s+)|\G(\\s+instanceof\\s+)|\G(\\s*===\\s*)|\G(\\s*!==\\s*)|\G(\\s*==\\s*|\\s+eq\\s+)|\G(\\s*!=\\s*|\\s*<>\\s*|\\s+(ne|neq)\\s+)|\G(\\s*>=\\s*|\\s+(ge|gte)\\s+)|\G(\\s*<=\\s*|\\s+(le|lte)\\s+)|\G(\\s*>\\s*|\\s+gt\\s+)|\G(\\s*<\\s*|\\s+lt\\s+)|\G(\\s+mod\\s+)|\G(!\\s*|not\\s+)|\G(\\s*&&\\s*|\\s*and\\s+)|\G(\\s*\\|\\|\\s*|\\s*or\\s+)|\G(\\s*xor\\s+)|\G(\\s+is\\s+odd\\s+by\\s+)|\G(\\s+is\\s+not\\s+odd\\s+by\\s+)|\G(\\s+is\\s+odd)|\G(\\s+is\\s+not\\s+odd)|\G(\\s+is\\s+even\\s+by\\s+)|\G(\\s+is\\s+not\\s+even\\s+by\\s+)|\G(\\s+is\\s+even)|\G(\\s+is\\s+not\\s+even)|\G(\\s+is\\s+div\\s+by\\s+)|\G(\\s+is\\s+not\\s+div\\s+by\\s+)|\G(\\((int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)\\)\\s*)|\G(\\s*\\(\\s*)|\G(\\s*\\))|\G(\\[\\s*)|\G(\\s*\\])|\G(\\s*->\\s*)|\G(\\s*=>\\s*)|\G(\\s*=\\s*)|\G(\\+\\+|--)|\G(\\s*(\\+|-)\\s*)|\G(\\s*(\\*|\/|%)\\s*)|\G(\\$)|\G(\\s*;)|\G(::)|\G(\\s*:\\s*)|\G(@)|\G(#)|\G(\")|\G(`)|\G(\\|)|\G(\\.)|\G(\\s*,\\s*)|\G(\\s*&\\s*)|\G(\\s*\\?\\s*)|\G(0[xX][0-9a-fA-F]+)|\G(\\s+[0-9]*[a-zA-Z_][a-zA-Z0-9_\-:]*\\s*=\\s*)|\G([0-9]*[a-zA-Z_]\\w*)|\G(\\d+)|\G(\\s+)|\G([\S\s])/iS";
458
459        do {
460            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)) {
461                $yysubmatches = $yymatches;
462                $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
463                if (!count($yymatches)) {
464                    throw new Exception('Error: lexing failed because a rule matched' .
465                        ' an empty string.  Input "' . substr($this->data,
466                        $this->counter, 5) . '... state SMARTY');
467                }
468                next($yymatches); // skip global match
469                $this->token = key($yymatches); // token number
470                if ($tokenMap[$this->token]) {
471                    // extract sub-patterns for passing to lex function
472                    $yysubmatches = array_slice($yysubmatches, $this->token + 1,
473                        $tokenMap[$this->token]);
474                } else {
475                    $yysubmatches = array();
476                }
477                $this->value = current($yymatches); // token value
478                $r = $this->{'yy_r2_' . $this->token}($yysubmatches);
479                if ($r === null) {
480                    $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
481                    $this->line += substr_count($this->value, "\n");
482                    // accept this token
483                    return true;
484                } elseif ($r === true) {
485                    // we have changed state
486                    // process this token in the new state
487                    return $this->yylex();
488                } elseif ($r === false) {
489                    $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
490                    $this->line += substr_count($this->value, "\n");
491                    if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
492                        return false; // end of input
493                    }
494                    // skip this token
495                    continue;
496                }            } else {
497                throw new Exception('Unexpected input at line' . $this->line .
498                    ': ' . $this->data[$this->counter]);
499            }
500            break;
501        } while (true);
502
503    } // end function
504
505
506    const SMARTY = 2;
507    function yy_r2_1($yy_subpatterns)
508    {
509
510  $this->token = Smarty_Internal_Templateparser::TP_SINGLEQUOTESTRING;
511    }
512    function yy_r2_2($yy_subpatterns)
513    {
514
515  if ($this->smarty->auto_literal) {
516     $this->token = Smarty_Internal_Templateparser::TP_TEXT;
517  } else {
518     $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH;
519     $this->yypushstate(self::SMARTY);
520     $this->taglineno = $this->line;
521  }
522    }
523    function yy_r2_3($yy_subpatterns)
524    {
525
526  if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
527     $this->token = Smarty_Internal_Templateparser::TP_TEXT;
528  } else {
529     $this->token = Smarty_Internal_Templateparser::TP_LDELIF;
530     $this->yypushstate(self::SMARTY);
531     $this->taglineno = $this->line;
532  }
533    }
534    function yy_r2_5($yy_subpatterns)
535    {
536
537  if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
538     $this->token = Smarty_Internal_Templateparser::TP_TEXT;
539  } else {
540     $this->token = Smarty_Internal_Templateparser::TP_LDELFOR;
541     $this->yypushstate(self::SMARTY);
542     $this->taglineno = $this->line;
543  }
544    }
545    function yy_r2_6($yy_subpatterns)
546    {
547
548  if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
549     $this->token = Smarty_Internal_Templateparser::TP_TEXT;
550  } else {
551     $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH;
552     $this->yypushstate(self::SMARTY);
553     $this->taglineno = $this->line;
554  }
555    }
556    function yy_r2_7($yy_subpatterns)
557    {
558
559  if ($this->smarty->auto_literal) {
560     $this->token = Smarty_Internal_Templateparser::TP_TEXT;
561  } else {
562     $this->token = Smarty_Internal_Templateparser::TP_LDEL;
563     $this->yypushstate(self::SMARTY);
564     $this->taglineno = $this->line;
565  }
566    }
567    function yy_r2_8($yy_subpatterns)
568    {
569
570  $this->token = Smarty_Internal_Templateparser::TP_RDEL;
571  $this->yypopstate();
572    }
573    function yy_r2_9($yy_subpatterns)
574    {
575
576  $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH;
577     $this->yypushstate(self::SMARTY);
578     $this->taglineno = $this->line;
579    }
580    function yy_r2_10($yy_subpatterns)
581    {
582
583  $this->token = Smarty_Internal_Templateparser::TP_LDEL;
584     $this->yypushstate(self::SMARTY);
585     $this->taglineno = $this->line;
586    }
587    function yy_r2_11($yy_subpatterns)
588    {
589
590  $this->token = Smarty_Internal_Templateparser::TP_RDEL;
591     $this->yypopstate();
592    }
593    function yy_r2_12($yy_subpatterns)
594    {
595
596  $this->token = Smarty_Internal_Templateparser::TP_ISIN;
597    }
598    function yy_r2_13($yy_subpatterns)
599    {
600
601  $this->token = Smarty_Internal_Templateparser::TP_AS;
602    }
603    function yy_r2_14($yy_subpatterns)
604    {
605
606  $this->token = Smarty_Internal_Templateparser::TP_TO;
607    }
608    function yy_r2_15($yy_subpatterns)
609    {
610
611  $this->token = Smarty_Internal_Templateparser::TP_STEP;
612    }
613    function yy_r2_16($yy_subpatterns)
614    {
615
616  $this->token = Smarty_Internal_Templateparser::TP_INSTANCEOF;
617    }
618    function yy_r2_17($yy_subpatterns)
619    {
620
621  $this->token = Smarty_Internal_Templateparser::TP_IDENTITY;
622    }
623    function yy_r2_18($yy_subpatterns)
624    {
625
626  $this->token = Smarty_Internal_Templateparser::TP_NONEIDENTITY;
627    }
628    function yy_r2_19($yy_subpatterns)
629    {
630
631  $this->token = Smarty_Internal_Templateparser::TP_EQUALS;
632    }
633    function yy_r2_20($yy_subpatterns)
634    {
635
636  $this->token = Smarty_Internal_Templateparser::TP_NOTEQUALS;
637    }
638    function yy_r2_22($yy_subpatterns)
639    {
640
641  $this->token = Smarty_Internal_Templateparser::TP_GREATEREQUAL;
642    }
643    function yy_r2_24($yy_subpatterns)
644    {
645
646  $this->token = Smarty_Internal_Templateparser::TP_LESSEQUAL;
647    }
648    function yy_r2_26($yy_subpatterns)
649    {
650
651  $this->token = Smarty_Internal_Templateparser::TP_GREATERTHAN;
652    }
653    function yy_r2_27($yy_subpatterns)
654    {
655
656  $this->token = Smarty_Internal_Templateparser::TP_LESSTHAN;
657    }
658    function yy_r2_28($yy_subpatterns)
659    {
660
661  $this->token = Smarty_Internal_Templateparser::TP_MOD;
662    }
663    function yy_r2_29($yy_subpatterns)
664    {
665
666  $this->token = Smarty_Internal_Templateparser::TP_NOT;
667    }
668    function yy_r2_30($yy_subpatterns)
669    {
670
671  $this->token = Smarty_Internal_Templateparser::TP_LAND;
672    }
673    function yy_r2_31($yy_subpatterns)
674    {
675
676  $this->token = Smarty_Internal_Templateparser::TP_LOR;
677    }
678    function yy_r2_32($yy_subpatterns)
679    {
680
681  $this->token = Smarty_Internal_Templateparser::TP_LXOR;
682    }
683    function yy_r2_33($yy_subpatterns)
684    {
685
686  $this->token = Smarty_Internal_Templateparser::TP_ISODDBY;
687    }
688    function yy_r2_34($yy_subpatterns)
689    {
690
691  $this->token = Smarty_Internal_Templateparser::TP_ISNOTODDBY;
692    }
693    function yy_r2_35($yy_subpatterns)
694    {
695
696  $this->token = Smarty_Internal_Templateparser::TP_ISODD;
697    }
698    function yy_r2_36($yy_subpatterns)
699    {
700
701  $this->token = Smarty_Internal_Templateparser::TP_ISNOTODD;
702    }
703    function yy_r2_37($yy_subpatterns)
704    {
705
706  $this->token = Smarty_Internal_Templateparser::TP_ISEVENBY;
707    }
708    function yy_r2_38($yy_subpatterns)
709    {
710
711  $this->token = Smarty_Internal_Templateparser::TP_ISNOTEVENBY;
712    }
713    function yy_r2_39($yy_subpatterns)
714    {
715
716  $this->token = Smarty_Internal_Templateparser::TP_ISEVEN;
717    }
718    function yy_r2_40($yy_subpatterns)
719    {
720
721  $this->token = Smarty_Internal_Templateparser::TP_ISNOTEVEN;
722    }
723    function yy_r2_41($yy_subpatterns)
724    {
725
726  $this->token = Smarty_Internal_Templateparser::TP_ISDIVBY;
727    }
728    function yy_r2_42($yy_subpatterns)
729    {
730
731  $this->token = Smarty_Internal_Templateparser::TP_ISNOTDIVBY;
732    }
733    function yy_r2_43($yy_subpatterns)
734    {
735
736  $this->token = Smarty_Internal_Templateparser::TP_TYPECAST;
737    }
738    function yy_r2_47($yy_subpatterns)
739    {
740
741  $this->token = Smarty_Internal_Templateparser::TP_OPENP;
742    }
743    function yy_r2_48($yy_subpatterns)
744    {
745
746  $this->token = Smarty_Internal_Templateparser::TP_CLOSEP;
747    }
748    function yy_r2_49($yy_subpatterns)
749    {
750
751  $this->token = Smarty_Internal_Templateparser::TP_OPENB;
752    }
753    function yy_r2_50($yy_subpatterns)
754    {
755
756  $this->token = Smarty_Internal_Templateparser::TP_CLOSEB;
757    }
758    function yy_r2_51($yy_subpatterns)
759    {
760
761  $this->token = Smarty_Internal_Templateparser::TP_PTR;
762    }
763    function yy_r2_52($yy_subpatterns)
764    {
765
766  $this->token = Smarty_Internal_Templateparser::TP_APTR;
767    }
768    function yy_r2_53($yy_subpatterns)
769    {
770
771  $this->token = Smarty_Internal_Templateparser::TP_EQUAL;
772    }
773    function yy_r2_54($yy_subpatterns)
774    {
775
776  $this->token = Smarty_Internal_Templateparser::TP_INCDEC;
777    }
778    function yy_r2_55($yy_subpatterns)
779    {
780
781  $this->token = Smarty_Internal_Templateparser::TP_UNIMATH;
782    }
783    function yy_r2_57($yy_subpatterns)
784    {
785
786  $this->token = Smarty_Internal_Templateparser::TP_MATH;
787    }
788    function yy_r2_59($yy_subpatterns)
789    {
790
791  $this->token = Smarty_Internal_Templateparser::TP_DOLLAR;
792    }
793    function yy_r2_60($yy_subpatterns)
794    {
795
796  $this->token = Smarty_Internal_Templateparser::TP_SEMICOLON;
797    }
798    function yy_r2_61($yy_subpatterns)
799    {
800
801  $this->token = Smarty_Internal_Templateparser::TP_DOUBLECOLON;
802    }
803    function yy_r2_62($yy_subpatterns)
804    {
805
806  $this->token = Smarty_Internal_Templateparser::TP_COLON;
807    }
808    function yy_r2_63($yy_subpatterns)
809    {
810
811  $this->token = Smarty_Internal_Templateparser::TP_AT;
812    }
813    function yy_r2_64($yy_subpatterns)
814    {
815
816  $this->token = Smarty_Internal_Templateparser::TP_HATCH;
817    }
818    function yy_r2_65($yy_subpatterns)
819    {
820
821  $this->token = Smarty_Internal_Templateparser::TP_QUOTE;
822  $this->yypushstate(self::DOUBLEQUOTEDSTRING);
823    }
824    function yy_r2_66($yy_subpatterns)
825    {
826
827  $this->token = Smarty_Internal_Templateparser::TP_BACKTICK;
828  $this->yypopstate();
829    }
830    function yy_r2_67($yy_subpatterns)
831    {
832
833  $this->token = Smarty_Internal_Templateparser::TP_VERT;
834    }
835    function yy_r2_68($yy_subpatterns)
836    {
837
838  $this->token = Smarty_Internal_Templateparser::TP_DOT;
839    }
840    function yy_r2_69($yy_subpatterns)
841    {
842
843  $this->token = Smarty_Internal_Templateparser::TP_COMMA;
844    }
845    function yy_r2_70($yy_subpatterns)
846    {
847
848  $this->token = Smarty_Internal_Templateparser::TP_ANDSYM;
849    }
850    function yy_r2_71($yy_subpatterns)
851    {
852
853  $this->token = Smarty_Internal_Templateparser::TP_QMARK;
854    }
855    function yy_r2_72($yy_subpatterns)
856    {
857
858  $this->token = Smarty_Internal_Templateparser::TP_HEX;
859    }
860    function yy_r2_73($yy_subpatterns)
861    {
862
863  // resolve conflicts with shorttag and right_delimiter starting with '='
864  if (substr($this->data, $this->counter + strlen($this->value) - 1, $this->rdel_length) == $this->smarty->right_delimiter) {
865     preg_match("/\s+/",$this->value,$match);
866     $this->value = $match[0];
867     $this->token = Smarty_Internal_Templateparser::TP_SPACE;
868  } else {
869     $this->token = Smarty_Internal_Templateparser::TP_ATTR;
870  }
871    }
872    function yy_r2_74($yy_subpatterns)
873    {
874
875  $this->token = Smarty_Internal_Templateparser::TP_ID;
876    }
877    function yy_r2_75($yy_subpatterns)
878    {
879
880  $this->token = Smarty_Internal_Templateparser::TP_INTEGER;
881    }
882    function yy_r2_76($yy_subpatterns)
883    {
884
885  $this->token = Smarty_Internal_Templateparser::TP_SPACE;
886    }
887    function yy_r2_77($yy_subpatterns)
888    {
889
890  $this->token = Smarty_Internal_Templateparser::TP_TEXT;
891    }
892
893
894
895    function yylex3()
896    {
897        $tokenMap = array (
898              1 => 0,
899              2 => 0,
900              3 => 0,
901              4 => 0,
902              5 => 0,
903              6 => 0,
904              7 => 0,
905            );
906        if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
907            return false; // end of input
908        }
909        $yy_global_pattern = "/\G(".$this->ldel."\\s*literal\\s*".$this->rdel.")|\G(".$this->ldel."\\s*\/literal\\s*".$this->rdel.")|\G(<\\?(?:php\\w+|=|[a-zA-Z]+)?)|\G(\\?>)|\G(<%)|\G(%>)|\G([\S\s])/iS";
910
911        do {
912            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)) {
913                $yysubmatches = $yymatches;
914                $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
915                if (!count($yymatches)) {
916                    throw new Exception('Error: lexing failed because a rule matched' .
917                        ' an empty string.  Input "' . substr($this->data,
918                        $this->counter, 5) . '... state LITERAL');
919                }
920                next($yymatches); // skip global match
921                $this->token = key($yymatches); // token number
922                if ($tokenMap[$this->token]) {
923                    // extract sub-patterns for passing to lex function
924                    $yysubmatches = array_slice($yysubmatches, $this->token + 1,
925                        $tokenMap[$this->token]);
926                } else {
927                    $yysubmatches = array();
928                }
929                $this->value = current($yymatches); // token value
930                $r = $this->{'yy_r3_' . $this->token}($yysubmatches);
931                if ($r === null) {
932                    $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
933                    $this->line += substr_count($this->value, "\n");
934                    // accept this token
935                    return true;
936                } elseif ($r === true) {
937                    // we have changed state
938                    // process this token in the new state
939                    return $this->yylex();
940                } elseif ($r === false) {
941                    $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
942                    $this->line += substr_count($this->value, "\n");
943                    if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
944                        return false; // end of input
945                    }
946                    // skip this token
947                    continue;
948                }            } else {
949                throw new Exception('Unexpected input at line' . $this->line .
950                    ': ' . $this->data[$this->counter]);
951            }
952            break;
953        } while (true);
954
955    } // end function
956
957
958    const LITERAL = 3;
959    function yy_r3_1($yy_subpatterns)
960    {
961
962  $this->token = Smarty_Internal_Templateparser::TP_LITERALSTART;
963  $this->yypushstate(self::LITERAL);
964    }
965    function yy_r3_2($yy_subpatterns)
966    {
967
968  $this->token = Smarty_Internal_Templateparser::TP_LITERALEND;
969  $this->yypopstate();
970    }
971    function yy_r3_3($yy_subpatterns)
972    {
973
974  if (in_array($this->value, Array('<?', '<?=', '<?php'))) {
975    $this->token = Smarty_Internal_Templateparser::TP_PHPSTARTTAG;
976   } else {
977    $this->token = Smarty_Internal_Templateparser::TP_FAKEPHPSTARTTAG;
978    $this->value = substr($this->value, 0, 2);
979   }
980    }
981    function yy_r3_4($yy_subpatterns)
982    {
983
984  $this->token = Smarty_Internal_Templateparser::TP_PHPENDTAG;
985    }
986    function yy_r3_5($yy_subpatterns)
987    {
988
989  $this->token = Smarty_Internal_Templateparser::TP_ASPSTARTTAG;
990    }
991    function yy_r3_6($yy_subpatterns)
992    {
993
994  $this->token = Smarty_Internal_Templateparser::TP_ASPENDTAG;
995    }
996    function yy_r3_7($yy_subpatterns)
997    {
998
999  if ($this->mbstring_overload) {
1000    $to = mb_strlen($this->data,'latin1');
1001  } else {
1002    $to = strlen($this->data);
1003  }
1004  preg_match("/{$this->ldel}\/?literal{$this->rdel}|<\?|<%|\?>|%>/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
1005  if (isset($match[0][1])) {
1006    $to = $match[0][1];
1007  } else {
1008    $this->compiler->trigger_template_error ("missing or misspelled literal closing tag");
1009  }
1010  if ($this->mbstring_overload) {
1011    $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1');
1012  } else {
1013    $this->value = substr($this->data,$this->counter,$to-$this->counter);
1014  }
1015  $this->token = Smarty_Internal_Templateparser::TP_LITERAL;
1016    }
1017
1018
1019    function yylex4()
1020    {
1021        $tokenMap = array (
1022              1 => 0,
1023              2 => 1,
1024              4 => 0,
1025              5 => 0,
1026              6 => 0,
1027              7 => 0,
1028              8 => 0,
1029              9 => 0,
1030              10 => 0,
1031              11 => 0,
1032              12 => 0,
1033              13 => 3,
1034              17 => 0,
1035            );
1036        if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
1037            return false; // end of input
1038        }
1039        $yy_global_pattern = "/\G(".$this->ldel."\\s{1,}\/)|\G(".$this->ldel."\\s*(if|elseif|else if|while)\\s+)|\G(".$this->ldel."\\s*for\\s+)|\G(".$this->ldel."\\s*foreach(?![^\s]))|\G(".$this->ldel."\\s{1,})|\G(".$this->ldel."\/)|\G(".$this->ldel.")|\G(\")|\G(`\\$)|\G(\\$[0-9]*[a-zA-Z_]\\w*)|\G(\\$)|\G(([^\"\\\\]*?)((?:\\\\.[^\"\\\\]*?)*?)(?=(".$this->ldel."|\\$|`\\$|\")))|\G([\S\s])/iS";
1040
1041        do {
1042            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)) {
1043                $yysubmatches = $yymatches;
1044                $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
1045                if (!count($yymatches)) {
1046                    throw new Exception('Error: lexing failed because a rule matched' .
1047                        ' an empty string.  Input "' . substr($this->data,
1048                        $this->counter, 5) . '... state DOUBLEQUOTEDSTRING');
1049                }
1050                next($yymatches); // skip global match
1051                $this->token = key($yymatches); // token number
1052                if ($tokenMap[$this->token]) {
1053                    // extract sub-patterns for passing to lex function
1054                    $yysubmatches = array_slice($yysubmatches, $this->token + 1,
1055                        $tokenMap[$this->token]);
1056                } else {
1057                    $yysubmatches = array();
1058                }
1059                $this->value = current($yymatches); // token value
1060                $r = $this->{'yy_r4_' . $this->token}($yysubmatches);
1061                if ($r === null) {
1062                    $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
1063                    $this->line += substr_count($this->value, "\n");
1064                    // accept this token
1065                    return true;
1066                } elseif ($r === true) {
1067                    // we have changed state
1068                    // process this token in the new state
1069                    return $this->yylex();
1070                } elseif ($r === false) {
1071                    $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value));
1072                    $this->line += substr_count($this->value, "\n");
1073                    if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) {
1074                        return false; // end of input
1075                    }
1076                    // skip this token
1077                    continue;
1078                }            } else {
1079                throw new Exception('Unexpected input at line' . $this->line .
1080                    ': ' . $this->data[$this->counter]);
1081            }
1082            break;
1083        } while (true);
1084
1085    } // end function
1086
1087
1088    const DOUBLEQUOTEDSTRING = 4;
1089    function yy_r4_1($yy_subpatterns)
1090    {
1091
1092  if ($this->smarty->auto_literal) {
1093     $this->token = Smarty_Internal_Templateparser::TP_TEXT;
1094  } else {
1095     $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH;
1096     $this->yypushstate(self::SMARTY);
1097     $this->taglineno = $this->line;
1098  }
1099    }
1100    function yy_r4_2($yy_subpatterns)
1101    {
1102
1103  if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
1104     $this->token = Smarty_Internal_Templateparser::TP_TEXT;
1105  } else {
1106     $this->token = Smarty_Internal_Templateparser::TP_LDELIF;
1107     $this->yypushstate(self::SMARTY);
1108     $this->taglineno = $this->line;
1109  }
1110    }
1111    function yy_r4_4($yy_subpatterns)
1112    {
1113
1114  if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
1115     $this->token = Smarty_Internal_Templateparser::TP_TEXT;
1116  } else {
1117     $this->token = Smarty_Internal_Templateparser::TP_LDELFOR;
1118     $this->yypushstate(self::SMARTY);
1119     $this->taglineno = $this->line;
1120  }
1121    }
1122    function yy_r4_5($yy_subpatterns)
1123    {
1124
1125  if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
1126     $this->token = Smarty_Internal_Templateparser::TP_TEXT;
1127  } else {
1128     $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH;
1129     $this->yypushstate(self::SMARTY);
1130     $this->taglineno = $this->line;
1131  }
1132    }
1133    function yy_r4_6($yy_subpatterns)
1134    {
1135
1136  if ($this->smarty->auto_literal) {
1137     $this->token = Smarty_Internal_Templateparser::TP_TEXT;
1138  } else {
1139     $this->token = Smarty_Internal_Templateparser::TP_LDEL;
1140     $this->yypushstate(self::SMARTY);
1141     $this->taglineno = $this->line;
1142  }
1143    }
1144    function yy_r4_7($yy_subpatterns)
1145    {
1146
1147  $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH;
1148     $this->yypushstate(self::SMARTY);
1149     $this->taglineno = $this->line;
1150    }
1151    function yy_r4_8($yy_subpatterns)
1152    {
1153
1154  $this->token = Smarty_Internal_Templateparser::TP_LDEL;
1155     $this->yypushstate(self::SMARTY);
1156     $this->taglineno = $this->line;
1157    }
1158    function yy_r4_9($yy_subpatterns)
1159    {
1160
1161  $this->token = Smarty_Internal_Templateparser::TP_QUOTE;
1162  $this->yypopstate();
1163    }
1164    function yy_r4_10($yy_subpatterns)
1165    {
1166
1167  $this->token = Smarty_Internal_Templateparser::TP_BACKTICK;
1168  $this->value = substr($this->value,0,-1);
1169  $this->yypushstate(self::SMARTY);
1170  $this->taglineno = $this->line;
1171    }
1172    function yy_r4_11($yy_subpatterns)
1173    {
1174
1175  $this->token = Smarty_Internal_Templateparser::TP_DOLLARID;
1176    }
1177    function yy_r4_12($yy_subpatterns)
1178    {
1179
1180  $this->token = Smarty_Internal_Templateparser::TP_TEXT;
1181    }
1182    function yy_r4_13($yy_subpatterns)
1183    {
1184
1185  $this->token = Smarty_Internal_Templateparser::TP_TEXT;
1186    }
1187    function yy_r4_17($yy_subpatterns)
1188    {
1189
1190  if ($this->mbstring_overload) {
1191    $to = mb_strlen($this->data,'latin1');
1192  } else {
1193    $to = strlen($this->data);
1194  }
1195  if ($this->mbstring_overload) {
1196    $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1');
1197  } else {
1198    $this->value = substr($this->data,$this->counter,$to-$this->counter);
1199  }
1200  $this->token = Smarty_Internal_Templateparser::TP_TEXT;
1201    }
1202
1203}
Note: See TracBrowser for help on using the repository browser.