1 ;;; cc-langs.el --- language specific settings for CC Mode -*- coding: utf-8 -*-
3 ;; Copyright (C) 1985, 1987, 1992-2014 Free Software Foundation, Inc.
5 ;; Authors: 2002- Alan Mackenzie
6 ;; 1998- Martin Stjernholm
7 ;; 1992-1999 Barry A. Warsaw
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
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/>.
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
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.
118 (unless (fboundp 'declare-function
) (defmacro declare-function
(&rest r
))))
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
)
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 ;; Except it is always loaded - see bug#17463.
134 ;;;(cc-external-require 'cl)
138 ;;; Setup for the `c-lang-defvar' system.
141 ;; These are used to collect the init forms from the subsequent
142 ;; `c-lang-defvar' and `c-lang-setvar'. They are used to build the
143 ;; lambda in `c-make-init-lang-vars-fun' below, and to build `defvar's
144 ;; and `make-variable-buffer-local's in cc-engine and
145 ;; `make-local-variable's in `c-init-language-vars-for'.
146 (defvar c-lang-variable-inits nil
)
147 (defvar c-lang-variable-inits-tail nil
)
148 (setq c-lang-variable-inits
(list nil
)
149 c-lang-variable-inits-tail c-lang-variable-inits
)
150 (defvar c-emacs-variable-inits nil
)
151 (defvar c-emacs-variable-inits-tail nil
)
152 (setq c-emacs-variable-inits
(list nil
)
153 c-emacs-variable-inits-tail c-emacs-variable-inits
))
155 (defmacro c-lang-defvar
(var val
&optional doc
)
156 "Declares the buffer local variable VAR to get the value VAL. VAL is
157 evaluated and assigned at mode initialization. More precisely, VAL is
158 evaluated and bound to VAR when the result from the macro
159 `c-init-language-vars' is evaluated.
161 `c-lang-const' is typically used in VAL to get the right value for the
162 language being initialized, and such calls will be macro expanded to
163 the evaluated constant value at compile time."
166 (eq (car-safe val
) 'c-lang-const
)
169 ;; Special case: If there's no docstring and the value is a
170 ;; simple (c-lang-const foo) where foo is the same name as VAR
171 ;; then take the docstring from the language constant foo.
172 (setq doc
(get (intern (symbol-name (nth 1 val
)) c-lang-constants
)
173 'variable-documentation
)))
177 (let ((elem (assq var
(cdr c-lang-variable-inits
))))
179 (setcdr elem
(list val doc
))
180 (setcdr c-lang-variable-inits-tail
(list (list var val doc
)))
181 (setq c-lang-variable-inits-tail
(cdr c-lang-variable-inits-tail
))))
183 ;; Return the symbol, like the other def* forms.
186 (defmacro c-lang-setvar
(var val
)
187 "Causes the variable VAR to be made buffer local and to get set to the
188 value VAL. VAL is evaluated and assigned at mode initialization. More
189 precisely, VAL is evaluated and bound to VAR when the result from the
190 macro `c-init-language-vars' is evaluated. VAR is typically a standard
191 Emacs variable like `comment-start'.
193 `c-lang-const' is typically used in VAL to get the right value for the
194 language being initialized, and such calls will be macro expanded to
195 the evaluated constant value at compile time."
196 (let ((elem (assq var
(cdr c-emacs-variable-inits
))))
198 (setcdr elem
(list val
)) ; Maybe remove "list", sometime. 2006-07-19
199 (setcdr c-emacs-variable-inits-tail
(list (list var val
)))
200 (setq c-emacs-variable-inits-tail
(cdr c-emacs-variable-inits-tail
))))
202 ;; Return the symbol, like the other def* forms.
205 (put 'c-lang-defvar
'lisp-indent-function
'defun
)
206 ; (eval-after-load "edebug" ; 2006-07-09: def-edebug-spec is now in subr.el.
208 (def-edebug-spec c-lang-defvar
209 (&define name def-form
&optional stringp
)) ;)
211 ;; Suppress "might not be defined at runtime" warning.
212 ;; This file is only used when compiling other cc files.
213 ;; These are defined in cl as aliases to the cl- versions.
214 ;(declare-function delete-duplicates "cl-seq" (cl-seq &rest cl-keys) t)
215 ;(declare-function mapcan "cl-extra" (cl-func cl-seq &rest cl-rest) t)
216 ;(declare-function cl-macroexpand-all "cl" (form &optional env))
219 ;; Some helper functions used when building the language constants.
221 (defun c-filter-ops (ops opgroup-filter op-filter
&optional xlate
)
222 ;; Extract a subset of the operators in the list OPS in a DWIM:ey
223 ;; way. The return value is a plain list of operators:
225 ;; OPS either has the structure of `c-operators', is a single
226 ;; group in `c-operators', or is a plain list of operators.
228 ;; OPGROUP-FILTER specifies how to select the operator groups. It
229 ;; can be t to choose all groups, a list of group type symbols
230 ;; (such as 'prefix) to accept, or a function which will be called
231 ;; with the group symbol for each group and should return non-nil
232 ;; if that group is to be included.
234 ;; If XLATE is given, it's a function which is called for each
235 ;; matching operator and its return value is collected instead.
236 ;; If it returns a list, the elements are spliced directly into
237 ;; the final result, which is returned as a list with duplicates
238 ;; removed using `equal'.
240 ;; `c-mode-syntax-table' for the current mode is in effect during
241 ;; the whole procedure.
242 (unless (listp (car-safe ops
))
243 (setq ops
(list ops
)))
244 (cond ((eq opgroup-filter t
)
245 (setq opgroup-filter
(lambda (opgroup) t
)))
246 ((not (functionp opgroup-filter
))
247 (setq opgroup-filter
`(lambda (opgroup)
248 (memq opgroup
',opgroup-filter
)))))
249 (cond ((eq op-filter t
)
250 (setq op-filter
(lambda (op) t
)))
252 (setq op-filter
`(lambda (op)
253 (string-match ,op-filter op
)))))
255 (setq xlate
'identity
))
256 (c-with-syntax-table (c-lang-const c-mode-syntax-table
)
257 (cl-delete-duplicates
258 (cl-mapcan (lambda (opgroup)
259 (when (if (symbolp (car opgroup
))
260 (when (funcall opgroup-filter
(car opgroup
))
261 (setq opgroup
(cdr opgroup
))
264 (cl-mapcan (lambda (op)
265 (when (funcall op-filter op
)
266 (let ((res (funcall xlate op
)))
267 (if (listp res
) res
(list res
)))))
273 ;;; Various mode specific values that aren't language related.
275 (c-lang-defconst c-mode-menu
276 ;; The definition for the mode menu. The menu title is prepended to
277 ;; this before it's fed to `easy-menu-define'.
278 t
`(["Comment Out Region" comment-region
279 (c-fn-region-is-active-p)]
280 ["Uncomment Region" (comment-region (region-beginning)
282 (c-fn-region-is-active-p)]
283 ["Indent Expression" c-indent-exp
284 (memq (char-after) '(?\
( ?\
[ ?\
{))]
285 ["Indent Line or Region" c-indent-line-or-region t
]
286 ["Fill Comment Paragraph" c-fill-paragraph t
]
288 ["Backward Statement" c-beginning-of-statement t
]
289 ["Forward Statement" c-end-of-statement t
]
290 ,@(when (c-lang-const c-opt-cpp-prefix
)
291 ;; Only applicable if there's a cpp preprocessor.
292 `(["Up Conditional" c-up-conditional t
]
293 ["Backward Conditional" c-backward-conditional t
]
294 ["Forward Conditional" c-forward-conditional t
]
296 ["Macro Expand Region" c-macro-expand
297 (c-fn-region-is-active-p)]
298 ["Backslashify" c-backslash-region
299 (c-fn-region-is-active-p)]))
302 ["Set Style..." c-set-style t
]
303 ["Show Current Style Name" (message
305 c-indentation-style
) t
]
306 ["Guess Style from this Buffer" c-guess-buffer-no-install t
]
307 ["Install the Last Guessed Style..." c-guess-install
308 (and c-guess-guessed-offsets-alist
309 c-guess-guessed-basic-offset
) ]
310 ["View the Last Guessed Style" c-guess-view
311 (and c-guess-guessed-offsets-alist
312 c-guess-guessed-basic-offset
) ])
315 ["Syntactic indentation" c-toggle-syntactic-indentation
316 :style toggle
:selected c-syntactic-indentation
]
317 ["Electric mode" c-toggle-electric-state
318 :style toggle
:selected c-electric-flag
]
319 ["Auto newline" c-toggle-auto-newline
320 :style toggle
:selected c-auto-newline
]
321 ["Hungry delete" c-toggle-hungry-state
322 :style toggle
:selected c-hungry-delete-key
]
323 ["Subword mode" subword-mode
324 :style toggle
:selected
(and (boundp 'subword-mode
)
330 (defun c-populate-syntax-table (table)
331 "Populate the given syntax table as necessary for a C-like language.
332 This includes setting ' and \" as string delimiters, and setting up
333 the comment syntax to handle both line style \"//\" and block style
334 \"/*\" \"*/\" comments."
336 (modify-syntax-entry ?_
"_" table
)
337 (modify-syntax-entry ?
\\ "\\" table
)
338 (modify-syntax-entry ?
+ "." table
)
339 (modify-syntax-entry ?-
"." table
)
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 ?
\240 "." table
)
349 ;; Set up block and line oriented comments. The new C
350 ;; standard mandates both comment styles even in C, so since
351 ;; all languages now require dual comments, we make this the
355 ((memq '8-bit c-emacs-features
)
356 (modify-syntax-entry ?
/ ". 1456" table
)
357 (modify-syntax-entry ?
* ". 23" table
))
359 ((memq '1-bit c-emacs-features
)
360 (modify-syntax-entry ?
/ ". 124b" table
)
361 (modify-syntax-entry ?
* ". 23" table
))
363 (t (error "CC Mode is incompatible with this version of Emacs")))
365 (modify-syntax-entry ?
\n "> b" table
)
366 ;; Give CR the same syntax as newline, for selective-display
367 (modify-syntax-entry ?\^m
"> b" table
))
369 (c-lang-defconst c-make-mode-syntax-table
370 "Functions that generates the mode specific syntax tables.
371 The syntax tables aren't stored directly since they're quite large."
373 (let ((table (make-syntax-table)))
374 (c-populate-syntax-table table
)
375 ;; Mode specific syntaxes.
376 ,(cond ((or (c-major-mode-is 'objc-mode
) (c-major-mode-is 'java-mode
))
377 ;; Let '@' be part of symbols in ObjC to cope with
378 ;; its compiler directives as single keyword tokens.
379 ;; This is then necessary since it's assumed that
380 ;; every keyword is a single symbol.
381 `(modify-syntax-entry ?
@ "_" table
))
382 ((c-major-mode-is 'pike-mode
)
383 `(modify-syntax-entry ?
@ "." table
)))
386 (c-lang-defconst c-mode-syntax-table
387 ;; The syntax tables in evaluated form. Only used temporarily when
388 ;; the constants in this file are evaluated.
389 t
(funcall (c-lang-const c-make-mode-syntax-table
)))
391 (c-lang-defconst c
++-make-template-syntax-table
392 ;; A variant of `c++-mode-syntax-table' that defines `<' and `>' as
393 ;; parenthesis characters. Used temporarily when template argument
394 ;; lists are parsed. Note that this encourages incorrect parsing of
395 ;; templates since they might contain normal operators that uses the
396 ;; '<' and '>' characters. Therefore this syntax table might go
397 ;; away when CC Mode handles templates correctly everywhere. WHILE
398 ;; THIS SYNTAX TABLE IS CURRENT, `c-parse-state' MUST _NOT_ BE
401 (java c
++) `(lambda ()
402 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table
))))
403 (modify-syntax-entry ?
< "(>" table
)
404 (modify-syntax-entry ?
> ")<" table
)
406 (c-lang-defvar c
++-template-syntax-table
407 (and (c-lang-const c
++-make-template-syntax-table
)
408 (funcall (c-lang-const c
++-make-template-syntax-table
))))
410 (c-lang-defconst c-no-parens-syntax-table
411 ;; A variant of the standard syntax table which is used to find matching
412 ;; "<"s and ">"s which have been marked as parens using syntax table
413 ;; properties. The other paren characters (e.g. "{", ")" "]") are given a
414 ;; non-paren syntax here. so that the list commands will work on "< ... >"
415 ;; even when there's unbalanced other parens inside them.
417 ;; This variable is nil for languages which don't have template stuff.
419 (if (c-lang-const c-recognize-
<>-arglists
)
420 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table
))))
421 (modify-syntax-entry ?\
( "." table
)
422 (modify-syntax-entry ?\
) "." table
)
423 (modify-syntax-entry ?\
[ "." table
)
424 (modify-syntax-entry ?\
] "." table
)
425 (modify-syntax-entry ?\
{ "." table
)
426 (modify-syntax-entry ?\
} "." table
)
428 (c-lang-defvar c-no-parens-syntax-table
429 (funcall (c-lang-const c-no-parens-syntax-table
)))
431 (c-lang-defconst c-identifier-syntax-modifications
432 "A list that describes the modifications that should be done to the
433 mode syntax table to get a syntax table that matches all identifiers
434 and keywords as words.
436 The list is just like the one used in `font-lock-defaults': Each
437 element is a cons where the car is the character to modify and the cdr
438 the new syntax, as accepted by `modify-syntax-entry'."
439 ;; The $ character is not allowed in most languages (one exception
440 ;; is Java which allows it for legacy reasons) but we still classify
441 ;; it as an identifier character since it's often used in various
442 ;; machine generated identifiers.
443 t
'((?_ .
"w") (?$ .
"w"))
444 (objc java
) (append '((?
@ .
"w"))
445 (c-lang-const c-identifier-syntax-modifications
))
447 (c-lang-defvar c-identifier-syntax-modifications
448 (c-lang-const c-identifier-syntax-modifications
))
450 (c-lang-defvar c-identifier-syntax-table
451 (let ((table (copy-syntax-table (c-mode-var "mode-syntax-table")))
452 (mods c-identifier-syntax-modifications
)
457 (modify-syntax-entry (car mod
) (cdr mod
) table
))
459 "Syntax table built on the mode syntax table but additionally
460 classifies symbol constituents like '_' and '$' as word constituents,
461 so that all identifiers are recognized as words.")
463 (c-lang-defconst c-get-state-before-change-functions
464 ;; For documentation see the following c-lang-defvar of the same name.
465 ;; The value here may be a list of functions or a single function.
467 c
++ '(c-extend-region-for-CPP
468 c-before-change-check-
<>-operators
469 c-invalidate-macro-cache
)
470 (c objc
) '(c-extend-region-for-CPP c-invalidate-macro-cache
)
471 ;; java 'c-before-change-check-<>-operators
472 awk
'c-awk-record-region-clear-NL
)
473 (c-lang-defvar c-get-state-before-change-functions
474 (let ((fs (c-lang-const c-get-state-before-change-functions
)))
478 "If non-nil, a list of functions called from c-before-change-hook.
479 Typically these will record enough state to allow
480 `c-before-font-lock-function' to extend the region to fontify,
481 and may do such things as removing text-properties which must be
484 These functions will be run in the order given. Each of them
485 takes 2 parameters, the BEG and END supplied to every
486 before-change function; on entry, the buffer will have been
487 widened and match-data will have been saved; point is undefined
488 on both entry and exit; the return value is ignored.
490 The functions are called even when font locking isn't enabled.
492 When the mode is initialized, the functions are called with
493 parameters \(point-min) and \(point-max).")
495 (c-lang-defconst c-before-font-lock-functions
496 ;; For documentation see the following c-lang-defvar of the same name.
497 ;; The value here may be a list of functions or a single function.
498 t
'c-change-set-fl-decl-start
499 (c c
++ objc
) '(c-neutralize-syntax-in-and-mark-CPP
500 c-change-set-fl-decl-start
)
501 awk
'c-awk-extend-and-syntax-tablify-region
)
502 (c-lang-defvar c-before-font-lock-functions
503 (let ((fs (c-lang-const c-before-font-lock-functions
)))
507 "If non-nil, a list of functions called just before font locking.
508 Typically they will extend the region about to be fontified \(see
509 below) and will set `syntax-table' text properties on the region.
511 These functions will be run in the order given. Each of them
512 takes 3 parameters, the BEG, END, and OLD-LEN supplied to every
513 after-change function; point is undefined on both entry and exit;
514 on entry, the buffer will have been widened and match-data will
515 have been saved; the return value is ignored.
517 The functions may extend the region to be fontified by setting the
518 buffer local variables c-new-BEG and c-new-END.
520 The functions are called even when font locking is disabled.
522 When the mode is initialized, these functions are called with
523 parameters \(point-min), \(point-max) and <buffer size>.")
525 (c-lang-defconst c-before-context-fontification-functions
527 t
'c-context-set-fl-decl-start
)
528 ;; For documentation see the following c-lang-defvar of the same name.
529 ;; The value here may be a list of functions or a single function.
530 (c-lang-defvar c-before-context-fontification-functions
531 (let ((fs (c-lang-const c-before-context-fontification-functions
)))
535 "If non-nil, a list of functions called just before context (or
536 other non-change) fontification is done. Typically they will
539 These functions will be run in the order given. Each of them
540 takes 2 parameters, the BEG and END of the region to be
541 fontified. Point is undefined on both entry and exit. On entry,
542 the buffer will have been widened and match-data will have been
543 saved; the return value is a cons of the adjusted
544 region, (NEW-BEG . NEW-END).")
547 ;;; Syntactic analysis ("virtual semicolons") for line-oriented languages (AWK).
548 (c-lang-defconst c-at-vsemi-p-fn
549 "Contains a function \"Is there a virtual semicolon at POS or point?\".
550 Such a function takes one optional parameter, a buffer position (defaults to
551 point), and returns nil or t. This variable contains nil for languages which
552 don't have EOL terminated statements. "
554 (c c
++ objc
) 'c-at-macro-vsemi-p
555 awk
'c-awk-at-vsemi-p
)
556 (c-lang-defvar c-at-vsemi-p-fn
(c-lang-const c-at-vsemi-p-fn
))
558 (c-lang-defconst c-vsemi-status-unknown-p-fn
559 "Contains a function \"are we unsure whether there is a virtual semicolon on this line?\".
560 The (admittedly kludgy) purpose of such a function is to prevent an infinite
561 recursion in c-beginning-of-statement-1 when point starts at a `while' token.
562 The function MUST NOT UNDER ANY CIRCUMSTANCES call c-beginning-of-statement-1,
563 even indirectly. This variable contains nil for languages which don't have
564 EOL terminated statements."
566 (c c
++ objc
) 'c-macro-vsemi-status-unknown-p
567 awk
'c-awk-vsemi-status-unknown-p
)
568 (c-lang-defvar c-vsemi-status-unknown-p-fn
569 (c-lang-const c-vsemi-status-unknown-p-fn
))
572 ;;; Lexer-level syntax (identifiers, tokens etc).
574 (c-lang-defconst c-has-bitfields
575 "Whether the language has bitfield declarations."
578 (c-lang-defvar c-has-bitfields
(c-lang-const c-has-bitfields
))
580 (c-lang-defconst c-symbol-start
581 "Regexp that matches the start of a symbol, i.e. any identifier or
582 keyword. It's unspecified how far it matches. Does not contain a \\|
583 operator at the top level."
584 t
(concat "[" c-alpha
"_]")
585 java
(concat "[" c-alpha
"_@]")
586 objc
(concat "[" c-alpha
"_@]")
587 pike
(concat "[" c-alpha
"_`]"))
588 (c-lang-defvar c-symbol-start
(c-lang-const c-symbol-start
))
590 (c-lang-defconst c-symbol-chars
591 "Set of characters that can be part of a symbol.
592 This is of the form that fits inside [ ] in a regexp."
593 ;; Pike note: With the backquote identifiers this would include most
594 ;; operator chars too, but they are handled with other means instead.
595 t
(concat c-alnum
"_$")
596 objc
(concat c-alnum
"_$@"))
597 (c-lang-defvar c-symbol-chars
(c-lang-const c-symbol-chars
))
599 (c-lang-defconst c-symbol-key
600 "Regexp matching identifiers and keywords (with submatch 0). Assumed
601 to match if `c-symbol-start' matches on the same position."
602 t
(concat (c-lang-const c-symbol-start
)
603 "[" (c-lang-const c-symbol-chars
) "]*")
605 ;; Use the value from C here since the operator backquote is
606 ;; covered by the other alternative.
607 (c-lang-const c-symbol-key c
)
609 (c-make-keywords-re nil
610 (c-lang-const c-overloadable-operators
))))
611 (c-lang-defvar c-symbol-key
(c-lang-const c-symbol-key
))
613 (c-lang-defconst c-symbol-key-depth
614 ;; Number of regexp grouping parens in `c-symbol-key'.
615 t
(regexp-opt-depth (c-lang-const c-symbol-key
)))
617 (c-lang-defconst c-nonsymbol-chars
618 "This is the set of chars that can't be part of a symbol, i.e. the
619 negation of `c-symbol-chars'."
620 t
(concat "^" (c-lang-const c-symbol-chars
)))
621 (c-lang-defvar c-nonsymbol-chars
(c-lang-const c-nonsymbol-chars
))
623 (c-lang-defconst c-nonsymbol-key
624 "Regexp that matches any character that can't be part of a symbol.
625 It's usually appended to other regexps to avoid matching a prefix.
626 It's assumed to not contain any submatchers."
627 ;; The same thing regarding Unicode identifiers applies here as to
629 t
(concat "[" (c-lang-const c-nonsymbol-chars
) "]"))
631 (c-lang-defconst c-identifier-ops
632 "The operators that make up fully qualified identifiers. nil in
633 languages that don't have such things. See `c-operators' for a
634 description of the format. Binary operators can concatenate symbols,
635 e.g. \"::\" in \"A::B::C\". Prefix operators can precede identifiers,
636 e.g. \"~\" in \"~A::B\". Other types of operators aren't supported.
638 This value is by default merged into `c-operators'."
640 c
++ '((prefix "~" "??-" "compl")
643 ;; Java has "." to concatenate identifiers but it's also used for
644 ;; normal indexing. There's special code in the Java font lock
645 ;; rules to fontify qualified identifiers based on the standard
646 ;; naming conventions. We still define "." here to make
647 ;; `c-forward-name' move over as long names as possible which is
648 ;; necessary to e.g. handle throws clauses correctly.
649 java
'((left-assoc "."))
650 idl
'((left-assoc "::")
652 pike
'((left-assoc "::")
656 (c-lang-defconst c-opt-identifier-concat-key
657 ;; Appendable adorned regexp matching the operators that join
658 ;; symbols to fully qualified identifiers, or nil in languages that
659 ;; don't have such things.
661 ;; This was a docstring constant in 5.30. It still works but is now
662 ;; considered internal - change `c-identifier-ops' instead.
663 t
(let ((ops (c-filter-ops (c-lang-const c-identifier-ops
)
664 '(left-assoc right-assoc
)
667 (c-make-keywords-re 'appendable ops
))))
668 (c-lang-defvar c-opt-identifier-concat-key
669 (c-lang-const c-opt-identifier-concat-key
)
672 (c-lang-defconst c-opt-identifier-concat-key-depth
673 ;; Number of regexp grouping parens in `c-opt-identifier-concat-key'.
674 t
(regexp-opt-depth (c-lang-const c-opt-identifier-concat-key
)))
676 (c-lang-defconst c-opt-identifier-prefix-key
677 ;; Appendable adorned regexp matching operators that might precede
678 ;; an identifier and that are part of the identifier in that case.
679 ;; nil in languages without such things.
680 t
(let ((ops (c-filter-ops (c-lang-const c-identifier-ops
)
684 (c-make-keywords-re 'appendable ops
))))
686 (c-lang-defconst c-after-id-concat-ops
687 "Operators that can occur after a binary operator on `c-identifier-ops'
688 in identifiers. nil in languages that don't have such things.
690 Operators here should also have appropriate entries in `c-operators' -
691 it's not taken care of by default."
693 ;; '~' for destructors in C++, '*' for member pointers.
695 ;; In Java we recognize '*' to deal with "foo.bar.*" that can occur
696 ;; in import declarations. (This will also match bogus things like
697 ;; "foo.*bar" but we don't bother.)
700 (c-lang-defconst c-opt-after-id-concat-key
701 ;; Regexp that must match the token after
702 ;; `c-opt-identifier-concat-key' for it to be considered an
703 ;; identifier concatenation operator (which e.g. causes the
704 ;; preceding identifier to be fontified as a reference). Assumed to
705 ;; be a string if `c-opt-identifier-concat-key' is.
707 ;; This was a docstring constant in 5.30. It still works but is now
708 ;; considered internal - change `c-after-id-concat-ops' instead.
709 t
(concat (c-lang-const c-symbol-start
)
710 (if (c-lang-const c-after-id-concat-ops
)
711 (concat "\\|" (c-make-keywords-re 'appendable
712 (c-lang-const c-after-id-concat-ops
)))
715 (c-lang-defconst c-identifier-start
716 "Regexp that matches the start of an (optionally qualified) identifier.
717 It should also match all keywords. It's unspecified how far it
719 t
(concat (c-lang-const c-symbol-start
)
720 (if (c-lang-const c-opt-identifier-prefix-key
)
722 (c-lang-const c-opt-identifier-prefix-key
))
724 (c-lang-defvar c-identifier-start
(c-lang-const c-identifier-start
))
726 (c-lang-defconst c-identifier-key
727 "Regexp matching a fully qualified identifier, like \"A::B::c\" in
728 C++. It does not recognize the full range of syntactic whitespace
729 between the tokens; `c-forward-name' has to be used for that. It
730 should also not match identifiers containing parenthesis groupings,
731 e.g. identifiers with template arguments such as \"A<X,Y>\" in C++."
732 ;; This regexp is more complex than strictly necessary to ensure
733 ;; that it can be matched with a minimum of backtracking.
734 t
(concat (if (c-lang-const c-opt-identifier-prefix-key
)
737 (c-lang-const c-opt-identifier-prefix-key
)
738 (c-lang-const c-simple-ws
) "*"
741 "\\(" (c-lang-const c-symbol-key
) "\\)"
742 (if (c-lang-const c-opt-identifier-concat-key
)
745 (c-lang-const c-simple-ws
) "*"
746 (c-lang-const c-opt-identifier-concat-key
)
747 (c-lang-const c-simple-ws
) "*"
748 (if (c-lang-const c-after-id-concat-ops
)
751 (c-make-keywords-re 'appendable
752 (c-lang-const c-after-id-concat-ops
))
754 ;; For flexibility, consider the symbol match
755 ;; optional if we've hit a
756 ;; `c-after-id-concat-ops' operator. This is
757 ;; also necessary to handle the "*" that can
758 ;; end import declaration identifiers in Java.
760 (c-lang-const c-simple-ws
) "*"
761 "\\(" (c-lang-const c-symbol-key
) "\\)"
764 "\\(" (c-lang-const c-symbol-key
) "\\)"
766 (concat "\\(" (c-lang-const c-symbol-key
) "\\)"))
769 (c-lang-defvar c-identifier-key
(c-lang-const c-identifier-key
))
771 (c-lang-defconst c-identifier-last-sym-match
772 ;; This was a docstring constant in 5.30 but it's no longer used.
773 ;; It's only kept to avoid breaking third party code.
775 ;; Used to identify the submatch in `c-identifier-key' that
776 ;; surrounds the last symbol in the qualified identifier. It's a
777 ;; list of submatch numbers, of which the first that has a match is
778 ;; taken. It's assumed that at least one does when the regexp has
782 (c-lang-defconst c-string-escaped-newlines
783 "Set if the language support backslash escaped newlines inside string
787 (c-lang-defvar c-string-escaped-newlines
788 (c-lang-const c-string-escaped-newlines
))
790 (c-lang-defconst c-multiline-string-start-char
791 "Set if the language supports multiline string literals without escaped
792 newlines. If t, all string literals are multiline. If a character,
793 only literals where the open quote is immediately preceded by that
794 literal are multiline."
797 (c-lang-defvar c-multiline-string-start-char
798 (c-lang-const c-multiline-string-start-char
))
800 (c-lang-defconst c-opt-cpp-symbol
801 "The symbol which starts preprocessor constructs when in the margin."
804 (c-lang-defvar c-opt-cpp-symbol
(c-lang-const c-opt-cpp-symbol
))
806 (c-lang-defconst c-opt-cpp-prefix
807 "Regexp matching the prefix of a cpp directive in the languages that
808 normally use that macro preprocessor. Tested at bol or at boi.
809 Assumed to not contain any submatches or \\| operators."
810 ;; TODO (ACM, 2005-04-01). Amend the following to recognize escaped NLs;
811 ;; amend all uses of c-opt-cpp-prefix which count regexp-depth.
814 (c-lang-defvar c-opt-cpp-prefix
(c-lang-const c-opt-cpp-prefix
))
816 (c-lang-defconst c-anchored-cpp-prefix
817 "Regexp matching the prefix of a cpp directive anchored to BOL,
818 in the languages that have a macro preprocessor."
819 t
"^\\s *\\(#\\)\\s *"
821 (c-lang-defvar c-anchored-cpp-prefix
(c-lang-const c-anchored-cpp-prefix
))
823 (c-lang-defconst c-opt-cpp-start
824 "Regexp matching the prefix of a cpp directive including the directive
825 name, or nil in languages without preprocessor support. The first
826 submatch surrounds the directive name."
827 t
(if (c-lang-const c-opt-cpp-prefix
)
828 (concat (c-lang-const c-opt-cpp-prefix
)
829 "\\([" c-alnum
"]+\\)"))
830 ;; Pike, being a scripting language, recognizes hash-bangs too.
831 pike
(concat (c-lang-const c-opt-cpp-prefix
)
832 "\\([" c-alnum
"]+\\|!\\)"))
833 (c-lang-defvar c-opt-cpp-start
(c-lang-const c-opt-cpp-start
))
835 (c-lang-defconst c-cpp-message-directives
836 "List of cpp directives (without the prefix) that are followed by a
838 t
(if (c-lang-const c-opt-cpp-prefix
)
840 (c c
++ objc pike
) '("error" "warning"))
842 (c-lang-defconst c-cpp-include-directives
843 "List of cpp directives (without the prefix) that are followed by a
844 file name in angle brackets or quotes."
845 t
(if (c-lang-const c-opt-cpp-prefix
)
847 objc
'("include" "import"))
849 (c-lang-defconst c-opt-cpp-macro-define
850 "Cpp directive (without the prefix) that is followed by a macro
851 definition, or nil if the language doesn't have any."
852 t
(if (c-lang-const c-opt-cpp-prefix
)
854 (c-lang-defvar c-opt-cpp-macro-define
855 (c-lang-const c-opt-cpp-macro-define
))
857 (c-lang-defconst c-opt-cpp-macro-define-start
858 ;; Regexp matching everything up to the macro body of a cpp define, or the
859 ;; end of the logical line if there is none. Submatch 1 is the name of the
860 ;; macro. Set if c-opt-cpp-macro-define is.
861 t
(if (c-lang-const c-opt-cpp-macro-define
)
862 (concat (c-lang-const c-opt-cpp-prefix
)
863 (c-lang-const c-opt-cpp-macro-define
)
864 "[ \t]+\\(\\(\\sw\\|_\\)+\\)\\(\([^\)]*\)\\)?"
866 "\\([ \t]\\|\\\\\n\\)*")))
867 (c-lang-defvar c-opt-cpp-macro-define-start
868 (c-lang-const c-opt-cpp-macro-define-start
))
870 (c-lang-defconst c-opt-cpp-macro-define-id
871 ;; Regexp matching everything up to the end of the identifier defined
873 t
(if (c-lang-const c-opt-cpp-macro-define
)
874 (concat (c-lang-const c-opt-cpp-prefix
) ; #
875 (c-lang-const c-opt-cpp-macro-define
) ; define
876 "[ \t]+\\(\\sw\\|_\\)+")))
877 (c-lang-defvar c-opt-cpp-macro-define-id
878 (c-lang-const c-opt-cpp-macro-define-id
))
880 (c-lang-defconst c-cpp-expr-directives
881 "List of cpp directives (without the prefix) that are followed by an
883 t
(if (c-lang-const c-opt-cpp-prefix
)
886 (c-lang-defconst c-cpp-expr-intro-re
887 "Regexp which matches the start of a CPP directive which contains an
888 expression, or nil if there aren't any in the language."
889 t
(if (c-lang-const c-cpp-expr-directives
)
891 (c-lang-const c-opt-cpp-prefix
)
892 (c-make-keywords-re t
(c-lang-const c-cpp-expr-directives
)))))
893 (c-lang-defvar c-cpp-expr-intro-re
894 (c-lang-const c-cpp-expr-intro-re
))
896 (c-lang-defconst c-cpp-expr-functions
897 "List of functions in cpp expressions."
898 t
(if (c-lang-const c-opt-cpp-prefix
)
900 pike
'("defined" "efun" "constant"))
902 (c-lang-defconst c-assignment-operators
903 "List of all assignment operators."
904 t
'("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=")
905 java
(append (c-lang-const c-assignment-operators
)
907 c
++ (append (c-lang-const c-assignment-operators
)
908 '("and_eq" "or_eq" "xor_eq" "??!=" "??'="))
911 (c-lang-defconst c-operators
912 "List describing all operators, along with their precedence and
913 associativity. The order in the list corresponds to the precedence of
914 the operators: The operators in each element are a group with the same
915 precedence, and the group has higher precedence than the groups in all
916 following elements. The car of each element describes the type of the
917 operator group, and the cdr is a list of the operator tokens in it.
918 The operator group types are:
920 'prefix Unary prefix operators.
921 'postfix Unary postfix operators.
923 Unary postfix operators if and only if the chars have
925 'left-assoc Binary left associative operators (i.e. a+b+c means (a+b)+c).
926 'right-assoc Binary right associative operators (i.e. a=b=c means a=(b=c)).
927 'right-assoc-sequence
928 Right associative operator that constitutes of a
929 sequence of tokens that separate expressions. All the
930 tokens in the group are in this case taken as
931 describing the sequence in one such operator, and the
932 order between them is therefore significant.
934 Operators containing a character with paren syntax are taken to match
935 with a corresponding open/close paren somewhere else. A postfix
936 operator with close paren syntax is taken to end a postfix expression
937 started somewhere earlier, rather than start a new one at point. Vice
938 versa for prefix operators with open paren syntax.
940 Note that operators like \".\" and \"->\" which in language references
941 often are described as postfix operators are considered binary here,
942 since CC Mode treats every identifier as an expression."
944 ;; There's currently no code in CC Mode that exploit all the info
945 ;; in this variable; precedence, associativity etc are present as a
946 ;; preparation for future work.
949 ,@(when (c-lang-const c-opt-cpp-prefix
)
951 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
954 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
955 '("%:%:" "??=??=")))))
958 ,@(c-lang-const c-identifier-ops
)
959 ,@(cond ((or (c-major-mode-is 'c
++-mode
) (c-major-mode-is 'java-mode
))
960 `((postfix-if-paren "<" ">"))) ; Templates.
961 ((c-major-mode-is 'pike-mode
)
962 `((prefix "global" "predef")))
963 ((c-major-mode-is 'java-mode
)
964 `((prefix "super"))))
967 ,@(when (c-major-mode-is 'c
++-mode
)
968 ;; The following need special treatment.
969 `((prefix "dynamic_cast" "static_cast"
970 "reinterpret_cast" "const_cast" "typeid")))
972 ,@(unless (c-major-mode-is 'java-mode
)
974 (postfix "++" "--" "[" "]" "(" ")"
975 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
976 '("<:" ":>" "??(" "??)")))
979 (prefix "++" "--" "+" "-" "!" "~"
980 ,@(when (c-major-mode-is 'c
++-mode
) '("not" "compl"))
981 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
982 '("*" "&" "sizeof" "??-"))
983 ,@(when (c-major-mode-is 'objc-mode
)
984 '("@selector" "@protocol" "@encode"))
985 ;; The following need special treatment.
986 ,@(cond ((c-major-mode-is 'c
++-mode
)
988 ((c-major-mode-is 'java-mode
)
990 ((c-major-mode-is 'pike-mode
)
991 '("class" "lambda" "catch" "throw" "gauge")))
993 ,@(when (c-major-mode-is 'pike-mode
)
994 '("[" "]"))) ; Type cast.
997 ,@(when (c-major-mode-is 'c
++-mode
)
998 `((left-assoc ".*" "->*")))
1001 (left-assoc "*" "/" "%")
1004 (left-assoc "+" "-")
1007 (left-assoc "<<" ">>"
1008 ,@(when (c-major-mode-is 'java-mode
)
1012 (left-assoc "<" ">" "<=" ">="
1013 ,@(when (c-major-mode-is 'java-mode
)
1017 (left-assoc "==" "!="
1018 ,@(when (c-major-mode-is 'c
++-mode
) '("not_eq")))
1022 ,@(when (c-major-mode-is 'c
++-mode
) '("bitand")))
1024 ;; Bitwise exclusive or.
1026 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
1028 ,@(when (c-major-mode-is 'c
++-mode
) '("xor")))
1032 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
1034 ,@(when (c-major-mode-is 'c
++-mode
) '("bitor")))
1038 ,@(when (c-major-mode-is 'c
++-mode
) '("and")))
1042 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
1044 ,@(when (c-major-mode-is 'c
++-mode
) '("or")))
1047 (right-assoc-sequence "?" ":")
1050 (right-assoc ,@(c-lang-const c-assignment-operators
))
1053 ,@(when (c-major-mode-is 'c
++-mode
)
1054 '((prefix "throw")))
1059 ;; IDL got its own definition since it has a much smaller operator
1060 ;; set than the other languages.
1061 idl
`(;; Preprocessor.
1065 ,@(c-lang-const c-identifier-ops
)
1067 (prefix "+" "-" "~")
1069 (left-assoc "*" "/" "%")
1071 (left-assoc "+" "-")
1073 (left-assoc "<<" ">>")
1081 (c-lang-defconst c-operator-list
1082 ;; The operators as a flat list (without duplicates).
1083 t
(c-filter-ops (c-lang-const c-operators
) t t
))
1085 (c-lang-defconst c-overloadable-operators
1086 "List of the operators that are overloadable, in their \"identifier
1087 form\". See also `c-op-identifier-prefix'."
1089 c
++ '("new" "delete" ;; Can be followed by "[]" but we ignore that.
1091 "^" "??'" "xor" "&" "bitand" "|" "??!" "bitor" "~" "??-" "compl"
1092 "!" "=" "<" ">" "+=" "-=" "*=" "/=" "%=" "^="
1093 "??'=" "xor_eq" "&=" "and_eq" "|=" "??!=" "or_eq"
1094 "<<" ">>" ">>=" "<<=" "==" "!=" "not_eq" "<=" ">="
1095 "&&" "and" "||" "??!??!" "or" "++" "--" "," "->*" "->"
1096 "()" "[]" "<::>" "??(??)")
1097 ;; These work like identifiers in Pike.
1098 pike
'("`+" "`-" "`&" "`|" "`^" "`<<" "`>>" "`*" "`/" "`%" "`~"
1099 "`==" "`<" "`>" "`!" "`[]" "`[]=" "`->" "`->=" "`()" "``+"
1100 "``-" "``&" "``|" "``^" "``<<" "``>>" "``*" "``/" "``%"
1103 (c-lang-defconst c-overloadable-operators-regexp
1104 ;; Regexp tested after an "operator" token in C++.
1106 c
++ (c-make-keywords-re nil
(c-lang-const c-overloadable-operators
)))
1107 (c-lang-defvar c-overloadable-operators-regexp
1108 (c-lang-const c-overloadable-operators-regexp
))
1110 (c-lang-defconst c-opt-op-identifier-prefix
1111 "Regexp matching the token before the ones in
1112 `c-overloadable-operators' when operators are specified in their
1113 \"identifier form\". This typically matches \"operator\" in C++ where
1114 operator functions are specified as e.g. \"operator +\". It's nil in
1115 languages without operator functions or where the complete operator
1116 identifier is listed in `c-overloadable-operators'.
1118 This regexp is assumed to not match any non-operator identifier."
1120 c
++ (c-make-keywords-re t
'("operator")))
1121 (c-lang-defvar c-opt-op-identifier-prefix
1122 (c-lang-const c-opt-op-identifier-prefix
))
1124 ;; Note: the following alias is an old name which was a mis-spelling. It has
1125 ;; been corrected above and throughout cc-engine.el. It will be removed at
1126 ;; some release very shortly in the future. ACM, 2006-04-14.
1127 (defvaralias 'c-opt-op-identitier-prefix
'c-opt-op-identifier-prefix
)
1128 (make-obsolete-variable 'c-opt-op-identitier-prefix
'c-opt-op-identifier-prefix
1129 "CC Mode 5.31.4, 2006-04-14")
1131 (c-lang-defconst c-other-op-syntax-tokens
1132 "List of the tokens made up of characters in the punctuation or
1133 parenthesis syntax classes that have uses other than as expression
1135 t
'("{" "}" "(" ")" "[" "]" ";" ":" "," "=" "/*" "*/" "//")
1136 (c c
++ pike
) (append '("#" "##" ; Used by cpp.
1138 (c-lang-const c-other-op-syntax-tokens
))
1139 (c c
++) (append '("*") (c-lang-const c-other-op-syntax-tokens
))
1140 c
++ (append '("&" "<%" "%>" "<:" ":>" "%:" "%:%:")
1141 (c-lang-const c-other-op-syntax-tokens
))
1142 objc
(append '("#" "##" ; Used by cpp.
1143 "+" "-") (c-lang-const c-other-op-syntax-tokens
))
1144 idl
(append '("#" "##") ; Used by cpp.
1145 (c-lang-const c-other-op-syntax-tokens
))
1146 pike
(append '("..")
1147 (c-lang-const c-other-op-syntax-tokens
)
1148 (c-lang-const c-overloadable-operators
))
1149 awk
'("{" "}" "(" ")" "[" "]" ";" "," "=" "/"))
1151 (c-lang-defconst c-all-op-syntax-tokens
1152 ;; List of all tokens in the punctuation and parenthesis syntax
1154 t
(cl-delete-duplicates (append (c-lang-const c-other-op-syntax-tokens
)
1155 (c-lang-const c-operator-list
))
1156 :test
'string-equal
))
1158 (c-lang-defconst c-nonsymbol-token-char-list
1159 ;; List containing all chars not in the word, symbol or
1160 ;; syntactically irrelevant syntax classes, i.e. all punctuation,
1161 ;; parenthesis and string delimiter chars.
1162 t
(c-with-syntax-table (c-lang-const c-mode-syntax-table
)
1163 ;; Only go through the chars in the printable ASCII range. No
1164 ;; language so far has 8-bit or widestring operators.
1165 (let (list (char 32))
1167 (or (memq (char-syntax char
) '(?w ?_ ?
< ?
> ?\
))
1168 (setq list
(cons (c-int-to-char char
) list
)))
1169 (setq char
(1+ char
)))
1172 (c-lang-defconst c-nonsymbol-token-regexp
1173 ;; Regexp matching all tokens in the punctuation and parenthesis
1174 ;; syntax classes. Note that this also matches ".", which can start
1176 t
(c-make-keywords-re nil
1177 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
1179 "\\`\\(\\s.\\|\\s\(\\|\\s\)\\)+\\'")))
1180 (c-lang-defvar c-nonsymbol-token-regexp
1181 (c-lang-const c-nonsymbol-token-regexp
))
1183 (c-lang-defconst c-assignment-op-regexp
1184 ;; Regexp matching all assignment operators and only them. The
1185 ;; beginning of the first submatch is used to detect the end of the
1186 ;; token, along with the end of the whole match.
1187 t
(if (c-lang-const c-assignment-operators
)
1189 ;; Need special case for "=" since it's a prefix of "==".
1192 (c-make-keywords-re nil
1193 (set-difference (c-lang-const c-assignment-operators
)
1195 :test
'string-equal
)))
1197 (c-lang-defvar c-assignment-op-regexp
1198 (c-lang-const c-assignment-op-regexp
))
1200 (c-lang-defconst c-
<>-multichar-token-regexp
1201 ;; Regexp matching all tokens containing "<" or ">" which are longer
1203 t
(c-make-keywords-re nil
1204 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
1207 (c-lang-defvar c-
<>-multichar-token-regexp
1208 (c-lang-const c-
<>-multichar-token-regexp
))
1210 (c-lang-defconst c-
<-op-cont-regexp
1211 ;; Regexp matching the second and subsequent characters of all
1212 ;; multicharacter tokens that begin with "<".
1213 t
(c-make-keywords-re nil
1214 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
1217 (lambda (op) (substring op
1)))))
1219 (c-lang-defvar c-
<-op-cont-regexp
(c-lang-const c-
<-op-cont-regexp
))
1221 (c-lang-defconst c-
>-op-cont-regexp
1222 ;; Regexp matching the second and subsequent characters of all
1223 ;; multicharacter tokens that begin with ">".
1224 t
(c-make-keywords-re nil
1225 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
1228 (lambda (op) (substring op
1))))
1229 java
(c-make-keywords-re nil
1230 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
1232 "\\`>[^>]\\|\\`>>[^>]"
1233 (lambda (op) (substring op
1)))))
1235 (c-lang-defvar c-
>-op-cont-regexp
(c-lang-const c-
>-op-cont-regexp
))
1237 (c-lang-defconst c-stmt-delim-chars
1238 ;; The characters that should be considered to bound statements. To
1239 ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to
1240 ;; begin with "^" to negate the set. If ? : operators should be
1241 ;; detected then the string must end with "?:".
1243 (c-lang-defvar c-stmt-delim-chars
(c-lang-const c-stmt-delim-chars
))
1245 (c-lang-defconst c-stmt-delim-chars-with-comma
1246 ;; Variant of `c-stmt-delim-chars' that additionally contains ','.
1248 (c-lang-defvar c-stmt-delim-chars-with-comma
1249 (c-lang-const c-stmt-delim-chars-with-comma
))
1252 ;;; Syntactic whitespace.
1254 (c-lang-defconst c-simple-ws
1255 "Regexp matching an ordinary whitespace character.
1256 Does not contain a \\| operator at the top level."
1257 ;; "\\s " is not enough since it doesn't match line breaks.
1258 t
"\\(\\s \\|[\n\r]\\)")
1260 (c-lang-defconst c-simple-ws-depth
1261 ;; Number of regexp grouping parens in `c-simple-ws'.
1262 t
(regexp-opt-depth (c-lang-const c-simple-ws
)))
1264 (c-lang-defconst c-line-comment-starter
1265 "String that starts line comments, or nil if such don't exist.
1266 Line comments are always terminated by newlines. At least one of
1267 `c-block-comment-starter' and this one is assumed to be set.
1269 Note that it's currently not enough to set this to support a new
1270 comment style. Other stuff like the syntax table must also be set up
1274 (c-lang-defvar c-line-comment-starter
(c-lang-const c-line-comment-starter
))
1276 (c-lang-defconst c-block-comment-starter
1277 "String that starts block comments, or nil if such don't exist.
1278 Block comments are ended by `c-block-comment-ender', which is assumed
1279 to be set if this is. At least one of `c-line-comment-starter' and
1280 this one is assumed to be set.
1282 Note that it's currently not enough to set this to support a new
1283 comment style. Other stuff like the syntax table must also be set up
1288 (c-lang-defconst c-block-comment-ender
1289 "String that ends block comments, or nil if such don't exist.
1291 Note that it's currently not enough to set this to support a new
1292 comment style. Other stuff like the syntax table must also be set up
1297 (c-lang-defconst c-comment-start-regexp
1298 ;; Regexp to match the start of any type of comment.
1299 t
(let ((re (c-make-keywords-re nil
1300 (list (c-lang-const c-line-comment-starter
)
1301 (c-lang-const c-block-comment-starter
)))))
1302 (if (memq 'gen-comment-delim c-emacs-features
)
1303 (concat re
"\\|\\s!")
1305 (c-lang-defvar c-comment-start-regexp
(c-lang-const c-comment-start-regexp
))
1307 (c-lang-defconst c-block-comment-start-regexp
1308 ;; Regexp which matches the start of a block comment (if such exists in the
1310 t
(if (c-lang-const c-block-comment-starter
)
1311 (regexp-quote (c-lang-const c-block-comment-starter
))
1313 (c-lang-defvar c-block-comment-start-regexp
1314 (c-lang-const c-block-comment-start-regexp
))
1316 (c-lang-defconst c-line-comment-start-regexp
1317 ;; Regexp which matches the start of a line comment (if such exists in the
1318 ;; language; it does in all 7 CC Mode languages).
1319 t
(if (c-lang-const c-line-comment-starter
)
1320 (regexp-quote (c-lang-const c-line-comment-starter
))
1322 (c-lang-defvar c-line-comment-start-regexp
1323 (c-lang-const c-line-comment-start-regexp
))
1325 (c-lang-defconst c-literal-start-regexp
1326 ;; Regexp to match the start of comments and string literals.
1327 t
(concat (c-lang-const c-comment-start-regexp
)
1329 (if (memq 'gen-string-delim c-emacs-features
)
1332 (c-lang-defvar c-literal-start-regexp
(c-lang-const c-literal-start-regexp
))
1334 (c-lang-defconst c-doc-comment-start-regexp
1335 "Regexp to match the start of documentation comments."
1337 ;; From font-lock.el: `doxygen' uses /*! while others use /**.
1338 (c c
++ objc
) "/\\*[*!]"
1341 (c-lang-defvar c-doc-comment-start-regexp
1342 (c-lang-const c-doc-comment-start-regexp
))
1344 (c-lang-defconst comment-start
1345 "String that starts comments inserted with M-; etc.
1346 `comment-start' is initialized from this."
1347 ;; Default: Prefer line comments to block comments, and pad with a space.
1348 t
(concat (or (c-lang-const c-line-comment-starter
)
1349 (c-lang-const c-block-comment-starter
))
1351 ;; In C we still default to the block comment style since line
1352 ;; comments aren't entirely portable.
1354 (c-lang-setvar comment-start
(c-lang-const comment-start
))
1356 (c-lang-defconst comment-end
1357 "String that ends comments inserted with M-; etc.
1358 `comment-end' is initialized from this."
1359 ;; Default: Use block comment style if comment-start uses block
1360 ;; comments, and pad with a space in that case.
1361 t
(if (string-match (concat "\\`\\("
1362 (c-lang-const c-block-comment-start-regexp
)
1364 (c-lang-const comment-start
))
1365 (concat " " (c-lang-const c-block-comment-ender
))
1367 (c-lang-setvar comment-end
(c-lang-const comment-end
))
1369 (c-lang-defconst comment-start-skip
1370 "Regexp to match the start of a comment plus everything up to its body.
1371 `comment-start-skip' is initialized from this."
1372 ;; Default: Allow the last char of the comment starter(s) to be
1373 ;; repeated, then allow any amount of horizontal whitespace.
1376 (mapcar (lambda (cs)
1378 (concat (regexp-quote cs
) "+")))
1379 (list (c-lang-const c-line-comment-starter
)
1380 (c-lang-const c-block-comment-starter
)))
1383 (c-lang-setvar comment-start-skip
(c-lang-const comment-start-skip
))
1385 (c-lang-defconst c-syntactic-ws-start
1386 ;; Regexp matching any sequence that can start syntactic whitespace.
1387 ;; The only uncertain case is '#' when there are cpp directives.
1389 (c-make-keywords-re nil
1390 (append (list (c-lang-const c-line-comment-starter
)
1391 (c-lang-const c-block-comment-starter
)
1392 (when (c-lang-const c-opt-cpp-prefix
)
1396 (when (memq 'gen-comment-delim c-emacs-features
)
1398 (c-lang-defvar c-syntactic-ws-start
(c-lang-const c-syntactic-ws-start
))
1400 (c-lang-defconst c-syntactic-ws-end
1401 ;; Regexp matching any single character that might end syntactic whitespace.
1403 (c-make-keywords-re nil
1404 (append (when (c-lang-const c-block-comment-ender
)
1407 (elt (c-lang-const c-block-comment-ender
)
1409 (c-lang-const c-block-comment-ender
)))))))
1411 (when (memq 'gen-comment-delim c-emacs-features
)
1413 (c-lang-defvar c-syntactic-ws-end
(c-lang-const c-syntactic-ws-end
))
1415 (c-lang-defconst c-unterminated-block-comment-regexp
1416 ;; Regexp matching an unterminated block comment that doesn't
1417 ;; contain line breaks, or nil in languages without block comments.
1418 ;; Does not contain a \| operator at the top level.
1419 t
(when (c-lang-const c-block-comment-starter
)
1421 (regexp-quote (c-lang-const c-block-comment-starter
))
1422 ;; It's messy to cook together a regexp that matches anything
1423 ;; but c-block-comment-ender.
1424 (let ((end (c-lang-const c-block-comment-ender
)))
1425 (cond ((= (length end
) 1)
1426 (concat "[^" end
"\n\r]*"))
1428 (concat "[^" (substring end
0 1) "\n\r]*"
1430 (regexp-quote (substring end
0 1)) "+"
1432 ;; The quoting rules inside char classes are silly. :P
1433 (cond ((= (elt end
0) (elt end
1))
1434 (concat (substring end
0 1) "\n\r"))
1435 ((= (elt end
1) ?\
])
1436 (concat (substring end
1 2) "\n\r"
1437 (substring end
0 1)))
1439 (concat (substring end
0 1) "\n\r"
1440 (substring end
1 2))))
1442 "[^" (substring end
0 1) "\n\r]*"
1445 (error "Can't handle a block comment ender of length %s"
1448 (c-lang-defconst c-block-comment-regexp
1449 ;; Regexp matching a block comment that doesn't contain line breaks,
1450 ;; or nil in languages without block comments. The reason we don't
1451 ;; allow line breaks is to avoid going very far and risk running out
1452 ;; of regexp stack; this regexp is intended to handle only short
1453 ;; comments that might be put in the middle of limited constructs
1454 ;; like declarations. Does not contain a \| operator at the top
1456 t
(when (c-lang-const c-unterminated-block-comment-regexp
)
1458 (c-lang-const c-unterminated-block-comment-regexp
)
1459 (let ((end (c-lang-const c-block-comment-ender
)))
1460 (cond ((= (length end
) 1)
1463 (concat (regexp-quote (substring end
0 1)) "+"
1464 (regexp-quote (substring end
1 2))))
1466 (error "Can't handle a block comment ender of length %s"
1469 (c-lang-defconst c-nonwhite-syntactic-ws
1470 ;; Regexp matching a piece of syntactic whitespace that isn't a
1471 ;; sequence of simple whitespace characters. As opposed to
1472 ;; `c-(forward|backward)-syntactic-ws', this doesn't regard cpp
1473 ;; directives as syntactic whitespace.
1474 t
(c-concat-separated
1475 (list (when (c-lang-const c-line-comment-starter
)
1476 (concat (regexp-quote (c-lang-const c-line-comment-starter
))
1478 (c-lang-const c-block-comment-regexp
)
1480 (when (memq 'gen-comment-delim c-emacs-features
)
1484 (c-lang-defconst c-syntactic-ws
1485 ;; Regexp matching syntactic whitespace, including possibly the
1486 ;; empty string. As opposed to `c-(forward|backward)-syntactic-ws',
1487 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1488 ;; not contain a \| operator at the top level.
1489 t
(concat (c-lang-const c-simple-ws
) "*"
1491 (concat "\\(" (c-lang-const c-nonwhite-syntactic-ws
) "\\)"
1492 (c-lang-const c-simple-ws
) "*")
1495 (c-lang-defconst c-syntactic-ws-depth
1496 ;; Number of regexp grouping parens in `c-syntactic-ws'.
1497 t
(regexp-opt-depth (c-lang-const c-syntactic-ws
)))
1499 (c-lang-defconst c-nonempty-syntactic-ws
1500 ;; Regexp matching syntactic whitespace, which is at least one
1501 ;; character long. As opposed to `c-(forward|backward)-syntactic-ws',
1502 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1503 ;; not contain a \| operator at the top level.
1505 (c-lang-const c-simple-ws
)
1507 (c-lang-const c-nonwhite-syntactic-ws
)
1510 (c-lang-defconst c-nonempty-syntactic-ws-depth
1511 ;; Number of regexp grouping parens in `c-nonempty-syntactic-ws'.
1512 t
(regexp-opt-depth (c-lang-const c-nonempty-syntactic-ws
)))
1514 (c-lang-defconst c-single-line-syntactic-ws
1515 ;; Regexp matching syntactic whitespace without any line breaks. As
1516 ;; opposed to `c-(forward|backward)-syntactic-ws', this doesn't
1517 ;; regard cpp directives as syntactic whitespace. Does not contain
1518 ;; a \| operator at the top level.
1519 t
(if (c-lang-const c-block-comment-regexp
)
1521 (c-lang-const c-block-comment-regexp
)
1525 (c-lang-defconst c-single-line-syntactic-ws-depth
1526 ;; Number of regexp grouping parens in `c-single-line-syntactic-ws'.
1527 t
(regexp-opt-depth (c-lang-const c-single-line-syntactic-ws
)))
1529 (c-lang-defconst c-syntactic-eol
1530 ;; Regexp that matches when there is no syntactically significant
1531 ;; text before eol. Macros are regarded as syntactically
1532 ;; significant text here.
1533 t
(concat (c-lang-const c-single-line-syntactic-ws
)
1534 ;; Match eol (possibly inside a block comment or preceded
1535 ;; by a line continuation backslash), or the beginning of a
1536 ;; line comment. Note: This has to be modified for awk
1537 ;; where line comments start with '#'.
1540 (list (when (c-lang-const c-line-comment-starter
)
1541 (regexp-quote (c-lang-const c-line-comment-starter
)))
1542 (when (c-lang-const c-unterminated-block-comment-regexp
)
1543 (concat (c-lang-const c-unterminated-block-comment-regexp
)
1549 (c-lang-defvar c-syntactic-eol
(c-lang-const c-syntactic-eol
))
1554 ;; The Emacs variables beginning-of-defun-function and
1555 ;; end-of-defun-function will be set so that commands like
1556 ;; `mark-defun' and `narrow-to-defun' work right. The key sequences
1557 ;; C-M-a and C-M-e are, however, bound directly to the CC Mode
1558 ;; functions, allowing optimization for large n.
1559 (c-lang-defconst beginning-of-defun-function
1560 "Function to which beginning-of-defun-function will be set."
1561 t
'c-beginning-of-defun
1562 awk
'c-awk-beginning-of-defun
)
1563 (c-lang-setvar beginning-of-defun-function
1564 (c-lang-const beginning-of-defun-function
))
1566 (c-lang-defconst end-of-defun-function
1567 "Function to which end-of-defun-function will be set."
1569 awk
'c-awk-end-of-defun
)
1570 (c-lang-setvar end-of-defun-function
(c-lang-const end-of-defun-function
))
1572 ;;; In-comment text handling.
1574 (c-lang-defconst c-paragraph-start
1575 "Regexp to append to `paragraph-start'."
1577 java
"\\(@[a-zA-Z]+\\>\\|$\\)" ; For Javadoc.
1578 pike
"\\(@[a-zA-Z_-]+\\>\\([^{]\\|$\\)\\|$\\)") ; For Pike refdoc.
1579 (c-lang-defvar c-paragraph-start
(c-lang-const c-paragraph-start
))
1581 (c-lang-defconst c-paragraph-separate
1582 "Regexp to append to `paragraph-separate'."
1584 pike
(c-lang-const c-paragraph-start
))
1585 (c-lang-defvar c-paragraph-separate
(c-lang-const c-paragraph-separate
))
1590 ;; Note: All and only all language constants containing keyword lists
1591 ;; should end with "-kwds"; they're automatically collected into the
1592 ;; `c-kwds-lang-consts' list below and used to build `c-keywords' etc.
1594 (c-lang-defconst c-primitive-type-kwds
1595 "Primitive type keywords. As opposed to the other keyword lists, the
1596 keywords listed here are fontified with the type face instead of the
1599 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1600 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1601 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1604 Do not try to modify this list for end user customizations; the
1605 `*-font-lock-extra-types' variable, where `*' is the mode prefix, is
1606 the appropriate place for that."
1607 t
'("char" "double" "float" "int" "long" "short" "signed"
1610 '("_Bool" "_Complex" "_Imaginary") ; Conditionally defined in C99.
1611 (c-lang-const c-primitive-type-kwds
))
1614 (c-lang-const c-primitive-type-kwds
))
1615 ;; Objective-C extends C, but probably not the new stuff in C99.
1617 '("id" "Class" "SEL" "IMP" "BOOL")
1618 (c-lang-const c-primitive-type-kwds
))
1619 java
'("boolean" "byte" "char" "double" "float" "int" "long" "short" "void")
1620 idl
'("Object" "ValueBase" "any" "boolean" "char" "double" "fixed" "float"
1621 "long" "octet" "sequence" "short" "string" "void" "wchar" "wstring"
1624 ;; The following can't really end a type, but we have to specify them
1625 ;; here due to the assumption in `c-primitive-type-prefix-kwds'. It
1626 ;; doesn't matter that much.
1627 "unsigned" "strong")
1628 pike
'(;; this_program isn't really a keyword, but it's practically
1629 ;; used as a builtin type.
1630 "array" "float" "function" "int" "mapping" "mixed" "multiset"
1631 "object" "program" "string" "this_program" "void"))
1633 (c-lang-defconst c-primitive-type-key
1634 ;; An adorned regexp that matches `c-primitive-type-kwds'.
1635 t
(c-make-keywords-re t
(c-lang-const c-primitive-type-kwds
)))
1636 (c-lang-defvar c-primitive-type-key
(c-lang-const c-primitive-type-key
))
1638 (c-lang-defconst c-primitive-type-prefix-kwds
1639 "Keywords that might act as prefixes for primitive types. Assumed to
1640 be a subset of `c-primitive-type-kwds'."
1642 (c c
++) '("long" "short" "signed" "unsigned")
1643 idl
'("long" "unsigned"
1647 (c-lang-defconst c-typedef-kwds
1648 "Prefix keyword\(s\) like \"typedef\" which make a type declaration out
1649 of a variable declaration."
1653 (c-lang-defconst c-typedef-key
1654 ;; Adorned regexp matching `c-typedef-kwds'.
1655 t
(c-make-keywords-re t
(c-lang-const c-typedef-kwds
)))
1656 (c-lang-defvar c-typedef-key
(c-lang-const c-typedef-key
))
1658 (c-lang-defconst c-type-prefix-kwds
1659 "Keywords where the following name - if any - is a type name, and
1660 where the keyword together with the symbol works as a type in
1663 Note that an alternative if the second part doesn't hold is
1664 `c-type-list-kwds'. Keywords on this list are typically also present
1665 on one of the `*-decl-kwds' lists."
1667 c
'("struct" "union" "enum")
1668 c
++ (append '("class" "typename")
1669 (c-lang-const c-type-prefix-kwds c
)))
1671 (c-lang-defconst c-type-prefix-key
1672 ;; Adorned regexp matching `c-type-prefix-kwds'.
1673 t
(c-make-keywords-re t
(c-lang-const c-type-prefix-kwds
)))
1674 (c-lang-defvar c-type-prefix-key
(c-lang-const c-type-prefix-key
))
1676 (c-lang-defconst c-type-modifier-kwds
1677 "Type modifier keywords. These can occur almost anywhere in types
1678 but they don't build a type of themselves. Unlike the keywords on
1679 `c-primitive-type-kwds', they are fontified with the keyword face and
1682 c
'("const" "restrict" "volatile")
1683 c
++ '("const" "volatile" "throw")
1684 objc
'("const" "volatile"))
1686 (c-lang-defconst c-opt-type-modifier-key
1687 ;; Adorned regexp matching `c-type-modifier-kwds', or nil in
1688 ;; languages without such keywords.
1689 t
(and (c-lang-const c-type-modifier-kwds
)
1690 (c-make-keywords-re t
(c-lang-const c-type-modifier-kwds
))))
1691 (c-lang-defvar c-opt-type-modifier-key
(c-lang-const c-opt-type-modifier-key
))
1693 (c-lang-defconst c-opt-type-component-key
1694 ;; An adorned regexp that matches `c-primitive-type-prefix-kwds' and
1695 ;; `c-type-modifier-kwds', or nil in languages without any of them.
1696 t
(and (or (c-lang-const c-primitive-type-prefix-kwds
)
1697 (c-lang-const c-type-modifier-kwds
))
1698 (c-make-keywords-re t
1699 (append (c-lang-const c-primitive-type-prefix-kwds
)
1700 (c-lang-const c-type-modifier-kwds
)))))
1701 (c-lang-defvar c-opt-type-component-key
1702 (c-lang-const c-opt-type-component-key
))
1704 (c-lang-defconst c-type-start-kwds
1705 ;; All keywords that can start a type (i.e. are either a type prefix
1706 ;; or a complete type).
1707 t
(cl-delete-duplicates (append (c-lang-const c-primitive-type-kwds
)
1708 (c-lang-const c-type-prefix-kwds
)
1709 (c-lang-const c-type-modifier-kwds
))
1710 :test
'string-equal
))
1712 (c-lang-defconst c-class-decl-kwds
1713 "Keywords introducing declarations where the following block (if any)
1714 contains another declaration level that should be considered a class.
1716 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1717 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1718 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1721 Note that presence on this list does not automatically treat the
1722 following identifier as a type; the keyword must also be present on
1723 `c-type-prefix-kwds' or `c-type-list-kwds' to accomplish that."
1725 c
'("struct" "union")
1726 c
++ '("class" "struct" "union")
1727 objc
'("struct" "union"
1728 "@interface" "@implementation" "@protocol")
1729 java
'("class" "@interface" "interface")
1730 idl
'("component" "eventtype" "exception" "home" "interface" "struct"
1733 "storagehome" "storagetype"
1735 "catalog" "executor" "manages" "segment")
1738 (c-lang-defconst c-class-key
1739 ;; Regexp matching the start of a class.
1740 t
(c-make-keywords-re t
(c-lang-const c-class-decl-kwds
)))
1741 (c-lang-defvar c-class-key
(c-lang-const c-class-key
))
1743 (c-lang-defconst c-brace-list-decl-kwds
1744 "Keywords introducing declarations where the following block (if
1745 any) is a brace list.
1747 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1748 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1749 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1754 (c-lang-defconst c-brace-list-key
1755 ;; Regexp matching the start of declarations where the following
1756 ;; block is a brace list.
1757 t
(c-make-keywords-re t
(c-lang-const c-brace-list-decl-kwds
)))
1758 (c-lang-defvar c-brace-list-key
(c-lang-const c-brace-list-key
))
1760 (c-lang-defconst c-other-block-decl-kwds
1761 "Keywords where the following block (if any) contains another
1762 declaration level that should not be considered a class. For every
1763 keyword here, CC Mode will add a set of special syntactic symbols for
1764 those blocks. E.g. if the keyword is \"foo\" then there will be
1765 `foo-open', `foo-close', and `infoo' symbols.
1767 The intention is that this category should be used for block
1768 constructs that aren't related to object orientation concepts like
1769 classes (which thus also include e.g. interfaces, templates,
1770 contracts, structs, etc). The more pragmatic distinction is that
1771 while most want some indentation inside classes, it's fairly common
1772 that they don't want it in some of these constructs, so it should be
1773 simple to configure that differently from classes. See also
1774 `c-class-decl-kwds'.
1776 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1777 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1778 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1781 (c objc
) '("extern")
1782 c
++ '("namespace" "extern")
1787 (c-lang-defconst c-other-decl-block-key
1788 ;; Regexp matching the start of blocks besides classes that contain
1789 ;; another declaration level.
1790 t
(c-make-keywords-re t
(c-lang-const c-other-block-decl-kwds
)))
1791 (c-lang-defvar c-other-decl-block-key
(c-lang-const c-other-decl-block-key
))
1793 (c-lang-defvar c-other-decl-block-key-in-symbols-alist
1797 (if (string= elt
"extern")
1799 (intern (concat "in" elt
)))))
1800 (c-lang-const c-other-block-decl-kwds
))
1801 "Alist associating keywords in c-other-decl-block-decl-kwds with
1802 their matching \"in\" syntactic symbols.")
1804 (c-lang-defconst c-typedef-decl-kwds
1805 "Keywords introducing declarations where the identifier(s) being
1808 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1809 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1810 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1812 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1813 ;; (since e.g. "Foo" is a type that's being defined in "class Foo
1815 t
(append (c-lang-const c-class-decl-kwds
)
1816 (c-lang-const c-brace-list-decl-kwds
))
1817 ;; Languages that have a "typedef" construct.
1818 (c c
++ objc idl pike
) (append (c-lang-const c-typedef-decl-kwds
)
1820 ;; Unlike most other languages, exception names are not handled as
1821 ;; types in IDL since they only can occur in "raises" specs.
1822 idl
(delete "exception" (append (c-lang-const c-typedef-decl-kwds
) nil
)))
1824 (c-lang-defconst c-typedef-decl-key
1825 t
(c-make-keywords-re t
(c-lang-const c-typedef-decl-kwds
)))
1826 (c-lang-defvar c-typedef-decl-key
(c-lang-const c-typedef-decl-key
))
1828 (c-lang-defconst c-typeless-decl-kwds
1829 "Keywords introducing declarations where the \(first) identifier
1830 \(declarator) follows directly after the keyword, without any type.
1832 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1833 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1834 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1836 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1837 ;; (since e.g. "Foo" is the identifier being defined in "class Foo
1839 t
(append (c-lang-const c-class-decl-kwds
)
1840 (c-lang-const c-brace-list-decl-kwds
))
1841 ;; Note: "manages" for CORBA CIDL clashes with its presence on
1842 ;; `c-type-list-kwds' for IDL.
1843 idl
(append (c-lang-const c-typeless-decl-kwds
)
1844 '("factory" "finder" "native"
1849 pike
(append (c-lang-const c-class-decl-kwds
)
1852 (c-lang-defconst c-modifier-kwds
1853 "Keywords that can prefix normal declarations of identifiers
1854 \(and typically act as flags). Things like argument declarations
1855 inside function headers are also considered declarations in this
1858 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1859 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1860 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1863 (c c
++) '("auto" "extern" "inline" "register" "static")
1864 c
++ (append '("explicit" "friend" "mutable" "template" "using" "virtual")
1865 (c-lang-const c-modifier-kwds
))
1866 objc
'("auto" "bycopy" "byref" "extern" "in" "inout" "oneway" "out" "static")
1867 ;; FIXME: Some of those below ought to be on `c-other-decl-kwds' instead.
1868 idl
'("abstract" "attribute" "const" "consumes" "custom" "emits" "import"
1869 "in" "inout" "local" "multiple" "oneway" "out" "private" "provides"
1870 "public" "publishes" "readonly" "typeid" "typeprefix" "uses"
1874 "bindsTo" "delegatesTo" "implements" "proxy" "storedOn")
1875 ;; Note: "const" is not used in Java, but it's still a reserved keyword.
1876 java
'("abstract" "const" "final" "native" "private" "protected" "public"
1877 "static" "strictfp" "synchronized" "transient" "volatile")
1878 pike
'("final" "inline" "local" "nomask" "optional" "private" "protected"
1879 "public" "static" "variant"))
1881 (c-lang-defconst c-other-decl-kwds
1882 "Keywords that can start or prefix any declaration level construct,
1883 besides those on `c-class-decl-kwds', `c-brace-list-decl-kwds',
1884 `c-other-block-decl-kwds', `c-typedef-decl-kwds',
1885 `c-typeless-decl-kwds' and `c-modifier-kwds'.
1887 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1888 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1889 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1892 objc
'("@class" "@end" "@defs")
1893 java
'("import" "package")
1894 pike
'("import" "inherit"))
1896 (c-lang-defconst c-decl-start-kwds
1897 "Keywords that always start declarations, wherever they occur.
1898 This can be used for declarations that aren't recognized by the normal
1899 combination of `c-decl-prefix-re' and `c-decl-start-re'."
1901 ;; Classes can be declared anywhere in a Pike expression.
1904 (c-lang-defconst c-decl-hangon-kwds
1905 "Keywords that can occur anywhere in a declaration level construct.
1906 This is used for self-contained things that can be tacked on anywhere
1907 on a declaration and that should be ignored to be able to recognize it
1908 correctly. Typical cases are compiler extensions like
1909 \"__attribute__\" or \"__declspec\":
1911 __declspec(noreturn) void foo();
1912 class __declspec(dllexport) classname {...};
1913 void foo() __attribute__((noreturn));
1915 Note that unrecognized plain symbols are skipped anyway if they occur
1916 before the type, so such things are not necessary to mention here.
1917 Mentioning them here is necessary only if they can occur in other
1918 places, or if they are followed by a construct that must be skipped
1919 over \(like the parens in the \"__attribute__\" and \"__declspec\"
1920 examples above). In the last case, they alse need to be present on
1921 one of `c-type-list-kwds', `c-ref-list-kwds',
1922 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1923 `c-<>-type-kwds', or `c-<>-arglist-kwds'."
1924 ;; NB: These are currently not recognized in all parts of a
1925 ;; declaration. Specifically, they aren't recognized in the middle
1926 ;; of multi-token types, inside declarators, and between the
1927 ;; identifier and the arglist paren of a function declaration.
1929 ;; FIXME: This ought to be user customizable since compiler stuff
1930 ;; like this usually is wrapped in project specific macros. (It'd
1931 ;; of course be even better if we could cope without knowing this.)
1933 (c c
++) '(;; GCC extension.
1938 (c-lang-defconst c-decl-hangon-key
1939 ;; Adorned regexp matching `c-decl-hangon-kwds'.
1940 t
(c-make-keywords-re t
(c-lang-const c-decl-hangon-kwds
)))
1941 (c-lang-defvar c-decl-hangon-key
(c-lang-const c-decl-hangon-key
))
1943 (c-lang-defconst c-prefix-spec-kwds
1944 ;; All keywords that can occur in the preamble of a declaration.
1945 ;; They typically occur before the type, but they are also matched
1946 ;; after presumptive types since we often can't be sure that
1947 ;; something is a type or just some sort of macro in front of the
1948 ;; declaration. They might be ambiguous with types or type
1950 t
(cl-delete-duplicates (append (c-lang-const c-class-decl-kwds
)
1951 (c-lang-const c-brace-list-decl-kwds
)
1952 (c-lang-const c-other-block-decl-kwds
)
1953 (c-lang-const c-typedef-decl-kwds
)
1954 (c-lang-const c-typeless-decl-kwds
)
1955 (c-lang-const c-modifier-kwds
)
1956 (c-lang-const c-other-decl-kwds
)
1957 (c-lang-const c-decl-start-kwds
)
1958 (c-lang-const c-decl-hangon-kwds
))
1959 :test
'string-equal
))
1961 (c-lang-defconst c-prefix-spec-kwds-re
1962 ;; Adorned regexp of `c-prefix-spec-kwds'.
1963 t
(c-make-keywords-re t
(c-lang-const c-prefix-spec-kwds
)))
1965 (c-lang-defvar c-prefix-spec-kwds-re
(c-lang-const c-prefix-spec-kwds-re
))
1967 (c-lang-defconst c-specifier-key
1968 ;; Adorned regexp of the keywords in `c-prefix-spec-kwds' that aren't
1969 ;; ambiguous with types or type prefixes. These are the keywords (like
1970 ;; extern, namespace, but NOT template) that can modify a declaration.
1971 t
(c-make-keywords-re t
1972 (set-difference (c-lang-const c-prefix-spec-kwds
)
1973 (append (c-lang-const c-type-start-kwds
)
1974 (c-lang-const c-
<>-arglist-kwds
))
1975 :test
'string-equal
)))
1976 (c-lang-defvar c-specifier-key
(c-lang-const c-specifier-key
))
1978 (c-lang-defconst c-postfix-spec-kwds
1979 ;; Keywords that can occur after argument list of a function header
1980 ;; declaration, i.e. in the "K&R region".
1981 t
(append (c-lang-const c-postfix-decl-spec-kwds
)
1982 (c-lang-const c-decl-hangon-kwds
)))
1984 (c-lang-defconst c-not-decl-init-keywords
1985 ;; Adorned regexp matching all keywords that can't appear at the
1986 ;; start of a declaration.
1987 t
(c-make-keywords-re t
1988 (set-difference (c-lang-const c-keywords
)
1989 (append (c-lang-const c-type-start-kwds
)
1990 (c-lang-const c-prefix-spec-kwds
))
1991 :test
'string-equal
)))
1992 (c-lang-defvar c-not-decl-init-keywords
1993 (c-lang-const c-not-decl-init-keywords
))
1995 (c-lang-defconst c-not-primitive-type-keywords
1996 "List of all keywords apart from primitive types (like \"int\")."
1997 t
(set-difference (c-lang-const c-keywords
)
1998 (c-lang-const c-primitive-type-kwds
)
1999 :test
'string-equal
)
2000 ;; The "more" for C++ is the QT keyword (as in "more slots:").
2001 ;; This variable is intended for use in c-beginning-of-statement-1.
2002 c
++ (append (c-lang-const c-not-primitive-type-keywords
) '("more")))
2004 (c-lang-defconst c-not-primitive-type-keywords-regexp
2005 t
(c-make-keywords-re t
2006 (c-lang-const c-not-primitive-type-keywords
)))
2007 (c-lang-defvar c-not-primitive-type-keywords-regexp
2008 (c-lang-const c-not-primitive-type-keywords-regexp
))
2010 (c-lang-defconst c-protection-kwds
2011 "Access protection label keywords in classes."
2013 c
++ '("private" "protected" "public")
2014 objc
'("@private" "@protected" "@public"))
2016 (c-lang-defconst c-block-decls-with-vars
2017 "Keywords introducing declarations that can contain a block which
2018 might be followed by variable declarations, e.g. like \"foo\" in
2019 \"class Foo { ... } foo;\". So if there is a block in a declaration
2020 like that, it ends with the following ';' and not right away.
2022 The keywords on list are assumed to also be present on one of the
2023 `*-decl-kwds' lists."
2025 (c objc
) '("struct" "union" "enum" "typedef")
2026 c
++ '("class" "struct" "union" "enum" "typedef"))
2028 (c-lang-defconst c-opt-block-decls-with-vars-key
2029 ;; Regexp matching the `c-block-decls-with-vars' keywords, or nil in
2030 ;; languages without such constructs.
2031 t
(and (c-lang-const c-block-decls-with-vars
)
2032 (c-make-keywords-re t
(c-lang-const c-block-decls-with-vars
))))
2033 (c-lang-defvar c-opt-block-decls-with-vars-key
2034 (c-lang-const c-opt-block-decls-with-vars-key
))
2036 (c-lang-defconst c-postfix-decl-spec-kwds
2037 "Keywords introducing extra declaration specifiers in the region
2038 between the header and the body \(i.e. the \"K&R-region\") in
2041 java
'("extends" "implements" "throws")
2042 idl
'("context" "getraises" "manages" "primarykey" "raises" "setraises"
2045 "as" "const" "implements" "of" "ref"))
2047 (c-lang-defconst c-postfix-decl-spec-key
2048 ;; Regexp matching the keywords in `c-postfix-decl-spec-kwds'.
2049 t
(c-make-keywords-re t
(c-lang-const c-postfix-decl-spec-kwds
)))
2050 (c-lang-defvar c-postfix-decl-spec-key
2051 (c-lang-const c-postfix-decl-spec-key
))
2053 (c-lang-defconst c-nonsymbol-sexp-kwds
2054 "Keywords that may be followed by a nonsymbol sexp before whatever
2055 construct it's part of continues."
2057 (c c
++ objc
) '("extern"))
2059 (c-lang-defconst c-type-list-kwds
2060 "Keywords that may be followed by a comma separated list of type
2061 identifiers, where each optionally can be prefixed by keywords. (Can
2062 also be used for the special case when the list can contain only one
2065 Assumed to be mutually exclusive with `c-ref-list-kwds'. There's no
2066 reason to put keywords on this list if they are on `c-type-prefix-kwds'.
2067 There's also no reason to add keywords that prefixes a normal
2068 declaration consisting of a type followed by a declarator (list), so
2069 the keywords on `c-modifier-kwds' should normally not be listed here
2072 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
2073 or variable identifier (that's being defined)."
2077 java
'("import" "new" "extends" "super" "implements" "throws")
2078 idl
'("manages" "native" "primarykey" "supports"
2080 "as" "implements" "of" "scope")
2083 (c-lang-defconst c-ref-list-kwds
2084 "Keywords that may be followed by a comma separated list of
2085 reference (i.e. namespace/scope/module) identifiers, where each
2086 optionally can be prefixed by keywords. (Can also be used for the
2087 special case when the list can contain only one element.) Assumed to
2088 be mutually exclusive with `c-type-list-kwds'.
2090 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
2091 or variable identifier (that's being defined)."
2095 idl
'("import" "module"
2100 (c-lang-defconst c-colon-type-list-kwds
2101 "Keywords that may be followed (not necessarily directly) by a colon
2102 and then a comma separated list of type identifiers, where each
2103 optionally can be prefixed by keywords. (Can also be used for the
2104 special case when the list can contain only one element.)"
2106 c
++ '("class" "struct")
2107 idl
'("component" "eventtype" "home" "interface" "valuetype"
2109 "storagehome" "storagetype"))
2111 (c-lang-defconst c-colon-type-list-re
2112 "Regexp matched after the keywords in `c-colon-type-list-kwds' to skip
2113 forward to the colon. The end of the match is assumed to be directly
2114 after the colon, so the regexp should end with \":\". Must be a
2115 regexp if `c-colon-type-list-kwds' isn't nil."
2116 t
(if (c-lang-const c-colon-type-list-kwds
)
2117 ;; Disallow various common punctuation chars that can't come
2118 ;; before the ":" that starts the inherit list after "class"
2119 ;; or "struct" in C++. (Also used as default for other
2121 "[^\]\[{}();,/#=:]*:"))
2122 (c-lang-defvar c-colon-type-list-re
(c-lang-const c-colon-type-list-re
))
2124 (c-lang-defconst c-paren-nontype-kwds
2125 "Keywords that may be followed by a parenthesis expression that doesn't
2126 contain type identifiers."
2128 (c c
++) '(;; GCC extension.
2133 (c-lang-defconst c-paren-type-kwds
2134 "Keywords that may be followed by a parenthesis expression containing
2135 type identifiers separated by arbitrary tokens."
2140 pike
'("array" "function" "int" "mapping" "multiset" "object" "program"))
2142 (c-lang-defconst c-paren-any-kwds
2143 t
(cl-delete-duplicates (append (c-lang-const c-paren-nontype-kwds
)
2144 (c-lang-const c-paren-type-kwds
))
2145 :test
'string-equal
))
2147 (c-lang-defconst c-
<>-type-kwds
2148 "Keywords that may be followed by an angle bracket expression
2149 containing type identifiers separated by \",\". The difference from
2150 `c-<>-arglist-kwds' is that unknown names are taken to be types and
2151 not other identifiers. `c-recognize-<>-arglists' is assumed to be set
2159 (c-lang-defconst c-
<>-arglist-kwds
2160 "Keywords that can be followed by a C++ style template arglist; see
2161 `c-recognize-<>-arglists' for details. That language constant is
2162 assumed to be set if this isn't nil."
2165 idl
'("fixed" "string" "wstring"))
2167 (c-lang-defconst c-
<>-sexp-kwds
2168 ;; All keywords that can be followed by an angle bracket sexp.
2169 t
(cl-delete-duplicates (append (c-lang-const c-
<>-type-kwds
)
2170 (c-lang-const c-
<>-arglist-kwds
))
2171 :test
'string-equal
))
2173 (c-lang-defconst c-opt-
<>-sexp-key
2174 ;; Adorned regexp matching keywords that can be followed by an angle
2175 ;; bracket sexp. Always set when `c-recognize-<>-arglists' is.
2176 t
(c-make-keywords-re t
(c-lang-const c-
<>-sexp-kwds
)))
2177 (c-lang-defvar c-opt-
<>-sexp-key
(c-lang-const c-opt-
<>-sexp-key
))
2179 (c-lang-defconst c-brace-id-list-kwds
2180 "Keywords that may be followed by a brace block containing a comma
2181 separated list of identifier definitions, i.e. like the list of
2182 identifiers that follows the type in a normal declaration."
2183 t
(c-lang-const c-brace-list-decl-kwds
))
2185 (c-lang-defconst c-block-stmt-1-kwds
2186 "Statement keywords followed directly by a substatement."
2188 c
++ '("do" "else" "try")
2189 objc
'("do" "else" "@finally" "@try")
2190 java
'("do" "else" "finally" "try")
2193 (c-lang-defconst c-block-stmt-1-key
2194 ;; Regexp matching the start of any statement followed directly by a
2195 ;; substatement (doesn't match a bare block, however).
2196 t
(c-make-keywords-re t
(c-lang-const c-block-stmt-1-kwds
)))
2197 (c-lang-defvar c-block-stmt-1-key
(c-lang-const c-block-stmt-1-key
))
2199 (c-lang-defconst c-block-stmt-1-2-kwds
2200 "Statement keywords optionally followed by a paren sexp.
2201 Keywords here should also be in `c-block-stmt-1-kwds'."
2205 (c-lang-defconst c-block-stmt-1-2-key
2206 ;; Regexp matching the start of a statement which may be followed by a
2207 ;; paren sexp and will then be followed by a substatement.
2208 t
(c-make-keywords-re t
(c-lang-const c-block-stmt-1-2-kwds
)))
2209 (c-lang-defvar c-block-stmt-1-2-key
(c-lang-const c-block-stmt-1-2-key
))
2211 (c-lang-defconst c-block-stmt-2-kwds
2212 "Statement keywords followed by a paren sexp and then by a substatement."
2213 t
'("for" "if" "switch" "while")
2214 c
++ '("for" "if" "switch" "while" "catch")
2215 objc
'("for" "if" "switch" "while" "@catch" "@synchronized")
2216 java
'("for" "if" "switch" "while" "catch" "synchronized")
2218 pike
'("for" "if" "switch" "while" "foreach")
2219 awk
'("for" "if" "while"))
2221 (c-lang-defconst c-block-stmt-2-key
2222 ;; Regexp matching the start of any statement followed by a paren sexp
2223 ;; and then by a substatement.
2224 t
(c-make-keywords-re t
(c-lang-const c-block-stmt-2-kwds
)))
2225 (c-lang-defvar c-block-stmt-2-key
(c-lang-const c-block-stmt-2-key
))
2227 (c-lang-defconst c-block-stmt-kwds
2228 ;; Union of `c-block-stmt-1-kwds' and `c-block-stmt-2-kwds'.
2229 t
(cl-delete-duplicates (append (c-lang-const c-block-stmt-1-kwds
)
2230 (c-lang-const c-block-stmt-2-kwds
))
2231 :test
'string-equal
))
2233 (c-lang-defconst c-opt-block-stmt-key
2234 ;; Regexp matching the start of any statement that has a
2235 ;; substatement (except a bare block). Nil in languages that
2236 ;; don't have such constructs.
2237 t
(if (or (c-lang-const c-block-stmt-1-kwds
)
2238 (c-lang-const c-block-stmt-2-kwds
))
2239 (c-make-keywords-re t
2240 (append (c-lang-const c-block-stmt-1-kwds
)
2241 (c-lang-const c-block-stmt-2-kwds
)))))
2242 (c-lang-defvar c-opt-block-stmt-key
(c-lang-const c-opt-block-stmt-key
))
2244 (c-lang-defconst c-simple-stmt-kwds
2245 "Statement keywords followed by an expression or nothing."
2246 t
'("break" "continue" "goto" "return")
2247 objc
'("break" "continue" "goto" "return" "@throw")
2248 ;; Note: `goto' is not valid in Java, but the keyword is still reserved.
2249 java
'("break" "continue" "goto" "return" "throw")
2251 pike
'("break" "continue" "return")
2252 awk
'(;; Not sure about "delete", "exit", "getline", etc. ; ACM 2002/5/30
2253 "break" "continue" "return" "delete" "exit" "getline" "next"
2254 "nextfile" "print" "printf"))
2256 (c-lang-defconst c-simple-stmt-key
2257 ;; Adorned regexp matching `c-simple-stmt-kwds'.
2258 t
(c-make-keywords-re t
(c-lang-const c-simple-stmt-kwds
)))
2259 (c-lang-defvar c-simple-stmt-key
(c-lang-const c-simple-stmt-key
))
2261 (c-lang-defconst c-paren-stmt-kwds
2262 "Statement keywords followed by a parenthesis expression that
2263 nevertheless contains a list separated with ';' and not ','."
2267 (c-lang-defconst c-paren-stmt-key
2268 ;; Adorned regexp matching `c-paren-stmt-kwds'.
2269 t
(c-make-keywords-re t
(c-lang-const c-paren-stmt-kwds
)))
2270 (c-lang-defvar c-paren-stmt-key
(c-lang-const c-paren-stmt-key
))
2272 (c-lang-defconst c-asm-stmt-kwds
2273 "Statement keywords followed by an assembler expression."
2275 (c c
++) '("asm" "__asm__")) ;; Not standard, but common.
2277 (c-lang-defconst c-opt-asm-stmt-key
2278 ;; Regexp matching the start of an assembler statement. Nil in
2279 ;; languages that don't support that.
2280 t
(if (c-lang-const c-asm-stmt-kwds
)
2281 (c-make-keywords-re t
(c-lang-const c-asm-stmt-kwds
))))
2282 (c-lang-defvar c-opt-asm-stmt-key
(c-lang-const c-opt-asm-stmt-key
))
2284 (c-lang-defconst c-case-kwds
2285 "The keyword\(s) which introduce a \"case\" like construct.
2286 This construct is \"<keyword> <expression> :\"."
2290 (c-lang-defconst c-case-kwds-regexp
2291 ;; Adorned regexp matching any "case"-like keyword.
2292 t
(c-make-keywords-re t
(c-lang-const c-case-kwds
)))
2293 (c-lang-defvar c-case-kwds-regexp
(c-lang-const c-case-kwds-regexp
))
2295 (c-lang-defconst c-label-kwds
2296 "Keywords introducing colon terminated labels in blocks."
2297 t
'("case" "default"))
2299 (c-lang-defconst c-label-kwds-regexp
2300 ;; Adorned regexp matching any keyword that introduces a label.
2301 t
(c-make-keywords-re t
(c-lang-const c-label-kwds
)))
2302 (c-lang-defvar c-label-kwds-regexp
(c-lang-const c-label-kwds-regexp
))
2304 (c-lang-defconst c-before-label-kwds
2305 "Keywords that might be followed by a label identifier."
2307 (java pike
) (append '("break" "continue")
2308 (c-lang-const c-before-label-kwds
))
2312 (c-lang-defconst c-constant-kwds
2313 "Keywords for constants."
2315 (c c
++) '("NULL" ;; Not a keyword, but practically works as one.
2316 "false" "true") ; Defined in C99.
2317 objc
'("nil" "Nil" "YES" "NO" "NS_DURING" "NS_HANDLER" "NS_ENDHANDLER")
2318 idl
'("TRUE" "FALSE")
2319 java
'("true" "false" "null") ; technically "literals", not keywords
2320 pike
'("UNDEFINED")) ;; Not a keyword, but practically works as one.
2322 (c-lang-defconst c-primary-expr-kwds
2323 "Keywords besides constants and operators that start primary expressions."
2325 c
++ '("operator" "this")
2326 objc
'("super" "self")
2328 pike
'("this")) ;; Not really a keyword, but practically works as one.
2330 (c-lang-defconst c-expr-kwds
2331 ;; Keywords that can occur anywhere in expressions. Built from
2332 ;; `c-primary-expr-kwds' and all keyword operators in `c-operators'.
2333 t
(cl-delete-duplicates
2334 (append (c-lang-const c-primary-expr-kwds
)
2335 (c-filter-ops (c-lang-const c-operator-list
)
2337 "\\`\\(\\w\\|\\s_\\)+\\'"))
2338 :test
'string-equal
))
2340 (c-lang-defconst c-lambda-kwds
2341 "Keywords that start lambda constructs, i.e. function definitions in
2346 (c-lang-defconst c-inexpr-block-kwds
2347 "Keywords that start constructs followed by statement blocks which can
2348 be used in expressions \(the gcc extension for this in C and C++ is
2349 handled separately by `c-recognize-paren-inexpr-blocks')."
2351 pike
'("catch" "gauge"))
2353 (c-lang-defconst c-inexpr-class-kwds
2354 "Keywords that can start classes inside expressions."
2359 (c-lang-defconst c-inexpr-brace-list-kwds
2360 "Keywords that can start brace list blocks inside expressions.
2361 Note that Java specific rules are currently applied to tell this from
2362 `c-inexpr-class-kwds'."
2366 (c-lang-defconst c-opt-inexpr-brace-list-key
2367 ;; Regexp matching the start of a brace list in an expression, or
2368 ;; nil in languages that don't have such things. This should not
2369 ;; match brace lists recognized through `c-special-brace-lists'.
2370 t
(and (c-lang-const c-inexpr-brace-list-kwds
)
2371 (c-make-keywords-re t
(c-lang-const c-inexpr-brace-list-kwds
))))
2372 (c-lang-defvar c-opt-inexpr-brace-list-key
2373 (c-lang-const c-opt-inexpr-brace-list-key
))
2375 (c-lang-defconst c-decl-block-key
2376 ;; Regexp matching keywords in any construct that contain another
2377 ;; declaration level, i.e. that isn't followed by a function block
2378 ;; or brace list. When the first submatch matches, it's an
2379 ;; unambiguous construct, otherwise it's an ambiguous match that
2380 ;; might also be the return type of a function declaration.
2381 t
(let* ((decl-kwds (append (c-lang-const c-class-decl-kwds
)
2382 (c-lang-const c-other-block-decl-kwds
)
2383 (c-lang-const c-inexpr-class-kwds
)))
2384 (unambiguous (set-difference decl-kwds
2385 (c-lang-const c-type-start-kwds
)
2386 :test
'string-equal
))
2387 (ambiguous (intersection decl-kwds
2388 (c-lang-const c-type-start-kwds
)
2389 :test
'string-equal
)))
2391 (concat (c-make-keywords-re t unambiguous
)
2393 (c-make-keywords-re t ambiguous
))
2394 (c-make-keywords-re t unambiguous
))))
2395 (c-lang-defvar c-decl-block-key
(c-lang-const c-decl-block-key
))
2397 (c-lang-defconst c-bitfield-kwds
2398 "Keywords that can introduce bitfields."
2400 (c c
++ objc
) '("char" "int" "long" "signed" "unsigned"))
2402 (c-lang-defconst c-opt-bitfield-key
2403 ;; Regexp matching the start of a bitfield (not uniquely), or nil in
2404 ;; languages without bitfield support.
2406 (c c
++) (c-make-keywords-re t
(c-lang-const c-bitfield-kwds
)))
2407 (c-lang-defvar c-opt-bitfield-key
(c-lang-const c-opt-bitfield-key
))
2409 (c-lang-defconst c-other-kwds
2410 "Keywords not accounted for by any other `*-kwds' language constant."
2413 ;; In CORBA CIDL: (These are declaration keywords that never
2414 ;; can start a declaration.)
2415 "entity" "process" "service" "session" "storage"))
2418 ;;; Constants built from keywords.
2420 ;; Note: No `*-kwds' language constants may be defined below this point.
2423 (defconst c-kwds-lang-consts
2424 ;; List of all the language constants that contain keyword lists.
2426 (mapatoms (lambda (sym)
2427 (when (and (boundp sym
)
2428 (string-match "-kwds\\'" (symbol-name sym
)))
2429 ;; Make the list of globally interned symbols
2430 ;; instead of ones interned in `c-lang-constants'.
2431 (setq list
(cons (intern (symbol-name sym
)) list
))))
2435 (c-lang-defconst c-keywords
2436 ;; All keywords as a list.
2437 t
(cl-delete-duplicates
2438 (c-lang-defconst-eval-immediately
2439 `(append ,@(mapcar (lambda (kwds-lang-const)
2440 `(c-lang-const ,kwds-lang-const
))
2443 :test
'string-equal
))
2445 (c-lang-defconst c-keywords-regexp
2446 ;; All keywords as an adorned regexp.
2447 t
(c-make-keywords-re t
(c-lang-const c-keywords
)))
2448 (c-lang-defvar c-keywords-regexp
(c-lang-const c-keywords-regexp
))
2450 (c-lang-defconst c-keyword-member-alist
2451 ;; An alist with all the keywords in the cars. The cdr for each
2452 ;; keyword is a list of the symbols for the `*-kwds' lists that
2454 t
(let ((kwd-list-alist
2455 (c-lang-defconst-eval-immediately
2456 `(list ,@(mapcar (lambda (kwds-lang-const)
2457 `(cons ',kwds-lang-const
2458 (c-lang-const ,kwds-lang-const
)))
2459 c-kwds-lang-consts
))))
2460 lang-const kwd-list kwd
2462 (while kwd-list-alist
2463 (setq lang-const
(caar kwd-list-alist
)
2464 kwd-list
(cdar kwd-list-alist
)
2465 kwd-list-alist
(cdr kwd-list-alist
))
2467 (setq kwd
(car kwd-list
)
2468 kwd-list
(cdr kwd-list
))
2469 (unless (setq elem
(assoc kwd result-alist
))
2470 (setq result-alist
(cons (setq elem
(list kwd
)) result-alist
)))
2471 (unless (memq lang-const
(cdr elem
))
2472 (setcdr elem
(cons lang-const
(cdr elem
))))))
2475 (c-lang-defvar c-keywords-obarray
2476 ;; An obarray containing all keywords as symbols. The property list
2477 ;; of each symbol has a non-nil entry for the specific `*-kwds'
2478 ;; lists it's a member of.
2480 ;; E.g. to see whether the string str contains a keyword on
2481 ;; `c-class-decl-kwds', one can do like this:
2482 ;; (get (intern-soft str c-keyword-obarray) 'c-class-decl-kwds)
2483 ;; Which preferably is written using the associated functions in
2485 ;; (c-keyword-member (c-keyword-sym str) 'c-class-decl-kwds)
2487 ;; The obarray is not stored directly as a language constant since
2488 ;; the printed representation for obarrays used in .elc files isn't
2491 (let* ((alist (c-lang-const c-keyword-member-alist
))
2493 (obarray (make-vector (* (length alist
) 2) 0)))
2495 (setq kwd
(caar alist
)
2496 lang-const-list
(cdar alist
)
2498 (setplist (intern kwd obarray
)
2499 ;; Emacs has an odd bug that causes `mapcan' to fail
2500 ;; with unintelligible errors. (XEmacs works.)
2501 ;;(mapcan (lambda (lang-const)
2502 ;; (list lang-const t))
2504 (apply 'nconc
(mapcar (lambda (lang-const)
2505 (list lang-const t
))
2509 (c-lang-defconst c-regular-keywords-regexp
2510 ;; Adorned regexp matching all keywords that should be fontified
2511 ;; with the keywords face. I.e. that aren't types or constants.
2512 t
(c-make-keywords-re t
2513 (set-difference (c-lang-const c-keywords
)
2514 (append (c-lang-const c-primitive-type-kwds
)
2515 (c-lang-const c-constant-kwds
))
2516 :test
'string-equal
)))
2517 (c-lang-defvar c-regular-keywords-regexp
2518 (c-lang-const c-regular-keywords-regexp
))
2520 (c-lang-defconst c-primary-expr-regexp
2521 ;; Regexp matching the start of any primary expression, i.e. any
2522 ;; literal, symbol, prefix operator, and '('. It doesn't need to
2523 ;; exclude keywords; they are excluded afterwards unless the second
2524 ;; submatch matches. If the first but not the second submatch
2525 ;; matches then it is an ambiguous primary expression; it could also
2526 ;; be a match of e.g. an infix operator. (The case with ambiguous
2527 ;; keyword operators isn't handled.)
2529 t
(let* ((prefix-ops
2530 (c-filter-ops (c-lang-const c-operators
)
2533 ;; Filter out the special case prefix
2534 ;; operators that are close parens.
2535 (not (string-match "\\s)" op
)))))
2537 (nonkeyword-prefix-ops
2538 (c-filter-ops prefix-ops
2540 "\\`\\(\\s.\\|\\s(\\|\\s)\\)+\\'"))
2543 (c-filter-ops (c-lang-const c-operators
)
2548 right-assoc-sequence
)
2551 (unambiguous-prefix-ops (set-difference nonkeyword-prefix-ops
2553 :test
'string-equal
))
2554 (ambiguous-prefix-ops (intersection nonkeyword-prefix-ops
2556 :test
'string-equal
)))
2560 ;; Take out all symbol class operators from `prefix-ops' and make the
2561 ;; first submatch from them together with `c-primary-expr-kwds'.
2562 (c-make-keywords-re t
2563 (append (c-lang-const c-primary-expr-kwds
)
2564 (set-difference prefix-ops nonkeyword-prefix-ops
2565 :test
'string-equal
)))
2568 ;; Match all ambiguous operators.
2569 (c-make-keywords-re nil
2570 (intersection nonkeyword-prefix-ops in-or-postfix-ops
2571 :test
'string-equal
))
2575 ;; Now match all other symbols.
2576 (c-lang-const c-symbol-start
)
2579 ;; The chars that can start integer and floating point
2584 ;; The unambiguous operators from `prefix-ops'.
2585 (c-make-keywords-re nil
2586 (set-difference nonkeyword-prefix-ops in-or-postfix-ops
2587 :test
'string-equal
))
2590 ;; Match string and character literals.
2592 (if (memq 'gen-string-delim c-emacs-features
)
2595 (c-lang-defvar c-primary-expr-regexp
(c-lang-const c-primary-expr-regexp
))
2598 ;;; Additional constants for parser-level constructs.
2600 (c-lang-defconst c-decl-start-colon-kwd-re
2601 "Regexp matching a keyword that is followed by a colon, where
2602 the whole construct can precede a declaration.
2603 E.g. \"public:\" in C++."
2605 c
++ (c-make-keywords-re t
(c-lang-const c-protection-kwds
)))
2606 (c-lang-defvar c-decl-start-colon-kwd-re
2607 (c-lang-const c-decl-start-colon-kwd-re
))
2609 (c-lang-defconst c-decl-prefix-re
2610 "Regexp matching something that might precede a declaration, cast or
2611 label, such as the last token of a preceding statement or declaration.
2612 This is used in the common situation where a declaration or cast
2613 doesn't start with any specific token that can be searched for.
2615 The regexp should not match bob; that is done implicitly. It can't
2616 require a match longer than one token. The end of the token is taken
2617 to be at the end of the first submatch, which is assumed to always
2618 match. It's undefined whether identifier syntax (see
2619 `c-identifier-syntax-table') is in effect or not. This regexp is
2620 assumed to be a superset of `c-label-prefix-re' if
2621 `c-recognize-colon-labels' is set.
2623 Besides this, `c-decl-start-kwds' is used to find declarations.
2625 Note: This variable together with `c-decl-start-re' and
2626 `c-decl-start-kwds' is only used to detect \"likely\"
2627 declaration/cast/label starts. I.e. they might produce more matches
2628 but should not miss anything (or else it's necessary to use text
2629 properties - see the next note). Wherever they match, the following
2630 construct is analyzed to see if it indeed is a declaration, cast or
2631 label. That analysis is not cheap, so it's important that not too
2632 many false matches are triggered.
2634 Note: If a declaration/cast/label start can't be detected with this
2635 variable, it's necessary to use the `c-type' text property with the
2636 value `c-decl-end' on the last char of the last token preceding the
2637 declaration. See the comment blurb at the start of cc-engine.el for
2640 ;; We match a sequence of characters to skip over things like \"};\"
2641 ;; more quickly. We match ")" in C for K&R region declarations, and
2642 ;; in all languages except Java for when a cpp macro definition
2643 ;; begins with a declaration.
2644 t
"\\([\{\}\(\);,]+\\)"
2645 java
"\\([\{\}\(;,<]+\\)"
2646 ;; Match "<" in C++ to get the first argument in a template arglist.
2647 ;; In that case there's an additional check in `c-find-decl-spots'
2648 ;; that it got open paren syntax. Match ":" to aid in picking up
2649 ;; "public:", etc. This involves additional checks in
2650 ;; `c-find-decl-prefix-search' to prevent a match of identifiers
2652 c
++ "\\([\{\}\(\);:,<]+\\)"
2653 ;; Additionally match the protection directives in Objective-C.
2654 ;; Note that this doesn't cope with the longer directives, which we
2655 ;; would have to match from start to end since they don't end with
2656 ;; any easily recognized characters.
2657 objc
(concat "\\([\{\}\(\);,]+\\|"
2658 (c-make-keywords-re nil
(c-lang-const c-protection-kwds
))
2660 ;; Pike is like C but we also match "[" for multiple value
2661 ;; assignments and type casts.
2662 pike
"\\([\{\}\(\)\[;,]+\\)")
2663 (c-lang-defvar c-decl-prefix-re
(c-lang-const c-decl-prefix-re
)
2666 (c-lang-defconst c-decl-start-re
2667 "Regexp matching the start of any declaration, cast or label.
2668 It's used on the token after the one `c-decl-prefix-re' matched. This
2669 regexp should not try to match those constructs accurately as it's
2670 only used as a sieve to avoid spending more time checking other
2672 t
(c-lang-const c-identifier-start
))
2673 (c-lang-defvar c-decl-start-re
(c-lang-const c-decl-start-re
))
2675 (c-lang-defconst c-decl-prefix-or-start-re
2676 ;; Regexp matching something that might precede or start a
2677 ;; declaration, cast or label.
2679 ;; If the first submatch matches, it's taken to match the end of a
2680 ;; token that might precede such a construct, e.g. ';', '}' or '{'.
2681 ;; It's built from `c-decl-prefix-re'.
2683 ;; If the first submatch did not match, the match of the whole
2684 ;; regexp is taken to be at the first token in the declaration.
2685 ;; `c-decl-start-re' is not checked in this case.
2687 ;; Design note: The reason the same regexp is used to match both
2688 ;; tokens that precede declarations and start them is to avoid an
2689 ;; extra regexp search from the previous declaration spot in
2690 ;; `c-find-decl-spots'. Users of `c-find-decl-spots' also count on
2691 ;; that it finds all declaration/cast/label starts in approximately
2692 ;; linear order, so we can't do the searches in two separate passes.
2693 t
(if (c-lang-const c-decl-start-kwds
)
2694 (concat (c-lang-const c-decl-prefix-re
)
2696 (c-make-keywords-re t
(c-lang-const c-decl-start-kwds
)))
2697 (c-lang-const c-decl-prefix-re
)))
2698 (c-lang-defvar c-decl-prefix-or-start-re
2699 (c-lang-const c-decl-prefix-or-start-re
)
2702 (c-lang-defconst c-cast-parens
2703 ;; List containing the paren characters that can open a cast, or nil in
2704 ;; languages without casts.
2705 t
(c-filter-ops (c-lang-const c-operators
)
2708 (lambda (op) (elt op
0))))
2709 (c-lang-defvar c-cast-parens
(c-lang-const c-cast-parens
))
2711 (c-lang-defconst c-block-prefix-disallowed-chars
2712 "List of syntactically relevant characters that never can occur before
2713 the open brace in any construct that contains a brace block, e.g. in
2714 the \"class Foo: public Bar\" part of:
2716 class Foo: public Bar {int x();} a, *b;
2718 If parens can occur, the chars inside those aren't filtered with this
2721 '<' and '>' should be disallowed even if angle bracket arglists can
2722 occur. That since the search function needs to stop at them anyway to
2723 ensure they are given paren syntax.
2725 This is used to skip backward from the open brace to find the region
2726 in which to look for a construct like \"class\", \"enum\",
2727 \"namespace\" or whatever. That skipping should be as tight as
2728 possible for good performance."
2730 ;; Default to all chars that only occurs in nonsymbol tokens outside
2733 (c-lang-const c-nonsymbol-token-char-list
)
2734 (c-filter-ops (append (c-lang-const c-identifier-ops
)
2736 (c-lang-const c-after-id-concat-ops
))))
2741 (while (string-match "\\(\\s.\\|\\s(\\|\\s)\\)"
2743 (setq res
(cons (aref op
(match-beginning 1)) res
)
2747 ;; Allow cpp operations (where applicable).
2748 t
(if (c-lang-const c-opt-cpp-prefix
)
2749 (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2751 (c-lang-const c-block-prefix-disallowed-chars
))
2753 ;; Allow ':' for inherit list starters.
2754 (c++ objc idl
) (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2757 ;; Allow ',' for multiple inherits.
2758 (c++ java
) (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2761 ;; Allow parentheses for anonymous inner classes in Java and class
2762 ;; initializer lists in Pike.
2763 (java pike
) (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2766 ;; Allow '"' for extern clauses (e.g. extern "C" {...}).
2767 (c c
++ objc
) (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2770 (c-lang-defconst c-block-prefix-charset
2771 ;; `c-block-prefix-disallowed-chars' as an inverted charset suitable
2772 ;; for `c-syntactic-skip-backward'.
2773 t
(c-make-bare-char-alt (c-lang-const c-block-prefix-disallowed-chars
) t
))
2774 (c-lang-defvar c-block-prefix-charset
(c-lang-const c-block-prefix-charset
))
2776 (c-lang-defconst c-type-decl-prefix-key
2777 "Regexp matching the declarator operators that might precede the
2778 identifier in a declaration, e.g. the \"*\" in \"char *argv\". This
2779 regexp should match \"(\" if parentheses are valid in declarators.
2780 The end of the first submatch is taken as the end of the operator.
2781 Identifier syntax is in effect when this is matched \(see
2782 `c-identifier-syntax-table')."
2783 t
(if (c-lang-const c-type-modifier-kwds
)
2784 (concat (regexp-opt (c-lang-const c-type-modifier-kwds
) t
) "\\>")
2785 ;; Default to a regexp that never matches.
2787 ;; Check that there's no "=" afterwards to avoid matching tokens
2789 (c objc
) (concat "\\("
2792 (c-lang-const c-type-decl-prefix-key
)
2798 (c-lang-const c-type-decl-prefix-key
)
2801 ;; If this matches there's special treatment in
2802 ;; `c-font-lock-declarators' and
2803 ;; `c-font-lock-declarations' that check for a
2804 ;; complete name followed by ":: *".
2805 (c-lang-const c-identifier-start
)
2809 pike
"\\(\\*\\)\\([^=]\\|$\\)")
2810 (c-lang-defvar c-type-decl-prefix-key
(c-lang-const c-type-decl-prefix-key
)
2813 (c-lang-defconst c-type-decl-suffix-key
2814 "Regexp matching the declarator operators that might follow after the
2815 identifier in a declaration, e.g. the \"[\" in \"char argv[]\". This
2816 regexp should match \")\" if parentheses are valid in declarators. If
2817 it matches an open paren of some kind, the type declaration check
2818 continues at the corresponding close paren, otherwise the end of the
2819 first submatch is taken as the end of the operator. Identifier syntax
2820 is in effect when this is matched (see `c-identifier-syntax-table')."
2821 ;; Default to a regexp that matches `c-type-modifier-kwds' and a
2822 ;; function argument list parenthesis.
2823 t
(if (c-lang-const c-type-modifier-kwds
)
2825 (regexp-opt (c-lang-const c-type-modifier-kwds
) t
) "\\>"
2828 (c c
++ objc
) (concat
2831 (if (c-lang-const c-type-modifier-kwds
)
2834 ;; "throw" in `c-type-modifier-kwds' is followed
2835 ;; by a parenthesis list, but no extra measures
2836 ;; are necessary to handle that.
2837 (regexp-opt (c-lang-const c-type-modifier-kwds
) t
)
2841 java
"\\([\[\(\)]\\)"
2843 (c-lang-defvar c-type-decl-suffix-key
(c-lang-const c-type-decl-suffix-key
)
2846 (c-lang-defconst c-after-suffixed-type-decl-key
2847 "This regexp is matched after a declarator expression where
2848 `c-type-decl-suffix-key' has matched. If it matches then the
2849 construct is taken as a declaration. It's typically used to match the
2850 beginning of a function body or whatever might occur after the
2851 function header in a function declaration or definition. It's
2852 undefined whether identifier syntax (see `c-identifier-syntax-table')
2853 is in effect or not.
2855 Note that it's used in cases like after \"foo (bar)\" so it should
2856 only match when it's certain that it's a declaration, e.g., \"{\" but
2857 not \",\" or \";\"."
2859 ;; If K&R style declarations should be recognized then one could
2860 ;; consider to match the start of any symbol since we want to match
2861 ;; the start of the first declaration in the "K&R region". That
2862 ;; could however produce false matches on code like "FOO(bar) x"
2863 ;; where FOO is a cpp macro, so it's better to leave it out and rely
2864 ;; on the other heuristics in that case.
2865 t
(if (c-lang-const c-postfix-spec-kwds
)
2866 ;; Add on the keywords in `c-postfix-spec-kwds'.
2867 (concat (c-lang-const c-after-suffixed-type-decl-key
)
2869 (c-make-keywords-re t
(c-lang-const c-postfix-spec-kwds
)))
2870 (c-lang-const c-after-suffixed-type-decl-key
))
2871 ;; Also match the colon that starts a base class initializer list in
2872 ;; C++. That can be confused with a function call before the colon
2873 ;; in a ? : operator, but we count on that `c-decl-prefix-re' won't
2874 ;; match before such a thing (as a declaration-level construct;
2875 ;; matches inside arglist contexts are already excluded).
2877 (c-lang-defvar c-after-suffixed-type-decl-key
2878 (c-lang-const c-after-suffixed-type-decl-key
)
2881 (c-lang-defconst c-after-suffixed-type-maybe-decl-key
2882 ;; Regexp that in addition to `c-after-suffixed-type-decl-key'
2883 ;; matches ";" and ",".
2884 t
(concat "\\(" (c-lang-const c-after-suffixed-type-decl-key
) "\\)"
2886 (c-lang-defvar c-after-suffixed-type-maybe-decl-key
2887 (c-lang-const c-after-suffixed-type-maybe-decl-key
))
2889 (c-lang-defconst c-opt-type-concat-key
2890 "Regexp matching operators that concatenate types, e.g. the \"|\" in
2891 \"int|string\" in Pike. The end of the first submatch is taken as the
2892 end of the operator. nil in languages without such operators. It's
2893 undefined whether identifier syntax (see `c-identifier-syntax-table')
2894 is in effect or not."
2896 pike
"\\([|.&]\\)\\($\\|[^|.&]\\)")
2897 (c-lang-defvar c-opt-type-concat-key
(c-lang-const c-opt-type-concat-key
)
2900 (c-lang-defconst c-opt-type-suffix-key
2901 "Regexp matching operators that might follow after a type, or nil in
2902 languages that don't have such operators. The end of the first
2903 submatch is taken as the end of the operator. This should not match
2904 things like C++ template arglists if `c-recognize-<>-arglists' is set.
2905 It's undefined whether identifier syntax (see `c-identifier-syntax-table')
2906 is in effect or not."
2908 (c c
++ objc pike
) "\\(\\.\\.\\.\\)"
2909 java
(concat "\\(\\[" (c-lang-const c-simple-ws
) "*\\]\\|\\.\\.\\.\\)"))
2910 (c-lang-defvar c-opt-type-suffix-key
(c-lang-const c-opt-type-suffix-key
))
2912 (c-lang-defvar c-known-type-key
2913 ;; Regexp matching the known type identifiers. This is initialized
2914 ;; from the type keywords and `*-font-lock-extra-types'. The first
2915 ;; submatch is the one that matches the type. Note that this regexp
2916 ;; assumes that symbol constituents like '_' and '$' have word
2919 (when (boundp (c-mode-symbol "font-lock-extra-types"))
2920 (c-mode-var "font-lock-extra-types")))
2923 (mapcar (lambda (re)
2924 (when (string-match "[][.*+?^$\\]" re
)
2929 (mapcar (lambda (re)
2930 (unless (string-match "[][.*+?^$\\]" re
)
2935 (append (list (c-make-keywords-re nil
2936 (append (c-lang-const c-primitive-type-kwds
)
2942 (c-lang-defconst c-special-brace-lists
2943 "List of open- and close-chars that makes up a pike-style brace list,
2944 i.e. for a ([Â ]) list there should be a cons (?\\[ . ?\\]) in this
2947 pike
'((?
{ . ?
}) (?\
[ . ?\
]) (?
< . ?
>)))
2948 (c-lang-defvar c-special-brace-lists
(c-lang-const c-special-brace-lists
))
2950 (c-lang-defconst c-recognize-knr-p
2951 "Non-nil means K&R style argument declarations are valid."
2954 (c-lang-defvar c-recognize-knr-p
(c-lang-const c-recognize-knr-p
))
2956 (c-lang-defconst c-recognize-typeless-decls
2957 "Non-nil means function declarations without return type should be
2958 recognized. That can introduce an ambiguity with parenthesized macro
2959 calls before a brace block. This setting does not affect declarations
2960 that are preceded by a declaration starting keyword, so
2961 e.g. `c-typeless-decl-kwds' may still be used when it's set to nil."
2963 (c c
++ objc java
) t
)
2964 (c-lang-defvar c-recognize-typeless-decls
2965 (c-lang-const c-recognize-typeless-decls
))
2967 (c-lang-defconst c-recognize-
<>-arglists
2968 "Non-nil means C++ style template arglists should be handled. More
2969 specifically, this means a comma separated list of types or
2970 expressions surrounded by \"<\" and \">\". It's always preceded by an
2971 identifier or one of the keywords on `c-<>-type-kwds' or
2972 `c-<>-arglist-kwds'. If there's an identifier before then the whole
2973 expression is considered to be a type."
2974 t
(or (consp (c-lang-const c-
<>-type-kwds
))
2975 (consp (c-lang-const c-
<>-arglist-kwds
)))
2977 (c-lang-defvar c-recognize-
<>-arglists
(c-lang-const c-recognize-
<>-arglists
))
2979 (c-lang-defconst c-enums-contain-decls
2980 "Non-nil means that an enum structure can contain declarations."
2983 (c-lang-defvar c-enums-contain-decls
(c-lang-const c-enums-contain-decls
))
2985 (c-lang-defconst c-recognize-paren-inits
2986 "Non-nil means that parenthesis style initializers exist,
2987 i.e. constructs like
2991 in addition to the more classic
2996 (c-lang-defvar c-recognize-paren-inits
(c-lang-const c-recognize-paren-inits
))
2998 (c-lang-defconst c-recognize-paren-inexpr-blocks
2999 "Non-nil to recognize gcc style in-expression blocks,
3000 i.e. compound statements surrounded by parentheses inside expressions."
3003 (c-lang-defvar c-recognize-paren-inexpr-blocks
3004 (c-lang-const c-recognize-paren-inexpr-blocks
))
3006 (c-lang-defconst c-opt-
<>-arglist-start
3007 ;; Regexp matching the start of angle bracket arglists in languages
3008 ;; where `c-recognize-<>-arglists' is set. Does not exclude
3009 ;; keywords outside `c-<>-arglist-kwds'. The first submatch is
3010 ;; assumed to surround the preceding symbol. The whole match is
3011 ;; assumed to end directly after the opening "<".
3012 t
(if (c-lang-const c-recognize-
<>-arglists
)
3014 (c-lang-const c-symbol-key
)
3016 (c-lang-const c-syntactic-ws
)
3018 (c-lang-defvar c-opt-
<>-arglist-start
(c-lang-const c-opt-
<>-arglist-start
))
3020 (c-lang-defconst c-opt-
<>-arglist-start-in-paren
3021 ;; Regexp that in addition to `c-opt-<>-arglist-start' matches close
3022 ;; parens. The first submatch is assumed to surround
3023 ;; `c-opt-<>-arglist-start'.
3024 t
(if (c-lang-const c-opt-
<>-arglist-start
)
3026 (c-lang-const c-opt-
<>-arglist-start
)
3028 (c-lang-defvar c-opt-
<>-arglist-start-in-paren
3029 (c-lang-const c-opt-
<>-arglist-start-in-paren
))
3031 (c-lang-defconst c-opt-postfix-decl-spec-key
3032 ;; Regexp matching the beginning of a declaration specifier in the
3033 ;; region between the header and the body of a declaration.
3035 ;; TODO: This is currently not used uniformly; c++-mode and
3036 ;; java-mode each have their own ways of using it.
3039 (c-lang-const c-simple-ws
) "*"
3040 "\\(virtual" (c-lang-const c-simple-ws
) "+\\)?\\("
3041 (c-make-keywords-re nil
(c-lang-const c-protection-kwds
))
3042 "\\)" (c-lang-const c-simple-ws
) "+"
3043 "\\(" (c-lang-const c-symbol-key
) "\\)")
3044 java
(c-make-keywords-re t
(c-lang-const c-postfix-spec-kwds
)))
3045 (c-lang-defvar c-opt-postfix-decl-spec-key
3046 (c-lang-const c-opt-postfix-decl-spec-key
))
3048 (c-lang-defconst c-recognize-colon-labels
3049 "Non-nil if generic labels ending with \":\" should be recognized.
3050 That includes labels in code and access keys in classes. This does
3051 not apply to labels recognized by `c-label-kwds' and
3052 `c-opt-extra-label-key'."
3054 (c c
++ objc java pike
) t
)
3055 (c-lang-defvar c-recognize-colon-labels
3056 (c-lang-const c-recognize-colon-labels
))
3058 (c-lang-defconst c-label-prefix-re
3059 "Regexp like `c-decl-prefix-re' that matches any token that can precede
3060 a generic colon label. Not used if `c-recognize-colon-labels' is
3063 (c-lang-defvar c-label-prefix-re
3064 (c-lang-const c-label-prefix-re
))
3066 (c-lang-defconst c-nonlabel-token-key
3067 "Regexp matching things that can't occur in generic colon labels,
3068 neither in a statement nor in a declaration context. The regexp is
3069 tested at the beginning of every sexp in a suspected label,
3070 i.e. before \":\". Only used if `c-recognize-colon-labels' is set."
3072 ;; All keywords except `c-label-kwds' and `c-protection-kwds'.
3073 (c-make-keywords-re t
3074 (set-difference (c-lang-const c-keywords
)
3075 (append (c-lang-const c-label-kwds
)
3076 (c-lang-const c-protection-kwds
))
3077 :test
'string-equal
)))
3078 ;; Don't allow string literals, except in AWK. Character constants are OK.
3079 (c objc java pike idl
) (concat "\"\\|"
3080 (c-lang-const c-nonlabel-token-key
))
3081 ;; Also check for open parens in C++, to catch member init lists in
3082 ;; constructors. We normally allow it so that macros with arguments
3084 c
++ (concat "\\s\(\\|\"\\|" (c-lang-const c-nonlabel-token-key
)))
3085 (c-lang-defvar c-nonlabel-token-key
(c-lang-const c-nonlabel-token-key
))
3087 (c-lang-defconst c-nonlabel-token-2-key
3088 "Regexp matching things that can't occur two symbols before a colon in
3089 a label construct. This catches C++'s inheritance construct \"class foo
3090 : bar\". Only used if `c-recognize-colon-labels' is set."
3091 t
"\\<\\>" ; matches nothing
3092 c
++ (c-make-keywords-re t
'("class")))
3093 (c-lang-defvar c-nonlabel-token-2-key
(c-lang-const c-nonlabel-token-2-key
))
3095 (c-lang-defconst c-opt-extra-label-key
3096 "Optional regexp matching labels.
3097 Normally, labels are detected according to `c-nonlabel-token-key',
3098 `c-decl-prefix-re' and `c-nonlabel-decl-prefix-re'. This regexp can
3099 be used if there are additional labels that aren't recognized that
3102 objc
(c-make-keywords-re t
(c-lang-const c-protection-kwds
)))
3103 (c-lang-defvar c-opt-extra-label-key
(c-lang-const c-opt-extra-label-key
))
3105 (c-lang-defconst c-opt-friend-key
3106 ;; Regexp describing friend declarations classes, or nil in
3107 ;; languages that don't have such things.
3109 ;; TODO: Ought to use `c-prefix-spec-kwds-re' or similar, and the
3110 ;; template skipping isn't done properly. This will disappear soon.
3112 c
++ (concat "friend" (c-lang-const c-simple-ws
) "+"
3115 (c-lang-const c-simple-ws
) "*"
3117 (c-lang-const c-simple-ws
) "*"
3119 (c-lang-const c-simple-ws
) "+")))
3120 (c-lang-defvar c-opt-friend-key
(c-lang-const c-opt-friend-key
))
3122 (c-lang-defconst c-opt-method-key
3123 ;; Special regexp to match the start of Objective-C methods. The
3124 ;; first submatch is assumed to end after the + or - key.
3127 ;; TODO: Ought to use a better method than anchoring on bol.
3130 (c-lang-const c-simple-ws
) "*"
3131 (concat "\\(" ; Return type.
3133 (c-lang-const c-simple-ws
) "*"
3135 "\\(" (c-lang-const c-symbol-key
) "\\)"))
3136 (c-lang-defvar c-opt-method-key
(c-lang-const c-opt-method-key
))
3138 (c-lang-defconst c-type-decl-end-used
3139 ;; Must be set in buffers where the `c-type' text property might be
3140 ;; used with the value `c-decl-end'.
3142 ;; `c-decl-end' is used to mark the ends of labels and access keys
3143 ;; to make interactive refontification work better.
3144 t
(or (c-lang-const c-recognize-colon-labels
)
3145 (and (c-lang-const c-label-kwds
) t
))
3146 ;; `c-decl-end' is used to mark the end of the @-style directives in
3149 (c-lang-defvar c-type-decl-end-used
(c-lang-const c-type-decl-end-used
))
3152 ;;; Wrap up the `c-lang-defvar' system.
3154 ;; Compile in the list of language variables that has been collected
3155 ;; with the `c-lang-defvar' and `c-lang-setvar' macros. Note that the
3156 ;; first element of each is nil.
3157 (defconst c-lang-variable-inits
(cc-eval-when-compile c-lang-variable-inits
))
3158 (defconst c-emacs-variable-inits
(cc-eval-when-compile c-emacs-variable-inits
))
3160 ;; Make the `c-lang-setvar' variables buffer local in the current buffer.
3161 ;; These are typically standard emacs variables such as `comment-start'.
3162 (defmacro c-make-emacs-variables-local
()
3164 ,@(mapcar (lambda (init)
3165 `(make-local-variable ',(car init
)))
3166 (cdr c-emacs-variable-inits
))))
3168 (defun c-make-init-lang-vars-fun (mode)
3169 "Create a function that initializes all the language dependent variables
3172 This function should be evaluated at compile time, so that the
3173 function it returns is byte compiled with all the evaluated results
3174 from the language constants. Use the `c-init-language-vars' macro to
3175 accomplish that conveniently."
3177 (if (and (not load-in-progress
)
3178 (boundp 'byte-compile-dest-file
)
3179 (stringp byte-compile-dest-file
))
3181 ;; No need to byte compile this lambda since the byte compiler is
3182 ;; smart enough to detect the `funcall' construct in the
3183 ;; `c-init-language-vars' macro below and compile it all straight
3184 ;; into the function that contains `c-init-language-vars'.
3187 ;; This let sets up the context for `c-mode-var' and similar
3188 ;; that could be in the result from `cl-macroexpand-all'.
3189 (let ((c-buffer-is-cc-mode ',mode
)
3190 current-var source-eval
)
3191 (c-make-emacs-variables-local)
3194 (if (eq c-version-sym
',c-version-sym
)
3195 (setq ,@(let ((c-buffer-is-cc-mode mode
)
3196 (c-lang-const-expansion 'immediate
))
3197 ;; `c-lang-const' will expand to the evaluated
3198 ;; constant immediately in `cl-macroexpand-all'
3202 `(current-var ',(car init
)
3203 ,(car init
) ,(macroexpand-all
3205 ;; Note: The following `append' copies the
3206 ;; first argument. That list is small, so
3207 ;; this doesn't matter too much.
3208 (append (cdr c-emacs-variable-inits
)
3209 (cdr c-lang-variable-inits
)))))
3211 ;; This diagnostic message isn't useful for end
3212 ;; users, so it's disabled.
3213 ;;(unless (get ',mode 'c-has-warned-lang-consts)
3214 ;; (message ,(concat "%s compiled with CC Mode %s "
3215 ;; "but loaded with %s - evaluating "
3216 ;; "language constants from source")
3217 ;; ',mode ,c-version c-version)
3218 ;; (put ',mode 'c-has-warned-lang-consts t))
3220 (setq source-eval t
)
3221 (let ((init ',(append (cdr c-emacs-variable-inits
)
3222 (cdr c-lang-variable-inits
))))
3224 (setq current-var
(caar init
))
3225 (set (caar init
) (eval (cadar init
)))
3226 (setq init
(cdr init
)))))
3230 (message "Eval error in the `c-lang-defvar' or `c-lang-setvar' for `%s'%s: %S"
3234 (fallback source eval - %s compiled with CC Mode %s but loaded with %s)"
3235 ',mode
,c-version c-version
)
3238 (signal (car err
) (cdr err
)))))))
3240 ;; Being evaluated from source. Always use the dynamic method to
3241 ;; work well when `c-lang-defvar's in this file are reevaluated
3245 (let ((c-buffer-is-cc-mode ',mode
)
3246 (init (append (cdr c-emacs-variable-inits
)
3247 (cdr c-lang-variable-inits
)))
3249 (c-make-emacs-variables-local)
3253 (setq current-var
(caar init
))
3254 (set (caar init
) (eval (cadar init
)))
3255 (setq init
(cdr init
)))
3260 "Eval error in the `c-lang-defvar' or `c-lang-setver' for `%s' (source eval): %S"
3262 (signal (car err
) (cdr err
)))))))
3265 (defmacro c-init-language-vars
(mode)
3266 "Initialize all the language dependent variables for the given mode.
3267 This macro is expanded at compile time to a form tailored for the mode
3268 in question, so MODE must be a constant. Therefore MODE is not
3269 evaluated and should not be quoted."
3270 `(funcall ,(c-make-init-lang-vars-fun mode
)))
3273 (cc-provide 'cc-langs
)
3275 ;;; cc-langs.el ends here