all repos — min @ 56adef7f33e9f3aef903e12ee3f33ed31afe6061

A small but practical concatenative programming language.

Documented expect operator; documented fs module.
h3rald h3rald@h3rald.com
Sun, 04 Jun 2017 16:06:24 +0200
commit

56adef7f33e9f3aef903e12ee3f33ed31afe6061

parent

9cf4f25a7d10a4f60346a79c4d2b12252330a1bd

M core/utils.nimcore/utils.nim

@@ -158,13 +158,13 @@

# Validators proc expect*(i: var MinInterpreter, elements: varargs[string]): seq[MinValue] = - let stack = elements.reverse.join(" ") + let stack = elements.join(" ") var valid = newSeq[string](0) result = newSeq[MinValue](0) let message = proc(invalid: string): string = result = "Incorrect values found on the stack:\n" - result &= "- expected: {" & stack & "}\n" - result &= "- got: {" & invalid & " " & valid.reverse.join(" ") & "}" + result &= "- expected: {top} " & stack & " {bottom}\n" + result &= "- got: {top} " & valid.reverse.join(" ") & " " & invalid & " {bottom}" for element in elements: let value = i.pop result.add value

@@ -217,6 +217,14 @@ raiseInvalid("A quotation is required on the stack")

for s in a.qVal: if not s.isNumber: raiseInvalid("A quotation of numbers is required on the stack") + +proc reqQuotationOfSymbols*(i: var MinInterpreter, a: var MinValue) = + a = i.pop + if not a.isQuotation: + raiseInvalid("A quotation is required on the stack") + for s in a.qVal: + if not s.isSymbol: + raiseInvalid("A quotation of symbols is required on the stack") proc reqTwoNumbersOrStrings*(i: var MinInterpreter, a, b: var MinValue) = a = i.pop
M lib/min_lang.nimlib/min_lang.nim

@@ -1,6 +1,7 @@

import critbits, strutils, + sequtils, parseopt2, json, os,

@@ -513,6 +514,11 @@ opts = i.dset(opts, key.newVal, val.newVal)

else: discard i.push opts + + def.symbol("expect") do (i: In): + var q: MinValue + i.reqQuotationOfSymbols q + i.push(i.expect(q.qVal.mapIt(it.getString())).newVal(i.scope)) # Sigils
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 ! != $ & ' * + # - % ^ -> . .. / : < <= == => =~ > >= @ ROOT aes all? and any? append args ask atime bind bool bool? call call! capitalize case cd chmod choose clear-stack cleave column-print concat confirm cons cp cpu crypto ctime datetime ddel debug decode define delete dget dictionary? dip dir? dirname div dprint dprint! dset dup encode env? error eval even? exists? exit fappend fatal find file? filename filter first flatten float float? foreach fperms fread from-json format-error fs fsize fstats ftype fwrite get gets get-env get-stack hardlink harvest hidden? id if import in? indent info insert int int? interpolate interval io join keep keys length linrec load load-symbol logic loglevel loglevel? lowercase ls ls-r map map-reduce match md5 mkdir mod module module-symbols module-sigils mtime mv newline nip not notice now num number? odd? opts os over partition password pick pop popd pred prepend print print! prompt publish puts puts! put-env q quotation? quote quote-bind quote-define random raise reduce regex reject remove remove-symbol repeat replace rest reverse rm rmdir run save-symbol scope scope? seal search seq set set-stack sha1 sha224 sha256 sha384 sha512 shorten sigils sip size sleep slice sort source split spread stack startup stored-symbols str string string? strip succ sum swap swons symbols symlink symlink? sys system take tformat time timeinfo times timestamp titleize to-json try unquote uppercase unzip values version warn when which while with xor zip +syntax keyword minDefaultSymbol ! != $ & ' * + # - % ^ -> . .. / : < <= == => =~ > >= @ ROOT aes all? and any? append args ask atime bind bool bool? call call! capitalize case cd chmod choose clear-stack cleave column-print concat confirm cons cp cpu crypto ctime datetime ddel debug decode define delete dget dictionary? dip dir? dirname div dprint dprint! dset dup encode env? error eval even? exists? exit expect fappend fatal find file? filename filter first flatten float float? foreach fperms fread from-json format-error fs fsize fstats ftype fwrite get gets get-env get-stack hardlink harvest hidden? id if import in? indent info insert int int? interpolate interval io join keep keys length linrec load load-symbol logic loglevel loglevel? lowercase ls ls-r map map-reduce match md5 mkdir mod module module-symbols module-sigils mtime mv newline nip not notice now num number? odd? opts os over partition password pick pop popd pred prepend print print! prompt publish puts puts! put-env q quotation? quote quote-bind quote-define random raise reduce regex reject remove remove-symbol repeat replace rest reverse rm rmdir run save-symbol scope scope? seal search seq set set-stack sha1 sha224 sha256 sha384 sha512 shorten sigils sip size sleep slice sort source split spread stack startup stored-symbols str string string? strip succ sum swap swons symbols symlink symlink? sys system take tformat time timeinfo times timestamp titleize to-json try unquote uppercase unzip values version warn when which while with xor zip syntax match minDefaultSigil ;\<[:@'~!$%&$=<>#^*#+/]; contained
M site/contents/_includes/_defs_.mdsite/contents/_includes/_defs_.md

