@dcoffey/espells
Version:
Pure JS/TS spellchecker, using Hunspell dictionaries. Based on Spylls.
67 lines (66 loc) • 2.54 kB
TypeScript
import type { Aff, Flags, FlagSet } from "./index.js";
import type { Flag } from "./types.js";
/** {@link Rule} quantifiers. */
declare enum Quantifier {
/** Must match the flag. */
ONE = 0,
/** May optionally match the flag repeatedly. ("*" quantifier) */
ZERO_OR_MORE = 1,
/** May optionally match the flag. ("?" quantifier) */
ZERO_OR_ONE = 2
}
/** A {@link CompoundRule} internal rule or step. */
interface Rule {
/** The flag that needs to be matched. */
flag: Flag;
/** The {@link Quantifier} for this rule. */
quantifier: Quantifier;
}
/**
* A `RegExp`-like rule for generating compound rules. It is an alternative
* way of specifying compound words to the {@link Aff.COMPOUNDFLAG} (and
* similar) {@link Flag}s. It uses the following syntax:
*
* ```text
* COMPOUNDRULE A*B?CD
* ```
*
* Which should be parsed as: A compound word may consist of zero or more
* words with the {@link Flag} `A`, then optionally a word with the
* {@link Flag} `B`, and then finally the compound must end with a word with
* the {@link Flag} `C` and a word with the {@link Flag} `D`.
*
* The similarity of this to a `RegExp` is exploited by both Spylls and
* Espells. The algorithm used to check for matches involves taking a
* {@link FlagSet} (representing words) and turning it into a string that is
* checked by a `RegExp`.
*/
export declare class CompoundRule {
/** The {@link Flags} this rule is relevant to. */
flags: Flags;
/** The `RegExp` used to check if a transformed {@link Flags} string is valid. */
regex: RegExp;
/**
* A fairly mangled looking `RegExp` that is used to determine if a
* transformed {@link Flags} string is at least *partially* valid. This is
* so that a compound word can be checked for if it *can* continue in some way.
*/
partialRegex: RegExp;
/** The orderd list of parsed rules. */
rules: Rule[];
/**
* @param rule - The `RegExp`-like syntax to generate this rule.
* @param aff - The {@link Aff} data to use when parsing flags.
*/
constructor(rule: string, aff: Aff);
/**
* Determines if a {@link FlagSet} matches this rule.
*
* @param flags - The {@link FlagSet} to check.
* @param partial - If true, the {@link FlagSet} will only need to
* partially match the rule to be considered valid. This is so that a
* compound word can be checked for if it *can* continue in some way.
*/
match(flags: FlagSet, partial?: boolean): boolean;
}
export {};