- _spec_explorer_data() helper: parses spec files into sections, defines, effects, params, source blocks, and Python translations via PyEmitter - specs-explorer.sx: 10 defcomp components for explorer UI — cards with effect badges, typed param lists, collapsible SX/Python translation panels - Route at /language/specs/explore/<slug> via docs.sx - "Explore" link on existing spec detail pages Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
195 lines
8.0 KiB
Plaintext
195 lines
8.0 KiB
Plaintext
;; ---------------------------------------------------------------------------
|
|
;; Spec Explorer — structured interactive view of SX spec files
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
(defcomp ~spec-explorer-content (&key data)
|
|
(~doc-page :title (str (get data "title") " — Explorer")
|
|
|
|
;; Header with filename and source link
|
|
(~spec-explorer-header
|
|
:filename (get data "filename")
|
|
:title (get data "title")
|
|
:desc (get data "desc")
|
|
:slug (replace (get data "filename") ".sx" ""))
|
|
|
|
;; Stats bar
|
|
(~spec-explorer-stats :stats (get data "stats"))
|
|
|
|
;; Sections
|
|
(map (fn (section)
|
|
(~spec-explorer-section :section section))
|
|
(get data "sections"))
|
|
|
|
;; Platform interface
|
|
(when (not (empty? (get data "platform-interface")))
|
|
(~spec-platform-interface :items (get data "platform-interface")))))
|
|
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
;; Header
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
(defcomp ~spec-explorer-header (&key filename title desc slug)
|
|
(div :class "mb-6"
|
|
(div :class "flex items-center justify-between"
|
|
(div
|
|
(h1 :class "text-2xl font-bold text-stone-800" title)
|
|
(p :class "text-sm text-stone-500 mt-1" desc))
|
|
(a :href (str "/language/specs/" slug)
|
|
:sx-get (str "/language/specs/" slug)
|
|
:sx-target "#main-panel" :sx-select "#main-panel"
|
|
:sx-swap "outerHTML" :sx-push-url "true"
|
|
:class "text-sm text-violet-600 hover:text-violet-800 font-medium"
|
|
"View Source"))
|
|
(p :class "text-xs text-stone-400 font-mono mt-2" filename)))
|
|
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
;; Stats bar
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
(defcomp ~spec-explorer-stats (&key stats)
|
|
(div :class "flex flex-wrap gap-2 mb-6 text-xs"
|
|
(span :class "bg-stone-100 text-stone-600 px-2 py-0.5 rounded font-medium"
|
|
(str (get stats "total-defines") " defines"))
|
|
(when (> (get stats "pure-count") 0)
|
|
(span :class "bg-green-100 text-green-700 px-2 py-0.5 rounded"
|
|
(str (get stats "pure-count") " pure")))
|
|
(when (> (get stats "mutation-count") 0)
|
|
(span :class "bg-amber-100 text-amber-700 px-2 py-0.5 rounded"
|
|
(str (get stats "mutation-count") " mutation")))
|
|
(when (> (get stats "io-count") 0)
|
|
(span :class "bg-orange-100 text-orange-700 px-2 py-0.5 rounded"
|
|
(str (get stats "io-count") " io")))
|
|
(when (> (get stats "render-count") 0)
|
|
(span :class "bg-sky-100 text-sky-700 px-2 py-0.5 rounded"
|
|
(str (get stats "render-count") " render")))
|
|
(span :class "bg-stone-100 text-stone-500 px-2 py-0.5 rounded"
|
|
(str (get stats "lines") " lines"))))
|
|
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
;; Section
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
(defcomp ~spec-explorer-section (&key section)
|
|
(div :class "mb-8"
|
|
(h2 :class "text-lg font-semibold text-stone-700 border-b border-stone-200 pb-1 mb-3"
|
|
:id (replace (lower-case (get section "title")) " " "-")
|
|
(get section "title"))
|
|
(when (get section "comment")
|
|
(p :class "text-sm text-stone-500 mb-3" (get section "comment")))
|
|
(div :class "space-y-4"
|
|
(map (fn (d) (~spec-explorer-define :d d))
|
|
(get section "defines")))))
|
|
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
;; Define card — one function/constant
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
(defcomp ~spec-explorer-define (&key d)
|
|
(div :class "rounded border border-stone-200 p-4"
|
|
:id (str "fn-" (get d "name"))
|
|
|
|
;; Name + effect badges
|
|
(div :class "flex items-center gap-2 flex-wrap"
|
|
(span :class "font-mono font-semibold text-stone-800" (get d "name"))
|
|
(span :class "text-xs text-stone-400" (get d "kind"))
|
|
(if (empty? (get d "effects"))
|
|
(span :class "text-xs px-1.5 py-0.5 rounded bg-green-100 text-green-700" "pure")
|
|
(map (fn (eff) (~spec-effect-badge :effect eff))
|
|
(get d "effects"))))
|
|
|
|
;; Params
|
|
(when (not (empty? (get d "params")))
|
|
(~spec-param-list :params (get d "params")))
|
|
|
|
;; Translation panels
|
|
(~spec-ring-translations
|
|
:source (get d "source")
|
|
:python (get d "python"))))
|
|
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
;; Effect badge
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
(defcomp ~spec-effect-badge (&key effect)
|
|
(span :class (str "text-xs px-1.5 py-0.5 rounded "
|
|
(case effect
|
|
"mutation" "bg-amber-100 text-amber-700"
|
|
"io" "bg-orange-100 text-orange-700"
|
|
"render" "bg-sky-100 text-sky-700"
|
|
:else "bg-stone-100 text-stone-500"))
|
|
effect))
|
|
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
;; Param list
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
(defcomp ~spec-param-list (&key params)
|
|
(div :class "mt-1 flex flex-wrap gap-1"
|
|
(map (fn (p)
|
|
(let ((name (get p "name"))
|
|
(typ (get p "type")))
|
|
(if (or (= name "&rest") (= name "&key"))
|
|
(span :class "text-xs font-mono text-violet-500" name)
|
|
(span :class "text-xs font-mono px-1 py-0.5 rounded bg-stone-50 border border-stone-200"
|
|
(if typ
|
|
(<> (span :class "text-stone-700" name)
|
|
(span :class "text-stone-400" " : ")
|
|
(span :class "text-violet-600" typ))
|
|
(span :class "text-stone-700" name))))))
|
|
params)))
|
|
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
;; Translation panels (Ring 2)
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
(defcomp ~spec-ring-translations (&key source python)
|
|
(when (not (= source ""))
|
|
(div :class "mt-3 border border-stone-200 rounded-lg overflow-hidden"
|
|
;; SX source — always open
|
|
(details :open "true"
|
|
(summary :class "px-3 py-1.5 bg-stone-50 text-xs font-medium text-stone-600 cursor-pointer"
|
|
"SX")
|
|
(pre :class "text-xs p-3 overflow-x-auto bg-white"
|
|
(code (highlight source "sx"))))
|
|
;; Python
|
|
(when python
|
|
(details
|
|
(summary :class "px-3 py-1.5 bg-stone-50 text-xs font-medium text-stone-600 cursor-pointer border-t border-stone-200"
|
|
"Python")
|
|
(pre :class "text-xs p-3 overflow-x-auto bg-white"
|
|
(code (highlight python "python"))))))))
|
|
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
;; Platform interface table (Ring 3)
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
(defcomp ~spec-platform-interface (&key items)
|
|
(div :class "mt-8"
|
|
(h2 :class "text-lg font-semibold text-stone-700 border-b border-stone-200 pb-1 mb-3"
|
|
"Platform Interface")
|
|
(p :class "text-sm text-stone-500 mb-3"
|
|
"Functions the host platform must provide.")
|
|
(div :class "overflow-x-auto rounded border border-stone-200"
|
|
(table :class "w-full text-left text-sm"
|
|
(thead (tr :class "border-b border-stone-200 bg-stone-50"
|
|
(th :class "px-3 py-2 font-medium text-stone-600" "Name")
|
|
(th :class "px-3 py-2 font-medium text-stone-600" "Params")
|
|
(th :class "px-3 py-2 font-medium text-stone-600" "Returns")
|
|
(th :class "px-3 py-2 font-medium text-stone-600" "Description")))
|
|
(tbody
|
|
(map (fn (item)
|
|
(tr :class "border-b border-stone-100"
|
|
(td :class "px-3 py-2 font-mono text-sm text-violet-700" (get item "name"))
|
|
(td :class "px-3 py-2 font-mono text-xs text-stone-500" (get item "params"))
|
|
(td :class "px-3 py-2 font-mono text-xs text-stone-500" (get item "returns"))
|
|
(td :class "px-3 py-2 text-stone-600" (get item "doc"))))
|
|
items))))))
|