1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Latte;
9:
10: use Nette;
11:
12:
13: 14: 15: 16: 17:
18: class MacroTokenizer extends Nette\Utils\Tokenizer
19: {
20: const T_WHITESPACE = 1,
21: = 2,
22: T_SYMBOL = 3,
23: T_NUMBER = 4,
24: T_VARIABLE = 5,
25: T_STRING = 6,
26: T_CAST = 7,
27: T_KEYWORD = 8,
28: T_CHAR = 9;
29:
30:
31: public function __construct($input)
32: {
33: parent::__construct(array(
34: self::T_WHITESPACE => '\s+',
35: self::T_COMMENT => '(?s)/\*.*?\*/',
36: self::T_STRING => Parser::RE_STRING,
37: self::T_KEYWORD => '(?:true|false|null|and|or|xor|clone|new|instanceof|return|continue|break|endif|endforeach|endwhile|endswitch|[A-Z_][A-Z0-9_]{2,})(?![\w\pL_])',
38: self::T_CAST => '\((?:expand|string|array|int|integer|float|bool|boolean|object)\)',
39: self::T_VARIABLE => '\$[\w\pL_]+',
40: self::T_NUMBER => '[+-]?[0-9]+(?:\.[0-9]+)?(?:e[0-9]+)?',
41: self::T_SYMBOL => '[\w\pL_]+(?:-[\w\pL_]+)*',
42: self::T_CHAR => '::|=>|->|\+\+|--|<<|>>|<=|>=|===|!==|==|!=|<>|&&|\|\||[^"\']',
43: ), 'u');
44: $this->ignored = array(self::T_COMMENT, self::T_WHITESPACE);
45: $this->tokenize($input);
46: }
47:
48:
49: 50: 51: 52: 53:
54: public function fetchWord()
55: {
56: $word = $this->fetchUntil(self::T_WHITESPACE, ',');
57: $this->fetch(',');
58: $this->fetchAll(self::T_WHITESPACE, self::T_COMMENT);
59: return $word;
60: }
61:
62: }
63: