all repos — hex @ d1002332983cbcfdb2bf8c474888c6b65d6407f5

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

scripts/doc.hex

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
#!/usr/bin/env hex
"./lib/utils.hbx" read "utils.hbx" !

(args len $3 <) 
    ("ERROR: no input file specified." puts $1 exit)
when

args $2 get "INFILE" : 

(args len $4 <) 
    ("ERROR: no output file specified." puts $1 exit)
when

args $3 get "OUTFILE" :


"*** Processing ${0}..." (INFILE) fmt puts 

INFILE read "\n" split "LINES" :

"" "PREV" :
"" "OUT"  :
"" "ID"   :
LINES
    (
        "LINE" :
        (LINE ";;;;;; " begins)
            ; ID
            (
                LINE ";;;;;; " "" sub "ID" :
                "id" "PREV" :
            )
        when
        (LINE ";;;;; <" begins)
            ; TOC
            (
                LINE ";;;;; <" "" sub () cons "<${0}\n" swap fmt OUT swap cat "OUT" :
                "tag" "PREV" :
            )
        when
        (LINE ";;;;; " begins "tag" PREV != and)
            (
                ("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}</h3>\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 (ID) cons "<h4>${0}<a href=\"#${1}\">&uarr;</a></h4>\n" swap fmt OUT swap cat "OUT" :
                        "h4" "PREV" :
                    )
                if
            )
        when 
        (LINE ";;; " begins)
            (
                LINE ";;; " "" sub (ID) cons "<h5 id=\"${0}-symbol\"><code><span class=\"hex-symbol\">${0}</span></code> Symbol<a href=\"#${1}\">&uarr;</a></h5>\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"    #
"ID"        #