This commit is contained in:
2026-03-04 18:15:45 +01:00
parent afa3778103
commit 3a2abf90f6
16 changed files with 1563 additions and 93 deletions

View File

@@ -1,10 +1,20 @@
#lang racket/base
(require racket/string
racket/port
json
)
(provide while
until
get-lib-path
do-for
esc-quote
esc-double-quote
fromJson
mk-js-array
js-code
list-of-kv?
)
(define-syntax while
@@ -61,4 +71,47 @@
[else
(error (format "Install the shared library: ~a" lib))]
)))
(define (esc-quote str)
(string-replace str "'" "\\'"))
(define (esc-double-quote str)
(string-replace str "\"" "\\\""))
(define (fromJson str)
(with-input-from-string str read-json))
(define (mk-js-array l)
(if (list? l)
(string-append "[ " (string-join (map (λ (e) (format "'~a'"
(esc-quote (format "~a" e)))) l) ", ") " ]")
(format "[ '~a' ]" (esc-quote (format "~a" l)))
)
)
(define (js-code . a)
(define (code* l)
(if (null? l)
""
(string-append (car l) "\n" (code* (cdr l)))
)
)
(code* a))
(define (list-of-kv? l)
(define (kv? e)
(let ((e (car l)))
(and (list? e)
(= (length e) 2)
(symbol? (car e)))))
(define (all-kv? l)
(if (null? l)
#t
(if (kv? (car e))
(all-kv? (cdr l))
#f)))
(if (list? l)
(all-kv? l)
#f))