自定义Scala REPL问题 [英] Custom Scala REPL Issues

查看:1270
本文介绍了自定义Scala REPL问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用我在各种网站上找到的一些信息写一个基本的Scala REPL。我最基本的REPL实现看起来像这样,

I'm trying to write a basic Scala REPL using some information I found on various sites. My most basic REPL implementation looks like this,

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

object BillyREPL extends App {
  val settings = new Settings
  settings.usejavacp.value = true
  settings.deprecation.value = true

  new ILoop().process(settings)
}

使用以下版本设置,

import sbt._
import sbt.Keys._

object BillyREPLBuild extends Build {

  lazy val billyrepl = Project(
    id = "billyrepl",
    base = file("."),
    settings = Project.defaultSettings ++ Seq(
      name := "BillyREPL",
      organization := "tv.yobriefcasts",
      version := "0.1-SNAPSHOT",
      scalaVersion := "2.10.1",
      libraryDependencies ++= Seq(
        "org.scala-lang" % "scala-compiler" % "2.10.1",
        "org.scala-lang" % "scala-library" % "2.10.1"
      )
    )
  )
}

尝试运行此操作会导致一些警告和最终错误(我认为是由初始警告引起的),

Attempting to run this however leads to some warnings and eventual error (which I presume are caused by the initial warning),

Welcome to Scala version 2.10.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_12-ea).
Type in expressions to have them evaluated.
Type :help for more information.

scala>
Failed to initialize compiler: object scala.annotation.Annotation in compiler mirror not found.
** Note that as of 2.8 scala does not assume use of the java classpath.
** For the old behavior pass -usejavacp to scala, or if using a Settings
** object programatically, settings.usejavacp.value = true.

尝试读取/评估ANYTHING时出现的错误如下。我不知道这是否是由于一些额外的缺失依赖,我意识到错误消息说,这是不常见的,但我想知道如果有人处理这之前,我打开一个问题之前?

And the error when trying to read/evaluate ANYTHING is below. I'm not sure if this is due to some extra missing dependency and I do realise what the error message says suggests this is not common but I wondered if before I open an issue if anyone has dealt with this before?

2

Failed to initialize the REPL due to an unexpected error.
This is a bug, please, report it along with the error diagnostics printed below.
java.lang.NullPointerException
    at scala.tools.nsc.interpreter.ExprTyper$codeParser$.applyRule(ExprTyper.scala:24)
    at scala.tools.nsc.interpreter.ExprTyper$codeParser$.stmts(ExprTyper.scala:35)
    at scala.tools.nsc.interpreter.ExprTyper$$anonfun$parse$2.apply(ExprTyper.scala:43)
    at scala.tools.nsc.interpreter.ExprTyper$$anonfun$parse$2.apply(ExprTyper.scala:42)
    at scala.tools.nsc.reporters.Reporter.withIncompleteHandler(Reporter.scala:51)
    at scala.tools.nsc.interpreter.ExprTyper$class.parse(ExprTyper.scala:42)
    at scala.tools.nsc.interpreter.IMain$exprTyper$.parse(IMain.scala:1074)
    at scala.tools.nsc.interpreter.IMain.parse(IMain.scala:1078)
    at scala.tools.nsc.interpreter.IMain$$anonfun$showCodeIfDebugging$1.apply(IMain.scala:1168)
    at scala.tools.nsc.interpreter.IMain$$anonfun$showCodeIfDebugging$1.apply(IMain.scala:1168)
    at scala.tools.nsc.interpreter.IMain.beSilentDuring(IMain.scala:238)
    at scala.tools.nsc.interpreter.IMain.showCodeIfDebugging(IMain.scala:1168)
    at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compileAndSaveRun(IMain.scala:800)
    at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compile(IMain.scala:761)
    at scala.tools.nsc.interpreter.IMain.bind(IMain.scala:618)
    at scala.tools.nsc.interpreter.IMain.bind(IMain.scala:661)
    at scala.tools.nsc.interpreter.IMain$$anonfun$quietBind$1.apply(IMain.scala:660)
    at scala.tools.nsc.interpreter.IMain$$anonfun$quietBind$1.apply(IMain.scala:660)
    at scala.tools.nsc.interpreter.IMain.beQuietDuring(IMain.scala:232)
    at scala.tools.nsc.interpreter.IMain.quietBind(IMain.scala:660)
    at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1$$anonfun$apply$mcZ$sp$2.apply$mcV$sp(ILoop.scala:838)
    at scala.tools.nsc.interpreter.ILoopInit$class.runThunks(ILoopInit.scala:122)
    at scala.tools.nsc.interpreter.ILoop.runThunks(ILoop.scala:42)
    at scala.tools.nsc.interpreter.ILoopInit$class.postInitialization(ILoopInit.scala:95)
    at scala.tools.nsc.interpreter.ILoop.postInitialization(ILoop.scala:42)
    at scala.tools.nsc.interpreter.ILoopInit$$anonfun$createAsyncListener$1.apply$mcV$sp(ILoopInit.scala:63)
    at scala.tools.nsc.interpreter.ILoopInit$$anonfun$createAsyncListener$1.apply(ILoopInit.scala:60)
    at scala.tools.nsc.interpreter.ILoopInit$$anonfun$createAsyncListener$1.apply(ILoopInit.scala:60)
    at scala.tools.nsc.io.package$$anon$3.call(package.scala:40)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
.


推荐答案

嵌入REPL和项目使用 sbt 运行。由于类加载器问题(?),从sbt启动自定义解释器不起作用。

A problem occurs when you embed a REPL and the project is run with sbt. Because of class loader issues (?), launching a custom interpreter from sbt does not work.

您可以尝试使用 sbt-assembly ,看看是否正确启动。

You can try building a standalone with sbt-assembly and see if that starts up correctly.

这篇关于自定义Scala REPL问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