Replace the notImplemented stub with a real parser built on a pull-based, streaming event core that never requires the whole document in memory. - Parsing.EventReader: pulls characters through a source closure with a bounded lookahead buffer and emits one Parsing.Event at a time, holding only an open-element stack. Drives chunked/streamed input. - Parsing.Parser: builds a Model.Node tree iteratively over the event core (explicit stack, no recursion). - Reader: streaming character cursor (closure-backed, bounded buffer) replacing the previous whole-string Array. - EntityDecoder: the five predefined entities and decimal/hex char references. - Handles elements, attributes, text, comments, CDATA, processing instructions, and an XML declaration in the prolog. Rejects <!DOCTYPE> by default (no DTD/XXE/entity-expansion exposure). - Top-level API: parse(_:), parse(pulling:), events(_:), events(pulling:). - 21 tests including event-stream and chunked-source coverage.
16 lines
692 B
Swift
16 lines
692 B
Swift
public extension PureXML.Parsing {
|
|
/// A single XML parse event emitted by the streaming ``EventReader``.
|
|
///
|
|
/// An empty element `<br/>` emits ``startElement(name:attributes:)`` followed
|
|
/// immediately by ``endElement(name:)``, so consumers see a consistent
|
|
/// open/close pair regardless of the source syntax.
|
|
enum Event: Equatable, Sendable {
|
|
case startElement(name: PureXML.Model.QualifiedName, attributes: [PureXML.Model.Attribute])
|
|
case endElement(name: PureXML.Model.QualifiedName)
|
|
case characters(String)
|
|
case cdata(String)
|
|
case comment(String)
|
|
case processingInstruction(target: String, data: String)
|
|
}
|
|
}
|