diff --git a/CMakeSettings.json b/CMakeSettings.json index 944b567..9204f06 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -4,7 +4,7 @@ "name": "x64-Debug", "generator": "Ninja", "configurationType": "Debug", - "inheritEnvironments": [ "clang_cl_x64_x64" ], + "inheritEnvironments": [ "msvc_x64_x64" ], "buildRoot": "${projectDir}\\out\\build\\${name}", "installRoot": "${projectDir}\\out\\install\\${name}", "cmakeCommandArgs": "", diff --git a/NouVeL/NVL.cpp b/NouVeL/NVL.cpp index 8899730..953d821 100644 --- a/NouVeL/NVL.cpp +++ b/NouVeL/NVL.cpp @@ -34,11 +34,19 @@ namespace { while (!current_scope.Scope.empty()) { stream.get(c); - for (auto const& x : SCOPER_MAP) - { - if (c == x.first) { - current_scope.Scope.push_back(c); - break; + + bool no_more_nesting_quotes = false; + for (auto const& x : current_scope.Scope) + if (x == '\'' || x == '\"') + no_more_nesting_quotes = true; + + if (!no_more_nesting_quotes) { + for (auto const& x : SCOPER_MAP) + { + if (c == x.first) { + current_scope.Scope.push_back(c); + break; + } } } @@ -74,7 +82,7 @@ namespace { char c; while (nvl.get(c)) { - if (c == ' ' || c == '{') + if (c == ' ' || c == '{' || c == '\n') { nvl.putback(c); break; @@ -89,64 +97,92 @@ namespace { namespace NVL { - template + template void parse_Object(Context parent_context, std::ifstream& nvl) { Object this_object; Context this_context = parent_context; this_context.Scope_Hierarchy.push_back(this_object); - + char start = nvl.peek(); nvl >> std::ws; std::streampos end; // unused if object is not scoped - std::variant> content; + std::variant> content = ""; char c{}; - switch (nvl.peek()) + switch (nvl.peek()) { case '[': // List, fucked + nvl.get(c); // do not exchange this line with the next one end = scope_cope('[', nvl); - nvl.get(c); - while (nvl.peek() != ']') + while (nvl.tellg() < end - static_cast(1)) { parse_Object(this_context, nvl); nvl >> std::ws; } nvl.get(c); break; - case '<': // Dialogue, not yet done + case '<': // Dialogue, not yet implemented end = scope_cope('<', nvl); break; - case '\"': // String, this is also fucked + case '\"': // String + nvl.get(c); end = scope_cope('\"', nvl); - while (nvl.tellg() < end - static_cast(1)) + while (nvl.tellg() < end - static_cast(1)) { nvl.get(c); content = std::get(content) + c; } nvl.get(c); // rid of final scoper + this_object.Value = std::get(content); break; default: - for (nvl.get(c);!(c == ' ' || c == '\n' || c == '}' || c == ']' || c == ',');nvl.get(c)) + for (nvl.get(c); !(c == ' ' || c == '\n' || c == '}' || c == ']' || c == ','); nvl.get(c)) { content = std::get(content) + c; } if (c == ']' || c == ',' || c == '}') nvl.putback(c); - this_object.Value = std::get(content); + + try + { + this_object.Value = std::stof(std::get(content)); + } + catch (std::exception) + { + if (std::get(content) == "true") + { + this_object.Value = true; + } + else if (std::get(content) == "false") { + this_object.Value = false; + } + else + { + this_object.Value = std::get(content); + } + } break; - } + } - this_object.Is_Token = is_token; + this_object.Is_Symbol = is_symbol; + + nvl >> std::ws; if (is_parent_call) (std::get>(parent_context.Scope_Hierarchy.back())).get().Objects.push_back(this_object); - else - std::get>((std::get>(parent_context.Scope_Hierarchy.back())).get().Value).push_back(this_object); + else if ((std::get>(parent_context.Scope_Hierarchy.back())).get().Value.index() == 4) { // 4 for list + ; + std::get>((std::get>(parent_context.Scope_Hierarchy.back())).get().Value).push_back(this_object); + } + else { + ; + (std::get>(parent_context.Scope_Hierarchy.back())).get().Value = std::vector { this_object }; + } } @@ -156,7 +192,7 @@ namespace NVL Context this_context = parent_context; this_context.Scope_Hierarchy.push_back(this_call); - + parse_Object(this_context, nvl); while (nvl.peek() != '!n' && nvl.peek() != '}') @@ -234,20 +270,29 @@ namespace NVL switch (Value.index()) { case 0: - std::cout << "float: " << std::get(Value) << std::endl; + std::cout << "Nil" << std::endl; break; case 1: - std::cout << "string: " << std::get(Value) << std::endl; + std::cout << "float: " << std::get(Value) << std::endl; break; case 2: - std::cout << "bool: " << std::get(Value) << std::endl; + if (Is_Symbol) + std::cout << "symbol: " << std::get(Value) << std::endl; + else + std::cout << "string: " << std::get(Value) << std::endl; break; case 3: + std::cout << "bool: " << std::boolalpha << std::get(Value) << std::endl; + break; + case 4: std::cout << "List:" << std::endl; for (auto& x : std::get>(Value)) { x.Print(indent + 1); - } + } + break; + case 5: + std::cout << "Nil" << std::endl; break; } } diff --git a/NouVeL/NVL.h b/NouVeL/NVL.h index e0ef4d7..e84398a 100644 --- a/NouVeL/NVL.h +++ b/NouVeL/NVL.h @@ -10,19 +10,24 @@ namespace NVL { + struct Nil + { + }; + struct Object { std::variant< + std::monostate, float, std::string, bool, - std::vector // Implies Object can be an array of other Object + std::vector, // Implies Object can be an array of other Object + Nil > Value; - bool Is_Token = false; + bool Is_Symbol = false; void Print(int indent); - }; struct Call @@ -63,5 +68,6 @@ namespace NVL void parse_Call(Context parent_context, std::ifstream& nvl); - void parse_Object(Context parent_context, std::ifstream& nvl, bool is_token); + template + void parse_Object(Context parent_context, std::ifstream& nvl); } diff --git a/NouVeL/NouVeL.cpp b/NouVeL/NouVeL.cpp index d9c627f..877aab9 100644 --- a/NouVeL/NouVeL.cpp +++ b/NouVeL/NouVeL.cpp @@ -5,7 +5,7 @@ int main() const std::string PJ_DIR = "E:\\Archive\\Projects\\NouVeL\\"; NVL::Tree tree; - NVL::parse_NVL(tree, PJ_DIR + "myfile.txt"); + NVL::parse_NVL(tree, PJ_DIR + "test.nvl"); tree.Print(0); diff --git a/myfile.txt b/myfile.txt deleted file mode 100644 index d2558e4..0000000 --- a/myfile.txt +++ /dev/null @@ -1,20 +0,0 @@ -dsahd { - dasjkhdakjsdasddsmnfdsf - asdkashjdsad - asdasd\\"fdoy893eryh - :awesome: -} - -twrgfgdfg { - fsgsfg} - -tsr4t4t -{ - dasjkhdakjs -} - -65e -{ - afwet4} - -asdjnasd{das;ldmad} \ No newline at end of file diff --git a/test.nvl b/test.nvl new file mode 100644 index 0000000..3877473 --- /dev/null +++ b/test.nvl @@ -0,0 +1,10 @@ +mmawesome +{ + mmawesome mmaji awesome asduhjaiodhj kl;d 3434.3434 true false +} + +dasijhdoisaj {} + +uihf98 { + dasdj [39439048 jidjao] [] [] [] [[][[][[[[[] hi [2323 d]]]]]]] +}