Commit 80337e43 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#1468 TMP

parent 2abd3279
......@@ -4673,6 +4673,7 @@
BECF3E4722E99DF400FF951A /* main_update_lua_file.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main_update_lua_file.cpp; sourceTree = "<group>"; };
BECF3E4822E99E2C00FF951A /* main_update_lua_file.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = main_update_lua_file.cpp; path = RivlinCube/main_update_lua_file.cpp; sourceTree = "<group>"; };
BECF3E4C22E9B05A00FF951A /* map_in_vector.lua */ = {isa = PBXFileReference; lastKnownFileType = text; path = map_in_vector.lua; sourceTree = "<group>"; };
BECF3E4D22EA00E300FF951A /* no_section.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = no_section.lua; sourceTree = "<group>"; };
BED13351206519C700A3B0AA /* Penalization.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Penalization.hxx; sourceTree = "<group>"; };
BED13352206519C800A3B0AA /* Penalization.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Penalization.hpp; sourceTree = "<group>"; };
BED748E41906734200BAB761 /* main_test_ondomatic_numbering.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main_test_ondomatic_numbering.cpp; sourceTree = "<group>"; };
......@@ -10249,6 +10250,7 @@
BEDE16A0204EEC6600DEFE08 /* demo_lua_option_file.lua */,
BEDE16B3204FF5CE00DEFE08 /* redundancy.lua */,
BECF3E4C22E9B05A00FF951A /* map_in_vector.lua */,
BECF3E4D22EA00E300FF951A /* no_section.lua */,
BEDE169D204EEB0F00DEFE08 /* main.cpp */,
);
path = LuaOptionFile;
......@@ -55,179 +55,180 @@ PRAGMA_DIAGNOSTIC(ignored "-Wdisabled-macro-expansion")
# endif // __clang__
BOOST_FIXTURE_TEST_CASE(parameters_properly_read, TestNS::FixtureNS::Environment)
{
decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
decltype(auto) input_file =
environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/Utilities/LuaOptionFile/demo_lua_option_file.lua");
std::unique_ptr<LuaOptionFile> ptr;
/* BOOST_REQUIRE_NO_THROW */(ptr.reset(new LuaOptionFile(input_file, __FILE__, __LINE__)));
auto& lua_option_file = *(ptr.get());
BOOST_CHECK(NumericNS::AreEqual(ReadLuaOptionFile<double>(lua_option_file, "root_value", __FILE__, __LINE__),
2.44));
BOOST_CHECK(ReadLuaOptionFile<std::string>(lua_option_file, "section1.string_value", __FILE__, __LINE__) == "string");
BOOST_CHECK(NumericNS::AreEqual(ReadLuaOptionFile<double>(lua_option_file, "section1.double_value",
__FILE__, __LINE__),
5.215));
BOOST_CHECK(ReadLuaOptionFile<unsigned int>(lua_option_file, "section1.int_value", __FILE__, __LINE__) == 10u);
BOOST_CHECK_THROW(ReadLuaOptionFile<unsigned int>(lua_option_file, "section1.double_value", __FILE__, __LINE__),
std::exception);
BOOST_CHECK(ReadLuaOptionFile<std::vector<std::string>>(lua_option_file, "section1.vector_value",
__FILE__, __LINE__).size()
== 3ul);
BOOST_CHECK(ReadLuaOptionFile<std::vector<std::string>>(lua_option_file, "section1.vector_value",
__FILE__, __LINE__)[0]
== "foo");
BOOST_CHECK(ReadLuaOptionFile<std::vector<std::string>>(lua_option_file, "section1.vector_value",
__FILE__, __LINE__)[1]
== "bar");
BOOST_CHECK(ReadLuaOptionFile<std::vector<std::string>>(lua_option_file, "section1.vector_value",
__FILE__, __LINE__)[2]
== "baz");
BOOST_CHECK_THROW(ReadLuaOptionFile<int>(lua_option_file, "section1.vector_value", __FILE__, __LINE__),
std::exception);
BOOST_CHECK_THROW(ReadLuaOptionFile<std::vector<int>>(lua_option_file, "section1.int_value", __FILE__, __LINE__),
std::exception);
BOOST_CHECK(ReadLuaOptionFile<std::string>(lua_option_file, "section1.string_value", __FILE__, __LINE__)
== "string");
BOOST_CHECK((ReadLuaOptionFile<std::map<int, int>>(lua_option_file, "section1.map_value",
__FILE__, __LINE__).size()
== 3ul));
BOOST_CHECK((ReadLuaOptionFile<std::map<int, int>>(lua_option_file, "section1.map_value",
__FILE__, __LINE__)[3]
== 5));
BOOST_CHECK((ReadLuaOptionFile<std::map<int, int>>(lua_option_file, "section1.map_value",
__FILE__, __LINE__)[4]
== 7));
BOOST_CHECK((ReadLuaOptionFile<std::map<int, int>>(lua_option_file, "section1.map_value",
__FILE__, __LINE__)[5]
== 8));
BOOST_CHECK_THROW(ReadLuaOptionFile<std::string>(lua_option_file, "unknown_key", __FILE__, __LINE__),
std::exception);
BOOST_CHECK_THROW(ReadLuaOptionFile<double>(lua_option_file, "section1.string_value", __FILE__, __LINE__),
std::exception);
BOOST_CHECK_THROW(ReadLuaOptionFile<double>(lua_option_file, "section1.invalid_value", __FILE__, __LINE__),
std::exception);
// When I have time to investigate how to do so in Boost
// CHECK_ABORT(ReadLuaOptionFile<double>(lua_option_file, __FILE__, __LINE__));
}
BOOST_FIXTURE_TEST_CASE(constraints, TestNS::FixtureNS::Environment)
{
decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
decltype(auto) input_file =
environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/Utilities/LuaOptionFile/demo_lua_option_file.lua");
std::unique_ptr<LuaOptionFile> ptr;
/* BOOST_REQUIRE_NO_THROW */(ptr.reset(new LuaOptionFile(input_file, __FILE__, __LINE__)));
auto& lua_option_file = *(ptr.get());
BOOST_CHECK_THROW(NumericNS::AreEqual(ReadLuaOptionFile<double>(lua_option_file, "root_value", __FILE__, __LINE__,
"v > 5."),
2.44),
std::exception);
/* BOOST_CHECK_NO_THROW */(NumericNS::AreEqual(ReadLuaOptionFile<double>(lua_option_file, "root_value",
__FILE__, __LINE__, "v < 3."),
2.44));
/* BOOST_CHECK_NO_THROW */(ReadLuaOptionFile<std::vector<std::string>>(lua_option_file, "section1.vector_value",
__FILE__, __LINE__, "value_in(v, { 'foo', 'bar', 'baz' })"));
BOOST_CHECK_THROW(ReadLuaOptionFile<std::vector<std::string>>(lua_option_file, "section1.vector_value",
__FILE__, __LINE__, "value_in(v, { 'bar', 'baz' })"),
std::exception);
}
//TEST_CASE("Forgotten call to Open()")
//BOOST_FIXTURE_TEST_CASE(parameters_properly_read, TestNS::FixtureNS::Environment)
//{
// decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
//
// decltype(auto) input_file =
// environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/Utilities/LuaOptionFile/demo_lua_option_file.lua");
//
// std::unique_ptr<LuaOptionFile> ptr;
// /* BOOST_REQUIRE_NO_THROW */(ptr.reset(new LuaOptionFile(input_file, __FILE__, __LINE__)));
//
// auto& lua_option_file = *(ptr.get());
//
// BOOST_CHECK(NumericNS::AreEqual(ReadLuaOptionFile<double>(lua_option_file, "root_value", __FILE__, __LINE__),
// 2.44));
//
// BOOST_CHECK(ReadLuaOptionFile<std::string>(lua_option_file, "section1.string_value", __FILE__, __LINE__) == "string");
// BOOST_CHECK(NumericNS::AreEqual(ReadLuaOptionFile<double>(lua_option_file, "section1.double_value",
// __FILE__, __LINE__),
// 5.215));
//
// BOOST_CHECK(ReadLuaOptionFile<unsigned int>(lua_option_file, "section1.int_value", __FILE__, __LINE__) == 10u);
// BOOST_CHECK_THROW(ReadLuaOptionFile<unsigned int>(lua_option_file, "section1.double_value", __FILE__, __LINE__),
// std::exception);
//
// BOOST_CHECK(ReadLuaOptionFile<std::vector<std::string>>(lua_option_file, "section1.vector_value",
// __FILE__, __LINE__).size()
// == 3ul);
// BOOST_CHECK(ReadLuaOptionFile<std::vector<std::string>>(lua_option_file, "section1.vector_value",
// __FILE__, __LINE__)[0]
// == "foo");
// BOOST_CHECK(ReadLuaOptionFile<std::vector<std::string>>(lua_option_file, "section1.vector_value",
// __FILE__, __LINE__)[1]
// == "bar");
// BOOST_CHECK(ReadLuaOptionFile<std::vector<std::string>>(lua_option_file, "section1.vector_value",
// __FILE__, __LINE__)[2]
// == "baz");
// BOOST_CHECK_THROW(ReadLuaOptionFile<int>(lua_option_file, "section1.vector_value", __FILE__, __LINE__),
// std::exception);
// BOOST_CHECK_THROW(ReadLuaOptionFile<std::vector<int>>(lua_option_file, "section1.int_value", __FILE__, __LINE__),
// std::exception);
//
// BOOST_CHECK(ReadLuaOptionFile<std::string>(lua_option_file, "section1.string_value", __FILE__, __LINE__)
// == "string");
//
// BOOST_CHECK((ReadLuaOptionFile<std::map<int, int>>(lua_option_file, "section1.map_value",
// __FILE__, __LINE__).size()
// == 3ul));
// BOOST_CHECK((ReadLuaOptionFile<std::map<int, int>>(lua_option_file, "section1.map_value",
// __FILE__, __LINE__)[3]
// == 5));
// BOOST_CHECK((ReadLuaOptionFile<std::map<int, int>>(lua_option_file, "section1.map_value",
// __FILE__, __LINE__)[4]
// == 7));
// BOOST_CHECK((ReadLuaOptionFile<std::map<int, int>>(lua_option_file, "section1.map_value",
// __FILE__, __LINE__)[5]
// == 8));
//
// BOOST_CHECK_THROW(ReadLuaOptionFile<std::string>(lua_option_file, "unknown_key", __FILE__, __LINE__),
// std::exception);
// BOOST_CHECK_THROW(ReadLuaOptionFile<double>(lua_option_file, "section1.string_value", __FILE__, __LINE__),
// std::exception);
//
// BOOST_CHECK_THROW(ReadLuaOptionFile<double>(lua_option_file, "section1.invalid_value", __FILE__, __LINE__),
// std::exception);
//
// // When I have time to investigate how to do so in Boost
// // CHECK_ABORT(ReadLuaOptionFile<double>(lua_option_file, __FILE__, __LINE__));
//}
//
//
//BOOST_FIXTURE_TEST_CASE(constraints, TestNS::FixtureNS::Environment)
//{
// decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
//
// decltype(auto) input_file =
// environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/Utilities/LuaOptionFile/demo_lua_option_file.lua");
//
// std::unique_ptr<LuaOptionFile> ptr;
// /* BOOST_REQUIRE_NO_THROW */(ptr.reset(new LuaOptionFile(input_file, __FILE__, __LINE__)));
// auto& lua_option_file = *(ptr.get());
//
// BOOST_CHECK_THROW(NumericNS::AreEqual(ReadLuaOptionFile<double>(lua_option_file, "root_value", __FILE__, __LINE__,
// "v > 5."),
// 2.44),
// std::exception);
// /* BOOST_CHECK_NO_THROW */(NumericNS::AreEqual(ReadLuaOptionFile<double>(lua_option_file, "root_value",
// __FILE__, __LINE__, "v < 3."),
// 2.44));
//
// /* BOOST_CHECK_NO_THROW */(ReadLuaOptionFile<std::vector<std::string>>(lua_option_file, "section1.vector_value",
// __FILE__, __LINE__, "value_in(v, { 'foo', 'bar', 'baz' })"));
//
// BOOST_CHECK_THROW(ReadLuaOptionFile<std::vector<std::string>>(lua_option_file, "section1.vector_value",
// __FILE__, __LINE__, "value_in(v, { 'bar', 'baz' })"),
// std::exception);
//
//}
//
//
////TEST_CASE("Forgotten call to Open()")
////{
//// decltype(auto) input_file =
//// environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/Utilities/LuaOptionFile/demo_lua_option_file.lua");
////
//// LuaOptionFile lua_option_file;
//// BOOST_CHECK_THROW(NumericNS::AreEqual(ReadLuaOptionFile<double>(("root_value", "v > 5.", __FILE__, __LINE__), 2.44));
////
////}
//
//
//BOOST_FIXTURE_TEST_CASE(lua_functions, TestNS::FixtureNS::Environment)
//{
// decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
//
// decltype(auto) input_file =
// environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/Utilities/LuaOptionFile/demo_lua_option_file.lua");
//
// std::unique_ptr<LuaOptionFile> ptr;
// ptr.reset(new LuaOptionFile(input_file, __FILE__, __LINE__));
// auto& lua_option_file = *(ptr.get());
//
// decltype(auto) one_arg_fct =
// ReadLuaOptionFile<Utilities::InputDataNS::LuaFunction<double(double)>>(lua_option_file,
// "section2.one_arg_function",
// __FILE__, __LINE__);
//
// BOOST_CHECK(NumericNS::AreEqual(one_arg_fct(3.), -3.));
//
// decltype(auto) several_arg_function =
// ReadLuaOptionFile<Utilities::InputDataNS::LuaFunction<double(double, double, double)>>(lua_option_file,
// "section2.several_arg_function",
// __FILE__, __LINE__);
//
// BOOST_CHECK(NumericNS::AreEqual(several_arg_function(3., 4., 5.), 2.));
//
//}
//
//
//
//BOOST_FIXTURE_TEST_CASE(redundant, TestNS::FixtureNS::Environment)
//{
// decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
//
// decltype(auto) input_file =
// environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/Utilities/LuaOptionFile/redundancy.lua");
//
// std::unique_ptr<LuaOptionFile> ptr = nullptr;
// BOOST_REQUIRE_THROW(ptr.reset(new LuaOptionFile(input_file, __FILE__, __LINE__)), std::exception);
//
//}
//
//
//
//BOOST_FIXTURE_TEST_CASE(invalid_lua, TestNS::FixtureNS::Environment)
//{
// decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
//
// decltype(auto) input_file =
// environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/Utilities/LuaOptionFile/demo_lua_option_file.lua");
//
// LuaOptionFile lua_option_file;
// BOOST_CHECK_THROW(NumericNS::AreEqual(ReadLuaOptionFile<double>(("root_value", "v > 5.", __FILE__, __LINE__), 2.44));
// std::unique_ptr<LuaOptionFile> ptr;
// ptr.reset(new LuaOptionFile(input_file, __FILE__, __LINE__));
// auto& lua_option_file = *(ptr.get());
//
// BOOST_REQUIRE_THROW(ReadLuaOptionFile<Utilities::InputDataNS::LuaFunction<double(double)>>(lua_option_file,
// "section3.invalid_function",
// __FILE__, __LINE__),
// std::exception);
//}
BOOST_FIXTURE_TEST_CASE(lua_functions, TestNS::FixtureNS::Environment)
{
decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
decltype(auto) input_file =
environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/Utilities/LuaOptionFile/demo_lua_option_file.lua");
std::unique_ptr<LuaOptionFile> ptr;
ptr.reset(new LuaOptionFile(input_file, __FILE__, __LINE__));
auto& lua_option_file = *(ptr.get());
decltype(auto) one_arg_fct =
ReadLuaOptionFile<Utilities::InputDataNS::LuaFunction<double(double)>>(lua_option_file,
"section2.one_arg_function",
__FILE__, __LINE__);
BOOST_CHECK(NumericNS::AreEqual(one_arg_fct(3.), -3.));
decltype(auto) several_arg_function =
ReadLuaOptionFile<Utilities::InputDataNS::LuaFunction<double(double, double, double)>>(lua_option_file,
"section2.several_arg_function",
__FILE__, __LINE__);
BOOST_CHECK(NumericNS::AreEqual(several_arg_function(3., 4., 5.), 2.));
}
BOOST_FIXTURE_TEST_CASE(redundant, TestNS::FixtureNS::Environment)
{
decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
decltype(auto) input_file =
environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/Utilities/LuaOptionFile/redundancy.lua");
std::unique_ptr<LuaOptionFile> ptr = nullptr;
BOOST_REQUIRE_THROW(ptr.reset(new LuaOptionFile(input_file, __FILE__, __LINE__)), std::exception);
}
BOOST_FIXTURE_TEST_CASE(invalid_lua, TestNS::FixtureNS::Environment)
{
decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
decltype(auto) input_file =
environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/Utilities/LuaOptionFile/demo_lua_option_file.lua");
std::unique_ptr<LuaOptionFile> ptr;
ptr.reset(new LuaOptionFile(input_file, __FILE__, __LINE__));
auto& lua_option_file = *(ptr.get());
BOOST_REQUIRE_THROW(ReadLuaOptionFile<Utilities::InputDataNS::LuaFunction<double(double)>>(lua_option_file,
"section3.invalid_function",
__FILE__, __LINE__),
std::exception);
}
BOOST_FIXTURE_TEST_CASE(map_in_vector, TestNS::FixtureNS::Environment)
{
std::cout << "================================== TMP =================================" << std::endl;
// Introduced after #1468, in which two braces on the same line wreak havoc...
decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
......@@ -241,11 +242,28 @@ BOOST_FIXTURE_TEST_CASE(map_in_vector, TestNS::FixtureNS::Environment)
Utilities::PrintContainer<>::Do(lua.GetEntryKeyList(), oconv);
BOOST_CHECK_EQUAL(oconv.str(),
"[TransientSource4.nature, TransientSource4.value, "
"TransientSource5.nature, TransientSource5.value]");
"[ValueOutsideBrace, "
"TransientSource4.nature, TransientSource4.value, "
"TransientSource5.nature, TransientSource5.value, "
"TransientSource5.whatever.sublevel, "
"TransientSource5.whatever.sublevel2]");
}
//BOOST_FIXTURE_TEST_CASE(no_section, TestNS::FixtureNS::Environment)
//{
// decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
//
// decltype(auto) input_file =
// environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/Utilities/LuaOptionFile/no_section.lua");
//
// LuaOptionFile lua(input_file, __FILE__, __LINE__);
//
// std::ostringstream oconv;
// Utilities::PrintContainer<>::Do(lua.GetEntryKeyList(), oconv);
//
// BOOST_CHECK_EQUAL(oconv.str(),
// "[a, b, c, d, e, f]");
//}
PRAGMA_DIAGNOSTIC(pop)
ValueOutsideBrace = 3.14
TransientSource4 = {
nature = { "lua_function", "constant", "piecewise_constant_by_domain"},
......@@ -25,7 +27,13 @@ TransientSource5 = {
end
]],
0.,
{ [1] = 0., [3] = 14.5, [4] = -31.231 }
{ [1] = 0., [3] = 14.5, [4] = -31.231 } },
whatever = {
sublevel = { 4 },
sublevel2 = 3
}
......
a = "jdls"
b = "foo"
c = 5
d = 3.21
e = -904
f = { "foo", 4, "s" }
......@@ -15,6 +15,7 @@
#include <fstream>
#include <sstream>
#include <array>
#include <cctype> // std::isalnum
#include "Utilities/Containers/Vector.hpp"
#include "Utilities/Filesystem/File.hpp"
......@@ -118,6 +119,14 @@ namespace MoReFEM
{
struct NameAndPos
{
std::string name;
std::size_t position;
};
void AddValueIn(lua_State* lua_state)
{
std::string code = "function value_in(v, table)\
......@@ -139,146 +148,305 @@ namespace MoReFEM
std::ifstream stream;
FilesystemNS::File::Read(stream, path, __FILE__, __LINE__);
auto npos = std::string::npos;
constexpr auto npos = std::string::npos;
std::string line;
std::string lhs;
std::ostringstream oconv;
std::string content;
std::vector<std::string> section_hierarchy;
// First we load all the content into a single string (barring the comments): we want to identify the
// braces without side effects due to line break present or not.
{
std::string line;
while (getline(stream, line))
{
auto pos = line.find("--");
std::vector<std::string> ret;
if (pos != npos)
line.erase(pos, npos);
oconv << line;
}
content = oconv.str();
oconv.str("");
}
// All strings that might be tagged as variable or section and begins with one
// of these keys followed by ' ' or '(' must be rejected.
std::array<std::string, 3> rejected_keys
// Then we want to work on the braces
// Convention: we do not count equals which last seen character was a ']'
// Because '=' in maps (such as { [1] = 0., [3] = 14.5, [4] = -31.231 }} ) shouldn't be considered to
// determine keywords.
std::vector<std::size_t> equal_position_list;
std::vector<int> brace_position_list; // convention: '{' positions are stored as positive values.
// '}' positions are stored as negative values.
const auto size = content.size();
bool is_last_non_space_character_close_bracket = false;
int inside_map = 0;
for (auto i = 0ul; i < size; ++i)
{
if (content[i] == '=')
{
"if",
"else",
"elseif"
if (!is_last_non_space_character_close_bracket)
equal_position_list.push_back(i);
else
++inside_map;
if (inside_map == 1)
brace_position_list.pop_back(); // cancel the last opening brace.
}
};
else if (content[i] == '{')
brace_position_list.push_back(static_cast<int>(i));
else if (content[i] == '}')
{
if (inside_map)
inside_map = 0;
else
brace_position_list.push_back(-static_cast<int>(i));
}
if (content[i] == ']')
is_last_non_space_character_close_bracket = true;
else if (content[i] == ' ')
;
else
is_last_non_space_character_close_bracket = false;
}
unsigned int line_count = 0;
// If there are no '=' signs between braces, it is a vector... So remove it
std::cout << "TMP EQUAL POSITION = ";
Utilities::PrintContainer<>::Do(equal_position_list);
while (std::getline(stream, line))
{
++line_count;
std::cout << "TMP BRACE POSITION = ";
Utilities::PrintContainer<>::Do(brace_position_list);
// Delete the comment part of the line.
auto pos = line.find("--");
if (pos != npos)
line.erase(pos, npos);
std::cout << "SIZES = " << content.size() << " ====== " << equal_position_list.size() << " and " << brace_position_list.size() << std::endl;
// If there are more closing braces than opening ones on the line, it means the current
// section has been closed.
auto Nopening_brace = (std::count(line.cbegin(), line.cend(), '{'));
auto Nclosing_brace = (std::count(line.cbegin(), line.cend(), '}'));
// For each equal, grab the name beforehand (sections will be reconstructed later).
std::vector<NameAndPos> name_list;
if (Nclosing_brace > Nopening_brace)
for (auto equal_pos : equal_position_list)
{
auto pos = equal_pos;
while (content[pos] == ' ' && pos > 0)
--pos;
if (pos == 0)
{
if (Nclosing_brace - Nopening_brace != 1u || section_hierarchy.empty())
throw Exception("Invalid Lua file: issue with closing braces somewhere in the block closed "
"in line " + std::to_string(line_count) + " (might be too much of them, "
", missing commas or opening brace not on the same line as its '=' sign).",
__FILE__,
__LINE__);
section_hierarchy.pop_back();
oconv << "Unable to find name before the first equal sign in file " << path;
throw Exception(oconv.str(), __FILE__, __LINE__);
}
// Consider only lines with an '='.
pos = line.find('=');
std::string name;
if (pos == npos)
continue;
// Keep doing it while reconstruct the name backwards.
while (!std::isalnum(content[pos]) && pos > 0)
--pos;
// Extract the name of the variable (or of the section).
if (pos == 0)
{
lhs = line.substr(0, pos);
Utilities::String::Strip(lhs, "\t\n ");
oconv << "Unable to find name before the first equal sign in file " << path;
throw Exception(oconv.str(), __FILE__, __LINE__);
}