All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.skillw.asahi.internal.parser.prefix.top.StringParser.kt Maven / Gradle / Ivy

There is a newer version: 1.6.7-beta-6
Show newest version
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