@@ -11,6 +11,7 @@ {{e => [err](class:kwd)}}

{{d => [dict](class:kwd)}} {{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)}}
M site/contents/_includes/_reference-fs.mdsite/contents/_includes/_reference-fs.md

@@ -1,1 +1,47 @@

-... +{@ _defs_.md || 0 @} + +{#op||atime||{{sl}}||{{flt}}|| +Returns a timestamp corresponding to the time that file/directory {{sl}} was last accessed.#} + +{#op||ctime||{{sl}}||{{flt}}|| +Returns a timestamp corresponding to the time that file/directory {{sl}} was created.#} + +{#op||fperms||{{sl}}||{{i}}|| +Returns the Unix permissions (expressed as a three-digit number) of file/directory {{sl}}.#} + +{#op||fsize||{{sl}}||{{i}}|| +Returns the size in bytes of file/directory {{sl}}.#} + +{#op||fstats||{{sl}}||{{d}}|| +> Returns a dictionary {{d}} containing information on file/directory {{sl}}. +> > %sidebar% +> > Example +> > +> > Assuming that `min` is a file, the following: +> > +> > `'min fstats` +> > +> > produces: +> > +> > ( +> > (name (min)) +> > (device 16777220) +> > (file 50112479) +> > (type "file") +> > (size 617068) +> > (permissions 755) +> > (nlinks 1) +> > (ctime 1496583112.0) +> > (atime 1496584370.0) +> > (mtime 1496583112.0) +> > )#} + +{#op||ftype||{{sl}}||{{s}}|| +Returns the type of file/directory {{sl}} (`"file"` or `"dir"`).#} + +{#op||hidden?||{{sl}}||{{b}}|| +Returns {{t}} if file/directory {{sl}} is hidden, {{f}} otherwise.#} + +{#op||mtime||{{sl}}||{{flt}}|| +Returns a timestamp corresponding to the time that file/directory {{sl}} was last modified.#} +
M site/contents/_includes/_reference-lang.mdsite/contents/_includes/_reference-lang.md

@@ -82,6 +82,19 @@

{#op||exit||{{null}}||{{null}}|| Exits the program or shell. #} +{#op||expect||{{q1}}||{{q2}}|| +> Validates the first _n_ elements of the stack against the type descriptions specified in {{q1}} (_n_ is {{q1}}'s length) and if all the elements are valid returns them wrapped in {{q2}}. +> > %sidebar% +> > Example +> > +> > Assuming that the following elements are on the stack (from top to bottom): `1 "test" 3.4` +> > +> > the following: +> > +> > `(int string num) expect` +> > +> > produces: `(1 "test" 3.4)`#} + {#op||foreach||{{q1}} {{q2}}||{{a0p}}|| Applies the quotation {{q2}} to each element of {{q1}}.#}
M site/contents/_includes/_reference.mdsite/contents/_includes/_reference.md

@@ -39,8 +39,10 @@ {{b}}

: A boolean value {{i}} : An integer value. +{{flt}} +: A float value. {{n}} -: A numeric value. +: A numeric (integer or float) value. {{s}} : A string value. {{sl}}