On personalizing Scala REPL for internal DSL, from create-your-custom-scala-repl
import scala.tools.nsc.Settings
import scala.tools.nsc.interpreter.ILoop
object TestConsole extends App {
val settings = new Settings
settings.usejavacp.value = true
settings.deprecation.value = true
new SampleILoop().process(settings)
}
class SampleILoop extends ILoop {
override def prompt = "myDSL $ "
addThunk {
intp.beQuietDuring {
intp.addImports("my.dsl._")
}
}
}
noticed that addThunk
is not supported in 2.11.* .
Thus how to load myDSL.jar
or import my.dsl._
into a personalized REPL ?
You can stick init code in a file, similar to "-i":
import scala.tools.nsc.Settings
import scala.tools.nsc.interpreter.ILoop
object TestConsole extends App {
val settings = new Settings
settings.usejavacp.value = true
settings.deprecation.value = true
new sys.SystemProperties += ("scala.repl.autoruncode" -> "myrepl.init")
new SampleILoop().process(settings)
}
class SampleILoop extends ILoop {
override def prompt = "myDSL $ "
}
Or:
object TestConsole extends App {
val settings = new Settings
settings.usejavacp.value = true
settings.deprecation.value = true
new sys.SystemProperties += (
"scala.repl.autoruncode" -> "myrepl.init",
"scala.shell.prompt" -> "myDSL $ "
)
new scala.tools.nsc.interpreter.ILoop process settings
}