diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2016-06-01 13:04:32 +0200 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2016-06-01 13:04:32 +0200 |
commit | 6c4414ee36186ee0add924b1655c827ee83d180b (patch) | |
tree | 649f37934b3a342006f7eda6b2b1082c5f64526f /src/repl/scala/tools/nsc/interpreter/IMain.scala | |
parent | 8384ebda45724b5a4e47dd2a508ecbbc3bca56f4 (diff) | |
parent | 90215ce2b9cb99b5dea7c0ef474eea50755c0a40 (diff) | |
download | scala-6c4414ee36186ee0add924b1655c827ee83d180b.tar.gz scala-6c4414ee36186ee0add924b1655c827ee83d180b.tar.bz2 scala-6c4414ee36186ee0add924b1655c827ee83d180b.zip |
Merge commit '90215ce' into merge-2.11-to-2.12-june-1
Diffstat (limited to 'src/repl/scala/tools/nsc/interpreter/IMain.scala')
-rw-r--r-- | src/repl/scala/tools/nsc/interpreter/IMain.scala | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/repl/scala/tools/nsc/interpreter/IMain.scala b/src/repl/scala/tools/nsc/interpreter/IMain.scala index 763a8ccd1b..2f20a1cd0a 100644 --- a/src/repl/scala/tools/nsc/interpreter/IMain.scala +++ b/src/repl/scala/tools/nsc/interpreter/IMain.scala @@ -1,5 +1,5 @@ /* NSC -- new Scala compiler - * Copyright 2005-2013 LAMP/EPFL + * Copyright 2005-2016 LAMP/EPFL * @author Martin Odersky */ @@ -69,13 +69,14 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends lazy val isClassBased: Boolean = settings.Yreplclassbased.value - private[nsc] var printResults = true // whether to print result lines - private[nsc] var totalSilence = false // whether to print anything - private var _initializeComplete = false // compiler is initialized - private var _isInitialized: Future[Boolean] = null // set up initialization future - private var bindExceptions = true // whether to bind the lastException variable - private var _executionWrapper = "" // code to be wrapped around all lines - var partialInput: String = "" // code accumulated in multi-line REPL input + private[nsc] var printResults = true // whether to print result lines + private[nsc] var totalSilence = false // whether to print anything + private var _initializeComplete = false // compiler is initialized + private var _isInitialized: Future[Boolean] = null // set up initialization future + private var bindExceptions = true // whether to bind the lastException variable + private var _executionWrapper = "" // code to be wrapped around all lines + var partialInput: String = "" // code accumulated in multi-line REPL input + private var label = "<console>" // compilation unit name for reporting /** We're going to go to some trouble to initialize the compiler asynchronously. * It's critical that nothing call into it until it's been initialized or we will @@ -103,6 +104,12 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends try body finally if (!saved) settings.nowarn.value = false } + // Apply a temporary label for compilation (for example, script name) + def withLabel[A](temp: String)(body: => A): A = { + val saved = label + label = temp + try body finally label = saved + } // the expanded prompt but without color escapes and without leading newline, for purposes of indenting lazy val formatting = Formatting.forPrompt(replProps.promptText) @@ -749,7 +756,7 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends case Right(result) => Right(result) } - def compile(source: String): Boolean = compileAndSaveRun("<console>", source) + def compile(source: String): Boolean = compileAndSaveRun(label, source) /** The innermost object inside the wrapper, found by * following accessPath into the outer one. @@ -1098,7 +1105,7 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends var isIncomplete = false def parse = { reporter.reset() - val trees = newUnitParser(line).parseStats() + val trees = newUnitParser(line, label).parseStats() if (reporter.hasErrors) Error(trees) else if (isIncomplete) Incomplete(trees) else Success(trees) |