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