all repos — min @ d09ad07be17e77b62e515b06cd48f8f415b3d601

A small but practical concatenative programming language.

Implemented mmm lookup.
h3rald h3rald@h3rald.com
Thu, 30 Nov 2023 14:53:31 +0100
commit

d09ad07be17e77b62e515b06cd48f8f415b3d601

parent

9af8b3ba97f2d16f18b6dbfff31bed3beb138a26

2 files changed, 32 insertions(+), 67 deletions(-)

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

@@ -102,10 +102,36 @@ def.symbol("require") do (i: In):

let vals = i.expect("'sym") let s = vals[0] var file = s.getString + var m = s.getString if not file.endsWith(".min"): file = file & ".min" info("[require] File: ", file) - let f = simplifyPath(i.filename, file) + let lookup = proc (filename: string): string = + # First check in current folder + result = simplifyPath(filename, file) + if result.fileExists: + return + # then check for a mmm... + let localDir = result.parentDir + # ...locally... + let localModuleDir = localDir/"mmm"/m + if localModuleDir.dirExists: + let versions = localModuleDir.walkDir.toSeq.filterIt(it.kind == pcDir or it.kind == pcLinkToDir) + if versions.len > 0: + let localModuleVersion = versions[0].path + result = localModuleVersion/"index.min" + if result.fileExists: + return + # ...and then globally. + let globalModuleDir = HOME/"mmm"/m + if globalModuleDir.dirExists: + let versions = globalModuleDir.walkDir.toSeq.filterIt(it.kind == pcDir or it.kind == pcLinkToDir) + if versions.len > 0: + let globalModuleVersion = versions[0].path + result = globalModuleVersion/"index.min" + if result.fileExists: + return + let f = lookup(i.filename) if MINCOMPILED and COMPILEDMINFILES.hasKey(f): var i2 = i.copy(f) i2.withScope():

@@ -120,7 +146,7 @@ mdl.scope.symbols[key] = value

i.push(mdl) else: if not f.fileExists: - raiseInvalid("File '$1' does not exist." % file) + raiseInvalid("Unable to resolve module '$1'." % m) i.push i.require(f) def.symbol("raw-args") do (i: In):
M site/rules.minsite/rules.min

@@ -1,4 +1,7 @@

+'min-highlight require :min-highlight + 'hastysite import +'min-highlight import ;Routing (

@@ -25,70 +28,6 @@ @result

) ) :: -; Syntax highlighter -( - symbol span - (str :class str :value ==> str :result) - ( - "<span class=\"min-$#\">$#</span>" (class value) =% @result - ) -) :: - -( - symbol highlight - (dict :token ==> str :result) - ( - token /value :value - token /type :type - ( - ((type "tkEof" ==) ("" @result)) - ((type "tkSpace" ==) (value @result)) - ((type "tkBlockComment" ==) (type "#|$#|#" (value) =% span @result)) - ((type "tkBlockDocComment" ==) (type "#||$#||#" (value) =% span @result)) - ((type "tkLineComment" ==) (type ";$#" (value) =% span @result)) - ((type "tkLineDocComment" ==) (type ";;$#" (value) =% span @result)) - ((type "tkString" ==) (type "\"$#\"" (value) =% span @result)) - ((true) (type value span @result)) - ) case - ) -) :: - -( - symbol min-block-highlight - (str :code ==> str :result) - ( - code tokenize 'highlight map "" join :code - "<div class='min-codeblock'>$#</div>" (code) =% @result - ) -) :: - -( - symbol min-inline-highlight - (str :code ==> str :result) - ( - code tokenize 'highlight map "" join :code - "<span class='min-code'>$#</span>" (code) =% @result - ) -) :: - -( - symbol highlight-min-codeblocks - (str :html ==> str :result) - ( - html "<pre>\s*<code>((?:.|\n)*?)<\/code>\s*<\/pre>" - (1 get min-block-highlight) replace-apply @result - ) -) :: - -( - symbol highlight-min-codes - (str :html ==> str :result) - ( - html "<code>(.*?)<\/code>" - (1 get min-inline-highlight) replace-apply @result - ) -) :: - ;Processing operators ( symbol process-md-with-template

@@ -102,7 +41,7 @@ (settings /title %site)

(settings /version %version) ( :temp contents temp markdown - highlight-min-codeblocks highlight-min-codes @contents temp + highlight-codeblocks highlight-codes @contents temp ) (contents %contents) (:temp tpl temp mustache @page temp)