mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-05 14:02:21 +00:00
45 lines
942 B
C++
45 lines
942 B
C++
#pragma once
|
|
|
|
#include <Parsers/IParser.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
/** Base class for most parsers
|
|
*/
|
|
class IParserBase : public IParser
|
|
{
|
|
public:
|
|
template <typename F>
|
|
ALWAYS_INLINE static bool wrapParseImpl(Pos & pos, const F & func)
|
|
{
|
|
Pos begin = pos;
|
|
bool res = func();
|
|
if (!res && !pos.no_backtrack_on_failure)
|
|
pos = begin;
|
|
return res;
|
|
}
|
|
|
|
struct IncreaseDepthTag {};
|
|
|
|
template <typename F>
|
|
ALWAYS_INLINE static bool wrapParseImpl(Pos & pos, IncreaseDepthTag, const F & func)
|
|
{
|
|
Pos begin = pos;
|
|
pos.increaseDepth();
|
|
bool res = func();
|
|
pos.decreaseDepth();
|
|
if (!res && !pos.no_backtrack_on_failure)
|
|
pos = begin;
|
|
return res;
|
|
}
|
|
|
|
bool parse(Pos & pos, ASTPtr & node, Expected & expected) override; // -V1071
|
|
|
|
protected:
|
|
virtual bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) = 0;
|
|
};
|
|
|
|
}
|