Partially correct fontification of "(b*3)", and the like, in C++ Mode
[emacs.git] / lisp / progmodes / cc-langs.el
blob83b8db3657e572776461890fb3fa4f8f96cafce0
1 ;;; cc-langs.el --- language specific settings for CC Mode -*- coding: utf-8 -*-
3 ;; Copyright (C) 1985, 1987, 1992-2016 Free Software Foundation, Inc.
5 ;; Authors: 2002- Alan Mackenzie
6 ;; 1998- Martin Stjernholm
7 ;; 1992-1999 Barry A. Warsaw
8 ;; 1987 Dave Detlefs
9 ;; 1987 Stewart Clamen
10 ;; 1985 Richard M. Stallman
11 ;; Maintainer: bug-cc-mode@gnu.org
12 ;; Created: 22-Apr-1997 (split from cc-mode.el)
13 ;; Keywords: c languages
14 ;; Package: cc-mode
16 ;; This file is part of GNU Emacs.
18 ;; GNU Emacs is free software: you can redistribute it and/or modify
19 ;; it under the terms of the GNU General Public License as published by
20 ;; the Free Software Foundation, either version 3 of the License, or
21 ;; (at your option) any later version.
23 ;; GNU Emacs is distributed in the hope that it will be useful,
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 ;; GNU General Public License for more details.
28 ;; You should have received a copy of the GNU General Public License
29 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
31 ;;; Commentary:
33 ;; HACKERS NOTE: There's heavy macro magic here. If you need to make
34 ;; changes in this or other files containing `c-lang-defconst' but
35 ;; don't want to read through the longer discussion below then read
36 ;; this:
38 ;; o A change in a `c-lang-defconst' or `c-lang-defvar' will not take
39 ;; effect if the file containing the mode init function (typically
40 ;; cc-mode.el) is byte compiled.
41 ;; o To make changes show in font locking you need to reevaluate the
42 ;; `*-font-lock-keywords-*' constants, which normally is easiest to
43 ;; do with M-x eval-buffer in cc-fonts.el.
44 ;; o In either case it's necessary to reinitialize the mode to make
45 ;; the changes show in an existing buffer.
47 ;;; Introduction to the language dependent variable system:
49 ;; This file contains all the language dependent variables, except
50 ;; those specific for font locking which reside in cc-fonts.el. As
51 ;; far as possible, all the differences between the languages that CC
52 ;; Mode supports are described with these variables only, so that the
53 ;; code can be shared.
55 ;; The language constant system (see cc-defs.el) is used to specify
56 ;; various language dependent info at a high level, such as lists of
57 ;; keywords, and then from them generate - at compile time - the
58 ;; various regexps and other low-level structures actually employed in
59 ;; the code at runtime.
61 ;; This system is also designed to make it easy for developers of
62 ;; derived modes to customize the source constants for new language
63 ;; variants, without having to keep up with the exact regexps etc that
64 ;; are used in each CC Mode version. It's possible from an external
65 ;; package to add a new language by inheriting an existing one, and
66 ;; then change specific constants as necessary for the new language.
67 ;; The old values for those constants (and the values of all the other
68 ;; high-level constants) may be used to build the new ones, and those
69 ;; new values will in turn be used by the low-level definitions here
70 ;; to build the runtime constants appropriately for the new language
71 ;; in the current version of CC Mode.
73 ;; Like elsewhere in CC Mode, the existence of a doc string signifies
74 ;; that a language constant is part of the external API, and that it
75 ;; therefore can be used with a high confidence that it will continue
76 ;; to work with future versions of CC Mode. Even so, it's not
77 ;; unlikely that such constants will change meaning slightly as this
78 ;; system is refined further; a certain degree of dependence on the CC
79 ;; Mode version is unavoidable when hooking in at this level. Also
80 ;; note that there's still work to be done to actually use these
81 ;; constants everywhere inside CC Mode; there are still hardcoded
82 ;; values in many places in the code.
84 ;; Separate packages will also benefit from the compile time
85 ;; evaluation; the byte compiled file(s) for them will contain the
86 ;; compiled runtime constants ready for use by (the byte compiled) CC
87 ;; Mode, and the source definitions in this file don't have to be
88 ;; loaded then. However, if a byte compiled package is loaded that
89 ;; has been compiled with a different version of CC Mode than the one
90 ;; currently loaded, then the compiled-in values will be discarded and
91 ;; new ones will be built when the mode is initialized. That will
92 ;; automatically trig a load of the file(s) containing the source
93 ;; definitions (i.e. this file and/or cc-fonts.el) if necessary.
95 ;; A small example of a derived mode is available at
96 ;; <http://cc-mode.sourceforge.net/derived-mode-ex.el>. It also
97 ;; contains some useful hints for derived mode developers.
99 ;;; Using language variables:
101 ;; The `c-lang-defvar' forms in this file comprise the language
102 ;; variables that CC Mode uses. It does not work to use
103 ;; `c-lang-defvar' anywhere else (which isn't much of a limitation
104 ;; since these variables sole purpose is to interface with the CC Mode
105 ;; core functions). The values in these `c-lang-defvar's are not
106 ;; evaluated right away but instead collected to a single large `setq'
107 ;; that can be inserted for a particular language with the
108 ;; `c-init-language-vars' macro.
110 ;; This file is only required at compile time, or when not running
111 ;; from byte compiled files, or when the source definitions for the
112 ;; language constants are requested.
114 ;;; Code:
116 ;; For Emacs < 22.2.
117 (eval-and-compile
118 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
120 (eval-when-compile
121 (let ((load-path
122 (if (and (boundp 'byte-compile-dest-file)
123 (stringp byte-compile-dest-file))
124 (cons (file-name-directory byte-compile-dest-file) load-path)
125 load-path)))
126 (load "cc-bytecomp" nil t)))
128 (cc-require 'cc-defs)
129 (cc-require 'cc-vars)
132 ;; This file is not always loaded. See note above.
133 (cc-external-require (if (eq c--mapcan-status 'cl-mapcan) 'cl-lib 'cl))
136 ;;; Setup for the `c-lang-defvar' system.
138 (eval-and-compile
139 ;; These are used to collect the init forms from the subsequent
140 ;; `c-lang-defvar' and `c-lang-setvar'. They are used to build the
141 ;; lambda in `c-make-init-lang-vars-fun' below, and to build `defvar's
142 ;; and `make-variable-buffer-local's in cc-engine and
143 ;; `make-local-variable's in `c-init-language-vars-for'.
144 (defvar c-lang-variable-inits nil)
145 (defvar c-lang-variable-inits-tail nil)
146 (setq c-lang-variable-inits (list nil)
147 c-lang-variable-inits-tail c-lang-variable-inits)
148 (defvar c-emacs-variable-inits nil)
149 (defvar c-emacs-variable-inits-tail nil)
150 (setq c-emacs-variable-inits (list nil)
151 c-emacs-variable-inits-tail c-emacs-variable-inits))
153 (defmacro c-lang-defvar (var val &optional doc)
154 "Declares the buffer local variable VAR to get the value VAL. VAL is
155 evaluated and assigned at mode initialization. More precisely, VAL is
156 evaluated and bound to VAR when the result from the macro
157 `c-init-language-vars' is evaluated.
159 `c-lang-const' is typically used in VAL to get the right value for the
160 language being initialized, and such calls will be macro expanded to
161 the evaluated constant value at compile time."
163 (when (and (not doc)
164 (eq (car-safe val) 'c-lang-const)
165 (eq (nth 1 val) var)
166 (not (nth 2 val)))
167 ;; Special case: If there's no docstring and the value is a
168 ;; simple (c-lang-const foo) where foo is the same name as VAR
169 ;; then take the docstring from the language constant foo.
170 (setq doc (get (intern (symbol-name (nth 1 val)) c-lang-constants)
171 'variable-documentation)))
172 (or (stringp doc)
173 (setq doc nil))
175 (let ((elem (assq var (cdr c-lang-variable-inits))))
176 (if elem
177 (setcdr elem (list val doc))
178 (setcdr c-lang-variable-inits-tail (list (list var val doc)))
179 (setq c-lang-variable-inits-tail (cdr c-lang-variable-inits-tail))))
181 ;; Return the symbol, like the other def* forms.
182 `',var)
184 (defmacro c-lang-setvar (var val)
185 "Causes the variable VAR to be made buffer local and to get set to the
186 value VAL. VAL is evaluated and assigned at mode initialization. More
187 precisely, VAL is evaluated and bound to VAR when the result from the
188 macro `c-init-language-vars' is evaluated. VAR is typically a standard
189 Emacs variable like `comment-start'.
191 `c-lang-const' is typically used in VAL to get the right value for the
192 language being initialized, and such calls will be macro expanded to
193 the evaluated constant value at compile time."
194 (let ((elem (assq var (cdr c-emacs-variable-inits))))
195 (if elem
196 (setcdr elem (list val)) ; Maybe remove "list", sometime. 2006-07-19
197 (setcdr c-emacs-variable-inits-tail (list (list var val)))
198 (setq c-emacs-variable-inits-tail (cdr c-emacs-variable-inits-tail))))
200 ;; Return the symbol, like the other def* forms.
201 `',var)
203 (put 'c-lang-defvar 'lisp-indent-function 'defun)
204 ; (eval-after-load "edebug" ; 2006-07-09: def-edebug-spec is now in subr.el.
206 (def-edebug-spec c-lang-defvar
207 (&define name def-form &optional stringp)) ;)
209 ;; Suppress "might not be defined at runtime" warning.
210 ;; This file is only used when compiling other cc files.
211 ;; These are defined in cl as aliases to the cl- versions.
212 ;(declare-function delete-duplicates "cl-seq" (cl-seq &rest cl-keys) t)
213 ;(declare-function mapcan "cl-extra" (cl-func cl-seq &rest cl-rest) t)
215 (eval-and-compile
216 ;; Some helper functions used when building the language constants.
218 (defun c-filter-ops (ops opgroup-filter op-filter &optional xlate)
219 ;; Extract a subset of the operators in the list OPS in a DWIM:ey
220 ;; way. The return value is a plain list of operators:
222 ;; OPS either has the structure of `c-operators', is a single
223 ;; group in `c-operators', or is a plain list of operators.
225 ;; OPGROUP-FILTER specifies how to select the operator groups. It
226 ;; can be t to choose all groups, a list of group type symbols
227 ;; (such as 'prefix) to accept, or a function which will be called
228 ;; with the group symbol for each group and should return non-nil
229 ;; if that group is to be included.
231 ;; OP-FILTER selects the operators. It is either t to select all
232 ;; operators, a string to select all operators for which `string-match'
233 ;; matches the operator with the string, or a function which will be
234 ;; called with the operator and should return non-nil when the operator
235 ;; is to be selected.
237 ;; If XLATE is given, it's a function which is called for each
238 ;; matching operator and its return value is collected instead.
239 ;; If it returns a list, the elements are spliced directly into
240 ;; the final result, which is returned as a list with duplicates
241 ;; removed using `equal'.
243 ;; `c-mode-syntax-table' for the current mode is in effect during
244 ;; the whole procedure.
245 (unless (listp (car-safe ops))
246 (setq ops (list ops)))
247 (cond ((eq opgroup-filter t)
248 (setq opgroup-filter (lambda (opgroup) t)))
249 ((not (functionp opgroup-filter))
250 (setq opgroup-filter `(lambda (opgroup)
251 (memq opgroup ',opgroup-filter)))))
252 (cond ((eq op-filter t)
253 (setq op-filter (lambda (op) t)))
254 ((stringp op-filter)
255 (setq op-filter `(lambda (op)
256 (string-match ,op-filter op)))))
257 (unless xlate
258 (setq xlate 'identity))
259 (c-with-syntax-table (c-lang-const c-mode-syntax-table)
260 (c--delete-duplicates
261 (c--mapcan (lambda (opgroup)
262 (when (if (symbolp (car opgroup))
263 (when (funcall opgroup-filter (car opgroup))
264 (setq opgroup (cdr opgroup))
267 (c--mapcan (lambda (op)
268 (when (funcall op-filter op)
269 (let ((res (funcall xlate op)))
270 (if (listp res) res (list res)))))
271 opgroup)))
272 ops)
273 :test 'equal))))
276 ;;; Various mode specific values that aren't language related.
278 (c-lang-defconst c-mode-menu
279 ;; The definition for the mode menu. The menu title is prepended to
280 ;; this before it's fed to `easy-menu-define'.
281 t `(["Comment Out Region" comment-region
282 (c-fn-region-is-active-p)]
283 ["Uncomment Region" (comment-region (region-beginning)
284 (region-end) '(4))
285 (c-fn-region-is-active-p)]
286 ["Indent Expression" c-indent-exp
287 (memq (char-after) '(?\( ?\[ ?\{))]
288 ["Indent Line or Region" c-indent-line-or-region t]
289 ["Fill Comment Paragraph" c-fill-paragraph t]
290 "----"
291 ["Backward Statement" c-beginning-of-statement t]
292 ["Forward Statement" c-end-of-statement t]
293 ,@(when (c-lang-const c-opt-cpp-prefix)
294 ;; Only applicable if there's a cpp preprocessor.
295 `(["Up Conditional" c-up-conditional t]
296 ["Backward Conditional" c-backward-conditional t]
297 ["Forward Conditional" c-forward-conditional t]
298 "----"
299 ["Macro Expand Region" c-macro-expand
300 (c-fn-region-is-active-p)]
301 ["Backslashify" c-backslash-region
302 (c-fn-region-is-active-p)]))
303 "----"
304 ("Style..."
305 ["Set Style..." c-set-style t]
306 ["Show Current Style Name" (message
307 "Style Name: %s"
308 c-indentation-style)
310 ["Guess Style from this Buffer" c-guess-buffer-no-install t]
311 ["Install the Last Guessed Style..." c-guess-install
312 (and c-guess-guessed-offsets-alist
313 c-guess-guessed-basic-offset) ]
314 ["View the Last Guessed Style" c-guess-view
315 (and c-guess-guessed-offsets-alist
316 c-guess-guessed-basic-offset) ])
317 "----"
318 ("Toggle..."
319 ["Syntactic indentation" c-toggle-syntactic-indentation
320 :style toggle :selected c-syntactic-indentation]
321 ["Electric mode" c-toggle-electric-state
322 :style toggle :selected c-electric-flag]
323 ["Auto newline" c-toggle-auto-newline
324 :style toggle :selected c-auto-newline]
325 ["Hungry delete" c-toggle-hungry-state
326 :style toggle :selected c-hungry-delete-key]
327 ["Subword mode" c-subword-mode
328 :style toggle :selected (and (boundp 'c-subword-mode)
329 c-subword-mode)])))
332 ;;; Syntax tables.
334 (defun c-populate-syntax-table (table)
335 "Populate the given syntax table as necessary for a C-like language.
336 This includes setting \\=' and \" as string delimiters, and setting up
337 the comment syntax to handle both line style \"//\" and block style
338 \"/*\" \"*/\" comments."
340 (modify-syntax-entry ?_ "_" table)
341 (modify-syntax-entry ?\\ "\\" table)
342 (modify-syntax-entry ?+ "." table)
343 (modify-syntax-entry ?- "." table)
344 (modify-syntax-entry ?= "." table)
345 (modify-syntax-entry ?% "." table)
346 (modify-syntax-entry ?< "." table)
347 (modify-syntax-entry ?> "." table)
348 (modify-syntax-entry ?& "." table)
349 (modify-syntax-entry ?| "." table)
350 (modify-syntax-entry ?\' "\"" table)
351 (modify-syntax-entry ?\240 "." table)
353 ;; Set up block and line oriented comments. The new C
354 ;; standard mandates both comment styles even in C, so since
355 ;; all languages now require dual comments, we make this the
356 ;; default.
357 (cond
358 ;; XEmacs
359 ((memq '8-bit c-emacs-features)
360 (modify-syntax-entry ?/ ". 1456" table)
361 (modify-syntax-entry ?* ". 23" table))
362 ;; Emacs
363 ((memq '1-bit c-emacs-features)
364 (modify-syntax-entry ?/ ". 124b" table)
365 (modify-syntax-entry ?* ". 23" table))
366 ;; incompatible
367 (t (error "CC Mode is incompatible with this version of Emacs")))
369 (modify-syntax-entry ?\n "> b" table)
370 ;; Give CR the same syntax as newline, for selective-display
371 (modify-syntax-entry ?\^m "> b" table))
373 (c-lang-defconst c-make-mode-syntax-table
374 "Functions that generates the mode specific syntax tables.
375 The syntax tables aren't stored directly since they're quite large."
376 t `(lambda ()
377 (let ((table (make-syntax-table)))
378 (c-populate-syntax-table table)
379 ;; Mode specific syntaxes.
380 ,(cond ((or (c-major-mode-is 'objc-mode) (c-major-mode-is 'java-mode))
381 ;; Let '@' be part of symbols in ObjC to cope with
382 ;; its compiler directives as single keyword tokens.
383 ;; This is then necessary since it's assumed that
384 ;; every keyword is a single symbol.
385 `(modify-syntax-entry ?@ "_" table))
386 ((c-major-mode-is 'pike-mode)
387 `(modify-syntax-entry ?@ "." table)))
388 table)))
390 (c-lang-defconst c-mode-syntax-table
391 ;; The syntax tables in evaluated form. Only used temporarily when
392 ;; the constants in this file are evaluated.
393 t (funcall (c-lang-const c-make-mode-syntax-table)))
395 (c-lang-defconst c++-make-template-syntax-table
396 ;; A variant of `c++-mode-syntax-table' that defines `<' and `>' as
397 ;; parenthesis characters. Used temporarily when template argument
398 ;; lists are parsed. Note that this encourages incorrect parsing of
399 ;; templates since they might contain normal operators that uses the
400 ;; '<' and '>' characters. Therefore this syntax table might go
401 ;; away when CC Mode handles templates correctly everywhere. WHILE
402 ;; THIS SYNTAX TABLE IS CURRENT, `c-parse-state' MUST _NOT_ BE
403 ;; CALLED!!!
404 t nil
405 (java c++) `(lambda ()
406 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table))))
407 (modify-syntax-entry ?< "(>" table)
408 (modify-syntax-entry ?> ")<" table)
409 table)))
410 (c-lang-defvar c++-template-syntax-table
411 (and (c-lang-const c++-make-template-syntax-table)
412 ;; The next eval remove a superfluous ' from '(lambda. This
413 ;; gets rid of compilation warnings.
414 (funcall (eval (c-lang-const c++-make-template-syntax-table)))))
416 (c-lang-defconst c-make-no-parens-syntax-table
417 ;; A variant of the standard syntax table which is used to find matching
418 ;; "<"s and ">"s which have been marked as parens using syntax table
419 ;; properties. The other paren characters (e.g. "{", ")" "]") are given a
420 ;; non-paren syntax here. so that the list commands will work on "< ... >"
421 ;; even when there's unbalanced other parens inside them.
423 ;; This variable is nil for languages which don't have template stuff.
424 t (if (c-lang-const c-recognize-<>-arglists)
425 `(lambda ()
426 ;(if (c-lang-const c-recognize-<>-arglists)
427 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table))))
428 (modify-syntax-entry ?\( "." table)
429 (modify-syntax-entry ?\) "." table)
430 (modify-syntax-entry ?\[ "." table)
431 (modify-syntax-entry ?\] "." table)
432 (modify-syntax-entry ?\{ "." table)
433 (modify-syntax-entry ?\} "." table)
434 table))))
435 (c-lang-defvar c-no-parens-syntax-table
436 (and (c-lang-const c-make-no-parens-syntax-table)
437 ;; See comment in `c++template-syntax-table' about the next `eval'.
438 (funcall (eval (c-lang-const c-make-no-parens-syntax-table)))))
440 (c-lang-defconst c-identifier-syntax-modifications
441 "A list that describes the modifications that should be done to the
442 mode syntax table to get a syntax table that matches all identifiers
443 and keywords as words.
445 The list is just like the one used in `font-lock-defaults': Each
446 element is a cons where the car is the character to modify and the cdr
447 the new syntax, as accepted by `modify-syntax-entry'."
448 ;; The $ character is not allowed in most languages (one exception
449 ;; is Java which allows it for legacy reasons) but we still classify
450 ;; it as an identifier character since it's often used in various
451 ;; machine generated identifiers.
452 t '((?_ . "w") (?$ . "w"))
453 (objc java) (append '((?@ . "w"))
454 (c-lang-const c-identifier-syntax-modifications))
455 awk '((?_ . "w")))
456 (c-lang-defvar c-identifier-syntax-modifications
457 (c-lang-const c-identifier-syntax-modifications))
459 (c-lang-defvar c-identifier-syntax-table
460 (let ((table (copy-syntax-table (c-mode-var "mode-syntax-table")))
461 (mods c-identifier-syntax-modifications)
462 mod)
463 (while mods
464 (setq mod (car mods)
465 mods (cdr mods))
466 (modify-syntax-entry (car mod) (cdr mod) table))
467 table)
468 "Syntax table built on the mode syntax table but additionally
469 classifies symbol constituents like `_' and `$' as word constituents,
470 so that all identifiers are recognized as words.")
472 (c-lang-defconst c-get-state-before-change-functions
473 ;; For documentation see the following c-lang-defvar of the same name.
474 ;; The value here may be a list of functions or a single function.
475 t nil
476 c++ '(c-extend-region-for-CPP
477 ; c-before-after-change-extend-region-for-lambda-capture ; doesn't seem needed.
478 c-before-change-check-raw-strings
479 c-before-change-check-<>-operators
480 c-depropertize-CPP
481 c-before-after-change-digit-quote
482 c-invalidate-macro-cache
483 c-truncate-bs-cache)
484 (c objc) '(c-extend-region-for-CPP
485 c-depropertize-CPP
486 c-invalidate-macro-cache
487 c-truncate-bs-cache)
488 ;; java 'c-before-change-check-<>-operators
489 awk 'c-awk-record-region-clear-NL)
490 (c-lang-defvar c-get-state-before-change-functions
491 (let ((fs (c-lang-const c-get-state-before-change-functions)))
492 (if (listp fs)
494 (list fs)))
495 "If non-nil, a list of functions called from c-before-change-hook.
496 Typically these will record enough state to allow
497 `c-before-font-lock-function' to extend the region to fontify,
498 and may do such things as removing text-properties which must be
499 recalculated.
501 These functions will be run in the order given. Each of them
502 takes 2 parameters, the BEG and END supplied to every
503 before-change function; on entry, the buffer will have been
504 widened and match-data will have been saved; point is undefined
505 on both entry and exit; the return value is ignored.
507 The functions are called even when font locking isn't enabled.
509 When the mode is initialized, the functions are called with
510 parameters \(point-min) and \(point-max).")
512 (c-lang-defconst c-before-font-lock-functions
513 ;; For documentation see the following c-lang-defvar of the same name.
514 ;; The value here may be a list of functions or a single function.
515 t '(c-depropertize-new-text
516 c-change-expand-fl-region)
517 (c objc) '(c-depropertize-new-text
518 c-extend-font-lock-region-for-macros
519 c-neutralize-syntax-in-and-mark-CPP
520 c-change-expand-fl-region)
521 c++ '(c-depropertize-new-text
522 c-extend-font-lock-region-for-macros
523 ; c-before-after-change-extend-region-for-lambda-capture ; doesn't seem needed.
524 c-before-after-change-digit-quote
525 c-after-change-re-mark-raw-strings
526 c-neutralize-syntax-in-and-mark-CPP
527 c-restore-<>-properties
528 c-change-expand-fl-region)
529 java '(c-depropertize-new-text
530 c-restore-<>-properties
531 c-change-expand-fl-region)
532 awk '(c-depropertize-new-text
533 c-awk-extend-and-syntax-tablify-region))
534 (c-lang-defvar c-before-font-lock-functions
535 (let ((fs (c-lang-const c-before-font-lock-functions)))
536 (if (listp fs)
538 (list fs)))
539 "If non-nil, a list of functions called just before font locking.
540 Typically they will extend the region about to be fontified \(see
541 below) and will set `syntax-table' text properties on the region.
543 These functions will be run in the order given. Each of them
544 takes 3 parameters, the BEG, END, and OLD-LEN supplied to every
545 after-change function; point is undefined on both entry and exit;
546 on entry, the buffer will have been widened and match-data will
547 have been saved; the return value is ignored.
549 The functions may extend the region to be fontified by setting the
550 buffer local variables c-new-BEG and c-new-END.
552 The functions are called even when font locking is disabled.
554 When the mode is initialized, these functions are called with
555 parameters \(point-min), \(point-max) and <buffer size>.")
557 (c-lang-defconst c-before-context-fontification-functions
558 t 'c-context-expand-fl-region
559 awk nil)
560 ;; For documentation see the following c-lang-defvar of the same name.
561 ;; The value here may be a list of functions or a single function.
562 (c-lang-defvar c-before-context-fontification-functions
563 (let ((fs (c-lang-const c-before-context-fontification-functions)))
564 (if (listp fs)
566 (list fs)))
567 "If non-nil, a list of functions called just before context (or
568 other non-change) fontification is done. Typically they will
569 extend the region.
571 These functions will be run in the order given. Each of them
572 takes 2 parameters, the BEG and END of the region to be
573 fontified. Point is undefined on both entry and exit. On entry,
574 the buffer will have been widened and match-data will have been
575 saved; the return value is a cons of the adjusted
576 region, (NEW-BEG . NEW-END).")
579 ;;; Syntactic analysis ("virtual semicolons") for line-oriented languages (AWK).
580 (c-lang-defconst c-at-vsemi-p-fn
581 "Contains a function \"Is there a virtual semicolon at POS or point?\".
582 Such a function takes one optional parameter, a buffer position (defaults to
583 point), and returns nil or t. This variable contains nil for languages which
584 don't have EOL terminated statements. "
585 t nil
586 (c c++ objc) 'c-at-macro-vsemi-p
587 awk 'c-awk-at-vsemi-p)
588 (c-lang-defvar c-at-vsemi-p-fn (c-lang-const c-at-vsemi-p-fn))
590 (c-lang-defconst c-vsemi-status-unknown-p-fn
591 "Contains a function \"are we unsure whether there is a virtual semicolon on this line?\".
592 The (admittedly kludgy) purpose of such a function is to prevent an infinite
593 recursion in c-beginning-of-statement-1 when point starts at a `while' token.
594 The function MUST NOT UNDER ANY CIRCUMSTANCES call c-beginning-of-statement-1,
595 even indirectly. This variable contains nil for languages which don't have
596 EOL terminated statements."
597 t nil
598 (c c++ objc) 'c-macro-vsemi-status-unknown-p
599 awk 'c-awk-vsemi-status-unknown-p)
600 (c-lang-defvar c-vsemi-status-unknown-p-fn
601 (c-lang-const c-vsemi-status-unknown-p-fn))
604 ;;; Lexer-level syntax (identifiers, tokens etc).
606 (c-lang-defconst c-has-bitfields
607 "Whether the language has bitfield declarations."
608 t nil
609 (c c++ objc) t)
610 (c-lang-defvar c-has-bitfields (c-lang-const c-has-bitfields))
612 (c-lang-defconst c-modified-constant
613 "Regexp that matches a “modified” constant literal such as \"L\\='a\\='\",
614 a “long character”. In particular, this recognizes forms of constant
615 which `c-backward-sexp' needs to be called twice to move backwards over."
616 t nil
617 (c c++ objc) "L'\\([^\\'\t\f\n\r]\\|\\\\.\\)'")
618 ;; FIXME!!! Extend this to cover strings, if needed. 2008-04-11
619 (c-lang-defvar c-modified-constant (c-lang-const c-modified-constant))
621 (c-lang-defconst c-symbol-start
622 "Regexp that matches the start of a symbol, i.e. any identifier or
623 keyword. It's unspecified how far it matches. Does not contain a \\|
624 operator at the top level."
625 t (concat "[" c-alpha "_]")
626 java (concat "[" c-alpha "_@]")
627 objc (concat "[" c-alpha "_@]")
628 pike (concat "[" c-alpha "_`]"))
629 (c-lang-defvar c-symbol-start (c-lang-const c-symbol-start))
631 (c-lang-defconst c-symbol-chars
632 "Set of characters that can be part of a symbol.
633 This is of the form that fits inside [ ] in a regexp."
634 ;; Pike note: With the backquote identifiers this would include most
635 ;; operator chars too, but they are handled with other means instead.
636 t (concat c-alnum "_$")
637 objc (concat c-alnum "_$@"))
638 (c-lang-defvar c-symbol-chars (c-lang-const c-symbol-chars))
640 (c-lang-defconst c-symbol-char-key
641 "Regexp matching a sequence of at least one identifier character."
642 t (concat "[" (c-lang-const c-symbol-chars) "]+"))
643 (c-lang-defvar c-symbol-char-key (c-lang-const c-symbol-char-key))
645 (c-lang-defconst c-symbol-key
646 "Regexp matching identifiers and keywords (with submatch 0). Assumed
647 to match if `c-symbol-start' matches on the same position."
648 t (concat (c-lang-const c-symbol-start)
649 "[" (c-lang-const c-symbol-chars) "]*")
650 pike (concat
651 ;; Use the value from C here since the operator backquote is
652 ;; covered by the other alternative.
653 (c-lang-const c-symbol-key c)
654 "\\|"
655 (c-make-keywords-re nil
656 (c-lang-const c-overloadable-operators))))
657 (c-lang-defvar c-symbol-key (c-lang-const c-symbol-key))
659 (c-lang-defconst c-symbol-key-depth
660 ;; Number of regexp grouping parens in `c-symbol-key'.
661 t (regexp-opt-depth (c-lang-const c-symbol-key)))
663 (c-lang-defconst c-nonsymbol-chars
664 "This is the set of chars that can't be part of a symbol, i.e. the
665 negation of `c-symbol-chars'."
666 t (concat "^" (c-lang-const c-symbol-chars)))
667 (c-lang-defvar c-nonsymbol-chars (c-lang-const c-nonsymbol-chars))
669 (c-lang-defconst c-nonsymbol-key
670 "Regexp that matches any character that can't be part of a symbol.
671 It's usually appended to other regexps to avoid matching a prefix.
672 It's assumed to not contain any submatchers."
673 ;; The same thing regarding Unicode identifiers applies here as to
674 ;; `c-symbol-key'.
675 t (concat "[" (c-lang-const c-nonsymbol-chars) "]"))
677 (c-lang-defconst c-identifier-ops
678 "The operators that make up fully qualified identifiers. nil in
679 languages that don't have such things. See `c-operators' for a
680 description of the format. Binary operators can concatenate symbols,
681 e.g. \"::\" in \"A::B::C\". Prefix operators can precede identifiers,
682 e.g. \"~\" in \"~A::B\". Other types of operators aren't supported.
684 This value is by default merged into `c-operators'."
685 t nil
686 c++ '((prefix "~" "??-" "compl")
687 (right-assoc "::")
688 (prefix "::"))
689 ;; Java has "." to concatenate identifiers but it's also used for
690 ;; normal indexing. There's special code in the Java font lock
691 ;; rules to fontify qualified identifiers based on the standard
692 ;; naming conventions. We still define "." here to make
693 ;; `c-forward-name' move over as long names as possible which is
694 ;; necessary to e.g. handle throws clauses correctly.
695 java '((left-assoc "."))
696 idl '((left-assoc "::")
697 (prefix "::"))
698 pike '((left-assoc "::")
699 (prefix "::")
700 (left-assoc ".")))
702 (c-lang-defconst c-opt-identifier-concat-key
703 ;; Appendable adorned regexp matching the operators that join
704 ;; symbols to fully qualified identifiers, or nil in languages that
705 ;; don't have such things.
707 ;; This was a docstring constant in 5.30. It still works but is now
708 ;; considered internal - change `c-identifier-ops' instead.
709 t (let ((ops (c-filter-ops (c-lang-const c-identifier-ops)
710 '(left-assoc right-assoc)
711 t)))
712 (when ops
713 (c-make-keywords-re 'appendable ops))))
714 (c-lang-defvar c-opt-identifier-concat-key
715 (c-lang-const c-opt-identifier-concat-key)
716 'dont-doc)
718 (c-lang-defconst c-opt-identifier-concat-key-depth
719 ;; Number of regexp grouping parens in `c-opt-identifier-concat-key'.
720 t (regexp-opt-depth (c-lang-const c-opt-identifier-concat-key)))
722 (c-lang-defconst c-opt-identifier-prefix-key
723 ;; Appendable adorned regexp matching operators that might precede
724 ;; an identifier and that are part of the identifier in that case.
725 ;; nil in languages without such things.
726 t (let ((ops (c-filter-ops (c-lang-const c-identifier-ops)
727 '(prefix)
728 t)))
729 (when ops
730 (c-make-keywords-re 'appendable ops))))
732 (c-lang-defconst c-after-id-concat-ops
733 "Operators that can occur after a binary operator on `c-identifier-ops'
734 in identifiers. nil in languages that don't have such things.
736 Operators here should also have appropriate entries in `c-operators' -
737 it's not taken care of by default."
738 t nil
739 ;; '~' for destructors in C++, '*' for member pointers.
740 c++ '("~" "*")
741 ;; In Java we recognize '*' to deal with "foo.bar.*" that can occur
742 ;; in import declarations. (This will also match bogus things like
743 ;; "foo.*bar" but we don't bother.)
744 java '("*"))
746 (c-lang-defconst c-opt-after-id-concat-key
747 ;; Regexp that must match the token after
748 ;; `c-opt-identifier-concat-key' for it to be considered an
749 ;; identifier concatenation operator (which e.g. causes the
750 ;; preceding identifier to be fontified as a reference). Assumed to
751 ;; be a string if `c-opt-identifier-concat-key' is.
753 ;; This was a docstring constant in 5.30. It still works but is now
754 ;; considered internal - change `c-after-id-concat-ops' instead.
755 t (concat (c-lang-const c-symbol-start)
756 (if (c-lang-const c-after-id-concat-ops)
757 (concat "\\|" (c-make-keywords-re 'appendable
758 (c-lang-const c-after-id-concat-ops)))
759 "")))
761 (c-lang-defconst c-identifier-start
762 "Regexp that matches the start of an (optionally qualified) identifier.
763 It should also match all keywords. It's unspecified how far it
764 matches."
765 t (concat (c-lang-const c-symbol-start)
766 (if (c-lang-const c-opt-identifier-prefix-key)
767 (concat "\\|"
768 (c-lang-const c-opt-identifier-prefix-key))
769 "")))
770 (c-lang-defvar c-identifier-start (c-lang-const c-identifier-start))
772 (c-lang-defconst c-identifier-key
773 "Regexp matching a fully qualified identifier, like \"A::B::c\" in
774 C++. It does not recognize the full range of syntactic whitespace
775 between the tokens; `c-forward-name' has to be used for that. It
776 should also not match identifiers containing parenthesis groupings,
777 e.g. identifiers with template arguments such as \"A<X,Y>\" in C++."
778 ;; This regexp is more complex than strictly necessary to ensure
779 ;; that it can be matched with a minimum of backtracking.
780 t (concat (if (c-lang-const c-opt-identifier-prefix-key)
781 (concat
782 "\\("
783 (c-lang-const c-opt-identifier-prefix-key)
784 (c-lang-const c-simple-ws) "*"
785 "\\)?")
787 "\\(" (c-lang-const c-symbol-key) "\\)"
788 (if (c-lang-const c-opt-identifier-concat-key)
789 (concat
790 "\\("
791 (c-lang-const c-simple-ws) "*"
792 (c-lang-const c-opt-identifier-concat-key)
793 (c-lang-const c-simple-ws) "*"
794 (if (c-lang-const c-after-id-concat-ops)
795 (concat
796 "\\("
797 (c-make-keywords-re 'appendable
798 (c-lang-const c-after-id-concat-ops))
799 (concat
800 ;; For flexibility, consider the symbol match
801 ;; optional if we've hit a
802 ;; `c-after-id-concat-ops' operator. This is
803 ;; also necessary to handle the "*" that can
804 ;; end import declaration identifiers in Java.
805 "\\("
806 (c-lang-const c-simple-ws) "*"
807 "\\(" (c-lang-const c-symbol-key) "\\)"
808 "\\)?")
809 "\\|"
810 "\\(" (c-lang-const c-symbol-key) "\\)"
811 "\\)")
812 (concat "\\(" (c-lang-const c-symbol-key) "\\)"))
813 "\\)*")
814 "")))
815 (c-lang-defvar c-identifier-key (c-lang-const c-identifier-key))
817 (c-lang-defconst c-identifier-last-sym-match
818 ;; This was a docstring constant in 5.30 but it's no longer used.
819 ;; It's only kept to avoid breaking third party code.
821 ;; Used to identify the submatch in `c-identifier-key' that
822 ;; surrounds the last symbol in the qualified identifier. It's a
823 ;; list of submatch numbers, of which the first that has a match is
824 ;; taken. It's assumed that at least one does when the regexp has
825 ;; matched.
826 t nil)
828 (c-lang-defconst c-string-escaped-newlines
829 "Set if the language support backslash escaped newlines inside string
830 literals."
831 t nil
832 (c c++ objc pike) t)
833 (c-lang-defvar c-string-escaped-newlines
834 (c-lang-const c-string-escaped-newlines))
836 (c-lang-defconst c-multiline-string-start-char
837 "Set if the language supports multiline string literals without escaped
838 newlines. If t, all string literals are multiline. If a character,
839 only literals where the open quote is immediately preceded by that
840 literal are multiline."
841 t nil
842 pike ?#)
843 (c-lang-defvar c-multiline-string-start-char
844 (c-lang-const c-multiline-string-start-char))
846 (c-lang-defconst c-opt-cpp-symbol
847 "The symbol which starts preprocessor constructs when in the margin."
848 t "#"
849 (java awk) nil)
850 (c-lang-defvar c-opt-cpp-symbol (c-lang-const c-opt-cpp-symbol))
852 (c-lang-defconst c-opt-cpp-prefix
853 "Regexp matching the prefix of a cpp directive in the languages that
854 normally use that macro preprocessor. Tested at bol or at boi.
855 Assumed to not contain any submatches or \\| operators."
856 ;; TODO (ACM, 2005-04-01). Amend the following to recognize escaped NLs;
857 ;; amend all uses of c-opt-cpp-prefix which count regexp-depth.
858 t "\\s *#\\s *"
859 (java awk) nil)
860 (c-lang-defvar c-opt-cpp-prefix (c-lang-const c-opt-cpp-prefix))
862 (c-lang-defconst c-anchored-cpp-prefix
863 "Regexp matching the prefix of a cpp directive anchored to BOL,
864 in the languages that have a macro preprocessor."
865 t "^\\s *\\(#\\)\\s *"
866 (java awk) nil)
867 (c-lang-defvar c-anchored-cpp-prefix (c-lang-const c-anchored-cpp-prefix))
869 (c-lang-defconst c-opt-cpp-start
870 "Regexp matching the prefix of a cpp directive including the directive
871 name, or nil in languages without preprocessor support. The first
872 submatch surrounds the directive name."
873 t (if (c-lang-const c-opt-cpp-prefix)
874 (concat (c-lang-const c-opt-cpp-prefix)
875 "\\([" c-alnum "]+\\)"))
876 ;; Pike, being a scripting language, recognizes hash-bangs too.
877 pike (concat (c-lang-const c-opt-cpp-prefix)
878 "\\([" c-alnum "]+\\|!\\)"))
879 (c-lang-defvar c-opt-cpp-start (c-lang-const c-opt-cpp-start))
881 (c-lang-defconst c-cpp-message-directives
882 "List of cpp directives (without the prefix) that are followed by a
883 string message."
884 t (if (c-lang-const c-opt-cpp-prefix)
885 '("error"))
886 (c c++ objc pike) '("error" "warning"))
888 (c-lang-defconst c-cpp-include-directives
889 "List of cpp directives (without the prefix) that are followed by a
890 file name in angle brackets or quotes."
891 t (if (c-lang-const c-opt-cpp-prefix)
892 '("include"))
893 objc '("include" "import"))
895 (c-lang-defconst c-opt-cpp-macro-define
896 "Cpp directive (without the prefix) that is followed by a macro
897 definition, or nil if the language doesn't have any."
898 t (if (c-lang-const c-opt-cpp-prefix)
899 "define"))
900 (c-lang-defvar c-opt-cpp-macro-define
901 (c-lang-const c-opt-cpp-macro-define))
903 (c-lang-defconst c-opt-cpp-macro-define-start
904 ;; Regexp matching everything up to the macro body of a cpp define, or the
905 ;; end of the logical line if there is none. Submatch 1 is the name of the
906 ;; macro. Set if c-opt-cpp-macro-define is.
907 t (if (c-lang-const c-opt-cpp-macro-define)
908 (concat (c-lang-const c-opt-cpp-prefix)
909 (c-lang-const c-opt-cpp-macro-define)
910 "[ \t]+\\(\\(\\sw\\|_\\)+\\)\\(([^)]*)\\)?"
911 ;; ^ ^ #defined name
912 "\\([ \t]\\|\\\\\n\\)*")))
913 (c-lang-defvar c-opt-cpp-macro-define-start
914 (c-lang-const c-opt-cpp-macro-define-start))
916 (c-lang-defconst c-opt-cpp-macro-define-id
917 ;; Regexp matching everything up to the end of the identifier defined
918 ;; by a cpp define.
919 t (if (c-lang-const c-opt-cpp-macro-define)
920 (concat (c-lang-const c-opt-cpp-prefix) ; #
921 (c-lang-const c-opt-cpp-macro-define) ; define
922 "[ \t]+\\(\\sw\\|_\\)+")))
923 (c-lang-defvar c-opt-cpp-macro-define-id
924 (c-lang-const c-opt-cpp-macro-define-id))
926 (c-lang-defconst c-cpp-expr-directives
927 "List of cpp directives (without the prefix) that are followed by an
928 expression."
929 t (if (c-lang-const c-opt-cpp-prefix)
930 '("if" "elif")))
932 (c-lang-defconst c-cpp-expr-intro-re
933 "Regexp which matches the start of a CPP directive which contains an
934 expression, or nil if there aren't any in the language."
935 t (if (c-lang-const c-cpp-expr-directives)
936 (concat
937 (c-lang-const c-opt-cpp-prefix)
938 (c-make-keywords-re t (c-lang-const c-cpp-expr-directives)))))
939 (c-lang-defvar c-cpp-expr-intro-re
940 (c-lang-const c-cpp-expr-intro-re))
942 (c-lang-defconst c-cpp-expr-functions
943 "List of functions in cpp expressions."
944 t (if (c-lang-const c-opt-cpp-prefix)
945 '("defined"))
946 pike '("defined" "efun" "constant"))
948 (c-lang-defconst c-assignment-operators
949 "List of all assignment operators."
950 t '("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=")
951 java (append (c-lang-const c-assignment-operators)
952 '(">>>="))
953 c++ (append (c-lang-const c-assignment-operators)
954 '("and_eq" "or_eq" "xor_eq" "??!=" "??'="))
955 idl nil)
957 (c-lang-defconst c-operators
958 "List describing all operators, along with their precedence and
959 associativity. The order in the list corresponds to the precedence of
960 the operators: The operators in each element are a group with the same
961 precedence, and the group has higher precedence than the groups in all
962 following elements. The car of each element describes the type of the
963 operator group, and the cdr is a list of the operator tokens in it.
964 The operator group types are:
966 `prefix' Unary prefix operators.
967 `postfix' Unary postfix operators.
968 `postfix-if-paren'
969 Unary postfix operators if and only if the chars have
970 parenthesis syntax.
971 `left-assoc' Binary left associative operators (i.e. a+b+c means (a+b)+c).
972 `right-assoc' Binary right associative operators (i.e. a=b=c means a=(b=c)).
973 `right-assoc-sequence'
974 Right associative operator that constitutes of a
975 sequence of tokens that separate expressions. All the
976 tokens in the group are in this case taken as
977 describing the sequence in one such operator, and the
978 order between them is therefore significant.
980 Operators containing a character with paren syntax are taken to match
981 with a corresponding open/close paren somewhere else. A postfix
982 operator with close paren syntax is taken to end a postfix expression
983 started somewhere earlier, rather than start a new one at point. Vice
984 versa for prefix operators with open paren syntax.
986 Note that operators like \".\" and \"->\" which in language references
987 often are described as postfix operators are considered binary here,
988 since CC Mode treats every identifier as an expression."
990 ;; There's currently no code in CC Mode that exploits all the info
991 ;; in this variable; precedence, associativity etc are present as a
992 ;; preparation for future work.
994 ;; FIXME!!! C++11's "auto" operators "=" and "->" need to go in here
995 ;; somewhere. 2012-03-24.
997 t `(;; Preprocessor.
998 ,@(when (c-lang-const c-opt-cpp-prefix)
999 `((prefix "#"
1000 ,@(when (c-major-mode-is '(c-mode c++-mode))
1001 '("%:" "??=")))
1002 (left-assoc "##"
1003 ,@(when (c-major-mode-is '(c-mode c++-mode))
1004 '("%:%:" "??=??=")))))
1006 ;; Primary.
1007 ,@(c-lang-const c-identifier-ops)
1008 ,@(cond ((or (c-major-mode-is 'c++-mode) (c-major-mode-is 'java-mode))
1009 `((postfix-if-paren "<" ">"))) ; Templates.
1010 ((c-major-mode-is 'pike-mode)
1011 `((prefix "global" "predef")))
1012 ((c-major-mode-is 'java-mode)
1013 `((prefix "super"))))
1015 ;; Postfix.
1016 ,@(when (c-major-mode-is 'c++-mode)
1017 ;; The following need special treatment.
1018 `((prefix "dynamic_cast" "static_cast"
1019 "reinterpret_cast" "const_cast" "typeid"
1020 "alignof")))
1021 (left-assoc "."
1022 ,@(unless (c-major-mode-is 'java-mode)
1023 '("->")))
1024 (postfix "++" "--" "[" "]" "(" ")"
1025 ,@(when (c-major-mode-is '(c-mode c++-mode))
1026 '("<:" ":>" "??(" "??)")))
1028 ;; Unary.
1029 (prefix "++" "--" "+" "-" "!" "~"
1030 ,@(when (c-major-mode-is 'c++-mode) '("not" "compl"))
1031 ,@(when (c-major-mode-is '(c-mode c++-mode))
1032 '("*" "&" "sizeof" "??-"))
1033 ,@(when (c-major-mode-is 'objc-mode)
1034 '("@selector" "@protocol" "@encode"))
1035 ;; The following need special treatment.
1036 ,@(cond ((c-major-mode-is 'c++-mode)
1037 '("new" "delete"))
1038 ((c-major-mode-is 'java-mode)
1039 '("new"))
1040 ((c-major-mode-is 'pike-mode)
1041 '("class" "lambda" "catch" "throw" "gauge")))
1042 "(" ")" ; Cast.
1043 ,@(when (c-major-mode-is 'pike-mode)
1044 '("[" "]"))) ; Type cast.
1046 ;; Member selection.
1047 ,@(when (c-major-mode-is 'c++-mode)
1048 `((left-assoc ".*" "->*")))
1050 ;; Multiplicative.
1051 (left-assoc "*" "/" "%")
1053 ;; Additive.
1054 (left-assoc "+" "-")
1056 ;; Shift.
1057 (left-assoc "<<" ">>"
1058 ,@(when (c-major-mode-is 'java-mode)
1059 '(">>>")))
1061 ;; Relational.
1062 (left-assoc "<" ">" "<=" ">="
1063 ,@(when (c-major-mode-is 'java-mode)
1064 '("instanceof")))
1066 ;; Equality.
1067 (left-assoc "==" "!="
1068 ,@(when (c-major-mode-is 'c++-mode) '("not_eq")))
1070 ;; Bitwise and.
1071 (left-assoc "&"
1072 ,@(when (c-major-mode-is 'c++-mode) '("bitand")))
1074 ;; Bitwise exclusive or.
1075 (left-assoc "^"
1076 ,@(when (c-major-mode-is '(c-mode c++-mode))
1077 '("??'"))
1078 ,@(when (c-major-mode-is 'c++-mode) '("xor")))
1080 ;; Bitwise or.
1081 (left-assoc "|"
1082 ,@(when (c-major-mode-is '(c-mode c++-mode))
1083 '("??!"))
1084 ,@(when (c-major-mode-is 'c++-mode) '("bitor")))
1086 ;; Logical and.
1087 (left-assoc "&&"
1088 ,@(when (c-major-mode-is 'c++-mode) '("and")))
1090 ;; Logical or.
1091 (left-assoc "||"
1092 ,@(when (c-major-mode-is '(c-mode c++-mode))
1093 '("??!??!"))
1094 ,@(when (c-major-mode-is 'c++-mode) '("or")))
1096 ;; Conditional.
1097 (right-assoc-sequence "?" ":")
1099 ;; Assignment.
1100 (right-assoc ,@(c-lang-const c-assignment-operators))
1102 ;; Exception.
1103 ,@(when (c-major-mode-is 'c++-mode)
1104 '((prefix "throw")))
1106 ;; Sequence.
1107 (left-assoc ","))
1109 ;; IDL got its own definition since it has a much smaller operator
1110 ;; set than the other languages.
1111 idl `(;; Preprocessor.
1112 (prefix "#")
1113 (left-assoc "##")
1114 ;; Primary.
1115 ,@(c-lang-const c-identifier-ops)
1116 ;; Unary.
1117 (prefix "+" "-" "~")
1118 ;; Multiplicative.
1119 (left-assoc "*" "/" "%")
1120 ;; Additive.
1121 (left-assoc "+" "-")
1122 ;; Shift.
1123 (left-assoc "<<" ">>")
1124 ;; And.
1125 (left-assoc "&")
1126 ;; Xor.
1127 (left-assoc "^")
1128 ;; Or.
1129 (left-assoc "|")))
1131 (c-lang-defconst c-operator-list
1132 ;; The operators as a flat list (without duplicates).
1133 t (c-filter-ops (c-lang-const c-operators) t t))
1135 (c-lang-defconst c-overloadable-operators
1136 "List of the operators that are overloadable, in their \"identifier
1137 form\". See also `c-op-identifier-prefix'."
1138 t nil
1139 c++ '("new" "delete" ;; Can be followed by "[]" but we ignore that.
1140 "+" "-" "*" "/" "%"
1141 "^" "??'" "xor" "&" "bitand" "|" "??!" "bitor" "~" "??-" "compl"
1142 "!" "=" "<" ">" "+=" "-=" "*=" "/=" "%=" "^="
1143 "??'=" "xor_eq" "&=" "and_eq" "|=" "??!=" "or_eq"
1144 "<<" ">>" ">>=" "<<=" "==" "!=" "not_eq" "<=" ">="
1145 "&&" "and" "||" "??!??!" "or" "++" "--" "," "->*" "->"
1146 "()" "[]" "<::>" "??(??)")
1147 ;; These work like identifiers in Pike.
1148 pike '("`+" "`-" "`&" "`|" "`^" "`<<" "`>>" "`*" "`/" "`%" "`~"
1149 "`==" "`<" "`>" "`!" "`[]" "`[]=" "`->" "`->=" "`()" "``+"
1150 "``-" "``&" "``|" "``^" "``<<" "``>>" "``*" "``/" "``%"
1151 "`+="))
1153 (c-lang-defconst c-overloadable-operators-regexp
1154 ;; Regexp tested after an "operator" token in C++.
1155 t nil
1156 c++ (c-make-keywords-re nil (c-lang-const c-overloadable-operators)))
1157 (c-lang-defvar c-overloadable-operators-regexp
1158 (c-lang-const c-overloadable-operators-regexp))
1160 (c-lang-defconst c-opt-op-identifier-prefix
1161 "Regexp matching the token before the ones in
1162 `c-overloadable-operators' when operators are specified in their
1163 \"identifier form\". This typically matches \"operator\" in C++ where
1164 operator functions are specified as e.g. \"operator +\". It's nil in
1165 languages without operator functions or where the complete operator
1166 identifier is listed in `c-overloadable-operators'.
1168 This regexp is assumed to not match any non-operator identifier."
1169 t nil
1170 c++ (c-make-keywords-re t '("operator")))
1171 (c-lang-defvar c-opt-op-identifier-prefix
1172 (c-lang-const c-opt-op-identifier-prefix))
1174 ;; Note: the following alias is an old name which was a mis-spelling. It has
1175 ;; been corrected above and throughout cc-engine.el. It will be removed at
1176 ;; some release very shortly in the future. ACM, 2006-04-14.
1177 (defvaralias 'c-opt-op-identitier-prefix 'c-opt-op-identifier-prefix)
1178 (make-obsolete-variable 'c-opt-op-identitier-prefix 'c-opt-op-identifier-prefix
1179 "CC Mode 5.31.4, 2006-04-14")
1181 (c-lang-defconst c-other-op-syntax-tokens
1182 "List of the tokens made up of characters in the punctuation or
1183 parenthesis syntax classes that have uses other than as expression
1184 operators."
1185 t '("{" "}" "(" ")" "[" "]" ";" ":" "," "=" "/*" "*/" "//")
1186 (c c++ pike) (append '("#" "##" ; Used by cpp.
1187 "::" "...")
1188 (c-lang-const c-other-op-syntax-tokens))
1189 (c c++) (append '("*") (c-lang-const c-other-op-syntax-tokens))
1190 c++ (append '("&" "<%" "%>" "<:" ":>" "%:" "%:%:")
1191 (c-lang-const c-other-op-syntax-tokens))
1192 objc (append '("#" "##" ; Used by cpp.
1193 "+" "-")
1194 (c-lang-const c-other-op-syntax-tokens))
1195 idl (append '("#" "##") ; Used by cpp.
1196 (c-lang-const c-other-op-syntax-tokens))
1197 pike (append '("..")
1198 (c-lang-const c-other-op-syntax-tokens)
1199 (c-lang-const c-overloadable-operators))
1200 awk '("{" "}" "(" ")" "[" "]" ";" "," "=" "/"))
1202 (c-lang-defconst c-all-op-syntax-tokens
1203 ;; List of all tokens in the punctuation and parenthesis syntax
1204 ;; classes.
1205 t (c--delete-duplicates (append (c-lang-const c-other-op-syntax-tokens)
1206 (c-lang-const c-operator-list))
1207 :test 'string-equal))
1209 (c-lang-defconst c-nonsymbol-token-char-list
1210 ;; List containing all chars not in the word, symbol or
1211 ;; syntactically irrelevant syntax classes, i.e. all punctuation,
1212 ;; parenthesis and string delimiter chars.
1213 t (c-with-syntax-table (c-lang-const c-mode-syntax-table)
1214 ;; Only go through the chars in the printable ASCII range. No
1215 ;; language so far has 8-bit or widestring operators.
1216 (let (list (char 32))
1217 (while (< char 127)
1218 (or (memq (char-syntax char) '(?w ?_ ?< ?> ?\ ))
1219 (setq list (cons (c-int-to-char char) list)))
1220 (setq char (1+ char)))
1221 list)))
1223 (c-lang-defconst c-nonsymbol-token-regexp
1224 ;; Regexp matching all tokens in the punctuation and parenthesis
1225 ;; syntax classes. Note that this also matches ".", which can start
1226 ;; a float.
1227 t (c-make-keywords-re nil
1228 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1230 "\\`\\(\\s.\\)+\\'")))
1231 (c-lang-defvar c-nonsymbol-token-regexp
1232 (c-lang-const c-nonsymbol-token-regexp))
1234 (c-lang-defconst c-assignment-op-regexp
1235 ;; Regexp matching all assignment operators and only them. The
1236 ;; beginning of the first submatch is used to detect the end of the
1237 ;; token, along with the end of the whole match.
1238 t (if (c-lang-const c-assignment-operators)
1239 (concat
1240 ;; Need special case for "=" since it's a prefix of "==".
1241 "=\\([^=]\\|$\\)"
1242 "\\|"
1243 (c-make-keywords-re nil
1244 (c--set-difference (c-lang-const c-assignment-operators)
1245 '("=")
1246 :test 'string-equal)))
1247 "\\<\\>"))
1248 (c-lang-defvar c-assignment-op-regexp
1249 (c-lang-const c-assignment-op-regexp))
1251 (c-lang-defconst c-arithmetic-operators
1252 "List of all arithmetic operators, including \"+=\", etc."
1253 ;; Note: in the following, there are too many operators for AWK and IDL.
1254 t (append (c-lang-const c-assignment-operators)
1255 '("+" "-" "*" "/" "%"
1256 "<<" ">>"
1257 "<" ">" "<=" ">="
1258 "==" "!="
1259 "&" "^" "|"
1260 "&&" "||")))
1262 (c-lang-defconst c-arithmetic-op-regexp
1263 t (c-make-keywords-re nil
1264 (c-lang-const c-arithmetic-operators)))
1265 (c-lang-defvar c-arithmetic-op-regexp (c-lang-const c-arithmetic-op-regexp))
1267 (c-lang-defconst c-:$-multichar-token-regexp
1268 ;; Regexp matching all tokens ending in ":" which are longer than one char.
1269 ;; Currently (2016-01-07) only used in C++ Mode.
1270 t (c-make-keywords-re nil
1271 (c-filter-ops (c-lang-const c-operators) t ".+:$")))
1272 (c-lang-defvar c-:$-multichar-token-regexp
1273 (c-lang-const c-:$-multichar-token-regexp))
1275 (c-lang-defconst c-<>-multichar-token-regexp
1276 ;; Regexp matching all tokens containing "<" or ">" which are longer
1277 ;; than one char.
1278 t (c-make-keywords-re nil
1279 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1281 ".[<>]\\|[<>].")))
1282 (c-lang-defvar c-<>-multichar-token-regexp
1283 (c-lang-const c-<>-multichar-token-regexp))
1285 (c-lang-defconst c-<-op-cont-regexp
1286 ;; Regexp matching the second and subsequent characters of all
1287 ;; multicharacter tokens that begin with "<".
1288 t (c-make-keywords-re nil
1289 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1291 "\\`<."
1292 (lambda (op) (substring op 1)))))
1293 (c-lang-defvar c-<-op-cont-regexp (c-lang-const c-<-op-cont-regexp))
1295 (c-lang-defconst c->-op-cont-tokens
1296 ;; A list of second and subsequent characters of all multicharacter tokens
1297 ;; that begin with ">".
1298 t (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1300 "\\`>."
1301 (lambda (op) (substring op 1)))
1302 java (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1304 "\\`>[^>]\\|\\`>>[^>]"
1305 (lambda (op) (substring op 1))))
1307 (c-lang-defconst c->-op-cont-regexp
1308 ;; Regexp matching the second and subsequent characters of all
1309 ;; multicharacter tokens that begin with ">".
1310 t (c-make-keywords-re nil (c-lang-const c->-op-cont-tokens)))
1311 (c-lang-defvar c->-op-cont-regexp (c-lang-const c->-op-cont-regexp))
1313 (c-lang-defconst c->-op-without->-cont-regexp
1314 ;; Regexp matching the second and subsequent characters of all
1315 ;; multicharacter tokens that begin with ">" except for those beginning with
1316 ;; ">>".
1317 t (c-make-keywords-re nil
1318 (c--set-difference
1319 (c-lang-const c->-op-cont-tokens)
1320 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1322 "\\`>>"
1323 (lambda (op) (substring op 1)))
1324 :test 'string-equal)))
1325 (c-lang-defvar c->-op-without->-cont-regexp
1326 (c-lang-const c->-op-without->-cont-regexp))
1328 (c-lang-defconst c-multichar->-op-not->>-regexp
1329 ;; Regexp matching multichar tokens containing ">", except ">>"
1330 t (c-make-keywords-re nil
1331 (delete ">>"
1332 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1334 "\\(.>\\|>.\\)"))))
1335 (c-lang-defvar c-multichar->-op-not->>-regexp
1336 (c-lang-const c-multichar->-op-not->>-regexp))
1338 (c-lang-defconst c-stmt-delim-chars
1339 ;; The characters that should be considered to bound statements. To
1340 ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to
1341 ;; begin with "^" to negate the set. If ? : operators should be
1342 ;; detected then the string must end with "?:".
1343 t "^;{}?:")
1344 (c-lang-defvar c-stmt-delim-chars (c-lang-const c-stmt-delim-chars))
1346 (c-lang-defconst c-stmt-delim-chars-with-comma
1347 ;; Variant of `c-stmt-delim-chars' that additionally contains ','.
1348 t "^;,{}?:")
1349 (c-lang-defvar c-stmt-delim-chars-with-comma
1350 (c-lang-const c-stmt-delim-chars-with-comma))
1352 (c-lang-defconst c-pack-ops
1353 "Ops which signal C++11's \"parameter pack\""
1354 t nil
1355 c++ '("..."))
1356 (c-lang-defconst c-pack-key
1357 t (c-make-keywords-re 'appendable (c-lang-const c-pack-ops)))
1358 (c-lang-defvar c-pack-key (c-lang-const c-pack-key))
1360 (c-lang-defconst c-auto-ops
1361 ;; Ops which signal C++11's new auto uses.
1362 t nil
1363 c++ '("=" "->"))
1364 (c-lang-defconst c-auto-ops-re
1365 t (c-make-keywords-re nil (c-lang-const c-auto-ops)))
1366 (c-lang-defvar c-auto-ops-re (c-lang-const c-auto-ops-re))
1368 (c-lang-defconst c-haskell-op
1369 ;; Op used in the new C++11 auto function definition, indicating type.
1370 t nil
1371 c++ '("->"))
1372 (c-lang-defconst c-haskell-op-re
1373 t (c-make-keywords-re nil (c-lang-const c-haskell-op)))
1374 (c-lang-defvar c-haskell-op-re (c-lang-const c-haskell-op-re))
1376 (c-lang-defconst c-pre-start-tokens
1377 "List of operators following which an apparent declaration \(e.g.
1378 \"t1 *fn (t2 *b);\") is most likely to be an actual declaration
1379 \(as opposed to an arithmetic expression)."
1380 t '(";" "{" "}"))
1381 (c-lang-defvar c-pre-start-tokens (c-lang-const c-pre-start-tokens))
1383 (c-lang-defconst c-pre-lambda-tokens
1384 "List of tokens which may precede a lambda declaration.
1385 In C++ this is something like \"[a,b] (foo, bar) -> int { ... };\".
1386 Currently (2016-08) only used in C++ mode."
1387 t (c--set-difference
1388 (c--delete-duplicates
1389 (append (c-lang-const c-operator-list)
1390 (c-lang-const c-other-op-syntax-tokens)))
1391 (append
1392 '("#" "%:" "??=" "##" "%:%:" "??=??=" "::" "." "->"
1393 "]" "<:" ":>" "??(" "??)" "??-" "new" "delete"
1394 ")" ".*" "->*" "??'" "??!" "??!??!" "??!=" "??'=")
1395 '("<%" "%>" "<:" ":>" "%:" "%:%:" "#" "##" "::" "..."))
1396 :test #'string-equal))
1398 (c-lang-defconst c-pre-lambda-tokens-re
1399 ;; Regexp matching any token in the list `c-pre-lambda-tokens'.
1400 t (regexp-opt (c-lang-const c-pre-lambda-tokens)))
1401 (c-lang-defvar c-pre-lambda-tokens-re (c-lang-const c-pre-lambda-tokens-re))
1403 ;;; Syntactic whitespace.
1405 (c-lang-defconst c-simple-ws
1406 "Regexp matching an ordinary whitespace character.
1407 Does not contain a \\| operator at the top level."
1408 ;; "\\s " is not enough since it doesn't match line breaks.
1409 t "\\(\\s \\|[\n\r]\\)")
1411 (c-lang-defconst c-simple-ws-depth
1412 ;; Number of regexp grouping parens in `c-simple-ws'.
1413 t (regexp-opt-depth (c-lang-const c-simple-ws)))
1415 (c-lang-defconst c-line-comment-starter
1416 "String that starts line comments, or nil if such don't exist.
1417 Line comments are always terminated by newlines. At least one of
1418 `c-block-comment-starter' and this one is assumed to be set.
1420 Note that it's currently not enough to set this to support a new
1421 comment style. Other stuff like the syntax table must also be set up
1422 properly."
1423 t "//"
1424 awk "#")
1425 (c-lang-defvar c-line-comment-starter (c-lang-const c-line-comment-starter))
1427 (c-lang-defconst c-block-comment-starter
1428 "String that starts block comments, or nil if such don't exist.
1429 Block comments are ended by `c-block-comment-ender', which is assumed
1430 to be set if this is. At least one of `c-line-comment-starter' and
1431 this one is assumed to be set.
1433 Note that it's currently not enough to set this to support a new
1434 comment style. Other stuff like the syntax table must also be set up
1435 properly."
1436 t "/*"
1437 awk nil)
1439 (c-lang-defconst c-block-comment-ender
1440 "String that ends block comments, or nil if such don't exist.
1442 Note that it's currently not enough to set this to support a new
1443 comment style. Other stuff like the syntax table must also be set up
1444 properly."
1445 t "*/"
1446 awk nil)
1448 (c-lang-defconst c-comment-start-regexp
1449 ;; Regexp to match the start of any type of comment.
1450 t (let ((re (c-make-keywords-re nil
1451 (list (c-lang-const c-line-comment-starter)
1452 (c-lang-const c-block-comment-starter)))))
1453 (if (memq 'gen-comment-delim c-emacs-features)
1454 (concat re "\\|\\s!")
1455 re)))
1456 (c-lang-defvar c-comment-start-regexp (c-lang-const c-comment-start-regexp))
1458 (c-lang-defconst c-block-comment-start-regexp
1459 ;; Regexp which matches the start of a block comment (if such exists in the
1460 ;; language)
1461 t (if (c-lang-const c-block-comment-starter)
1462 (regexp-quote (c-lang-const c-block-comment-starter))
1463 "\\<\\>"))
1464 (c-lang-defvar c-block-comment-start-regexp
1465 (c-lang-const c-block-comment-start-regexp))
1467 (c-lang-defconst c-line-comment-start-regexp
1468 ;; Regexp which matches the start of a line comment (if such exists in the
1469 ;; language; it does in all 7 CC Mode languages).
1470 t (if (c-lang-const c-line-comment-starter)
1471 (regexp-quote (c-lang-const c-line-comment-starter))
1472 "\\<\\>"))
1473 (c-lang-defvar c-line-comment-start-regexp
1474 (c-lang-const c-line-comment-start-regexp))
1476 (c-lang-defconst c-literal-start-regexp
1477 ;; Regexp to match the start of comments and string literals.
1478 t (concat (c-lang-const c-comment-start-regexp)
1479 "\\|"
1480 (if (memq 'gen-string-delim c-emacs-features)
1481 "\"|"
1482 "\"")))
1483 (c-lang-defvar c-literal-start-regexp (c-lang-const c-literal-start-regexp))
1485 (c-lang-defconst c-doc-comment-start-regexp
1486 "Regexp to match the start of documentation comments."
1487 t "\\<\\>"
1488 ;; From font-lock.el: `doxygen' uses /*! while others use /**.
1489 (c c++ objc) "/\\*[*!]"
1490 java "/\\*\\*"
1491 pike "/[/*]!")
1492 (c-lang-defvar c-doc-comment-start-regexp
1493 (c-lang-const c-doc-comment-start-regexp))
1495 (c-lang-defconst comment-start
1496 "String that starts comments inserted with M-; etc.
1497 `comment-start' is initialized from this."
1498 ;; Default: Prefer line comments to block comments, and pad with a space.
1499 t (concat (or (c-lang-const c-line-comment-starter)
1500 (c-lang-const c-block-comment-starter))
1501 " ")
1502 ;; In C we still default to the block comment style since line
1503 ;; comments aren't entirely portable.
1504 c "/* ")
1505 (c-lang-setvar comment-start (c-lang-const comment-start))
1507 (c-lang-defconst comment-end
1508 "String that ends comments inserted with M-; etc.
1509 `comment-end' is initialized from this."
1510 ;; Default: Use block comment style if comment-start uses block
1511 ;; comments, and pad with a space in that case.
1512 t (if (string-match (concat "\\`\\("
1513 (c-lang-const c-block-comment-start-regexp)
1514 "\\)")
1515 (c-lang-const comment-start))
1516 (concat " " (c-lang-const c-block-comment-ender))
1517 ""))
1518 (c-lang-setvar comment-end (c-lang-const comment-end))
1520 (c-lang-defconst comment-start-skip
1521 "Regexp to match the start of a comment plus everything up to its body.
1522 `comment-start-skip' is initialized from this."
1523 ;; Default: Allow the last char of the comment starter(s) to be
1524 ;; repeated, then allow any amount of horizontal whitespace.
1525 t (concat "\\("
1526 (c-concat-separated
1527 (mapcar (lambda (cs)
1528 (when cs
1529 (concat (regexp-quote cs) "+")))
1530 (list (c-lang-const c-line-comment-starter)
1531 (c-lang-const c-block-comment-starter)))
1532 "\\|")
1533 "\\)\\s *"))
1534 (c-lang-setvar comment-start-skip (c-lang-const comment-start-skip))
1536 (c-lang-defconst comment-end-can-be-escaped
1537 "When non-nil, escaped EOLs inside comments are valid.
1538 This works in Emacs >= 25.1."
1539 t nil
1540 (c c++ objc) t)
1541 (c-lang-setvar comment-end-can-be-escaped
1542 (c-lang-const comment-end-can-be-escaped))
1544 (c-lang-defconst c-syntactic-ws-start
1545 ;; Regexp matching any sequence that can start syntactic whitespace.
1546 ;; The only uncertain case is '#' when there are cpp directives.
1547 t (concat "\\s \\|"
1548 (c-make-keywords-re nil
1549 (append (list (c-lang-const c-line-comment-starter)
1550 (c-lang-const c-block-comment-starter)
1551 (when (c-lang-const c-opt-cpp-prefix)
1552 "#"))
1553 '("\n" "\r")))
1554 "\\|\\\\[\n\r]"
1555 (when (memq 'gen-comment-delim c-emacs-features)
1556 "\\|\\s!")))
1557 (c-lang-defvar c-syntactic-ws-start (c-lang-const c-syntactic-ws-start))
1559 (c-lang-defconst c-syntactic-ws-end
1560 ;; Regexp matching any single character that might end syntactic whitespace.
1561 t (concat "\\s \\|"
1562 (c-make-keywords-re nil
1563 (append (when (c-lang-const c-block-comment-ender)
1564 (list
1565 (string
1566 (elt (c-lang-const c-block-comment-ender)
1567 (1- (length
1568 (c-lang-const c-block-comment-ender)))))))
1569 '("\n" "\r")))
1570 (when (memq 'gen-comment-delim c-emacs-features)
1571 "\\|\\s!")))
1572 (c-lang-defvar c-syntactic-ws-end (c-lang-const c-syntactic-ws-end))
1574 (c-lang-defconst c-unterminated-block-comment-regexp
1575 ;; Regexp matching an unterminated block comment that doesn't
1576 ;; contain line breaks, or nil in languages without block comments.
1577 ;; Does not contain a \| operator at the top level.
1578 t (when (c-lang-const c-block-comment-starter)
1579 (concat
1580 (regexp-quote (c-lang-const c-block-comment-starter))
1581 ;; It's messy to cook together a regexp that matches anything
1582 ;; but c-block-comment-ender.
1583 (let ((end (c-lang-const c-block-comment-ender)))
1584 (cond ((= (length end) 1)
1585 (concat "[^" end "\n\r]*"))
1586 ((= (length end) 2)
1587 (concat "[^" (substring end 0 1) "\n\r]*"
1588 "\\("
1589 (regexp-quote (substring end 0 1)) "+"
1590 "[^"
1591 ;; The quoting rules inside char classes are silly. :P
1592 (cond ((= (elt end 0) (elt end 1))
1593 (concat (substring end 0 1) "\n\r"))
1594 ((= (elt end 1) ?\])
1595 (concat (substring end 1 2) "\n\r"
1596 (substring end 0 1)))
1598 (concat (substring end 0 1) "\n\r"
1599 (substring end 1 2))))
1601 "[^" (substring end 0 1) "\n\r]*"
1602 "\\)*"))
1604 (error "Can't handle a block comment ender of length %s"
1605 (length end))))))))
1607 (c-lang-defconst c-block-comment-regexp
1608 ;; Regexp matching a block comment that doesn't contain line breaks,
1609 ;; or nil in languages without block comments. The reason we don't
1610 ;; allow line breaks is to avoid going very far and risk running out
1611 ;; of regexp stack; this regexp is intended to handle only short
1612 ;; comments that might be put in the middle of limited constructs
1613 ;; like declarations. Does not contain a \| operator at the top
1614 ;; level.
1615 t (when (c-lang-const c-unterminated-block-comment-regexp)
1616 (concat
1617 (c-lang-const c-unterminated-block-comment-regexp)
1618 (let ((end (c-lang-const c-block-comment-ender)))
1619 (cond ((= (length end) 1)
1620 (regexp-quote end))
1621 ((= (length end) 2)
1622 (concat (regexp-quote (substring end 0 1)) "+"
1623 (regexp-quote (substring end 1 2))))
1625 (error "Can't handle a block comment ender of length %s"
1626 (length end))))))))
1628 (c-lang-defconst c-nonwhite-syntactic-ws
1629 ;; Regexp matching a piece of syntactic whitespace that isn't a
1630 ;; sequence of simple whitespace characters. As opposed to
1631 ;; `c-(forward|backward)-syntactic-ws', this doesn't regard cpp
1632 ;; directives as syntactic whitespace.
1633 t (c-concat-separated
1634 (list (when (c-lang-const c-line-comment-starter)
1635 (concat (regexp-quote (c-lang-const c-line-comment-starter))
1636 "[^\n\r]*[\n\r]"))
1637 (c-lang-const c-block-comment-regexp)
1638 "\\\\[\n\r]"
1639 (when (memq 'gen-comment-delim c-emacs-features)
1640 "\\s!\\S!*\\s!"))
1641 "\\|"))
1643 (c-lang-defconst c-syntactic-ws
1644 ;; Regexp matching syntactic whitespace, including possibly the
1645 ;; empty string. As opposed to `c-(forward|backward)-syntactic-ws',
1646 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1647 ;; not contain a \| operator at the top level.
1648 t (concat (c-lang-const c-simple-ws) "*"
1649 "\\("
1650 (concat "\\(" (c-lang-const c-nonwhite-syntactic-ws) "\\)"
1651 (c-lang-const c-simple-ws) "*")
1652 "\\)*"))
1654 (c-lang-defconst c-syntactic-ws-depth
1655 ;; Number of regexp grouping parens in `c-syntactic-ws'.
1656 t (regexp-opt-depth (c-lang-const c-syntactic-ws)))
1658 (c-lang-defconst c-nonempty-syntactic-ws
1659 ;; Regexp matching syntactic whitespace, which is at least one
1660 ;; character long. As opposed to `c-(forward|backward)-syntactic-ws',
1661 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1662 ;; not contain a \| operator at the top level.
1663 t (concat "\\("
1664 (c-lang-const c-simple-ws)
1665 "\\|"
1666 (c-lang-const c-nonwhite-syntactic-ws)
1667 "\\)+"))
1669 (c-lang-defconst c-nonempty-syntactic-ws-depth
1670 ;; Number of regexp grouping parens in `c-nonempty-syntactic-ws'.
1671 t (regexp-opt-depth (c-lang-const c-nonempty-syntactic-ws)))
1673 (c-lang-defconst c-single-line-syntactic-ws
1674 ;; Regexp matching syntactic whitespace without any line breaks. As
1675 ;; opposed to `c-(forward|backward)-syntactic-ws', this doesn't
1676 ;; regard cpp directives as syntactic whitespace. Does not contain
1677 ;; a \| operator at the top level.
1678 t (if (c-lang-const c-block-comment-regexp)
1679 (concat "\\s *\\("
1680 (c-lang-const c-block-comment-regexp)
1681 "\\s *\\)*")
1682 "\\s *"))
1684 (c-lang-defconst c-single-line-syntactic-ws-depth
1685 ;; Number of regexp grouping parens in `c-single-line-syntactic-ws'.
1686 t (regexp-opt-depth (c-lang-const c-single-line-syntactic-ws)))
1688 (c-lang-defconst c-syntactic-eol
1689 ;; Regexp that matches when there is no syntactically significant
1690 ;; text before eol. Macros are regarded as syntactically
1691 ;; significant text here.
1692 t (concat (c-lang-const c-single-line-syntactic-ws)
1693 ;; Match eol (possibly inside a block comment or preceded
1694 ;; by a line continuation backslash), or the beginning of a
1695 ;; line comment. Note: This has to be modified for awk
1696 ;; where line comments start with '#'.
1697 "\\("
1698 (c-concat-separated
1699 (list (when (c-lang-const c-line-comment-starter)
1700 (regexp-quote (c-lang-const c-line-comment-starter)))
1701 (when (c-lang-const c-unterminated-block-comment-regexp)
1702 (concat (c-lang-const c-unterminated-block-comment-regexp)
1703 "$"))
1704 "\\\\$"
1705 "$")
1706 "\\|")
1707 "\\)"))
1708 (c-lang-defvar c-syntactic-eol (c-lang-const c-syntactic-eol))
1711 ;;; Defun handling.
1713 ;; The Emacs variables beginning-of-defun-function and end-of-defun-function
1714 ;; will be set so that commands like `mark-defun' and `narrow-to-defun' work
1715 ;; right. In older Emacsen, the key sequences C-M-a and C-M-e are, however,
1716 ;; bound directly to the CC Mode functions, allowing optimization for large n.
1717 ;; From Emacs 23, this isn't necessary any more, since n is passed to the two
1718 ;; functions.
1719 (c-lang-defconst beginning-of-defun-function
1720 "Function to which beginning-of-defun-function will be set."
1721 t 'c-beginning-of-defun
1722 awk 'c-awk-beginning-of-defun)
1723 (c-lang-setvar beginning-of-defun-function
1724 (c-lang-const beginning-of-defun-function))
1726 (c-lang-defconst end-of-defun-function
1727 "Function to which end-of-defun-function will be set."
1728 t 'c-end-of-defun
1729 awk 'c-awk-end-of-defun)
1730 (c-lang-setvar end-of-defun-function (c-lang-const end-of-defun-function))
1732 ;;; In-comment text handling.
1734 (c-lang-defconst c-paragraph-start
1735 "Regexp to append to `paragraph-start'."
1736 t "$"
1737 java "\\(@[a-zA-Z]+\\>\\|$\\)" ; For Javadoc.
1738 pike "\\(@[a-zA-Z_-]+\\>\\([^{]\\|$\\)\\|$\\)") ; For Pike refdoc.
1739 (c-lang-defvar c-paragraph-start (c-lang-const c-paragraph-start))
1741 (c-lang-defconst c-paragraph-separate
1742 "Regexp to append to `paragraph-separate'."
1743 t "$"
1744 pike (c-lang-const c-paragraph-start))
1745 (c-lang-defvar c-paragraph-separate (c-lang-const c-paragraph-separate))
1748 ;;; Keyword lists.
1750 ;; Note: All and only all language constants containing keyword lists
1751 ;; should end with "-kwds"; they're automatically collected into the
1752 ;; `c-kwds-lang-consts' list below and used to build `c-keywords' etc.
1754 (c-lang-defconst c-primitive-type-kwds
1755 "Primitive type keywords. As opposed to the other keyword lists, the
1756 keywords listed here are fontified with the type face instead of the
1757 keyword face.
1759 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1760 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1761 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1762 will be handled.
1764 Do not try to modify this list for end user customizations; the
1765 `*-font-lock-extra-types' variable, where `*' is the mode prefix, is
1766 the appropriate place for that."
1767 t '("char" "double" "float" "int" "long" "short" "signed"
1768 "unsigned" "void")
1769 c (append
1770 '("_Bool" "_Complex" "_Imaginary") ; Conditionally defined in C99.
1771 (c-lang-const c-primitive-type-kwds))
1772 c++ (append
1773 '("bool" "wchar_t" "char16_t" "char32_t")
1774 (c-lang-const c-primitive-type-kwds))
1775 ;; Objective-C extends C, but probably not the new stuff in C99.
1776 objc (append
1777 '("id" "Class" "SEL" "IMP" "BOOL")
1778 (c-lang-const c-primitive-type-kwds))
1779 java '("boolean" "byte" "char" "double" "float" "int" "long" "short" "void")
1780 idl '("Object" "ValueBase" "any" "boolean" "char" "double" "fixed" "float"
1781 "long" "octet" "sequence" "short" "string" "void" "wchar" "wstring"
1782 ;; In CORBA PSDL:
1783 "ref"
1784 ;; The following can't really end a type, but we have to specify them
1785 ;; here due to the assumption in `c-primitive-type-prefix-kwds'. It
1786 ;; doesn't matter that much.
1787 "unsigned" "strong")
1788 pike '(;; this_program isn't really a keyword, but it's practically
1789 ;; used as a builtin type.
1790 "array" "float" "function" "int" "mapping" "mixed" "multiset"
1791 "object" "program" "string" "this_program" "void"))
1793 (c-lang-defconst c-return-kwds
1794 "Keywords which return a value to the calling function."
1795 t '("return")
1796 idl nil)
1798 (c-lang-defconst c-return-key
1799 ;; Adorned regexp matching `c-return-kwds'.
1800 t (c-make-keywords-re t (c-lang-const c-return-kwds)))
1801 (c-lang-defvar c-return-key (c-lang-const c-return-key))
1803 (c-lang-defconst c-primitive-type-key
1804 ;; An adorned regexp that matches `c-primitive-type-kwds'.
1805 t (c-make-keywords-re t (c-lang-const c-primitive-type-kwds)))
1806 (c-lang-defvar c-primitive-type-key (c-lang-const c-primitive-type-key))
1808 (c-lang-defconst c-primitive-type-prefix-kwds
1809 "Keywords that might act as prefixes for primitive types. Assumed to
1810 be a subset of `c-primitive-type-kwds'."
1811 t nil
1812 (c c++) '("long" "short" "signed" "unsigned")
1813 idl '("long" "unsigned"
1814 ;; In CORBA PSDL:
1815 "strong"))
1817 (c-lang-defconst c-typedef-kwds
1818 "Prefix keyword(s) like \"typedef\" which make a type declaration out
1819 of a variable declaration."
1820 t '("typedef")
1821 (awk idl java) nil)
1823 (c-lang-defconst c-typedef-key
1824 ;; Adorned regexp matching `c-typedef-kwds'.
1825 t (c-make-keywords-re t (c-lang-const c-typedef-kwds)))
1826 (c-lang-defvar c-typedef-key (c-lang-const c-typedef-key))
1828 (c-lang-defconst c-typeof-kwds
1829 "Keywords followed by a parenthesized expression, which stands for
1830 the type of that expression."
1831 t nil
1832 c '("typeof") ; longstanding GNU C(++) extension.
1833 c++ '("decltype" "typeof"))
1835 (c-lang-defconst c-typeof-key
1836 ;; Adorned regexp matching `c-typeof-kwds'.
1837 t (c-make-keywords-re t (c-lang-const c-typeof-kwds)))
1838 (c-lang-defvar c-typeof-key (c-lang-const c-typeof-key))
1840 (c-lang-defconst c-type-prefix-kwds
1841 "Keywords where the following name - if any - is a type name, and
1842 where the keyword together with the symbol works as a type in
1843 declarations.
1845 Note that an alternative if the second part doesn't hold is
1846 `c-type-list-kwds'. Keywords on this list are typically also present
1847 on one of the `*-decl-kwds' lists."
1848 t nil
1849 c '("struct" "union" "enum")
1850 c++ (append '("class" "typename")
1851 (c-lang-const c-type-prefix-kwds c)))
1853 (c-lang-defconst c-type-prefix-key
1854 ;; Adorned regexp matching `c-type-prefix-kwds'.
1855 t (c-make-keywords-re t (c-lang-const c-type-prefix-kwds)))
1856 (c-lang-defvar c-type-prefix-key (c-lang-const c-type-prefix-key))
1858 (c-lang-defconst c-type-modifier-kwds
1859 "Type modifier keywords. These can occur almost anywhere in types
1860 but they don't build a type of themselves. Unlike the keywords on
1861 `c-primitive-type-kwds', they are fontified with the keyword face and
1862 not the type face."
1863 t nil
1864 c '("const" "restrict" "volatile")
1865 c++ '("const" "noexcept" "volatile" "throw")
1866 objc '("const" "volatile"))
1868 (c-lang-defconst c-opt-type-modifier-key
1869 ;; Adorned regexp matching `c-type-modifier-kwds', or nil in
1870 ;; languages without such keywords.
1871 t (and (c-lang-const c-type-modifier-kwds)
1872 (c-make-keywords-re t (c-lang-const c-type-modifier-kwds))))
1873 (c-lang-defvar c-opt-type-modifier-key (c-lang-const c-opt-type-modifier-key))
1875 (c-lang-defconst c-opt-type-component-key
1876 ;; An adorned regexp that matches `c-primitive-type-prefix-kwds' and
1877 ;; `c-type-modifier-kwds', or nil in languages without any of them.
1878 t (and (or (c-lang-const c-primitive-type-prefix-kwds)
1879 (c-lang-const c-type-modifier-kwds))
1880 (c-make-keywords-re t
1881 (append (c-lang-const c-primitive-type-prefix-kwds)
1882 (c-lang-const c-type-modifier-kwds)))))
1883 (c-lang-defvar c-opt-type-component-key
1884 (c-lang-const c-opt-type-component-key))
1886 (c-lang-defconst c-type-start-kwds
1887 ;; All keywords that can start a type (i.e. are either a type prefix
1888 ;; or a complete type).
1889 t (c--delete-duplicates (append (c-lang-const c-primitive-type-kwds)
1890 (c-lang-const c-type-prefix-kwds)
1891 (c-lang-const c-type-modifier-kwds))
1892 :test 'string-equal))
1894 (c-lang-defconst c-type-decl-suffix-ws-ids-kwds
1895 "\"Identifiers\" that when immediately following a declarator have semantic
1896 effect in the declaration, but are syntactically like whitespace."
1897 t nil
1898 c++ '("final" "override"))
1900 (c-lang-defconst c-type-decl-suffix-ws-ids-key
1901 ;; An adorned regexp matching `c-type-decl-suffix-ws-ids-kwds'.
1902 t (c-make-keywords-re t (c-lang-const c-type-decl-suffix-ws-ids-kwds)))
1903 (c-lang-defvar c-type-decl-suffix-ws-ids-key
1904 (c-lang-const c-type-decl-suffix-ws-ids-key))
1906 (c-lang-defconst c-class-decl-kwds
1907 "Keywords introducing declarations where the following block (if any)
1908 contains another declaration level that should be considered a class.
1910 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1911 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1912 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1913 will be handled.
1915 Note that presence on this list does not automatically treat the
1916 following identifier as a type; the keyword must also be present on
1917 `c-type-prefix-kwds' or `c-type-list-kwds' to accomplish that."
1918 t nil
1919 c '("struct" "union")
1920 c++ '("class" "struct" "union")
1921 objc '("struct" "union"
1922 "@interface" "@implementation" "@protocol")
1923 java '("class" "@interface" "interface")
1924 idl '("component" "eventtype" "exception" "home" "interface" "struct"
1925 "union" "valuetype"
1926 ;; In CORBA PSDL:
1927 "storagehome" "storagetype"
1928 ;; In CORBA CIDL:
1929 "catalog" "executor" "manages" "segment")
1930 pike '("class"))
1932 (c-lang-defconst c-class-key
1933 ;; Regexp matching the start of a class.
1934 t (c-make-keywords-re t (c-lang-const c-class-decl-kwds)))
1935 (c-lang-defvar c-class-key (c-lang-const c-class-key))
1937 (c-lang-defconst c-brace-list-decl-kwds
1938 "Keywords introducing declarations where the following block (if
1939 any) is a brace list.
1941 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1942 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1943 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1944 will be handled."
1945 t '("enum")
1946 (awk) nil)
1948 (c-lang-defconst c-brace-list-key
1949 ;; Regexp matching the start of declarations where the following
1950 ;; block is a brace list.
1951 t (c-make-keywords-re t (c-lang-const c-brace-list-decl-kwds)))
1952 (c-lang-defvar c-brace-list-key (c-lang-const c-brace-list-key))
1954 (c-lang-defconst c-after-brace-list-decl-kwds
1955 "Keywords that might follow keywords in `c-brace-list-decl-kwds'
1956 and precede the opening brace."
1957 t nil
1958 c++ '("class" "struct"))
1960 (c-lang-defconst c-after-brace-list-key
1961 ;; Regexp matching keywords that can fall between a brace-list
1962 ;; keyword and the associated brace list.
1963 t (c-make-keywords-re t (c-lang-const c-after-brace-list-decl-kwds)))
1964 (c-lang-defvar c-after-brace-list-key (c-lang-const c-after-brace-list-key))
1966 (c-lang-defconst c-recognize-post-brace-list-type-p
1967 "Set to t when we recognize a colon and then a type after an enum,
1968 e.g., enum foo : int { A, B, C };"
1969 t nil
1970 c++ t)
1971 (c-lang-defvar c-recognize-post-brace-list-type-p
1972 (c-lang-const c-recognize-post-brace-list-type-p))
1974 (c-lang-defconst c-other-block-decl-kwds
1975 "Keywords where the following block (if any) contains another
1976 declaration level that should not be considered a class. For every
1977 keyword here, CC Mode will add a set of special syntactic symbols for
1978 those blocks. E.g. if the keyword is \"foo\" then there will be
1979 `foo-open', `foo-close', and `infoo' symbols.
1981 The intention is that this category should be used for block
1982 constructs that aren't related to object orientation concepts like
1983 classes (which thus also include e.g. interfaces, templates,
1984 contracts, structs, etc). The more pragmatic distinction is that
1985 while most want some indentation inside classes, it's fairly common
1986 that they don't want it in some of these constructs, so it should be
1987 simple to configure that differently from classes. See also
1988 `c-class-decl-kwds'.
1990 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1991 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1992 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1993 will be handled."
1994 t nil
1995 (c objc) '("extern")
1996 c++ '("namespace" "extern")
1997 idl '("module"
1998 ;; In CORBA CIDL:
1999 "composition"))
2001 (c-lang-defconst c-other-decl-block-key
2002 ;; Regexp matching the start of blocks besides classes that contain
2003 ;; another declaration level.
2004 t (c-make-keywords-re t (c-lang-const c-other-block-decl-kwds)))
2005 (c-lang-defvar c-other-decl-block-key (c-lang-const c-other-decl-block-key))
2007 (c-lang-defvar c-other-decl-block-key-in-symbols-alist
2008 (mapcar
2009 (lambda (elt)
2010 (cons elt
2011 (if (string= elt "extern")
2012 'inextern-lang
2013 (intern (concat "in" elt)))))
2014 (c-lang-const c-other-block-decl-kwds))
2015 "Alist associating keywords in c-other-decl-block-decl-kwds with
2016 their matching \"in\" syntactic symbols.")
2018 (c-lang-defconst c-typedef-decl-kwds
2019 "Keywords introducing declarations where the identifier(s) being
2020 declared are types.
2022 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
2023 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
2024 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
2025 will be handled."
2026 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
2027 ;; (since e.g. "Foo" is a type that's being defined in "class Foo
2028 ;; {...}").
2029 t (append (c-lang-const c-class-decl-kwds)
2030 (c-lang-const c-brace-list-decl-kwds))
2031 ;; Languages that have a "typedef" construct.
2032 (c c++ objc idl pike) (append (c-lang-const c-typedef-decl-kwds)
2033 '("typedef"))
2034 ;; Unlike most other languages, exception names are not handled as
2035 ;; types in IDL since they only can occur in "raises" specs.
2036 idl (delete "exception" (append (c-lang-const c-typedef-decl-kwds) nil)))
2038 (c-lang-defconst c-typedef-decl-key
2039 t (c-make-keywords-re t (c-lang-const c-typedef-decl-kwds)))
2040 (c-lang-defvar c-typedef-decl-key (c-lang-const c-typedef-decl-key))
2042 (c-lang-defconst c-typeless-decl-kwds
2043 "Keywords introducing declarations where the \(first) identifier
2044 \(declarator) follows directly after the keyword, without any type.
2046 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
2047 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
2048 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
2049 will be handled."
2050 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
2051 ;; (since e.g. "Foo" is the identifier being defined in "class Foo
2052 ;; {...}").
2053 t (append (c-lang-const c-class-decl-kwds)
2054 (c-lang-const c-brace-list-decl-kwds))
2055 c++ (append (c-lang-const c-typeless-decl-kwds) '("auto")) ; C++11.
2056 ;; Note: "manages" for CORBA CIDL clashes with its presence on
2057 ;; `c-type-list-kwds' for IDL.
2058 idl (append (c-lang-const c-typeless-decl-kwds)
2059 '("factory" "finder" "native"
2060 ;; In CORBA PSDL:
2061 "key" "stores"
2062 ;; In CORBA CIDL:
2063 "facet"))
2064 pike (append (c-lang-const c-class-decl-kwds)
2065 '("constant")))
2067 (c-lang-defconst c-modifier-kwds
2068 "Keywords that can prefix normal declarations of identifiers
2069 \(and typically act as flags). Things like argument declarations
2070 inside function headers are also considered declarations in this
2071 sense.
2073 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
2074 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
2075 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
2076 will be handled."
2077 t nil
2078 (c c++) '("auto" "extern" "inline" "register" "static")
2079 c++ (append '("constexpr" "explicit" "friend" "mutable" "template"
2080 "thread_local" "using" "virtual")
2081 (c-lang-const c-modifier-kwds))
2082 objc '("auto" "bycopy" "byref" "extern" "in" "inout" "oneway" "out" "static")
2083 ;; FIXME: Some of those below ought to be on `c-other-decl-kwds' instead.
2084 idl '("abstract" "attribute" "const" "consumes" "custom" "emits" "import"
2085 "in" "inout" "local" "multiple" "oneway" "out" "private" "provides"
2086 "public" "publishes" "readonly" "typeid" "typeprefix" "uses"
2087 ;; In CORBA PSDL:
2088 "primary" "state"
2089 ;; In CORBA CIDL:
2090 "bindsTo" "delegatesTo" "implements" "proxy" "storedOn")
2091 ;; Note: "const" is not used in Java, but it's still a reserved keyword.
2092 java '("abstract" "const" "default" "final" "native" "private" "protected"
2093 "public" "static" "strictfp" "synchronized" "transient" "volatile")
2094 pike '("final" "inline" "local" "nomask" "optional" "private" "protected"
2095 "public" "static" "variant"))
2097 (c-lang-defconst c-other-decl-kwds
2098 "Keywords that can start or prefix any declaration level construct,
2099 besides those on `c-class-decl-kwds', `c-brace-list-decl-kwds',
2100 `c-other-block-decl-kwds', `c-typedef-decl-kwds',
2101 `c-typeless-decl-kwds' and `c-modifier-kwds'.
2103 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
2104 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
2105 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
2106 will be handled."
2107 t nil
2108 objc '("@class" "@end" "@defs")
2109 java '("import" "package")
2110 pike '("import" "inherit"))
2112 (c-lang-defconst c-decl-start-kwds
2113 "Keywords that always start declarations, wherever they occur.
2114 This can be used for declarations that aren't recognized by the normal
2115 combination of `c-decl-prefix-re' and `c-decl-start-re'."
2116 t nil
2117 ;; Classes can be declared anywhere in a Pike expression.
2118 pike '("class"))
2120 (c-lang-defconst c-decl-hangon-kwds
2121 "Keywords that can occur anywhere in a declaration level construct.
2122 This is used for self-contained things that can be tacked on anywhere
2123 on a declaration and that should be ignored to be able to recognize it
2124 correctly. Typical cases are compiler extensions like
2125 \"__attribute__\" or \"__declspec\":
2127 __declspec(noreturn) void foo();
2128 class __declspec(dllexport) classname {...};
2129 void foo() __attribute__((noreturn));
2131 Note that unrecognized plain symbols are skipped anyway if they occur
2132 before the type, so such things are not necessary to mention here.
2133 Mentioning them here is necessary only if they can occur in other
2134 places, or if they are followed by a construct that must be skipped
2135 over \(like the parens in the \"__attribute__\" and \"__declspec\"
2136 examples above). In the last case, they alse need to be present on
2137 one of `c-type-list-kwds', `c-ref-list-kwds',
2138 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
2139 `c-<>-type-kwds', or `c-<>-arglist-kwds'."
2140 ;; NB: These are currently not recognized in all parts of a
2141 ;; declaration. Specifically, they aren't recognized in the middle
2142 ;; of multi-token types, inside declarators, and between the
2143 ;; identifier and the arglist paren of a function declaration.
2145 ;; FIXME: This ought to be user customizable since compiler stuff
2146 ;; like this usually is wrapped in project specific macros. (It'd
2147 ;; of course be even better if we could cope without knowing this.)
2148 t nil
2149 (c c++) '(;; GCC extension.
2150 "__attribute__"
2151 ;; MSVC extension.
2152 "__declspec"))
2154 (c-lang-defconst c-decl-hangon-key
2155 ;; Adorned regexp matching `c-decl-hangon-kwds'.
2156 t (c-make-keywords-re t (c-lang-const c-decl-hangon-kwds)))
2157 (c-lang-defvar c-decl-hangon-key (c-lang-const c-decl-hangon-key))
2159 (c-lang-defconst c-prefix-spec-kwds
2160 ;; All keywords that can occur in the preamble of a declaration.
2161 ;; They typically occur before the type, but they are also matched
2162 ;; after presumptive types since we often can't be sure that
2163 ;; something is a type or just some sort of macro in front of the
2164 ;; declaration. They might be ambiguous with types or type
2165 ;; prefixes.
2166 t (c--delete-duplicates (append (c-lang-const c-class-decl-kwds)
2167 (c-lang-const c-brace-list-decl-kwds)
2168 (c-lang-const c-other-block-decl-kwds)
2169 (c-lang-const c-typedef-decl-kwds)
2170 (c-lang-const c-typeless-decl-kwds)
2171 (c-lang-const c-modifier-kwds)
2172 (c-lang-const c-other-decl-kwds)
2173 (c-lang-const c-decl-start-kwds)
2174 (c-lang-const c-decl-hangon-kwds))
2175 :test 'string-equal))
2177 (c-lang-defconst c-prefix-spec-kwds-re
2178 ;; Adorned regexp of `c-prefix-spec-kwds'.
2179 t (c-make-keywords-re t (c-lang-const c-prefix-spec-kwds)))
2181 (c-lang-defvar c-prefix-spec-kwds-re (c-lang-const c-prefix-spec-kwds-re))
2183 (c-lang-defconst c-specifier-key
2184 ;; Adorned regexp of the keywords in `c-prefix-spec-kwds' that aren't
2185 ;; ambiguous with types or type prefixes. These are the keywords (like
2186 ;; extern, namespace, but NOT template) that can modify a declaration.
2187 t (c-make-keywords-re t
2188 (c--set-difference (c-lang-const c-prefix-spec-kwds)
2189 (append (c-lang-const c-type-start-kwds)
2190 (c-lang-const c-<>-arglist-kwds))
2191 :test 'string-equal)))
2192 (c-lang-defvar c-specifier-key (c-lang-const c-specifier-key))
2194 (c-lang-defconst c-postfix-spec-kwds
2195 ;; Keywords that can occur after argument list of a function header
2196 ;; declaration, i.e. in the "K&R region".
2197 t (append (c-lang-const c-postfix-decl-spec-kwds)
2198 (c-lang-const c-decl-hangon-kwds)))
2200 (c-lang-defconst c-not-decl-init-keywords
2201 ;; Adorned regexp matching all keywords that can't appear at the
2202 ;; start of a declaration.
2203 t (c-make-keywords-re t
2204 (c--set-difference (c-lang-const c-keywords)
2205 (append (c-lang-const c-type-start-kwds)
2206 (c-lang-const c-prefix-spec-kwds)
2207 (c-lang-const c-typeof-kwds))
2208 :test 'string-equal)))
2209 (c-lang-defvar c-not-decl-init-keywords
2210 (c-lang-const c-not-decl-init-keywords))
2212 (c-lang-defconst c-not-primitive-type-keywords
2213 "List of all keywords apart from primitive types (like \"int\")."
2214 t (c--set-difference (c-lang-const c-keywords)
2215 (c-lang-const c-primitive-type-kwds)
2216 :test 'string-equal)
2217 ;; The "more" for C++ is the QT keyword (as in "more slots:").
2218 ;; This variable is intended for use in c-beginning-of-statement-1.
2219 c++ (append (c-lang-const c-not-primitive-type-keywords) '("more")))
2221 (c-lang-defconst c-not-primitive-type-keywords-regexp
2222 t (c-make-keywords-re t
2223 (c-lang-const c-not-primitive-type-keywords)))
2224 (c-lang-defvar c-not-primitive-type-keywords-regexp
2225 (c-lang-const c-not-primitive-type-keywords-regexp))
2227 (c-lang-defconst c-protection-kwds
2228 "Access protection label keywords in classes."
2229 t nil
2230 c++ '("private" "protected" "public")
2231 objc '("@private" "@protected" "@public"))
2233 (c-lang-defconst c-block-decls-with-vars
2234 "Keywords introducing declarations that can contain a block which
2235 might be followed by variable declarations, e.g. like \"foo\" in
2236 \"class Foo { ... } foo;\". So if there is a block in a declaration
2237 like that, it ends with the following `;' and not right away.
2239 The keywords on list are assumed to also be present on one of the
2240 `*-decl-kwds' lists."
2241 t nil
2242 (c objc) '("struct" "union" "enum" "typedef")
2243 c++ '("class" "struct" "union" "enum" "typedef"))
2245 (c-lang-defconst c-opt-block-decls-with-vars-key
2246 ;; Regexp matching the `c-block-decls-with-vars' keywords, or nil in
2247 ;; languages without such constructs.
2248 t (and (c-lang-const c-block-decls-with-vars)
2249 (c-make-keywords-re t (c-lang-const c-block-decls-with-vars))))
2250 (c-lang-defvar c-opt-block-decls-with-vars-key
2251 (c-lang-const c-opt-block-decls-with-vars-key))
2253 (c-lang-defconst c-postfix-decl-spec-kwds
2254 "Keywords introducing extra declaration specifiers in the region
2255 between the header and the body \(i.e. the \"K&R-region\") in
2256 declarations."
2257 t nil
2258 java '("extends" "implements" "throws")
2259 idl '("context" "getraises" "manages" "primarykey" "raises" "setraises"
2260 "supports"
2261 ;; In CORBA PSDL:
2262 "as" "const" "implements" "of" "ref"))
2264 (c-lang-defconst c-postfix-decl-spec-key
2265 ;; Regexp matching the keywords in `c-postfix-decl-spec-kwds'.
2266 t (c-make-keywords-re t (c-lang-const c-postfix-decl-spec-kwds)))
2267 (c-lang-defvar c-postfix-decl-spec-key
2268 (c-lang-const c-postfix-decl-spec-key))
2270 (c-lang-defconst c-nonsymbol-sexp-kwds
2271 "Keywords that may be followed by a nonsymbol sexp before whatever
2272 construct it's part of continues."
2273 t nil
2274 (c c++ objc) '("extern"))
2276 (c-lang-defconst c-type-list-kwds
2277 "Keywords that may be followed by a comma separated list of type
2278 identifiers, where each optionally can be prefixed by keywords. (Can
2279 also be used for the special case when the list can contain only one
2280 element.)
2282 Assumed to be mutually exclusive with `c-ref-list-kwds'. There's no
2283 reason to put keywords on this list if they are on `c-type-prefix-kwds'.
2284 There's also no reason to add keywords that prefixes a normal
2285 declaration consisting of a type followed by a declarator (list), so
2286 the keywords on `c-modifier-kwds' should normally not be listed here
2287 either.
2289 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
2290 or variable identifier (that's being defined)."
2291 t nil
2292 c++ '("operator")
2293 objc '("@class")
2294 java '("import" "new" "extends" "super" "implements" "throws")
2295 idl '("manages" "native" "primarykey" "supports"
2296 ;; In CORBA PSDL:
2297 "as" "implements" "of" "scope")
2298 pike '("inherit"))
2300 (c-lang-defconst c-ref-list-kwds
2301 "Keywords that may be followed by a comma separated list of
2302 reference (i.e. namespace/scope/module) identifiers, where each
2303 optionally can be prefixed by keywords. (Can also be used for the
2304 special case when the list can contain only one element.) Assumed to
2305 be mutually exclusive with `c-type-list-kwds'.
2307 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
2308 or variable identifier (that's being defined)."
2309 t nil
2310 c++ '("namespace")
2311 java '("package")
2312 idl '("import" "module"
2313 ;; In CORBA CIDL:
2314 "composition")
2315 pike '("import"))
2317 (c-lang-defconst c-colon-type-list-kwds
2318 "Keywords that may be followed (not necessarily directly) by a colon
2319 and then a comma separated list of type identifiers, where each
2320 optionally can be prefixed by keywords. (Can also be used for the
2321 special case when the list can contain only one element.)"
2322 t nil
2323 c++ '("class" "struct")
2324 idl '("component" "eventtype" "home" "interface" "valuetype"
2325 ;; In CORBA PSDL:
2326 "storagehome" "storagetype"))
2328 (c-lang-defconst c-colon-type-list-re
2329 "Regexp matched after the keywords in `c-colon-type-list-kwds' to skip
2330 forward to the colon. The end of the match is assumed to be directly
2331 after the colon, so the regexp should end with \":\". Must be a
2332 regexp if `c-colon-type-list-kwds' isn't nil."
2333 t (if (c-lang-const c-colon-type-list-kwds)
2334 ;; Disallow various common punctuation chars that can't come
2335 ;; before the ":" that starts the inherit list after "class"
2336 ;; or "struct" in C++. (Also used as default for other
2337 ;; languages.)
2338 "[^][{}();,/#=:]*:"))
2339 (c-lang-defvar c-colon-type-list-re (c-lang-const c-colon-type-list-re))
2341 (c-lang-defconst c-paren-nontype-kwds
2342 "Keywords that may be followed by a parenthesis expression that doesn't
2343 contain type identifiers."
2344 t nil
2345 (c c++) '(;; GCC extension.
2346 "__attribute__"
2347 ;; MSVC extension.
2348 "__declspec")
2349 c++ (append (c-lang-const c-paren-nontype-kwds) '("noexcept")))
2351 (c-lang-defconst c-paren-nontype-key
2352 t (c-make-keywords-re t (c-lang-const c-paren-nontype-kwds)))
2353 (c-lang-defvar c-paren-nontype-key (c-lang-const c-paren-nontype-key))
2355 (c-lang-defconst c-paren-type-kwds
2356 "Keywords that may be followed by a parenthesis expression containing
2357 type identifiers separated by arbitrary tokens."
2358 t nil
2359 c++ '("throw")
2360 objc '("@defs")
2361 idl '("switch")
2362 pike '("array" "function" "int" "mapping" "multiset" "object" "program"))
2364 (c-lang-defconst c-paren-any-kwds
2365 t (c--delete-duplicates (append (c-lang-const c-paren-nontype-kwds)
2366 (c-lang-const c-paren-type-kwds))
2367 :test 'string-equal))
2369 (c-lang-defconst c-<>-type-kwds
2370 "Keywords that may be followed by an angle bracket expression
2371 containing type identifiers separated by \",\". The difference from
2372 `c-<>-arglist-kwds' is that unknown names are taken to be types and
2373 not other identifiers. `c-recognize-<>-arglists' is assumed to be set
2374 if this isn't nil."
2375 t nil
2376 objc '("id")
2377 idl '("sequence"
2378 ;; In CORBA PSDL:
2379 "ref"))
2381 (c-lang-defconst c-<>-arglist-kwds
2382 "Keywords that can be followed by a C++ style template arglist; see
2383 `c-recognize-<>-arglists' for details. That language constant is
2384 assumed to be set if this isn't nil."
2385 t nil
2386 c++ '("template")
2387 idl '("fixed" "string" "wstring"))
2389 (c-lang-defconst c-<>-sexp-kwds
2390 ;; All keywords that can be followed by an angle bracket sexp.
2391 t (c--delete-duplicates (append (c-lang-const c-<>-type-kwds)
2392 (c-lang-const c-<>-arglist-kwds))
2393 :test 'string-equal))
2395 (c-lang-defconst c-opt-<>-sexp-key
2396 ;; Adorned regexp matching keywords that can be followed by an angle
2397 ;; bracket sexp. Always set when `c-recognize-<>-arglists' is.
2398 t (c-make-keywords-re t (c-lang-const c-<>-sexp-kwds)))
2399 (c-lang-defvar c-opt-<>-sexp-key (c-lang-const c-opt-<>-sexp-key))
2401 (c-lang-defconst c-inside-<>-type-kwds
2402 "Keywords which, used inside a C++ style template arglist, introduce a type."
2403 t nil
2404 java '("extends" "super"))
2406 (c-lang-defconst c-inside-<>-type-key
2407 t (c-make-keywords-re t (c-lang-const c-inside-<>-type-kwds)))
2408 (c-lang-defvar c-inside-<>-type-key (c-lang-const c-inside-<>-type-key))
2410 (c-lang-defconst c-brace-id-list-kwds
2411 "Keywords that may be followed by a brace block containing a comma
2412 separated list of identifier definitions, i.e. like the list of
2413 identifiers that follows the type in a normal declaration."
2414 t (c-lang-const c-brace-list-decl-kwds))
2416 (c-lang-defconst c-block-stmt-1-kwds
2417 "Statement keywords followed directly by a substatement."
2418 t '("do" "else")
2419 c++ '("do" "else" "try")
2420 objc '("do" "else" "@finally" "@try")
2421 java '("do" "else" "finally" "try")
2422 idl nil)
2424 (c-lang-defconst c-block-stmt-1-key
2425 ;; Regexp matching the start of any statement followed directly by a
2426 ;; substatement (doesn't match a bare block, however).
2427 t (c-make-keywords-re t (c-lang-const c-block-stmt-1-kwds)))
2428 (c-lang-defvar c-block-stmt-1-key (c-lang-const c-block-stmt-1-key))
2430 (c-lang-defconst c-block-stmt-1-2-kwds
2431 "Statement keywords optionally followed by a paren sexp.
2432 Keywords here should also be in `c-block-stmt-1-kwds'."
2433 t nil
2434 java '("try"))
2436 (c-lang-defconst c-block-stmt-1-2-key
2437 ;; Regexp matching the start of a statement which may be followed by a
2438 ;; paren sexp and will then be followed by a substatement.
2439 t (c-make-keywords-re t (c-lang-const c-block-stmt-1-2-kwds)))
2440 (c-lang-defvar c-block-stmt-1-2-key (c-lang-const c-block-stmt-1-2-key))
2442 (c-lang-defconst c-block-stmt-2-kwds
2443 "Statement keywords followed by a paren sexp and then by a substatement."
2444 t '("for" "if" "switch" "while")
2445 c++ '("for" "if" "switch" "while" "catch")
2446 objc '("for" "if" "switch" "while" "@catch" "@synchronized")
2447 java '("for" "if" "switch" "while" "catch" "synchronized")
2448 idl nil
2449 pike '("for" "if" "switch" "while" "foreach")
2450 awk '("for" "if" "while"))
2452 (c-lang-defconst c-block-stmt-2-key
2453 ;; Regexp matching the start of any statement followed by a paren sexp
2454 ;; and then by a substatement.
2455 t (c-make-keywords-re t (c-lang-const c-block-stmt-2-kwds)))
2456 (c-lang-defvar c-block-stmt-2-key (c-lang-const c-block-stmt-2-key))
2458 (c-lang-defconst c-block-stmt-kwds
2459 ;; Union of `c-block-stmt-1-kwds' and `c-block-stmt-2-kwds'.
2460 t (c--delete-duplicates (append (c-lang-const c-block-stmt-1-kwds)
2461 (c-lang-const c-block-stmt-2-kwds))
2462 :test 'string-equal))
2464 (c-lang-defconst c-opt-block-stmt-key
2465 ;; Regexp matching the start of any statement that has a
2466 ;; substatement (except a bare block). Nil in languages that
2467 ;; don't have such constructs.
2468 t (if (or (c-lang-const c-block-stmt-1-kwds)
2469 (c-lang-const c-block-stmt-2-kwds))
2470 (c-make-keywords-re t
2471 (append (c-lang-const c-block-stmt-1-kwds)
2472 (c-lang-const c-block-stmt-2-kwds)))))
2473 (c-lang-defvar c-opt-block-stmt-key (c-lang-const c-opt-block-stmt-key))
2475 (c-lang-defconst c-simple-stmt-kwds
2476 "Statement keywords followed by an expression or nothing."
2477 t '("break" "continue" "goto" "return")
2478 objc '("break" "continue" "goto" "return" "@throw")
2479 ;; Note: `goto' is not valid in Java, but the keyword is still reserved.
2480 java '("break" "continue" "goto" "return" "throw")
2481 idl nil
2482 pike '("break" "continue" "return")
2483 awk '(;; Not sure about "delete", "exit", "getline", etc. ; ACM 2002/5/30
2484 "break" "continue" "return" "delete" "exit" "getline" "next"
2485 "nextfile" "print" "printf"))
2487 (c-lang-defconst c-simple-stmt-key
2488 ;; Adorned regexp matching `c-simple-stmt-kwds'.
2489 t (c-make-keywords-re t (c-lang-const c-simple-stmt-kwds)))
2490 (c-lang-defvar c-simple-stmt-key (c-lang-const c-simple-stmt-key))
2492 (c-lang-defconst c-paren-stmt-kwds
2493 "Statement keywords followed by a parenthesis expression that
2494 nevertheless contains a list separated with `;' and not `,'."
2495 t '("for")
2496 idl nil)
2498 (c-lang-defconst c-paren-stmt-key
2499 ;; Adorned regexp matching `c-paren-stmt-kwds'.
2500 t (c-make-keywords-re t (c-lang-const c-paren-stmt-kwds)))
2501 (c-lang-defvar c-paren-stmt-key (c-lang-const c-paren-stmt-key))
2503 (c-lang-defconst c-asm-stmt-kwds
2504 "Statement keywords followed by an assembler expression."
2505 t nil
2506 (c c++) '("asm" "__asm__")) ;; Not standard, but common.
2508 (c-lang-defconst c-opt-asm-stmt-key
2509 ;; Regexp matching the start of an assembler statement. Nil in
2510 ;; languages that don't support that.
2511 t (if (c-lang-const c-asm-stmt-kwds)
2512 (c-make-keywords-re t (c-lang-const c-asm-stmt-kwds))))
2513 (c-lang-defvar c-opt-asm-stmt-key (c-lang-const c-opt-asm-stmt-key))
2515 (c-lang-defconst c-case-kwds
2516 "The keyword(s) which introduce a \"case\" like construct.
2517 This construct is \"<keyword> <expression> :\"."
2518 t '("case")
2519 awk nil)
2521 (c-lang-defconst c-case-kwds-regexp
2522 ;; Adorned regexp matching any "case"-like keyword.
2523 t (c-make-keywords-re t (c-lang-const c-case-kwds)))
2524 (c-lang-defvar c-case-kwds-regexp (c-lang-const c-case-kwds-regexp))
2526 (c-lang-defconst c-label-kwds
2527 "Keywords introducing colon terminated labels in blocks."
2528 t '("case" "default"))
2530 (c-lang-defconst c-label-kwds-regexp
2531 ;; Adorned regexp matching any keyword that introduces a label.
2532 t (c-make-keywords-re t (c-lang-const c-label-kwds)))
2533 (c-lang-defvar c-label-kwds-regexp (c-lang-const c-label-kwds-regexp))
2535 (c-lang-defconst c-before-label-kwds
2536 "Keywords that might be followed by a label identifier."
2537 t '("goto")
2538 (java pike) (append '("break" "continue")
2539 (c-lang-const c-before-label-kwds))
2540 idl nil
2541 awk nil)
2543 (c-lang-defconst c-constant-kwds
2544 "Keywords for constants."
2545 t nil
2546 c '("NULL" ;; Not a keyword, but practically works as one.
2547 "false" "true") ; Defined in C99.
2548 c++ (append
2549 '("nullptr")
2550 (c-lang-const c-constant-kwds c))
2551 objc '("nil" "Nil" "YES" "NO" "NS_DURING" "NS_HANDLER" "NS_ENDHANDLER")
2552 idl '("TRUE" "FALSE")
2553 java '("true" "false" "null") ; technically "literals", not keywords
2554 pike '("UNDEFINED")) ;; Not a keyword, but practically works as one.
2556 (c-lang-defconst c-primary-expr-kwds
2557 "Keywords besides constants and operators that start primary expressions."
2558 t nil
2559 c++ '("operator" "this")
2560 objc '("super" "self")
2561 java '("this")
2562 pike '("this")) ;; Not really a keyword, but practically works as one.
2564 (c-lang-defconst c-expr-kwds
2565 ;; Keywords that can occur anywhere in expressions. Built from
2566 ;; `c-primary-expr-kwds' and all keyword operators in `c-operators'.
2567 t (c--delete-duplicates
2568 (append (c-lang-const c-primary-expr-kwds)
2569 (c-filter-ops (c-lang-const c-operator-list)
2571 "\\`\\(\\w\\|\\s_\\)+\\'"))
2572 :test 'string-equal))
2574 (c-lang-defconst c-lambda-kwds
2575 "Keywords that start lambda constructs, i.e. function definitions in
2576 expressions."
2577 t nil
2578 pike '("lambda"))
2580 (c-lang-defconst c-inexpr-block-kwds
2581 "Keywords that start constructs followed by statement blocks which can
2582 be used in expressions \(the gcc extension for this in C and C++ is
2583 handled separately by `c-recognize-paren-inexpr-blocks')."
2584 t nil
2585 pike '("catch" "gauge"))
2587 (c-lang-defconst c-inexpr-class-kwds
2588 "Keywords that can start classes inside expressions."
2589 t nil
2590 java '("new")
2591 pike '("class"))
2593 (c-lang-defconst c-inexpr-brace-list-kwds
2594 "Keywords that can start brace list blocks inside expressions.
2595 Note that Java specific rules are currently applied to tell this from
2596 `c-inexpr-class-kwds'."
2597 t nil
2598 java '("new"))
2600 (c-lang-defconst c-opt-inexpr-brace-list-key
2601 ;; Regexp matching the start of a brace list in an expression, or
2602 ;; nil in languages that don't have such things. This should not
2603 ;; match brace lists recognized through `c-special-brace-lists'.
2604 t (and (c-lang-const c-inexpr-brace-list-kwds)
2605 (c-make-keywords-re t (c-lang-const c-inexpr-brace-list-kwds))))
2606 (c-lang-defvar c-opt-inexpr-brace-list-key
2607 (c-lang-const c-opt-inexpr-brace-list-key))
2609 (c-lang-defconst c-flat-decl-block-kwds
2610 ;; Keywords that can introduce another declaration level, i.e. where a
2611 ;; following "{" isn't a function block or brace list. Note that, for
2612 ;; historical reasons, `c-decl-block-key' is NOT constructed from this lang
2613 ;; const.
2614 t (c--delete-duplicates
2615 (append (c-lang-const c-class-decl-kwds)
2616 (c-lang-const c-other-block-decl-kwds)
2617 (c-lang-const c-inexpr-class-kwds))
2618 :test 'string-equal))
2620 (c-lang-defconst c-brace-stack-thing-key
2621 ;; Regexp matching any keyword or operator relevant to the brace stack (see
2622 ;; `c-update-brace-stack' in cc-engine.el).
2623 t (c-make-keywords-re 'appendable
2624 (append
2625 (c-lang-const c-flat-decl-block-kwds)
2626 (if (c-lang-const c-recognize-<>-arglists)
2627 '("{" "}" ";" "," ")" ":" "<")
2628 '("{" "}" ";" "," ")" ":")))))
2629 (c-lang-defvar c-brace-stack-thing-key (c-lang-const c-brace-stack-thing-key))
2631 (c-lang-defconst c-brace-stack-no-semi-key
2632 ;; Regexp matching any keyword or operator relevant to the brace stack when
2633 ;; a semicolon is not relevant (see `c-update-brace-stack' in
2634 ;; cc-engine.el).
2635 t (c-make-keywords-re 'appendable
2636 (append
2637 (c-lang-const c-flat-decl-block-kwds)
2638 (if (c-lang-const c-recognize-<>-arglists)
2639 '("{" "}" "<")
2640 '("{" "}")))))
2641 (c-lang-defvar c-brace-stack-no-semi-key
2642 (c-lang-const c-brace-stack-no-semi-key))
2644 (c-lang-defconst c-decl-block-key
2645 ;; Regexp matching keywords in any construct that contain another
2646 ;; declaration level, i.e. that isn't followed by a function block
2647 ;; or brace list. When the first submatch matches, it's an
2648 ;; unambiguous construct, otherwise it's an ambiguous match that
2649 ;; might also be the return type of a function declaration.
2650 t (let* ((decl-kwds (append (c-lang-const c-class-decl-kwds)
2651 (c-lang-const c-other-block-decl-kwds)
2652 (c-lang-const c-inexpr-class-kwds)))
2653 (unambiguous (c--set-difference decl-kwds
2654 (c-lang-const c-type-start-kwds)
2655 :test 'string-equal))
2656 (ambiguous (c--intersection decl-kwds
2657 (c-lang-const c-type-start-kwds)
2658 :test 'string-equal)))
2659 (if ambiguous
2660 (concat (c-make-keywords-re t unambiguous)
2661 "\\|"
2662 (c-make-keywords-re t ambiguous))
2663 (c-make-keywords-re t unambiguous))))
2664 (c-lang-defvar c-decl-block-key (c-lang-const c-decl-block-key))
2666 (c-lang-defconst c-bitfield-kwds
2667 "Keywords that can introduce bitfields."
2668 t nil
2669 (c c++ objc) '("char" "int" "long" "signed" "unsigned"))
2671 (c-lang-defconst c-opt-bitfield-key
2672 ;; Regexp matching the start of a bitfield (not uniquely), or nil in
2673 ;; languages without bitfield support.
2674 t nil
2675 (c c++) (c-make-keywords-re t (c-lang-const c-bitfield-kwds)))
2676 (c-lang-defvar c-opt-bitfield-key (c-lang-const c-opt-bitfield-key))
2678 (c-lang-defconst c-other-kwds
2679 "Keywords not accounted for by any other `*-kwds' language constant."
2680 t nil
2681 idl '("truncatable"
2682 ;; In CORBA CIDL: (These are declaration keywords that never
2683 ;; can start a declaration.)
2684 "entity" "process" "service" "session" "storage"))
2687 ;;; Constants built from keywords.
2689 ;; Note: No `*-kwds' language constants may be defined below this point.
2691 (eval-and-compile
2692 (defconst c-kwds-lang-consts
2693 ;; List of all the language constants that contain keyword lists.
2694 (let (list)
2695 (mapatoms (lambda (sym)
2696 (when (and (boundp sym)
2697 (string-match "-kwds\\'" (symbol-name sym)))
2698 ;; Make the list of globally interned symbols
2699 ;; instead of ones interned in `c-lang-constants'.
2700 (setq list (cons (intern (symbol-name sym)) list))))
2701 c-lang-constants)
2702 list)))
2704 (c-lang-defconst c-keywords
2705 ;; All keywords as a list.
2706 t (c--delete-duplicates
2707 (c-lang-defconst-eval-immediately
2708 `(append ,@(mapcar (lambda (kwds-lang-const)
2709 `(c-lang-const ,kwds-lang-const))
2710 c-kwds-lang-consts)
2711 nil))
2712 :test 'string-equal))
2714 (c-lang-defconst c-keywords-regexp
2715 ;; All keywords as an adorned regexp.
2716 t (c-make-keywords-re t (c-lang-const c-keywords)))
2717 (c-lang-defvar c-keywords-regexp (c-lang-const c-keywords-regexp))
2719 (c-lang-defconst c-keyword-member-alist
2720 ;; An alist with all the keywords in the cars. The cdr for each
2721 ;; keyword is a list of the symbols for the `*-kwds' lists that
2722 ;; contains it.
2723 t (let ((kwd-list-alist
2724 (c-lang-defconst-eval-immediately
2725 `(list ,@(mapcar (lambda (kwds-lang-const)
2726 `(cons ',kwds-lang-const
2727 (c-lang-const ,kwds-lang-const)))
2728 c-kwds-lang-consts))))
2729 lang-const kwd-list kwd
2730 result-alist elem)
2731 (while kwd-list-alist
2732 (setq lang-const (caar kwd-list-alist)
2733 kwd-list (cdar kwd-list-alist)
2734 kwd-list-alist (cdr kwd-list-alist))
2735 (while kwd-list
2736 (setq kwd (car kwd-list)
2737 kwd-list (cdr kwd-list))
2738 (unless (setq elem (assoc kwd result-alist))
2739 (setq result-alist (cons (setq elem (list kwd)) result-alist)))
2740 (unless (memq lang-const (cdr elem))
2741 (setcdr elem (cons lang-const (cdr elem))))))
2742 result-alist))
2744 (c-lang-defvar c-keywords-obarray
2745 ;; An obarray containing all keywords as symbols. The property list
2746 ;; of each symbol has a non-nil entry for the specific `*-kwds'
2747 ;; lists it's a member of.
2749 ;; E.g. to see whether the string str contains a keyword on
2750 ;; `c-class-decl-kwds', one can do like this:
2751 ;; (get (intern-soft str c-keyword-obarray) 'c-class-decl-kwds)
2752 ;; Which preferably is written using the associated functions in
2753 ;; cc-engine:
2754 ;; (c-keyword-member (c-keyword-sym str) 'c-class-decl-kwds)
2756 ;; The obarray is not stored directly as a language constant since
2757 ;; the printed representation for obarrays used in .elc files isn't
2758 ;; complete.
2760 (let* ((alist (c-lang-const c-keyword-member-alist))
2761 kwd lang-const-list
2762 (obarray (make-vector (* (length alist) 2) 0)))
2763 (while alist
2764 (setq kwd (caar alist)
2765 lang-const-list (cdar alist)
2766 alist (cdr alist))
2767 (setplist (intern kwd obarray)
2768 ;; Emacs has an odd bug that causes `mapcan' to fail
2769 ;; with unintelligible errors. (XEmacs works.)
2770 ;; (2015-06-24): This bug has not yet been fixed.
2771 ;;(mapcan (lambda (lang-const)
2772 ;; (list lang-const t))
2773 ;; lang-const-list)
2774 (apply 'nconc (mapcar (lambda (lang-const)
2775 (list lang-const t))
2776 lang-const-list))))
2777 obarray))
2779 (c-lang-defconst c-regular-keywords-regexp
2780 ;; Adorned regexp matching all keywords that should be fontified
2781 ;; with the keywords face. I.e. that aren't types or constants.
2782 t (c-make-keywords-re t
2783 (c--set-difference (c-lang-const c-keywords)
2784 (append (c-lang-const c-primitive-type-kwds)
2785 (c-lang-const c-constant-kwds))
2786 :test 'string-equal)))
2787 (c-lang-defvar c-regular-keywords-regexp
2788 (c-lang-const c-regular-keywords-regexp))
2790 (c-lang-defconst c-primary-expr-regexp
2791 ;; Regexp matching the start of any primary expression, i.e. any
2792 ;; literal, symbol, prefix operator, and '('. It doesn't need to
2793 ;; exclude keywords; they are excluded afterwards unless the second
2794 ;; submatch matches. If the first but not the second submatch
2795 ;; matches then it is an ambiguous primary expression; it could also
2796 ;; be a match of e.g. an infix operator. (The case with ambiguous
2797 ;; keyword operators isn't handled.)
2799 t (let* ((prefix-ops
2800 (c-filter-ops (c-lang-const c-operators)
2801 '(prefix)
2802 (lambda (op)
2803 ;; Filter out the special case prefix
2804 ;; operators that are close parens.
2805 (not (string-match "\\s)" op)))))
2807 (nonkeyword-prefix-ops
2808 (c-filter-ops prefix-ops
2810 "\\`\\(\\s.\\|\\s(\\|\\s)\\)+\\'"))
2812 (in-or-postfix-ops
2813 (c-filter-ops (c-lang-const c-operators)
2814 '(postfix
2815 postfix-if-paren
2816 left-assoc
2817 right-assoc
2818 right-assoc-sequence)
2821 (unambiguous-prefix-ops (c--set-difference nonkeyword-prefix-ops
2822 in-or-postfix-ops
2823 :test 'string-equal))
2824 (ambiguous-prefix-ops (c--intersection nonkeyword-prefix-ops
2825 in-or-postfix-ops
2826 :test 'string-equal)))
2828 (concat
2829 "\\("
2830 ;; Take out all symbol class operators from `prefix-ops' and make the
2831 ;; first submatch from them together with `c-primary-expr-kwds'.
2832 (c-make-keywords-re t
2833 (append (c-lang-const c-primary-expr-kwds)
2834 (c--set-difference prefix-ops nonkeyword-prefix-ops
2835 :test 'string-equal)))
2837 "\\|"
2838 ;; Match all ambiguous operators.
2839 (c-make-keywords-re nil
2840 (c--intersection nonkeyword-prefix-ops in-or-postfix-ops
2841 :test 'string-equal))
2842 "\\)"
2844 "\\|"
2845 ;; Now match all other symbols.
2846 (c-lang-const c-symbol-start)
2848 "\\|"
2849 ;; The chars that can start integer and floating point
2850 ;; constants.
2851 "\\.?[0-9]"
2853 "\\|"
2854 ;; The unambiguous operators from `prefix-ops'.
2855 (c-make-keywords-re nil
2856 (c--set-difference nonkeyword-prefix-ops in-or-postfix-ops
2857 :test 'string-equal))
2859 "\\|"
2860 ;; Match string and character literals.
2861 "\\s\""
2862 (if (memq 'gen-string-delim c-emacs-features)
2863 "\\|\\s|"
2864 ""))))
2865 (c-lang-defvar c-primary-expr-regexp (c-lang-const c-primary-expr-regexp))
2868 ;;; Additional constants for parser-level constructs.
2870 (c-lang-defconst c-decl-start-colon-kwd-re
2871 "Regexp matching a keyword that is followed by a colon, where
2872 the whole construct can precede a declaration.
2873 E.g. \"public:\" in C++."
2874 t "\\<\\>"
2875 c++ (c-make-keywords-re t (c-lang-const c-protection-kwds)))
2876 (c-lang-defvar c-decl-start-colon-kwd-re
2877 (c-lang-const c-decl-start-colon-kwd-re))
2879 (c-lang-defconst c-decl-prefix-re
2880 "Regexp matching something that might precede a declaration, cast or
2881 label, such as the last token of a preceding statement or declaration.
2882 This is used in the common situation where a declaration or cast
2883 doesn't start with any specific token that can be searched for.
2885 The regexp should not match bob; that is done implicitly. It can't
2886 require a match longer than one token. The end of the token is taken
2887 to be at the end of the first submatch, which is assumed to always
2888 match. It's undefined whether identifier syntax (see
2889 `c-identifier-syntax-table') is in effect or not. This regexp is
2890 assumed to be a superset of `c-label-prefix-re' if
2891 `c-recognize-colon-labels' is set.
2893 Besides this, `c-decl-start-kwds' is used to find declarations.
2895 Note: This variable together with `c-decl-start-re' and
2896 `c-decl-start-kwds' is only used to detect \"likely\"
2897 declaration/cast/label starts. I.e. they might produce more matches
2898 but should not miss anything (or else it's necessary to use text
2899 properties - see the next note). Wherever they match, the following
2900 construct is analyzed to see if it indeed is a declaration, cast or
2901 label. That analysis is not cheap, so it's important that not too
2902 many false matches are triggered.
2904 Note: If a declaration/cast/label start can't be detected with this
2905 variable, it's necessary to use the `c-type' text property with the
2906 value `c-decl-end' on the last char of the last token preceding the
2907 declaration. See the comment blurb at the start of cc-engine.el for
2908 more info."
2910 ;; We match a sequence of characters to skip over things like \"};\"
2911 ;; more quickly. We match ")" in C for K&R region declarations, and
2912 ;; in all languages except Java for when a cpp macro definition
2913 ;; begins with a declaration.
2914 t "\\([{}();,]+\\)"
2915 java "\\([{}(;,<]+\\)"
2916 ;; Match "<" in C++ to get the first argument in a template arglist.
2917 ;; In that case there's an additional check in `c-find-decl-spots'
2918 ;; that it got open paren syntax. Match ":" to aid in picking up
2919 ;; "public:", etc. This involves additional checks in
2920 ;; `c-find-decl-prefix-search' to prevent a match of identifiers
2921 ;; or labels.
2922 c++ "\\([{}();:,<]+\\)"
2923 ;; Additionally match the protection directives in Objective-C.
2924 ;; Note that this doesn't cope with the longer directives, which we
2925 ;; would have to match from start to end since they don't end with
2926 ;; any easily recognized characters.
2927 objc (concat "\\([{}();,]+\\|"
2928 (c-make-keywords-re nil (c-lang-const c-protection-kwds))
2929 "\\)")
2930 ;; Pike is like C but we also match "[" for multiple value
2931 ;; assignments and type casts.
2932 pike "\\([{}()[;,]+\\)")
2933 (c-lang-defvar c-decl-prefix-re (c-lang-const c-decl-prefix-re)
2934 'dont-doc)
2936 (c-lang-defconst c-decl-start-re
2937 "Regexp matching the start of any declaration, cast or label.
2938 It's used on the token after the one `c-decl-prefix-re' matched. This
2939 regexp should not try to match those constructs accurately as it's
2940 only used as a sieve to avoid spending more time checking other
2941 constructs."
2942 t (c-lang-const c-identifier-start))
2943 (c-lang-defvar c-decl-start-re (c-lang-const c-decl-start-re))
2945 (c-lang-defconst c-decl-prefix-or-start-re
2946 ;; Regexp matching something that might precede or start a
2947 ;; declaration, cast or label.
2949 ;; If the first submatch matches, it's taken to match the end of a
2950 ;; token that might precede such a construct, e.g. ';', '}' or '{'.
2951 ;; It's built from `c-decl-prefix-re'.
2953 ;; If the first submatch did not match, the match of the whole
2954 ;; regexp is taken to be at the first token in the declaration.
2955 ;; `c-decl-start-re' is not checked in this case.
2957 ;; Design note: The reason the same regexp is used to match both
2958 ;; tokens that precede declarations and start them is to avoid an
2959 ;; extra regexp search from the previous declaration spot in
2960 ;; `c-find-decl-spots'. Users of `c-find-decl-spots' also count on
2961 ;; that it finds all declaration/cast/label starts in approximately
2962 ;; linear order, so we can't do the searches in two separate passes.
2963 t (if (c-lang-const c-decl-start-kwds)
2964 (concat (c-lang-const c-decl-prefix-re)
2965 "\\|"
2966 (c-make-keywords-re t (c-lang-const c-decl-start-kwds)))
2967 (c-lang-const c-decl-prefix-re)))
2968 (c-lang-defvar c-decl-prefix-or-start-re
2969 (c-lang-const c-decl-prefix-or-start-re)
2970 'dont-doc)
2972 (c-lang-defconst c-cast-parens
2973 ;; List containing the paren characters that can open a cast, or nil in
2974 ;; languages without casts.
2975 t (c-filter-ops (c-lang-const c-operators)
2976 '(prefix)
2977 "\\`\\s(\\'"
2978 (lambda (op) (elt op 0))))
2979 (c-lang-defvar c-cast-parens (c-lang-const c-cast-parens))
2981 (c-lang-defconst c-block-prefix-disallowed-chars
2982 "List of syntactically relevant characters that never can occur before
2983 the open brace in any construct that contains a brace block, e.g. in
2984 the \"class Foo: public Bar\" part of:
2986 class Foo: public Bar {int x();} a, *b;
2988 If parens can occur, the chars inside those aren't filtered with this
2989 list.
2991 `<' and `>' should be disallowed even if angle bracket arglists can
2992 occur. That since the search function needs to stop at them anyway to
2993 ensure they are given paren syntax.
2995 This is used to skip backward from the open brace to find the region
2996 in which to look for a construct like \"class\", \"enum\",
2997 \"namespace\" or whatever. That skipping should be as tight as
2998 possible for good performance."
3000 ;; Default to all chars that only occurs in nonsymbol tokens outside
3001 ;; identifiers.
3002 t (c--set-difference
3003 (c-lang-const c-nonsymbol-token-char-list)
3004 (c-filter-ops (append (c-lang-const c-identifier-ops)
3005 (list (cons nil
3006 (c-lang-const c-after-id-concat-ops))))
3009 (lambda (op)
3010 (let ((pos 0) res)
3011 (while (string-match "\\(\\s.\\|\\s(\\|\\s)\\)"
3012 op pos)
3013 (setq res (cons (aref op (match-beginning 1)) res)
3014 pos (match-end 0)))
3015 res))))
3017 ;; Allow cpp operations (where applicable).
3018 t (if (c-lang-const c-opt-cpp-prefix)
3019 (c--set-difference (c-lang-const c-block-prefix-disallowed-chars)
3020 '(?#))
3021 (c-lang-const c-block-prefix-disallowed-chars))
3023 ;; Allow ':' for inherit list starters.
3024 (c++ objc idl) (c--set-difference (c-lang-const c-block-prefix-disallowed-chars)
3025 '(?:))
3027 ;; Allow ',' for multiple inherits.
3028 (c++ java) (c--set-difference (c-lang-const c-block-prefix-disallowed-chars)
3029 '(?,))
3031 ;; Allow parentheses for anonymous inner classes in Java and class
3032 ;; initializer lists in Pike.
3033 (java pike) (c--set-difference (c-lang-const c-block-prefix-disallowed-chars)
3034 '(?\( ?\)))
3036 ;; Allow '"' for extern clauses (e.g. extern "C" {...}).
3037 (c c++ objc) (c--set-difference (c-lang-const c-block-prefix-disallowed-chars)
3038 '(?\" ?')))
3040 (c-lang-defconst c-block-prefix-charset
3041 ;; `c-block-prefix-disallowed-chars' as an inverted charset suitable
3042 ;; for `c-syntactic-skip-backward'.
3043 t (c-make-bare-char-alt (c-lang-const c-block-prefix-disallowed-chars) t))
3044 (c-lang-defvar c-block-prefix-charset (c-lang-const c-block-prefix-charset))
3046 (c-lang-defconst c-type-decl-prefix-key
3047 "Regexp matching any declarator operator that might precede the
3048 identifier in a declaration, e.g. the \"*\" in \"char *argv\". This
3049 regexp should match \"(\" if parentheses are valid in declarators.
3050 The end of the first submatch is taken as the end of the operator.
3051 Identifier syntax is in effect when this is matched \(see
3052 `c-identifier-syntax-table')."
3053 t (if (c-lang-const c-type-modifier-kwds)
3054 (concat (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>")
3055 ;; Default to a regexp that never matches.
3056 "\\<\\>")
3057 ;; Check that there's no "=" afterwards to avoid matching tokens
3058 ;; like "*=".
3059 (c objc) (concat "\\("
3060 "[*(]"
3061 "\\|"
3062 (c-lang-const c-type-decl-prefix-key)
3063 "\\)"
3064 "\\([^=]\\|$\\)")
3065 c++ (concat "\\("
3066 "&&"
3067 "\\|"
3068 "\\.\\.\\."
3069 "\\|"
3070 "[*(&]"
3071 "\\|"
3072 (c-lang-const c-type-decl-prefix-key)
3073 "\\|"
3074 (concat "\\(" ; 3
3075 ;; If this matches there's special treatment in
3076 ;; `c-font-lock-declarators' and
3077 ;; `c-font-lock-declarations' that check for a
3078 ;; complete name followed by ":: *".
3079 (c-lang-const c-identifier-start)
3080 "\\)")
3081 "\\)"
3082 "\\([^=]\\|$\\)")
3083 pike "\\(\\*\\)\\([^=]\\|$\\)")
3084 (c-lang-defvar c-type-decl-prefix-key (c-lang-const c-type-decl-prefix-key)
3085 'dont-doc)
3087 (c-lang-defconst c-type-decl-operator-prefix-key
3088 "Regexp matching any declarator operator which isn't a keyword
3089 that might precede the identifier in a declaration, e.g. the
3090 \"*\" in \"char *argv\". The end of the first submatch is taken
3091 as the end of the operator. Identifier syntax is in effect when
3092 this is matched \(see `c-identifier-syntax-table')."
3093 t ;; Default to a regexp that never matches.
3094 "\\<\\>"
3095 ;; Check that there's no "=" afterwards to avoid matching tokens
3096 ;; like "*=".
3097 (c objc) (concat "\\(\\*\\)"
3098 "\\([^=]\\|$\\)")
3099 c++ (concat "\\("
3100 "\\.\\.\\."
3101 "\\|"
3102 "\\*"
3103 "\\)"
3104 "\\([^=]\\|$\\)")
3105 pike "\\(\\*\\)\\([^=]\\|$\\)")
3106 (c-lang-defvar c-type-decl-operator-prefix-key
3107 (c-lang-const c-type-decl-operator-prefix-key))
3109 (c-lang-defconst c-type-decl-suffix-key
3110 "Regexp matching the declarator operators that might follow after the
3111 identifier in a declaration, e.g. the \"[\" in \"char argv[]\". This
3112 regexp should match \")\" if parentheses are valid in declarators. If
3113 it matches an open paren of some kind, the type declaration check
3114 continues at the corresponding close paren, otherwise the end of the
3115 first submatch is taken as the end of the operator. Identifier syntax
3116 is in effect when this is matched (see `c-identifier-syntax-table')."
3117 ;; Default to a regexp that matches `c-type-modifier-kwds' and a
3118 ;; function argument list parenthesis.
3119 t (if (c-lang-const c-type-modifier-kwds)
3120 (concat "\\((\\|"
3121 (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>"
3122 "\\)")
3123 "\\((\\)")
3124 (c c++ objc) (concat
3125 "\\("
3126 "[)[(]"
3127 (if (c-lang-const c-type-modifier-kwds)
3128 (concat
3129 "\\|"
3130 ;; "throw" in `c-type-modifier-kwds' is followed
3131 ;; by a parenthesis list, but no extra measures
3132 ;; are necessary to handle that.
3133 (regexp-opt (c-lang-const c-type-modifier-kwds) t)
3134 "\\>")
3136 "\\)")
3137 java "\\([[()]\\)"
3138 idl "\\([[(]\\)")
3139 (c-lang-defvar c-type-decl-suffix-key (c-lang-const c-type-decl-suffix-key)
3140 'dont-doc)
3142 (c-lang-defconst c-after-suffixed-type-decl-key
3143 "This regexp is matched after a declarator expression where
3144 `c-type-decl-suffix-key' has matched. If it matches then the
3145 construct is taken as a declaration. It's typically used to match the
3146 beginning of a function body or whatever might occur after the
3147 function header in a function declaration or definition. It's
3148 undefined whether identifier syntax (see `c-identifier-syntax-table')
3149 is in effect or not.
3151 Note that it's used in cases like after \"foo (bar)\" so it should
3152 only match when it's certain that it's a declaration, e.g., \"{\" but
3153 not \",\" or \";\"."
3154 t "{"
3155 ;; If K&R style declarations should be recognized then one could
3156 ;; consider to match the start of any symbol since we want to match
3157 ;; the start of the first declaration in the "K&R region". That
3158 ;; could however produce false matches on code like "FOO(bar) x"
3159 ;; where FOO is a cpp macro, so it's better to leave it out and rely
3160 ;; on the other heuristics in that case.
3161 t (if (c-lang-const c-postfix-spec-kwds)
3162 ;; Add on the keywords in `c-postfix-spec-kwds'.
3163 (concat (c-lang-const c-after-suffixed-type-decl-key)
3164 "\\|"
3165 (c-make-keywords-re t (c-lang-const c-postfix-spec-kwds)))
3166 (c-lang-const c-after-suffixed-type-decl-key))
3167 ;; Also match the colon that starts a base class initializer list in
3168 ;; C++. That can be confused with a function call before the colon
3169 ;; in a ? : operator, but we count on that `c-decl-prefix-re' won't
3170 ;; match before such a thing (as a declaration-level construct;
3171 ;; matches inside arglist contexts are already excluded).
3172 c++ "[{:]")
3173 (c-lang-defvar c-after-suffixed-type-decl-key
3174 (c-lang-const c-after-suffixed-type-decl-key)
3175 'dont-doc)
3177 (c-lang-defconst c-after-suffixed-type-maybe-decl-key
3178 ;; Regexp that in addition to `c-after-suffixed-type-decl-key'
3179 ;; matches ";" and ",".
3180 t (concat "\\(" (c-lang-const c-after-suffixed-type-decl-key) "\\)"
3181 "\\|[;,]"))
3182 (c-lang-defvar c-after-suffixed-type-maybe-decl-key
3183 (c-lang-const c-after-suffixed-type-maybe-decl-key))
3185 (c-lang-defconst c-opt-type-concat-key
3186 "Regexp matching operators that concatenate types, e.g. the \"|\" in
3187 \"int|string\" in Pike. The end of the first submatch is taken as the
3188 end of the operator. nil in languages without such operators. It's
3189 undefined whether identifier syntax (see `c-identifier-syntax-table')
3190 is in effect or not."
3191 t nil
3192 pike "\\([|.&]\\)\\($\\|[^|.&]\\)")
3193 (c-lang-defvar c-opt-type-concat-key (c-lang-const c-opt-type-concat-key)
3194 'dont-doc)
3196 (c-lang-defconst c-opt-type-suffix-key
3197 "Regexp matching operators that might follow after a type, or nil in
3198 languages that don't have such operators. The end of the first
3199 submatch is taken as the end of the operator. This should not match
3200 things like C++ template arglists if `c-recognize-<>-arglists' is set.
3201 It's undefined whether identifier syntax (see `c-identifier-syntax-table')
3202 is in effect or not."
3203 t nil
3204 (c c++ objc pike) "\\(\\.\\.\\.\\)"
3205 java (concat "\\(\\[" (c-lang-const c-simple-ws) "*\\]\\|\\.\\.\\.\\)"))
3206 (c-lang-defvar c-opt-type-suffix-key (c-lang-const c-opt-type-suffix-key))
3208 (c-lang-defvar c-known-type-key
3209 ;; Regexp matching the known type identifiers. This is initialized
3210 ;; from the type keywords and `*-font-lock-extra-types'. The first
3211 ;; submatch is the one that matches the type. Note that this regexp
3212 ;; assumes that symbol constituents like '_' and '$' have word
3213 ;; syntax.
3214 (let* ((extra-types
3215 (when (boundp (c-mode-symbol "font-lock-extra-types"))
3216 (c-mode-var "font-lock-extra-types")))
3217 (regexp-strings
3218 (delq nil (mapcar (lambda (re)
3219 (when (string-match "[][.*+?^$\\]" re)
3220 re))
3221 extra-types)))
3222 (plain-strings
3223 (delq nil (mapcar (lambda (re)
3224 (unless (string-match "[][.*+?^$\\]" re)
3225 re))
3226 extra-types))))
3227 (concat "\\<\\("
3228 (c-concat-separated
3229 (append (list (c-make-keywords-re nil
3230 (append (c-lang-const c-primitive-type-kwds)
3231 plain-strings)))
3232 regexp-strings)
3233 "\\|")
3234 "\\)\\>")))
3236 (c-lang-defconst c-special-brace-lists
3237 "List of open- and close-chars that makes up a pike-style brace list,
3238 i.e., for a ([ ]) list there should be a cons (?\\[ . ?\\]) in this
3239 list."
3240 t nil
3241 pike '((?{ . ?}) (?\[ . ?\]) (?< . ?>)))
3242 (c-lang-defvar c-special-brace-lists (c-lang-const c-special-brace-lists))
3244 (c-lang-defconst c-recognize-knr-p
3245 "Non-nil means K&R style argument declarations are valid."
3246 t nil
3247 c t)
3248 (c-lang-defvar c-recognize-knr-p (c-lang-const c-recognize-knr-p))
3250 (c-lang-defconst c-pre-id-bracelist-key
3251 "A regexp matching tokens which, preceding an identifier, signify a bracelist.
3253 t "\\<\\>"
3254 c++ "new\\([^[:alnum:]_$]\\|$\\)\\|&&?\\(\\S.\\|$\\)")
3255 (c-lang-defvar c-pre-id-bracelist-key (c-lang-const c-pre-id-bracelist-key))
3257 (c-lang-defconst c-recognize-typeless-decls
3258 "Non-nil means function declarations without return type should be
3259 recognized. That can introduce an ambiguity with parenthesized macro
3260 calls before a brace block. This setting does not affect declarations
3261 that are preceded by a declaration starting keyword, so
3262 e.g. `c-typeless-decl-kwds' may still be used when it's set to nil."
3263 t nil
3264 (c c++ objc java) t)
3265 (c-lang-defvar c-recognize-typeless-decls
3266 (c-lang-const c-recognize-typeless-decls))
3268 (c-lang-defconst c-recognize-<>-arglists
3269 "Non-nil means C++ style template arglists should be handled. More
3270 specifically, this means a comma separated list of types or
3271 expressions surrounded by \"<\" and \">\". It's always preceded by an
3272 identifier or one of the keywords on `c-<>-type-kwds' or
3273 `c-<>-arglist-kwds'. If there's an identifier before then the whole
3274 expression is considered to be a type."
3275 t (or (consp (c-lang-const c-<>-type-kwds))
3276 (consp (c-lang-const c-<>-arglist-kwds)))
3277 java t) ; 2008-10-19. This is crude. The syntax for java
3278 ; generics is not yet coded in CC Mode.
3279 (c-lang-defvar c-recognize-<>-arglists (c-lang-const c-recognize-<>-arglists))
3281 (c-lang-defconst c-<>-notable-chars-re
3282 "A regexp matching any single character notable inside a <...> construct.
3283 This must include \"<\" and \">\", and should include \",\", and
3284 any character which cannot be valid inside such a construct.
3285 This is used in `c-forward-<>-arglist-recur' to try to detect
3286 sequences of tokens which cannot be a template/generic construct.
3287 When \"(\" is present, that defun will attempt to parse a
3288 parenthesized expression inside the template. When \")\" is
3289 present it will treat an unbalanced closing paren as a sign of
3290 the invalidity of the putative template construct."
3291 t "[<;{},|+&->)]"
3292 c++ "[<;{},>()]")
3293 (c-lang-defvar c-<>-notable-chars-re (c-lang-const c-<>-notable-chars-re))
3295 (c-lang-defconst c-enums-contain-decls
3296 "Non-nil means that an enum structure can contain declarations."
3297 t nil
3298 java t)
3299 (c-lang-defvar c-enums-contain-decls (c-lang-const c-enums-contain-decls))
3301 (c-lang-defconst c-recognize-paren-inits
3302 "Non-nil means that parenthesis style initializers exist,
3303 i.e. constructs like
3305 Foo bar (gnu);
3307 in addition to the more classic
3309 Foo bar = gnu;"
3310 t nil
3311 c++ t)
3312 (c-lang-defvar c-recognize-paren-inits (c-lang-const c-recognize-paren-inits))
3314 (c-lang-defconst c-recognize-paren-inexpr-blocks
3315 "Non-nil to recognize gcc style in-expression blocks,
3316 i.e. compound statements surrounded by parentheses inside expressions."
3317 t nil
3318 (c c++) t)
3319 (c-lang-defvar c-recognize-paren-inexpr-blocks
3320 (c-lang-const c-recognize-paren-inexpr-blocks))
3322 (c-lang-defconst c-opt-<>-arglist-start
3323 ;; Regexp matching the start of angle bracket arglists in languages
3324 ;; where `c-recognize-<>-arglists' is set. Does not exclude
3325 ;; keywords outside `c-<>-arglist-kwds'. The first submatch is
3326 ;; assumed to surround the preceding symbol. The whole match is
3327 ;; assumed to end directly after the opening "<".
3328 t (if (c-lang-const c-recognize-<>-arglists)
3329 (concat "\\("
3330 (c-lang-const c-symbol-key)
3331 "\\)"
3332 (c-lang-const c-syntactic-ws)
3333 "<")))
3334 (c-lang-defvar c-opt-<>-arglist-start (c-lang-const c-opt-<>-arglist-start))
3336 (c-lang-defconst c-opt-<>-arglist-start-in-paren
3337 ;; Regexp that in addition to `c-opt-<>-arglist-start' matches close
3338 ;; parens. The first submatch is assumed to surround
3339 ;; `c-opt-<>-arglist-start'.
3340 t (if (c-lang-const c-opt-<>-arglist-start)
3341 (concat "\\("
3342 (c-lang-const c-opt-<>-arglist-start)
3343 "\\)\\|\\s)")))
3344 (c-lang-defvar c-opt-<>-arglist-start-in-paren
3345 (c-lang-const c-opt-<>-arglist-start-in-paren))
3347 (c-lang-defconst c-opt-postfix-decl-spec-key
3348 ;; Regexp matching the beginning of a declaration specifier in the
3349 ;; region between the header and the body of a declaration.
3351 ;; TODO: This is currently not used uniformly; c++-mode and
3352 ;; java-mode each have their own ways of using it.
3353 t nil
3354 c++ (concat ":?"
3355 (c-lang-const c-simple-ws) "*"
3356 "\\(virtual" (c-lang-const c-simple-ws) "+\\)?\\("
3357 (c-make-keywords-re nil (c-lang-const c-protection-kwds))
3358 "\\)" (c-lang-const c-simple-ws) "+"
3359 "\\(" (c-lang-const c-symbol-key) "\\)")
3360 java (c-make-keywords-re t (c-lang-const c-postfix-spec-kwds)))
3361 (c-lang-defvar c-opt-postfix-decl-spec-key
3362 (c-lang-const c-opt-postfix-decl-spec-key))
3364 (c-lang-defconst c-recognize-colon-labels
3365 "Non-nil if generic labels ending with \":\" should be recognized.
3366 That includes labels in code and access keys in classes. This does
3367 not apply to labels recognized by `c-label-kwds' and
3368 `c-opt-extra-label-key'."
3369 t nil
3370 (c c++ objc java pike) t)
3371 (c-lang-defvar c-recognize-colon-labels
3372 (c-lang-const c-recognize-colon-labels))
3374 (c-lang-defconst c-label-prefix-re
3375 "Regexp like `c-decl-prefix-re' that matches any token that can precede
3376 a generic colon label. Not used if `c-recognize-colon-labels' is
3377 nil."
3378 t "\\([{};]+\\)")
3379 (c-lang-defvar c-label-prefix-re
3380 (c-lang-const c-label-prefix-re))
3382 (c-lang-defconst c-nonlabel-token-key
3383 "Regexp matching things that can't occur in generic colon labels,
3384 neither in a statement nor in a declaration context. The regexp is
3385 tested at the beginning of every sexp in a suspected label,
3386 i.e. before \":\". Only used if `c-recognize-colon-labels' is set."
3387 t (concat
3388 ;; All keywords except `c-label-kwds' and `c-protection-kwds'.
3389 (c-make-keywords-re t
3390 (c--set-difference (c-lang-const c-keywords)
3391 (append (c-lang-const c-label-kwds)
3392 (c-lang-const c-protection-kwds))
3393 :test 'string-equal)))
3394 ;; Don't allow string literals, except in AWK and Java. Character constants are OK.
3395 (c objc pike idl) (concat "\"\\|"
3396 (c-lang-const c-nonlabel-token-key))
3397 ;; Also check for open parens in C++, to catch member init lists in
3398 ;; constructors. We normally allow it so that macros with arguments
3399 ;; work in labels.
3400 c++ (concat "\\s(\\|\"\\|" (c-lang-const c-nonlabel-token-key)))
3401 (c-lang-defvar c-nonlabel-token-key (c-lang-const c-nonlabel-token-key))
3403 (c-lang-defconst c-nonlabel-token-2-key
3404 "Regexp matching things that can't occur two symbols before a colon in
3405 a label construct. This catches C++'s inheritance construct \"class foo
3406 : bar\". Only used if `c-recognize-colon-labels' is set."
3407 t "\\<\\>" ; matches nothing
3408 c++ (c-make-keywords-re t '("class")))
3409 (c-lang-defvar c-nonlabel-token-2-key (c-lang-const c-nonlabel-token-2-key))
3411 (c-lang-defconst c-opt-extra-label-key
3412 "Optional regexp matching labels.
3413 Normally, labels are detected according to `c-nonlabel-token-key',
3414 `c-decl-prefix-re' and `c-nonlabel-decl-prefix-re'. This regexp can
3415 be used if there are additional labels that aren't recognized that
3416 way."
3417 t nil
3418 objc (c-make-keywords-re t (c-lang-const c-protection-kwds)))
3419 (c-lang-defvar c-opt-extra-label-key (c-lang-const c-opt-extra-label-key))
3421 (c-lang-defconst c-opt-friend-key
3422 ;; Regexp describing friend declarations classes, or nil in
3423 ;; languages that don't have such things.
3425 ;; TODO: Ought to use `c-prefix-spec-kwds-re' or similar, and the
3426 ;; template skipping isn't done properly. This will disappear soon.
3427 t nil
3428 c++ (concat "friend" (c-lang-const c-simple-ws) "+"
3429 "\\|"
3430 (concat "template"
3431 (c-lang-const c-simple-ws) "*"
3432 "<.+>"
3433 (c-lang-const c-simple-ws) "*"
3434 "friend"
3435 (c-lang-const c-simple-ws) "+")))
3436 (c-lang-defvar c-opt-friend-key (c-lang-const c-opt-friend-key))
3438 (c-lang-defconst c-opt-method-key
3439 ;; Special regexp to match the start of Objective-C methods. The
3440 ;; first submatch is assumed to end after the + or - key.
3441 t nil
3442 objc (concat
3443 ;; TODO: Ought to use a better method than anchoring on bol.
3444 "^\\s *"
3445 "\\([+-]\\)"
3446 (c-lang-const c-simple-ws) "*"
3447 (concat "\\(" ; Return type.
3448 "([^)]*)"
3449 (c-lang-const c-simple-ws) "*"
3450 "\\)?")
3451 "\\(" (c-lang-const c-symbol-key) "\\)"))
3452 (c-lang-defvar c-opt-method-key (c-lang-const c-opt-method-key))
3454 (c-lang-defconst c-type-decl-end-used
3455 ;; Must be set in buffers where the `c-type' text property might be
3456 ;; used with the value `c-decl-end'.
3458 ;; `c-decl-end' is used to mark the ends of labels and access keys
3459 ;; to make interactive refontification work better.
3460 t (or (c-lang-const c-recognize-colon-labels)
3461 (and (c-lang-const c-label-kwds) t))
3462 ;; `c-decl-end' is used to mark the end of the @-style directives in
3463 ;; Objective-C.
3464 objc t)
3465 (c-lang-defvar c-type-decl-end-used (c-lang-const c-type-decl-end-used))
3467 (c-lang-defconst c-maybe-decl-faces
3468 "List of faces that might be put at the start of a type when
3469 `c-font-lock-declarations' runs. This must be evaluated (with `eval') at
3470 runtime to get the actual list of faces. This ensures that face name
3471 aliases in Emacs are resolved."
3472 t '(list nil
3473 font-lock-type-face
3474 c-reference-face-name
3475 font-lock-keyword-face)
3476 java (append (c-lang-const c-maybe-decl-faces)
3477 '(font-lock-preprocessor-face)))
3478 (c-lang-defvar c-maybe-decl-faces (c-lang-const c-maybe-decl-faces))
3481 ;;; Wrap up the `c-lang-defvar' system.
3483 ;; Compile in the list of language variables that has been collected
3484 ;; with the `c-lang-defvar' and `c-lang-setvar' macros. Note that the
3485 ;; first element of each is nil.
3486 (defconst c-lang-variable-inits (cc-eval-when-compile c-lang-variable-inits))
3487 (defconst c-emacs-variable-inits (cc-eval-when-compile c-emacs-variable-inits))
3489 ;; Make the `c-lang-setvar' variables buffer local in the current buffer.
3490 ;; These are typically standard emacs variables such as `comment-start'.
3491 (defmacro c-make-emacs-variables-local ()
3492 `(progn
3493 ,@(mapcar (lambda (init)
3494 `(make-local-variable ',(car init)))
3495 (cdr c-emacs-variable-inits))))
3497 (defun c-make-init-lang-vars-fun (mode)
3498 "Create a function that initializes all the language dependent variables
3499 for the given mode.
3501 This function should be evaluated at compile time, so that the
3502 function it returns is byte compiled with all the evaluated results
3503 from the language constants. Use the `c-init-language-vars' macro to
3504 accomplish that conveniently."
3506 (if (cc-bytecomp-is-compiling)
3507 ;; No need to byte compile this lambda since the byte compiler is
3508 ;; smart enough to detect the `funcall' construct in the
3509 ;; `c-init-language-vars' macro below and compile it all straight
3510 ;; into the function that contains `c-init-language-vars'.
3511 `(lambda ()
3513 ;; This let sets up the context for `c-mode-var' and similar
3514 ;; that could be in the result from `c--macroexpand-all'.
3515 (let ((c-buffer-is-cc-mode ',mode)
3516 current-var source-eval)
3517 (c-make-emacs-variables-local)
3518 (condition-case err
3520 (if (eq c-version-sym ',c-version-sym)
3521 (setq ,@(let ((c-buffer-is-cc-mode mode)
3522 (c-lang-const-expansion 'immediate))
3523 ;; `c-lang-const' will expand to the evaluated
3524 ;; constant immediately in `c--macroexpand-all'
3525 ;; below.
3526 (c--mapcan
3527 (lambda (init)
3528 `(current-var ',(car init)
3529 ,(car init) ,(c--macroexpand-all
3530 (elt init 1))))
3531 ;; Note: The following `append' copies the
3532 ;; first argument. That list is small, so
3533 ;; this doesn't matter too much.
3534 (append (cdr c-emacs-variable-inits)
3535 (cdr c-lang-variable-inits)))))
3537 ;; This diagnostic message isn't useful for end
3538 ;; users, so it's disabled.
3539 ;;(unless (get ',mode 'c-has-warned-lang-consts)
3540 ;; (message ,(concat "%s compiled with CC Mode %s "
3541 ;; "but loaded with %s - evaluating "
3542 ;; "language constants from source")
3543 ;; ',mode ,c-version c-version)
3544 ;; (put ',mode 'c-has-warned-lang-consts t))
3546 (setq source-eval t)
3547 (let ((init ',(append (cdr c-emacs-variable-inits)
3548 (cdr c-lang-variable-inits))))
3549 (dolist (var-init init)
3550 (setq current-var (car var-init))
3551 (set (car var-init) (eval (cadr var-init))))))
3553 (error
3554 (if current-var
3555 (message "Eval error in the `c-lang-defvar' or `c-lang-setvar' for `%s'%s: %S"
3556 current-var
3557 (if source-eval
3558 (format "\
3559 (fallback source eval - %s compiled with CC Mode %s but loaded with %s)"
3560 ',mode ,c-version c-version)
3562 err)
3563 (signal (car err) (cdr err)))))))
3565 ;; Being evaluated from source. Always use the dynamic method to
3566 ;; work well when `c-lang-defvar's in this file are reevaluated
3567 ;; interactively.
3568 `(lambda ()
3569 (require 'cc-langs)
3570 (let ((c-buffer-is-cc-mode ',mode)
3571 (init (append (cdr c-emacs-variable-inits)
3572 (cdr c-lang-variable-inits)))
3573 current-var)
3574 (c-make-emacs-variables-local)
3575 (condition-case err
3577 (dolist (var-init init)
3578 (setq current-var (car var-init))
3579 (set (car var-init) (eval (cadr var-init))))
3581 (error
3582 (if current-var
3583 (message
3584 "Eval error in the `c-lang-defvar' or `c-lang-setver' for `%s' (source eval): %S"
3585 current-var err)
3586 (signal (car err) (cdr err)))))))
3589 (defmacro c-init-language-vars (mode)
3590 "Initialize all the language dependent variables for the given mode.
3591 This macro is expanded at compile time to a form tailored for the mode
3592 in question, so MODE must be a constant. Therefore MODE is not
3593 evaluated and should not be quoted."
3594 `(funcall ,(c-make-init-lang-vars-fun mode)))
3597 (cc-provide 'cc-langs)
3599 ;; Local Variables:
3600 ;; indent-tabs-mode: t
3601 ;; tab-width: 8
3602 ;; End:
3603 ;;; cc-langs.el ends here