aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuanma Barranquero2003-01-31 20:43:22 +0000
committerJuanma Barranquero2003-01-31 20:43:22 +0000
commit4e7fbbc69bb5cb53d0ac00bd855a1bcc317ebec2 (patch)
tree7e29f3918f24f41ce12c14424d297563039f7e44
parent6d29587b1a00c1f57a562db62107b5e96be1e689 (diff)
downloademacs-4e7fbbc69bb5cb53d0ac00bd855a1bcc317ebec2.tar.gz
emacs-4e7fbbc69bb5cb53d0ac00bd855a1bcc317ebec2.zip
Version 2.2b
-rw-r--r--lisp/ChangeLog105
-rw-r--r--lisp/progmodes/antlr-mode.el790
2 files changed, 575 insertions, 320 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 45dae9f96dd..8d3617561ab 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,108 @@
12003-01-31 Christoph Wedler <Christoph.Wedler@sap.com>
2
3 * antlr-mode.el: Bug fixes, miscellaneous.
4 (antlr-mode): Make major mode work with cc-mode-5.29 or higher,
5 make it more rubust against changes in cc-mode's style variables
6 by using `boundp' and function `c-init-language-vars' if defined.
7 (antlr-c++-mode-extra): Only ask if language is not "Cpp".
8 (antlr-read-value): With completion, ignore case.
9 (antlr-run-tool-interactive): New function.
10 (antlr-run-tool): Use it for `interactive' specification.
11
12 * antlr-mode.el: Simplify Emacs/XEmacs compatibility.
13 (cond-emacs-xemacs): New compile-time macro.
14 (defunx): New compile-time macro.
15 (ignore-errors-x): New compile-time macro.
16 (save-buffer-state-x): New compile-time macro.
17
18 (antlr-scan-sexps, antlr-simple-scan-sexps): Deletia.
19 (antlr-scan-lists, antlr-simple-scan-sexps): Deletia.
20 (antlr-simple-default-directory): Deletia.
21 (antlr-default-directory): Define directly.
22 (antlr-simple-read-shell-command): Deletia.
23 (antlr-read-shell-command): Define directly.
24 (antlr-simple-with-displaying-help-buffer): Deletia.
25 (antlr-with-displaying-help-buffer): Define directly.
26 (antlr-fast-invalidate-context-cache): Deletia.
27 (antlr-slow-invalidate-context-cache): Deletia.
28 (antlr-invalidate-context-cache): Define directly.
29 (antlr-fast-syntactic-context): Deletia.
30 (antlr-slow-syntactic-context): Deletia.
31 (antlr-syntactic-context): Define directly.
32
33 (antlr-mode-menu): Use new macros.
34 (antlr-font-lock-additional-keywords): Ditto.
35 (antlr-skip-sexps): Ditto.
36 (antlr-end-of-rule): Ditto.
37 (antlr-beginning-of-rule): Ditto.
38 (antlr-end-of-body): Ditto.
39 (antlr-beginning-of-body): Ditto.
40 (antlr-hide-actions): Ditto.
41 (antlr-option-kind): Ditto.
42
43 * antlr-mode.el: In Emacs, use face attribute :weight, not :bold.
44 (antlr-font-lock-keyword-face): Use new macros.
45 (antlr-font-lock-syntax-face): Ditto.
46 (antlr-font-lock-ruledef-face): Ditto.
47 (antlr-font-lock-tokendef-face): Ditto.
48 (antlr-font-lock-literal-face): Ditto.
49
50 Changes from 2002-05-24:
51
52 * antlr-mode.el: Version 2.2a.
53
54 Changes from 2002-05-03:
55
56 * antlr-mode.el: Make context parsing faster on Emacs, for faster
57 syntax highlighting, indentation and imenu support.
58 Suggested by Aaron Davies <adavies42@users.sourceforge.net>.
59 (antlr-slow-context-cache): New variable.
60 (antlr-slow-syntactic-context): Use cache.
61 (antlr-slow-cache-enabling-symbol): New internal variable.
62 (antlr-slow-cache-diff-threshold): New variable.
63 (antlr-fast-invalidate-context-cache): Renamed from
64 antlr-xemacs-bug-workaround.
65 (antlr-imenu-create-index-function): Search from beginning.
66
67 * antlr-mode.el: More sophisticated indentation, i.e., use the
68 indentation engine of cc-mode for most actions.
69 (antlr-c-common-init): Allow nil for `antlr-indent-style'.
70 (antlr-indent-line): Use indentation engine of cc-mode more often.
71 (antlr-indent-at-bol-alist): Only used for header actions.
72 (antlr-disabling-cc-syntactic-symbols): New variable.
73 (antlr-indent-item-regexp): Delete stuff for actions.
74 (antlr-indent-at-bol-alist): With language "Java", indent
75 "package" and "import" at column 0 in header part.
76
77 * antlr-mode.el (antlr-simple-default-directory): Define.
78 (antlr-simple-read-shell-command): Define.
79 (antlr-simple-with-displaying-help-buffer): Define.
80 (antlr-simple-scan-sexps, antlr-simple-scan-lists):
81 Renamed from antlr-scan-{sexps,lists}-internal.
82
83 Changes from 2002-02-28:
84
85 * antlr-mode: Version 2.2 is released.
86
87 * antlr-mode.el (antlr): Moved to SourceForge.net
88
89 Changes from 2002-02-28:
90
91 * antlr-mode.el: Minor bug fixes: insert options and indentation.
92 (antlr-option-location): Don't use point as position where to
93 insert options if point is in comment.
94 (antlr-mode): Don't set style here.
95 (antlr-c-common-init): Set style here. If boundp, set
96 `c-current-comment-prefix' to not break indentation in comments.
97 Hm, I should probably split `c-common-init' from cc-mode into two
98 parts, one of which I could use for antlr-mode.el.
99
100 Changes from 2002-01-31:
101
102 * antlr-mode.el (antlr-font-lock-additional-keywords): Also
103 hightlight `~' with `antlr-font-lock-syntax-face'.
104 Suggested by Helmut Neukirchen <neukirchen@itm.mu-luebeck.de>.
105
12003-01-31 Joe Buehler <jhpb@draco.hekimian.com> 1062003-01-31 Joe Buehler <jhpb@draco.hekimian.com>
2 107
3 * comint.el: 108 * comint.el:
diff --git a/lisp/progmodes/antlr-mode.el b/lisp/progmodes/antlr-mode.el
index b87c7c52b39..1d1fbfab252 100644
--- a/lisp/progmodes/antlr-mode.el
+++ b/lisp/progmodes/antlr-mode.el
@@ -1,11 +1,11 @@
1;;; antlr-mode.el --- major mode for ANTLR grammar files 1;;; antlr-mode.el --- major mode for ANTLR grammar files
2 2
3;; Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. 3;; Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
4;; 4;;
5;; Author: Christoph.Wedler@sap.com 5;; Author: Christoph.Wedler@sap.com
6;; Keywords: languages 6;; Keywords: languages
7;; Version: 2.1 7;; Version: (see `antlr-version' below)
8;; X-URL: http://antlr-mode.sf.net 8;; X-URL: http://antlr-mode.sourceforge.net/
9 9
10;; This file is part of GNU Emacs. 10;; This file is part of GNU Emacs.
11 11
@@ -26,60 +26,22 @@
26 26
27;;; Commentary: 27;;; Commentary:
28 28
29;; This Emacs extension (major mode) provides various features for editing 29;; The Emacs package ANTLR-Mode provides: syntax highlighting for ANTLR grammar
30;; ANTLR grammar files. ANTLR is a tool for LL(k)-based language recognition 30;; files, automatic indentation, menus containing rule/token definitions and
31;; and an excellent alternative to lex & yacc, see <http://www.ANTLR.org>. 31;; supported options and various other things like running ANTLR from within
32;; Some features depend on the value of ANTLR's "language" option (check the 32;; Emacs.
33;; modeline for "Antlr.Java" or "Antlr.C++").
34
35;; This package provides the following features:
36;; * Syntax highlighting for grammar symbols and the code in actions.
37;; * Indentation (pretty-print) for the current line (TAB) and lines in the
38;; selected region (C-M-\). Inserting an ANTLR syntax symbol (one of
39;; ":;|&(){}") might also indent the current line.
40;; * Menu "Index" and Speedbar tags with all class, token and rule
41;; definitions. Jump to corresponding position by selecting an entry.
42;; * Commands to move to previous/next rule, beginning/end of rule body etc.
43;; * Commands to hide/unhide actions.
44;; * Support to insert/change file/grammar/rule/subrule options.
45;; * Run ANTLR from within Emacs, create Makefile dependencies.
46
47;; SYNTAX HIGHLIGHTING comes in three phases. First, comments and strings are
48;; highlighted. Second, the grammar code is highlighted according to
49;; `antlr-font-lock-additional-keywords' (rule refs: dark blue, token refs:
50;; dark orange, definition: bold blue). Third, actions, semantic predicates
51;; and arguments are highlighted according to the usual font-lock keywords of
52;; the major-mode corresponding to ANTLR's "language" option, see also
53;; `antlr-font-lock-maximum-decoration'. We define special font-lock faces for
54;; the grammar code to allow you to distinguish ANTLR keywords from Java/C++
55;; keywords.
56
57;; INDENTATION. This package supports ANTLR's (intended) indentation style
58;; which is based on a simple paren/brace/bracket depth-level calculation, see
59;; `antlr-indent-line'. The indentation engine of cc-mode is only used inside
60;; block comments. By default, this package defines a tab width of 4 to be
61;; consistent to both ANTLR's conventions (TABs usage) and the
62;; `c-indentation-style' "java" which sets `c-basic-offset' to 4, see
63;; `antlr-tab-offset-alist'. You might want to set this variable to nil.
64
65;; OPTION SUPPORT. This package provides special support to insert or change
66;; file, grammar, rule and subrule options via the menu or via the keyboard
67;; with completion. For most options, you can also insert the value with
68;; completion (or select a value from a list by pressing `?'). You get a
69;; warning if an option is not supported by the version of ANTLR you are using
70;; (`antlr-tool-version' defaults to 2.7.1), or if the option shouldn't be
71;; inserted for other reasons. This package knows the correct position where
72;; to insert the option and inserts "options {...}" if it is not already
73;; present. For details, see the docstring of command \\[antlr-insert-option].
74
75;; MAKEFILE CREATION. Command \\[antlr-show-makefile-rules] shows/inserts the
76;; dependencies for all grammar files in the current directory. It considers
77;; ANTLR's "language" option, import/export vocabularies and grammar
78;; inheritance, and provides a value for the -glib option if necessary (which
79;; you have to edit if the super-grammar is not in the same directory).
80
81;; TODO/WISH-LIST. Things which might be supported in future versions:
82 33
34;; For details, check <http://antlr-mode.sourceforge.net/> or, if you prefer
35;; the manual style, follow all commands mentioned in the documentation of
36;; `antlr-mode'. ANTLR is a LL(k)-based recognition tool which generates
37;; lexers, parsers and tree transformers in Java, C++ or Sather and can be
38;; found at <http://www.antlr.org/>.
39
40;; Bug fixes, bug reports, improvements, and suggestions for the newest version
41;; are strongly appreciated.
42
43;; To-do/Wish-list:
44;;
83;; * Next Version [C-c C-w]. Produce HTML document with syntax highlighted 45;; * Next Version [C-c C-w]. Produce HTML document with syntax highlighted
84;; and hyper-links (using htmlize). 46;; and hyper-links (using htmlize).
85;; * Next Version [C-c C-u]. Insert/update special comments: each rule lists 47;; * Next Version [C-c C-u]. Insert/update special comments: each rule lists
@@ -89,7 +51,7 @@
89;; * Planned. Further support for imenu, i.e., include entries for method 51;; * Planned. Further support for imenu, i.e., include entries for method
90;; definitions at beginning of grammar class. 52;; definitions at beginning of grammar class.
91;; * Planned [C-c C-p]. Pack/unpack rule/subrule & options (one/multi-line). 53;; * Planned [C-c C-p]. Pack/unpack rule/subrule & options (one/multi-line).
92 54;;
93;; * Probably. Show rules/dependencies for ANT like for Makefile (does ANT 55;; * Probably. Show rules/dependencies for ANT like for Makefile (does ANT
94;; support vocabularies and grammar inheritance?), I have to look at 56;; support vocabularies and grammar inheritance?), I have to look at
95;; jde-ant.el: http://jakarta.apache.org/ant/manual/OptionalTasks/antlr.html 57;; jde-ant.el: http://jakarta.apache.org/ant/manual/OptionalTasks/antlr.html
@@ -101,10 +63,6 @@
101;; and action code and run special highlighting functions on these regions. 63;; and action code and run special highlighting functions on these regions.
102;; Problems: code size, this mode would depend on font-lock internals. 64;; Problems: code size, this mode would depend on font-lock internals.
103 65
104;; Bug fixes, bug reports, improvements, and suggestions are strongly
105;; appreciated. Please check the newest version first:
106;; http://antlr-mode.sf.net
107
108;;; Installation: 66;;; Installation:
109 67
110;; This file requires Emacs-20.3, XEmacs-20.4 or higher and package cc-mode. 68;; This file requires Emacs-20.3, XEmacs-20.4 or higher and package cc-mode.
@@ -116,10 +74,6 @@
116;; (add-hook 'speedbar-load-hook ; would be too late in antlr-mode.el 74;; (add-hook 'speedbar-load-hook ; would be too late in antlr-mode.el
117;; (lambda () (speedbar-add-supported-extension ".g"))) 75;; (lambda () (speedbar-add-supported-extension ".g")))
118 76
119;; If you edit ANTLR's source files, you might also want to use
120;; (autoload 'antlr-set-tabs "antlr-mode")
121;; (add-hook 'java-mode-hook 'antlr-set-tabs)
122
123;; I strongly recommend to use font-lock with a support mode like fast-lock, 77;; I strongly recommend to use font-lock with a support mode like fast-lock,
124;; lazy-lock or better jit-lock (Emacs-21.1+) / lazy-shot (XEmacs). 78;; lazy-lock or better jit-lock (Emacs-21.1+) / lazy-shot (XEmacs).
125 79
@@ -128,48 +82,103 @@
128;;; Code: 82;;; Code:
129 83
130(provide 'antlr-mode) 84(provide 'antlr-mode)
85(require 'easymenu)
86
87;; General Emacs/XEmacs-compatibility compile-time macros
88(eval-when-compile
89 (require 'cl)
90 (defmacro cond-emacs-xemacs (&rest args)
91 (cond-emacs-xemacs-macfn
92 args "`cond-emacs-xemacs' must return exactly one element"))
93 (defun cond-emacs-xemacs-macfn (args &optional msg)
94 (if (atom args) args
95 (and (eq (car args) :@) (null msg) ; (:@ ...spliced...)
96 (setq args (cdr args)
97 msg "(:@ ....) must return exactly one element"))
98 (let ((ignore (if (string-match "XEmacs" emacs-version) :EMACS :XEMACS))
99 (mode :BOTH) code)
100 (while (consp args)
101 (if (memq (car args) '(:EMACS :XEMACS :BOTH)) (setq mode (pop args)))
102 (if (atom args)
103 (or args (error "Used selector %s without elements" mode))
104 (or (eq ignore mode)
105 (push (cond-emacs-xemacs-macfn (car args)) code))
106 (pop args)))
107 (cond (msg (if (or args (cdr code)) (error msg) (car code)))
108 ((or (null args) (eq ignore mode)) (nreverse code))
109 (t (nconc (nreverse code) args))))))
110 ;; Emacs/XEmacs-compatibility `defun': remove interactive "_" for Emacs, use
111 ;; existing functions when they are `fboundp', provide shortcuts if they are
112 ;; known to be defined in a specific Emacs branch (for short .elc)
113 (defmacro defunx (name arglist &rest definition)
114 (let ((xemacsp (string-match "XEmacs" emacs-version)) reuses)
115 (while (memq (car definition)
116 '(:try :emacs-and-try :xemacs-and-try))
117 (if (eq (pop definition) (if xemacsp :xemacs-and-try :emacs-and-try))
118 (setq reuses (car definition)
119 definition nil)
120 (push (pop definition) reuses)))
121 (if (and reuses (symbolp reuses))
122 `(defalias ',name ',reuses)
123 (let* ((docstring (if (stringp (car definition)) (pop definition)))
124 (spec (and (not xemacsp)
125 (eq (car-safe (car definition)) 'interactive)
126 (null (cddar definition))
127 (cadar definition))))
128 (if (and (stringp spec)
129 (not (string-equal spec ""))
130 (eq (aref spec 0) ?_))
131 (setq definition
132 (cons (if (string-equal spec "_")
133 '(interactive)
134 `(interactive ,(substring spec 1)))
135 (cdr definition))))
136 (if (null reuses)
137 `(defun ,name ,arglist ,docstring
138 ,@(cond-emacs-xemacs-macfn definition))
139 ;; no dynamic docstring in this case
140 `(eval-and-compile ; no warnings in Emacs
141 (defalias ',name
142 (cond ,@(mapcar (lambda (func) `((fboundp ',func) ',func))
143 (nreverse reuses))
144 (t ,(if definition
145 `(lambda ,arglist ,docstring
146 ,@(cond-emacs-xemacs-macfn definition))
147 'ignore))))))))))
148 (defmacro ignore-errors-x (&rest body)
149 (let ((specials '((scan-sexps . 4) (scan-lists . 5)))
150 spec nils)
151 (if (and (string-match "XEmacs" emacs-version)
152 (null (cdr body)) (consp (car body))
153 (setq spec (assq (caar body) specials))
154 (>= (setq nils (- (cdr spec) (length (car body)))) 0))
155 `(,@(car body) ,@(make-list nils nil) t)
156 `(ignore-errors ,@body)))))
157
158;; More compile-time-macros
159(eval-when-compile
160 (defmacro save-buffer-state-x (&rest body) ; similar to EMACS/lazy-lock.el
161 (let ((modified (gensym "save-buffer-state-x-modified-")))
162 `(let ((,modified (buffer-modified-p)))
163 (unwind-protect
164 (let ((buffer-undo-list t) (inhibit-read-only t)
165 ,@(unless (string-match "XEmacs" emacs-version)
166 '((inhibit-point-motion-hooks t) deactivate-mark))
167 before-change-functions after-change-functions
168 buffer-file-name buffer-file-truename)
169 ,@body)
170 (and (not ,modified) (buffer-modified-p)
171 (set-buffer-modified-p nil)))))))
172(put 'save-buffer-state-x 'lisp-indent-function 0)
173
174;; get rid of byte-compile warnings
131(eval-when-compile ; required and optional libraries 175(eval-when-compile ; required and optional libraries
132 (require 'cc-mode) 176 (ignore-errors (require 'cc-mode))
133 (defvar c-Java-access-key) ; former cc-mode variable 177 (ignore-errors (require 'font-lock))
134 (condition-case nil (require 'font-lock) (error nil)) 178 (ignore-errors (require 'compile))
135 (condition-case nil (require 'compile) (error nil))
136 (defvar outline-level) (defvar imenu-use-markers) 179 (defvar outline-level) (defvar imenu-use-markers)
137 (defvar imenu-create-index-function)) 180 (defvar imenu-create-index-function)
138(eval-when-compile ; Emacs: cl, easymenu, XEmacs vars 181 (ignore-errors (defun c-init-language-vars)))
139 (require 'cl)
140 (require 'easymenu)
141 (defvar zmacs-region-stays))
142(eval-when-compile ; XEmacs: Emacs vars
143 (defvar inhibit-point-motion-hooks) (defvar deactivate-mark))
144
145(eval-and-compile ; XEmacs functions, simplified
146 (if (featurep 'xemacs)
147 (defalias 'antlr-scan-sexps 'scan-sexps)
148 (defalias 'antlr-scan-sexps 'antlr-scan-sexps-internal))
149 (if (featurep 'xemacs)
150 (defalias 'antlr-scan-lists 'scan-lists)
151 (defalias 'antlr-scan-lists 'antlr-scan-lists-internal))
152 (if (fboundp 'default-directory)
153 (defalias 'antlr-default-directory 'default-directory)
154 (defun antlr-default-directory () default-directory))
155 (if (fboundp 'read-shell-command)
156 (defalias 'antlr-read-shell-command 'read-shell-command)
157 (defun antlr-read-shell-command (prompt &optional initial-input history)
158 (read-from-minibuffer prompt initial-input nil nil
159 (or history 'shell-command-history))))
160 (if (fboundp 'with-displaying-help-buffer)
161 (defalias 'antlr-with-displaying-help-buffer 'with-displaying-help-buffer)
162 (defun antlr-with-displaying-help-buffer (thunk &optional name)
163 (with-output-to-temp-buffer "*Help*"
164 (save-excursion (funcall thunk)))))
165 (if (and (fboundp 'buffer-syntactic-context)
166 (fboundp 'buffer-syntactic-context-depth))
167 (progn
168 (defalias 'antlr-invalidate-context-cache 'antlr-xemacs-bug-workaround)
169 (defalias 'antlr-syntactic-context 'antlr-fast-syntactic-context))
170 (defalias 'antlr-invalidate-context-cache 'ignore)
171 (defalias 'antlr-syntactic-context 'antlr-slow-syntactic-context)))
172
173 182
174 183
175;;;;########################################################################## 184;;;;##########################################################################
@@ -181,11 +190,12 @@
181 "Major mode for ANTLR grammar files." 190 "Major mode for ANTLR grammar files."
182 :group 'languages 191 :group 'languages
183 :link '(emacs-commentary-link "antlr-mode.el") 192 :link '(emacs-commentary-link "antlr-mode.el")
184 :link '(url-link "http://antlr-mode.sf.net") 193 :link '(url-link "http://antlr-mode.sourceforge.net/")
185 :prefix "antlr-") 194 :prefix "antlr-")
186 195
187(defconst antlr-version "2.1" 196(defconst antlr-version "2.2b"
188 "ANTLR major mode version number.") 197 "ANTLR major mode version number.
198Check <http://antlr-mode.sourceforge.net/> for the newest.")
189 199
190 200
191;;;=========================================================================== 201;;;===========================================================================
@@ -272,12 +282,13 @@ ANTLR's and Java's indentation styles. Used by `antlr-set-tabs'."
272 282
273(defcustom antlr-indent-style "java" 283(defcustom antlr-indent-style "java"
274 "*If non-nil, cc-mode indentation style used for `antlr-mode'. 284 "*If non-nil, cc-mode indentation style used for `antlr-mode'.
275See `c-set-style' for details." 285See `c-set-style' and for details, where the most interesting part in
286`c-style-alist' is the value of `c-basic-offset'."
276 :group 'antlr 287 :group 'antlr
277 :type '(choice (const nil) regexp)) 288 :type '(choice (const nil) regexp))
278 289
279(defcustom antlr-indent-item-regexp 290(defcustom antlr-indent-item-regexp
280 "[]}):;|&]\\|default[ \t]*:\\|case[ \t]+\\('\\\\?.'\\|[0-9]+\\|[A-Za-z_][A-Za-z_0-9]*\\)[ \t]*:" ; & is local ANTLR extension (SGML's and-connector) 291 "[]}):;|&]" ; & is local ANTLR extension (SGML's and-connector)
281 "Regexp matching lines which should be indented by one TAB less. 292 "Regexp matching lines which should be indented by one TAB less.
282See `antlr-indent-line' and command \\[antlr-indent-command]." 293See `antlr-indent-line' and command \\[antlr-indent-command]."
283 :group 'antlr 294 :group 'antlr
@@ -285,17 +296,28 @@ See `antlr-indent-line' and command \\[antlr-indent-command]."
285 296
286(defcustom antlr-indent-at-bol-alist 297(defcustom antlr-indent-at-bol-alist
287 ;; eval-when-compile not usable with defcustom... 298 ;; eval-when-compile not usable with defcustom...
288 '((c++-mode . "#\\(assert\\|cpu\\|define\\|endif\\|el\\(if\\|se\\)\\|i\\(dent\\|f\\(def\\|ndef\\)?\\|mport\\|nclude\\(_next\\)?\\)\\|line\\|machine\\|pragma\\|system\\|un\\(assert\\|def\\)\\|warning\\)\\>")) 299 '((java-mode . "\\(package\\|import\\)\\>")
300 (c++-mode . "#\\(assert\\|cpu\\|define\\|endif\\|el\\(if\\|se\\)\\|i\\(dent\\|f\\(def\\|ndef\\)?\\|mport\\|nclude\\(_next\\)?\\)\\|line\\|machine\\|pragma\\|system\\|un\\(assert\\|def\\)\\|warning\\)\\>"))
289 "Alist of regexps matching lines are indented at column 0. 301 "Alist of regexps matching lines are indented at column 0.
290Each element in this list looks like (MODE . REGEXP) where MODE is a 302Each element in this list looks like (MODE . REGEXP) where MODE is a
291function and REGEXP is a regular expression. 303function and REGEXP is a regular expression.
292 304
293If `antlr-language' equals to a MODE and the line starting at the first 305If `antlr-language' equals to a MODE, the line starting at the first
294non-whitespace is matched by the corresponding REGEXP, indent the line 306non-whitespace is matched by the corresponding REGEXP, and the line is
295at column 0 instead according to the normal rules of `antlr-indent-line'." 307part of an header action, indent the line at column 0 instead according
308to the normal rules of `antlr-indent-line'."
296 :group 'antlr 309 :group 'antlr
297 :type '(repeat (cons (function :tag "Major mode") regexp))) 310 :type '(repeat (cons (function :tag "Major mode") regexp)))
298 311
312;; adopt indentation to cc-engine
313(defvar antlr-disabling-cc-syntactic-symbols
314 '(statement-block-intro
315 defun-block-intro topmost-intro statement-case-intro member-init-intro
316 arglist-intro brace-list-intro knr-argdecl-intro inher-intro
317 objc-method-intro
318 block-close defun-close class-close brace-list-close arglist-close
319 inline-close extern-lang-close namespace-close))
320
299 321
300;;;=========================================================================== 322;;;===========================================================================
301;;; Options: customization 323;;; Options: customization
@@ -647,7 +669,7 @@ DIRECTORY is the name of the current directory.")
647;;; Menu 669;;; Menu
648;;;=========================================================================== 670;;;===========================================================================
649 671
650(defcustom antlr-imenu-name t 672(defcustom antlr-imenu-name t ; (featurep 'xemacs) ; TODO: Emacs-21 bug?
651 "*Non-nil, if a \"Index\" menu should be added to the menubar. 673 "*Non-nil, if a \"Index\" menu should be added to the menubar.
652If it is a string, it is used instead \"Index\". Requires package 674If it is a string, it is used instead \"Index\". Requires package
653imenu." 675imenu."
@@ -687,9 +709,10 @@ imenu."
687(easy-menu-define antlr-mode-menu antlr-mode-map 709(easy-menu-define antlr-mode-menu antlr-mode-map
688 "Major mode menu." 710 "Major mode menu."
689 `("Antlr" 711 `("Antlr"
690 ,@(if (and antlr-options-use-submenus 712 ,@(if (cond-emacs-xemacs
691 (boundp 'emacs-major-version) 713 :EMACS (and antlr-options-use-submenus
692 (or (featurep 'xemacs) (>= emacs-major-version 21))) 714 (>= emacs-major-version 21))
715 :XEMACS antlr-options-use-submenus)
693 `(("Insert File Option" 716 `(("Insert File Option"
694 :filter ,(lambda (x) (antlr-options-menu-filter 1 x))) 717 :filter ,(lambda (x) (antlr-options-menu-filter 1 x)))
695 ("Insert Grammar Option" 718 ("Insert Grammar Option"
@@ -797,25 +820,33 @@ Do not change."
797 820
798(defvar antlr-font-lock-keyword-face 'antlr-font-lock-keyword-face) 821(defvar antlr-font-lock-keyword-face 'antlr-font-lock-keyword-face)
799(defface antlr-font-lock-keyword-face 822(defface antlr-font-lock-keyword-face
800 '((((class color) (background light)) (:foreground "black" :weight bold))) 823 (cond-emacs-xemacs
824 '((((class color) (background light))
825 (:foreground "black" :EMACS :weight bold :XEMACS :bold t))))
801 "ANTLR keywords." 826 "ANTLR keywords."
802 :group 'antlr) 827 :group 'antlr)
803 828
804(defvar antlr-font-lock-syntax-face 'antlr-font-lock-keyword-face) 829(defvar antlr-font-lock-syntax-face 'antlr-font-lock-keyword-face)
805(defface antlr-font-lock-syntax-face 830(defface antlr-font-lock-syntax-face
806 '((((class color) (background light)) (:foreground "black" :weight bold))) 831 (cond-emacs-xemacs
832 '((((class color) (background light))
833 (:foreground "black" :EMACS :weight bold :XEMACS :bold t))))
807 "ANTLR syntax symbols like :, |, (, ), ...." 834 "ANTLR syntax symbols like :, |, (, ), ...."
808 :group 'antlr) 835 :group 'antlr)
809 836
810(defvar antlr-font-lock-ruledef-face 'antlr-font-lock-ruledef-face) 837(defvar antlr-font-lock-ruledef-face 'antlr-font-lock-ruledef-face)
811(defface antlr-font-lock-ruledef-face 838(defface antlr-font-lock-ruledef-face
812 '((((class color) (background light)) (:foreground "blue" :weight bold))) 839 (cond-emacs-xemacs
840 '((((class color) (background light))
841 (:foreground "blue" :EMACS :weight bold :XEMACS :bold t))))
813 "ANTLR rule references (definition)." 842 "ANTLR rule references (definition)."
814 :group 'antlr) 843 :group 'antlr)
815 844
816(defvar antlr-font-lock-tokendef-face 'antlr-font-lock-tokendef-face) 845(defvar antlr-font-lock-tokendef-face 'antlr-font-lock-tokendef-face)
817(defface antlr-font-lock-tokendef-face 846(defface antlr-font-lock-tokendef-face
818 '((((class color) (background light)) (:foreground "blue" :weight bold))) 847 (cond-emacs-xemacs
848 '((((class color) (background light))
849 (:foreground "blue" :EMACS :weight bold :XEMACS :bold t))))
819 "ANTLR token references (definition)." 850 "ANTLR token references (definition)."
820 :group 'antlr) 851 :group 'antlr)
821 852
@@ -833,7 +864,9 @@ Do not change."
833 864
834(defvar antlr-font-lock-literal-face 'antlr-font-lock-literal-face) 865(defvar antlr-font-lock-literal-face 'antlr-font-lock-literal-face)
835(defface antlr-font-lock-literal-face 866(defface antlr-font-lock-literal-face
836 '((((class color) (background light)) (:foreground "brown4" :weight bold))) 867 (cond-emacs-xemacs
868 '((((class color) (background light))
869 (:foreground "brown4" :EMACS :weight bold :XEMACS :bold t))))
837 "ANTLR special literal tokens. 870 "ANTLR special literal tokens.
838It is used to highlight strings matched by the first regexp group of 871It is used to highlight strings matched by the first regexp group of
839`antlr-font-lock-literal-regexp'." 872`antlr-font-lock-literal-regexp'."
@@ -853,47 +886,48 @@ group. The string matched by the first group is highlighted with
853 "Regexp matching class headers.") 886 "Regexp matching class headers.")
854 887
855(defvar antlr-font-lock-additional-keywords 888(defvar antlr-font-lock-additional-keywords
856 `((antlr-invalidate-context-cache) 889 (cond-emacs-xemacs
857 ("\\$setType[ \t]*(\\([A-Za-z\300-\326\330-\337]\\sw*\\))" 890 `((antlr-invalidate-context-cache)
858 (1 antlr-font-lock-tokendef-face)) 891 ("\\$setType[ \t]*(\\([A-Za-z\300-\326\330-\337]\\sw*\\))"
859 ("\\$\\sw+" (0 font-lock-keyword-face)) 892 (1 antlr-font-lock-tokendef-face))
860 ;; the tokens are already fontified as string/docstrings: 893 ("\\$\\sw+" (0 font-lock-keyword-face))
861 (,(lambda (limit) 894 ;; the tokens are already fontified as string/docstrings:
862 (if antlr-font-lock-literal-regexp 895 (,(lambda (limit)
863 (antlr-re-search-forward antlr-font-lock-literal-regexp limit))) 896 (if antlr-font-lock-literal-regexp
864 (1 antlr-font-lock-literal-face t) 897 (antlr-re-search-forward antlr-font-lock-literal-regexp limit)))
865 ,@(and (featurep 'xemacs) '((0 nil)))) ; XEmacs bug workaround 898 (1 antlr-font-lock-literal-face t)
866 (,(lambda (limit) 899 :XEMACS (0 nil)) ; XEmacs bug workaround
867 (antlr-re-search-forward antlr-class-header-regexp limit)) 900 (,(lambda (limit)
868 (1 antlr-font-lock-keyword-face) 901 (antlr-re-search-forward antlr-class-header-regexp limit))
869 (2 antlr-font-lock-ruledef-face) 902 (1 antlr-font-lock-keyword-face)
870 (3 antlr-font-lock-keyword-face) 903 (2 antlr-font-lock-ruledef-face)
871 (4 (if (member (match-string 4) '("Lexer" "Parser" "TreeParser")) 904 (3 antlr-font-lock-keyword-face)
872 'antlr-font-lock-keyword-face 905 (4 (if (member (match-string 4) '("Lexer" "Parser" "TreeParser"))
873 'font-lock-type-face))) 906 'antlr-font-lock-keyword-face
874 (,(lambda (limit) 907 'font-lock-type-face)))
875 (antlr-re-search-forward 908 (,(lambda (limit)
876 "\\<\\(header\\|options\\|tokens\\|exception\\|catch\\|returns\\)\\>" 909 (antlr-re-search-forward
877 limit)) 910 "\\<\\(header\\|options\\|tokens\\|exception\\|catch\\|returns\\)\\>"
911 limit))
878 (1 antlr-font-lock-keyword-face)) 912 (1 antlr-font-lock-keyword-face))
879 (,(lambda (limit) 913 (,(lambda (limit)
880 (antlr-re-search-forward 914 (antlr-re-search-forward
881 "^\\(private\\|public\\|protected\\)\\>[ \t]*\\(\\(\\sw+[ \t]*\\(:\\)?\\)\\)?" 915 "^\\(private\\|public\\|protected\\)\\>[ \t]*\\(\\(\\sw+[ \t]*\\(:\\)?\\)\\)?"
882 limit)) 916 limit))
883 (1 font-lock-type-face) ; not XEmacs' java level-3 fruit salad 917 (1 font-lock-type-face) ; not XEmacs' java level-3 fruit salad
884 (3 (if (antlr-upcase-p (char-after (match-beginning 3))) 918 (3 (if (antlr-upcase-p (char-after (match-beginning 3)))
885 'antlr-font-lock-tokendef-face 919 'antlr-font-lock-tokendef-face
886 'antlr-font-lock-ruledef-face) nil t) 920 'antlr-font-lock-ruledef-face) nil t)
887 (4 antlr-font-lock-syntax-face nil t)) 921 (4 antlr-font-lock-syntax-face nil t))
888 (,(lambda (limit) 922 (,(lambda (limit)
889 (antlr-re-search-forward "^\\(\\sw+\\)[ \t]*\\(:\\)?" limit)) 923 (antlr-re-search-forward "^\\(\\sw+\\)[ \t]*\\(:\\)?" limit))
890 (1 (if (antlr-upcase-p (char-after (match-beginning 0))) 924 (1 (if (antlr-upcase-p (char-after (match-beginning 0)))
891 'antlr-font-lock-tokendef-face 925 'antlr-font-lock-tokendef-face
892 'antlr-font-lock-ruledef-face) nil t) 926 'antlr-font-lock-ruledef-face) nil t)
893 (2 antlr-font-lock-syntax-face nil t)) 927 (2 antlr-font-lock-syntax-face nil t))
894 (,(lambda (limit) 928 (,(lambda (limit)
895 ;; v:ruleref and v:"literal" is allowed... 929 ;; v:ruleref and v:"literal" is allowed...
896 (antlr-re-search-forward "\\(\\sw+\\)[ \t]*\\([=:]\\)?" limit)) 930 (antlr-re-search-forward "\\(\\sw+\\)[ \t]*\\([=:]\\)?" limit))
897 (1 (if (match-beginning 2) 931 (1 (if (match-beginning 2)
898 (if (eq (char-after (match-beginning 2)) ?=) 932 (if (eq (char-after (match-beginning 2)) ?=)
899 'antlr-font-lock-default-face 933 'antlr-font-lock-default-face
@@ -902,9 +936,9 @@ group. The string matched by the first group is highlighted with
902 'antlr-font-lock-tokenref-face 936 'antlr-font-lock-tokenref-face
903 'antlr-font-lock-ruleref-face))) 937 'antlr-font-lock-ruleref-face)))
904 (2 antlr-font-lock-default-face nil t)) 938 (2 antlr-font-lock-default-face nil t))
905 (,(lambda (limit) 939 (,(lambda (limit)
906 (antlr-re-search-forward "[|&:;(]\\|)\\([*+?]\\|=>\\)?" limit)) 940 (antlr-re-search-forward "[|&:;(~]\\|)\\([*+?]\\|=>\\)?" limit))
907 (0 'antlr-font-lock-syntax-face))) 941 (0 'antlr-font-lock-syntax-face))))
908 "Font-lock keywords for ANTLR's normal grammar code. 942 "Font-lock keywords for ANTLR's normal grammar code.
909See `antlr-font-lock-keywords-alist' for the keywords of actions.") 943See `antlr-font-lock-keywords-alist' for the keywords of actions.")
910 944
@@ -939,6 +973,16 @@ not to confuse their context_cache.")
939 "Abbreviation table used in `antlr-mode' buffers.") 973 "Abbreviation table used in `antlr-mode' buffers.")
940(define-abbrev-table 'antlr-mode-abbrev-table ()) 974(define-abbrev-table 'antlr-mode-abbrev-table ())
941 975
976(defvar antlr-slow-cache-enabling-symbol 'loudly
977;; Emacs' font-lock changes buffer's tick counter, therefore this value should
978;; be a parameter of a font-lock function, but not any other variable of
979;; functions which call `antlr-slow-syntactic-context'.
980 "If value is a bound symbol, cache will be used even with text changes.
981This is no user option. Used for `antlr-slow-syntactic-context'.")
982
983(defvar antlr-slow-cache-diff-threshold 5000
984 "Maximum distance between `point' and cache position for cache use.
985Used for `antlr-slow-syntactic-context'.")
942 986
943 987
944;;;;########################################################################## 988;;;;##########################################################################
@@ -948,7 +992,7 @@ not to confuse their context_cache.")
948 992
949 993
950;;;=========================================================================== 994;;;===========================================================================
951;;; Syntax functions -- Emacs vs XEmacs dependent 995;;; Syntax functions -- Emacs vs XEmacs dependent, part 1
952;;;=========================================================================== 996;;;===========================================================================
953 997
954;; From help.el (XEmacs-21.1), without `copy-syntax-table' 998;; From help.el (XEmacs-21.1), without `copy-syntax-table'
@@ -961,62 +1005,140 @@ not to confuse their context_cache.")
961(put 'antlr-with-syntax-table 'lisp-indent-function 1) 1005(put 'antlr-with-syntax-table 'lisp-indent-function 1)
962(put 'antlr-with-syntax-table 'edebug-form-spec '(form body)) 1006(put 'antlr-with-syntax-table 'edebug-form-spec '(form body))
963 1007
964(defun antlr-scan-sexps-internal (from count &optional dummy no-error) 1008(defunx antlr-default-directory ()
965;; checkdoc-params: (from count dummy) 1009 :xemacs-and-try default-directory
966 "Like `scan-sexps' but with additional arguments. 1010 "Return `default-directory'."
967When optional arg NO-ERROR is non-nil, `antlr-scan-sexps-internal' will 1011 default-directory)
968return nil instead of signaling an error." 1012
969 (if no-error 1013;; Check Emacs-21.1 simple.el, `shell-command'.
970 (condition-case nil 1014(defunx antlr-read-shell-command (prompt &optional initial-input history)
971 (scan-sexps from count) 1015 :xemacs-and-try read-shell-command
972 (error nil)) 1016 "Read a string from the minibuffer, using `shell-command-history'."
973 (scan-sexps from count))) 1017 (read-from-minibuffer prompt initial-input nil nil
974 1018 (or history 'shell-command-history)))
975(defun antlr-scan-lists-internal (from count depth &optional dummy no-error) 1019
976;; checkdoc-params: (from count depth dummy) 1020(defunx antlr-with-displaying-help-buffer (thunk &optional name)
977 "Like `scan-lists' but with additional arguments. 1021 :xemacs-and-try with-displaying-help-buffer
978When optional arg NO-ERROR is non-nil, `antlr-scan-lists-internal' will 1022 "Make a help buffer and call `thunk' there."
979return nil instead of signaling an error." 1023 (with-output-to-temp-buffer "*Help*"
980 (if no-error 1024 (save-excursion (funcall thunk))))
981 (condition-case nil 1025
982 (scan-lists from count depth) 1026
983 (error nil)) 1027;;;===========================================================================
984 (scan-lists from count depth))) 1028;;; Context cache
985 1029;;;===========================================================================
986(defun antlr-xemacs-bug-workaround (&rest dummies) 1030
1031(defvar antlr-slow-context-cache nil "Internal.")
1032
1033;;;(defvar antlr-statistics-full-neg 0)
1034;;;(defvar antlr-statistics-full-diff 0)
1035;;;(defvar antlr-statistics-full-other 0)
1036;;;(defvar antlr-statistics-cache 0)
1037;;;(defvar antlr-statistics-inval 0)
1038
1039(defunx antlr-invalidate-context-cache (&rest dummies)
987;; checkdoc-params: (dummies) 1040;; checkdoc-params: (dummies)
988 "Invalidate context_cache for syntactical context information." 1041 "Invalidate context cache for syntactical context information."
989 ;; XEmacs bug workaround 1042 :XEMACS ; XEmacs bug workaround
990 (save-excursion 1043 (save-excursion
991 (set-buffer (get-buffer-create " ANTLR XEmacs bug workaround")) 1044 (set-buffer (get-buffer-create " ANTLR XEmacs bug workaround"))
992 (buffer-syntactic-context-depth)) 1045 (buffer-syntactic-context-depth)
993 nil) 1046 nil)
1047 :EMACS
1048;;; (incf antlr-statistics-inval)
1049 (setq antlr-slow-context-cache nil))
994 1050
995(defun antlr-fast-syntactic-context () 1051(defunx antlr-syntactic-context ()
996 "Return some syntactic context information. 1052 "Return some syntactic context information.
997Return `string' if point is within a string, `block-comment' or 1053Return `string' if point is within a string, `block-comment' or
998`comment' is point is within a comment or the depth within all 1054`comment' is point is within a comment or the depth within all
999parenthesis-syntax delimiters at point otherwise. 1055parenthesis-syntax delimiters at point otherwise.
1000WARNING: this may alter `match-data'." 1056WARNING: this may alter `match-data'."
1001 (or (buffer-syntactic-context) (buffer-syntactic-context-depth))) 1057 :XEMACS
1002 1058 (or (buffer-syntactic-context) (buffer-syntactic-context-depth))
1003(defun antlr-slow-syntactic-context () 1059 :EMACS
1004 "Return some syntactic context information. 1060 (let ((orig (point)) diff state
1005Return `string' if point is within a string, `block-comment' or 1061 ;; Arg, Emacs' (buffer-modified-tick) changes with font-lock. Use
1006`comment' is point is within a comment or the depth within all 1062 ;; hack that `loudly' is bound during font-locking => cache use will
1007parenthesis-syntax delimiters at point otherwise. 1063 ;; increase from 7% to 99.99% during font-locking.
1008WARNING: this may alter `match-data'." 1064 (tick (or (boundp antlr-slow-cache-enabling-symbol)
1009 (let ((orig (point))) 1065 (buffer-modified-tick))))
1010 (beginning-of-defun) 1066 (if (and (cdr antlr-slow-context-cache)
1011 (let ((state (parse-partial-sexp (point) orig))) 1067 (>= (setq diff (- orig (cadr antlr-slow-context-cache))) 0)
1012 (goto-char orig) 1068 (< diff antlr-slow-cache-diff-threshold)
1013 (cond ((nth 3 state) 'string) 1069 (eq (current-buffer) (caar antlr-slow-context-cache))
1014 ((nth 4 state) 'comment) ; block-comment? -- we don't care 1070 (eq tick (cdar antlr-slow-context-cache)))
1015 (t (car state)))))) 1071 ;; (setq antlr-statistics-cache (1+ antlr-statistics-cache) ...)
1072 (setq state (parse-partial-sexp (cadr antlr-slow-context-cache) orig
1073 nil nil
1074 (cddr antlr-slow-context-cache)))
1075 (if (>= orig antlr-slow-cache-diff-threshold)
1076 (beginning-of-defun)
1077 (goto-char (point-min)))
1078;;; (cond ((and diff (< diff 0)) (incf antlr-statistics-full-neg))
1079;;; ((and diff (>= diff 3000)) (incf antlr-statistics-full-diff))
1080;;; (t (incf antlr-statistics-full-other)))
1081 (setq state (parse-partial-sexp (point) orig)))
1082 (goto-char orig)
1083 (if antlr-slow-context-cache
1084 (setcdr antlr-slow-context-cache (cons orig state))
1085 (setq antlr-slow-context-cache
1086 (cons (cons (current-buffer) tick)
1087 (cons orig state))))
1088 (cond ((nth 3 state) 'string)
1089 ((nth 4 state) 'comment) ; block-comment? -- we don't care
1090 (t (car state)))))
1091
1092;;; (incf (aref antlr-statistics 2))
1093;;; (unless (and (eq (current-buffer)
1094;;; (caar antlr-slow-context-cache))
1095;;; (eq (buffer-modified-tick)
1096;;; (cdar antlr-slow-context-cache)))
1097;;; (incf (aref antlr-statistics 1))
1098;;; (setq antlr-slow-context-cache nil))
1099;;; (let* ((orig (point))
1100;;; (base (cadr antlr-slow-context-cache))
1101;;; (curr (cddr antlr-slow-context-cache))
1102;;; (state (cond ((eq orig (car curr)) (cdr curr))
1103;;; ((eq orig (car base)) (cdr base))))
1104;;; diff diff2)
1105;;; (unless state
1106;;; (incf (aref antlr-statistics 3))
1107;;; (when curr
1108;;; (if (< (setq diff (abs (- orig (car curr))))
1109;;; (setq diff2 (abs (- orig (car base)))))
1110;;; (setq state curr)
1111;;; (setq state base
1112;;; diff diff2))
1113;;; (if (or (>= (1+ diff) (point)) (>= diff 3000))
1114;;; (setq state nil))) ; start from bod/bob
1115;;; (if state
1116;;; (setq state
1117;;; (parse-partial-sexp (car state) orig nil nil (cdr state)))
1118;;; (if (>= orig 3000) (beginning-of-defun) (goto-char (point-min)))
1119;;; (incf (aref antlr-statistics 4))
1120;;; (setq cw (list orig (point) base curr))
1121;;; (setq state (parse-partial-sexp (point) orig)))
1122;;; (goto-char orig)
1123;;; (if antlr-slow-context-cache
1124;;; (setcdr (cdr antlr-slow-context-cache) (cons orig state))
1125;;; (setq antlr-slow-context-cache
1126;;; (cons (cons (current-buffer) (buffer-modified-tick))
1127;;; (cons (cons orig state) (cons orig state))))))
1128;;; (cond ((nth 3 state) 'string)
1129;;; ((nth 4 state) 'comment) ; block-comment? -- we don't care
1130;;; (t (car state)))))
1131
1132;;; (beginning-of-defun)
1133;;; (let ((state (parse-partial-sexp (point) orig)))
1134;;; (goto-char orig)
1135;;; (cond ((nth 3 state) 'string)
1136;;; ((nth 4 state) 'comment) ; block-comment? -- we don't care
1137;;; (t (car state))))))
1016 1138
1017 1139
1018;;;=========================================================================== 1140;;;===========================================================================
1019;;; Misc functions 1141;;; Miscellaneous functions
1020;;;=========================================================================== 1142;;;===========================================================================
1021 1143
1022(defun antlr-upcase-p (char) 1144(defun antlr-upcase-p (char)
@@ -1066,7 +1188,7 @@ strings and actions/semantic predicates."
1066(defsubst antlr-skip-sexps (count) 1188(defsubst antlr-skip-sexps (count)
1067 "Skip the next COUNT balanced expressions and the comments after it. 1189 "Skip the next COUNT balanced expressions and the comments after it.
1068Return position before the comments after the last expression." 1190Return position before the comments after the last expression."
1069 (goto-char (or (antlr-scan-sexps (point) count nil t) (point-max))) 1191 (goto-char (or (ignore-errors-x (scan-sexps (point) count)) (point-max)))
1070 (prog1 (point) 1192 (prog1 (point)
1071 (c-forward-syntactic-ws))) 1193 (c-forward-syntactic-ws)))
1072 1194
@@ -1104,19 +1226,15 @@ See `antlr-font-lock-additional-keywords', `antlr-language' and
1104IF TOKENREFS-ONLY is non-nil, just return alist with tokenref names." 1226IF TOKENREFS-ONLY is non-nil, just return alist with tokenref names."
1105 (let ((items nil) 1227 (let ((items nil)
1106 (classes nil) 1228 (classes nil)
1107 (semi (point-max))) 1229 (continue t))
1108 ;; Using `imenu-progress-message' would require imenu for compilation -- 1230 ;; Using `imenu-progress-message' would require imenu for compilation, but
1109 ;; nobody is missing these messages... 1231 ;; nobody is missing these messages. The generic imenu function searches
1232 ;; backward, which is slower and more likely not to work during editing.
1110 (antlr-with-syntax-table antlr-action-syntax-table 1233 (antlr-with-syntax-table antlr-action-syntax-table
1111 ;; We stick to the imenu standard and search backwards, although I don't 1234 (antlr-invalidate-context-cache)
1112 ;; think this is right. It is slower and more likely not to work during 1235 (goto-char (point-min))
1113 ;; editing (you are more likely to add functions to the end of the file). 1236 (antlr-skip-file-prelude t)
1114 (while semi 1237 (while continue
1115 (goto-char semi)
1116 (setq semi (antlr-search-backward ";"))
1117 (if semi
1118 (progn (forward-char) (antlr-skip-exception-part t))
1119 (antlr-skip-file-prelude t))
1120 (if (looking-at "{") (antlr-skip-sexps 1)) 1238 (if (looking-at "{") (antlr-skip-sexps 1))
1121 (if (looking-at antlr-class-header-regexp) 1239 (if (looking-at antlr-class-header-regexp)
1122 (or tokenrefs-only 1240 (or tokenrefs-only
@@ -1135,8 +1253,12 @@ IF TOKENREFS-ONLY is non-nil, just return alist with tokenref names."
1135 (if imenu-use-markers 1253 (if imenu-use-markers
1136 (copy-marker (match-beginning 0)) 1254 (copy-marker (match-beginning 0))
1137 (match-beginning 0))) 1255 (match-beginning 0)))
1138 items)))))) 1256 items))))
1139 (if classes (cons (cons "Classes" classes) items) items))) 1257 (if (setq continue (antlr-search-forward ";"))
1258 (antlr-skip-exception-part t))))
1259 (if classes
1260 (cons (cons "Classes" (nreverse classes)) (nreverse items))
1261 (nreverse items))))
1140 1262
1141 1263
1142;;;=========================================================================== 1264;;;===========================================================================
@@ -1255,35 +1377,33 @@ rule."
1255 (antlr-with-syntax-table antlr-action-syntax-table 1377 (antlr-with-syntax-table antlr-action-syntax-table
1256 (not (antlr-outside-rule-p))))) 1378 (not (antlr-outside-rule-p)))))
1257 1379
1258(defun antlr-end-of-rule (&optional arg) 1380(defunx antlr-end-of-rule (&optional arg)
1259 "Move forward to next end of rule. Do it ARG [default: 1] many times. 1381 "Move forward to next end of rule. Do it ARG [default: 1] many times.
1260A grammar class header and the file prelude are also considered as a 1382A grammar class header and the file prelude are also considered as a
1261rule. Negative argument ARG means move back to ARGth preceding end of 1383rule. Negative argument ARG means move back to ARGth preceding end of
1262rule. If ARG is zero, run `antlr-end-of-body'." 1384rule. If ARG is zero, run `antlr-end-of-body'."
1263 (interactive "p") 1385 (interactive "_p")
1264 (if (zerop arg) 1386 (if (zerop arg)
1265 (antlr-end-of-body) 1387 (antlr-end-of-body)
1266 (antlr-with-syntax-table antlr-action-syntax-table 1388 (antlr-with-syntax-table antlr-action-syntax-table
1267 (antlr-next-rule arg nil)) 1389 (antlr-next-rule arg nil))))
1268 (setq zmacs-region-stays t)))
1269 1390
1270(defun antlr-beginning-of-rule (&optional arg) 1391(defunx antlr-beginning-of-rule (&optional arg)
1271 "Move backward to preceding beginning of rule. Do it ARG many times. 1392 "Move backward to preceding beginning of rule. Do it ARG many times.
1272A grammar class header and the file prelude are also considered as a 1393A grammar class header and the file prelude are also considered as a
1273rule. Negative argument ARG means move forward to ARGth next beginning 1394rule. Negative argument ARG means move forward to ARGth next beginning
1274of rule. If ARG is zero, run `antlr-beginning-of-body'." 1395of rule. If ARG is zero, run `antlr-beginning-of-body'."
1275 (interactive "p") 1396 (interactive "_p")
1276 (if (zerop arg) 1397 (if (zerop arg)
1277 (antlr-beginning-of-body) 1398 (antlr-beginning-of-body)
1278 (antlr-with-syntax-table antlr-action-syntax-table 1399 (antlr-with-syntax-table antlr-action-syntax-table
1279 (antlr-next-rule (- arg) t)) 1400 (antlr-next-rule (- arg) t))))
1280 (setq zmacs-region-stays t)))
1281 1401
1282(defun antlr-end-of-body (&optional msg) 1402(defunx antlr-end-of-body (&optional msg)
1283 "Move to position after the `;' of the current rule. 1403 "Move to position after the `;' of the current rule.
1284A grammar class header is also considered as a rule. With optional 1404A grammar class header is also considered as a rule. With optional
1285prefix arg MSG, move to `:'." 1405prefix arg MSG, move to `:'."
1286 (interactive) 1406 (interactive "_")
1287 (antlr-with-syntax-table antlr-action-syntax-table 1407 (antlr-with-syntax-table antlr-action-syntax-table
1288 (let ((orig (point))) 1408 (let ((orig (point)))
1289 (if (antlr-outside-rule-p) 1409 (if (antlr-outside-rule-p)
@@ -1300,12 +1420,11 @@ prefix arg MSG, move to `:'."
1300 (or (antlr-search-forward ":") (point-max)))) 1420 (or (antlr-search-forward ":") (point-max))))
1301 (goto-char orig) 1421 (goto-char orig)
1302 (error msg)) 1422 (error msg))
1303 (c-forward-syntactic-ws))))) 1423 (c-forward-syntactic-ws))))))
1304 (setq zmacs-region-stays t))
1305 1424
1306(defun antlr-beginning-of-body () 1425(defunx antlr-beginning-of-body ()
1307 "Move to the first element after the `:' of the current rule." 1426 "Move to the first element after the `:' of the current rule."
1308 (interactive) 1427 (interactive "_")
1309 (antlr-end-of-body "Class headers and the file prelude are without `:'")) 1428 (antlr-end-of-body "Class headers and the file prelude are without `:'"))
1310 1429
1311 1430
@@ -1342,12 +1461,7 @@ actions if ARG is 0 or negative. See `antlr-action-visibility'.
1342 1461
1343Display a message unless optional argument SILENT is non-nil." 1462Display a message unless optional argument SILENT is non-nil."
1344 (interactive "p") 1463 (interactive "p")
1345 ;; from Emacs/lazy-lock: `save-buffer-state' 1464 (save-buffer-state-x
1346 (let ((modified (buffer-modified-p))
1347 (buffer-undo-list t) (inhibit-read-only t)
1348 (inhibit-point-motion-hooks t) deactivate-mark ; Emacs only
1349 before-change-functions after-change-functions
1350 buffer-file-name buffer-file-truename)
1351 (if (> arg 0) 1465 (if (> arg 0)
1352 (let ((regexp (if (= arg 1) "[]}]" "}")) 1466 (let ((regexp (if (= arg 1) "[]}]" "}"))
1353 (diff (and antlr-action-visibility 1467 (diff (and antlr-action-visibility
@@ -1358,7 +1472,7 @@ Display a message unless optional argument SILENT is non-nil."
1358 (antlr-with-syntax-table antlr-action-syntax-table 1472 (antlr-with-syntax-table antlr-action-syntax-table
1359 (antlr-invalidate-context-cache) 1473 (antlr-invalidate-context-cache)
1360 (while (antlr-re-search-forward regexp nil) 1474 (while (antlr-re-search-forward regexp nil)
1361 (let ((beg (antlr-scan-sexps (point) -1 nil t))) 1475 (let ((beg (ignore-errors-x (scan-sexps (point) -1))))
1362 (when beg 1476 (when beg
1363 (if diff ; braces are visible 1477 (if diff ; braces are visible
1364 (if (> (point) (+ beg diff)) 1478 (if (> (point) (+ beg diff))
@@ -1379,9 +1493,7 @@ Display a message unless optional argument SILENT is non-nil."
1379 (remove-text-properties (point-min) (point-max) 1493 (remove-text-properties (point-min) (point-max)
1380 '(invisible nil intangible nil)) 1494 '(invisible nil intangible nil))
1381 (or silent 1495 (or silent
1382 (message "Unhide all actions (including arguments)...done"))) 1496 (message "Unhide all actions (including arguments)...done")))))
1383 (and (not modified) (buffer-modified-p)
1384 (set-buffer-modified-p nil))))
1385 1497
1386 1498
1387;;;=========================================================================== 1499;;;===========================================================================
@@ -1416,7 +1528,7 @@ Inserting an option with this command works as follows:
1416 according to a newly inserted language option. 1528 according to a newly inserted language option.
1417 1529
1418The name of all options with a specification for their values are stored 1530The name of all options with a specification for their values are stored
1419in `antlr-options-alist'. The used specification also depends on the 1531in `antlr-options-alists'. The used specification also depends on the
1420value of `antlr-tool-version', i.e., step 4 will warn you if you use an 1532value of `antlr-tool-version', i.e., step 4 will warn you if you use an
1421option that has been introduced in newer version of ANTLR, and step 5 1533option that has been introduced in newer version of ANTLR, and step 5
1422will offer completion using version-correct values. 1534will offer completion using version-correct values.
@@ -1553,7 +1665,7 @@ like \(AREA \. PLACE), see `antlr-option-location'."
1553 (cond ((null pos) 'error) 1665 (cond ((null pos) 'error)
1554 ((looking-at "options[ \t\n]*{") 1666 ((looking-at "options[ \t\n]*{")
1555 (goto-char (match-end 0)) 1667 (goto-char (match-end 0))
1556 (setq pos (antlr-scan-lists (point) 1 1 nil t)) 1668 (setq pos (ignore-errors-x (scan-lists (point) 1 1)))
1557 (antlr-option-location orig min0 max0 1669 (antlr-option-location orig min0 max0
1558 (point) 1670 (point)
1559 (if pos (1- pos) (point-max)) 1671 (if pos (1- pos) (point-max))
@@ -1636,8 +1748,12 @@ a visible start position and (MAX-AREA . end) for a visible end position
1636where the beginning is preferred if WITHP is nil and the end if WITHP is 1748where the beginning is preferred if WITHP is nil and the end if WITHP is
1637non-nil." 1749non-nil."
1638 (cons (and withp (cons min-area max-area)) 1750 (cons (and withp (cons min-area max-area))
1639 (cond ((and (<= min-area orig) (<= orig max-area)) 1751 (cond ((and (<= min-area orig) (<= orig max-area)
1640 ;; point in options area 1752 (save-excursion
1753 (goto-char orig)
1754 (not (memq (antlr-syntactic-context)
1755 '(comment block-comment)))))
1756 ;; point in options area and not in comment
1641 (list orig)) 1757 (list orig))
1642 ((and (null withp) (<= min-vis min-area) (<= min-area max-vis)) 1758 ((and (null withp) (<= min-vis min-area) (<= min-area max-vis))
1643 ;; use start of options area (only if not `withp') 1759 ;; use start of options area (only if not `withp')
@@ -1873,7 +1989,8 @@ table is the resulting alist of TABLE-X concatenated with TABLE where
1873TABLE can also be a function evaluation to an alist. 1989TABLE can also be a function evaluation to an alist.
1874 1990
1875Used inside `antlr-options-alists'." 1991Used inside `antlr-options-alists'."
1876 (let* ((table0 (and (or table table-x) 1992 (let* ((completion-ignore-case t) ; dynamic
1993 (table0 (and (or table table-x)
1877 (append table-x 1994 (append table-x
1878 (if (functionp table) (funcall table) table)))) 1995 (if (functionp table) (funcall table) table))))
1879 (input (if table0 1996 (input (if table0
@@ -1924,6 +2041,7 @@ Ask user \(\"y or n\"), if a C++ only option is going to be inserted but
1924 2041
1925Called in PHASE `before-input', see `antlr-options-alists'." 2042Called in PHASE `before-input', see `antlr-options-alists'."
1926 (and (eq phase 'before-input) 2043 (and (eq phase 'before-input)
2044 (not (eq antlr-language 'c++-mode))
1927 (not (y-or-n-p (format "Insert C++ %s option? " option))) 2045 (not (y-or-n-p (format "Insert C++ %s option? " option)))
1928 (error "Didn't insert C++ %s option with language %s" 2046 (error "Didn't insert C++ %s option with language %s"
1929 option (cadr (assq antlr-language antlr-language-alist))))) 2047 option (cadr (assq antlr-language antlr-language-alist)))))
@@ -1949,7 +2067,7 @@ Each SUPER is a super-grammar class where USE-EVOCAB-P indicates whether
1949its export vocabulary is used as an import vocabulary." 2067its export vocabulary is used as an import vocabulary."
1950 (unless buffer-file-name 2068 (unless buffer-file-name
1951 (error "Grammar buffer does not visit a file")) 2069 (error "Grammar buffer does not visit a file"))
1952 (let (classes exportVocabs importVocabs superclasses default-vocab) 2070 (let (classes export-vocabs import-vocabs superclasses default-vocab)
1953 (antlr-with-syntax-table antlr-action-syntax-table 2071 (antlr-with-syntax-table antlr-action-syntax-table
1954 (goto-char (point-min)) 2072 (goto-char (point-min))
1955 (while (antlr-re-search-forward antlr-class-header-regexp nil) 2073 (while (antlr-re-search-forward antlr-class-header-regexp nil)
@@ -1988,13 +2106,13 @@ its export vocabulary is used as an import vocabulary."
1988 (push (cons class evocab) classes) 2106 (push (cons class evocab) classes)
1989 ;; default export vocab is export vocab of first grammar in file: 2107 ;; default export vocab is export vocab of first grammar in file:
1990 (or default-vocab (setq default-vocab evocab)) 2108 (or default-vocab (setq default-vocab evocab))
1991 (or (member evocab exportVocabs) (push evocab exportVocabs)) 2109 (or (member evocab export-vocabs) (push evocab export-vocabs))
1992 (or (null ivocab) 2110 (or (null ivocab)
1993 (member ivocab importVocabs) (push ivocab importVocabs))))) 2111 (member ivocab import-vocabs) (push ivocab import-vocabs)))))
1994 (if classes 2112 (if classes
1995 (list* (file-name-nondirectory buffer-file-name) 2113 (list* (file-name-nondirectory buffer-file-name)
1996 (cons (nreverse classes) (nreverse superclasses)) 2114 (cons (nreverse classes) (nreverse superclasses))
1997 (cons (nreverse exportVocabs) (nreverse importVocabs)) 2115 (cons (nreverse export-vocabs) (nreverse import-vocabs))
1998 antlr-language)))) 2116 antlr-language))))
1999 2117
2000(defun antlr-directory-dependencies (dirname) 2118(defun antlr-directory-dependencies (dirname)
@@ -2088,29 +2206,33 @@ necessary.
2088Save all buffers first unless optional value SAVED is non-nil. When 2206Save all buffers first unless optional value SAVED is non-nil. When
2089called interactively, the buffers are always saved, see also variable 2207called interactively, the buffers are always saved, see also variable
2090`antlr-ask-about-save'." 2208`antlr-ask-about-save'."
2091 (interactive 2209 (interactive (antlr-run-tool-interactive))
2092 ;; code in `interactive' is not compiled: do not use cl macros (`cdadr')
2093 (let* ((supers (cdr (cadr (save-excursion
2094 (save-restriction
2095 (widen)
2096 (antlr-file-dependencies))))))
2097 (glibs ""))
2098 (when supers
2099 (save-some-buffers (not antlr-ask-about-save) nil)
2100 (setq glibs (car (antlr-superclasses-glibs
2101 supers
2102 (car (antlr-directory-dependencies
2103 (antlr-default-directory)))))))
2104 (list (antlr-read-shell-command "Run Antlr on current file with: "
2105 (concat antlr-tool-command glibs " "))
2106 buffer-file-name
2107 supers)))
2108 (or saved (save-some-buffers (not antlr-ask-about-save))) 2210 (or saved (save-some-buffers (not antlr-ask-about-save)))
2109 (let ((default-directory (file-name-directory file))) 2211 (let ((default-directory (file-name-directory file)))
2110 (require 'compile) ; only `compile' autoload 2212 (require 'compile) ; only `compile' autoload
2111 (compile-internal (concat command " " (file-name-nondirectory file)) 2213 (compile-internal (concat command " " (file-name-nondirectory file))
2112 "No more errors" "Antlr-Run"))) 2214 "No more errors" "Antlr-Run")))
2113 2215
2216(defun antlr-run-tool-interactive ()
2217 ;; code in `interactive' is not compiled
2218 "Interactive specification for `antlr-run-tool'.
2219Use prefix argument ARG to return \(COMMAND FILE SAVED)."
2220 (let* ((supers (cdadr (save-excursion
2221 (save-restriction
2222 (widen)
2223 (antlr-file-dependencies)))))
2224 (glibs ""))
2225 (when supers
2226 (save-some-buffers (not antlr-ask-about-save) nil)
2227 (setq glibs (car (antlr-superclasses-glibs
2228 supers
2229 (car (antlr-directory-dependencies
2230 (antlr-default-directory)))))))
2231 (list (antlr-read-shell-command "Run Antlr on current file with: "
2232 (concat antlr-tool-command glibs " "))
2233 buffer-file-name
2234 supers)))
2235
2114 2236
2115;;;=========================================================================== 2237;;;===========================================================================
2116;;; Makefile creation 2238;;; Makefile creation
@@ -2230,16 +2352,19 @@ multiplied by:
2230Lines inside block comments are indented by `c-indent-line' according to 2352Lines inside block comments are indented by `c-indent-line' according to
2231`antlr-indent-comment'. 2353`antlr-indent-comment'.
2232 2354
2233If `antlr-language' equals to a key in `antlr-indent-at-bol-alist' and 2355Lines in actions except top-level actions in a header part or an option
2234the line starting at the first non-whitespace is matched by the 2356area are indented by `c-indent-line'.
2235corresponding value, indent the line at column 0. 2357
2358Lines in header actions are indented at column 0 if `antlr-language'
2359equals to a key in `antlr-indent-at-bol-alist' and the line starting at
2360the first non-whitespace is matched by the corresponding value.
2236 2361
2237For the initialization of `c-basic-offset', see `antlr-indent-style' and, 2362For the initialization of `c-basic-offset', see `antlr-indent-style' and,
2238to a lesser extent, `antlr-tab-offset-alist'." 2363to a lesser extent, `antlr-tab-offset-alist'."
2239 (save-restriction 2364 (save-restriction
2240 (let ((orig (point)) 2365 (let ((orig (point))
2241 (min0 (point-min)) 2366 (min0 (point-min))
2242 bol boi indent syntax) 2367 bol boi indent syntax cc-syntax)
2243 (widen) 2368 (widen)
2244 (beginning-of-line) 2369 (beginning-of-line)
2245 (setq bol (point)) 2370 (setq bol (point))
@@ -2253,11 +2378,6 @@ to a lesser extent, `antlr-tab-offset-alist'."
2253 (setq syntax (antlr-syntactic-context)) 2378 (setq syntax (antlr-syntactic-context))
2254 (cond ((symbolp syntax) 2379 (cond ((symbolp syntax)
2255 (setq indent nil)) ; block-comments, strings, (comments) 2380 (setq indent nil)) ; block-comments, strings, (comments)
2256 ((and (assq antlr-language antlr-indent-at-bol-alist)
2257 (looking-at (cdr (assq antlr-language
2258 antlr-indent-at-bol-alist))))
2259 (setq syntax 'bol)
2260 (setq indent 0)) ; indentation at 0
2261 ((progn 2381 ((progn
2262 (antlr-next-rule -1 t) 2382 (antlr-next-rule -1 t)
2263 (if (antlr-search-forward ":") (< boi (1- (point))) t)) 2383 (if (antlr-search-forward ":") (< boi (1- (point))) t))
@@ -2268,20 +2388,45 @@ to a lesser extent, `antlr-tab-offset-alist'."
2268 (forward-char) 2388 (forward-char)
2269 (antlr-skip-exception-part nil) 2389 (antlr-skip-exception-part nil)
2270 (setq indent (if (> (point) boi) 1 0))))) ; in exception part? 2390 (setq indent (if (> (point) boi) 1 0))))) ; in exception part?
2271 ;; compute the corresponding indentation and indent -------------------- 2391 ;; check whether to use indentation engine of cc-mode ------------------
2392 (antlr-invalidate-context-cache)
2393 (goto-char boi)
2394 (when (and indent (> syntax 0))
2395 (cond ((> syntax 1) ; block in action => use cc-mode
2396 (setq indent nil))
2397 ((and (= indent 0)
2398 (assq antlr-language antlr-indent-at-bol-alist)
2399 (looking-at (cdr (assq antlr-language
2400 antlr-indent-at-bol-alist))))
2401 (setq syntax 'bol))
2402 ((setq cc-syntax (c-guess-basic-syntax))
2403 (let ((cc cc-syntax) symbol)
2404 (while (setq symbol (pop cc))
2405 (when (cdr symbol)
2406 (or (memq (car symbol)
2407 antlr-disabling-cc-syntactic-symbols)
2408 (setq indent nil))
2409 (setq cc nil)))))))
2410;;; ((= indent 1) ; exception part => use cc-mode
2411;;; (setq indent nil))
2412;;; ((save-restriction ; not in option part => cc-mode
2413;;; (goto-char (scan-lists (point) -1 1))
2414;;; (skip-chars-backward " \t\n")
2415;;; (narrow-to-region (point-min) (point))
2416;;; (not (re-search-backward "\\<options\\'" nil t)))
2417;;; (setq indent nil)))))
2418 ;; compute the corresponding indentation and indent --------------------
2272 (if (null indent) 2419 (if (null indent)
2273 ;; Use the indentation engine of cc-mode for block comments. Using 2420 ;; Use the indentation engine of cc-mode
2274 ;; it-mode for actions is not easy, especially if the actions come
2275 ;; early in the rule body.
2276 (progn 2421 (progn
2277 (goto-char orig) 2422 (goto-char orig)
2278 (and (eq antlr-indent-comment t) 2423 (if (or (numberp syntax)
2279 (not (eq syntax 'string)) 2424 (if (eq syntax 'string) nil (eq antlr-indent-comment t)))
2280 (c-indent-line))) 2425 (c-indent-line cc-syntax)))
2281 ;; do it ourselves 2426 ;; do it ourselves
2282 (goto-char boi) 2427 (goto-char boi)
2283 (unless (symbolp syntax) ; direct indentation 2428 (unless (symbolp syntax) ; direct indentation
2284 (antlr-invalidate-context-cache) 2429 ;;(antlr-invalidate-context-cache)
2285 (incf indent (antlr-syntactic-context)) 2430 (incf indent (antlr-syntactic-context))
2286 (and (> indent 0) (looking-at antlr-indent-item-regexp) (decf indent)) 2431 (and (> indent 0) (looking-at antlr-indent-item-regexp) (decf indent))
2287 (setq indent (* indent c-basic-offset))) 2432 (setq indent (* indent c-basic-offset)))
@@ -2382,6 +2527,13 @@ ANTLR's syntax and influences the auto indentation, see
2382 comment-line-break-function 'c-comment-line-break-function 2527 comment-line-break-function 'c-comment-line-break-function
2383 adaptive-fill-regexp nil 2528 adaptive-fill-regexp nil
2384 adaptive-fill-mode nil) 2529 adaptive-fill-mode nil)
2530 (c-set-style (or antlr-indent-style "gnu"))
2531 (and (boundp 'c-current-comment-prefix) (boundp 'c-comment-prefix-regexp)
2532 (setq c-current-comment-prefix
2533 (if (listp c-comment-prefix-regexp)
2534 (cdr-safe (or (assoc major-mode c-comment-prefix-regexp)
2535 (assoc 'other c-comment-prefix-regexp)))
2536 c-comment-prefix-regexp)))
2385 ;; we have to do something special for c-offsets-alist so that the 2537 ;; we have to do something special for c-offsets-alist so that the
2386 ;; buffer local value has its own alist structure. 2538 ;; buffer local value has its own alist structure.
2387 (setq c-offsets-alist (copy-alist c-offsets-alist)) 2539 (setq c-offsets-alist (copy-alist c-offsets-alist))
@@ -2403,7 +2555,7 @@ the default language."
2403 (match-string 1))) 2555 (match-string 1)))
2404 (seq antlr-language-alist) 2556 (seq antlr-language-alist)
2405 r) 2557 r)
2406 ;; Like (find-VALUE antlr-language-alist :key 'cddr :test 'member) 2558 ;; Like (find VALUE antlr-language-alist :key 'cddr :test 'member)
2407 (while seq 2559 (while seq
2408 (setq r (pop seq)) 2560 (setq r (pop seq))
2409 (if (member value (cddr r)) 2561 (if (member value (cddr r))
@@ -2417,7 +2569,7 @@ the default language."
2417 "Major mode for editing ANTLR grammar files. 2569 "Major mode for editing ANTLR grammar files.
2418\\{antlr-mode-map}" 2570\\{antlr-mode-map}"
2419 (interactive) 2571 (interactive)
2420 (c-initialize-cc-mode) ; for java syntax table 2572 (c-initialize-cc-mode) ; required when depending on cc-mode
2421 (kill-all-local-variables) 2573 (kill-all-local-variables)
2422 ;; ANTLR specific ---------------------------------------------------------- 2574 ;; ANTLR specific ----------------------------------------------------------
2423 (setq major-mode 'antlr-mode 2575 (setq major-mode 'antlr-mode
@@ -2448,25 +2600,39 @@ the default language."
2448 (antlr-c-common-init) 2600 (antlr-c-common-init)
2449 (setq indent-line-function 'antlr-indent-line 2601 (setq indent-line-function 'antlr-indent-line
2450 indent-region-function nil) ; too lazy 2602 indent-region-function nil) ; too lazy
2603 (setq c-buffer-is-cc-mode antlr-language)
2604 (if (fboundp 'c-init-language-vars)
2605 (c-init-language-vars) ; cc-mode >= v5.29
2606 (let ((settings ; (cdr '(setq...)) will be optimized
2607 (if (eq antlr-language 'c++-mode)
2608 (cdr '(setq ;' from `c++-mode' v5.20, v5.28
2609 c-keywords (c-identifier-re c-C++-keywords)
2610 c-conditional-key c-C++-conditional-key
2611 c-comment-start-regexp c-C++-comment-start-regexp
2612 c-class-key c-C++-class-key
2613 c-extra-toplevel-key c-C++-extra-toplevel-key
2614 c-access-key c-C++-access-key
2615 c-recognize-knr-p nil
2616 c-bitfield-key c-C-bitfield-key ; v5.28
2617 ))
2618 (cdr '(setq ; from `java-mode' v5.20, v5.28
2619 c-keywords (c-identifier-re c-Java-keywords)
2620 c-conditional-key c-Java-conditional-key
2621 c-comment-start-regexp c-Java-comment-start-regexp
2622 c-class-key c-Java-class-key
2623 c-method-key nil
2624 c-baseclass-key nil
2625 c-recognize-knr-p nil
2626 c-access-key c-Java-access-key ; v5.20
2627 c-inexpr-class-key c-Java-inexpr-class-key ; v5.28
2628 )))))
2629 (while settings
2630 (when (boundp (car settings))
2631 (ignore-errors
2632 (set (car settings) (eval (cadr settings)))))
2633 (setq settings (cddr settings)))))
2451 (setq comment-start "// " 2634 (setq comment-start "// "
2452 comment-end "") 2635 comment-end "")
2453 (c-set-style "java")
2454 (if (eq antlr-language 'c++-mode)
2455 (setq c-conditional-key c-C++-conditional-key
2456 c-comment-start-regexp c-C++-comment-start-regexp
2457 c-class-key c-C++-class-key
2458 c-extra-toplevel-key c-C++-extra-toplevel-key
2459 c-access-key c-C++-access-key
2460 c-recognize-knr-p nil)
2461 (setq c-conditional-key c-Java-conditional-key
2462 c-comment-start-regexp c-Java-comment-start-regexp
2463 c-class-key c-Java-class-key
2464 c-method-key nil
2465 c-baseclass-key nil
2466 c-recognize-knr-p nil
2467 c-access-key (and (boundp 'c-Java-access-key) c-Java-access-key))
2468 (and (boundp 'c-inexpr-class-key) (boundp 'c-Java-inexpr-class-key)
2469 (setq c-inexpr-class-key c-Java-inexpr-class-key)))
2470 ;; various ----------------------------------------------------------------- 2636 ;; various -----------------------------------------------------------------
2471 (make-local-variable 'font-lock-defaults) 2637 (make-local-variable 'font-lock-defaults)
2472 (setq font-lock-defaults antlr-font-lock-defaults) 2638 (setq font-lock-defaults antlr-font-lock-defaults)
@@ -2502,21 +2668,5 @@ Used in `antlr-mode'. Also a useful function in `java-mode-hook'."
2502 indent-tabs-mode (cadddr elem) 2668 indent-tabs-mode (cadddr elem)
2503 alist nil)))))) 2669 alist nil))))))
2504 2670
2505; LocalWords: antlr ANother ANTLR's Cpp Lexer TreeParser esp refs VALUEs ea ee 2671;;; Local IspellPersDict: .ispell_antlr
2506; LocalWords: Java's Nomencl ruledef tokendef ruleref tokenref setType ader ev
2507; LocalWords: ivate syntab lexer treeparser lic rotected rivate bor boi AFAIK
2508; LocalWords: slist knr inexpr unhide jit GENS SEP GEN sTokenTypes hpp cpp DEP
2509; LocalWords: VOCAB EVOCAB Antlr's TokenTypes exportVocab incl excl SUPERS gen
2510; LocalWords: VOCABS IVOCAB exportVocabs importVocabs superclasses vocab kens
2511; LocalWords: sclass evocab ivocab importVocab deps glibs supers sep dep lang
2512; LocalWords: htmlize subrule jde Sather sather eiffel SGML's XYYZZ namespace
2513; LocalWords: mangleLiteralPrefix namespaceStd namespaceAntlr genHashLines AST
2514; LocalWords: testLiterals defaultErrorHandler codeGenMakeSwitchThreshold XXX
2515; LocalWords: codeGenBitsetTestThreshold bitset analyzerDebug codeGenDebug boc
2516; LocalWords: buildAST ASTLabelType charVocabulary caseSensitive autoTokenDef
2517; LocalWords: caseSensitiveLiterals classHeaderSuffix keywordsMeltTo NAMEs LL
2518; LocalWords: warnWhenFollowAmbig generateAmbigWarnings ARGs tokenrefs withp
2519; LocalWords: outsidep existsp JOR sert endif se ndef mport nclude pragma LE
2520; LocalWords: TION ASE RSION OMPT ava serting VEL mparison AMMAR
2521
2522;;; antlr-mode.el ends here 2672;;; antlr-mode.el ends here