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

com.skillw.asahi.internal.namespacing.prefix.lang.Script.kt Maven / Gradle / Ivy

There is a newer version: 1.6.7-beta-6
Show newest version
package com.skillw.asahi.internal.namespacing.prefix.lang

import com.skillw.asahi.api.annotation.AsahiPrefix
import com.skillw.asahi.api.prefixParser
import com.skillw.asahi.api.quest
import com.skillw.asahi.api.quester
import com.skillw.asahi.api.script.linking.NativeFunction
import com.skillw.pouvoir.util.toArgs


private val funcRegex = Regex(".*?([a-zA-Z_$]+).*?\\((.*?)\\).*?")

@AsahiPrefix(["fun", "def"], "lang")
private fun `fun`() = prefixParser {
    val result = funcRegex.find(splitBeforeString("{"))!!
    val name = result.groups[1]?.value!!
    val params = result.groups[2]?.value!!.toArgs().filter { it.isNotEmpty() && it.isNotBlank() }.toTypedArray()
    val content = parseScript()
    result {
        NativeFunction.create(name, params, content).also { context().addInvoker(name, it) }
    }
}

@AsahiPrefix(["invoke", "call"], "lang")
private fun invoke() = prefixParser {
    val func = quest()
    val paramsGetter = if (peek() == "[") quest>() else quester { emptyArray() }
    result {
        val params = paramsGetter.get()
        invoke(func.get(), *params)
    }
}

@AsahiPrefix(["import"], "lang")
private fun import() = prefixParser {
    val paths = if (peek() == "[") quest() else quest().quester { arrayOf(it) }
    result {
        import(*paths.get())
    }
}






© 2015 - 2024 Weber Informatics LLC | Privacy Policy