dbms: development.

This commit is contained in:
Alexey Milovidov 2010-06-25 19:55:19 +00:00
parent a3470586b9
commit ba83040cb0
6 changed files with 11 additions and 8 deletions

View File

@ -44,6 +44,7 @@ namespace ErrorCodes
CANNOT_READ_ALL_DATA, CANNOT_READ_ALL_DATA,
TOO_MUCH_ARGUMENTS_FOR_FUNCTION, TOO_MUCH_ARGUMENTS_FOR_FUNCTION,
TOO_LESS_ARGUMENTS_FOR_FUNCTION, TOO_LESS_ARGUMENTS_FOR_FUNCTION,
UNKNOWN_ELEMENT_IN_AST,
}; };
} }

View File

@ -78,7 +78,7 @@ protected:
if (end - pos >= 4 && pos[0] == '/' && pos[1] == '*') if (end - pos >= 4 && pos[0] == '/' && pos[1] == '*')
{ {
pos += 2; pos += 2;
while (end - pos >= 2 && pos[0] != '*' && pos[1] != '/') while (end - pos >= 2 && (pos[0] != '*' || pos[1] != '/'))
++pos; ++pos;
if (end - pos < 2) if (end - pos < 2)

View File

@ -26,7 +26,7 @@ public:
if (res) if (res)
{ {
String s(begin, pos - begin); String s(begin, pos - begin);
std::cerr << getName() << ": " << s << std::endl; //std::cerr << getName() << ": " << s << std::endl;
} }
return res; return res;

View File

@ -12,7 +12,6 @@
#include <DB/Parsers/ExpressionElementParsers.h> #include <DB/Parsers/ExpressionElementParsers.h>
#include <iostream>
namespace DB namespace DB
{ {
@ -63,7 +62,7 @@ bool ParserParenthesisExpression::parseImpl(Pos & pos, Pos end, ASTPtr & node, S
if (!close.ignore(pos, end, expected)) if (!close.ignore(pos, end, expected))
return false; return false;
ASTExpressionList & expr_list = dynamic_cast<ASTExpressionList &>(*node); ASTExpressionList & expr_list = dynamic_cast<ASTExpressionList &>(*contents_node);
/// пустое выражение в скобках недопустимо /// пустое выражение в скобках недопустимо
if (expr_list.children.empty()) if (expr_list.children.empty())

View File

@ -22,7 +22,7 @@ bool ParserLeftAssociativeBinaryOperatorList::parseImpl(Pos & pos, Pos end, ASTP
{ {
ASTPtr elem; ASTPtr elem;
if (!elem_parser->parse(pos, end, elem, expected)) if (!elem_parser->parse(pos, end, elem, expected))
break; return false;
node = elem; node = elem;
} }
@ -105,6 +105,8 @@ bool ParserPrefixUnaryOperatorExpression::parseImpl(Pos & pos, Pos end, ASTPtr &
break; break;
} }
ws.ignore(pos, end);
ASTPtr elem; ASTPtr elem;
if (!elem_parser->parse(pos, end, elem, expected)) if (!elem_parser->parse(pos, end, elem, expected))
return false; return false;
@ -113,8 +115,6 @@ bool ParserPrefixUnaryOperatorExpression::parseImpl(Pos & pos, Pos end, ASTPtr &
node = elem; node = elem;
else else
{ {
ws.ignore(pos, end);
/// функция, соответствующая оператору /// функция, соответствующая оператору
ASTFunction * p_function = new ASTFunction; ASTFunction * p_function = new ASTFunction;
ASTFunction & function = *p_function; ASTFunction & function = *p_function;

View File

@ -4,13 +4,14 @@
#include <DB/Parsers/ASTSelectQuery.h> #include <DB/Parsers/ASTSelectQuery.h>
#include <DB/Parsers/ParserSelectQuery.h> #include <DB/Parsers/ParserSelectQuery.h>
#include <DB/Parsers/formatAST.h>
int main(int argc, char ** argv) int main(int argc, char ** argv)
{ {
DB::ParserSelectQuery parser; DB::ParserSelectQuery parser;
DB::ASTPtr ast; 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; std::string expected;
const char * begin = input.data(); const char * begin = input.data();
@ -20,6 +21,8 @@ int main(int argc, char ** argv)
if (parser.parse(pos, end, ast, expected)) if (parser.parse(pos, end, ast, expected))
{ {
std::cout << "Success." << std::endl; std::cout << "Success." << std::endl;
DB::formatAST(*ast, std::cout);
std::cout << std::endl;
} }
else else
{ {