fix(parsing): accept tabs as block-scalar content past the indentation
The block-scalar break scanner raised 'found a tab character where an indentation space is expected' for every tab seen while auto-detecting the content indentation. But a tab at or beyond the content column is content, not indentation: only a tab below the content column is illegal. Gate the tab check on a content-column floor (the resolved indent, or the parent indent + 1 while auto-detecting) instead of firing on every tab in auto-detect mode. A tab-only line shallower than the content is still rejected, so tab-as-indentation errors (Y79Y/000 and friends) are preserved. Surpasses libyaml on 96NN/00, 96NN/01, R4YG, Y79Y/001. Port score 286 -> 290.
This commit is contained in:
parent
254905fe67
commit
26e09103b4
@ -22,6 +22,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Fixed
|
||||
|
||||
- Accept a tab as block-scalar content once the indentation is satisfied. The
|
||||
block-scalar break scanner rejected any tab seen while auto-detecting the
|
||||
content indentation, but a tab at or beyond the content column is content, not
|
||||
indentation. The tab is now an error only below the content column (the parent
|
||||
indent + 1 floor while auto-detecting), so `foo: |-` / `bar` lines whose
|
||||
content begins with a tab parse, while a tab used as indentation (a tab-only
|
||||
line shallower than the content) is still rejected. Surpasses libyaml on
|
||||
96NN/00, 96NN/01, R4YG, and Y79Y/001.
|
||||
- Auto-detect indentation 0 for a root-level block scalar. The block-scalar
|
||||
scanner used 0 as the "indentation not yet detected" sentinel and floored the
|
||||
detected indent at 1 (as libyaml does in `scan_block_scalar_breaks`), so a
|
||||
|
||||
@ -107,6 +107,10 @@ extension PureYAML.Parsing.LibYAML.Scanner {
|
||||
private mutating func scanBlockScalarBreaks(indent: inout Int, state: inout BlockState, startMark: PureYAML.Parsing.Mark, endMark: inout PureYAML.Parsing.Mark) throws {
|
||||
var maxIndent = 0
|
||||
endMark = reader.mark
|
||||
// A tab is content (or separation) once the column reaches the content
|
||||
// indentation; it is illegal only while still inside the required
|
||||
// indentation. During auto-detection the floor is the parent indent + 1.
|
||||
let tabFloor = indent >= 0 ? indent : max(0, indentEngine.indent + 1)
|
||||
while true {
|
||||
while indent < 0 || reader.column < indent, reader.peek() == " " {
|
||||
reader.skip()
|
||||
@ -114,7 +118,7 @@ extension PureYAML.Parsing.LibYAML.Scanner {
|
||||
if reader.column > maxIndent {
|
||||
maxIndent = reader.column
|
||||
}
|
||||
if indent < 0 || reader.column < indent, Classify.isTab(reader.peek()) {
|
||||
if reader.column < tabFloor, Classify.isTab(reader.peek()) {
|
||||
throw blockError("found a tab character where an indentation space is expected", startMark)
|
||||
}
|
||||
if !Classify.isBreak(reader.peek()) {
|
||||
|
||||
@ -12,7 +12,7 @@ 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,
|
||||
/// 18 currently throw on valid input and 4 emit a wrong event stream.
|
||||
/// 14 currently throw on valid input and 4 emit a wrong event stream.
|
||||
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
|
||||
@ -22,10 +22,10 @@ struct CanonicalEventConformanceTests {
|
||||
//
|
||||
// false-rejects (parseEvents throws on valid input, as libyaml does)
|
||||
"4ABK", "58MP", "5T43", "6BCT", "6CA3",
|
||||
"96NN/00", "96NN/01", "A2M4", "CFD4", "DBG4", "DK95/00",
|
||||
"A2M4", "CFD4", "DBG4", "DK95/00",
|
||||
"DK95/04", "FRK4", "HM87/00",
|
||||
"Q5MG", "R4YG",
|
||||
"Y79Y/001", "Y79Y/010",
|
||||
"Q5MG",
|
||||
"Y79Y/010",
|
||||
// wrong event stream: the port matches libyaml but both deviate from the
|
||||
// canonical events (libyaml quirks to be surpassed).
|
||||
"652Z", "HM87/01", "JEF9/02", "W4TN",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user