UNPKG

cm-tarnation

Version:

An alternative parser for CodeMirror 6

55 lines (54 loc) 2.08 kB
import type { Matcher, VariableTable } from "../../types"; /** * `RegExp` wrapper class. Designed to improve performance by implementing * certain operations (like matching) with edge case handling and short * circuits. In order to assist with this goal, the internal `RegExp` is * always set to be `sticky`, so this class won't work if you want to use a * non-sticky `RegExp`. */ export declare class RegExpMatcher implements Matcher { /** * Internal `RegExp`. Can be null, which is so that even a malformed * input `RegExp` source won't throw. This is used to combat inconsistent * browser behavior. */ private regexp; /** * True if the source `RegExp` has an capturing groups. Used to short * circuit the `match` method's behavior, and improve performance. */ private hasCapturingGroups; /** * @param src - The source `RegExp` to wrap. * @param ignoreCase - If `true`, the ignore case flag is set automatically. * @param variables - A variable table to use when expanding variables. */ constructor(src: string, ignoreCase?: boolean, variables?: VariableTable); /** * Performs the standard `RegExp.test` operation on a string. * * @param str - The string to match. * @param pos - The position to start matching at. */ test(str: string, pos: number): boolean; /** * Performs the standard `RegExp.exec` operation on a string. This is an * internal method because consumers should use the `match` method instead. * * @param str - The string to match. * @param pos - The position to start matching at. */ private exec; /** * Returns the results of attempting to match a string against this * regular expression. * * @param str - The string to match. * @param pos - The position to start matching at. */ match(str: string, pos: number): { total: string; captures: string[] | null; length: number; } | null; }