all repos — min @ 292224a42ebc3e1e47d3b1501d032a65ee3e7c66

A small but practical concatenative programming language.

Implemented line editing in the REPL via linenoise.
h3rald h3rald@h3rald.com
Mon, 08 Dec 2014 17:15:21 +0100
commit

292224a42ebc3e1e47d3b1501d032a65ee3e7c66

parent

13cc78a8e730572bcde7c529c288f2374437359a

3 files changed, 12 insertions(+), 6 deletions(-)

jump to
M interpreter.niminterpreter.nim

@@ -1,5 +1,5 @@

import streams, strutils, tables -import parser +import parser, linenoise type TMinInterpreter* = object
M linenoise.nimlinenoise.nim

@@ -54,7 +54,7 @@ #

# Sets the current tab completion handler and returns the previous one, or NULL # if no prior one has been set. # - proc linenoiseSetCompletionCallback(a: linenoiseCompletionCallback): linenoiseCompletions; + proc linenoiseSetCompletionCallback*(a: linenoiseCompletionCallback): linenoiseCompletions; # # Adds a copy of the given string to the given completion list. The copy is owned # by the linenoiseCompletions object.
M minim.nimminim.nim

@@ -51,6 +51,11 @@ stderr.writeln("Error - Cannot read from "& filename)

stderr.flushFile() minimStream(stream, filename) +proc completionCallback*(str: cstring, completions: ptr linenoiseCompletions) = + for s in SYMBOLS.keys: + if startsWith(s, $str): + linenoiseAddCompletion completions, s + proc minimRepl*() = var i = newMinInterpreter(debugging) var s = newStringStream("")

@@ -60,12 +65,13 @@ echo "MiNiM v"&version&" - REPL initialized."

i.eval prelude echo "Prelude loaded." echo "-> Press Ctrl+C to exit." - var line: string + discard linenoiseSetCompletionCallback completionCallback + var line: cstring while true: - stdout.write(": ") - line = stdin.readLine() + line = linenoise(": ") + discard linenoiseHistoryAdd line s.writeln(line) - i.parser.buf = $i.parser.buf & line + i.parser.buf = $i.parser.buf & $line i.parser.bufLen = i.parser.buf.len discard i.parser.getToken() try: