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

.10.dp.source-code.iloop.scala Maven / Gradle / Ivy

The newest version!
package cc.drx

import scala.tools.nsc.Settings
import scala.tools.nsc.interpreter._

//Note don't use default values here since this class needs to be basically reproduced in scala2.13's special implementation
/**Specific implementation for scala <= 2.12*/
class DrxILoop(settings:Settings, prompt:String, welcome:Option[String], prelude:Option[String], isVerbose:Boolean){

  private val promptString = prompt //prevent clobber from override value in ILoop
  private val welcomeOption = welcome //prevent clobber from override value in ILoop

  //--interactive repl
  private val iloop = new ILoop(){
    override def createInterpreter():Unit = { //example from keithohara sp5repl.scala
      super.createInterpreter()
      prelude foreach intp.quietRun
      ()
    }
    override lazy val prompt:String = promptString
    override def printWelcome:Unit = welcomeOption foreach echo

  }

  def launch:Unit = {
    // iloop.createInterpreter() //produces null pointer before 2.13

    iloop.process(settings) //--run the loop

    iloop.closeInterpreter()

    () //end of main
  }
}

class DrxIMain(settings:Settings){
  private def nullPrintWriter = new java.io.PrintWriter(Output.nullOutput.os)

  private val intp = new IMain(settings, nullPrintWriter)

  def complete(str:String):List[String] = Nil //no completion engine in 2.10??

  def completeDetail(str:String):List[String] = {complete(str); complete(str)}

  def !(str:String) = intp.interpret(str)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy