Skip to content

Commit 61de340

Browse files
authored
Merge branch 'unstable' into xpending
2 parents 0afdc36 + 03a332b commit 61de340

File tree

17 files changed

+1150
-37
lines changed

17 files changed

+1150
-37
lines changed

.github/workflows/kvrocks.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,9 @@ jobs:
440440
- name: Install cmake
441441
if: ${{ startsWith(matrix.image, 'centos') }}
442442
run: |
443-
wget https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4-linux-x86_64.sh
444-
bash cmake-3.26.4-linux-x86_64.sh --skip-license --prefix=/usr
443+
VERSION=3.26.4
444+
wget https://github.com/Kitware/CMake/releases/download/v$VERSION/cmake-$VERSION-linux-x86_64.sh
445+
bash cmake-$VERSION-linux-x86_64.sh --skip-license --prefix=/usr
445446
446447
- uses: actions/checkout@v3 #v4 use Node 20 and not working at CentOS 7
447448
- uses: actions/setup-go@v4 #v5 use Node 20 too

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ include(cmake/jsoncons.cmake)
139139
include(cmake/xxhash.cmake)
140140
include(cmake/span.cmake)
141141
include(cmake/trie.cmake)
142+
include(cmake/pegtl.cmake)
142143

143144
if (ENABLE_LUAJIT)
144145
include(cmake/luajit.cmake)
@@ -171,6 +172,7 @@ list(APPEND EXTERNAL_LIBS ${Backtrace_LIBRARY})
171172
list(APPEND EXTERNAL_LIBS xxhash)
172173
list(APPEND EXTERNAL_LIBS span-lite)
173174
list(APPEND EXTERNAL_LIBS tsl_hat_trie)
175+
list(APPEND EXTERNAL_LIBS pegtl)
174176

175177
# Add git sha to version.h
176178
find_package(Git REQUIRED)

