/usr/share/php/Nette/Latte/MacroTokens.php is in php-nette 2.1.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | <?php
/**
* This file is part of the Nette Framework (http://nette.org)
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/
namespace Nette\Latte;
use Nette;
/**
* Macro tag tokenizer.
*
* @author David Grudl
*/
class MacroTokens extends Nette\Utils\TokenIterator
{
const T_WHITESPACE = 1,
T_COMMENT = 2,
T_SYMBOL = 3,
T_NUMBER = 4,
T_VARIABLE = 5,
T_STRING = 6,
T_CAST = 7,
T_KEYWORD = 8,
T_CHAR = 9;
/** @var Nette\Utils\Tokenizer */
private static $tokenizer;
/** @var int */
public $depth = 0;
public function __construct($input = NULL)
{
parent::__construct(is_array($input) ? $input : $this->parse($input));
$this->ignored = array(self::T_COMMENT, self::T_WHITESPACE);
}
public function parse($s)
{
self::$tokenizer = self::$tokenizer ?: new Nette\Utils\Tokenizer(array(
self::T_WHITESPACE => '\s+',
self::T_COMMENT => '(?s)/\*.*?\*/',
self::T_STRING => Parser::RE_STRING,
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_])', // keyword or const
self::T_CAST => '\((?:expand|string|array|int|integer|float|bool|boolean|object)\)', // type casting
self::T_VARIABLE => '\$[\w\pL_]+',
self::T_NUMBER => '[+-]?[0-9]+(?:\.[0-9]+)?(?:e[0-9]+)?',
self::T_SYMBOL => '[\w\pL_]+(?:-[\w\pL_]+)*',
self::T_CHAR => '::|=>|->|\+\+|--|<<|>>|<=|>=|===|!==|==|!=|<>|&&|\|\||[^"\']', // =>, any char except quotes
), 'u');
return self::$tokenizer->tokenize($s);
}
/**
* Appends simple token or string (will be parsed).
* @return MacroTokens
*/
public function append($val, $position = NULL)
{
if ($val != NULL) { // intentionally @
array_splice(
$this->tokens,
$position === NULL ? count($this->tokens) : $position, 0,
is_array($val) ? array($val) : $this->parse($val)
);
}
return $this;
}
/**
* Prepends simple token or string (will be parsed).
* @return MacroTokens
*/
public function prepend($val)
{
if ($val != NULL) { // intentionally @
array_splice($this->tokens, 0, 0, is_array($val) ? array($val) : $this->parse($val));
}
return $this;
}
/**
* Reads single token (optionally delimited by comma) from string.
* @param string
* @return string
*/
public function fetchWord()
{
$words = $this->fetchWords();
return $words ? implode(':', $words) : FALSE;
}
/**
* Reads single tokens delimited by colon from string.
* @param string
* @return array
*/
public function fetchWords()
{
do {
$words[] = $this->joinUntil(self::T_WHITESPACE, ',', ':');
} while ($this->nextToken(':'));
$this->nextToken(',');
$this->nextAll(self::T_WHITESPACE, self::T_COMMENT);
return $words === array('') ? array() : $words;
}
public function reset()
{
$this->depth = 0;
return parent::reset();
}
protected function next()
{
parent::next();
if ($this->isCurrent('[', '(', '{')) {
$this->depth++;
} elseif ($this->isCurrent(']', ')', '}')) {
$this->depth--;
}
}
}
|