comparison lisp/progmodes/ebnf-bnf.el @ 89909:68c22ea6027c

Sync to HEAD
author Kenichi Handa <handa@m17n.org>
date Fri, 16 Apr 2004 12:51:06 +0000
parents 375f2633d815
children 4da4a09e8b1b
comparison
equal deleted inserted replaced
89908:ee1402f7b568 89909:68c22ea6027c
1 ;;; ebnf-bnf.el --- parser for EBNF 1 ;;; ebnf-bnf.el --- parser for EBNF
2 2
3 ;; Copyright (C) 1999, 2000, 2001 Free Sofware Foundation, Inc. 3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004
4 4 ;; Free Sofware Foundation, Inc.
5 ;; Author: Vinicius Jose Latorre <vinicius@cpqd.com.br> 5
6 ;; Maintainer: Vinicius Jose Latorre <vinicius@cpqd.com.br> 6 ;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br>
7 ;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br>
8 ;; Time-stamp: <2004/04/03 16:42:18 vinicius>
7 ;; Keywords: wp, ebnf, PostScript 9 ;; Keywords: wp, ebnf, PostScript
8 ;; Time-stamp: <2003-02-10 10:29:48 jbarranquero> 10 ;; Version: 1.9
9 ;; Version: 1.7
10 11
11 ;; This file is part of GNU Emacs. 12 ;; This file is part of GNU Emacs.
12 13
13 ;; GNU Emacs is free software; you can redistribute it and/or modify 14 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by 15 ;; it under the terms of the GNU General Public License as published by
51 ;; $?C? default special 52 ;; $?C? default special
52 ;; A = B. production (A is the header and B the body) 53 ;; A = B. production (A is the header and B the body)
53 ;; C D sequence (C occurs before D) 54 ;; C D sequence (C occurs before D)
54 ;; C | D alternative (C or D occurs) 55 ;; C | D alternative (C or D occurs)
55 ;; A - B exception (A excluding B, B without any non-terminal) 56 ;; A - B exception (A excluding B, B without any non-terminal)
56 ;; n * A repetition (A repeats n (integer) times) 57 ;; n * A repetition (A repeats at least n (integer) times)
58 ;; n * n A repetition (A repeats exactly n (integer) times)
59 ;; n * m A repetition (A repeats at least n (integer) and at most
60 ;; m (integer) times)
57 ;; (C) group (expression C is grouped together) 61 ;; (C) group (expression C is grouped together)
58 ;; [C] optional (C may or not occurs) 62 ;; [C] optional (C may or not occurs)
59 ;; C+ one or more occurrences of C 63 ;; C+ one or more occurrences of C
60 ;; {C}+ one or more occurrences of C 64 ;; {C}+ one or more occurrences of C
61 ;; {C}* zero or more occurrences of C 65 ;; {C}* zero or more occurrences of C
75 ;; 79 ;;
76 ;; sequence = {exception}*. ;; sequence 80 ;; sequence = {exception}*. ;; sequence
77 ;; 81 ;;
78 ;; exception = repeat [ "-" repeat]. ;; exception 82 ;; exception = repeat [ "-" repeat]. ;; exception
79 ;; 83 ;;
80 ;; repeat = [ integer "*" ] term. ;; repetition 84 ;; repeat = [ integer "*" [ integer ]] term. ;; repetition
81 ;; 85 ;;
82 ;; term = factor 86 ;; term = factor
83 ;; | [factor] "+" ;; one-or-more 87 ;; | [factor] "+" ;; one-or-more
84 ;; | [factor] "/" [factor] ;; one-or-more 88 ;; | [factor] "/" [factor] ;; one-or-more
85 ;; . 89 ;; .
93 ;; | "{" body [ "||" body ] "}*" ;; zero-or-more 97 ;; | "{" body [ "||" body ] "}*" ;; zero-or-more
94 ;; | "{" body [ "||" body ] "}" ;; zero-or-more 98 ;; | "{" body [ "||" body ] "}" ;; zero-or-more
95 ;; . 99 ;; .
96 ;; 100 ;;
97 ;; non_terminal = "[!#%&'*-,0-:<>@-Z\\\\^-z~\\240-\\377]+". 101 ;; non_terminal = "[!#%&'*-,0-:<>@-Z\\\\^-z~\\240-\\377]+".
102 ;; ;; that is, a valid non_terminal accepts decimal digits, letters (upper
103 ;; ;; and lower), 8-bit accentuated characters,
104 ;; ;; "!", "#", "%", "&", "'", "*", "+", ",", ":",
105 ;; ;; "<", ">", "@", "\", "^", "_", "`" and "~".
98 ;; 106 ;;
99 ;; terminal = "\\([^\"\\]\\|\\\\[ -~\\240-\\377]\\)+". 107 ;; terminal = "\\([^\"\\]\\|\\\\[ -~\\240-\\377]\\)+".
100 ;; 108 ;; ;; that is, a valid terminal accepts any printable character (including
101 ;; special = "[^?\\n\\000-\\010\\016-\\037\\177-\\237]*". 109 ;; ;; 8-bit accentuated characters) except `"', as `"' is used to delimit a
110 ;; ;; terminal. Also, accepts escaped characters, that is, a character
111 ;; ;; pair starting with `\' followed by a printable character, for
112 ;; ;; example: \", \\.
113 ;;
114 ;; special = "[^?\\000-\\010\\012-\\037\\177-\\237]*".
115 ;; ;; that is, a valid special accepts any printable character (including
116 ;; ;; 8-bit accentuated characters) and tabs except `?', as `?' is used to
117 ;; ;; delimit a special.
102 ;; 118 ;;
103 ;; integer = "[0-9]+". 119 ;; integer = "[0-9]+".
120 ;; ;; that is, an integer is a sequence of one or more decimal digits.
104 ;; 121 ;;
105 ;; comment = ";" "[^\\n\\000-\\010\\016-\\037\\177-\\237]*" "\\n". 122 ;; comment = ";" "[^\\n\\000-\\010\\016-\\037\\177-\\237]*" "\\n".
123 ;; ;; that is, a comment starts with the character `;' and terminates at end
124 ;; ;; of line. Also, it only accepts printable characters (including 8-bit
125 ;; ;; accentuated characters) and tabs.
106 ;; 126 ;;
107 ;; 127 ;;
108 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 128 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
109 129
110 ;;; Code: 130 ;;; Code:
184 (while (setq term (ebnf-exception token) 204 (while (setq term (ebnf-exception token)
185 token (car term) 205 token (car term)
186 term (cdr term)) 206 term (cdr term))
187 (setq seq (cons term seq))) 207 (setq seq (cons term seq)))
188 (cons token 208 (cons token
189 (cond 209 (ebnf-token-sequence seq))))
190 ;; null sequence
191 ((null seq)
192 (ebnf-make-empty))
193 ;; sequence with only one element
194 ((= (length seq) 1)
195 (car seq))
196 ;; a real sequence
197 (t
198 (ebnf-make-sequence (nreverse seq)))
199 ))))
200 210
201 211
202 ;;; exception = repeat [ "-" repeat]. 212 ;;; exception = repeat [ "-" repeat].
203 213
204 (defun ebnf-exception (token) 214 (defun ebnf-exception (token)
231 (ebnf-no-non-terminal (car seq)) 241 (ebnf-no-non-terminal (car seq))
232 (setq seq (cdr seq))))) 242 (setq seq (cdr seq)))))
233 )))) 243 ))))
234 244
235 245
236 ;;; repeat = [ integer "*" ] term. 246 ;;; repeat = [ integer "*" [ integer ]] term.
237 247
238 (defun ebnf-repeat (token) 248 (defun ebnf-repeat (token)
239 (if (not (eq token 'integer)) 249 (if (not (eq token 'integer))
240 (ebnf-term token) 250 (ebnf-term token)
241 (let ((times ebnf-bnf-lex)) 251 (let ((times ebnf-bnf-lex)
252 upper)
242 (or (eq (ebnf-bnf-lex) 'repeat) 253 (or (eq (ebnf-bnf-lex) 'repeat)
243 (error "Missing `*'")) 254 (error "Missing `*'"))
244 (ebnf-token-repeat times (ebnf-term (ebnf-bnf-lex)))))) 255 (setq token (ebnf-bnf-lex))
256 (when (eq token 'integer)
257 (setq upper ebnf-bnf-lex
258 token (ebnf-bnf-lex)))
259 (ebnf-token-repeat times (ebnf-term token) upper))))
245 260
246 261
247 ;;; term = factor 262 ;;; term = factor
248 ;;; | [factor] "+" ;; one-or-more 263 ;;; | [factor] "+" ;; one-or-more
249 ;;; | [factor] "/" [factor] ;; one-or-more 264 ;;; | [factor] "/" [factor] ;; one-or-more
460 ((eq token 'integer) 475 ((eq token 'integer)
461 (setq ebnf-bnf-lex (ebnf-buffer-substring "0-9")) 476 (setq ebnf-bnf-lex (ebnf-buffer-substring "0-9"))
462 'integer) 477 'integer)
463 ;; special: ?special? 478 ;; special: ?special?
464 ((eq token 'special) 479 ((eq token 'special)
465 (setq ebnf-bnf-lex (concat "?" 480 (setq ebnf-bnf-lex (concat (and ebnf-special-show-delimiter "?")
466 (ebnf-string " ->@-~" ?\? "special") 481 (ebnf-string " ->@-~" ?\? "special")
467 "?")) 482 (and ebnf-special-show-delimiter "?")))
468 'special) 483 'special)
469 ;; terminal: "string" 484 ;; terminal: "string"
470 ((eq token 'terminal) 485 ((eq token 'terminal)
471 (setq ebnf-bnf-lex (ebnf-unescape-string (ebnf-get-string))) 486 (setq ebnf-bnf-lex (ebnf-unescape-string (ebnf-get-string)))
472 'terminal) 487 'terminal)
584 599
585 600
586 (provide 'ebnf-bnf) 601 (provide 'ebnf-bnf)
587 602
588 603
604 ;;; arch-tag: 3b1834d3-8367-475b-80d5-8e0bbd00ce50
589 ;;; ebnf-bnf.el ends here 605 ;;; ebnf-bnf.el ends here