Tagged.Scalar/Sequence/Mapping gain anchor and style fields (Tagged.ScalarStyle, Tagged.CollectionStyle), Tagged.Node gains an alias(anchor:node:) case carrying both the reference and its resolution, and parseTagged populates all of it from the parse events instead of discarding anchors and expanding aliases into copies. PureYAML.dump(_ node: Tagged.Node, options:) re-emits anchors, alias references, tags, and per-node styles over the document-wide policy. Plain scalars re-emit their source spelling (NO stays NO, an empty null stays empty); literal blocks cover keep chomping, single-line strip chomping, leading blank lines, and whitespace-led first lines via an explicit indentation indicator; folded scalars re-emit as > when the folding rules invert exactly and degrade to a literal block otherwise. The round-trip law parseTagged(dump(parseTagged(d))) == parseTagged(d) is corpus-tested over every real-world fixture, with one documented degradation: single-quoted content containing line breaks re-emits double-quoted, value unchanged. Closes #9
29 lines
850 B
Swift
29 lines
850 B
Swift
public extension PureYAML.Tagged {
|
|
/// The presentation style a scalar had in the source document, or the
|
|
/// style a caller wants a scalar to take on output. `nil` on a node means
|
|
/// "no per-node preference": the emitter's document-wide policy decides.
|
|
enum ScalarStyle: String, Equatable, Sendable, CustomStringConvertible {
|
|
case plain
|
|
case singleQuoted
|
|
case doubleQuoted
|
|
case literal
|
|
case folded
|
|
|
|
public var description: String {
|
|
rawValue
|
|
}
|
|
}
|
|
}
|
|
|
|
extension PureYAML.Tagged.ScalarStyle {
|
|
init(_ style: PureYAML.Parsing.ScalarStyle) {
|
|
self = switch style {
|
|
case .plain: .plain
|
|
case .singleQuoted: .singleQuoted
|
|
case .doubleQuoted: .doubleQuoted
|
|
case .literal: .literal
|
|
case .folded: .folded
|
|
}
|
|
}
|
|
}
|