Stable NOT chain formatting

This commit is contained in:
Azat Khuzhin 2021-05-24 10:07:25 +03:00
parent 4b1b612cfd
commit c6339b4c08
3 changed files with 26 additions and 17 deletions

View File

@ -489,14 +489,12 @@ bool ParserPrefixUnaryOperatorExpression::parseImpl(Pos & pos, ASTPtr & node, Ex
/** This is done, because among the unary operators there is only a minus and NOT.
* But for a minus the chain of unary operators does not need to be supported.
*/
size_t count = 1;
if (it[0] && 0 == strncmp(it[0], "NOT", 3))
{
/// Was there an even number of NOTs.
bool even = false;
const char ** jt;
while (true)
{
const char ** jt;
for (jt = operators; *jt; jt += 2)
if (parseOperator(pos, *jt, expected))
break;
@ -504,11 +502,8 @@ bool ParserPrefixUnaryOperatorExpression::parseImpl(Pos & pos, ASTPtr & node, Ex
if (!*jt)
break;
even = !even;
++count;
}
if (even)
it = jt; /// Zero the result of parsing the first NOT. It turns out, as if there is no `NOT` chain at all.
}
ASTPtr elem;
@ -519,19 +514,25 @@ bool ParserPrefixUnaryOperatorExpression::parseImpl(Pos & pos, ASTPtr & node, Ex
node = elem;
else
{
/// the function corresponding to the operator
auto function = std::make_shared<ASTFunction>();
for (size_t i = 0; i < count; ++i)
{
/// the function corresponding to the operator
auto function = std::make_shared<ASTFunction>();
/// function arguments
auto exp_list = std::make_shared<ASTExpressionList>();
/// function arguments
auto exp_list = std::make_shared<ASTExpressionList>();
function->name = it[1];
function->arguments = exp_list;
function->children.push_back(exp_list);
function->name = it[1];
function->arguments = exp_list;
function->children.push_back(exp_list);
exp_list->children.push_back(elem);
if (node)
exp_list->children.push_back(node);
else
exp_list->children.push_back(elem);
node = function;
node = function;
}
}
return true;

View File

@ -0,0 +1,5 @@
-- { echo }
EXPLAIN SYNTAX SELECT NOT NOT (NOT (NOT (NULL)));
SELECT NOT (NOT (NOT NOT NULL))
EXPLAIN SYNTAX SELECT NOT (NOT (NOT NOT NULL));
SELECT NOT (NOT (NOT NOT NULL))

View File

@ -0,0 +1,3 @@
-- { echo }
EXPLAIN SYNTAX SELECT NOT NOT (NOT (NOT (NULL)));
EXPLAIN SYNTAX SELECT NOT (NOT (NOT NOT NULL));