;; _hyperscript Language Specification ;; SX Implementation — Formal Reference (defcomp () (~docs/page :title "_hyperscript Language Specification" (p (~tw :tokens "text-lg text-gray-600 mb-8") "This specification defines the _hyperscript language as implemented by the SX " "compiler pipeline. _hyperscript source is compiled ahead-of-time to SX expressions " "targeting the DOM platform primitives — there is no interpreter.") (~docs/section :title "1. Overview" :id "overview" (p "The _hyperscript compilation pipeline has three stages:") (ol (~tw :tokens "list-decimal list-inside space-y-1 text-gray-700 mb-4") (li (strong "Tokenize") " — source string to token list (" (code "hs-tokenize") ")") (li (strong "Parse") " — token list to AST (" (code "hs-parse") ", " (code "hs-compile") ")") (li (strong "Compile") " — AST to SX expressions (" (code "hs-to-sx") ", " (code "hs-to-sx-from-source") ")")) (p "The compiled SX targets runtime shims in " (code "lib/hyperscript/runtime.sx") " which delegate to " (code "web/lib/dom.sx") " platform primitives.") (~docs/subsection :title "1.1 Attribute Binding" :id "attribute-binding" (p "Hyperscript is bound to DOM elements via the " (code "_") " attribute. At boot time, " (code "hs-boot!") " scans the document, " "compiles each attribute value to an SX closure, and invokes it " "with the element as " (code "me") ". Dynamic content is activated via " (code "hs-boot-subtree!") "."))) (~docs/section :title "2. Lexical Grammar" :id "lexical-grammar" (p "The tokenizer produces a list of token dicts, each with " (code ":type") ", " (code ":value") ", and " (code ":pos") " keys.") (~docs/subsection :title "2.1 Token Types" :id "token-types" (table (~tw :tokens "w-full text-sm border-collapse mb-6") (thead (~tw :tokens "bg-gray-50") (tr (th (~tw :tokens "text-left p-2 border-b font-semibold") "Type") (th (~tw :tokens "text-left p-2 border-b font-semibold") "Pattern") (th (~tw :tokens "text-left p-2 border-b font-semibold") "Examples"))) (tbody (tr (~tw :tokens "border-b") (td (~tw :tokens "p-2 font-mono") "keyword") (td (~tw :tokens "p-2") "Reserved word from keyword set") (td (~tw :tokens "p-2 font-mono") "on, set, add, if, for, def")) (tr (~tw :tokens "border-b") (td (~tw :tokens "p-2 font-mono") "ident") (td (~tw :tokens "p-2") "Identifier (not a keyword)") (td (~tw :tokens "p-2 font-mono") "count, x, myVar")) (tr (~tw :tokens "border-b") (td (~tw :tokens "p-2 font-mono") "number") (td (~tw :tokens "p-2") "Integer or decimal, optional ms/s suffix") (td (~tw :tokens "p-2 font-mono") "42, 3.14, 200ms, 2s")) (tr (~tw :tokens "border-b") (td (~tw :tokens "p-2 font-mono") "string") (td (~tw :tokens "p-2") "Single or double quoted, backslash escapes") (td (~tw :tokens "p-2 font-mono") "hello, world")) (tr (~tw :tokens "border-b") (td (~tw :tokens "p-2 font-mono") "template") (td (~tw :tokens "p-2") "Backtick-delimited with interpolation") (td (~tw :tokens "p-2 font-mono") "count is ...")) (tr (~tw :tokens "border-b") (td (~tw :tokens "p-2 font-mono") "class") (td (~tw :tokens "p-2") (code ".") " followed by CSS class name") (td (~tw :tokens "p-2 font-mono") ".active, .text-red-500")) (tr (~tw :tokens "border-b") (td (~tw :tokens "p-2 font-mono") "id") (td (~tw :tokens "p-2") (code "#") " followed by identifier") (td (~tw :tokens "p-2 font-mono") "#main, #output")) (tr (~tw :tokens "border-b") (td (~tw :tokens "p-2 font-mono") "attr") (td (~tw :tokens "p-2") (code "@") " followed by identifier") (td (~tw :tokens "p-2 font-mono") "@href, @disabled")) (tr (~tw :tokens "border-b") (td (~tw :tokens "p-2 font-mono") "style") (td (~tw :tokens "p-2") (code "*") " followed by identifier") (td (~tw :tokens "p-2 font-mono") "*opacity, *display")) (tr (~tw :tokens "border-b") (td (~tw :tokens "p-2 font-mono") "selector") (td (~tw :tokens "p-2") "CSS selector in angle brackets") (td (~tw :tokens "p-2 font-mono") "