fix(parsing): accept a tab as a leading indicator boundary
A tab is separation white space in YAML, forbidden only for indentation, so it ends a leading indicator exactly as a space does. isIndicatorBoundary treated only a space, line break, or end of input as a boundary, so a document marker, block entry, or explicit key followed by a tab was folded into a plain scalar: `---\tscalar` parsed to the string `---\tscalar` rather than a document whose root scalar is `scalar`. Accept a tab there too. The document-marker and block-entry forms also strip the tab as separation, so the content is clean; the explicit-key form is now recognized as well, with post-indicator tab stripping left for a later change. Raises yaml-test-suite value-level conformance to 175/192 (91.1%) with the parse-level and should-error rejection rates unchanged. 429 tests pass.
This commit is contained in:
parent
c1610f1eec
commit
37e84b5eb4
@ -84,6 +84,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Fixed
|
||||
|
||||
- A tab now ends a leading indicator the way a space does, since a tab is separation white space in
|
||||
YAML (only indentation forbids a tab). A document marker, block entry, or explicit key followed by a
|
||||
tab (`---\tscalar`, `-\titem`, `?\tkey`) is recognized as the indicator rather than folded into a
|
||||
plain scalar. Raises yaml-test-suite value-level conformance to 175/192 (91.1%), with the parse and
|
||||
should-error rates unchanged.
|
||||
|
||||
- A flow sequence element that begins with `:` is now parsed as a single-pair mapping with an empty
|
||||
(null) key, e.g. `[ : value ]` is `[{null: value}]`. The parser raised "expected a YAML node" for
|
||||
the leading `:`; it now emits the empty-key mapping, mirroring the way `[ a: b ]` (a scalar key
|
||||
|
||||
@ -44,7 +44,9 @@ extension PureYAML.Parsing.Scanner {
|
||||
guard let character else {
|
||||
return true
|
||||
}
|
||||
return character == " " || isLineBreak(character)
|
||||
// A tab is separation white space in YAML (only indentation forbids it), so it ends an
|
||||
// indicator just as a space does: `---\tscalar`, `-\titem`, `?\tkey`.
|
||||
return character == " " || character == "\t" || isLineBreak(character)
|
||||
}
|
||||
|
||||
func isMappingValueBoundary(_ character: Character?) -> Bool {
|
||||
|
||||
24
Tests/IndicatorTabBoundaryTests.swift
Normal file
24
Tests/IndicatorTabBoundaryTests.swift
Normal file
@ -0,0 +1,24 @@
|
||||
@testable import PureYAML
|
||||
import Testing
|
||||
|
||||
/// A tab is separation white space in YAML (only indentation forbids a tab), so it ends a leading
|
||||
/// indicator exactly as a space does. A document marker, block entry, or explicit key followed by a
|
||||
/// tab is recognized as the indicator, not folded into a plain scalar.
|
||||
@Suite("Indicator tab boundary")
|
||||
struct IndicatorTabBoundaryTests {
|
||||
@Test("A document marker followed by a tab introduces an inline root scalar")
|
||||
func test_documentMarkerTab() throws {
|
||||
#expect(try PureYAML.parse("---\tscalar\n") == .string("scalar"))
|
||||
}
|
||||
|
||||
@Test("A block entry indicator followed by a tab still starts a sequence item")
|
||||
func test_blockEntryTab() throws {
|
||||
#expect(try PureYAML.parse("-\titem\n") == .sequence([.string("item")]))
|
||||
}
|
||||
|
||||
@Test("A space after an indicator is unchanged")
|
||||
func test_spaceStillWorks() throws {
|
||||
#expect(try PureYAML.parse("--- scalar\n") == .string("scalar"))
|
||||
#expect(try PureYAML.parse("- item\n") == .sequence([.string("item")]))
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user