diff options
author | Chong Yidong <cyd@gnu.org> | 2012-01-09 13:42:57 +0800 |
---|---|---|
committer | Chong Yidong <cyd@gnu.org> | 2012-01-09 13:42:57 +0800 |
commit | 866b58d61afd2eccfed53d1707bea233bde3c030 (patch) | |
tree | 860d0ce299d0482248ecec6e618dd967a2904178 | |
parent | 9ca4c014c87716b8712f710cbc8bbdf1421a08fc (diff) | |
download | emacs-866b58d61afd2eccfed53d1707bea233bde3c030.tar.gz |
Add CEDET grammar files to emacs-23 branch.
-rw-r--r-- | etc/grammars/README | 8 | ||||
-rw-r--r-- | etc/grammars/bovine-grammar.el | 501 | ||||
-rw-r--r-- | etc/grammars/c.by | 1202 | ||||
-rw-r--r-- | etc/grammars/grammar.wy | 432 | ||||
-rw-r--r-- | etc/grammars/java-tags.wy | 750 | ||||
-rw-r--r-- | etc/grammars/js.wy | 524 | ||||
-rw-r--r-- | etc/grammars/make.by | 168 | ||||
-rw-r--r-- | etc/grammars/python.wy | 1132 | ||||
-rw-r--r-- | etc/grammars/scheme.by | 84 | ||||
-rw-r--r-- | etc/grammars/srecode-template.wy | 235 | ||||
-rw-r--r-- | etc/grammars/wisent-grammar.el | 542 | ||||
-rw-r--r-- | lisp/cedet/semantic/bovine/c-by.el | 3 | ||||
-rw-r--r-- | lisp/cedet/semantic/bovine/make-by.el | 3 | ||||
-rw-r--r-- | lisp/cedet/semantic/bovine/scm-by.el | 3 | ||||
-rw-r--r-- | lisp/cedet/semantic/grammar-wy.el | 3 | ||||
-rw-r--r-- | lisp/cedet/semantic/wisent/javat-wy.el | 3 | ||||
-rw-r--r-- | lisp/cedet/semantic/wisent/js-wy.el | 38 | ||||
-rw-r--r-- | lisp/cedet/semantic/wisent/python-wy.el | 54 | ||||
-rw-r--r-- | lisp/cedet/srecode/srt-wy.el | 4 |
19 files changed, 5673 insertions, 16 deletions
diff --git a/etc/grammars/README b/etc/grammars/README new file mode 100644 index 00000000000..8365303f811 --- /dev/null +++ b/etc/grammars/README @@ -0,0 +1,8 @@ +This directory contains grammar files in Bison and Wisent, used to +generate the parser data in the lisp/semantic/bovine/ and +lisp/semantic/wisent/ directories. Currently, the parser files in +lisp/ are generated by hand, not automatically. You can run the +parser generators with + +emacs -batch -Q -l bovine-grammar.el -f bovine-make-parsers +emacs -batch -Q -l wisent-grammar.el -f wisent-make-parsers diff --git a/etc/grammars/bovine-grammar.el b/etc/grammars/bovine-grammar.el new file mode 100644 index 00000000000..ee08c84eec7 --- /dev/null +++ b/etc/grammars/bovine-grammar.el @@ -0,0 +1,501 @@ +;;; bovine-grammar.el --- Bovine's input grammar mode +;; +;; Copyright (C) 2002-2011 Free Software Foundation, Inc. +;; +;; Author: David Ponce <david@dponce.com> +;; Maintainer: David Ponce <david@dponce.com> +;; Created: 26 Aug 2002 +;; Keywords: syntax + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: +;; +;; Major mode for editing Bovine's input grammar (.by) files. + +;;; History: + +;;; Code: +(require 'semantic) +(require 'semantic/grammar) +(require 'semantic/find) +(require 'semantic/lex) +(require 'semantic/wisent) +(require 'semantic/bovine) + +(defun bovine-grammar-EXPAND (bounds nonterm) + "Expand call to EXPAND grammar macro. +Return the form to parse from within a nonterminal between BOUNDS. +NONTERM is the nonterminal symbol to start with." + `(semantic-bovinate-from-nonterminal + (car ,bounds) (cdr ,bounds) ',nonterm)) + +(defun bovine-grammar-EXPANDFULL (bounds nonterm) + "Expand call to EXPANDFULL grammar macro. +Return the form to recursively parse the area between BOUNDS. +NONTERM is the nonterminal symbol to start with." + `(semantic-parse-region + (car ,bounds) (cdr ,bounds) ',nonterm 1)) + +(defun bovine-grammar-TAG (name class &rest attributes) + "Expand call to TAG grammar macro. +Return the form to create a generic semantic tag. +See the function `semantic-tag' for the meaning of arguments NAME, +CLASS and ATTRIBUTES." + `(semantic-tag ,name ,class ,@attributes)) + +(defun bovine-grammar-VARIABLE-TAG (name type default-value &rest attributes) + "Expand call to VARIABLE-TAG grammar macro. +Return the form to create a semantic tag of class variable. +See the function `semantic-tag-new-variable' for the meaning of +arguments NAME, TYPE, DEFAULT-VALUE and ATTRIBUTES." + `(semantic-tag-new-variable ,name ,type ,default-value ,@attributes)) + +(defun bovine-grammar-FUNCTION-TAG (name type arg-list &rest attributes) + "Expand call to FUNCTION-TAG grammar macro. +Return the form to create a semantic tag of class function. +See the function `semantic-tag-new-function' for the meaning of +arguments NAME, TYPE, ARG-LIST and ATTRIBUTES." + `(semantic-tag-new-function ,name ,type ,arg-list ,@attributes)) + +(defun bovine-grammar-TYPE-TAG (name type members parents &rest attributes) + "Expand call to TYPE-TAG grammar macro. +Return the form to create a semantic tag of class type. +See the function `semantic-tag-new-type' for the meaning of arguments +NAME, TYPE, MEMBERS, PARENTS and ATTRIBUTES." + `(semantic-tag-new-type ,name ,type ,members ,parents ,@attributes)) + +(defun bovine-grammar-INCLUDE-TAG (name system-flag &rest attributes) + "Expand call to INCLUDE-TAG grammar macro. +Return the form to create a semantic tag of class include. +See the function `semantic-tag-new-include' for the meaning of +arguments NAME, SYSTEM-FLAG and ATTRIBUTES." + `(semantic-tag-new-include ,name ,system-flag ,@attributes)) + +(defun bovine-grammar-PACKAGE-TAG (name detail &rest attributes) + "Expand call to PACKAGE-TAG grammar macro. +Return the form to create a semantic tag of class package. +See the function `semantic-tag-new-package' for the meaning of +arguments NAME, DETAIL and ATTRIBUTES." + `(semantic-tag-new-package ,name ,detail ,@attributes)) + +(defun bovine-grammar-CODE-TAG (name detail &rest attributes) + "Expand call to CODE-TAG grammar macro. +Return the form to create a semantic tag of class code. +See the function `semantic-tag-new-code' for the meaning of arguments +NAME, DETAIL and ATTRIBUTES." + `(semantic-tag-new-code ,name ,detail ,@attributes)) + +(defun bovine-grammar-ALIAS-TAG (name aliasclass definition &rest attributes) + "Expand call to ALIAS-TAG grammar macro. +Return the form to create a semantic tag of class alias. +See the function `semantic-tag-new-alias' for the meaning of arguments +NAME, ALIASCLASS, DEFINITION and ATTRIBUTES." + `(semantic-tag-new-alias ,name ,aliasclass ,definition ,@attributes)) + +;; Cache of macro definitions currently in use. +(defvar bovine--grammar-macros nil) + +(defun bovine-grammar-expand-form (form quotemode &optional inplace) + "Expand FORM into a new one suitable to the bovine parser. +FORM is a list in which we are substituting. +Argument QUOTEMODE is non-nil if we are in backquote mode. +When non-nil, optional argument INPLACE indicates that FORM is being +expanded from elsewhere." + (when (eq (car form) 'quote) + (setq form (cdr form)) + (cond + ((and (= (length form) 1) (listp (car form))) + (insert "\n(append") + (bovine-grammar-expand-form (car form) quotemode nil) + (insert ")") + (setq form nil inplace nil) + ) + ((and (= (length form) 1) (symbolp (car form))) + (insert "\n'" (symbol-name (car form))) + (setq form nil inplace nil) + ) + (t + (insert "\n(list") + (setq inplace t) + ))) + (let ((macro (assq (car form) bovine--grammar-macros)) + inlist first n q x) + (if macro + (bovine-grammar-expand-form + (apply (cdr macro) (cdr form)) + quotemode t) + (if inplace (insert "\n(")) + (while form + (setq first (car form) + form (cdr form)) + (cond + ((eq first nil) + (when (and (not inlist) (not inplace)) + (insert "\n(list") + (setq inlist t)) + (insert " nil") + ) + ((listp first) + ;;(let ((fn (and (symbolp (caar form)) (fboundp (caar form))))) + (when (and (not inlist) (not inplace)) + (insert "\n(list") + (setq inlist t)) + ;;(if (and inplace (not fn) (not (eq (caar form) 'EXPAND))) + ;; (insert " (append")) + (bovine-grammar-expand-form + first quotemode t) ;;(and fn (not (eq fn 'quote)))) + ;;(if (and inplace (not fn) (not (eq (caar form) 'EXPAND))) + ;; (insert ")")) + ;;) + ) + ((symbolp first) + (setq n (symbol-name first) ;the name + q quotemode ;implied quote flag + x nil) ;expand flag + (if (eq (aref n 0) ?,) + (if quotemode + ;; backquote mode needs the @ + (if (eq (aref n 1) ?@) + (setq n (substring n 2) + q nil + x t) + ;; non backquote mode behaves normally. + (setq n (substring n 1) + q nil)) + (setq n (substring n 1) + x t))) + (if (string= n "") + (progn + ;; We expand only the next item in place (a list?) + ;; A regular inline-list... + (bovine-grammar-expand-form (car form) quotemode t) + (setq form (cdr form))) + (if (and (eq (aref n 0) ?$) + ;; Don't expand $ tokens in implied quote mode. + ;; This acts like quoting in other symbols. + (not q)) + (progn + (cond + ((and (not x) (not inlist) (not inplace)) + (insert "\n(list")) + ((and x inlist (not inplace)) + (insert ")") + (setq inlist nil))) + (insert "\n(nth " (int-to-string + (1- (string-to-number + (substring n 1)))) + " vals)") + (and (not x) (not inplace) + (setq inlist t))) + + (when (and (not inlist) (not inplace)) + (insert "\n(list") + (setq inlist t)) + (or (char-equal (char-before) ?\() + (insert " ")) + (insert (if (or inplace (eq first t)) + "" "'") + n))) ;; " " + ) + (t + (when (and (not inlist) (not inplace)) + (insert "\n(list") + (setq inlist t)) + (insert (format "\n%S" first)) + ) + )) + (if inlist (insert ")")) + (if inplace (insert ")"))) + )) + +(defun bovine-grammar-expand-action (textform quotemode) + "Expand semantic action string TEXTFORM into Lisp code. +QUOTEMODE is the mode in which quoted symbols are slurred." + (if (string= "" textform) + nil + (let ((sexp (read textform))) + ;; We converted the lambda string into a list. Now write it + ;; out as the bovine lambda expression, and do macro-like + ;; conversion upon it. + (insert "\n") + (cond + ((eq (car sexp) 'EXPAND) + (insert ",(lambda (vals start end)") + ;; The EXPAND macro definition is mandatory + (bovine-grammar-expand-form + (apply (cdr (assq 'EXPAND bovine--grammar-macros)) (cdr sexp)) + quotemode t) + ) + ((and (listp (car sexp)) (eq (caar sexp) 'EVAL)) + ;; The user wants to evaluate the following args. + ;; Use a simpler expander + ) + (t + (insert ",(semantic-lambda") + (bovine-grammar-expand-form sexp quotemode) + )) + (insert ")\n"))) +) + +(defun bovine-grammar-parsetable-builder () + "Return the parser table expression as a string value. +The format of a bovine parser table is: + + ( ( NONTERMINAL-SYMBOL1 MATCH-LIST1 ) + ( NONTERMINAL-SYMBOL2 MATCH-LIST2 ) + ... + ( NONTERMINAL-SYMBOLn MATCH-LISTn ) + +Where each NONTERMINAL-SYMBOL is an artificial symbol which can appear +in any child state. As a starting place, one of the NONTERMINAL-SYMBOLS +must be `bovine-toplevel'. + +A MATCH-LIST is a list of possible matches of the form: + + ( STATE-LIST1 + STATE-LIST2 + ... + STATE-LISTN ) + +where STATE-LIST is of the form: + ( TYPE1 [ \"VALUE1\" ] TYPE2 [ \"VALUE2\" ] ... LAMBDA ) + +where TYPE is one of the returned types of the token stream. +VALUE is a value, or range of values to match against. For +example, a SYMBOL might need to match \"foo\". Some TYPES will not +have matching criteria. + +LAMBDA is a lambda expression which is evaled with the text of the +type when it is found. It is passed the list of all buffer text +elements found since the last lambda expression. It should return a +semantic element (see below.) + +For consistency between languages, try to use common return values +from your parser. Please reference the chapter \"Writing Parsers\" in +the \"Language Support Developer's Guide -\" in the semantic texinfo +manual." + (let* ((start (semantic-grammar-start)) + (scopestart (semantic-grammar-scopestart)) + (quotemode (semantic-grammar-quotemode)) + (tags (semantic-find-tags-by-class + 'token (current-buffer))) + (nterms (semantic-find-tags-by-class + 'nonterminal (current-buffer))) + ;; Setup the cache of macro definitions. + (bovine--grammar-macros (semantic-grammar-macros)) + nterm rules items item actn prec tag type regex) + + ;; Check some trivial things + (cond + ((null nterms) + (error "Bad input grammar")) + (start + (if (cdr start) + (message "Extra start symbols %S ignored" (cdr start))) + (setq start (symbol-name (car start))) + (unless (semantic-find-first-tag-by-name start nterms) + (error "start symbol `%s' has no rule" start))) + (t + ;; Default to the first grammar rule. + (setq start (semantic-tag-name (car nterms))))) + (when scopestart + (setq scopestart (symbol-name scopestart)) + (unless (semantic-find-first-tag-by-name scopestart nterms) + (error "scopestart symbol `%s' has no rule" scopestart))) + + ;; Generate the grammar Lisp form. + (with-temp-buffer + (erase-buffer) + (insert "`(") + ;; Insert the start/scopestart rules + (insert "\n(bovine-toplevel \n(" + start + ")\n) ;; end bovine-toplevel\n") + (when scopestart + (insert "\n(bovine-inner-scope \n(" + scopestart + ")\n) ;; end bovine-inner-scope\n")) + ;; Process each nonterminal + (while nterms + (setq nterm (car nterms) + ;; We can't use the override form because the current buffer + ;; is not the originator of the tag. + rules (semantic-tag-components-semantic-grammar-mode nterm) + nterm (semantic-tag-name nterm) + nterms (cdr nterms)) + (when (member nterm '("bovine-toplevel" "bovine-inner-scope")) + (error "`%s' is a reserved internal name" nterm)) + (insert "\n(" nterm) + ;; Process each rule + (while rules + (setq items (semantic-tag-get-attribute (car rules) :value) + prec (semantic-tag-get-attribute (car rules) :prec) + actn (semantic-tag-get-attribute (car rules) :expr) + rules (cdr rules)) + ;; Process each item + (insert "\n(") + (if (null items) + ;; EMPTY rule + (insert ";;EMPTY" (if actn "" "\n")) + ;; Expand items + (while items + (setq item (car items) + items (cdr items)) + (if (consp item) ;; mid-rule action + (message "Mid-rule action %S ignored" item) + (or (char-equal (char-before) ?\() + (insert "\n")) + (cond + ((member item '("bovine-toplevel" "bovine-inner-scope")) + (error "`%s' is a reserved internal name" item)) + ;; Replace ITEM by its %token definition. + ;; If a '%token TYPE ITEM [REGEX]' definition exists + ;; in the grammar, ITEM is replaced by TYPE [REGEX]. + ((setq tag (semantic-find-first-tag-by-name + item tags) + type (semantic-tag-get-attribute tag :type)) + (insert type) + (if (setq regex (semantic-tag-get-attribute tag :value)) + (insert (format "\n%S" regex)))) + ;; Don't change ITEM + (t + (insert (semantic-grammar-item-text item))) + )))) + (if prec + (message "%%prec %S ignored" prec)) + (if actn + (bovine-grammar-expand-action actn quotemode)) + (insert ")")) + (insert "\n) ;; end " nterm "\n")) + (insert ")\n") + (buffer-string)))) + +(defun bovine-grammar-setupcode-builder () + "Return the text of the setup code." + (format + "(setq semantic--parse-table %s\n\ + semantic-debug-parser-source %S\n\ + semantic-debug-parser-class 'semantic-bovine-debug-parser + semantic-flex-keywords-obarray %s\n\ + %s)" + (semantic-grammar-parsetable) + (buffer-name) + (semantic-grammar-keywordtable) + (let ((mode (semantic-grammar-languagemode))) + ;; Is there more than one major mode? + (if (and (listp mode) (> (length mode) 1)) + (format "semantic-equivalent-major-modes '%S\n" mode) + "")))) + +(defvar bovine-grammar-menu + '("BY Grammar" + ) + "BY mode specific grammar menu. +Menu items are appended to the common grammar menu.") + +(define-derived-mode bovine-grammar-mode semantic-grammar-mode "BY" + "Major mode for editing Bovine grammars." + (semantic-grammar-setup-menu bovine-grammar-menu) + (semantic-install-function-overrides + '((grammar-parsetable-builder . bovine-grammar-parsetable-builder) + (grammar-setupcode-builder . bovine-grammar-setupcode-builder) + ))) + +(add-to-list 'auto-mode-alist '("\\.by$" . bovine-grammar-mode)) + +(defvar-mode-local bovine-grammar-mode semantic-grammar-macros + '( + (ASSOC . semantic-grammar-ASSOC) + (EXPAND . bovine-grammar-EXPAND) + (EXPANDFULL . bovine-grammar-EXPANDFULL) + (TAG . bovine-grammar-TAG) + (VARIABLE-TAG . bovine-grammar-VARIABLE-TAG) + (FUNCTION-TAG . bovine-grammar-FUNCTION-TAG) + (TYPE-TAG . bovine-grammar-TYPE-TAG) + (INCLUDE-TAG . bovine-grammar-INCLUDE-TAG) + (PACKAGE-TAG . bovine-grammar-PACKAGE-TAG) + (CODE-TAG . bovine-grammar-CODE-TAG) + (ALIAS-TAG . bovine-grammar-ALIAS-TAG) + ) + "Semantic grammar macros used in bovine grammars.") + +(provide 'semantic/bovine/grammar) + + +(defun bovine-make-parsers () + "Generate Emacs' built-in Bovine-based parser files." + (semantic-mode 1) + ;; Loop through each .by file in current directory, and run + ;; `semantic-grammar-batch-build-one-package' to build the grammar. + (dolist (f (directory-files default-directory nil ".by$")) + (let ((packagename + (condition-case err + (with-current-buffer (find-file-noselect f) + (semantic-grammar-create-package)) + (error (message "%s" (error-message-string err)) nil))) + lang) + (when (and packagename + (string-match "^semantic-\\(.*\\)-by.el$" packagename)) + (setq lang (match-string 1 packagename)) + (with-temp-buffer + (insert-file-contents packagename) + (setq buffer-file-name (expand-file-name packagename)) + ;; Fix copyright header: + (goto-char (point-min)) + (re-search-forward "^;; Author:") + (setq copyright-end (match-beginning 0)) + (re-search-forward "^;;; Code:\n") + (delete-region copyright-end (match-end 0)) + (goto-char copyright-end) + (insert ";; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: +;; +;; This file was generated from etc/grammars/" + lang ".by. + +;;; Code: + +\(require 'semantic/lex) +\(eval-when-compile (require 'semantic/bovine))\n") + (goto-char (point-min)) + (delete-region (point-min) (line-end-position)) + (insert ";;; semantic/bovine/" lang + "-by.el --- Generated parser support file") + (delete-trailing-whitespace) + ;; Fix footer: + (goto-char (point-max)) + (re-search-backward ".\n;;; Analyzers") + (delete-region (point) (point-max)) + (insert "(provide 'semantic/bovine/" lang "-by)\n\n") + (insert ";;; semantic/bovine/" lang "-by.el ends here\n") + (save-buffer)))))) + +;;; bovine-grammar.el ends here diff --git a/etc/grammars/c.by b/etc/grammars/c.by new file mode 100644 index 00000000000..ca54159aa57 --- /dev/null +++ b/etc/grammars/c.by @@ -0,0 +1,1202 @@ +;;; c.by -- LL grammar for C/C++ language specification + +;; Copyright (C) 1999-2011 Free Software Foundation, Inc. +;; +;; Author: Eric M. Ludlam <zappo@gnu.org> +;; David Ponce <david@dponce.com> +;; Klaus Berndl <klaus.berndl@sdm.de> +;; +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +;; TODO: From Nate Schley +;; > * Can't parse signature element: "const char* const rmc_ClrTxt" +;; > * Can't parse signature element: "char* const dellog_ClrTxt" +;; > * Can't parse signature element: "const char* dellog_SetTxt" +;; > * Can't parse signature element: "const RmcCmdSSPADetailedStatus& status" +;; > +;; > And FWIW I have seen the following argument cases not handled, even +;; > with no leading/trailing spaces in the split: +;; > +;; > * Can't parse signature element: "const bool currentAlarmStatus" +;; > * Can't parse signature element: "unsigned char mode" +;; > * Can't parse signature element: "TskTimingTask* tsktimingtask" +;; > * Can't parse signature element: "unsigned char htrStatus" +;; > * Can't parse signature element: "char trackPower[]" +;; > * Can't parse signature element: "const RmcCmdMCDetailedStatus& status" +;; > * Can't parse signature element: "RmcBucStatus* rftBucStatus" + +%package semantic-c-by + +%languagemode c-mode c++-mode +%start declaration +%scopestart codeblock + +%token <punctuation> HASH "\\`[#]\\'" +%token <punctuation> PERIOD "\\`[.]\\'" +%token <punctuation> COLON "\\`[:]\\'" +%token <punctuation> SEMICOLON "\\`[;]\\'" +%token <punctuation> STAR "\\`[*]\\'" +%token <punctuation> AMPERSAND "\\`[&]\\'" +%token <punctuation> DIVIDE "\\`[/]\\'" +%token <punctuation> PLUS "\\`[+]\\'" +%token <punctuation> MINUS "\\`[-]\\'" +%token <punctuation> BANG "\\`[!]\\'" +%token <punctuation> EQUAL "\\`[=]\\'" +%token <punctuation> LESS "\\`[<]\\'" +%token <punctuation> GREATER "\\`[>]\\'" +%token <punctuation> COMA "\\`[,]\\'" +%token <punctuation> TILDE "\\`[~]\\'" +%token <punctuation> MOD "\\`[%]\\'" +%token <punctuation> HAT "\\`\\^\\'" +%token <punctuation> OR "\\`[|]\\'" +%token <string> C "\"C\"" +%token <string> CPP "\"C\\+\\+\"" +%token <number> ZERO "^0$" +%token <symbol> RESTRICT "\\<\\(__\\)?restrict\\>" +%token <open-paren> LPAREN "(" +%token <close-paren> RPAREN ")" +%token <open-paren> LBRACE "{" +%token <close-paren> RBRACE "}" +%token <semantic-list> BRACK_BLCK "\\[.*\\]$" +%token <semantic-list> PAREN_BLCK "^(" +%token <semantic-list> BRACE_BLCK "^{" +%token <semantic-list> VOID_BLCK "^(void)$" +%token <semantic-list> PARENS "()" +%token <semantic-list> BRACKETS "\\[\\]" + +%token EXTERN "extern" +%put EXTERN summary "Declaration Modifier: extern <type> <name> ..." +%token STATIC "static" +%put STATIC summary "Declaration Modifier: static <type> <name> ..." +%token CONST "const" +%put CONST summary "Declaration Modifier: const <type> <name> ..." +%token VOLATILE "volatile" +%put VOLATILE summary "Declaration Modifier: volatile <type> <name> ..." +%token REGISTER "register" +%put REGISTER summary "Declaration Modifier: register <type> <name> ..." +%token SIGNED "signed" +%put SIGNED summary "Numeric Type Modifier: signed <numeric type> <name> ..." +%token UNSIGNED "unsigned" +%put UNSIGNED summary "Numeric Type Modifier: unsigned <numeric type> <name> ..." + +%token INLINE "inline" +%put INLINE summary "Function Modifier: inline <return type> <name>(...) {...};" +%token VIRTUAL "virtual" +%put VIRTUAL summary "Method Modifier: virtual <type> <name>(...) ..." +%token MUTABLE "mutable" +%put MUTABLE summary "Member Declaration Modifier: mutable <type> <name> ..." + +%token STRUCT "struct" +%put STRUCT summary "Structure Type Declaration: struct [name] { ... };" +%token UNION "union" +%put UNION summary "Union Type Declaration: union [name] { ... };" +%token ENUM "enum" +%put ENUM summary "Enumeration Type Declaration: enum [name] { ... };" +%token TYPEDEF "typedef" +%put TYPEDEF summary "Arbitrary Type Declaration: typedef <typedeclaration> <name>;" +%token CLASS "class" +%put CLASS summary "Class Declaration: class <name>[:parents] { ... };" +%token TYPENAME "typename" +%put TYPENAME summary "typename is used to handle a qualified name as a typename;" +%token NAMESPACE "namespace" +%put NAMESPACE summary "Namespace Declaration: namespace <name> { ... };" +%token USING "using" +%put USING summary "using <namespace>;" + +%token NEW "new" +%put NEW summary "new <classname>();" +%token DELETE "delete" +%put DELETE summary "delete <object>;" + +;; Despite this, this parser can find templates by ignoring the TEMPLATE +;; keyword, and finding the class/method being templateized. +%token TEMPLATE "template" +%put TEMPLATE summary "template <class TYPE ...> TYPE_OR_FUNCTION" + +%token THROW "throw" +%put THROW summary "<type> <methoddef> (<method args>) throw (<exception>) ..." +%token REENTRANT "reentrant" +%put REENTRANT summary "<type> <methoddef> (<method args>) reentrant ..." +%token TRY "try" +%token CATCH "catch" +%put { TRY CATCH } summary "try { <body> } catch { <catch code> }" + +;; Leave these alone for now. +%token OPERATOR "operator" +%token PUBLIC "public" +%token PRIVATE "private" +%token PROTECTED "protected" +%token FRIEND "friend" +%put FRIEND summary "friend class <CLASSNAME>" + +;; These aren't used for parsing, but is a useful place to describe the keywords. +%token IF "if" +%token ELSE "else" +%put {IF ELSE} summary "if (<condition>) { code } [ else { code } ]" + +%token DO "do" +%token WHILE "while" +%put DO summary " do { code } while (<condition>);" +%put WHILE summary "do { code } while (<condition>); or while (<condition>) { code };" + +%token FOR "for" +%put FOR summary "for(<init>; <condition>; <increment>) { code }" + +%token SWITCH "switch" +%token CASE "case" +%token DEFAULT "default" +%put {SWITCH CASE DEFAULT} summary +"switch (<variable>) { case <constvalue>: code; ... default: code; }" + +%token RETURN "return" +%put RETURN summary "return <value>;" + +%token BREAK "break" +%put BREAK summary "Non-local exit within a loop or switch (for, do/while, switch): break;" +%token CONTINUE "continue" +%put CONTINUE summary "Non-local continue within a loop (for, do/while): continue;" + +%token SIZEOF "sizeof" +%put SIZEOF summary "Compile time macro: sizeof(<type or variable>) // size in bytes" + +;; Types +%token VOID "void" +%put VOID summary "Built in typeless type: void" +%token CHAR "char" +%put CHAR summary "Integral Character Type: (0 to 256)" +%token WCHAR "wchar_t" +%put WCHAR summary "Wide Character Type" +%token SHORT "short" +%put SHORT summary "Integral Primitive Type: (-32768 to 32767)" +%token INT "int" +%put INT summary "Integral Primitive Type: (-2147483648 to 2147483647)" +%token LONG "long" +%put LONG summary "Integral primitive type (-9223372036854775808 to 9223372036854775807)" +%token FLOAT "float" +%put FLOAT summary "Primitive floating-point type (single-precision 32-bit IEEE 754)" +%token DOUBLE "double" +%put DOUBLE summary "Primitive floating-point type (double-precision 64-bit IEEE 754)" +%token BOOL "bool" +%put BOOL summary "Primitive boolean type" + +%token UNDERP "_P" +%token UNDERUNDERP "__P" +%put UNDERP summary "Common macro to eliminate prototype compatibility on some compilers" +%put UNDERUNDERP summary "Common macro to eliminate prototype compatibility on some compilers" + +%% + +declaration + : macro + | type + ;; TODO: Klaus Berndl: Is the define here necessary or even wrong? + ;; Is this part not already covered by macro?? + | define + | var-or-fun + | extern-c + | template + | using + ; + +codeblock + : define + | codeblock-var-or-fun + | type ;; type is less likely to be used here. + | using + ; + +extern-c-contents + : open-paren + ( nil ) + | declaration + | close-paren + ( nil ) + ; + +extern-c + : EXTERN C semantic-list + ;; Extern C commands which contain a list need to have the + ;; entries of the list extracted, and spliced into the main + ;; list of entries. This must be done via the function + ;; that expands singular nonterminals, such as int x,y; + (TAG "C" 'extern :members (EXPANDFULL $3 extern-c-contents) ) + | EXTERN CPP semantic-list + (TAG "C" 'extern :members (EXPANDFULL $3 extern-c-contents) ) + | EXTERN C + ;; A plain extern "C" call should add something to the token, + ;; but just strip it from the buffer here for now. + ( nil ) + | EXTERN CPP + ( nil ) + ; + +macro + : spp-macro-def + (VARIABLE-TAG $1 nil nil :constant-flag t ) + | spp-system-include + (INCLUDE-TAG $1 t) + | spp-include + (INCLUDE-TAG $1 nil) + ; + +;; This is used in struct parts. +define + : spp-macro-def + (VARIABLE-TAG $1 nil nil :constant-flag t) + | spp-macro-undef + ( nil ) + ; + +;; In C++, structures can have the same things as classes. +;; So delete this somday in the figure. +;; +;;structparts : semantic-list +;; (EXPANDFULL $1 structsubparts) +;; ; +;; +;;structsubparts : LBRACE +;; ( nil ) +;; | RBRACE +;; ( nil ) +;; | var-or-fun +;; | define +;; ;; sometimes there are defines in structs. +;; ; + +unionparts + : semantic-list + (EXPANDFULL $1 classsubparts) + ; + +opt-symbol + : symbol + | ;;EMPTY + ; + +;; @todo - support 'friend' construct. +classsubparts + : LBRACE + ( nil ) + | RBRACE + ( nil ) + | class-protection opt-symbol COLON + ;; For QT, they may put a `slot' keyword between the protection + ;; and the COLON. @todo - Have the QT stuff use macros. + (TAG (car $1) 'label) + | var-or-fun + | FRIEND func-decl + (TAG (car $2) 'friend) + | FRIEND CLASS symbol + (TAG $3 'friend) + | type + | define + | template + | ;;EMPTY + ; + +opt-class-parents + : COLON class-parents opt-template-specifier + ( $2 ) + | ;;EMPTY + ( ) + ; + +one-class-parent + : opt-class-protection opt-class-declmods namespace-symbol + (TYPE-TAG (car $3) "class" nil nil :protection (car $1)) + | opt-class-declmods opt-class-protection namespace-symbol + (TYPE-TAG (car $3) "class" nil nil :protection (car $2)) + ; + +class-parents + : one-class-parent COMA class-parents + ( ,(cons ,$1 $3 ) ) + | one-class-parent + ( $1 ) + ; + +opt-class-declmods + : class-declmods opt-class-declmods + ( nil ) + | ;;EMPTY + ; + +class-declmods + : VIRTUAL + ; + +class-protection + : PUBLIC + | PRIVATE + | PROTECTED + ; + +opt-class-protection + : class-protection + ( ,$1 ) + | ;;EMPTY - Same as private + ( "unspecified" ) + ; + +namespaceparts + : semantic-list + (EXPANDFULL $1 namespacesubparts) + ; + +namespacesubparts + : LBRACE + ( nil ) + | RBRACE + ( nil ) + | type + | var-or-fun + | define + | class-protection COLON + (TAG (car $1) 'label) + ;; In C++, this label in a classsubpart represents + ;; PUBLIC or PRIVATE bits. Ignore them for now. + | template + | using + | ;;EMPTY + ; + +enumparts + : semantic-list + (EXPANDFULL $1 enumsubparts) + ; + +enumsubparts + : symbol opt-assign + (VARIABLE-TAG $1 "int" (car $2) :constant-flag t ) + | LBRACE + ( nil ) + | RBRACE + ( nil ) + | COMA + ( nil ) + ; + +opt-name + : symbol + | ;;EMPTY + ( "" ) + ; + +typesimple + : struct-or-class opt-class opt-name opt-template-specifier + opt-class-parents semantic-list + (TYPE-TAG (car $3) (car $1) + (let ((semantic-c-classname (cons (car ,$3) (car ,$1)))) + (EXPANDFULL $6 classsubparts)) + $5 + :template-specifier $4 + :parent (car ,$2)) + | struct-or-class opt-class opt-name opt-template-specifier + opt-class-parents + (TYPE-TAG (car $3) (car $1) nil $5 + :template-specifier $4 + :prototype t + :parent (car ,$2)) + | UNION opt-class opt-name unionparts + (TYPE-TAG (car $3) $1 $4 nil + :parent (car ,$2)) + | ENUM opt-class opt-name enumparts + (TYPE-TAG (car $3) $1 $4 nil + :parent (car ,$2)) + ;; Klaus Berndl: a typedef can be a typeformbase with all this + ;; declmods stuff. + | TYPEDEF declmods typeformbase cv-declmods typedef-symbol-list + ;;;; We put the type this typedef renames into PARENT + ;;;; but will move it in the expand function. + (TYPE-TAG $5 $1 nil (list $3) ) + ; + +typedef-symbol-list + : typedefname COMA typedef-symbol-list + ( ,(cons $1 $3) ) + | typedefname + ( $1 ) + ; + +;; TODO: Klaus Berndl: symbol -> namespace-symbol?! Answer: Probably +;; symbol is correct here! +typedefname + : opt-stars symbol opt-bits opt-array + ( $1 $2 ) + ; + +struct-or-class + : STRUCT + | CLASS + ; + +type + : typesimple SEMICOLON + ( ,$1 ) + ;; named namespaces like "namespace XXX {" + | NAMESPACE symbol namespaceparts + (TYPE-TAG $2 $1 $3 nil ) + ;; unnamed namespaces like "namespace {" + | NAMESPACE namespaceparts + (TYPE-TAG "unnamed" $1 $2 nil ) + ;; David Engster: namespace alias like "namespace foo = bar;" + | NAMESPACE symbol EQUAL typeformbase SEMICOLON + (TYPE-TAG $2 $1 (list (TYPE-TAG (car $4) $1 nil nil)) nil :kind 'alias ) + ; + +;; Klaus Berndl: We must parse "using namespace XXX" too + +;; Using is vaguely like an include statement in the named portions +;; of the code. We should probably specify a new token type for this. + +using + : USING usingname SEMICOLON + (TAG (car $2) 'using :type ,$2 ) + ; + +;; Jan Moringen: Differentiate between 'using' and 'using namespace' +;; Adapted to creating type tags by EML. +usingname + : typeformbase + (TYPE-TAG (car $1) "class" nil nil :prototype t) + | NAMESPACE typeformbase + (TYPE-TAG (car $2) "namespace" nil nil :prototype t) + ; + +template + : TEMPLATE template-specifier opt-friend template-definition + ( ,(semantic-c-reconstitute-template $4 ,$2) ) + ; + +opt-friend + : FRIEND + | ;;EMPTY + ; + +opt-template-specifier + : template-specifier + ( ,$1 ) + | ;;EMPTY + ( ) + ; + +template-specifier + : LESS template-specifier-types GREATER + ( ,$2 ) + ; + +template-specifier-types + : template-var template-specifier-type-list + ( ,(cons ,$1 ,$2 ) ) + | ;;EMPTY + ; + +template-specifier-type-list + : COMA template-specifier-types + ( ,$2 ) + | ;;EMPTY + ( ) + ; + +;; template-var +;; : template-type opt-stars opt-template-equal +;; ( ,(cons (concat (car $1) (make-string (car ,$2) ?*)) +;; (cdr $1))) +;; ;; Klaus Berndl: for template-types the template-var can also be +;; ;; literals or constants. Example: map<ClassX, ClassY, 10> +;; ;; map_size10_var; This parses also template<class T, 0> which is +;; ;; nonsense but who cares.... +;; | string +;; ( $1 ) +;; | number +;; ( $1 ) +;; ; + +template-var + : + ;; Klaus Berndl: The following handles all template-vars of + ;; template-definitions + template-type opt-template-equal + ( ,(cons (car $1) (cdr $1)) ) + ;; Klaus Berndl: for template-types the template-var can also be + ;; literals or constants. + ;; Example: map<ClassX, ClassY, 10> map_size10_var; This parses also + ;; template<class T, 0> which is nonsense but who cares.... + | string + ( $1 ) + | number + ( $1 ) + ;; Klaus Berndl: In template-types arguments can be any symbols with + ;; optional address-operator (&) and optional dereferencing operator + ;; (*). Example map<ClassX, ClassY, *size_var_ptr> sized_map_var. + | opt-stars opt-ref namespace-symbol + ( ,$3 ) + ;; Some code can compile down into a number, but starts out as an + ;; expression, such as "sizeof(a)", or (sizeof(a)/sizeof(b)) + | semantic-list + ( $1 ) + | SIZEOF semantic-list + ( $2 ) + ; + +opt-template-equal + : EQUAL symbol LESS template-specifier-types GREATER + ( $2 ) + | EQUAL symbol + ( $2 ) + | ;;EMPTY + ( ) + ; + +template-type + : CLASS symbol + (TYPE-TAG $2 "class" nil nil ) + | STRUCT symbol + (TYPE-TAG $2 "struct" nil nil ) + ;; TODO: Klaus Berndl: For the moment is is ok, that we parse the C++ + ;; keyword typename as a class.... + | TYPENAME symbol + (TYPE-TAG $2 "class" nil nil) + ;; Klaus Berndl: template-types can be all flavors of variable-args + ;; but here the argument is ignored, only the type stuff is needed. + | declmods typeformbase cv-declmods opt-stars + opt-ref variablearg-opt-name + (TYPE-TAG (car $2) nil nil nil + :constant-flag (if (member "const" (append $1 $3)) t nil) + :typemodifiers (delete "const" (append $1 $3)) + :reference (car ,$5) + :pointer (car $4) + ) + ; + +template-definition + : type + ( ,$1 ) + | var-or-fun + ( ,$1 ) + ; + +opt-stars + : STAR opt-starmod opt-stars + ( (1+ (car $3)) ) + | ;;EMPTY + ( 0 ) + ; + +opt-starmod + : STARMOD opt-starmod + ( ,(cons (,car ,$1) $2) ) + | ;;EMPTY + () + ; + +STARMOD + : CONST + ; + +declmods + : DECLMOD declmods + ( ,(cons ,(car ,$1) $2 ) ) + | DECLMOD + ( ,$1 ) + | ;;EMPTY + () + ; + +DECLMOD + : EXTERN + | STATIC + | CVDECLMOD + ;; Klaus Berndl: IMHO signed and unsigned are not decl-modes but + ;; these are only valid for some buildin-types like short, int + ;; etc... whereas "real" declmods are valid for all types, buildin + ;; and user-defined! SIGNED UNSIGNED + | INLINE + | REGISTER + | FRIEND + ;; Klaus Berndl: There can be a few cases where TYPENAME is not + ;; allowed in C++-syntax but better than not recognizing the allowed + ;; situations. + | TYPENAME + | METADECLMOD + ;; This is a hack in case we are in a class. + | VIRTUAL + ; + +metadeclmod + : METADECLMOD + () + | ;;EMPTY + () + ; + +CVDECLMOD + : CONST + | VOLATILE + ; + +cv-declmods + : CVDECLMOD cv-declmods + ( ,(cons ,(car ,$1) $2 ) ) + | CVDECLMOD + ( ,$1 ) + | ;;EMPTY + () + ; + +METADECLMOD + : VIRTUAL + | MUTABLE + ; + +;; C++: A type can be modified into a reference by "&" +opt-ref + : AMPERSAND + ( 1 ) + | ;;EMPTY + ( 0 ) + ; + +typeformbase + : typesimple + ( ,$1 ) + | STRUCT symbol + (TYPE-TAG $2 $1 nil nil ) + | UNION symbol + (TYPE-TAG $2 $1 nil nil ) + | ENUM symbol + (TYPE-TAG $2 $1 nil nil ) + | builtintype + ( ,$1 ) + | symbol template-specifier + (TYPE-TAG $1 "class" nil nil :template-specifier $2) + ;;| namespace-symbol opt-stars opt-template-specifier + ;;| namespace-symbol opt-template-specifier + | namespace-symbol-for-typeformbase opt-template-specifier + (TYPE-TAG (car $1) "class" nil nil + :template-specifier $2) + | symbol + ( $1 ) + ; + +signedmod + : UNSIGNED + | SIGNED + ; + +;; Klaus Berndl: builtintype-types was builtintype +builtintype-types + : VOID + | CHAR + ;; Klaus Berndl: Added WCHAR + | WCHAR + | SHORT INT + ( (concat $1 " " $2) ) + | SHORT + | INT + | LONG INT + ( (concat $1 " " $2) ) + | FLOAT + | DOUBLE + | BOOL + | LONG DOUBLE + ( (concat $1 " " $2) ) + ;; TODO: Klaus Berndl: Is there a long long, i think so?! + | LONG LONG + ( (concat $1 " " $2) ) + | LONG + ; + +builtintype + : signedmod builtintype-types + ( (concat (car $1) " " (car $2)) ) + | builtintype-types + ( ,$1 ) + ;; Klaus Berndl: unsigned is synonym for unsigned int and signed for + ;; signed int. To make this confusing stuff clear we add here the + ;; int. + | signedmod + ( (concat (car $1) " int") ) + ; + +;; Klaus Berndl: This parses also nonsense like "const volatile int +;; const volatile const const volatile a ..." but IMHO nobody writes +;; such code. Normaly we shoud define a rule like typeformbase-mode +;; which exactly defines the different allowed cases and combinations +;; of declmods (minus the CVDECLMOD) typeformbase and cv-declmods so +;; we could recognize more invalid code but IMHO this is not worth the +;; effort... +codeblock-var-or-fun + : declmods typeformbase declmods + opt-ref var-or-func-decl + ( ,(semantic-c-reconstitute-token ,$5 $1 $2 ) ) + ; + +var-or-fun + : codeblock-var-or-fun + ( ,$1 ) + ;; it is possible for a function to not have a type, and + ;; it is then assumed to be an int. How annoying. + ;; In C++, this could be a constructor or a destructor. + ;; Even more annoying. Only ever do this for regular + ;; top-level items. Ignore this problem in code blocks + ;; so that we don't have to deal with regular code + ;; being erroneously converted into types. + | declmods var-or-func-decl + ( ,(semantic-c-reconstitute-token ,$2 $1 nil ) ) + ; + +var-or-func-decl + : func-decl + ( ,$1 ) + | var-decl + ( ,$1 ) + ; + +func-decl + : opt-stars opt-class opt-destructor functionname + opt-template-specifier + opt-under-p + arg-list + opt-post-fcn-modifiers + opt-throw + opt-initializers + fun-or-proto-end + ( ,$4 'function + ;; Extra stuff goes in here. + ;; Continue with the stuff we found in + ;; this definition + $2 $3 $7 $9 $8 ,$1 ,$11 $5 ,$10) + | opt-stars opt-class opt-destructor functionname + opt-template-specifier + opt-under-p + ;; arg-list - - ini this case, a try implies a fcn. + opt-post-fcn-modifiers + opt-throw + opt-initializers + fun-try-end + ( ,$4 'function + ;; Extra stuff goes in here. + ;; Continue with the stuff we found in + ;; this definition + $2 $3 nil $8 $7 ,$1 ,$10 $5 ,$9) + ; + +var-decl + : varnamelist SEMICOLON + ( $1 'variable ) + ; + +opt-under-p + : UNDERP + ( nil ) + | UNDERUNDERP + ( nil ) + | ;;EMPTY + ; + +;; Klaus Berndl: symbol -> namespace-symbol +opt-initializers + : COLON namespace-symbol semantic-list opt-initializers + | COMA namespace-symbol semantic-list opt-initializers + | ;;EMPTY + ; + +opt-post-fcn-modifiers + : post-fcn-modifiers opt-post-fcn-modifiers + ( ,(cons ,$1 $2) ) + | ;;EMPTY + ( nil ) + ; + +post-fcn-modifiers + : REENTRANT + | CONST + ; + +opt-throw + : THROW semantic-list + ( EXPAND $2 throw-exception-list ) + | ;;EMPTY + ; + +;; Is this true? I don't actually know. +throw-exception-list + : namespace-symbol COMA throw-exception-list + ( ,(cons (car $1) $3) ) + | namespace-symbol RPAREN + ( ,$1 ) + | symbol RPAREN + ( $1 ) + | LPAREN throw-exception-list + ( ,$2 ) + | RPAREN + ( ) + ; + +opt-bits + : COLON number + ( $2 ) + | ;;EMPTY + ( nil ) + ; + +opt-array + : BRACK_BLCK opt-array + ;; Eventually we want to replace the 1 below with a size + ;; (if available) + ( (cons 1 (car ,$2) ) ) + | ;;EMPTY + ( nil ) + ; + +opt-assign + : EQUAL expression + ( $2 ) + | ;;EMPTY + ( nil ) + ; + +opt-restrict + : RESTRICT + | ;;EMPTY + ; + +;; Klaus Berndl: symbol -> namespace-symbol?! I think so. Can be that +;; then also some invalid C++-syntax is parsed but this is better than +;; not parsing valid syntax. +varname + : opt-stars opt-restrict namespace-symbol opt-bits opt-array + ( ,$3 ,$1 ,$4 ,$5 ) +; + +;; I should store more in this def, but leave it simple for now. +;; Klaus Berndl: const and volatile can be written after the type! +variablearg + : declmods typeformbase cv-declmods opt-ref variablearg-opt-name + ( VARIABLE-TAG (list $5) $2 nil + :constant-flag (if (member "const" (append $1 $3)) t nil) + :typemodifiers (delete "const" (append $1 $3)) + :reference (car ,$4) + ) + ; + +variablearg-opt-name + : varname + ( ,$1 ) + ;; Klaus Berndl: This allows variableargs without a arg-name being + ;; parsed correct even if there several pointers (*) + | opt-stars + ( "" ,$1 nil nil nil ) + ; + +varname-opt-initializer + : semantic-list + | opt-assign + | ;; EMPTY + ; + +varnamelist + : opt-ref varname varname-opt-initializer COMA varnamelist + ( ,(cons $2 $5) ) + | opt-ref varname varname-opt-initializer + ( $2 ) + ; + +;; Klaus Berndl: Is necessary to parse stuff like +;; class list_of_facts : public list<fact>, public entity +;; and +;; list <shared_ptr<item> >::const_iterator l; +;; Parses also invalid(?) and senseless(?) c++-syntax like +;; symbol<template-spec>::symbol1<template-spec1>::test_iterator +;; but better parsing too much than to less +namespace-symbol + : symbol opt-template-specifier COLON COLON namespace-symbol + ( (concat $1 "::" (car $5)) ) + | symbol opt-template-specifier + ( $1 ) + ; + +;; Don't pull an optional template specifier at the end of the +;; namespace symbol so that it can be picked up by the type. +namespace-symbol-for-typeformbase + : symbol opt-template-specifier COLON COLON namespace-symbol-for-typeformbase + ( (concat $1 "::" (car $5)) ) + | symbol + ( $1 ) + ; +;; namespace-symbol +;; : symbol COLON COLON namespace-symbol +;; ( (concat $1 "::" (car $4)) ) +;; | symbol +;; ( $1 ) +;; ; + +namespace-opt-class + : symbol COLON COLON namespace-opt-class + ( (concat $1 "::" (car $4)) ) + ;; Klaus Berndl: We must recognize template-specifiers here so we can + ;; parse correctly the method-implementations of template-classes + ;; outside the template-class-declaration Example: + ;; TemplateClass1<T>::method_1(...) + | symbol opt-template-specifier COLON COLON + ( $1 ) + ; + +;; Klaus Berndl: The opt-class of a func-decl must be able to +;; recognize opt-classes with namespaces, e.g. +;; Test1::Test2::classname:: +opt-class + : namespace-opt-class + ( ,$1 ) + | ;;EMPTY + ( nil ) + ; + +opt-destructor + : TILDE + ( t ) + | ;;EMPTY + ( nil ) + ; + +arg-list + : PAREN_BLCK knr-arguments + ( ,$2 ) + | PAREN_BLCK + (EXPANDFULL $1 arg-sub-list) + | VOID_BLCK + ( ) + ; + +knr-varnamelist + : varname COMA knr-varnamelist + ( ,(cons $1 $3) ) + | varname + ( $1 ) + ; + + +knr-one-variable-decl + : declmods typeformbase cv-declmods knr-varnamelist + ( VARIABLE-TAG (nreverse $4) $2 nil + :constant-flag (if (member "const" (append $3)) t nil) + :typemodifiers (delete "const" $3) + ) + ; + +knr-arguments + : knr-one-variable-decl SEMICOLON knr-arguments + ( ,(append (semantic-expand-c-tag ,$1) ,$3) ) + | knr-one-variable-decl SEMICOLON + ( ,(semantic-expand-c-tag ,$1) ) + ; + +arg-sub-list + : variablearg + ( ,$1 ) + | PERIOD PERIOD PERIOD RPAREN + (VARIABLE-TAG "..." "vararg" nil) + | COMA + ( nil ) + | LPAREN + ( nil ) + | RPAREN + ( nil ) + ; + +operatorsym + : LESS LESS EQUAL + ( "<<=" ) + | GREATER GREATER EQUAL + ( ">>=" ) + | LESS LESS + ( "<<" ) + | GREATER GREATER + ( ">>" ) + | EQUAL EQUAL + ( "==" ) + | LESS EQUAL + ( "<=" ) + | GREATER EQUAL + ( ">=" ) + | BANG EQUAL + ( "!=" ) + | PLUS EQUAL + ( "+=" ) + | MINUS EQUAL + ( "-=" ) + | STAR EQUAL + ( "*=" ) + | DIVIDE EQUAL + ( "/=" ) + | MOD EQUAL + ( "%=" ) + | AMPERSAND EQUAL + ( "&=" ) + | OR EQUAL + ( "|=" ) + | MINUS GREATER STAR + ( "->*" ) + | MINUS GREATER + ( "->" ) + | PARENS + ( "()" ) + | BRACKETS + ( "[]" ) + | LESS + | GREATER + | STAR + | PLUS PLUS + ( "++" ) + | PLUS + | MINUS MINUS + ( "--" ) + | MINUS + | AMPERSAND AMPERSAND + ( "&&" ) + | AMPERSAND + | OR OR + ( "||" ) + | OR + | DIVIDE + | EQUAL + | BANG + | TILDE + | MOD + | COMA + ;; HAT EQUAL seems to have a really unpleasant result and + ;; breaks everything after it. Leave it at the end, though it + ;; doesn't seem to work. + | HAT EQUAL + ( "^=" ) + | HAT + ; + +functionname + : OPERATOR operatorsym + ( ,$2 ) + | semantic-list + ( EXPAND $1 function-pointer ) + | symbol + ( $1 ) + ; + +function-pointer + : LPAREN STAR symbol RPAREN + ( (concat "*" $3) ) + ; + +fun-or-proto-end + : SEMICOLON + ( t ) + | semantic-list + ( nil ) + ;; Here is an anoying feature of C++ pure virtual methods + | EQUAL ZERO SEMICOLON + ( :pure-virtual-flag ) + | fun-try-end + ( nil ) + ; + +fun-try-end + : TRY opt-initializers BRACE_BLCK fun-try-several-catches + ( nil ) + ; + +fun-try-several-catches + : CATCH PAREN_BLCK BRACE_BLCK fun-try-several-catches + ( ) + | CATCH BRACE_BLCK fun-try-several-catches + ( ) + | ;; EMPTY + ( ) + ; + +type-cast + : semantic-list + ( EXPAND $1 type-cast-list ) + ; + +type-cast-list + : open-paren typeformbase close-paren + ; + +opt-stuff-after-symbol + : PAREN_BLCK + | BRACK_BLCK + | ;; EMPTY + ; + +multi-stage-dereference + : namespace-symbol opt-stuff-after-symbol PERIOD multi-stage-dereference ;; method call + | namespace-symbol opt-stuff-after-symbol MINUS GREATER multi-stage-dereference ;;method call + | namespace-symbol opt-stuff-after-symbol + ; + +string-seq + : string string-seq + ( (concat $1 (car $2)) ) + | string + ( $1 ) + ; + +expr-start + : MINUS + | PLUS + | STAR + | AMPERSAND + ; + +expr-binop + : MINUS + | PLUS + | STAR + | DIVIDE + | AMPERSAND AMPERSAND + | AMPERSAND + | OR OR + | OR + ;; There are more. + ; + +;; Use expression for parsing only. Don't actually return anything +;; for now. Hopefully we can fix this later. +expression + : unaryexpression expr-binop unaryexpression + ( (identity start) (identity end) ) + | unaryexpression + ( (identity start) (identity end) ) + ; + +unaryexpression + : number + | multi-stage-dereference + | NEW multi-stage-dereference + | NEW builtintype-types semantic-list + ;; Klaus Berndl: symbol -> namespace-symbol! + | namespace-symbol + ;; Klaus Berndl: C/C++ allows sequences of strings which are + ;; concatenated by the precompiler to one string + | string-seq + | type-cast expression ;; A cast to some other type + ;; Casting the results of one expression to something else. + | semantic-list expression + | semantic-list + | expr-start expression + ; + +;;; c.by ends here diff --git a/etc/grammars/grammar.wy b/etc/grammars/grammar.wy new file mode 100644 index 00000000000..d1a2bf15abf --- /dev/null +++ b/etc/grammars/grammar.wy @@ -0,0 +1,432 @@ +;;; semantic-grammar.wy -- LALR grammar of Semantic input grammars +;; +;; Copyright (C) 2002-2011 Free Software Foundation, Inc. +;; +;; Author: David Ponce <david@dponce.com> +;; Maintainer: David Ponce <david@dponce.com> +;; Created: 26 Aug 2002 +;; Keywords: syntax +;; X-RCS: $Id: semantic-grammar.wy,v 1.16 2005/09/30 20:20:27 zappo Exp $ + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +%{ + ;; Current parsed nonterminal name. + (defvar semantic-grammar-wy--nterm nil) + ;; Index of rule in a nonterminal clause. + (defvar semantic-grammar-wy--rindx nil) + } + +%package semantic-grammar-wy + +%languagemode wy-mode + +;; Main +%start grammar +;; Reparse +%start prologue epilogue declaration nonterminal rule +;; EXPANDFULL +%start put_names put_values use_names + +;; Keywords +%type <keyword> +%keyword DEFAULT-PREC "%default-prec" +%keyword NO-DEFAULT-PREC "%no-default-prec" +%keyword KEYWORD "%keyword" +%keyword LANGUAGEMODE "%languagemode" +%keyword LEFT "%left" +%keyword NONASSOC "%nonassoc" +%keyword PACKAGE "%package" +%keyword PREC "%prec" +%keyword PUT "%put" +%keyword QUOTEMODE "%quotemode" +%keyword RIGHT "%right" +%keyword SCOPESTART "%scopestart" +%keyword START "%start" +%keyword TOKEN "%token" +%keyword TYPE "%type" +%keyword USE-MACROS "%use-macros" + +;; Literals +%type <string> +%token <string> STRING + +%type <symbol> syntax ":?\\(\\sw\\|\\s_\\)+" +%token <symbol> SYMBOL +%token <symbol> PERCENT_PERCENT "\\`%%\\'" + +%type <char> syntax semantic-grammar-lex-c-char-re +%token <char> CHARACTER + +%type <qlist> matchdatatype sexp syntax "\\s'\\s-*(" +%token <qlist> PREFIXED_LIST + +%type <sexp> matchdatatype sexp syntax "\\=" +%token <sexp> SEXP + +;; Don't generate these analyzers which needs special handling code. +%token <code> PROLOGUE "%{...%}" +%token <code> EPILOGUE "%%...EOF" + +;; Blocks & Parenthesis +%type <block> +%token <block> PAREN_BLOCK "(LPAREN RPAREN)" +%token <block> BRACE_BLOCK "(LBRACE RBRACE)" +%token <open-paren> LPAREN "(" +%token <close-paren> RPAREN ")" +%token <open-paren> LBRACE "{" +%token <close-paren> RBRACE "}" + +;; Punctuations +%type <punctuation> +%token <punctuation> COLON ":" +%token <punctuation> SEMI ";" +%token <punctuation> OR "|" +%token <punctuation> LT "<" +%token <punctuation> GT ">" + +%% + +grammar: + prologue + | epilogue + | declaration + | nonterminal + | PERCENT_PERCENT + ; + +;;; Prologue/Epilogue +;; +prologue: + PROLOGUE + (CODE-TAG "prologue" nil) + ; + +epilogue: + EPILOGUE + (CODE-TAG "epilogue" nil) + ; + +;;; Declarations +;; +declaration: + decl + (eval $1) + ; + +decl: + default_prec_decl + | no_default_prec_decl + | languagemode_decl + | package_decl + | precedence_decl + | put_decl + | quotemode_decl + | scopestart_decl + | start_decl + | keyword_decl + | token_decl + | type_decl + | use_macros_decl + ; + +default_prec_decl: + DEFAULT-PREC + `(TAG "default-prec" 'assoc :value '("t")) + ; + +no_default_prec_decl: + NO-DEFAULT-PREC + `(TAG "default-prec" 'assoc :value '("nil")) + ; + +languagemode_decl: + LANGUAGEMODE symbols + `(TAG ',(car $2) 'languagemode :rest ',(cdr $2)) + ; + +package_decl: + PACKAGE SYMBOL + `(PACKAGE-TAG ',$2 nil) + ; + +precedence_decl: + associativity token_type_opt items + `(TAG ',$1 'assoc :type ',$2 :value ',$3) + ; + +associativity: + LEFT + (progn "left") + | RIGHT + (progn "right") + | NONASSOC + (progn "nonassoc") + ; + +put_decl: + PUT put_name put_value + `(TAG ',$2 'put :value ',(list $3)) + | PUT put_name put_value_list + `(TAG ',$2 'put :value ',$3) + | PUT put_name_list put_value + `(TAG ',(car $2) 'put :rest ',(cdr $2) :value ',(list $3)) + | PUT put_name_list put_value_list + `(TAG ',(car $2) 'put :rest ',(cdr $2) :value ',$3) + ; + +put_name_list: + BRACE_BLOCK + (mapcar 'semantic-tag-name (EXPANDFULL $1 put_names)) + ; + +put_names: + LBRACE + () + | RBRACE + () + | put_name + ;; Must return a list of Semantic tags to EXPANDFULL! + (TAG $1 'put-name) + ; + +put_name: + SYMBOL + | token_type + ; + +put_value_list: + BRACE_BLOCK + (mapcar 'semantic-tag-code-detail (EXPANDFULL $1 put_values)) + ; + +put_values: + LBRACE + () + | RBRACE + () + | put_value + ;; Must return a list of Semantic tags to EXPANDFULL! + (CODE-TAG "put-value" $1) + ; + +put_value: + SYMBOL any_value + (cons $1 $2) + ; + +scopestart_decl: + SCOPESTART SYMBOL + `(TAG ',$2 'scopestart) + ; + +quotemode_decl: + QUOTEMODE SYMBOL + `(TAG ',$2 'quotemode) + ; + +start_decl: + START symbols + `(TAG ',(car $2) 'start :rest ',(cdr $2)) + ; + +keyword_decl: + KEYWORD SYMBOL string_value + `(TAG ',$2 'keyword :value ',$3) + ; + +token_decl: + TOKEN token_type_opt SYMBOL string_value + `(TAG ',$3 ',(if $2 'token 'keyword) :type ',$2 :value ',$4) + | TOKEN token_type_opt symbols + `(TAG ',(car $3) 'token :type ',$2 :rest ',(cdr $3)) + ; + +token_type_opt: + ;; EMPTY + | token_type + ; + +token_type: + LT SYMBOL GT + (progn $2) + ; + +type_decl: + TYPE token_type plist_opt + `(TAG ',$2 'type :value ',$3) + ; + +plist_opt: + ;;EMPTY + | plist + ; + +plist: + plist put_value + (append (list $2) $1) + | put_value + (list $1) + ; + +use_name_list: + BRACE_BLOCK + (mapcar 'semantic-tag-name (EXPANDFULL $1 use_names)) + ; + +use_names: + LBRACE + () + | RBRACE + () + | SYMBOL + ;; Must return a list of Semantic tags to EXPANDFULL! + (TAG $1 'use-name) + ; + +use_macros_decl: + USE-MACROS SYMBOL use_name_list + `(TAG "macro" 'macro :type ',$2 :value ',$3) + ; + +string_value: + STRING + (read $1) + ; + +;; Return a Lisp readable form +any_value: + SYMBOL + | STRING + | PAREN_BLOCK + | PREFIXED_LIST + | SEXP + ; + +symbols: + lifo_symbols + (nreverse $1) + ; + +lifo_symbols: + lifo_symbols SYMBOL + (cons $2 $1) + | SYMBOL + (list $1) + ; + +;;; Grammar rules +;; +nonterminal: + SYMBOL + (setq semantic-grammar-wy--nterm $1 + semantic-grammar-wy--rindx 0) + COLON rules SEMI + (TAG $1 'nonterminal :children $4) + ; + +rules: + lifo_rules + (apply 'nconc (nreverse $1)) + ; + +lifo_rules: + lifo_rules OR rule + (cons $3 $1) + | rule + (list $1) + ; + +rule: + rhs + (let* ((nterm semantic-grammar-wy--nterm) + (rindx semantic-grammar-wy--rindx) + (rhs $1) + comps prec action elt) + (setq semantic-grammar-wy--rindx (1+ semantic-grammar-wy--rindx)) + (while rhs + (setq elt (car rhs) + rhs (cdr rhs)) + (cond + ;; precedence level + ((vectorp elt) + (if prec + (error "Duplicate %%prec in `%s:%d' rule" nterm rindx)) + (setq prec (aref elt 0))) + ;; action + ((consp elt) + ;; don't forget that rhs items are in reverse order, so + ;; the end-of-rule semantic action is the first item. + (if (or action comps) + ;; a mid-rule action + (setq comps (cons elt comps) + ;; keep rule and action index synchronized + semantic-grammar-wy--rindx + (1+ semantic-grammar-wy--rindx)) + ;; the end-of-rule action + (setq action (car elt)))) + ;; item + (t + (setq comps (cons elt comps))))) + (EXPANDTAG + (TAG (format "%s:%d" nterm rindx) 'rule + :type (if comps "group" "empty") + :value comps :prec prec :expr action))) + ; + +rhs: + ;; EMPTY + | rhs item + (cons $2 $1) + | rhs action + (cons (list $2) $1) + | rhs PREC item + (cons (vector $3) $1) + ; + +action: + PAREN_BLOCK + | PREFIXED_LIST + | BRACE_BLOCK + (format "(progn\n%s)" + (let ((s $1)) + (if (string-match "^{[\r\n\t ]*" s) + (setq s (substring s (match-end 0)))) + (if (string-match "[\r\n\t ]*}$" s) + (setq s (substring s 0 (match-beginning 0)))) + s)) + ; + +items: + lifo_items + (nreverse $1) + ; + +lifo_items: + lifo_items item + (cons $2 $1) + | item + (list $1) + ; + +item: + SYMBOL + | CHARACTER + ; + +%% + +;;; grammar.wy ends here diff --git a/etc/grammars/java-tags.wy b/etc/grammars/java-tags.wy new file mode 100644 index 00000000000..99d2b9df81d --- /dev/null +++ b/etc/grammars/java-tags.wy @@ -0,0 +1,750 @@ +;;; java-tags.wy -- Semantic LALR grammar for Java + +;; Copyright (C) 2002-2011 Free Software Foundation, Inc. +;; +;; Author: David Ponce <david@dponce.com> +;; Maintainer: David Ponce <david@dponce.com> +;; Created: 26 Aug 2002 +;; Keywords: syntax + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +%package wisent-java-tags-wy + +%languagemode java-mode + +;; The default start symbol +%start compilation_unit +;; Alternate entry points +;; - Needed by partial re-parse +%start package_declaration +%start import_declaration +%start class_declaration +%start field_declaration +%start method_declaration +%start formal_parameter +%start constructor_declaration +%start interface_declaration +;; - Needed by EXPANDFULL clauses +%start class_member_declaration +%start interface_member_declaration +%start formal_parameters + +;; ----------------------------- +;; Block & Parenthesis terminals +;; ----------------------------- +%type <block> ;;syntax "\\s(\\|\\s)" matchdatatype block + +%token <block> PAREN_BLOCK "(LPAREN RPAREN)" +%token <block> BRACE_BLOCK "(LBRACE RBRACE)" +%token <block> BRACK_BLOCK "(LBRACK RBRACK)" + +%token <open-paren> LPAREN "(" +%token <close-paren> RPAREN ")" +%token <open-paren> LBRACE "{" +%token <close-paren> RBRACE "}" +%token <open-paren> LBRACK "[" +%token <close-paren> RBRACK "]" + +;; ------------------ +;; Operator terminals +;; ------------------ +%type <punctuation> ;;syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string + +%token <punctuation> NOT "!" +%token <punctuation> NOTEQ "!=" +%token <punctuation> MOD "%" +%token <punctuation> MODEQ "%=" +%token <punctuation> AND "&" +%token <punctuation> ANDAND "&&" +%token <punctuation> ANDEQ "&=" +%token <punctuation> MULT "*" +%token <punctuation> MULTEQ "*=" +%token <punctuation> PLUS "+" +%token <punctuation> PLUSPLUS "++" +%token <punctuation> PLUSEQ "+=" +%token <punctuation> COMMA "," +%token <punctuation> MINUS "-" +%token <punctuation> MINUSMINUS "--" +%token <punctuation> MINUSEQ "-=" +%token <punctuation> DOT "." +%token <punctuation> DIV "/" +%token <punctuation> DIVEQ "/=" +%token <punctuation> COLON ":" +%token <punctuation> SEMICOLON ";" +%token <punctuation> LT "<" +%token <punctuation> LSHIFT "<<" +%token <punctuation> LSHIFTEQ "<<=" +%token <punctuation> LTEQ "<=" +%token <punctuation> EQ "=" +%token <punctuation> EQEQ "==" +%token <punctuation> GT ">" +%token <punctuation> GTEQ ">=" +%token <punctuation> RSHIFT ">>" +%token <punctuation> RSHIFTEQ ">>=" +%token <punctuation> URSHIFT ">>>" +%token <punctuation> URSHIFTEQ ">>>=" +%token <punctuation> QUESTION "?" +%token <punctuation> XOR "^" +%token <punctuation> XOREQ "^=" +%token <punctuation> OR "|" +%token <punctuation> OREQ "|=" +%token <punctuation> OROR "||" +%token <punctuation> COMP "~" + +;; ----------------- +;; Literal terminals +;; ----------------- +%type <symbol> ;;syntax "\\(\\sw\\|\\s_\\)+" +%token <symbol> IDENTIFIER + +%type <string> ;;syntax "\\s\"" matchdatatype sexp +%token <string> STRING_LITERAL + +%type <number> ;;syntax semantic-lex-number-expression +%token <number> NUMBER_LITERAL + +%type <unicode> syntax "\\\\u[0-9a-f][0-9a-f][0-9a-f][0-9a-f]" +%token <unicode> unicodecharacter + +;; ----------------- +;; Keyword terminals +;; ----------------- + +;; Generate a keyword analyzer +%type <keyword> ;;syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword + +%keyword ABSTRACT "abstract" +%put ABSTRACT summary +"Class|Method declaration modifier: abstract {class|<type>} <name> ..." + +%keyword BOOLEAN "boolean" +%put BOOLEAN summary +"Primitive logical quantity type (true or false)" + +%keyword BREAK "break" +%put BREAK summary +"break [<label>] ;" + +%keyword BYTE "byte" +%put BYTE summary +"Integral primitive type (-128 to 127)" + +%keyword CASE "case" +%put CASE summary +"switch(<expr>) {case <const-expr>: <stmts> ... }" + +%keyword CATCH "catch" +%put CATCH summary +"try {<stmts>} catch(<parm>) {<stmts>} ... " + +%keyword CHAR "char" +%put CHAR summary +"Integral primitive type ('\u0000' to '\uffff') (0 to 65535)" + +%keyword CLASS "class" +%put CLASS summary +"Class declaration: class <name>" + +%keyword CONST "const" +%put CONST summary +"Unused reserved word" + +%keyword CONTINUE "continue" +%put CONTINUE summary +"continue [<label>] ;" + +%keyword DEFAULT "default" +%put DEFAULT summary +"switch(<expr>) { ... default: <stmts>}" + +%keyword DO "do" +%put DO summary +"do <stmt> while (<expr>);" + +%keyword DOUBLE "double" +%put DOUBLE summary +"Primitive floating-point type (double-precision 64-bit IEEE 754)" + +%keyword ELSE "else" +%put ELSE summary +"if (<expr>) <stmt> else <stmt>" + +%keyword EXTENDS "extends" +%put EXTENDS summary +"SuperClass|SuperInterfaces declaration: extends <name> [, ...]" + +%keyword FINAL "final" +%put FINAL summary +"Class|Member declaration modifier: final {class|<type>} <name> ..." + +%keyword FINALLY "finally" +%put FINALLY summary +"try {<stmts>} ... finally {<stmts>}" + +%keyword FLOAT "float" +%put FLOAT summary +"Primitive floating-point type (single-precision 32-bit IEEE 754)" + +%keyword FOR "for" +%put FOR summary +"for ([<init-expr>]; [<expr>]; [<update-expr>]) <stmt>" + +%keyword GOTO "goto" +%put GOTO summary +"Unused reserved word" + +%keyword IF "if" +%put IF summary +"if (<expr>) <stmt> [else <stmt>]" + +%keyword IMPLEMENTS "implements" +%put IMPLEMENTS summary +"Class SuperInterfaces declaration: implements <name> [, ...]" + +%keyword IMPORT "import" +%put IMPORT summary +"Import package declarations: import <package>" + +%keyword INSTANCEOF "instanceof" + +%keyword INT "int" +%put INT summary +"Integral primitive type (-2147483648 to 2147483647)" + +%keyword INTERFACE "interface" +%put INTERFACE summary +"Interface declaration: interface <name>" + +%keyword LONG "long" +%put LONG summary +"Integral primitive type (-9223372036854775808 to 9223372036854775807)" + +%keyword NATIVE "native" +%put NATIVE summary +"Method declaration modifier: native <type> <name> ..." + +%keyword NEW "new" + +%keyword PACKAGE "package" +%put PACKAGE summary +"Package declaration: package <name>" + +%keyword PRIVATE "private" +%put PRIVATE summary +"Access level modifier: private {class|interface|<type>} <name> ..." + +%keyword PROTECTED "protected" +%put PROTECTED summary +"Access level modifier: protected {class|interface|<type>} <name> ..." + +%keyword PUBLIC "public" +%put PUBLIC summary +"Access level modifier: public {class|interface|<type>} <name> ..." + +%keyword RETURN "return" +%put RETURN summary +"return [<expr>] ;" + +%keyword SHORT "short" +%put SHORT summary +"Integral primitive type (-32768 to 32767)" + +%keyword STATIC "static" +%put STATIC summary +"Declaration modifier: static {class|interface|<type>} <name> ..." + +%keyword STRICTFP "strictfp" +%put STRICTFP summary +"Declaration modifier: strictfp {class|interface|<type>} <name> ..." + +%keyword SUPER "super" + +%keyword SWITCH "switch" +%put SWITCH summary +"switch(<expr>) {[case <const-expr>: <stmts> ...] [default: <stmts>]}" + + +%keyword SYNCHRONIZED "synchronized" +%put SYNCHRONIZED summary +"synchronized (<expr>) ... | Method decl. modifier: synchronized <type> <name> ..." + +%keyword THIS "this" + +%keyword THROW "throw" +%put THROW summary +"throw <expr> ;" + +%keyword THROWS "throws" +%put THROWS summary +"Method|Constructor declaration: throws <classType>, ..." + +%keyword TRANSIENT "transient" +%put TRANSIENT summary +"Field declaration modifier: transient <type> <name> ..." + +%keyword TRY "try" +%put TRY summary +"try {<stmts>} [catch(<parm>) {<stmts>} ...] [finally {<stmts>}]" + +%keyword VOID "void" +%put VOID summary +"Method return type: void <name> ..." + +%keyword VOLATILE "volatile" +%put VOLATILE summary +"Field declaration modifier: volatile <type> <name> ..." + +%keyword WHILE "while" +%put WHILE summary +"while (<expr>) <stmt> | do <stmt> while (<expr>);" + +;; -------------------------- +;; Official javadoc line tags +;; -------------------------- + +;; Javadoc tags are identified by a 'javadoc' keyword property. The +;; value of this property must be itself a property list where the +;; following properties are recognized: +;; +;; - `seq' (mandatory) is the tag sequence number used to check if tags +;; are correctly ordered in a javadoc comment block. +;; +;; - `usage' (mandatory) is the list of token categories for which this +;; documentation tag is allowed. +;; +;; - `opt' (optional) if non-nil indicates this is an optional tag. +;; By default tags are mandatory. +;; +;; - `with-name' (optional) if non-nil indicates that this tag is +;; followed by an identifier like in "@param <var-name> description" +;; or "@exception <class-name> description". +;; +;; - `with-ref' (optional) if non-nil indicates that the tag is +;; followed by a reference like in "@see <reference>". + +%keyword _AUTHOR "@author" +%put _AUTHOR javadoc (seq 1 usage (type)) +%keyword _VERSION "@version" +%put _VERSION javadoc (seq 2 usage (type)) +%keyword _PARAM "@param" +%put _PARAM javadoc (seq 3 usage (function) with-name t) +%keyword _RETURN "@return" +%put _RETURN javadoc (seq 4 usage (function)) +%keyword _EXCEPTION "@exception" +%put _EXCEPTION javadoc (seq 5 usage (function) with-name t) +%keyword _THROWS "@throws" +%put _THROWS javadoc (seq 6 usage (function) with-name t) +%keyword _SEE "@see" +%put _SEE javadoc (seq 7 usage (type function variable) opt t with-ref t) +%keyword _SINCE "@since" +%put _SINCE javadoc (seq 8 usage (type function variable) opt t) +%keyword _SERIAL "@serial" +%put _SERIAL javadoc (seq 9 usage (variable) opt t) +%keyword _SERIALDATA "@serialData" +%put _SERIALDATA javadoc (seq 10 usage (function) opt t) +%keyword _SERIALFIELD "@serialField" +%put _SERIALFIELD javadoc (seq 11 usage (variable) opt t) +%keyword _DEPRECATED "@deprecated" +%put _DEPRECATED javadoc (seq 12 usage (type function variable) opt t) + +%% + +;; ------------ +;; LALR Grammar +;; ------------ + +;; This grammar is not designed to fully parse correct Java syntax. It +;; is optimized to work in an interactive environment to extract tokens +;; (tags) needed by Semantic. In some cases a syntax not allowed by +;; the Java Language Specification will be accepted by this grammar. + +compilation_unit + : package_declaration + | import_declaration + | type_declaration + ; + +;;; Package statement token +;; ("NAME" package DETAIL "DOCSTRING") +package_declaration + : PACKAGE qualified_name SEMICOLON + (PACKAGE-TAG $2 nil) + ; + +;;; Include file token +;; ("FILE" include SYSTEM "DOCSTRING") +import_declaration + : IMPORT qualified_name SEMICOLON + (INCLUDE-TAG $2 nil) + | IMPORT qualified_name DOT MULT SEMICOLON + (INCLUDE-TAG (concat $2 $3 $4) nil) + ; + +type_declaration + : SEMICOLON + () + | class_declaration + | interface_declaration + ; + +;;; Type Declaration token +;; ("NAME" type "TYPE" ( PART-LIST ) ( PARENTS ) EXTRA-SPEC "DOCSTRING") +class_declaration + : modifiers_opt CLASS qualified_name superc_opt interfaces_opt class_body + (TYPE-TAG $3 $2 $6 (if (or $4 $5) (cons $4 $5)) :typemodifiers $1) + ; + +superc_opt + : ;;EMPTY + | EXTENDS qualified_name + (identity $2) + ; + +interfaces_opt + : ;;EMPTY + | IMPLEMENTS qualified_name_list + (nreverse $2) + ; + +class_body + : BRACE_BLOCK + (EXPANDFULL $1 class_member_declaration) + ; + +class_member_declaration + : LBRACE + () + | RBRACE + () + | block + () + | static_initializer + () + | constructor_declaration + | interface_declaration + | class_declaration + | method_declaration + | field_declaration + ; + +;;; Type Declaration token +;; ("NAME" type "TYPE" ( PART-LIST ) ( PARENTS ) EXTRA-SPEC "DOCSTRING") +interface_declaration + : modifiers_opt INTERFACE IDENTIFIER extends_interfaces_opt interface_body + (TYPE-TAG $3 $2 $5 (if $4 (cons nil $4)) :typemodifiers $1) + ; + +extends_interfaces_opt + : ;;EMPTY + | EXTENDS qualified_name_list + (identity $2) + ; + +interface_body + : BRACE_BLOCK + (EXPANDFULL $1 interface_member_declaration) + ; + +interface_member_declaration + : LBRACE + () + | RBRACE + () + | interface_declaration + | class_declaration + | method_declaration + | field_declaration + ; + +static_initializer + : STATIC block + ; + +;;; Function token +;; ("NAME" function "TYPE" ( ARG-LIST ) EXTRA-SPEC "DOCSTRING") +constructor_declaration + : modifiers_opt constructor_declarator throwsc_opt constructor_body + (FUNCTION-TAG (car $2) nil (cdr $2) + :typemodifiers $1 + :throws $3 + :constructor-flag t) + ; + +constructor_declarator + : IDENTIFIER formal_parameter_list + (cons $1 $2) + ; + +constructor_body + : block + ; + +;;; Function token +;; ("NAME" function "TYPE" ( ARG-LIST ) EXTRA-SPEC "DOCSTRING") +method_declaration + : modifiers_opt VOID method_declarator throwsc_opt method_body + (FUNCTION-TAG (car $3) $2 (cdr $3) :typemodifiers $1 :throws $4) + | modifiers_opt type method_declarator throwsc_opt method_body + (FUNCTION-TAG (car $3) $2 (cdr $3) :typemodifiers $1 :throws $4) + ; + +method_declarator + : IDENTIFIER formal_parameter_list dims_opt + (cons (concat $1 $3) $2) + ; + +throwsc_opt + : ;;EMPTY + | THROWS qualified_name_list + (nreverse $2) + ; + +qualified_name_list + : qualified_name_list COMMA qualified_name + (cons $3 $1) + | qualified_name + (list $1) + ; + +method_body + : SEMICOLON + | block + ; + +;; Just eat {...} block! +block + : BRACE_BLOCK + ; + +formal_parameter_list + : PAREN_BLOCK + (EXPANDFULL $1 formal_parameters) + ; + +formal_parameters + : LPAREN + () + | RPAREN + () + | formal_parameter COMMA + | formal_parameter RPAREN + ; + +;;; Variable token +;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING") +formal_parameter + : formal_parameter_modifier_opt type variable_declarator_id + (VARIABLE-TAG $3 $2 nil :typemodifiers $1) + ; + +formal_parameter_modifier_opt + : ;;EMPTY + | FINAL + (list $1) + ; + +;;; Variable token +;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING") +field_declaration + : modifiers_opt type variable_declarators SEMICOLON + (VARIABLE-TAG $3 $2 nil :typemodifiers $1) + ; + +variable_declarators + : variable_declarators COMMA variable_declarator + (progn + ;; Set the end of the compound declaration to the end of the + ;; COMMA delimiter. + (setcdr (cdr (car $1)) (cdr $region2)) + (cons $3 $1)) + | variable_declarator + (list $1) + ; + +variable_declarator + : variable_declarator_id EQ variable_initializer + (cons $1 $region) + | variable_declarator_id + (cons $1 $region) + ; + +variable_declarator_id + : IDENTIFIER dims_opt + (concat $1 $2) + ; + +variable_initializer + : expression + ; + +;; Just eat expression! +expression + : expression term + | term + ; + +term + : literal + | operator + | primitive_type + | IDENTIFIER + | BRACK_BLOCK + | PAREN_BLOCK + | BRACE_BLOCK + | NEW + | CLASS + | THIS + | SUPER + ; + +literal +;; : NULL_LITERAL +;; | BOOLEAN_LITERAL + : STRING_LITERAL + | NUMBER_LITERAL + ; + +operator + : NOT + | PLUS + | PLUSPLUS + | MINUS + | MINUSMINUS + | NOTEQ + | MOD + | MODEQ + | AND + | ANDAND + | ANDEQ + | MULT + | MULTEQ + | PLUSEQ + | MINUSEQ + | DOT + | DIV + | DIVEQ + | COLON + | LT + | LSHIFT + | LSHIFTEQ + | LTEQ + | EQ + | EQEQ + | GT + | GTEQ + | RSHIFT + | RSHIFTEQ + | URSHIFT + | URSHIFTEQ + | QUESTION + | XOR + | XOREQ + | OR + | OREQ + | OROR + | COMP + | INSTANCEOF + ; + +primitive_type + : BOOLEAN + | CHAR + | LONG + | INT + | SHORT + | BYTE + | DOUBLE + | FLOAT + ; + +modifiers_opt + : ;;EMPTY + | modifiers + (nreverse $1) + ; + +modifiers + : modifiers modifier + (cons $2 $1) + | modifier + (list $1) + ; + +modifier + : STRICTFP + | VOLATILE + | TRANSIENT + | SYNCHRONIZED + | NATIVE + | FINAL + | ABSTRACT + | STATIC + | PRIVATE + | PROTECTED + | PUBLIC + ; + +type + : qualified_name dims_opt + (concat $1 $2) + | primitive_type dims_opt + (concat $1 $2) + ; + +qualified_name + : qualified_name DOT IDENTIFIER + (concat $1 $2 $3) + | IDENTIFIER + ; + +dims_opt + : ;;EMPTY + (identity "") + | dims + ; + +dims + : dims BRACK_BLOCK + (concat $1 "[]") + | BRACK_BLOCK + (identity "[]") + ; + +%% +;; Define the lexer for this grammar +(define-lex wisent-java-tags-lexer + "Lexical analyzer that handles Java buffers. +It ignores whitespaces, newlines and comments." + semantic-lex-ignore-whitespace + semantic-lex-ignore-newline + semantic-lex-ignore-comments + ;;;; Auto-generated analyzers. + wisent-java-tags-wy--<number>-regexp-analyzer + wisent-java-tags-wy--<string>-sexp-analyzer + ;; Must detect keywords before other symbols + wisent-java-tags-wy--<keyword>-keyword-analyzer + wisent-java-tags-wy--<symbol>-regexp-analyzer + wisent-java-tags-wy--<punctuation>-string-analyzer + wisent-java-tags-wy--<block>-block-analyzer + ;; In theory, unicode chars should be turned into normal chars + ;; and then combined into regular ascii keywords and text. This + ;; analyzer just keeps these things from making the lexer go boom. + wisent-java-tags-wy--<unicode>-regexp-analyzer + ;;;; + semantic-lex-default-action) + +;;; java-tags.wy ends here diff --git a/etc/grammars/js.wy b/etc/grammars/js.wy new file mode 100644 index 00000000000..f67e2813daf --- /dev/null +++ b/etc/grammars/js.wy @@ -0,0 +1,524 @@ +;;; javascript-jv.wy -- LALR grammar for Javascript + +;; Copyright (C) 2005-2011 Free Software Foundation, Inc. +;; Copyright (C) 1998-2011 Ecma International. + +;; Author: Joakim Verona + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: + +;; The grammar itself is transcribed from the ECMAScript Language +;; Specification published at +;; +;; http://www.ecma-international.org/publications/standards/Ecma-262.htm +;; +;; and redistributed under the following license: + +;; Redistribution and use in source and binary forms, with or without +;; modification, are permitted provided that the following conditions +;; are met: + +;; 1. Redistributions of source code must retain the above copyright +;; notice, this list of conditions and the following disclaimer. + +;; 2. Redistributions in binary form must reproduce the above +;; copyright notice, this list of conditions and the following +;; disclaimer in the documentation and/or other materials provided +;; with the distribution. + +;; 3. Neither the name of the authors nor Ecma International may be +;; used to endorse or promote products derived from this software +;; without specific prior written permission. THIS SOFTWARE IS +;; PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR +;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +;; ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR +;; ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +;; OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +;; USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH +;; DAMAGE. + +%package wisent-javascript-jv-wy +;; JAVE I prefere ecmascript-mode +%languagemode ecmascript-mode javascript-mode + +;; The default goal +%start Program +;; Other Goals +%start FormalParameterList + +;; with the terminals stuff, I used the javacript.y names, +;; but the wisent-java-tags.wy types +;; when possible +;; ------------------ +;; Operator terminals +;; ------------------ + +;;define-lex-string-type-analyzer gets called with the "syntax" comment +%type <punctuation> ;;syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string + +%token <punctuation> ASSIGN_SYMBOL "=" +%token <punctuation> BITWISE_AND "&" +%token <punctuation> BITWISE_AND_EQUALS "&=" +%token <punctuation> BITWISE_EXCLUSIVE_OR "^" +%token <punctuation> BITWISE_EXCLUSIVE_OR_EQUALS "^=" +%token <punctuation> BITWISE_OR "|" +%token <punctuation> BITWISE_OR_EQUALS "|=" +%token <punctuation> BITWISE_SHIFT_LEFT "<<" +%token <punctuation> BITWISE_SHIFT_LEFT_EQUALS "<<=" +%token <punctuation> BITWISE_SHIFT_RIGHT ">>" +%token <punctuation> BITWISE_SHIFT_RIGHT_EQUALS ">>=" +%token <punctuation> BITWISE_SHIFT_RIGHT_ZERO_FILL ">>>" +%token <punctuation> BITWISE_SHIFT_RIGHT_ZERO_FILL_EQUALS ">>>=" +%token <punctuation> NOT_EQUAL "!=" +%token <punctuation> DIV_EQUALS "/=" +%token <punctuation> EQUALS "==" +%token <punctuation> GREATER_THAN ">" +%token <punctuation> GT_EQUAL ">=" +%token <punctuation> LOGICAL_AND "&&" +%token <punctuation> LOGICAL_OR "||" +%token <punctuation> LOGICAL_NOT "!!" +%token <punctuation> LS_EQUAL "<=" +%token <punctuation> MINUS "-" +%token <punctuation> MINUS_EQUALS "-=" +%token <punctuation> MOD "%" +%token <punctuation> MOD_EQUALS "%=" +%token <punctuation> MULTIPLY "*" +%token <punctuation> MULTIPLY_EQUALS "*=" +%token <punctuation> PLUS "+" +%token <punctuation> PLUS_EQUALS "+=" +%token <punctuation> INCREMENT "++" +%token <punctuation> DECREMENT "--" +%token <punctuation> DIV "/" +%token <punctuation> COLON ":" +%token <punctuation> COMMA "," +%token <punctuation> DOT "." +%token <punctuation> LESS_THAN "<" +%token <punctuation> LINE_TERMINATOR "\n" +%token <punctuation> SEMICOLON ";" +%token <punctuation> ONES_COMPLIMENT "~" + + +;; ----------------------------- +;; Block & Parenthesis terminals +;; ----------------------------- +%type <block> ;;syntax "\\s(\\|\\s)" matchdatatype block +%token <block> PAREN_BLOCK "(OPEN_PARENTHESIS CLOSE_PARENTHESIS)" +%token <block> BRACE_BLOCK "(START_BLOCK END_BLOCK)" +%token <block> BRACK_BLOCK "(OPEN_SQ_BRACKETS CLOSE_SQ_BRACKETS)" + +%token <open-paren> OPEN_PARENTHESIS "(" +%token <close-paren> CLOSE_PARENTHESIS ")" + +%token <open-paren> START_BLOCK "{" +%token <close-paren> END_BLOCK "}" + +%token <open-paren> OPEN_SQ_BRACKETS "[" +%token <close-paren> CLOSE_SQ_BRACKETS "]" + + +;; ----------------- +;; Keyword terminals +;; ----------------- + +;; Generate a keyword analyzer +%type <keyword> ;;syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword + +%keyword IF "if" +%put IF summary +"if (<expr>) <stmt> [else <stmt>] (jv)" + +%keyword BREAK "break" +%put BREAK summary +"break [<label>] ;" + +%keyword CONTINUE "continue" +%put CONTINUE summary +"continue [<label>] ;" + +%keyword ELSE "else" +%put ELSE summary +"if (<expr>) <stmt> else <stmt>" + + +%keyword FOR "for" +%put FOR summary +"for ([<init-expr>]; [<expr>]; [<update-expr>]) <stmt>" + + +%keyword FUNCTION "function" +%put FUNCTION summary +"function declaration blah blah" + +%keyword THIS "this" +%put THIS summary +"this" + + +%keyword RETURN "return" +%put RETURN summary +"return [<expr>] ;" + +%keyword WHILE "while" +%put WHILE summary +"while (<expr>) <stmt> | do <stmt> while (<expr>);" + +%keyword VOID_SYMBOL "void" +%put VOID_SYMBOL summary +"Method return type: void <name> ..." + + + +%keyword NEW "new" +%put NEW summary +"new <objecttype> - Creates a new object." + +%keyword DELETE "delete" +%put DELETE summary +"delete(<objectreference>) - Deletes the object." + +%keyword VAR "var" +%put VAR summary +"var <variablename> [= value];" + +%keyword WITH "with" +%put WITH summary +"with " + +%keyword TYPEOF "typeof" +%put TYPEOF summary +"typeof " + +%keyword IN "in" +%put IN summary +"in something" + + +;; ----------------- +;; Literal terminals +;; ----------------- + +;;the .y file uses VARIABLE as IDENTIFIER, which seems a bit evil +;; it think the normal .wy convention is better than this +%type <symbol> ;;syntax "\\(\\sw\\|\\s_\\)+" +%token <symbol> VARIABLE + +%type <string> ;;syntax "\\s\"" matchdatatype sexp +%token <string> STRING + +%type <number> ;;syntax semantic-lex-number-expression +%token <number> NUMBER + + +%token FALSE +%token TRUE +%token QUERY + + +%token NULL_TOKEN + +;;%token UNDEFINED_TOKEN +;;%token INFINITY + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; associativity and stuff +%left PLUS MINUS +%left MULTIPLY DIV MOD + +%nonassoc FALSE +%nonassoc HIGHER_THAN_FALSE +%nonassoc ELSE +%nonassoc LOWER_THAN_CLOSE_PARENTHESIS +%nonassoc CLOSE_PARENTHESIS + +%% + +Program : SourceElement + ; + +SourceElement : Statement + | FunctionDeclaration + ; + +Statement : Block + | VariableStatement + | EmptyStatement + | ExpressionStatement + | IfStatement + | IterationExpression + | ContinueStatement + | BreakStatement + | ReturnStatement + | WithStatement + ; + +FunctionDeclaration : FUNCTION VARIABLE FormalParameterListBlock Block + (FUNCTION-TAG $2 nil $3) + ; + +FormalParameterListBlock : PAREN_BLOCK + (EXPANDFULL $1 FormalParameterList) + ; + +FormalParameterList: OPEN_PARENTHESIS + () + | VARIABLE + (VARIABLE-TAG $1 nil nil) + | CLOSE_PARENTHESIS + () + | COMMA + () + ; + +StatementList : Statement + | StatementList Statement + ; + +Block : BRACE_BLOCK + ;; If you want to parse the body of the function + ;; ( EXPANDFULL $1 BlockExpand ) + ; + +BlockExpand: START_BLOCK StatementList END_BLOCK + | START_BLOCK END_BLOCK + ; + +VariableStatement : VAR VariableDeclarationList SEMICOLON + (VARIABLE-TAG $2 nil nil) + ; + +VariableDeclarationList : VariableDeclaration + (list $1) + | VariableDeclarationList COMMA VariableDeclaration + (append $1 (list $3)) + ; + +VariableDeclaration : VARIABLE + (append (list $1 nil) $region) + | VARIABLE Initializer + (append (cons $1 $2) $region) + ; + +Initializer : ASSIGN_SYMBOL AssignmentExpression + (list $2) + ; + +EmptyStatement : SEMICOLON + ; + +ExpressionStatement : Expression SEMICOLON + ; + +IfStatement : IF OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS Statement %prec HIGHER_THAN_FALSE + | IF OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS Statement ELSE Statement + | IF OPEN_PARENTHESIS FALSE CLOSE_PARENTHESIS Statement + | IF OPEN_PARENTHESIS LeftHandSideExpression AssignmentOperator AssignmentExpression CLOSE_PARENTHESIS Statement + ; + +IterationExpression : WHILE OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS Statement %prec HIGHER_THAN_FALSE + | WHILE OPEN_PARENTHESIS FALSE CLOSE_PARENTHESIS Statement + | WHILE OPEN_PARENTHESIS LeftHandSideExpression AssignmentOperator AssignmentExpression CLOSE_PARENTHESIS Statement + | FOR OPEN_PARENTHESIS OptionalExpression SEMICOLON OptionalExpression SEMICOLON OptionalExpression CLOSE_PARENTHESIS Statement + | FOR OPEN_PARENTHESIS VAR VariableDeclarationList SEMICOLON OptionalExpression SEMICOLON OptionalExpression CLOSE_PARENTHESIS Statement + | FOR OPEN_PARENTHESIS LeftHandSideExpression IN Expression CLOSE_PARENTHESIS Statement + | FOR OPEN_PARENTHESIS VAR VARIABLE OptionalInitializer IN Expression CLOSE_PARENTHESIS Statement + ; + +ContinueStatement : CONTINUE SEMICOLON + ; + +;;JAVE break needs labels +BreakStatement : BREAK SEMICOLON + ;; | BREAK identifier SEMICOLON + ; + +ReturnStatement : RETURN Expression SEMICOLON + | RETURN SEMICOLON + ; + +WithStatement : WITH OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS Statement + ; + +OptionalInitializer : Initializer + | + ; + +PrimaryExpression : THIS + | VARIABLE + | NUMBER + | STRING + | NULL_TOKEN + | TRUE + | FALSE + | OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS + ; + +MemberExpression : PrimaryExpression + | MemberExpression OPEN_SQ_BRACKETS Expression CLOSE_SQ_BRACKETS + | MemberExpression DOT VARIABLE + | NEW MemberExpression Arguments + ; + +NewExpression : MemberExpression + | NEW NewExpression + ; + +CallExpression : MemberExpression Arguments + | CallExpression Arguments + | CallExpression OPEN_SQ_BRACKETS Expression CLOSE_SQ_BRACKETS + | CallExpression DOT VARIABLE + ; + +Arguments : OPEN_PARENTHESIS CLOSE_PARENTHESIS + | OPEN_PARENTHESIS ArgumentList CLOSE_PARENTHESIS + ; + +ArgumentList : AssignmentExpression + | ArgumentList COMMA AssignmentExpression + ; + +LeftHandSideExpression : NewExpression + | CallExpression + ; + +PostfixExpression : LeftHandSideExpression + | LeftHandSideExpression INCREMENT + | LeftHandSideExpression DECREMENT + ; + +UnaryExpression : PostfixExpression + | DELETE UnaryExpression + | VOID_SYMBOL UnaryExpression + | TYPEOF UnaryExpression + | INCREMENT UnaryExpression + | DECREMENT UnaryExpression + | PLUS UnaryExpression + | MINUS UnaryExpression + | ONES_COMPLIMENT UnaryExpression + | LOGICAL_NOT UnaryExpression + ; + +MultiplicativeExpression : UnaryExpression + | MultiplicativeExpression MULTIPLY UnaryExpression + | MultiplicativeExpression DIV UnaryExpression + | MultiplicativeExpression MOD UnaryExpression + ; + +AdditiveExpression : MultiplicativeExpression + | AdditiveExpression PLUS MultiplicativeExpression + | AdditiveExpression MINUS MultiplicativeExpression + ; + +ShiftExpression : AdditiveExpression + | ShiftExpression BITWISE_SHIFT_LEFT AdditiveExpression + | ShiftExpression BITWISE_SHIFT_RIGHT AdditiveExpression + | ShiftExpression BITWISE_SHIFT_RIGHT_ZERO_FILL AdditiveExpression + ; + +RelationalExpression : ShiftExpression + | RelationalExpression LESS_THAN ShiftExpression + | RelationalExpression GREATER_THAN ShiftExpression + | RelationalExpression LS_EQUAL ShiftExpression + | RelationalExpression GT_EQUAL ShiftExpression + ; + +EqualityExpression : RelationalExpression + | EqualityExpression EQUALS RelationalExpression + | EqualityExpression NOT_EQUAL RelationalExpression + ; + +BitwiseANDExpression : EqualityExpression + | BitwiseANDExpression BITWISE_AND EqualityExpression + ; + +BitwiseXORExpression : BitwiseANDExpression + | BitwiseXORExpression BITWISE_EXCLUSIVE_OR BitwiseANDExpression + ; + +BitwiseORExpression : BitwiseXORExpression + | BitwiseORExpression BITWISE_OR BitwiseXORExpression + ; + +LogicalANDExpression : BitwiseORExpression + | LogicalANDExpression LOGICAL_AND BitwiseORExpression + ; + +LogicalORExpression : LogicalANDExpression + | LogicalORExpression LOGICAL_OR LogicalANDExpression + ; + +ConditionalExpression : LogicalORExpression + | LogicalORExpression QUERY AssignmentExpression COLON AssignmentExpression + ; + +AssignmentExpression : ConditionalExpression + | LeftHandSideExpression AssignmentOperator AssignmentExpression %prec LOWER_THAN_CLOSE_PARENTHESIS + ; + +AssignmentOperator : ASSIGN_SYMBOL + | MULTIPLY_EQUALS + | DIV_EQUALS + | MOD_EQUALS + | PLUS_EQUALS + | MINUS_EQUALS + | BITWISE_SHIFT_LEFT_EQUALS + | BITWISE_SHIFT_RIGHT_EQUALS + | BITWISE_SHIFT_RIGHT_ZERO_FILL_EQUALS + | BITWISE_AND_EQUALS + | BITWISE_EXCLUSIVE_OR_EQUALS + | BITWISE_OR_EQUALS + ; + +Expression : AssignmentExpression + | Expression COMMA AssignmentExpression + ; + +OptionalExpression : Expression + | + ; + +%% + +;;here something like: +;;(define-lex wisent-java-tags-lexer +;; should go +(define-lex javascript-lexer-jv +"javascript thingy" +;;std stuff + semantic-lex-ignore-whitespace + semantic-lex-ignore-newline + semantic-lex-ignore-comments + + ;;stuff generated from the wy file(one for each "type" declaration) + wisent-javascript-jv-wy--<number>-regexp-analyzer + wisent-javascript-jv-wy--<string>-sexp-analyzer + + wisent-javascript-jv-wy--<keyword>-keyword-analyzer + + wisent-javascript-jv-wy--<symbol>-regexp-analyzer + wisent-javascript-jv-wy--<punctuation>-string-analyzer + wisent-javascript-jv-wy--<block>-block-analyzer + + + ;;;;more std stuff + semantic-lex-default-action + ) diff --git a/etc/grammars/make.by b/etc/grammars/make.by new file mode 100644 index 00000000000..dab4472b737 --- /dev/null +++ b/etc/grammars/make.by @@ -0,0 +1,168 @@ +;;; make.by -- BY notation for Makefiles. + +;; Copyright (C) 1999-2011 Free Software Foundation, Inc. +;; +;; Author: Eric M. Ludlam <zappo@gnu.org> +;; David Ponce <david@dponce.com> +;; Klaus Berndl <klaus.berndl@sdm.de> +;; +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +%package semantic-make-by + +%languagemode makefile-mode +%start Makefile + +;; This was always a test case. +%quotemode backquote + +%token IF "if" +%token IFDEF "ifdef" +%token IFNDEF "ifndef" +%token IFEQ "ifeq" +%token IFNEQ "ifneq" +%token ELSE "else" +%token ENDIF "endif" +%token INCLUDE "include" + +%put { IF ELSE ENDIF } summary "Conditional: if (expression) ... else ... endif" +%put IFDEF summary "Conditional: ifdef (expression) ... else ... endif" +%put IFNDEF summary "Conditional: ifndef (expression) ... else ... endif" +%put IFEQ summary "Conditional: ifeq (expression) ... else ... endif" +%put IFNEQ summary "Conditional: ifneq (expression) ... else ... endif" +%put INCLUDE summary "Macro: include filename1 filename2 ..." + +%token <punctuation> COLON "\\`[:]\\'" +%token <punctuation> PLUS "\\`[+]\\'" +%token <punctuation> EQUAL "\\`[=]\\'" +%token <punctuation> DOLLAR "\\`[$]\\'" +%token <punctuation> BACKSLASH "\\`[\\]\\'" + +%% + +Makefile : bol newline (nil) + | bol variable + ( ,@$2 ) + | bol rule + ( ,@$2 ) + | bol conditional + ( ,@$2 ) + | bol include + ( ,@$2 ) + | whitespace ( nil ) + | newline ( nil ) + ; + +variable: symbol opt-whitespace equals opt-whitespace element-list + (VARIABLE-TAG ,$1 nil ,$5) + ; + +rule: targets opt-whitespace colons opt-whitespace element-list commands + (FUNCTION-TAG ,$1 nil ,$5) + ; + +targets: target opt-whitespace targets + ( (car ,$1) (car ,@$3) ) + | target + ( (car ,$1) ) + ; + +target: sub-target target + ( (concat (car ,$1) (car ,@$3) ) ) + | sub-target + ( (car ,$1) ) + ; + +sub-target: symbol + | string + | varref + ; + +conditional: IF some-whitespace symbol newline + ( nil ) + | IFDEF some-whitespace symbol newline + ( nil ) + | IFNDEF some-whitespace symbol newline + ( nil ) + | IFEQ some-whitespace expression newline + ( nil ) + | IFNEQ some-whitespace expression newline + ( nil ) + | ELSE newline + ( nil ) + | ENDIF newline + ( nil ) + ; + +expression : semantic-list + ; + +include: INCLUDE some-whitespace element-list + (INCLUDE-TAG ,$3 nil) + ; + +equals: COLON EQUAL () + | PLUS EQUAL () + | EQUAL () + ; + +colons: COLON COLON () + | COLON () + ; + +element-list: elements newline + ( ,@$1 ) + ; + +elements: element some-whitespace elements + ( ,@$1 ,@$3 ) + | element + ( ,@$1 ) + | ;;EMPTY + ; + +element: sub-element element + ( (concat (car ,$1) (car ,$2)) ) + | ;;EMPTY + ; + +sub-element: symbol + | string + | punctuation + | semantic-list + ( (buffer-substring-no-properties + (identity start) (identity end)) ) + ; + +varref: DOLLAR semantic-list + ( (buffer-substring-no-properties (identity start) (identity end)) ) + ; + +commands: bol shell-command newline commands + ( ,$1 ,@$2 ) + | ;;EMPTY + ( ) + ; + +opt-whitespace : some-whitespace ( nil ) + | ;;EMPTY + ; + +some-whitespace : whitespace some-whitespace (nil) + | whitespace (nil) + ; + +;;; make.by ends here diff --git a/etc/grammars/python.wy b/etc/grammars/python.wy new file mode 100644 index 00000000000..44d4394f369 --- /dev/null +++ b/etc/grammars/python.wy @@ -0,0 +1,1132 @@ +;;; python.wy -- LALR grammar for Python + +;; Copyright (C) 2002-2011 Free Software Foundation, Inc. +;; Copyright (C) 2001-2010 Python Software Foundation + +;; Author: Richard Kim <ryk@dspwiz.com> +;; Maintainer: Richard Kim <ryk@dspwiz.com> +;; Created: June 2002 +;; Keywords: syntax +;; +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: +;; +;; This is an LALR python parser that follows the official python +;; grammar closely with very few exceptions. The Python grammar is +;; used and reproduced under the following license: +;; +;; PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 +;; -------------------------------------------- +;; 1. This LICENSE AGREEMENT is between the Python Software Foundation +;; ("PSF"), and the Individual or Organization ("Licensee") accessing +;; and otherwise using this software ("Python") in source or binary +;; form and its associated documentation. +;; +;; 2. Subject to the terms and conditions of this License Agreement, +;; PSF hereby grants Licensee a nonexclusive, royalty-free, world-wide +;; license to reproduce, analyze, test, perform and/or display +;; publicly, prepare derivative works, distribute, and otherwise use +;; Python alone or in any derivative version, provided, however, that +;; PSF's License Agreement and PSF's notice of copyright, i.e., +;; "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, +;; 2009, 2010 Python Software Foundation; All Rights Reserved" are +;; retained in Python alone or in any derivative version prepared by +;; Licensee. +;; +;; 3. In the event Licensee prepares a derivative work that is based +;; on or incorporates Python or any part thereof, and wants to make +;; the derivative work available to others as provided herein, then +;; Licensee hereby agrees to include in any such work a brief summary +;; of the changes made to Python. +;; +;; 4. PSF is making Python available to Licensee on an "AS IS" +;; basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR +;; IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND +;; DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS +;; FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT +;; INFRINGE ANY THIRD PARTY RIGHTS. +;; +;; 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON +;; FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A +;; RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, OR +;; ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. +;; +;; 6. This License Agreement will automatically terminate upon a +;; material breach of its terms and conditions. +;; +;; 7. Nothing in this License Agreement shall be deemed to create any +;; relationship of agency, partnership, or joint venture between PSF +;; and Licensee. This License Agreement does not grant permission to +;; use PSF trademarks or trade name in a trademark sense to endorse or +;; promote products or services of Licensee, or any third party. +;; +;; 8. By copying, installing or otherwise using Python, Licensee +;; agrees to be bound by the terms and conditions of this License +;; Agreement. + +;;; To do: +;; +;; * Verify that semantic-lex-python-number regexp is correct. + +;; -------- +;; Settings +;; -------- + +%package wisent-python-wy + +%languagemode python-mode + +;; The default start symbol +%start goal +;; Alternate entry points +;; - Needed by partial re-parse +%start function_parameter +%start paren_class +%start indented_block +;; - Needed by EXPANDFULL clauses +%start function_parameters +%start paren_classes +%start indented_block_body + +;; ------------------------------- +;; Misc. Python specific terminals +;; ------------------------------- +;; The value of these tokens are for documentation only, they are not +;; used by the lexer. +%token <charquote> BACKSLASH "\\" +%token <newline> NEWLINE "\n" +%token <indentation> INDENT "^\\s-+" +%token <indentation> DEDENT "[^:INDENT:]" +%token <indentation> INDENT_BLOCK "(INDENT DEDENT)" + +;; ----------------------------- +;; Block & Parenthesis terminals +;; ----------------------------- +%type <block> ;;syntax "\\s(\\|\\s)" matchdatatype block + +%token <block> PAREN_BLOCK "(LPAREN RPAREN)" +%token <block> BRACE_BLOCK "(LBRACE RBRACE)" +%token <block> BRACK_BLOCK "(LBRACK RBRACK)" + +%token <open-paren> LPAREN "(" +%token <close-paren> RPAREN ")" +%token <open-paren> LBRACE "{" +%token <close-paren> RBRACE "}" +%token <open-paren> LBRACK "[" +%token <close-paren> RBRACK "]" + +;; ------------------ +;; Operator terminals +;; ------------------ +%type <punctuation> ;;syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string + +%token <punctuation> LTLTEQ "<<=" +%token <punctuation> GTGTEQ ">>=" +%token <punctuation> EXPEQ "**=" +%token <punctuation> DIVDIVEQ "//=" +%token <punctuation> DIVDIV "//" +%token <punctuation> LTLT "<<" +%token <punctuation> GTGT ">>" +%token <punctuation> EXPONENT "**" +%token <punctuation> EQ "==" +%token <punctuation> GE ">=" +%token <punctuation> LE "<=" +%token <punctuation> PLUSEQ "+=" +%token <punctuation> MINUSEQ "-=" +%token <punctuation> MULTEQ "*=" +%token <punctuation> DIVEQ "/=" +%token <punctuation> MODEQ "%=" +%token <punctuation> AMPEQ "&=" +%token <punctuation> OREQ "|=" +%token <punctuation> HATEQ "^=" +%token <punctuation> LTGT "<>" +%token <punctuation> NE "!=" +%token <punctuation> HAT "^" +%token <punctuation> LT "<" +%token <punctuation> GT ">" +%token <punctuation> AMP "&" +%token <punctuation> MULT "*" +%token <punctuation> DIV "/" +%token <punctuation> MOD "%" +%token <punctuation> PLUS "+" +%token <punctuation> MINUS "-" +%token <punctuation> PERIOD "." +%token <punctuation> TILDE "~" +%token <punctuation> BAR "|" +%token <punctuation> COLON ":" +%token <punctuation> SEMICOLON ";" +%token <punctuation> COMMA "," +%token <punctuation> ASSIGN "=" +%token <punctuation> BACKQUOTE "`" + + +;; ----------------- +;; Literal terminals +;; ----------------- +%token <string> STRING_LITERAL + +%type <number> ;;syntax semantic-lex-number-expression +%token <number> NUMBER_LITERAL + +%type <symbol> ;;syntax "\\(\\sw\\|\\s_\\)+" +%token <symbol> NAME + +;; ----------------- +;; Keyword terminals +;; ----------------- +%type <keyword> ;;syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword + +%keyword AND "and" +%put AND summary +"Logical AND binary operator ... " + +%keyword AS "as" +%put AS summary +"EXPR as NAME makes value of EXPR available as variable NAME" + +%keyword ASSERT "assert" +%put ASSERT summary +"Raise AssertionError exception if <expr> is false" + +%keyword BREAK "break" +%put BREAK summary +"Terminate 'for' or 'while' loop" + +%keyword CLASS "class" +%put CLASS summary +"Define a new class" + +%keyword CONTINUE "continue" +%put CONTINUE summary +"Skip to the next iteration of enclosing 'for' or 'while' loop" + +%keyword DEF "def" +%put DEF summary +"Define a new function" + +%keyword DEL "del" +%put DEL summary +"Delete specified objects, i.e., undo what assignment did" + +%keyword ELIF "elif" +%put ELIF summary +"Shorthand for 'else if' following an 'if' statement" + +%keyword ELSE "else" +%put ELSE summary +"Start the 'else' clause following an 'if' statement" + +%keyword EXCEPT "except" +%put EXCEPT summary +"Specify exception handlers along with 'try' keyword" + +%keyword EXEC "exec" +%put EXEC summary +"Dynamically execute Python code" + +%keyword FINALLY "finally" +%put FINALLY summary +"Specify code to be executed after 'try' statements whether or not an exception occurred" + +%keyword FOR "for" +%put FOR summary +"Start a 'for' loop" + +%keyword FROM "from" +%put FROM summary +"Modify behavior of 'import' statement" + +%keyword GLOBAL "global" +%put GLOBAL summary +"Declare one or more symbols as global symbols" + +%keyword IF "if" +%put IF summary +"Start 'if' conditional statement" + +%keyword IMPORT "import" +%put IMPORT summary +"Load specified modules" + +%keyword IN "in" +%put IN summary +"Part of 'for' statement " + +%keyword IS "is" +%put IS summary +"Binary operator that tests for object equality" + +%keyword LAMBDA "lambda" +%put LAMBDA summary +"Create anonymous function" + +%keyword NOT "not" +%put NOT summary +"Unary boolean negation operator" + +%keyword OR "or" +%put OR summary +"Binary logical 'or' operator" + +%keyword PASS "pass" +%put PASS summary +"Statement that does nothing" + +%keyword PRINT "print" +%put PRINT summary +"Print each argument to standard output" + +%keyword RAISE "raise" +%put RAISE summary +"Raise an exception" + +%keyword RETURN "return" +%put RETURN summary +"Return from a function" + +%keyword TRY "try" +%put TRY summary +"Start of statements protected by exception handlers" + +%keyword WHILE "while" +%put WHILE summary +"Start a 'while' loop" + +%keyword YIELD "yield" +%put YIELD summary +"Create a generator function" + +%% + +;;;**************************************************************************** +;;;@ goal +;;;**************************************************************************** + +;; simple_stmt are statements that do not involve INDENT tokens +;; compound_stmt are statements that involve INDENT tokens +goal + : NEWLINE + | simple_stmt + | compound_stmt + ; + +;;;**************************************************************************** +;;;@ simple_stmt +;;;**************************************************************************** + +;; simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE +simple_stmt + : small_stmt_list semicolon_opt NEWLINE + ; + +;; small_stmt (';' small_stmt)* +small_stmt_list + : small_stmt + | small_stmt_list SEMICOLON small_stmt + ; + +small_stmt + : expr_stmt + | print_stmt + | del_stmt + | pass_stmt + | flow_stmt + | import_stmt + | global_stmt + | exec_stmt + | assert_stmt + ; + +;;;============================================================================ +;;;@@ print_stmt +;;;============================================================================ + +;; print_stmt: 'print' [ test (',' test)* [','] ] +;; | '>>' test [ (',' test)+ [','] ] +print_stmt + : PRINT print_stmt_trailer + (CODE-TAG $1 nil) + ; + +;; [ test (',' test)* [','] ] | '>>' test [ (',' test)+ [','] ] +print_stmt_trailer + : test_list_opt + () + | GTGT test trailing_test_list_with_opt_comma_opt + () + ; + +;; [ (',' test)+ [','] ] +trailing_test_list_with_opt_comma_opt + : ;;EMPTY + | trailing_test_list comma_opt + () + ; + +;; (',' test)+ +trailing_test_list + : COMMA test + () + | trailing_test_list COMMA test + () + ; + +;;;============================================================================ +;;;@@ expr_stmt +;;;============================================================================ + +;; expr_stmt: testlist (augassign testlist | ('=' testlist)*) +expr_stmt + : testlist expr_stmt_trailer + (if (and $2 (stringp $1) (string-match "^\\(\\sw\\|\\s_\\)+$" $1)) + ;; If this is an assignment statement and left side is a symbol, + ;; then generate a 'variable token, else return 'code token. + (VARIABLE-TAG $1 nil nil) + (CODE-TAG $1 nil)) + ; + +;; Could be EMPTY because of eq_testlist_zom. +;; (augassign testlist | ('=' testlist)*) +expr_stmt_trailer + : augassign testlist + | eq_testlist_zom + ; + +;; Could be EMPTY! +;; ('=' testlist)* +eq_testlist_zom + : ;;EMPTY + | eq_testlist_zom ASSIGN testlist + (identity $3) + ; + +;; augassign: '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' +;; | '<<=' | '>>=' | '**=' | '//=' +augassign + : PLUSEQ | MINUSEQ | MULTEQ | DIVEQ | MODEQ + | AMPEQ | OREQ | HATEQ | LTLTEQ + | GTGTEQ | EXPEQ | DIVDIVEQ + ; + +;;;============================================================================ +;;;@@ del_stmt +;;;============================================================================ + +;; del_stmt: 'del' exprlist +del_stmt + : DEL exprlist + (CODE-TAG $1 nil) + ; + +;; exprlist: expr (',' expr)* [','] +exprlist + : expr_list comma_opt + () + ; + +;; expr (',' expr)* +expr_list + : expr + () + | expr_list COMMA expr + () + ; + +;;;============================================================================ +;;;@@ pass_stmt +;;;============================================================================ + +;; pass_stmt: 'pass' +pass_stmt + : PASS + (CODE-TAG $1 nil) + ; + +;;;============================================================================ +;;;@@ flow_stmt +;;;============================================================================ + +flow_stmt + : break_stmt + | continue_stmt + | return_stmt + | raise_stmt + | yield_stmt + ; + +;; break_stmt: 'break' +break_stmt + : BREAK + (CODE-TAG $1 nil) + ; + +;; continue_stmt: 'continue' +continue_stmt + : CONTINUE + (CODE-TAG $1 nil) + ; + +;; return_stmt: 'return' [testlist] +return_stmt + : RETURN testlist_opt + (CODE-TAG $1 nil) + ; + +;; [testlist] +testlist_opt + : ;;EMPTY + | testlist + () + ; + +;; yield_stmt: 'yield' testlist +yield_stmt + : YIELD + (CODE-TAG $1 nil) + | YIELD testlist + (CODE-TAG $1 nil) + ; + +;; raise_stmt: 'raise' [test [',' test [',' test]]] +raise_stmt + : RAISE zero_one_two_or_three_tests + (CODE-TAG $1 nil) + ; + +;; [test [',' test [',' test]]] +zero_one_two_or_three_tests + : ;;EMPTY + | test zero_one_or_two_tests + () + ; + +;; [',' test [',' test]] +zero_one_or_two_tests + : ;;EMPTY + | COMMA test zero_or_one_comma_test + () + ; + +;; [',' test] +zero_or_one_comma_test + : ;;EMPTY + | COMMA test + () + ; + +;;;============================================================================ +;;;@@ import_stmt +;;;============================================================================ + +;; import_stmt : 'import' dotted_as_name (',' dotted_as_name)* +;; | 'from' dotted_name 'import' +;; ('*' | import_as_name (',' import_as_name)*) +import_stmt + : IMPORT dotted_as_name_list + (INCLUDE-TAG $2 nil) + | FROM dotted_name IMPORT star_or_import_as_name_list + (INCLUDE-TAG $2 nil) + ; + +;; dotted_as_name (',' dotted_as_name)* +dotted_as_name_list + : dotted_as_name + | dotted_as_name_list COMMA dotted_as_name + ; + +;; ('*' | import_as_name (',' import_as_name)*) +star_or_import_as_name_list + : MULT + () + | import_as_name_list + () + ; + +;; import_as_name (',' import_as_name)* +import_as_name_list + : import_as_name + () + | import_as_name_list COMMA import_as_name + () + ; + +;; import_as_name: NAME [NAME NAME] +import_as_name + : NAME as_name_opt + () + ; + +;; dotted_as_name: dotted_name [AS NAME] +dotted_as_name + : dotted_name as_name_opt + ; + +;; [AS NAME] +as_name_opt + : ;;EMPTY + | AS NAME + (identity $2) + ; + +;; dotted_name: NAME ('.' NAME)* +dotted_name + : NAME + | dotted_name PERIOD NAME + (format "%s.%s" $1 $3) + ; + +;;;============================================================================ +;;;@@ global_stmt +;;;============================================================================ + +;; global_stmt: 'global' NAME (',' NAME)* +global_stmt + : GLOBAL comma_sep_name_list + (CODE-TAG $1 nil) + ; + +;; NAME (',' NAME)* +comma_sep_name_list + : NAME + | comma_sep_name_list COMMA NAME + ; + +;;;============================================================================ +;;;@@ exec_stmt +;;;============================================================================ + +;; exec_stmt: 'exec' expr ['in' test [',' test]] +exec_stmt + : EXEC expr exec_trailer + (CODE-TAG $1 nil) + ; + +;; ['in' test [',' test]] +exec_trailer + : ;;EMPTY + | IN test comma_test_opt + () + ; + +;; [',' test] +comma_test_opt + : ;;EMPTY + | COMMA test + () + ; + +;;;============================================================================ +;;;@@ assert_stmt +;;;============================================================================ + +;; assert_stmt: 'assert' test [',' test] +assert_stmt + : ASSERT test comma_test_opt + (CODE-TAG $1 nil) + ; + +;;;**************************************************************************** +;;;@ compound_stmt +;;;**************************************************************************** + +compound_stmt + : if_stmt + | while_stmt + | for_stmt + | try_stmt + | funcdef + | class_declaration + ; + +;;;============================================================================ +;;;@@ if_stmt +;;;============================================================================ + +;; if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] +if_stmt + : IF test COLON suite elif_suite_pair_list else_suite_pair_opt + (CODE-TAG $1 nil) + ; + +;; ('elif' test ':' suite)* +elif_suite_pair_list + : ;;EMPTY + | elif_suite_pair_list ELIF test COLON suite + () + ; + +;; ['else' ':' suite] +else_suite_pair_opt + : ;;EMPTY + | ELSE COLON suite + () + ; + +;; This NT follows the COLON token for most compound statements. +;; suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT +suite + : simple_stmt + (list $1) + | NEWLINE indented_block + (progn $2) + ; + +indented_block + : INDENT_BLOCK + (EXPANDFULL $1 indented_block_body) + ; + +indented_block_body + : INDENT + () + | DEDENT + () + | simple_stmt + | compound_stmt + ; + +;;;============================================================================ +;;;@@ while_stmt +;;;============================================================================ + +;; while_stmt: 'while' test ':' suite ['else' ':' suite] +while_stmt + : WHILE test COLON suite else_suite_pair_opt + (CODE-TAG $1 nil) + ; + +;;;============================================================================ +;;;@@ for_stmt +;;;============================================================================ + +;; for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] +for_stmt + : FOR exprlist IN testlist COLON suite else_suite_pair_opt + (CODE-TAG $1 nil) + ; + +;;;============================================================================ +;;;@@ try_stmt +;;;============================================================================ + +;; try_stmt: ('try' ':' suite (except_clause ':' suite)+ #diagram:break +;; ['else' ':' suite] | 'try' ':' suite 'finally' ':' suite) +try_stmt + : TRY COLON suite except_clause_suite_pair_list else_suite_pair_opt + (CODE-TAG $1 nil) + | TRY COLON suite FINALLY COLON suite + (CODE-TAG $1 nil) + ; + +;; (except_clause ':' suite)+ +except_clause_suite_pair_list + : except_clause COLON suite + () + | except_clause_suite_pair_list except_clause COLON suite + () + ; + +;; # NB compile.c makes sure that the default except clause is last +;; except_clause: 'except' [test [',' test]] +except_clause + : EXCEPT zero_one_or_two_test + () + ; + +;; [test [',' test]] +zero_one_or_two_test + : ;;EMPTY + | test zero_or_one_comma_test + () + ; + +;;;============================================================================ +;;;@@ funcdef +;;;============================================================================ + +;; funcdef: 'def' NAME parameters ':' suite +funcdef + : DEF NAME function_parameter_list COLON suite + (FUNCTION-TAG $2 nil $3) + ; + +function_parameter_list + : PAREN_BLOCK + (let ((wisent-python-EXPANDING-block t)) + (EXPANDFULL $1 function_parameters)) + ; + +;; parameters: '(' [varargslist] ')' +function_parameters + : LPAREN + () + | RPAREN + () + | function_parameter COMMA + | function_parameter RPAREN + ; + +function_parameter + : fpdef_opt_test + ;; : NAME + ;; (VARIABLE-TAG $1 nil nil) + | MULT NAME + (VARIABLE-TAG $2 nil nil) + | EXPONENT NAME + (VARIABLE-TAG $2 nil nil) + ; + +;;;============================================================================ +;;;@@ class_declaration +;;;============================================================================ + +;; classdef: 'class' NAME ['(' testlist ')'] ':' suite +class_declaration + : CLASS NAME paren_class_list_opt COLON suite + (TYPE-TAG $2 $1 ;; Name "class" + $5 ;; Members + (cons $3 nil) ;; (SUPERCLASSES . INTERFACES) + ) + ; + +;; ['(' testlist ')'] +paren_class_list_opt + : ;;EMPTY + | paren_class_list + ; + +paren_class_list + : PAREN_BLOCK + (let ((wisent-python-EXPANDING-block t)) + (mapcar 'semantic-tag-name (EXPANDFULL $1 paren_classes))) + ; + +;; parameters: '(' [varargslist] ')' +paren_classes + : LPAREN + () + | RPAREN + () + | paren_class COMMA + (VARIABLE-TAG $1 nil nil) + | paren_class RPAREN + (VARIABLE-TAG $1 nil nil) + ; + +;; In general, the base class can be specified by a general expression +;; which evalue to a class object, i.e., base classes are not just names! +;; However base classes are names in most cases. Thus the +;; non-terminals below work only with simple names. Even if the +;; parser can parse general expressions, I don't see much benefit in +;; generating a string of expression as base class "name". +paren_class + : dotted_name + ; + +;;;**************************************************************************** +;;;@ test +;;;**************************************************************************** + +;; test: and_test ('or' and_test)* | lambdef +test + : test_test + | lambdef + ; + +;; and_test ('or' and_test)* +test_test + : and_test + | test_test OR and_test + () + ; + +;; and_test: not_test ('and' not_test)* +and_test + : not_test + | and_test AND not_test + () + ; + +;; not_test: 'not' not_test | comparison +not_test + : NOT not_test + () + | comparison + ; + +;; comparison: expr (comp_op expr)* +comparison + : expr + | comparison comp_op expr + () + ; + +;; comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' +comp_op + : LT | GT | EQ | GE | LE | LTGT | NE | IN | NOT IN | IS | IS NOT + ; + +;; expr: xor_expr ('|' xor_expr)* +expr + : xor_expr + | expr BAR xor_expr + () + ; + +;; xor_expr: and_expr ('^' and_expr)* +xor_expr + : and_expr + | xor_expr HAT and_expr + () + ; + +;; and_expr: shift_expr ('&' shift_expr)* +and_expr + : shift_expr + | and_expr AMP shift_expr + () + ; + +;; shift_expr: arith_expr (('<<'|'>>') arith_expr)* +shift_expr + : arith_expr + | shift_expr shift_expr_operators arith_expr + () + ; + +;; ('<<'|'>>') +shift_expr_operators + : LTLT + | GTGT + ; + +;; arith_expr: term (('+'|'-') term)* +arith_expr + : term + | arith_expr plus_or_minus term + () + ; + +;; ('+'|'-') +plus_or_minus + : PLUS + | MINUS + ; + +;; term: factor (('*'|'/'|'%'|'//') factor)* +term + : factor + | term term_operator factor + () + ; + +term_operator + : MULT + | DIV + | MOD + | DIVDIV + ; + +;; factor: ('+'|'-'|'~') factor | power +factor + : prefix_operators factor + () + | power + ; + +;; ('+'|'-'|'~') +prefix_operators + : PLUS + | MINUS + | TILDE + ; + +;; power: atom trailer* ('**' factor)* +power + : atom trailer_zom exponent_zom + (concat $1 + (if $2 (concat " " $2 " ") "") + (if $3 (concat " " $3) "") + ) + ; + +trailer_zom + : ;;EMPTY + | trailer_zom trailer + () + ; + +exponent_zom + : ;;EMPTY + | exponent_zom EXPONENT factor + () + ; + +;; trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME +trailer + : PAREN_BLOCK + () + | BRACK_BLOCK + () + | PERIOD NAME + () + ; + +;; atom: '(' [testlist] ')' | '[' [listmaker] ']' | '{' [dictmaker] '}' +;; | '`' testlist '`' | NAME | NUMBER | STRING+ +atom + : PAREN_BLOCK + () + | BRACK_BLOCK + () + | BRACE_BLOCK + () + | BACKQUOTE testlist BACKQUOTE + () + | NAME + | NUMBER_LITERAL + | one_or_more_string + ; + +test_list_opt + : ;;EMPTY + | testlist + () + ; + +;; testlist: test (',' test)* [','] +testlist + : comma_sep_test_list comma_opt + ; + +;; test (',' test)* +comma_sep_test_list + : test + | comma_sep_test_list COMMA test + (format "%s, %s" $1 $3) + ; + +;; (read $1) and (read $2) were done before to peel away the double quotes. +;; However that does not work for single quotes, so it was taken out. +one_or_more_string + : STRING_LITERAL + | one_or_more_string STRING_LITERAL + (concat $1 $2) + ; + +;;;**************************************************************************** +;;;@ lambdef +;;;**************************************************************************** + +;; lambdef: 'lambda' [varargslist] ':' test +lambdef + : LAMBDA varargslist_opt COLON test + (format "%s %s" $1 (or $2 "")) + ; + +;; [varargslist] +varargslist_opt + : ;;EMPTY + | varargslist + ; + +;; varargslist: (fpdef ['=' test] ',')* ('*' NAME [',' '**' NAME] | '**' NAME) +;; | fpdef ['=' test] (',' fpdef ['=' test])* [','] +varargslist + : fpdef_opt_test_list_comma_zom rest_args + (nconc $2 $1) + | fpdef_opt_test_list comma_opt + ; + +;; ('*' NAME [',' '**' NAME] | '**' NAME) +rest_args + : MULT NAME multmult_name_opt + () ;;(VARIABLE-TAG $2 nil nil) + | EXPONENT NAME + () ;;(VARIABLE-TAG $2 nil nil) + ; + +;; [',' '**' NAME] +multmult_name_opt + : ;;EMPTY + | COMMA EXPONENT NAME + (VARIABLE-TAG $3 nil nil) + ; + +fpdef_opt_test_list_comma_zom + : ;;EMPTY + | fpdef_opt_test_list_comma_zom fpdef_opt_test COMMA + (nconc $2 $1) + ; + +;; fpdef ['=' test] (',' fpdef ['=' test])* +fpdef_opt_test_list + : fpdef_opt_test + | fpdef_opt_test_list COMMA fpdef_opt_test + (nconc $3 $1) + ; + +;; fpdef ['=' test] +fpdef_opt_test + : fpdef eq_test_opt + ; + +;; fpdef: NAME | '(' fplist ')' +fpdef + : NAME + (VARIABLE-TAG $1 nil nil) + ;; Below breaks the parser. Don't know why, but my guess is that + ;; LPAREN/RPAREN clashes with the ones in function_parameters. + ;; | LPAREN fplist RPAREN + ;; (identity $2) + ; + +;; fplist: fpdef (',' fpdef)* [','] +fplist + : fpdef_list comma_opt + ; + +;; fpdef (',' fpdef)* +fpdef_list + : fpdef + | fpdef_list COMMA fpdef + ; + +;; ['=' test] +eq_test_opt + : ;;EMPTY + | ASSIGN test + () + ; + +;;;**************************************************************************** +;;;@ Misc +;;;**************************************************************************** + +;; [','] +comma_opt + : ;;EMPTY + | COMMA + ; + +;; [';'] +semicolon_opt + : ;;EMPTY + | SEMICOLON + ; + +;;; wisent-python.wy ends here diff --git a/etc/grammars/scheme.by b/etc/grammars/scheme.by new file mode 100644 index 00000000000..bc6612d4c70 --- /dev/null +++ b/etc/grammars/scheme.by @@ -0,0 +1,84 @@ +;;; scheme.by -- Scheme BNF language specification + +;; Copyright (C) 2001-2011 Free Software Foundation, Inc. + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +%package semantic-scm-by + +%languagemode scheme-mode +%start scheme + +%token DEFINE "define" +%token DEFINE-MODULE "define-module" +%token LOAD "load" + +%put DEFINE summary "Function: (define symbol expression)" +%put DEFINE-MODULE summary "Function: (define-module (name arg1 ...)) " +%put LOAD summary "Function: (load \"filename\")" + +%token <open-paren> OPENPAREN "(" +%token <close-paren> CLOSEPAREN ")" + +%% + +scheme : semantic-list + (EXPAND $1 scheme-list) + ; + +scheme-list : OPENPAREN scheme-in-list CLOSEPAREN + ( ,$2 ) + ; + +scheme-in-list: DEFINE symbol expression + (VARIABLE-TAG $2 nil $3 ) + | DEFINE name-args opt-doc sequence + (FUNCTION-TAG (car ,$2) nil (cdr ,$2) ) + | DEFINE-MODULE name-args + (PACKAGE-TAG (nth (length $2) $2 ) nil) + | LOAD string + (INCLUDE-TAG (file-name-nondirectory (read $2)) (read $2) ) + | symbol + (CODE-TAG $1 nil) + ; + +name-args: semantic-list + (EXPAND $1 name-arg-expand) + ; + +name-arg-expand : open-paren name-arg-expand + ( ,$2 ) + | symbol name-arg-expand + ( ,(cons $1 ,$2) ) + | ;; EMPTY + ( ) + ; + +opt-doc : string + | ;; EMPTY + ; + +sequence : expression sequence + | expression + ; + +expression : symbol + | semantic-list + | string + | number + ; + +;;; scheme.by ends here diff --git a/etc/grammars/srecode-template.wy b/etc/grammars/srecode-template.wy new file mode 100644 index 00000000000..4ff2d7e4e41 --- /dev/null +++ b/etc/grammars/srecode-template.wy @@ -0,0 +1,235 @@ +;;; srecode-template.wy --- Semantic Recoder Template parser + +;; Copyright (C) 2005-2011 Free Software Foundation, Inc. + +;; Author: Eric Ludlam <zappo@gnu.org> +;; Keywords: syntax +;; X-RCS: $Id: srecode-template.wy,v 1.10 2009-01-09 23:01:54 zappo Exp $ + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: +;; +;; Parser for the Semantic Recoder template language +;; +;; Semantic Recoder templates are based on Google Templates +;; and are at the bottom of the Semantic Recoder API. + +%languagemode srecode-mode + +%start template_file + +;;; KEYWORDS +%type <keyword> +%keyword SET "set" +%put SET summary "set <name> <value>" +%keyword SHOW "show" +%put SHOW summary "show <name> ; to show a section" +%keyword MACRO "macro" +%put MACRO summary "... macro \"string\" ..." +%keyword CONTEXT "context" +%put CONTEXT summary "context <name>" +%keyword TEMPLATE "template" +%put TEMPLATE summary "template <name>\\n <template definition>" +%keyword SECTIONDICTIONARY "sectiondictionary" +%put SECTIONDICTIONARY summary "sectiondictionary <name>\\n <dictionary entries>" +%keyword PROMPT "prompt" +%keyword DEFAULT "default" +%keyword DEFAULTMACRO "defaultmacro" +%keyword READ "read" +%put { PROMPT DEFAULT DEFAULTMACRO READ } summary "prompt <symbol> \"Describe Symbol: \" [default[macro] <lispsym>|\"valuetext\"] [read <lispsym>]" +%keyword BIND "bind" +%put BIND summary "bind \"<letter>\"" + +;;; Punctuation Types +%type <punctuation> syntax "\\s.+" +%type <newline> +%token <newline> newline + +%token <separator> TEMPLATE_BLOCK "^----" + +;;; Bland default types +%type <property> ":\\(\\w\\|\\s_\\)*" +%token <property> property + +%type <symbol> +%token <symbol> symbol + +%type <string> +%token <string> string + +%type <number> +%token <number> number + +%% + +template_file + : newline ( ) + | context + | prompt + | variable + | template + ; + +context + : CONTEXT symbol newline + (TAG $2 'context) + ; + +prompt + : PROMPT symbol string opt-default-fcn opt-read-fcn newline + (TAG $2 'prompt :text (read $3) :default $4 :read $5) + ; + +opt-default-fcn + : DEFAULT symbol + (progn (read $2)) + | DEFAULT string + (progn (read $2)) + | DEFAULTMACRO string + (progn (cons 'macro (read $2))) + | () + ; + +opt-read-fcn + : READ symbol + (progn (read $2)) + | () + ; + +variable + : SET symbol insertable-string-list newline + (VARIABLE-TAG $2 nil $3) + | SHOW symbol newline + (VARIABLE-TAG $2 nil t) + ; + +insertable-string-list + : insertable-string + (list $1) + | insertable-string-list insertable-string + (append $1 (list $2)) + ; + +insertable-string + : string + (read $1) + | MACRO string + (cons 'macro (read $2)) + ; + +template + : TEMPLATE templatename opt-dynamic-arguments newline + opt-string + opt-section-dictionaries + TEMPLATE_BLOCK newline + opt-bind + (FUNCTION-TAG $2 nil $3 :documentation $5 :code $7 + :dictionaries $6 :binding $9 ) + ; + +templatename + : symbol + | PROMPT + | CONTEXT + | TEMPLATE + | DEFAULT + | MACRO + | DEFAULTMACRO + | READ + | SET + ; + +opt-dynamic-arguments + : property opt-dynamic-arguments + (cons $1 $2) + | () + ; + +opt-string + : string newline + ( read $1 ) + | () + ; + +opt-section-dictionaries + : () ;; EMPTY + | section-dictionary-list + ; + +section-dictionary-list + : one-section-dictionary + (list $1) + | section-dictionary-list one-section-dictionary + (append $1 (list $2)) + ; + +one-section-dictionary + : SECTIONDICTIONARY string newline + variable-list + (cons (read $2) $4) + ; + +variable-list + : variable + (EXPANDTAG $1) + | variable-list variable + (append $1 (EXPANDTAG $2)) + ; + +opt-bind + : BIND string newline + ( read $2 ) + | () + ; + +%% +(define-lex-simple-regex-analyzer srecode-template-property-analyzer + "Detect and create a dynamic argument properties." + ":\\(\\w\\|\\s_\\)*" 'property 0) + +(define-lex-regex-analyzer srecode-template-separator-block + "Detect and create a template quote block." + "^----\n" + (semantic-lex-push-token + (semantic-lex-token + 'TEMPLATE_BLOCK + (match-end 0) + (semantic-lex-unterminated-syntax-protection 'TEMPLATE_BLOCK + (goto-char (match-end 0)) + (re-search-forward "^----$") + (match-beginning 0)))) + (setq semantic-lex-end-point (point))) + + +(define-lex wisent-srecode-template-lexer + "Lexical analyzer that handles SRecode Template buffers. +It ignores whitespace, newlines and comments." + semantic-lex-newline + semantic-lex-ignore-whitespace + semantic-lex-ignore-newline + semantic-lex-ignore-comments + srecode-template-separator-block + srecode-template-wy--<keyword>-keyword-analyzer + srecode-template-property-analyzer + srecode-template-wy--<symbol>-regexp-analyzer + srecode-template-wy--<number>-regexp-analyzer + srecode-template-wy--<string>-sexp-analyzer + srecode-template-wy--<punctuation>-string-analyzer + semantic-lex-default-action + ) + +;;; wisent-dot.wy ends here diff --git a/etc/grammars/wisent-grammar.el b/etc/grammars/wisent-grammar.el new file mode 100644 index 00000000000..67b6032ea4e --- /dev/null +++ b/etc/grammars/wisent-grammar.el @@ -0,0 +1,542 @@ +;;; wisent-grammar.el --- Wisent's input grammar mode + +;; Copyright (C) 2002-2011 Free Software Foundation, Inc. +;; +;; Author: David Ponce <david@dponce.com> +;; Maintainer: David Ponce <david@dponce.com> +;; Created: 26 Aug 2002 +;; Keywords: syntax +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: +;; +;; Major mode for editing Wisent's input grammar (.wy) files. + +;;; Code: +(require 'semantic) +(require 'semantic/grammar) +(require 'semantic/find) +(require 'semantic/lex) +(require 'semantic/wisent) +(require 'semantic/bovine) + +(defsubst wisent-grammar-region-placeholder (symb) + "Given a $N placeholder symbol in SYMB, return a $regionN symbol. +Return nil if $N is not a valid placeholder symbol." + (let ((n (symbol-name symb))) + (if (string-match "^[$]\\([1-9][0-9]*\\)$" n) + (intern (concat "$region" (match-string 1 n)))))) + +(defun wisent-grammar-EXPAND (symb nonterm) + "Expand call to EXPAND grammar macro. +Return the form to parse from within a nonterminal. +SYMB is a $I placeholder symbol that gives the bounds of the area to +parse. +NONTERM is the nonterminal symbol to start with." + (unless (member nonterm (semantic-grammar-start)) + (error "EXPANDFULL macro called with %s, but not used with %%start" + nonterm)) + (let (($ri (wisent-grammar-region-placeholder symb))) + (if $ri + `(semantic-bovinate-from-nonterminal + (car ,$ri) (cdr ,$ri) ',nonterm) + (error "Invalid form (EXPAND %s %s)" symb nonterm)))) + +(defun wisent-grammar-EXPANDFULL (symb nonterm) + "Expand call to EXPANDFULL grammar macro. +Return the form to recursively parse an area. +SYMB is a $I placeholder symbol that gives the bounds of the area. +NONTERM is the nonterminal symbol to start with." + (unless (member nonterm (semantic-grammar-start)) + (error "EXPANDFULL macro called with %s, but not used with %%start" + nonterm)) + (let (($ri (wisent-grammar-region-placeholder symb))) + (if $ri + `(semantic-parse-region + (car ,$ri) (cdr ,$ri) ',nonterm 1) + (error "Invalid form (EXPANDFULL %s %s)" symb nonterm)))) + +(defun wisent-grammar-TAG (name class &rest attributes) + "Expand call to TAG grammar macro. +Return the form to create a generic semantic tag. +See the function `semantic-tag' for the meaning of arguments NAME, +CLASS and ATTRIBUTES." + `(wisent-raw-tag + (semantic-tag ,name ,class ,@attributes))) + +(defun wisent-grammar-VARIABLE-TAG (name type default-value &rest attributes) + "Expand call to VARIABLE-TAG grammar macro. +Return the form to create a semantic tag of class variable. +See the function `semantic-tag-new-variable' for the meaning of +arguments NAME, TYPE, DEFAULT-VALUE and ATTRIBUTES." + `(wisent-raw-tag + (semantic-tag-new-variable ,name ,type ,default-value ,@attributes))) + +(defun wisent-grammar-FUNCTION-TAG (name type arg-list &rest attributes) + "Expand call to FUNCTION-TAG grammar macro. +Return the form to create a semantic tag of class function. +See the function `semantic-tag-new-function' for the meaning of +arguments NAME, TYPE, ARG-LIST and ATTRIBUTES." + `(wisent-raw-tag + (semantic-tag-new-function ,name ,type ,arg-list ,@attributes))) + +(defun wisent-grammar-TYPE-TAG (name type members parents &rest attributes) + "Expand call to TYPE-TAG grammar macro. +Return the form to create a semantic tag of class type. +See the function `semantic-tag-new-type' for the meaning of arguments +NAME, TYPE, MEMBERS, PARENTS and ATTRIBUTES." + `(wisent-raw-tag + (semantic-tag-new-type ,name ,type ,members ,parents ,@attributes))) + +(defun wisent-grammar-INCLUDE-TAG (name system-flag &rest attributes) + "Expand call to INCLUDE-TAG grammar macro. +Return the form to create a semantic tag of class include. +See the function `semantic-tag-new-include' for the meaning of +arguments NAME, SYSTEM-FLAG and ATTRIBUTES." + `(wisent-raw-tag + (semantic-tag-new-include ,name ,system-flag ,@attributes))) + +(defun wisent-grammar-PACKAGE-TAG (name detail &rest attributes) + "Expand call to PACKAGE-TAG grammar macro. +Return the form to create a semantic tag of class package. +See the function `semantic-tag-new-package' for the meaning of +arguments NAME, DETAIL and ATTRIBUTES." + `(wisent-raw-tag + (semantic-tag-new-package ,name ,detail ,@attributes))) + +(defun wisent-grammar-CODE-TAG (name detail &rest attributes) + "Expand call to CODE-TAG grammar macro. +Return the form to create a semantic tag of class code. +See the function `semantic-tag-new-code' for the meaning of arguments +NAME, DETAIL and ATTRIBUTES." + `(wisent-raw-tag + (semantic-tag-new-code ,name ,detail ,@attributes))) + +(defun wisent-grammar-ALIAS-TAG (name aliasclass definition &rest attributes) + "Expand call to ALIAS-TAG grammar macro. +Return the form to create a semantic tag of class alias. +See the function `semantic-tag-new-alias' for the meaning of arguments +NAME, ALIASCLASS, DEFINITION and ATTRIBUTES." + `(wisent-raw-tag + (semantic-tag-new-alias ,name ,aliasclass ,definition ,@attributes))) + +(defun wisent-grammar-EXPANDTAG (raw-tag) + "Expand call to EXPANDTAG grammar macro. +Return the form to produce a list of cooked tags from raw form of +Semantic tag RAW-TAG." + `(wisent-cook-tag ,raw-tag)) + +(defun wisent-grammar-AST-ADD (ast &rest nodes) + "Expand call to AST-ADD grammar macro. +Return the form to update the abstract syntax tree AST with NODES. +See also the function `semantic-ast-add'." + `(semantic-ast-add ,ast ,@nodes)) + +(defun wisent-grammar-AST-PUT (ast &rest nodes) + "Expand call to AST-PUT grammar macro. +Return the form to update the abstract syntax tree AST with NODES. +See also the function `semantic-ast-put'." + `(semantic-ast-put ,ast ,@nodes)) + +(defun wisent-grammar-AST-GET (ast node) + "Expand call to AST-GET grammar macro. +Return the form to get, from the abstract syntax tree AST, the value +of NODE. +See also the function `semantic-ast-get'." + `(semantic-ast-get ,ast ,node)) + +(defun wisent-grammar-AST-GET1 (ast node) + "Expand call to AST-GET1 grammar macro. +Return the form to get, from the abstract syntax tree AST, the first +value of NODE. +See also the function `semantic-ast-get1'." + `(semantic-ast-get1 ,ast ,node)) + +(defun wisent-grammar-AST-GET-STRING (ast node) + "Expand call to AST-GET-STRING grammar macro. +Return the form to get, from the abstract syntax tree AST, the value +of NODE as a string. +See also the function `semantic-ast-get-string'." + `(semantic-ast-get-string ,ast ,node)) + +(defun wisent-grammar-AST-MERGE (ast1 ast2) + "Expand call to AST-MERGE grammar macro. +Return the form to merge the abstract syntax trees AST1 and AST2. +See also the function `semantic-ast-merge'." + `(semantic-ast-merge ,ast1 ,ast2)) + +(defun wisent-grammar-SKIP-BLOCK (&optional symb) + "Expand call to SKIP-BLOCK grammar macro. +Return the form to skip a parenthesized block. +Optional argument SYMB is a $I placeholder symbol that gives the +bounds of the block to skip. By default, skip the block at `$1'. +See also the function `wisent-skip-block'." + (let ($ri) + (when symb + (unless (setq $ri (wisent-grammar-region-placeholder symb)) + (error "Invalid form (SKIP-BLOCK %s)" symb))) + `(wisent-skip-block ,$ri))) + +(defun wisent-grammar-SKIP-TOKEN () + "Expand call to SKIP-TOKEN grammar macro. +Return the form to skip the lookahead token. +See also the function `wisent-skip-token'." + `(wisent-skip-token)) + +(defun wisent-grammar-assocs () + "Return associativity and precedence level definitions." + (mapcar + #'(lambda (tag) + (cons (intern (semantic-tag-name tag)) + (mapcar #'semantic-grammar-item-value + (semantic-tag-get-attribute tag :value)))) + (semantic-find-tags-by-class 'assoc (current-buffer)))) + +(defun wisent-grammar-terminals () + "Return the list of terminal symbols. +Keep order of declaration in the WY file without duplicates." + (let (terms) + (mapcar + #'(lambda (tag) + (mapcar #'(lambda (name) + (add-to-list 'terms (intern name))) + (cons (semantic-tag-name tag) + (semantic-tag-get-attribute tag :rest)))) + (semantic--find-tags-by-function + #'(lambda (tag) + (memq (semantic-tag-class tag) '(token keyword))) + (current-buffer))) + (nreverse terms))) + +;; Cache of macro definitions currently in use. +(defvar wisent--grammar-macros nil) + +(defun wisent-grammar-expand-macros (expr) + "Expand expression EXPR into a form without grammar macros. +Return the expanded expression." + (if (or (atom expr) (semantic-grammar-quote-p (car expr))) + expr ;; Just return atom or quoted expression. + (let* ((expr (mapcar 'wisent-grammar-expand-macros expr)) + (macro (assq (car expr) wisent--grammar-macros))) + (if macro ;; Expand Semantic built-in. + (apply (cdr macro) (cdr expr)) + expr)))) + +(defun wisent-grammar-nonterminals () + "Return the list form of nonterminal definitions." + (let ((nttags (semantic-find-tags-by-class + 'nonterminal (current-buffer))) + ;; Setup the cache of macro definitions. + (wisent--grammar-macros (semantic-grammar-macros)) + rltags nterms rules rule elems elem actn sexp prec) + (while nttags + (setq rltags (semantic-tag-components (car nttags)) + rules nil) + (while rltags + (setq elems (semantic-tag-get-attribute (car rltags) :value) + prec (semantic-tag-get-attribute (car rltags) :prec) + actn (semantic-tag-get-attribute (car rltags) :expr) + rule nil) + (when elems ;; not an EMPTY rule + (while elems + (setq elem (car elems) + elems (cdr elems)) + (setq elem (if (consp elem) ;; mid-rule action + (wisent-grammar-expand-macros (read (car elem))) + (semantic-grammar-item-value elem)) ;; item + rule (cons elem rule))) + (setq rule (nreverse rule))) + (if prec + (setq prec (vector (semantic-grammar-item-value prec)))) + (if actn + (setq sexp (wisent-grammar-expand-macros (read actn)))) + (setq rule (if actn + (if prec + (list rule prec sexp) + (list rule sexp)) + (if prec + (list rule prec) + (list rule)))) + (setq rules (cons rule rules) + rltags (cdr rltags))) + (setq nterms (cons (cons (intern (semantic-tag-name (car nttags))) + (nreverse rules)) + nterms) + nttags (cdr nttags))) + (nreverse nterms))) + +(defun wisent-grammar-grammar () + "Return Elisp form of the grammar." + (let* ((terminals (wisent-grammar-terminals)) + (nonterminals (wisent-grammar-nonterminals)) + (assocs (wisent-grammar-assocs))) + (cons terminals (cons assocs nonterminals)))) + +(defun wisent-grammar-parsetable-builder () + "Return the value of the parser table." + `(progn + ;; Ensure that the grammar [byte-]compiler is available. + (eval-when-compile (require 'semantic/wisent/comp)) + (wisent-compile-grammar + ',(wisent-grammar-grammar) + ',(semantic-grammar-start)))) + +(defun wisent-grammar-setupcode-builder () + "Return the parser setup code." + (format + "(semantic-install-function-overrides\n\ + '((parse-stream . wisent-parse-stream)))\n\ + (setq semantic-parser-name \"LALR\"\n\ + semantic--parse-table %s\n\ + semantic-debug-parser-source %S\n\ + semantic-flex-keywords-obarray %s\n\ + semantic-lex-types-obarray %s)\n\ + ;; Collect unmatched syntax lexical tokens\n\ + (semantic-make-local-hook 'wisent-discarding-token-functions)\n\ + (add-hook 'wisent-discarding-token-functions\n\ + 'wisent-collect-unmatched-syntax nil t)" + (semantic-grammar-parsetable) + (buffer-name) + (semantic-grammar-keywordtable) + (semantic-grammar-tokentable))) + +(defvar wisent-grammar-menu + '("WY Grammar" + ["LALR Compiler Verbose" wisent-toggle-verbose-flag + :style toggle :active (boundp 'wisent-verbose-flag) + :selected (and (boundp 'wisent-verbose-flag) + wisent-verbose-flag)] + ) + "WY mode specific grammar menu. +Menu items are appended to the common grammar menu.") + +(define-derived-mode wisent-grammar-mode semantic-grammar-mode "WY" + "Major mode for editing Wisent grammars." + (semantic-grammar-setup-menu wisent-grammar-menu) + (semantic-install-function-overrides + '((grammar-parsetable-builder . wisent-grammar-parsetable-builder) + (grammar-setupcode-builder . wisent-grammar-setupcode-builder) + ))) + +(add-to-list 'auto-mode-alist '("\\.wy$" . wisent-grammar-mode)) + +(defvar-mode-local wisent-grammar-mode semantic-grammar-macros + '( + (ASSOC . semantic-grammar-ASSOC) + (EXPAND . wisent-grammar-EXPAND) + (EXPANDFULL . wisent-grammar-EXPANDFULL) + (TAG . wisent-grammar-TAG) + (VARIABLE-TAG . wisent-grammar-VARIABLE-TAG) + (FUNCTION-TAG . wisent-grammar-FUNCTION-TAG) + (TYPE-TAG . wisent-grammar-TYPE-TAG) + (INCLUDE-TAG . wisent-grammar-INCLUDE-TAG) + (PACKAGE-TAG . wisent-grammar-PACKAGE-TAG) + (EXPANDTAG . wisent-grammar-EXPANDTAG) + (CODE-TAG . wisent-grammar-CODE-TAG) + (ALIAS-TAG . wisent-grammar-ALIAS-TAG) + (AST-ADD . wisent-grammar-AST-ADD) + (AST-PUT . wisent-grammar-AST-PUT) + (AST-GET . wisent-grammar-AST-GET) + (AST-GET1 . wisent-grammar-AST-GET1) + (AST-GET-STRING . wisent-grammar-AST-GET-STRING) + (AST-MERGE . wisent-grammar-AST-MERGE) + (SKIP-BLOCK . wisent-grammar-SKIP-BLOCK) + (SKIP-TOKEN . wisent-grammar-SKIP-TOKEN) + ) + "Semantic grammar macros used in wisent grammars.") + + +(defvar wisent-make-parsers--emacs-license + ";; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.") + +(defvar wisent-make-parsers--python-license + ";; It is derived in part from the Python grammar, used under the +;; following license: +;; +;; PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 +;; -------------------------------------------- +;; 1. This LICENSE AGREEMENT is between the Python Software Foundation +;; (\"PSF\"), and the Individual or Organization (\"Licensee\") accessing +;; and otherwise using this software (\"Python\") in source or binary +;; form and its associated documentation. +;; +;; 2. Subject to the terms and conditions of this License Agreement, +;; PSF hereby grants Licensee a nonexclusive, royalty-free, world-wide +;; license to reproduce, analyze, test, perform and/or display +;; publicly, prepare derivative works, distribute, and otherwise use +;; Python alone or in any derivative version, provided, however, that +;; PSF's License Agreement and PSF's notice of copyright, i.e., +;; \"Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, +;; 2009, 2010 Python Software Foundation; All Rights Reserved\" are +;; retained in Python alone or in any derivative version prepared by +;; Licensee. +;; +;; 3. In the event Licensee prepares a derivative work that is based +;; on or incorporates Python or any part thereof, and wants to make +;; the derivative work available to others as provided herein, then +;; Licensee hereby agrees to include in any such work a brief summary +;; of the changes made to Python. +;; +;; 4. PSF is making Python available to Licensee on an \"AS IS\" +;; basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR +;; IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND +;; DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS +;; FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT +;; INFRINGE ANY THIRD PARTY RIGHTS. +;; +;; 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON +;; FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A +;; RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, OR +;; ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. +;; +;; 6. This License Agreement will automatically terminate upon a +;; material breach of its terms and conditions. +;; +;; 7. Nothing in this License Agreement shall be deemed to create any +;; relationship of agency, partnership, or joint venture between PSF +;; and Licensee. This License Agreement does not grant permission to +;; use PSF trademarks or trade name in a trademark sense to endorse or +;; promote products or services of Licensee, or any third party. +;; +;; 8. By copying, installing or otherwise using Python, Licensee +;; agrees to be bound by the terms and conditions of this License +;; Agreement.") + +(defvar wisent-make-parsers--ecmascript-license + "\n;; It is derived from the grammar in the ECMAScript Language +;; Specification published at +;; +;; http://www.ecma-international.org/publications/standards/Ecma-262.htm +;; +;; and redistributed under the following license: +;; +;; Redistribution and use in source and binary forms, with or without +;; modification, are permitted provided that the following conditions +;; are met: +;; +;; 1. Redistributions of source code must retain the above copyright +;; notice, this list of conditions and the following disclaimer. +;; +;; 2. Redistributions in binary form must reproduce the above +;; copyright notice, this list of conditions and the following +;; disclaimer in the documentation and/or other materials provided +;; with the distribution. +;; +;; 3. Neither the name of the authors nor Ecma International may be +;; used to endorse or promote products derived from this software +;; without specific prior written permission. THIS SOFTWARE IS +;; PROVIDED BY THE ECMA INTERNATIONAL \"AS IS\" AND ANY EXPRESS OR +;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +;; ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR +;; ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +;; OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +;; USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH +;; DAMAGE.") + +(defvar wisent-make-parsers--parser-file-name + `(("semantic-grammar-wy.el" + "semantic/grammar-wy") + ("srecode-template-wy.el" + "srecode/srt-wy") + ("wisent-javascript-jv-wy.el" + "semantic/wisent/js-wy" + "Copyright (C) 1998-2011 Ecma International" + ,wisent-make-parsers--ecmascript-license) + ("wisent-java-tags-wy.el" + "semantic/wisent/javat-wy") + ("wisent-python-wy.el" + "semantic/wisent/python-wy" + "Copyright (C) 2001-2010 Python Software Foundation" + ,wisent-make-parsers--python-license))) + +(defun wisent-make-parsers () + "Generate Emacs' built-in Wisent-based parser files." + (semantic-mode 1) + ;; Loop through each .wy file in current directory, and run + ;; `semantic-grammar-batch-build-one-package' to build the grammar. + (dolist (f (directory-files default-directory nil ".wy$")) + (let ((packagename + (condition-case err + (with-current-buffer (find-file-noselect f) + (semantic-grammar-create-package)) + (error (message "%s" (error-message-string err)) nil))) + output-data) + (when (setq output-data (assoc packagename wisent-make-parsers--parser-file-name)) + (let ((require-name (nth 1 output-data)) + (additional-copyright (nth 2 output-data)) + (additional-license (nth 3 output-data)) + copyright-end) + ;; Touch up the generated parsers for Emacs integration. + (with-temp-buffer + (insert-file-contents packagename) + (setq buffer-file-name (expand-file-name packagename)) + ;; Fix copyright header: + (goto-char (point-min)) + (when additional-copyright + (re-search-forward "Copyright (C).*$") + (insert "\n;; " additional-copyright)) + (re-search-forward "^;; Author:") + (setq copyright-end (match-beginning 0)) + (re-search-forward "^;;; Code:\n") + (delete-region copyright-end (match-end 0)) + (goto-char copyright-end) + (insert wisent-make-parsers--emacs-license) + (insert "\n\n;;; Commentary: +;; +;; This file was generated from etc/grammars/" + f ".") + (when additional-license + (insert "\n" additional-license)) + (insert "\n\n;;; Code:\n +\(require 'semantic/lex)\n") + (goto-char (point-min)) + (delete-region (point-min) (line-end-position)) + (insert ";;; " require-name + ".el --- Generated parser support file") + (delete-trailing-whitespace) + (re-search-forward ";;\n(require 'semantic-lex)\n") + (delete-region (match-beginning 0) (match-end 0)) + ;; Fix footer: + (goto-char (point-max)) + (re-search-backward "^(provide") + (delete-region (match-beginning 0) (point-max)) + (goto-char (point-max)) + (insert "(provide '" require-name ")\n\n") + (insert ";;; " require-name ".el ends here\n") + (let ((make-backup-files nil)) + (save-buffer)))))))) + + + +;;; wisent-grammar.el ends here diff --git a/lisp/cedet/semantic/bovine/c-by.el b/lisp/cedet/semantic/bovine/c-by.el index 0308ace619b..36aa480e514 100644 --- a/lisp/cedet/semantic/bovine/c-by.el +++ b/lisp/cedet/semantic/bovine/c-by.el @@ -20,8 +20,7 @@ ;;; Commentary: ;; -;; This file was generated from the grammar file semantic/bovine/c.by -;; in the CEDET repository. +;; This file was generated from etc/grammars/c.by. ;;; Code: diff --git a/lisp/cedet/semantic/bovine/make-by.el b/lisp/cedet/semantic/bovine/make-by.el index 1db454f6ea8..17dd5613a50 100644 --- a/lisp/cedet/semantic/bovine/make-by.el +++ b/lisp/cedet/semantic/bovine/make-by.el @@ -20,8 +20,7 @@ ;;; Commentary: ;; -;; This file was generated from the grammar file -;; semantic/bovine/make.by in the CEDET repository. +;; This file was generated from etc/grammars/make.by. ;;; Code: diff --git a/lisp/cedet/semantic/bovine/scm-by.el b/lisp/cedet/semantic/bovine/scm-by.el index ac8211bfc8c..0b27abaf211 100644 --- a/lisp/cedet/semantic/bovine/scm-by.el +++ b/lisp/cedet/semantic/bovine/scm-by.el @@ -19,8 +19,7 @@ ;;; Commentary: ;; -;; This file was generated from the grammar file -;; semantic/bovine/scm.by in the CEDET repository. +;; This file was generated from etc/grammars/scm.by. ;;; Code: diff --git a/lisp/cedet/semantic/grammar-wy.el b/lisp/cedet/semantic/grammar-wy.el index 58f7f9900e2..59729863316 100644 --- a/lisp/cedet/semantic/grammar-wy.el +++ b/lisp/cedet/semantic/grammar-wy.el @@ -22,8 +22,7 @@ ;;; Commentary: ;; -;; This file is generated from the grammar file semantic-grammar.wy in -;; the upstream CEDET repository. +;; This file was generated from etc/grammars/grammar.wy. ;;; Code: diff --git a/lisp/cedet/semantic/wisent/javat-wy.el b/lisp/cedet/semantic/wisent/javat-wy.el index 258b1ac4af7..9057ee9fd45 100644 --- a/lisp/cedet/semantic/wisent/javat-wy.el +++ b/lisp/cedet/semantic/wisent/javat-wy.el @@ -19,8 +19,7 @@ ;;; Commentary: ;; -;; This file was generated from the grammar file -;; semantic/wisent/wisent-java-tags.wy in the CEDET repository. +;; This file was generated from etc/grammars/java-tags.wy. ;;; Code: diff --git a/lisp/cedet/semantic/wisent/js-wy.el b/lisp/cedet/semantic/wisent/js-wy.el index 021002059f8..a974a28bcd9 100644 --- a/lisp/cedet/semantic/wisent/js-wy.el +++ b/lisp/cedet/semantic/wisent/js-wy.el @@ -19,8 +19,42 @@ ;;; Commentary: ;; -;; This file was generated from the grammar file -;; semantic/wisent/wisent-javascript-jv.wy in the CEDET repository. +;; This file was generated from etc/grammars/js.wy. +;; +;; It is derived from the grammar in the ECMAScript Language +;; Specification published at +;; +;; http://www.ecma-international.org/publications/standards/Ecma-262.htm +;; +;; and redistributed under the following license: +;; +;; Redistribution and use in source and binary forms, with or without +;; modification, are permitted provided that the following conditions +;; are met: +;; +;; 1. Redistributions of source code must retain the above copyright +;; notice, this list of conditions and the following disclaimer. +;; +;; 2. Redistributions in binary form must reproduce the above +;; copyright notice, this list of conditions and the following +;; disclaimer in the documentation and/or other materials provided +;; with the distribution. +;; +;; 3. Neither the name of the authors nor Ecma International may be +;; used to endorse or promote products derived from this software +;; without specific prior written permission. THIS SOFTWARE IS +;; PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR +;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +;; ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR +;; ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +;; OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +;; USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH +;; DAMAGE. ;;; Code: (require 'semantic/lex) diff --git a/lisp/cedet/semantic/wisent/python-wy.el b/lisp/cedet/semantic/wisent/python-wy.el index 32466a31cec..f4cae7545fc 100644 --- a/lisp/cedet/semantic/wisent/python-wy.el +++ b/lisp/cedet/semantic/wisent/python-wy.el @@ -19,9 +19,59 @@ ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. ;;; Commentary: + +;; This file was generated from etc/grammars/python.wy. +;; It is derived in part from the Python grammar, used under the +;; following license: +;; +;; PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 +;; -------------------------------------------- +;; 1. This LICENSE AGREEMENT is between the Python Software Foundation +;; ("PSF"), and the Individual or Organization ("Licensee") accessing +;; and otherwise using this software ("Python") in source or binary +;; form and its associated documentation. +;; +;; 2. Subject to the terms and conditions of this License Agreement, +;; PSF hereby grants Licensee a nonexclusive, royalty-free, world-wide +;; license to reproduce, analyze, test, perform and/or display +;; publicly, prepare derivative works, distribute, and otherwise use +;; Python alone or in any derivative version, provided, however, that +;; PSF's License Agreement and PSF's notice of copyright, i.e., +;; "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, +;; 2009, 2010 Python Software Foundation; All Rights Reserved" are +;; retained in Python alone or in any derivative version prepared by +;; Licensee. +;; +;; 3. In the event Licensee prepares a derivative work that is based +;; on or incorporates Python or any part thereof, and wants to make +;; the derivative work available to others as provided herein, then +;; Licensee hereby agrees to include in any such work a brief summary +;; of the changes made to Python. +;; +;; 4. PSF is making Python available to Licensee on an "AS IS" +;; basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR +;; IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND +;; DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS +;; FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT +;; INFRINGE ANY THIRD PARTY RIGHTS. +;; +;; 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON +;; FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A +;; RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, OR +;; ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. +;; +;; 6. This License Agreement will automatically terminate upon a +;; material breach of its terms and conditions. +;; +;; 7. Nothing in this License Agreement shall be deemed to create any +;; relationship of agency, partnership, or joint venture between PSF +;; and Licensee. This License Agreement does not grant permission to +;; use PSF trademarks or trade name in a trademark sense to endorse or +;; promote products or services of Licensee, or any third party. ;; -;; This file was generated from the grammar file -;; semantic/wisent/wisent-python.wy in the CEDET repository. +;; 8. By copying, installing or otherwise using Python, Licensee +;; agrees to be bound by the terms and conditions of this License +;; Agreement. ;;; Code: diff --git a/lisp/cedet/srecode/srt-wy.el b/lisp/cedet/srecode/srt-wy.el index 3dde065c2a6..2910483bba3 100644 --- a/lisp/cedet/srecode/srt-wy.el +++ b/lisp/cedet/srecode/srt-wy.el @@ -18,8 +18,8 @@ ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. ;;; Commentary: - -;; Generated from srecode-template.wy in the CEDET repository. +;; +;; This file was generated from etc/grammars/srecode-template.wy. ;;; Code: |