From 297cfb4857836295f25cdb783d6b6afe78d7e017 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Thu, 28 Jan 2021 06:34:44 +0300 Subject: [PATCH] Less parser depth --- src/Parsers/ParserDataType.cpp | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/Parsers/ParserDataType.cpp b/src/Parsers/ParserDataType.cpp index 0148f2f3bb9..3d3f393a300 100644 --- a/src/Parsers/ParserDataType.cpp +++ b/src/Parsers/ParserDataType.cpp @@ -14,21 +14,29 @@ namespace { /// Wrapper to allow mixed lists of nested and normal types. -class ParserNestedTableOrExpression : public IParserBase +/// Parameters are either: +/// - Nested table elements; +/// - Enum element in form of 'a' = 1; +/// - literal; +/// - another data type (or identifier) +class ParserDataTypeArgument : public IParserBase { - private: - const char * getName() const override { return "data type or expression"; } - bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override - { - ParserNestedTable parser1; +private: + const char * getName() const override { return "data type argument"; } + bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override + { + ParserNestedTable nested_parser; + ParserDataType data_type_parser; + ParserLiteral literal_parser; - if (parser1.parse(pos, node, expected)) - return true; + const char * operators[] = {"=", "equals", nullptr}; + ParserLeftAssociativeBinaryOperatorList enum_parser(operators, std::make_unique()); - ParserExpression parser2; - - return parser2.parse(pos, node, expected); - } + return nested_parser.parse(pos, node, expected) + || enum_parser.parse(pos, node, expected) + || literal_parser.parse(pos, node, expected) + || data_type_parser.parse(pos, node, expected); + } }; } @@ -104,7 +112,7 @@ bool ParserDataType::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) ++pos; /// Parse optional parameters - ParserList args_parser(std::make_unique(), std::make_unique(TokenType::Comma)); + ParserList args_parser(std::make_unique(), std::make_unique(TokenType::Comma)); ASTPtr expr_list_args; if (!args_parser.parse(pos, expr_list_args, expected))