all repos — min @ 37be4c8071e4c7a5dde4c3902299053abb432342

A small but practical concatenative programming language.

Improved steing interpolation.
h3rald h3rald@h3rald.com
Wed, 02 Dec 2020 18:05:32 +0100
commit

37be4c8071e4c7a5dde4c3902299053abb432342

parent

513d422be4972c1d075a3d115dffe2cf99d96d52

4 files changed, 25 insertions(+), 3 deletions(-)

jump to
M lib/min_str.nimlib/min_str.nim

@@ -22,6 +22,10 @@ strings.add $$el

let res = s.strVal % strings i.push res.newVal + def.symbol("apply-interpolate") do (i: In): + i.push "apply".newSym + i.push "interpolate".newSym + def.symbol("strip") do (i: In): let vals = i.expect("'sym") let s = vals[0]

@@ -152,5 +156,8 @@ i.push("regex".newSym)

def.symbol("%") do (i: In): i.push("interpolate".newSym) + + def.symbol("=%") do (i: In): + i.push("apply-interpolate".newSym) def.finalize("str")
M site/contents/reference-str.mdsite/contents/reference-str.md

@@ -6,7 +6,12 @@ {@ _defs_.md || 0 @}

{#alias||%||interpolate#} +{#alias||=%||apply-interpolate#} + {#alias||=~||regex#} + +{#op||apply-interpolate||{{s}} {{q}}||{{s}}|| +The same as pushing `apply` and then `interpolate` on the stack.#} {#op||capitalize||{{sl}}||{{s}}|| Returns a copy of {{sl}} with the first character capitalized.#}

@@ -23,9 +28,11 @@

{#op||interpolate||{{s}} {{q}}||{{s}}|| > Substitutes the placeholders included in {{s}} with the values in {{q}}. > > %note% -> > Note +> > Notes > > -> > If {{q}} contains symbols or quotations, they are not interpreted. To do so, call `apply` before interpolating. +> > * If {{q}} contains symbols or quotations, they are not interpreted. To do so, call `apply` before interpolating or use `apply-interpolate` instead. +> > * You can use the `$#` placeholder to indicate the next placeholder that has not been already referenced in the string. +> > * You can use named placeholders like `$pwd`, but in this case {{q}} must contain a quotation containing both the placeholder names (odd items) and the values (even items). > > > %sidebar% > > Example

@@ -74,7 +81,9 @@ > > The following:

> > > > `"This is a stupid test. Is it really a stupid test?" " s[a-z]+" " simple" replace` > > -> > produces: `"This is a simple test. Is it really a simple test?"`#} +> > produces: +> > +> > `"This is a simple test. Is it really a simple test?"`#} {#op||regex||{{s1}} {{s2}}||{{q}}|| > Performs a search and/or a search-and-replace operation using pattern {{s2}}.
M tests/lang.mintests/lang.min

@@ -220,6 +220,10 @@ ({3 :x 5 :y} "point" set-type 'point type?) assert

({} :myscope (2 :two 3 :three scope @myscope) -> myscope scope-symbols ("three" "two") ==) assert + ((2 < 3 and (4 > 2)) >< true) assert + + ((float 3) >> 3.0 ==) assert + report ; Tidy up clear-stack
M tests/str.mintests/str.min

@@ -53,5 +53,7 @@ ("test" 4 indent " test" ==) assert

((1 3 "test") ", " join "1, 3, test" ==) assert + ("PWD: $pwd" ("pwd" .) =% ("PWD: " .) => "" join ==) assert + report clear-stack