19declare(strict_types=1);
30 Operators::SUBTRACTION,
31 Operators::MULTIPLICATION,
64 public function tokenize(
string $expression): array
66 $expression = ltrim($expression,
'=');
67 $expression = trim($expression);
71 preg_match_all(
"/\[\[[^\]]*&[^\]]*\]\]/ui", $expression, $matches);
72 $matches_inside_brackets = $matches[0];
73 $replace_random = sha1(
"replacement_string");
76 foreach ($matches_inside_brackets as $match) {
80 $match_save = str_replace(
"&", $replace_random, $match);
81 $expression = str_replace($match, $match_save, $expression);
85 preg_match_all(
"/([^\\\\&]|\\\\&)*/ui", $expression, $matches);
93 $replace = str_ireplace(
'\&',
'&', $result);
96 $return[] = str_replace($replace_random,
"&", $replace);
105 static fn(
Operators $operator):
string => $operator->value,
114 $result = (bool) preg_match(
130 static fn(
Operators $operator):
string => $operator->value,
133 $pattern =
'#((^\[\[)[\d\.]+)|(\(|\)|\\' . implode(
"|\\",
$operators) .
')#';
PREG_SPLIT_NO_EMPTY PREG_SPLIT_DELIM_CAPTURE