Mercurial > emacs
annotate lisp/progmodes/ebnf-iso.el @ 89905:37e044cc35f6
(Ffind_coding_systems_region_internal): Include raw-text and
no-conversion in the result.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Wed, 14 Apr 2004 12:37:29 +0000 |
parents | 375f2633d815 |
children | 68c22ea6027c |
rev | line source |
---|---|
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34805
diff
changeset
|
1 ;;; ebnf-iso.el --- parser for ISO EBNF |
27451 | 2 |
88123 | 3 ;; Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. |
27451 | 4 |
39344 | 5 ;; Author: Vinicius Jose Latorre <vinicius@cpqd.com.br> |
27451 | 6 ;; Maintainer: Vinicius Jose Latorre <vinicius@cpqd.com.br> |
39344 | 7 ;; Keywords: wp, ebnf, PostScript |
88123 | 8 ;; Time-stamp: <2003-02-10 10:26:32 jbarranquero> |
39423
5695968e6eb1
Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents:
39344
diff
changeset
|
9 ;; Version: 1.6 |
27451 | 10 |
27539 | 11 ;; This file is part of GNU Emacs. |
27451 | 12 |
27539 | 13 ;; GNU Emacs is free software; you can redistribute it and/or modify |
27451 | 14 ;; it under the terms of the GNU General Public License as published by |
15 ;; the Free Software Foundation; either version 2, or (at your option) | |
16 ;; any later version. | |
17 | |
27539 | 18 ;; GNU Emacs is distributed in the hope that it will be useful, |
27451 | 19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;; GNU General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
26 ;; Boston, MA 02111-1307, USA. | |
27 | |
28 ;;; Commentary: | |
29 | |
30 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
31 ;; | |
32 ;; | |
33 ;; This is part of ebnf2ps package. | |
34 ;; | |
35 ;; This package defines a parser for ISO EBNF. | |
36 ;; | |
37 ;; See ebnf2ps.el for documentation. | |
38 ;; | |
39 ;; | |
40 ;; ISO EBNF Syntax | |
41 ;; --------------- | |
42 ;; | |
43 ;; See the URL: | |
44 ;; `http://www.cl.cam.ac.uk/~mgk25/iso-ebnf.html' | |
45 ;; ("International Standard of the ISO EBNF Notation"). | |
46 ;; | |
47 ;; | |
48 ;; ISO EBNF = syntax rule, {syntax rule}; | |
49 ;; | |
50 ;; syntax rule = meta identifier, '=', definition list, ';'; | |
51 ;; | |
52 ;; definition list = single definition, {'|', single definition}; | |
53 ;; | |
54 ;; single definition = term, {',', term}; | |
55 ;; | |
56 ;; term = factor, ['-', exception]; | |
57 ;; | |
58 ;; exception = factor (* without <meta identifier> *); | |
59 ;; | |
60 ;; factor = [integer, '*'], primary; | |
61 ;; | |
62 ;; primary = optional sequence | repeated sequence | special sequence | |
63 ;; | grouped sequence | meta identifier | terminal string | |
64 ;; | empty; | |
65 ;; | |
66 ;; empty = ; | |
67 ;; | |
68 ;; optional sequence = '[', definition list, ']'; | |
69 ;; | |
70 ;; repeated sequence = '{', definition list, '}'; | |
71 ;; | |
72 ;; grouped sequence = '(', definition list, ')'; | |
73 ;; | |
74 ;; terminal string = "'", character - "'", {character - "'"}, "'" | |
75 ;; | '"', character - '"', {character - '"'}, '"'; | |
76 ;; | |
77 ;; special sequence = '?', {character - '?'}, '?'; | |
78 ;; | |
79 ;; meta identifier = letter, { letter | decimal digit | ' ' }; | |
80 ;; | |
81 ;; integer = decimal digit, {decimal digit}; | |
82 ;; | |
83 ;; comment = '(*', {comment symbol}, '*)'; | |
84 ;; | |
85 ;; comment symbol = comment (* <== NESTED COMMENT *) | |
86 ;; | terminal string | special sequence | character; | |
87 ;; | |
88 ;; letter = ? A-Z a-z ?; | |
89 ;; | |
90 ;; decimal digit = ? 0-9 ?; | |
91 ;; | |
92 ;; character = letter | decimal digit | |
93 ;; | ',' | '=' | '|' | '/' | '!' | '*' | '(' | ')' | '[' | ']' | '{' | |
94 ;; | '}' | "'" | '"' | '?' | '-' | ';' | '.' | ' ' | ':' | '+' | '_' | |
95 ;; | '%' | '@' | '&' | '#' | '$' | '<' | '>' | '\' | '^' | '`' | '~'; | |
96 ;; | |
97 ;; | |
98 ;; There is also the following alternative representation: | |
99 ;; | |
100 ;; STANDARD ALTERNATIVE | |
101 ;; | ==> / or ! | |
102 ;; [ ==> (/ | |
103 ;; ] ==> /) | |
104 ;; { ==> (: | |
105 ;; } ==> :) | |
106 ;; ; ==> . | |
107 ;; | |
108 ;; | |
109 ;; Differences Between ISO EBNF And ebnf2ps ISO EBNF | |
110 ;; ------------------------------------------------- | |
111 ;; | |
112 ;; ISO EBNF accepts the characters given by <character> production above, | |
113 ;; HORIZONTAL TAB (^I), VERTICAL TAB (^K), NEWLINE (^J or ^M) and FORM FEED | |
114 ;; (^L), any other characters are illegal. But ebnf2ps accepts also the | |
115 ;; european 8-bit accentuated characters (from \240 to \377). | |
116 ;; | |
117 ;; | |
118 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
119 | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34805
diff
changeset
|
120 ;;; Code: |
27451 | 121 |
122 | |
123 (require 'ebnf-otz) | |
124 | |
125 | |
126 (defvar ebnf-iso-lex nil | |
127 "Value returned by `ebnf-iso-lex' function.") | |
128 | |
129 | |
88123 | 130 (defconst ebnf-no-meta-identifier nil) |
27451 | 131 |
132 | |
133 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
49670
cc820064216c
Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents:
39423
diff
changeset
|
134 ;; Syntactic analyzer |
27451 | 135 |
136 | |
137 ;;; ISO EBNF = syntax rule, {syntax rule}; | |
138 | |
139 (defun ebnf-iso-parser (start) | |
140 "ISO EBNF parser." | |
141 (let ((total (+ (- ebnf-limit start) 1)) | |
142 (bias (1- start)) | |
143 (origin (point)) | |
144 syntax-list token rule) | |
145 (goto-char start) | |
146 (setq token (ebnf-iso-lex)) | |
147 (and (eq token 'end-of-input) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34805
diff
changeset
|
148 (error "Invalid ISO EBNF file format")) |
27451 | 149 (while (not (eq token 'end-of-input)) |
150 (ebnf-message-float | |
151 "Parsing...%s%%" | |
152 (/ (* (- (point) bias) 100.0) total)) | |
153 (setq token (ebnf-iso-syntax-rule token) | |
154 rule (cdr token) | |
155 token (car token)) | |
156 (or (ebnf-add-empty-rule-list rule) | |
157 (setq syntax-list (cons rule syntax-list)))) | |
158 (goto-char origin) | |
159 syntax-list)) | |
160 | |
161 | |
162 ;;; syntax rule = meta identifier, '=', definition list, ';'; | |
163 | |
164 (defun ebnf-iso-syntax-rule (token) | |
165 (let ((header ebnf-iso-lex) | |
166 (action ebnf-action) | |
167 body) | |
168 (setq ebnf-action nil) | |
169 (or (eq token 'non-terminal) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34805
diff
changeset
|
170 (error "Invalid meta identifier syntax rule")) |
27451 | 171 (or (eq (ebnf-iso-lex) 'equal) |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34805
diff
changeset
|
172 (error "Invalid syntax rule: missing `='")) |
27451 | 173 (setq body (ebnf-iso-definition-list)) |
174 (or (eq (car body) 'period) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34805
diff
changeset
|
175 (error "Invalid syntax rule: missing `;' or `.'")) |
27451 | 176 (setq body (cdr body)) |
177 (ebnf-eps-add-production header) | |
178 (cons (ebnf-iso-lex) | |
179 (ebnf-make-production header body action)))) | |
180 | |
181 | |
182 ;;; definition list = single definition, {'|', single definition}; | |
183 | |
184 (defun ebnf-iso-definition-list () | |
185 (let (body sequence) | |
186 (while (eq (car (setq sequence (ebnf-iso-single-definition))) | |
187 'alternative) | |
188 (setq sequence (cdr sequence) | |
189 body (cons sequence body))) | |
190 (ebnf-token-alternative body sequence))) | |
191 | |
192 | |
193 ;;; single definition = term, {',', term}; | |
194 | |
195 (defun ebnf-iso-single-definition () | |
196 (let (token seq term) | |
197 (while (and (setq term (ebnf-iso-term (ebnf-iso-lex)) | |
198 token (car term) | |
199 term (cdr term)) | |
200 (eq token 'catenate)) | |
201 (setq seq (cons term seq))) | |
202 (cons token | |
203 (cond | |
204 ;; null sequence | |
205 ((null seq) | |
206 term) | |
207 ;; sequence with only one element | |
208 ((and (null term) (= (length seq) 1)) | |
209 (car seq)) | |
210 ;; a real sequence | |
211 (t | |
212 (ebnf-make-sequence (nreverse (cons term seq)))) | |
213 )))) | |
214 | |
215 | |
216 ;;; term = factor, ['-', exception]; | |
217 ;;; | |
218 ;;; exception = factor (* without <meta identifier> *); | |
219 | |
220 (defun ebnf-iso-term (token) | |
221 (let ((factor (ebnf-iso-factor token))) | |
222 (if (not (eq (car factor) 'except)) | |
223 ;; factor | |
224 factor | |
225 ;; factor - exception | |
226 (let ((ebnf-no-meta-identifier t)) | |
227 (ebnf-token-except (cdr factor) (ebnf-iso-factor (ebnf-iso-lex))))))) | |
228 | |
229 | |
230 ;;; factor = [integer, '*'], primary; | |
231 | |
232 (defun ebnf-iso-factor (token) | |
233 (if (eq token 'integer) | |
234 (let ((times ebnf-iso-lex)) | |
235 (or (eq (ebnf-iso-lex) 'repeat) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34805
diff
changeset
|
236 (error "Missing `*'")) |
27451 | 237 (ebnf-token-repeat times (ebnf-iso-primary (ebnf-iso-lex)))) |
238 (ebnf-iso-primary token))) | |
239 | |
240 | |
241 ;;; primary = optional sequence | repeated sequence | special sequence | |
242 ;;; | grouped sequence | meta identifier | terminal string | |
243 ;;; | empty; | |
244 ;;; | |
245 ;;; empty = ; | |
246 ;;; | |
247 ;;; optional sequence = '[', definition list, ']'; | |
248 ;;; | |
249 ;;; repeated sequence = '{', definition list, '}'; | |
250 ;;; | |
251 ;;; grouped sequence = '(', definition list, ')'; | |
252 ;;; | |
253 ;;; terminal string = "'", character - "'", {character - "'"}, "'" | |
254 ;;; | '"', character - '"', {character - '"'}, '"'; | |
255 ;;; | |
256 ;;; special sequence = '?', {character - '?'}, '?'; | |
257 ;;; | |
258 ;;; meta identifier = letter, {letter | decimal digit}; | |
259 | |
260 (defun ebnf-iso-primary (token) | |
261 (let ((primary | |
262 (cond | |
263 ;; terminal string | |
264 ((eq token 'terminal) | |
265 (ebnf-make-terminal ebnf-iso-lex)) | |
266 ;; meta identifier | |
267 ((eq token 'non-terminal) | |
268 (ebnf-make-non-terminal ebnf-iso-lex)) | |
269 ;; special sequence | |
270 ((eq token 'special) | |
271 (ebnf-make-special ebnf-iso-lex)) | |
272 ;; grouped sequence | |
273 ((eq token 'begin-group) | |
274 (let ((body (ebnf-iso-definition-list))) | |
275 (or (eq (car body) 'end-group) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34805
diff
changeset
|
276 (error "Missing `)'")) |
27451 | 277 (cdr body))) |
278 ;; optional sequence | |
279 ((eq token 'begin-optional) | |
280 (let ((body (ebnf-iso-definition-list))) | |
281 (or (eq (car body) 'end-optional) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34805
diff
changeset
|
282 (error "Missing `]' or `/)'")) |
27451 | 283 (ebnf-token-optional (cdr body)))) |
284 ;; repeated sequence | |
285 ((eq token 'begin-zero-or-more) | |
286 (let* ((body (ebnf-iso-definition-list)) | |
287 (repeat (cdr body))) | |
288 (or (eq (car body) 'end-zero-or-more) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34805
diff
changeset
|
289 (error "Missing `}' or `:)'")) |
27451 | 290 (ebnf-make-zero-or-more repeat))) |
291 ;; empty | |
292 (t | |
293 nil) | |
294 ))) | |
295 (cons (if primary | |
296 (ebnf-iso-lex) | |
297 token) | |
298 primary))) | |
299 | |
300 | |
301 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
302 ;; Lexical analyzer | |
303 | |
304 | |
305 (defconst ebnf-iso-token-table | |
306 ;; control character & 8-bit character are set to `error' | |
307 (let ((table (make-vector 256 'error)) | |
308 (char ?\040)) | |
309 ;; printable character | |
310 (while (< char ?\060) | |
311 (aset table char 'character) | |
312 (setq char (1+ char))) | |
313 ;; digits: | |
314 (while (< char ?\072) | |
315 (aset table char 'integer) | |
316 (setq char (1+ char))) | |
317 (while (< char ?\101) | |
318 (aset table char 'character) | |
319 (setq char (1+ char))) | |
320 ;; upper case letters: | |
321 (while (< char ?\133) | |
322 (aset table char 'non-terminal) | |
323 (setq char (1+ char))) | |
324 (while (< char ?\141) | |
325 (aset table char 'character) | |
326 (setq char (1+ char))) | |
327 ;; lower case letters: | |
328 (while (< char ?\173) | |
329 (aset table char 'non-terminal) | |
330 (setq char (1+ char))) | |
331 (while (< char ?\177) | |
332 (aset table char 'character) | |
333 (setq char (1+ char))) | |
334 ;; European 8-bit accentuated characters: | |
335 (setq char ?\240) | |
336 (while (< char ?\400) | |
337 (aset table char 'non-terminal) | |
338 (setq char (1+ char))) | |
339 ;; Override space characters: | |
340 (aset table ?\013 'space) ; [VT] vertical tab | |
341 (aset table ?\n 'space) ; [NL] linefeed | |
342 (aset table ?\r 'space) ; [CR] carriage return | |
343 (aset table ?\t 'space) ; [HT] horizontal tab | |
344 (aset table ?\ 'space) ; [SP] space | |
345 ;; Override form feed character: | |
346 (aset table ?\f 'form-feed) ; [FF] form feed | |
347 ;; Override other lexical characters: | |
348 (aset table ?\" 'double-terminal) | |
349 (aset table ?\' 'single-terminal) | |
350 (aset table ?\? 'special) | |
351 (aset table ?* 'repeat) | |
352 (aset table ?, 'catenate) | |
353 (aset table ?- 'except) | |
354 (aset table ?= 'equal) | |
355 (aset table ?\) 'end-group) | |
356 table) | |
357 "Vector used to map characters to a lexical token.") | |
358 | |
359 | |
360 (defun ebnf-iso-initialize () | |
361 "Initialize ISO EBNF token table." | |
362 (if ebnf-iso-alternative-p | |
363 ;; Override alternative lexical characters: | |
364 (progn | |
365 (aset ebnf-iso-token-table ?\( 'left-parenthesis) | |
366 (aset ebnf-iso-token-table ?\[ 'character) | |
367 (aset ebnf-iso-token-table ?\] 'character) | |
368 (aset ebnf-iso-token-table ?\{ 'character) | |
369 (aset ebnf-iso-token-table ?\} 'character) | |
370 (aset ebnf-iso-token-table ?| 'character) | |
371 (aset ebnf-iso-token-table ?\; 'character) | |
372 (aset ebnf-iso-token-table ?/ 'slash) | |
373 (aset ebnf-iso-token-table ?! 'alternative) | |
374 (aset ebnf-iso-token-table ?: 'colon) | |
375 (aset ebnf-iso-token-table ?. 'period)) | |
376 ;; Override standard lexical characters: | |
377 (aset ebnf-iso-token-table ?\( 'begin-parenthesis) | |
378 (aset ebnf-iso-token-table ?\[ 'begin-optional) | |
379 (aset ebnf-iso-token-table ?\] 'end-optional) | |
380 (aset ebnf-iso-token-table ?\{ 'begin-zero-or-more) | |
381 (aset ebnf-iso-token-table ?\} 'end-zero-or-more) | |
382 (aset ebnf-iso-token-table ?| 'alternative) | |
383 (aset ebnf-iso-token-table ?\; 'period) | |
384 (aset ebnf-iso-token-table ?/ 'character) | |
385 (aset ebnf-iso-token-table ?! 'character) | |
386 (aset ebnf-iso-token-table ?: 'character) | |
387 (aset ebnf-iso-token-table ?. 'character))) | |
388 | |
389 | |
39423
5695968e6eb1
Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents:
39344
diff
changeset
|
390 ;; replace the range "\240-\377" (see `ebnf-range-regexp'). |
5695968e6eb1
Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents:
39344
diff
changeset
|
391 (defconst ebnf-iso-non-terminal-chars |
5695968e6eb1
Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents:
39344
diff
changeset
|
392 (ebnf-range-regexp " 0-9A-Za-z" ?\240 ?\377)) |
5695968e6eb1
Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents:
39344
diff
changeset
|
393 |
5695968e6eb1
Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents:
39344
diff
changeset
|
394 |
27451 | 395 (defun ebnf-iso-lex () |
396 "Lexical analyser for ISO EBNF. | |
397 | |
398 Return a lexical token. | |
399 | |
400 See documentation for variable `ebnf-iso-lex'." | |
401 (if (>= (point) ebnf-limit) | |
402 'end-of-input | |
403 (let (token) | |
404 ;; skip spaces and comments | |
405 (while (if (> (following-char) 255) | |
406 (progn | |
407 (setq token 'error) | |
408 nil) | |
409 (setq token (aref ebnf-iso-token-table (following-char))) | |
410 (cond | |
411 ((eq token 'space) | |
412 (skip-chars-forward " \013\n\r\t" ebnf-limit) | |
413 (< (point) ebnf-limit)) | |
414 ((or (eq token 'begin-parenthesis) | |
415 (eq token 'left-parenthesis)) | |
416 (forward-char) | |
417 (if (/= (following-char) ?*) | |
418 ;; no comment | |
419 nil | |
420 ;; comment | |
421 (ebnf-iso-skip-comment) | |
422 t)) | |
423 ((eq token 'form-feed) | |
424 (forward-char) | |
425 (setq ebnf-action 'form-feed)) | |
426 (t nil) | |
427 ))) | |
428 (cond | |
429 ;; end of input | |
430 ((>= (point) ebnf-limit) | |
431 'end-of-input) | |
432 ;; error | |
433 ((eq token 'error) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34805
diff
changeset
|
434 (error "Illegal character")) |
27451 | 435 ;; integer |
436 ((eq token 'integer) | |
437 (setq ebnf-iso-lex (ebnf-buffer-substring "0-9")) | |
438 'integer) | |
439 ;; special: ?special? | |
440 ((eq token 'special) | |
441 (setq ebnf-iso-lex (concat "?" | |
442 (ebnf-string " ->@-~" ?\? "special") | |
443 "?")) | |
444 'special) | |
445 ;; terminal: "string" | |
446 ((eq token 'double-terminal) | |
447 (setq ebnf-iso-lex (ebnf-string " !#-~" ?\" "terminal")) | |
448 'terminal) | |
449 ;; terminal: 'string' | |
450 ((eq token 'single-terminal) | |
451 (setq ebnf-iso-lex (ebnf-string " -&(-~" ?\' "terminal")) | |
452 'terminal) | |
453 ;; non-terminal | |
454 ((eq token 'non-terminal) | |
39423
5695968e6eb1
Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents:
39344
diff
changeset
|
455 (setq ebnf-iso-lex |
5695968e6eb1
Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents:
39344
diff
changeset
|
456 (ebnf-iso-normalize |
5695968e6eb1
Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents:
39344
diff
changeset
|
457 (ebnf-trim-right |
5695968e6eb1
Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents:
39344
diff
changeset
|
458 (ebnf-buffer-substring ebnf-iso-non-terminal-chars)))) |
27451 | 459 (and ebnf-no-meta-identifier |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34805
diff
changeset
|
460 (error "Exception sequence should not contain a meta identifier")) |
27451 | 461 'non-terminal) |
462 ;; begin optional, begin list or begin group | |
463 ((eq token 'left-parenthesis) | |
464 (forward-char) | |
465 (cond ((= (following-char) ?/) | |
466 (forward-char) | |
467 'begin-optional) | |
468 ((= (following-char) ?:) | |
469 (forward-char) | |
470 'begin-zero-or-more) | |
471 (t | |
472 'begin-group) | |
473 )) | |
474 ;; end optional or alternative | |
475 ((eq token 'slash) | |
476 (forward-char) | |
477 (if (/= (following-char) ?\)) | |
478 'alternative | |
479 (forward-char) | |
480 'end-optional)) | |
481 ;; end list | |
482 ((eq token 'colon) | |
483 (forward-char) | |
484 (if (/= (following-char) ?\)) | |
485 'character | |
486 (forward-char) | |
487 'end-zero-or-more)) | |
488 ;; begin group | |
489 ((eq token 'begin-parenthesis) | |
490 'begin-group) | |
491 ;; miscellaneous | |
492 (t | |
493 (forward-char) | |
494 token) | |
495 )))) | |
496 | |
497 | |
34805
aef14b635283
Fix the same problem as described on ebnf2ps.el log
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
498 ;; replace the range "\177-\237" (see `ebnf-range-regexp'). |
aef14b635283
Fix the same problem as described on ebnf2ps.el log
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
499 (defconst ebnf-iso-comment-chars |
aef14b635283
Fix the same problem as described on ebnf2ps.el log
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
500 (ebnf-range-regexp "^*(\000-\010\016-\037" ?\177 ?\237)) |
27451 | 501 |
502 | |
503 (defun ebnf-iso-skip-comment () | |
504 (forward-char) | |
505 (cond | |
506 ;; open EPS file | |
507 ((and ebnf-eps-executing (= (following-char) ?\[)) | |
508 (ebnf-eps-add-context (ebnf-iso-eps-filename))) | |
509 ;; close EPS file | |
510 ((and ebnf-eps-executing (= (following-char) ?\])) | |
511 (ebnf-eps-remove-context (ebnf-iso-eps-filename))) | |
512 ;; any other action in comment | |
513 (t | |
514 (setq ebnf-action (aref ebnf-comment-table (following-char)))) | |
515 ) | |
516 (let ((pair 1)) | |
517 (while (> pair 0) | |
518 (skip-chars-forward ebnf-iso-comment-chars ebnf-limit) | |
519 (cond ((>= (point) ebnf-limit) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34805
diff
changeset
|
520 (error "Missing end of comment: `*)'")) |
27451 | 521 ((= (following-char) ?*) |
522 (skip-chars-forward "*" ebnf-limit) | |
523 (when (= (following-char) ?\)) | |
524 ;; end of comment | |
525 (forward-char) | |
526 (setq pair (1- pair)))) | |
527 ((= (following-char) ?\() | |
528 (skip-chars-forward "(" ebnf-limit) | |
529 (when (= (following-char) ?*) | |
530 ;; beginning of comment | |
531 (forward-char) | |
532 (setq pair (1+ pair)))) | |
533 (t | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34805
diff
changeset
|
534 (error "Illegal character")) |
27451 | 535 )))) |
536 | |
537 | |
538 (defun ebnf-iso-eps-filename () | |
539 (forward-char) | |
540 (buffer-substring-no-properties | |
541 (point) | |
542 (let ((chars (concat ebnf-iso-comment-chars "\n")) | |
543 found) | |
544 (while (not found) | |
545 (skip-chars-forward chars ebnf-limit) | |
546 (setq found | |
547 (cond ((>= (point) ebnf-limit) | |
548 (point)) | |
549 ((= (following-char) ?*) | |
550 (skip-chars-forward "*" ebnf-limit) | |
551 (if (/= (following-char) ?\)) | |
552 nil | |
553 (backward-char) | |
554 (point))) | |
555 ((= (following-char) ?\() | |
556 (forward-char) | |
557 (if (/= (following-char) ?*) | |
558 nil | |
559 (backward-char) | |
560 (point))) | |
561 (t | |
562 (point)) | |
563 ))) | |
564 found))) | |
565 | |
566 | |
567 (defun ebnf-iso-normalize (str) | |
568 (if (not ebnf-iso-normalize-p) | |
569 str | |
570 (let ((len (length str)) | |
571 (stri 0) | |
572 (spaces 0)) | |
573 ;; count exceeding spaces | |
574 (while (< stri len) | |
575 (if (/= (aref str stri) ?\ ) | |
576 (setq stri (1+ stri)) | |
577 (setq stri (1+ stri)) | |
578 (while (and (< stri len) (= (aref str stri) ?\ )) | |
579 (setq stri (1+ stri) | |
580 spaces (1+ spaces))))) | |
581 (if (zerop spaces) | |
582 ;; no exceeding space | |
583 str | |
584 ;; at least one exceeding space | |
585 (let ((new (make-string (- len spaces) ?\ )) | |
586 (newi 0)) | |
587 ;; eliminate exceeding spaces | |
588 (setq stri 0) | |
589 (while (> spaces 0) | |
590 (if (/= (aref str stri) ?\ ) | |
591 (progn | |
592 (aset new newi (aref str stri)) | |
593 (setq stri (1+ stri) | |
594 newi (1+ newi))) | |
595 (aset new newi (aref str stri)) | |
596 (setq stri (1+ stri) | |
597 newi (1+ newi)) | |
598 (while (and (> spaces 0) (= (aref str stri) ?\ )) | |
599 (setq stri (1+ stri) | |
600 spaces (1- spaces))))) | |
601 ;; remaining is normalized | |
602 (while (< stri len) | |
603 (aset new newi (aref str stri)) | |
604 (setq stri (1+ stri) | |
605 newi (1+ newi))) | |
606 new))))) | |
607 | |
608 | |
609 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
610 | |
611 | |
612 (provide 'ebnf-iso) | |
613 | |
614 | |
615 ;;; ebnf-iso.el ends here |