ClickHouse/src/Parsers/CommonParsers.h

63 lines
1.5 KiB
C++
Raw Normal View History

2011-10-31 06:37:12 +00:00
#pragma once
2010-06-24 19:12:10 +00:00
#include <Parsers/IParserBase.h>
2010-06-24 19:12:10 +00:00
#include <cassert>
2010-06-24 19:12:10 +00:00
namespace DB
{
/** Parse specified keyword such as SELECT or compound keyword such as ORDER BY.
* All case insensitive. Requires word boundary.
* For compound keywords, any whitespace characters and comments could be in the middle.
*/
/// Example: ORDER/* Hello */BY
class ParserKeyword : public IParserBase
{
private:
std::string_view s;
public:
2021-09-06 15:59:46 +00:00
//NOLINTNEXTLINE Want to be able to init ParserKeyword("literal")
constexpr ParserKeyword(std::string_view s_): s(s_) { assert(!s.empty()); }
protected:
2021-09-06 15:59:46 +00:00
constexpr const char * getName() const override { return s.data(); }
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
};
class ParserToken : public IParserBase
2010-06-24 19:12:10 +00:00
{
private:
TokenType token_type;
2011-10-31 06:37:12 +00:00
public:
2019-08-03 11:02:40 +00:00
ParserToken(TokenType token_type_) : token_type(token_type_) {}
2010-06-24 19:12:10 +00:00
protected:
const char * getName() const override { return "token"; }
2017-12-01 18:36:55 +00:00
bool parseImpl(Pos & pos, ASTPtr & /*node*/, Expected & expected) override
{
if (pos->type != token_type)
{
expected.add(pos, getTokenName(token_type));
return false;
}
++pos;
return true;
}
2010-06-24 19:12:10 +00:00
};
2019-10-07 16:23:16 +00:00
// Parser always returns true and do nothing.
class ParserNothing : public IParserBase
{
public:
const char * getName() const override { return "nothing"; }
bool parseImpl(Pos & /*pos*/, ASTPtr & /*node*/, Expected & /*expected*/) override { return true; }
};
2010-06-24 19:12:10 +00:00
}