import { Listeners } from "./InputState"; import { MatchingLogic } from "./Matchers"; import { Concatenation } from "./matchers/Concat"; import { DismatchReport, PatternMatch } from "./PatternMatch"; import { FromStringOptions } from "./FromStringOptions"; import { AnyKeysOf, Grammar, TermsDefinition } from "./Grammar"; import { MatchUpdater } from "./internal/MicrogrammarUpdates"; import { MatchReport, SuccessfulMatchReport } from "./MatchReport"; import { InputStream } from "./spi/InputStream"; /** * Holds a set of updatable matches */ export declare class Updatable { readonly matches: T[]; private readonly cs; constructor(hits: Array, content: string); updated(): string; } /** * Central class for microgrammar usage. * Represents a microgrammar that we can use to match input * in a string or stream. * Modifications are tracked and we can get an updated string * afterwards. */ export declare class Microgrammar implements Grammar { matcher: Concatenation; /** * Make this match transparently updatable using property mutation * @param match match to make updatable * @param content the match is within * @return {T&MatchUpdater} */ static updatableMatch(match: T & PatternMatch, content: string): T & MatchUpdater; /** * Make these matches transparently updatable using property mutation * @param matches matches * @param content content the matches are within * @return {Updatable} */ static updatable(matches: Array, content: string): Updatable; /** * Create a microgrammar with typed properties according * to the given interface. * If the definitions aren't nested, infer string type * @param {TermsDefinition} definitions * @return {Microgrammar} */ static fromDefinitions(definitions: TermsDefinition): Microgrammar; /** * Create a microgrammar with inferred interface taking properties of type "any" from definitions. * Use fromDefinitions for stronger typing. * If the definitions aren't nested, infer string type * @param {TermsDefinition} definitions * @return {Microgrammar} */ static fromDefinitionsAs(definitions: TermsDefinition): Microgrammar>; /** * Create a microgrammar with string variables. * String is of form "method ${name}(): ${returnType}". * Definitions should be provided for each string variable. * Use fromDefinitions to achieve nesting or non-string typing. * If the definitions aren't nested, infer string type * @return {Microgrammar} */ static fromString(spec: string, components?: TermsDefinition, options?: FromStringOptions): Microgrammar; /** * Create a microgrammar with string variables with automatic typing as in * fromDefinitionsAs. * String is of form "method ${name}(): ${returnType}". * Definitions should be provided for each string variable. * Use fromDefinitions to achieve nesting or non-string typing. * If the definitions aren't nested, infer string type * @return {Microgrammar} */ static fromStringAs(spec: string, components?: TermsDefinition, options?: FromStringOptions): Microgrammar>; readonly $id: string; readonly definitions: any; constructor(matcher: Concatenation); /** * Generator for matching the given input. * @param {string | InputStream} input * @param {{}} parseContext * @param {Listeners} l * @return {Iterable} */ matchIterator(input: string | InputStream, parseContext?: {}, l?: Listeners): Iterable; matchReportIterator(input: string | InputStream, parseContext?: {}, l?: Listeners): Iterable; /** * Convenience method to find matches without the ability to update them * @param input * @param stopAfterMatch() function that can cause matching to stop after a given match. * Often used to stop after one. * @param parseContext context for the whole parsing operation * @param l listeners observing input characters as they are read * @return {PatternMatch[]} */ findMatches(input: string | InputStream, parseContext?: {}, l?: Listeners, stopAfterMatch?: (pm: PatternMatch) => boolean): Array; /** * Parallel to findMatches, but returns a Promise * @param {string | InputStream} input * @param {{}} parseContext * @return {Promise>} */ findMatchesAsync(input: string | InputStream, parseContext?: {}): Promise>; findMatchReportsAsync(input: string | InputStream, parseContext?: {}): Promise; /** * Convenient method to find the first match, or null if not found. * Stops searching after the first match. * @param input * @param l listeners observing input characters as they are read * @returns {PatternMatch[]} */ firstMatch(input: string | InputStream, l?: Listeners): PatternMatch & T | null; /** * Return a match if it explains the whole of the input. * This style of usage is more like a traditional parser, * building an AST for a whole file. * @param input * @param parseContext context for the whole parsing operation * @param l listeners observing input characters as they are read * @return {PatternMatch&T} * @Deprecated prefer perfectMatch */ exactMatch(input: string | InputStream, parseContext?: {}, l?: Listeners): PatternMatch & T | DismatchReport; /** * Return a MatchReport. if it is successful, call .toValueStructure() to get the match value. * Otherwise, call .toExplanationTree() to get a report of why it didn't match. * @param input * @param parseContext context for the whole parsing operation * @param l listeners observing input characters as they are read */ perfectMatch(input: string | InputStream, parseContext?: {}, l?: Listeners): MatchReport; } /** * Single use, usually stateful, class for matching input. * Offers the ability to observe a match, as well as match one, * and to change the matcher in use depending on observation and matching. * E.g. it's possible to choose to start matching pattern B after finding pattern A, * or after *seeing* pattern A, even if starting off matching something else. * This enables us, for example, to parse XML, with the observer watching element * open and close to maintain the current path, while the matcher matches anything we want. */ export declare class MatchingMachine { protected matcher: MatchingLogic; protected observer: MatchingLogic; private readonly omg; /** * Create a new stateful matching machine * @param initialMatcher matcher to start using. This can be changed by the callback methods in this class * @param o optional observer */ constructor(initialMatcher: any, o?: any); /** * Stream-oriented matching. The observer can match in parallel with the main matcher. * @param input * @param parseContext context for the whole parsing operation * @param l listeners observing input characters as they are read */ consume(input: string | InputStream, parseContext?: {}, l?: Listeners): void; /** * Observe a match. The return can change the matcher in use, or return the current matcher. * @param pm pattern to observe * @returns {MatchingLogic} */ protected observeMatch(pm: PatternMatch): any; /** * React to a match. The return can change the matcher, or return the current matcher. * @param pm matcher */ protected onMatch(pm: PatternMatch): any; } /** * Generator for matching the given input. * @param matcher * @param {string | InputStream} input * @param {{}} parseContext * @param {Listeners} l * @return {Iterable} */ export declare function matchesIn(matcher: any, input: string | InputStream, parseContext?: {}, l?: Listeners): Iterable;