HS E36: socket URL parsing + hs-socket-register! runtime (+3 tests)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 15s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 15s
- parser.sx: parse-socket-feat handles /path and scheme:// URLs; collect-url greedily joins URL continuation tokens (ident/number/op/colon/dot) - tokenizer.sx: fix :// not treated as line comment (lookback check) - compiler.sx: emit-socket compiles socket AST to hs-socket-register! call - runtime.sx: hs-socket-register! normalises URL (relative→ws:/wss:), constructs WebSocket, builds wrapper dict, binds on window name-path - hs-run-filtered.js: WebSocket mock uses plain object (not JS array) so host-global returns a foreign value rather than SX list; host-get idx works Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2733,7 +2733,6 @@
|
||||
parse-socket-feat
|
||||
(fn
|
||||
()
|
||||
;; Collect name-path: ident (class)* → e.g. ["Foo"] or ["MyApp" "chat"]
|
||||
(let
|
||||
((seg0 (tp-val)))
|
||||
(adv!)
|
||||
@@ -2750,7 +2749,6 @@
|
||||
acc)))
|
||||
(let
|
||||
((name-path (collect-segs (list seg0))))
|
||||
;; url-cont?: token types that can appear inside a URL
|
||||
(define
|
||||
url-cont?
|
||||
(fn
|
||||
@@ -2769,7 +2767,6 @@
|
||||
(= (tp-val) "with")
|
||||
(= (tp-val) "on")
|
||||
(= (tp-val) "as")))))))
|
||||
;; collect-url: accumulate URL tokens into a joined string
|
||||
(define
|
||||
collect-url
|
||||
(fn
|
||||
@@ -2781,51 +2778,12 @@
|
||||
(adv!)
|
||||
(collect-url (append parts (list v))))
|
||||
(join "" parts))))
|
||||
;; Parse URL: /path, scheme://..., string literal, or expression
|
||||
(let
|
||||
((url
|
||||
(cond
|
||||
;; Relative path starting with /
|
||||
((and (= (tp-type) "op") (= (tp-val) "/"))
|
||||
(adv!)
|
||||
(collect-url (list "/")))
|
||||
;; Absolute URL: ident + colon → collect as scheme:rest
|
||||
((= (tp-type) "ident")
|
||||
(let
|
||||
((scheme (tp-val)))
|
||||
(adv!)
|
||||
(if
|
||||
(= (tp-type) "colon")
|
||||
(collect-url (list scheme))
|
||||
(parse-arith (parse-poss (list (quote ref) scheme))))))
|
||||
;; String literal or other expression
|
||||
(true (parse-atom)))))
|
||||
;; Optional: with timeout <expr>
|
||||
((url (cond ((and (= (tp-type) "op") (= (tp-val) "/")) (do (adv!) (collect-url (list "/")))) ((= (tp-type) "ident") (let ((scheme (tp-val))) (adv!) (if (= (tp-type) "colon") (collect-url (list scheme)) (parse-arith (parse-poss (list (quote ref) scheme)))))) (true (parse-atom)))))
|
||||
(let
|
||||
((timeout-ms
|
||||
(if
|
||||
(match-kw "with")
|
||||
(do
|
||||
(adv!)
|
||||
(parse-expr))
|
||||
nil)))
|
||||
;; Optional: on message [as JSON] <cmd-list>
|
||||
((timeout-ms (if (match-kw "with") (do (adv!) (parse-expr)) nil)))
|
||||
(let
|
||||
((on-msg
|
||||
(if
|
||||
(match-kw "on")
|
||||
(do
|
||||
(adv!)
|
||||
(let
|
||||
((json?
|
||||
(if
|
||||
(match-kw "as")
|
||||
(do (adv!) true)
|
||||
false)))
|
||||
(let
|
||||
((body (parse-cmd-list)))
|
||||
(list (quote on-message) json? body))))
|
||||
nil)))
|
||||
((on-msg (if (match-kw "on") (do (adv!) (let ((json? (if (match-kw "as") (do (adv!) true) false))) (let ((body (parse-cmd-list))) (list (quote on-message) json? body)))) nil)))
|
||||
(match-kw "end")
|
||||
(list (quote socket) name-path url timeout-ms on-msg))))))))
|
||||
(define
|
||||
|
||||
Reference in New Issue
Block a user