1 ;;; cc-langs.el --- language specific settings for CC Mode
3 ;; Copyright (C) 1985, 1987, 1992-2011
4 ;; Free Software Foundation, Inc.
6 ;; Authors: 2002- Alan Mackenzie
7 ;; 1998- Martin Stjernholm
8 ;; 1992-1999 Barry A. Warsaw
10 ;; 1987 Stewart Clamen
11 ;; 1985 Richard M. Stallman
12 ;; Maintainer: bug-cc-mode@gnu.org
13 ;; Created: 22-Apr-1997 (split from cc-mode.el)
14 ;; Keywords: c languages
17 ;; This file is part of GNU Emacs.
19 ;; GNU Emacs is free software: you can redistribute it and/or modify
20 ;; it under the terms of the GNU General Public License as published by
21 ;; the Free Software Foundation, either version 3 of the License, or
22 ;; (at your option) any later version.
24 ;; GNU Emacs is distributed in the hope that it will be useful,
25 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
26 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 ;; GNU General Public License for more details.
29 ;; You should have received a copy of the GNU General Public License
30 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
34 ;; HACKERS NOTE: There's heavy macro magic here. If you need to make
35 ;; changes in this or other files containing `c-lang-defconst' but
36 ;; don't want to read through the longer discussion below then read
39 ;; o A change in a `c-lang-defconst' or `c-lang-defvar' will not take
40 ;; effect if the file containing the mode init function (typically
41 ;; cc-mode.el) is byte compiled.
42 ;; o To make changes show in font locking you need to reevaluate the
43 ;; `*-font-lock-keywords-*' constants, which normally is easiest to
44 ;; do with M-x eval-buffer in cc-fonts.el.
45 ;; o In either case it's necessary to reinitialize the mode to make
46 ;; the changes show in an existing buffer.
48 ;;; Introduction to the language dependent variable system:
50 ;; This file contains all the language dependent variables, except
51 ;; those specific for font locking which reside in cc-fonts.el. As
52 ;; far as possible, all the differences between the languages that CC
53 ;; Mode supports are described with these variables only, so that the
54 ;; code can be shared.
56 ;; The language constant system (see cc-defs.el) is used to specify
57 ;; various language dependent info at a high level, such as lists of
58 ;; keywords, and then from them generate - at compile time - the
59 ;; various regexps and other low-level structures actually employed in
60 ;; the code at runtime.
62 ;; This system is also designed to make it easy for developers of
63 ;; derived modes to customize the source constants for new language
64 ;; variants, without having to keep up with the exact regexps etc that
65 ;; are used in each CC Mode version. It's possible from an external
66 ;; package to add a new language by inheriting an existing one, and
67 ;; then change specific constants as necessary for the new language.
68 ;; The old values for those constants (and the values of all the other
69 ;; high-level constants) may be used to build the new ones, and those
70 ;; new values will in turn be used by the low-level definitions here
71 ;; to build the runtime constants appropriately for the new language
72 ;; in the current version of CC Mode.
74 ;; Like elsewhere in CC Mode, the existence of a doc string signifies
75 ;; that a language constant is part of the external API, and that it
76 ;; therefore can be used with a high confidence that it will continue
77 ;; to work with future versions of CC Mode. Even so, it's not
78 ;; unlikely that such constants will change meaning slightly as this
79 ;; system is refined further; a certain degree of dependence on the CC
80 ;; Mode version is unavoidable when hooking in at this level. Also
81 ;; note that there's still work to be done to actually use these
82 ;; constants everywhere inside CC Mode; there are still hardcoded
83 ;; values in many places in the code.
85 ;; Separate packages will also benefit from the compile time
86 ;; evaluation; the byte compiled file(s) for them will contain the
87 ;; compiled runtime constants ready for use by (the byte compiled) CC
88 ;; Mode, and the source definitions in this file don't have to be
89 ;; loaded then. However, if a byte compiled package is loaded that
90 ;; has been compiled with a different version of CC Mode than the one
91 ;; currently loaded, then the compiled-in values will be discarded and
92 ;; new ones will be built when the mode is initialized. That will
93 ;; automatically trig a load of the file(s) containing the source
94 ;; definitions (i.e. this file and/or cc-fonts.el) if necessary.
96 ;; A small example of a derived mode is available at
97 ;; <http://cc-mode.sourceforge.net/derived-mode-ex.el>. It also
98 ;; contains some useful hints for derived mode developers.
100 ;;; Using language variables:
102 ;; The `c-lang-defvar' forms in this file comprise the language
103 ;; variables that CC Mode uses. It does not work to use
104 ;; `c-lang-defvar' anywhere else (which isn't much of a limitation
105 ;; since these variables sole purpose is to interface with the CC Mode
106 ;; core functions). The values in these `c-lang-defvar's are not
107 ;; evaluated right away but instead collected to a single large `setq'
108 ;; that can be inserted for a particular language with the
109 ;; `c-init-language-vars' macro.
111 ;; This file is only required at compile time, or when not running
112 ;; from byte compiled files, or when the source definitions for the
113 ;; language constants are requested.
119 (unless (fboundp 'declare-function
) (defmacro declare-function
(&rest r
))))
123 (if (and (boundp 'byte-compile-dest-file
)
124 (stringp byte-compile-dest-file
))
125 (cons (file-name-directory byte-compile-dest-file
) load-path
)
127 (load "cc-bytecomp" nil t
)))
129 (cc-require 'cc-defs
)
130 (cc-require 'cc-vars
)
133 ;; This file is not always loaded. See note above.
134 (cc-external-require 'cl
)
137 ;;; Setup for the `c-lang-defvar' system.
140 ;; These are used to collect the init forms from the subsequent
141 ;; `c-lang-defvar' and `c-lang-setvar'. They are used to build the
142 ;; lambda in `c-make-init-lang-vars-fun' below, and to build `defvar's
143 ;; and `make-variable-buffer-local's in cc-engine and
144 ;; `make-local-variable's in `c-init-language-vars-for'.
145 (defvar c-lang-variable-inits nil
)
146 (defvar c-lang-variable-inits-tail nil
)
147 (setq c-lang-variable-inits
(list nil
)
148 c-lang-variable-inits-tail c-lang-variable-inits
)
149 (defvar c-emacs-variable-inits nil
)
150 (defvar c-emacs-variable-inits-tail nil
)
151 (setq c-emacs-variable-inits
(list nil
)
152 c-emacs-variable-inits-tail c-emacs-variable-inits
))
154 (defmacro c-lang-defvar
(var val
&optional doc
)
155 "Declares the buffer local variable VAR to get the value VAL. VAL is
156 evaluated and assigned at mode initialization. More precisely, VAL is
157 evaluated and bound to VAR when the result from the macro
158 `c-init-language-vars' is evaluated.
160 `c-lang-const' is typically used in VAL to get the right value for the
161 language being initialized, and such calls will be macro expanded to
162 the evaluated constant value at compile time."
165 (eq (car-safe val
) 'c-lang-const
)
168 ;; Special case: If there's no docstring and the value is a
169 ;; simple (c-lang-const foo) where foo is the same name as VAR
170 ;; then take the docstring from the language constant foo.
171 (setq doc
(get (intern (symbol-name (nth 1 val
)) c-lang-constants
)
172 'variable-documentation
)))
176 (let ((elem (assq var
(cdr c-lang-variable-inits
))))
178 (setcdr elem
(list val doc
))
179 (setcdr c-lang-variable-inits-tail
(list (list var val doc
)))
180 (setq c-lang-variable-inits-tail
(cdr c-lang-variable-inits-tail
))))
182 ;; Return the symbol, like the other def* forms.
185 (defmacro c-lang-setvar
(var val
)
186 "Causes the variable VAR to be made buffer local and to get set to the
187 value VAL. VAL is evaluated and assigned at mode initialization. More
188 precisely, VAL is evaluated and bound to VAR when the result from the
189 macro `c-init-language-vars' is evaluated. VAR is typically a standard
190 Emacs variable like `comment-start'.
192 `c-lang-const' is typically used in VAL to get the right value for the
193 language being initialized, and such calls will be macro expanded to
194 the evaluated constant value at compile time."
195 (let ((elem (assq var
(cdr c-emacs-variable-inits
))))
197 (setcdr elem
(list val
)) ; Maybe remove "list", sometime. 2006-07-19
198 (setcdr c-emacs-variable-inits-tail
(list (list var val
)))
199 (setq c-emacs-variable-inits-tail
(cdr c-emacs-variable-inits-tail
))))
201 ;; Return the symbol, like the other def* forms.
204 (put 'c-lang-defvar
'lisp-indent-function
'defun
)
205 ; (eval-after-load "edebug" ; 2006-07-09: def-edebug-spec is now in subr.el.
207 (def-edebug-spec c-lang-defvar
208 (&define name def-form
&optional stringp
)) ;)
210 ;; Suppress "might not be defined at runtime" warning.
211 ;; This file is only used when compiling other cc files.
212 (declare-function delete-duplicates
"cl-seq" (cl-seq &rest cl-keys
))
213 (declare-function mapcan
"cl-extra" (cl-func cl-seq
&rest cl-rest
))
214 (declare-function cl-macroexpand-all
"cl-extra" (form &optional env
))
217 ;; Some helper functions used when building the language constants.
219 (defun c-filter-ops (ops opgroup-filter op-filter
&optional xlate
)
220 ;; Extract a subset of the operators in the list OPS in a DWIM:ey
221 ;; way. The return value is a plain list of operators:
223 ;; OPS either has the structure of `c-operators', is a single
224 ;; group in `c-operators', or is a plain list of operators.
226 ;; OPGROUP-FILTER specifies how to select the operator groups. It
227 ;; can be t to choose all groups, a list of group type symbols
228 ;; (such as 'prefix) to accept, or a function which will be called
229 ;; with the group symbol for each group and should return non-nil
230 ;; if that group is to be included.
232 ;; If XLATE is given, it's a function which is called for each
233 ;; matching operator and its return value is collected instead.
234 ;; If it returns a list, the elements are spliced directly into
235 ;; the final result, which is returned as a list with duplicates
236 ;; removed using `equal'.
238 ;; `c-mode-syntax-table' for the current mode is in effect during
239 ;; the whole procedure.
240 (unless (listp (car-safe ops
))
241 (setq ops
(list ops
)))
242 (cond ((eq opgroup-filter t
)
243 (setq opgroup-filter
(lambda (opgroup) t
)))
244 ((not (functionp opgroup-filter
))
245 (setq opgroup-filter
`(lambda (opgroup)
246 (memq opgroup
',opgroup-filter
)))))
247 (cond ((eq op-filter t
)
248 (setq op-filter
(lambda (op) t
)))
250 (setq op-filter
`(lambda (op)
251 (string-match ,op-filter op
)))))
253 (setq xlate
'identity
))
254 (c-with-syntax-table (c-lang-const c-mode-syntax-table
)
256 (mapcan (lambda (opgroup)
257 (when (if (symbolp (car opgroup
))
258 (when (funcall opgroup-filter
(car opgroup
))
259 (setq opgroup
(cdr opgroup
))
263 (when (funcall op-filter op
)
264 (let ((res (funcall xlate op
)))
265 (if (listp res
) res
(list res
)))))
271 ;;; Various mode specific values that aren't language related.
273 (c-lang-defconst c-mode-menu
274 ;; The definition for the mode menu. The menu title is prepended to
275 ;; this before it's fed to `easy-menu-define'.
276 t
`(["Comment Out Region" comment-region
277 (c-fn-region-is-active-p)]
278 ["Uncomment Region" (comment-region (region-beginning)
280 (c-fn-region-is-active-p)]
281 ["Indent Expression" c-indent-exp
282 (memq (char-after) '(?\
( ?\
[ ?\
{))]
283 ["Indent Line or Region" c-indent-line-or-region t
]
284 ["Fill Comment Paragraph" c-fill-paragraph t
]
286 ["Backward Statement" c-beginning-of-statement t
]
287 ["Forward Statement" c-end-of-statement t
]
288 ,@(when (c-lang-const c-opt-cpp-prefix
)
289 ;; Only applicable if there's a cpp preprocessor.
290 `(["Up Conditional" c-up-conditional t
]
291 ["Backward Conditional" c-backward-conditional t
]
292 ["Forward Conditional" c-forward-conditional t
]
294 ["Macro Expand Region" c-macro-expand
295 (c-fn-region-is-active-p)]
296 ["Backslashify" c-backslash-region
297 (c-fn-region-is-active-p)]))
300 ["Syntactic indentation" c-toggle-syntactic-indentation
301 :style toggle
:selected c-syntactic-indentation
]
302 ["Electric mode" c-toggle-electric-state
303 :style toggle
:selected c-electric-flag
]
304 ["Auto newline" c-toggle-auto-newline
305 :style toggle
:selected c-auto-newline
]
306 ["Hungry delete" c-toggle-hungry-state
307 :style toggle
:selected c-hungry-delete-key
]
308 ["Subword mode" subword-mode
309 :style toggle
:selected
(and (boundp 'subword-mode
)
315 (defun c-populate-syntax-table (table)
316 "Populate the given syntax table as necessary for a C-like language.
317 This includes setting ' and \" as string delimiters, and setting up
318 the comment syntax to handle both line style \"//\" and block style
319 \"/*\" \"*/\" comments."
321 (modify-syntax-entry ?_
"_" table
)
322 (modify-syntax-entry ?
\\ "\\" table
)
323 (modify-syntax-entry ?
+ "." table
)
324 (modify-syntax-entry ?-
"." table
)
325 (modify-syntax-entry ?
= "." table
)
326 (modify-syntax-entry ?%
"." table
)
327 (modify-syntax-entry ?
< "." table
)
328 (modify-syntax-entry ?
> "." table
)
329 (modify-syntax-entry ?
& "." table
)
330 (modify-syntax-entry ?|
"." table
)
331 (modify-syntax-entry ?
\' "\"" table
)
332 (modify-syntax-entry ?
\240 "." table
)
334 ;; Set up block and line oriented comments. The new C
335 ;; standard mandates both comment styles even in C, so since
336 ;; all languages now require dual comments, we make this the
340 ((memq '8-bit c-emacs-features
)
341 (modify-syntax-entry ?
/ ". 1456" table
)
342 (modify-syntax-entry ?
* ". 23" table
))
344 ((memq '1-bit c-emacs-features
)
345 (modify-syntax-entry ?
/ ". 124b" table
)
346 (modify-syntax-entry ?
* ". 23" table
))
348 (t (error "CC Mode is incompatible with this version of Emacs")))
350 (modify-syntax-entry ?
\n "> b" table
)
351 ;; Give CR the same syntax as newline, for selective-display
352 (modify-syntax-entry ?\^m
"> b" table
))
354 (c-lang-defconst c-make-mode-syntax-table
355 "Functions that generates the mode specific syntax tables.
356 The syntax tables aren't stored directly since they're quite large."
358 (let ((table (make-syntax-table)))
359 (c-populate-syntax-table table
)
360 ;; Mode specific syntaxes.
361 ,(cond ((or (c-major-mode-is 'objc-mode
) (c-major-mode-is 'java-mode
))
362 ;; Let '@' be part of symbols in ObjC to cope with
363 ;; its compiler directives as single keyword tokens.
364 ;; This is then necessary since it's assumed that
365 ;; every keyword is a single symbol.
366 `(modify-syntax-entry ?
@ "_" table
))
367 ((c-major-mode-is 'pike-mode
)
368 `(modify-syntax-entry ?
@ "." table
)))
371 (c-lang-defconst c-mode-syntax-table
372 ;; The syntax tables in evaluated form. Only used temporarily when
373 ;; the constants in this file are evaluated.
374 t
(funcall (c-lang-const c-make-mode-syntax-table
)))
376 (c-lang-defconst c
++-make-template-syntax-table
377 ;; A variant of `c++-mode-syntax-table' that defines `<' and `>' as
378 ;; parenthesis characters. Used temporarily when template argument
379 ;; lists are parsed. Note that this encourages incorrect parsing of
380 ;; templates since they might contain normal operators that uses the
381 ;; '<' and '>' characters. Therefore this syntax table might go
382 ;; away when CC Mode handles templates correctly everywhere.
384 (java c
++) `(lambda ()
385 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table
))))
386 (modify-syntax-entry ?
< "(>" table
)
387 (modify-syntax-entry ?
> ")<" table
)
389 (c-lang-defvar c
++-template-syntax-table
390 (and (c-lang-const c
++-make-template-syntax-table
)
391 (funcall (c-lang-const c
++-make-template-syntax-table
))))
393 (c-lang-defconst c-no-parens-syntax-table
394 ;; A variant of the standard syntax table which is used to find matching
395 ;; "<"s and ">"s which have been marked as parens using syntax table
396 ;; properties. The other paren characters (e.g. "{", ")" "]") are given a
397 ;; non-paren syntax here. so that the list commands will work on "< ... >"
398 ;; even when there's unbalanced other parens inside them.
400 ;; This variable is nil for languages which don't have template stuff.
402 (if (c-lang-const c-recognize-
<>-arglists
)
403 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table
))))
404 (modify-syntax-entry ?\
( "." table
)
405 (modify-syntax-entry ?\
) "." table
)
406 (modify-syntax-entry ?\
[ "." table
)
407 (modify-syntax-entry ?\
] "." table
)
408 (modify-syntax-entry ?\
{ "." table
)
409 (modify-syntax-entry ?\
} "." table
)
411 (c-lang-defvar c-no-parens-syntax-table
412 (funcall (c-lang-const c-no-parens-syntax-table
)))
414 (c-lang-defconst c-identifier-syntax-modifications
415 "A list that describes the modifications that should be done to the
416 mode syntax table to get a syntax table that matches all identifiers
417 and keywords as words.
419 The list is just like the one used in `font-lock-defaults': Each
420 element is a cons where the car is the character to modify and the cdr
421 the new syntax, as accepted by `modify-syntax-entry'."
422 ;; The $ character is not allowed in most languages (one exception
423 ;; is Java which allows it for legacy reasons) but we still classify
424 ;; it as an indentifier character since it's often used in various
425 ;; machine generated identifiers.
426 t
'((?_ .
"w") (?$ .
"w"))
427 (objc java
) (append '((?
@ .
"w"))
428 (c-lang-const c-identifier-syntax-modifications
))
430 (c-lang-defvar c-identifier-syntax-modifications
431 (c-lang-const c-identifier-syntax-modifications
))
433 (c-lang-defvar c-identifier-syntax-table
434 (let ((table (copy-syntax-table (c-mode-var "mode-syntax-table")))
435 (mods c-identifier-syntax-modifications
)
440 (modify-syntax-entry (car mod
) (cdr mod
) table
))
442 "Syntax table built on the mode syntax table but additionally
443 classifies symbol constituents like '_' and '$' as word constituents,
444 so that all identifiers are recognized as words.")
446 (c-lang-defconst c-get-state-before-change-functions
447 ;; For documentation see the following c-lang-defvar of the same name.
448 ;; The value here may be a list of functions or a single function.
450 c
++ '(c-extend-region-for-CPP c-before-change-check-
<>-operators
)
451 (c objc
) 'c-extend-region-for-CPP
452 ;; java 'c-before-change-check-<>-operators
453 awk
'c-awk-record-region-clear-NL
)
454 (c-lang-defvar c-get-state-before-change-functions
455 (let ((fs (c-lang-const c-get-state-before-change-functions
)))
459 "If non-nil, a list of functions called from c-before-change-hook.
460 Typically these will record enough state to allow
461 `c-before-font-lock-function' to extend the region to fontify,
462 and may do such things as removing text-properties which must be
465 These functions will be run in the order given. Each of them
466 takes 2 parameters, the BEG and END supplied to every
467 before-change function; on entry, the buffer will have been
468 widened and match-data will have been saved; point is undefined
469 on both entry and exit; the return value is ignored.
471 The functions are called even when font locking isn't enabled.
473 When the mode is initialized, the functions are called with
474 parameters \(point-min) and \(point-max).")
476 (c-lang-defconst c-before-font-lock-function
477 "If non-nil, a function called just before font locking.
478 Typically it will extend the region about to be fontified \(see
479 below) and will set `syntax-table' text properties on the region.
481 It takes 3 parameters, the BEG, END, and OLD-LEN supplied to
482 every after-change function; point is undefined on both entry and
483 exit; on entry, the buffer will have been widened and match-data
484 will have been saved; the return value is ignored.
486 The function may extend the region to be fontified by setting the
487 buffer local variables c-new-BEG and c-new-END.
489 The function is called even when font locking is disabled.
491 When the mode is initialized, this function is called with
492 parameters \(point-min), \(point-max) and <buffer size>."
494 (c c
++ objc
) 'c-neutralize-syntax-in-and-mark-CPP
495 awk
'c-awk-extend-and-syntax-tablify-region
)
496 (c-lang-defvar c-before-font-lock-function
497 (c-lang-const c-before-font-lock-function
))
500 ;;; Lexer-level syntax (identifiers, tokens etc).
502 (c-lang-defconst c-symbol-start
503 "Regexp that matches the start of a symbol, i.e. any identifier or
504 keyword. It's unspecified how far it matches. Does not contain a \\|
505 operator at the top level."
506 t
(concat "[" c-alpha
"_]")
507 java
(concat "[" c-alpha
"_@]")
508 objc
(concat "[" c-alpha
"@]")
509 pike
(concat "[" c-alpha
"_`]"))
510 (c-lang-defvar c-symbol-start
(c-lang-const c-symbol-start
))
512 (c-lang-defconst c-symbol-chars
513 "Set of characters that can be part of a symbol.
514 This is on the form that fits inside [ ] in a regexp."
515 ;; Pike note: With the backquote identifiers this would include most
516 ;; operator chars too, but they are handled with other means instead.
517 t
(concat c-alnum
"_$")
518 objc
(concat c-alnum
"_$@"))
520 (c-lang-defconst c-symbol-key
521 "Regexp matching identifiers and keywords (with submatch 0). Assumed
522 to match if `c-symbol-start' matches on the same position."
523 t
(concat (c-lang-const c-symbol-start
)
524 "[" (c-lang-const c-symbol-chars
) "]*")
526 ;; Use the value from C here since the operator backquote is
527 ;; covered by the other alternative.
528 (c-lang-const c-symbol-key c
)
530 (c-make-keywords-re nil
531 (c-lang-const c-overloadable-operators
))))
532 (c-lang-defvar c-symbol-key
(c-lang-const c-symbol-key
))
534 (c-lang-defconst c-symbol-key-depth
535 ;; Number of regexp grouping parens in `c-symbol-key'.
536 t
(regexp-opt-depth (c-lang-const c-symbol-key
)))
538 (c-lang-defconst c-nonsymbol-chars
539 "This is the set of chars that can't be part of a symbol, i.e. the
540 negation of `c-symbol-chars'."
541 t
(concat "^" (c-lang-const c-symbol-chars
)))
542 (c-lang-defvar c-nonsymbol-chars
(c-lang-const c-nonsymbol-chars
))
544 (c-lang-defconst c-nonsymbol-key
545 "Regexp that matches any character that can't be part of a symbol.
546 It's usually appended to other regexps to avoid matching a prefix.
547 It's assumed to not contain any submatchers."
548 ;; The same thing regarding Unicode identifiers applies here as to
550 t
(concat "[" (c-lang-const c-nonsymbol-chars
) "]"))
552 (c-lang-defconst c-identifier-ops
553 "The operators that make up fully qualified identifiers. nil in
554 languages that don't have such things. See `c-operators' for a
555 description of the format. Binary operators can concatenate symbols,
556 e.g. \"::\" in \"A::B::C\". Prefix operators can precede identifiers,
557 e.g. \"~\" in \"~A::B\". Other types of operators aren't supported.
559 This value is by default merged into `c-operators'."
561 c
++ '((prefix "~" "??-" "compl")
564 ;; Java has "." to concatenate identifiers but it's also used for
565 ;; normal indexing. There's special code in the Java font lock
566 ;; rules to fontify qualified identifiers based on the standard
567 ;; naming conventions. We still define "." here to make
568 ;; `c-forward-name' move over as long names as possible which is
569 ;; necessary to e.g. handle throws clauses correctly.
570 java
'((left-assoc "."))
571 idl
'((left-assoc "::")
573 pike
'((left-assoc "::")
577 (c-lang-defconst c-opt-identifier-concat-key
578 ;; Appendable adorned regexp matching the operators that join
579 ;; symbols to fully qualified identifiers, or nil in languages that
580 ;; don't have such things.
582 ;; This was a docstring constant in 5.30. It still works but is now
583 ;; considered internal - change `c-identifier-ops' instead.
584 t
(let ((ops (c-filter-ops (c-lang-const c-identifier-ops
)
585 '(left-assoc right-assoc
)
588 (c-make-keywords-re 'appendable ops
))))
589 (c-lang-defvar c-opt-identifier-concat-key
590 (c-lang-const c-opt-identifier-concat-key
)
593 (c-lang-defconst c-opt-identifier-concat-key-depth
594 ;; Number of regexp grouping parens in `c-opt-identifier-concat-key'.
595 t
(regexp-opt-depth (c-lang-const c-opt-identifier-concat-key
)))
597 (c-lang-defconst c-opt-identifier-prefix-key
598 ;; Appendable adorned regexp matching operators that might precede
599 ;; an identifier and that are part of the identifier in that case.
600 ;; nil in languages without such things.
601 t
(let ((ops (c-filter-ops (c-lang-const c-identifier-ops
)
605 (c-make-keywords-re 'appendable ops
))))
607 (c-lang-defconst c-after-id-concat-ops
608 "Operators that can occur after a binary operator on `c-identifier-ops'
609 in identifiers. nil in languages that don't have such things.
611 Operators here should also have appropriate entries in `c-operators' -
612 it's not taken care of by default."
614 ;; '~' for destructors in C++, '*' for member pointers.
616 ;; In Java we recognize '*' to deal with "foo.bar.*" that can occur
617 ;; in import declarations. (This will also match bogus things like
618 ;; "foo.*bar" but we don't bother.)
621 (c-lang-defconst c-opt-after-id-concat-key
622 ;; Regexp that must match the token after
623 ;; `c-opt-identifier-concat-key' for it to be considered an
624 ;; identifier concatenation operator (which e.g. causes the
625 ;; preceding identifier to be fontified as a reference). Assumed to
626 ;; be a string if `c-opt-identifier-concat-key' is.
628 ;; This was a docstring constant in 5.30. It still works but is now
629 ;; considered internal - change `c-after-id-concat-ops' instead.
630 t
(concat (c-lang-const c-symbol-start
)
631 (if (c-lang-const c-after-id-concat-ops
)
632 (concat "\\|" (c-make-keywords-re 'appendable
633 (c-lang-const c-after-id-concat-ops
)))
636 (c-lang-defconst c-identifier-start
637 "Regexp that matches the start of an (optionally qualified) identifier.
638 It should also match all keywords. It's unspecified how far it
640 t
(concat (c-lang-const c-symbol-start
)
641 (if (c-lang-const c-opt-identifier-prefix-key
)
643 (c-lang-const c-opt-identifier-prefix-key
))
645 (c-lang-defvar c-identifier-start
(c-lang-const c-identifier-start
))
647 (c-lang-defconst c-identifier-key
648 "Regexp matching a fully qualified identifier, like \"A::B::c\" in
649 C++. It does not recognize the full range of syntactic whitespace
650 between the tokens; `c-forward-name' has to be used for that. It
651 should also not match identifiers containing parenthesis groupings,
652 e.g. identifiers with template arguments such as \"A<X,Y>\" in C++."
653 ;; This regexp is more complex than strictly necessary to ensure
654 ;; that it can be matched with a minimum of backtracking.
655 t
(concat (if (c-lang-const c-opt-identifier-prefix-key
)
658 (c-lang-const c-opt-identifier-prefix-key
)
659 (c-lang-const c-simple-ws
) "*"
662 "\\(" (c-lang-const c-symbol-key
) "\\)"
663 (if (c-lang-const c-opt-identifier-concat-key
)
666 (c-lang-const c-simple-ws
) "*"
667 (c-lang-const c-opt-identifier-concat-key
)
668 (c-lang-const c-simple-ws
) "*"
669 (if (c-lang-const c-after-id-concat-ops
)
672 (c-make-keywords-re 'appendable
673 (c-lang-const c-after-id-concat-ops
))
675 ;; For flexibility, consider the symbol match
676 ;; optional if we've hit a
677 ;; `c-after-id-concat-ops' operator. This is
678 ;; also necessary to handle the "*" that can
679 ;; end import declaration identifiers in Java.
681 (c-lang-const c-simple-ws
) "*"
682 "\\(" (c-lang-const c-symbol-key
) "\\)"
685 "\\(" (c-lang-const c-symbol-key
) "\\)"
687 (concat "\\(" (c-lang-const c-symbol-key
) "\\)"))
690 (c-lang-defvar c-identifier-key
(c-lang-const c-identifier-key
))
692 (c-lang-defconst c-identifier-last-sym-match
693 ;; This was a docstring constant in 5.30 but it's no longer used.
694 ;; It's only kept to avoid breaking third party code.
696 ;; Used to identify the submatch in `c-identifier-key' that
697 ;; surrounds the last symbol in the qualified identifier. It's a
698 ;; list of submatch numbers, of which the first that has a match is
699 ;; taken. It's assumed that at least one does when the regexp has
703 (c-lang-defconst c-string-escaped-newlines
704 "Set if the language support backslash escaped newlines inside string
708 (c-lang-defvar c-string-escaped-newlines
709 (c-lang-const c-string-escaped-newlines
))
711 (c-lang-defconst c-multiline-string-start-char
712 "Set if the language supports multiline string literals without escaped
713 newlines. If t, all string literals are multiline. If a character,
714 only literals where the open quote is immediately preceded by that
715 literal are multiline."
718 (c-lang-defvar c-multiline-string-start-char
719 (c-lang-const c-multiline-string-start-char
))
721 (c-lang-defconst c-opt-cpp-prefix
722 "Regexp matching the prefix of a cpp directive in the languages that
723 normally use that macro preprocessor. Tested at bol or at boi.
724 Assumed to not contain any submatches or \\| operators."
725 ;; TODO (ACM, 2005-04-01). Amend the following to recognise escaped NLs;
726 ;; amend all uses of c-opt-cpp-prefix which count regexp-depth.
729 (c-lang-defvar c-opt-cpp-prefix
(c-lang-const c-opt-cpp-prefix
))
731 (c-lang-defconst c-anchored-cpp-prefix
732 "Regexp matching the prefix of a cpp directive anchored to BOL,
733 in the languages that have a macro preprocessor."
734 t
(if (c-lang-const c-opt-cpp-prefix
)
735 (concat "^" (c-lang-const c-opt-cpp-prefix
))))
736 (c-lang-defvar c-anchored-cpp-prefix
(c-lang-const c-anchored-cpp-prefix
))
738 (c-lang-defconst c-opt-cpp-start
739 "Regexp matching the prefix of a cpp directive including the directive
740 name, or nil in languages without preprocessor support. The first
741 submatch surrounds the directive name."
742 t
(if (c-lang-const c-opt-cpp-prefix
)
743 (concat (c-lang-const c-opt-cpp-prefix
)
744 "\\([" c-alnum
"]+\\)"))
745 ;; Pike, being a scripting language, recognizes hash-bangs too.
746 pike
(concat (c-lang-const c-opt-cpp-prefix
)
747 "\\([" c-alnum
"]+\\|!\\)"))
748 (c-lang-defvar c-opt-cpp-start
(c-lang-const c-opt-cpp-start
))
750 (c-lang-defconst c-cpp-message-directives
751 "List of cpp directives (without the prefix) that are followed by a
753 t
(if (c-lang-const c-opt-cpp-prefix
)
755 (c c
++ objc pike
) '("error" "warning"))
757 (c-lang-defconst c-cpp-include-directives
758 "List of cpp directives (without the prefix) that are followed by a
759 file name in angle brackets or quotes."
760 t
(if (c-lang-const c-opt-cpp-prefix
)
762 objc
'("include" "import"))
764 (c-lang-defconst c-opt-cpp-macro-define
765 "Cpp directive (without the prefix) that is followed by a macro
766 definition, or nil if the language doesn't have any."
767 t
(if (c-lang-const c-opt-cpp-prefix
)
770 (c-lang-defconst c-opt-cpp-macro-define-start
771 ;; Regexp matching everything up to the macro body of a cpp define, or the
772 ;; end of the logical line if there is none. Submatch 1 is the name of the
773 ;; macro. Set if c-opt-cpp-macro-define is.
774 t
(if (c-lang-const c-opt-cpp-macro-define
)
775 (concat (c-lang-const c-opt-cpp-prefix
)
776 (c-lang-const c-opt-cpp-macro-define
)
777 "[ \t]+\\(\\(\\sw\\|_\\)+\\)\\(\([^\)]*\)\\)?"
779 "\\([ \t]\\|\\\\\n\\)*")))
780 (c-lang-defvar c-opt-cpp-macro-define-start
781 (c-lang-const c-opt-cpp-macro-define-start
))
783 (c-lang-defconst c-opt-cpp-macro-define-id
784 ;; Regexp matching everything up to the end of the identifier defined
786 t
(if (c-lang-const c-opt-cpp-macro-define
)
787 (concat (c-lang-const c-opt-cpp-prefix
) ; #
788 (c-lang-const c-opt-cpp-macro-define
) ; define
789 "[ \t]+\\(\\sw\\|_\\)+")))
790 (c-lang-defvar c-opt-cpp-macro-define-id
791 (c-lang-const c-opt-cpp-macro-define-id
))
793 (c-lang-defconst c-cpp-expr-directives
794 "List of cpp directives (without the prefix) that are followed by an
796 t
(if (c-lang-const c-opt-cpp-prefix
)
799 (c-lang-defconst c-cpp-expr-functions
800 "List of functions in cpp expressions."
801 t
(if (c-lang-const c-opt-cpp-prefix
)
803 pike
'("defined" "efun" "constant"))
805 (c-lang-defconst c-assignment-operators
806 "List of all assignment operators."
807 t
'("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=")
808 java
(append (c-lang-const c-assignment-operators
)
810 c
++ (append (c-lang-const c-assignment-operators
)
811 '("and_eq" "or_eq" "xor_eq" "??!=" "??'="))
814 (c-lang-defconst c-operators
815 "List describing all operators, along with their precedence and
816 associativity. The order in the list corresponds to the precedence of
817 the operators: The operators in each element are a group with the same
818 precedence, and the group has higher precedence than the groups in all
819 following elements. The car of each element describes the type of the
820 operator group, and the cdr is a list of the operator tokens in it.
821 The operator group types are:
823 'prefix Unary prefix operators.
824 'postfix Unary postfix operators.
826 Unary postfix operators if and only if the chars have
828 'left-assoc Binary left associative operators (i.e. a+b+c means (a+b)+c).
829 'right-assoc Binary right associative operators (i.e. a=b=c means a=(b=c)).
830 'right-assoc-sequence
831 Right associative operator that constitutes of a
832 sequence of tokens that separate expressions. All the
833 tokens in the group are in this case taken as
834 describing the sequence in one such operator, and the
835 order between them is therefore significant.
837 Operators containing a character with paren syntax are taken to match
838 with a corresponding open/close paren somewhere else. A postfix
839 operator with close paren syntax is taken to end a postfix expression
840 started somewhere earlier, rather than start a new one at point. Vice
841 versa for prefix operators with open paren syntax.
843 Note that operators like \".\" and \"->\" which in language references
844 often are described as postfix operators are considered binary here,
845 since CC Mode treats every identifier as an expression."
847 ;; There's currently no code in CC Mode that exploit all the info
848 ;; in this variable; precedence, associativity etc are present as a
849 ;; preparation for future work.
852 ,@(when (c-lang-const c-opt-cpp-prefix
)
854 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
857 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
858 '("%:%:" "??=??=")))))
861 ,@(c-lang-const c-identifier-ops
)
862 ,@(cond ((or (c-major-mode-is 'c
++-mode
) (c-major-mode-is 'java-mode
))
863 `((postfix-if-paren "<" ">"))) ; Templates.
864 ((c-major-mode-is 'pike-mode
)
865 `((prefix "global" "predef")))
866 ((c-major-mode-is 'java-mode
)
867 `((prefix "super"))))
870 ,@(when (c-major-mode-is 'c
++-mode
)
871 ;; The following need special treatment.
872 `((prefix "dynamic_cast" "static_cast"
873 "reinterpret_cast" "const_cast" "typeid")))
875 ,@(unless (c-major-mode-is 'java-mode
)
877 (postfix "++" "--" "[" "]" "(" ")"
878 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
879 '("<:" ":>" "??(" "??)")))
882 (prefix "++" "--" "+" "-" "!" "~"
883 ,@(when (c-major-mode-is 'c
++-mode
) '("not" "compl"))
884 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
885 '("*" "&" "sizeof" "??-"))
886 ,@(when (c-major-mode-is 'objc-mode
)
887 '("@selector" "@protocol" "@encode"))
888 ;; The following need special treatment.
889 ,@(cond ((c-major-mode-is 'c
++-mode
)
891 ((c-major-mode-is 'java-mode
)
893 ((c-major-mode-is 'pike-mode
)
894 '("class" "lambda" "catch" "throw" "gauge")))
896 ,@(when (c-major-mode-is 'pike-mode
)
897 '("[" "]"))) ; Type cast.
900 ,@(when (c-major-mode-is 'c
++-mode
)
901 `((left-assoc ".*" "->*")))
904 (left-assoc "*" "/" "%")
910 (left-assoc "<<" ">>"
911 ,@(when (c-major-mode-is 'java-mode
)
915 (left-assoc "<" ">" "<=" ">="
916 ,@(when (c-major-mode-is 'java-mode
)
920 (left-assoc "==" "!="
921 ,@(when (c-major-mode-is 'c
++-mode
) '("not_eq")))
925 ,@(when (c-major-mode-is 'c
++-mode
) '("bitand")))
927 ;; Bitwise exclusive or.
929 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
931 ,@(when (c-major-mode-is 'c
++-mode
) '("xor")))
935 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
937 ,@(when (c-major-mode-is 'c
++-mode
) '("bitor")))
941 ,@(when (c-major-mode-is 'c
++-mode
) '("and")))
945 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
947 ,@(when (c-major-mode-is 'c
++-mode
) '("or")))
950 (right-assoc-sequence "?" ":")
953 (right-assoc ,@(c-lang-const c-assignment-operators
))
956 ,@(when (c-major-mode-is 'c
++-mode
)
962 ;; IDL got its own definition since it has a much smaller operator
963 ;; set than the other languages.
964 idl
`(;; Preprocessor.
968 ,@(c-lang-const c-identifier-ops
)
972 (left-assoc "*" "/" "%")
976 (left-assoc "<<" ">>")
984 (c-lang-defconst c-operator-list
985 ;; The operators as a flat list (without duplicates).
986 t
(c-filter-ops (c-lang-const c-operators
) t t
))
988 (c-lang-defconst c-overloadable-operators
989 "List of the operators that are overloadable, in their \"identifier
990 form\". See also `c-op-identifier-prefix'."
992 c
++ '("new" "delete" ;; Can be followed by "[]" but we ignore that.
994 "^" "??'" "xor" "&" "bitand" "|" "??!" "bitor" "~" "??-" "compl"
995 "!" "=" "<" ">" "+=" "-=" "*=" "/=" "%=" "^="
996 "??'=" "xor_eq" "&=" "and_eq" "|=" "??!=" "or_eq"
997 "<<" ">>" ">>=" "<<=" "==" "!=" "not_eq" "<=" ">="
998 "&&" "and" "||" "??!??!" "or" "++" "--" "," "->*" "->"
999 "()" "[]" "<::>" "??(??)")
1000 ;; These work like identifiers in Pike.
1001 pike
'("`+" "`-" "`&" "`|" "`^" "`<<" "`>>" "`*" "`/" "`%" "`~"
1002 "`==" "`<" "`>" "`!" "`[]" "`[]=" "`->" "`->=" "`()" "``+"
1003 "``-" "``&" "``|" "``^" "``<<" "``>>" "``*" "``/" "``%"
1006 (c-lang-defconst c-overloadable-operators-regexp
1007 ;; Regexp tested after an "operator" token in C++.
1009 c
++ (c-make-keywords-re nil
(c-lang-const c-overloadable-operators
)))
1010 (c-lang-defvar c-overloadable-operators-regexp
1011 (c-lang-const c-overloadable-operators-regexp
))
1013 (c-lang-defconst c-opt-op-identifier-prefix
1014 "Regexp matching the token before the ones in
1015 `c-overloadable-operators' when operators are specified in their
1016 \"identifier form\". This typically matches \"operator\" in C++ where
1017 operator functions are specified as e.g. \"operator +\". It's nil in
1018 languages without operator functions or where the complete operator
1019 identifier is listed in `c-overloadable-operators'.
1021 This regexp is assumed to not match any non-operator identifier."
1023 c
++ (c-make-keywords-re t
'("operator")))
1024 (c-lang-defvar c-opt-op-identifier-prefix
1025 (c-lang-const c-opt-op-identifier-prefix
))
1027 ;; Note: the following alias is an old name which was a mis-spelling. It has
1028 ;; been corrected above and throughout cc-engine.el. It will be removed at
1029 ;; some release very shortly in the future. ACM, 2006-04-14.
1030 (defvaralias 'c-opt-op-identitier-prefix
'c-opt-op-identifier-prefix
)
1031 (make-obsolete-variable 'c-opt-op-identitier-prefix
'c-opt-op-identifier-prefix
1032 "CC Mode 5.31.4, 2006-04-14")
1034 (c-lang-defconst c-other-op-syntax-tokens
1035 "List of the tokens made up of characters in the punctuation or
1036 parenthesis syntax classes that have uses other than as expression
1038 t
'("{" "}" "(" ")" "[" "]" ";" ":" "," "=" "/*" "*/" "//")
1039 (c c
++ pike
) (append '("#" "##" ; Used by cpp.
1041 (c-lang-const c-other-op-syntax-tokens
))
1042 (c c
++) (append '("*") (c-lang-const c-other-op-syntax-tokens
))
1043 c
++ (append '("&" "<%" "%>" "<:" ":>" "%:" "%:%:")
1044 (c-lang-const c-other-op-syntax-tokens
))
1045 objc
(append '("#" "##" ; Used by cpp.
1046 "+" "-") (c-lang-const c-other-op-syntax-tokens
))
1047 idl
(append '("#" "##") ; Used by cpp.
1048 (c-lang-const c-other-op-syntax-tokens
))
1049 pike
(append '("..")
1050 (c-lang-const c-other-op-syntax-tokens
)
1051 (c-lang-const c-overloadable-operators
))
1052 awk
'("{" "}" "(" ")" "[" "]" ";" "," "=" "/"))
1054 (c-lang-defconst c-all-op-syntax-tokens
1055 ;; List of all tokens in the punctuation and parenthesis syntax
1057 t
(delete-duplicates (append (c-lang-const c-other-op-syntax-tokens
)
1058 (c-lang-const c-operator-list
))
1059 :test
'string-equal
))
1061 (c-lang-defconst c-nonsymbol-token-char-list
1062 ;; List containing all chars not in the word, symbol or
1063 ;; syntactically irrelevant syntax classes, i.e. all punctuation,
1064 ;; parenthesis and string delimiter chars.
1065 t
(c-with-syntax-table (c-lang-const c-mode-syntax-table
)
1066 ;; Only go through the chars in the printable ASCII range. No
1067 ;; language so far has 8-bit or widestring operators.
1068 (let (list (char 32))
1070 (or (memq (char-syntax char
) '(?w ?_ ?
< ?
> ?\
))
1071 (setq list
(cons (c-int-to-char char
) list
)))
1072 (setq char
(1+ char
)))
1075 (c-lang-defconst c-nonsymbol-token-regexp
1076 ;; Regexp matching all tokens in the punctuation and parenthesis
1077 ;; syntax classes. Note that this also matches ".", which can start
1079 t
(c-make-keywords-re nil
1080 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
1082 "\\`\\(\\s.\\|\\s\(\\|\\s\)\\)+\\'")))
1083 (c-lang-defvar c-nonsymbol-token-regexp
1084 (c-lang-const c-nonsymbol-token-regexp
))
1086 (c-lang-defconst c-assignment-op-regexp
1087 ;; Regexp matching all assignment operators and only them. The
1088 ;; beginning of the first submatch is used to detect the end of the
1089 ;; token, along with the end of the whole match.
1090 t
(if (c-lang-const c-assignment-operators
)
1092 ;; Need special case for "=" since it's a prefix of "==".
1095 (c-make-keywords-re nil
1096 (set-difference (c-lang-const c-assignment-operators
)
1098 :test
'string-equal
)))
1100 (c-lang-defvar c-assignment-op-regexp
1101 (c-lang-const c-assignment-op-regexp
))
1103 (c-lang-defconst c-
<>-multichar-token-regexp
1104 ;; Regexp matching all tokens containing "<" or ">" which are longer
1106 t
(c-make-keywords-re nil
1107 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
1110 (c-lang-defvar c-
<>-multichar-token-regexp
1111 (c-lang-const c-
<>-multichar-token-regexp
))
1113 (c-lang-defconst c-
<-op-cont-regexp
1114 ;; Regexp matching the second and subsequent characters of all
1115 ;; multicharacter tokens that begin with "<".
1116 t
(c-make-keywords-re nil
1117 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
1120 (lambda (op) (substring op
1)))))
1122 (c-lang-defvar c-
<-op-cont-regexp
(c-lang-const c-
<-op-cont-regexp
))
1124 (c-lang-defconst c-
>-op-cont-regexp
1125 ;; Regexp matching the second and subsequent characters of all
1126 ;; multicharacter tokens that begin with ">".
1127 t
(c-make-keywords-re nil
1128 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
1131 (lambda (op) (substring op
1))))
1132 java
(c-make-keywords-re nil
1133 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
1135 "\\`>[^>]\\|\\`>>[^>]"
1136 (lambda (op) (substring op
1)))))
1138 (c-lang-defvar c-
>-op-cont-regexp
(c-lang-const c-
>-op-cont-regexp
))
1140 (c-lang-defconst c-stmt-delim-chars
1141 ;; The characters that should be considered to bound statements. To
1142 ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to
1143 ;; begin with "^" to negate the set. If ? : operators should be
1144 ;; detected then the string must end with "?:".
1146 awk
"^;{}#\n\r?:") ; The newline chars gets special treatment.
1147 (c-lang-defvar c-stmt-delim-chars
(c-lang-const c-stmt-delim-chars
))
1149 (c-lang-defconst c-stmt-delim-chars-with-comma
1150 ;; Variant of `c-stmt-delim-chars' that additionally contains ','.
1152 awk
"^;,{}\n\r?:") ; The newline chars gets special treatment.
1153 (c-lang-defvar c-stmt-delim-chars-with-comma
1154 (c-lang-const c-stmt-delim-chars-with-comma
))
1157 ;;; Syntactic whitespace.
1159 (c-lang-defconst c-simple-ws
1160 "Regexp matching an ordinary whitespace character.
1161 Does not contain a \\| operator at the top level."
1162 ;; "\\s " is not enough since it doesn't match line breaks.
1163 t
"\\(\\s \\|[\n\r]\\)")
1165 (c-lang-defconst c-simple-ws-depth
1166 ;; Number of regexp grouping parens in `c-simple-ws'.
1167 t
(regexp-opt-depth (c-lang-const c-simple-ws
)))
1169 (c-lang-defconst c-line-comment-starter
1170 "String that starts line comments, or nil if such don't exist.
1171 Line comments are always terminated by newlines. At least one of
1172 `c-block-comment-starter' and this one is assumed to be set.
1174 Note that it's currently not enough to set this to support a new
1175 comment style. Other stuff like the syntax table must also be set up
1179 (c-lang-defvar c-line-comment-starter
(c-lang-const c-line-comment-starter
))
1181 (c-lang-defconst c-block-comment-starter
1182 "String that starts block comments, or nil if such don't exist.
1183 Block comments are ended by `c-block-comment-ender', which is assumed
1184 to be set if this is. At least one of `c-line-comment-starter' and
1185 this one is assumed to be set.
1187 Note that it's currently not enough to set this to support a new
1188 comment style. Other stuff like the syntax table must also be set up
1193 (c-lang-defconst c-block-comment-ender
1194 "String that ends block comments, or nil if such don't exist.
1196 Note that it's currently not enough to set this to support a new
1197 comment style. Other stuff like the syntax table must also be set up
1202 (c-lang-defconst c-comment-start-regexp
1203 ;; Regexp to match the start of any type of comment.
1204 t
(let ((re (c-make-keywords-re nil
1205 (list (c-lang-const c-line-comment-starter
)
1206 (c-lang-const c-block-comment-starter
)))))
1207 (if (memq 'gen-comment-delim c-emacs-features
)
1208 (concat re
"\\|\\s!")
1210 (c-lang-defvar c-comment-start-regexp
(c-lang-const c-comment-start-regexp
))
1212 ;;;; Added by ACM, 2003/9/18.
1213 (c-lang-defconst c-block-comment-start-regexp
1214 ;; Regexp which matches the start of a block comment (if such exists in the
1216 t
(if (c-lang-const c-block-comment-starter
)
1217 (regexp-quote (c-lang-const c-block-comment-starter
))
1219 (c-lang-defvar c-block-comment-start-regexp
1220 (c-lang-const c-block-comment-start-regexp
))
1222 (c-lang-defconst c-literal-start-regexp
1223 ;; Regexp to match the start of comments and string literals.
1224 t
(concat (c-lang-const c-comment-start-regexp
)
1226 (if (memq 'gen-string-delim c-emacs-features
)
1229 (c-lang-defvar c-literal-start-regexp
(c-lang-const c-literal-start-regexp
))
1231 (c-lang-defconst c-doc-comment-start-regexp
1232 "Regexp to match the start of documentation comments."
1234 ;; From font-lock.el: `doxygen' uses /*! while others use /**.
1235 (c c
++ objc
) "/\\*[*!]"
1238 (c-lang-defvar c-doc-comment-start-regexp
1239 (c-lang-const c-doc-comment-start-regexp
))
1241 (c-lang-defconst comment-start
1242 "String that starts comments inserted with M-; etc.
1243 `comment-start' is initialized from this."
1244 ;; Default: Prefer line comments to block comments, and pad with a space.
1245 t
(concat (or (c-lang-const c-line-comment-starter
)
1246 (c-lang-const c-block-comment-starter
))
1248 ;; In C we still default to the block comment style since line
1249 ;; comments aren't entirely portable.
1251 (c-lang-setvar comment-start
(c-lang-const comment-start
))
1253 (c-lang-defconst comment-end
1254 "String that ends comments inserted with M-; etc.
1255 `comment-end' is initialized from this."
1256 ;; Default: Use block comment style if comment-start uses block
1257 ;; comments, and pad with a space in that case.
1258 t
(if (string-match (concat "\\`\\("
1259 (c-lang-const c-block-comment-start-regexp
)
1261 (c-lang-const comment-start
))
1262 (concat " " (c-lang-const c-block-comment-ender
))
1264 (c-lang-setvar comment-end
(c-lang-const comment-end
))
1266 (c-lang-defconst comment-start-skip
1267 "Regexp to match the start of a comment plus everything up to its body.
1268 `comment-start-skip' is initialized from this."
1269 ;; Default: Allow the last char of the comment starter(s) to be
1270 ;; repeated, then allow any amount of horizontal whitespace.
1273 (mapcar (lambda (cs)
1275 (concat (regexp-quote cs
) "+")))
1276 (list (c-lang-const c-line-comment-starter
)
1277 (c-lang-const c-block-comment-starter
)))
1280 (c-lang-setvar comment-start-skip
(c-lang-const comment-start-skip
))
1282 (c-lang-defconst c-syntactic-ws-start
1283 ;; Regexp matching any sequence that can start syntactic whitespace.
1284 ;; The only uncertain case is '#' when there are cpp directives.
1286 (c-make-keywords-re nil
1287 (append (list (c-lang-const c-line-comment-starter
)
1288 (c-lang-const c-block-comment-starter
)
1289 (when (c-lang-const c-opt-cpp-prefix
)
1293 (when (memq 'gen-comment-delim c-emacs-features
)
1295 (c-lang-defvar c-syntactic-ws-start
(c-lang-const c-syntactic-ws-start
))
1297 (c-lang-defconst c-syntactic-ws-end
1298 ;; Regexp matching any single character that might end syntactic whitespace.
1300 (c-make-keywords-re nil
1301 (append (when (c-lang-const c-block-comment-ender
)
1304 (elt (c-lang-const c-block-comment-ender
)
1306 (c-lang-const c-block-comment-ender
)))))))
1308 (when (memq 'gen-comment-delim c-emacs-features
)
1310 (c-lang-defvar c-syntactic-ws-end
(c-lang-const c-syntactic-ws-end
))
1312 (c-lang-defconst c-unterminated-block-comment-regexp
1313 ;; Regexp matching an unterminated block comment that doesn't
1314 ;; contain line breaks, or nil in languages without block comments.
1315 ;; Does not contain a \| operator at the top level.
1316 t
(when (c-lang-const c-block-comment-starter
)
1318 (regexp-quote (c-lang-const c-block-comment-starter
))
1319 ;; It's messy to cook together a regexp that matches anything
1320 ;; but c-block-comment-ender.
1321 (let ((end (c-lang-const c-block-comment-ender
)))
1322 (cond ((= (length end
) 1)
1323 (concat "[^" end
"\n\r]*"))
1325 (concat "[^" (substring end
0 1) "\n\r]*"
1327 (regexp-quote (substring end
0 1)) "+"
1329 ;; The quoting rules inside char classes are silly. :P
1330 (cond ((= (elt end
0) (elt end
1))
1331 (concat (substring end
0 1) "\n\r"))
1332 ((= (elt end
1) ?\
])
1333 (concat (substring end
1 2) "\n\r"
1334 (substring end
0 1)))
1336 (concat (substring end
0 1) "\n\r"
1337 (substring end
1 2))))
1339 "[^" (substring end
0 1) "\n\r]*"
1342 (error "Can't handle a block comment ender of length %s"
1345 (c-lang-defconst c-block-comment-regexp
1346 ;; Regexp matching a block comment that doesn't contain line breaks,
1347 ;; or nil in languages without block comments. The reason we don't
1348 ;; allow line breaks is to avoid going very far and risk running out
1349 ;; of regexp stack; this regexp is intended to handle only short
1350 ;; comments that might be put in the middle of limited constructs
1351 ;; like declarations. Does not contain a \| operator at the top
1353 t
(when (c-lang-const c-unterminated-block-comment-regexp
)
1355 (c-lang-const c-unterminated-block-comment-regexp
)
1356 (let ((end (c-lang-const c-block-comment-ender
)))
1357 (cond ((= (length end
) 1)
1360 (concat (regexp-quote (substring end
0 1)) "+"
1361 (regexp-quote (substring end
1 2))))
1363 (error "Can't handle a block comment ender of length %s"
1366 (c-lang-defconst c-nonwhite-syntactic-ws
1367 ;; Regexp matching a piece of syntactic whitespace that isn't a
1368 ;; sequence of simple whitespace characters. As opposed to
1369 ;; `c-(forward|backward)-syntactic-ws', this doesn't regard cpp
1370 ;; directives as syntactic whitespace.
1371 t
(c-concat-separated
1372 (list (when (c-lang-const c-line-comment-starter
)
1373 (concat (regexp-quote (c-lang-const c-line-comment-starter
))
1375 (c-lang-const c-block-comment-regexp
)
1377 (when (memq 'gen-comment-delim c-emacs-features
)
1381 (c-lang-defconst c-syntactic-ws
1382 ;; Regexp matching syntactic whitespace, including possibly the
1383 ;; empty string. As opposed to `c-(forward|backward)-syntactic-ws',
1384 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1385 ;; not contain a \| operator at the top level.
1386 t
(concat (c-lang-const c-simple-ws
) "*"
1388 (concat "\\(" (c-lang-const c-nonwhite-syntactic-ws
) "\\)"
1389 (c-lang-const c-simple-ws
) "*")
1392 (c-lang-defconst c-syntactic-ws-depth
1393 ;; Number of regexp grouping parens in `c-syntactic-ws'.
1394 t
(regexp-opt-depth (c-lang-const c-syntactic-ws
)))
1396 (c-lang-defconst c-nonempty-syntactic-ws
1397 ;; Regexp matching syntactic whitespace, which is at least one
1398 ;; character long. As opposed to `c-(forward|backward)-syntactic-ws',
1399 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1400 ;; not contain a \| operator at the top level.
1402 (c-lang-const c-simple-ws
)
1404 (c-lang-const c-nonwhite-syntactic-ws
)
1407 (c-lang-defconst c-nonempty-syntactic-ws-depth
1408 ;; Number of regexp grouping parens in `c-nonempty-syntactic-ws'.
1409 t
(regexp-opt-depth (c-lang-const c-nonempty-syntactic-ws
)))
1411 (c-lang-defconst c-single-line-syntactic-ws
1412 ;; Regexp matching syntactic whitespace without any line breaks. As
1413 ;; opposed to `c-(forward|backward)-syntactic-ws', this doesn't
1414 ;; regard cpp directives as syntactic whitespace. Does not contain
1415 ;; a \| operator at the top level.
1416 t
(if (c-lang-const c-block-comment-regexp
)
1418 (c-lang-const c-block-comment-regexp
)
1422 (c-lang-defconst c-single-line-syntactic-ws-depth
1423 ;; Number of regexp grouping parens in `c-single-line-syntactic-ws'.
1424 t
(regexp-opt-depth (c-lang-const c-single-line-syntactic-ws
)))
1426 (c-lang-defconst c-syntactic-eol
1427 ;; Regexp that matches when there is no syntactically significant
1428 ;; text before eol. Macros are regarded as syntactically
1429 ;; significant text here.
1430 t
(concat (c-lang-const c-single-line-syntactic-ws
)
1431 ;; Match eol (possibly inside a block comment or preceded
1432 ;; by a line continuation backslash), or the beginning of a
1433 ;; line comment. Note: This has to be modified for awk
1434 ;; where line comments start with '#'.
1437 (list (when (c-lang-const c-line-comment-starter
)
1438 (regexp-quote (c-lang-const c-line-comment-starter
)))
1439 (when (c-lang-const c-unterminated-block-comment-regexp
)
1440 (concat (c-lang-const c-unterminated-block-comment-regexp
)
1446 (c-lang-defvar c-syntactic-eol
(c-lang-const c-syntactic-eol
))
1449 ;;; Syntactic analysis ("virtual semicolons") for line-oriented languages (AWK).
1450 (c-lang-defconst c-at-vsemi-p-fn
1451 "Contains a function \"Is there a virtual semicolon at POS or point?\".
1452 Such a function takes one optional parameter, a buffer position (defaults to
1453 point), and returns nil or t. This variable contains nil for languages which
1454 don't have EOL terminated statements. "
1456 awk
'c-awk-at-vsemi-p
)
1457 (c-lang-defvar c-at-vsemi-p-fn
(c-lang-const c-at-vsemi-p-fn
))
1459 (c-lang-defconst c-vsemi-status-unknown-p-fn
1460 "Contains a function \"are we unsure whether there is a virtual semicolon on this line?\".
1461 The (admittedly kludgey) purpose of such a function is to prevent an infinite
1462 recursion in c-beginning-of-statement-1 when point starts at a `while' token.
1463 The function MUST NOT UNDER ANY CIRCUMSTANCES call c-beginning-of-statement-1,
1464 even indirectly. This variable contains nil for languages which don't have
1465 EOL terminated statements."
1467 awk
'c-awk-vsemi-status-unknown-p
)
1468 (c-lang-defvar c-vsemi-status-unknown-p-fn
1469 (c-lang-const c-vsemi-status-unknown-p-fn
))
1474 ;; The Emacs variables beginning-of-defun-function and
1475 ;; end-of-defun-function will be set so that commands like
1476 ;; `mark-defun' and `narrow-to-defun' work right. The key sequences
1477 ;; C-M-a and C-M-e are, however, bound directly to the CC Mode
1478 ;; functions, allowing optimisation for large n.
1479 (c-lang-defconst beginning-of-defun-function
1480 "Function to which beginning-of-defun-function will be set."
1481 t
'c-beginning-of-defun
1482 awk
'c-awk-beginning-of-defun
)
1483 (c-lang-setvar beginning-of-defun-function
1484 (c-lang-const beginning-of-defun-function
))
1486 (c-lang-defconst end-of-defun-function
1487 "Function to which end-of-defun-function will be set."
1489 awk
'c-awk-end-of-defun
)
1490 (c-lang-setvar end-of-defun-function
(c-lang-const end-of-defun-function
))
1492 ;;; In-comment text handling.
1494 (c-lang-defconst c-paragraph-start
1495 "Regexp to append to `paragraph-start'."
1497 java
"\\(@[a-zA-Z]+\\>\\|$\\)" ; For Javadoc.
1498 pike
"\\(@[a-zA-Z_-]+\\>\\([^{]\\|$\\)\\|$\\)") ; For Pike refdoc.
1499 (c-lang-defvar c-paragraph-start
(c-lang-const c-paragraph-start
))
1501 (c-lang-defconst c-paragraph-separate
1502 "Regexp to append to `paragraph-separate'."
1504 pike
(c-lang-const c-paragraph-start
))
1505 (c-lang-defvar c-paragraph-separate
(c-lang-const c-paragraph-separate
))
1510 ;; Note: All and only all language constants containing keyword lists
1511 ;; should end with "-kwds"; they're automatically collected into the
1512 ;; `c-kwds-lang-consts' list below and used to build `c-keywords' etc.
1514 (c-lang-defconst c-primitive-type-kwds
1515 "Primitive type keywords. As opposed to the other keyword lists, the
1516 keywords listed here are fontified with the type face instead of the
1519 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1520 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1521 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1524 Do not try to modify this list for end user customizations; the
1525 `*-font-lock-extra-types' variable, where `*' is the mode prefix, is
1526 the appropriate place for that."
1527 t
'("char" "double" "float" "int" "long" "short" "signed"
1530 '("_Bool" "_Complex" "_Imaginary") ; Conditionally defined in C99.
1531 (c-lang-const c-primitive-type-kwds
))
1534 (c-lang-const c-primitive-type-kwds
))
1535 ;; Objective-C extends C, but probably not the new stuff in C99.
1537 '("id" "Class" "SEL" "IMP" "BOOL")
1538 (c-lang-const c-primitive-type-kwds
))
1539 java
'("boolean" "byte" "char" "double" "float" "int" "long" "short" "void")
1540 idl
'("Object" "ValueBase" "any" "boolean" "char" "double" "fixed" "float"
1541 "long" "octet" "sequence" "short" "string" "void" "wchar" "wstring"
1544 ;; The following can't really end a type, but we have to specify them
1545 ;; here due to the assumption in `c-primitive-type-prefix-kwds'. It
1546 ;; doesn't matter that much.
1547 "unsigned" "strong")
1548 pike
'(;; this_program isn't really a keyword, but it's practically
1549 ;; used as a builtin type.
1550 "array" "float" "function" "int" "mapping" "mixed" "multiset"
1551 "object" "program" "string" "this_program" "void"))
1553 (c-lang-defconst c-primitive-type-key
1554 ;; An adorned regexp that matches `c-primitive-type-kwds'.
1555 t
(c-make-keywords-re t
(c-lang-const c-primitive-type-kwds
)))
1556 (c-lang-defvar c-primitive-type-key
(c-lang-const c-primitive-type-key
))
1558 (c-lang-defconst c-primitive-type-prefix-kwds
1559 "Keywords that might act as prefixes for primitive types. Assumed to
1560 be a subset of `c-primitive-type-kwds'."
1562 (c c
++) '("long" "short" "signed" "unsigned")
1563 idl
'("long" "unsigned"
1567 (c-lang-defconst c-typedef-kwds
1568 "Prefix keyword\(s\) like \"typedef\" which make a type declaration out
1569 of a variable declaration."
1573 (c-lang-defconst c-typedef-key
1574 ;; Adorned regexp matching `c-typedef-kwds'.
1575 t
(c-make-keywords-re t
(c-lang-const c-typedef-kwds
)))
1576 (c-lang-defvar c-typedef-key
(c-lang-const c-typedef-key
))
1578 (c-lang-defconst c-type-prefix-kwds
1579 "Keywords where the following name - if any - is a type name, and
1580 where the keyword together with the symbol works as a type in
1583 Note that an alternative if the second part doesn't hold is
1584 `c-type-list-kwds'. Keywords on this list are typically also present
1585 on one of the `*-decl-kwds' lists."
1587 c
'("struct" "union" "enum")
1588 c
++ (append '("class" "typename")
1589 (c-lang-const c-type-prefix-kwds c
)))
1591 (c-lang-defconst c-type-prefix-key
1592 ;; Adorned regexp matching `c-type-prefix-kwds'.
1593 t
(c-make-keywords-re t
(c-lang-const c-type-prefix-kwds
)))
1594 (c-lang-defvar c-type-prefix-key
(c-lang-const c-type-prefix-key
))
1596 (c-lang-defconst c-type-modifier-kwds
1597 "Type modifier keywords. These can occur almost anywhere in types
1598 but they don't build a type of themselves. Unlike the keywords on
1599 `c-primitive-type-kwds', they are fontified with the keyword face and
1602 c
'("const" "restrict" "volatile")
1603 c
++ '("const" "volatile" "throw")
1604 objc
'("const" "volatile"))
1606 (c-lang-defconst c-opt-type-modifier-key
1607 ;; Adorned regexp matching `c-type-modifier-kwds', or nil in
1608 ;; languages without such keywords.
1609 t
(and (c-lang-const c-type-modifier-kwds
)
1610 (c-make-keywords-re t
(c-lang-const c-type-modifier-kwds
))))
1611 (c-lang-defvar c-opt-type-modifier-key
(c-lang-const c-opt-type-modifier-key
))
1613 (c-lang-defconst c-opt-type-component-key
1614 ;; An adorned regexp that matches `c-primitive-type-prefix-kwds' and
1615 ;; `c-type-modifier-kwds', or nil in languages without any of them.
1616 t
(and (or (c-lang-const c-primitive-type-prefix-kwds
)
1617 (c-lang-const c-type-modifier-kwds
))
1618 (c-make-keywords-re t
1619 (append (c-lang-const c-primitive-type-prefix-kwds
)
1620 (c-lang-const c-type-modifier-kwds
)))))
1621 (c-lang-defvar c-opt-type-component-key
1622 (c-lang-const c-opt-type-component-key
))
1624 (c-lang-defconst c-type-start-kwds
1625 ;; All keywords that can start a type (i.e. are either a type prefix
1626 ;; or a complete type).
1627 t
(delete-duplicates (append (c-lang-const c-primitive-type-kwds
)
1628 (c-lang-const c-type-prefix-kwds
)
1629 (c-lang-const c-type-modifier-kwds
))
1630 :test
'string-equal
))
1632 (c-lang-defconst c-class-decl-kwds
1633 "Keywords introducing declarations where the following block (if any)
1634 contains another declaration level that should be considered a class.
1636 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1637 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1638 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1641 Note that presence on this list does not automatically treat the
1642 following identifier as a type; the keyword must also be present on
1643 `c-type-prefix-kwds' or `c-type-list-kwds' to accomplish that."
1645 c
'("struct" "union")
1646 c
++ '("class" "struct" "union")
1647 objc
'("struct" "union"
1648 "@interface" "@implementation" "@protocol")
1649 java
'("class" "@interface" "interface")
1650 idl
'("component" "eventtype" "exception" "home" "interface" "struct"
1653 "storagehome" "storagetype"
1655 "catalog" "executor" "manages" "segment")
1658 (c-lang-defconst c-class-key
1659 ;; Regexp matching the start of a class.
1660 t
(c-make-keywords-re t
(c-lang-const c-class-decl-kwds
)))
1661 (c-lang-defvar c-class-key
(c-lang-const c-class-key
))
1663 (c-lang-defconst c-brace-list-decl-kwds
1664 "Keywords introducing declarations where the following block (if
1665 any) is a brace list.
1667 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1668 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1669 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1674 (c-lang-defconst c-brace-list-key
1675 ;; Regexp matching the start of declarations where the following
1676 ;; block is a brace list.
1677 t
(c-make-keywords-re t
(c-lang-const c-brace-list-decl-kwds
)))
1678 (c-lang-defvar c-brace-list-key
(c-lang-const c-brace-list-key
))
1680 (c-lang-defconst c-other-block-decl-kwds
1681 "Keywords where the following block (if any) contains another
1682 declaration level that should not be considered a class. For every
1683 keyword here, CC Mode will add a set of special syntactic symbols for
1684 those blocks. E.g. if the keyword is \"foo\" then there will be
1685 `foo-open', `foo-close', and `infoo' symbols.
1687 The intention is that this category should be used for block
1688 constructs that aren't related to object orientation concepts like
1689 classes (which thus also include e.g. interfaces, templates,
1690 contracts, structs, etc). The more pragmatic distinction is that
1691 while most want some indentation inside classes, it's fairly common
1692 that they don't want it in some of these constructs, so it should be
1693 simple to configure that differently from classes. See also
1694 `c-class-decl-kwds'.
1696 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1697 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1698 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1701 (c objc
) '("extern")
1702 c
++ '("namespace" "extern")
1707 (c-lang-defconst c-other-decl-block-key
1708 ;; Regexp matching the start of blocks besides classes that contain
1709 ;; another declaration level.
1710 t
(c-make-keywords-re t
(c-lang-const c-other-block-decl-kwds
)))
1711 (c-lang-defvar c-other-decl-block-key
(c-lang-const c-other-decl-block-key
))
1713 (c-lang-defvar c-other-decl-block-key-in-symbols-alist
1717 (if (string= elt
"extern")
1719 (intern (concat "in" elt
)))))
1720 (c-lang-const c-other-block-decl-kwds
))
1721 "Alist associating keywords in c-other-decl-block-decl-kwds with
1722 their matching \"in\" syntactic symbols.")
1724 (c-lang-defconst c-typedef-decl-kwds
1725 "Keywords introducing declarations where the identifier(s) being
1728 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1729 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1730 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1732 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1733 ;; (since e.g. "Foo" is a type that's being defined in "class Foo
1735 t
(append (c-lang-const c-class-decl-kwds
)
1736 (c-lang-const c-brace-list-decl-kwds
))
1737 ;; Languages that have a "typedef" construct.
1738 (c c
++ objc idl pike
) (append (c-lang-const c-typedef-decl-kwds
)
1740 ;; Unlike most other languages, exception names are not handled as
1741 ;; types in IDL since they only can occur in "raises" specs.
1742 idl
(delete "exception" (append (c-lang-const c-typedef-decl-kwds
) nil
)))
1744 (c-lang-defconst c-typedef-decl-key
1745 t
(c-make-keywords-re t
(c-lang-const c-typedef-decl-kwds
)))
1746 (c-lang-defvar c-typedef-decl-key
(c-lang-const c-typedef-decl-key
))
1748 (c-lang-defconst c-typeless-decl-kwds
1749 "Keywords introducing declarations where the \(first) identifier
1750 \(declarator) follows directly after the keyword, without any type.
1752 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1753 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1754 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1756 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1757 ;; (since e.g. "Foo" is the identifier being defined in "class Foo
1759 t
(append (c-lang-const c-class-decl-kwds
)
1760 (c-lang-const c-brace-list-decl-kwds
))
1761 ;; Note: "manages" for CORBA CIDL clashes with its presence on
1762 ;; `c-type-list-kwds' for IDL.
1763 idl
(append (c-lang-const c-typeless-decl-kwds
)
1764 '("factory" "finder" "native"
1769 pike
(append (c-lang-const c-class-decl-kwds
)
1772 (c-lang-defconst c-modifier-kwds
1773 "Keywords that can prefix normal declarations of identifiers
1774 \(and typically act as flags). Things like argument declarations
1775 inside function headers are also considered declarations in this
1778 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1779 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1780 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1783 (c c
++) '("auto" "extern" "inline" "register" "static")
1784 c
++ (append '("explicit" "friend" "mutable" "template" "using" "virtual")
1785 (c-lang-const c-modifier-kwds
))
1786 objc
'("auto" "bycopy" "byref" "extern" "in" "inout" "oneway" "out" "static")
1787 ;; FIXME: Some of those below ought to be on `c-other-decl-kwds' instead.
1788 idl
'("abstract" "attribute" "const" "consumes" "custom" "emits" "import"
1789 "in" "inout" "local" "multiple" "oneway" "out" "private" "provides"
1790 "public" "publishes" "readonly" "typeid" "typeprefix" "uses"
1794 "bindsTo" "delegatesTo" "implements" "proxy" "storedOn")
1795 ;; Note: "const" is not used in Java, but it's still a reserved keyword.
1796 java
'("abstract" "const" "final" "native" "private" "protected" "public"
1797 "static" "strictfp" "synchronized" "transient" "volatile" "@[A-Za-z0-9]+")
1798 pike
'("final" "inline" "local" "nomask" "optional" "private" "protected"
1799 "public" "static" "variant"))
1801 (c-lang-defconst c-other-decl-kwds
1802 "Keywords that can start or prefix any declaration level construct,
1803 besides those on `c-class-decl-kwds', `c-brace-list-decl-kwds',
1804 `c-other-block-decl-kwds', `c-typedef-decl-kwds',
1805 `c-typeless-decl-kwds' and `c-modifier-kwds'.
1807 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1808 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1809 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1812 objc
'("@class" "@end" "@defs")
1813 java
'("import" "package")
1814 pike
'("import" "inherit"))
1816 (c-lang-defconst c-decl-start-kwds
1817 "Keywords that always start declarations, wherever they occur.
1818 This can be used for declarations that aren't recognized by the normal
1819 combination of `c-decl-prefix-re' and `c-decl-start-re'."
1821 ;; Classes can be declared anywhere in a Pike expression.
1824 (c-lang-defconst c-decl-hangon-kwds
1825 "Keywords that can occur anywhere in a declaration level construct.
1826 This is used for self-contained things that can be tacked on anywhere
1827 on a declaration and that should be ignored to be able to recognize it
1828 correctly. Typical cases are compiler extensions like
1829 \"__attribute__\" or \"__declspec\":
1831 __declspec(noreturn) void foo();
1832 class __declspec(dllexport) classname {...};
1833 void foo() __attribute__((noreturn));
1835 Note that unrecognized plain symbols are skipped anyway if they occur
1836 before the type, so such things are not necessary to mention here.
1837 Mentioning them here is necessary only if they can occur in other
1838 places, or if they are followed by a construct that must be skipped
1839 over \(like the parens in the \"__attribute__\" and \"__declspec\"
1840 examples above). In the last case, they alse need to be present on
1841 one of `c-type-list-kwds', `c-ref-list-kwds',
1842 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1843 `c-<>-type-kwds', or `c-<>-arglist-kwds'."
1844 ;; NB: These are currently not recognized in all parts of a
1845 ;; declaration. Specifically, they aren't recognized in the middle
1846 ;; of multi-token types, inside declarators, and between the
1847 ;; identifier and the arglist paren of a function declaration.
1849 ;; FIXME: This ought to be user customizable since compiler stuff
1850 ;; like this usually is wrapped in project specific macros. (It'd
1851 ;; of course be even better if we could cope without knowing this.)
1853 (c c
++) '(;; GCC extension.
1858 (c-lang-defconst c-decl-hangon-key
1859 ;; Adorned regexp matching `c-decl-hangon-kwds'.
1860 t
(c-make-keywords-re t
(c-lang-const c-decl-hangon-kwds
)))
1861 (c-lang-defvar c-decl-hangon-key
(c-lang-const c-decl-hangon-key
))
1863 (c-lang-defconst c-prefix-spec-kwds
1864 ;; All keywords that can occur in the preamble of a declaration.
1865 ;; They typically occur before the type, but they are also matched
1866 ;; after presumptive types since we often can't be sure that
1867 ;; something is a type or just some sort of macro in front of the
1868 ;; declaration. They might be ambiguous with types or type
1870 t
(delete-duplicates (append (c-lang-const c-class-decl-kwds
)
1871 (c-lang-const c-brace-list-decl-kwds
)
1872 (c-lang-const c-other-block-decl-kwds
)
1873 (c-lang-const c-typedef-decl-kwds
)
1874 (c-lang-const c-typeless-decl-kwds
)
1875 (c-lang-const c-modifier-kwds
)
1876 (c-lang-const c-other-decl-kwds
)
1877 (c-lang-const c-decl-start-kwds
)
1878 (c-lang-const c-decl-hangon-kwds
))
1879 :test
'string-equal
))
1881 (c-lang-defconst c-prefix-spec-kwds-re
1882 ;; Adorned regexp of `c-prefix-spec-kwds'.
1883 t
(c-make-keywords-re t
(c-lang-const c-prefix-spec-kwds
))
1884 java
(replace-regexp-in-string
1886 (replace-regexp-in-string "\\\\\\+" "+" (c-make-keywords-re t
(c-lang-const c-prefix-spec-kwds
)))))
1888 (c-lang-defvar c-prefix-spec-kwds-re
(c-lang-const c-prefix-spec-kwds-re
))
1890 (c-lang-defconst c-specifier-key
1891 ;; Adorned regexp of the keywords in `c-prefix-spec-kwds' that aren't
1892 ;; ambiguous with types or type prefixes. These are the keywords (like
1893 ;; extern, namespace, but NOT template) that can modify a declaration.
1894 t
(c-make-keywords-re t
1895 (set-difference (c-lang-const c-prefix-spec-kwds
)
1896 (append (c-lang-const c-type-start-kwds
)
1897 (c-lang-const c-
<>-arglist-kwds
))
1898 :test
'string-equal
)))
1899 (c-lang-defvar c-specifier-key
(c-lang-const c-specifier-key
))
1901 (c-lang-defconst c-postfix-spec-kwds
1902 ;; Keywords that can occur after argument list of a function header
1903 ;; declaration, i.e. in the "K&R region".
1904 t
(append (c-lang-const c-postfix-decl-spec-kwds
)
1905 (c-lang-const c-decl-hangon-kwds
)))
1907 (c-lang-defconst c-not-decl-init-keywords
1908 ;; Adorned regexp matching all keywords that can't appear at the
1909 ;; start of a declaration.
1910 t
(c-make-keywords-re t
1911 (set-difference (c-lang-const c-keywords
)
1912 (append (c-lang-const c-type-start-kwds
)
1913 (c-lang-const c-prefix-spec-kwds
))
1914 :test
'string-equal
)))
1915 (c-lang-defvar c-not-decl-init-keywords
1916 (c-lang-const c-not-decl-init-keywords
))
1918 (c-lang-defconst c-protection-kwds
1919 "Access protection label keywords in classes."
1921 c
++ '("private" "protected" "public")
1922 objc
'("@private" "@protected" "@public"))
1924 (c-lang-defconst c-block-decls-with-vars
1925 "Keywords introducing declarations that can contain a block which
1926 might be followed by variable declarations, e.g. like \"foo\" in
1927 \"class Foo { ... } foo;\". So if there is a block in a declaration
1928 like that, it ends with the following ';' and not right away.
1930 The keywords on list are assumed to also be present on one of the
1931 `*-decl-kwds' lists."
1933 (c objc
) '("struct" "union" "enum" "typedef")
1934 c
++ '("class" "struct" "union" "enum" "typedef"))
1936 (c-lang-defconst c-opt-block-decls-with-vars-key
1937 ;; Regexp matching the `c-block-decls-with-vars' keywords, or nil in
1938 ;; languages without such constructs.
1939 t
(and (c-lang-const c-block-decls-with-vars
)
1940 (c-make-keywords-re t
(c-lang-const c-block-decls-with-vars
))))
1941 (c-lang-defvar c-opt-block-decls-with-vars-key
1942 (c-lang-const c-opt-block-decls-with-vars-key
))
1944 (c-lang-defconst c-postfix-decl-spec-kwds
1945 "Keywords introducing extra declaration specifiers in the region
1946 between the header and the body \(i.e. the \"K&R-region\") in
1949 java
'("extends" "implements" "throws")
1950 idl
'("context" "getraises" "manages" "primarykey" "raises" "setraises"
1953 "as" "const" "implements" "of" "ref"))
1955 (c-lang-defconst c-nonsymbol-sexp-kwds
1956 "Keywords that may be followed by a nonsymbol sexp before whatever
1957 construct it's part of continues."
1959 (c c
++ objc
) '("extern"))
1961 (c-lang-defconst c-type-list-kwds
1962 "Keywords that may be followed by a comma separated list of type
1963 identifiers, where each optionally can be prefixed by keywords. (Can
1964 also be used for the special case when the list can contain only one
1967 Assumed to be mutually exclusive with `c-ref-list-kwds'. There's no
1968 reason to put keywords on this list if they are on `c-type-prefix-kwds'.
1969 There's also no reason to add keywords that prefixes a normal
1970 declaration consisting of a type followed by a declarator (list), so
1971 the keywords on `c-modifier-kwds' should normally not be listed here
1974 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
1975 or variable identifier (that's being defined)."
1979 java
'("import" "new" "extends" "super" "implements" "throws")
1980 idl
'("manages" "native" "primarykey" "supports"
1982 "as" "implements" "of" "scope")
1985 (c-lang-defconst c-ref-list-kwds
1986 "Keywords that may be followed by a comma separated list of
1987 reference (i.e. namespace/scope/module) identifiers, where each
1988 optionally can be prefixed by keywords. (Can also be used for the
1989 special case when the list can contain only one element.) Assumed to
1990 be mutually exclusive with `c-type-list-kwds'.
1992 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
1993 or variable identifier (that's being defined)."
1997 idl
'("import" "module"
2002 (c-lang-defconst c-colon-type-list-kwds
2003 "Keywords that may be followed (not necessarily directly) by a colon
2004 and then a comma separated list of type identifiers, where each
2005 optionally can be prefixed by keywords. (Can also be used for the
2006 special case when the list can contain only one element.)"
2008 c
++ '("class" "struct")
2009 idl
'("component" "eventtype" "home" "interface" "valuetype"
2011 "storagehome" "storagetype"))
2013 (c-lang-defconst c-colon-type-list-re
2014 "Regexp matched after the keywords in `c-colon-type-list-kwds' to skip
2015 forward to the colon. The end of the match is assumed to be directly
2016 after the colon, so the regexp should end with \":\". Must be a
2017 regexp if `c-colon-type-list-kwds' isn't nil."
2018 t
(if (c-lang-const c-colon-type-list-kwds
)
2019 ;; Disallow various common punctuation chars that can't come
2020 ;; before the ":" that starts the inherit list after "class"
2021 ;; or "struct" in C++. (Also used as default for other
2023 "[^\]\[{}();,/#=:]*:"))
2024 (c-lang-defvar c-colon-type-list-re
(c-lang-const c-colon-type-list-re
))
2026 (c-lang-defconst c-paren-nontype-kwds
2027 "Keywords that may be followed by a parenthesis expression that doesn't
2028 contain type identifiers."
2030 (c c
++) '(;; GCC extension.
2035 (c-lang-defconst c-paren-type-kwds
2036 "Keywords that may be followed by a parenthesis expression containing
2037 type identifiers separated by arbitrary tokens."
2042 pike
'("array" "function" "int" "mapping" "multiset" "object" "program"))
2044 (c-lang-defconst c-paren-any-kwds
2045 t
(delete-duplicates (append (c-lang-const c-paren-nontype-kwds
)
2046 (c-lang-const c-paren-type-kwds
))
2047 :test
'string-equal
))
2049 (c-lang-defconst c-
<>-type-kwds
2050 "Keywords that may be followed by an angle bracket expression
2051 containing type identifiers separated by \",\". The difference from
2052 `c-<>-arglist-kwds' is that unknown names are taken to be types and
2053 not other identifiers. `c-recognize-<>-arglists' is assumed to be set
2061 (c-lang-defconst c-
<>-arglist-kwds
2062 "Keywords that can be followed by a C++ style template arglist; see
2063 `c-recognize-<>-arglists' for details. That language constant is
2064 assumed to be set if this isn't nil."
2067 idl
'("fixed" "string" "wstring"))
2069 (c-lang-defconst c-
<>-sexp-kwds
2070 ;; All keywords that can be followed by an angle bracket sexp.
2071 t
(delete-duplicates (append (c-lang-const c-
<>-type-kwds
)
2072 (c-lang-const c-
<>-arglist-kwds
))
2073 :test
'string-equal
))
2075 (c-lang-defconst c-opt-
<>-sexp-key
2076 ;; Adorned regexp matching keywords that can be followed by an angle
2077 ;; bracket sexp. Always set when `c-recognize-<>-arglists' is.
2078 t
(if (c-lang-const c-recognize-
<>-arglists
)
2079 (c-make-keywords-re t
(c-lang-const c-
<>-sexp-kwds
))))
2080 (c-lang-defvar c-opt-
<>-sexp-key
(c-lang-const c-opt-
<>-sexp-key
))
2082 (c-lang-defconst c-brace-id-list-kwds
2083 "Keywords that may be followed by a brace block containing a comma
2084 separated list of identifier definitions, i.e. like the list of
2085 identifiers that follows the type in a normal declaration."
2086 t
(c-lang-const c-brace-list-decl-kwds
))
2088 (c-lang-defconst c-block-stmt-1-kwds
2089 "Statement keywords followed directly by a substatement."
2091 c
++ '("do" "else" "try")
2092 objc
'("do" "else" "@finally" "@try")
2093 java
'("do" "else" "finally" "try")
2096 (c-lang-defconst c-block-stmt-1-key
2097 ;; Regexp matching the start of any statement followed directly by a
2098 ;; substatement (doesn't match a bare block, however).
2099 t
(c-make-keywords-re t
(c-lang-const c-block-stmt-1-kwds
)))
2100 (c-lang-defvar c-block-stmt-1-key
(c-lang-const c-block-stmt-1-key
))
2102 (c-lang-defconst c-block-stmt-2-kwds
2103 "Statement keywords followed by a paren sexp and then by a substatement."
2104 t
'("for" "if" "switch" "while")
2105 c
++ '("for" "if" "switch" "while" "catch")
2106 objc
'("for" "if" "switch" "while" "@catch" "@synchronized")
2107 java
'("for" "if" "switch" "while" "catch" "synchronized")
2109 pike
'("for" "if" "switch" "while" "foreach")
2110 awk
'("for" "if" "while"))
2112 (c-lang-defconst c-block-stmt-2-key
2113 ;; Regexp matching the start of any statement followed by a paren sexp
2114 ;; and then by a substatement.
2115 t
(c-make-keywords-re t
(c-lang-const c-block-stmt-2-kwds
)))
2116 (c-lang-defvar c-block-stmt-2-key
(c-lang-const c-block-stmt-2-key
))
2118 (c-lang-defconst c-block-stmt-kwds
2119 ;; Union of `c-block-stmt-1-kwds' and `c-block-stmt-2-kwds'.
2120 t
(delete-duplicates (append (c-lang-const c-block-stmt-1-kwds
)
2121 (c-lang-const c-block-stmt-2-kwds
))
2122 :test
'string-equal
))
2124 (c-lang-defconst c-opt-block-stmt-key
2125 ;; Regexp matching the start of any statement that has a
2126 ;; substatement (except a bare block). Nil in languages that
2127 ;; don't have such constructs.
2128 t
(if (or (c-lang-const c-block-stmt-1-kwds
)
2129 (c-lang-const c-block-stmt-2-kwds
))
2130 (c-make-keywords-re t
2131 (append (c-lang-const c-block-stmt-1-kwds
)
2132 (c-lang-const c-block-stmt-2-kwds
)))))
2133 (c-lang-defvar c-opt-block-stmt-key
(c-lang-const c-opt-block-stmt-key
))
2135 (c-lang-defconst c-simple-stmt-kwds
2136 "Statement keywords followed by an expression or nothing."
2137 t
'("break" "continue" "goto" "return")
2138 objc
'("break" "continue" "goto" "return" "@throw")
2139 ;; Note: `goto' is not valid in Java, but the keyword is still reserved.
2140 java
'("break" "continue" "goto" "return" "throw")
2142 pike
'("break" "continue" "return")
2143 awk
'(;; Not sure about "delete", "exit", "getline", etc. ; ACM 2002/5/30
2144 "break" "continue" "return" "delete" "exit" "getline" "next"
2145 "nextfile" "print" "printf"))
2147 (c-lang-defconst c-simple-stmt-key
2148 ;; Adorned regexp matching `c-simple-stmt-kwds'.
2149 t
(c-make-keywords-re t
(c-lang-const c-simple-stmt-kwds
)))
2150 (c-lang-defvar c-simple-stmt-key
(c-lang-const c-simple-stmt-key
))
2152 (c-lang-defconst c-paren-stmt-kwds
2153 "Statement keywords followed by a parenthesis expression that
2154 nevertheless contains a list separated with ';' and not ','."
2158 (c-lang-defconst c-paren-stmt-key
2159 ;; Adorned regexp matching `c-paren-stmt-kwds'.
2160 t
(c-make-keywords-re t
(c-lang-const c-paren-stmt-kwds
)))
2161 (c-lang-defvar c-paren-stmt-key
(c-lang-const c-paren-stmt-key
))
2163 (c-lang-defconst c-asm-stmt-kwds
2164 "Statement keywords followed by an assembler expression."
2166 (c c
++) '("asm" "__asm__")) ;; Not standard, but common.
2168 (c-lang-defconst c-opt-asm-stmt-key
2169 ;; Regexp matching the start of an assembler statement. Nil in
2170 ;; languages that don't support that.
2171 t
(if (c-lang-const c-asm-stmt-kwds
)
2172 (c-make-keywords-re t
(c-lang-const c-asm-stmt-kwds
))))
2173 (c-lang-defvar c-opt-asm-stmt-key
(c-lang-const c-opt-asm-stmt-key
))
2175 (c-lang-defconst c-case-kwds
2176 "The keyword\(s) which introduce a \"case\" like construct.
2177 This construct is \"<keyword> <expression> :\"."
2181 (c-lang-defconst c-case-kwds-regexp
2182 ;; Adorned regexp matching any "case"-like keyword.
2183 t
(c-make-keywords-re t
(c-lang-const c-case-kwds
)))
2184 (c-lang-defvar c-case-kwds-regexp
(c-lang-const c-case-kwds-regexp
))
2186 (c-lang-defconst c-label-kwds
2187 "Keywords introducing colon terminated labels in blocks."
2188 t
'("case" "default")
2191 (c-lang-defconst c-label-kwds-regexp
2192 ;; Adorned regexp matching any keyword that introduces a label.
2193 t
(c-make-keywords-re t
(c-lang-const c-label-kwds
)))
2194 (c-lang-defvar c-label-kwds-regexp
(c-lang-const c-label-kwds-regexp
))
2196 (c-lang-defconst c-before-label-kwds
2197 "Keywords that might be followed by a label identifier."
2199 (java pike
) (append '("break" "continue")
2200 (c-lang-const c-before-label-kwds
))
2204 (c-lang-defconst c-constant-kwds
2205 "Keywords for constants."
2207 (c c
++) '("NULL" ;; Not a keyword, but practically works as one.
2208 "false" "true") ; Defined in C99.
2209 objc
'("nil" "Nil" "YES" "NO" "NS_DURING" "NS_HANDLER" "NS_ENDHANDLER")
2210 idl
'("TRUE" "FALSE")
2211 java
'("true" "false" "null") ; technically "literals", not keywords
2212 pike
'("UNDEFINED")) ;; Not a keyword, but practically works as one.
2214 (c-lang-defconst c-primary-expr-kwds
2215 "Keywords besides constants and operators that start primary expressions."
2217 c
++ '("operator" "this")
2218 objc
'("super" "self")
2220 pike
'("this")) ;; Not really a keyword, but practically works as one.
2222 (c-lang-defconst c-expr-kwds
2223 ;; Keywords that can occur anywhere in expressions. Built from
2224 ;; `c-primary-expr-kwds' and all keyword operators in `c-operators'.
2225 t
(delete-duplicates
2226 (append (c-lang-const c-primary-expr-kwds
)
2227 (c-filter-ops (c-lang-const c-operator-list
)
2229 "\\`\\(\\w\\|\\s_\\)+\\'"))
2230 :test
'string-equal
))
2232 (c-lang-defconst c-lambda-kwds
2233 "Keywords that start lambda constructs, i.e. function definitions in
2238 (c-lang-defconst c-inexpr-block-kwds
2239 "Keywords that start constructs followed by statement blocks which can
2240 be used in expressions \(the gcc extension for this in C and C++ is
2241 handled separately by `c-recognize-paren-inexpr-blocks')."
2243 pike
'("catch" "gauge"))
2245 (c-lang-defconst c-inexpr-class-kwds
2246 "Keywords that can start classes inside expressions."
2251 (c-lang-defconst c-inexpr-brace-list-kwds
2252 "Keywords that can start brace list blocks inside expressions.
2253 Note that Java specific rules are currently applied to tell this from
2254 `c-inexpr-class-kwds'."
2258 (c-lang-defconst c-opt-inexpr-brace-list-key
2259 ;; Regexp matching the start of a brace list in an expression, or
2260 ;; nil in languages that don't have such things. This should not
2261 ;; match brace lists recognized through `c-special-brace-lists'.
2262 t
(and (c-lang-const c-inexpr-brace-list-kwds
)
2263 (c-make-keywords-re t
(c-lang-const c-inexpr-brace-list-kwds
))))
2264 (c-lang-defvar c-opt-inexpr-brace-list-key
2265 (c-lang-const c-opt-inexpr-brace-list-key
))
2267 (c-lang-defconst c-decl-block-key
2268 ;; Regexp matching keywords in any construct that contain another
2269 ;; declaration level, i.e. that isn't followed by a function block
2270 ;; or brace list. When the first submatch matches, it's an
2271 ;; unambiguous construct, otherwise it's an ambiguous match that
2272 ;; might also be the return type of a function declaration.
2273 t
(let* ((decl-kwds (append (c-lang-const c-class-decl-kwds
)
2274 (c-lang-const c-other-block-decl-kwds
)
2275 (c-lang-const c-inexpr-class-kwds
)))
2276 (unambiguous (set-difference decl-kwds
2277 (c-lang-const c-type-start-kwds
)
2278 :test
'string-equal
))
2279 (ambiguous (intersection decl-kwds
2280 (c-lang-const c-type-start-kwds
)
2281 :test
'string-equal
)))
2283 (concat (c-make-keywords-re t unambiguous
)
2285 (c-make-keywords-re t ambiguous
))
2286 (c-make-keywords-re t unambiguous
))))
2287 (c-lang-defvar c-decl-block-key
(c-lang-const c-decl-block-key
))
2289 (c-lang-defconst c-bitfield-kwds
2290 "Keywords that can introduce bitfields."
2292 (c c
++ objc
) '("char" "int" "long" "signed" "unsigned"))
2294 (c-lang-defconst c-opt-bitfield-key
2295 ;; Regexp matching the start of a bitfield (not uniquely), or nil in
2296 ;; languages without bitfield support.
2298 (c c
++) (c-make-keywords-re t
(c-lang-const c-bitfield-kwds
)))
2299 (c-lang-defvar c-opt-bitfield-key
(c-lang-const c-opt-bitfield-key
))
2301 (c-lang-defconst c-other-kwds
2302 "Keywords not accounted for by any other `*-kwds' language constant."
2305 ;; In CORBA CIDL: (These are declaration keywords that never
2306 ;; can start a declaration.)
2307 "entity" "process" "service" "session" "storage"))
2310 ;;; Constants built from keywords.
2312 ;; Note: No `*-kwds' language constants may be defined below this point.
2315 (defconst c-kwds-lang-consts
2316 ;; List of all the language constants that contain keyword lists.
2318 (mapatoms (lambda (sym)
2319 (when (and (boundp sym
)
2320 (string-match "-kwds\\'" (symbol-name sym
)))
2321 ;; Make the list of globally interned symbols
2322 ;; instead of ones interned in `c-lang-constants'.
2323 (setq list
(cons (intern (symbol-name sym
)) list
))))
2327 (c-lang-defconst c-keywords
2328 ;; All keywords as a list.
2329 t
(delete-duplicates
2330 (c-lang-defconst-eval-immediately
2331 `(append ,@(mapcar (lambda (kwds-lang-const)
2332 `(c-lang-const ,kwds-lang-const
))
2335 :test
'string-equal
))
2337 (c-lang-defconst c-keywords-regexp
2338 ;; All keywords as an adorned regexp.
2339 t
(c-make-keywords-re t
(c-lang-const c-keywords
)))
2340 (c-lang-defvar c-keywords-regexp
(c-lang-const c-keywords-regexp
))
2342 (c-lang-defconst c-keyword-member-alist
2343 ;; An alist with all the keywords in the cars. The cdr for each
2344 ;; keyword is a list of the symbols for the `*-kwds' lists that
2346 t
(let ((kwd-list-alist
2347 (c-lang-defconst-eval-immediately
2348 `(list ,@(mapcar (lambda (kwds-lang-const)
2349 `(cons ',kwds-lang-const
2350 (c-lang-const ,kwds-lang-const
)))
2351 c-kwds-lang-consts
))))
2352 lang-const kwd-list kwd
2354 (while kwd-list-alist
2355 (setq lang-const
(caar kwd-list-alist
)
2356 kwd-list
(cdar kwd-list-alist
)
2357 kwd-list-alist
(cdr kwd-list-alist
))
2359 (setq kwd
(car kwd-list
)
2360 kwd-list
(cdr kwd-list
))
2361 (unless (setq elem
(assoc kwd result-alist
))
2362 (setq result-alist
(cons (setq elem
(list kwd
)) result-alist
)))
2363 (unless (memq lang-const
(cdr elem
))
2364 (setcdr elem
(cons lang-const
(cdr elem
))))))
2367 (c-lang-defvar c-keywords-obarray
2368 ;; An obarray containing all keywords as symbols. The property list
2369 ;; of each symbol has a non-nil entry for the specific `*-kwds'
2370 ;; lists it's a member of.
2372 ;; E.g. to see whether the string str contains a keyword on
2373 ;; `c-class-decl-kwds', one can do like this:
2374 ;; (get (intern-soft str c-keyword-obarray) 'c-class-decl-kwds)
2375 ;; Which preferably is written using the associated functions in
2377 ;; (c-keyword-member (c-keyword-sym str) 'c-class-decl-kwds)
2379 ;; The obarray is not stored directly as a language constant since
2380 ;; the printed representation for obarrays used in .elc files isn't
2383 (let* ((alist (c-lang-const c-keyword-member-alist
))
2385 (obarray (make-vector (* (length alist
) 2) 0)))
2387 (setq kwd
(caar alist
)
2388 lang-const-list
(cdar alist
)
2390 (setplist (intern kwd obarray
)
2391 ;; Emacs has an odd bug that causes `mapcan' to fail
2392 ;; with unintelligible errors. (XEmacs works.)
2393 ;;(mapcan (lambda (lang-const)
2394 ;; (list lang-const t))
2396 (apply 'nconc
(mapcar (lambda (lang-const)
2397 (list lang-const t
))
2401 (c-lang-defconst c-regular-keywords-regexp
2402 ;; Adorned regexp matching all keywords that should be fontified
2403 ;; with the keywords face. I.e. that aren't types or constants.
2404 t
(c-make-keywords-re t
2405 (set-difference (c-lang-const c-keywords
)
2406 (append (c-lang-const c-primitive-type-kwds
)
2407 (c-lang-const c-constant-kwds
))
2408 :test
'string-equal
)))
2409 (c-lang-defvar c-regular-keywords-regexp
2410 (c-lang-const c-regular-keywords-regexp
))
2412 (c-lang-defconst c-primary-expr-regexp
2413 ;; Regexp matching the start of any primary expression, i.e. any
2414 ;; literal, symbol, prefix operator, and '('. It doesn't need to
2415 ;; exclude keywords; they are excluded afterwards unless the second
2416 ;; submatch matches. If the first but not the second submatch
2417 ;; matches then it is an ambiguous primary expression; it could also
2418 ;; be a match of e.g. an infix operator. (The case with ambiguous
2419 ;; keyword operators isn't handled.)
2421 t
(let* ((prefix-ops
2422 (c-filter-ops (c-lang-const c-operators
)
2425 ;; Filter out the special case prefix
2426 ;; operators that are close parens.
2427 (not (string-match "\\s)" op
)))))
2429 (nonkeyword-prefix-ops
2430 (c-filter-ops prefix-ops
2432 "\\`\\(\\s.\\|\\s(\\|\\s)\\)+\\'"))
2435 (c-filter-ops (c-lang-const c-operators
)
2440 right-assoc-sequence
)
2443 (unambiguous-prefix-ops (set-difference nonkeyword-prefix-ops
2445 :test
'string-equal
))
2446 (ambiguous-prefix-ops (intersection nonkeyword-prefix-ops
2448 :test
'string-equal
)))
2452 ;; Take out all symbol class operators from `prefix-ops' and make the
2453 ;; first submatch from them together with `c-primary-expr-kwds'.
2454 (c-make-keywords-re t
2455 (append (c-lang-const c-primary-expr-kwds
)
2456 (set-difference prefix-ops nonkeyword-prefix-ops
2457 :test
'string-equal
)))
2460 ;; Match all ambiguous operators.
2461 (c-make-keywords-re nil
2462 (intersection nonkeyword-prefix-ops in-or-postfix-ops
2463 :test
'string-equal
))
2467 ;; Now match all other symbols.
2468 (c-lang-const c-symbol-start
)
2471 ;; The chars that can start integer and floating point
2476 ;; The nonambiguous operators from `prefix-ops'.
2477 (c-make-keywords-re nil
2478 (set-difference nonkeyword-prefix-ops in-or-postfix-ops
2479 :test
'string-equal
))
2482 ;; Match string and character literals.
2484 (if (memq 'gen-string-delim c-emacs-features
)
2487 (c-lang-defvar c-primary-expr-regexp
(c-lang-const c-primary-expr-regexp
))
2490 ;;; Additional constants for parser-level constructs.
2492 (c-lang-defconst c-decl-prefix-re
2493 "Regexp matching something that might precede a declaration, cast or
2494 label, such as the last token of a preceding statement or declaration.
2495 This is used in the common situation where a declaration or cast
2496 doesn't start with any specific token that can be searched for.
2498 The regexp should not match bob; that is done implicitly. It can't
2499 require a match longer than one token. The end of the token is taken
2500 to be at the end of the first submatch, which is assumed to always
2501 match. It's undefined whether identifier syntax (see
2502 `c-identifier-syntax-table') is in effect or not. This regexp is
2503 assumed to be a superset of `c-label-prefix-re' if
2504 `c-recognize-colon-labels' is set.
2506 Besides this, `c-decl-start-kwds' is used to find declarations.
2508 Note: This variable together with `c-decl-start-re' and
2509 `c-decl-start-kwds' is only used to detect \"likely\"
2510 declaration/cast/label starts. I.e. they might produce more matches
2511 but should not miss anything (or else it's necessary to use text
2512 properties - see the next note). Wherever they match, the following
2513 construct is analyzed to see if it indeed is a declaration, cast or
2514 label. That analysis is not cheap, so it's important that not too
2515 many false matches are triggered.
2517 Note: If a declaration/cast/label start can't be detected with this
2518 variable, it's necessary to use the `c-type' text property with the
2519 value `c-decl-end' on the last char of the last token preceding the
2520 declaration. See the comment blurb at the start of cc-engine.el for
2523 ;; We match a sequence of characters to skip over things like \"};\"
2524 ;; more quickly. We match ")" in C for K&R region declarations, and
2525 ;; in all languages except Java for when a cpp macro definition
2526 ;; begins with a declaration.
2527 t
"\\([\{\}\(\);,]+\\)"
2528 java
"\\([\{\}\(;,<]+\\)"
2529 ;; Match "<" in C++ to get the first argument in a template arglist.
2530 ;; In that case there's an additional check in `c-find-decl-spots'
2531 ;; that it got open paren syntax.
2532 c
++ "\\([\{\}\(\);,<]+\\)"
2533 ;; Additionally match the protection directives in Objective-C.
2534 ;; Note that this doesn't cope with the longer directives, which we
2535 ;; would have to match from start to end since they don't end with
2536 ;; any easily recognized characters.
2537 objc
(concat "\\([\{\}\(\);,]+\\|"
2538 (c-make-keywords-re nil
(c-lang-const c-protection-kwds
))
2540 ;; Pike is like C but we also match "[" for multiple value
2541 ;; assignments and type casts.
2542 pike
"\\([\{\}\(\)\[;,]+\\)")
2543 (c-lang-defvar c-decl-prefix-re
(c-lang-const c-decl-prefix-re
)
2546 (c-lang-defconst c-decl-start-re
2547 "Regexp matching the start of any declaration, cast or label.
2548 It's used on the token after the one `c-decl-prefix-re' matched. This
2549 regexp should not try to match those constructs accurately as it's
2550 only used as a sieve to avoid spending more time checking other
2552 t
(c-lang-const c-identifier-start
))
2553 (c-lang-defvar c-decl-start-re
(c-lang-const c-decl-start-re
))
2555 (c-lang-defconst c-decl-prefix-or-start-re
2556 ;; Regexp matching something that might precede or start a
2557 ;; declaration, cast or label.
2559 ;; If the first submatch matches, it's taken to match the end of a
2560 ;; token that might precede such a construct, e.g. ';', '}' or '{'.
2561 ;; It's built from `c-decl-prefix-re'.
2563 ;; If the first submatch did not match, the match of the whole
2564 ;; regexp is taken to be at the first token in the declaration.
2565 ;; `c-decl-start-re' is not checked in this case.
2567 ;; Design note: The reason the same regexp is used to match both
2568 ;; tokens that precede declarations and start them is to avoid an
2569 ;; extra regexp search from the previous declaration spot in
2570 ;; `c-find-decl-spots'. Users of `c-find-decl-spots' also count on
2571 ;; that it finds all declaration/cast/label starts in approximately
2572 ;; linear order, so we can't do the searches in two separate passes.
2573 t
(if (c-lang-const c-decl-start-kwds
)
2574 (concat (c-lang-const c-decl-prefix-re
)
2576 (c-make-keywords-re t
(c-lang-const c-decl-start-kwds
)))
2577 (c-lang-const c-decl-prefix-re
)))
2578 (c-lang-defvar c-decl-prefix-or-start-re
2579 (c-lang-const c-decl-prefix-or-start-re
)
2582 (c-lang-defconst c-cast-parens
2583 ;; List containing the paren characters that can open a cast, or nil in
2584 ;; languages without casts.
2585 t
(c-filter-ops (c-lang-const c-operators
)
2588 (lambda (op) (elt op
0))))
2589 (c-lang-defvar c-cast-parens
(c-lang-const c-cast-parens
))
2591 (c-lang-defconst c-block-prefix-disallowed-chars
2592 "List of syntactically relevant characters that never can occur before
2593 the open brace in any construct that contains a brace block, e.g. in
2594 the \"class Foo: public Bar\" part of:
2596 class Foo: public Bar {int x();} a, *b;
2598 If parens can occur, the chars inside those aren't filtered with this
2601 '<' and '>' should be disallowed even if angle bracket arglists can
2602 occur. That since the search function needs to stop at them anyway to
2603 ensure they are given paren syntax.
2605 This is used to skip backward from the open brace to find the region
2606 in which to look for a construct like \"class\", \"enum\",
2607 \"namespace\" or whatever. That skipping should be as tight as
2608 possible for good performance."
2610 ;; Default to all chars that only occurs in nonsymbol tokens outside
2613 (c-lang-const c-nonsymbol-token-char-list
)
2614 (c-filter-ops (append (c-lang-const c-identifier-ops
)
2616 (c-lang-const c-after-id-concat-ops
))))
2621 (while (string-match "\\(\\s.\\|\\s(\\|\\s)\\)"
2623 (setq res
(cons (aref op
(match-beginning 1)) res
)
2627 ;; Allow cpp operatios (where applicable).
2628 t
(if (c-lang-const c-opt-cpp-prefix
)
2629 (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2631 (c-lang-const c-block-prefix-disallowed-chars
))
2633 ;; Allow ':' for inherit list starters.
2634 (c++ objc idl
) (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2637 ;; Allow ',' for multiple inherits.
2638 (c++ java
) (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2641 ;; Allow parentheses for anonymous inner classes in Java and class
2642 ;; initializer lists in Pike.
2643 (java pike
) (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2646 ;; Allow '"' for extern clauses (e.g. extern "C" {...}).
2647 (c c
++ objc
) (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2650 (c-lang-defconst c-block-prefix-charset
2651 ;; `c-block-prefix-disallowed-chars' as an inverted charset suitable
2652 ;; for `c-syntactic-skip-backward'.
2653 t
(c-make-bare-char-alt (c-lang-const c-block-prefix-disallowed-chars
) t
))
2654 (c-lang-defvar c-block-prefix-charset
(c-lang-const c-block-prefix-charset
))
2656 (c-lang-defconst c-type-decl-prefix-key
2657 "Regexp matching the declarator operators that might precede the
2658 identifier in a declaration, e.g. the \"*\" in \"char *argv\". This
2659 regexp should match \"(\" if parentheses are valid in declarators.
2660 The end of the first submatch is taken as the end of the operator.
2661 Identifier syntax is in effect when this is matched \(see
2662 `c-identifier-syntax-table')."
2663 t
(if (c-lang-const c-type-modifier-kwds
)
2664 (concat (regexp-opt (c-lang-const c-type-modifier-kwds
) t
) "\\>")
2665 ;; Default to a regexp that never matches.
2667 ;; Check that there's no "=" afterwards to avoid matching tokens
2669 (c objc
) (concat "\\("
2672 (c-lang-const c-type-decl-prefix-key
)
2678 (c-lang-const c-type-decl-prefix-key
)
2681 ;; If this matches there's special treatment in
2682 ;; `c-font-lock-declarators' and
2683 ;; `c-font-lock-declarations' that check for a
2684 ;; complete name followed by ":: *".
2685 (c-lang-const c-identifier-start
)
2689 pike
"\\(\\*\\)\\([^=]\\|$\\)")
2690 (c-lang-defvar c-type-decl-prefix-key
(c-lang-const c-type-decl-prefix-key
)
2693 (c-lang-defconst c-type-decl-suffix-key
2694 "Regexp matching the declarator operators that might follow after the
2695 identifier in a declaration, e.g. the \"[\" in \"char argv[]\". This
2696 regexp should match \")\" if parentheses are valid in declarators. If
2697 it matches an open paren of some kind, the type declaration check
2698 continues at the corresponding close paren, otherwise the end of the
2699 first submatch is taken as the end of the operator. Identifier syntax
2700 is in effect when this is matched (see `c-identifier-syntax-table')."
2701 ;; Default to a regexp that matches `c-type-modifier-kwds' and a
2702 ;; function argument list parenthesis.
2703 t
(if (c-lang-const c-type-modifier-kwds
)
2705 (regexp-opt (c-lang-const c-type-modifier-kwds
) t
) "\\>"
2708 (c c
++ objc
) (concat
2711 (if (c-lang-const c-type-modifier-kwds
)
2714 ;; "throw" in `c-type-modifier-kwds' is followed
2715 ;; by a parenthesis list, but no extra measures
2716 ;; are necessary to handle that.
2717 (regexp-opt (c-lang-const c-type-modifier-kwds
) t
)
2721 (java idl
) "\\([\[\(]\\)")
2722 (c-lang-defvar c-type-decl-suffix-key
(c-lang-const c-type-decl-suffix-key
)
2725 (c-lang-defconst c-after-suffixed-type-decl-key
2726 "This regexp is matched after a declarator expression where
2727 `c-type-decl-suffix-key' has matched. If it matches then the
2728 construct is taken as a declaration. It's typically used to match the
2729 beginning of a function body or whatever might occur after the
2730 function header in a function declaration or definition. It's
2731 undefined whether identifier syntax (see `c-identifier-syntax-table')
2732 is in effect or not.
2734 Note that it's used in cases like after \"foo (bar)\" so it should
2735 only match when it's certain that it's a declaration, e.g \"{\" but
2736 not \",\" or \";\"."
2738 ;; If K&R style declarations should be recognized then one could
2739 ;; consider to match the start of any symbol since we want to match
2740 ;; the start of the first declaration in the "K&R region". That
2741 ;; could however produce false matches on code like "FOO(bar) x"
2742 ;; where FOO is a cpp macro, so it's better to leave it out and rely
2743 ;; on the other heuristics in that case.
2744 t
(if (c-lang-const c-postfix-spec-kwds
)
2745 ;; Add on the keywords in `c-postfix-spec-kwds'.
2746 (concat (c-lang-const c-after-suffixed-type-decl-key
)
2748 (c-make-keywords-re t
(c-lang-const c-postfix-spec-kwds
)))
2749 (c-lang-const c-after-suffixed-type-decl-key
))
2750 ;; Also match the colon that starts a base class initializer list in
2751 ;; C++. That can be confused with a function call before the colon
2752 ;; in a ? : operator, but we count on that `c-decl-prefix-re' won't
2753 ;; match before such a thing (as a declaration-level construct;
2754 ;; matches inside arglist contexts are already excluded).
2756 (c-lang-defvar c-after-suffixed-type-decl-key
2757 (c-lang-const c-after-suffixed-type-decl-key
)
2760 (c-lang-defconst c-after-suffixed-type-maybe-decl-key
2761 ;; Regexp that in addition to `c-after-suffixed-type-decl-key'
2762 ;; matches ";" and ",".
2763 t
(concat "\\(" (c-lang-const c-after-suffixed-type-decl-key
) "\\)"
2765 (c-lang-defvar c-after-suffixed-type-maybe-decl-key
2766 (c-lang-const c-after-suffixed-type-maybe-decl-key
))
2768 (c-lang-defconst c-opt-type-concat-key
2769 "Regexp matching operators that concatenate types, e.g. the \"|\" in
2770 \"int|string\" in Pike. The end of the first submatch is taken as the
2771 end of the operator. nil in languages without such operators. It's
2772 undefined whether identifier syntax (see `c-identifier-syntax-table')
2773 is in effect or not."
2775 pike
"\\([|.&]\\)\\($\\|[^|.&]\\)")
2776 (c-lang-defvar c-opt-type-concat-key
(c-lang-const c-opt-type-concat-key
)
2779 (c-lang-defconst c-opt-type-suffix-key
2780 "Regexp matching operators that might follow after a type, or nil in
2781 languages that don't have such operators. The end of the first
2782 submatch is taken as the end of the operator. This should not match
2783 things like C++ template arglists if `c-recognize-<>-arglists' is set.
2784 It's undefined whether identifier syntax (see `c-identifier-syntax-table')
2785 is in effect or not."
2787 (c c
++ objc pike
) "\\(\\.\\.\\.\\)"
2788 java
(concat "\\(\\[" (c-lang-const c-simple-ws
) "*\\]\\|\\.\\.\\.\\)"))
2789 (c-lang-defvar c-opt-type-suffix-key
(c-lang-const c-opt-type-suffix-key
))
2791 (c-lang-defvar c-known-type-key
2792 ;; Regexp matching the known type identifiers. This is initialized
2793 ;; from the type keywords and `*-font-lock-extra-types'. The first
2794 ;; submatch is the one that matches the type. Note that this regexp
2795 ;; assumes that symbol constituents like '_' and '$' have word
2798 (when (boundp (c-mode-symbol "font-lock-extra-types"))
2799 (c-mode-var "font-lock-extra-types")))
2802 (mapcar (lambda (re)
2803 (when (string-match "[][.*+?^$\\]" re
)
2808 (mapcar (lambda (re)
2809 (unless (string-match "[][.*+?^$\\]" re
)
2814 (append (list (c-make-keywords-re nil
2815 (append (c-lang-const c-primitive-type-kwds
)
2821 (c-lang-defconst c-special-brace-lists
2822 "List of open- and close-chars that makes up a pike-style brace list,
2823 i.e. for a ([Â ]) list there should be a cons (?\\[ . ?\\]) in this
2826 pike
'((?
{ . ?
}) (?\
[ . ?\
]) (?
< . ?
>)))
2827 (c-lang-defvar c-special-brace-lists
(c-lang-const c-special-brace-lists
))
2829 (c-lang-defconst c-recognize-knr-p
2830 "Non-nil means K&R style argument declarations are valid."
2833 (c-lang-defvar c-recognize-knr-p
(c-lang-const c-recognize-knr-p
))
2835 (c-lang-defconst c-recognize-typeless-decls
2836 "Non-nil means function declarations without return type should be
2837 recognized. That can introduce an ambiguity with parenthesized macro
2838 calls before a brace block. This setting does not affect declarations
2839 that are preceded by a declaration starting keyword, so
2840 e.g. `c-typeless-decl-kwds' may still be used when it's set to nil."
2843 (c-lang-defvar c-recognize-typeless-decls
2844 (c-lang-const c-recognize-typeless-decls
))
2846 (c-lang-defconst c-recognize-
<>-arglists
2847 "Non-nil means C++ style template arglists should be handled. More
2848 specifically, this means a comma separated list of types or
2849 expressions surrounded by \"<\" and \">\". It's always preceded by an
2850 identifier or one of the keywords on `c-<>-type-kwds' or
2851 `c-<>-arglist-kwds'. If there's an identifier before then the whole
2852 expression is considered to be a type."
2853 t
(or (consp (c-lang-const c-
<>-type-kwds
))
2854 (consp (c-lang-const c-
<>-arglist-kwds
))))
2855 (c-lang-defvar c-recognize-
<>-arglists
(c-lang-const c-recognize-
<>-arglists
))
2857 (c-lang-defconst c-recognize-paren-inits
2858 "Non-nil means that parenthesis style initializers exist,
2859 i.e. constructs like
2863 in addition to the more classic
2868 (c-lang-defvar c-recognize-paren-inits
(c-lang-const c-recognize-paren-inits
))
2870 (c-lang-defconst c-recognize-paren-inexpr-blocks
2871 "Non-nil to recognize gcc style in-expression blocks,
2872 i.e. compound statements surrounded by parentheses inside expressions."
2875 (c-lang-defvar c-recognize-paren-inexpr-blocks
2876 (c-lang-const c-recognize-paren-inexpr-blocks
))
2878 (c-lang-defconst c-opt-
<>-arglist-start
2879 ;; Regexp matching the start of angle bracket arglists in languages
2880 ;; where `c-recognize-<>-arglists' is set. Does not exclude
2881 ;; keywords outside `c-<>-arglist-kwds'. The first submatch is
2882 ;; assumed to surround the preceding symbol. The whole match is
2883 ;; assumed to end directly after the opening "<".
2884 t
(if (c-lang-const c-recognize-
<>-arglists
)
2886 (c-lang-const c-symbol-key
)
2888 (c-lang-const c-syntactic-ws
)
2890 (c-lang-defvar c-opt-
<>-arglist-start
(c-lang-const c-opt-
<>-arglist-start
))
2892 (c-lang-defconst c-opt-
<>-arglist-start-in-paren
2893 ;; Regexp that in addition to `c-opt-<>-arglist-start' matches close
2894 ;; parens. The first submatch is assumed to surround
2895 ;; `c-opt-<>-arglist-start'.
2896 t
(if (c-lang-const c-opt-
<>-arglist-start
)
2898 (c-lang-const c-opt-
<>-arglist-start
)
2900 (c-lang-defvar c-opt-
<>-arglist-start-in-paren
2901 (c-lang-const c-opt-
<>-arglist-start-in-paren
))
2903 (c-lang-defconst c-opt-postfix-decl-spec-key
2904 ;; Regexp matching the beginning of a declaration specifier in the
2905 ;; region between the header and the body of a declaration.
2907 ;; TODO: This is currently not used uniformly; c++-mode and
2908 ;; java-mode each have their own ways of using it.
2911 (c-lang-const c-simple-ws
) "*"
2912 "\\(virtual" (c-lang-const c-simple-ws
) "+\\)?\\("
2913 (c-make-keywords-re nil
(c-lang-const c-protection-kwds
))
2914 "\\)" (c-lang-const c-simple-ws
) "+"
2915 "\\(" (c-lang-const c-symbol-key
) "\\)")
2916 java
(c-make-keywords-re t
(c-lang-const c-postfix-spec-kwds
)))
2917 (c-lang-defvar c-opt-postfix-decl-spec-key
2918 (c-lang-const c-opt-postfix-decl-spec-key
))
2920 (c-lang-defconst c-recognize-colon-labels
2921 "Non-nil if generic labels ending with \":\" should be recognized.
2922 That includes labels in code and access keys in classes. This does
2923 not apply to labels recognized by `c-label-kwds' and
2924 `c-opt-extra-label-key'."
2926 (c c
++ objc java pike
) t
)
2927 (c-lang-defvar c-recognize-colon-labels
2928 (c-lang-const c-recognize-colon-labels
))
2930 (c-lang-defconst c-label-prefix-re
2931 "Regexp like `c-decl-prefix-re' that matches any token that can precede
2932 a generic colon label. Not used if `c-recognize-colon-labels' is
2935 (c-lang-defvar c-label-prefix-re
2936 (c-lang-const c-label-prefix-re
))
2938 (c-lang-defconst c-nonlabel-token-key
2939 "Regexp matching things that can't occur in generic colon labels,
2940 neither in a statement nor in a declaration context. The regexp is
2941 tested at the beginning of every sexp in a suspected label,
2942 i.e. before \":\". Only used if `c-recognize-colon-labels' is set."
2944 ;; Don't allow string literals.
2946 ;; All keywords except `c-label-kwds' and `c-protection-kwds'.
2947 (c-make-keywords-re t
2948 (set-difference (c-lang-const c-keywords
)
2949 (append (c-lang-const c-label-kwds
)
2950 (c-lang-const c-protection-kwds
))
2951 :test
'string-equal
)))
2952 ;; Also check for open parens in C++, to catch member init lists in
2953 ;; constructors. We normally allow it so that macros with arguments
2955 c
++ (concat "\\s\(\\|" (c-lang-const c-nonlabel-token-key
)))
2956 (c-lang-defvar c-nonlabel-token-key
(c-lang-const c-nonlabel-token-key
))
2958 (c-lang-defconst c-opt-extra-label-key
2959 "Optional regexp matching labels.
2960 Normally, labels are detected according to `c-nonlabel-token-key',
2961 `c-decl-prefix-re' and `c-nonlabel-decl-prefix-re'. This regexp can
2962 be used if there are additional labels that aren't recognized that
2965 objc
(c-make-keywords-re t
(c-lang-const c-protection-kwds
)))
2966 (c-lang-defvar c-opt-extra-label-key
(c-lang-const c-opt-extra-label-key
))
2968 (c-lang-defconst c-opt-friend-key
2969 ;; Regexp describing friend declarations classes, or nil in
2970 ;; languages that don't have such things.
2972 ;; TODO: Ought to use `c-prefix-spec-kwds-re' or similar, and the
2973 ;; template skipping isn't done properly. This will disappear soon.
2975 c
++ (concat "friend" (c-lang-const c-simple-ws
) "+"
2978 (c-lang-const c-simple-ws
) "*"
2980 (c-lang-const c-simple-ws
) "*"
2982 (c-lang-const c-simple-ws
) "+")))
2983 (c-lang-defvar c-opt-friend-key
(c-lang-const c-opt-friend-key
))
2985 (c-lang-defconst c-opt-method-key
2986 ;; Special regexp to match the start of Objective-C methods. The
2987 ;; first submatch is assumed to end after the + or - key.
2990 ;; TODO: Ought to use a better method than anchoring on bol.
2993 (c-lang-const c-simple-ws
) "*"
2994 (concat "\\(" ; Return type.
2996 (c-lang-const c-simple-ws
) "*"
2998 "\\(" (c-lang-const c-symbol-key
) "\\)"))
2999 (c-lang-defvar c-opt-method-key
(c-lang-const c-opt-method-key
))
3001 (c-lang-defconst c-type-decl-end-used
3002 ;; Must be set in buffers where the `c-type' text property might be
3003 ;; used with the value `c-decl-end'.
3005 ;; `c-decl-end' is used to mark the ends of labels and access keys
3006 ;; to make interactive refontification work better.
3007 t
(or (c-lang-const c-recognize-colon-labels
)
3008 (and (c-lang-const c-label-kwds
) t
))
3009 ;; `c-decl-end' is used to mark the end of the @-style directives in
3012 (c-lang-defvar c-type-decl-end-used
(c-lang-const c-type-decl-end-used
))
3015 ;;; Wrap up the `c-lang-defvar' system.
3017 ;; Compile in the list of language variables that has been collected
3018 ;; with the `c-lang-defvar' and `c-lang-setvar' macros. Note that the
3019 ;; first element of each is nil.
3020 (defconst c-lang-variable-inits
(cc-eval-when-compile c-lang-variable-inits
))
3021 (defconst c-emacs-variable-inits
(cc-eval-when-compile c-emacs-variable-inits
))
3023 ;; Make the `c-lang-setvar' variables buffer local in the current buffer.
3024 ;; These are typically standard emacs variables such as `comment-start'.
3025 (defmacro c-make-emacs-variables-local
()
3027 ,@(mapcar (lambda (init)
3028 `(make-local-variable ',(car init
)))
3029 (cdr c-emacs-variable-inits
))))
3031 (defun c-make-init-lang-vars-fun (mode)
3032 "Create a function that initializes all the language dependent variables
3035 This function should be evaluated at compile time, so that the
3036 function it returns is byte compiled with all the evaluated results
3037 from the language constants. Use the `c-init-language-vars' macro to
3038 accomplish that conveniently."
3040 (if (and (not load-in-progress
)
3041 (boundp 'byte-compile-dest-file
)
3042 (stringp byte-compile-dest-file
))
3044 ;; No need to byte compile this lambda since the byte compiler is
3045 ;; smart enough to detect the `funcall' construct in the
3046 ;; `c-init-language-vars' macro below and compile it all straight
3047 ;; into the function that contains `c-init-language-vars'.
3050 ;; This let sets up the context for `c-mode-var' and similar
3051 ;; that could be in the result from `cl-macroexpand-all'.
3052 (let ((c-buffer-is-cc-mode ',mode
)
3053 current-var source-eval
)
3054 (c-make-emacs-variables-local)
3057 (if (eq c-version-sym
',c-version-sym
)
3058 (setq ,@(let ((c-buffer-is-cc-mode mode
)
3059 (c-lang-const-expansion 'immediate
))
3060 ;; `c-lang-const' will expand to the evaluated
3061 ;; constant immediately in `cl-macroexpand-all'
3065 `(current-var ',(car init
)
3066 ,(car init
) ,(cl-macroexpand-all
3068 ;; Note: The following `append' copies the
3069 ;; first argument. That list is small, so
3070 ;; this doesn't matter too much.
3071 (append (cdr c-emacs-variable-inits
)
3072 (cdr c-lang-variable-inits
)))))
3074 ;; This diagnostic message isn't useful for end
3075 ;; users, so it's disabled.
3076 ;;(unless (get ',mode 'c-has-warned-lang-consts)
3077 ;; (message ,(concat "%s compiled with CC Mode %s "
3078 ;; "but loaded with %s - evaluating "
3079 ;; "language constants from source")
3080 ;; ',mode ,c-version c-version)
3081 ;; (put ',mode 'c-has-warned-lang-consts t))
3084 (setq source-eval t
)
3085 (let ((init (append (cdr c-emacs-variable-inits
)
3086 (cdr c-lang-variable-inits
))))
3088 (setq current-var
(caar init
))
3089 (set (caar init
) (eval (cadar init
)))
3090 (setq init
(cdr init
)))))
3094 (message "Eval error in the `c-lang-defvar' or `c-lang-setvar' for `%s'%s: %S"
3098 (fallback source eval - %s compiled with CC Mode %s but loaded with %s)"
3099 ',mode
,c-version c-version
)
3102 (signal (car err
) (cdr err
)))))))
3104 ;; Being evaluated from source. Always use the dynamic method to
3105 ;; work well when `c-lang-defvar's in this file are reevaluated
3109 (let ((c-buffer-is-cc-mode ',mode
)
3110 (init (append (cdr c-emacs-variable-inits
)
3111 (cdr c-lang-variable-inits
)))
3113 (c-make-emacs-variables-local)
3117 (setq current-var
(caar init
))
3118 (set (caar init
) (eval (cadar init
)))
3119 (setq init
(cdr init
)))
3124 "Eval error in the `c-lang-defvar' or `c-lang-setver' for `%s' (source eval): %S"
3126 (signal (car err
) (cdr err
)))))))
3129 (defmacro c-init-language-vars
(mode)
3130 "Initialize all the language dependent variables for the given mode.
3131 This macro is expanded at compile time to a form tailored for the mode
3132 in question, so MODE must be a constant. Therefore MODE is not
3133 evaluated and should not be quoted."
3134 `(funcall ,(c-make-init-lang-vars-fun mode
)))
3137 (cc-provide 'cc-langs
)
3139 ;;; cc-langs.el ends here