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) {
|
2018-09-28 14:02:42 +02:00
|
|
|
components.append("\(type.string.capitalized) token: \(token)")
|
2018-08-24 18:42:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|