jeudi 12 mars 2015

How to evalulate xml literal using scala.tools.reflect.ToolBox in runtime?


Welcome to Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_25).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import scala.reflect.runtime.currentMirror
import scala.reflect.runtime.currentMirror

scala> import scala.tools.reflect.ToolBox
import scala.tools.reflect.ToolBox

scala> def eval(code: String) = {
| val toolbox = currentMirror.mkToolBox()
| toolbox.eval(toolbox.parse(code))
| }
eval: (code: String)Any

scala> eval("1 + 2")
res0: Any = 3

scala> eval("<a>b</a>")
scala.tools.reflect.ToolBoxError: reflective compilation has failed:

not found: value $scope
at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.throwIfErrors(ToolBoxFactory.scala:316)
at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.wrapInPackageAndCompile(ToolBoxFactory.scala:198)
at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.compile(ToolBoxFactory.scala:252)
at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$$anonfun$compile$2.apply(ToolBoxFactory.scala:429)
at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$$anonfun$compile$2.apply(ToolBoxFactory.scala:422)
at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$withCompilerApi$.liftedTree2$1(ToolBoxFactory.scala:355)
at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$withCompilerApi$.apply(ToolBoxFactory.scala:355)
at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.compile(ToolBoxFactory.scala:422)
at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.eval(ToolBoxFactory.scala:444)
at .eval(<console>:11)


What is the meaning of not fould: value $scope?






Aucun commentaire:

Enregistrer un commentaire