LARA

package minijava
 
trait Reporter {
  private var foundErrors = false
 
  /** Simple warnings */
  def warn(msg: String) = outputErrorMsg("Warning", msg)
  def warn(msg: String, pos: Positional) = outputErrorMsg("Warning", msg, pos)
 
  /** Non-fatal errors. The compiler should call terminateIfErrors
   * before the errors can have an impact (for instance at the end
   * of the phase). */
  def error(msg: String) = { foundErrors = true; outputErrorMsg("Error", msg) }
  def error(msg: String, pos: Positional) = { foundErrors = true; outputErrorMsg("Error", msg, pos) }
 
  /** Errors from which the compiler cannot recover or continue. */
  def fatalError(msg: String) = { outputErrorMsg("Fatal error", msg); terminate }
  def fatalError(msg: String, pos: Positional) = { outputErrorMsg("Fatal error", msg, pos); terminate }
 
  /** Stops the compiler if they were non-fatal errors. */
  def terminateIfErrors = {
    if(foundErrors) {
      Console.err.println("There were errors.")
      terminate
    }
  }
 
  private def outputErrorMsg(prefix: String, msg: String) = {
    Console.err.println(prefix + ": " + msg)
  }
 
  private def outputErrorMsg(prefix: String, msg: String, pos: Positional) = {
    Console.err.println(prefix + "@(" + pos.row + "," + pos.col + ": " + msg)
  }
 
  private def terminate = {
    exit(-1)
  }
}