Documented help system.
h3rald h3rald@h3rald.com
Wed, 20 Jan 2021 20:36:44 +0000
7 files changed,
35 insertions(+),
8 deletions(-)
M
minpkg/lib/min_lang.nim
→
minpkg/lib/min_lang.nim
@@ -187,11 +187,11 @@ elif sv.qVal.len mod 2 == 0:
raiseInvalid("Invalid signature") var c = 0 # Process signature + let docSig = $sv var inExpects= newSeq[string](0) var inVars = newSeq[string](0) var outExpects= newSeq[string](0) var outVars = newSeq[string](0) - var docSig = newSeq[string](0) var generics: CritBitTree[string] var origGenerics: CritBitTree[string] var o = false@@ -218,11 +218,9 @@ v = vv.symVal
if check: if v == "==>": o = true - docSig.add "==>" elif not i.validType(v) and not generics.hasKey(v): raiseInvalid("Invalid type specified in signature at position $#" % $(c+1)) else: - docSig.add $vv if o: outExpects.add v else:@@ -298,9 +296,9 @@ raiseInvalid("Invalid value for output symbol '$#'. Expected $#, found $#" % [outVars[k], tp, $x])
generics = origGenerics # Define symbol/sigil var doc = newJObject() - doc["operator"] = %n + doc["name"] = %n doc["kind"] = %t - doc["signature"] = %docSig.join(" ") + doc["signature"] = %docSig doc["description"] = %i.currSym.docComment.strip if t == "symbol": if i.scope.symbols.hasKey(n) and i.scope.symbols[n].sealed:@@ -569,7 +567,7 @@ let s = i.pop.getString
var found = false var foundDoc = false let displayDoc = proc (j: JsonNode) = - echo "=== $# [$#]" % [j["operator"].getStr, j["kind"].getStr] + echo "=== $# [$#]" % [j["name"].getStr, j["kind"].getStr] echo j["signature"].getStr if j.hasKey("description"): let desc = j["description"].getStr
M
site/contents/_defs_.md
→
site/contents/_defs_.md
@@ -48,6 +48,7 @@ {{f => [false](class:kwd)}}
{{t => [true](class:kwd)}} {{null => [null](class:kwd)}} {{none => ∅}} +{{help => [dict:help](class:kwd)}} {{sock => [dict:socket](class:kwd)}} {{url => [url](class:kwd)}} {{req => [request](class:kwd)}}
M
site/contents/learn-operators.md
→
site/contents/learn-operators.md
@@ -28,8 +28,11 @@ symbol square
(num :n ==> num :result) (n dup * @result) ) operator + ;; Calculates the square of n. In this case, note how inputs and outputs are captured into the `n` and `result` symbols in the signature quotation and then referenced in the body quotation. Sure, the original version was much more succinct, but this is definitely more readable. + +Also, symbols defined with the {#link-operator||lang||operator#} symbol can be annotated with documentation comments (starting with `;;` or wrapped in `#| ... |#`)`) so that a help text can be displayed using the {#link-operator||lang||help#} symbol. Besides symbols, you can also define sigils. min provides a set of predefined _sigils_ as abbreviations for for commonly-used symbols. For example, the previous definition could be rewritten as follows using sigils:@@ -99,6 +102,8 @@ sigil j
(str :json ==> a :result) (json from-json @result) ) operator + +Also, symbols defined with the {#link-operator||lang||operator#} symbol can be annotated with documentation comments (starting with `;;` or wrapped in `#| ... |#`)`) so that a help text can be displayed using the {#link-operator||lang||help#} symbol. ## Operator signatures
M
site/contents/learn.md
→
site/contents/learn.md
@@ -12,6 +12,8 @@ If not, well, here's how a short min program looks like:
; This is a comment (1 2 3 4 5) (dup *) map + #| This is a... + ...multiline comment |# This program returns a list containing the square values of the first five integer numbers:
M
site/contents/reference-dict.md
→
site/contents/reference-dict.md
@@ -6,8 +6,6 @@ {@ _defs_.md || 0 @}
{#sig||/||dget#} -{#sig||?||dhas?#} - {#sig||%||dset#} {#op||ddup||{{d1}}||{{d2}}||
M
site/contents/reference-lang.md
→
site/contents/reference-lang.md
@@ -22,6 +22,10 @@ {#sig||^||call#}
{#alias||^||call#} +{#sig||?||help#} + +{#alias||?||help#} + {#sig||*||invoke#} {#sig||@||bind#}@@ -184,6 +188,9 @@ > > At present, only YAML objects containing string values are supported.#}
{#op||gets||{{none}}||{{s}}|| Reads a line from STDIN and places it on top of the stack as a string.#} + +{#op||help||{{sl}}||{{none}}|| +Prints the help text for {{sl}}, if available. #} {#op||if||{{q1}} {{q2}} {{q3}}||{{a0p}}|| If {{q1}} evaluates to {{t}} then evaluates {{q2}}, otherwise evaluates {{q3}}.#}@@ -436,6 +443,9 @@
{#op||set-type||{{d}} {{sl}}||{{d}}|| Sets the type for dictionary {{d}} to {{sl}}.#} +{#op||sigil-help||{{sl}}||{{help}}|{{null}}|| +Returns the help dictionary for the sigil {{sl}}, if available, {{null}} otherwise. #} + {#op||sigils||{{none}}||({{s0p}})|| Returns a list of all sigils defined in the [ROOT](class:kwd) scope.#}@@ -447,6 +457,9 @@ Converts {{any}} to its string representation.#}
{#op||symbols||{{none}}||({{s0p}})|| Returns a list of all symbols defined in the [ROOT](class:kwd) scope.#} + +{#op||symbol-help||{{sl}}||{{help}}|{{null}}|| +Returns the help dictionary for the symbol {{sl}}, if available, {{null}} otherwise. #} {#op||tap||{{any}} {{q}}||{{any}}|| > Performs the following operations:
M
site/contents/reference.md
→
site/contents/reference.md
@@ -68,6 +68,16 @@ {{q}}
: A quotation (also expressed as parenthesis enclosing other values). {{d}} : A dictionary value. +{{help}} +: A help dictionary: + + { + "puts" :name + "symbol" :kind + "a ==>" :signature + "Prints a and a new line to STDOUT." :description + ;help + } {{url}} : An URL dictionary: