From ba83040cb032358d50d002359170689acc6fc61b Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Fri, 25 Jun 2010 19:55:19 +0000 Subject: [PATCH] dbms: development. --- dbms/include/DB/Core/ErrorCodes.h | 1 + dbms/include/DB/Parsers/CommonParsers.h | 2 +- dbms/include/DB/Parsers/IParserBase.h | 2 +- dbms/src/Parsers/ExpressionElementParsers.cpp | 3 +-- dbms/src/Parsers/ExpressionListParsers.cpp | 6 +++--- dbms/src/Parsers/tests/parsers.cpp | 5 ++++- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/dbms/include/DB/Core/ErrorCodes.h b/dbms/include/DB/Core/ErrorCodes.h index cc2c214401f..0896a6a9936 100644 --- a/dbms/include/DB/Core/ErrorCodes.h +++ b/dbms/include/DB/Core/ErrorCodes.h @@ -44,6 +44,7 @@ namespace ErrorCodes CANNOT_READ_ALL_DATA, TOO_MUCH_ARGUMENTS_FOR_FUNCTION, TOO_LESS_ARGUMENTS_FOR_FUNCTION, + UNKNOWN_ELEMENT_IN_AST, }; } diff --git a/dbms/include/DB/Parsers/CommonParsers.h b/dbms/include/DB/Parsers/CommonParsers.h index 09ce5013edf..b6c116b1c36 100644 --- a/dbms/include/DB/Parsers/CommonParsers.h +++ b/dbms/include/DB/Parsers/CommonParsers.h @@ -78,7 +78,7 @@ protected: if (end - pos >= 4 && pos[0] == '/' && pos[1] == '*') { pos += 2; - while (end - pos >= 2 && pos[0] != '*' && pos[1] != '/') + while (end - pos >= 2 && (pos[0] != '*' || pos[1] != '/')) ++pos; if (end - pos < 2) diff --git a/dbms/include/DB/Parsers/IParserBase.h b/dbms/include/DB/Parsers/IParserBase.h index 4e88c3dc5f9..e02feeae4b4 100644 --- a/dbms/include/DB/Parsers/IParserBase.h +++ b/dbms/include/DB/Parsers/IParserBase.h @@ -26,7 +26,7 @@ public: if (res) { String s(begin, pos - begin); - std::cerr << getName() << ": " << s << std::endl; + //std::cerr << getName() << ": " << s << std::endl; } return res; diff --git a/dbms/src/Parsers/ExpressionElementParsers.cpp b/dbms/src/Parsers/ExpressionElementParsers.cpp index c13e7d8b9fb..7cf82eebce1 100644 --- a/dbms/src/Parsers/ExpressionElementParsers.cpp +++ b/dbms/src/Parsers/ExpressionElementParsers.cpp @@ -12,7 +12,6 @@ #include -#include namespace DB { @@ -63,7 +62,7 @@ bool ParserParenthesisExpression::parseImpl(Pos & pos, Pos end, ASTPtr & node, S if (!close.ignore(pos, end, expected)) return false; - ASTExpressionList & expr_list = dynamic_cast(*node); + ASTExpressionList & expr_list = dynamic_cast(*contents_node); /// пустое выражение в скобках недопустимо if (expr_list.children.empty()) diff --git a/dbms/src/Parsers/ExpressionListParsers.cpp b/dbms/src/Parsers/ExpressionListParsers.cpp index bbc48f75fdc..a18bc63f707 100644 --- a/dbms/src/Parsers/ExpressionListParsers.cpp +++ b/dbms/src/Parsers/ExpressionListParsers.cpp @@ -22,7 +22,7 @@ bool ParserLeftAssociativeBinaryOperatorList::parseImpl(Pos & pos, Pos end, ASTP { ASTPtr elem; if (!elem_parser->parse(pos, end, elem, expected)) - break; + return false; node = elem; } @@ -105,6 +105,8 @@ bool ParserPrefixUnaryOperatorExpression::parseImpl(Pos & pos, Pos end, ASTPtr & break; } + ws.ignore(pos, end); + ASTPtr elem; if (!elem_parser->parse(pos, end, elem, expected)) return false; @@ -113,8 +115,6 @@ bool ParserPrefixUnaryOperatorExpression::parseImpl(Pos & pos, Pos end, ASTPtr & node = elem; else { - ws.ignore(pos, end); - /// функция, соответствующая оператору ASTFunction * p_function = new ASTFunction; ASTFunction & function = *p_function; diff --git a/dbms/src/Parsers/tests/parsers.cpp b/dbms/src/Parsers/tests/parsers.cpp index f5aa5947492..ebbc2e04974 100644 --- a/dbms/src/Parsers/tests/parsers.cpp +++ b/dbms/src/Parsers/tests/parsers.cpp @@ -4,13 +4,14 @@ #include #include +#include int main(int argc, char ** argv) { DB::ParserSelectQuery parser; DB::ASTPtr ast; - std::string input = "SELECT f(x), 1, 2, 3, x, NULL, 'abc\\\\def\\'\\\\''"; + std::string input = "SELECT f(1), '\\\\', [a, b, c], (a, b, c), 1 + 2 * -3, a = b OR c > d.1 + 2 * -g[0] AND NOT e < f * (x + y)"; std::string expected; const char * begin = input.data(); @@ -20,6 +21,8 @@ int main(int argc, char ** argv) if (parser.parse(pos, end, ast, expected)) { std::cout << "Success." << std::endl; + DB::formatAST(*ast, std::cout); + std::cout << std::endl; } else {