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