mathjslab
Version:
MathJSLab - An interpreter with language syntax like MATLAB®/Octave, ISBN 978-65-00-82338-7.
60 lines (59 loc) • 2.84 kB
TypeScript
import type { NameEntry, NodeBuiltInFunction, NodeFunctionDefinition, NodeInput } from './AST';
import { CharString, Structure } from './AST';
import { FunctionHandle } from './FunctionHandle';
type LookupFunction = NodeBuiltInFunction | NodeFunctionDefinition;
type ResolveFunction = (name: string) => LookupFunction | undefined;
type AliasNameFunction = (name: string) => string;
type UnparseHandle = (handle: FunctionHandle) => string;
type ThrowEvalError = (message: string) => never;
type EvaluateAnonymousHandle = (source: string) => NodeInput;
/**
* Implements function/handle lookup and introspection helpers.
*
* Browser-hosted MathJSLab cannot fully mirror MATLAB/Octave file-system
* lookup, so this module deliberately focuses on in-memory entities registered
* in scopes: variables, user-defined functions, built-ins, function handles,
* and the small runtime class-name set.
*/
declare class FunctionLookup {
/**
* Compute the numeric result of `exist(name, kind)`.
*/
static existCode(name: string, kind: string | undefined, variable: NameEntry | undefined, func: LookupFunction | undefined): number;
/**
* Produce the user-facing result for `which`.
*/
static whichResult(name: string, variable: NameEntry | undefined, func: LookupFunction | undefined, handle: FunctionHandle | undefined, unparseHandle: UnparseHandle): CharString;
/**
* Convert a function handle to its string representation.
*/
static func2str(handle: FunctionHandle, unparseHandle: UnparseHandle): CharString;
/**
* Convert text to a named or anonymous function handle.
*
* Anonymous handles are parsed/evaluated through the supplied callback so
* the interpreter can reuse its normal parser and closure creation logic.
*/
static str2func(sourceText: string, evaluateAnonymousHandle: EvaluateAnonymousHandle, throwEvalError: ThrowEvalError): FunctionHandle;
/**
* Build the structure returned by `functions(handle)`.
*/
static functionsInfo(handle: FunctionHandle, aliasNameFunction: AliasNameFunction, resolveFunction: ResolveFunction, unparseHandle: UnparseHandle): Structure;
/**
* Resolve the function targeted by a named handle.
*
* Handle closures are consulted first so local/nested handles remain bound
* to their lexical function environment.
*/
static resolveHandleFunction(handle: FunctionHandle, name: string, aliasNameFunction: AliasNameFunction, resolveFunction: ResolveFunction): LookupFunction | undefined;
/**
* Runtime class names currently recognized by `exist(name, 'class')`.
*/
private static isRuntimeClassName;
}
export type { LookupFunction };
export { FunctionLookup };
declare const _default: {
FunctionLookup: typeof FunctionLookup;
};
export default _default;