diff --git a/javascript/plain/lang/reader.ss b/javascript/plain/lang/reader.ss new file mode 100644 index 0000000..8793817 --- /dev/null +++ b/javascript/plain/lang/reader.ss @@ -0,0 +1,14 @@ +(module reader syntax/module-reader + #:language `(planet "module.ss" ("untyped" "mirrors.plt" 2) "javascript/plain") + #:read + (lambda ([in (current-input-port)]) + (let ([ast (with-syntax-errors (lambda () (parse-program-unit in)))]) + (list `(#%module-begin ,@ast)))) + #:read-syntax + (lambda ([source-name #f] [in (current-input-port)]) + (let ([ast (with-syntax-errors (lambda () (parse-program-unit in)))]) + (list `(#%module-begin ,@ast)))) + #:whole-body-readers? #t + (require "../../../base.ss") + (require (javascript-in private/compiler/compile + private/syntax/parse))) \ No newline at end of file diff --git a/javascript/plain/module.ss b/javascript/plain/module.ss new file mode 100644 index 0000000..85a445a --- /dev/null +++ b/javascript/plain/module.ss @@ -0,0 +1,31 @@ +#lang scheme/base + +(require (for-syntax scheme/base) + "../javascript.ss" + "../struct.ss") + +;(define (extract-requires stx accum) +; (let loop ([stx stx] [req-accum null] [stmt-accum null]) +; (syntax-case* stx (require) symbolic-identifer=? +; [((require arg ...) req+stmt ...) +; (loop #'(req+stmt ...) +; (cons #'(require arg ...) req-accum) +; stmt-accum)] +; [(stmt req+stmt ...) +; (loop #'(req+stmt ...) +; req-accum +; (cons #'stmt stmt-accum))] +; [() #`(#,@(reverse req-accum) +; #,@(reverse stmt-accum))]))) + +(define-syntax (module-begin stx) + (syntax-case stx () + [(module-begin) #'(#%plain-module-begin (begin #f))] + [(module-begin stmt ...) + #'(#%plain-module-begin + (define ans (make-BeginStatement #f (list stmt ...))) + (display (javascript->pretty-string ans)) + (provide ans))])) + +(provide (rename-out [module-begin #%module-begin]) + (except-out (all-from-out scheme/base) #%module-begin)) \ No newline at end of file diff --git a/javascript/sexp/lang/reader.ss b/javascript/sexp/lang/reader.ss new file mode 100644 index 0000000..0030dbd --- /dev/null +++ b/javascript/sexp/lang/reader.ss @@ -0,0 +1,2 @@ +(module reader syntax/module-reader + #:language `(planet "module.ss" ("untyped" "mirrors.plt" 2) "javascript/sexp")) diff --git a/javascript/sexp/module.ss b/javascript/sexp/module.ss new file mode 100644 index 0000000..592a4ac --- /dev/null +++ b/javascript/sexp/module.ss @@ -0,0 +1,35 @@ +#lang scheme/base + +(require (for-syntax scheme/base + (planet untyped/unlib:3/debug) + (planet untyped/unlib:3/syntax)) + "../javascript.ss") + +(define-for-syntax (extract-requires stx) + (let loop ([stx stx] [req-accum null] [stmt-accum null]) + (syntax-case* stx (require) symbolic-identifier=? + [((require arg ...) req+stmt ...) + (loop #'(req+stmt ...) + (cons #'(require arg ...) req-accum) + stmt-accum)] + [(stmt req+stmt ...) + (loop #'(req+stmt ...) + req-accum + (cons #'stmt stmt-accum))] + [() #`(#,(reverse req-accum) + #,(reverse stmt-accum))]))) + +(define-syntax (module-begin stx) + (syntax-case stx () + [(module-begin) #'(#%plain-module-begin (begin #f))] + [(module-begin req+stmt ...) + (with-syntax ([((require ...) (stmt ...)) + (extract-requires #'(req+stmt ...))]) + #'(#%plain-module-begin + require ... + (define ans (js stmt ...)) + (display (javascript->pretty-string ans)) + (provide ans)))])) + +(provide (rename-out [module-begin #%module-begin]) + (except-out (all-from-out scheme/base) #%module-begin))