r2960: *** empty log message ***
[umlisp.git] / parse-macros.lisp
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: umlisp -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          parse-macros.lisp
6 ;;;; Purpose:       Macros for UMLS file parsing
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Apr 2000
9 ;;;;
10 ;;;; $Id: parse-macros.lisp,v 1.2 2002/10/09 23:03:41 kevin Exp $
11 ;;;;
12 ;;;; This file, part of UMLisp, is
13 ;;;;    Copyright (c) 2000-2002 by Kevin M. Rosenberg, M.D.
14 ;;;;
15 ;;;; UMLisp users are granted the rights to distribute and use this software
16 ;;;; as governed by the terms of the GNU General Public License.
17 ;;;; *************************************************************************
18
19 (in-package :umlisp)
20 (declaim (optimize (speed 3) (safety 1) (compilation-speed 0) (debug 3)))
21
22
23 (defmacro with-umls-file ((line filename) &body body)
24 "Opens a UMLS and processes each parsed line with (body) argument"
25   (let ((ustream (gensym)))
26     `(with-open-file
27       (,ustream (umls-pathname ,filename)
28                 :direction :input :if-exists :overwrite)
29       (do ((,line (read-umls-line ,ustream) (read-umls-line ,ustream)))
30           ((eq ,line 'eof) t)
31         ,@body))))
32
33 (defmacro with-buffered-umls-file ((line filename) &body body)
34 "Opens a UMLS and processes each parsed line with (body) argument"
35   (let ((ustream (gensym))
36         (buffer (gensym)))
37     `(let ((,buffer (make-fields-buffer)))
38        (with-open-file
39            (,ustream (umls-pathname ,filename)
40             :direction :input :if-exists :overwrite)
41          (do ((,line (read-buffered-fields ,buffer ,ustream) (read-buffered-fields ,buffer ,ustream)))
42              ((eq ,line 'eof) t)
43            ,@body)))))
44
45 (defmacro with-buffered2-umls-file ((line filename) &body body)
46 "Opens a UMLS and processes each parsed line with (body) argument"
47   (let ((ustream (gensym))
48         (buffer (gensym)))
49     `(let ((,buffer (make-fields-buffer2)))
50        (with-open-file
51            (,ustream (umls-pathname ,filename)
52             :direction :input :if-exists :overwrite)
53          (do ((,line (read-buffered-fields2 ,buffer ,ustream) (read-buffered-fields2 ,buffer ,ustream)))
54              ((eq ,line 'eof) t)
55            ,@body)))))
56