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

commonMain.piacenti.dslmaker.structures.StepStack.kt Maven / Gradle / Ivy

Go to download

Kotlin multiplatform library to facilitate creation of DSLs with ANTLR or a simple built in parser

There is a newer version: 1.1.55
Show newest version
package piacenti.dslmaker.structures

import piacenti.dslmaker.abstraction.ProductionStep
import piacenti.dslmaker.removeLast

/**
 * @param 
 * @author Piacenti
 */
@Suppress("unused")
class StepStack {

    private val list = mutableListOf()
    fun getAsList(): List {
        return list.toList()
    }
    fun getFirstFoundInCallStackFromList(steps: Collection): ProductionStep? {
        for (i in list.size - 1 downTo -1 + 1) {
            for (step in steps) {
                if (step === list[i]) {
                    return list[i]
                }
            }

        }
        return null
    }

    /**
     * @param steps
     * @return
     */
    fun getFirstFoundInCallStackFromList(vararg steps: ProductionStep): ProductionStep? {
        for (i in list.size - 1 downTo -1 + 1) {
            for (step in steps) {
                if (step === list[i]) {
                    return list[i]
                }
            }

        }
        return null
    }

    /**
     * @return
     */
    fun removeLast(): StepStack {
        list.removeLast()
        return this
    }

    /**
     * @param e
     * @return
     */
    fun add(e: ProductionStep): StepStack {
        list.add(e)
        return this
    }

    override fun toString(): String {
        return "StepStack{" +
                "stack=" + list +
                '}'
    }

    fun addAll(generalStack: Collection): StepStack {
        list.addAll(generalStack)
        return this
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy