-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobjc-read-syntax.scm
37 lines (33 loc) · 1.04 KB
/
objc-read-syntax.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
;;;; read-syntax for ObjC method calls - highly problematic for those that use [...] as list notation
(require 'srfi-1)
(use objc-compile-time)
(set-read-syntax!
#\[
(lambda (port)
(let* ((receiver (read port))
(msg (read port)) )
(define (fail err . args)
(syntax-error err (cons* receiver msg '... args)))
(let loop ((args '()) (msg msg) (kw (keyword? msg)) (done (not (keyword? msg))))
(let ((c (peek-char port)))
(cond ((eof-object? c)
(fail "unexpected end of [ ... ]"))
((char=? c #\])
(read-char port)
(if kw
(fail "missing argument in [ ... ]")
(let ((args (reverse args)))
`(send ,receiver ,msg ,@args))))
((char-whitespace? c)
(read-char port)
(loop args msg kw done))
(kw
(let ((x (read port)))
(loop (cons x args) msg #f #f)))
(else
(let ((x (read port)))
(if (keyword? x)
(if done
(fail "unexpected argument in [ ... ]")
(loop args (append-keywords msg x) #t #f))
(fail "expected keyword in [ ... ]" x))))))))))