Better parser

This commit is contained in:
Amos Bird 2019-10-31 23:22:48 +08:00
parent 0d2a2c332f
commit 4aff9a20c6
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
6 changed files with 32 additions and 16 deletions

View File

@ -81,6 +81,13 @@ bool ParserParenthesisExpression::parseImpl(Pos & pos, ASTPtr & node, Expected &
if (!contents.parse(pos, contents_node, expected))
return false;
bool is_elem = true;
if (pos->type == TokenType::Comma)
{
is_elem = false;
++pos;
}
if (pos->type != TokenType::ClosingRoundBracket)
return false;
++pos;
@ -94,7 +101,7 @@ bool ParserParenthesisExpression::parseImpl(Pos & pos, ASTPtr & node, Expected &
return false;
}
if (expr_list.children.size() == 1)
if (expr_list.children.size() == 1 && is_elem)
{
node = expr_list.children.front();
}

View File

@ -275,8 +275,7 @@ class ParserWithOptionalAlias : public IParserBase
{
public:
ParserWithOptionalAlias(ParserPtr && elem_parser_, bool allow_alias_without_as_keyword_)
: elem_parser(std::move(elem_parser_)), allow_alias_without_as_keyword(allow_alias_without_as_keyword_)
{}
: elem_parser(std::move(elem_parser_)), allow_alias_without_as_keyword(allow_alias_without_as_keyword_) {}
protected:
ParserPtr elem_parser;
bool allow_alias_without_as_keyword;

View File

@ -560,7 +560,7 @@ bool ParserOrderByExpressionList::parseImpl(Pos & pos, ASTPtr & node, Expected &
bool ParserNullityChecking::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
ASTPtr node_comp;
if (!ParserComparisonExpression{}.parse(pos, node_comp, expected))
if (!elem_parser.parse(pos, node_comp, expected))
return false;
ParserKeyword s_is{"IS"};

View File

@ -115,18 +115,6 @@ protected:
};
class ParserTupleElementExpression : public IParserBase
{
private:
static const char * operators[];
protected:
const char * getName() const { return "tuple element expression"; }
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected);
};
class ParserArrayElementExpression : public IParserBase
{
private:
@ -139,6 +127,18 @@ protected:
};
class ParserTupleElementExpression : public IParserBase
{
private:
static const char * operators[];
protected:
const char * getName() const { return "tuple element expression"; }
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected);
};
class ParserUnaryMinusExpression : public IParserBase
{
private:
@ -241,6 +241,9 @@ protected:
*/
class ParserNullityChecking : public IParserBase
{
private:
ParserComparisonExpression elem_parser;
protected:
const char * getName() const override { return "nullity checking"; }
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;

View File

@ -0,0 +1,2 @@
Tuple(UInt8) (1)
SELECT tuple(1)

View File

@ -0,0 +1,5 @@
SELECT toTypeName((1,)), (1,);
SET enable_debug_queries = 1;
ANALYZE SELECT (1,)