PureYAML/Sources/Parsing/Scanner.FlowContext.swift
Mihaela Mihaljevic 16da7248c7 fix(parsing): complete flow-collection key and empty-node handling
Implement libyaml's simple-key mechanism for flow context: the scanner records a potential key position before a plain or quoted scalar, an anchor/tag, or a [/{ opener, and a later ':' splices a mappingKey token retroactively in front of that node. This lets a quoted scalar ("k":v), a nested collection ({k}:v), or a property-carrying node (&c c: d) become a flow mapping key. In flow context ':' is always a value indicator and '?' always an explicit-key indicator regardless of the next character (the block-only following-blank lookahead is disabled), so adjacent forms and trailing '?' parse, and multi-line plain keys fold before the ':' is read. The flow parser is rebuilt around the flow_sequence_entry / flow_mapping_key / flow_mapping_value productions, composing empty scalars for absent keys and values. The streaming token cursor now buffers an open flow collection's tokens until it closes so the retroactive key splice stays valid.

Flips 10 official YAML test suite cases (348/402): 4FJ6, 8KB6, 9BXH, 9MMW, CN3R, DFF7, FRK4, NJ66, UT92, CT4Q. Flow collections used as block mapping keys (LX3P, 6BFJ) need the splice in block context and stay tracked. Updates manifest, fixtures, counts, and roadmap.
2026-06-23 23:18:59 +02:00

23 lines
825 B
Swift

extension PureYAML.Parsing {
enum ScannerFlowContextKind {
case sequence
case mapping
}
struct ScannerFlowContext {
var kind: ScannerFlowContextKind
var isExpectingKey: Bool
}
/// A position that may be promoted to a flow-mapping key, mirroring libyaml's
/// `yaml_simple_key_t`. When a `:` value indicator is later found, the scanner
/// inserts a ``TokenKind/mappingKey`` token at ``tokenIndex`` so a node of any
/// kind (plain or quoted scalar, or a nested `[...]`/`{...}` collection) that
/// precedes the `:` becomes that pair's key. Only used inside flow collections;
/// block context promotes keys with a forward lookahead instead.
struct ScannerFlowSimpleKey {
var tokenIndex: Int
var mark: PureYAML.Parsing.Mark
}
}