ebnf2ps.el 183 KB
Newer Older
Juanma Barranquero's avatar
Juanma Barranquero committed
1
;;; ebnf2ps.el --- translate an EBNF to a syntactic chart on PostScript
Gerd Moellmann's avatar
Gerd Moellmann committed
2

Glenn Morris's avatar
Glenn Morris committed
3
;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
4
;;   Free Software Foundation, Inc.
Gerd Moellmann's avatar
Gerd Moellmann committed
5

6 7
;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br>
;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br>
8
;; Keywords: wp, ebnf, PostScript
9
;; Version: 4.4
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
10
;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre
Gerd Moellmann's avatar
Gerd Moellmann committed
11

Gerd Moellmann's avatar
Gerd Moellmann committed
12
;; This file is part of GNU Emacs.
Gerd Moellmann's avatar
Gerd Moellmann committed
13

Gerd Moellmann's avatar
Gerd Moellmann committed
14
;; GNU Emacs is free software; you can redistribute it and/or modify
Gerd Moellmann's avatar
Gerd Moellmann committed
15
;; it under the terms of the GNU General Public License as published by
16
;; the Free Software Foundation; either version 3, or (at your option)
Gerd Moellmann's avatar
Gerd Moellmann committed
17 18
;; any later version.

Gerd Moellmann's avatar
Gerd Moellmann committed
19
;; GNU Emacs is distributed in the hope that it will be useful,
Gerd Moellmann's avatar
Gerd Moellmann committed
20 21 22 23 24 25
;; 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 GNU Emacs; see the file COPYING.  If not, write to the
Lute Kamstra's avatar
Lute Kamstra committed
26 27
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
Gerd Moellmann's avatar
Gerd Moellmann committed
28

29 30
(defconst ebnf-version "4.4"
  "ebnf2ps.el, v 4.4 <2007/02/12 vinicius>
Gerd Moellmann's avatar
Gerd Moellmann committed
31 32 33 34 35

Vinicius's last change version.  When reporting bugs, please also
report the version of Emacs, if any, that ebnf2ps was running with.

Please send all bug fixes and enhancements to
36
	Vinicius Jose Latorre <viniciusjl@ig.com.br>.
Gerd Moellmann's avatar
Gerd Moellmann committed
37 38 39
")


Gerd Moellmann's avatar
Gerd Moellmann committed
40 41 42 43 44 45 46
;;; Commentary:

;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Introduction
;; ------------
;;
Juanma Barranquero's avatar
Juanma Barranquero committed
47
;; This package translates an EBNF to a syntactic chart on PostScript.
Gerd Moellmann's avatar
Gerd Moellmann committed
48 49 50 51 52
;;
;; To use ebnf2ps, insert in your ~/.emacs:
;;
;;        (require 'ebnf2ps)
;;
53 54 55
;; ebnf2ps uses ps-print package (version 5.2.3 or later), so see ps-print to
;; know how to set options like landscape printing, page headings, margins,
;; etc.
Gerd Moellmann's avatar
Gerd Moellmann committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
;;
;; NOTE: ps-print zebra stripes and line number options doesn't have effect on
;;       ebnf2ps, they behave as it's turned off.
;;
;; For good performance, be sure to byte-compile ebnf2ps.el, e.g.
;;
;;    M-x byte-compile-file <give the path to ebnf2ps.el when prompted>
;;
;; This will generate ebnf2ps.elc, which will be loaded instead of ebnf2ps.el.
;;
;; ebnf2ps was tested with GNU Emacs 20.4.1.
;;
;;
;; Using ebnf2ps
;; -------------
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
72 73
;; ebnf2ps provides the following commands for generating PostScript syntactic
;; chart images of Emacs buffers:
Gerd Moellmann's avatar
Gerd Moellmann committed
74
;;
75 76 77 78 79 80 81 82 83 84 85 86
;;    ebnf-print-directory
;;    ebnf-print-file
;;    ebnf-print-buffer
;;    ebnf-print-region
;;    ebnf-spool-directory
;;    ebnf-spool-file
;;    ebnf-spool-buffer
;;    ebnf-spool-region
;;    ebnf-eps-directory
;;    ebnf-eps-file
;;    ebnf-eps-buffer
;;    ebnf-eps-region
Gerd Moellmann's avatar
Gerd Moellmann committed
87 88
;;
;; These commands all perform essentially the same function: they generate
Juanma Barranquero's avatar
Juanma Barranquero committed
89
;; PostScript syntactic chart images suitable for printing on a PostScript
Gerd Moellmann's avatar
Gerd Moellmann committed
90 91 92 93 94 95
;; printer or displaying with GhostScript.  These commands are collectively
;; referred to as "ebnf- commands".
;;
;; The word "print", "spool" and "eps" in the command name determines when the
;; PostScript image is sent to the printer (or file):
;;
96
;;    print  - The PostScript image is immediately sent to the printer;
Gerd Moellmann's avatar
Gerd Moellmann committed
97
;;
98 99 100 101
;;    spool  - The PostScript image is saved temporarily in an Emacs buffer.
;;             Many images may be spooled locally before printing them.  To
;;             send the spooled images to the printer, use the command
;;             `ebnf-despool'.
Gerd Moellmann's avatar
Gerd Moellmann committed
102
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
103
;;    eps    - The PostScript image is immediately sent to an EPS file.
Gerd Moellmann's avatar
Gerd Moellmann committed
104 105 106 107 108 109 110 111 112 113 114 115
;;
;; The spooling mechanism is the same as used by ps-print and was designed for
;; printing lots of small files to save paper that would otherwise be wasted on
;; banner pages, and to make it easier to find your output at the printer (it's
;; easier to pick up one 50-page printout than to find 50 single-page
;; printouts).  As ebnf2ps and ps-print use the same Emacs buffer to spool
;; images, you can intermix the spooling of ebnf2ps and ps-print images.
;;
;; ebnf2ps use the same hook of ps-print in the `kill-emacs-hook' so that you
;; won't accidentally quit from Emacs while you have unprinted PostScript
;; waiting in the spool buffer.  If you do attempt to exit with spooled
;; PostScript, you'll be asked if you want to print it, and if you decline,
116 117
;; you'll be asked to confirm the exit; this is modeled on the confirmation
;; that Emacs uses for modified buffers.
Gerd Moellmann's avatar
Gerd Moellmann committed
118
;;
119 120
;; The word "directory", "file", "buffer" or "region" in the command name
;; determines how much of the buffer is printed:
Gerd Moellmann's avatar
Gerd Moellmann committed
121
;;
122
;;    directory  - Read files in the directory and print them.
Gerd Moellmann's avatar
Gerd Moellmann committed
123
;;
124
;;    file       - Read file and print it.
125
;;
126
;;    buffer     - Print the entire buffer.
127
;;
128
;;    region     - Print just the current region.
Gerd Moellmann's avatar
Gerd Moellmann committed
129 130 131
;;
;; Two ebnf- command examples:
;;
132 133
;;    ebnf-print-buffer  - translate and print the entire buffer, and send it
;;                         immediately to the printer.
Gerd Moellmann's avatar
Gerd Moellmann committed
134
;;
135 136 137
;;    ebnf-spool-region  - translate and print just the current region, and
;;                         spool the image in Emacs to send to the printer
;;                         later.
Gerd Moellmann's avatar
Gerd Moellmann committed
138
;;
139 140 141 142
;; Note that `ebnf-eps-directory', `ebnf-eps-file', `ebnf-eps-buffer' and
;; `ebnf-eps-region' never spool the EPS image, so they don't use the ps-print
;; spooling mechanism.  See section "Actions in Comments" for an explanation
;; about EPS file generation.
Gerd Moellmann's avatar
Gerd Moellmann committed
143 144 145 146 147 148 149
;;
;;
;; Invoking Ebnf2ps
;; ----------------
;;
;; To translate and print your buffer, type
;;
150
;;    M-x ebnf-print-buffer
Gerd Moellmann's avatar
Gerd Moellmann committed
151 152 153 154 155
;;
;; or substitute one of the other four ebnf- commands.  The command will
;; generate the PostScript image and print or spool it as specified.  By giving
;; the command a prefix argument
;;
156
;;    C-u M-x ebnf-print-buffer
Gerd Moellmann's avatar
Gerd Moellmann committed
157 158 159 160 161 162 163
;;
;; it will save the PostScript image to a file instead of sending it to the
;; printer; you will be prompted for the name of the file to save the image to.
;; The prefix argument is ignored by the commands that spool their images, but
;; you may save the spooled images to a file by giving a prefix argument to
;; `ebnf-despool':
;;
164
;;    C-u M-x ebnf-despool
Gerd Moellmann's avatar
Gerd Moellmann committed
165 166 167 168 169 170 171 172 173
;;
;; When invoked this way, `ebnf-despool' will prompt you for the name of the
;; file to save to.
;;
;; The prefix argument is also ignored by `ebnf-eps-buffer' and
;; `ebnf-eps-region'.
;;
;; Any of the `ebnf-' commands can be bound to keys.  Here are some examples:
;;
174 175 176
;;    (global-set-key 'f22 'ebnf-print-buffer) ;f22 is prsc
;;    (global-set-key '(shift f22) 'ebnf-print-region)
;;    (global-set-key '(control f22) 'ebnf-despool)
Gerd Moellmann's avatar
Gerd Moellmann committed
177 178
;;
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
;; 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.
;;
;;
Gerd Moellmann's avatar
Gerd Moellmann committed
200 201 202
;; EBNF Syntax
;; -----------
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
203 204 205 206 207 208
;; 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.
;;
Gerd Moellmann's avatar
Gerd Moellmann committed
209 210 211 212 213 214 215 216 217 218 219 220 221
;; The current EBNF that ebnf2ps accepts has the following constructions:
;;
;;    ;			comment (until end of line)
;;    A			non-terminal
;;    "C"		terminal
;;    ?C?		special
;;    $A		default non-terminal (see text below)
;;    $"C"		default terminal (see text below)
;;    $?C?		default special (see text below)
;;    A = B.		production (A is the header and B the body)
;;    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)
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
222 223 224 225
;;    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)
Gerd Moellmann's avatar
Gerd Moellmann committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
;;    (C)		group (expression C is grouped together)
;;    [C]		optional (C may or not occurs)
;;    C+		one or more occurrences of C
;;    {C}+		one or more occurrences of C
;;    {C}*		zero or more occurrences of C
;;    {C}		zero or more occurrences of C
;;    C / D		equivalent to: C {D C}*
;;    {C || D}+		equivalent to: C {D C}*
;;    {C || D}*		equivalent to: [C {D C}*]
;;    {C || D}		equivalent to: [C {D C}*]
;;
;; The EBNF syntax written using the notation above is:
;;
;;    EBNF = {production}+.
;;
;;    production = non_terminal "=" body ".".   ;; production
;;
;;    body = {sequence || "|"}*.                ;; alternative
;;
;;    sequence = {exception}*.                  ;; sequence
;;
;;    exception = repeat [ "-" repeat].         ;; exception
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
249
;;    repeat = [ integer "*" [ integer ]] term. ;; repetition
Gerd Moellmann's avatar
Gerd Moellmann committed
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
;;
;;    term = factor
;;         | [factor] "+"                       ;; one-or-more
;;         | [factor] "/" [factor]              ;; one-or-more
;;         .
;;
;;    factor = [ "$" ] "\"" terminal "\""       ;; terminal
;;           | [ "$" ] non_terminal             ;; non-terminal
;;           | [ "$" ] "?" special "?"          ;; special
;;           | "(" body ")"                     ;; group
;;           | "[" body "]"                     ;; zero-or-one
;;           | "{" body [ "||" body ] "}+"      ;; one-or-more
;;           | "{" body [ "||" body ] "}*"      ;; zero-or-more
;;           | "{" body [ "||" body ] "}"       ;; zero-or-more
;;           .
;;
266
;;    non_terminal = "[!#%&'*-,0-:<>@-Z\\\\^-z~\\240-\\377]+".
267 268 269 270
;;    ;; that is, a valid non_terminal accepts decimal digits, letters (upper
;;    ;; and lower), 8-bit accentuated characters,
;;    ;; "!", "#", "%", "&", "'", "*", "+", ",", ":",
;;    ;; "<", ">", "@", "\", "^", "_", "`" and "~".
Gerd Moellmann's avatar
Gerd Moellmann committed
271 272
;;
;;    terminal = "\\([^\"\\]\\|\\\\[ -~\\240-\\377]\\)+".
273 274 275 276
;;    ;; that is, a valid terminal accepts any printable character (including
;;    ;; 8-bit accentuated characters) except `"', as `"' is used to delimit a
;;    ;; terminal.  Also, accepts escaped characters, that is, a character
;;    ;; pair starting with `\' followed by a printable character, for
277
;;    ;; example: \", \\.
Gerd Moellmann's avatar
Gerd Moellmann committed
278
;;
279 280 281 282
;;    special = "[^?\\000-\\010\\012-\\037\\177-\\237]*".
;;    ;; that is, a valid special accepts any printable character (including
;;    ;; 8-bit accentuated characters) and tabs except `?', as `?' is used to
;;    ;; delimit a special.
Gerd Moellmann's avatar
Gerd Moellmann committed
283 284
;;
;;    integer = "[0-9]+".
285
;;    ;; that is, an integer is a sequence of one or more decimal digits.
Gerd Moellmann's avatar
Gerd Moellmann committed
286 287
;;
;;    comment = ";" "[^\\n\\000-\\010\\016-\\037\\177-\\237]*" "\\n".
288 289 290
;;    ;; that is, a comment starts with the character `;' and terminates at end
;;    ;; of line.  Also, it only accepts printable characters (including 8-bit
;;    ;; accentuated characters) and tabs.
Gerd Moellmann's avatar
Gerd Moellmann committed
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
;;
;; Try to use the above EBNF to test ebnf2ps.
;;
;; The `default' terminal, non-terminal and special is a way to indicate a
;; default path in a production.  For example, the production:
;;
;;    X = [ $A ( B | $C ) | D ].
;;
;; Indicates that the default meaning for "X" is "A C" if "X" is empty.
;;
;; The terminal name is controlled by `ebnf-terminal-regexp' and
;; `ebnf-case-fold-search', so it's possible to match other kind of terminal
;; name besides that enclosed by `"'.
;;
;; Let's see an example:
;;
;;    (setq ebnf-terminal-regexp "[A-Z][_A-Z]*") ; upper case name
;;    (setq ebnf-case-fold-search nil) ; exact matching
;;
;; If you have the production:
;;
;;    Logical = "(" Expression ( OR | AND | "XOR" ) Expression ")".
;;
;; The names are classified as:
;;
;;    Logical  Expression		non-terminal
;;    "("  OR  AND  "XOR"  ")"		terminal
;;
319 320
;; The line comment is controlled by `ebnf-lex-comment-char'.  The default
;; value is ?\; (character `;').
Gerd Moellmann's avatar
Gerd Moellmann committed
321 322 323 324 325 326 327 328 329 330 331 332
;;
;; The end of production is controlled by `ebnf-lex-eop-char'.  The default
;; value is ?. (character `.').
;;
;; The variable `ebnf-syntax' specifies which syntax to recognize:
;;
;;    `ebnf'		ebnf2ps recognizes the syntax described above.
;;			The following variables *ONLY* have effect with this
;;			setting:
;;			`ebnf-terminal-regexp', `ebnf-case-fold-search',
;;			`ebnf-lex-comment-char' and `ebnf-lex-eop-char'.
;;
333
;;    `abnf'		ebnf2ps recognizes the syntax described in the URL:
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
334
;;			`http://www.ietf.org/rfc/rfc2234.txt'
335 336
;;			("Augmented BNF for Syntax Specifications: ABNF").
;;
Gerd Moellmann's avatar
Gerd Moellmann committed
337 338 339 340 341 342 343 344 345 346 347 348
;;    `iso-ebnf'	ebnf2ps recognizes the syntax described in the URL:
;;			`http://www.cl.cam.ac.uk/~mgk25/iso-ebnf.html'
;;			("International Standard of the ISO EBNF Notation").
;;			The following variables *ONLY* have effect with this
;;			setting:
;;			`ebnf-iso-alternative-p' and `ebnf-iso-normalize-p'.
;;
;;    `yacc'		ebnf2ps recognizes the Yacc/Bison syntax.
;;			The following variable *ONLY* has effect with this
;;			setting:
;;			`ebnf-yac-ignore-error-recovery'.
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
349 350 351 352
;;    `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)")
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
353 354 355 356
;;    `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)")
;;
Gerd Moellmann's avatar
Gerd Moellmann committed
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
;; Any other value is treated as `ebnf'.
;;
;; The default value is `ebnf'.
;;
;;
;; Optimizations
;; -------------
;;
;; The following EBNF optimizations are done:
;;
;;    [ { A }* ]          ==> { A }*
;;    [ { A }+ ]          ==> { A }*
;;    [ A ] +             ==> { A }*
;;    { A }* +            ==> { A }*
;;    { A }+ +            ==> { A }+
;;    { A }-              ==> { A }+
;;    [ A ]-              ==> A
;;    ( A | EMPTY )-      ==> A
;;    ( A | B | EMPTY )-  ==> A | B
;;    [ A | B ]           ==> A | B | EMPTY
;;    n * EMPTY           ==> EMPTY
;;    EMPTY +             ==> EMPTY
;;    EMPTY / EMPTY       ==> EMPTY
;;    EMPTY - A           ==> EMPTY
;;
;; The following optimizations are done when `ebnf-optimize' is non-nil:
;;
;; left recursion:
;;    1.  A = B | A C.             ==>   A = B {C}*.
;;    2.  A = B | A B.             ==>   A = {B}+.
;;    3.  A =   | A B.             ==>   A = {B}*.
;;    4.  A = B | A C B.           ==>   A = {B || C}+.
;;    5.  A = B | D | A C | A E.   ==>   A = ( B | D ) { C | E }*.
;;
;; optional:
;;    6.  A = B | .                ==>   A = [B].
;;    7.  A =   | B .              ==>   A = [B].
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
395
;; factorization:
Gerd Moellmann's avatar
Gerd Moellmann committed
396 397 398 399 400 401 402 403 404 405
;;    8.  A = B C | B D.           ==>   A = B (C | D).
;;    9.  A = C B | D B.           ==>   A = (C | D) B.
;;    10. A = B C E | B D E.       ==>   A = B (C | D) E.
;;
;; The above optimizations are specially useful when `ebnf-syntax' is `yacc'.
;;
;;
;; Form Feed
;; ---------
;;
406 407
;; You may use form feed (^L \014) to force a production to start on a new
;; page, for example:
Gerd Moellmann's avatar
Gerd Moellmann committed
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
;;
;;    a) A = B | C.
;;	 ^L
;;	 X = Y | Z.
;;
;;    b) A = B ^L | C.
;;	 X = Y | Z.
;;
;;    c) A = B ^L^L^L | C.^L
;;	 ^L
;;	 X = Y | Z.
;;
;; In all examples above, only the production X will start on a new page.
;;
;;
;; Actions in Comments
;; -------------------
;;
;; ebnf2ps accepts the following actions in comments:
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
428 429
;;    ;^	same as form feed.  See section Form Feed above.
;;
Gerd Moellmann's avatar
Gerd Moellmann committed
430 431 432 433 434 435 436 437
;;    ;>	the next production starts in the same line as the current one.
;;		It is useful when `ebnf-horizontal-orientation' is nil.
;;
;;    ;<	the next production starts in the next line.
;;		It is useful when `ebnf-horizontal-orientation' is non-nil.
;;
;;    ;[EPS	open a new EPS file.  The EPS file name has the form:
;;			<PREFIX><NAME>.eps
438 439 440
;;		where <PREFIX> is given by variable `ebnf-eps-prefix' and
;;		<NAME> is the string given by ;[ action comment, this string is
;;		mapped to form a valid file name (see documentation for
Gerd Moellmann's avatar
Gerd Moellmann committed
441 442 443 444 445 446 447 448 449 450
;;		`ebnf-eps-buffer' or `ebnf-eps-region').
;;		It has effect only during `ebnf-eps-buffer' or
;;		`ebnf-eps-region' execution.
;;		It's an error to try to open an already opened EPS file.
;;
;;    ;]EPS	close an opened EPS file.
;;		It has effect only during `ebnf-eps-buffer' or
;;		`ebnf-eps-region' execution.
;;		It's an error to try to close a not opened EPS file.
;;
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
;;    ;Hheader	generate a header in current EPS file.  The header string can
;;		have the following formats:
;;
;;		%%	prints a % character.
;;
;;		%H	prints the `ebnf-eps-header' (which see) value.
;;
;;		%F	prints the `ebnf-eps-footer' (which see) value.
;;
;;		Any  other format is ignored, that is, if, for example, it's
;;		used %s then %s characters are stripped out from the header.
;;		If header is an empty string, no header is generated until a
;;		non-empty header is specified or `ebnf-eps-header' has a
;;		non-empty string value.
;;
;;    ;Ffooter	generate a footer in current EPS file.  Similar to ;H action
;;		comment.
;;
Gerd Moellmann's avatar
Gerd Moellmann committed
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
;; So if you have:
;;
;;    (setq ebnf-horizontal-orientation nil)
;;
;;    A = t.
;;    C = x.
;;    ;> C and B are drawn in the same line
;;    B = y.
;;    W = v.
;;
;; The graphical result is:
;;
;;    +---+
;;    | A |
;;    +---+
;;
;;    +---------+   +-----+
;;    |         |   |     |
;;    |    C    |   |     |
;;    |         |   |  B  |
;;    +---------+   |     |
;;                  |     |
;;                  +-----+
;;
;;    +-----------+
;;    |     W     |
;;    +-----------+
;;
;; Note that if ascending production sort is used, the productions A and B will
;; be drawn in the same line instead of C and B.
;;
500 501
;; If consecutive actions occur, only the last one takes effect, so if you
;; have:
Gerd Moellmann's avatar
Gerd Moellmann committed
502 503 504 505 506 507 508 509 510 511
;;
;;    A = X.
;;    ;<
;;    ^L
;;    ;>
;;    B = Y.
;;
;; Only the ;> will take effect, that is, A and B will be drawn in the same
;; line.
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
512 513
;; In ISO EBNF the above actions are specified as (*^*), (*>*), (*<*), (*[EPS*)
;; and (*]EPS*).  The first example above should be written:
Gerd Moellmann's avatar
Gerd Moellmann committed
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
;;
;;    A = t;
;;    C = x;
;;    (*> C and B are drawn in the same line *)
;;    B = y;
;;    W = v;
;;
;; For an example of EPS action when executing `ebnf-eps-buffer' or
;; `ebnf-eps-region':
;;
;;    Z = B0.
;;    ;[CC
;;    ;[AA
;;    A = B1.
;;    ;[BB
;;    C = B2.
;;    ;]AA
;;    B = B3.
;;    ;]BB
;;    ;]CC
;;    D = B4.
;;    E = B5.
;;    ;[CC
;;    F = B6.
;;    ;]CC
;;    G = B7.
;;
;; The following table summarizes the results:
;;
543 544 545 546 547 548 549 550
;;    EPS FILE NAME    NO SORT    ASCENDING SORT    DESCENDING SORT
;;    ebnf--AA.eps     A C        A C               C A
;;    ebnf--BB.eps     C B        B C               C B
;;    ebnf--CC.eps     A C B F    A B C F           F C B A
;;    ebnf--D.eps      D          D                 D
;;    ebnf--E.eps      E          E                 E
;;    ebnf--G.eps      G          G                 G
;;    ebnf--Z.eps      Z          Z                 Z
Gerd Moellmann's avatar
Gerd Moellmann committed
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
;;
;; As you can see if EPS actions is not used, each single production is
;; generated per EPS file.  To avoid overriding EPS files, use names in ;[ that
;; it's not an existing production name.
;;
;; In the following case:
;;
;;    A = B0.
;;    ;[AA
;;    A = B1.
;;    ;[BB
;;    A = B2.
;;
;; The production A is generated in both files ebnf--AA.eps and ebnf--BB.eps.
;;
;;
567 568 569 570 571 572 573 574 575 576
;; Log Messages
;; ------------
;;
;; The buffer *Ebnf2ps Log* is where the ebnf2ps log messages are inserted.
;; These messages are intended to help debugging ebnf2ps.
;;
;; The log messages are enabled by `ebnf-log' option (which see).  The default
;; value is nil, that is, no log messages are generated.
;;
;;
Gerd Moellmann's avatar
Gerd Moellmann committed
577 578 579 580 581 582 583
;; Utilities
;; ---------
;;
;; Some tools are provided to help you.
;;
;; `ebnf-setup' returns the current setup.
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
584 585 586 587 588 589
;; `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.
;;
Juanma Barranquero's avatar
Juanma Barranquero committed
590
;; `ebnf-syntax-buffer' does a syntactic analysis of your EBNF in the current
Gerd Moellmann's avatar
Gerd Moellmann committed
591 592
;; buffer.
;;
Juanma Barranquero's avatar
Juanma Barranquero committed
593
;; `ebnf-syntax-region' does a syntactic analysis of your EBNF in the current
Gerd Moellmann's avatar
Gerd Moellmann committed
594 595 596 597
;; region.
;;
;; `ebnf-customize' activates a customization buffer for ebnf2ps options.
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
598 599 600
;; `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.
Gerd Moellmann's avatar
Gerd Moellmann committed
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632
;;
;;
;; Hooks
;; -----
;;
;; ebn2ps has the following hook variables:
;;
;; `ebnf-hook'
;;    It is evaluated once before any ebnf2ps process.
;;
;; `ebnf-production-hook'
;;    It is evaluated on each beginning of production.
;;
;; `ebnf-page-hook'
;;    It is evaluated on each beginning of page.
;;
;;
;; Options
;; -------
;;
;; Below it's shown a brief description of ebnf2ps options, please, see the
;; options declaration in the code for a long documentation.
;;
;; `ebnf-horizontal-orientation'	Non-nil means productions are drawn
;;					horizontally.
;;
;; `ebnf-horizontal-max-height'		Non-nil means to use maximum production
;;					height in horizontal orientation.
;;
;; `ebnf-production-horizontal-space'	Specify horizontal space in points
;;					between productions.
;;
633 634
;; `ebnf-production-vertical-space'	Specify vertical space in points
;;					between productions.
Gerd Moellmann's avatar
Gerd Moellmann committed
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
;;
;; `ebnf-justify-sequence'		Specify justification of terms in a
;;					sequence inside alternatives.
;;
;; `ebnf-terminal-regexp'		Specify how it's a terminal name.
;;
;; `ebnf-case-fold-search'		Non-nil means ignore case on matching.
;;
;; `ebnf-terminal-font'			Specify terminal font.
;;
;; `ebnf-terminal-shape'		Specify terminal box shape.
;;
;; `ebnf-terminal-shadow'		Non-nil means terminal box will have a
;;					shadow.
;;
;; `ebnf-terminal-border-width'		Specify border width for terminal box.
;;
;; `ebnf-terminal-border-color'		Specify border color for terminal box.
;;
654 655 656
;; `ebnf-production-name-p'		Non-nil means production name will be
;;					printed.
;;
Gerd Moellmann's avatar
Gerd Moellmann committed
657 658 659 660 661 662 663 664
;; `ebnf-sort-production'		Specify how productions are sorted.
;;
;; `ebnf-production-font'		Specify production font.
;;
;; `ebnf-non-terminal-font'		Specify non-terminal font.
;;
;; `ebnf-non-terminal-shape'		Specify non-terminal box shape.
;;
665 666
;; `ebnf-non-terminal-shadow'		Non-nil means non-terminal box will
;;					have a shadow.
Gerd Moellmann's avatar
Gerd Moellmann committed
667 668 669 670 671 672 673
;;
;; `ebnf-non-terminal-border-width'	Specify border width for non-terminal
;;					box.
;;
;; `ebnf-non-terminal-border-color'	Specify border color for non-terminal
;;					box.
;;
674 675 676
;; `ebnf-special-show-delimiter'	Non-nil means special delimiter
;;					(character `?') is shown.
;;
Gerd Moellmann's avatar
Gerd Moellmann committed
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721
;; `ebnf-special-font'			Specify special font.
;;
;; `ebnf-special-shape'			Specify special box shape.
;;
;; `ebnf-special-shadow'		Non-nil means special box will have a
;;					shadow.
;;
;; `ebnf-special-border-width'		Specify border width for special box.
;;
;; `ebnf-special-border-color'		Specify border color for special box.
;;
;; `ebnf-except-font'			Specify except font.
;;
;; `ebnf-except-shape'			Specify except box shape.
;;
;; `ebnf-except-shadow'			Non-nil means except box will have a
;;					shadow.
;;
;; `ebnf-except-border-width'		Specify border width for except box.
;;
;; `ebnf-except-border-color'		Specify border color for except box.
;;
;; `ebnf-repeat-font'			Specify repeat font.
;;
;; `ebnf-repeat-shape'			Specify repeat box shape.
;;
;; `ebnf-repeat-shadow'			Non-nil means repeat box will have a
;;					shadow.
;;
;; `ebnf-repeat-border-width'		Specify border width for repeat box.
;;
;; `ebnf-repeat-border-color'		Specify border color for repeat box.
;;
;; `ebnf-entry-percentage'		Specify entry height on alternatives.
;;
;; `ebnf-arrow-shape'			Specify the arrow shape.
;;
;; `ebnf-chart-shape'			Specify chart flow shape.
;;
;; `ebnf-color-p'			Non-nil means use color.
;;
;; `ebnf-line-width'			Specify flow line width.
;;
;; `ebnf-line-color'			Specify flow line color.
;;
722 723 724 725 726
;; `ebnf-arrow-extra-width'		Specify extra width for arrow shape
;;					drawing.
;;
;; `ebnf-arrow-scale'			Specify the arrow scale.
;;
Gerd Moellmann's avatar
Gerd Moellmann committed
727
;; `ebnf-user-arrow'			Specify a sexp for user arrow shape (a
728
;;					PostScript code).
Gerd Moellmann's avatar
Gerd Moellmann committed
729 730 731 732 733 734
;;
;; `ebnf-debug-ps'			Non-nil means to generate PostScript
;;					debug procedures.
;;
;; `ebnf-lex-comment-char'		Specify the line comment character.
;;
735 736
;; `ebnf-lex-eop-char'			Specify the end of production
;;					character.
Gerd Moellmann's avatar
Gerd Moellmann committed
737 738 739 740 741 742 743 744 745 746 747 748
;;
;; `ebnf-syntax'			Specify syntax to be recognized.
;;
;; `ebnf-iso-alternative-p'		Non-nil means use alternative ISO EBNF.
;;
;; `ebnf-iso-normalize-p'		Non-nil means normalize ISO EBNF syntax
;;					names.
;;
;; `ebnf-default-width'			Specify additional border width over
;;					default terminal, non-terminal or
;;					special.
;;
749 750 751
;; `ebnf-file-suffix-regexp'		Specify file name suffix that contains
;;					EBNF.
;;
Gerd Moellmann's avatar
Gerd Moellmann committed
752 753
;; `ebnf-eps-prefix'			Specify EPS prefix file name.
;;
754 755 756 757 758 759 760 761
;; `ebnf-eps-header-font'		Specify EPS header font.
;;
;; `ebnf-eps-header'			Specify EPS header.
;;
;; `ebnf-eps-footer-font'		Specify EPS footer font.
;;
;; `ebnf-eps-footer'			Specify EPS footer.
;;
Gerd Moellmann's avatar
Gerd Moellmann committed
762 763
;; `ebnf-use-float-format'		Non-nil means use `%f' float format.
;;
764 765 766
;; `ebnf-stop-on-error'			Non-nil means signal error and stop.
;;					Nil means signal error and continue.
;;
Gerd Moellmann's avatar
Gerd Moellmann committed
767 768 769 770
;; `ebnf-yac-ignore-error-recovery'	Non-nil means ignore error recovery.
;;
;; `ebnf-ignore-empty-rule'		Non-nil means ignore empty rules.
;;
Juanma Barranquero's avatar
Juanma Barranquero committed
771
;; `ebnf-optimize'			Non-nil means optimize syntactic chart
772
;;					of rules.
Gerd Moellmann's avatar
Gerd Moellmann committed
773
;;
774 775
;; `ebnf-log'				Non-nil means generate log messages.
;;
Gerd Moellmann's avatar
Gerd Moellmann committed
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827
;; To set the above options you may:
;;
;; a) insert the code in your ~/.emacs, like:
;;
;;	 (setq ebnf-terminal-shape 'bevel)
;;
;;    This way always keep your default settings when you enter a new Emacs
;;    session.
;;
;; b) or use `set-variable' in your Emacs session, like:
;;
;;	 M-x set-variable RET ebnf-terminal-shape RET bevel RET
;;
;;    This way keep your settings only during the current Emacs session.
;;
;; c) or use customization, for example:
;;	 click on menu-bar *Help* option,
;;	 then click on *Customize*,
;;	 then click on *Browse Customization Groups*,
;;	 expand *PostScript* group,
;;	 expand *Ebnf2ps* group
;;	 and then customize ebnf2ps options.
;;    Through this way, you may choose if the settings are kept or not when
;;    you leave out the current Emacs session.
;;
;; d) or see the option value:
;;
;;	 C-h v ebnf-terminal-shape RET
;;
;;    and click the *customize* hypertext button.
;;    Through this way, you may choose if the settings are kept or not when
;;    you leave out the current Emacs session.
;;
;; e) or invoke:
;;
;;	 M-x ebnf-customize RET
;;
;;    and then customize ebnf2ps options.
;;    Through this way, you may choose if the settings are kept or not when
;;    you leave out the current Emacs session.
;;
;;
;; Styles
;; ------
;;
;; Sometimes you need to change the EBNF style you are using, for example,
;; change the shapes and colors.  These changes may force you to set some
;; variables and after use, set back the variables to the old values.
;;
;; To help to handle this situation, ebnf2ps has the following commands to
;; handle styles:
;;
828 829 830
;; `ebnf-find-style'	Return style definition if NAME is already defined;
;;			otherwise, return nil.
;;
Gerd Moellmann's avatar
Gerd Moellmann committed
831 832 833
;; `ebnf-insert-style'	Insert a new style NAME with inheritance INHERITS and
;;			values VALUES.
;;
834 835
;; `ebnf-delete-style'	Delete style NAME.
;;
Gerd Moellmann's avatar
Gerd Moellmann committed
836 837
;; `ebnf-merge-style'	Merge values of style NAME with style VALUES.
;;
838
;; `ebnf-apply-style'	Set STYLE as the current style.
Gerd Moellmann's avatar
Gerd Moellmann committed
839 840 841
;;
;; `ebnf-reset-style'	Reset current style.
;;
842
;; `ebnf-push-style'	Push the current style and set STYLE as the current
843
;;			style.
Gerd Moellmann's avatar
Gerd Moellmann committed
844
;;
845
;; `ebnf-pop-style'	Pop a style and set it as the current style.
Gerd Moellmann's avatar
Gerd Moellmann committed
846
;;
847
;; These commands help to put together a lot of variable settings in a group
Gerd Moellmann's avatar
Gerd Moellmann committed
848 849 850
;; and name this group.  So when you wish to apply these settings it's only
;; needed to give the name.
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
851 852 853 854
;; There is also a notion of simple inheritance of style: if you declare that
;; style A inherits from style B, all settings of B are applied first and then
;; the settings of A are applied.  This is useful when you wish to modify some
;; aspects of an existing style, but at same time wish to keep it unmodified.
Gerd Moellmann's avatar
Gerd Moellmann committed
855 856 857 858 859 860 861 862 863 864 865 866 867
;;
;; See documentation for `ebnf-style-database'.
;;
;;
;; Layout
;; ------
;;
;; Below it is the layout of minimum area to draw each element, and it's used
;; the following terms:
;;
;;    font height	is given by:
;;			(terminal font height + non-terminal font height) / 2
;;
868 869
;;    entry		is the vertical position used to know where it should
;;			be drawn the flow line in the current element.
Gerd Moellmann's avatar
Gerd Moellmann committed
870
;;
871 872
;;    extra		is given by `ebnf-arrow-extra-width'.
;;
Gerd Moellmann's avatar
Gerd Moellmann committed
873 874 875 876 877 878 879 880 881 882 883
;;
;;    * SPECIAL, TERMINAL and NON-TERMINAL
;;
;;           +==============+...................................
;;           |              |      } font height / 2  } entry  }
;;           |   XXXXXXXX...|.......                  }        }
;;       ====+   XXXXXXXX   +====  } text height ......        } height
;;       :   |   XXXXXXXX...|...:...                           }
;;       :   |   :      :   |   :  } font height / 2           }
;;       :   +==============+...:...............................
;;       :   :   :      :   :   :
884 885 886 887 888 889 890 891 892 893 894
;;       :   :   :      :   :   :.........................
;;       :   :   :      :   :      } font height          }
;;       :   :   :      :   :.......                      }
;;       :   :   :      :          } font height / 2      }
;;       :   :   :      :...........                      }
;;       :   :   :                 } text width           } width
;;       :   :   :..................                      }
;;       :   :                     } font height / 2      }
;;       :   :......................                      }
;;       :                         } font height + extra  }
;;       :.................................................
Gerd Moellmann's avatar
Gerd Moellmann committed
895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024
;;
;;
;;    * OPTIONAL
;;
;;              +==========+.....................................
;;              |          |         }        }                 }
;;              |          |         } entry  }                 }
;;              |          |         }        }                 }
;;       ===+===+          +===+===...        } element height  } height
;;       :   \  |          |  /   :           }                 }
;;       :    + |          | +    :           }                 }
;;       :    | +==========+.|.................                 }
;;       :    | :          : |    :           } font height     }
;;       :    +==============+...................................
;;       :      :          :      :
;;       :      :          :      :......................
;;       :      :          :         } font height * 2  }
;;       :      :          :..........                  }
;;       :      :                    } element width    } width
;;       :      :.....................                  }
;;       :                           } font height * 2  }
;;       :...............................................
;;
;;
;;    * ALTERNATIVE
;;
;;               +===+...................................
;;            +==+ A +==+       } A height     }        }
;;            |  +===+..|........              } entry  }
;;            +         +       } font height  }        }
;;           /   +===+...\.......              }        }
;;       ===+====+ B +====+===  } B height .....        } height
;;       :   \   +===+.../.......                       }
;;       :    +         +    :  } font height           }
;;       :    |  +===+..|........                       }
;;       :    +==+ C +==+    :  } C height              }
;;       :     : +===+...................................
;;       :     :       :     :
;;       :     :       :     :......................
;;       :     :       :        } font height * 2  }
;;       :     :       :.........                  }
;;       :     :                } max width        } width
;;       :     :.................                  }
;;       :                      } font height * 2  }
;;       :..........................................
;;
;;       NOTES:
;;          1. An empty alternative has zero of height.
;;
;;          2. The variable `ebnf-entry-percentage' is used to determine the
;;             entry point.
;;
;;
;;    * ZERO OR MORE
;;
;;               +===========+...............................
;;             +=+ separator +=+        } separator height  }
;;            /  +===========+..\........                   }
;;           +                   +      }                   }
;;           |                   |      } font height       }
;;           +                   +      }                   }
;;            \  +===========+../........                   } height = entry
;;             +=+ element   +=+        } element height    }
;;            /: +===========+..\........                   }
;;           + :               : +      }                   }
;;           + :               : +      } font height       }
;;          /  :               :  \     }                   }
;;       ==+=======================+==.......................
;;       :     :               :     :
;;       :     :               :     :.......................
;;       :     :               :        } font height * 2   }
;;       :     :               :.........                   }
;;       :     :                        } max width         } width
;;       :     :.........................                   }
;;       :                              } font height * 2   }
;;       :...................................................
;;
;;
;;    * ONE OR MORE
;;
;;            +===========+......................................
;;          +=+ separator +=+      } separator height  }        }
;;         /  +===========+..\......                   }        }
;;        +                   +    }                   } entry  }
;;        |                   |    } font height       }        } height
;;        +                   +    }                   }        }
;;         \  +===========+../......                   }        }
;;       ===+=+ element   +=+===   } element height ....        }
;;       :  : +===========+......................................
;;       :  :               :  :
;;       :  :               :  :........................
;;       :  :               :      } font height * 2   }
;;       :  :               :.......                   }
;;       :  :                      } max width         } width
;;       :  :.......................                   }
;;       :                         } font height * 2   }
;;       :..............................................
;;
;;
;;    * PRODUCTION
;;
;;       XXXXXX:......................................
;;       XXXXXX:           } production font height  }
;;       XXXXXX:............                         }
;;                         } font height             }
;;           +======+.......                         } height = entry
;;           |      |      }                         }
;;       ====+      +====  } element height          }
;;       :   |      |   :  }                         }
;;       :   +======+.................................
;;       :   :      :   :
;;       :   :      :   :......................
;;       :   :      :      } font height * 2  }
;;       :   :      :.......                  }
;;       :   :             } element width    } width
;;       :   :..............                  }
;;       :                 } font height * 2  }
;;       :.....................................
;;
;;
;;    * REPEAT
;;
;;           +================+...................................
;;           |                |      } font height / 2  } entry  }
;;           |        +===+...|.......                  }        }
;;       ====+  N *   | X |   +====  } X height .........        } height
;;       :   |  :  :  +===+...|...:...                           }
;;       :   |  :  :  :   :   |   :  } font height / 2           }
;;       :   +================+...:...............................
;;       :   :  :  :  :   :   :   :
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039
;;       :   :  :  :  :   :   :   :..........................
;;       :   :  :  :  :   :   :      } font height          }
;;       :   :  :  :  :   :   :.......                      }
;;       :   :  :  :  :   :          } font height / 2      }
;;       :   :  :  :  :   :...........                      }
;;       :   :  :  :  :              } X width              }
;;       :   :  :  :  :...............                      }
;;       :   :  :  :                 } font height / 2      } width
;;       :   :  :  :..................                      }
;;       :   :  :                    } text width           }
;;       :   :  :.....................                      }
;;       :   :                       } font height / 2      }
;;       :   :........................                      }
;;       :                           } font height + extra  }
;;       :...................................................
Gerd Moellmann's avatar
Gerd Moellmann committed
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
;;
;;
;;    * EXCEPT
;;
;;           +==================+...................................
;;           |                  |      } font height / 2  } entry  }
;;           |  +===+   +===+...|.......                  }        }
;;       ====+  | X | - | y |   +====  } max height .......        } height
;;       :   |  +===+   +===+...|...:...                           }
;;       :   |  :   :   :   :   |   :  } font height / 2           }
;;       :   +==================+...:...............................
;;       :   :  :   :   :   :   :   :
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
;;       :   :  :   :   :   :   :   :..........................
;;       :   :  :   :   :   :   :      } font height          }
;;       :   :  :   :   :   :   :.......                      }
;;       :   :  :   :   :   :          } font height / 2      }
;;       :   :  :   :   :   :...........                      }
;;       :   :  :   :   :              } Y width              }
;;       :   :  :   :   :...............                      }
;;       :   :  :   :                  } font height          } width
;;       :   :  :   :...................                      }
;;       :   :  :                      } X width              }
;;       :   :  :.......................                      }
;;       :   :                         } font height / 2      }
;;       :   :..........................                      }
;;       :                             } font height + extra  }
;;       :.....................................................
Gerd Moellmann's avatar
Gerd Moellmann committed
1067 1068 1069 1070 1071 1072 1073
;;
;;       NOTE: If Y element is empty, it's draw nothing at Y place.
;;
;;
;; Internal Structures
;; -------------------
;;
Juanma Barranquero's avatar
Juanma Barranquero committed
1074
;; ebnf2ps has two passes.  The first pass does a lexical and syntactic analysis
Gerd Moellmann's avatar
Gerd Moellmann committed
1075
;; of current buffer and generates an intermediate representation.  The second
1076
;; pass uses the intermediate representation to generate the PostScript
Juanma Barranquero's avatar
Juanma Barranquero committed
1077
;; syntactic chart.
Gerd Moellmann's avatar
Gerd Moellmann committed
1078 1079
;;
;; The intermediate representation is a list of vectors, the vector element
Juanma Barranquero's avatar
Juanma Barranquero committed
1080 1081
;; represents a syntactic chart element.  Below is a vector representation for
;; each syntactic chart element.
Gerd Moellmann's avatar
Gerd Moellmann committed
1082
;;
1083
;; [production   WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH NAME   PRODUCTION ACTION]
Gerd Moellmann's avatar
Gerd Moellmann committed
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
;; [alternative  WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH LIST]
;; [sequence     WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH LIST]
;; [terminal     WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH NAME    DEFAULT]
;; [non-terminal WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH NAME    DEFAULT]
;; [special      WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH NAME    DEFAULT]
;; [empty        WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH]
;; [optional     WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH ELEMENT]
;; [one-or-more  WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH ELEMENT SEPARATOR]
;; [zero-or-more WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH ELEMENT SEPARATOR]
;; [repeat       WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH TIMES   ELEMENT]
;; [except       WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH ELEMENT ELEMENT]
;;
;; The first vector position is a function symbol used to generate PostScript
;; for this element.
;; WIDTH-FUN is a function symbol called to adjust the element width.
;; DIM-FUN is a function symbol called to set the element dimensions.
;; ENTRY is the element entry point.
;; HEIGHT and WIDTH are the element height and width, respectively.
;; NAME is a string that it's the element name.
;; DEFAULT is a boolean that indicates if it's a `default' element.
;; PRODUCTION and ELEMENT are vectors that represents sub-elements of current
;; one.
;; LIST is a list of vector that represents the list part for alternatives and
;; sequences.
;; SEPARATOR is a vector that represents the sub-element used to separate the
;; list elements.
;; TIMES is a string representing the number of times that ELEMENT is repeated
;; on a repeat construction.
;; ACTION indicates some action that should be done before production is
;; generated.  The current actions are:
;;
;;    nil		no action.
;;
;;    form-feed		current production starts on a new page.
;;
;;    newline		current production starts on next line, this is useful
;;			when `ebnf-horizontal-orientation' is non-nil.
;;
;;    keep-line		current production continues on the current line, this
;;			is useful when `ebnf-horizontal-orientation' is nil.
;;
;;
;; Things To Change
;; ----------------
;;
Juanma Barranquero's avatar
Juanma Barranquero committed
1129
;; . Handle situations when syntactic chart is out of paper.
Gerd Moellmann's avatar
Gerd Moellmann committed
1130 1131 1132 1133 1134 1135 1136
;; . Use other alphabet than ascii.
;; . Optimizations...
;;
;;
;; Acknowledgements
;; ----------------
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1137 1138
;; Thanks to Eli Zaretskii <eliz@gnu.org> for some doc fixes.
;;
1139
;; Thanks to Drew Adams <drew.adams@oracle.com> for suggestions:
1140 1141
;;    - `ebnf-arrow-extra-width', `ebnf-arrow-scale',
;;	`ebnf-production-name-p', `ebnf-stop-on-error',
1142 1143 1144 1145 1146 1147 1148 1149 1150
;;	`ebnf-file-suffix-regexp'and `ebnf-special-show-delimiter' variables.
;;    - `ebnf-delete-style', `ebnf-eps-file' and `ebnf-eps-directory'
;;	commands.
;;    - some docs fix.
;;
;; Thanks to Matthew K. Junker <junker@alum.mit.edu> for the suggestion to deal
;; with some Bison features (%right, %left and %prec pragmas).  His suggestion
;; was extended to deal with %nonassoc pragma too.
;;
Gerd Moellmann's avatar
Gerd Moellmann committed
1151 1152 1153 1154 1155
;; Thanks to all who emailed comments.
;;
;;
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

1156
;;; Code:
Gerd Moellmann's avatar
Gerd Moellmann committed
1157 1158 1159 1160


(require 'ps-print)

1161 1162
(and (string< ps-print-version "5.2.3")
     (error "`ebnf2ps' requires `ps-print' package version 5.2.3 or later"))
Gerd Moellmann's avatar
Gerd Moellmann committed
1163

1164 1165

;; to avoid gripes with Emacs 20
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1166 1167 1168
(or (fboundp 'assq-delete-all)
    (defun assq-delete-all (key alist)
      "Delete from ALIST all elements whose car is KEY.
1169 1170
Return the modified alist.
Elements of ALIST that are not conses are ignored."
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1171 1172 1173 1174 1175 1176 1177
      (let ((tail alist))
	(while tail
	  (if (and (consp (car tail))
		   (eq (car (car tail)) key))
	      (setq alist (delq (car tail) alist)))
	  (setq tail (cdr tail)))
	alist)))
1178

Gerd Moellmann's avatar
Gerd Moellmann committed
1179 1180 1181 1182 1183 1184 1185 1186

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; User Variables:


;;; Interface to the command system

(defgroup postscript nil
1187
  "PostScript Group."
Gerd Moellmann's avatar
Gerd Moellmann committed
1188
  :tag "PostScript"
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1189
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1190 1191 1192 1193
  :group 'emacs)


(defgroup ebnf2ps nil
1194
  "Translate an EBNF to a syntactic chart on PostScript."
Gerd Moellmann's avatar
Gerd Moellmann committed
1195
  :prefix "ebnf-"
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1196
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1197 1198 1199 1200 1201
  :group 'wp
  :group 'postscript)


(defgroup ebnf-special nil
1202
  "Special customization."
Gerd Moellmann's avatar
Gerd Moellmann committed
1203 1204
  :prefix "ebnf-"
  :tag "Special"
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1205
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1206 1207 1208 1209
  :group 'ebnf2ps)


(defgroup ebnf-except nil
1210
  "Except customization."
Gerd Moellmann's avatar
Gerd Moellmann committed
1211 1212
  :prefix "ebnf-"
  :tag "Except"
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1213
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1214 1215 1216 1217
  :group 'ebnf2ps)


(defgroup ebnf-repeat nil
1218
  "Repeat customization."
Gerd Moellmann's avatar
Gerd Moellmann committed
1219 1220
  :prefix "ebnf-"
  :tag "Repeat"
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1221
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1222 1223 1224 1225
  :group 'ebnf2ps)


(defgroup ebnf-terminal nil
1226
  "Terminal customization."
Gerd Moellmann's avatar
Gerd Moellmann committed
1227 1228
  :prefix "ebnf-"
  :tag "Terminal"
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1229
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1230 1231 1232 1233
  :group 'ebnf2ps)


(defgroup ebnf-non-terminal nil
1234
  "Non-Terminal customization."
Gerd Moellmann's avatar
Gerd Moellmann committed
1235 1236
  :prefix "ebnf-"
  :tag "Non-Terminal"
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1237
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1238 1239 1240 1241
  :group 'ebnf2ps)


(defgroup ebnf-production nil
1242
  "Production customization."
Gerd Moellmann's avatar
Gerd Moellmann committed
1243 1244
  :prefix "ebnf-"
  :tag "Production"
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1245
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1246 1247 1248 1249
  :group 'ebnf2ps)


(defgroup ebnf-shape nil
1250
  "Shapes customization."
Gerd Moellmann's avatar
Gerd Moellmann committed
1251 1252
  :prefix "ebnf-"
  :tag "Shape"
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1253
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1254 1255 1256 1257
  :group 'ebnf2ps)


(defgroup ebnf-displacement nil
1258
  "Displacement customization."
Gerd Moellmann's avatar
Gerd Moellmann committed
1259 1260
  :prefix "ebnf-"
  :tag "Displacement"
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1261
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1262 1263 1264
  :group 'ebnf2ps)


Juanma Barranquero's avatar
Juanma Barranquero committed
1265
(defgroup ebnf-syntactic nil
1266
  "Syntactic customization."
Gerd Moellmann's avatar
Gerd Moellmann committed
1267
  :prefix "ebnf-"
Juanma Barranquero's avatar
Juanma Barranquero committed
1268
  :tag "Syntactic"
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1269
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1270 1271 1272 1273
  :group 'ebnf2ps)


(defgroup ebnf-optimization nil
1274
  "Optimization customization."
Gerd Moellmann's avatar
Gerd Moellmann committed
1275 1276
  :prefix "ebnf-"
  :tag "Optimization"
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1277
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1278 1279 1280 1281 1282 1283
  :group 'ebnf2ps)


(defcustom ebnf-horizontal-orientation nil
  "*Non-nil means productions are drawn horizontally."
  :type 'boolean
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1284
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1285 1286 1287 1288 1289 1290 1291 1292
  :group 'ebnf-displacement)


(defcustom ebnf-horizontal-max-height nil
  "*Non-nil means to use maximum production height in horizontal orientation.

It is only used when `ebnf-horizontal-orientation' is non-nil."
  :type 'boolean
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1293
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1294 1295 1296 1297 1298 1299 1300 1301
  :group 'ebnf-displacement)


(defcustom ebnf-production-horizontal-space 0.0 ; use ebnf2ps default value
  "*Specify horizontal space in points between productions.

Value less or equal to zero forces ebnf2ps to set a proper default value."
  :type 'number
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1302
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1303 1304 1305 1306 1307 1308 1309 1310
  :group 'ebnf-displacement)


(defcustom ebnf-production-vertical-space 0.0 ; use ebnf2ps default value
  "*Specify vertical space in points between productions.

Value less or equal to zero forces ebnf2ps to set a proper default value."
  :type 'number
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1311
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324
  :group 'ebnf-displacement)


(defcustom ebnf-justify-sequence 'center
  "*Specify justification of terms in a sequence inside alternatives.

Valid values are:

   `left'		left justification
   `right'		right justification
   any other value	centralize"
  :type '(radio :tag "Sequence Justification"
		(const left) (const right) (other :tag "center" center))
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1325
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1326 1327 1328
  :group 'ebnf-displacement)


1329 1330 1331
(defcustom ebnf-special-show-delimiter t
  "*Non-nil means special delimiter (character `?') is shown."
  :type 'boolean
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1332
  :version "20"
1333 1334 1335
  :group 'ebnf-special)


Gerd Moellmann's avatar
Gerd Moellmann committed
1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353
(defcustom ebnf-special-font '(7 Courier "Black" "Gray95" bold italic)
  "*Specify special font.

See documentation for `ebnf-production-font'."
  :type '(list :tag "Special Font"
	       (number :tag "Font Size")
	       (symbol :tag "Font Name")
	       (choice :tag "Foreground Color"
		       (string :tag "Name")
		       (other :tag "Default" nil))
	       (choice :tag "Background Color"
		       (string :tag "Name")
		       (other :tag "Default" nil))
	       (repeat :tag "Font Attributes" :inline t
		       (choice (const bold)      (const italic)
			       (const underline) (const strikeout)
			       (const overline)  (const shadow)
			       (const box)       (const outline))))
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1354
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1355 1356 1357 1358 1359 1360 1361 1362 1363
  :group 'ebnf-special)


(defcustom ebnf-special-shape 'bevel
  "*Specify special box shape.

See documentation for `ebnf-non-terminal-shape'."
  :type '(radio :tag "Special Shape"
		(const miter) (const round) (const bevel))
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1364
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1365 1366 1367 1368 1369 1370
  :group 'ebnf-special)


(defcustom ebnf-special-shadow nil
  "*Non-nil means special box will have a shadow."
  :type 'boolean
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1371
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1372 1373 1374 1375 1376 1377
  :group 'ebnf-special)


(defcustom ebnf-special-border-width 0.5
  "*Specify border width for special box."
  :type 'number
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1378
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1379 1380 1381 1382 1383 1384
  :group 'ebnf-special)


(defcustom ebnf-special-border-color "Black"
  "*Specify border color for special box."
  :type 'string
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1385
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406
  :group 'ebnf-special)


(defcustom ebnf-except-font '(7 Courier "Black" "Gray90" bold italic)
  "*Specify except font.

See documentation for `ebnf-production-font'."
  :type '(list :tag "Except Font"
	       (number :tag "Font Size")
	       (symbol :tag "Font Name")
	       (choice :tag "Foreground Color"
		       (string :tag "Name")
		       (other :tag "Default" nil))
	       (choice :tag "Background Color"
		       (string :tag "Name")
		       (other :tag "Default" nil))
	       (repeat :tag "Font Attributes" :inline t
		       (choice (const bold)      (const italic)
			       (const underline) (const strikeout)
			       (const overline)  (const shadow)
			       (const box)       (const outline))))
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1407
  :version "20"
Gerd Moellmann's avatar
Gerd Moellmann committed
1408 1409 1410 1411 1412 1413 1414 1415 1416
  :group 'ebnf-except)


(defcustom ebnf-except-shape 'bevel
  "*Specify except box shape.

See documentation for `ebnf-non-terminal-shape'."
  :type '(radio :tag "Except Shape"
		(const miter) (const round) (const bevel))
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1417
  :version "20"