From db678b45302651f2e58a020e28e1d1897e60bb65 Mon Sep 17 00:00:00 2001 From: Tomas Pilar Date: Wed, 28 Aug 2019 13:30:43 +0200 Subject: [PATCH] allow use "[" and "]" in domain name --- .editorconfig | 2 +- README.md | 2 +- src/Generator/SQL/Phrase.php | 4 ++-- .../SQL/Resolver/AbstractFilterResolver.php | 2 +- src/Generator/SQL/Word.php | 4 ++-- src/Tokenizer/Full.php | 12 ++++++------ 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.editorconfig b/.editorconfig index fa0484f..f4b5226 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,7 +7,7 @@ charset = utf-8 trim_trailing_whitespace = true [*.{php,php}] -indent_style = tab +indent_style = space indent_size = 4 [*.{yml,yaml}] diff --git a/README.md b/README.md index e1cd052..31f6678 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Write filter query as simple string via Filter Query Language (FQL) syntax. Filt **Some FQL query example:** -`q:"samsung" AND introducedAt:["2018-01-01 00:00:00" TO NOW] AND NOT (type:tv OR type:mobile) OR price:{10 TO *]` +`q:"samsung" AND introducedAt:["2018-01-01 00:00:00" TO NOW] AND NOT type:(tv OR "mobile phone") OR price:{10 TO *]` ## Installation diff --git a/src/Generator/SQL/Phrase.php b/src/Generator/SQL/Phrase.php index f9c0ead..1107bea 100644 --- a/src/Generator/SQL/Phrase.php +++ b/src/Generator/SQL/Phrase.php @@ -39,14 +39,14 @@ public function visit(AbstractNode $node, ?AbstractVisitor $subVisitor = null, ? $token = $termNode->getToken(); $domain = $token->getDomain(); - if ($domain === '') { + if ($domain === '' || $domain === null) { $parent = $options['parent'] ?? false; if ($parent instanceof GroupNode) { $tokenLeft = $parent->getTokenLeft(); $domain = $tokenLeft->getDomain(); } - if ($domain === '') { + if ($domain === '' || $domain === null) { throw new LogicException('Missing required domain'); } } diff --git a/src/Generator/SQL/Resolver/AbstractFilterResolver.php b/src/Generator/SQL/Resolver/AbstractFilterResolver.php index a3c3d9c..650af41 100644 --- a/src/Generator/SQL/Resolver/AbstractFilterResolver.php +++ b/src/Generator/SQL/Resolver/AbstractFilterResolver.php @@ -14,7 +14,7 @@ public function resolve(string $column, $value): string { $mapping = $this->getResolvers(); if (! isset($mapping[$column])) { - throw new InvalidArgumentException($column); + throw new InvalidArgumentException('Missing filter for "' . $column . '"'); } return call_user_func($mapping[$column], $value); diff --git a/src/Generator/SQL/Word.php b/src/Generator/SQL/Word.php index 2202162..b509d59 100644 --- a/src/Generator/SQL/Word.php +++ b/src/Generator/SQL/Word.php @@ -39,14 +39,14 @@ public function visit(AbstractNode $node, ?AbstractVisitor $subVisitor = null, ? $token = $termNode->getToken(); $domain = $token->getDomain(); - if ($domain === '') { + if ($domain === '' || $domain === null) { $parent = $options['parent'] ?? false; if ($parent instanceof GroupNode) { $tokenLeft = $parent->getTokenLeft(); $domain = $tokenLeft->getDomain(); } - if ($domain === '') { + if ($domain === '' || $domain === null) { throw new LogicException('Missing required domain'); } } diff --git a/src/Tokenizer/Full.php b/src/Tokenizer/Full.php index 9641df3..9066890 100644 --- a/src/Tokenizer/Full.php +++ b/src/Tokenizer/Full.php @@ -27,19 +27,19 @@ final class Full extends AbstractTokenExtractor '/(?NOT)(?:[\s"()+\-!]|$)/Au' => Tokenizer::TOKEN_LOGICAL_NOT, '/(?(?:AND|&&))(?:[\s"()+\-!]|$)/Au' => Tokenizer::TOKEN_LOGICAL_AND, '/(?(?:OR|\|\|))(?:[\s"()+\-!]|$)/Au' => Tokenizer::TOKEN_LOGICAL_OR, - '/(?(?:(?[a-zA-Z_][a-zA-Z0-9_\-.]*):)?(?\())/Au' => Tokenizer::TOKEN_GROUP_BEGIN, + '/(?(?:(?[a-zA-Z_][a-zA-Z0-9_\-.\[\]]*):)?(?\())/Au' => Tokenizer::TOKEN_GROUP_BEGIN, '/(?(?:(?(?[a-zA-Z0-9_][a-zA-Z0-9_\-.]*)))(?:[\s"()+!]|$)/Au' => Tokenizer::TOKEN_TERM, '/(?(?:(?(?[a-zA-Z0-9_][a-zA-Z0-9_\-.]*)))(?:[\s"()+!]|$)/Au' => Tokenizer::TOKEN_TERM, - '/(?(?:(?[a-zA-Z_][a-zA-Z0-9_\-.]*):)?(?(?.*?)(?:(? Tokenizer::TOKEN_TERM, - '/(?(?:(?[a-zA-Z_][a-zA-Z0-9_\-.]*):)?(?[\[\{])' . + '/(?(?:(?[a-zA-Z_][a-zA-Z0-9_\-.\[\]]*):)?(?(?.*?)(?:(? Tokenizer::TOKEN_TERM, + '/(?(?:(?[a-zA-Z_][a-zA-Z0-9_\-.\[\]]*):)?(?[\[\{])' . '(?([a-zA-Z0-9\,\._-]+|\*)|(?(?([a-zA-Z0-9\,\._-]+|\*)|(?(?[\]\}]))/Aus' => Tokenizer::TOKEN_TERM, - '/(?(?:(?[a-zA-Z_][a-zA-Z0-9_\-.]*):)?(?(?:\\\\\\\\|\\\\ |\\\\\(|\\\\\)|\\\\"|' . - '[^"()\s])+?))(?:(? Tokenizer::TOKEN_TERM, + '/(?(?:(?[a-zA-Z_][a-zA-Z0-9_\-.\[\]]*):)?(?(?:\\\\\\\\|\\\\ |\\\\\(|\\\\\)|\\\\"|' . + '[^"()\s])+?))(?:(? Tokenizer::TOKEN_TERM, ];