Port the located value tree onto the hand-rolled engine, reusing the
engine-agnostic located layer (Model.LocatedValue, LocatedPair,
SourcePosition, SourceRange, and the located composer helper) authored
on the conformance branch. The streaming composer now builds a parallel
located tree behind an opt-in tracksLocations flag, exposed as
parseLocated / parseStreamLocated; the plain Value path stays
byte-identical, gated behind the flag.
The scalar event carries the scanner token's end mark, so a located
scalar spans the whole token (end exclusive, one past the last
character) rather than being start-anchored. The hand-rolled scanner
already tracked token end marks, so this surfaces information the engine
was already computing.
Also stop emitting a spurious null document for a comment-only or empty
stream: YAML 1.2 gives such a stream zero documents, while the
single-document value API still maps it to null, so parse("") is
unchanged.
A whole-suite test proves the located projection equals a plain parse
for every passing case; the value, event-dump, and conformance suites
stay green (507 tests).
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
|
|
}
|
|
}
|
|
}
|