-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added experimental module readers for plain and s-expression Javascript.
Each language creates a module that defines and exports a single variable, "ans", containing a Javascript !begin block: #lang planet untyped/mirrors/javascript/plain function sum (a, b) { return a + b; } #lang planet untyped/mirrors/javascript/sexp (function sum (a b) (return (+ a b))) The idea is to create a require-like mechanism that allows the programmer to specify dependencies between modules. Once we have that, we have the basis for an automated JS build process. And if it works with JS, it can work with CSS too.
- Loading branch information
Dave Gurnell
committed
Jun 20, 2009
1 parent
1250e20
commit 3a064b6
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
(module reader syntax/module-reader | ||
#:language `(planet "module.ss" ("untyped" "mirrors.plt" 2) "javascript/sexp")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |