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