MySQL 8.0.39
Source Code Documentation
sql_lexer.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2022, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTING_SQL_LEXER_INCLUDED
27#define ROUTING_SQL_LEXER_INCLUDED
28
29#include <string_view>
30
31#include "sql/lexer_yystype.h"
32
33class THD;
34
35class SqlLexer {
36 public:
37 using TokenId = int;
38
39 SqlLexer(THD *session);
40
41 class iterator {
42 public:
43 struct Token {
44 std::string_view text;
46 };
47
51 using const_pointer = const value_type *;
52
53 iterator(THD *session);
54
55 iterator(THD *session, Token token)
56 : session_(session), token_{std::move(token)} {}
57
58 value_type operator*() const { return token_; }
59 pointer operator->() { return &token_; }
60 const_pointer operator->() const { return &token_; }
61
64
65 friend bool operator==(const iterator &a, const iterator &b);
66 friend bool operator!=(const iterator &a, const iterator &b);
67
68 private:
69 Token next_token();
70 std::string_view get_token_text(TokenId token_id) const;
71
74
76 };
77
79 iterator end() { return iterator(nullptr); }
80
81 private:
83};
84
85#endif
Definition: sql_lexer.h:41
THD * session_
Definition: sql_lexer.h:72
iterator & operator++()
Definition: sql_lexer.cc:1320
Token token_
Definition: sql_lexer.h:75
friend bool operator!=(const iterator &a, const iterator &b)
Definition: sql_lexer.cc:1366
Token next_token()
Definition: sql_lexer.cc:1295
std::string_view get_token_text(TokenId token_id) const
Definition: sql_lexer.cc:1335
friend bool operator==(const iterator &a, const iterator &b)
Definition: sql_lexer.cc:1362
value_type operator*() const
Definition: sql_lexer.h:58
const_pointer operator->() const
Definition: sql_lexer.h:60
pointer operator->()
Definition: sql_lexer.h:59
lexer_state st
Definition: sql_lexer.h:73
iterator(THD *session)
Definition: sql_lexer.cc:1288
iterator(THD *session, Token token)
Definition: sql_lexer.h:55
Definition: sql_lexer.h:35
iterator end()
Definition: sql_lexer.h:79
THD * session_
Definition: sql_lexer.h:82
SqlLexer(THD *session)
Definition: sql_lexer.cc:1278
iterator begin()
Definition: sql_lexer.h:78
int TokenId
Definition: sql_lexer.h:37
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
Definition: gcs_xcom_synode.h:64
Definition: sql_lexer.h:43
std::string_view text
Definition: sql_lexer.h:44
TokenId id
Definition: sql_lexer.h:45
Definition: lexer_yystype.h:33