Skip to content

Commit

Permalink
Use symbols +cite-key+ (rather than the string "KEY") and +entry-type+
Browse files Browse the repository at this point in the history
(rather than the string "ENTRY-TYPE") as keys for the cite key and
the entry types in the hash table representing a bibliographic entry.
This removes the confusion with the bibliography-defined attribute "KEY".

(bib-entry-cite-key, bib-entry-type): New accessor macros.
Use them throughout.
  • Loading branch information
mkoeppe committed Dec 17, 2007
1 parent 2733b29 commit d26a952
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
28 changes: 21 additions & 7 deletions bibtex-runtime.lisp
Expand Up @@ -62,6 +62,20 @@ everything up to the beginning of the next entry."
(mark-fatal)
(error "Fatal BibTeX error"))

;;; Interface to BibTeX entries

;; BibTeX entries are EQUALP hash tables, the keys being arbitrary strings.
;; In addition, we use two symbols as keys:

(defvar +cite-key+ '+cite-key+)
(defvar +entry-type+ '+entry-type+)

(defmacro bib-entry-cite-key (entry)
`(gethash +cite-key+ ,entry))

(defmacro bib-entry-type (entry)
`(gethash +entry-type+ ,entry))

;;; Reading the database files

(defvar *bib-stream* nil)
Expand Down Expand Up @@ -265,8 +279,8 @@ non-nil, remove any leading or trailing whitespace."
(bib-error "Expected `,' character"))
(read-char *bib-stream*)
(let ((entry (make-bib-entry)))
(setf (gethash "entry-type" entry) (string-downcase entry-type))
(setf (gethash "key" entry) key)
(setf (bib-entry-type entry) (string-downcase entry-type))
(setf (bib-entry-cite-key entry) key)
(loop (multiple-value-bind (name value)
(read-bib-field t)
(setf (gethash name entry)
Expand All @@ -288,12 +302,12 @@ non-nil, remove any leading or trailing whitespace."

(defun write-bib-entry (entry &optional (stream *standard-output*))
(format stream "~&@~A{~A"
(gethash "entry-type" entry)
(gethash "key" entry))
(bib-entry-type entry)
(bib-entry-cite-key entry))
(loop for field being each hash-key in entry
and value being each hash-value in entry
unless (or (string-equal field "entry-type")
(string-equal field "key"))
unless (or (eql field +entry-type+)
(eql field +cite-key+))
do (format stream ",~% ~A = {~A}" field value))
(format stream "~%}~%"))

Expand Down Expand Up @@ -1125,7 +1139,7 @@ copies of that entry).")
(defun check-multiple-cited-equivalent-entries (bib-entries)
(let ((equivalence-classes
(compute-bib-equivalence-classes))
(bib-keys (mapcar (lambda (entry) (gethash "KEY" entry)) bib-entries)))
(bib-keys (mapcar #'bib-entry-cite-key bib-entries)))
(loop for class in equivalence-classes
do (let ((cited-equivalent-keys
(remove-if-not (lambda (key) (member key bib-keys :test 'equalp))
Expand Down
12 changes: 6 additions & 6 deletions bst-builtins.lisp
Expand Up @@ -44,15 +44,15 @@

(define-bst-primitive "call.type$" () ()
:interpreted
(let* ((type (gethash "ENTRY-TYPE" *bib-entry*))
(let* ((type (bib-entry-type *bib-entry*))
(function (or (get-bst-function-of-type type '(wiz-defined compiled-wiz-defined))
(get-bst-function-of-type 'default.type '(wiz-defined compiled-wiz-defined)))))
(when function
(bst-execute function)))
:compiled
(let ((type/fun-sym (bst-intern "TYPE/FUN")))
`(let ((,type/fun-sym
(assoc (gethash "ENTRY-TYPE" *bib-entry*)
(assoc (bib-entry-type *bib-entry*)
*bib-entry-type-functions* :test 'string-equal)))
(if ,type/fun-sym
(funcall (cdr ,type/fun-sym))
Expand Down Expand Up @@ -101,8 +101,8 @@
0)))

(define-bst-primitive "cite$" () ((string))
:interpreted (gethash "KEY" *bib-entry* "")
:compiled `(gethash "KEY" *bib-entry* ""))
:interpreted (or (bib-entry-cite-key *bib-entry*) "")
:compiled `(or (bib-entry-cite-key *bib-entry*) ""))

(define-bst-primitive "duplicate$" ((object t)) (t t)
:interpreted (values object object))
Expand Down Expand Up @@ -201,8 +201,8 @@
:side-effects-p t)

(define-bst-primitive "type$" () ((string))
:interpreted (gethash "ENTRY-TYPE" *bib-entry* "")
:compiled `(gethash "ENTRY-TYPE" *bib-entry* ""))
:interpreted (or (bib-entry-type *bib-entry*) "")
:compiled `(or (bib-entry-type *bib-entry*) ""))

(define-bst-primitive "warning$" ((warning (string))) ()
:interpreted (bib-warn warning)
Expand Down
1 change: 1 addition & 0 deletions packages.lisp
Expand Up @@ -20,6 +20,7 @@
#:*bib-entry* #:*bib-preamble* #:*bib-style*
#:*bib-files* #:*cite-all-entries* #:*cite-keys*
#:*bib-entry-type-functions* #:*min-crossrefs*
#:bib-entry-cite-key #:bib-entry-type
#:read-aux-file #:read-bib-database #:cited-bib-entries
#:write-bib-entry
#:read-all-bib-files-and-compute-bib-entries
Expand Down

0 comments on commit d26a952

Please sign in to comment.