Содержимое файла | Последнее изменение | Открыть журнал | RSS
Редакция | Автор | № строки | Строка |
---|---|---|---|
304 | alex-w | 1 | <?php |
2 | /** |
||
3 | * Smarty Internal Plugin Configfilelexer |
||
4 | * |
||
5 | * This is the lexer to break the config file source into tokens |
||
6 | * @package Smarty |
||
7 | * @subpackage Config |
||
8 | * @author Uwe Tews |
||
9 | */ |
||
10 | /** |
||
11 | * Smarty Internal Plugin Templatelexer |
||
12 | */ |
||
13 | class Smarty_Internal_Configfilelexer |
||
14 | { |
||
15 | |||
16 | public $data; |
||
17 | public $counter; |
||
18 | public $token; |
||
19 | public $value; |
||
20 | public $node; |
||
21 | public $line; |
||
22 | private $state = 1; |
||
23 | public $smarty_token_names = array ( // Text for parser error messages |
||
24 | ); |
||
25 | |||
26 | |||
27 | function __construct($data, $smarty) |
||
28 | { |
||
29 | // set instance object |
||
30 | self::instance($this); |
||
31 | $this->data = $data; |
||
32 | $this->counter = 0; |
||
33 | $this->line = 1; |
||
34 | $this->smarty = $smarty; |
||
35 | } |
||
36 | public static function &instance($new_instance = null) |
||
37 | { |
||
38 | static $instance = null; |
||
39 | if (isset($new_instance) && is_object($new_instance)) |
||
40 | $instance = $new_instance; |
||
41 | return $instance; |
||
42 | } |
||
43 | |||
44 | |||
45 | |||
46 | private $_yy_state = 1; |
||
47 | private $_yy_stack = array(); |
||
48 | |||
49 | function yylex() |
||
50 | { |
||
51 | return $this->{'yylex' . $this->_yy_state}(); |
||
52 | } |
||
53 | |||
54 | function yypushstate($state) |
||
55 | { |
||
56 | array_push($this->_yy_stack, $this->_yy_state); |
||
57 | $this->_yy_state = $state; |
||
58 | } |
||
59 | |||
60 | function yypopstate() |
||
61 | { |
||
62 | $this->_yy_state = array_pop($this->_yy_stack); |
||
63 | } |
||
64 | |||
65 | function yybegin($state) |
||
66 | { |
||
67 | $this->_yy_state = $state; |
||
68 | } |
||
69 | |||
70 | |||
71 | |||
72 | function yylex1() |
||
73 | { |
||
74 | $tokenMap = array ( |
||
75 | 1 => 0, |
||
76 | 2 => 0, |
||
77 | 3 => 0, |
||
78 | 4 => 0, |
||
79 | 5 => 0, |
||
80 | 6 => 0, |
||
81 | 7 => 0, |
||
82 | 8 => 1, |
||
83 | 10 => 1, |
||
84 | 12 => 0, |
||
85 | 13 => 0, |
||
86 | 14 => 0, |
||
87 | 15 => 0, |
||
88 | ); |
||
89 | if ($this->counter >= strlen($this->data)) { |
||
90 | return false; // end of input |
||
91 | } |
||
92 | $yy_global_pattern = "/^(#)|^('[^'\\\\\\\\]*(?:\\\\\\\\.[^'\\\\\\\\]*)*')|^(\"\"\"[^\"\\\\\\\\]*(?:\\\\\\\\.[^\"\\\\\\\\]*)*\"\"\")|^(\"[^\"\\\\\\\\]*(?:\\\\\\\\.[^\"\\\\\\\\]*)*\")|^(\\[)|^(])|^(\\s*=\\s*)|^(\\d+(\\.\\d+)?)|^((\n|\r\n))|^([\s]+)|^(\\.)|^(\\w+)|^(.)/"; |
||
93 | |||
94 | do { |
||
95 | if (preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches)) { |
||
96 | $yysubmatches = $yymatches; |
||
97 | $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns |
||
98 | if (!count($yymatches)) { |
||
99 | throw new Exception('Error: lexing failed because a rule matched' . |
||
100 | 'an empty string. Input "' . substr($this->data, |
||
101 | $this->counter, 5) . '... state START'); |
||
102 | } |
||
103 | next($yymatches); // skip global match |
||
104 | $this->token = key($yymatches); // token number |
||
105 | if ($tokenMap[$this->token]) { |
||
106 | // extract sub-patterns for passing to lex function |
||
107 | $yysubmatches = array_slice($yysubmatches, $this->token + 1, |
||
108 | $tokenMap[$this->token]); |
||
109 | } else { |
||
110 | $yysubmatches = array(); |
||
111 | } |
||
112 | $this->value = current($yymatches); // token value |
||
113 | $r = $this->{'yy_r1_' . $this->token}($yysubmatches); |
||
114 | if ($r === null) { |
||
115 | $this->counter += strlen($this->value); |
||
116 | $this->line += substr_count($this->value, "\n"); |
||
117 | // accept this token |
||
118 | return true; |
||
119 | } elseif ($r === true) { |
||
120 | // we have changed state |
||
121 | // process this token in the new state |
||
122 | return $this->yylex(); |
||
123 | } elseif ($r === false) { |
||
124 | $this->counter += strlen($this->value); |
||
125 | $this->line += substr_count($this->value, "\n"); |
||
126 | if ($this->counter >= strlen($this->data)) { |
||
127 | return false; // end of input |
||
128 | } |
||
129 | // skip this token |
||
130 | continue; |
||
131 | } else { $yy_yymore_patterns = array( |
||
132 | 1 => array(0, "^('[^'\\\\\\\\]*(?:\\\\\\\\.[^'\\\\\\\\]*)*')|^(\"\"\"[^\"\\\\\\\\]*(?:\\\\\\\\.[^\"\\\\\\\\]*)*\"\"\")|^(\"[^\"\\\\\\\\]*(?:\\\\\\\\.[^\"\\\\\\\\]*)*\")|^(\\[)|^(])|^(\\s*=\\s*)|^(\\d+(\\.\\d+)?)|^((\n|\r\n))|^([\s]+)|^(\\.)|^(\\w+)|^(.)"), |
||
133 | 2 => array(0, "^(\"\"\"[^\"\\\\\\\\]*(?:\\\\\\\\.[^\"\\\\\\\\]*)*\"\"\")|^(\"[^\"\\\\\\\\]*(?:\\\\\\\\.[^\"\\\\\\\\]*)*\")|^(\\[)|^(])|^(\\s*=\\s*)|^(\\d+(\\.\\d+)?)|^((\n|\r\n))|^([\s]+)|^(\\.)|^(\\w+)|^(.)"), |
||
134 | 3 => array(0, "^(\"[^\"\\\\\\\\]*(?:\\\\\\\\.[^\"\\\\\\\\]*)*\")|^(\\[)|^(])|^(\\s*=\\s*)|^(\\d+(\\.\\d+)?)|^((\n|\r\n))|^([\s]+)|^(\\.)|^(\\w+)|^(.)"), |
||
135 | 4 => array(0, "^(\\[)|^(])|^(\\s*=\\s*)|^(\\d+(\\.\\d+)?)|^((\n|\r\n))|^([\s]+)|^(\\.)|^(\\w+)|^(.)"), |
||
136 | 5 => array(0, "^(])|^(\\s*=\\s*)|^(\\d+(\\.\\d+)?)|^((\n|\r\n))|^([\s]+)|^(\\.)|^(\\w+)|^(.)"), |
||
137 | 6 => array(0, "^(\\s*=\\s*)|^(\\d+(\\.\\d+)?)|^((\n|\r\n))|^([\s]+)|^(\\.)|^(\\w+)|^(.)"), |
||
138 | 7 => array(0, "^(\\d+(\\.\\d+)?)|^((\n|\r\n))|^([\s]+)|^(\\.)|^(\\w+)|^(.)"), |
||
139 | 8 => array(1, "^((\n|\r\n))|^([\s]+)|^(\\.)|^(\\w+)|^(.)"), |
||
140 | 10 => array(2, "^([\s]+)|^(\\.)|^(\\w+)|^(.)"), |
||
141 | 12 => array(2, "^(\\.)|^(\\w+)|^(.)"), |
||
142 | 13 => array(2, "^(\\w+)|^(.)"), |
||
143 | 14 => array(2, "^(.)"), |
||
144 | 15 => array(2, ""), |
||
145 | ); |
||
146 | |||
147 | // yymore is needed |
||
148 | do { |
||
149 | if (!strlen($yy_yymore_patterns[$this->token][1])) { |
||
150 | throw new Exception('cannot do yymore for the last token'); |
||
151 | } |
||
152 | $yysubmatches = array(); |
||
153 | if (preg_match('/' . $yy_yymore_patterns[$this->token][1] . '/', |
||
154 | substr($this->data, $this->counter), $yymatches)) { |
||
155 | $yysubmatches = $yymatches; |
||
156 | $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns |
||
157 | next($yymatches); // skip global match |
||
158 | $this->token += key($yymatches) + $yy_yymore_patterns[$this->token][0]; // token number |
||
159 | $this->value = current($yymatches); // token value |
||
160 | $this->line = substr_count($this->value, "\n"); |
||
161 | if ($tokenMap[$this->token]) { |
||
162 | // extract sub-patterns for passing to lex function |
||
163 | $yysubmatches = array_slice($yysubmatches, $this->token + 1, |
||
164 | $tokenMap[$this->token]); |
||
165 | } else { |
||
166 | $yysubmatches = array(); |
||
167 | } |
||
168 | } |
||
169 | $r = $this->{'yy_r1_' . $this->token}($yysubmatches); |
||
170 | } while ($r !== null && !is_bool($r)); |
||
171 | if ($r === true) { |
||
172 | // we have changed state |
||
173 | // process this token in the new state |
||
174 | return $this->yylex(); |
||
175 | } elseif ($r === false) { |
||
176 | $this->counter += strlen($this->value); |
||
177 | $this->line += substr_count($this->value, "\n"); |
||
178 | if ($this->counter >= strlen($this->data)) { |
||
179 | return false; // end of input |
||
180 | } |
||
181 | // skip this token |
||
182 | continue; |
||
183 | } else { |
||
184 | // accept |
||
185 | $this->counter += strlen($this->value); |
||
186 | $this->line += substr_count($this->value, "\n"); |
||
187 | return true; |
||
188 | } |
||
189 | } |
||
190 | } else { |
||
191 | throw new Exception('Unexpected input at line' . $this->line . |
||
192 | ': ' . $this->data[$this->counter]); |
||
193 | } |
||
194 | break; |
||
195 | } while (true); |
||
196 | |||
197 | } // end function |
||
198 | |||
199 | |||
200 | const START = 1; |
||
201 | function yy_r1_1($yy_subpatterns) |
||
202 | { |
||
203 | |||
204 | $this->token = Smarty_Internal_Configfileparser::TPC_COMMENTSTART; |
||
205 | } |
||
206 | function yy_r1_2($yy_subpatterns) |
||
207 | { |
||
208 | |||
209 | $this->token = Smarty_Internal_Configfileparser::TPC_SI_QSTR; |
||
210 | } |
||
211 | function yy_r1_3($yy_subpatterns) |
||
212 | { |
||
213 | |||
214 | $this->token = Smarty_Internal_Configfileparser::TPC_ML_QSTR; |
||
215 | } |
||
216 | function yy_r1_4($yy_subpatterns) |
||
217 | { |
||
218 | |||
219 | $this->token = Smarty_Internal_Configfileparser::TPC_DO_QSTR; |
||
220 | } |
||
221 | function yy_r1_5($yy_subpatterns) |
||
222 | { |
||
223 | |||
224 | $this->token = Smarty_Internal_Configfileparser::TPC_OPENB; |
||
225 | } |
||
226 | function yy_r1_6($yy_subpatterns) |
||
227 | { |
||
228 | |||
229 | $this->token = Smarty_Internal_Configfileparser::TPC_CLOSEB; |
||
230 | } |
||
231 | function yy_r1_7($yy_subpatterns) |
||
232 | { |
||
233 | |||
234 | $this->token = Smarty_Internal_Configfileparser::TPC_EQUAL; |
||
235 | } |
||
236 | function yy_r1_8($yy_subpatterns) |
||
237 | { |
||
238 | |||
239 | $this->token = Smarty_Internal_Configfileparser::TPC_NUMBER; |
||
240 | } |
||
241 | function yy_r1_10($yy_subpatterns) |
||
242 | { |
||
243 | |||
244 | $this->token = Smarty_Internal_Configfileparser::TPC_EOL; |
||
245 | } |
||
246 | function yy_r1_12($yy_subpatterns) |
||
247 | { |
||
248 | |||
249 | $this->token = Smarty_Internal_Configfileparser::TPC_SPACE; |
||
250 | } |
||
251 | function yy_r1_13($yy_subpatterns) |
||
252 | { |
||
253 | |||
254 | $this->token = Smarty_Internal_Configfileparser::TPC_DOT; |
||
255 | } |
||
256 | function yy_r1_14($yy_subpatterns) |
||
257 | { |
||
258 | |||
259 | $this->token = Smarty_Internal_Configfileparser::TPC_ID; |
||
260 | } |
||
261 | function yy_r1_15($yy_subpatterns) |
||
262 | { |
||
263 | |||
264 | $this->token = Smarty_Internal_Configfileparser::TPC_OTHER; |
||
265 | } |
||
266 | |||
267 | } |