diff options
author | Lex Spoon <lex@lexspoon.org> | 2007-06-18 13:42:30 +0000 |
---|---|---|
committer | Lex Spoon <lex@lexspoon.org> | 2007-06-18 13:42:30 +0000 |
commit | 46285f430930ef03d8a8dabc125a5b4e1d9a6386 (patch) | |
tree | e18558aeb98bc818fb3a2879851c31fa2058823b /src/compiler | |
parent | 4dc591846225fb4a97aeaea15556d8132505eda3 (diff) | |
download | scala-46285f430930ef03d8a8dabc125a5b4e1d9a6386.tar.gz scala-46285f430930ef03d8a8dabc125a5b4e1d9a6386.tar.bz2 scala-46285f430930ef03d8a8dabc125a5b4e1d9a6386.zip |
factored out the choice of wrapper code, so tha...
factored out the choice of wrapper code, so that subclasses can tweak it
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/ScriptRunner.scala | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/src/compiler/scala/tools/nsc/ScriptRunner.scala b/src/compiler/scala/tools/nsc/ScriptRunner.scala index 5ce1a64d4d..f67fc15f80 100644 --- a/src/compiler/scala/tools/nsc/ScriptRunner.scala +++ b/src/compiler/scala/tools/nsc/ScriptRunner.scala @@ -152,15 +152,10 @@ class ScriptRunner { (Some(fullname.substring(0,idx)), fullname.substring(idx+1)) } - - /** Wrap a script file into a runnable object named - * <code>scala.scripting.Main</code>. + /** Code that is added to the beginning of a script file to make + * it a complete Scala compilation unit. */ - def wrappedScript( - objectName: String, - filename: String, - getSourceFile: PlainFile => SourceFile): SourceFile = - { + protected def preambleCode(objectName: String) = { val (maybePack, objName) = splitObjectName(objectName) val packageDecl = @@ -169,12 +164,29 @@ class ScriptRunner { case None => "" } + (packageDecl + + "object " + objName + " {\n" + + " def main(argv: Array[String]): Unit = {\n" + + " val args = argv;\n") + } + + /** Code that is added to the end of a script file to make + * it a complete Scala compilation unit. + */ + val endCode = "\n} }\n" + + + /** Wrap a script file into a runnable object named + * <code>scala.scripting.Main</code>. + */ + def wrappedScript( + objectName: String, + filename: String, + getSourceFile: PlainFile => SourceFile): SourceFile = + { val preamble = new SourceFile("<script preamble>", - (packageDecl + - "object " + objName + " {\n" + - " def main(argv: Array[String]): Unit = {\n" + - " val args = argv;\n").toCharArray) + preambleCode(objectName).toCharArray) val middle = { val f = new File(filename) @@ -183,7 +195,8 @@ class ScriptRunner { headerLength(filename), f.length.asInstanceOf[Int]) } - val end = new SourceFile("<script trailer>", "\n} }\n".toCharArray) + + val end = new SourceFile("<script trailer>", endCode.toCharArray) new CompoundSourceFile(preamble, middle, end) } |