MySQL 9.1.0
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 /**
42 * init the library that's used by the lexer.
43 *
44 * NOT thread-safe, MUST be called before threads are spawned.
45 */
46 static void init_library();
47
48 class iterator {
49 public:
50 struct Token {
51 std::string_view text;
53 };
54
58 using const_pointer = const value_type *;
59
60 iterator(THD *session);
61
62 iterator(THD *session, Token token)
63 : session_(session), token_{std::move(token)} {}
64
65 value_type operator*() const { return token_; }
66 pointer operator->() { return &token_; }
67 const_pointer operator->() const { return &token_; }
68
71
72 friend bool operator==(const iterator &a, const iterator &b);
73 friend bool operator!=(const iterator &a, const iterator &b);
74
75 private:
76 Token next_token();
77 std::string_view get_token_text(TokenId token_id) const;
78
81
83 };
84
86 iterator end() { return iterator(nullptr); }
87
88 private:
90};
91
92#endif
Definition: sql_lexer.h:48
THD * session_
Definition: sql_lexer.h:79
iterator & operator++()
Definition: sql_lexer.cc:1353
Token token_
Definition: sql_lexer.h:82
friend bool operator!=(const iterator &a, const iterator &b)
Definition: sql_lexer.cc:1399
Token next_token()
Definition: sql_lexer.cc:1328
std::string_view get_token_text(TokenId token_id) const
Definition: sql_lexer.cc:1368
friend bool operator==(const iterator &a, const iterator &b)
Definition: sql_lexer.cc:1395
value_type operator*() const
Definition: sql_lexer.h:65
const_pointer operator->() const
Definition: sql_lexer.h:67
pointer operator->()
Definition: sql_lexer.h:66
lexer_state st
Definition: sql_lexer.h:80
iterator(THD *session)
Definition: sql_lexer.cc:1290
iterator(THD *session, Token token)
Definition: sql_lexer.h:62
Definition: sql_lexer.h:35
static void init_library()
init the library that's used by the lexer.
Definition: sql_lexer.cc:1278
iterator end()
Definition: sql_lexer.h:86
THD * session_
Definition: sql_lexer.h:89
SqlLexer(THD *session)
Definition: sql_lexer.cc:1284
iterator begin()
Definition: sql_lexer.h:85
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:36
Definition: gcs_xcom_synode.h:64
Definition: sql_lexer.h:50
std::string_view text
Definition: sql_lexer.h:51
TokenId id
Definition: sql_lexer.h:52
Definition: lexer_yystype.h:33