Files
swift-async-algorithms/Sources/AsyncSequenceValidation/Theme.swift
T
Philippe Hauslerandkperryua 7969001299 Add a detailed proposal-like guide for AsyncSequence validation (#56)
* Add a detailed proposal like guide for MarbleDiagram

* Slight spacing change

Co-authored-by: kperryua <kperry@apple.com>

* Fix some pluralization agreement

Co-authored-by: kperryua <kperry@apple.com>

* Clarify the testing of merge and add a future direction for unordered groups

* rename the diagram system to a more general 'validate' based name

* Spelling fixes

* Grammar fixes for credits

Co-authored-by: kperryua <kperry@apple.com>
2022-02-22 11:03:27 -08:00

52 lines
1.6 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Async Algorithms open source project
//
// Copyright (c) 2022 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//
public protocol AsyncSequenceValidationTheme {
func token(_ character: Character, inValue: Bool) -> AsyncSequenceValidationDiagram.Token
}
extension AsyncSequenceValidationTheme where Self == AsyncSequenceValidationDiagram.ASCIITheme {
public static var ascii: AsyncSequenceValidationDiagram.ASCIITheme {
return AsyncSequenceValidationDiagram.ASCIITheme()
}
}
extension AsyncSequenceValidationDiagram {
public enum Token {
case step
case error
case finish
case cancel
case beginValue
case endValue
case beginGroup
case endGroup
case skip
case value(String)
}
public struct ASCIITheme: AsyncSequenceValidationTheme {
public func token(_ character: Character, inValue: Bool) -> AsyncSequenceValidationDiagram.Token {
switch character {
case "-": return .step
case "^": return .error
case "|": return .finish
case ";": return .cancel
case "'": return inValue ? .endValue : .beginValue
case "[": return .beginGroup
case "]": return .endGroup
case " ": return .skip
default: return .value(String(character))
}
}
}
}