all repos — min @ a82d0c84bcb1727bccc1f0ab1a252d7762d1d028

A small but practical concatenative programming language.

tasks/help.min

 1
"tasks/data/doc-snippets.json" fs.read from-json :snippets
"site/contents" ls ("reference-" match?) filter :src-files
"(?sm)\\{#op\\|\\|([^|]+)\\|\\|([^|]+)\\|\\|([^|]+)\\|\\|(.+?)#\\}" :op-regex
"(?sm)\\{#sig\\|\\|([^|]+)\\|\\|([^#]+)#\\}" :sig-regex
"(?sm)\\{#alias\\|\\|([^|]+)\\|\\|([^#]+)#\\}" :alias-regex
"(?sm)\\{\\{([^}]+)\\}\\}" :snippet-regex
"(?sm)\\>( \\>)*" :block-regex
"(?sm)%([^%]+)%" :title-regex
"(?sm)\\{@[^@]+@\\}" :incl-regex
"(?sm)`([^`]+)`" :code-regex

(
  symbol fix-name
  (str :s ==> str :result)
  (
    s
      "!" (stack.pop "!") replace-apply
      """ (stack.pop "\"") replace-apply
      "|" (stack.pop "|") replace-apply
      "\\[" (stack.pop "") replace-apply
      "\\]" (stack.pop "") replace-apply
      "\\(class:kwd\\)" (stack.pop "") replace-apply
      ">" (stack.pop ">") replace-apply
      "&lt;" (stack.pop "<") replace-apply
      "&apos;" (stack.pop "'") replace-apply
      "&ast;" (stack.pop "*") replace-apply
    @result
  )
) ::
;; Fixes names with special characters
(
    symbol process-block-markup
    (str :s ==> str :result)
    (
        s 
            block-regex (stack.pop "") replace-apply
            title-regex (stack.pop "") replace-apply
            incl-regex (stack.pop "") replace-apply
            code-regex (1 get) replace-apply
        @result
    )
) ::
;; Simplify block-level markup

(
    symbol process-snippets
    (str :s ==> str :result)
    (
        s snippet-regex (
            1 get :id
            snippets id dget
        ) replace-apply @result
    )
) ::
;; Resolves documentation snippets.

(
    symbol process
    (str :s ==> str :result)
    (
        s process-snippets process-block-markup strip @result
    )
) ::
;; Processes documentation snippets and markup.

(
    symbol process-op
    (quot :matches ==> dict :data)
    (
        {}
            matches 1 get process fix-name "name" dset
            matches 2 get process fix-name :input
            matches 3 get process fix-name :output
            "$# ==> $#" (input output) =% "signature" dset
            matches 4 get process "description" dset
            "symbol" "kind" dset
        @data
    )   
) ::
;; Processes operator reference documentation.

(
    symbol process-alias
    (quot :matches ==> dict :data)
    (
        {}
            matches 1 get process fix-name "name" dset
            matches 2 get :ref
            "See $#" (ref) =% "description" dset
            "symbol" "kind" dset
        @data
    )   
) ::
;; Processes alias reference documentation.

(
    symbol process-sig
    (quot :matches ==> dict :data)
    (
        {}
            matches 1 get process fix-name "name" dset
            matches 2 get :ref
            "See $#" (ref) =% "description" dset
            "sigil" "kind" dset
        @data
    )   
) ::
;; Processes sigil reference documentation.

(
    symbol default
    (==>)
    ( 
        {} :ref-dict
        {} :op-dict
        {} :sig-dict
        src-files (
            :file 
            file "reference-([a-z]+)\\.md" search 1 get :mod-id
            "Processing: $#" (mod-id) =% io.notice!
            file fs.read :contents
            contents op-regex search-all (
                process-op :op
                op "name" dget :op-name 
                op mod-id 'module dset @op
                op-dict 
                  op op-name dset
                @op-dict
            ) foreach
            contents alias-regex search-all (
                process-alias :alias
                alias "name" dget :alias-name
                alias mod-id 'module dset @alias
                op-dict 
                  alias alias-name dset
                @op-dict
            ) foreach
            contents sig-regex search-all (
                process-sig :sig
                sig "name" dget :sig-name
                sig mod-id 'module dset @sig
                sig-dict 
                  sig sig-name dset
                @sig-dict
            ) foreach
            ref-dict
              op-dict   "symbols" dset
              sig-dict  "sigils" dset
            @ref-dict
        ) foreach
        "Writing help.json" io.notice!
        ref-dict to-json "help.json" fs.write
    )
) ::
;; Builds the reference help JSON sources.