Merge branch 'next' of github.com:h3rald/min into next
jump to
@@ -4,8 +4,8 @@ # Controls when the action will run.
on: # Run only when a new tag is pushed push: - tags: - - 'v*.*.*' + branches: + - 'test-**' # Allows you to run this workflow manually from the Actions tab workflow_dispatch:
@@ -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
@@ -165,6 +165,22 @@ i.push true.newVal
else: i.push false.newVal + def.symbol("replace-apply") do (i: In): + let vals = i.expect("quot", "string", "string") + let q = vals[0] + let reg = vals[1] + let s_find = vals[2] + var i2 = i.copy(i.filename) + let repFn = proc(a: seq[string]): string = + var ss = newSeq[MinValue](0) + for s in a: + ss.add s.newVal + i2.push ss.newVal + i2.push q + i2.pushSym "dequote" + return i2.pop.getString + i.push sgregex.replacefn(s_find.strVal, reg.strVal, "", repFn).newVal + def.symbol("replace") do (i: In): let vals = i.expect("string", "string", "string") let s_replace = vals[0]
@@ -1,4 +1,5 @@
* Added support for Scheme-style block comments using hashpipe style: `#| ... |#`. * Implemented support for documentation comments (`;;` or `#|| ... ||#`) placed right after an operator definition. * **BREAKING CHANGE** -- **?** is now used as a sigil for **help**, not **dget**. -* Added **help** (and also **?** alias and **?** sigil), **symbol-help**, **sigil-help** -- UNDOCUMENTED!+* Added **help** (and also **?** alias and **?** sigil), **symbol-help**, **sigil-help** +* Added **replace-apply**.
@@ -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)}}
@@ -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
@@ -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:
@@ -6,8 +6,6 @@ {@ _defs_.md || 0 @}
{#sig||/||dget#} -{#sig||?||dhas?#} - {#sig||%||dset#} {#op||ddup||{{d1}}||{{d2}}||
@@ -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:
@@ -98,6 +98,30 @@ > > produces:
> > > > `"This is a simple test. Is it really a simple test?"`#} +{#op||replace-apply||{{s1}} {{s2}} {{q}}||{{s3}}|| +> Returns a copy of {{s1}} containing all occurrences of {{s2}} replaced by applying {{q}} to each quotation correponding to each match. +> > %tip% +> > Tip +> > +> > {{s2}} can be a {{sgregex}}-compatible regular expression. +> +> > %sidebar% +> > Example +> > +> > The following: +> > +> > `":1::2::3::4:" ":(\d):" (=m m 1 get :d "-$#-" (d) =%) replace-apply` +> > +> > produces: +> > +> > `"-1--2--3--4-"` +> > +> > Note that for each match the following quotations (each containing tbe full matcb and the captured matches) are produced as input for the replace quotation: +> > ("-1-" "1") +> > ("-2-" "2") +> > ("-3-" "3") +> > ("-4-" "4") #} + {#op||regex||{{s1}} {{s2}}||{{q}}|| > Performs a search and/or a search-and-replace operation using pattern {{s2}}. >
@@ -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: