This is not all. You must convince the parser to accept multiple arguments for a function. In the source code of TFPExpressionParser.Primitive you can find a hint on it:
// Determine number of arguments
if Iff then
ACount:=3
else if IfC then
ACount:=-4
else if (ID.IdentifierType in [itFunctionCallBack,itFunctionHandler,itFunctionNode]) then
ACount:=ID.ArgumentCount
else
ACount:=0;
// Parse arguments.
// Negative is for variable number of arguments, where Abs(value) is the minimum number of arguments
If (ACount<>0) then
...
This means that you must somehow make ACount, the count of arguments, a negative value, then everything should work. Unfortunately, the method ArgumentCount returns a positive value:
function TFPExprIdentifierDef.ArgumentCount: Integer;
begin
Result:=Length(FArgumentTypes);
end;
Therefore, you must modify the fpexprpars sources to allow for negative values. I did this for the formula parser of fpspreadsheet. It defines variable parameter count by appending a '+' to the last input type specifier symbol in the AddFunction call for registering external functions to the parser, i.e. in your example:
FParser.Identifiers.AddFunction('mAn', 'F', 'F+', @ExprMin);
The TExprIdentiferDef must be extended by a boolean field FVariableArgumentCount which is set when the '+' is found as last symbol in the AddFunction call and is evaluated when the ArgumentCount is determined:
function TsExprIdentifierDefs.AddFunction(const AName: ShortString;
const AResultType: Char; const AParamTypes: String; const AExcelCode: Integer;
ACallBack: TsExprFunctionEvent): TsExprIdentifierDef;
begin
Result := Add as TsExprIdentifierDef;
Result.Name := AName;
Result.IdentifierType := itFunctionHandler;
Result.ResultType := CharToResultType(AResultType);
//Result.ExcelCode := AExcelCode;
Result.FOnGetValue := ACallBack;
if (Length(AParamTypes) > 0) and (AParamTypes[Length(AParamTypes)]='+') then
begin
Result.ParameterTypes := Copy(AParamTypes, 1, Length(AParamTypes)-1);
Result.VariableArgumentCount := true;
end else
Result.ParameterTypes := AParamTypes;
end;
function TsExprIdentifierDef.ArgumentCount: Integer;
begin
if FVariableArgumentCount then
Result := -Length(FArgumentTypes)
else
Result := Length(FArgumentTypes);
end;
Not sure whether some more changes are required. Please study the source code of fpspreadsheet's fpsexprpars (
https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/fpspreadsheet/source/common/fpsexprparser.pas).
P.S.
Please give your "min" function a more speaking name, e.g. "minvalue" or "minof" instead of "mAn"