Surface the parsed <!DOCTYPE> internal subset's <!ELEMENT> declarations from the parser and validate a tree against them. Reimplemented from the DTD content-model spec; no upstream code copied. - DoctypeScanner captures <!ELEMENT name model> declarations; the parser surfaces them as Parsing.DocumentType (via parseWithDocumentType). - Validation.ContentModel + ContentModelParser parse a model string (EMPTY, ANY, (#PCDATA), mixed, and element content with sequence/choice and ?/*/+). - ContentModelMatcher matches the child element-name sequence against a model as a regular language (NFA-position matching). - Validation.DTDSchema.validate reports issues for EMPTY/PCDATA/mixed violations, element content with stray text, and child sequences that do not match. - PureXML.validateAgainstInternalDTD(_:) parses and validates in one call. - ATTLIST validation is out of scope. 9 tests; 70 total.
12 lines
502 B
Swift
12 lines
502 B
Swift
extension PureXML.Validation {
|
|
/// A particle of a DTD element-content model: an element name, a sequence
|
|
/// (`,`), or a choice (`|`), each carrying an occurrence indicator. The
|
|
/// content model is effectively a regular expression over child element
|
|
/// names, and a particle is one node of that expression.
|
|
indirect enum Particle: Equatable {
|
|
case name(String, Occurrence)
|
|
case sequence([Particle], Occurrence)
|
|
case choice([Particle], Occurrence)
|
|
}
|
|
}
|