From c4f1e1c3fedd9da3b506e6536c9c84d9f6285e2d Mon Sep 17 00:00:00 2001 From: michelou Date: Thu, 23 Mar 2006 13:59:03 +0000 Subject: hide stack trace in error messages when handlin... hide stack trace in error messages when handling arguments in Scala interpreter --- src/compiler/scala/tools/nsc/CompilerCommand.scala | 45 +++++++++++----------- src/compiler/scala/tools/nsc/Interpreter.scala | 5 ++- .../scala/tools/nsc/InterpreterCommand.scala | 8 +++- src/compiler/scala/tools/nsc/MainInterpreter.scala | 21 ++++++---- 4 files changed, 46 insertions(+), 33 deletions(-) diff --git a/src/compiler/scala/tools/nsc/CompilerCommand.scala b/src/compiler/scala/tools/nsc/CompilerCommand.scala index ddf3165ac3..4f953ba12b 100644 --- a/src/compiler/scala/tools/nsc/CompilerCommand.scala +++ b/src/compiler/scala/tools/nsc/CompilerCommand.scala @@ -1,35 +1,36 @@ -/* NSC -- new scala compiler - * Copyright 2005 LAMP/EPFL +/* NSC -- new Scala compiler + * Copyright 2005-2006 LAMP/EPFL * @author Martin Odersky */ // $Id$ -package scala.tools.nsc; + +package scala.tools.nsc /** A class representing command line info for scalac */ class CompilerCommand(arguments: List[String], error: String => unit, interactive: boolean) { - private var fs: List[String] = List(); + private var fs: List[String] = List() /** All files to compile */ - def files: List[String] = fs.reverse; + def files: List[String] = fs.reverse /** The applicable settings */ - val settings: Settings = new Settings(error); + val settings: Settings = new Settings(error) /** The name of the command */ - val cmdName = "scalac"; + val cmdName = "scalac" /** The file extension of files that the compiler can process */ - val fileEnding = ".scala"; + val fileEnding = ".scala" /** A message explaining usage and options */ def usageMsg: String = { val helpSyntaxColumnWidth: int = Iterable.max(settings.allSettings map (. helpSyntax.length())); def format(s: String): String = { - val buf = new StringBuffer(); - buf.append(s); - var i = s.length(); + val buf = new StringBuffer() + buf.append(s) + var i = s.length() while (i < helpSyntaxColumnWidth) { buf.append(' '); i = i + 1 } buf.toString() } @@ -37,34 +38,34 @@ class CompilerCommand(arguments: List[String], error: String => unit, interactiv .map(setting => format(setting.helpSyntax) + " " + setting.helpDescription) .mkString( - "Usage: " + cmdName + " \n" + - "where possible options include: \n ", - "\n ", - "\n"); + "Usage: " + cmdName + " \n" + + "where possible options include: \n ", + "\n ", + "\n"); } // initialization - var args = arguments; - var ok = true; + var args = arguments + var ok = true while (!args.isEmpty && ok) { - val args0 = args; + val args0 = args if (args.head.startsWith("-")) { if (interactive) { - error("no options can be given in interactive mode"); + error("no options can be given in interactive mode") ok = false } else { for (val setting <- settings.allSettings) args = setting.tryToSet(args); if (args eq args0) { - error("unknown option: '" + args.head + "'"); + error("unknown option: '" + args.head + "'") ok = false } } } else if (args.head.endsWith(fileEnding)) { - fs = args.head :: fs; + fs = args.head :: fs args = args.tail } else { - error("don't know what to do with " + args.head); + error("don't know what to do with " + args.head) ok = false } } diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala index 3eae5d9c23..6a8258b02c 100644 --- a/src/compiler/scala/tools/nsc/Interpreter.scala +++ b/src/compiler/scala/tools/nsc/Interpreter.scala @@ -1,8 +1,9 @@ -/* NSC -- new scala compiler - * Copyright 2005 LAMP/EPFL +/* NSC -- new Scala compiler + * Copyright 2005-2006 LAMP/EPFL * @author Martin Odersky */ // $Id$ + package scala.tools.nsc import reporters.Reporter diff --git a/src/compiler/scala/tools/nsc/InterpreterCommand.scala b/src/compiler/scala/tools/nsc/InterpreterCommand.scala index d25202dd3b..2ea52a322f 100644 --- a/src/compiler/scala/tools/nsc/InterpreterCommand.scala +++ b/src/compiler/scala/tools/nsc/InterpreterCommand.scala @@ -1,8 +1,14 @@ +/* NSC -- new Scala compiler + * Copyright 2005-2006 LAMP/EPFL + * @author Martin Odersky + */ +// $Id: $ + package scala.tools.nsc /** a command line for the interpreter */ class InterpreterCommand(arguments: List[String], error: String => unit) extends CompilerCommand(arguments, error, false) { - override val cmdName = "scalaint" + override val cmdName = "scalaint" override val fileEnding = ".scalaint" } diff --git a/src/compiler/scala/tools/nsc/MainInterpreter.scala b/src/compiler/scala/tools/nsc/MainInterpreter.scala index b6b43acc06..e98d5ace68 100644 --- a/src/compiler/scala/tools/nsc/MainInterpreter.scala +++ b/src/compiler/scala/tools/nsc/MainInterpreter.scala @@ -1,8 +1,7 @@ /* NSC -- new Scala compiler * Copyright 2005-2006 LAMP/EPFL - * @author emir + * @author Burak Emir */ - // $Id$ package scala.tools.nsc @@ -40,11 +39,11 @@ class InterpreterLoop(in: BufferedReader, out: PrintWriter) { out.print("\nscala> ") out.flush var line = in.readLine() - if(line == null) + if (line == null) return () // assumes null means EOF val keepGoing = command(line) - if(!keepGoing) + if (!keepGoing) return () // the evpr function said to stop } } @@ -71,7 +70,7 @@ class InterpreterLoop(in: BufferedReader, out: PrintWriter) { } if (fileIn == null) return () val in = new BufferedReader(fileIn) - while(true) { + while (true) { val line = in.readLine if (line == null) { fileIn.close @@ -120,11 +119,17 @@ class InterpreterLoop(in: BufferedReader, out: PrintWriter) { * parentClassLoader0, and the parentClassLoader method in Interpreter */ var uglinessxxx: ClassLoader = _ - def parentClassLoader0 : ClassLoader = uglinessxxx; + def parentClassLoader0: ClassLoader = uglinessxxx - /** process command-line arguments and do as they request */ + /** process command-line arguments and do as they request */ def main(args: Array[String]): unit = { - val command = new InterpreterCommand(List.fromArray(args), error) + def error1(msg: String): Unit = out.println("scalaint: " + msg) + val command = new InterpreterCommand(List.fromArray(args), error1) + if (!command.ok) { + // some error occured while processing the arguments + out.flush() + return () + } reporter.prompt = command.settings.prompt.value if (command.settings.help.value) { -- cgit v1.2.3