all repos — hex @ d1ae8bfd891f9df8ca2476987d54e5581aaec4f3

A tiny, minimalist, slightly-esoteric concatenative programming lannguage.

Implemented doc generation.
h3rald h3rald@h3rald.com
Sat, 06 Sep 2025 14:44:47 +0200
commit

d1ae8bfd891f9df8ca2476987d54e5581aaec4f3

parent

3508e7df44db3cceb0ad8cbe5e79cffe03277a2a

M .gitignore.gitignore

@@ -65,3 +65,4 @@ web/assets/*.h[eb]x

*.com.dbg hex.js hex.wasm +lib/*.html
M MakefileMakefile

@@ -38,6 +38,7 @@ ./hex -b scripts/test.hex

./hex scripts/test.hbx web: playground utils.hbx hex + ./hex scripts/doc.hex lib/utils.hex lib/utils.html ./hex -b scripts/web.hex ./hex scripts/web.hex
M lib/utils.hexlib/utils.hex

@@ -393,7 +393,7 @@ ) "ends" ::

;;; fmt ;; s1 q -> s2 -;; Substitutes %:$0%% to %%$9%% placeholders in %:s1%% with items in %:q%%. +;; Substitutes %:$\{0\}%% to %%$\{9\}%% placeholders in %:s1%% with items in %:q%%. ( "_fmt_q" : "_fmt_s" :

@@ -403,7 +403,7 @@ ("[symbol fmt] Only a maximum of 10 placeholders are supported" throw)

when (_fmt_c _fmt_q len <) ( - _fmt_s "$" _fmt_c str cat _fmt_q _fmt_c get gsub "_fmt_s" : + _fmt_s "${" _fmt_c str cat "}" cat _fmt_q _fmt_c get gsub "_fmt_s" : _fmt_c 0x1 + "_fmt_c" : ) while
A scripts/doc.hex

@@ -0,0 +1,87 @@

+#!/usr/bin/env hex +"./lib/utils.hbx" read "utils.hbx" ! + +(args len 0x3 <) + ("ERROR: no input file specified." puts 0x1 exit) +when + +args 0x2 get "INFILE" : + +(args len 0x4 <) + ("ERROR: no output file specified." puts 0x1 exit) +when + +args 0x3 get "OUTFILE" : + + +"*** Processing ${0}..." (INFILE) fmt puts + +INFILE read "\n" split "LINES" : + +"" "PREV" : +"" "OUT" : +LINES + ( + "LINE" : + (LINE ";;;;; " begins) + ( + ("h3" PREV ==) + ; Paragraph after title + ( + LINE ";;;;; " "" sub () cons "<p>${0}</p>\n" swap fmt OUT swap cat "OUT" : + "p" "PREV" : + ) + ; H3 + ( + LINE ";;;;; " "" sub () cons "<h3>${0}</h2>\n" swap fmt OUT swap cat "OUT" : + "h3" "PREV" : + ) + if + ) + when + (LINE ";;;; " begins) + ( + ("h4" PREV ==) + ; Paragraph after title + ( + LINE ";;;; " "" sub () cons "<p>${0}</p>\n" swap fmt OUT swap cat "OUT" : + "p" "PREV" : + ) + ; H4 + ( + LINE ";;;; " "" sub () cons "<h4>${0}</h3>\n" swap fmt OUT swap cat "OUT" : + "h4" "PREV" : + ) + if + ) + when + (LINE ";;; " begins) + ( + LINE ";;; " "" sub () cons "<h5 id=\"${0}-symbol\"><code><span class=\"hex-symbol\">${0}</span></code> Symbol</h5><a href=\"top\"></a>\n" swap fmt OUT swap cat "OUT" : + "sym" "PREV" : + ) + when + (LINE ";; " begins "sig" PREV == and) + ( + LINE ";; " "" sub () cons "<p>${0}</p>\n" swap fmt OUT swap cat "OUT" : + "desc" "PREV" : + ) + when + (LINE ";; " begins "sym" PREV == and) + ( + LINE ";; " "" sub () cons "<p><mark>${0}</mark></p>\n" swap fmt "->" "→" sub OUT swap cat "OUT" : + "sig" "PREV" : + ) + when + "LINE" # + ) +each + +"*** Writing output to ${0}..." (OUTFILE) fmt puts +OUT OUTFILE write +"*** Done!" puts + +"OUT" # +"PREV" # +"LINES" # +"INFILE" #
M scripts/test.hexscripts/test.hex

@@ -355,10 +355,10 @@ ((0x1 0x4 0x5) min 0x1 ==)

((0x1 0x4 0x5) max 0x5 ==) ;190 - ("$0, $1!" ("hello" "world") fmt "hello, world!" ==) + ("${0}, ${1}!" ("hello" "world") fmt "hello, world!" ==) (("" ("a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n") fmt) (error) try "[symbol fmt] Only a maximum of 10 placeholders are supported" ==) - ("This is a $0, and another $0, and yet another $0" ("test") fmt "This is a test, and another test, and yet another test" ==) - ("$0, $2, $1!" ("first" "third") fmt "first, $2, third!" ==) + ("This is a ${0}, and another ${0}, and yet another ${0}" ("test") fmt "This is a test, and another test, and yet another test" ==) + ("${0}, ${2}, ${1}!" ("first" "third") fmt "first, ${2}, third!" ==) ;194 (0x0 "_a" : (0x1 0x2 0x3) (_a + "_a" :) each _a 0x6 == "_a" #)
M scripts/web.hexscripts/web.hex

@@ -38,6 +38,8 @@ "$:"

"$$" "%:" "%%" + "\{" + "\}" ) "highlight-delimiters" : (

@@ -50,6 +52,8 @@ "<span class=\"hex-symbol\">"

"</span>" "<code>" "</code>" + "{" + "}" ) "highlight-replacements" : ; Highlight syntax in text

@@ -190,6 +194,9 @@ changelog-content highlight

"CHANGELOG.md" write "*** Done!" puts +; Read reference docs +"lib/utils.html" read "lib_utils_docs" : + ;;;;; Write web site contents "*** Generating hex web site..." puts 0x0 "_c" :

@@ -206,6 +213,8 @@ "release" meta-release process-tag

"year" meta-year process-tag "changelog-toc" changelog-toc process-tag "releases" releases-content process-tag + ; Replace files + "@@@lib/utils.html@@@" lib_utils_docs sub "new-content" : ; Replace symbols with links 0x0 "_i" :
M src/hex.csrc/hex.c

@@ -7058,7 +7058,7 @@

hex_register_symbols(ctx); hex_create_docs(ctx->docs); - char *file; + char *file = NULL; int generate_bytecode = 0; if (argc > 1)

@@ -7115,7 +7115,11 @@ }

} else { - file = arg; + if (!file) + { + file = arg; + } + // Ignore extra arguments } } if (file)
M src/main.csrc/main.c

@@ -358,7 +358,7 @@

hex_register_symbols(ctx); hex_create_docs(ctx->docs); - char *file; + char *file = NULL; int generate_bytecode = 0; if (argc > 1)

@@ -415,7 +415,11 @@ }

} else { - file = arg; + if (!file) + { + file = arg; + } + // Ignore extra arguments } } if (file)
M web/contents/lib.htmlweb/contents/lib.html

@@ -8,4 +8,6 @@ To pre-load this file, you can start hex like this:</p>

<pre><code>hex -l utils.hbx</code></pre> </p> + @@@lib/utils.html@@@ + </article>