ClickHouse/dbms/Parsers/IParserBase.h
Ivan 97f2a2213e
Move all folders inside /dbms one level up (#9974)
* Move some code outside dbms/src folder
* Fix paths
2020-04-02 02:51:21 +03:00

45 lines
839 B
C++

#pragma once
#include <Parsers/IParser.h>
namespace DB
{
/** Base class for most parsers
*/
class IParserBase : public IParser
{
public:
template <typename F>
static bool wrapParseImpl(Pos & pos, const F & func)
{
Pos begin = pos;
bool res = func();
if (!res)
pos = begin;
return res;
}
struct IncreaseDepthTag {};
template <typename F>
static bool wrapParseImpl(Pos & pos, IncreaseDepthTag, const F & func)
{
Pos begin = pos;
pos.increaseDepth();
bool res = func();
pos.decreaseDepth();
if (!res)
pos = begin;
return res;
}
bool parse(Pos & pos, ASTPtr & node, Expected & expected) override;
protected:
virtual bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) = 0;
};
}