org.jetbrains.kotlinx.jupyter.libraries.LibraryResolutionInfoParser.kt Maven / Gradle / Ivy
package org.jetbrains.kotlinx.jupyter.libraries
import org.jetbrains.kotlinx.jupyter.api.libraries.LibraryResolutionInfo
import org.jetbrains.kotlinx.jupyter.api.libraries.Variable
import org.jetbrains.kotlinx.jupyter.exceptions.ReplLibraryLoadingException
import kotlin.script.experimental.api.ResultWithDiagnostics
import kotlin.script.experimental.api.asSuccess
abstract class LibraryResolutionInfoParser(val name: String, private val parameters: List) {
fun getInfo(args: List): LibraryResolutionInfo {
val map = when (val mapResult = substituteArguments(parameters, args)) {
is ResultWithDiagnostics.Success -> mapResult.value
is ResultWithDiagnostics.Failure -> throw ReplLibraryLoadingException(name, mapResult.reports.firstOrNull()?.message)
}
return getInfo(map)
}
abstract fun getInfo(args: Map): LibraryResolutionInfo
companion object {
fun make(name: String, parameters: List, getInfo: (Map) -> LibraryResolutionInfo): LibraryResolutionInfoParser {
return object : LibraryResolutionInfoParser(name, parameters) {
override fun getInfo(args: Map): LibraryResolutionInfo = getInfo(args)
}
}
private fun substituteArguments(parameters: List, arguments: List): ResultWithDiagnostics