extension PureYAML.Parsing.LibYAML.Scanner { private typealias Classify = PureYAML.Parsing.LibYAML.CharacterClass /// Port of `yaml_parser_scan_anchor`. Scans an anchor (`&name`) or alias /// (`*name`): the name is a run of `IS_ALPHA` characters and must be non-empty /// and followed by a blank, the end of input, or one of the indicators that may /// terminate it. mutating func scanAnchor(isAnchor: Bool) throws -> PureYAML.Parsing.LibYAML.Token { let startMark = reader.mark reader.skip() var name = "" while let character = reader.peek(), Classify.isAlpha(character) { name.unicodeScalars.append(character) reader.skip() } let endMark = reader.mark guard !name.isEmpty, Classify.isBlankZ(reader.peek()) || isAnchorTerminator(reader.peek()) else { throw PureYAML.Parsing.LibYAML.ScannerError( context: isAnchor ? "while scanning an anchor" : "while scanning an alias", problem: "did not find expected alphabetic or numeric character", mark: startMark, ) } return PureYAML.Parsing.LibYAML.Token( type: isAnchor ? .anchor(name: name) : .alias(name: name), startMark: startMark, endMark: endMark, ) } private func isAnchorTerminator(_ scalar: Unicode.Scalar?) -> Bool { switch scalar { case "?", ":", ",", "]", "}", "%", "@", "`": true default: false } } }