Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/website-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
-DSOURCEMETA_CORE_JSON:BOOL=OFF
-DSOURCEMETA_CORE_JSONL:BOOL=OFF
-DSOURCEMETA_CORE_JSONPOINTER:BOOL=OFF
-DSOURCEMETA_CORE_JSONPATH:BOOL=OFF
-DSOURCEMETA_CORE_JSONLD:BOOL=OFF
-DSOURCEMETA_CORE_YAML:BOOL=OFF
-DSOURCEMETA_CORE_JSONRPC:BOOL=OFF
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/website-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
-DSOURCEMETA_CORE_JSON:BOOL=OFF
-DSOURCEMETA_CORE_JSONL:BOOL=OFF
-DSOURCEMETA_CORE_JSONPOINTER:BOOL=OFF
-DSOURCEMETA_CORE_JSONPATH:BOOL=OFF
-DSOURCEMETA_CORE_JSONLD:BOOL=OFF
-DSOURCEMETA_CORE_YAML:BOOL=OFF
-DSOURCEMETA_CORE_JSONRPC:BOOL=OFF
Expand Down
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ option(SOURCEMETA_CORE_URI "Build the Sourcemeta Core URI library" ON)
option(SOURCEMETA_CORE_URITEMPLATE "Build the Sourcemeta Core URI Template library" ON)
option(SOURCEMETA_CORE_JSON "Build the Sourcemeta Core JSON library" ON)
option(SOURCEMETA_CORE_JSONPOINTER "Build the Sourcemeta Core JSON Pointer library" ON)
option(SOURCEMETA_CORE_JSONPATH "Build the Sourcemeta Core JSON Path library" ON)
option(SOURCEMETA_CORE_JSONLD "Build the Sourcemeta Core JSON-LD library" ON)
option(SOURCEMETA_CORE_JSONL "Build the Sourcemeta Core JSONL library" ON)
option(SOURCEMETA_CORE_YAML "Build the Sourcemeta Core YAML library" ON)
Expand Down Expand Up @@ -183,6 +184,10 @@ if(SOURCEMETA_CORE_JSONPOINTER)
add_subdirectory(src/core/jsonpointer)
endif()

if(SOURCEMETA_CORE_JSONPATH)
add_subdirectory(src/core/jsonpath)
endif()

if(SOURCEMETA_CORE_JSONLD)
add_subdirectory(src/core/jsonld)
endif()
Expand Down Expand Up @@ -348,6 +353,10 @@ if(SOURCEMETA_CORE_TESTS)
add_subdirectory(test/jsonpointer)
endif()

if(SOURCEMETA_CORE_JSONPATH)
add_subdirectory(test/jsonpath)
endif()

if(SOURCEMETA_CORE_JSONLD)
add_subdirectory(test/jsonld)
endif()
Expand Down
10 changes: 10 additions & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ if(SOURCEMETA_CORE_JSONPOINTER)
list(APPEND BENCHMARK_SOURCES jsonpointer.cc)
endif()

if(SOURCEMETA_CORE_JSONPATH)
list(APPEND BENCHMARK_SOURCES jsonpath.cc)
endif()

if(SOURCEMETA_CORE_URITEMPLATE)
list(APPEND BENCHMARK_SOURCES uritemplate.cc)
endif()
Expand Down Expand Up @@ -57,6 +61,12 @@ if(BENCHMARK_SOURCES)
PRIVATE sourcemeta::core::jsonpointer)
endif()

if(SOURCEMETA_CORE_JSONPATH)
target_link_libraries(sourcemeta_core_benchmark
PRIVATE sourcemeta::core::jsonpath sourcemeta::core::json
sourcemeta::core::jsonpointer)
endif()

if(SOURCEMETA_CORE_URITEMPLATE)
target_link_libraries(sourcemeta_core_benchmark
PRIVATE sourcemeta::core::uritemplate)
Expand Down
69 changes: 69 additions & 0 deletions benchmark/jsonpath.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include <benchmark/benchmark.h>

#include <cassert> // assert
#include <cstddef> // std::size_t

#include <sourcemeta/core/json.h>
#include <sourcemeta/core/jsonpath.h>

