A flow `?` did not mark an explicit key, so the scalar after it synthesized
its own implicit key: `{? foo : bar}` parsed as `{{foo: bar}: null}` instead of
`{foo: bar}`, and `[? foo : bar]` the same way.
Track the explicit-key state per flow level on the flow context: set it at a
flow `?`, clear it at that level's `:` or a `,`, and discard it with the
context when the collection closes. The key scalar then is not turned into an
implicit key, the pair's `:` is its value indicator, and a nested collection's
`:` does not affect an outer key (`{? {a: b} : c}`). The continuation fold for
a multi-line explicit key now also consults the flow context, restoring
`[? foo\n bar : baz]` to the single key `foo bar`.
The block explicit-key flag is left untouched, since it is not cleared between
valueless `? a` / `? b` entries and folding it into this check regressed
block sets; only the flow path is changed here.
Raises yaml-test-suite value-level conformance to 192/194 (99.0%) with the
parse-level and should-error rejection rates unchanged. 472 tests pass.
12 lines
588 B
Swift
12 lines
588 B
Swift
extension PureYAML.Parsing {
|
|
struct ScannerFlowContext {
|
|
var kind: ScannerFlowContextKind
|
|
var isExpectingKey: Bool
|
|
/// Whether an explicit key indicator (`?`) is open at this flow level, so the following scalar
|
|
/// is the explicit key's content and must not synthesize its own implicit key. Cleared by the
|
|
/// pair's `:` value indicator or a `,`, and discarded with the context when the collection
|
|
/// closes, so it tracks per-level and a nested collection's `:` does not affect an outer key.
|
|
var hasExplicitKey = false
|
|
}
|
|
}
|