Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/sitepres.../lib/twig/src
File: Lexer.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/*
[2] Fix | Delete
* This file is part of Twig.
[3] Fix | Delete
*
[4] Fix | Delete
* (c) Fabien Potencier
[5] Fix | Delete
* (c) Armin Ronacher
[6] Fix | Delete
*
[7] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[8] Fix | Delete
* file that was distributed with this source code.
[9] Fix | Delete
*/
[10] Fix | Delete
namespace WPML\Core\Twig;
[11] Fix | Delete
[12] Fix | Delete
use WPML\Core\Twig\Error\SyntaxError;
[13] Fix | Delete
/**
[14] Fix | Delete
* Lexes a template string.
[15] Fix | Delete
*
[16] Fix | Delete
* @author Fabien Potencier <fabien@symfony.com>
[17] Fix | Delete
*/
[18] Fix | Delete
class Lexer implements \WPML\Core\Twig_LexerInterface
[19] Fix | Delete
{
[20] Fix | Delete
protected $tokens;
[21] Fix | Delete
protected $code;
[22] Fix | Delete
protected $cursor;
[23] Fix | Delete
protected $lineno;
[24] Fix | Delete
protected $end;
[25] Fix | Delete
protected $state;
[26] Fix | Delete
protected $states;
[27] Fix | Delete
protected $brackets;
[28] Fix | Delete
protected $env;
[29] Fix | Delete
// to be renamed to $name in 2.0 (where it is private)
[30] Fix | Delete
protected $filename;
[31] Fix | Delete
protected $options;
[32] Fix | Delete
protected $regexes;
[33] Fix | Delete
protected $position;
[34] Fix | Delete
protected $positions;
[35] Fix | Delete
protected $currentVarBlockLine;
[36] Fix | Delete
private $source;
[37] Fix | Delete
const STATE_DATA = 0;
[38] Fix | Delete
const STATE_BLOCK = 1;
[39] Fix | Delete
const STATE_VAR = 2;
[40] Fix | Delete
const STATE_STRING = 3;
[41] Fix | Delete
const STATE_INTERPOLATION = 4;
[42] Fix | Delete
const REGEX_NAME = '/[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*/A';
[43] Fix | Delete
const REGEX_NUMBER = '/[0-9]+(?:\\.[0-9]+)?([Ee][\\+\\-][0-9]+)?/A';
[44] Fix | Delete
const REGEX_STRING = '/"([^#"\\\\]*(?:\\\\.[^#"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As';
[45] Fix | Delete
const REGEX_DQ_STRING_DELIM = '/"/A';
[46] Fix | Delete
const REGEX_DQ_STRING_PART = '/[^#"\\\\]*(?:(?:\\\\.|#(?!\\{))[^#"\\\\]*)*/As';
[47] Fix | Delete
const PUNCTUATION = '()[]{}?:.,|';
[48] Fix | Delete
public function __construct(\WPML\Core\Twig\Environment $env, array $options = [])
[49] Fix | Delete
{
[50] Fix | Delete
$this->env = $env;
[51] Fix | Delete
$this->options = \array_merge(['tag_comment' => ['{#', '#}'], 'tag_block' => ['{%', '%}'], 'tag_variable' => ['{{', '}}'], 'whitespace_trim' => '-', 'whitespace_line_trim' => '~', 'whitespace_line_chars' => ' \\t\\0\\x0B', 'interpolation' => ['#{', '}']], $options);
[52] Fix | Delete
// when PHP 7.3 is the min version, we will be able to remove the '#' part in preg_quote as it's part of the default
[53] Fix | Delete
$this->regexes = [
[54] Fix | Delete
// }}
[55] Fix | Delete
'lex_var' => '{
[56] Fix | Delete
\\s*
[57] Fix | Delete
(?:' . \preg_quote($this->options['whitespace_trim'] . $this->options['tag_variable'][1], '#') . '\\s*' . '|' . \preg_quote($this->options['whitespace_line_trim'] . $this->options['tag_variable'][1], '#') . '[' . $this->options['whitespace_line_chars'] . ']*' . '|' . \preg_quote($this->options['tag_variable'][1], '#') . ')
[58] Fix | Delete
}Ax',
[59] Fix | Delete
// %}
[60] Fix | Delete
'lex_block' => '{
[61] Fix | Delete
\\s*
[62] Fix | Delete
(?:' . \preg_quote($this->options['whitespace_trim'] . $this->options['tag_block'][1], '#') . '\\s*\\n?' . '|' . \preg_quote($this->options['whitespace_line_trim'] . $this->options['tag_block'][1], '#') . '[' . $this->options['whitespace_line_chars'] . ']*' . '|' . \preg_quote($this->options['tag_block'][1], '#') . '\\n?' . ')
[63] Fix | Delete
}Ax',
[64] Fix | Delete
// {% endverbatim %}
[65] Fix | Delete
'lex_raw_data' => '{' . \preg_quote($this->options['tag_block'][0], '#') . '(' . $this->options['whitespace_trim'] . '|' . $this->options['whitespace_line_trim'] . ')?\\s*' . '(?:end%s)' . '\\s*' . '(?:' . \preg_quote($this->options['whitespace_trim'] . $this->options['tag_block'][1], '#') . '\\s*' . '|' . \preg_quote($this->options['whitespace_line_trim'] . $this->options['tag_block'][1], '#') . '[' . $this->options['whitespace_line_chars'] . ']*' . '|' . \preg_quote($this->options['tag_block'][1], '#') . ')
[66] Fix | Delete
}sx',
[67] Fix | Delete
'operator' => $this->getOperatorRegex(),
[68] Fix | Delete
// #}
[69] Fix | Delete
'lex_comment' => '{
[70] Fix | Delete
(?:' . \preg_quote($this->options['whitespace_trim']) . \preg_quote($this->options['tag_comment'][1], '#') . '\\s*\\n?' . '|' . \preg_quote($this->options['whitespace_line_trim'] . $this->options['tag_comment'][1], '#') . '[' . $this->options['whitespace_line_chars'] . ']*' . '|' . \preg_quote($this->options['tag_comment'][1], '#') . '\\n?' . ')
[71] Fix | Delete
}sx',
[72] Fix | Delete
// verbatim %}
[73] Fix | Delete
'lex_block_raw' => '{
[74] Fix | Delete
\\s*
[75] Fix | Delete
(raw|verbatim)
[76] Fix | Delete
\\s*
[77] Fix | Delete
(?:' . \preg_quote($this->options['whitespace_trim'] . $this->options['tag_block'][1], '#') . '\\s*' . '|' . \preg_quote($this->options['whitespace_line_trim'] . $this->options['tag_block'][1], '#') . '[' . $this->options['whitespace_line_chars'] . ']*' . '|' . \preg_quote($this->options['tag_block'][1], '#') . ')
[78] Fix | Delete
}Asx',
[79] Fix | Delete
'lex_block_line' => '{\\s*line\\s+(\\d+)\\s*' . \preg_quote($this->options['tag_block'][1], '#') . '}As',
[80] Fix | Delete
// {{ or {% or {#
[81] Fix | Delete
'lex_tokens_start' => '{
[82] Fix | Delete
(' . \preg_quote($this->options['tag_variable'][0], '#') . '|' . \preg_quote($this->options['tag_block'][0], '#') . '|' . \preg_quote($this->options['tag_comment'][0], '#') . ')(' . \preg_quote($this->options['whitespace_trim'], '#') . '|' . \preg_quote($this->options['whitespace_line_trim'], '#') . ')?
[83] Fix | Delete
}sx',
[84] Fix | Delete
'interpolation_start' => '{' . \preg_quote($this->options['interpolation'][0], '#') . '\\s*}A',
[85] Fix | Delete
'interpolation_end' => '{\\s*' . \preg_quote($this->options['interpolation'][1], '#') . '}A',
[86] Fix | Delete
];
[87] Fix | Delete
}
[88] Fix | Delete
public function tokenize($code, $name = null)
[89] Fix | Delete
{
[90] Fix | Delete
if (!$code instanceof \WPML\Core\Twig\Source) {
[91] Fix | Delete
@\trigger_error(\sprintf('Passing a string as the $code argument of %s() is deprecated since version 1.27 and will be removed in 2.0. Pass a \\Twig\\Source instance instead.', __METHOD__), \E_USER_DEPRECATED);
[92] Fix | Delete
$this->source = new \WPML\Core\Twig\Source($code, $name);
[93] Fix | Delete
} else {
[94] Fix | Delete
$this->source = $code;
[95] Fix | Delete
}
[96] Fix | Delete
if ((int) \ini_get('mbstring.func_overload') & 2) {
[97] Fix | Delete
@\trigger_error('Support for having "mbstring.func_overload" different from 0 is deprecated version 1.29 and will be removed in 2.0.', \E_USER_DEPRECATED);
[98] Fix | Delete
}
[99] Fix | Delete
if (\function_exists('mb_internal_encoding') && (int) \ini_get('mbstring.func_overload') & 2) {
[100] Fix | Delete
$mbEncoding = \mb_internal_encoding();
[101] Fix | Delete
\mb_internal_encoding('ASCII');
[102] Fix | Delete
} else {
[103] Fix | Delete
$mbEncoding = null;
[104] Fix | Delete
}
[105] Fix | Delete
$this->code = \str_replace(["\r\n", "\r"], "\n", $this->source->getCode());
[106] Fix | Delete
$this->filename = $this->source->getName();
[107] Fix | Delete
$this->cursor = 0;
[108] Fix | Delete
$this->lineno = 1;
[109] Fix | Delete
$this->end = \strlen($this->code);
[110] Fix | Delete
$this->tokens = [];
[111] Fix | Delete
$this->state = self::STATE_DATA;
[112] Fix | Delete
$this->states = [];
[113] Fix | Delete
$this->brackets = [];
[114] Fix | Delete
$this->position = -1;
[115] Fix | Delete
// find all token starts in one go
[116] Fix | Delete
\preg_match_all($this->regexes['lex_tokens_start'], $this->code, $matches, \PREG_OFFSET_CAPTURE);
[117] Fix | Delete
$this->positions = $matches;
[118] Fix | Delete
while ($this->cursor < $this->end) {
[119] Fix | Delete
// dispatch to the lexing functions depending
[120] Fix | Delete
// on the current state
[121] Fix | Delete
switch ($this->state) {
[122] Fix | Delete
case self::STATE_DATA:
[123] Fix | Delete
$this->lexData();
[124] Fix | Delete
break;
[125] Fix | Delete
case self::STATE_BLOCK:
[126] Fix | Delete
$this->lexBlock();
[127] Fix | Delete
break;
[128] Fix | Delete
case self::STATE_VAR:
[129] Fix | Delete
$this->lexVar();
[130] Fix | Delete
break;
[131] Fix | Delete
case self::STATE_STRING:
[132] Fix | Delete
$this->lexString();
[133] Fix | Delete
break;
[134] Fix | Delete
case self::STATE_INTERPOLATION:
[135] Fix | Delete
$this->lexInterpolation();
[136] Fix | Delete
break;
[137] Fix | Delete
}
[138] Fix | Delete
}
[139] Fix | Delete
$this->pushToken(\WPML\Core\Twig\Token::EOF_TYPE);
[140] Fix | Delete
if (!empty($this->brackets)) {
[141] Fix | Delete
list($expect, $lineno) = \array_pop($this->brackets);
[142] Fix | Delete
throw new \WPML\Core\Twig\Error\SyntaxError(\sprintf('Unclosed "%s".', $expect), $lineno, $this->source);
[143] Fix | Delete
}
[144] Fix | Delete
if ($mbEncoding) {
[145] Fix | Delete
\mb_internal_encoding($mbEncoding);
[146] Fix | Delete
}
[147] Fix | Delete
return new \WPML\Core\Twig\TokenStream($this->tokens, $this->source);
[148] Fix | Delete
}
[149] Fix | Delete
protected function lexData()
[150] Fix | Delete
{
[151] Fix | Delete
// if no matches are left we return the rest of the template as simple text token
[152] Fix | Delete
if ($this->position == \count($this->positions[0]) - 1) {
[153] Fix | Delete
$this->pushToken(\WPML\Core\Twig\Token::TEXT_TYPE, \substr($this->code, $this->cursor));
[154] Fix | Delete
$this->cursor = $this->end;
[155] Fix | Delete
return;
[156] Fix | Delete
}
[157] Fix | Delete
// Find the first token after the current cursor
[158] Fix | Delete
$position = $this->positions[0][++$this->position];
[159] Fix | Delete
while ($position[1] < $this->cursor) {
[160] Fix | Delete
if ($this->position == \count($this->positions[0]) - 1) {
[161] Fix | Delete
return;
[162] Fix | Delete
}
[163] Fix | Delete
$position = $this->positions[0][++$this->position];
[164] Fix | Delete
}
[165] Fix | Delete
// push the template text first
[166] Fix | Delete
$text = $textContent = \substr($this->code, $this->cursor, $position[1] - $this->cursor);
[167] Fix | Delete
// trim?
[168] Fix | Delete
if (isset($this->positions[2][$this->position][0])) {
[169] Fix | Delete
if ($this->options['whitespace_trim'] === $this->positions[2][$this->position][0]) {
[170] Fix | Delete
// whitespace_trim detected ({%-, {{- or {#-)
[171] Fix | Delete
$text = \rtrim($text);
[172] Fix | Delete
} elseif ($this->options['whitespace_line_trim'] === $this->positions[2][$this->position][0]) {
[173] Fix | Delete
// whitespace_line_trim detected ({%~, {{~ or {#~)
[174] Fix | Delete
// don't trim \r and \n
[175] Fix | Delete
$text = \rtrim($text, " \t\0\v");
[176] Fix | Delete
}
[177] Fix | Delete
}
[178] Fix | Delete
$this->pushToken(\WPML\Core\Twig\Token::TEXT_TYPE, $text);
[179] Fix | Delete
$this->moveCursor($textContent . $position[0]);
[180] Fix | Delete
switch ($this->positions[1][$this->position][0]) {
[181] Fix | Delete
case $this->options['tag_comment'][0]:
[182] Fix | Delete
$this->lexComment();
[183] Fix | Delete
break;
[184] Fix | Delete
case $this->options['tag_block'][0]:
[185] Fix | Delete
// raw data?
[186] Fix | Delete
if (\preg_match($this->regexes['lex_block_raw'], $this->code, $match, 0, $this->cursor)) {
[187] Fix | Delete
$this->moveCursor($match[0]);
[188] Fix | Delete
$this->lexRawData($match[1]);
[189] Fix | Delete
// {% line \d+ %}
[190] Fix | Delete
} elseif (\preg_match($this->regexes['lex_block_line'], $this->code, $match, 0, $this->cursor)) {
[191] Fix | Delete
$this->moveCursor($match[0]);
[192] Fix | Delete
$this->lineno = (int) $match[1];
[193] Fix | Delete
} else {
[194] Fix | Delete
$this->pushToken(\WPML\Core\Twig\Token::BLOCK_START_TYPE);
[195] Fix | Delete
$this->pushState(self::STATE_BLOCK);
[196] Fix | Delete
$this->currentVarBlockLine = $this->lineno;
[197] Fix | Delete
}
[198] Fix | Delete
break;
[199] Fix | Delete
case $this->options['tag_variable'][0]:
[200] Fix | Delete
$this->pushToken(\WPML\Core\Twig\Token::VAR_START_TYPE);
[201] Fix | Delete
$this->pushState(self::STATE_VAR);
[202] Fix | Delete
$this->currentVarBlockLine = $this->lineno;
[203] Fix | Delete
break;
[204] Fix | Delete
}
[205] Fix | Delete
}
[206] Fix | Delete
protected function lexBlock()
[207] Fix | Delete
{
[208] Fix | Delete
if (empty($this->brackets) && \preg_match($this->regexes['lex_block'], $this->code, $match, 0, $this->cursor)) {
[209] Fix | Delete
$this->pushToken(\WPML\Core\Twig\Token::BLOCK_END_TYPE);
[210] Fix | Delete
$this->moveCursor($match[0]);
[211] Fix | Delete
$this->popState();
[212] Fix | Delete
} else {
[213] Fix | Delete
$this->lexExpression();
[214] Fix | Delete
}
[215] Fix | Delete
}
[216] Fix | Delete
protected function lexVar()
[217] Fix | Delete
{
[218] Fix | Delete
if (empty($this->brackets) && \preg_match($this->regexes['lex_var'], $this->code, $match, 0, $this->cursor)) {
[219] Fix | Delete
$this->pushToken(\WPML\Core\Twig\Token::VAR_END_TYPE);
[220] Fix | Delete
$this->moveCursor($match[0]);
[221] Fix | Delete
$this->popState();
[222] Fix | Delete
} else {
[223] Fix | Delete
$this->lexExpression();
[224] Fix | Delete
}
[225] Fix | Delete
}
[226] Fix | Delete
protected function lexExpression()
[227] Fix | Delete
{
[228] Fix | Delete
// whitespace
[229] Fix | Delete
if (\preg_match('/\\s+/A', $this->code, $match, 0, $this->cursor)) {
[230] Fix | Delete
$this->moveCursor($match[0]);
[231] Fix | Delete
if ($this->cursor >= $this->end) {
[232] Fix | Delete
throw new \WPML\Core\Twig\Error\SyntaxError(\sprintf('Unclosed "%s".', self::STATE_BLOCK === $this->state ? 'block' : 'variable'), $this->currentVarBlockLine, $this->source);
[233] Fix | Delete
}
[234] Fix | Delete
}
[235] Fix | Delete
// arrow function
[236] Fix | Delete
if ('=' === $this->code[$this->cursor] && '>' === $this->code[$this->cursor + 1]) {
[237] Fix | Delete
$this->pushToken(\WPML\Core\Twig\Token::ARROW_TYPE, '=>');
[238] Fix | Delete
$this->moveCursor('=>');
[239] Fix | Delete
} elseif (\preg_match($this->regexes['operator'], $this->code, $match, 0, $this->cursor)) {
[240] Fix | Delete
$this->pushToken(\WPML\Core\Twig\Token::OPERATOR_TYPE, \preg_replace('/\\s+/', ' ', $match[0]));
[241] Fix | Delete
$this->moveCursor($match[0]);
[242] Fix | Delete
} elseif (\preg_match(self::REGEX_NAME, $this->code, $match, 0, $this->cursor)) {
[243] Fix | Delete
$this->pushToken(\WPML\Core\Twig\Token::NAME_TYPE, $match[0]);
[244] Fix | Delete
$this->moveCursor($match[0]);
[245] Fix | Delete
} elseif (\preg_match(self::REGEX_NUMBER, $this->code, $match, 0, $this->cursor)) {
[246] Fix | Delete
$number = (float) $match[0];
[247] Fix | Delete
// floats
[248] Fix | Delete
if (\ctype_digit($match[0]) && $number <= \PHP_INT_MAX) {
[249] Fix | Delete
$number = (int) $match[0];
[250] Fix | Delete
// integers lower than the maximum
[251] Fix | Delete
}
[252] Fix | Delete
$this->pushToken(\WPML\Core\Twig\Token::NUMBER_TYPE, $number);
[253] Fix | Delete
$this->moveCursor($match[0]);
[254] Fix | Delete
} elseif (\false !== \strpos(self::PUNCTUATION, $this->code[$this->cursor])) {
[255] Fix | Delete
// opening bracket
[256] Fix | Delete
if (\false !== \strpos('([{', $this->code[$this->cursor])) {
[257] Fix | Delete
$this->brackets[] = [$this->code[$this->cursor], $this->lineno];
[258] Fix | Delete
} elseif (\false !== \strpos(')]}', $this->code[$this->cursor])) {
[259] Fix | Delete
if (empty($this->brackets)) {
[260] Fix | Delete
throw new \WPML\Core\Twig\Error\SyntaxError(\sprintf('Unexpected "%s".', $this->code[$this->cursor]), $this->lineno, $this->source);
[261] Fix | Delete
}
[262] Fix | Delete
list($expect, $lineno) = \array_pop($this->brackets);
[263] Fix | Delete
if ($this->code[$this->cursor] != \strtr($expect, '([{', ')]}')) {
[264] Fix | Delete
throw new \WPML\Core\Twig\Error\SyntaxError(\sprintf('Unclosed "%s".', $expect), $lineno, $this->source);
[265] Fix | Delete
}
[266] Fix | Delete
}
[267] Fix | Delete
$this->pushToken(\WPML\Core\Twig\Token::PUNCTUATION_TYPE, $this->code[$this->cursor]);
[268] Fix | Delete
++$this->cursor;
[269] Fix | Delete
} elseif (\preg_match(self::REGEX_STRING, $this->code, $match, 0, $this->cursor)) {
[270] Fix | Delete
$this->pushToken(\WPML\Core\Twig\Token::STRING_TYPE, \stripcslashes(\substr($match[0], 1, -1)));
[271] Fix | Delete
$this->moveCursor($match[0]);
[272] Fix | Delete
} elseif (\preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, 0, $this->cursor)) {
[273] Fix | Delete
$this->brackets[] = ['"', $this->lineno];
[274] Fix | Delete
$this->pushState(self::STATE_STRING);
[275] Fix | Delete
$this->moveCursor($match[0]);
[276] Fix | Delete
} else {
[277] Fix | Delete
throw new \WPML\Core\Twig\Error\SyntaxError(\sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source);
[278] Fix | Delete
}
[279] Fix | Delete
}
[280] Fix | Delete
protected function lexRawData($tag)
[281] Fix | Delete
{
[282] Fix | Delete
if ('raw' === $tag) {
[283] Fix | Delete
@\trigger_error(\sprintf('Twig Tag "raw" is deprecated since version 1.21. Use "verbatim" instead in %s at line %d.', $this->filename, $this->lineno), \E_USER_DEPRECATED);
[284] Fix | Delete
}
[285] Fix | Delete
if (!\preg_match(\str_replace('%s', $tag, $this->regexes['lex_raw_data']), $this->code, $match, \PREG_OFFSET_CAPTURE, $this->cursor)) {
[286] Fix | Delete
throw new \WPML\Core\Twig\Error\SyntaxError(\sprintf('Unexpected end of file: Unclosed "%s" block.', $tag), $this->lineno, $this->source);
[287] Fix | Delete
}
[288] Fix | Delete
$text = \substr($this->code, $this->cursor, $match[0][1] - $this->cursor);
[289] Fix | Delete
$this->moveCursor($text . $match[0][0]);
[290] Fix | Delete
// trim?
[291] Fix | Delete
if (isset($match[1][0])) {
[292] Fix | Delete
if ($this->options['whitespace_trim'] === $match[1][0]) {
[293] Fix | Delete
// whitespace_trim detected ({%-, {{- or {#-)
[294] Fix | Delete
$text = \rtrim($text);
[295] Fix | Delete
} else {
[296] Fix | Delete
// whitespace_line_trim detected ({%~, {{~ or {#~)
[297] Fix | Delete
// don't trim \r and \n
[298] Fix | Delete
$text = \rtrim($text, " \t\0\v");
[299] Fix | Delete
}
[300] Fix | Delete
}
[301] Fix | Delete
$this->pushToken(\WPML\Core\Twig\Token::TEXT_TYPE, $text);
[302] Fix | Delete
}
[303] Fix | Delete
protected function lexComment()
[304] Fix | Delete
{
[305] Fix | Delete
if (!\preg_match($this->regexes['lex_comment'], $this->code, $match, \PREG_OFFSET_CAPTURE, $this->cursor)) {
[306] Fix | Delete
throw new \WPML\Core\Twig\Error\SyntaxError('Unclosed comment.', $this->lineno, $this->source);
[307] Fix | Delete
}
[308] Fix | Delete
$this->moveCursor(\substr($this->code, $this->cursor, $match[0][1] - $this->cursor) . $match[0][0]);
[309] Fix | Delete
}
[310] Fix | Delete
protected function lexString()
[311] Fix | Delete
{
[312] Fix | Delete
if (\preg_match($this->regexes['interpolation_start'], $this->code, $match, 0, $this->cursor)) {
[313] Fix | Delete
$this->brackets[] = [$this->options['interpolation'][0], $this->lineno];
[314] Fix | Delete
$this->pushToken(\WPML\Core\Twig\Token::INTERPOLATION_START_TYPE);
[315] Fix | Delete
$this->moveCursor($match[0]);
[316] Fix | Delete
$this->pushState(self::STATE_INTERPOLATION);
[317] Fix | Delete
} elseif (\preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, 0, $this->cursor) && \strlen($match[0]) > 0) {
[318] Fix | Delete
$this->pushToken(\WPML\Core\Twig\Token::STRING_TYPE, \stripcslashes($match[0]));
[319] Fix | Delete
$this->moveCursor($match[0]);
[320] Fix | Delete
} elseif (\preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, 0, $this->cursor)) {
[321] Fix | Delete
list($expect, $lineno) = \array_pop($this->brackets);
[322] Fix | Delete
if ('"' != $this->code[$this->cursor]) {
[323] Fix | Delete
throw new \WPML\Core\Twig\Error\SyntaxError(\sprintf('Unclosed "%s".', $expect), $lineno, $this->source);
[324] Fix | Delete
}
[325] Fix | Delete
$this->popState();
[326] Fix | Delete
++$this->cursor;
[327] Fix | Delete
} else {
[328] Fix | Delete
// unlexable
[329] Fix | Delete
throw new \WPML\Core\Twig\Error\SyntaxError(\sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source);
[330] Fix | Delete
}
[331] Fix | Delete
}
[332] Fix | Delete
protected function lexInterpolation()
[333] Fix | Delete
{
[334] Fix | Delete
$bracket = \end($this->brackets);
[335] Fix | Delete
if ($this->options['interpolation'][0] === $bracket[0] && \preg_match($this->regexes['interpolation_end'], $this->code, $match, 0, $this->cursor)) {
[336] Fix | Delete
\array_pop($this->brackets);
[337] Fix | Delete
$this->pushToken(\WPML\Core\Twig\Token::INTERPOLATION_END_TYPE);
[338] Fix | Delete
$this->moveCursor($match[0]);
[339] Fix | Delete
$this->popState();
[340] Fix | Delete
} else {
[341] Fix | Delete
$this->lexExpression();
[342] Fix | Delete
}
[343] Fix | Delete
}
[344] Fix | Delete
protected function pushToken($type, $value = '')
[345] Fix | Delete
{
[346] Fix | Delete
// do not push empty text tokens
[347] Fix | Delete
if (\WPML\Core\Twig\Token::TEXT_TYPE === $type && '' === $value) {
[348] Fix | Delete
return;
[349] Fix | Delete
}
[350] Fix | Delete
$this->tokens[] = new \WPML\Core\Twig\Token($type, $value, $this->lineno);
[351] Fix | Delete
}
[352] Fix | Delete
protected function moveCursor($text)
[353] Fix | Delete
{
[354] Fix | Delete
$this->cursor += \strlen($text);
[355] Fix | Delete
$this->lineno += \substr_count($text, "\n");
[356] Fix | Delete
}
[357] Fix | Delete
protected function getOperatorRegex()
[358] Fix | Delete
{
[359] Fix | Delete
$operators = \array_merge(['='], \array_keys($this->env->getUnaryOperators()), \array_keys($this->env->getBinaryOperators()));
[360] Fix | Delete
$operators = \array_combine($operators, \array_map('strlen', $operators));
[361] Fix | Delete
\arsort($operators);
[362] Fix | Delete
$regex = [];
[363] Fix | Delete
foreach ($operators as $operator => $length) {
[364] Fix | Delete
// an operator that ends with a character must be followed by
[365] Fix | Delete
// a whitespace or a parenthesis
[366] Fix | Delete
if (\ctype_alpha($operator[$length - 1])) {
[367] Fix | Delete
$r = \preg_quote($operator, '/') . '(?=[\\s()])';
[368] Fix | Delete
} else {
[369] Fix | Delete
$r = \preg_quote($operator, '/');
[370] Fix | Delete
}
[371] Fix | Delete
// an operator with a space can be any amount of whitespaces
[372] Fix | Delete
$r = \preg_replace('/\\s+/', '\\s+', $r);
[373] Fix | Delete
$regex[] = $r;
[374] Fix | Delete
}
[375] Fix | Delete
return '/' . \implode('|', $regex) . '/A';
[376] Fix | Delete
}
[377] Fix | Delete
protected function pushState($state)
[378] Fix | Delete
{
[379] Fix | Delete
$this->states[] = $this->state;
[380] Fix | Delete
$this->state = $state;
[381] Fix | Delete
}
[382] Fix | Delete
protected function popState()
[383] Fix | Delete
{
[384] Fix | Delete
if (0 === \count($this->states)) {
[385] Fix | Delete
throw new \LogicException('Cannot pop state without a previous state.');
[386] Fix | Delete
}
[387] Fix | Delete
$this->state = \array_pop($this->states);
[388] Fix | Delete
}
[389] Fix | Delete
}
[390] Fix | Delete
\class_alias('WPML\\Core\\Twig\\Lexer', 'WPML\\Core\\Twig_Lexer');
[391] Fix | Delete
[392] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function