2011-10-31 06:37:12 +00:00
|
|
|
#pragma once
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/IParserBase.h>
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2021-11-26 16:19:47 +00:00
|
|
|
#include <cassert>
|
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-06-18 03:07:03 +00:00
|
|
|
/** 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:
|
2021-09-06 14:24:03 +00:00
|
|
|
std::string_view s;
|
2017-06-18 03:07:03 +00:00
|
|
|
|
|
|
|
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()); }
|
2017-06-18 03:07:03 +00:00
|
|
|
|
|
|
|
protected:
|
2021-09-06 15:59:46 +00:00
|
|
|
constexpr const char * getName() const override { return s.data(); }
|
2017-06-18 03:07:03 +00:00
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2017-06-18 03:07:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
class ParserToken : public IParserBase
|
2010-06-24 19:12:10 +00:00
|
|
|
{
|
2017-07-10 03:28:12 +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:
|
2017-07-10 03:28:12 +00:00
|
|
|
const char * getName() const override { return "token"; }
|
2017-12-01 18:36:55 +00:00
|
|
|
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & /*node*/, Expected & expected) override
|
2017-07-10 03:28:12 +00:00
|
|
|
{
|
|
|
|
if (pos->type != token_type)
|
2017-07-13 04:20:56 +00:00
|
|
|
{
|
|
|
|
expected.add(pos, getTokenName(token_type));
|
2017-07-10 03:28:12 +00:00
|
|
|
return false;
|
2017-07-13 04:20:56 +00:00
|
|
|
}
|
2017-07-10 03:28:12 +00:00
|
|
|
++pos;
|
|
|
|
return true;
|
|
|
|
}
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
2018-12-19 10:27:07 +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
|
|
|
}
|