spike for scheme->javascript syntax transformation (subset)
more debug info in process-file
This commit is contained in:
69
private/js-transform.rkt
Normal file
69
private/js-transform.rkt
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
#lang racket/base
|
||||||
|
|
||||||
|
(define-syntax js-let
|
||||||
|
(syntax-rules ()
|
||||||
|
((_ (a b))
|
||||||
|
(string-append "let " (js1 a) " = " (js1 b) ";\n")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
(define-syntax js1
|
||||||
|
(syntax-rules (if let* *)
|
||||||
|
((_ (if cond body1 body2))
|
||||||
|
(string-append "if (" (js1 cond) ") then {\n"
|
||||||
|
(js1 body1) "; }\n"
|
||||||
|
"else {\n"
|
||||||
|
(js1 body2)
|
||||||
|
"; }\n"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
((_ (let (a ...)))
|
||||||
|
(string-append
|
||||||
|
(js-let a)
|
||||||
|
...)
|
||||||
|
)
|
||||||
|
((_ a)
|
||||||
|
(format "~a" 'a))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
#|
|
||||||
|
((_ (if cond
|
||||||
|
body1
|
||||||
|
body2))
|
||||||
|
(string-append "if ("
|
||||||
|
(js1 cond) ") then {\n"
|
||||||
|
(js1 body1) " }\n"
|
||||||
|
"else { \n"
|
||||||
|
(js1 body2)
|
||||||
|
" }\n"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
((_ (let ((a b) ...)
|
||||||
|
body))
|
||||||
|
(string-append "let " (js1 a)
|
||||||
|
" = " (js1 b) ";\n")
|
||||||
|
...
|
||||||
|
)
|
||||||
|
((_ (* a b ...))
|
||||||
|
(string-append (js1 a) "*" (js1 b) ...))
|
||||||
|
((_ a)
|
||||||
|
(format "~a" 'a))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|#
|
||||||
|
|
||||||
|
(define-syntax js
|
||||||
|
(syntax-rules ()
|
||||||
|
((_ js-statement ...)
|
||||||
|
(string-append
|
||||||
|
"{ \n"
|
||||||
|
(js1 js-statement)
|
||||||
|
...
|
||||||
|
"}\n"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@@ -196,6 +196,7 @@
|
|||||||
(display html* out))))
|
(display html* out))))
|
||||||
|
|
||||||
(define (process-file context ext path out)
|
(define (process-file context ext path out)
|
||||||
|
(dbg-webview "process-file: ext = ~a, path = ~a" ext path)
|
||||||
(let ((content (file->bytes path)))
|
(let ((content (file->bytes path)))
|
||||||
(dbg-webview "path = ~a, number of bytes read: ~a" path (bytes-length content))
|
(dbg-webview "path = ~a, number of bytes read: ~a" path (bytes-length content))
|
||||||
(display content out)))
|
(display content out)))
|
||||||
|
|||||||
Reference in New Issue
Block a user