Step 18 (part 8): Playground page + compile handler + url_decode fix
sx/sx/hyperscript.sx — _hyperscript playground page at /sx/(applications.(hyperscript)) - compile-result defcomp (SSR compilation display) - pipeline documentation (tokenize → parse → compile) - example showcases with pre-compiled output - sx-post form → handler for interactive compilation sx/sx/handlers/hyperscript-api.sx — POST handler: /sx/(applications.(hyperscript.(api.compile))) Accepts source param, returns compiled SX + parse tree HTML NOTE: hs-parse returns (do) in server context — JIT/CEK runtime issue where parser closures don't evaluate correctly. Works in test runner (3127/3127). Investigating separately. sx_server.ml — url_decode fix: decode + as space in form data Standard application/x-www-form-urlencoded uses + for spaces. Nav: _hyperscript added to Applications section. Config: handler:hs- prefix added for handler dispatch. 3127/3127 tests, zero regressions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
37
sx/sx/handlers/hyperscript-api.sx
Normal file
37
sx/sx/handlers/hyperscript-api.sx
Normal file
@@ -0,0 +1,37 @@
|
||||
;; _hyperscript playground API handler
|
||||
;; Compiles hyperscript source and returns the AST + SX output as HTML
|
||||
|
||||
(defhandler
|
||||
hs-compile
|
||||
:path "/sx/(applications.(hyperscript.(api.compile)))"
|
||||
:method :post
|
||||
:csrf false
|
||||
:returns "element"
|
||||
(&key source)
|
||||
(if
|
||||
(or (nil? source) (empty? source))
|
||||
(p
|
||||
(~tw :tokens "text-sm text-gray-400 italic")
|
||||
"Enter some hyperscript and click Compile.")
|
||||
(let
|
||||
((ast (hs-compile source)) (sx (hs-to-sx-from-source source)))
|
||||
(div
|
||||
(~tw :tokens "space-y-4")
|
||||
(div
|
||||
(h4
|
||||
(~tw
|
||||
:tokens "text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2")
|
||||
"Compiled SX")
|
||||
(pre
|
||||
(~tw
|
||||
:tokens "bg-gray-900 text-green-400 p-4 rounded-lg text-sm overflow-x-auto whitespace-pre-wrap font-mono")
|
||||
(sx-serialize sx)))
|
||||
(div
|
||||
(h4
|
||||
(~tw
|
||||
:tokens "text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2")
|
||||
"Parse Tree")
|
||||
(pre
|
||||
(~tw
|
||||
:tokens "bg-gray-900 text-amber-400 p-4 rounded-lg text-sm overflow-x-auto whitespace-pre-wrap font-mono")
|
||||
(sx-serialize ast)))))))
|
||||
Reference in New Issue
Block a user