<?php
declare (strict_types=1);
namespace MailPoetVendor\Doctrine\ORM\Query;
if (!defined('ABSPATH')) exit;
use MailPoetVendor\Doctrine\Common\Lexer\AbstractLexer;
use MailPoetVendor\Doctrine\Deprecations\Deprecation;
use function constant;
use function ctype_alpha;
use function defined;
use function is_numeric;
use function str_contains;
use function str_replace;
use function stripos;
use function strlen;
use function strtoupper;
use function substr;
class Lexer extends AbstractLexer
{
 // All tokens that are not valid identifiers must be < 100
 public const T_NONE = TokenType::T_NONE;
 public const T_INTEGER = TokenType::T_INTEGER;
 public const T_STRING = TokenType::T_STRING;
 public const T_INPUT_PARAMETER = TokenType::T_INPUT_PARAMETER;
 public const T_FLOAT = TokenType::T_FLOAT;
 public const T_CLOSE_PARENTHESIS = TokenType::T_CLOSE_PARENTHESIS;
 public const T_OPEN_PARENTHESIS = TokenType::T_OPEN_PARENTHESIS;
 public const T_COMMA = TokenType::T_COMMA;
 public const T_DIVIDE = TokenType::T_DIVIDE;
 public const T_DOT = TokenType::T_DOT;
 public const T_EQUALS = TokenType::T_EQUALS;
 public const T_GREATER_THAN = TokenType::T_GREATER_THAN;
 public const T_LOWER_THAN = TokenType::T_LOWER_THAN;
 public const T_MINUS = TokenType::T_MINUS;
 public const T_MULTIPLY = TokenType::T_MULTIPLY;
 public const T_NEGATE = TokenType::T_NEGATE;
 public const T_PLUS = TokenType::T_PLUS;
 public const T_OPEN_CURLY_BRACE = TokenType::T_OPEN_CURLY_BRACE;
 public const T_CLOSE_CURLY_BRACE = TokenType::T_CLOSE_CURLY_BRACE;
 // All tokens that are identifiers or keywords that could be considered as identifiers should be >= 100
 public const T_ALIASED_NAME = TokenType::T_ALIASED_NAME;
 public const T_FULLY_QUALIFIED_NAME = TokenType::T_FULLY_QUALIFIED_NAME;
 public const T_IDENTIFIER = TokenType::T_IDENTIFIER;
 // All keyword tokens should be >= 200
 public const T_ALL = TokenType::T_ALL;
 public const T_AND = TokenType::T_AND;
 public const T_ANY = TokenType::T_ANY;
 public const T_AS = TokenType::T_AS;
 public const T_ASC = TokenType::T_ASC;
 public const T_AVG = TokenType::T_AVG;
 public const T_BETWEEN = TokenType::T_BETWEEN;
 public const T_BOTH = TokenType::T_BOTH;
 public const T_BY = TokenType::T_BY;
 public const T_CASE = TokenType::T_CASE;
 public const T_COALESCE = TokenType::T_COALESCE;
 public const T_COUNT = TokenType::T_COUNT;
 public const T_DELETE = TokenType::T_DELETE;
 public const T_DESC = TokenType::T_DESC;
 public const T_DISTINCT = TokenType::T_DISTINCT;
 public const T_ELSE = TokenType::T_ELSE;
 public const T_EMPTY = TokenType::T_EMPTY;
 public const T_END = TokenType::T_END;
 public const T_ESCAPE = TokenType::T_ESCAPE;
 public const T_EXISTS = TokenType::T_EXISTS;
 public const T_FALSE = TokenType::T_FALSE;
 public const T_FROM = TokenType::T_FROM;
 public const T_GROUP = TokenType::T_GROUP;
 public const T_HAVING = TokenType::T_HAVING;
 public const T_HIDDEN = TokenType::T_HIDDEN;
 public const T_IN = TokenType::T_IN;
 public const T_INDEX = TokenType::T_INDEX;
 public const T_INNER = TokenType::T_INNER;
 public const T_INSTANCE = TokenType::T_INSTANCE;
 public const T_IS = TokenType::T_IS;
 public const T_JOIN = TokenType::T_JOIN;
 public const T_LEADING = TokenType::T_LEADING;
 public const T_LEFT = TokenType::T_LEFT;
 public const T_LIKE = TokenType::T_LIKE;
 public const T_MAX = TokenType::T_MAX;
 public const T_MEMBER = TokenType::T_MEMBER;
 public const T_MIN = TokenType::T_MIN;
 public const T_NEW = TokenType::T_NEW;
 public const T_NOT = TokenType::T_NOT;
 public const T_NULL = TokenType::T_NULL;
 public const T_NULLIF = TokenType::T_NULLIF;
 public const T_OF = TokenType::T_OF;
 public const T_OR = TokenType::T_OR;
 public const T_ORDER = TokenType::T_ORDER;
 public const T_OUTER = TokenType::T_OUTER;
 public const T_PARTIAL = TokenType::T_PARTIAL;
 public const T_SELECT = TokenType::T_SELECT;
 public const T_SET = TokenType::T_SET;
 public const T_SOME = TokenType::T_SOME;
 public const T_SUM = TokenType::T_SUM;
 public const T_THEN = TokenType::T_THEN;
 public const T_TRAILING = TokenType::T_TRAILING;
 public const T_TRUE = TokenType::T_TRUE;
 public const T_UPDATE = TokenType::T_UPDATE;
 public const T_WHEN = TokenType::T_WHEN;
 public const T_WHERE = TokenType::T_WHERE;
 public const T_WITH = TokenType::T_WITH;
 public function __construct($input)
 {
 $this->setInput($input);
 }
 protected function getCatchablePatterns()
 {
 return [
 '[a-z_][a-z0-9_]*\\:[a-z_][a-z0-9_]*(?:\\\\[a-z_][a-z0-9_]*)*',
 // aliased name
 '[a-z_\\\\][a-z0-9_]*(?:\\\\[a-z_][a-z0-9_]*)*',
 // identifier or qualified name
 '(?:[0-9]+(?:[\\.][0-9]+)*)(?:e[+-]?[0-9]+)?',
 // numbers
 "'(?:[^']|'')*'",
 // quoted strings
 '\\?[0-9]*|:[a-z_][a-z0-9_]*',
 ];
 }
 protected function getNonCatchablePatterns()
 {
 return ['\\s+', '--.*', '(.)'];
 }
 protected function getType(&$value)
 {
 $type = TokenType::T_NONE;
 switch (\true) {
 // Recognize numeric values
 case is_numeric($value):
 if (str_contains($value, '.') || stripos($value, 'e') !== \false) {
 return TokenType::T_FLOAT;
 }
 return TokenType::T_INTEGER;
 // Recognize quoted strings
 case $value[0] === "'":
 $value = str_replace("''", "'", substr($value, 1, strlen($value) - 2));
 return TokenType::T_STRING;
 // Recognize identifiers, aliased or qualified names
 case ctype_alpha($value[0]) || $value[0] === '_' || $value[0] === '\\':
 $name = 'MailPoetVendor\\Doctrine\\ORM\\Query\\TokenType::T_' . strtoupper($value);
 if (defined($name)) {
 $type = constant($name);
 if ($type > 100) {
 return $type;
 }
 }
 if (str_contains($value, ':')) {
 Deprecation::trigger('doctrine/orm', 'https://github.com/doctrine/orm/issues/8818', 'Short namespace aliases such as "%s" are deprecated and will be removed in Doctrine ORM 3.0.', $value);
 // @phpstan-ignore classConstant.deprecated
 return TokenType::T_ALIASED_NAME;
 }
 if (str_contains($value, '\\')) {
 return TokenType::T_FULLY_QUALIFIED_NAME;
 }
 return TokenType::T_IDENTIFIER;
 // Recognize input parameters
 case $value[0] === '?' || $value[0] === ':':
 return TokenType::T_INPUT_PARAMETER;
 // Recognize symbols
 case $value === '.':
 return TokenType::T_DOT;
 case $value === ',':
 return TokenType::T_COMMA;
 case $value === '(':
 return TokenType::T_OPEN_PARENTHESIS;
 case $value === ')':
 return TokenType::T_CLOSE_PARENTHESIS;
 case $value === '=':
 return TokenType::T_EQUALS;
 case $value === '>':
 return TokenType::T_GREATER_THAN;
 case $value === '<':
 return TokenType::T_LOWER_THAN;
 case $value === '+':
 return TokenType::T_PLUS;
 case $value === '-':
 return TokenType::T_MINUS;
 case $value === '*':
 return TokenType::T_MULTIPLY;
 case $value === '/':
 return TokenType::T_DIVIDE;
 case $value === '!':
 return TokenType::T_NEGATE;
 case $value === '{':
 return TokenType::T_OPEN_CURLY_BRACE;
 case $value === '}':
 return TokenType::T_CLOSE_CURLY_BRACE;
 // Default
 default:
 }
 return $type;
 }
}
