UNPKG

mathjslab

Version:

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

65 lines (64 loc) 2.74 kB
import type { ExpressionBoundaryValue, NodeInput } from './AST'; import { CharString } from './CharString'; type DiagnosticFunctionName = 'warning' | 'error'; type DiagnosticMessageCallbacks = { expressionValue(value: unknown, name: string): ExpressionBoundaryValue; unparse(value: NodeInput): string; throwEvalError(message: string): never; }; type DiagnosticMessageParts = { identifier: string; message: string; }; /** * Shared formatting helpers for MATLAB/Octave-style diagnostic functions. * * `warning` and `error` both accept message-only forms, identifier/message * forms, and `sprintf`-style formatting arguments. This module keeps that * policy outside `Interpreter` while still delegating value validation and * rendering back to the active runtime. */ declare class DiagnosticMessage { /** * Convert one formatting argument to inserted text. * * @param value Evaluated formatting argument. * @param specifier Conversion specifier. * @param callbacks Runtime callbacks for value validation and display. * @returns Text inserted into the diagnostic message. */ private static formatArgument; /** * Apply the supported diagnostic formatting subset. * * Supported conversions are `%s`, `%d`, `%i`, `%f`, `%g`, and `%%`. * Width/precision flags are recognized enough to find the conversion; * precision currently affects `%f`. * * @param format Diagnostic format string. * @param values Evaluated values inserted into the format string. * @param callbacks Runtime callbacks for validation and display. * @returns Formatted diagnostic message. */ static format(format: string, values: NodeInput[], callbacks: DiagnosticMessageCallbacks): string; /** * Split diagnostic arguments into optional identifier, message, and values. * * A leading string containing `:` is treated as a message identifier when a * second string is present. Otherwise the first string is the message * format. * * @param args Evaluated diagnostic arguments. * @param functionName Built-in name used in diagnostics. * @param charArgument Runtime character-string validator. * @param callbacks Runtime callbacks for formatting. * @returns Identifier/message pair. */ static parts(args: NodeInput[], functionName: DiagnosticFunctionName, charArgument: (value: unknown, name: string) => CharString, callbacks: DiagnosticMessageCallbacks): DiagnosticMessageParts; } export type { DiagnosticMessageCallbacks, DiagnosticMessageParts }; export { DiagnosticMessage }; declare const _default: { DiagnosticMessage: typeof DiagnosticMessage; }; export default _default;