Skip to content

Commit

Permalink
fixup typo and bitwise const
Browse files Browse the repository at this point in the history
  • Loading branch information
instabledesign committed Dec 16, 2023
1 parent 5daedfa commit cf7ea53
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
72 changes: 36 additions & 36 deletions src/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down Expand Up @@ -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));

Expand All @@ -218,7 +218,7 @@ protected function getType(&$value)

break;

// Comparison operator
// Comparison operator
case '=' === $value:
$type = self::T_EQUALS;

Expand Down Expand Up @@ -255,7 +255,7 @@ protected function getType(&$value)

break;

// Composite operator
// Composite operator
case '&' === $value:
$type = self::T_AND;

Expand Down Expand Up @@ -283,7 +283,7 @@ protected function getType(&$value)

break;

// Brace
// Brace
case '(' === $value:
$type = self::T_OPEN_PARENTHESIS;

Expand Down Expand Up @@ -324,7 +324,7 @@ protected function getType(&$value)

break;

// Default
// Default
default:
throw new UnknownTokenTypeException($value);
}
Expand Down
22 changes: 11 additions & 11 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down

0 comments on commit cf7ea53

Please sign in to comment.