[climacs-cvs] CVS climacs

thenriksen thenriksen at common-lisp.net
Sun Apr 23 15:17:17 UTC 2006


Update of /project/climacs/cvsroot/climacs
In directory clnet:/tmp/cvs-serv20924

Modified Files:
	lisp-syntax.lisp 
Log Message:
Added convenience functions for picking out elements of forms.


--- /project/climacs/cvsroot/climacs/lisp-syntax.lisp	2006/04/23 15:14:49	1.55
+++ /project/climacs/cvsroot/climacs/lisp-syntax.lisp	2006/04/23 15:17:17	1.56
@@ -1264,6 +1264,36 @@
   "Returns the third formw in list."
   (nth-form 2 list))
 
+(defgeneric form-operator (form syntax)
+  (:documentation "Return the operator of `form' as a Lisp
+object. Returns nil if none can be found.")
+  (:method (form syntax) nil))
+
+(defmethod form-operator ((form list-form) syntax)
+  (let* ((operator-token (first-form (rest (children form))))
+         (operator-symbol (when operator-token
+                            (token-to-object syntax operator-token t))))
+    operator-symbol))
+
+(defgeneric form-operands (form syntax)
+  (:documentation "Returns the operands of `form' as a list of
+  Lisp objects. Returns nil if none can be found.")
+  (:method (form syntax) nil))
+
+(defmethod form-operands ((form list-form) syntax)
+  ;; If *anything' goes wrong, just assume that we could not find any
+  ;; operands and return nil.
+  (mapcar #'(lambda (operand)
+              (if (typep operand 'form)
+                  (token-to-object syntax operand t)))
+          (rest-forms (children form))))
+
+(defun form-toplevel (form syntax)
+  "Return the top-level form of `form'."
+  (if (null (parent (parent form)))
+      form
+      (form-toplevel (parent form) syntax)))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;
 ;;; display




More information about the Climacs-cvs mailing list