UNPKG

mathjslab

Version:

MathJSLab - An interpreter with language syntax like MATLAB®/Octave, ISBN 978-65-00-82338-7.

40 lines (39 loc) 1.58 kB
import type { NodeInput } from './AST'; import type { Callable as ArityCallable } from './Callable'; type ArityCheckName = 'narginchk' | 'nargoutchk'; 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 { /** * Compute the number of accepted input arguments for a callable. */ static inputArity(callable: ArityCallable): number; /** * Compute the number of produced/requestable output arguments for a callable. */ static outputArity(callable: ArityCallable): number; /** * Validate and convert a `narginchk`/`nargoutchk` bound. */ static countBound(name: ArityCheckName, bound: NodeInput, allowInfinity: boolean, throwSyntaxError: ThrowError): number; /** * Implement the range check shared by `narginchk` and `nargoutchk`. */ 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. */ private static identifierListArity; } export type { ArityCallable, ArityCheckName }; export { FunctionArity }; declare const _default: { FunctionArity: typeof FunctionArity; }; export default _default;