all repos — min @ 3e33d91cada9f5aa369230a9b72a4a2c44b4f943

A small but practical concatenative programming language.

Added -d:nopcre flag and explained how to build for different platforms.
h3rald h3rald@h3rald.com
Mon, 31 Jul 2023 08:08:41 +0200
commit

3e33d91cada9f5aa369230a9b72a4a2c44b4f943

parent

a9b37ff31fb0a4cba043bec3b216bfa5e070bc5f

3 files changed, 108 insertions(+), 74 deletions(-)

jump to
M minpkg/lib/min_crypto.nimminpkg/lib/min_crypto.nim

@@ -40,11 +40,11 @@ i.push s.getString.decode.newVal

when defined(ssl): - when defined(windows): + when defined(windows) and defined(amd64): {.passL: "-static -L"&getProjectPath()&"/minpkg/vendor/openssl/windows -lssl -lcrypto -lbcrypt".} - elif defined(linux): + elif defined(linux) and defined(amd64): {.passL: "-static -L"&getProjectPath()&"/minpkg/vendor/openssl/linux -lssl -lcrypto".} - elif defined(macosx): + elif defined(macosx) and defined(amd64): {.passL: "-Bstatic -L"&getProjectPath()&"/minpkg/vendor/openssl/macosx -lssl -lcrypto -Bdynamic".} proc hash(s: string, kind: EVP_MD, size: int): string =
M minpkg/lib/min_str.nimminpkg/lib/min_str.nim

@@ -14,12 +14,78 @@

proc str_module*(i: In) = let def = i.define() - when defined(windows): - {.passL: "-static -L"&getProjectPath()&"/minpkg/vendor/pcre/windows -lpcre".} - elif defined(linux): - {.passL: "-static -L"&getProjectPath()&"/minpkg/vendor/pcre/linux -lpcre".} - elif defined(macosx): - {.passL: "-Bstatic -L"&getProjectPath()&"/minpkg/vendor/pcre/macosx -lpcre -Bdynamic".} + when not defined(nopcre): + when defined(windows) and defined(amd64): + {.passL: "-static -L"&getProjectPath()&"/minpkg/vendor/pcre/windows -lpcre".} + elif defined(linux) and defined(amd64): + {.passL: "-static -L"&getProjectPath()&"/minpkg/vendor/pcre/linux -lpcre".} + elif defined(macosx) and defined(amd64): + {.passL: "-Bstatic -L"&getProjectPath()&"/minpkg/vendor/pcre/macosx -lpcre -Bdynamic".} + + def.symbol("search") do (i: In): + let vals = i.expect("str", "str") + let reg = re(vals[0].strVal) + let str = vals[1] + let m = str.strVal.find(reg) + var res = newSeq[MinValue](0) + if m.isNone: + res.add "".newVal + for i in 0..reg.captureCount-1: + res.add "".newVal + i.push res.newVal + return + let matches = m.get.captures + res.add m.get.match.newVal + for i in 0..reg.captureCount-1: + res.add matches[i].newVal + i.push res.newVal + + def.symbol("match?") do (i: In): + let vals = i.expect("str", "str") + let reg = re(vals[0].strVal) + let str = vals[1].strVal + i.push str.find(reg).isSome.newVal + + def.symbol("search-all") do (i: In): + let vals = i.expect("str", "str") + var res = newSeq[MinValue](0) + let reg = re(vals[0].strVal) + let str = vals[1].strVal + for m in str.findIter(reg): + let matches = m.captures + var mres = newSeq[MinValue](0) + mres.add m.match.newVal + for i in 0..reg.captureCount-1: + mres.add matches[i].newVal + res.add mres.newval + i.push res.newVal + + def.symbol("replace-apply") do (i: In): + let vals = i.expect("quot", "str", "str") + let q = vals[0] + let reg = re(vals[1].strVal) + let s_find = vals[2].strVal + var i2 = i.copy(i.filename) + let repFn = proc(match: RegexMatch): string = + var ss = newSeq[MinValue](0) + ss.add match.match.newVal + for s in match.captures: + if s.isNone: + ss.add "".newVal + else: + ss.add s.get.newVal + i2.push ss.newVal + i2.push q + i2.pushSym "dequote" + return i2.pop.getString + i.push s_find.replace(reg, repFn).newVal + + def.symbol("replace") do (i: In): + let vals = i.expect("str", "str", "str") + let s_replace = vals[0].strVal + let reg = re(vals[1].strVal) + let s_find = vals[2].strVal + i.push s_find.replace(reg, s_replace).newVal def.symbol("interpolate") do (i: In): let vals = i.expect("quot", "str")

