home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
vis-ftp.cs.umass.edu
/
vis-ftp.cs.umass.edu.tar
/
vis-ftp.cs.umass.edu
/
pub
/
Software
/
ASCENDER
/
ascendMar8.tar
/
UMass
/
ISR
/
isr2macros.lisp
< prev
next >
Wrap
Text File
|
1995-04-11
|
8KB
|
232 lines
;;; -*- Mode:Common-Lisp; Package:isr2; Base:10 -*-
;;;------------------------------------------------------------------------
;;; ISR2TSS.LISP - Token[sub]sequence functions
;;; Created: Wed May 18 10:07:22 1988
;;; Author: Robert Heller
;;;------------------------------------------------------------------------
;;; Copyright (c) University of Massachusetts 1988
;;;------------------------------------------------------------------------
(in-package "ISR2")
(defmacro for-every-token ((token-var path &optional feature-list) &body body)
"FOR-EVERY-TOKEN (token-var path &OPTIONAL feature-list) &BODY body -
Traverse the TSS described by path and executes the body with the feature names
in feature-list bound to token-feature handles indexed to the current token."
(let ((pathvar (gensym))
(parsed-path (gensym))
(path-handle (gensym))
(more-path (gensym))
(frame-handle (gensym))
(token-index (gensym))
)
(setf feature-list
(mapcar #'(lambda (fname)
(intern (string-upcase fname)
*package*))
feature-list))
`(let* ((,pathvar ,path)
(,parsed-path (parse-token-name ,pathvar)))
(multiple-value-bind (,path-handle ,more-path)
(make-handle-from-parsed-path ,parsed-path)
(unless (and (handle-p ,path-handle)
(check-terminal-path ,path-handle
,more-path)
(null ,more-path)
(member (handle-type ,path-handle)
'(:frame :token-subset :token-sort)))
(error "~S is not a TSS or TS !" ,pathvar))
(let ((,frame-handle
(make-handle :type :frame
:frame (handle-frame ,path-handle)))
(,token-var (make-handle :type :token
:frame (handle-frame ,path-handle)
:token :?))
)
(let ,(mapcar
#'(lambda (fname)
`(,fname
(make-handle
:type :token-feature
:frame (handle-frame ,frame-handle)
:feature ,(string-upcase fname)
:token :?
:fdescr
(or (first (member
,(string-upcase fname)
(frame-token-set-feature-vector
(handle-frame ,frame-handle))
:test #'equalp
:key #'fdescr-featurename))
(error
"~S is not a token feature of frame ~S"
',fname
,frame-handle)))))
feature-list)
(cond ((eq (handle-type ,path-handle) :frame)
(do-active-tokens
(,token-index
(frame-token-set-globalp-vector
(handle-frame
,path-handle)))
(setf (handle-token ,token-var)
,token-index
,@(mapcan
#'(lambda (fname)
`((handle-token
,fname)
,token-index))
feature-list)
)
,@body))
((typep (handle-token-existence-array
,path-handle)
'2index-vector-vector)
(do-active-tokens
(,token-index
(handle-token-existence-array ,path-handle))
(setf (handle-token ,token-var) ,token-index)
(when (token-exists-p ,token-var)
(setf ,@(mapcan
#'(lambda (fname)
`((handle-token
,fname)
,token-index))
feature-list)
)
,@body))
)
(t (dolist (,token-index
(handle-token-existence-array ,path-handle))
(setf (handle-token ,token-var) ,token-index)
(when (token-exists-p ,token-var)
(setf ,@(mapcan
#'(lambda (fname)
`((handle-token
,fname)
,token-index))
feature-list)
)
,@body)))
)
)
)
)
)
)
)
(defmacro for-every-token! ((token-symbol tokensubset feature-handle-list
&key (error-check nil))
&body body)
"Body is executed once for each token in the given tokensubset. Each time
through the loop, token-symbol is bound to the current token handle.
Feature-handle-list is a list of feature handles from the given tokensubset.
Each time through the loop all feature handles get destructively changed to point
to their respective features for the current token. By default, no error
checking takes place, but error checking can be forced by specifying the
error-check key as non-nil. Error checking tests to see if each feature-handle
in the feature-handle-list points to a feature in the given tokensubset."
(let ((echeck (gensym))
(feat (gensym))
(tokset (gensym))
(feat-list (gensym))
(tokframe (gensym))
)
`(let* ((,echeck ,error-check)
(,tokset (handle ,tokensubset))
(,feat-list ,feature-handle-list)
(,tokframe (handle-frame (frame ,tokset)))
)
(when ,echeck
(dolist (,feat ,feat-list)
(unless (and (handle-p ,feat)
(eq (handle-type ,feat) :token-feature)
(eq (handle-frame (frame ,feat))
,tokframe)
(member (handle-feature ,feat)
(frame-token-set-feature-vector ,tokframe)
:test #'equalp
:key #'fdescr-featurename))
(error "Bad feature-handle: ~S (tokensubset = ~S)"
,feat ,tokset))))
(unwind-protect
(for-every-token (,token-symbol ,tokset)
(map nil #'(lambda (,feat)
(setf (handle-token ,feat)
(handle-token ,token-symbol)))
,feat-list)
,@body)
(map nil #'(lambda (,feat)
(setf (handle-token ,feat)
:?)
) ,feat-list)
)
)
)
)
(defmacro for-every-feature! ((feature-symbol feature-list frame-handle
&optional token-handle-list
&key (error-check nil))
&body body)
"Body is executed once for each feature in the feature list. Each time through
the loop, feature-symbol is bound to the current feature handle. Frame-handle
is a reference frame for the feature-list. Token-handle-list, if given, is a
list of token handles from the same tokensubset. Each time through the loop all
token handles get destructively changed to point to their respective features
for the current feature. By default, no error checking takes place, but error
checking can be forced by specifying the error-check key as non-nil. Error
checking tests to see if each token-handle in the token-handle-list points to the
same tokensubset, and that each feature in the feature-list is a valid feature for
that tokensubset."
(let ((feat-list (gensym))
(frame-hand (gensym))
(frame (gensym))
(token-h-list (gensym))
(echeck (gensym))
(feat (gensym))
(tok (gensym))
)
`(let* ((,feat-list ,feature-list)
(,frame-hand (handle ,frame-handle))
(,token-h-list ,token-handle-list)
(,echeck ,error-check)
(,frame (handle-frame ,frame-hand))
(,feature-symbol (copy-handle ,frame-hand))
)
(when ,echeck
(dolist (,tok ,token-h-list)
(unless (and (handle-p ,tok)
(eq (handle-type ,tok) :token)
(integerp (handle-token ,tok))
(eq (handle-frame ,tok) ,frame))
(error "Token ~S not in frame ~S" ,tok ,frame-hand)))
(dolist (,feat ,feat-list)
(unless (member (string ,feat)
(frame-token-set-feature-vector ,frame)
:test #'equalp
:key #'fdescr-featurename)
(error "feature ~s not in frame ~s" ,feat ,frame-hand))))
(setf (handle-type ,feature-symbol) :token-feature
(handle-token ,feature-symbol) :?)
(dolist (,tok ,token-h-list)
(setf (handle-type ,tok) :token-feature))
(unwind-protect
(dolist (,feat ,feat-list)
(setf (handle-feature ,feature-symbol) ,feat
(handle-fdescr ,feature-symbol)
(first (member (string ,feat)
(frame-token-set-feature-vector ,frame)
:test #'equalp
:key #'fdescr-featurename)))
(dolist (,tok ,token-h-list)
(setf (handle-feature ,tok) (handle-feature ,feature-symbol)
(handle-fdescr ,tok) (handle-fdescr ,feature-symbol)))
,@body)
(dolist (,tok ,token-h-list)
(setf (handle-type ,tok) :token)))
)
)
)