File: parse-macros.lisp

package info (click to toggle)
cl-umlisp-orf 3.3.2-3.1
  • links: PTS, VCS
  • area: contrib
  • in suites: bookworm, sid
  • size: 228 kB
  • sloc: lisp: 2,841; makefile: 56
file content (60 lines) | stat: -rw-r--r-- 2,381 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: umlisp -*-
;;;; *************************************************************************
;;;; FILE IDENTIFICATION
;;;;
;;;; Name:     parse-macros.lisp
;;;; Purpose:  Macros for UMLS file parsing
;;;; Author:   Kevin M. Rosenberg
;;;; Created:  Apr 2000
;;;;
;;;; $Id$
;;;;
;;;; This file, part of UMLisp, is
;;;;    Copyright (c) 2000-2004 by Kevin M. Rosenberg, M.D.
;;;;
;;;; UMLisp users are granted the rights to distribute and use this software
;;;; as governed by the terms of the GNU General Public License.
;;;; *************************************************************************

(in-package #:umlisp-orf)

(defmacro with-umls-file ((line filename) &body body)
"Opens a UMLS and processes each parsed line with (body) argument"
  (let ((ustream (gensym "STRM-"))
        (eof (gensym "EOF-")))
    `(let ((,eof (gensym "EOFSYM-")))
      (with-open-file
          (,ustream (umls-pathname ,filename) :direction :input)
        (do ((,line (read-umls-line ,ustream ,eof)
                    (read-umls-line ,ustream ,eof)))
            ((eq ,line ,eof) t)
          ,@body)))))

(defmacro with-buffered-umls-file ((line filename) &body body)
  "Opens a UMLS and processes each parsed line with (body) argument"
  (let ((ustream (gensym "STRM-"))
        (buffer (gensym "BUF-"))
        (eof (gensym "EOF-")))
    `(let ((,buffer (make-fields-buffer))
           (,eof (gensym "EOFSYM-")))
      (with-open-file
          (,ustream (umls-pathname ,filename) :direction :input)
        (do ((,line (read-buffered-fields ,buffer ,ustream #\| ,eof)
                    (read-buffered-fields ,buffer ,ustream #\| ,eof)))
            ((eq ,line ,eof) t)
          ,@body)))))

(defmacro with-buffered2-umls-file ((line filename) &body body)
  "Opens a UMLS and processes each parsed line with (body) argument"
  (let ((ustream (gensym "STRM-"))
        (buffer (gensym "BUF-"))
        (eof (gensym "EOF-")))
    `(let ((,buffer (make-fields-buffer2))
           (,eof (gensym "EOFSYM-")))
      (with-open-file
          (,ustream (umls-pathname ,filename)
           :direction :input :if-exists :overwrite)
        (do ((,line (read-buffered-fields ,buffer ,ustream #\| ,eof)
                    (read-buffered-fields ,buffer ,ustream #\| ,eof)))
            ((eq ,line ,eof) t)
          ,@body)))))