PureYAML's scanner is a hand-rolled approximation of libyaml's algorithm; its indentation and simple-key bugs are the gap between the two. Rather than keep patching the approximation, re-derive the scanner as a faithful, function-by-function Swift port of libyaml's scanner.c (parser.c to follow), so correctness is by construction. The no-C-runtime constraint is preserved: this translates the algorithm into pure Swift, it does not bind to libyaml. First piece: the indentation engine under PureYAML.Parsing.LibYAML, a line-for-line port of yaml_parser_roll_indent and yaml_parser_unroll_indent. A block collection opens only when content is strictly more indented than the current level, which fixes the '- a:' / same-column 'b:' mis-nesting by construction. Unit-tested against that exact case (sibling vs nested vs flow-inert). Lands as a parallel implementation verified against libyaml built from the CYaml source; swapped in only once it matches the reference with no regression. docs/LIBYAML_PORT.md records the plan. No public behavior changed yet.
11 lines
396 B
Swift
11 lines
396 B
Swift
extension PureYAML.Parsing.LibYAML {
|
|
/// A scanner token kind, mirroring `yaml_token_type_t`. Only the structural
|
|
/// kinds the indentation engine produces are modelled here; scalar, anchor,
|
|
/// tag, and document kinds are added as their fetchers are ported.
|
|
enum TokenType: Equatable {
|
|
case blockSequenceStart
|
|
case blockMappingStart
|
|
case blockEnd
|
|
}
|
|
}
|