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
609 B
Swift
11 lines
609 B
Swift
extension PureYAML.Parsing {
|
|
/// Faithful Swift port of libyaml's scanner (`CYaml/src/scanner.c`). It is
|
|
/// built as a parallel implementation, verified token-for-token against
|
|
/// libyaml through the differential harness, to replace the hand-rolled
|
|
/// approximation whose indentation and simple-key handling the official test
|
|
/// suite surfaced as incorrect. The port proceeds function by function; each
|
|
/// piece mirrors its C counterpart so correctness is by construction rather
|
|
/// than re-derived. Members live under this namespace in their own files.
|
|
enum LibYAML {}
|
|
}
|