static void JSONPath_Descendant_Filter_Nested(benchmark::State &state) {
const auto document{sourcemeta::core::parse_json(R"JSON({
"store": {
"departments": [
{
"name": "literature",
"shelves": [
{
"books": [
{ "category": "fiction", "title": "Sayings of the Century", "price": 8.95 },
{ "category": "fiction", "title": "Sword of Honour", "price": 12.99 },
{ "category": "reference", "title": "Moby Dick", "price": 8.99 },
{ "category": "fiction", "title": "The Lord of the Rings", "price": 22.99 }
]
},
{
"books": [
{ "category": "reference", "title": "Atlas of the World", "price": 45.5 },
{ "category": "fictional biography", "title": "The Quixote", "price": 6.15 },
{ "category": "fiction", "title": "The Aleph", "price": 9.99 },
{ "category": "poetry", "title": "Leaves of Grass", "price": 5.75 }
]
}
]
},
{
"name": "science",
"shelves": [
{
"books": [
{ "category": "fiction", "title": "Solaris", "price": 7.25 },
{ "category": "reference", "title": "Relativity", "price": 11.5 },
{ "category": "fiction", "title": "Foundation", "price": 3.99 },
{ "category": "fiction", "title": "Dune", "price": 10.0 }
]
}
],
"archive": {
"books": [
{ "category": "fiction", "title": "The Time Machine", "price": 2.5 },
{ "category": "essay", "title": "On the Motion of Bodies", "price": 4.05 }
]
}
}
]
}
})JSON")};

const sourcemeta::core::JSONPath path{
"$..books[?@.price < 10 && match(@.category, 'fic.*')]"};

for (auto _ : state) {
std::size_t count{0};
path.evaluate(document,
[&count](const auto &, const auto &) { count += 1; });
assert(count == 6);
benchmark::DoNotOptimize(count);
}
}

BENCHMARK(JSONPath_Descendant_Filter_Nested);
14 changes: 14 additions & 0 deletions config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if(NOT SOURCEMETA_CORE_COMPONENTS)
list(APPEND SOURCEMETA_CORE_COMPONENTS json)
list(APPEND SOURCEMETA_CORE_COMPONENTS jsonl)
list(APPEND SOURCEMETA_CORE_COMPONENTS jsonpointer)
list(APPEND SOURCEMETA_CORE_COMPONENTS jsonpath)
list(APPEND SOURCEMETA_CORE_COMPONENTS jsonld)
list(APPEND SOURCEMETA_CORE_COMPONENTS yaml)
list(APPEND SOURCEMETA_CORE_COMPONENTS jsonrpc)
Expand Down Expand Up @@ -145,6 +146,19 @@ foreach(component ${SOURCEMETA_CORE_COMPONENTS})
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_json.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_text.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_jsonpointer.cmake")
elseif(component STREQUAL "jsonpath")
find_dependency(PCRE2 CONFIG)
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_regex.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_ip.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_uri.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_preprocessor.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_numeric.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_io.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_unicode.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_json.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_text.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_jsonpointer.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_jsonpath.cmake")
elseif(component STREQUAL "jsonld")
find_dependency(PCRE2 CONFIG)
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_preprocessor.cmake")
Expand Down
20 changes: 20 additions & 0 deletions src/core/jsonpath/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME jsonpath
PRIVATE_HEADERS error.h
SOURCES jsonpath.cc parser.h)

if(SOURCEMETA_CORE_INSTALL)
sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME jsonpath)
endif()

target_link_libraries(sourcemeta_core_jsonpath PUBLIC
sourcemeta::core::json)
target_link_libraries(sourcemeta_core_jsonpath PUBLIC
sourcemeta::core::jsonpointer)
target_link_libraries(sourcemeta_core_jsonpath PUBLIC
sourcemeta::core::regex)
target_link_libraries(sourcemeta_core_jsonpath PRIVATE
sourcemeta::core::numeric)
target_link_libraries(sourcemeta_core_jsonpath PRIVATE
sourcemeta::core::text)
target_link_libraries(sourcemeta_core_jsonpath PRIVATE
sourcemeta::core::unicode)
Loading
Loading