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

com.skillw.asahi.internal.namespacing.prefix.lang.Variable.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.lazyQuester
import com.skillw.asahi.api.member.quest.Quester
import com.skillw.asahi.api.prefixParser
import com.skillw.asahi.api.quest

/**
 * @className Variable
 *
 * @author Glom
 * @date 2023/1/13 19:09 Copyright 2024 Glom. 
 */
@AsahiPrefix(["set"], "lang")
private fun set() = prefixParser {
    val key = next()
    when {
        expect("ifndef") -> {
            expect("to", "=")
            val value = quest()
            result {
                if (get(key) != null) return@result get(key)
                value.get()?.let {
                    context()[key] = it;
                } ?: context().remove(key)
            }
        }

        expect("by") && expect("lazy") -> {
            expect("to", "=");

            val block = quest>()
            result {
                lazyQuester {
                    block.get().also { result -> context()[key] = result }
                }.also { context()[key] = it }
            }
        }

        else -> {
            expect("to", "=")
            val value = quest()
            result {
                value.get()?.let {
                    context()[key] = it;
                } ?: context().remove(key)
            }
        }
    }
}

@AsahiPrefix(["has"], "lang")
private fun has() = prefixParser {
    val key = quest()
    result { get(key.get()) != null }
}

@AsahiPrefix(["get"], "lang")
private fun get() = prefixParser {
    val key = quest()
    result { get(key.get()) }
}

@AsahiPrefix(["delete"], "lang")
private fun delete() = prefixParser {
    val key = quest()
    result { remove(key.get()) }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy