From fc42fe56a57eace2dbdb31574c2e161f0eacf839 Mon Sep 17 00:00:00 2001 From: Ludovic Court`es Date: Wed, 15 Jun 2005 13:00:39 +0000 Subject: Initial import of Skribe 1.2d. Initial import of Skribe 1.2d. git-archimport-id: lcourtes@laas.fr--2004-libre/skribilo--devel--1.2--base-0 --- tools/skribebibtex/stklos/Makefile | 62 ++++++++++++++++ tools/skribebibtex/stklos/bibtex-lex.l | 75 +++++++++++++++++++ tools/skribebibtex/stklos/bibtex-parser.y | 117 +++++++++++++++++++++++++++++ tools/skribebibtex/stklos/main.stk | 118 ++++++++++++++++++++++++++++++ 4 files changed, 372 insertions(+) create mode 100644 tools/skribebibtex/stklos/Makefile create mode 100644 tools/skribebibtex/stklos/bibtex-lex.l create mode 100644 tools/skribebibtex/stklos/bibtex-parser.y create mode 100644 tools/skribebibtex/stklos/main.stk (limited to 'tools/skribebibtex/stklos') diff --git a/tools/skribebibtex/stklos/Makefile b/tools/skribebibtex/stklos/Makefile new file mode 100644 index 0000000..3e31d88 --- /dev/null +++ b/tools/skribebibtex/stklos/Makefile @@ -0,0 +1,62 @@ +# +# Makefile for STklos skribebibtex +# +# Author: Erick Gallesio [eg@essi.fr] +# Creation date: 26-Oct-2004 18:40 (eg) +# Last file update: 8-Nov-2004 15:25 (eg) + +include ../../../etc/stklos/Makefile.skb +include ../../../etc/Makefile.config + +POPULATION = Makefile bibtex-lex.l bibtex-parser.y skribebibtex.stk main.stk +BINDIR = ../../../bin +TARGET = skribebibtex +EXE = $(BINDIR)/$(TARGET).stklos + +all: $(EXE) + +$(EXE): main.stk bibtex-lex.stk bibtex-parser.stk + stklos-compile -l -o $(EXE) main.stk + +bibtex-lex.stk: bibtex-lex.l + stklos-genlex bibtex-lex.l bibtex-lex.stk bibtex-lex + +bibtex-parser.stk: bibtex-parser.y + stklos -f bibtex-parser.y + +bibtex: bibtex-lex.stk + + +#====================================================================== +# install ... +#====================================================================== +install: $(INSTALL_BINDIR) + cp $(EXE) $(INSTALL_BINDIR)/$(TARGET).stklos \ + && chmod $(BMASK) $(INSTALL_BINDIR)/$(TARGET).stklos + rm -f $(INSTALL_BINDIR)/$(TARGET) + ln -s $(TARGET).stklos $(INSTALL_BINDIR)/$(TARGET) + +$(INSTALL_BINDIR): + mkdir -p $(INSTALL_BINDIR) && chmod a+rx $(INSTALL_BINDIR) + + +#====================================================================== +# uninstall ... +#====================================================================== +uninstall: + rm $(INSTALL_BINDIR)/$(TARGET) + rm $(INSTALL_BINDIR)/$(TARGET).stklos + + +#====================================================================== +# pop ... +#====================================================================== +pop: + @echo $(POPULATION:%=tools/skribebibtex/stklos/%) + +#====================================================================== +# clean ... +#====================================================================== + +clean: + rm -f $(EXE) bibtex-lex.stk bibtex-parser.stk *~ diff --git a/tools/skribebibtex/stklos/bibtex-lex.l b/tools/skribebibtex/stklos/bibtex-lex.l new file mode 100644 index 0000000..03b4871 --- /dev/null +++ b/tools/skribebibtex/stklos/bibtex-lex.l @@ -0,0 +1,75 @@ +;;;; -*- Scheme -*- +;;;; bibtex-lex.l -- SILex input for BibTeX +;;;; +;;;; Copyright © 2004 Erick Gallesio - I3S-CNRS/ESSI +;;;; +;;;; +;;;; This program is free software; you can redistribute it and/or modify +;;;; it under the terms of the GNU General Public License as published by +;;;; the Free Software Foundation; either version 2 of the License, or +;;;; (at your option) any later version. +;;;; +;;;; This program 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 General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with this program; if not, write to the Free Software +;;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +;;;; USA. +;;;; +;;;; Author: Erick Gallesio [eg@essi.fr] +;;;; Creation date: 21-Oct-2004 17:47 (eg) +;;;; Last file update: 25-Oct-2004 20:16 (eg) +;;;; + + +space [ \n\9] +alpha [-+a-zA-ZàâäéèêëîïôöûüùÀÂÄÉÈÊËÎÏÔÖÛÜÙ./:()?!'&_~] + +%% + +;; Spaces +{space}+ (list 'BLANK) +;; Comment +\%.*$ (yycontinue) +;; equal sign += (list 'EQUAL) +;; Open Bracket +\{ (list 'LBRACKET) +;; Close Bracket +\} (list 'RBRACKET) +;; Comma +, (list 'COMMA) +;; Strings +\"[^\"]*\" (list 'STRING yytext) +;; Commands +@{alpha}+ (let* ((str (string-downcase + (substring yytext 1 + (string-length yytext)))) + (sym (string->symbol str))) + (case sym + ((string) (list 'BIBSTRING)) + (else (list 'BIBITEM sym)))) +;; Ident +{alpha}({alpha}|[0-9])* (list 'IDENT yytext) +;; Number +[0-9]+ (list 'NUMBER yytext) +;; Diacritic +\\['`^\"][aeiouAEIOU] (lex-char (string-ref yytext 1) + (string-ref yytext 2)) +\{\\['`^\"][aeiouAEIOU]\} (lex-char (string-ref yytext 2) + (string-ref yytext 3)) + +;; Unrecognized character +. (begin + (format (current-error-port) + "Skipping character ~S\n" yytext) + (yycontinue)) + +;;;; ====================================================================== +<> '*eoi* +<> (error 'bibtex-lexer "Parse error" yytext) + + diff --git a/tools/skribebibtex/stklos/bibtex-parser.y b/tools/skribebibtex/stklos/bibtex-parser.y new file mode 100644 index 0000000..50236a9 --- /dev/null +++ b/tools/skribebibtex/stklos/bibtex-parser.y @@ -0,0 +1,117 @@ +;;;; -*- Scheme -*- +;;;; bibtex-parser.y -- SILex input for BibTeX +;;;; +;;;; Copyright © 2004 Erick Gallesio - I3S-CNRS/ESSI +;;;; +;;;; +;;;; This program is free software; you can redistribute it and/or modify +;;;; it under the terms of the GNU General Public License as published by +;;;; the Free Software Foundation; either version 2 of the License, or +;;;; (at your option) any later version. +;;;; +;;;; This program 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 General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with this program; if not, write to the Free Software +;;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +;;;; USA. +;;;; +;;;; Author: Erick Gallesio [eg@essi.fr] +;;;; Creation date: 21-Oct-2004 17:47 (eg) +;;;; Last file update: 22-Oct-2004 18:14 (eg) +;;;; + +(load "lalr") + +(define (main args) + ;; Build the parser + (lalr-parser + ;; Options + (output: parser "bibtex-parser.stk") + + ;; Terminal symbols + (CHAR BLANK IDENT STRING COMMA LBRACKET RBRACKET NUMBER EQUAL + BIBSTRING BIBITEM) + + ;; Rules + (S + () + (S string-def) + (S blank*) + (S bibtex-entry)) + + + (blank* + () + (blank* BLANK)) + + + (string-def + (BIBSTRING LBRACKET blank* IDENT blank* EQUAL blank* entry-value + blank* RBRACKET) + : (bibtex-string-def! (car $4) (car $8))) + + + (bibtex-entry + (BIBITEM LBRACKET blank* IDENT blank* COMMA blank* entry-item* RBRACKET) + : (make-bibentry $1 $4 $8)) + + + (entry-item* + (blank*) + : '() + (entry-item) + : (list $1) + (entry-item COMMA entry-item*) + : (cons $1 $3)) + + + (entry-item + (blank* IDENT blank* EQUAL blank* entry-value blank*) + : (cons (car $2) $6)) + + + (entry-value + (NUMBER) + : (list (car $1)) + (STRING) + : $1 + (IDENT) + : (bibtex-string-ref (car $1)) + (LBRACKET entry-value-block* RBRACKET) + : (list (apply string-append $2))) + + + (entry-value-block* + () + : '() + (entry-value-block* entry-value-block) + : (append $1 $2)) + + + (entry-value-block + (LBRACKET entry-value-block* RBRACKET) + : $2 + (COMMA) + : (list ",") + (IDENT) + : $1 + (BLANK) + : (list " ") + (EQUAL) + : (list "=") + (CHAR) + : $1 + (NUMBER) + : $1 + (STRING) + : $1) + ) + ;; Terminate + 0) + + + \ No newline at end of file diff --git a/tools/skribebibtex/stklos/main.stk b/tools/skribebibtex/stklos/main.stk new file mode 100644 index 0000000..3225658 --- /dev/null +++ b/tools/skribebibtex/stklos/main.stk @@ -0,0 +1,118 @@ +;;;; +;;;; main.stk -- Skribebibtex Main +;;;; +;;;; Copyright © 2004 Erick Gallesio - I3S-CNRS/ESSI +;;;; +;;;; +;;;; This program is free software; you can redistribute it and/or modify +;;;; it under the terms of the GNU General Public License as published by +;;;; the Free Software Foundation; either version 2 of the License, or +;;;; (at your option) any later version. +;;;; +;;;; This program 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 General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with this program; if not, write to the Free Software +;;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +;;;; USA. +;;;; +;;;; Author: Erick Gallesio [eg@essi.fr] +;;;; Creation date: 22-Oct-2004 10:29 (eg) +;;;; Last file update: 26-Oct-2004 21:52 (eg) +;;;; + +(define *bibtex-strings* (make-hash-table string=?)) +(define *debug* (getenv "DEBUG")) +(define *in* (current-input-port)) +(define *out* (current-output-port)) + + +(define (bibtex-string-def! str val) + (hash-table-put! *bibtex-strings* str val)) + + +(define (bibtex-string-ref str) + (list (hash-table-get *bibtex-strings* str str))) + + +(define (lex-char accent letter) + (list 'CHAR + (case accent + ((#\') (case letter + ((#\a) "á") ((#\e) "é") ((#\i) "í") ((#\o) "ó") ((#\u) "ú") + ((#\A) "Á") ((#\E) "É") ((#\I) "Í") ((#\O) "Ó") ((#\U) "ú") + (else "?"))) + ((#\`) (case letter + ((#\a) "à") ((#\e) "è") ((#\i) "ì") ((#\o) "ò") ((#\u) "ù") + ((#\A) "À") ((#\E) "È") ((#\I) "Ì") ((#\O) "Ò") ((#\U) "Ù") + (else "?"))) + ((#\^) (case letter + ((#\a) "â") ((#\e) "ê") ((#\i) "î") ((#\o) "ô") ((#\u) "û") + ((#\A) "Â") ((#\E) "Ê") ((#\I) "Î") ((#\O) "Ô") ((#\U) "Û") + (else "?"))) + ((#\") (case letter + ((#\a) "ä") ((#\e) "ë") ((#\i) "ï") ((#\o) "ö") ((#\u) "ü") + ((#\A) "Ä") ((#\E) "Ë") ((#\I) "Ï") ((#\O) "Ö") ((#\U) "Ü") + (else "?"))) + (else "?")))) + + +(define (make-bibentry kind key infos) + (define (pretty-string s) + (if (and (string? s) + (>= (string-length s) 2) + (eq? #\" (string-ref s 0)) + (eq? #\" (string-ref s (- (string-length s) 1)))) + (substring s 1 (- (string-length s) 1)) + s)) + (format *out* ";;;;\n(~A ~S\n" (car kind) (car key)) + (for-each (lambda (x) (format *out* " (~A ~S)\n" + (car x) + (pretty-string (cadr x)))) + infos) + (format *out* ")\n\n")) + + +;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- +(include "bibtex-lex.stk") +(include "bibtex-parser.stk") +;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- + +(define (bibtex2scheme in out) + (let* ((lex (bibtex-lex in)) + (scan (lambda () + (let ((tok (lexer-next-token lex))) + (when *debug* + (format (current-error-port) "token = ~S\n" tok)) + tok))) + (error (lambda (a b) (error 'bibtex-parser "~A~A" a b)))) + (parser scan error))) + + +(define (main args) + ;; Parse the program arguments + (parse-arguments args + "Usage: skribebibtex [options] [input]" + (("help" :alternate "h" :help "provide help for the command") + (arg-usage (current-error-port)) + (exit 0)) + (("options" :help "display the options and exit") + (arg-usage (current-output-port) #t) + (exit 0)) + (("output" :alternate "o" :arg file :help "set the output to ") + (let ((port (open-file file "w"))) + (if port + (set! *out* port) + (die (format "~A: bad output file ~S" 'skribebibtex file) 1)))) + (else + (cond + ((= (length other-arguments) 1) + (let* ((file (car other-arguments)) + (port (open-file file "r"))) + (if port + (set! *in* file) + (die (format "~A: bad input file ~S" 'skribebibtex file) 1))))))) + (bibtex2scheme *in* *out*)) -- cgit v1.2.3