all repos — min @ 32152f44d88ffb528e64af9095b2bc1818c15aed

A small but practical concatenative programming language.

Implemented args and opts.
h3rald h3rald@h3rald.com
Sun, 04 Jun 2017 12:36:59 +0200
commit

32152f44d88ffb528e64af9095b2bc1818c15aed

parent

b12d6698fb941ca8be8719221e5a5032c47847ae

5 files changed, 37 insertions(+), 4 deletions(-)

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

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

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

@@ -474,6 +475,30 @@ m = i.pop

i.push @[m].newVal(i.scope) i.push s i.push "define".newSym + + + def.symbol("args") do (i: In): + var args = newSeq[MinValue](0) + for kind, key, val in getopt(): + case kind: + of cmdArgument: + args.add key.newVal + else: + discard + i.push args.newVal(i.scope) + + def.symbol("opts") do (i: In): + var opts = newVal(newSeq[MinValue](0), i.scope) + for kind, key, val in getopt(): + case kind: + of cmdLongOption, cmdShortOption: + if val == "": + opts = i.dset(opts, key.newVal, true.newVal) + else: + opts = i.dset(opts, key.newVal, val.newVal) + else: + discard + i.push opts # Sigils
M lib/min_seq.nimlib/min_seq.nim

@@ -335,6 +335,4 @@ var d: MinValue

i.reqDictionary d i.push i.values(d) - - def.finalize("seq")
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 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? 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 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/_reference-lang.mdsite/contents/_includes/_reference-lang.md

@@ -36,6 +36,9 @@ {#sig||#||quote-define#}

{#sig||=||quote-bind#} +{#op||args||{{null}}||{{q}}|| +Returns a list of all arguments passed to the current program.#} + {#op||bind||{{any}} {{sl}}||{{null}}|| Binds the specified value (auto-quoted) to an existing symbol {{sl}}.#}

@@ -147,6 +150,9 @@ Returns a list of all sigils defined in module {{q}}.#}

{#op||module-symbols||{{q}}||({{s0p}})|| Returns a list of all symbols defined in module {{q}}.#} + +{#op||opts||{{null}}||{{d}}|| +Returns a dictionary of all options passed to the current program, with their respective values.#} {#op||publish||{{sl}} {{q}}||{{null}}|| > Publishes symbol {{sl}} to the scope of {{q}}.
M tests/lang.mintests/lang.min

@@ -147,6 +147,10 @@ (time module-symbols ("datetime" "now" "tformat" "timeinfo" "timestamp") ==) assert

(sys module-sigils ("!" "$" "&") ==) assert + (opts () ==) assert + + (args ("tests/all.min") ==) assert + report ; Tidy up - clear-stack+ clear-stack