mathjslab
Version:
MathJSLab - An interpreter with language syntax like MATLAB®/Octave, ISBN 978-65-00-82338-7.
242 lines (241 loc) • 10.3 kB
TypeScript
import type { ClassAttributeTable, ExpressionBoundaryValue, NodeClassAttribute, NodeClassEnumeration, NodeClassEvent, NodeClassProperty, NodeClassSection, NodeExpr, NodeFunctionDefinition, NodeInput } from './AST';
/**
* Access specifier stored in class member metadata.
*
* MATLAB accepts named levels such as `public`, `protected`, `private`, and
* class-qualified access lists. The runtime stores the parsed value as text and
* lets the interpreter decide which forms it can enforce.
*/
type ClassAccess = string;
/**
* Runtime metadata for a property declared in a `properties` block.
*/
interface ClassPropertyDefinition<OWNER = unknown> {
/** Property name as declared in the classdef block. */
name: string;
/** AST node that originated the property declaration. */
node: NodeClassProperty;
/** Default value expression, when one was declared. */
defaultValue: NodeExpr | null;
/** Literal/symbolic size declaration from the property validation syntax. */
size: ExpressionBoundaryValue[];
/** Class declaration from the property validation syntax. */
class: NodeInput | null;
/** Validator function declarations from the property validation syntax. */
functions: ExpressionBoundaryValue[];
/** Containing `properties` section. */
section: NodeClassSection;
/** Duplicate-preserving attribute table inherited from the section. */
attributes: ClassAttributeTable;
/** Effective read/write access when no specific accessor rule is present. */
access: ClassAccess;
/** Effective getter access. */
getAccess: ClassAccess;
/** Effective setter access. */
setAccess: ClassAccess;
/** Explicit getter method declared with the `GetMethod` attribute. */
getMethodName: string | null;
/** Explicit setter method declared with the `SetMethod` attribute. */
setMethodName: string | null;
/** Whether the property was declared with `Constant`. */
isConstant: boolean;
/** Whether the property was declared with `Dependent`. */
isDependent: boolean;
/** Whether the property was declared with `Abstract`. */
isAbstract: boolean;
/** Whether the property was declared with `Hidden`. */
isHidden: boolean;
/** Whether the property was declared with `Transient`. */
isTransient: boolean;
/** Whether the property was declared with `NonCopyable`. */
isNonCopyable: boolean;
/** Whether reads should raise observable get events. */
isGetObservable: boolean;
/** Whether writes should raise observable set events. */
isSetObservable: boolean;
/** Whether repeated equal assignments may be skipped. */
isAbortSet: boolean;
/** Relative priority for partial property-name matching. */
partialMatchPriority: number;
/** Class that owns the property metadata. */
classDefinition: OWNER;
}
/**
* Runtime metadata for a method declared in a `methods` block.
*/
interface ClassMethodDefinition<OWNER = unknown> {
/** Method name, including qualified names preserved by the parser. */
name: string;
/** Function-definition AST node for the method body or prototype. */
node: NodeFunctionDefinition;
/** Containing `methods` section. */
section: NodeClassSection;
/** Duplicate-preserving attribute table inherited from the section. */
attributes: ClassAttributeTable;
/** Effective method access. */
access: ClassAccess;
/** Whether the method was declared in a `Static` section. */
isStatic: boolean;
/** Whether the method is abstract or prototype-only. */
isAbstract: boolean;
/** Whether subclasses may override this method. */
isSealed: boolean;
/** Whether the method was declared with `Hidden`. */
isHidden: boolean;
/** Class that owns the method metadata. */
classDefinition: OWNER;
}
/**
* Runtime metadata for an event declared in an `events` block.
*/
interface ClassEventDefinition<OWNER = unknown> {
/** Event name as declared in the classdef block. */
name: string;
/** AST node that originated the event declaration. */
node: NodeClassEvent;
/** Containing `events` section. */
section: NodeClassSection;
/** Duplicate-preserving attribute table inherited from the section. */
attributes: ClassAttributeTable;
/** Effective event access. */
access: ClassAccess;
/** Effective listener registration access. */
listenAccess: ClassAccess;
/** Effective event notification access. */
notifyAccess: ClassAccess;
/** Whether the event was declared with `Hidden`. */
isHidden: boolean;
/** Class that owns the event metadata. */
classDefinition: OWNER;
}
/**
* Runtime metadata for an enumeration member declared in an `enumeration` block.
*/
interface ClassEnumerationDefinition<OWNER = unknown> {
/** Enumeration member name. */
name: string;
/** AST node that originated the enumeration member. */
node: NodeClassEnumeration;
/** Constructor-like arguments attached to the enumeration member. */
args: ExpressionBoundaryValue[];
/** Containing `enumeration` section. */
section: NodeClassSection;
/** Duplicate-preserving attribute table inherited from the section. */
attributes: ClassAttributeTable;
/** Whether the enumeration member was declared in a `Hidden` section. */
isHidden: boolean;
/** Class that owns the enumeration metadata. */
classDefinition: OWNER;
}
/**
* Shared helpers for interpreting `classdef` member attributes.
*/
declare class ClassMember {
/** Default MATLAB/Octave member access when no attribute overrides it. */
static readonly defaultAccess = "public";
/**
* Test whether a parsed attribute value is a metaclass literal.
*
* @param value Value to test.
* @returns `true` when the value is a `?ClassName` AST node.
*/
private static readonly isMetaClassNode;
/**
* Test whether a parsed attribute value is a negated attribute marker.
*
* @param value Value to test.
* @returns `true` for parser nodes produced by `~Attribute` or `!Attribute`.
*/
private static readonly isNegatedAttributeNode;
/**
* Convert a class-name-like AST value to a class name.
*
* @param value Value to convert.
* @returns Class name, if recognized.
*/
private static readonly classNameValue;
/**
* Test whether an attribute table contains at least one entry with a name.
*
* @param table Attribute table produced by the AST layer.
* @param name Attribute name to test.
* @returns `true` when the effective attribute value is true.
*/
static readonly hasAttribute: (table: ClassAttributeTable, name: string) => boolean;
/**
* Resolve an attribute as a boolean marker when possible.
*
* @param attribute Attribute node to read.
* @returns Effective boolean value, or `null` when the attribute is absent
* or has a non-boolean value.
*/
static readonly attributeBooleanValue: (attribute: NodeClassAttribute | undefined) => boolean | null;
/**
* Test whether an effective access string is supported by the runtime.
*
* @param access Access value to test.
* @returns `true` for named access levels or class-qualified friend lists.
*/
static readonly isSupportedAccess: (access: string) => boolean;
/**
* Convert a class attribute value node into the textual value used by the
* runtime metadata layer.
*
* @param attribute Attribute node to read.
* @returns Identifier/string value, or `null` for marker attributes.
*/
static readonly attributeValue: (attribute: NodeClassAttribute | undefined) => string | null;
/**
* Resolve an attribute value as a class-name list.
*
* MATLAB-like class attributes such as `InferiorClasses` and
* `AllowedSubclasses` accept class names or cell arrays of class-name-like
* entries. The runtime stores those names as strings.
*
* @param attribute Attribute node to read.
* @returns Class names, or `null` when the attribute is absent or invalid.
*/
static readonly classNameListFromAttribute: (attribute: NodeClassAttribute | undefined) => string[] | null;
/**
* Resolve an attribute value as a positive integer.
*
* MATLAB property metadata uses this shape for `PartialMatchPriority`.
*
* @param attribute Attribute node to read.
* @returns Positive integer value, or `null` when absent or invalid.
*/
static readonly positiveIntegerFromAttribute: (attribute: NodeClassAttribute | undefined) => number | null;
/**
* Resolve an access-like attribute with a fallback value.
*
* @param table Attribute table to inspect.
* @param name Attribute name, usually `Access`, `GetAccess`, or
* `SetAccess`.
* @param fallback Value used when the attribute is absent.
* @returns Effective access specifier.
*/
static readonly accessFromAttributes: (table: ClassAttributeTable, name?: string, fallback?: string) => ClassAccess;
/**
* Resolve a property accessor method attribute.
*
* @param table Attribute table to inspect.
* @param name Attribute name, usually `GetMethod` or `SetMethod`.
* @returns Method name, or `null` when the attribute is absent or invalid.
*/
static readonly methodNameFromAttribute: (table: ClassAttributeTable, name: "GetMethod" | "SetMethod") => string | null;
/**
* Validate a parsed access-like attribute before class registration.
*
* @param table Attribute table to inspect.
* @param name Attribute name to validate.
* @param owner Description used in error messages.
* @param throwEvalError Interpreter error callback.
*/
static readonly validateAccessAttribute: (table: ClassAttributeTable, name: string, owner: string, throwEvalError: (message: string) => never) => void;
}
export type { ClassAccess, ClassPropertyDefinition, ClassMethodDefinition, ClassEventDefinition, ClassEnumerationDefinition };
export { ClassMember };
declare const _default: {
ClassMember: typeof ClassMember;
};
export default _default;