ClickHouse/dbms/src/Parsers/CommonParsers.h

46 lines
991 B
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:
ParserToken(TokenType token_type) : token_type(token_type) {}
2010-06-24 19:12:10 +00:00
protected:
const char * getName() const override { return "token"; }
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override
{
if (pos->type != token_type)
return false;
++pos;
return true;
}
2010-06-24 19:12:10 +00:00
};
}