mathjslab
Version:
MathJSLab - An interpreter with language syntax like MATLAB®/Octave, ISBN 978-65-00-82338-7.
68 lines (67 loc) • 2.73 kB
TypeScript
import type { NodeInput } from './AST';
import type { Callable as ArityCallable } from './Callable';
type ArityCheckName = 'nargchk' | 'narginchk' | 'nargoutchk';
/** Error callback used by arity helpers. */
type ThrowError = (message: string) => never;
/**
* Implements arity introspection and arity-check helper built-ins.
*
* The returned arity convention follows MATLAB/Octave-style `nargin(fun)` and
* `nargout(fun)`: fixed arity is nonnegative, while variadic signatures are
* negative and encode the position of `varargin`/`varargout`.
*/
declare class FunctionArity {
/**
* Validate arity metadata that should already be guaranteed by AST factories.
*/
private static checkedList;
/**
* Compute the number of accepted input arguments for a callable.
*
* @param callable Callable to inspect.
* @returns Fixed arity or negative variadic arity.
*/
static inputArity(callable: ArityCallable): number;
/**
* Compute the number of produced/requestable output arguments for a callable.
*
* @param callable Callable to inspect.
* @returns Fixed arity or negative variadic arity.
*/
static outputArity(callable: ArityCallable): number;
/**
* Validate and convert a `nargchk`/`narginchk`/`nargoutchk` bound.
*
* @param name Built-in name used in diagnostics.
* @param bound Evaluated bound value.
* @param allowInfinity Whether positive infinity is accepted.
* @param throwSyntaxError Syntax-error callback.
* @returns Numeric bound.
*/
static countBound(name: ArityCheckName, bound: NodeInput, allowInfinity: boolean, throwSyntaxError: ThrowError): number;
/**
* Implement the range check shared by `narginchk` and `nargoutchk`.
*
* @param name Built-in name used in diagnostics.
* @param min Minimum bound value.
* @param max Maximum bound value.
* @param count Actual argument count.
* @param throwSyntaxError Syntax-error callback.
* @param throwEvalError Evaluation-error callback.
*/
static checkFunctionCount(name: ArityCheckName, min: NodeInput, max: NodeInput, count: number, throwSyntaxError: ThrowError, throwEvalError: ThrowError): void;
/**
* Convert an identifier list to the fixed/variadic arity convention.
*
* @param items Parameter or return-name nodes.
* @param variadicName Expected trailing variadic identifier.
* @returns Fixed list length or negative variadic position.
*/
private static identifierListArity;
}
export type { ArityCallable, ArityCheckName };
export { FunctionArity };
declare const _default: {
FunctionArity: typeof FunctionArity;
};
export default _default;