| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | #include <Parsers/IParser.h> |
| 4 | |
| 5 | |
| 6 | namespace DB |
| 7 | { |
| 8 | |
| 9 | /** Base class for most parsers |
| 10 | */ |
| 11 | class IParserBase : public IParser |
| 12 | { |
| 13 | public: |
| 14 | template <typename F> |
| 15 | static bool wrapParseImpl(Pos & pos, const F & func) |
| 16 | { |
| 17 | Pos begin = pos; |
| 18 | bool res = func(); |
| 19 | if (!res) |
| 20 | pos = begin; |
| 21 | return res; |
| 22 | } |
| 23 | |
| 24 | struct IncreaseDepthTag {}; |
| 25 | |
| 26 | template <typename F> |
| 27 | static bool wrapParseImpl(Pos & pos, IncreaseDepthTag, const F & func) |
| 28 | { |
| 29 | Pos begin = pos; |
| 30 | pos.increaseDepth(); |
| 31 | bool res = func(); |
| 32 | pos.decreaseDepth(); |
| 33 | if (!res) |
| 34 | pos = begin; |
| 35 | return res; |
| 36 | } |
| 37 | |
| 38 | bool parse(Pos & pos, ASTPtr & node, Expected & expected); |
| 39 | |
| 40 | protected: |
| 41 | virtual bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) = 0; |
| 42 | }; |
| 43 | |
| 44 | } |
| 45 |