dbms: development.

This commit is contained in:
Alexey Milovidov 2010-06-24 19:37:23 +00:00
parent 8fc01e90d7
commit e5d9895b57
5 changed files with 41 additions and 31 deletions

View File

@ -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<ssize_t>(s.size()) < end - pos || std::strncmp(pos, s.data(), s.size()))
if (static_cast<ssize_t>(s.size()) > end - pos || std::strncmp(pos, s.data(), s.size()))
return false;
else
{

View File

@ -24,7 +24,7 @@ typedef std::map<String, String> 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)
{

View File

@ -7,6 +7,7 @@
#include <DB/Core/Types.h>
#include <DB/Parsers/IParser.h>
#include <iostream>
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;

View File

@ -26,7 +26,7 @@ protected:
ParserString s("SELECT");
ParserNotWordCharOrEnd nw;
ParserNotEmptyExpressionList exp_list;
ws.ignore(pos, end);
if (!(s.ignore(pos, end, expected)

View File

@ -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;
}