Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
/**
2
* Smarty Internal Plugin Configfileparser
3
*
4
* This is the config file parser
5
*
6
*
7
* @package Smarty
8
* @subpackage Config
9
* @author Uwe Tews
10
*/
11
%name TPC_
12
%declare_class {
13
/**
14
* Smarty Internal Plugin Configfileparse
15
*
16
* This is the config file parser.
17
* It is generated from the smarty_internal_configfileparser.y file
18
* @package Smarty
19
* @subpackage Compiler
20
* @author Uwe Tews
21
*/
22
class Smarty_Internal_Configfileparser
23
}
24
%include_class
25
{
26
    /**
27
     * result status
28
     *
29
     * @var bool
30
     */
31
    public $successful = true;
32
    /**
33
     * return value
34
     *
35
     * @var mixed
36
     */
37
    public $retvalue = 0;
38
    /**
39
     * @var
40
     */
41
    public $yymajor;
42
    /**
43
     * lexer object
44
     *
45
     * @var Smarty_Internal_Configfilelexer
46
     */
47
    private $lex;
48
    /**
49
     * internal error flag
50
     *
51
     * @var bool
52
     */
53
    private $internalError = false;
54
    /**
55
     * compiler object
56
     *
57
     * @var Smarty_Internal_Config_File_Compiler
58
     */
59
    public $compiler = null;
60
    /**
61
     * smarty object
62
     *
63
     * @var Smarty
64
     */
65
    public $smarty = null;
66
    /**
67
     * copy of config_overwrite property
68
     *
69
     * @var bool
70
     */
71
    private $configOverwrite = false;
72
    /**
73
     * copy of config_read_hidden property
74
     *
75
     * @var bool
76
     */
77
    private $configReadHidden = false;
78
    /**
79
     * helper map
80
     *
81
     * @var array
82
     */
83
    private static $escapes_single = array('\\' => '\\',
84
                                           '\'' => '\'');
85
 
86
    /**
87
     * constructor
88
     *
89
     * @param Smarty_Internal_Configfilelexer      $lex
90
     * @param Smarty_Internal_Config_File_Compiler $compiler
91
     */
92
    public function __construct(Smarty_Internal_Configfilelexer $lex, Smarty_Internal_Config_File_Compiler $compiler)
93
    {
94
        $this->lex = $lex;
95
        $this->smarty = $compiler->smarty;
96
        $this->compiler = $compiler;
97
        $this->configOverwrite = $this->smarty->config_overwrite;
98
        $this->configReadHidden = $this->smarty->config_read_hidden;
99
    }
100
 
101
    /**
102
     * parse optional boolean keywords
103
     *
104
     * @param string $str
105
     *
106
     * @return bool
107
     */
108
    private function parse_bool($str)
109
    {
110
        $str = strtolower($str);
111
        if (in_array($str, array('on', 'yes', 'true'))) {
112
            $res = true;
113
        } else {
114
            $res = false;
115
        }
116
        return $res;
117
    }
118
 
119
    /**
120
     * parse single quoted string
121
     *  remove outer quotes
122
     *  unescape inner quotes
123
     *
124
     * @param string $qstr
125
     *
126
     * @return string
127
     */
128
    private static function parse_single_quoted_string($qstr)
129
    {
130
        $escaped_string = substr($qstr, 1, strlen($qstr) - 2); //remove outer quotes
131
 
132
        $ss = preg_split('/(\\\\.)/', $escaped_string, - 1, PREG_SPLIT_DELIM_CAPTURE);
133
 
134
        $str = '';
135
        foreach ($ss as $s) {
136
            if (strlen($s) === 2 && $s[0] === '\\') {
137
                if (isset(self::$escapes_single[$s[1]])) {
138
                    $s = self::$escapes_single[$s[1]];
139
                }
140
            }
141
            $str .= $s;
142
        }
143
        return $str;
144
    }
145
 
146
    /**
147
     * parse double quoted string
148
     *
149
     * @param string $qstr
150
     *
151
     * @return string
152
     */
153
    private static function parse_double_quoted_string($qstr)
154
    {
155
        $inner_str = substr($qstr, 1, strlen($qstr) - 2);
156
        return stripcslashes($inner_str);
157
    }
158
 
159
    /**
160
     * parse triple quoted string
161
     *
162
     * @param string $qstr
163
     *
164
     * @return string
165
     */
166
    private static function parse_tripple_double_quoted_string($qstr)
167
    {
168
        return stripcslashes($qstr);
169
    }
170
 
171
    /**
172
     * set a config variable in target array
173
     *
174
     * @param array $var
175
     * @param array $target_array
176
     */
177
    private function set_var(array $var, array &$target_array)
178
    {
179
        $key = $var['key'];
180
        $value = $var['value'];
181
 
182
        if ($this->configOverwrite || !isset($target_array['vars'][$key])) {
183
            $target_array['vars'][$key] = $value;
184
        } else {
185
            settype($target_array['vars'][$key], 'array');
186
            $target_array['vars'][$key][] = $value;
187
        }
188
    }
189
 
190
    /**
191
     * add config variable to global vars
192
     *
193
     * @param array $vars
194
     */
195
    private function add_global_vars(array $vars)
196
    {
197
        if (!isset($this->compiler->config_data['vars'])) {
198
            $this->compiler->config_data['vars'] = array();
199
        }
200
        foreach ($vars as $var) {
201
            $this->set_var($var, $this->compiler->config_data);
202
        }
203
    }
204
 
205
    /**
206
     * add config variable to section
207
     *
208
     * @param string $section_name
209
     * @param array  $vars
210
     */
211
    private function add_section_vars($section_name, array $vars)
212
    {
213
        if (!isset($this->compiler->config_data['sections'][$section_name]['vars'])) {
214
            $this->compiler->config_data['sections'][$section_name]['vars'] = array();
215
        }
216
        foreach ($vars as $var) {
217
            $this->set_var($var, $this->compiler->config_data['sections'][$section_name]);
218
        }
219
    }
220
}
221
 
