;;; antlr-mode.el --- major mode for ANTLR grammar files
-;; Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+;; Free Software Foundation, Inc.
;;
;; Author: Christoph.Wedler@sap.com
;; Keywords: languages, ANTLR, code generator
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
\((java-mode \. 2) (c++-mode \. 0))
Java actions are fontified with level 2 and C++ actions are not
fontified at all."
+ :group 'antlr
:type '(choice (const :tag "None" none)
(const :tag "Inherit" inherit)
(const :tag "Default" nil)
in the grammar's actions and semantic predicates, see
`antlr-font-lock-maximum-decoration'.")
-(defvar antlr-font-lock-default-face 'antlr-font-lock-default-face)
-(defface antlr-font-lock-default-face nil
+(defvar antlr-default-face 'antlr-default)
+(defface antlr-default '((t nil))
"Face to prevent strings from language dependent highlighting.
Do not change."
:group 'antlr)
+;; backward-compatibility alias
+(put 'antlr-font-lock-default-face 'face-alias 'antlr-default)
-(defvar antlr-font-lock-keyword-face 'antlr-font-lock-keyword-face)
-(defface antlr-font-lock-keyword-face
+(defvar antlr-keyword-face 'antlr-keyword)
+(defface antlr-keyword
(cond-emacs-xemacs
'((((class color) (background light))
(:foreground "black" :EMACS :weight bold :XEMACS :bold t))))
"ANTLR keywords."
:group 'antlr)
+;; backward-compatibility alias
+(put 'antlr-font-lock-keyword-face 'face-alias 'antlr-keyword)
-(defvar antlr-font-lock-syntax-face 'antlr-font-lock-keyword-face)
-(defface antlr-font-lock-syntax-face
+(defvar antlr-syntax-face 'antlr-keyword)
+(defface antlr-syntax
(cond-emacs-xemacs
'((((class color) (background light))
(:foreground "black" :EMACS :weight bold :XEMACS :bold t))))
"ANTLR syntax symbols like :, |, (, ), ...."
:group 'antlr)
+;; backward-compatibility alias
+(put 'antlr-font-lock-syntax-face 'face-alias 'antlr-syntax)
-(defvar antlr-font-lock-ruledef-face 'antlr-font-lock-ruledef-face)
-(defface antlr-font-lock-ruledef-face
+(defvar antlr-ruledef-face 'antlr-ruledef)
+(defface antlr-ruledef
(cond-emacs-xemacs
'((((class color) (background light))
(:foreground "blue" :EMACS :weight bold :XEMACS :bold t))))
"ANTLR rule references (definition)."
:group 'antlr)
+;; backward-compatibility alias
+(put 'antlr-font-lock-ruledef-face 'face-alias 'antlr-ruledef)
-(defvar antlr-font-lock-tokendef-face 'antlr-font-lock-tokendef-face)
-(defface antlr-font-lock-tokendef-face
+(defvar antlr-tokendef-face 'antlr-tokendef)
+(defface antlr-tokendef
(cond-emacs-xemacs
'((((class color) (background light))
(:foreground "blue" :EMACS :weight bold :XEMACS :bold t))))
"ANTLR token references (definition)."
:group 'antlr)
+;; backward-compatibility alias
+(put 'antlr-font-lock-tokendef-face 'face-alias 'antlr-tokendef)
-(defvar antlr-font-lock-ruleref-face 'antlr-font-lock-ruleref-face)
-(defface antlr-font-lock-ruleref-face
+(defvar antlr-ruleref-face 'antlr-ruleref)
+(defface antlr-ruleref
'((((class color) (background light)) (:foreground "blue4")))
"ANTLR rule references (usage)."
:group 'antlr)
+;; backward-compatibility alias
+(put 'antlr-font-lock-ruleref-face 'face-alias 'antlr-ruleref)
-(defvar antlr-font-lock-tokenref-face 'antlr-font-lock-tokenref-face)
-(defface antlr-font-lock-tokenref-face
+(defvar antlr-tokenref-face 'antlr-tokenref)
+(defface antlr-tokenref
'((((class color) (background light)) (:foreground "orange4")))
"ANTLR token references (usage)."
:group 'antlr)
+;; backward-compatibility alias
+(put 'antlr-font-lock-tokenref-face 'face-alias 'antlr-tokenref)
-(defvar antlr-font-lock-literal-face 'antlr-font-lock-literal-face)
-(defface antlr-font-lock-literal-face
+(defvar antlr-literal-face 'antlr-literal)
+(defface antlr-literal
(cond-emacs-xemacs
'((((class color) (background light))
(:foreground "brown4" :EMACS :weight bold :XEMACS :bold t))))
It is used to highlight strings matched by the first regexp group of
`antlr-font-lock-literal-regexp'."
:group 'antlr)
+;; backward-compatibility alias
+(put 'antlr-font-lock-literal-face 'face-alias 'antlr-literal)
(defcustom antlr-font-lock-literal-regexp "\"\\(\\sw\\(\\sw\\|-\\)*\\)\""
"Regexp matching literals with special syntax highlighting, or nil.
(cond-emacs-xemacs
`((antlr-invalidate-context-cache)
("\\$setType[ \t]*(\\([A-Za-z\300-\326\330-\337]\\sw*\\))"
- (1 antlr-font-lock-tokendef-face))
- ("\\$\\sw+" (0 font-lock-keyword-face))
+ (1 antlr-tokendef-face))
+ ("\\$\\sw+" (0 keyword-face))
;; the tokens are already fontified as string/docstrings:
(,(lambda (limit)
(if antlr-font-lock-literal-regexp
(antlr-re-search-forward antlr-font-lock-literal-regexp limit)))
- (1 antlr-font-lock-literal-face t)
+ (1 antlr-literal-face t)
:XEMACS (0 nil)) ; XEmacs bug workaround
(,(lambda (limit)
(antlr-re-search-forward antlr-class-header-regexp limit))
- (1 antlr-font-lock-keyword-face)
- (2 antlr-font-lock-ruledef-face)
- (3 antlr-font-lock-keyword-face)
+ (1 antlr-keyword-face)
+ (2 antlr-ruledef-face)
+ (3 antlr-keyword-face)
(4 (if (member (match-string 4) '("Lexer" "Parser" "TreeParser"))
- 'antlr-font-lock-keyword-face
- 'font-lock-type-face)))
+ antlr-keyword-face
+ type-face)))
(,(lambda (limit)
(antlr-re-search-forward
"\\<\\(header\\|options\\|tokens\\|exception\\|catch\\|returns\\)\\>"
limit))
- (1 antlr-font-lock-keyword-face))
+ (1 antlr-keyword-face))
(,(lambda (limit)
(antlr-re-search-forward
"^\\(private\\|public\\|protected\\)\\>[ \t]*\\(\\(\\sw+[ \t]*\\(:\\)?\\)\\)?"
limit))
(1 font-lock-type-face) ; not XEmacs' java level-3 fruit salad
(3 (if (antlr-upcase-p (char-after (match-beginning 3)))
- 'antlr-font-lock-tokendef-face
- 'antlr-font-lock-ruledef-face) nil t)
- (4 antlr-font-lock-syntax-face nil t))
+ antlr-tokendef-face
+ antlr-ruledef-face) nil t)
+ (4 antlr-syntax-face nil t))
(,(lambda (limit)
(antlr-re-search-forward "^\\(\\sw+\\)[ \t]*\\(:\\)?" limit))
(1 (if (antlr-upcase-p (char-after (match-beginning 0)))
- 'antlr-font-lock-tokendef-face
- 'antlr-font-lock-ruledef-face) nil t)
- (2 antlr-font-lock-syntax-face nil t))
+ antlr-tokendef-face
+ antlr-ruledef-face) nil t)
+ (2 antlr-syntax-face nil t))
(,(lambda (limit)
;; v:ruleref and v:"literal" is allowed...
(antlr-re-search-forward "\\(\\sw+\\)[ \t]*\\([=:]\\)?" limit))
(1 (if (match-beginning 2)
(if (eq (char-after (match-beginning 2)) ?=)
- 'antlr-font-lock-default-face
- 'font-lock-variable-name-face)
+ antlr-default-face
+ font-lock-variable-name-face)
(if (antlr-upcase-p (char-after (match-beginning 1)))
- 'antlr-font-lock-tokenref-face
- 'antlr-font-lock-ruleref-face)))
- (2 antlr-font-lock-default-face nil t))
+ antlr-tokenref-face
+ antlr-ruleref-face)))
+ (2 antlr-default-face nil t))
(,(lambda (limit)
(antlr-re-search-forward "[|&:;(~]\\|)\\([*+?]\\|=>\\)?" limit))
- (0 'antlr-font-lock-syntax-face))))
+ (0 antlr-syntax-face))))
"Font-lock keywords for ANTLR's normal grammar code.
See `antlr-font-lock-keywords-alist' for the keywords of actions.")
(interactive (antlr-run-tool-interactive))
(or saved (save-some-buffers (not antlr-ask-about-save)))
(let ((default-directory (file-name-directory file)))
- (require 'compile) ; only `compile' autoload
- (compile-internal (concat command " " (file-name-nondirectory file))
- "No more errors" "Antlr-Run")))
+ (compilation-start (concat command " " (file-name-nondirectory file))
+ nil #'(lambda (mode-name) "*Antlr-Run*"))))
(defun antlr-run-tool-interactive ()
;; code in `interactive' is not compiled
(set (car settings) (eval (cadr settings)))))
(setq settings (cddr settings)))))
-(defun antlr-c-common-init ()
- "Like `c-basic-common-init' when using cc-mode before v5.30."
- ;; X/Emacs 20 only
- (make-local-variable 'paragraph-start)
- (make-local-variable 'paragraph-separate)
- (make-local-variable 'paragraph-ignore-fill-prefix)
- (make-local-variable 'require-final-newline)
- (make-local-variable 'parse-sexp-ignore-comments)
- (make-local-variable 'comment-start)
- (make-local-variable 'comment-multi-line)
- (make-local-variable 'outline-regexp)
- (make-local-variable 'outline-level)
- (make-local-variable 'adaptive-fill-regexp)
- (make-local-variable 'adaptive-fill-mode)
- (make-local-variable 'imenu-generic-expression) ;set in the mode functions
- (and (boundp 'comment-line-break-function)
- (make-local-variable 'comment-line-break-function))
- ;; Emacs 19.30 and beyond only, AFAIK
- (if (boundp 'fill-paragraph-function)
- (progn
- (make-local-variable 'fill-paragraph-function)
- (setq fill-paragraph-function 'c-fill-paragraph)))
- ;; now set their values
- (setq paragraph-start (concat page-delimiter "\\|$")
- paragraph-separate paragraph-start
- paragraph-ignore-fill-prefix t
- parse-sexp-ignore-comments t
- comment-column 32
- comment-multi-line nil
- comment-line-break-function 'c-comment-line-break-function
- adaptive-fill-regexp nil
- adaptive-fill-mode nil)
- (c-set-style (or antlr-indent-style "gnu"))
- (and (boundp 'c-current-comment-prefix) (boundp 'c-comment-prefix-regexp)
- (setq c-current-comment-prefix
- (if (listp c-comment-prefix-regexp)
- (cdr-safe (or (assoc major-mode c-comment-prefix-regexp)
- (assoc 'other c-comment-prefix-regexp)))
- c-comment-prefix-regexp)))
- ;; we have to do something special for c-offsets-alist so that the
- ;; buffer local value has its own alist structure.
- (setq c-offsets-alist (copy-alist c-offsets-alist))
- ;; setup the comment indent variable in a Emacs version portable way
- ;; ignore any byte compiler warnings you might get here
- (make-local-variable 'comment-indent-function)
- (setq comment-indent-function 'c-comment-indent))
-
(defun antlr-language-option (search)
"Find language in `antlr-language-alist' for language option.
If SEARCH is non-nil, find element for language option. Otherwise, find
(funcall init-fn))) ; is a function in v5.29
(t ; cc-mode upto 5.28
(antlr-c-init-language-vars))) ; do it myself
- (cond ((fboundp 'c-basic-common-init) ; cc-mode 5.30+
- (c-basic-common-init antlr-language (or antlr-indent-style "gnu")))
- (t
- (antlr-c-common-init)))
+ (c-basic-common-init antlr-language (or antlr-indent-style "gnu"))
(make-local-variable 'outline-regexp)
(make-local-variable 'outline-level)
(make-local-variable 'require-final-newline)
(make-local-variable 'indent-region-function)
(setq outline-regexp "[^#\n\^M]"
outline-level 'c-outline-level) ; TODO: define own
- (setq require-final-newline t)
+ (setq require-final-newline mode-require-final-newline)
(setq indent-line-function 'antlr-indent-line
indent-region-function nil) ; too lazy
(setq comment-start "// "
(imenu-add-to-menubar
(if (stringp antlr-imenu-name) antlr-imenu-name "Index")))
(antlr-set-tabs)
- (run-hooks 'antlr-mode-hook))
+ (run-mode-hooks 'antlr-mode-hook))
;; A smarter version of `group-buffers-menu-by-mode-then-alphabetically' (in
;; XEmacs) could use the following property. The header of the submenu would