From 07b233e01a8aadf7be50072cbac6f1555211bb9d Mon Sep 17 00:00:00 2001 From: nightly <47933317+nightly@users.noreply.github.com> Date: Wed, 9 Aug 2023 14:15:11 +0100 Subject: [PATCH] parsing: Remove JSON support --- .gitmodules | 3 -- external/nlohmann-json | 1 - src/CMakeLists.txt | 7 ---- src/lts/parsers/parsers.h | 42 ------------------- tests/lts/export.cpp | 8 ++-- tests/lts/parsers.cpp | 12 ------ ...final_states.gv => export_final_states.gv} | 0 tests/lts/testdata/lts1.json | 15 ------- 8 files changed, 4 insertions(+), 84 deletions(-) delete mode 160000 external/nlohmann-json rename tests/lts/testdata/{export/final_states.gv => export_final_states.gv} (100%) delete mode 100644 tests/lts/testdata/lts1.json diff --git a/.gitmodules b/.gitmodules index 6a1caee..2bfc831 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "external/nlohmann-json"] - path = external/nlohmann-json - url = https://github.com/nlohmann/json [submodule "external/googletest"] path = external/googletest url = https://github.com/google/googletest diff --git a/external/nlohmann-json b/external/nlohmann-json deleted file mode 160000 index bc889af..0000000 --- a/external/nlohmann-json +++ /dev/null @@ -1 +0,0 @@ -Subproject commit bc889afb4c5bf1c0d8ee29ef35eaaf4c8bef8a5d diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index de56929..ca809da 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,11 +19,4 @@ endif() target_include_directories(lts PUBLIC ${PROJECT_SOURCE_DIR}/src -) - -add_subdirectory("${PROJECT_SOURCE_DIR}/external/nlohmann-json" "external/nlohmann-json") - -target_link_libraries(lts - PUBLIC - nlohmann_json ) \ No newline at end of file diff --git a/src/lts/parsers/parsers.h b/src/lts/parsers/parsers.h index e7562df..164705a 100644 --- a/src/lts/parsers/parsers.h +++ b/src/lts/parsers/parsers.h @@ -7,8 +7,6 @@ #include #include -#include - #include "lts/lts.h" #include "lts/parsers/state.h" #include "lts/parsers/transition.h" @@ -67,45 +65,5 @@ namespace nightly { } } - template - void ParseJson(LTS& lts, const nlohmann::json& j) { - std::string initial_state_str = j["initialState"]; - StateT initial_state = ParseStateString(initial_state_str); - lts.set_initial_state(initial_state); - - for (const auto& t : j["transitions"]) { - std::string start_state_str, label_str, end_state_str; - StateT start_state, end_state; - TransitionT label; - - start_state_str = t["startState"]; - label_str = t["label"]; - end_state_str = t["endState"]; - - start_state = ParseStateString(start_state_str); - end_state = ParseStateString(end_state_str); - label = ParseTransitionString(label_str); - - lts.AddTransition(start_state, label, end_state); - } - } - - /** - * @brief Parses a JSON file into a Labelled Transition System - * The expected form consists of: initialState as a string, and an array of transitions - * consisting of startState, label, and endState strings. - */ - template - void ReadFromJsonFile(LTS& lts, const std::filesystem::path& filepath) { - nlohmann::json j; - try { - std::ifstream stream(filepath); - stream >> j; - } catch (std::ifstream::failure& e) { - throw; - } - ParseJson(lts, j); - } - } \ No newline at end of file diff --git a/tests/lts/export.cpp b/tests/lts/export.cpp index a837fed..1b9da4d 100644 --- a/tests/lts/export.cpp +++ b/tests/lts/export.cpp @@ -21,9 +21,9 @@ TEST(LTS, FinalStates) { got.AddFinalState("s5"); got.AddTransition("s5", "a6", "s6"); - std::ifstream s1("../../tests/lts/testdata/export/final_states.gv"); - std::stringstream ex_buffer; - ex_buffer << s1.rdbuf(); + std::ifstream s1("../../tests/lts/testdata/export_final_states.gv"); + std::stringstream expected_buffer; + expected_buffer << s1.rdbuf(); nightly::Styling style; nightly::ExportToFile(got, "final_states_test.gv", style, false); @@ -31,5 +31,5 @@ TEST(LTS, FinalStates) { std::stringstream got_buffer; got_buffer << s2.rdbuf(); - ASSERT_EQ(got_buffer.str(), ex_buffer.str()); + ASSERT_EQ(got_buffer.str(), expected_buffer.str()); } diff --git a/tests/lts/parsers.cpp b/tests/lts/parsers.cpp index 59b8a7e..6d3026e 100644 --- a/tests/lts/parsers.cpp +++ b/tests/lts/parsers.cpp @@ -29,17 +29,5 @@ TEST(ParseLTS, LTSWithVectorTransition) { expected.AddTransition("s0", std::vector{"a1", "a2"}, "s1"); expected.AddTransition("s1", std::vector{"a3", "a4"}, "s2"); - ASSERT_EQ(got, expected); -} - -TEST(ParseLTS, LTS1_JSON) { - nightly::LTS got; - nightly::ReadFromJsonFile(got, "../../tests/lts/testdata/lts1.json"); - - nightly::LTS expected; - expected.set_initial_state("s0"); - expected.AddTransition("s0", "a1", "s1"); - expected.AddTransition("s1", "a2", "s2"); - ASSERT_EQ(got, expected); } \ No newline at end of file diff --git a/tests/lts/testdata/export/final_states.gv b/tests/lts/testdata/export_final_states.gv similarity index 100% rename from tests/lts/testdata/export/final_states.gv rename to tests/lts/testdata/export_final_states.gv diff --git a/tests/lts/testdata/lts1.json b/tests/lts/testdata/lts1.json deleted file mode 100644 index 32dcf44..0000000 --- a/tests/lts/testdata/lts1.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "initialState": "s0", - "transitions": [ - { - "startState": "s0", - "label": "a1", - "endState": "s1" - }, - { - "startState": "s1", - "label": "a2", - "endState": "s2" - } - ] -} \ No newline at end of file