Mercurial > emacs
annotate lisp/progmodes/ebnf-yac.el @ 83076:5eaa708b8d47
README updates.
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-116
author | Karoly Lorentey <lorentey@elte.hu> |
---|---|
date | Thu, 11 Mar 2004 01:55:50 +0000 |
parents | 7d439240423b |
children | fc6e53c00fcf |
rev | line source |
---|---|
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34807
diff
changeset
|
1 ;;; ebnf-yac.el --- parser for Yacc/Bison |
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 Sofware 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 20:23:29 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.2.1 |
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 Yacc/Bison. | |
37 ;; | |
38 ;; See ebnf2ps.el for documentation. | |
39 ;; | |
40 ;; | |
41 ;; Yacc/Bison Syntax | |
42 ;; ----------------- | |
43 ;; | |
44 ;; YACC = { YACC-Definitions }* "%%" { YACC-Rule }* [ "%%" [ YACC-Code ] ]. | |
45 ;; | |
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
|
46 ;; YACC-Definitions = ( "%token" | "%left" | "%right" | "%nonassoc" ) |
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
|
47 ;; [ "<" Name ">" ] Name-List |
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
|
48 ;; | "%prec" Name |
27451 | 49 ;; | "any other Yacc definition" |
50 ;; . | |
51 ;; | |
52 ;; YACC-Code = "any C definition". | |
53 ;; | |
54 ;; YACC-Rule = Name ":" Alternative ";". | |
55 ;; | |
56 ;; Alternative = { Sequence || "|" }*. | |
57 ;; | |
58 ;; Sequence = { Factor }*. | |
59 ;; | |
60 ;; Factor = Name | |
61 ;; | "'" "character" "'" | |
62 ;; | "error" | |
63 ;; | "{" "C like commands" "}" | |
64 ;; . | |
65 ;; | |
66 ;; Name-List = { Name || "," }*. | |
67 ;; | |
68 ;; Name = "[A-Za-z][A-Za-z0-9_.]*". | |
69 ;; | |
70 ;; Comment = "/*" "any character, but the sequence \"*/\"" "*/" | |
54208 | 71 ;; | "//" "any character, but the newline \"\\n\"" "\\n". |
27451 | 72 ;; |
73 ;; | |
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
|
74 ;; In other words, a valid Name begins with a letter (upper or lower case) |
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
|
75 ;; followed by letters, decimal digits, underscore (_) or point (.). For |
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
|
76 ;; example: this_is_a_valid.name, Another_EXAMPLE, mIxEd.CaSe. |
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
|
77 ;; |
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
|
78 ;; |
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
|
79 ;; Acknowledgements |
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
|
80 ;; ---------------- |
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
|
81 ;; |
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
|
82 ;; Thanks to Matthew K. Junker <junker@alum.mit.edu> for the suggestion to deal |
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
|
83 ;; with %right, %left and %prec pragmas. His suggestion was extended to deal |
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
|
84 ;; with %nonassoc pragma too. |
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
|
85 ;; |
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
|
86 ;; |
27451 | 87 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
88 | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34807
diff
changeset
|
89 ;;; Code: |
27451 | 90 |
91 | |
92 (require 'ebnf-otz) | |
93 | |
94 | |
95 (defvar ebnf-yac-lex nil | |
96 "Value returned by `ebnf-yac-lex' function.") | |
97 | |
98 | |
99 (defvar ebnf-yac-token-list nil | |
100 "List of `%TOKEN' names.") | |
101 | |
102 | |
103 (defvar ebnf-yac-skip-char nil | |
104 "Non-nil means skip printable characters with no grammatical meaning.") | |
105 | |
106 | |
107 (defvar ebnf-yac-error nil | |
46275
0d5f7cc6ce91
(ebnf-yac-error): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents:
39424
diff
changeset
|
108 "Non-nil means \"error\" occurred.") |
27451 | 109 |
110 | |
111 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
49670
cc820064216c
Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents:
46275
diff
changeset
|
112 ;; Syntactic analyzer |
27451 | 113 |
114 | |
115 ;;; YACC = { YACC-Definitions }* "%%" { YACC-Rule }* [ "%%" [ YACC-Code ] ]. | |
116 ;;; | |
117 ;;; YACC-Code = "any C definition". | |
118 | |
119 (defun ebnf-yac-parser (start) | |
120 "yacc/Bison parser." | |
121 (let ((total (+ (- ebnf-limit start) 1)) | |
122 (bias (1- start)) | |
123 (origin (point)) | |
124 syntax-list token rule) | |
125 (goto-char start) | |
126 (setq token (ebnf-yac-lex)) | |
127 (and (eq token 'end-of-input) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34807
diff
changeset
|
128 (error "Invalid Yacc/Bison file format")) |
27451 | 129 (or (eq (ebnf-yac-definitions token) 'yac-separator) |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34807
diff
changeset
|
130 (error "Missing `%%%%'")) |
27451 | 131 (setq token (ebnf-yac-lex)) |
132 (while (not (memq token '(end-of-input yac-separator))) | |
133 (ebnf-message-float | |
134 "Parsing...%s%%" | |
135 (/ (* (- (point) bias) 100.0) total)) | |
136 (setq token (ebnf-yac-rule token) | |
137 rule (cdr token) | |
138 token (car token)) | |
139 (or (ebnf-add-empty-rule-list rule) | |
140 (setq syntax-list (cons rule syntax-list)))) | |
141 (goto-char origin) | |
142 syntax-list)) | |
143 | |
144 | |
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
|
145 ;;; YACC-Definitions = ( "%token" | "%left" | "%right" | "%nonassoc" ) |
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
|
146 ;;; [ "<" Name ">" ] Name-List |
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
|
147 ;;; | "%prec" Name |
27451 | 148 ;;; | "any other Yacc definition" |
149 ;;; . | |
150 | |
151 (defun ebnf-yac-definitions (token) | |
152 (let ((ebnf-yac-skip-char t)) | |
153 (while (not (memq token '(yac-separator end-of-input))) | |
154 (setq token | |
155 (cond | |
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
|
156 ;; ( "%token" | "%left" | "%right" | "%nonassoc" ) |
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
|
157 ;; [ "<" Name ">" ] Name-List |
27451 | 158 ((eq token 'yac-token) |
159 (setq token (ebnf-yac-lex)) | |
160 (when (eq token 'open-angle) | |
161 (or (eq (ebnf-yac-lex) 'non-terminal) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34807
diff
changeset
|
162 (error "Missing type name")) |
27451 | 163 (or (eq (ebnf-yac-lex) 'close-angle) |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34807
diff
changeset
|
164 (error "Missing `>'")) |
27451 | 165 (setq token (ebnf-yac-lex))) |
166 (setq token (ebnf-yac-name-list token) | |
167 ebnf-yac-token-list (nconc (cdr token) | |
168 ebnf-yac-token-list)) | |
169 (car token)) | |
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
|
170 ;; "%prec" Name |
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
|
171 ((eq token 'yac-prec) |
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
|
172 (or (eq (ebnf-yac-lex) 'non-terminal) |
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
|
173 (error "Missing prec name")) |
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
|
174 (ebnf-yac-lex)) |
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
|
175 ;; "any other Yacc definition" |
27451 | 176 (t |
177 (ebnf-yac-lex)) | |
178 ))) | |
179 token)) | |
180 | |
181 | |
182 ;;; YACC-Rule = Name ":" Alternative ";". | |
183 | |
184 (defun ebnf-yac-rule (token) | |
185 (let ((header ebnf-yac-lex) | |
186 (action ebnf-action) | |
187 body) | |
188 (setq ebnf-action nil) | |
189 (or (eq token 'non-terminal) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34807
diff
changeset
|
190 (error "Invalid rule name")) |
27451 | 191 (or (eq (ebnf-yac-lex) 'colon) |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34807
diff
changeset
|
192 (error "Invalid rule: missing `:'")) |
27451 | 193 (setq body (ebnf-yac-alternative)) |
194 (or (eq (car body) 'period) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34807
diff
changeset
|
195 (error "Invalid rule: missing `;'")) |
27451 | 196 (setq body (cdr body)) |
197 (ebnf-eps-add-production header) | |
198 (cons (ebnf-yac-lex) | |
199 (ebnf-make-production header body action)))) | |
200 | |
201 | |
202 ;;; Alternative = { Sequence || "|" }*. | |
203 | |
204 (defun ebnf-yac-alternative () | |
205 (let (body sequence) | |
206 (while (eq (car (setq sequence (ebnf-yac-sequence))) | |
207 'alternative) | |
208 (and (setq sequence (cdr sequence)) | |
209 (setq body (cons sequence body)))) | |
210 (ebnf-token-alternative body sequence))) | |
211 | |
212 | |
213 ;;; Sequence = { Factor }*. | |
214 | |
215 (defun ebnf-yac-sequence () | |
216 (let (ebnf-yac-error token seq factor) | |
217 (while (setq token (ebnf-yac-lex) | |
218 factor (ebnf-yac-factor token)) | |
219 (setq seq (cons factor seq))) | |
220 (cons token | |
221 (cond | |
222 ;; ignore error recovery | |
223 ((and ebnf-yac-ignore-error-recovery ebnf-yac-error) | |
224 nil) | |
225 ;; null sequence | |
226 ((null seq) | |
227 (ebnf-make-empty)) | |
228 ;; sequence with only one element | |
229 ((= (length seq) 1) | |
230 (car seq)) | |
231 ;; a real sequence | |
232 (t | |
233 (ebnf-make-sequence (nreverse seq))) | |
234 )))) | |
235 | |
236 | |
237 ;;; Factor = Name | |
238 ;;; | "'" "character" "'" | |
239 ;;; | "error" | |
240 ;;; | "{" "C like commands" "}" | |
241 ;;; . | |
242 | |
243 (defun ebnf-yac-factor (token) | |
244 (cond | |
245 ;; 'character' | |
246 ((eq token 'terminal) | |
247 (ebnf-make-terminal ebnf-yac-lex)) | |
248 ;; Name | |
249 ((eq token 'non-terminal) | |
250 (ebnf-make-non-terminal ebnf-yac-lex)) | |
251 ;; "error" | |
252 ((eq token 'yac-error) | |
253 (ebnf-make-special ebnf-yac-lex)) | |
254 ;; not a factor | |
255 (t | |
256 nil) | |
257 )) | |
258 | |
259 | |
260 ;;; Name-List = { Name || "," }*. | |
261 | |
262 (defun ebnf-yac-name-list (token) | |
263 (let (names) | |
264 (when (eq token 'non-terminal) | |
265 (while (progn | |
266 (setq names (cons ebnf-yac-lex names) | |
267 token (ebnf-yac-lex)) | |
268 (eq token 'comma)) | |
269 (or (eq (ebnf-yac-lex) 'non-terminal) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34807
diff
changeset
|
270 (error "Missing token name")))) |
27451 | 271 (cons token names))) |
272 | |
273 | |
274 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
275 ;; Lexical analyzer | |
276 | |
277 | |
278 ;;; Name = "[A-Za-z][A-Za-z0-9_.]*". | |
279 ;;; | |
280 ;;; Comment = "/*" "any character, but the sequence \"*/\"" "*/" | |
281 ;;; | "//" "any character" "\\n". | |
282 | |
283 (defconst ebnf-yac-token-table | |
284 ;; control character & 8-bit character are set to `error' | |
285 (let ((table (make-vector 256 'error))) | |
286 ;; upper & lower case letters: | |
287 (mapcar | |
288 #'(lambda (char) | |
289 (aset table char 'non-terminal)) | |
290 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") | |
291 ;; printable characters: | |
292 (mapcar | |
293 #'(lambda (char) | |
294 (aset table char 'character)) | |
295 "!#$&()*+-.0123456789=?@[\\]^_`~") | |
296 ;; Override space characters: | |
297 (aset table ?\n 'space) ; [NL] linefeed | |
298 (aset table ?\r 'space) ; [CR] carriage return | |
299 (aset table ?\t 'space) ; [HT] horizontal tab | |
300 (aset table ?\ 'space) ; [SP] space | |
301 ;; Override form feed character: | |
302 (aset table ?\f 'form-feed) ; [FF] form feed | |
303 ;; Override other lexical characters: | |
304 (aset table ?< 'open-angle) | |
305 (aset table ?> 'close-angle) | |
306 (aset table ?, 'comma) | |
307 (aset table ?% 'yac-pragma) | |
308 (aset table ?/ 'slash) | |
309 (aset table ?\{ 'yac-code) | |
310 (aset table ?\" 'string) | |
311 (aset table ?\' 'terminal) | |
312 (aset table ?: 'colon) | |
313 (aset table ?| 'alternative) | |
314 (aset table ?\; 'period) | |
315 table) | |
316 "Vector used to map characters to a lexical token.") | |
317 | |
318 | |
319 (defun ebnf-yac-initialize () | |
320 "Initializations for Yacc/Bison parser." | |
321 (setq ebnf-yac-token-list nil)) | |
322 | |
323 | |
324 (defun ebnf-yac-lex () | |
325 "Lexical analyser for Yacc/Bison. | |
326 | |
327 Return a lexical token. | |
328 | |
329 See documentation for variable `ebnf-yac-lex'." | |
330 (if (>= (point) ebnf-limit) | |
331 'end-of-input | |
332 (let (token) | |
333 ;; skip spaces, code blocks and comments | |
334 (while (if (> (following-char) 255) | |
335 (progn | |
336 (setq token 'error) | |
337 nil) | |
338 (setq token (aref ebnf-yac-token-table (following-char))) | |
339 (cond | |
340 ((or (eq token 'space) | |
341 (and ebnf-yac-skip-char | |
342 (eq token 'character))) | |
343 (ebnf-yac-skip-spaces)) | |
344 ((eq token 'yac-code) | |
345 (ebnf-yac-skip-code)) | |
346 ((eq token 'slash) | |
347 (ebnf-yac-handle-comment)) | |
348 ((eq token 'form-feed) | |
349 (forward-char) | |
350 (setq ebnf-action 'form-feed)) | |
351 (t nil) | |
352 ))) | |
353 (cond | |
354 ;; end of input | |
355 ((>= (point) ebnf-limit) | |
356 'end-of-input) | |
357 ;; error | |
358 ((eq token 'error) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34807
diff
changeset
|
359 (error "Illegal character")) |
27451 | 360 ;; "string" |
361 ((eq token 'string) | |
362 (setq ebnf-yac-lex (ebnf-get-string)) | |
363 'string) | |
364 ;; terminal: 'char' | |
365 ((eq token 'terminal) | |
366 (setq ebnf-yac-lex (ebnf-string " -&(-~" ?\' "terminal")) | |
367 'terminal) | |
368 ;; non-terminal, terminal or "error" | |
369 ((eq token 'non-terminal) | |
370 (setq ebnf-yac-lex (ebnf-buffer-substring "0-9A-Za-z_.")) | |
371 (cond ((member ebnf-yac-lex ebnf-yac-token-list) | |
372 'terminal) | |
373 ((string= ebnf-yac-lex "error") | |
374 (setq ebnf-yac-error t) | |
375 'yac-error) | |
376 (t | |
377 'non-terminal) | |
378 )) | |
379 ;; %% and Yacc pragmas (%TOKEN, %START, etc). | |
380 ((eq token 'yac-pragma) | |
381 (forward-char) | |
382 (cond | |
383 ;; Yacc separator | |
384 ((eq (following-char) ?%) | |
385 (forward-char) | |
386 'yac-separator) | |
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
|
387 ;; %TOKEN, %RIGHT, %LEFT, %PREC, %NONASSOC |
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
|
388 ((cdr (assoc (upcase (ebnf-buffer-substring "0-9A-Za-z_")) |
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
|
389 '(("TOKEN" . yac-token) |
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
|
390 ("RIGHT" . yac-token) |
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
|
391 ("LEFT" . yac-token) |
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
|
392 ("NONASSOC" . yac-token) |
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
|
393 ("PREC" . yac-prec))))) |
27451 | 394 ;; other Yacc pragmas |
395 (t | |
396 'yac-pragma) | |
397 )) | |
398 ;; miscellaneous | |
399 (t | |
400 (forward-char) | |
401 token) | |
402 )))) | |
403 | |
404 | |
405 (defun ebnf-yac-skip-spaces () | |
406 (skip-chars-forward | |
407 (if ebnf-yac-skip-char | |
408 "\n\r\t !#$&()*+-.0123456789=?@[\\\\]^_`~" | |
409 "\n\r\t ") | |
410 ebnf-limit) | |
411 (< (point) ebnf-limit)) | |
412 | |
413 | |
39424
b7142e063fee
Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents:
39344
diff
changeset
|
414 ;; replace the range "\177-\377" (see `ebnf-range-regexp'). |
b7142e063fee
Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents:
39344
diff
changeset
|
415 (defconst ebnf-yac-skip-chars |
b7142e063fee
Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents:
39344
diff
changeset
|
416 (ebnf-range-regexp "^{}/'\"\000-\010\013\016-\037" ?\177 ?\377)) |
b7142e063fee
Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents:
39344
diff
changeset
|
417 |
b7142e063fee
Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents:
39344
diff
changeset
|
418 |
27451 | 419 (defun ebnf-yac-skip-code () |
420 (forward-char) | |
421 (let ((pair 1)) | |
422 (while (> pair 0) | |
39424
b7142e063fee
Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents:
39344
diff
changeset
|
423 (skip-chars-forward ebnf-yac-skip-chars ebnf-limit) |
27451 | 424 (cond |
425 ((= (following-char) ?{) | |
426 (forward-char) | |
427 (setq pair (1+ pair))) | |
428 ((= (following-char) ?}) | |
429 (forward-char) | |
430 (setq pair (1- pair))) | |
431 ((= (following-char) ?/) | |
432 (ebnf-yac-handle-comment)) | |
433 ((= (following-char) ?\") | |
434 (ebnf-get-string)) | |
435 ((= (following-char) ?\') | |
436 (ebnf-string " -&(-~" ?\' "character")) | |
437 (t | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34807
diff
changeset
|
438 (error "Illegal character")) |
27451 | 439 ))) |
440 (ebnf-yac-skip-spaces)) | |
441 | |
442 | |
443 (defun ebnf-yac-handle-comment () | |
444 (forward-char) | |
445 (cond | |
446 ;; begin comment | |
447 ((= (following-char) ?*) | |
448 (ebnf-yac-skip-comment) | |
449 (ebnf-yac-skip-spaces)) | |
450 ;; line comment | |
451 ((= (following-char) ?/) | |
452 (end-of-line) | |
453 (ebnf-yac-skip-spaces)) | |
454 ;; no comment | |
455 (t nil) | |
456 )) | |
457 | |
458 | |
34807
05c7152c7aeb
Fix the same problem as described on ebnf2ps.el log
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
459 ;; replace the range "\177-\237" (see `ebnf-range-regexp'). |
05c7152c7aeb
Fix the same problem as described on ebnf2ps.el log
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
460 (defconst ebnf-yac-comment-chars |
05c7152c7aeb
Fix the same problem as described on ebnf2ps.el log
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
461 (ebnf-range-regexp "^*\000-\010\013\016-\037" ?\177 ?\237)) |
27451 | 462 |
463 | |
464 (defun ebnf-yac-skip-comment () | |
465 (forward-char) | |
466 (cond | |
467 ;; open EPS file | |
468 ((and ebnf-eps-executing (= (following-char) ?\[)) | |
469 (ebnf-eps-add-context (ebnf-yac-eps-filename))) | |
470 ;; close EPS file | |
471 ((and ebnf-eps-executing (= (following-char) ?\])) | |
472 (ebnf-eps-remove-context (ebnf-yac-eps-filename))) | |
473 ;; any other action in comment | |
474 (t | |
475 (setq ebnf-action (aref ebnf-comment-table (following-char)))) | |
476 ) | |
477 (let ((not-end t)) | |
478 (while not-end | |
479 (skip-chars-forward ebnf-yac-comment-chars ebnf-limit) | |
480 (cond ((>= (point) ebnf-limit) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34807
diff
changeset
|
481 (error "Missing end of comment: `*/'")) |
27451 | 482 ((= (following-char) ?*) |
483 (skip-chars-forward "*" ebnf-limit) | |
484 (when (= (following-char) ?/) | |
485 ;; end of comment | |
486 (forward-char) | |
487 (setq not-end nil))) | |
488 (t | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34807
diff
changeset
|
489 (error "Illegal character")) |
27451 | 490 )))) |
491 | |
492 | |
493 (defun ebnf-yac-eps-filename () | |
494 (forward-char) | |
495 (buffer-substring-no-properties | |
496 (point) | |
497 (let ((chars (concat ebnf-yac-comment-chars "\n")) | |
498 found) | |
499 (while (not found) | |
500 (skip-chars-forward chars ebnf-limit) | |
501 (setq found | |
502 (cond ((>= (point) ebnf-limit) | |
503 (point)) | |
504 ((= (following-char) ?*) | |
505 (skip-chars-forward "*" ebnf-limit) | |
506 (if (/= (following-char) ?\/) | |
507 nil | |
508 (backward-char) | |
509 (point))) | |
510 (t | |
511 (point)) | |
512 ))) | |
513 found))) | |
514 | |
515 | |
516 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
517 | |
518 | |
519 (provide 'ebnf-yac) | |
520 | |
521 | |
52401 | 522 ;;; arch-tag: 8a96989c-0b1d-42ba-a020-b2901f9a2a4d |
27451 | 523 ;;; ebnf-yac.el ends here |