Next Prev Up Top Contents Index

define-form-parser

Macro
Summary

Establishes a parser for top level forms with the given definer.

Package

dspec

Signature

define-form-parser definer-and-options &optional parameters &body body => parser

Arguments

definer-and-options

A symbol definer naming a definer of functions, macros, variables and so on, or a list ( definer options ) where options is a plist of keys and values.

parameters

nil , or list of parameters in the top level form.

body

The body of a parser function.

Values

parser

A form parser function.

Description

The macro define-form-parser associates a form parser function with the definer named by definer .

options is a plist with the following keys allowed:

:parser

:alias

If parameters is supplied, then the form parser function is defined with the code in body . Otherwise the parser function is expected to be supplied as the value of the key :parser in the plist options, or you can specify as an alias a definer with an existing form parser via the :alias key in options .

Lispworks contains predefined form parser functions for the Common Lisp definers defun , defmethod , defgeneric , defvar , defparameter , defconstant , defstruct , defclass , defmacro and deftype and for LispWorks definers such as fli:define-foreign-type and dspec:define-form-parser itself.

When a defining symbol definer has an associated form parser, this parser function is used by the source location commands such as Expression > Find Source in the Common LispWorks development environment. Having identified the file where the definition spec was recorded, LispWorks parses the top level forms in the file looking for the one which matches the definition spec. When found, this match is displayed.

Example

Place these defining forms in a file and load it:

(defmacro parameterdef  (value name)
  `(defparameter ,name ,value))
 
(dspec:define-form-parser parameterdef (value name)
  `(defparameter ,name))
 
(parameterdef 42 *foo*)

Now the source of the definition of *foo* is displayed correctly by the source location commands. Without the form parser, this and related commands know that the definition is in the file, but cannot find the defining top level form.

In this second example note the use of define-dspec-alias to inform the dspec system that my-defmethod is simply another way of doing defmethod :

(defmacro my-defmethod (name args &body body)
  `(defmethod ,name ,args 
     ,@body))
 
(dspec:define-dspec-alias my-defmethod 
    (name &rest args)
  `(defmethod ,name ,@args))
 
(my-defmethod foo ((x number)) 
  42)
 
(dspec:define-form-parser 
    (my-defmethod 
        (:parser 
         #.(dspec:get-form-parser 'defmethod))))
See also

get-form-parser


LispWorks Reference Manual - 13 Jun 2003

Next Prev Up Top Contents Index