PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/brackets.scm

http://github.com/alimoeeny/arc
Scheme | 48 lines | 17 code | 16 blank | 15 comment | 0 complexity | 5af4777794c8751d75f3abe7b9b0beb5 MD5 | raw file
 1; From Eli Barzilay, eli@barzilay.org
 2
 3;> (require "brackets.scm") 
 4;> (use-bracket-readtable) 
 5;> ([+ _ 1] 10) 
 6;11
 7
 8(module brackets mzscheme
 9  
10; main reader function for []s
11; recursive read starts with default readtable's [ parser,
12; but nested reads still use the curent readtable:
13
14(define (read-square-brackets ch port src line col pos)
15  `(make-br-fn
16     ,(read/recursive port #\[ #f)))
17  
18; a readtable that is just like the builtin except for []s
19
20(define bracket-readtable
21  (make-readtable #f #\[ 'terminating-macro read-square-brackets))
22  
23; call this to set the global readtable
24
25(provide use-bracket-readtable)
26
27(define (use-bracket-readtable)
28  (current-readtable bracket-readtable))
29  
30; these two implement the required functionality for #reader
31    
32;(define (*read inp)
33;  (parameterize ((current-readtable bracket-readtable))
34;    (read inp)))
35
36(define (*read . args)
37  (parameterize ((current-readtable bracket-readtable))
38    (read (if (null? args) (current-input-port) (car args)))))
39
40(define (*read-syntax src port)
41  (parameterize ((current-readtable bracket-readtable))
42    (read-syntax src port)))
43
44; and the need to be provided as `read' and `read-syntax'
45
46(provide (rename *read read) (rename *read-syntax read-syntax))
47
48)