all repos — min @ a23e56f1aa3f2317cf0db3c4ad4b78be06d10ef3

A small but practical concatenative programming language.

Implemented substr operator; fixed split.
* Closes #24.
h3rald h3rald@h3rald.com
Sat, 10 Mar 2018 21:17:32 +0100
commit

a23e56f1aa3f2317cf0db3c4ad4b78be06d10ef3

parent

0fe0f6020891ea8dadb480c6b97c58d9f889323c

5 files changed, 29 insertions(+), 8 deletions(-)

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

@@ -28,13 +28,25 @@ let vals = i.expect("'sym")

let s = vals[0] i.push s.getString.strip.newVal + def.symbol("substr") do (i: In): + let vals = i.expect("int", "int", "'sym") + let length = vals[0].intVal + let start = vals[1].intVal + let s = vals[2].getString + let index = min(start+length-1, s.len-1) + i.push s[start..index].newVal + def.symbol("split") do (i: In): let vals = i.expect("'sym", "'sym") - let sep = vals[0] - let s = vals[1] + let sep = vals[0].getString + let s = vals[1].getString var q = newSeq[MinValue](0) - for e in s.getString().split(sep.getString()): - q.add e.newVal + if (sep == ""): + for c in s: + q.add ($c).newVal + else: + for e in s.split(sep): + q.add e.newVal i.push q.newVal(i.scope) def.symbol("join") do (i: In):
M min.vimmin.vim

@@ -11,7 +11,7 @@

setl iskeyword=@,36-39,+,-,*,.,/,:,~,!,48-57,60-65,94-95,192-255 setl iskeyword+=^ -syntax keyword minDefaultSymbol ! != $ & ' * + # - % ^ -> . .. / § : = # < <= == => =~ > >= @ -inf ROOT accept acos aes all? and any? append apply args asin ask atan atime bind bool boolean? call call! capitalize case cd ceil chmod choose clear-stack cleave close column-print concat confirm connect cons cos cosh cp cpu crypto ctime d2r datetime ddel debug decode define defined? delete dequote dequote-and dequote-or dget dhas? dkeys dictionary? dip dir? dirname div download dpick dprint dprint! dset dsort dup dvalues e encode env? error eval even? exists? exit expect fappend fatal find file? filename filter first flatten float float? floor foreach fperms fread from-json format-error fs fsize fstats ftype fwrite get get-content gets get-env get-stack hardlink harvest hidden? http id if import in? indent indexof inf info insert int integer? interpolate interval io join keep last length linrec listen ln load load-symbol log2 log10 logic loglevel loglevel? lowercase ls ls-r map map-reduce match math md5 mkdir mod module module-symbols module-sigils mtime mv nan newline net nip not notice now num number? odd? opts os over parse partition password pi pick pop popd pow pred prepend print print! prompt publish puts puts! put-env q quotation? quote quote-bind quote-define quote-map r2d random raise read recv recv-line reduce regex reject remove remove-symbol repeat replace request rest reverse rm rmdir round run save-symbol scope scope? seal search send seq set set-stack sha1 sha224 sha256 sha384 sha512 shorten sigils sin sinh sip size sleep slice socket sort source split spread sqrt stack start-server startup stop-server stored-symbols str string string? strip succ sum swap swons symbols symlink symlink? sys system take tan tanh tap tap! tau tformat time timeinfo times timestamp titleize to-json to-timestamp try trunc unless unseal unzip uppercase version warn when which while with xor zip +syntax keyword minDefaultSymbol ! != $ & ' * + # - % ^ -> . .. / § : = # < <= == => =~ > >= @ -inf ROOT accept acos aes all? and any? append apply args asin ask atan atime bind bool boolean? call call! capitalize case cd ceil chmod choose clear-stack cleave close column-print concat confirm connect cons cos cosh cp cpu crypto ctime d2r datetime ddel debug decode define defined? delete dequote dequote-and dequote-or dget dhas? dkeys dictionary? dip dir? dirname div download dpick dprint dprint! dset dsort dup dvalues e encode env? error eval even? exists? exit expect fappend fatal find file? filename filter first flatten float float? floor foreach fperms fread from-json format-error fs fsize fstats ftype fwrite get get-content gets get-env get-stack hardlink harvest hidden? http id if import in? indent indexof inf info insert int integer? interpolate interval io join keep last length linrec listen ln load load-symbol log2 log10 logic loglevel loglevel? lowercase ls ls-r map map-reduce match math md5 mkdir mod module module-symbols module-sigils mtime mv nan newline net nip not notice now num number? odd? opts os over parse partition password pi pick pop popd pow pred prepend print print! prompt publish puts puts! put-env q quotation? quote quote-bind quote-define quote-map r2d random raise read recv recv-line reduce regex reject remove remove-symbol repeat replace request rest reverse rm rmdir round run save-symbol scope scope? seal search send seq set set-stack sha1 sha224 sha256 sha384 sha512 shorten sigils sin sinh sip size sleep slice socket sort source split spread sqrt stack start-server startup stop-server stored-symbols str string string? strip succ sum swap swons symbols symlink symlink? sys system take tan tanh tap tap! tau tformat time timeinfo times timestamp titleize to-json to-timestamp try trunc unless substr unseal unzip uppercase version warn when which while with xor zip syntax match minDefaultSigil ;\<[/:@'~!?$%&$=<>#^*#+]; contained syntax match minQuote ;\<['];
M site/contents/_defs_.mdsite/contents/_defs_.md

@@ -14,9 +14,9 @@ {{d1 => [dict<sub>1</sub>](class:kwd)}}

{{d2 => [dict<sub>2</sub>](class:kwd)}} {{flt => [float](class:kwd)}} {{i => [int](class:kwd)}} -{{i1 => [a<sub>1</sub>](class:kwd)}} -{{i2 => [a<sub>2</sub>](class:kwd)}} -{{i3 => [a<sub>3</sub>](class:kwd)}} +{{i1 => [int<sub>1</sub>](class:kwd)}} +{{i2 => [int<sub>2</sub>](class:kwd)}} +{{i3 => [int<sub>3</sub>](class:kwd)}} {{n => [num](class:kwd)}} {{n1 => [num<sub>1</sub>](class:kwd)}} {{n2 => [num<sub>2</sub>](class:kwd)}}
M site/contents/reference-str.mdsite/contents/reference-str.md

@@ -136,6 +136,9 @@

{#op||strip||{{sl}}||{{s}}|| Returns {{s}}, which is set to {{sl}} with leading and trailing spaces removed.#} +{#op||substr||{{s1}} {{i1}} {{i2}}||{{s2}}|| +Returns a substring {{s2}} obtained by retriving {{i2}} characters starting from index {{i1}} within {{s1}}.#} + {#op||titleize||{{sl}}||{{s}}|| Returns a copy of {{sl}} in which the first character of each word is capitalized.#}
M tests/str.mintests/str.min

@@ -13,6 +13,12 @@ ("test" length 4 ==) assert

("a,b,c" "," split ("a" "b" "c") ==) assert + ("abc" "" split ("a" "b" "c") ==) assert + + ("This is a test" 5 2 substr "is" ==) assert + + ("this" 2 3 substr "is" ==) assert + ("This is a test" "is" indexof 2 ==) assert ("test #1" "[0-9]" search ("1") ==) assert