all repos — min @ 7242a0ed9cce30ab96160fed1f7e34d5b49e5b3d

A small but practical concatenative programming language.

Re-added linenoise completion.
h3rald h3rald@h3rald.com
Sat, 16 Jul 2016 12:20:45 +0200
commit

7242a0ed9cce30ab96160fed1f7e34d5b49e5b3d

parent

73d51afbc6313727e28d9427204ea07a4ec43015

1 files changed, 14 insertions(+), 12 deletions(-)

jump to
M minim.nimminim.nim

@@ -50,17 +50,18 @@ -s, --server Start server remote command execution

-v, --version Print the program version -i, --interactive Start MiNiM's Read Eval Print Loop""" + +var CURRSCOPE*: ref MinScope + proc completionCallback*(str: cstring, completions: ptr linenoiseCompletions) {.cdecl.}= - discard - #var words = ($str).split(" ") - #var w = if words.len > 0: words.pop else: "" - #var sep = "" - #if words.len > 0: - # sep = " " - # TODO REDO - #for s in ROOT.symbols.keys: - # if startsWith(s, w): - # linenoiseAddCompletion completions, words.join(" ") & sep & s + var words = ($str).split(" ") + var w = if words.len > 0: words.pop else: "" + var sep = "" + if words.len > 0: + sep = " " + for s in CURRSCOPE.symbols.keys: + if startsWith(s, w): + linenoiseAddCompletion completions, words.join(" ") & sep & s proc prompt(s: string): string = var res = linenoise(s) discard $linenoiseHistoryAdd(res)

@@ -113,10 +114,11 @@ var s = newStringStream("")

i.open(s, "") echo "MiNiM v"&version&" - REPL initialized." echo "-> Type 'exit' or 'quit' to exit." - when USE_LINENOISE: - linenoiseSetCompletionCallback completionCallback var line: string while true: + when USE_LINENOISE: + CURRSCOPE = i.scope + linenoiseSetCompletionCallback completionCallback line = prompt(": ") i.parser.buf = $i.parser.buf & $line i.parser.bufLen = i.parser.buf.len