aboutsummaryrefslogtreecommitdiffstats
path: root/admin/grammars
diff options
context:
space:
mode:
Diffstat (limited to 'admin/grammars')
-rw-r--r--admin/grammars/README11
-rw-r--r--admin/grammars/bovine-grammar.el519
-rw-r--r--admin/grammars/c.by1202
-rw-r--r--admin/grammars/grammar.wy434
-rw-r--r--admin/grammars/java-tags.wy750
-rw-r--r--admin/grammars/js.wy526
-rw-r--r--admin/grammars/make.by168
-rw-r--r--admin/grammars/python.wy1133
-rw-r--r--admin/grammars/scheme.by84
-rw-r--r--admin/grammars/srecode-template.wy235
-rw-r--r--admin/grammars/wisent-grammar.el537
11 files changed, 5599 insertions, 0 deletions
diff --git a/admin/grammars/README b/admin/grammars/README
new file mode 100644
index 00000000000..419797e0dcb
--- /dev/null
+++ b/admin/grammars/README
@@ -0,0 +1,11 @@
1This directory contains grammar files in Bison and Wisent, used to
2generate the parser data in the lisp/semantic/bovine/ and
3lisp/semantic/wisent/ directories. You can run the parser generators
4with
5
6emacs -batch -Q -l bovine-grammar.el -f bovine-make-parsers
7emacs -batch -Q -l wisent-grammar.el -f wisent-make-parsers
8
9Currently, the parser files in lisp/ are not generated directly from
10these grammar files when making Emacs. This state of affairs, and the
11contents of this directory, will change in a future version of Emacs.
diff --git a/admin/grammars/bovine-grammar.el b/admin/grammars/bovine-grammar.el
new file mode 100644
index 00000000000..efe4db039c4
--- /dev/null
+++ b/admin/grammars/bovine-grammar.el
@@ -0,0 +1,519 @@
1;;; bovine-grammar.el --- Bovine's input grammar mode
2;;
3;; Copyright (C) 2002-2012 Free Software Foundation, Inc.
4;;
5;; Author: David Ponce <david@dponce.com>
6;; Maintainer: David Ponce <david@dponce.com>
7;; Created: 26 Aug 2002
8;; Keywords: syntax
9
10;; This file is part of GNU Emacs.
11
12;; GNU Emacs is free software: you can redistribute it and/or modify
13;; it under the terms of the GNU General Public License as published by
14;; the Free Software Foundation, either version 3 of the License, or
15;; (at your option) any later version.
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
23;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24
25;;; Commentary:
26;;
27;; Major mode for editing Bovine's input grammar (.by) files.
28
29;;; History:
30
31;;; Code:
32(require 'semantic)
33(require 'semantic/grammar)
34(require 'semantic/find)
35(require 'semantic/lex)
36(require 'semantic/wisent)
37(require 'semantic/bovine)
38
39(defun bovine-grammar-EXPAND (bounds nonterm)
40 "Expand call to EXPAND grammar macro.
41Return the form to parse from within a nonterminal between BOUNDS.
42NONTERM is the nonterminal symbol to start with."
43 `(semantic-bovinate-from-nonterminal
44 (car ,bounds) (cdr ,bounds) ',nonterm))
45
46(defun bovine-grammar-EXPANDFULL (bounds nonterm)
47 "Expand call to EXPANDFULL grammar macro.
48Return the form to recursively parse the area between BOUNDS.
49NONTERM is the nonterminal symbol to start with."
50 `(semantic-parse-region
51 (car ,bounds) (cdr ,bounds) ',nonterm 1))
52
53(defun bovine-grammar-TAG (name class &rest attributes)
54 "Expand call to TAG grammar macro.
55Return the form to create a generic semantic tag.
56See the function `semantic-tag' for the meaning of arguments NAME,
57CLASS and ATTRIBUTES."
58 `(semantic-tag ,name ,class ,@attributes))
59
60(defun bovine-grammar-VARIABLE-TAG (name type default-value &rest attributes)
61 "Expand call to VARIABLE-TAG grammar macro.
62Return the form to create a semantic tag of class variable.
63See the function `semantic-tag-new-variable' for the meaning of
64arguments NAME, TYPE, DEFAULT-VALUE and ATTRIBUTES."
65 `(semantic-tag-new-variable ,name ,type ,default-value ,@attributes))
66
67(defun bovine-grammar-FUNCTION-TAG (name type arg-list &rest attributes)
68 "Expand call to FUNCTION-TAG grammar macro.
69Return the form to create a semantic tag of class function.
70See the function `semantic-tag-new-function' for the meaning of
71arguments NAME, TYPE, ARG-LIST and ATTRIBUTES."
72 `(semantic-tag-new-function ,name ,type ,arg-list ,@attributes))
73
74(defun bovine-grammar-TYPE-TAG (name type members parents &rest attributes)
75 "Expand call to TYPE-TAG grammar macro.
76Return the form to create a semantic tag of class type.
77See the function `semantic-tag-new-type' for the meaning of arguments
78NAME, TYPE, MEMBERS, PARENTS and ATTRIBUTES."
79 `(semantic-tag-new-type ,name ,type ,members ,parents ,@attributes))
80
81(defun bovine-grammar-INCLUDE-TAG (name system-flag &rest attributes)
82 "Expand call to INCLUDE-TAG grammar macro.
83Return the form to create a semantic tag of class include.
84See the function `semantic-tag-new-include' for the meaning of
85arguments NAME, SYSTEM-FLAG and ATTRIBUTES."
86 `(semantic-tag-new-include ,name ,system-flag ,@attributes))
87
88(defun bovine-grammar-PACKAGE-TAG (name detail &rest attributes)
89 "Expand call to PACKAGE-TAG grammar macro.
90Return the form to create a semantic tag of class package.
91See the function `semantic-tag-new-package' for the meaning of
92arguments NAME, DETAIL and ATTRIBUTES."
93 `(semantic-tag-new-package ,name ,detail ,@attributes))
94
95(defun bovine-grammar-CODE-TAG (name detail &rest attributes)
96 "Expand call to CODE-TAG grammar macro.
97Return the form to create a semantic tag of class code.
98See the function `semantic-tag-new-code' for the meaning of arguments
99NAME, DETAIL and ATTRIBUTES."
100 `(semantic-tag-new-code ,name ,detail ,@attributes))
101
102(defun bovine-grammar-ALIAS-TAG (name aliasclass definition &rest attributes)
103 "Expand call to ALIAS-TAG grammar macro.
104Return the form to create a semantic tag of class alias.
105See the function `semantic-tag-new-alias' for the meaning of arguments
106NAME, ALIASCLASS, DEFINITION and ATTRIBUTES."
107 `(semantic-tag-new-alias ,name ,aliasclass ,definition ,@attributes))
108
109;; Cache of macro definitions currently in use.
110(defvar bovine--grammar-macros nil)
111
112;; Detect if we have an Emacs with newstyle unquotes allowed outside
113;; of backquote.
114;; This should probably be changed to a test to (= emacs-major-version 24)
115;; when it is released, but at the moment it might be possible that people
116;; are using an older snapshot.
117(defvar bovine--grammar-newstyle-unquote
118 (equal '(\, test) (read ",test")))
119
120(defun bovine-grammar-expand-form (form quotemode &optional inplace)
121 "Expand FORM into a new one suitable to the bovine parser.
122FORM is a list in which we are substituting.
123Argument QUOTEMODE is non-nil if we are in backquote mode.
124When non-nil, optional argument INPLACE indicates that FORM is being
125expanded from elsewhere."
126 (when (eq (car form) 'quote)
127 (setq form (cdr form))
128 (cond
129 ((and (= (length form) 1) (listp (car form)))
130 (insert "\n(append")
131 (bovine-grammar-expand-form (car form) quotemode nil)
132 (insert ")")
133 (setq form nil inplace nil)
134 )
135 ((and (= (length form) 1) (symbolp (car form)))
136 (insert "\n'" (symbol-name (car form)))
137 (setq form nil inplace nil)
138 )
139 (t
140 (insert "\n(list")
141 (setq inplace t)
142 )))
143 (let ((macro (assq (car form) bovine--grammar-macros))
144 inlist first n q x)
145 (if macro
146 (bovine-grammar-expand-form
147 (apply (cdr macro) (cdr form))
148 quotemode t)
149 (if inplace (insert "\n("))
150 (while form
151 (setq first (car form)
152 form (cdr form))
153 ;; Hack for dealing with new reading of unquotes outside of
154 ;; backquote (introduced in rev. 102591 in emacs-bzr).
155 (when (and bovine--grammar-newstyle-unquote
156 (listp first)
157 (or (equal (car first) '\,)
158 (equal (car first) '\,@)))
159 (if (listp (cadr first))
160 (setq form (append (cdr first) form)
161 first (car first))
162 (setq first (intern (concat (symbol-name (car first))
163 (symbol-name (cadr first)))))))
164 (cond
165 ((eq first nil)
166 (when (and (not inlist) (not inplace))
167 (insert "\n(list")
168 (setq inlist t))
169 (insert " nil")
170 )
171 ((listp first)
172 ;;(let ((fn (and (symbolp (caar form)) (fboundp (caar form)))))
173 (when (and (not inlist) (not inplace))
174 (insert "\n(list")
175 (setq inlist t))
176 ;;(if (and inplace (not fn) (not (eq (caar form) 'EXPAND)))
177 ;; (insert " (append"))
178 (bovine-grammar-expand-form
179 first quotemode t) ;;(and fn (not (eq fn 'quote))))
180 ;;(if (and inplace (not fn) (not (eq (caar form) 'EXPAND)))
181 ;; (insert ")"))
182 ;;)
183 )
184 ((symbolp first)
185 (setq n (symbol-name first) ;the name
186 q quotemode ;implied quote flag
187 x nil) ;expand flag
188 (if (eq (aref n 0) ?,)
189 (if quotemode
190 ;; backquote mode needs the @
191 (if (eq (aref n 1) ?@)
192 (setq n (substring n 2)
193 q nil
194 x t)
195 ;; non backquote mode behaves normally.
196 (setq n (substring n 1)
197 q nil))
198 (setq n (substring n 1)
199 x t)))
200 (if (string= n "")
201 (progn
202 ;; We expand only the next item in place (a list?)
203 ;; A regular inline-list...
204 (bovine-grammar-expand-form (car form) quotemode t)
205 (setq form (cdr form)))
206 (if (and (eq (aref n 0) ?$)
207 ;; Don't expand $ tokens in implied quote mode.
208 ;; This acts like quoting in other symbols.
209 (not q))
210 (progn
211 (cond
212 ((and (not x) (not inlist) (not inplace))
213 (insert "\n(list"))
214 ((and x inlist (not inplace))
215 (insert ")")
216 (setq inlist nil)))
217 (insert "\n(nth " (int-to-string
218 (1- (string-to-number
219 (substring n 1))))
220 " vals)")
221 (and (not x) (not inplace)
222 (setq inlist t)))
223
224 (when (and (not inlist) (not inplace))
225 (insert "\n(list")
226 (setq inlist t))
227 (or (char-equal (char-before) ?\()
228 (insert " "))
229 (insert (if (or inplace (eq first t))
230 "" "'")
231 n))) ;; " "
232 )
233 (t
234 (when (and (not inlist) (not inplace))
235 (insert "\n(list")
236 (setq inlist t))
237 (insert (format "\n%S" first))
238 )
239 ))
240 (if inlist (insert ")"))
241 (if inplace (insert ")")))
242 ))
243
244(defun bovine-grammar-expand-action (textform quotemode)
245 "Expand semantic action string TEXTFORM into Lisp code.
246QUOTEMODE is the mode in which quoted symbols are slurred."
247 (if (string= "" textform)
248 nil
249 (let ((sexp (read textform)))
250 ;; We converted the lambda string into a list. Now write it
251 ;; out as the bovine lambda expression, and do macro-like
252 ;; conversion upon it.
253 (insert "\n")
254 (cond
255 ((eq (car sexp) 'EXPAND)
256 (insert ",(lambda (vals start end)")
257 ;; The EXPAND macro definition is mandatory
258 (bovine-grammar-expand-form
259 (apply (cdr (assq 'EXPAND bovine--grammar-macros)) (cdr sexp))
260 quotemode t)
261 )
262 ((and (listp (car sexp)) (eq (caar sexp) 'EVAL))
263 ;; The user wants to evaluate the following args.
264 ;; Use a simpler expander
265 )
266 (t
267 (insert ",(semantic-lambda")
268 (bovine-grammar-expand-form sexp quotemode)
269 ))
270 (insert ")\n")))
271)
272
273(defun bovine-grammar-parsetable-builder ()
274 "Return the parser table expression as a string value.
275The format of a bovine parser table is:
276
277 ( ( NONTERMINAL-SYMBOL1 MATCH-LIST1 )
278 ( NONTERMINAL-SYMBOL2 MATCH-LIST2 )
279 ...
280 ( NONTERMINAL-SYMBOLn MATCH-LISTn )
281
282Where each NONTERMINAL-SYMBOL is an artificial symbol which can appear
283in any child state. As a starting place, one of the NONTERMINAL-SYMBOLS
284must be `bovine-toplevel'.
285
286A MATCH-LIST is a list of possible matches of the form:
287
288 ( STATE-LIST1
289 STATE-LIST2
290 ...
291 STATE-LISTN )
292
293where STATE-LIST is of the form:
294 ( TYPE1 [ \"VALUE1\" ] TYPE2 [ \"VALUE2\" ] ... LAMBDA )
295
296where TYPE is one of the returned types of the token stream.
297VALUE is a value, or range of values to match against. For
298example, a SYMBOL might need to match \"foo\". Some TYPES will not
299have matching criteria.
300
301LAMBDA is a lambda expression which is evalled with the text of the
302type when it is found. It is passed the list of all buffer text
303elements found since the last lambda expression. It should return a
304semantic element (see below.)
305
306For consistency between languages, try to use common return values
307from your parser. Please reference the chapter \"Writing Parsers\" in
308the \"Language Support Developer's Guide -\" in the semantic texinfo
309manual."
310 (let* ((start (semantic-grammar-start))
311 (scopestart (semantic-grammar-scopestart))
312 (quotemode (semantic-grammar-quotemode))
313 (tags (semantic-find-tags-by-class
314 'token (current-buffer)))
315 (nterms (semantic-find-tags-by-class
316 'nonterminal (current-buffer)))
317 ;; Setup the cache of macro definitions.
318 (bovine--grammar-macros (semantic-grammar-macros))
319 nterm rules items item actn prec tag type regex)
320
321 ;; Check some trivial things
322 (cond
323 ((null nterms)
324 (error "Bad input grammar"))
325 (start
326 (if (cdr start)
327 (message "Extra start symbols %S ignored" (cdr start)))
328 (setq start (symbol-name (car start)))
329 (unless (semantic-find-first-tag-by-name start nterms)
330 (error "start symbol `%s' has no rule" start)))
331 (t
332 ;; Default to the first grammar rule.
333 (setq start (semantic-tag-name (car nterms)))))
334 (when scopestart
335 (setq scopestart (symbol-name scopestart))
336 (unless (semantic-find-first-tag-by-name scopestart nterms)
337 (error "scopestart symbol `%s' has no rule" scopestart)))
338
339 ;; Generate the grammar Lisp form.
340 (with-temp-buffer
341 (erase-buffer)
342 (insert "`(")
343 ;; Insert the start/scopestart rules
344 (insert "\n(bovine-toplevel \n("
345 start
346 ")\n) ;; end bovine-toplevel\n")
347 (when scopestart
348 (insert "\n(bovine-inner-scope \n("
349 scopestart
350 ")\n) ;; end bovine-inner-scope\n"))
351 ;; Process each nonterminal
352 (while nterms
353 (setq nterm (car nterms)
354 ;; We can't use the override form because the current buffer
355 ;; is not the originator of the tag.
356 rules (semantic-tag-components-semantic-grammar-mode nterm)
357 nterm (semantic-tag-name nterm)
358 nterms (cdr nterms))
359 (when (member nterm '("bovine-toplevel" "bovine-inner-scope"))
360 (error "`%s' is a reserved internal name" nterm))
361 (insert "\n(" nterm)
362 ;; Process each rule
363 (while rules
364 (setq items (semantic-tag-get-attribute (car rules) :value)
365 prec (semantic-tag-get-attribute (car rules) :prec)
366 actn (semantic-tag-get-attribute (car rules) :expr)
367 rules (cdr rules))
368 ;; Process each item
369 (insert "\n(")
370 (if (null items)
371 ;; EMPTY rule
372 (insert ";;EMPTY" (if actn "" "\n"))
373 ;; Expand items
374 (while items
375 (setq item (car items)
376 items (cdr items))
377 (if (consp item) ;; mid-rule action
378 (message "Mid-rule action %S ignored" item)
379 (or (char-equal (char-before) ?\()
380 (insert "\n"))
381 (cond
382 ((member item '("bovine-toplevel" "bovine-inner-scope"))
383 (error "`%s' is a reserved internal name" item))
384 ;; Replace ITEM by its %token definition.
385 ;; If a '%token TYPE ITEM [REGEX]' definition exists
386 ;; in the grammar, ITEM is replaced by TYPE [REGEX].
387 ((setq tag (semantic-find-first-tag-by-name
388 item tags)
389 type (semantic-tag-get-attribute tag :type))
390 (insert type)
391 (if (setq regex (semantic-tag-get-attribute tag :value))
392 (insert (format "\n%S" regex))))
393 ;; Don't change ITEM
394 (t
395 (insert (semantic-grammar-item-text item)))
396 ))))
397 (if prec
398 (message "%%prec %S ignored" prec))
399 (if actn
400 (bovine-grammar-expand-action actn quotemode))
401 (insert ")"))
402 (insert "\n) ;; end " nterm "\n"))
403 (insert ")\n")
404 (buffer-string))))
405
406(defun bovine-grammar-setupcode-builder ()
407 "Return the text of the setup code."
408 (format
409 "(setq semantic--parse-table %s\n\
410 semantic-debug-parser-source %S\n\
411 semantic-debug-parser-class 'semantic-bovine-debug-parser
412 semantic-flex-keywords-obarray %s\n\
413 %s)"
414 (semantic-grammar-parsetable)
415 (buffer-name)
416 (semantic-grammar-keywordtable)
417 (let ((mode (semantic-grammar-languagemode)))
418 ;; Is there more than one major mode?
419 (if (and (listp mode) (> (length mode) 1))
420 (format "semantic-equivalent-major-modes '%S\n" mode)
421 ""))))
422
423(defvar bovine-grammar-menu
424 '("BY Grammar"
425 )
426 "BY mode specific grammar menu.
427Menu items are appended to the common grammar menu.")
428
429(define-derived-mode bovine-grammar-mode semantic-grammar-mode "BY"
430 "Major mode for editing Bovine grammars."
431 (semantic-grammar-setup-menu bovine-grammar-menu)
432 (semantic-install-function-overrides
433 '((grammar-parsetable-builder . bovine-grammar-parsetable-builder)
434 (grammar-setupcode-builder . bovine-grammar-setupcode-builder)
435 )))
436
437(add-to-list 'auto-mode-alist '("\\.by\\'" . bovine-grammar-mode))
438
439(defvar-mode-local bovine-grammar-mode semantic-grammar-macros
440 '(
441 (ASSOC . semantic-grammar-ASSOC)
442 (EXPAND . bovine-grammar-EXPAND)
443 (EXPANDFULL . bovine-grammar-EXPANDFULL)
444 (TAG . bovine-grammar-TAG)
445 (VARIABLE-TAG . bovine-grammar-VARIABLE-TAG)
446 (FUNCTION-TAG . bovine-grammar-FUNCTION-TAG)
447 (TYPE-TAG . bovine-grammar-TYPE-TAG)
448 (INCLUDE-TAG . bovine-grammar-INCLUDE-TAG)
449 (PACKAGE-TAG . bovine-grammar-PACKAGE-TAG)
450 (CODE-TAG . bovine-grammar-CODE-TAG)
451 (ALIAS-TAG . bovine-grammar-ALIAS-TAG)
452 )
453 "Semantic grammar macros used in bovine grammars.")
454
455(provide 'semantic/bovine/grammar)
456
457(defun bovine-make-parsers ()
458 "Generate Emacs' built-in Bovine-based parser files."
459 (semantic-mode 1)
460 ;; Loop through each .by file in current directory, and run
461 ;; `semantic-grammar-batch-build-one-package' to build the grammar.
462 (dolist (f (directory-files default-directory nil "\\.by\\'"))
463 (let ((packagename
464 (condition-case err
465 (with-current-buffer (find-file-noselect f)
466 (semantic-grammar-create-package))
467 (error (message "%s" (error-message-string err)) nil)))
468 lang)
469 (when (and packagename
470 (string-match "^semantic-\\(.*\\)-by\\.el\\'" packagename))
471 (setq lang (match-string 1 packagename))
472 (with-temp-buffer
473 (insert-file-contents packagename)
474 (setq buffer-file-name (expand-file-name packagename))
475 ;; Fix copyright header:
476 (goto-char (point-min))
477 (re-search-forward "^;; Author:")
478 (setq copyright-end (match-beginning 0))
479 (re-search-forward "^;;; Code:\n")
480 (delete-region copyright-end (match-end 0))
481 (goto-char copyright-end)
482 (insert ";; This file is part of GNU Emacs.
483
484;; GNU Emacs is free software: you can redistribute it and/or modify
485;; it under the terms of the GNU General Public License as published by
486;; the Free Software Foundation, either version 3 of the License, or
487;; (at your option) any later version.
488
489;; GNU Emacs is distributed in the hope that it will be useful,
490;; but WITHOUT ANY WARRANTY; without even the implied warranty of
491;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
492;; GNU General Public License for more details.
493
494;; You should have received a copy of the GNU General Public License
495;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
496
497;;; Commentary:
498;;
499;; This file was generated from admin/grammars/"
500 lang ".by.
501
502;;; Code:
503
504\(require 'semantic/lex)
505\(eval-when-compile (require 'semantic/bovine))\n")
506 (goto-char (point-min))
507 (delete-region (point-min) (line-end-position))
508 (insert ";;; semantic/bovine/" lang
509 "-by.el --- Generated parser support file")
510 (delete-trailing-whitespace)
511 ;; Fix footer:
512 (goto-char (point-max))
513 (re-search-backward ".\n;;; Analyzers")
514 (delete-region (point) (point-max))
515 (insert "(provide 'semantic/bovine/" lang "-by)\n\n")
516 (insert ";;; semantic/bovine/" lang "-by.el ends here\n")
517 (save-buffer))))))
518
519;;; bovine-grammar.el ends here
diff --git a/admin/grammars/c.by b/admin/grammars/c.by
new file mode 100644
index 00000000000..1bdaf8f447b
--- /dev/null
+++ b/admin/grammars/c.by
@@ -0,0 +1,1202 @@
1;;; c.by -- LL grammar for C/C++ language specification
2
3;; Copyright (C) 1999-2012 Free Software Foundation, Inc.
4;;
5;; Author: Eric M. Ludlam <zappo@gnu.org>
6;; David Ponce <david@dponce.com>
7;; Klaus Berndl <klaus.berndl@sdm.de>
8;;
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software: you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24;; TODO: From Nate Schley
25;; > * Can't parse signature element: "const char* const rmc_ClrTxt"
26;; > * Can't parse signature element: "char* const dellog_ClrTxt"
27;; > * Can't parse signature element: "const char* dellog_SetTxt"
28;; > * Can't parse signature element: "const RmcCmdSSPADetailedStatus& status"
29;; >
30;; > And FWIW I have seen the following argument cases not handled, even
31;; > with no leading/trailing spaces in the split:
32;; >
33;; > * Can't parse signature element: "const bool currentAlarmStatus"
34;; > * Can't parse signature element: "unsigned char mode"
35;; > * Can't parse signature element: "TskTimingTask* tsktimingtask"
36;; > * Can't parse signature element: "unsigned char htrStatus"
37;; > * Can't parse signature element: "char trackPower[]"
38;; > * Can't parse signature element: "const RmcCmdMCDetailedStatus& status"
39;; > * Can't parse signature element: "RmcBucStatus* rftBucStatus"
40
41%package semantic-c-by
42
43%languagemode c-mode c++-mode
44%start declaration
45%scopestart codeblock
46
47%token <punctuation> HASH "\\`[#]\\'"
48%token <punctuation> PERIOD "\\`[.]\\'"
49%token <punctuation> COLON "\\`[:]\\'"
50%token <punctuation> SEMICOLON "\\`[;]\\'"
51%token <punctuation> STAR "\\`[*]\\'"
52%token <punctuation> AMPERSAND "\\`[&]\\'"
53%token <punctuation> DIVIDE "\\`[/]\\'"
54%token <punctuation> PLUS "\\`[+]\\'"
55%token <punctuation> MINUS "\\`[-]\\'"
56%token <punctuation> BANG "\\`[!]\\'"
57%token <punctuation> EQUAL "\\`[=]\\'"
58%token <punctuation> LESS "\\`[<]\\'"
59%token <punctuation> GREATER "\\`[>]\\'"
60%token <punctuation> COMA "\\`[,]\\'"
61%token <punctuation> TILDE "\\`[~]\\'"
62%token <punctuation> MOD "\\`[%]\\'"
63%token <punctuation> HAT "\\`\\^\\'"
64%token <punctuation> OR "\\`[|]\\'"
65%token <string> C "\"C\""
66%token <string> CPP "\"C\\+\\+\""
67%token <number> ZERO "^0$"
68%token <symbol> RESTRICT "\\<\\(__\\)?restrict\\>"
69%token <open-paren> LPAREN "("
70%token <close-paren> RPAREN ")"
71%token <open-paren> LBRACE "{"
72%token <close-paren> RBRACE "}"
73%token <semantic-list> BRACK_BLCK "\\[.*\\]$"
74%token <semantic-list> PAREN_BLCK "^("
75%token <semantic-list> BRACE_BLCK "^{"
76%token <semantic-list> VOID_BLCK "^(void)$"
77%token <semantic-list> PARENS "()"
78%token <semantic-list> BRACKETS "\\[\\]"
79
80%token EXTERN "extern"
81%put EXTERN summary "Declaration Modifier: extern <type> <name> ..."
82%token STATIC "static"
83%put STATIC summary "Declaration Modifier: static <type> <name> ..."
84%token CONST "const"
85%put CONST summary "Declaration Modifier: const <type> <name> ..."
86%token VOLATILE "volatile"
87%put VOLATILE summary "Declaration Modifier: volatile <type> <name> ..."
88%token REGISTER "register"
89%put REGISTER summary "Declaration Modifier: register <type> <name> ..."
90%token SIGNED "signed"
91%put SIGNED summary "Numeric Type Modifier: signed <numeric type> <name> ..."
92%token UNSIGNED "unsigned"
93%put UNSIGNED summary "Numeric Type Modifier: unsigned <numeric type> <name> ..."
94
95%token INLINE "inline"
96%put INLINE summary "Function Modifier: inline <return type> <name>(...) {...};"
97%token VIRTUAL "virtual"
98%put VIRTUAL summary "Method Modifier: virtual <type> <name>(...) ..."
99%token MUTABLE "mutable"
100%put MUTABLE summary "Member Declaration Modifier: mutable <type> <name> ..."
101
102%token STRUCT "struct"
103%put STRUCT summary "Structure Type Declaration: struct [name] { ... };"
104%token UNION "union"
105%put UNION summary "Union Type Declaration: union [name] { ... };"
106%token ENUM "enum"
107%put ENUM summary "Enumeration Type Declaration: enum [name] { ... };"
108%token TYPEDEF "typedef"
109%put TYPEDEF summary "Arbitrary Type Declaration: typedef <typedeclaration> <name>;"
110%token CLASS "class"
111%put CLASS summary "Class Declaration: class <name>[:parents] { ... };"
112%token TYPENAME "typename"
113%put TYPENAME summary "typename is used to handle a qualified name as a typename;"
114%token NAMESPACE "namespace"
115%put NAMESPACE summary "Namespace Declaration: namespace <name> { ... };"
116%token USING "using"
117%put USING summary "using <namespace>;"
118
119%token NEW "new"
120%put NEW summary "new <classname>();"
121%token DELETE "delete"
122%put DELETE summary "delete <object>;"
123
124;; Despite this, this parser can find templates by ignoring the TEMPLATE
125;; keyword, and finding the class/method being templatized.
126%token TEMPLATE "template"
127%put TEMPLATE summary "template <class TYPE ...> TYPE_OR_FUNCTION"
128
129%token THROW "throw"
130%put THROW summary "<type> <methoddef> (<method args>) throw (<exception>) ..."
131%token REENTRANT "reentrant"
132%put REENTRANT summary "<type> <methoddef> (<method args>) reentrant ..."
133%token TRY "try"
134%token CATCH "catch"
135%put { TRY CATCH } summary "try { <body> } catch { <catch code> }"
136
137;; Leave these alone for now.
138%token OPERATOR "operator"
139%token PUBLIC "public"
140%token PRIVATE "private"
141%token PROTECTED "protected"
142%token FRIEND "friend"
143%put FRIEND summary "friend class <CLASSNAME>"
144
145;; These aren't used for parsing, but is a useful place to describe the keywords.
146%token IF "if"
147%token ELSE "else"
148%put {IF ELSE} summary "if (<condition>) { code } [ else { code } ]"
149
150%token DO "do"
151%token WHILE "while"
152%put DO summary " do { code } while (<condition>);"
153%put WHILE summary "do { code } while (<condition>); or while (<condition>) { code };"
154
155%token FOR "for"
156%put FOR summary "for(<init>; <condition>; <increment>) { code }"
157
158%token SWITCH "switch"
159%token CASE "case"
160%token DEFAULT "default"
161%put {SWITCH CASE DEFAULT} summary
162"switch (<variable>) { case <constvalue>: code; ... default: code; }"
163
164%token RETURN "return"
165%put RETURN summary "return <value>;"
166
167%token BREAK "break"
168%put BREAK summary "Non-local exit within a loop or switch (for, do/while, switch): break;"
169%token CONTINUE "continue"
170%put CONTINUE summary "Non-local continue within a loop (for, do/while): continue;"
171
172%token SIZEOF "sizeof"
173%put SIZEOF summary "Compile time macro: sizeof(<type or variable>) // size in bytes"
174
175;; Types
176%token VOID "void"
177%put VOID summary "Built in typeless type: void"
178%token CHAR "char"
179%put CHAR summary "Integral Character Type: (0 to 256)"
180%token WCHAR "wchar_t"
181%put WCHAR summary "Wide Character Type"
182%token SHORT "short"
183%put SHORT summary "Integral Primitive Type: (-32768 to 32767)"
184%token INT "int"
185%put INT summary "Integral Primitive Type: (-2147483648 to 2147483647)"
186%token LONG "long"
187%put LONG summary "Integral primitive type (-9223372036854775808 to 9223372036854775807)"
188%token FLOAT "float"
189%put FLOAT summary "Primitive floating-point type (single-precision 32-bit IEEE 754)"
190%token DOUBLE "double"
191%put DOUBLE summary "Primitive floating-point type (double-precision 64-bit IEEE 754)"
192%token BOOL "bool"
193%put BOOL summary "Primitive boolean type"
194
195%token UNDERP "_P"
196%token UNDERUNDERP "__P"
197%put UNDERP summary "Common macro to eliminate prototype compatibility on some compilers"
198%put UNDERUNDERP summary "Common macro to eliminate prototype compatibility on some compilers"
199
200%%
201
202declaration
203 : macro
204 | type
205 ;; TODO: Klaus Berndl: Is the define here necessary or even wrong?
206 ;; Is this part not already covered by macro??
207 | define
208 | var-or-fun
209 | extern-c
210 | template
211 | using
212 ;
213
214codeblock
215 : define
216 | codeblock-var-or-fun
217 | type ;; type is less likely to be used here.
218 | using
219 ;
220
221extern-c-contents
222 : open-paren
223 ( nil )
224 | declaration
225 | close-paren
226 ( nil )
227 ;
228
229extern-c
230 : EXTERN C semantic-list
231 ;; Extern C commands which contain a list need to have the
232 ;; entries of the list extracted, and spliced into the main
233 ;; list of entries. This must be done via the function
234 ;; that expands singular nonterminals, such as int x,y;
235 (TAG "C" 'extern :members (EXPANDFULL $3 extern-c-contents) )
236 | EXTERN CPP semantic-list
237 (TAG "C" 'extern :members (EXPANDFULL $3 extern-c-contents) )
238 | EXTERN C
239 ;; A plain extern "C" call should add something to the token,
240 ;; but just strip it from the buffer here for now.
241 ( nil )
242 | EXTERN CPP
243 ( nil )
244 ;
245
246macro
247 : spp-macro-def
248 (VARIABLE-TAG $1 nil nil :constant-flag t )
249 | spp-system-include
250 (INCLUDE-TAG $1 t)
251 | spp-include
252 (INCLUDE-TAG $1 nil)
253 ;
254
255;; This is used in struct parts.
256define
257 : spp-macro-def
258 (VARIABLE-TAG $1 nil nil :constant-flag t)
259 | spp-macro-undef
260 ( nil )
261 ;
262
263;; In C++, structures can have the same things as classes.
264;; So delete this some day in the figure.
265;;
266;;structparts : semantic-list
267;; (EXPANDFULL $1 structsubparts)
268;; ;
269;;
270;;structsubparts : LBRACE
271;; ( nil )
272;; | RBRACE
273;; ( nil )
274;; | var-or-fun
275;; | define
276;; ;; sometimes there are defines in structs.
277;; ;
278
279unionparts
280 : semantic-list
281 (EXPANDFULL $1 classsubparts)
282 ;
283
284opt-symbol
285 : symbol
286 | ;;EMPTY
287 ;
288
289;; @todo - support 'friend' construct.
290classsubparts
291 : LBRACE
292 ( nil )
293 | RBRACE
294 ( nil )
295 | class-protection opt-symbol COLON
296 ;; For QT, they may put a `slot' keyword between the protection
297 ;; and the COLON. @todo - Have the QT stuff use macros.
298 (TAG (car $1) 'label)
299 | var-or-fun
300 | FRIEND func-decl
301 (TAG (car $2) 'friend)
302 | FRIEND CLASS symbol
303 (TAG $3 'friend)
304 | type
305 | define
306 | template
307 | ;;EMPTY
308 ;
309
310opt-class-parents
311 : COLON class-parents opt-template-specifier
312 ( $2 )
313 | ;;EMPTY
314 ( )
315 ;
316
317one-class-parent
318 : opt-class-protection opt-class-declmods namespace-symbol
319 (TYPE-TAG (car $3) "class" nil nil :protection (car $1))
320 | opt-class-declmods opt-class-protection namespace-symbol
321 (TYPE-TAG (car $3) "class" nil nil :protection (car $2))
322 ;
323
324class-parents
325 : one-class-parent COMA class-parents
326 ( ,(cons ,$1 $3 ) )
327 | one-class-parent
328 ( $1 )
329 ;
330
331opt-class-declmods
332 : class-declmods opt-class-declmods
333 ( nil )
334 | ;;EMPTY
335 ;
336
337class-declmods
338 : VIRTUAL
339 ;
340
341class-protection
342 : PUBLIC
343 | PRIVATE
344 | PROTECTED
345 ;
346
347opt-class-protection
348 : class-protection
349 ( ,$1 )
350 | ;;EMPTY - Same as private
351 ( "unspecified" )
352 ;
353
354namespaceparts
355 : semantic-list
356 (EXPANDFULL $1 namespacesubparts)
357 ;
358
359namespacesubparts
360 : LBRACE
361 ( nil )
362 | RBRACE
363 ( nil )
364 | type
365 | var-or-fun
366 | define
367 | class-protection COLON
368 (TAG (car $1) 'label)
369 ;; In C++, this label in a classsubpart represents
370 ;; PUBLIC or PRIVATE bits. Ignore them for now.
371 | template
372 | using
373 | ;;EMPTY
374 ;
375
376enumparts
377 : semantic-list
378 (EXPANDFULL $1 enumsubparts)
379 ;
380
381enumsubparts
382 : symbol opt-assign
383 (VARIABLE-TAG $1 "int" (car $2) :constant-flag t )
384 | LBRACE
385 ( nil )
386 | RBRACE
387 ( nil )
388 | COMA
389 ( nil )
390 ;
391
392opt-name
393 : symbol
394 | ;;EMPTY
395 ( "" )
396 ;
397
398typesimple
399 : struct-or-class opt-class opt-name opt-template-specifier
400 opt-class-parents semantic-list
401 (TYPE-TAG (car $3) (car $1)
402 (let ((semantic-c-classname (cons (car ,$3) (car ,$1))))
403 (EXPANDFULL $6 classsubparts))
404 $5
405 :template-specifier $4
406 :parent (car ,$2))
407 | struct-or-class opt-class opt-name opt-template-specifier
408 opt-class-parents
409 (TYPE-TAG (car $3) (car $1) nil $5
410 :template-specifier $4
411 :prototype t
412 :parent (car ,$2))
413 | UNION opt-class opt-name unionparts
414 (TYPE-TAG (car $3) $1 $4 nil
415 :parent (car ,$2))
416 | ENUM opt-class opt-name enumparts
417 (TYPE-TAG (car $3) $1 $4 nil
418 :parent (car ,$2))
419 ;; Klaus Berndl: a typedef can be a typeformbase with all this
420 ;; declmods stuff.
421 | TYPEDEF declmods typeformbase cv-declmods typedef-symbol-list
422 ;;;; We put the type this typedef renames into PARENT
423 ;;;; but will move it in the expand function.
424 (TYPE-TAG $5 $1 nil (list $3) )
425 ;
426
427typedef-symbol-list
428 : typedefname COMA typedef-symbol-list
429 ( ,(cons $1 $3) )
430 | typedefname
431 ( $1 )
432 ;
433
434;; TODO: Klaus Berndl: symbol -> namespace-symbol?! Answer: Probably
435;; symbol is correct here!
436typedefname
437 : opt-stars symbol opt-bits opt-array
438 ( $1 $2 )
439 ;
440
441struct-or-class
442 : STRUCT
443 | CLASS
444 ;
445
446type
447 : typesimple SEMICOLON
448 ( ,$1 )
449 ;; named namespaces like "namespace XXX {"
450 | NAMESPACE symbol namespaceparts
451 (TYPE-TAG $2 $1 $3 nil )
452 ;; unnamed namespaces like "namespace {"
453 | NAMESPACE namespaceparts
454 (TYPE-TAG "unnamed" $1 $2 nil )
455 ;; David Engster: namespace alias like "namespace foo = bar;"
456 | NAMESPACE symbol EQUAL typeformbase SEMICOLON
457 (TYPE-TAG $2 $1 (list (TYPE-TAG (car $4) $1 nil nil)) nil :kind 'alias )
458 ;
459
460;; Klaus Berndl: We must parse "using namespace XXX" too
461
462;; Using is vaguely like an include statement in the named portions
463;; of the code. We should probably specify a new token type for this.
464
465using
466 : USING usingname SEMICOLON
467 (TAG (car $2) 'using :type ,$2 )
468 ;
469
470;; Jan Moringen: Differentiate between 'using' and 'using namespace'
471;; Adapted to creating type tags by EML.
472usingname
473 : typeformbase
474 (TYPE-TAG (car $1) "class" nil nil :prototype t)
475 | NAMESPACE typeformbase
476 (TYPE-TAG (car $2) "namespace" nil nil :prototype t)
477 ;
478
479template
480 : TEMPLATE template-specifier opt-friend template-definition
481 ( ,(semantic-c-reconstitute-template $4 ,$2) )
482 ;
483
484opt-friend
485 : FRIEND
486 | ;;EMPTY
487 ;
488
489opt-template-specifier
490 : template-specifier
491 ( ,$1 )
492 | ;;EMPTY
493 ( )
494 ;
495
496template-specifier
497 : LESS template-specifier-types GREATER
498 ( ,$2 )
499 ;
500
501template-specifier-types
502 : template-var template-specifier-type-list
503 ( ,(cons ,$1 ,$2 ) )
504 | ;;EMPTY
505 ;
506
507template-specifier-type-list
508 : COMA template-specifier-types
509 ( ,$2 )
510 | ;;EMPTY
511 ( )
512 ;
513
514;; template-var
515;; : template-type opt-stars opt-template-equal
516;; ( ,(cons (concat (car $1) (make-string (car ,$2) ?*))
517;; (cdr $1)))
518;; ;; Klaus Berndl: for template-types the template-var can also be
519;; ;; literals or constants. Example: map<ClassX, ClassY, 10>
520;; ;; map_size10_var; This parses also template<class T, 0> which is
521;; ;; nonsense but who cares....
522;; | string
523;; ( $1 )
524;; | number
525;; ( $1 )
526;; ;
527
528template-var
529 :
530 ;; Klaus Berndl: The following handles all template-vars of
531 ;; template-definitions
532 template-type opt-template-equal
533 ( ,(cons (car $1) (cdr $1)) )
534 ;; Klaus Berndl: for template-types the template-var can also be
535 ;; literals or constants.
536 ;; Example: map<ClassX, ClassY, 10> map_size10_var; This parses also
537 ;; template<class T, 0> which is nonsense but who cares....
538 | string
539 ( $1 )
540 | number
541 ( $1 )
542 ;; Klaus Berndl: In template-types arguments can be any symbols with
543 ;; optional address-operator (&) and optional dereferencing operator
544 ;; (*). Example map<ClassX, ClassY, *size_var_ptr> sized_map_var.
545 | opt-stars opt-ref namespace-symbol
546 ( ,$3 )
547 ;; Some code can compile down into a number, but starts out as an
548 ;; expression, such as "sizeof(a)", or (sizeof(a)/sizeof(b))
549 | semantic-list
550 ( $1 )
551 | SIZEOF semantic-list
552 ( $2 )
553 ;
554
555opt-template-equal
556 : EQUAL symbol LESS template-specifier-types GREATER
557 ( $2 )
558 | EQUAL symbol
559 ( $2 )
560 | ;;EMPTY
561 ( )
562 ;
563
564template-type
565 : CLASS symbol
566 (TYPE-TAG $2 "class" nil nil )
567 | STRUCT symbol
568 (TYPE-TAG $2 "struct" nil nil )
569 ;; TODO: Klaus Berndl: For the moment it is ok, that we parse the C++
570 ;; keyword typename as a class....
571 | TYPENAME symbol
572 (TYPE-TAG $2 "class" nil nil)
573 ;; Klaus Berndl: template-types can be all flavors of variable-args
574 ;; but here the argument is ignored, only the type stuff is needed.
575 | declmods typeformbase cv-declmods opt-stars
576 opt-ref variablearg-opt-name
577 (TYPE-TAG (car $2) nil nil nil
578 :constant-flag (if (member "const" (append $1 $3)) t nil)
579 :typemodifiers (delete "const" (append $1 $3))
580 :reference (car ,$5)
581 :pointer (car $4)
582 )
583 ;
584
585template-definition
586 : type
587 ( ,$1 )
588 | var-or-fun
589 ( ,$1 )
590 ;
591
592opt-stars
593 : STAR opt-starmod opt-stars
594 ( (1+ (car $3)) )
595 | ;;EMPTY
596 ( 0 )
597 ;
598
599opt-starmod
600 : STARMOD opt-starmod
601 ( ,(cons (,car ,$1) $2) )
602 | ;;EMPTY
603 ()
604 ;
605
606STARMOD
607 : CONST
608 ;
609
610declmods
611 : DECLMOD declmods
612 ( ,(cons ,(car ,$1) $2 ) )
613 | DECLMOD
614 ( ,$1 )
615 | ;;EMPTY
616 ()
617 ;
618
619DECLMOD
620 : EXTERN
621 | STATIC
622 | CVDECLMOD
623 ;; Klaus Berndl: IMHO signed and unsigned are not decl-modes but
624 ;; these are only valid for some buildin-types like short, int
625 ;; etc... whereas "real" declmods are valid for all types, buildin
626 ;; and user-defined! SIGNED UNSIGNED
627 | INLINE
628 | REGISTER
629 | FRIEND
630 ;; Klaus Berndl: There can be a few cases where TYPENAME is not
631 ;; allowed in C++-syntax but better than not recognizing the allowed
632 ;; situations.
633 | TYPENAME
634 | METADECLMOD
635 ;; This is a hack in case we are in a class.
636 | VIRTUAL
637 ;
638
639metadeclmod
640 : METADECLMOD
641 ()
642 | ;;EMPTY
643 ()
644 ;
645
646CVDECLMOD
647 : CONST
648 | VOLATILE
649 ;
650
651cv-declmods
652 : CVDECLMOD cv-declmods
653 ( ,(cons ,(car ,$1) $2 ) )
654 | CVDECLMOD
655 ( ,$1 )
656 | ;;EMPTY
657 ()
658 ;
659
660METADECLMOD
661 : VIRTUAL
662 | MUTABLE
663 ;
664
665;; C++: A type can be modified into a reference by "&"
666opt-ref
667 : AMPERSAND
668 ( 1 )
669 | ;;EMPTY
670 ( 0 )
671 ;
672
673typeformbase
674 : typesimple
675 ( ,$1 )
676 | STRUCT symbol
677 (TYPE-TAG $2 $1 nil nil )
678 | UNION symbol
679 (TYPE-TAG $2 $1 nil nil )
680 | ENUM symbol
681 (TYPE-TAG $2 $1 nil nil )
682 | builtintype
683 ( ,$1 )
684 | symbol template-specifier
685 (TYPE-TAG $1 "class" nil nil :template-specifier $2)
686 ;;| namespace-symbol opt-stars opt-template-specifier
687 ;;| namespace-symbol opt-template-specifier
688 | namespace-symbol-for-typeformbase opt-template-specifier
689 (TYPE-TAG (car $1) "class" nil nil
690 :template-specifier $2)
691 | symbol
692 ( $1 )
693 ;
694
695signedmod
696 : UNSIGNED
697 | SIGNED
698 ;
699
700;; Klaus Berndl: builtintype-types was builtintype
701builtintype-types
702 : VOID
703 | CHAR
704 ;; Klaus Berndl: Added WCHAR
705 | WCHAR
706 | SHORT INT
707 ( (concat $1 " " $2) )
708 | SHORT
709 | INT
710 | LONG INT
711 ( (concat $1 " " $2) )
712 | FLOAT
713 | DOUBLE
714 | BOOL
715 | LONG DOUBLE
716 ( (concat $1 " " $2) )
717 ;; TODO: Klaus Berndl: Is there a long long, i think so?!
718 | LONG LONG
719 ( (concat $1 " " $2) )
720 | LONG
721 ;
722
723builtintype
724 : signedmod builtintype-types
725 ( (concat (car $1) " " (car $2)) )
726 | builtintype-types
727 ( ,$1 )
728 ;; Klaus Berndl: unsigned is synonym for unsigned int and signed for
729 ;; signed int. To make this confusing stuff clear we add here the
730 ;; int.
731 | signedmod
732 ( (concat (car $1) " int") )
733 ;
734
735;; Klaus Berndl: This parses also nonsense like "const volatile int
736;; const volatile const const volatile a ..." but IMHO nobody writes
737;; such code. Normally we should define a rule like typeformbase-mode
738;; which exactly defines the different allowed cases and combinations
739;; of declmods (minus the CVDECLMOD) typeformbase and cv-declmods so
740;; we could recognize more invalid code but IMHO this is not worth the
741;; effort...
742codeblock-var-or-fun
743 : declmods typeformbase declmods
744 opt-ref var-or-func-decl
745 ( ,(semantic-c-reconstitute-token ,$5 $1 $2 ) )
746 ;
747
748var-or-fun
749 : codeblock-var-or-fun
750 ( ,$1 )
751 ;; it is possible for a function to not have a type, and
752 ;; it is then assumed to be an int. How annoying.
753 ;; In C++, this could be a constructor or a destructor.
754 ;; Even more annoying. Only ever do this for regular
755 ;; top-level items. Ignore this problem in code blocks
756 ;; so that we don't have to deal with regular code
757 ;; being erroneously converted into types.
758 | declmods var-or-func-decl
759 ( ,(semantic-c-reconstitute-token ,$2 $1 nil ) )
760 ;
761
762var-or-func-decl
763 : func-decl
764 ( ,$1 )
765 | var-decl
766 ( ,$1 )
767 ;
768
769func-decl
770 : opt-stars opt-class opt-destructor functionname
771 opt-template-specifier
772 opt-under-p
773 arg-list
774 opt-post-fcn-modifiers
775 opt-throw
776 opt-initializers
777 fun-or-proto-end
778 ( ,$4 'function
779 ;; Extra stuff goes in here.
780 ;; Continue with the stuff we found in
781 ;; this definition
782 $2 $3 $7 $9 $8 ,$1 ,$11 $5 ,$10)
783 | opt-stars opt-class opt-destructor functionname
784 opt-template-specifier
785 opt-under-p
786 ;; arg-list - - ini this case, a try implies a fcn.
787 opt-post-fcn-modifiers
788 opt-throw
789 opt-initializers
790 fun-try-end
791 ( ,$4 'function
792 ;; Extra stuff goes in here.
793 ;; Continue with the stuff we found in
794 ;; this definition
795 $2 $3 nil $8 $7 ,$1 ,$10 $5 ,$9)
796 ;
797
798var-decl
799 : varnamelist SEMICOLON
800 ( $1 'variable )
801 ;
802
803opt-under-p
804 : UNDERP
805 ( nil )
806 | UNDERUNDERP
807 ( nil )
808 | ;;EMPTY
809 ;
810
811;; Klaus Berndl: symbol -> namespace-symbol
812opt-initializers
813 : COLON namespace-symbol semantic-list opt-initializers
814 | COMA namespace-symbol semantic-list opt-initializers
815 | ;;EMPTY
816 ;
817
818opt-post-fcn-modifiers
819 : post-fcn-modifiers opt-post-fcn-modifiers
820 ( ,(cons ,$1 $2) )
821 | ;;EMPTY
822 ( nil )
823 ;
824
825post-fcn-modifiers
826 : REENTRANT
827 | CONST
828 ;
829
830opt-throw
831 : THROW semantic-list
832 ( EXPAND $2 throw-exception-list )
833 | ;;EMPTY
834 ;
835
836;; Is this true? I don't actually know.
837throw-exception-list
838 : namespace-symbol COMA throw-exception-list
839 ( ,(cons (car $1) $3) )
840 | namespace-symbol RPAREN
841 ( ,$1 )
842 | symbol RPAREN
843 ( $1 )
844 | LPAREN throw-exception-list
845 ( ,$2 )
846 | RPAREN
847 ( )
848 ;
849
850opt-bits
851 : COLON number
852 ( $2 )
853 | ;;EMPTY
854 ( nil )
855 ;
856
857opt-array
858 : BRACK_BLCK opt-array
859 ;; Eventually we want to replace the 1 below with a size
860 ;; (if available)
861 ( (cons 1 (car ,$2) ) )
862 | ;;EMPTY
863 ( nil )
864 ;
865
866opt-assign
867 : EQUAL expression
868 ( $2 )
869 | ;;EMPTY
870 ( nil )
871 ;
872
873opt-restrict
874 : RESTRICT
875 | ;;EMPTY
876 ;
877
878;; Klaus Berndl: symbol -> namespace-symbol?! I think so. Can be that
879;; then also some invalid C++-syntax is parsed but this is better than
880;; not parsing valid syntax.
881varname
882 : opt-stars opt-restrict namespace-symbol opt-bits opt-array
883 ( ,$3 ,$1 ,$4 ,$5 )
884 ;
885
886;; I should store more in this def, but leave it simple for now.
887;; Klaus Berndl: const and volatile can be written after the type!
888variablearg
889 : declmods typeformbase cv-declmods opt-ref variablearg-opt-name
890 ( VARIABLE-TAG (list $5) $2 nil
891 :constant-flag (if (member "const" (append $1 $3)) t nil)
892 :typemodifiers (delete "const" (append $1 $3))
893 :reference (car ,$4)
894 )
895 ;
896
897variablearg-opt-name
898 : varname
899 ( ,$1 )
900 ;; Klaus Berndl: This allows variableargs without a arg-name being
901 ;; parsed correct even if there several pointers (*)
902 | opt-stars
903 ( "" ,$1 nil nil nil )
904 ;
905
906varname-opt-initializer
907 : semantic-list
908 | opt-assign
909 | ;; EMPTY
910 ;
911
912varnamelist
913 : opt-ref varname varname-opt-initializer COMA varnamelist
914 ( ,(cons $2 $5) )
915 | opt-ref varname varname-opt-initializer
916 ( $2 )
917 ;
918
919;; Klaus Berndl: Is necessary to parse stuff like
920;; class list_of_facts : public list<fact>, public entity
921;; and
922;; list <shared_ptr<item> >::const_iterator l;
923;; Parses also invalid(?) and senseless(?) c++-syntax like
924;; symbol<template-spec>::symbol1<template-spec1>::test_iterator
925;; but better parsing too much than to less
926namespace-symbol
927 : symbol opt-template-specifier COLON COLON namespace-symbol
928 ( (concat $1 "::" (car $5)) )
929 | symbol opt-template-specifier
930 ( $1 )
931 ;
932
933;; Don't pull an optional template specifier at the end of the
934;; namespace symbol so that it can be picked up by the type.
935namespace-symbol-for-typeformbase
936 : symbol opt-template-specifier COLON COLON namespace-symbol-for-typeformbase
937 ( (concat $1 "::" (car $5)) )
938 | symbol
939 ( $1 )
940 ;
941;; namespace-symbol
942;; : symbol COLON COLON namespace-symbol
943;; ( (concat $1 "::" (car $4)) )
944;; | symbol
945;; ( $1 )
946;; ;
947
948namespace-opt-class
949 : symbol COLON COLON namespace-opt-class
950 ( (concat $1 "::" (car $4)) )
951 ;; Klaus Berndl: We must recognize template-specifiers here so we can
952 ;; parse correctly the method-implementations of template-classes
953 ;; outside the template-class-declaration Example:
954 ;; TemplateClass1<T>::method_1(...)
955 | symbol opt-template-specifier COLON COLON
956 ( $1 )
957 ;
958
959;; Klaus Berndl: The opt-class of a func-decl must be able to
960;; recognize opt-classes with namespaces, e.g.
961;; Test1::Test2::classname::
962opt-class
963 : namespace-opt-class
964 ( ,$1 )
965 | ;;EMPTY
966 ( nil )
967 ;
968
969opt-destructor
970 : TILDE
971 ( t )
972 | ;;EMPTY
973 ( nil )
974 ;
975
976arg-list
977 : PAREN_BLCK knr-arguments
978 ( ,$2 )
979 | PAREN_BLCK
980 (EXPANDFULL $1 arg-sub-list)
981 | VOID_BLCK
982 ( )
983 ;
984
985knr-varnamelist
986 : varname COMA knr-varnamelist
987 ( ,(cons $1 $3) )
988 | varname
989 ( $1 )
990 ;
991
992
993knr-one-variable-decl
994 : declmods typeformbase cv-declmods knr-varnamelist
995 ( VARIABLE-TAG (nreverse $4) $2 nil
996 :constant-flag (if (member "const" (append $3)) t nil)
997 :typemodifiers (delete "const" $3)
998 )
999 ;
1000
1001knr-arguments
1002 : knr-one-variable-decl SEMICOLON knr-arguments
1003 ( ,(append (semantic-expand-c-tag ,$1) ,$3) )
1004 | knr-one-variable-decl SEMICOLON
1005 ( ,(semantic-expand-c-tag ,$1) )
1006 ;
1007
1008arg-sub-list
1009 : variablearg
1010 ( ,$1 )
1011 | PERIOD PERIOD PERIOD RPAREN
1012 (VARIABLE-TAG "..." "vararg" nil)
1013 | COMA
1014 ( nil )
1015 | LPAREN
1016 ( nil )
1017 | RPAREN
1018 ( nil )
1019 ;
1020
1021operatorsym
1022 : LESS LESS EQUAL
1023 ( "<<=" )
1024 | GREATER GREATER EQUAL
1025 ( ">>=" )
1026 | LESS LESS
1027 ( "<<" )
1028 | GREATER GREATER
1029 ( ">>" )
1030 | EQUAL EQUAL
1031 ( "==" )
1032 | LESS EQUAL
1033 ( "<=" )
1034 | GREATER EQUAL
1035 ( ">=" )
1036 | BANG EQUAL
1037 ( "!=" )
1038 | PLUS EQUAL
1039 ( "+=" )
1040 | MINUS EQUAL
1041 ( "-=" )
1042 | STAR EQUAL
1043 ( "*=" )
1044 | DIVIDE EQUAL
1045 ( "/=" )
1046 | MOD EQUAL
1047 ( "%=" )
1048 | AMPERSAND EQUAL
1049 ( "&=" )
1050 | OR EQUAL
1051 ( "|=" )
1052 | MINUS GREATER STAR
1053 ( "->*" )
1054 | MINUS GREATER
1055 ( "->" )
1056 | PARENS
1057 ( "()" )
1058 | BRACKETS
1059 ( "[]" )
1060 | LESS
1061 | GREATER
1062 | STAR
1063 | PLUS PLUS
1064 ( "++" )
1065 | PLUS
1066 | MINUS MINUS
1067 ( "--" )
1068 | MINUS
1069 | AMPERSAND AMPERSAND
1070 ( "&&" )
1071 | AMPERSAND
1072 | OR OR
1073 ( "||" )
1074 | OR
1075 | DIVIDE
1076 | EQUAL
1077 | BANG
1078 | TILDE
1079 | MOD
1080 | COMA
1081 ;; HAT EQUAL seems to have a really unpleasant result and
1082 ;; breaks everything after it. Leave it at the end, though it
1083 ;; doesn't seem to work.
1084 | HAT EQUAL
1085 ( "^=" )
1086 | HAT
1087 ;
1088
1089functionname
1090 : OPERATOR operatorsym
1091 ( ,$2 )
1092 | semantic-list
1093 ( EXPAND $1 function-pointer )
1094 | symbol
1095 ( $1 )
1096 ;
1097
1098function-pointer
1099 : LPAREN STAR symbol RPAREN
1100 ( (concat "*" $3) )
1101 ;
1102
1103fun-or-proto-end
1104 : SEMICOLON
1105 ( t )
1106 | semantic-list
1107 ( nil )
1108 ;; Here is an annoying feature of C++ pure virtual methods
1109 | EQUAL ZERO SEMICOLON
1110 ( :pure-virtual-flag )
1111 | fun-try-end
1112 ( nil )
1113 ;
1114
1115fun-try-end
1116 : TRY opt-initializers BRACE_BLCK fun-try-several-catches
1117 ( nil )
1118 ;
1119
1120fun-try-several-catches
1121 : CATCH PAREN_BLCK BRACE_BLCK fun-try-several-catches
1122 ( )
1123 | CATCH BRACE_BLCK fun-try-several-catches
1124 ( )
1125 | ;; EMPTY
1126 ( )
1127 ;
1128
1129type-cast
1130 : semantic-list
1131 ( EXPAND $1 type-cast-list )
1132 ;
1133
1134type-cast-list
1135 : open-paren typeformbase close-paren
1136 ;
1137
1138opt-stuff-after-symbol
1139 : PAREN_BLCK
1140 | BRACK_BLCK
1141 | ;; EMPTY
1142 ;
1143
1144multi-stage-dereference
1145 : namespace-symbol opt-stuff-after-symbol PERIOD multi-stage-dereference ;; method call
1146 | namespace-symbol opt-stuff-after-symbol MINUS GREATER multi-stage-dereference ;;method call
1147 | namespace-symbol opt-stuff-after-symbol
1148 ;
1149
1150string-seq
1151 : string string-seq
1152 ( (concat $1 (car $2)) )
1153 | string
1154 ( $1 )
1155 ;
1156
1157expr-start
1158 : MINUS
1159 | PLUS
1160 | STAR
1161 | AMPERSAND
1162 ;
1163
1164expr-binop
1165 : MINUS
1166 | PLUS
1167 | STAR
1168 | DIVIDE
1169 | AMPERSAND AMPERSAND
1170 | AMPERSAND
1171 | OR OR
1172 | OR
1173 ;; There are more.
1174 ;
1175
1176;; Use expression for parsing only. Don't actually return anything
1177;; for now. Hopefully we can fix this later.
1178expression
1179 : unaryexpression expr-binop unaryexpression
1180 ( (identity start) (identity end) )
1181 | unaryexpression
1182 ( (identity start) (identity end) )
1183 ;
1184
1185unaryexpression
1186 : number
1187 | multi-stage-dereference
1188 | NEW multi-stage-dereference
1189 | NEW builtintype-types semantic-list
1190 ;; Klaus Berndl: symbol -> namespace-symbol!
1191 | namespace-symbol
1192 ;; Klaus Berndl: C/C++ allows sequences of strings which are
1193 ;; concatenated by the precompiler to one string
1194 | string-seq
1195 | type-cast expression ;; A cast to some other type
1196 ;; Casting the results of one expression to something else.
1197 | semantic-list expression
1198 | semantic-list
1199 | expr-start expression
1200 ;
1201
1202;;; c.by ends here
diff --git a/admin/grammars/grammar.wy b/admin/grammars/grammar.wy
new file mode 100644
index 00000000000..1189d6b0886
--- /dev/null
+++ b/admin/grammars/grammar.wy
@@ -0,0 +1,434 @@
1;;; semantic-grammar.wy -- LALR grammar of Semantic input grammars
2;;
3;; Copyright (C) 2002-2012 Free Software Foundation, Inc.
4;;
5;; Author: David Ponce <david@dponce.com>
6;; Maintainer: David Ponce <david@dponce.com>
7;; Created: 26 Aug 2002
8;; Keywords: syntax
9;; X-RCS: $Id: semantic-grammar.wy,v 1.16 2005/09/30 20:20:27 zappo Exp $
10
11;; This file is part of GNU Emacs.
12
13;; GNU Emacs is free software: you can redistribute it and/or modify
14;; it under the terms of the GNU General Public License as published by
15;; the Free Software Foundation, either version 3 of the License, or
16;; (at your option) any later version.
17
18;; GNU Emacs is distributed in the hope that it will be useful,
19;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21;; GNU General Public License for more details.
22
23;; You should have received a copy of the GNU General Public License
24;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25
26%{
27(defvar semantic-grammar-lex-c-char-re)
28
29;; Current parsed nonterminal name.
30(defvar semantic-grammar-wy--nterm nil)
31;; Index of rule in a nonterminal clause.
32(defvar semantic-grammar-wy--rindx nil)
33}
34
35%package semantic-grammar-wy
36
37%languagemode wy-mode
38
39;; Main
40%start grammar
41;; Reparse
42%start prologue epilogue declaration nonterminal rule
43;; EXPANDFULL
44%start put_names put_values use_names
45
46;; Keywords
47%type <keyword>
48%keyword DEFAULT-PREC "%default-prec"
49%keyword NO-DEFAULT-PREC "%no-default-prec"
50%keyword KEYWORD "%keyword"
51%keyword LANGUAGEMODE "%languagemode"
52%keyword LEFT "%left"
53%keyword NONASSOC "%nonassoc"
54%keyword PACKAGE "%package"
55%keyword PREC "%prec"
56%keyword PUT "%put"
57%keyword QUOTEMODE "%quotemode"
58%keyword RIGHT "%right"
59%keyword SCOPESTART "%scopestart"
60%keyword START "%start"
61%keyword TOKEN "%token"
62%keyword TYPE "%type"
63%keyword USE-MACROS "%use-macros"
64
65;; Literals
66%type <string>
67%token <string> STRING
68
69%type <symbol> syntax ":?\\(\\sw\\|\\s_\\)+"
70%token <symbol> SYMBOL
71%token <symbol> PERCENT_PERCENT "\\`%%\\'"
72
73%type <char> syntax semantic-grammar-lex-c-char-re
74%token <char> CHARACTER
75
76%type <qlist> matchdatatype sexp syntax "\\s'\\s-*("
77%token <qlist> PREFIXED_LIST
78
79%type <sexp> matchdatatype sexp syntax "\\="
80%token <sexp> SEXP
81
82;; Don't generate these analyzers which needs special handling code.
83%token <code> PROLOGUE "%{...%}"
84%token <code> EPILOGUE "%%...EOF"
85
86;; Blocks & Parenthesis
87%type <block>
88%token <block> PAREN_BLOCK "(LPAREN RPAREN)"
89%token <block> BRACE_BLOCK "(LBRACE RBRACE)"
90%token <open-paren> LPAREN "("
91%token <close-paren> RPAREN ")"
92%token <open-paren> LBRACE "{"
93%token <close-paren> RBRACE "}"
94
95;; Punctuations
96%type <punctuation>
97%token <punctuation> COLON ":"
98%token <punctuation> SEMI ";"
99%token <punctuation> OR "|"
100%token <punctuation> LT "<"
101%token <punctuation> GT ">"
102
103%%
104
105grammar:
106 prologue
107 | epilogue
108 | declaration
109 | nonterminal
110 | PERCENT_PERCENT
111 ;
112
113;;; Prologue/Epilogue
114;;
115prologue:
116 PROLOGUE
117 (CODE-TAG "prologue" nil)
118 ;
119
120epilogue:
121 EPILOGUE
122 (CODE-TAG "epilogue" nil)
123 ;
124
125;;; Declarations
126;;
127declaration:
128 decl
129 (eval $1)
130 ;
131
132decl:
133 default_prec_decl
134 | no_default_prec_decl
135 | languagemode_decl
136 | package_decl
137 | precedence_decl
138 | put_decl
139 | quotemode_decl
140 | scopestart_decl
141 | start_decl
142 | keyword_decl
143 | token_decl
144 | type_decl
145 | use_macros_decl
146 ;
147
148default_prec_decl:
149 DEFAULT-PREC
150 `(TAG "default-prec" 'assoc :value '("t"))
151 ;
152
153no_default_prec_decl:
154 NO-DEFAULT-PREC
155 `(TAG "default-prec" 'assoc :value '("nil"))
156 ;
157
158languagemode_decl:
159 LANGUAGEMODE symbols
160 `(TAG ',(car $2) 'languagemode :rest ',(cdr $2))
161 ;
162
163package_decl:
164 PACKAGE SYMBOL
165 `(PACKAGE-TAG ',$2 nil)
166 ;
167
168precedence_decl:
169 associativity token_type_opt items
170 `(TAG ',$1 'assoc :type ',$2 :value ',$3)
171 ;
172
173associativity:
174 LEFT
175 (progn "left")
176 | RIGHT
177 (progn "right")
178 | NONASSOC
179 (progn "nonassoc")
180 ;
181
182put_decl:
183 PUT put_name put_value
184 `(TAG ',$2 'put :value ',(list $3))
185 | PUT put_name put_value_list
186 `(TAG ',$2 'put :value ',$3)
187 | PUT put_name_list put_value
188 `(TAG ',(car $2) 'put :rest ',(cdr $2) :value ',(list $3))
189 | PUT put_name_list put_value_list
190 `(TAG ',(car $2) 'put :rest ',(cdr $2) :value ',$3)
191 ;
192
193put_name_list:
194 BRACE_BLOCK
195 (mapcar 'semantic-tag-name (EXPANDFULL $1 put_names))
196 ;
197
198put_names:
199 LBRACE
200 ()
201 | RBRACE
202 ()
203 | put_name
204 ;; Must return a list of Semantic tags to EXPANDFULL!
205 (TAG $1 'put-name)
206 ;
207
208put_name:
209 SYMBOL
210 | token_type
211 ;
212
213put_value_list:
214 BRACE_BLOCK
215 (mapcar 'semantic-tag-code-detail (EXPANDFULL $1 put_values))
216 ;
217
218put_values:
219 LBRACE
220 ()
221 | RBRACE
222 ()
223 | put_value
224 ;; Must return a list of Semantic tags to EXPANDFULL!
225 (CODE-TAG "put-value" $1)
226 ;
227
228put_value:
229 SYMBOL any_value
230 (cons $1 $2)
231 ;
232
233scopestart_decl:
234 SCOPESTART SYMBOL
235 `(TAG ',$2 'scopestart)
236 ;
237
238quotemode_decl:
239 QUOTEMODE SYMBOL
240 `(TAG ',$2 'quotemode)
241 ;
242
243start_decl:
244 START symbols
245 `(TAG ',(car $2) 'start :rest ',(cdr $2))
246 ;
247
248keyword_decl:
249 KEYWORD SYMBOL string_value
250 `(TAG ',$2 'keyword :value ',$3)
251 ;
252
253token_decl:
254 TOKEN token_type_opt SYMBOL string_value
255 `(TAG ',$3 ',(if $2 'token 'keyword) :type ',$2 :value ',$4)
256 | TOKEN token_type_opt symbols
257 `(TAG ',(car $3) 'token :type ',$2 :rest ',(cdr $3))
258 ;
259
260token_type_opt:
261 ;; EMPTY
262 | token_type
263 ;
264
265token_type:
266 LT SYMBOL GT
267 (progn $2)
268 ;
269
270type_decl:
271 TYPE token_type plist_opt
272 `(TAG ',$2 'type :value ',$3)
273 ;
274
275plist_opt:
276 ;;EMPTY
277 | plist
278 ;
279
280plist:
281 plist put_value
282 (append (list $2) $1)
283 | put_value
284 (list $1)
285 ;
286
287use_name_list:
288 BRACE_BLOCK
289 (mapcar 'semantic-tag-name (EXPANDFULL $1 use_names))
290 ;
291
292use_names:
293 LBRACE
294 ()
295 | RBRACE
296 ()
297 | SYMBOL
298 ;; Must return a list of Semantic tags to EXPANDFULL!
299 (TAG $1 'use-name)
300 ;
301
302use_macros_decl:
303 USE-MACROS SYMBOL use_name_list
304 `(TAG "macro" 'macro :type ',$2 :value ',$3)
305 ;
306
307string_value:
308 STRING
309 (read $1)
310 ;
311
312;; Return a Lisp readable form
313any_value:
314 SYMBOL
315 | STRING
316 | PAREN_BLOCK
317 | PREFIXED_LIST
318 | SEXP
319 ;
320
321symbols:
322 lifo_symbols
323 (nreverse $1)
324 ;
325
326lifo_symbols:
327 lifo_symbols SYMBOL
328 (cons $2 $1)
329 | SYMBOL
330 (list $1)
331 ;
332
333;;; Grammar rules
334;;
335nonterminal:
336 SYMBOL
337 (setq semantic-grammar-wy--nterm $1
338 semantic-grammar-wy--rindx 0)
339 COLON rules SEMI
340 (TAG $1 'nonterminal :children $4)
341 ;
342
343rules:
344 lifo_rules
345 (apply 'nconc (nreverse $1))
346 ;
347
348lifo_rules:
349 lifo_rules OR rule
350 (cons $3 $1)
351 | rule
352 (list $1)
353 ;
354
355rule:
356 rhs
357 (let* ((nterm semantic-grammar-wy--nterm)
358 (rindx semantic-grammar-wy--rindx)
359 (rhs $1)
360 comps prec action elt)
361 (setq semantic-grammar-wy--rindx (1+ semantic-grammar-wy--rindx))
362 (while rhs
363 (setq elt (car rhs)
364 rhs (cdr rhs))
365 (cond
366 ;; precedence level
367 ((vectorp elt)
368 (if prec
369 (error "Duplicate %%prec in `%s:%d' rule" nterm rindx))
370 (setq prec (aref elt 0)))
371 ;; action
372 ((consp elt)
373 ;; don't forget that rhs items are in reverse order, so
374 ;; the end-of-rule semantic action is the first item.
375 (if (or action comps)
376 ;; a mid-rule action
377 (setq comps (cons elt comps)
378 ;; keep rule and action index synchronized
379 semantic-grammar-wy--rindx
380 (1+ semantic-grammar-wy--rindx))
381 ;; the end-of-rule action
382 (setq action (car elt))))
383 ;; item
384 (t
385 (setq comps (cons elt comps)))))
386 (EXPANDTAG
387 (TAG (format "%s:%d" nterm rindx) 'rule
388 :type (if comps "group" "empty")
389 :value comps :prec prec :expr action)))
390 ;
391
392rhs:
393 ;; EMPTY
394 | rhs item
395 (cons $2 $1)
396 | rhs action
397 (cons (list $2) $1)
398 | rhs PREC item
399 (cons (vector $3) $1)
400 ;
401
402action:
403 PAREN_BLOCK
404 | PREFIXED_LIST
405 | BRACE_BLOCK
406 (format "(progn\n%s)"
407 (let ((s $1))
408 (if (string-match "^{[\r\n\t ]*" s)
409 (setq s (substring s (match-end 0))))
410 (if (string-match "[\r\n\t ]*}$" s)
411 (setq s (substring s 0 (match-beginning 0))))
412 s))
413 ;
414
415items:
416 lifo_items
417 (nreverse $1)
418 ;
419
420lifo_items:
421 lifo_items item
422 (cons $2 $1)
423 | item
424 (list $1)
425 ;
426
427item:
428 SYMBOL
429 | CHARACTER
430 ;
431
432%%
433
434;;; grammar.wy ends here
diff --git a/admin/grammars/java-tags.wy b/admin/grammars/java-tags.wy
new file mode 100644
index 00000000000..b58b96c6bfb
--- /dev/null
+++ b/admin/grammars/java-tags.wy
@@ -0,0 +1,750 @@
1;;; java-tags.wy -- Semantic LALR grammar for Java
2
3;; Copyright (C) 2002-2012 Free Software Foundation, Inc.
4;;
5;; Author: David Ponce <david@dponce.com>
6;; Maintainer: David Ponce <david@dponce.com>
7;; Created: 26 Aug 2002
8;; Keywords: syntax
9
10;; This file is part of GNU Emacs.
11
12;; GNU Emacs is free software: you can redistribute it and/or modify
13;; it under the terms of the GNU General Public License as published by
14;; the Free Software Foundation, either version 3 of the License, or
15;; (at your option) any later version.
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
23;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24
25%package wisent-java-tags-wy
26
27%languagemode java-mode
28
29;; The default start symbol
30%start compilation_unit
31;; Alternate entry points
32;; - Needed by partial re-parse
33%start package_declaration
34%start import_declaration
35%start class_declaration
36%start field_declaration
37%start method_declaration
38%start formal_parameter
39%start constructor_declaration
40%start interface_declaration
41;; - Needed by EXPANDFULL clauses
42%start class_member_declaration
43%start interface_member_declaration
44%start formal_parameters
45
46;; -----------------------------
47;; Block & Parenthesis terminals
48;; -----------------------------
49%type <block> ;;syntax "\\s(\\|\\s)" matchdatatype block
50
51%token <block> PAREN_BLOCK "(LPAREN RPAREN)"
52%token <block> BRACE_BLOCK "(LBRACE RBRACE)"
53%token <block> BRACK_BLOCK "(LBRACK RBRACK)"
54
55%token <open-paren> LPAREN "("
56%token <close-paren> RPAREN ")"
57%token <open-paren> LBRACE "{"
58%token <close-paren> RBRACE "}"
59%token <open-paren> LBRACK "["
60%token <close-paren> RBRACK "]"
61
62;; ------------------
63;; Operator terminals
64;; ------------------
65%type <punctuation> ;;syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string
66
67%token <punctuation> NOT "!"
68%token <punctuation> NOTEQ "!="
69%token <punctuation> MOD "%"
70%token <punctuation> MODEQ "%="
71%token <punctuation> AND "&"
72%token <punctuation> ANDAND "&&"
73%token <punctuation> ANDEQ "&="
74%token <punctuation> MULT "*"
75%token <punctuation> MULTEQ "*="
76%token <punctuation> PLUS "+"
77%token <punctuation> PLUSPLUS "++"
78%token <punctuation> PLUSEQ "+="
79%token <punctuation> COMMA ","
80%token <punctuation> MINUS "-"
81%token <punctuation> MINUSMINUS "--"
82%token <punctuation> MINUSEQ "-="
83%token <punctuation> DOT "."
84%token <punctuation> DIV "/"
85%token <punctuation> DIVEQ "/="
86%token <punctuation> COLON ":"
87%token <punctuation> SEMICOLON ";"
88%token <punctuation> LT "<"
89%token <punctuation> LSHIFT "<<"
90%token <punctuation> LSHIFTEQ "<<="
91%token <punctuation> LTEQ "<="
92%token <punctuation> EQ "="
93%token <punctuation> EQEQ "=="
94%token <punctuation> GT ">"
95%token <punctuation> GTEQ ">="
96%token <punctuation> RSHIFT ">>"
97%token <punctuation> RSHIFTEQ ">>="
98%token <punctuation> URSHIFT ">>>"
99%token <punctuation> URSHIFTEQ ">>>="
100%token <punctuation> QUESTION "?"
101%token <punctuation> XOR "^"
102%token <punctuation> XOREQ "^="
103%token <punctuation> OR "|"
104%token <punctuation> OREQ "|="
105%token <punctuation> OROR "||"
106%token <punctuation> COMP "~"
107
108;; -----------------
109;; Literal terminals
110;; -----------------
111%type <symbol> ;;syntax "\\(\\sw\\|\\s_\\)+"
112%token <symbol> IDENTIFIER
113
114%type <string> ;;syntax "\\s\"" matchdatatype sexp
115%token <string> STRING_LITERAL
116
117%type <number> ;;syntax semantic-lex-number-expression
118%token <number> NUMBER_LITERAL
119
120%type <unicode> syntax "\\\\u[0-9a-f][0-9a-f][0-9a-f][0-9a-f]"
121%token <unicode> unicodecharacter
122
123;; -----------------
124;; Keyword terminals
125;; -----------------
126
127;; Generate a keyword analyzer
128%type <keyword> ;;syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword
129
130%keyword ABSTRACT "abstract"
131%put ABSTRACT summary
132"Class|Method declaration modifier: abstract {class|<type>} <name> ..."
133
134%keyword BOOLEAN "boolean"
135%put BOOLEAN summary
136"Primitive logical quantity type (true or false)"
137
138%keyword BREAK "break"
139%put BREAK summary
140"break [<label>] ;"
141
142%keyword BYTE "byte"
143%put BYTE summary
144"Integral primitive type (-128 to 127)"
145
146%keyword CASE "case"
147%put CASE summary
148"switch(<expr>) {case <const-expr>: <stmts> ... }"
149
150%keyword CATCH "catch"
151%put CATCH summary
152"try {<stmts>} catch(<parm>) {<stmts>} ... "
153
154%keyword CHAR "char"
155%put CHAR summary
156"Integral primitive type ('\u0000' to '\uffff') (0 to 65535)"
157
158%keyword CLASS "class"
159%put CLASS summary
160"Class declaration: class <name>"
161
162%keyword CONST "const"
163%put CONST summary
164"Unused reserved word"
165
166%keyword CONTINUE "continue"
167%put CONTINUE summary
168"continue [<label>] ;"
169
170%keyword DEFAULT "default"
171%put DEFAULT summary
172"switch(<expr>) { ... default: <stmts>}"
173
174%keyword DO "do"
175%put DO summary
176"do <stmt> while (<expr>);"
177
178%keyword DOUBLE "double"
179%put DOUBLE summary
180"Primitive floating-point type (double-precision 64-bit IEEE 754)"
181
182%keyword ELSE "else"
183%put ELSE summary
184"if (<expr>) <stmt> else <stmt>"
185
186%keyword EXTENDS "extends"
187%put EXTENDS summary
188"SuperClass|SuperInterfaces declaration: extends <name> [, ...]"
189
190%keyword FINAL "final"
191%put FINAL summary
192"Class|Member declaration modifier: final {class|<type>} <name> ..."
193
194%keyword FINALLY "finally"
195%put FINALLY summary
196"try {<stmts>} ... finally {<stmts>}"
197
198%keyword FLOAT "float"
199%put FLOAT summary
200"Primitive floating-point type (single-precision 32-bit IEEE 754)"
201
202%keyword FOR "for"
203%put FOR summary
204"for ([<init-expr>]; [<expr>]; [<update-expr>]) <stmt>"
205
206%keyword GOTO "goto"
207%put GOTO summary
208"Unused reserved word"
209
210%keyword IF "if"
211%put IF summary
212"if (<expr>) <stmt> [else <stmt>]"
213
214%keyword IMPLEMENTS "implements"
215%put IMPLEMENTS summary
216"Class SuperInterfaces declaration: implements <name> [, ...]"
217
218%keyword IMPORT "import"
219%put IMPORT summary
220"Import package declarations: import <package>"
221
222%keyword INSTANCEOF "instanceof"
223
224%keyword INT "int"
225%put INT summary
226"Integral primitive type (-2147483648 to 2147483647)"
227
228%keyword INTERFACE "interface"
229%put INTERFACE summary
230"Interface declaration: interface <name>"
231
232%keyword LONG "long"
233%put LONG summary
234"Integral primitive type (-9223372036854775808 to 9223372036854775807)"
235
236%keyword NATIVE "native"
237%put NATIVE summary
238"Method declaration modifier: native <type> <name> ..."
239
240%keyword NEW "new"
241
242%keyword PACKAGE "package"
243%put PACKAGE summary
244"Package declaration: package <name>"
245
246%keyword PRIVATE "private"
247%put PRIVATE summary
248"Access level modifier: private {class|interface|<type>} <name> ..."
249
250%keyword PROTECTED "protected"
251%put PROTECTED summary
252"Access level modifier: protected {class|interface|<type>} <name> ..."
253
254%keyword PUBLIC "public"
255%put PUBLIC summary
256"Access level modifier: public {class|interface|<type>} <name> ..."
257
258%keyword RETURN "return"
259%put RETURN summary
260"return [<expr>] ;"
261
262%keyword SHORT "short"
263%put SHORT summary
264"Integral primitive type (-32768 to 32767)"
265
266%keyword STATIC "static"
267%put STATIC summary
268"Declaration modifier: static {class|interface|<type>} <name> ..."
269
270%keyword STRICTFP "strictfp"
271%put STRICTFP summary
272"Declaration modifier: strictfp {class|interface|<type>} <name> ..."
273
274%keyword SUPER "super"
275
276%keyword SWITCH "switch"
277%put SWITCH summary
278"switch(<expr>) {[case <const-expr>: <stmts> ...] [default: <stmts>]}"
279
280
281%keyword SYNCHRONIZED "synchronized"
282%put SYNCHRONIZED summary
283"synchronized (<expr>) ... | Method decl. modifier: synchronized <type> <name> ..."
284
285%keyword THIS "this"
286
287%keyword THROW "throw"
288%put THROW summary
289"throw <expr> ;"
290
291%keyword THROWS "throws"
292%put THROWS summary
293"Method|Constructor declaration: throws <classType>, ..."
294
295%keyword TRANSIENT "transient"
296%put TRANSIENT summary
297"Field declaration modifier: transient <type> <name> ..."
298
299%keyword TRY "try"
300%put TRY summary
301"try {<stmts>} [catch(<parm>) {<stmts>} ...] [finally {<stmts>}]"
302
303%keyword VOID "void"
304%put VOID summary
305"Method return type: void <name> ..."
306
307%keyword VOLATILE "volatile"
308%put VOLATILE summary
309"Field declaration modifier: volatile <type> <name> ..."
310
311%keyword WHILE "while"
312%put WHILE summary
313"while (<expr>) <stmt> | do <stmt> while (<expr>);"
314
315;; --------------------------
316;; Official javadoc line tags
317;; --------------------------
318
319;; Javadoc tags are identified by a 'javadoc' keyword property. The
320;; value of this property must be itself a property list where the
321;; following properties are recognized:
322;;
323;; - `seq' (mandatory) is the tag sequence number used to check if tags
324;; are correctly ordered in a javadoc comment block.
325;;
326;; - `usage' (mandatory) is the list of token categories for which this
327;; documentation tag is allowed.
328;;
329;; - `opt' (optional) if non-nil indicates this is an optional tag.
330;; By default tags are mandatory.
331;;
332;; - `with-name' (optional) if non-nil indicates that this tag is
333;; followed by an identifier like in "@param <var-name> description"
334;; or "@exception <class-name> description".
335;;
336;; - `with-ref' (optional) if non-nil indicates that the tag is
337;; followed by a reference like in "@see <reference>".
338
339%keyword _AUTHOR "@author"
340%put _AUTHOR javadoc (seq 1 usage (type))
341%keyword _VERSION "@version"
342%put _VERSION javadoc (seq 2 usage (type))
343%keyword _PARAM "@param"
344%put _PARAM javadoc (seq 3 usage (function) with-name t)
345%keyword _RETURN "@return"
346%put _RETURN javadoc (seq 4 usage (function))
347%keyword _EXCEPTION "@exception"
348%put _EXCEPTION javadoc (seq 5 usage (function) with-name t)
349%keyword _THROWS "@throws"
350%put _THROWS javadoc (seq 6 usage (function) with-name t)
351%keyword _SEE "@see"
352%put _SEE javadoc (seq 7 usage (type function variable) opt t with-ref t)
353%keyword _SINCE "@since"
354%put _SINCE javadoc (seq 8 usage (type function variable) opt t)
355%keyword _SERIAL "@serial"
356%put _SERIAL javadoc (seq 9 usage (variable) opt t)
357%keyword _SERIALDATA "@serialData"
358%put _SERIALDATA javadoc (seq 10 usage (function) opt t)
359%keyword _SERIALFIELD "@serialField"
360%put _SERIALFIELD javadoc (seq 11 usage (variable) opt t)
361%keyword _DEPRECATED "@deprecated"
362%put _DEPRECATED javadoc (seq 12 usage (type function variable) opt t)
363
364%%
365
366;; ------------
367;; LALR Grammar
368;; ------------
369
370;; This grammar is not designed to fully parse correct Java syntax. It
371;; is optimized to work in an interactive environment to extract tokens
372;; (tags) needed by Semantic. In some cases a syntax not allowed by
373;; the Java Language Specification will be accepted by this grammar.
374
375compilation_unit
376 : package_declaration
377 | import_declaration
378 | type_declaration
379 ;
380
381;;; Package statement token
382;; ("NAME" package DETAIL "DOCSTRING")
383package_declaration
384 : PACKAGE qualified_name SEMICOLON
385 (PACKAGE-TAG $2 nil)
386 ;
387
388;;; Include file token
389;; ("FILE" include SYSTEM "DOCSTRING")
390import_declaration
391 : IMPORT qualified_name SEMICOLON
392 (INCLUDE-TAG $2 nil)
393 | IMPORT qualified_name DOT MULT SEMICOLON
394 (INCLUDE-TAG (concat $2 $3 $4) nil)
395 ;
396
397type_declaration
398 : SEMICOLON
399 ()
400 | class_declaration
401 | interface_declaration
402 ;
403
404;;; Type Declaration token
405;; ("NAME" type "TYPE" ( PART-LIST ) ( PARENTS ) EXTRA-SPEC "DOCSTRING")
406class_declaration
407 : modifiers_opt CLASS qualified_name superc_opt interfaces_opt class_body
408 (TYPE-TAG $3 $2 $6 (if (or $4 $5) (cons $4 $5)) :typemodifiers $1)
409 ;
410
411superc_opt
412 : ;;EMPTY
413 | EXTENDS qualified_name
414 (identity $2)
415 ;
416
417interfaces_opt
418 : ;;EMPTY
419 | IMPLEMENTS qualified_name_list
420 (nreverse $2)
421 ;
422
423class_body
424 : BRACE_BLOCK
425 (EXPANDFULL $1 class_member_declaration)
426 ;
427
428class_member_declaration
429 : LBRACE
430 ()
431 | RBRACE
432 ()
433 | block
434 ()
435 | static_initializer
436 ()
437 | constructor_declaration
438 | interface_declaration
439 | class_declaration
440 | method_declaration
441 | field_declaration
442 ;
443
444;;; Type Declaration token
445;; ("NAME" type "TYPE" ( PART-LIST ) ( PARENTS ) EXTRA-SPEC "DOCSTRING")
446interface_declaration
447 : modifiers_opt INTERFACE IDENTIFIER extends_interfaces_opt interface_body
448 (TYPE-TAG $3 $2 $5 (if $4 (cons nil $4)) :typemodifiers $1)
449 ;
450
451extends_interfaces_opt
452 : ;;EMPTY
453 | EXTENDS qualified_name_list
454 (identity $2)
455 ;
456
457interface_body
458 : BRACE_BLOCK
459 (EXPANDFULL $1 interface_member_declaration)
460 ;
461
462interface_member_declaration
463 : LBRACE
464 ()
465 | RBRACE
466 ()
467 | interface_declaration
468 | class_declaration
469 | method_declaration
470 | field_declaration
471 ;
472
473static_initializer
474 : STATIC block
475 ;
476
477;;; Function token
478;; ("NAME" function "TYPE" ( ARG-LIST ) EXTRA-SPEC "DOCSTRING")
479constructor_declaration
480 : modifiers_opt constructor_declarator throwsc_opt constructor_body
481 (FUNCTION-TAG (car $2) nil (cdr $2)
482 :typemodifiers $1
483 :throws $3
484 :constructor-flag t)
485 ;
486
487constructor_declarator
488 : IDENTIFIER formal_parameter_list
489 (cons $1 $2)
490 ;
491
492constructor_body
493 : block
494 ;
495
496;;; Function token
497;; ("NAME" function "TYPE" ( ARG-LIST ) EXTRA-SPEC "DOCSTRING")
498method_declaration
499 : modifiers_opt VOID method_declarator throwsc_opt method_body
500 (FUNCTION-TAG (car $3) $2 (cdr $3) :typemodifiers $1 :throws $4)
501 | modifiers_opt type method_declarator throwsc_opt method_body
502 (FUNCTION-TAG (car $3) $2 (cdr $3) :typemodifiers $1 :throws $4)
503 ;
504
505method_declarator
506 : IDENTIFIER formal_parameter_list dims_opt
507 (cons (concat $1 $3) $2)
508 ;
509
510throwsc_opt
511 : ;;EMPTY
512 | THROWS qualified_name_list
513 (nreverse $2)
514 ;
515
516qualified_name_list
517 : qualified_name_list COMMA qualified_name
518 (cons $3 $1)
519 | qualified_name
520 (list $1)
521 ;
522
523method_body
524 : SEMICOLON
525 | block
526 ;
527
528;; Just eat {...} block!
529block
530 : BRACE_BLOCK
531 ;
532
533formal_parameter_list
534 : PAREN_BLOCK
535 (EXPANDFULL $1 formal_parameters)
536 ;
537
538formal_parameters
539 : LPAREN
540 ()
541 | RPAREN
542 ()
543 | formal_parameter COMMA
544 | formal_parameter RPAREN
545 ;
546
547;;; Variable token
548;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING")
549formal_parameter
550 : formal_parameter_modifier_opt type variable_declarator_id
551 (VARIABLE-TAG $3 $2 nil :typemodifiers $1)
552 ;
553
554formal_parameter_modifier_opt
555 : ;;EMPTY
556 | FINAL
557 (list $1)
558 ;
559
560;;; Variable token
561;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING")
562field_declaration
563 : modifiers_opt type variable_declarators SEMICOLON
564 (VARIABLE-TAG $3 $2 nil :typemodifiers $1)
565 ;
566
567variable_declarators
568 : variable_declarators COMMA variable_declarator
569 (progn
570 ;; Set the end of the compound declaration to the end of the
571 ;; COMMA delimiter.
572 (setcdr (cdr (car $1)) (cdr $region2))
573 (cons $3 $1))
574 | variable_declarator
575 (list $1)
576 ;
577
578variable_declarator
579 : variable_declarator_id EQ variable_initializer
580 (cons $1 $region)
581 | variable_declarator_id
582 (cons $1 $region)
583 ;
584
585variable_declarator_id
586 : IDENTIFIER dims_opt
587 (concat $1 $2)
588 ;
589
590variable_initializer
591 : expression
592 ;
593
594;; Just eat expression!
595expression
596 : expression term
597 | term
598 ;
599
600term
601 : literal
602 | operator
603 | primitive_type
604 | IDENTIFIER
605 | BRACK_BLOCK
606 | PAREN_BLOCK
607 | BRACE_BLOCK
608 | NEW
609 | CLASS
610 | THIS
611 | SUPER
612 ;
613
614literal
615;; : NULL_LITERAL
616;; | BOOLEAN_LITERAL
617 : STRING_LITERAL
618 | NUMBER_LITERAL
619 ;
620
621operator
622 : NOT
623 | PLUS
624 | PLUSPLUS
625 | MINUS
626 | MINUSMINUS
627 | NOTEQ
628 | MOD
629 | MODEQ
630 | AND
631 | ANDAND
632 | ANDEQ
633 | MULT
634 | MULTEQ
635 | PLUSEQ
636 | MINUSEQ
637 | DOT
638 | DIV
639 | DIVEQ
640 | COLON
641 | LT
642 | LSHIFT
643 | LSHIFTEQ
644 | LTEQ
645 | EQ
646 | EQEQ
647 | GT
648 | GTEQ
649 | RSHIFT
650 | RSHIFTEQ
651 | URSHIFT
652 | URSHIFTEQ
653 | QUESTION
654 | XOR
655 | XOREQ
656 | OR
657 | OREQ
658 | OROR
659 | COMP
660 | INSTANCEOF
661 ;
662
663primitive_type
664 : BOOLEAN
665 | CHAR
666 | LONG
667 | INT
668 | SHORT
669 | BYTE
670 | DOUBLE
671 | FLOAT
672 ;
673
674modifiers_opt
675 : ;;EMPTY
676 | modifiers
677 (nreverse $1)
678 ;
679
680modifiers
681 : modifiers modifier
682 (cons $2 $1)
683 | modifier
684 (list $1)
685 ;
686
687modifier
688 : STRICTFP
689 | VOLATILE
690 | TRANSIENT
691 | SYNCHRONIZED
692 | NATIVE
693 | FINAL
694 | ABSTRACT
695 | STATIC
696 | PRIVATE
697 | PROTECTED
698 | PUBLIC
699 ;
700
701type
702 : qualified_name dims_opt
703 (concat $1 $2)
704 | primitive_type dims_opt
705 (concat $1 $2)
706 ;
707
708qualified_name
709 : qualified_name DOT IDENTIFIER
710 (concat $1 $2 $3)
711 | IDENTIFIER
712 ;
713
714dims_opt
715 : ;;EMPTY
716 (identity "")
717 | dims
718 ;
719
720dims
721 : dims BRACK_BLOCK
722 (concat $1 "[]")
723 | BRACK_BLOCK
724 (identity "[]")
725 ;
726
727%%
728;; Define the lexer for this grammar
729(define-lex wisent-java-tags-lexer
730 "Lexical analyzer that handles Java buffers.
731It ignores whitespaces, newlines and comments."
732 semantic-lex-ignore-whitespace
733 semantic-lex-ignore-newline
734 semantic-lex-ignore-comments
735 ;;;; Auto-generated analyzers.
736 wisent-java-tags-wy--<number>-regexp-analyzer
737 wisent-java-tags-wy--<string>-sexp-analyzer
738 ;; Must detect keywords before other symbols
739 wisent-java-tags-wy--<keyword>-keyword-analyzer
740 wisent-java-tags-wy--<symbol>-regexp-analyzer
741 wisent-java-tags-wy--<punctuation>-string-analyzer
742 wisent-java-tags-wy--<block>-block-analyzer
743 ;; In theory, Unicode chars should be turned into normal chars
744 ;; and then combined into regular ascii keywords and text. This
745 ;; analyzer just keeps these things from making the lexer go boom.
746 wisent-java-tags-wy--<unicode>-regexp-analyzer
747 ;;;;
748 semantic-lex-default-action)
749
750;;; java-tags.wy ends here
diff --git a/admin/grammars/js.wy b/admin/grammars/js.wy
new file mode 100644
index 00000000000..c6b3a58aac3
--- /dev/null
+++ b/admin/grammars/js.wy
@@ -0,0 +1,526 @@
1;;; javascript-jv.wy -- LALR grammar for Javascript
2
3;; Copyright (C) 2005-2012 Free Software Foundation, Inc.
4;; Copyright (C) 1998-2011 Ecma International.
5
6;; Author: Joakim Verona
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software: you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23;;; Commentary:
24
25;; The grammar itself is transcribed from the ECMAScript Language
26;; Specification published at
27;;
28;; http://www.ecma-international.org/publications/standards/Ecma-262.htm
29;;
30;; and redistributed under the following license:
31
32;; Redistribution and use in source and binary forms, with or without
33;; modification, are permitted provided that the following conditions
34;; are met:
35
36;; 1. Redistributions of source code must retain the above copyright
37;; notice, this list of conditions and the following disclaimer.
38
39;; 2. Redistributions in binary form must reproduce the above
40;; copyright notice, this list of conditions and the following
41;; disclaimer in the documentation and/or other materials provided
42;; with the distribution.
43
44;; 3. Neither the name of the authors nor Ecma International may be
45;; used to endorse or promote products derived from this software
46;; without specific prior written permission. THIS SOFTWARE IS
47;; PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR
48;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
49;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50;; ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR
51;; ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
52;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
53;; OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
54;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
55;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
56;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
57;; USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
58;; DAMAGE.
59
60%package wisent-javascript-jv-wy
61;; JAVE I prefere ecmascript-mode
62%languagemode ecmascript-mode javascript-mode
63
64;; The default goal
65%start Program
66;; Other Goals
67%start FormalParameterList
68
69;; with the terminals stuff, I used the javascript.y names,
70;; but the semantic/wisent/java-tags.wy types
71;; when possible
72;; ------------------
73;; Operator terminals
74;; ------------------
75
76;;define-lex-string-type-analyzer gets called with the "syntax" comment
77%type <punctuation> ;;syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string
78
79%token <punctuation> ASSIGN_SYMBOL "="
80%token <punctuation> BITWISE_AND "&"
81%token <punctuation> BITWISE_AND_EQUALS "&="
82%token <punctuation> BITWISE_EXCLUSIVE_OR "^"
83%token <punctuation> BITWISE_EXCLUSIVE_OR_EQUALS "^="
84%token <punctuation> BITWISE_OR "|"
85%token <punctuation> BITWISE_OR_EQUALS "|="
86%token <punctuation> BITWISE_SHIFT_LEFT "<<"
87%token <punctuation> BITWISE_SHIFT_LEFT_EQUALS "<<="
88%token <punctuation> BITWISE_SHIFT_RIGHT ">>"
89%token <punctuation> BITWISE_SHIFT_RIGHT_EQUALS ">>="
90%token <punctuation> BITWISE_SHIFT_RIGHT_ZERO_FILL ">>>"
91%token <punctuation> BITWISE_SHIFT_RIGHT_ZERO_FILL_EQUALS ">>>="
92%token <punctuation> NOT_EQUAL "!="
93%token <punctuation> DIV_EQUALS "/="
94%token <punctuation> EQUALS "=="
95%token <punctuation> GREATER_THAN ">"
96%token <punctuation> GT_EQUAL ">="
97%token <punctuation> LOGICAL_AND "&&"
98%token <punctuation> LOGICAL_OR "||"
99%token <punctuation> LOGICAL_NOT "!!"
100%token <punctuation> LS_EQUAL "<="
101%token <punctuation> MINUS "-"
102%token <punctuation> MINUS_EQUALS "-="
103%token <punctuation> MOD "%"
104%token <punctuation> MOD_EQUALS "%="
105%token <punctuation> MULTIPLY "*"
106%token <punctuation> MULTIPLY_EQUALS "*="
107%token <punctuation> PLUS "+"
108%token <punctuation> PLUS_EQUALS "+="
109%token <punctuation> INCREMENT "++"
110%token <punctuation> DECREMENT "--"
111%token <punctuation> DIV "/"
112%token <punctuation> COLON ":"
113%token <punctuation> COMMA ","
114%token <punctuation> DOT "."
115%token <punctuation> LESS_THAN "<"
116%token <punctuation> LINE_TERMINATOR "\n"
117%token <punctuation> SEMICOLON ";"
118%token <punctuation> ONES_COMPLIMENT "~"
119
120
121;; -----------------------------
122;; Block & Parenthesis terminals
123;; -----------------------------
124%type <block> ;;syntax "\\s(\\|\\s)" matchdatatype block
125%token <block> PAREN_BLOCK "(OPEN_PARENTHESIS CLOSE_PARENTHESIS)"
126%token <block> BRACE_BLOCK "(START_BLOCK END_BLOCK)"
127%token <block> BRACK_BLOCK "(OPEN_SQ_BRACKETS CLOSE_SQ_BRACKETS)"
128
129%token <open-paren> OPEN_PARENTHESIS "("
130%token <close-paren> CLOSE_PARENTHESIS ")"
131
132%token <open-paren> START_BLOCK "{"
133%token <close-paren> END_BLOCK "}"
134
135%token <open-paren> OPEN_SQ_BRACKETS "["
136%token <close-paren> CLOSE_SQ_BRACKETS "]"
137
138
139;; -----------------
140;; Keyword terminals
141;; -----------------
142
143;; Generate a keyword analyzer
144%type <keyword> ;;syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword
145
146%keyword IF "if"
147%put IF summary
148"if (<expr>) <stmt> [else <stmt>] (jv)"
149
150%keyword BREAK "break"
151%put BREAK summary
152"break [<label>] ;"
153
154%keyword CONTINUE "continue"
155%put CONTINUE summary
156"continue [<label>] ;"
157
158%keyword ELSE "else"
159%put ELSE summary
160"if (<expr>) <stmt> else <stmt>"
161
162
163%keyword FOR "for"
164%put FOR summary
165"for ([<init-expr>]; [<expr>]; [<update-expr>]) <stmt>"
166
167
168%keyword FUNCTION "function"
169%put FUNCTION summary
170"function declaration blah blah"
171
172%keyword THIS "this"
173%put THIS summary
174"this"
175
176
177%keyword RETURN "return"
178%put RETURN summary
179"return [<expr>] ;"
180
181%keyword WHILE "while"
182%put WHILE summary
183"while (<expr>) <stmt> | do <stmt> while (<expr>);"
184
185%keyword VOID_SYMBOL "void"
186%put VOID_SYMBOL summary
187"Method return type: void <name> ..."
188
189
190
191%keyword NEW "new"
192%put NEW summary
193"new <objecttype> - Creates a new object."
194
195%keyword DELETE "delete"
196%put DELETE summary
197"delete(<objectreference>) - Deletes the object."
198
199%keyword VAR "var"
200%put VAR summary
201"var <variablename> [= value];"
202
203%keyword WITH "with"
204%put WITH summary
205"with "
206
207%keyword TYPEOF "typeof"
208%put TYPEOF summary
209"typeof "
210
211%keyword IN "in"
212%put IN summary
213"in something"
214
215
216;; -----------------
217;; Literal terminals
218;; -----------------
219
220;;the .y file uses VARIABLE as IDENTIFIER, which seems a bit evil
221;; it think the normal .wy convention is better than this
222%type <symbol> ;;syntax "\\(\\sw\\|\\s_\\)+"
223%token <symbol> VARIABLE
224
225%type <string> ;;syntax "\\s\"" matchdatatype sexp
226%token <string> STRING
227
228%type <number> ;;syntax semantic-lex-number-expression
229%token <number> NUMBER
230
231
232%token FALSE
233%token TRUE
234%token QUERY
235
236
237%token NULL_TOKEN
238
239;;%token UNDEFINED_TOKEN
240;;%token INFINITY
241
242;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
243;; associativity and stuff
244%left PLUS MINUS
245%left MULTIPLY DIV MOD
246
247%nonassoc FALSE
248%nonassoc HIGHER_THAN_FALSE
249%nonassoc ELSE
250%nonassoc LOWER_THAN_CLOSE_PARENTHESIS
251%nonassoc CLOSE_PARENTHESIS
252
253%%
254
255Program : SourceElement
256 ;
257
258SourceElement : Statement
259 | FunctionDeclaration
260 ;
261
262Statement : Block
263 | VariableStatement
264 | EmptyStatement
265 | ExpressionStatement
266 | IfStatement
267 | IterationExpression
268 | ContinueStatement
269 | BreakStatement
270 | ReturnStatement
271 | WithStatement
272 ;
273
274FunctionDeclaration : FUNCTION VARIABLE FormalParameterListBlock Block
275 (FUNCTION-TAG $2 nil $3)
276 ;
277
278FormalParameterListBlock : PAREN_BLOCK
279 (EXPANDFULL $1 FormalParameterList)
280 ;
281
282FormalParameterList: OPEN_PARENTHESIS
283 ()
284 | VARIABLE
285 (VARIABLE-TAG $1 nil nil)
286 | CLOSE_PARENTHESIS
287 ()
288 | COMMA
289 ()
290 ;
291
292StatementList : Statement
293 | StatementList Statement
294 ;
295
296Block : BRACE_BLOCK
297 ;; If you want to parse the body of the function
298 ;; ( EXPANDFULL $1 BlockExpand )
299 ;
300
301BlockExpand: START_BLOCK StatementList END_BLOCK
302 | START_BLOCK END_BLOCK
303 ;
304
305VariableStatement : VAR VariableDeclarationList SEMICOLON
306 (VARIABLE-TAG $2 nil nil)
307 ;
308
309VariableDeclarationList : VariableDeclaration
310 (list $1)
311 | VariableDeclarationList COMMA VariableDeclaration
312 (append $1 (list $3))
313 ;
314
315VariableDeclaration : VARIABLE
316 (append (list $1 nil) $region)
317 | VARIABLE Initializer
318 (append (cons $1 $2) $region)
319 ;
320
321Initializer : ASSIGN_SYMBOL AssignmentExpression
322 (list $2)
323 ;
324
325EmptyStatement : SEMICOLON
326 ;
327
328ExpressionStatement : Expression SEMICOLON
329 ;
330
331IfStatement : IF OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS Statement %prec HIGHER_THAN_FALSE
332 | IF OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS Statement ELSE Statement
333 | IF OPEN_PARENTHESIS FALSE CLOSE_PARENTHESIS Statement
334 | IF OPEN_PARENTHESIS LeftHandSideExpression AssignmentOperator AssignmentExpression CLOSE_PARENTHESIS Statement
335 ;
336
337IterationExpression : WHILE OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS Statement %prec HIGHER_THAN_FALSE
338 | WHILE OPEN_PARENTHESIS FALSE CLOSE_PARENTHESIS Statement
339 | WHILE OPEN_PARENTHESIS LeftHandSideExpression AssignmentOperator AssignmentExpression CLOSE_PARENTHESIS Statement
340 | FOR OPEN_PARENTHESIS OptionalExpression SEMICOLON OptionalExpression SEMICOLON OptionalExpression CLOSE_PARENTHESIS Statement
341 | FOR OPEN_PARENTHESIS VAR VariableDeclarationList SEMICOLON OptionalExpression SEMICOLON OptionalExpression CLOSE_PARENTHESIS Statement
342 | FOR OPEN_PARENTHESIS LeftHandSideExpression IN Expression CLOSE_PARENTHESIS Statement
343 | FOR OPEN_PARENTHESIS VAR VARIABLE OptionalInitializer IN Expression CLOSE_PARENTHESIS Statement
344 ;
345
346ContinueStatement : CONTINUE SEMICOLON
347 ;
348
349;;JAVE break needs labels
350BreakStatement : BREAK SEMICOLON
351 ;; | BREAK identifier SEMICOLON
352 ;
353
354ReturnStatement : RETURN Expression SEMICOLON
355 | RETURN SEMICOLON
356 ;
357
358WithStatement : WITH OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS Statement
359 ;
360
361OptionalInitializer : Initializer
362 |
363 ;
364
365PrimaryExpression : THIS
366 | VARIABLE
367 | NUMBER
368 | STRING
369 | NULL_TOKEN
370 | TRUE
371 | FALSE
372 | OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS
373 ;
374
375MemberExpression : PrimaryExpression
376 | MemberExpression OPEN_SQ_BRACKETS Expression CLOSE_SQ_BRACKETS
377 | MemberExpression DOT VARIABLE
378 | NEW MemberExpression Arguments
379 ;
380
381NewExpression : MemberExpression
382 | NEW NewExpression
383 ;
384
385CallExpression : MemberExpression Arguments
386 | CallExpression Arguments
387 | CallExpression OPEN_SQ_BRACKETS Expression CLOSE_SQ_BRACKETS
388 | CallExpression DOT VARIABLE
389 ;
390
391Arguments : OPEN_PARENTHESIS CLOSE_PARENTHESIS
392 | OPEN_PARENTHESIS ArgumentList CLOSE_PARENTHESIS
393 ;
394
395ArgumentList : AssignmentExpression
396 | ArgumentList COMMA AssignmentExpression
397 ;
398
399LeftHandSideExpression : NewExpression
400 | CallExpression
401 ;
402
403PostfixExpression : LeftHandSideExpression
404 | LeftHandSideExpression INCREMENT
405 | LeftHandSideExpression DECREMENT
406 ;
407
408UnaryExpression : PostfixExpression
409 | DELETE UnaryExpression
410 | VOID_SYMBOL UnaryExpression
411 | TYPEOF UnaryExpression
412 | INCREMENT UnaryExpression
413 | DECREMENT UnaryExpression
414 | PLUS UnaryExpression
415 | MINUS UnaryExpression
416 | ONES_COMPLIMENT UnaryExpression
417 | LOGICAL_NOT UnaryExpression
418 ;
419
420MultiplicativeExpression : UnaryExpression
421 | MultiplicativeExpression MULTIPLY UnaryExpression
422 | MultiplicativeExpression DIV UnaryExpression
423 | MultiplicativeExpression MOD UnaryExpression
424 ;
425
426AdditiveExpression : MultiplicativeExpression
427 | AdditiveExpression PLUS MultiplicativeExpression
428 | AdditiveExpression MINUS MultiplicativeExpression
429 ;
430
431ShiftExpression : AdditiveExpression
432 | ShiftExpression BITWISE_SHIFT_LEFT AdditiveExpression
433 | ShiftExpression BITWISE_SHIFT_RIGHT AdditiveExpression
434 | ShiftExpression BITWISE_SHIFT_RIGHT_ZERO_FILL AdditiveExpression
435 ;
436
437RelationalExpression : ShiftExpression
438 | RelationalExpression LESS_THAN ShiftExpression
439 | RelationalExpression GREATER_THAN ShiftExpression
440 | RelationalExpression LS_EQUAL ShiftExpression
441 | RelationalExpression GT_EQUAL ShiftExpression
442 ;
443
444EqualityExpression : RelationalExpression
445 | EqualityExpression EQUALS RelationalExpression
446 | EqualityExpression NOT_EQUAL RelationalExpression
447 ;
448
449BitwiseANDExpression : EqualityExpression
450 | BitwiseANDExpression BITWISE_AND EqualityExpression
451 ;
452
453BitwiseXORExpression : BitwiseANDExpression
454 | BitwiseXORExpression BITWISE_EXCLUSIVE_OR BitwiseANDExpression
455 ;
456
457BitwiseORExpression : BitwiseXORExpression
458 | BitwiseORExpression BITWISE_OR BitwiseXORExpression
459 ;
460
461LogicalANDExpression : BitwiseORExpression
462 | LogicalANDExpression LOGICAL_AND BitwiseORExpression
463 ;
464
465LogicalORExpression : LogicalANDExpression
466 | LogicalORExpression LOGICAL_OR LogicalANDExpression
467 ;
468
469ConditionalExpression : LogicalORExpression
470 | LogicalORExpression QUERY AssignmentExpression COLON AssignmentExpression
471 ;
472
473AssignmentExpression : ConditionalExpression
474 | LeftHandSideExpression AssignmentOperator AssignmentExpression %prec LOWER_THAN_CLOSE_PARENTHESIS
475 ;
476
477AssignmentOperator : ASSIGN_SYMBOL
478 | MULTIPLY_EQUALS
479 | DIV_EQUALS
480 | MOD_EQUALS
481 | PLUS_EQUALS
482 | MINUS_EQUALS
483 | BITWISE_SHIFT_LEFT_EQUALS
484 | BITWISE_SHIFT_RIGHT_EQUALS
485 | BITWISE_SHIFT_RIGHT_ZERO_FILL_EQUALS
486 | BITWISE_AND_EQUALS
487 | BITWISE_EXCLUSIVE_OR_EQUALS
488 | BITWISE_OR_EQUALS
489 ;
490
491Expression : AssignmentExpression
492 | Expression COMMA AssignmentExpression
493 ;
494
495OptionalExpression : Expression
496 |
497 ;
498
499%%
500
501;;here something like:
502;;(define-lex wisent-java-tags-lexer
503;; should go
504(define-lex javascript-lexer-jv
505"javascript thingy"
506;;std stuff
507 semantic-lex-ignore-whitespace
508 semantic-lex-ignore-newline
509 semantic-lex-ignore-comments
510
511 ;;stuff generated from the wy file(one for each "type" declaration)
512 wisent-javascript-jv-wy--<number>-regexp-analyzer
513 wisent-javascript-jv-wy--<string>-sexp-analyzer
514
515 wisent-javascript-jv-wy--<keyword>-keyword-analyzer
516
517 wisent-javascript-jv-wy--<symbol>-regexp-analyzer
518 wisent-javascript-jv-wy--<punctuation>-string-analyzer
519 wisent-javascript-jv-wy--<block>-block-analyzer
520
521
522 ;;;;more std stuff
523 semantic-lex-default-action
524 )
525
526;;; javascript-jv.wy ends here
diff --git a/admin/grammars/make.by b/admin/grammars/make.by
new file mode 100644
index 00000000000..ee933805cf6
--- /dev/null
+++ b/admin/grammars/make.by
@@ -0,0 +1,168 @@
1;;; make.by -- BY notation for Makefiles.
2
3;; Copyright (C) 1999-2012 Free Software Foundation, Inc.
4;;
5;; Author: Eric M. Ludlam <zappo@gnu.org>
6;; David Ponce <david@dponce.com>
7;; Klaus Berndl <klaus.berndl@sdm.de>
8;;
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software: you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24%package semantic-make-by
25
26%languagemode makefile-mode
27%start Makefile
28
29;; This was always a test case.
30%quotemode backquote
31
32%token IF "if"
33%token IFDEF "ifdef"
34%token IFNDEF "ifndef"
35%token IFEQ "ifeq"
36%token IFNEQ "ifneq"
37%token ELSE "else"
38%token ENDIF "endif"
39%token INCLUDE "include"
40
41%put { IF ELSE ENDIF } summary "Conditional: if (expression) ... else ... endif"
42%put IFDEF summary "Conditional: ifdef (expression) ... else ... endif"
43%put IFNDEF summary "Conditional: ifndef (expression) ... else ... endif"
44%put IFEQ summary "Conditional: ifeq (expression) ... else ... endif"
45%put IFNEQ summary "Conditional: ifneq (expression) ... else ... endif"
46%put INCLUDE summary "Macro: include filename1 filename2 ..."
47
48%token <punctuation> COLON "\\`[:]\\'"
49%token <punctuation> PLUS "\\`[+]\\'"
50%token <punctuation> EQUAL "\\`[=]\\'"
51%token <punctuation> DOLLAR "\\`[$]\\'"
52%token <punctuation> BACKSLASH "\\`[\\]\\'"
53
54%%
55
56Makefile : bol newline (nil)
57 | bol variable
58 ( ,@$2 )
59 | bol rule
60 ( ,@$2 )
61 | bol conditional
62 ( ,@$2 )
63 | bol include
64 ( ,@$2 )
65 | whitespace ( nil )
66 | newline ( nil )
67 ;
68
69variable: symbol opt-whitespace equals opt-whitespace element-list
70 (VARIABLE-TAG ,$1 nil ,$5)
71 ;
72
73rule: targets opt-whitespace colons opt-whitespace element-list commands
74 (FUNCTION-TAG ,$1 nil ,$5)
75 ;
76
77targets: target opt-whitespace targets
78 ( (car ,$1) (car ,@$3) )
79 | target
80 ( (car ,$1) )
81 ;
82
83target: sub-target target
84 ( (concat (car ,$1) (car ,@$3) ) )
85 | sub-target
86 ( (car ,$1) )
87 ;
88
89sub-target: symbol
90 | string
91 | varref
92 ;
93
94conditional: IF some-whitespace symbol newline
95 ( nil )
96 | IFDEF some-whitespace symbol newline
97 ( nil )
98 | IFNDEF some-whitespace symbol newline
99 ( nil )
100 | IFEQ some-whitespace expression newline
101 ( nil )
102 | IFNEQ some-whitespace expression newline
103 ( nil )
104 | ELSE newline
105 ( nil )
106 | ENDIF newline
107 ( nil )
108 ;
109
110expression : semantic-list
111 ;
112
113include: INCLUDE some-whitespace element-list
114 (INCLUDE-TAG ,$3 nil)
115 ;
116
117equals: COLON EQUAL ()
118 | PLUS EQUAL ()
119 | EQUAL ()
120 ;
121
122colons: COLON COLON ()
123 | COLON ()
124 ;
125
126element-list: elements newline
127 ( ,@$1 )
128 ;
129
130elements: element some-whitespace elements
131 ( ,@$1 ,@$3 )
132 | element
133 ( ,@$1 )
134 | ;;EMPTY
135 ;
136
137element: sub-element element
138 ( (concat (car ,$1) (car ,$2)) )
139 | ;;EMPTY
140 ;
141
142sub-element: symbol
143 | string
144 | punctuation
145 | semantic-list
146 ( (buffer-substring-no-properties
147 (identity start) (identity end)) )
148 ;
149
150varref: DOLLAR semantic-list
151 ( (buffer-substring-no-properties (identity start) (identity end)) )
152 ;
153
154commands: bol shell-command newline commands
155 ( ,$1 ,@$2 )
156 | ;;EMPTY
157 ( )
158 ;
159
160opt-whitespace : some-whitespace ( nil )
161 | ;;EMPTY
162 ;
163
164some-whitespace : whitespace some-whitespace (nil)
165 | whitespace (nil)
166 ;
167
168;;; make.by ends here
diff --git a/admin/grammars/python.wy b/admin/grammars/python.wy
new file mode 100644
index 00000000000..f7808fd20b8
--- /dev/null
+++ b/admin/grammars/python.wy
@@ -0,0 +1,1133 @@
1;;; python.wy -- LALR grammar for Python
2
3;; Copyright (C) 2002-2012 Free Software Foundation, Inc.
4;; Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
5;; 2009, 2010 Python Software Foundation; All Rights Reserved
6
7;; Author: Richard Kim <ryk@dspwiz.com>
8;; Maintainer: Richard Kim <ryk@dspwiz.com>
9;; Created: June 2002
10;; Keywords: syntax
11;;
12;; This file is part of GNU Emacs.
13
14;; GNU Emacs is free software: you can redistribute it and/or modify
15;; it under the terms of the GNU General Public License as published by
16;; the Free Software Foundation, either version 3 of the License, or
17;; (at your option) any later version.
18
19;; GNU Emacs is distributed in the hope that it will be useful,
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. If not, see <http://www.gnu.org/licenses/>.
26
27;;; Commentary:
28;;
29;; This is an LALR python parser that follows the official python
30;; grammar closely with very few exceptions. The Python grammar is
31;; used and reproduced under the following license:
32;;
33;; PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
34;; --------------------------------------------
35;; 1. This LICENSE AGREEMENT is between the Python Software Foundation
36;; ("PSF"), and the Individual or Organization ("Licensee") accessing
37;; and otherwise using this software ("Python") in source or binary
38;; form and its associated documentation.
39;;
40;; 2. Subject to the terms and conditions of this License Agreement,
41;; PSF hereby grants Licensee a nonexclusive, royalty-free, world-wide
42;; license to reproduce, analyze, test, perform and/or display
43;; publicly, prepare derivative works, distribute, and otherwise use
44;; Python alone or in any derivative version, provided, however, that
45;; PSF's License Agreement and PSF's notice of copyright, i.e.,
46;; "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
47;; 2009, 2010 Python Software Foundation; All Rights Reserved" are
48;; retained in Python alone or in any derivative version prepared by
49;; Licensee.
50;;
51;; 3. In the event Licensee prepares a derivative work that is based
52;; on or incorporates Python or any part thereof, and wants to make
53;; the derivative work available to others as provided herein, then
54;; Licensee hereby agrees to include in any such work a brief summary
55;; of the changes made to Python.
56;;
57;; 4. PSF is making Python available to Licensee on an "AS IS"
58;; basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
59;; IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
60;; DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
61;; FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
62;; INFRINGE ANY THIRD PARTY RIGHTS.
63;;
64;; 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
65;; FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A
66;; RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, OR
67;; ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
68;;
69;; 6. This License Agreement will automatically terminate upon a
70;; material breach of its terms and conditions.
71;;
72;; 7. Nothing in this License Agreement shall be deemed to create any
73;; relationship of agency, partnership, or joint venture between PSF
74;; and Licensee. This License Agreement does not grant permission to
75;; use PSF trademarks or trade name in a trademark sense to endorse or
76;; promote products or services of Licensee, or any third party.
77;;
78;; 8. By copying, installing or otherwise using Python, Licensee
79;; agrees to be bound by the terms and conditions of this License
80;; Agreement.
81
82;;; To do:
83;;
84;; * Verify that semantic-lex-python-number regexp is correct.
85
86;; --------
87;; Settings
88;; --------
89
90%package wisent-python-wy
91
92%languagemode python-mode
93
94;; The default start symbol
95%start goal
96;; Alternate entry points
97;; - Needed by partial re-parse
98%start function_parameter
99%start paren_class
100%start indented_block
101;; - Needed by EXPANDFULL clauses
102%start function_parameters
103%start paren_classes
104%start indented_block_body
105
106;; -------------------------------
107;; Misc. Python specific terminals
108;; -------------------------------
109;; The value of these tokens are for documentation only, they are not
110;; used by the lexer.
111%token <charquote> BACKSLASH "\\"
112%token <newline> NEWLINE "\n"
113%token <indentation> INDENT "^\\s-+"
114%token <indentation> DEDENT "[^:INDENT:]"
115%token <indentation> INDENT_BLOCK "(INDENT DEDENT)"
116
117;; -----------------------------
118;; Block & Parenthesis terminals
119;; -----------------------------
120%type <block> ;;syntax "\\s(\\|\\s)" matchdatatype block
121
122%token <block> PAREN_BLOCK "(LPAREN RPAREN)"
123%token <block> BRACE_BLOCK "(LBRACE RBRACE)"
124%token <block> BRACK_BLOCK "(LBRACK RBRACK)"
125
126%token <open-paren> LPAREN "("
127%token <close-paren> RPAREN ")"
128%token <open-paren> LBRACE "{"
129%token <close-paren> RBRACE "}"
130%token <open-paren> LBRACK "["
131%token <close-paren> RBRACK "]"
132
133;; ------------------
134;; Operator terminals
135;; ------------------
136%type <punctuation> ;;syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string
137
138%token <punctuation> LTLTEQ "<<="
139%token <punctuation> GTGTEQ ">>="
140%token <punctuation> EXPEQ "**="
141%token <punctuation> DIVDIVEQ "//="
142%token <punctuation> DIVDIV "//"
143%token <punctuation> LTLT "<<"
144%token <punctuation> GTGT ">>"
145%token <punctuation> EXPONENT "**"
146%token <punctuation> EQ "=="
147%token <punctuation> GE ">="
148%token <punctuation> LE "<="
149%token <punctuation> PLUSEQ "+="
150%token <punctuation> MINUSEQ "-="
151%token <punctuation> MULTEQ "*="
152%token <punctuation> DIVEQ "/="
153%token <punctuation> MODEQ "%="
154%token <punctuation> AMPEQ "&="
155%token <punctuation> OREQ "|="
156%token <punctuation> HATEQ "^="
157%token <punctuation> LTGT "<>"
158%token <punctuation> NE "!="
159%token <punctuation> HAT "^"
160%token <punctuation> LT "<"
161%token <punctuation> GT ">"
162%token <punctuation> AMP "&"
163%token <punctuation> MULT "*"
164%token <punctuation> DIV "/"
165%token <punctuation> MOD "%"
166%token <punctuation> PLUS "+"
167%token <punctuation> MINUS "-"
168%token <punctuation> PERIOD "."
169%token <punctuation> TILDE "~"
170%token <punctuation> BAR "|"
171%token <punctuation> COLON ":"
172%token <punctuation> SEMICOLON ";"
173%token <punctuation> COMMA ","
174%token <punctuation> ASSIGN "="
175%token <punctuation> BACKQUOTE "`"
176
177
178;; -----------------
179;; Literal terminals
180;; -----------------
181%token <string> STRING_LITERAL
182
183%type <number> ;;syntax semantic-lex-number-expression
184%token <number> NUMBER_LITERAL
185
186%type <symbol> ;;syntax "\\(\\sw\\|\\s_\\)+"
187%token <symbol> NAME
188
189;; -----------------
190;; Keyword terminals
191;; -----------------
192%type <keyword> ;;syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword
193
194%keyword AND "and"
195%put AND summary
196"Logical AND binary operator ... "
197
198%keyword AS "as"
199%put AS summary
200"EXPR as NAME makes value of EXPR available as variable NAME"
201
202%keyword ASSERT "assert"
203%put ASSERT summary
204"Raise AssertionError exception if <expr> is false"
205
206%keyword BREAK "break"
207%put BREAK summary
208"Terminate 'for' or 'while' loop"
209
210%keyword CLASS "class"
211%put CLASS summary
212"Define a new class"
213
214%keyword CONTINUE "continue"
215%put CONTINUE summary
216"Skip to the next iteration of enclosing 'for' or 'while' loop"
217
218%keyword DEF "def"
219%put DEF summary
220"Define a new function"
221
222%keyword DEL "del"
223%put DEL summary
224"Delete specified objects, i.e., undo what assignment did"
225
226%keyword ELIF "elif"
227%put ELIF summary
228"Shorthand for 'else if' following an 'if' statement"
229
230%keyword ELSE "else"
231%put ELSE summary
232"Start the 'else' clause following an 'if' statement"
233
234%keyword EXCEPT "except"
235%put EXCEPT summary
236"Specify exception handlers along with 'try' keyword"
237
238%keyword EXEC "exec"
239%put EXEC summary
240"Dynamically execute Python code"
241
242%keyword FINALLY "finally"
243%put FINALLY summary
244"Specify code to be executed after 'try' statements whether or not an exception occurred"
245
246%keyword FOR "for"
247%put FOR summary
248"Start a 'for' loop"
249
250%keyword FROM "from"
251%put FROM summary
252"Modify behavior of 'import' statement"
253
254%keyword GLOBAL "global"
255%put GLOBAL summary
256"Declare one or more symbols as global symbols"
257
258%keyword IF "if"
259%put IF summary
260"Start 'if' conditional statement"
261
262%keyword IMPORT "import"
263%put IMPORT summary
264"Load specified modules"
265
266%keyword IN "in"
267%put IN summary
268"Part of 'for' statement "
269
270%keyword IS "is"
271%put IS summary
272"Binary operator that tests for object equality"
273
274%keyword LAMBDA "lambda"
275%put LAMBDA summary
276"Create anonymous function"
277
278%keyword NOT "not"
279%put NOT summary
280"Unary boolean negation operator"
281
282%keyword OR "or"
283%put OR summary
284"Binary logical 'or' operator"
285
286%keyword PASS "pass"
287%put PASS summary
288"Statement that does nothing"
289
290%keyword PRINT "print"
291%put PRINT summary
292"Print each argument to standard output"
293
294%keyword RAISE "raise"
295%put RAISE summary
296"Raise an exception"
297
298%keyword RETURN "return"
299%put RETURN summary
300"Return from a function"
301
302%keyword TRY "try"
303%put TRY summary
304"Start of statements protected by exception handlers"
305
306%keyword WHILE "while"
307%put WHILE summary
308"Start a 'while' loop"
309
310%keyword YIELD "yield"
311%put YIELD summary
312"Create a generator function"
313
314%%
315
316;;;****************************************************************************
317;;;@ goal
318;;;****************************************************************************
319
320;; simple_stmt are statements that do not involve INDENT tokens
321;; compound_stmt are statements that involve INDENT tokens
322goal
323 : NEWLINE
324 | simple_stmt
325 | compound_stmt
326 ;
327
328;;;****************************************************************************
329;;;@ simple_stmt
330;;;****************************************************************************
331
332;; simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
333simple_stmt
334 : small_stmt_list semicolon_opt NEWLINE
335 ;
336
337;; small_stmt (';' small_stmt)*
338small_stmt_list
339 : small_stmt
340 | small_stmt_list SEMICOLON small_stmt
341 ;
342
343small_stmt
344 : expr_stmt
345 | print_stmt
346 | del_stmt
347 | pass_stmt
348 | flow_stmt
349 | import_stmt
350 | global_stmt
351 | exec_stmt
352 | assert_stmt
353 ;
354
355;;;============================================================================
356;;;@@ print_stmt
357;;;============================================================================
358
359;; print_stmt: 'print' [ test (',' test)* [','] ]
360;; | '>>' test [ (',' test)+ [','] ]
361print_stmt
362 : PRINT print_stmt_trailer
363 (CODE-TAG $1 nil)
364 ;
365
366;; [ test (',' test)* [','] ] | '>>' test [ (',' test)+ [','] ]
367print_stmt_trailer
368 : test_list_opt
369 ()
370 | GTGT test trailing_test_list_with_opt_comma_opt
371 ()
372 ;
373
374;; [ (',' test)+ [','] ]
375trailing_test_list_with_opt_comma_opt
376 : ;;EMPTY
377 | trailing_test_list comma_opt
378 ()
379 ;
380
381;; (',' test)+
382trailing_test_list
383 : COMMA test
384 ()
385 | trailing_test_list COMMA test
386 ()
387 ;
388
389;;;============================================================================
390;;;@@ expr_stmt
391;;;============================================================================
392
393;; expr_stmt: testlist (augassign testlist | ('=' testlist)*)
394expr_stmt
395 : testlist expr_stmt_trailer
396 (if (and $2 (stringp $1) (string-match "^\\(\\sw\\|\\s_\\)+$" $1))
397 ;; If this is an assignment statement and left side is a symbol,
398 ;; then generate a 'variable token, else return 'code token.
399 (VARIABLE-TAG $1 nil nil)
400 (CODE-TAG $1 nil))
401 ;
402
403;; Could be EMPTY because of eq_testlist_zom.
404;; (augassign testlist | ('=' testlist)*)
405expr_stmt_trailer
406 : augassign testlist
407 | eq_testlist_zom
408 ;
409
410;; Could be EMPTY!
411;; ('=' testlist)*
412eq_testlist_zom
413 : ;;EMPTY
414 | eq_testlist_zom ASSIGN testlist
415 (identity $3)
416 ;
417
418;; augassign: '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^='
419;; | '<<=' | '>>=' | '**=' | '//='
420augassign
421 : PLUSEQ | MINUSEQ | MULTEQ | DIVEQ | MODEQ
422 | AMPEQ | OREQ | HATEQ | LTLTEQ
423 | GTGTEQ | EXPEQ | DIVDIVEQ
424 ;
425
426;;;============================================================================
427;;;@@ del_stmt
428;;;============================================================================
429
430;; del_stmt: 'del' exprlist
431del_stmt
432 : DEL exprlist
433 (CODE-TAG $1 nil)
434 ;
435
436;; exprlist: expr (',' expr)* [',']
437exprlist
438 : expr_list comma_opt
439 ()
440 ;
441
442;; expr (',' expr)*
443expr_list
444 : expr
445 ()
446 | expr_list COMMA expr
447 ()
448 ;
449
450;;;============================================================================
451;;;@@ pass_stmt
452;;;============================================================================
453
454;; pass_stmt: 'pass'
455pass_stmt
456 : PASS
457 (CODE-TAG $1 nil)
458 ;
459
460;;;============================================================================
461;;;@@ flow_stmt
462;;;============================================================================
463
464flow_stmt
465 : break_stmt
466 | continue_stmt
467 | return_stmt
468 | raise_stmt
469 | yield_stmt
470 ;
471
472;; break_stmt: 'break'
473break_stmt
474 : BREAK
475 (CODE-TAG $1 nil)
476 ;
477
478;; continue_stmt: 'continue'
479continue_stmt
480 : CONTINUE
481 (CODE-TAG $1 nil)
482 ;
483
484;; return_stmt: 'return' [testlist]
485return_stmt
486 : RETURN testlist_opt
487 (CODE-TAG $1 nil)
488 ;
489
490;; [testlist]
491testlist_opt
492 : ;;EMPTY
493 | testlist
494 ()
495 ;
496
497;; yield_stmt: 'yield' testlist
498yield_stmt
499 : YIELD
500 (CODE-TAG $1 nil)
501 | YIELD testlist
502 (CODE-TAG $1 nil)
503 ;
504
505;; raise_stmt: 'raise' [test [',' test [',' test]]]
506raise_stmt
507 : RAISE zero_one_two_or_three_tests
508 (CODE-TAG $1 nil)
509 ;
510
511;; [test [',' test [',' test]]]
512zero_one_two_or_three_tests
513 : ;;EMPTY
514 | test zero_one_or_two_tests
515 ()
516 ;
517
518;; [',' test [',' test]]
519zero_one_or_two_tests
520 : ;;EMPTY
521 | COMMA test zero_or_one_comma_test
522 ()
523 ;
524
525;; [',' test]
526zero_or_one_comma_test
527 : ;;EMPTY
528 | COMMA test
529 ()
530 ;
531
532;;;============================================================================
533;;;@@ import_stmt
534;;;============================================================================
535
536;; import_stmt : 'import' dotted_as_name (',' dotted_as_name)*
537;; | 'from' dotted_name 'import'
538;; ('*' | import_as_name (',' import_as_name)*)
539import_stmt
540 : IMPORT dotted_as_name_list
541 (INCLUDE-TAG $2 nil)
542 | FROM dotted_name IMPORT star_or_import_as_name_list
543 (INCLUDE-TAG $2 nil)
544 ;
545
546;; dotted_as_name (',' dotted_as_name)*
547dotted_as_name_list
548 : dotted_as_name
549 | dotted_as_name_list COMMA dotted_as_name
550 ;
551
552;; ('*' | import_as_name (',' import_as_name)*)
553star_or_import_as_name_list
554 : MULT
555 ()
556 | import_as_name_list
557 ()
558 ;
559
560;; import_as_name (',' import_as_name)*
561import_as_name_list
562 : import_as_name
563 ()
564 | import_as_name_list COMMA import_as_name
565 ()
566 ;
567
568;; import_as_name: NAME [NAME NAME]
569import_as_name
570 : NAME as_name_opt
571 ()
572 ;
573
574;; dotted_as_name: dotted_name [AS NAME]
575dotted_as_name
576 : dotted_name as_name_opt
577 ;
578
579;; [AS NAME]
580as_name_opt
581 : ;;EMPTY
582 | AS NAME
583 (identity $2)
584 ;
585
586;; dotted_name: NAME ('.' NAME)*
587dotted_name
588 : NAME
589 | dotted_name PERIOD NAME
590 (format "%s.%s" $1 $3)
591 ;
592
593;;;============================================================================
594;;;@@ global_stmt
595;;;============================================================================
596
597;; global_stmt: 'global' NAME (',' NAME)*
598global_stmt
599 : GLOBAL comma_sep_name_list
600 (CODE-TAG $1 nil)
601 ;
602
603;; NAME (',' NAME)*
604comma_sep_name_list
605 : NAME
606 | comma_sep_name_list COMMA NAME
607 ;
608
609;;;============================================================================
610;;;@@ exec_stmt
611;;;============================================================================
612
613;; exec_stmt: 'exec' expr ['in' test [',' test]]
614exec_stmt
615 : EXEC expr exec_trailer
616 (CODE-TAG $1 nil)
617 ;
618
619;; ['in' test [',' test]]
620exec_trailer
621 : ;;EMPTY
622 | IN test comma_test_opt
623 ()
624 ;
625
626;; [',' test]
627comma_test_opt
628 : ;;EMPTY
629 | COMMA test
630 ()
631 ;
632
633;;;============================================================================
634;;;@@ assert_stmt
635;;;============================================================================
636
637;; assert_stmt: 'assert' test [',' test]
638assert_stmt
639 : ASSERT test comma_test_opt
640 (CODE-TAG $1 nil)
641 ;
642
643;;;****************************************************************************
644;;;@ compound_stmt
645;;;****************************************************************************
646
647compound_stmt
648 : if_stmt
649 | while_stmt
650 | for_stmt
651 | try_stmt
652 | funcdef
653 | class_declaration
654 ;
655
656;;;============================================================================
657;;;@@ if_stmt
658;;;============================================================================
659
660;; if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
661if_stmt
662 : IF test COLON suite elif_suite_pair_list else_suite_pair_opt
663 (CODE-TAG $1 nil)
664 ;
665
666;; ('elif' test ':' suite)*
667elif_suite_pair_list
668 : ;;EMPTY
669 | elif_suite_pair_list ELIF test COLON suite
670 ()
671 ;
672
673;; ['else' ':' suite]
674else_suite_pair_opt
675 : ;;EMPTY
676 | ELSE COLON suite
677 ()
678 ;
679
680;; This NT follows the COLON token for most compound statements.
681;; suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT
682suite
683 : simple_stmt
684 (list $1)
685 | NEWLINE indented_block
686 (progn $2)
687 ;
688
689indented_block
690 : INDENT_BLOCK
691 (EXPANDFULL $1 indented_block_body)
692 ;
693
694indented_block_body
695 : INDENT
696 ()
697 | DEDENT
698 ()
699 | simple_stmt
700 | compound_stmt
701 ;
702
703;;;============================================================================
704;;;@@ while_stmt
705;;;============================================================================
706
707;; while_stmt: 'while' test ':' suite ['else' ':' suite]
708while_stmt
709 : WHILE test COLON suite else_suite_pair_opt
710 (CODE-TAG $1 nil)
711 ;
712
713;;;============================================================================
714;;;@@ for_stmt
715;;;============================================================================
716
717;; for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
718for_stmt
719 : FOR exprlist IN testlist COLON suite else_suite_pair_opt
720 (CODE-TAG $1 nil)
721 ;
722
723;;;============================================================================
724;;;@@ try_stmt
725;;;============================================================================
726
727;; try_stmt: ('try' ':' suite (except_clause ':' suite)+ #diagram:break
728;; ['else' ':' suite] | 'try' ':' suite 'finally' ':' suite)
729try_stmt
730 : TRY COLON suite except_clause_suite_pair_list else_suite_pair_opt
731 (CODE-TAG $1 nil)
732 | TRY COLON suite FINALLY COLON suite
733 (CODE-TAG $1 nil)
734 ;
735
736;; (except_clause ':' suite)+
737except_clause_suite_pair_list
738 : except_clause COLON suite
739 ()
740 | except_clause_suite_pair_list except_clause COLON suite
741 ()
742 ;
743
744;; # NB compile.c makes sure that the default except clause is last
745;; except_clause: 'except' [test [',' test]]
746except_clause
747 : EXCEPT zero_one_or_two_test
748 ()
749 ;
750
751;; [test [',' test]]
752zero_one_or_two_test
753 : ;;EMPTY
754 | test zero_or_one_comma_test
755 ()
756 ;
757
758;;;============================================================================
759;;;@@ funcdef
760;;;============================================================================
761
762;; funcdef: 'def' NAME parameters ':' suite
763funcdef
764 : DEF NAME function_parameter_list COLON suite
765 (FUNCTION-TAG $2 nil $3)
766 ;
767
768function_parameter_list
769 : PAREN_BLOCK
770 (let ((wisent-python-EXPANDING-block t))
771 (EXPANDFULL $1 function_parameters))
772 ;
773
774;; parameters: '(' [varargslist] ')'
775function_parameters
776 : LPAREN
777 ()
778 | RPAREN
779 ()
780 | function_parameter COMMA
781 | function_parameter RPAREN
782 ;
783
784function_parameter
785 : fpdef_opt_test
786 ;; : NAME
787 ;; (VARIABLE-TAG $1 nil nil)
788 | MULT NAME
789 (VARIABLE-TAG $2 nil nil)
790 | EXPONENT NAME
791 (VARIABLE-TAG $2 nil nil)
792 ;
793
794;;;============================================================================
795;;;@@ class_declaration
796;;;============================================================================
797
798;; classdef: 'class' NAME ['(' testlist ')'] ':' suite
799class_declaration
800 : CLASS NAME paren_class_list_opt COLON suite
801 (TYPE-TAG $2 $1 ;; Name "class"
802 $5 ;; Members
803 (cons $3 nil) ;; (SUPERCLASSES . INTERFACES)
804 )
805 ;
806
807;; ['(' testlist ')']
808paren_class_list_opt
809 : ;;EMPTY
810 | paren_class_list
811 ;
812
813paren_class_list
814 : PAREN_BLOCK
815 (let ((wisent-python-EXPANDING-block t))
816 (mapcar 'semantic-tag-name (EXPANDFULL $1 paren_classes)))
817 ;
818
819;; parameters: '(' [varargslist] ')'
820paren_classes
821 : LPAREN
822 ()
823 | RPAREN
824 ()
825 | paren_class COMMA
826 (VARIABLE-TAG $1 nil nil)
827 | paren_class RPAREN
828 (VARIABLE-TAG $1 nil nil)
829 ;
830
831;; In general, the base class can be specified by a general expression
832;; which evaluates to a class object, i.e., base classes are not just names!
833;; However base classes are names in most cases. Thus the
834;; non-terminals below work only with simple names. Even if the
835;; parser can parse general expressions, I don't see much benefit in
836;; generating a string of expression as base class "name".
837paren_class
838 : dotted_name
839 ;
840
841;;;****************************************************************************
842;;;@ test
843;;;****************************************************************************
844
845;; test: and_test ('or' and_test)* | lambdef
846test
847 : test_test
848 | lambdef
849 ;
850
851;; and_test ('or' and_test)*
852test_test
853 : and_test
854 | test_test OR and_test
855 ()
856 ;
857
858;; and_test: not_test ('and' not_test)*
859and_test
860 : not_test
861 | and_test AND not_test
862 ()
863 ;
864
865;; not_test: 'not' not_test | comparison
866not_test
867 : NOT not_test
868 ()
869 | comparison
870 ;
871
872;; comparison: expr (comp_op expr)*
873comparison
874 : expr
875 | comparison comp_op expr
876 ()
877 ;
878
879;; comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
880comp_op
881 : LT | GT | EQ | GE | LE | LTGT | NE | IN | NOT IN | IS | IS NOT
882 ;
883
884;; expr: xor_expr ('|' xor_expr)*
885expr
886 : xor_expr
887 | expr BAR xor_expr
888 ()
889 ;
890
891;; xor_expr: and_expr ('^' and_expr)*
892xor_expr
893 : and_expr
894 | xor_expr HAT and_expr
895 ()
896 ;
897
898;; and_expr: shift_expr ('&' shift_expr)*
899and_expr
900 : shift_expr
901 | and_expr AMP shift_expr
902 ()
903 ;
904
905;; shift_expr: arith_expr (('<<'|'>>') arith_expr)*
906shift_expr
907 : arith_expr
908 | shift_expr shift_expr_operators arith_expr
909 ()
910 ;
911
912;; ('<<'|'>>')
913shift_expr_operators
914 : LTLT
915 | GTGT
916 ;
917
918;; arith_expr: term (('+'|'-') term)*
919arith_expr
920 : term
921 | arith_expr plus_or_minus term
922 ()
923 ;
924
925;; ('+'|'-')
926plus_or_minus
927 : PLUS
928 | MINUS
929 ;
930
931;; term: factor (('*'|'/'|'%'|'//') factor)*
932term
933 : factor
934 | term term_operator factor
935 ()
936 ;
937
938term_operator
939 : MULT
940 | DIV
941 | MOD
942 | DIVDIV
943 ;
944
945;; factor: ('+'|'-'|'~') factor | power
946factor
947 : prefix_operators factor
948 ()
949 | power
950 ;
951
952;; ('+'|'-'|'~')
953prefix_operators
954 : PLUS
955 | MINUS
956 | TILDE
957 ;
958
959;; power: atom trailer* ('**' factor)*
960power
961 : atom trailer_zom exponent_zom
962 (concat $1
963 (if $2 (concat " " $2 " ") "")
964 (if $3 (concat " " $3) "")
965 )
966 ;
967
968trailer_zom
969 : ;;EMPTY
970 | trailer_zom trailer
971 ()
972 ;
973
974exponent_zom
975 : ;;EMPTY
976 | exponent_zom EXPONENT factor
977 ()
978 ;
979
980;; trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
981trailer
982 : PAREN_BLOCK
983 ()
984 | BRACK_BLOCK
985 ()
986 | PERIOD NAME
987 ()
988 ;
989
990;; atom: '(' [testlist] ')' | '[' [listmaker] ']' | '{' [dictmaker] '}'
991;; | '`' testlist '`' | NAME | NUMBER | STRING+
992atom
993 : PAREN_BLOCK
994 ()
995 | BRACK_BLOCK
996 ()
997 | BRACE_BLOCK
998 ()
999 | BACKQUOTE testlist BACKQUOTE
1000 ()
1001 | NAME
1002 | NUMBER_LITERAL
1003 | one_or_more_string
1004 ;
1005
1006test_list_opt
1007 : ;;EMPTY
1008 | testlist
1009 ()
1010 ;
1011
1012;; testlist: test (',' test)* [',']
1013testlist
1014 : comma_sep_test_list comma_opt
1015 ;
1016
1017;; test (',' test)*
1018comma_sep_test_list
1019 : test
1020 | comma_sep_test_list COMMA test
1021 (format "%s, %s" $1 $3)
1022 ;
1023
1024;; (read $1) and (read $2) were done before to peel away the double quotes.
1025;; However that does not work for single quotes, so it was taken out.
1026one_or_more_string
1027 : STRING_LITERAL
1028 | one_or_more_string STRING_LITERAL
1029 (concat $1 $2)
1030 ;
1031
1032;;;****************************************************************************
1033;;;@ lambdef
1034;;;****************************************************************************
1035
1036;; lambdef: 'lambda' [varargslist] ':' test
1037lambdef
1038 : LAMBDA varargslist_opt COLON test
1039 (format "%s %s" $1 (or $2 ""))
1040 ;
1041
1042;; [varargslist]
1043varargslist_opt
1044 : ;;EMPTY
1045 | varargslist
1046 ;
1047
1048;; varargslist: (fpdef ['=' test] ',')* ('*' NAME [',' '**' NAME] | '**' NAME)
1049;; | fpdef ['=' test] (',' fpdef ['=' test])* [',']
1050varargslist
1051 : fpdef_opt_test_list_comma_zom rest_args
1052 (nconc $2 $1)
1053 | fpdef_opt_test_list comma_opt
1054 ;
1055
1056;; ('*' NAME [',' '**' NAME] | '**' NAME)
1057rest_args
1058 : MULT NAME multmult_name_opt
1059 () ;;(VARIABLE-TAG $2 nil nil)
1060 | EXPONENT NAME
1061 () ;;(VARIABLE-TAG $2 nil nil)
1062 ;
1063
1064;; [',' '**' NAME]
1065multmult_name_opt
1066 : ;;EMPTY
1067 | COMMA EXPONENT NAME
1068 (VARIABLE-TAG $3 nil nil)
1069 ;
1070
1071fpdef_opt_test_list_comma_zom
1072 : ;;EMPTY
1073 | fpdef_opt_test_list_comma_zom fpdef_opt_test COMMA
1074 (nconc $2 $1)
1075 ;
1076
1077;; fpdef ['=' test] (',' fpdef ['=' test])*
1078fpdef_opt_test_list
1079 : fpdef_opt_test
1080 | fpdef_opt_test_list COMMA fpdef_opt_test
1081 (nconc $3 $1)
1082 ;
1083
1084;; fpdef ['=' test]
1085fpdef_opt_test
1086 : fpdef eq_test_opt
1087 ;
1088
1089;; fpdef: NAME | '(' fplist ')'
1090fpdef
1091 : NAME
1092 (VARIABLE-TAG $1 nil nil)
1093 ;; Below breaks the parser. Don't know why, but my guess is that
1094 ;; LPAREN/RPAREN clashes with the ones in function_parameters.
1095 ;; | LPAREN fplist RPAREN
1096 ;; (identity $2)
1097 ;
1098
1099;; fplist: fpdef (',' fpdef)* [',']
1100fplist
1101 : fpdef_list comma_opt
1102 ;
1103
1104;; fpdef (',' fpdef)*
1105fpdef_list
1106 : fpdef
1107 | fpdef_list COMMA fpdef
1108 ;
1109
1110;; ['=' test]
1111eq_test_opt
1112 : ;;EMPTY
1113 | ASSIGN test
1114 ()
1115 ;
1116
1117;;;****************************************************************************
1118;;;@ Misc
1119;;;****************************************************************************
1120
1121;; [',']
1122comma_opt
1123 : ;;EMPTY
1124 | COMMA
1125 ;
1126
1127;; [';']
1128semicolon_opt
1129 : ;;EMPTY
1130 | SEMICOLON
1131 ;
1132
1133;;; python.wy ends here
diff --git a/admin/grammars/scheme.by b/admin/grammars/scheme.by
new file mode 100644
index 00000000000..3925f03c28b
--- /dev/null
+++ b/admin/grammars/scheme.by
@@ -0,0 +1,84 @@
1;;; scheme.by -- Scheme BNF language specification
2
3;; Copyright (C) 2001-2012 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software: you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
19
20%package semantic-scm-by
21
22%languagemode scheme-mode
23%start scheme
24
25%token DEFINE "define"
26%token DEFINE-MODULE "define-module"
27%token LOAD "load"
28
29%put DEFINE summary "Function: (define symbol expression)"
30%put DEFINE-MODULE summary "Function: (define-module (name arg1 ...)) "
31%put LOAD summary "Function: (load \"filename\")"
32
33%token <open-paren> OPENPAREN "("
34%token <close-paren> CLOSEPAREN ")"
35
36%%
37
38scheme : semantic-list
39 (EXPAND $1 scheme-list)
40 ;
41
42scheme-list : OPENPAREN scheme-in-list CLOSEPAREN
43 ( ,$2 )
44 ;
45
46scheme-in-list: DEFINE symbol expression
47 (VARIABLE-TAG $2 nil $3 )
48 | DEFINE name-args opt-doc sequence
49 (FUNCTION-TAG (car ,$2) nil (cdr ,$2) )
50 | DEFINE-MODULE name-args
51 (PACKAGE-TAG (nth (length $2) $2 ) nil)
52 | LOAD string
53 (INCLUDE-TAG (file-name-nondirectory (read $2)) (read $2) )
54 | symbol
55 (CODE-TAG $1 nil)
56 ;
57
58name-args: semantic-list
59 (EXPAND $1 name-arg-expand)
60 ;
61
62name-arg-expand : open-paren name-arg-expand
63 ( ,$2 )
64 | symbol name-arg-expand
65 ( ,(cons $1 ,$2) )
66 | ;; EMPTY
67 ( )
68 ;
69
70opt-doc : string
71 | ;; EMPTY
72 ;
73
74sequence : expression sequence
75 | expression
76 ;
77
78expression : symbol
79 | semantic-list
80 | string
81 | number
82 ;
83
84;;; scheme.by ends here
diff --git a/admin/grammars/srecode-template.wy b/admin/grammars/srecode-template.wy
new file mode 100644
index 00000000000..f38d7eaa2a1
--- /dev/null
+++ b/admin/grammars/srecode-template.wy
@@ -0,0 +1,235 @@
1;;; srecode-template.wy --- Semantic Recoder Template parser
2
3;; Copyright (C) 2005-2012 Free Software Foundation, Inc.
4
5;; Author: Eric Ludlam <zappo@gnu.org>
6;; Keywords: syntax
7;; X-RCS: $Id: srecode-template.wy,v 1.10 2009-01-09 23:01:54 zappo Exp $
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software: you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24;;; Commentary:
25;;
26;; Parser for the Semantic Recoder template language
27;;
28;; Semantic Recoder templates are based on Google Templates
29;; and are at the bottom of the Semantic Recoder API.
30
31%languagemode srecode-mode
32
33%start template_file
34
35;;; KEYWORDS
36%type <keyword>
37%keyword SET "set"
38%put SET summary "set <name> <value>"
39%keyword SHOW "show"
40%put SHOW summary "show <name> ; to show a section"
41%keyword MACRO "macro"
42%put MACRO summary "... macro \"string\" ..."
43%keyword CONTEXT "context"
44%put CONTEXT summary "context <name>"
45%keyword TEMPLATE "template"
46%put TEMPLATE summary "template <name>\\n <template definition>"
47%keyword SECTIONDICTIONARY "sectiondictionary"
48%put SECTIONDICTIONARY summary "sectiondictionary <name>\\n <dictionary entries>"
49%keyword PROMPT "prompt"
50%keyword DEFAULT "default"
51%keyword DEFAULTMACRO "defaultmacro"
52%keyword READ "read"
53%put { PROMPT DEFAULT DEFAULTMACRO READ } summary "prompt <symbol> \"Describe Symbol: \" [default[macro] <lispsym>|\"valuetext\"] [read <lispsym>]"
54%keyword BIND "bind"
55%put BIND summary "bind \"<letter>\""
56
57;;; Punctuation Types
58%type <punctuation> syntax "\\s.+"
59%type <newline>
60%token <newline> newline
61
62%token <separator> TEMPLATE_BLOCK "^----"
63
64;;; Bland default types
65%type <property> ":\\(\\w\\|\\s_\\)*"
66%token <property> property
67
68%type <symbol>
69%token <symbol> symbol
70
71%type <string>
72%token <string> string
73
74%type <number>
75%token <number> number
76
77%%
78
79template_file
80 : newline ( )
81 | context
82 | prompt
83 | variable
84 | template
85 ;
86
87context
88 : CONTEXT symbol newline
89 (TAG $2 'context)
90 ;
91
92prompt
93 : PROMPT symbol string opt-default-fcn opt-read-fcn newline
94 (TAG $2 'prompt :text (read $3) :default $4 :read $5)
95 ;
96
97opt-default-fcn
98 : DEFAULT symbol
99 (progn (read $2))
100 | DEFAULT string
101 (progn (read $2))
102 | DEFAULTMACRO string
103 (progn (cons 'macro (read $2)))
104 | ()
105 ;
106
107opt-read-fcn
108 : READ symbol
109 (progn (read $2))
110 | ()
111 ;
112
113variable
114 : SET symbol insertable-string-list newline
115 (VARIABLE-TAG $2 nil $3)
116 | SHOW symbol newline
117 (VARIABLE-TAG $2 nil t)
118 ;
119
120insertable-string-list
121 : insertable-string
122 (list $1)
123 | insertable-string-list insertable-string
124 (append $1 (list $2))
125 ;
126
127insertable-string
128 : string
129 (read $1)
130 | MACRO string
131 (cons 'macro (read $2))
132 ;
133
134template
135 : TEMPLATE templatename opt-dynamic-arguments newline
136 opt-string
137 opt-section-dictionaries
138 TEMPLATE_BLOCK newline
139 opt-bind
140 (FUNCTION-TAG $2 nil $3 :documentation $5 :code $7
141 :dictionaries $6 :binding $9 )
142 ;
143
144templatename
145 : symbol
146 | PROMPT
147 | CONTEXT
148 | TEMPLATE
149 | DEFAULT
150 | MACRO
151 | DEFAULTMACRO
152 | READ
153 | SET
154 ;
155
156opt-dynamic-arguments
157 : property opt-dynamic-arguments
158 (cons $1 $2)
159 | ()
160 ;
161
162opt-string
163 : string newline
164 ( read $1 )
165 | ()
166 ;
167
168opt-section-dictionaries
169 : () ;; EMPTY
170 | section-dictionary-list
171 ;
172
173section-dictionary-list
174 : one-section-dictionary
175 (list $1)
176 | section-dictionary-list one-section-dictionary
177 (append $1 (list $2))
178 ;
179
180one-section-dictionary
181 : SECTIONDICTIONARY string newline
182 variable-list
183 (cons (read $2) $4)
184 ;
185
186variable-list
187 : variable
188 (EXPANDTAG $1)
189 | variable-list variable
190 (append $1 (EXPANDTAG $2))
191 ;
192
193opt-bind
194 : BIND string newline
195 ( read $2 )
196 | ()
197 ;
198
199%%
200(define-lex-simple-regex-analyzer srecode-template-property-analyzer
201 "Detect and create a dynamic argument properties."
202 ":\\(\\w\\|\\s_\\)*" 'property 0)
203
204(define-lex-regex-analyzer srecode-template-separator-block
205 "Detect and create a template quote block."
206 "^----\n"
207 (semantic-lex-push-token
208 (semantic-lex-token
209 'TEMPLATE_BLOCK
210 (match-end 0)
211 (semantic-lex-unterminated-syntax-protection 'TEMPLATE_BLOCK
212 (goto-char (match-end 0))
213 (re-search-forward "^----$")
214 (match-beginning 0))))
215 (setq semantic-lex-end-point (point)))
216
217
218(define-lex wisent-srecode-template-lexer
219 "Lexical analyzer that handles SRecode Template buffers.
220It ignores whitespace, newlines and comments."
221 semantic-lex-newline
222 semantic-lex-ignore-whitespace
223 semantic-lex-ignore-newline
224 semantic-lex-ignore-comments
225 srecode-template-separator-block
226 srecode-template-wy--<keyword>-keyword-analyzer
227 srecode-template-property-analyzer
228 srecode-template-wy--<symbol>-regexp-analyzer
229 srecode-template-wy--<number>-regexp-analyzer
230 srecode-template-wy--<string>-sexp-analyzer
231 srecode-template-wy--<punctuation>-string-analyzer
232 semantic-lex-default-action
233 )
234
235;;; wisent-dot.wy ends here
diff --git a/admin/grammars/wisent-grammar.el b/admin/grammars/wisent-grammar.el
new file mode 100644
index 00000000000..714b5211127
--- /dev/null
+++ b/admin/grammars/wisent-grammar.el
@@ -0,0 +1,537 @@
1;;; wisent-grammar.el --- Wisent's input grammar mode
2
3;; Copyright (C) 2002-2012 Free Software Foundation, Inc.
4;;
5;; Author: David Ponce <david@dponce.com>
6;; Maintainer: David Ponce <david@dponce.com>
7;; Created: 26 Aug 2002
8;; Keywords: syntax
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software: you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24;;; Commentary:
25;;
26;; Major mode for editing Wisent's input grammar (.wy) files.
27
28;;; Code:
29(require 'semantic)
30(require 'semantic/grammar)
31(require 'semantic/find)
32(require 'semantic/lex)
33(require 'semantic/wisent)
34(require 'semantic/bovine)
35
36(defsubst wisent-grammar-region-placeholder (symb)
37 "Given a $N placeholder symbol in SYMB, return a $regionN symbol.
38Return nil if $N is not a valid placeholder symbol."
39 (let ((n (symbol-name symb)))
40 (if (string-match "^[$]\\([1-9][0-9]*\\)$" n)
41 (intern (concat "$region" (match-string 1 n))))))
42
43(defun wisent-grammar-EXPAND (symb nonterm)
44 "Expand call to EXPAND grammar macro.
45Return the form to parse from within a nonterminal.
46SYMB is a $I placeholder symbol that gives the bounds of the area to
47parse.
48NONTERM is the nonterminal symbol to start with."
49 (unless (member nonterm (semantic-grammar-start))
50 (error "EXPANDFULL macro called with %s, but not used with %%start"
51 nonterm))
52 (let (($ri (wisent-grammar-region-placeholder symb)))
53 (if $ri
54 `(semantic-bovinate-from-nonterminal
55 (car ,$ri) (cdr ,$ri) ',nonterm)
56 (error "Invalid form (EXPAND %s %s)" symb nonterm))))
57
58(defun wisent-grammar-EXPANDFULL (symb nonterm)
59 "Expand call to EXPANDFULL grammar macro.
60Return the form to recursively parse an area.
61SYMB is a $I placeholder symbol that gives the bounds of the area.
62NONTERM is the nonterminal symbol to start with."
63 (unless (member nonterm (semantic-grammar-start))
64 (error "EXPANDFULL macro called with %s, but not used with %%start"
65 nonterm))
66 (let (($ri (wisent-grammar-region-placeholder symb)))
67 (if $ri
68 `(semantic-parse-region
69 (car ,$ri) (cdr ,$ri) ',nonterm 1)
70 (error "Invalid form (EXPANDFULL %s %s)" symb nonterm))))
71
72(defun wisent-grammar-TAG (name class &rest attributes)
73 "Expand call to TAG grammar macro.
74Return the form to create a generic semantic tag.
75See the function `semantic-tag' for the meaning of arguments NAME,
76CLASS and ATTRIBUTES."
77 `(wisent-raw-tag
78 (semantic-tag ,name ,class ,@attributes)))
79
80(defun wisent-grammar-VARIABLE-TAG (name type default-value &rest attributes)
81 "Expand call to VARIABLE-TAG grammar macro.
82Return the form to create a semantic tag of class variable.
83See the function `semantic-tag-new-variable' for the meaning of
84arguments NAME, TYPE, DEFAULT-VALUE and ATTRIBUTES."
85 `(wisent-raw-tag
86 (semantic-tag-new-variable ,name ,type ,default-value ,@attributes)))
87
88(defun wisent-grammar-FUNCTION-TAG (name type arg-list &rest attributes)
89 "Expand call to FUNCTION-TAG grammar macro.
90Return the form to create a semantic tag of class function.
91See the function `semantic-tag-new-function' for the meaning of
92arguments NAME, TYPE, ARG-LIST and ATTRIBUTES."
93 `(wisent-raw-tag
94 (semantic-tag-new-function ,name ,type ,arg-list ,@attributes)))
95
96(defun wisent-grammar-TYPE-TAG (name type members parents &rest attributes)
97 "Expand call to TYPE-TAG grammar macro.
98Return the form to create a semantic tag of class type.
99See the function `semantic-tag-new-type' for the meaning of arguments
100NAME, TYPE, MEMBERS, PARENTS and ATTRIBUTES."
101 `(wisent-raw-tag
102 (semantic-tag-new-type ,name ,type ,members ,parents ,@attributes)))
103
104(defun wisent-grammar-INCLUDE-TAG (name system-flag &rest attributes)
105 "Expand call to INCLUDE-TAG grammar macro.
106Return the form to create a semantic tag of class include.
107See the function `semantic-tag-new-include' for the meaning of
108arguments NAME, SYSTEM-FLAG and ATTRIBUTES."
109 `(wisent-raw-tag
110 (semantic-tag-new-include ,name ,system-flag ,@attributes)))
111
112(defun wisent-grammar-PACKAGE-TAG (name detail &rest attributes)
113 "Expand call to PACKAGE-TAG grammar macro.
114Return the form to create a semantic tag of class package.
115See the function `semantic-tag-new-package' for the meaning of
116arguments NAME, DETAIL and ATTRIBUTES."
117 `(wisent-raw-tag
118 (semantic-tag-new-package ,name ,detail ,@attributes)))
119
120(defun wisent-grammar-CODE-TAG (name detail &rest attributes)
121 "Expand call to CODE-TAG grammar macro.
122Return the form to create a semantic tag of class code.
123See the function `semantic-tag-new-code' for the meaning of arguments
124NAME, DETAIL and ATTRIBUTES."
125 `(wisent-raw-tag
126 (semantic-tag-new-code ,name ,detail ,@attributes)))
127
128(defun wisent-grammar-ALIAS-TAG (name aliasclass definition &rest attributes)
129 "Expand call to ALIAS-TAG grammar macro.
130Return the form to create a semantic tag of class alias.
131See the function `semantic-tag-new-alias' for the meaning of arguments
132NAME, ALIASCLASS, DEFINITION and ATTRIBUTES."
133 `(wisent-raw-tag
134 (semantic-tag-new-alias ,name ,aliasclass ,definition ,@attributes)))
135
136(defun wisent-grammar-EXPANDTAG (raw-tag)
137 "Expand call to EXPANDTAG grammar macro.
138Return the form to produce a list of cooked tags from raw form of
139Semantic tag RAW-TAG."
140 `(wisent-cook-tag ,raw-tag))
141
142(defun wisent-grammar-AST-ADD (ast &rest nodes)
143 "Expand call to AST-ADD grammar macro.
144Return the form to update the abstract syntax tree AST with NODES.
145See also the function `semantic-ast-add'."
146 `(semantic-ast-add ,ast ,@nodes))
147
148(defun wisent-grammar-AST-PUT (ast &rest nodes)
149 "Expand call to AST-PUT grammar macro.
150Return the form to update the abstract syntax tree AST with NODES.
151See also the function `semantic-ast-put'."
152 `(semantic-ast-put ,ast ,@nodes))
153
154(defun wisent-grammar-AST-GET (ast node)
155 "Expand call to AST-GET grammar macro.
156Return the form to get, from the abstract syntax tree AST, the value
157of NODE.
158See also the function `semantic-ast-get'."
159 `(semantic-ast-get ,ast ,node))
160
161(defun wisent-grammar-AST-GET1 (ast node)
162 "Expand call to AST-GET1 grammar macro.
163Return the form to get, from the abstract syntax tree AST, the first
164value of NODE.
165See also the function `semantic-ast-get1'."
166 `(semantic-ast-get1 ,ast ,node))
167
168(defun wisent-grammar-AST-GET-STRING (ast node)
169 "Expand call to AST-GET-STRING grammar macro.
170Return the form to get, from the abstract syntax tree AST, the value
171of NODE as a string.
172See also the function `semantic-ast-get-string'."
173 `(semantic-ast-get-string ,ast ,node))
174
175(defun wisent-grammar-AST-MERGE (ast1 ast2)
176 "Expand call to AST-MERGE grammar macro.
177Return the form to merge the abstract syntax trees AST1 and AST2.
178See also the function `semantic-ast-merge'."
179 `(semantic-ast-merge ,ast1 ,ast2))
180
181(defun wisent-grammar-SKIP-BLOCK (&optional symb)
182 "Expand call to SKIP-BLOCK grammar macro.
183Return the form to skip a parenthesized block.
184Optional argument SYMB is a $I placeholder symbol that gives the
185bounds of the block to skip. By default, skip the block at `$1'.
186See also the function `wisent-skip-block'."
187 (let ($ri)
188 (when symb
189 (unless (setq $ri (wisent-grammar-region-placeholder symb))
190 (error "Invalid form (SKIP-BLOCK %s)" symb)))
191 `(wisent-skip-block ,$ri)))
192
193(defun wisent-grammar-SKIP-TOKEN ()
194 "Expand call to SKIP-TOKEN grammar macro.
195Return the form to skip the lookahead token.
196See also the function `wisent-skip-token'."
197 `(wisent-skip-token))
198
199(defun wisent-grammar-assocs ()
200 "Return associativity and precedence level definitions."
201 (mapcar
202 #'(lambda (tag)
203 (cons (intern (semantic-tag-name tag))
204 (mapcar #'semantic-grammar-item-value
205 (semantic-tag-get-attribute tag :value))))
206 (semantic-find-tags-by-class 'assoc (current-buffer))))
207
208(defun wisent-grammar-terminals ()
209 "Return the list of terminal symbols.
210Keep order of declaration in the WY file without duplicates."
211 (let (terms)
212 (mapcar
213 #'(lambda (tag)
214 (mapcar #'(lambda (name)
215 (add-to-list 'terms (intern name)))
216 (cons (semantic-tag-name tag)
217 (semantic-tag-get-attribute tag :rest))))
218 (semantic--find-tags-by-function
219 #'(lambda (tag)
220 (memq (semantic-tag-class tag) '(token keyword)))
221 (current-buffer)))
222 (nreverse terms)))
223
224;; Cache of macro definitions currently in use.
225(defvar wisent--grammar-macros nil)
226
227(defun wisent-grammar-expand-macros (expr)
228 "Expand expression EXPR into a form without grammar macros.
229Return the expanded expression."
230 (if (or (atom expr) (semantic-grammar-quote-p (car expr)))
231 expr ;; Just return atom or quoted expression.
232 (let* ((expr (mapcar 'wisent-grammar-expand-macros expr))
233 (macro (assq (car expr) wisent--grammar-macros)))
234 (if macro ;; Expand Semantic built-in.
235 (apply (cdr macro) (cdr expr))
236 expr))))
237
238(defun wisent-grammar-nonterminals ()
239 "Return the list form of nonterminal definitions."
240 (let ((nttags (semantic-find-tags-by-class
241 'nonterminal (current-buffer)))
242 ;; Setup the cache of macro definitions.
243 (wisent--grammar-macros (semantic-grammar-macros))
244 rltags nterms rules rule elems elem actn sexp prec)
245 (while nttags
246 (setq rltags (semantic-tag-components (car nttags))
247 rules nil)
248 (while rltags
249 (setq elems (semantic-tag-get-attribute (car rltags) :value)
250 prec (semantic-tag-get-attribute (car rltags) :prec)
251 actn (semantic-tag-get-attribute (car rltags) :expr)
252 rule nil)
253 (when elems ;; not an EMPTY rule
254 (while elems
255 (setq elem (car elems)
256 elems (cdr elems))
257 (setq elem (if (consp elem) ;; mid-rule action
258 (wisent-grammar-expand-macros (read (car elem)))
259 (semantic-grammar-item-value elem)) ;; item
260 rule (cons elem rule)))
261 (setq rule (nreverse rule)))
262 (if prec
263 (setq prec (vector (semantic-grammar-item-value prec))))
264 (if actn
265 (setq sexp (wisent-grammar-expand-macros (read actn))))
266 (setq rule (if actn
267 (if prec
268 (list rule prec sexp)
269 (list rule sexp))
270 (if prec
271 (list rule prec)
272 (list rule))))
273 (setq rules (cons rule rules)
274 rltags (cdr rltags)))
275 (setq nterms (cons (cons (intern (semantic-tag-name (car nttags)))
276 (nreverse rules))
277 nterms)
278 nttags (cdr nttags)))
279 (nreverse nterms)))
280
281(defun wisent-grammar-grammar ()
282 "Return Elisp form of the grammar."
283 (let* ((terminals (wisent-grammar-terminals))
284 (nonterminals (wisent-grammar-nonterminals))
285 (assocs (wisent-grammar-assocs)))
286 (cons terminals (cons assocs nonterminals))))
287
288(defun wisent-grammar-parsetable-builder ()
289 "Return the value of the parser table."
290 `(progn
291 ;; Ensure that the grammar [byte-]compiler is available.
292 (eval-when-compile (require 'semantic/wisent/comp))
293 (wisent-compile-grammar
294 ',(wisent-grammar-grammar)
295 ',(semantic-grammar-start))))
296
297(defun wisent-grammar-setupcode-builder ()
298 "Return the parser setup code."
299 (format
300 "(semantic-install-function-overrides\n\
301 '((parse-stream . wisent-parse-stream)))\n\
302 (setq semantic-parser-name \"LALR\"\n\
303 semantic--parse-table %s\n\
304 semantic-debug-parser-source %S\n\
305 semantic-flex-keywords-obarray %s\n\
306 semantic-lex-types-obarray %s)\n\
307 ;; Collect unmatched syntax lexical tokens\n\
308 (semantic-make-local-hook 'wisent-discarding-token-functions)\n\
309 (add-hook 'wisent-discarding-token-functions\n\
310 'wisent-collect-unmatched-syntax nil t)"
311 (semantic-grammar-parsetable)
312 (buffer-name)
313 (semantic-grammar-keywordtable)
314 (semantic-grammar-tokentable)))
315
316(defvar wisent-grammar-menu
317 '("WY Grammar"
318 ["LALR Compiler Verbose" wisent-toggle-verbose-flag
319 :style toggle :active (boundp 'wisent-verbose-flag)
320 :selected (and (boundp 'wisent-verbose-flag)
321 wisent-verbose-flag)]
322 )
323 "WY mode specific grammar menu.
324Menu items are appended to the common grammar menu.")
325
326(define-derived-mode wisent-grammar-mode semantic-grammar-mode "WY"
327 "Major mode for editing Wisent grammars."
328 (semantic-grammar-setup-menu wisent-grammar-menu)
329 (semantic-install-function-overrides
330 '((grammar-parsetable-builder . wisent-grammar-parsetable-builder)
331 (grammar-setupcode-builder . wisent-grammar-setupcode-builder)
332 )))
333
334(add-to-list 'auto-mode-alist '("\\.wy\\'" . wisent-grammar-mode))
335
336(defvar-mode-local wisent-grammar-mode semantic-grammar-macros
337 '(
338 (ASSOC . semantic-grammar-ASSOC)
339 (EXPAND . wisent-grammar-EXPAND)
340 (EXPANDFULL . wisent-grammar-EXPANDFULL)
341 (TAG . wisent-grammar-TAG)
342 (VARIABLE-TAG . wisent-grammar-VARIABLE-TAG)
343 (FUNCTION-TAG . wisent-grammar-FUNCTION-TAG)
344 (TYPE-TAG . wisent-grammar-TYPE-TAG)
345 (INCLUDE-TAG . wisent-grammar-INCLUDE-TAG)
346 (PACKAGE-TAG . wisent-grammar-PACKAGE-TAG)
347 (EXPANDTAG . wisent-grammar-EXPANDTAG)
348 (CODE-TAG . wisent-grammar-CODE-TAG)
349 (ALIAS-TAG . wisent-grammar-ALIAS-TAG)
350 (AST-ADD . wisent-grammar-AST-ADD)
351 (AST-PUT . wisent-grammar-AST-PUT)
352 (AST-GET . wisent-grammar-AST-GET)
353 (AST-GET1 . wisent-grammar-AST-GET1)
354 (AST-GET-STRING . wisent-grammar-AST-GET-STRING)
355 (AST-MERGE . wisent-grammar-AST-MERGE)
356 (SKIP-BLOCK . wisent-grammar-SKIP-BLOCK)
357 (SKIP-TOKEN . wisent-grammar-SKIP-TOKEN)
358 )
359 "Semantic grammar macros used in wisent grammars.")
360
361(defvar wisent-make-parsers--emacs-license
362 ";; This file is part of GNU Emacs.
363
364;; GNU Emacs is free software: you can redistribute it and/or modify
365;; it under the terms of the GNU General Public License as published by
366;; the Free Software Foundation, either version 3 of the License, or
367;; (at your option) any later version.
368
369;; GNU Emacs is distributed in the hope that it will be useful,
370;; but WITHOUT ANY WARRANTY; without even the implied warranty of
371;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
372;; GNU General Public License for more details.
373
374;; You should have received a copy of the GNU General Public License
375;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.")
376
377(defvar wisent-make-parsers--python-license
378 ";; It is derived in part from the Python grammar, used under the
379;; following license:
380;;
381;; PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
382;; --------------------------------------------
383;; 1. This LICENSE AGREEMENT is between the Python Software Foundation
384;; (\"PSF\"), and the Individual or Organization (\"Licensee\") accessing
385;; and otherwise using this software (\"Python\") in source or binary
386;; form and its associated documentation.
387;;
388;; 2. Subject to the terms and conditions of this License Agreement,
389;; PSF hereby grants Licensee a nonexclusive, royalty-free, world-wide
390;; license to reproduce, analyze, test, perform and/or display
391;; publicly, prepare derivative works, distribute, and otherwise use
392;; Python alone or in any derivative version, provided, however, that
393;; PSF's License Agreement and PSF's notice of copyright, i.e.,
394;; \"Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
395;; 2009, 2010 Python Software Foundation; All Rights Reserved\" are
396;; retained in Python alone or in any derivative version prepared by
397;; Licensee.
398;;
399;; 3. In the event Licensee prepares a derivative work that is based
400;; on or incorporates Python or any part thereof, and wants to make
401;; the derivative work available to others as provided herein, then
402;; Licensee hereby agrees to include in any such work a brief summary
403;; of the changes made to Python.
404;;
405;; 4. PSF is making Python available to Licensee on an \"AS IS\"
406;; basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
407;; IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
408;; DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
409;; FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
410;; INFRINGE ANY THIRD PARTY RIGHTS.
411;;
412;; 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
413;; FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A
414;; RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, OR
415;; ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
416;;
417;; 6. This License Agreement will automatically terminate upon a
418;; material breach of its terms and conditions.
419;;
420;; 7. Nothing in this License Agreement shall be deemed to create any
421;; relationship of agency, partnership, or joint venture between PSF
422;; and Licensee. This License Agreement does not grant permission to
423;; use PSF trademarks or trade name in a trademark sense to endorse or
424;; promote products or services of Licensee, or any third party.
425;;
426;; 8. By copying, installing or otherwise using Python, Licensee
427;; agrees to be bound by the terms and conditions of this License
428;; Agreement.")
429
430(defvar wisent-make-parsers--ecmascript-license
431 "\n;; It is derived from the grammar in the ECMAScript Language
432;; Specification published at
433;;
434;; http://www.ecma-international.org/publications/standards/Ecma-262.htm
435;;
436;; and redistributed under the following license:
437;;
438;; Redistribution and use in source and binary forms, with or without
439;; modification, are permitted provided that the following conditions
440;; are met:
441;;
442;; 1. Redistributions of source code must retain the above copyright
443;; notice, this list of conditions and the following disclaimer.
444;;
445;; 2. Redistributions in binary form must reproduce the above
446;; copyright notice, this list of conditions and the following
447;; disclaimer in the documentation and/or other materials provided
448;; with the distribution.
449;;
450;; 3. Neither the name of the authors nor Ecma International may be
451;; used to endorse or promote products derived from this software
452;; without specific prior written permission. THIS SOFTWARE IS
453;; PROVIDED BY THE ECMA INTERNATIONAL \"AS IS\" AND ANY EXPRESS OR
454;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
455;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
456;; ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR
457;; ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
458;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
459;; OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
460;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
461;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
462;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
463;; USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
464;; DAMAGE.")
465
466(defvar wisent-make-parsers--parser-file-name
467 `(("semantic-grammar-wy.el"
468 "semantic/grammar-wy")
469 ("srecode-template-wy.el"
470 "srecode/srt-wy")
471 ("wisent-javascript-jv-wy.el"
472 "semantic/wisent/js-wy"
473 "Copyright (C) 1998-2011 Ecma International."
474 ,wisent-make-parsers--ecmascript-license)
475 ("wisent-java-tags-wy.el"
476 "semantic/wisent/javat-wy")
477 ("wisent-python-wy.el"
478 "semantic/wisent/python-wy"
479 "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Python Software Foundation; All Rights Reserved."
480 ,wisent-make-parsers--python-license)))
481
482(defun wisent-make-parsers ()
483 "Generate Emacs' built-in Wisent-based parser files."
484 (semantic-mode 1)
485 ;; Loop through each .wy file in current directory, and run
486 ;; `semantic-grammar-batch-build-one-package' to build the grammar.
487 (dolist (f (directory-files default-directory nil "\\.wy\\'"))
488 (let ((packagename
489 (condition-case err
490 (with-current-buffer (find-file-noselect f)
491 (semantic-grammar-create-package))
492 (error (message "%s" (error-message-string err)) nil)))
493 output-data)
494 (when (setq output-data (assoc packagename wisent-make-parsers--parser-file-name))
495 (let ((require-name (nth 1 output-data))
496 (additional-copyright (nth 2 output-data))
497 (additional-license (nth 3 output-data))
498 copyright-end)
499 ;; Touch up the generated parsers for Emacs integration.
500 (with-temp-buffer
501 (insert-file-contents packagename)
502 ;; Fix copyright header:
503 (goto-char (point-min))
504 (when additional-copyright
505 (re-search-forward "Copyright (C).*$")
506 (insert "\n;; " additional-copyright))
507 (re-search-forward "^;; Author:")
508 (setq copyright-end (match-beginning 0))
509 (re-search-forward "^;;; Code:\n")
510 (delete-region copyright-end (match-end 0))
511 (goto-char copyright-end)
512 (insert wisent-make-parsers--emacs-license)
513 (insert "\n\n;;; Commentary:
514;;
515;; This file was generated from admin/grammars/"
516 f ".")
517 (when additional-license
518 (insert "\n" additional-license))
519 (insert "\n\n;;; Code:\n
520\(require 'semantic/lex)\n")
521 (goto-char (point-min))
522 (delete-region (point-min) (line-end-position))
523 (insert ";;; " require-name
524 ".el --- Generated parser support file")
525 (delete-trailing-whitespace)
526 (re-search-forward ";;\n(require 'semantic/lex)\n")
527 (delete-region (match-beginning 0) (match-end 0))
528 ;; Fix footer:
529 (goto-char (point-max))
530 (re-search-backward "^(provide")
531 (delete-region (match-beginning 0) (point-max))
532 (goto-char (point-max))
533 (insert "(provide '" require-name ")\n\n")
534 (insert ";;; " require-name ".el ends here\n")
535 (write-region nil nil (expand-file-name packagename))))))))
536
537;;; wisent-grammar.el ends here