public static function verify(&$context, $template)
{
$template = SafeString::stripExtendedComments($template);
$context['level'] = 0;
Parser::setDelimiter($context);
while (preg_match($context['tokens']['search'], $template, $matches)) {
// Skip a token when it is slash escaped
if ($context['flags']['slash'] && $matches[Token::POS_LSPACE] === '' && preg_match('/^(.*?)(\\\\+)$/s', $matches[Token::POS_LOTHER], $escmatch)) {
if (strlen($escmatch[2]) % 4) {
static::pushToken($context, substr($matches[Token::POS_LOTHER], 0, -2) . $context['tokens']['startchar']);
$matches[Token::POS_BEGINTAG] = substr($matches[Token::POS_BEGINTAG], 1);
$template = implode('', array_slice($matches, Token::POS_BEGINTAG));
continue;
} else {
$matches[Token::POS_LOTHER] = $escmatch[1] . str_repeat('\\', strlen($escmatch[2]) / 2);
}
}
$context['tokens']['count']++;
$V = static::token($matches, $context);
static::pushLeft($context);
if ($V) {
if (is_array($V)) {
array_push($V, $matches, $context['tokens']['partialind']);
}
static::pushToken($context, $V);
}
$template = "{$matches[Token::POS_RSPACE]}{$matches[Token::POS_ROTHER]}";
}
static::pushToken($context, $template);
if ($context['level'] > 0) {
array_pop($context['stack']);
array_pop($context['stack']);
$token = array_pop($context['stack']);
$context['error'][] = 'Unclosed token ' . ($context['rawblock'] ? "{{{{{$token}}}}}" : ($context['partialblock'] ? "{{#>{$token}}}" : "{{#{$token}}}")) . ' !!';
}
}