Implemented additional sigil completions.
h3rald h3rald@h3rald.com
Sun, 04 Sep 2016 22:09:45 +0200
4 files changed,
60 insertions(+),
1 deletions(-)
M
core/interpreter.nim
→
core/interpreter.nim
@@ -35,6 +35,8 @@ return false
proc delSymbol*(scope: ref MinScope, key: string): bool {.discardable.}= if scope.symbols.hasKey(key): + if scope.symbols[key].sealed: + raiseInvalid("Symbol '$1' is sealed." % key) scope.symbols.excl(key) return true return false
M
lib/min_lang.nim
→
lib/min_lang.nim
@@ -490,6 +490,13 @@ raiseUndefined("Symbol '$1' not found." % sym)
json.delete(sym) MINIMSYMBOLS.writeFile(json.pretty) + .symbol("seal") do (i: In): + var sym: MinValue + i.reqStringLike sym + var s = i.scope.getSymbol(sym.getString) + s.sealed = true + i.scope.setSymbol(sym.getString, s) + # Sigils .sigil("'") do (i: In):@@ -529,5 +536,8 @@ i.push("save-symbol".newSym)
.sigil("<") do (i: In): i.push("load-symbol".newSym) + + .sigil("*") do (i: In): + i.push("seal".newSym) .finalize()
M
minim.nim
→
minim.nim
@@ -1,4 +1,4 @@
-import streams, critbits, parseopt2, strutils, os +import streams, critbits, parseopt2, strutils, os, json import core/types, core/parser,@@ -43,6 +43,17 @@
var CURRSCOPE*: ref MinScope +proc getExecs(): seq[string] = + var res = newSeq[string](0) + let getFiles = proc(dir: string) = + for c, s in walkDir(dir, true): + if (c == pcFile or c == pcLinkToFile) and not res.contains(s): + res.add s + getFiles(getCurrentDir()) + for dir in "PATH".getEnv.split(PathSep): + getFiles(dir) + return res + when USE_LINENOISE: proc completionCallback*(str: cstring, completions: ptr linenoiseCompletions) {.cdecl.}= var words = ($str).split(" ")@@ -55,6 +66,31 @@ for s in CURRSCOPE.symbols.keys:
if startsWith("'$1"%s, w): linenoiseAddCompletion completions, words.join(" ") & sep & "'" & s return + if w.startsWith("~"): + for s in CURRSCOPE.symbols.keys: + if startsWith("~$1"%s, w): + linenoiseAddCompletion completions, words.join(" ") & sep & "~" & s + return + if w.startsWith("@"): + for s in CURRSCOPE.symbols.keys: + if startsWith("@$1"%s, w): + linenoiseAddCompletion completions, words.join(" ") & sep & "@" & s + return + if w.startsWith(">"): + for s in CURRSCOPE.symbols.keys: + if startsWith(">$1"%s, w): + linenoiseAddCompletion completions, words.join(" ") & sep & ">" & s + return + if w.startsWith("<"): + for s, v in MINIMSYMBOLS.readFile.parseJson.pairs: + if startsWith("<$1"%s, w): + linenoiseAddCompletion completions, words.join(" ") & sep & "<" & s + return + if w.startsWith("*"): + for s in CURRSCOPE.symbols.keys: + if startsWith("*$1"%s, w): + linenoiseAddCompletion completions, words.join(" ") & sep & "*" & s + return if w.startsWith("$"): for s,v in envPairs(): if startsWith("$$1"%s, w):@@ -65,6 +101,15 @@ for c,s in walkDir(getCurrentDir(), true):
if startsWith("\"$1"%s, w): linenoiseAddCompletion completions, words.join(" ") & sep & "\"" & s & "\"" return + let execs = getExecs() + if w.startsWith("!"): + for s in execs: + if startsWith("!$1"%s, w): + linenoiseAddCompletion completions, words.join(" ") & sep & "!" & s + if w.startsWith("&"): + for s in execs: + if startsWith("&$1"%s, w): + linenoiseAddCompletion completions, words.join(" ") & sep & "&" & s for s in CURRSCOPE.symbols.keys: if s.startsWith(w): linenoiseAddCompletion completions, words.join(" ") & sep & s
M
tests/lang.min
→
tests/lang.min
@@ -96,6 +96,8 @@ ) try "Caught a MinEmptyStackError" ==) assert
("aaaa" :. . "aaaa" ==) assert ;It is possible to shadow sealed symbols in child scopes + (((2 :a1 *a1 3 :a1) ("failed")) try "failed" ==) assert + ( ( (("TestError" "Test Message") raise)