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

com.skillw.asahi.internal.namespacing.prefix.lang.math.Calculate.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.math

import com.skillw.asahi.api.AsahiAPI.analysis
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.pouvoir.util.calculate.CalcOperator.Companion.toCalcOperator

/**
 * @className Calculate
 *
 * @author Glom
 * @date 2023/1/14 0:31 Copyright 2024 Glom.
 */
@AsahiPrefix(["calculate", "calc"], "lang")
private fun calculate() = prefixParser {
    val formulaGetter = quest()
    result {
        val formula = formulaGetter.get().analysis(this, *namespaceNames())
        com.skillw.pouvoir.util.calculate(formula)
    }
}

@AsahiPrefix(["math"], "lang")
private fun math() = prefixParser {
    val numA = questDouble()
    val operator = questString().quester { it.first() }
    val numB = questDouble()
    result {
        operator.get().toCalcOperator().calc(numB.get(), numA.get())
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy