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