Commit | Line | Data |
---|---|---|
130c507e | 1 | ;;; cc-langs.el --- language specific settings for CC Mode |
785eecbb | 2 | |
95df8112 | 3 | ;; Copyright (C) 1985, 1987, 1992-2011 Free Software Foundation, Inc. |
785eecbb | 4 | |
e309f66c AM |
5 | ;; Authors: 2002- Alan Mackenzie |
6 | ;; 1998- Martin Stjernholm | |
d9e94c22 | 7 | ;; 1992-1999 Barry A. Warsaw |
5858f68c GM |
8 | ;; 1987 Dave Detlefs |
9 | ;; 1987 Stewart Clamen | |
785eecbb | 10 | ;; 1985 Richard M. Stallman |
0ec8351b | 11 | ;; Maintainer: bug-cc-mode@gnu.org |
785eecbb | 12 | ;; Created: 22-Apr-1997 (split from cc-mode.el) |
bd78fa1d CY |
13 | ;; Keywords: c languages |
14 | ;; Package: cc-mode | |
785eecbb RS |
15 | |
16 | ;; This file is part of GNU Emacs. | |
17 | ||
b1fc2b50 | 18 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
785eecbb | 19 | ;; it under the terms of the GNU General Public License as published by |
b1fc2b50 GM |
20 | ;; the Free Software Foundation, either version 3 of the License, or |
21 | ;; (at your option) any later version. | |
785eecbb RS |
22 | |
23 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
24 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26 | ;; GNU General Public License for more details. | |
27 | ||
28 | ;; You should have received a copy of the GNU General Public License | |
b1fc2b50 | 29 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
785eecbb | 30 | |
3afbc435 PJ |
31 | ;;; Commentary: |
32 | ||
d9e94c22 MS |
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 | ||
3afbc435 PJ |
114 | ;;; Code: |
115 | ||
66d279a7 GM |
116 | ;; For Emacs < 22.2. |
117 | (eval-and-compile | |
118 | (unless (fboundp 'declare-function) (defmacro declare-function (&rest r)))) | |
119 | ||
51f606de GM |
120 | (eval-when-compile |
121 | (let ((load-path | |
130c507e GM |
122 | (if (and (boundp 'byte-compile-dest-file) |
123 | (stringp byte-compile-dest-file)) | |
124 | (cons (file-name-directory byte-compile-dest-file) load-path) | |
51f606de | 125 | load-path))) |
d9e94c22 | 126 | (load "cc-bytecomp" nil t))) |
51f606de | 127 | |
130c507e GM |
128 | (cc-require 'cc-defs) |
129 | (cc-require 'cc-vars) | |
a6739a05 | 130 | |
0386b551 | 131 | |
9a737a1f MS |
132 | ;; This file is not always loaded. See note above. |
133 | (cc-external-require 'cl) | |
134 | ||
785eecbb | 135 | \f |
d9e94c22 | 136 | ;;; Setup for the `c-lang-defvar' system. |
a66cd3ee MS |
137 | |
138 | (eval-and-compile | |
d9e94c22 | 139 | ;; These are used to collect the init forms from the subsequent |
26b8f810 AM |
140 | ;; `c-lang-defvar' and `c-lang-setvar'. They are used to build the |
141 | ;; lambda in `c-make-init-lang-vars-fun' below, and to build `defvar's | |
142 | ;; and `make-variable-buffer-local's in cc-engine and | |
143 | ;; `make-local-variable's in `c-init-language-vars-for'. | |
2eb455ab MS |
144 | (defvar c-lang-variable-inits nil) |
145 | (defvar c-lang-variable-inits-tail nil) | |
146 | (setq c-lang-variable-inits (list nil) | |
26b8f810 AM |
147 | c-lang-variable-inits-tail c-lang-variable-inits) |
148 | (defvar c-emacs-variable-inits nil) | |
149 | (defvar c-emacs-variable-inits-tail nil) | |
150 | (setq c-emacs-variable-inits (list nil) | |
151 | c-emacs-variable-inits-tail c-emacs-variable-inits)) | |
d9e94c22 MS |
152 | |
153 | (defmacro c-lang-defvar (var val &optional doc) | |
0386b551 AM |
154 | "Declares the buffer local variable VAR to get the value VAL. VAL is |
155 | evaluated and assigned at mode initialization. More precisely, VAL is | |
156 | evaluated and bound to VAR when the result from the macro | |
d9e94c22 MS |
157 | `c-init-language-vars' is evaluated. |
158 | ||
159 | `c-lang-const' is typically used in VAL to get the right value for the | |
160 | language being initialized, and such calls will be macro expanded to | |
0386b551 | 161 | the evaluated constant value at compile time." |
d9e94c22 MS |
162 | |
163 | (when (and (not doc) | |
164 | (eq (car-safe val) 'c-lang-const) | |
165 | (eq (nth 1 val) var) | |
166 | (not (nth 2 val))) | |
167 | ;; Special case: If there's no docstring and the value is a | |
168 | ;; simple (c-lang-const foo) where foo is the same name as VAR | |
169 | ;; then take the docstring from the language constant foo. | |
170 | (setq doc (get (intern (symbol-name (nth 1 val)) c-lang-constants) | |
171 | 'variable-documentation))) | |
172 | (or (stringp doc) | |
173 | (setq doc nil)) | |
174 | ||
175 | (let ((elem (assq var (cdr c-lang-variable-inits)))) | |
176 | (if elem | |
177 | (setcdr elem (list val doc)) | |
178 | (setcdr c-lang-variable-inits-tail (list (list var val doc))) | |
179 | (setq c-lang-variable-inits-tail (cdr c-lang-variable-inits-tail)))) | |
180 | ||
181 | ;; Return the symbol, like the other def* forms. | |
182 | `',var) | |
183 | ||
26b8f810 AM |
184 | (defmacro c-lang-setvar (var val) |
185 | "Causes the variable VAR to be made buffer local and to get set to the | |
186 | value VAL. VAL is evaluated and assigned at mode initialization. More | |
187 | precisely, VAL is evaluated and bound to VAR when the result from the | |
188 | macro `c-init-language-vars' is evaluated. VAR is typically a standard | |
189 | Emacs variable like `comment-start'. | |
190 | ||
191 | `c-lang-const' is typically used in VAL to get the right value for the | |
192 | language being initialized, and such calls will be macro expanded to | |
193 | the evaluated constant value at compile time." | |
194 | (let ((elem (assq var (cdr c-emacs-variable-inits)))) | |
195 | (if elem | |
196 | (setcdr elem (list val)) ; Maybe remove "list", sometime. 2006-07-19 | |
197 | (setcdr c-emacs-variable-inits-tail (list (list var val))) | |
198 | (setq c-emacs-variable-inits-tail (cdr c-emacs-variable-inits-tail)))) | |
199 | ||
200 | ;; Return the symbol, like the other def* forms. | |
201 | `',var) | |
202 | ||
d9e94c22 | 203 | (put 'c-lang-defvar 'lisp-indent-function 'defun) |
3c0ab532 AM |
204 | ; (eval-after-load "edebug" ; 2006-07-09: def-edebug-spec is now in subr.el. |
205 | ; ' | |
206 | (def-edebug-spec c-lang-defvar | |
207 | (&define name def-form &optional stringp)) ;) | |
c55676a1 | 208 | |
66d279a7 GM |
209 | ;; Suppress "might not be defined at runtime" warning. |
210 | ;; This file is only used when compiling other cc files. | |
211 | (declare-function delete-duplicates "cl-seq" (cl-seq &rest cl-keys)) | |
212 | (declare-function mapcan "cl-extra" (cl-func cl-seq &rest cl-rest)) | |
213 | (declare-function cl-macroexpand-all "cl-extra" (form &optional env)) | |
214 | ||
cb694ab7 | 215 | (eval-and-compile |
0386b551 AM |
216 | ;; Some helper functions used when building the language constants. |
217 | ||
218 | (defun c-filter-ops (ops opgroup-filter op-filter &optional xlate) | |
e6a9e584 | 219 | ;; Extract a subset of the operators in the list OPS in a DWIM:ey |
212906e2 AM |
220 | ;; way. The return value is a plain list of operators: |
221 | ;; | |
e6a9e584 | 222 | ;; OPS either has the structure of `c-operators', is a single |
0386b551 | 223 | ;; group in `c-operators', or is a plain list of operators. |
cd1181db | 224 | ;; |
e6a9e584 AM |
225 | ;; OPGROUP-FILTER specifies how to select the operator groups. It |
226 | ;; can be t to choose all groups, a list of group type symbols | |
227 | ;; (such as 'prefix) to accept, or a function which will be called | |
228 | ;; with the group symbol for each group and should return non-nil | |
229 | ;; if that group is to be included. | |
230 | ;; | |
0386b551 AM |
231 | ;; If XLATE is given, it's a function which is called for each |
232 | ;; matching operator and its return value is collected instead. | |
233 | ;; If it returns a list, the elements are spliced directly into | |
234 | ;; the final result, which is returned as a list with duplicates | |
e6a9e584 AM |
235 | ;; removed using `equal'. |
236 | ;; | |
237 | ;; `c-mode-syntax-table' for the current mode is in effect during | |
238 | ;; the whole procedure. | |
0386b551 AM |
239 | (unless (listp (car-safe ops)) |
240 | (setq ops (list ops))) | |
241 | (cond ((eq opgroup-filter t) | |
242 | (setq opgroup-filter (lambda (opgroup) t))) | |
243 | ((not (functionp opgroup-filter)) | |
244 | (setq opgroup-filter `(lambda (opgroup) | |
245 | (memq opgroup ',opgroup-filter))))) | |
246 | (cond ((eq op-filter t) | |
247 | (setq op-filter (lambda (op) t))) | |
248 | ((stringp op-filter) | |
249 | (setq op-filter `(lambda (op) | |
250 | (string-match ,op-filter op))))) | |
251 | (unless xlate | |
252 | (setq xlate 'identity)) | |
253 | (c-with-syntax-table (c-lang-const c-mode-syntax-table) | |
254 | (delete-duplicates | |
255 | (mapcan (lambda (opgroup) | |
256 | (when (if (symbolp (car opgroup)) | |
257 | (when (funcall opgroup-filter (car opgroup)) | |
258 | (setq opgroup (cdr opgroup)) | |
259 | t) | |
260 | t) | |
261 | (mapcan (lambda (op) | |
262 | (when (funcall op-filter op) | |
263 | (let ((res (funcall xlate op))) | |
264 | (if (listp res) res (list res))))) | |
265 | opgroup))) | |
266 | ops) | |
267 | :test 'equal)))) | |
268 | ||
51f606de | 269 | \f |
d9e94c22 MS |
270 | ;;; Various mode specific values that aren't language related. |
271 | ||
272 | (c-lang-defconst c-mode-menu | |
273 | ;; The definition for the mode menu. The menu title is prepended to | |
274 | ;; this before it's fed to `easy-menu-define'. | |
275 | t `(["Comment Out Region" comment-region | |
276 | (c-fn-region-is-active-p)] | |
277 | ["Uncomment Region" (comment-region (region-beginning) | |
278 | (region-end) '(4)) | |
279 | (c-fn-region-is-active-p)] | |
280 | ["Indent Expression" c-indent-exp | |
281 | (memq (char-after) '(?\( ?\[ ?\{))] | |
282 | ["Indent Line or Region" c-indent-line-or-region t] | |
283 | ["Fill Comment Paragraph" c-fill-paragraph t] | |
284 | "----" | |
285 | ["Backward Statement" c-beginning-of-statement t] | |
286 | ["Forward Statement" c-end-of-statement t] | |
287 | ,@(when (c-lang-const c-opt-cpp-prefix) | |
288 | ;; Only applicable if there's a cpp preprocessor. | |
289 | `(["Up Conditional" c-up-conditional t] | |
290 | ["Backward Conditional" c-backward-conditional t] | |
291 | ["Forward Conditional" c-forward-conditional t] | |
292 | "----" | |
293 | ["Macro Expand Region" c-macro-expand | |
294 | (c-fn-region-is-active-p)] | |
295 | ["Backslashify" c-backslash-region | |
296 | (c-fn-region-is-active-p)])) | |
297 | "----" | |
b14c0c55 AM |
298 | ("Style..." |
299 | ["Set Style..." c-set-style t] | |
300 | ["Show Current Style Name" (message | |
301 | "Style Name: %s" | |
302 | c-indentation-style) t] | |
303 | ["Guess Style from this Buffer" c-guess-buffer-no-install t] | |
304 | ["Install the Last Guessed Style..." c-guess-install | |
305 | (and c-guess-guessed-offsets-alist | |
306 | c-guess-guessed-basic-offset) ] | |
307 | ["View the Last Guessed Style" c-guess-view | |
308 | (and c-guess-guessed-offsets-alist | |
309 | c-guess-guessed-basic-offset) ]) | |
310 | "----" | |
d9e94c22 | 311 | ("Toggle..." |
d91362c9 NR |
312 | ["Syntactic indentation" c-toggle-syntactic-indentation |
313 | :style toggle :selected c-syntactic-indentation] | |
cb694ab7 AM |
314 | ["Electric mode" c-toggle-electric-state |
315 | :style toggle :selected c-electric-flag] | |
316 | ["Auto newline" c-toggle-auto-newline | |
d91362c9 | 317 | :style toggle :selected c-auto-newline] |
cb694ab7 AM |
318 | ["Hungry delete" c-toggle-hungry-state |
319 | :style toggle :selected c-hungry-delete-key] | |
653d1554 TH |
320 | ["Subword mode" subword-mode |
321 | :style toggle :selected (and (boundp 'subword-mode) | |
322 | subword-mode)]))) | |
a66cd3ee | 323 | |
d9e94c22 MS |
324 | \f |
325 | ;;; Syntax tables. | |
326 | ||
327 | (defun c-populate-syntax-table (table) | |
328 | "Populate the given syntax table as necessary for a C-like language. | |
329 | This includes setting ' and \" as string delimiters, and setting up | |
330 | the comment syntax to handle both line style \"//\" and block style | |
331 | \"/*\" \"*/\" comments." | |
332 | ||
333 | (modify-syntax-entry ?_ "_" table) | |
334 | (modify-syntax-entry ?\\ "\\" table) | |
335 | (modify-syntax-entry ?+ "." table) | |
336 | (modify-syntax-entry ?- "." table) | |
337 | (modify-syntax-entry ?= "." table) | |
338 | (modify-syntax-entry ?% "." table) | |
339 | (modify-syntax-entry ?< "." table) | |
340 | (modify-syntax-entry ?> "." table) | |
341 | (modify-syntax-entry ?& "." table) | |
342 | (modify-syntax-entry ?| "." table) | |
343 | (modify-syntax-entry ?\' "\"" table) | |
344 | (modify-syntax-entry ?\240 "." table) | |
345 | ||
346 | ;; Set up block and line oriented comments. The new C | |
347 | ;; standard mandates both comment styles even in C, so since | |
348 | ;; all languages now require dual comments, we make this the | |
349 | ;; default. | |
350 | (cond | |
351 | ;; XEmacs | |
352 | ((memq '8-bit c-emacs-features) | |
353 | (modify-syntax-entry ?/ ". 1456" table) | |
354 | (modify-syntax-entry ?* ". 23" table)) | |
355 | ;; Emacs | |
356 | ((memq '1-bit c-emacs-features) | |
357 | (modify-syntax-entry ?/ ". 124b" table) | |
358 | (modify-syntax-entry ?* ". 23" table)) | |
359 | ;; incompatible | |
360 | (t (error "CC Mode is incompatible with this version of Emacs"))) | |
361 | ||
362 | (modify-syntax-entry ?\n "> b" table) | |
363 | ;; Give CR the same syntax as newline, for selective-display | |
364 | (modify-syntax-entry ?\^m "> b" table)) | |
365 | ||
366 | (c-lang-defconst c-make-mode-syntax-table | |
367 | "Functions that generates the mode specific syntax tables. | |
368 | The syntax tables aren't stored directly since they're quite large." | |
369 | t `(lambda () | |
370 | (let ((table (make-syntax-table))) | |
371 | (c-populate-syntax-table table) | |
372 | ;; Mode specific syntaxes. | |
452ea855 | 373 | ,(cond ((or (c-major-mode-is 'objc-mode) (c-major-mode-is 'java-mode)) |
0386b551 AM |
374 | ;; Let '@' be part of symbols in ObjC to cope with |
375 | ;; its compiler directives as single keyword tokens. | |
376 | ;; This is then necessary since it's assumed that | |
377 | ;; every keyword is a single symbol. | |
d9e94c22 MS |
378 | `(modify-syntax-entry ?@ "_" table)) |
379 | ((c-major-mode-is 'pike-mode) | |
380 | `(modify-syntax-entry ?@ "." table))) | |
381 | table))) | |
382 | ||
383 | (c-lang-defconst c-mode-syntax-table | |
384 | ;; The syntax tables in evaluated form. Only used temporarily when | |
385 | ;; the constants in this file are evaluated. | |
386 | t (funcall (c-lang-const c-make-mode-syntax-table))) | |
387 | ||
f75ef66d | 388 | (c-lang-defconst c++-make-template-syntax-table |
d9e94c22 MS |
389 | ;; A variant of `c++-mode-syntax-table' that defines `<' and `>' as |
390 | ;; parenthesis characters. Used temporarily when template argument | |
391 | ;; lists are parsed. Note that this encourages incorrect parsing of | |
392 | ;; templates since they might contain normal operators that uses the | |
393 | ;; '<' and '>' characters. Therefore this syntax table might go | |
394 | ;; away when CC Mode handles templates correctly everywhere. | |
395 | t nil | |
452ea855 | 396 | (java c++) `(lambda () |
d9e94c22 MS |
397 | (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table)))) |
398 | (modify-syntax-entry ?< "(>" table) | |
399 | (modify-syntax-entry ?> ")<" table) | |
400 | table))) | |
401 | (c-lang-defvar c++-template-syntax-table | |
f75ef66d MS |
402 | (and (c-lang-const c++-make-template-syntax-table) |
403 | (funcall (c-lang-const c++-make-template-syntax-table)))) | |
d9e94c22 | 404 | |
dd969a56 AM |
405 | (c-lang-defconst c-no-parens-syntax-table |
406 | ;; A variant of the standard syntax table which is used to find matching | |
407 | ;; "<"s and ">"s which have been marked as parens using syntax table | |
408 | ;; properties. The other paren characters (e.g. "{", ")" "]") are given a | |
409 | ;; non-paren syntax here. so that the list commands will work on "< ... >" | |
410 | ;; even when there's unbalanced other parens inside them. | |
411 | ;; | |
412 | ;; This variable is nil for languages which don't have template stuff. | |
413 | t `(lambda () | |
414 | (if (c-lang-const c-recognize-<>-arglists) | |
415 | (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table)))) | |
416 | (modify-syntax-entry ?\( "." table) | |
417 | (modify-syntax-entry ?\) "." table) | |
418 | (modify-syntax-entry ?\[ "." table) | |
419 | (modify-syntax-entry ?\] "." table) | |
420 | (modify-syntax-entry ?\{ "." table) | |
421 | (modify-syntax-entry ?\} "." table) | |
422 | table)))) | |
423 | (c-lang-defvar c-no-parens-syntax-table | |
424 | (funcall (c-lang-const c-no-parens-syntax-table))) | |
425 | ||
d9e94c22 MS |
426 | (c-lang-defconst c-identifier-syntax-modifications |
427 | "A list that describes the modifications that should be done to the | |
428 | mode syntax table to get a syntax table that matches all identifiers | |
429 | and keywords as words. | |
430 | ||
431 | The list is just like the one used in `font-lock-defaults': Each | |
432 | element is a cons where the car is the character to modify and the cdr | |
433 | the new syntax, as accepted by `modify-syntax-entry'." | |
434 | ;; The $ character is not allowed in most languages (one exception | |
435 | ;; is Java which allows it for legacy reasons) but we still classify | |
e4769531 | 436 | ;; it as an identifier character since it's often used in various |
d9e94c22 MS |
437 | ;; machine generated identifiers. |
438 | t '((?_ . "w") (?$ . "w")) | |
452ea855 | 439 | (objc java) (append '((?@ . "w")) |
d9e94c22 MS |
440 | (c-lang-const c-identifier-syntax-modifications)) |
441 | awk '((?_ . "w"))) | |
442 | (c-lang-defvar c-identifier-syntax-modifications | |
443 | (c-lang-const c-identifier-syntax-modifications)) | |
444 | ||
445 | (c-lang-defvar c-identifier-syntax-table | |
446 | (let ((table (copy-syntax-table (c-mode-var "mode-syntax-table"))) | |
447 | (mods c-identifier-syntax-modifications) | |
448 | mod) | |
449 | (while mods | |
450 | (setq mod (car mods) | |
451 | mods (cdr mods)) | |
452 | (modify-syntax-entry (car mod) (cdr mod) table)) | |
453 | table) | |
454 | "Syntax table built on the mode syntax table but additionally | |
455 | classifies symbol constituents like '_' and '$' as word constituents, | |
456 | so that all identifiers are recognized as words.") | |
457 | ||
dd969a56 AM |
458 | (c-lang-defconst c-get-state-before-change-functions |
459 | ;; For documentation see the following c-lang-defvar of the same name. | |
460 | ;; The value here may be a list of functions or a single function. | |
461 | t nil | |
462 | c++ '(c-extend-region-for-CPP c-before-change-check-<>-operators) | |
463 | (c objc) 'c-extend-region-for-CPP | |
464 | ;; java 'c-before-change-check-<>-operators | |
465 | awk 'c-awk-record-region-clear-NL) | |
466 | (c-lang-defvar c-get-state-before-change-functions | |
467 | (let ((fs (c-lang-const c-get-state-before-change-functions))) | |
468 | (if (listp fs) | |
469 | fs | |
470 | (list fs))) | |
471 | "If non-nil, a list of functions called from c-before-change-hook. | |
472 | Typically these will record enough state to allow | |
5ee2e988 AM |
473 | `c-before-font-lock-function' to extend the region to fontify, |
474 | and may do such things as removing text-properties which must be | |
475 | recalculated. | |
476 | ||
dd969a56 AM |
477 | These functions will be run in the order given. Each of them |
478 | takes 2 parameters, the BEG and END supplied to every | |
5ee2e988 AM |
479 | before-change function; on entry, the buffer will have been |
480 | widened and match-data will have been saved; point is undefined | |
481 | on both entry and exit; the return value is ignored. | |
482 | ||
dd969a56 AM |
483 | The functions are called even when font locking isn't enabled. |
484 | ||
485 | When the mode is initialized, the functions are called with | |
486 | parameters \(point-min) and \(point-max).") | |
487 | ||
5ee2e988 AM |
488 | (c-lang-defconst c-before-font-lock-function |
489 | "If non-nil, a function called just before font locking. | |
490 | Typically it will extend the region about to be fontified \(see | |
491 | below) and will set `syntax-table' text properties on the region. | |
492 | ||
493 | It takes 3 parameters, the BEG, END, and OLD-LEN supplied to | |
494 | every after-change function; point is undefined on both entry and | |
495 | exit; on entry, the buffer will have been widened and match-data | |
496 | will have been saved; the return value is ignored. | |
497 | ||
498 | The function may extend the region to be fontified by setting the | |
8835a0f7 | 499 | buffer local variables c-new-BEG and c-new-END. |
5ee2e988 AM |
500 | |
501 | The function is called even when font locking is disabled. | |
502 | ||
503 | When the mode is initialized, this function is called with | |
504 | parameters \(point-min), \(point-max) and <buffer size>." | |
505 | t nil | |
0ec1d2c5 | 506 | (c c++ objc) 'c-neutralize-syntax-in-and-mark-CPP |
5ee2e988 AM |
507 | awk 'c-awk-extend-and-syntax-tablify-region) |
508 | (c-lang-defvar c-before-font-lock-function | |
509 | (c-lang-const c-before-font-lock-function)) | |
510 | ||
d9e94c22 | 511 | \f |
536610a4 AM |
512 | ;;; Syntactic analysis ("virtual semicolons") for line-oriented languages (AWK). |
513 | (c-lang-defconst c-at-vsemi-p-fn | |
514 | "Contains a function \"Is there a virtual semicolon at POS or point?\". | |
515 | Such a function takes one optional parameter, a buffer position (defaults to | |
516 | point), and returns nil or t. This variable contains nil for languages which | |
517 | don't have EOL terminated statements. " | |
518 | t nil | |
519 | (c c++ objc) 'c-at-macro-vsemi-p | |
520 | awk 'c-awk-at-vsemi-p) | |
521 | (c-lang-defvar c-at-vsemi-p-fn (c-lang-const c-at-vsemi-p-fn)) | |
522 | ||
523 | (c-lang-defconst c-vsemi-status-unknown-p-fn | |
524 | "Contains a function \"are we unsure whether there is a virtual semicolon on this line?\". | |
333f9019 | 525 | The (admittedly kludgy) purpose of such a function is to prevent an infinite |
536610a4 AM |
526 | recursion in c-beginning-of-statement-1 when point starts at a `while' token. |
527 | The function MUST NOT UNDER ANY CIRCUMSTANCES call c-beginning-of-statement-1, | |
528 | even indirectly. This variable contains nil for languages which don't have | |
529 | EOL terminated statements." | |
530 | t nil | |
531 | (c c++ objc) 'c-macro-vsemi-status-unknown-p | |
532 | awk 'c-awk-vsemi-status-unknown-p) | |
533 | (c-lang-defvar c-vsemi-status-unknown-p-fn | |
534 | (c-lang-const c-vsemi-status-unknown-p-fn)) | |
535 | ||
536 | \f | |
d9e94c22 MS |
537 | ;;; Lexer-level syntax (identifiers, tokens etc). |
538 | ||
b248a85d AM |
539 | (c-lang-defconst c-has-bitfields |
540 | "Whether the language has bitfield declarations." | |
541 | t nil | |
542 | (c c++ objc) t) | |
543 | (c-lang-defvar c-has-bitfields (c-lang-const c-has-bitfields)) | |
544 | ||
d9e94c22 MS |
545 | (c-lang-defconst c-symbol-start |
546 | "Regexp that matches the start of a symbol, i.e. any identifier or | |
452ea855 | 547 | keyword. It's unspecified how far it matches. Does not contain a \\| |
d9e94c22 MS |
548 | operator at the top level." |
549 | t (concat "[" c-alpha "_]") | |
452ea855 | 550 | java (concat "[" c-alpha "_@]") |
0386b551 | 551 | objc (concat "[" c-alpha "@]") |
d9e94c22 MS |
552 | pike (concat "[" c-alpha "_`]")) |
553 | (c-lang-defvar c-symbol-start (c-lang-const c-symbol-start)) | |
554 | ||
555 | (c-lang-defconst c-symbol-chars | |
556 | "Set of characters that can be part of a symbol. | |
bf2c1571 | 557 | This is of the form that fits inside [ ] in a regexp." |
d9e94c22 MS |
558 | ;; Pike note: With the backquote identifiers this would include most |
559 | ;; operator chars too, but they are handled with other means instead. | |
560 | t (concat c-alnum "_$") | |
561 | objc (concat c-alnum "_$@")) | |
b248a85d | 562 | (c-lang-defvar c-symbol-chars (c-lang-const c-symbol-chars)) |
a66cd3ee | 563 | |
a66cd3ee | 564 | (c-lang-defconst c-symbol-key |
0386b551 AM |
565 | "Regexp matching identifiers and keywords (with submatch 0). Assumed |
566 | to match if `c-symbol-start' matches on the same position." | |
d9e94c22 MS |
567 | t (concat (c-lang-const c-symbol-start) |
568 | "[" (c-lang-const c-symbol-chars) "]*") | |
569 | pike (concat | |
570 | ;; Use the value from C here since the operator backquote is | |
571 | ;; covered by the other alternative. | |
572 | (c-lang-const c-symbol-key c) | |
573 | "\\|" | |
574 | (c-make-keywords-re nil | |
575 | (c-lang-const c-overloadable-operators)))) | |
576 | (c-lang-defvar c-symbol-key (c-lang-const c-symbol-key)) | |
577 | ||
578 | (c-lang-defconst c-symbol-key-depth | |
579 | ;; Number of regexp grouping parens in `c-symbol-key'. | |
0386b551 | 580 | t (regexp-opt-depth (c-lang-const c-symbol-key))) |
d9e94c22 MS |
581 | |
582 | (c-lang-defconst c-nonsymbol-chars | |
583 | "This is the set of chars that can't be part of a symbol, i.e. the | |
584 | negation of `c-symbol-chars'." | |
585 | t (concat "^" (c-lang-const c-symbol-chars))) | |
586 | (c-lang-defvar c-nonsymbol-chars (c-lang-const c-nonsymbol-chars)) | |
587 | ||
588 | (c-lang-defconst c-nonsymbol-key | |
589 | "Regexp that matches any character that can't be part of a symbol. | |
590 | It's usually appended to other regexps to avoid matching a prefix. | |
591 | It's assumed to not contain any submatchers." | |
592 | ;; The same thing regarding Unicode identifiers applies here as to | |
593 | ;; `c-symbol-key'. | |
594 | t (concat "[" (c-lang-const c-nonsymbol-chars) "]")) | |
595 | ||
0386b551 AM |
596 | (c-lang-defconst c-identifier-ops |
597 | "The operators that make up fully qualified identifiers. nil in | |
598 | languages that don't have such things. See `c-operators' for a | |
599 | description of the format. Binary operators can concatenate symbols, | |
600 | e.g. \"::\" in \"A::B::C\". Prefix operators can precede identifiers, | |
601 | e.g. \"~\" in \"~A::B\". Other types of operators aren't supported. | |
602 | ||
603 | This value is by default merged into `c-operators'." | |
d9e94c22 | 604 | t nil |
0386b551 AM |
605 | c++ '((prefix "~" "??-" "compl") |
606 | (right-assoc "::") | |
607 | (prefix "::")) | |
2a15eb73 MS |
608 | ;; Java has "." to concatenate identifiers but it's also used for |
609 | ;; normal indexing. There's special code in the Java font lock | |
610 | ;; rules to fontify qualified identifiers based on the standard | |
611 | ;; naming conventions. We still define "." here to make | |
612 | ;; `c-forward-name' move over as long names as possible which is | |
613 | ;; necessary to e.g. handle throws clauses correctly. | |
0386b551 AM |
614 | java '((left-assoc ".")) |
615 | idl '((left-assoc "::") | |
616 | (prefix "::")) | |
617 | pike '((left-assoc "::") | |
618 | (prefix "::") | |
619 | (left-assoc "."))) | |
620 | ||
621 | (c-lang-defconst c-opt-identifier-concat-key | |
622 | ;; Appendable adorned regexp matching the operators that join | |
623 | ;; symbols to fully qualified identifiers, or nil in languages that | |
624 | ;; don't have such things. | |
625 | ;; | |
626 | ;; This was a docstring constant in 5.30. It still works but is now | |
627 | ;; considered internal - change `c-identifier-ops' instead. | |
628 | t (let ((ops (c-filter-ops (c-lang-const c-identifier-ops) | |
629 | '(left-assoc right-assoc) | |
630 | t))) | |
631 | (when ops | |
632 | (c-make-keywords-re 'appendable ops)))) | |
d9e94c22 MS |
633 | (c-lang-defvar c-opt-identifier-concat-key |
634 | (c-lang-const c-opt-identifier-concat-key) | |
635 | 'dont-doc) | |
636 | ||
0386b551 AM |
637 | (c-lang-defconst c-opt-identifier-concat-key-depth |
638 | ;; Number of regexp grouping parens in `c-opt-identifier-concat-key'. | |
639 | t (regexp-opt-depth (c-lang-const c-opt-identifier-concat-key))) | |
640 | ||
641 | (c-lang-defconst c-opt-identifier-prefix-key | |
642 | ;; Appendable adorned regexp matching operators that might precede | |
643 | ;; an identifier and that are part of the identifier in that case. | |
644 | ;; nil in languages without such things. | |
645 | t (let ((ops (c-filter-ops (c-lang-const c-identifier-ops) | |
646 | '(prefix) | |
647 | t))) | |
648 | (when ops | |
649 | (c-make-keywords-re 'appendable ops)))) | |
650 | ||
651 | (c-lang-defconst c-after-id-concat-ops | |
652 | "Operators that can occur after a binary operator on `c-identifier-ops' | |
653 | in identifiers. nil in languages that don't have such things. | |
654 | ||
655 | Operators here should also have appropriate entries in `c-operators' - | |
656 | it's not taken care of by default." | |
657 | t nil | |
658 | ;; '~' for destructors in C++, '*' for member pointers. | |
659 | c++ '("~" "*") | |
660 | ;; In Java we recognize '*' to deal with "foo.bar.*" that can occur | |
661 | ;; in import declarations. (This will also match bogus things like | |
662 | ;; "foo.*bar" but we don't bother.) | |
663 | java '("*")) | |
664 | ||
d9e94c22 | 665 | (c-lang-defconst c-opt-after-id-concat-key |
0386b551 AM |
666 | ;; Regexp that must match the token after |
667 | ;; `c-opt-identifier-concat-key' for it to be considered an | |
668 | ;; identifier concatenation operator (which e.g. causes the | |
669 | ;; preceding identifier to be fontified as a reference). Assumed to | |
670 | ;; be a string if `c-opt-identifier-concat-key' is. | |
671 | ;; | |
672 | ;; This was a docstring constant in 5.30. It still works but is now | |
673 | ;; considered internal - change `c-after-id-concat-ops' instead. | |
674 | t (concat (c-lang-const c-symbol-start) | |
675 | (if (c-lang-const c-after-id-concat-ops) | |
676 | (concat "\\|" (c-make-keywords-re 'appendable | |
677 | (c-lang-const c-after-id-concat-ops))) | |
678 | ""))) | |
d9e94c22 MS |
679 | |
680 | (c-lang-defconst c-identifier-start | |
0386b551 AM |
681 | "Regexp that matches the start of an (optionally qualified) identifier. |
682 | It should also match all keywords. It's unspecified how far it | |
683 | matches." | |
684 | t (concat (c-lang-const c-symbol-start) | |
685 | (if (c-lang-const c-opt-identifier-prefix-key) | |
686 | (concat "\\|" | |
687 | (c-lang-const c-opt-identifier-prefix-key)) | |
688 | ""))) | |
d9e94c22 MS |
689 | (c-lang-defvar c-identifier-start (c-lang-const c-identifier-start)) |
690 | ||
691 | (c-lang-defconst c-identifier-key | |
692 | "Regexp matching a fully qualified identifier, like \"A::B::c\" in | |
693 | C++. It does not recognize the full range of syntactic whitespace | |
0386b551 AM |
694 | between the tokens; `c-forward-name' has to be used for that. It |
695 | should also not match identifiers containing parenthesis groupings, | |
696 | e.g. identifiers with template arguments such as \"A<X,Y>\" in C++." | |
697 | ;; This regexp is more complex than strictly necessary to ensure | |
698 | ;; that it can be matched with a minimum of backtracking. | |
699 | t (concat (if (c-lang-const c-opt-identifier-prefix-key) | |
700 | (concat | |
701 | "\\(" | |
702 | (c-lang-const c-opt-identifier-prefix-key) | |
703 | (c-lang-const c-simple-ws) "*" | |
d9e94c22 | 704 | "\\)?") |
0386b551 AM |
705 | "") |
706 | "\\(" (c-lang-const c-symbol-key) "\\)" | |
707 | (if (c-lang-const c-opt-identifier-concat-key) | |
708 | (concat | |
709 | "\\(" | |
710 | (c-lang-const c-simple-ws) "*" | |
711 | (c-lang-const c-opt-identifier-concat-key) | |
712 | (c-lang-const c-simple-ws) "*" | |
713 | (if (c-lang-const c-after-id-concat-ops) | |
714 | (concat | |
715 | "\\(" | |
716 | (c-make-keywords-re 'appendable | |
717 | (c-lang-const c-after-id-concat-ops)) | |
718 | (concat | |
719 | ;; For flexibility, consider the symbol match | |
720 | ;; optional if we've hit a | |
721 | ;; `c-after-id-concat-ops' operator. This is | |
722 | ;; also necessary to handle the "*" that can | |
723 | ;; end import declaration identifiers in Java. | |
724 | "\\(" | |
725 | (c-lang-const c-simple-ws) "*" | |
726 | "\\(" (c-lang-const c-symbol-key) "\\)" | |
727 | "\\)?") | |
728 | "\\|" | |
d9e94c22 | 729 | "\\(" (c-lang-const c-symbol-key) "\\)" |
0386b551 AM |
730 | "\\)") |
731 | (concat "\\(" (c-lang-const c-symbol-key) "\\)")) | |
732 | "\\)*") | |
733 | ""))) | |
d9e94c22 MS |
734 | (c-lang-defvar c-identifier-key (c-lang-const c-identifier-key)) |
735 | ||
736 | (c-lang-defconst c-identifier-last-sym-match | |
0386b551 AM |
737 | ;; This was a docstring constant in 5.30 but it's no longer used. |
738 | ;; It's only kept to avoid breaking third party code. | |
739 | ;; | |
740 | ;; Used to identify the submatch in `c-identifier-key' that | |
741 | ;; surrounds the last symbol in the qualified identifier. It's a | |
742 | ;; list of submatch numbers, of which the first that has a match is | |
743 | ;; taken. It's assumed that at least one does when the regexp has | |
744 | ;; matched. | |
745 | t nil) | |
746 | ||
747 | (c-lang-defconst c-string-escaped-newlines | |
748 | "Set if the language support backslash escaped newlines inside string | |
749 | literals." | |
750 | t nil | |
751 | (c c++ objc pike) t) | |
752 | (c-lang-defvar c-string-escaped-newlines | |
753 | (c-lang-const c-string-escaped-newlines)) | |
754 | ||
755 | (c-lang-defconst c-multiline-string-start-char | |
756 | "Set if the language supports multiline string literals without escaped | |
757 | newlines. If t, all string literals are multiline. If a character, | |
758 | only literals where the open quote is immediately preceded by that | |
759 | literal are multiline." | |
760 | t nil | |
761 | pike ?#) | |
762 | (c-lang-defvar c-multiline-string-start-char | |
763 | (c-lang-const c-multiline-string-start-char)) | |
d9e94c22 | 764 | |
536610a4 AM |
765 | (c-lang-defconst c-opt-cpp-symbol |
766 | "The symbol which starts preprocessor constructs when in the margin." | |
767 | t "#" | |
768 | (java awk) nil) | |
769 | (c-lang-defvar c-opt-cpp-symbol (c-lang-const c-opt-cpp-symbol)) | |
770 | ||
d9e94c22 MS |
771 | (c-lang-defconst c-opt-cpp-prefix |
772 | "Regexp matching the prefix of a cpp directive in the languages that | |
773 | normally use that macro preprocessor. Tested at bol or at boi. | |
774 | Assumed to not contain any submatches or \\| operators." | |
e1dbe924 | 775 | ;; TODO (ACM, 2005-04-01). Amend the following to recognize escaped NLs; |
0386b551 | 776 | ;; amend all uses of c-opt-cpp-prefix which count regexp-depth. |
d9e94c22 MS |
777 | t "\\s *#\\s *" |
778 | (java awk) nil) | |
779 | (c-lang-defvar c-opt-cpp-prefix (c-lang-const c-opt-cpp-prefix)) | |
780 | ||
5ee2e988 AM |
781 | (c-lang-defconst c-anchored-cpp-prefix |
782 | "Regexp matching the prefix of a cpp directive anchored to BOL, | |
783 | in the languages that have a macro preprocessor." | |
784 | t (if (c-lang-const c-opt-cpp-prefix) | |
785 | (concat "^" (c-lang-const c-opt-cpp-prefix)))) | |
786 | (c-lang-defvar c-anchored-cpp-prefix (c-lang-const c-anchored-cpp-prefix)) | |
787 | ||
d9e94c22 MS |
788 | (c-lang-defconst c-opt-cpp-start |
789 | "Regexp matching the prefix of a cpp directive including the directive | |
790 | name, or nil in languages without preprocessor support. The first | |
791 | submatch surrounds the directive name." | |
792 | t (if (c-lang-const c-opt-cpp-prefix) | |
793 | (concat (c-lang-const c-opt-cpp-prefix) | |
794 | "\\([" c-alnum "]+\\)")) | |
795 | ;; Pike, being a scripting language, recognizes hash-bangs too. | |
796 | pike (concat (c-lang-const c-opt-cpp-prefix) | |
797 | "\\([" c-alnum "]+\\|!\\)")) | |
798 | (c-lang-defvar c-opt-cpp-start (c-lang-const c-opt-cpp-start)) | |
799 | ||
0386b551 AM |
800 | (c-lang-defconst c-cpp-message-directives |
801 | "List of cpp directives (without the prefix) that are followed by a | |
802 | string message." | |
803 | t (if (c-lang-const c-opt-cpp-prefix) | |
804 | '("error")) | |
5ee2e988 | 805 | (c c++ objc pike) '("error" "warning")) |
0386b551 AM |
806 | |
807 | (c-lang-defconst c-cpp-include-directives | |
808 | "List of cpp directives (without the prefix) that are followed by a | |
809 | file name in angle brackets or quotes." | |
810 | t (if (c-lang-const c-opt-cpp-prefix) | |
811 | '("include")) | |
812 | objc '("include" "import")) | |
813 | ||
814 | (c-lang-defconst c-opt-cpp-macro-define | |
815 | "Cpp directive (without the prefix) that is followed by a macro | |
816 | definition, or nil if the language doesn't have any." | |
817 | t (if (c-lang-const c-opt-cpp-prefix) | |
818 | "define")) | |
536610a4 AM |
819 | (c-lang-defvar c-opt-cpp-macro-define |
820 | (c-lang-const c-opt-cpp-macro-define)) | |
0386b551 AM |
821 | |
822 | (c-lang-defconst c-opt-cpp-macro-define-start | |
772a3544 AM |
823 | ;; Regexp matching everything up to the macro body of a cpp define, or the |
824 | ;; end of the logical line if there is none. Submatch 1 is the name of the | |
825 | ;; macro. Set if c-opt-cpp-macro-define is. | |
0386b551 AM |
826 | t (if (c-lang-const c-opt-cpp-macro-define) |
827 | (concat (c-lang-const c-opt-cpp-prefix) | |
828 | (c-lang-const c-opt-cpp-macro-define) | |
772a3544 AM |
829 | "[ \t]+\\(\\(\\sw\\|_\\)+\\)\\(\([^\)]*\)\\)?" |
830 | ;; ^ ^ #defined name | |
0386b551 AM |
831 | "\\([ \t]\\|\\\\\n\\)*"))) |
832 | (c-lang-defvar c-opt-cpp-macro-define-start | |
833 | (c-lang-const c-opt-cpp-macro-define-start)) | |
834 | ||
51c9af45 AM |
835 | (c-lang-defconst c-opt-cpp-macro-define-id |
836 | ;; Regexp matching everything up to the end of the identifier defined | |
837 | ;; by a cpp define. | |
838 | t (if (c-lang-const c-opt-cpp-macro-define) | |
839 | (concat (c-lang-const c-opt-cpp-prefix) ; # | |
840 | (c-lang-const c-opt-cpp-macro-define) ; define | |
841 | "[ \t]+\\(\\sw\\|_\\)+"))) | |
842 | (c-lang-defvar c-opt-cpp-macro-define-id | |
843 | (c-lang-const c-opt-cpp-macro-define-id)) | |
844 | ||
0386b551 | 845 | (c-lang-defconst c-cpp-expr-directives |
5ee2e988 | 846 | "List of cpp directives (without the prefix) that are followed by an |
0386b551 AM |
847 | expression." |
848 | t (if (c-lang-const c-opt-cpp-prefix) | |
849 | '("if" "elif"))) | |
850 | ||
b128268e AM |
851 | (c-lang-defconst c-cpp-expr-intro-re |
852 | "Regexp which matches the start of a CPP directive which contains an | |
853 | expression, or nil if there aren't any in the language." | |
854 | t (if (c-lang-const c-cpp-expr-directives) | |
855 | (concat | |
856 | (c-lang-const c-opt-cpp-prefix) | |
857 | (c-make-keywords-re t (c-lang-const c-cpp-expr-directives))))) | |
858 | (c-lang-defvar c-cpp-expr-intro-re | |
859 | (c-lang-const c-cpp-expr-intro-re)) | |
860 | ||
0386b551 AM |
861 | (c-lang-defconst c-cpp-expr-functions |
862 | "List of functions in cpp expressions." | |
d9e94c22 MS |
863 | t (if (c-lang-const c-opt-cpp-prefix) |
864 | '("defined")) | |
865 | pike '("defined" "efun" "constant")) | |
866 | ||
846f5040 MS |
867 | (c-lang-defconst c-assignment-operators |
868 | "List of all assignment operators." | |
869 | t '("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=") | |
870 | java (append (c-lang-const c-assignment-operators) | |
871 | '(">>>=")) | |
872 | c++ (append (c-lang-const c-assignment-operators) | |
0386b551 | 873 | '("and_eq" "or_eq" "xor_eq" "??!=" "??'=")) |
846f5040 MS |
874 | idl nil) |
875 | ||
d9e94c22 MS |
876 | (c-lang-defconst c-operators |
877 | "List describing all operators, along with their precedence and | |
878 | associativity. The order in the list corresponds to the precedence of | |
e6a9e584 | 879 | the operators: The operators in each element are a group with the same |
d9e94c22 | 880 | precedence, and the group has higher precedence than the groups in all |
e6a9e584 AM |
881 | following elements. The car of each element describes the type of the |
882 | operator group, and the cdr is a list of the operator tokens in it. | |
883 | The operator group types are: | |
d9e94c22 MS |
884 | |
885 | 'prefix Unary prefix operators. | |
886 | 'postfix Unary postfix operators. | |
0386b551 AM |
887 | 'postfix-if-paren |
888 | Unary postfix operators if and only if the chars have | |
889 | parenthesis syntax. | |
d9e94c22 MS |
890 | 'left-assoc Binary left associative operators (i.e. a+b+c means (a+b)+c). |
891 | 'right-assoc Binary right associative operators (i.e. a=b=c means a=(b=c)). | |
892 | 'right-assoc-sequence | |
893 | Right associative operator that constitutes of a | |
894 | sequence of tokens that separate expressions. All the | |
895 | tokens in the group are in this case taken as | |
896 | describing the sequence in one such operator, and the | |
897 | order between them is therefore significant. | |
898 | ||
899 | Operators containing a character with paren syntax are taken to match | |
900 | with a corresponding open/close paren somewhere else. A postfix | |
901 | operator with close paren syntax is taken to end a postfix expression | |
902 | started somewhere earlier, rather than start a new one at point. Vice | |
903 | versa for prefix operators with open paren syntax. | |
904 | ||
905 | Note that operators like \".\" and \"->\" which in language references | |
906 | often are described as postfix operators are considered binary here, | |
907 | since CC Mode treats every identifier as an expression." | |
908 | ||
909 | ;; There's currently no code in CC Mode that exploit all the info | |
910 | ;; in this variable; precedence, associativity etc are present as a | |
911 | ;; preparation for future work. | |
912 | ||
913 | t `(;; Preprocessor. | |
914 | ,@(when (c-lang-const c-opt-cpp-prefix) | |
915 | `((prefix "#" | |
916 | ,@(when (c-major-mode-is '(c-mode c++-mode)) | |
917 | '("%:" "??="))) | |
918 | (left-assoc "##" | |
919 | ,@(when (c-major-mode-is '(c-mode c++-mode)) | |
920 | '("%:%:" "??=??="))))) | |
921 | ||
0386b551 AM |
922 | ;; Primary. |
923 | ,@(c-lang-const c-identifier-ops) | |
452ea855 | 924 | ,@(cond ((or (c-major-mode-is 'c++-mode) (c-major-mode-is 'java-mode)) |
0386b551 | 925 | `((postfix-if-paren "<" ">"))) ; Templates. |
d9e94c22 | 926 | ((c-major-mode-is 'pike-mode) |
0386b551 | 927 | `((prefix "global" "predef"))) |
d9e94c22 | 928 | ((c-major-mode-is 'java-mode) |
0386b551 | 929 | `((prefix "super")))) |
d9e94c22 MS |
930 | |
931 | ;; Postfix. | |
932 | ,@(when (c-major-mode-is 'c++-mode) | |
933 | ;; The following need special treatment. | |
934 | `((prefix "dynamic_cast" "static_cast" | |
935 | "reinterpret_cast" "const_cast" "typeid"))) | |
936 | (left-assoc "." | |
937 | ,@(unless (c-major-mode-is 'java-mode) | |
938 | '("->"))) | |
939 | (postfix "++" "--" "[" "]" "(" ")" | |
940 | ,@(when (c-major-mode-is '(c-mode c++-mode)) | |
941 | '("<:" ":>" "??(" "??)"))) | |
942 | ||
943 | ;; Unary. | |
944 | (prefix "++" "--" "+" "-" "!" "~" | |
945 | ,@(when (c-major-mode-is 'c++-mode) '("not" "compl")) | |
946 | ,@(when (c-major-mode-is '(c-mode c++-mode)) | |
947 | '("*" "&" "sizeof" "??-")) | |
948 | ,@(when (c-major-mode-is 'objc-mode) | |
949 | '("@selector" "@protocol" "@encode")) | |
950 | ;; The following need special treatment. | |
951 | ,@(cond ((c-major-mode-is 'c++-mode) | |
952 | '("new" "delete")) | |
953 | ((c-major-mode-is 'java-mode) | |
954 | '("new")) | |
955 | ((c-major-mode-is 'pike-mode) | |
956 | '("class" "lambda" "catch" "throw" "gauge"))) | |
957 | "(" ")" ; Cast. | |
958 | ,@(when (c-major-mode-is 'pike-mode) | |
959 | '("[" "]"))) ; Type cast. | |
960 | ||
961 | ;; Member selection. | |
962 | ,@(when (c-major-mode-is 'c++-mode) | |
963 | `((left-assoc ".*" "->*"))) | |
964 | ||
965 | ;; Multiplicative. | |
966 | (left-assoc "*" "/" "%") | |
967 | ||
968 | ;; Additive. | |
969 | (left-assoc "+" "-") | |
970 | ||
971 | ;; Shift. | |
972 | (left-assoc "<<" ">>" | |
973 | ,@(when (c-major-mode-is 'java-mode) | |
974 | '(">>>"))) | |
975 | ||
976 | ;; Relational. | |
977 | (left-assoc "<" ">" "<=" ">=" | |
978 | ,@(when (c-major-mode-is 'java-mode) | |
979 | '("instanceof"))) | |
980 | ||
981 | ;; Equality. | |
982 | (left-assoc "==" "!=" | |
983 | ,@(when (c-major-mode-is 'c++-mode) '("not_eq"))) | |
984 | ||
985 | ;; Bitwise and. | |
986 | (left-assoc "&" | |
987 | ,@(when (c-major-mode-is 'c++-mode) '("bitand"))) | |
988 | ||
989 | ;; Bitwise exclusive or. | |
990 | (left-assoc "^" | |
991 | ,@(when (c-major-mode-is '(c-mode c++-mode)) | |
992 | '("??'")) | |
993 | ,@(when (c-major-mode-is 'c++-mode) '("xor"))) | |
994 | ||
995 | ;; Bitwise or. | |
996 | (left-assoc "|" | |
997 | ,@(when (c-major-mode-is '(c-mode c++-mode)) | |
998 | '("??!")) | |
999 | ,@(when (c-major-mode-is 'c++-mode) '("bitor"))) | |
1000 | ||
1001 | ;; Logical and. | |
1002 | (left-assoc "&&" | |
1003 | ,@(when (c-major-mode-is 'c++-mode) '("and"))) | |
1004 | ||
1005 | ;; Logical or. | |
1006 | (left-assoc "||" | |
1007 | ,@(when (c-major-mode-is '(c-mode c++-mode)) | |
1008 | '("??!??!")) | |
1009 | ,@(when (c-major-mode-is 'c++-mode) '("or"))) | |
1010 | ||
1011 | ;; Conditional. | |
1012 | (right-assoc-sequence "?" ":") | |
1013 | ||
1014 | ;; Assignment. | |
846f5040 | 1015 | (right-assoc ,@(c-lang-const c-assignment-operators)) |
d9e94c22 MS |
1016 | |
1017 | ;; Exception. | |
1018 | ,@(when (c-major-mode-is 'c++-mode) | |
1019 | '((prefix "throw"))) | |
1020 | ||
1021 | ;; Sequence. | |
1022 | (left-assoc ",")) | |
1023 | ||
1024 | ;; IDL got its own definition since it has a much smaller operator | |
1025 | ;; set than the other languages. | |
1026 | idl `(;; Preprocessor. | |
1027 | (prefix "#") | |
1028 | (left-assoc "##") | |
0386b551 AM |
1029 | ;; Primary. |
1030 | ,@(c-lang-const c-identifier-ops) | |
d9e94c22 MS |
1031 | ;; Unary. |
1032 | (prefix "+" "-" "~") | |
1033 | ;; Multiplicative. | |
1034 | (left-assoc "*" "/" "%") | |
1035 | ;; Additive. | |
1036 | (left-assoc "+" "-") | |
1037 | ;; Shift. | |
1038 | (left-assoc "<<" ">>") | |
1039 | ;; And. | |
1040 | (left-assoc "&") | |
1041 | ;; Xor. | |
1042 | (left-assoc "^") | |
1043 | ;; Or. | |
1044 | (left-assoc "|"))) | |
1045 | ||
1046 | (c-lang-defconst c-operator-list | |
1047 | ;; The operators as a flat list (without duplicates). | |
0386b551 | 1048 | t (c-filter-ops (c-lang-const c-operators) t t)) |
d9e94c22 MS |
1049 | |
1050 | (c-lang-defconst c-overloadable-operators | |
0386b551 | 1051 | "List of the operators that are overloadable, in their \"identifier |
51c9af45 | 1052 | form\". See also `c-op-identifier-prefix'." |
d9e94c22 | 1053 | t nil |
d9e94c22 MS |
1054 | c++ '("new" "delete" ;; Can be followed by "[]" but we ignore that. |
1055 | "+" "-" "*" "/" "%" | |
1056 | "^" "??'" "xor" "&" "bitand" "|" "??!" "bitor" "~" "??-" "compl" | |
1057 | "!" "=" "<" ">" "+=" "-=" "*=" "/=" "%=" "^=" | |
1058 | "??'=" "xor_eq" "&=" "and_eq" "|=" "??!=" "or_eq" | |
1059 | "<<" ">>" ">>=" "<<=" "==" "!=" "not_eq" "<=" ">=" | |
1060 | "&&" "and" "||" "??!??!" "or" "++" "--" "," "->*" "->" | |
1061 | "()" "[]" "<::>" "??(??)") | |
1062 | ;; These work like identifiers in Pike. | |
1063 | pike '("`+" "`-" "`&" "`|" "`^" "`<<" "`>>" "`*" "`/" "`%" "`~" | |
1064 | "`==" "`<" "`>" "`!" "`[]" "`[]=" "`->" "`->=" "`()" "``+" | |
1065 | "``-" "``&" "``|" "``^" "``<<" "``>>" "``*" "``/" "``%" | |
1066 | "`+=")) | |
1067 | ||
1068 | (c-lang-defconst c-overloadable-operators-regexp | |
1069 | ;; Regexp tested after an "operator" token in C++. | |
1070 | t nil | |
1071 | c++ (c-make-keywords-re nil (c-lang-const c-overloadable-operators))) | |
1072 | (c-lang-defvar c-overloadable-operators-regexp | |
1073 | (c-lang-const c-overloadable-operators-regexp)) | |
1074 | ||
51c9af45 | 1075 | (c-lang-defconst c-opt-op-identifier-prefix |
0386b551 AM |
1076 | "Regexp matching the token before the ones in |
1077 | `c-overloadable-operators' when operators are specified in their | |
1078 | \"identifier form\". This typically matches \"operator\" in C++ where | |
1079 | operator functions are specified as e.g. \"operator +\". It's nil in | |
1080 | languages without operator functions or where the complete operator | |
1081 | identifier is listed in `c-overloadable-operators'. | |
1082 | ||
1083 | This regexp is assumed to not match any non-operator identifier." | |
1084 | t nil | |
1085 | c++ (c-make-keywords-re t '("operator"))) | |
51c9af45 AM |
1086 | (c-lang-defvar c-opt-op-identifier-prefix |
1087 | (c-lang-const c-opt-op-identifier-prefix)) | |
1088 | ||
1089 | ;; Note: the following alias is an old name which was a mis-spelling. It has | |
1090 | ;; been corrected above and throughout cc-engine.el. It will be removed at | |
1091 | ;; some release very shortly in the future. ACM, 2006-04-14. | |
c97833f0 | 1092 | (defvaralias 'c-opt-op-identitier-prefix 'c-opt-op-identifier-prefix) |
51c9af45 AM |
1093 | (make-obsolete-variable 'c-opt-op-identitier-prefix 'c-opt-op-identifier-prefix |
1094 | "CC Mode 5.31.4, 2006-04-14") | |
0386b551 | 1095 | |
d9e94c22 MS |
1096 | (c-lang-defconst c-other-op-syntax-tokens |
1097 | "List of the tokens made up of characters in the punctuation or | |
1098 | parenthesis syntax classes that have uses other than as expression | |
1099 | operators." | |
1100 | t '("{" "}" "(" ")" "[" "]" ";" ":" "," "=" "/*" "*/" "//") | |
1101 | (c c++ pike) (append '("#" "##" ; Used by cpp. | |
1102 | "::" "...") | |
1103 | (c-lang-const c-other-op-syntax-tokens)) | |
0386b551 AM |
1104 | (c c++) (append '("*") (c-lang-const c-other-op-syntax-tokens)) |
1105 | c++ (append '("&" "<%" "%>" "<:" ":>" "%:" "%:%:") | |
1106 | (c-lang-const c-other-op-syntax-tokens)) | |
d9e94c22 MS |
1107 | objc (append '("#" "##" ; Used by cpp. |
1108 | "+" "-") (c-lang-const c-other-op-syntax-tokens)) | |
1109 | idl (append '("#" "##") ; Used by cpp. | |
1110 | (c-lang-const c-other-op-syntax-tokens)) | |
1111 | pike (append '("..") | |
1112 | (c-lang-const c-other-op-syntax-tokens) | |
1113 | (c-lang-const c-overloadable-operators)) | |
1114 | awk '("{" "}" "(" ")" "[" "]" ";" "," "=" "/")) | |
1115 | ||
0386b551 AM |
1116 | (c-lang-defconst c-all-op-syntax-tokens |
1117 | ;; List of all tokens in the punctuation and parenthesis syntax | |
1118 | ;; classes. | |
1119 | t (delete-duplicates (append (c-lang-const c-other-op-syntax-tokens) | |
1120 | (c-lang-const c-operator-list)) | |
1121 | :test 'string-equal)) | |
1122 | ||
1123 | (c-lang-defconst c-nonsymbol-token-char-list | |
1124 | ;; List containing all chars not in the word, symbol or | |
1125 | ;; syntactically irrelevant syntax classes, i.e. all punctuation, | |
1126 | ;; parenthesis and string delimiter chars. | |
1127 | t (c-with-syntax-table (c-lang-const c-mode-syntax-table) | |
1128 | ;; Only go through the chars in the printable ASCII range. No | |
1129 | ;; language so far has 8-bit or widestring operators. | |
1130 | (let (list (char 32)) | |
1131 | (while (< char 127) | |
1132 | (or (memq (char-syntax char) '(?w ?_ ?< ?> ?\ )) | |
1133 | (setq list (cons (c-int-to-char char) list))) | |
1134 | (setq char (1+ char))) | |
1135 | list))) | |
1136 | ||
d9e94c22 MS |
1137 | (c-lang-defconst c-nonsymbol-token-regexp |
1138 | ;; Regexp matching all tokens in the punctuation and parenthesis | |
1139 | ;; syntax classes. Note that this also matches ".", which can start | |
1140 | ;; a float. | |
1141 | t (c-make-keywords-re nil | |
0386b551 AM |
1142 | (c-filter-ops (c-lang-const c-all-op-syntax-tokens) |
1143 | t | |
1144 | "\\`\\(\\s.\\|\\s\(\\|\\s\)\\)+\\'"))) | |
d9e94c22 MS |
1145 | (c-lang-defvar c-nonsymbol-token-regexp |
1146 | (c-lang-const c-nonsymbol-token-regexp)) | |
1147 | ||
846f5040 MS |
1148 | (c-lang-defconst c-assignment-op-regexp |
1149 | ;; Regexp matching all assignment operators and only them. The | |
1150 | ;; beginning of the first submatch is used to detect the end of the | |
1151 | ;; token, along with the end of the whole match. | |
1152 | t (if (c-lang-const c-assignment-operators) | |
1153 | (concat | |
1154 | ;; Need special case for "=" since it's a prefix of "==". | |
1155 | "=\\([^=]\\|$\\)" | |
1156 | "\\|" | |
1157 | (c-make-keywords-re nil | |
1158 | (set-difference (c-lang-const c-assignment-operators) | |
1159 | '("=") | |
1160 | :test 'string-equal))) | |
1161 | "\\<\\>")) | |
1162 | (c-lang-defvar c-assignment-op-regexp | |
1163 | (c-lang-const c-assignment-op-regexp)) | |
1164 | ||
0386b551 AM |
1165 | (c-lang-defconst c-<>-multichar-token-regexp |
1166 | ;; Regexp matching all tokens containing "<" or ">" which are longer | |
1167 | ;; than one char. | |
1168 | t (c-make-keywords-re nil | |
1169 | (c-filter-ops (c-lang-const c-all-op-syntax-tokens) | |
1170 | t | |
1171 | ".[<>]\\|[<>]."))) | |
1172 | (c-lang-defvar c-<>-multichar-token-regexp | |
1173 | (c-lang-const c-<>-multichar-token-regexp)) | |
1174 | ||
d9e94c22 MS |
1175 | (c-lang-defconst c-<-op-cont-regexp |
1176 | ;; Regexp matching the second and subsequent characters of all | |
1177 | ;; multicharacter tokens that begin with "<". | |
1178 | t (c-make-keywords-re nil | |
0386b551 AM |
1179 | (c-filter-ops (c-lang-const c-all-op-syntax-tokens) |
1180 | t | |
1181 | "\\`<." | |
1182 | (lambda (op) (substring op 1))))) | |
452ea855 | 1183 | |
d9e94c22 MS |
1184 | (c-lang-defvar c-<-op-cont-regexp (c-lang-const c-<-op-cont-regexp)) |
1185 | ||
1186 | (c-lang-defconst c->-op-cont-regexp | |
1187 | ;; Regexp matching the second and subsequent characters of all | |
1188 | ;; multicharacter tokens that begin with ">". | |
1189 | t (c-make-keywords-re nil | |
0386b551 AM |
1190 | (c-filter-ops (c-lang-const c-all-op-syntax-tokens) |
1191 | t | |
1192 | "\\`>." | |
452ea855 AM |
1193 | (lambda (op) (substring op 1)))) |
1194 | java (c-make-keywords-re nil | |
1195 | (c-filter-ops (c-lang-const c-all-op-syntax-tokens) | |
1196 | t | |
1197 | "\\`>[^>]\\|\\`>>[^>]" | |
1198 | (lambda (op) (substring op 1))))) | |
1199 | ||
d9e94c22 MS |
1200 | (c-lang-defvar c->-op-cont-regexp (c-lang-const c->-op-cont-regexp)) |
1201 | ||
1202 | (c-lang-defconst c-stmt-delim-chars | |
1203 | ;; The characters that should be considered to bound statements. To | |
1204 | ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to | |
1205 | ;; begin with "^" to negate the set. If ? : operators should be | |
1206 | ;; detected then the string must end with "?:". | |
536610a4 | 1207 | t "^;{}?:") |
d9e94c22 MS |
1208 | (c-lang-defvar c-stmt-delim-chars (c-lang-const c-stmt-delim-chars)) |
1209 | ||
1210 | (c-lang-defconst c-stmt-delim-chars-with-comma | |
1211 | ;; Variant of `c-stmt-delim-chars' that additionally contains ','. | |
536610a4 | 1212 | t "^;,{}?:") |
d9e94c22 MS |
1213 | (c-lang-defvar c-stmt-delim-chars-with-comma |
1214 | (c-lang-const c-stmt-delim-chars-with-comma)) | |
1215 | ||
1216 | \f | |
1217 | ;;; Syntactic whitespace. | |
1218 | ||
0386b551 AM |
1219 | (c-lang-defconst c-simple-ws |
1220 | "Regexp matching an ordinary whitespace character. | |
1221 | Does not contain a \\| operator at the top level." | |
1222 | ;; "\\s " is not enough since it doesn't match line breaks. | |
1223 | t "\\(\\s \\|[\n\r]\\)") | |
1224 | ||
1225 | (c-lang-defconst c-simple-ws-depth | |
1226 | ;; Number of regexp grouping parens in `c-simple-ws'. | |
1227 | t (regexp-opt-depth (c-lang-const c-simple-ws))) | |
1228 | ||
1229 | (c-lang-defconst c-line-comment-starter | |
1230 | "String that starts line comments, or nil if such don't exist. | |
1231 | Line comments are always terminated by newlines. At least one of | |
1232 | `c-block-comment-starter' and this one is assumed to be set. | |
1233 | ||
1234 | Note that it's currently not enough to set this to support a new | |
1235 | comment style. Other stuff like the syntax table must also be set up | |
1236 | properly." | |
1237 | t "//" | |
1238 | awk "#") | |
1239 | (c-lang-defvar c-line-comment-starter (c-lang-const c-line-comment-starter)) | |
1240 | ||
1241 | (c-lang-defconst c-block-comment-starter | |
1242 | "String that starts block comments, or nil if such don't exist. | |
1243 | Block comments are ended by `c-block-comment-ender', which is assumed | |
1244 | to be set if this is. At least one of `c-line-comment-starter' and | |
1245 | this one is assumed to be set. | |
1246 | ||
1247 | Note that it's currently not enough to set this to support a new | |
1248 | comment style. Other stuff like the syntax table must also be set up | |
1249 | properly." | |
1250 | t "/*" | |
1251 | awk nil) | |
1252 | ||
1253 | (c-lang-defconst c-block-comment-ender | |
1254 | "String that ends block comments, or nil if such don't exist. | |
1255 | ||
1256 | Note that it's currently not enough to set this to support a new | |
1257 | comment style. Other stuff like the syntax table must also be set up | |
1258 | properly." | |
1259 | t "*/" | |
1260 | awk nil) | |
1261 | ||
d9e94c22 MS |
1262 | (c-lang-defconst c-comment-start-regexp |
1263 | ;; Regexp to match the start of any type of comment. | |
0386b551 AM |
1264 | t (let ((re (c-make-keywords-re nil |
1265 | (list (c-lang-const c-line-comment-starter) | |
1266 | (c-lang-const c-block-comment-starter))))) | |
1267 | (if (memq 'gen-comment-delim c-emacs-features) | |
1268 | (concat re "\\|\\s!") | |
1269 | re))) | |
d9e94c22 MS |
1270 | (c-lang-defvar c-comment-start-regexp (c-lang-const c-comment-start-regexp)) |
1271 | ||
0386b551 AM |
1272 | (c-lang-defconst c-block-comment-start-regexp |
1273 | ;; Regexp which matches the start of a block comment (if such exists in the | |
1274 | ;; language) | |
1275 | t (if (c-lang-const c-block-comment-starter) | |
1276 | (regexp-quote (c-lang-const c-block-comment-starter)) | |
1277 | "\\<\\>")) | |
1278 | (c-lang-defvar c-block-comment-start-regexp | |
1279 | (c-lang-const c-block-comment-start-regexp)) | |
1280 | ||
536610a4 AM |
1281 | (c-lang-defconst c-line-comment-start-regexp |
1282 | ;; Regexp which matches the start of a line comment (if such exists in the | |
1283 | ;; language; it does in all 7 CC Mode languages). | |
1284 | t (if (c-lang-const c-line-comment-starter) | |
1285 | (regexp-quote (c-lang-const c-line-comment-starter)) | |
1286 | "\\<\\>")) | |
1287 | (c-lang-defvar c-line-comment-start-regexp | |
1288 | (c-lang-const c-line-comment-start-regexp)) | |
1289 | ||
d9e94c22 MS |
1290 | (c-lang-defconst c-literal-start-regexp |
1291 | ;; Regexp to match the start of comments and string literals. | |
1292 | t (concat (c-lang-const c-comment-start-regexp) | |
1293 | "\\|" | |
1294 | (if (memq 'gen-string-delim c-emacs-features) | |
1295 | "\"|" | |
1296 | "\""))) | |
1297 | (c-lang-defvar c-literal-start-regexp (c-lang-const c-literal-start-regexp)) | |
1298 | ||
1299 | (c-lang-defconst c-doc-comment-start-regexp | |
1300 | "Regexp to match the start of documentation comments." | |
1301 | t "\\<\\>" | |
1302 | ;; From font-lock.el: `doxygen' uses /*! while others use /**. | |
1303 | (c c++ objc) "/\\*[*!]" | |
1304 | java "/\\*\\*" | |
1305 | pike "/[/*]!") | |
1306 | (c-lang-defvar c-doc-comment-start-regexp | |
1307 | (c-lang-const c-doc-comment-start-regexp)) | |
1308 | ||
1309 | (c-lang-defconst comment-start | |
1310 | "String that starts comments inserted with M-; etc. | |
1311 | `comment-start' is initialized from this." | |
0386b551 AM |
1312 | ;; Default: Prefer line comments to block comments, and pad with a space. |
1313 | t (concat (or (c-lang-const c-line-comment-starter) | |
1314 | (c-lang-const c-block-comment-starter)) | |
1315 | " ") | |
1316 | ;; In C we still default to the block comment style since line | |
1317 | ;; comments aren't entirely portable. | |
1318 | c "/* ") | |
26b8f810 | 1319 | (c-lang-setvar comment-start (c-lang-const comment-start)) |
d9e94c22 MS |
1320 | |
1321 | (c-lang-defconst comment-end | |
1322 | "String that ends comments inserted with M-; etc. | |
1323 | `comment-end' is initialized from this." | |
0386b551 AM |
1324 | ;; Default: Use block comment style if comment-start uses block |
1325 | ;; comments, and pad with a space in that case. | |
1326 | t (if (string-match (concat "\\`\\(" | |
1327 | (c-lang-const c-block-comment-start-regexp) | |
1328 | "\\)") | |
1329 | (c-lang-const comment-start)) | |
1330 | (concat " " (c-lang-const c-block-comment-ender)) | |
1331 | "")) | |
26b8f810 | 1332 | (c-lang-setvar comment-end (c-lang-const comment-end)) |
d9e94c22 MS |
1333 | |
1334 | (c-lang-defconst comment-start-skip | |
1335 | "Regexp to match the start of a comment plus everything up to its body. | |
1336 | `comment-start-skip' is initialized from this." | |
0386b551 AM |
1337 | ;; Default: Allow the last char of the comment starter(s) to be |
1338 | ;; repeated, then allow any amount of horizontal whitespace. | |
1339 | t (concat "\\(" | |
1340 | (c-concat-separated | |
1341 | (mapcar (lambda (cs) | |
1342 | (when cs | |
1343 | (concat (regexp-quote cs) "+"))) | |
1344 | (list (c-lang-const c-line-comment-starter) | |
1345 | (c-lang-const c-block-comment-starter))) | |
1346 | "\\|") | |
1347 | "\\)\\s *")) | |
26b8f810 | 1348 | (c-lang-setvar comment-start-skip (c-lang-const comment-start-skip)) |
d9e94c22 | 1349 | |
f75ef66d | 1350 | (c-lang-defconst c-syntactic-ws-start |
0386b551 AM |
1351 | ;; Regexp matching any sequence that can start syntactic whitespace. |
1352 | ;; The only uncertain case is '#' when there are cpp directives. | |
1353 | t (concat "\\s \\|" | |
1354 | (c-make-keywords-re nil | |
1355 | (append (list (c-lang-const c-line-comment-starter) | |
1356 | (c-lang-const c-block-comment-starter) | |
1357 | (when (c-lang-const c-opt-cpp-prefix) | |
1358 | "#")) | |
1359 | '("\n" "\r"))) | |
1360 | "\\|\\\\[\n\r]" | |
1361 | (when (memq 'gen-comment-delim c-emacs-features) | |
1362 | "\\|\\s!"))) | |
1363 | (c-lang-defvar c-syntactic-ws-start (c-lang-const c-syntactic-ws-start)) | |
d9e94c22 | 1364 | |
f75ef66d | 1365 | (c-lang-defconst c-syntactic-ws-end |
0386b551 AM |
1366 | ;; Regexp matching any single character that might end syntactic whitespace. |
1367 | t (concat "\\s \\|" | |
1368 | (c-make-keywords-re nil | |
1369 | (append (when (c-lang-const c-block-comment-ender) | |
1370 | (list | |
1371 | (string | |
1372 | (elt (c-lang-const c-block-comment-ender) | |
1373 | (1- (length | |
1374 | (c-lang-const c-block-comment-ender))))))) | |
1375 | '("\n" "\r"))) | |
1376 | (when (memq 'gen-comment-delim c-emacs-features) | |
1377 | "\\|\\s!"))) | |
1378 | (c-lang-defvar c-syntactic-ws-end (c-lang-const c-syntactic-ws-end)) | |
1379 | ||
1380 | (c-lang-defconst c-unterminated-block-comment-regexp | |
1381 | ;; Regexp matching an unterminated block comment that doesn't | |
1382 | ;; contain line breaks, or nil in languages without block comments. | |
1383 | ;; Does not contain a \| operator at the top level. | |
1384 | t (when (c-lang-const c-block-comment-starter) | |
1385 | (concat | |
1386 | (regexp-quote (c-lang-const c-block-comment-starter)) | |
1387 | ;; It's messy to cook together a regexp that matches anything | |
1388 | ;; but c-block-comment-ender. | |
1389 | (let ((end (c-lang-const c-block-comment-ender))) | |
1390 | (cond ((= (length end) 1) | |
1391 | (concat "[^" end "\n\r]*")) | |
1392 | ((= (length end) 2) | |
1393 | (concat "[^" (substring end 0 1) "\n\r]*" | |
1394 | "\\(" | |
1395 | (regexp-quote (substring end 0 1)) "+" | |
1396 | "[^" | |
1397 | ;; The quoting rules inside char classes are silly. :P | |
1398 | (cond ((= (elt end 0) (elt end 1)) | |
1399 | (concat (substring end 0 1) "\n\r")) | |
1400 | ((= (elt end 1) ?\]) | |
1401 | (concat (substring end 1 2) "\n\r" | |
1402 | (substring end 0 1))) | |
1403 | (t | |
1404 | (concat (substring end 0 1) "\n\r" | |
1405 | (substring end 1 2)))) | |
1406 | "]" | |
1407 | "[^" (substring end 0 1) "\n\r]*" | |
1408 | "\\)*")) | |
1409 | (t | |
1410 | (error "Can't handle a block comment ender of length %s" | |
1411 | (length end)))))))) | |
1412 | ||
1413 | (c-lang-defconst c-block-comment-regexp | |
1414 | ;; Regexp matching a block comment that doesn't contain line breaks, | |
1415 | ;; or nil in languages without block comments. The reason we don't | |
1416 | ;; allow line breaks is to avoid going very far and risk running out | |
1417 | ;; of regexp stack; this regexp is intended to handle only short | |
1418 | ;; comments that might be put in the middle of limited constructs | |
1419 | ;; like declarations. Does not contain a \| operator at the top | |
1420 | ;; level. | |
1421 | t (when (c-lang-const c-unterminated-block-comment-regexp) | |
1422 | (concat | |
1423 | (c-lang-const c-unterminated-block-comment-regexp) | |
1424 | (let ((end (c-lang-const c-block-comment-ender))) | |
1425 | (cond ((= (length end) 1) | |
1426 | (regexp-quote end)) | |
1427 | ((= (length end) 2) | |
1428 | (concat (regexp-quote (substring end 0 1)) "+" | |
1429 | (regexp-quote (substring end 1 2)))) | |
1430 | (t | |
1431 | (error "Can't handle a block comment ender of length %s" | |
1432 | (length end)))))))) | |
d9e94c22 MS |
1433 | |
1434 | (c-lang-defconst c-nonwhite-syntactic-ws | |
1435 | ;; Regexp matching a piece of syntactic whitespace that isn't a | |
1436 | ;; sequence of simple whitespace characters. As opposed to | |
1437 | ;; `c-(forward|backward)-syntactic-ws', this doesn't regard cpp | |
1438 | ;; directives as syntactic whitespace. | |
0386b551 AM |
1439 | t (c-concat-separated |
1440 | (list (when (c-lang-const c-line-comment-starter) | |
1441 | (concat (regexp-quote (c-lang-const c-line-comment-starter)) | |
1442 | "[^\n\r]*[\n\r]")) | |
1443 | (c-lang-const c-block-comment-regexp) | |
1444 | "\\\\[\n\r]" | |
1445 | (when (memq 'gen-comment-delim c-emacs-features) | |
1446 | "\\s!\\S!*\\s!")) | |
1447 | "\\|")) | |
d9e94c22 MS |
1448 | |
1449 | (c-lang-defconst c-syntactic-ws | |
1450 | ;; Regexp matching syntactic whitespace, including possibly the | |
1451 | ;; empty string. As opposed to `c-(forward|backward)-syntactic-ws', | |
1452 | ;; this doesn't regard cpp directives as syntactic whitespace. Does | |
1453 | ;; not contain a \| operator at the top level. | |
0386b551 AM |
1454 | t (concat (c-lang-const c-simple-ws) "*" |
1455 | "\\(" | |
1456 | (concat "\\(" (c-lang-const c-nonwhite-syntactic-ws) "\\)" | |
1457 | (c-lang-const c-simple-ws) "*") | |
1458 | "\\)*")) | |
d9e94c22 MS |
1459 | |
1460 | (c-lang-defconst c-syntactic-ws-depth | |
1461 | ;; Number of regexp grouping parens in `c-syntactic-ws'. | |
0386b551 | 1462 | t (regexp-opt-depth (c-lang-const c-syntactic-ws))) |
d9e94c22 MS |
1463 | |
1464 | (c-lang-defconst c-nonempty-syntactic-ws | |
1465 | ;; Regexp matching syntactic whitespace, which is at least one | |
1466 | ;; character long. As opposed to `c-(forward|backward)-syntactic-ws', | |
1467 | ;; this doesn't regard cpp directives as syntactic whitespace. Does | |
1468 | ;; not contain a \| operator at the top level. | |
0386b551 AM |
1469 | t (concat "\\(" |
1470 | (c-lang-const c-simple-ws) | |
1471 | "\\|" | |
d9e94c22 MS |
1472 | (c-lang-const c-nonwhite-syntactic-ws) |
1473 | "\\)+")) | |
1474 | ||
1475 | (c-lang-defconst c-nonempty-syntactic-ws-depth | |
1476 | ;; Number of regexp grouping parens in `c-nonempty-syntactic-ws'. | |
0386b551 | 1477 | t (regexp-opt-depth (c-lang-const c-nonempty-syntactic-ws))) |
d9e94c22 MS |
1478 | |
1479 | (c-lang-defconst c-single-line-syntactic-ws | |
1480 | ;; Regexp matching syntactic whitespace without any line breaks. As | |
1481 | ;; opposed to `c-(forward|backward)-syntactic-ws', this doesn't | |
1482 | ;; regard cpp directives as syntactic whitespace. Does not contain | |
1483 | ;; a \| operator at the top level. | |
0386b551 AM |
1484 | t (if (c-lang-const c-block-comment-regexp) |
1485 | (concat "\\s *\\(" | |
1486 | (c-lang-const c-block-comment-regexp) | |
1487 | "\\s *\\)*") | |
1488 | "\\s *")) | |
d9e94c22 MS |
1489 | |
1490 | (c-lang-defconst c-single-line-syntactic-ws-depth | |
1491 | ;; Number of regexp grouping parens in `c-single-line-syntactic-ws'. | |
0386b551 | 1492 | t (regexp-opt-depth (c-lang-const c-single-line-syntactic-ws))) |
d9e94c22 | 1493 | |
0386b551 | 1494 | (c-lang-defconst c-syntactic-eol |
d9e94c22 MS |
1495 | ;; Regexp that matches when there is no syntactically significant |
1496 | ;; text before eol. Macros are regarded as syntactically | |
1497 | ;; significant text here. | |
0386b551 AM |
1498 | t (concat (c-lang-const c-single-line-syntactic-ws) |
1499 | ;; Match eol (possibly inside a block comment or preceded | |
1500 | ;; by a line continuation backslash), or the beginning of a | |
1501 | ;; line comment. Note: This has to be modified for awk | |
1502 | ;; where line comments start with '#'. | |
1503 | "\\(" | |
1504 | (c-concat-separated | |
1505 | (list (when (c-lang-const c-line-comment-starter) | |
1506 | (regexp-quote (c-lang-const c-line-comment-starter))) | |
1507 | (when (c-lang-const c-unterminated-block-comment-regexp) | |
1508 | (concat (c-lang-const c-unterminated-block-comment-regexp) | |
1509 | "$")) | |
1510 | "\\\\$" | |
d9e94c22 | 1511 | "$") |
0386b551 AM |
1512 | "\\|") |
1513 | "\\)")) | |
1514 | (c-lang-defvar c-syntactic-eol (c-lang-const c-syntactic-eol)) | |
1515 | ||
1516 | \f | |
28abe5e2 AM |
1517 | ;;; Defun functions |
1518 | ||
1519 | ;; The Emacs variables beginning-of-defun-function and | |
1520 | ;; end-of-defun-function will be set so that commands like | |
1521 | ;; `mark-defun' and `narrow-to-defun' work right. The key sequences | |
1522 | ;; C-M-a and C-M-e are, however, bound directly to the CC Mode | |
e1dbe924 | 1523 | ;; functions, allowing optimization for large n. |
28abe5e2 AM |
1524 | (c-lang-defconst beginning-of-defun-function |
1525 | "Function to which beginning-of-defun-function will be set." | |
1526 | t 'c-beginning-of-defun | |
1527 | awk 'c-awk-beginning-of-defun) | |
1528 | (c-lang-setvar beginning-of-defun-function | |
1529 | (c-lang-const beginning-of-defun-function)) | |
1530 | ||
1531 | (c-lang-defconst end-of-defun-function | |
1532 | "Function to which end-of-defun-function will be set." | |
1533 | t 'c-end-of-defun | |
1534 | awk 'c-awk-end-of-defun) | |
1535 | (c-lang-setvar end-of-defun-function (c-lang-const end-of-defun-function)) | |
1536 | \f | |
d9e94c22 MS |
1537 | ;;; In-comment text handling. |
1538 | ||
1539 | (c-lang-defconst c-paragraph-start | |
1540 | "Regexp to append to `paragraph-start'." | |
1541 | t "$" | |
1542 | java "\\(@[a-zA-Z]+\\>\\|$\\)" ; For Javadoc. | |
1543 | pike "\\(@[a-zA-Z_-]+\\>\\([^{]\\|$\\)\\|$\\)") ; For Pike refdoc. | |
1544 | (c-lang-defvar c-paragraph-start (c-lang-const c-paragraph-start)) | |
1545 | ||
1546 | (c-lang-defconst c-paragraph-separate | |
1547 | "Regexp to append to `paragraph-separate'." | |
1548 | t "$" | |
1549 | pike (c-lang-const c-paragraph-start)) | |
1550 | (c-lang-defvar c-paragraph-separate (c-lang-const c-paragraph-separate)) | |
1551 | ||
1552 | \f | |
1553 | ;;; Keyword lists. | |
1554 | ||
1555 | ;; Note: All and only all language constants containing keyword lists | |
1556 | ;; should end with "-kwds"; they're automatically collected into the | |
1557 | ;; `c-kwds-lang-consts' list below and used to build `c-keywords' etc. | |
1558 | ||
a66cd3ee | 1559 | (c-lang-defconst c-primitive-type-kwds |
d9e94c22 MS |
1560 | "Primitive type keywords. As opposed to the other keyword lists, the |
1561 | keywords listed here are fontified with the type face instead of the | |
1562 | keyword face. | |
1563 | ||
1564 | If any of these also are on `c-type-list-kwds', `c-ref-list-kwds', | |
1565 | `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds', | |
1566 | `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses | |
1567 | will be handled. | |
1568 | ||
1569 | Do not try to modify this list for end user customizations; the | |
1570 | `*-font-lock-extra-types' variable, where `*' is the mode prefix, is | |
1571 | the appropriate place for that." | |
1572 | t '("char" "double" "float" "int" "long" "short" "signed" | |
1573 | "unsigned" "void") | |
1574 | c (append | |
1575 | '("_Bool" "_Complex" "_Imaginary") ; Conditionally defined in C99. | |
1576 | (c-lang-const c-primitive-type-kwds)) | |
1577 | c++ (append | |
1578 | '("bool" "wchar_t") | |
1579 | (c-lang-const c-primitive-type-kwds)) | |
1580 | ;; Objective-C extends C, but probably not the new stuff in C99. | |
1581 | objc (append | |
1582 | '("id" "Class" "SEL" "IMP" "BOOL") | |
1583 | (c-lang-const c-primitive-type-kwds)) | |
a66cd3ee | 1584 | java '("boolean" "byte" "char" "double" "float" "int" "long" "short" "void") |
d9e94c22 MS |
1585 | idl '("Object" "ValueBase" "any" "boolean" "char" "double" "fixed" "float" |
1586 | "long" "octet" "sequence" "short" "string" "void" "wchar" "wstring" | |
1587 | ;; In CORBA PSDL: | |
1588 | "ref" | |
1589 | ;; The following can't really end a type, but we have to specify them | |
1590 | ;; here due to the assumption in `c-primitive-type-prefix-kwds'. It | |
1591 | ;; doesn't matter that much. | |
1592 | "unsigned" "strong") | |
1593 | pike '(;; this_program isn't really a keyword, but it's practically | |
1594 | ;; used as a builtin type. | |
1595 | "array" "float" "function" "int" "mapping" "mixed" "multiset" | |
1596 | "object" "program" "string" "this_program" "void")) | |
1597 | ||
1598 | (c-lang-defconst c-primitive-type-key | |
1599 | ;; An adorned regexp that matches `c-primitive-type-kwds'. | |
1600 | t (c-make-keywords-re t (c-lang-const c-primitive-type-kwds))) | |
1601 | (c-lang-defvar c-primitive-type-key (c-lang-const c-primitive-type-key)) | |
1602 | ||
1603 | (c-lang-defconst c-primitive-type-prefix-kwds | |
1604 | "Keywords that might act as prefixes for primitive types. Assumed to | |
1605 | be a subset of `c-primitive-type-kwds'." | |
1606 | t nil | |
1607 | (c c++) '("long" "short" "signed" "unsigned") | |
1608 | idl '("long" "unsigned" | |
1609 | ;; In CORBA PSDL: | |
1610 | "strong")) | |
1611 | ||
e15f8aaa AM |
1612 | (c-lang-defconst c-typedef-kwds |
1613 | "Prefix keyword\(s\) like \"typedef\" which make a type declaration out | |
1614 | of a variable declaration." | |
1615 | t '("typedef") | |
1616 | (awk idl java) nil) | |
1617 | ||
1618 | (c-lang-defconst c-typedef-key | |
1619 | ;; Adorned regexp matching `c-typedef-kwds'. | |
1620 | t (c-make-keywords-re t (c-lang-const c-typedef-kwds))) | |
1621 | (c-lang-defvar c-typedef-key (c-lang-const c-typedef-key)) | |
1622 | ||
d9e94c22 MS |
1623 | (c-lang-defconst c-type-prefix-kwds |
1624 | "Keywords where the following name - if any - is a type name, and | |
1625 | where the keyword together with the symbol works as a type in | |
1626 | declarations. | |
1627 | ||
1628 | Note that an alternative if the second part doesn't hold is | |
1629 | `c-type-list-kwds'. Keywords on this list are typically also present | |
1630 | on one of the `*-decl-kwds' lists." | |
1631 | t nil | |
1632 | c '("struct" "union" "enum") | |
1633 | c++ (append '("class" "typename") | |
1634 | (c-lang-const c-type-prefix-kwds c))) | |
1635 | ||
1636 | (c-lang-defconst c-type-prefix-key | |
1637 | ;; Adorned regexp matching `c-type-prefix-kwds'. | |
1638 | t (c-make-keywords-re t (c-lang-const c-type-prefix-kwds))) | |
1639 | (c-lang-defvar c-type-prefix-key (c-lang-const c-type-prefix-key)) | |
1640 | ||
1641 | (c-lang-defconst c-type-modifier-kwds | |
1642 | "Type modifier keywords. These can occur almost anywhere in types | |
1643 | but they don't build a type of themselves. Unlike the keywords on | |
1644 | `c-primitive-type-kwds', they are fontified with the keyword face and | |
1645 | not the type face." | |
1646 | t nil | |
1647 | c '("const" "restrict" "volatile") | |
1648 | c++ '("const" "volatile" "throw") | |
1649 | objc '("const" "volatile")) | |
1650 | ||
1651 | (c-lang-defconst c-opt-type-modifier-key | |
1652 | ;; Adorned regexp matching `c-type-modifier-kwds', or nil in | |
1653 | ;; languages without such keywords. | |
1654 | t (and (c-lang-const c-type-modifier-kwds) | |
1655 | (c-make-keywords-re t (c-lang-const c-type-modifier-kwds)))) | |
1656 | (c-lang-defvar c-opt-type-modifier-key (c-lang-const c-opt-type-modifier-key)) | |
1657 | ||
1658 | (c-lang-defconst c-opt-type-component-key | |
1659 | ;; An adorned regexp that matches `c-primitive-type-prefix-kwds' and | |
1660 | ;; `c-type-modifier-kwds', or nil in languages without any of them. | |
1661 | t (and (or (c-lang-const c-primitive-type-prefix-kwds) | |
1662 | (c-lang-const c-type-modifier-kwds)) | |
1663 | (c-make-keywords-re t | |
1664 | (append (c-lang-const c-primitive-type-prefix-kwds) | |
1665 | (c-lang-const c-type-modifier-kwds))))) | |
1666 | (c-lang-defvar c-opt-type-component-key | |
1667 | (c-lang-const c-opt-type-component-key)) | |
1668 | ||
0386b551 AM |
1669 | (c-lang-defconst c-type-start-kwds |
1670 | ;; All keywords that can start a type (i.e. are either a type prefix | |
1671 | ;; or a complete type). | |
1672 | t (delete-duplicates (append (c-lang-const c-primitive-type-kwds) | |
1673 | (c-lang-const c-type-prefix-kwds) | |
1674 | (c-lang-const c-type-modifier-kwds)) | |
1675 | :test 'string-equal)) | |
1676 | ||
d9e94c22 MS |
1677 | (c-lang-defconst c-class-decl-kwds |
1678 | "Keywords introducing declarations where the following block (if any) | |
1679 | contains another declaration level that should be considered a class. | |
1680 | ||
1681 | If any of these also are on `c-type-list-kwds', `c-ref-list-kwds', | |
1682 | `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds', | |
1683 | `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses | |
1684 | will be handled. | |
1685 | ||
1686 | Note that presence on this list does not automatically treat the | |
1687 | following identifier as a type; the keyword must also be present on | |
1688 | `c-type-prefix-kwds' or `c-type-list-kwds' to accomplish that." | |
1689 | t nil | |
1690 | c '("struct" "union") | |
1691 | c++ '("class" "struct" "union") | |
1692 | objc '("struct" "union" | |
1693 | "@interface" "@implementation" "@protocol") | |
452ea855 | 1694 | java '("class" "@interface" "interface") |
d9e94c22 MS |
1695 | idl '("component" "eventtype" "exception" "home" "interface" "struct" |
1696 | "union" "valuetype" | |
1697 | ;; In CORBA PSDL: | |
1698 | "storagehome" "storagetype" | |
1699 | ;; In CORBA CIDL: | |
1700 | "catalog" "executor" "manages" "segment") | |
a66cd3ee MS |
1701 | pike '("class")) |
1702 | ||
a66cd3ee | 1703 | (c-lang-defconst c-class-key |
d9e94c22 MS |
1704 | ;; Regexp matching the start of a class. |
1705 | t (c-make-keywords-re t (c-lang-const c-class-decl-kwds))) | |
1706 | (c-lang-defvar c-class-key (c-lang-const c-class-key)) | |
1707 | ||
1708 | (c-lang-defconst c-brace-list-decl-kwds | |
1709 | "Keywords introducing declarations where the following block (if | |
1710 | any) is a brace list. | |
1711 | ||
1712 | If any of these also are on `c-type-list-kwds', `c-ref-list-kwds', | |
1713 | `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds', | |
1714 | `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses | |
1715 | will be handled." | |
1716 | t '("enum") | |
452ea855 | 1717 | (awk) nil) |
d9e94c22 MS |
1718 | |
1719 | (c-lang-defconst c-brace-list-key | |
1720 | ;; Regexp matching the start of declarations where the following | |
1721 | ;; block is a brace list. | |
1722 | t (c-make-keywords-re t (c-lang-const c-brace-list-decl-kwds))) | |
1723 | (c-lang-defvar c-brace-list-key (c-lang-const c-brace-list-key)) | |
1724 | ||
1725 | (c-lang-defconst c-other-block-decl-kwds | |
3efc2cd7 | 1726 | "Keywords where the following block (if any) contains another |
0386b551 AM |
1727 | declaration level that should not be considered a class. For every |
1728 | keyword here, CC Mode will add a set of special syntactic symbols for | |
1729 | those blocks. E.g. if the keyword is \"foo\" then there will be | |
1730 | `foo-open', `foo-close', and `infoo' symbols. | |
1731 | ||
1732 | The intention is that this category should be used for block | |
1733 | constructs that aren't related to object orientation concepts like | |
1734 | classes (which thus also include e.g. interfaces, templates, | |
1735 | contracts, structs, etc). The more pragmatic distinction is that | |
1736 | while most want some indentation inside classes, it's fairly common | |
1737 | that they don't want it in some of these constructs, so it should be | |
1738 | simple to configure that differently from classes. See also | |
1739 | `c-class-decl-kwds'. | |
d9e94c22 MS |
1740 | |
1741 | If any of these also are on `c-type-list-kwds', `c-ref-list-kwds', | |
1742 | `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds', | |
1743 | `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses | |
1744 | will be handled." | |
1745 | t nil | |
0386b551 | 1746 | (c objc) '("extern") |
a66cd3ee | 1747 | c++ '("namespace" "extern") |
d9e94c22 MS |
1748 | idl '("module" |
1749 | ;; In CORBA CIDL: | |
1750 | "composition")) | |
a66cd3ee | 1751 | |
a66cd3ee | 1752 | (c-lang-defconst c-other-decl-block-key |
d9e94c22 MS |
1753 | ;; Regexp matching the start of blocks besides classes that contain |
1754 | ;; another declaration level. | |
1755 | t (c-make-keywords-re t (c-lang-const c-other-block-decl-kwds))) | |
1756 | (c-lang-defvar c-other-decl-block-key (c-lang-const c-other-decl-block-key)) | |
1757 | ||
c382ec40 AM |
1758 | (c-lang-defvar c-other-decl-block-key-in-symbols-alist |
1759 | (mapcar | |
1760 | (lambda (elt) | |
1761 | (cons elt | |
1762 | (if (string= elt "extern") | |
1763 | 'inextern-lang | |
1764 | (intern (concat "in" elt))))) | |
1765 | (c-lang-const c-other-block-decl-kwds)) | |
1766 | "Alist associating keywords in c-other-decl-block-decl-kwds with | |
1767 | their matching \"in\" syntactic symbols.") | |
1768 | ||
d9e94c22 | 1769 | (c-lang-defconst c-typedef-decl-kwds |
0386b551 AM |
1770 | "Keywords introducing declarations where the identifier(s) being |
1771 | declared are types. | |
d9e94c22 MS |
1772 | |
1773 | If any of these also are on `c-type-list-kwds', `c-ref-list-kwds', | |
1774 | `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds', | |
1775 | `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses | |
1776 | will be handled." | |
0386b551 AM |
1777 | ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds' |
1778 | ;; (since e.g. "Foo" is a type that's being defined in "class Foo | |
1779 | ;; {...}"). | |
1780 | t (append (c-lang-const c-class-decl-kwds) | |
1781 | (c-lang-const c-brace-list-decl-kwds)) | |
1782 | ;; Languages that have a "typedef" construct. | |
1783 | (c c++ objc idl pike) (append (c-lang-const c-typedef-decl-kwds) | |
1784 | '("typedef")) | |
1785 | ;; Unlike most other languages, exception names are not handled as | |
1786 | ;; types in IDL since they only can occur in "raises" specs. | |
1787 | idl (delete "exception" (append (c-lang-const c-typedef-decl-kwds) nil))) | |
d9e94c22 | 1788 | |
e15f8aaa AM |
1789 | (c-lang-defconst c-typedef-decl-key |
1790 | t (c-make-keywords-re t (c-lang-const c-typedef-decl-kwds))) | |
1791 | (c-lang-defvar c-typedef-decl-key (c-lang-const c-typedef-decl-key)) | |
1792 | ||
d9e94c22 | 1793 | (c-lang-defconst c-typeless-decl-kwds |
0386b551 AM |
1794 | "Keywords introducing declarations where the \(first) identifier |
1795 | \(declarator) follows directly after the keyword, without any type. | |
d9e94c22 MS |
1796 | |
1797 | If any of these also are on `c-type-list-kwds', `c-ref-list-kwds', | |
1798 | `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds', | |
1799 | `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses | |
1800 | will be handled." | |
0386b551 AM |
1801 | ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds' |
1802 | ;; (since e.g. "Foo" is the identifier being defined in "class Foo | |
1803 | ;; {...}"). | |
1804 | t (append (c-lang-const c-class-decl-kwds) | |
1805 | (c-lang-const c-brace-list-decl-kwds)) | |
1806 | ;; Note: "manages" for CORBA CIDL clashes with its presence on | |
1807 | ;; `c-type-list-kwds' for IDL. | |
1808 | idl (append (c-lang-const c-typeless-decl-kwds) | |
1809 | '("factory" "finder" "native" | |
1810 | ;; In CORBA PSDL: | |
1811 | "key" "stores" | |
1812 | ;; In CORBA CIDL: | |
1813 | "facet")) | |
1814 | pike (append (c-lang-const c-class-decl-kwds) | |
1815 | '("constant"))) | |
d9e94c22 MS |
1816 | |
1817 | (c-lang-defconst c-modifier-kwds | |
1818 | "Keywords that can prefix normal declarations of identifiers | |
0386b551 | 1819 | \(and typically act as flags). Things like argument declarations |
d9e94c22 MS |
1820 | inside function headers are also considered declarations in this |
1821 | sense. | |
1822 | ||
1823 | If any of these also are on `c-type-list-kwds', `c-ref-list-kwds', | |
1824 | `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds', | |
1825 | `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses | |
1826 | will be handled." | |
1827 | t nil | |
1828 | (c c++) '("auto" "extern" "inline" "register" "static") | |
1829 | c++ (append '("explicit" "friend" "mutable" "template" "using" "virtual") | |
1830 | (c-lang-const c-modifier-kwds)) | |
1831 | objc '("auto" "bycopy" "byref" "extern" "in" "inout" "oneway" "out" "static") | |
1832 | ;; FIXME: Some of those below ought to be on `c-other-decl-kwds' instead. | |
1833 | idl '("abstract" "attribute" "const" "consumes" "custom" "emits" "import" | |
1834 | "in" "inout" "local" "multiple" "oneway" "out" "private" "provides" | |
1835 | "public" "publishes" "readonly" "typeid" "typeprefix" "uses" | |
1836 | ;; In CORBA PSDL: | |
1837 | "primary" "state" | |
1838 | ;; In CORBA CIDL: | |
1839 | "bindsTo" "delegatesTo" "implements" "proxy" "storedOn") | |
1840 | ;; Note: "const" is not used in Java, but it's still a reserved keyword. | |
1841 | java '("abstract" "const" "final" "native" "private" "protected" "public" | |
e3715033 | 1842 | "static" "strictfp" "synchronized" "transient" "volatile") |
d9e94c22 MS |
1843 | pike '("final" "inline" "local" "nomask" "optional" "private" "protected" |
1844 | "public" "static" "variant")) | |
a66cd3ee | 1845 | |
d9e94c22 MS |
1846 | (c-lang-defconst c-other-decl-kwds |
1847 | "Keywords that can start or prefix any declaration level construct, | |
1848 | besides those on `c-class-decl-kwds', `c-brace-list-decl-kwds', | |
1849 | `c-other-block-decl-kwds', `c-typedef-decl-kwds', | |
0386b551 | 1850 | `c-typeless-decl-kwds' and `c-modifier-kwds'. |
d9e94c22 MS |
1851 | |
1852 | If any of these also are on `c-type-list-kwds', `c-ref-list-kwds', | |
1853 | `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds', | |
1854 | `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses | |
1855 | will be handled." | |
1856 | t nil | |
d9e94c22 MS |
1857 | objc '("@class" "@end" "@defs") |
1858 | java '("import" "package") | |
1859 | pike '("import" "inherit")) | |
1860 | ||
0386b551 AM |
1861 | (c-lang-defconst c-decl-start-kwds |
1862 | "Keywords that always start declarations, wherever they occur. | |
1863 | This can be used for declarations that aren't recognized by the normal | |
1864 | combination of `c-decl-prefix-re' and `c-decl-start-re'." | |
1865 | t nil | |
1866 | ;; Classes can be declared anywhere in a Pike expression. | |
1867 | pike '("class")) | |
1868 | ||
1869 | (c-lang-defconst c-decl-hangon-kwds | |
1870 | "Keywords that can occur anywhere in a declaration level construct. | |
1871 | This is used for self-contained things that can be tacked on anywhere | |
1872 | on a declaration and that should be ignored to be able to recognize it | |
1873 | correctly. Typical cases are compiler extensions like | |
1874 | \"__attribute__\" or \"__declspec\": | |
1875 | ||
1876 | __declspec(noreturn) void foo(); | |
1877 | class __declspec(dllexport) classname {...}; | |
1878 | void foo() __attribute__((noreturn)); | |
1879 | ||
1880 | Note that unrecognized plain symbols are skipped anyway if they occur | |
1881 | before the type, so such things are not necessary to mention here. | |
1882 | Mentioning them here is necessary only if they can occur in other | |
1883 | places, or if they are followed by a construct that must be skipped | |
1884 | over \(like the parens in the \"__attribute__\" and \"__declspec\" | |
1885 | examples above). In the last case, they alse need to be present on | |
1886 | one of `c-type-list-kwds', `c-ref-list-kwds', | |
1887 | `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds', | |
1888 | `c-<>-type-kwds', or `c-<>-arglist-kwds'." | |
1889 | ;; NB: These are currently not recognized in all parts of a | |
1890 | ;; declaration. Specifically, they aren't recognized in the middle | |
1891 | ;; of multi-token types, inside declarators, and between the | |
1892 | ;; identifier and the arglist paren of a function declaration. | |
1893 | ;; | |
1894 | ;; FIXME: This ought to be user customizable since compiler stuff | |
1895 | ;; like this usually is wrapped in project specific macros. (It'd | |
1896 | ;; of course be even better if we could cope without knowing this.) | |
1897 | t nil | |
1898 | (c c++) '(;; GCC extension. | |
1899 | "__attribute__" | |
1900 | ;; MSVC extension. | |
1901 | "__declspec")) | |
1902 | ||
1903 | (c-lang-defconst c-decl-hangon-key | |
1904 | ;; Adorned regexp matching `c-decl-hangon-kwds'. | |
1905 | t (c-make-keywords-re t (c-lang-const c-decl-hangon-kwds))) | |
1906 | (c-lang-defvar c-decl-hangon-key (c-lang-const c-decl-hangon-key)) | |
1907 | ||
1908 | (c-lang-defconst c-prefix-spec-kwds | |
1909 | ;; All keywords that can occur in the preamble of a declaration. | |
1910 | ;; They typically occur before the type, but they are also matched | |
1911 | ;; after presumptive types since we often can't be sure that | |
1912 | ;; something is a type or just some sort of macro in front of the | |
1913 | ;; declaration. They might be ambiguous with types or type | |
1914 | ;; prefixes. | |
1915 | t (delete-duplicates (append (c-lang-const c-class-decl-kwds) | |
1916 | (c-lang-const c-brace-list-decl-kwds) | |
1917 | (c-lang-const c-other-block-decl-kwds) | |
1918 | (c-lang-const c-typedef-decl-kwds) | |
1919 | (c-lang-const c-typeless-decl-kwds) | |
1920 | (c-lang-const c-modifier-kwds) | |
1921 | (c-lang-const c-other-decl-kwds) | |
1922 | (c-lang-const c-decl-start-kwds) | |
1923 | (c-lang-const c-decl-hangon-kwds)) | |
1924 | :test 'string-equal)) | |
1925 | ||
1926 | (c-lang-defconst c-prefix-spec-kwds-re | |
1927 | ;; Adorned regexp of `c-prefix-spec-kwds'. | |
e3715033 | 1928 | t (c-make-keywords-re t (c-lang-const c-prefix-spec-kwds))) |
452ea855 | 1929 | |
0386b551 AM |
1930 | (c-lang-defvar c-prefix-spec-kwds-re (c-lang-const c-prefix-spec-kwds-re)) |
1931 | ||
d9e94c22 | 1932 | (c-lang-defconst c-specifier-key |
cc1cce14 AM |
1933 | ;; Adorned regexp of the keywords in `c-prefix-spec-kwds' that aren't |
1934 | ;; ambiguous with types or type prefixes. These are the keywords (like | |
1935 | ;; extern, namespace, but NOT template) that can modify a declaration. | |
d9e94c22 | 1936 | t (c-make-keywords-re t |
0386b551 | 1937 | (set-difference (c-lang-const c-prefix-spec-kwds) |
cc1cce14 AM |
1938 | (append (c-lang-const c-type-start-kwds) |
1939 | (c-lang-const c-<>-arglist-kwds)) | |
d9e94c22 MS |
1940 | :test 'string-equal))) |
1941 | (c-lang-defvar c-specifier-key (c-lang-const c-specifier-key)) | |
a66cd3ee | 1942 | |
0386b551 AM |
1943 | (c-lang-defconst c-postfix-spec-kwds |
1944 | ;; Keywords that can occur after argument list of a function header | |
1945 | ;; declaration, i.e. in the "K&R region". | |
1946 | t (append (c-lang-const c-postfix-decl-spec-kwds) | |
1947 | (c-lang-const c-decl-hangon-kwds))) | |
1948 | ||
1949 | (c-lang-defconst c-not-decl-init-keywords | |
1950 | ;; Adorned regexp matching all keywords that can't appear at the | |
1951 | ;; start of a declaration. | |
1952 | t (c-make-keywords-re t | |
1953 | (set-difference (c-lang-const c-keywords) | |
1954 | (append (c-lang-const c-type-start-kwds) | |
1955 | (c-lang-const c-prefix-spec-kwds)) | |
1956 | :test 'string-equal))) | |
1957 | (c-lang-defvar c-not-decl-init-keywords | |
1958 | (c-lang-const c-not-decl-init-keywords)) | |
1959 | ||
b248a85d AM |
1960 | (c-lang-defconst c-not-primitive-type-keywords |
1961 | "List of all keywords apart from primitive types (like \"int\")." | |
1962 | t (set-difference (c-lang-const c-keywords) | |
1963 | (c-lang-const c-primitive-type-kwds) | |
1964 | :test 'string-equal) | |
1965 | ;; The "more" for C++ is the QT keyword (as in "more slots:"). | |
1966 | ;; This variable is intended for use in c-beginning-of-statement-1. | |
1967 | c++ (append (c-lang-const c-not-primitive-type-keywords) '("more"))) | |
1968 | ||
1969 | (c-lang-defconst c-not-primitive-type-keywords-regexp | |
1970 | t (c-make-keywords-re t | |
1971 | (c-lang-const c-not-primitive-type-keywords))) | |
1972 | (c-lang-defvar c-not-primitive-type-keywords-regexp | |
1973 | (c-lang-const c-not-primitive-type-keywords-regexp)) | |
1974 | ||
d9e94c22 | 1975 | (c-lang-defconst c-protection-kwds |
0386b551 | 1976 | "Access protection label keywords in classes." |
d9e94c22 MS |
1977 | t nil |
1978 | c++ '("private" "protected" "public") | |
1979 | objc '("@private" "@protected" "@public")) | |
a66cd3ee | 1980 | |
d9e94c22 MS |
1981 | (c-lang-defconst c-block-decls-with-vars |
1982 | "Keywords introducing declarations that can contain a block which | |
1983 | might be followed by variable declarations, e.g. like \"foo\" in | |
1984 | \"class Foo { ... } foo;\". So if there is a block in a declaration | |
1985 | like that, it ends with the following ';' and not right away. | |
130c507e | 1986 | |
d9e94c22 MS |
1987 | The keywords on list are assumed to also be present on one of the |
1988 | `*-decl-kwds' lists." | |
1989 | t nil | |
1990 | (c objc) '("struct" "union" "enum" "typedef") | |
1991 | c++ '("class" "struct" "union" "enum" "typedef")) | |
1992 | ||
1993 | (c-lang-defconst c-opt-block-decls-with-vars-key | |
1994 | ;; Regexp matching the `c-block-decls-with-vars' keywords, or nil in | |
1995 | ;; languages without such constructs. | |
1996 | t (and (c-lang-const c-block-decls-with-vars) | |
1997 | (c-make-keywords-re t (c-lang-const c-block-decls-with-vars)))) | |
1998 | (c-lang-defvar c-opt-block-decls-with-vars-key | |
1999 | (c-lang-const c-opt-block-decls-with-vars-key)) | |
2000 | ||
2001 | (c-lang-defconst c-postfix-decl-spec-kwds | |
2002 | "Keywords introducing extra declaration specifiers in the region | |
2003 | between the header and the body \(i.e. the \"K&R-region\") in | |
2004 | declarations." | |
2005 | t nil | |
d9e94c22 MS |
2006 | java '("extends" "implements" "throws") |
2007 | idl '("context" "getraises" "manages" "primarykey" "raises" "setraises" | |
2008 | "supports" | |
2009 | ;; In CORBA PSDL: | |
2010 | "as" "const" "implements" "of" "ref")) | |
2011 | ||
2012 | (c-lang-defconst c-nonsymbol-sexp-kwds | |
2013 | "Keywords that may be followed by a nonsymbol sexp before whatever | |
2014 | construct it's part of continues." | |
2015 | t nil | |
2016 | (c c++ objc) '("extern")) | |
2017 | ||
2018 | (c-lang-defconst c-type-list-kwds | |
2019 | "Keywords that may be followed by a comma separated list of type | |
2020 | identifiers, where each optionally can be prefixed by keywords. (Can | |
2021 | also be used for the special case when the list can contain only one | |
2022 | element.) | |
2023 | ||
2024 | Assumed to be mutually exclusive with `c-ref-list-kwds'. There's no | |
2025 | reason to put keywords on this list if they are on `c-type-prefix-kwds'. | |
2026 | There's also no reason to add keywords that prefixes a normal | |
2027 | declaration consisting of a type followed by a declarator (list), so | |
2028 | the keywords on `c-modifier-kwds' should normally not be listed here | |
0386b551 | 2029 | either. |
d9e94c22 MS |
2030 | |
2031 | Note: Use `c-typeless-decl-kwds' for keywords followed by a function | |
2032 | or variable identifier (that's being defined)." | |
0386b551 | 2033 | t nil |
fa14078b | 2034 | c++ '("operator") |
0386b551 | 2035 | objc '("@class") |
452ea855 | 2036 | java '("import" "new" "extends" "super" "implements" "throws") |
0386b551 AM |
2037 | idl '("manages" "native" "primarykey" "supports" |
2038 | ;; In CORBA PSDL: | |
2039 | "as" "implements" "of" "scope") | |
2040 | pike '("inherit")) | |
d9e94c22 MS |
2041 | |
2042 | (c-lang-defconst c-ref-list-kwds | |
2043 | "Keywords that may be followed by a comma separated list of | |
2044 | reference (i.e. namespace/scope/module) identifiers, where each | |
2045 | optionally can be prefixed by keywords. (Can also be used for the | |
2046 | special case when the list can contain only one element.) Assumed to | |
2047 | be mutually exclusive with `c-type-list-kwds'. | |
2048 | ||
2049 | Note: Use `c-typeless-decl-kwds' for keywords followed by a function | |
2050 | or variable identifier (that's being defined)." | |
2051 | t nil | |
2052 | c++ '("namespace") | |
2053 | java '("package") | |
2054 | idl '("import" "module" | |
2055 | ;; In CORBA CIDL: | |
2056 | "composition") | |
2057 | pike '("import")) | |
2058 | ||
2059 | (c-lang-defconst c-colon-type-list-kwds | |
2060 | "Keywords that may be followed (not necessarily directly) by a colon | |
2061 | and then a comma separated list of type identifiers, where each | |
2062 | optionally can be prefixed by keywords. (Can also be used for the | |
2063 | special case when the list can contain only one element.)" | |
2064 | t nil | |
2065 | c++ '("class" "struct") | |
2066 | idl '("component" "eventtype" "home" "interface" "valuetype" | |
2067 | ;; In CORBA PSDL: | |
2068 | "storagehome" "storagetype")) | |
2069 | ||
2070 | (c-lang-defconst c-colon-type-list-re | |
2071 | "Regexp matched after the keywords in `c-colon-type-list-kwds' to skip | |
2072 | forward to the colon. The end of the match is assumed to be directly | |
0386b551 AM |
2073 | after the colon, so the regexp should end with \":\". Must be a |
2074 | regexp if `c-colon-type-list-kwds' isn't nil." | |
d9e94c22 MS |
2075 | t (if (c-lang-const c-colon-type-list-kwds) |
2076 | ;; Disallow various common punctuation chars that can't come | |
2077 | ;; before the ":" that starts the inherit list after "class" | |
2078 | ;; or "struct" in C++. (Also used as default for other | |
2079 | ;; languages.) | |
2080 | "[^\]\[{}();,/#=:]*:")) | |
2081 | (c-lang-defvar c-colon-type-list-re (c-lang-const c-colon-type-list-re)) | |
2082 | ||
2083 | (c-lang-defconst c-paren-nontype-kwds | |
2084 | "Keywords that may be followed by a parenthesis expression that doesn't | |
2085 | contain type identifiers." | |
2086 | t nil | |
0386b551 AM |
2087 | (c c++) '(;; GCC extension. |
2088 | "__attribute__" | |
2089 | ;; MSVC extension. | |
2090 | "__declspec")) | |
d9e94c22 MS |
2091 | |
2092 | (c-lang-defconst c-paren-type-kwds | |
2093 | "Keywords that may be followed by a parenthesis expression containing | |
2094 | type identifiers separated by arbitrary tokens." | |
2095 | t nil | |
2096 | c++ '("throw") | |
2097 | objc '("@defs") | |
2098 | idl '("switch") | |
2099 | pike '("array" "function" "int" "mapping" "multiset" "object" "program")) | |
2100 | ||
2101 | (c-lang-defconst c-paren-any-kwds | |
2102 | t (delete-duplicates (append (c-lang-const c-paren-nontype-kwds) | |
2103 | (c-lang-const c-paren-type-kwds)) | |
2104 | :test 'string-equal)) | |
2105 | ||
2106 | (c-lang-defconst c-<>-type-kwds | |
2107 | "Keywords that may be followed by an angle bracket expression | |
2108 | containing type identifiers separated by \",\". The difference from | |
2109 | `c-<>-arglist-kwds' is that unknown names are taken to be types and | |
2110 | not other identifiers. `c-recognize-<>-arglists' is assumed to be set | |
2111 | if this isn't nil." | |
2112 | t nil | |
2113 | objc '("id") | |
2114 | idl '("sequence" | |
2115 | ;; In CORBA PSDL: | |
2116 | "ref")) | |
2117 | ||
2118 | (c-lang-defconst c-<>-arglist-kwds | |
2119 | "Keywords that can be followed by a C++ style template arglist; see | |
2120 | `c-recognize-<>-arglists' for details. That language constant is | |
2121 | assumed to be set if this isn't nil." | |
2122 | t nil | |
2123 | c++ '("template") | |
2124 | idl '("fixed" "string" "wstring")) | |
2125 | ||
2126 | (c-lang-defconst c-<>-sexp-kwds | |
2127 | ;; All keywords that can be followed by an angle bracket sexp. | |
2128 | t (delete-duplicates (append (c-lang-const c-<>-type-kwds) | |
2129 | (c-lang-const c-<>-arglist-kwds)) | |
2130 | :test 'string-equal)) | |
2131 | ||
2132 | (c-lang-defconst c-opt-<>-sexp-key | |
2133 | ;; Adorned regexp matching keywords that can be followed by an angle | |
846f5040 | 2134 | ;; bracket sexp. Always set when `c-recognize-<>-arglists' is. |
d9e94c22 MS |
2135 | t (if (c-lang-const c-recognize-<>-arglists) |
2136 | (c-make-keywords-re t (c-lang-const c-<>-sexp-kwds)))) | |
2137 | (c-lang-defvar c-opt-<>-sexp-key (c-lang-const c-opt-<>-sexp-key)) | |
2138 | ||
2139 | (c-lang-defconst c-brace-id-list-kwds | |
2140 | "Keywords that may be followed by a brace block containing a comma | |
2141 | separated list of identifier definitions, i.e. like the list of | |
2142 | identifiers that follows the type in a normal declaration." | |
2143 | t (c-lang-const c-brace-list-decl-kwds)) | |
a66cd3ee | 2144 | |
a66cd3ee | 2145 | (c-lang-defconst c-block-stmt-1-kwds |
d9e94c22 MS |
2146 | "Statement keywords followed directly by a substatement." |
2147 | t '("do" "else") | |
2148 | c++ '("do" "else" "try") | |
9555a4cf | 2149 | objc '("do" "else" "@finally" "@try") |
d9e94c22 MS |
2150 | java '("do" "else" "finally" "try") |
2151 | idl nil) | |
a66cd3ee | 2152 | |
a66cd3ee | 2153 | (c-lang-defconst c-block-stmt-1-key |
d9e94c22 MS |
2154 | ;; Regexp matching the start of any statement followed directly by a |
2155 | ;; substatement (doesn't match a bare block, however). | |
2156 | t (c-make-keywords-re t (c-lang-const c-block-stmt-1-kwds))) | |
2157 | (c-lang-defvar c-block-stmt-1-key (c-lang-const c-block-stmt-1-key)) | |
a66cd3ee | 2158 | |
a66cd3ee | 2159 | (c-lang-defconst c-block-stmt-2-kwds |
d9e94c22 MS |
2160 | "Statement keywords followed by a paren sexp and then by a substatement." |
2161 | t '("for" "if" "switch" "while") | |
2162 | c++ '("for" "if" "switch" "while" "catch") | |
9555a4cf | 2163 | objc '("for" "if" "switch" "while" "@catch" "@synchronized") |
a66cd3ee | 2164 | java '("for" "if" "switch" "while" "catch" "synchronized") |
d9e94c22 MS |
2165 | idl nil |
2166 | pike '("for" "if" "switch" "while" "foreach") | |
2167 | awk '("for" "if" "while")) | |
a66cd3ee | 2168 | |
a66cd3ee | 2169 | (c-lang-defconst c-block-stmt-2-key |
d9e94c22 MS |
2170 | ;; Regexp matching the start of any statement followed by a paren sexp |
2171 | ;; and then by a substatement. | |
2172 | t (c-make-keywords-re t (c-lang-const c-block-stmt-2-kwds))) | |
2173 | (c-lang-defvar c-block-stmt-2-key (c-lang-const c-block-stmt-2-key)) | |
a66cd3ee | 2174 | |
0386b551 AM |
2175 | (c-lang-defconst c-block-stmt-kwds |
2176 | ;; Union of `c-block-stmt-1-kwds' and `c-block-stmt-2-kwds'. | |
2177 | t (delete-duplicates (append (c-lang-const c-block-stmt-1-kwds) | |
2178 | (c-lang-const c-block-stmt-2-kwds)) | |
2179 | :test 'string-equal)) | |
2180 | ||
a66cd3ee | 2181 | (c-lang-defconst c-opt-block-stmt-key |
d9e94c22 MS |
2182 | ;; Regexp matching the start of any statement that has a |
2183 | ;; substatement (except a bare block). Nil in languages that | |
2184 | ;; don't have such constructs. | |
2185 | t (if (or (c-lang-const c-block-stmt-1-kwds) | |
2186 | (c-lang-const c-block-stmt-2-kwds)) | |
2187 | (c-make-keywords-re t | |
2188 | (append (c-lang-const c-block-stmt-1-kwds) | |
2189 | (c-lang-const c-block-stmt-2-kwds))))) | |
2190 | (c-lang-defvar c-opt-block-stmt-key (c-lang-const c-opt-block-stmt-key)) | |
2191 | ||
a66cd3ee | 2192 | (c-lang-defconst c-simple-stmt-kwds |
d9e94c22 MS |
2193 | "Statement keywords followed by an expression or nothing." |
2194 | t '("break" "continue" "goto" "return") | |
9555a4cf | 2195 | objc '("break" "continue" "goto" "return" "@throw") |
a66cd3ee MS |
2196 | ;; Note: `goto' is not valid in Java, but the keyword is still reserved. |
2197 | java '("break" "continue" "goto" "return" "throw") | |
d9e94c22 MS |
2198 | idl nil |
2199 | pike '("break" "continue" "return") | |
2200 | awk '(;; Not sure about "delete", "exit", "getline", etc. ; ACM 2002/5/30 | |
2201 | "break" "continue" "return" "delete" "exit" "getline" "next" | |
2202 | "nextfile" "print" "printf")) | |
2203 | ||
2204 | (c-lang-defconst c-simple-stmt-key | |
2205 | ;; Adorned regexp matching `c-simple-stmt-kwds'. | |
2206 | t (c-make-keywords-re t (c-lang-const c-simple-stmt-kwds))) | |
2207 | (c-lang-defvar c-simple-stmt-key (c-lang-const c-simple-stmt-key)) | |
2208 | ||
2209 | (c-lang-defconst c-paren-stmt-kwds | |
2210 | "Statement keywords followed by a parenthesis expression that | |
2211 | nevertheless contains a list separated with ';' and not ','." | |
2212 | t '("for") | |
2213 | idl nil) | |
2214 | ||
2215 | (c-lang-defconst c-paren-stmt-key | |
2216 | ;; Adorned regexp matching `c-paren-stmt-kwds'. | |
2217 | t (c-make-keywords-re t (c-lang-const c-paren-stmt-kwds))) | |
2218 | (c-lang-defvar c-paren-stmt-key (c-lang-const c-paren-stmt-key)) | |
a66cd3ee | 2219 | |
a66cd3ee | 2220 | (c-lang-defconst c-asm-stmt-kwds |
d9e94c22 MS |
2221 | "Statement keywords followed by an assembler expression." |
2222 | t nil | |
2223 | (c c++) '("asm" "__asm__")) ;; Not standard, but common. | |
a66cd3ee | 2224 | |
a66cd3ee | 2225 | (c-lang-defconst c-opt-asm-stmt-key |
d9e94c22 MS |
2226 | ;; Regexp matching the start of an assembler statement. Nil in |
2227 | ;; languages that don't support that. | |
2228 | t (if (c-lang-const c-asm-stmt-kwds) | |
2229 | (c-make-keywords-re t (c-lang-const c-asm-stmt-kwds)))) | |
2230 | (c-lang-defvar c-opt-asm-stmt-key (c-lang-const c-opt-asm-stmt-key)) | |
2231 | ||
d28e7f28 AM |
2232 | (c-lang-defconst c-case-kwds |
2233 | "The keyword\(s) which introduce a \"case\" like construct. | |
2234 | This construct is \"<keyword> <expression> :\"." | |
2235 | t '("case") | |
2236 | awk nil) | |
2237 | ||
2238 | (c-lang-defconst c-case-kwds-regexp | |
2239 | ;; Adorned regexp matching any "case"-like keyword. | |
2240 | t (c-make-keywords-re t (c-lang-const c-case-kwds))) | |
2241 | (c-lang-defvar c-case-kwds-regexp (c-lang-const c-case-kwds-regexp)) | |
2242 | ||
d9e94c22 | 2243 | (c-lang-defconst c-label-kwds |
0386b551 | 2244 | "Keywords introducing colon terminated labels in blocks." |
898169a2 | 2245 | t '("case" "default")) |
d9e94c22 | 2246 | |
0386b551 AM |
2247 | (c-lang-defconst c-label-kwds-regexp |
2248 | ;; Adorned regexp matching any keyword that introduces a label. | |
2249 | t (c-make-keywords-re t (c-lang-const c-label-kwds))) | |
2250 | (c-lang-defvar c-label-kwds-regexp (c-lang-const c-label-kwds-regexp)) | |
2251 | ||
d9e94c22 MS |
2252 | (c-lang-defconst c-before-label-kwds |
2253 | "Keywords that might be followed by a label identifier." | |
2254 | t '("goto") | |
2255 | (java pike) (append '("break" "continue") | |
2256 | (c-lang-const c-before-label-kwds)) | |
2257 | idl nil | |
2258 | awk nil) | |
130c507e | 2259 | |
d9e94c22 MS |
2260 | (c-lang-defconst c-constant-kwds |
2261 | "Keywords for constants." | |
2262 | t nil | |
2263 | (c c++) '("NULL" ;; Not a keyword, but practically works as one. | |
2264 | "false" "true") ; Defined in C99. | |
f0e4b2f2 | 2265 | objc '("nil" "Nil" "YES" "NO" "NS_DURING" "NS_HANDLER" "NS_ENDHANDLER") |
d9e94c22 | 2266 | idl '("TRUE" "FALSE") |
fbd4de65 | 2267 | java '("true" "false" "null") ; technically "literals", not keywords |
d9e94c22 MS |
2268 | pike '("UNDEFINED")) ;; Not a keyword, but practically works as one. |
2269 | ||
2270 | (c-lang-defconst c-primary-expr-kwds | |
2271 | "Keywords besides constants and operators that start primary expressions." | |
2272 | t nil | |
2273 | c++ '("operator" "this") | |
2274 | objc '("super" "self") | |
2275 | java '("this") | |
2276 | pike '("this")) ;; Not really a keyword, but practically works as one. | |
130c507e | 2277 | |
a66cd3ee | 2278 | (c-lang-defconst c-expr-kwds |
d9e94c22 MS |
2279 | ;; Keywords that can occur anywhere in expressions. Built from |
2280 | ;; `c-primary-expr-kwds' and all keyword operators in `c-operators'. | |
2281 | t (delete-duplicates | |
2282 | (append (c-lang-const c-primary-expr-kwds) | |
0386b551 AM |
2283 | (c-filter-ops (c-lang-const c-operator-list) |
2284 | t | |
2285 | "\\`\\(\\w\\|\\s_\\)+\\'")) | |
d9e94c22 MS |
2286 | :test 'string-equal)) |
2287 | ||
2288 | (c-lang-defconst c-lambda-kwds | |
2289 | "Keywords that start lambda constructs, i.e. function definitions in | |
2290 | expressions." | |
2291 | t nil | |
2292 | pike '("lambda")) | |
a66cd3ee | 2293 | |
d9e94c22 MS |
2294 | (c-lang-defconst c-inexpr-block-kwds |
2295 | "Keywords that start constructs followed by statement blocks which can | |
2296 | be used in expressions \(the gcc extension for this in C and C++ is | |
0386b551 | 2297 | handled separately by `c-recognize-paren-inexpr-blocks')." |
d9e94c22 MS |
2298 | t nil |
2299 | pike '("catch" "gauge")) | |
a66cd3ee | 2300 | |
a66cd3ee | 2301 | (c-lang-defconst c-inexpr-class-kwds |
d9e94c22 MS |
2302 | "Keywords that can start classes inside expressions." |
2303 | t nil | |
a66cd3ee MS |
2304 | java '("new") |
2305 | pike '("class")) | |
2306 | ||
d9e94c22 MS |
2307 | (c-lang-defconst c-inexpr-brace-list-kwds |
2308 | "Keywords that can start brace list blocks inside expressions. | |
2309 | Note that Java specific rules are currently applied to tell this from | |
2310 | `c-inexpr-class-kwds'." | |
2311 | t nil | |
2312 | java '("new")) | |
2313 | ||
2314 | (c-lang-defconst c-opt-inexpr-brace-list-key | |
2315 | ;; Regexp matching the start of a brace list in an expression, or | |
2316 | ;; nil in languages that don't have such things. This should not | |
2317 | ;; match brace lists recognized through `c-special-brace-lists'. | |
2318 | t (and (c-lang-const c-inexpr-brace-list-kwds) | |
2319 | (c-make-keywords-re t (c-lang-const c-inexpr-brace-list-kwds)))) | |
2320 | (c-lang-defvar c-opt-inexpr-brace-list-key | |
2321 | (c-lang-const c-opt-inexpr-brace-list-key)) | |
a66cd3ee | 2322 | |
a66cd3ee | 2323 | (c-lang-defconst c-decl-block-key |
0386b551 AM |
2324 | ;; Regexp matching keywords in any construct that contain another |
2325 | ;; declaration level, i.e. that isn't followed by a function block | |
2326 | ;; or brace list. When the first submatch matches, it's an | |
2327 | ;; unambiguous construct, otherwise it's an ambiguous match that | |
2328 | ;; might also be the return type of a function declaration. | |
2329 | t (let* ((decl-kwds (append (c-lang-const c-class-decl-kwds) | |
2330 | (c-lang-const c-other-block-decl-kwds) | |
2331 | (c-lang-const c-inexpr-class-kwds))) | |
2332 | (unambiguous (set-difference decl-kwds | |
2333 | (c-lang-const c-type-start-kwds) | |
2334 | :test 'string-equal)) | |
2335 | (ambiguous (intersection decl-kwds | |
2336 | (c-lang-const c-type-start-kwds) | |
2337 | :test 'string-equal))) | |
2338 | (if ambiguous | |
2339 | (concat (c-make-keywords-re t unambiguous) | |
2340 | "\\|" | |
2341 | (c-make-keywords-re t ambiguous)) | |
2342 | (c-make-keywords-re t unambiguous)))) | |
d9e94c22 MS |
2343 | (c-lang-defvar c-decl-block-key (c-lang-const c-decl-block-key)) |
2344 | ||
a66cd3ee | 2345 | (c-lang-defconst c-bitfield-kwds |
d9e94c22 MS |
2346 | "Keywords that can introduce bitfields." |
2347 | t nil | |
2348 | (c c++ objc) '("char" "int" "long" "signed" "unsigned")) | |
a66cd3ee | 2349 | |
a66cd3ee | 2350 | (c-lang-defconst c-opt-bitfield-key |
d9e94c22 MS |
2351 | ;; Regexp matching the start of a bitfield (not uniquely), or nil in |
2352 | ;; languages without bitfield support. | |
2353 | t nil | |
2354 | (c c++) (c-make-keywords-re t (c-lang-const c-bitfield-kwds))) | |
2355 | (c-lang-defvar c-opt-bitfield-key (c-lang-const c-opt-bitfield-key)) | |
2356 | ||
2357 | (c-lang-defconst c-other-kwds | |
2358 | "Keywords not accounted for by any other `*-kwds' language constant." | |
2359 | t nil | |
2360 | idl '("truncatable" | |
2361 | ;; In CORBA CIDL: (These are declaration keywords that never | |
2362 | ;; can start a declaration.) | |
2363 | "entity" "process" "service" "session" "storage")) | |
2364 | ||
2365 | \f | |
2366 | ;;; Constants built from keywords. | |
2367 | ||
2368 | ;; Note: No `*-kwds' language constants may be defined below this point. | |
2369 | ||
2370 | (eval-and-compile | |
2371 | (defconst c-kwds-lang-consts | |
2372 | ;; List of all the language constants that contain keyword lists. | |
2373 | (let (list) | |
2374 | (mapatoms (lambda (sym) | |
2375 | (when (and (boundp sym) | |
2376 | (string-match "-kwds\\'" (symbol-name sym))) | |
2377 | ;; Make the list of globally interned symbols | |
2378 | ;; instead of ones interned in `c-lang-constants'. | |
2379 | (setq list (cons (intern (symbol-name sym)) list)))) | |
2380 | c-lang-constants) | |
2381 | list))) | |
a66cd3ee | 2382 | |
a66cd3ee | 2383 | (c-lang-defconst c-keywords |
d9e94c22 MS |
2384 | ;; All keywords as a list. |
2385 | t (delete-duplicates | |
2386 | (c-lang-defconst-eval-immediately | |
2387 | `(append ,@(mapcar (lambda (kwds-lang-const) | |
2388 | `(c-lang-const ,kwds-lang-const)) | |
2389 | c-kwds-lang-consts) | |
2390 | nil)) | |
2391 | :test 'string-equal)) | |
2392 | ||
a66cd3ee | 2393 | (c-lang-defconst c-keywords-regexp |
d9e94c22 MS |
2394 | ;; All keywords as an adorned regexp. |
2395 | t (c-make-keywords-re t (c-lang-const c-keywords))) | |
2396 | (c-lang-defvar c-keywords-regexp (c-lang-const c-keywords-regexp)) | |
2397 | ||
2398 | (c-lang-defconst c-keyword-member-alist | |
2399 | ;; An alist with all the keywords in the cars. The cdr for each | |
2400 | ;; keyword is a list of the symbols for the `*-kwds' lists that | |
2401 | ;; contains it. | |
2402 | t (let ((kwd-list-alist | |
2403 | (c-lang-defconst-eval-immediately | |
2404 | `(list ,@(mapcar (lambda (kwds-lang-const) | |
2405 | `(cons ',kwds-lang-const | |
2406 | (c-lang-const ,kwds-lang-const))) | |
2407 | c-kwds-lang-consts)))) | |
2408 | lang-const kwd-list kwd | |
2409 | result-alist elem) | |
2410 | (while kwd-list-alist | |
2411 | (setq lang-const (caar kwd-list-alist) | |
2412 | kwd-list (cdar kwd-list-alist) | |
2413 | kwd-list-alist (cdr kwd-list-alist)) | |
2414 | (while kwd-list | |
2415 | (setq kwd (car kwd-list) | |
2416 | kwd-list (cdr kwd-list)) | |
2417 | (unless (setq elem (assoc kwd result-alist)) | |
2418 | (setq result-alist (cons (setq elem (list kwd)) result-alist))) | |
2419 | (unless (memq lang-const (cdr elem)) | |
2420 | (setcdr elem (cons lang-const (cdr elem)))))) | |
2421 | result-alist)) | |
2422 | ||
2423 | (c-lang-defvar c-keywords-obarray | |
2424 | ;; An obarray containing all keywords as symbols. The property list | |
2425 | ;; of each symbol has a non-nil entry for the specific `*-kwds' | |
2426 | ;; lists it's a member of. | |
2427 | ;; | |
2428 | ;; E.g. to see whether the string str contains a keyword on | |
2429 | ;; `c-class-decl-kwds', one can do like this: | |
2430 | ;; (get (intern-soft str c-keyword-obarray) 'c-class-decl-kwds) | |
2431 | ;; Which preferably is written using the associated functions in | |
2432 | ;; cc-engine: | |
2433 | ;; (c-keyword-member (c-keyword-sym str) 'c-class-decl-kwds) | |
2434 | ||
2435 | ;; The obarray is not stored directly as a language constant since | |
2436 | ;; the printed representation for obarrays used in .elc files isn't | |
2437 | ;; complete. | |
2438 | ||
2439 | (let* ((alist (c-lang-const c-keyword-member-alist)) | |
2440 | kwd lang-const-list | |
2441 | (obarray (make-vector (* (length alist) 2) 0))) | |
2442 | (while alist | |
2443 | (setq kwd (caar alist) | |
2444 | lang-const-list (cdar alist) | |
2445 | alist (cdr alist)) | |
2446 | (setplist (intern kwd obarray) | |
2447 | ;; Emacs has an odd bug that causes `mapcan' to fail | |
0386b551 | 2448 | ;; with unintelligible errors. (XEmacs works.) |
d9e94c22 MS |
2449 | ;;(mapcan (lambda (lang-const) |
2450 | ;; (list lang-const t)) | |
2451 | ;; lang-const-list) | |
2452 | (apply 'nconc (mapcar (lambda (lang-const) | |
2453 | (list lang-const t)) | |
2454 | lang-const-list)))) | |
2455 | obarray)) | |
2456 | ||
2457 | (c-lang-defconst c-regular-keywords-regexp | |
0386b551 AM |
2458 | ;; Adorned regexp matching all keywords that should be fontified |
2459 | ;; with the keywords face. I.e. that aren't types or constants. | |
d9e94c22 MS |
2460 | t (c-make-keywords-re t |
2461 | (set-difference (c-lang-const c-keywords) | |
2462 | (append (c-lang-const c-primitive-type-kwds) | |
2463 | (c-lang-const c-constant-kwds)) | |
2464 | :test 'string-equal))) | |
2465 | (c-lang-defvar c-regular-keywords-regexp | |
2466 | (c-lang-const c-regular-keywords-regexp)) | |
2467 | ||
d9e94c22 MS |
2468 | (c-lang-defconst c-primary-expr-regexp |
2469 | ;; Regexp matching the start of any primary expression, i.e. any | |
2470 | ;; literal, symbol, prefix operator, and '('. It doesn't need to | |
2471 | ;; exclude keywords; they are excluded afterwards unless the second | |
2472 | ;; submatch matches. If the first but not the second submatch | |
2473 | ;; matches then it is an ambiguous primary expression; it could also | |
2474 | ;; be a match of e.g. an infix operator. (The case with ambiguous | |
2475 | ;; keyword operators isn't handled.) | |
2476 | ||
0386b551 AM |
2477 | t (let* ((prefix-ops |
2478 | (c-filter-ops (c-lang-const c-operators) | |
2479 | '(prefix) | |
2480 | (lambda (op) | |
2481 | ;; Filter out the special case prefix | |
2482 | ;; operators that are close parens. | |
2483 | (not (string-match "\\s)" op))))) | |
2484 | ||
2485 | (nonkeyword-prefix-ops | |
2486 | (c-filter-ops prefix-ops | |
2487 | t | |
2488 | "\\`\\(\\s.\\|\\s(\\|\\s)\\)+\\'")) | |
2489 | ||
2490 | (in-or-postfix-ops | |
2491 | (c-filter-ops (c-lang-const c-operators) | |
2492 | '(postfix | |
2493 | postfix-if-paren | |
2494 | left-assoc | |
2495 | right-assoc | |
2496 | right-assoc-sequence) | |
2497 | t)) | |
2498 | ||
2499 | (unambiguous-prefix-ops (set-difference nonkeyword-prefix-ops | |
2500 | in-or-postfix-ops | |
2501 | :test 'string-equal)) | |
2502 | (ambiguous-prefix-ops (intersection nonkeyword-prefix-ops | |
2503 | in-or-postfix-ops | |
2504 | :test 'string-equal))) | |
2505 | ||
2506 | (concat | |
2507 | "\\(" | |
2508 | ;; Take out all symbol class operators from `prefix-ops' and make the | |
2509 | ;; first submatch from them together with `c-primary-expr-kwds'. | |
2510 | (c-make-keywords-re t | |
2511 | (append (c-lang-const c-primary-expr-kwds) | |
2512 | (set-difference prefix-ops nonkeyword-prefix-ops | |
2513 | :test 'string-equal))) | |
2514 | ||
2515 | "\\|" | |
2516 | ;; Match all ambiguous operators. | |
2517 | (c-make-keywords-re nil | |
2518 | (intersection nonkeyword-prefix-ops in-or-postfix-ops | |
2519 | :test 'string-equal)) | |
2520 | "\\)" | |
d9e94c22 | 2521 | |
0386b551 AM |
2522 | "\\|" |
2523 | ;; Now match all other symbols. | |
2524 | (c-lang-const c-symbol-start) | |
d9e94c22 | 2525 | |
0386b551 AM |
2526 | "\\|" |
2527 | ;; The chars that can start integer and floating point | |
2528 | ;; constants. | |
2529 | "\\.?[0-9]" | |
d9e94c22 | 2530 | |
0386b551 | 2531 | "\\|" |
e1dbe924 | 2532 | ;; The unambiguous operators from `prefix-ops'. |
0386b551 AM |
2533 | (c-make-keywords-re nil |
2534 | (set-difference nonkeyword-prefix-ops in-or-postfix-ops | |
2535 | :test 'string-equal)) | |
d9e94c22 | 2536 | |
0386b551 AM |
2537 | "\\|" |
2538 | ;; Match string and character literals. | |
2539 | "\\s\"" | |
2540 | (if (memq 'gen-string-delim c-emacs-features) | |
2541 | "\\|\\s|" | |
2542 | "")))) | |
d9e94c22 | 2543 | (c-lang-defvar c-primary-expr-regexp (c-lang-const c-primary-expr-regexp)) |
a66cd3ee | 2544 | |
d9e94c22 MS |
2545 | \f |
2546 | ;;; Additional constants for parser-level constructs. | |
2547 | ||
2548 | (c-lang-defconst c-decl-prefix-re | |
0386b551 AM |
2549 | "Regexp matching something that might precede a declaration, cast or |
2550 | label, such as the last token of a preceding statement or declaration. | |
2551 | This is used in the common situation where a declaration or cast | |
2552 | doesn't start with any specific token that can be searched for. | |
2553 | ||
2554 | The regexp should not match bob; that is done implicitly. It can't | |
2555 | require a match longer than one token. The end of the token is taken | |
2556 | to be at the end of the first submatch, which is assumed to always | |
2557 | match. It's undefined whether identifier syntax (see | |
2558 | `c-identifier-syntax-table') is in effect or not. This regexp is | |
2559 | assumed to be a superset of `c-label-prefix-re' if | |
2560 | `c-recognize-colon-labels' is set. | |
2561 | ||
2562 | Besides this, `c-decl-start-kwds' is used to find declarations. | |
2563 | ||
2564 | Note: This variable together with `c-decl-start-re' and | |
2565 | `c-decl-start-kwds' is only used to detect \"likely\" | |
2566 | declaration/cast/label starts. I.e. they might produce more matches | |
2567 | but should not miss anything (or else it's necessary to use text | |
2568 | properties - see the next note). Wherever they match, the following | |
2569 | construct is analyzed to see if it indeed is a declaration, cast or | |
2570 | label. That analysis is not cheap, so it's important that not too | |
2571 | many false matches are triggered. | |
2572 | ||
2573 | Note: If a declaration/cast/label start can't be detected with this | |
2574 | variable, it's necessary to use the `c-type' text property with the | |
2575 | value `c-decl-end' on the last char of the last token preceding the | |
2576 | declaration. See the comment blurb at the start of cc-engine.el for | |
2577 | more info." | |
2578 | ||
d9e94c22 MS |
2579 | ;; We match a sequence of characters to skip over things like \"};\" |
2580 | ;; more quickly. We match ")" in C for K&R region declarations, and | |
2581 | ;; in all languages except Java for when a cpp macro definition | |
2582 | ;; begins with a declaration. | |
2583 | t "\\([\{\}\(\);,]+\\)" | |
452ea855 | 2584 | java "\\([\{\}\(;,<]+\\)" |
d9e94c22 MS |
2585 | ;; Match "<" in C++ to get the first argument in a template arglist. |
2586 | ;; In that case there's an additional check in `c-find-decl-spots' | |
2587 | ;; that it got open paren syntax. | |
0386b551 | 2588 | c++ "\\([\{\}\(\);,<]+\\)" |
d9e94c22 MS |
2589 | ;; Additionally match the protection directives in Objective-C. |
2590 | ;; Note that this doesn't cope with the longer directives, which we | |
2591 | ;; would have to match from start to end since they don't end with | |
2592 | ;; any easily recognized characters. | |
2593 | objc (concat "\\([\{\}\(\);,]+\\|" | |
2594 | (c-make-keywords-re nil (c-lang-const c-protection-kwds)) | |
2595 | "\\)") | |
d9e94c22 MS |
2596 | ;; Pike is like C but we also match "[" for multiple value |
2597 | ;; assignments and type casts. | |
2598 | pike "\\([\{\}\(\)\[;,]+\\)") | |
2599 | (c-lang-defvar c-decl-prefix-re (c-lang-const c-decl-prefix-re) | |
2600 | 'dont-doc) | |
2601 | ||
0386b551 AM |
2602 | (c-lang-defconst c-decl-start-re |
2603 | "Regexp matching the start of any declaration, cast or label. | |
2604 | It's used on the token after the one `c-decl-prefix-re' matched. This | |
2605 | regexp should not try to match those constructs accurately as it's | |
2606 | only used as a sieve to avoid spending more time checking other | |
2607 | constructs." | |
2608 | t (c-lang-const c-identifier-start)) | |
2609 | (c-lang-defvar c-decl-start-re (c-lang-const c-decl-start-re)) | |
2610 | ||
2611 | (c-lang-defconst c-decl-prefix-or-start-re | |
2612 | ;; Regexp matching something that might precede or start a | |
2613 | ;; declaration, cast or label. | |
2614 | ;; | |
2615 | ;; If the first submatch matches, it's taken to match the end of a | |
2616 | ;; token that might precede such a construct, e.g. ';', '}' or '{'. | |
2617 | ;; It's built from `c-decl-prefix-re'. | |
2618 | ;; | |
2619 | ;; If the first submatch did not match, the match of the whole | |
2620 | ;; regexp is taken to be at the first token in the declaration. | |
2621 | ;; `c-decl-start-re' is not checked in this case. | |
2622 | ;; | |
2623 | ;; Design note: The reason the same regexp is used to match both | |
2624 | ;; tokens that precede declarations and start them is to avoid an | |
2625 | ;; extra regexp search from the previous declaration spot in | |
2626 | ;; `c-find-decl-spots'. Users of `c-find-decl-spots' also count on | |
2627 | ;; that it finds all declaration/cast/label starts in approximately | |
2628 | ;; linear order, so we can't do the searches in two separate passes. | |
2629 | t (if (c-lang-const c-decl-start-kwds) | |
2630 | (concat (c-lang-const c-decl-prefix-re) | |
2631 | "\\|" | |
2632 | (c-make-keywords-re t (c-lang-const c-decl-start-kwds))) | |
2633 | (c-lang-const c-decl-prefix-re))) | |
2634 | (c-lang-defvar c-decl-prefix-or-start-re | |
2635 | (c-lang-const c-decl-prefix-or-start-re) | |
2636 | 'dont-doc) | |
2637 | ||
d9e94c22 MS |
2638 | (c-lang-defconst c-cast-parens |
2639 | ;; List containing the paren characters that can open a cast, or nil in | |
2640 | ;; languages without casts. | |
0386b551 AM |
2641 | t (c-filter-ops (c-lang-const c-operators) |
2642 | '(prefix) | |
2643 | "\\`\\s\(\\'" | |
2644 | (lambda (op) (elt op 0)))) | |
d9e94c22 MS |
2645 | (c-lang-defvar c-cast-parens (c-lang-const c-cast-parens)) |
2646 | ||
0386b551 AM |
2647 | (c-lang-defconst c-block-prefix-disallowed-chars |
2648 | "List of syntactically relevant characters that never can occur before | |
2649 | the open brace in any construct that contains a brace block, e.g. in | |
2650 | the \"class Foo: public Bar\" part of: | |
2651 | ||
2652 | class Foo: public Bar {int x();} a, *b; | |
2653 | ||
2654 | If parens can occur, the chars inside those aren't filtered with this | |
2655 | list. | |
2656 | ||
2657 | '<' and '>' should be disallowed even if angle bracket arglists can | |
2658 | occur. That since the search function needs to stop at them anyway to | |
2659 | ensure they are given paren syntax. | |
2660 | ||
2661 | This is used to skip backward from the open brace to find the region | |
2662 | in which to look for a construct like \"class\", \"enum\", | |
2663 | \"namespace\" or whatever. That skipping should be as tight as | |
2664 | possible for good performance." | |
2665 | ||
2666 | ;; Default to all chars that only occurs in nonsymbol tokens outside | |
2667 | ;; identifiers. | |
2668 | t (set-difference | |
2669 | (c-lang-const c-nonsymbol-token-char-list) | |
2670 | (c-filter-ops (append (c-lang-const c-identifier-ops) | |
2671 | (list (cons nil | |
2672 | (c-lang-const c-after-id-concat-ops)))) | |
2673 | t | |
2674 | t | |
2675 | (lambda (op) | |
2676 | (let ((pos 0) res) | |
2677 | (while (string-match "\\(\\s.\\|\\s(\\|\\s)\\)" | |
2678 | op pos) | |
2679 | (setq res (cons (aref op (match-beginning 1)) res) | |
2680 | pos (match-end 0))) | |
2681 | res)))) | |
2682 | ||
e1dbe924 | 2683 | ;; Allow cpp operations (where applicable). |
0386b551 AM |
2684 | t (if (c-lang-const c-opt-cpp-prefix) |
2685 | (set-difference (c-lang-const c-block-prefix-disallowed-chars) | |
2686 | '(?#)) | |
2687 | (c-lang-const c-block-prefix-disallowed-chars)) | |
2688 | ||
2689 | ;; Allow ':' for inherit list starters. | |
2690 | (c++ objc idl) (set-difference (c-lang-const c-block-prefix-disallowed-chars) | |
2691 | '(?:)) | |
2692 | ||
2693 | ;; Allow ',' for multiple inherits. | |
2694 | (c++ java) (set-difference (c-lang-const c-block-prefix-disallowed-chars) | |
2695 | '(?,)) | |
2696 | ||
2697 | ;; Allow parentheses for anonymous inner classes in Java and class | |
2698 | ;; initializer lists in Pike. | |
2699 | (java pike) (set-difference (c-lang-const c-block-prefix-disallowed-chars) | |
2700 | '(?\( ?\))) | |
2701 | ||
2702 | ;; Allow '"' for extern clauses (e.g. extern "C" {...}). | |
2703 | (c c++ objc) (set-difference (c-lang-const c-block-prefix-disallowed-chars) | |
2704 | '(?\" ?'))) | |
2705 | ||
2706 | (c-lang-defconst c-block-prefix-charset | |
2707 | ;; `c-block-prefix-disallowed-chars' as an inverted charset suitable | |
2708 | ;; for `c-syntactic-skip-backward'. | |
2709 | t (c-make-bare-char-alt (c-lang-const c-block-prefix-disallowed-chars) t)) | |
2710 | (c-lang-defvar c-block-prefix-charset (c-lang-const c-block-prefix-charset)) | |
2711 | ||
d9e94c22 | 2712 | (c-lang-defconst c-type-decl-prefix-key |
0386b551 AM |
2713 | "Regexp matching the declarator operators that might precede the |
2714 | identifier in a declaration, e.g. the \"*\" in \"char *argv\". This | |
2715 | regexp should match \"(\" if parentheses are valid in declarators. | |
2716 | The end of the first submatch is taken as the end of the operator. | |
2717 | Identifier syntax is in effect when this is matched \(see | |
2718 | `c-identifier-syntax-table')." | |
d9e94c22 | 2719 | t (if (c-lang-const c-type-modifier-kwds) |
0386b551 | 2720 | (concat (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>") |
d9e94c22 MS |
2721 | ;; Default to a regexp that never matches. |
2722 | "\\<\\>") | |
0386b551 AM |
2723 | ;; Check that there's no "=" afterwards to avoid matching tokens |
2724 | ;; like "*=". | |
d9e94c22 MS |
2725 | (c objc) (concat "\\(" |
2726 | "[*\(]" | |
2727 | "\\|" | |
2728 | (c-lang-const c-type-decl-prefix-key) | |
2729 | "\\)" | |
2730 | "\\([^=]\\|$\\)") | |
2731 | c++ (concat "\\(" | |
2732 | "[*\(&]" | |
2733 | "\\|" | |
7f0789c9 AM |
2734 | (c-lang-const c-type-decl-prefix-key) |
2735 | "\\|" | |
2736 | (concat "\\(" ; 3 | |
d9e94c22 MS |
2737 | ;; If this matches there's special treatment in |
2738 | ;; `c-font-lock-declarators' and | |
2739 | ;; `c-font-lock-declarations' that check for a | |
2740 | ;; complete name followed by ":: *". | |
2741 | (c-lang-const c-identifier-start) | |
2742 | "\\)") | |
d9e94c22 MS |
2743 | "\\)" |
2744 | "\\([^=]\\|$\\)") | |
0386b551 | 2745 | pike "\\(\\*\\)\\([^=]\\|$\\)") |
d9e94c22 MS |
2746 | (c-lang-defvar c-type-decl-prefix-key (c-lang-const c-type-decl-prefix-key) |
2747 | 'dont-doc) | |
2748 | ||
2749 | (c-lang-defconst c-type-decl-suffix-key | |
0386b551 AM |
2750 | "Regexp matching the declarator operators that might follow after the |
2751 | identifier in a declaration, e.g. the \"[\" in \"char argv[]\". This | |
2752 | regexp should match \")\" if parentheses are valid in declarators. If | |
d9e94c22 MS |
2753 | it matches an open paren of some kind, the type declaration check |
2754 | continues at the corresponding close paren, otherwise the end of the | |
2755 | first submatch is taken as the end of the operator. Identifier syntax | |
2756 | is in effect when this is matched (see `c-identifier-syntax-table')." | |
2757 | ;; Default to a regexp that matches `c-type-modifier-kwds' and a | |
2758 | ;; function argument list parenthesis. | |
2759 | t (if (c-lang-const c-type-modifier-kwds) | |
2760 | (concat "\\(\(\\|" | |
0386b551 | 2761 | (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>" |
d9e94c22 MS |
2762 | "\\)") |
2763 | "\\(\(\\)") | |
2764 | (c c++ objc) (concat | |
2765 | "\\(" | |
2766 | "[\)\[\(]" | |
0386b551 AM |
2767 | (if (c-lang-const c-type-modifier-kwds) |
2768 | (concat | |
2769 | "\\|" | |
2770 | ;; "throw" in `c-type-modifier-kwds' is followed | |
2771 | ;; by a parenthesis list, but no extra measures | |
2772 | ;; are necessary to handle that. | |
2773 | (regexp-opt (c-lang-const c-type-modifier-kwds) t) | |
2774 | "\\>") | |
2775 | "") | |
d9e94c22 MS |
2776 | "\\)") |
2777 | (java idl) "\\([\[\(]\\)") | |
2778 | (c-lang-defvar c-type-decl-suffix-key (c-lang-const c-type-decl-suffix-key) | |
2779 | 'dont-doc) | |
2780 | ||
2781 | (c-lang-defconst c-after-suffixed-type-decl-key | |
0386b551 | 2782 | "This regexp is matched after a declarator expression where |
d9e94c22 MS |
2783 | `c-type-decl-suffix-key' has matched. If it matches then the |
2784 | construct is taken as a declaration. It's typically used to match the | |
2785 | beginning of a function body or whatever might occur after the | |
2786 | function header in a function declaration or definition. It's | |
2787 | undefined whether identifier syntax (see `c-identifier-syntax-table') | |
2788 | is in effect or not. | |
2789 | ||
2790 | Note that it's used in cases like after \"foo (bar)\" so it should | |
2791 | only match when it's certain that it's a declaration, e.g \"{\" but | |
2792 | not \",\" or \";\"." | |
2793 | t "{" | |
2794 | ;; If K&R style declarations should be recognized then one could | |
2795 | ;; consider to match the start of any symbol since we want to match | |
2796 | ;; the start of the first declaration in the "K&R region". That | |
2797 | ;; could however produce false matches on code like "FOO(bar) x" | |
2798 | ;; where FOO is a cpp macro, so it's better to leave it out and rely | |
2799 | ;; on the other heuristics in that case. | |
0386b551 AM |
2800 | t (if (c-lang-const c-postfix-spec-kwds) |
2801 | ;; Add on the keywords in `c-postfix-spec-kwds'. | |
d9e94c22 MS |
2802 | (concat (c-lang-const c-after-suffixed-type-decl-key) |
2803 | "\\|" | |
0386b551 | 2804 | (c-make-keywords-re t (c-lang-const c-postfix-spec-kwds))) |
d9e94c22 MS |
2805 | (c-lang-const c-after-suffixed-type-decl-key)) |
2806 | ;; Also match the colon that starts a base class initializer list in | |
2807 | ;; C++. That can be confused with a function call before the colon | |
2808 | ;; in a ? : operator, but we count on that `c-decl-prefix-re' won't | |
2809 | ;; match before such a thing (as a declaration-level construct; | |
2810 | ;; matches inside arglist contexts are already excluded). | |
2811 | c++ "[{:]") | |
2812 | (c-lang-defvar c-after-suffixed-type-decl-key | |
2813 | (c-lang-const c-after-suffixed-type-decl-key) | |
2814 | 'dont-doc) | |
2815 | ||
2816 | (c-lang-defconst c-after-suffixed-type-maybe-decl-key | |
2817 | ;; Regexp that in addition to `c-after-suffixed-type-decl-key' | |
2818 | ;; matches ";" and ",". | |
2819 | t (concat "\\(" (c-lang-const c-after-suffixed-type-decl-key) "\\)" | |
2820 | "\\|[;,]")) | |
2821 | (c-lang-defvar c-after-suffixed-type-maybe-decl-key | |
2822 | (c-lang-const c-after-suffixed-type-maybe-decl-key)) | |
2823 | ||
2824 | (c-lang-defconst c-opt-type-concat-key | |
2825 | "Regexp matching operators that concatenate types, e.g. the \"|\" in | |
2826 | \"int|string\" in Pike. The end of the first submatch is taken as the | |
2827 | end of the operator. nil in languages without such operators. It's | |
2828 | undefined whether identifier syntax (see `c-identifier-syntax-table') | |
2829 | is in effect or not." | |
2830 | t nil | |
2831 | pike "\\([|.&]\\)\\($\\|[^|.&]\\)") | |
2832 | (c-lang-defvar c-opt-type-concat-key (c-lang-const c-opt-type-concat-key) | |
2833 | 'dont-doc) | |
2834 | ||
2835 | (c-lang-defconst c-opt-type-suffix-key | |
2836 | "Regexp matching operators that might follow after a type, or nil in | |
2837 | languages that don't have such operators. The end of the first | |
2838 | submatch is taken as the end of the operator. This should not match | |
2839 | things like C++ template arglists if `c-recognize-<>-arglists' is set. | |
2840 | It's undefined whether identifier syntax (see `c-identifier-syntax-table') | |
2841 | is in effect or not." | |
2842 | t nil | |
2843 | (c c++ objc pike) "\\(\\.\\.\\.\\)" | |
452ea855 | 2844 | java (concat "\\(\\[" (c-lang-const c-simple-ws) "*\\]\\|\\.\\.\\.\\)")) |
d9e94c22 MS |
2845 | (c-lang-defvar c-opt-type-suffix-key (c-lang-const c-opt-type-suffix-key)) |
2846 | ||
2847 | (c-lang-defvar c-known-type-key | |
2848 | ;; Regexp matching the known type identifiers. This is initialized | |
2849 | ;; from the type keywords and `*-font-lock-extra-types'. The first | |
2850 | ;; submatch is the one that matches the type. Note that this regexp | |
2851 | ;; assumes that symbol constituents like '_' and '$' have word | |
2852 | ;; syntax. | |
0386b551 AM |
2853 | (let* ((extra-types |
2854 | (when (boundp (c-mode-symbol "font-lock-extra-types")) | |
2855 | (c-mode-var "font-lock-extra-types"))) | |
2856 | (regexp-strings | |
6faed041 AM |
2857 | (apply 'nconc |
2858 | (mapcar (lambda (re) | |
0386b551 AM |
2859 | (when (string-match "[][.*+?^$\\]" re) |
2860 | (list re))) | |
6faed041 | 2861 | extra-types))) |
0386b551 | 2862 | (plain-strings |
6faed041 AM |
2863 | (apply 'nconc |
2864 | (mapcar (lambda (re) | |
0386b551 AM |
2865 | (unless (string-match "[][.*+?^$\\]" re) |
2866 | (list re))) | |
6faed041 | 2867 | extra-types)))) |
d9e94c22 | 2868 | (concat "\\<\\(" |
0386b551 AM |
2869 | (c-concat-separated |
2870 | (append (list (c-make-keywords-re nil | |
2871 | (append (c-lang-const c-primitive-type-kwds) | |
2872 | plain-strings))) | |
2873 | regexp-strings) | |
2874 | "\\|") | |
d9e94c22 MS |
2875 | "\\)\\>"))) |
2876 | ||
2877 | (c-lang-defconst c-special-brace-lists | |
2878 | "List of open- and close-chars that makes up a pike-style brace list, | |
2879 |