mathjslab
Version:
MathJSLab - An interpreter with language syntax like MATLAB®/Octave, ISBN 978-65-00-82338-7.
177 lines (176 loc) • 5.59 kB
TypeScript
import { Complex } from './Complex';
/**
* Single quote string character type.
*/
type SingleQuoteCharacter = "'";
/**
* Single quote string character literal.
*/
declare const singleQuoteCharacter: SingleQuoteCharacter;
/**
* Double quote string character type.
*/
type DoubleQuoteCharacter = '"';
/**
* Double quote string character literal.
*/
declare const doubleQuoteCharacter: DoubleQuoteCharacter;
/**
* String quote character type.
*/
type StringQuoteCharacter = SingleQuoteCharacter | DoubleQuoteCharacter;
/**
* Type number for `CharString` node.
*/
declare const stringClass = 3;
/**
* Runtime string value used by the AST and interpreter.
*
* `CharString` preserves the source quote style when the parser knows it, but
* semantic operations treat `str` as the canonical value. Truthiness follows
* MATLAB/Octave-like string behavior: empty strings are false and non-empty
* strings are true.
*/
declare class CharString {
/**
* String value property.
*/
str: string;
/**
* Type of string quote (single or double).
*/
quote: StringQuoteCharacter;
/**
* String class type number.
*/
static readonly STRING = 3;
/**
* String class type property.
*/
type: number;
/**
* Parent node.
*/
parent: any;
/**
* `CharString` constructor.
* @param str Runtime string value.
* @param quote Source quote style to preserve when unparsing.
*/
constructor(str: string, quote?: StringQuoteCharacter);
/**
* Creates a `CharString` instance.
* @param str String value.
* @param quote Quote character.
* @returns A new `CharString` instance.
*/
static readonly create: (str: string, quote?: StringQuoteCharacter) => CharString;
/**
* Test if an object is a instance of `CharString`.
* @param value Object to test.
* @returns `true` if `obj` is an instance of `CharString`. `false` otherwise.
*/
static readonly isInstanceOf: (obj: unknown) => obj is CharString;
/**
* Creates a copy of `CharString` `value`.
* @param value `CharString` to copy.
* @returns A copy of `value`.
*/
static readonly copy: (value: CharString) => CharString;
/**
* Creates a copy of `CharString` instance.
* @returns A copy of `this` `CharString`.
*/
copy(): CharString;
/**
* Parse a raw string token into a `CharString`.
*
* The current parser already supplies the decoded string content, so this
* helper simply wraps it with the default double-quote style.
*
* @param str Decoded string content.
* @returns Parsed `CharString`.
*/
static readonly parse: (str: string) => CharString;
/**
* Render the string as source text without adding quotes.
*
* `parentPrecedence` is accepted for compatibility with other unparse
* helpers; string rendering does not need precedence.
*
* @param value String value to render.
* @param parentPrecedence Parent operator precedence, unused.
* @returns Raw string content.
*/
static readonly unparse: (value: CharString, parentPrecedence?: number) => string;
/**
* Convert a `CharString` to its runtime string value.
*
* @param value String wrapper.
* @returns Raw string content.
*/
static readonly toString: (value: CharString) => string;
/**
* Convert this instance to its runtime string value.
*
* @returns Raw string content.
*/
toString(): string;
/**
* Render the string as a double-quoted escaped source literal.
*
* The escaping mirrors MATLAB/Octave double-quote conventions used by the
* rest of the unparsing pipeline.
*
* @param value String wrapper.
* @returns Escaped source literal.
*/
static readonly unparseEscaped: (value: CharString) => string;
/**
* Render the string as MathML.
*
* `parentPrecedence` is accepted for compatibility with other MathML
* helpers; string rendering does not need precedence.
*
* @param value String value to render.
* @param parentPrecedence Parent operator precedence, unused.
* @returns MathML fragment.
*/
static readonly unparseMathML: (value: CharString, parentPrecedence?: number) => string;
/**
* Render the string as an escaped MathML literal.
*
* @param value String value to render.
* @returns MathML fragment containing a quoted escaped string.
*/
static readonly unparseEscapedMathML: (value: CharString) => string;
/**
* Convert a string to a logical complex scalar.
*
* @param value String wrapper.
* @returns `true` for non-empty strings, `false` for empty strings.
*/
static readonly logical: (value: CharString) => Complex;
/**
* Alias for `logical` used by the common element interface.
*
* @param value String wrapper.
* @returns Logical complex scalar.
*/
static readonly toLogical: (value: CharString) => Complex;
/**
* Convert this instance to a logical complex scalar.
*
* @returns Logical complex scalar.
*/
toLogical(): Complex;
}
export type { SingleQuoteCharacter, DoubleQuoteCharacter, StringQuoteCharacter };
export { singleQuoteCharacter, doubleQuoteCharacter, stringClass, CharString };
declare const _default: {
singleQuoteCharacter: "'";
doubleQuoteCharacter: "\"";
stringClass: number;
CharString: typeof CharString;
};
export default _default;