X-Git-Url: http://git.kpe.io/?p=umlisp.git;a=blobdiff_plain;f=parse-macros.lisp;h=490934fd79fa3836794cceac703a6ef665390849;hp=2a7469b75b58ed22b3dc9f3a8b5a3275bd2c358d;hb=6c10979737dc10b0c510b1edfe070346bcac3ff5;hpb=f8c80d433d78aa6df55309a6c04a80d3b7f1c679 diff --git a/parse-macros.lisp b/parse-macros.lisp index 2a7469b..490934f 100644 --- a/parse-macros.lisp +++ b/parse-macros.lisp @@ -7,10 +7,8 @@ ;;;; Author: Kevin M. Rosenberg ;;;; Created: Apr 2000 ;;;; -;;;; $Id$ -;;;; ;;;; This file, part of UMLisp, is -;;;; Copyright (c) 2000-2006 by Kevin M. Rosenberg, M.D. +;;;; Copyright (c) 2000-2010 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. @@ -22,57 +20,70 @@ "Read a line from a UMLS stream, split into fields" (let ((line (read-line strm nil eof))) (if (eq line eof) - eof - (delimited-string-to-list line #\| t)))) + eof + (delimited-string-to-list line #\| t)))) (defun source-files (path) (if (probe-file path) (list path) (sort (directory (make-pathname :defaults path - :type :wild - :name (concatenate 'string (pathname-name path) - (aif (pathname-type path) - (concatenate 'string "." it) - "")))) + :type :wild + :name (concatenate 'string (pathname-name path) + (aif (pathname-type path) + (concatenate 'string "." it) + "")))) #'(lambda (a b) - (string-lessp (pathname-type a) (pathname-type b)))))) + (string-lessp (pathname-type a) (pathname-type b)))))) (defmacro with-buffered-reading-umls-file ((line path) &body body) "Opens a UMLS and processes each parsed line with (body) argument" (let ((ustream (gensym "STRM-")) - (buffer (gensym "BUF-")) - (eof (gensym "EOF-")) - (files (gensym "FILES-"))) + (buffer (gensym "BUF-")) + (eof (gensym "EOF-")) + (files (gensym "FILES-"))) `(let ((,eof (gensym "EOFSYM-")) - (,buffer (make-fields-buffer)) - (,files (source-files ,path))) + (,buffer (make-fields-buffer)) + (,files (source-files ,path))) (with-open-file (,ustream (first ,files) :direction :input + #+(and sbcl sb-unicode) :external-format + #+(and sbcl sb-unicode) :UTF-8 + #+(and allegro ics) :external-format + #+(and allegro ics) :UTF-8 + #+lispworks :external-format + #+lispworks :UTF-8 #+(and clisp unicode) :external-format #+(and clisp unicode) charset:utf-8) - (do ((,line (read-buffered-fields ,buffer ,ustream #\| ,eof) - (read-buffered-fields ,buffer ,ustream #\| ,eof))) - ((eq ,line ,eof) t) - (setq ,line (coerce ,line 'list)) - (print ,line) - ,@body))))) + (do ((,line (read-buffered-fields ,buffer ,ustream #\| ,eof) + (read-buffered-fields ,buffer ,ustream #\| ,eof))) + ((eq ,line ,eof) t) + (setq ,line (coerce ,line 'list)) + (print ,line) + ,@body))))) (defmacro with-reading-umls-file ((line path) &body body) "Opens a UMLS and processes each parsed line with (body) argument" (let ((ustream (gensym "STRM-")) - (eof (gensym "EOF-")) - (files (gensym "FILES-"))) + (eof (gensym "EOF-")) + (files (gensym "FILES-"))) `(let ((,eof (gensym "EOFSYM-")) - (,files (source-files ,path))) + (,files (source-files ,path))) (unless ,files (error "Can't find files for ~A~%" (namestring ,path))) (with-open-file (,ustream (first ,files) :direction :input - #+(and clisp unicode) :external-format - #+(and clisp unicode) charset:utf-8) + #+(and sbcl sb-unicode) :external-format + #+(and sbcl sb-unicode) :UTF-8 + #+(and allegro ics) :external-format + #+(and allegro ics) :UTF-8 + #+lispworks :external-format + #+lispworks :UTF-8 + #+(and clisp unicode) :external-format + #+(and clisp unicode) charset:utf-8) (do ((,line (read-umls-line ,ustream ,eof) (read-umls-line ,ustream ,eof))) ((eq ,line ,eof) t) - ,@body))))) + (locally (declare (type list ,line)) + ,@body)))))) (defmacro with-umls-ufile ((line ufile) &body body) "Opens a UMLS and processes each parsed line with (body) argument" @@ -87,15 +98,23 @@ (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-"))) + (buffer (gensym "BUF-")) + (eof (gensym "EOF-"))) `(let ((,buffer (make-fields-buffer)) - (,eof (gensym "EOFSYM-"))) + (,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))))) + (,ustream (umls-pathname ,filename) :direction :input + #+(and sbcl sb-unicode) :external-format + #+(and sbcl sb-unicode) :UTF-8 + #+(and allegro ics) :external-format + #+(and allegro ics) :UTF-8 + #+lispworks :external-format + #+lispworks :UTF-8 + #+(and clisp unicode) :external-format + #+(and clisp unicode) charset:utf-8) + (do ((,line (read-buffered-fields ,buffer ,ustream #\| ,eof) + (read-buffered-fields ,buffer ,ustream #\| ,eof))) + ((eq ,line ,eof) t) + ,@body)))))