NOTICE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ The text of each license is also included in licenses/LICENSE-[project].txt
6666
* LuaJIT(https://github.com/KvrocksLabs/LuaJIT)
6767
* lua(https://github.com/KvrocksLabs/lua, alternative to LuaJIT)
6868
* hat-trie(https://github.com/Tessil/hat-trie)
69+
* pegtl(https://github.com/taocpp/PEGTL, NOTE: changed to BSL-1.0 in main branch)
6970

7071
================================================================
7172
Boost Software License Version 1.0

cmake/pegtl.cmake

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
include_guard()
19+
20+
include(cmake/utils.cmake)
21+
22+
FetchContent_DeclareGitHubTarWithMirror(pegtl
23+
taocpp/PEGTL 3.2.7
24+
MD5=31b14660c883bc0489ddcdfbd29199c9
25+
)
26+
27+
FetchContent_MakeAvailableWithArgs(pegtl)

cmake/utils.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,10 @@ function(FetchContent_DeclareGitHubWithMirror dep repo tag hash)
5858
${hash}
5959
)
6060
endfunction()
61+
62+
function(FetchContent_DeclareGitHubTarWithMirror dep repo tag hash)
63+
FetchContent_DeclareWithMirror(${dep}
64+
https://github.com/${repo}/archive/${tag}.tar.gz
65+
${hash}
66+
)
67+
endfunction()

licenses/LICENSE-pegtl.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2007-2022 Dr. Colin Hirsch and Daniel Frey
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

src/common/string_util.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,12 @@ std::string EscapeString(std::string_view s) {
357357
case '\b':
358358
str += "\\b";
359359
break;
360+
case '\v':
361+
str += "\\v";
362+
break;
363+
case '\f':
364+
str += "\\f";
365+
break;
360366
default:
361367
if (isprint(ch)) {
362368
str += ch;

src/common/string_util.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,20 @@ std::string StringToHex(std::string_view input);
3939
std::vector<std::string> TokenizeRedisProtocol(const std::string &value);
4040
std::string EscapeString(std::string_view s);
4141

42+
template <typename T, typename F>
43+
std::string StringJoin(
44+
const T &con, F &&f = [](const auto &v) -> decltype(auto) { return v; }, const std::string &sep = ", ") {
45+
std::string res;
46+
bool is_first = true;
47+
for (const auto &v : con) {
48+
if (is_first) {
49+
is_first = false;
50+
} else {
51+
res += sep;
52+
}
53+
res += std::forward<F>(f)(v);
54+
}
55+
return res;
56+
}
57+
4258
} // namespace util

src/search/common_parser.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
*/
20+
21+
#pragma once
22+
23+
#include <tao/pegtl.hpp>
24+
25+
namespace kqir {
26+
27+
namespace peg = tao::pegtl;
28+
29+
struct True : peg::string<'t', 'r', 'u', 'e'> {};
30+
struct False : peg::string<'f', 'a', 'l', 's', 'e'> {};
31+
struct Boolean : peg::sor<True, False> {};
32+
33+
struct Digits : peg::plus<peg::digit> {};
34+
struct NumberExp : peg::seq<peg::one<'e', 'E'>, peg::opt<peg::one<'-', '+'>>, Digits> {};
35+
struct NumberFrac : peg::seq<peg::one<'.'>, Digits> {};
36+
struct Number : peg::seq<peg::opt<peg::one<'-'>>, Digits, peg::opt<NumberFrac>, peg::opt<NumberExp>> {};
37+
38+
struct UnicodeXDigit : peg::list<peg::seq<peg::one<'u'>, peg::rep<4, peg::xdigit>>, peg::one<'\\'>> {};
39+
struct EscapedSingleChar : peg::one<'"', '\\', 'b', 'f', 'n', 'r', 't'> {};
40+
struct EscapedChar : peg::sor<EscapedSingleChar, UnicodeXDigit> {};
41+
struct UnescapedChar : peg::utf8::range<0x20, 0x10FFFF> {};
42+
struct Char : peg::if_then_else<peg::one<'\\'>, EscapedChar, UnescapedChar> {};
43+
44+
struct StringContent : peg::until<peg::at<peg::one<'"'>>, Char> {};
45+
struct String : peg::seq<peg::one<'"'>, StringContent, peg::any> {};
46+
47+
struct Identifier : peg::identifier {};
48+
49+
struct WhiteSpace : peg::one<' ', '\t', '\n', '\r'> {};
50+
template <typename T>
51+
struct WSPad : peg::pad<T, WhiteSpace> {};
52+
53+
struct UnsignedInteger : Digits {};
54+
struct Integer : peg::seq<peg::opt<peg::one<'-'>>, Digits> {};
55+
56+
} // namespace kqir

src/search/common_transformer.h

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
*/
20+
21+
#pragma once
22+
23+
#include <tao/pegtl/contrib/parse_tree.hpp>
24+
#include <tao/pegtl/contrib/unescape.hpp>
25+
#include <tao/pegtl/demangle.hpp>
26+
27+
#include "common_parser.h"
28+
#include "status.h"
29+
30+
namespace kqir {
31+
32+
struct TreeTransformer {
33+
using TreeNode = std::unique_ptr<peg::parse_tree::node>;
34+
35+
template <typename T>
36+
static bool Is(const TreeNode& node) {
37+
return node->type == peg::demangle<T>();
38+
}
39+
40+
static bool IsRoot(const TreeNode& node) { return node->type.empty(); }
41+
42+
static StatusOr<std::string> UnescapeString(std::string_view str) {
43+
str = str.substr(1, str.size() - 2);
44+
45+
std::string result;
46+
while (!str.empty()) {
47+
if (str[0] == '\\') {
48+
str.remove_prefix(1);
49+
switch (str[0]) {
50+
case '\\':
51+
case '"':
52+
result.push_back(str[0]);
53+
break;
54+
case 'b':
55+
result.push_back('\b');
56+
break;
57+
case 'f':
58+
result.push_back('\f');
59+
break;
60+
case 'n':
61+
result.push_back('\n');
62+
break;
63+
case 'r':
64+
result.push_back('\r');
65+
break;
66+
case 't':
67+
result.push_back('\t');
68+
break;
69+
case 'u':
70+
if (!peg::unescape::utf8_append_utf32(
71+
result, peg::unescape::unhex_string<unsigned>(str.data() + 1, str.data() + 5))) {
72+
return {Status::NotOK,
73+
fmt::format("invalid Unicode code point '{}' in string literal", std::string(str.data() + 1, 4))};
74+
}
75+
str.remove_prefix(4);
76+
break;
77+
default:
78+
__builtin_unreachable();
79+
};
80+
str.remove_prefix(1);
81+
} else {
82+
result.push_back(str[0]);
83+
str.remove_prefix(1);
84+
}
85+
}
86+
87+
return result;
88+
}
89+
};
90+
91+
} // namespace kqir

0 commit comments

Comments
 (0)