ClickHouse/src/Parsers/CommonParsers.h

60 lines
1.3 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
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:
const char * s;
public:
ParserKeyword(const char * s_);
protected:
const char * getName() const override;
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
}