diff --git a/CMakeLists.txt b/CMakeLists.txt index aa6af8f6..a41e31e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,6 @@ endif() ############################################################################### -RAGEL_TARGET(json-flat json/flat.cpp.rl ${CMAKE_CURRENT_BINARY_DIR}/json/flat.cpp COMPILE_FLAGS -G2) RAGEL_TARGET(uri uri.cpp.rl ${CMAKE_CURRENT_BINARY_DIR}/uri.cpp COMPILE_FLAGS -G2) RAGEL_TARGET(version version.cpp.rl ${CMAKE_CURRENT_BINARY_DIR}/version.cpp) RAGEL_TARGET(format.cpp format.cpp.rl ${CMAKE_CURRENT_BINARY_DIR}/format.cpp) @@ -291,46 +290,6 @@ list ( job/dispatch.hpp job/queue.cpp job/queue.hpp - json/fwd.hpp - json/except.cpp - json/except.hpp - ${CMAKE_CURRENT_BINARY_DIR}/json/flat.cpp - json/flat.hpp - json/pointer.cpp - json/pointer.hpp - json/schema.cpp - json/schema.hpp - json/constraint/fwd.hpp - json/constraint/base.cpp - json/constraint/base.hpp - json/constraint/combine.cpp - json/constraint/combine.hpp - json/constraint/enum.cpp - json/constraint/enum.hpp - json/constraint/except.hpp - json/constraint/introspection.hpp - json/constraint/length.cpp - json/constraint/length.hpp - json/constraint/inequality.cpp - json/constraint/inequality.hpp - json/constraint/properties.cpp - json/constraint/properties.hpp - json/constraint/type.cpp - json/constraint/type.hpp - json/tree.cpp - json/tree.hpp - json2/fwd.hpp - json2/event.hpp - json2/event.cpp - json2/except.hpp - json2/personality/base.cpp - json2/personality/base.hpp - json2/personality/jsonish.cpp - json2/personality/jsonish.hpp - json2/personality/rfc7519.cpp - json2/personality/rfc7519.hpp - json2/tree.cpp - json2/tree.hpp kmeans.hpp library.hpp log.cpp @@ -481,7 +440,7 @@ target_link_libraries(cruft-util dl) ############################################################################### -foreach (tool cpuid json-clean json-schema json-validate json-compare json-pointer poisson macro scratch) +foreach (tool cpuid poisson macro scratch) add_executable (util_${tool} tools/${tool}.cpp) set_target_properties (util_${tool} PROPERTIES OUTPUT_NAME ${tool}) target_link_libraries (util_${tool} cruft-util) @@ -542,8 +501,6 @@ if (TESTS) introspection iterator job/queue - json_types - json2/event kmeans maths maths/fast @@ -596,18 +553,6 @@ if (TESTS) set_tests_properties(util_${name} PROPERTIES FAIL_REGULAR_EXPRESSION "not ok -") endforeach(t) - foreach (jtest compare schema pointer) - configure_file ("test/json/${jtest}.py.in" "util_test_json_${jtest}.py" @ONLY) - add_test(NAME "util_test_json_${jtest}" COMMAND "util_test_json_${jtest}.py") - set_property(TEST "util_test_json_${jtest}" APPEND PROPERTY DEPENDS "util_json-${jtest}") - set_tests_properties(util_test_json_${jtest} PROPERTIES FAIL_REGULAR_EXPRESSION "not ok -") - endforeach() - - configure_file (test/json-parse.sh.in util_test_json_parse.sh @ONLY) - add_test(NAME util_test_json_parse COMMAND util_test_json_parse.sh) - set_property(TEST util_test_json_parse APPEND PROPERTY DEPENDS util_json-validate) - set_tests_properties(util_test_json_parse PROPERTIES FAIL_REGULAR_EXPRESSION "not ok -") - configure_file (test/cpp.sh.in util_test_cpp.sh @ONLY) add_test (NAME util_test_cpp COMMAND util_test_cpp.sh) set_property (TEST util_test_cpp APPEND PROPERTY DEPENDS util_macro) diff --git a/json/constraint/base.cpp b/json/constraint/base.cpp deleted file mode 100644 index dc6d61a7..00000000 --- a/json/constraint/base.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2018 Danny Robson - */ - -#include "base.hpp" - -#include "type.hpp" -#include "length.hpp" -#include "inequality.hpp" -#include "properties.hpp" -#include "enum.hpp" - -using util::json::schema::constraint::base; - - -/////////////////////////////////////////////////////////////////////////////// -std::unique_ptr -base::instantiate (std::string const &name, ::json::tree::node const &def) -{ - if (name == "type") return std::make_unique (def); - if (name == "minLength") return std::make_unique (def); - if (name == "maxLength") return std::make_unique (def); - if (name == "minimum") return std::make_unique (def); - if (name == "exclusiveMaximum") return std::make_unique (def); - if (name == "exclusiveMinimum") return std::make_unique (def); - if (name == "multipleOf") return std::make_unique (def); - if (name == "maximum") return std::make_unique (def); - if (name == "properties") return std::make_unique (def); - if (name == "patternProperties") return std::make_unique (def); - if (name == "additionalProperties") return std::make_unique (def); - if (name == "enum") return std::make_unique (def); - - throw unknown_constraint (name); -} diff --git a/json/constraint/base.hpp b/json/constraint/base.hpp deleted file mode 100644 index 5d2c0e59..00000000 --- a/json/constraint/base.hpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2018 Danny Robson - */ - -#pragma once - -#include "except.hpp" - -#include -#include -#include - - -namespace util::json::schema::constraint { - struct failure { - constraint::base const &rule; - ::json::tree::node const ⌖ - }; - - - class base { - public: - using output_container = std::vector; - using output_iterator = std::back_insert_iterator; - - base () = default; - base (base &&) = default; - base& operator= (base &&) = default; - base (base const&) = delete; - base& operator= (base const&) = delete; - virtual ~base () = default; - - virtual output_iterator validate (output_iterator res, ::json::tree::node &) const noexcept = 0; - virtual std::ostream& describe (std::ostream&) const = 0; - - static std::unique_ptr instantiate (std::string const &name, ::json::tree::node const&); - }; - - - inline std::ostream& - operator<< (std::ostream &os, base const &obj) - { - return obj.describe (os); - } -} diff --git a/json/constraint/combine.cpp b/json/constraint/combine.cpp deleted file mode 100644 index 9cb27ee7..00000000 --- a/json/constraint/combine.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2018 Danny Robson - */ - -#include "combine.hpp" - -#include "properties.hpp" - -#include "../tree.hpp" - -#include "../../iterator.hpp" -#include "../../cast.hpp" - -using util::json::schema::constraint::combine; - - -/////////////////////////////////////////////////////////////////////////////// -combine::combine (::json::tree::node const &def) -{ - for (auto const &[key,val]: def.as_object ()) { - if (key == "$schema") { - m_version = val->as_string (); - continue; - } - - if (key == "default") { - m_default = val->clone (); - continue; - } - - m_constraints.push_back (instantiate (key, *val)); - - if (key == "additionalProperties") { - m_additional = util::cast::known (m_constraints.back ().get ()); - m_additional->use (m_properties); - m_additional->use (m_patterns); - } else if (key == "properties") { - m_properties = util::cast::known (m_constraints.back().get ()); - if (m_additional) - m_additional->use (m_properties); - } else if (key == "patternProperties") { - m_patterns = util::cast::known (m_constraints.back ().get ()); - if (m_additional) - m_additional->use (m_patterns); - } - } -} - - -/////////////////////////////////////////////////////////////////////////////// -combine::output_iterator -combine::validate (output_iterator res, ::json::tree::node &data) const noexcept -{ - for (auto const &i: m_constraints) - res = i->validate (res, data); - return res; -} - - -/////////////////////////////////////////////////////////////////////////////// -std::ostream& -combine::describe (std::ostream &os) const -{ - return os << "{ combine: [ "; - for (auto const &i: m_constraints) - os << *i << ", "; - return os << " ] }"; -} - - -/////////////////////////////////////////////////////////////////////////////// -bool -combine::has_default (void) const -{ - return !!m_default; -} - -//----------------------------------------------------------------------------- -std::unique_ptr<::json::tree::node> -combine::default_value (void) const -{ - return m_default->clone (); -} diff --git a/json/constraint/combine.hpp b/json/constraint/combine.hpp deleted file mode 100644 index e192d190..00000000 --- a/json/constraint/combine.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2018 Danny Robson - */ - -#pragma once - -#include "base.hpp" - -#include "fwd.hpp" -#include "../tree.hpp" - -#include -#include - - -/////////////////////////////////////////////////////////////////////////////// -namespace util::json::schema::constraint { - class combine final : public base { - public: - combine (::json::tree::node const &def); - - combine (combine const&) = delete; - combine& operator= (combine const&) = delete; - - combine (combine &&) = default; - combine& operator= (combine &&) = default; - - virtual ~combine () = default; - - output_iterator validate (output_iterator res, ::json::tree::node &) const noexcept override; - std::ostream& describe (std::ostream&) const override; - - bool has_default (void) const; - std::unique_ptr<::json::tree::node> default_value (void) const; - - private: - std::string m_version; - std::unique_ptr<::json::tree::node> m_default; - - properties *m_properties = nullptr; - pattern_properties *m_patterns = nullptr; - additional_properties *m_additional = nullptr; - - std::vector> m_constraints; - }; -} \ No newline at end of file diff --git a/json/constraint/enum.cpp b/json/constraint/enum.cpp deleted file mode 100644 index 22a1b896..00000000 --- a/json/constraint/enum.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "enum.hpp" - -#include "../tree.hpp" - -using util::json::schema::constraint::enumeration; - - -/////////////////////////////////////////////////////////////////////////////// -enumeration::enumeration (::json::tree::node const &def) -{ - for (auto const &i: def.as_array ()) - m_values.push_back (i.clone ()); -} - - -/////////////////////////////////////////////////////////////////////////////// -enumeration::output_iterator -enumeration::validate (util::json::schema::constraint::base::output_iterator res, - ::json::tree::node &target) const noexcept -{ - for (auto const &i: m_values) - if (target == *i) - return res; - - return *res++ = { .rule = *this, .target = target }; -} - - -/////////////////////////////////////////////////////////////////////////////// -std::ostream& -enumeration::describe (std::ostream &os) const -{ - os << "{ enumeration: [ "; - - for (auto const &i: m_values) - os << *i << ", "; - - return os << " ] }"; -} diff --git a/json/constraint/enum.hpp b/json/constraint/enum.hpp deleted file mode 100644 index 98794db5..00000000 --- a/json/constraint/enum.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2018 Danny Robson - */ - -#pragma once - -#include "base.hpp" - -#include "../fwd.hpp" - -#include - -namespace util::json::schema::constraint { - class enumeration final : public base { - public: - enumeration (::json::tree::node const &def); - - virtual ~enumeration () = default; - - output_iterator validate (output_iterator res, ::json::tree::node &) const noexcept override; - std::ostream& describe (std::ostream&) const override; - - private: - std::vector> m_values; - }; -} \ No newline at end of file diff --git a/json/constraint/except.hpp b/json/constraint/except.hpp deleted file mode 100644 index 8fa23c45..00000000 --- a/json/constraint/except.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2018 Danny Robson - */ - -#pragma once - -#include "fwd.hpp" -#include "introspection.hpp" -#include "../fwd.hpp" - -#include - - -/////////////////////////////////////////////////////////////////////////////// -namespace util::json::schema { - class error : public std::exception { }; - - - template - class constraint_error : public error { - public: - virtual ~constraint_error () = default; - constraint_error (::json::tree::node const &_def): - def (_def) - { ; } - - char const* what (void) const noexcept override - { - return util::type_name_v; - } - - ::json::tree::node const &def; - }; - - - class unknown_constraint : public error { - public: - unknown_constraint (std::string const &name): - m_name (name) - { ; } - - virtual ~unknown_constraint () = default; - - char const* what (void) const noexcept override - { - return m_name.c_str (); - } - - private: - std::string m_name; - }; -} diff --git a/json/constraint/fwd.hpp b/json/constraint/fwd.hpp deleted file mode 100644 index 3a082073..00000000 --- a/json/constraint/fwd.hpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2018 Danny Robson - */ - -#pragma once - - -namespace util::json::schema::constraint { - struct failure; - - class base; - - class type; - class combine; - template class length; - template