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.
21 lines
793 B
Swift
21 lines
793 B
Swift
public extension PureYAML.Model {
|
|
/// A source span for a value-tree node: a start and end ``SourcePosition``. A collection
|
|
/// spans from its opening to its closing event; a scalar carries a start-anchored span
|
|
/// (start equal to end), because the event stream records a scalar's start mark only.
|
|
struct SourceRange: Equatable, Hashable, Sendable {
|
|
public var start: SourcePosition
|
|
public var end: SourcePosition
|
|
|
|
public init(start: SourcePosition, end: SourcePosition) {
|
|
self.start = start
|
|
self.end = end
|
|
}
|
|
|
|
/// A zero-width span at a single position, used when only a point is known.
|
|
public init(at position: SourcePosition) {
|
|
start = position
|
|
end = position
|
|
}
|
|
}
|
|
}
|