feat(parsing): treat tab-containing blank lines as blank
YAML 1.2 separation lines may contain tabs, so a line of only spaces and tabs is blank. libyaml leaves a leading tab and later rejects it; the scanner now consumes the trailing blanks of a whitespace-only line so the break is reached and the line is skipped. Canonical event conformance: 258 -> 259 of 308 (DK95/03). 333 tests pass.
This commit is contained in:
parent
6ce1f906f9
commit
c906993f00
@ -25,6 +25,15 @@ extension PureYAML.Parsing.LibYAML.Scanner {
|
||||
while reader.peek() == " " || ((flowLevel > 0 || !simpleKeyAllowed) && reader.peek() == "\t") {
|
||||
reader.skip()
|
||||
}
|
||||
// YAML 1.2: a line containing only whitespace is blank even when that
|
||||
// whitespace includes tabs. libyaml leaves a leading tab in place and
|
||||
// later rejects it; instead consume the trailing blanks so the line
|
||||
// break below is reached and the blank line is skipped.
|
||||
if blankLineAhead() {
|
||||
while reader.peek() == " " || Classify.isTab(reader.peek()) {
|
||||
reader.skip()
|
||||
}
|
||||
}
|
||||
if reader.peek() == "#" {
|
||||
while !Classify.isBreakZ(reader.peek()) {
|
||||
reader.skip()
|
||||
@ -301,6 +310,16 @@ extension PureYAML.Parsing.LibYAML.Scanner {
|
||||
indentEngine.enqueue(token)
|
||||
}
|
||||
|
||||
/// Whether the rest of the current line, from the current position, is only
|
||||
/// spaces and tabs up to a line break or end of stream (a blank line).
|
||||
private func blankLineAhead() -> Bool {
|
||||
var offset = 0
|
||||
while let character = reader.peek(offset), character == " " || Classify.isTab(character) {
|
||||
offset += 1
|
||||
}
|
||||
return Classify.isBreakZ(reader.peek(offset))
|
||||
}
|
||||
|
||||
private func isDocumentMarker(_ character: Unicode.Scalar) -> Bool {
|
||||
reader.peek(0) == character
|
||||
&& reader.peek(1) == character
|
||||
|
||||
@ -24,7 +24,7 @@ struct CanonicalEventConformanceTests {
|
||||
"2JQS", "2SXE", "4ABK", "4MUZ/00", "4MUZ/01", "4MUZ/02", "58MP",
|
||||
"5MUD", "5T43", "6BCT", "6CA3", "6M2F", "7Z25", "8XYN", "96NN/00",
|
||||
"96NN/01", "9SA2", "A2M4", "CFD4", "DBG4", "DK3J", "DK95/00",
|
||||
"DK95/03", "DK95/04", "FP8R", "FRK4", "HM87/00", "HWV9", "K3WX", "M2N8/00",
|
||||
"DK95/04", "FP8R", "FRK4", "HM87/00", "HWV9", "K3WX", "M2N8/00",
|
||||
"M7A3", "NHX8", "NJ66", "NKF9", "Q5MG", "QT73",
|
||||
"R4YG", "S3PD", "SM9W/01", "UKK6/00", "UT92", "VJP3/01", "W4TN", "W5VH",
|
||||
"Y79Y/001", "Y79Y/010",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user