From 5d6b4a5dfdea6d4e2814391afcfcd9cf4259c046 Mon Sep 17 00:00:00 2001 From: Fatih Kızmaz Date: Tue, 17 May 2022 00:57:37 +0300 Subject: Full support for arrays => min, max and avg funcs accept array argument. Also array function is defined which return arguments as array. Square bracket arrays are also supported. (#108) valid expression -> "max([1,2,3])" valid expression -> "max(array(1,2,3))" valid expression -> "max($ages_arr)" valid expression -> "max(ages_arr())" --- src/NXP/Classes/Tokenizer.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/NXP/Classes/Tokenizer.php') diff --git a/src/NXP/Classes/Tokenizer.php b/src/NXP/Classes/Tokenizer.php index 23e1cc9..c8b415d 100644 --- a/src/NXP/Classes/Tokenizer.php +++ b/src/NXP/Classes/Tokenizer.php @@ -76,6 +76,13 @@ class Tokenizer continue 2; + case '[' === $ch: + $this->tokens[] = new Token(Token::Function, 'array'); + $this->allowNegative = true; + $this->tokens[] = new Token(Token::LeftParenthesis, ''); + + continue 2; + case ' ' == $ch || "\n" == $ch || "\r" == $ch || "\t" == $ch: $this->tokens[] = new Token(Token::Space, ''); @@ -140,7 +147,7 @@ class Tokenizer break; - case $this->isRP($ch): + case $this->isRP($ch) || ']' === $ch : $this->emptyNumberBufferAsLiteral(); $this->emptyStrBufferAsVariable(); $this->allowNegative = false; @@ -196,8 +203,8 @@ class Tokenizer } /** - * @throws UnknownOperatorException * @throws IncorrectBracketsException + * @throws UnknownOperatorException * @return Token[] Array of tokens in revers polish notation */ public function buildReversePolishNotation() : array -- cgit v1.2.3