import { Token } from '../token'; import { BS } from '../bs'; import * as XmlLike from './xml-like'; /** * Parsing XML Element * @public */ export declare namespace Parser { /** * Interface that must be implemented by a parser * @public */ interface IParser { /** * Called on start-tag of a child element. * * Receiving the start-tag opened and a parser if different than the parent parser. If returns `false`, the child element is skipped. */ onChild?: (startTag: Token.StartTag) => IParser | false; /** * Called on end-tag. * * Receiving the context of the current element being closed and the context of its parent */ onEnd?: (ctx: any, parentCtx: any) => any; /** * Called on start-tag. * * Receiving the context of the current element being opened and the context of its parent */ onStart?: (startTag: Token.StartTag, parentCtx: any) => any; /** * Called on text or CDATA. * * Receiving the text token (`text.textContent`) and the context of its parent */ onText?: (text: Token.Text | Token.CDATA, ctx: any) => void; /** when `true`, child nodes are ignored */ skipChildNodes?: boolean; /** @internal */ passThrough?: boolean; } /** * Helps with intermediate nodes of a path like `a/b/c`. * * When calling docParser.on(`a/b/c`, myParser), `c` will be associated with the target parser but `a` and `b` will be associatiated with `PassThrough` */ class PassThrough implements IParser { readonly names: BS[]; readonly parser: IParser; passThrough: boolean; private constructor(); static on(path: string, parser: IParser): PassThrough; onChild(startTag: Token.StartTag): false | IParser | PassThrough; } /** * Switches to the first parser amongst a list of possible parsers */ class Switch implements IParser { readonly then: IParser[]; private constructor(); static create(): Switch; /** * Adds a parser to the list * @param parser-parser to be added */ case(parser: IParser): this; /** * Returns the first parser matching the start tag * @param startTag-current start-tag */ onChild(startTag: Token.StartTag): false | IParser | Switch; } /** * Returns parser to generate a simple object representation of an xml element * * @beta */ function getXmlToObjectParser(): IParser; /** Representation of an xml element */ export import XmlElement = XmlLike.XmlElement; /** Returns a object representation based on XmlElement */ export import XmlElementParser = XmlLike.XmlElementParser; }