PureYAML/Sources/Tagged/Tagged.Node.Traversable.swift
Mihaela Mihaljevic bf2dc4ece7 refactor(validation): rename framework to match the validation idiom
The validation module already implemented the composable-rule idiom under
its own names (Check/Issue/SubjectContext) and a value-type Validator with
duplicated traversal machinery per layer. Renamed the core types to the
canonical names (Validation/ValidationError/ValidationErrorCollection/
ValidationContext/BuiltinValidation/AnyValidation), converted Validator to
a reference-type class with the two-tier default-rule split, and genericized
it over both Subject and Document via a new Traversable protocol so the
model and tagged layers share one walk engine instead of two copies. Wired
the JSON-representability rule set into the same shape and closed the two
missing pieces (unwrap combinator, JSON coverage/config-pin tests).
2026-07-12 18:10:00 +02:00

27 lines
1.3 KiB
Swift

extension PureYAML.Tagged.Node: PureYAML.Validation.Traversable {
/// For a mapping: the mapping itself (a `Validation<Mapping, _>` fires on this). Unlike the model
/// layer, key nodes are not offered separately: a tagged mapping's keys are plain `String`, not a
/// `Validatable` key type of their own.
public var extraOffers: [(component: PureYAML.Validation.Path.Component?, value: any PureYAML.Validation.Validatable)] {
guard case let .mapping(mapping) = self else {
return []
}
return [(nil, mapping)]
}
/// A mapping's children are its pairs' values, keyed by their string key; a sequence's children are
/// its values, keyed by index. An alias's aliased subtree was already walked at its anchor's
/// definition site, so recursing here would report every error in that subtree once per reference;
/// a scalar has no children either.
public var children: [(component: PureYAML.Validation.Path.Component, value: PureYAML.Tagged.Node)] {
switch self {
case let .mapping(mapping):
mapping.pairs.map { pair in (component: .key(pair.key), value: pair.value) }
case let .sequence(sequence):
sequence.values.indices.map { index in (component: .index(index), value: sequence.values[index]) }
case .scalar, .alias:
[]
}
}
}