aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/grammars/README8
-rw-r--r--etc/grammars/bovine-grammar.el501
-rw-r--r--etc/grammars/c.by1202
-rw-r--r--etc/grammars/grammar.wy432
-rw-r--r--etc/grammars/java-tags.wy750
-rw-r--r--etc/grammars/js.wy524
-rw-r--r--etc/grammars/make.by168
-rw-r--r--etc/grammars/python.wy1132
-rw-r--r--etc/grammars/scheme.by84
-rw-r--r--etc/grammars/srecode-template.wy235
-rw-r--r--etc/grammars/wisent-grammar.el542
-rw-r--r--lisp/cedet/semantic/bovine/c-by.el3
-rw-r--r--lisp/cedet/semantic/bovine/make-by.el3
-rw-r--r--lisp/cedet/semantic/bovine/scm-by.el3
-rw-r--r--lisp/cedet/semantic/grammar-wy.el3
-rw-r--r--lisp/cedet/semantic/wisent/javat-wy.el3
-rw-r--r--lisp/cedet/semantic/wisent/js-wy.el38
-rw-r--r--lisp/cedet/semantic/wisent/python-wy.el54
-rw-r--r--lisp/cedet/srecode/srt-wy.el4
19 files changed, 5673 insertions, 16 deletions
diff --git a/etc/grammars/README b/etc/grammars/README
new file mode 100644
index 00000000000..8365303f811
--- /dev/null
+++ b/etc/grammars/README
@@ -0,0 +1,8 @@
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. Currently, the parser files in
4lisp/ are generated by hand, not automatically. You can run the
5parser generators with
6
7emacs -batch -Q -l bovine-grammar.el -f bovine-make-parsers
8emacs -batch -Q -l wisent-grammar.el -f wisent-make-parsers
diff --git a/etc/grammars/bovine-grammar.el b/etc/grammars/bovine-grammar.el
new file mode 100644
index 00000000000..ee08c84eec7
--- /dev/null
+++ b/etc/grammars/bovine-grammar.el
@@ -0,0 +1,501 @@
1;;; bovine-grammar.el --- Bovine's input grammar mode
2;;
3;; Copyright (C) 2002-2011 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(defun bovine-grammar-expand-form (form quotemode &optional inplace)
113 "Expand FORM into a new one suitable to the bovine parser.
114FORM is a list in which we are substituting.
115Argument QUOTEMODE is non-nil if we are in backquote mode.
116When non-nil, optional argument INPLACE indicates that FORM is being
117expanded from elsewhere."
118 (when (eq (car form) 'quote)
119 (setq form (cdr form))
120 (cond
121 ((and (= (length form) 1) (listp (car form)))
122 (insert "\n(append")
123 (bovine-grammar-expand-form (car form) quotemode nil)
124 (insert ")")
125 (setq form nil inplace nil)
126 )
127 ((and (= (length form) 1) (symbolp (car form)))
128 (insert "\n'" (symbol-name (car form)))
129 (setq form nil inplace nil)
130 )
131 (t
132 (insert "\n(list")
133 (setq inplace t)
134 )))
135 (let ((macro (assq (car form) bovine--grammar-macros))
136 inlist first n q x)
137 (if macro
138 (bovine-grammar-expand-form
139 (apply (cdr macro) (cdr form))
140 quotemode t)
141 (if inplace (insert "\n("))
142 (while form
143 (setq first (car form)
144 form (cdr form))
145 (cond
146 ((eq first nil)
147 (when (and (not inlist) (not inplace))
148 (insert "\n(list")
149 (setq inlist t))
150 (insert " nil")
151 )
152 ((listp first)
153 ;;(let ((fn (and (symbolp (caar form)) (fboundp (caar form)))))
154 (when (and (not inlist) (not inplace))
155 (insert "\n(list")
156 (setq inlist t))
157 ;;(if (and inplace (not fn) (not (eq (caar form) 'EXPAND)))
158 ;; (insert " (append"))
159 (bovine-grammar-expand-form
160 first quotemode t) ;;(and fn (not (eq fn 'quote))))
161 ;;(if (and inplace (not fn) (not (eq (caar form) 'EXPAND)))
162 ;; (insert ")"))
163 ;;)
164 )
165 ((symbolp first)
166 (setq n (symbol-name first) ;the name
167 q quotemode ;implied quote flag
168 x nil) ;expand flag
169 (if (eq (aref n 0) ?,)
170 (if quotemode
171 ;; backquote mode needs the @
172 (if (eq (aref n 1) ?@)
173 (setq n (substring n 2)
174 q nil
175 x t)
176 ;; non backquote mode behaves normally.
177 (setq n (substring n 1)
178 q nil))
179 (setq n (substring n 1)
180 x t)))
181 (if (string= n "")
182 (progn
183 ;; We expand only the next item in place (a list?)
184 ;; A regular inline-list...
185 (bovine-grammar-expand-form (car form) quotemode t)
186 (setq form (cdr form)))
187 (if (and (eq (aref n 0) ?$)
188 ;; Don't expand $ tokens in implied quote mode.
189 ;; This acts like quoting in other symbols.
190 (not q))
191 (progn
192 (cond
193 ((and (not x) (not inlist) (not inplace))
194 (insert "\n(list"))
195 ((and x inlist (not inplace))
196 (insert ")")
197 (setq inlist nil)))
198 (insert "\n(nth " (int-to-string
199 (1- (string-to-number
200 (substring n 1))))
201 " vals)")
202 (and (not x) (not inplace)
203 (setq inlist t)))
204
205 (when (and (not inlist) (not inplace))
206 (insert "\n(list")
207 (setq inlist t))
208 (or (char-equal (char-before) ?\()
209 (insert " "))
210 (insert (if (or inplace (eq first t))
211 "" "'")
212 n))) ;; " "
213 )
214 (t
215 (when (and (not inlist) (not inplace))
216 (insert "\n(list")
217 (setq inlist t))
218 (insert (format "\n%S" first))
219 )
220 ))
221 (if inlist (insert ")"))
222 (if inplace (insert ")")))
223 ))
224
225(defun bovine-grammar-expand-action (textform quotemode)
226 "Expand semantic action string TEXTFORM into Lisp code.
227QUOTEMODE is the mode in which quoted symbols are slurred."
228 (if (string= "" textform)
229 nil
230 (let ((sexp (read textform)))
231 ;; We converted the lambda string into a list. Now write it
232 ;; out as the bovine lambda expression, and do macro-like
233 ;; conversion upon it.
234 (insert "\n")
235 (cond
236 ((eq (car sexp) 'EXPAND)
237 (insert ",(lambda (vals start end)")
238 ;; The EXPAND macro definition is mandatory
239 (bovine-grammar-expand-form
240 (apply (cdr (assq 'EXPAND bovine--grammar-macros)) (cdr sexp))
241 quotemode t)
242 )
243 ((and (listp (car sexp)) (eq (caar sexp) 'EVAL))
244 ;; The user wants to evaluate the following args.
245 ;; Use a simpler expander
246 )
247 (t
248 (insert ",(semantic-lambda")
249 (bovine-grammar-expand-form sexp quotemode)
250 ))
251 (insert ")\n")))
252)
253
254(defun bovine-grammar-parsetable-builder ()
255 "Return the parser table expression as a string value.
256The format of a bovine parser table is:
257
258 ( ( NONTERMINAL-SYMBOL1 MATCH-LIST1 )
259 ( NONTERMINAL-SYMBOL2 MATCH-LIST2 )
260 ...
261 ( NONTERMINAL-SYMBOLn MATCH-LISTn )
262
263Where each NONTERMINAL-SYMBOL is an artificial symbol which can appear
264in any child state. As a starting place, one of the NONTERMINAL-SYMBOLS
265must be `bovine-toplevel'.
266
267A MATCH-LIST is a list of possible matches of the form:
268
269 ( STATE-LIST1
270 STATE-LIST2
271 ...
272 STATE-LISTN )
273
274where STATE-LIST is of the form:
275 ( TYPE1 [ \"VALUE1\" ] TYPE2 [ \"VALUE2\" ] ... LAMBDA )
276
277where TYPE is one of the returned types of the token stream.
278VALUE is a value, or range of values to match against. For
279example, a SYMBOL might need to match \"foo\". Some TYPES will not
280have matching criteria.
281
282LAMBDA is a lambda expression which is evaled with the text of the
283type when it is found. It is passed the list of all buffer text
284elements found since the last lambda expression. It should return a
285semantic element (see below.)
286
287For consistency between languages, try to use common return values
288from your parser. Please reference the chapter \"Writing Parsers\" in
289the \"Language Support Developer's Guide -\" in the semantic texinfo
290manual."
291 (let* ((start (semantic-grammar-start))
292 (scopestart (semantic-grammar-scopestart))
293 (quotemode (semantic-grammar-quotemode))
294 (tags (semantic-find-tags-by-class
295 'token (current-buffer)))
296 (nterms (semantic-find-tags-by-class
297 'nonterminal (current-buffer)))
298 ;; Setup the cache of macro definitions.
299 (bovine--grammar-macros (semantic-grammar-macros))
300 nterm rules items item actn prec tag type regex)
301
302 ;; Check some trivial things
303 (cond
304 ((null nterms)
305 (error "Bad input grammar"))
306 (start
307 (if (cdr start)
308 (message "Extra start symbols %S ignored" (cdr start)))
309 (setq start (symbol-name (car start)))
310 (unless (semantic-find-first-tag-by-name start nterms)
311 (error "start symbol `%s' has no rule" start)))
312 (t
313 ;; Default to the first grammar rule.
314 (setq start (semantic-tag-name (car nterms)))))
315 (when scopestart
316 (setq scopestart (symbol-name scopestart))
317 (unless (semantic-find-first-tag-by-name scopestart nterms)
318 (error "scopestart symbol `%s' has no rule" scopestart)))
319
320 ;; Generate the grammar Lisp form.
321 (with-temp-buffer
322 (erase-buffer)
323 (insert "`(")
324 ;; Insert the start/scopestart rules
325 (insert "\n(bovine-toplevel \n("
326 start
327 ")\n) ;; end bovine-toplevel\n")
328 (when scopestart
329 (insert "\n(bovine-inner-scope \n("
330 scopestart
331 ")\n) ;; end bovine-inner-scope\n"))
332 ;; Process each nonterminal
333 (while nterms
334 (setq nterm (car nterms)
335 ;; We can't use the override form because the current buffer
336 ;; is not the originator of the tag.
337 rules (semantic-tag-components-semantic-grammar-mode nterm)
338 nterm (semantic-tag-name nterm)
339 nterms (cdr nterms))
340 (when (member nterm '("bovine-toplevel" "bovine-inner-scope"))
341 (error "`%s' is a reserved internal name" nterm))
342 (insert "\n(" nterm)
343 ;; Process each rule
344 (while rules
345 (setq items (semantic-tag-get-attribute (car rules) :value)
346 prec (semantic-tag-get-attribute (car rules) :prec)
347 actn (semantic-tag-get-attribute (car rules) :expr)
348 rules (cdr rules))
349 ;; Process each item
350 (insert "\n(")
351 (if (null items)
352 ;; EMPTY rule
353 (insert ";;EMPTY" (if actn "" "\n"))
354 ;; Expand items
355 (while items
356 (setq item (car items)
357 items (cdr items))
358 (if (consp item) ;; mid-rule action
359 (message "Mid-rule action %S ignored" item)
360 (or (char-equal (char-before) ?\()
361 (insert "\n"))
362 (cond
363 ((member item '("bovine-toplevel" "bovine-inner-scope"))
364 (error "`%s' is a reserved internal name" item))
365 ;; Replace ITEM by its %token definition.
366 ;; If a '%token TYPE ITEM [REGEX]' definition exists
367 ;; in the grammar, ITEM is replaced by TYPE [REGEX].
368 ((setq tag (semantic-find-first-tag-by-name
369 item tags)
370 type (semantic-tag-get-attribute tag :type))
371 (insert type)
372 (if (setq regex (semantic-tag-get-attribute tag :value))
373 (insert (format "\n%S" regex))))
374 ;; Don't change ITEM
375 (t
376 (insert (semantic-grammar-item-text item)))
377 ))))
378 (if prec
379 (message "%%prec %S ignored" prec))
380 (if actn
381 (bovine-grammar-expand-action actn quotemode))
382 (insert ")"))
383 (insert "\n) ;; end " nterm "\n"))
384 (insert ")\n")
385 (buffer-string))))
386
387(defun bovine-grammar-setupcode-builder ()
388 "Return the text of the setup code."
389 (format
390 "(setq semantic--parse-table %s\n\
391 semantic-debug-parser-source %S\n\
392 semantic-debug-parser-class 'semantic-bovine-debug-parser
393 semantic-flex-keywords-obarray %s\n\
394 %s)"
395 (semantic-grammar-parsetable)
396 (buffer-name)
397 (semantic-grammar-keywordtable)
398 (let ((mode (semantic-grammar-languagemode)))
399 ;; Is there more than one major mode?
400 (if (and (listp mode) (> (length mode) 1))
401 (format "semantic-equivalent-major-modes '%S\n" mode)
402 ""))))
403
404(defvar bovine-grammar-menu
405 '("BY Grammar"
406 )
407 "BY mode specific grammar menu.
408Menu items are appended to the common grammar menu.")
409
410(define-derived-mode bovine-grammar-mode semantic-grammar-mode "BY"
411 "Major mode for editing Bovine grammars."
412 (semantic-grammar-setup-menu bovine-grammar-menu)
413 (semantic-install-function-overrides
414 '((grammar-parsetable-builder . bovine-grammar-parsetable-builder)
415 (grammar-setupcode-builder . bovine-grammar-setupcode-builder)
416 )))
417
418(add-to-list 'auto-mode-alist '("\\.by$" . bovine-grammar-mode))
419
420(defvar-mode-local bovine-grammar-mode semantic-grammar-macros
421 '(
422 (ASSOC . semantic-grammar-ASSOC)
423 (EXPAND . bovine-grammar-EXPAND)
424 (EXPANDFULL . bovine-grammar-EXPANDFULL)
425 (TAG . bovine-grammar-TAG)
426 (VARIABLE-TAG . bovine-grammar-VARIABLE-TAG)
427 (FUNCTION-TAG . bovine-grammar-FUNCTION-TAG)
428 (TYPE-TAG . bovine-grammar-TYPE-TAG)
429 (INCLUDE-TAG . bovine-grammar-INCLUDE-TAG)
430 (PACKAGE-TAG . bovine-grammar-PACKAGE-TAG)
431 (CODE-TAG . bovine-grammar-CODE-TAG)
432 (ALIAS-TAG . bovine-grammar-ALIAS-TAG)
433 )
434 "Semantic grammar macros used in bovine grammars.")
435
436(provide 'semantic/bovine/grammar)
437
438
439(defun bovine-make-parsers ()
440 "Generate Emacs' built-in Bovine-based parser files."
441 (semantic-mode 1)
442 ;; Loop through each .by file in current directory, and run
443 ;; `semantic-grammar-batch-build-one-package' to build the grammar.
444 (dolist (f (directory-files default-directory nil ".by$"))
445 (let ((packagename
446 (condition-case err
447 (with-current-buffer (find-file-noselect f)
448 (semantic-grammar-create-package))
449 (error (message "%s" (error-message-string err)) nil)))
450 lang)
451 (when (and packagename
452 (string-match "^semantic-\\(.*\\)-by.el$" packagename))
453 (setq lang (match-string 1 packagename))
454 (with-temp-buffer
455 (insert-file-contents packagename)
456 (setq buffer-file-name (expand-file-name packagename))
457 ;; Fix copyright header:
458 (goto-char (point-min))
459 (re-search-forward "^;; Author:")
460 (setq copyright-end (match-beginning 0))
461 (re-search-forward "^;;; Code:\n")
462 (delete-region copyright-end (match-end 0))
463 (goto-char copyright-end)
464 (insert ";; This file is part of GNU Emacs.
465
466;; GNU Emacs is free software: you can redistribute it and/or modify
467;; it under the terms of the GNU General Public License as published by
468;; the Free Software Foundation, either version 3 of the License, or
469;; (at your option) any later version.
470
471;; GNU Emacs is distributed in the hope that it will be useful,
472;; but WITHOUT ANY WARRANTY; without even the implied warranty of
473;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
474;; GNU General Public License for more details.
475
476;; You should have received a copy of the GNU General Public License
477;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
478
479;;; Commentary:
480;;
481;; This file was generated from etc/grammars/"
482 lang ".by.
483
484;;; Code:
485
486\(require 'semantic/lex)
487\(eval-when-compile (require 'semantic/bovine))\n")
488 (goto-char (point-min))
489 (delete-region (point-min) (line-end-position))
490 (insert ";;; semantic/bovine/" lang
491 "-by.el --- Generated parser support file")
492 (delete-trailing-whitespace)
493 ;; Fix footer:
494 (goto-char (point-max))
495 (re-search-backward ".\n;;; Analyzers")
496 (delete-region (point) (point-max))
497 (insert "(provide 'semantic/bovine/" lang "-by)\n\n")
498 (insert ";;; semantic/bovine/" lang "-by.el ends here\n")
499 (save-buffer))))))
500
501;;; bovine-grammar.el ends here
diff --git a/etc/grammars/c.by b/etc/grammars/c.by
new file mode 100644
index 00000000000..ca54159aa57
--- /dev/null
+++ b/etc/grammars/c.by
@@ -0,0 +1,1202 @@
1;;; c.by -- LL grammar for C/C++ language specification
2
3;; Copyright (C) 1999-2011 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 templateized.
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 somday 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 is 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. Normaly we shoud 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 anoying 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/etc/grammars/grammar.wy b/etc/grammars/grammar.wy
new file mode 100644
index 00000000000..d1a2bf15abf
--- /dev/null
+++ b/etc/grammars/grammar.wy
@@ -0,0 +1,432 @@
1;;; semantic-grammar.wy -- LALR grammar of Semantic input grammars
2;;
3;; Copyright (C) 2002-2011 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 ;; Current parsed nonterminal name.
28 (defvar semantic-grammar-wy--nterm nil)
29 ;; Index of rule in a nonterminal clause.
30 (defvar semantic-grammar-wy--rindx nil)
31 }
32
33%package semantic-grammar-wy
34
35%languagemode wy-mode
36
37;; Main
38%start grammar
39;; Reparse
40%start prologue epilogue declaration nonterminal rule
41;; EXPANDFULL
42%start put_names put_values use_names
43
44;; Keywords
45%type <keyword>
46%keyword DEFAULT-PREC "%default-prec"
47%keyword NO-DEFAULT-PREC "%no-default-prec"
48%keyword KEYWORD "%keyword"
49%keyword LANGUAGEMODE "%languagemode"
50%keyword LEFT "%left"
51%keyword NONASSOC "%nonassoc"
52%keyword PACKAGE "%package"
53%keyword PREC "%prec"
54%keyword PUT "%put"
55%keyword QUOTEMODE "%quotemode"
56%keyword RIGHT "%right"
57%keyword SCOPESTART "%scopestart"
58%keyword START "%start"
59%keyword TOKEN "%token"
60%keyword TYPE "%type"
61%keyword USE-MACROS "%use-macros"
62
63;; Literals
64%type <string>
65%token <string> STRING
66
67%type <symbol> syntax ":?\\(\\sw\\|\\s_\\)+"
68%token <symbol> SYMBOL
69%token <symbol> PERCENT_PERCENT "\\`%%\\'"
70
71%type <char> syntax semantic-grammar-lex-c-char-re
72%token <char> CHARACTER
73
74%type <qlist> matchdatatype sexp syntax "\\s'\\s-*("
75%token <qlist> PREFIXED_LIST
76
77%type <sexp> matchdatatype sexp syntax "\\="
78%token <sexp> SEXP
79
80;; Don't generate these analyzers which needs special handling code.
81%token <code> PROLOGUE "%{...%}"
82%token <code> EPILOGUE "%%...EOF"
83
84;; Blocks & Parenthesis
85%type <block>
86%token <block> PAREN_BLOCK "(LPAREN RPAREN)"
87%token <block> BRACE_BLOCK "(LBRACE RBRACE)"
88%token <open-paren> LPAREN "("
89%token <close-paren> RPAREN ")"
90%token <open-paren> LBRACE "{"
91%token <close-paren> RBRACE "}"
92
93;; Punctuations
94%type <punctuation>
95%token <punctuation> COLON ":"
96%token <punctuation> SEMI ";"
97%token <punctuation> OR "|"
98%token <punctuation> LT "<"
99%token <punctuation> GT ">"
100
101%%
102
103grammar:
104 prologue
105 | epilogue
106 | declaration
107 | nonterminal
108 | PERCENT_PERCENT
109 ;
110
111;;; Prologue/Epilogue
112;;
113prologue:
114 PROLOGUE
115 (CODE-TAG "prologue" nil)
116 ;
117
118epilogue:
119 EPILOGUE
120 (CODE-TAG "epilogue" nil)
121 ;
122
123;;; Declarations
124;;
125declaration:
126 decl
127 (eval $1)
128 ;
129
130decl:
131 default_prec_decl
132 | no_default_prec_decl
133 | languagemode_decl
134 | package_decl
135 | precedence_decl
136 | put_decl
137 | quotemode_decl
138 | scopestart_decl
139 | start_decl
140 | keyword_decl
141 | token_decl
142 | type_decl
143 | use_macros_decl
144 ;
145
146default_prec_decl:
147 DEFAULT-PREC
148 `(TAG "default-prec" 'assoc :value '("t"))
149 ;
150
151no_default_prec_decl:
152 NO-DEFAULT-PREC
153 `(TAG "default-prec" 'assoc :value '("nil"))
154 ;
155
156languagemode_decl:
157 LANGUAGEMODE symbols
158 `(TAG ',(car $2) 'languagemode :rest ',(cdr $2))
159 ;
160
161package_decl:
162 PACKAGE SYMBOL
163 `(PACKAGE-TAG ',$2 nil)
164 ;
165
166precedence_decl:
167 associativity token_type_opt items
168 `(TAG ',$1 'assoc :type ',$2 :value ',$3)
169 ;
170
171associativity:
172 LEFT
173 (progn "left")
174 | RIGHT
175 (progn "right")
176 | NONASSOC
177 (progn "nonassoc")
178 ;
179
180put_decl:
181 PUT put_name put_value
182 `(TAG ',$2 'put :value ',(list $3))
183 | PUT put_name put_value_list
184 `(TAG ',$2 'put :value ',$3)
185 | PUT put_name_list put_value
186 `(TAG ',(car $2) 'put :rest ',(cdr $2) :value ',(list $3))
187 | PUT put_name_list put_value_list
188 `(TAG ',(car $2) 'put :rest ',(cdr $2) :value ',$3)
189 ;
190
191put_name_list:
192 BRACE_BLOCK
193 (mapcar 'semantic-tag-name (EXPANDFULL $1 put_names))
194 ;
195
196put_names:
197 LBRACE
198 ()
199 | RBRACE
200 ()
201 | put_name
202 ;; Must return a list of Semantic tags to EXPANDFULL!
203 (TAG $1 'put-name)
204 ;
205
206put_name:
207 SYMBOL
208 | token_type
209 ;
210
211put_value_list:
212 BRACE_BLOCK
213 (mapcar 'semantic-tag-code-detail (EXPANDFULL $1 put_values))
214 ;
215
216put_values:
217 LBRACE
218 ()
219 | RBRACE
220 ()
221 | put_value
222 ;; Must return a list of Semantic tags to EXPANDFULL!
223 (CODE-TAG "put-value" $1)
224 ;
225
226put_value:
227 SYMBOL any_value
228 (cons $1 $2)
229 ;
230
231scopestart_decl:
232 SCOPESTART SYMBOL
233 `(TAG ',$2 'scopestart)
234 ;
235
236quotemode_decl:
237 QUOTEMODE SYMBOL
238 `(TAG ',$2 'quotemode)
239 ;
240
241start_decl:
242 START symbols
243 `(TAG ',(car $2) 'start :rest ',(cdr $2))
244 ;
245
246keyword_decl:
247 KEYWORD SYMBOL string_value
248 `(TAG ',$2 'keyword :value ',$3)
249 ;
250
251token_decl:
252 TOKEN token_type_opt SYMBOL string_value
253 `(TAG ',$3 ',(if $2 'token 'keyword) :type ',$2 :value ',$4)
254 | TOKEN token_type_opt symbols
255 `(TAG ',(car $3) 'token :type ',$2 :rest ',(cdr $3))
256 ;
257
258token_type_opt:
259 ;; EMPTY
260 | token_type
261 ;
262
263token_type:
264 LT SYMBOL GT
265 (progn $2)
266 ;
267
268type_decl:
269 TYPE token_type plist_opt
270 `(TAG ',$2 'type :value ',$3)
271 ;
272
273plist_opt:
274 ;;EMPTY
275 | plist
276 ;
277
278plist:
279 plist put_value
280 (append (list $2) $1)
281 | put_value
282 (list $1)
283 ;
284
285use_name_list:
286 BRACE_BLOCK
287 (mapcar 'semantic-tag-name (EXPANDFULL $1 use_names))
288 ;
289
290use_names:
291 LBRACE
292 ()
293 | RBRACE
294 ()
295 | SYMBOL
296 ;; Must return a list of Semantic tags to EXPANDFULL!
297 (TAG $1 'use-name)
298 ;
299
300use_macros_decl:
301 USE-MACROS SYMBOL use_name_list
302 `(TAG "macro" 'macro :type ',$2 :value ',$3)
303 ;
304
305string_value:
306 STRING
307 (read $1)
308 ;
309
310;; Return a Lisp readable form
311any_value:
312 SYMBOL
313 | STRING
314 | PAREN_BLOCK
315 | PREFIXED_LIST
316 | SEXP
317 ;
318
319symbols:
320 lifo_symbols
321 (nreverse $1)
322 ;
323
324lifo_symbols:
325 lifo_symbols SYMBOL
326 (cons $2 $1)
327 | SYMBOL
328 (list $1)
329 ;
330
331;;; Grammar rules
332;;
333nonterminal:
334 SYMBOL
335 (setq semantic-grammar-wy--nterm $1
336 semantic-grammar-wy--rindx 0)
337 COLON rules SEMI
338 (TAG $1 'nonterminal :children $4)
339 ;
340
341rules:
342 lifo_rules
343 (apply 'nconc (nreverse $1))
344 ;
345
346lifo_rules:
347 lifo_rules OR rule
348 (cons $3 $1)
349 | rule
350 (list $1)
351 ;
352
353rule:
354 rhs
355 (let* ((nterm semantic-grammar-wy--nterm)
356 (rindx semantic-grammar-wy--rindx)
357 (rhs $1)
358 comps prec action elt)
359 (setq semantic-grammar-wy--rindx (1+ semantic-grammar-wy--rindx))
360 (while rhs
361 (setq elt (car rhs)
362 rhs (cdr rhs))
363 (cond
364 ;; precedence level
365 ((vectorp elt)
366 (if prec
367 (error "Duplicate %%prec in `%s:%d' rule" nterm rindx))
368 (setq prec (aref elt 0)))
369 ;; action
370 ((consp elt)
371 ;; don't forget that rhs items are in reverse order, so
372 ;; the end-of-rule semantic action is the first item.
373 (if (or action comps)
374 ;; a mid-rule action
375 (setq comps (cons elt comps)
376 ;; keep rule and action index synchronized
377 semantic-grammar-wy--rindx
378 (1+ semantic-grammar-wy--rindx))
379 ;; the end-of-rule action
380 (setq action (car elt))))
381 ;; item
382 (t
383 (setq comps (cons elt comps)))))
384 (EXPANDTAG
385 (TAG (format "%s:%d" nterm rindx) 'rule
386 :type (if comps "group" "empty")
387 :value comps :prec prec :expr action)))
388 ;
389
390rhs:
391 ;; EMPTY
392 | rhs item
393 (cons $2 $1)
394 | rhs action
395 (cons (list $2) $1)
396 | rhs PREC item
397 (cons (vector $3) $1)
398 ;
399
400action:
401 PAREN_BLOCK
402 | PREFIXED_LIST
403 | BRACE_BLOCK
404 (format "(progn\n%s)"
405 (let ((s $1))
406 (if (string-match "^{[\r\n\t ]*" s)
407 (setq s (substring s (match-end 0))))
408 (if (string-match "[\r\n\t ]*}$" s)
409 (setq s (substring s 0 (match-beginning 0))))
410 s))
411 ;
412
413items:
414 lifo_items
415 (nreverse $1)
416 ;
417
418lifo_items:
419 lifo_items item
420 (cons $2 $1)
421 | item
422 (list $1)
423 ;
424
425item:
426 SYMBOL
427 | CHARACTER
428 ;
429
430%%
431
432;;; grammar.wy ends here
diff --git a/etc/grammars/java-tags.wy b/etc/grammars/java-tags.wy
new file mode 100644
index 00000000000..99d2b9df81d
--- /dev/null
+++ b/etc/grammars/java-tags.wy
@@ -0,0 +1,750 @@
1;;; java-tags.wy -- Semantic LALR grammar for Java
2
3;; Copyright (C) 2002-2011 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/etc/grammars/js.wy b/etc/grammars/js.wy
new file mode 100644
index 00000000000..f67e2813daf
--- /dev/null
+++ b/etc/grammars/js.wy
@@ -0,0 +1,524 @@
1;;; javascript-jv.wy -- LALR grammar for Javascript
2
3;; Copyright (C) 2005-2011 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 javacript.y names,
70;; but the 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 )
diff --git a/etc/grammars/make.by b/etc/grammars/make.by
new file mode 100644
index 00000000000..dab4472b737
--- /dev/null
+++ b/etc/grammars/make.by
@@ -0,0 +1,168 @@
1;;; make.by -- BY notation for Makefiles.
2
3;; Copyright (C) 1999-2011 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/etc/grammars/python.wy b/etc/grammars/python.wy
new file mode 100644
index 00000000000..44d4394f369
--- /dev/null
+++ b/etc/grammars/python.wy
@@ -0,0 +1,1132 @@
1;;; python.wy -- LALR grammar for Python
2
3;; Copyright (C) 2002-2011 Free Software Foundation, Inc.
4;; Copyright (C) 2001-2010 Python Software Foundation
5
6;; Author: Richard Kim <ryk@dspwiz.com>
7;; Maintainer: Richard Kim <ryk@dspwiz.com>
8;; Created: June 2002
9;; Keywords: syntax
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;;; Commentary:
27;;
28;; This is an LALR python parser that follows the official python
29;; grammar closely with very few exceptions. The Python grammar is
30;; used and reproduced under the following license:
31;;
32;; PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
33;; --------------------------------------------
34;; 1. This LICENSE AGREEMENT is between the Python Software Foundation
35;; ("PSF"), and the Individual or Organization ("Licensee") accessing
36;; and otherwise using this software ("Python") in source or binary
37;; form and its associated documentation.
38;;
39;; 2. Subject to the terms and conditions of this License Agreement,
40;; PSF hereby grants Licensee a nonexclusive, royalty-free, world-wide
41;; license to reproduce, analyze, test, perform and/or display
42;; publicly, prepare derivative works, distribute, and otherwise use
43;; Python alone or in any derivative version, provided, however, that
44;; PSF's License Agreement and PSF's notice of copyright, i.e.,
45;; "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
46;; 2009, 2010 Python Software Foundation; All Rights Reserved" are
47;; retained in Python alone or in any derivative version prepared by
48;; Licensee.
49;;
50;; 3. In the event Licensee prepares a derivative work that is based
51;; on or incorporates Python or any part thereof, and wants to make
52;; the derivative work available to others as provided herein, then
53;; Licensee hereby agrees to include in any such work a brief summary
54;; of the changes made to Python.
55;;
56;; 4. PSF is making Python available to Licensee on an "AS IS"
57;; basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
58;; IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
59;; DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
60;; FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
61;; INFRINGE ANY THIRD PARTY RIGHTS.
62;;
63;; 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
64;; FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A
65;; RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, OR
66;; ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
67;;
68;; 6. This License Agreement will automatically terminate upon a
69;; material breach of its terms and conditions.
70;;
71;; 7. Nothing in this License Agreement shall be deemed to create any
72;; relationship of agency, partnership, or joint venture between PSF
73;; and Licensee. This License Agreement does not grant permission to
74;; use PSF trademarks or trade name in a trademark sense to endorse or
75;; promote products or services of Licensee, or any third party.
76;;
77;; 8. By copying, installing or otherwise using Python, Licensee
78;; agrees to be bound by the terms and conditions of this License
79;; Agreement.
80
81;;; To do:
82;;
83;; * Verify that semantic-lex-python-number regexp is correct.
84
85;; --------
86;; Settings
87;; --------
88
89%package wisent-python-wy
90
91%languagemode python-mode
92
93;; The default start symbol
94%start goal
95;; Alternate entry points
96;; - Needed by partial re-parse
97%start function_parameter
98%start paren_class
99%start indented_block
100;; - Needed by EXPANDFULL clauses
101%start function_parameters
102%start paren_classes
103%start indented_block_body
104
105;; -------------------------------
106;; Misc. Python specific terminals
107;; -------------------------------
108;; The value of these tokens are for documentation only, they are not
109;; used by the lexer.
110%token <charquote> BACKSLASH "\\"
111%token <newline> NEWLINE "\n"
112%token <indentation> INDENT "^\\s-+"
113%token <indentation> DEDENT "[^:INDENT:]"
114%token <indentation> INDENT_BLOCK "(INDENT DEDENT)"
115
116;; -----------------------------
117;; Block & Parenthesis terminals
118;; -----------------------------
119%type <block> ;;syntax "\\s(\\|\\s)" matchdatatype block
120
121%token <block> PAREN_BLOCK "(LPAREN RPAREN)"
122%token <block> BRACE_BLOCK "(LBRACE RBRACE)"
123%token <block> BRACK_BLOCK "(LBRACK RBRACK)"
124
125%token <open-paren> LPAREN "("
126%token <close-paren> RPAREN ")"
127%token <open-paren> LBRACE "{"
128%token <close-paren> RBRACE "}"
129%token <open-paren> LBRACK "["
130%token <close-paren> RBRACK "]"
131
132;; ------------------
133;; Operator terminals
134;; ------------------
135%type <punctuation> ;;syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string
136
137%token <punctuation> LTLTEQ "<<="
138%token <punctuation> GTGTEQ ">>="
139%token <punctuation> EXPEQ "**="
140%token <punctuation> DIVDIVEQ "//="
141%token <punctuation> DIVDIV "//"
142%token <punctuation> LTLT "<<"
143%token <punctuation> GTGT ">>"
144%token <punctuation> EXPONENT "**"
145%token <punctuation> EQ "=="
146%token <punctuation> GE ">="
147%token <punctuation> LE "<="
148%token <punctuation> PLUSEQ "+="
149%token <punctuation> MINUSEQ "-="
150%token <punctuation> MULTEQ "*="
151%token <punctuation> DIVEQ "/="
152%token <punctuation> MODEQ "%="
153%token <punctuation> AMPEQ "&="
154%token <punctuation> OREQ "|="
155%token <punctuation> HATEQ "^="
156%token <punctuation> LTGT "<>"
157%token <punctuation> NE "!="
158%token <punctuation> HAT "^"
159%token <punctuation> LT "<"
160%token <punctuation> GT ">"
161%token <punctuation> AMP "&"
162%token <punctuation> MULT "*"
163%token <punctuation> DIV "/"
164%token <punctuation> MOD "%"
165%token <punctuation> PLUS "+"
166%token <punctuation> MINUS "-"
167%token <punctuation> PERIOD "."
168%token <punctuation> TILDE "~"
169%token <punctuation> BAR "|"
170%token <punctuation> COLON ":"
171%token <punctuation> SEMICOLON ";"
172%token <punctuation> COMMA ","
173%token <punctuation> ASSIGN "="
174%token <punctuation> BACKQUOTE "`"
175
176
177;; -----------------
178;; Literal terminals
179;; -----------------
180%token <string> STRING_LITERAL
181
182%type <number> ;;syntax semantic-lex-number-expression
183%token <number> NUMBER_LITERAL
184
185%type <symbol> ;;syntax "\\(\\sw\\|\\s_\\)+"
186%token <symbol> NAME
187
188;; -----------------
189;; Keyword terminals
190;; -----------------
191%type <keyword> ;;syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword
192
193%keyword AND "and"
194%put AND summary
195"Logical AND binary operator ... "
196
197%keyword AS "as"
198%put AS summary
199"EXPR as NAME makes value of EXPR available as variable NAME"
200
201%keyword ASSERT "assert"
202%put ASSERT summary
203"Raise AssertionError exception if <expr> is false"
204
205%keyword BREAK "break"
206%put BREAK summary
207"Terminate 'for' or 'while' loop"
208
209%keyword CLASS "class"
210%put CLASS summary
211"Define a new class"
212
213%keyword CONTINUE "continue"
214%put CONTINUE summary
215"Skip to the next iteration of enclosing 'for' or 'while' loop"
216
217%keyword DEF "def"
218%put DEF summary
219"Define a new function"
220
221%keyword DEL "del"
222%put DEL summary
223"Delete specified objects, i.e., undo what assignment did"
224
225%keyword ELIF "elif"
226%put ELIF summary
227"Shorthand for 'else if' following an 'if' statement"
228
229%keyword ELSE "else"
230%put ELSE summary
231"Start the 'else' clause following an 'if' statement"
232
233%keyword EXCEPT "except"
234%put EXCEPT summary
235"Specify exception handlers along with 'try' keyword"
236
237%keyword EXEC "exec"
238%put EXEC summary
239"Dynamically execute Python code"
240
241%keyword FINALLY "finally"
242%put FINALLY summary
243"Specify code to be executed after 'try' statements whether or not an exception occurred"
244
245%keyword FOR "for"
246%put FOR summary
247"Start a 'for' loop"
248
249%keyword FROM "from"
250%put FROM summary
251"Modify behavior of 'import' statement"
252
253%keyword GLOBAL "global"
254%put GLOBAL summary
255"Declare one or more symbols as global symbols"
256
257%keyword IF "if"
258%put IF summary
259"Start 'if' conditional statement"
260
261%keyword IMPORT "import"
262%put IMPORT summary
263"Load specified modules"
264
265%keyword IN "in"
266%put IN summary
267"Part of 'for' statement "
268
269%keyword IS "is"
270%put IS summary
271"Binary operator that tests for object equality"
272
273%keyword LAMBDA "lambda"
274%put LAMBDA summary
275"Create anonymous function"
276
277%keyword NOT "not"
278%put NOT summary
279"Unary boolean negation operator"
280
281%keyword OR "or"
282%put OR summary
283"Binary logical 'or' operator"
284
285%keyword PASS "pass"
286%put PASS summary
287"Statement that does nothing"
288
289%keyword PRINT "print"
290%put PRINT summary
291"Print each argument to standard output"
292
293%keyword RAISE "raise"
294%put RAISE summary
295"Raise an exception"
296
297%keyword RETURN "return"
298%put RETURN summary
299"Return from a function"
300
301%keyword TRY "try"
302%put TRY summary
303"Start of statements protected by exception handlers"
304
305%keyword WHILE "while"
306%put WHILE summary
307"Start a 'while' loop"
308
309%keyword YIELD "yield"
310%put YIELD summary
311"Create a generator function"
312
313%%
314
315;;;****************************************************************************
316;;;@ goal
317;;;****************************************************************************
318
319;; simple_stmt are statements that do not involve INDENT tokens
320;; compound_stmt are statements that involve INDENT tokens
321goal
322 : NEWLINE
323 | simple_stmt
324 | compound_stmt
325 ;
326
327;;;****************************************************************************
328;;;@ simple_stmt
329;;;****************************************************************************
330
331;; simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
332simple_stmt
333 : small_stmt_list semicolon_opt NEWLINE
334 ;
335
336;; small_stmt (';' small_stmt)*
337small_stmt_list
338 : small_stmt
339 | small_stmt_list SEMICOLON small_stmt
340 ;
341
342small_stmt
343 : expr_stmt
344 | print_stmt
345 | del_stmt
346 | pass_stmt
347 | flow_stmt
348 | import_stmt
349 | global_stmt
350 | exec_stmt
351 | assert_stmt
352 ;
353
354;;;============================================================================
355;;;@@ print_stmt
356;;;============================================================================
357
358;; print_stmt: 'print' [ test (',' test)* [','] ]
359;; | '>>' test [ (',' test)+ [','] ]
360print_stmt
361 : PRINT print_stmt_trailer
362 (CODE-TAG $1 nil)
363 ;
364
365;; [ test (',' test)* [','] ] | '>>' test [ (',' test)+ [','] ]
366print_stmt_trailer
367 : test_list_opt
368 ()
369 | GTGT test trailing_test_list_with_opt_comma_opt
370 ()
371 ;
372
373;; [ (',' test)+ [','] ]
374trailing_test_list_with_opt_comma_opt
375 : ;;EMPTY
376 | trailing_test_list comma_opt
377 ()
378 ;
379
380;; (',' test)+
381trailing_test_list
382 : COMMA test
383 ()
384 | trailing_test_list COMMA test
385 ()
386 ;
387
388;;;============================================================================
389;;;@@ expr_stmt
390;;;============================================================================
391
392;; expr_stmt: testlist (augassign testlist | ('=' testlist)*)
393expr_stmt
394 : testlist expr_stmt_trailer
395 (if (and $2 (stringp $1) (string-match "^\\(\\sw\\|\\s_\\)+$" $1))
396 ;; If this is an assignment statement and left side is a symbol,
397 ;; then generate a 'variable token, else return 'code token.
398 (VARIABLE-TAG $1 nil nil)
399 (CODE-TAG $1 nil))
400 ;
401
402;; Could be EMPTY because of eq_testlist_zom.
403;; (augassign testlist | ('=' testlist)*)
404expr_stmt_trailer
405 : augassign testlist
406 | eq_testlist_zom
407 ;
408
409;; Could be EMPTY!
410;; ('=' testlist)*
411eq_testlist_zom
412 : ;;EMPTY
413 | eq_testlist_zom ASSIGN testlist
414 (identity $3)
415 ;
416
417;; augassign: '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^='
418;; | '<<=' | '>>=' | '**=' | '//='
419augassign
420 : PLUSEQ | MINUSEQ | MULTEQ | DIVEQ | MODEQ
421 | AMPEQ | OREQ | HATEQ | LTLTEQ
422 | GTGTEQ | EXPEQ | DIVDIVEQ
423 ;
424
425;;;============================================================================
426;;;@@ del_stmt
427;;;============================================================================
428
429;; del_stmt: 'del' exprlist
430del_stmt
431 : DEL exprlist
432 (CODE-TAG $1 nil)
433 ;
434
435;; exprlist: expr (',' expr)* [',']
436exprlist
437 : expr_list comma_opt
438 ()
439 ;
440
441;; expr (',' expr)*
442expr_list
443 : expr
444 ()
445 | expr_list COMMA expr
446 ()
447 ;
448
449;;;============================================================================
450;;;@@ pass_stmt
451;;;============================================================================
452
453;; pass_stmt: 'pass'
454pass_stmt
455 : PASS
456 (CODE-TAG $1 nil)
457 ;
458
459;;;============================================================================
460;;;@@ flow_stmt
461;;;============================================================================
462
463flow_stmt
464 : break_stmt
465 | continue_stmt
466 | return_stmt
467 | raise_stmt
468 | yield_stmt
469 ;
470
471;; break_stmt: 'break'
472break_stmt
473 : BREAK
474 (CODE-TAG $1 nil)
475 ;
476
477;; continue_stmt: 'continue'
478continue_stmt
479 : CONTINUE
480 (CODE-TAG $1 nil)
481 ;
482
483;; return_stmt: 'return' [testlist]
484return_stmt
485 : RETURN testlist_opt
486 (CODE-TAG $1 nil)
487 ;
488
489;; [testlist]
490testlist_opt
491 : ;;EMPTY
492 | testlist
493 ()
494 ;
495
496;; yield_stmt: 'yield' testlist
497yield_stmt
498 : YIELD
499 (CODE-TAG $1 nil)
500 | YIELD testlist
501 (CODE-TAG $1 nil)
502 ;
503
504;; raise_stmt: 'raise' [test [',' test [',' test]]]
505raise_stmt
506 : RAISE zero_one_two_or_three_tests
507 (CODE-TAG $1 nil)
508 ;
509
510;; [test [',' test [',' test]]]
511zero_one_two_or_three_tests
512 : ;;EMPTY
513 | test zero_one_or_two_tests
514 ()
515 ;
516
517;; [',' test [',' test]]
518zero_one_or_two_tests
519 : ;;EMPTY
520 | COMMA test zero_or_one_comma_test
521 ()
522 ;
523
524;; [',' test]
525zero_or_one_comma_test
526 : ;;EMPTY
527 | COMMA test
528 ()
529 ;
530
531;;;============================================================================
532;;;@@ import_stmt
533;;;============================================================================
534
535;; import_stmt : 'import' dotted_as_name (',' dotted_as_name)*
536;; | 'from' dotted_name 'import'
537;; ('*' | import_as_name (',' import_as_name)*)
538import_stmt
539 : IMPORT dotted_as_name_list
540 (INCLUDE-TAG $2 nil)
541 | FROM dotted_name IMPORT star_or_import_as_name_list
542 (INCLUDE-TAG $2 nil)
543 ;
544
545;; dotted_as_name (',' dotted_as_name)*
546dotted_as_name_list
547 : dotted_as_name
548 | dotted_as_name_list COMMA dotted_as_name
549 ;
550
551;; ('*' | import_as_name (',' import_as_name)*)
552star_or_import_as_name_list
553 : MULT
554 ()
555 | import_as_name_list
556 ()
557 ;
558
559;; import_as_name (',' import_as_name)*
560import_as_name_list
561 : import_as_name
562 ()
563 | import_as_name_list COMMA import_as_name
564 ()
565 ;
566
567;; import_as_name: NAME [NAME NAME]
568import_as_name
569 : NAME as_name_opt
570 ()
571 ;
572
573;; dotted_as_name: dotted_name [AS NAME]
574dotted_as_name
575 : dotted_name as_name_opt
576 ;
577
578;; [AS NAME]
579as_name_opt
580 : ;;EMPTY
581 | AS NAME
582 (identity $2)
583 ;
584
585;; dotted_name: NAME ('.' NAME)*
586dotted_name
587 : NAME
588 | dotted_name PERIOD NAME
589 (format "%s.%s" $1 $3)
590 ;
591
592;;;============================================================================
593;;;@@ global_stmt
594;;;============================================================================
595
596;; global_stmt: 'global' NAME (',' NAME)*
597global_stmt
598 : GLOBAL comma_sep_name_list
599 (CODE-TAG $1 nil)
600 ;
601
602;; NAME (',' NAME)*
603comma_sep_name_list
604 : NAME
605 | comma_sep_name_list COMMA NAME
606 ;
607
608;;;============================================================================
609;;;@@ exec_stmt
610;;;============================================================================
611
612;; exec_stmt: 'exec' expr ['in' test [',' test]]
613exec_stmt
614 : EXEC expr exec_trailer
615 (CODE-TAG $1 nil)
616 ;
617
618;; ['in' test [',' test]]
619exec_trailer
620 : ;;EMPTY
621 | IN test comma_test_opt
622 ()
623 ;
624
625;; [',' test]
626comma_test_opt
627 : ;;EMPTY
628 | COMMA test
629 ()
630 ;
631
632;;;============================================================================
633;;;@@ assert_stmt
634;;;============================================================================
635
636;; assert_stmt: 'assert' test [',' test]
637assert_stmt
638 : ASSERT test comma_test_opt
639 (CODE-TAG $1 nil)
640 ;
641
642;;;****************************************************************************
643;;;@ compound_stmt
644;;;****************************************************************************
645
646compound_stmt
647 : if_stmt
648 | while_stmt
649 | for_stmt
650 | try_stmt
651 | funcdef
652 | class_declaration
653 ;
654
655;;;============================================================================
656;;;@@ if_stmt
657;;;============================================================================
658
659;; if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
660if_stmt
661 : IF test COLON suite elif_suite_pair_list else_suite_pair_opt
662 (CODE-TAG $1 nil)
663 ;
664
665;; ('elif' test ':' suite)*
666elif_suite_pair_list
667 : ;;EMPTY
668 | elif_suite_pair_list ELIF test COLON suite
669 ()
670 ;
671
672;; ['else' ':' suite]
673else_suite_pair_opt
674 : ;;EMPTY
675 | ELSE COLON suite
676 ()
677 ;
678
679;; This NT follows the COLON token for most compound statements.
680;; suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT
681suite
682 : simple_stmt
683 (list $1)
684 | NEWLINE indented_block
685 (progn $2)
686 ;
687
688indented_block
689 : INDENT_BLOCK
690 (EXPANDFULL $1 indented_block_body)
691 ;
692
693indented_block_body
694 : INDENT
695 ()
696 | DEDENT
697 ()
698 | simple_stmt
699 | compound_stmt
700 ;
701
702;;;============================================================================
703;;;@@ while_stmt
704;;;============================================================================
705
706;; while_stmt: 'while' test ':' suite ['else' ':' suite]
707while_stmt
708 : WHILE test COLON suite else_suite_pair_opt
709 (CODE-TAG $1 nil)
710 ;
711
712;;;============================================================================
713;;;@@ for_stmt
714;;;============================================================================
715
716;; for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
717for_stmt
718 : FOR exprlist IN testlist COLON suite else_suite_pair_opt
719 (CODE-TAG $1 nil)
720 ;
721
722;;;============================================================================
723;;;@@ try_stmt
724;;;============================================================================
725
726;; try_stmt: ('try' ':' suite (except_clause ':' suite)+ #diagram:break
727;; ['else' ':' suite] | 'try' ':' suite 'finally' ':' suite)
728try_stmt
729 : TRY COLON suite except_clause_suite_pair_list else_suite_pair_opt
730 (CODE-TAG $1 nil)
731 | TRY COLON suite FINALLY COLON suite
732 (CODE-TAG $1 nil)
733 ;
734
735;; (except_clause ':' suite)+
736except_clause_suite_pair_list
737 : except_clause COLON suite
738 ()
739 | except_clause_suite_pair_list except_clause COLON suite
740 ()
741 ;
742
743;; # NB compile.c makes sure that the default except clause is last
744;; except_clause: 'except' [test [',' test]]
745except_clause
746 : EXCEPT zero_one_or_two_test
747 ()
748 ;
749
750;; [test [',' test]]
751zero_one_or_two_test
752 : ;;EMPTY
753 | test zero_or_one_comma_test
754 ()
755 ;
756
757;;;============================================================================
758;;;@@ funcdef
759;;;============================================================================
760
761;; funcdef: 'def' NAME parameters ':' suite
762funcdef
763 : DEF NAME function_parameter_list COLON suite
764 (FUNCTION-TAG $2 nil $3)
765 ;
766
767function_parameter_list
768 : PAREN_BLOCK
769 (let ((wisent-python-EXPANDING-block t))
770 (EXPANDFULL $1 function_parameters))
771 ;
772
773;; parameters: '(' [varargslist] ')'
774function_parameters
775 : LPAREN
776 ()
777 | RPAREN
778 ()
779 | function_parameter COMMA
780 | function_parameter RPAREN
781 ;
782
783function_parameter
784 : fpdef_opt_test
785 ;; : NAME
786 ;; (VARIABLE-TAG $1 nil nil)
787 | MULT NAME
788 (VARIABLE-TAG $2 nil nil)
789 | EXPONENT NAME
790 (VARIABLE-TAG $2 nil nil)
791 ;
792
793;;;============================================================================
794;;;@@ class_declaration
795;;;============================================================================
796
797;; classdef: 'class' NAME ['(' testlist ')'] ':' suite
798class_declaration
799 : CLASS NAME paren_class_list_opt COLON suite
800 (TYPE-TAG $2 $1 ;; Name "class"
801 $5 ;; Members
802 (cons $3 nil) ;; (SUPERCLASSES . INTERFACES)
803 )
804 ;
805
806;; ['(' testlist ')']
807paren_class_list_opt
808 : ;;EMPTY
809 | paren_class_list
810 ;
811
812paren_class_list
813 : PAREN_BLOCK
814 (let ((wisent-python-EXPANDING-block t))
815 (mapcar 'semantic-tag-name (EXPANDFULL $1 paren_classes)))
816 ;
817
818;; parameters: '(' [varargslist] ')'
819paren_classes
820 : LPAREN
821 ()
822 | RPAREN
823 ()
824 | paren_class COMMA
825 (VARIABLE-TAG $1 nil nil)
826 | paren_class RPAREN
827 (VARIABLE-TAG $1 nil nil)
828 ;
829
830;; In general, the base class can be specified by a general expression
831;; which evalue to a class object, i.e., base classes are not just names!
832;; However base classes are names in most cases. Thus the
833;; non-terminals below work only with simple names. Even if the
834;; parser can parse general expressions, I don't see much benefit in
835;; generating a string of expression as base class "name".
836paren_class
837 : dotted_name
838 ;
839
840;;;****************************************************************************
841;;;@ test
842;;;****************************************************************************
843
844;; test: and_test ('or' and_test)* | lambdef
845test
846 : test_test
847 | lambdef
848 ;
849
850;; and_test ('or' and_test)*
851test_test
852 : and_test
853 | test_test OR and_test
854 ()
855 ;
856
857;; and_test: not_test ('and' not_test)*
858and_test
859 : not_test
860 | and_test AND not_test
861 ()
862 ;
863
864;; not_test: 'not' not_test | comparison
865not_test
866 : NOT not_test
867 ()
868 | comparison
869 ;
870
871;; comparison: expr (comp_op expr)*
872comparison
873 : expr
874 | comparison comp_op expr
875 ()
876 ;
877
878;; comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
879comp_op
880 : LT | GT | EQ | GE | LE | LTGT | NE | IN | NOT IN | IS | IS NOT
881 ;
882
883;; expr: xor_expr ('|' xor_expr)*
884expr
885 : xor_expr
886 | expr BAR xor_expr
887 ()
888 ;
889
890;; xor_expr: and_expr ('^' and_expr)*
891xor_expr
892 : and_expr
893 | xor_expr HAT and_expr
894 ()
895 ;
896
897;; and_expr: shift_expr ('&' shift_expr)*
898and_expr
899 : shift_expr
900 | and_expr AMP shift_expr
901 ()
902 ;
903
904;; shift_expr: arith_expr (('<<'|'>>') arith_expr)*
905shift_expr
906 : arith_expr
907 | shift_expr shift_expr_operators arith_expr
908 ()
909 ;
910
911;; ('<<'|'>>')
912shift_expr_operators
913 : LTLT
914 | GTGT
915 ;
916
917;; arith_expr: term (('+'|'-') term)*
918arith_expr
919 : term
920 | arith_expr plus_or_minus term
921 ()
922 ;
923
924;; ('+'|'-')
925plus_or_minus
926 : PLUS
927 | MINUS
928 ;
929
930;; term: factor (('*'|'/'|'%'|'//') factor)*
931term
932 : factor
933 | term term_operator factor
934 ()
935 ;
936
937term_operator
938 : MULT
939 | DIV
940 | MOD
941 | DIVDIV
942 ;
943
944;; factor: ('+'|'-'|'~') factor | power
945factor
946 : prefix_operators factor
947 ()
948 | power
949 ;
950
951;; ('+'|'-'|'~')
952prefix_operators
953 : PLUS
954 | MINUS
955 | TILDE
956 ;
957
958;; power: atom trailer* ('**' factor)*
959power
960 : atom trailer_zom exponent_zom
961 (concat $1
962 (if $2 (concat " " $2 " ") "")
963 (if $3 (concat " " $3) "")
964 )
965 ;
966
967trailer_zom
968 : ;;EMPTY
969 | trailer_zom trailer
970 ()
971 ;
972
973exponent_zom
974 : ;;EMPTY
975 | exponent_zom EXPONENT factor
976 ()
977 ;
978
979;; trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
980trailer
981 : PAREN_BLOCK
982 ()
983 | BRACK_BLOCK
984 ()
985 | PERIOD NAME
986 ()
987 ;
988
989;; atom: '(' [testlist] ')' | '[' [listmaker] ']' | '{' [dictmaker] '}'
990;; | '`' testlist '`' | NAME | NUMBER | STRING+
991atom
992 : PAREN_BLOCK
993 ()
994 | BRACK_BLOCK
995 ()
996 | BRACE_BLOCK
997 ()
998 | BACKQUOTE testlist BACKQUOTE
999 ()
1000 | NAME
1001 | NUMBER_LITERAL
1002 | one_or_more_string
1003 ;
1004
1005test_list_opt
1006 : ;;EMPTY
1007 | testlist
1008 ()
1009 ;
1010
1011;; testlist: test (',' test)* [',']
1012testlist
1013 : comma_sep_test_list comma_opt
1014 ;
1015
1016;; test (',' test)*
1017comma_sep_test_list
1018 : test
1019 | comma_sep_test_list COMMA test
1020 (format "%s, %s" $1 $3)
1021 ;
1022
1023;; (read $1) and (read $2) were done before to peel away the double quotes.
1024;; However that does not work for single quotes, so it was taken out.
1025one_or_more_string
1026 : STRING_LITERAL
1027 | one_or_more_string STRING_LITERAL
1028 (concat $1 $2)
1029 ;
1030
1031;;;****************************************************************************
1032;;;@ lambdef
1033;;;****************************************************************************
1034
1035;; lambdef: 'lambda' [varargslist] ':' test
1036lambdef
1037 : LAMBDA varargslist_opt COLON test
1038 (format "%s %s" $1 (or $2 ""))
1039 ;
1040
1041;; [varargslist]
1042varargslist_opt
1043 : ;;EMPTY
1044 | varargslist
1045 ;
1046
1047;; varargslist: (fpdef ['=' test] ',')* ('*' NAME [',' '**' NAME] | '**' NAME)
1048;; | fpdef ['=' test] (',' fpdef ['=' test])* [',']
1049varargslist
1050 : fpdef_opt_test_list_comma_zom rest_args
1051 (nconc $2 $1)
1052 | fpdef_opt_test_list comma_opt
1053 ;
1054
1055;; ('*' NAME [',' '**' NAME] | '**' NAME)
1056rest_args
1057 : MULT NAME multmult_name_opt
1058 () ;;(VARIABLE-TAG $2 nil nil)
1059 | EXPONENT NAME
1060 () ;;(VARIABLE-TAG $2 nil nil)
1061 ;
1062
1063;; [',' '**' NAME]
1064multmult_name_opt
1065 : ;;EMPTY
1066 | COMMA EXPONENT NAME
1067 (VARIABLE-TAG $3 nil nil)
1068 ;
1069
1070fpdef_opt_test_list_comma_zom
1071 : ;;EMPTY
1072 | fpdef_opt_test_list_comma_zom fpdef_opt_test COMMA
1073 (nconc $2 $1)
1074 ;
1075
1076;; fpdef ['=' test] (',' fpdef ['=' test])*
1077fpdef_opt_test_list
1078 : fpdef_opt_test
1079 | fpdef_opt_test_list COMMA fpdef_opt_test
1080 (nconc $3 $1)
1081 ;
1082
1083;; fpdef ['=' test]
1084fpdef_opt_test
1085 : fpdef eq_test_opt
1086 ;
1087
1088;; fpdef: NAME | '(' fplist ')'
1089fpdef
1090 : NAME
1091 (VARIABLE-TAG $1 nil nil)
1092 ;; Below breaks the parser. Don't know why, but my guess is that
1093 ;; LPAREN/RPAREN clashes with the ones in function_parameters.
1094 ;; | LPAREN fplist RPAREN
1095 ;; (identity $2)
1096 ;
1097
1098;; fplist: fpdef (',' fpdef)* [',']
1099fplist
1100 : fpdef_list comma_opt
1101 ;
1102
1103;; fpdef (',' fpdef)*
1104fpdef_list
1105 : fpdef
1106 | fpdef_list COMMA fpdef
1107 ;
1108
1109;; ['=' test]
1110eq_test_opt
1111 : ;;EMPTY
1112 | ASSIGN test
1113 ()
1114 ;
1115
1116;;;****************************************************************************
1117;;;@ Misc
1118;;;****************************************************************************
1119
1120;; [',']
1121comma_opt
1122 : ;;EMPTY
1123 | COMMA
1124 ;
1125
1126;; [';']
1127semicolon_opt
1128 : ;;EMPTY
1129 | SEMICOLON
1130 ;
1131
1132;;; wisent-python.wy ends here
diff --git a/etc/grammars/scheme.by b/etc/grammars/scheme.by
new file mode 100644
index 00000000000..bc6612d4c70
--- /dev/null
+++ b/etc/grammars/scheme.by
@@ -0,0 +1,84 @@
1;;; scheme.by -- Scheme BNF language specification
2
3;; Copyright (C) 2001-2011 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/etc/grammars/srecode-template.wy b/etc/grammars/srecode-template.wy
new file mode 100644
index 00000000000..4ff2d7e4e41
--- /dev/null
+++ b/etc/grammars/srecode-template.wy
@@ -0,0 +1,235 @@
1;;; srecode-template.wy --- Semantic Recoder Template parser
2
3;; Copyright (C) 2005-2011 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/etc/grammars/wisent-grammar.el b/etc/grammars/wisent-grammar.el
new file mode 100644
index 00000000000..67b6032ea4e
--- /dev/null
+++ b/etc/grammars/wisent-grammar.el
@@ -0,0 +1,542 @@
1;;; wisent-grammar.el --- Wisent's input grammar mode
2
3;; Copyright (C) 2002-2011 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
362(defvar wisent-make-parsers--emacs-license
363 ";; This file is part of GNU Emacs.
364
365;; GNU Emacs is free software: you can redistribute it and/or modify
366;; it under the terms of the GNU General Public License as published by
367;; the Free Software Foundation, either version 3 of the License, or
368;; (at your option) any later version.
369
370;; GNU Emacs is distributed in the hope that it will be useful,
371;; but WITHOUT ANY WARRANTY; without even the implied warranty of
372;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
373;; GNU General Public License for more details.
374
375;; You should have received a copy of the GNU General Public License
376;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.")
377
378(defvar wisent-make-parsers--python-license
379 ";; It is derived in part from the Python grammar, used under the
380;; following license:
381;;
382;; PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
383;; --------------------------------------------
384;; 1. This LICENSE AGREEMENT is between the Python Software Foundation
385;; (\"PSF\"), and the Individual or Organization (\"Licensee\") accessing
386;; and otherwise using this software (\"Python\") in source or binary
387;; form and its associated documentation.
388;;
389;; 2. Subject to the terms and conditions of this License Agreement,
390;; PSF hereby grants Licensee a nonexclusive, royalty-free, world-wide
391;; license to reproduce, analyze, test, perform and/or display
392;; publicly, prepare derivative works, distribute, and otherwise use
393;; Python alone or in any derivative version, provided, however, that
394;; PSF's License Agreement and PSF's notice of copyright, i.e.,
395;; \"Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
396;; 2009, 2010 Python Software Foundation; All Rights Reserved\" are
397;; retained in Python alone or in any derivative version prepared by
398;; Licensee.
399;;
400;; 3. In the event Licensee prepares a derivative work that is based
401;; on or incorporates Python or any part thereof, and wants to make
402;; the derivative work available to others as provided herein, then
403;; Licensee hereby agrees to include in any such work a brief summary
404;; of the changes made to Python.
405;;
406;; 4. PSF is making Python available to Licensee on an \"AS IS\"
407;; basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
408;; IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
409;; DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
410;; FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
411;; INFRINGE ANY THIRD PARTY RIGHTS.
412;;
413;; 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
414;; FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A
415;; RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, OR
416;; ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
417;;
418;; 6. This License Agreement will automatically terminate upon a
419;; material breach of its terms and conditions.
420;;
421;; 7. Nothing in this License Agreement shall be deemed to create any
422;; relationship of agency, partnership, or joint venture between PSF
423;; and Licensee. This License Agreement does not grant permission to
424;; use PSF trademarks or trade name in a trademark sense to endorse or
425;; promote products or services of Licensee, or any third party.
426;;
427;; 8. By copying, installing or otherwise using Python, Licensee
428;; agrees to be bound by the terms and conditions of this License
429;; Agreement.")
430
431(defvar wisent-make-parsers--ecmascript-license
432 "\n;; It is derived from the grammar in the ECMAScript Language
433;; Specification published at
434;;
435;; http://www.ecma-international.org/publications/standards/Ecma-262.htm
436;;
437;; and redistributed under the following license:
438;;
439;; Redistribution and use in source and binary forms, with or without
440;; modification, are permitted provided that the following conditions
441;; are met:
442;;
443;; 1. Redistributions of source code must retain the above copyright
444;; notice, this list of conditions and the following disclaimer.
445;;
446;; 2. Redistributions in binary form must reproduce the above
447;; copyright notice, this list of conditions and the following
448;; disclaimer in the documentation and/or other materials provided
449;; with the distribution.
450;;
451;; 3. Neither the name of the authors nor Ecma International may be
452;; used to endorse or promote products derived from this software
453;; without specific prior written permission. THIS SOFTWARE IS
454;; PROVIDED BY THE ECMA INTERNATIONAL \"AS IS\" AND ANY EXPRESS OR
455;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
456;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
457;; ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR
458;; ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
459;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
460;; OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
461;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
462;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
463;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
464;; USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
465;; DAMAGE.")
466
467(defvar wisent-make-parsers--parser-file-name
468 `(("semantic-grammar-wy.el"
469 "semantic/grammar-wy")
470 ("srecode-template-wy.el"
471 "srecode/srt-wy")
472 ("wisent-javascript-jv-wy.el"
473 "semantic/wisent/js-wy"
474 "Copyright (C) 1998-2011 Ecma International"
475 ,wisent-make-parsers--ecmascript-license)
476 ("wisent-java-tags-wy.el"
477 "semantic/wisent/javat-wy")
478 ("wisent-python-wy.el"
479 "semantic/wisent/python-wy"
480 "Copyright (C) 2001-2010 Python Software Foundation"
481 ,wisent-make-parsers--python-license)))
482
483(defun wisent-make-parsers ()
484 "Generate Emacs' built-in Wisent-based parser files."
485 (semantic-mode 1)
486 ;; Loop through each .wy file in current directory, and run
487 ;; `semantic-grammar-batch-build-one-package' to build the grammar.
488 (dolist (f (directory-files default-directory nil ".wy$"))
489 (let ((packagename
490 (condition-case err
491 (with-current-buffer (find-file-noselect f)
492 (semantic-grammar-create-package))
493 (error (message "%s" (error-message-string err)) nil)))
494 output-data)
495 (when (setq output-data (assoc packagename wisent-make-parsers--parser-file-name))
496 (let ((require-name (nth 1 output-data))
497 (additional-copyright (nth 2 output-data))
498 (additional-license (nth 3 output-data))
499 copyright-end)
500 ;; Touch up the generated parsers for Emacs integration.
501 (with-temp-buffer
502 (insert-file-contents packagename)
503 (setq buffer-file-name (expand-file-name packagename))
504 ;; Fix copyright header:
505 (goto-char (point-min))
506 (when additional-copyright
507 (re-search-forward "Copyright (C).*$")
508 (insert "\n;; " additional-copyright))
509 (re-search-forward "^;; Author:")
510 (setq copyright-end (match-beginning 0))
511 (re-search-forward "^;;; Code:\n")
512 (delete-region copyright-end (match-end 0))
513 (goto-char copyright-end)
514 (insert wisent-make-parsers--emacs-license)
515 (insert "\n\n;;; Commentary:
516;;
517;; This file was generated from etc/grammars/"
518 f ".")
519 (when additional-license
520 (insert "\n" additional-license))
521 (insert "\n\n;;; Code:\n
522\(require 'semantic/lex)\n")
523 (goto-char (point-min))
524 (delete-region (point-min) (line-end-position))
525 (insert ";;; " require-name
526 ".el --- Generated parser support file")
527 (delete-trailing-whitespace)
528 (re-search-forward ";;\n(require 'semantic-lex)\n")
529 (delete-region (match-beginning 0) (match-end 0))
530 ;; Fix footer:
531 (goto-char (point-max))
532 (re-search-backward "^(provide")
533 (delete-region (match-beginning 0) (point-max))
534 (goto-char (point-max))
535 (insert "(provide '" require-name ")\n\n")
536 (insert ";;; " require-name ".el ends here\n")
537 (let ((make-backup-files nil))
538 (save-buffer))))))))
539
540
541
542;;; wisent-grammar.el ends here
diff --git a/lisp/cedet/semantic/bovine/c-by.el b/lisp/cedet/semantic/bovine/c-by.el
index 0308ace619b..36aa480e514 100644
--- a/lisp/cedet/semantic/bovine/c-by.el
+++ b/lisp/cedet/semantic/bovine/c-by.el
@@ -20,8 +20,7 @@
20 20
21;;; Commentary: 21;;; Commentary:
22;; 22;;
23;; This file was generated from the grammar file semantic/bovine/c.by 23;; This file was generated from etc/grammars/c.by.
24;; in the CEDET repository.
25 24
26;;; Code: 25;;; Code:
27 26
diff --git a/lisp/cedet/semantic/bovine/make-by.el b/lisp/cedet/semantic/bovine/make-by.el
index 1db454f6ea8..17dd5613a50 100644
--- a/lisp/cedet/semantic/bovine/make-by.el
+++ b/lisp/cedet/semantic/bovine/make-by.el
@@ -20,8 +20,7 @@
20 20
21;;; Commentary: 21;;; Commentary:
22;; 22;;
23;; This file was generated from the grammar file 23;; This file was generated from etc/grammars/make.by.
24;; semantic/bovine/make.by in the CEDET repository.
25 24
26;;; Code: 25;;; Code:
27 26
diff --git a/lisp/cedet/semantic/bovine/scm-by.el b/lisp/cedet/semantic/bovine/scm-by.el
index ac8211bfc8c..0b27abaf211 100644
--- a/lisp/cedet/semantic/bovine/scm-by.el
+++ b/lisp/cedet/semantic/bovine/scm-by.el
@@ -19,8 +19,7 @@
19 19
20;;; Commentary: 20;;; Commentary:
21;; 21;;
22;; This file was generated from the grammar file 22;; This file was generated from etc/grammars/scm.by.
23;; semantic/bovine/scm.by in the CEDET repository.
24 23
25;;; Code: 24;;; Code:
26 25
diff --git a/lisp/cedet/semantic/grammar-wy.el b/lisp/cedet/semantic/grammar-wy.el
index 58f7f9900e2..59729863316 100644
--- a/lisp/cedet/semantic/grammar-wy.el
+++ b/lisp/cedet/semantic/grammar-wy.el
@@ -22,8 +22,7 @@
22 22
23;;; Commentary: 23;;; Commentary:
24;; 24;;
25;; This file is generated from the grammar file semantic-grammar.wy in 25;; This file was generated from etc/grammars/grammar.wy.
26;; the upstream CEDET repository.
27 26
28;;; Code: 27;;; Code:
29 28
diff --git a/lisp/cedet/semantic/wisent/javat-wy.el b/lisp/cedet/semantic/wisent/javat-wy.el
index 258b1ac4af7..9057ee9fd45 100644
--- a/lisp/cedet/semantic/wisent/javat-wy.el
+++ b/lisp/cedet/semantic/wisent/javat-wy.el
@@ -19,8 +19,7 @@
19 19
20;;; Commentary: 20;;; Commentary:
21;; 21;;
22;; This file was generated from the grammar file 22;; This file was generated from etc/grammars/java-tags.wy.
23;; semantic/wisent/wisent-java-tags.wy in the CEDET repository.
24 23
25;;; Code: 24;;; Code:
26 25
diff --git a/lisp/cedet/semantic/wisent/js-wy.el b/lisp/cedet/semantic/wisent/js-wy.el
index 021002059f8..a974a28bcd9 100644
--- a/lisp/cedet/semantic/wisent/js-wy.el
+++ b/lisp/cedet/semantic/wisent/js-wy.el
@@ -19,8 +19,42 @@
19 19
20;;; Commentary: 20;;; Commentary:
21;; 21;;
22;; This file was generated from the grammar file 22;; This file was generated from etc/grammars/js.wy.
23;; semantic/wisent/wisent-javascript-jv.wy in the CEDET repository. 23;;
24;; It is derived from the grammar in the ECMAScript Language
25;; Specification published at
26;;
27;; http://www.ecma-international.org/publications/standards/Ecma-262.htm
28;;
29;; and redistributed under the following license:
30;;
31;; Redistribution and use in source and binary forms, with or without
32;; modification, are permitted provided that the following conditions
33;; are met:
34;;
35;; 1. Redistributions of source code must retain the above copyright
36;; notice, this list of conditions and the following disclaimer.
37;;
38;; 2. Redistributions in binary form must reproduce the above
39;; copyright notice, this list of conditions and the following
40;; disclaimer in the documentation and/or other materials provided
41;; with the distribution.
42;;
43;; 3. Neither the name of the authors nor Ecma International may be
44;; used to endorse or promote products derived from this software
45;; without specific prior written permission. THIS SOFTWARE IS
46;; PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR
47;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
48;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49;; ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR
50;; ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
51;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
52;; OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
53;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
54;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
56;; USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
57;; DAMAGE.
24 58
25;;; Code: 59;;; Code:
26(require 'semantic/lex) 60(require 'semantic/lex)
diff --git a/lisp/cedet/semantic/wisent/python-wy.el b/lisp/cedet/semantic/wisent/python-wy.el
index 32466a31cec..f4cae7545fc 100644
--- a/lisp/cedet/semantic/wisent/python-wy.el
+++ b/lisp/cedet/semantic/wisent/python-wy.el
@@ -19,9 +19,59 @@
19;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. 19;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
20 20
21;;; Commentary: 21;;; Commentary:
22
23;; This file was generated from etc/grammars/python.wy.
24;; It is derived in part from the Python grammar, used under the
25;; following license:
26;;
27;; PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
28;; --------------------------------------------
29;; 1. This LICENSE AGREEMENT is between the Python Software Foundation
30;; ("PSF"), and the Individual or Organization ("Licensee") accessing
31;; and otherwise using this software ("Python") in source or binary
32;; form and its associated documentation.
33;;
34;; 2. Subject to the terms and conditions of this License Agreement,
35;; PSF hereby grants Licensee a nonexclusive, royalty-free, world-wide
36;; license to reproduce, analyze, test, perform and/or display
37;; publicly, prepare derivative works, distribute, and otherwise use
38;; Python alone or in any derivative version, provided, however, that
39;; PSF's License Agreement and PSF's notice of copyright, i.e.,
40;; "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
41;; 2009, 2010 Python Software Foundation; All Rights Reserved" are
42;; retained in Python alone or in any derivative version prepared by
43;; Licensee.
44;;
45;; 3. In the event Licensee prepares a derivative work that is based
46;; on or incorporates Python or any part thereof, and wants to make
47;; the derivative work available to others as provided herein, then
48;; Licensee hereby agrees to include in any such work a brief summary
49;; of the changes made to Python.
50;;
51;; 4. PSF is making Python available to Licensee on an "AS IS"
52;; basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
53;; IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
54;; DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
55;; FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
56;; INFRINGE ANY THIRD PARTY RIGHTS.
57;;
58;; 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
59;; FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A
60;; RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, OR
61;; ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
62;;
63;; 6. This License Agreement will automatically terminate upon a
64;; material breach of its terms and conditions.
65;;
66;; 7. Nothing in this License Agreement shall be deemed to create any
67;; relationship of agency, partnership, or joint venture between PSF
68;; and Licensee. This License Agreement does not grant permission to
69;; use PSF trademarks or trade name in a trademark sense to endorse or
70;; promote products or services of Licensee, or any third party.
22;; 71;;
23;; This file was generated from the grammar file 72;; 8. By copying, installing or otherwise using Python, Licensee
24;; semantic/wisent/wisent-python.wy in the CEDET repository. 73;; agrees to be bound by the terms and conditions of this License
74;; Agreement.
25 75
26;;; Code: 76;;; Code:
27 77
diff --git a/lisp/cedet/srecode/srt-wy.el b/lisp/cedet/srecode/srt-wy.el
index 3dde065c2a6..2910483bba3 100644
--- a/lisp/cedet/srecode/srt-wy.el
+++ b/lisp/cedet/srecode/srt-wy.el
@@ -18,8 +18,8 @@
18;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. 18;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
19 19
20;;; Commentary: 20;;; Commentary:
21 21;;
22;; Generated from srecode-template.wy in the CEDET repository. 22;; This file was generated from etc/grammars/srecode-template.wy.
23 23
24;;; Code: 24;;; Code:
25 25