Skip to content

Instantly share code, notes, and snippets.

@danking
Created February 10, 2011 00:35
Show Gist options
  • Select an option

  • Save danking/819682 to your computer and use it in GitHub Desktop.

Select an option

Save danking/819682 to your computer and use it in GitHub Desktop.
(define read-js
(lambda (ch port src line col pos)
(datum->syntax
#f
(->js (read port))
(let-values ([(l c p) (port-next-location port)])
(list src line col pos (and pos (- p pos)))))))
(define js-readtable
(make-readtable #f #f 'non-terminating-macro read-js))
(define (test x)
(parameterize ([current-readtable js-readtable])
(read (open-input-string x))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> > > > (test "(js:lambda (x y) (js:+ x y))")
UNKNOWN::15: read: unexpected `)'
=== context ===
stdin::8017: read-js
stdin::8017: read-js
stdin::8017: read-js
stdin::8017: read-js
stdin::8017: read-js
stdin::8017: read-js
stdin::8017: read-js
stdin::8017: read-js
stdin::8017: read-js
stdin::8017: read-js
stdin::8017: read-js
/usr/local/lib/racket/collects/racket/private/misc.rkt:74:7
> (test "'(1 2 3)")
UNKNOWN::7: read: unexpected `)'
=== context ===
stdin::8017: read-js
stdin::8017: read-js
stdin::8017: read-js
/usr/local/lib/racket/collects/racket/private/misc.rkt:74:7
> (test "1")
#<eof>
> (test "1 2")
#<eof>
> (test "(1 2)")
UNKNOWN::4: read: unexpected `)'
=== context ===
stdin::8017: read-js
stdin::8017: read-js
/usr/local/lib/racket/collects/racket/private/misc.rkt:74:7
> (test "'(1 2)")
UNKNOWN::5: read: unexpected `)'
=== context ===
stdin::8017: read-js
stdin::8017: read-js
/usr/local/lib/racket/collects/racket/private/misc.rkt:74:7
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment