;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br>
;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br>
-;; Time-stamp: <2004/02/25 20:17:43 vinicius>
+;; Time-stamp: <2004/04/04 21:40:30 vinicius>
;; Keywords: wp, ebnf, PostScript
-;; Version: 4.0
+;; Version: 4.2
;; X-URL: http://www.cpqd.com.br/~vinicius/emacs/
;; This file is part of GNU Emacs.
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
-(defconst ebnf-version "4.0"
- "ebnf2ps.el, v 4.0 <2004/02/24 vinicius>
+(defconst ebnf-version "4.2"
+ "ebnf2ps.el, v 4.2 <2004/04/04 vinicius>
Vinicius's last change version. When reporting bugs, please also
report the version of Emacs, if any, that ebnf2ps was running with.
;; Using ebnf2ps
;; -------------
;;
-;; ebnf2ps provides six commands for generating PostScript syntactic chart
-;; images of Emacs buffers:
+;; ebnf2ps provides the following commands for generating PostScript syntactic
+;; chart images of Emacs buffers:
;;
;; ebnf-print-directory
;; ebnf-print-file
;; (global-set-key '(control f22) 'ebnf-despool)
;;
;;
+;; Invoking Ebnf2ps in Batch
+;; -------------------------
+;;
+;; It's possible also to run ebnf2ps in batch, this is useful when, for
+;; example, you have a directory with a lot of files containing the EBNF to be
+;; translated to PostScript.
+;;
+;; To run ebnf2ps in batch type, for example:
+;;
+;; emacs -batch -l setup-ebnf2ps.el -f ebnf-eps-directory
+;;
+;; Where setup-ebnf2ps.el should be a file containing:
+;;
+;; ;; set load-path if ebnf2ps isn't installed in your Emacs environment
+;; (setq load-path (append (list "/dir/of/ebnf2ps") load-path))
+;; (require 'ebnf2ps)
+;; ;; insert here your ebnf2ps settings
+;; (setq ebnf-terminal-shape 'bevel)
+;; ;; etc.
+;;
+;;
;; EBNF Syntax
;; -----------
;;
+;; BNF (Backus Naur Form) notation is defined like languages, and like
+;; languages there are rules about name formation and syntax. In this section
+;; it's defined a BNF syntax that it's called simply EBNF (Extended BNF).
+;; ebnf2ps package also deal with other BNF notation. Please, see the variable
+;; `ebnf-syntax' documentation below in this section.
+;;
;; The current EBNF that ebnf2ps accepts has the following constructions:
;;
;; ; comment (until end of line)
;; C D sequence (C occurs before D)
;; C | D alternative (C or D occurs)
;; A - B exception (A excluding B, B without any non-terminal)
-;; n * A repetition (A repeats n (integer) times)
+;; n * A repetition (A repeats at least n (integer) times)
+;; n * n A repetition (A repeats exactly n (integer) times)
+;; n * m A repetition (A repeats at least n (integer) and at most
+;; m (integer) times)
;; (C) group (expression C is grouped together)
;; [C] optional (C may or not occurs)
;; C+ one or more occurrences of C
;;
;; exception = repeat [ "-" repeat]. ;; exception
;;
-;; repeat = [ integer "*" ] term. ;; repetition
+;; repeat = [ integer "*" [ integer ]] term. ;; repetition
;;
;; term = factor
;; | [factor] "+" ;; one-or-more
;; `ebnf-lex-comment-char' and `ebnf-lex-eop-char'.
;;
;; `abnf' ebnf2ps recognizes the syntax described in the URL:
-;; `http://www.faqs.org/rfcs/rfc2234.html'
+;; `http://www.ietf.org/rfc/rfc2234.txt'
;; ("Augmented BNF for Syntax Specifications: ABNF").
;;
;; `iso-ebnf' ebnf2ps recognizes the syntax described in the URL:
;; setting:
;; `ebnf-yac-ignore-error-recovery'.
;;
+;; `ebnfx' ebnf2ps recognizes the syntax described in the URL:
+;; `http://www.w3.org/TR/2004/REC-xml-20040204/#sec-notation'
+;; ("Extensible Markup Language (XML) 1.0 (Third Edition)")
+;;
+;; `dtd' ebnf2ps recognizes the syntax described in the URL:
+;; `http://www.w3.org/TR/2004/REC-xml-20040204/'
+;; ("Extensible Markup Language (XML) 1.0 (Third Edition)")
+;;
;; Any other value is treated as `ebnf'.
;;
;; The default value is `ebnf'.
;;
;; ebnf2ps accepts the following actions in comments:
;;
+;; ;^ same as form feed. See section Form Feed above.
+;;
;; ;> the next production starts in the same line as the current one.
;; It is useful when `ebnf-horizontal-orientation' is nil.
;;
;; Only the ;> will take effect, that is, A and B will be drawn in the same
;; line.
;;
-;; In ISO EBNF the above actions are specified as (*>*), (*<*), (*[EPS*) and
-;; (*]EPS*). The first example above should be written:
+;; In ISO EBNF the above actions are specified as (*^*), (*>*), (*<*), (*[EPS*)
+;; and (*]EPS*). The first example above should be written:
;;
;; A = t;
;; C = x;
;;
;; `ebnf-setup' returns the current setup.
;;
+;; `ebnf-syntax-directory' does a syntactic analysis of your EBNF files in the
+;; given directory.
+;;
+;; `ebnf-syntax-file' does a syntactic analysis of your EBNF in the given
+;; file.
+;;
;; `ebnf-syntax-buffer' does a syntactic analysis of your EBNF in the current
;; buffer.
;;
;;
;; `ebnf-customize' activates a customization buffer for ebnf2ps options.
;;
-;; `ebnf-syntax-buffer', `ebnf-syntax-region' and `ebnf-customize' can be bound
-;; to keys in the same way as `ebnf-' commands.
+;; `ebnf-syntax-directory', `ebnf-syntax-file', `ebnf-syntax-buffer',
+;; `ebnf-syntax-region' and `ebnf-customize' can be bound to keys in the same
+;; way as `ebnf-' commands.
;;
;;
;; Hooks
`ebnf-lex-comment-char' and `ebnf-lex-eop-char'.
`abnf' ebnf2ps recognizes the syntax described in the URL:
- `http://www.faqs.org/rfcs/rfc2234.html'
+ `http://www.ietf.org/rfc/rfc2234.txt'
(\"Augmented BNF for Syntax Specifications: ABNF\").
`iso-ebnf' ebnf2ps recognizes the syntax described in the URL:
setting:
`ebnf-yac-ignore-error-recovery'.
+ `ebnfx' ebnf2ps recognizes the syntax described in the URL:
+ `http://www.w3.org/TR/2004/REC-xml-20040204/#sec-notation'
+ (\"Extensible Markup Language (XML) 1.0 (Third Edition)\")
+
+ `dtd' ebnf2ps recognizes the syntax described in the URL:
+ `http://www.w3.org/TR/2004/REC-xml-20040204/'
+ (\"Extensible Markup Language (XML) 1.0 (Third Edition)\")
+
Any other value is treated as `ebnf'."
:type '(radio :tag "Syntax"
- (const ebnf) (const abnf) (const iso-ebnf) (const yacc))
+ (const ebnf) (const abnf) (const iso-ebnf)
+ (const yacc) (const ebnfx) (const dtd))
:group 'ebnf-syntactic)
:type 'boolean
:group 'ebnf-optimization)
+\f
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; To make this file smaller, some commands go in a separate file.
+;; But autoload them here to make the separation invisible.
+;; Autoload is here to avoid compilation gripes.
+
+(autoload 'ebnf-eliminate-empty-rules "ebnf-otz"
+ "Eliminate empty rules.")
+
+(autoload 'ebnf-optimize "ebnf-otz"
+ "Syntactic chart optimizer.")
+
+(autoload 'ebnf-otz-initialize "ebnf-otz"
+ "Initialize optimizer.")
+
\f
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Customization
(defalias 'ebnf-despool 'ps-despool)
+;;;###autoload
+(defun ebnf-syntax-directory (&optional directory)
+ "Does a syntactic analysis of the files in DIRECTORY.
+
+If DIRECTORY is nil, it's used `default-directory'.
+
+The files in DIRECTORY that matches `ebnf-file-suffix-regexp' (which see) are
+processed.
+
+See also `ebnf-syntax-buffer'."
+ (interactive
+ (list (read-file-name "Directory containing EBNF files (syntax): "
+ nil default-directory)))
+ (ebnf-directory 'ebnf-syntax-buffer directory))
+
+
+;;;###autoload
+(defun ebnf-syntax-file (file &optional do-not-kill-buffer-when-done)
+ "Does a syntactic analysis of the FILE.
+
+If optional arg DO-NOT-KILL-BUFFER-WHEN-DONE is non-nil, the buffer isn't
+killed after syntax checking.
+
+See also `ebnf-syntax-buffer'."
+ (interactive "fEBNF file to check syntax: ")
+ (ebnf-file 'ebnf-syntax-buffer file do-not-kill-buffer-when-done))
+
+
;;;###autoload
(defun ebnf-syntax-buffer ()
"Does a syntactic analysis of the current buffer."
(yacc
default
(ebnf-syntax . 'yacc))
+ ;; ebnfx default
+ (ebnfx
+ default
+ (ebnf-syntax . 'ebnfx))
+ ;; dtd default
+ (dtd
+ default
+ (ebnf-syntax . 'dtd))
)
"Style database.
'((iso-ebnf ebnf-iso-parser ebnf-iso-initialize)
(yacc ebnf-yac-parser ebnf-yac-initialize)
(abnf ebnf-abn-parser ebnf-abn-initialize)
- (ebnf ebnf-bnf-parser ebnf-bnf-initialize))
+ (ebnf ebnf-bnf-parser ebnf-bnf-initialize)
+ (ebnfx ebnf-ebx-parser ebnf-ebx-initialize)
+ (dtd ebnf-dtd-parser ebnf-dtd-initialize))
"Alist associating ebnf syntax with a parser and a initializer.")
(defun ebnf-eps-finish-and-write (buffer filename)
- (save-excursion
- (set-buffer buffer)
- (setq ebnf-eps-upper-x (max ebnf-eps-upper-x ebnf-eps-max-width)
- ebnf-eps-upper-y (if (zerop ebnf-eps-upper-y)
- ebnf-eps-max-height
- (+ ebnf-eps-upper-y
- ebnf-production-vertical-space
- ebnf-eps-max-height)))
- ;; prologue
- (goto-char (point-min))
- (insert
- "%!PS-Adobe-3.0 EPSF-3.0"
- "\n%%BoundingBox: 0 0 "
- (format "%d %d" (1+ ebnf-eps-upper-x) (1+ ebnf-eps-upper-y))
- "\n%%Title: " filename
- "\n%%CreationDate: " (format-time-string "%T %b %d %Y")
- "\n%%Creator: " (user-full-name) " (using ebnf2ps v" ebnf-version ")"
- "\n%%DocumentNeededResources: font "
- (or ebnf-fonts-required
- (setq ebnf-fonts-required
- (mapconcat 'identity
- (ps-remove-duplicates
- (mapcar 'ebnf-font-name-select
- (list ebnf-production-font
- ebnf-terminal-font
- ebnf-non-terminal-font
- ebnf-special-font
- ebnf-except-font
- ebnf-repeat-font)))
- "\n%%+ font ")))
- "\n%%Pages: 0\n%%EndComments\n\n%%BeginProlog\n"
- ebnf-eps-prologue)
- (ebnf-insert-ebnf-prologue)
- (insert ebnf-eps-begin
- "\n0 " (ebnf-format-float
- (- ebnf-eps-upper-y (* ebnf-font-height-P 0.7)))
- " #ebnf2ps#begin\n")
- ;; epilogue
- (goto-char (point-max))
- (insert ebnf-eps-end)
- ;; write file
- (message "Saving...")
- (setq filename (expand-file-name filename))
- (let ((coding-system-for-write 'raw-text-unix))
- (write-region (point-min) (point-max) filename))
- (message "Wrote %s" filename)))
+ (when (buffer-modified-p buffer)
+ (save-excursion
+ (set-buffer buffer)
+ (setq ebnf-eps-upper-x (max ebnf-eps-upper-x ebnf-eps-max-width)
+ ebnf-eps-upper-y (if (zerop ebnf-eps-upper-y)
+ ebnf-eps-max-height
+ (+ ebnf-eps-upper-y
+ ebnf-production-vertical-space
+ ebnf-eps-max-height)))
+ ;; prologue
+ (goto-char (point-min))
+ (insert
+ "%!PS-Adobe-3.0 EPSF-3.0"
+ "\n%%BoundingBox: 0 0 "
+ (format "%d %d" (1+ ebnf-eps-upper-x) (1+ ebnf-eps-upper-y))
+ "\n%%Title: " filename
+ "\n%%CreationDate: " (format-time-string "%T %b %d %Y")
+ "\n%%Creator: " (user-full-name) " (using ebnf2ps v" ebnf-version ")"
+ "\n%%DocumentNeededResources: font "
+ (or ebnf-fonts-required
+ (setq ebnf-fonts-required
+ (mapconcat 'identity
+ (ps-remove-duplicates
+ (mapcar 'ebnf-font-name-select
+ (list ebnf-production-font
+ ebnf-terminal-font
+ ebnf-non-terminal-font
+ ebnf-special-font
+ ebnf-except-font
+ ebnf-repeat-font)))
+ "\n%%+ font ")))
+ "\n%%Pages: 0\n%%EndComments\n\n%%BeginProlog\n"
+ ebnf-eps-prologue)
+ (ebnf-insert-ebnf-prologue)
+ (insert ebnf-eps-begin
+ "\n0 " (ebnf-format-float
+ (- ebnf-eps-upper-y (* ebnf-font-height-P 0.7)))
+ " #ebnf2ps#begin\n")
+ ;; epilogue
+ (goto-char (point-max))
+ (insert ebnf-eps-end)
+ ;; write file
+ (message "Saving...")
+ (setq filename (expand-file-name filename))
+ (let ((coding-system-for-write 'raw-text-unix))
+ (write-region (point-min) (point-max) filename))
+ (message "Wrote %s" filename))))
(defun ebnf-insert-ebnf-prologue ()
(cons seq body)
body))))))))
+
+(defun ebnf-token-sequence (sequence)
+ (cond
+ ;; null sequence
+ ((null sequence)
+ (ebnf-make-empty))
+ ;; sequence with only one element
+ ((= (length sequence) 1)
+ (car sequence))
+ ;; a real sequence
+ (t
+ (ebnf-make-sequence (nreverse sequence)))
+ ))
+
\f
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Variables used by parsers
;; Override special comment character:
(aset table ?< 'newline)
(aset table ?> 'keep-line)
+ (aset table ?^ 'form-feed)
table)
"Vector used to map characters to a special comment token.")
(autoload 'ebnf-yac-initialize "ebnf-yac"
"Initializations for Yacc/Bison parser.")
-(autoload 'ebnf-eliminate-empty-rules "ebnf-otz"
- "Eliminate empty rules.")
+(autoload 'ebnf-ebx-parser "ebnf-ebx"
+ "EBNFX parser.")
-(autoload 'ebnf-optimize "ebnf-otz"
- "Syntactic chart optimizer.")
+(autoload 'ebnf-ebx-initialize "ebnf-ebx"
+ "Initializations for EBNFX parser.")
-(autoload 'ebnf-otz-initialize "ebnf-otz"
- "Initialize optimizer.")
+(autoload 'ebnf-dtd-parser "ebnf-dtd"
+ "DTD parser.")
+
+(autoload 'ebnf-dtd-initialize "ebnf-dtd"
+ "Initializations for DTD parser.")
\f
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;