Implement reverse(str) and concat(a, b, ...) in the expr engine

Both matched their function name but had empty branch bodies, silently
producing nothing regardless of arguments. reverse(str) follows the same
single-argument shape as trim/toupper/tolower; concat(a, b, ...) follows
the same variadic comma-separated shape as max/min.

reverse() converts to std::string and reverses in place via the already-
imported <algorithm> (std::reverse), then assigns back through MString's
std::string constructor. concat() starts from the first argument and
appends each subsequent one via MString's own operator<<(ZString).

Verified via real jet-2.0 runs: reverse('hello') -> "olleh",
concat('a','b','c') -> "abc", concat('x','y') -> "xy". Full 9-script
regression suite (custom tag scoping, dump tag tree, try/catch, if/else,
keyword sigil) still passes unchanged.
This commit is contained in:
Brad Arant committed 2026-08-26 10:45:43 -07:00
1 parent 97142ce9b4
commit 5c703f5620
1 file changed
+19 -2
+19 -2
View File
@@ -124,9 +124,26 @@ namespace jet {
} else } else
throw coreutils::Exception("Expecting ) at end of TOLOWER expression."); throw coreutils::Exception("Expecting ) at end of TOLOWER expression.");
} else if(in.ifNextIgnoreCase("REVERSE")) { } else if(in.ifNextIgnoreCase("REVERSE")) {
if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for REVERSE parameters.");
Operand parm1(in, tag);
if(in.ifNext(")")) {
std::string reversed = parm1.string.str();
std::reverse(reversed.begin(), reversed.end());
string = reversed;
} else
throw coreutils::Exception("Expecting ) at end of REVERSE expression.");
} else if(in.ifNextIgnoreCase("CONCAT")) { } else if(in.ifNextIgnoreCase("CONCAT")) {
if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for CONCAT parameters.");
Operand parm1(in, tag);
string = parm1.string;
while(in.ifNext(",")) {
Operand parm(in, tag);
string << parm.string;
}
if(!in.ifNext(")"))
throw coreutils::Exception("Expecting ) at end of CONCAT expression.");
} else if(in.ifNextIgnoreCase("INTEGER")) { } else if(in.ifNextIgnoreCase("INTEGER")) {
if(!in.ifNext("(")) if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for INTEGER parameters."); throw coreutils::Exception("Expecting ( for INTEGER parameters.");