all repos — min @ 3286ac59bd12b6ce89e210c41d7b1cffb8276cfe

A small but practical concatenative programming language.

Added url management symbols.
h3rald h3rald@h3rald.com
Sun, 20 Dec 2020 12:02:14 +0100
commit

3286ac59bd12b6ce89e210c41d7b1cffb8276cfe

parent

f0b2add3fb1e58a8ed2babe6d02b14fa0ca13a2b

M lib/min_str.nimlib/min_str.nim

@@ -10,7 +10,8 @@ ../core/utils

when not defined(mini): import - ../packages/nim-sgregex/sgregex + ../packages/nim-sgregex/sgregex, + uri proc str_module*(i: In) = let def = i.define()

@@ -119,6 +120,32 @@ let index = str.strVal.find(reg.strVal)

i.push index.newVal when not defined(mini): + + def.symbol("encode-url") do (i: In): + let vals = i.expect("string") + let s = vals[0].strVal + i.push s.encodeUrl.newVal + + def.symbol("decode-url") do (i: In): + let vals = i.expect("string") + let s = vals[0].strVal + i.push s.decodeUrl.newVal + + def.symbol("parse-url") do (i: In): + let vals = i.expect("string") + let s = vals[0].strVal + let u = s.parseUri + var d = newDict(i.scope) + i.dset(d, "scheme", u.scheme.newVal) + i.dset(d, "username", u.username.newVal) + i.dset(d, "password", u.password.newVal) + i.dset(d, "hostname", u.hostname.newVal) + i.dset(d, "port", u.port.newVal) + i.dset(d, "path", u.path.newVal) + i.dset(d, "query", u.query.newVal) + i.dset(d, "anchor", u.anchor.newVal) + i.push d + def.symbol("search") do (i: In): let vals = i.expect("string", "string") let reg = vals[0]
M min.ymlmin.yml

@@ -1,5 +1,5 @@

author: Fabio Cevasco description: A tiny concatenative programming language and shell. -id: 35518954 +id: 35537914 name: min -version: 0.25.0+version: 0.26.0
M next-release.mdnext-release.md

@@ -1,10 +1,1 @@

-* Added support for sigils on double-quoted strings. -* Added support for arbitrary strings as dictionary keys. -* Added **define-sigil**, **delete-sigil**, **seal-sigil**, **unseal-sigil**, **defined-sigil?**. -* Fixed behavior of **semver-inc-mahor** and **semver-inc-minor** to set lower digits to zero. -* Now using OpenSSL for all hashing symbols in the crypto module. -* Added **md4** symbol. -* Re-added the possibility to exclude OpenSSL by not defining the **ssl** flag. -* Added **clear** symbol to clear the screen. -* Added the **mapkey** and the **unmapkey** symbols to configure key mappings. -* Fixed execution of scripts from stdin (when running min with no parameters). +* Added **encode-url**, **decode-url**, **parse-url** symbols.
M site/contents/_defs_.mdsite/contents/_defs_.md

@@ -46,6 +46,7 @@ {{f => [false](class:kwd)}}

{{t => [true](class:kwd)}} {{null => &#x2205;}} {{sock => [dict:socket](class:kwd)}} +{{url => [url](class:kwd)}} {{req => [request](class:kwd)}} {{res => [response](class:kwd)}} {{sock1 => [dict:socket<sub>1</sub>](class:kwd)}}
M site/contents/get-started.mdsite/contents/get-started.md

@@ -86,6 +86,9 @@ * {#link-operator||str||replace#}

* {#link-operator||str||regex#} * {#link-operator||str||semver?#} * {#link-operator||str||from-semver#} + * {#link-operator||str||parse-url#} + * {#link-operator||str||decode-url#} + * {#link-operator||str||encode-url#} * {#link-operator||sys||zip#} * {#link-operator||sys||unzip#}
M site/contents/reference-str.mdsite/contents/reference-str.md

@@ -71,6 +71,9 @@

{#op||ord||{{s}}||{{i}}|| Returns the ASCII code {{i}} corresponding to the single character {{s}}.#} +{#op||parse-url||{{s}}||{{url}}|| +Parses the url {{s}} into its components and stores them into {{url}}.#} + {#op||prefix||{{sl1}} {{sl2}}||{{s}}|| Prepends {{sl2}} to {{sl1}}.#}
M site/contents/reference.mdsite/contents/reference.md

@@ -64,6 +64,19 @@ {{q}}

: A quotation (also expressed as parenthesis enclosing other values). {{d}} : A dictionary value. +{{url}} +: An URL dictionary: + + { + "http" :scheme + "h3rald" :hostname + "" :port + "" :username + "" :password + "min" :path + "" :anchor + "" :query + } {{tinfo}} : A timeinfo dictionary:
M site/settings.jsonsite/settings.json

@@ -6,5 +6,5 @@ "rules": "rules.min",

"temp": "temp", "templates": "templates", "title": "min language", - "version": "0.25.0" + "version": "0.26.0" }
M tests/str.mintests/str.min

@@ -73,5 +73,11 @@ ("fix" "pre" prefix "prefix" ==) assert

("suf" "fix" suffix "suffix" ==) assert + ("http://test.com?€%,,!{}" encode-url "http%3A%2F%2Ftest.com%3F%E2%82%AC%25%2C%2C%21%7B%7D" ==) assert + + ("http%3A%2F%2Ftest.com%3F%E2%82%AC%25%2C%2C%21%7B%7D" decode-url "http://test.com?€%,,!{}" ==) assert + + ("http://h3rald.com/a/b/c?test=1#123" parse-url {"123" :anchor "h3rald.com" :hostname "" :password "/a/b/c" :path "" :port "test=1" :query "http" :scheme "" :username} ==) assert + report clear-stack