Created
May 12, 2011 19:53
-
-
Save qerub/969308 to your computer and use it in GitHub Desktop.
Revisions
-
qerub revised this gist
May 27, 2011 . 1 changed file with 7 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -9,18 +9,21 @@ (if (stx-list? stx) (let ((stx* (stx-map rewrite-method-calls stx))) (if (eq? (syntax-property stx 'paren-shape) #\[) (match (stx->list stx*) ((list obj msg args ...) #`(send #,obj '#,msg #,@args))) stx*)) stx)) (define (objective-r-read . args) (let ((stx (apply objective-r-read-syntax #f args))) (if (eof-object? stx) stx (syntax->datum stx)))) (define (objective-r-read-syntax . args) ; TODO: Do something with the rest of the arguments (rewrite-method-calls (read-syntax (first args) (second args)))) ; Example: (objective-r-read (open-input-string "[[document get-element-by-id stuff] remove]")) ; => (send (send document 'get-element-by-id stuff) 'remove) -
qerub revised this gist
May 25, 2011 . 1 changed file with 6 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,10 @@ #lang racket ; Requires Racket >= 5.1.1 (provide (rename-out (objective-r-read read) (objective-r-read-syntax read-syntax))) (require syntax/stx) (define (rewrite-method-calls stx) (if (stx-list? stx) (let ((stx* (stx-map rewrite-method-calls stx))) @@ -19,12 +13,12 @@ stx*)) stx)) (define (objective-r-read . args) (let ((stx (apply read-syntax #f args))) (if (eof-object? stx) stx (syntax->datum stx)))) (define (objective-r-read-syntax . args) (rewrite-method-calls (read-syntax (first args) (second args)))) ; Example: -
qerub revised this gist
May 24, 2011 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,8 @@ (let ((stx (apply read-syntax #f args))) (if (eof-object? stx) stx (syntax->datum stx)))) (define (read-syntax . args) (rewrite-method-calls (vanilla-read-syntax (first args) (second args)))) ; Example: -
qerub revised this gist
May 24, 2011 . 1 changed file with 1 addition and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -11,14 +11,11 @@ (define (stx-map proc stxl) (datum->syntax stxl (map proc (stx->list stxl)))) (define (rewrite-method-calls stx) (if (stx-list? stx) (let ((stx* (stx-map rewrite-method-calls stx))) (if (eq? (syntax-property stx 'paren-shape) #\[) #`(send #,stx*) stx*)) stx)) -
qerub revised this gist
May 24, 2011 . 1 changed file with 23 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,30 +1,34 @@ #lang racket (provide read read-syntax) (require (rename-in racket/base (read vanilla-read) (read-syntax vanilla-read-syntax))) (require syntax/stx) ; Not available in Racket 5.1 :( (define (stx-map proc stxl) (datum->syntax stxl (map proc (stx->list stxl)))) (define (stx-cons stx stxl) (datum->syntax stx (cons stx stxl))) (define (rewrite-method-calls stx) (if (stx-list? stx) (let ((stx* (stx-map rewrite-method-calls stx))) (if (eq? (syntax-property stx 'paren-shape) #\[) (stx-cons #'send stx*) stx*)) stx)) (define (read . args) (let ((stx (apply read-syntax #f args))) (if (eof-object? stx) stx (syntax->datum stx)))) (define read-syntax (compose rewrite-method-calls vanilla-read-syntax)) ; Example: (read (open-input-string "[[document get-element-by-id stuff] remove]")) ; => (send (send document get-element-by-id stuff) remove) -
qerub created this gist
May 12, 2011 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ #lang racket ; TODO: Add support for nested method calls (require syntax/stx) (provide read read-syntax) (define (read in) (let ((stx (read-syntax #f in))) (if (eof-object? stx) stx (syntax->datum stx)))) (define (read-syntax src in) (read-syntax/recursive src in #f (objective-r-readtable))) (define (objective-r-readtable) (define (handle-method-call ch in src line col pos) (rewrite (read-syntax/recursive (object-name in) in #\[ #f))) (define (rewrite stx) (match (stx->list stx) ((list obj message args ...) #`(send #,obj '#,message #,@args)))) (make-readtable (current-readtable) #\[ 'terminating-macro handle-method-call)) ; Example: (read (open-input-string "[[document get-element-by-id stuff] remove]"))