mathjslab
Version:
MathJSLab - An interpreter with language syntax like MATLAB®/Octave, ISBN 978-65-00-82338-7.
75 lines (74 loc) • 3.1 kB
TypeScript
import type { BuiltInFunctionParameter, BuiltInFunctionParameterValidator, NodeInput } from './AST';
import { ComplexType } from './AST';
interface FunctionParameterValidationSpec {
name?: string;
classes?: string[];
validators?: BuiltInFunctionParameterValidator[];
allowedStrings?: string[];
identifier?: boolean;
allowInfinity?: boolean;
}
/**
* Value validation shared by built-in signatures and `arguments` blocks.
*
* This module is intentionally value-oriented: it does not know how to evaluate
* expressions or resolve variables. Callers provide evaluated `NodeInput`
* values and receive boolean results, making the same validator vocabulary
* usable for native built-ins and MATLAB-like function declarations.
*/
declare class FunctionValidation {
/**
* Return the MATLAB-like runtime class name for a value.
*/
static className(value: NodeInput): string;
/**
* Extract numeric elements from a scalar or numeric array.
*/
static numericElements(value: NodeInput): ComplexType[] | undefined;
/**
* Check whether a value matches a supported class constraint.
*/
static matchesClass(value: NodeInput, className: string): boolean;
/**
* Remove validators implied by more specific validators.
*/
static normalizeValidators(validators?: BuiltInFunctionParameterValidator[]): BuiltInFunctionParameterValidator[];
/**
* Check whether a value can be used as a dimension scalar.
*/
static isDimensionValue(value: NodeInput, allowEmpty: boolean): boolean;
/**
* Check whether a value is a valid dimension vector.
*/
static isDimensionVector(value: NodeInput, allowEmpty: boolean): boolean;
/**
* Check classes, literal allowed strings, identifier syntax, and validators.
*/
static matchesParameter(value: NodeInput, spec: FunctionParameterValidationSpec): boolean;
/**
* Match a built-in parameter before considering alternatives.
*/
static matchesBuiltInParameterBase(value: NodeInput, parameter: BuiltInFunctionParameter): boolean;
/**
* Match a built-in parameter, including alternative parameter shapes.
*/
static matchesBuiltInParameter(value: NodeInput, parameter: BuiltInFunctionParameter): boolean;
/**
* Check an evaluated argument list against declarative built-in parameters.
*/
static argumentsMatchBuiltInParameters(args: NodeInput[], parameters?: BuiltInFunctionParameter[]): boolean;
/**
* Check one low-level validator predicate.
*/
static matchesBuiltInValidator(value: NodeInput, validator: BuiltInFunctionParameterValidator, allowInfinity?: boolean): boolean;
/**
* Map MATLAB `mustBe*` validator names to built-in signature validators.
*/
static builtInValidatorForArgumentValidator(validator: string): BuiltInFunctionParameterValidator | undefined;
}
export type { FunctionParameterValidationSpec };
export { FunctionValidation };
declare const _default: {
FunctionValidation: typeof FunctionValidation;
};
export default _default;