private function lexFragment(LexerInterface $referenceLexer, string $valueFragment) : array
{
foreach (self::PATTERNS as $pattern => $tokenTypeConstant) {
if (1 === preg_match($pattern, $valueFragment, $matches)) {
if (null === $tokenTypeConstant) {
throw InvalidArgumentExceptionFactory::createForInvalidExpressionLanguageToken($valueFragment);
}
$match = $matches[1];
if (self::REFERENCE_LEXER === $tokenTypeConstant) {
return $referenceLexer->lex($match);
}
return [new Token($match, new TokenType($tokenTypeConstant))];
}
}
throw ExpressionLanguageExceptionFactory::createForCouldNotLexValue($valueFragment);
}