diff options
-rw-r--r-- | Lisp/defpackage.lisp | 2 | ||||
-rw-r--r-- | Lisp/reader-syntax.lisp | 27 |
2 files changed, 27 insertions, 2 deletions
diff --git a/Lisp/defpackage.lisp b/Lisp/defpackage.lisp index 17a81c8..eaeae3e 100644 --- a/Lisp/defpackage.lisp +++ b/Lisp/defpackage.lisp @@ -25,6 +25,8 @@ #:shutdown-runtime #:enable-method-syntax #:enable-objective-c-syntax + #:disable-method-syntax + #:disable-objective-c-syntax #:invoke-by-name #:invoke #:find-objc-class diff --git a/Lisp/reader-syntax.lisp b/Lisp/reader-syntax.lisp index 56ae6db..4263df0 100644 --- a/Lisp/reader-syntax.lisp +++ b/Lisp/reader-syntax.lisp @@ -18,6 +18,10 @@ (in-package #:mulk.objective-cl) +(defvar *method-syntax-macro-chars* (list)) +(defvar *bracket-syntax-macro-chars* (list)) + + (defun enable-method-syntax () "Install a **reader macro** that makes method calls look nicer. @@ -66,11 +70,19 @@ __defgeneric__ form has been executed. __enable-objective-c-syntax__" + (push (get-dispatch-macro-character #\# #\/) *method-syntax-macro-chars*) (set-dispatch-macro-character #\# #\/ #'(lambda (stream char arg) (declare (ignore char arg)) (read-objective-c-method stream)))) +(defun disable-method-syntax () + "FIXME" + (when *method-syntax-macro-chars* + (let ((macro-char (pop *method-syntax-macro-chars*))) + (set-dispatch-macro-character #\# #\/ macro-char)))) + + (defun read-objective-c-method (stream) (loop for char = (read-char stream nil nil t) while (or (alphanumericp char) @@ -85,7 +97,7 @@ __defgeneric__ form has been executed. (defun install-reader-syntax () "This function is deprecated. Use __enable-objective-c-syntax__ instead." - (enable-reader-syntax)) + (enable-objective-c-syntax)) (defun enable-objective-c-syntax () @@ -199,13 +211,24 @@ conciseness. __invoke__, __invoke-by-name__, __disable-objective-c-syntax__, __enable-method-syntax__" + (push (cons (get-macro-character #\[) + (get-macro-character #\])) + *bracket-syntax-macro-chars*) (set-macro-character #\] (get-macro-character #\))) - (set-macro-character #\[ #'(lambda (stream char) (declare (ignore char)) (parse-objc-call stream)))) +(defun disable-objective-c-syntax () + "FIXME" + (when *bracket-syntax-macro-chars* + (destructuring-bind (open . close) + (pop *bracket-syntax-macro-chars*) + (set-macro-character #\[ open) + (set-macro-character #\[ close)))) + + (defun parse-objc-call (stream) (let ((*standard-input* stream)) (flet ((read-message-part (buffer) |