fix(parsing): keep the final break of a newline-less block scalar
A block scalar whose last line is whitespace only and ends at end of input without a break still owns one line break, which keep (+) chomping preserves. libyaml records no break because there is no break byte, so '- |+' over a spaces-only unterminated line yields '' instead of '\n'. In scan_block_scalar_breaks, when the break loop stops at end of input after consuming whitespace on that line, append one implicit '\n' to the trailing breaks (used only by keep chomping). Content lines are unaffected because they do not skip whitespace in this loop. With this the ported engine emits the exact canonical event stream for every valid case in the vendored YAML test suite: 308/308, ahead of libyaml (252) and the old hand-rolled parser (267). Port score 307 -> 308.
This commit is contained in:
parent
d222b8cc53
commit
7898dcd1a9
@ -22,6 +22,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Fixed
|
||||
|
||||
- Keep the final line break of a block scalar that ends at end of input without a
|
||||
trailing newline. A whitespace-only last line still counts as one line break
|
||||
under keep (`+`) chomping, so `- |+` followed by a spaces-only unterminated line
|
||||
yields `"\n"` rather than `""`. With this the ported engine emits the exact
|
||||
canonical event stream for every valid case in the vendored YAML test suite
|
||||
(308/308), surpassing libyaml (252) and the previous hand-rolled parser (267).
|
||||
Surpasses libyaml on JEF9/02.
|
||||
- End a root-level block scalar at a `---` or `...` document marker in column 0.
|
||||
Now that a root block scalar can take indentation 0, its content loop reaches
|
||||
column-0 lines, so a marker line must end the scalar instead of being folded
|
||||
|
||||
@ -118,6 +118,7 @@ extension PureYAML.Parsing.LibYAML.Scanner {
|
||||
// indentation. During auto-detection the floor is the parent indent + 1.
|
||||
let tabFloor = indent >= 0 ? indent : max(0, indentEngine.indent + 1)
|
||||
while true {
|
||||
let lineStart = reader.column
|
||||
while indent < 0 || reader.column < indent, reader.peek() == " " {
|
||||
reader.skip()
|
||||
}
|
||||
@ -128,6 +129,12 @@ extension PureYAML.Parsing.LibYAML.Scanner {
|
||||
throw blockError("found a tab character where an indentation space is expected", startMark)
|
||||
}
|
||||
if !Classify.isBreak(reader.peek()) {
|
||||
// A trailing whitespace-only line that ends at end of input without
|
||||
// a break still counts as one line break for keep chomping (as the
|
||||
// test-suite reference does), even with no break byte present.
|
||||
if reader.peek() == nil, reader.column > lineStart {
|
||||
state.trailingBreaks += "\n"
|
||||
}
|
||||
break
|
||||
}
|
||||
state.trailingBreaks += readBlockLine()
|
||||
|
||||
@ -11,19 +11,13 @@ import Testing
|
||||
struct CanonicalEventConformanceTests {
|
||||
/// Valid suite cases whose event stream PureYAML does NOT yet emit exactly.
|
||||
/// This is the authoritative gap set: a fix removes an id (and the test fails
|
||||
/// until it is removed), a regression adds one (and the test fails). Of these,
|
||||
/// The one remaining gap emits a wrong event stream (it does not throw).
|
||||
static let knownEventGaps: Set<String> = [
|
||||
// Gap set for the ported libyaml engine. Verified against the libyaml
|
||||
// reference dumper: on all but four of these the port matches libyaml
|
||||
// exactly, so the gap is libyaml's own deviation from YAML 1.2, not a port
|
||||
// bug. Surpassing libyaml means shrinking this set beyond what libyaml
|
||||
// itself handles.
|
||||
//
|
||||
// wrong event stream: the port matches libyaml but both deviate from the
|
||||
// canonical events (libyaml quirks to be surpassed).
|
||||
"JEF9/02",
|
||||
]
|
||||
/// until it is removed), a regression adds one (and the test fails).
|
||||
///
|
||||
/// The ported libyaml engine now emits the exact canonical event stream for
|
||||
/// every valid case in the vendored YAML test suite, so this set is empty.
|
||||
/// Each entry that used to live here was a libyaml deviation from YAML 1.2 that
|
||||
/// the port has since surpassed; adding any id back means a regression.
|
||||
static let knownEventGaps: Set<String> = []
|
||||
|
||||
@Test("Every valid case emits canonical events, except the recorded gaps")
|
||||
func test_canonicalEventConformance() throws {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user