Lines Matching refs:this

58         $this->env = $env;
60 $this->options = array_merge([
68 $this->regexes = [
69 …var' => '/\s*'.preg_quote($this->options['whitespace_trim'].$this->options['tag_variable'][1], '/'…
70 …k' => '/\s*(?:'.preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '/').…
71this->options['tag_block'][0].$this->options['whitespace_trim'], '/').'|'.preg_quote($this->option…
72 'operator' => $this->getOperatorRegex(),
73 … '/(?:'.preg_quote($this->options['whitespace_trim'], '/').preg_quote($this->options['tag_comment'…
74 …erbatim)\s*(?:'.preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '/').…
75 … 'lex_block_line' => '/\s*line\s+(\d+)\s*'.preg_quote($this->options['tag_block'][1], '/').'/As',
76this->options['tag_variable'][0], '/').'|'.preg_quote($this->options['tag_block'][0], '/').'|'.pre…
77 … 'interpolation_start' => '/'.preg_quote($this->options['interpolation'][0], '/').'\s*/A',
78 'interpolation_end' => '/\s*'.preg_quote($this->options['interpolation'][1], '/').'/A',
86 $this->source = new Source($code, $name);
88 $this->source = $code;
102 $this->code = str_replace(["\r\n", "\r"], "\n", $this->source->getCode());
103 $this->filename = $this->source->getName();
104 $this->cursor = 0;
105 $this->lineno = 1;
106 $this->end = \strlen($this->code);
107 $this->tokens = [];
108 $this->state = self::STATE_DATA;
109 $this->states = [];
110 $this->brackets = [];
111 $this->position = -1;
114 … preg_match_all($this->regexes['lex_tokens_start'], $this->code, $matches, PREG_OFFSET_CAPTURE);
115 $this->positions = $matches;
117 while ($this->cursor < $this->end) {
120 switch ($this->state) {
122 $this->lexData();
126 $this->lexBlock();
130 $this->lexVar();
134 $this->lexString();
138 $this->lexInterpolation();
143 $this->pushToken(Token::EOF_TYPE);
145 if (!empty($this->brackets)) {
146 list($expect, $lineno) = array_pop($this->brackets);
147 throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source);
154 return new TokenStream($this->tokens, $this->source);
160 if ($this->position == \count($this->positions[0]) - 1) {
161 $this->pushToken(Token::TEXT_TYPE, substr($this->code, $this->cursor));
162 $this->cursor = $this->end;
168 $position = $this->positions[0][++$this->position];
169 while ($position[1] < $this->cursor) {
170 if ($this->position == \count($this->positions[0]) - 1) {
173 $position = $this->positions[0][++$this->position];
177 $text = $textContent = substr($this->code, $this->cursor, $position[1] - $this->cursor);
178 if (isset($this->positions[2][$this->position][0])) {
181 $this->pushToken(Token::TEXT_TYPE, $text);
182 $this->moveCursor($textContent.$position[0]);
184 switch ($this->positions[1][$this->position][0]) {
185 case $this->options['tag_comment'][0]:
186 $this->lexComment();
189 case $this->options['tag_block'][0]:
191 … if (preg_match($this->regexes['lex_block_raw'], $this->code, $match, null, $this->cursor)) {
192 $this->moveCursor($match[0]);
193 $this->lexRawData($match[1]);
195 …} elseif (preg_match($this->regexes['lex_block_line'], $this->code, $match, null, $this->cursor)) {
196 $this->moveCursor($match[0]);
197 $this->lineno = (int) $match[1];
199 $this->pushToken(Token::BLOCK_START_TYPE);
200 $this->pushState(self::STATE_BLOCK);
201 $this->currentVarBlockLine = $this->lineno;
205 case $this->options['tag_variable'][0]:
206 $this->pushToken(Token::VAR_START_TYPE);
207 $this->pushState(self::STATE_VAR);
208 $this->currentVarBlockLine = $this->lineno;
215 …if (empty($this->brackets) && preg_match($this->regexes['lex_block'], $this->code, $match, null, $
216 $this->pushToken(Token::BLOCK_END_TYPE);
217 $this->moveCursor($match[0]);
218 $this->popState();
220 $this->lexExpression();
226 …if (empty($this->brackets) && preg_match($this->regexes['lex_var'], $this->code, $match, null, $th…
227 $this->pushToken(Token::VAR_END_TYPE);
228 $this->moveCursor($match[0]);
229 $this->popState();
231 $this->lexExpression();
238 if (preg_match('/\s+/A', $this->code, $match, null, $this->cursor)) {
239 $this->moveCursor($match[0]);
241 if ($this->cursor >= $this->end) {
242 …'Unclosed "%s".', self::STATE_BLOCK === $this->state ? 'block' : 'variable'), $this->currentVarBlo…
247 if (preg_match($this->regexes['operator'], $this->code, $match, null, $this->cursor)) {
248 $this->pushToken(Token::OPERATOR_TYPE, preg_replace('/\s+/', ' ', $match[0]));
249 $this->moveCursor($match[0]);
252 elseif (preg_match(self::REGEX_NAME, $this->code, $match, null, $this->cursor)) {
253 $this->pushToken(Token::NAME_TYPE, $match[0]);
254 $this->moveCursor($match[0]);
257 elseif (preg_match(self::REGEX_NUMBER, $this->code, $match, null, $this->cursor)) {
262 $this->pushToken(Token::NUMBER_TYPE, $number);
263 $this->moveCursor($match[0]);
266 elseif (false !== strpos(self::PUNCTUATION, $this->code[$this->cursor])) {
268 if (false !== strpos('([{', $this->code[$this->cursor])) {
269 $this->brackets[] = [$this->code[$this->cursor], $this->lineno];
272 elseif (false !== strpos(')]}', $this->code[$this->cursor])) {
273 if (empty($this->brackets)) {
274 …throw new SyntaxError(sprintf('Unexpected "%s".', $this->code[$this->cursor]), $this->lineno, $thi…
277 list($expect, $lineno) = array_pop($this->brackets);
278 if ($this->code[$this->cursor] != strtr($expect, '([{', ')]}')) {
279 … throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source);
283 $this->pushToken(Token::PUNCTUATION_TYPE, $this->code[$this->cursor]);
284 ++$this->cursor;
287 elseif (preg_match(self::REGEX_STRING, $this->code, $match, null, $this->cursor)) {
288 $this->pushToken(Token::STRING_TYPE, stripcslashes(substr($match[0], 1, -1)));
289 $this->moveCursor($match[0]);
292 elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) {
293 $this->brackets[] = ['"', $this->lineno];
294 $this->pushState(self::STATE_STRING);
295 $this->moveCursor($match[0]);
299 … SyntaxError(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $th…
306 …d since version 1.21. Use "verbatim" instead in %s at line %d.', $this->filename, $this->lineno), …
309 …!preg_match(str_replace('%s', $tag, $this->regexes['lex_raw_data']), $this->code, $match, PREG_OFF…
310 …Error(sprintf('Unexpected end of file: Unclosed "%s" block.', $tag), $this->lineno, $this->source);
313 $text = substr($this->code, $this->cursor, $match[0][1] - $this->cursor);
314 $this->moveCursor($text.$match[0][0]);
316 if (false !== strpos($match[1][0], $this->options['whitespace_trim'])) {
320 $this->pushToken(Token::TEXT_TYPE, $text);
325 …if (!preg_match($this->regexes['lex_comment'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cu…
326 throw new SyntaxError('Unclosed comment.', $this->lineno, $this->source);
329 … $this->moveCursor(substr($this->code, $this->cursor, $match[0][1] - $this->cursor).$match[0][0]);
334 … if (preg_match($this->regexes['interpolation_start'], $this->code, $match, null, $this->cursor)) {
335 $this->brackets[] = [$this->options['interpolation'][0], $this->lineno];
336 $this->pushToken(Token::INTERPOLATION_START_TYPE);
337 $this->moveCursor($match[0]);
338 $this->pushState(self::STATE_INTERPOLATION);
339 …} elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, null, $this->cursor) && \str…
340 $this->pushToken(Token::STRING_TYPE, stripcslashes($match[0]));
341 $this->moveCursor($match[0]);
342 … } elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) {
343 list($expect, $lineno) = array_pop($this->brackets);
344 if ('"' != $this->code[$this->cursor]) {
345 throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source);
348 $this->popState();
349 ++$this->cursor;
352 … SyntaxError(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $th…
358 $bracket = end($this->brackets);
359 …if ($this->options['interpolation'][0] === $bracket[0] && preg_match($this->regexes['interpolation…
360 array_pop($this->brackets);
361 $this->pushToken(Token::INTERPOLATION_END_TYPE);
362 $this->moveCursor($match[0]);
363 $this->popState();
365 $this->lexExpression();
376 $this->tokens[] = new Token($type, $value, $this->lineno);
381 $this->cursor += \strlen($text);
382 $this->lineno += substr_count($text, "\n");
389 array_keys($this->env->getUnaryOperators()),
390 array_keys($this->env->getBinaryOperators())
417 $this->states[] = $this->state;
418 $this->state = $state;
423 if (0 === \count($this->states)) {
427 $this->state = array_pop($this->states);