summaryrefslogtreecommitdiff
path: root/src/repl/scala/tools/nsc/interpreter/IMain.scala
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2016-05-27 14:43:22 -0700
committerSom Snytt <som.snytt@gmail.com>2016-06-02 17:04:31 -0700
commitfe61bcf99c0c10054066f7ff41e4c7f44cf02e5d (patch)
tree341cc2ee54d3f8e07cc52ca6710e916d7b02baf8 /src/repl/scala/tools/nsc/interpreter/IMain.scala
parent461c896581a6e16d1b79e91e9322eb2d14dc53d2 (diff)
downloadscala-fe61bcf99c0c10054066f7ff41e4c7f44cf02e5d.tar.gz
scala-fe61bcf99c0c10054066f7ff41e4c7f44cf02e5d.tar.bz2
scala-fe61bcf99c0c10054066f7ff41e4c7f44cf02e5d.zip
SI-9104 Autodetect raw pastage
If `-raw` is not supplied explicitly to REPL `:paste`, see if the code text starts with `package` keyword or else see if it parses to a named package (to cope with leading commentary). In that case, take it as raw. But parse only on suspect comment slash. It's only worth parsing for a package if there's a chance that package keyword is buried behind comments. Small refactors to the `paste` object.
Diffstat (limited to 'src/repl/scala/tools/nsc/interpreter/IMain.scala')
-rw-r--r--src/repl/scala/tools/nsc/interpreter/IMain.scala16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/repl/scala/tools/nsc/interpreter/IMain.scala b/src/repl/scala/tools/nsc/interpreter/IMain.scala
index 2f20a1cd0a..44784aa953 100644
--- a/src/repl/scala/tools/nsc/interpreter/IMain.scala
+++ b/src/repl/scala/tools/nsc/interpreter/IMain.scala
@@ -1101,7 +1101,7 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
case class Incomplete(trees: List[Tree]) extends Result
case class Success(trees: List[Tree]) extends Result
- def apply(line: String): Result = debugging(s"""parse("$line")""") {
+ def apply(line: String): Result = debugging(s"""parse("$line")""") {
var isIncomplete = false
def parse = {
reporter.reset()
@@ -1110,8 +1110,18 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
else if (isIncomplete) Incomplete(trees)
else Success(trees)
}
- currentRun.parsing.withIncompleteHandler((_, _) => isIncomplete = true) {parse}
-
+ currentRun.parsing.withIncompleteHandler((_, _) => isIncomplete = true)(parse)
+ }
+ // code has a named package
+ def packaged(line: String): Boolean = {
+ def parses = {
+ reporter.reset()
+ val tree = newUnitParser(line).parse()
+ !reporter.hasErrors && {
+ tree match { case PackageDef(Ident(id), _) => id != nme.EMPTY_PACKAGE_NAME case _ => false }
+ }
+ }
+ beSilentDuring(parses)
}
}