From cf7ea538841fd4a11ef1dbf97f8a3a4bd8a8912b Mon Sep 17 00:00:00 2001 From: Anthony Moutte Date: Sat, 16 Dec 2023 08:14:32 +0100 Subject: [PATCH] fixup typo and bitwise const --- src/Lexer.php | 72 +++++++++++++++++++++++++------------------------- src/Parser.php | 22 +++++++-------- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/Lexer.php b/src/Lexer.php index 701d446..629e58c 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -10,44 +10,44 @@ class Lexer extends AbstractLexer { public const T_NONE = 0; - public const T_ALL = 16777215; + public const T_ALL = 2 ** 24 - 1; // Punctuation - public const T_COMMA = 1; // 2**0 + public const T_COMMA = 2 ** 0; // Operand - public const T_OPERANDE = 30; // 2**1 + 2**2 + 2**3 + 2**4 - public const T_INTEGER = 2; // 2**1 - public const T_STRING = 4; // 2**2 - public const T_INPUT_PARAMETER = 8; // 2**3 - public const T_FLOAT = 16; // 2**4 + public const T_OPERAND = 2 ** 1 + 2 ** 2 + 2 ** 3 + 2 ** 4; + public const T_INTEGER = 2 ** 1; + public const T_STRING = 2 ** 2; + public const T_INPUT_PARAMETER = 2 ** 3; + public const T_FLOAT = 2 ** 4; // Comparison operator - public const T_COMPARISON = 7079904; // 2**5 + 2**6 + 2**7 + 2**8 + 2**9 + 2**10 + 2**18 + 2**19 + 2**21 + 2**22 - public const T_EQUALS = 32; // 2**5 - public const T_NOT_EQUALS = 64; // 2**6 - public const T_GREATER_THAN = 128; // 2**7 - public const T_GREATER_THAN_EQUALS = 256; // 2**8 - public const T_LOWER_THAN = 512; // 2**9 - public const T_LOWER_THAN_EQUALS = 1024; // 2**10 + public const T_COMPARISON = 2 ** 5 + 2 ** 6 + 2 ** 7 + 2 ** 8 + 2 ** 9 + 2 ** 10 + 2 ** 18 + 2 ** 19 + 2 ** 21 + 2 ** 22; + public const T_EQUALS = 2 ** 5; + public const T_NOT_EQUALS = 2 ** 6; + public const T_GREATER_THAN = 2 ** 7; + public const T_GREATER_THAN_EQUALS = 2 ** 8; + public const T_LOWER_THAN = 2 ** 9; + public const T_LOWER_THAN_EQUALS = 2 ** 10; // Composite operator - public const T_COMPOSITE = 63488; // 2**11 + 2**12 + 2**13 + 2**14 + 2**15 - public const T_AND = 2048; // 2**11 - public const T_NOT_AND = 4096; // 2**12 - public const T_OR = 8192; // 2**13 - public const T_NOT_OR = 16384; // 2**14 - public const T_XOR = 32768; // 2**15 + public const T_COMPOSITE = 2 ** 11 + 2 ** 12 + 2 ** 13 + 2 ** 14 + 2 ** 15; + public const T_AND = 2 ** 11; + public const T_NOT_AND = 2 ** 12; + public const T_OR = 2 ** 13; + public const T_NOT_OR = 2 ** 14; + public const T_XOR = 2 ** 15; // Brace - public const T_OPEN_PARENTHESIS = 65536; // 2**16 - public const T_CLOSE_PARENTHESIS = 131072; // 2**17 - public const T_OPEN_SQUARE_BRACKET = 262144; // 2**18 - public const T_NOT_OPEN_SQUARE_BRACKET = 524288; // 2**19 - public const T_CLOSE_SQUARE_BRACKET = 1048576; // 2**20 - public const T_DOUBLE_OPEN_CURLY_BRACKET = 2097152; // 2**21 - public const T_NOT_DOUBLE_OPEN_CURLY_BRACKET = 4194304; // 2**22 - public const T_DOUBLE_CLOSE_CURLY_BRACKET = 8388608; // 2**23 + public const T_OPEN_PARENTHESIS = 2 ** 16; + public const T_CLOSE_PARENTHESIS = 2 ** 17; + public const T_OPEN_SQUARE_BRACKET = 2 ** 18; + public const T_NOT_OPEN_SQUARE_BRACKET = 2 ** 19; + public const T_CLOSE_SQUARE_BRACKET = 2 ** 20; + public const T_DOUBLE_OPEN_CURLY_BRACKET = 2 ** 21; + public const T_NOT_DOUBLE_OPEN_CURLY_BRACKET = 2 ** 22; + public const T_DOUBLE_CLOSE_CURLY_BRACKET = 2 ** 23; /** * @return string[] @@ -184,21 +184,21 @@ protected function getType(&$value) break; - // Recognize numeric values + // Recognize numeric values case is_numeric($value): if (str_contains($value, '.') || false !== stripos($value, 'e')) { - $value = (float) $value; + $value = (float)$value; $type = self::T_FLOAT; break; } - $value = (int) $value; + $value = (int)$value; $type = self::T_INTEGER; break; - // Recognize quoted strings + // Recognize quoted strings case '"' === $value[0]: $value = str_replace('""', '"', substr($value, 1, \strlen($value) - 2)); @@ -218,7 +218,7 @@ protected function getType(&$value) break; - // Comparison operator + // Comparison operator case '=' === $value: $type = self::T_EQUALS; @@ -255,7 +255,7 @@ protected function getType(&$value) break; - // Composite operator + // Composite operator case '&' === $value: $type = self::T_AND; @@ -283,7 +283,7 @@ protected function getType(&$value) break; - // Brace + // Brace case '(' === $value: $type = self::T_OPEN_PARENTHESIS; @@ -324,7 +324,7 @@ protected function getType(&$value) break; - // Default + // Default default: throw new UnknownTokenTypeException($value); } diff --git a/src/Parser.php b/src/Parser.php index 9d1cce7..2ae5f46 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -136,7 +136,7 @@ private function getExpression(mixed $previousExpression = null): mixed break; case Lexer::T_COMMA: - $expectedTokenType = Lexer::T_OPERANDE; + $expectedTokenType = Lexer::T_OPERAND; break; @@ -188,51 +188,51 @@ private function getExpression(mixed $previousExpression = null): mixed case Lexer::T_EQUALS: $comparisonMethod = 'eq'; - $expectedTokenType = Lexer::T_OPERANDE; + $expectedTokenType = Lexer::T_OPERAND; break; case Lexer::T_NOT_EQUALS: $comparisonMethod = 'neq'; - $expectedTokenType = Lexer::T_OPERANDE; + $expectedTokenType = Lexer::T_OPERAND; break; case Lexer::T_GREATER_THAN: $comparisonMethod = 'gt'; - $expectedTokenType = Lexer::T_OPERANDE; + $expectedTokenType = Lexer::T_OPERAND; break; case Lexer::T_GREATER_THAN_EQUALS: $comparisonMethod = 'gte'; - $expectedTokenType = Lexer::T_OPERANDE; + $expectedTokenType = Lexer::T_OPERAND; break; case Lexer::T_LOWER_THAN: $comparisonMethod = 'lt'; - $expectedTokenType = Lexer::T_OPERANDE; + $expectedTokenType = Lexer::T_OPERAND; break; case Lexer::T_LOWER_THAN_EQUALS: $comparisonMethod = 'lte'; - $expectedTokenType = Lexer::T_OPERANDE; + $expectedTokenType = Lexer::T_OPERAND; break; case Lexer::T_NOT_OPEN_SQUARE_BRACKET: $comparisonMethod = 'notIn'; $comparisonMultipleOperande = []; - $expectedTokenType = Lexer::T_OPERANDE | Lexer::T_CLOSE_SQUARE_BRACKET; + $expectedTokenType = Lexer::T_OPERAND | Lexer::T_CLOSE_SQUARE_BRACKET; break; case Lexer::T_OPEN_SQUARE_BRACKET: $comparisonMethod = 'in'; $comparisonMultipleOperande = []; - $expectedTokenType = Lexer::T_OPERANDE | Lexer::T_CLOSE_SQUARE_BRACKET; + $expectedTokenType = Lexer::T_OPERAND | Lexer::T_CLOSE_SQUARE_BRACKET; break; @@ -248,14 +248,14 @@ private function getExpression(mixed $previousExpression = null): mixed case Lexer::T_DOUBLE_OPEN_CURLY_BRACKET: $comparisonMethod = 'contains'; $contains = true; - $expectedTokenType = Lexer::T_OPERANDE | Lexer::T_DOUBLE_CLOSE_CURLY_BRACKET; + $expectedTokenType = Lexer::T_OPERAND | Lexer::T_DOUBLE_CLOSE_CURLY_BRACKET; break; case Lexer::T_NOT_DOUBLE_OPEN_CURLY_BRACKET: $comparisonMethod = 'notContains'; $contains = true; - $expectedTokenType = Lexer::T_OPERANDE | Lexer::T_DOUBLE_CLOSE_CURLY_BRACKET; + $expectedTokenType = Lexer::T_OPERAND | Lexer::T_DOUBLE_CLOSE_CURLY_BRACKET; break;