improved syntax checking on expr. Laid foundation for expr function.

This commit is contained in:
Brad Arant 2024-11-18 10:19:39 -08:00
parent 839f7e2eb8
commit c39220d39c
3 changed files with 20 additions and 5 deletions

View File

@ -53,7 +53,16 @@ namespace jet {
} else
throw coreutils::Exception("Expecting ) at end of LEFT expression.");
} else if(in.ifNextIgnoreCase("EXPR")) {
if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for LEFT parameters.");
Operand parm1(in, global, lvariables);
if(in.ifNext(")")) {
Operand op(in, global, lvariables);
string = op.string;
isNumber = op.isNumber;
boolean = op.boolean;
} else
throw coreutils::Exception("Expecting ) at end of EXPR expression.");
} else if(in.ifNextIgnoreCase("RIGHT")) {
} else if(in.ifNextIgnoreCase("TRIM")) {
@ -90,7 +99,8 @@ namespace jet {
string = in.getTokenExclude("'");
in.ifNext("'");
isNumber = false;
}
} else
throw coreutils::Exception("operand is not valid.");
in.skipWhitespace();
@ -284,7 +294,6 @@ namespace jet {
throw coreutils::Exception("operand is not a number.");
} else
return;
}
}

6
tests/testexpr.jet Executable file
View File

@ -0,0 +1,6 @@
#!../jet-2.0
<jet name1="localname" filterblanklines="true" trimlines="true">
<set name="test1" value="5 + 5" />
<set name="test2" expr="expr($[test1])" />
$[test2]
</jet>