forked from tensorfork/tlarc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
brackets.scm
58 lines (39 loc) · 1.55 KB
/
brackets.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#lang racket/load
; From Eli Barzilay, [email protected]
;> (require "brackets.scm")
;> (use-bracket-readtable)
;> ([+ _ 1] 10)
;11
; (module brackets racket/base
; main reader function for []s
; recursive read starts with default readtable's [ parser,
; but nested reads still use the curent readtable:
; (define (arc-read-square-brackets ch port src line col pos)
; `(fn (_)
; ,(read/recursive port #\[ #f)))
(define (arc-read-square-brackets ch port src line col pos)
#`(%brackets #,@(read-syntax/recursive ch port #\[ #f)))
(define (arc-read-curly-braces ch port src line col pos)
#`(%braces #,@(read-syntax/recursive ch port #\{ #f)))
; a readtable that is just like the builtin except for []s
(define arc-readtable
(make-readtable #f #\[ 'terminating-macro arc-read-square-brackets
#\{ 'terminating-macro arc-read-curly-braces))
; call this to set the global readtable
; (provide use-arc-readtable)
(define (use-arc-readtable)
(current-readtable arc-readtable))
; these two implement the required functionality for #reader
;(define (*read inp)
; (parameterize ((current-readtable arc-readtable))
; (read inp)))
(define (arc-read (port (current-input-port)))
(parameterize ((current-readtable arc-readtable))
(read port)))
(define (arc-read-syntax src (port (current-input-port)))
(parameterize ((current-readtable arc-readtable))
(read-syntax src port)))
; and the need to be provided as `read' and `read-syntax'
; (provide (rename *read read) (rename *read-syntax read-syntax))
; )
'brackets