@@ -145,71 +211,6 @@ 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("str", "str") - let reg = re(vals[0].strVal) - let str = vals[1] - let m = str.strVal.find(reg) - var res = newSeq[MinValue](0) - if m.isNone: - res.add "".newVal - for i in 0..reg.captureCount-1: - res.add "".newVal - i.push res.newVal - return - let matches = m.get.captures - res.add m.get.match.newVal - for i in 0..reg.captureCount-1: - res.add matches[i].newVal - i.push res.newVal - - def.symbol("match?") do (i: In): - let vals = i.expect("str", "str") - let reg = re(vals[0].strVal) - let str = vals[1].strVal - i.push str.find(reg).isSome.newVal - - def.symbol("search-all") do (i: In): - let vals = i.expect("str", "str") - var res = newSeq[MinValue](0) - let reg = re(vals[0].strVal) - let str = vals[1].strVal - for m in str.findIter(reg): - let matches = m.captures - var mres = newSeq[MinValue](0) - mres.add m.match.newVal - for i in 0..reg.captureCount-1: - mres.add matches[i].newVal - res.add mres.newval - i.push res.newVal - - def.symbol("replace-apply") do (i: In): - let vals = i.expect("quot", "str", "str") - let q = vals[0] - let reg = re(vals[1].strVal) - let s_find = vals[2].strVal - var i2 = i.copy(i.filename) - let repFn = proc(match: RegexMatch): string = - var ss = newSeq[MinValue](0) - ss.add match.match.newVal - for s in match.captures: - if s.isNone: - ss.add "".newVal - else: - ss.add s.get.newVal - i2.push ss.newVal - i2.push q - i2.pushSym "dequote" - return i2.pop.getString - i.push s_find.replace(reg, repFn).newVal - - def.symbol("replace") do (i: In): - let vals = i.expect("str", "str", "str") - let s_replace = vals[0].strVal - let reg = re(vals[1].strVal) - let s_find = vals[2].strVal - i.push s_find.replace(reg, s_replace).newVal def.symbol("semver?") do (i: In): let vals = i.expect("str")
M site/contents/get-started.mdsite/contents/get-started.md

@@ -34,6 +34,29 @@ 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**. +### Building from source for additional platforms + +By default, min is released as a pre-built binary executable for Windows x64, macOS x64 and Linux x64. However, it should run without issues on any [platform supported by the Nim programming language](https://github.com/nim-lang/Nim/blob/devel/lib/system/platforms.nim). + +To build on a different operating system and architecture from the default ones, you also need to get or build the following static libraries: + +* libssl (OpenSSL) +* libcrypto (OpenSSL) +* libpcre (PCRE) + +and also specify the following additional flag when compiling: + +`--passL:"-static -L<dir> -lpcre -lssl -lcrypto"` + +Where `<dir>` is the directory containing the `*.a` files for the static libraries listed above. + +> %tip% +> +> Alternatively, if you can also opt out from OpenSSL and PCRE support by: +> +> * _Not_ specifying `-d:ssl` +> * Specifying `-d:nopcre` + ### Additional build options #### -d:ssl

@@ -53,6 +76,16 @@ * {#link-operator||crypto||sha1#}

* {#link-operator||crypto||encode#} * {#link-operator||crypto||decode#} * {#link-operator||crypto||aes#} + +#### -d:nopcre + +If the **-d:nopcre** is specified when compiling, min will be built _without_ PCRE support, so it will not be possible to use regular expressions and the following symbols will _not_ be exposed by the {#link-module||str#}: + +* {#link-operator||str||search#} +* {#link-operator||str||match?#} +* {#link-operator||str||search-all#} +* {#link-operator||str||replace#} +* {#link-operator||str||replace-apply#} ## Building a Docker image