splash/Sources/SplashTokenizer/TokenizerOutputFormat.swift

37 lines
841 B
Swift
Raw Normal View History

2018-08-24 18:42:07 +02:00
/**
* Splash
* Copyright (c) John Sundell 2018
* MIT license - see LICENSE.md
*/
import Foundation
import Splash
struct TokenizerOutputFormat: OutputFormat {
func makeBuilder() -> Builder {
return Builder()
}
}
extension TokenizerOutputFormat {
struct Builder: OutputBuilder {
private var components = [String]()
mutating func addToken(_ token: String, ofType type: TokenType) {
components.append("\(type.rawValue.capitalized) token: \(token)")
}
mutating func addPlainText(_ text: String) {
components.append("Plain text: \(text)")
}
mutating func addWhitespace(_ whitespace: String) {
// Ignore whitespace
}
func build() -> String {
return components.joined(separator: "\n")
}
}
}