com.skillw.asahi.internal.parser.prefix.top.StringParser.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Pouvoir Show documentation
Show all versions of Pouvoir Show documentation
Bukkit Script Engine Plugin.
package com.skillw.asahi.internal.parser.prefix.top
import com.skillw.asahi.api.annotation.AsahiTopParser
import com.skillw.asahi.api.member.lexer.AsahiLexer
import com.skillw.asahi.api.member.parser.prefix.TopPrefixParser
import com.skillw.asahi.api.member.quest.Quester
import com.skillw.asahi.api.quester
@AsahiTopParser
internal object StringParser : TopPrefixParser("string", 999) {
private val symbols = arrayOf('\'', '"')
override fun AsahiLexer.canParse(token: String): Boolean {
return isWrapping(token)
}
fun isWrapping(str: String): Boolean {
return str.first() in symbols && str.last() in symbols
}
fun content(str: String): String {
return if (isWrapping(str)) {
str.substring(1, str.lastIndex)
} else str
}
override fun AsahiLexer.parse(token: String): Quester {
return quester {
content(token)
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy