all repos — min @ 85a2cc6a348e908f4ec0c850d7659f600334ce20

A small but practical concatenative programming language.

Added docs, removed unnecessary operators from HTTP module.
h3rald h3rald@h3rald.com
Sat, 17 Feb 2018 15:35:04 +0100
commit

85a2cc6a348e908f4ec0c850d7659f600334ce20

parent

d3c9cd6bc61cc261712d439a8a5ef92bf43f6a07

M lib/min_http.nimlib/min_http.nim

@@ -14,7 +14,7 @@

proc newVal(i: In, headers: HttpHeaders): MinValue = result = newVal(newSeq[MinValue](), i.scope) for k, v in headers: - i.dset(result, k.newVal, v.newVal) + result = i.dset(result, k.newVal, v.newVal) proc execRequest(i:In, req: MinValue): MinValue = let cli = newCli()

@@ -37,8 +37,8 @@ meth = req.dget("method".newVal)

url = req.dget("url".newVal) let resp = cli.request(url = url.getString, httpMethod = meth.getString, body = body.getString, headers = headers) result = newVal(newSeq[MinValue](), i.scope) - result = i.dset(result, "version".newVal, resp.version.newVal) - result = i.dset(result, "status".newVal, resp.status.newVal) + result = i.dset(result, "version".newVal, resp.version.parseFloat.newVal) + result = i.dset(result, "status".newVal, resp.status[0..2].parseInt.newVal) result = i.dset(result, "headers".newVal, i.newVal(resp.headers)) result = i.dset(result, "body".newVal, resp.body.newVal)

@@ -58,9 +58,6 @@ let url = vals[0]

let cli = newCli() i.push cli.getContent(url.getString).newVal - def.symbol("post-content") do (i: In): - discard - def.symbol("download") do (i: In): let vals = i.expect("string", "string") let file = vals[0]

@@ -68,47 +65,5 @@ let url = vals[1]

let cli = newCli() cli.downloadFile(url.getString, file.getString) discard - - def.symbol("put-request") do (i: In): - let vals = i.expect "dict" - var req = vals[0] - req = i.dset(req, "method".newVal, "PUT".newVal) - i.push i.execRequest(req) - - def.symbol("get-request") do (i: In): - let vals = i.expect "dict" - var req = vals[0] - req = i.dset(req, "method".newVal, "GET".newVal) - i.push i.execRequest(req) - - def.symbol("post-request") do (i: In): - let vals = i.expect "dict" - var req = vals[0] - req = i.dset(req, "method".newVal, "POST".newVal) - i.push i.execRequest(req) - - def.symbol("head-request") do (i: In): - let vals = i.expect "dict" - var req = vals[0] - req = i.dset(req, "method".newVal, "HEAD".newVal) - i.push i.execRequest(req) - - def.symbol("options-request") do (i: In): - let vals = i.expect "dict" - var req = vals[0] - req = i.dset(req, "method".newVal, "OPTIONS".newVal) - i.push i.execRequest(req) - - def.symbol("patch-request") do (i: In): - let vals = i.expect "dict" - var req = vals[0] - req = i.dset(req, "method".newVal, "PATCH".newVal) - i.push i.execRequest(req) - - def.symbol("delete-request") do (i: In): - let vals = i.expect "dict" - var req = vals[0] - req = i.dset(req, "method".newVal, "DELETE".newVal) - i.push i.execRequest(req) def.finalize("http")
M lib/min_lang.nimlib/min_lang.nim

@@ -67,6 +67,9 @@ for s in m.scope.sigils.keys:

q.add s.newVal i.push q.newVal(i.scope) + def.symbol("lite?") do (i: In): + i.push defined(lite).newVal + def.symbol("from-json") do (i: In): let vals = i.expect("string") let s = vals[0]
M min.vimmin.vim

@@ -8,13 +8,12 @@ if exists("b:current_syntax")

