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