1
0
Fork 0
mirror of https://gitlab.com/niansa/pilang3.git synced 2025-03-06 20:49:20 +01:00

Implemented just the very basics of conditions

This commit is contained in:
niansa 2021-03-10 10:03:48 +01:00
parent 6acc61b26f
commit dc472601bb
2 changed files with 88 additions and 13 deletions

View file

@ -34,6 +34,22 @@ namespace Pilang3 {
using SharedFunction = std::shared_ptr<Function>;
using SharedEvaluationWBool = std::tuple<SharedEvaluation, bool>;
namespace condition {
enum type {
_none,
equals,
not_equals,
biggerthan,
smallerthan,
biggerthanorequals,
smallerthanorequals,
ncpp_and,
ncpp_or,
_end
};
using array = std::vector<Variable*>;
}
struct Variable {
enum Type {
id_string,
@ -48,7 +64,7 @@ namespace Pilang3 {
id_null [[maybe_unused]]
} type;
using Data = std::variant<std::string, integer_type, SharedVariable, SharedEvaluationWBool, SharedFunction, Type>;
using Data = std::variant<std::string, integer_type, SharedVariable, SharedEvaluationWBool, SharedFunction, condition::array, Type>;
Data data;
};

View file

@ -45,8 +45,10 @@ namespace Pilang3 {
Variable thisarg;
bool in_command_name = true;
bool in_string = false;
bool is_condition = false;
bool newarg = false;
bool escapenext = false;
condition::array condition_cache;
std::string cache;
for (auto characterit = expression.begin() + tspaces; characterit < expression.end(); characterit++) {
char character = *characterit;
@ -88,8 +90,9 @@ namespace Pilang3 {
thisarg.type = Variable::id_function;
goto parsechar;
} else if (character == '!') {
// Function
thisarg.type = Variable::id_condition;
// Condition
is_condition = true;
thisarg.type = Variable::id_null;
goto parsechar;
} else {
// Reference
@ -222,20 +225,76 @@ namespace Pilang3 {
thisarg.data = thisfunc;
newarg = true;
} break;
case Variable::id_condition: {
//TODO
} break;
}
// Check if argument might be a condition
//TODO
if (not (in_string or newarg)) {
// Check if argument might be a condition
if (character == '!' or character == '=') {
is_condition = true;
}
// Continue building condition
if (is_condition) {
uint64_t cond_extends = condition::_none;
// Equals
if (character == '=' and *(characterit + 1) == '=') {
cond_extends = condition::equals;
}
// Not equals
else if (character == '!' and *(characterit + 1) == '=') {
cond_extends = condition::not_equals;
}
// Bigger than or equals
else if (character == '>' and *(characterit + 1) == '=') {
cond_extends = condition::biggerthanorequals;
}
// Smaller than or equals
else if (character == '<' and *(characterit + 1) == '=') {
cond_extends = condition::smallerthanorequals;
}
// Bigger than
else if (character == '>') {
cond_extends = condition::biggerthan;
}
// Smaller than
else if (character == '<') {
cond_extends = condition::smallerthan;
}
// And
else if (character == '&' and *(characterit + 1) == '&') {
cond_extends = condition::ncpp_and;
}
// Or
else if (character == '|' and *(characterit + 1) == '|') {
cond_extends = condition::ncpp_or;
}
// Extend
if (cond_extends != condition::_none) {
condition_cache.push_back(new Variable(thisarg));
condition_cache.push_back(reinterpret_cast<Variable*>(cond_extends));
newarg = true;
// Note: some conditional strings have just one character
if (cond_extends != condition::biggerthan and cond_extends != condition::smallerthan) {
characterit += 1;
}
}
}
} else if (newarg and is_condition) {
// End condition
condition_cache.push_back(new Variable(thisarg));
is_condition = false;
thisarg.type = Variable::id_condition;
thisarg.data = condition_cache;
condition_cache.clear();
}
// Actually end argument if required
if (newarg) {
arguments.push_back(thisarg);
cache.clear();
// Check if end of command was reached
if (character == ';') {
exprlen = std::distance(expression.begin(), characterit);
break;
if (not is_condition) {
arguments.push_back(thisarg);
// Check if end of command was reached
if (character == ';') {
exprlen = std::distance(expression.begin(), characterit);
break;
}
}
}
}