src/Pure/System/scala.scala
changeset 75429 436747f1f632
parent 75417 2c861b196d52
child 75440 39011d0d2128
equal deleted inserted replaced
75427:323481d143c6 75429:436747f1f632
   110             if (class_loader == null) super.parentClassLoader
   110             if (class_loader == null) super.parentClassLoader
   111             else class_loader
   111             else class_loader
   112         }
   112         }
   113       }
   113       }
   114 
   114 
   115       def toplevel(source: String): List[String] = {
   115       def toplevel(interpret: Boolean, source: String): List[String] = {
   116         val out = new StringWriter
   116         val out = new StringWriter
   117         val interp = interpreter(new PrintWriter(out))
   117         val interp = interpreter(new PrintWriter(out))
   118         val marker = '\u000b'
   118         val marker = '\u000b'
   119         val ok = interp.withLabel(marker.toString) { (new interp.ReadEvalPrint).compile(source) }
   119         val ok =
       
   120           interp.withLabel(marker.toString) {
       
   121             if (interpret) interp.interpret(source) == Results.Success
       
   122             else (new interp.ReadEvalPrint).compile(source)
       
   123           }
   120         out.close()
   124         out.close()
   121 
   125 
   122         val Error = """(?s)^\S* error: (.*)$""".r
   126         val Error = """(?s)^\S* error: (.*)$""".r
   123         val errors =
   127         val errors =
   124           space_explode(marker, Library.strip_ansi_color(out.toString)).
   128           space_explode(marker, Library.strip_ansi_color(out.toString)).
   129     }
   133     }
   130   }
   134   }
   131 
   135 
   132   object Toplevel extends Fun_String("scala_toplevel") {
   136   object Toplevel extends Fun_String("scala_toplevel") {
   133     val here = Scala_Project.here
   137     val here = Scala_Project.here
   134     def apply(source: String): String = {
   138     def apply(arg: String): String = {
       
   139       val (interpret, source) =
       
   140         YXML.parse_body(arg) match {
       
   141           case Nil => (false, "")
       
   142           case List(XML.Text(source)) => (false, source)
       
   143           case body => import XML.Decode._; pair(bool, string)(body)
       
   144         }
   135       val errors =
   145       val errors =
   136         try { Compiler.context().toplevel(source) }
   146         try { Compiler.context().toplevel(interpret, source) }
   137         catch { case ERROR(msg) => List(msg) }
   147         catch { case ERROR(msg) => List(msg) }
   138       locally { import XML.Encode._; YXML.string_of_body(list(string)(errors)) }
   148       locally { import XML.Encode._; YXML.string_of_body(list(string)(errors)) }
   139     }
   149     }
   140   }
   150   }
   141 
   151