This commit is contained in:
lachrymaL 2021-05-14 20:44:09 -04:00
parent 5505945f8e
commit e2e7d8ed13
No known key found for this signature in database
GPG key ID: F3640ACFA174B1C1
4 changed files with 106 additions and 51 deletions

View file

@ -4,7 +4,7 @@
"name": "x64-Debug", "name": "x64-Debug",
"generator": "Ninja", "generator": "Ninja",
"configurationType": "Debug", "configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ], "inheritEnvironments": [ "clang_cl_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}", "buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}", "installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "", "cmakeCommandArgs": "",

View file

@ -67,7 +67,7 @@ namespace {
return final; return final;
} }
std::string read_token(std::ifstream& nvl) std::string read_sequence_name(std::ifstream& nvl)
{ {
nvl >> std::ws; nvl >> std::ws;
std::string token; std::string token;
@ -89,39 +89,94 @@ namespace {
namespace NVL namespace NVL
{ {
void parse_Call(Context context, std::ifstream& nvl, std::streampos end_pos) template <bool is_parent_call, bool is_token>
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<std::string, std::vector<Object>> content;
char c{};
switch (nvl.peek())
{
case '[': // List, fucked
end = scope_cope('[', nvl);
nvl.get(c);
while (nvl.peek() != ']')
{
parse_Object<false, false>(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<std::streampos>(1))
{
nvl.get(c);
content = std::get<std::string>(content) + c;
}
nvl.get(c); // rid of final scoper
this_object.Value = std::get<std::string>(content);
break;
default:
for (nvl.get(c);!(c == ' ' || c == '\n' || c == '}' || c == ']' || c == ',');nvl.get(c))
{
content = std::get<std::string>(content) + c;
}
if (c == ']' || c == ',' || c == '}')
nvl.putback(c);
this_object.Value = std::get<std::string>(content);
break;
}
this_object.Is_Token = is_token;
if (is_parent_call)
(std::get<std::reference_wrapper<Call>>(parent_context.Scope_Hierarchy.back())).get().Objects.push_back(this_object);
else
std::get<std::vector<NVL::Object>>((std::get<std::reference_wrapper<Object>>(parent_context.Scope_Hierarchy.back())).get().Value).push_back(this_object);
}
void parse_Call(Context parent_context, std::ifstream& nvl)
{ {
Call this_call; Call this_call;
// temp fuckery Context this_context = parent_context;
Object tmp_obj; this_context.Scope_Hierarchy.push_back(this_call);
tmp_obj.Value;
parse_Object<true, true>(this_context, nvl);
std::string tmp_str; while (nvl.peek() != '!n' && nvl.peek() != '}')
char c{};
while (nvl.tellg() < end_pos)
{ {
nvl.get(c); parse_Object<true, false>(this_context, nvl);
tmp_str += c;
} }
tmp_obj.Value = tmp_str; (std::get<std::reference_wrapper<Sequence>>(parent_context.Scope_Hierarchy.back())).get().Calls.push_back(this_call);
this_call.Objects.push_back(tmp_obj);
std::get<std::shared_ptr<Sequence>>(context.Scope_Hierarchy.back())->Calls.push_back(this_call);
} }
void parse_Sequence(Context parent_context, std::ifstream& nvl) 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; Context this_context = parent_context;
this_context.Scope_Hierarchy.push_back(std::make_shared<Sequence>(this_sequence)); this_context.Scope_Hierarchy.push_back(this_sequence);
nvl >> std::ws; nvl >> std::ws;
char c; char c;
nvl.get(c); nvl.get(c); // get {
if (c != '{') { if (c != '{') {
std::cerr << "Sequence parse failed!" << std::endl; std::cerr << "Sequence parse failed!" << std::endl;
throw; throw;
@ -129,12 +184,14 @@ namespace NVL
std::streampos end_pos = scope_cope(c, nvl); std::streampos end_pos = scope_cope(c, nvl);
while (nvl.tellg() < end_pos) while (nvl.tellg() < end_pos - static_cast<std::streampos>(1))
{ {
parse_Call(this_context, nvl, end_pos); parse_Call(this_context, nvl);
} }
std::get<std::shared_ptr<Tree>>(parent_context.Scope_Hierarchy.back())->Sequences.push_back(this_sequence); nvl.get(c); // get }
std::get<std::reference_wrapper<Tree>>(parent_context.Scope_Hierarchy.back()).get().Sequences.push_back(this_sequence);
} }
void parse_NVL(Tree& root, std::string path) void parse_NVL(Tree& root, std::string path)
@ -146,7 +203,7 @@ namespace NVL
Context current_context; Context current_context;
current_context.Scope_Hierarchy.push_back(std::make_shared<Tree>(root)); current_context.Scope_Hierarchy.push_back(root);
while (!nvl.eof()) { while (!nvl.eof()) {
parse_Sequence(current_context, nvl); parse_Sequence(current_context, nvl);
@ -169,10 +226,7 @@ namespace NVL
std::cout << "\t"; std::cout << "\t";
} }
} }
void Token::Print()
{
std::cout << "Token: " << Identifier << std::endl;
}
void Object::Print(int indent) void Object::Print(int indent)
{ {
indent_loop(indent); indent_loop(indent);
@ -180,18 +234,15 @@ namespace NVL
switch (Value.index()) switch (Value.index())
{ {
case 0: case 0:
std::get<Token>(Value).Print();
break;
case 1:
std::cout << "float: " << std::get<float>(Value) << std::endl; std::cout << "float: " << std::get<float>(Value) << std::endl;
break; break;
case 2: case 1:
std::cout << "string: " << std::get<std::string>(Value) << std::endl; std::cout << "string: " << std::get<std::string>(Value) << std::endl;
break; break;
case 3: case 2:
std::cout << "bool: " << std::get<bool>(Value) << std::endl; std::cout << "bool: " << std::get<bool>(Value) << std::endl;
break; break;
case 4: case 3:
std::cout << "List:" << std::endl; std::cout << "List:" << std::endl;
for (auto& x : std::get<std::vector<Object>>(Value)) for (auto& x : std::get<std::vector<Object>>(Value))
{ {
@ -217,6 +268,8 @@ namespace NVL
{ {
x.Print(indent + 1); x.Print(indent + 1);
} }
indent_loop(indent);
std::cout << "------------------------" << std::endl;
} }
void Tree::Print(int indent) void Tree::Print(int indent)
{ {

View file

@ -10,23 +10,17 @@
namespace NVL namespace NVL
{ {
struct Token
{
std::string Identifier;
void Print();
};
struct Object struct Object
{ {
std::variant< std::variant<
Token,
float, float,
std::string, std::string,
bool, bool,
std::vector<Object> // Implies Object can be an array of other Object std::vector<Object> // Implies Object can be an array of other Object
> Value; > Value;
bool Is_Token = false;
void Print(int indent); void Print(int indent);
}; };
@ -56,16 +50,18 @@ namespace NVL
struct Context { struct Context {
std::vector<std::variant< std::vector<std::variant<
std::shared_ptr<Tree>, std::reference_wrapper<Tree>,
std::shared_ptr<Sequence>, std::reference_wrapper<Sequence>,
std::shared_ptr<Call>, std::reference_wrapper<Call>,
std::shared_ptr<Object> std::reference_wrapper<Object>
>> Scope_Hierarchy; >> Scope_Hierarchy;
}; };
void parse_NVL(Tree& root, std::string path); 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);
} }

View file

@ -1,14 +1,20 @@
dsahd { dsahd {
dasjkhdakjsdasddsmnfdsf dasjkhdakjsdasddsmnfdsf
asdkashjdsad asdkashjdsad
asdasdfdoy893eryh asdasd\\"fdoy893eryh
:awesome: :awesome:
} }
twrgfgdfg { twrgfgdfg {
fsgsfg fsgsfg}
}
tsr4t4t { tsr4t4t
{
dasjkhdakjs dasjkhdakjs
} }
65e
{
afwet4}
asdjnasd{das;ldmad}