PureYAML/Sources/Parsing/LibYAML.Token.swift
Mihaela Mihaljevic c3033c356d feat(parsing): begin faithful libyaml scanner port (indent engine)
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.
2026-06-24 02:46:29 +02:00

11 lines
392 B
Swift

extension PureYAML.Parsing.LibYAML {
/// A scanner token, mirroring `yaml_token_t`: a kind plus its start and end
/// marks. Token-specific payloads (scalar value, anchor name, tag) are added
/// as their fetchers are ported.
struct Token: Equatable {
var type: TokenType
var startMark: PureYAML.Parsing.Mark
var endMark: PureYAML.Parsing.Mark
}
}