Mercurial > emacs
annotate lisp/progmodes/ebnf2ps.el @ 35241:5d83c58bea03
*** empty log message ***
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Thu, 11 Jan 2001 16:41:38 +0000 |
parents | de1f65fa5dcd |
children | c2604e531b66 |
rev | line source |
---|---|
27451 | 1 ;;; ebnf2ps --- Translate an EBNF to a syntatic chart on PostScript |
2 | |
27539 | 3 ;; Copyright (C) 1999, 2000 Free Software Foundation, Inc. |
27451 | 4 |
5 ;; Author: Vinicius Jose Latorre <vinicius@cpqd.com.br> | |
6 ;; Maintainer: Vinicius Jose Latorre <vinicius@cpqd.com.br> | |
7 ;; Keywords: wp, ebnf, PostScript | |
34803
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
8 ;; Time-stamp: <2000/12/19 15:17:15 vinicius> |
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
9 ;; Version: 3.4 |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
10 ;; X-URL: http://www.cpqd.com.br/~vinicius/emacs/Emacs.html |
27451 | 11 |
27539 | 12 ;; This file is part of GNU Emacs. |
13 | |
14 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
15 ;; it under the terms of the GNU General Public License as published by | |
16 ;; the Free Software Foundation; either version 2, or (at your option) | |
17 ;; any later version. | |
18 | |
19 ;; GNU Emacs is distributed in the hope that it will be useful, | |
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 ;; GNU General Public License for more details. | |
23 | |
24 ;; You should have received a copy of the GNU General Public License | |
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
27 ;; Boston, MA 02111-1307, USA. | |
28 | |
34803
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
29 (defconst ebnf-version "3.4" |
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
30 "ebnf2ps.el, v 3.4 <2000/12/19 vinicius> |
27451 | 31 |
32 Vinicius's last change version. When reporting bugs, please also | |
33 report the version of Emacs, if any, that ebnf2ps was running with. | |
34 | |
35 Please send all bug fixes and enhancements to | |
36 Vinicius Jose Latorre <vinicius@cpqd.com.br>. | |
37 ") | |
38 | |
39 | |
40 ;;; Commentary: | |
41 | |
42 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
43 ;; | |
44 ;; Introduction | |
45 ;; ------------ | |
46 ;; | |
47 ;; This package translates an EBNF to a syntatic chart on PostScript. | |
48 ;; | |
49 ;; To use ebnf2ps, insert in your ~/.emacs: | |
50 ;; | |
51 ;; (require 'ebnf2ps) | |
52 ;; | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
53 ;; ebnf2ps uses ps-print package (version 5.2.3 or later), so see ps-print to |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
54 ;; know how to set options like landscape printing, page headings, margins, |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
55 ;; etc. |
27451 | 56 ;; |
57 ;; NOTE: ps-print zebra stripes and line number options doesn't have effect on | |
58 ;; ebnf2ps, they behave as it's turned off. | |
59 ;; | |
60 ;; For good performance, be sure to byte-compile ebnf2ps.el, e.g. | |
61 ;; | |
62 ;; M-x byte-compile-file <give the path to ebnf2ps.el when prompted> | |
63 ;; | |
64 ;; This will generate ebnf2ps.elc, which will be loaded instead of ebnf2ps.el. | |
65 ;; | |
66 ;; ebnf2ps was tested with GNU Emacs 20.4.1. | |
67 ;; | |
68 ;; | |
69 ;; Using ebnf2ps | |
70 ;; ------------- | |
71 ;; | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
72 ;; ebnf2ps provides six commands for generating PostScript syntatic chart |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
73 ;; images of Emacs buffers: |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
74 ;; |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
75 ;; ebnf-print-buffer |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
76 ;; ebnf-print-region |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
77 ;; ebnf-spool-buffer |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
78 ;; ebnf-spool-region |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
79 ;; ebnf-eps-buffer |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
80 ;; ebnf-eps-region |
27451 | 81 ;; |
82 ;; These commands all perform essentially the same function: they generate | |
83 ;; PostScript syntatic chart images suitable for printing on a PostScript | |
84 ;; printer or displaying with GhostScript. These commands are collectively | |
85 ;; referred to as "ebnf- commands". | |
86 ;; | |
87 ;; The word "print", "spool" and "eps" in the command name determines when the | |
88 ;; PostScript image is sent to the printer (or file): | |
89 ;; | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
90 ;; print - The PostScript image is immediately sent to the printer; |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
91 ;; |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
92 ;; spool - The PostScript image is saved temporarily in an Emacs buffer. |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
93 ;; Many images may be spooled locally before printing them. To |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
94 ;; send the spooled images to the printer, use the command |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
95 ;; `ebnf-despool'. |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
96 ;; |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
97 ;; eps - The PostScript image is immediately sent to a EPS file. |
27451 | 98 ;; |
99 ;; The spooling mechanism is the same as used by ps-print and was designed for | |
100 ;; printing lots of small files to save paper that would otherwise be wasted on | |
101 ;; banner pages, and to make it easier to find your output at the printer (it's | |
102 ;; easier to pick up one 50-page printout than to find 50 single-page | |
103 ;; printouts). As ebnf2ps and ps-print use the same Emacs buffer to spool | |
104 ;; images, you can intermix the spooling of ebnf2ps and ps-print images. | |
105 ;; | |
106 ;; ebnf2ps use the same hook of ps-print in the `kill-emacs-hook' so that you | |
107 ;; won't accidentally quit from Emacs while you have unprinted PostScript | |
108 ;; waiting in the spool buffer. If you do attempt to exit with spooled | |
109 ;; PostScript, you'll be asked if you want to print it, and if you decline, | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
110 ;; you'll be asked to confirm the exit; this is modeled on the confirmation |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
111 ;; that Emacs uses for modified buffers. |
27451 | 112 ;; |
113 ;; The word "buffer" or "region" in the command name determines how much of the | |
114 ;; buffer is printed: | |
115 ;; | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
116 ;; buffer - Print the entire buffer. |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
117 ;; |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
118 ;; region - Print just the current region. |
27451 | 119 ;; |
120 ;; Two ebnf- command examples: | |
121 ;; | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
122 ;; ebnf-print-buffer - translate and print the entire buffer, and send it |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
123 ;; immediately to the printer. |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
124 ;; |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
125 ;; ebnf-spool-region - translate and print just the current region, and |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
126 ;; spool the image in Emacs to send to the printer |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
127 ;; later. |
27451 | 128 ;; |
129 ;; Note that `ebnf-eps-buffer' and `ebnf-eps-region' never spool the EPS image, | |
130 ;; so they don't use the ps-print spooling mechanism. See section "Actions in | |
131 ;; Comments" for an explanation about EPS file generation. | |
132 ;; | |
133 ;; | |
134 ;; Invoking Ebnf2ps | |
135 ;; ---------------- | |
136 ;; | |
137 ;; To translate and print your buffer, type | |
138 ;; | |
139 ;; M-x ebnf-print-buffer | |
140 ;; | |
141 ;; or substitute one of the other four ebnf- commands. The command will | |
142 ;; generate the PostScript image and print or spool it as specified. By giving | |
143 ;; the command a prefix argument | |
144 ;; | |
145 ;; C-u M-x ebnf-print-buffer | |
146 ;; | |
147 ;; it will save the PostScript image to a file instead of sending it to the | |
148 ;; printer; you will be prompted for the name of the file to save the image to. | |
149 ;; The prefix argument is ignored by the commands that spool their images, but | |
150 ;; you may save the spooled images to a file by giving a prefix argument to | |
151 ;; `ebnf-despool': | |
152 ;; | |
153 ;; C-u M-x ebnf-despool | |
154 ;; | |
155 ;; When invoked this way, `ebnf-despool' will prompt you for the name of the | |
156 ;; file to save to. | |
157 ;; | |
158 ;; The prefix argument is also ignored by `ebnf-eps-buffer' and | |
159 ;; `ebnf-eps-region'. | |
160 ;; | |
161 ;; Any of the `ebnf-' commands can be bound to keys. Here are some examples: | |
162 ;; | |
163 ;; (global-set-key 'f22 'ebnf-print-buffer) ;f22 is prsc | |
164 ;; (global-set-key '(shift f22) 'ebnf-print-region) | |
165 ;; (global-set-key '(control f22) 'ebnf-despool) | |
166 ;; | |
167 ;; | |
168 ;; EBNF Syntax | |
169 ;; ----------- | |
170 ;; | |
171 ;; The current EBNF that ebnf2ps accepts has the following constructions: | |
172 ;; | |
173 ;; ; comment (until end of line) | |
174 ;; A non-terminal | |
175 ;; "C" terminal | |
176 ;; ?C? special | |
177 ;; $A default non-terminal (see text below) | |
178 ;; $"C" default terminal (see text below) | |
179 ;; $?C? default special (see text below) | |
180 ;; A = B. production (A is the header and B the body) | |
181 ;; C D sequence (C occurs before D) | |
182 ;; C | D alternative (C or D occurs) | |
183 ;; A - B exception (A excluding B, B without any non-terminal) | |
184 ;; n * A repetition (A repeats n (integer) times) | |
185 ;; (C) group (expression C is grouped together) | |
186 ;; [C] optional (C may or not occurs) | |
187 ;; C+ one or more occurrences of C | |
188 ;; {C}+ one or more occurrences of C | |
189 ;; {C}* zero or more occurrences of C | |
190 ;; {C} zero or more occurrences of C | |
191 ;; C / D equivalent to: C {D C}* | |
192 ;; {C || D}+ equivalent to: C {D C}* | |
193 ;; {C || D}* equivalent to: [C {D C}*] | |
194 ;; {C || D} equivalent to: [C {D C}*] | |
195 ;; | |
196 ;; The EBNF syntax written using the notation above is: | |
197 ;; | |
198 ;; EBNF = {production}+. | |
199 ;; | |
200 ;; production = non_terminal "=" body ".". ;; production | |
201 ;; | |
202 ;; body = {sequence || "|"}*. ;; alternative | |
203 ;; | |
204 ;; sequence = {exception}*. ;; sequence | |
205 ;; | |
206 ;; exception = repeat [ "-" repeat]. ;; exception | |
207 ;; | |
208 ;; repeat = [ integer "*" ] term. ;; repetition | |
209 ;; | |
210 ;; term = factor | |
211 ;; | [factor] "+" ;; one-or-more | |
212 ;; | [factor] "/" [factor] ;; one-or-more | |
213 ;; . | |
214 ;; | |
215 ;; factor = [ "$" ] "\"" terminal "\"" ;; terminal | |
216 ;; | [ "$" ] non_terminal ;; non-terminal | |
217 ;; | [ "$" ] "?" special "?" ;; special | |
218 ;; | "(" body ")" ;; group | |
219 ;; | "[" body "]" ;; zero-or-one | |
220 ;; | "{" body [ "||" body ] "}+" ;; one-or-more | |
221 ;; | "{" body [ "||" body ] "}*" ;; zero-or-more | |
222 ;; | "{" body [ "||" body ] "}" ;; zero-or-more | |
223 ;; . | |
224 ;; | |
225 ;; non_terminal = "[A-Za-z\\240-\\377][!#%&'*-,0-:<>@-Z\\^-z~\\240-\\377]*". | |
226 ;; | |
227 ;; terminal = "\\([^\"\\]\\|\\\\[ -~\\240-\\377]\\)+". | |
228 ;; | |
229 ;; special = "[^?\\n\\000-\\010\\016-\\037\\177-\\237]*". | |
230 ;; | |
231 ;; integer = "[0-9]+". | |
232 ;; | |
233 ;; comment = ";" "[^\\n\\000-\\010\\016-\\037\\177-\\237]*" "\\n". | |
234 ;; | |
235 ;; Try to use the above EBNF to test ebnf2ps. | |
236 ;; | |
237 ;; The `default' terminal, non-terminal and special is a way to indicate a | |
238 ;; default path in a production. For example, the production: | |
239 ;; | |
240 ;; X = [ $A ( B | $C ) | D ]. | |
241 ;; | |
242 ;; Indicates that the default meaning for "X" is "A C" if "X" is empty. | |
243 ;; | |
244 ;; The terminal name is controlled by `ebnf-terminal-regexp' and | |
245 ;; `ebnf-case-fold-search', so it's possible to match other kind of terminal | |
246 ;; name besides that enclosed by `"'. | |
247 ;; | |
248 ;; Let's see an example: | |
249 ;; | |
250 ;; (setq ebnf-terminal-regexp "[A-Z][_A-Z]*") ; upper case name | |
251 ;; (setq ebnf-case-fold-search nil) ; exact matching | |
252 ;; | |
253 ;; If you have the production: | |
254 ;; | |
255 ;; Logical = "(" Expression ( OR | AND | "XOR" ) Expression ")". | |
256 ;; | |
257 ;; The names are classified as: | |
258 ;; | |
259 ;; Logical Expression non-terminal | |
260 ;; "(" OR AND "XOR" ")" terminal | |
261 ;; | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
262 ;; The line comment is controlled by `ebnf-lex-comment-char'. The default |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
263 ;; value is ?\; (character `;'). |
27451 | 264 ;; |
265 ;; The end of production is controlled by `ebnf-lex-eop-char'. The default | |
266 ;; value is ?. (character `.'). | |
267 ;; | |
268 ;; The variable `ebnf-syntax' specifies which syntax to recognize: | |
269 ;; | |
270 ;; `ebnf' ebnf2ps recognizes the syntax described above. | |
271 ;; The following variables *ONLY* have effect with this | |
272 ;; setting: | |
273 ;; `ebnf-terminal-regexp', `ebnf-case-fold-search', | |
274 ;; `ebnf-lex-comment-char' and `ebnf-lex-eop-char'. | |
275 ;; | |
276 ;; `iso-ebnf' ebnf2ps recognizes the syntax described in the URL: | |
277 ;; `http://www.cl.cam.ac.uk/~mgk25/iso-ebnf.html' | |
278 ;; ("International Standard of the ISO EBNF Notation"). | |
279 ;; The following variables *ONLY* have effect with this | |
280 ;; setting: | |
281 ;; `ebnf-iso-alternative-p' and `ebnf-iso-normalize-p'. | |
282 ;; | |
283 ;; `yacc' ebnf2ps recognizes the Yacc/Bison syntax. | |
284 ;; The following variable *ONLY* has effect with this | |
285 ;; setting: | |
286 ;; `ebnf-yac-ignore-error-recovery'. | |
287 ;; | |
288 ;; Any other value is treated as `ebnf'. | |
289 ;; | |
290 ;; The default value is `ebnf'. | |
291 ;; | |
292 ;; | |
293 ;; Optimizations | |
294 ;; ------------- | |
295 ;; | |
296 ;; The following EBNF optimizations are done: | |
297 ;; | |
298 ;; [ { A }* ] ==> { A }* | |
299 ;; [ { A }+ ] ==> { A }* | |
300 ;; [ A ] + ==> { A }* | |
301 ;; { A }* + ==> { A }* | |
302 ;; { A }+ + ==> { A }+ | |
303 ;; { A }- ==> { A }+ | |
304 ;; [ A ]- ==> A | |
305 ;; ( A | EMPTY )- ==> A | |
306 ;; ( A | B | EMPTY )- ==> A | B | |
307 ;; [ A | B ] ==> A | B | EMPTY | |
308 ;; n * EMPTY ==> EMPTY | |
309 ;; EMPTY + ==> EMPTY | |
310 ;; EMPTY / EMPTY ==> EMPTY | |
311 ;; EMPTY - A ==> EMPTY | |
312 ;; | |
313 ;; The following optimizations are done when `ebnf-optimize' is non-nil: | |
314 ;; | |
315 ;; left recursion: | |
316 ;; 1. A = B | A C. ==> A = B {C}*. | |
317 ;; 2. A = B | A B. ==> A = {B}+. | |
318 ;; 3. A = | A B. ==> A = {B}*. | |
319 ;; 4. A = B | A C B. ==> A = {B || C}+. | |
320 ;; 5. A = B | D | A C | A E. ==> A = ( B | D ) { C | E }*. | |
321 ;; | |
322 ;; optional: | |
323 ;; 6. A = B | . ==> A = [B]. | |
324 ;; 7. A = | B . ==> A = [B]. | |
325 ;; | |
326 ;; factoration: | |
327 ;; 8. A = B C | B D. ==> A = B (C | D). | |
328 ;; 9. A = C B | D B. ==> A = (C | D) B. | |
329 ;; 10. A = B C E | B D E. ==> A = B (C | D) E. | |
330 ;; | |
331 ;; The above optimizations are specially useful when `ebnf-syntax' is `yacc'. | |
332 ;; | |
333 ;; | |
334 ;; Form Feed | |
335 ;; --------- | |
336 ;; | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
337 ;; You may use form feed (^L \014) to force a production to start on a new |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
338 ;; page, for example: |
27451 | 339 ;; |
340 ;; a) A = B | C. | |
341 ;; ^L | |
342 ;; X = Y | Z. | |
343 ;; | |
344 ;; b) A = B ^L | C. | |
345 ;; X = Y | Z. | |
346 ;; | |
347 ;; c) A = B ^L^L^L | C.^L | |
348 ;; ^L | |
349 ;; X = Y | Z. | |
350 ;; | |
351 ;; In all examples above, only the production X will start on a new page. | |
352 ;; | |
353 ;; | |
354 ;; Actions in Comments | |
355 ;; ------------------- | |
356 ;; | |
357 ;; ebnf2ps accepts the following actions in comments: | |
358 ;; | |
359 ;; ;> the next production starts in the same line as the current one. | |
360 ;; It is useful when `ebnf-horizontal-orientation' is nil. | |
361 ;; | |
362 ;; ;< the next production starts in the next line. | |
363 ;; It is useful when `ebnf-horizontal-orientation' is non-nil. | |
364 ;; | |
365 ;; ;[EPS open a new EPS file. The EPS file name has the form: | |
366 ;; <PREFIX><NAME>.eps | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
367 ;; where <PREFIX> is given by variable `ebnf-eps-prefix' and |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
368 ;; <NAME> is the string given by ;[ action comment, this string is |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
369 ;; mapped to form a valid file name (see documentation for |
27451 | 370 ;; `ebnf-eps-buffer' or `ebnf-eps-region'). |
371 ;; It has effect only during `ebnf-eps-buffer' or | |
372 ;; `ebnf-eps-region' execution. | |
373 ;; It's an error to try to open an already opened EPS file. | |
374 ;; | |
375 ;; ;]EPS close an opened EPS file. | |
376 ;; It has effect only during `ebnf-eps-buffer' or | |
377 ;; `ebnf-eps-region' execution. | |
378 ;; It's an error to try to close a not opened EPS file. | |
379 ;; | |
380 ;; So if you have: | |
381 ;; | |
382 ;; (setq ebnf-horizontal-orientation nil) | |
383 ;; | |
384 ;; A = t. | |
385 ;; C = x. | |
386 ;; ;> C and B are drawn in the same line | |
387 ;; B = y. | |
388 ;; W = v. | |
389 ;; | |
390 ;; The graphical result is: | |
391 ;; | |
392 ;; +---+ | |
393 ;; | A | | |
394 ;; +---+ | |
395 ;; | |
396 ;; +---------+ +-----+ | |
397 ;; | | | | | |
398 ;; | C | | | | |
399 ;; | | | B | | |
400 ;; +---------+ | | | |
401 ;; | | | |
402 ;; +-----+ | |
403 ;; | |
404 ;; +-----------+ | |
405 ;; | W | | |
406 ;; +-----------+ | |
407 ;; | |
408 ;; Note that if ascending production sort is used, the productions A and B will | |
409 ;; be drawn in the same line instead of C and B. | |
410 ;; | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
411 ;; If consecutive actions occur, only the last one takes effect, so if you |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
412 ;; have: |
27451 | 413 ;; |
414 ;; A = X. | |
415 ;; ;< | |
416 ;; ^L | |
417 ;; ;> | |
418 ;; B = Y. | |
419 ;; | |
420 ;; Only the ;> will take effect, that is, A and B will be drawn in the same | |
421 ;; line. | |
422 ;; | |
423 ;; In ISO EBNF the above actions are specified as (*>*), (*<*), (*[EPS*) and | |
424 ;; (*]EPS*). The first example above should be written: | |
425 ;; | |
426 ;; A = t; | |
427 ;; C = x; | |
428 ;; (*> C and B are drawn in the same line *) | |
429 ;; B = y; | |
430 ;; W = v; | |
431 ;; | |
432 ;; For an example of EPS action when executing `ebnf-eps-buffer' or | |
433 ;; `ebnf-eps-region': | |
434 ;; | |
435 ;; Z = B0. | |
436 ;; ;[CC | |
437 ;; ;[AA | |
438 ;; A = B1. | |
439 ;; ;[BB | |
440 ;; C = B2. | |
441 ;; ;]AA | |
442 ;; B = B3. | |
443 ;; ;]BB | |
444 ;; ;]CC | |
445 ;; D = B4. | |
446 ;; E = B5. | |
447 ;; ;[CC | |
448 ;; F = B6. | |
449 ;; ;]CC | |
450 ;; G = B7. | |
451 ;; | |
452 ;; The following table summarizes the results: | |
453 ;; | |
454 ;; EPS FILE NAME NO SORT ASCENDING SORT DESCENDING SORT | |
455 ;; ebnf--AA.eps A C A C C A | |
456 ;; ebnf--BB.eps C B B C C B | |
457 ;; ebnf--CC.eps A C B F A B C F F C B A | |
458 ;; ebnf--D.eps D D D | |
459 ;; ebnf--E.eps E E E | |
460 ;; ebnf--G.eps G G G | |
461 ;; ebnf--Z.eps Z Z Z | |
462 ;; | |
463 ;; As you can see if EPS actions is not used, each single production is | |
464 ;; generated per EPS file. To avoid overriding EPS files, use names in ;[ that | |
465 ;; it's not an existing production name. | |
466 ;; | |
467 ;; In the following case: | |
468 ;; | |
469 ;; A = B0. | |
470 ;; ;[AA | |
471 ;; A = B1. | |
472 ;; ;[BB | |
473 ;; A = B2. | |
474 ;; | |
475 ;; The production A is generated in both files ebnf--AA.eps and ebnf--BB.eps. | |
476 ;; | |
477 ;; | |
478 ;; Utilities | |
479 ;; --------- | |
480 ;; | |
481 ;; Some tools are provided to help you. | |
482 ;; | |
483 ;; `ebnf-setup' returns the current setup. | |
484 ;; | |
485 ;; `ebnf-syntax-buffer' does a syntatic analysis of your EBNF in the current | |
486 ;; buffer. | |
487 ;; | |
488 ;; `ebnf-syntax-region' does a syntatic analysis of your EBNF in the current | |
489 ;; region. | |
490 ;; | |
491 ;; `ebnf-customize' activates a customization buffer for ebnf2ps options. | |
492 ;; | |
493 ;; `ebnf-syntax-buffer', `ebnf-syntax-region' and `ebnf-customize' can be bound | |
494 ;; to keys in the same way as `ebnf-' commands. | |
495 ;; | |
496 ;; | |
497 ;; Hooks | |
498 ;; ----- | |
499 ;; | |
500 ;; ebn2ps has the following hook variables: | |
501 ;; | |
502 ;; `ebnf-hook' | |
503 ;; It is evaluated once before any ebnf2ps process. | |
504 ;; | |
505 ;; `ebnf-production-hook' | |
506 ;; It is evaluated on each beginning of production. | |
507 ;; | |
508 ;; `ebnf-page-hook' | |
509 ;; It is evaluated on each beginning of page. | |
510 ;; | |
511 ;; | |
512 ;; Options | |
513 ;; ------- | |
514 ;; | |
515 ;; Below it's shown a brief description of ebnf2ps options, please, see the | |
516 ;; options declaration in the code for a long documentation. | |
517 ;; | |
518 ;; `ebnf-horizontal-orientation' Non-nil means productions are drawn | |
519 ;; horizontally. | |
520 ;; | |
521 ;; `ebnf-horizontal-max-height' Non-nil means to use maximum production | |
522 ;; height in horizontal orientation. | |
523 ;; | |
524 ;; `ebnf-production-horizontal-space' Specify horizontal space in points | |
525 ;; between productions. | |
526 ;; | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
527 ;; `ebnf-production-vertical-space' Specify vertical space in points |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
528 ;; between productions. |
27451 | 529 ;; |
530 ;; `ebnf-justify-sequence' Specify justification of terms in a | |
531 ;; sequence inside alternatives. | |
532 ;; | |
533 ;; `ebnf-terminal-regexp' Specify how it's a terminal name. | |
534 ;; | |
535 ;; `ebnf-case-fold-search' Non-nil means ignore case on matching. | |
536 ;; | |
537 ;; `ebnf-terminal-font' Specify terminal font. | |
538 ;; | |
539 ;; `ebnf-terminal-shape' Specify terminal box shape. | |
540 ;; | |
541 ;; `ebnf-terminal-shadow' Non-nil means terminal box will have a | |
542 ;; shadow. | |
543 ;; | |
544 ;; `ebnf-terminal-border-width' Specify border width for terminal box. | |
545 ;; | |
546 ;; `ebnf-terminal-border-color' Specify border color for terminal box. | |
547 ;; | |
548 ;; `ebnf-sort-production' Specify how productions are sorted. | |
549 ;; | |
550 ;; `ebnf-production-font' Specify production font. | |
551 ;; | |
552 ;; `ebnf-non-terminal-font' Specify non-terminal font. | |
553 ;; | |
554 ;; `ebnf-non-terminal-shape' Specify non-terminal box shape. | |
555 ;; | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
556 ;; `ebnf-non-terminal-shadow' Non-nil means non-terminal box will |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
557 ;; have a shadow. |
27451 | 558 ;; |
559 ;; `ebnf-non-terminal-border-width' Specify border width for non-terminal | |
560 ;; box. | |
561 ;; | |
562 ;; `ebnf-non-terminal-border-color' Specify border color for non-terminal | |
563 ;; box. | |
564 ;; | |
565 ;; `ebnf-special-font' Specify special font. | |
566 ;; | |
567 ;; `ebnf-special-shape' Specify special box shape. | |
568 ;; | |
569 ;; `ebnf-special-shadow' Non-nil means special box will have a | |
570 ;; shadow. | |
571 ;; | |
572 ;; `ebnf-special-border-width' Specify border width for special box. | |
573 ;; | |
574 ;; `ebnf-special-border-color' Specify border color for special box. | |
575 ;; | |
576 ;; `ebnf-except-font' Specify except font. | |
577 ;; | |
578 ;; `ebnf-except-shape' Specify except box shape. | |
579 ;; | |
580 ;; `ebnf-except-shadow' Non-nil means except box will have a | |
581 ;; shadow. | |
582 ;; | |
583 ;; `ebnf-except-border-width' Specify border width for except box. | |
584 ;; | |
585 ;; `ebnf-except-border-color' Specify border color for except box. | |
586 ;; | |
587 ;; `ebnf-repeat-font' Specify repeat font. | |
588 ;; | |
589 ;; `ebnf-repeat-shape' Specify repeat box shape. | |
590 ;; | |
591 ;; `ebnf-repeat-shadow' Non-nil means repeat box will have a | |
592 ;; shadow. | |
593 ;; | |
594 ;; `ebnf-repeat-border-width' Specify border width for repeat box. | |
595 ;; | |
596 ;; `ebnf-repeat-border-color' Specify border color for repeat box. | |
597 ;; | |
598 ;; `ebnf-entry-percentage' Specify entry height on alternatives. | |
599 ;; | |
600 ;; `ebnf-arrow-shape' Specify the arrow shape. | |
601 ;; | |
602 ;; `ebnf-chart-shape' Specify chart flow shape. | |
603 ;; | |
604 ;; `ebnf-color-p' Non-nil means use color. | |
605 ;; | |
606 ;; `ebnf-line-width' Specify flow line width. | |
607 ;; | |
608 ;; `ebnf-line-color' Specify flow line color. | |
609 ;; | |
31255 | 610 ;; `ebnf-user-arrow' Specify a sexp for user arrow shape (a |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
611 ;; PostScript code). |
27451 | 612 ;; |
613 ;; `ebnf-debug-ps' Non-nil means to generate PostScript | |
614 ;; debug procedures. | |
615 ;; | |
616 ;; `ebnf-lex-comment-char' Specify the line comment character. | |
617 ;; | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
618 ;; `ebnf-lex-eop-char' Specify the end of production |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
619 ;; character. |
27451 | 620 ;; |
621 ;; `ebnf-syntax' Specify syntax to be recognized. | |
622 ;; | |
623 ;; `ebnf-iso-alternative-p' Non-nil means use alternative ISO EBNF. | |
624 ;; | |
625 ;; `ebnf-iso-normalize-p' Non-nil means normalize ISO EBNF syntax | |
626 ;; names. | |
627 ;; | |
628 ;; `ebnf-default-width' Specify additional border width over | |
629 ;; default terminal, non-terminal or | |
630 ;; special. | |
631 ;; | |
632 ;; `ebnf-eps-prefix' Specify EPS prefix file name. | |
633 ;; | |
634 ;; `ebnf-use-float-format' Non-nil means use `%f' float format. | |
635 ;; | |
636 ;; `ebnf-yac-ignore-error-recovery' Non-nil means ignore error recovery. | |
637 ;; | |
638 ;; `ebnf-ignore-empty-rule' Non-nil means ignore empty rules. | |
639 ;; | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
640 ;; `ebnf-optimize' Non-nil means optimize syntatic chart |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
641 ;; of rules. |
27451 | 642 ;; |
643 ;; To set the above options you may: | |
644 ;; | |
645 ;; a) insert the code in your ~/.emacs, like: | |
646 ;; | |
647 ;; (setq ebnf-terminal-shape 'bevel) | |
648 ;; | |
649 ;; This way always keep your default settings when you enter a new Emacs | |
650 ;; session. | |
651 ;; | |
652 ;; b) or use `set-variable' in your Emacs session, like: | |
653 ;; | |
654 ;; M-x set-variable RET ebnf-terminal-shape RET bevel RET | |
655 ;; | |
656 ;; This way keep your settings only during the current Emacs session. | |
657 ;; | |
658 ;; c) or use customization, for example: | |
659 ;; click on menu-bar *Help* option, | |
660 ;; then click on *Customize*, | |
661 ;; then click on *Browse Customization Groups*, | |
662 ;; expand *PostScript* group, | |
663 ;; expand *Ebnf2ps* group | |
664 ;; and then customize ebnf2ps options. | |
665 ;; Through this way, you may choose if the settings are kept or not when | |
666 ;; you leave out the current Emacs session. | |
667 ;; | |
668 ;; d) or see the option value: | |
669 ;; | |
670 ;; C-h v ebnf-terminal-shape RET | |
671 ;; | |
672 ;; and click the *customize* hypertext button. | |
673 ;; Through this way, you may choose if the settings are kept or not when | |
674 ;; you leave out the current Emacs session. | |
675 ;; | |
676 ;; e) or invoke: | |
677 ;; | |
678 ;; M-x ebnf-customize RET | |
679 ;; | |
680 ;; and then customize ebnf2ps options. | |
681 ;; Through this way, you may choose if the settings are kept or not when | |
682 ;; you leave out the current Emacs session. | |
683 ;; | |
684 ;; | |
685 ;; Styles | |
686 ;; ------ | |
687 ;; | |
688 ;; Sometimes you need to change the EBNF style you are using, for example, | |
689 ;; change the shapes and colors. These changes may force you to set some | |
690 ;; variables and after use, set back the variables to the old values. | |
691 ;; | |
692 ;; To help to handle this situation, ebnf2ps has the following commands to | |
693 ;; handle styles: | |
694 ;; | |
695 ;; `ebnf-insert-style' Insert a new style NAME with inheritance INHERITS and | |
696 ;; values VALUES. | |
697 ;; | |
698 ;; `ebnf-merge-style' Merge values of style NAME with style VALUES. | |
699 ;; | |
700 ;; `ebnf-apply-style' Set STYLE to current style. | |
701 ;; | |
702 ;; `ebnf-reset-style' Reset current style. | |
703 ;; | |
704 ;; `ebnf-push-style' Push the current style and set STYLE to current style. | |
705 ;; | |
706 ;; `ebnf-pop-style' Pop a style and set it to current style. | |
707 ;; | |
708 ;; These commands helps to put together a lot of variable settings in a group | |
709 ;; and name this group. So when you wish to apply these settings it's only | |
710 ;; needed to give the name. | |
711 ;; | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
712 ;; There is also a notion of simple inheritance of style; so if you declare |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
713 ;; that a style A inherits from a style B, all settings of B is applied first |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
714 ;; and then the settings of A is applied. This is useful when you wish to |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
715 ;; modify some aspects of an existing style, but at same time wish to keep it |
27451 | 716 ;; unmodified. |
717 ;; | |
718 ;; See documentation for `ebnf-style-database'. | |
719 ;; | |
720 ;; | |
721 ;; Layout | |
722 ;; ------ | |
723 ;; | |
724 ;; Below it is the layout of minimum area to draw each element, and it's used | |
725 ;; the following terms: | |
726 ;; | |
727 ;; font height is given by: | |
728 ;; (terminal font height + non-terminal font height) / 2 | |
729 ;; | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
730 ;; entry is the vertical position used to know where it should |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
731 ;; be drawn the flow line in the current element. |
27451 | 732 ;; |
733 ;; | |
734 ;; * SPECIAL, TERMINAL and NON-TERMINAL | |
735 ;; | |
736 ;; +==============+................................... | |
737 ;; | | } font height / 2 } entry } | |
738 ;; | XXXXXXXX...|....... } } | |
739 ;; ====+ XXXXXXXX +==== } text height ...... } height | |
740 ;; : | XXXXXXXX...|...:... } | |
741 ;; : | : : | : } font height / 2 } | |
742 ;; : +==============+...:............................... | |
743 ;; : : : : : : | |
744 ;; : : : : : :...................... | |
745 ;; : : : : : } font height } | |
746 ;; : : : : :....... } | |
747 ;; : : : : } font height / 2 } | |
748 ;; : : : :........... } | |
749 ;; : : : } text width } width | |
750 ;; : : :.................. } | |
751 ;; : : } font height / 2 } | |
752 ;; : :...................... } | |
753 ;; : } font height } | |
754 ;; :............................................. | |
755 ;; | |
756 ;; | |
757 ;; * OPTIONAL | |
758 ;; | |
759 ;; +==========+..................................... | |
760 ;; | | } } } | |
761 ;; | | } entry } } | |
762 ;; | | } } } | |
763 ;; ===+===+ +===+===... } element height } height | |
764 ;; : \ | | / : } } | |
765 ;; : + | | + : } } | |
766 ;; : | +==========+.|................. } | |
767 ;; : | : : | : } font height } | |
768 ;; : +==============+................................... | |
769 ;; : : : : | |
770 ;; : : : :...................... | |
771 ;; : : : } font height * 2 } | |
772 ;; : : :.......... } | |
773 ;; : : } element width } width | |
774 ;; : :..................... } | |
775 ;; : } font height * 2 } | |
776 ;; :............................................... | |
777 ;; | |
778 ;; | |
779 ;; * ALTERNATIVE | |
780 ;; | |
781 ;; +===+................................... | |
782 ;; +==+ A +==+ } A height } } | |
783 ;; | +===+..|........ } entry } | |
784 ;; + + } font height } } | |
785 ;; / +===+...\....... } } | |
786 ;; ===+====+ B +====+=== } B height ..... } height | |
787 ;; : \ +===+.../....... } | |
788 ;; : + + : } font height } | |
789 ;; : | +===+..|........ } | |
790 ;; : +==+ C +==+ : } C height } | |
791 ;; : : +===+................................... | |
792 ;; : : : : | |
793 ;; : : : :...................... | |
794 ;; : : : } font height * 2 } | |
795 ;; : : :......... } | |
796 ;; : : } max width } width | |
797 ;; : :................. } | |
798 ;; : } font height * 2 } | |
799 ;; :.......................................... | |
800 ;; | |
801 ;; NOTES: | |
802 ;; 1. An empty alternative has zero of height. | |
803 ;; | |
804 ;; 2. The variable `ebnf-entry-percentage' is used to determine the | |
805 ;; entry point. | |
806 ;; | |
807 ;; | |
808 ;; * ZERO OR MORE | |
809 ;; | |
810 ;; +===========+............................... | |
811 ;; +=+ separator +=+ } separator height } | |
812 ;; / +===========+..\........ } | |
813 ;; + + } } | |
814 ;; | | } font height } | |
815 ;; + + } } | |
816 ;; \ +===========+../........ } height = entry | |
817 ;; +=+ element +=+ } element height } | |
818 ;; /: +===========+..\........ } | |
819 ;; + : : + } } | |
820 ;; + : : + } font height } | |
821 ;; / : : \ } } | |
822 ;; ==+=======================+==....................... | |
823 ;; : : : : | |
824 ;; : : : :....................... | |
825 ;; : : : } font height * 2 } | |
826 ;; : : :......... } | |
827 ;; : : } max width } width | |
828 ;; : :......................... } | |
829 ;; : } font height * 2 } | |
830 ;; :................................................... | |
831 ;; | |
832 ;; | |
833 ;; * ONE OR MORE | |
834 ;; | |
835 ;; +===========+...................................... | |
836 ;; +=+ separator +=+ } separator height } } | |
837 ;; / +===========+..\...... } } | |
838 ;; + + } } entry } | |
839 ;; | | } font height } } height | |
840 ;; + + } } } | |
841 ;; \ +===========+../...... } } | |
842 ;; ===+=+ element +=+=== } element height .... } | |
843 ;; : : +===========+...................................... | |
844 ;; : : : : | |
845 ;; : : : :........................ | |
846 ;; : : : } font height * 2 } | |
847 ;; : : :....... } | |
848 ;; : : } max width } width | |
849 ;; : :....................... } | |
850 ;; : } font height * 2 } | |
851 ;; :.............................................. | |
852 ;; | |
853 ;; | |
854 ;; * PRODUCTION | |
855 ;; | |
856 ;; XXXXXX:...................................... | |
857 ;; XXXXXX: } production font height } | |
858 ;; XXXXXX:............ } | |
859 ;; } font height } | |
860 ;; +======+....... } height = entry | |
861 ;; | | } } | |
862 ;; ====+ +==== } element height } | |
863 ;; : | | : } } | |
864 ;; : +======+................................. | |
865 ;; : : : : | |
866 ;; : : : :...................... | |
867 ;; : : : } font height * 2 } | |
868 ;; : : :....... } | |
869 ;; : : } element width } width | |
870 ;; : :.............. } | |
871 ;; : } font height * 2 } | |
872 ;; :..................................... | |
873 ;; | |
874 ;; | |
875 ;; * REPEAT | |
876 ;; | |
877 ;; +================+................................... | |
878 ;; | | } font height / 2 } entry } | |
879 ;; | +===+...|....... } } | |
880 ;; ====+ N * | X | +==== } X height ......... } height | |
881 ;; : | : : +===+...|...:... } | |
882 ;; : | : : : : | : } font height / 2 } | |
883 ;; : +================+...:............................... | |
884 ;; : : : : : : : : | |
885 ;; : : : : : : : :...................... | |
886 ;; : : : : : : : } font height } | |
887 ;; : : : : : : :....... } | |
888 ;; : : : : : : } font height / 2 } | |
889 ;; : : : : : :........... } | |
890 ;; : : : : : } X width } | |
891 ;; : : : : :............... } | |
892 ;; : : : : } font height / 2 } width | |
893 ;; : : : :.................. } | |
894 ;; : : : } text width } | |
895 ;; : : :..................... } | |
896 ;; : : } font height / 2 } | |
897 ;; : :........................ } | |
898 ;; : } font height } | |
899 ;; :............................................... | |
900 ;; | |
901 ;; | |
902 ;; * EXCEPT | |
903 ;; | |
904 ;; +==================+................................... | |
905 ;; | | } font height / 2 } entry } | |
906 ;; | +===+ +===+...|....... } } | |
907 ;; ====+ | X | - | y | +==== } max height ....... } height | |
908 ;; : | +===+ +===+...|...:... } | |
909 ;; : | : : : : | : } font height / 2 } | |
910 ;; : +==================+...:............................... | |
911 ;; : : : : : : : : | |
912 ;; : : : : : : : :...................... | |
913 ;; : : : : : : : } font height } | |
914 ;; : : : : : : :....... } | |
915 ;; : : : : : : } font height / 2 } | |
916 ;; : : : : : :........... } | |
917 ;; : : : : : } Y width } | |
918 ;; : : : : :............... } | |
919 ;; : : : : } font height } width | |
920 ;; : : : :................... } | |
921 ;; : : : } X width } | |
922 ;; : : :....................... } | |
923 ;; : : } font height / 2 } | |
924 ;; : :.......................... } | |
925 ;; : } font height } | |
926 ;; :................................................. | |
927 ;; | |
928 ;; NOTE: If Y element is empty, it's draw nothing at Y place. | |
929 ;; | |
930 ;; | |
931 ;; Internal Structures | |
932 ;; ------------------- | |
933 ;; | |
934 ;; ebnf2ps has two passes. The first pass does a lexical and syntatic analysis | |
935 ;; of current buffer and generates an intermediate representation. The second | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
936 ;; pass uses the intermediate representation to generate the PostScript |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
937 ;; syntatic chart. |
27451 | 938 ;; |
939 ;; The intermediate representation is a list of vectors, the vector element | |
940 ;; represents a syntatic chart element. Below is a vector representation for | |
941 ;; each syntatic chart element. | |
942 ;; | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
943 ;; [production WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH NAME PRODUCTION ACTION] |
27451 | 944 ;; [alternative WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH LIST] |
945 ;; [sequence WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH LIST] | |
946 ;; [terminal WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH NAME DEFAULT] | |
947 ;; [non-terminal WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH NAME DEFAULT] | |
948 ;; [special WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH NAME DEFAULT] | |
949 ;; [empty WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH] | |
950 ;; [optional WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH ELEMENT] | |
951 ;; [one-or-more WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH ELEMENT SEPARATOR] | |
952 ;; [zero-or-more WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH ELEMENT SEPARATOR] | |
953 ;; [repeat WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH TIMES ELEMENT] | |
954 ;; [except WIDTH-FUN DIM-FUN ENTRY HEIGHT WIDTH ELEMENT ELEMENT] | |
955 ;; | |
956 ;; The first vector position is a function symbol used to generate PostScript | |
957 ;; for this element. | |
958 ;; WIDTH-FUN is a function symbol called to adjust the element width. | |
959 ;; DIM-FUN is a function symbol called to set the element dimensions. | |
960 ;; ENTRY is the element entry point. | |
961 ;; HEIGHT and WIDTH are the element height and width, respectively. | |
962 ;; NAME is a string that it's the element name. | |
963 ;; DEFAULT is a boolean that indicates if it's a `default' element. | |
964 ;; PRODUCTION and ELEMENT are vectors that represents sub-elements of current | |
965 ;; one. | |
966 ;; LIST is a list of vector that represents the list part for alternatives and | |
967 ;; sequences. | |
968 ;; SEPARATOR is a vector that represents the sub-element used to separate the | |
969 ;; list elements. | |
970 ;; TIMES is a string representing the number of times that ELEMENT is repeated | |
971 ;; on a repeat construction. | |
972 ;; ACTION indicates some action that should be done before production is | |
973 ;; generated. The current actions are: | |
974 ;; | |
975 ;; nil no action. | |
976 ;; | |
977 ;; form-feed current production starts on a new page. | |
978 ;; | |
979 ;; newline current production starts on next line, this is useful | |
980 ;; when `ebnf-horizontal-orientation' is non-nil. | |
981 ;; | |
982 ;; keep-line current production continues on the current line, this | |
983 ;; is useful when `ebnf-horizontal-orientation' is nil. | |
984 ;; | |
985 ;; | |
986 ;; Things To Change | |
987 ;; ---------------- | |
988 ;; | |
989 ;; . Handle situations when syntatic chart is out of paper. | |
990 ;; . Use other alphabet than ascii. | |
991 ;; . Optimizations... | |
992 ;; | |
993 ;; | |
994 ;; Acknowledgements | |
995 ;; ---------------- | |
996 ;; | |
997 ;; Thanks to all who emailed comments. | |
998 ;; | |
999 ;; | |
1000 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1001 | |
1002 ;;; code: | |
1003 | |
1004 | |
1005 (require 'ps-print) | |
1006 | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
1007 (and (string< ps-print-version "5.2.3") |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
1008 (error "`ebnf2ps' requires `ps-print' package version 5.2.3 or later")) |
27451 | 1009 |
1010 | |
1011 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1012 ;; User Variables: | |
1013 | |
1014 | |
1015 ;;; Interface to the command system | |
1016 | |
1017 (defgroup postscript nil | |
1018 "PostScript Group" | |
1019 :tag "PostScript" | |
1020 :group 'emacs) | |
1021 | |
1022 | |
1023 (defgroup ebnf2ps nil | |
1024 "Translate an EBNF to a syntatic chart on PostScript" | |
1025 :prefix "ebnf-" | |
1026 :group 'wp | |
1027 :group 'postscript) | |
1028 | |
1029 | |
1030 (defgroup ebnf-special nil | |
1031 "Special customization" | |
1032 :prefix "ebnf-" | |
1033 :tag "Special" | |
1034 :group 'ebnf2ps) | |
1035 | |
1036 | |
1037 (defgroup ebnf-except nil | |
1038 "Except customization" | |
1039 :prefix "ebnf-" | |
1040 :tag "Except" | |
1041 :group 'ebnf2ps) | |
1042 | |
1043 | |
1044 (defgroup ebnf-repeat nil | |
1045 "Repeat customization" | |
1046 :prefix "ebnf-" | |
1047 :tag "Repeat" | |
1048 :group 'ebnf2ps) | |
1049 | |
1050 | |
1051 (defgroup ebnf-terminal nil | |
1052 "Terminal customization" | |
1053 :prefix "ebnf-" | |
1054 :tag "Terminal" | |
1055 :group 'ebnf2ps) | |
1056 | |
1057 | |
1058 (defgroup ebnf-non-terminal nil | |
1059 "Non-Terminal customization" | |
1060 :prefix "ebnf-" | |
1061 :tag "Non-Terminal" | |
1062 :group 'ebnf2ps) | |
1063 | |
1064 | |
1065 (defgroup ebnf-production nil | |
1066 "Production customization" | |
1067 :prefix "ebnf-" | |
1068 :tag "Production" | |
1069 :group 'ebnf2ps) | |
1070 | |
1071 | |
1072 (defgroup ebnf-shape nil | |
1073 "Shapes customization" | |
1074 :prefix "ebnf-" | |
1075 :tag "Shape" | |
1076 :group 'ebnf2ps) | |
1077 | |
1078 | |
1079 (defgroup ebnf-displacement nil | |
1080 "Displacement customization" | |
1081 :prefix "ebnf-" | |
1082 :tag "Displacement" | |
1083 :group 'ebnf2ps) | |
1084 | |
1085 | |
1086 (defgroup ebnf-syntatic nil | |
1087 "Syntatic customization" | |
1088 :prefix "ebnf-" | |
1089 :tag "Syntatic" | |
1090 :group 'ebnf2ps) | |
1091 | |
1092 | |
1093 (defgroup ebnf-optimization nil | |
1094 "Optimization customization" | |
1095 :prefix "ebnf-" | |
1096 :tag "Optimization" | |
1097 :group 'ebnf2ps) | |
1098 | |
1099 | |
1100 (defcustom ebnf-horizontal-orientation nil | |
1101 "*Non-nil means productions are drawn horizontally." | |
1102 :type 'boolean | |
1103 :group 'ebnf-displacement) | |
1104 | |
1105 | |
1106 (defcustom ebnf-horizontal-max-height nil | |
1107 "*Non-nil means to use maximum production height in horizontal orientation. | |
1108 | |
1109 It is only used when `ebnf-horizontal-orientation' is non-nil." | |
1110 :type 'boolean | |
1111 :group 'ebnf-displacement) | |
1112 | |
1113 | |
1114 (defcustom ebnf-production-horizontal-space 0.0 ; use ebnf2ps default value | |
1115 "*Specify horizontal space in points between productions. | |
1116 | |
1117 Value less or equal to zero forces ebnf2ps to set a proper default value." | |
1118 :type 'number | |
1119 :group 'ebnf-displacement) | |
1120 | |
1121 | |
1122 (defcustom ebnf-production-vertical-space 0.0 ; use ebnf2ps default value | |
1123 "*Specify vertical space in points between productions. | |
1124 | |
1125 Value less or equal to zero forces ebnf2ps to set a proper default value." | |
1126 :type 'number | |
1127 :group 'ebnf-displacement) | |
1128 | |
1129 | |
1130 (defcustom ebnf-justify-sequence 'center | |
1131 "*Specify justification of terms in a sequence inside alternatives. | |
1132 | |
1133 Valid values are: | |
1134 | |
1135 `left' left justification | |
1136 `right' right justification | |
1137 any other value centralize" | |
1138 :type '(radio :tag "Sequence Justification" | |
1139 (const left) (const right) (other :tag "center" center)) | |
1140 :group 'ebnf-displacement) | |
1141 | |
1142 | |
1143 (defcustom ebnf-special-font '(7 Courier "Black" "Gray95" bold italic) | |
1144 "*Specify special font. | |
1145 | |
1146 See documentation for `ebnf-production-font'." | |
1147 :type '(list :tag "Special Font" | |
1148 (number :tag "Font Size") | |
1149 (symbol :tag "Font Name") | |
1150 (choice :tag "Foreground Color" | |
1151 (string :tag "Name") | |
1152 (other :tag "Default" nil)) | |
1153 (choice :tag "Background Color" | |
1154 (string :tag "Name") | |
1155 (other :tag "Default" nil)) | |
1156 (repeat :tag "Font Attributes" :inline t | |
1157 (choice (const bold) (const italic) | |
1158 (const underline) (const strikeout) | |
1159 (const overline) (const shadow) | |
1160 (const box) (const outline)))) | |
1161 :group 'ebnf-special) | |
1162 | |
1163 | |
1164 (defcustom ebnf-special-shape 'bevel | |
1165 "*Specify special box shape. | |
1166 | |
1167 See documentation for `ebnf-non-terminal-shape'." | |
1168 :type '(radio :tag "Special Shape" | |
1169 (const miter) (const round) (const bevel)) | |
1170 :group 'ebnf-special) | |
1171 | |
1172 | |
1173 (defcustom ebnf-special-shadow nil | |
1174 "*Non-nil means special box will have a shadow." | |
1175 :type 'boolean | |
1176 :group 'ebnf-special) | |
1177 | |
1178 | |
1179 (defcustom ebnf-special-border-width 0.5 | |
1180 "*Specify border width for special box." | |
1181 :type 'number | |
1182 :group 'ebnf-special) | |
1183 | |
1184 | |
1185 (defcustom ebnf-special-border-color "Black" | |
1186 "*Specify border color for special box." | |
1187 :type 'string | |
1188 :group 'ebnf-special) | |
1189 | |
1190 | |
1191 (defcustom ebnf-except-font '(7 Courier "Black" "Gray90" bold italic) | |
1192 "*Specify except font. | |
1193 | |
1194 See documentation for `ebnf-production-font'." | |
1195 :type '(list :tag "Except Font" | |
1196 (number :tag "Font Size") | |
1197 (symbol :tag "Font Name") | |
1198 (choice :tag "Foreground Color" | |
1199 (string :tag "Name") | |
1200 (other :tag "Default" nil)) | |
1201 (choice :tag "Background Color" | |
1202 (string :tag "Name") | |
1203 (other :tag "Default" nil)) | |
1204 (repeat :tag "Font Attributes" :inline t | |
1205 (choice (const bold) (const italic) | |
1206 (const underline) (const strikeout) | |
1207 (const overline) (const shadow) | |
1208 (const box) (const outline)))) | |
1209 :group 'ebnf-except) | |
1210 | |
1211 | |
1212 (defcustom ebnf-except-shape 'bevel | |
1213 "*Specify except box shape. | |
1214 | |
1215 See documentation for `ebnf-non-terminal-shape'." | |
1216 :type '(radio :tag "Except Shape" | |
1217 (const miter) (const round) (const bevel)) | |
1218 :group 'ebnf-except) | |
1219 | |
1220 | |
1221 (defcustom ebnf-except-shadow nil | |
1222 "*Non-nil means except box will have a shadow." | |
1223 :type 'boolean | |
1224 :group 'ebnf-except) | |
1225 | |
1226 | |
1227 (defcustom ebnf-except-border-width 0.25 | |
1228 "*Specify border width for except box." | |
1229 :type 'number | |
1230 :group 'ebnf-except) | |
1231 | |
1232 | |
1233 (defcustom ebnf-except-border-color "Black" | |
1234 "*Specify border color for except box." | |
1235 :type 'string | |
1236 :group 'ebnf-except) | |
1237 | |
1238 | |
1239 (defcustom ebnf-repeat-font '(7 Courier "Black" "Gray85" bold italic) | |
1240 "*Specify repeat font. | |
1241 | |
1242 See documentation for `ebnf-production-font'." | |
1243 :type '(list :tag "Repeat Font" | |
1244 (number :tag "Font Size") | |
1245 (symbol :tag "Font Name") | |
1246 (choice :tag "Foreground Color" | |
1247 (string :tag "Name") | |
1248 (other :tag "Default" nil)) | |
1249 (choice :tag "Background Color" | |
1250 (string :tag "Name") | |
1251 (other :tag "Default" nil)) | |
1252 (repeat :tag "Font Attributes" :inline t | |
1253 (choice (const bold) (const italic) | |
1254 (const underline) (const strikeout) | |
1255 (const overline) (const shadow) | |
1256 (const box) (const outline)))) | |
1257 :group 'ebnf-repeat) | |
1258 | |
1259 | |
1260 (defcustom ebnf-repeat-shape 'bevel | |
1261 "*Specify repeat box shape. | |
1262 | |
1263 See documentation for `ebnf-non-terminal-shape'." | |
1264 :type '(radio :tag "Repeat Shape" | |
1265 (const miter) (const round) (const bevel)) | |
1266 :group 'ebnf-repeat) | |
1267 | |
1268 | |
1269 (defcustom ebnf-repeat-shadow nil | |
1270 "*Non-nil means repeat box will have a shadow." | |
1271 :type 'boolean | |
1272 :group 'ebnf-repeat) | |
1273 | |
1274 | |
1275 (defcustom ebnf-repeat-border-width 0.0 | |
1276 "*Specify border width for repeat box." | |
1277 :type 'number | |
1278 :group 'ebnf-repeat) | |
1279 | |
1280 | |
1281 (defcustom ebnf-repeat-border-color "Black" | |
1282 "*Specify border color for repeat box." | |
1283 :type 'string | |
1284 :group 'ebnf-repeat) | |
1285 | |
1286 | |
1287 (defcustom ebnf-terminal-font '(7 Courier "Black" "White") | |
1288 "*Specify terminal font. | |
1289 | |
1290 See documentation for `ebnf-production-font'." | |
1291 :type '(list :tag "Terminal Font" | |
1292 (number :tag "Font Size") | |
1293 (symbol :tag "Font Name") | |
1294 (choice :tag "Foreground Color" | |
1295 (string :tag "Name") | |
1296 (other :tag "Default" nil)) | |
1297 (choice :tag "Background Color" | |
1298 (string :tag "Name") | |
1299 (other :tag "Default" nil)) | |
1300 (repeat :tag "Font Attributes" :inline t | |
1301 (choice (const bold) (const italic) | |
1302 (const underline) (const strikeout) | |
1303 (const overline) (const shadow) | |
1304 (const box) (const outline)))) | |
1305 :group 'ebnf-terminal) | |
1306 | |
1307 | |
1308 (defcustom ebnf-terminal-shape 'miter | |
1309 "*Specify terminal box shape. | |
1310 | |
1311 See documentation for `ebnf-non-terminal-shape'." | |
1312 :type '(radio :tag "Terminal Shape" | |
1313 (const miter) (const round) (const bevel)) | |
1314 :group 'ebnf-terminal) | |
1315 | |
1316 | |
1317 (defcustom ebnf-terminal-shadow nil | |
1318 "*Non-nil means terminal box will have a shadow." | |
1319 :type 'boolean | |
1320 :group 'ebnf-terminal) | |
1321 | |
1322 | |
1323 (defcustom ebnf-terminal-border-width 1.0 | |
1324 "*Specify border width for terminal box." | |
1325 :type 'number | |
1326 :group 'ebnf-terminal) | |
1327 | |
1328 | |
1329 (defcustom ebnf-terminal-border-color "Black" | |
1330 "*Specify border color for terminal box." | |
1331 :type 'string | |
1332 :group 'ebnf-terminal) | |
1333 | |
1334 | |
1335 (defcustom ebnf-sort-production nil | |
1336 "*Specify how productions are sorted. | |
1337 | |
1338 Valid values are: | |
1339 | |
1340 nil don't sort productions. | |
1341 `ascending' ascending sort. | |
1342 any other value descending sort." | |
1343 :type '(radio :tag "Production Sort" | |
1344 (const :tag "Ascending" ascending) | |
1345 (const :tag "Descending" descending) | |
1346 (other :tag "No Sort" nil)) | |
1347 :group 'ebnf-production) | |
1348 | |
1349 | |
1350 (defcustom ebnf-production-font '(10 Helvetica "Black" "White" bold) | |
1351 "*Specify production header font. | |
1352 | |
1353 It is a list with the following form: | |
1354 | |
1355 (SIZE NAME FOREGROUND BACKGROUND ATTRIBUTE...) | |
1356 | |
1357 Where: | |
1358 SIZE is the font size. | |
1359 NAME is the font name symbol. | |
1360 ATTRIBUTE is one of the following symbols: | |
1361 bold - use bold font. | |
1362 italic - use italic font. | |
1363 underline - put a line under text. | |
1364 strikeout - like underline, but the line is in middle of text. | |
1365 overline - like underline, but the line is over the text. | |
1366 shadow - text will have a shadow. | |
1367 box - text will be surrounded by a box. | |
1368 outline - print characters as hollow outlines. | |
1369 FOREGROUND is a foreground string color name; if it's nil, the default color is | |
1370 \"Black\". | |
1371 BACKGROUND is a background string color name; if it's nil, the default color is | |
1372 \"White\". | |
1373 | |
1374 See `ps-font-info-database' for valid font name." | |
1375 :type '(list :tag "Production Font" | |
1376 (number :tag "Font Size") | |
1377 (symbol :tag "Font Name") | |
1378 (choice :tag "Foreground Color" | |
1379 (string :tag "Name") | |
1380 (other :tag "Default" nil)) | |
1381 (choice :tag "Background Color" | |
1382 (string :tag "Name") | |
1383 (other :tag "Default" nil)) | |
1384 (repeat :tag "Font Attributes" :inline t | |
1385 (choice (const bold) (const italic) | |
1386 (const underline) (const strikeout) | |
1387 (const overline) (const shadow) | |
1388 (const box) (const outline)))) | |
1389 :group 'ebnf-production) | |
1390 | |
1391 | |
1392 (defcustom ebnf-non-terminal-font '(7 Helvetica "Black" "White") | |
1393 "*Specify non-terminal font. | |
1394 | |
1395 See documentation for `ebnf-production-font'." | |
1396 :type '(list :tag "Non-Terminal Font" | |
1397 (number :tag "Font Size") | |
1398 (symbol :tag "Font Name") | |
1399 (choice :tag "Foreground Color" | |
1400 (string :tag "Name") | |
1401 (other :tag "Default" nil)) | |
1402 (choice :tag "Background Color" | |
1403 (string :tag "Name") | |
1404 (other :tag "Default" nil)) | |
1405 (repeat :tag "Font Attributes" :inline t | |
1406 (choice (const bold) (const italic) | |
1407 (const underline) (const strikeout) | |
1408 (const overline) (const shadow) | |
1409 (const box) (const outline)))) | |
1410 :group 'ebnf-non-terminal) | |
1411 | |
1412 | |
1413 (defcustom ebnf-non-terminal-shape 'round | |
1414 "*Specify non-terminal box shape. | |
1415 | |
1416 Valid values are: | |
1417 | |
1418 `miter' +-------+ | |
1419 | | | |
1420 +-------+ | |
1421 | |
1422 `round' ------- | |
1423 ( ) | |
1424 ------- | |
1425 | |
1426 `bevel' /-------\\ | |
1427 | | | |
1428 \\-------/ | |
1429 | |
1430 Any other value is treated as `miter'." | |
1431 :type '(radio :tag "Non-Terminal Shape" | |
1432 (const miter) (const round) (const bevel)) | |
1433 :group 'ebnf-non-terminal) | |
1434 | |
1435 | |
1436 (defcustom ebnf-non-terminal-shadow nil | |
1437 "*Non-nil means non-terminal box will have a shadow." | |
1438 :type 'boolean | |
1439 :group 'ebnf-non-terminal) | |
1440 | |
1441 | |
1442 (defcustom ebnf-non-terminal-border-width 1.0 | |
1443 "*Specify border width for non-terminal box." | |
1444 :type 'number | |
1445 :group 'ebnf-non-terminal) | |
1446 | |
1447 | |
1448 (defcustom ebnf-non-terminal-border-color "Black" | |
1449 "*Specify border color for non-terminal box." | |
1450 :type 'string | |
1451 :group 'ebnf-non-terminal) | |
1452 | |
1453 | |
1454 (defcustom ebnf-arrow-shape 'hollow | |
1455 "*Specify the arrow shape. | |
1456 | |
1457 Valid values are: | |
1458 | |
1459 `none' ====== | |
1460 | |
1461 `semi-up' * `transparent' * | |
1462 * |* | |
1463 =====* | * | |
1464 ==+==* | |
1465 | * | |
1466 |* | |
1467 * | |
1468 | |
1469 `semi-down' =====* `hollow' * | |
1470 * |* | |
1471 * | * | |
1472 ==+ * | |
1473 | * | |
1474 |* | |
1475 * | |
1476 | |
1477 `simple' * `full' * | |
1478 * |* | |
1479 =====* |X* | |
1480 * ==+XX* | |
1481 * |X* | |
1482 |* | |
1483 * | |
1484 | |
1485 `user' See also documentation for variable `ebnf-user-arrow'. | |
1486 | |
1487 Any other value is treated as `none'." | |
1488 :type '(radio :tag "Arrow Shape" | |
1489 (const none) (const semi-up) | |
1490 (const semi-down) (const simple) | |
1491 (const transparent) (const hollow) | |
1492 (const full) (const user)) | |
1493 :group 'ebnf-shape) | |
1494 | |
1495 | |
1496 (defcustom ebnf-chart-shape 'round | |
1497 "*Specify chart flow shape. | |
1498 | |
1499 See documentation for `ebnf-non-terminal-shape'." | |
1500 :type '(radio :tag "Chart Flow Shape" | |
1501 (const miter) (const round) (const bevel)) | |
1502 :group 'ebnf-shape) | |
1503 | |
1504 | |
1505 (defcustom ebnf-user-arrow nil | |
31255 | 1506 "*Specify a sexp for user arrow shape (a PostScript code). |
1507 | |
1508 When evaluated, the sexp should return nil or a string containing PostScript | |
1509 code. PostScript code should draw a right arrow. | |
27451 | 1510 |
1511 The anatomy of a right arrow is: | |
1512 | |
1513 ...... Initial position | |
1514 : | |
1515 : *................. | |
1516 : | * } } | |
1517 : | * } hT4 } | |
1518 v | * } } | |
1519 ======+======*... } hT2 | |
1520 : | *: } } | |
1521 : | * : } hT4 } | |
1522 : | * : } } | |
1523 : *................. | |
1524 : : : | |
1525 : : :.......... | |
1526 : : } hT2 } | |
1527 : :.......... } hT | |
1528 : } hT2 } | |
1529 :....................... | |
1530 | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
1531 Where `hT', `hT2' and `hT4' are predefined PostScript variable names that can |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
1532 be used to generate your own arrow. As these variables are used along |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
1533 PostScript execution, *DON'T* modify the values of them. Instead, copy the |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
1534 values, if you need to modify them. |
27451 | 1535 |
1536 The relation between these variables is: hT = 2 * hT2 = 4 * hT4. | |
1537 | |
1538 The variable `ebnf-user-arrow' is only used when `ebnf-arrow-shape' is set to | |
31255 | 1539 symbol `user'." |
1540 :type '(sexp :tag "User Arrow Shape") | |
27451 | 1541 :group 'ebnf-shape) |
1542 | |
1543 | |
1544 (defcustom ebnf-syntax 'ebnf | |
1545 "*Specify syntax to be recognized. | |
1546 | |
1547 Valid values are: | |
1548 | |
27495 | 1549 `ebnf' ebnf2ps recognizes the syntax described in ebnf2ps |
1550 documentation. | |
27451 | 1551 The following variables *ONLY* have effect with this |
1552 setting: | |
1553 `ebnf-terminal-regexp', `ebnf-case-fold-search', | |
1554 `ebnf-lex-comment-char' and `ebnf-lex-eop-char'. | |
1555 | |
1556 `iso-ebnf' ebnf2ps recognizes the syntax described in the URL: | |
1557 `http://www.cl.cam.ac.uk/~mgk25/iso-ebnf.html' | |
1558 (\"International Standard of the ISO EBNF Notation\"). | |
1559 The following variables *ONLY* have effect with this | |
1560 setting: | |
1561 `ebnf-iso-alternative-p' and `ebnf-iso-normalize-p'. | |
1562 | |
1563 `yacc' ebnf2ps recognizes the Yacc/Bison syntax. | |
1564 The following variable *ONLY* has effect with this | |
1565 setting: | |
1566 `ebnf-yac-ignore-error-recovery'. | |
1567 | |
1568 Any other value is treated as `ebnf'." | |
1569 :type '(radio :tag "Syntax" | |
1570 (const ebnf) (const iso-ebnf) (const yacc)) | |
1571 :group 'ebnf-syntatic) | |
1572 | |
1573 | |
1574 (defcustom ebnf-lex-comment-char ?\; | |
1575 "*Specify the line comment character. | |
1576 | |
1577 It's used only when `ebnf-syntax' is `ebnf'." | |
1578 :type 'character | |
1579 :group 'ebnf-syntatic) | |
1580 | |
1581 | |
1582 (defcustom ebnf-lex-eop-char ?. | |
1583 "*Specify the end of production character. | |
1584 | |
1585 It's used only when `ebnf-syntax' is `ebnf'." | |
1586 :type 'character | |
1587 :group 'ebnf-syntatic) | |
1588 | |
1589 | |
1590 (defcustom ebnf-terminal-regexp nil | |
1591 "*Specify how it's a terminal name. | |
1592 | |
1593 If it's nil, the terminal name must be enclosed by `\"'. | |
1594 If it's a string, it should be a regexp that it'll be used to determine a | |
1595 terminal name; terminal name may also be enclosed by `\"'. | |
1596 | |
1597 It's used only when `ebnf-syntax' is `ebnf'." | |
1598 :type '(radio :tag "Terminal Name" | |
1599 (const nil) regexp) | |
1600 :group 'ebnf-syntatic) | |
1601 | |
1602 | |
1603 (defcustom ebnf-case-fold-search nil | |
1604 "*Non-nil means ignore case on matching. | |
1605 | |
1606 It's only used when `ebnf-terminal-regexp' is non-nil and when `ebnf-syntax' is | |
1607 `ebnf'." | |
1608 :type 'boolean | |
1609 :group 'ebnf-syntatic) | |
1610 | |
1611 | |
1612 (defcustom ebnf-iso-alternative-p nil | |
1613 "*Non-nil means use alternative ISO EBNF. | |
1614 | |
1615 It's only used when `ebnf-syntax' is `iso-ebnf'. | |
1616 | |
1617 This variable affects the following symbol set: | |
1618 | |
1619 STANDARD ALTERNATIVE | |
1620 | ==> / or ! | |
1621 [ ==> (/ | |
1622 ] ==> /) | |
1623 { ==> (: | |
1624 } ==> :) | |
1625 ; ==> ." | |
1626 :type 'boolean | |
1627 :group 'ebnf-syntatic) | |
1628 | |
1629 | |
1630 (defcustom ebnf-iso-normalize-p nil | |
1631 "*Non-nil means normalize ISO EBNF syntax names. | |
1632 | |
1633 Normalize a name means that several contiguous spaces inside name become a | |
1634 single space, so \"A B C\" is normalized to \"A B C\". | |
1635 | |
1636 It's only used when `ebnf-syntax' is `iso-ebnf'." | |
1637 :type 'boolean | |
1638 :group 'ebnf-syntatic) | |
1639 | |
1640 | |
1641 (defcustom ebnf-eps-prefix "ebnf--" | |
1642 "*Specify EPS prefix file name. | |
1643 | |
1644 See `ebnf-eps-buffer' and `ebnf-eps-region' commands." | |
1645 :type 'string | |
1646 :group 'ebnf2ps) | |
1647 | |
1648 | |
1649 (defcustom ebnf-entry-percentage 0.5 ; middle | |
1650 "*Specify entry height on alternatives. | |
1651 | |
1652 It must be a float between 0.0 (top) and 1.0 (bottom)." | |
1653 :type 'number | |
1654 :group 'ebnf2ps) | |
1655 | |
1656 | |
1657 (defcustom ebnf-default-width 0.6 | |
1658 "*Specify additional border width over default terminal, non-terminal or | |
1659 special." | |
1660 :type 'number | |
1661 :group 'ebnf2ps) | |
1662 | |
1663 | |
1664 ;; Printing color requires x-color-values. | |
1665 (defcustom ebnf-color-p (or (fboundp 'x-color-values) ; Emacs | |
1666 (fboundp 'color-instance-rgb-components)) ; XEmacs | |
1667 "*Non-nil means use color." | |
1668 :type 'boolean | |
1669 :group 'ebnf2ps) | |
1670 | |
1671 | |
1672 (defcustom ebnf-line-width 1.0 | |
1673 "*Specify flow line width." | |
1674 :type 'number | |
1675 :group 'ebnf2ps) | |
1676 | |
1677 | |
1678 (defcustom ebnf-line-color "Black" | |
1679 "*Specify flow line color." | |
1680 :type 'string | |
1681 :group 'ebnf2ps) | |
1682 | |
1683 | |
1684 (defcustom ebnf-debug-ps nil | |
1685 "*Non-nil means to generate PostScript debug procedures. | |
1686 | |
1687 It is intended to help PostScript programmers in debugging." | |
1688 :type 'boolean | |
1689 :group 'ebnf2ps) | |
1690 | |
1691 | |
1692 (defcustom ebnf-use-float-format t | |
1693 "*Non-nil means use `%f' float format. | |
1694 | |
1695 The advantage of using float format is that ebnf2ps generates a little short | |
1696 PostScript file. | |
1697 | |
1698 If it occurs the error message: | |
1699 | |
1700 Invalid format operation %f | |
1701 | |
1702 when executing ebnf2ps, set `ebnf-use-float-format' to nil." | |
1703 :type 'boolean | |
1704 :group 'ebnf2ps) | |
1705 | |
1706 | |
1707 (defcustom ebnf-yac-ignore-error-recovery nil | |
1708 "*Non-nil means ignore error recovery. | |
1709 | |
1710 It's only used when `ebnf-syntax' is `yacc'." | |
1711 :type 'boolean | |
1712 :group 'ebnf-syntatic) | |
1713 | |
1714 | |
1715 (defcustom ebnf-ignore-empty-rule nil | |
1716 "*Non-nil means ignore empty rules. | |
1717 | |
1718 It's interesting to set this variable if your Yacc/Bison grammar has a lot of | |
1719 middle action rule." | |
1720 :type 'boolean | |
1721 :group 'ebnf-optimization) | |
1722 | |
1723 | |
1724 (defcustom ebnf-optimize nil | |
1725 "*Non-nil means optimize syntatic chart of rules. | |
1726 | |
1727 The following optimizations are done: | |
1728 | |
1729 left recursion: | |
1730 1. A = B | A C. ==> A = B {C}*. | |
1731 2. A = B | A B. ==> A = {B}+. | |
1732 3. A = | A B. ==> A = {B}*. | |
1733 4. A = B | A C B. ==> A = {B || C}+. | |
1734 5. A = B | D | A C | A E. ==> A = ( B | D ) { C | E }*. | |
1735 | |
1736 optional: | |
1737 6. A = B | . ==> A = [B]. | |
1738 7. A = | B . ==> A = [B]. | |
1739 | |
1740 factoration: | |
1741 8. A = B C | B D. ==> A = B (C | D). | |
1742 9. A = C B | D B. ==> A = (C | D) B. | |
1743 10. A = B C E | B D E. ==> A = B (C | D) E. | |
1744 | |
1745 The above optimizations are specially useful when `ebnf-syntax' is `yacc'." | |
1746 :type 'boolean | |
1747 :group 'ebnf-optimization) | |
1748 | |
1749 | |
1750 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1751 ;; Customization | |
1752 | |
1753 | |
1754 ;;;###autoload | |
1755 (defun ebnf-customize () | |
1756 "Customization for ebnf group." | |
1757 (interactive) | |
1758 (customize-group 'ebnf2ps)) | |
1759 | |
1760 | |
1761 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1762 ;; User commands | |
1763 | |
1764 | |
1765 ;;;###autoload | |
1766 (defun ebnf-print-buffer (&optional filename) | |
1767 "Generate and print a PostScript syntatic chart image of the buffer. | |
1768 | |
1769 When called with a numeric prefix argument (C-u), prompts the user for | |
1770 the name of a file to save the PostScript image in, instead of sending | |
1771 it to the printer. | |
1772 | |
1773 More specifically, the FILENAME argument is treated as follows: if it | |
1774 is nil, send the image to the printer. If FILENAME is a string, save | |
1775 the PostScript image in a file with that name. If FILENAME is a | |
1776 number, prompt the user for the name of the file to save in." | |
1777 (interactive (list (ps-print-preprint current-prefix-arg))) | |
1778 (ebnf-print-region (point-min) (point-max) filename)) | |
1779 | |
1780 | |
1781 ;;;###autoload | |
1782 (defun ebnf-print-region (from to &optional filename) | |
1783 "Generate and print a PostScript syntatic chart image of the region. | |
1784 Like `ebnf-print-buffer', but prints just the current region." | |
1785 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg))) | |
1786 (run-hooks 'ebnf-hook) | |
1787 (or (ebnf-spool-region from to) | |
1788 (ps-do-despool filename))) | |
1789 | |
1790 | |
1791 ;;;###autoload | |
1792 (defun ebnf-spool-buffer () | |
1793 "Generate and spool a PostScript syntatic chart image of the buffer. | |
1794 Like `ebnf-print-buffer' except that the PostScript image is saved in a | |
1795 local buffer to be sent to the printer later. | |
1796 | |
1797 Use the command `ebnf-despool' to send the spooled images to the printer." | |
1798 (interactive) | |
1799 (ebnf-spool-region (point-min) (point-max))) | |
1800 | |
1801 | |
1802 ;;;###autoload | |
1803 (defun ebnf-spool-region (from to) | |
1804 "Generate a PostScript syntatic chart image of the region and spool locally. | |
1805 Like `ebnf-spool-buffer', but spools just the current region. | |
1806 | |
1807 Use the command `ebnf-despool' to send the spooled images to the printer." | |
1808 (interactive "r") | |
1809 (ebnf-generate-region from to 'ebnf-generate)) | |
1810 | |
1811 | |
1812 ;;;###autoload | |
1813 (defun ebnf-eps-buffer () | |
1814 "Generate a PostScript syntatic chart image of the buffer in a EPS file. | |
1815 | |
1816 Indeed, for each production is generated a EPS file. | |
1817 The EPS file name has the following form: | |
1818 | |
1819 <PREFIX><PRODUCTION>.eps | |
1820 | |
1821 <PREFIX> is given by variable `ebnf-eps-prefix'. | |
1822 The default value is \"ebnf--\". | |
1823 | |
1824 <PRODUCTION> is the production name. | |
1825 The production name is mapped to form a valid file name. | |
1826 For example, the production name \"A/B + C\" is mapped to | |
1827 \"A_B_+_C\" and the EPS file name used is \"ebnf--A_B_+_C.eps\". | |
1828 | |
1829 WARNING: It's *NOT* asked any confirmation to override an existing file." | |
1830 (interactive) | |
1831 (ebnf-eps-region (point-min) (point-max))) | |
1832 | |
1833 | |
1834 ;;;###autoload | |
1835 (defun ebnf-eps-region (from to) | |
1836 "Generate a PostScript syntatic chart image of the region in a EPS file. | |
1837 | |
1838 Indeed, for each production is generated a EPS file. | |
1839 The EPS file name has the following form: | |
1840 | |
1841 <PREFIX><PRODUCTION>.eps | |
1842 | |
1843 <PREFIX> is given by variable `ebnf-eps-prefix'. | |
1844 The default value is \"ebnf--\". | |
1845 | |
1846 <PRODUCTION> is the production name. | |
1847 The production name is mapped to form a valid file name. | |
1848 For example, the production name \"A/B + C\" is mapped to | |
1849 \"A_B_+_C\" and the EPS file name used is \"ebnf--A_B_+_C.eps\". | |
1850 | |
1851 WARNING: It's *NOT* asked any confirmation to override an existing file." | |
1852 (interactive "r") | |
1853 (let ((ebnf-eps-executing t)) | |
1854 (ebnf-generate-region from to 'ebnf-generate-eps))) | |
1855 | |
1856 | |
1857 ;;;###autoload | |
1858 (defalias 'ebnf-despool 'ps-despool) | |
1859 | |
1860 | |
1861 ;;;###autoload | |
1862 (defun ebnf-syntax-buffer () | |
1863 "Does a syntatic analysis of the current buffer." | |
1864 (interactive) | |
1865 (ebnf-syntax-region (point-min) (point-max))) | |
1866 | |
1867 | |
1868 ;;;###autoload | |
1869 (defun ebnf-syntax-region (from to) | |
1870 "Does a syntatic analysis of a region." | |
1871 (interactive "r") | |
1872 (ebnf-generate-region from to nil)) | |
1873 | |
1874 | |
1875 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1876 ;; Utilities | |
1877 | |
1878 | |
1879 ;;;###autoload | |
1880 (defun ebnf-setup () | |
1881 "Return the current ebnf2ps setup." | |
1882 (format | |
1883 " | |
34803
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
1884 ;;; ebnf2ps.el version %s |
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
1885 |
27451 | 1886 \(setq ebnf-special-font %s |
1887 ebnf-special-shape %s | |
1888 ebnf-special-shadow %S | |
1889 ebnf-special-border-width %S | |
1890 ebnf-special-border-color %S | |
1891 ebnf-except-font %s | |
1892 ebnf-except-shape %s | |
1893 ebnf-except-shadow %S | |
1894 ebnf-except-border-width %S | |
1895 ebnf-except-border-color %S | |
1896 ebnf-repeat-font %s | |
1897 ebnf-repeat-shape %s | |
1898 ebnf-repeat-shadow %S | |
1899 ebnf-repeat-border-width %S | |
1900 ebnf-repeat-border-color %S | |
1901 ebnf-terminal-regexp %S | |
1902 ebnf-case-fold-search %S | |
1903 ebnf-terminal-font %s | |
1904 ebnf-terminal-shape %s | |
1905 ebnf-terminal-shadow %S | |
1906 ebnf-terminal-border-width %S | |
1907 ebnf-terminal-border-color %S | |
1908 ebnf-non-terminal-font %s | |
1909 ebnf-non-terminal-shape %s | |
1910 ebnf-non-terminal-shadow %S | |
1911 ebnf-non-terminal-border-width %S | |
1912 ebnf-non-terminal-border-color %S | |
1913 ebnf-sort-production %s | |
1914 ebnf-production-font %s | |
1915 ebnf-arrow-shape %s | |
1916 ebnf-chart-shape %s | |
1917 ebnf-user-arrow %s | |
1918 ebnf-horizontal-orientation %S | |
1919 ebnf-horizontal-max-height %S | |
1920 ebnf-production-horizontal-space %S | |
1921 ebnf-production-vertical-space %S | |
1922 ebnf-justify-sequence %s | |
1923 ebnf-lex-comment-char ?\\%03o | |
1924 ebnf-lex-eop-char ?\\%03o | |
1925 ebnf-syntax %s | |
1926 ebnf-iso-alternative-p %S | |
1927 ebnf-iso-normalize-p %S | |
1928 ebnf-eps-prefix %S | |
1929 ebnf-entry-percentage %S | |
1930 ebnf-color-p %S | |
1931 ebnf-line-width %S | |
1932 ebnf-line-color %S | |
1933 ebnf-debug-ps %S | |
1934 ebnf-use-float-format %S | |
1935 ebnf-yac-ignore-error-recovery %S | |
1936 ebnf-ignore-empty-rule %S | |
1937 ebnf-optimize %S) | |
34803
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
1938 |
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
1939 ;;; ebnf2ps.el - end of settings |
27451 | 1940 " |
34803
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
1941 ebnf-version |
27451 | 1942 (ps-print-quote ebnf-special-font) |
1943 (ps-print-quote ebnf-special-shape) | |
1944 ebnf-special-shadow | |
1945 ebnf-special-border-width | |
1946 ebnf-special-border-color | |
1947 (ps-print-quote ebnf-except-font) | |
1948 (ps-print-quote ebnf-except-shape) | |
1949 ebnf-except-shadow | |
1950 ebnf-except-border-width | |
1951 ebnf-except-border-color | |
1952 (ps-print-quote ebnf-repeat-font) | |
1953 (ps-print-quote ebnf-repeat-shape) | |
1954 ebnf-repeat-shadow | |
1955 ebnf-repeat-border-width | |
1956 ebnf-repeat-border-color | |
1957 ebnf-terminal-regexp | |
1958 ebnf-case-fold-search | |
1959 (ps-print-quote ebnf-terminal-font) | |
1960 (ps-print-quote ebnf-terminal-shape) | |
1961 ebnf-terminal-shadow | |
1962 ebnf-terminal-border-width | |
1963 ebnf-terminal-border-color | |
1964 (ps-print-quote ebnf-non-terminal-font) | |
1965 (ps-print-quote ebnf-non-terminal-shape) | |
1966 ebnf-non-terminal-shadow | |
1967 ebnf-non-terminal-border-width | |
1968 ebnf-non-terminal-border-color | |
1969 (ps-print-quote ebnf-sort-production) | |
1970 (ps-print-quote ebnf-production-font) | |
1971 (ps-print-quote ebnf-arrow-shape) | |
1972 (ps-print-quote ebnf-chart-shape) | |
1973 (ps-print-quote ebnf-user-arrow) | |
1974 ebnf-horizontal-orientation | |
1975 ebnf-horizontal-max-height | |
1976 ebnf-production-horizontal-space | |
1977 ebnf-production-vertical-space | |
1978 (ps-print-quote ebnf-justify-sequence) | |
1979 ebnf-lex-comment-char | |
1980 ebnf-lex-eop-char | |
1981 (ps-print-quote ebnf-syntax) | |
1982 ebnf-iso-alternative-p | |
1983 ebnf-iso-normalize-p | |
1984 ebnf-eps-prefix | |
1985 ebnf-entry-percentage | |
1986 ebnf-color-p | |
1987 ebnf-line-width | |
1988 ebnf-line-color | |
1989 ebnf-debug-ps | |
1990 ebnf-use-float-format | |
1991 ebnf-yac-ignore-error-recovery | |
1992 ebnf-ignore-empty-rule | |
1993 ebnf-optimize)) | |
1994 | |
1995 | |
1996 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1997 ;; Style variables | |
1998 | |
1999 | |
2000 (defvar ebnf-stack-style nil | |
2001 "Used in functions `ebnf-reset-style', `ebnf-push-style' and | |
2002 `ebnf-pop-style'.") | |
2003 | |
2004 | |
2005 (defvar ebnf-current-style 'default | |
2006 "Used in functions `ebnf-apply-style' and `ebnf-push-style'.") | |
2007 | |
2008 | |
2009 (defconst ebnf-style-custom-list | |
2010 '(ebnf-special-font | |
2011 ebnf-special-shape | |
2012 ebnf-special-shadow | |
2013 ebnf-special-border-width | |
2014 ebnf-special-border-color | |
2015 ebnf-except-font | |
2016 ebnf-except-shape | |
2017 ebnf-except-shadow | |
2018 ebnf-except-border-width | |
2019 ebnf-except-border-color | |
2020 ebnf-repeat-font | |
2021 ebnf-repeat-shape | |
2022 ebnf-repeat-shadow | |
2023 ebnf-repeat-border-width | |
2024 ebnf-repeat-border-color | |
2025 ebnf-terminal-regexp | |
2026 ebnf-case-fold-search | |
2027 ebnf-terminal-font | |
2028 ebnf-terminal-shape | |
2029 ebnf-terminal-shadow | |
2030 ebnf-terminal-border-width | |
2031 ebnf-terminal-border-color | |
2032 ebnf-non-terminal-font | |
2033 ebnf-non-terminal-shape | |
2034 ebnf-non-terminal-shadow | |
2035 ebnf-non-terminal-border-width | |
2036 ebnf-non-terminal-border-color | |
2037 ebnf-sort-production | |
2038 ebnf-production-font | |
2039 ebnf-arrow-shape | |
2040 ebnf-chart-shape | |
2041 ebnf-user-arrow | |
2042 ebnf-horizontal-orientation | |
2043 ebnf-horizontal-max-height | |
2044 ebnf-production-horizontal-space | |
2045 ebnf-production-vertical-space | |
2046 ebnf-justify-sequence | |
2047 ebnf-lex-comment-char | |
2048 ebnf-lex-eop-char | |
2049 ebnf-syntax | |
2050 ebnf-iso-alternative-p | |
2051 ebnf-iso-normalize-p | |
2052 ebnf-eps-prefix | |
2053 ebnf-entry-percentage | |
2054 ebnf-color-p | |
2055 ebnf-line-width | |
2056 ebnf-line-color | |
2057 ebnf-debug-ps | |
2058 ebnf-use-float-format | |
2059 ebnf-yac-ignore-error-recovery | |
2060 ebnf-ignore-empty-rule | |
2061 ebnf-optimize) | |
2062 "List of valid symbol custom variable.") | |
2063 | |
2064 | |
2065 (defvar ebnf-style-database | |
2066 '(;; EBNF default | |
2067 (default | |
2068 nil | |
2069 (ebnf-special-font . '(7 Courier "Black" "Gray95" bold italic)) | |
2070 (ebnf-special-shape . 'bevel) | |
2071 (ebnf-special-shadow . nil) | |
2072 (ebnf-special-border-width . 0.5) | |
2073 (ebnf-special-border-color . "Black") | |
2074 (ebnf-except-font . '(7 Courier "Black" "Gray90" bold italic)) | |
2075 (ebnf-except-shape . 'bevel) | |
2076 (ebnf-except-shadow . nil) | |
2077 (ebnf-except-border-width . 0.25) | |
2078 (ebnf-except-border-color . "Black") | |
2079 (ebnf-repeat-font . '(7 Courier "Black" "Gray85" bold italic)) | |
2080 (ebnf-repeat-shape . 'bevel) | |
2081 (ebnf-repeat-shadow . nil) | |
2082 (ebnf-repeat-border-width . 0.0) | |
2083 (ebnf-repeat-border-color . "Black") | |
2084 (ebnf-terminal-regexp . nil) | |
2085 (ebnf-case-fold-search . nil) | |
2086 (ebnf-terminal-font . '(7 Courier "Black" "White")) | |
2087 (ebnf-terminal-shape . 'miter) | |
2088 (ebnf-terminal-shadow . nil) | |
2089 (ebnf-terminal-border-width . 1.0) | |
2090 (ebnf-terminal-border-color . "Black") | |
2091 (ebnf-non-terminal-font . '(7 Helvetica "Black" "White")) | |
2092 (ebnf-non-terminal-shape . 'round) | |
2093 (ebnf-non-terminal-shadow . nil) | |
2094 (ebnf-non-terminal-border-width . 1.0) | |
2095 (ebnf-non-terminal-border-color . "Black") | |
2096 (ebnf-sort-production . nil) | |
2097 (ebnf-production-font . '(10 Helvetica "Black" "White" bold)) | |
2098 (ebnf-arrow-shape . 'hollow) | |
2099 (ebnf-chart-shape . 'round) | |
2100 (ebnf-user-arrow . nil) | |
2101 (ebnf-horizontal-orientation . nil) | |
2102 (ebnf-horizontal-max-height . nil) | |
2103 (ebnf-production-horizontal-space . 0.0) | |
2104 (ebnf-production-vertical-space . 0.0) | |
2105 (ebnf-justify-sequence . 'center) | |
2106 (ebnf-lex-comment-char . ?\;) | |
2107 (ebnf-lex-eop-char . ?.) | |
2108 (ebnf-syntax . 'ebnf) | |
2109 (ebnf-iso-alternative-p . nil) | |
2110 (ebnf-iso-normalize-p . nil) | |
2111 (ebnf-eps-prefix . "ebnf--") | |
2112 (ebnf-entry-percentage . 0.5) | |
2113 (ebnf-color-p . (or (fboundp 'x-color-values) ; Emacs | |
2114 (fboundp 'color-instance-rgb-components))) ; XEmacs | |
2115 (ebnf-line-width . 1.0) | |
2116 (ebnf-line-color . "Black") | |
2117 (ebnf-debug-ps . nil) | |
2118 (ebnf-use-float-format . t) | |
2119 (ebnf-yac-ignore-error-recovery . nil) | |
2120 (ebnf-ignore-empty-rule . nil) | |
2121 (ebnf-optimize . nil)) | |
2122 ;; Happy EBNF default | |
2123 (happy | |
2124 default | |
2125 (ebnf-justify-sequence . 'left) | |
2126 (ebnf-lex-comment-char . ?\#) | |
2127 (ebnf-lex-eop-char . ?\;)) | |
2128 ;; ISO EBNF default | |
2129 (iso-ebnf | |
2130 default | |
2131 (ebnf-syntax . 'iso-ebnf)) | |
2132 ;; Yacc/Bison default | |
2133 (yacc | |
2134 default | |
2135 (ebnf-syntax . 'yacc)) | |
2136 ) | |
2137 "Style database. | |
2138 | |
2139 Each element has the following form: | |
2140 | |
2141 (CUSTOM INHERITS (VAR . VALUE)...) | |
2142 | |
2143 CUSTOM is a symbol name style. | |
2144 INHERITS is a symbol name style from which the current style inherits the | |
2145 context. If INHERITS is nil, means that there is no inheritance. | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
2146 VAR is a valid ebnf2ps symbol custom variable. See `ebnf-style-custom-list' |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
2147 for valid symbol variable. |
27451 | 2148 VALUE is a sexp which it'll be evaluated to set the value to VAR. So, don't |
2149 forget to quote symbols and constant lists. See `default' style for an | |
2150 example. | |
2151 | |
2152 Don't handle this variable directly. Use functions `ebnf-insert-style' and | |
2153 `ebnf-merge-style'.") | |
2154 | |
2155 | |
2156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
2157 ;; Style commands | |
2158 | |
2159 | |
2160 ;;;###autoload | |
2161 (defun ebnf-insert-style (name inherits &rest values) | |
2162 "Insert a new style NAME with inheritance INHERITS and values VALUES." | |
2163 (interactive) | |
2164 (and (assoc name ebnf-style-database) | |
2165 (error "Style name already exists: %s" name)) | |
2166 (or (assoc inherits ebnf-style-database) | |
2167 (error "Style inheritance name does'nt exist: %s" inherits)) | |
2168 (setq ebnf-style-database | |
2169 (cons (cons name (cons inherits (ebnf-check-style-values values))) | |
2170 ebnf-style-database))) | |
2171 | |
2172 | |
2173 ;;;###autoload | |
2174 (defun ebnf-merge-style (name &rest values) | |
2175 "Merge values of style NAME with style VALUES." | |
2176 (interactive) | |
2177 (let ((style (or (assoc name ebnf-style-database) | |
2178 (error "Style name does'nt exist: %s" name))) | |
2179 (merge (ebnf-check-style-values values)) | |
2180 val elt new check) | |
2181 ;; modify value of existing variables | |
2182 (setq val (nthcdr 2 style)) | |
2183 (while merge | |
2184 (setq check (car merge) | |
2185 merge (cdr merge) | |
2186 elt (assoc (car check) val)) | |
2187 (if elt | |
2188 (setcdr elt (cdr check)) | |
2189 (setq new (cons check new)))) | |
2190 ;; insert new variables | |
2191 (nconc style (nreverse new)))) | |
2192 | |
2193 | |
2194 ;;;###autoload | |
2195 (defun ebnf-apply-style (style) | |
2196 "Set STYLE to current style. | |
2197 | |
2198 It returns the old style symbol." | |
2199 (interactive) | |
2200 (prog1 | |
2201 ebnf-current-style | |
2202 (and (ebnf-apply-style1 style) | |
2203 (setq ebnf-current-style style)))) | |
2204 | |
2205 | |
2206 ;;;###autoload | |
2207 (defun ebnf-reset-style (&optional style) | |
2208 "Reset current style. | |
2209 | |
2210 It returns the old style symbol." | |
2211 (interactive) | |
2212 (setq ebnf-stack-style nil) | |
2213 (ebnf-apply-style (or style 'default))) | |
2214 | |
2215 | |
2216 ;;;###autoload | |
2217 (defun ebnf-push-style (&optional style) | |
2218 "Push the current style and set STYLE to current style. | |
2219 | |
2220 It returns the old style symbol." | |
2221 (interactive) | |
2222 (prog1 | |
2223 ebnf-current-style | |
2224 (setq ebnf-stack-style (cons ebnf-current-style ebnf-stack-style)) | |
2225 (and style | |
2226 (ebnf-apply-style style)))) | |
2227 | |
2228 | |
2229 ;;;###autoload | |
2230 (defun ebnf-pop-style () | |
2231 "Pop a style and set it to current style. | |
2232 | |
2233 It returns the old style symbol." | |
2234 (interactive) | |
2235 (prog1 | |
2236 (ebnf-apply-style (car ebnf-stack-style)) | |
2237 (setq ebnf-stack-style (cdr ebnf-stack-style)))) | |
2238 | |
2239 | |
2240 (defun ebnf-apply-style1 (style) | |
2241 (let ((value (cdr (assoc style ebnf-style-database)))) | |
2242 (prog1 | |
2243 value | |
2244 (and (car value) (ebnf-apply-style1 (car value))) | |
2245 (while (setq value (cdr value)) | |
2246 (set (caar value) (eval (cdar value))))))) | |
2247 | |
2248 | |
2249 (defun ebnf-check-style-values (values) | |
2250 (let (style) | |
2251 (while values | |
2252 (and (memq (car values) ebnf-style-custom-list) | |
2253 (setq style (cons (car values) style))) | |
2254 (setq values (cdr values))) | |
2255 (nreverse style))) | |
2256 | |
2257 | |
2258 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
2259 ;; Internal variables | |
2260 | |
2261 | |
2262 (make-local-hook 'ebnf-hook) | |
2263 (make-local-hook 'ebnf-production-hook) | |
2264 (make-local-hook 'ebnf-page-hook) | |
2265 | |
2266 | |
2267 (defvar ebnf-eps-buffer-name " *EPS*") | |
2268 (defvar ebnf-parser-func nil) | |
2269 (defvar ebnf-eps-executing nil) | |
2270 (defvar ebnf-eps-upper-x 0.0) | |
2271 (make-variable-buffer-local 'ebnf-eps-upper-x) | |
2272 (defvar ebnf-eps-upper-y 0.0) | |
2273 (make-variable-buffer-local 'ebnf-eps-upper-y) | |
2274 (defvar ebnf-eps-prod-width 0.0) | |
2275 (make-variable-buffer-local 'ebnf-eps-prod-width) | |
2276 (defvar ebnf-eps-max-height 0.0) | |
2277 (make-variable-buffer-local 'ebnf-eps-max-height) | |
2278 (defvar ebnf-eps-max-width 0.0) | |
2279 (make-variable-buffer-local 'ebnf-eps-max-width) | |
2280 | |
2281 | |
2282 (defvar ebnf-eps-context nil | |
2283 "List of EPS file name during parsing. | |
2284 | |
2285 See section \"Actions in Comments\" in ebnf2ps documentation.") | |
2286 | |
2287 | |
2288 (defvar ebnf-eps-production-list nil | |
2289 "Alist associating production name with EPS file name list. | |
2290 | |
2291 Each element has the following form: | |
2292 | |
2293 (PRODUCTION EPS-FILENAME...) | |
2294 | |
2295 PRODUCTION is the production name. | |
2296 EPS-FILENAME is the EPS file name. | |
2297 | |
2298 It's generated during parsing and used during EPS generation. | |
2299 | |
2300 See `ebnf-eps-context' and section \"Actions in Comments\" in ebnf2ps | |
2301 documentation.") | |
2302 | |
2303 | |
2304 (defconst ebnf-arrow-shape-alist | |
2305 '((none . 0) | |
2306 (semi-up . 1) | |
2307 (semi-down . 2) | |
2308 (simple . 3) | |
2309 (transparent . 4) | |
2310 (hollow . 5) | |
2311 (full . 6) | |
2312 (user . 7)) | |
2313 "Alist associating values for `ebnf-arrow-shape'. | |
2314 | |
2315 See documentation for `ebnf-arrow-shape'.") | |
2316 | |
2317 | |
2318 (defconst ebnf-terminal-shape-alist | |
2319 '((miter . 0) | |
2320 (round . 1) | |
2321 (bevel . 2)) | |
2322 "Alist associating values from `ebnf-terminal-shape' to a bit vector. | |
2323 | |
2324 See documentation for `ebnf-terminal-shape', `ebnf-non-terminal-shape' and | |
2325 `ebnf-chart-shape'.") | |
2326 | |
2327 | |
2328 (defvar ebnf-limit nil) | |
2329 (defvar ebnf-action nil) | |
2330 (defvar ebnf-action-list nil) | |
2331 | |
2332 | |
2333 (defvar ebnf-default-p nil) | |
2334 | |
2335 | |
2336 (defvar ebnf-font-height-P 0) | |
2337 (defvar ebnf-font-height-T 0) | |
2338 (defvar ebnf-font-height-NT 0) | |
2339 (defvar ebnf-font-height-S 0) | |
2340 (defvar ebnf-font-height-E 0) | |
2341 (defvar ebnf-font-height-R 0) | |
2342 (defvar ebnf-font-width-P 0) | |
2343 (defvar ebnf-font-width-T 0) | |
2344 (defvar ebnf-font-width-NT 0) | |
2345 (defvar ebnf-font-width-S 0) | |
2346 (defvar ebnf-font-width-E 0) | |
2347 (defvar ebnf-font-width-R 0) | |
2348 (defvar ebnf-space-T 0) | |
2349 (defvar ebnf-space-NT 0) | |
2350 (defvar ebnf-space-S 0) | |
2351 (defvar ebnf-space-E 0) | |
2352 (defvar ebnf-space-R 0) | |
2353 | |
2354 | |
2355 (defvar ebnf-basic-width 0) | |
2356 (defvar ebnf-basic-height 0) | |
2357 (defvar ebnf-vertical-space 0) | |
2358 (defvar ebnf-horizontal-space 0) | |
2359 | |
2360 | |
2361 (defvar ebnf-settings nil) | |
2362 (defvar ebnf-fonts-required nil) | |
2363 | |
2364 | |
2365 (defconst ebnf-debug | |
2366 " | |
2367 % === begin EBNF procedures to help debugging | |
2368 | |
2369 % Mark visually current point: string debug | |
2370 /debug | |
2371 {/-s- exch def | |
2372 currentpoint | |
2373 gsave -s- show grestore | |
2374 gsave | |
2375 20 20 rlineto | |
2376 0 -40 rlineto | |
2377 -40 40 rlineto | |
2378 0 -40 rlineto | |
2379 20 20 rlineto | |
2380 stroke | |
2381 grestore | |
2382 moveto | |
2383 }def | |
2384 | |
2385 % Show number value: number string debug-number | |
2386 /debug-number | |
2387 {gsave | |
2388 20 0 rmoveto show ([) show 60 string cvs show (]) show | |
2389 grestore | |
2390 }def | |
2391 | |
2392 % === end EBNF procedures to help debugging | |
2393 | |
2394 " | |
2395 "This is intended to help debugging PostScript programming.") | |
2396 | |
2397 | |
2398 (defconst ebnf-prologue | |
2399 " | |
2400 % === begin EBNF engine | |
2401 | |
2402 % --- Basic Definitions | |
2403 | |
2404 /fS F | |
2405 /SpaceS FontHeight 0.5 mul def | |
2406 /HeightS FontHeight FontHeight add def | |
2407 | |
2408 /fE F | |
2409 /SpaceE FontHeight 0.5 mul def | |
2410 /HeightE FontHeight FontHeight add def | |
2411 | |
2412 /fR F | |
2413 /SpaceR FontHeight 0.5 mul def | |
2414 /HeightR FontHeight FontHeight add def | |
2415 | |
2416 /fT F | |
2417 /SpaceT FontHeight 0.5 mul def | |
2418 /HeightT FontHeight FontHeight add def | |
2419 | |
2420 /fNT F | |
2421 /SpaceNT FontHeight 0.5 mul def | |
2422 /HeightNT FontHeight FontHeight add def | |
2423 | |
2424 /T HeightT HeightNT add 0.5 mul def | |
2425 /hT T 0.5 mul def | |
2426 /hT2 hT 0.5 mul def | |
2427 /hT4 hT 0.25 mul def | |
2428 | |
2429 /Er 0.1 def % Error factor | |
2430 | |
2431 | |
2432 /c{currentpoint}bind def | |
2433 /xyi{/xi c /yi exch def def}bind def | |
2434 /xyo{/xo c /yo exch def def}bind def | |
2435 /xyp{/xp c /yp exch def def}bind def | |
2436 /xyt{/xt c /yt exch def def}bind def | |
2437 | |
2438 % vertical movement: x y height vm | |
2439 /vm{add moveto}bind def | |
2440 | |
2441 % horizontal movement: x y width hm | |
2442 /hm{3 -1 roll exch add exch moveto}bind def | |
2443 | |
2444 % set color: [R G B] SetRGB | |
2445 /SetRGB{aload pop setrgbcolor}bind def | |
2446 | |
2447 % filling gray area: gray-scale FillGray | |
2448 /FillGray{gsave setgray fill grestore}bind def | |
2449 | |
2450 % filling color area: [R G B] FillRGB | |
2451 /FillRGB{gsave SetRGB fill grestore}bind def | |
2452 | |
2453 /Stroke{LineWidth setlinewidth LineColor SetRGB stroke}bind def | |
2454 /StrokeShape{borderwidth setlinewidth bordercolor SetRGB stroke}bind def | |
2455 /Gstroke{gsave Stroke grestore}bind def | |
2456 | |
2457 % Empty Line: width EL | |
2458 /EL{0 rlineto Gstroke}bind def | |
2459 | |
2460 % --- Arrows | |
2461 | |
2462 /Down{hT2 neg hT4 neg rlineto}bind def | |
2463 | |
2464 /Arrow | |
2465 {hT2 neg hT4 rmoveto | |
2466 hT2 hT4 neg rlineto | |
2467 Down | |
2468 }bind def | |
2469 | |
2470 /ArrowPath{c newpath moveto Arrow closepath}bind def | |
2471 | |
2472 %>Right Arrow: RA | |
2473 % \\ | |
2474 % *---+ | |
2475 % / | |
2476 /RA-vector | |
2477 [{} % 0 - none | |
2478 {hT2 neg hT4 rlineto} % 1 - semi-up | |
2479 {Down} % 2 - semi-down | |
2480 {Arrow} % 3 - simple | |
2481 {Gstroke ArrowPath} % 4 - transparent | |
2482 {Gstroke ArrowPath 1 FillGray} % 5 - hollow | |
2483 {Gstroke ArrowPath LineColor FillRGB} % 6 - full | |
2484 {Gstroke gsave UserArrow grestore} % 7 - user | |
2485 ]def | |
2486 | |
2487 /RA | |
2488 {hT 0 rlineto | |
2489 c | |
2490 RA-vector ArrowShape get exec | |
2491 Gstroke | |
2492 moveto | |
2493 }def | |
2494 | |
2495 % rotation DrawArrow | |
2496 /DrawArrow | |
2497 {gsave | |
2498 0 0 translate | |
2499 rotate | |
2500 RA | |
2501 c | |
2502 grestore | |
2503 rmoveto | |
2504 }def | |
2505 | |
2506 %>Left Arrow: LA | |
2507 % / | |
2508 % +---* | |
2509 % \\ | |
2510 /LA{180 DrawArrow}def | |
2511 | |
2512 %>Up Arrow: UA | |
2513 % + | |
2514 % /|\\ | |
2515 % | | |
2516 % * | |
2517 /UA{90 DrawArrow}def | |
2518 | |
2519 %>Down Arrow: DA | |
2520 % * | |
2521 % | | |
2522 % \\|/ | |
2523 % + | |
2524 /DA{270 DrawArrow}def | |
2525 | |
2526 % --- Corners | |
2527 | |
2528 %>corner Right Descendent: height arrow corner_RD | |
2529 % _ | arrow | |
2530 % / height > 0 | 0 - none | |
2531 % | | 1 - right | |
2532 % * ---------- | 2 - left | |
2533 % | | 3 - vertical | |
2534 % \\ height < 0 | | |
2535 % - | | |
2536 /cRD0-vector | |
2537 [% 0 - none | |
2538 {0 h rlineto | |
2539 hT 0 rlineto} | |
2540 % 1 - right | |
2541 {0 h rlineto | |
2542 RA} | |
2543 % 2 - left | |
2544 {hT 0 rmoveto xyi | |
2545 LA | |
2546 0 h neg rlineto | |
2547 xi yi moveto} | |
2548 % 3 - vertical | |
2549 {hT h rmoveto xyi | |
2550 hT neg 0 rlineto | |
2551 h 0 gt{DA}{UA}ifelse | |
2552 xi yi moveto} | |
2553 ]def | |
2554 | |
2555 /cRD-vector | |
2556 [{cRD0-vector arrow get exec} % 0 - miter | |
2557 {0 0 0 h hT h rcurveto} % 1 - rounded | |
2558 {hT h rlineto} % 2 - bevel | |
2559 ]def | |
2560 | |
2561 /corner_RD | |
2562 {/arrow exch def /h exch def | |
2563 cRD-vector ChartShape get exec | |
2564 Gstroke | |
2565 }def | |
2566 | |
2567 %>corner Right Ascendent: height arrow corner_RA | |
2568 % | arrow | |
2569 % | height > 0 | 0 - none | |
2570 % / | 1 - right | |
2571 % *- ---------- | 2 - left | |
2572 % \\ | 3 - vertical | |
2573 % | height < 0 | | |
2574 % | | |
2575 /cRA0-vector | |
2576 [% 0 - none | |
2577 {hT 0 rlineto | |
2578 0 h rlineto} | |
2579 % 1 - right | |
2580 {RA | |
2581 0 h rlineto} | |
2582 % 2 - left | |
2583 {hT h rmoveto xyi | |
2584 0 h neg rlineto | |
2585 LA | |
2586 xi yi moveto} | |
2587 % 3 - vertical | |
2588 {hT h rmoveto xyi | |
2589 h 0 gt{DA}{UA}ifelse | |
2590 hT neg 0 rlineto | |
2591 xi yi moveto} | |
2592 ]def | |
2593 | |
2594 /cRA-vector | |
2595 [{cRA0-vector arrow get exec} % 0 - miter | |
2596 {0 0 hT 0 hT h rcurveto} % 1 - rounded | |
2597 {hT h rlineto} % 2 - bevel | |
2598 ]def | |
2599 | |
2600 /corner_RA | |
2601 {/arrow exch def /h exch def | |
2602 cRA-vector ChartShape get exec | |
2603 Gstroke | |
2604 }def | |
2605 | |
2606 %>corner Left Descendent: height arrow corner_LD | |
2607 % _ | arrow | |
2608 % \\ height > 0 | 0 - none | |
2609 % | | 1 - right | |
2610 % * ---------- | 2 - left | |
2611 % | | 3 - vertical | |
2612 % / height < 0 | | |
2613 % - | | |
2614 /cLD0-vector | |
2615 [% 0 - none | |
2616 {0 h rlineto | |
2617 hT neg 0 rlineto} | |
2618 % 1 - right | |
2619 {hT neg h rmoveto xyi | |
2620 RA | |
2621 0 h neg rlineto | |
2622 xi yi moveto} | |
2623 % 2 - left | |
2624 {0 h rlineto | |
2625 LA} | |
2626 % 3 - vertical | |
2627 {hT neg h rmoveto xyi | |
2628 hT 0 rlineto | |
2629 h 0 gt{DA}{UA}ifelse | |
2630 xi yi moveto} | |
2631 ]def | |
2632 | |
2633 /cLD-vector | |
2634 [{cLD0-vector arrow get exec} % 0 - miter | |
2635 {0 0 0 h hT neg h rcurveto} % 1 - rounded | |
2636 {hT neg h rlineto} % 2 - bevel | |
2637 ]def | |
2638 | |
2639 /corner_LD | |
2640 {/arrow exch def /h exch def | |
2641 cLD-vector ChartShape get exec | |
2642 Gstroke | |
2643 }def | |
2644 | |
2645 %>corner Left Ascendent: height arrow corner_LA | |
2646 % | arrow | |
2647 % | height > 0 | 0 - none | |
2648 % \\ | 1 - right | |
2649 % -* ---------- | 2 - left | |
2650 % / | 3 - vertical | |
2651 % | height < 0 | | |
2652 % | | |
2653 /cLA0-vector | |
2654 [% 0 - none | |
2655 {hT neg 0 rlineto | |
2656 0 h rlineto} | |
2657 % 1 - right | |
2658 {hT neg h rmoveto xyi | |
2659 0 h neg rlineto | |
2660 RA | |
2661 xi yi moveto} | |
2662 % 2 - left | |
2663 {LA | |
2664 0 h rlineto} | |
2665 % 3 - vertical | |
2666 {hT neg h rmoveto xyi | |
2667 h 0 gt{DA}{UA}ifelse | |
2668 hT 0 rlineto | |
2669 xi yi moveto} | |
2670 ]def | |
2671 | |
2672 /cLA-vector | |
2673 [{cLA0-vector arrow get exec} % 0 - miter | |
2674 {0 0 hT neg 0 hT neg h rcurveto} % 1 - rounded | |
2675 {hT neg h rlineto} % 2 - bevel | |
2676 ]def | |
2677 | |
2678 /corner_LA | |
2679 {/arrow exch def /h exch def | |
2680 cLA-vector ChartShape get exec | |
2681 Gstroke | |
2682 }def | |
2683 | |
2684 % --- Flow Stuff | |
2685 | |
2686 % height prepare_height |- line_height corner_height corner_height | |
2687 /prepare_height | |
2688 {dup 0 gt | |
2689 {T sub hT} | |
2690 {T add hT neg}ifelse | |
2691 dup | |
2692 }def | |
2693 | |
2694 %>Left Alternative: height LAlt | |
2695 % _ | |
2696 % / | |
2697 % | height > 0 | |
2698 % | | |
2699 % / | |
2700 % *- ---------- | |
2701 % \\ | |
2702 % | | |
2703 % | height < 0 | |
2704 % \\ | |
2705 % - | |
2706 /LAlt | |
2707 {dup 0 eq | |
2708 {T exch rlineto} | |
2709 {dup abs T lt | |
2710 {0.5 mul dup | |
2711 1 corner_RA | |
2712 0 corner_RD} | |
2713 {prepare_height | |
2714 1 corner_RA | |
2715 exch 0 exch rlineto | |
2716 0 corner_RD | |
2717 }ifelse | |
2718 }ifelse | |
2719 }def | |
2720 | |
2721 %>Left Loop: height LLoop | |
2722 % _ | |
2723 % / | |
2724 % | height > 0 | |
2725 % | | |
2726 % \\ | |
2727 % -* ---------- | |
2728 % / | |
2729 % | | |
2730 % | height < 0 | |
2731 % \\ | |
2732 % - | |
2733 /LLoop | |
2734 {prepare_height | |
2735 3 corner_LA | |
2736 exch 0 exch rlineto | |
2737 0 corner_RD | |
2738 }def | |
2739 | |
2740 %>Right Alternative: height RAlt | |
2741 % _ | |
2742 % \\ | |
2743 % | height > 0 | |
2744 % | | |
2745 % \\ | |
2746 % -* ---------- | |
2747 % / | |
2748 % | | |
2749 % | height < 0 | |
2750 % / | |
2751 % - | |
2752 /RAlt | |
2753 {dup 0 eq | |
2754 {T neg exch rlineto} | |
2755 {dup abs T lt | |
2756 {0.5 mul dup | |
2757 1 corner_LA | |
2758 0 corner_LD} | |
2759 {prepare_height | |
2760 1 corner_LA | |
2761 exch 0 exch rlineto | |
2762 0 corner_LD | |
2763 }ifelse | |
2764 }ifelse | |
2765 }def | |
2766 | |
2767 %>Right Loop: height RLoop | |
2768 % _ | |
2769 % \\ | |
2770 % | height > 0 | |
2771 % | | |
2772 % / | |
2773 % *- ---------- | |
2774 % \\ | |
2775 % | | |
2776 % | height < 0 | |
2777 % / | |
2778 % - | |
2779 /RLoop | |
2780 {prepare_height | |
2781 1 corner_RA | |
2782 exch 0 exch rlineto | |
2783 0 corner_LD | |
2784 }def | |
2785 | |
2786 % --- Terminal, Non-terminal and Special Basics | |
2787 | |
2788 % string width prepare-width |- string | |
2789 /prepare-width | |
2790 {/width exch def | |
2791 dup stringwidth pop space add space add width exch sub 0.5 mul | |
2792 /w exch def | |
2793 }def | |
2794 | |
2795 % string width begin-right | |
2796 /begin-right | |
2797 {xyo | |
2798 prepare-width | |
2799 w hT sub EL | |
2800 RA | |
2801 }def | |
2802 | |
2803 % end-right | |
2804 /end-right | |
2805 {xo width add Er add yo moveto | |
2806 w Er add neg EL | |
2807 xo yo moveto | |
2808 }def | |
2809 | |
2810 % string width begin-left | |
2811 /begin-left | |
2812 {xyo | |
2813 prepare-width | |
2814 w EL | |
2815 }def | |
2816 | |
2817 % end-left | |
2818 /end-left | |
2819 {xo width add Er add yo moveto | |
2820 hT w sub Er add EL | |
2821 LA | |
2822 xo yo moveto | |
2823 }def | |
2824 | |
2825 /ShapePath-vector | |
2826 [% 0 - miter | |
2827 {xx yy moveto | |
2828 xx YY lineto | |
2829 XX YY lineto | |
2830 XX yy lineto} | |
2831 % 1 - rounded | |
2832 {/half YY yy sub 0.5 mul abs def | |
2833 xx half add YY moveto | |
2834 0 0 half neg 0 half neg half neg rcurveto | |
2835 0 0 0 half neg half half neg rcurveto | |
2836 XX xx sub abs half sub half sub 0 rlineto | |
2837 0 0 half 0 half half rcurveto | |
2838 0 0 0 half half neg half rcurveto} | |
2839 % 2 - bevel | |
2840 {/quarter YY yy sub 0.25 mul abs def | |
2841 xx quarter add YY moveto | |
2842 quarter neg quarter neg rlineto | |
2843 0 quarter quarter add neg rlineto | |
2844 quarter quarter neg rlineto | |
2845 XX xx sub abs quarter sub quarter sub 0 rlineto | |
2846 quarter quarter rlineto | |
2847 0 quarter quarter add rlineto | |
2848 quarter neg quarter rlineto} | |
2849 ]def | |
2850 | |
2851 /doShapePath | |
2852 {newpath | |
2853 ShapePath-vector shape get exec | |
2854 closepath | |
2855 }def | |
2856 | |
2857 /doShapeShadow | |
2858 {gsave | |
2859 Xshadow Xshadow add Xshadow add | |
2860 Yshadow Yshadow add Yshadow add translate | |
2861 doShapePath | |
2862 0.9 FillGray | |
2863 grestore | |
2864 }def | |
2865 | |
2866 /doShape | |
2867 {gsave | |
2868 doShapePath | |
2869 shapecolor FillRGB | |
2870 StrokeShape | |
2871 grestore | |
2872 }def | |
2873 | |
2874 % string SBound |- string | |
2875 /SBound | |
2876 {/xx c dup /yy exch def | |
2877 FontHeight add /YY exch def def | |
2878 dup stringwidth pop xx add /XX exch def | |
2879 Effect 8 and 0 ne | |
2880 {/yy yy YShadow add def | |
2881 /XX XX XShadow add def | |
2882 }if | |
2883 }def | |
2884 | |
2885 % string SBox | |
2886 /SBox | |
2887 {gsave | |
2888 c space sub moveto | |
2889 SBound | |
2890 /XX XX space add space add def | |
2891 /YY YY space add def | |
2892 /yy yy space sub def | |
2893 shadow{doShapeShadow}if | |
2894 doShape | |
2895 space Descent abs rmoveto | |
2896 foreground SetRGB S | |
2897 grestore | |
2898 }def | |
2899 | |
2900 % --- Terminal | |
2901 | |
2902 % TeRminal: string TR | |
2903 /TR | |
2904 {/Effect EffectT def | |
2905 /shape ShapeT def | |
2906 /shapecolor BackgroundT def | |
2907 /borderwidth BorderWidthT def | |
2908 /bordercolor BorderColorT def | |
2909 /foreground ForegroundT def | |
2910 /shadow ShadowT def | |
2911 SBox | |
2912 }def | |
2913 | |
2914 %>Right Terminal: string width RT |- x y | |
2915 /RT | |
2916 {xyt | |
2917 /fT F | |
2918 /space SpaceT def | |
2919 begin-right | |
2920 TR | |
2921 end-right | |
2922 xt yt | |
2923 }def | |
2924 | |
2925 %>Left Terminal: string width LT |- x y | |
2926 /LT | |
2927 {xyt | |
2928 /fT F | |
2929 /space SpaceT def | |
2930 begin-left | |
2931 TR | |
2932 end-left | |
2933 xt yt | |
2934 }def | |
2935 | |
2936 %>Right Terminal Default: string width RTD |- x y | |
2937 /RTD | |
2938 {/-save- BorderWidthT def | |
2939 /BorderWidthT BorderWidthT DefaultWidth add def | |
2940 RT | |
2941 /BorderWidthT -save- def | |
2942 }def | |
2943 | |
2944 %>Left Terminal Default: string width LTD |- x y | |
2945 /LTD | |
2946 {/-save- BorderWidthT def | |
2947 /BorderWidthT BorderWidthT DefaultWidth add def | |
2948 LT | |
2949 /BorderWidthT -save- def | |
2950 }def | |
2951 | |
2952 % --- Non-Terminal | |
2953 | |
2954 % Non-Terminal: string NT | |
2955 /NT | |
2956 {/Effect EffectNT def | |
2957 /shape ShapeNT def | |
2958 /shapecolor BackgroundNT def | |
2959 /borderwidth BorderWidthNT def | |
2960 /bordercolor BorderColorNT def | |
2961 /foreground ForegroundNT def | |
2962 /shadow ShadowNT def | |
2963 SBox | |
2964 }def | |
2965 | |
2966 %>Right Non-Terminal: string width RNT |- x y | |
2967 /RNT | |
2968 {xyt | |
2969 /fNT F | |
2970 /space SpaceNT def | |
2971 begin-right | |
2972 NT | |
2973 end-right | |
2974 xt yt | |
2975 }def | |
2976 | |
2977 %>Left Non-Terminal: string width LNT |- x y | |
2978 /LNT | |
2979 {xyt | |
2980 /fNT F | |
2981 /space SpaceNT def | |
2982 begin-left | |
2983 NT | |
2984 end-left | |
2985 xt yt | |
2986 }def | |
2987 | |
2988 %>Right Non-Terminal Default: string width RNTD |- x y | |
2989 /RNTD | |
2990 {/-save- BorderWidthNT def | |
2991 /BorderWidthNT BorderWidthNT DefaultWidth add def | |
2992 RNT | |
2993 /BorderWidthNT -save- def | |
2994 }def | |
2995 | |
2996 %>Left Non-Terminal Default: string width LNTD |- x y | |
2997 /LNTD | |
2998 {/-save- BorderWidthNT def | |
2999 /BorderWidthNT BorderWidthNT DefaultWidth add def | |
3000 LNT | |
3001 /BorderWidthNT -save- def | |
3002 }def | |
3003 | |
3004 % --- Special | |
3005 | |
3006 % SPecial: string SP | |
3007 /SP | |
3008 {/Effect EffectS def | |
3009 /shape ShapeS def | |
3010 /shapecolor BackgroundS def | |
3011 /borderwidth BorderWidthS def | |
3012 /bordercolor BorderColorS def | |
3013 /foreground ForegroundS def | |
3014 /shadow ShadowS def | |
3015 SBox | |
3016 }def | |
3017 | |
3018 %>Right SPecial: string width RSP |- x y | |
3019 /RSP | |
3020 {xyt | |
3021 /fS F | |
3022 /space SpaceS def | |
3023 begin-right | |
3024 SP | |
3025 end-right | |
3026 xt yt | |
3027 }def | |
3028 | |
3029 %>Left SPecial: string width LSP |- x y | |
3030 /LSP | |
3031 {xyt | |
3032 /fS F | |
3033 /space SpaceS def | |
3034 begin-left | |
3035 SP | |
3036 end-left | |
3037 xt yt | |
3038 }def | |
3039 | |
3040 %>Right SPecial Default: string width RSPD |- x y | |
3041 /RSPD | |
3042 {/-save- BorderWidthS def | |
3043 /BorderWidthS BorderWidthS DefaultWidth add def | |
3044 RSP | |
3045 /BorderWidthS -save- def | |
3046 }def | |
3047 | |
3048 %>Left SPecial Default: string width LSPD |- x y | |
3049 /LSPD | |
3050 {/-save- BorderWidthS def | |
3051 /BorderWidthS BorderWidthS DefaultWidth add def | |
3052 LSP | |
3053 /BorderWidthS -save- def | |
3054 }def | |
3055 | |
3056 % --- Repeat and Except basics | |
3057 | |
3058 /begin-direction | |
3059 {/w width rwidth sub 0.5 mul def | |
3060 width 0 rmoveto}def | |
3061 | |
3062 /end-direction | |
3063 {gsave | |
3064 /xx c entry add /YY exch def def | |
3065 /yy YY height sub def | |
3066 /XX xx rwidth add def | |
3067 shadow{doShapeShadow}if | |
3068 doShape | |
3069 grestore | |
3070 }def | |
3071 | |
3072 /right-direction | |
3073 {begin-direction | |
3074 w neg EL | |
3075 xt yt moveto | |
3076 w hT sub EL RA | |
3077 end-direction | |
3078 }def | |
3079 | |
3080 /left-direction | |
3081 {begin-direction | |
3082 hT w sub EL LA | |
3083 xt yt moveto | |
3084 w EL | |
3085 end-direction | |
3086 }def | |
3087 | |
3088 % --- Repeat | |
3089 | |
3090 % entry height width rwidth begin-repeat | |
3091 /begin-repeat | |
3092 {/rwidth exch def | |
3093 /width exch def | |
3094 /height exch def | |
3095 /entry exch def | |
3096 /fR F | |
3097 /space SpaceR def | |
3098 /Effect EffectR def | |
3099 /shape ShapeR def | |
3100 /shapecolor BackgroundR def | |
3101 /borderwidth BorderWidthR def | |
3102 /bordercolor BorderColorR def | |
3103 /foreground ForegroundR def | |
3104 /shadow ShadowR def | |
3105 xyt | |
3106 }def | |
3107 | |
3108 % string end-repeat |- x y | |
3109 /end-repeat | |
3110 {gsave | |
3111 space Descent rmoveto | |
3112 foreground SetRGB S | |
3113 c Descent sub | |
3114 grestore | |
3115 exch space add exch moveto | |
3116 xt yt | |
3117 }def | |
3118 | |
3119 %>Right RePeat: string entry height width rwidth RRP |- x y | |
3120 /RRP{begin-repeat right-direction end-repeat}def | |
3121 | |
3122 %>Left RePeat: string entry height width rwidth LRP |- x y | |
3123 /LRP{begin-repeat left-direction end-repeat}def | |
3124 | |
3125 % --- Except | |
3126 | |
3127 % entry height width rwidth begin-except | |
3128 /begin-except | |
3129 {/rwidth exch def | |
3130 /width exch def | |
3131 /height exch def | |
3132 /entry exch def | |
3133 /fE F | |
3134 /space SpaceE def | |
3135 /Effect EffectE def | |
3136 /shape ShapeE def | |
3137 /shapecolor BackgroundE def | |
3138 /borderwidth BorderWidthE def | |
3139 /bordercolor BorderColorE def | |
3140 /foreground ForegroundE def | |
3141 /shadow ShadowE def | |
3142 xyt | |
3143 }def | |
3144 | |
3145 % x-width end-except |- x y | |
3146 /end-except | |
3147 {gsave | |
3148 space space add add Descent rmoveto | |
3149 (-) foreground SetRGB S | |
3150 grestore | |
3151 space 0 rmoveto | |
3152 xt yt | |
3153 }def | |
3154 | |
3155 %>Right EXcept: x-width entry height width rwidth REX |- x y | |
3156 /REX{begin-except right-direction end-except}def | |
3157 | |
3158 %>Left EXcept: x-width entry height width rwidth LEX |- x y | |
3159 /LEX{begin-except left-direction end-except}def | |
3160 | |
3161 % --- Sequence | |
3162 | |
3163 %>Beginning Of Sequence: BOS |- x y | |
3164 /BOS{currentpoint}bind def | |
3165 | |
3166 %>End Of Sequence: x y x1 y1 EOS |- x y | |
3167 /EOS{pop pop}bind def | |
3168 | |
3169 % --- Production | |
3170 | |
3171 %>Beginning Of Production: string width height BOP |- y x | |
3172 /BOP | |
3173 {xyp | |
3174 neg yp add /yw exch def | |
3175 xp add T sub /xw exch def | |
3176 /Effect EffectP def | |
3177 /fP F ForegroundP SetRGB BackgroundP aload pop true BG S | |
3178 /Effect 0 def | |
3179 ( :) S false BG | |
3180 xw yw moveto | |
3181 hT EL RA | |
3182 xp yw moveto | |
3183 T EL | |
3184 yp xp | |
3185 }def | |
3186 | |
3187 %>End Of Production: y x delta EOP | |
3188 /EOPH{add exch moveto}bind def % horizontal | |
3189 /EOPV{exch pop sub 0 exch moveto}bind def % vertical | |
3190 | |
3191 % --- Empty Alternative | |
3192 | |
3193 %>Empty Alternative: width EA |- x y | |
3194 /EA | |
3195 {gsave | |
3196 Er add 0 rlineto | |
3197 Stroke | |
3198 grestore | |
3199 c | |
3200 }def | |
3201 | |
3202 % --- Alternative | |
3203 | |
3204 %>AlTernative: h1 h2 ... hn n width AT |- x y | |
3205 /AT | |
3206 {xyo xo add /xw exch def | |
3207 xw yo moveto | |
3208 Er EL | |
3209 {xw yo moveto | |
3210 dup RAlt | |
3211 xo yo moveto | |
3212 LAlt}repeat | |
3213 xo yo | |
3214 }def | |
3215 | |
3216 % --- Optional | |
3217 | |
3218 %>OPtional: height width OP |- x y | |
3219 /OP | |
3220 {xyo | |
3221 T sub /ow exch def | |
3222 ow Er sub 0 rmoveto | |
3223 T Er add EL | |
3224 neg dup RAlt | |
3225 ow T sub neg EL | |
3226 xo yo moveto | |
3227 LAlt | |
3228 xo yo moveto | |
3229 T EL | |
3230 xo yo | |
3231 }def | |
3232 | |
3233 % --- List Flow | |
3234 | |
3235 %>One or More: height width OM |- x y | |
3236 /OM | |
3237 {xyo | |
3238 /ow exch def | |
3239 ow Er add 0 rmoveto | |
3240 T Er add neg EL | |
3241 dup RLoop | |
3242 xo T add yo moveto | |
3243 LLoop | |
3244 xo yo moveto | |
3245 T EL | |
3246 xo yo | |
3247 }def | |
3248 | |
3249 %>Zero or More: h2 h1 width ZM |- x y | |
3250 /ZM | |
3251 {xyo | |
3252 Er add EL | |
3253 Er neg 0 rmoveto | |
3254 dup RAlt | |
3255 exch dup RLoop | |
3256 xo yo moveto | |
3257 exch dup LAlt | |
3258 exch LLoop | |
3259 yo add xo T add exch moveto | |
3260 xo yo | |
3261 }def | |
3262 | |
3263 % === end EBNF engine | |
3264 | |
3265 " | |
3266 "EBNF PostScript prologue") | |
3267 | |
3268 | |
3269 (defconst ebnf-eps-prologue | |
3270 " | |
3271 /#ebnf2ps#dict 230 dict def | |
3272 #ebnf2ps#dict begin | |
3273 | |
3274 % Initiliaze variables to avoid name-conflicting with document variables. | |
3275 % This is the case when using `bind' operator. | |
3276 /-fillp- 0 def /h 0 def | |
3277 /-ox- 0 def /half 0 def | |
3278 /-oy- 0 def /height 0 def | |
3279 /-save- 0 def /ow 0 def | |
3280 /Ascent 0 def /quarter 0 def | |
3281 /Descent 0 def /rXX 0 def | |
3282 /Effect 0 def /rYY 0 def | |
3283 /FontHeight 0 def /rwidth 0 def | |
3284 /LineThickness 0 def /rxx 0 def | |
3285 /OverlinePosition 0 def /ryy 0 def | |
3286 /SpaceBackground 0 def /shadow 0 def | |
3287 /StrikeoutPosition 0 def /shape 0 def | |
3288 /UnderlinePosition 0 def /shapecolor 0 def | |
3289 /XBox 0 def /space 0 def | |
3290 /XX 0 def /st 1 string def | |
3291 /Xshadow 0 def /w 0 def | |
3292 /YBox 0 def /width 0 def | |
3293 /YY 0 def /xi 0 def | |
3294 /Yshadow 0 def /xo 0 def | |
3295 /arrow 0 def /xp 0 def | |
3296 /bg false def /xt 0 def | |
3297 /bgcolor 0 def /xw 0 def | |
3298 /bordercolor 0 def /xx 0 def | |
3299 /borderwidth 0 def /yi 0 def | |
3300 /dd 0 def /yo 0 def | |
3301 /entry 0 def /yp 0 def | |
3302 /foreground 0 def /yt 0 def | |
3303 /yy 0 def | |
3304 | |
3305 | |
3306 % ISOLatin1Encoding stolen from ps_init.ps in GhostScript 2.6.1.4: | |
3307 /ISOLatin1Encoding where | |
3308 {pop} | |
3309 {% -- The ISO Latin-1 encoding vector isn't known, so define it. | |
3310 % -- The first half is the same as the standard encoding, | |
3311 % -- except for minus instead of hyphen at code 055. | |
3312 /ISOLatin1Encoding | |
3313 StandardEncoding 0 45 getinterval aload pop | |
3314 /minus | |
3315 StandardEncoding 46 82 getinterval aload pop | |
3316 %*** NOTE: the following are missing in the Adobe documentation, | |
3317 %*** but appear in the displayed table: | |
3318 %*** macron at 0225, dieresis at 0230, cedilla at 0233, space at 0240. | |
3319 % 0200 (128) | |
3320 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef | |
3321 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef | |
3322 /dotlessi /grave /acute /circumflex /tilde /macron /breve /dotaccent | |
3323 /dieresis /.notdef /ring /cedilla /.notdef /hungarumlaut /ogonek /caron | |
3324 % 0240 (160) | |
3325 /space /exclamdown /cent /sterling | |
3326 /currency /yen /brokenbar /section | |
3327 /dieresis /copyright /ordfeminine /guillemotleft | |
3328 /logicalnot /hyphen /registered /macron | |
3329 /degree /plusminus /twosuperior /threesuperior | |
3330 /acute /mu /paragraph /periodcentered | |
3331 /cedilla /onesuperior /ordmasculine /guillemotright | |
3332 /onequarter /onehalf /threequarters /questiondown | |
3333 % 0300 (192) | |
3334 /Agrave /Aacute /Acircumflex /Atilde | |
3335 /Adieresis /Aring /AE /Ccedilla | |
3336 /Egrave /Eacute /Ecircumflex /Edieresis | |
3337 /Igrave /Iacute /Icircumflex /Idieresis | |
3338 /Eth /Ntilde /Ograve /Oacute | |
3339 /Ocircumflex /Otilde /Odieresis /multiply | |
3340 /Oslash /Ugrave /Uacute /Ucircumflex | |
3341 /Udieresis /Yacute /Thorn /germandbls | |
3342 % 0340 (224) | |
3343 /agrave /aacute /acircumflex /atilde | |
3344 /adieresis /aring /ae /ccedilla | |
3345 /egrave /eacute /ecircumflex /edieresis | |
3346 /igrave /iacute /icircumflex /idieresis | |
3347 /eth /ntilde /ograve /oacute | |
3348 /ocircumflex /otilde /odieresis /divide | |
3349 /oslash /ugrave /uacute /ucircumflex | |
3350 /udieresis /yacute /thorn /ydieresis | |
3351 256 packedarray def | |
3352 }ifelse | |
3353 | |
3354 /reencodeFontISO %def | |
3355 {dup | |
3356 length 12 add dict % Make a new font (a new dict the same size | |
3357 % as the old one) with room for our new symbols. | |
3358 | |
3359 begin % Make the new font the current dictionary. | |
3360 {1 index /FID ne | |
3361 {def}{pop pop}ifelse | |
3362 }forall % Copy each of the symbols from the old dictionary | |
3363 % to the new one except for the font ID. | |
3364 | |
3365 currentdict /FontType get 0 ne | |
3366 {/Encoding ISOLatin1Encoding def}if % Override the encoding with | |
3367 % the ISOLatin1 encoding. | |
3368 | |
3369 % Use the font's bounding box to determine the ascent, descent, | |
3370 % and overall height; don't forget that these values have to be | |
3371 % transformed using the font's matrix. | |
3372 | |
3373 % ^ (x2 y2) | |
3374 % | | | |
3375 % | v | |
3376 % | +----+ - - | |
3377 % | | | ^ | |
3378 % | | | | Ascent (usually > 0) | |
3379 % | | | | | |
3380 % (0 0) -> +--+----+--------> | |
3381 % | | | | |
3382 % | | v Descent (usually < 0) | |
3383 % (x1 y1) --> +----+ - - | |
3384 | |
3385 currentdict /FontType get 0 ne | |
3386 {/FontBBox load aload pop % -- x1 y1 x2 y2 | |
3387 FontMatrix transform /Ascent exch def pop | |
3388 FontMatrix transform /Descent exch def pop} | |
3389 {/PrimaryFont FDepVector 0 get def | |
3390 PrimaryFont /FontBBox get aload pop | |
3391 PrimaryFont /FontMatrix get transform /Ascent exch def pop | |
3392 PrimaryFont /FontMatrix get transform /Descent exch def pop | |
3393 }ifelse | |
3394 | |
3395 /FontHeight Ascent Descent sub def % use `sub' because descent < 0 | |
3396 | |
3397 % Define these in case they're not in the FontInfo | |
3398 % (also, here they're easier to get to). | |
3399 /UnderlinePosition Descent 0.70 mul def | |
3400 /OverlinePosition Descent UnderlinePosition sub Ascent add def | |
3401 /StrikeoutPosition Ascent 0.30 mul def | |
3402 /LineThickness FontHeight 0.05 mul def | |
3403 /Xshadow FontHeight 0.08 mul def | |
3404 /Yshadow FontHeight -0.09 mul def | |
3405 /SpaceBackground Descent neg UnderlinePosition add def | |
3406 /XBox Descent neg def | |
3407 /YBox LineThickness 0.7 mul def | |
3408 | |
3409 currentdict % Leave the new font on the stack | |
3410 end % Stop using the font as the current dictionary | |
3411 definefont % Put the font into the font dictionary | |
3412 pop % Discard the returned font | |
3413 }bind def | |
3414 | |
3415 % Font definition | |
3416 /DefFont{findfont exch scalefont reencodeFontISO}def | |
3417 | |
3418 % Font selection | |
3419 /F | |
3420 {findfont | |
3421 dup /Ascent get /Ascent exch def | |
3422 dup /Descent get /Descent exch def | |
3423 dup /FontHeight get /FontHeight exch def | |
3424 dup /UnderlinePosition get /UnderlinePosition exch def | |
3425 dup /OverlinePosition get /OverlinePosition exch def | |
3426 dup /StrikeoutPosition get /StrikeoutPosition exch def | |
3427 dup /LineThickness get /LineThickness exch def | |
3428 dup /Xshadow get /Xshadow exch def | |
3429 dup /Yshadow get /Yshadow exch def | |
3430 dup /SpaceBackground get /SpaceBackground exch def | |
3431 dup /XBox get /XBox exch def | |
3432 dup /YBox get /YBox exch def | |
3433 setfont | |
3434 }def | |
3435 | |
3436 /BG | |
3437 {dup /bg exch def | |
3438 {mark 4 1 roll ]} | |
3439 {[ 1.0 1.0 1.0 ]} | |
3440 ifelse | |
3441 /bgcolor exch def | |
3442 }def | |
3443 | |
3444 % stack: -- | |
3445 /FillBgColor{bgcolor aload pop setrgbcolor fill}bind def | |
3446 | |
3447 % stack: fill-or-not lower-x lower-y upper-x upper-y |- -- | |
3448 /doRect | |
3449 {/rYY exch def | |
3450 /rXX exch def | |
3451 /ryy exch def | |
3452 /rxx exch def | |
3453 gsave | |
3454 newpath | |
3455 rXX rYY moveto | |
3456 rxx rYY lineto | |
3457 rxx ryy lineto | |
3458 rXX ryy lineto | |
3459 closepath | |
3460 % top of stack: fill-or-not | |
3461 {FillBgColor} | |
3462 {LineThickness setlinewidth stroke} | |
3463 ifelse | |
3464 grestore | |
3465 }bind def | |
3466 | |
3467 % stack: string fill-or-not |- -- | |
3468 /doOutline | |
3469 {/-fillp- exch def | |
3470 /-ox- currentpoint /-oy- exch def def | |
3471 gsave | |
3472 LineThickness setlinewidth | |
3473 {st 0 3 -1 roll put | |
3474 st dup true charpath | |
3475 -fillp- {gsave FillBgColor grestore}if | |
3476 stroke stringwidth | |
3477 -oy- add /-oy- exch def | |
3478 -ox- add /-ox- exch def | |
3479 -ox- -oy- moveto | |
3480 }forall | |
3481 grestore | |
3482 -ox- -oy- moveto | |
3483 }bind def | |
3484 | |
3485 % stack: fill-or-not delta |- -- | |
3486 /doBox | |
3487 {/dd exch def | |
3488 xx XBox sub dd sub yy YBox sub dd sub | |
3489 XX XBox add dd add YY YBox add dd add | |
3490 doRect | |
3491 }bind def | |
3492 | |
3493 % stack: string |- -- | |
3494 /doShadow | |
3495 {gsave | |
3496 Xshadow Yshadow rmoveto | |
3497 false doOutline | |
3498 grestore | |
3499 }bind def | |
3500 | |
3501 % stack: position |- -- | |
3502 /Hline | |
3503 {currentpoint exch pop add dup | |
3504 gsave | |
3505 newpath | |
3506 xx exch moveto | |
3507 XX exch lineto | |
3508 closepath | |
3509 LineThickness setlinewidth stroke | |
3510 grestore | |
3511 }bind def | |
3512 | |
3513 % stack: string |- -- | |
3514 % effect: 1 - underline 2 - strikeout 4 - overline | |
3515 % 8 - shadow 16 - box 32 - outline | |
3516 /S | |
3517 {/xx currentpoint dup Descent add /yy exch def | |
3518 Ascent add /YY exch def def | |
3519 dup stringwidth pop xx add /XX exch def | |
3520 Effect 8 and 0 ne | |
3521 {/yy yy Yshadow add def | |
3522 /XX XX Xshadow add def | |
3523 }if | |
3524 bg | |
3525 {true | |
3526 Effect 16 and 0 ne | |
3527 {SpaceBackground doBox} | |
3528 {xx yy XX YY doRect} | |
3529 ifelse | |
3530 }if % background | |
3531 Effect 16 and 0 ne{false 0 doBox}if % box | |
3532 Effect 8 and 0 ne{dup doShadow}if % shadow | |
3533 Effect 32 and 0 ne | |
3534 {true doOutline} % outline | |
3535 {show} % normal text | |
3536 ifelse | |
3537 Effect 1 and 0 ne{UnderlinePosition Hline}if % underline | |
3538 Effect 2 and 0 ne{StrikeoutPosition Hline}if % strikeout | |
3539 Effect 4 and 0 ne{OverlinePosition Hline}if % overline | |
3540 }bind def | |
3541 | |
3542 " | |
3543 "EBNF EPS prologue") | |
3544 | |
3545 | |
3546 (defconst ebnf-eps-begin | |
3547 " | |
3548 end | |
3549 | |
3550 % x y #ebnf2ps#begin | |
3551 /#ebnf2ps#begin | |
3552 {#ebnf2ps#dict begin /#ebnf2ps#save save def | |
3553 moveto false BG 0.0 0.0 0.0 setrgbcolor}def | |
3554 | |
3555 /#ebnf2ps#end{showpage #ebnf2ps#save restore end}def | |
3556 | |
3557 %%EndPrologue | |
3558 " | |
3559 "EBNF EPS begin") | |
3560 | |
3561 | |
3562 (defconst ebnf-eps-end | |
3563 "#ebnf2ps#end | |
3564 %%EOF | |
3565 " | |
3566 "EBNF EPS end") | |
3567 | |
3568 | |
3569 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
3570 ;; Formatting | |
3571 | |
3572 | |
3573 (defvar ebnf-format-float "%1.3f") | |
3574 | |
3575 | |
3576 (defun ebnf-format-float (&rest floats) | |
3577 (mapconcat | |
3578 #'(lambda (float) | |
3579 (format ebnf-format-float float)) | |
3580 floats | |
3581 " ")) | |
3582 | |
3583 | |
3584 (defun ebnf-format-color (format-str color default) | |
3585 (let* ((the-color (or color default)) | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
3586 (rgb (ps-color-scale the-color))) |
27451 | 3587 (format format-str |
3588 (concat "[" | |
3589 (ebnf-format-float (nth 0 rgb) (nth 1 rgb) (nth 2 rgb)) | |
3590 "]") | |
3591 the-color))) | |
3592 | |
3593 | |
3594 (defvar ebnf-message-float "%3.2f") | |
3595 | |
3596 | |
3597 (defsubst ebnf-message-float (format-str value) | |
3598 (message format-str | |
3599 (format ebnf-message-float value))) | |
3600 | |
3601 | |
3602 (defsubst ebnf-message-info (messag) | |
3603 (message "%s...%3d%%" | |
3604 messag | |
3605 (round (/ (* (setq ebnf-nprod (1+ ebnf-nprod)) 100.0) ebnf-total)))) | |
3606 | |
3607 | |
3608 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
3609 ;; Macros | |
3610 | |
3611 | |
3612 (defmacro ebnf-node-kind (vec &optional value) | |
3613 (if value | |
3614 `(aset ,vec 0 ,value) | |
3615 `(aref ,vec 0))) | |
3616 | |
3617 | |
3618 (defmacro ebnf-node-width-func (node width) | |
3619 `(funcall (aref ,node 1) ,node ,width)) | |
3620 | |
3621 | |
3622 (defmacro ebnf-node-dimension-func (node &optional value) | |
3623 (if value | |
3624 `(aset ,node 2 ,value) | |
3625 `(funcall (aref ,node 2) ,node))) | |
3626 | |
3627 | |
3628 (defmacro ebnf-node-entry (vec &optional value) | |
3629 (if value | |
3630 `(aset ,vec 3 ,value) | |
3631 `(aref ,vec 3))) | |
3632 | |
3633 | |
3634 (defmacro ebnf-node-height (vec &optional value) | |
3635 (if value | |
3636 `(aset ,vec 4 ,value) | |
3637 `(aref ,vec 4))) | |
3638 | |
3639 | |
3640 (defmacro ebnf-node-width (vec &optional value) | |
3641 (if value | |
3642 `(aset ,vec 5 ,value) | |
3643 `(aref ,vec 5))) | |
3644 | |
3645 | |
3646 (defmacro ebnf-node-name (vec) | |
3647 `(aref ,vec 6)) | |
3648 | |
3649 | |
3650 (defmacro ebnf-node-list (vec &optional value) | |
3651 (if value | |
3652 `(aset ,vec 6 ,value) | |
3653 `(aref ,vec 6))) | |
3654 | |
3655 | |
3656 (defmacro ebnf-node-default (vec) | |
3657 `(aref ,vec 7)) | |
3658 | |
3659 | |
3660 (defmacro ebnf-node-production (vec &optional value) | |
3661 (if value | |
3662 `(aset ,vec 7 ,value) | |
3663 `(aref ,vec 7))) | |
3664 | |
3665 | |
3666 (defmacro ebnf-node-separator (vec &optional value) | |
3667 (if value | |
3668 `(aset ,vec 7 ,value) | |
3669 `(aref ,vec 7))) | |
3670 | |
3671 | |
3672 (defmacro ebnf-node-action (vec &optional value) | |
3673 (if value | |
3674 `(aset ,vec 8 ,value) | |
3675 `(aref ,vec 8))) | |
3676 | |
3677 | |
3678 (defmacro ebnf-node-generation (node) | |
3679 `(funcall (ebnf-node-kind ,node) ,node)) | |
3680 | |
3681 | |
3682 (defmacro ebnf-max-width (prod) | |
3683 `(max (ebnf-node-width ,prod) | |
3684 (+ (* (length (ebnf-node-name ,prod)) | |
3685 ebnf-font-width-P) | |
3686 ebnf-production-horizontal-space))) | |
3687 | |
3688 | |
3689 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
3690 ;; PostScript generation | |
3691 | |
3692 | |
3693 (defun ebnf-generate-eps (ebnf-tree) | |
3694 (let* ((ps-color-p (and ebnf-color-p (ps-color-device))) | |
3695 (ps-print-color-scale (if ps-color-p | |
3696 (float (car (ps-color-values "white"))) | |
3697 1.0)) | |
3698 (ebnf-total (length ebnf-tree)) | |
3699 (ebnf-nprod 0) | |
3700 (old-ps-output (symbol-function 'ps-output)) | |
3701 (old-ps-output-string (symbol-function 'ps-output-string)) | |
3702 (eps-buffer (get-buffer-create ebnf-eps-buffer-name)) | |
3703 ebnf-debug-ps error-msg horizontal | |
3704 prod prod-name prod-width prod-height prod-list file-list) | |
3705 ;; redefines `ps-output' and `ps-output-string' | |
3706 (defalias 'ps-output 'ebnf-eps-output) | |
3707 (defalias 'ps-output-string 'ps-output-string-prim) | |
3708 ;; generate EPS file | |
3709 (save-excursion | |
3710 (condition-case data | |
3711 (progn | |
3712 (while ebnf-tree | |
3713 (setq prod (car ebnf-tree) | |
3714 prod-name (ebnf-node-name prod) | |
3715 prod-width (ebnf-max-width prod) | |
3716 prod-height (ebnf-node-height prod) | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
3717 horizontal (memq (ebnf-node-action prod) |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
3718 ebnf-action-list)) |
27451 | 3719 ;; generate production in EPS buffer |
3720 (save-excursion | |
3721 (set-buffer eps-buffer) | |
3722 (setq ebnf-eps-upper-x 0.0 | |
3723 ebnf-eps-upper-y 0.0 | |
3724 ebnf-eps-max-width prod-width | |
3725 ebnf-eps-max-height prod-height) | |
3726 (ebnf-generate-production prod)) | |
3727 (if (setq prod-list (cdr (assoc prod-name | |
3728 ebnf-eps-production-list))) | |
3729 ;; insert EPS buffer in all buffer associated with production | |
3730 (ebnf-eps-production-list prod-list 'file-list horizontal | |
3731 prod-width prod-height eps-buffer) | |
3732 ;; write EPS file for production | |
3733 (ebnf-eps-finish-and-write eps-buffer | |
3734 (ebnf-eps-filename prod-name))) | |
3735 ;; prepare for next loop | |
3736 (save-excursion | |
3737 (set-buffer eps-buffer) | |
3738 (erase-buffer)) | |
3739 (setq ebnf-tree (cdr ebnf-tree))) | |
3740 ;; write and kill temporary buffers | |
3741 (ebnf-eps-write-kill-temp file-list t) | |
3742 (setq file-list nil)) | |
3743 ;; handler | |
3744 ((quit error) | |
3745 (setq error-msg (error-message-string data))))) | |
3746 ;; restore `ps-output' and `ps-output-string' | |
3747 (defalias 'ps-output old-ps-output) | |
3748 (defalias 'ps-output-string old-ps-output-string) | |
3749 ;; kill temporary buffers | |
3750 (kill-buffer eps-buffer) | |
3751 (ebnf-eps-write-kill-temp file-list nil) | |
3752 (and error-msg (error error-msg)) | |
3753 (message " "))) | |
3754 | |
3755 | |
3756 ;; write and kill temporary buffers | |
3757 (defun ebnf-eps-write-kill-temp (file-list write-p) | |
3758 (while file-list | |
3759 (let ((buffer (get-buffer (concat " *" (car file-list) "*")))) | |
3760 (when buffer | |
3761 (and write-p | |
3762 (ebnf-eps-finish-and-write buffer (car file-list))) | |
3763 (kill-buffer buffer))) | |
3764 (setq file-list (cdr file-list)))) | |
3765 | |
3766 | |
3767 ;; insert EPS buffer in all buffer associated with production | |
3768 (defun ebnf-eps-production-list (prod-list file-list-sym horizontal | |
3769 prod-width prod-height eps-buffer) | |
3770 (while prod-list | |
3771 (add-to-list file-list-sym (car prod-list)) | |
3772 (save-excursion | |
3773 (set-buffer (get-buffer-create (concat " *" (car prod-list) "*"))) | |
3774 (goto-char (point-max)) | |
3775 (cond | |
3776 ;; first production | |
3777 ((zerop (buffer-size)) | |
3778 (setq ebnf-eps-upper-x 0.0 | |
3779 ebnf-eps-upper-y 0.0 | |
3780 ebnf-eps-max-width prod-width | |
3781 ebnf-eps-max-height prod-height)) | |
3782 ;; horizontal | |
3783 (horizontal | |
3784 (ebnf-eop-horizontal ebnf-eps-prod-width) | |
3785 (setq ebnf-eps-max-width (+ ebnf-eps-max-width | |
3786 ebnf-production-horizontal-space | |
3787 prod-width) | |
3788 ebnf-eps-max-height (max ebnf-eps-max-height prod-height))) | |
3789 ;; vertical | |
3790 (t | |
3791 (ebnf-eop-vertical ebnf-eps-max-height) | |
3792 (setq ebnf-eps-upper-x (max ebnf-eps-upper-x ebnf-eps-max-width) | |
3793 ebnf-eps-upper-y (if (zerop ebnf-eps-upper-y) | |
3794 ebnf-eps-max-height | |
3795 (+ ebnf-eps-upper-y | |
3796 ebnf-production-vertical-space | |
3797 ebnf-eps-max-height)) | |
3798 ebnf-eps-max-width prod-width | |
3799 ebnf-eps-max-height prod-height)) | |
3800 ) | |
3801 (setq ebnf-eps-prod-width prod-width) | |
3802 (insert-buffer eps-buffer)) | |
3803 (setq prod-list (cdr prod-list)))) | |
3804 | |
3805 | |
3806 (defun ebnf-generate (ebnf-tree) | |
3807 (let* ((ps-color-p (and ebnf-color-p (ps-color-device))) | |
3808 (ps-print-color-scale (if ps-color-p | |
3809 (float (car (ps-color-values "white"))) | |
3810 1.0)) | |
3811 ps-zebra-stripes ps-line-number ps-razzle-dazzle | |
3812 ps-print-hook | |
3813 ps-print-begin-sheet-hook | |
3814 ps-print-begin-page-hook | |
3815 ps-print-begin-column-hook) | |
3816 (ps-generate (current-buffer) (point-min) (point-max) | |
3817 'ebnf-generate-postscript))) | |
3818 | |
3819 | |
3820 (defvar ebnf-tree nil) | |
3821 (defvar ebnf-direction "R") | |
3822 (defvar ebnf-total 0) | |
3823 (defvar ebnf-nprod 0) | |
3824 | |
3825 | |
3826 (defun ebnf-generate-postscript (from to) | |
3827 (ebnf-begin-file) | |
3828 (if ebnf-horizontal-max-height | |
3829 (ebnf-generate-with-max-height) | |
3830 (ebnf-generate-without-max-height)) | |
3831 (message " ")) | |
3832 | |
3833 | |
3834 (defun ebnf-generate-with-max-height () | |
3835 (let ((ebnf-total (length ebnf-tree)) | |
3836 (ebnf-nprod 0) | |
3837 next-line max-height prod the-width) | |
3838 (while ebnf-tree | |
3839 ;; find next line point | |
3840 (setq next-line ebnf-tree | |
3841 prod (car ebnf-tree) | |
3842 max-height (ebnf-node-height prod)) | |
3843 (ebnf-begin-line prod (ebnf-max-width prod)) | |
3844 (while (and (setq next-line (cdr next-line)) | |
3845 (setq prod (car next-line)) | |
3846 (memq (ebnf-node-action prod) ebnf-action-list) | |
3847 (setq the-width (ebnf-max-width prod)) | |
3848 (<= the-width ps-width-remaining)) | |
3849 (setq max-height (max max-height (ebnf-node-height prod)) | |
3850 ps-width-remaining (- ps-width-remaining | |
3851 (+ the-width | |
3852 ebnf-production-horizontal-space)))) | |
3853 ;; generate current line | |
3854 (ebnf-newline max-height) | |
3855 (setq prod (car ebnf-tree)) | |
3856 (ebnf-generate-production prod) | |
3857 (while (not (eq (setq ebnf-tree (cdr ebnf-tree)) next-line)) | |
3858 (ebnf-eop-horizontal (ebnf-max-width prod)) | |
3859 (setq prod (car ebnf-tree)) | |
3860 (ebnf-generate-production prod)) | |
3861 (ebnf-eop-vertical max-height)))) | |
3862 | |
3863 | |
3864 (defun ebnf-generate-without-max-height () | |
3865 (let ((ebnf-total (length ebnf-tree)) | |
3866 (ebnf-nprod 0) | |
3867 max-height prod bef-width cur-width) | |
3868 (while ebnf-tree | |
3869 ;; generate current line | |
3870 (setq prod (car ebnf-tree) | |
3871 max-height (ebnf-node-height prod) | |
3872 bef-width (ebnf-max-width prod)) | |
3873 (ebnf-begin-line prod bef-width) | |
3874 (ebnf-generate-production prod) | |
3875 (while (and (setq ebnf-tree (cdr ebnf-tree)) | |
3876 (setq prod (car ebnf-tree)) | |
3877 (memq (ebnf-node-action prod) ebnf-action-list) | |
3878 (setq cur-width (ebnf-max-width prod)) | |
3879 (<= cur-width ps-width-remaining) | |
3880 (<= (ebnf-node-height prod) ps-height-remaining)) | |
3881 (ebnf-eop-horizontal bef-width) | |
3882 (ebnf-generate-production prod) | |
3883 (setq bef-width cur-width | |
3884 max-height (max max-height (ebnf-node-height prod)) | |
3885 ps-width-remaining (- ps-width-remaining | |
3886 (+ cur-width | |
3887 ebnf-production-horizontal-space)))) | |
3888 (ebnf-eop-vertical max-height) | |
3889 ;; prepare next line | |
3890 (ebnf-newline max-height)))) | |
3891 | |
3892 | |
3893 (defun ebnf-begin-line (prod width) | |
3894 (and (or (eq (ebnf-node-action prod) 'form-feed) | |
3895 (> (ebnf-node-height prod) ps-height-remaining)) | |
3896 (ebnf-new-page)) | |
3897 (setq ps-width-remaining (- ps-width-remaining | |
3898 (+ width | |
3899 ebnf-production-horizontal-space)))) | |
3900 | |
3901 | |
3902 (defun ebnf-newline (height) | |
3903 (and (> height ps-height-remaining) | |
3904 (ebnf-new-page)) | |
3905 (setq ps-width-remaining ps-print-width | |
3906 ps-height-remaining (- ps-height-remaining | |
3907 (+ height | |
3908 ebnf-production-vertical-space)))) | |
3909 | |
3910 | |
3911 ;; [production width-fun dim-fun entry height width name production action] | |
3912 (defun ebnf-generate-production (production) | |
3913 (ebnf-message-info "Generating") | |
3914 (run-hooks 'ebnf-production-hook) | |
3915 (ps-output-string (ebnf-node-name production)) | |
3916 (ps-output " " | |
3917 (ebnf-format-float | |
3918 (ebnf-node-width production) | |
3919 (+ ebnf-basic-height | |
3920 (ebnf-node-entry (ebnf-node-production production)))) | |
3921 " BOP\n") | |
3922 (ebnf-node-generation (ebnf-node-production production)) | |
3923 (ps-output "EOS\n")) | |
3924 | |
3925 | |
3926 ;; [alternative width-fun dim-fun entry height width list] | |
3927 (defun ebnf-generate-alternative (alternative) | |
3928 (let ((alt (ebnf-node-list alternative)) | |
3929 (entry (ebnf-node-entry alternative)) | |
3930 (nlist 0) | |
3931 alt-height alt-entry) | |
3932 (while alt | |
3933 (ps-output (ebnf-format-float (- entry (ebnf-node-entry (car alt)))) | |
3934 " ") | |
3935 (setq entry (- entry (ebnf-node-height (car alt)) ebnf-vertical-space) | |
3936 nlist (1+ nlist) | |
3937 alt (cdr alt))) | |
3938 (ps-output (format "%d " nlist) | |
3939 (ebnf-format-float (ebnf-node-width alternative)) | |
3940 " AT\n") | |
3941 (setq alt (ebnf-node-list alternative)) | |
3942 (when alt | |
3943 (ebnf-node-generation (car alt)) | |
3944 (setq alt-height (- (ebnf-node-height (car alt)) | |
3945 (ebnf-node-entry (car alt))))) | |
3946 (while (setq alt (cdr alt)) | |
3947 (setq alt-entry (ebnf-node-entry (car alt))) | |
3948 (ebnf-vertical-movement | |
3949 (- (+ alt-height ebnf-vertical-space alt-entry))) | |
3950 (ebnf-node-generation (car alt)) | |
3951 (setq alt-height (- (ebnf-node-height (car alt)) alt-entry)))) | |
3952 (ps-output "EOS\n")) | |
3953 | |
3954 | |
3955 ;; [sequence width-fun dim-fun entry height width list] | |
3956 (defun ebnf-generate-sequence (sequence) | |
3957 (ps-output "BOS\n") | |
3958 (let ((seq (ebnf-node-list sequence)) | |
3959 seq-width) | |
3960 (when seq | |
3961 (ebnf-node-generation (car seq)) | |
3962 (setq seq-width (ebnf-node-width (car seq)))) | |
3963 (while (setq seq (cdr seq)) | |
3964 (ebnf-horizontal-movement seq-width) | |
3965 (ebnf-node-generation (car seq)) | |
3966 (setq seq-width (ebnf-node-width (car seq))))) | |
3967 (ps-output "EOS\n")) | |
3968 | |
3969 | |
3970 ;; [terminal width-fun dim-fun entry height width name] | |
3971 (defun ebnf-generate-terminal (terminal) | |
3972 (ebnf-gen-terminal terminal "T")) | |
3973 | |
3974 | |
3975 ;; [non-terminal width-fun dim-fun entry height width name] | |
3976 (defun ebnf-generate-non-terminal (non-terminal) | |
3977 (ebnf-gen-terminal non-terminal "NT")) | |
3978 | |
3979 | |
3980 ;; [empty width-fun dim-fun entry height width] | |
3981 (defun ebnf-generate-empty (empty) | |
3982 (ebnf-empty-alternative (ebnf-node-width empty))) | |
3983 | |
3984 | |
3985 ;; [optional width-fun dim-fun entry height width element] | |
3986 (defun ebnf-generate-optional (optional) | |
3987 (let ((the-optional (ebnf-node-list optional))) | |
3988 (ps-output (ebnf-format-float | |
3989 (+ (- (ebnf-node-height the-optional) | |
3990 (ebnf-node-entry optional)) | |
3991 ebnf-vertical-space) | |
3992 (ebnf-node-width optional)) | |
3993 " OP\n") | |
3994 (ebnf-node-generation the-optional) | |
3995 (ps-output "EOS\n"))) | |
3996 | |
3997 | |
3998 ;; [one-or-more width-fun dim-fun entry height width element separator] | |
3999 (defun ebnf-generate-one-or-more (one-or-more) | |
4000 (let* ((width (ebnf-node-width one-or-more)) | |
4001 (sep (ebnf-node-separator one-or-more)) | |
4002 (entry (- (ebnf-node-entry one-or-more) | |
4003 (if sep | |
4004 (ebnf-node-entry sep) | |
4005 0)))) | |
4006 (ps-output (ebnf-format-float entry width) | |
4007 " OM\n") | |
4008 (ebnf-node-generation (ebnf-node-list one-or-more)) | |
4009 (ebnf-vertical-movement entry) | |
4010 (if sep | |
4011 (let ((ebnf-direction "L")) | |
4012 (ebnf-node-generation sep)) | |
4013 (ebnf-empty-alternative (- width ebnf-horizontal-space)))) | |
4014 (ps-output "EOS\n")) | |
4015 | |
4016 | |
4017 ;; [zero-or-more width-fun dim-fun entry height width element separator] | |
4018 (defun ebnf-generate-zero-or-more (zero-or-more) | |
4019 (let* ((width (ebnf-node-width zero-or-more)) | |
4020 (node-list (ebnf-node-list zero-or-more)) | |
4021 (list-entry (ebnf-node-entry node-list)) | |
4022 (node-sep (ebnf-node-separator zero-or-more)) | |
4023 (entry (+ list-entry | |
4024 ebnf-vertical-space | |
4025 (if node-sep | |
4026 (- (ebnf-node-height node-sep) | |
4027 (ebnf-node-entry node-sep)) | |
4028 0)))) | |
4029 (ps-output (ebnf-format-float entry | |
4030 (+ (- (ebnf-node-height node-list) | |
4031 list-entry) | |
4032 ebnf-vertical-space) | |
4033 width) | |
4034 " ZM\n") | |
4035 (ebnf-node-generation (ebnf-node-list zero-or-more)) | |
4036 (ebnf-vertical-movement entry) | |
4037 (if (ebnf-node-separator zero-or-more) | |
4038 (let ((ebnf-direction "L")) | |
4039 (ebnf-node-generation (ebnf-node-separator zero-or-more))) | |
4040 (ebnf-empty-alternative (- width ebnf-horizontal-space)))) | |
4041 (ps-output "EOS\n")) | |
4042 | |
4043 | |
4044 ;; [special width-fun dim-fun entry height width name] | |
4045 (defun ebnf-generate-special (special) | |
4046 (ebnf-gen-terminal special "SP")) | |
4047 | |
4048 | |
4049 ;; [repeat width-fun dim-fun entry height width times element] | |
4050 (defun ebnf-generate-repeat (repeat) | |
4051 (let ((times (ebnf-node-name repeat)) | |
4052 (element (ebnf-node-separator repeat))) | |
4053 (ps-output-string times) | |
4054 (ps-output " " | |
4055 (ebnf-format-float | |
4056 (ebnf-node-entry repeat) | |
4057 (ebnf-node-height repeat) | |
4058 (ebnf-node-width repeat) | |
4059 (if element | |
4060 (+ (ebnf-node-width element) | |
4061 ebnf-space-R ebnf-space-R ebnf-space-R | |
4062 (* (length times) ebnf-font-width-R)) | |
4063 0.0)) | |
4064 " " ebnf-direction "RP\n") | |
4065 (and element | |
4066 (ebnf-node-generation element))) | |
4067 (ps-output "EOS\n")) | |
4068 | |
4069 | |
4070 ;; [except width-fun dim-fun entry height width element element] | |
4071 (defun ebnf-generate-except (except) | |
4072 (let* ((element (ebnf-node-list except)) | |
4073 (exception (ebnf-node-separator except)) | |
4074 (width (ebnf-node-width element))) | |
4075 (ps-output (ebnf-format-float | |
4076 width | |
4077 (ebnf-node-entry except) | |
4078 (ebnf-node-height except) | |
4079 (ebnf-node-width except) | |
4080 (+ width | |
4081 ebnf-space-E ebnf-space-E ebnf-space-E | |
4082 ebnf-font-width-E | |
4083 (if exception | |
4084 (+ (ebnf-node-width exception) ebnf-space-E) | |
4085 0.0))) | |
4086 " " ebnf-direction "EX\n") | |
4087 (ebnf-node-generation (ebnf-node-list except)) | |
4088 (when exception | |
4089 (ebnf-horizontal-movement (+ width ebnf-space-E | |
4090 ebnf-font-width-E ebnf-space-E)) | |
4091 (ebnf-node-generation exception))) | |
4092 (ps-output "EOS\n")) | |
4093 | |
4094 | |
4095 (defun ebnf-gen-terminal (node code) | |
4096 (ps-output-string (ebnf-node-name node)) | |
4097 (ps-output " " (ebnf-format-float (ebnf-node-width node)) | |
4098 " " ebnf-direction code | |
4099 (if (ebnf-node-default node) | |
4100 "D\n" | |
4101 "\n"))) | |
4102 | |
4103 | |
4104 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
4105 ;; Internal functions | |
4106 | |
4107 | |
34803
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
4108 ;; function `ebnf-range-regexp' is used to avoid a bug of `skip-chars-forward' |
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
4109 ;; on version 20.4.1, that is, it doesn't accept ranges like "\240-\377" (or |
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
4110 ;; "\177-\237"), but it accepts the character sequence from \240 to \377 (or |
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
4111 ;; from \177 to \237). It seems that version 20.7 has the same problem. |
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
4112 (defun ebnf-range-regexp (prefix from to) |
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
4113 (let (str) |
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
4114 (while (<= from to) |
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
4115 (setq str (concat str (char-to-string from)) |
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
4116 from (1+ from))) |
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
4117 (concat prefix str))) |
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
4118 |
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
4119 |
27451 | 4120 (defvar ebnf-map-name |
4121 (let ((map (make-vector 256 ?\_))) | |
4122 (mapcar #'(lambda (char) | |
4123 (aset map char char)) | |
4124 (concat "#$%&+-.0123456789=?@~" | |
4125 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
4126 "abcdefghijklmnopqrstuvwxyz")) | |
4127 map)) | |
4128 | |
4129 | |
4130 (defun ebnf-eps-filename (str) | |
4131 (let* ((len (length str)) | |
4132 (stri 0) | |
4133 (new (make-string len ?\ ))) | |
4134 (while (< stri len) | |
4135 (aset new stri (aref ebnf-map-name (aref str stri))) | |
4136 (setq stri (1+ stri))) | |
4137 (concat ebnf-eps-prefix new ".eps"))) | |
4138 | |
4139 | |
4140 (defun ebnf-eps-output (&rest args) | |
4141 (while args | |
4142 (insert (car args)) | |
4143 (setq args (cdr args)))) | |
4144 | |
4145 | |
4146 (defun ebnf-generate-region (from to gen-func) | |
4147 (run-hooks 'ebnf-hook) | |
4148 (let ((ebnf-limit (max from to)) | |
4149 the-point) | |
4150 (save-excursion | |
4151 (save-restriction | |
4152 (save-match-data | |
4153 (condition-case data | |
4154 (let ((tree (ebnf-parse-and-sort (min from to)))) | |
4155 (when gen-func | |
4156 (funcall gen-func | |
4157 (ebnf-dimensions | |
4158 (ebnf-optimize | |
4159 (ebnf-eliminate-empty-rules tree)))))) | |
4160 ;; handler | |
4161 ((quit error) | |
4162 (ding) | |
4163 (setq the-point (max (1- (point)) (point-min))) | |
4164 (message (error-message-string data))))))) | |
4165 (cond | |
4166 (the-point | |
4167 (goto-char the-point)) | |
4168 (gen-func | |
4169 nil) | |
4170 (t | |
4171 (message "EBNF syntatic analysis: NO ERRORS."))))) | |
4172 | |
4173 | |
4174 (defun ebnf-parse-and-sort (start) | |
4175 (ebnf-begin-job) | |
4176 (let ((tree (funcall ebnf-parser-func start))) | |
4177 (if ebnf-sort-production | |
4178 (progn | |
4179 (message "Sorting...") | |
4180 (sort tree | |
4181 (if (eq ebnf-sort-production 'ascending) | |
4182 'ebnf-sorter-ascending | |
4183 'ebnf-sorter-descending))) | |
4184 (nreverse tree)))) | |
4185 | |
4186 | |
4187 (defun ebnf-sorter-ascending (first second) | |
4188 (string< (ebnf-node-name first) | |
4189 (ebnf-node-name second))) | |
4190 | |
4191 | |
4192 (defun ebnf-sorter-descending (first second) | |
4193 (string< (ebnf-node-name second) | |
4194 (ebnf-node-name first))) | |
4195 | |
4196 | |
4197 (defun ebnf-empty-alternative (width) | |
4198 (ps-output (ebnf-format-float width) " EA\n")) | |
4199 | |
4200 | |
4201 (defun ebnf-vertical-movement (height) | |
4202 (ps-output (ebnf-format-float height) " vm\n")) | |
4203 | |
4204 | |
4205 (defun ebnf-horizontal-movement (width) | |
4206 (ps-output (ebnf-format-float width) " hm\n")) | |
4207 | |
4208 | |
4209 (defun ebnf-entry (height) | |
4210 (* height ebnf-entry-percentage)) | |
4211 | |
4212 | |
4213 (defun ebnf-eop-vertical (height) | |
4214 (ps-output (ebnf-format-float (+ height ebnf-production-vertical-space)) | |
4215 " EOPV\n\n")) | |
4216 | |
4217 | |
4218 (defun ebnf-eop-horizontal (width) | |
4219 (ps-output (ebnf-format-float (+ width ebnf-production-horizontal-space)) | |
4220 " EOPH\n\n")) | |
4221 | |
4222 | |
4223 (defun ebnf-new-page () | |
4224 (when (< ps-height-remaining ps-print-height) | |
4225 (run-hooks 'ebnf-page-hook) | |
4226 (ps-next-page) | |
4227 (ps-output "\n"))) | |
4228 | |
4229 | |
4230 (defsubst ebnf-font-size (font) (nth 0 font)) | |
4231 (defsubst ebnf-font-name (font) (nth 1 font)) | |
4232 (defsubst ebnf-font-foreground (font) (nth 2 font)) | |
4233 (defsubst ebnf-font-background (font) (nth 3 font)) | |
4234 (defsubst ebnf-font-list (font) (nthcdr 4 font)) | |
4235 (defsubst ebnf-font-attributes (font) | |
4236 (lsh (ps-extension-bit (cdr font)) -2)) | |
4237 | |
4238 | |
4239 (defconst ebnf-font-name-select | |
4240 (vector 'normal 'bold 'italic 'bold-italic)) | |
4241 | |
4242 | |
4243 (defun ebnf-font-name-select (font) | |
4244 (let* ((font-list (ebnf-font-list font)) | |
4245 (font-index (+ (if (memq 'bold font-list) 1 0) | |
4246 (if (memq 'italic font-list) 2 0))) | |
4247 (name (ebnf-font-name font)) | |
4248 (database (cdr (assoc name ps-font-info-database))) | |
4249 (info-list (or (cdr (assoc 'fonts database)) | |
4250 (error "Invalid font: %s" name)))) | |
4251 (or (cdr (assoc (aref ebnf-font-name-select font-index) | |
4252 info-list)) | |
4253 (error "Invalid attributes for font %s" name)))) | |
4254 | |
4255 | |
4256 (defun ebnf-font-select (font select) | |
4257 (let* ((name (ebnf-font-name font)) | |
4258 (database (cdr (assoc name ps-font-info-database))) | |
4259 (size (cdr (assoc 'size database))) | |
4260 (base (cdr (assoc select database)))) | |
4261 (if (and size base) | |
4262 (/ (* (ebnf-font-size font) base) | |
4263 size) | |
4264 (error "Invalid font: %s" name)))) | |
4265 | |
4266 | |
4267 (defsubst ebnf-font-width (font) | |
4268 (ebnf-font-select font 'avg-char-width)) | |
4269 (defsubst ebnf-font-height (font) | |
4270 (ebnf-font-select font 'line-height)) | |
4271 | |
4272 | |
4273 (defun ebnf-begin-job () | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
4274 (ps-printing-region nil nil) |
27451 | 4275 (if ebnf-use-float-format |
4276 (setq ebnf-format-float "%1.3f" | |
4277 ebnf-message-float "%3.2f") | |
4278 (setq ebnf-format-float "%s" | |
4279 ebnf-message-float "%s")) | |
4280 (ebnf-otz-initialize) | |
4281 ;; to avoid compilation gripes when calling autoloaded functions | |
4282 (funcall (cond ((eq ebnf-syntax 'iso-ebnf) | |
4283 (setq ebnf-parser-func 'ebnf-iso-parser) | |
4284 'ebnf-iso-initialize) | |
4285 ((eq ebnf-syntax 'yacc) | |
4286 (setq ebnf-parser-func 'ebnf-yac-parser) | |
4287 'ebnf-yac-initialize) | |
4288 (t | |
4289 (setq ebnf-parser-func 'ebnf-bnf-parser) | |
4290 'ebnf-bnf-initialize))) | |
4291 (and ebnf-terminal-regexp ; ensures that it's a string or nil | |
4292 (not (stringp ebnf-terminal-regexp)) | |
4293 (setq ebnf-terminal-regexp nil)) | |
4294 (or (and ebnf-eps-prefix ; ensures that it's a string | |
4295 (stringp ebnf-eps-prefix)) | |
4296 (setq ebnf-eps-prefix "ebnf--")) | |
4297 (setq ebnf-entry-percentage ; ensures value between 0.0 and 1.0 | |
4298 (min (max ebnf-entry-percentage 0.0) 1.0) | |
4299 ebnf-action-list (if ebnf-horizontal-orientation | |
4300 '(nil keep-line) | |
4301 '(keep-line)) | |
4302 ebnf-settings nil | |
4303 ebnf-fonts-required nil | |
4304 ebnf-action nil | |
4305 ebnf-default-p nil | |
4306 ebnf-eps-context nil | |
4307 ebnf-eps-production-list nil | |
4308 ebnf-eps-upper-x 0.0 | |
4309 ebnf-eps-upper-y 0.0 | |
4310 ebnf-font-height-P (ebnf-font-height ebnf-production-font) | |
4311 ebnf-font-height-T (ebnf-font-height ebnf-terminal-font) | |
4312 ebnf-font-height-NT (ebnf-font-height ebnf-non-terminal-font) | |
4313 ebnf-font-height-S (ebnf-font-height ebnf-special-font) | |
4314 ebnf-font-height-E (ebnf-font-height ebnf-except-font) | |
4315 ebnf-font-height-R (ebnf-font-height ebnf-repeat-font) | |
4316 ebnf-font-width-P (ebnf-font-width ebnf-production-font) | |
4317 ebnf-font-width-T (ebnf-font-width ebnf-terminal-font) | |
4318 ebnf-font-width-NT (ebnf-font-width ebnf-non-terminal-font) | |
4319 ebnf-font-width-S (ebnf-font-width ebnf-special-font) | |
4320 ebnf-font-width-E (ebnf-font-width ebnf-except-font) | |
4321 ebnf-font-width-R (ebnf-font-width ebnf-repeat-font) | |
4322 ebnf-space-T (* ebnf-font-height-T 0.5) | |
4323 ebnf-space-NT (* ebnf-font-height-NT 0.5) | |
4324 ebnf-space-S (* ebnf-font-height-S 0.5) | |
4325 ebnf-space-E (* ebnf-font-height-E 0.5) | |
4326 ebnf-space-R (* ebnf-font-height-R 0.5)) | |
4327 (let ((basic (+ ebnf-font-height-T ebnf-font-height-NT))) | |
4328 (setq ebnf-basic-width (* basic 0.5) | |
4329 ebnf-horizontal-space (+ basic basic) | |
4330 ebnf-basic-height ebnf-basic-width | |
4331 ebnf-vertical-space ebnf-basic-width) | |
4332 ;; ensures value is greater than zero | |
4333 (or (and (numberp ebnf-production-horizontal-space) | |
4334 (> ebnf-production-horizontal-space 0.0)) | |
4335 (setq ebnf-production-horizontal-space basic)) | |
4336 ;; ensures value is greater than zero | |
4337 (or (and (numberp ebnf-production-vertical-space) | |
4338 (> ebnf-production-vertical-space 0.0)) | |
4339 (setq ebnf-production-vertical-space basic)))) | |
4340 | |
4341 | |
4342 (defsubst ebnf-shape-value (sym alist) | |
4343 (or (cdr (assq sym alist)) 0)) | |
4344 | |
4345 | |
4346 (defsubst ebnf-boolean (value) | |
4347 (if value "true" "false")) | |
4348 | |
4349 | |
4350 (defun ebnf-begin-file () | |
4351 (ps-flush-output) | |
4352 (save-excursion | |
4353 (set-buffer ps-spool-buffer) | |
4354 (goto-char (point-min)) | |
4355 (and (search-forward "%%Creator: " nil t) | |
4356 (not (search-forward "& ebnf2ps v" | |
4357 (save-excursion (end-of-line) (point)) | |
4358 t)) | |
4359 (progn | |
4360 ;; adjust creator comment | |
4361 (end-of-line) | |
4362 (backward-char) | |
4363 (insert " & ebnf2ps v" ebnf-version) | |
4364 ;; insert ebnf settings & engine | |
4365 (goto-char (point-max)) | |
4366 (search-backward "\n%%EndPrologue\n") | |
4367 (ebnf-insert-ebnf-prologue) | |
4368 (ps-output "\n"))))) | |
4369 | |
4370 | |
4371 (defun ebnf-eps-finish-and-write (buffer filename) | |
4372 (save-excursion | |
4373 (set-buffer buffer) | |
4374 (setq ebnf-eps-upper-x (max ebnf-eps-upper-x ebnf-eps-max-width) | |
4375 ebnf-eps-upper-y (if (zerop ebnf-eps-upper-y) | |
4376 ebnf-eps-max-height | |
4377 (+ ebnf-eps-upper-y | |
4378 ebnf-production-vertical-space | |
4379 ebnf-eps-max-height))) | |
4380 ;; prologue | |
4381 (goto-char (point-min)) | |
4382 (insert | |
4383 "%!PS-Adobe-3.0 EPSF-3.0" | |
4384 "\n%%BoundingBox: 0 0 " | |
4385 (format "%d %d" (1+ ebnf-eps-upper-x) (1+ ebnf-eps-upper-y)) | |
4386 "\n%%Title: " filename | |
4387 "\n%%CreationDate: " (time-stamp-hh:mm:ss) " " (time-stamp-mon-dd-yyyy) | |
4388 "\n%%Creator: " (user-full-name) " (using ebnf2ps v" ebnf-version ")" | |
4389 "\n%%DocumentNeededResources: font " | |
4390 (or ebnf-fonts-required | |
4391 (setq ebnf-fonts-required | |
31255 | 4392 (mapconcat 'identity |
4393 (ps-remove-duplicates | |
4394 (mapcar 'ebnf-font-name-select | |
4395 (list ebnf-production-font | |
4396 ebnf-terminal-font | |
4397 ebnf-non-terminal-font | |
4398 ebnf-special-font | |
4399 ebnf-except-font | |
4400 ebnf-repeat-font))) | |
4401 "\n%%+ font "))) | |
27451 | 4402 "\n%%Pages: 0\n%%EndComments\n\n%%BeginPrologue\n" |
4403 ebnf-eps-prologue) | |
4404 (ebnf-insert-ebnf-prologue) | |
4405 (insert ebnf-eps-begin | |
4406 "\n0 " (ebnf-format-float | |
4407 (- ebnf-eps-upper-y (* ebnf-font-height-P 0.7))) | |
4408 " #ebnf2ps#begin\n") | |
4409 ;; epilogue | |
4410 (goto-char (point-max)) | |
4411 (insert ebnf-eps-end) | |
4412 ;; write file | |
4413 (message "Saving...") | |
4414 (setq filename (expand-file-name filename)) | |
4415 (let ((coding-system-for-write 'raw-text-unix)) | |
4416 (write-region (point-min) (point-max) filename)) | |
4417 (message "Wrote %s" filename))) | |
4418 | |
4419 | |
4420 (defun ebnf-insert-ebnf-prologue () | |
4421 (insert | |
4422 (or ebnf-settings | |
4423 (setq ebnf-settings | |
4424 (concat | |
4425 "\n\n% === begin EBNF settings\n\n" | |
4426 ;; production | |
4427 (format "/fP %s /%s DefFont\n" | |
4428 (ebnf-format-float (ebnf-font-size ebnf-production-font)) | |
4429 (ebnf-font-name-select ebnf-production-font)) | |
4430 (ebnf-format-color "/ForegroundP %s def %% %s\n" | |
4431 (ebnf-font-foreground ebnf-production-font) | |
4432 "Black") | |
4433 (ebnf-format-color "/BackgroundP %s def %% %s\n" | |
4434 (ebnf-font-background ebnf-production-font) | |
4435 "White") | |
4436 (format "/EffectP %d def\n" | |
4437 (ebnf-font-attributes ebnf-production-font)) | |
4438 ;; terminal | |
4439 (format "/fT %s /%s DefFont\n" | |
4440 (ebnf-format-float (ebnf-font-size ebnf-terminal-font)) | |
4441 (ebnf-font-name-select ebnf-terminal-font)) | |
4442 (ebnf-format-color "/ForegroundT %s def %% %s\n" | |
4443 (ebnf-font-foreground ebnf-terminal-font) | |
4444 "Black") | |
4445 (ebnf-format-color "/BackgroundT %s def %% %s\n" | |
4446 (ebnf-font-background ebnf-terminal-font) | |
4447 "White") | |
4448 (format "/EffectT %d def\n" | |
4449 (ebnf-font-attributes ebnf-terminal-font)) | |
4450 (format "/BorderWidthT %s def\n" | |
4451 (ebnf-format-float ebnf-terminal-border-width)) | |
4452 (ebnf-format-color "/BorderColorT %s def %% %s\n" | |
4453 ebnf-terminal-border-color | |
4454 "Black") | |
4455 (format "/ShapeT %d def\n" | |
4456 (ebnf-shape-value ebnf-terminal-shape | |
4457 ebnf-terminal-shape-alist)) | |
4458 (format "/ShadowT %s def\n" | |
4459 (ebnf-boolean ebnf-terminal-shadow)) | |
4460 ;; non-terminal | |
4461 (format "/fNT %s /%s DefFont\n" | |
4462 (ebnf-format-float | |
4463 (ebnf-font-size ebnf-non-terminal-font)) | |
4464 (ebnf-font-name-select ebnf-non-terminal-font)) | |
4465 (ebnf-format-color "/ForegroundNT %s def %% %s\n" | |
4466 (ebnf-font-foreground ebnf-non-terminal-font) | |
4467 "Black") | |
4468 (ebnf-format-color "/BackgroundNT %s def %% %s\n" | |
4469 (ebnf-font-background ebnf-non-terminal-font) | |
4470 "White") | |
4471 (format "/EffectNT %d def\n" | |
4472 (ebnf-font-attributes ebnf-non-terminal-font)) | |
4473 (format "/BorderWidthNT %s def\n" | |
4474 (ebnf-format-float ebnf-non-terminal-border-width)) | |
4475 (ebnf-format-color "/BorderColorNT %s def %% %s\n" | |
4476 ebnf-non-terminal-border-color | |
4477 "Black") | |
4478 (format "/ShapeNT %d def\n" | |
4479 (ebnf-shape-value ebnf-non-terminal-shape | |
4480 ebnf-terminal-shape-alist)) | |
4481 (format "/ShadowNT %s def\n" | |
4482 (ebnf-boolean ebnf-non-terminal-shadow)) | |
4483 ;; special | |
4484 (format "/fS %s /%s DefFont\n" | |
4485 (ebnf-format-float (ebnf-font-size ebnf-special-font)) | |
4486 (ebnf-font-name-select ebnf-special-font)) | |
4487 (ebnf-format-color "/ForegroundS %s def %% %s\n" | |
4488 (ebnf-font-foreground ebnf-special-font) | |
4489 "Black") | |
4490 (ebnf-format-color "/BackgroundS %s def %% %s\n" | |
4491 (ebnf-font-background ebnf-special-font) | |
4492 "Gray95") | |
4493 (format "/EffectS %d def\n" | |
4494 (ebnf-font-attributes ebnf-special-font)) | |
4495 (format "/BorderWidthS %s def\n" | |
4496 (ebnf-format-float ebnf-special-border-width)) | |
4497 (ebnf-format-color "/BorderColorS %s def %% %s\n" | |
4498 ebnf-special-border-color | |
4499 "Black") | |
4500 (format "/ShapeS %d def\n" | |
4501 (ebnf-shape-value ebnf-special-shape | |
4502 ebnf-terminal-shape-alist)) | |
4503 (format "/ShadowS %s def\n" | |
4504 (ebnf-boolean ebnf-special-shadow)) | |
4505 ;; except | |
4506 (format "/fE %s /%s DefFont\n" | |
4507 (ebnf-format-float (ebnf-font-size ebnf-except-font)) | |
4508 (ebnf-font-name-select ebnf-except-font)) | |
4509 (ebnf-format-color "/ForegroundE %s def %% %s\n" | |
4510 (ebnf-font-foreground ebnf-except-font) | |
4511 "Black") | |
4512 (ebnf-format-color "/BackgroundE %s def %% %s\n" | |
4513 (ebnf-font-background ebnf-except-font) | |
4514 "Gray90") | |
4515 (format "/EffectE %d def\n" | |
4516 (ebnf-font-attributes ebnf-except-font)) | |
4517 (format "/BorderWidthE %s def\n" | |
4518 (ebnf-format-float ebnf-except-border-width)) | |
4519 (ebnf-format-color "/BorderColorE %s def %% %s\n" | |
4520 ebnf-except-border-color | |
4521 "Black") | |
4522 (format "/ShapeE %d def\n" | |
4523 (ebnf-shape-value ebnf-except-shape | |
4524 ebnf-terminal-shape-alist)) | |
4525 (format "/ShadowE %s def\n" | |
4526 (ebnf-boolean ebnf-except-shadow)) | |
4527 ;; repeat | |
4528 (format "/fR %s /%s DefFont\n" | |
4529 (ebnf-format-float (ebnf-font-size ebnf-repeat-font)) | |
4530 (ebnf-font-name-select ebnf-repeat-font)) | |
4531 (ebnf-format-color "/ForegroundR %s def %% %s\n" | |
4532 (ebnf-font-foreground ebnf-repeat-font) | |
4533 "Black") | |
4534 (ebnf-format-color "/BackgroundR %s def %% %s\n" | |
4535 (ebnf-font-background ebnf-repeat-font) | |
4536 "Gray85") | |
4537 (format "/EffectR %d def\n" | |
4538 (ebnf-font-attributes ebnf-repeat-font)) | |
4539 (format "/BorderWidthR %s def\n" | |
4540 (ebnf-format-float ebnf-repeat-border-width)) | |
4541 (ebnf-format-color "/BorderColorR %s def %% %s\n" | |
4542 ebnf-repeat-border-color | |
4543 "Black") | |
4544 (format "/ShapeR %d def\n" | |
4545 (ebnf-shape-value ebnf-repeat-shape | |
4546 ebnf-terminal-shape-alist)) | |
4547 (format "/ShadowR %s def\n" | |
4548 (ebnf-boolean ebnf-repeat-shadow)) | |
4549 ;; miscellaneous | |
4550 (format "/DefaultWidth %s def\n" | |
4551 (ebnf-format-float ebnf-default-width)) | |
4552 (format "/LineWidth %s def\n" | |
4553 (ebnf-format-float ebnf-line-width)) | |
4554 (ebnf-format-color "/LineColor %s def %% %s\n" | |
4555 ebnf-line-color | |
4556 "Black") | |
4557 (format "/ArrowShape %d def\n" | |
4558 (ebnf-shape-value ebnf-arrow-shape | |
4559 ebnf-arrow-shape-alist)) | |
4560 (format "/ChartShape %d def\n" | |
4561 (ebnf-shape-value ebnf-chart-shape | |
4562 ebnf-terminal-shape-alist)) | |
4563 (format "/UserArrow{%s}def\n" | |
31255 | 4564 (let ((arrow (eval ebnf-user-arrow))) |
4565 (if (stringp arrow) | |
4566 arrow | |
4567 ""))) | |
27451 | 4568 "\n% === end EBNF settings\n\n" |
4569 (and ebnf-debug-ps ebnf-debug)))) | |
4570 ebnf-prologue)) | |
4571 | |
4572 | |
4573 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
4574 ;; Adjusting dimensions | |
4575 | |
4576 | |
4577 (defun ebnf-dimensions (tree) | |
4578 (let ((ebnf-total (length tree)) | |
4579 (ebnf-nprod 0)) | |
4580 (mapcar 'ebnf-production-dimension tree)) | |
4581 tree) | |
4582 | |
4583 | |
4584 ;; [empty width-fun dim-fun entry height width] | |
4585 ;;(defun ebnf-empty-dimension (empty) | |
4586 ;; ) | |
4587 | |
4588 | |
4589 ;; [production width-fun dim-fun entry height width name production action] | |
4590 (defun ebnf-production-dimension (production) | |
4591 (ebnf-message-info "Calculating dimensions") | |
4592 (ebnf-node-dimension-func (ebnf-node-production production)) | |
4593 (let* ((prod (ebnf-node-production production)) | |
4594 (height (+ ebnf-font-height-P | |
4595 ebnf-basic-height | |
4596 (ebnf-node-height prod)))) | |
4597 (ebnf-node-entry production height) | |
4598 (ebnf-node-height production height) | |
4599 (ebnf-node-width production (+ (ebnf-node-width prod) | |
4600 ebnf-horizontal-space)))) | |
4601 | |
4602 | |
4603 ;; [terminal width-fun dim-fun entry height width name] | |
4604 (defun ebnf-terminal-dimension (terminal) | |
4605 (ebnf-terminal-dimension1 terminal | |
4606 ebnf-font-height-T | |
4607 ebnf-font-width-T | |
4608 ebnf-space-T)) | |
4609 | |
4610 | |
4611 ;; [non-terminal width-fun dim-fun entry height width name] | |
4612 (defun ebnf-non-terminal-dimension (non-terminal) | |
4613 (ebnf-terminal-dimension1 non-terminal | |
4614 ebnf-font-height-NT | |
4615 ebnf-font-width-NT | |
4616 ebnf-space-NT)) | |
4617 | |
4618 | |
4619 ;; [special width-fun dim-fun entry height width name] | |
4620 (defun ebnf-special-dimension (special) | |
4621 (ebnf-terminal-dimension1 special | |
4622 ebnf-font-height-S | |
4623 ebnf-font-width-S | |
4624 ebnf-space-S)) | |
4625 | |
4626 | |
4627 (defun ebnf-terminal-dimension1 (node font-height font-width space) | |
4628 (let ((height (+ space font-height space)) | |
4629 (len (length (ebnf-node-name node)))) | |
4630 (ebnf-node-entry node (* height 0.5)) | |
4631 (ebnf-node-height node height) | |
4632 (ebnf-node-width node (+ ebnf-basic-width space | |
4633 (* len font-width) | |
4634 space ebnf-basic-width)))) | |
4635 | |
4636 | |
4637 (defconst ebnf-null-vector (vector t t t 0.0 0.0 0.0)) | |
4638 | |
4639 | |
4640 ;; [repeat width-fun dim-fun entry height width times element] | |
4641 (defun ebnf-repeat-dimension (repeat) | |
4642 (let ((times (ebnf-node-name repeat)) | |
4643 (element (ebnf-node-separator repeat))) | |
4644 (if element | |
4645 (ebnf-node-dimension-func element) | |
4646 (setq element ebnf-null-vector)) | |
4647 (ebnf-node-entry repeat (+ (ebnf-node-entry element) | |
4648 ebnf-space-R)) | |
4649 (ebnf-node-height repeat (+ (max (ebnf-node-height element) | |
4650 ebnf-font-height-S) | |
4651 ebnf-space-R ebnf-space-R)) | |
4652 (ebnf-node-width repeat (+ (ebnf-node-width element) | |
4653 ebnf-space-R ebnf-space-R ebnf-space-R | |
4654 ebnf-horizontal-space | |
4655 (* (length times) ebnf-font-width-R))))) | |
4656 | |
4657 | |
4658 ;; [except width-fun dim-fun entry height width element element] | |
4659 (defun ebnf-except-dimension (except) | |
4660 (let ((factor (ebnf-node-list except)) | |
4661 (element (ebnf-node-separator except))) | |
4662 (ebnf-node-dimension-func factor) | |
4663 (if element | |
4664 (ebnf-node-dimension-func element) | |
4665 (setq element ebnf-null-vector)) | |
4666 (ebnf-node-entry except (+ (max (ebnf-node-entry factor) | |
4667 (ebnf-node-entry element)) | |
4668 ebnf-space-E)) | |
4669 (ebnf-node-height except (+ (max (ebnf-node-height factor) | |
4670 (ebnf-node-height element)) | |
4671 ebnf-space-E ebnf-space-E)) | |
4672 (ebnf-node-width except (+ (ebnf-node-width factor) | |
4673 (ebnf-node-width element) | |
4674 ebnf-space-E ebnf-space-E | |
4675 ebnf-space-E ebnf-space-E | |
4676 ebnf-font-width-E | |
4677 ebnf-horizontal-space)))) | |
4678 | |
4679 | |
4680 ;; [alternative width-fun dim-fun entry height width list] | |
4681 (defun ebnf-alternative-dimension (alternative) | |
4682 (let ((body (ebnf-node-list alternative)) | |
4683 (lis (ebnf-node-list alternative))) | |
4684 (while lis | |
4685 (ebnf-node-dimension-func (car lis)) | |
4686 (setq lis (cdr lis))) | |
4687 (let ((height 0.0) | |
4688 (width 0.0) | |
4689 (alt body) | |
4690 (tail (car (last body))) | |
4691 (entry (ebnf-node-entry (car body))) | |
4692 node) | |
4693 (while alt | |
4694 (setq node (car alt) | |
4695 alt (cdr alt) | |
4696 height (+ (ebnf-node-height node) height) | |
4697 width (max (ebnf-node-width node) width))) | |
4698 (ebnf-adjust-width body width) | |
4699 (setq height (+ height (* (1- (length body)) ebnf-vertical-space))) | |
4700 (ebnf-node-entry alternative (+ entry | |
4701 (ebnf-entry | |
4702 (- height entry | |
4703 (- (ebnf-node-height tail) | |
4704 (ebnf-node-entry tail)))))) | |
4705 (ebnf-node-height alternative height) | |
4706 (ebnf-node-width alternative (+ width ebnf-horizontal-space)) | |
4707 (ebnf-node-list alternative body)))) | |
4708 | |
4709 | |
4710 ;; [optional width-fun dim-fun entry height width element] | |
4711 (defun ebnf-optional-dimension (optional) | |
4712 (let ((body (ebnf-node-list optional))) | |
4713 (ebnf-node-dimension-func body) | |
4714 (ebnf-node-entry optional (ebnf-node-entry body)) | |
4715 (ebnf-node-height optional (+ (ebnf-node-height body) | |
4716 ebnf-vertical-space)) | |
4717 (ebnf-node-width optional (+ (ebnf-node-width body) | |
4718 ebnf-horizontal-space)))) | |
4719 | |
4720 | |
4721 ;; [one-or-more width-fun dim-fun entry height width element separator] | |
4722 (defun ebnf-one-or-more-dimension (or-more) | |
4723 (let ((list-part (ebnf-node-list or-more)) | |
4724 (sep-part (ebnf-node-separator or-more))) | |
4725 (ebnf-node-dimension-func list-part) | |
4726 (and sep-part | |
4727 (ebnf-node-dimension-func sep-part)) | |
4728 (let ((height (+ (if sep-part | |
4729 (ebnf-node-height sep-part) | |
4730 0.0) | |
4731 ebnf-vertical-space | |
4732 (ebnf-node-height list-part))) | |
4733 (width (max (if sep-part | |
4734 (ebnf-node-width sep-part) | |
4735 0.0) | |
4736 (ebnf-node-width list-part)))) | |
4737 (when sep-part | |
4738 (ebnf-adjust-width list-part width) | |
4739 (ebnf-adjust-width sep-part width)) | |
4740 (ebnf-node-entry or-more (+ (- height (ebnf-node-height list-part)) | |
4741 (ebnf-node-entry list-part))) | |
4742 (ebnf-node-height or-more height) | |
4743 (ebnf-node-width or-more (+ width ebnf-horizontal-space))))) | |
4744 | |
4745 | |
4746 ;; [zero-or-more width-fun dim-fun entry height width element separator] | |
4747 (defun ebnf-zero-or-more-dimension (or-more) | |
4748 (let ((list-part (ebnf-node-list or-more)) | |
4749 (sep-part (ebnf-node-separator or-more))) | |
4750 (ebnf-node-dimension-func list-part) | |
4751 (and sep-part | |
4752 (ebnf-node-dimension-func sep-part)) | |
4753 (let ((height (+ (if sep-part | |
4754 (ebnf-node-height sep-part) | |
4755 0.0) | |
4756 ebnf-vertical-space | |
4757 (ebnf-node-height list-part) | |
4758 ebnf-vertical-space)) | |
4759 (width (max (if sep-part | |
4760 (ebnf-node-width sep-part) | |
4761 0.0) | |
4762 (ebnf-node-width list-part)))) | |
4763 (when sep-part | |
4764 (ebnf-adjust-width list-part width) | |
4765 (ebnf-adjust-width sep-part width)) | |
4766 (ebnf-node-entry or-more height) | |
4767 (ebnf-node-height or-more height) | |
4768 (ebnf-node-width or-more (+ width ebnf-horizontal-space))))) | |
4769 | |
4770 | |
4771 ;; [sequence width-fun dim-fun entry height width list] | |
4772 (defun ebnf-sequence-dimension (sequence) | |
4773 (let ((above 0.0) | |
4774 (below 0.0) | |
4775 (width 0.0) | |
4776 (lis (ebnf-node-list sequence)) | |
4777 entry node) | |
4778 (while lis | |
4779 (setq node (car lis) | |
4780 lis (cdr lis)) | |
4781 (ebnf-node-dimension-func node) | |
4782 (setq entry (ebnf-node-entry node) | |
4783 above (max above entry) | |
4784 below (max below (- (ebnf-node-height node) entry)) | |
4785 width (+ width (ebnf-node-width node)))) | |
4786 (ebnf-node-entry sequence above) | |
4787 (ebnf-node-height sequence (+ above below)) | |
4788 (ebnf-node-width sequence width))) | |
4789 | |
4790 | |
4791 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
4792 ;; Adjusting width | |
4793 | |
4794 | |
4795 (defun ebnf-adjust-width (node width) | |
4796 (cond | |
4797 ((listp node) | |
4798 (prog1 | |
4799 node | |
4800 (while node | |
4801 (setcar node (ebnf-adjust-width (car node) width)) | |
4802 (setq node (cdr node))))) | |
4803 ((vectorp node) | |
4804 (cond | |
4805 ;; nothing to be done | |
4806 ((= width (ebnf-node-width node)) | |
4807 node) | |
4808 ;; left justify term | |
4809 ((eq ebnf-justify-sequence 'left) | |
4810 (ebnf-adjust-empty node width nil)) | |
4811 ;; right justify terms | |
4812 ((eq ebnf-justify-sequence 'right) | |
4813 (ebnf-adjust-empty node width t)) | |
4814 ;; centralize terms | |
4815 (t | |
4816 (ebnf-node-width-func node width) | |
4817 (ebnf-node-width node width) | |
4818 node) | |
4819 )) | |
4820 (t | |
4821 node) | |
4822 )) | |
4823 | |
4824 | |
4825 (defun ebnf-adjust-empty (node width last-p) | |
4826 (if (eq (ebnf-node-kind node) 'ebnf-generate-empty) | |
4827 (progn | |
4828 (ebnf-node-width node width) | |
4829 node) | |
4830 (let ((empty (ebnf-make-empty (- width (ebnf-node-width node))))) | |
4831 (ebnf-make-dup-sequence node | |
4832 (if last-p | |
4833 (list empty node) | |
4834 (list node empty)))))) | |
4835 | |
4836 | |
4837 ;; [terminal width-fun dim-fun entry height width name] | |
4838 ;; [non-terminal width-fun dim-fun entry height width name] | |
4839 ;; [empty width-fun dim-fun entry height width] | |
4840 ;; [special width-fun dim-fun entry height width name] | |
4841 ;; [repeat width-fun dim-fun entry height width times element] | |
4842 ;; [except width-fun dim-fun entry height width element element] | |
4843 ;;(defun ebnf-terminal-width (terminal width) | |
4844 ;; ) | |
4845 | |
4846 | |
4847 ;; [alternative width-fun dim-fun entry height width list] | |
4848 ;; [optional width-fun dim-fun entry height width element] | |
4849 (defun ebnf-alternative-width (alternative width) | |
4850 (ebnf-adjust-width (ebnf-node-list alternative) | |
4851 (- width ebnf-horizontal-space))) | |
4852 | |
4853 | |
4854 ;; [one-or-more width-fun dim-fun entry height width element separator] | |
4855 ;; [zero-or-more width-fun dim-fun entry height width element separator] | |
4856 (defun ebnf-list-width (or-more width) | |
4857 (setq width (- width ebnf-horizontal-space)) | |
4858 (ebnf-node-list or-more | |
4859 (ebnf-justify-list or-more | |
4860 (ebnf-node-list or-more) | |
4861 width)) | |
4862 (ebnf-node-separator or-more | |
4863 (ebnf-justify-list or-more | |
4864 (ebnf-node-separator or-more) | |
4865 width))) | |
4866 | |
4867 | |
4868 ;; [sequence width-fun dim-fun entry height width list] | |
4869 (defun ebnf-sequence-width (sequence width) | |
4870 (ebnf-node-list sequence | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
4871 (ebnf-justify-list sequence |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
4872 (ebnf-node-list sequence) |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
4873 width))) |
27451 | 4874 |
4875 | |
4876 (defun ebnf-justify-list (node seq width) | |
4877 (let ((seq-width (ebnf-node-width node))) | |
4878 (if (= width seq-width) | |
4879 seq | |
4880 (cond | |
4881 ;; left justify terms | |
4882 ((eq ebnf-justify-sequence 'left) | |
4883 (ebnf-justify node seq seq-width width t)) | |
4884 ;; right justify terms | |
4885 ((eq ebnf-justify-sequence 'right) | |
4886 (ebnf-justify node seq seq-width width nil)) | |
4887 ;; centralize terms | |
4888 (t | |
4889 (let ((the-width (/ (- width seq-width) (length seq))) | |
4890 (lis seq)) | |
4891 (while lis | |
4892 (ebnf-adjust-width (car lis) | |
4893 (+ (ebnf-node-width (car lis)) | |
4894 the-width)) | |
4895 (setq lis (cdr lis))) | |
4896 seq)) | |
4897 )))) | |
4898 | |
4899 | |
4900 (defun ebnf-justify (node seq seq-width width last-p) | |
4901 (let ((term (car (if last-p (last seq) seq)))) | |
4902 (cond | |
4903 ;; adjust empty term | |
4904 ((eq (ebnf-node-kind term) 'ebnf-generate-empty) | |
4905 (ebnf-node-width term (+ (- width seq-width) | |
4906 (ebnf-node-width term))) | |
4907 seq) | |
4908 ;; insert empty at end ==> left justify | |
4909 (last-p | |
4910 (nconc seq | |
4911 (list (ebnf-make-empty (- width seq-width))))) | |
4912 ;; insert empty at beginning ==> right justify | |
4913 (t | |
4914 (cons (ebnf-make-empty (- width seq-width)) | |
4915 seq)) | |
4916 ))) | |
4917 | |
4918 | |
4919 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
4920 ;; Functions used by parsers | |
4921 | |
4922 | |
4923 (defun ebnf-eps-add-context (name) | |
4924 (let ((filename (ebnf-eps-filename name))) | |
4925 (if (member filename ebnf-eps-context) | |
4926 (error "Try to open an already opened EPS file: %s" filename) | |
4927 (setq ebnf-eps-context (cons filename ebnf-eps-context))))) | |
4928 | |
4929 | |
4930 (defun ebnf-eps-remove-context (name) | |
4931 (let ((filename (ebnf-eps-filename name))) | |
4932 (if (member filename ebnf-eps-context) | |
4933 (setq ebnf-eps-context (delete filename ebnf-eps-context)) | |
4934 (error "Try to close a not opened EPS file: %s" filename)))) | |
4935 | |
4936 | |
4937 (defun ebnf-eps-add-production (header) | |
4938 (and ebnf-eps-executing | |
4939 ebnf-eps-context | |
4940 (let ((prod (assoc header ebnf-eps-production-list))) | |
4941 (if prod | |
4942 (setcdr prod (append ebnf-eps-context (cdr prod))) | |
4943 (setq ebnf-eps-production-list | |
4944 (cons (cons header (ebnf-dup-list ebnf-eps-context)) | |
4945 ebnf-eps-production-list)))))) | |
4946 | |
4947 | |
4948 (defun ebnf-dup-list (old) | |
4949 (let (new) | |
4950 (while old | |
4951 (setq new (cons (car old) new) | |
4952 old (cdr old))) | |
4953 (nreverse new))) | |
4954 | |
4955 | |
4956 (defun ebnf-buffer-substring (chars) | |
4957 (buffer-substring-no-properties | |
4958 (point) | |
4959 (progn | |
4960 (skip-chars-forward chars ebnf-limit) | |
4961 (point)))) | |
4962 | |
4963 | |
34803
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
4964 ;; replace the range "\240-\377" (see `ebnf-range-regexp'). |
de1f65fa5dcd
Fix a problem with skip-chars-forward: it doesn't accept
Gerd Moellmann <gerd@gnu.org>
parents:
31255
diff
changeset
|
4965 (defconst ebnf-8-bit-chars (ebnf-range-regexp "" ?\240 ?\377)) |
30572
f0463edb8518
Get around a bug on skip-chars-forward.
Gerd Moellmann <gerd@gnu.org>
parents:
30552
diff
changeset
|
4966 |
f0463edb8518
Get around a bug on skip-chars-forward.
Gerd Moellmann <gerd@gnu.org>
parents:
30552
diff
changeset
|
4967 |
27451 | 4968 (defun ebnf-string (chars eos-char kind) |
4969 (forward-char) | |
4970 (buffer-substring-no-properties | |
4971 (point) | |
4972 (progn | |
30572
f0463edb8518
Get around a bug on skip-chars-forward.
Gerd Moellmann <gerd@gnu.org>
parents:
30552
diff
changeset
|
4973 ;;(skip-chars-forward (concat chars "\240-\377") ebnf-limit) |
f0463edb8518
Get around a bug on skip-chars-forward.
Gerd Moellmann <gerd@gnu.org>
parents:
30552
diff
changeset
|
4974 (skip-chars-forward (concat chars ebnf-8-bit-chars) ebnf-limit) |
27451 | 4975 (if (or (eobp) (/= (following-char) eos-char)) |
4976 (error "Illegal %s: missing `%c'." kind eos-char) | |
4977 (forward-char) | |
4978 (1- (point)))))) | |
4979 | |
4980 | |
4981 (defun ebnf-get-string () | |
4982 (forward-char) | |
4983 (buffer-substring-no-properties (point) (ebnf-end-of-string))) | |
4984 | |
4985 | |
4986 (defun ebnf-end-of-string () | |
4987 (let ((n 1)) | |
4988 (while (> (logand n 1) 0) | |
4989 (skip-chars-forward "^\"" ebnf-limit) | |
4990 (setq n (- (skip-chars-backward "\\\\"))) | |
4991 (goto-char (+ (point) n 1)))) | |
4992 (if (= (preceding-char) ?\") | |
4993 (1- (point)) | |
4994 (error "Missing `\"'."))) | |
4995 | |
4996 | |
4997 (defun ebnf-trim-right (str) | |
4998 (let* ((len (1- (length str))) | |
4999 (index len)) | |
5000 (while (and (> index 0) (= (aref str index) ?\ )) | |
5001 (setq index (1- index))) | |
5002 (if (= index len) | |
5003 str | |
5004 (substring str 0 (1+ index))))) | |
5005 | |
5006 | |
5007 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
5008 ;; Vector creation | |
5009 | |
5010 | |
5011 (defun ebnf-make-empty (&optional width) | |
5012 (vector 'ebnf-generate-empty | |
5013 'ignore | |
5014 'ignore | |
5015 0.0 | |
5016 0.0 | |
5017 (or width ebnf-horizontal-space))) | |
5018 | |
5019 | |
5020 (defun ebnf-make-terminal (name) | |
5021 (ebnf-make-terminal1 name | |
5022 'ebnf-generate-terminal | |
5023 'ebnf-terminal-dimension)) | |
5024 | |
5025 | |
5026 (defun ebnf-make-non-terminal (name) | |
5027 (ebnf-make-terminal1 name | |
5028 'ebnf-generate-non-terminal | |
5029 'ebnf-non-terminal-dimension)) | |
5030 | |
5031 | |
5032 (defun ebnf-make-special (name) | |
5033 (ebnf-make-terminal1 name | |
5034 'ebnf-generate-special | |
5035 'ebnf-special-dimension)) | |
5036 | |
5037 | |
5038 (defun ebnf-make-terminal1 (name gen-func dim-func) | |
5039 (vector gen-func | |
5040 'ignore | |
5041 dim-func | |
5042 0.0 | |
5043 0.0 | |
5044 0.0 | |
5045 (let ((len (length name))) | |
5046 (cond ((> len 2) name) | |
5047 ((= len 2) (concat " " name)) | |
5048 ((= len 1) (concat " " name " ")) | |
5049 (t " "))) | |
5050 ebnf-default-p)) | |
5051 | |
5052 | |
5053 (defun ebnf-make-one-or-more (list-part &optional sep-part) | |
5054 (ebnf-make-or-more1 'ebnf-generate-one-or-more | |
5055 'ebnf-one-or-more-dimension | |
5056 list-part | |
5057 sep-part)) | |
5058 | |
5059 | |
5060 (defun ebnf-make-zero-or-more (list-part &optional sep-part) | |
5061 (ebnf-make-or-more1 'ebnf-generate-zero-or-more | |
5062 'ebnf-zero-or-more-dimension | |
5063 list-part | |
5064 sep-part)) | |
5065 | |
5066 | |
5067 (defun ebnf-make-or-more1 (gen-func dim-func list-part sep-part) | |
5068 (vector gen-func | |
5069 'ebnf-list-width | |
5070 dim-func | |
5071 0.0 | |
5072 0.0 | |
5073 0.0 | |
5074 (if (listp list-part) | |
5075 (ebnf-make-sequence list-part) | |
5076 list-part) | |
5077 (if (and sep-part (listp sep-part)) | |
5078 (ebnf-make-sequence sep-part) | |
5079 sep-part))) | |
5080 | |
5081 | |
5082 (defun ebnf-make-production (name prod action) | |
5083 (vector 'ebnf-generate-production | |
5084 'ignore | |
5085 'ebnf-production-dimension | |
5086 0.0 | |
5087 0.0 | |
5088 0.0 | |
5089 name | |
5090 prod | |
5091 action)) | |
5092 | |
5093 | |
5094 (defun ebnf-make-alternative (body) | |
5095 (vector 'ebnf-generate-alternative | |
5096 'ebnf-alternative-width | |
5097 'ebnf-alternative-dimension | |
5098 0.0 | |
5099 0.0 | |
5100 0.0 | |
5101 body)) | |
5102 | |
5103 | |
5104 (defun ebnf-make-optional (body) | |
5105 (vector 'ebnf-generate-optional | |
5106 'ebnf-alternative-width | |
5107 'ebnf-optional-dimension | |
5108 0.0 | |
5109 0.0 | |
5110 0.0 | |
5111 body)) | |
5112 | |
5113 | |
5114 (defun ebnf-make-except (factor exception) | |
5115 (vector 'ebnf-generate-except | |
5116 'ignore | |
5117 'ebnf-except-dimension | |
5118 0.0 | |
5119 0.0 | |
5120 0.0 | |
5121 factor | |
5122 exception)) | |
5123 | |
5124 | |
5125 (defun ebnf-make-repeat (times primary) | |
5126 (vector 'ebnf-generate-repeat | |
5127 'ignore | |
5128 'ebnf-repeat-dimension | |
5129 0.0 | |
5130 0.0 | |
5131 0.0 | |
5132 (concat times " *") | |
5133 primary)) | |
5134 | |
5135 | |
5136 (defun ebnf-make-sequence (seq) | |
5137 (vector 'ebnf-generate-sequence | |
5138 'ebnf-sequence-width | |
5139 'ebnf-sequence-dimension | |
5140 0.0 | |
5141 0.0 | |
5142 0.0 | |
5143 seq)) | |
5144 | |
5145 | |
5146 (defun ebnf-make-dup-sequence (node seq) | |
5147 (vector 'ebnf-generate-sequence | |
5148 'ebnf-sequence-width | |
5149 'ebnf-sequence-dimension | |
5150 (ebnf-node-entry node) | |
5151 (ebnf-node-height node) | |
5152 (ebnf-node-width node) | |
5153 seq)) | |
5154 | |
5155 | |
5156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
5157 ;; Optimizers used by parsers | |
5158 | |
5159 | |
5160 (defun ebnf-token-except (element exception) | |
5161 (cons (prog1 | |
5162 (car exception) | |
5163 (setq exception (cdr exception))) | |
5164 (and element ; EMPTY - A ==> EMPTY | |
5165 (let ((kind (ebnf-node-kind element))) | |
5166 (cond | |
5167 ;; [ A ]- ==> A | |
5168 ((and (null exception) | |
5169 (eq kind 'ebnf-generate-optional)) | |
5170 (ebnf-node-list element)) | |
5171 ;; { A }- ==> { A }+ | |
5172 ((and (null exception) | |
5173 (eq kind 'ebnf-generate-zero-or-more)) | |
5174 (ebnf-node-kind element 'ebnf-generate-one-or-more) | |
5175 (ebnf-node-dimension-func element 'ebnf-one-or-more-dimension) | |
5176 element) | |
5177 ;; ( A | EMPTY )- ==> A | |
5178 ;; ( A | B | EMPTY )- ==> A | B | |
5179 ((and (null exception) | |
5180 (eq kind 'ebnf-generate-alternative) | |
30552
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
5181 (eq (ebnf-node-kind |
a7498193b035
Update ps-print functions call. Indentation fix. Doc
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
5182 (car (last (ebnf-node-list element)))) |
27451 | 5183 'ebnf-generate-empty)) |
5184 (let ((elt (ebnf-node-list element)) | |
5185 bef) | |
5186 (while (cdr elt) | |
5187 (setq bef elt | |
5188 elt (cdr elt))) | |
5189 (if (null bef) | |
5190 ;; this should not happen!!?! | |
5191 (setq element (ebnf-make-empty | |
5192 (ebnf-node-width element))) | |
5193 (setcdr bef nil) | |
5194 (setq elt (ebnf-node-list element)) | |
5195 (and (= (length elt) 1) | |
5196 (setq element (car elt)))) | |
5197 element)) | |
5198 ;; A - B | |
5199 (t | |
5200 (ebnf-make-except element exception)) | |
5201 ))))) | |
5202 | |
5203 | |
5204 (defun ebnf-token-repeat (times repeat) | |
5205 (if (null (cdr repeat)) | |
5206 ;; n * EMPTY ==> EMPTY | |
5207 repeat | |
5208 ;; n * term | |
5209 (cons (car repeat) | |
5210 (ebnf-make-repeat times (cdr repeat))))) | |
5211 | |
5212 | |
5213 (defun ebnf-token-optional (body) | |
5214 (let ((kind (ebnf-node-kind body))) | |
5215 (cond | |
5216 ;; [ EMPTY ] ==> EMPTY | |
5217 ((eq kind 'ebnf-generate-empty) | |
5218 nil) | |
5219 ;; [ { A }* ] ==> { A }* | |
5220 ((eq kind 'ebnf-generate-zero-or-more) | |
5221 body) | |
5222 ;; [ { A }+ ] ==> { A }* | |
5223 ((eq kind 'ebnf-generate-one-or-more) | |
5224 (ebnf-node-kind body 'ebnf-generate-zero-or-more) | |
5225 body) | |
5226 ;; [ A | B ] ==> A | B | EMPTY | |
5227 ((eq kind 'ebnf-generate-alternative) | |
5228 (ebnf-node-list body (nconc (ebnf-node-list body) | |
5229 (list (ebnf-make-empty)))) | |
5230 body) | |
5231 ;; [ A ] | |
5232 (t | |
5233 (ebnf-make-optional body)) | |
5234 ))) | |
5235 | |
5236 | |
5237 (defun ebnf-token-alternative (body sequence) | |
5238 (if (null body) | |
5239 (if (cdr sequence) | |
5240 sequence | |
5241 (cons (car sequence) | |
5242 (ebnf-make-empty))) | |
5243 (cons (car sequence) | |
5244 (let ((seq (cdr sequence))) | |
5245 (if (and (= (length body) 1) (null seq)) | |
5246 (car body) | |
5247 (ebnf-make-alternative (nreverse (if seq | |
5248 (cons seq body) | |
5249 body)))))))) | |
5250 | |
5251 | |
5252 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
5253 ;; Variables used by parsers | |
5254 | |
5255 | |
5256 (defconst ebnf-comment-table | |
5257 (let ((table (make-vector 256 nil))) | |
5258 ;; Override special comment character: | |
5259 (aset table ?< 'newline) | |
5260 (aset table ?> 'keep-line) | |
5261 table) | |
5262 "Vector used to map characters to a special comment token.") | |
5263 | |
5264 | |
5265 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
5266 ;; To make this file smaller, some commands go in a separate file. | |
5267 ;; But autoload them here to make the separation invisible. | |
5268 | |
5269 (autoload 'ebnf-bnf-parser "ebnf-bnf" | |
5270 "EBNF parser.") | |
5271 | |
5272 (autoload 'ebnf-bnf-initialize "ebnf-bnf" | |
5273 "Initialize EBNF token table.") | |
5274 | |
5275 (autoload 'ebnf-iso-parser "ebnf-iso" | |
5276 "ISO EBNF parser.") | |
5277 | |
5278 (autoload 'ebnf-iso-initialize "ebnf-iso" | |
5279 "Initialize ISO EBNF token table.") | |
5280 | |
5281 (autoload 'ebnf-yac-parser "ebnf-yac" | |
5282 "Yacc/Bison parser.") | |
5283 | |
5284 (autoload 'ebnf-yac-initialize "ebnf-yac" | |
5285 "Initializations for Yacc/Bison parser.") | |
5286 | |
5287 (autoload 'ebnf-eliminate-empty-rules "ebnf-otz" | |
5288 "Eliminate empty rules.") | |
5289 | |
5290 (autoload 'ebnf-optimize "ebnf-otz" | |
5291 "Syntatic chart optimizer.") | |
5292 | |
5293 (autoload 'ebnf-otz-initialize "ebnf-otz" | |
5294 "Initialize optimizer.") | |
5295 | |
5296 | |
5297 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
5298 | |
5299 | |
5300 (provide 'ebnf2ps) | |
5301 | |
5302 | |
5303 ;;; ebnf2ps.el ends here |