@zsnout/ithkuil
Version:
A set of tools which can generate and parse romanized Ithkuil text and which can generate Ithkuil script from text and JSON data.
172 lines (171 loc) • 5.42 kB
TypeScript
/** A generic part of a regular expression. */
export declare class RegexPart {
/** The source text for this RegexPart. */
readonly source: string;
constructor(
/** The source text for this RegexPart. */
source: string);
/**
* Creates a new RegexPart matching the contents of this one in a capture
* group.
*
* @returns The new RegexPart.
*/
asGroup(): AtomicRegexPart;
/**
* Creates a new RegexPart matching the contents of this one in a named
* capture group.
*
* @returns The new RegexPart.
*/
asNamedGroup(name: string): AtomicRegexPart;
/**
* Creates a new RegexPart that matches the same content as this one, but is
* optional.
*
* @returns The new RegexPart.
*/
optional(): RegexPart;
/**
* Creates a new RegexPart that matches zero or more repetitions of this
* pattern.
*
* @returns The new RegexPart.
*/
zeroOrMore(): RegexPart;
/**
* Creates a new RegexPart that matches one or more repetitions of this
* pattern.
*
* @returns The new RegexPart.
*/
oneOrMore(): RegexPart;
/**
* Creates a new RegexPart that matches this part's content, but only if it
* will match the entire source string.
*
* @returns The new RegexPart.
*/
matchEntireText(): RegexPart;
/**
* Creates a new RegexPart that is a negative lookahead that prevents the
* future text from matching the current pattern.
*
* @returns The new RegexPart.
*/
not(): AtomicRegexPart;
/**
* Creates a regular expression matching the contents of this RegexPart.
*
* @param flags The flags to compile with.
* @returns A regular expression.
*/
compile(flags?: string): RegExp;
/**
* Gets the source text of this RegexPart.
*
* @returns The source text of this RegexPart.
*/
toString(): string;
}
/**
* A subclass of `RegexPart` used for atomic matchers such as single characters,
* character classes, groups, and so on.
*/
export declare class AtomicRegexPart extends RegexPart {
/**
* Creates a new RegexPart that matches the same content as this one, but is
* optional.
*
* @returns The new RegexPart.
*/
optional(): RegexPart;
/**
* Creates a new RegexPart that matches zero or more repetitions of this
* pattern.
*
* @returns The new RegexPart.
*/
zeroOrMore(): RegexPart;
/**
* Creates a new RegexPart that matches one or more repetitions of this
* pattern.
*
* @returns The new RegexPart.
*/
oneOrMore(): RegexPart;
}
/** A subclass of `RegexPart` used for matchers that include multiple paths. */
export declare class RegexPartWithAlternates extends RegexPart {
/**
* Creates a new RegexPart that matches this part's content, but only if it
* will match the entire source string.
*
* @returns The new RegexPart.
*/
matchEntireText(): RegexPart;
}
/**
* Escapes text for use in a regular expression (e.g. `hello$world.` becomes
* `hello\$world\.`).
*
* @param text The text to be escaped.
* @returns The escaped text.
*/
export declare function escapeRegex(text: string): string;
/** A `RegexPart` matching the start of the source text. */
export declare const start: RegexPart;
/** A `RegexPart` matching the end of the source text. */
export declare const end: RegexPart;
/**
* Creates a `RegexPart` matching a specified piece of text.
*
* @param text The text to be matched.
* @returns A `RegexPart` matching the specified text.
*/
export declare function text(text: string): RegexPart;
/**
* Creates a `RegexPart` matching any of the specified characters.
*
* @param chars The characters that may be matched.
* @returns A `RegexPart` matching one of the specified characters.
*/
export declare function charIn(chars: string): AtomicRegexPart;
/**
* Creates a `RegexPart` matching any character except for those specified.
*
* @param chars The characters that may NOT be matched.
* @returns A `RegexPart` matching any character except those specified.
*/
export declare function charNotIn(chars: string): AtomicRegexPart;
/**
* Creates a `RegexPart` matching any of a list of parts, giving precedence to
* matching the first one.
*
* @param parts The parts that may be matched.
* @returns A `RegexPart` matching any of the passed parts.
*/
export declare function any(...parts: RegexPart[]): RegexPartWithAlternates;
/**
* Creates a `RegexPart` matching any of the passed texts, giving precedence to
* the first one.
*
* @param texts The texts that may be matched.
* @returns A `RegexPart` matching any of the passed texts.
*/
export declare function anyText(...texts: string[]): RegexPartWithAlternates;
/**
* Creates a `RegexPart` matching any of the passed texts, giving precedence to
* the first one.
*
* @param texts The texts that may be matched.
* @returns A `RegexPart` matching any of the passed texts.
*/
export declare function anyTextArray(texts: readonly string[]): RegexPartWithAlternates;
/**
* Creates a `RegexPart` matching each of the passed parts in order.
*
* @param parts The parts that will be matched.
* @returns A `RegexPart` matching all of the passed parts in order.
*/
export declare function seq(...parts: RegexPart[]): RegexPart;