| 1 | #pragma once |
| 2 | |
| 3 | #include <Parsers/IParserBase.h> |
| 4 | |
| 5 | namespace DB |
| 6 | { |
| 7 | |
| 8 | /** Parse specified keyword such as SELECT or compound keyword such as ORDER BY. |
| 9 | * All case insensitive. Requires word boundary. |
| 10 | * For compound keywords, any whitespace characters and comments could be in the middle. |
| 11 | */ |
| 12 | /// Example: ORDER/* Hello */BY |
| 13 | class ParserKeyword : public IParserBase |
| 14 | { |
| 15 | private: |
| 16 | const char * s; |
| 17 | |
| 18 | public: |
| 19 | ParserKeyword(const char * s_); |
| 20 | |
| 21 | protected: |
| 22 | const char * getName() const override; |
| 23 | |
| 24 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override; |
| 25 | }; |
| 26 | |
| 27 | |
| 28 | class ParserToken : public IParserBase |
| 29 | { |
| 30 | private: |
| 31 | TokenType token_type; |
| 32 | public: |
| 33 | ParserToken(TokenType token_type_) : token_type(token_type_) {} |
| 34 | protected: |
| 35 | const char * getName() const override { return "token" ; } |
| 36 | |
| 37 | bool parseImpl(Pos & pos, ASTPtr & /*node*/, Expected & expected) override |
| 38 | { |
| 39 | if (pos->type != token_type) |
| 40 | { |
| 41 | expected.add(pos, getTokenName(token_type)); |
| 42 | return false; |
| 43 | } |
| 44 | ++pos; |
| 45 | return true; |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | |
| 50 | // Parser always returns true and do nothing. |
| 51 | class ParserNothing : public IParserBase |
| 52 | { |
| 53 | public: |
| 54 | const char * getName() const override { return "nothing" ; } |
| 55 | |
| 56 | bool parseImpl(Pos & /*pos*/, ASTPtr & /*node*/, Expected & /*expected*/) override { return true; } |
| 57 | }; |
| 58 | |
| 59 | } |
| 60 | |