annotate lisp/progmodes/ebnf-bnf.el @ 108635:e565448628b8

Set rallocobj with configure, not cpp. * configure.in (REL_ALLOC): Unset on gnu, gnu-linux if DOUG_LEA_MALLOC. (RALLOC_OBJ): New output variable. * config.bat (RALLOC_OBJ): Edit to empty if sys_malloc. * src/Makefile.in (RALLOC_OBJ): New, set by configure. (rallocobj): Replace with the previous variable. (otherobj): Use $RALLOC_OBJ. * src/s/gnu.h (REL_ALLOC) [DOUG_LEA_MALLOC]: * src/s/gnu-linux.h (REL_ALLOC) [DOUG_LEA_MALLOC]: Move undef to configure. * msdos/sed1v2.inp (RALLOC_OBJ): Edit to ralloc.o.
author Glenn Morris <rgm@gnu.org>
date Mon, 17 May 2010 19:44:07 -0700
parents 1d1d5d9bd884
children 280c8ae2476d 376148b31b5e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 34804
diff changeset
1 ;;; ebnf-bnf.el --- parser for EBNF
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
75347
e3694f1cb928 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 74417
diff changeset
4 ;; Free Software Foundation, Inc.
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
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>
39343
aa2d472f6aa7 Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents: 38436
diff changeset
8 ;; Keywords: wp, ebnf, PostScript
82143
81c81019e0c6 New: Header/Footer comment & Log messages
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 78234
diff changeset
9 ;; Version: 1.10
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10
27539
9299c470e566 Update copyright.
Gerd Moellmann <gerd@gnu.org>
parents: 27451
diff changeset
11 ;; This file is part of GNU Emacs.
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12
94673
52b7a8c22af5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
94673
52b7a8c22af5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
15 ;; the Free Software Foundation, either version 3 of the License, or
52b7a8c22af5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
16 ;; (at your option) any later version.
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17
27539
9299c470e566 Update copyright.
Gerd Moellmann <gerd@gnu.org>
parents: 27451
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
94673
52b7a8c22af5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 ;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 ;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 ;; This is part of ebnf2ps package.
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 ;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 ;; This package defines a parser for EBNF.
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 ;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 ;; See ebnf2ps.el for documentation.
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 ;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 ;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38 ;; EBNF Syntax
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 ;; -----------
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 ;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 ;; The current EBNF that ebnf2ps accepts has the following constructions:
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 ;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 ;; ; comment (until end of line)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 ;; A non-terminal
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 ;; "C" terminal
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 ;; ?C? special
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 ;; $A default non-terminal
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 ;; $"C" default terminal
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 ;; $?C? default special
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 ;; A = B. production (A is the header and B the body)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 ;; C D sequence (C occurs before D)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 ;; C | D alternative (C or D occurs)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 ;; A - B exception (A excluding B, B without any non-terminal)
54192
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
54 ;; n * A repetition (A repeats at least n (integer) times)
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
55 ;; n * n A repetition (A repeats exactly n (integer) times)
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
56 ;; n * m A repetition (A repeats at least n (integer) and at most
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
57 ;; m (integer) times)
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 ;; (C) group (expression C is grouped together)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 ;; [C] optional (C may or not occurs)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 ;; C+ one or more occurrences of C
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 ;; {C}+ one or more occurrences of C
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 ;; {C}* zero or more occurrences of C
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 ;; {C} zero or more occurrences of C
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 ;; C / D equivalent to: C {D C}*
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 ;; {C || D}+ equivalent to: C {D C}*
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 ;; {C || D}* equivalent to: [C {D C}*]
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 ;; {C || D} equivalent to: [C {D C}*]
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 ;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 ;; The EBNF syntax written using the notation above is:
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 ;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 ;; EBNF = {production}+.
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 ;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 ;; production = non_terminal "=" body ".". ;; production
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 ;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 ;; body = {sequence || "|"}*. ;; alternative
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 ;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 ;; sequence = {exception}*. ;; sequence
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 ;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 ;; exception = repeat [ "-" repeat]. ;; exception
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 ;;
54192
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
81 ;; repeat = [ integer "*" [ integer ]] term. ;; repetition
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 ;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 ;; term = factor
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 ;; | [factor] "+" ;; one-or-more
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 ;; | [factor] "/" [factor] ;; one-or-more
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 ;; .
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 ;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 ;; factor = [ "$" ] "\"" terminal "\"" ;; terminal
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 ;; | [ "$" ] non_terminal ;; non-terminal
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 ;; | [ "$" ] "?" special "?" ;; special
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91 ;; | "(" body ")" ;; group
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 ;; | "[" body "]" ;; zero-or-one
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 ;; | "{" body [ "||" body ] "}+" ;; one-or-more
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 ;; | "{" body [ "||" body ] "}*" ;; zero-or-more
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 ;; | "{" body [ "||" body ] "}" ;; zero-or-more
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96 ;; .
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 ;;
39343
aa2d472f6aa7 Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents: 38436
diff changeset
98 ;; non_terminal = "[!#%&'*-,0-:<>@-Z\\\\^-z~\\240-\\377]+".
54192
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
99 ;; ;; that is, a valid non_terminal accepts decimal digits, letters (upper
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
100 ;; ;; and lower), 8-bit accentuated characters,
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
101 ;; ;; "!", "#", "%", "&", "'", "*", "+", ",", ":",
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
102 ;; ;; "<", ">", "@", "\", "^", "_", "`" and "~".
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 ;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 ;; terminal = "\\([^\"\\]\\|\\\\[ -~\\240-\\377]\\)+".
54192
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
105 ;; ;; that is, a valid terminal accepts any printable character (including
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
106 ;; ;; 8-bit accentuated characters) except `"', as `"' is used to delimit a
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
107 ;; ;; terminal. Also, accepts escaped characters, that is, a character
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
108 ;; ;; pair starting with `\' followed by a printable character, for
63629
b42bf212f030 (ebnf-bnf-lex): Fix spellings.
Juanma Barranquero <lekktu@gmail.com>
parents: 60917
diff changeset
109 ;; ;; example: \", \\.
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 ;;
54192
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
111 ;; special = "[^?\\000-\\010\\012-\\037\\177-\\237]*".
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
112 ;; ;; that is, a valid special accepts any printable character (including
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
113 ;; ;; 8-bit accentuated characters) and tabs except `?', as `?' is used to
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
114 ;; ;; delimit a special.
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 ;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116 ;; integer = "[0-9]+".
54192
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
117 ;; ;; that is, an integer is a sequence of one or more decimal digits.
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 ;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 ;; comment = ";" "[^\\n\\000-\\010\\016-\\037\\177-\\237]*" "\\n".
54192
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
120 ;; ;; that is, a comment starts with the character `;' and terminates at end
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
121 ;; ;; of line. Also, it only accepts printable characters (including 8-bit
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
122 ;; ;; accentuated characters) and tabs.
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123 ;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124 ;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 34804
diff changeset
127 ;;; Code:
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130 (require 'ebnf-otz)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 (defvar ebnf-bnf-lex nil
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 "Value returned by `ebnf-bnf-lex' function.")
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
49670
cc820064216c Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 39422
diff changeset
138 ;; Syntactic analyzer
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 ;;; EBNF = {production}+.
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 (defun ebnf-bnf-parser (start)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 "EBNF parser."
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 (let ((total (+ (- ebnf-limit start) 1))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 (bias (1- start))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 (origin (point))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 prod-list token rule)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 (goto-char start)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 (setq token (ebnf-bnf-lex))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 (and (eq token 'end-of-input)
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 34804
diff changeset
152 (error "Invalid EBNF file format"))
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 (while (not (eq token 'end-of-input))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 (ebnf-message-float
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 "Parsing...%s%%"
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 (/ (* (- (point) bias) 100.0) total))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 (setq token (ebnf-production token)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158 rule (cdr token)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 token (car token))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160 (or (ebnf-add-empty-rule-list rule)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161 (setq prod-list (cons rule prod-list))))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162 (goto-char origin)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163 prod-list))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 ;;; production = non-terminal "=" body ".".
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168 (defun ebnf-production (token)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169 (let ((header ebnf-bnf-lex)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170 (action ebnf-action)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 body)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 (setq ebnf-action nil)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 (or (eq token 'non-terminal)
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 34804
diff changeset
174 (error "Invalid header production"))
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 (or (eq (ebnf-bnf-lex) 'equal)
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 34804
diff changeset
176 (error "Invalid production: missing `='"))
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 (setq body (ebnf-body))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178 (or (eq (car body) 'period)
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 34804
diff changeset
179 (error "Invalid production: missing `.'"))
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
180 (setq body (cdr body))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181 (ebnf-eps-add-production header)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182 (cons (ebnf-bnf-lex)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183 (ebnf-make-production header body action))))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186 ;;; body = {sequence || "|"}*.
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188 (defun ebnf-body ()
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 (let (body sequence)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 (while (eq (car (setq sequence (ebnf-sequence))) 'alternative)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 (setq sequence (cdr sequence)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 body (cons sequence body)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 (ebnf-token-alternative body sequence)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196 ;;; sequence = {exception}*.
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198 (defun ebnf-sequence ()
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 (let ((token (ebnf-bnf-lex))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200 seq term)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201 (while (setq term (ebnf-exception token)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 token (car term)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203 term (cdr term))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 (setq seq (cons term seq)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205 (cons token
54714
fc6e53c00fcf ebnf2ps 4.2
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54192
diff changeset
206 (ebnf-token-sequence seq))))
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 ;;; exception = repeat [ "-" repeat].
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 (defun ebnf-exception (token)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 (let ((term (ebnf-repeat token)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 (if (not (eq (car term) 'except))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 ;; repeat
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215 term
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
216 ;; repeat - repeat
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217 (let ((exception (ebnf-repeat (ebnf-bnf-lex))))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218 (ebnf-no-non-terminal (cdr exception))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 (ebnf-token-except (cdr term) exception)))))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
221
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222 (defun ebnf-no-non-terminal (node)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223 (and (vectorp node)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224 (let ((kind (ebnf-node-kind node)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
225 (cond
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226 ((eq kind 'ebnf-generate-non-terminal)
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 34804
diff changeset
227 (error "Exception sequence should not contain a non-terminal"))
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228 ((eq kind 'ebnf-generate-repeat)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229 (ebnf-no-non-terminal (ebnf-node-separator node)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230 ((memq kind '(ebnf-generate-optional ebnf-generate-except))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231 (ebnf-no-non-terminal (ebnf-node-list node)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232 ((memq kind '(ebnf-generate-one-or-more ebnf-generate-zero-or-more))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233 (ebnf-no-non-terminal (ebnf-node-list node))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234 (ebnf-no-non-terminal (ebnf-node-separator node)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235 ((memq kind '(ebnf-generate-alternative ebnf-generate-sequence))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
236 (let ((seq (ebnf-node-list node)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
237 (while seq
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
238 (ebnf-no-non-terminal (car seq))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
239 (setq seq (cdr seq)))))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240 ))))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
241
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
242
54192
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
243 ;;; repeat = [ integer "*" [ integer ]] term.
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
244
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
245 (defun ebnf-repeat (token)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
246 (if (not (eq token 'integer))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
247 (ebnf-term token)
54192
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
248 (let ((times ebnf-bnf-lex)
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
249 upper)
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
250 (or (eq (ebnf-bnf-lex) 'repeat)
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 34804
diff changeset
251 (error "Missing `*'"))
54192
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
252 (setq token (ebnf-bnf-lex))
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
253 (when (eq token 'integer)
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
254 (setq upper ebnf-bnf-lex
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
255 token (ebnf-bnf-lex)))
20bee085cbee Doc fix.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 54140
diff changeset
256 (ebnf-token-repeat times (ebnf-term token) upper))))
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
257
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
258
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
259 ;;; term = factor
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
260 ;;; | [factor] "+" ;; one-or-more
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
261 ;;; | [factor] "/" [factor] ;; one-or-more
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
262 ;;; .
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
264 (defun ebnf-term (token)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
265 (let ((factor (ebnf-factor token)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
266 (and factor
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
267 (setq token (ebnf-bnf-lex)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
268 (cond
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
269 ;; [factor] +
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 ((eq token 'one-or-more)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
271 (cons (ebnf-bnf-lex)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
272 (and factor
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
273 (let ((kind (ebnf-node-kind factor)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
274 (cond
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
275 ;; { A }+ + ==> { A }+
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
276 ;; { A }* + ==> { A }*
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
277 ((memq kind '(ebnf-generate-zero-or-more
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
278 ebnf-generate-one-or-more))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
279 factor)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
280 ;; [ A ] + ==> { A }*
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
281 ((eq kind 'ebnf-generate-optional)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
282 (ebnf-make-zero-or-more (list factor)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
283 ;; A +
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
284 (t
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285 (ebnf-make-one-or-more (list factor)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
286 )))))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
287 ;; [factor] / [factor]
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
288 ((eq token 'list)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
289 (setq token (ebnf-bnf-lex))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
290 (let ((sep (ebnf-factor token)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
291 (and sep
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
292 (setq factor (or factor (ebnf-make-empty))))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
293 (cons (if sep
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
294 (ebnf-bnf-lex)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
295 token)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
296 (and factor
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
297 (ebnf-make-one-or-more factor sep)))))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
298 ;; factor
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
299 (t
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
300 (cons token factor))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
301 )))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
302
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
303
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
304 ;;; factor = [ "$" ] "\"" terminal "\"" ;; terminal
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
305 ;;; | [ "$" ] non_terminal ;; non-terminal
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
306 ;;; | [ "$" ] "?" special "?" ;; special
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
307 ;;; | "(" body ")" ;; group
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
308 ;;; | "[" body "]" ;; zero-or-one
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
309 ;;; | "{" body [ "||" body ] "}+" ;; one-or-more
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310 ;;; | "{" body [ "||" body ] "}*" ;; zero-or-more
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
311 ;;; | "{" body [ "||" body ] "}" ;; zero-or-more
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
312 ;;; .
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
313
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
314 (defun ebnf-factor (token)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
315 (cond
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
316 ;; terminal
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
317 ((eq token 'terminal)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
318 (ebnf-make-terminal ebnf-bnf-lex))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
319 ;; non-terminal
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
320 ((eq token 'non-terminal)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
321 (ebnf-make-non-terminal ebnf-bnf-lex))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
322 ;; special
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
323 ((eq token 'special)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
324 (ebnf-make-special ebnf-bnf-lex))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
325 ;; group
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
326 ((eq token 'begin-group)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
327 (let ((body (ebnf-body)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
328 (or (eq (car body) 'end-group)
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 34804
diff changeset
329 (error "Missing `)'"))
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
330 (cdr body)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331 ;; optional
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
332 ((eq token 'begin-optional)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
333 (let ((body (ebnf-body)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
334 (or (eq (car body) 'end-optional)
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 34804
diff changeset
335 (error "Missing `]'"))
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
336 (ebnf-token-optional (cdr body))))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
337 ;; list
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
338 ((eq token 'begin-list)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
339 (let* ((body (ebnf-body))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
340 (token (car body))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
341 (list-part (cdr body))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
342 sep-part)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
343 (and (eq token 'list-separator)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
344 ;; { A || B }
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
345 (setq body (ebnf-body) ; get separator
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
346 token (car body)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
347 sep-part (cdr body)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
348 (cond
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
349 ;; { A }+
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
350 ((eq token 'end-one-or-more)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
351 (ebnf-make-one-or-more list-part sep-part))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
352 ;; { A }*
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
353 ((eq token 'end-zero-or-more)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
354 (ebnf-make-zero-or-more list-part sep-part))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
355 (t
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 34804
diff changeset
356 (error "Missing `}+', `}*' or `}'"))
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
357 )))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
358 ;; no term
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
359 (t
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
360 nil)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
361 ))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
362
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
363
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
364 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
365 ;; Lexical analyzer
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
366
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
367
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
368 (defconst ebnf-bnf-token-table (make-vector 256 'error)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
369 "Vector used to map characters to a lexical token.")
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
370
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
371
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
372 (defun ebnf-bnf-initialize ()
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
373 "Initialize EBNF token table."
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
374 ;; control character & control 8-bit character are set to `error'
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
375 (let ((char ?\040))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
376 ;; printable character:
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
377 (while (< char ?\060)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
378 (aset ebnf-bnf-token-table char 'non-terminal)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
379 (setq char (1+ char)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
380 ;; digits:
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
381 (while (< char ?\072)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
382 (aset ebnf-bnf-token-table char 'integer)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
383 (setq char (1+ char)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
384 ;; printable character:
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
385 (while (< char ?\177)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
386 (aset ebnf-bnf-token-table char 'non-terminal)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
387 (setq char (1+ char)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
388 ;; European 8-bit accentuated characters:
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
389 (setq char ?\240)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
390 (while (< char ?\400)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
391 (aset ebnf-bnf-token-table char 'non-terminal)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
392 (setq char (1+ char)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
393 ;; Override space characters:
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
394 (aset ebnf-bnf-token-table ?\013 'space) ; [VT] vertical tab
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
395 (aset ebnf-bnf-token-table ?\n 'space) ; [NL] linefeed
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
396 (aset ebnf-bnf-token-table ?\r 'space) ; [CR] carriage return
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
397 (aset ebnf-bnf-token-table ?\t 'space) ; [HT] horizontal tab
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
398 (aset ebnf-bnf-token-table ?\ 'space) ; [SP] space
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
399 ;; Override form feed character:
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
400 (aset ebnf-bnf-token-table ?\f 'form-feed) ; [FF] form feed
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
401 ;; Override other lexical characters:
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
402 (aset ebnf-bnf-token-table ?\" 'terminal)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
403 (aset ebnf-bnf-token-table ?\? 'special)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
404 (aset ebnf-bnf-token-table ?\( 'begin-group)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
405 (aset ebnf-bnf-token-table ?\) 'end-group)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
406 (aset ebnf-bnf-token-table ?* 'repeat)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
407 (aset ebnf-bnf-token-table ?- 'except)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
408 (aset ebnf-bnf-token-table ?= 'equal)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
409 (aset ebnf-bnf-token-table ?\[ 'begin-optional)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
410 (aset ebnf-bnf-token-table ?\] 'end-optional)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
411 (aset ebnf-bnf-token-table ?\{ 'begin-list)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
412 (aset ebnf-bnf-token-table ?| 'alternative)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
413 (aset ebnf-bnf-token-table ?\} 'end-list)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
414 (aset ebnf-bnf-token-table ?/ 'list)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
415 (aset ebnf-bnf-token-table ?+ 'one-or-more)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
416 (aset ebnf-bnf-token-table ?$ 'default)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
417 ;; Override comment character:
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418 (aset ebnf-bnf-token-table ebnf-lex-comment-char 'comment)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
419 ;; Override end of production character:
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
420 (aset ebnf-bnf-token-table ebnf-lex-eop-char 'period)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
421
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
422
39422
3e68652d365d Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents: 39343
diff changeset
423 ;; replace the range "\240-\377" (see `ebnf-range-regexp').
3e68652d365d Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents: 39343
diff changeset
424 (defconst ebnf-bnf-non-terminal-chars
3e68652d365d Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents: 39343
diff changeset
425 (ebnf-range-regexp "!#%&'*-,0-:<>@-Z\\\\^-z~" ?\240 ?\377))
3e68652d365d Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents: 39343
diff changeset
426
3e68652d365d Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents: 39343
diff changeset
427
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
428 (defun ebnf-bnf-lex ()
63629
b42bf212f030 (ebnf-bnf-lex): Fix spellings.
Juanma Barranquero <lekktu@gmail.com>
parents: 60917
diff changeset
429 "Lexical analyzer for EBNF.
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
430
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
431 Return a lexical token.
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
432
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
433 See documentation for variable `ebnf-bnf-lex'."
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
434 (if (>= (point) ebnf-limit)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
435 'end-of-input
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
436 (let (token)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
437 ;; skip spaces and comments
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
438 (while (if (> (following-char) 255)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
439 (progn
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
440 (setq token 'error)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
441 nil)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
442 (setq token (aref ebnf-bnf-token-table (following-char)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
443 (cond
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
444 ((eq token 'space)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
445 (skip-chars-forward " \013\n\r\t" ebnf-limit)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
446 (< (point) ebnf-limit))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
447 ((eq token 'comment)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
448 (ebnf-bnf-skip-comment))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
449 ((eq token 'form-feed)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
450 (forward-char)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
451 (setq ebnf-action 'form-feed))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
452 (t nil)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
453 )))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
454 (setq ebnf-default-p nil)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
455 (cond
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
456 ;; end of input
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
457 ((>= (point) ebnf-limit)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
458 'end-of-input)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
459 ;; error
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
460 ((eq token 'error)
60917
87f9bb9d3718 * progmodes/ebnf-abn.el, progmodes/ebnf-bnf.el,
Werner LEMBERG <wl@gnu.org>
parents: 54714
diff changeset
461 (error "Invalid character"))
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
462 ;; default
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
463 ((eq token 'default)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
464 (forward-char)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
465 (if (memq (aref ebnf-bnf-token-table (following-char))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
466 '(terminal non-terminal special))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
467 (prog1
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
468 (ebnf-bnf-lex)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
469 (setq ebnf-default-p t))
60917
87f9bb9d3718 * progmodes/ebnf-abn.el, progmodes/ebnf-bnf.el,
Werner LEMBERG <wl@gnu.org>
parents: 54714
diff changeset
470 (error "Invalid `default' element")))
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
471 ;; integer
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
472 ((eq token 'integer)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
473 (setq ebnf-bnf-lex (ebnf-buffer-substring "0-9"))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
474 'integer)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
475 ;; special: ?special?
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
476 ((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
477 (setq ebnf-bnf-lex (concat (and ebnf-special-show-delimiter "?")
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
478 (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
479 (and ebnf-special-show-delimiter "?")))
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
480 'special)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
481 ;; terminal: "string"
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
482 ((eq token 'terminal)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
483 (setq ebnf-bnf-lex (ebnf-unescape-string (ebnf-get-string)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
484 'terminal)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
485 ;; non-terminal or terminal
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
486 ((eq token 'non-terminal)
39422
3e68652d365d Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents: 39343
diff changeset
487 (setq ebnf-bnf-lex (ebnf-buffer-substring ebnf-bnf-non-terminal-chars))
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
488 (let ((case-fold-search ebnf-case-fold-search)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
489 match)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
490 (if (and ebnf-terminal-regexp
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
491 (setq match (string-match ebnf-terminal-regexp
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
492 ebnf-bnf-lex))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
493 (zerop match)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
494 (= (match-end 0) (length ebnf-bnf-lex)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
495 'terminal
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
496 'non-terminal)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
497 ;; end of list: }+, }*, }
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
498 ((eq token 'end-list)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
499 (forward-char)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
500 (cond
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
501 ((= (following-char) ?+)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
502 (forward-char)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
503 'end-one-or-more)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
504 ((= (following-char) ?*)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
505 (forward-char)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
506 'end-zero-or-more)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
507 (t
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
508 'end-zero-or-more)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
509 ))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
510 ;; alternative: |, ||
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
511 ((eq token 'alternative)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
512 (forward-char)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
513 (if (/= (following-char) ?|)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
514 'alternative
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
515 (forward-char)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
516 'list-separator))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
517 ;; miscellaneous: {, (, ), [, ], ., =, /, +, -, *
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
518 (t
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
519 (forward-char)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
520 token)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
521 ))))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
522
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
523
34804
3347fac37b3d Fix the same problem as described on ebnf2ps.el log
Gerd Moellmann <gerd@gnu.org>
parents: 27539
diff changeset
524 ;; replace the range "\177-\237" (see `ebnf-range-regexp').
3347fac37b3d Fix the same problem as described on ebnf2ps.el log
Gerd Moellmann <gerd@gnu.org>
parents: 27539
diff changeset
525 (defconst ebnf-bnf-comment-chars
3347fac37b3d Fix the same problem as described on ebnf2ps.el log
Gerd Moellmann <gerd@gnu.org>
parents: 27539
diff changeset
526 (ebnf-range-regexp "^\n\000-\010\016-\037" ?\177 ?\237))
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
527
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
528
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
529 (defun ebnf-bnf-skip-comment ()
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
530 (forward-char)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
531 (cond
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
532 ;; open EPS file
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
533 ((and ebnf-eps-executing (= (following-char) ?\[))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
534 (ebnf-eps-add-context (ebnf-bnf-eps-filename)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
535 ;; close EPS file
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
536 ((and ebnf-eps-executing (= (following-char) ?\]))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
537 (ebnf-eps-remove-context (ebnf-bnf-eps-filename)))
82143
81c81019e0c6 New: Header/Footer comment & Log messages
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 78234
diff changeset
538 ;; EPS header
81c81019e0c6 New: Header/Footer comment & Log messages
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 78234
diff changeset
539 ((and ebnf-eps-executing (= (following-char) ?H))
81c81019e0c6 New: Header/Footer comment & Log messages
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 78234
diff changeset
540 (ebnf-eps-header-comment (ebnf-bnf-eps-filename)))
81c81019e0c6 New: Header/Footer comment & Log messages
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 78234
diff changeset
541 ;; EPS footer
81c81019e0c6 New: Header/Footer comment & Log messages
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 78234
diff changeset
542 ((and ebnf-eps-executing (= (following-char) ?F))
81c81019e0c6 New: Header/Footer comment & Log messages
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents: 78234
diff changeset
543 (ebnf-eps-footer-comment (ebnf-bnf-eps-filename)))
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
544 ;; any other action in comment
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
545 (t
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
546 (setq ebnf-action (aref ebnf-comment-table (following-char)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
547 (skip-chars-forward ebnf-bnf-comment-chars ebnf-limit))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
548 )
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
549 ;; check for a valid end of comment
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
550 (cond ((>= (point) ebnf-limit)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
551 nil)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
552 ((= (following-char) ?\n)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
553 (forward-char)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
554 t)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
555 (t
60917
87f9bb9d3718 * progmodes/ebnf-abn.el, progmodes/ebnf-bnf.el,
Werner LEMBERG <wl@gnu.org>
parents: 54714
diff changeset
556 (error "Invalid character"))
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
557 ))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
558
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
559
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
560 (defun ebnf-bnf-eps-filename ()
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
561 (forward-char)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
562 (ebnf-buffer-substring ebnf-bnf-comment-chars))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
563
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
564
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
565 (defun ebnf-unescape-string (str)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
566 (let* ((len (length str))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
567 (size (1- len))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
568 (istr 0)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
569 (n-esc 0))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
570 ;; count number of escapes
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
571 (while (< istr size)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
572 (setq istr (+ istr
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
573 (if (= (aref str istr) ?\\)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
574 (progn
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
575 (setq n-esc (1+ n-esc))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
576 2)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
577 1))))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
578 (if (zerop n-esc)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
579 ;; no escapes
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
580 str
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
581 ;; at least one escape
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
582 (let ((new (make-string (- len n-esc) ?\ ))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
583 (inew 0))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
584 ;; eliminate all escapes
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
585 (setq istr 0)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
586 (while (> n-esc 0)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
587 (and (= (aref str istr) ?\\)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
588 (setq istr (1+ istr)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
589 n-esc (1- n-esc)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
590 (aset new inew (aref str istr))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
591 (setq inew (1+ inew)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
592 istr (1+ istr)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
593 ;; remaining string has no escape
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
594 (while (< istr len)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
595 (aset new inew (aref str istr))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
596 (setq inew (1+ inew)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
597 istr (1+ istr)))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
598 new))))
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
599
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
600
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
601 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
602
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
603
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
604 (provide 'ebnf-bnf)
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
605
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
606
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
607 ;; arch-tag: 3b1834d3-8367-475b-80d5-8e0bbd00ce50
27451
f062cc830f07 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
608 ;;; ebnf-bnf.el ends here