PureYAML/Sources/Parsing/LibYAML.Parser.Helpers.swift
Mihaela Mihaljevic 521062d974 feat(parsing): port libyaml parser state machine to Swift
Ports parser.c: the one-event-at-a-time state machine that turns the
scanner's token stream into the YAML event stream. Covers stream and
document framing, directive processing with %TAG handle resolution and
default handles, the node property/tag/anchor production, block and
indentless sequences, block mappings, and flow sequences and mappings
including the single-pair `?` mapping forms.

Output verified against the libyaml reference event dumper: the empty
mapping value, %TAG resolution, and shorthand tags all match byte for
byte. 331 tests, no regression.
2026-06-24 17:05:59 +02:00

51 lines
1.1 KiB
Swift

extension PureYAML.Parsing.LibYAML.Parser {
func isBlockEntry(_ token: Token) -> Bool {
if case .blockEntry = token.type {
return true
}
return false
}
func isBlockEnd(_ token: Token) -> Bool {
if case .blockEnd = token.type {
return true
}
return false
}
func isKey(_ token: Token) -> Bool {
if case .key = token.type {
return true
}
return false
}
func isValue(_ token: Token) -> Bool {
if case .value = token.type {
return true
}
return false
}
func isFlowEntry(_ token: Token) -> Bool {
if case .flowEntry = token.type {
return true
}
return false
}
func isFlowSequenceEnd(_ token: Token) -> Bool {
if case .flowSequenceEnd = token.type {
return true
}
return false
}
func isFlowMappingEnd(_ token: Token) -> Bool {
if case .flowMappingEnd = token.type {
return true
}
return false
}
}