PureYAML/Sources/Model/SourcePosition.swift
Mihaela M d4ba594012 feat(parsing): opt-in located parse on the hand-rolled engine
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).
2026-06-29 07:14:42 +02:00

20 lines
782 B
Swift

public extension PureYAML.Model {
/// A 1-based line/column position in the source text. Carried by ``LocatedValue`` so a
/// consumer (an editor, a linter, a CI report) can point at exactly where a value-tree
/// node was written. Positions live on the parallel located tree, never on ``Value``,
/// so the plain value tree and its equality stay free of source coordinates.
struct SourcePosition: Equatable, Hashable, Sendable, Comparable {
public var line: Int
public var column: Int
public init(line: Int, column: Int) {
self.line = line
self.column = column
}
public static func < (lhs: Self, rhs: Self) -> Bool {
(lhs.line, lhs.column) < (rhs.line, rhs.column)
}
}
}