Mercurial > emacs
comparison lisp/progmodes/cc-langs.el @ 51714:bc91cbf50c24
Updated CC Mode to version 5.30.
author | Martin Stjernholm <mast@lysator.liu.se> |
---|---|
date | Thu, 03 Jul 2003 12:30:59 +0000 |
parents | e496049a6234 |
children | f3cad02bce62 |
comparison
equal
deleted
inserted
replaced
51713:205602055b5f | 51714:bc91cbf50c24 |
---|---|
1 ;;; cc-langs.el --- language specific settings for CC Mode | 1 ;;; cc-langs.el --- language specific settings for CC Mode |
2 | 2 |
3 ;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1985,1987,1992-2003 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Authors: 2000- Martin Stjernholm | 5 ;; Authors: 1998- Martin Stjernholm |
6 ;; 1998-1999 Barry A. Warsaw and Martin Stjernholm | 6 ;; 1992-1999 Barry A. Warsaw |
7 ;; 1992-1997 Barry A. Warsaw | |
8 ;; 1987 Dave Detlefs and Stewart Clamen | 7 ;; 1987 Dave Detlefs and Stewart Clamen |
9 ;; 1985 Richard M. Stallman | 8 ;; 1985 Richard M. Stallman |
10 ;; Maintainer: bug-cc-mode@gnu.org | 9 ;; Maintainer: bug-cc-mode@gnu.org |
11 ;; Created: 22-Apr-1997 (split from cc-mode.el) | 10 ;; Created: 22-Apr-1997 (split from cc-mode.el) |
12 ;; Version: See cc-mode.el | 11 ;; Version: See cc-mode.el |
29 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 28 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
30 ;; Boston, MA 02111-1307, USA. | 29 ;; Boston, MA 02111-1307, USA. |
31 | 30 |
32 ;;; Commentary: | 31 ;;; Commentary: |
33 | 32 |
33 ;; HACKERS NOTE: There's heavy macro magic here. If you need to make | |
34 ;; changes in this or other files containing `c-lang-defconst' but | |
35 ;; don't want to read through the longer discussion below then read | |
36 ;; this: | |
37 ;; | |
38 ;; o A change in a `c-lang-defconst' or `c-lang-defvar' will not take | |
39 ;; effect if the file containing the mode init function (typically | |
40 ;; cc-mode.el) is byte compiled. | |
41 ;; o To make changes show in font locking you need to reevaluate the | |
42 ;; `*-font-lock-keywords-*' constants, which normally is easiest to | |
43 ;; do with M-x eval-buffer in cc-fonts.el. | |
44 ;; o In either case it's necessary to reinitialize the mode to make | |
45 ;; the changes show in an existing buffer. | |
46 | |
47 ;;; Introduction to the language dependent variable system: | |
48 ;; | |
49 ;; This file contains all the language dependent variables, except | |
50 ;; those specific for font locking which reside in cc-fonts.el. As | |
51 ;; far as possible, all the differences between the languages that CC | |
52 ;; Mode supports are described with these variables only, so that the | |
53 ;; code can be shared. | |
54 ;; | |
55 ;; The language constant system (see cc-defs.el) is used to specify | |
56 ;; various language dependent info at a high level, such as lists of | |
57 ;; keywords, and then from them generate - at compile time - the | |
58 ;; various regexps and other low-level structures actually employed in | |
59 ;; the code at runtime. | |
60 ;; | |
61 ;; This system is also designed to make it easy for developers of | |
62 ;; derived modes to customize the source constants for new language | |
63 ;; variants, without having to keep up with the exact regexps etc that | |
64 ;; are used in each CC Mode version. It's possible from an external | |
65 ;; package to add a new language by inheriting an existing one, and | |
66 ;; then change specific constants as necessary for the new language. | |
67 ;; The old values for those constants (and the values of all the other | |
68 ;; high-level constants) may be used to build the new ones, and those | |
69 ;; new values will in turn be used by the low-level definitions here | |
70 ;; to build the runtime constants appropriately for the new language | |
71 ;; in the current version of CC Mode. | |
72 ;; | |
73 ;; Like elsewhere in CC Mode, the existence of a doc string signifies | |
74 ;; that a language constant is part of the external API, and that it | |
75 ;; therefore can be used with a high confidence that it will continue | |
76 ;; to work with future versions of CC Mode. Even so, it's not | |
77 ;; unlikely that such constants will change meaning slightly as this | |
78 ;; system is refined further; a certain degree of dependence on the CC | |
79 ;; Mode version is unavoidable when hooking in at this level. Also | |
80 ;; note that there's still work to be done to actually use these | |
81 ;; constants everywhere inside CC Mode; there are still hardcoded | |
82 ;; values in many places in the code. | |
83 ;; | |
84 ;; Separate packages will also benefit from the compile time | |
85 ;; evaluation; the byte compiled file(s) for them will contain the | |
86 ;; compiled runtime constants ready for use by (the byte compiled) CC | |
87 ;; Mode, and the source definitions in this file don't have to be | |
88 ;; loaded then. However, if a byte compiled package is loaded that | |
89 ;; has been compiled with a different version of CC Mode than the one | |
90 ;; currently loaded, then the compiled-in values will be discarded and | |
91 ;; new ones will be built when the mode is initialized. That will | |
92 ;; automatically trig a load of the file(s) containing the source | |
93 ;; definitions (i.e. this file and/or cc-fonts.el) if necessary. | |
94 ;; | |
95 ;; A small example of a derived mode is available at | |
96 ;; <http://cc-mode.sourceforge.net/derived-mode-ex.el>. It also | |
97 ;; contains some useful hints for derived mode developers. | |
98 | |
99 ;;; Using language variables: | |
100 ;; | |
101 ;; The `c-lang-defvar' forms in this file comprise the language | |
102 ;; variables that CC Mode uses. It does not work to use | |
103 ;; `c-lang-defvar' anywhere else (which isn't much of a limitation | |
104 ;; since these variables sole purpose is to interface with the CC Mode | |
105 ;; core functions). The values in these `c-lang-defvar's are not | |
106 ;; evaluated right away but instead collected to a single large `setq' | |
107 ;; that can be inserted for a particular language with the | |
108 ;; `c-init-language-vars' macro. | |
109 | |
110 ;; This file is only required at compile time, or when not running | |
111 ;; from byte compiled files, or when the source definitions for the | |
112 ;; language constants are requested. | |
113 | |
34 ;;; Code: | 114 ;;; Code: |
35 | 115 |
36 (eval-when-compile | 116 (eval-when-compile |
37 (let ((load-path | 117 (let ((load-path |
38 (if (and (boundp 'byte-compile-dest-file) | 118 (if (and (boundp 'byte-compile-dest-file) |
39 (stringp byte-compile-dest-file)) | 119 (stringp byte-compile-dest-file)) |
40 (cons (file-name-directory byte-compile-dest-file) load-path) | 120 (cons (file-name-directory byte-compile-dest-file) load-path) |
41 load-path))) | 121 load-path))) |
42 (require 'cc-bytecomp))) | 122 (load "cc-bytecomp" nil t))) |
43 | 123 |
44 (cc-require 'cc-defs) | 124 (cc-require 'cc-defs) |
45 (cc-require 'cc-vars) | 125 (cc-require 'cc-vars) |
46 | 126 |
47 | 127 |
48 ;; Some support functions that are used when the language specific | 128 ;;; Setup for the `c-lang-defvar' system. |
49 ;; constants are built. Since the constants are built during compile | |
50 ;; time, these need to be defined then too. | |
51 | 129 |
52 (eval-and-compile | 130 (eval-and-compile |
53 ;; `require' in XEmacs doesn't have the third NOERROR argument. | 131 ;; These are used to collect the init forms from the subsequent |
54 (condition-case nil (require 'regexp-opt) (file-error nil)) | 132 ;; `c-lang-defvar'. They are used to build the lambda in |
55 | 133 ;; `c-make-init-lang-vars-fun' below. |
56 (if (fboundp 'regexp-opt) | 134 (defconst c-lang-variable-inits (list nil)) |
57 (fset 'c-regexp-opt (symbol-function 'regexp-opt)) | 135 (defconst c-lang-variable-inits-tail c-lang-variable-inits)) |
58 ;; Emacs 19.34 doesn't have the regexp-opt package. | 136 |
59 (defun c-regexp-opt (strings &optional paren) | 137 (defmacro c-lang-defvar (var val &optional doc) |
60 (if paren | 138 "Declares the buffer local variable VAR to get the value VAL at mode |
61 (concat "\\(" (mapconcat 'regexp-quote strings "\\|") "\\)") | 139 initialization, at which point VAL is evaluated. More accurately, VAL |
62 (mapconcat 'regexp-quote strings "\\|")))) | 140 is evaluated and bound to VAR when the result from the macro |
63 | 141 `c-init-language-vars' is evaluated. |
64 (if (fboundp 'regexp-opt-depth) | 142 |
65 (fset 'c-regexp-opt-depth (symbol-function 'regexp-opt-depth)) | 143 `c-lang-const' is typically used in VAL to get the right value for the |
66 ;; Emacs 19.34 doesn't have the regexp-opt package. | 144 language being initialized, and such calls will be macro expanded to |
67 (defun c-regexp-opt-depth (regexp) | 145 the evaluated constant value at compile time. |
68 ;; This is the definition of `regexp-opt-depth' in Emacs 20. | 146 |
69 (save-match-data | 147 This macro does not do any hidden buffer changes." |
70 ;; Hack to signal an error if REGEXP does not have balanced | 148 |
71 ;; parentheses. | 149 (when (and (not doc) |
72 (string-match regexp "") | 150 (eq (car-safe val) 'c-lang-const) |
73 ;; Count the number of open parentheses in REGEXP. | 151 (eq (nth 1 val) var) |
74 (let ((count 0) start) | 152 (not (nth 2 val))) |
75 (while (string-match "\\\\(" regexp start) | 153 ;; Special case: If there's no docstring and the value is a |
76 (setq count (1+ count) start (match-end 0))) | 154 ;; simple (c-lang-const foo) where foo is the same name as VAR |
77 count)))) | 155 ;; then take the docstring from the language constant foo. |
78 | 156 (setq doc (get (intern (symbol-name (nth 1 val)) c-lang-constants) |
79 (defun c-delete-duplicates (list) | 157 'variable-documentation))) |
80 (let ((tail list)) | 158 (or (stringp doc) |
81 (while tail | 159 (setq doc nil)) |
82 (setcdr tail (delete (car tail) (cdr tail))) | 160 |
83 (setq tail (cdr tail))) | 161 (let ((elem (assq var (cdr c-lang-variable-inits)))) |
84 list)) | 162 (if elem |
85 | 163 (setcdr elem (list val doc)) |
86 (defun c-make-keywords-re (adorn &rest lists) | 164 (setcdr c-lang-variable-inits-tail (list (list var val doc))) |
87 "Make a regexp that matches all the strings in all the lists. | 165 (setq c-lang-variable-inits-tail (cdr c-lang-variable-inits-tail)))) |
88 Duplicates in the lists are removed. The regexp may contain zero or | 166 |
89 more submatch expressions. If ADORN is non-nil there will be at least | 167 ;; Return the symbol, like the other def* forms. |
90 one submatch which matches the whole keyword, and the regexp will also | 168 `',var) |
91 not match a prefix of any identifier. Adorned regexps cannot be | 169 |
92 appended." | 170 (put 'c-lang-defvar 'lisp-indent-function 'defun) |
93 (let ((list (copy-sequence (apply 'append lists)))) | 171 (eval-after-load "edebug" |
94 (setq list (c-delete-duplicates list)) | 172 '(def-edebug-spec c-lang-defvar |
95 (if list | 173 (&define name def-form &optional stringp))) |
96 (let ((re (c-regexp-opt list))) | |
97 ;; Add our own grouping parenthesis around re instead of | |
98 ;; passing adorn to regexp-opt, since it in XEmacs makes the | |
99 ;; top level grouping "shy". | |
100 (if adorn | |
101 (concat "\\(" re "\\)\\>\\([^_]\\|$\\)") | |
102 re)) | |
103 "\\<\\>" ; Matches nothing. | |
104 ))) | |
105 (put 'c-make-keywords-re 'lisp-indent-function 1) | |
106 ) | |
107 | 174 |
108 | 175 |
109 ;; Building of constants that are parameterized on a per-language | 176 ;;; Various mode specific values that aren't language related. |
110 ;; basis. | 177 |
111 | 178 (c-lang-defconst c-mode-menu |
112 (eval-and-compile | 179 ;; The definition for the mode menu. The menu title is prepended to |
113 (defvar c-macroexpand-mode nil | 180 ;; this before it's fed to `easy-menu-define'. |
114 ;; Dynamically bound to the mode symbol during `c-lang-defconst' | 181 t `(["Comment Out Region" comment-region |
115 ;; so that `c-lang-var' can do the right expansion. | 182 (c-fn-region-is-active-p)] |
116 ) | 183 ["Uncomment Region" (comment-region (region-beginning) |
117 | 184 (region-end) '(4)) |
118 (defmacro c-lang-defconst (var &rest args) | 185 (c-fn-region-is-active-p)] |
119 ;; Sets the mode specific values of the constant VAR. The rest of | 186 ["Indent Expression" c-indent-exp |
120 ;; the arguments are one or more repetitions of MODE VAL. MODE is | 187 (memq (char-after) '(?\( ?\[ ?\{))] |
121 ;; the mode name without the "-mode" suffix, or a list of such | 188 ["Indent Line or Region" c-indent-line-or-region t] |
122 ;; mode names, or `all' as a shortcut for a list of all modes. | 189 ["Fill Comment Paragraph" c-fill-paragraph t] |
123 ;; VAL is evaluated (during compilation) for each mode with | 190 "----" |
124 ;; `c-macroexpand-mode' temporarily bound, so `c-lang-var' without | 191 ["Backward Statement" c-beginning-of-statement t] |
125 ;; an explicit mode may be used within it. The assignments in | 192 ["Forward Statement" c-end-of-statement t] |
126 ;; ARGS are processed in sequence, similar to `setq'. | 193 ,@(when (c-lang-const c-opt-cpp-prefix) |
127 (let* ((res (list 'progn)) | 194 ;; Only applicable if there's a cpp preprocessor. |
128 (res-tail res)) | 195 `(["Up Conditional" c-up-conditional t] |
129 (while args | 196 ["Backward Conditional" c-backward-conditional t] |
130 (let ((mode (car args))) | 197 ["Forward Conditional" c-forward-conditional t] |
131 (cond ((eq mode 'all) | 198 "----" |
132 (setq mode '(c c++ objc java idl pike))) | 199 ["Macro Expand Region" c-macro-expand |
133 ((symbolp mode) | 200 (c-fn-region-is-active-p)] |
134 (setq mode (list mode)))) | 201 ["Backslashify" c-backslash-region |
135 (while mode | 202 (c-fn-region-is-active-p)])) |
136 (let* ((c-macroexpand-mode | 203 "----" |
137 (intern (concat (symbol-name (car mode)) "-mode"))) | 204 ("Toggle..." |
138 (val (eval (car (cdr args))))) | 205 ["Syntactic indentation" c-toggle-syntactic-indentation t] |
139 ;; Need to install the value also during compilation, | 206 ["Auto newline" c-toggle-auto-state t] |
140 ;; since val might refer to earlier mode specific | 207 ["Hungry delete" c-toggle-hungry-state t]))) |
141 ;; values. | |
142 (put var c-macroexpand-mode val) | |
143 (setcdr res-tail (list `(put ',var ',c-macroexpand-mode ',val))) | |
144 (setq res-tail (cdr res-tail))) | |
145 (setq mode (cdr mode)))) | |
146 (setq args (cdr (cdr args)))) | |
147 res)) | |
148 (put 'c-lang-defconst 'lisp-indent-function 1) | |
149 | |
150 (defmacro c-lang-var (var &optional mode) | |
151 ;; Get the mode specific value of the variable VAR in mode MODE. | |
152 ;; MODE is the mode name without the "-mode" suffix. It may also | |
153 ;; be nil to use the current value of `c-macroexpand-mode' (which | |
154 ;; is useful inside `c-lang-defconst') or `c-buffer-is-cc-mode' | |
155 ;; (which is useful inside `c-lang-defvar'). | |
156 `(get ',var ,(if (eq mode 'nil) | |
157 (if c-macroexpand-mode | |
158 ;; In the macro expansion of c-lang-defconst. | |
159 `(quote ,c-macroexpand-mode) | |
160 `c-buffer-is-cc-mode) | |
161 `(quote ,(intern (concat (symbol-name mode) "-mode")))))) | |
162 | |
163 ;; These are used to collect the init forms from the subsequent | |
164 ;; `c-lang-defvar'. They become a big setq in the | |
165 ;; `c-init-lang-defvars' lambda below. | |
166 (defconst c-lang-defvar-init-form (list 'setq)) | |
167 (defvar c-lang-defvar-init-form-tail nil) | |
168 (setq c-lang-defvar-init-form-tail c-lang-defvar-init-form) | |
169 | |
170 (defmacro c-lang-defvar (var val) | |
171 ;; Declares the buffer local variable VAR to get the value VAL at | |
172 ;; mode initialization, at which point VAL is evaluated. | |
173 ;; `c-lang-var' is typically used in VAL to get the right value | |
174 ;; according to `c-buffer-is-cc-mode'. | |
175 (setcdr c-lang-defvar-init-form-tail (list var val)) | |
176 (setq c-lang-defvar-init-form-tail | |
177 (cdr (cdr c-lang-defvar-init-form-tail))) | |
178 `(progn | |
179 (defvar ,var nil) | |
180 (make-variable-buffer-local ',var))) | |
181 (put 'c-lang-defvar 'lisp-indent-function 1) | |
182 ) | |
183 | |
184 ;; Regexp describing a `symbol' in all languages, not excluding | |
185 ;; keywords. | |
186 (c-lang-defconst c-symbol-key | |
187 (c c++ objc java idl) | |
188 (if (string-match "[[:alpha:]]" "a") | |
189 "[[:alpha:]_][[:alnum:]_]*" ; Emacs 21. | |
190 ;; We cannot use just `word' syntax class since `_' cannot be | |
191 ;; in word class. Putting underscore in word class breaks | |
192 ;; forward word movement behavior that users are familiar | |
193 ;; with. Besides, it runs counter to Emacs convention. | |
194 "[a-zA-Z_]\\(\\w\\|_\\)*") | |
195 pike (concat "\\(" (c-lang-var c-symbol-key c) "\\|" | |
196 (c-make-keywords-re nil | |
197 '("`+" "`-" "`&" "`|" "`^" "`<<" "`>>" "`*" "`/" "`%" "`~" | |
198 "`==" "`<" "`>" "`!" "`[]" "`[]=" "`->" "`->=" "`()" "``+" | |
199 "``-" "``&" "``|" "``^" "``<<" "``>>" "``*" "``/" "``%" | |
200 "`+=")) | |
201 "\\)")) | |
202 (c-lang-defvar c-symbol-key (c-lang-var c-symbol-key)) | |
203 | |
204 ;; Number of regexp grouping parens in c-symbol-key. | |
205 (c-lang-defvar c-symbol-key-depth (c-regexp-opt-depth c-symbol-key)) | |
206 | |
207 (defvar c-stmt-delim-chars "^;{}?:") | |
208 ;; The characters that should be considered to bound statements. To | |
209 ;; optimize c-crosses-statement-barrier-p somewhat, it's assumed to | |
210 ;; begin with "^" to negate the set. If ? : operators should be | |
211 ;; detected then the string must end with "?:". | |
212 | |
213 (defvar c-stmt-delim-chars-with-comma "^;,{}?:") | |
214 ;; Variant of c-stmt-delim-chars that additionally contains ','. | |
215 | |
216 ;; HELPME: Many of the following keyword lists are more or less bogus | |
217 ;; for some languages (notably ObjC and IDL). The effects of the | |
218 ;; erroneous values in the language handling are mostly negligible | |
219 ;; since the constants that actually matter in the syntax detection | |
220 ;; code are mostly correct in the situations they are used, but I'd | |
221 ;; still appreciate help to get them correct for other uses. | |
222 | |
223 ;; Primitive type keywords. | |
224 (c-lang-defconst c-primitive-type-kwds | |
225 (c c++ objc idl) '("char" "double" "float" "int" "long" "short" | |
226 "signed" "unsigned" "void") | |
227 java '("boolean" "byte" "char" "double" "float" "int" "long" "short" "void") | |
228 pike '("constant" "float" "int" "mapping" "multiset" "object" "program" | |
229 "string" "void")) | |
230 | |
231 ;; Declaration specifier keywords. | |
232 (c-lang-defconst c-specifier-kwds | |
233 c '("auto" "const" "extern" "register" "static" "volatile") | |
234 (c++ objc idl) (append '("friend" "inline" "virtual") | |
235 (c-lang-var c-specifier-kwds c)) | |
236 ;; Note: `const' is not used in Java, but it's still a reserved keyword. | |
237 java '("abstract" "const" "final" "native" "private" "protected" | |
238 "public" "static" "synchronized" "transient" "volatile") | |
239 pike '("final" "inline" "local" "nomask" "optional" "private" | |
240 "protected" "static" "variant")) | |
241 | |
242 ;; Class/struct declaration keywords. | |
243 (c-lang-defconst c-class-kwds | |
244 c '("struct" "union") | |
245 c++ '("class" "struct" "union") | |
246 objc '("interface" "implementation") | |
247 java '("class" "interface") | |
248 idl '("interface" "valuetype" "class" "struct" "union") | |
249 pike '("class")) | |
250 | |
251 ;; Regexp matching the start of a class. | |
252 (c-lang-defconst c-class-key | |
253 all (c-make-keywords-re t (c-lang-var c-class-kwds))) | |
254 (c-lang-defconst c-class-key ; ObjC needs some tuning of the regexp. | |
255 objc (concat "@" (c-lang-var c-class-key))) | |
256 (c-lang-defvar c-class-key (c-lang-var c-class-key)) | |
257 | |
258 ;; Keywords introducing blocks besides classes that contain another | |
259 ;; declaration level. | |
260 (c-lang-defconst c-other-decl-block-kwds | |
261 c '("extern") | |
262 c++ '("namespace" "extern") | |
263 idl '("module")) | |
264 | |
265 ;; Regexp matching the start of blocks besides classes that contain | |
266 ;; another declaration level. | |
267 (c-lang-defconst c-other-decl-block-key | |
268 all (c-make-keywords-re t (c-lang-var c-other-decl-block-kwds))) | |
269 (c-lang-defvar c-other-decl-block-key (c-lang-var c-other-decl-block-key)) | |
270 | |
271 ;; Keywords introducing declarations that can contain a block which | |
272 ;; might be followed by variable declarations, e.g. like "foo" in | |
273 ;; "class Foo { ... } foo;". So if there is a block in a declaration | |
274 ;; like that, it ends with the following ';' and not right away. | |
275 (c-lang-defconst c-block-decls-with-vars | |
276 c '("struct" "union" "enum" "typedef") | |
277 c++ '("class" "struct" "union" "enum" "typedef")) | |
278 | |
279 ;; Regexp matching the `c-block-decls-with-vars' keywords, or nil in | |
280 ;; languages without such constructs. | |
281 (c-lang-defconst c-opt-block-decls-with-vars-key | |
282 all (and (c-lang-var c-block-decls-with-vars) | |
283 (c-make-keywords-re t (c-lang-var c-block-decls-with-vars)))) | |
284 (c-lang-defvar c-opt-block-decls-with-vars-key | |
285 (c-lang-var c-opt-block-decls-with-vars-key)) | |
286 | |
287 ;; Keywords introducing declarations that has not been accounted for | |
288 ;; by any of the above. | |
289 (c-lang-defconst c-other-decl-kwds | |
290 ;; FIXME: Shouldn't "template" be moved to c-specifier-kwds for C++? | |
291 c++ '("template") | |
292 java '("import" "package") | |
293 pike '("import" "inherit")) | |
294 | |
295 ;; Keywords introducing extra declaration specifiers in the region | |
296 ;; between the header and the body (i.e. the "K&R-region") in | |
297 ;; declarations. | |
298 (c-lang-defconst c-decl-spec-kwds java '("extends" "implements" "throws")) | |
299 | |
300 ;; Protection label keywords in classes. | |
301 (c-lang-defconst c-protection-kwds | |
302 (c++ objc) '("private" "protected" "public")) | |
303 | |
304 ;; Statement keywords followed directly by a substatement. | |
305 (c-lang-defconst c-block-stmt-1-kwds | |
306 (c pike) '("do" "else") | |
307 (c++ objc) '("do" "else" "asm" "try") | |
308 java '("do" "else" "finally" "try")) | |
309 | |
310 ;; Regexp matching the start of any statement followed directly by a | |
311 ;; substatement (doesn't match a bare block, however). | |
312 (c-lang-defconst c-block-stmt-1-key | |
313 all (c-make-keywords-re t (c-lang-var c-block-stmt-1-kwds))) | |
314 (c-lang-defvar c-block-stmt-1-key (c-lang-var c-block-stmt-1-key)) | |
315 | |
316 ;; Statement keywords followed by a paren sexp and then by a substatement. | |
317 (c-lang-defconst c-block-stmt-2-kwds | |
318 c '("for" "if" "switch" "while") | |
319 (c++ objc) '("for" "if" "switch" "while" "catch") | |
320 java '("for" "if" "switch" "while" "catch" "synchronized") | |
321 pike '("for" "if" "switch" "while" "foreach")) | |
322 | |
323 ;; Regexp matching the start of any statement followed by a paren sexp | |
324 ;; and then by a substatement. | |
325 (c-lang-defconst c-block-stmt-2-key | |
326 all (c-make-keywords-re t (c-lang-var c-block-stmt-2-kwds))) | |
327 (c-lang-defvar c-block-stmt-2-key (c-lang-var c-block-stmt-2-key)) | |
328 | |
329 ;; Regexp matching the start of any statement that has a substatement | |
330 ;; (except a bare block). Nil in languages that doesn't have such | |
331 ;; constructs. | |
332 (c-lang-defconst c-opt-block-stmt-key | |
333 all (if (or (c-lang-var c-block-stmt-1-kwds) | |
334 (c-lang-var c-block-stmt-2-kwds)) | |
335 (c-make-keywords-re t | |
336 (c-lang-var c-block-stmt-1-kwds) | |
337 (c-lang-var c-block-stmt-2-kwds)))) | |
338 (c-lang-defvar c-opt-block-stmt-key (c-lang-var c-opt-block-stmt-key)) | |
339 | |
340 ;; Statement keywords followed by an expression or nothing. | |
341 (c-lang-defconst c-simple-stmt-kwds | |
342 (c c++ objc) '("break" "continue" "goto" "return") | |
343 ;; Note: `goto' is not valid in Java, but the keyword is still reserved. | |
344 java '("break" "continue" "goto" "return" "throw") | |
345 pike '("break" "continue" "return")) | |
346 | |
347 ;; Statement keywords followed by an assembler expression. | |
348 (c-lang-defconst c-asm-stmt-kwds | |
349 (c c++) '("asm" "__asm__")) | |
350 | |
351 ;; Regexp matching the start of an assembler statement. Nil in | |
352 ;; languages that doesn't support that. | |
353 (c-lang-defconst c-opt-asm-stmt-key | |
354 all (if (c-lang-var c-asm-stmt-kwds) | |
355 (c-make-keywords-re t (c-lang-var c-asm-stmt-kwds)))) | |
356 (c-lang-defvar c-opt-asm-stmt-key (c-lang-var c-opt-asm-stmt-key)) | |
357 | |
358 ;; Keywords introducing labels in blocks. | |
359 (c-lang-defconst c-label-kwds (c c++ objc java pike) '("case" "default")) | |
360 | |
361 ;; Regexp matching any keyword that introduces a label. | |
362 (c-lang-defconst c-label-kwds-regexp | |
363 all (c-make-keywords-re t (c-lang-var c-label-kwds))) | |
364 (c-lang-defvar c-label-kwds-regexp (c-lang-var c-label-kwds-regexp)) | |
365 | |
366 ;; Keywords that can occur anywhere in expressions. | |
367 (c-lang-defconst c-expr-kwds | |
368 (c objc) '("sizeof") | |
369 c++ '("sizeof" "delete" "new" "operator" "this" "throw") | |
370 java '("instanceof" "new" "super" "this") | |
371 pike '("sizeof" "catch" "class" "gauge" "lambda" "predef")) | |
372 | |
373 ;; Keywords that start lambda constructs, i.e. function definitions in | |
374 ;; expressions. | |
375 (c-lang-defconst c-lambda-kwds pike '("lambda")) | |
376 | |
377 ;; Regexp matching the start of lambda constructs, or nil in languages | |
378 ;; that doesn't have such things. | |
379 (c-lang-defconst c-opt-lambda-key | |
380 pike (c-make-keywords-re t (c-lang-var c-lambda-kwds))) | |
381 (c-lang-defvar c-opt-lambda-key (c-lang-var c-opt-lambda-key)) | |
382 | |
383 ;; Keywords that start constructs followed by statement blocks which | |
384 ;; can be used in expressions (the gcc extension for this in C and C++ | |
385 ;; is handled separately). | |
386 (c-lang-defconst c-inexpr-block-kwds pike '("catch" "gauge")) | |
387 | |
388 ;; Regexp matching the start of in-expression statements, or nil in | |
389 ;; languages that doesn't have such things. | |
390 (c-lang-defconst c-opt-inexpr-block-key | |
391 pike (c-make-keywords-re t (c-lang-var c-inexpr-block-kwds))) | |
392 (c-lang-defvar c-opt-inexpr-block-key (c-lang-var c-opt-inexpr-block-key)) | |
393 | |
394 ;; Keywords that start classes in expressions. | |
395 (c-lang-defconst c-inexpr-class-kwds | |
396 java '("new") | |
397 pike '("class")) | |
398 | |
399 ;; Regexp matching the start of a class in an expression, or nil in | |
400 ;; languages that doesn't have such things. | |
401 (c-lang-defconst c-opt-inexpr-class-key | |
402 (java pike) (c-make-keywords-re t (c-lang-var c-inexpr-class-kwds))) | |
403 (c-lang-defvar c-opt-inexpr-class-key (c-lang-var c-opt-inexpr-class-key)) | |
404 | |
405 ;; Regexp matching the start of any class, both at top level and in | |
406 ;; expressions. | |
407 (c-lang-defconst c-any-class-key | |
408 all (c-make-keywords-re t | |
409 (c-lang-var c-class-kwds) | |
410 (c-lang-var c-inexpr-class-kwds))) | |
411 (c-lang-defconst c-any-class-key ; ObjC needs some tuning of the regexp. | |
412 objc (concat "@" (c-lang-var c-any-class-key))) | |
413 (c-lang-defvar c-any-class-key (c-lang-var c-any-class-key)) | |
414 | |
415 ;; Regexp matching the start of any declaration-level block that | |
416 ;; contain another declaration level, i.e. that isn't a function | |
417 ;; block. | |
418 (c-lang-defconst c-decl-block-key | |
419 all (c-make-keywords-re t | |
420 (c-lang-var c-class-kwds) | |
421 (c-lang-var c-other-decl-block-kwds) | |
422 (c-lang-var c-inexpr-class-kwds))) | |
423 (c-lang-defconst c-decl-block-key ; ObjC needs some tuning of the regexp. | |
424 objc (concat "@" (c-lang-var c-decl-block-key))) | |
425 (c-lang-defvar c-decl-block-key (c-lang-var c-decl-block-key)) | |
426 | |
427 ;; Keywords that can introduce bitfields. | |
428 (c-lang-defconst c-bitfield-kwds | |
429 (c c++) '("char" "int" "long" "signed" "unsigned")) | |
430 | |
431 ;; Regexp matching the start of a bitfield (not uniquely), or nil in | |
432 ;; languages without bitfield support. | |
433 (c-lang-defconst c-opt-bitfield-key | |
434 (c c++) (c-make-keywords-re t (c-lang-var c-bitfield-kwds))) | |
435 (c-lang-defvar c-opt-bitfield-key (c-lang-var c-opt-bitfield-key)) | |
436 | |
437 ;; All keywords as a list. | |
438 (c-lang-defconst c-keywords | |
439 all (c-delete-duplicates | |
440 (append (c-lang-var c-primitive-type-kwds) | |
441 (c-lang-var c-specifier-kwds) | |
442 (c-lang-var c-class-kwds) | |
443 (c-lang-var c-other-decl-block-kwds) | |
444 (c-lang-var c-block-decls-with-vars) | |
445 (c-lang-var c-other-decl-kwds) | |
446 (c-lang-var c-decl-spec-kwds) | |
447 (c-lang-var c-protection-kwds) | |
448 (c-lang-var c-block-stmt-1-kwds) | |
449 (c-lang-var c-block-stmt-2-kwds) | |
450 (c-lang-var c-simple-stmt-kwds) | |
451 (c-lang-var c-asm-stmt-kwds) | |
452 (c-lang-var c-label-kwds) | |
453 (c-lang-var c-expr-kwds) | |
454 (c-lang-var c-lambda-kwds) | |
455 (c-lang-var c-inexpr-block-kwds) | |
456 (c-lang-var c-inexpr-class-kwds) | |
457 (c-lang-var c-bitfield-kwds) | |
458 nil))) | |
459 (c-lang-defvar c-keywords (c-lang-var c-keywords)) | |
460 | |
461 ;; All keywords as an adorned regexp. | |
462 (c-lang-defconst c-keywords-regexp | |
463 all (c-make-keywords-re t (c-lang-var c-keywords))) | |
464 (c-lang-defvar c-keywords-regexp (c-lang-var c-keywords-regexp)) | |
465 | |
466 ;; Regexp matching an access protection label in a class, or nil in | |
467 ;; languages that doesn't have such things. | |
468 (c-lang-defconst c-opt-access-key | |
469 c++ (concat "\\(" | |
470 (c-make-keywords-re nil (c-lang-var c-protection-kwds)) | |
471 "\\)[ \t\n\r]*:")) | |
472 (c-lang-defconst c-opt-access-key | |
473 objc (concat "@" (c-make-keywords-re t (c-lang-var c-protection-kwds)))) | |
474 (c-lang-defvar c-opt-access-key (c-lang-var c-opt-access-key)) | |
475 | |
476 ;; Regexp matching a normal label, i.e. not a label that's recognized | |
477 ;; with a keyword, like switch labels. It's only used at the | |
478 ;; beginning of a statement. | |
479 (c-lang-defconst c-label-key | |
480 all (concat (c-lang-var c-symbol-key) "[ \t\n\r]*:\\([^:]\\|$\\)")) | |
481 (c-lang-defvar c-label-key (c-lang-var c-label-key)) | |
482 | |
483 ;; Regexp matching the beginning of a declaration specifier in the | |
484 ;; region between the header and the body of a declaration. | |
485 ;; | |
486 ;; FIXME: This is currently not used in a uniformly; c++-mode and | |
487 ;; java-mode each have their own ways of using it. | |
488 (c-lang-defconst c-opt-decl-spec-key | |
489 c++ (concat ":?[ \t\n\r]*\\(virtual[ \t\n\r]+\\)?\\(" | |
490 (c-make-keywords-re nil (c-lang-var c-protection-kwds)) | |
491 "\\)[ \t\n\r]+" | |
492 (c-lang-var c-symbol-key)) | |
493 java (c-make-keywords-re t (c-lang-var c-decl-spec-kwds))) | |
494 (c-lang-defvar c-opt-decl-spec-key (c-lang-var c-opt-decl-spec-key)) | |
495 | |
496 ;; Regexp describing friend declarations classes, or nil in languages | |
497 ;; that doesn't have such things. | |
498 (c-lang-defconst c-opt-friend-key | |
499 ;; FIXME: Ought to use c-specifier-kwds or similar, and the template | |
500 ;; skipping isn't done properly. | |
501 c++ "friend[ \t]+\\|template[ \t]*<.+>[ \t]*friend[ \t]+") | |
502 (c-lang-defvar c-opt-friend-key (c-lang-var c-opt-friend-key)) | |
503 | |
504 ;; Special regexp to match the start of methods. | |
505 (c-lang-defconst c-opt-method-key | |
506 objc (concat | |
507 "^\\s *[+-]\\s *" | |
508 "\\(([^)]*)\\)?" ; return type | |
509 ;; \\s- in objc syntax table does not include \n | |
510 ;; since it is considered the end of //-comments. | |
511 "[ \t\n]*" (c-lang-var c-symbol-key))) | |
512 (c-lang-defvar c-opt-method-key (c-lang-var c-opt-method-key)) | |
513 | |
514 ;; Name of functions in cpp expressions that take an identifier as the | |
515 ;; argument. | |
516 (c-lang-defconst c-cpp-defined-fns | |
517 (c c++) '("defined") | |
518 pike '("defined" "efun" "constant")) | |
519 | |
520 ;; List of open- and close-chars that makes up a pike-style brace | |
521 ;; list, i.e. for a `([ ])' list there should be a cons (?\[ . ?\]) in | |
522 ;; this list. | |
523 (c-lang-defconst c-special-brace-lists pike '((?{ . ?}) | |
524 (?\[ . ?\]) | |
525 (?< . ?>))) | |
526 (c-lang-defvar c-special-brace-lists (c-lang-var c-special-brace-lists)) | |
527 | |
528 ;; Non-nil means K&R style argument declarations are valid. | |
529 (c-lang-defconst c-recognize-knr-p c t) | |
530 (c-lang-defvar c-recognize-knr-p (c-lang-var c-recognize-knr-p)) | |
531 | |
532 ;; Regexp to match the start of any type of comment. | |
533 ;; | |
534 ;; FIXME: Ought to use c-comment-prefix-regexp with some modifications | |
535 ;; instead of this. | |
536 (c-lang-defconst c-comment-start-regexp | |
537 (c c++ objc idl pike) "/[/*]" | |
538 ;; We need to match all 3 Java style comments | |
539 ;; 1) Traditional C block; 2) javadoc /** ...; 3) C++ style | |
540 java "/\\(/\\|[*][*]?\\)") | |
541 (c-lang-defvar c-comment-start-regexp (c-lang-var c-comment-start-regexp)) | |
542 | |
543 ;; Strings that starts and ends comments inserted with M-; etc. | |
544 ;; comment-start and comment-end are initialized from these. | |
545 (c-lang-defconst comment-start | |
546 c "/* " | |
547 (c++ objc java idl pike) "// ") | |
548 (c-lang-defvar comment-start (c-lang-var comment-start)) | |
549 (c-lang-defconst comment-end | |
550 c "*/" | |
551 (c++ objc java idl pike) "") | |
552 (c-lang-defvar comment-end (c-lang-var comment-end)) | |
553 | |
554 ;; Regexp that matches when there is no syntactically significant text | |
555 ;; before eol. Macros are regarded as syntactically significant text | |
556 ;; here. | |
557 (c-lang-defvar c-syntactic-eol | |
558 (concat (concat | |
559 ;; Match horizontal whitespace and block comments that | |
560 ;; doesn't contain newlines. | |
561 "\\(\\s \\|" | |
562 (concat "/\\*" | |
563 "\\([^*\n\r]\\|\\*[^/\n\r]\\)*" | |
564 "\\*/") | |
565 "\\)*") | |
566 (concat | |
567 ;; Match eol (possibly inside a block comment), or the | |
568 ;; beginning of a line comment. Note: This has to be | |
569 ;; modified for awk where line comments start with '#'. | |
570 "\\(" | |
571 (concat "\\(" | |
572 "/\\*\\([^*\n\r]\\|\\*[^/\n\r]\\)*" | |
573 "\\)?" | |
574 "$") | |
575 "\\|//\\)"))) | |
576 | |
577 ;; Regexp to append to paragraph-start. | |
578 (c-lang-defconst paragraph-start | |
579 (c c++ objc idl) "$" | |
580 java "\\(@[a-zA-Z]+\\>\\|$\\)" ; For Javadoc. | |
581 pike "\\(@[a-zA-Z]+\\>\\([^{]\\|$\\)\\|$\\)") ; For Pike refdoc. | |
582 | |
583 ;; Regexp to append to paragraph-separate. | |
584 (c-lang-defconst paragraph-separate | |
585 (c c++ objc java idl) "$" | |
586 pike (c-lang-var paragraph-start)) | |
587 | |
588 ;; Prefix added to `c-current-comment-prefix' to set | |
589 ;; `c-opt-in-comment-lc', or nil if it should be nil. | |
590 (c-lang-defconst c-in-comment-lc-prefix pike "@[\n\r]\\s *") | |
591 | |
592 ;; Regexp to match in-comment line continuations, or nil in languages | |
593 ;; where that isn't applicable. It's assumed that it only might match | |
594 ;; from and including the last character on a line. Built from | |
595 ;; *-in-comment-lc-prefix and the current value of | |
596 ;; c-current-comment-prefix. | |
597 (c-lang-defvar c-opt-in-comment-lc | |
598 (if (c-lang-var c-in-comment-lc-prefix) | |
599 (concat (c-lang-var c-in-comment-lc-prefix) | |
600 c-current-comment-prefix))) | |
601 | |
602 (defconst c-init-lang-defvars | |
603 ;; Make a lambda of the collected `c-lang-defvar' initializations. | |
604 (cc-eval-when-compile | |
605 (if (cc-bytecomp-is-compiling) | |
606 (byte-compile-lambda `(lambda () ,c-lang-defvar-init-form)) | |
607 `(lambda () ,c-lang-defvar-init-form)))) | |
608 | |
609 (defun c-init-language-vars () | |
610 ;; Initialize all `c-lang-defvar' variables according to | |
611 ;; `c-buffer-is-cc-mode'. | |
612 (if (not (memq c-buffer-is-cc-mode | |
613 '(c-mode c++-mode objc-mode java-mode idl-mode pike-mode))) | |
614 (error "Cannot initialize language variables for unknown mode %s" | |
615 c-buffer-is-cc-mode)) | |
616 (funcall c-init-lang-defvars)) | |
617 | |
618 ;; Regexp trying to describe the beginning of a Java top-level | |
619 ;; definition. This is not used by CC Mode, nor is it maintained | |
620 ;; since it's practically impossible to write a regexp that reliably | |
621 ;; matches such a construct. Other tools are necessary. | |
622 (defconst c-Java-defun-prompt-regexp | |
623 "^[ \t]*\\(\\(\\(public\\|protected\\|private\\|const\\|abstract\\|synchronized\\|final\\|static\\|threadsafe\\|transient\\|native\\|volatile\\)\\s-+\\)*\\(\\(\\([[a-zA-Z][][_$.a-zA-Z0-9]*[][_$.a-zA-Z0-9]+\\|[[a-zA-Z]\\)\\s-*\\)\\s-+\\)\\)?\\(\\([[a-zA-Z][][_$.a-zA-Z0-9]*\\s-+\\)\\s-*\\)?\\([_a-zA-Z][^][ \t:;.,{}()=]*\\|\\([_$a-zA-Z][_$.a-zA-Z0-9]*\\)\\)\\s-*\\(([^);{}]*)\\)?\\([] \t]*\\)\\(\\s-*\\<throws\\>\\s-*\\(\\([_$a-zA-Z][_$.a-zA-Z0-9]*\\)[, \t\n\r\f]*\\)+\\)?\\s-*") | |
624 | 208 |
625 | 209 |
626 ;; Syntax tables. | 210 ;;; Syntax tables. |
627 | 211 |
628 (defun c-populate-syntax-table (table) | 212 (defun c-populate-syntax-table (table) |
629 ;; Populate the syntax TABLE | 213 "Populate the given syntax table as necessary for a C-like language. |
214 This includes setting ' and \" as string delimiters, and setting up | |
215 the comment syntax to handle both line style \"//\" and block style | |
216 \"/*\" \"*/\" comments." | |
217 | |
630 (modify-syntax-entry ?_ "_" table) | 218 (modify-syntax-entry ?_ "_" table) |
631 (modify-syntax-entry ?\\ "\\" table) | 219 (modify-syntax-entry ?\\ "\\" table) |
632 (modify-syntax-entry ?+ "." table) | 220 (modify-syntax-entry ?+ "." table) |
633 (modify-syntax-entry ?- "." table) | 221 (modify-syntax-entry ?- "." table) |
634 (modify-syntax-entry ?= "." table) | 222 (modify-syntax-entry ?= "." table) |
636 (modify-syntax-entry ?< "." table) | 224 (modify-syntax-entry ?< "." table) |
637 (modify-syntax-entry ?> "." table) | 225 (modify-syntax-entry ?> "." table) |
638 (modify-syntax-entry ?& "." table) | 226 (modify-syntax-entry ?& "." table) |
639 (modify-syntax-entry ?| "." table) | 227 (modify-syntax-entry ?| "." table) |
640 (modify-syntax-entry ?\' "\"" table) | 228 (modify-syntax-entry ?\' "\"" table) |
641 ;; Set up block and line oriented comments. The new C standard | 229 (modify-syntax-entry ?\240 "." table) |
642 ;; mandates both comment styles even in C, so since all languages | 230 |
643 ;; now require dual comments, we make this the default. | 231 ;; Set up block and line oriented comments. The new C |
232 ;; standard mandates both comment styles even in C, so since | |
233 ;; all languages now require dual comments, we make this the | |
234 ;; default. | |
644 (cond | 235 (cond |
645 ;; XEmacs 19 & 20 | 236 ;; XEmacs |
646 ((memq '8-bit c-emacs-features) | 237 ((memq '8-bit c-emacs-features) |
647 (modify-syntax-entry ?/ ". 1456" table) | 238 (modify-syntax-entry ?/ ". 1456" table) |
648 (modify-syntax-entry ?* ". 23" table)) | 239 (modify-syntax-entry ?* ". 23" table)) |
649 ;; Emacs 19 & 20 | 240 ;; Emacs |
650 ((memq '1-bit c-emacs-features) | 241 ((memq '1-bit c-emacs-features) |
651 (modify-syntax-entry ?/ ". 124b" table) | 242 (modify-syntax-entry ?/ ". 124b" table) |
652 (modify-syntax-entry ?* ". 23" table)) | 243 (modify-syntax-entry ?* ". 23" table)) |
653 ;; incompatible | 244 ;; incompatible |
654 (t (error "CC Mode is incompatible with this version of Emacs")) | 245 (t (error "CC Mode is incompatible with this version of Emacs"))) |
655 ) | 246 |
656 (modify-syntax-entry ?\n "> b" table) | 247 (modify-syntax-entry ?\n "> b" table) |
657 ;; Give CR the same syntax as newline, for selective-display | 248 ;; Give CR the same syntax as newline, for selective-display |
658 (modify-syntax-entry ?\^m "> b" table)) | 249 (modify-syntax-entry ?\^m "> b" table)) |
659 | 250 |
660 ;;;###autoload | 251 (c-lang-defconst c-make-mode-syntax-table |
661 (defvar c-mode-syntax-table nil | 252 "Functions that generates the mode specific syntax tables. |
662 "Syntax table used in c-mode buffers.") | 253 The syntax tables aren't stored directly since they're quite large." |
663 (if c-mode-syntax-table | 254 t `(lambda () |
664 () | 255 (let ((table (make-syntax-table))) |
665 (setq c-mode-syntax-table (make-syntax-table)) | 256 (c-populate-syntax-table table) |
666 (c-populate-syntax-table c-mode-syntax-table)) | 257 ;; Mode specific syntaxes. |
667 | 258 ,(cond ((c-major-mode-is 'objc-mode) |
668 ;;;###autoload | 259 `(modify-syntax-entry ?@ "_" table)) |
669 (defvar c++-mode-syntax-table nil | 260 ((c-major-mode-is 'pike-mode) |
670 "Syntax table used in c++-mode buffers.") | 261 `(modify-syntax-entry ?@ "." table))) |
671 (if c++-mode-syntax-table | 262 table))) |
672 () | 263 |
673 (setq c++-mode-syntax-table (make-syntax-table)) | 264 (c-lang-defconst c-mode-syntax-table |
674 (c-populate-syntax-table c++-mode-syntax-table)) | 265 ;; The syntax tables in evaluated form. Only used temporarily when |
675 | 266 ;; the constants in this file are evaluated. |
676 (defvar c++-template-syntax-table nil | 267 t (funcall (c-lang-const c-make-mode-syntax-table))) |
677 "A variant of `c++-mode-syntax-table' that defines `<' and `>' as | 268 |
678 parenthesis characters. Used temporarily when template argument lists | 269 (c-lang-defconst make-c++-template-syntax-table |
679 are parsed.") | 270 ;; A variant of `c++-mode-syntax-table' that defines `<' and `>' as |
680 (if c++-template-syntax-table | 271 ;; parenthesis characters. Used temporarily when template argument |
681 () | 272 ;; lists are parsed. Note that this encourages incorrect parsing of |
682 (setq c++-template-syntax-table | 273 ;; templates since they might contain normal operators that uses the |
683 (copy-syntax-table c++-mode-syntax-table)) | 274 ;; '<' and '>' characters. Therefore this syntax table might go |
684 (modify-syntax-entry ?< "(>" c++-template-syntax-table) | 275 ;; away when CC Mode handles templates correctly everywhere. |
685 (modify-syntax-entry ?> ")<" c++-template-syntax-table)) | 276 t nil |
686 | 277 c++ `(lambda () |
687 ;;;###autoload | 278 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table)))) |
688 (defvar objc-mode-syntax-table nil | 279 (modify-syntax-entry ?< "(>" table) |
689 "Syntax table used in objc-mode buffers.") | 280 (modify-syntax-entry ?> ")<" table) |
690 (if objc-mode-syntax-table | 281 table))) |
691 () | 282 (c-lang-defvar c++-template-syntax-table |
692 (setq objc-mode-syntax-table (make-syntax-table)) | 283 (and (c-lang-const make-c++-template-syntax-table) |
693 (c-populate-syntax-table objc-mode-syntax-table) | 284 (funcall (c-lang-const make-c++-template-syntax-table)))) |
694 ;; add extra Objective-C only syntax | 285 |
695 (modify-syntax-entry ?@ "_" objc-mode-syntax-table)) | 286 (c-lang-defconst c-identifier-syntax-modifications |
696 | 287 "A list that describes the modifications that should be done to the |
697 ;;;###autoload | 288 mode syntax table to get a syntax table that matches all identifiers |
698 (defvar java-mode-syntax-table nil | 289 and keywords as words. |
699 "Syntax table used in java-mode buffers.") | 290 |
700 (if java-mode-syntax-table | 291 The list is just like the one used in `font-lock-defaults': Each |
701 () | 292 element is a cons where the car is the character to modify and the cdr |
702 (setq java-mode-syntax-table (make-syntax-table)) | 293 the new syntax, as accepted by `modify-syntax-entry'." |
703 (c-populate-syntax-table java-mode-syntax-table)) | 294 ;; The $ character is not allowed in most languages (one exception |
704 | 295 ;; is Java which allows it for legacy reasons) but we still classify |
705 ;;;###autoload | 296 ;; it as an indentifier character since it's often used in various |
706 (defvar idl-mode-syntax-table nil | 297 ;; machine generated identifiers. |
707 "Syntax table used in idl-mode buffers.") | 298 t '((?_ . "w") (?$ . "w")) |
708 (if idl-mode-syntax-table | 299 objc (append '((?@ . "w")) |
709 nil | 300 (c-lang-const c-identifier-syntax-modifications)) |
710 (setq idl-mode-syntax-table (make-syntax-table)) | 301 awk '((?_ . "w"))) |
711 (c-populate-syntax-table idl-mode-syntax-table)) | 302 (c-lang-defvar c-identifier-syntax-modifications |
712 | 303 (c-lang-const c-identifier-syntax-modifications)) |
713 ;;;###autoload | 304 |
714 (defvar pike-mode-syntax-table nil | 305 (c-lang-defvar c-identifier-syntax-table |
715 "Syntax table used in pike-mode buffers.") | 306 (let ((table (copy-syntax-table (c-mode-var "mode-syntax-table"))) |
716 (if pike-mode-syntax-table | 307 (mods c-identifier-syntax-modifications) |
717 () | 308 mod) |
718 (setq pike-mode-syntax-table (make-syntax-table)) | 309 (while mods |
719 (c-populate-syntax-table pike-mode-syntax-table) | 310 (setq mod (car mods) |
720 (modify-syntax-entry ?@ "." pike-mode-syntax-table)) | 311 mods (cdr mods)) |
312 (modify-syntax-entry (car mod) (cdr mod) table)) | |
313 table) | |
314 "Syntax table built on the mode syntax table but additionally | |
315 classifies symbol constituents like '_' and '$' as word constituents, | |
316 so that all identifiers are recognized as words.") | |
721 | 317 |
722 | 318 |
723 ;; internal state variables | 319 ;;; Lexer-level syntax (identifiers, tokens etc). |
724 | 320 |
725 ;; Internal state of hungry delete key feature | 321 (c-lang-defconst c-symbol-start |
726 (defvar c-hungry-delete-key nil) | 322 "Regexp that matches the start of a symbol, i.e. any identifier or |
727 (make-variable-buffer-local 'c-hungry-delete-key) | 323 keyword. It's unspecified how far it matches. Does not contain a \\| |
728 | 324 operator at the top level." |
729 ;; Internal state of auto newline feature. | 325 t (concat "[" c-alpha "_]") |
730 (defvar c-auto-newline nil) | 326 pike (concat "[" c-alpha "_`]")) |
731 (make-variable-buffer-local 'c-auto-newline) | 327 (c-lang-defvar c-symbol-start (c-lang-const c-symbol-start)) |
732 | 328 |
733 ;; Internal auto-newline/hungry-delete designation string for mode line. | 329 (c-lang-defconst c-symbol-chars |
734 (defvar c-auto-hungry-string nil) | 330 "Set of characters that can be part of a symbol. |
735 (make-variable-buffer-local 'c-auto-hungry-string) | 331 This is on the form that fits inside [ ] in a regexp." |
332 ;; Pike note: With the backquote identifiers this would include most | |
333 ;; operator chars too, but they are handled with other means instead. | |
334 t (concat c-alnum "_$") | |
335 objc (concat c-alnum "_$@")) | |
336 | |
337 (c-lang-defconst c-symbol-key | |
338 "Regexp matching identifiers and keywords. Assumed to match if | |
339 `c-symbol-start' matches on the same position." | |
340 t (concat (c-lang-const c-symbol-start) | |
341 "[" (c-lang-const c-symbol-chars) "]*") | |
342 pike (concat | |
343 ;; Use the value from C here since the operator backquote is | |
344 ;; covered by the other alternative. | |
345 (c-lang-const c-symbol-key c) | |
346 "\\|" | |
347 (c-make-keywords-re nil | |
348 (c-lang-const c-overloadable-operators)))) | |
349 (c-lang-defvar c-symbol-key (c-lang-const c-symbol-key)) | |
350 | |
351 (c-lang-defconst c-symbol-key-depth | |
352 ;; Number of regexp grouping parens in `c-symbol-key'. | |
353 t (c-regexp-opt-depth (c-lang-const c-symbol-key))) | |
354 | |
355 (c-lang-defconst c-nonsymbol-chars | |
356 "This is the set of chars that can't be part of a symbol, i.e. the | |
357 negation of `c-symbol-chars'." | |
358 t (concat "^" (c-lang-const c-symbol-chars))) | |
359 (c-lang-defvar c-nonsymbol-chars (c-lang-const c-nonsymbol-chars)) | |
360 | |
361 (c-lang-defconst c-nonsymbol-key | |
362 "Regexp that matches any character that can't be part of a symbol. | |
363 It's usually appended to other regexps to avoid matching a prefix. | |
364 It's assumed to not contain any submatchers." | |
365 ;; The same thing regarding Unicode identifiers applies here as to | |
366 ;; `c-symbol-key'. | |
367 t (concat "[" (c-lang-const c-nonsymbol-chars) "]")) | |
368 | |
369 (c-lang-defconst c-opt-identifier-concat-key | |
370 "Regexp matching the operators that join symbols to fully qualified | |
371 identifiers, or nil in languages that don't have such things. Does | |
372 not contain a \\| operator at the top level." | |
373 t nil | |
374 c++ "::" | |
375 java "\\." | |
376 idl "::" | |
377 pike "\\(::\\|\\.\\)") | |
378 (c-lang-defvar c-opt-identifier-concat-key | |
379 (c-lang-const c-opt-identifier-concat-key) | |
380 'dont-doc) | |
381 | |
382 (c-lang-defconst c-opt-after-id-concat-key | |
383 "Regexp that must match the token after `c-opt-identifier-concat-key' | |
384 for it to be considered an identifier concatenation operator (which | |
385 e.g. causes the preceding identifier to be fontified as a reference). | |
386 Assumed to be a string if `c-opt-identifier-concat-key' is." | |
387 t (if (c-lang-const c-opt-identifier-concat-key) | |
388 (c-lang-const c-symbol-start)) | |
389 c++ (concat (c-lang-const c-symbol-start) | |
390 "\\|[~*]") | |
391 java (concat (c-lang-const c-symbol-start) | |
392 "\\|\\*")) | |
393 | |
394 (c-lang-defconst c-identifier-start | |
395 "Regexp that matches the start of an \(optionally qualified) | |
396 identifier. It should also match all keywords. It's unspecified how | |
397 far it matches." | |
398 t (concat (c-lang-const c-symbol-start) | |
399 (if (c-lang-const c-opt-identifier-concat-key) | |
400 (concat "\\|" (c-lang-const c-opt-identifier-concat-key)) | |
401 "")) | |
402 c++ (concat (c-lang-const c-identifier-start) | |
403 "\\|" | |
404 "[~*][ \t\n\r\f\v]*" (c-lang-const c-symbol-start)) | |
405 ;; Java does not allow a leading qualifier operator. | |
406 java (c-lang-const c-symbol-start)) | |
407 (c-lang-defvar c-identifier-start (c-lang-const c-identifier-start)) | |
408 | |
409 (c-lang-defconst c-identifier-key | |
410 "Regexp matching a fully qualified identifier, like \"A::B::c\" in | |
411 C++. It does not recognize the full range of syntactic whitespace | |
412 between the tokens; `c-forward-name' has to be used for that." | |
413 t (c-lang-const c-symbol-key) ; Default to `c-symbol-key'. | |
414 ;; C++ allows a leading qualifier operator and a `~' before the last | |
415 ;; symbol. This regexp is more complex than strictly necessary to | |
416 ;; ensure that it can be matched with a minimum of backtracking. | |
417 c++ (concat | |
418 "\\(" (c-lang-const c-opt-identifier-concat-key) "[ \t\n\r\f\v]*\\)?" | |
419 (concat | |
420 "\\(" | |
421 ;; The submatch below is depth of `c-opt-identifier-concat-key' + 3. | |
422 "\\(" (c-lang-const c-symbol-key) "\\)" | |
423 (concat "\\(" | |
424 "[ \t\n\r\f\v]*" | |
425 (c-lang-const c-opt-identifier-concat-key) | |
426 "[ \t\n\r\f\v]*" | |
427 ;; The submatch below is: `c-symbol-key-depth' + | |
428 ;; 2 * depth of `c-opt-identifier-concat-key' + 5. | |
429 "\\(" (c-lang-const c-symbol-key) "\\)" | |
430 "\\)*") | |
431 (concat "\\(" | |
432 "[ \t\n\r\f\v]*" | |
433 (c-lang-const c-opt-identifier-concat-key) | |
434 "[ \t\n\r\f\v]*" | |
435 "[~*]" | |
436 "[ \t\n\r\f\v]*" | |
437 ;; The submatch below is: 2 * `c-symbol-key-depth' + | |
438 ;; 3 * depth of `c-opt-identifier-concat-key' + 7. | |
439 "\\(" (c-lang-const c-symbol-key) "\\)" | |
440 "\\)?") | |
441 "\\|" | |
442 "~[ \t\n\r\f\v]*" | |
443 ;; The submatch below is: 3 * `c-symbol-key-depth' + | |
444 ;; 3 * depth of `c-opt-identifier-concat-key' + 8. | |
445 "\\(" (c-lang-const c-symbol-key) "\\)" | |
446 "\\)")) | |
447 ;; IDL and Pike allows a leading qualifier operator. | |
448 (idl pike) (concat | |
449 "\\(" | |
450 (c-lang-const c-opt-identifier-concat-key) | |
451 "[ \t\n\r\f\v]*" | |
452 "\\)?" | |
453 ;; The submatch below is depth of | |
454 ;; `c-opt-identifier-concat-key' + 2. | |
455 "\\(" (c-lang-const c-symbol-key) "\\)" | |
456 (concat "\\(" | |
457 "[ \t\n\r\f\v]*" | |
458 (c-lang-const c-opt-identifier-concat-key) | |
459 "[ \t\n\r\f\v]*" | |
460 ;; The submatch below is: `c-symbol-key-depth' + | |
461 ;; 2 * depth of `c-opt-identifier-concat-key' + 4. | |
462 "\\(" (c-lang-const c-symbol-key) "\\)" | |
463 "\\)*")) | |
464 ;; Java does not allow a leading qualifier operator. If it ends | |
465 ;; with ".*" (used in import declarations) we also consider that as | |
466 ;; part of the name. ("*" is actually recognized in any position | |
467 ;; except the first by this regexp, but we don't bother.) | |
468 java (concat "\\(" (c-lang-const c-symbol-key) "\\)" ; 1 | |
469 (concat "\\(" | |
470 "[ \t\n\r\f\v]*" | |
471 (c-lang-const c-opt-identifier-concat-key) | |
472 "[ \t\n\r\f\v]*" | |
473 (concat "\\(" | |
474 ;; The submatch below is `c-symbol-key-depth' + | |
475 ;; depth of `c-opt-identifier-concat-key' + 4. | |
476 "\\(" (c-lang-const c-symbol-key) "\\)" | |
477 "\\|\\*\\)") | |
478 "\\)*"))) | |
479 (c-lang-defvar c-identifier-key (c-lang-const c-identifier-key)) | |
480 | |
481 (c-lang-defconst c-identifier-last-sym-match | |
482 "Used to identify the submatch in `c-identifier-key' that surrounds | |
483 the last symbol in the qualified identifier. It's a list of submatch | |
484 numbers, of which the first that has a match is taken. It's assumed | |
485 that at least one does when the regexp has matched." | |
486 t '(0) | |
487 c++ (list (+ (* 3 (c-lang-const c-symbol-key-depth)) | |
488 (* 3 (c-regexp-opt-depth | |
489 (c-lang-const c-opt-identifier-concat-key))) | |
490 8) | |
491 (+ (* 2 (c-lang-const c-symbol-key-depth)) | |
492 (* 3 (c-regexp-opt-depth | |
493 (c-lang-const c-opt-identifier-concat-key))) | |
494 7) | |
495 (+ (c-lang-const c-symbol-key-depth) | |
496 (* 2 (c-regexp-opt-depth | |
497 (c-lang-const c-opt-identifier-concat-key))) | |
498 5) | |
499 (+ (c-regexp-opt-depth | |
500 (c-lang-const c-opt-identifier-concat-key)) | |
501 3)) | |
502 (idl pike) (list (+ (c-lang-const c-symbol-key-depth) | |
503 (* 2 (c-regexp-opt-depth | |
504 (c-lang-const c-opt-identifier-concat-key))) | |
505 4) | |
506 (+ (c-regexp-opt-depth | |
507 (c-lang-const c-opt-identifier-concat-key)) | |
508 2)) | |
509 java (list (+ (c-lang-const c-symbol-key-depth) | |
510 (c-regexp-opt-depth | |
511 (c-lang-const c-opt-identifier-concat-key)) | |
512 4) | |
513 1)) | |
514 (c-lang-defvar c-identifier-last-sym-match | |
515 (c-lang-const c-identifier-last-sym-match) | |
516 'dont-doc) | |
517 | |
518 (c-lang-defconst c-opt-cpp-prefix | |
519 "Regexp matching the prefix of a cpp directive in the languages that | |
520 normally use that macro preprocessor. Tested at bol or at boi. | |
521 Assumed to not contain any submatches or \\| operators." | |
522 t "\\s *#\\s *" | |
523 (java awk) nil) | |
524 (c-lang-defvar c-opt-cpp-prefix (c-lang-const c-opt-cpp-prefix)) | |
525 | |
526 (c-lang-defconst c-opt-cpp-start | |
527 "Regexp matching the prefix of a cpp directive including the directive | |
528 name, or nil in languages without preprocessor support. The first | |
529 submatch surrounds the directive name." | |
530 t (if (c-lang-const c-opt-cpp-prefix) | |
531 (concat (c-lang-const c-opt-cpp-prefix) | |
532 "\\([" c-alnum "]+\\)")) | |
533 ;; Pike, being a scripting language, recognizes hash-bangs too. | |
534 pike (concat (c-lang-const c-opt-cpp-prefix) | |
535 "\\([" c-alnum "]+\\|!\\)")) | |
536 (c-lang-defvar c-opt-cpp-start (c-lang-const c-opt-cpp-start)) | |
537 | |
538 (c-lang-defconst c-cpp-defined-fns | |
539 ;; Name of functions in cpp expressions that take an identifier as | |
540 ;; the argument. | |
541 t (if (c-lang-const c-opt-cpp-prefix) | |
542 '("defined")) | |
543 pike '("defined" "efun" "constant")) | |
544 | |
545 (c-lang-defconst c-operators | |
546 "List describing all operators, along with their precedence and | |
547 associativity. The order in the list corresponds to the precedence of | |
548 the operators: The operators in each element is a group with the same | |
549 precedence, and the group has higher precedence than the groups in all | |
550 following elements. The car of each element describes the type of of | |
551 the operator group, and the cdr is a list of the operator tokens in | |
552 it. The operator group types are: | |
553 | |
554 'prefix Unary prefix operators. | |
555 'postfix Unary postfix operators. | |
556 'left-assoc Binary left associative operators (i.e. a+b+c means (a+b)+c). | |
557 'right-assoc Binary right associative operators (i.e. a=b=c means a=(b=c)). | |
558 'right-assoc-sequence | |
559 Right associative operator that constitutes of a | |
560 sequence of tokens that separate expressions. All the | |
561 tokens in the group are in this case taken as | |
562 describing the sequence in one such operator, and the | |
563 order between them is therefore significant. | |
564 | |
565 Operators containing a character with paren syntax are taken to match | |
566 with a corresponding open/close paren somewhere else. A postfix | |
567 operator with close paren syntax is taken to end a postfix expression | |
568 started somewhere earlier, rather than start a new one at point. Vice | |
569 versa for prefix operators with open paren syntax. | |
570 | |
571 Note that operators like \".\" and \"->\" which in language references | |
572 often are described as postfix operators are considered binary here, | |
573 since CC Mode treats every identifier as an expression." | |
574 | |
575 ;; There's currently no code in CC Mode that exploit all the info | |
576 ;; in this variable; precedence, associativity etc are present as a | |
577 ;; preparation for future work. | |
578 | |
579 t `(;; Preprocessor. | |
580 ,@(when (c-lang-const c-opt-cpp-prefix) | |
581 `((prefix "#" | |
582 ,@(when (c-major-mode-is '(c-mode c++-mode)) | |
583 '("%:" "??="))) | |
584 (left-assoc "##" | |
585 ,@(when (c-major-mode-is '(c-mode c++-mode)) | |
586 '("%:%:" "??=??="))))) | |
587 | |
588 ;; Primary. Info duplicated in `c-opt-identifier-concat-key' | |
589 ;; and `c-identifier-key'. | |
590 ,@(cond ((c-major-mode-is 'c++-mode) | |
591 `((postfix-if-paren "<" ">") ; Templates. | |
592 (prefix "~" "??-" "compl") | |
593 (right-assoc "::") | |
594 (prefix "::"))) | |
595 ((c-major-mode-is 'pike-mode) | |
596 `((left-assoc "::") | |
597 (prefix "::" "global" "predef"))) | |
598 ((c-major-mode-is 'java-mode) | |
599 `(;; Not necessary since it's also in the postfix group below. | |
600 ;;(left-assoc ".") | |
601 (prefix "super")))) | |
602 | |
603 ;; Postfix. | |
604 ,@(when (c-major-mode-is 'c++-mode) | |
605 ;; The following need special treatment. | |
606 `((prefix "dynamic_cast" "static_cast" | |
607 "reinterpret_cast" "const_cast" "typeid"))) | |
608 (left-assoc "." | |
609 ,@(unless (c-major-mode-is 'java-mode) | |
610 '("->"))) | |
611 (postfix "++" "--" "[" "]" "(" ")" | |
612 ,@(when (c-major-mode-is '(c-mode c++-mode)) | |
613 '("<:" ":>" "??(" "??)"))) | |
614 | |
615 ;; Unary. | |
616 (prefix "++" "--" "+" "-" "!" "~" | |
617 ,@(when (c-major-mode-is 'c++-mode) '("not" "compl")) | |
618 ,@(when (c-major-mode-is '(c-mode c++-mode)) | |
619 '("*" "&" "sizeof" "??-")) | |
620 ,@(when (c-major-mode-is 'objc-mode) | |
621 '("@selector" "@protocol" "@encode")) | |
622 ;; The following need special treatment. | |
623 ,@(cond ((c-major-mode-is 'c++-mode) | |
624 '("new" "delete")) | |
625 ((c-major-mode-is 'java-mode) | |
626 '("new")) | |
627 ((c-major-mode-is 'pike-mode) | |
628 '("class" "lambda" "catch" "throw" "gauge"))) | |
629 "(" ")" ; Cast. | |
630 ,@(when (c-major-mode-is 'pike-mode) | |
631 '("[" "]"))) ; Type cast. | |
632 | |
633 ;; Member selection. | |
634 ,@(when (c-major-mode-is 'c++-mode) | |
635 `((left-assoc ".*" "->*"))) | |
636 | |
637 ;; Multiplicative. | |
638 (left-assoc "*" "/" "%") | |
639 | |
640 ;; Additive. | |
641 (left-assoc "+" "-") | |
642 | |
643 ;; Shift. | |
644 (left-assoc "<<" ">>" | |
645 ,@(when (c-major-mode-is 'java-mode) | |
646 '(">>>"))) | |
647 | |
648 ;; Relational. | |
649 (left-assoc "<" ">" "<=" ">=" | |
650 ,@(when (c-major-mode-is 'java-mode) | |
651 '("instanceof"))) | |
652 | |
653 ;; Equality. | |
654 (left-assoc "==" "!=" | |
655 ,@(when (c-major-mode-is 'c++-mode) '("not_eq"))) | |
656 | |
657 ;; Bitwise and. | |
658 (left-assoc "&" | |
659 ,@(when (c-major-mode-is 'c++-mode) '("bitand"))) | |
660 | |
661 ;; Bitwise exclusive or. | |
662 (left-assoc "^" | |
663 ,@(when (c-major-mode-is '(c-mode c++-mode)) | |
664 '("??'")) | |
665 ,@(when (c-major-mode-is 'c++-mode) '("xor"))) | |
666 | |
667 ;; Bitwise or. | |
668 (left-assoc "|" | |
669 ,@(when (c-major-mode-is '(c-mode c++-mode)) | |
670 '("??!")) | |
671 ,@(when (c-major-mode-is 'c++-mode) '("bitor"))) | |
672 | |
673 ;; Logical and. | |
674 (left-assoc "&&" | |
675 ,@(when (c-major-mode-is 'c++-mode) '("and"))) | |
676 | |
677 ;; Logical or. | |
678 (left-assoc "||" | |
679 ,@(when (c-major-mode-is '(c-mode c++-mode)) | |
680 '("??!??!")) | |
681 ,@(when (c-major-mode-is 'c++-mode) '("or"))) | |
682 | |
683 ;; Conditional. | |
684 (right-assoc-sequence "?" ":") | |
685 | |
686 ;; Assignment. | |
687 (right-assoc "=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=" | |
688 ,@(when (c-major-mode-is 'java-mode) | |
689 '(">>>=")) | |
690 ,@(when (c-major-mode-is 'c++-mode) | |
691 '("and_eq" "or_eq" "xor_eq"))) | |
692 | |
693 ;; Exception. | |
694 ,@(when (c-major-mode-is 'c++-mode) | |
695 '((prefix "throw"))) | |
696 | |
697 ;; Sequence. | |
698 (left-assoc ",")) | |
699 | |
700 ;; IDL got its own definition since it has a much smaller operator | |
701 ;; set than the other languages. | |
702 idl `(;; Preprocessor. | |
703 (prefix "#") | |
704 (left-assoc "##") | |
705 ;; Primary. Info duplicated in `c-opt-identifier-concat-key' | |
706 ;; and `c-identifier-key'. | |
707 (left-assoc "::") | |
708 (prefix "::") | |
709 ;; Unary. | |
710 (prefix "+" "-" "~") | |
711 ;; Multiplicative. | |
712 (left-assoc "*" "/" "%") | |
713 ;; Additive. | |
714 (left-assoc "+" "-") | |
715 ;; Shift. | |
716 (left-assoc "<<" ">>") | |
717 ;; And. | |
718 (left-assoc "&") | |
719 ;; Xor. | |
720 (left-assoc "^") | |
721 ;; Or. | |
722 (left-assoc "|"))) | |
723 | |
724 (c-lang-defconst c-operator-list | |
725 ;; The operators as a flat list (without duplicates). | |
726 t (delete-duplicates (mapcan (lambda (elem) (append (cdr elem) nil)) | |
727 (c-lang-const c-operators)) | |
728 :test 'string-equal)) | |
729 | |
730 (c-lang-defconst c-overloadable-operators | |
731 "List of the operators that are overloadable, in their \"identifier form\"." | |
732 t nil | |
733 ;; The preceding "operator" keyword is treated separately in C++. | |
734 c++ '("new" "delete" ;; Can be followed by "[]" but we ignore that. | |
735 "+" "-" "*" "/" "%" | |
736 "^" "??'" "xor" "&" "bitand" "|" "??!" "bitor" "~" "??-" "compl" | |
737 "!" "=" "<" ">" "+=" "-=" "*=" "/=" "%=" "^=" | |
738 "??'=" "xor_eq" "&=" "and_eq" "|=" "??!=" "or_eq" | |
739 "<<" ">>" ">>=" "<<=" "==" "!=" "not_eq" "<=" ">=" | |
740 "&&" "and" "||" "??!??!" "or" "++" "--" "," "->*" "->" | |
741 "()" "[]" "<::>" "??(??)") | |
742 ;; These work like identifiers in Pike. | |
743 pike '("`+" "`-" "`&" "`|" "`^" "`<<" "`>>" "`*" "`/" "`%" "`~" | |
744 "`==" "`<" "`>" "`!" "`[]" "`[]=" "`->" "`->=" "`()" "``+" | |
745 "``-" "``&" "``|" "``^" "``<<" "``>>" "``*" "``/" "``%" | |
746 "`+=")) | |
747 | |
748 (c-lang-defconst c-overloadable-operators-regexp | |
749 ;; Regexp tested after an "operator" token in C++. | |
750 t nil | |
751 c++ (c-make-keywords-re nil (c-lang-const c-overloadable-operators))) | |
752 (c-lang-defvar c-overloadable-operators-regexp | |
753 (c-lang-const c-overloadable-operators-regexp)) | |
754 | |
755 (c-lang-defconst c-other-op-syntax-tokens | |
756 "List of the tokens made up of characters in the punctuation or | |
757 parenthesis syntax classes that have uses other than as expression | |
758 operators." | |
759 t '("{" "}" "(" ")" "[" "]" ";" ":" "," "=" "/*" "*/" "//") | |
760 (c c++ pike) (append '("#" "##" ; Used by cpp. | |
761 "::" "...") | |
762 (c-lang-const c-other-op-syntax-tokens)) | |
763 (c c++) (append '("<%" "%>" "<:" ":>" "%:" "%:%:" "*") | |
764 (c-lang-const c-other-op-syntax-tokens)) | |
765 c++ (append '("&") (c-lang-const c-other-op-syntax-tokens)) | |
766 objc (append '("#" "##" ; Used by cpp. | |
767 "+" "-") (c-lang-const c-other-op-syntax-tokens)) | |
768 idl (append '("#" "##") ; Used by cpp. | |
769 (c-lang-const c-other-op-syntax-tokens)) | |
770 pike (append '("..") | |
771 (c-lang-const c-other-op-syntax-tokens) | |
772 (c-lang-const c-overloadable-operators)) | |
773 awk '("{" "}" "(" ")" "[" "]" ";" "," "=" "/")) | |
774 | |
775 (c-lang-defconst c-nonsymbol-token-regexp | |
776 ;; Regexp matching all tokens in the punctuation and parenthesis | |
777 ;; syntax classes. Note that this also matches ".", which can start | |
778 ;; a float. | |
779 t (c-make-keywords-re nil | |
780 (c-with-syntax-table (c-lang-const c-mode-syntax-table) | |
781 (mapcan (lambda (op) | |
782 (if (string-match "\\`\\(\\s.\\|\\s\(\\|\\s\)\\)+\\'" op) | |
783 (list op))) | |
784 (append (c-lang-const c-other-op-syntax-tokens) | |
785 (c-lang-const c-operator-list)))))) | |
786 (c-lang-defvar c-nonsymbol-token-regexp | |
787 (c-lang-const c-nonsymbol-token-regexp)) | |
788 | |
789 (c-lang-defconst c-<-op-cont-regexp | |
790 ;; Regexp matching the second and subsequent characters of all | |
791 ;; multicharacter tokens that begin with "<". | |
792 t (c-make-keywords-re nil | |
793 (mapcan (lambda (op) | |
794 (if (string-match "\\`<." op) | |
795 (list (substring op 1)))) | |
796 (append (c-lang-const c-other-op-syntax-tokens) | |
797 (c-lang-const c-operator-list))))) | |
798 (c-lang-defvar c-<-op-cont-regexp (c-lang-const c-<-op-cont-regexp)) | |
799 | |
800 (c-lang-defconst c->-op-cont-regexp | |
801 ;; Regexp matching the second and subsequent characters of all | |
802 ;; multicharacter tokens that begin with ">". | |
803 t (c-make-keywords-re nil | |
804 (mapcan (lambda (op) | |
805 (if (string-match "\\`>." op) | |
806 (list (substring op 1)))) | |
807 (append (c-lang-const c-other-op-syntax-tokens) | |
808 (c-lang-const c-operator-list))))) | |
809 (c-lang-defvar c->-op-cont-regexp (c-lang-const c->-op-cont-regexp)) | |
810 | |
811 (c-lang-defconst c-stmt-delim-chars | |
812 ;; The characters that should be considered to bound statements. To | |
813 ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to | |
814 ;; begin with "^" to negate the set. If ? : operators should be | |
815 ;; detected then the string must end with "?:". | |
816 t "^;{}?:" | |
817 awk "^;{}\n\r?:") ; The newline chars gets special treatment. | |
818 (c-lang-defvar c-stmt-delim-chars (c-lang-const c-stmt-delim-chars)) | |
819 | |
820 (c-lang-defconst c-stmt-delim-chars-with-comma | |
821 ;; Variant of `c-stmt-delim-chars' that additionally contains ','. | |
822 t "^;,{}?:" | |
823 awk "^;,{}\n\r?:") ; The newline chars gets special treatment. | |
824 (c-lang-defvar c-stmt-delim-chars-with-comma | |
825 (c-lang-const c-stmt-delim-chars-with-comma)) | |
826 | |
827 | |
828 ;;; Syntactic whitespace. | |
829 | |
830 (c-lang-defconst c-comment-start-regexp | |
831 ;; Regexp to match the start of any type of comment. | |
832 ;; | |
833 ;; TODO: Ought to use `c-comment-prefix-regexp' with some | |
834 ;; modifications instead of this. | |
835 t "/[/*]" | |
836 awk "#") | |
837 (c-lang-defvar c-comment-start-regexp (c-lang-const c-comment-start-regexp)) | |
838 | |
839 (c-lang-defconst c-literal-start-regexp | |
840 ;; Regexp to match the start of comments and string literals. | |
841 t (concat (c-lang-const c-comment-start-regexp) | |
842 "\\|" | |
843 (if (memq 'gen-string-delim c-emacs-features) | |
844 "\"|" | |
845 "\""))) | |
846 (c-lang-defvar c-literal-start-regexp (c-lang-const c-literal-start-regexp)) | |
847 | |
848 (c-lang-defconst c-doc-comment-start-regexp | |
849 "Regexp to match the start of documentation comments." | |
850 t "\\<\\>" | |
851 ;; From font-lock.el: `doxygen' uses /*! while others use /**. | |
852 (c c++ objc) "/\\*[*!]" | |
853 java "/\\*\\*" | |
854 pike "/[/*]!") | |
855 (c-lang-defvar c-doc-comment-start-regexp | |
856 (c-lang-const c-doc-comment-start-regexp)) | |
857 | |
858 (c-lang-defconst comment-start | |
859 "String that starts comments inserted with M-; etc. | |
860 `comment-start' is initialized from this." | |
861 t "// " | |
862 c "/* " | |
863 awk "# ") | |
864 (c-lang-defvar comment-start (c-lang-const comment-start) | |
865 'dont-doc) | |
866 | |
867 (c-lang-defconst comment-end | |
868 "String that ends comments inserted with M-; etc. | |
869 `comment-end' is initialized from this." | |
870 t "" | |
871 c " */") | |
872 (c-lang-defvar comment-end (c-lang-const comment-end) | |
873 'dont-doc) | |
874 | |
875 (c-lang-defconst comment-start-skip | |
876 "Regexp to match the start of a comment plus everything up to its body. | |
877 `comment-start-skip' is initialized from this." | |
878 t "/\\*+ *\\|//+ *" | |
879 awk "#+ *") | |
880 (c-lang-defvar comment-start-skip (c-lang-const comment-start-skip) | |
881 'dont-doc) | |
882 | |
883 (c-lang-defconst syntactic-ws-start | |
884 "Regexp matching any sequence that can start syntactic whitespace. | |
885 The only uncertain case is '#' when there are cpp directives." | |
886 t "[ \n\t\r\v\f#]\\|/[/*]\\|\\\\[\n\r]" | |
887 awk "[ \n\t\r\v\f#]\\|\\\\[\n\r]") | |
888 (c-lang-defvar c-syntactic-ws-start (c-lang-const syntactic-ws-start) | |
889 'dont-doc) | |
890 | |
891 (c-lang-defconst syntactic-ws-end | |
892 "Regexp matching any single character that might end syntactic whitespace." | |
893 t "[ \n\t\r\v\f/]" | |
894 awk "[ \n\t\r\v\f]") | |
895 (c-lang-defvar c-syntactic-ws-end (c-lang-const syntactic-ws-end) | |
896 'dont-doc) | |
897 | |
898 (c-lang-defconst c-nonwhite-syntactic-ws | |
899 ;; Regexp matching a piece of syntactic whitespace that isn't a | |
900 ;; sequence of simple whitespace characters. As opposed to | |
901 ;; `c-(forward|backward)-syntactic-ws', this doesn't regard cpp | |
902 ;; directives as syntactic whitespace. | |
903 t (concat "/" (concat | |
904 "\\(" | |
905 "/[^\n\r]*[\n\r]" ; Line comment. | |
906 "\\|" | |
907 ;; Block comment. We intentionally don't allow line | |
908 ;; breaks in them to avoid going very far and risk | |
909 ;; running out of regexp stack; this regexp is | |
910 ;; intended to handle only short comments that | |
911 ;; might be put in the middle of limited constructs | |
912 ;; like declarations. | |
913 "\\*\\([^*\n\r]\\|\\*[^/\n\r]\\)*\\*/" | |
914 "\\)") | |
915 "\\|" | |
916 "\\\\[\n\r]") ; Line continuations. | |
917 awk ("#.*[\n\r]\\|\\\\[\n\r]")) | |
918 | |
919 (c-lang-defconst c-syntactic-ws | |
920 ;; Regexp matching syntactic whitespace, including possibly the | |
921 ;; empty string. As opposed to `c-(forward|backward)-syntactic-ws', | |
922 ;; this doesn't regard cpp directives as syntactic whitespace. Does | |
923 ;; not contain a \| operator at the top level. | |
924 t (concat "[ \t\n\r\f\v]*\\(" | |
925 "\\(" (c-lang-const c-nonwhite-syntactic-ws) "\\)" | |
926 "[ \t\n\r\f\v]*\\)*")) | |
927 | |
928 (c-lang-defconst c-syntactic-ws-depth | |
929 ;; Number of regexp grouping parens in `c-syntactic-ws'. | |
930 t (c-regexp-opt-depth (c-lang-const c-syntactic-ws))) | |
931 | |
932 (c-lang-defconst c-nonempty-syntactic-ws | |
933 ;; Regexp matching syntactic whitespace, which is at least one | |
934 ;; character long. As opposed to `c-(forward|backward)-syntactic-ws', | |
935 ;; this doesn't regard cpp directives as syntactic whitespace. Does | |
936 ;; not contain a \| operator at the top level. | |
937 t (concat "\\([ \t\n\r\f\v]\\|" | |
938 (c-lang-const c-nonwhite-syntactic-ws) | |
939 "\\)+")) | |
940 | |
941 (c-lang-defconst c-nonempty-syntactic-ws-depth | |
942 ;; Number of regexp grouping parens in `c-nonempty-syntactic-ws'. | |
943 t (c-regexp-opt-depth (c-lang-const c-nonempty-syntactic-ws))) | |
944 | |
945 (c-lang-defconst c-single-line-syntactic-ws | |
946 ;; Regexp matching syntactic whitespace without any line breaks. As | |
947 ;; opposed to `c-(forward|backward)-syntactic-ws', this doesn't | |
948 ;; regard cpp directives as syntactic whitespace. Does not contain | |
949 ;; a \| operator at the top level. | |
950 t (concat "[ \t]*\\(" | |
951 "/\\*\\([^*\n\r]\\|\\*[^/\n\r]\\)*\\*/" ; Block comment | |
952 "[ \t]*\\)*") | |
953 awk ("[ \t]*\\(#.*$\\)?")) | |
954 | |
955 (c-lang-defconst c-single-line-syntactic-ws-depth | |
956 ;; Number of regexp grouping parens in `c-single-line-syntactic-ws'. | |
957 t (c-regexp-opt-depth (c-lang-const c-single-line-syntactic-ws))) | |
958 | |
959 (c-lang-defvar c-syntactic-eol | |
960 ;; Regexp that matches when there is no syntactically significant | |
961 ;; text before eol. Macros are regarded as syntactically | |
962 ;; significant text here. | |
963 (concat (concat | |
964 ;; Match horizontal whitespace and block comments that | |
965 ;; don't contain newlines. | |
966 "\\(\\s \\|" | |
967 (concat "/\\*" | |
968 "\\([^*\n\r]\\|\\*[^/\n\r]\\)*" | |
969 "\\*/") | |
970 "\\)*") | |
971 (concat | |
972 ;; Match eol (possibly inside a block comment or preceded | |
973 ;; by a line continuation backslash), or the beginning of a | |
974 ;; line comment. Note: This has to be modified for awk | |
975 ;; where line comments start with '#'. | |
976 "\\(" | |
977 (concat "\\(" | |
978 "/\\*\\([^*\n\r]\\|\\*[^/\n\r]\\)*" | |
979 "\\|" | |
980 "\\\\" | |
981 "\\)?" | |
982 "$") | |
983 "\\|//\\)"))) | |
984 | |
985 | |
986 ;;; In-comment text handling. | |
987 | |
988 (c-lang-defconst c-paragraph-start | |
989 "Regexp to append to `paragraph-start'." | |
990 t "$" | |
991 java "\\(@[a-zA-Z]+\\>\\|$\\)" ; For Javadoc. | |
992 pike "\\(@[a-zA-Z_-]+\\>\\([^{]\\|$\\)\\|$\\)") ; For Pike refdoc. | |
993 (c-lang-defvar c-paragraph-start (c-lang-const c-paragraph-start)) | |
994 | |
995 (c-lang-defconst c-paragraph-separate | |
996 "Regexp to append to `paragraph-separate'." | |
997 t "$" | |
998 pike (c-lang-const c-paragraph-start)) | |
999 (c-lang-defvar c-paragraph-separate (c-lang-const c-paragraph-separate)) | |
1000 | |
1001 | |
1002 ;;; Keyword lists. | |
1003 | |
1004 ;; Note: All and only all language constants containing keyword lists | |
1005 ;; should end with "-kwds"; they're automatically collected into the | |
1006 ;; `c-kwds-lang-consts' list below and used to build `c-keywords' etc. | |
1007 | |
1008 (c-lang-defconst c-primitive-type-kwds | |
1009 "Primitive type keywords. As opposed to the other keyword lists, the | |
1010 keywords listed here are fontified with the type face instead of the | |
1011 keyword face. | |
1012 | |
1013 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds', | |
1014 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds', | |
1015 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses | |
1016 will be handled. | |
1017 | |
1018 Do not try to modify this list for end user customizations; the | |
1019 `*-font-lock-extra-types' variable, where `*' is the mode prefix, is | |
1020 the appropriate place for that." | |
1021 t '("char" "double" "float" "int" "long" "short" "signed" | |
1022 "unsigned" "void") | |
1023 c (append | |
1024 '("_Bool" "_Complex" "_Imaginary") ; Conditionally defined in C99. | |
1025 (c-lang-const c-primitive-type-kwds)) | |
1026 c++ (append | |
1027 '("bool" "wchar_t") | |
1028 (c-lang-const c-primitive-type-kwds)) | |
1029 ;; Objective-C extends C, but probably not the new stuff in C99. | |
1030 objc (append | |
1031 '("id" "Class" "SEL" "IMP" "BOOL") | |
1032 (c-lang-const c-primitive-type-kwds)) | |
1033 java '("boolean" "byte" "char" "double" "float" "int" "long" "short" "void") | |
1034 idl '("Object" "ValueBase" "any" "boolean" "char" "double" "fixed" "float" | |
1035 "long" "octet" "sequence" "short" "string" "void" "wchar" "wstring" | |
1036 ;; In CORBA PSDL: | |
1037 "ref" | |
1038 ;; The following can't really end a type, but we have to specify them | |
1039 ;; here due to the assumption in `c-primitive-type-prefix-kwds'. It | |
1040 ;; doesn't matter that much. | |
1041 "unsigned" "strong") | |
1042 pike '(;; this_program isn't really a keyword, but it's practically | |
1043 ;; used as a builtin type. | |
1044 "array" "float" "function" "int" "mapping" "mixed" "multiset" | |
1045 "object" "program" "string" "this_program" "void")) | |
1046 | |
1047 (c-lang-defconst c-primitive-type-key | |
1048 ;; An adorned regexp that matches `c-primitive-type-kwds'. | |
1049 t (c-make-keywords-re t (c-lang-const c-primitive-type-kwds))) | |
1050 (c-lang-defvar c-primitive-type-key (c-lang-const c-primitive-type-key)) | |
1051 | |
1052 (c-lang-defconst c-primitive-type-prefix-kwds | |
1053 "Keywords that might act as prefixes for primitive types. Assumed to | |
1054 be a subset of `c-primitive-type-kwds'." | |
1055 t nil | |
1056 (c c++) '("long" "short" "signed" "unsigned") | |
1057 idl '("long" "unsigned" | |
1058 ;; In CORBA PSDL: | |
1059 "strong")) | |
1060 | |
1061 (c-lang-defconst c-type-prefix-kwds | |
1062 "Keywords where the following name - if any - is a type name, and | |
1063 where the keyword together with the symbol works as a type in | |
1064 declarations. | |
1065 | |
1066 Note that an alternative if the second part doesn't hold is | |
1067 `c-type-list-kwds'. Keywords on this list are typically also present | |
1068 on one of the `*-decl-kwds' lists." | |
1069 t nil | |
1070 c '("struct" "union" "enum") | |
1071 c++ (append '("class" "typename") | |
1072 (c-lang-const c-type-prefix-kwds c))) | |
1073 | |
1074 (c-lang-defconst c-type-prefix-key | |
1075 ;; Adorned regexp matching `c-type-prefix-kwds'. | |
1076 t (c-make-keywords-re t (c-lang-const c-type-prefix-kwds))) | |
1077 (c-lang-defvar c-type-prefix-key (c-lang-const c-type-prefix-key)) | |
1078 | |
1079 (c-lang-defconst c-type-modifier-kwds | |
1080 "Type modifier keywords. These can occur almost anywhere in types | |
1081 but they don't build a type of themselves. Unlike the keywords on | |
1082 `c-primitive-type-kwds', they are fontified with the keyword face and | |
1083 not the type face." | |
1084 t nil | |
1085 c '("const" "restrict" "volatile") | |
1086 c++ '("const" "volatile" "throw") | |
1087 objc '("const" "volatile")) | |
1088 | |
1089 (c-lang-defconst c-opt-type-modifier-key | |
1090 ;; Adorned regexp matching `c-type-modifier-kwds', or nil in | |
1091 ;; languages without such keywords. | |
1092 t (and (c-lang-const c-type-modifier-kwds) | |
1093 (c-make-keywords-re t (c-lang-const c-type-modifier-kwds)))) | |
1094 (c-lang-defvar c-opt-type-modifier-key (c-lang-const c-opt-type-modifier-key)) | |
1095 | |
1096 (c-lang-defconst c-opt-type-component-key | |
1097 ;; An adorned regexp that matches `c-primitive-type-prefix-kwds' and | |
1098 ;; `c-type-modifier-kwds', or nil in languages without any of them. | |
1099 t (and (or (c-lang-const c-primitive-type-prefix-kwds) | |
1100 (c-lang-const c-type-modifier-kwds)) | |
1101 (c-make-keywords-re t | |
1102 (append (c-lang-const c-primitive-type-prefix-kwds) | |
1103 (c-lang-const c-type-modifier-kwds))))) | |
1104 (c-lang-defvar c-opt-type-component-key | |
1105 (c-lang-const c-opt-type-component-key)) | |
1106 | |
1107 (c-lang-defconst c-class-decl-kwds | |
1108 "Keywords introducing declarations where the following block (if any) | |
1109 contains another declaration level that should be considered a class. | |
1110 | |
1111 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds', | |
1112 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds', | |
1113 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses | |
1114 will be handled. | |
1115 | |
1116 Note that presence on this list does not automatically treat the | |
1117 following identifier as a type; the keyword must also be present on | |
1118 `c-type-prefix-kwds' or `c-type-list-kwds' to accomplish that." | |
1119 t nil | |
1120 c '("struct" "union") | |
1121 c++ '("class" "struct" "union") | |
1122 objc '("struct" "union" | |
1123 "@interface" "@implementation" "@protocol") | |
1124 java '("class" "interface") | |
1125 idl '("component" "eventtype" "exception" "home" "interface" "struct" | |
1126 "union" "valuetype" | |
1127 ;; In CORBA PSDL: | |
1128 "storagehome" "storagetype" | |
1129 ;; In CORBA CIDL: | |
1130 "catalog" "executor" "manages" "segment") | |
1131 pike '("class")) | |
1132 | |
1133 (c-lang-defconst c-class-key | |
1134 ;; Regexp matching the start of a class. | |
1135 t (c-make-keywords-re t (c-lang-const c-class-decl-kwds))) | |
1136 (c-lang-defvar c-class-key (c-lang-const c-class-key)) | |
1137 | |
1138 (c-lang-defconst c-brace-list-decl-kwds | |
1139 "Keywords introducing declarations where the following block (if | |
1140 any) is a brace list. | |
1141 | |
1142 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds', | |
1143 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds', | |
1144 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses | |
1145 will be handled." | |
1146 t '("enum") | |
1147 (java awk) nil) | |
1148 | |
1149 (c-lang-defconst c-brace-list-key | |
1150 ;; Regexp matching the start of declarations where the following | |
1151 ;; block is a brace list. | |
1152 t (c-make-keywords-re t (c-lang-const c-brace-list-decl-kwds))) | |
1153 (c-lang-defvar c-brace-list-key (c-lang-const c-brace-list-key)) | |
1154 | |
1155 (c-lang-defconst c-other-block-decl-kwds | |
1156 "Keywords where the following block (if any) contain another | |
1157 declaration level that should not be considered a class. | |
1158 | |
1159 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds', | |
1160 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds', | |
1161 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses | |
1162 will be handled." | |
1163 t nil | |
1164 c '("extern") | |
1165 c++ '("namespace" "extern") | |
1166 idl '("module" | |
1167 ;; In CORBA CIDL: | |
1168 "composition")) | |
1169 | |
1170 (c-lang-defconst c-other-decl-block-key | |
1171 ;; Regexp matching the start of blocks besides classes that contain | |
1172 ;; another declaration level. | |
1173 t (c-make-keywords-re t (c-lang-const c-other-block-decl-kwds))) | |
1174 (c-lang-defvar c-other-decl-block-key (c-lang-const c-other-decl-block-key)) | |
1175 | |
1176 (c-lang-defconst c-typedef-decl-kwds | |
1177 "Keywords introducing declarations where the identifiers are defined | |
1178 to be types. | |
1179 | |
1180 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds', | |
1181 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds', | |
1182 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses | |
1183 will be handled." | |
1184 t '("typedef") | |
1185 (java awk) nil) | |
1186 | |
1187 (c-lang-defconst c-typeless-decl-kwds | |
1188 "Keywords introducing declarations where the identifier (declarator) | |
1189 list follows directly after the keyword, without any type. | |
1190 | |
1191 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds', | |
1192 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds', | |
1193 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses | |
1194 will be handled." | |
1195 t nil | |
1196 ;; Unlike most other languages, exception names are not handled as | |
1197 ;; types in IDL since they only can occur in "raises" specs. | |
1198 idl '("exception" "factory" "finder" "native" | |
1199 ;; In CORBA PSDL: | |
1200 "key" "stores" | |
1201 ;; In CORBA CIDL: | |
1202 ;; Note that "manages" here clashes with its presence on | |
1203 ;; `c-type-list-kwds' for IDL. | |
1204 "executor" "facet" "manages" "segment") | |
1205 pike '("constant")) | |
1206 | |
1207 (c-lang-defconst c-modifier-kwds | |
1208 "Keywords that can prefix normal declarations of identifiers | |
1209 \(and typically acts as flags). Things like argument declarations | |
1210 inside function headers are also considered declarations in this | |
1211 sense. | |
1212 | |
1213 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds', | |
1214 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds', | |
1215 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses | |
1216 will be handled." | |
1217 t nil | |
1218 (c c++) '("auto" "extern" "inline" "register" "static") | |
1219 c++ (append '("explicit" "friend" "mutable" "template" "using" "virtual") | |
1220 (c-lang-const c-modifier-kwds)) | |
1221 objc '("auto" "bycopy" "byref" "extern" "in" "inout" "oneway" "out" "static") | |
1222 ;; FIXME: Some of those below ought to be on `c-other-decl-kwds' instead. | |
1223 idl '("abstract" "attribute" "const" "consumes" "custom" "emits" "import" | |
1224 "in" "inout" "local" "multiple" "oneway" "out" "private" "provides" | |
1225 "public" "publishes" "readonly" "typeid" "typeprefix" "uses" | |
1226 ;; In CORBA PSDL: | |
1227 "primary" "state" | |
1228 ;; In CORBA CIDL: | |
1229 "bindsTo" "delegatesTo" "implements" "proxy" "storedOn") | |
1230 ;; Note: "const" is not used in Java, but it's still a reserved keyword. | |
1231 java '("abstract" "const" "final" "native" "private" "protected" "public" | |
1232 "static" "strictfp" "synchronized" "transient" "volatile") | |
1233 pike '("final" "inline" "local" "nomask" "optional" "private" "protected" | |
1234 "public" "static" "variant")) | |
1235 | |
1236 (c-lang-defconst c-other-decl-kwds | |
1237 "Keywords that can start or prefix any declaration level construct, | |
1238 besides those on `c-class-decl-kwds', `c-brace-list-decl-kwds', | |
1239 `c-other-block-decl-kwds', `c-typedef-decl-kwds', | |
1240 `c-typeless-decl-kwds' and `c-modifier-kwds'. In a declaration, these | |
1241 keywords are also recognized inside or after the identifiers that | |
1242 makes up the type. | |
1243 | |
1244 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds', | |
1245 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds', | |
1246 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses | |
1247 will be handled." | |
1248 t nil | |
1249 (c c++) '("__declspec") ; MSVC extension. | |
1250 objc '("@class" "@end" "@defs") | |
1251 java '("import" "package") | |
1252 pike '("import" "inherit")) | |
1253 | |
1254 (c-lang-defconst c-specifier-key | |
1255 ;; Adorned regexp matching keywords that can start a declaration but | |
1256 ;; not a type. | |
1257 t (c-make-keywords-re t | |
1258 (set-difference (append (c-lang-const c-class-decl-kwds) | |
1259 (c-lang-const c-brace-list-decl-kwds) | |
1260 (c-lang-const c-other-block-decl-kwds) | |
1261 (c-lang-const c-typedef-decl-kwds) | |
1262 (c-lang-const c-typeless-decl-kwds) | |
1263 (c-lang-const c-modifier-kwds) | |
1264 (c-lang-const c-other-decl-kwds)) | |
1265 (append (c-lang-const c-primitive-type-kwds) | |
1266 (c-lang-const c-type-prefix-kwds) | |
1267 (c-lang-const c-type-modifier-kwds)) | |
1268 :test 'string-equal))) | |
1269 (c-lang-defvar c-specifier-key (c-lang-const c-specifier-key)) | |
1270 | |
1271 (c-lang-defconst c-protection-kwds | |
1272 "Protection label keywords in classes." | |
1273 t nil | |
1274 c++ '("private" "protected" "public") | |
1275 objc '("@private" "@protected" "@public")) | |
1276 | |
1277 (c-lang-defconst c-opt-access-key | |
1278 ;; Regexp matching an access protection label in a class, or nil in | |
1279 ;; languages that don't have such things. | |
1280 t (if (c-lang-const c-protection-kwds) | |
1281 (c-make-keywords-re t (c-lang-const c-protection-kwds))) | |
1282 c++ (concat "\\(" | |
1283 (c-make-keywords-re nil (c-lang-const c-protection-kwds)) | |
1284 "\\)[ \t\n\r\f\v]*:")) | |
1285 (c-lang-defvar c-opt-access-key (c-lang-const c-opt-access-key)) | |
1286 | |
1287 (c-lang-defconst c-block-decls-with-vars | |
1288 "Keywords introducing declarations that can contain a block which | |
1289 might be followed by variable declarations, e.g. like \"foo\" in | |
1290 \"class Foo { ... } foo;\". So if there is a block in a declaration | |
1291 like that, it ends with the following ';' and not right away. | |
1292 | |
1293 The keywords on list are assumed to also be present on one of the | |
1294 `*-decl-kwds' lists." | |
1295 t nil | |
1296 (c objc) '("struct" "union" "enum" "typedef") | |
1297 c++ '("class" "struct" "union" "enum" "typedef")) | |
1298 | |
1299 (c-lang-defconst c-opt-block-decls-with-vars-key | |
1300 ;; Regexp matching the `c-block-decls-with-vars' keywords, or nil in | |
1301 ;; languages without such constructs. | |
1302 t (and (c-lang-const c-block-decls-with-vars) | |
1303 (c-make-keywords-re t (c-lang-const c-block-decls-with-vars)))) | |
1304 (c-lang-defvar c-opt-block-decls-with-vars-key | |
1305 (c-lang-const c-opt-block-decls-with-vars-key)) | |
1306 | |
1307 (c-lang-defconst c-postfix-decl-spec-kwds | |
1308 "Keywords introducing extra declaration specifiers in the region | |
1309 between the header and the body \(i.e. the \"K&R-region\") in | |
1310 declarations." | |
1311 t nil | |
1312 (c c++) '("__attribute__") ; GCC extension. | |
1313 java '("extends" "implements" "throws") | |
1314 idl '("context" "getraises" "manages" "primarykey" "raises" "setraises" | |
1315 "supports" | |
1316 ;; In CORBA PSDL: | |
1317 "as" "const" "implements" "of" "ref")) | |
1318 | |
1319 (c-lang-defconst c-nonsymbol-sexp-kwds | |
1320 "Keywords that may be followed by a nonsymbol sexp before whatever | |
1321 construct it's part of continues." | |
1322 t nil | |
1323 (c c++ objc) '("extern")) | |
1324 | |
1325 (c-lang-defconst c-type-list-kwds | |
1326 "Keywords that may be followed by a comma separated list of type | |
1327 identifiers, where each optionally can be prefixed by keywords. (Can | |
1328 also be used for the special case when the list can contain only one | |
1329 element.) | |
1330 | |
1331 Assumed to be mutually exclusive with `c-ref-list-kwds'. There's no | |
1332 reason to put keywords on this list if they are on `c-type-prefix-kwds'. | |
1333 There's also no reason to add keywords that prefixes a normal | |
1334 declaration consisting of a type followed by a declarator (list), so | |
1335 the keywords on `c-modifier-kwds' should normally not be listed here | |
1336 too. | |
1337 | |
1338 Note: Use `c-typeless-decl-kwds' for keywords followed by a function | |
1339 or variable identifier (that's being defined)." | |
1340 t '("struct" "union" "enum") | |
1341 (c c++ awk) nil | |
1342 objc (append '("@class" "@interface" "@implementation" "@protocol") | |
1343 (c-lang-const c-type-list-kwds)) | |
1344 java '("class" "import" "interface" "new" "extends" "implements" "throws") | |
1345 idl (append '("component" "eventtype" "home" "interface" "manages" "native" | |
1346 "primarykey" "supports" "valuetype" | |
1347 ;; In CORBA PSDL: | |
1348 "as" "implements" "of" "scope" "storagehome" "storagetype") | |
1349 (c-lang-const c-type-list-kwds)) | |
1350 pike '("class" "enum" "inherit")) | |
1351 | |
1352 (c-lang-defconst c-ref-list-kwds | |
1353 "Keywords that may be followed by a comma separated list of | |
1354 reference (i.e. namespace/scope/module) identifiers, where each | |
1355 optionally can be prefixed by keywords. (Can also be used for the | |
1356 special case when the list can contain only one element.) Assumed to | |
1357 be mutually exclusive with `c-type-list-kwds'. | |
1358 | |
1359 Note: Use `c-typeless-decl-kwds' for keywords followed by a function | |
1360 or variable identifier (that's being defined)." | |
1361 t nil | |
1362 c++ '("namespace") | |
1363 java '("package") | |
1364 idl '("import" "module" | |
1365 ;; In CORBA CIDL: | |
1366 "composition") | |
1367 pike '("import")) | |
1368 | |
1369 (c-lang-defconst c-colon-type-list-kwds | |
1370 "Keywords that may be followed (not necessarily directly) by a colon | |
1371 and then a comma separated list of type identifiers, where each | |
1372 optionally can be prefixed by keywords. (Can also be used for the | |
1373 special case when the list can contain only one element.)" | |
1374 t nil | |
1375 c++ '("class" "struct") | |
1376 idl '("component" "eventtype" "home" "interface" "valuetype" | |
1377 ;; In CORBA PSDL: | |
1378 "storagehome" "storagetype")) | |
1379 | |
1380 (c-lang-defconst c-colon-type-list-re | |
1381 "Regexp matched after the keywords in `c-colon-type-list-kwds' to skip | |
1382 forward to the colon. The end of the match is assumed to be directly | |
1383 after the colon, so the regexp should end with \":\" although that | |
1384 isn't necessary. Must be a regexp if `c-colon-type-list-kwds' isn't | |
1385 nil." | |
1386 t (if (c-lang-const c-colon-type-list-kwds) | |
1387 ;; Disallow various common punctuation chars that can't come | |
1388 ;; before the ":" that starts the inherit list after "class" | |
1389 ;; or "struct" in C++. (Also used as default for other | |
1390 ;; languages.) | |
1391 "[^\]\[{}();,/#=:]*:")) | |
1392 (c-lang-defvar c-colon-type-list-re (c-lang-const c-colon-type-list-re)) | |
1393 | |
1394 (c-lang-defconst c-paren-nontype-kwds | |
1395 "Keywords that may be followed by a parenthesis expression that doesn't | |
1396 contain type identifiers." | |
1397 t nil | |
1398 (c c++) '("__declspec")) ; MSVC extension. | |
1399 | |
1400 (c-lang-defconst c-paren-type-kwds | |
1401 "Keywords that may be followed by a parenthesis expression containing | |
1402 type identifiers separated by arbitrary tokens." | |
1403 t nil | |
1404 c++ '("throw") | |
1405 objc '("@defs") | |
1406 idl '("switch") | |
1407 pike '("array" "function" "int" "mapping" "multiset" "object" "program")) | |
1408 | |
1409 (c-lang-defconst c-paren-any-kwds | |
1410 t (delete-duplicates (append (c-lang-const c-paren-nontype-kwds) | |
1411 (c-lang-const c-paren-type-kwds)) | |
1412 :test 'string-equal)) | |
1413 | |
1414 (c-lang-defconst c-<>-type-kwds | |
1415 "Keywords that may be followed by an angle bracket expression | |
1416 containing type identifiers separated by \",\". The difference from | |
1417 `c-<>-arglist-kwds' is that unknown names are taken to be types and | |
1418 not other identifiers. `c-recognize-<>-arglists' is assumed to be set | |
1419 if this isn't nil." | |
1420 t nil | |
1421 objc '("id") | |
1422 idl '("sequence" | |
1423 ;; In CORBA PSDL: | |
1424 "ref")) | |
1425 | |
1426 (c-lang-defconst c-<>-arglist-kwds | |
1427 "Keywords that can be followed by a C++ style template arglist; see | |
1428 `c-recognize-<>-arglists' for details. That language constant is | |
1429 assumed to be set if this isn't nil." | |
1430 t nil | |
1431 c++ '("template") | |
1432 idl '("fixed" "string" "wstring")) | |
1433 | |
1434 (c-lang-defconst c-<>-sexp-kwds | |
1435 ;; All keywords that can be followed by an angle bracket sexp. | |
1436 t (delete-duplicates (append (c-lang-const c-<>-type-kwds) | |
1437 (c-lang-const c-<>-arglist-kwds)) | |
1438 :test 'string-equal)) | |
1439 | |
1440 (c-lang-defconst c-opt-<>-sexp-key | |
1441 ;; Adorned regexp matching keywords that can be followed by an angle | |
1442 ;; bracket sexp. | |
1443 t (if (c-lang-const c-recognize-<>-arglists) | |
1444 (c-make-keywords-re t (c-lang-const c-<>-sexp-kwds)))) | |
1445 (c-lang-defvar c-opt-<>-sexp-key (c-lang-const c-opt-<>-sexp-key)) | |
1446 | |
1447 (c-lang-defconst c-brace-id-list-kwds | |
1448 "Keywords that may be followed by a brace block containing a comma | |
1449 separated list of identifier definitions, i.e. like the list of | |
1450 identifiers that follows the type in a normal declaration." | |
1451 t (c-lang-const c-brace-list-decl-kwds)) | |
1452 | |
1453 (c-lang-defconst c-block-stmt-1-kwds | |
1454 "Statement keywords followed directly by a substatement." | |
1455 t '("do" "else") | |
1456 c++ '("do" "else" "try") | |
1457 java '("do" "else" "finally" "try") | |
1458 idl nil) | |
1459 | |
1460 (c-lang-defconst c-block-stmt-1-key | |
1461 ;; Regexp matching the start of any statement followed directly by a | |
1462 ;; substatement (doesn't match a bare block, however). | |
1463 t (c-make-keywords-re t (c-lang-const c-block-stmt-1-kwds))) | |
1464 (c-lang-defvar c-block-stmt-1-key (c-lang-const c-block-stmt-1-key)) | |
1465 | |
1466 (c-lang-defconst c-block-stmt-2-kwds | |
1467 "Statement keywords followed by a paren sexp and then by a substatement." | |
1468 t '("for" "if" "switch" "while") | |
1469 c++ '("for" "if" "switch" "while" "catch") | |
1470 java '("for" "if" "switch" "while" "catch" "synchronized") | |
1471 idl nil | |
1472 pike '("for" "if" "switch" "while" "foreach") | |
1473 awk '("for" "if" "while")) | |
1474 | |
1475 (c-lang-defconst c-block-stmt-2-key | |
1476 ;; Regexp matching the start of any statement followed by a paren sexp | |
1477 ;; and then by a substatement. | |
1478 t (c-make-keywords-re t (c-lang-const c-block-stmt-2-kwds))) | |
1479 (c-lang-defvar c-block-stmt-2-key (c-lang-const c-block-stmt-2-key)) | |
1480 | |
1481 (c-lang-defconst c-opt-block-stmt-key | |
1482 ;; Regexp matching the start of any statement that has a | |
1483 ;; substatement (except a bare block). Nil in languages that | |
1484 ;; don't have such constructs. | |
1485 t (if (or (c-lang-const c-block-stmt-1-kwds) | |
1486 (c-lang-const c-block-stmt-2-kwds)) | |
1487 (c-make-keywords-re t | |
1488 (append (c-lang-const c-block-stmt-1-kwds) | |
1489 (c-lang-const c-block-stmt-2-kwds))))) | |
1490 (c-lang-defvar c-opt-block-stmt-key (c-lang-const c-opt-block-stmt-key)) | |
1491 | |
1492 (c-lang-defconst c-simple-stmt-kwds | |
1493 "Statement keywords followed by an expression or nothing." | |
1494 t '("break" "continue" "goto" "return") | |
1495 ;; Note: `goto' is not valid in Java, but the keyword is still reserved. | |
1496 java '("break" "continue" "goto" "return" "throw") | |
1497 idl nil | |
1498 pike '("break" "continue" "return") | |
1499 awk '(;; Not sure about "delete", "exit", "getline", etc. ; ACM 2002/5/30 | |
1500 "break" "continue" "return" "delete" "exit" "getline" "next" | |
1501 "nextfile" "print" "printf")) | |
1502 | |
1503 (c-lang-defconst c-simple-stmt-key | |
1504 ;; Adorned regexp matching `c-simple-stmt-kwds'. | |
1505 t (c-make-keywords-re t (c-lang-const c-simple-stmt-kwds))) | |
1506 (c-lang-defvar c-simple-stmt-key (c-lang-const c-simple-stmt-key)) | |
1507 | |
1508 (c-lang-defconst c-paren-stmt-kwds | |
1509 "Statement keywords followed by a parenthesis expression that | |
1510 nevertheless contains a list separated with ';' and not ','." | |
1511 t '("for") | |
1512 idl nil) | |
1513 | |
1514 (c-lang-defconst c-paren-stmt-key | |
1515 ;; Adorned regexp matching `c-paren-stmt-kwds'. | |
1516 t (c-make-keywords-re t (c-lang-const c-paren-stmt-kwds))) | |
1517 (c-lang-defvar c-paren-stmt-key (c-lang-const c-paren-stmt-key)) | |
1518 | |
1519 (c-lang-defconst c-asm-stmt-kwds | |
1520 "Statement keywords followed by an assembler expression." | |
1521 t nil | |
1522 (c c++) '("asm" "__asm__")) ;; Not standard, but common. | |
1523 | |
1524 (c-lang-defconst c-opt-asm-stmt-key | |
1525 ;; Regexp matching the start of an assembler statement. Nil in | |
1526 ;; languages that don't support that. | |
1527 t (if (c-lang-const c-asm-stmt-kwds) | |
1528 (c-make-keywords-re t (c-lang-const c-asm-stmt-kwds)))) | |
1529 (c-lang-defvar c-opt-asm-stmt-key (c-lang-const c-opt-asm-stmt-key)) | |
1530 | |
1531 (c-lang-defconst c-label-kwds | |
1532 "Keywords introducing labels in blocks." | |
1533 t '("case" "default") | |
1534 awk nil) | |
1535 | |
1536 (c-lang-defconst c-before-label-kwds | |
1537 "Keywords that might be followed by a label identifier." | |
1538 t '("goto") | |
1539 (java pike) (append '("break" "continue") | |
1540 (c-lang-const c-before-label-kwds)) | |
1541 idl nil | |
1542 awk nil) | |
1543 | |
1544 (c-lang-defconst c-label-kwds-regexp | |
1545 ;; Regexp matching any keyword that introduces a label. | |
1546 t (c-make-keywords-re t (c-lang-const c-label-kwds))) | |
1547 (c-lang-defvar c-label-kwds-regexp (c-lang-const c-label-kwds-regexp)) | |
1548 | |
1549 (c-lang-defconst c-constant-kwds | |
1550 "Keywords for constants." | |
1551 t nil | |
1552 (c c++) '("NULL" ;; Not a keyword, but practically works as one. | |
1553 "false" "true") ; Defined in C99. | |
1554 objc '("nil" "Nil") | |
1555 idl '("TRUE" "FALSE") | |
1556 pike '("UNDEFINED")) ;; Not a keyword, but practically works as one. | |
1557 | |
1558 (c-lang-defconst c-primary-expr-kwds | |
1559 "Keywords besides constants and operators that start primary expressions." | |
1560 t nil | |
1561 c++ '("operator" "this") | |
1562 objc '("super" "self") | |
1563 java '("this") | |
1564 pike '("this")) ;; Not really a keyword, but practically works as one. | |
1565 | |
1566 (c-lang-defconst c-expr-kwds | |
1567 ;; Keywords that can occur anywhere in expressions. Built from | |
1568 ;; `c-primary-expr-kwds' and all keyword operators in `c-operators'. | |
1569 t (delete-duplicates | |
1570 (append (c-lang-const c-primary-expr-kwds) | |
1571 (c-with-syntax-table (c-lang-const c-mode-syntax-table) | |
1572 (mapcan (lambda (op) | |
1573 (and (string-match "\\`\\(\\w\\|\\s_\\)+\\'" op) | |
1574 (list op))) | |
1575 (c-lang-const c-operator-list)))) | |
1576 :test 'string-equal)) | |
1577 | |
1578 (c-lang-defconst c-lambda-kwds | |
1579 "Keywords that start lambda constructs, i.e. function definitions in | |
1580 expressions." | |
1581 t nil | |
1582 pike '("lambda")) | |
1583 | |
1584 (c-lang-defconst c-opt-lambda-key | |
1585 ;; Adorned regexp matching the start of lambda constructs, or nil in | |
1586 ;; languages that don't have such things. | |
1587 t (and (c-lang-const c-lambda-kwds) | |
1588 (c-make-keywords-re t (c-lang-const c-lambda-kwds)))) | |
1589 (c-lang-defvar c-opt-lambda-key (c-lang-const c-opt-lambda-key)) | |
1590 | |
1591 (c-lang-defconst c-inexpr-block-kwds | |
1592 "Keywords that start constructs followed by statement blocks which can | |
1593 be used in expressions \(the gcc extension for this in C and C++ is | |
1594 handled separately)." | |
1595 t nil | |
1596 pike '("catch" "gauge")) | |
1597 | |
1598 (c-lang-defconst c-opt-inexpr-block-key | |
1599 ;; Regexp matching the start of in-expression statements, or nil in | |
1600 ;; languages that don't have such things. | |
1601 t nil | |
1602 pike (c-make-keywords-re t (c-lang-const c-inexpr-block-kwds))) | |
1603 (c-lang-defvar c-opt-inexpr-block-key (c-lang-const c-opt-inexpr-block-key)) | |
1604 | |
1605 (c-lang-defconst c-inexpr-class-kwds | |
1606 "Keywords that can start classes inside expressions." | |
1607 t nil | |
1608 java '("new") | |
1609 pike '("class")) | |
1610 | |
1611 (c-lang-defconst c-opt-inexpr-class-key | |
1612 ;; Regexp matching the start of a class in an expression, or nil in | |
1613 ;; languages that don't have such things. | |
1614 t (and (c-lang-const c-inexpr-class-kwds) | |
1615 (c-make-keywords-re t (c-lang-const c-inexpr-class-kwds)))) | |
1616 (c-lang-defvar c-opt-inexpr-class-key (c-lang-const c-opt-inexpr-class-key)) | |
1617 | |
1618 (c-lang-defconst c-inexpr-brace-list-kwds | |
1619 "Keywords that can start brace list blocks inside expressions. | |
1620 Note that Java specific rules are currently applied to tell this from | |
1621 `c-inexpr-class-kwds'." | |
1622 t nil | |
1623 java '("new")) | |
1624 | |
1625 (c-lang-defconst c-opt-inexpr-brace-list-key | |
1626 ;; Regexp matching the start of a brace list in an expression, or | |
1627 ;; nil in languages that don't have such things. This should not | |
1628 ;; match brace lists recognized through `c-special-brace-lists'. | |
1629 t (and (c-lang-const c-inexpr-brace-list-kwds) | |
1630 (c-make-keywords-re t (c-lang-const c-inexpr-brace-list-kwds)))) | |
1631 (c-lang-defvar c-opt-inexpr-brace-list-key | |
1632 (c-lang-const c-opt-inexpr-brace-list-key)) | |
1633 | |
1634 (c-lang-defconst c-any-class-key | |
1635 ;; Regexp matching the start of any class, both at top level and in | |
1636 ;; expressions. | |
1637 t (c-make-keywords-re t | |
1638 (append (c-lang-const c-class-decl-kwds) | |
1639 (c-lang-const c-inexpr-class-kwds)))) | |
1640 (c-lang-defvar c-any-class-key (c-lang-const c-any-class-key)) | |
1641 | |
1642 (c-lang-defconst c-decl-block-key | |
1643 ;; Regexp matching the start of any declaration-level block that | |
1644 ;; contain another declaration level, i.e. that isn't a function | |
1645 ;; block or brace list. | |
1646 t (c-make-keywords-re t | |
1647 (append (c-lang-const c-class-decl-kwds) | |
1648 (c-lang-const c-other-block-decl-kwds) | |
1649 (c-lang-const c-inexpr-class-kwds))) | |
1650 ;; In Pike modifiers might be followed by a block | |
1651 ;; to apply to several declarations. | |
1652 pike (concat (c-lang-const c-decl-block-key) | |
1653 "\\|" | |
1654 "\\(" (c-make-keywords-re nil | |
1655 (c-lang-const c-modifier-kwds)) "\\)" | |
1656 (c-lang-const c-syntactic-ws) | |
1657 "{")) | |
1658 (c-lang-defvar c-decl-block-key (c-lang-const c-decl-block-key)) | |
1659 | |
1660 (c-lang-defconst c-bitfield-kwds | |
1661 "Keywords that can introduce bitfields." | |
1662 t nil | |
1663 (c c++ objc) '("char" "int" "long" "signed" "unsigned")) | |
1664 | |
1665 (c-lang-defconst c-opt-bitfield-key | |
1666 ;; Regexp matching the start of a bitfield (not uniquely), or nil in | |
1667 ;; languages without bitfield support. | |
1668 t nil | |
1669 (c c++) (c-make-keywords-re t (c-lang-const c-bitfield-kwds))) | |
1670 (c-lang-defvar c-opt-bitfield-key (c-lang-const c-opt-bitfield-key)) | |
1671 | |
1672 (c-lang-defconst c-other-kwds | |
1673 "Keywords not accounted for by any other `*-kwds' language constant." | |
1674 t nil | |
1675 idl '("truncatable" | |
1676 ;; In CORBA CIDL: (These are declaration keywords that never | |
1677 ;; can start a declaration.) | |
1678 "entity" "process" "service" "session" "storage")) | |
1679 | |
1680 | |
1681 ;;; Constants built from keywords. | |
1682 | |
1683 ;; Note: No `*-kwds' language constants may be defined below this point. | |
1684 | |
1685 (eval-and-compile | |
1686 (defconst c-kwds-lang-consts | |
1687 ;; List of all the language constants that contain keyword lists. | |
1688 (let (list) | |
1689 (mapatoms (lambda (sym) | |
1690 (when (and (boundp sym) | |
1691 (string-match "-kwds\\'" (symbol-name sym))) | |
1692 ;; Make the list of globally interned symbols | |
1693 ;; instead of ones interned in `c-lang-constants'. | |
1694 (setq list (cons (intern (symbol-name sym)) list)))) | |
1695 c-lang-constants) | |
1696 list))) | |
1697 | |
1698 (c-lang-defconst c-keywords | |
1699 ;; All keywords as a list. | |
1700 t (delete-duplicates | |
1701 (c-lang-defconst-eval-immediately | |
1702 `(append ,@(mapcar (lambda (kwds-lang-const) | |
1703 `(c-lang-const ,kwds-lang-const)) | |
1704 c-kwds-lang-consts) | |
1705 nil)) | |
1706 :test 'string-equal)) | |
1707 | |
1708 (c-lang-defconst c-keywords-regexp | |
1709 ;; All keywords as an adorned regexp. | |
1710 t (c-make-keywords-re t (c-lang-const c-keywords))) | |
1711 (c-lang-defvar c-keywords-regexp (c-lang-const c-keywords-regexp)) | |
1712 | |
1713 (c-lang-defconst c-keyword-member-alist | |
1714 ;; An alist with all the keywords in the cars. The cdr for each | |
1715 ;; keyword is a list of the symbols for the `*-kwds' lists that | |
1716 ;; contains it. | |
1717 t (let ((kwd-list-alist | |
1718 (c-lang-defconst-eval-immediately | |
1719 `(list ,@(mapcar (lambda (kwds-lang-const) | |
1720 `(cons ',kwds-lang-const | |
1721 (c-lang-const ,kwds-lang-const))) | |
1722 c-kwds-lang-consts)))) | |
1723 lang-const kwd-list kwd | |
1724 result-alist elem) | |
1725 (while kwd-list-alist | |
1726 (setq lang-const (caar kwd-list-alist) | |
1727 kwd-list (cdar kwd-list-alist) | |
1728 kwd-list-alist (cdr kwd-list-alist)) | |
1729 (while kwd-list | |
1730 (setq kwd (car kwd-list) | |
1731 kwd-list (cdr kwd-list)) | |
1732 (unless (setq elem (assoc kwd result-alist)) | |
1733 (setq result-alist (cons (setq elem (list kwd)) result-alist))) | |
1734 (unless (memq lang-const (cdr elem)) | |
1735 (setcdr elem (cons lang-const (cdr elem)))))) | |
1736 result-alist)) | |
1737 | |
1738 (c-lang-defvar c-keywords-obarray | |
1739 ;; An obarray containing all keywords as symbols. The property list | |
1740 ;; of each symbol has a non-nil entry for the specific `*-kwds' | |
1741 ;; lists it's a member of. | |
1742 ;; | |
1743 ;; E.g. to see whether the string str contains a keyword on | |
1744 ;; `c-class-decl-kwds', one can do like this: | |
1745 ;; (get (intern-soft str c-keyword-obarray) 'c-class-decl-kwds) | |
1746 ;; Which preferably is written using the associated functions in | |
1747 ;; cc-engine: | |
1748 ;; (c-keyword-member (c-keyword-sym str) 'c-class-decl-kwds) | |
1749 | |
1750 ;; The obarray is not stored directly as a language constant since | |
1751 ;; the printed representation for obarrays used in .elc files isn't | |
1752 ;; complete. | |
1753 | |
1754 (let* ((alist (c-lang-const c-keyword-member-alist)) | |
1755 kwd lang-const-list | |
1756 (obarray (make-vector (* (length alist) 2) 0))) | |
1757 (while alist | |
1758 (setq kwd (caar alist) | |
1759 lang-const-list (cdar alist) | |
1760 alist (cdr alist)) | |
1761 (setplist (intern kwd obarray) | |
1762 ;; Emacs has an odd bug that causes `mapcan' to fail | |
1763 ;; with unintelligible errors. (XEmacs >= 20 works.) | |
1764 ;;(mapcan (lambda (lang-const) | |
1765 ;; (list lang-const t)) | |
1766 ;; lang-const-list) | |
1767 (apply 'nconc (mapcar (lambda (lang-const) | |
1768 (list lang-const t)) | |
1769 lang-const-list)))) | |
1770 obarray)) | |
1771 | |
1772 (c-lang-defconst c-regular-keywords-regexp | |
1773 ;; Adorned regexp matching all keywords that aren't types or | |
1774 ;; constants. | |
1775 t (c-make-keywords-re t | |
1776 (set-difference (c-lang-const c-keywords) | |
1777 (append (c-lang-const c-primitive-type-kwds) | |
1778 (c-lang-const c-constant-kwds)) | |
1779 :test 'string-equal))) | |
1780 (c-lang-defvar c-regular-keywords-regexp | |
1781 (c-lang-const c-regular-keywords-regexp)) | |
1782 | |
1783 (c-lang-defconst c-not-decl-init-keywords | |
1784 ;; Adorned regexp matching all keywords that can't appear at the | |
1785 ;; start of a declaration. | |
1786 t (c-make-keywords-re t | |
1787 (set-difference (c-lang-const c-keywords) | |
1788 (append (c-lang-const c-primitive-type-kwds) | |
1789 (c-lang-const c-type-prefix-kwds) | |
1790 (c-lang-const c-type-modifier-kwds) | |
1791 (c-lang-const c-class-decl-kwds) | |
1792 (c-lang-const c-brace-list-decl-kwds) | |
1793 (c-lang-const c-other-block-decl-kwds) | |
1794 (c-lang-const c-typedef-decl-kwds) | |
1795 (c-lang-const c-typeless-decl-kwds) | |
1796 (c-lang-const c-modifier-kwds) | |
1797 (c-lang-const c-other-decl-kwds)) | |
1798 :test 'string-equal))) | |
1799 (c-lang-defvar c-not-decl-init-keywords | |
1800 (c-lang-const c-not-decl-init-keywords)) | |
1801 | |
1802 (c-lang-defconst c-primary-expr-regexp | |
1803 ;; Regexp matching the start of any primary expression, i.e. any | |
1804 ;; literal, symbol, prefix operator, and '('. It doesn't need to | |
1805 ;; exclude keywords; they are excluded afterwards unless the second | |
1806 ;; submatch matches. If the first but not the second submatch | |
1807 ;; matches then it is an ambiguous primary expression; it could also | |
1808 ;; be a match of e.g. an infix operator. (The case with ambiguous | |
1809 ;; keyword operators isn't handled.) | |
1810 | |
1811 t (c-with-syntax-table (c-lang-const c-mode-syntax-table) | |
1812 (let* ((prefix-ops | |
1813 (mapcan (lambda (op) | |
1814 ;; Filter out the special case prefix | |
1815 ;; operators that are close parens. | |
1816 (unless (string-match "\\s\)" op) | |
1817 (list op))) | |
1818 (mapcan | |
1819 (lambda (opclass) | |
1820 (when (eq (car opclass) 'prefix) | |
1821 (append (cdr opclass) nil))) | |
1822 (c-lang-const c-operators)))) | |
1823 | |
1824 (nonkeyword-prefix-ops | |
1825 (mapcan (lambda (op) | |
1826 (unless (string-match "\\`\\(\\w\\|\\s_\\)+\\'" op) | |
1827 (list op))) | |
1828 prefix-ops)) | |
1829 | |
1830 (in-or-postfix-ops | |
1831 (mapcan (lambda (opclass) | |
1832 (when (memq (car opclass) | |
1833 '(postfix | |
1834 left-assoc | |
1835 right-assoc | |
1836 right-assoc-sequence)) | |
1837 (append (cdr opclass) nil))) | |
1838 (c-lang-const c-operators))) | |
1839 | |
1840 (unambiguous-prefix-ops (set-difference nonkeyword-prefix-ops | |
1841 in-or-postfix-ops | |
1842 :test 'string-equal)) | |
1843 (ambiguous-prefix-ops (intersection nonkeyword-prefix-ops | |
1844 in-or-postfix-ops | |
1845 :test 'string-equal))) | |
1846 | |
1847 (concat | |
1848 "\\(" | |
1849 ;; Take out all symbol class operators from `prefix-ops' and make the | |
1850 ;; first submatch from them together with `c-primary-expr-kwds'. | |
1851 (c-make-keywords-re t | |
1852 (append (c-lang-const c-primary-expr-kwds) | |
1853 (set-difference prefix-ops nonkeyword-prefix-ops | |
1854 :test 'string-equal))) | |
1855 | |
1856 "\\|" | |
1857 ;; Match all ambiguous operators. | |
1858 (c-make-keywords-re nil | |
1859 (intersection nonkeyword-prefix-ops in-or-postfix-ops | |
1860 :test 'string-equal)) | |
1861 "\\)" | |
1862 | |
1863 "\\|" | |
1864 ;; Now match all other symbols. | |
1865 (c-lang-const c-symbol-start) | |
1866 | |
1867 "\\|" | |
1868 ;; The chars that can start integer and floating point | |
1869 ;; constants. | |
1870 "\\.?[0-9]" | |
1871 | |
1872 "\\|" | |
1873 ;; The nonambiguous operators from `prefix-ops'. | |
1874 (c-make-keywords-re nil | |
1875 (set-difference nonkeyword-prefix-ops in-or-postfix-ops | |
1876 :test 'string-equal)) | |
1877 | |
1878 "\\|" | |
1879 ;; Match string and character literals. | |
1880 "\\s\"" | |
1881 (if (memq 'gen-string-delim c-emacs-features) | |
1882 "\\|\\s|" | |
1883 ""))))) | |
1884 (c-lang-defvar c-primary-expr-regexp (c-lang-const c-primary-expr-regexp)) | |
1885 | |
1886 | |
1887 ;;; Additional constants for parser-level constructs. | |
1888 | |
1889 (c-lang-defconst c-decl-prefix-re | |
1890 "Regexp matching something that might precede a declaration or a cast, | |
1891 such as the last token of a preceding statement or declaration. It | |
1892 should not match bob, though. It can't require a match longer than | |
1893 one token. The end of the token is taken to be at the end of the | |
1894 first submatch. It must not include any following whitespace. It's | |
1895 undefined whether identifier syntax (see `c-identifier-syntax-table') | |
1896 is in effect or not." | |
1897 ;; We match a sequence of characters to skip over things like \"};\" | |
1898 ;; more quickly. We match ")" in C for K&R region declarations, and | |
1899 ;; in all languages except Java for when a cpp macro definition | |
1900 ;; begins with a declaration. | |
1901 t "\\([\{\}\(\);,]+\\)" | |
1902 java "\\([\{\}\(;,]+\\)" | |
1903 ;; Match "<" in C++ to get the first argument in a template arglist. | |
1904 ;; In that case there's an additional check in `c-find-decl-spots' | |
1905 ;; that it got open paren syntax. | |
1906 ;; | |
1907 ;; Also match a single ":" for protection labels. We cheat a little | |
1908 ;; and require a symbol immediately before to avoid false matches | |
1909 ;; when starting directly on a single ":", which can be the start of | |
1910 ;; the base class initializer list in a constructor. | |
1911 c++ "\\([\{\}\(\);,<]+\\|\\(\\w\\|\\s_\\):\\)\\([^:]\\|\\'\\)" | |
1912 ;; Additionally match the protection directives in Objective-C. | |
1913 ;; Note that this doesn't cope with the longer directives, which we | |
1914 ;; would have to match from start to end since they don't end with | |
1915 ;; any easily recognized characters. | |
1916 objc (concat "\\([\{\}\(\);,]+\\|" | |
1917 (c-make-keywords-re nil (c-lang-const c-protection-kwds)) | |
1918 "\\)") | |
1919 ;; Match ":" for switch labels inside union declarations in IDL. | |
1920 idl "\\([\{\}\(\);:,]+\\)\\([^:]\\|\\'\\)" | |
1921 ;; Pike is like C but we also match "[" for multiple value | |
1922 ;; assignments and type casts. | |
1923 pike "\\([\{\}\(\)\[;,]+\\)") | |
1924 (c-lang-defvar c-decl-prefix-re (c-lang-const c-decl-prefix-re) | |
1925 'dont-doc) | |
1926 | |
1927 (c-lang-defconst c-cast-parens | |
1928 ;; List containing the paren characters that can open a cast, or nil in | |
1929 ;; languages without casts. | |
1930 t (c-with-syntax-table (c-lang-const c-mode-syntax-table) | |
1931 (mapcan (lambda (opclass) | |
1932 (when (eq (car opclass) 'prefix) | |
1933 (mapcan (lambda (op) | |
1934 (when (string-match "\\`\\s\(\\'" op) | |
1935 (list (elt op 0)))) | |
1936 (cdr opclass)))) | |
1937 (c-lang-const c-operators)))) | |
1938 (c-lang-defvar c-cast-parens (c-lang-const c-cast-parens)) | |
1939 | |
1940 (c-lang-defconst c-type-decl-prefix-key | |
1941 "Regexp matching the operators that might precede the identifier in a | |
1942 declaration, e.g. the \"*\" in \"char *argv\". This regexp should | |
1943 match \"(\" if parentheses are valid in type declarations. The end of | |
1944 the first submatch is taken as the end of the operator. Identifier | |
1945 syntax is in effect when this is matched (see `c-identifier-syntax-table')." | |
1946 t (if (c-lang-const c-type-modifier-kwds) | |
1947 (concat (c-regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>") | |
1948 ;; Default to a regexp that never matches. | |
1949 "\\<\\>") | |
1950 (c objc) (concat "\\(" | |
1951 "[*\(]" | |
1952 "\\|" | |
1953 (c-lang-const c-type-decl-prefix-key) | |
1954 "\\)" | |
1955 "\\([^=]\\|$\\)") | |
1956 c++ (concat "\\(" | |
1957 "[*\(&]" | |
1958 "\\|" | |
1959 (concat "\\(" ; 2 | |
1960 ;; If this matches there's special treatment in | |
1961 ;; `c-font-lock-declarators' and | |
1962 ;; `c-font-lock-declarations' that check for a | |
1963 ;; complete name followed by ":: *". | |
1964 (c-lang-const c-identifier-start) | |
1965 "\\)") | |
1966 "\\|" | |
1967 (c-lang-const c-type-decl-prefix-key) | |
1968 "\\)" | |
1969 "\\([^=]\\|$\\)") | |
1970 pike "\\([*\(!~]\\)\\([^=]\\|$\\)") | |
1971 (c-lang-defvar c-type-decl-prefix-key (c-lang-const c-type-decl-prefix-key) | |
1972 'dont-doc) | |
1973 | |
1974 (c-lang-defconst c-type-decl-suffix-key | |
1975 "Regexp matching the operators that might follow after the identifier | |
1976 in a declaration, e.g. the \"[\" in \"char argv[]\". This regexp | |
1977 should match \")\" if parentheses are valid in type declarations. If | |
1978 it matches an open paren of some kind, the type declaration check | |
1979 continues at the corresponding close paren, otherwise the end of the | |
1980 first submatch is taken as the end of the operator. Identifier syntax | |
1981 is in effect when this is matched (see `c-identifier-syntax-table')." | |
1982 ;; Default to a regexp that matches `c-type-modifier-kwds' and a | |
1983 ;; function argument list parenthesis. | |
1984 t (if (c-lang-const c-type-modifier-kwds) | |
1985 (concat "\\(\(\\|" | |
1986 (c-regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>" | |
1987 "\\)") | |
1988 "\\(\(\\)") | |
1989 (c c++ objc) (concat | |
1990 "\\(" | |
1991 "[\)\[\(]" | |
1992 "\\|" | |
1993 ;; "throw" in `c-type-modifier-kwds' is followed by a | |
1994 ;; parenthesis list, but no extra measures are | |
1995 ;; necessary to handle that. | |
1996 (c-regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>" | |
1997 "\\)") | |
1998 (java idl) "\\([\[\(]\\)") | |
1999 (c-lang-defvar c-type-decl-suffix-key (c-lang-const c-type-decl-suffix-key) | |
2000 'dont-doc) | |
2001 | |
2002 (c-lang-defconst c-after-suffixed-type-decl-key | |
2003 "This regexp is matched after a type declaration expression where | |
2004 `c-type-decl-suffix-key' has matched. If it matches then the | |
2005 construct is taken as a declaration. It's typically used to match the | |
2006 beginning of a function body or whatever might occur after the | |
2007 function header in a function declaration or definition. It's | |
2008 undefined whether identifier syntax (see `c-identifier-syntax-table') | |
2009 is in effect or not. | |
2010 | |
2011 Note that it's used in cases like after \"foo (bar)\" so it should | |
2012 only match when it's certain that it's a declaration, e.g \"{\" but | |
2013 not \",\" or \";\"." | |
2014 t "{" | |
2015 ;; If K&R style declarations should be recognized then one could | |
2016 ;; consider to match the start of any symbol since we want to match | |
2017 ;; the start of the first declaration in the "K&R region". That | |
2018 ;; could however produce false matches on code like "FOO(bar) x" | |
2019 ;; where FOO is a cpp macro, so it's better to leave it out and rely | |
2020 ;; on the other heuristics in that case. | |
2021 t (if (c-lang-const c-postfix-decl-spec-kwds) | |
2022 ;; Add on the keywords in `c-postfix-decl-spec-kwds'. | |
2023 (concat (c-lang-const c-after-suffixed-type-decl-key) | |
2024 "\\|" | |
2025 (c-make-keywords-re t (c-lang-const c-postfix-decl-spec-kwds))) | |
2026 (c-lang-const c-after-suffixed-type-decl-key)) | |
2027 ;; Also match the colon that starts a base class initializer list in | |
2028 ;; C++. That can be confused with a function call before the colon | |
2029 ;; in a ? : operator, but we count on that `c-decl-prefix-re' won't | |
2030 ;; match before such a thing (as a declaration-level construct; | |
2031 ;; matches inside arglist contexts are already excluded). | |
2032 c++ "[{:]") | |
2033 (c-lang-defvar c-after-suffixed-type-decl-key | |
2034 (c-lang-const c-after-suffixed-type-decl-key) | |
2035 'dont-doc) | |
2036 | |
2037 (c-lang-defconst c-after-suffixed-type-maybe-decl-key | |
2038 ;; Regexp that in addition to `c-after-suffixed-type-decl-key' | |
2039 ;; matches ";" and ",". | |
2040 t (concat "\\(" (c-lang-const c-after-suffixed-type-decl-key) "\\)" | |
2041 "\\|[;,]")) | |
2042 (c-lang-defvar c-after-suffixed-type-maybe-decl-key | |
2043 (c-lang-const c-after-suffixed-type-maybe-decl-key)) | |
2044 | |
2045 (c-lang-defconst c-opt-type-concat-key | |
2046 "Regexp matching operators that concatenate types, e.g. the \"|\" in | |
2047 \"int|string\" in Pike. The end of the first submatch is taken as the | |
2048 end of the operator. nil in languages without such operators. It's | |
2049 undefined whether identifier syntax (see `c-identifier-syntax-table') | |
2050 is in effect or not." | |
2051 t nil | |
2052 pike "\\([|.&]\\)\\($\\|[^|.&]\\)") | |
2053 (c-lang-defvar c-opt-type-concat-key (c-lang-const c-opt-type-concat-key) | |
2054 'dont-doc) | |
2055 | |
2056 (c-lang-defconst c-opt-type-suffix-key | |
2057 "Regexp matching operators that might follow after a type, or nil in | |
2058 languages that don't have such operators. The end of the first | |
2059 submatch is taken as the end of the operator. This should not match | |
2060 things like C++ template arglists if `c-recognize-<>-arglists' is set. | |
2061 It's undefined whether identifier syntax (see `c-identifier-syntax-table') | |
2062 is in effect or not." | |
2063 t nil | |
2064 (c c++ objc pike) "\\(\\.\\.\\.\\)" | |
2065 java "\\(\\[[ \t\n\r\f\v]*\\]\\)") | |
2066 (c-lang-defvar c-opt-type-suffix-key (c-lang-const c-opt-type-suffix-key)) | |
2067 | |
2068 (c-lang-defvar c-known-type-key | |
2069 ;; Regexp matching the known type identifiers. This is initialized | |
2070 ;; from the type keywords and `*-font-lock-extra-types'. The first | |
2071 ;; submatch is the one that matches the type. Note that this regexp | |
2072 ;; assumes that symbol constituents like '_' and '$' have word | |
2073 ;; syntax. | |
2074 (let ((extra-types (when (boundp (c-mode-symbol "font-lock-extra-types")) | |
2075 (c-mode-var "font-lock-extra-types")))) | |
2076 (concat "\\<\\(" | |
2077 (c-make-keywords-re nil (c-lang-const c-primitive-type-kwds)) | |
2078 (if (consp extra-types) | |
2079 (concat "\\|" (mapconcat 'identity extra-types "\\|")) | |
2080 "") | |
2081 "\\)\\>"))) | |
2082 | |
2083 (c-lang-defconst c-special-brace-lists | |
2084 "List of open- and close-chars that makes up a pike-style brace list, | |
2085 i.e. for a ([ ]) list there should be a cons (?\\[ . ?\\]) in this | |
2086 list." | |
2087 t nil | |
2088 pike '((?{ . ?}) (?\[ . ?\]) (?< . ?>))) | |
2089 (c-lang-defvar c-special-brace-lists (c-lang-const c-special-brace-lists)) | |
2090 | |
2091 (c-lang-defconst c-recognize-knr-p | |
2092 "Non-nil means K&R style argument declarations are valid." | |
2093 t nil | |
2094 c t) | |
2095 (c-lang-defvar c-recognize-knr-p (c-lang-const c-recognize-knr-p)) | |
2096 | |
2097 (c-lang-defconst c-recognize-typeless-decls | |
2098 "Non-nil means function declarations without return type should be | |
2099 recognized. That can introduce an ambiguity with parenthesized macro | |
2100 calls before a brace block. This setting does not affect declarations | |
2101 that are preceded by a declaration starting keyword, so | |
2102 e.g. `c-typeless-decl-kwds' may still be used when it's set to nil." | |
2103 t nil | |
2104 (c c++ objc) t) | |
2105 (c-lang-defvar c-recognize-typeless-decls | |
2106 (c-lang-const c-recognize-typeless-decls)) | |
2107 | |
2108 (c-lang-defconst c-recognize-<>-arglists | |
2109 "Non-nil means C++ style template arglists should be handled. More | |
2110 specifically, this means a comma separated list of types or | |
2111 expressions surrounded by \"<\" and \">\". It's always preceded by an | |
2112 identifier or one of the keywords on `c-<>-type-kwds' or | |
2113 `c-<>-arglist-kwds'. If there's an identifier before then the whole | |
2114 expression is considered to be a type." | |
2115 t (or (consp (c-lang-const c-<>-type-kwds)) | |
2116 (consp (c-lang-const c-<>-arglist-kwds)))) | |
2117 (c-lang-defvar c-recognize-<>-arglists (c-lang-const c-recognize-<>-arglists)) | |
2118 | |
2119 (c-lang-defconst c-recognize-paren-inits | |
2120 "Non-nil means that parenthesis style initializers exist, | |
2121 i.e. constructs like | |
2122 | |
2123 Foo bar (gnu); | |
2124 | |
2125 in addition to the more classic | |
2126 | |
2127 Foo bar = gnu;" | |
2128 t nil | |
2129 c++ t) | |
2130 (c-lang-defvar c-recognize-paren-inits (c-lang-const c-recognize-paren-inits)) | |
2131 | |
2132 (c-lang-defconst c-opt-<>-arglist-start | |
2133 ;; Regexp matching the start of angle bracket arglists in languages | |
2134 ;; where `c-recognize-<>-arglists' is set. Does not exclude | |
2135 ;; keywords outside `c-<>-arglist-kwds'. The first submatch is | |
2136 ;; assumed to surround the preceding symbol. The whole match is | |
2137 ;; assumed to end directly after the opening "<". | |
2138 t (if (c-lang-const c-recognize-<>-arglists) | |
2139 (concat "\\(" | |
2140 (c-lang-const c-symbol-key) | |
2141 "\\)" | |
2142 (c-lang-const c-syntactic-ws) | |
2143 "<"))) | |
2144 (c-lang-defvar c-opt-<>-arglist-start (c-lang-const c-opt-<>-arglist-start)) | |
2145 | |
2146 (c-lang-defconst c-opt-<>-arglist-start-in-paren | |
2147 ;; Regexp that in addition to `c-opt-<>-arglist-start' matches close | |
2148 ;; parens. The first submatch is assumed to surround | |
2149 ;; `c-opt-<>-arglist-start'. | |
2150 t (if (c-lang-const c-opt-<>-arglist-start) | |
2151 (concat "\\(" | |
2152 (c-lang-const c-opt-<>-arglist-start) | |
2153 "\\)\\|\\s\)"))) | |
2154 (c-lang-defvar c-opt-<>-arglist-start-in-paren | |
2155 (c-lang-const c-opt-<>-arglist-start-in-paren)) | |
2156 | |
2157 (c-lang-defconst c-label-key | |
2158 "Regexp matching a normal label, i.e. a label that doesn't begin with | |
2159 a keyword like switch labels. It's only used at the beginning of a | |
2160 statement." | |
2161 t "\\<\\>" | |
2162 (c c++ objc java pike) (concat "\\(" (c-lang-const c-symbol-key) "\\)" | |
2163 "[ \t\n\r\f\v]*:\\([^:]\\|$\\)")) | |
2164 (c-lang-defvar c-label-key (c-lang-const c-label-key) | |
2165 'dont-doc) | |
2166 | |
2167 (c-lang-defconst c-opt-postfix-decl-spec-key | |
2168 ;; Regexp matching the beginning of a declaration specifier in the | |
2169 ;; region between the header and the body of a declaration. | |
2170 ;; | |
2171 ;; TODO: This is currently not used uniformly; c++-mode and | |
2172 ;; java-mode each have their own ways of using it. | |
2173 t nil | |
2174 c++ (concat ":?[ \t\n\r\f\v]*\\(virtual[ \t\n\r\f\v]+\\)?\\(" | |
2175 (c-make-keywords-re nil (c-lang-const c-protection-kwds)) | |
2176 "\\)[ \t\n\r\f\v]+" | |
2177 "\\(" (c-lang-const c-symbol-key) "\\)") | |
2178 java (c-make-keywords-re t (c-lang-const c-postfix-decl-spec-kwds))) | |
2179 (c-lang-defvar c-opt-postfix-decl-spec-key | |
2180 (c-lang-const c-opt-postfix-decl-spec-key)) | |
2181 | |
2182 (c-lang-defconst c-opt-friend-key | |
2183 ;; Regexp describing friend declarations classes, or nil in | |
2184 ;; languages that don't have such things. | |
2185 ;; | |
2186 ;; TODO: Ought to use `c-specifier-key' or similar, and the template | |
2187 ;; skipping isn't done properly. This will disappear soon. | |
2188 t nil | |
2189 c++ "friend[ \t]+\\|template[ \t]*<.+>[ \t]*friend[ \t]+") | |
2190 (c-lang-defvar c-opt-friend-key (c-lang-const c-opt-friend-key)) | |
2191 | |
2192 (c-lang-defconst c-opt-method-key | |
2193 ;; Special regexp to match the start of Objective-C methods. The | |
2194 ;; first submatch is assumed to end after the + or - key. | |
2195 t nil | |
2196 objc (concat | |
2197 ;; TODO: Ought to use a better method than anchoring on bol. | |
2198 "^[ \t]*\\([+-]\\)[ \t\n\r\f\v]*" | |
2199 "\\(([^)]*)[ \t\n\r\f\v]*\\)?" ; return type | |
2200 "\\(" (c-lang-const c-symbol-key) "\\)")) | |
2201 (c-lang-defvar c-opt-method-key (c-lang-const c-opt-method-key)) | |
2202 | |
2203 | |
2204 ;;; Wrap up the `c-lang-defvar' system. | |
2205 | |
2206 ;; Compile in the list of language variables that has been collected | |
2207 ;; with the `c-lang-defvar' macro. Note that the first element is | |
2208 ;; nil. | |
2209 (defconst c-lang-variable-inits (cc-eval-when-compile c-lang-variable-inits)) | |
2210 | |
2211 (defun c-make-init-lang-vars-fun (mode) | |
2212 "Create a function that initializes all the language dependent variables | |
2213 for the given mode. | |
2214 | |
2215 This function should be evaluated at compile time, so that the | |
2216 function it returns is byte compiled with all the evaluated results | |
2217 from the language constants. Use the `c-init-language-vars' macro to | |
2218 accomplish that conveniently. | |
2219 | |
2220 This function does not do any hidden buffer changes." | |
2221 | |
2222 (if (and (not load-in-progress) | |
2223 (boundp 'byte-compile-dest-file) | |
2224 (stringp byte-compile-dest-file)) | |
2225 | |
2226 ;; No need to byte compile this lambda since the byte compiler is | |
2227 ;; smart enough to detect the `funcall' construct in the | |
2228 ;; `c-init-language-vars' macro below and compile it all straight | |
2229 ;; into the function that contains `c-init-language-vars'. | |
2230 `(lambda () | |
2231 | |
2232 ;; This let sets up the context for `c-mode-var' and similar | |
2233 ;; that could be in the result from `cl-macroexpand-all'. | |
2234 (let ((c-buffer-is-cc-mode ',mode) | |
2235 current-var) | |
2236 (condition-case err | |
2237 | |
2238 (if (eq c-version-sym ',c-version-sym) | |
2239 (setq ,@(let ((c-buffer-is-cc-mode mode) | |
2240 (c-lang-const-expansion 'immediate)) | |
2241 ;; `c-lang-const' will expand to the evaluated | |
2242 ;; constant immediately in `cl-macroexpand-all' | |
2243 ;; below. | |
2244 (mapcan | |
2245 (lambda (init) | |
2246 `(current-var ',(car init) | |
2247 ,(car init) ,(cl-macroexpand-all | |
2248 (elt init 1)))) | |
2249 (cdr c-lang-variable-inits)))) | |
2250 | |
2251 (unless (get ',mode 'c-has-warned-lang-consts) | |
2252 (message ,(concat "%s compiled with CC Mode %s " | |
2253 "but loaded with %s - evaluating " | |
2254 "language constants from source") | |
2255 ',mode ,c-version c-version) | |
2256 (put ',mode 'c-has-warned-lang-consts t)) | |
2257 | |
2258 (require 'cc-langs) | |
2259 (let ((init (cdr c-lang-variable-inits))) | |
2260 (while init | |
2261 (setq current-var (caar init)) | |
2262 (set (caar init) (eval (cadar init))) | |
2263 (setq init (cdr init))))) | |
2264 | |
2265 (error | |
2266 (if current-var | |
2267 (message "Eval error in the `c-lang-defvar' for `%s': %S" | |
2268 current-var err) | |
2269 (signal (car err) (cdr err))))))) | |
2270 | |
2271 ;; Being evaluated from source. Always use the dynamic method to | |
2272 ;; work well when `c-lang-defvar's in this file are reevaluated | |
2273 ;; interactively. | |
2274 `(lambda () | |
2275 (require 'cc-langs) | |
2276 (let ((c-buffer-is-cc-mode ',mode) | |
2277 (init (cdr c-lang-variable-inits)) | |
2278 current-var) | |
2279 (condition-case err | |
2280 | |
2281 (while init | |
2282 (setq current-var (caar init)) | |
2283 (set (caar init) (eval (cadar init))) | |
2284 (setq init (cdr init))) | |
2285 | |
2286 (error | |
2287 (if current-var | |
2288 (message "Eval error in the `c-lang-defvar' for `%s': %S" | |
2289 current-var err) | |
2290 (signal (car err) (cdr err))))))) | |
2291 )) | |
2292 | |
2293 (defmacro c-init-language-vars (mode) | |
2294 "Initialize all the language dependent variables for the given mode. | |
2295 This macro is expanded at compile time to a form tailored for the mode | |
2296 in question, so MODE must be a constant. Therefore MODE is not | |
2297 evaluated and should not be quoted. | |
2298 | |
2299 This macro does not do any hidden buffer changes." | |
2300 `(funcall ,(c-make-init-lang-vars-fun mode))) | |
736 | 2301 |
737 | 2302 |
738 (cc-provide 'cc-langs) | 2303 (cc-provide 'cc-langs) |
739 | 2304 |
740 ;;; cc-langs.el ends here | 2305 ;;; cc-langs.el ends here |