finish endif -setl iskeyword=@,36-39,+,-,/,*,.,:,~,!,48-57,60-65,94-95,192-255 +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 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 gets get-env get-stack hardlink harvest hidden? 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 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 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 startup 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 uppercase unzip 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 startup 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 match minDefaultSigil ;\<[:@'~!?$%&$=<>#^*#+/]; contained -syntax match minSpecialSymbols ;[:@'~!?$%&$=<>#^*#+/]; contained +syntax match minDefaultSigil ;\<[/:@'~!?$%&$=<>#^*#+]; contained syntax match minQuote ;\<[']; syntax match minQuotedBinding ;#; syntax match minBinding ;@;

@@ -26,7 +25,7 @@ syntax match minNumber ;[-+]\=\d\+\(\.\d*\)\=;

syntax keyword minBoolean true false syntax region minString start=+"+ skip=+\\\\\|\\$"+ end=+"+ -syntax region minSigilSymbol start=;\<[:@'~!?$%&$=<>^*#+/]; end=;\>; contains=minDefaultSigil +syntax region minSigilSymbol start=;\<[/:@'~!?$%&$=<>^*#+]; end=;\>; contains=minDefaultSigil syntax region minQuotedSymbol start=;\<[']; end=;\>; contains=minQuote syntax region minBoundSymbol start=;@; end=;\>; contains=minBinding syntax region minQuotedBoundSymbol start=;#; end=;\>; contains=minQuotedBinding
M prelude.minprelude.min

@@ -8,9 +8,13 @@ 'stack import

'seq import 'time import 'fs import -'crypto import -'math import -'net import -'http import +'lite? ( + ( + 'crypto import + 'math import + 'net import + 'http import + ) ROOT with +) unless ; Unseal prompt symbol 'prompt unseal
M site/contents/_defs_.mdsite/contents/_defs_.md

@@ -45,9 +45,11 @@ {{sl2 => [&apos;sym<sub>2</sub>](class:kwd)}}

{{f => [false](class:kwd)}} {{t => [true](class:kwd)}} {{null => &#x2205;}} -{{sock => [dict:socket](class:kwd)}} -{{sock1 => [dict:socket<sub>1</sub>](class:kwd)}} -{{sock2 => [dict:socket<sub>2</sub>](class:kwd)}} +{{sock => [socket](class:kwd)}} +{{req => [request](class:kwd)}} +{{res => [response](class:kwd)}} +{{sock1 => [socket<sub>1</sub>](class:kwd)}} +{{sock2 => [socket<sub>2</sub>](class:kwd)}} {{m => _min_}} {{sgregex => [sgregex](https://github.com/snake5/sgregex).}}
M site/contents/download.mdsite/contents/download.md

@@ -28,6 +28,23 @@ 4. Navigate to the min repository local folder.

5. Run **nifty install** to download min’s dependencies. 7. Run **nim c -d:release min.nim**. +### Additional build options + + +#### -d:ssl + +If the **-d:ssl** flag is specified when compiling, min will be built with SSL support, so it will be possible to perform HTTPS requests with the {#link-module||http#}. This means that the resulting **min** executable will no longer be self-contained and it will require the OpenSSL dynamic library to be available on your system. + +#### -d:lite + +If the **d:lite** flag is specified, an even more minimal executable file will be generated, however the following functionalities will not be available: + +* The {#link-module||crypto#} +* The {#link-module||net#} +* The {#link-module||http#} +* The {#link-module||math#} +* The {#link-operator||sys||zip#} and {#link-operator||sys||unzip#} operators. + ## Running then min Shell To start min shell, run [min -i](class:cmd). You will be presented with a prompt displaying the path to the current directory:
A site/contents/reference-http.md

@@ -0,0 +1,26 @@

+----- +content-type: "page" +title: "http Module" +----- +{@ _defs_.md || 0 @} + +{#op||download||{{s1}} {{s2}}||{{null}}|| +Downloads the contents of URL {{s1}} to the local file {{s2}}. #} + +{#op||get-content||{{s1}}||{{s2}}|| +Retrieves the contents of URL {{s1}} as {{s2}}.#} + +{#op||request||{{req}}||{{res}}|| +> Performs an HTTP request. +> +> > %sidebar% +> > Example +> > +> > The following code constructs a {{req}} dictionary using the **tap** operator and passes it to the **request** operator to perform an HTTP GET request to <http://httpbin.org/ip>: +> > +> > () ( +> > ("GET" %method) +> > ("http://httpbin.org/ip" %url) +> > ) tap request + #} +
M site/contents/reference-lang.mdsite/contents/reference-lang.md

@@ -167,6 +167,9 @@ > >

> > (dup 0 ==) 'succ (dup pred) '* linrec #} +{#op||lite?||{{null}}||{{b}}|| +Returns {{t}} if min was built in _lite_ mode. #} + {#op||load||{{sl}}||{{a0p}}|| Parses and interprets the specified {{m}} file, adding [.min](class:ext) if not specified. #}

@@ -236,6 +239,15 @@ Reads and parses the specified {{m}} file {{sl}} and returns a quoted program {{q}}. #}

{#op||remove-symbol||{{sl}}||{{null}}|| Removes the symbol {{sl}} from the [.min\_symbols](class:file) file. #} + +{#op||ROOT||{{null}}||{{q}}|| +Returns an empty quotation holding a reference to the [ROOT](class:kwd) scope. + +> > %tip% +> > Tip +> > +> > This symbol is very useful in conjunction with the **with** operator. +#} {#op||save-symbol||{{sl}}||{{null}}|| Saves the contents of symbol {{sl}} to the [.min\_symbols](class:file) file. #}

@@ -353,4 +365,19 @@ > > (count 10 <=)

> > (count puts succ @count) while #} {#op||with||{{q1}} {{q2}}||{{a0p}}|| -Applies quotation {{q1}} within the scope of {{q2}}. #} +Applies quotation {{q1}} within the scope of {{q2}}. + +> > %sidebar% +> > Example +> > +> > This operator is useful to define symbols on the [ROOT](class:kwd) scope or a parent scope. For example min's prelude includes the following code used to import certain modules only if min was not compiled in lite mode: +> > +> > 'lite? ( +> > ( +> > 'crypto import +> > 'math import +> > 'net import +> > 'http import +> > ) ROOT with +> > ) unless +#}
M site/contents/reference.mdsite/contents/reference.md

@@ -32,6 +32,9 @@ {#link-module||math#}

: Provides many mathematical operators and constants such as trigonometric functions, square root, logarithms, etc. {#link-module||net#} : Provides basic supports for sockets (some features are not supported on Windows systems). +{#link-module||http#} +: Provides operators to perform HTTP requests, download files and create basic HTTP servers. + ## Notation

@@ -61,32 +64,54 @@ {{d}}

: A dictionary value. {{tinfo}} : A timeinfo dictionary: - <pre><code>( - ("year" 2017) - ("month" 7) - ("day" 8) - ("weekday" 6) - ("yearday" 188) - ("hour" 15) - ("minute" 16) - ("second" 25) - ("dst" true) - ("timezone" -3600) - ) - </code></pre> + + ( + ("year" 2017) + ("month" 7) + ("day" 8) + ("weekday" 6) + ("yearday" 188) + ("hour" 15) + ("minute" 16) + ("second" 25) + ("dst" true) + ("timezone" -3600) + ) {{e}} : An error dictionary: - <pre><code>( - ("error" "MyError") - ("message" "An error occurred") - ("symbol" "symbol1") - ("filename" "dir1/file1.min") - ("line" 3) - ("column" 13) - ) - </code></pre> + + ( + ("error" "MyError") + ("message" "An error occurred") + ("symbol" "symbol1") + ("filename" "dir1/file1.min") + ("line" 3) + ("column" 13) + ) {{sock}} -: A socket dictionary, created through the {#link-operator||net||socket#} method. +: A socket dictionary, created through the {#link-operator||net||socket#} operator. +{{req}} +: A request dictionary, representing an HTTP request to be performed through the operators exposed by the {#link-module||http#}: + + ( + ("url" "http://httpbin.org/put") + ("methdd" "PUT") + ("headers" ( + ("Accept-Language" "it-id") + ("Host" "httpbin.org"))) + ("body" "test body") + ) +{{res}} +: A response dictionary, representing an HTTP response returned by some of the operators exposed by the {#link-module||http#}: + + ( + ("version" 1.1) + ("status" 200) + ("headers" + (("Content-Type" "application/json"))) + ("body" + "{\"test\": \"This is a test\"}") + ) {{t}} : true (boolean type). {{f}}
M tests/http.mintests/http.min

@@ -22,39 +22,36 @@

( () ( ("$1/put" (url) => % %url) + ("PUT" %method) ((("test" "put")) to-json %body) - (put-request) + (request) ) tap /body from-json /json (("test" "put")) == ) assert ( () ( ("$1/post" (url) => % %url) + ("POST" %method) ((("test" "post")) to-json %body) - (post-request) - ) tap /body from-json /json (("test" "post")) == + (request) + ) tap /headers /content-length "341" == ) assert ( () ( ("$1/patch" (url) => % %url) + ("PATCH" %method) ((("test" "patch")) to-json %body) - (patch-request) + (request) ) tap /body from-json /json (("test" "patch")) == ) assert ( () ( ("$1/delete" (url) => % %url) - (delete-request) + ("DELETE" %method) + (request) ) tap /body from-json /url "$1/delete" (url) => % == - ) assert - - ( - () ( - ("$1/get" (url) => % %url) - (get-request) - ) tap /body from-json /url "$1/get" (url) => % == ) assert report
M tests/lang.mintests/lang.min

@@ -209,6 +209,8 @@ "testread.min" rm

("aaa bbb ccc 2 2 + (2 3 4)" parse (aaa bbb ccc 2 2 + (2 3 4)) ==) assert + (lite? false ==) assert + report ; Tidy up clear-stack