]> code.delx.au - gnu-emacs/blobdiff - admin/grammars/bovine-grammar.el
Update CEDET from upstream.
[gnu-emacs] / admin / grammars / bovine-grammar.el
index 5a948608671ab11c9a0dd6668fcea40abecbc425..a7289f6bafee59dc86640b033782b3c8bfab86e0 100644 (file)
@@ -1,6 +1,6 @@
 ;;; bovine-grammar.el --- Bovine's input grammar mode
 ;;
-;; Copyright (C) 2002-2011 Free Software Foundation, Inc.
+;; Copyright (C) 2002-2012 Free Software Foundation, Inc.
 ;;
 ;; Author: David Ponce <david@dponce.com>
 ;; Maintainer: David Ponce <david@dponce.com>
@@ -142,6 +142,17 @@ expanded from elsewhere."
       (while form
         (setq first (car form)
               form  (cdr form))
+       ;; Hack for dealing with new reading of unquotes outside of
+       ;; backquote (introduced in rev. 102591 in emacs-bzr).
+       (when (and (>= emacs-major-version 24)
+                  (listp first)
+                  (or (equal (car first) '\,)
+                      (equal (car first) '\,@)))
+         (if (listp (cadr first))
+             (setq form (append (cdr first) form)
+                   first (car first))
+           (setq first (intern (concat (symbol-name (car first))
+                                       (symbol-name (cadr first)))))))
         (cond
          ((eq first nil)
           (when (and (not inlist) (not inplace))
@@ -279,7 +290,7 @@ 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
+LAMBDA is a lambda expression which is evalled 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.)
@@ -415,7 +426,7 @@ Menu items are appended to the common grammar menu.")
      (grammar-setupcode-builder  . bovine-grammar-setupcode-builder)
      )))
 
-(add-to-list 'auto-mode-alist '("\\.by$" . bovine-grammar-mode))
+(add-to-list 'auto-mode-alist '("\\.by\\'" . bovine-grammar-mode))
 
 (defvar-mode-local bovine-grammar-mode semantic-grammar-macros
   '(
@@ -435,4 +446,62 @@ Menu items are appended to the common grammar menu.")
 
 (provide 'semantic/bovine/grammar)
 
+(defun bovine-make-parsers ()
+  "Generate Emacs' built-in Bovine-based parser files."
+  (interactive)
+  (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 filename)
+      (when (and packagename
+                (string-match "^.*/\\(.*\\)-by\\.el\\'" packagename))
+       (setq lang (match-string 1 packagename))
+       (setq filename (concat lang "-by.el"))
+       (with-temp-buffer
+         (insert-file-contents filename)
+         (setq buffer-file-name (expand-file-name filename))
+         ;; 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 admin/grammars/"
+                 lang ".by.
+
+;;; Code:
+")
+         (goto-char (point-min))
+         (delete-region (point-min) (line-end-position))
+         (insert ";;; " packagename
+                 " --- Generated parser support file")
+         (delete-trailing-whitespace)
+         (re-search-forward ";;; \\(.*\\) ends here")
+         (replace-match packagename nil nil nil 1)
+         (save-buffer))))))
+
 ;;; bovine-grammar.el ends here