Skip to content

Commit

Permalink
repl history support
Browse files Browse the repository at this point in the history
  • Loading branch information
prakashk committed Mar 13, 2013
1 parent 937943c commit 0446b1c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/main/scala/org/moe/Moe.scala
Expand Up @@ -118,24 +118,28 @@ object Moe {

object REPL {
def enter (interpreter: Interpreter, runtime: MoeRuntime, dumpAST: Boolean = false): Unit = {
def isReplCommand(input: String) = input(0) == ':'

import jline.ConsoleReader
import jline.{ConsoleReader, History}

val cReader: ConsoleReader = new ConsoleReader
val prompt = "moe> "
val continuationPrompt = " |> "
def isReplCommand(input: String) = input(0) == ':'

var replOptions = Map(
"printOutput" -> true,
"dumpAST" -> dumpAST,
"prettyPrintAST" -> true
)

val historyFile = new File(System.getProperty("user.home") + File.separator + ".moereplhist")
val cReader: ConsoleReader = new ConsoleReader
cReader.setHistory(new History(historyFile))

val prompt = "moe> "
val continuationPrompt = "...| "

var partialInput: String = ""
while (true) {
val line = cReader readLine (if (partialInput == "") prompt else continuationPrompt)
line match {
case null => println(); return
case null => { println(); return }
case "exit" => return
case "" => ""
case _ => if (isReplCommand(line))
Expand Down

0 comments on commit 0446b1c

Please sign in to comment.