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

commonMain.dsl.Generator.kt Maven / Gradle / Ivy

The newest version!
package org.openrndr.orsl.shadergenerator.dsl


val generatorStack = ArrayDeque()
interface Generator {
    fun emit(code: String) {
        emit("", code)
    }

    fun emit(symbol: String, code: String) {
        if (code.isNotBlank()) {
            if (symbol.isBlank() || symbol !in declaredSymbols) {
                this.code += code.trimEnd() + "\n"
                if (symbol.isNotBlank()) {
                    declaredSymbols.add(symbol)
                }
            }
        }
    }
    fun emitPreamble(code: String) {
        emitPreamble("", code)
    }

    fun emitPreamble(symbol: String, code: String) {
        if (code.isNotBlank()) {
            if (symbol.isBlank() || symbol !in declaredSymbols) {
                this.preamble += code.trimEnd() + "\n"
                if (symbol.isNotBlank()) {
                    declaredSymbols.add(symbol)
                }
            }
        }
    }


    fun push() {
        generatorStack.addLast(this)
    }

    fun pop() {
        generatorStack.removeLast()
    }

    val declaredSymbols: MutableSet
    var code: String
    var preamble: String
}

fun activeGenerator():Generator = generatorStack.lastOrNull() ?: error("no active generator")




© 2015 - 2024 Weber Informatics LLC | Privacy Policy