MySQL
8.0.39
Source Code Documentation
sql_parser.h
Go to the documentation of this file.
1
/*
2
Copyright (c) 2023, 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_PARSER_INCLUDED
27
#define ROUTING_SQL_PARSER_INCLUDED
28
29
#include <string>
30
#include <string_view>
31
32
#include "
sql/lex.h
"
33
#include "
sql_lexer.h
"
34
#include "
sql_lexer_thd.h
"
35
36
class
SqlParser
{
37
public
:
38
SqlParser
(
SqlLexer::iterator
first,
SqlLexer::iterator
last
)
39
:
cur_
{first},
end_
{
last
} {}
40
41
protected
:
42
class
TokenText
{
43
public
:
44
TokenText
() =
default
;
45
TokenText
(std::string_view txt) :
txt_
{txt} {}
46
47
operator
bool()
const
{
return
!
txt_
.empty(); }
48
49
[[nodiscard]] std::string_view
text
()
const
{
return
txt_
; }
50
51
private
:
52
std::string_view
txt_
{};
53
};
54
55
TokenText
ident
() {
56
if
(
auto
ident_tkn =
accept
(
IDENT
)) {
57
return
ident_tkn;
58
}
else
if
(
auto
ident_tkn =
accept
(
IDENT_QUOTED
)) {
59
return
ident_tkn;
60
}
else
{
61
return
{};
62
}
63
}
64
65
TokenText
accept
(
int
sym) {
66
if
(
has_error
())
return
{};
67
68
if
(
cur_
->
id
== sym) {
69
auto
txt =
cur_
->
text
;
70
++
cur_
;
71
return
txt;
72
}
73
74
return
{};
75
}
76
77
TokenText
expect
(
int
sym) {
78
if
(
has_error
())
return
{};
79
80
if
(
auto
txt =
accept
(sym)) {
81
return
txt;
82
}
83
84
error_
=
"expected sym, got ..."
;
85
86
return
{};
87
}
88
89
bool
has_error
()
const
{
return
!
error_
.empty(); }
90
91
SqlLexer::iterator
cur_
;
92
SqlLexer::iterator
end_
;
93
94
std::string
error_
{};
95
};
96
97
#endif
SqlLexer::iterator
Definition:
sql_lexer.h:41
SqlParser::TokenText
Definition:
sql_parser.h:42
SqlParser::TokenText::TokenText
TokenText()=default
SqlParser::TokenText::txt_
std::string_view txt_
Definition:
sql_parser.h:52
SqlParser::TokenText::TokenText
TokenText(std::string_view txt)
Definition:
sql_parser.h:45
SqlParser::TokenText::text
std::string_view text() const
Definition:
sql_parser.h:49
SqlParser
Definition:
sql_parser.h:36
SqlParser::cur_
SqlLexer::iterator cur_
Definition:
sql_parser.h:91
SqlParser::accept
TokenText accept(int sym)
Definition:
sql_parser.h:65
SqlParser::SqlParser
SqlParser(SqlLexer::iterator first, SqlLexer::iterator last)
Definition:
sql_parser.h:38
SqlParser::error_
std::string error_
Definition:
sql_parser.h:94
SqlParser::has_error
bool has_error() const
Definition:
sql_parser.h:89
SqlParser::ident
TokenText ident()
Definition:
sql_parser.h:55
SqlParser::end_
SqlLexer::iterator end_
Definition:
sql_parser.h:92
SqlParser::expect
TokenText expect(int sym)
Definition:
sql_parser.h:77
lex.h
sql_lexer.h
sql_lexer_thd.h
IDENT_QUOTED
@ IDENT_QUOTED
Definition:
sql_yacc.h:274
IDENT
@ IDENT
Definition:
sql_yacc.h:272
Ssl_acceptor_context_property_type::last
@ last
SqlLexer::iterator::Token::text
std::string_view text
Definition:
sql_lexer.h:44
SqlLexer::iterator::Token::id
TokenId id
Definition:
sql_lexer.h:45
router
src
routing
src
sql_parser.h
Generated by
1.9.2