diff --git a/CMakeSettings.json b/CMakeSettings.json index 9204f06..944b567 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -4,7 +4,7 @@ "name": "x64-Debug", "generator": "Ninja", "configurationType": "Debug", - "inheritEnvironments": [ "msvc_x64_x64" ], + "inheritEnvironments": [ "clang_cl_x64_x64" ], "buildRoot": "${projectDir}\\out\\build\\${name}", "installRoot": "${projectDir}\\out\\install\\${name}", "cmakeCommandArgs": "", diff --git a/NouVeL/NVL.cpp b/NouVeL/NVL.cpp index 196e0e8..8899730 100644 --- a/NouVeL/NVL.cpp +++ b/NouVeL/NVL.cpp @@ -67,7 +67,7 @@ namespace { return final; } - std::string read_token(std::ifstream& nvl) + std::string read_sequence_name(std::ifstream& nvl) { nvl >> std::ws; std::string token; @@ -89,39 +89,94 @@ namespace { namespace NVL { - void parse_Call(Context context, std::ifstream& nvl, std::streampos end_pos) + 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; + char c{}; + switch (nvl.peek()) + { + case '[': // List, fucked + end = scope_cope('[', nvl); + nvl.get(c); + while (nvl.peek() != ']') + { + parse_Object(this_context, nvl); + nvl >> std::ws; + } + nvl.get(c); + break; + case '<': // Dialogue, not yet done + end = scope_cope('<', nvl); + break; + case '\"': // String, this is also fucked + end = scope_cope('\"', nvl); + 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)) + { + content = std::get(content) + c; + } + if (c == ']' || c == ',' || c == '}') + nvl.putback(c); + this_object.Value = std::get(content); + break; + } + + + this_object.Is_Token = is_token; + + 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); + } + + + void parse_Call(Context parent_context, std::ifstream& nvl) { Call this_call; - // temp fuckery - Object tmp_obj; - tmp_obj.Value; + Context this_context = parent_context; + this_context.Scope_Hierarchy.push_back(this_call); + + parse_Object(this_context, nvl); - std::string tmp_str; - char c{}; - while (nvl.tellg() < end_pos) + while (nvl.peek() != '!n' && nvl.peek() != '}') { - nvl.get(c); - tmp_str += c; + parse_Object(this_context, nvl); } - tmp_obj.Value = tmp_str; - - this_call.Objects.push_back(tmp_obj); - - std::get>(context.Scope_Hierarchy.back())->Calls.push_back(this_call); + (std::get>(parent_context.Scope_Hierarchy.back())).get().Calls.push_back(this_call); } void parse_Sequence(Context parent_context, std::ifstream& nvl) { - Sequence this_sequence = Sequence( read_token(nvl) ); + Sequence this_sequence = Sequence( read_sequence_name(nvl) ); Context this_context = parent_context; - this_context.Scope_Hierarchy.push_back(std::make_shared(this_sequence)); + this_context.Scope_Hierarchy.push_back(this_sequence); nvl >> std::ws; char c; - nvl.get(c); + nvl.get(c); // get { if (c != '{') { std::cerr << "Sequence parse failed!" << std::endl; throw; @@ -129,12 +184,14 @@ namespace NVL std::streampos end_pos = scope_cope(c, nvl); - while (nvl.tellg() < end_pos) + while (nvl.tellg() < end_pos - static_cast(1)) { - parse_Call(this_context, nvl, end_pos); + parse_Call(this_context, nvl); } - std::get>(parent_context.Scope_Hierarchy.back())->Sequences.push_back(this_sequence); + nvl.get(c); // get } + + std::get>(parent_context.Scope_Hierarchy.back()).get().Sequences.push_back(this_sequence); } void parse_NVL(Tree& root, std::string path) @@ -146,7 +203,7 @@ namespace NVL Context current_context; - current_context.Scope_Hierarchy.push_back(std::make_shared(root)); + current_context.Scope_Hierarchy.push_back(root); while (!nvl.eof()) { parse_Sequence(current_context, nvl); @@ -169,10 +226,7 @@ namespace NVL std::cout << "\t"; } } - void Token::Print() - { - std::cout << "Token: " << Identifier << std::endl; - } + void Object::Print(int indent) { indent_loop(indent); @@ -180,18 +234,15 @@ namespace NVL switch (Value.index()) { case 0: - std::get(Value).Print(); - break; - case 1: std::cout << "float: " << std::get(Value) << std::endl; break; - case 2: + case 1: std::cout << "string: " << std::get(Value) << std::endl; break; - case 3: + case 2: std::cout << "bool: " << std::get(Value) << std::endl; break; - case 4: + case 3: std::cout << "List:" << std::endl; for (auto& x : std::get>(Value)) { @@ -217,6 +268,8 @@ namespace NVL { x.Print(indent + 1); } + indent_loop(indent); + std::cout << "------------------------" << std::endl; } void Tree::Print(int indent) { diff --git a/NouVeL/NVL.h b/NouVeL/NVL.h index fa54341..e0ef4d7 100644 --- a/NouVeL/NVL.h +++ b/NouVeL/NVL.h @@ -10,23 +10,17 @@ namespace NVL { - struct Token - { - std::string Identifier; - - void Print(); - }; - struct Object { std::variant< - Token, float, std::string, bool, std::vector // Implies Object can be an array of other Object > Value; + bool Is_Token = false; + void Print(int indent); }; @@ -56,16 +50,18 @@ namespace NVL struct Context { std::vector, - std::shared_ptr, - std::shared_ptr, - std::shared_ptr + std::reference_wrapper, + std::reference_wrapper, + std::reference_wrapper, + std::reference_wrapper >> Scope_Hierarchy; }; void parse_NVL(Tree& root, std::string path); - void parse_Sequence(Context context, std::ifstream& nvl); + void parse_Sequence(Context parent_context, std::ifstream& nvl); - void parse_Call(Context context, std::ifstream& nvl, std::streampos end_pos); + void parse_Call(Context parent_context, std::ifstream& nvl); + + void parse_Object(Context parent_context, std::ifstream& nvl, bool is_token); } diff --git a/myfile.txt b/myfile.txt index 569a7c0..d2558e4 100644 --- a/myfile.txt +++ b/myfile.txt @@ -1,14 +1,20 @@ dsahd { dasjkhdakjsdasddsmnfdsf asdkashjdsad - asdasdfdoy893eryh + asdasd\\"fdoy893eryh :awesome: } twrgfgdfg { - fsgsfg -} + fsgsfg} -tsr4t4t { +tsr4t4t +{ dasjkhdakjs } + +65e +{ + afwet4} + +asdjnasd{das;ldmad} \ No newline at end of file