MiniOB
1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
src
oblsm
client
cliutil
parser.h
1
/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
2
miniob is licensed under Mulan PSL v2.
3
You can use this software according to the terms and conditions of the Mulan PSL v2.
4
You may obtain a copy of Mulan PSL v2 at:
5
http://license.coscl.org.cn/MulanPSL2
6
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9
See the Mulan PSL v2 for more details. */
10
11
//
12
// Created by Ping Xu(haibarapink@gmail.com)
13
//
14
#pragma once
15
16
#include <cstdlib>
17
#include <iostream>
18
#include <fstream>
19
#include <map>
20
#include <ctime>
21
22
#include "common/sys/rc.h"
23
#include "common/lang/string.h"
24
#include "common/lang/string_view.h"
25
#include "oblsm/client/cliutil/defs.h"
26
27
#define MAX_MEM_BUFFER_SIZE 8192
28
namespace
oceanbase {
29
30
inline
const
string
LINE_HISTORY_FILE =
"./.oblsm_cli.history"
;
31
32
enum class
TokenType
33
{
34
COMMAND,
35
STRING,
36
BOUND,
37
INVALID
38
};
39
40
class
ObLsmCliCmdTokenizer
41
{
42
public
:
43
TokenType token_type;
44
ObLsmCliCmdType cmd;
45
string
str;
46
47
ObLsmCliCmdTokenizer
()
48
{
49
#define MAP_COMMAND(cmd) token_map_[string{ObLsmCliUtil::strcmd(ObLsmCliCmdType::cmd)}] = ObLsmCliCmdType::cmd
50
MAP_COMMAND(OPEN);
51
MAP_COMMAND(CLOSE);
52
MAP_COMMAND(SET);
53
MAP_COMMAND(DELETE);
54
MAP_COMMAND(SCAN);
55
MAP_COMMAND(HELP);
56
MAP_COMMAND(EXIT);
57
MAP_COMMAND(GET);
58
#undef MAP_COMMAND
59
}
60
61
void
init(string_view command)
62
{
63
command_ = command;
64
p_ = 0;
65
}
66
67
RC next();
68
69
private
:
70
bool
out_of_range() {
return
p_ >= command_.size(); }
71
void
skip_blank_space();
72
RC parse_string(
string
&res);
73
74
std::map<string, ObLsmCliCmdType> token_map_;
75
76
string_view command_;
77
size_t
p_;
78
};
79
80
// Semantic checks
81
class
ObLsmCliCmdParser
82
{
83
public
:
84
struct
Result
85
{
86
ObLsmCliCmdType cmd;
87
string
error;
88
89
string
args[2];
90
bool
bounds[2] = {
false
,
false
};
91
};
92
Result
result;
93
RC parse(string_view command);
94
95
private
:
96
ObLsmCliCmdTokenizer
tokenizer_;
97
};
98
99
}
// namespace oceanbase
oceanbase::ObLsmCliCmdParser
Definition:
parser.h:82
oceanbase::ObLsmCliCmdTokenizer
Definition:
parser.h:41
oceanbase::ObLsmCliCmdParser::Result
Definition:
parser.h:85
制作者
1.9.5