Mercurial > emacs
annotate lisp/progmodes/ebnf-yac.el @ 110456:8d106071e2c8
Use tool-bar-position in menu Options/Show.
* menu-bar.el (menu-bar-set-tool-bar-position): customize-set-variable
tool-bar-position. Don't modify frame parameters here.
author | Jan D. <jan.h.d@swipnet.se> |
---|---|
date | Tue, 21 Sep 2010 09:31:01 +0200 |
parents | 280c8ae2476d |
children | 417b1e4d63cd |
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 |
106815 | 3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
75347 | 4 ;; Free Software Foundation, Inc. |
27451 | 5 |
54140
766aaa5bded5
ABNF parser. Fix bug on productions like test = {"test"}* | ("tt" ["test"]). Reported by Markus Dreyer.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
52401
diff
changeset
|
6 ;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br> |
766aaa5bded5
ABNF parser. Fix bug on productions like test = {"test"}* | ("tt" ["test"]). Reported by Markus Dreyer.
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
52401
diff
changeset
|
7 ;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br> |
39344 | 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.4 |
110015
280c8ae2476d
Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
10 ;; Package: ebnf2ps |
27451 | 11 |
27539 | 12 ;; This file is part of GNU Emacs. |
27451 | 13 |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
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 |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
16 ;; 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
|
17 ;; (at your option) any later version. |
27451 | 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 | |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
27451 | 26 |
27 ;;; Commentary: | |
28 | |
29 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
30 ;; | |
31 ;; | |
32 ;; This is part of ebnf2ps package. | |
33 ;; | |
34 ;; This package defines a parser for Yacc/Bison. | |
35 ;; | |
36 ;; See ebnf2ps.el for documentation. | |
37 ;; | |
38 ;; | |
39 ;; Yacc/Bison Syntax | |
40 ;; ----------------- | |
41 ;; | |
42 ;; YACC = { YACC-Definitions }* "%%" { YACC-Rule }* [ "%%" [ YACC-Code ] ]. | |
43 ;; | |
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
|
44 ;; 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
|
45 ;; [ "<" 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
|
46 ;; | "%prec" Name |
27451 | 47 ;; | "any other Yacc definition" |
48 ;; . | |
49 ;; | |
50 ;; YACC-Code = "any C definition". | |
51 ;; | |
52 ;; YACC-Rule = Name ":" Alternative ";". | |
53 ;; | |
54 ;; Alternative = { Sequence || "|" }*. | |
55 ;; | |
56 ;; Sequence = { Factor }*. | |
57 ;; | |
58 ;; Factor = Name | |
59 ;; | "'" "character" "'" | |
60 ;; | "error" | |
61 ;; | "{" "C like commands" "}" | |
62 ;; . | |
63 ;; | |
64 ;; Name-List = { Name || "," }*. | |
65 ;; | |
66 ;; Name = "[A-Za-z][A-Za-z0-9_.]*". | |
67 ;; | |
68 ;; Comment = "/*" "any character, but the sequence \"*/\"" "*/" | |
54208 | 69 ;; | "//" "any character, but the newline \"\\n\"" "\\n". |
27451 | 70 ;; |
71 ;; | |
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
|
72 ;; 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
|
73 ;; 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
|
74 ;; 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
|
75 ;; |
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 ;; |
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 ;; 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
|
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 ;; |
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 ;; 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
|
81 ;; 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
|
82 ;; 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
|
83 ;; |
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 ;; |
27451 | 85 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
86 | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34807
diff
changeset
|
87 ;;; Code: |
27451 | 88 |
89 | |
90 (require 'ebnf-otz) | |
91 | |
92 | |
93 (defvar ebnf-yac-lex nil | |
94 "Value returned by `ebnf-yac-lex' function.") | |
95 | |
96 | |
97 (defvar ebnf-yac-token-list nil | |
98 "List of `%TOKEN' names.") | |
99 | |
100 | |
101 (defvar ebnf-yac-skip-char nil | |
102 "Non-nil means skip printable characters with no grammatical meaning.") | |
103 | |
104 | |
105 (defvar ebnf-yac-error nil | |
46275
0d5f7cc6ce91
(ebnf-yac-error): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents:
39424
diff
changeset
|
106 "Non-nil means \"error\" occurred.") |
27451 | 107 |
108 | |
109 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
49670
cc820064216c
Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents:
46275
diff
changeset
|
110 ;; Syntactic analyzer |
27451 | 111 |
112 | |
113 ;;; YACC = { YACC-Definitions }* "%%" { YACC-Rule }* [ "%%" [ YACC-Code ] ]. | |
114 ;;; | |
115 ;;; YACC-Code = "any C definition". | |
116 | |
117 (defun ebnf-yac-parser (start) | |
118 "yacc/Bison parser." | |
119 (let ((total (+ (- ebnf-limit start) 1)) | |
120 (bias (1- start)) | |
121 (origin (point)) | |
122 syntax-list token rule) | |
123 (goto-char start) | |
124 (setq token (ebnf-yac-lex)) | |
125 (and (eq token 'end-of-input) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34807
diff
changeset
|
126 (error "Invalid Yacc/Bison file format")) |
27451 | 127 (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
|
128 (error "Missing `%%%%'")) |
27451 | 129 (setq token (ebnf-yac-lex)) |
130 (while (not (memq token '(end-of-input yac-separator))) | |
131 (ebnf-message-float | |
132 "Parsing...%s%%" | |
133 (/ (* (- (point) bias) 100.0) total)) | |
134 (setq token (ebnf-yac-rule token) | |
135 rule (cdr token) | |
136 token (car token)) | |
137 (or (ebnf-add-empty-rule-list rule) | |
138 (setq syntax-list (cons rule syntax-list)))) | |
139 (goto-char origin) | |
140 syntax-list)) | |
141 | |
142 | |
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
|
143 ;;; 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
|
144 ;;; [ "<" 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
|
145 ;;; | "%prec" Name |
27451 | 146 ;;; | "any other Yacc definition" |
147 ;;; . | |
148 | |
149 (defun ebnf-yac-definitions (token) | |
150 (let ((ebnf-yac-skip-char t)) | |
151 (while (not (memq token '(yac-separator end-of-input))) | |
152 (setq token | |
153 (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
|
154 ;; ( "%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
|
155 ;; [ "<" Name ">" ] Name-List |
27451 | 156 ((eq token 'yac-token) |
157 (setq token (ebnf-yac-lex)) | |
158 (when (eq token 'open-angle) | |
159 (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
|
160 (error "Missing type name")) |
27451 | 161 (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
|
162 (error "Missing `>'")) |
27451 | 163 (setq token (ebnf-yac-lex))) |
164 (setq token (ebnf-yac-name-list token) | |
165 ebnf-yac-token-list (nconc (cdr token) | |
166 ebnf-yac-token-list)) | |
167 (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
|
168 ;; "%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
|
169 ((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
|
170 (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
|
171 (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
|
172 (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
|
173 ;; "any other Yacc definition" |
27451 | 174 (t |
175 (ebnf-yac-lex)) | |
176 ))) | |
177 token)) | |
178 | |
179 | |
180 ;;; YACC-Rule = Name ":" Alternative ";". | |
181 | |
182 (defun ebnf-yac-rule (token) | |
183 (let ((header ebnf-yac-lex) | |
184 (action ebnf-action) | |
185 body) | |
186 (setq ebnf-action nil) | |
187 (or (eq token 'non-terminal) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34807
diff
changeset
|
188 (error "Invalid rule name")) |
27451 | 189 (or (eq (ebnf-yac-lex) 'colon) |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34807
diff
changeset
|
190 (error "Invalid rule: missing `:'")) |
27451 | 191 (setq body (ebnf-yac-alternative)) |
192 (or (eq (car body) 'period) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34807
diff
changeset
|
193 (error "Invalid rule: missing `;'")) |
27451 | 194 (setq body (cdr body)) |
195 (ebnf-eps-add-production header) | |
196 (cons (ebnf-yac-lex) | |
197 (ebnf-make-production header body action)))) | |
198 | |
199 | |
200 ;;; Alternative = { Sequence || "|" }*. | |
201 | |
202 (defun ebnf-yac-alternative () | |
203 (let (body sequence) | |
204 (while (eq (car (setq sequence (ebnf-yac-sequence))) | |
205 'alternative) | |
206 (and (setq sequence (cdr sequence)) | |
207 (setq body (cons sequence body)))) | |
208 (ebnf-token-alternative body sequence))) | |
209 | |
210 | |
211 ;;; Sequence = { Factor }*. | |
212 | |
213 (defun ebnf-yac-sequence () | |
214 (let (ebnf-yac-error token seq factor) | |
215 (while (setq token (ebnf-yac-lex) | |
216 factor (ebnf-yac-factor token)) | |
217 (setq seq (cons factor seq))) | |
218 (cons token | |
54714 | 219 (if (and ebnf-yac-ignore-error-recovery ebnf-yac-error) |
220 ;; ignore error recovery | |
221 nil | |
222 (ebnf-token-sequence seq))))) | |
27451 | 223 |
224 | |
225 ;;; Factor = Name | |
226 ;;; | "'" "character" "'" | |
227 ;;; | "error" | |
228 ;;; | "{" "C like commands" "}" | |
229 ;;; . | |
230 | |
231 (defun ebnf-yac-factor (token) | |
232 (cond | |
233 ;; 'character' | |
234 ((eq token 'terminal) | |
235 (ebnf-make-terminal ebnf-yac-lex)) | |
236 ;; Name | |
237 ((eq token 'non-terminal) | |
238 (ebnf-make-non-terminal ebnf-yac-lex)) | |
239 ;; "error" | |
240 ((eq token 'yac-error) | |
241 (ebnf-make-special ebnf-yac-lex)) | |
242 ;; not a factor | |
243 (t | |
244 nil) | |
245 )) | |
246 | |
247 | |
248 ;;; Name-List = { Name || "," }*. | |
249 | |
250 (defun ebnf-yac-name-list (token) | |
251 (let (names) | |
252 (when (eq token 'non-terminal) | |
253 (while (progn | |
254 (setq names (cons ebnf-yac-lex names) | |
255 token (ebnf-yac-lex)) | |
256 (eq token 'comma)) | |
257 (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
|
258 (error "Missing token name")))) |
27451 | 259 (cons token names))) |
260 | |
261 | |
262 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
263 ;; Lexical analyzer | |
264 | |
265 | |
266 ;;; Name = "[A-Za-z][A-Za-z0-9_.]*". | |
267 ;;; | |
268 ;;; Comment = "/*" "any character, but the sequence \"*/\"" "*/" | |
269 ;;; | "//" "any character" "\\n". | |
270 | |
271 (defconst ebnf-yac-token-table | |
272 ;; control character & 8-bit character are set to `error' | |
273 (let ((table (make-vector 256 'error))) | |
274 ;; upper & lower case letters: | |
85222
12b40810304b
(ebnf-yac-token-table): Use mapc rather than mapcar.
Glenn Morris <rgm@gnu.org>
parents:
82143
diff
changeset
|
275 (mapc |
27451 | 276 #'(lambda (char) |
277 (aset table char 'non-terminal)) | |
278 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") | |
279 ;; printable characters: | |
85222
12b40810304b
(ebnf-yac-token-table): Use mapc rather than mapcar.
Glenn Morris <rgm@gnu.org>
parents:
82143
diff
changeset
|
280 (mapc |
27451 | 281 #'(lambda (char) |
282 (aset table char 'character)) | |
283 "!#$&()*+-.0123456789=?@[\\]^_`~") | |
284 ;; Override space characters: | |
285 (aset table ?\n 'space) ; [NL] linefeed | |
286 (aset table ?\r 'space) ; [CR] carriage return | |
287 (aset table ?\t 'space) ; [HT] horizontal tab | |
288 (aset table ?\ 'space) ; [SP] space | |
289 ;; Override form feed character: | |
290 (aset table ?\f 'form-feed) ; [FF] form feed | |
291 ;; Override other lexical characters: | |
292 (aset table ?< 'open-angle) | |
293 (aset table ?> 'close-angle) | |
294 (aset table ?, 'comma) | |
295 (aset table ?% 'yac-pragma) | |
296 (aset table ?/ 'slash) | |
297 (aset table ?\{ 'yac-code) | |
298 (aset table ?\" 'string) | |
299 (aset table ?\' 'terminal) | |
300 (aset table ?: 'colon) | |
301 (aset table ?| 'alternative) | |
302 (aset table ?\; 'period) | |
303 table) | |
304 "Vector used to map characters to a lexical token.") | |
305 | |
306 | |
307 (defun ebnf-yac-initialize () | |
308 "Initializations for Yacc/Bison parser." | |
309 (setq ebnf-yac-token-list nil)) | |
310 | |
311 | |
312 (defun ebnf-yac-lex () | |
63632
174466935578
(ebnf-yac-lex): Fix spellings.
Juanma Barranquero <lekktu@gmail.com>
parents:
60917
diff
changeset
|
313 "Lexical analyzer for Yacc/Bison. |
27451 | 314 |
315 Return a lexical token. | |
316 | |
317 See documentation for variable `ebnf-yac-lex'." | |
318 (if (>= (point) ebnf-limit) | |
319 'end-of-input | |
320 (let (token) | |
321 ;; skip spaces, code blocks and comments | |
322 (while (if (> (following-char) 255) | |
323 (progn | |
324 (setq token 'error) | |
325 nil) | |
326 (setq token (aref ebnf-yac-token-table (following-char))) | |
327 (cond | |
328 ((or (eq token 'space) | |
329 (and ebnf-yac-skip-char | |
330 (eq token 'character))) | |
331 (ebnf-yac-skip-spaces)) | |
332 ((eq token 'yac-code) | |
333 (ebnf-yac-skip-code)) | |
334 ((eq token 'slash) | |
335 (ebnf-yac-handle-comment)) | |
336 ((eq token 'form-feed) | |
337 (forward-char) | |
338 (setq ebnf-action 'form-feed)) | |
339 (t nil) | |
340 ))) | |
341 (cond | |
342 ;; end of input | |
343 ((>= (point) ebnf-limit) | |
344 'end-of-input) | |
345 ;; error | |
346 ((eq token 'error) | |
60917
87f9bb9d3718
* progmodes/ebnf-abn.el, progmodes/ebnf-bnf.el,
Werner LEMBERG <wl@gnu.org>
parents:
54714
diff
changeset
|
347 (error "Invalid character")) |
27451 | 348 ;; "string" |
349 ((eq token 'string) | |
350 (setq ebnf-yac-lex (ebnf-get-string)) | |
351 'string) | |
352 ;; terminal: 'char' | |
353 ((eq token 'terminal) | |
354 (setq ebnf-yac-lex (ebnf-string " -&(-~" ?\' "terminal")) | |
355 'terminal) | |
356 ;; non-terminal, terminal or "error" | |
357 ((eq token 'non-terminal) | |
358 (setq ebnf-yac-lex (ebnf-buffer-substring "0-9A-Za-z_.")) | |
359 (cond ((member ebnf-yac-lex ebnf-yac-token-list) | |
360 'terminal) | |
361 ((string= ebnf-yac-lex "error") | |
362 (setq ebnf-yac-error t) | |
363 'yac-error) | |
364 (t | |
365 'non-terminal) | |
366 )) | |
367 ;; %% and Yacc pragmas (%TOKEN, %START, etc). | |
368 ((eq token 'yac-pragma) | |
369 (forward-char) | |
370 (cond | |
371 ;; Yacc separator | |
372 ((eq (following-char) ?%) | |
373 (forward-char) | |
374 '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
|
375 ;; %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
|
376 ((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
|
377 '(("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
|
378 ("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
|
379 ("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
|
380 ("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
|
381 ("PREC" . yac-prec))))) |
27451 | 382 ;; other Yacc pragmas |
383 (t | |
384 'yac-pragma) | |
385 )) | |
386 ;; miscellaneous | |
387 (t | |
388 (forward-char) | |
389 token) | |
390 )))) | |
391 | |
392 | |
393 (defun ebnf-yac-skip-spaces () | |
394 (skip-chars-forward | |
395 (if ebnf-yac-skip-char | |
396 "\n\r\t !#$&()*+-.0123456789=?@[\\\\]^_`~" | |
397 "\n\r\t ") | |
398 ebnf-limit) | |
399 (< (point) ebnf-limit)) | |
400 | |
401 | |
39424
b7142e063fee
Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents:
39344
diff
changeset
|
402 ;; 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
|
403 (defconst ebnf-yac-skip-chars |
b7142e063fee
Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents:
39344
diff
changeset
|
404 (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
|
405 |
b7142e063fee
Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents:
39344
diff
changeset
|
406 |
27451 | 407 (defun ebnf-yac-skip-code () |
408 (forward-char) | |
409 (let ((pair 1)) | |
410 (while (> pair 0) | |
39424
b7142e063fee
Fix character range regexp. Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents:
39344
diff
changeset
|
411 (skip-chars-forward ebnf-yac-skip-chars ebnf-limit) |
27451 | 412 (cond |
413 ((= (following-char) ?{) | |
414 (forward-char) | |
415 (setq pair (1+ pair))) | |
416 ((= (following-char) ?}) | |
417 (forward-char) | |
418 (setq pair (1- pair))) | |
419 ((= (following-char) ?/) | |
420 (ebnf-yac-handle-comment)) | |
421 ((= (following-char) ?\") | |
422 (ebnf-get-string)) | |
423 ((= (following-char) ?\') | |
424 (ebnf-string " -&(-~" ?\' "character")) | |
425 (t | |
60917
87f9bb9d3718
* progmodes/ebnf-abn.el, progmodes/ebnf-bnf.el,
Werner LEMBERG <wl@gnu.org>
parents:
54714
diff
changeset
|
426 (error "Invalid character")) |
27451 | 427 ))) |
428 (ebnf-yac-skip-spaces)) | |
429 | |
430 | |
431 (defun ebnf-yac-handle-comment () | |
432 (forward-char) | |
433 (cond | |
434 ;; begin comment | |
435 ((= (following-char) ?*) | |
436 (ebnf-yac-skip-comment) | |
437 (ebnf-yac-skip-spaces)) | |
438 ;; line comment | |
439 ((= (following-char) ?/) | |
440 (end-of-line) | |
441 (ebnf-yac-skip-spaces)) | |
442 ;; no comment | |
443 (t nil) | |
444 )) | |
445 | |
446 | |
34807
05c7152c7aeb
Fix the same problem as described on ebnf2ps.el log
Gerd Moellmann <gerd@gnu.org>
parents:
27539
diff
changeset
|
447 ;; 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
|
448 (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
|
449 (ebnf-range-regexp "^*\000-\010\013\016-\037" ?\177 ?\237)) |
27451 | 450 |
451 | |
452 (defun ebnf-yac-skip-comment () | |
453 (forward-char) | |
454 (cond | |
455 ;; open EPS file | |
456 ((and ebnf-eps-executing (= (following-char) ?\[)) | |
457 (ebnf-eps-add-context (ebnf-yac-eps-filename))) | |
458 ;; close EPS file | |
459 ((and ebnf-eps-executing (= (following-char) ?\])) | |
460 (ebnf-eps-remove-context (ebnf-yac-eps-filename))) | |
82143
81c81019e0c6
New: Header/Footer comment & Log messages
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
78234
diff
changeset
|
461 ;; EPS header |
81c81019e0c6
New: Header/Footer comment & Log messages
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
78234
diff
changeset
|
462 ((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
|
463 (ebnf-eps-header-comment (ebnf-yac-eps-filename))) |
81c81019e0c6
New: Header/Footer comment & Log messages
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
78234
diff
changeset
|
464 ;; EPS footer |
81c81019e0c6
New: Header/Footer comment & Log messages
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
78234
diff
changeset
|
465 ((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
|
466 (ebnf-eps-footer-comment (ebnf-yac-eps-filename))) |
27451 | 467 ;; any other action in comment |
468 (t | |
469 (setq ebnf-action (aref ebnf-comment-table (following-char)))) | |
470 ) | |
471 (let ((not-end t)) | |
472 (while not-end | |
473 (skip-chars-forward ebnf-yac-comment-chars ebnf-limit) | |
474 (cond ((>= (point) ebnf-limit) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34807
diff
changeset
|
475 (error "Missing end of comment: `*/'")) |
27451 | 476 ((= (following-char) ?*) |
477 (skip-chars-forward "*" ebnf-limit) | |
478 (when (= (following-char) ?/) | |
479 ;; end of comment | |
480 (forward-char) | |
481 (setq not-end nil))) | |
482 (t | |
60917
87f9bb9d3718
* progmodes/ebnf-abn.el, progmodes/ebnf-bnf.el,
Werner LEMBERG <wl@gnu.org>
parents:
54714
diff
changeset
|
483 (error "Invalid character")) |
27451 | 484 )))) |
485 | |
486 | |
487 (defun ebnf-yac-eps-filename () | |
488 (forward-char) | |
489 (buffer-substring-no-properties | |
490 (point) | |
491 (let ((chars (concat ebnf-yac-comment-chars "\n")) | |
492 found) | |
493 (while (not found) | |
494 (skip-chars-forward chars ebnf-limit) | |
495 (setq found | |
496 (cond ((>= (point) ebnf-limit) | |
497 (point)) | |
498 ((= (following-char) ?*) | |
499 (skip-chars-forward "*" ebnf-limit) | |
500 (if (/= (following-char) ?\/) | |
501 nil | |
502 (backward-char) | |
503 (point))) | |
504 (t | |
505 (point)) | |
506 ))) | |
507 found))) | |
508 | |
509 | |
510 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
511 | |
512 | |
513 (provide 'ebnf-yac) | |
514 | |
515 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
516 ;; arch-tag: 8a96989c-0b1d-42ba-a020-b2901f9a2a4d |
27451 | 517 ;;; ebnf-yac.el ends here |