1
0
Fork 0
mirror of https://github.com/dragonflydb/dragonfly.git synced 2024-12-15 17:51:06 +00:00

chore: parse a simple jsonpath (#2566)

Also, add an ubuntu-20 reusable devcontainer.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2024-02-09 15:41:22 +02:00 committed by GitHub
parent c2ee348d2c
commit 06d88ddc88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 73 additions and 10 deletions

View file

@ -1,5 +1,5 @@
{ {
"name": "helio", "name": "fedora30",
"image": "ghcr.io/romange/fedora:30", "image": "ghcr.io/romange/fedora:30",
"customizations": { "customizations": {
"vscode": { "vscode": {

View file

@ -0,0 +1,10 @@
[
{
"name": "GCC x86_64-linux-gnu",
"compilers": {
"C": "gcc",
"CXX": "g++"
},
"isTrusted": true
}
]

View file

@ -0,0 +1,21 @@
{
"name": "ubuntu20",
"image": "ghcr.io/romange/ubuntu-dev:20",
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cpptools",
"ms-vscode.cmake-tools",
"ms-vscode.cpptools-themes",
"twxs.cmake"
],
"settings": {
"cmake.buildDirectory": "/build"
}
}
},
"mounts": [
"source=ubuntu20-vol,target=/build,type=volume"
],
"postCreateCommand": ".devcontainer/ubuntu20/post-create.sh ${containerWorkspaceFolder}"
}

View file

@ -0,0 +1,6 @@
#!/bin/bash
containerWorkspaceFolder=$1
git config --global --add safe.directory ${containerWorkspaceFolder}/helio
mkdir -p /root/.local/share/CMakeTools
cp ${containerWorkspaceFolder}/.devcontainer/ubuntu20/cmake-tools-kits.json /root/.local/share/CMakeTools/

View file

@ -45,12 +45,15 @@ using namespace std;
%token %token
LBRACKET "[" LBRACKET "["
RBRACKET "]"
ROOT "$" ROOT "$"
DOT "." DOT "."
WILDCARD "*"
// Needed 0 at the end to satisfy bison 3.5.1 // Needed 0 at the end to satisfy bison 3.5.1
%token YYEOF 0 %token YYEOF 0
%token <std::string> UNQ_STR "unq_str" %token <std::string> UNQ_STR "unquoted string"
%token <unsigned> UINT "integer"
%% %%
// Based on the following specification: // Based on the following specification:
@ -60,14 +63,21 @@ jsonpath: ROOT
| ROOT relative_location | ROOT relative_location
relative_location: DOT relative_path relative_location: DOT relative_path
| LBRACKET bracket_expr RBRACKET
relative_path: identifier relative_path: identifier opt_relative_location
| identifier relative_location | WILDCARD opt_relative_location
identifier: unquoted_string opt_relative_location:
| relative_location
identifier: UNQ_STR
// | single_quoted_string | double_quoted_string // | single_quoted_string | double_quoted_string
unquoted_string : UNQ_STR bracket_expr: WILDCARD
| index_expr
index_expr: UINT
%% %%

View file

@ -5,7 +5,8 @@
%{ %{
// SECOND SECTION #include <absl/strings/numbers.h>
#include "base/logging.h"
%} %}
%o bison-cc-namespace="dfly.json" bison-cc-parser="Parser" %o bison-cc-namespace="dfly.json" bison-cc-parser="Parser"
@ -41,6 +42,14 @@
"$" return Parser::make_ROOT(loc()); "$" return Parser::make_ROOT(loc());
"." return Parser::make_DOT(loc()); "." return Parser::make_DOT(loc());
"[" return Parser::make_LBRACKET(loc());
"]" return Parser::make_RBRACKET(loc());
"*" return Parser::make_WILDCARD(loc());
[0-9]{1,9} {
unsigned val;
CHECK(absl::SimpleAtoi(str(), &val));
return Parser::make_UINT(val, loc());
}
\w[\w_\-]* return Parser::make_UNQ_STR(str(), loc()); \w[\w_\-]* return Parser::make_UNQ_STR(str(), loc());
<<EOF>> printf("EOF%s\n", matcher().text()); <<EOF>> printf("EOF%s\n", matcher().text());
%% %%

View file

@ -31,21 +31,28 @@ class JsonPathTest : public ::testing::Test {
#define NEXT_TOK(tok_enum) \ #define NEXT_TOK(tok_enum) \
{ \ { \
auto tok = Lex(); \ auto tok = Lex(); \
ASSERT_EQ(tok.type_get(), Parser::token::TOK_##tok_enum); \ ASSERT_EQ(Parser::token::TOK_##tok_enum, tok.type_get()); \
} }
#define NEXT_EQ(tok_enum, type, val) \ #define NEXT_EQ(tok_enum, type, val) \
{ \ { \
auto tok = Lex(); \ auto tok = Lex(); \
ASSERT_EQ(tok.type_get(), Parser::token::TOK_##tok_enum); \ ASSERT_EQ(Parser::token::TOK_##tok_enum, tok.type_get()); \
EXPECT_EQ(val, tok.value.as<type>()); \ EXPECT_EQ(val, tok.value.as<type>()); \
} }
TEST_F(JsonPathTest, Scanner) { TEST_F(JsonPathTest, Scanner) {
SetInput("$.мага-зин2.book[0].title"); SetInput("$.мага-зин2.book[0].*");
NEXT_TOK(ROOT); NEXT_TOK(ROOT);
NEXT_TOK(DOT); NEXT_TOK(DOT);
NEXT_EQ(UNQ_STR, string, "мага-зин2"); NEXT_EQ(UNQ_STR, string, "мага-зин2");
NEXT_TOK(DOT);
NEXT_EQ(UNQ_STR, string, "book");
NEXT_TOK(LBRACKET);
NEXT_EQ(UINT, unsigned, 0);
NEXT_TOK(RBRACKET);
NEXT_TOK(DOT);
NEXT_TOK(WILDCARD);
} }
} // namespace dfly::json } // namespace dfly::json