From be704d28b9bbba63633e5570ec705fe5648d3888 Mon Sep 17 00:00:00 2001 From: Peter Pirkelbauer Date: Fri, 12 Dec 2025 10:18:21 -0800 Subject: [PATCH 1/2] Switch to jsonlogic nojson branch and update tests to new API - Change FetchContent declaration to use the jsonlogic `nojson` branch instead of the v0.1.0 tag TODO: USE PROPER TAG after merging jsonlogic/nojson - Adapt tests to the new jsonlogic API: - Pre compile rules with jsonlogic::create_logic to get logic_rule - Use logic_rule::apply with jsonlogic::json_accessor - Replace any_expr / unpack_value with truthy(any_value) - Simplify lifetime handling by avoiding manual expr ownership --- CMakeLists.txt | 3 ++- test/TestBag/remove_if.cpp | 7 ++++--- test/TestGraph/where.cpp | 19 +++++-------------- test/TestSet/remove_if.cpp | 10 +++++----- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ea7238..a9ceea0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,7 +100,8 @@ FetchContent_MakeAvailable(Boost) FetchContent_Declare(jsonlogic GIT_REPOSITORY https://github.com/LLNL/jsonlogic.git - GIT_TAG v0.1.0 + GIT_TAG nojson + # was: GIT_TAG v0.1.0 SOURCE_SUBDIR cpp ) # set(jsonlogic_INCLUDE_DIR ${jsonlogic_SOURCE_DIR}/cpp/include/jsonlogic) diff --git a/test/TestBag/remove_if.cpp b/test/TestBag/remove_if.cpp index 62b172c..87a8c52 100644 --- a/test/TestBag/remove_if.cpp +++ b/test/TestBag/remove_if.cpp @@ -32,11 +32,12 @@ int main(int argc, char **argv) { // // Expression here - auto apply_jl = [&expression](int value) { + jsonlogic::logic_rule jlrule = jsonlogic::create_logic(expression["rule"]); + + auto apply_jl = [&jlrule](int value) { boostjsn::object data; data["value"] = value; - jsonlogic::any_expr res = jsonlogic::apply(expression["rule"], data); - return jsonlogic::unpack_value(res); + return truthy(jlrule.apply(jsonlogic::json_accessor(std::move(data)))); }; the_bag.remove_if(apply_jl); diff --git a/test/TestGraph/where.cpp b/test/TestGraph/where.cpp index d42a13e..47c5034 100644 --- a/test/TestGraph/where.cpp +++ b/test/TestGraph/where.cpp @@ -19,25 +19,17 @@ auto parse_where_expression(M& mvmap_, boost::json::object& expression, // boost::json::object submission_data{}; std::vector vars; - jsonlogic::any_expr expression_rule_; // we use expression_rule_ (and expression_rule; see below) in order to avoid // having to recompute this every time we call the lambda. - std::tie(expression_rule_, vars, std::ignore) = - jsonlogic::create_logic(exp2["rule"]); - - // this works around a deficiency in C++ compilers where - // unique pointers moved into a lambda cannot be moved into - // an std::function. - jsonlogic::expr* rawexpr = expression_rule_.release(); - std::shared_ptr expression_rule{rawexpr}; + jsonlogic::logic_rule jlrule = jsonlogic::create_logic(exp2["rule"]); std::cerr << "parse_where: # of vars: " << vars.size() << std::endl; for (const auto& var : vars) { std::cerr << " apply_jl var dump: var: " << var << std::endl; } - auto apply_jl = [&expression, vars, expression_rule, &mvmap_, + auto apply_jl = [rule=std::move(jlrule), vars, &mvmap_, &submission_data](mvmap::locator loc) mutable { std::cerr << " apply_jl: # of vars: " << vars.size() << std::endl; for (const auto& var : vars) { @@ -74,10 +66,9 @@ auto parse_where_expression(M& mvmap_, boost::json::object& expression, } std::cerr << " apply_jl: submission_data: " << submission_data << std::endl; - jsonlogic::any_expr res = jsonlogic::apply( - *expression_rule, jsonlogic::data_accessor(submission_data)); + jsonlogic::any_value res = rule.apply(jsonlogic::json_accessor(submission_data)); std::cerr << " apply_jl: res: " << res << std::endl; - return jsonlogic::unpack_value(res); + return truthy(res); }; return apply_jl; @@ -146,4 +137,4 @@ std::vector where_nodes(const testgraph::testgraph& g, }); return filtered_results; -} \ No newline at end of file +} diff --git a/test/TestSet/remove_if.cpp b/test/TestSet/remove_if.cpp index 28b69ea..15122c7 100644 --- a/test/TestSet/remove_if.cpp +++ b/test/TestSet/remove_if.cpp @@ -28,13 +28,13 @@ int main(int argc, char **argv) { auto expression = clip.get("expression"); auto the_set = clip.get_state>(state_name); + // // // Expression here - auto apply_jl = [&expression](int value) { - boostjsn::object data; - data["value"] = value; - jsonlogic::any_expr res = jsonlogic::apply(expression["rule"], data); - return jsonlogic::unpack_value(res); + jsonlogic::logic_rule jlrule = jsonlogic::create_logic(expression["rule"]); + + auto apply_jl = [&jlrule](int value) { + return truthy(jlrule.apply(jsonlogic::json_accessor({{"value", value}}))); }; for (auto first = the_set.begin(), last = the_set.end(); first != last;) { From 03264e4687359e91656cef694d0449ed641cbe72 Mon Sep 17 00:00:00 2001 From: Roger Pearce Date: Mon, 15 Dec 2025 01:18:13 +0000 Subject: [PATCH 2/2] Updated to use jsonlogic v0.2.0 --- CMakeLists.txt | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9ceea0..050667b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ cmake_policy(SET CMP0135 NEW) endif() project(CLIPPy - VERSION 0.2 + VERSION 0.5 DESCRIPTION "Command Line Interface Plus Python" LANGUAGES CXX) @@ -93,26 +93,18 @@ FetchContent_MakeAvailable(Boost) # # JSONLogic -# find_package(jsonlogic QUIET) -# if (NOT jsonlogic_FOUND) -# message(STATUS "jsonlogic not found, doing stuff") - set(Boost_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/boost-install) # needed for jsonlogic - - FetchContent_Declare(jsonlogic - GIT_REPOSITORY https://github.com/LLNL/jsonlogic.git - GIT_TAG nojson - # was: GIT_TAG v0.1.0 - SOURCE_SUBDIR cpp - ) - # set(jsonlogic_INCLUDE_DIR ${jsonlogic_SOURCE_DIR}/cpp/include/jsonlogic) - FetchContent_MakeAvailable(jsonlogic) - message(STATUS "jsonlogic source dir: ${jsonlogic_SOURCE_DIR}") +set(Boost_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/boost-install) # needed for jsonlogic - -# else() -# message(STATUS "jsonlogic found, weird") +FetchContent_Declare(jsonlogic + GIT_REPOSITORY https://github.com/LLNL/jsonlogic.git + GIT_TAG v0.2.0 + SOURCE_SUBDIR cpp +) +# set(jsonlogic_INCLUDE_DIR ${jsonlogic_SOURCE_DIR}/cpp/include/jsonlogic) +FetchContent_MakeAvailable(jsonlogic) +message(STATUS "jsonlogic source dir: ${jsonlogic_SOURCE_DIR}") -# endif() + ### Require out-of-source builds file(TO_CMAKE_PATH "${PROJECT_BINARY_DIR}/CMakeLists.txt" LOC_PATH)