diff --git a/firmware/controllers/core/logic_expression.cpp b/firmware/controllers/core/logic_expression.cpp index 66042aae42..2f1be543bc 100644 --- a/firmware/controllers/core/logic_expression.cpp +++ b/firmware/controllers/core/logic_expression.cpp @@ -8,6 +8,27 @@ #include "main.h" #include "logic_expression.h" +LENameOrdinalPair * LE_FIRST = NULL; + +/** + * the main point of these static fields is that their constructor would register + * them in the magic list of operator name/ordinal pairs + */ +static LENameOrdinalPair leAnd(LE_OPERATOR_AND, "and"); +static LENameOrdinalPair leOr(LE_OPERATOR_OR, "or"); +static LENameOrdinalPair leMore(LE_OPERATOR_MORE, ">"); +static LENameOrdinalPair leMoreOrEqual(LE_OPERATOR_MORE_OR_EQUAL, ">="); + +LENameOrdinalPair::LENameOrdinalPair(le_action_e action, const char *name) { + this->next = NULL; + this->action = action; + this->name = name; + if (LE_FIRST != NULL) { + LE_FIRST->next = this; + } + LE_FIRST = this; +} + LEElement::LEElement() { action = LE_UNDEFINED; next = NULL; @@ -156,10 +177,12 @@ const char *processToken(const char *line, char *buffer) { } le_action_e parseAction(const char * line) { - if (strEqualCaseInsensitive("or", line)) { - return LE_OPERATOR_OR; - } else if (strEqualCaseInsensitive("AND", line)) { - return LE_OPERATOR_AND; + LENameOrdinalPair *pair = LE_FIRST; + while (pair != NULL) { + if (strEqualCaseInsensitive(pair->name, line)) { +// return pair->action; + } + pair = pair->next; } return LE_UNDEFINED; } diff --git a/firmware/controllers/core/logic_expression.h b/firmware/controllers/core/logic_expression.h index bfde1c1693..185d2f60dd 100644 --- a/firmware/controllers/core/logic_expression.h +++ b/firmware/controllers/core/logic_expression.h @@ -72,6 +72,15 @@ private: FLStack stack; }; +class LENameOrdinalPair { +public: + LENameOrdinalPair(le_action_e action, const char *name); + LENameOrdinalPair *next; + le_action_e action; + const char *name; +}; + + const char *processToken(const char *line, char *buffer); bool isNumeric(const char* line); le_action_e parseAction(const char * line);