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:
parent
6acc61b26f
commit
dc472601bb
2 changed files with 88 additions and 13 deletions
|
@ -34,6 +34,22 @@ namespace Pilang3 {
|
||||||
using SharedFunction = std::shared_ptr<Function>;
|
using SharedFunction = std::shared_ptr<Function>;
|
||||||
using SharedEvaluationWBool = std::tuple<SharedEvaluation, bool>;
|
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 {
|
struct Variable {
|
||||||
enum Type {
|
enum Type {
|
||||||
id_string,
|
id_string,
|
||||||
|
@ -48,7 +64,7 @@ namespace Pilang3 {
|
||||||
id_null [[maybe_unused]]
|
id_null [[maybe_unused]]
|
||||||
} type;
|
} 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;
|
Data data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
83
pilang.cpp
83
pilang.cpp
|
@ -45,8 +45,10 @@ namespace Pilang3 {
|
||||||
Variable thisarg;
|
Variable thisarg;
|
||||||
bool in_command_name = true;
|
bool in_command_name = true;
|
||||||
bool in_string = false;
|
bool in_string = false;
|
||||||
|
bool is_condition = false;
|
||||||
bool newarg = false;
|
bool newarg = false;
|
||||||
bool escapenext = false;
|
bool escapenext = false;
|
||||||
|
condition::array condition_cache;
|
||||||
std::string cache;
|
std::string cache;
|
||||||
for (auto characterit = expression.begin() + tspaces; characterit < expression.end(); characterit++) {
|
for (auto characterit = expression.begin() + tspaces; characterit < expression.end(); characterit++) {
|
||||||
char character = *characterit;
|
char character = *characterit;
|
||||||
|
@ -88,8 +90,9 @@ namespace Pilang3 {
|
||||||
thisarg.type = Variable::id_function;
|
thisarg.type = Variable::id_function;
|
||||||
goto parsechar;
|
goto parsechar;
|
||||||
} else if (character == '!') {
|
} else if (character == '!') {
|
||||||
// Function
|
// Condition
|
||||||
thisarg.type = Variable::id_condition;
|
is_condition = true;
|
||||||
|
thisarg.type = Variable::id_null;
|
||||||
goto parsechar;
|
goto parsechar;
|
||||||
} else {
|
} else {
|
||||||
// Reference
|
// Reference
|
||||||
|
@ -222,20 +225,76 @@ namespace Pilang3 {
|
||||||
thisarg.data = thisfunc;
|
thisarg.data = thisfunc;
|
||||||
newarg = true;
|
newarg = true;
|
||||||
} break;
|
} break;
|
||||||
case Variable::id_condition: {
|
|
||||||
//TODO
|
|
||||||
} break;
|
|
||||||
}
|
}
|
||||||
// Check if argument might be a condition
|
if (not (in_string or newarg)) {
|
||||||
//TODO
|
// 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
|
// Actually end argument if required
|
||||||
if (newarg) {
|
if (newarg) {
|
||||||
arguments.push_back(thisarg);
|
|
||||||
cache.clear();
|
cache.clear();
|
||||||
// Check if end of command was reached
|
if (not is_condition) {
|
||||||
if (character == ';') {
|
arguments.push_back(thisarg);
|
||||||
exprlen = std::distance(expression.begin(), characterit);
|
// Check if end of command was reached
|
||||||
break;
|
if (character == ';') {
|
||||||
|
exprlen = std::distance(expression.begin(), characterit);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue