all repos — min @ bae02ddf6ecc00f6ee991ab732c861260048f903

A small but practical concatenative programming language.

refactor(minim-repl) Using linenoise always; marked version as preview.
h3rald h3rald@h3rald.com
Fri, 03 Jun 2016 22:23:16 +0200
commit

bae02ddf6ecc00f6ee991ab732c861260048f903

parent

12fe4ab511b5fe1a2f48d16c9bea62ec82d9ebb4

1 files changed, 19 insertions(+), 25 deletions(-)

jump to
M minim.nimminim.nim

@@ -2,7 +2,8 @@ import streams, critbits, parseopt2, strutils, os

import core/parser, core/interpreter, - core/utils + core/utils, + vendor/linenoise import lib/lang, lib/stack,

@@ -13,12 +14,12 @@ lib/time,

lib/io, lib/sys -const version* = "1.0.0" +const version* = "1.0.0-preview" var REPL = false const prelude = "lib/prelude.min".slurp.strip const - USE_LINENOISE = true#(defined(i386) or defined(amd64)) + USE_LINENOISE = true let usage* = " MiNiM v" & version & " - a tiny concatenative system programming language" & """

@@ -34,27 +35,21 @@ Options:

-e, --evaluate Evaluate a minim program inline -h, --help Print this help -v, --version Print the program version - -i, --interactive Starts MiNiM's Read Eval Print Loop""" + -i, --interactive Start MiNiM's Read Eval Print Loop""" -when USE_LINENOISE: - import vendor/linenoise - proc completionCallback*(str: cstring, completions: ptr linenoiseCompletions) {.cdecl.}= - var words = ($str).split(" ") - var w = if words.len > 0: words.pop else: "" - var sep = "" - if words.len > 0: - sep = " " - for s in ROOT.symbols.keys: - if startsWith(s, w): - linenoiseAddCompletion completions, words.join(" ") & sep & s - proc prompt(s: string): string = - var res = linenoise(s) - discard $linenoiseHistoryAdd(res) - return $res -else: - proc prompt(s: string): string = - stdout.write(s) - return stdin.readLine +proc completionCallback*(str: cstring, completions: ptr linenoiseCompletions) {.cdecl.}= + var words = ($str).split(" ") + var w = if words.len > 0: words.pop else: "" + var sep = "" + if words.len > 0: + sep = " " + for s in ROOT.symbols.keys: + if startsWith(s, w): + linenoiseAddCompletion completions, words.join(" ") & sep & s +proc prompt(s: string): string = + var res = linenoise(s) + discard $linenoiseHistoryAdd(res) + return $res proc minimStream(s: Stream, filename: string) = var i = INTERPRETER

@@ -66,7 +61,7 @@ i.interpret()

i.close() proc minimString*(buffer: string) = - minimStream(newStringStream(buffer), "input") + minimStream(newStringStream(buffer), "input") proc minimFile*(filename: string) = var stream = newFileStream(filename, fmRead)

@@ -88,7 +83,6 @@ var s = newStringStream("")

i.open(s, "") echo "MiNiM v"&version&" - REPL initialized." i.eval prelude - echo "Prelude loaded." echo "-> Type 'exit' or 'quit' to exit." when USE_LINENOISE: linenoiseSetCompletionCallback completionCallback