2015-04-14 02:11:59 +00:00
|
|
|
#include <DB/Parsers/IParserBase.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-01-11 21:46:36 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
extern const int LOGICAL_ERROR;
|
2016-01-11 21:46:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-14 02:11:59 +00:00
|
|
|
bool IParserBase::parse(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
Pos begin = pos;
|
|
|
|
Pos new_max_parsed_pos = pos;
|
|
|
|
Expected new_expected = getName();
|
2015-04-14 02:11:59 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
bool res = parseImpl(pos, end, node, new_max_parsed_pos, new_expected);
|
2015-04-14 02:11:59 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (pos > new_max_parsed_pos)
|
|
|
|
new_max_parsed_pos = pos;
|
2015-04-14 02:11:59 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (new_max_parsed_pos > max_parsed_pos)
|
|
|
|
max_parsed_pos = new_max_parsed_pos;
|
2015-04-14 02:11:59 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (!res && new_max_parsed_pos >= max_parsed_pos)
|
|
|
|
expected = new_expected;
|
2015-04-14 02:11:59 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (pos > end)
|
|
|
|
throw Exception("Logical error: pos > end.", ErrorCodes::LOGICAL_ERROR);
|
2015-04-14 02:11:59 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
node = nullptr;
|
|
|
|
pos = begin;
|
|
|
|
}
|
2015-04-14 02:11:59 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return res;
|
2015-04-14 02:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|