2

create-your-custom-scala-replからの内部 DSL 用の 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._")
    }
  }
}

addThunk2.11.* ではサポートされていないことに気付きました。

したがって、パーソナライズされた REPLにロードする方法はmyDSL.jar?import my.dsl._

4

1 に答える 1

4

「-i」のように、init コードをファイルに貼り付けることができます。

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 $  "
}

または:

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
}
于 2015-01-02T17:08:41.200 に答える