working tree thing

This commit is contained in:
lachrymaL 2021-05-14 23:17:55 -04:00
parent e2e7d8ed13
commit 73b9f4c81d
No known key found for this signature in database
GPG key ID: F3640ACFA174B1C1
6 changed files with 93 additions and 52 deletions

View file

@ -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": "",

View file

@ -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,7 +97,7 @@ namespace {
namespace NVL
{
template <bool is_parent_call, bool is_token>
template <bool is_parent_call, bool is_symbol>
void parse_Object(Context parent_context, std::ifstream& nvl)
{
Object this_object;
@ -102,24 +110,25 @@ namespace NVL
std::streampos end; // unused if object is not scoped
std::variant<std::string, std::vector<Object>> content;
std::variant<std::string, std::vector<Object>> content = "";
char c{};
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<std::streampos>(1))
{
parse_Object<false, false>(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<std::streampos>(1))
{
@ -127,26 +136,53 @@ namespace NVL
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))
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);
try
{
this_object.Value = std::stof(std::get<std::string>(content));
}
catch (std::exception)
{
if (std::get<std::string>(content) == "true")
{
this_object.Value = true;
}
else if (std::get<std::string>(content) == "false") {
this_object.Value = false;
}
else
{
this_object.Value = std::get<std::string>(content);
}
}
break;
}
this_object.Is_Token = is_token;
this_object.Is_Symbol = is_symbol;
nvl >> std::ws;
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);
else if ((std::get<std::reference_wrapper<Object>>(parent_context.Scope_Hierarchy.back())).get().Value.index() == 4) { // 4 for list
;
std::get<std::vector<Object>>((std::get<std::reference_wrapper<Object>>(parent_context.Scope_Hierarchy.back())).get().Value).push_back(this_object);
}
else {
;
(std::get<std::reference_wrapper<Object>>(parent_context.Scope_Hierarchy.back())).get().Value = std::vector<Object> { this_object };
}
}
@ -234,21 +270,30 @@ namespace NVL
switch (Value.index())
{
case 0:
std::cout << "float: " << std::get<float>(Value) << std::endl;
std::cout << "Nil" << std::endl;
break;
case 1:
std::cout << "string: " << std::get<std::string>(Value) << std::endl;
std::cout << "float: " << std::get<float>(Value) << std::endl;
break;
case 2:
std::cout << "bool: " << std::get<bool>(Value) << std::endl;
if (Is_Symbol)
std::cout << "symbol: " << std::get<std::string>(Value) << std::endl;
else
std::cout << "string: " << std::get<std::string>(Value) << std::endl;
break;
case 3:
std::cout << "bool: " << std::boolalpha << std::get<bool>(Value) << std::endl;
break;
case 4:
std::cout << "List:" << std::endl;
for (auto& x : std::get<std::vector<Object>>(Value))
{
x.Print(indent + 1);
}
break;
case 5:
std::cout << "Nil" << std::endl;
break;
}
}
void Call::Print(int indent)

View file

@ -10,19 +10,24 @@
namespace NVL
{
struct Nil
{
};
struct Object
{
std::variant<
std::monostate,
float,
std::string,
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
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 <bool is_parent_call, bool is_symbol>
void parse_Object(Context parent_context, std::ifstream& nvl);
}

View file

@ -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);

View file

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

10
test.nvl Normal file
View file

@ -0,0 +1,10 @@
mmawesome
{
mmawesome mmaji awesome asduhjaiodhj kl;d 3434.3434 true false
}
dasijhdoisaj {}
uihf98 {
dasdj [39439048 jidjao] [] [] [] [[][[][[[[[] hi [2323 d]]]]]]]
}