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

org.jetbrains.kotlinx.jupyter.magics.MagicsProcessor.kt Maven / Gradle / Ivy

Go to download

Implementation of REPL compiler and preprocessor for Jupyter dialect of Kotlin (IDE-compatible)

There is a newer version: 0.12.0-290
Show newest version
package org.jetbrains.kotlinx.jupyter.magics

import org.jetbrains.kotlinx.jupyter.api.CodePreprocessor
import org.jetbrains.kotlinx.jupyter.api.KotlinKernelHost
import org.jetbrains.kotlinx.jupyter.exceptions.KernelInternalObject

class MagicsProcessor(
    private val handler: LibrariesAwareMagicsHandler,
    parseOutCellMarker: Boolean = false,
) : CodePreprocessor, AbstractMagicsProcessor(parseOutCellMarker), KernelInternalObject {
    fun processMagics(
        code: String,
        parseOnly: Boolean = false,
        tryIgnoreErrors: Boolean = false,
    ): CodePreprocessor.Result {
        val magics = magicsIntervals(code)

        for (magicRange in magics) {
            processSingleMagic(code, handler, magicRange, parseOnly, tryIgnoreErrors)
        }
        return CodePreprocessor.Result(getCleanCode(code, magics), handler.getLibraries())
    }

    override fun process(
        code: String,
        host: KotlinKernelHost,
    ): CodePreprocessor.Result {
        return processMagics(code)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy