PureYAML/Sources/Parsing/TagHandleIssue.swift
Mihaela M df3d43804c feat(parsing): scope %TAG per document, diagnose undefined handles
A tag shorthand using a named handle (`!handle!suffix`) must be declared by a
`%TAG` directive in the document that uses it; the handle does not carry across
documents (YAML 1.2). The parser was permissive but silent here, so an
undeclared handle passed unnoticed.

- Scope tag handles per document: a `%TAG` handle now applies only to the
  document it precedes (merged onto the defaults at the document start, cleared
  at the boundary) instead of accumulating across the whole stream. A directive
  repeated for each document keeps working, as the suite requires.
- Detect the named-handle form before the primary-handle fallback (which
  previously masked `!prefix!x` as a local tag) and record an undeclared handle.
  The parse stays permissive: it still yields a value, and
  `PureYAML.validationReport` surfaces the issue as an `undefinedTagHandle`
  error. The check reads the scanner's tokens, so it is exact: a `!x!` inside a
  scalar or comment is never flagged.

Extracts `Scanner.State` and the tag helpers into their own files to keep each
source file within the 400-line limit. Adds focused tests; the full suite and
strict lint stay green.
2026-06-29 07:54:55 +02:00

12 lines
524 B
Swift

extension PureYAML.Parsing {
/// A tag shorthand (`!handle!suffix`) whose named handle was never declared by a `%TAG`
/// directive in the document where it is used. The scanner records these rather than rejecting,
/// so a permissive parse still produces a value while the diagnostic layer can surface the issue.
struct TagHandleIssue: Equatable {
var line: Int
var column: Int
/// The undeclared handle, including its surrounding `!`, e.g. `!e!`.
var handle: String
}
}