From unknown Sat Jun 21 12:12:26 2025 X-Loop: help-debbugs@gnu.org Subject: bug#55035: [PATCH] biblio: Replace template interpreter with a macro (a "compiler"). Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: skribilo-bugs@nongnu.org Resent-Date: Wed, 20 Apr 2022 10:14:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 55035 X-GNU-PR-Package: skribilo X-GNU-PR-Keywords: patch To: 55035@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= X-Debbugs-Original-To: skribilo-bugs@nongnu.org Received: via spool by submit@debbugs.gnu.org id=B.165044962131126 (code B ref -1); Wed, 20 Apr 2022 10:14:01 +0000 Received: (at submit) by debbugs.gnu.org; 20 Apr 2022 10:13:41 +0000 Received: from localhost ([127.0.0.1]:45126 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nh7L8-00085q-Aw for submit@debbugs.gnu.org; Wed, 20 Apr 2022 06:13:41 -0400 Received: from lists.gnu.org ([209.51.188.17]:51844) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nh7L6-00085g-D5 for submit@debbugs.gnu.org; Wed, 20 Apr 2022 06:13:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55392) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nh7L6-0007E0-5b for skribilo-bugs@nongnu.org; Wed, 20 Apr 2022 06:13:36 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:59876) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nh7L5-0003cY-6C; Wed, 20 Apr 2022 06:13:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=FigNWw3CdRscmw+hF468HIjmkYUyhynwK1TsAHEGbSM=; b=VjB0J7NQ1tk62q RvYqaV9qRVqQzDjeE2Y8eMf915SblH/JxRxRpX+9oLsWmuDb58zSyKpRgdVUjfTiv0hgW/FrD/WKc 2vS9cqq7/yKKivC1D/PfPBpZbo2unydaQpHPPuZ+VryMepyQcrU3ChbW/PAps5DPgVDCn4Y8wisRk 4K1FvlflteeEftkbvqz8FLtYCIJv5irAV9Wo+/mzSQBZuYUeQGtHpR7zqs1sfyqgrz6Li71TGHNW3 1CnWQYnPkgyDCWGW8EoYGQCsZYPzpmenf1ov0tqYNMjM07N84QRU4T3UA9g0cRBzGxhBOUaDl4971 qoyEwQ2d/Qaty4k5PQaQ==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:63454 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nh7L4-0008ET-E3; Wed, 20 Apr 2022 06:13:34 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Wed, 20 Apr 2022 12:13:25 +0200 Message-Id: <20220420101325.19577-1-ludo@gnu.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) This allows us to catch invalid templates at macro-expansion time and is more efficient. * src/guile/skribilo/biblio/template.scm (evaluate-bib-entry-template): Remove. (define-template-engine, bibliography-template): New macros. (output-bib-entry-template): Rewrite and remove 'get-field' optional argument. (make-bib-entry-template/default, make-bib-entry-template/skribe): Use 'bibliography-template' instead of quasiquote/unquote. * src/guile/skribilo/package/jfp.scm (le): Likewise. * src/guile/skribilo/package/lncs.scm (bib-entry-template): Likewise. * src/guile/skribilo/biblio.scm (&biblio-template-error): Remove. (handle-biblio-error): Adjust accordingly. * tests/biblio.test: New file. * tests/Makefile.am (TESTS): Add it. --- src/guile/skribilo/biblio.scm | 16 +- src/guile/skribilo/biblio/template.scm | 304 ++++++++++++------------- src/guile/skribilo/package/jfp.scm | 75 +++--- src/guile/skribilo/package/lncs.scm | 111 ++++----- tests/Makefile.am | 1 + tests/biblio.test | 88 +++++++ 6 files changed, 336 insertions(+), 259 deletions(-) create mode 100644 tests/biblio.test diff --git a/src/guile/skribilo/biblio.scm b/src/guile/skribilo/biblio.scm index 9d83cde..7d95d51 100644 --- a/src/guile/skribilo/biblio.scm +++ b/src/guile/skribilo/biblio.scm @@ -55,13 +55,11 @@ bib-sort-refs/number ;; error conditions - &biblio-error &biblio-entry-error &biblio-template-error + &biblio-error &biblio-entry-error &biblio-parse-error - biblio-error? biblio-entry-error? biblio-template-error? + biblio-error? biblio-entry-error? biblio-parse-error? biblio-entry-error:entry - biblio-template-error:expression - biblio-template-error:template biblio-parse-error:sexp)) ;;; Commentary: @@ -86,11 +84,6 @@ biblio-entry-error? (entry biblio-entry-error:entry)) -(define-condition-type &biblio-template-error &biblio-error - biblio-template-error? - (expression biblio-template-error:expression) - (template biblio-template-error:template)) - (define-condition-type &biblio-parse-error &biblio-error biblio-parse-error? (sexp biblio-parse-error:sexp)) @@ -110,11 +103,6 @@ (format (current-error-port) (G_ "invalid bibliography entry: ~a~%") entry)))) - ((biblio-template-error? c) - (format (current-error-port) - (G_ "invalid bibliography entry template: '~a', in '~a'~%") - (biblio-template-error:expression c) - (biblio-template-error:template c))) ((biblio-parse-error? c) (format (current-error-port) (G_ "invalid bibliography entry s-exp: '~a'~%") diff --git a/src/guile/skribilo/biblio/template.scm b/src/guile/skribilo/biblio/template.scm index 96ac4e3..aefb20d 100644 --- a/src/guile/skribilo/biblio/template.scm +++ b/src/guile/skribilo/biblio/template.scm @@ -1,7 +1,7 @@ ;;; template.scm -- Template system for bibliography entries. ;;; ;;; Copyright 2003, 2004 Manuel Serrano -;;; Copyright 2006, 2007, 2015, 2018 Ludovic Courtès +;;; Copyright 2006, 2007, 2015, 2018, 2022 Ludovic Courtès ;;; ;;; ;;; This file is part of Skribilo. @@ -32,14 +32,14 @@ #:use-module (skribilo utils syntax) - #:export (evaluate-bib-entry-template - output-bib-entry-template - make-bib-entry-template/default - make-bib-entry-template/skribe)) + #:export (bibliography-template + output-bib-entry-template + make-bib-entry-template/default + make-bib-entry-template/skribe)) (skribilo-module-syntax) -;;; Author: Manuel Serrano, Ludovic Courtès +;;; Author: Manuel Serrano, Ludovic Courtès ;;; ;;; Commentary: ;;; @@ -57,85 +57,77 @@ ;;; Outputting a bibliography entry template for a specific entry. ;;; -(define (evaluate-bib-entry-template bib template . rest) - ;; An interpreter for the bibliography template language. Overview of the - ;; language: - ;; - ;; form := (cond-list|special-sexp|string|field-spec) - ;; - ;; field-spec := ("author"|"title"|...) - ;; cond-list := (form+) - ;; special-sexp := (("if" form form form?)|("or" form*)) - ;; - ;; A `cond-list' gets issued only if all its elements are true. - - (define get-field - (if (null? rest) - markup-option - (car rest))) - - (define (eval-cond-list sexp eval-sexp) - (let loop ((sexp sexp) - (result '())) - (if (null? sexp) - (reverse! result) - (let ((head (eval-sexp (car sexp)))) - (if (not head) - #f - (loop (cdr sexp) - (cons head result))))))) - - (define (eval-special-sexp sexp eval-sexp) - (let ((special (car sexp)) - (formals (cdr sexp))) - (case special - ((or) - (any eval-sexp formals)) - ((if) - (if (or (> (length formals) 3) - (< (length formals) 2)) - (raise (condition - (&biblio-template-error (expression sexp) - (template template))))) - (let* ((if-cond (car formals)) - (if-then (cadr formals)) - (if-else (if (null? (cddr formals)) - #f - (caddr formals))) - (result (eval-sexp if-cond))) - (if result - (eval-sexp if-then) - (eval-sexp if-else)))) - (else - (eval-cond-list sexp eval-sexp))))) - - (let loop ((template template)) - (cond ((symbol? template) - (get-field bib template)) - ((null? template) - #f) - ((pair? template) - (cond ((symbol? (car template)) - (eval-special-sexp template loop)) - (else - (eval-cond-list template loop)))) - ((string? template) - template) - (else - (raise (condition - (&biblio-template-error (expression template) - (template template)))))))) - - -(define* (output-bib-entry-template bib engine template - :optional (get-field markup-option)) +(define-syntax-rule (define-template-engine instantiate literal ...) + "Define INSTANTIATE as a macro that, given a template, produces a +one-argument procedure to instantiate that template given a '&bib-entry' +node. LITERAL... is the list of literals, the name of valid markup options." + (begin + (define-public literal + (lambda (s) + (syntax-violation 'literal + "template literal used outside of 'bibliography-template'" + s))) + ... + + (define-syntax instantiate-body + (lambda (s) + (define (literal? id) + (any (lambda (l) + (and (identifier? id) + (free-identifier=? id l))) + #'(literal ...))) + + (syntax-case s (literal ... or if G_) + ((_ n str rest (... ...)) + (string? (syntax->datum #'str)) + #'(cons str (instantiate-body n rest (... ...)))) + ((_ n (G_ str) rest (... ...)) + (string? (syntax->datum #'str)) + #'(cons (G_ str) (instantiate-body n rest (... ...)))) + ((_ n (or options (... ...)) rest (... ...)) + (every literal? #'(options (... ...))) + #'(cons (or (markup-option n 'options) (... ...)) + (instantiate-body n rest (... ...)))) + ((_ n (if cond a b) rest (... ...)) + (literal? #'cond) + #'(cons (if (markup-option n 'cond) + (instantiate-body n a) + (instantiate-body n b)) + (instantiate-body n rest (... ...)))) + ((_ n (lst (... ...)) rest (... ...)) + #'(append (let ((body (instantiate-body n lst (... ...)))) + (if (every ->bool body) + body + '())) + (instantiate-body n rest (... ...)))) + ((_ n literal rest (... ...)) + #'(cons (markup-option n 'literal) + (instantiate-body n rest (... ...)))) + ... + ((_ n) + #''())))) + + (define-syntax-rule (instantiate body (... ...)) + (lambda (n) + (instantiate-body n body (... ...)))))) + +;; Define 'bibliography-template' as a macro that builds a procedure to +;; instantiate a template from a '&bib-entry' node. +(define-template-engine bibliography-template + + ;; Keywords that may appear in the template. + author title url documenturl type + journal number volume series booktitle editor + school institution address + month year day + pages chapter publisher) + + +(define* (output-bib-entry-template bib engine template) ;; Output the fields of BIB (a bibliography entry) for ENGINE according to ;; TEMPLATE. Example of templates are found below (e.g., ;; `make-bib-entry-template/default'). - (output (map (lambda (form) - (evaluate-bib-entry-template bib form get-field)) - template) - engine)) + (output (template bib) engine)) ;;; @@ -147,98 +139,98 @@ (case kind ((techreport) - `(author ". " (or title url documenturl) ". " - ;; TRANSLATORS: The next few msgids are fragments of - ;; bibliography items. - ,(G_ "Technical Report") " " number - (", " institution) - (", " address) - (", " month) " " year - (", pp. " pages) ".")) + (bibliography-template author ". " (or title url documenturl) ". " + ;; TRANSLATORS: The next few msgids are fragments of + ;; bibliography items. + (G_ "Technical Report") " " number + (", " institution) + (", " address) + (", " month) " " year + (", pp. " pages) ".")) ((article) - `(author ". " (or title url documenturl) ". " - ,(G_ "In ") journal ", " volume - ("(" number ") ")", " - (address ", ") month " " year ", " - ("pp. " pages) ".")) + (bibliography-template author ". " (or title url documenturl) ". " + (G_ "In ") journal ", " volume + ("(" number ") ")", " + (address ", ") month " " year ", " + ("pp. " pages) ".")) ((inproceedings) - `(author ". " (or title url documenturl) ". " - ,(G_ "In ") booktitle ", " - (series ", ") - ("(" number ")") - ("pp. " pages ", ") - (publisher ", ") - (month " ") year ".")) + (bibliography-template author ". " (or title url documenturl) ". " + (G_ "In ") booktitle ", " + (series ", ") + ("(" number ")") + ("pp. " pages ", ") + (publisher ", ") + (month " ") year ".")) ((book) ;; FIXME: Title should be in italics - '((or author editor) - ". " (or title url documenturl) ". " - publisher - (", " address) - (", " month) - ", " year - (", pp. " pages) ".")) + (bibliography-template (or author editor) + ". " (or title url documenturl) ". " + publisher + (", " address) + (", " month) + ", " year + (", pp. " pages) ".")) ((inbook) - `(author ". " (or title url documenturl) ". " - ,(G_ "In ") booktitle ", " publisher - (", " editor " (" ,(G_ "editor") ")") - (", " ,(G_ "Chapter ") chapter) - (", pp. " pages) ", " - (month " ") year ".")) + (bibliography-template author ". " (or title url documenturl) ". " + (G_ "In ") booktitle ", " publisher + (", " editor " (" (G_ "editor") ")") + (", " (G_ "Chapter ") chapter) + (", pp. " pages) ", " + (month " ") year ".")) ((phdthesis) - `(author ". " (or title url documenturl) - ", " ,(G_ "PhD Thesis") - (", " (or school institution)) - (", " address) - (", " month) - (if month " " ", ") year ".")) + (bibliography-template author ". " (or title url documenturl) + ", " (G_ "PhD Thesis") + (", " (or school institution)) + (", " address) + (", " month) + (if month " " ", ") year ".")) ((misc) - '(author ". " (or title url documenturl) ". " - (institution ", ") - (publisher ", ") - (address ", ") - (month " ") year ". " - (url "."))) + (bibliography-template author ". " (or title url documenturl) ". " + (institution ", ") + (publisher ", ") + (address ", ") + (month " ") year ". " + (url "."))) (else - '(author ". " (or title url documenturl) ". " - (publisher ", ") - (address ", ") - (month " ") year ", " - ("pp. " pages) ".")))) + (bibliography-template author ". " (or title url documenturl) ". " + (publisher ", ") + (address ", ") + (month " ") year ", " + ("pp. " pages) ".")))) (define (make-bib-entry-template/skribe kind) ;; The awful template found by default in Skribe. (case kind ((techreport) - `(author " -- " (or title url documenturl) " -- " - ,(G_ "Technical Report") " " number ", " institution ", " - address ", " month ", " year ", " - ("pp. " pages) ".")) + (bibliography-template author " -- " (or title url documenturl) " -- " + (G_ "Technical Report") " " number ", " institution ", " + address ", " month ", " year ", " + ("pp. " pages) ".")) ((article) - `(author " -- " (or title url documenturl) " -- " - journal ", " volume "" ("(" number ")") ", " - address ", " month ", " year ", " - ("pp. " pages) ".")) + (bibliography-template author " -- " (or title url documenturl) " -- " + journal ", " volume "" ("(" number ")") ", " + address ", " month ", " year ", " + ("pp. " pages) ".")) ((inproceedings) - `(author " -- " (or title url documenturl) " -- " - booktitle ", " series ", " ("(" number ")") ", " - address ", " month ", " year ", " - ("pp. " pages) ".")) + (bibliography-template author " -- " (or title url documenturl) " -- " + booktitle ", " series ", " ("(" number ")") ", " + address ", " month ", " year ", " + ("pp. " pages) ".")) ((book) - '(author " -- " (or title url documenturl) " -- " - publisher ", " address - ", " month ", " year ", " ("pp. " pages) ".")) + (bibliography-template author " -- " (or title url documenturl) " -- " + publisher ", " address + ", " month ", " year ", " ("pp. " pages) ".")) ((phdthesis) - '(author " -- " (or title url documenturl) " -- " type ", " - school ", " address - ", " month ", " year".")) + (bibliography-template author " -- " (or title url documenturl) " -- " type ", " + school ", " address + ", " month ", " year".")) ((misc) - '(author " -- " (or title url documenturl) " -- " - publisher ", " address - ", " month ", " year".")) + (bibliography-template author " -- " (or title url documenturl) " -- " + publisher ", " address + ", " month ", " year".")) (else - '(author " -- " (or title url documenturl) " -- " - publisher ", " address - ", " month ", " year ", " ("pp. " pages) ".")))) + (bibliography-template author " -- " (or title url documenturl) " -- " + publisher ", " address + ", " month ", " year ", " ("pp. " pages) ".")))) ;;; arch-tag: 5931579f-b606-442d-9a45-6047c94da5a2 diff --git a/src/guile/skribilo/package/jfp.scm b/src/guile/skribilo/package/jfp.scm index 140ff4c..fa6fcc6 100644 --- a/src/guile/skribilo/package/jfp.scm +++ b/src/guile/skribilo/package/jfp.scm @@ -1,7 +1,7 @@ ;;; jfp.scm -- The Skribe style for JFP articles. ;;; ;;; Copyright 2003, 2004 Manuel Serrano -;;; Copyright 2007, 2020 Ludovic Courtès +;;; Copyright 2007, 2020, 2022 Ludovic Courtès ;;; ;;; ;;; This file is part of Skribilo. @@ -26,9 +26,9 @@ #:autoload (skribilo output) (output) #:autoload (skribilo evaluator) (evaluate-document) #:use-module (skribilo lib) - #:autoload (skribilo biblio template) (output-bib-entry-template) + #:use-module (skribilo biblio template) #:autoload (skribilo utils keywords) (the-body) - #:use-module (skribilo package base) + #:use-module ((skribilo package base) #:hide (author)) #:use-module (srfi srfi-1) #:use-module (skribilo utils syntax) @@ -228,37 +228,44 @@ (output-bib-entry-template n e (case (markup-option n 'kind) - ((techreport) - `(author (" (" year ")") " " (or title url) ". " - number ", " institution ", " - address ", " month ", " - ("pp. " pages) ".")) - ((article) - `(author (" (" year ")") " " (or title url) ". " - journal ", " volume ", " ("(" number ")") ", " - address ", " month ", " - ("pp. " pages) ".")) - ((inproceedings) - `(author (" (" year ")") " " (or title url) ". " - book(or title url) ", " series ", " ("(" number ")") ", " - address ", " month ", " - ("pp. " pages) ".")) - ((book) - '(author (" (" year ")") " " (or title url) ". " - publisher ", " address - ", " month ", " ("pp. " pages) ".")) - ((phdthesis) - '(author (" (" year ")") " " (or title url) ". " type ", " - school ", " address - ", " month ".")) - ((misc) - '(author (" (" year ")") " " (or title url) ". " - publisher ", " address - ", " month ".")) - (else - '(author (" (" year ")") " " (or title url) ". " - publisher ", " address - ", " month ", " ("pp. " pages) ".")))))) + ((techreport) + (bibliography-template + author (" (" year ")") " " (or title url) ". " + number ", " institution ", " + address ", " month ", " + ("pp. " pages) ".")) + ((article) + (bibliography-template + author (" (" year ")") " " (or title url) ". " + journal ", " volume ", " ("(" number ")") ", " + address ", " month ", " + ("pp. " pages) ".")) + ((inproceedings) + (bibliography-template + author (" (" year ")") " " (or title url) ". " + booktitle (or title url) ", " series ", " ("(" number ")") ", " + address ", " month ", " + ("pp. " pages) ".")) + ((book) + (bibliography-template + author (" (" year ")") " " (or title url) ". " + publisher ", " address + ", " month ", " ("pp. " pages) ".")) + ((phdthesis) + (bibliography-template + author (" (" year ")") " " (or title url) ". " type ", " + school ", " address + ", " month ".")) + ((misc) + (bibliography-template + author (" (" year ")") " " (or title url) ". " + publisher ", " address + ", " month ".")) + (else + (bibliography-template + author (" (" year ")") " " (or title url) ". " + publisher ", " address + ", " month ", " ("pp. " pages) ".")))))) ;; abstract (markup-writer 'jfp-abstract le :options '(postscript) diff --git a/src/guile/skribilo/package/lncs.scm b/src/guile/skribilo/package/lncs.scm index 2e6bb21..bf6b7cb 100644 --- a/src/guile/skribilo/package/lncs.scm +++ b/src/guile/skribilo/package/lncs.scm @@ -1,7 +1,7 @@ ;;; lncs.scm -- The Skribilo style for LNCS articles. ;;; ;;; Copyright 2003, 2004 Manuel Serrano -;;; Copyright 2007, 2015, 2018, 2020 Ludovic Courtès +;;; Copyright 2007, 2015, 2018, 2020, 2022 Ludovic Courtès ;;; ;;; ;;; This file is part of Skribilo. @@ -24,10 +24,11 @@ #:use-module (skribilo engine) #:use-module (skribilo writer) #:autoload (skribilo output) (output) - #:use-module (skribilo package base) + #:use-module ((skribilo package base) #:hide (author)) #:autoload (skribilo utils keywords) (the-options the-body) - #:autoload (skribilo biblio template)(output-bib-entry-template - make-bib-entry-template/default) + #:use-module ((skribilo biblio template) #:hide (chapter)) + #:use-module ((skribilo biblio template) + #:select ((chapter . biblio:chapter))) #:autoload (skribilo biblio author) (bib-sort/first-author-last-name abbreviate-author-first-names/family-first abbreviate-first-names) @@ -211,64 +212,64 @@ ;; Return the LNCS bibliography entry template for KIND. (case kind ((techreport) - `(author ": " (or title url documenturl) ". " - ;; TRANSLATORS: The next few msgids are fragments of - ;; bibliography items. - ,(G_ "Technical Report") " " number - (", " institution) - (", " address) - (", " pages) - (" (" year ")"))) + (bibliography-template author ": " (or title url documenturl) ". " + ;; TRANSLATORS: The next few msgids are fragments + ;; of bibliography items. + (G_ "Technical Report") " " number + (", " institution) + (", " address) + (", " pages) + (" (" year ")"))) ((article) - `(author ": " (or title url documenturl) ". " - ,(G_ "In: ") journal ", " volume - ("(" number ")") ", " - (address ", ") - ("pp. " pages) (" (" year ")"))) + (bibliography-template author ": " (or title url documenturl) ". " + (G_ "In: ") journal ", " volume + ("(" number ")") ", " + (address ", ") + ("pp. " pages) (" (" year ")"))) ((inproceedings) - '(author ": " (or title url documenturl) ". " - ,(G_ "In: ") booktitle ", " - (series) - ("(" number "), ") - (publisher ", ") - ("pp. " pages) - (" (" year ")"))) + (bibliography-template author ": " (or title url documenturl) ". " + (G_ "In: ") booktitle ", " + (series) + ("(" number "), ") + (publisher ", ") + ("pp. " pages) + (" (" year ")"))) ((book) - '((or author editor) ": " - (or title url documenturl) ". " - publisher - (", " address) - (", " month) - ", " year - (", pp. " pages))) + (bibliography-template (or author editor) ": " + (or title url documenturl) ". " + publisher + (", " address) + (", " month) + ", " year + (", pp. " pages))) ((inbook) - `(author ": " (or title url documenturl) ". " - ,(G_ "In: ") booktitle ", " publisher - (", " editor " (" ,(G_ "editor") ")") - (", " ,(G_ "Chapter ") chapter) - (", pp. " pages) - (" (" year ")"))) + (bibliography-template author ": " (or title url documenturl) ". " + (G_ "In: ") booktitle ", " publisher + (", " editor " (" (G_ "editor") ")") + (", " (G_ "Chapter ") biblio:chapter) + (", pp. " pages) + (" (" year ")"))) ((phdthesis) - `(author ": " (or title url documenturl) - ", " ,(G_ "PhD Thesis") - (", " (or school institution)) - (", " address) - (", " month) - (if month " " ", ") year)) + (bibliography-template author ": " (or title url documenturl) + ", " (G_ "PhD Thesis") + (", " (or school institution)) + (", " address) + (", " month) + (if month " " ", ") year)) ((misc) - '(author ": " (or title url documenturl) ". " - (institution ", ") - (publisher ", ") - (address ", ") - (month " ") ("(" year ")") - (" " url))) + (bibliography-template author ": " (or title url documenturl) ". " + (institution ", ") + (publisher ", ") + (address ", ") + (month " ") ("(" year ")") + (" " url))) (else - '(author ": " (or title url documenturl) ". " - (publisher ", ") - (address ", ") - (month " ") - (", pp. " pages) - (" (" year ")"))))) + (bibliography-template author ": " (or title url documenturl) ". " + (publisher ", ") + (address ", ") + (month " ") + (", pp. " pages) + (" (" year ")"))))) ;;; diff --git a/tests/Makefile.am b/tests/Makefile.am index 8ba7637..a423234 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -11,6 +11,7 @@ TEST_LOG_DRIVER = \ TESTS = \ ast.test \ + biblio.test \ resolve.test \ engines/info.test \ location.test diff --git a/tests/biblio.test b/tests/biblio.test new file mode 100644 index 0000000..954d964 --- /dev/null +++ b/tests/biblio.test @@ -0,0 +1,88 @@ +;;; Exercise the `biblio' routines. -*- Scheme -*- +;;; +;;; Copyright (C) 2022 Ludovic Courtès +;;; +;;; This file is part of Skribilo. +;;; +;;; Skribilo is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU Lesser General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; Skribilo is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU Lesser General Public License +;;; along with this program. If not, see . + +(define-module (tests biblio) + #:use-module ((skribilo reader) #:select (*document-reader*)) + #:use-module (skribilo ast) + #:use-module (skribilo biblio) + #:use-module (skribilo biblio template) + #:use-module (srfi srfi-64)) + +(define sbib + '(article + scheme:r5rs + (title "The Revised5 Report on the Algorithmic Language Scheme") + (author "Richard Kelsey, William D. Clinger, Jonathan Rees") + (journal "Higher-Order and Symbolic Computation") + (volume "11") + (number "1") + (month "Sep") + (year "1998") + (url "http://kaolin.unice.fr/Bigloo/doc/r5rs.html"))) + +(define table + (make-bib-table 'table)) + + +(test-begin "biblio") + +(test-equal "parse-bib" + "The Revised5 Report on the Algorithmic Language Scheme" + (begin + (call-with-input-string (object->string sbib) + (lambda (port) + (parameterize ((*document-reader* read)) + (parse-bib table port)))) + (and (bib-table? table) + (let ((entry (resolve-bib table 'scheme:r5rs))) + (and (is-markup? entry '&bib-entry) + (markup-body (markup-option entry 'title))))))) + +(test-equal "bibliography-template, simple" + (let ((entry (resolve-bib table 'scheme:r5rs))) + (list "A: " (markup-option entry 'author) + "T: " (markup-option entry 'title) + "Y: " (markup-option entry 'year))) + (let ((template (bibliography-template "A: " author + "T: " title + "Y: " year))) + (template (resolve-bib table 'scheme:r5rs)))) + +(test-equal "bibliography-template, conditionals" + (let ((entry (resolve-bib table 'scheme:r5rs))) + (list "A: " (markup-option entry 'author) + "T: " (markup-option entry 'title) + "Y: " (list (markup-option entry 'year)) + "B: " '("no"))) + (let ((template (bibliography-template "A: " (or editor author) + "T: " (or booktitle title) + "Y: " (if year year "N") + "B: " (if booktitle "yes" "no")))) + (template (resolve-bib table 'scheme:r5rs)))) + +(test-equal "bibliography-template, tricky things" + (let ((entry (resolve-bib table 'scheme:r5rs))) + (list "A: " (markup-option entry 'author) + "Y: " (markup-option entry 'year) "!")) + (let ((template (bibliography-template ("A: " author) + ("T: " booktitle "+" title) + ("Y: " year "!")))) + (template (resolve-bib table 'scheme:r5rs)))) + +(test-end "biblio") base-commit: 3746030f437db70c8ede10f7f063fac2a8d51248 -- 2.35.1 From unknown Sat Jun 21 12:12:26 2025 X-Loop: help-debbugs@gnu.org Subject: bug#55035: [PATCH] biblio: Replace template interpreter with a macro (a "compiler"). Resent-From: Arun Isaac Original-Sender: "Debbugs-submit" Resent-CC: skribilo-bugs@nongnu.org Resent-Date: Fri, 22 Apr 2022 09:01:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55035 X-GNU-PR-Package: skribilo X-GNU-PR-Keywords: patch To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 55035@debbugs.gnu.org Received: via spool by 55035-submit@debbugs.gnu.org id=B55035.16506180401125 (code B ref 55035); Fri, 22 Apr 2022 09:01:02 +0000 Received: (at 55035) by debbugs.gnu.org; 22 Apr 2022 09:00:40 +0000 Received: from localhost ([127.0.0.1]:51475 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nhp9c-0000I4-8O for submit@debbugs.gnu.org; Fri, 22 Apr 2022 05:00:40 -0400 Received: from mugam.systemreboot.net ([139.59.75.54]:36272) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nhp9Z-0000Hv-9d for 55035@debbugs.gnu.org; Fri, 22 Apr 2022 05:00:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=systemreboot.net; s=default; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Message-ID:Date:References:In-Reply-To:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=hCD2K2QFgx9ZpGeptXzyewGDjdN/xCTjS9j3h10s+uk=; b=gZ6//a7BXWiUaSO9jsHxs3sK5I EDYizLEMNJAuPl6onuxYJjtiZct1x7DiMp3iURhiqkXL9p1BKIxXkEdkPUhaxNsw1+vqdDfRoDlDh EiukDJq970coeapTton/CylydJ8C4r9bdHyKxDEPuxBeFzjA1nKx8cDEJvvNrwwoUTH2nK8sIOcs/ pKgYQD4mVmi99Me7dJxXBFOtRKxFtOwqJ2md4PoW497v3FvqtUJMKbiLUQwgROgvaXjcEkx18UHUu ZHS8qPsKui/VgfWpQe5R/HHeAdYaf48For5IEHDzJxz8+hFlTvyMqiTzM8ooJp7RJlwA11d6/tixc swuG93xQ==; Received: from [192.168.2.1] (port=5534 helo=steel) by systemreboot.net with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1nhp9W-0002uS-Fb; Fri, 22 Apr 2022 14:30:34 +0530 From: Arun Isaac In-Reply-To: <20220420101325.19577-1-ludo@gnu.org> References: <20220420101325.19577-1-ludo@gnu.org> Date: Fri, 22 Apr 2022 14:30:33 +0530 Message-ID: <87a6cd8pce.fsf@systemreboot.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hi Ludo, > This allows us to catch invalid templates at macro-expansion time and is > more efficient. I have never had occasion to use the skribilo bibliography system, and I haven't actually tested this patch, but it looks neat! I only have cosmetic and nitpicky changes to suggest. > diff --git a/src/guile/skribilo/biblio.scm > b/src/guile/skribilo/biblio.scm This file only has deletions. But maybe, update copyright header in this file as well? It would be nice if we had automated tests for unupdated copyright headers. > + (define-syntax instantiate-body > + (lambda (s) > + (define (literal? id) > + (any (lambda (l) > + (and (identifier? id) > + (free-identifier=3D? id l))) We should avoid single letter names like `l'. :-) > + (syntax-case s (literal ... or if G_) > + ((_ n str rest (... ...)) And `n'. > diff --git a/tests/biblio.test b/tests/biblio.test > new file mode 100644 > index 0000000..954d964 > --- /dev/null > +++ b/tests/biblio.test > @@ -0,0 +1,88 @@ > +;;; Exercise the `biblio' routines. -*- Scheme -*- > +;;; > +;;; Copyright (C) 2022 Ludovic Court=C3=A8s We should switch to the unicode copyright symbol =C2=A9, at least in new files. > +(test-equal "bibliography-template, simple" The comma is slightly confusing. I'd go with "bibliography-template: simple" or "simple bibliography-template". > +(test-equal "bibliography-template, conditionals" Likewise. > +(test-equal "bibliography-template, tricky things" Likewise. Thanks! :-) Arun From unknown Sat Jun 21 12:12:26 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Subject: bug#55035: closed (Re: bug#55035: [PATCH] biblio: Replace template interpreter with a macro (a "compiler").) Message-ID: References: <877d6z7m8t.fsf@gnu.org> <20220420101325.19577-1-ludo@gnu.org> X-Gnu-PR-Message: they-closed 55035 X-Gnu-PR-Package: skribilo X-Gnu-PR-Keywords: patch Reply-To: 55035@debbugs.gnu.org Date: Thu, 05 May 2022 20:34:03 +0000 Content-Type: multipart/mixed; boundary="----------=_1651782843-28711-1" This is a multi-part message in MIME format... ------------=_1651782843-28711-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #55035: [PATCH] biblio: Replace template interpreter with a macro (a "compi= ler"). which was filed against the skribilo package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 55035@debbugs.gnu.org. --=20 55035: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D55035 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1651782843-28711-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 55035-done) by debbugs.gnu.org; 5 May 2022 20:33:48 +0000 Received: from localhost ([127.0.0.1]:46566 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nmiAW-0007SJ-F4 for submit@debbugs.gnu.org; Thu, 05 May 2022 16:33:48 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48804) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nmiAV-0007S6-9r for 55035-done@debbugs.gnu.org; Thu, 05 May 2022 16:33:47 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:59900) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmiAO-0001sT-Rn; Thu, 05 May 2022 16:33:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=VbOcjQ5OFGQGXvYmvPK+lzC6qn3AhLqX1SOqfVZP/vQ=; b=ZiJ8fLV0sekg7S2HWeGc +k/4q0ElqFRdOLeGzC5tK9wAC0G1KEuWBFd/YuTvdD2cdJ3tzW/MjhetA210v+LqdrlrgUxV43uuy fZ2hShbYXOAQuiVdieTfBq6DOo7yEAxmG2HsfpIXz59fqZVWEHIHATcMRyvAkt0ib0aGMK06LxWcX dHf5xdwVu6Axf/d4fGVbMEcHb2GK9+YoaxJ2xuTu9TnOdQ75xKo78tRd7CoMplurRk2usb2p6xavj wMCjX1M1zcBrqHyNqnENxUsOL1/FI72rmV0VoL6ydubgI2Hy7x5m9VelrRSIxL8ZAVVCPRyAHxqAB /DFhj1x4w5rc+Q==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:64097 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmiAO-0003ET-FT; Thu, 05 May 2022 16:33:40 -0400 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Arun Isaac Subject: Re: bug#55035: [PATCH] biblio: Replace template interpreter with a macro (a "compiler"). References: <20220420101325.19577-1-ludo@gnu.org> <87a6cd8pce.fsf@systemreboot.net> Date: Thu, 05 May 2022 22:33:38 +0200 In-Reply-To: <87a6cd8pce.fsf@systemreboot.net> (Arun Isaac's message of "Fri, 22 Apr 2022 14:30:33 +0530") Message-ID: <877d6z7m8t.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 55035-done Cc: 55035-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hi Arun! Arun Isaac skribis: >> diff --git a/src/guile/skribilo/biblio.scm >> b/src/guile/skribilo/biblio.scm > > This file only has deletions. But maybe, update copyright header in this > file as well? It would be nice if we had automated tests for unupdated > copyright headers. Ah, good question. I=E2=80=99d lean towards leaving copyright lines unchan= ged when removing text, but I don=E2=80=99t know if there=E2=80=99s a preferred= way. >> + (define-syntax instantiate-body >> + (lambda (s) >> + (define (literal? id) >> + (any (lambda (l) >> + (and (identifier? id) >> + (free-identifier=3D? id l))) > > We should avoid single letter names like `l'. :-) I this particular case, the spelled-out name would be =E2=80=98literal=E2= =80=99, but we can=E2=80=99t use it because it=E2=80=99s a pattern variable. So=E2=80=A6 = an exception. :-) >> + (syntax-case s (literal ... or if G_) >> + ((_ n str rest (... ...)) > > And `n'. This one yes; fixed! >> diff --git a/tests/biblio.test b/tests/biblio.test >> new file mode 100644 >> index 0000000..954d964 >> --- /dev/null >> +++ b/tests/biblio.test >> @@ -0,0 +1,88 @@ >> +;;; Exercise the `biblio' routines. -*- Scheme -*- >> +;;; >> +;;; Copyright (C) 2022 Ludovic Court=C3=A8s > > We should switch to the unicode copyright symbol =C2=A9, at least in new > files. Probably we should rewrite en bloc with a sed script. We first need to reencode as UTF-8 and leftover Latin-1 files. >> +(test-equal "bibliography-template, simple" > > The comma is slightly confusing. I'd go with "bibliography-template: > simple" or "simple bibliography-template". Done. Pushed as 424bef0d0aac2a5a8607cf9f76a6def5ee0ca183! Thanks, :-) Ludo=E2=80=99. ------------=_1651782843-28711-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 20 Apr 2022 10:13:41 +0000 Received: from localhost ([127.0.0.1]:45126 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nh7L8-00085q-Aw for submit@debbugs.gnu.org; Wed, 20 Apr 2022 06:13:41 -0400 Received: from lists.gnu.org ([209.51.188.17]:51844) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nh7L6-00085g-D5 for submit@debbugs.gnu.org; Wed, 20 Apr 2022 06:13:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55392) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nh7L6-0007E0-5b for skribilo-bugs@nongnu.org; Wed, 20 Apr 2022 06:13:36 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:59876) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nh7L5-0003cY-6C; Wed, 20 Apr 2022 06:13:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=FigNWw3CdRscmw+hF468HIjmkYUyhynwK1TsAHEGbSM=; b=VjB0J7NQ1tk62q RvYqaV9qRVqQzDjeE2Y8eMf915SblH/JxRxRpX+9oLsWmuDb58zSyKpRgdVUjfTiv0hgW/FrD/WKc 2vS9cqq7/yKKivC1D/PfPBpZbo2unydaQpHPPuZ+VryMepyQcrU3ChbW/PAps5DPgVDCn4Y8wisRk 4K1FvlflteeEftkbvqz8FLtYCIJv5irAV9Wo+/mzSQBZuYUeQGtHpR7zqs1sfyqgrz6Li71TGHNW3 1CnWQYnPkgyDCWGW8EoYGQCsZYPzpmenf1ov0tqYNMjM07N84QRU4T3UA9g0cRBzGxhBOUaDl4971 qoyEwQ2d/Qaty4k5PQaQ==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:63454 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nh7L4-0008ET-E3; Wed, 20 Apr 2022 06:13:34 -0400 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= To: skribilo-bugs@nongnu.org Subject: [PATCH] biblio: Replace template interpreter with a macro (a "compiler"). Date: Wed, 20 Apr 2022 12:13:25 +0200 Message-Id: <20220420101325.19577-1-ludo@gnu.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: submit Cc: =?UTF-8?q?Ludovic=20Court=C3=A8s?= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) This allows us to catch invalid templates at macro-expansion time and is more efficient. * src/guile/skribilo/biblio/template.scm (evaluate-bib-entry-template): Remove. (define-template-engine, bibliography-template): New macros. (output-bib-entry-template): Rewrite and remove 'get-field' optional argument. (make-bib-entry-template/default, make-bib-entry-template/skribe): Use 'bibliography-template' instead of quasiquote/unquote. * src/guile/skribilo/package/jfp.scm (le): Likewise. * src/guile/skribilo/package/lncs.scm (bib-entry-template): Likewise. * src/guile/skribilo/biblio.scm (&biblio-template-error): Remove. (handle-biblio-error): Adjust accordingly. * tests/biblio.test: New file. * tests/Makefile.am (TESTS): Add it. --- src/guile/skribilo/biblio.scm | 16 +- src/guile/skribilo/biblio/template.scm | 304 ++++++++++++------------- src/guile/skribilo/package/jfp.scm | 75 +++--- src/guile/skribilo/package/lncs.scm | 111 ++++----- tests/Makefile.am | 1 + tests/biblio.test | 88 +++++++ 6 files changed, 336 insertions(+), 259 deletions(-) create mode 100644 tests/biblio.test diff --git a/src/guile/skribilo/biblio.scm b/src/guile/skribilo/biblio.scm index 9d83cde..7d95d51 100644 --- a/src/guile/skribilo/biblio.scm +++ b/src/guile/skribilo/biblio.scm @@ -55,13 +55,11 @@ bib-sort-refs/number ;; error conditions - &biblio-error &biblio-entry-error &biblio-template-error + &biblio-error &biblio-entry-error &biblio-parse-error - biblio-error? biblio-entry-error? biblio-template-error? + biblio-error? biblio-entry-error? biblio-parse-error? biblio-entry-error:entry - biblio-template-error:expression - biblio-template-error:template biblio-parse-error:sexp)) ;;; Commentary: @@ -86,11 +84,6 @@ biblio-entry-error? (entry biblio-entry-error:entry)) -(define-condition-type &biblio-template-error &biblio-error - biblio-template-error? - (expression biblio-template-error:expression) - (template biblio-template-error:template)) - (define-condition-type &biblio-parse-error &biblio-error biblio-parse-error? (sexp biblio-parse-error:sexp)) @@ -110,11 +103,6 @@ (format (current-error-port) (G_ "invalid bibliography entry: ~a~%") entry)))) - ((biblio-template-error? c) - (format (current-error-port) - (G_ "invalid bibliography entry template: '~a', in '~a'~%") - (biblio-template-error:expression c) - (biblio-template-error:template c))) ((biblio-parse-error? c) (format (current-error-port) (G_ "invalid bibliography entry s-exp: '~a'~%") diff --git a/src/guile/skribilo/biblio/template.scm b/src/guile/skribilo/biblio/template.scm index 96ac4e3..aefb20d 100644 --- a/src/guile/skribilo/biblio/template.scm +++ b/src/guile/skribilo/biblio/template.scm @@ -1,7 +1,7 @@ ;;; template.scm -- Template system for bibliography entries. ;;; ;;; Copyright 2003, 2004 Manuel Serrano -;;; Copyright 2006, 2007, 2015, 2018 Ludovic Courtès +;;; Copyright 2006, 2007, 2015, 2018, 2022 Ludovic Courtès ;;; ;;; ;;; This file is part of Skribilo. @@ -32,14 +32,14 @@ #:use-module (skribilo utils syntax) - #:export (evaluate-bib-entry-template - output-bib-entry-template - make-bib-entry-template/default - make-bib-entry-template/skribe)) + #:export (bibliography-template + output-bib-entry-template + make-bib-entry-template/default + make-bib-entry-template/skribe)) (skribilo-module-syntax) -;;; Author: Manuel Serrano, Ludovic Courtès +;;; Author: Manuel Serrano, Ludovic Courtès ;;; ;;; Commentary: ;;; @@ -57,85 +57,77 @@ ;;; Outputting a bibliography entry template for a specific entry. ;;; -(define (evaluate-bib-entry-template bib template . rest) - ;; An interpreter for the bibliography template language. Overview of the - ;; language: - ;; - ;; form := (cond-list|special-sexp|string|field-spec) - ;; - ;; field-spec := ("author"|"title"|...) - ;; cond-list := (form+) - ;; special-sexp := (("if" form form form?)|("or" form*)) - ;; - ;; A `cond-list' gets issued only if all its elements are true. - - (define get-field - (if (null? rest) - markup-option - (car rest))) - - (define (eval-cond-list sexp eval-sexp) - (let loop ((sexp sexp) - (result '())) - (if (null? sexp) - (reverse! result) - (let ((head (eval-sexp (car sexp)))) - (if (not head) - #f - (loop (cdr sexp) - (cons head result))))))) - - (define (eval-special-sexp sexp eval-sexp) - (let ((special (car sexp)) - (formals (cdr sexp))) - (case special - ((or) - (any eval-sexp formals)) - ((if) - (if (or (> (length formals) 3) - (< (length formals) 2)) - (raise (condition - (&biblio-template-error (expression sexp) - (template template))))) - (let* ((if-cond (car formals)) - (if-then (cadr formals)) - (if-else (if (null? (cddr formals)) - #f - (caddr formals))) - (result (eval-sexp if-cond))) - (if result - (eval-sexp if-then) - (eval-sexp if-else)))) - (else - (eval-cond-list sexp eval-sexp))))) - - (let loop ((template template)) - (cond ((symbol? template) - (get-field bib template)) - ((null? template) - #f) - ((pair? template) - (cond ((symbol? (car template)) - (eval-special-sexp template loop)) - (else - (eval-cond-list template loop)))) - ((string? template) - template) - (else - (raise (condition - (&biblio-template-error (expression template) - (template template)))))))) - - -(define* (output-bib-entry-template bib engine template - :optional (get-field markup-option)) +(define-syntax-rule (define-template-engine instantiate literal ...) + "Define INSTANTIATE as a macro that, given a template, produces a +one-argument procedure to instantiate that template given a '&bib-entry' +node. LITERAL... is the list of literals, the name of valid markup options." + (begin + (define-public literal + (lambda (s) + (syntax-violation 'literal + "template literal used outside of 'bibliography-template'" + s))) + ... + + (define-syntax instantiate-body + (lambda (s) + (define (literal? id) + (any (lambda (l) + (and (identifier? id) + (free-identifier=? id l))) + #'(literal ...))) + + (syntax-case s (literal ... or if G_) + ((_ n str rest (... ...)) + (string? (syntax->datum #'str)) + #'(cons str (instantiate-body n rest (... ...)))) + ((_ n (G_ str) rest (... ...)) + (string? (syntax->datum #'str)) + #'(cons (G_ str) (instantiate-body n rest (... ...)))) + ((_ n (or options (... ...)) rest (... ...)) + (every literal? #'(options (... ...))) + #'(cons (or (markup-option n 'options) (... ...)) + (instantiate-body n rest (... ...)))) + ((_ n (if cond a b) rest (... ...)) + (literal? #'cond) + #'(cons (if (markup-option n 'cond) + (instantiate-body n a) + (instantiate-body n b)) + (instantiate-body n rest (... ...)))) + ((_ n (lst (... ...)) rest (... ...)) + #'(append (let ((body (instantiate-body n lst (... ...)))) + (if (every ->bool body) + body + '())) + (instantiate-body n rest (... ...)))) + ((_ n literal rest (... ...)) + #'(cons (markup-option n 'literal) + (instantiate-body n rest (... ...)))) + ... + ((_ n) + #''())))) + + (define-syntax-rule (instantiate body (... ...)) + (lambda (n) + (instantiate-body n body (... ...)))))) + +;; Define 'bibliography-template' as a macro that builds a procedure to +;; instantiate a template from a '&bib-entry' node. +(define-template-engine bibliography-template + + ;; Keywords that may appear in the template. + author title url documenturl type + journal number volume series booktitle editor + school institution address + month year day + pages chapter publisher) + + +(define* (output-bib-entry-template bib engine template) ;; Output the fields of BIB (a bibliography entry) for ENGINE according to ;; TEMPLATE. Example of templates are found below (e.g., ;; `make-bib-entry-template/default'). - (output (map (lambda (form) - (evaluate-bib-entry-template bib form get-field)) - template) - engine)) + (output (template bib) engine)) ;;; @@ -147,98 +139,98 @@ (case kind ((techreport) - `(author ". " (or title url documenturl) ". " - ;; TRANSLATORS: The next few msgids are fragments of - ;; bibliography items. - ,(G_ "Technical Report") " " number - (", " institution) - (", " address) - (", " month) " " year - (", pp. " pages) ".")) + (bibliography-template author ". " (or title url documenturl) ". " + ;; TRANSLATORS: The next few msgids are fragments of + ;; bibliography items. + (G_ "Technical Report") " " number + (", " institution) + (", " address) + (", " month) " " year + (", pp. " pages) ".")) ((article) - `(author ". " (or title url documenturl) ". " - ,(G_ "In ") journal ", " volume - ("(" number ") ")", " - (address ", ") month " " year ", " - ("pp. " pages) ".")) + (bibliography-template author ". " (or title url documenturl) ". " + (G_ "In ") journal ", " volume + ("(" number ") ")", " + (address ", ") month " " year ", " + ("pp. " pages) ".")) ((inproceedings) - `(author ". " (or title url documenturl) ". " - ,(G_ "In ") booktitle ", " - (series ", ") - ("(" number ")") - ("pp. " pages ", ") - (publisher ", ") - (month " ") year ".")) + (bibliography-template author ". " (or title url documenturl) ". " + (G_ "In ") booktitle ", " + (series ", ") + ("(" number ")") + ("pp. " pages ", ") + (publisher ", ") + (month " ") year ".")) ((book) ;; FIXME: Title should be in italics - '((or author editor) - ". " (or title url documenturl) ". " - publisher - (", " address) - (", " month) - ", " year - (", pp. " pages) ".")) + (bibliography-template (or author editor) + ". " (or title url documenturl) ". " + publisher + (", " address) + (", " month) + ", " year + (", pp. " pages) ".")) ((inbook) - `(author ". " (or title url documenturl) ". " - ,(G_ "In ") booktitle ", " publisher - (", " editor " (" ,(G_ "editor") ")") - (", " ,(G_ "Chapter ") chapter) - (", pp. " pages) ", " - (month " ") year ".")) + (bibliography-template author ". " (or title url documenturl) ". " + (G_ "In ") booktitle ", " publisher + (", " editor " (" (G_ "editor") ")") + (", " (G_ "Chapter ") chapter) + (", pp. " pages) ", " + (month " ") year ".")) ((phdthesis) - `(author ". " (or title url documenturl) - ", " ,(G_ "PhD Thesis") - (", " (or school institution)) - (", " address) - (", " month) - (if month " " ", ") year ".")) + (bibliography-template author ". " (or title url documenturl) + ", " (G_ "PhD Thesis") + (", " (or school institution)) + (", " address) + (", " month) + (if month " " ", ") year ".")) ((misc) - '(author ". " (or title url documenturl) ". " - (institution ", ") - (publisher ", ") - (address ", ") - (month " ") year ". " - (url "."))) + (bibliography-template author ". " (or title url documenturl) ". " + (institution ", ") + (publisher ", ") + (address ", ") + (month " ") year ". " + (url "."))) (else - '(author ". " (or title url documenturl) ". " - (publisher ", ") - (address ", ") - (month " ") year ", " - ("pp. " pages) ".")))) + (bibliography-template author ". " (or title url documenturl) ". " + (publisher ", ") + (address ", ") + (month " ") year ", " + ("pp. " pages) ".")))) (define (make-bib-entry-template/skribe kind) ;; The awful template found by default in Skribe. (case kind ((techreport) - `(author " -- " (or title url documenturl) " -- " - ,(G_ "Technical Report") " " number ", " institution ", " - address ", " month ", " year ", " - ("pp. " pages) ".")) + (bibliography-template author " -- " (or title url documenturl) " -- " + (G_ "Technical Report") " " number ", " institution ", " + address ", " month ", " year ", " + ("pp. " pages) ".")) ((article) - `(author " -- " (or title url documenturl) " -- " - journal ", " volume "" ("(" number ")") ", " - address ", " month ", " year ", " - ("pp. " pages) ".")) + (bibliography-template author " -- " (or title url documenturl) " -- " + journal ", " volume "" ("(" number ")") ", " + address ", " month ", " year ", " + ("pp. " pages) ".")) ((inproceedings) - `(author " -- " (or title url documenturl) " -- " - booktitle ", " series ", " ("(" number ")") ", " - address ", " month ", " year ", " - ("pp. " pages) ".")) + (bibliography-template author " -- " (or title url documenturl) " -- " + booktitle ", " series ", " ("(" number ")") ", " + address ", " month ", " year ", " + ("pp. " pages) ".")) ((book) - '(author " -- " (or title url documenturl) " -- " - publisher ", " address - ", " month ", " year ", " ("pp. " pages) ".")) + (bibliography-template author " -- " (or title url documenturl) " -- " + publisher ", " address + ", " month ", " year ", " ("pp. " pages) ".")) ((phdthesis) - '(author " -- " (or title url documenturl) " -- " type ", " - school ", " address - ", " month ", " year".")) + (bibliography-template author " -- " (or title url documenturl) " -- " type ", " + school ", " address + ", " month ", " year".")) ((misc) - '(author " -- " (or title url documenturl) " -- " - publisher ", " address - ", " month ", " year".")) + (bibliography-template author " -- " (or title url documenturl) " -- " + publisher ", " address + ", " month ", " year".")) (else - '(author " -- " (or title url documenturl) " -- " - publisher ", " address - ", " month ", " year ", " ("pp. " pages) ".")))) + (bibliography-template author " -- " (or title url documenturl) " -- " + publisher ", " address + ", " month ", " year ", " ("pp. " pages) ".")))) ;;; arch-tag: 5931579f-b606-442d-9a45-6047c94da5a2 diff --git a/src/guile/skribilo/package/jfp.scm b/src/guile/skribilo/package/jfp.scm index 140ff4c..fa6fcc6 100644 --- a/src/guile/skribilo/package/jfp.scm +++ b/src/guile/skribilo/package/jfp.scm @@ -1,7 +1,7 @@ ;;; jfp.scm -- The Skribe style for JFP articles. ;;; ;;; Copyright 2003, 2004 Manuel Serrano -;;; Copyright 2007, 2020 Ludovic Courtès +;;; Copyright 2007, 2020, 2022 Ludovic Courtès ;;; ;;; ;;; This file is part of Skribilo. @@ -26,9 +26,9 @@ #:autoload (skribilo output) (output) #:autoload (skribilo evaluator) (evaluate-document) #:use-module (skribilo lib) - #:autoload (skribilo biblio template) (output-bib-entry-template) + #:use-module (skribilo biblio template) #:autoload (skribilo utils keywords) (the-body) - #:use-module (skribilo package base) + #:use-module ((skribilo package base) #:hide (author)) #:use-module (srfi srfi-1) #:use-module (skribilo utils syntax) @@ -228,37 +228,44 @@ (output-bib-entry-template n e (case (markup-option n 'kind) - ((techreport) - `(author (" (" year ")") " " (or title url) ". " - number ", " institution ", " - address ", " month ", " - ("pp. " pages) ".")) - ((article) - `(author (" (" year ")") " " (or title url) ". " - journal ", " volume ", " ("(" number ")") ", " - address ", " month ", " - ("pp. " pages) ".")) - ((inproceedings) - `(author (" (" year ")") " " (or title url) ". " - book(or title url) ", " series ", " ("(" number ")") ", " - address ", " month ", " - ("pp. " pages) ".")) - ((book) - '(author (" (" year ")") " " (or title url) ". " - publisher ", " address - ", " month ", " ("pp. " pages) ".")) - ((phdthesis) - '(author (" (" year ")") " " (or title url) ". " type ", " - school ", " address - ", " month ".")) - ((misc) - '(author (" (" year ")") " " (or title url) ". " - publisher ", " address - ", " month ".")) - (else - '(author (" (" year ")") " " (or title url) ". " - publisher ", " address - ", " month ", " ("pp. " pages) ".")))))) + ((techreport) + (bibliography-template + author (" (" year ")") " " (or title url) ". " + number ", " institution ", " + address ", " month ", " + ("pp. " pages) ".")) + ((article) + (bibliography-template + author (" (" year ")") " " (or title url) ". " + journal ", " volume ", " ("(" number ")") ", " + address ", " month ", " + ("pp. " pages) ".")) + ((inproceedings) + (bibliography-template + author (" (" year ")") " " (or title url) ". " + booktitle (or title url) ", " series ", " ("(" number ")") ", " + address ", " month ", " + ("pp. " pages) ".")) + ((book) + (bibliography-template + author (" (" year ")") " " (or title url) ". " + publisher ", " address + ", " month ", " ("pp. " pages) ".")) + ((phdthesis) + (bibliography-template + author (" (" year ")") " " (or title url) ". " type ", " + school ", " address + ", " month ".")) + ((misc) + (bibliography-template + author (" (" year ")") " " (or title url) ". " + publisher ", " address + ", " month ".")) + (else + (bibliography-template + author (" (" year ")") " " (or title url) ". " + publisher ", " address + ", " month ", " ("pp. " pages) ".")))))) ;; abstract (markup-writer 'jfp-abstract le :options '(postscript) diff --git a/src/guile/skribilo/package/lncs.scm b/src/guile/skribilo/package/lncs.scm index 2e6bb21..bf6b7cb 100644 --- a/src/guile/skribilo/package/lncs.scm +++ b/src/guile/skribilo/package/lncs.scm @@ -1,7 +1,7 @@ ;;; lncs.scm -- The Skribilo style for LNCS articles. ;;; ;;; Copyright 2003, 2004 Manuel Serrano -;;; Copyright 2007, 2015, 2018, 2020 Ludovic Courtès +;;; Copyright 2007, 2015, 2018, 2020, 2022 Ludovic Courtès ;;; ;;; ;;; This file is part of Skribilo. @@ -24,10 +24,11 @@ #:use-module (skribilo engine) #:use-module (skribilo writer) #:autoload (skribilo output) (output) - #:use-module (skribilo package base) + #:use-module ((skribilo package base) #:hide (author)) #:autoload (skribilo utils keywords) (the-options the-body) - #:autoload (skribilo biblio template)(output-bib-entry-template - make-bib-entry-template/default) + #:use-module ((skribilo biblio template) #:hide (chapter)) + #:use-module ((skribilo biblio template) + #:select ((chapter . biblio:chapter))) #:autoload (skribilo biblio author) (bib-sort/first-author-last-name abbreviate-author-first-names/family-first abbreviate-first-names) @@ -211,64 +212,64 @@ ;; Return the LNCS bibliography entry template for KIND. (case kind ((techreport) - `(author ": " (or title url documenturl) ". " - ;; TRANSLATORS: The next few msgids are fragments of - ;; bibliography items. - ,(G_ "Technical Report") " " number - (", " institution) - (", " address) - (", " pages) - (" (" year ")"))) + (bibliography-template author ": " (or title url documenturl) ". " + ;; TRANSLATORS: The next few msgids are fragments + ;; of bibliography items. + (G_ "Technical Report") " " number + (", " institution) + (", " address) + (", " pages) + (" (" year ")"))) ((article) - `(author ": " (or title url documenturl) ". " - ,(G_ "In: ") journal ", " volume - ("(" number ")") ", " - (address ", ") - ("pp. " pages) (" (" year ")"))) + (bibliography-template author ": " (or title url documenturl) ". " + (G_ "In: ") journal ", " volume + ("(" number ")") ", " + (address ", ") + ("pp. " pages) (" (" year ")"))) ((inproceedings) - '(author ": " (or title url documenturl) ". " - ,(G_ "In: ") booktitle ", " - (series) - ("(" number "), ") - (publisher ", ") - ("pp. " pages) - (" (" year ")"))) + (bibliography-template author ": " (or title url documenturl) ". " + (G_ "In: ") booktitle ", " + (series) + ("(" number "), ") + (publisher ", ") + ("pp. " pages) + (" (" year ")"))) ((book) - '((or author editor) ": " - (or title url documenturl) ". " - publisher - (", " address) - (", " month) - ", " year - (", pp. " pages))) + (bibliography-template (or author editor) ": " + (or title url documenturl) ". " + publisher + (", " address) + (", " month) + ", " year + (", pp. " pages))) ((inbook) - `(author ": " (or title url documenturl) ". " - ,(G_ "In: ") booktitle ", " publisher - (", " editor " (" ,(G_ "editor") ")") - (", " ,(G_ "Chapter ") chapter) - (", pp. " pages) - (" (" year ")"))) + (bibliography-template author ": " (or title url documenturl) ". " + (G_ "In: ") booktitle ", " publisher + (", " editor " (" (G_ "editor") ")") + (", " (G_ "Chapter ") biblio:chapter) + (", pp. " pages) + (" (" year ")"))) ((phdthesis) - `(author ": " (or title url documenturl) - ", " ,(G_ "PhD Thesis") - (", " (or school institution)) - (", " address) - (", " month) - (if month " " ", ") year)) + (bibliography-template author ": " (or title url documenturl) + ", " (G_ "PhD Thesis") + (", " (or school institution)) + (", " address) + (", " month) + (if month " " ", ") year)) ((misc) - '(author ": " (or title url documenturl) ". " - (institution ", ") - (publisher ", ") - (address ", ") - (month " ") ("(" year ")") - (" " url))) + (bibliography-template author ": " (or title url documenturl) ". " + (institution ", ") + (publisher ", ") + (address ", ") + (month " ") ("(" year ")") + (" " url))) (else - '(author ": " (or title url documenturl) ". " - (publisher ", ") - (address ", ") - (month " ") - (", pp. " pages) - (" (" year ")"))))) + (bibliography-template author ": " (or title url documenturl) ". " + (publisher ", ") + (address ", ") + (month " ") + (", pp. " pages) + (" (" year ")"))))) ;;; diff --git a/tests/Makefile.am b/tests/Makefile.am index 8ba7637..a423234 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -11,6 +11,7 @@ TEST_LOG_DRIVER = \ TESTS = \ ast.test \ + biblio.test \ resolve.test \ engines/info.test \ location.test diff --git a/tests/biblio.test b/tests/biblio.test new file mode 100644 index 0000000..954d964 --- /dev/null +++ b/tests/biblio.test @@ -0,0 +1,88 @@ +;;; Exercise the `biblio' routines. -*- Scheme -*- +;;; +;;; Copyright (C) 2022 Ludovic Courtès +;;; +;;; This file is part of Skribilo. +;;; +;;; Skribilo is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU Lesser General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; Skribilo is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU Lesser General Public License +;;; along with this program. If not, see . + +(define-module (tests biblio) + #:use-module ((skribilo reader) #:select (*document-reader*)) + #:use-module (skribilo ast) + #:use-module (skribilo biblio) + #:use-module (skribilo biblio template) + #:use-module (srfi srfi-64)) + +(define sbib + '(article + scheme:r5rs + (title "The Revised5 Report on the Algorithmic Language Scheme") + (author "Richard Kelsey, William D. Clinger, Jonathan Rees") + (journal "Higher-Order and Symbolic Computation") + (volume "11") + (number "1") + (month "Sep") + (year "1998") + (url "http://kaolin.unice.fr/Bigloo/doc/r5rs.html"))) + +(define table + (make-bib-table 'table)) + + +(test-begin "biblio") + +(test-equal "parse-bib" + "The Revised5 Report on the Algorithmic Language Scheme" + (begin + (call-with-input-string (object->string sbib) + (lambda (port) + (parameterize ((*document-reader* read)) + (parse-bib table port)))) + (and (bib-table? table) + (let ((entry (resolve-bib table 'scheme:r5rs))) + (and (is-markup? entry '&bib-entry) + (markup-body (markup-option entry 'title))))))) + +(test-equal "bibliography-template, simple" + (let ((entry (resolve-bib table 'scheme:r5rs))) + (list "A: " (markup-option entry 'author) + "T: " (markup-option entry 'title) + "Y: " (markup-option entry 'year))) + (let ((template (bibliography-template "A: " author + "T: " title + "Y: " year))) + (template (resolve-bib table 'scheme:r5rs)))) + +(test-equal "bibliography-template, conditionals" + (let ((entry (resolve-bib table 'scheme:r5rs))) + (list "A: " (markup-option entry 'author) + "T: " (markup-option entry 'title) + "Y: " (list (markup-option entry 'year)) + "B: " '("no"))) + (let ((template (bibliography-template "A: " (or editor author) + "T: " (or booktitle title) + "Y: " (if year year "N") + "B: " (if booktitle "yes" "no")))) + (template (resolve-bib table 'scheme:r5rs)))) + +(test-equal "bibliography-template, tricky things" + (let ((entry (resolve-bib table 'scheme:r5rs))) + (list "A: " (markup-option entry 'author) + "Y: " (markup-option entry 'year) "!")) + (let ((template (bibliography-template ("A: " author) + ("T: " booktitle "+" title) + ("Y: " year "!")))) + (template (resolve-bib table 'scheme:r5rs)))) + +(test-end "biblio") base-commit: 3746030f437db70c8ede10f7f063fac2a8d51248 -- 2.35.1 ------------=_1651782843-28711-1--