all repos — min @ 4dfad89c076fb1cf36f480fa727cdd1d4d3cc67b

A small but practical concatenative programming language.

Started updating mmm.
h3rald h3rald@h3rald.com
Mon, 27 Nov 2023 15:30:05 +0100
commit

4dfad89c076fb1cf36f480fa727cdd1d4d3cc67b

parent

fd4591c5b329f219b1db55c52821a14a71b92a7d

5 files changed, 222 insertions(+), 77 deletions(-)

jump to
M min.nimmin.nim

@@ -15,7 +15,8 @@ scope,

interpreter, stdlib, shell, - utils] + utils, + mmm] import minpkg/lib/[ min_lang

@@ -35,6 +36,7 @@ niftylogger

var NIMOPTIONS* = "" var MINMODULES* = newSeq[string](0) +var MMM*: MinModuleManager if logging.getHandlers().len == 0: newNiftyLogger().addHandler()

@@ -156,6 +158,7 @@ -m, --module-path Specify a directory containing the .min files to include in the

compiled executable (if -c is set) -n, --passN Pass options to the nim compiler (if -c is set) -p, --prelude:<file.min> If specified, it loads <file.min> instead of the default prelude code + -r, --registry:<url> If specified, uses the specified url as MMM registry -v, —-version Print the program version""" % [ "exe", pkgName, "version", pkgVersion,

@@ -203,6 +206,8 @@ REPL = true

of "interactive-simple", "j": if file == "": SIMPLEREPL = true + of "registry", "r": + MMMREGISTRY = val else: discard else:

@@ -239,6 +244,22 @@ logging.error "[help] No symbol to lookup was specified."

quit(9) minStr("\"$#\" help" % [args[1]]) quit(0) + elif file == "install": + MMM.init() + logging.error "[install] Not implemented." + quit(100) + elif file == "remote": + logging.error "[install] Not implemented." + quit(100) + elif file == "update": + logging.error "[install] Not implemented." + quit(100) + elif file == "info": + logging.error "[install] Not implemented." + quit(100) + elif file == "search": + logging.error "[install] Not implemented." + quit(100) minFile fn, op elif SIMPLEREPL: minSimpleRepl()
M minpkg/core/env.nimminpkg/core/env.nim

@@ -8,6 +8,8 @@ HOME = getenv("USERPROFILE")

if not defined(windows): HOME = getenv("HOME") +var MMMREGISTRY* {.threadvar.}: string +MMMREGISTRY = "https://min-lang.org" var MINRC* {.threadvar.}: string MINRC = HOME / ".minrc" var MINSYMBOLS* {.threadvar.}: string
A minpkg/core/mmm.nim

@@ -0,0 +1,65 @@

+import + std/[json, + os, + httpclient, + strutils, + logging +] +import + env + + + +type + MinModuleManager* = object + registry: string + modules = %[] + globalDir: string + localDir: string + + +proc init*(MMM: var MinModuleManager) = + MMM.registry = MMMREGISTRY + MMM.globalDir = HOME / "mmm" + MMM.localDir = os.getCurrentDir() / "mmm" + var updatedLocal = 0 + let mmmJson = MMM.globalDir / "mmm.json" + if not os.dirExists(MMM.globalDir): + os.createDir(MMM.globalDir) + if not os.dirExists(MMM.localDir): + os.createDir(MMM.localDir) + if os.fileExists(mmmJson): + try: + let data = parseFile(mmmJson) + updatedLocal = data["updated"].getInt + MMM.modules = data["modules"] + except CatchableError: + logging.debug getCurrentExceptionMsg() + error "Invalid local registry data ($#)" % [mmmJson] + let client = newHttpClient() + # Check remote data + var updatedRemote = 0 + try: + logging.debug "Checking remote registry..." + updatedRemote = client.getContent(MMMREGISTRY & "/mmm.timestamp").parseInt + logging.debug "Remote registry timestamp retrieved." + except CatchableError: + logging.debug getCurrentExceptionMsg() + logging.warn "Unable to connect to remote registry ($#)" % [MMMREGISTRY] + if updatedRemote > updatedLocal: + logging.notice "Updating local module registry..." + try: + client.downloadFile(MMMREGISTRY & "/mmm.json", mmmJson) + except CatchableError: + logging.debug getCurrentExceptionMsg() + logging.warn "Unable to download remote registry data ($#)" % [MMMREGISTRY & "/mmm.json"] + try: + let data = parseFile(mmmJson) + MMM.modules = data["modules"] + except CatchableError: + logging.debug getCurrentExceptionMsg() + error "Invalid local registry data ($#)" % [mmmJson] + else: + logging.debug "Local registry up-to-date: $#" % [$updatedLocal] + +
A site/assets/mmm.json

@@ -0,0 +1,14 @@

+{ + "updated": null, + "modules": [ + { + "name": "min-highlight", + "method": "git", + "url": "https://github.com/h3rald/min-highlight", + "author": "Fabio Cevasco", + "description": "HTML syntax highlighter for min code.", + "license": "MIT", + "deps": {} + } + ] +}
M site/rules.minsite/rules.min

@@ -2,24 +2,28 @@ 'hastysite import

;Routing ( - (dict) expect -> :meta - meta /id :id - meta /ext :ext + symbol set-destination + (dict :meta ==> dict :result) ( - ((id "home" ==) ( - meta ( - ("index" %id) - (".html" %ext) - ) tap - )) - ((ext ".md" ==) ( - meta ( - (".html" %ext) - ("$1/index" (id) => % %id) - ) tap - )) - ) case -) ^set-destination + meta /id :id + meta /ext :ext + ( + ((id "home" ==) ( + meta ( + ("index" %id) + (".html" %ext) + ) tap + )) + ((ext ".md" ==) ( + meta ( + (".html" %ext) + ("$1/index" (id) => % %id) + ) tap + )) + ) case + @result + ) +) :: ; Syntax highlighter (

@@ -87,66 +91,107 @@ ) ::

;Processing operators ( - ('sym dict) expect -> :tpl :meta - "" :page - "" :contents - meta ( - (input-fread @contents meta) - (settings /title %site) - (settings /version %version) - ( - :temp contents temp markdown - highlight-min-codeblocks highlight-min-codes @contents temp - ) - (contents %contents) - (:temp tpl temp mustache @page temp) - (page %contents) - ) tap -) ^process-md-with-template + symbol process-md-with-template + (dict :meta 'sym :tpl ==> dict :result) + ( + "" :page + "" :contents + meta ( + (input-fread @contents meta) + (settings /title %site) + (settings /version %version) + ( + :temp contents temp markdown + highlight-min-codeblocks highlight-min-codes @contents temp + ) + (contents %contents) + (:temp tpl temp mustache @page temp) + (page %contents) + ) tap @result + ) +) :: ( - (dict) expect -> :meta - meta /content-type :ct - meta ct process-md-with-template -) ^process-md-content + symbol process-md-content + (dict :meta ==> dict :result) + ( + meta /content-type :ct + meta ct process-md-with-template + @result + ) +) :: + +( + symbol process-content + (dict :meta ==> dict :result) + ( + meta /ext :ext + meta /id :id + meta + ( + ((".md" ext ==) (process-md-content)) + ) case + @result + ) +) :: ( - (dict) expect -> :meta - meta /ext :ext - meta + symbol process-css-asset + (dict :meta ==>) ( - ((".md" ext ==) (process-md-content)) - ) case -) ^process-content + "" :contents + meta ( + (input-fread @contents meta) + (:temp contents preprocess-css @contents temp) + (contents %contents) + ) tap + output-fwrite + ) +) :: ( - (dict) expect -> :meta - "" :contents - meta ( - (input-fread @contents meta) - (:temp contents preprocess-css @contents temp) - (contents %contents) - ) tap - output-fwrite -) ^process-css-asset + symbol process-mmm-json + (dict :data ==>) + ( + timestamp :ts + data input-fread from-json :contents + ; Update timestamp + contents ts %updated @contents + data contents to-json %contents + output-fwrite + ; Add timesyamp file + { + "mmm.timestamp" :path + "mmm" :id + ".timestamp" :ext + "asset" :type + } + ts string %contents + output-fwrite + ) +) :: ( - "Downloading latest min executables..." notice! - settings /version :version - ("windows" "macosx" "linux") + symbol download-latest-min-exes + (==>) ( - :opsys - "https://github.com/h3rald/min/releases/download/v$1/min_v$1_$2_x64.zip" (version opsys) =% :remote - "min_$#.zip" (opsys) =% :local - "wget $# -O $#" (remote local) =% :cmd - cmd system - "assets/downloads/$#/" (opsys) =% :dir - "assets/downloads/" mkdir - "unzip $# -o -d $#" (local dir) =% @cmd - cmd system! - local rm - ) foreach -) ^download-latest-min-exes + "Downloading latest min executables..." notice! + settings /version :version + ("windows" "macosx" "linux") + ( + :opsys + "https://github.com/h3rald/min/releases/download/v$1/min_v$1_$2_x64.zip" (version opsys) =% :remote + "min_$#.zip" (opsys) =% :local + "wget $# -O $#" (remote local) =% :cmd + cmd system + "assets/downloads/$#/" (opsys) =% :dir + "assets/downloads/" mkdir + "unzip $# -o -d $#" (local dir) =% @cmd + cmd system! + local rm + ) foreach + ) +) :: ;Main

@@ -154,23 +199,21 @@ ((('wget "" !=) ('zip which "" !=)) &&)

(download-latest-min-exes) when - "Processing contents..." notice! contents ( - (dict) expect -> - dup + (dict) expect -> :meta ( - ((/id "^_" match?) ()) ;Ignore files starting with underscore. - ((true) (process-content set-destination output-fwrite)) + ((meta /id "^_" match?) ()) ;Ignore files starting with underscore. + ((true) (meta process-content set-destination output-fwrite)) ) case ) foreach "Processing assets..." notice! assets ( - (dict) expect -> - dup + (dict) expect -> :meta ( - ((/ext ".css" match?) (process-css-asset)) - ((true) (output-cp)) + ((meta /ext ".css" ==) (meta process-css-asset)) + ((meta /path "mmm.json" ==) (meta process-mmm-json)) + ((true) (meta output-cp)) ) case ) foreach