all repos — min @ 365b1be7f553dfc1bcc62a696fa8c29a75635ef7

A small but practical concatenative programming language.

Added replace-apply
h3rald h3rald@h3rald.com
Thu, 21 Jan 2021 01:54:01 +0000
commit

365b1be7f553dfc1bcc62a696fa8c29a75635ef7

parent

9ad654f155794e448a530d8c882c13cfcb8aba89

3 files changed, 42 insertions(+), 1 deletions(-)

jump to
M minpkg/lib/min_str.nimminpkg/lib/min_str.nim

@@ -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]
M next-release.mdnext-release.md

@@ -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**.
M site/contents/reference-str.mdsite/contents/reference-str.md

@@ -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}}. >