diff --git a/source/script/args.c b/source/script/args.c index e4a26f4..0d8a5ff 100644 --- a/source/script/args.c +++ b/source/script/args.c @@ -344,6 +344,36 @@ Variable_t solveEquation(scriptCtx_t* ctx, lexarToken_t* tokens, u32 len, u8 sho } } } + else if (res.varType == StringType && val.varType == IntType){ + if (localOpToken == Minus){ + u32 resLen = strlen(res.stringType); + if (resLen < val.integerType) + return ErrValue(ERRSYNTAX); + + char *temp = malloc(resLen - val.integerType + 1); + memcpy(temp, res.stringType, resLen - val.integerType); + temp[resLen - val.integerType] = 0; + + freeVariable(res); + res.stringType = temp; + res.free = 1; + } + ELIFT(Selector){ + u32 resLen = strlen(res.stringType); + if (resLen < val.integerType) + return ErrValue(ERRSYNTAX); + + char *temp = malloc(resLen - val.integerType + 1); + memcpy(temp, res.stringType + val.integerType, resLen - val.integerType); + temp[resLen - val.integerType] = 0; + + freeVariable(res); + res.stringType = temp; + res.free = 1; + } + else + return ErrValue(ERRBADOPERATOR); + } else return ErrValue(ERRBADOPERATOR); } @@ -351,7 +381,7 @@ Variable_t solveEquation(scriptCtx_t* ctx, lexarToken_t* tokens, u32 len, u8 sho res = val; } } - else if (tokens[i].token >= Plus && tokens[i].token <= OR) { + else if (tokens[i].token >= Plus && tokens[i].token <= Selector) { lastToken = tokens[i].token; } } diff --git a/source/script/lexer.c b/source/script/lexer.c index f2bd685..bb9bf7c 100644 --- a/source/script/lexer.c +++ b/source/script/lexer.c @@ -39,6 +39,7 @@ lexarTranslation_t lexarTranslations[] = { {'<', Smaller}, {'>', Bigger}, {'!', Not}, + {':', Selector}, {')', RBracket}, {']', RSBracket}, {'(', LBracket}, diff --git a/source/script/types.h b/source/script/types.h index 0372ebc..8c3f3f4 100644 --- a/source/script/types.h +++ b/source/script/types.h @@ -37,6 +37,7 @@ enum Tokens { RSBracket, AND, OR, + Selector, EquationSeperator, };