PureYAML/Sources/Model/LocatedPair.swift
Mihaela Mihaljevic 3f3ce310b1 feat(parsing): opt-in located parse with source spans on every node
Add parseLocated / parseStreamLocated, returning a Model.LocatedValue
tree parallel in shape to Value, where every node carries its source
span (1-based line/column) and located children. Collections span from
their opening to closing event; scalars carry a start-anchored span;
aliases and merge-inherited pairs honestly point at their reference site.

The plain Value, its equality, and the conformance oracle are untouched:
locations are built only when the streaming composer is asked for them
(tracksLocations), behind new entry points, so the default value path is
byte-identical. A whole-suite test proves the located projection equals
a plain parse for every passing case (402/402), including through merge
keys and aliases, and the canonical-event and gap gates stay green.
2026-06-26 00:57:55 +02:00

21 lines
773 B
Swift

public extension PureYAML.Model {
/// A key-value pair in a located mapping: the key (as a ``Key``), the source span of the
/// key node, and the located value. Parallel to ``Pair`` but carrying source coordinates.
struct LocatedPair: Equatable, Sendable {
public var keyNode: Key
public var keyRange: SourceRange
public var value: LocatedValue
public init(keyNode: Key, keyRange: SourceRange, value: LocatedValue) {
self.keyNode = keyNode
self.keyRange = keyRange
self.value = value
}
/// The position-free pair, projecting the located value back to a plain ``Value``.
public var pair: Pair {
Pair(keyNode: keyNode, value: value.value)
}
}
}