/** * SaxParser — Phase 10: True event-based SAX parser * ─────────────────────────────────────────────────── * Operates directly on the XmlLexer token stream without building a DOM. * Memory usage is O(nesting depth) not O(document size) — safe for GB files. * * Events * ────── * startDocument () * xmlDeclaration (version, encoding, standalone) * startElement (localName, qName, namespaceURI, attributes) * endElement (localName, qName, namespaceURI) * text (content: string) * cdata (content: string) * comment (content: string) * processingInstruction (target: string, data: string) * doctype (content: string) * endDocument () * error (err: XmlError) * * Pull-parser API * ──────────────── * const parser = new SaxParser(xml); * for (const event of parser.events()) { ... } * * Usage * ───── * const sax = new SaxParser(bigXmlString); * sax.on('startElement', ({ qName, attributes }) => { ... }); * sax.parse(); */ import { LexerOptions } from './XmlLexer'; import { XmlError } from '../errors/XmlError'; export interface SaxAttribute { name: string; localName: string; prefix: string; value: string; namespaceURI: string; } export interface StartElementEvent { qName: string; localName: string; prefix: string; namespaceURI: string; attributes: SaxAttribute[]; /** Namespace declarations introduced by this element (prefix → URI). */ nsDeclarations: Map; line: number; col: number; } export interface EndElementEvent { qName: string; localName: string; prefix: string; namespaceURI: string; line: number; col: number; } export interface XmlDeclarationEvent { version: string; encoding: string; standalone: boolean | null; } export type SaxEventType = 'startDocument' | 'endDocument' | 'xmlDeclaration' | 'startElement' | 'endElement' | 'text' | 'cdata' | 'comment' | 'processingInstruction' | 'doctype' | 'error'; export type SaxEvent = { type: 'startDocument'; } | { type: 'endDocument'; } | { type: 'xmlDeclaration'; event: XmlDeclarationEvent; } | { type: 'startElement'; event: StartElementEvent; } | { type: 'endElement'; event: EndElementEvent; } | { type: 'text'; value: string; line: number; col: number; } | { type: 'cdata'; value: string; line: number; col: number; } | { type: 'comment'; value: string; line: number; col: number; } | { type: 'processingInstruction'; target: string; data: string; line: number; col: number; } | { type: 'doctype'; content: string; line: number; col: number; } | { type: 'error'; error: XmlError; }; export type SaxHandler = (event: Extract) => void; export declare class SaxParser { private input; private options; private handlers; private ns; constructor(input: string, options?: LexerOptions); on(type: T, handler: SaxHandler): this; off(type: T, handler: SaxHandler): this; /** Lazy generator — yields one SaxEvent per token without building a DOM */ events(): Generator; /** Push-style parse: drives the generator and calls registered handlers */ parse(): void; private _run; private _emit; } /** * Convenience: parse XML with a SAX-style callback object. */ export declare function parseSax(input: string, handlers: Partial<{ [T in SaxEventType]: SaxHandler; }>, options?: LexerOptions): void; //# sourceMappingURL=SaxParser.d.ts.map