From e5d9895b57be67a63ab4dbeae992eab948c69252 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Thu, 24 Jun 2010 19:37:23 +0000 Subject: [PATCH] dbms: development. --- dbms/include/DB/Parsers/CommonParsers.h | 4 +- .../DB/Parsers/ExpressionListParsers.h | 6 +-- dbms/include/DB/Parsers/IParserBase.h | 12 ++++- dbms/include/DB/Parsers/ParserSelectQuery.h | 2 +- dbms/src/Parsers/ExpressionListParsers.cpp | 48 +++++++++---------- 5 files changed, 41 insertions(+), 31 deletions(-) diff --git a/dbms/include/DB/Parsers/CommonParsers.h b/dbms/include/DB/Parsers/CommonParsers.h index 98f6c777168..fe5383620a8 100644 --- a/dbms/include/DB/Parsers/CommonParsers.h +++ b/dbms/include/DB/Parsers/CommonParsers.h @@ -17,7 +17,7 @@ using Poco::SharedPtr; class ParserString : public IParserBase { private: - const String & s; + String s; public: ParserString(const String & s_) : s(s_) {} protected: @@ -25,7 +25,7 @@ protected: bool parseImpl(Pos & pos, Pos end, ASTPtr & node, String & expected) { - if (static_cast(s.size()) < end - pos || std::strncmp(pos, s.data(), s.size())) + if (static_cast(s.size()) > end - pos || std::strncmp(pos, s.data(), s.size())) return false; else { diff --git a/dbms/include/DB/Parsers/ExpressionListParsers.h b/dbms/include/DB/Parsers/ExpressionListParsers.h index 93cd2bc39cc..e8d02a76831 100644 --- a/dbms/include/DB/Parsers/ExpressionListParsers.h +++ b/dbms/include/DB/Parsers/ExpressionListParsers.h @@ -24,7 +24,7 @@ typedef std::map Operators_t; class ParserLeftAssociativeBinaryOperatorList : public IParserBase { private: - const Operators_t & operators; + Operators_t operators; ParserPtr elem_parser; public: @@ -50,7 +50,7 @@ protected: class ParserPrefixUnaryOperatorExpression : public IParserBase { private: - const Operators_t & operators; + Operators_t operators; ParserPtr elem_parser; public: @@ -76,7 +76,7 @@ public: ParserAccessExpression(); protected: - String getName() { return "acess expression"; } + String getName() { return "access expression"; } bool parseImpl(Pos & pos, Pos end, ASTPtr & node, String & expected) { diff --git a/dbms/include/DB/Parsers/IParserBase.h b/dbms/include/DB/Parsers/IParserBase.h index 8edeeec0845..4e88c3dc5f9 100644 --- a/dbms/include/DB/Parsers/IParserBase.h +++ b/dbms/include/DB/Parsers/IParserBase.h @@ -7,6 +7,7 @@ #include #include +#include namespace DB { @@ -19,7 +20,16 @@ public: bool parse(Pos & pos, Pos end, ASTPtr & node, String & expected) { expected = getName(); - return parseImpl(pos, end, node, expected); + + Pos begin = pos; + bool res = parseImpl(pos, end, node, expected); + if (res) + { + String s(begin, pos - begin); + std::cerr << getName() << ": " << s << std::endl; + } + + return res; } protected: virtual bool parseImpl(Pos & pos, Pos end, ASTPtr & node, String & expected) = 0; diff --git a/dbms/include/DB/Parsers/ParserSelectQuery.h b/dbms/include/DB/Parsers/ParserSelectQuery.h index 93b3e640ea7..9d6dbaba9f5 100644 --- a/dbms/include/DB/Parsers/ParserSelectQuery.h +++ b/dbms/include/DB/Parsers/ParserSelectQuery.h @@ -26,7 +26,7 @@ protected: ParserString s("SELECT"); ParserNotWordCharOrEnd nw; ParserNotEmptyExpressionList exp_list; - + ws.ignore(pos, end); if (!(s.ignore(pos, end, expected) diff --git a/dbms/src/Parsers/ExpressionListParsers.cpp b/dbms/src/Parsers/ExpressionListParsers.cpp index 62101554e3c..d9bc754fe58 100644 --- a/dbms/src/Parsers/ExpressionListParsers.cpp +++ b/dbms/src/Parsers/ExpressionListParsers.cpp @@ -95,8 +95,6 @@ bool ParserPrefixUnaryOperatorExpression::parseImpl(Pos & pos, Pos end, ASTPtr & { ParserWhiteSpaceOrComments ws; - ws.ignore(pos, end); - /// пробуем найти какой-нибудь из допустимых операторов Pos begin = pos; Operators_t::const_iterator it; @@ -107,34 +105,36 @@ bool ParserPrefixUnaryOperatorExpression::parseImpl(Pos & pos, Pos end, ASTPtr & break; } - if (it == operators.end()) - return false; - - ws.ignore(pos, end); - - /// функция, соответствующая оператору - ASTFunction * p_function = new ASTFunction(StringRange(pos, pos)); - ASTFunction & function = *p_function; - ASTPtr function_node = p_function; - - /// аргументы функции - ASTExpressionList * p_exp_list = new ASTExpressionList(StringRange(pos, pos)); - ASTExpressionList & exp_list = *p_exp_list; - ASTPtr exp_list_node = p_exp_list; - ASTPtr elem; if (!elem_parser->parse(pos, end, elem, expected)) return false; - function.range.first = begin; - function.range.second = pos; - function.name = it->second; - function.arguments = exp_list_node; + if (it == operators.end()) + node = elem; + else + { + ws.ignore(pos, end); - exp_list.children.push_back(elem); - exp_list.range.second = pos; + /// функция, соответствующая оператору + ASTFunction * p_function = new ASTFunction(StringRange(pos, pos)); + ASTFunction & function = *p_function; + ASTPtr function_node = p_function; - node = function_node; + /// аргументы функции + ASTExpressionList * p_exp_list = new ASTExpressionList(StringRange(pos, pos)); + ASTExpressionList & exp_list = *p_exp_list; + ASTPtr exp_list_node = p_exp_list; + + function.range.first = begin; + function.range.second = pos; + function.name = it->second; + function.arguments = exp_list_node; + + exp_list.children.push_back(elem); + exp_list.range.second = pos; + + node = function_node; + } return true; }