updated some commments in interpreter
git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@9687 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
parent
ef96a8dc33
commit
bac5360d90
|
@ -232,7 +232,14 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter)
|
|||
def compileString(code: String): Boolean =
|
||||
compileSources(List(new SourceFile("<script>", code.toCharArray)))
|
||||
|
||||
/** build a request from the user. "trees" is "line" after being parsed. */
|
||||
/** Build a request from the user. <code>trees</code> is <code>line</code>
|
||||
* after being parsed.
|
||||
*
|
||||
* @param trees ..
|
||||
* @param line ..
|
||||
* @param lineName ..
|
||||
* @return ..
|
||||
*/
|
||||
private def buildRequest(trees: List[Tree], line: String, lineName: String): Request =
|
||||
trees match {
|
||||
/* This case for assignments is more specialized than desirable: it only
|
||||
|
@ -262,12 +269,13 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter)
|
|||
* reporter. Values defined are available for future interpreted
|
||||
* strings.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* The return value is whether the line was interpreter successfully,
|
||||
* e.g. that there were no parse errors.
|
||||
* </p>
|
||||
*
|
||||
* @param line ...
|
||||
* @return ...
|
||||
*/
|
||||
def interpret(line: String): IR.Result = {
|
||||
// parse
|
||||
|
@ -301,7 +309,7 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter)
|
|||
if (succeeded)
|
||||
prevRequests += req
|
||||
|
||||
if(succeeded) IR.Success else IR.Error
|
||||
if (succeeded) IR.Success else IR.Error
|
||||
}
|
||||
|
||||
/** A counter used for numbering objects created by bind() */
|
||||
|
@ -367,8 +375,8 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter)
|
|||
Interpreter.deleteRecursively(classfilePath)
|
||||
|
||||
/** A traverser that finds all mentioned identifiers, i.e. things
|
||||
that need to be imported.
|
||||
It might return extra names. */
|
||||
* that need to be imported. It might return extra names.
|
||||
*/
|
||||
private class ImportVarsTraverser(definedVars: List[Name]) extends Traverser {
|
||||
val importVars = new HashSet[Name]()
|
||||
|
||||
|
@ -671,8 +679,8 @@ object Interpreter {
|
|||
*/
|
||||
def deleteRecursively(path: File): Unit = {
|
||||
path match {
|
||||
case _ if (!path.exists) => ()
|
||||
case _ if (path.isDirectory) =>
|
||||
case _ if !path.exists => {}
|
||||
case _ if path.isDirectory =>
|
||||
for (val p <- path.listFiles)
|
||||
deleteRecursively(p)
|
||||
path.delete
|
||||
|
|
|
@ -73,7 +73,7 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
|
|||
}
|
||||
|
||||
/** print a friendly help message */
|
||||
def printHelp = {
|
||||
def printHelp {
|
||||
out.println("This is an interpreter for Scala.")
|
||||
out.println("Type in expressions to have them evaluated.")
|
||||
out.println("Type :compile followed by a filename to compile a complete Scala file.")
|
||||
|
@ -84,7 +84,7 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
|
|||
}
|
||||
|
||||
/** Print a welcome message */
|
||||
def printWelcome = {
|
||||
def printWelcome {
|
||||
out.println("This is an interpreter for Scala.")
|
||||
out.println("Type in expressions to have them evaluated.")
|
||||
out.println("Type :help for more information.")
|
||||
|
@ -92,15 +92,15 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
|
|||
|
||||
/** The main read-eval-print loop for the interpereter. It calls
|
||||
* <code>command()</code> for each line of input, and stops when
|
||||
* <code>command()</code> returns false.
|
||||
* <code>command()</code> returns <code>false</code>.
|
||||
*/
|
||||
def repl(): Unit = {
|
||||
def repl {
|
||||
var firstTime = true
|
||||
while(true) {
|
||||
if(interactive) {
|
||||
while (true) {
|
||||
if (interactive) {
|
||||
out.print("\nscala> ")
|
||||
out.flush
|
||||
if(firstTime) {
|
||||
if (firstTime) {
|
||||
interpreter.prime
|
||||
firstTime = false
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
|
|||
val Pair(keepGoing, finalLineMaybe) = command(line)
|
||||
|
||||
if (!keepGoing)
|
||||
return ()
|
||||
return
|
||||
|
||||
finalLineMaybe match {
|
||||
case Some(finalLine) => addReplay(finalLine)
|
||||
|
@ -122,13 +122,13 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
|
|||
}
|
||||
|
||||
/** interpret all lines from a specified file */
|
||||
def interpretAllFrom(filename: String): Unit = {
|
||||
def interpretAllFrom(filename: String) {
|
||||
val fileIn = try {
|
||||
new FileReader(filename)
|
||||
} catch {
|
||||
case _:IOException =>
|
||||
out.println("Error opening file: " + filename)
|
||||
return ()
|
||||
return
|
||||
}
|
||||
val oldIn = in
|
||||
val oldInteractive = interactive
|
||||
|
@ -137,7 +137,7 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
|
|||
interactive = false
|
||||
out.println("Loading " + filename + "...")
|
||||
out.flush
|
||||
repl()
|
||||
repl
|
||||
} finally {
|
||||
in = oldIn
|
||||
interactive = oldInteractive
|
||||
|
@ -146,7 +146,7 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
|
|||
}
|
||||
|
||||
/** create a new interpreter and replay all commands so far */
|
||||
def replay = {
|
||||
def replay {
|
||||
closeInterpreter
|
||||
createInterpreter
|
||||
for (val cmd <- replayCommands) {
|
||||
|
@ -219,22 +219,21 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
|
|||
interpreter.interpret(code) match {
|
||||
case IR.Success => Some(code)
|
||||
case IR.Error => None
|
||||
case IR.Incomplete => {
|
||||
if(interactive && code.endsWith("\n\n")) {
|
||||
case IR.Incomplete =>
|
||||
if (interactive && code.endsWith("\n\n")) {
|
||||
out.println("Two blank lines seen. Aborting this expression.")
|
||||
None
|
||||
} else {
|
||||
if(interactive) {
|
||||
if (interactive) {
|
||||
out.print(" | ")
|
||||
out.flush
|
||||
}
|
||||
val nextLine = in.readLine
|
||||
if(nextLine == null)
|
||||
if (nextLine == null)
|
||||
None // end of file
|
||||
else
|
||||
interpretStartingWith(code + "\n" + nextLine)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -259,7 +258,7 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
|
|||
}
|
||||
|
||||
/** process command-line arguments and do as they request */
|
||||
def main(args: Array[String]): unit = {
|
||||
def main(args: Array[String]) {
|
||||
def error1(msg: String): Unit = out.println("scala: " + msg)
|
||||
val command = new InterpreterCommand(List.fromArray(args), error1)
|
||||
|
||||
|
@ -268,9 +267,8 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
|
|||
// explicitly requested a help listing
|
||||
out.println(command.usageMsg)
|
||||
out.flush
|
||||
return ()
|
||||
}
|
||||
|
||||
main(command.settings)
|
||||
else
|
||||
main(command.settings)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,25 @@
|
|||
/* NSC -- new Scala compiler
|
||||
* Copyright 2005-2007 LAMP/EPFL
|
||||
* @author Martin Odersky
|
||||
*/
|
||||
// $Id: $
|
||||
|
||||
package scala.tools.nsc
|
||||
|
||||
object InterpreterResults {
|
||||
/** A result from interpreting one line of input */
|
||||
|
||||
/** A result from interpreting one line of input. */
|
||||
abstract sealed class Result
|
||||
|
||||
/** The line was interpreted successfully */
|
||||
/** The line was interpreted successfully. */
|
||||
case object Success extends Result
|
||||
|
||||
/** The line was erroneous in some way */
|
||||
/** The line was erroneous in some way. */
|
||||
case object Error extends Result
|
||||
|
||||
/** The input was incomplete. The caller should request more
|
||||
* input. */
|
||||
* input.
|
||||
*/
|
||||
case object Incomplete extends Result
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* NSC -- new Scala compiler
|
||||
* Copyright 2005-2006 LAMP/EPFL
|
||||
* Copyright 2005-2007 LAMP/EPFL
|
||||
* @author Lex Spoon
|
||||
*/
|
||||
// $Id$
|
||||
|
@ -8,7 +8,7 @@ package scala.tools.nsc
|
|||
|
||||
/** A command-line wrapper for the interpreter */
|
||||
object MainInterpreter {
|
||||
def main(args: Array[String]): Unit = {
|
||||
def main(args: Array[String]) {
|
||||
(new InterpreterLoop).main(args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue