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 class ParserString : public IParserBase
{ {
private: private:
const String & s; String s;
public: public:
ParserString(const String & s_) : s(s_) {} ParserString(const String & s_) : s(s_) {}
protected: protected:
@ -25,7 +25,7 @@ protected:
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, String & expected) 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; return false;
else else
{ {

View File

@ -24,7 +24,7 @@ typedef std::map<String, String> Operators_t;
class ParserLeftAssociativeBinaryOperatorList : public IParserBase class ParserLeftAssociativeBinaryOperatorList : public IParserBase
{ {
private: private:
const Operators_t & operators; Operators_t operators;
ParserPtr elem_parser; ParserPtr elem_parser;
public: public:
@ -50,7 +50,7 @@ protected:
class ParserPrefixUnaryOperatorExpression : public IParserBase class ParserPrefixUnaryOperatorExpression : public IParserBase
{ {
private: private:
const Operators_t & operators; Operators_t operators;
ParserPtr elem_parser; ParserPtr elem_parser;
public: public:
@ -76,7 +76,7 @@ public:
ParserAccessExpression(); ParserAccessExpression();
protected: protected:
String getName() { return "acess expression"; } String getName() { return "access expression"; }
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, String & expected) bool parseImpl(Pos & pos, Pos end, ASTPtr & node, String & expected)
{ {

View File

@ -7,6 +7,7 @@
#include <DB/Core/Types.h> #include <DB/Core/Types.h>
#include <DB/Parsers/IParser.h> #include <DB/Parsers/IParser.h>
#include <iostream>
namespace DB namespace DB
{ {
@ -19,7 +20,16 @@ public:
bool parse(Pos & pos, Pos end, ASTPtr & node, String & expected) bool parse(Pos & pos, Pos end, ASTPtr & node, String & expected)
{ {
expected = getName(); 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: protected:
virtual bool parseImpl(Pos & pos, Pos end, ASTPtr & node, String & expected) = 0; virtual bool parseImpl(Pos & pos, Pos end, ASTPtr & node, String & expected) = 0;

View File

@ -95,8 +95,6 @@ bool ParserPrefixUnaryOperatorExpression::parseImpl(Pos & pos, Pos end, ASTPtr &
{ {
ParserWhiteSpaceOrComments ws; ParserWhiteSpaceOrComments ws;
ws.ignore(pos, end);
/// пробуем найти какой-нибудь из допустимых операторов /// пробуем найти какой-нибудь из допустимых операторов
Pos begin = pos; Pos begin = pos;
Operators_t::const_iterator it; Operators_t::const_iterator it;
@ -107,9 +105,14 @@ bool ParserPrefixUnaryOperatorExpression::parseImpl(Pos & pos, Pos end, ASTPtr &
break; break;
} }
if (it == operators.end()) ASTPtr elem;
if (!elem_parser->parse(pos, end, elem, expected))
return false; return false;
if (it == operators.end())
node = elem;
else
{
ws.ignore(pos, end); ws.ignore(pos, end);
/// функция, соответствующая оператору /// функция, соответствующая оператору
@ -122,10 +125,6 @@ bool ParserPrefixUnaryOperatorExpression::parseImpl(Pos & pos, Pos end, ASTPtr &
ASTExpressionList & exp_list = *p_exp_list; ASTExpressionList & exp_list = *p_exp_list;
ASTPtr exp_list_node = 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.first = begin;
function.range.second = pos; function.range.second = pos;
function.name = it->second; function.name = it->second;
@ -135,6 +134,7 @@ bool ParserPrefixUnaryOperatorExpression::parseImpl(Pos & pos, Pos end, ASTPtr &
exp_list.range.second = pos; exp_list.range.second = pos;
node = function_node; node = function_node;
}
return true; return true;
} }