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

com.skillw.asahi.internal.parser.prefix.top.NamespaceCallParser.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.AsahiManager
import com.skillw.asahi.api.annotation.AsahiTopParser
import com.skillw.asahi.api.member.context.AsahiContext
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

@AsahiTopParser
internal object NamespaceCallParser : TopPrefixParser("namespace-call-function", 1) {
    override fun AsahiLexer.canParse(token: String): Boolean {
        if (!token.contains("::")) return false
        val splits = token.split("::")
        val namespace = AsahiManager.getNamespace(splits[0])
        return namespace.hasPrefix(splits[1])
    }

    override fun AsahiLexer.parse(token: String): Quester? {
        val splits = token.split("::")
        val namespace = AsahiManager.getNamespace(splits[0])
        val function = namespace.getPrefix(splits[1]) ?: return null
        return function.parseWith(this@parse) as Quester?
    }

    override fun  Quester.topQuester(): Quester {
        return object : Quester {
            override fun AsahiContext.execute(): R {
                return [email protected](this)
            }

            override fun toString(): String {
                return "Namespace Call Quester - $key ${this@topQuester}"
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy