Slice 1 of #94 (editor integration). The keystone: a located validation finding can now be mapped back to a source range. - TreeNode gains a sourceRange (start/end Mark); SourceRange is a half-open span. - PureXML.readTree builds a mutable, parent-aware, best-effort tree whose every node carries its span (an element from the < of its start tag to past its end tag; leaves over the text they consumed). Never throws, recovers in place, returns located diagnostics. - TreeNode.node(at:) navigates a validation coding path to its node using the same canonical convention the validators build paths with (a sibling index only when a name repeats), and sourceRange(at:) returns the span. So Document.validate's ValidationError.codingPath resolves to characters in the document. Tests prove the spans, the navigation, the end-to-end bridge (an XSD finding to a source range), and that ranged reading of invalid input never crashes.
21 lines
790 B
Swift
21 lines
790 B
Swift
public extension PureXML.Parsing {
|
|
/// A half-open span of source text, from the start of a construct to just past
|
|
/// its end. Carried on a ``PureXML/Model/TreeNode`` by the ranged reader so a
|
|
/// located finding can be mapped back to characters in the document.
|
|
struct SourceRange: Equatable, Sendable, CustomStringConvertible {
|
|
/// The position of the first character of the construct.
|
|
public var start: Mark
|
|
/// The position just past the last character of the construct.
|
|
public var end: Mark
|
|
|
|
public init(start: Mark, end: Mark) {
|
|
self.start = start
|
|
self.end = end
|
|
}
|
|
|
|
public var description: String {
|
|
"\(start.line):\(start.column)-\(end.line):\(end.column)"
|
|
}
|
|
}
|
|
}
|