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