import { MatchingLogic } from "./Matchers"; import { MatchPrefixResult } from "./MatchPrefixResult"; import { DismatchReport, PatternMatch } from "./PatternMatch"; import { TreeNodeCompatible } from "./TreeNodeCompatible"; export interface AnyMatchReport { offset: number; matched?: string; matcher: MatchingLogic; successful: boolean; description?: string; toExplanationTree(): MatchExplanationTreeNode; } export interface FailedMatchReport extends AnyMatchReport { successful: false; } export interface SuccessfulMatchReport extends AnyMatchReport { successful: true; matched: string; endingOffset: number; toPatternMatch(): PatternMatch & T; toParseTree(): TreeNodeCompatible; toValueStructure(): T; } export declare function isSuccessfulMatchReport(fmr: MatchReport): fmr is SuccessfulMatchReport; export declare function isFailedMatchReport(fmr: MatchReport): fmr is FailedMatchReport; /** * All the data about the match, enough to generate either a PatternMatch * or a value structure (with fields as declared in microgrammar terms) * or a TreeNodeCompatible parse tree * or a TreeNodeCompatible report of why it matched or didn't. * * I can't get from one of these structures to another, because the child * structures are different. So, let's output one structure that can * be turned into any of them. */ export declare type MatchReport = SuccessfulMatchReport | FailedMatchReport; export declare function toPatternMatchOrDismatchReport(mr: MatchReport): PatternMatch & T | DismatchReport; /** * Extract a tree describing how the match was parsed. * Each matcher adds a node, plus Concat adds nodes for all its properties * and Rep adds nodes for all its elements. * Synthetic elements are empty elements are not included; each node * maps to content in the file. * @param mr match report from Grammar.perfectMatch */ export declare function toParseTree(mr: MatchReport): TreeNodeCompatible; export interface MatchExplanationTreeNode extends TreeNodeCompatible { $children: MatchExplanationTreeNode[]; /** * Whether this part of the tree matched successfully */ successful: boolean; /** * If failed, please always populate the description of why. * If successful, you may describe why this input string was so compelling */ reason?: string; } /** * Return a tree which explains the activity of the matching, both * what matched and what didn't. Empty matches are included, and failed * matches are included. Use this to figure out why something matched (or didn't). * @param mr a MatchReport from Grammar.perfectMatch */ export declare function toExplanationTree(mr: MatchReport): MatchExplanationTreeNode; /** * Return the values extracted from a match. For any match constructed with * `microgrammar(...)` this will return an object with a property for each term. * Synthetic properties are included. * @param mr a MatchReport from Grammar.perfectMatch */ export declare function toValueStructure(mr: MatchReport): T; export declare function toMatchPrefixResult(mr: MatchReport): MatchPrefixResult;