import { Opcode } from './opcodes'; import { Arguments, FormatterCall, Operator } from './instructions'; import { MatcherProps } from './matchers'; export type RegExpCompiler = (s: string) => RegExp; /** * Helper for low-level pattern matching over a range of characters. */ export declare class Matcher implements MatcherProps { str: string; start: number; end: number; matchEnd: number; private filePath; private formatterArgs; private instructionArgs; private operator; private predicate; private variableDefinition; private variableReference; private variableSeparator; private whitespace; private word; constructor(str: string); /** * Overridden by mixin. */ compile(str: string): RegExp; /** * Overridden by mixin. */ match(pattern: RegExp, start: number): string | null; /** * Overridden by mixin. */ test(pattern: RegExp, start: number): boolean; init(str: string): void; /** * Position of the match pointer. */ pos(): number; /** * Set the range to match over. */ set(start: number, end: number): void; /** * Seek forward until we find the matched character. */ seekTo(ch: string): string | null; /** * Consume / skip over the last match. */ consume(): void; /** * Return true if entire input has been matched. */ complete(): boolean; /** * This instruction matching scheme lets us do a few things simultaneously * with speed versus a regular expression: * * 1. check if a sequence of characters at a certain offset is an instruction * 2. identify the end position of the instruction * 3. mapping the instruction characters to its opcode, e.g. '.end' -> END * * A regular expression can do 1 and 2 using lastIndex, but for 3 it must copy * the substring and do a further lookup to get the opcode. * * A hand-written switch() is even faster than this method, but far less * maintainable. Code generation could help with maintainability, but the * performance improvement is not enough to be worth it right now. */ matchInstruction(): Opcode; /** * Match arguments to a predicate. */ matchArguments(): Arguments | null; /** * Match one or more variable bindings. */ matchBindings(): any; /** * Match a variable definition. */ matchDefinition(): string | null; /** * Match a path for an INJECT or MACRO instruction. */ matchFilePath(): string | null; /** * Match an IF expression, variables separated by && and ||. */ matchIfExpression(): [Operator[], (string | number)[][]] | null; /** * Match a predicate. */ matchPredicate(): string | null; /** * Match a chain of pipe-separated formatters and optional arguments. */ matchFormatters(): FormatterCall[] | null; /** * Match a single variable reference. */ matchVariable(): (string | number)[] | null; /** * Match a list of variable references. */ matchVariables(): (string | number)[][] | null; /** * Match a single space. */ matchSpace(): boolean; /** * Match one or more whitespace characters. */ matchWhitespace(): boolean; } declare const GlobalMatcher_base: { new (...args: any[]): { compile(s: string): RegExp; match(pattern: RegExp, i: number): string | null; test(pattern: RegExp, start: number): boolean; str: string; matchEnd: number; start: number; end: number; }; } & typeof Matcher; export declare class GlobalMatcher extends GlobalMatcher_base { } declare const StickyMatcher_base: { new (...args: any[]): { compile(s: string): RegExp; match(pattern: RegExp, i: number): string | null; test(pattern: RegExp, i: number): boolean; str: string; matchEnd: number; start: number; end: number; }; } & typeof Matcher; export declare class StickyMatcher extends StickyMatcher_base { } export declare const MatcherImpl: typeof GlobalMatcher; export {};