all repos — min @ 3db420e2dc5509fd2ae0e7ec4ca05ac3dad6d48d

A small but practical concatenative programming language.

Implemented smart completion for invocations.
h3rald h3rald@h3rald.com
Sun, 29 Oct 2023 11:10:02 +0100
commit

3db420e2dc5509fd2ae0e7ec4ca05ac3dad6d48d

parent

967880b93d7faebc8e14b1883ab7d2497c9005a9

M minpkg/core/parser.nimminpkg/core/parser.nim

@@ -115,6 +115,7 @@ doc*: JsonNode

case kind*: MinOperatorKind of minProcOp: prc*: MinOperatorProc + mdl*: MinValue # Only set in case of modules of minValOp: quotation*: bool val*: MinValue
M minpkg/core/shell.nimminpkg/core/shell.nim

@@ -34,7 +34,8 @@ except CatchableError:

discard i.close() -proc getCompletions*(ed: LineEditor, symbols: seq[string]): seq[string] = +proc getCompletions*(ed: LineEditor, i: MinInterpreter): seq[string] = + let symbols = toSeq(i.scope.symbols.keys) var words = ed.lineText.split(" ") var word: string if words.len == 0:

@@ -53,8 +54,36 @@ if word.startsWith("#"):

return symbols.mapIt("#" & $it) if word.startsWith(">"): return symbols.mapIt(">" & $it) + if word.startsWith("*") and word.contains("/"): + let dicts = word.substr(1).split("/") + var op: MinOperator + var dict: MinValue + var path = "*" + for d in dicts: + if dict.isNil: + if i.scope.symbols.hasKey(d): + op = i.scope.symbols[d] + if op.kind == minProcOp and not op.mdl.isNil: + dict = op.mdl + elif op.kind == minValOp and op.val.kind == minDictionary: + dict = op.val + path &= d & "/" + elif dict.dVal.hasKey(d): + op = dict.dVal[d] + if op.kind == minProcOp and not op.mdl.isNil: + dict = op.mdl + elif op.kind == minValOp and op.val.kind == minDictionary: + dict = op.val + path &= d & "/" + return dict.dVal.keys.toSeq.mapIt(path & it) if word.startsWith("*"): - return symbols.mapIt("*" & $it) + let filterProc = proc (it: string): bool = + let op = i.scope.symbols[it] + if op.kind == minProcOp and not op.mdl.isNil: + return true + else: + return op.kind == minValOp and op.val.kind == minDictionary + return symbols.filter(filterProc).mapIt("*" & $it) if word.startsWith("("): return symbols.mapIt("(" & $it) if word.startsWith("<"):

@@ -176,9 +205,9 @@ i.open(s, "<repl>")

var line: string echo "$# shell v$#" % [pkgName, pkgVersion] while true: - let symbols = toSeq(i.scope.symbols.keys) + let iref = i EDITOR.completionCallback = proc(ed: LineEditor): seq[string] = - var completions = ed.getCompletions(symbols) + var completions = ed.getCompletions(iref) completions.sort() return completions # evaluate prompt
M minpkg/core/utils.nimminpkg/core/utils.nim

@@ -40,7 +40,7 @@ i.evaluating = true

i.push mdl i.evaluating = false if name != "": - scope.previous.symbols[name] = MinOperator(kind: minProcOp, prc: op) + scope.previous.symbols[name] = MinOperator(kind: minProcOp, prc: op, mdl: mdl) # Dictionary Methods
M next-release.mdnext-release.md

@@ -6,6 +6,7 @@

### New Features * min shell now supports syntax highlighting for entered values. +* Implemented smart completion for invocations in min shell. ### Fixes and Improvements
M site/contents/learn-shell.mdsite/contents/learn-shell.md

@@ -29,7 +29,8 @@ Context | Result

---------------------------------------------------------------|-------------- ...a string | Auto-completes the current word using file and directory names. ...a word starting with `$` | Auto-completes the current word using environment variable names. -...a word starting with `'`, `@`, `#`, `>`, `<`, `*`, `(`, `?` | Auto-completes the current word using symbol names. +...a word starting with `'`, `@`, `#`, `>`, `<`, `(`, `?` | Auto-completes the current word using symbol names. +...a word starting with `*` and optionally containing `/`s | Auto-completes the current word using dictionaries and their symbol (nested invocation) Additionally, the following common shortcuts are also available: