Skip to content

Commit

Permalink
allow use "[" and "]" in domain name
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasPilar committed Aug 28, 2019
1 parent 815dcfb commit db678b4
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ charset = utf-8
trim_trailing_whitespace = true

[*.{php,php}]
indent_style = tab
indent_style = space
indent_size = 4

[*.{yml,yaml}]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Generator/SQL/Phrase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/SQL/Resolver/AbstractFilterResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Generator/SQL/Word.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/Tokenizer/Full.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ final class Full extends AbstractTokenExtractor
'/(?<lexeme>NOT)(?:[\s"()+\-!]|$)/Au' => Tokenizer::TOKEN_LOGICAL_NOT,
'/(?<lexeme>(?:AND|&&))(?:[\s"()+\-!]|$)/Au' => Tokenizer::TOKEN_LOGICAL_AND,
'/(?<lexeme>(?:OR|\|\|))(?:[\s"()+\-!]|$)/Au' => Tokenizer::TOKEN_LOGICAL_OR,
'/(?<lexeme>(?:(?<domain>[a-zA-Z_][a-zA-Z0-9_\-.]*):)?(?<delimiter>\())/Au' => Tokenizer::TOKEN_GROUP_BEGIN,
'/(?<lexeme>(?:(?<domain>[a-zA-Z_][a-zA-Z0-9_\-.\[\]]*):)?(?<delimiter>\())/Au' => Tokenizer::TOKEN_GROUP_BEGIN,
'/(?<lexeme>(?:(?<marker>(?<!\\\\)\#)(?<tag>[a-zA-Z0-9_][a-zA-Z0-9_\-.]*)))(?:[\s"()+!]|$)/Au'
=> Tokenizer::TOKEN_TERM,
'/(?<lexeme>(?:(?<marker>(?<!\\\\)@)(?<user>[a-zA-Z0-9_][a-zA-Z0-9_\-.]*)))(?:[\s"()+!]|$)/Au'
=> Tokenizer::TOKEN_TERM,
'/(?<lexeme>(?:(?<domain>[a-zA-Z_][a-zA-Z0-9_\-.]*):)?(?<quote>(?<!\\\\)["])(?<phrase>.*?)(?:(?<!\\\\)' .
'(?P=quote)))/Aus' => Tokenizer::TOKEN_TERM,
'/(?<lexeme>(?:(?<domain>[a-zA-Z_][a-zA-Z0-9_\-.]*):)?(?<rangeStartSymbol>[\[\{])' .
'/(?<lexeme>(?:(?<domain>[a-zA-Z_][a-zA-Z0-9_\-.\[\]]*):)?(?<quote>(?<!\\\\)["])(?<phrase>.*?)(?:(?<!\\\\)' .
'(?P=quote)))/Aus' => Tokenizer::TOKEN_TERM,
'/(?<lexeme>(?:(?<domain>[a-zA-Z_][a-zA-Z0-9_\-.\[\]]*):)?(?<rangeStartSymbol>[\[\{])' .
'(?<rangeFrom>([a-zA-Z0-9\,\._-]+|\*)|(?<quoteFrom>(?<!\\\\)["]).*(?:(?<!\\\\)(?P=quoteFrom))) TO ' .
'(?<rangeTo>([a-zA-Z0-9\,\._-]+|\*)|(?<quoteTo>(?<!\\\\)["]).*(?:(?<!\\\\)(?P=quoteTo)))' .
'(?<rangeEndSymbol>[\]\}]))/Aus' => Tokenizer::TOKEN_TERM,
'/(?<lexeme>(?:(?<domain>[a-zA-Z_][a-zA-Z0-9_\-.]*):)?(?<word>(?:\\\\\\\\|\\\\ |\\\\\(|\\\\\)|\\\\"|' .
'[^"()\s])+?))(?:(?<!\\\\)["]|\(|\)|$|\s)/Au' => Tokenizer::TOKEN_TERM,
'/(?<lexeme>(?:(?<domain>[a-zA-Z_][a-zA-Z0-9_\-.\[\]]*):)?(?<word>(?:\\\\\\\\|\\\\ |\\\\\(|\\\\\)|\\\\"|' .
'[^"()\s])+?))(?:(?<!\\\\)["]|\(|\)|$|\s)/Au' => Tokenizer::TOKEN_TERM,
];


Expand Down

0 comments on commit db678b4

Please sign in to comment.