PureYAML/Sources/Parsing/LibYAML.SimpleKey.swift
Mihaela Mihaljevic 9ce57e86e5 feat(parsing): port libyaml simple-key mechanism to Swift
Stage 2 of the faithful libyaml scanner port. Translates yaml_parser_save_simple_key, yaml_parser_remove_simple_key, yaml_parser_stale_simple_keys, and the flow-level push/pop (yaml_parser_increase_flow_level / decrease) onto a new PureYAML.Parsing.LibYAML.Scanner aggregate that embeds the indent engine. The simple-key mechanism is what lets a quoted scalar, a nested collection, or a property-carrying node become a mapping key when a ':' follows, and is required exactly at the block indent. Modelled faithfully: a potential key goes stale once it spans a line break or exceeds 1024 characters, and a required key that is removed or goes stale is the 'could not find expected colon' error. Unit-tested for the required/not-required, removal-error, staleness, and flow-level cases. No public behavior changed yet.
2026-06-24 02:55:07 +02:00

21 lines
939 B
Swift

extension PureYAML.Parsing.LibYAML {
/// Port of `yaml_simple_key_t`. A potential implicit ("simple") mapping key:
/// a node that may turn out to be a key once a `:` is seen on the same line.
/// `tokenNumber` records where its `KEY` token must be spliced into the queue.
struct SimpleKey: Equatable {
/// Whether a simple key is still possible at this flow level.
var possible: Bool
/// Whether a `:` is required (a key sitting exactly at the block indent).
var required: Bool
/// The absolute token number where the `KEY` token is inserted.
var tokenNumber: Int
/// The position the potential key started at.
var mark: PureYAML.Parsing.Mark
/// The empty entry pushed for a new flow level (`{ 0, 0, 0, {0,0,0} }`).
static var empty: Self {
Self(possible: false, required: false, tokenNumber: 0, mark: .start)
}
}
}