Skip to content

Commit

Permalink
parsing: Remove JSON support
Browse files Browse the repository at this point in the history
  • Loading branch information
nightly committed Aug 9, 2023
1 parent 4bb2a6f commit 07b233e
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 84 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion external/nlohmann-json
Submodule nlohmann-json deleted from bc889a
7 changes: 0 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
42 changes: 0 additions & 42 deletions src/lts/parsers/parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include <filesystem>
#include <sstream>

#include <nlohmann/json.hpp>

#include "lts/lts.h"
#include "lts/parsers/state.h"
#include "lts/parsers/transition.h"
Expand Down Expand Up @@ -67,45 +65,5 @@ namespace nightly {
}
}

template <typename StateT, typename TransitionT, typename HashF>
void ParseJson(LTS<StateT, TransitionT, HashF>& lts, const nlohmann::json& j) {
std::string initial_state_str = j["initialState"];
StateT initial_state = ParseStateString<StateT>(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<StateT>(start_state_str);
end_state = ParseStateString<StateT>(end_state_str);
label = ParseTransitionString<TransitionT>(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 <typename StateT, typename TransitionT, typename HashF>
void ReadFromJsonFile(LTS<StateT, TransitionT, HashF>& 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);
}


}
8 changes: 4 additions & 4 deletions tests/lts/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ 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);
std::ifstream s2("final_states_test.gv");
std::stringstream got_buffer;
got_buffer << s2.rdbuf();

ASSERT_EQ(got_buffer.str(), ex_buffer.str());
ASSERT_EQ(got_buffer.str(), expected_buffer.str());
}
12 changes: 0 additions & 12 deletions tests/lts/parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,5 @@ TEST(ParseLTS, LTSWithVectorTransition) {
expected.AddTransition("s0", std::vector<std::string>{"a1", "a2"}, "s1");
expected.AddTransition("s1", std::vector<std::string>{"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);
}
File renamed without changes.
15 changes: 0 additions & 15 deletions tests/lts/testdata/lts1.json

This file was deleted.

0 comments on commit 07b233e

Please sign in to comment.