Don't record eshell/clear "command" in history (Bug#25838)
[emacs.git] / lisp / progmodes / cc-langs.el
blob3b455fc0908459809fa4c175102a0b5c9ca4937a
1 ;;; cc-langs.el --- language specific settings for CC Mode -*- coding: utf-8 -*-
3 ;; Copyright (C) 1985, 1987, 1992-2017 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 &or ("quote" symbolp) 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))
717 (c-lang-defconst c-opt-identifier-concat-key-depth
718 ;; Number of regexp grouping parens in `c-opt-identifier-concat-key'.
719 t (regexp-opt-depth (c-lang-const c-opt-identifier-concat-key)))
721 (c-lang-defconst c-opt-identifier-prefix-key
722 ;; Appendable adorned regexp matching operators that might precede
723 ;; an identifier and that are part of the identifier in that case.
724 ;; nil in languages without such things.
725 t (let ((ops (c-filter-ops (c-lang-const c-identifier-ops)
726 '(prefix)
727 t)))
728 (when ops
729 (c-make-keywords-re 'appendable ops))))
731 (c-lang-defconst c-after-id-concat-ops
732 "Operators that can occur after a binary operator on `c-identifier-ops'
733 in identifiers. nil in languages that don't have such things.
735 Operators here should also have appropriate entries in `c-operators' -
736 it's not taken care of by default."
737 t nil
738 ;; '~' for destructors in C++, '*' for member pointers.
739 c++ '("~" "*")
740 ;; In Java we recognize '*' to deal with "foo.bar.*" that can occur
741 ;; in import declarations. (This will also match bogus things like
742 ;; "foo.*bar" but we don't bother.)
743 java '("*"))
745 (c-lang-defconst c-opt-after-id-concat-key
746 ;; Regexp that must match the token after
747 ;; `c-opt-identifier-concat-key' for it to be considered an
748 ;; identifier concatenation operator (which e.g. causes the
749 ;; preceding identifier to be fontified as a reference). Assumed to
750 ;; be a string if `c-opt-identifier-concat-key' is.
752 ;; This was a docstring constant in 5.30. It still works but is now
753 ;; considered internal - change `c-after-id-concat-ops' instead.
754 t (concat (c-lang-const c-symbol-start)
755 (if (c-lang-const c-after-id-concat-ops)
756 (concat "\\|" (c-make-keywords-re 'appendable
757 (c-lang-const c-after-id-concat-ops)))
758 "")))
760 (c-lang-defconst c-identifier-start
761 "Regexp that matches the start of an (optionally qualified) identifier.
762 It should also match all keywords. It's unspecified how far it
763 matches."
764 t (concat (c-lang-const c-symbol-start)
765 (if (c-lang-const c-opt-identifier-prefix-key)
766 (concat "\\|"
767 (c-lang-const c-opt-identifier-prefix-key))
768 "")))
769 (c-lang-defvar c-identifier-start (c-lang-const c-identifier-start))
771 (c-lang-defconst c-identifier-key
772 "Regexp matching a fully qualified identifier, like \"A::B::c\" in
773 C++. It does not recognize the full range of syntactic whitespace
774 between the tokens; `c-forward-name' has to be used for that. It
775 should also not match identifiers containing parenthesis groupings,
776 e.g. identifiers with template arguments such as \"A<X,Y>\" in C++."
777 ;; This regexp is more complex than strictly necessary to ensure
778 ;; that it can be matched with a minimum of backtracking.
779 t (concat (if (c-lang-const c-opt-identifier-prefix-key)
780 (concat
781 "\\("
782 (c-lang-const c-opt-identifier-prefix-key)
783 (c-lang-const c-simple-ws) "*"
784 "\\)?")
786 "\\(" (c-lang-const c-symbol-key) "\\)"
787 (if (c-lang-const c-opt-identifier-concat-key)
788 (concat
789 "\\("
790 (c-lang-const c-simple-ws) "*"
791 (c-lang-const c-opt-identifier-concat-key)
792 (c-lang-const c-simple-ws) "*"
793 (if (c-lang-const c-after-id-concat-ops)
794 (concat
795 "\\("
796 (c-make-keywords-re 'appendable
797 (c-lang-const c-after-id-concat-ops))
798 (concat
799 ;; For flexibility, consider the symbol match
800 ;; optional if we've hit a
801 ;; `c-after-id-concat-ops' operator. This is
802 ;; also necessary to handle the "*" that can
803 ;; end import declaration identifiers in Java.
804 "\\("
805 (c-lang-const c-simple-ws) "*"
806 "\\(" (c-lang-const c-symbol-key) "\\)"
807 "\\)?")
808 "\\|"
809 "\\(" (c-lang-const c-symbol-key) "\\)"
810 "\\)")
811 (concat "\\(" (c-lang-const c-symbol-key) "\\)"))
812 "\\)*")
813 "")))
814 (c-lang-defvar c-identifier-key (c-lang-const c-identifier-key))
816 (c-lang-defconst c-identifier-last-sym-match
817 ;; This was a docstring constant in 5.30 but it's no longer used.
818 ;; It's only kept to avoid breaking third party code.
820 ;; Used to identify the submatch in `c-identifier-key' that
821 ;; surrounds the last symbol in the qualified identifier. It's a
822 ;; list of submatch numbers, of which the first that has a match is
823 ;; taken. It's assumed that at least one does when the regexp has
824 ;; matched.
825 t nil)
827 (c-lang-defconst c-string-escaped-newlines
828 "Set if the language support backslash escaped newlines inside string
829 literals."
830 t nil
831 (c c++ objc pike) t)
832 (c-lang-defvar c-string-escaped-newlines
833 (c-lang-const c-string-escaped-newlines))
835 (c-lang-defconst c-multiline-string-start-char
836 "Set if the language supports multiline string literals without escaped
837 newlines. If t, all string literals are multiline. If a character,
838 only literals where the open quote is immediately preceded by that
839 literal are multiline."
840 t nil
841 pike ?#)
842 (c-lang-defvar c-multiline-string-start-char
843 (c-lang-const c-multiline-string-start-char))
845 (c-lang-defconst c-opt-cpp-symbol
846 "The symbol which starts preprocessor constructs when in the margin."
847 t "#"
848 (java awk) nil)
849 (c-lang-defvar c-opt-cpp-symbol (c-lang-const c-opt-cpp-symbol))
851 (c-lang-defconst c-opt-cpp-prefix
852 "Regexp matching the prefix of a cpp directive in the languages that
853 normally use that macro preprocessor. Tested at bol or at boi.
854 Assumed to not contain any submatches or \\| operators."
855 ;; TODO (ACM, 2005-04-01). Amend the following to recognize escaped NLs;
856 ;; amend all uses of c-opt-cpp-prefix which count regexp-depth.
857 t "\\s *#\\s *"
858 (java awk) nil)
859 (c-lang-defvar c-opt-cpp-prefix (c-lang-const c-opt-cpp-prefix))
861 (c-lang-defconst c-anchored-cpp-prefix
862 "Regexp matching the prefix of a cpp directive anchored to BOL,
863 in the languages that have a macro preprocessor."
864 t "^\\s *\\(#\\)\\s *"
865 (java awk) nil)
866 (c-lang-defvar c-anchored-cpp-prefix (c-lang-const c-anchored-cpp-prefix))
868 (c-lang-defconst c-opt-cpp-start
869 "Regexp matching the prefix of a cpp directive including the directive
870 name, or nil in languages without preprocessor support. The first
871 submatch surrounds the directive name."
872 t (if (c-lang-const c-opt-cpp-prefix)
873 (concat (c-lang-const c-opt-cpp-prefix)
874 "\\([" c-alnum "]+\\)"))
875 ;; Pike, being a scripting language, recognizes hash-bangs too.
876 pike (concat (c-lang-const c-opt-cpp-prefix)
877 "\\([" c-alnum "]+\\|!\\)"))
878 (c-lang-defvar c-opt-cpp-start (c-lang-const c-opt-cpp-start))
880 (c-lang-defconst c-cpp-message-directives
881 "List of cpp directives (without the prefix) that are followed by a
882 string message."
883 t (if (c-lang-const c-opt-cpp-prefix)
884 '("error"))
885 (c c++ objc pike) '("error" "warning"))
887 (c-lang-defconst c-cpp-include-directives
888 "List of cpp directives (without the prefix) that are followed by a
889 file name in angle brackets or quotes."
890 t (if (c-lang-const c-opt-cpp-prefix)
891 '("include"))
892 objc '("include" "import"))
894 (c-lang-defconst c-opt-cpp-macro-define
895 "Cpp directive (without the prefix) that is followed by a macro
896 definition, or nil if the language doesn't have any."
897 t (if (c-lang-const c-opt-cpp-prefix)
898 "define"))
899 (c-lang-defvar c-opt-cpp-macro-define
900 (c-lang-const c-opt-cpp-macro-define))
902 (c-lang-defconst c-opt-cpp-macro-define-start
903 ;; Regexp matching everything up to the macro body of a cpp define, or the
904 ;; end of the logical line if there is none. Submatch 1 is the name of the
905 ;; macro. Set if c-opt-cpp-macro-define is.
906 t (if (c-lang-const c-opt-cpp-macro-define)
907 (concat (c-lang-const c-opt-cpp-prefix)
908 (c-lang-const c-opt-cpp-macro-define)
909 "[ \t]+\\(\\(\\sw\\|_\\)+\\)\\(([^)]*)\\)?"
910 ;; ^ ^ #defined name
911 "\\([ \t]\\|\\\\\n\\)*")))
912 (c-lang-defvar c-opt-cpp-macro-define-start
913 (c-lang-const c-opt-cpp-macro-define-start))
915 (c-lang-defconst c-opt-cpp-macro-define-id
916 ;; Regexp matching everything up to the end of the identifier defined
917 ;; by a cpp define.
918 t (if (c-lang-const c-opt-cpp-macro-define)
919 (concat (c-lang-const c-opt-cpp-prefix) ; #
920 (c-lang-const c-opt-cpp-macro-define) ; define
921 "[ \t]+\\(\\sw\\|_\\)+")))
922 (c-lang-defvar c-opt-cpp-macro-define-id
923 (c-lang-const c-opt-cpp-macro-define-id))
925 (c-lang-defconst c-cpp-expr-directives
926 "List of cpp directives (without the prefix) that are followed by an
927 expression."
928 t (if (c-lang-const c-opt-cpp-prefix)
929 '("if" "elif")))
931 (c-lang-defconst c-cpp-expr-intro-re
932 "Regexp which matches the start of a CPP directive which contains an
933 expression, or nil if there aren't any in the language."
934 t (if (c-lang-const c-cpp-expr-directives)
935 (concat
936 (c-lang-const c-opt-cpp-prefix)
937 (c-make-keywords-re t (c-lang-const c-cpp-expr-directives)))))
938 (c-lang-defvar c-cpp-expr-intro-re
939 (c-lang-const c-cpp-expr-intro-re))
941 (c-lang-defconst c-cpp-expr-functions
942 "List of functions in cpp expressions."
943 t (if (c-lang-const c-opt-cpp-prefix)
944 '("defined"))
945 pike '("defined" "efun" "constant"))
947 (c-lang-defconst c-assignment-operators
948 "List of all assignment operators."
949 t '("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=")
950 java (append (c-lang-const c-assignment-operators)
951 '(">>>="))
952 c++ (append (c-lang-const c-assignment-operators)
953 '("and_eq" "or_eq" "xor_eq" "??!=" "??'="))
954 idl nil)
956 (c-lang-defconst c-operators
957 "List describing all operators, along with their precedence and
958 associativity. The order in the list corresponds to the precedence of
959 the operators: The operators in each element are a group with the same
960 precedence, and the group has higher precedence than the groups in all
961 following elements. The car of each element describes the type of the
962 operator group, and the cdr is a list of the operator tokens in it.
963 The operator group types are:
965 `prefix' Unary prefix operators.
966 `postfix' Unary postfix operators.
967 `postfix-if-paren'
968 Unary postfix operators if and only if the chars have
969 parenthesis syntax.
970 `left-assoc' Binary left associative operators (i.e. a+b+c means (a+b)+c).
971 `right-assoc' Binary right associative operators (i.e. a=b=c means a=(b=c)).
972 `right-assoc-sequence'
973 Right associative operator that constitutes of a
974 sequence of tokens that separate expressions. All the
975 tokens in the group are in this case taken as
976 describing the sequence in one such operator, and the
977 order between them is therefore significant.
979 Operators containing a character with paren syntax are taken to match
980 with a corresponding open/close paren somewhere else. A postfix
981 operator with close paren syntax is taken to end a postfix expression
982 started somewhere earlier, rather than start a new one at point. Vice
983 versa for prefix operators with open paren syntax.
985 Note that operators like \".\" and \"->\" which in language references
986 often are described as postfix operators are considered binary here,
987 since CC Mode treats every identifier as an expression."
989 ;; There's currently no code in CC Mode that exploits all the info
990 ;; in this variable; precedence, associativity etc are present as a
991 ;; preparation for future work.
993 ;; FIXME!!! C++11's "auto" operators "=" and "->" need to go in here
994 ;; somewhere. 2012-03-24.
996 t `(;; Preprocessor.
997 ,@(when (c-lang-const c-opt-cpp-prefix)
998 `((prefix "#"
999 ,@(when (c-major-mode-is '(c-mode c++-mode))
1000 '("%:" "??=")))
1001 (left-assoc "##"
1002 ,@(when (c-major-mode-is '(c-mode c++-mode))
1003 '("%:%:" "??=??=")))))
1005 ;; Primary.
1006 ,@(c-lang-const c-identifier-ops)
1007 ,@(cond ((or (c-major-mode-is 'c++-mode) (c-major-mode-is 'java-mode))
1008 `((postfix-if-paren "<" ">"))) ; Templates.
1009 ((c-major-mode-is 'pike-mode)
1010 `((prefix "global" "predef")))
1011 ((c-major-mode-is 'java-mode)
1012 `((prefix "super"))))
1014 ;; Postfix.
1015 ,@(when (c-major-mode-is 'c++-mode)
1016 ;; The following need special treatment.
1017 `((prefix "dynamic_cast" "static_cast"
1018 "reinterpret_cast" "const_cast" "typeid"
1019 "alignof")))
1020 (left-assoc "."
1021 ,@(unless (c-major-mode-is 'java-mode)
1022 '("->")))
1023 (postfix "++" "--" "[" "]" "(" ")"
1024 ,@(when (c-major-mode-is '(c-mode c++-mode))
1025 '("<:" ":>" "??(" "??)")))
1027 ;; Unary.
1028 (prefix "++" "--" "+" "-" "!" "~"
1029 ,@(when (c-major-mode-is 'c++-mode) '("not" "compl"))
1030 ,@(when (c-major-mode-is '(c-mode c++-mode))
1031 '("*" "&" "sizeof" "??-"))
1032 ,@(when (c-major-mode-is 'objc-mode)
1033 '("@selector" "@protocol" "@encode"))
1034 ;; The following need special treatment.
1035 ,@(cond ((c-major-mode-is 'c++-mode)
1036 '("new" "delete"))
1037 ((c-major-mode-is 'java-mode)
1038 '("new"))
1039 ((c-major-mode-is 'pike-mode)
1040 '("class" "lambda" "catch" "throw" "gauge")))
1041 "(" ")" ; Cast.
1042 ,@(when (c-major-mode-is 'pike-mode)
1043 '("[" "]"))) ; Type cast.
1045 ;; Member selection.
1046 ,@(when (c-major-mode-is 'c++-mode)
1047 `((left-assoc ".*" "->*")))
1049 ;; Multiplicative.
1050 (left-assoc "*" "/" "%")
1052 ;; Additive.
1053 (left-assoc "+" "-")
1055 ;; Shift.
1056 (left-assoc "<<" ">>"
1057 ,@(when (c-major-mode-is 'java-mode)
1058 '(">>>")))
1060 ;; Relational.
1061 (left-assoc "<" ">" "<=" ">="
1062 ,@(when (c-major-mode-is 'java-mode)
1063 '("instanceof")))
1065 ;; Equality.
1066 (left-assoc "==" "!="
1067 ,@(when (c-major-mode-is 'c++-mode) '("not_eq")))
1069 ;; Bitwise and.
1070 (left-assoc "&"
1071 ,@(when (c-major-mode-is 'c++-mode) '("bitand")))
1073 ;; Bitwise exclusive or.
1074 (left-assoc "^"
1075 ,@(when (c-major-mode-is '(c-mode c++-mode))
1076 '("??'"))
1077 ,@(when (c-major-mode-is 'c++-mode) '("xor")))
1079 ;; Bitwise or.
1080 (left-assoc "|"
1081 ,@(when (c-major-mode-is '(c-mode c++-mode))
1082 '("??!"))
1083 ,@(when (c-major-mode-is 'c++-mode) '("bitor")))
1085 ;; Logical and.
1086 (left-assoc "&&"
1087 ,@(when (c-major-mode-is 'c++-mode) '("and")))
1089 ;; Logical or.
1090 (left-assoc "||"
1091 ,@(when (c-major-mode-is '(c-mode c++-mode))
1092 '("??!??!"))
1093 ,@(when (c-major-mode-is 'c++-mode) '("or")))
1095 ;; Conditional.
1096 (right-assoc-sequence "?" ":")
1098 ;; Assignment.
1099 (right-assoc ,@(c-lang-const c-assignment-operators))
1101 ;; Exception.
1102 ,@(when (c-major-mode-is 'c++-mode)
1103 '((prefix "throw")))
1105 ;; Sequence.
1106 (left-assoc ","))
1108 ;; IDL got its own definition since it has a much smaller operator
1109 ;; set than the other languages.
1110 idl `(;; Preprocessor.
1111 (prefix "#")
1112 (left-assoc "##")
1113 ;; Primary.
1114 ,@(c-lang-const c-identifier-ops)
1115 ;; Unary.
1116 (prefix "+" "-" "~")
1117 ;; Multiplicative.
1118 (left-assoc "*" "/" "%")
1119 ;; Additive.
1120 (left-assoc "+" "-")
1121 ;; Shift.
1122 (left-assoc "<<" ">>")
1123 ;; And.
1124 (left-assoc "&")
1125 ;; Xor.
1126 (left-assoc "^")
1127 ;; Or.
1128 (left-assoc "|")))
1130 (c-lang-defconst c-operator-list
1131 ;; The operators as a flat list (without duplicates).
1132 t (c-filter-ops (c-lang-const c-operators) t t))
1134 (c-lang-defconst c-overloadable-operators
1135 "List of the operators that are overloadable, in their \"identifier
1136 form\". See also `c-op-identifier-prefix'."
1137 t nil
1138 c++ '("new" "delete" ;; Can be followed by "[]" but we ignore that.
1139 "+" "-" "*" "/" "%"
1140 "^" "??'" "xor" "&" "bitand" "|" "??!" "bitor" "~" "??-" "compl"
1141 "!" "=" "<" ">" "+=" "-=" "*=" "/=" "%=" "^="
1142 "??'=" "xor_eq" "&=" "and_eq" "|=" "??!=" "or_eq"
1143 "<<" ">>" ">>=" "<<=" "==" "!=" "not_eq" "<=" ">="
1144 "&&" "and" "||" "??!??!" "or" "++" "--" "," "->*" "->"
1145 "()" "[]" "<::>" "??(??)")
1146 ;; These work like identifiers in Pike.
1147 pike '("`+" "`-" "`&" "`|" "`^" "`<<" "`>>" "`*" "`/" "`%" "`~"
1148 "`==" "`<" "`>" "`!" "`[]" "`[]=" "`->" "`->=" "`()" "``+"
1149 "``-" "``&" "``|" "``^" "``<<" "``>>" "``*" "``/" "``%"
1150 "`+="))
1152 (c-lang-defconst c-overloadable-operators-regexp
1153 ;; Regexp tested after an "operator" token in C++.
1154 t nil
1155 c++ (c-make-keywords-re nil (c-lang-const c-overloadable-operators)))
1156 (c-lang-defvar c-overloadable-operators-regexp
1157 (c-lang-const c-overloadable-operators-regexp))
1159 (c-lang-defconst c-opt-op-identifier-prefix
1160 "Regexp matching the token before the ones in
1161 `c-overloadable-operators' when operators are specified in their
1162 \"identifier form\". This typically matches \"operator\" in C++ where
1163 operator functions are specified as e.g. \"operator +\". It's nil in
1164 languages without operator functions or where the complete operator
1165 identifier is listed in `c-overloadable-operators'.
1167 This regexp is assumed to not match any non-operator identifier."
1168 t nil
1169 c++ (c-make-keywords-re t '("operator")))
1170 (c-lang-defvar c-opt-op-identifier-prefix
1171 (c-lang-const c-opt-op-identifier-prefix))
1173 ;; Note: the following alias is an old name which was a mis-spelling. It has
1174 ;; been corrected above and throughout cc-engine.el. It will be removed at
1175 ;; some release very shortly in the future. ACM, 2006-04-14.
1176 (defvaralias 'c-opt-op-identitier-prefix 'c-opt-op-identifier-prefix)
1177 (make-obsolete-variable 'c-opt-op-identitier-prefix 'c-opt-op-identifier-prefix
1178 "CC Mode 5.31.4, 2006-04-14")
1180 (c-lang-defconst c-other-op-syntax-tokens
1181 "List of the tokens made up of characters in the punctuation or
1182 parenthesis syntax classes that have uses other than as expression
1183 operators."
1184 t '("{" "}" "(" ")" "[" "]" ";" ":" "," "=" "/*" "*/" "//")
1185 (c c++ pike) (append '("#" "##" ; Used by cpp.
1186 "::" "...")
1187 (c-lang-const c-other-op-syntax-tokens))
1188 (c c++) (append '("*") (c-lang-const c-other-op-syntax-tokens))
1189 c++ (append '("&" "<%" "%>" "<:" ":>" "%:" "%:%:")
1190 (c-lang-const c-other-op-syntax-tokens))
1191 objc (append '("#" "##" ; Used by cpp.
1192 "+" "-")
1193 (c-lang-const c-other-op-syntax-tokens))
1194 idl (append '("#" "##") ; Used by cpp.
1195 (c-lang-const c-other-op-syntax-tokens))
1196 pike (append '("..")
1197 (c-lang-const c-other-op-syntax-tokens)
1198 (c-lang-const c-overloadable-operators))
1199 awk '("{" "}" "(" ")" "[" "]" ";" "," "=" "/"))
1201 (c-lang-defconst c-all-op-syntax-tokens
1202 ;; List of all tokens in the punctuation and parenthesis syntax
1203 ;; classes.
1204 t (c--delete-duplicates (append (c-lang-const c-other-op-syntax-tokens)
1205 (c-lang-const c-operator-list))
1206 :test 'string-equal))
1208 (c-lang-defconst c-nonsymbol-token-char-list
1209 ;; List containing all chars not in the word, symbol or
1210 ;; syntactically irrelevant syntax classes, i.e. all punctuation,
1211 ;; parenthesis and string delimiter chars.
1212 t (c-with-syntax-table (c-lang-const c-mode-syntax-table)
1213 ;; Only go through the chars in the printable ASCII range. No
1214 ;; language so far has 8-bit or widestring operators.
1215 (let (list (char 32))
1216 (while (< char 127)
1217 (or (memq (char-syntax char) '(?w ?_ ?< ?> ?\ ))
1218 (setq list (cons (c-int-to-char char) list)))
1219 (setq char (1+ char)))
1220 list)))
1222 (c-lang-defconst c-nonsymbol-token-regexp
1223 ;; Regexp matching all tokens in the punctuation and parenthesis
1224 ;; syntax classes. Note that this also matches ".", which can start
1225 ;; a float.
1226 t (c-make-keywords-re nil
1227 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1229 "\\`\\(\\s.\\)+\\'")))
1230 (c-lang-defvar c-nonsymbol-token-regexp
1231 (c-lang-const c-nonsymbol-token-regexp))
1233 (c-lang-defconst c-assignment-op-regexp
1234 ;; Regexp matching all assignment operators and only them. The
1235 ;; beginning of the first submatch is used to detect the end of the
1236 ;; token, along with the end of the whole match.
1237 t (if (c-lang-const c-assignment-operators)
1238 (concat
1239 ;; Need special case for "=" since it's a prefix of "==".
1240 "=\\([^=]\\|$\\)"
1241 "\\|"
1242 (c-make-keywords-re nil
1243 (c--set-difference (c-lang-const c-assignment-operators)
1244 '("=")
1245 :test 'string-equal)))
1246 "\\<\\>"))
1247 (c-lang-defvar c-assignment-op-regexp
1248 (c-lang-const c-assignment-op-regexp))
1250 (c-lang-defconst c-arithmetic-operators
1251 "List of all arithmetic operators, including \"+=\", etc."
1252 ;; Note: in the following, there are too many operators for AWK and IDL.
1253 t (append (c-lang-const c-assignment-operators)
1254 '("+" "-" "*" "/" "%"
1255 "<<" ">>"
1256 "<" ">" "<=" ">="
1257 "==" "!="
1258 "&" "^" "|"
1259 "&&" "||")))
1261 (c-lang-defconst c-arithmetic-op-regexp
1262 t (c-make-keywords-re nil
1263 (c-lang-const c-arithmetic-operators)))
1264 (c-lang-defvar c-arithmetic-op-regexp (c-lang-const c-arithmetic-op-regexp))
1266 (c-lang-defconst c-:$-multichar-token-regexp
1267 ;; Regexp matching all tokens ending in ":" which are longer than one char.
1268 ;; Currently (2016-01-07) only used in C++ Mode.
1269 t (c-make-keywords-re nil
1270 (c-filter-ops (c-lang-const c-operators) t ".+:$")))
1271 (c-lang-defvar c-:$-multichar-token-regexp
1272 (c-lang-const c-:$-multichar-token-regexp))
1274 (c-lang-defconst c-<>-multichar-token-regexp
1275 ;; Regexp matching all tokens containing "<" or ">" which are longer
1276 ;; than one char.
1277 t (c-make-keywords-re nil
1278 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1280 ".[<>]\\|[<>].")))
1281 (c-lang-defvar c-<>-multichar-token-regexp
1282 (c-lang-const c-<>-multichar-token-regexp))
1284 (c-lang-defconst c-<-op-cont-regexp
1285 ;; Regexp matching the second and subsequent characters of all
1286 ;; multicharacter tokens that begin with "<".
1287 t (c-make-keywords-re nil
1288 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1290 "\\`<."
1291 (lambda (op) (substring op 1)))))
1292 (c-lang-defvar c-<-op-cont-regexp (c-lang-const c-<-op-cont-regexp))
1294 (c-lang-defconst c->-op-cont-tokens
1295 ;; A list of second and subsequent characters of all multicharacter tokens
1296 ;; that begin with ">".
1297 t (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1299 "\\`>."
1300 (lambda (op) (substring op 1)))
1301 java (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1303 "\\`>[^>]\\|\\`>>[^>]"
1304 (lambda (op) (substring op 1))))
1306 (c-lang-defconst c->-op-cont-regexp
1307 ;; Regexp matching the second and subsequent characters of all
1308 ;; multicharacter tokens that begin with ">".
1309 t (c-make-keywords-re nil (c-lang-const c->-op-cont-tokens)))
1310 (c-lang-defvar c->-op-cont-regexp (c-lang-const c->-op-cont-regexp))
1312 (c-lang-defconst c->-op-without->-cont-regexp
1313 ;; Regexp matching the second and subsequent characters of all
1314 ;; multicharacter tokens that begin with ">" except for those beginning with
1315 ;; ">>".
1316 t (c-make-keywords-re nil
1317 (c--set-difference
1318 (c-lang-const c->-op-cont-tokens)
1319 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1321 "\\`>>"
1322 (lambda (op) (substring op 1)))
1323 :test 'string-equal)))
1324 (c-lang-defvar c->-op-without->-cont-regexp
1325 (c-lang-const c->-op-without->-cont-regexp))
1327 (c-lang-defconst c-multichar->-op-not->>-regexp
1328 ;; Regexp matching multichar tokens containing ">", except ">>"
1329 t (c-make-keywords-re nil
1330 (delete ">>"
1331 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1333 "\\(.>\\|>.\\)"))))
1334 (c-lang-defvar c-multichar->-op-not->>-regexp
1335 (c-lang-const c-multichar->-op-not->>-regexp))
1337 (c-lang-defconst c-stmt-delim-chars
1338 ;; The characters that should be considered to bound statements. To
1339 ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to
1340 ;; begin with "^" to negate the set. If ? : operators should be
1341 ;; detected then the string must end with "?:".
1342 t "^;{}?:")
1343 (c-lang-defvar c-stmt-delim-chars (c-lang-const c-stmt-delim-chars))
1345 (c-lang-defconst c-stmt-delim-chars-with-comma
1346 ;; Variant of `c-stmt-delim-chars' that additionally contains ','.
1347 t "^;,{}?:")
1348 (c-lang-defvar c-stmt-delim-chars-with-comma
1349 (c-lang-const c-stmt-delim-chars-with-comma))
1351 (c-lang-defconst c-pack-ops
1352 "Ops which signal C++11's \"parameter pack\""
1353 t nil
1354 c++ '("..."))
1355 (c-lang-defconst c-pack-key
1356 t (c-make-keywords-re 'appendable (c-lang-const c-pack-ops)))
1357 (c-lang-defvar c-pack-key (c-lang-const c-pack-key))
1359 (c-lang-defconst c-auto-ops
1360 ;; Ops which signal C++11's new auto uses.
1361 t nil
1362 c++ '("=" "->"))
1363 (c-lang-defconst c-auto-ops-re
1364 t (c-make-keywords-re nil (c-lang-const c-auto-ops)))
1365 (c-lang-defvar c-auto-ops-re (c-lang-const c-auto-ops-re))
1367 (c-lang-defconst c-haskell-op
1368 ;; Op used in the new C++11 auto function definition, indicating type.
1369 t nil
1370 c++ '("->"))
1371 (c-lang-defconst c-haskell-op-re
1372 t (c-make-keywords-re nil (c-lang-const c-haskell-op)))
1373 (c-lang-defvar c-haskell-op-re (c-lang-const c-haskell-op-re))
1375 (c-lang-defconst c-pre-start-tokens
1376 "List of operators following which an apparent declaration \(e.g.
1377 \"t1 *fn (t2 *b);\") is most likely to be an actual declaration
1378 \(as opposed to an arithmetic expression)."
1379 t '(";" "{" "}"))
1380 (c-lang-defvar c-pre-start-tokens (c-lang-const c-pre-start-tokens))
1382 (c-lang-defconst c-pre-lambda-tokens
1383 "List of tokens which may precede a lambda declaration.
1384 In C++ this is something like \"[a,b] (foo, bar) -> int { ... };\".
1385 Currently (2016-08) only used in C++ mode."
1386 t (c--set-difference
1387 (c--delete-duplicates
1388 (append (c-lang-const c-operator-list)
1389 (c-lang-const c-other-op-syntax-tokens)))
1390 (append
1391 '("#" "%:" "??=" "##" "%:%:" "??=??=" "::" "." "->"
1392 "]" "<:" ":>" "??(" "??)" "??-" "new" "delete"
1393 ")" ".*" "->*" "??'" "??!" "??!??!" "??!=" "??'=")
1394 '("<%" "%>" "<:" ":>" "%:" "%:%:" "#" "##" "::" "..."))
1395 :test #'string-equal))
1397 (c-lang-defconst c-pre-lambda-tokens-re
1398 ;; Regexp matching any token in the list `c-pre-lambda-tokens'.
1399 t (regexp-opt (c-lang-const c-pre-lambda-tokens)))
1400 (c-lang-defvar c-pre-lambda-tokens-re (c-lang-const c-pre-lambda-tokens-re))
1402 ;;; Syntactic whitespace.
1404 (c-lang-defconst c-simple-ws
1405 "Regexp matching an ordinary whitespace character.
1406 Does not contain a \\| operator at the top level."
1407 ;; "\\s " is not enough since it doesn't match line breaks.
1408 t "\\(\\s \\|[\n\r]\\)")
1410 (c-lang-defconst c-simple-ws-depth
1411 ;; Number of regexp grouping parens in `c-simple-ws'.
1412 t (regexp-opt-depth (c-lang-const c-simple-ws)))
1414 (c-lang-defconst c-line-comment-starter
1415 "String that starts line comments, or nil if such don't exist.
1416 Line comments are always terminated by newlines. At least one of
1417 `c-block-comment-starter' and this one is assumed to be set.
1419 Note that it's currently not enough to set this to support a new
1420 comment style. Other stuff like the syntax table must also be set up
1421 properly."
1422 t "//"
1423 awk "#")
1424 (c-lang-defvar c-line-comment-starter (c-lang-const c-line-comment-starter))
1426 (c-lang-defconst c-block-comment-starter
1427 "String that starts block comments, or nil if such don't exist.
1428 Block comments are ended by `c-block-comment-ender', which is assumed
1429 to be set if this is. At least one of `c-line-comment-starter' and
1430 this one is assumed to be set.
1432 Note that it's currently not enough to set this to support a new
1433 comment style. Other stuff like the syntax table must also be set up
1434 properly."
1435 t "/*"
1436 awk nil)
1438 (c-lang-defconst c-block-comment-ender
1439 "String that ends block comments, or nil if such don't exist.
1441 Note that it's currently not enough to set this to support a new
1442 comment style. Other stuff like the syntax table must also be set up
1443 properly."
1444 t "*/"
1445 awk nil)
1447 (c-lang-defconst c-block-comment-ender-regexp
1448 ;; Regexp which matches the end of a block comment (if such exists in the
1449 ;; language)
1450 t (if (c-lang-const c-block-comment-ender)
1451 (regexp-quote (c-lang-const c-block-comment-ender))
1452 "\\<\\>"))
1453 (c-lang-defvar c-block-comment-ender-regexp
1454 (c-lang-const c-block-comment-ender-regexp))
1456 (c-lang-defconst c-comment-start-regexp
1457 ;; Regexp to match the start of any type of comment.
1458 t (let ((re (c-make-keywords-re nil
1459 (list (c-lang-const c-line-comment-starter)
1460 (c-lang-const c-block-comment-starter)))))
1461 (if (memq 'gen-comment-delim c-emacs-features)
1462 (concat re "\\|\\s!")
1463 re)))
1464 (c-lang-defvar c-comment-start-regexp (c-lang-const c-comment-start-regexp))
1466 (c-lang-defconst c-block-comment-start-regexp
1467 ;; Regexp which matches the start of a block comment (if such exists in the
1468 ;; language)
1469 t (if (c-lang-const c-block-comment-starter)
1470 (regexp-quote (c-lang-const c-block-comment-starter))
1471 "\\<\\>"))
1472 (c-lang-defvar c-block-comment-start-regexp
1473 (c-lang-const c-block-comment-start-regexp))
1475 (c-lang-defconst c-line-comment-start-regexp
1476 ;; Regexp which matches the start of a line comment (if such exists in the
1477 ;; language; it does in all 7 CC Mode languages).
1478 t (if (c-lang-const c-line-comment-starter)
1479 (regexp-quote (c-lang-const c-line-comment-starter))
1480 "\\<\\>"))
1481 (c-lang-defvar c-line-comment-start-regexp
1482 (c-lang-const c-line-comment-start-regexp))
1484 (c-lang-defconst c-literal-start-regexp
1485 ;; Regexp to match the start of comments and string literals.
1486 t (concat (c-lang-const c-comment-start-regexp)
1487 "\\|"
1488 (if (memq 'gen-string-delim c-emacs-features)
1489 "\"|"
1490 "\"")))
1491 (c-lang-defvar c-literal-start-regexp (c-lang-const c-literal-start-regexp))
1493 (c-lang-defconst c-doc-comment-start-regexp
1494 "Regexp to match the start of documentation comments."
1495 t "\\<\\>"
1496 ;; From font-lock.el: `doxygen' uses /*! while others use /**.
1497 (c c++ objc) "/\\*[*!]"
1498 java "/\\*\\*"
1499 pike "/[/*]!")
1500 (c-lang-defvar c-doc-comment-start-regexp
1501 (c-lang-const c-doc-comment-start-regexp))
1503 (c-lang-defconst comment-start
1504 "String that starts comments inserted with M-; etc.
1505 `comment-start' is initialized from this."
1506 ;; Default: Prefer line comments to block comments, and pad with a space.
1507 t (concat (or (c-lang-const c-line-comment-starter)
1508 (c-lang-const c-block-comment-starter))
1509 " ")
1510 ;; In C we still default to the block comment style since line
1511 ;; comments aren't entirely portable.
1512 c "/* ")
1513 (c-lang-setvar comment-start (c-lang-const comment-start))
1515 (c-lang-defconst comment-end
1516 "String that ends comments inserted with M-; etc.
1517 `comment-end' is initialized from this."
1518 ;; Default: Use block comment style if comment-start uses block
1519 ;; comments, and pad with a space in that case.
1520 t (if (string-match (concat "\\`\\("
1521 (c-lang-const c-block-comment-start-regexp)
1522 "\\)")
1523 (c-lang-const comment-start))
1524 (concat " " (c-lang-const c-block-comment-ender))
1525 ""))
1526 (c-lang-setvar comment-end (c-lang-const comment-end))
1528 (c-lang-defconst comment-start-skip
1529 "Regexp to match the start of a comment plus everything up to its body.
1530 `comment-start-skip' is initialized from this."
1531 ;; Default: Allow the last char of the comment starter(s) to be
1532 ;; repeated, then allow any amount of horizontal whitespace.
1533 t (concat "\\("
1534 (c-concat-separated
1535 (mapcar (lambda (cs)
1536 (when cs
1537 (concat (regexp-quote cs) "+")))
1538 (list (c-lang-const c-line-comment-starter)
1539 (c-lang-const c-block-comment-starter)))
1540 "\\|")
1541 "\\)\\s *"))
1542 (c-lang-setvar comment-start-skip (c-lang-const comment-start-skip))
1544 (c-lang-defconst comment-end-can-be-escaped
1545 "When non-nil, escaped EOLs inside comments are valid.
1546 This works in Emacs >= 25.1."
1547 t nil
1548 (c c++ objc) t)
1549 (c-lang-setvar comment-end-can-be-escaped
1550 (c-lang-const comment-end-can-be-escaped))
1552 (c-lang-defconst c-syntactic-ws-start
1553 ;; Regexp matching any sequence that can start syntactic whitespace.
1554 ;; The only uncertain case is '#' when there are cpp directives.
1555 t (concat "\\s \\|"
1556 (c-make-keywords-re nil
1557 (append (list (c-lang-const c-line-comment-starter)
1558 (c-lang-const c-block-comment-starter)
1559 (when (c-lang-const c-opt-cpp-prefix)
1560 "#"))
1561 '("\n" "\r")))
1562 "\\|\\\\[\n\r]"
1563 (when (memq 'gen-comment-delim c-emacs-features)
1564 "\\|\\s!")))
1565 (c-lang-defvar c-syntactic-ws-start (c-lang-const c-syntactic-ws-start))
1567 (c-lang-defconst c-syntactic-ws-end
1568 ;; Regexp matching any single character that might end syntactic whitespace.
1569 t (concat "\\s \\|"
1570 (c-make-keywords-re nil
1571 (append (when (c-lang-const c-block-comment-ender)
1572 (list
1573 (string
1574 (elt (c-lang-const c-block-comment-ender)
1575 (1- (length
1576 (c-lang-const c-block-comment-ender)))))))
1577 '("\n" "\r")))
1578 (when (memq 'gen-comment-delim c-emacs-features)
1579 "\\|\\s!")))
1580 (c-lang-defvar c-syntactic-ws-end (c-lang-const c-syntactic-ws-end))
1582 (c-lang-defconst c-unterminated-block-comment-regexp
1583 ;; Regexp matching an unterminated block comment that doesn't
1584 ;; contain line breaks, or nil in languages without block comments.
1585 ;; Does not contain a \| operator at the top level.
1586 t (when (c-lang-const c-block-comment-starter)
1587 (concat
1588 (regexp-quote (c-lang-const c-block-comment-starter))
1589 ;; It's messy to cook together a regexp that matches anything
1590 ;; but c-block-comment-ender.
1591 (let ((end (c-lang-const c-block-comment-ender)))
1592 (cond ((= (length end) 1)
1593 (concat "[^" end "\n\r]*"))
1594 ((= (length end) 2)
1595 (concat "[^" (substring end 0 1) "\n\r]*"
1596 "\\("
1597 (regexp-quote (substring end 0 1)) "+"
1598 "[^"
1599 ;; The quoting rules inside char classes are silly. :P
1600 (cond ((= (elt end 0) (elt end 1))
1601 (concat (substring end 0 1) "\n\r"))
1602 ((= (elt end 1) ?\])
1603 (concat (substring end 1 2) "\n\r"
1604 (substring end 0 1)))
1606 (concat (substring end 0 1) "\n\r"
1607 (substring end 1 2))))
1609 "[^" (substring end 0 1) "\n\r]*"
1610 "\\)*"))
1612 (error "Can't handle a block comment ender of length %s"
1613 (length end))))))))
1615 (c-lang-defconst c-block-comment-regexp
1616 ;; Regexp matching a block comment that doesn't contain line breaks,
1617 ;; or nil in languages without block comments. The reason we don't
1618 ;; allow line breaks is to avoid going very far and risk running out
1619 ;; of regexp stack; this regexp is intended to handle only short
1620 ;; comments that might be put in the middle of limited constructs
1621 ;; like declarations. Does not contain a \| operator at the top
1622 ;; level.
1623 t (when (c-lang-const c-unterminated-block-comment-regexp)
1624 (concat
1625 (c-lang-const c-unterminated-block-comment-regexp)
1626 (let ((end (c-lang-const c-block-comment-ender)))
1627 (cond ((= (length end) 1)
1628 (regexp-quote end))
1629 ((= (length end) 2)
1630 (concat (regexp-quote (substring end 0 1)) "+"
1631 (regexp-quote (substring end 1 2))))
1633 (error "Can't handle a block comment ender of length %s"
1634 (length end))))))))
1636 (c-lang-defconst c-nonwhite-syntactic-ws
1637 ;; Regexp matching a piece of syntactic whitespace that isn't a
1638 ;; sequence of simple whitespace characters. As opposed to
1639 ;; `c-(forward|backward)-syntactic-ws', this doesn't regard cpp
1640 ;; directives as syntactic whitespace.
1641 t (c-concat-separated
1642 (list (when (c-lang-const c-line-comment-starter)
1643 (concat (regexp-quote (c-lang-const c-line-comment-starter))
1644 "[^\n\r]*[\n\r]"))
1645 (c-lang-const c-block-comment-regexp)
1646 "\\\\[\n\r]"
1647 (when (memq 'gen-comment-delim c-emacs-features)
1648 "\\s!\\S!*\\s!"))
1649 "\\|"))
1651 (c-lang-defconst c-syntactic-ws
1652 ;; Regexp matching syntactic whitespace, including possibly the
1653 ;; empty string. As opposed to `c-(forward|backward)-syntactic-ws',
1654 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1655 ;; not contain a \| operator at the top level.
1656 t (concat (c-lang-const c-simple-ws) "*"
1657 "\\("
1658 (concat "\\(" (c-lang-const c-nonwhite-syntactic-ws) "\\)"
1659 (c-lang-const c-simple-ws) "*")
1660 "\\)*"))
1662 (c-lang-defconst c-syntactic-ws-depth
1663 ;; Number of regexp grouping parens in `c-syntactic-ws'.
1664 t (regexp-opt-depth (c-lang-const c-syntactic-ws)))
1666 (c-lang-defconst c-nonempty-syntactic-ws
1667 ;; Regexp matching syntactic whitespace, which is at least one
1668 ;; character long. As opposed to `c-(forward|backward)-syntactic-ws',
1669 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1670 ;; not contain a \| operator at the top level.
1671 t (concat "\\("
1672 (c-lang-const c-simple-ws)
1673 "\\|"
1674 (c-lang-const c-nonwhite-syntactic-ws)
1675 "\\)+"))
1677 (c-lang-defconst c-nonempty-syntactic-ws-depth
1678 ;; Number of regexp grouping parens in `c-nonempty-syntactic-ws'.
1679 t (regexp-opt-depth (c-lang-const c-nonempty-syntactic-ws)))
1681 (c-lang-defconst c-single-line-syntactic-ws
1682 ;; Regexp matching syntactic whitespace without any line breaks. As
1683 ;; opposed to `c-(forward|backward)-syntactic-ws', this doesn't
1684 ;; regard cpp directives as syntactic whitespace. Does not contain
1685 ;; a \| operator at the top level.
1686 t (if (c-lang-const c-block-comment-regexp)
1687 (concat "\\s *\\("
1688 (c-lang-const c-block-comment-regexp)
1689 "\\s *\\)*")
1690 "\\s *"))
1692 (c-lang-defconst c-single-line-syntactic-ws-depth
1693 ;; Number of regexp grouping parens in `c-single-line-syntactic-ws'.
1694 t (regexp-opt-depth (c-lang-const c-single-line-syntactic-ws)))
1696 (c-lang-defconst c-syntactic-eol
1697 ;; Regexp that matches when there is no syntactically significant
1698 ;; text before eol. Macros are regarded as syntactically
1699 ;; significant text here.
1700 t (concat (c-lang-const c-single-line-syntactic-ws)
1701 ;; Match eol (possibly inside a block comment or preceded
1702 ;; by a line continuation backslash), or the beginning of a
1703 ;; line comment. Note: This has to be modified for awk
1704 ;; where line comments start with '#'.
1705 "\\("
1706 (c-concat-separated
1707 (list (when (c-lang-const c-line-comment-starter)
1708 (regexp-quote (c-lang-const c-line-comment-starter)))
1709 (when (c-lang-const c-unterminated-block-comment-regexp)
1710 (concat (c-lang-const c-unterminated-block-comment-regexp)
1711 "$"))
1712 "\\\\$"
1713 "$")
1714 "\\|")
1715 "\\)"))
1716 (c-lang-defvar c-syntactic-eol (c-lang-const c-syntactic-eol))
1719 ;;; Defun handling.
1721 ;; The Emacs variables beginning-of-defun-function and end-of-defun-function
1722 ;; will be set so that commands like `mark-defun' and `narrow-to-defun' work
1723 ;; right. In older Emacsen, the key sequences C-M-a and C-M-e are, however,
1724 ;; bound directly to the CC Mode functions, allowing optimization for large n.
1725 ;; From Emacs 23, this isn't necessary any more, since n is passed to the two
1726 ;; functions.
1727 (c-lang-defconst beginning-of-defun-function
1728 "Function to which beginning-of-defun-function will be set."
1729 t 'c-beginning-of-defun
1730 awk 'c-awk-beginning-of-defun)
1731 (c-lang-setvar beginning-of-defun-function
1732 (c-lang-const beginning-of-defun-function))
1734 (c-lang-defconst end-of-defun-function
1735 "Function to which end-of-defun-function will be set."
1736 t 'c-end-of-defun
1737 awk 'c-awk-end-of-defun)
1738 (c-lang-setvar end-of-defun-function (c-lang-const end-of-defun-function))
1740 ;;; In-comment text handling.
1742 (c-lang-defconst c-paragraph-start
1743 "Regexp to append to `paragraph-start'."
1744 t "$"
1745 java "\\(@[a-zA-Z]+\\>\\|$\\)" ; For Javadoc.
1746 pike "\\(@[a-zA-Z_-]+\\>\\([^{]\\|$\\)\\|$\\)") ; For Pike refdoc.
1747 (c-lang-defvar c-paragraph-start (c-lang-const c-paragraph-start))
1749 (c-lang-defconst c-paragraph-separate
1750 "Regexp to append to `paragraph-separate'."
1751 t "$"
1752 pike (c-lang-const c-paragraph-start))
1753 (c-lang-defvar c-paragraph-separate (c-lang-const c-paragraph-separate))
1756 ;;; Keyword lists.
1758 ;; Note: All and only all language constants containing keyword lists
1759 ;; should end with "-kwds"; they're automatically collected into the
1760 ;; `c-kwds-lang-consts' list below and used to build `c-keywords' etc.
1762 (c-lang-defconst c-primitive-type-kwds
1763 "Primitive type keywords. As opposed to the other keyword lists, the
1764 keywords listed here are fontified with the type face instead of the
1765 keyword face.
1767 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1768 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1769 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1770 will be handled.
1772 Do not try to modify this list for end user customizations; the
1773 `*-font-lock-extra-types' variable, where `*' is the mode prefix, is
1774 the appropriate place for that."
1775 t '("char" "double" "float" "int" "long" "short" "signed"
1776 "unsigned" "void")
1777 c (append
1778 '("_Bool" "_Complex" "_Imaginary") ; Conditionally defined in C99.
1779 (c-lang-const c-primitive-type-kwds))
1780 c++ (append
1781 '("bool" "wchar_t" "char16_t" "char32_t")
1782 (c-lang-const c-primitive-type-kwds))
1783 ;; Objective-C extends C, but probably not the new stuff in C99.
1784 objc (append
1785 '("id" "Class" "SEL" "IMP" "BOOL")
1786 (c-lang-const c-primitive-type-kwds))
1787 java '("boolean" "byte" "char" "double" "float" "int" "long" "short" "void")
1788 idl '("Object" "ValueBase" "any" "boolean" "char" "double" "fixed" "float"
1789 "long" "octet" "sequence" "short" "string" "void" "wchar" "wstring"
1790 ;; In CORBA PSDL:
1791 "ref"
1792 ;; The following can't really end a type, but we have to specify them
1793 ;; here due to the assumption in `c-primitive-type-prefix-kwds'. It
1794 ;; doesn't matter that much.
1795 "unsigned" "strong")
1796 pike '(;; this_program isn't really a keyword, but it's practically
1797 ;; used as a builtin type.
1798 "array" "float" "function" "int" "mapping" "mixed" "multiset"
1799 "object" "program" "string" "this_program" "void"))
1801 (c-lang-defconst c-return-kwds
1802 "Keywords which return a value to the calling function."
1803 t '("return")
1804 idl nil)
1806 (c-lang-defconst c-return-key
1807 ;; Adorned regexp matching `c-return-kwds'.
1808 t (c-make-keywords-re t (c-lang-const c-return-kwds)))
1809 (c-lang-defvar c-return-key (c-lang-const c-return-key))
1811 (c-lang-defconst c-primitive-type-key
1812 ;; An adorned regexp that matches `c-primitive-type-kwds'.
1813 t (c-make-keywords-re t (c-lang-const c-primitive-type-kwds)))
1814 (c-lang-defvar c-primitive-type-key (c-lang-const c-primitive-type-key))
1816 (c-lang-defconst c-primitive-type-prefix-kwds
1817 "Keywords that might act as prefixes for primitive types. Assumed to
1818 be a subset of `c-primitive-type-kwds'."
1819 t nil
1820 (c c++) '("long" "short" "signed" "unsigned")
1821 idl '("long" "unsigned"
1822 ;; In CORBA PSDL:
1823 "strong"))
1825 (c-lang-defconst c-typedef-kwds
1826 "Prefix keyword(s) like \"typedef\" which make a type declaration out
1827 of a variable declaration."
1828 t '("typedef")
1829 (awk idl java) nil)
1831 (c-lang-defconst c-typedef-key
1832 ;; Adorned regexp matching `c-typedef-kwds'.
1833 t (c-make-keywords-re t (c-lang-const c-typedef-kwds)))
1834 (c-lang-defvar c-typedef-key (c-lang-const c-typedef-key))
1836 (c-lang-defconst c-typeof-kwds
1837 "Keywords followed by a parenthesized expression, which stands for
1838 the type of that expression."
1839 t nil
1840 c '("typeof") ; longstanding GNU C(++) extension.
1841 c++ '("decltype" "typeof"))
1843 (c-lang-defconst c-typeof-key
1844 ;; Adorned regexp matching `c-typeof-kwds'.
1845 t (c-make-keywords-re t (c-lang-const c-typeof-kwds)))
1846 (c-lang-defvar c-typeof-key (c-lang-const c-typeof-key))
1848 (c-lang-defconst c-type-prefix-kwds
1849 "Keywords where the following name - if any - is a type name, and
1850 where the keyword together with the symbol works as a type in
1851 declarations.
1853 Note that an alternative if the second part doesn't hold is
1854 `c-type-list-kwds'. Keywords on this list are typically also present
1855 on one of the `*-decl-kwds' lists."
1856 t nil
1857 c '("struct" "union" "enum")
1858 c++ (append '("class" "typename")
1859 (c-lang-const c-type-prefix-kwds c)))
1861 (c-lang-defconst c-type-prefix-key
1862 ;; Adorned regexp matching `c-type-prefix-kwds'.
1863 t (c-make-keywords-re t (c-lang-const c-type-prefix-kwds)))
1864 (c-lang-defvar c-type-prefix-key (c-lang-const c-type-prefix-key))
1866 (c-lang-defconst c-type-modifier-kwds
1867 "Type modifier keywords. These can occur almost anywhere in types
1868 but they don't build a type of themselves. Unlike the keywords on
1869 `c-primitive-type-kwds', they are fontified with the keyword face and
1870 not the type face."
1871 t nil
1872 c '("const" "restrict" "volatile")
1873 c++ '("const" "noexcept" "volatile" "throw")
1874 objc '("const" "volatile"))
1876 (c-lang-defconst c-opt-type-modifier-key
1877 ;; Adorned regexp matching `c-type-modifier-kwds', or nil in
1878 ;; languages without such keywords.
1879 t (and (c-lang-const c-type-modifier-kwds)
1880 (c-make-keywords-re t (c-lang-const c-type-modifier-kwds))))
1881 (c-lang-defvar c-opt-type-modifier-key (c-lang-const c-opt-type-modifier-key))
1883 (c-lang-defconst c-opt-type-component-key
1884 ;; An adorned regexp that matches `c-primitive-type-prefix-kwds' and
1885 ;; `c-type-modifier-kwds', or nil in languages without any of them.
1886 t (and (or (c-lang-const c-primitive-type-prefix-kwds)
1887 (c-lang-const c-type-modifier-kwds))
1888 (c-make-keywords-re t
1889 (append (c-lang-const c-primitive-type-prefix-kwds)
1890 (c-lang-const c-type-modifier-kwds)))))
1891 (c-lang-defvar c-opt-type-component-key
1892 (c-lang-const c-opt-type-component-key))
1894 (c-lang-defconst c-type-start-kwds
1895 ;; All keywords that can start a type (i.e. are either a type prefix
1896 ;; or a complete type).
1897 t (c--delete-duplicates (append (c-lang-const c-primitive-type-kwds)
1898 (c-lang-const c-type-prefix-kwds)
1899 (c-lang-const c-type-modifier-kwds))
1900 :test 'string-equal))
1902 (c-lang-defconst c-type-decl-suffix-ws-ids-kwds
1903 "\"Identifiers\" that when immediately following a declarator have semantic
1904 effect in the declaration, but are syntactically like whitespace."
1905 t nil
1906 c++ '("final" "override"))
1908 (c-lang-defconst c-type-decl-suffix-ws-ids-key
1909 ;; An adorned regexp matching `c-type-decl-suffix-ws-ids-kwds'.
1910 t (c-make-keywords-re t (c-lang-const c-type-decl-suffix-ws-ids-kwds)))
1911 (c-lang-defvar c-type-decl-suffix-ws-ids-key
1912 (c-lang-const c-type-decl-suffix-ws-ids-key))
1914 (c-lang-defconst c-class-decl-kwds
1915 "Keywords introducing declarations where the following block (if any)
1916 contains another declaration level that should be considered a class.
1918 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1919 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1920 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1921 will be handled.
1923 Note that presence on this list does not automatically treat the
1924 following identifier as a type; the keyword must also be present on
1925 `c-type-prefix-kwds' or `c-type-list-kwds' to accomplish that."
1926 t nil
1927 c '("struct" "union")
1928 c++ '("class" "struct" "union")
1929 objc '("struct" "union"
1930 "@interface" "@implementation" "@protocol")
1931 java '("class" "@interface" "interface")
1932 idl '("component" "eventtype" "exception" "home" "interface" "struct"
1933 "union" "valuetype"
1934 ;; In CORBA PSDL:
1935 "storagehome" "storagetype"
1936 ;; In CORBA CIDL:
1937 "catalog" "executor" "manages" "segment")
1938 pike '("class"))
1940 (c-lang-defconst c-class-key
1941 ;; Regexp matching the start of a class.
1942 t (c-make-keywords-re t (c-lang-const c-class-decl-kwds)))
1943 (c-lang-defvar c-class-key (c-lang-const c-class-key))
1945 (c-lang-defconst c-brace-list-decl-kwds
1946 "Keywords introducing declarations where the following block (if
1947 any) is a brace list.
1949 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1950 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1951 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1952 will be handled."
1953 t '("enum")
1954 (awk) nil)
1956 (c-lang-defconst c-brace-list-key
1957 ;; Regexp matching the start of declarations where the following
1958 ;; block is a brace list.
1959 t (c-make-keywords-re t (c-lang-const c-brace-list-decl-kwds)))
1960 (c-lang-defvar c-brace-list-key (c-lang-const c-brace-list-key))
1962 (c-lang-defconst c-after-brace-list-decl-kwds
1963 "Keywords that might follow keywords in `c-brace-list-decl-kwds'
1964 and precede the opening brace."
1965 t nil
1966 c++ '("class" "struct"))
1968 (c-lang-defconst c-after-brace-list-key
1969 ;; Regexp matching keywords that can fall between a brace-list
1970 ;; keyword and the associated brace list.
1971 t (c-make-keywords-re t (c-lang-const c-after-brace-list-decl-kwds)))
1972 (c-lang-defvar c-after-brace-list-key (c-lang-const c-after-brace-list-key))
1974 (c-lang-defconst c-recognize-post-brace-list-type-p
1975 "Set to t when we recognize a colon and then a type after an enum,
1976 e.g., enum foo : int { A, B, C };"
1977 t nil
1978 c++ t)
1979 (c-lang-defvar c-recognize-post-brace-list-type-p
1980 (c-lang-const c-recognize-post-brace-list-type-p))
1982 (c-lang-defconst c-other-block-decl-kwds
1983 "Keywords where the following block (if any) contains another
1984 declaration level that should not be considered a class. For every
1985 keyword here, CC Mode will add a set of special syntactic symbols for
1986 those blocks. E.g. if the keyword is \"foo\" then there will be
1987 `foo-open', `foo-close', and `infoo' symbols.
1989 The intention is that this category should be used for block
1990 constructs that aren't related to object orientation concepts like
1991 classes (which thus also include e.g. interfaces, templates,
1992 contracts, structs, etc). The more pragmatic distinction is that
1993 while most want some indentation inside classes, it's fairly common
1994 that they don't want it in some of these constructs, so it should be
1995 simple to configure that differently from classes. See also
1996 `c-class-decl-kwds'.
1998 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1999 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
2000 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
2001 will be handled."
2002 t nil
2003 (c objc) '("extern")
2004 c++ '("namespace" "extern")
2005 idl '("module"
2006 ;; In CORBA CIDL:
2007 "composition"))
2009 (c-lang-defconst c-other-decl-block-key
2010 ;; Regexp matching the start of blocks besides classes that contain
2011 ;; another declaration level.
2012 t (c-make-keywords-re t (c-lang-const c-other-block-decl-kwds)))
2013 (c-lang-defvar c-other-decl-block-key (c-lang-const c-other-decl-block-key))
2015 (c-lang-defvar c-other-decl-block-key-in-symbols-alist
2016 (mapcar
2017 (lambda (elt)
2018 (cons elt
2019 (if (string= elt "extern")
2020 'inextern-lang
2021 (intern (concat "in" elt)))))
2022 (c-lang-const c-other-block-decl-kwds))
2023 "Alist associating keywords in c-other-decl-block-decl-kwds with
2024 their matching \"in\" syntactic symbols.")
2026 (c-lang-defconst c-typedef-decl-kwds
2027 "Keywords introducing declarations where the identifier(s) being
2028 declared are types.
2030 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
2031 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
2032 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
2033 will be handled."
2034 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
2035 ;; (since e.g. "Foo" is a type that's being defined in "class Foo
2036 ;; {...}").
2037 t (append (c-lang-const c-class-decl-kwds)
2038 (c-lang-const c-brace-list-decl-kwds))
2039 ;; Languages that have a "typedef" construct.
2040 (c c++ objc idl pike) (append (c-lang-const c-typedef-decl-kwds)
2041 '("typedef"))
2042 ;; Unlike most other languages, exception names are not handled as
2043 ;; types in IDL since they only can occur in "raises" specs.
2044 idl (delete "exception" (append (c-lang-const c-typedef-decl-kwds) nil)))
2046 (c-lang-defconst c-typedef-decl-key
2047 t (c-make-keywords-re t (c-lang-const c-typedef-decl-kwds)))
2048 (c-lang-defvar c-typedef-decl-key (c-lang-const c-typedef-decl-key))
2050 (c-lang-defconst c-typeless-decl-kwds
2051 "Keywords introducing declarations where the \(first) identifier
2052 \(declarator) follows directly after the keyword, without any type.
2054 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
2055 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
2056 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
2057 will be handled."
2058 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
2059 ;; (since e.g. "Foo" is the identifier being defined in "class Foo
2060 ;; {...}").
2061 t (append (c-lang-const c-class-decl-kwds)
2062 (c-lang-const c-brace-list-decl-kwds))
2063 c++ (append (c-lang-const c-typeless-decl-kwds) '("auto")) ; C++11.
2064 ;; Note: "manages" for CORBA CIDL clashes with its presence on
2065 ;; `c-type-list-kwds' for IDL.
2066 idl (append (c-lang-const c-typeless-decl-kwds)
2067 '("factory" "finder" "native"
2068 ;; In CORBA PSDL:
2069 "key" "stores"
2070 ;; In CORBA CIDL:
2071 "facet"))
2072 pike (append (c-lang-const c-class-decl-kwds)
2073 '("constant")))
2075 (c-lang-defconst c-modifier-kwds
2076 "Keywords that can prefix normal declarations of identifiers
2077 \(and typically act as flags). Things like argument declarations
2078 inside function headers are also considered declarations in this
2079 sense.
2081 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
2082 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
2083 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
2084 will be handled."
2085 t nil
2086 (c c++) '("auto" "extern" "inline" "register" "static")
2087 c++ (append '("constexpr" "explicit" "friend" "mutable" "template"
2088 "thread_local" "using" "virtual")
2089 (c-lang-const c-modifier-kwds))
2090 objc '("auto" "bycopy" "byref" "extern" "in" "inout" "oneway" "out" "static")
2091 ;; FIXME: Some of those below ought to be on `c-other-decl-kwds' instead.
2092 idl '("abstract" "attribute" "const" "consumes" "custom" "emits" "import"
2093 "in" "inout" "local" "multiple" "oneway" "out" "private" "provides"
2094 "public" "publishes" "readonly" "typeid" "typeprefix" "uses"
2095 ;; In CORBA PSDL:
2096 "primary" "state"
2097 ;; In CORBA CIDL:
2098 "bindsTo" "delegatesTo" "implements" "proxy" "storedOn")
2099 ;; Note: "const" is not used in Java, but it's still a reserved keyword.
2100 java '("abstract" "const" "default" "final" "native" "private" "protected"
2101 "public" "static" "strictfp" "synchronized" "transient" "volatile")
2102 pike '("final" "inline" "local" "nomask" "optional" "private" "protected"
2103 "public" "static" "variant"))
2105 (c-lang-defconst c-other-decl-kwds
2106 "Keywords that can start or prefix any declaration level construct,
2107 besides those on `c-class-decl-kwds', `c-brace-list-decl-kwds',
2108 `c-other-block-decl-kwds', `c-typedef-decl-kwds',
2109 `c-typeless-decl-kwds' and `c-modifier-kwds'.
2111 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
2112 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
2113 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
2114 will be handled."
2115 t nil
2116 objc '("@class" "@end" "@defs")
2117 java '("import" "package")
2118 pike '("import" "inherit"))
2120 (c-lang-defconst c-decl-start-kwds
2121 "Keywords that always start declarations, wherever they occur.
2122 This can be used for declarations that aren't recognized by the normal
2123 combination of `c-decl-prefix-re' and `c-decl-start-re'."
2124 t nil
2125 ;; Classes can be declared anywhere in a Pike expression.
2126 pike '("class"))
2128 (c-lang-defconst c-decl-hangon-kwds
2129 "Keywords that can occur anywhere in a declaration level construct.
2130 This is used for self-contained things that can be tacked on anywhere
2131 on a declaration and that should be ignored to be able to recognize it
2132 correctly. Typical cases are compiler extensions like
2133 \"__attribute__\" or \"__declspec\":
2135 __declspec(noreturn) void foo();
2136 class __declspec(dllexport) classname {...};
2137 void foo() __attribute__((noreturn));
2139 Note that unrecognized plain symbols are skipped anyway if they occur
2140 before the type, so such things are not necessary to mention here.
2141 Mentioning them here is necessary only if they can occur in other
2142 places, or if they are followed by a construct that must be skipped
2143 over \(like the parens in the \"__attribute__\" and \"__declspec\"
2144 examples above). In the last case, they alse need to be present on
2145 one of `c-type-list-kwds', `c-ref-list-kwds',
2146 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
2147 `c-<>-type-kwds', or `c-<>-arglist-kwds'."
2148 ;; NB: These are currently not recognized in all parts of a
2149 ;; declaration. Specifically, they aren't recognized in the middle
2150 ;; of multi-token types, inside declarators, and between the
2151 ;; identifier and the arglist paren of a function declaration.
2153 ;; FIXME: This ought to be user customizable since compiler stuff
2154 ;; like this usually is wrapped in project specific macros. (It'd
2155 ;; of course be even better if we could cope without knowing this.)
2156 t nil
2157 (c c++) '(;; GCC extension.
2158 "__attribute__"
2159 ;; MSVC extension.
2160 "__declspec"))
2162 (c-lang-defconst c-decl-hangon-key
2163 ;; Adorned regexp matching `c-decl-hangon-kwds'.
2164 t (c-make-keywords-re t (c-lang-const c-decl-hangon-kwds)))
2165 (c-lang-defvar c-decl-hangon-key (c-lang-const c-decl-hangon-key))
2167 (c-lang-defconst c-prefix-spec-kwds
2168 ;; All keywords that can occur in the preamble of a declaration.
2169 ;; They typically occur before the type, but they are also matched
2170 ;; after presumptive types since we often can't be sure that
2171 ;; something is a type or just some sort of macro in front of the
2172 ;; declaration. They might be ambiguous with types or type
2173 ;; prefixes.
2174 t (c--delete-duplicates (append (c-lang-const c-class-decl-kwds)
2175 (c-lang-const c-brace-list-decl-kwds)
2176 (c-lang-const c-other-block-decl-kwds)
2177 (c-lang-const c-typedef-decl-kwds)
2178 (c-lang-const c-typeless-decl-kwds)
2179 (c-lang-const c-modifier-kwds)
2180 (c-lang-const c-other-decl-kwds)
2181 (c-lang-const c-decl-start-kwds)
2182 (c-lang-const c-decl-hangon-kwds))
2183 :test 'string-equal))
2185 (c-lang-defconst c-prefix-spec-kwds-re
2186 ;; Adorned regexp of `c-prefix-spec-kwds'.
2187 t (c-make-keywords-re t (c-lang-const c-prefix-spec-kwds)))
2189 (c-lang-defvar c-prefix-spec-kwds-re (c-lang-const c-prefix-spec-kwds-re))
2191 (c-lang-defconst c-specifier-key
2192 ;; Adorned regexp of the keywords in `c-prefix-spec-kwds' that aren't
2193 ;; ambiguous with types or type prefixes. These are the keywords (like
2194 ;; extern, namespace, but NOT template) that can modify a declaration.
2195 t (c-make-keywords-re t
2196 (c--set-difference (c-lang-const c-prefix-spec-kwds)
2197 (append (c-lang-const c-type-start-kwds)
2198 (c-lang-const c-<>-arglist-kwds))
2199 :test 'string-equal)))
2200 (c-lang-defvar c-specifier-key (c-lang-const c-specifier-key))
2202 (c-lang-defconst c-postfix-spec-kwds
2203 ;; Keywords that can occur after argument list of a function header
2204 ;; declaration, i.e. in the "K&R region".
2205 t (append (c-lang-const c-postfix-decl-spec-kwds)
2206 (c-lang-const c-decl-hangon-kwds)))
2208 (c-lang-defconst c-not-decl-init-keywords
2209 ;; Adorned regexp matching all keywords that can't appear at the
2210 ;; start of a declaration.
2211 t (c-make-keywords-re t
2212 (c--set-difference (c-lang-const c-keywords)
2213 (append (c-lang-const c-type-start-kwds)
2214 (c-lang-const c-prefix-spec-kwds)
2215 (c-lang-const c-typeof-kwds))
2216 :test 'string-equal)))
2217 (c-lang-defvar c-not-decl-init-keywords
2218 (c-lang-const c-not-decl-init-keywords))
2220 (c-lang-defconst c-not-primitive-type-keywords
2221 "List of all keywords apart from primitive types (like \"int\")."
2222 t (c--set-difference (c-lang-const c-keywords)
2223 (c-lang-const c-primitive-type-kwds)
2224 :test 'string-equal)
2225 ;; The "more" for C++ is the QT keyword (as in "more slots:").
2226 ;; This variable is intended for use in c-beginning-of-statement-1.
2227 c++ (append (c-lang-const c-not-primitive-type-keywords) '("more")))
2229 (c-lang-defconst c-not-primitive-type-keywords-regexp
2230 t (c-make-keywords-re t
2231 (c-lang-const c-not-primitive-type-keywords)))
2232 (c-lang-defvar c-not-primitive-type-keywords-regexp
2233 (c-lang-const c-not-primitive-type-keywords-regexp))
2235 (c-lang-defconst c-protection-kwds
2236 "Access protection label keywords in classes."
2237 t nil
2238 c++ '("private" "protected" "public")
2239 objc '("@private" "@protected" "@public"))
2241 (c-lang-defconst c-block-decls-with-vars
2242 "Keywords introducing declarations that can contain a block which
2243 might be followed by variable declarations, e.g. like \"foo\" in
2244 \"class Foo { ... } foo;\". So if there is a block in a declaration
2245 like that, it ends with the following `;' and not right away.
2247 The keywords on list are assumed to also be present on one of the
2248 `*-decl-kwds' lists."
2249 t nil
2250 (c objc) '("struct" "union" "enum" "typedef")
2251 c++ '("class" "struct" "union" "enum" "typedef"))
2253 (c-lang-defconst c-opt-block-decls-with-vars-key
2254 ;; Regexp matching the `c-block-decls-with-vars' keywords, or nil in
2255 ;; languages without such constructs.
2256 t (and (c-lang-const c-block-decls-with-vars)
2257 (c-make-keywords-re t (c-lang-const c-block-decls-with-vars))))
2258 (c-lang-defvar c-opt-block-decls-with-vars-key
2259 (c-lang-const c-opt-block-decls-with-vars-key))
2261 (c-lang-defconst c-postfix-decl-spec-kwds
2262 "Keywords introducing extra declaration specifiers in the region
2263 between the header and the body \(i.e. the \"K&R-region\") in
2264 declarations."
2265 t nil
2266 java '("extends" "implements" "throws")
2267 idl '("context" "getraises" "manages" "primarykey" "raises" "setraises"
2268 "supports"
2269 ;; In CORBA PSDL:
2270 "as" "const" "implements" "of" "ref"))
2272 (c-lang-defconst c-postfix-decl-spec-key
2273 ;; Regexp matching the keywords in `c-postfix-decl-spec-kwds'.
2274 t (c-make-keywords-re t (c-lang-const c-postfix-decl-spec-kwds)))
2275 (c-lang-defvar c-postfix-decl-spec-key
2276 (c-lang-const c-postfix-decl-spec-key))
2278 (c-lang-defconst c-nonsymbol-sexp-kwds
2279 "Keywords that may be followed by a nonsymbol sexp before whatever
2280 construct it's part of continues."
2281 t nil
2282 (c c++ objc) '("extern"))
2284 (c-lang-defconst c-type-list-kwds
2285 "Keywords that may be followed by a comma separated list of type
2286 identifiers, where each optionally can be prefixed by keywords. (Can
2287 also be used for the special case when the list can contain only one
2288 element.)
2290 Assumed to be mutually exclusive with `c-ref-list-kwds'. There's no
2291 reason to put keywords on this list if they are on `c-type-prefix-kwds'.
2292 There's also no reason to add keywords that prefixes a normal
2293 declaration consisting of a type followed by a declarator (list), so
2294 the keywords on `c-modifier-kwds' should normally not be listed here
2295 either.
2297 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
2298 or variable identifier (that's being defined)."
2299 t nil
2300 c++ '("operator")
2301 objc '("@class")
2302 java '("import" "new" "extends" "super" "implements" "throws")
2303 idl '("manages" "native" "primarykey" "supports"
2304 ;; In CORBA PSDL:
2305 "as" "implements" "of" "scope")
2306 pike '("inherit"))
2308 (c-lang-defconst c-ref-list-kwds
2309 "Keywords that may be followed by a comma separated list of
2310 reference (i.e. namespace/scope/module) identifiers, where each
2311 optionally can be prefixed by keywords. (Can also be used for the
2312 special case when the list can contain only one element.) Assumed to
2313 be mutually exclusive with `c-type-list-kwds'.
2315 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
2316 or variable identifier (that's being defined)."
2317 t nil
2318 c++ '("namespace")
2319 java '("package")
2320 idl '("import" "module"
2321 ;; In CORBA CIDL:
2322 "composition")
2323 pike '("import"))
2325 (c-lang-defconst c-colon-type-list-kwds
2326 "Keywords that may be followed (not necessarily directly) by a colon
2327 and then a comma separated list of type identifiers, where each
2328 optionally can be prefixed by keywords. (Can also be used for the
2329 special case when the list can contain only one element.)"
2330 t nil
2331 c++ '("class" "struct")
2332 idl '("component" "eventtype" "home" "interface" "valuetype"
2333 ;; In CORBA PSDL:
2334 "storagehome" "storagetype"))
2336 (c-lang-defconst c-colon-type-list-re
2337 "Regexp matched after the keywords in `c-colon-type-list-kwds' to skip
2338 forward to the colon. The end of the match is assumed to be directly
2339 after the colon, so the regexp should end with \":\". Must be a
2340 regexp if `c-colon-type-list-kwds' isn't nil."
2341 t (if (c-lang-const c-colon-type-list-kwds)
2342 ;; Disallow various common punctuation chars that can't come
2343 ;; before the ":" that starts the inherit list after "class"
2344 ;; or "struct" in C++. (Also used as default for other
2345 ;; languages.)
2346 "[^][{}();,/#=:]*:"))
2347 (c-lang-defvar c-colon-type-list-re (c-lang-const c-colon-type-list-re))
2349 (c-lang-defconst c-paren-nontype-kwds
2350 "Keywords that may be followed by a parenthesis expression that doesn't
2351 contain type identifiers."
2352 t nil
2353 (c c++) '(;; GCC extension.
2354 "__attribute__"
2355 ;; MSVC extension.
2356 "__declspec")
2357 c++ (append (c-lang-const c-paren-nontype-kwds) '("noexcept")))
2359 (c-lang-defconst c-paren-nontype-key
2360 t (c-make-keywords-re t (c-lang-const c-paren-nontype-kwds)))
2361 (c-lang-defvar c-paren-nontype-key (c-lang-const c-paren-nontype-key))
2363 (c-lang-defconst c-paren-type-kwds
2364 "Keywords that may be followed by a parenthesis expression containing
2365 type identifiers separated by arbitrary tokens."
2366 t nil
2367 c++ '("throw")
2368 objc '("@defs")
2369 idl '("switch")
2370 pike '("array" "function" "int" "mapping" "multiset" "object" "program"))
2372 (c-lang-defconst c-paren-any-kwds
2373 t (c--delete-duplicates (append (c-lang-const c-paren-nontype-kwds)
2374 (c-lang-const c-paren-type-kwds))
2375 :test 'string-equal))
2377 (c-lang-defconst c-<>-type-kwds
2378 "Keywords that may be followed by an angle bracket expression
2379 containing type identifiers separated by \",\". The difference from
2380 `c-<>-arglist-kwds' is that unknown names are taken to be types and
2381 not other identifiers. `c-recognize-<>-arglists' is assumed to be set
2382 if this isn't nil."
2383 t nil
2384 objc '("id")
2385 idl '("sequence"
2386 ;; In CORBA PSDL:
2387 "ref"))
2389 (c-lang-defconst c-<>-arglist-kwds
2390 "Keywords that can be followed by a C++ style template arglist; see
2391 `c-recognize-<>-arglists' for details. That language constant is
2392 assumed to be set if this isn't nil."
2393 t nil
2394 c++ '("template")
2395 idl '("fixed" "string" "wstring"))
2397 (c-lang-defconst c-<>-sexp-kwds
2398 ;; All keywords that can be followed by an angle bracket sexp.
2399 t (c--delete-duplicates (append (c-lang-const c-<>-type-kwds)
2400 (c-lang-const c-<>-arglist-kwds))
2401 :test 'string-equal))
2403 (c-lang-defconst c-opt-<>-sexp-key
2404 ;; Adorned regexp matching keywords that can be followed by an angle
2405 ;; bracket sexp. Always set when `c-recognize-<>-arglists' is.
2406 t (c-make-keywords-re t (c-lang-const c-<>-sexp-kwds)))
2407 (c-lang-defvar c-opt-<>-sexp-key (c-lang-const c-opt-<>-sexp-key))
2409 (c-lang-defconst c-inside-<>-type-kwds
2410 "Keywords which, used inside a C++ style template arglist, introduce a type."
2411 t nil
2412 java '("extends" "super"))
2414 (c-lang-defconst c-inside-<>-type-key
2415 t (c-make-keywords-re t (c-lang-const c-inside-<>-type-kwds)))
2416 (c-lang-defvar c-inside-<>-type-key (c-lang-const c-inside-<>-type-key))
2418 (c-lang-defconst c-brace-id-list-kwds
2419 "Keywords that may be followed by a brace block containing a comma
2420 separated list of identifier definitions, i.e. like the list of
2421 identifiers that follows the type in a normal declaration."
2422 t (c-lang-const c-brace-list-decl-kwds))
2424 (c-lang-defconst c-block-stmt-1-kwds
2425 "Statement keywords followed directly by a substatement."
2426 t '("do" "else")
2427 c++ '("do" "else" "try")
2428 objc '("do" "else" "@finally" "@try")
2429 java '("do" "else" "finally" "try")
2430 idl nil)
2432 (c-lang-defconst c-block-stmt-1-key
2433 ;; Regexp matching the start of any statement followed directly by a
2434 ;; substatement (doesn't match a bare block, however).
2435 t (c-make-keywords-re t (c-lang-const c-block-stmt-1-kwds)))
2436 (c-lang-defvar c-block-stmt-1-key (c-lang-const c-block-stmt-1-key))
2438 (c-lang-defconst c-block-stmt-1-2-kwds
2439 "Statement keywords optionally followed by a paren sexp.
2440 Keywords here should also be in `c-block-stmt-1-kwds'."
2441 t nil
2442 java '("try"))
2444 (c-lang-defconst c-block-stmt-1-2-key
2445 ;; Regexp matching the start of a statement which may be followed by a
2446 ;; paren sexp and will then be followed by a substatement.
2447 t (c-make-keywords-re t (c-lang-const c-block-stmt-1-2-kwds)))
2448 (c-lang-defvar c-block-stmt-1-2-key (c-lang-const c-block-stmt-1-2-key))
2450 (c-lang-defconst c-block-stmt-2-kwds
2451 "Statement keywords followed by a paren sexp and then by a substatement."
2452 t '("for" "if" "switch" "while")
2453 c++ '("for" "if" "switch" "while" "catch")
2454 objc '("for" "if" "switch" "while" "@catch" "@synchronized")
2455 java '("for" "if" "switch" "while" "catch" "synchronized")
2456 idl nil
2457 pike '("for" "if" "switch" "while" "foreach")
2458 awk '("for" "if" "while"))
2460 (c-lang-defconst c-block-stmt-2-key
2461 ;; Regexp matching the start of any statement followed by a paren sexp
2462 ;; and then by a substatement.
2463 t (c-make-keywords-re t (c-lang-const c-block-stmt-2-kwds)))
2464 (c-lang-defvar c-block-stmt-2-key (c-lang-const c-block-stmt-2-key))
2466 (c-lang-defconst c-block-stmt-kwds
2467 ;; Union of `c-block-stmt-1-kwds' and `c-block-stmt-2-kwds'.
2468 t (c--delete-duplicates (append (c-lang-const c-block-stmt-1-kwds)
2469 (c-lang-const c-block-stmt-2-kwds))
2470 :test 'string-equal))
2472 (c-lang-defconst c-opt-block-stmt-key
2473 ;; Regexp matching the start of any statement that has a
2474 ;; substatement (except a bare block). Nil in languages that
2475 ;; don't have such constructs.
2476 t (if (or (c-lang-const c-block-stmt-1-kwds)
2477 (c-lang-const c-block-stmt-2-kwds))
2478 (c-make-keywords-re t
2479 (append (c-lang-const c-block-stmt-1-kwds)
2480 (c-lang-const c-block-stmt-2-kwds)))))
2481 (c-lang-defvar c-opt-block-stmt-key (c-lang-const c-opt-block-stmt-key))
2483 (c-lang-defconst c-simple-stmt-kwds
2484 "Statement keywords followed by an expression or nothing."
2485 t '("break" "continue" "goto" "return")
2486 objc '("break" "continue" "goto" "return" "@throw")
2487 ;; Note: `goto' is not valid in Java, but the keyword is still reserved.
2488 java '("break" "continue" "goto" "return" "throw")
2489 idl nil
2490 pike '("break" "continue" "return")
2491 awk '(;; Not sure about "delete", "exit", "getline", etc. ; ACM 2002/5/30
2492 "break" "continue" "return" "delete" "exit" "getline" "next"
2493 "nextfile" "print" "printf"))
2495 (c-lang-defconst c-simple-stmt-key
2496 ;; Adorned regexp matching `c-simple-stmt-kwds'.
2497 t (c-make-keywords-re t (c-lang-const c-simple-stmt-kwds)))
2498 (c-lang-defvar c-simple-stmt-key (c-lang-const c-simple-stmt-key))
2500 (c-lang-defconst c-paren-stmt-kwds
2501 "Statement keywords followed by a parenthesis expression that
2502 nevertheless contains a list separated with `;' and not `,'."
2503 t '("for")
2504 idl nil)
2506 (c-lang-defconst c-paren-stmt-key
2507 ;; Adorned regexp matching `c-paren-stmt-kwds'.
2508 t (c-make-keywords-re t (c-lang-const c-paren-stmt-kwds)))
2509 (c-lang-defvar c-paren-stmt-key (c-lang-const c-paren-stmt-key))
2511 (c-lang-defconst c-asm-stmt-kwds
2512 "Statement keywords followed by an assembler expression."
2513 t nil
2514 (c c++) '("asm" "__asm__")) ;; Not standard, but common.
2516 (c-lang-defconst c-opt-asm-stmt-key
2517 ;; Regexp matching the start of an assembler statement. Nil in
2518 ;; languages that don't support that.
2519 t (if (c-lang-const c-asm-stmt-kwds)
2520 (c-make-keywords-re t (c-lang-const c-asm-stmt-kwds))))
2521 (c-lang-defvar c-opt-asm-stmt-key (c-lang-const c-opt-asm-stmt-key))
2523 (c-lang-defconst c-case-kwds
2524 "The keyword(s) which introduce a \"case\" like construct.
2525 This construct is \"<keyword> <expression> :\"."
2526 t '("case")
2527 awk nil)
2529 (c-lang-defconst c-case-kwds-regexp
2530 ;; Adorned regexp matching any "case"-like keyword.
2531 t (c-make-keywords-re t (c-lang-const c-case-kwds)))
2532 (c-lang-defvar c-case-kwds-regexp (c-lang-const c-case-kwds-regexp))
2534 (c-lang-defconst c-label-kwds
2535 "Keywords introducing colon terminated labels in blocks."
2536 t '("case" "default"))
2538 (c-lang-defconst c-label-kwds-regexp
2539 ;; Adorned regexp matching any keyword that introduces a label.
2540 t (c-make-keywords-re t (c-lang-const c-label-kwds)))
2541 (c-lang-defvar c-label-kwds-regexp (c-lang-const c-label-kwds-regexp))
2543 (c-lang-defconst c-before-label-kwds
2544 "Keywords that might be followed by a label identifier."
2545 t '("goto")
2546 (java pike) (append '("break" "continue")
2547 (c-lang-const c-before-label-kwds))
2548 idl nil
2549 awk nil)
2551 (c-lang-defconst c-constant-kwds
2552 "Keywords for constants."
2553 t nil
2554 c '("NULL" ;; Not a keyword, but practically works as one.
2555 "false" "true") ; Defined in C99.
2556 c++ (append
2557 '("nullptr")
2558 (c-lang-const c-constant-kwds c))
2559 objc '("nil" "Nil" "YES" "NO" "NS_DURING" "NS_HANDLER" "NS_ENDHANDLER")
2560 idl '("TRUE" "FALSE")
2561 java '("true" "false" "null") ; technically "literals", not keywords
2562 pike '("UNDEFINED")) ;; Not a keyword, but practically works as one.
2564 (c-lang-defconst c-primary-expr-kwds
2565 "Keywords besides constants and operators that start primary expressions."
2566 t nil
2567 c++ '("operator" "this")
2568 objc '("super" "self")
2569 java '("this")
2570 pike '("this")) ;; Not really a keyword, but practically works as one.
2572 (c-lang-defconst c-expr-kwds
2573 ;; Keywords that can occur anywhere in expressions. Built from
2574 ;; `c-primary-expr-kwds' and all keyword operators in `c-operators'.
2575 t (c--delete-duplicates
2576 (append (c-lang-const c-primary-expr-kwds)
2577 (c-filter-ops (c-lang-const c-operator-list)
2579 "\\`\\(\\w\\|\\s_\\)+\\'"))
2580 :test 'string-equal))
2582 (c-lang-defconst c-lambda-kwds
2583 "Keywords that start lambda constructs, i.e. function definitions in
2584 expressions."
2585 t nil
2586 pike '("lambda"))
2588 (c-lang-defconst c-inexpr-block-kwds
2589 "Keywords that start constructs followed by statement blocks which can
2590 be used in expressions \(the gcc extension for this in C and C++ is
2591 handled separately by `c-recognize-paren-inexpr-blocks')."
2592 t nil
2593 pike '("catch" "gauge"))
2595 (c-lang-defconst c-inexpr-class-kwds
2596 "Keywords that can start classes inside expressions."
2597 t nil
2598 java '("new")
2599 pike '("class"))
2601 (c-lang-defconst c-inexpr-brace-list-kwds
2602 "Keywords that can start brace list blocks inside expressions.
2603 Note that Java specific rules are currently applied to tell this from
2604 `c-inexpr-class-kwds'."
2605 t nil
2606 java '("new"))
2608 (c-lang-defconst c-opt-inexpr-brace-list-key
2609 ;; Regexp matching the start of a brace list in an expression, or
2610 ;; nil in languages that don't have such things. This should not
2611 ;; match brace lists recognized through `c-special-brace-lists'.
2612 t (and (c-lang-const c-inexpr-brace-list-kwds)
2613 (c-make-keywords-re t (c-lang-const c-inexpr-brace-list-kwds))))
2614 (c-lang-defvar c-opt-inexpr-brace-list-key
2615 (c-lang-const c-opt-inexpr-brace-list-key))
2617 (c-lang-defconst c-flat-decl-block-kwds
2618 ;; Keywords that can introduce another declaration level, i.e. where a
2619 ;; following "{" isn't a function block or brace list. Note that, for
2620 ;; historical reasons, `c-decl-block-key' is NOT constructed from this lang
2621 ;; const.
2622 t (c--delete-duplicates
2623 (append (c-lang-const c-class-decl-kwds)
2624 (c-lang-const c-other-block-decl-kwds)
2625 (c-lang-const c-inexpr-class-kwds))
2626 :test 'string-equal))
2628 (c-lang-defconst c-brace-stack-thing-key
2629 ;; Regexp matching any keyword or operator relevant to the brace stack (see
2630 ;; `c-update-brace-stack' in cc-engine.el).
2631 t (c-make-keywords-re 'appendable
2632 (append
2633 (c-lang-const c-flat-decl-block-kwds)
2634 (if (c-lang-const c-recognize-<>-arglists)
2635 '("{" "}" ";" "," ")" ":" "<")
2636 '("{" "}" ";" "," ")" ":")))))
2637 (c-lang-defvar c-brace-stack-thing-key (c-lang-const c-brace-stack-thing-key))
2639 (c-lang-defconst c-brace-stack-no-semi-key
2640 ;; Regexp matching any keyword or operator relevant to the brace stack when
2641 ;; a semicolon is not relevant (see `c-update-brace-stack' in
2642 ;; cc-engine.el).
2643 t (c-make-keywords-re 'appendable
2644 (append
2645 (c-lang-const c-flat-decl-block-kwds)
2646 (if (c-lang-const c-recognize-<>-arglists)
2647 '("{" "}" "<")
2648 '("{" "}")))))
2649 (c-lang-defvar c-brace-stack-no-semi-key
2650 (c-lang-const c-brace-stack-no-semi-key))
2652 (c-lang-defconst c-decl-block-key
2653 ;; Regexp matching keywords in any construct that contain another
2654 ;; declaration level, i.e. that isn't followed by a function block
2655 ;; or brace list. When the first submatch matches, it's an
2656 ;; unambiguous construct, otherwise it's an ambiguous match that
2657 ;; might also be the return type of a function declaration.
2658 t (let* ((decl-kwds (append (c-lang-const c-class-decl-kwds)
2659 (c-lang-const c-other-block-decl-kwds)
2660 (c-lang-const c-inexpr-class-kwds)))
2661 (unambiguous (c--set-difference decl-kwds
2662 (c-lang-const c-type-start-kwds)
2663 :test 'string-equal))
2664 (ambiguous (c--intersection decl-kwds
2665 (c-lang-const c-type-start-kwds)
2666 :test 'string-equal)))
2667 (if ambiguous
2668 (concat (c-make-keywords-re t unambiguous)
2669 "\\|"
2670 (c-make-keywords-re t ambiguous))
2671 (c-make-keywords-re t unambiguous))))
2672 (c-lang-defvar c-decl-block-key (c-lang-const c-decl-block-key))
2674 (c-lang-defconst c-bitfield-kwds
2675 "Keywords that can introduce bitfields."
2676 t nil
2677 (c c++ objc) '("char" "int" "long" "signed" "unsigned"))
2679 (c-lang-defconst c-opt-bitfield-key
2680 ;; Regexp matching the start of a bitfield (not uniquely), or nil in
2681 ;; languages without bitfield support.
2682 t nil
2683 (c c++) (c-make-keywords-re t (c-lang-const c-bitfield-kwds)))
2684 (c-lang-defvar c-opt-bitfield-key (c-lang-const c-opt-bitfield-key))
2686 (c-lang-defconst c-other-kwds
2687 "Keywords not accounted for by any other `*-kwds' language constant."
2688 t nil
2689 idl '("truncatable"
2690 ;; In CORBA CIDL: (These are declaration keywords that never
2691 ;; can start a declaration.)
2692 "entity" "process" "service" "session" "storage"))
2695 ;;; Constants built from keywords.
2697 ;; Note: No `*-kwds' language constants may be defined below this point.
2699 (eval-and-compile
2700 (defconst c-kwds-lang-consts
2701 ;; List of all the language constants that contain keyword lists.
2702 (let (list)
2703 (mapatoms (lambda (sym)
2704 (when (and (boundp sym)
2705 (string-match "-kwds\\'" (symbol-name sym)))
2706 ;; Make the list of globally interned symbols
2707 ;; instead of ones interned in `c-lang-constants'.
2708 (setq list (cons (intern (symbol-name sym)) list))))
2709 c-lang-constants)
2710 list)))
2712 (c-lang-defconst c-keywords
2713 ;; All keywords as a list.
2714 t (c--delete-duplicates
2715 (c-lang-defconst-eval-immediately
2716 `(append ,@(mapcar (lambda (kwds-lang-const)
2717 `(c-lang-const ,kwds-lang-const))
2718 c-kwds-lang-consts)
2719 nil))
2720 :test 'string-equal))
2722 (c-lang-defconst c-keywords-regexp
2723 ;; All keywords as an adorned regexp.
2724 t (c-make-keywords-re t (c-lang-const c-keywords)))
2725 (c-lang-defvar c-keywords-regexp (c-lang-const c-keywords-regexp))
2727 (c-lang-defconst c-keyword-member-alist
2728 ;; An alist with all the keywords in the cars. The cdr for each
2729 ;; keyword is a list of the symbols for the `*-kwds' lists that
2730 ;; contains it.
2731 t (let ((kwd-list-alist
2732 (c-lang-defconst-eval-immediately
2733 `(list ,@(mapcar (lambda (kwds-lang-const)
2734 `(cons ',kwds-lang-const
2735 (c-lang-const ,kwds-lang-const)))
2736 c-kwds-lang-consts))))
2737 lang-const kwd-list kwd
2738 result-alist elem)
2739 (while kwd-list-alist
2740 (setq lang-const (caar kwd-list-alist)
2741 kwd-list (cdar kwd-list-alist)
2742 kwd-list-alist (cdr kwd-list-alist))
2743 (while kwd-list
2744 (setq kwd (car kwd-list)
2745 kwd-list (cdr kwd-list))
2746 (unless (setq elem (assoc kwd result-alist))
2747 (setq result-alist (cons (setq elem (list kwd)) result-alist)))
2748 (unless (memq lang-const (cdr elem))
2749 (setcdr elem (cons lang-const (cdr elem))))))
2750 result-alist))
2752 (c-lang-defvar c-keywords-obarray
2753 ;; An obarray containing all keywords as symbols. The property list
2754 ;; of each symbol has a non-nil entry for the specific `*-kwds'
2755 ;; lists it's a member of.
2757 ;; E.g. to see whether the string str contains a keyword on
2758 ;; `c-class-decl-kwds', one can do like this:
2759 ;; (get (intern-soft str c-keyword-obarray) 'c-class-decl-kwds)
2760 ;; Which preferably is written using the associated functions in
2761 ;; cc-engine:
2762 ;; (c-keyword-member (c-keyword-sym str) 'c-class-decl-kwds)
2764 ;; The obarray is not stored directly as a language constant since
2765 ;; the printed representation for obarrays used in .elc files isn't
2766 ;; complete.
2768 (let* ((alist (c-lang-const c-keyword-member-alist))
2769 kwd lang-const-list
2770 (obarray (make-vector (* (length alist) 2) 0)))
2771 (while alist
2772 (setq kwd (caar alist)
2773 lang-const-list (cdar alist)
2774 alist (cdr alist))
2775 (setplist (intern kwd obarray)
2776 ;; Emacs has an odd bug that causes `mapcan' to fail
2777 ;; with unintelligible errors. (XEmacs works.)
2778 ;; (2015-06-24): This bug has not yet been fixed.
2779 ;;(mapcan (lambda (lang-const)
2780 ;; (list lang-const t))
2781 ;; lang-const-list)
2782 (apply 'nconc (mapcar (lambda (lang-const)
2783 (list lang-const t))
2784 lang-const-list))))
2785 obarray))
2787 (c-lang-defconst c-regular-keywords-regexp
2788 ;; Adorned regexp matching all keywords that should be fontified
2789 ;; with the keywords face. I.e. that aren't types or constants.
2790 t (c-make-keywords-re t
2791 (c--set-difference (c-lang-const c-keywords)
2792 (append (c-lang-const c-primitive-type-kwds)
2793 (c-lang-const c-constant-kwds))
2794 :test 'string-equal)))
2795 (c-lang-defvar c-regular-keywords-regexp
2796 (c-lang-const c-regular-keywords-regexp))
2798 (c-lang-defconst c-primary-expr-regexp
2799 ;; Regexp matching the start of any primary expression, i.e. any
2800 ;; literal, symbol, prefix operator, and '('. It doesn't need to
2801 ;; exclude keywords; they are excluded afterwards unless the second
2802 ;; submatch matches. If the first but not the second submatch
2803 ;; matches then it is an ambiguous primary expression; it could also
2804 ;; be a match of e.g. an infix operator. (The case with ambiguous
2805 ;; keyword operators isn't handled.)
2807 t (let* ((prefix-ops
2808 (c-filter-ops (c-lang-const c-operators)
2809 '(prefix)
2810 (lambda (op)
2811 ;; Filter out the special case prefix
2812 ;; operators that are close parens.
2813 (not (string-match "\\s)" op)))))
2815 (nonkeyword-prefix-ops
2816 (c-filter-ops prefix-ops
2818 "\\`\\(\\s.\\|\\s(\\|\\s)\\)+\\'"))
2820 (in-or-postfix-ops
2821 (c-filter-ops (c-lang-const c-operators)
2822 '(postfix
2823 postfix-if-paren
2824 left-assoc
2825 right-assoc
2826 right-assoc-sequence)
2829 (unambiguous-prefix-ops (c--set-difference nonkeyword-prefix-ops
2830 in-or-postfix-ops
2831 :test 'string-equal))
2832 (ambiguous-prefix-ops (c--intersection nonkeyword-prefix-ops
2833 in-or-postfix-ops
2834 :test 'string-equal)))
2836 (concat
2837 "\\("
2838 ;; Take out all symbol class operators from `prefix-ops' and make the
2839 ;; first submatch from them together with `c-primary-expr-kwds'.
2840 (c-make-keywords-re t
2841 (append (c-lang-const c-primary-expr-kwds)
2842 (c--set-difference prefix-ops nonkeyword-prefix-ops
2843 :test 'string-equal)))
2845 "\\|"
2846 ;; Match all ambiguous operators.
2847 (c-make-keywords-re nil
2848 (c--intersection nonkeyword-prefix-ops in-or-postfix-ops
2849 :test 'string-equal))
2850 "\\)"
2852 "\\|"
2853 ;; Now match all other symbols.
2854 (c-lang-const c-symbol-start)
2856 "\\|"
2857 ;; The chars that can start integer and floating point
2858 ;; constants.
2859 "\\.?[0-9]"
2861 "\\|"
2862 ;; The unambiguous operators from `prefix-ops'.
2863 (c-make-keywords-re nil
2864 (c--set-difference nonkeyword-prefix-ops in-or-postfix-ops
2865 :test 'string-equal))
2867 "\\|"
2868 ;; Match string and character literals.
2869 "\\s\""
2870 (if (memq 'gen-string-delim c-emacs-features)
2871 "\\|\\s|"
2872 ""))))
2873 (c-lang-defvar c-primary-expr-regexp (c-lang-const c-primary-expr-regexp))
2876 ;;; Additional constants for parser-level constructs.
2878 (c-lang-defconst c-decl-start-colon-kwd-re
2879 "Regexp matching a keyword that is followed by a colon, where
2880 the whole construct can precede a declaration.
2881 E.g. \"public:\" in C++."
2882 t "\\<\\>"
2883 c++ (c-make-keywords-re t (c-lang-const c-protection-kwds)))
2884 (c-lang-defvar c-decl-start-colon-kwd-re
2885 (c-lang-const c-decl-start-colon-kwd-re))
2887 (c-lang-defconst c-decl-prefix-re
2888 "Regexp matching something that might precede a declaration, cast or
2889 label, such as the last token of a preceding statement or declaration.
2890 This is used in the common situation where a declaration or cast
2891 doesn't start with any specific token that can be searched for.
2893 The regexp should not match bob; that is done implicitly. It can't
2894 require a match longer than one token. The end of the token is taken
2895 to be at the end of the first submatch, which is assumed to always
2896 match. It's undefined whether identifier syntax (see
2897 `c-identifier-syntax-table') is in effect or not. This regexp is
2898 assumed to be a superset of `c-label-prefix-re' if
2899 `c-recognize-colon-labels' is set.
2901 Besides this, `c-decl-start-kwds' is used to find declarations.
2903 Note: This variable together with `c-decl-start-re' and
2904 `c-decl-start-kwds' is only used to detect \"likely\"
2905 declaration/cast/label starts. I.e. they might produce more matches
2906 but should not miss anything (or else it's necessary to use text
2907 properties - see the next note). Wherever they match, the following
2908 construct is analyzed to see if it indeed is a declaration, cast or
2909 label. That analysis is not cheap, so it's important that not too
2910 many false matches are triggered.
2912 Note: If a declaration/cast/label start can't be detected with this
2913 variable, it's necessary to use the `c-type' text property with the
2914 value `c-decl-end' on the last char of the last token preceding the
2915 declaration. See the comment blurb at the start of cc-engine.el for
2916 more info."
2918 ;; We match a sequence of characters to skip over things like \"};\"
2919 ;; more quickly. We match ")" in C for K&R region declarations, and
2920 ;; in all languages except Java for when a cpp macro definition
2921 ;; begins with a declaration.
2922 t "\\([{}();,]+\\)"
2923 java "\\([{}(;,<]+\\)"
2924 ;; Match "<" in C++ to get the first argument in a template arglist.
2925 ;; In that case there's an additional check in `c-find-decl-spots'
2926 ;; that it got open paren syntax. Match ":" to aid in picking up
2927 ;; "public:", etc. This involves additional checks in
2928 ;; `c-find-decl-prefix-search' to prevent a match of identifiers
2929 ;; or labels.
2930 c++ "\\([{}();:,<]+\\)"
2931 ;; Additionally match the protection directives in Objective-C.
2932 ;; Note that this doesn't cope with the longer directives, which we
2933 ;; would have to match from start to end since they don't end with
2934 ;; any easily recognized characters.
2935 objc (concat "\\([{}();,]+\\|"
2936 (c-make-keywords-re nil (c-lang-const c-protection-kwds))
2937 "\\)")
2938 ;; Pike is like C but we also match "[" for multiple value
2939 ;; assignments and type casts.
2940 pike "\\([{}()[;,]+\\)")
2941 (c-lang-defvar c-decl-prefix-re (c-lang-const c-decl-prefix-re)
2942 'dont-doc)
2944 (c-lang-defconst c-decl-start-re
2945 "Regexp matching the start of any declaration, cast or label.
2946 It's used on the token after the one `c-decl-prefix-re' matched. This
2947 regexp should not try to match those constructs accurately as it's
2948 only used as a sieve to avoid spending more time checking other
2949 constructs."
2950 t (c-lang-const c-identifier-start))
2951 (c-lang-defvar c-decl-start-re (c-lang-const c-decl-start-re))
2953 (c-lang-defconst c-decl-prefix-or-start-re
2954 ;; Regexp matching something that might precede or start a
2955 ;; declaration, cast or label.
2957 ;; If the first submatch matches, it's taken to match the end of a
2958 ;; token that might precede such a construct, e.g. ';', '}' or '{'.
2959 ;; It's built from `c-decl-prefix-re'.
2961 ;; If the first submatch did not match, the match of the whole
2962 ;; regexp is taken to be at the first token in the declaration.
2963 ;; `c-decl-start-re' is not checked in this case.
2965 ;; Design note: The reason the same regexp is used to match both
2966 ;; tokens that precede declarations and start them is to avoid an
2967 ;; extra regexp search from the previous declaration spot in
2968 ;; `c-find-decl-spots'. Users of `c-find-decl-spots' also count on
2969 ;; that it finds all declaration/cast/label starts in approximately
2970 ;; linear order, so we can't do the searches in two separate passes.
2971 t (if (c-lang-const c-decl-start-kwds)
2972 (concat (c-lang-const c-decl-prefix-re)
2973 "\\|"
2974 (c-make-keywords-re t (c-lang-const c-decl-start-kwds)))
2975 (c-lang-const c-decl-prefix-re)))
2976 (c-lang-defvar c-decl-prefix-or-start-re
2977 (c-lang-const c-decl-prefix-or-start-re))
2979 (c-lang-defconst c-cast-parens
2980 ;; List containing the paren characters that can open a cast, or nil in
2981 ;; languages without casts.
2982 t (c-filter-ops (c-lang-const c-operators)
2983 '(prefix)
2984 "\\`\\s(\\'"
2985 (lambda (op) (elt op 0))))
2986 (c-lang-defvar c-cast-parens (c-lang-const c-cast-parens))
2988 (c-lang-defconst c-block-prefix-disallowed-chars
2989 "List of syntactically relevant characters that never can occur before
2990 the open brace in any construct that contains a brace block, e.g. in
2991 the \"class Foo: public Bar\" part of:
2993 class Foo: public Bar {int x();} a, *b;
2995 If parens can occur, the chars inside those aren't filtered with this
2996 list.
2998 `<' and `>' should be disallowed even if angle bracket arglists can
2999 occur. That since the search function needs to stop at them anyway to
3000 ensure they are given paren syntax.
3002 This is used to skip backward from the open brace to find the region
3003 in which to look for a construct like \"class\", \"enum\",
3004 \"namespace\" or whatever. That skipping should be as tight as
3005 possible for good performance."
3007 ;; Default to all chars that only occurs in nonsymbol tokens outside
3008 ;; identifiers.
3009 t (c--set-difference
3010 (c-lang-const c-nonsymbol-token-char-list)
3011 (c-filter-ops (append (c-lang-const c-identifier-ops)
3012 (list (cons nil
3013 (c-lang-const c-after-id-concat-ops))))
3016 (lambda (op)
3017 (let ((pos 0) res)
3018 (while (string-match "\\(\\s.\\|\\s(\\|\\s)\\)"
3019 op pos)
3020 (setq res (cons (aref op (match-beginning 1)) res)
3021 pos (match-end 0)))
3022 res))))
3024 ;; Allow cpp operations (where applicable).
3025 t (if (c-lang-const c-opt-cpp-prefix)
3026 (c--set-difference (c-lang-const c-block-prefix-disallowed-chars)
3027 '(?#))
3028 (c-lang-const c-block-prefix-disallowed-chars))
3030 ;; Allow ':' for inherit list starters.
3031 (c++ objc idl) (c--set-difference (c-lang-const c-block-prefix-disallowed-chars)
3032 '(?:))
3034 ;; Allow ',' for multiple inherits.
3035 (c++ java) (c--set-difference (c-lang-const c-block-prefix-disallowed-chars)
3036 '(?,))
3038 ;; Allow parentheses for anonymous inner classes in Java and class
3039 ;; initializer lists in Pike.
3040 (java pike) (c--set-difference (c-lang-const c-block-prefix-disallowed-chars)
3041 '(?\( ?\)))
3043 ;; Allow '"' for extern clauses (e.g. extern "C" {...}).
3044 (c c++ objc) (c--set-difference (c-lang-const c-block-prefix-disallowed-chars)
3045 '(?\" ?')))
3047 (c-lang-defconst c-block-prefix-charset
3048 ;; `c-block-prefix-disallowed-chars' as an inverted charset suitable
3049 ;; for `c-syntactic-skip-backward'.
3050 t (c-make-bare-char-alt (c-lang-const c-block-prefix-disallowed-chars) t))
3051 (c-lang-defvar c-block-prefix-charset (c-lang-const c-block-prefix-charset))
3053 (c-lang-defconst c-type-decl-prefix-key
3054 "Regexp matching any declarator operator that might precede the
3055 identifier in a declaration, e.g. the \"*\" in \"char *argv\". This
3056 regexp should match \"(\" if parentheses are valid in declarators.
3057 The end of the first submatch is taken as the end of the operator.
3058 Identifier syntax is in effect when this is matched \(see
3059 `c-identifier-syntax-table')."
3060 t (if (c-lang-const c-type-modifier-kwds)
3061 (concat (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>")
3062 ;; Default to a regexp that never matches.
3063 "\\<\\>")
3064 ;; Check that there's no "=" afterwards to avoid matching tokens
3065 ;; like "*=".
3066 (c objc) (concat "\\("
3067 "[*(]"
3068 "\\|"
3069 (c-lang-const c-type-decl-prefix-key)
3070 "\\)"
3071 "\\([^=]\\|$\\)")
3072 c++ (concat "\\("
3073 "&&"
3074 "\\|"
3075 "\\.\\.\\."
3076 "\\|"
3077 "[*(&]"
3078 "\\|"
3079 (c-lang-const c-type-decl-prefix-key)
3080 "\\|"
3081 (concat "\\(" ; 3
3082 ;; If this matches there's special treatment in
3083 ;; `c-font-lock-declarators' and
3084 ;; `c-font-lock-declarations' that check for a
3085 ;; complete name followed by ":: *".
3086 (c-lang-const c-identifier-start)
3087 "\\)")
3088 "\\)"
3089 "\\([^=]\\|$\\)")
3090 pike "\\(\\*\\)\\([^=]\\|$\\)")
3091 (c-lang-defvar c-type-decl-prefix-key (c-lang-const c-type-decl-prefix-key)
3092 'dont-doc)
3094 (c-lang-defconst c-type-decl-operator-prefix-key
3095 "Regexp matching any declarator operator which isn't a keyword
3096 that might precede the identifier in a declaration, e.g. the
3097 \"*\" in \"char *argv\". The end of the first submatch is taken
3098 as the end of the operator. Identifier syntax is in effect when
3099 this is matched \(see `c-identifier-syntax-table')."
3100 t ;; Default to a regexp that never matches.
3101 "\\<\\>"
3102 ;; Check that there's no "=" afterwards to avoid matching tokens
3103 ;; like "*=".
3104 (c objc) (concat "\\(\\*\\)"
3105 "\\([^=]\\|$\\)")
3106 c++ (concat "\\("
3107 "\\.\\.\\."
3108 "\\|"
3109 "\\*"
3110 "\\)"
3111 "\\([^=]\\|$\\)")
3112 pike "\\(\\*\\)\\([^=]\\|$\\)")
3113 (c-lang-defvar c-type-decl-operator-prefix-key
3114 (c-lang-const c-type-decl-operator-prefix-key))
3116 (c-lang-defconst c-type-decl-suffix-key
3117 "Regexp matching the declarator operators that might follow after the
3118 identifier in a declaration, e.g. the \"[\" in \"char argv[]\". This
3119 regexp should match \")\" if parentheses are valid in declarators. If
3120 it matches an open paren of some kind, the type declaration check
3121 continues at the corresponding close paren, otherwise the end of the
3122 first submatch is taken as the end of the operator. Identifier syntax
3123 is in effect when this is matched (see `c-identifier-syntax-table')."
3124 ;; Default to a regexp that matches `c-type-modifier-kwds' and a
3125 ;; function argument list parenthesis.
3126 t (if (c-lang-const c-type-modifier-kwds)
3127 (concat "\\((\\|"
3128 (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>"
3129 "\\)")
3130 "\\((\\)")
3131 (c c++ objc) (concat
3132 "\\("
3133 "[)[(]"
3134 (if (c-lang-const c-type-modifier-kwds)
3135 (concat
3136 "\\|"
3137 ;; "throw" in `c-type-modifier-kwds' is followed
3138 ;; by a parenthesis list, but no extra measures
3139 ;; are necessary to handle that.
3140 (regexp-opt (c-lang-const c-type-modifier-kwds) t)
3141 "\\>")
3143 "\\)")
3144 java "\\([[()]\\)"
3145 idl "\\([[(]\\)")
3146 (c-lang-defvar c-type-decl-suffix-key (c-lang-const c-type-decl-suffix-key)
3147 'dont-doc)
3149 (c-lang-defconst c-after-suffixed-type-decl-key
3150 "This regexp is matched after a declarator expression where
3151 `c-type-decl-suffix-key' has matched. If it matches then the
3152 construct is taken as a declaration. It's typically used to match the
3153 beginning of a function body or whatever might occur after the
3154 function header in a function declaration or definition. It's
3155 undefined whether identifier syntax (see `c-identifier-syntax-table')
3156 is in effect or not.
3158 Note that it's used in cases like after \"foo (bar)\" so it should
3159 only match when it's certain that it's a declaration, e.g., \"{\" but
3160 not \",\" or \";\"."
3161 t "{"
3162 ;; If K&R style declarations should be recognized then one could
3163 ;; consider to match the start of any symbol since we want to match
3164 ;; the start of the first declaration in the "K&R region". That
3165 ;; could however produce false matches on code like "FOO(bar) x"
3166 ;; where FOO is a cpp macro, so it's better to leave it out and rely
3167 ;; on the other heuristics in that case.
3168 t (if (c-lang-const c-postfix-spec-kwds)
3169 ;; Add on the keywords in `c-postfix-spec-kwds'.
3170 (concat (c-lang-const c-after-suffixed-type-decl-key)
3171 "\\|"
3172 (c-make-keywords-re t (c-lang-const c-postfix-spec-kwds)))
3173 (c-lang-const c-after-suffixed-type-decl-key))
3174 ;; Also match the colon that starts a base class initializer list in
3175 ;; C++. That can be confused with a function call before the colon
3176 ;; in a ? : operator, but we count on that `c-decl-prefix-re' won't
3177 ;; match before such a thing (as a declaration-level construct;
3178 ;; matches inside arglist contexts are already excluded).
3179 c++ "[{:]")
3180 (c-lang-defvar c-after-suffixed-type-decl-key
3181 (c-lang-const c-after-suffixed-type-decl-key)
3182 'dont-doc)
3184 (c-lang-defconst c-after-suffixed-type-maybe-decl-key
3185 ;; Regexp that in addition to `c-after-suffixed-type-decl-key'
3186 ;; matches ";" and ",".
3187 t (concat "\\(" (c-lang-const c-after-suffixed-type-decl-key) "\\)"
3188 "\\|[;,]"))
3189 (c-lang-defvar c-after-suffixed-type-maybe-decl-key
3190 (c-lang-const c-after-suffixed-type-maybe-decl-key))
3192 (c-lang-defconst c-opt-type-concat-key
3193 "Regexp matching operators that concatenate types, e.g. the \"|\" in
3194 \"int|string\" in Pike. The end of the first submatch is taken as the
3195 end of the operator. nil in languages without such operators. It's
3196 undefined whether identifier syntax (see `c-identifier-syntax-table')
3197 is in effect or not."
3198 t nil
3199 pike "\\([|.&]\\)\\($\\|[^|.&]\\)")
3200 (c-lang-defvar c-opt-type-concat-key (c-lang-const c-opt-type-concat-key)
3201 'dont-doc)
3203 (c-lang-defconst c-opt-type-suffix-key
3204 "Regexp matching operators that might follow after a type, or nil in
3205 languages that don't have such operators. The end of the first
3206 submatch is taken as the end of the operator. This should not match
3207 things like C++ template arglists if `c-recognize-<>-arglists' is set.
3208 It's undefined whether identifier syntax (see `c-identifier-syntax-table')
3209 is in effect or not."
3210 t nil
3211 (c c++ objc pike) "\\(\\.\\.\\.\\)"
3212 java (concat "\\(\\[" (c-lang-const c-simple-ws) "*\\]\\|\\.\\.\\.\\)"))
3213 (c-lang-defvar c-opt-type-suffix-key (c-lang-const c-opt-type-suffix-key))
3215 (c-lang-defvar c-known-type-key
3216 ;; Regexp matching the known type identifiers. This is initialized
3217 ;; from the type keywords and `*-font-lock-extra-types'. The first
3218 ;; submatch is the one that matches the type. Note that this regexp
3219 ;; assumes that symbol constituents like '_' and '$' have word
3220 ;; syntax.
3221 (let* ((extra-types
3222 (when (boundp (c-mode-symbol "font-lock-extra-types"))
3223 (c-mode-var "font-lock-extra-types")))
3224 (regexp-strings
3225 (delq nil (mapcar (lambda (re)
3226 (when (string-match "[][.*+?^$\\]" re)
3227 re))
3228 extra-types)))
3229 (plain-strings
3230 (delq nil (mapcar (lambda (re)
3231 (unless (string-match "[][.*+?^$\\]" re)
3232 re))
3233 extra-types))))
3234 (concat "\\<\\("
3235 (c-concat-separated
3236 (append (list (c-make-keywords-re nil
3237 (append (c-lang-const c-primitive-type-kwds)
3238 plain-strings)))
3239 regexp-strings)
3240 "\\|")
3241 "\\)\\>")))
3243 (c-lang-defconst c-special-brace-lists
3244 "List of open- and close-chars that makes up a pike-style brace list,
3245 i.e., for a ([ ]) list there should be a cons (?\\[ . ?\\]) in this
3246 list."
3247 t nil
3248 pike '((?{ . ?}) (?\[ . ?\]) (?< . ?>)))
3249 (c-lang-defvar c-special-brace-lists (c-lang-const c-special-brace-lists))
3251 (c-lang-defconst c-recognize-knr-p
3252 "Non-nil means K&R style argument declarations are valid."
3253 t nil
3254 c t)
3255 (c-lang-defvar c-recognize-knr-p (c-lang-const c-recognize-knr-p))
3257 (c-lang-defconst c-pre-id-bracelist-key
3258 "A regexp matching tokens which, preceding an identifier, signify a bracelist.
3260 t "\\<\\>"
3261 c++ "new\\([^[:alnum:]_$]\\|$\\)\\|&&?\\(\\S.\\|$\\)")
3262 (c-lang-defvar c-pre-id-bracelist-key (c-lang-const c-pre-id-bracelist-key))
3264 (c-lang-defconst c-recognize-typeless-decls
3265 "Non-nil means function declarations without return type should be
3266 recognized. That can introduce an ambiguity with parenthesized macro
3267 calls before a brace block. This setting does not affect declarations
3268 that are preceded by a declaration starting keyword, so
3269 e.g. `c-typeless-decl-kwds' may still be used when it's set to nil."
3270 t nil
3271 (c c++ objc java) t)
3272 (c-lang-defvar c-recognize-typeless-decls
3273 (c-lang-const c-recognize-typeless-decls))
3275 (c-lang-defconst c-recognize-<>-arglists
3276 "Non-nil means C++ style template arglists should be handled. More
3277 specifically, this means a comma separated list of types or
3278 expressions surrounded by \"<\" and \">\". It's always preceded by an
3279 identifier or one of the keywords on `c-<>-type-kwds' or
3280 `c-<>-arglist-kwds'. If there's an identifier before then the whole
3281 expression is considered to be a type."
3282 t (or (consp (c-lang-const c-<>-type-kwds))
3283 (consp (c-lang-const c-<>-arglist-kwds)))
3284 java t) ; 2008-10-19. This is crude. The syntax for java
3285 ; generics is not yet coded in CC Mode.
3286 (c-lang-defvar c-recognize-<>-arglists (c-lang-const c-recognize-<>-arglists))
3288 (c-lang-defconst c-<>-notable-chars-re
3289 "A regexp matching any single character notable inside a <...> construct.
3290 This must include \"<\" and \">\", and should include \",\", and
3291 any character which cannot be valid inside such a construct.
3292 This is used in `c-forward-<>-arglist-recur' to try to detect
3293 sequences of tokens which cannot be a template/generic construct.
3294 When \"(\" is present, that defun will attempt to parse a
3295 parenthesized expression inside the template. When \")\" is
3296 present it will treat an unbalanced closing paren as a sign of
3297 the invalidity of the putative template construct."
3298 t "[<;{},|+&->)]"
3299 c++ "[<;{},>()]")
3300 (c-lang-defvar c-<>-notable-chars-re (c-lang-const c-<>-notable-chars-re))
3302 (c-lang-defconst c-enum-clause-introduction-re
3303 ;; A regexp loosely matching the start of an enum clause, starting at the
3304 ;; keyword itself, and extending up to the "{". It may match text which
3305 ;; isn't such a construct; more accurate tests will rule these out when
3306 ;; needed.
3307 t (if (c-lang-const c-brace-list-decl-kwds)
3308 (concat
3309 "\\<\\("
3310 (c-make-keywords-re nil (c-lang-const c-brace-list-decl-kwds))
3311 "\\)\\>"
3312 ;; Disallow various common punctuation chars that can't come
3313 ;; before the '{' of the enum list, to avoid searching too far.
3314 "[^][{};/#=]*"
3315 "{")
3316 "\\<\\>"))
3317 (c-lang-defvar c-enum-clause-introduction-re
3318 (c-lang-const c-enum-clause-introduction-re))
3320 (c-lang-defconst c-enums-contain-decls
3321 "Non-nil means that an enum structure can contain declarations."
3322 t nil
3323 java t)
3324 (c-lang-defvar c-enums-contain-decls (c-lang-const c-enums-contain-decls))
3326 (c-lang-defconst c-recognize-paren-inits
3327 "Non-nil means that parenthesis style initializers exist,
3328 i.e. constructs like
3330 Foo bar (gnu);
3332 in addition to the more classic
3334 Foo bar = gnu;"
3335 t nil
3336 c++ t)
3337 (c-lang-defvar c-recognize-paren-inits (c-lang-const c-recognize-paren-inits))
3339 (c-lang-defconst c-recognize-paren-inexpr-blocks
3340 "Non-nil to recognize gcc style in-expression blocks,
3341 i.e. compound statements surrounded by parentheses inside expressions."
3342 t nil
3343 (c c++) t)
3344 (c-lang-defvar c-recognize-paren-inexpr-blocks
3345 (c-lang-const c-recognize-paren-inexpr-blocks))
3347 (c-lang-defconst c-opt-<>-arglist-start
3348 ;; Regexp matching the start of angle bracket arglists in languages
3349 ;; where `c-recognize-<>-arglists' is set. Does not exclude
3350 ;; keywords outside `c-<>-arglist-kwds'. The first submatch is
3351 ;; assumed to surround the preceding symbol. The whole match is
3352 ;; assumed to end directly after the opening "<".
3353 t (if (c-lang-const c-recognize-<>-arglists)
3354 (concat "\\("
3355 (c-lang-const c-symbol-key)
3356 "\\)"
3357 (c-lang-const c-syntactic-ws)
3358 "<")))
3359 (c-lang-defvar c-opt-<>-arglist-start (c-lang-const c-opt-<>-arglist-start))
3361 (c-lang-defconst c-opt-<>-arglist-start-in-paren
3362 ;; Regexp that in addition to `c-opt-<>-arglist-start' matches close
3363 ;; parens. The first submatch is assumed to surround
3364 ;; `c-opt-<>-arglist-start'.
3365 t (if (c-lang-const c-opt-<>-arglist-start)
3366 (concat "\\("
3367 (c-lang-const c-opt-<>-arglist-start)
3368 "\\)\\|\\s)")))
3369 (c-lang-defvar c-opt-<>-arglist-start-in-paren
3370 (c-lang-const c-opt-<>-arglist-start-in-paren))
3372 (c-lang-defconst c-opt-postfix-decl-spec-key
3373 ;; Regexp matching the beginning of a declaration specifier in the
3374 ;; region between the header and the body of a declaration.
3376 ;; TODO: This is currently not used uniformly; c++-mode and
3377 ;; java-mode each have their own ways of using it.
3378 t nil
3379 c++ (concat ":?"
3380 (c-lang-const c-simple-ws) "*"
3381 "\\(virtual" (c-lang-const c-simple-ws) "+\\)?\\("
3382 (c-make-keywords-re nil (c-lang-const c-protection-kwds))
3383 "\\)" (c-lang-const c-simple-ws) "+"
3384 "\\(" (c-lang-const c-symbol-key) "\\)")
3385 java (c-make-keywords-re t (c-lang-const c-postfix-spec-kwds)))
3386 (c-lang-defvar c-opt-postfix-decl-spec-key
3387 (c-lang-const c-opt-postfix-decl-spec-key))
3389 (c-lang-defconst c-recognize-colon-labels
3390 "Non-nil if generic labels ending with \":\" should be recognized.
3391 That includes labels in code and access keys in classes. This does
3392 not apply to labels recognized by `c-label-kwds' and
3393 `c-opt-extra-label-key'."
3394 t nil
3395 (c c++ objc java pike) t)
3396 (c-lang-defvar c-recognize-colon-labels
3397 (c-lang-const c-recognize-colon-labels))
3399 (c-lang-defconst c-label-prefix-re
3400 "Regexp like `c-decl-prefix-re' that matches any token that can precede
3401 a generic colon label. Not used if `c-recognize-colon-labels' is
3402 nil."
3403 t "\\([{};]+\\)")
3404 (c-lang-defvar c-label-prefix-re
3405 (c-lang-const c-label-prefix-re))
3407 (c-lang-defconst c-nonlabel-token-key
3408 "Regexp matching things that can't occur in generic colon labels,
3409 neither in a statement nor in a declaration context. The regexp is
3410 tested at the beginning of every sexp in a suspected label,
3411 i.e. before \":\". Only used if `c-recognize-colon-labels' is set."
3412 t (concat
3413 ;; All keywords except `c-label-kwds' and `c-protection-kwds'.
3414 (c-make-keywords-re t
3415 (c--set-difference (c-lang-const c-keywords)
3416 (append (c-lang-const c-label-kwds)
3417 (c-lang-const c-protection-kwds))
3418 :test 'string-equal)))
3419 ;; Don't allow string literals, except in AWK and Java. Character constants are OK.
3420 (c objc pike idl) (concat "\"\\|"
3421 (c-lang-const c-nonlabel-token-key))
3422 ;; Also check for open parens in C++, to catch member init lists in
3423 ;; constructors. We normally allow it so that macros with arguments
3424 ;; work in labels.
3425 c++ (concat "\\s(\\|\"\\|" (c-lang-const c-nonlabel-token-key)))
3426 (c-lang-defvar c-nonlabel-token-key (c-lang-const c-nonlabel-token-key))
3428 (c-lang-defconst c-nonlabel-token-2-key
3429 "Regexp matching things that can't occur two symbols before a colon in
3430 a label construct. This catches C++'s inheritance construct \"class foo
3431 : bar\". Only used if `c-recognize-colon-labels' is set."
3432 t "\\<\\>" ; matches nothing
3433 c++ (c-make-keywords-re t '("class")))
3434 (c-lang-defvar c-nonlabel-token-2-key (c-lang-const c-nonlabel-token-2-key))
3436 (c-lang-defconst c-opt-extra-label-key
3437 "Optional regexp matching labels.
3438 Normally, labels are detected according to `c-nonlabel-token-key',
3439 `c-decl-prefix-re' and `c-nonlabel-decl-prefix-re'. This regexp can
3440 be used if there are additional labels that aren't recognized that
3441 way."
3442 t nil
3443 objc (c-make-keywords-re t (c-lang-const c-protection-kwds)))
3444 (c-lang-defvar c-opt-extra-label-key (c-lang-const c-opt-extra-label-key))
3446 (c-lang-defconst c-opt-friend-key
3447 ;; Regexp describing friend declarations classes, or nil in
3448 ;; languages that don't have such things.
3450 ;; TODO: Ought to use `c-prefix-spec-kwds-re' or similar, and the
3451 ;; template skipping isn't done properly. This will disappear soon.
3452 t nil
3453 c++ (concat "friend" (c-lang-const c-simple-ws) "+"
3454 "\\|"
3455 (concat "template"
3456 (c-lang-const c-simple-ws) "*"
3457 "<.+>"
3458 (c-lang-const c-simple-ws) "*"
3459 "friend"
3460 (c-lang-const c-simple-ws) "+")))
3461 (c-lang-defvar c-opt-friend-key (c-lang-const c-opt-friend-key))
3463 (c-lang-defconst c-opt-method-key
3464 ;; Special regexp to match the start of Objective-C methods. The
3465 ;; first submatch is assumed to end after the + or - key.
3466 t nil
3467 objc (concat
3468 ;; TODO: Ought to use a better method than anchoring on bol.
3469 "^\\s *"
3470 "\\([+-]\\)"
3471 (c-lang-const c-simple-ws) "*"
3472 (concat "\\(" ; Return type.
3473 "([^)]*)"
3474 (c-lang-const c-simple-ws) "*"
3475 "\\)?")
3476 "\\(" (c-lang-const c-symbol-key) "\\)"))
3477 (c-lang-defvar c-opt-method-key (c-lang-const c-opt-method-key))
3479 (c-lang-defconst c-type-decl-end-used
3480 ;; Must be set in buffers where the `c-type' text property might be
3481 ;; used with the value `c-decl-end'.
3483 ;; `c-decl-end' is used to mark the ends of labels and access keys
3484 ;; to make interactive refontification work better.
3485 t (or (c-lang-const c-recognize-colon-labels)
3486 (and (c-lang-const c-label-kwds) t))
3487 ;; `c-decl-end' is used to mark the end of the @-style directives in
3488 ;; Objective-C.
3489 objc t)
3490 (c-lang-defvar c-type-decl-end-used (c-lang-const c-type-decl-end-used))
3492 (c-lang-defconst c-maybe-decl-faces
3493 "List of faces that might be put at the start of a type when
3494 `c-font-lock-declarations' runs. This must be evaluated (with `eval') at
3495 runtime to get the actual list of faces. This ensures that face name
3496 aliases in Emacs are resolved."
3497 t '(list nil
3498 font-lock-type-face
3499 c-reference-face-name
3500 font-lock-keyword-face)
3501 java (append (c-lang-const c-maybe-decl-faces)
3502 '(font-lock-preprocessor-face)))
3503 (c-lang-defvar c-maybe-decl-faces (c-lang-const c-maybe-decl-faces))
3506 ;;; Wrap up the `c-lang-defvar' system.
3508 ;; Compile in the list of language variables that has been collected
3509 ;; with the `c-lang-defvar' and `c-lang-setvar' macros. Note that the
3510 ;; first element of each is nil.
3511 (defconst c-lang-variable-inits (cc-eval-when-compile c-lang-variable-inits))
3512 (defconst c-emacs-variable-inits (cc-eval-when-compile c-emacs-variable-inits))
3514 ;; Make the `c-lang-setvar' variables buffer local in the current buffer.
3515 ;; These are typically standard emacs variables such as `comment-start'.
3516 (defmacro c-make-emacs-variables-local ()
3517 `(progn
3518 ,@(mapcar (lambda (init)
3519 `(make-local-variable ',(car init)))
3520 (cdr c-emacs-variable-inits))))
3522 (defun c-make-init-lang-vars-fun (mode)
3523 "Create a function that initializes all the language dependent variables
3524 for the given mode.
3526 This function should be evaluated at compile time, so that the
3527 function it returns is byte compiled with all the evaluated results
3528 from the language constants. Use the `c-init-language-vars' macro to
3529 accomplish that conveniently."
3531 (if (cc-bytecomp-is-compiling)
3532 ;; No need to byte compile this lambda since the byte compiler is
3533 ;; smart enough to detect the `funcall' construct in the
3534 ;; `c-init-language-vars' macro below and compile it all straight
3535 ;; into the function that contains `c-init-language-vars'.
3536 `(lambda ()
3538 ;; This let sets up the context for `c-mode-var' and similar
3539 ;; that could be in the result from `c--macroexpand-all'.
3540 (let ((c-buffer-is-cc-mode ',mode)
3541 current-var source-eval)
3542 (c-make-emacs-variables-local)
3543 (condition-case err
3545 (if (eq c-version-sym ',c-version-sym)
3546 (setq ,@(let ((c-buffer-is-cc-mode mode)
3547 (c-lang-const-expansion 'immediate))
3548 ;; `c-lang-const' will expand to the evaluated
3549 ;; constant immediately in `c--macroexpand-all'
3550 ;; below.
3551 (c--mapcan
3552 (lambda (init)
3553 `(current-var ',(car init)
3554 ,(car init) ,(c--macroexpand-all
3555 (elt init 1))))
3556 ;; Note: The following `append' copies the
3557 ;; first argument. That list is small, so
3558 ;; this doesn't matter too much.
3559 (append (cdr c-emacs-variable-inits)
3560 (cdr c-lang-variable-inits)))))
3562 ;; This diagnostic message isn't useful for end
3563 ;; users, so it's disabled.
3564 ;;(unless (get ',mode 'c-has-warned-lang-consts)
3565 ;; (message ,(concat "%s compiled with CC Mode %s "
3566 ;; "but loaded with %s - evaluating "
3567 ;; "language constants from source")
3568 ;; ',mode ,c-version c-version)
3569 ;; (put ',mode 'c-has-warned-lang-consts t))
3571 (setq source-eval t)
3572 (let ((init ',(append (cdr c-emacs-variable-inits)
3573 (cdr c-lang-variable-inits))))
3574 (dolist (var-init init)
3575 (setq current-var (car var-init))
3576 (set (car var-init) (eval (cadr var-init))))))
3578 (error
3579 (if current-var
3580 (message "Eval error in the `c-lang-defvar' or `c-lang-setvar' for `%s'%s: %S"
3581 current-var
3582 (if source-eval
3583 (format "\
3584 (fallback source eval - %s compiled with CC Mode %s but loaded with %s)"
3585 ',mode ,c-version c-version)
3587 err)
3588 (signal (car err) (cdr err)))))))
3590 ;; Being evaluated from source. Always use the dynamic method to
3591 ;; work well when `c-lang-defvar's in this file are reevaluated
3592 ;; interactively.
3593 `(lambda ()
3594 (require 'cc-langs)
3595 (let ((c-buffer-is-cc-mode ',mode)
3596 (init (append (cdr c-emacs-variable-inits)
3597 (cdr c-lang-variable-inits)))
3598 current-var)
3599 (c-make-emacs-variables-local)
3600 (condition-case err
3602 (dolist (var-init init)
3603 (setq current-var (car var-init))
3604 (set (car var-init) (eval (cadr var-init))))
3606 (error
3607 (if current-var
3608 (message
3609 "Eval error in the `c-lang-defvar' or `c-lang-setver' for `%s' (source eval): %S"
3610 current-var err)
3611 (signal (car err) (cdr err)))))))
3614 (defmacro c-init-language-vars (mode)
3615 "Initialize all the language dependent variables for the given mode.
3616 This macro is expanded at compile time to a form tailored for the mode
3617 in question, so MODE must be a constant. Therefore MODE is not
3618 evaluated and should not be quoted."
3619 `(funcall ,(c-make-init-lang-vars-fun mode)))
3622 (cc-provide 'cc-langs)
3624 ;; Local Variables:
3625 ;; indent-tabs-mode: t
3626 ;; tab-width: 8
3627 ;; End:
3628 ;;; cc-langs.el ends here