diff options
| author | Richard M. Stallman | 2001-12-21 23:57:08 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2001-12-21 23:57:08 +0000 |
| commit | 2633072a0d997d42901a661a3fdede8f32c50da1 (patch) | |
| tree | c26fa265bcd44c757a97149565240bd037caaf10 | |
| parent | 31877e0a33581c44506c24af9ed3163a0b19faf5 (diff) | |
| download | emacs-2633072a0d997d42901a661a3fdede8f32c50da1.tar.gz emacs-2633072a0d997d42901a661a3fdede8f32c50da1.zip | |
More sophisticated indentation of cpp directive.
(antlr-indent-at-bol-alist): New user option.
(antlr-indent-line): Use it.
(antlr-indent-style): New user option.
(antlr-mode): Use it.
(antlr-indent-item-regexp): Customize.
Syntax highlighting changes.
(antlr-font-lock-literal-regexp): New user option.
(antlr-font-lock-syntax-face): New face used for :, |, ....
(antlr-font-lock-default-face): New face.
(antlr-font-lock-additional-keywords): Use them.
New command to insert options -- variables.
(antlr-mode-map): New binding [C-c C-o].
(antlr-mode-menu): New submenus.
(antlr-options-use-submenus): New user option.
(antlr-tool-version): New user option.
(antlr-options-auto-colon): New user option.
(antlr-options-style): New user option.
(antlr-options-push-mark): New user option.
(antlr-options-assign-string): New user option.
(antlr-options-headings): New variable.
New command to insert options -- specific.
(antlr-options-alists): New variable.
(antlr-read-value): New function.
(antlr-read-boolean): New function.
(antlr-language-option-extra): New function.
(antlr-language-limit-n-regexp): Change default to higher LIMIT.
(antlr-c++-mode-extra): New function.
(antlr-grammar-tokens): New function.
(antlr-imenu-create-index-function): New optional argument.
New command to insert options -- functions.
(antlr-insert-option): New command.
(antlr-insert-option-interactive): New function.
(antlr-options-menu-filter): New function.
(antlr-option-kind): New function.
(antlr-scan-lists): New alias.
(antlr-scan-lists-internal): New function.
(antlr-skip-file-prelude): Hack for special SKIP-COMMENT.
(antlr-option-level): New function.
(antlr-syntactic-grammar-depth): New function.
(antlr-option-location): New function.
(antlr-insert-option-do): New function.
(antlr-option-spec): New function.
(antlr-version-string): New function.
(antlr-insert-option-existing): New function.
(antlr-insert-option-space): New function.
(antlr-insert-option-area): New function.
New electric keys ":;|&(){}", TAB works better
with narrowing. Menu change. Miscellaneous.
(antlr-mode-menu): Include "Indent Region" and "Customize Antlr".
(antlr-mode-map): New bindings for characters in ":;|&(){}".
(antlr-electric-character): New command.
(antlr-class-header-regexp): New variable.
(antlr-font-lock-additional-keywords): Use it.
(antlr-imenu-create-index-function): Use it.
(antlr-file-dependencies): Use it.
(antlr-indent-line): Also works with restrictions.
(antlr-indent-command): Interactive spec - changes the buffer.
(antlr-language-for-option): Deletia.
(antlr-language-option): New function, defined instead.
(antlr-mode): Use it.
| -rw-r--r-- | lisp/ChangeLog | 2 | ||||
| -rw-r--r-- | lisp/progmodes/antlr-mode.el | 1420 |
2 files changed, 1201 insertions, 221 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d25d0acd80d..bf8ccc62c00 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -21,6 +21,8 @@ | |||
| 21 | 21 | ||
| 22 | 2001-12-21 Richard M. Stallman <rms@gnu.org> | 22 | 2001-12-21 Richard M. Stallman <rms@gnu.org> |
| 23 | 23 | ||
| 24 | * net/ange-ftp.el (ange-ftp-file-modtime): Use save-match-data. | ||
| 25 | |||
| 24 | * emacs-lisp/easy-mmode.el (define-minor-mode): | 26 | * emacs-lisp/easy-mmode.el (define-minor-mode): |
| 25 | Make no arg by default in an interactive call, | 27 | Make no arg by default in an interactive call, |
| 26 | so that repeating the command toggles again. | 28 | so that repeating the command toggles again. |
diff --git a/lisp/progmodes/antlr-mode.el b/lisp/progmodes/antlr-mode.el index 40e2a18334c..5ef5c4d35be 100644 --- a/lisp/progmodes/antlr-mode.el +++ b/lisp/progmodes/antlr-mode.el | |||
| @@ -1,10 +1,10 @@ | |||
| 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-2001 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: 1.4 | 7 | ;; Version: 2.1 |
| 8 | ;; X-URL: http://www.fmi.uni-passau.de/~wedler/antlr-mode/ | 8 | ;; X-URL: http://www.fmi.uni-passau.de/~wedler/antlr-mode/ |
| 9 | 9 | ||
| 10 | ;; This file is part of GNU Emacs. | 10 | ;; This file is part of GNU Emacs. |
| @@ -26,54 +26,80 @@ | |||
| 26 | 26 | ||
| 27 | ;;; Commentary: | 27 | ;;; Commentary: |
| 28 | 28 | ||
| 29 | ;; Major mode for editing ANTLR grammar files, i.e., files ending with `.g'. | 29 | ;; This Emacs extension (major mode) provides various features for editing |
| 30 | ;; ANTLR is ANother Tool for Language Recognition (an excellent alternative to | 30 | ;; ANTLR grammar files. ANTLR is a tool for LL(k)-based language recognition |
| 31 | ;; lex/yacc), see <http://www.ANTLR.org> and <news:comp.compilers.tools.pccts>. | 31 | ;; and an excellent alternative to lex & yacc, see <http://www.ANTLR.org>. |
| 32 | ;; Some features depend on the value of ANTLR's "language" option (check the | ||
| 33 | ;; modeline for "Antlr.Java" or "Antlr.C++"). | ||
| 32 | 34 | ||
| 33 | ;; This package provides the following features: | 35 | ;; This package provides the following features: |
| 34 | ;; * Syntax coloring (via font-lock) for grammar symbols and the code in | 36 | ;; * Syntax highlighting for grammar symbols and the code in actions. |
| 35 | ;; actions. The latter depends on the language settings. | 37 | ;; * Indentation (pretty-print) for the current line (TAB) and lines in the |
| 36 | ;; * Indentation for the current line (TAB) and selected region (C-M-\). | 38 | ;; selected region (C-M-\). Inserting an ANTLR syntax symbol (one of |
| 37 | ;; * Support for imenu/speedbar: menu "Index" (Parser, Lexer, TreeParser). | 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. | ||
| 38 | ;; * Commands to move to previous/next rule, beginning/end of rule body etc. | 42 | ;; * Commands to move to previous/next rule, beginning/end of rule body etc. |
| 39 | ;; * Commands to hide/unhide actions, upcase/downcase literals. | 43 | ;; * Commands to hide/unhide actions. |
| 44 | ;; * Support to insert/change file/grammar/rule/subrule options. | ||
| 40 | ;; * Run ANTLR from within Emacs, create Makefile dependencies. | 45 | ;; * Run ANTLR from within Emacs, create Makefile dependencies. |
| 41 | 46 | ||
| 42 | ;; LANGUAGE SETTINGS. This mode needs to know which language is used in | 47 | ;; SYNTAX HIGHLIGHTING comes in three phases. First, comments and strings are |
| 43 | ;; actions and semantic predicated of the grammar. This information is used | 48 | ;; highlighted. Second, the grammar code is highlighted according to |
| 44 | ;; for syntax coloring and the creation of the Makefile dependencies. It is | 49 | ;; `antlr-font-lock-additional-keywords' (rule refs: dark blue, token refs: |
| 45 | ;; stored in variable `antlr-language' and automatically set according to | 50 | ;; dark orange, definition: bold blue). Third, actions, semantic predicates |
| 46 | ;; ANTLR's file option "language", see `antlr-language-alist'. The supported | 51 | ;; and arguments are highlighted according to the usual font-lock keywords of |
| 47 | ;; languages are "Java" (java-mode) and "Cpp" (c++-mode). | 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. | ||
| 48 | 56 | ||
| 49 | ;; INDENTATION. This package supports ANTLR's (intended) indentation style | 57 | ;; INDENTATION. This package supports ANTLR's (intended) indentation style |
| 50 | ;; which is based on a simple paren/brace/bracket depth-level calculation, see | 58 | ;; which is based on a simple paren/brace/bracket depth-level calculation, see |
| 51 | ;; `antlr-indent-line'. The indentation engine of cc-mode is only used inside | 59 | ;; `antlr-indent-line'. The indentation engine of cc-mode is only used inside |
| 52 | ;; block comments (it is not easy to use it for actions, esp if they come early | 60 | ;; block comments. By default, this package defines a tab width of 4 to be |
| 53 | ;; in the rule body). By default, this package defines a tab width of 4 to be | ||
| 54 | ;; consistent to both ANTLR's conventions (TABs usage) and the | 61 | ;; consistent to both ANTLR's conventions (TABs usage) and the |
| 55 | ;; `c-indentation-style' "java" which sets `c-basic-offset' to 4, see | 62 | ;; `c-indentation-style' "java" which sets `c-basic-offset' to 4, see |
| 56 | ;; `antlr-tab-offset-alist'. You might want to set this variable to nil. | 63 | ;; `antlr-tab-offset-alist'. You might want to set this variable to nil. |
| 57 | 64 | ||
| 58 | ;; SYNTAX COLORING comes in three phases. First, comments and strings are | 65 | ;; OPTION SUPPORT. This package provides special support to insert or change |
| 59 | ;; highlighted. Second, the grammar code is highlighted according to | 66 | ;; file, grammar, rule and subrule options via the menu or via the keyboard |
| 60 | ;; `antlr-font-lock-additional-keywords' (rule refs: dark blue, token refs: | 67 | ;; with completion. For most options, you can also insert the value with |
| 61 | ;; dark orange, definition: bold blue). Third, actions, semantic predicates | 68 | ;; completion (or select a value from a list by pressing `?'). You get a |
| 62 | ;; and arguments are highlighted according to the usual font-lock keywords of | 69 | ;; warning if an option is not supported by the version of ANTLR you are using |
| 63 | ;; `antlr-language', see also `antlr-font-lock-maximum-decoration'. We define | 70 | ;; (`antlr-tool-version' defaults to 2.7.1), or if the option shouldn't be |
| 64 | ;; special font-lock faces for the grammar code to allow you to distinguish | 71 | ;; inserted for other reasons. This package knows the correct position where |
| 65 | ;; ANTLR keywords from Java/C++ keywords. | 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]. | ||
| 66 | 74 | ||
| 67 | ;; MAKEFILE CREATION. Command \\[antlr-show-makefile-rules] shows/inserts the | 75 | ;; MAKEFILE CREATION. Command \\[antlr-show-makefile-rules] shows/inserts the |
| 68 | ;; dependencies for all grammar files in the current directory. It considers | 76 | ;; dependencies for all grammar files in the current directory. It considers |
| 69 | ;; import/export vocabularies and grammar inheritance and provides a value for | 77 | ;; ANTLR's "language" option, import/export vocabularies and grammar |
| 70 | ;; the -glib option if necessary (which you have to edit if the super-grammar | 78 | ;; inheritance, and provides a value for the -glib option if necessary (which |
| 71 | ;; is not in the same directory). | 79 | ;; you have to edit if the super-grammar is not in the same directory). |
| 72 | 80 | ||
| 73 | ;; TODO. Support to insert/change file/grammar/rule/subrule options. imenu | 81 | ;; TODO/WISH-LIST. Things which might be supported in future versions: |
| 74 | ;; support for method definitions in actions is not really planned (you can | 82 | |
| 75 | ;; send be a patch, though). This mode would become too dependent on cc-mode | 83 | ;; * Next Version [C-c C-w]. Produce HTML document with syntax highlighted |
| 76 | ;; or I would have to do a lot of language-dependent things myself... | 84 | ;; and hyper-links (using htmlize). |
| 85 | ;; * Next Version [C-c C-u]. Insert/update special comments: each rule lists | ||
| 86 | ;; all rules which use the current rule. With font-lock update. | ||
| 87 | ;; * Next Version. Make hiding much more customizable. | ||
| 88 | ;; * Planned [C-c C-j]. Jump to generated coding. | ||
| 89 | ;; * Planned. Further support for imenu, i.e., include entries for method | ||
| 90 | ;; definitions at beginning of grammar class. | ||
| 91 | ;; * Planned [C-c C-p]. Pack/unpack rule/subrule & options (one/multi-line). | ||
| 92 | |||
| 93 | ;; * Probably. Show rules/dependencies for ANT like for Makefile (does ANT | ||
| 94 | ;; support vocabularies and grammar inheritance?), I have to look at | ||
| 95 | ;; jde-ant.el: http://jakarta.apache.org/ant/manual/OptionalTasks/antlr.html | ||
| 96 | ;; * Unlikely. Sather as generated language with syntax highlighting etc/. | ||
| 97 | ;; Questions/problems: is sather-mode.el the standard mode for sather, is it | ||
| 98 | ;; still supported, what is its relationship to eiffel3.el? Requirement: | ||
| 99 | ;; this mode must not depend on a Sather mode. | ||
| 100 | ;; * Unlikely. Faster syntax highlighting: sectionize the buffer into Antlr | ||
| 101 | ;; and action code and run special highlighting functions on these regions. | ||
| 102 | ;; Problems: code size, this mode would depend on font-lock internals. | ||
| 77 | 103 | ||
| 78 | ;; Bug fixes, bug reports, improvements, and suggestions are strongly | 104 | ;; Bug fixes, bug reports, improvements, and suggestions are strongly |
| 79 | ;; appreciated. Please check the newest version first: | 105 | ;; appreciated. Please check the newest version first: |
| @@ -97,19 +123,22 @@ | |||
| 97 | ;; I strongly recommend to use font-lock with a support mode like fast-lock, | 123 | ;; I strongly recommend to use font-lock with a support mode like fast-lock, |
| 98 | ;; lazy-lock or better jit-lock (Emacs-21.1+) / lazy-shot (XEmacs). | 124 | ;; lazy-lock or better jit-lock (Emacs-21.1+) / lazy-shot (XEmacs). |
| 99 | 125 | ||
| 100 | ;; To customize, use `M-x customize-group RET antlr RET' or the custom browser | 126 | ;; To customize, use menu item "Antlr" -> "Customize Antlr". |
| 101 | ;; (Emacs->Programming->Languages->Antlr). | ||
| 102 | 127 | ||
| 103 | ;;; Code: | 128 | ;;; Code: |
| 104 | 129 | ||
| 105 | (provide 'antlr-mode) | 130 | (provide 'antlr-mode) |
| 106 | (eval-when-compile ; required and optional libraries | 131 | (eval-when-compile ; required and optional libraries |
| 107 | (require 'cc-mode) | 132 | (require 'cc-mode) |
| 133 | (defvar c-Java-access-key) ; former cc-mode variable | ||
| 134 | (condition-case nil (require 'font-lock) (error nil)) | ||
| 135 | (condition-case nil (require 'compile) (error nil)) | ||
| 108 | (defvar outline-level) (defvar imenu-use-markers) | 136 | (defvar outline-level) (defvar imenu-use-markers) |
| 109 | (defvar imenu-create-index-function)) | 137 | (defvar imenu-create-index-function)) |
| 110 | (eval-when-compile ; Emacs: cl, easymenu | 138 | (eval-when-compile ; Emacs: cl, easymenu, XEmacs vars |
| 111 | (require 'cl) | 139 | (require 'cl) |
| 112 | (require 'easymenu)) | 140 | (require 'easymenu) |
| 141 | (defvar zmacs-region-stays)) | ||
| 113 | (eval-when-compile ; XEmacs: Emacs vars | 142 | (eval-when-compile ; XEmacs: Emacs vars |
| 114 | (defvar inhibit-point-motion-hooks) (defvar deactivate-mark)) | 143 | (defvar inhibit-point-motion-hooks) (defvar deactivate-mark)) |
| 115 | 144 | ||
| @@ -117,6 +146,9 @@ | |||
| 117 | (if (featurep 'xemacs) | 146 | (if (featurep 'xemacs) |
| 118 | (defalias 'antlr-scan-sexps 'scan-sexps) | 147 | (defalias 'antlr-scan-sexps 'scan-sexps) |
| 119 | (defalias 'antlr-scan-sexps 'antlr-scan-sexps-internal)) | 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)) | ||
| 120 | (if (fboundp 'default-directory) | 152 | (if (fboundp 'default-directory) |
| 121 | (defalias 'antlr-default-directory 'default-directory) | 153 | (defalias 'antlr-default-directory 'default-directory) |
| 122 | (defun antlr-default-directory () default-directory)) | 154 | (defun antlr-default-directory () default-directory)) |
| @@ -152,7 +184,7 @@ | |||
| 152 | :link '(url-link "http://www.fmi.uni-passau.de/~wedler/antlr-mode/") | 184 | :link '(url-link "http://www.fmi.uni-passau.de/~wedler/antlr-mode/") |
| 153 | :prefix "antlr-") | 185 | :prefix "antlr-") |
| 154 | 186 | ||
| 155 | (defconst antlr-version "1.4" | 187 | (defconst antlr-version "2.1" |
| 156 | "ANTLR major mode version number.") | 188 | "ANTLR major mode version number.") |
| 157 | 189 | ||
| 158 | 190 | ||
| @@ -172,7 +204,7 @@ variable list\" near the end of the file, see | |||
| 172 | (c++-mode "C++" "\"Cpp\"" "Cpp")) | 204 | (c++-mode "C++" "\"Cpp\"" "Cpp")) |
| 173 | "List of ANTLR's supported languages. | 205 | "List of ANTLR's supported languages. |
| 174 | Each element in this list looks like | 206 | Each element in this list looks like |
| 175 | (MAJOR-MODE MODELINE-STRING OPTION-VALUE...) | 207 | \(MAJOR-MODE MODELINE-STRING OPTION-VALUE...) |
| 176 | 208 | ||
| 177 | MAJOR-MODE, the major mode of the code in the grammar's actions, is the | 209 | MAJOR-MODE, the major mode of the code in the grammar's actions, is the |
| 178 | value of `antlr-language' if the first group in the string matched by | 210 | value of `antlr-language' if the first group in the string matched by |
| @@ -188,9 +220,9 @@ also displayed in the modeline next to \"Antlr\"." | |||
| 188 | string ))))) | 220 | string ))))) |
| 189 | 221 | ||
| 190 | (defcustom antlr-language-limit-n-regexp | 222 | (defcustom antlr-language-limit-n-regexp |
| 191 | '(3000 . "language[ \t]*=[ \t]*\\(\"?[A-Z][A-Za-z_]*\"?\\)") | 223 | '(8192 . "language[ \t]*=[ \t]*\\(\"?[A-Z][A-Za-z_]*\"?\\)") |
| 192 | "Used to set a reasonable value for `antlr-language'. | 224 | "Used to set a reasonable value for `antlr-language'. |
| 193 | Looks like (LIMIT . REGEXP). Search for REGEXP from the beginning of | 225 | Looks like \(LIMIT \. REGEXP). Search for REGEXP from the beginning of |
| 194 | the buffer to LIMIT and use the first group in the matched string to set | 226 | the buffer to LIMIT and use the first group in the matched string to set |
| 195 | the language according to `antlr-language-alist'." | 227 | the language according to `antlr-language-alist'." |
| 196 | :group 'antlr | 228 | :group 'antlr |
| @@ -225,10 +257,10 @@ they are only changed by \\[antlr-indent-command]." | |||
| 225 | '((antlr-mode nil 4 nil) | 257 | '((antlr-mode nil 4 nil) |
| 226 | (java-mode "antlr" 4 nil)) | 258 | (java-mode "antlr" 4 nil)) |
| 227 | "Alist to determine whether to use ANTLR's convention for TABs. | 259 | "Alist to determine whether to use ANTLR's convention for TABs. |
| 228 | Each element looks like (MAJOR-MODE REGEXP TAB-WIDTH INDENT-TABS-MODE). | 260 | Each element looks like \(MAJOR-MODE REGEXP TAB-WIDTH INDENT-TABS-MODE). |
| 229 | The first element whose MAJOR-MODE is nil or equal to `major-mode' and | 261 | The first element whose MAJOR-MODE is nil or equal to `major-mode' and |
| 230 | whose REGEXP is nil or matches `buffer-file-name' is used to set | 262 | whose REGEXP is nil or matches variable `buffer-file-name' is used to |
| 231 | `tab-width' and `indent-tabs-mode'. This is useful to support both | 263 | set `tab-width' and `indent-tabs-mode'. This is useful to support both |
| 232 | ANTLR's and Java's indentation styles. Used by `antlr-set-tabs'." | 264 | ANTLR's and Java's indentation styles. Used by `antlr-set-tabs'." |
| 233 | :group 'antlr | 265 | :group 'antlr |
| 234 | :type '(repeat (group :value (antlr-mode nil 8 nil) | 266 | :type '(repeat (group :value (antlr-mode nil 8 nil) |
| @@ -238,10 +270,270 @@ ANTLR's and Java's indentation styles. Used by `antlr-set-tabs'." | |||
| 238 | (integer :tag "Tab width") | 270 | (integer :tag "Tab width") |
| 239 | (boolean :tag "Indent-tabs-mode")))) | 271 | (boolean :tag "Indent-tabs-mode")))) |
| 240 | 272 | ||
| 241 | (defvar antlr-indent-item-regexp | 273 | (defcustom antlr-indent-style "java" |
| 242 | "[]}):;|&]\\|default[ \t]*:\\|case[ \t]+\\('\\\\?.'\\|[0-9]+\\|[A-Za-z_][A-Za-z_0-9]*\\)[ \t]*:" ; & is local ANTLR extension | 274 | "*If non-nil, cc-mode indentation style used for `antlr-mode'. |
| 275 | See `c-set-style' for details." | ||
| 276 | :group 'antlr | ||
| 277 | :type '(choice (const nil) regexp)) | ||
| 278 | |||
| 279 | (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) | ||
| 243 | "Regexp matching lines which should be indented by one TAB less. | 281 | "Regexp matching lines which should be indented by one TAB less. |
| 244 | See command \\[antlr-indent-command].") | 282 | See `antlr-indent-line' and command \\[antlr-indent-command]." |
| 283 | :group 'antlr | ||
| 284 | :type 'regexp) | ||
| 285 | |||
| 286 | (defcustom antlr-indent-at-bol-alist | ||
| 287 | ;; 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\\)\\>")) | ||
| 289 | "Alist of regexps matching lines are indented at column 0. | ||
| 290 | Each element in this list looks like (MODE . REGEXP) where MODE is a | ||
| 291 | function and REGEXP is a regular expression. | ||
| 292 | |||
| 293 | If `antlr-language' equals to a MODE and the line starting at the first | ||
| 294 | non-whitespace is matched by the corresponding REGEXP, indent the line | ||
| 295 | at column 0 instead according to the normal rules of `antlr-indent-line'." | ||
| 296 | :group 'antlr | ||
| 297 | :type '(repeat (cons (function :tag "Major mode") regexp))) | ||
| 298 | |||
| 299 | |||
| 300 | ;;;=========================================================================== | ||
| 301 | ;;; Options: customization | ||
| 302 | ;;;=========================================================================== | ||
| 303 | |||
| 304 | (defcustom antlr-options-use-submenus t | ||
| 305 | "*Non-nil, if the major mode menu should include option submenus. | ||
| 306 | If nil, the menu just includes a command to insert options. Otherwise, | ||
| 307 | it includes four submenus to insert file/grammar/rule/subrule options." | ||
| 308 | :group 'antlr | ||
| 309 | :type 'boolean) | ||
| 310 | |||
| 311 | (defcustom antlr-tool-version 20701 | ||
| 312 | "*The version number of the Antlr tool. | ||
| 313 | The value is an integer of the form XYYZZ which stands for vX.YY.ZZ. | ||
| 314 | This variable is used to warn about non-supported options and to supply | ||
| 315 | version correct option values when using \\[antlr-insert-option]. | ||
| 316 | |||
| 317 | Don't use a number smaller than 20600 since the stored history of | ||
| 318 | Antlr's options starts with v2.06.00, see `antlr-options-alists'. You | ||
| 319 | can make this variable buffer-local." | ||
| 320 | :group 'antlr | ||
| 321 | :type 'integer) | ||
| 322 | |||
| 323 | (defcustom antlr-options-auto-colon t | ||
| 324 | "*Non-nil, if `:' is inserted with a rule or subrule options section. | ||
| 325 | A `:' is only inserted if this value is non-nil, if a rule or subrule | ||
| 326 | option is inserted with \\[antlr-insert-option], if there was no rule or | ||
| 327 | subrule options section before, and if a `:' is not already present | ||
| 328 | after the section, ignoring whitespace, comments and the init action." | ||
| 329 | :group 'antlr | ||
| 330 | :type 'boolean) | ||
| 331 | |||
| 332 | (defcustom antlr-options-style nil | ||
| 333 | "List of symbols which determine the style of option values. | ||
| 334 | If a style symbol is present, the corresponding option value is put into | ||
| 335 | quotes, i.e., represented as a string, otherwise it is represented as an | ||
| 336 | identifier. | ||
| 337 | |||
| 338 | The only style symbol used in the default value of `antlr-options-alist' | ||
| 339 | is `language-as-string'. See also `antlr-read-value'." | ||
| 340 | :group 'antlr | ||
| 341 | :type '(repeat (symbol :tag "Style symbol"))) | ||
| 342 | |||
| 343 | (defcustom antlr-options-push-mark t | ||
| 344 | "*Non-nil, if inserting an option should set & push mark. | ||
| 345 | If nil, never set mark when inserting an option with command | ||
| 346 | \\[antlr-insert-option]. If t, always set mark via `push-mark'. If a | ||
| 347 | number, only set mark if point was outside the options area before and | ||
| 348 | the number of lines between point and the insert position is greater | ||
| 349 | than this value. Otherwise, only set mark if point was outside the | ||
| 350 | options area before." | ||
| 351 | :group 'antlr | ||
| 352 | :type '(radio (const :tag "No" nil) | ||
| 353 | (const :tag "Always" t) | ||
| 354 | (integer :tag "Lines between" :value 10) | ||
| 355 | (sexp :tag "If outside options" :format "%t" :value outside))) | ||
| 356 | |||
| 357 | (defcustom antlr-options-assign-string " = " | ||
| 358 | "*String containing `=' to use between option name and value. | ||
| 359 | This string is only used if the option to insert did not exist before | ||
| 360 | or if there was no `=' after it. In other words, the spacing around an | ||
| 361 | existing `=' won't be changed when changing an option value." | ||
| 362 | :group 'antlr | ||
| 363 | :type 'string) | ||
| 364 | |||
| 365 | |||
| 366 | ;;;=========================================================================== | ||
| 367 | ;;; Options: definitions | ||
| 368 | ;;;=========================================================================== | ||
| 369 | |||
| 370 | (defvar antlr-options-headings '("file" "grammar" "rule" "subrule") | ||
| 371 | "Headings for the four different option kinds. | ||
| 372 | The standard value is (\"file\" \"grammar\" \"rule\" \"subrule\"). See | ||
| 373 | `antlr-options-alists'") | ||
| 374 | |||
| 375 | (defvar antlr-options-alists | ||
| 376 | '(;; file options ---------------------------------------------------------- | ||
| 377 | (("language" antlr-language-option-extra | ||
| 378 | (20600 antlr-read-value | ||
| 379 | "Generated language: " language-as-string | ||
| 380 | (("Java") ("Cpp") ("HTML") ("Diagnostic"))) | ||
| 381 | (20700 antlr-read-value | ||
| 382 | "Generated language: " language-as-string | ||
| 383 | (("Java") ("Cpp") ("HTML") ("Diagnostic") ("Sather")))) | ||
| 384 | ("mangleLiteralPrefix" nil | ||
| 385 | (20600 antlr-read-value | ||
| 386 | "Prefix for literals (default LITERAL_): " t)) | ||
| 387 | ("namespace" antlr-c++-mode-extra | ||
| 388 | (20700 antlr-read-value | ||
| 389 | "Wrap generated C++ code in namespace: " t)) | ||
| 390 | ("namespaceStd" antlr-c++-mode-extra | ||
| 391 | (20701 antlr-read-value | ||
| 392 | "Replace ANTLR_USE_NAMESPACE(std) by: " t)) | ||
| 393 | ("namespaceAntlr" antlr-c++-mode-extra | ||
| 394 | (20701 antlr-read-value | ||
| 395 | "Replace ANTLR_USE_NAMESPACE(antlr) by: " t)) | ||
| 396 | ("genHashLines" antlr-c++-mode-extra | ||
| 397 | (20701 antlr-read-boolean | ||
| 398 | "Include #line in generated C++ code? ")) | ||
| 399 | ) | ||
| 400 | ;; grammar options -------------------------------------------------------- | ||
| 401 | (("k" nil | ||
| 402 | (20600 antlr-read-value | ||
| 403 | "Lookahead depth: ")) | ||
| 404 | ("importVocab" nil | ||
| 405 | (20600 antlr-read-value | ||
| 406 | "Import vocabulary: ")) | ||
| 407 | ("exportVocab" nil | ||
| 408 | (20600 antlr-read-value | ||
| 409 | "Export vocabulary: ")) | ||
| 410 | ("testLiterals" nil ; lexer only | ||
| 411 | (20600 antlr-read-boolean | ||
| 412 | "Test each token against literals table? ")) | ||
| 413 | ("defaultErrorHandler" nil ; not for lexer | ||
| 414 | (20600 antlr-read-boolean | ||
| 415 | "Generate default exception handler for each rule? ")) | ||
| 416 | ("codeGenMakeSwitchThreshold" nil | ||
| 417 | (20600 antlr-read-value | ||
| 418 | "Min number of alternatives for 'switch': ")) | ||
| 419 | ("codeGenBitsetTestThreshold" nil | ||
| 420 | (20600 antlr-read-value | ||
| 421 | "Min size of lookahead set for bitset test: ")) | ||
| 422 | ("analyzerDebug" nil | ||
| 423 | (20600 antlr-read-boolean | ||
| 424 | "Display debugging info during grammar analysis? ")) | ||
| 425 | ("codeGenDebug" nil | ||
| 426 | (20600 antlr-read-boolean | ||
| 427 | "Display debugging info during code generation? ")) | ||
| 428 | ("buildAST" nil ; not for lexer | ||
| 429 | (20600 antlr-read-boolean | ||
| 430 | "Use automatic AST construction/transformation? ")) | ||
| 431 | ("ASTLabelType" nil ; not for lexer | ||
| 432 | (20600 antlr-read-value | ||
| 433 | "Class of user-defined AST node: " t)) | ||
| 434 | ("charVocabulary" nil ; lexer only | ||
| 435 | (20600 nil | ||
| 436 | "Insert character vocabulary")) | ||
| 437 | ("interactive" nil | ||
| 438 | (20600 antlr-read-boolean | ||
| 439 | "Generate interactive lexer/parser? ")) | ||
| 440 | ("caseSensitive" nil ; lexer only | ||
| 441 | (20600 antlr-read-boolean | ||
| 442 | "Case significant when matching characters? ")) | ||
| 443 | ("caseSensitiveLiterals" nil ; lexer only | ||
| 444 | (20600 antlr-read-boolean | ||
| 445 | "Case significant when testing literals table? ")) | ||
| 446 | ("classHeaderSuffix" nil | ||
| 447 | (20600 nil | ||
| 448 | "Additional string for grammar class definition")) | ||
| 449 | ("filter" nil ; lexer only | ||
| 450 | (20600 antlr-read-boolean | ||
| 451 | "Skip rule (the name, true or false): " | ||
| 452 | antlr-grammar-tokens)) | ||
| 453 | ("namespace" antlr-c++-mode-extra | ||
| 454 | (20700 antlr-read-value | ||
| 455 | "Wrap generated C++ code for grammar in namespace: " t)) | ||
| 456 | ("namespaceStd" antlr-c++-mode-extra | ||
| 457 | (20701 antlr-read-value | ||
| 458 | "Replace ANTLR_USE_NAMESPACE(std) by: " t)) | ||
| 459 | ("namespaceAntlr" antlr-c++-mode-extra | ||
| 460 | (20701 antlr-read-value | ||
| 461 | "Replace ANTLR_USE_NAMESPACE(antlr) by: " t)) | ||
| 462 | ("genHashLines" antlr-c++-mode-extra | ||
| 463 | (20701 antlr-read-boolean | ||
| 464 | "Include #line in generated C++ code? ")) | ||
| 465 | ;;; ("autoTokenDef" nil ; parser only | ||
| 466 | ;;; (80000 antlr-read-boolean ; default: true | ||
| 467 | ;;; "Automatically define referenced token? ")) | ||
| 468 | ;;; ("keywordsMeltTo" nil ; parser only | ||
| 469 | ;;; (80000 antlr-read-value | ||
| 470 | ;;; "Change non-matching keywords to token type: ")) | ||
| 471 | ) | ||
| 472 | ;; rule options ---------------------------------------------------------- | ||
| 473 | (("testLiterals" nil ; lexer only | ||
| 474 | (20600 antlr-read-boolean | ||
| 475 | "Test this token against literals table? ")) | ||
| 476 | ("defaultErrorHandler" nil ; not for lexer | ||
| 477 | (20600 antlr-read-boolean | ||
| 478 | "Generate default exception handler for this rule? ")) | ||
| 479 | ("ignore" nil ; lexer only | ||
| 480 | (20600 antlr-read-value | ||
| 481 | "In this rule, ignore tokens of type: " nil | ||
| 482 | antlr-grammar-tokens)) | ||
| 483 | ("paraphrase" nil ; lexer only | ||
| 484 | (20600 antlr-read-value | ||
| 485 | "In messages, replace name of this token by: " t)) | ||
| 486 | ) | ||
| 487 | ;; subrule options ------------------------------------------------------- | ||
| 488 | (("warnWhenFollowAmbig" nil | ||
| 489 | (20600 antlr-read-boolean | ||
| 490 | "Display warnings for ambiguities with FOLLOW? ")) | ||
| 491 | ("generateAmbigWarnings" nil | ||
| 492 | (20600 antlr-read-boolean | ||
| 493 | "Display warnings for ambiguities? ")) | ||
| 494 | ("greedy" nil | ||
| 495 | (20700 antlr-read-boolean | ||
| 496 | "Make this optional/loop subrule greedy? ")) | ||
| 497 | )) | ||
| 498 | "Definitions for Antlr's options of all four different kinds. | ||
| 499 | |||
| 500 | The value looks like \(FILE GRAMMAR RULE SUBRULE) where each FILE, | ||
| 501 | GRAMMAR, RULE, and SUBRULE is a list of option definitions of the | ||
| 502 | corresponding kind, i.e., looks like \(OPTION-DEF...). | ||
| 503 | |||
| 504 | Each OPTION-DEF looks like \(OPTION-NAME EXTRA-FN VALUE-SPEC...) which | ||
| 505 | defines a file/grammar/rule/subrule option with name OPTION-NAME. The | ||
| 506 | OPTION-NAMEs are used for the creation of the \"Insert XXX Option\" | ||
| 507 | submenus, see `antlr-options-use-submenus', and to allow to insert the | ||
| 508 | option name with completion when using \\[antlr-insert-option]. | ||
| 509 | |||
| 510 | If EXTRA-FN is a function, it is called at different phases of the | ||
| 511 | insertion with arguments \(PHASE OPTION-NAME). PHASE can have the | ||
| 512 | values `before-input' or `after-insertion', additional phases might be | ||
| 513 | defined in future versions of this mode. The phase `before-input' | ||
| 514 | occurs before the user is asked to insert a value. The phase | ||
| 515 | `after-insertion' occurs after the option value has been inserted. | ||
| 516 | EXTRA-FN might be called with additional arguments in future versions of | ||
| 517 | this mode. | ||
| 518 | |||
| 519 | Each specification VALUE-SPEC looks like \(VERSION READ-FN ARG...). The | ||
| 520 | last VALUE-SPEC in an OPTION-DEF whose VERSION is smaller or equal to | ||
| 521 | `antlr-tool-version' specifies how the user is asked for the value of | ||
| 522 | the option. | ||
| 523 | |||
| 524 | If READ-FN is nil, the only ARG is a string which is printed at the echo | ||
| 525 | area to guide the user what to insert at point. Otherwise, READ-FN is | ||
| 526 | called with arguments \(INIT-VALUE ARG...) to get the new value of the | ||
| 527 | option. INIT-VALUE is the old value of the option or nil. | ||
| 528 | |||
| 529 | The standard value contains the following functions as READ-FN: | ||
| 530 | `antlr-read-value' with ARGs = \(PROMPT AS-STRING TABLE) which reads a | ||
| 531 | general value, or `antlr-read-boolean' with ARGs = \(PROMPT TABLE) which | ||
| 532 | reads a boolean value or a member of TABLE. PROMPT is the prompt when | ||
| 533 | asking for a new value. If non-nil, TABLE is a table for completion or | ||
| 534 | a function evaluating to such a table. The return value is quoted iff | ||
| 535 | AS-STRING is non-nil and is either t or a symbol which is a member of | ||
| 536 | `antlr-options-style'.") | ||
| 245 | 537 | ||
| 246 | 538 | ||
| 247 | ;;;=========================================================================== | 539 | ;;;=========================================================================== |
| @@ -265,7 +557,7 @@ Otherwise, it saves all modified buffers before running without asking." | |||
| 265 | '("\n" ("GENS" "GENS%d" " \\\n\t") "$(ANTLR)") | 557 | '("\n" ("GENS" "GENS%d" " \\\n\t") "$(ANTLR)") |
| 266 | "*Variable to specify the appearance of the generated makefile rules. | 558 | "*Variable to specify the appearance of the generated makefile rules. |
| 267 | This variable influences the output of \\[antlr-show-makefile-rules]. | 559 | This variable influences the output of \\[antlr-show-makefile-rules]. |
| 268 | It looks like (RULE-SEP GEN-VAR-SPEC COMMAND). | 560 | It looks like \(RULE-SEP GEN-VAR-SPEC COMMAND). |
| 269 | 561 | ||
| 270 | RULE-SEP is the string to separate different makefile rules. COMMAND is | 562 | RULE-SEP is the string to separate different makefile rules. COMMAND is |
| 271 | a string with the command which runs the Antlr tool, it should include | 563 | a string with the command which runs the Antlr tool, it should include |
| @@ -273,7 +565,7 @@ all options except the option \"-glib\" which is automatically added | |||
| 273 | if necessary. | 565 | if necessary. |
| 274 | 566 | ||
| 275 | If GEN-VAR-SPEC is nil, each target directly consists of a list of | 567 | If GEN-VAR-SPEC is nil, each target directly consists of a list of |
| 276 | files. If GEN-VAR-SPEC looks like (GEN-VAR GEN-VAR-FORMAT GEN-SEP), a | 568 | files. If GEN-VAR-SPEC looks like \(GEN-VAR GEN-VAR-FORMAT GEN-SEP), a |
| 277 | Makefile variable is created for each rule target. | 569 | Makefile variable is created for each rule target. |
| 278 | 570 | ||
| 279 | Then, GEN-VAR is a string with the name of the variable which contains | 571 | Then, GEN-VAR is a string with the name of the variable which contains |
| @@ -295,7 +587,7 @@ COUNT starts with 1. GEN-SEP is used to separate long variable values." | |||
| 295 | (c++-mode ("%sTokenTypes.hpp") ("%s.cpp" "%s.hpp"))) | 587 | (c++-mode ("%sTokenTypes.hpp") ("%s.cpp" "%s.hpp"))) |
| 296 | "Language dependent formats which specify generated files. | 588 | "Language dependent formats which specify generated files. |
| 297 | Each element in this list looks looks like | 589 | Each element in this list looks looks like |
| 298 | (MAJOR-MODE (VOCAB-FILE-FORMAT...) (CLASS-FILE-FORMAT...)). | 590 | \(MAJOR-MODE (VOCAB-FILE-FORMAT...) (CLASS-FILE-FORMAT...)). |
| 299 | 591 | ||
| 300 | The element whose MAJOR-MODE is equal to `antlr-language' is used to | 592 | The element whose MAJOR-MODE is equal to `antlr-language' is used to |
| 301 | specify the generated files which are language dependent. See variable | 593 | specify the generated files which are language dependent. See variable |
| @@ -308,7 +600,7 @@ CLASS/%s the generated file for each grammar class CLASS.") | |||
| 308 | 600 | ||
| 309 | (defvar antlr-special-file-formats '("%sTokenTypes.txt" "expanded%s.g") | 601 | (defvar antlr-special-file-formats '("%sTokenTypes.txt" "expanded%s.g") |
| 310 | "Language independent formats which specify generated files. | 602 | "Language independent formats which specify generated files. |
| 311 | The value looks like (VOCAB-FILE-FORMAT EXPANDED-GRAMMAR-FORMAT). | 603 | The value looks like \(VOCAB-FILE-FORMAT EXPANDED-GRAMMAR-FORMAT). |
| 312 | 604 | ||
| 313 | VOCAB-FILE-FORMAT is a format string, it specifies with substitution | 605 | VOCAB-FILE-FORMAT is a format string, it specifies with substitution |
| 314 | VOCAB/%s the generated or input file for each export or import | 606 | VOCAB/%s the generated or input file for each export or import |
| @@ -322,7 +614,7 @@ formats.") | |||
| 322 | 614 | ||
| 323 | (defvar antlr-unknown-file-formats '("?%s?.g" "?%s?") | 615 | (defvar antlr-unknown-file-formats '("?%s?.g" "?%s?") |
| 324 | "*Formats which specify the names of unknown files. | 616 | "*Formats which specify the names of unknown files. |
| 325 | The value looks like (SUPER-GRAMMAR-FILE-FORMAT SUPER-EVOCAB-FORMAT). | 617 | The value looks like \(SUPER-GRAMMAR-FILE-FORMAT SUPER-EVOCAB-FORMAT). |
| 326 | 618 | ||
| 327 | SUPER-GRAMMAR-FORMAT is a format string, it specifies with substitution | 619 | SUPER-GRAMMAR-FORMAT is a format string, it specifies with substitution |
| 328 | SUPER/%s the name of a grammar file for Antlr's option \"-glib\" if no | 620 | SUPER/%s the name of a grammar file for Antlr's option \"-glib\" if no |
| @@ -376,46 +668,67 @@ imenu." | |||
| 376 | (define-key map "\C-c\C-c" 'comment-region) | 668 | (define-key map "\C-c\C-c" 'comment-region) |
| 377 | (define-key map "\C-c\C-v" 'antlr-hide-actions) | 669 | (define-key map "\C-c\C-v" 'antlr-hide-actions) |
| 378 | (define-key map "\C-c\C-r" 'antlr-run-tool) | 670 | (define-key map "\C-c\C-r" 'antlr-run-tool) |
| 671 | (define-key map "\C-c\C-o" 'antlr-insert-option) | ||
| 379 | ;; I'm too lazy to define my own: | 672 | ;; I'm too lazy to define my own: |
| 380 | (define-key map "\ea" 'c-beginning-of-statement) | 673 | (define-key map "\ea" 'c-beginning-of-statement) |
| 381 | (define-key map "\ee" 'c-end-of-statement) | 674 | (define-key map "\ee" 'c-end-of-statement) |
| 675 | ;; electric keys: | ||
| 676 | (define-key map ":" 'antlr-electric-character) | ||
| 677 | (define-key map ";" 'antlr-electric-character) | ||
| 678 | (define-key map "|" 'antlr-electric-character) | ||
| 679 | (define-key map "&" 'antlr-electric-character) | ||
| 680 | (define-key map "(" 'antlr-electric-character) | ||
| 681 | (define-key map ")" 'antlr-electric-character) | ||
| 682 | (define-key map "{" 'antlr-electric-character) | ||
| 683 | (define-key map "}" 'antlr-electric-character) | ||
| 382 | map) | 684 | map) |
| 383 | "Keymap used in `antlr-mode' buffers.") | 685 | "Keymap used in `antlr-mode' buffers.") |
| 384 | 686 | ||
| 385 | (easy-menu-define antlr-mode-menu | 687 | (easy-menu-define antlr-mode-menu antlr-mode-map |
| 386 | antlr-mode-map | 688 | "Major mode menu." |
| 387 | "Major mode menu." | 689 | `("Antlr" |
| 388 | '("Antlr" | 690 | ,@(if (and antlr-options-use-submenus |
| 389 | ["Indent Line" antlr-indent-command | 691 | (boundp 'emacs-major-version) |
| 390 | :active (not buffer-read-only)] | 692 | (or (featurep 'xemacs) (>= emacs-major-version 21))) |
| 391 | ["Indent for Comment" indent-for-comment | 693 | `(("Insert File Option" |
| 392 | :active (not buffer-read-only)] | 694 | :filter ,(lambda (x) (antlr-options-menu-filter 1 x))) |
| 393 | ["Comment Out Region" comment-region | 695 | ("Insert Grammar Option" |
| 394 | :active (and (not buffer-read-only) | 696 | :filter ,(lambda (x) (antlr-options-menu-filter 2 x))) |
| 395 | (c-region-is-active-p))] | 697 | ("Insert Rule Option" |
| 396 | ["Uncomment Region" | 698 | :filter ,(lambda (x) (antlr-options-menu-filter 3 x))) |
| 397 | (comment-region (region-beginning) (region-end) '(4)) | 699 | ("Insert Subrule Option" |
| 398 | :active (and (not buffer-read-only) | 700 | :filter ,(lambda (x) (antlr-options-menu-filter 4 x))) |
| 399 | (c-region-is-active-p))] | 701 | "---") |
| 400 | "---" | 702 | '(["Insert Option" antlr-insert-option |
| 401 | ["Backward Rule" antlr-beginning-of-rule t] | 703 | :active (not buffer-read-only)])) |
| 402 | ["Forward Rule" antlr-end-of-rule t] | 704 | ("Forward/Backward" |
| 403 | ["Start of Rule Body" antlr-beginning-of-body | 705 | ["Backward Rule" antlr-beginning-of-rule t] |
| 404 | :active (antlr-inside-rule-p)] | 706 | ["Forward Rule" antlr-end-of-rule t] |
| 405 | ["End of Rule Body" antlr-end-of-body | 707 | ["Start of Rule Body" antlr-beginning-of-body |
| 406 | :active (antlr-inside-rule-p)] | 708 | :active (antlr-inside-rule-p)] |
| 407 | "---" | 709 | ["End of Rule Body" antlr-end-of-body |
| 408 | ["Backward Statement" c-beginning-of-statement t] | 710 | :active (antlr-inside-rule-p)] |
| 409 | ["Forward Statement" c-end-of-statement t] | 711 | "---" |
| 410 | ["Backward Into Nomencl." c-backward-into-nomenclature t] | 712 | ["Backward Statement" c-beginning-of-statement t] |
| 411 | ["Forward Into Nomencl." c-forward-into-nomenclature t] | 713 | ["Forward Statement" c-end-of-statement t] |
| 412 | "---" | 714 | ["Backward Into Nomencl." c-backward-into-nomenclature t] |
| 413 | ["Hide Actions (incl. Args)" antlr-hide-actions t] | 715 | ["Forward Into Nomencl." c-forward-into-nomenclature t]) |
| 414 | ["Hide Actions (excl. Args)" (antlr-hide-actions 2) t] | 716 | ["Indent Region" indent-region |
| 415 | ["Unhide All Actions" (antlr-hide-actions 0) t] | 717 | :active (and (not buffer-read-only) (c-region-is-active-p))] |
| 416 | "---" | 718 | ["Comment Out Region" comment-region |
| 417 | ["Run Tool on Grammar" antlr-run-tool t] | 719 | :active (and (not buffer-read-only) (c-region-is-active-p))] |
| 418 | ["Show Makefile Rules" antlr-show-makefile-rules t])) | 720 | ["Uncomment Region" |
| 721 | (comment-region (region-beginning) (region-end) '(4)) | ||
| 722 | :active (and (not buffer-read-only) (c-region-is-active-p))] | ||
| 723 | "---" | ||
| 724 | ["Hide Actions (incl. Args)" antlr-hide-actions t] | ||
| 725 | ["Hide Actions (excl. Args)" (antlr-hide-actions 2) t] | ||
| 726 | ["Unhide All Actions" (antlr-hide-actions 0) t] | ||
| 727 | "---" | ||
| 728 | ["Run Tool on Grammar" antlr-run-tool t] | ||
| 729 | ["Show Makefile Rules" antlr-show-makefile-rules t] | ||
| 730 | "---" | ||
| 731 | ["Customize Antlr" (customize-group 'antlr) t])) | ||
| 419 | 732 | ||
| 420 | 733 | ||
| 421 | ;;;=========================================================================== | 734 | ;;;=========================================================================== |
| @@ -432,24 +745,24 @@ fontification, see `antlr-font-lock-keywords-alist'. | |||
| 432 | 745 | ||
| 433 | While calculating the decoration level for actions, `major-mode' is | 746 | While calculating the decoration level for actions, `major-mode' is |
| 434 | bound to `antlr-language'. For example, with value | 747 | bound to `antlr-language'. For example, with value |
| 435 | ((java-mode . 2) (c++-mode . 0)) | 748 | \((java-mode \. 2) (c++-mode \. 0)) |
| 436 | Java actions are fontified with level 2 and C++ actions are not | 749 | Java actions are fontified with level 2 and C++ actions are not |
| 437 | fontified at all." | 750 | fontified at all." |
| 438 | :type '(choice (const :tag "none" none) | 751 | :type '(choice (const :tag "None" none) |
| 439 | (const :tag "inherit" inherit) | 752 | (const :tag "Inherit" inherit) |
| 440 | (const :tag "default" nil) | 753 | (const :tag "Default" nil) |
| 441 | (const :tag "maximum" t) | 754 | (const :tag "Maximum" t) |
| 442 | (integer :tag "level" 1) | 755 | (integer :tag "Level" 1) |
| 443 | (repeat :menu-tag "mode specific" :tag "mode specific" | 756 | (repeat :menu-tag "Mode specific" :tag "Mode specific" |
| 444 | :value ((t . t)) | 757 | :value ((t . t)) |
| 445 | (cons :tag "Instance" | 758 | (cons :tag "Instance" |
| 446 | (radio :tag "Mode" | 759 | (radio :tag "Mode" |
| 447 | (const :tag "all" t) | 760 | (const :tag "All" t) |
| 448 | (symbol :tag "name")) | 761 | (symbol :tag "Name")) |
| 449 | (radio :tag "Decoration" | 762 | (radio :tag "Decoration" |
| 450 | (const :tag "default" nil) | 763 | (const :tag "Default" nil) |
| 451 | (const :tag "maximum" t) | 764 | (const :tag "Maximum" t) |
| 452 | (integer :tag "level" 1)))))) | 765 | (integer :tag "Level" 1)))))) |
| 453 | 766 | ||
| 454 | (defconst antlr-no-action-keywords nil | 767 | (defconst antlr-no-action-keywords nil |
| 455 | ;; Using nil directly won't work (would use highest level, see | 768 | ;; Using nil directly won't work (would use highest level, see |
| @@ -469,19 +782,31 @@ Do not change the value of this constant.") | |||
| 469 | c++-font-lock-keywords-3)) | 782 | c++-font-lock-keywords-3)) |
| 470 | "List of font-lock keywords for actions in the grammar. | 783 | "List of font-lock keywords for actions in the grammar. |
| 471 | Each element in this list looks like | 784 | Each element in this list looks like |
| 472 | (MAJOR-MODE KEYWORD...) | 785 | \(MAJOR-MODE KEYWORD...) |
| 473 | 786 | ||
| 474 | If `antlr-language' is equal to MAJOR-MODE, the KEYWORDs are the | 787 | If `antlr-language' is equal to MAJOR-MODE, the KEYWORDs are the |
| 475 | font-lock keywords according to `font-lock-defaults' used for the code | 788 | font-lock keywords according to `font-lock-defaults' used for the code |
| 476 | in the grammar's actions and semantic predicates, see | 789 | in the grammar's actions and semantic predicates, see |
| 477 | `antlr-font-lock-maximum-decoration'.") | 790 | `antlr-font-lock-maximum-decoration'.") |
| 478 | 791 | ||
| 792 | (defvar antlr-font-lock-default-face 'antlr-font-lock-default-face) | ||
| 793 | (defface antlr-font-lock-default-face nil | ||
| 794 | "Face to prevent strings from language dependent highlighting. | ||
| 795 | Do not change." | ||
| 796 | :group 'antlr) | ||
| 797 | |||
| 479 | (defvar antlr-font-lock-keyword-face 'antlr-font-lock-keyword-face) | 798 | (defvar antlr-font-lock-keyword-face 'antlr-font-lock-keyword-face) |
| 480 | (defface antlr-font-lock-keyword-face | 799 | (defface antlr-font-lock-keyword-face |
| 481 | '((((class color) (background light)) (:foreground "black" :bold t))) | 800 | '((((class color) (background light)) (:foreground "black" :bold t))) |
| 482 | "ANTLR keywords." | 801 | "ANTLR keywords." |
| 483 | :group 'antlr) | 802 | :group 'antlr) |
| 484 | 803 | ||
| 804 | (defvar antlr-font-lock-syntax-face 'antlr-font-lock-keyword-face) | ||
| 805 | (defface antlr-font-lock-syntax-face | ||
| 806 | '((((class color) (background light)) (:foreground "black" :bold t))) | ||
| 807 | "ANTLR syntax symbols like :, |, (, ), ...." | ||
| 808 | :group 'antlr) | ||
| 809 | |||
| 485 | (defvar antlr-font-lock-ruledef-face 'antlr-font-lock-ruledef-face) | 810 | (defvar antlr-font-lock-ruledef-face 'antlr-font-lock-ruledef-face) |
| 486 | (defface antlr-font-lock-ruledef-face | 811 | (defface antlr-font-lock-ruledef-face |
| 487 | '((((class color) (background light)) (:foreground "blue" :bold t))) | 812 | '((((class color) (background light)) (:foreground "blue" :bold t))) |
| @@ -509,9 +834,24 @@ in the grammar's actions and semantic predicates, see | |||
| 509 | (defvar antlr-font-lock-literal-face 'antlr-font-lock-literal-face) | 834 | (defvar antlr-font-lock-literal-face 'antlr-font-lock-literal-face) |
| 510 | (defface antlr-font-lock-literal-face | 835 | (defface antlr-font-lock-literal-face |
| 511 | '((((class color) (background light)) (:foreground "brown4" :bold t))) | 836 | '((((class color) (background light)) (:foreground "brown4" :bold t))) |
| 512 | "ANTLR literal tokens consisting merely of letter-like characters." | 837 | "ANTLR special literal tokens. |
| 838 | It is used to highlight strings matched by the first regexp group of | ||
| 839 | `antlr-font-lock-literal-regexp'." | ||
| 513 | :group 'antlr) | 840 | :group 'antlr) |
| 514 | 841 | ||
| 842 | (defcustom antlr-font-lock-literal-regexp "\"\\(\\sw\\(\\sw\\|-\\)*\\)\"" | ||
| 843 | "Regexp matching literals with special syntax highlighting, or nil. | ||
| 844 | If nil, there is no special syntax highlighting for some literals. | ||
| 845 | Otherwise, it should be a regular expression which must contain a regexp | ||
| 846 | group. The string matched by the first group is highlighted with | ||
| 847 | `antlr-font-lock-literal-face'." | ||
| 848 | :group 'antlr | ||
| 849 | :type '(choice (const :tag "None" nil) regexp)) | ||
| 850 | |||
| 851 | (defvar antlr-class-header-regexp | ||
| 852 | "\\(class\\)[ \t]+\\([A-Za-z\300-\326\330-\337]\\sw*\\)[ \t]+\\(extends\\)[ \t]+\\([A-Za-z\300-\326\330-\337]\\sw*\\)[ \t]*;" | ||
| 853 | "Regexp matching class headers.") | ||
| 854 | |||
| 515 | (defvar antlr-font-lock-additional-keywords | 855 | (defvar antlr-font-lock-additional-keywords |
| 516 | `((antlr-invalidate-context-cache) | 856 | `((antlr-invalidate-context-cache) |
| 517 | ("\\$setType[ \t]*(\\([A-Za-z\300-\326\330-\337]\\sw*\\))" | 857 | ("\\$setType[ \t]*(\\([A-Za-z\300-\326\330-\337]\\sw*\\))" |
| @@ -519,13 +859,12 @@ in the grammar's actions and semantic predicates, see | |||
| 519 | ("\\$\\sw+" (0 font-lock-keyword-face)) | 859 | ("\\$\\sw+" (0 font-lock-keyword-face)) |
| 520 | ;; the tokens are already fontified as string/docstrings: | 860 | ;; the tokens are already fontified as string/docstrings: |
| 521 | (,(lambda (limit) | 861 | (,(lambda (limit) |
| 522 | (antlr-re-search-forward "\"\\(\\sw\\(\\sw\\|-\\)*\\)\"" limit)) | 862 | (if antlr-font-lock-literal-regexp |
| 863 | (antlr-re-search-forward antlr-font-lock-literal-regexp limit))) | ||
| 523 | (1 antlr-font-lock-literal-face t) | 864 | (1 antlr-font-lock-literal-face t) |
| 524 | ,@(and (string-match "XEmacs" emacs-version) | 865 | ,@(and (featurep 'xemacs) '((0 nil)))) ; XEmacs bug workaround |
| 525 | '((0 nil)))) ; XEmacs bug workaround | ||
| 526 | (,(lambda (limit) | 866 | (,(lambda (limit) |
| 527 | (antlr-re-search-forward | 867 | (antlr-re-search-forward antlr-class-header-regexp limit)) |
| 528 | "^\\(class\\)[ \t]+\\([A-Za-z\300-\326\330-\337]\\sw*\\)[ \t]+\\(extends\\)[ \t]+\\([A-Za-z\300-\326\330-\337]\\sw*\\)[ \t]*;" limit)) | ||
| 529 | (1 antlr-font-lock-keyword-face) | 868 | (1 antlr-font-lock-keyword-face) |
| 530 | (2 antlr-font-lock-ruledef-face) | 869 | (2 antlr-font-lock-ruledef-face) |
| 531 | (3 antlr-font-lock-keyword-face) | 870 | (3 antlr-font-lock-keyword-face) |
| @@ -539,34 +878,40 @@ in the grammar's actions and semantic predicates, see | |||
| 539 | (1 antlr-font-lock-keyword-face)) | 878 | (1 antlr-font-lock-keyword-face)) |
| 540 | (,(lambda (limit) | 879 | (,(lambda (limit) |
| 541 | (antlr-re-search-forward | 880 | (antlr-re-search-forward |
| 542 | "^\\(private\\|public\\|protected\\)\\>\\([ \t]+\\(\\sw+\\)\\)?" | 881 | "^\\(private\\|public\\|protected\\)\\>[ \t]*\\(\\(\\sw+[ \t]*\\(:\\)?\\)\\)?" |
| 543 | limit)) | 882 | limit)) |
| 544 | (1 font-lock-type-face) ; not XEmacs' java level-3 fruit salad | 883 | (1 font-lock-type-face) ; not XEmacs' java level-3 fruit salad |
| 545 | (3 (if (antlr-upcase-p (char-after (match-beginning 3))) | 884 | (3 (if (antlr-upcase-p (char-after (match-beginning 3))) |
| 546 | 'antlr-font-lock-tokendef-face | 885 | 'antlr-font-lock-tokendef-face |
| 547 | 'antlr-font-lock-ruledef-face) nil t)) | 886 | 'antlr-font-lock-ruledef-face) nil t) |
| 887 | (4 antlr-font-lock-syntax-face nil t)) | ||
| 548 | (,(lambda (limit) | 888 | (,(lambda (limit) |
| 549 | (antlr-re-search-forward "^\\sw+" limit)) | 889 | (antlr-re-search-forward "^\\(\\sw+\\)[ \t]*\\(:\\)?" limit)) |
| 550 | (0 (if (antlr-upcase-p (char-after (match-beginning 0))) | 890 | (1 (if (antlr-upcase-p (char-after (match-beginning 0))) |
| 551 | 'antlr-font-lock-tokendef-face | 891 | 'antlr-font-lock-tokendef-face |
| 552 | 'antlr-font-lock-ruledef-face) nil t)) | 892 | 'antlr-font-lock-ruledef-face) nil t) |
| 893 | (2 antlr-font-lock-syntax-face nil t)) | ||
| 553 | (,(lambda (limit) | 894 | (,(lambda (limit) |
| 554 | ;; not only before a rule ref, also before a literal | 895 | ;; v:ruleref and v:"literal" is allowed... |
| 555 | (antlr-re-search-forward "\\<\\(\\sw+\\)[ \t]*:" limit)) | 896 | (antlr-re-search-forward "\\(\\sw+\\)[ \t]*\\([=:]\\)?" limit)) |
| 556 | (1 font-lock-variable-name-face)) | 897 | (1 (if (match-beginning 2) |
| 898 | (if (eq (char-after (match-beginning 2)) ?=) | ||
| 899 | 'antlr-font-lock-default-face | ||
| 900 | 'font-lock-variable-name-face) | ||
| 901 | (if (antlr-upcase-p (char-after (match-beginning 1))) | ||
| 902 | 'antlr-font-lock-tokenref-face | ||
| 903 | 'antlr-font-lock-ruleref-face))) | ||
| 904 | (2 antlr-font-lock-default-face nil t)) | ||
| 557 | (,(lambda (limit) | 905 | (,(lambda (limit) |
| 558 | (antlr-re-search-forward "\\<\\(\\sw+[ \t]*=[ \t]*\\)?\\(\\sw+[ \t]*:[ \t]*\\)?\\(\\sw+\\)" limit)) | 906 | (antlr-re-search-forward "[|&:;(]\\|)\\([*+?]\\|=>\\)?" limit)) |
| 559 | ;;(1 antlr-font-lock-default-face nil t) ; fool java-font-lock-keywords | 907 | (0 'antlr-font-lock-syntax-face))) |
| 560 | (3 (if (antlr-upcase-p (char-after (match-beginning 3))) | ||
| 561 | 'antlr-font-lock-tokenref-face | ||
| 562 | 'antlr-font-lock-ruleref-face)))) | ||
| 563 | "Font-lock keywords for ANTLR's normal grammar code. | 908 | "Font-lock keywords for ANTLR's normal grammar code. |
| 564 | See `antlr-font-lock-keywords-alist' for the keywords of actions.") | 909 | See `antlr-font-lock-keywords-alist' for the keywords of actions.") |
| 565 | 910 | ||
| 566 | (defvar antlr-font-lock-defaults | 911 | (defvar antlr-font-lock-defaults |
| 567 | '(antlr-font-lock-keywords | 912 | '(antlr-font-lock-keywords |
| 568 | nil nil ((?_ . "w") (?\( . ".") (?\) . ".")) beginning-of-defun) | 913 | nil nil ((?_ . "w") (?\( . ".") (?\) . ".")) beginning-of-defun) |
| 569 | "Font-lock defaults used for ANTLR syntax coloring. | 914 | "Font-lock defaults used for ANTLR syntax highlighting. |
| 570 | The SYNTAX-ALIST element is also used to initialize | 915 | The SYNTAX-ALIST element is also used to initialize |
| 571 | `antlr-action-syntax-table'.") | 916 | `antlr-action-syntax-table'.") |
| 572 | 917 | ||
| @@ -601,6 +946,7 @@ not to confuse their context_cache.") | |||
| 601 | ;;;;########################################################################## | 946 | ;;;;########################################################################## |
| 602 | 947 | ||
| 603 | 948 | ||
| 949 | |||
| 604 | ;;;=========================================================================== | 950 | ;;;=========================================================================== |
| 605 | ;;; Syntax functions -- Emacs vs XEmacs dependent | 951 | ;;; Syntax functions -- Emacs vs XEmacs dependent |
| 606 | ;;;=========================================================================== | 952 | ;;;=========================================================================== |
| @@ -618,14 +964,25 @@ not to confuse their context_cache.") | |||
| 618 | (defun antlr-scan-sexps-internal (from count &optional dummy no-error) | 964 | (defun antlr-scan-sexps-internal (from count &optional dummy no-error) |
| 619 | ;; checkdoc-params: (from count dummy) | 965 | ;; checkdoc-params: (from count dummy) |
| 620 | "Like `scan-sexps' but with additional arguments. | 966 | "Like `scan-sexps' but with additional arguments. |
| 621 | When optional arg NO-ERROR is non-nil, `scan-sexps' will return nil | 967 | When optional arg NO-ERROR is non-nil, `antlr-scan-sexps-internal' will |
| 622 | instead of signaling an error." | 968 | return nil instead of signaling an error." |
| 623 | (if no-error | 969 | (if no-error |
| 624 | (condition-case nil | 970 | (condition-case nil |
| 625 | (scan-sexps from count) | 971 | (scan-sexps from count) |
| 626 | (t nil)) | 972 | (error nil)) |
| 627 | (scan-sexps from count))) | 973 | (scan-sexps from count))) |
| 628 | 974 | ||
| 975 | (defun antlr-scan-lists-internal (from count depth &optional dummy no-error) | ||
| 976 | ;; checkdoc-params: (from count depth dummy) | ||
| 977 | "Like `scan-lists' but with additional arguments. | ||
| 978 | When optional arg NO-ERROR is non-nil, `antlr-scan-lists-internal' will | ||
| 979 | return nil instead of signaling an error." | ||
| 980 | (if no-error | ||
| 981 | (condition-case nil | ||
| 982 | (scan-lists from count depth) | ||
| 983 | (error nil)) | ||
| 984 | (scan-lists from count depth))) | ||
| 985 | |||
| 629 | (defun antlr-xemacs-bug-workaround (&rest dummies) | 986 | (defun antlr-xemacs-bug-workaround (&rest dummies) |
| 630 | ;; checkdoc-params: (dummies) | 987 | ;; checkdoc-params: (dummies) |
| 631 | "Invalidate context_cache for syntactical context information." | 988 | "Invalidate context_cache for syntactical context information." |
| @@ -738,8 +1095,13 @@ See `antlr-font-lock-additional-keywords', `antlr-language' and | |||
| 738 | ;;; imenu support | 1095 | ;;; imenu support |
| 739 | ;;;=========================================================================== | 1096 | ;;;=========================================================================== |
| 740 | 1097 | ||
| 741 | (defun antlr-imenu-create-index-function () | 1098 | (defun antlr-grammar-tokens () |
| 742 | "Return imenu index-alist for ANTLR grammar files." | 1099 | "Return alist for tokens defined in current buffer." |
| 1100 | (save-excursion (antlr-imenu-create-index-function t))) | ||
| 1101 | |||
| 1102 | (defun antlr-imenu-create-index-function (&optional tokenrefs-only) | ||
| 1103 | "Return imenu index-alist for ANTLR grammar files. | ||
| 1104 | IF TOKENREFS-ONLY is non-nil, just return alist with tokenref names." | ||
| 743 | (let ((items nil) | 1105 | (let ((items nil) |
| 744 | (classes nil) | 1106 | (classes nil) |
| 745 | (semi (point-max))) | 1107 | (semi (point-max))) |
| @@ -751,24 +1113,29 @@ See `antlr-font-lock-additional-keywords', `antlr-language' and | |||
| 751 | ;; editing (you are more likely to add functions to the end of the file). | 1113 | ;; editing (you are more likely to add functions to the end of the file). |
| 752 | (while semi | 1114 | (while semi |
| 753 | (goto-char semi) | 1115 | (goto-char semi) |
| 754 | (if (setq semi (antlr-search-backward ";")) | 1116 | (setq semi (antlr-search-backward ";")) |
| 1117 | (if semi | ||
| 755 | (progn (forward-char) (antlr-skip-exception-part t)) | 1118 | (progn (forward-char) (antlr-skip-exception-part t)) |
| 756 | (antlr-skip-file-prelude t)) | 1119 | (antlr-skip-file-prelude t)) |
| 757 | (if (looking-at "{") (antlr-skip-sexps 1)) | 1120 | (if (looking-at "{") (antlr-skip-sexps 1)) |
| 758 | (if (looking-at "class[ \t]+\\([A-Za-z\300-\326\330-\337]\\sw*\\)[ \t]+extends[ \t]+\\([A-Za-z\300-\326\330-\337]\\sw*\\)[ \t]*;") | 1121 | (if (looking-at antlr-class-header-regexp) |
| 759 | (push (cons (match-string 1) | 1122 | (or tokenrefs-only |
| 760 | (if imenu-use-markers | 1123 | (push (cons (match-string 2) |
| 761 | (copy-marker (match-beginning 1)) | 1124 | (if imenu-use-markers |
| 762 | (match-beginning 1))) | 1125 | (copy-marker (match-beginning 2)) |
| 763 | classes) | 1126 | (match-beginning 2))) |
| 1127 | classes)) | ||
| 764 | (if (looking-at "p\\(ublic\\|rotected\\|rivate\\)") | 1128 | (if (looking-at "p\\(ublic\\|rotected\\|rivate\\)") |
| 765 | (antlr-skip-sexps 1)) | 1129 | (antlr-skip-sexps 1)) |
| 766 | (when (looking-at "\\sw+") | 1130 | (when (looking-at "\\sw+") |
| 767 | (push (cons (match-string 0) | 1131 | (if tokenrefs-only |
| 768 | (if imenu-use-markers | 1132 | (if (antlr-upcase-p (char-after (point))) |
| 769 | (copy-marker (match-beginning 0)) | 1133 | (push (list (match-string 0)) items)) |
| 770 | (match-beginning 0))) | 1134 | (push (cons (match-string 0) |
| 771 | items))))) | 1135 | (if imenu-use-markers |
| 1136 | (copy-marker (match-beginning 0)) | ||
| 1137 | (match-beginning 0))) | ||
| 1138 | items)))))) | ||
| 772 | (if classes (cons (cons "Classes" classes) items) items))) | 1139 | (if classes (cons (cons "Classes" classes) items) items))) |
| 773 | 1140 | ||
| 774 | 1141 | ||
| @@ -794,7 +1161,8 @@ part." | |||
| 794 | (if (looking-at "{") (setq pos (antlr-skip-sexps 1))) | 1161 | (if (looking-at "{") (setq pos (antlr-skip-sexps 1))) |
| 795 | (while (looking-at "exception\\>") | 1162 | (while (looking-at "exception\\>") |
| 796 | (setq pos (antlr-skip-sexps 1)) | 1163 | (setq pos (antlr-skip-sexps 1)) |
| 797 | (if (looking-at "\\[") (setq pos (antlr-skip-sexps 1))) | 1164 | (when (looking-at "\\[") |
| 1165 | (setq pos (antlr-skip-sexps 1))) | ||
| 798 | (while (looking-at "catch\\>") | 1166 | (while (looking-at "catch\\>") |
| 799 | (setq pos (antlr-skip-sexps 3))))) | 1167 | (setq pos (antlr-skip-sexps 3))))) |
| 800 | (or skip-comment (goto-char pos)))) | 1168 | (or skip-comment (goto-char pos)))) |
| @@ -802,16 +1170,22 @@ part." | |||
| 802 | (defun antlr-skip-file-prelude (skip-comment) | 1170 | (defun antlr-skip-file-prelude (skip-comment) |
| 803 | "Skip the file prelude: the header and file options. | 1171 | "Skip the file prelude: the header and file options. |
| 804 | If SKIP-COMMENT is non-nil, also skip the comment after that part. | 1172 | If SKIP-COMMENT is non-nil, also skip the comment after that part. |
| 805 | Return the start position of the file prelude." | 1173 | Return the start position of the file prelude. |
| 1174 | |||
| 1175 | Hack: if SKIP-COMMENT is `header-only' only skip header and return | ||
| 1176 | position before the comment after the header." | ||
| 806 | (let* ((pos (point)) | 1177 | (let* ((pos (point)) |
| 807 | (pos0 pos)) | 1178 | (pos0 pos)) |
| 808 | (c-forward-syntactic-ws) | 1179 | (c-forward-syntactic-ws) |
| 809 | (if skip-comment (setq pos0 (point))) | 1180 | (if skip-comment (setq pos0 (point))) |
| 810 | (while (looking-at "header\\>[ \t]*\\(\"\\)?") | 1181 | (while (looking-at "header\\>[ \t]*\\(\"\\)?") |
| 811 | (setq pos (antlr-skip-sexps (if (match-beginning 1) 3 2)))) | 1182 | (setq pos (antlr-skip-sexps (if (match-beginning 1) 3 2)))) |
| 812 | (if (looking-at "options\\>") (setq pos (antlr-skip-sexps 2))) | 1183 | (if (eq skip-comment 'header-only) ; a hack... |
| 813 | (or skip-comment (goto-char pos)) | 1184 | pos |
| 814 | pos0)) | 1185 | (when (looking-at "options\\>") |
| 1186 | (setq pos (antlr-skip-sexps 2))) | ||
| 1187 | (or skip-comment (goto-char pos)) | ||
| 1188 | pos0))) | ||
| 815 | 1189 | ||
| 816 | (defun antlr-next-rule (arg skip-comment) | 1190 | (defun antlr-next-rule (arg skip-comment) |
| 817 | "Move forward to next end of rule. Do it ARG many times. | 1191 | "Move forward to next end of rule. Do it ARG many times. |
| @@ -1011,15 +1385,560 @@ Display a message unless optional argument SILENT is non-nil." | |||
| 1011 | 1385 | ||
| 1012 | 1386 | ||
| 1013 | ;;;=========================================================================== | 1387 | ;;;=========================================================================== |
| 1388 | ;;; Insert option: command | ||
| 1389 | ;;;=========================================================================== | ||
| 1390 | |||
| 1391 | (defun antlr-insert-option (level option &optional location) | ||
| 1392 | "Insert file/grammar/rule/subrule option near point. | ||
| 1393 | LEVEL determines option kind to insert: 1=file, 2=grammar, 3=rule, | ||
| 1394 | 4=subrule. OPTION is a string with the name of the option to insert. | ||
| 1395 | LOCATION can be specified for not calling `antlr-option-kind' twice. | ||
| 1396 | |||
| 1397 | Inserting an option with this command works as follows: | ||
| 1398 | |||
| 1399 | 1. When called interactively, LEVEL is determined by the prefix | ||
| 1400 | argument or automatically deduced without prefix argument. | ||
| 1401 | 2. Signal an error if no option of that level could be inserted, e.g., | ||
| 1402 | if the buffer is read-only, the option area is outside the visible | ||
| 1403 | part of the buffer or a subrule/rule option should be inserted with | ||
| 1404 | point outside a subrule/rule. | ||
| 1405 | 3. When called interactively, OPTION is read from the minibuffer with | ||
| 1406 | completion over the known options of the given LEVEL. | ||
| 1407 | 4. Ask user for confirmation if the given OPTION does not seem to be a | ||
| 1408 | valid option to insert into the current file. | ||
| 1409 | 5. Find a correct position to insert the option. | ||
| 1410 | 6. Depending on the option, insert it the following way \(inserting an | ||
| 1411 | option also means inserting the option section if necessary\): | ||
| 1412 | - Insert the option and let user insert the value at point. | ||
| 1413 | - Read a value (with completion) from the minibuffer, using a | ||
| 1414 | previous value as initial contents, and insert option with value. | ||
| 1415 | 7. Final action depending on the option. For example, set the language | ||
| 1416 | according to a newly inserted language option. | ||
| 1417 | |||
| 1418 | The name of all options with a specification for their values are stored | ||
| 1419 | in `antlr-options-alist'. The used specification also depends on the | ||
| 1420 | value of `antlr-tool-version', i.e., step 4 will warn you if you use an | ||
| 1421 | option that has been introduced in newer version of ANTLR, and step 5 | ||
| 1422 | will offer completion using version-correct values. | ||
| 1423 | |||
| 1424 | If the option already exists inside the visible part of the buffer, this | ||
| 1425 | command can be used to change the value of that option. Otherwise, find | ||
| 1426 | a correct position where the option can be inserted near point. | ||
| 1427 | |||
| 1428 | The search for a correct position is as follows: | ||
| 1429 | |||
| 1430 | * If search is within an area where options can be inserted, use the | ||
| 1431 | position of point. Inside the options section and if point is in | ||
| 1432 | the middle of a option definition, skip the rest of it. | ||
| 1433 | * If an options section already exists, insert the options at the end. | ||
| 1434 | If only the beginning of the area is visible, insert at the | ||
| 1435 | beginning. | ||
| 1436 | * Otherwise, find the position where an options section can be | ||
| 1437 | inserted and insert a new section before any comments. If the | ||
| 1438 | position before the comments is not visible, insert the new section | ||
| 1439 | after the comments. | ||
| 1440 | |||
| 1441 | This function also inserts \"options {...}\" and the \":\" if necessary, | ||
| 1442 | see `antlr-options-auto-colon'. See also `antlr-options-assign-string'. | ||
| 1443 | |||
| 1444 | This command might also set the mark like \\[set-mark-command] does, see | ||
| 1445 | `antlr-options-push-mark'." | ||
| 1446 | (interactive (antlr-insert-option-interactive current-prefix-arg)) | ||
| 1447 | (barf-if-buffer-read-only) | ||
| 1448 | (or location (setq location (cdr (antlr-option-kind level)))) | ||
| 1449 | (cond ((null level) | ||
| 1450 | (error "Cannot deduce what kind of option to insert")) | ||
| 1451 | ((atom location) | ||
| 1452 | (error "Cannot insert any %s options around here" | ||
| 1453 | (elt antlr-options-headings (1- level))))) | ||
| 1454 | (let ((area (car location)) | ||
| 1455 | (place (cdr location))) | ||
| 1456 | (cond ((null place) ; invisible | ||
| 1457 | (error (if area | ||
| 1458 | "Invisible %s options, use %s to make them visible" | ||
| 1459 | "Invisible area for %s options, use %s to make it visible") | ||
| 1460 | (elt antlr-options-headings (1- level)) | ||
| 1461 | (substitute-command-keys "\\[widen]"))) | ||
| 1462 | ((null area) ; without option part | ||
| 1463 | (antlr-insert-option-do level option nil | ||
| 1464 | (null (cdr place)) | ||
| 1465 | (car place))) | ||
| 1466 | ((save-excursion ; with option part, option visible | ||
| 1467 | (goto-char (max (point-min) (car area))) | ||
| 1468 | (re-search-forward (concat "\\(^\\|;\\)[ \t]*\\(\\<" | ||
| 1469 | (regexp-quote option) | ||
| 1470 | "\\>\\)[ \t\n]*\\(\\(=[ \t]?\\)[ \t]*\\(\\(\\sw\\|\\s_\\)+\\|\"\\([^\n\"\\]\\|[\\][^\n]\\)*\"\\)?\\)?") | ||
| 1471 | ;; 2=name, 3=4+5, 4="=", 5=value | ||
| 1472 | (min (point-max) (cdr area)) | ||
| 1473 | t)) | ||
| 1474 | (antlr-insert-option-do level option | ||
| 1475 | (cons (or (match-beginning 5) | ||
| 1476 | (match-beginning 3)) | ||
| 1477 | (match-end 5)) | ||
| 1478 | (and (null (cdr place)) area) | ||
| 1479 | (or (match-beginning 5) | ||
| 1480 | (match-end 4) | ||
| 1481 | (match-end 2)))) | ||
| 1482 | (t ; with option part, option not yet | ||
| 1483 | (antlr-insert-option-do level option t | ||
| 1484 | (and (null (cdr place)) area) | ||
| 1485 | (car place)))))) | ||
| 1486 | |||
| 1487 | (defun antlr-insert-option-interactive (arg) | ||
| 1488 | "Interactive specification for `antlr-insert-option'. | ||
| 1489 | Use prefix argument ARG to return \(LEVEL OPTION LOCATION)." | ||
| 1490 | (barf-if-buffer-read-only) | ||
| 1491 | (if arg (setq arg (prefix-numeric-value arg))) | ||
| 1492 | (unless (memq arg '(nil 1 2 3 4)) | ||
| 1493 | (error "Valid prefix args: no=auto, 1=file, 2=grammar, 3=rule, 4=subrule")) | ||
| 1494 | (let* ((kind (antlr-option-kind arg)) | ||
| 1495 | (level (car kind))) | ||
| 1496 | (if (atom (cdr kind)) | ||
| 1497 | (list level nil (cdr kind)) | ||
| 1498 | (let* ((table (elt antlr-options-alists (1- level))) | ||
| 1499 | (completion-ignore-case t) ;dynamic | ||
| 1500 | (input (completing-read (format "Insert %s option: " | ||
| 1501 | (elt antlr-options-headings | ||
| 1502 | (1- level))) | ||
| 1503 | table))) | ||
| 1504 | (list level input (cdr kind)))))) | ||
| 1505 | |||
| 1506 | (defun antlr-options-menu-filter (level menu-items) | ||
| 1507 | "Return items for options submenu of level LEVEL." | ||
| 1508 | ;; checkdoc-params: (menu-items) | ||
| 1509 | (let ((active (if buffer-read-only | ||
| 1510 | nil | ||
| 1511 | (consp (cdr-safe (cdr (antlr-option-kind level))))))) | ||
| 1512 | (mapcar (lambda (option) | ||
| 1513 | (vector option | ||
| 1514 | (list 'antlr-insert-option level option) | ||
| 1515 | :active active)) | ||
| 1516 | (sort (mapcar 'car (elt antlr-options-alists (1- level))) | ||
| 1517 | 'string-lessp)))) | ||
| 1518 | |||
| 1519 | |||
| 1520 | ;;;=========================================================================== | ||
| 1521 | ;;; Insert option: determine section-kind | ||
| 1522 | ;;;=========================================================================== | ||
| 1523 | |||
| 1524 | (defun antlr-option-kind (requested) | ||
| 1525 | "Return level and location for option to insert near point. | ||
| 1526 | Call function `antlr-option-level' with argument REQUESTED. If the | ||
| 1527 | result is nil, return \(REQUESTED \. error). If the result has the | ||
| 1528 | non-nil value LEVEL, return \(LEVEL \. LOCATION) where LOCATION looks | ||
| 1529 | like \(AREA \. PLACE), see `antlr-option-location'." | ||
| 1530 | (save-excursion | ||
| 1531 | (save-restriction | ||
| 1532 | (let ((min0 (point-min)) ; before `widen'! | ||
| 1533 | (max0 (point-max)) | ||
| 1534 | (orig (point)) | ||
| 1535 | (level (antlr-option-level requested)) ; calls `widen'! | ||
| 1536 | pos) | ||
| 1537 | (cond ((null level) | ||
| 1538 | (setq level requested)) | ||
| 1539 | ((eq level 1) ; file options | ||
| 1540 | (goto-char (point-min)) | ||
| 1541 | (setq pos (antlr-skip-file-prelude 'header-only))) | ||
| 1542 | ((not (eq level 3)) ; grammar or subrule options | ||
| 1543 | (setq pos (point)) | ||
| 1544 | (c-forward-syntactic-ws)) | ||
| 1545 | ((looking-at "^\\(private[ \t\n]\\|public[ \t\n]\\|protected[ \t\n]\\)?[ \t\n]*\\(\\(\\sw\\|\\s_\\)+\\)[ \t\n]*\\(!\\)?[ \t\n]*\\(\\[\\)?") | ||
| 1546 | ;; rule options, with complete rule header | ||
| 1547 | (goto-char (or (match-end 4) (match-end 3))) | ||
| 1548 | (setq pos (antlr-skip-sexps (if (match-end 5) 1 0))) | ||
| 1549 | (when (looking-at "returns[ \t\n]*\\[") | ||
| 1550 | (goto-char (1- (match-end 0))) | ||
| 1551 | (setq pos (antlr-skip-sexps 1))))) | ||
| 1552 | (cons level | ||
| 1553 | (cond ((null pos) 'error) | ||
| 1554 | ((looking-at "options[ \t\n]*{") | ||
| 1555 | (goto-char (match-end 0)) | ||
| 1556 | (setq pos (antlr-scan-lists (point) 1 1 nil t)) | ||
| 1557 | (antlr-option-location orig min0 max0 | ||
| 1558 | (point) | ||
| 1559 | (if pos (1- pos) (point-max)) | ||
| 1560 | t)) | ||
| 1561 | (t | ||
| 1562 | (antlr-option-location orig min0 max0 | ||
| 1563 | pos (point) | ||
| 1564 | nil)))))))) | ||
| 1565 | |||
| 1566 | (defun antlr-option-level (requested) | ||
| 1567 | "Return level for option to insert near point. | ||
| 1568 | Remove any restrictions from current buffer and return level for the | ||
| 1569 | option to insert near point, i.e., 1, 2, 3, 4, or nil if no such option | ||
| 1570 | can be inserted. If REQUESTED is non-nil, it is the only possible value | ||
| 1571 | to return except nil. If REQUESTED is nil, return level for the nearest | ||
| 1572 | option kind, i.e., the highest number possible. | ||
| 1573 | |||
| 1574 | If the result is 2, point is at the beginning of the class after the | ||
| 1575 | class definition. If the result is 3 or 4, point is at the beginning of | ||
| 1576 | the rule/subrule after the init action. Otherwise, the point position | ||
| 1577 | is undefined." | ||
| 1578 | (widen) | ||
| 1579 | (if (eq requested 1) | ||
| 1580 | 1 | ||
| 1581 | (antlr-with-syntax-table antlr-action-syntax-table | ||
| 1582 | (antlr-invalidate-context-cache) | ||
| 1583 | (let* ((orig (point)) | ||
| 1584 | (outsidep (antlr-outside-rule-p)) | ||
| 1585 | bor depth) | ||
| 1586 | (if (eq (char-after) ?\{) (antlr-skip-sexps 1)) | ||
| 1587 | (setq bor (point)) ; beginning of rule (after init action) | ||
| 1588 | (cond ((eq requested 2) ; grammar options required? | ||
| 1589 | (let (boc) ; beginning of class | ||
| 1590 | (goto-char (point-min)) | ||
| 1591 | (while (and (<= (point) bor) | ||
| 1592 | (antlr-re-search-forward antlr-class-header-regexp | ||
| 1593 | nil)) | ||
| 1594 | (if (<= (match-beginning 0) bor) | ||
| 1595 | (setq boc (match-end 0)))) | ||
| 1596 | (when boc | ||
| 1597 | (goto-char boc) | ||
| 1598 | 2))) | ||
| 1599 | ((save-excursion ; in region of file options? | ||
| 1600 | (goto-char (point-min)) | ||
| 1601 | (antlr-skip-file-prelude t) ; ws/comment after: OK | ||
| 1602 | (< orig (point))) | ||
| 1603 | (and (null requested) 1)) | ||
| 1604 | (outsidep ; outside rule not OK | ||
| 1605 | nil) | ||
| 1606 | ((looking-at antlr-class-header-regexp) ; rule = class def? | ||
| 1607 | (goto-char (match-end 0)) | ||
| 1608 | (and (null requested) 2)) | ||
| 1609 | ((eq requested 3) ; rule options required? | ||
| 1610 | (goto-char bor) | ||
| 1611 | 3) | ||
| 1612 | ((setq depth (antlr-syntactic-grammar-depth orig bor)) | ||
| 1613 | (if (> depth 0) ; move out of actions | ||
| 1614 | (goto-char (scan-lists (point) -1 depth))) | ||
| 1615 | (set-syntax-table antlr-mode-syntax-table) | ||
| 1616 | (antlr-invalidate-context-cache) | ||
| 1617 | (if (eq (antlr-syntactic-context) 0) ; not in subrule? | ||
| 1618 | (unless (eq requested 4) | ||
| 1619 | (goto-char bor) | ||
| 1620 | 3) | ||
| 1621 | (goto-char (1+ (scan-lists (point) -1 1))) | ||
| 1622 | 4))))))) | ||
| 1623 | |||
| 1624 | (defun antlr-option-location (orig min-vis max-vis min-area max-area withp) | ||
| 1625 | "Return location for the options area. | ||
| 1626 | ORIG is the original position of `point', MIN-VIS is `point-min' and | ||
| 1627 | MAX-VIS is `point-max'. If WITHP is non-nil, there exists an option | ||
| 1628 | specification and it starts after the brace at MIN-AREA and stops at | ||
| 1629 | MAX-AREA. If WITHP is nil, there is no area and the region where it | ||
| 1630 | could be inserted starts at MIN-AREA and stops at MAX-AREA. | ||
| 1631 | |||
| 1632 | The result has the form (AREA . PLACE). AREA is (MIN-AREA . MAX-AREA) | ||
| 1633 | if WITHP is non-nil, and nil otherwise. PLACE is nil if the area is | ||
| 1634 | invisible, (ORIG) if ORIG is inside the area, (MIN-AREA . beginning) for | ||
| 1635 | a visible start position and (MAX-AREA . end) for a visible end position | ||
| 1636 | where the beginning is preferred if WITHP is nil and the end if WITHP is | ||
| 1637 | non-nil." | ||
| 1638 | (cons (and withp (cons min-area max-area)) | ||
| 1639 | (cond ((and (<= min-area orig) (<= orig max-area)) | ||
| 1640 | ;; point in options area | ||
| 1641 | (list orig)) | ||
| 1642 | ((and (null withp) (<= min-vis min-area) (<= min-area max-vis)) | ||
| 1643 | ;; use start of options area (only if not `withp') | ||
| 1644 | (cons min-area 'beginning)) | ||
| 1645 | ((and (<= min-vis max-area) (<= max-area max-vis)) | ||
| 1646 | ;; use end of options area | ||
| 1647 | (cons max-area 'end)) | ||
| 1648 | ((and withp (<= min-vis min-area) (<= min-area max-vis)) | ||
| 1649 | ;; use start of options area (only if `withp') | ||
| 1650 | (cons min-area 'beginning))))) | ||
| 1651 | |||
| 1652 | (defun antlr-syntactic-grammar-depth (pos beg) | ||
| 1653 | "Return syntactic context depth at POS. | ||
| 1654 | Move to POS and from there on to the beginning of the string or comment | ||
| 1655 | if POS is inside such a construct. Then, return the syntactic context | ||
| 1656 | depth at point if the point position is smaller than BEG. | ||
| 1657 | WARNING: this may alter `match-data'." | ||
| 1658 | (goto-char pos) | ||
| 1659 | (let ((context (or (antlr-syntactic-context) 0))) | ||
| 1660 | (while (and context (not (integerp context))) | ||
| 1661 | (cond ((eq context 'string) | ||
| 1662 | (setq context | ||
| 1663 | (and (search-backward "\"" nil t) | ||
| 1664 | (>= (point) beg) | ||
| 1665 | (or (antlr-syntactic-context) 0)))) | ||
| 1666 | ((memq context '(comment block-comment)) | ||
| 1667 | (setq context | ||
| 1668 | (and (re-search-backward "/[/*]" nil t) | ||
| 1669 | (>= (point) beg) | ||
| 1670 | (or (antlr-syntactic-context) 0)))))) | ||
| 1671 | context)) | ||
| 1672 | |||
| 1673 | |||
| 1674 | ;;;=========================================================================== | ||
| 1675 | ;;; Insert options: do the insertion | ||
| 1676 | ;;;=========================================================================== | ||
| 1677 | |||
| 1678 | (defun antlr-insert-option-do (level option old area pos) | ||
| 1679 | "Insert option into buffer at position POS. | ||
| 1680 | Insert option of level LEVEL and name OPTION. If OLD is non-nil, an | ||
| 1681 | options area is already exists. If OLD looks like \(BEG \. END), the | ||
| 1682 | option already exists. Then, BEG is the start position of the option | ||
| 1683 | value, the position of the `=' or nil, and END is the end position of | ||
| 1684 | the option value or nil. | ||
| 1685 | |||
| 1686 | If the original point position was outside an options area, AREA is nil. | ||
| 1687 | Otherwise, and if an option specification already exists, AREA is a cons | ||
| 1688 | cell where the two values determine the area inside the braces." | ||
| 1689 | (let* ((spec (cdr (assoc option (elt antlr-options-alists (1- level))))) | ||
| 1690 | (value (antlr-option-spec level option (cdr spec) (consp old)))) | ||
| 1691 | (if (fboundp (car spec)) (funcall (car spec) 'before-input option)) | ||
| 1692 | ;; set mark (unless point was inside options area before) | ||
| 1693 | (if (cond (area (eq antlr-options-push-mark t)) | ||
| 1694 | ((numberp antlr-options-push-mark) | ||
| 1695 | (> (count-lines (min (point) pos) (max (point) pos)) | ||
| 1696 | antlr-options-push-mark)) | ||
| 1697 | (antlr-options-push-mark)) | ||
| 1698 | (push-mark)) | ||
| 1699 | ;; read option value ----------------------------------------------------- | ||
| 1700 | (goto-char pos) | ||
| 1701 | (if (null value) | ||
| 1702 | ;; no option specification found | ||
| 1703 | (if (y-or-n-p (format "Insert unknown %s option %s? " | ||
| 1704 | (elt antlr-options-headings (1- level)) | ||
| 1705 | option)) | ||
| 1706 | (message "Insert value for %s option %s" | ||
| 1707 | (elt antlr-options-headings (1- level)) | ||
| 1708 | option) | ||
| 1709 | (error "Didn't insert unknown %s option %s" | ||
| 1710 | (elt antlr-options-headings (1- level)) | ||
| 1711 | option)) | ||
| 1712 | ;; option specification found | ||
| 1713 | (setq value (cdr value)) | ||
| 1714 | (if (car value) | ||
| 1715 | (let ((initial (and (consp old) (cdr old) | ||
| 1716 | (buffer-substring (car old) (cdr old))))) | ||
| 1717 | (setq value (apply (car value) | ||
| 1718 | (and initial | ||
| 1719 | (if (eq (aref initial 0) ?\") | ||
| 1720 | (read initial) | ||
| 1721 | initial)) | ||
| 1722 | (cdr value)))) | ||
| 1723 | (message (cadr value)) | ||
| 1724 | (setq value nil))) | ||
| 1725 | ;; insert value ---------------------------------------------------------- | ||
| 1726 | (if (consp old) | ||
| 1727 | (antlr-insert-option-existing old value) | ||
| 1728 | (if (consp area) | ||
| 1729 | ;; Move outside string/comment if point is inside option spec | ||
| 1730 | (antlr-syntactic-grammar-depth (point) (car area))) | ||
| 1731 | (antlr-insert-option-space area old) | ||
| 1732 | (or old (antlr-insert-option-area level)) | ||
| 1733 | (insert option " = ;") | ||
| 1734 | (backward-char) | ||
| 1735 | (if value (insert value))) | ||
| 1736 | ;; final ----------------------------------------------------------------- | ||
| 1737 | (if (fboundp (car spec)) (funcall (car spec) 'after-insertion option)))) | ||
| 1738 | |||
| 1739 | (defun antlr-option-spec (level option specs existsp) | ||
| 1740 | "Return version correct option value specification. | ||
| 1741 | Return specification for option OPTION of kind level LEVEL. SPECS | ||
| 1742 | should correspond to the VALUE-SPEC... in `antlr-option-alists'. | ||
| 1743 | EXISTSP determines whether the option already exists." | ||
| 1744 | (let (value) | ||
| 1745 | (while (and specs (>= antlr-tool-version (caar specs))) | ||
| 1746 | (setq value (pop specs))) | ||
| 1747 | (cond (value) ; found correct spec | ||
| 1748 | ((null specs) nil) ; didn't find any specs | ||
| 1749 | (existsp (car specs)) ; wrong version, but already present | ||
| 1750 | ((y-or-n-p (format "Insert v%s %s option %s in v%s? " | ||
| 1751 | (antlr-version-string (caar specs)) | ||
| 1752 | (elt antlr-options-headings (1- level)) | ||
| 1753 | option | ||
| 1754 | (antlr-version-string antlr-tool-version))) | ||
| 1755 | (car specs)) | ||
| 1756 | (t | ||
| 1757 | (error "Didn't insert v%s %s option %s in v%s" | ||
| 1758 | (antlr-version-string (caar specs)) | ||
| 1759 | (elt antlr-options-headings (1- level)) | ||
| 1760 | option | ||
| 1761 | (antlr-version-string antlr-tool-version)))))) | ||
| 1762 | |||
| 1763 | (defun antlr-version-string (version) | ||
| 1764 | "Format the Antlr version number VERSION, see `antlr-tool-version'." | ||
| 1765 | (let ((version100 (/ version 100))) | ||
| 1766 | (format "%d.%d.%d" | ||
| 1767 | (/ version100 100) (mod version100 100) (mod version 100)))) | ||
| 1768 | |||
| 1769 | |||
| 1770 | ;;;=========================================================================== | ||
| 1771 | ;;; Insert options: the details (used by `antlr-insert-option-do') | ||
| 1772 | ;;;=========================================================================== | ||
| 1773 | |||
| 1774 | (defun antlr-insert-option-existing (old value) | ||
| 1775 | "Insert option value VALUE at point for existing option. | ||
| 1776 | For OLD, see `antlr-insert-option-do'." | ||
| 1777 | ;; no = => insert = | ||
| 1778 | (unless (car old) (insert antlr-options-assign-string)) | ||
| 1779 | ;; with user input => insert if necessary | ||
| 1780 | (when value | ||
| 1781 | (if (cdr old) ; with value | ||
| 1782 | (if (string-equal value (buffer-substring (car old) (cdr old))) | ||
| 1783 | (goto-char (cdr old)) | ||
| 1784 | (delete-region (car old) (cdr old)) | ||
| 1785 | (insert value)) | ||
| 1786 | (insert value))) | ||
| 1787 | (unless (looking-at "\\([^\n=;{}/'\"]\\|'\\([^\n'\\]\\|\\\\.\\)*'\\|\"\\([^\n\"\\]\\|\\\\.\\)*\"\\)*;") | ||
| 1788 | ;; stuff (no =, {, } or /) at point is not followed by ";" | ||
| 1789 | (insert ";") | ||
| 1790 | (backward-char))) | ||
| 1791 | |||
| 1792 | (defun antlr-insert-option-space (area old) | ||
| 1793 | "Find appropriate place to insert option, insert newlines/spaces. | ||
| 1794 | For AREA and OLD, see `antlr-insert-option-do'." | ||
| 1795 | (let ((orig (point)) | ||
| 1796 | (open t)) | ||
| 1797 | (skip-chars-backward " \t") | ||
| 1798 | (unless (bolp) | ||
| 1799 | (let ((before (char-after (1- (point))))) | ||
| 1800 | (goto-char orig) | ||
| 1801 | (and old ; with existing options area | ||
| 1802 | (consp area) ; if point inside existing area | ||
| 1803 | (not (eq before ?\;)) ; if not at beginning of option | ||
| 1804 | ; => skip to end of option | ||
| 1805 | (if (and (search-forward ";" (cdr area) t) | ||
| 1806 | (let ((context (antlr-syntactic-context))) | ||
| 1807 | (or (null context) (numberp context)))) | ||
| 1808 | (setq orig (point)) | ||
| 1809 | (goto-char orig))) | ||
| 1810 | (skip-chars-forward " \t") | ||
| 1811 | |||
| 1812 | (if (looking-at "$\\|//") | ||
| 1813 | ;; just comment after point => skip (+ lines w/ same col comment) | ||
| 1814 | (let ((same (if (> (match-end 0) (match-beginning 0)) | ||
| 1815 | (current-column)))) | ||
| 1816 | (beginning-of-line 2) | ||
| 1817 | (or (bolp) (insert "\n")) | ||
| 1818 | (when (and same (null area)) ; or (consp area)? | ||
| 1819 | (while (and (looking-at "[ \t]*\\(//\\)") | ||
| 1820 | (goto-char (match-beginning 1)) | ||
| 1821 | (= (current-column) same)) | ||
| 1822 | (beginning-of-line 2) | ||
| 1823 | (or (bolp) (insert "\n"))))) | ||
| 1824 | (goto-char orig) | ||
| 1825 | (if (null old) | ||
| 1826 | (progn (insert "\n") (antlr-indent-line)) | ||
| 1827 | (unless (eq (char-after (1- (point))) ?\ ) | ||
| 1828 | (insert " ")) | ||
| 1829 | (unless (eq (char-after (point)) ?\ ) | ||
| 1830 | (insert " ") | ||
| 1831 | (backward-char)) | ||
| 1832 | (setq open nil))))) | ||
| 1833 | (when open | ||
| 1834 | (beginning-of-line 1) | ||
| 1835 | (insert "\n") | ||
| 1836 | (backward-char) | ||
| 1837 | (antlr-indent-line)))) | ||
| 1838 | |||
| 1839 | (defun antlr-insert-option-area (level) | ||
| 1840 | "Insert new options area for options of level LEVEL. | ||
| 1841 | Used by `antlr-insert-option-do'." | ||
| 1842 | (insert "options {\n\n}") | ||
| 1843 | (when (and antlr-options-auto-colon | ||
| 1844 | (memq level '(3 4)) | ||
| 1845 | (save-excursion | ||
| 1846 | (c-forward-syntactic-ws) | ||
| 1847 | (if (eq (char-after (point)) ?\{) (antlr-skip-sexps 1)) | ||
| 1848 | (not (eq (char-after (point)) ?\:)))) | ||
| 1849 | (insert "\n:") | ||
| 1850 | (antlr-indent-line) | ||
| 1851 | (end-of-line 0)) | ||
| 1852 | (backward-char 1) | ||
| 1853 | (antlr-indent-line) | ||
| 1854 | (beginning-of-line 0) | ||
| 1855 | (antlr-indent-line)) | ||
| 1856 | |||
| 1857 | |||
| 1858 | ;;;=========================================================================== | ||
| 1859 | ;;; Insert options: in `antlr-options-alists' | ||
| 1860 | ;;;=========================================================================== | ||
| 1861 | |||
| 1862 | (defun antlr-read-value (initial-contents prompt | ||
| 1863 | &optional as-string table table-x) | ||
| 1864 | "Read a string from the minibuffer, possibly with completion. | ||
| 1865 | If INITIAL-CONTENTS is non-nil, insert it in the minibuffer initially. | ||
| 1866 | PROMPT is a string to prompt with, normally it ends in a colon and a | ||
| 1867 | space. If AS-STRING is t or is a member \(comparison done with `eq') of | ||
| 1868 | `antlr-options-style', return printed representation of the user input, | ||
| 1869 | otherwise return the user input directly. | ||
| 1870 | |||
| 1871 | If TABLE or TABLE-X is non-nil, read with completion. The completion | ||
| 1872 | table is the resulting alist of TABLE-X concatenated with TABLE where | ||
| 1873 | TABLE can also be a function evaluation to an alist. | ||
| 1874 | |||
| 1875 | Used inside `antlr-options-alists'." | ||
| 1876 | (let* ((table0 (and (or table table-x) | ||
| 1877 | (append table-x | ||
| 1878 | (if (functionp table) (funcall table) table)))) | ||
| 1879 | (input (if table0 | ||
| 1880 | (completing-read prompt table0 nil nil initial-contents) | ||
| 1881 | (read-from-minibuffer prompt initial-contents)))) | ||
| 1882 | (if (and as-string | ||
| 1883 | (or (eq as-string t) | ||
| 1884 | (cdr (assq as-string antlr-options-style)))) | ||
| 1885 | (format "%S" input) | ||
| 1886 | input))) | ||
| 1887 | |||
| 1888 | (defun antlr-read-boolean (initial-contents prompt &optional table) | ||
| 1889 | "Read a boolean value from the minibuffer, with completion. | ||
| 1890 | If INITIAL-CONTENTS is non-nil, insert it in the minibuffer initially. | ||
| 1891 | PROMPT is a string to prompt with, normally it ends in a question mark | ||
| 1892 | and a space. \"(true or false) \" is appended if TABLE is nil. | ||
| 1893 | |||
| 1894 | Read with completion over \"true\", \"false\" and the keys in TABLE, see | ||
| 1895 | also `antlr-read-value'. | ||
| 1896 | |||
| 1897 | Used inside `antlr-options-alists'." | ||
| 1898 | (antlr-read-value initial-contents | ||
| 1899 | (if table prompt (concat prompt "(true or false) ")) | ||
| 1900 | nil | ||
| 1901 | table '(("false") ("true")))) | ||
| 1902 | |||
| 1903 | (defun antlr-language-option-extra (phase &rest dummies) | ||
| 1904 | ;; checkdoc-params: (dummies) | ||
| 1905 | "Change language according to the new value of the \"language\" option. | ||
| 1906 | Call `antlr-mode' if the new language would be different from the value | ||
| 1907 | of `antlr-language', keeping the value of variable `font-lock-mode'. | ||
| 1908 | |||
| 1909 | Called in PHASE `after-insertion', see `antlr-options-alists'." | ||
| 1910 | (when (eq phase 'after-insertion) | ||
| 1911 | (let ((new-language (antlr-language-option t))) | ||
| 1912 | (or (null new-language) | ||
| 1913 | (eq new-language antlr-language) | ||
| 1914 | (let ((font-lock (and (boundp 'font-lock-mode) font-lock-mode))) | ||
| 1915 | (if font-lock (font-lock-mode 0)) | ||
| 1916 | (antlr-mode) | ||
| 1917 | (and font-lock (null font-lock-mode) (font-lock-mode 1))))))) | ||
| 1918 | |||
| 1919 | (defun antlr-c++-mode-extra (phase option &rest dummies) | ||
| 1920 | ;; checkdoc-params: (option dummies) | ||
| 1921 | "Warn if C++ option is used with the wrong language. | ||
| 1922 | Ask user \(\"y or n\"), if a C++ only option is going to be inserted but | ||
| 1923 | `antlr-language' has not the value `c++-mode'. | ||
| 1924 | |||
| 1925 | Called in PHASE `before-input', see `antlr-options-alists'." | ||
| 1926 | (and (eq phase 'before-input) | ||
| 1927 | (not (y-or-n-p (format "Insert C++ %s option? " option))) | ||
| 1928 | (error "Didn't insert C++ %s option with language %s" | ||
| 1929 | option (cadr (assq antlr-language antlr-language-alist))))) | ||
| 1930 | |||
| 1931 | |||
| 1932 | ;;;=========================================================================== | ||
| 1014 | ;;; Compute dependencies | 1933 | ;;; Compute dependencies |
| 1015 | ;;;=========================================================================== | 1934 | ;;;=========================================================================== |
| 1016 | 1935 | ||
| 1017 | (defun antlr-file-dependencies () | 1936 | (defun antlr-file-dependencies () |
| 1018 | "Return dependencies for grammar in current buffer. | 1937 | "Return dependencies for grammar in current buffer. |
| 1019 | The result looks like (FILE (CLASSES . SUPERS) VOCABS . LANGUAGE) | 1938 | The result looks like \(FILE \(CLASSES \. SUPERS) VOCABS \. LANGUAGE) |
| 1020 | where CLASSES = ((CLASS . CLASS-EVOCAB) ...), | 1939 | where CLASSES = ((CLASS . CLASS-EVOCAB) ...), |
| 1021 | SUPERS = ((SUPER . USE-EVOCAB-P) ...), and | 1940 | SUPERS = ((SUPER . USE-EVOCAB-P) ...), and |
| 1022 | VOCABS = ((EVOCAB ...) . (IVOCAB ...)) | 1941 | VOCABS = ((EVOCAB ...) . (IVOCAB ...)) |
| 1023 | 1942 | ||
| 1024 | FILE is the current buffer's file-name without directory part and | 1943 | FILE is the current buffer's file-name without directory part and |
| 1025 | LANGUAGE is the value of `antlr-language' in the current buffer. Each | 1944 | LANGUAGE is the value of `antlr-language' in the current buffer. Each |
| @@ -1033,10 +1952,10 @@ its export vocabulary is used as an import vocabulary." | |||
| 1033 | (let (classes exportVocabs importVocabs superclasses default-vocab) | 1952 | (let (classes exportVocabs importVocabs superclasses default-vocab) |
| 1034 | (antlr-with-syntax-table antlr-action-syntax-table | 1953 | (antlr-with-syntax-table antlr-action-syntax-table |
| 1035 | (goto-char (point-min)) | 1954 | (goto-char (point-min)) |
| 1036 | (while (antlr-re-search-forward "class[ \t]+\\([A-Za-z\300-\326\330-\337]\\sw*\\)[ \t]+extends[ \t]+\\([A-Za-z\300-\326\330-\337]\\sw*\\)[ \t]*;" nil) | 1955 | (while (antlr-re-search-forward antlr-class-header-regexp nil) |
| 1037 | ;; parse class definition -------------------------------------------- | 1956 | ;; parse class definition -------------------------------------------- |
| 1038 | (let* ((class (match-string 1)) | 1957 | (let* ((class (match-string 2)) |
| 1039 | (sclass (match-string 2)) | 1958 | (sclass (match-string 4)) |
| 1040 | ;; export vocab defaults to class name (first grammar in file) | 1959 | ;; export vocab defaults to class name (first grammar in file) |
| 1041 | ;; or to the export vocab of the first grammar in file: | 1960 | ;; or to the export vocab of the first grammar in file: |
| 1042 | (evocab (or default-vocab class)) | 1961 | (evocab (or default-vocab class)) |
| @@ -1048,7 +1967,7 @@ its export vocabulary is used as an import vocabulary." | |||
| 1048 | (antlr-skip-sexps 2) | 1967 | (antlr-skip-sexps 2) |
| 1049 | (goto-char (match-end 0)) | 1968 | (goto-char (match-end 0)) |
| 1050 | (c-forward-syntactic-ws) | 1969 | (c-forward-syntactic-ws) |
| 1051 | ;; parse grammar option section -------------------------------- | 1970 | ;; parse grammar option sections ------------------------------- |
| 1052 | (when (eq (char-after (point)) ?\{) | 1971 | (when (eq (char-after (point)) ?\{) |
| 1053 | (let* ((beg (1+ (point))) | 1972 | (let* ((beg (1+ (point))) |
| 1054 | (end (1- (antlr-skip-sexps 1))) | 1973 | (end (1- (antlr-skip-sexps 1))) |
| @@ -1080,8 +1999,8 @@ its export vocabulary is used as an import vocabulary." | |||
| 1080 | 1999 | ||
| 1081 | (defun antlr-directory-dependencies (dirname) | 2000 | (defun antlr-directory-dependencies (dirname) |
| 1082 | "Return dependencies for all grammar files in directory DIRNAME. | 2001 | "Return dependencies for all grammar files in directory DIRNAME. |
| 1083 | The result looks like ((CLASS-SPEC ...) . (FILE-DEP ...)) | 2002 | The result looks like \((CLASS-SPEC ...) \. \(FILE-DEP ...)) |
| 1084 | where CLASS-SPEC = (CLASS (FILE . EVOCAB) ...). | 2003 | where CLASS-SPEC = (CLASS (FILE \. EVOCAB) ...). |
| 1085 | 2004 | ||
| 1086 | FILE-DEP are the dependencies for each grammar file in DIRNAME, see | 2005 | FILE-DEP are the dependencies for each grammar file in DIRNAME, see |
| 1087 | `antlr-file-dependencies'. For each grammar class CLASS, FILE is a | 2006 | `antlr-file-dependencies'. For each grammar class CLASS, FILE is a |
| @@ -1131,14 +2050,14 @@ export vocabulary specified in that file." | |||
| 1131 | "Compute the grammar lib option for the super grammars SUPERS. | 2050 | "Compute the grammar lib option for the super grammars SUPERS. |
| 1132 | Look in CLASSES for the right grammar lib files for SUPERS. SUPERS is | 2051 | Look in CLASSES for the right grammar lib files for SUPERS. SUPERS is |
| 1133 | part SUPER in the result of `antlr-file-dependencies'. CLASSES is the | 2052 | part SUPER in the result of `antlr-file-dependencies'. CLASSES is the |
| 1134 | part (CLASS-SPEC ...) in the result of `antlr-directory-dependencies'. | 2053 | part \(CLASS-SPEC ...) in the result of `antlr-directory-dependencies'. |
| 1135 | 2054 | ||
| 1136 | The result looks like (OPTION WITH-UNKNOWN GLIB ...). OPTION is the | 2055 | The result looks like \(OPTION WITH-UNKNOWN GLIB ...). OPTION is the |
| 1137 | complete \"-glib\" option. WITH-UNKNOWN has value t iff there is none | 2056 | complete \"-glib\" option. WITH-UNKNOWN has value t iff there is none |
| 1138 | or more than one grammar file for at least one super grammar. | 2057 | or more than one grammar file for at least one super grammar. |
| 1139 | 2058 | ||
| 1140 | Each GLIB looks like (GRAMMAR-FILE . EVOCAB). GRAMMAR-FILE is a file in | 2059 | Each GLIB looks like \(GRAMMAR-FILE \. EVOCAB). GRAMMAR-FILE is a file |
| 1141 | which a super-grammar is defined. EVOCAB is the value of the export | 2060 | in which a super-grammar is defined. EVOCAB is the value of the export |
| 1142 | vocabulary of the super-grammar or nil if it is not needed." | 2061 | vocabulary of the super-grammar or nil if it is not needed." |
| 1143 | ;; If the superclass is defined in the same file, that file will be included | 2062 | ;; If the superclass is defined in the same file, that file will be included |
| 1144 | ;; with -glib again. This will lead to a redefinition. But defining a | 2063 | ;; with -glib again. This will lead to a redefinition. But defining a |
| @@ -1306,69 +2225,115 @@ multiplied by: | |||
| 1306 | - plus 0/2/1, depending on the position inside the rule: header, body, | 2225 | - plus 0/2/1, depending on the position inside the rule: header, body, |
| 1307 | exception part, | 2226 | exception part, |
| 1308 | - minus 1 if `antlr-indent-item-regexp' matches the beginning of the | 2227 | - minus 1 if `antlr-indent-item-regexp' matches the beginning of the |
| 1309 | line starting from the first non-blank. | 2228 | line starting from the first non-whitespace. |
| 1310 | 2229 | ||
| 1311 | Lines inside block comments are not changed or indented by | 2230 | Lines inside block comments are indented by `c-indent-line' according to |
| 1312 | `c-indent-line', see `antlr-indent-comment'." | 2231 | `antlr-indent-comment'. |
| 1313 | (let ((orig (point)) bol boi indent syntax) | 2232 | |
| 1314 | (beginning-of-line) | 2233 | If `antlr-language' equals to a key in `antlr-indent-at-bol-alist' and |
| 1315 | (setq bol (point)) | 2234 | the line starting at the first non-whitespace is matched by the |
| 1316 | (skip-chars-forward " \t") | 2235 | corresponding value, indent the line at column 0. |
| 1317 | (setq boi (point)) | 2236 | |
| 1318 | ;; check syntax at beginning of indentation ------------------------------ | 2237 | For the initialization of `c-basic-offset', see `antlr-indent-style' and, |
| 1319 | (antlr-with-syntax-table antlr-action-syntax-table | 2238 | to a lesser extent, `antlr-tab-offset-alist'." |
| 1320 | (antlr-invalidate-context-cache) | 2239 | (save-restriction |
| 1321 | (cond ((symbolp (setq syntax (antlr-syntactic-context))) | 2240 | (let ((orig (point)) |
| 1322 | (setq indent nil)) ; block-comments, strings, (comments) | 2241 | (min0 (point-min)) |
| 1323 | ((eq (char-after) ?#) ; cpp directive | 2242 | bol boi indent syntax) |
| 1324 | (setq syntax 'cpp) | 2243 | (widen) |
| 1325 | (setq indent 0)) ; indentation at 0 | 2244 | (beginning-of-line) |
| 1326 | ((progn | 2245 | (setq bol (point)) |
| 1327 | (antlr-next-rule -1 t) | 2246 | (if (< bol min0) |
| 1328 | (if (antlr-search-forward ":") (< boi (1- (point))) t)) | 2247 | (error "Beginning of current line not visible")) |
| 1329 | (setq indent 0)) ; in rule header | 2248 | (skip-chars-forward " \t") |
| 1330 | ((if (antlr-search-forward ";") (< boi (point)) t) | 2249 | (setq boi (point)) |
| 1331 | (setq indent 2)) ; in rule body | 2250 | ;; check syntax at beginning of indentation ---------------------------- |
| 1332 | (t | 2251 | (antlr-with-syntax-table antlr-action-syntax-table |
| 1333 | (forward-char) | ||
| 1334 | (antlr-skip-exception-part nil) | ||
| 1335 | (setq indent (if (> (point) boi) 1 0))))) ; in exception part? | ||
| 1336 | ;; compute the corresponding indentation and indent ---------------------- | ||
| 1337 | (if (null indent) | ||
| 1338 | (progn | ||
| 1339 | (goto-char orig) | ||
| 1340 | (and (eq antlr-indent-comment t) | ||
| 1341 | (not (eq syntax 'string)) | ||
| 1342 | (c-indent-line))) | ||
| 1343 | ;; do it ourselves | ||
| 1344 | (goto-char boi) | ||
| 1345 | (unless (symbolp syntax) ; direct indentation | ||
| 1346 | (antlr-invalidate-context-cache) | 2252 | (antlr-invalidate-context-cache) |
| 1347 | (incf indent (antlr-syntactic-context)) | 2253 | (setq syntax (antlr-syntactic-context)) |
| 1348 | (and (> indent 0) (looking-at antlr-indent-item-regexp) (decf indent)) | 2254 | (cond ((symbolp syntax) |
| 1349 | (setq indent (* indent c-basic-offset))) | 2255 | (setq indent nil)) ; block-comments, strings, (comments) |
| 1350 | ;; the usual major-mode indent stuff ----------------------------------- | 2256 | ((and (assq antlr-language antlr-indent-at-bol-alist) |
| 1351 | (setq orig (- (point-max) orig)) | 2257 | (looking-at (cdr (assq antlr-language |
| 1352 | (unless (= (current-column) indent) | 2258 | antlr-indent-at-bol-alist)))) |
| 1353 | (delete-region bol boi) | 2259 | (setq syntax 'bol) |
| 1354 | (beginning-of-line) | 2260 | (setq indent 0)) ; indentation at 0 |
| 1355 | (indent-to indent)) | 2261 | ((progn |
| 1356 | ;; If initial point was within line's indentation, | 2262 | (antlr-next-rule -1 t) |
| 1357 | ;; position after the indentation. Else stay at same point in text. | 2263 | (if (antlr-search-forward ":") (< boi (1- (point))) t)) |
| 1358 | (if (> (- (point-max) orig) (point)) | 2264 | (setq indent 0)) ; in rule header |
| 1359 | (goto-char (- (point-max) orig)))))) | 2265 | ((if (antlr-search-forward ";") (< boi (point)) t) |
| 2266 | (setq indent 2)) ; in rule body | ||
| 2267 | (t | ||
| 2268 | (forward-char) | ||
| 2269 | (antlr-skip-exception-part nil) | ||
| 2270 | (setq indent (if (> (point) boi) 1 0))))) ; in exception part? | ||
| 2271 | ;; compute the corresponding indentation and indent -------------------- | ||
| 2272 | (if (null indent) | ||
| 2273 | ;; Use the indentation engine of cc-mode for block comments. Using | ||
| 2274 | ;; it-mode for actions is not easy, especially if the actions come | ||
| 2275 | ;; early in the rule body. | ||
| 2276 | (progn | ||
| 2277 | (goto-char orig) | ||
| 2278 | (and (eq antlr-indent-comment t) | ||
| 2279 | (not (eq syntax 'string)) | ||
| 2280 | (c-indent-line))) | ||
| 2281 | ;; do it ourselves | ||
| 2282 | (goto-char boi) | ||
| 2283 | (unless (symbolp syntax) ; direct indentation | ||
| 2284 | (antlr-invalidate-context-cache) | ||
| 2285 | (incf indent (antlr-syntactic-context)) | ||
| 2286 | (and (> indent 0) (looking-at antlr-indent-item-regexp) (decf indent)) | ||
| 2287 | (setq indent (* indent c-basic-offset))) | ||
| 2288 | ;; the usual major-mode indent stuff --------------------------------- | ||
| 2289 | (setq orig (- (point-max) orig)) | ||
| 2290 | (unless (= (current-column) indent) | ||
| 2291 | (delete-region bol boi) | ||
| 2292 | (beginning-of-line) | ||
| 2293 | (indent-to indent)) | ||
| 2294 | ;; If initial point was within line's indentation, | ||
| 2295 | ;; position after the indentation. Else stay at same point in text. | ||
| 2296 | (if (> (- (point-max) orig) (point)) | ||
| 2297 | (goto-char (- (point-max) orig))))))) | ||
| 1360 | 2298 | ||
| 1361 | (defun antlr-indent-command (&optional arg) | 2299 | (defun antlr-indent-command (&optional arg) |
| 1362 | "Indent the current line or insert tabs/spaces. | 2300 | "Indent the current line or insert tabs/spaces. |
| 1363 | With optional prefix argument ARG or if the previous command was this | 2301 | With optional prefix argument ARG or if the previous command was this |
| 1364 | command, insert ARG tabs or spaces according to `indent-tabs-mode'. | 2302 | command, insert ARG tabs or spaces according to `indent-tabs-mode'. |
| 1365 | Otherwise, indent the current line with `antlr-indent-line'." | 2303 | Otherwise, indent the current line with `antlr-indent-line'." |
| 1366 | (interactive "P") | 2304 | (interactive "*P") |
| 1367 | (if (or arg (eq last-command 'antlr-indent-command)) | 2305 | (if (or arg (eq last-command 'antlr-indent-command)) |
| 1368 | (insert-tab arg) | 2306 | (insert-tab arg) |
| 1369 | (let ((antlr-indent-comment (and antlr-indent-comment t))) ; dynamic | 2307 | (let ((antlr-indent-comment (and antlr-indent-comment t))) ; dynamic |
| 1370 | (antlr-indent-line)))) | 2308 | (antlr-indent-line)))) |
| 1371 | 2309 | ||
| 2310 | (defun antlr-electric-character (&optional arg) | ||
| 2311 | "Insert the character you type and indent the current line. | ||
| 2312 | Insert the character like `self-insert-command' and indent the current | ||
| 2313 | line as `antlr-indent-command' does. Do not indent the line if | ||
| 2314 | |||
| 2315 | * this command is called with a prefix argument ARG, | ||
| 2316 | * there are characters except whitespaces between point and the | ||
| 2317 | beginning of the line, or | ||
| 2318 | * point is not inside a normal grammar code, { and } are also OK in | ||
| 2319 | actions. | ||
| 2320 | |||
| 2321 | This command is useful for a character which has some special meaning in | ||
| 2322 | ANTLR's syntax and influences the auto indentation, see | ||
| 2323 | `antlr-indent-item-regexp'." | ||
| 2324 | (interactive "*P") | ||
| 2325 | (if (or arg | ||
| 2326 | (save-excursion (skip-chars-backward " \t") (not (bolp))) | ||
| 2327 | (antlr-with-syntax-table antlr-action-syntax-table | ||
| 2328 | (antlr-invalidate-context-cache) | ||
| 2329 | (let ((context (antlr-syntactic-context))) | ||
| 2330 | (not (and (numberp context) | ||
| 2331 | (or (zerop context) | ||
| 2332 | (memq last-command-char '(?\{ ?\})))))))) | ||
| 2333 | (self-insert-command (prefix-numeric-value arg)) | ||
| 2334 | (self-insert-command (prefix-numeric-value arg)) | ||
| 2335 | (antlr-indent-line))) | ||
| 2336 | |||
| 1372 | 2337 | ||
| 1373 | ;;;=========================================================================== | 2338 | ;;;=========================================================================== |
| 1374 | ;;; Mode entry | 2339 | ;;; Mode entry |
| @@ -1425,17 +2390,27 @@ Otherwise, indent the current line with `antlr-indent-line'." | |||
| 1425 | (make-local-variable 'comment-indent-function) | 2390 | (make-local-variable 'comment-indent-function) |
| 1426 | (setq comment-indent-function 'c-comment-indent)) | 2391 | (setq comment-indent-function 'c-comment-indent)) |
| 1427 | 2392 | ||
| 1428 | (defun antlr-language-for-option (option-value) | 2393 | (defun antlr-language-option (search) |
| 1429 | "Find element in `antlr-language-alist' for OPTION-VALUE." | 2394 | "Find language in `antlr-language-alist' for language option. |
| 1430 | ;; Like (find OPTION-VALUE antlr-language-alist :key 'cddr :test 'member) | 2395 | If SEARCH is non-nil, find element for language option. Otherwise, find |
| 1431 | (let ((seq antlr-language-alist) | 2396 | the default language." |
| 2397 | (let ((value (and search | ||
| 2398 | (save-excursion | ||
| 2399 | (goto-char (point-min)) | ||
| 2400 | (re-search-forward (cdr antlr-language-limit-n-regexp) | ||
| 2401 | (car antlr-language-limit-n-regexp) | ||
| 2402 | t)) | ||
| 2403 | (match-string 1))) | ||
| 2404 | (seq antlr-language-alist) | ||
| 1432 | r) | 2405 | r) |
| 2406 | ;; Like (find-VALUE antlr-language-alist :key 'cddr :test 'member) | ||
| 1433 | (while seq | 2407 | (while seq |
| 1434 | (setq r (pop seq)) | 2408 | (setq r (pop seq)) |
| 1435 | (if (member option-value (cddr r)) | 2409 | (if (member value (cddr r)) |
| 1436 | (setq seq nil) ; stop | 2410 | (setq seq nil) ; stop |
| 1437 | (setq r nil))) ; no result yet | 2411 | (setq r nil))) ; no result yet |
| 1438 | r)) | 2412 | (car r))) |
| 2413 | |||
| 1439 | 2414 | ||
| 1440 | ;;;###autoload | 2415 | ;;;###autoload |
| 1441 | (defun antlr-mode () | 2416 | (defun antlr-mode () |
| @@ -1463,14 +2438,8 @@ Otherwise, indent the current line with `antlr-indent-line'." | |||
| 1463 | (use-local-map antlr-mode-map) | 2438 | (use-local-map antlr-mode-map) |
| 1464 | (make-local-variable 'antlr-language) | 2439 | (make-local-variable 'antlr-language) |
| 1465 | (unless antlr-language | 2440 | (unless antlr-language |
| 1466 | (save-excursion | 2441 | (setq antlr-language |
| 1467 | (goto-char (point-min)) | 2442 | (or (antlr-language-option t) (antlr-language-option nil)))) |
| 1468 | (setq antlr-language | ||
| 1469 | (car (or (and (re-search-forward (cdr antlr-language-limit-n-regexp) | ||
| 1470 | (car antlr-language-limit-n-regexp) | ||
| 1471 | t) | ||
| 1472 | (antlr-language-for-option (match-string 1))) | ||
| 1473 | (antlr-language-for-option nil)))))) | ||
| 1474 | (if (stringp (cadr (assq antlr-language antlr-language-alist))) | 2443 | (if (stringp (cadr (assq antlr-language antlr-language-alist))) |
| 1475 | (setq mode-name | 2444 | (setq mode-name |
| 1476 | (concat "Antlr." | 2445 | (concat "Antlr." |
| @@ -1540,5 +2509,14 @@ Used in `antlr-mode'. Also a useful function in `java-mode-hook'." | |||
| 1540 | ; LocalWords: VOCAB EVOCAB Antlr's TokenTypes exportVocab incl excl SUPERS gen | 2509 | ; LocalWords: VOCAB EVOCAB Antlr's TokenTypes exportVocab incl excl SUPERS gen |
| 1541 | ; LocalWords: VOCABS IVOCAB exportVocabs importVocabs superclasses vocab kens | 2510 | ; LocalWords: VOCABS IVOCAB exportVocabs importVocabs superclasses vocab kens |
| 1542 | ; LocalWords: sclass evocab ivocab importVocab deps glibs supers sep dep lang | 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 | ||
| 1543 | 2521 | ||
| 1544 | ;;; antlr-mode.el ends here | 2522 | ;;; antlr-mode.el ends here |