222
%token_prefix TPC_
223
 
224
%parse_accept
225
{
226
    $this->successful = !$this->internalError;
227
    $this->internalError = false;
228
    $this->retvalue = $this->_retvalue;
229
}
230
 
231
%syntax_error
232
{
233
    $this->internalError = true;
234
    $this->yymajor = $yymajor;
235
    $this->compiler->trigger_config_file_error();
236
}
237
 
238
%stack_overflow
239
{
240
    $this->internalError = true;
241
    $this->compiler->trigger_config_file_error('Stack overflow in configfile parser');
242
}
243
 
244
// Complete config file
245
start(res) ::= global_vars sections. {
246
    res = null;
247
}
248
 
249
// Global vars
250
global_vars(res) ::= var_list(vl). {
251
    $this->add_global_vars(vl);
252
    res = null;
253
}
254
 
255
// Sections
256
sections(res) ::= sections section. {
257
    res = null;
258
}
259
 
260
sections(res) ::= . {
261
    res = null;
262
}
263
 
264
section(res) ::= OPENB SECTION(i) CLOSEB newline var_list(vars). {
265
    $this->add_section_vars(i, vars);
266
    res = null;
267
}
268
 
269
section(res) ::= OPENB DOT SECTION(i) CLOSEB newline var_list(vars). {
270
    if ($this->configReadHidden) {
271
        $this->add_section_vars(i, vars);
272
    }
273
    res = null;
274
}
275
 
276
// Var list
277
var_list(res) ::= var_list(vl) newline. {
278
    res = vl;
279
}
280
 
281
var_list(res) ::= var_list(vl) var(v). {
282
    res = array_merge(vl, array(v));
283
}
284
 
285
var_list(res) ::= . {
286
    res = array();
287
}
288
 
289
 
290
// Var
291
var(res) ::= ID(id) EQUAL value(v). {
292
    res = array('key' => id, 'value' => v);
293
}
294
 
295
 
296
value(res) ::= FLOAT(i). {
297
    res = (float) i;
298
}
299
 
300
value(res) ::= INT(i). {
301
    res = (int) i;
302
}
303
 
304
value(res) ::= BOOL(i). {
305
    res = $this->parse_bool(i);
306
}
307
 
308
value(res) ::= SINGLE_QUOTED_STRING(i). {
309
    res = self::parse_single_quoted_string(i);
310
}
311
 
312
value(res) ::= DOUBLE_QUOTED_STRING(i). {
313
    res = self::parse_double_quoted_string(i);
314
}
315
 
316
value(res) ::= TRIPPLE_QUOTES(i) TRIPPLE_TEXT(c) TRIPPLE_QUOTES_END(ii). {
317
    res = self::parse_tripple_double_quoted_string(c);
318
}
319
 
320
value(res) ::= TRIPPLE_QUOTES(i) TRIPPLE_QUOTES_END(ii). {
321
    res = '';
322
}
323
 
324
value(res) ::= NAKED_STRING(i). {
325
    res = i;
326
}
327
 
328
// NOTE: this is not a valid rule
329
// It is added hier to produce a usefull error message on a missing '=';
330
value(res) ::= OTHER(i). {
331
    res = i;
332
}
333
 
334
 
335
// Newline and comments
336
newline(res) ::= NEWLINE. {
337
    res = null;
338
}
339
 
340
newline(res) ::= COMMENTSTART NEWLINE. {
341
    res = null;
342
}
343
 
344
newline(res) ::= COMMENTSTART NAKED_STRING NEWLINE. {
345
    res = null;
346
}