37 lines
841 B
Swift
37 lines
841 B
Swift
|
/**
|
||
|
* 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")
|
||
|
}
|
||
|
}
|
||
|
}
|