com.skillw.asahi.api.member.lexer.tokenizer.ScriptTokenizer.kt Maven / Gradle / Ivy
package com.skillw.asahi.api.member.lexer.tokenizer
import com.skillw.asahi.internal.lexer.Tokenizer
/**
* @className MultiLine
*
* @author Glom
* @date 2023/1/19 16:28 Copyright 2024 Glom.
*/
class ScriptTokenizer {
private val tokens = ArrayList()
private val indexesToLine = HashMap()
private val scriptGen: () -> String
private constructor(script: String) {
this.scriptGen = { script }
val (tokens, indexesToLine) = Tokenizer.prepareTokens(script)
this.tokens.addAll(tokens)
this.indexesToLine.putAll(indexesToLine)
}
private constructor(tokens: Collection) {
this.scriptGen = { tokens.joinToString(" ") }
val (tokensTemp, indexesToLine) = Tokenizer.prepareTokens(tokens)
this.tokens.addAll(tokensTemp)
this.indexesToLine.putAll(indexesToLine)
}
fun tokens(): List {
return tokens
}
fun script(): String {
return scriptGen()
}
fun getLine(index: Int): Line {
return indexesToLine.filterKeys { index in it }.values.first()
}
fun info(message: String, index: Int): String {
return Tokenizer.prepareInfo(message, index, this)
}
companion object {
@JvmStatic
fun of(origin: String): ScriptTokenizer {
return ScriptTokenizer(origin)
}
@JvmStatic
fun of(tokens: Collection): ScriptTokenizer {
return ScriptTokenizer(tokens)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy