1 ;;; cc-langs.el --- language specific settings for CC Mode
3 ;; Copyright (C) 1985,1987,1992-2003, 2004, 2005 Free Software Foundation,
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)
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.
34 ;; HACKERS NOTE: There's heavy macro magic here. If you need to make
35 ;; changes in this or other files containing `c-lang-defconst' but
36 ;; don't want to read through the longer discussion below then read
39 ;; o A change in a `c-lang-defconst' or `c-lang-defvar' will not take
40 ;; effect if the file containing the mode init function (typically
41 ;; cc-mode.el) is byte compiled.
42 ;; o To make changes show in font locking you need to reevaluate the
43 ;; `*-font-lock-keywords-*' constants, which normally is easiest to
44 ;; do with M-x eval-buffer in cc-fonts.el.
45 ;; o In either case it's necessary to reinitialize the mode to make
46 ;; the changes show in an existing buffer.
48 ;;; Introduction to the language dependent variable system:
50 ;; This file contains all the language dependent variables, except
51 ;; those specific for font locking which reside in cc-fonts.el. As
52 ;; far as possible, all the differences between the languages that CC
53 ;; Mode supports are described with these variables only, so that the
54 ;; code can be shared.
56 ;; The language constant system (see cc-defs.el) is used to specify
57 ;; various language dependent info at a high level, such as lists of
58 ;; keywords, and then from them generate - at compile time - the
59 ;; various regexps and other low-level structures actually employed in
60 ;; the code at runtime.
62 ;; This system is also designed to make it easy for developers of
63 ;; derived modes to customize the source constants for new language
64 ;; variants, without having to keep up with the exact regexps etc that
65 ;; are used in each CC Mode version. It's possible from an external
66 ;; package to add a new language by inheriting an existing one, and
67 ;; then change specific constants as necessary for the new language.
68 ;; The old values for those constants (and the values of all the other
69 ;; high-level constants) may be used to build the new ones, and those
70 ;; new values will in turn be used by the low-level definitions here
71 ;; to build the runtime constants appropriately for the new language
72 ;; in the current version of CC Mode.
74 ;; Like elsewhere in CC Mode, the existence of a doc string signifies
75 ;; that a language constant is part of the external API, and that it
76 ;; therefore can be used with a high confidence that it will continue
77 ;; to work with future versions of CC Mode. Even so, it's not
78 ;; unlikely that such constants will change meaning slightly as this
79 ;; system is refined further; a certain degree of dependence on the CC
80 ;; Mode version is unavoidable when hooking in at this level. Also
81 ;; note that there's still work to be done to actually use these
82 ;; constants everywhere inside CC Mode; there are still hardcoded
83 ;; values in many places in the code.
85 ;; Separate packages will also benefit from the compile time
86 ;; evaluation; the byte compiled file(s) for them will contain the
87 ;; compiled runtime constants ready for use by (the byte compiled) CC
88 ;; Mode, and the source definitions in this file don't have to be
89 ;; loaded then. However, if a byte compiled package is loaded that
90 ;; has been compiled with a different version of CC Mode than the one
91 ;; currently loaded, then the compiled-in values will be discarded and
92 ;; new ones will be built when the mode is initialized. That will
93 ;; automatically trig a load of the file(s) containing the source
94 ;; definitions (i.e. this file and/or cc-fonts.el) if necessary.
96 ;; A small example of a derived mode is available at
97 ;; <http://cc-mode.sourceforge.net/derived-mode-ex.el>. It also
98 ;; contains some useful hints for derived mode developers.
100 ;;; Using language variables:
102 ;; The `c-lang-defvar' forms in this file comprise the language
103 ;; variables that CC Mode uses. It does not work to use
104 ;; `c-lang-defvar' anywhere else (which isn't much of a limitation
105 ;; since these variables sole purpose is to interface with the CC Mode
106 ;; core functions). The values in these `c-lang-defvar's are not
107 ;; evaluated right away but instead collected to a single large `setq'
108 ;; that can be inserted for a particular language with the
109 ;; `c-init-language-vars' macro.
111 ;; This file is only required at compile time, or when not running
112 ;; from byte compiled files, or when the source definitions for the
113 ;; language constants are requested.
119 (if (and (boundp 'byte-compile-dest-file
)
120 (stringp byte-compile-dest-file
))
121 (cons (file-name-directory byte-compile-dest-file
) 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.
136 ;; These are used to collect the init forms from the subsequent
137 ;; `c-lang-defvar'. They are used to build the lambda in
138 ;; `c-make-init-lang-vars-fun' below.
139 (defvar c-lang-variable-inits nil
)
140 (defvar c-lang-variable-inits-tail nil
)
141 (setq c-lang-variable-inits
(list nil
)
142 c-lang-variable-inits-tail c-lang-variable-inits
))
144 (defmacro c-lang-defvar
(var val
&optional doc
)
145 "Declares the buffer local variable VAR to get the value VAL. VAL is
146 evaluated and assigned at mode initialization. More precisely, VAL is
147 evaluated and bound to VAR when the result from the macro
148 `c-init-language-vars' is evaluated.
150 `c-lang-const' is typically used in VAL to get the right value for the
151 language being initialized, and such calls will be macro expanded to
152 the evaluated constant value at compile time."
155 (eq (car-safe val
) 'c-lang-const
)
158 ;; Special case: If there's no docstring and the value is a
159 ;; simple (c-lang-const foo) where foo is the same name as VAR
160 ;; then take the docstring from the language constant foo.
161 (setq doc
(get (intern (symbol-name (nth 1 val
)) c-lang-constants
)
162 'variable-documentation
)))
166 (let ((elem (assq var
(cdr c-lang-variable-inits
))))
168 (setcdr elem
(list val doc
))
169 (setcdr c-lang-variable-inits-tail
(list (list var val doc
)))
170 (setq c-lang-variable-inits-tail
(cdr c-lang-variable-inits-tail
))))
172 ;; Return the symbol, like the other def* forms.
175 (put 'c-lang-defvar
'lisp-indent-function
'defun
)
176 (eval-after-load "edebug"
177 '(def-edebug-spec c-lang-defvar
178 (&define name def-form
&optional stringp
)))
181 ;; Some helper functions used when building the language constants.
183 (defun c-filter-ops (ops opgroup-filter op-filter
&optional xlate
)
184 ;; Used to filter operators from the list OPS in a DWIM:ey way:
185 ;; OPS either has the structure of `c-operators', as a single
186 ;; group in `c-operators', or is a plain list of operators.
187 ;; OPGROUP-FILTER is used filter out the operator groups. It can
188 ;; be t to choose all groups, a list of the group type symbols to
189 ;; accept, or a function which will be called with the group
190 ;; symbol for each group and should return non-nil for those to
191 ;; include. OP-FILTER filters the individual operators in each
192 ;; group. It can be t to choose all operators, a regexp to test
193 ;; against each operator, or a function which will be called for
194 ;; each operator and should return non-nil for those to include.
195 ;; If XLATE is given, it's a function which is called for each
196 ;; matching operator and its return value is collected instead.
197 ;; If it returns a list, the elements are spliced directly into
198 ;; the final result, which is returned as a list with duplicates
199 ;; removed using `equal'. `c-mode-syntax-table' for the current
200 ;; mode is in effect during the whole procedure.
201 (unless (listp (car-safe ops
))
202 (setq ops
(list ops
)))
203 (cond ((eq opgroup-filter t
)
204 (setq opgroup-filter
(lambda (opgroup) t
)))
205 ((not (functionp opgroup-filter
))
206 (setq opgroup-filter
`(lambda (opgroup)
207 (memq opgroup
',opgroup-filter
)))))
208 (cond ((eq op-filter t
)
209 (setq op-filter
(lambda (op) t
)))
211 (setq op-filter
`(lambda (op)
212 (string-match ,op-filter op
)))))
214 (setq xlate
'identity
))
215 (c-with-syntax-table (c-lang-const c-mode-syntax-table
)
217 (mapcan (lambda (opgroup)
218 (when (if (symbolp (car opgroup
))
219 (when (funcall opgroup-filter
(car opgroup
))
220 (setq opgroup
(cdr opgroup
))
224 (when (funcall op-filter op
)
225 (let ((res (funcall xlate op
)))
226 (if (listp res
) res
(list res
)))))
232 ;;; Various mode specific values that aren't language related.
234 (c-lang-defconst c-mode-menu
235 ;; The definition for the mode menu. The menu title is prepended to
236 ;; this before it's fed to `easy-menu-define'.
237 t
`(["Comment Out Region" comment-region
238 (c-fn-region-is-active-p)]
239 ["Uncomment Region" (comment-region (region-beginning)
241 (c-fn-region-is-active-p)]
242 ["Indent Expression" c-indent-exp
243 (memq (char-after) '(?\
( ?\
[ ?\
{))]
244 ["Indent Line or Region" c-indent-line-or-region t
]
245 ["Fill Comment Paragraph" c-fill-paragraph t
]
247 ["Backward Statement" c-beginning-of-statement t
]
248 ["Forward Statement" c-end-of-statement t
]
249 ,@(when (c-lang-const c-opt-cpp-prefix
)
250 ;; Only applicable if there's a cpp preprocessor.
251 `(["Up Conditional" c-up-conditional t
]
252 ["Backward Conditional" c-backward-conditional t
]
253 ["Forward Conditional" c-forward-conditional t
]
255 ["Macro Expand Region" c-macro-expand
256 (c-fn-region-is-active-p)]
257 ["Backslashify" c-backslash-region
258 (c-fn-region-is-active-p)]))
261 ["Syntactic indentation" c-toggle-syntactic-indentation t
]
262 ["Auto newline" c-toggle-auto-newline t
]
263 ["Hungry delete" c-toggle-hungry-state t
])))
268 (defun c-populate-syntax-table (table)
269 "Populate the given syntax table as necessary for a C-like language.
270 This includes setting ' and \" as string delimiters, and setting up
271 the comment syntax to handle both line style \"//\" and block style
272 \"/*\" \"*/\" comments."
274 (modify-syntax-entry ?_
"_" table
)
275 (modify-syntax-entry ?
\\ "\\" table
)
276 (modify-syntax-entry ?
+ "." table
)
277 (modify-syntax-entry ?-
"." table
)
278 (modify-syntax-entry ?
= "." table
)
279 (modify-syntax-entry ?%
"." table
)
280 (modify-syntax-entry ?
< "." table
)
281 (modify-syntax-entry ?
> "." table
)
282 (modify-syntax-entry ?
& "." table
)
283 (modify-syntax-entry ?|
"." table
)
284 (modify-syntax-entry ?
\' "\"" table
)
285 (modify-syntax-entry ?
\240 "." table
)
287 ;; Set up block and line oriented comments. The new C
288 ;; standard mandates both comment styles even in C, so since
289 ;; all languages now require dual comments, we make this the
293 ((memq '8-bit c-emacs-features
)
294 (modify-syntax-entry ?
/ ". 1456" table
)
295 (modify-syntax-entry ?
* ". 23" table
))
297 ((memq '1-bit c-emacs-features
)
298 (modify-syntax-entry ?
/ ". 124b" table
)
299 (modify-syntax-entry ?
* ". 23" table
))
301 (t (error "CC Mode is incompatible with this version of Emacs")))
303 (modify-syntax-entry ?
\n "> b" table
)
304 ;; Give CR the same syntax as newline, for selective-display
305 (modify-syntax-entry ?\^m
"> b" table
))
307 (c-lang-defconst c-make-mode-syntax-table
308 "Functions that generates the mode specific syntax tables.
309 The syntax tables aren't stored directly since they're quite large."
311 (let ((table (make-syntax-table)))
312 (c-populate-syntax-table table
)
313 ;; Mode specific syntaxes.
314 ,(cond ((c-major-mode-is 'objc-mode
)
315 ;; Let '@' be part of symbols in ObjC to cope with
316 ;; its compiler directives as single keyword tokens.
317 ;; This is then necessary since it's assumed that
318 ;; every keyword is a single symbol.
319 `(modify-syntax-entry ?
@ "_" table
))
320 ((c-major-mode-is 'pike-mode
)
321 `(modify-syntax-entry ?
@ "." table
)))
324 (c-lang-defconst c-mode-syntax-table
325 ;; The syntax tables in evaluated form. Only used temporarily when
326 ;; the constants in this file are evaluated.
327 t
(funcall (c-lang-const c-make-mode-syntax-table
)))
329 (c-lang-defconst c
++-make-template-syntax-table
330 ;; A variant of `c++-mode-syntax-table' that defines `<' and `>' as
331 ;; parenthesis characters. Used temporarily when template argument
332 ;; lists are parsed. Note that this encourages incorrect parsing of
333 ;; templates since they might contain normal operators that uses the
334 ;; '<' and '>' characters. Therefore this syntax table might go
335 ;; away when CC Mode handles templates correctly everywhere.
338 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table
))))
339 (modify-syntax-entry ?
< "(>" table
)
340 (modify-syntax-entry ?
> ")<" table
)
342 (c-lang-defvar c
++-template-syntax-table
343 (and (c-lang-const c
++-make-template-syntax-table
)
344 (funcall (c-lang-const c
++-make-template-syntax-table
))))
346 (c-lang-defconst c-identifier-syntax-modifications
347 "A list that describes the modifications that should be done to the
348 mode syntax table to get a syntax table that matches all identifiers
349 and keywords as words.
351 The list is just like the one used in `font-lock-defaults': Each
352 element is a cons where the car is the character to modify and the cdr
353 the new syntax, as accepted by `modify-syntax-entry'."
354 ;; The $ character is not allowed in most languages (one exception
355 ;; is Java which allows it for legacy reasons) but we still classify
356 ;; it as an indentifier character since it's often used in various
357 ;; machine generated identifiers.
358 t
'((?_ .
"w") (?$ .
"w"))
359 objc
(append '((?
@ .
"w"))
360 (c-lang-const c-identifier-syntax-modifications
))
362 (c-lang-defvar c-identifier-syntax-modifications
363 (c-lang-const c-identifier-syntax-modifications
))
365 (c-lang-defvar c-identifier-syntax-table
366 (let ((table (copy-syntax-table (c-mode-var "mode-syntax-table")))
367 (mods c-identifier-syntax-modifications
)
372 (modify-syntax-entry (car mod
) (cdr mod
) table
))
374 "Syntax table built on the mode syntax table but additionally
375 classifies symbol constituents like '_' and '$' as word constituents,
376 so that all identifiers are recognized as words.")
379 ;;; Lexer-level syntax (identifiers, tokens etc).
381 (c-lang-defconst c-symbol-start
382 "Regexp that matches the start of a symbol, i.e. any identifier or
383 keyword. It's unspecified how far it matches. Does not contain a \\|
384 operator at the top level."
385 t
(concat "[" c-alpha
"_]")
386 objc
(concat "[" c-alpha
"@]")
387 pike
(concat "[" c-alpha
"_`]"))
388 (c-lang-defvar c-symbol-start
(c-lang-const c-symbol-start
))
390 (c-lang-defconst c-symbol-chars
391 "Set of characters that can be part of a symbol.
392 This is on the form that fits inside [ ] in a regexp."
393 ;; Pike note: With the backquote identifiers this would include most
394 ;; operator chars too, but they are handled with other means instead.
395 t
(concat c-alnum
"_$")
396 objc
(concat c-alnum
"_$@"))
398 (c-lang-defconst c-symbol-key
399 "Regexp matching identifiers and keywords (with submatch 0). Assumed
400 to match if `c-symbol-start' matches on the same position."
401 t
(concat (c-lang-const c-symbol-start
)
402 "[" (c-lang-const c-symbol-chars
) "]*")
404 ;; Use the value from C here since the operator backquote is
405 ;; covered by the other alternative.
406 (c-lang-const c-symbol-key c
)
408 (c-make-keywords-re nil
409 (c-lang-const c-overloadable-operators
))))
410 (c-lang-defvar c-symbol-key
(c-lang-const c-symbol-key
))
412 (c-lang-defconst c-symbol-key-depth
413 ;; Number of regexp grouping parens in `c-symbol-key'.
414 t
(regexp-opt-depth (c-lang-const c-symbol-key
)))
416 (c-lang-defconst c-nonsymbol-chars
417 "This is the set of chars that can't be part of a symbol, i.e. the
418 negation of `c-symbol-chars'."
419 t
(concat "^" (c-lang-const c-symbol-chars
)))
420 (c-lang-defvar c-nonsymbol-chars
(c-lang-const c-nonsymbol-chars
))
422 (c-lang-defconst c-nonsymbol-key
423 "Regexp that matches any character that can't be part of a symbol.
424 It's usually appended to other regexps to avoid matching a prefix.
425 It's assumed to not contain any submatchers."
426 ;; The same thing regarding Unicode identifiers applies here as to
428 t
(concat "[" (c-lang-const c-nonsymbol-chars
) "]"))
430 (c-lang-defconst c-identifier-ops
431 "The operators that make up fully qualified identifiers. nil in
432 languages that don't have such things. See `c-operators' for a
433 description of the format. Binary operators can concatenate symbols,
434 e.g. \"::\" in \"A::B::C\". Prefix operators can precede identifiers,
435 e.g. \"~\" in \"~A::B\". Other types of operators aren't supported.
437 This value is by default merged into `c-operators'."
439 c
++ '((prefix "~" "??-" "compl")
442 ;; Java has "." to concatenate identifiers but it's also used for
443 ;; normal indexing. There's special code in the Java font lock
444 ;; rules to fontify qualified identifiers based on the standard
445 ;; naming conventions. We still define "." here to make
446 ;; `c-forward-name' move over as long names as possible which is
447 ;; necessary to e.g. handle throws clauses correctly.
448 java
'((left-assoc "."))
449 idl
'((left-assoc "::")
451 pike
'((left-assoc "::")
455 (c-lang-defconst c-opt-identifier-concat-key
456 ;; Appendable adorned regexp matching the operators that join
457 ;; symbols to fully qualified identifiers, or nil in languages that
458 ;; don't have such things.
460 ;; This was a docstring constant in 5.30. It still works but is now
461 ;; considered internal - change `c-identifier-ops' instead.
462 t
(let ((ops (c-filter-ops (c-lang-const c-identifier-ops
)
463 '(left-assoc right-assoc
)
466 (c-make-keywords-re 'appendable ops
))))
467 (c-lang-defvar c-opt-identifier-concat-key
468 (c-lang-const c-opt-identifier-concat-key
)
471 (c-lang-defconst c-opt-identifier-concat-key-depth
472 ;; Number of regexp grouping parens in `c-opt-identifier-concat-key'.
473 t
(regexp-opt-depth (c-lang-const c-opt-identifier-concat-key
)))
475 (c-lang-defconst c-opt-identifier-prefix-key
476 ;; Appendable adorned regexp matching operators that might precede
477 ;; an identifier and that are part of the identifier in that case.
478 ;; nil in languages without such things.
479 t
(let ((ops (c-filter-ops (c-lang-const c-identifier-ops
)
483 (c-make-keywords-re 'appendable ops
))))
485 (c-lang-defconst c-after-id-concat-ops
486 "Operators that can occur after a binary operator on `c-identifier-ops'
487 in identifiers. nil in languages that don't have such things.
489 Operators here should also have appropriate entries in `c-operators' -
490 it's not taken care of by default."
492 ;; '~' for destructors in C++, '*' for member pointers.
494 ;; In Java we recognize '*' to deal with "foo.bar.*" that can occur
495 ;; in import declarations. (This will also match bogus things like
496 ;; "foo.*bar" but we don't bother.)
499 (c-lang-defconst c-opt-after-id-concat-key
500 ;; Regexp that must match the token after
501 ;; `c-opt-identifier-concat-key' for it to be considered an
502 ;; identifier concatenation operator (which e.g. causes the
503 ;; preceding identifier to be fontified as a reference). Assumed to
504 ;; be a string if `c-opt-identifier-concat-key' is.
506 ;; This was a docstring constant in 5.30. It still works but is now
507 ;; considered internal - change `c-after-id-concat-ops' instead.
508 t
(concat (c-lang-const c-symbol-start
)
509 (if (c-lang-const c-after-id-concat-ops
)
510 (concat "\\|" (c-make-keywords-re 'appendable
511 (c-lang-const c-after-id-concat-ops
)))
514 (c-lang-defconst c-identifier-start
515 "Regexp that matches the start of an (optionally qualified) identifier.
516 It should also match all keywords. It's unspecified how far it
518 t
(concat (c-lang-const c-symbol-start
)
519 (if (c-lang-const c-opt-identifier-prefix-key
)
521 (c-lang-const c-opt-identifier-prefix-key
))
523 (c-lang-defvar c-identifier-start
(c-lang-const c-identifier-start
))
525 (c-lang-defconst c-identifier-key
526 "Regexp matching a fully qualified identifier, like \"A::B::c\" in
527 C++. It does not recognize the full range of syntactic whitespace
528 between the tokens; `c-forward-name' has to be used for that. It
529 should also not match identifiers containing parenthesis groupings,
530 e.g. identifiers with template arguments such as \"A<X,Y>\" in C++."
531 ;; This regexp is more complex than strictly necessary to ensure
532 ;; that it can be matched with a minimum of backtracking.
533 t
(concat (if (c-lang-const c-opt-identifier-prefix-key
)
536 (c-lang-const c-opt-identifier-prefix-key
)
537 (c-lang-const c-simple-ws
) "*"
540 "\\(" (c-lang-const c-symbol-key
) "\\)"
541 (if (c-lang-const c-opt-identifier-concat-key
)
544 (c-lang-const c-simple-ws
) "*"
545 (c-lang-const c-opt-identifier-concat-key
)
546 (c-lang-const c-simple-ws
) "*"
547 (if (c-lang-const c-after-id-concat-ops
)
550 (c-make-keywords-re 'appendable
551 (c-lang-const c-after-id-concat-ops
))
553 ;; For flexibility, consider the symbol match
554 ;; optional if we've hit a
555 ;; `c-after-id-concat-ops' operator. This is
556 ;; also necessary to handle the "*" that can
557 ;; end import declaration identifiers in Java.
559 (c-lang-const c-simple-ws
) "*"
560 "\\(" (c-lang-const c-symbol-key
) "\\)"
563 "\\(" (c-lang-const c-symbol-key
) "\\)"
565 (concat "\\(" (c-lang-const c-symbol-key
) "\\)"))
568 (c-lang-defvar c-identifier-key
(c-lang-const c-identifier-key
))
570 (c-lang-defconst c-identifier-last-sym-match
571 ;; This was a docstring constant in 5.30 but it's no longer used.
572 ;; It's only kept to avoid breaking third party code.
574 ;; Used to identify the submatch in `c-identifier-key' that
575 ;; surrounds the last symbol in the qualified identifier. It's a
576 ;; list of submatch numbers, of which the first that has a match is
577 ;; taken. It's assumed that at least one does when the regexp has
581 (c-lang-defconst c-string-escaped-newlines
582 "Set if the language support backslash escaped newlines inside string
586 (c-lang-defvar c-string-escaped-newlines
587 (c-lang-const c-string-escaped-newlines
))
589 (c-lang-defconst c-multiline-string-start-char
590 "Set if the language supports multiline string literals without escaped
591 newlines. If t, all string literals are multiline. If a character,
592 only literals where the open quote is immediately preceded by that
593 literal are multiline."
596 (c-lang-defvar c-multiline-string-start-char
597 (c-lang-const c-multiline-string-start-char
))
599 (c-lang-defconst c-opt-cpp-prefix
600 "Regexp matching the prefix of a cpp directive in the languages that
601 normally use that macro preprocessor. Tested at bol or at boi.
602 Assumed to not contain any submatches or \\| operators."
603 ;; TODO (ACM, 2005-04-01). Amend the following to recognise escaped NLs;
604 ;; amend all uses of c-opt-cpp-prefix which count regexp-depth.
607 (c-lang-defvar c-opt-cpp-prefix
(c-lang-const c-opt-cpp-prefix
))
609 (c-lang-defconst c-opt-cpp-start
610 "Regexp matching the prefix of a cpp directive including the directive
611 name, or nil in languages without preprocessor support. The first
612 submatch surrounds the directive name."
613 t
(if (c-lang-const c-opt-cpp-prefix
)
614 (concat (c-lang-const c-opt-cpp-prefix
)
615 "\\([" c-alnum
"]+\\)"))
616 ;; Pike, being a scripting language, recognizes hash-bangs too.
617 pike
(concat (c-lang-const c-opt-cpp-prefix
)
618 "\\([" c-alnum
"]+\\|!\\)"))
619 (c-lang-defvar c-opt-cpp-start
(c-lang-const c-opt-cpp-start
))
621 (c-lang-defconst c-cpp-message-directives
622 "List of cpp directives (without the prefix) that are followed by a
624 t
(if (c-lang-const c-opt-cpp-prefix
)
626 pike
'("error" "warning"))
628 (c-lang-defconst c-cpp-include-directives
629 "List of cpp directives (without the prefix) that are followed by a
630 file name in angle brackets or quotes."
631 t
(if (c-lang-const c-opt-cpp-prefix
)
633 objc
'("include" "import"))
635 (c-lang-defconst c-opt-cpp-macro-define
636 "Cpp directive (without the prefix) that is followed by a macro
637 definition, or nil if the language doesn't have any."
638 t
(if (c-lang-const c-opt-cpp-prefix
)
641 (c-lang-defconst c-opt-cpp-macro-define-start
642 ;; Regexp matching everything up to the macro body of a cpp define,
643 ;; or the end of the logical line if there is none. Set if
644 ;; c-opt-cpp-macro-define is.
645 t
(if (c-lang-const c-opt-cpp-macro-define
)
646 (concat (c-lang-const c-opt-cpp-prefix
)
647 (c-lang-const c-opt-cpp-macro-define
)
648 "[ \t]+\\(\\sw\\|_\\)+\\(\([^\)]*\)\\)?"
649 "\\([ \t]\\|\\\\\n\\)*")))
650 (c-lang-defvar c-opt-cpp-macro-define-start
651 (c-lang-const c-opt-cpp-macro-define-start
))
653 (c-lang-defconst c-cpp-expr-directives
654 "List if cpp directives (without the prefix) that are followed by an
656 t
(if (c-lang-const c-opt-cpp-prefix
)
659 (c-lang-defconst c-cpp-expr-functions
660 "List of functions in cpp expressions."
661 t
(if (c-lang-const c-opt-cpp-prefix
)
663 pike
'("defined" "efun" "constant"))
665 (c-lang-defconst c-assignment-operators
666 "List of all assignment operators."
667 t
'("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=")
668 java
(append (c-lang-const c-assignment-operators
)
670 c
++ (append (c-lang-const c-assignment-operators
)
671 '("and_eq" "or_eq" "xor_eq" "??!=" "??'="))
674 (c-lang-defconst c-operators
675 "List describing all operators, along with their precedence and
676 associativity. The order in the list corresponds to the precedence of
677 the operators: The operators in each element is a group with the same
678 precedence, and the group has higher precedence than the groups in all
679 following elements. The car of each element describes the type of of
680 the operator group, and the cdr is a list of the operator tokens in
681 it. The operator group types are:
683 'prefix Unary prefix operators.
684 'postfix Unary postfix operators.
686 Unary postfix operators if and only if the chars have
688 'left-assoc Binary left associative operators (i.e. a+b+c means (a+b)+c).
689 'right-assoc Binary right associative operators (i.e. a=b=c means a=(b=c)).
690 'right-assoc-sequence
691 Right associative operator that constitutes of a
692 sequence of tokens that separate expressions. All the
693 tokens in the group are in this case taken as
694 describing the sequence in one such operator, and the
695 order between them is therefore significant.
697 Operators containing a character with paren syntax are taken to match
698 with a corresponding open/close paren somewhere else. A postfix
699 operator with close paren syntax is taken to end a postfix expression
700 started somewhere earlier, rather than start a new one at point. Vice
701 versa for prefix operators with open paren syntax.
703 Note that operators like \".\" and \"->\" which in language references
704 often are described as postfix operators are considered binary here,
705 since CC Mode treats every identifier as an expression."
707 ;; There's currently no code in CC Mode that exploit all the info
708 ;; in this variable; precedence, associativity etc are present as a
709 ;; preparation for future work.
712 ,@(when (c-lang-const c-opt-cpp-prefix
)
714 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
717 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
718 '("%:%:" "??=??=")))))
721 ,@(c-lang-const c-identifier-ops
)
722 ,@(cond ((c-major-mode-is 'c
++-mode
)
723 `((postfix-if-paren "<" ">"))) ; Templates.
724 ((c-major-mode-is 'pike-mode
)
725 `((prefix "global" "predef")))
726 ((c-major-mode-is 'java-mode
)
727 `((prefix "super"))))
730 ,@(when (c-major-mode-is 'c
++-mode
)
731 ;; The following need special treatment.
732 `((prefix "dynamic_cast" "static_cast"
733 "reinterpret_cast" "const_cast" "typeid")))
735 ,@(unless (c-major-mode-is 'java-mode
)
737 (postfix "++" "--" "[" "]" "(" ")"
738 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
739 '("<:" ":>" "??(" "??)")))
742 (prefix "++" "--" "+" "-" "!" "~"
743 ,@(when (c-major-mode-is 'c
++-mode
) '("not" "compl"))
744 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
745 '("*" "&" "sizeof" "??-"))
746 ,@(when (c-major-mode-is 'objc-mode
)
747 '("@selector" "@protocol" "@encode"))
748 ;; The following need special treatment.
749 ,@(cond ((c-major-mode-is 'c
++-mode
)
751 ((c-major-mode-is 'java-mode
)
753 ((c-major-mode-is 'pike-mode
)
754 '("class" "lambda" "catch" "throw" "gauge")))
756 ,@(when (c-major-mode-is 'pike-mode
)
757 '("[" "]"))) ; Type cast.
760 ,@(when (c-major-mode-is 'c
++-mode
)
761 `((left-assoc ".*" "->*")))
764 (left-assoc "*" "/" "%")
770 (left-assoc "<<" ">>"
771 ,@(when (c-major-mode-is 'java-mode
)
775 (left-assoc "<" ">" "<=" ">="
776 ,@(when (c-major-mode-is 'java-mode
)
780 (left-assoc "==" "!="
781 ,@(when (c-major-mode-is 'c
++-mode
) '("not_eq")))
785 ,@(when (c-major-mode-is 'c
++-mode
) '("bitand")))
787 ;; Bitwise exclusive or.
789 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
791 ,@(when (c-major-mode-is 'c
++-mode
) '("xor")))
795 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
797 ,@(when (c-major-mode-is 'c
++-mode
) '("bitor")))
801 ,@(when (c-major-mode-is 'c
++-mode
) '("and")))
805 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
807 ,@(when (c-major-mode-is 'c
++-mode
) '("or")))
810 (right-assoc-sequence "?" ":")
813 (right-assoc ,@(c-lang-const c-assignment-operators
))
816 ,@(when (c-major-mode-is 'c
++-mode
)
822 ;; IDL got its own definition since it has a much smaller operator
823 ;; set than the other languages.
824 idl
`(;; Preprocessor.
828 ,@(c-lang-const c-identifier-ops
)
832 (left-assoc "*" "/" "%")
836 (left-assoc "<<" ">>")
844 (c-lang-defconst c-operator-list
845 ;; The operators as a flat list (without duplicates).
846 t
(c-filter-ops (c-lang-const c-operators
) t t
))
848 (c-lang-defconst c-overloadable-operators
849 "List of the operators that are overloadable, in their \"identifier
850 form\". See also `c-op-identitier-prefix'."
852 c
++ '("new" "delete" ;; Can be followed by "[]" but we ignore that.
854 "^" "??'" "xor" "&" "bitand" "|" "??!" "bitor" "~" "??-" "compl"
855 "!" "=" "<" ">" "+=" "-=" "*=" "/=" "%=" "^="
856 "??'=" "xor_eq" "&=" "and_eq" "|=" "??!=" "or_eq"
857 "<<" ">>" ">>=" "<<=" "==" "!=" "not_eq" "<=" ">="
858 "&&" "and" "||" "??!??!" "or" "++" "--" "," "->*" "->"
859 "()" "[]" "<::>" "??(??)")
860 ;; These work like identifiers in Pike.
861 pike
'("`+" "`-" "`&" "`|" "`^" "`<<" "`>>" "`*" "`/" "`%" "`~"
862 "`==" "`<" "`>" "`!" "`[]" "`[]=" "`->" "`->=" "`()" "``+"
863 "``-" "``&" "``|" "``^" "``<<" "``>>" "``*" "``/" "``%"
866 (c-lang-defconst c-overloadable-operators-regexp
867 ;; Regexp tested after an "operator" token in C++.
869 c
++ (c-make-keywords-re nil
(c-lang-const c-overloadable-operators
)))
870 (c-lang-defvar c-overloadable-operators-regexp
871 (c-lang-const c-overloadable-operators-regexp
))
873 (c-lang-defconst c-opt-op-identitier-prefix
874 "Regexp matching the token before the ones in
875 `c-overloadable-operators' when operators are specified in their
876 \"identifier form\". This typically matches \"operator\" in C++ where
877 operator functions are specified as e.g. \"operator +\". It's nil in
878 languages without operator functions or where the complete operator
879 identifier is listed in `c-overloadable-operators'.
881 This regexp is assumed to not match any non-operator identifier."
883 c
++ (c-make-keywords-re t
'("operator")))
884 (c-lang-defvar c-opt-op-identitier-prefix
885 (c-lang-const c-opt-op-identitier-prefix
))
887 (c-lang-defconst c-other-op-syntax-tokens
888 "List of the tokens made up of characters in the punctuation or
889 parenthesis syntax classes that have uses other than as expression
891 t
'("{" "}" "(" ")" "[" "]" ";" ":" "," "=" "/*" "*/" "//")
892 (c c
++ pike
) (append '("#" "##" ; Used by cpp.
894 (c-lang-const c-other-op-syntax-tokens
))
895 (c c
++) (append '("*") (c-lang-const c-other-op-syntax-tokens
))
896 c
++ (append '("&" "<%" "%>" "<:" ":>" "%:" "%:%:")
897 (c-lang-const c-other-op-syntax-tokens
))
898 objc
(append '("#" "##" ; Used by cpp.
899 "+" "-") (c-lang-const c-other-op-syntax-tokens
))
900 idl
(append '("#" "##") ; Used by cpp.
901 (c-lang-const c-other-op-syntax-tokens
))
903 (c-lang-const c-other-op-syntax-tokens
)
904 (c-lang-const c-overloadable-operators
))
905 awk
'("{" "}" "(" ")" "[" "]" ";" "," "=" "/"))
907 (c-lang-defconst c-all-op-syntax-tokens
908 ;; List of all tokens in the punctuation and parenthesis syntax
910 t
(delete-duplicates (append (c-lang-const c-other-op-syntax-tokens
)
911 (c-lang-const c-operator-list
))
912 :test
'string-equal
))
914 (c-lang-defconst c-nonsymbol-token-char-list
915 ;; List containing all chars not in the word, symbol or
916 ;; syntactically irrelevant syntax classes, i.e. all punctuation,
917 ;; parenthesis and string delimiter chars.
918 t
(c-with-syntax-table (c-lang-const c-mode-syntax-table
)
919 ;; Only go through the chars in the printable ASCII range. No
920 ;; language so far has 8-bit or widestring operators.
921 (let (list (char 32))
923 (or (memq (char-syntax char
) '(?w ?_ ?
< ?
> ?\
))
924 (setq list
(cons (c-int-to-char char
) list
)))
925 (setq char
(1+ char
)))
928 (c-lang-defconst c-nonsymbol-token-regexp
929 ;; Regexp matching all tokens in the punctuation and parenthesis
930 ;; syntax classes. Note that this also matches ".", which can start
932 t
(c-make-keywords-re nil
933 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
935 "\\`\\(\\s.\\|\\s\(\\|\\s\)\\)+\\'")))
936 (c-lang-defvar c-nonsymbol-token-regexp
937 (c-lang-const c-nonsymbol-token-regexp
))
939 (c-lang-defconst c-assignment-op-regexp
940 ;; Regexp matching all assignment operators and only them. The
941 ;; beginning of the first submatch is used to detect the end of the
942 ;; token, along with the end of the whole match.
943 t
(if (c-lang-const c-assignment-operators
)
945 ;; Need special case for "=" since it's a prefix of "==".
948 (c-make-keywords-re nil
949 (set-difference (c-lang-const c-assignment-operators
)
951 :test
'string-equal
)))
953 (c-lang-defvar c-assignment-op-regexp
954 (c-lang-const c-assignment-op-regexp
))
956 (c-lang-defconst c-
<>-multichar-token-regexp
957 ;; Regexp matching all tokens containing "<" or ">" which are longer
959 t
(c-make-keywords-re nil
960 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
963 (c-lang-defvar c-
<>-multichar-token-regexp
964 (c-lang-const c-
<>-multichar-token-regexp
))
966 (c-lang-defconst c-
<-op-cont-regexp
967 ;; Regexp matching the second and subsequent characters of all
968 ;; multicharacter tokens that begin with "<".
969 t
(c-make-keywords-re nil
970 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
973 (lambda (op) (substring op
1)))))
974 (c-lang-defvar c-
<-op-cont-regexp
(c-lang-const c-
<-op-cont-regexp
))
976 (c-lang-defconst c-
>-op-cont-regexp
977 ;; Regexp matching the second and subsequent characters of all
978 ;; multicharacter tokens that begin with ">".
979 t
(c-make-keywords-re nil
980 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
983 (lambda (op) (substring op
1)))))
984 (c-lang-defvar c-
>-op-cont-regexp
(c-lang-const c-
>-op-cont-regexp
))
986 (c-lang-defconst c-stmt-delim-chars
987 ;; The characters that should be considered to bound statements. To
988 ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to
989 ;; begin with "^" to negate the set. If ? : operators should be
990 ;; detected then the string must end with "?:".
992 awk
"^;{}#\n\r?:") ; The newline chars gets special treatment.
993 (c-lang-defvar c-stmt-delim-chars
(c-lang-const c-stmt-delim-chars
))
995 (c-lang-defconst c-stmt-delim-chars-with-comma
996 ;; Variant of `c-stmt-delim-chars' that additionally contains ','.
998 awk
"^;,{}\n\r?:") ; The newline chars gets special treatment.
999 (c-lang-defvar c-stmt-delim-chars-with-comma
1000 (c-lang-const c-stmt-delim-chars-with-comma
))
1003 ;;; Syntactic whitespace.
1005 (c-lang-defconst c-simple-ws
1006 "Regexp matching an ordinary whitespace character.
1007 Does not contain a \\| operator at the top level."
1008 ;; "\\s " is not enough since it doesn't match line breaks.
1009 t
"\\(\\s \\|[\n\r]\\)")
1011 (c-lang-defconst c-simple-ws-depth
1012 ;; Number of regexp grouping parens in `c-simple-ws'.
1013 t
(regexp-opt-depth (c-lang-const c-simple-ws
)))
1015 (c-lang-defconst c-line-comment-starter
1016 "String that starts line comments, or nil if such don't exist.
1017 Line comments are always terminated by newlines. At least one of
1018 `c-block-comment-starter' and this one is assumed to be set.
1020 Note that it's currently not enough to set this to support a new
1021 comment style. Other stuff like the syntax table must also be set up
1025 (c-lang-defvar c-line-comment-starter
(c-lang-const c-line-comment-starter
))
1027 (c-lang-defconst c-block-comment-starter
1028 "String that starts block comments, or nil if such don't exist.
1029 Block comments are ended by `c-block-comment-ender', which is assumed
1030 to be set if this is. At least one of `c-line-comment-starter' and
1031 this one is assumed to be set.
1033 Note that it's currently not enough to set this to support a new
1034 comment style. Other stuff like the syntax table must also be set up
1039 (c-lang-defconst c-block-comment-ender
1040 "String that ends block comments, or nil if such don't exist.
1042 Note that it's currently not enough to set this to support a new
1043 comment style. Other stuff like the syntax table must also be set up
1048 (c-lang-defconst c-comment-start-regexp
1049 ;; Regexp to match the start of any type of comment.
1050 t
(let ((re (c-make-keywords-re nil
1051 (list (c-lang-const c-line-comment-starter
)
1052 (c-lang-const c-block-comment-starter
)))))
1053 (if (memq 'gen-comment-delim c-emacs-features
)
1054 (concat re
"\\|\\s!")
1056 (c-lang-defvar c-comment-start-regexp
(c-lang-const c-comment-start-regexp
))
1058 ;;;; Added by ACM, 2003/9/18.
1059 (c-lang-defconst c-block-comment-start-regexp
1060 ;; Regexp which matches the start of a block comment (if such exists in the
1062 t
(if (c-lang-const c-block-comment-starter
)
1063 (regexp-quote (c-lang-const c-block-comment-starter
))
1065 (c-lang-defvar c-block-comment-start-regexp
1066 (c-lang-const c-block-comment-start-regexp
))
1068 (c-lang-defconst c-literal-start-regexp
1069 ;; Regexp to match the start of comments and string literals.
1070 t
(concat (c-lang-const c-comment-start-regexp
)
1072 (if (memq 'gen-string-delim c-emacs-features
)
1075 (c-lang-defvar c-literal-start-regexp
(c-lang-const c-literal-start-regexp
))
1077 (c-lang-defconst c-doc-comment-start-regexp
1078 "Regexp to match the start of documentation comments."
1080 ;; From font-lock.el: `doxygen' uses /*! while others use /**.
1081 (c c
++ objc
) "/\\*[*!]"
1084 (c-lang-defvar c-doc-comment-start-regexp
1085 (c-lang-const c-doc-comment-start-regexp
))
1087 (c-lang-defconst comment-start
1088 "String that starts comments inserted with M-; etc.
1089 `comment-start' is initialized from this."
1090 ;; Default: Prefer line comments to block comments, and pad with a space.
1091 t
(concat (or (c-lang-const c-line-comment-starter
)
1092 (c-lang-const c-block-comment-starter
))
1094 ;; In C we still default to the block comment style since line
1095 ;; comments aren't entirely portable.
1097 (c-lang-defvar comment-start
(c-lang-const comment-start
)
1100 (c-lang-defconst comment-end
1101 "String that ends comments inserted with M-; etc.
1102 `comment-end' is initialized from this."
1103 ;; Default: Use block comment style if comment-start uses block
1104 ;; comments, and pad with a space in that case.
1105 t
(if (string-match (concat "\\`\\("
1106 (c-lang-const c-block-comment-start-regexp
)
1108 (c-lang-const comment-start
))
1109 (concat " " (c-lang-const c-block-comment-ender
))
1111 (c-lang-defvar comment-end
(c-lang-const comment-end
)
1114 (c-lang-defconst comment-start-skip
1115 "Regexp to match the start of a comment plus everything up to its body.
1116 `comment-start-skip' is initialized from this."
1117 ;; Default: Allow the last char of the comment starter(s) to be
1118 ;; repeated, then allow any amount of horizontal whitespace.
1121 (mapcar (lambda (cs)
1123 (concat (regexp-quote cs
) "+")))
1124 (list (c-lang-const c-line-comment-starter
)
1125 (c-lang-const c-block-comment-starter
)))
1128 (c-lang-defvar comment-start-skip
(c-lang-const comment-start-skip
)
1131 (c-lang-defconst c-syntactic-ws-start
1132 ;; Regexp matching any sequence that can start syntactic whitespace.
1133 ;; The only uncertain case is '#' when there are cpp directives.
1135 (c-make-keywords-re nil
1136 (append (list (c-lang-const c-line-comment-starter
)
1137 (c-lang-const c-block-comment-starter
)
1138 (when (c-lang-const c-opt-cpp-prefix
)
1142 (when (memq 'gen-comment-delim c-emacs-features
)
1144 (c-lang-defvar c-syntactic-ws-start
(c-lang-const c-syntactic-ws-start
))
1146 (c-lang-defconst c-syntactic-ws-end
1147 ;; Regexp matching any single character that might end syntactic whitespace.
1149 (c-make-keywords-re nil
1150 (append (when (c-lang-const c-block-comment-ender
)
1153 (elt (c-lang-const c-block-comment-ender
)
1155 (c-lang-const c-block-comment-ender
)))))))
1157 (when (memq 'gen-comment-delim c-emacs-features
)
1159 (c-lang-defvar c-syntactic-ws-end
(c-lang-const c-syntactic-ws-end
))
1161 (c-lang-defconst c-unterminated-block-comment-regexp
1162 ;; Regexp matching an unterminated block comment that doesn't
1163 ;; contain line breaks, or nil in languages without block comments.
1164 ;; Does not contain a \| operator at the top level.
1165 t
(when (c-lang-const c-block-comment-starter
)
1167 (regexp-quote (c-lang-const c-block-comment-starter
))
1168 ;; It's messy to cook together a regexp that matches anything
1169 ;; but c-block-comment-ender.
1170 (let ((end (c-lang-const c-block-comment-ender
)))
1171 (cond ((= (length end
) 1)
1172 (concat "[^" end
"\n\r]*"))
1174 (concat "[^" (substring end
0 1) "\n\r]*"
1176 (regexp-quote (substring end
0 1)) "+"
1178 ;; The quoting rules inside char classes are silly. :P
1179 (cond ((= (elt end
0) (elt end
1))
1180 (concat (substring end
0 1) "\n\r"))
1181 ((= (elt end
1) ?\
])
1182 (concat (substring end
1 2) "\n\r"
1183 (substring end
0 1)))
1185 (concat (substring end
0 1) "\n\r"
1186 (substring end
1 2))))
1188 "[^" (substring end
0 1) "\n\r]*"
1191 (error "Can't handle a block comment ender of length %s"
1194 (c-lang-defconst c-block-comment-regexp
1195 ;; Regexp matching a block comment that doesn't contain line breaks,
1196 ;; or nil in languages without block comments. The reason we don't
1197 ;; allow line breaks is to avoid going very far and risk running out
1198 ;; of regexp stack; this regexp is intended to handle only short
1199 ;; comments that might be put in the middle of limited constructs
1200 ;; like declarations. Does not contain a \| operator at the top
1202 t
(when (c-lang-const c-unterminated-block-comment-regexp
)
1204 (c-lang-const c-unterminated-block-comment-regexp
)
1205 (let ((end (c-lang-const c-block-comment-ender
)))
1206 (cond ((= (length end
) 1)
1209 (concat (regexp-quote (substring end
0 1)) "+"
1210 (regexp-quote (substring end
1 2))))
1212 (error "Can't handle a block comment ender of length %s"
1215 (c-lang-defconst c-nonwhite-syntactic-ws
1216 ;; Regexp matching a piece of syntactic whitespace that isn't a
1217 ;; sequence of simple whitespace characters. As opposed to
1218 ;; `c-(forward|backward)-syntactic-ws', this doesn't regard cpp
1219 ;; directives as syntactic whitespace.
1220 t
(c-concat-separated
1221 (list (when (c-lang-const c-line-comment-starter
)
1222 (concat (regexp-quote (c-lang-const c-line-comment-starter
))
1224 (c-lang-const c-block-comment-regexp
)
1226 (when (memq 'gen-comment-delim c-emacs-features
)
1230 (c-lang-defconst c-syntactic-ws
1231 ;; Regexp matching syntactic whitespace, including possibly the
1232 ;; empty string. As opposed to `c-(forward|backward)-syntactic-ws',
1233 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1234 ;; not contain a \| operator at the top level.
1235 t
(concat (c-lang-const c-simple-ws
) "*"
1237 (concat "\\(" (c-lang-const c-nonwhite-syntactic-ws
) "\\)"
1238 (c-lang-const c-simple-ws
) "*")
1241 (c-lang-defconst c-syntactic-ws-depth
1242 ;; Number of regexp grouping parens in `c-syntactic-ws'.
1243 t
(regexp-opt-depth (c-lang-const c-syntactic-ws
)))
1245 (c-lang-defconst c-nonempty-syntactic-ws
1246 ;; Regexp matching syntactic whitespace, which is at least one
1247 ;; character long. As opposed to `c-(forward|backward)-syntactic-ws',
1248 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1249 ;; not contain a \| operator at the top level.
1251 (c-lang-const c-simple-ws
)
1253 (c-lang-const c-nonwhite-syntactic-ws
)
1256 (c-lang-defconst c-nonempty-syntactic-ws-depth
1257 ;; Number of regexp grouping parens in `c-nonempty-syntactic-ws'.
1258 t
(regexp-opt-depth (c-lang-const c-nonempty-syntactic-ws
)))
1260 (c-lang-defconst c-single-line-syntactic-ws
1261 ;; Regexp matching syntactic whitespace without any line breaks. As
1262 ;; opposed to `c-(forward|backward)-syntactic-ws', this doesn't
1263 ;; regard cpp directives as syntactic whitespace. Does not contain
1264 ;; a \| operator at the top level.
1265 t
(if (c-lang-const c-block-comment-regexp
)
1267 (c-lang-const c-block-comment-regexp
)
1271 (c-lang-defconst c-single-line-syntactic-ws-depth
1272 ;; Number of regexp grouping parens in `c-single-line-syntactic-ws'.
1273 t
(regexp-opt-depth (c-lang-const c-single-line-syntactic-ws
)))
1275 (c-lang-defconst c-syntactic-eol
1276 ;; Regexp that matches when there is no syntactically significant
1277 ;; text before eol. Macros are regarded as syntactically
1278 ;; significant text here.
1279 t
(concat (c-lang-const c-single-line-syntactic-ws
)
1280 ;; Match eol (possibly inside a block comment or preceded
1281 ;; by a line continuation backslash), or the beginning of a
1282 ;; line comment. Note: This has to be modified for awk
1283 ;; where line comments start with '#'.
1286 (list (when (c-lang-const c-line-comment-starter
)
1287 (regexp-quote (c-lang-const c-line-comment-starter
)))
1288 (when (c-lang-const c-unterminated-block-comment-regexp
)
1289 (concat (c-lang-const c-unterminated-block-comment-regexp
)
1295 (c-lang-defvar c-syntactic-eol
(c-lang-const c-syntactic-eol
))
1298 ;;; Syntactic analysis ("virtual semicolons") for line-oriented languages (AWK).
1299 (c-lang-defconst c-at-vsemi-p-fn
1300 "Contains a function \"Is there a virtual semicolon at POS or point?\".
1301 Such a function takes one optional parameter, a buffer position (defaults to
1302 point), and returns NIL or t. This variable contains NIL for languages which
1303 don't have EOL terminated statements. "
1305 awk
'c-awk-at-vsemi-p
)
1306 (c-lang-defvar c-at-vsemi-p-fn
(c-lang-const c-at-vsemi-p-fn
))
1308 (c-lang-defconst c-vsemi-status-unknown-p-fn
1309 "Contains a function \"are we unsure whether there is a virtual semicolon on this line?\".
1310 The (admittedly kludgey) purpose of such a function is to prevent an infinite
1311 recursion in c-beginning-of-statement-1 when point starts at a `while' token.
1312 The function MUST NOT UNDER ANY CIRCUMSTANCES call c-beginning-of-statement-1,
1313 even indirectly. This variable contains NIL for languages which don't have
1314 EOL terminated statements."
1316 awk
'c-awk-vsemi-status-unknown-p
)
1317 (c-lang-defvar c-vsemi-status-unknown-p-fn
1318 (c-lang-const c-vsemi-status-unknown-p-fn
))
1321 ;;; In-comment text handling.
1323 (c-lang-defconst c-paragraph-start
1324 "Regexp to append to `paragraph-start'."
1326 java
"\\(@[a-zA-Z]+\\>\\|$\\)" ; For Javadoc.
1327 pike
"\\(@[a-zA-Z_-]+\\>\\([^{]\\|$\\)\\|$\\)") ; For Pike refdoc.
1328 (c-lang-defvar c-paragraph-start
(c-lang-const c-paragraph-start
))
1330 (c-lang-defconst c-paragraph-separate
1331 "Regexp to append to `paragraph-separate'."
1333 pike
(c-lang-const c-paragraph-start
))
1334 (c-lang-defvar c-paragraph-separate
(c-lang-const c-paragraph-separate
))
1339 ;; Note: All and only all language constants containing keyword lists
1340 ;; should end with "-kwds"; they're automatically collected into the
1341 ;; `c-kwds-lang-consts' list below and used to build `c-keywords' etc.
1343 (c-lang-defconst c-primitive-type-kwds
1344 "Primitive type keywords. As opposed to the other keyword lists, the
1345 keywords listed here are fontified with the type face instead of the
1348 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1349 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1350 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1353 Do not try to modify this list for end user customizations; the
1354 `*-font-lock-extra-types' variable, where `*' is the mode prefix, is
1355 the appropriate place for that."
1356 t
'("char" "double" "float" "int" "long" "short" "signed"
1359 '("_Bool" "_Complex" "_Imaginary") ; Conditionally defined in C99.
1360 (c-lang-const c-primitive-type-kwds
))
1363 (c-lang-const c-primitive-type-kwds
))
1364 ;; Objective-C extends C, but probably not the new stuff in C99.
1366 '("id" "Class" "SEL" "IMP" "BOOL")
1367 (c-lang-const c-primitive-type-kwds
))
1368 java
'("boolean" "byte" "char" "double" "float" "int" "long" "short" "void")
1369 idl
'("Object" "ValueBase" "any" "boolean" "char" "double" "fixed" "float"
1370 "long" "octet" "sequence" "short" "string" "void" "wchar" "wstring"
1373 ;; The following can't really end a type, but we have to specify them
1374 ;; here due to the assumption in `c-primitive-type-prefix-kwds'. It
1375 ;; doesn't matter that much.
1376 "unsigned" "strong")
1377 pike
'(;; this_program isn't really a keyword, but it's practically
1378 ;; used as a builtin type.
1379 "array" "float" "function" "int" "mapping" "mixed" "multiset"
1380 "object" "program" "string" "this_program" "void"))
1382 (c-lang-defconst c-primitive-type-key
1383 ;; An adorned regexp that matches `c-primitive-type-kwds'.
1384 t
(c-make-keywords-re t
(c-lang-const c-primitive-type-kwds
)))
1385 (c-lang-defvar c-primitive-type-key
(c-lang-const c-primitive-type-key
))
1387 (c-lang-defconst c-primitive-type-prefix-kwds
1388 "Keywords that might act as prefixes for primitive types. Assumed to
1389 be a subset of `c-primitive-type-kwds'."
1391 (c c
++) '("long" "short" "signed" "unsigned")
1392 idl
'("long" "unsigned"
1396 (c-lang-defconst c-type-prefix-kwds
1397 "Keywords where the following name - if any - is a type name, and
1398 where the keyword together with the symbol works as a type in
1401 Note that an alternative if the second part doesn't hold is
1402 `c-type-list-kwds'. Keywords on this list are typically also present
1403 on one of the `*-decl-kwds' lists."
1405 c
'("struct" "union" "enum")
1406 c
++ (append '("class" "typename")
1407 (c-lang-const c-type-prefix-kwds c
)))
1409 (c-lang-defconst c-type-prefix-key
1410 ;; Adorned regexp matching `c-type-prefix-kwds'.
1411 t
(c-make-keywords-re t
(c-lang-const c-type-prefix-kwds
)))
1412 (c-lang-defvar c-type-prefix-key
(c-lang-const c-type-prefix-key
))
1414 (c-lang-defconst c-type-modifier-kwds
1415 "Type modifier keywords. These can occur almost anywhere in types
1416 but they don't build a type of themselves. Unlike the keywords on
1417 `c-primitive-type-kwds', they are fontified with the keyword face and
1420 c
'("const" "restrict" "volatile")
1421 c
++ '("const" "volatile" "throw")
1422 objc
'("const" "volatile"))
1424 (c-lang-defconst c-opt-type-modifier-key
1425 ;; Adorned regexp matching `c-type-modifier-kwds', or nil in
1426 ;; languages without such keywords.
1427 t
(and (c-lang-const c-type-modifier-kwds
)
1428 (c-make-keywords-re t
(c-lang-const c-type-modifier-kwds
))))
1429 (c-lang-defvar c-opt-type-modifier-key
(c-lang-const c-opt-type-modifier-key
))
1431 (c-lang-defconst c-opt-type-component-key
1432 ;; An adorned regexp that matches `c-primitive-type-prefix-kwds' and
1433 ;; `c-type-modifier-kwds', or nil in languages without any of them.
1434 t
(and (or (c-lang-const c-primitive-type-prefix-kwds
)
1435 (c-lang-const c-type-modifier-kwds
))
1436 (c-make-keywords-re t
1437 (append (c-lang-const c-primitive-type-prefix-kwds
)
1438 (c-lang-const c-type-modifier-kwds
)))))
1439 (c-lang-defvar c-opt-type-component-key
1440 (c-lang-const c-opt-type-component-key
))
1442 (c-lang-defconst c-type-start-kwds
1443 ;; All keywords that can start a type (i.e. are either a type prefix
1444 ;; or a complete type).
1445 t
(delete-duplicates (append (c-lang-const c-primitive-type-kwds
)
1446 (c-lang-const c-type-prefix-kwds
)
1447 (c-lang-const c-type-modifier-kwds
))
1448 :test
'string-equal
))
1450 (c-lang-defconst c-class-decl-kwds
1451 "Keywords introducing declarations where the following block (if any)
1452 contains another declaration level that should be considered a class.
1454 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1455 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1456 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1459 Note that presence on this list does not automatically treat the
1460 following identifier as a type; the keyword must also be present on
1461 `c-type-prefix-kwds' or `c-type-list-kwds' to accomplish that."
1463 c
'("struct" "union")
1464 c
++ '("class" "struct" "union")
1465 objc
'("struct" "union"
1466 "@interface" "@implementation" "@protocol")
1467 java
'("class" "interface")
1468 idl
'("component" "eventtype" "exception" "home" "interface" "struct"
1471 "storagehome" "storagetype"
1473 "catalog" "executor" "manages" "segment")
1476 (c-lang-defconst c-class-key
1477 ;; Regexp matching the start of a class.
1478 t
(c-make-keywords-re t
(c-lang-const c-class-decl-kwds
)))
1479 (c-lang-defvar c-class-key
(c-lang-const c-class-key
))
1481 (c-lang-defconst c-brace-list-decl-kwds
1482 "Keywords introducing declarations where the following block (if
1483 any) is a brace list.
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
1492 (c-lang-defconst c-brace-list-key
1493 ;; Regexp matching the start of declarations where the following
1494 ;; block is a brace list.
1495 t
(c-make-keywords-re t
(c-lang-const c-brace-list-decl-kwds
)))
1496 (c-lang-defvar c-brace-list-key
(c-lang-const c-brace-list-key
))
1498 (c-lang-defconst c-other-block-decl-kwds
1499 "Keywords where the following block (if any) contains another
1500 declaration level that should not be considered a class. For every
1501 keyword here, CC Mode will add a set of special syntactic symbols for
1502 those blocks. E.g. if the keyword is \"foo\" then there will be
1503 `foo-open', `foo-close', and `infoo' symbols.
1505 The intention is that this category should be used for block
1506 constructs that aren't related to object orientation concepts like
1507 classes (which thus also include e.g. interfaces, templates,
1508 contracts, structs, etc). The more pragmatic distinction is that
1509 while most want some indentation inside classes, it's fairly common
1510 that they don't want it in some of these constructs, so it should be
1511 simple to configure that differently from classes. See also
1512 `c-class-decl-kwds'.
1514 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1515 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1516 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1519 (c objc
) '("extern")
1520 c
++ '("namespace" "extern")
1525 (c-lang-defconst c-other-decl-block-key
1526 ;; Regexp matching the start of blocks besides classes that contain
1527 ;; another declaration level.
1528 t
(c-make-keywords-re t
(c-lang-const c-other-block-decl-kwds
)))
1529 (c-lang-defvar c-other-decl-block-key
(c-lang-const c-other-decl-block-key
))
1531 (c-lang-defconst c-typedef-decl-kwds
1532 "Keywords introducing declarations where the identifier(s) being
1535 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1536 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1537 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1539 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1540 ;; (since e.g. "Foo" is a type that's being defined in "class Foo
1542 t
(append (c-lang-const c-class-decl-kwds
)
1543 (c-lang-const c-brace-list-decl-kwds
))
1544 ;; Languages that have a "typedef" construct.
1545 (c c
++ objc idl pike
) (append (c-lang-const c-typedef-decl-kwds
)
1547 ;; Unlike most other languages, exception names are not handled as
1548 ;; types in IDL since they only can occur in "raises" specs.
1549 idl
(delete "exception" (append (c-lang-const c-typedef-decl-kwds
) nil
)))
1551 (c-lang-defconst c-typeless-decl-kwds
1552 "Keywords introducing declarations where the \(first) identifier
1553 \(declarator) follows directly after the keyword, without any type.
1555 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1556 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1557 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1559 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1560 ;; (since e.g. "Foo" is the identifier being defined in "class Foo
1562 t
(append (c-lang-const c-class-decl-kwds
)
1563 (c-lang-const c-brace-list-decl-kwds
))
1564 ;; Note: "manages" for CORBA CIDL clashes with its presence on
1565 ;; `c-type-list-kwds' for IDL.
1566 idl
(append (c-lang-const c-typeless-decl-kwds
)
1567 '("factory" "finder" "native"
1572 pike
(append (c-lang-const c-class-decl-kwds
)
1575 (c-lang-defconst c-modifier-kwds
1576 "Keywords that can prefix normal declarations of identifiers
1577 \(and typically act as flags). Things like argument declarations
1578 inside function headers are also considered declarations in this
1581 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1582 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1583 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1586 (c c
++) '("auto" "extern" "inline" "register" "static")
1587 c
++ (append '("explicit" "friend" "mutable" "template" "using" "virtual")
1588 (c-lang-const c-modifier-kwds
))
1589 objc
'("auto" "bycopy" "byref" "extern" "in" "inout" "oneway" "out" "static")
1590 ;; FIXME: Some of those below ought to be on `c-other-decl-kwds' instead.
1591 idl
'("abstract" "attribute" "const" "consumes" "custom" "emits" "import"
1592 "in" "inout" "local" "multiple" "oneway" "out" "private" "provides"
1593 "public" "publishes" "readonly" "typeid" "typeprefix" "uses"
1597 "bindsTo" "delegatesTo" "implements" "proxy" "storedOn")
1598 ;; Note: "const" is not used in Java, but it's still a reserved keyword.
1599 java
'("abstract" "const" "final" "native" "private" "protected" "public"
1600 "static" "strictfp" "synchronized" "transient" "volatile")
1601 pike
'("final" "inline" "local" "nomask" "optional" "private" "protected"
1602 "public" "static" "variant"))
1604 (c-lang-defconst c-other-decl-kwds
1605 "Keywords that can start or prefix any declaration level construct,
1606 besides those on `c-class-decl-kwds', `c-brace-list-decl-kwds',
1607 `c-other-block-decl-kwds', `c-typedef-decl-kwds',
1608 `c-typeless-decl-kwds' and `c-modifier-kwds'.
1610 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1611 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1612 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1615 objc
'("@class" "@end" "@defs")
1616 java
'("import" "package")
1617 pike
'("import" "inherit"))
1619 (c-lang-defconst c-decl-start-kwds
1620 "Keywords that always start declarations, wherever they occur.
1621 This can be used for declarations that aren't recognized by the normal
1622 combination of `c-decl-prefix-re' and `c-decl-start-re'."
1624 ;; Classes can be declared anywhere in a Pike expression.
1627 (c-lang-defconst c-decl-hangon-kwds
1628 "Keywords that can occur anywhere in a declaration level construct.
1629 This is used for self-contained things that can be tacked on anywhere
1630 on a declaration and that should be ignored to be able to recognize it
1631 correctly. Typical cases are compiler extensions like
1632 \"__attribute__\" or \"__declspec\":
1634 __declspec(noreturn) void foo();
1635 class __declspec(dllexport) classname {...};
1636 void foo() __attribute__((noreturn));
1638 Note that unrecognized plain symbols are skipped anyway if they occur
1639 before the type, so such things are not necessary to mention here.
1640 Mentioning them here is necessary only if they can occur in other
1641 places, or if they are followed by a construct that must be skipped
1642 over \(like the parens in the \"__attribute__\" and \"__declspec\"
1643 examples above). In the last case, they alse need to be present on
1644 one of `c-type-list-kwds', `c-ref-list-kwds',
1645 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1646 `c-<>-type-kwds', or `c-<>-arglist-kwds'."
1647 ;; NB: These are currently not recognized in all parts of a
1648 ;; declaration. Specifically, they aren't recognized in the middle
1649 ;; of multi-token types, inside declarators, and between the
1650 ;; identifier and the arglist paren of a function declaration.
1652 ;; FIXME: This ought to be user customizable since compiler stuff
1653 ;; like this usually is wrapped in project specific macros. (It'd
1654 ;; of course be even better if we could cope without knowing this.)
1656 (c c
++) '(;; GCC extension.
1661 (c-lang-defconst c-decl-hangon-key
1662 ;; Adorned regexp matching `c-decl-hangon-kwds'.
1663 t
(c-make-keywords-re t
(c-lang-const c-decl-hangon-kwds
)))
1664 (c-lang-defvar c-decl-hangon-key
(c-lang-const c-decl-hangon-key
))
1666 (c-lang-defconst c-prefix-spec-kwds
1667 ;; All keywords that can occur in the preamble of a declaration.
1668 ;; They typically occur before the type, but they are also matched
1669 ;; after presumptive types since we often can't be sure that
1670 ;; something is a type or just some sort of macro in front of the
1671 ;; declaration. They might be ambiguous with types or type
1673 t
(delete-duplicates (append (c-lang-const c-class-decl-kwds
)
1674 (c-lang-const c-brace-list-decl-kwds
)
1675 (c-lang-const c-other-block-decl-kwds
)
1676 (c-lang-const c-typedef-decl-kwds
)
1677 (c-lang-const c-typeless-decl-kwds
)
1678 (c-lang-const c-modifier-kwds
)
1679 (c-lang-const c-other-decl-kwds
)
1680 (c-lang-const c-decl-start-kwds
)
1681 (c-lang-const c-decl-hangon-kwds
))
1682 :test
'string-equal
))
1684 (c-lang-defconst c-prefix-spec-kwds-re
1685 ;; Adorned regexp of `c-prefix-spec-kwds'.
1686 t
(c-make-keywords-re t
(c-lang-const c-prefix-spec-kwds
)))
1687 (c-lang-defvar c-prefix-spec-kwds-re
(c-lang-const c-prefix-spec-kwds-re
))
1689 (c-lang-defconst c-specifier-key
1690 ;; Adorned regexp of the keywords in `c-prefix-spec-kwds' that
1691 ;; aren't ambiguous with types or type prefixes.
1692 t
(c-make-keywords-re t
1693 (set-difference (c-lang-const c-prefix-spec-kwds
)
1694 (c-lang-const c-type-start-kwds
)
1695 :test
'string-equal
)))
1696 (c-lang-defvar c-specifier-key
(c-lang-const c-specifier-key
))
1698 (c-lang-defconst c-postfix-spec-kwds
1699 ;; Keywords that can occur after argument list of a function header
1700 ;; declaration, i.e. in the "K&R region".
1701 t
(append (c-lang-const c-postfix-decl-spec-kwds
)
1702 (c-lang-const c-decl-hangon-kwds
)))
1704 (c-lang-defconst c-not-decl-init-keywords
1705 ;; Adorned regexp matching all keywords that can't appear at the
1706 ;; start of a declaration.
1707 t
(c-make-keywords-re t
1708 (set-difference (c-lang-const c-keywords
)
1709 (append (c-lang-const c-type-start-kwds
)
1710 (c-lang-const c-prefix-spec-kwds
))
1711 :test
'string-equal
)))
1712 (c-lang-defvar c-not-decl-init-keywords
1713 (c-lang-const c-not-decl-init-keywords
))
1715 (c-lang-defconst c-protection-kwds
1716 "Access protection label keywords in classes."
1718 c
++ '("private" "protected" "public")
1719 objc
'("@private" "@protected" "@public"))
1721 (c-lang-defconst c-block-decls-with-vars
1722 "Keywords introducing declarations that can contain a block which
1723 might be followed by variable declarations, e.g. like \"foo\" in
1724 \"class Foo { ... } foo;\". So if there is a block in a declaration
1725 like that, it ends with the following ';' and not right away.
1727 The keywords on list are assumed to also be present on one of the
1728 `*-decl-kwds' lists."
1730 (c objc
) '("struct" "union" "enum" "typedef")
1731 c
++ '("class" "struct" "union" "enum" "typedef"))
1733 (c-lang-defconst c-opt-block-decls-with-vars-key
1734 ;; Regexp matching the `c-block-decls-with-vars' keywords, or nil in
1735 ;; languages without such constructs.
1736 t
(and (c-lang-const c-block-decls-with-vars
)
1737 (c-make-keywords-re t
(c-lang-const c-block-decls-with-vars
))))
1738 (c-lang-defvar c-opt-block-decls-with-vars-key
1739 (c-lang-const c-opt-block-decls-with-vars-key
))
1741 (c-lang-defconst c-postfix-decl-spec-kwds
1742 "Keywords introducing extra declaration specifiers in the region
1743 between the header and the body \(i.e. the \"K&R-region\") in
1746 java
'("extends" "implements" "throws")
1747 idl
'("context" "getraises" "manages" "primarykey" "raises" "setraises"
1750 "as" "const" "implements" "of" "ref"))
1752 (c-lang-defconst c-nonsymbol-sexp-kwds
1753 "Keywords that may be followed by a nonsymbol sexp before whatever
1754 construct it's part of continues."
1756 (c c
++ objc
) '("extern"))
1758 (c-lang-defconst c-type-list-kwds
1759 "Keywords that may be followed by a comma separated list of type
1760 identifiers, where each optionally can be prefixed by keywords. (Can
1761 also be used for the special case when the list can contain only one
1764 Assumed to be mutually exclusive with `c-ref-list-kwds'. There's no
1765 reason to put keywords on this list if they are on `c-type-prefix-kwds'.
1766 There's also no reason to add keywords that prefixes a normal
1767 declaration consisting of a type followed by a declarator (list), so
1768 the keywords on `c-modifier-kwds' should normally not be listed here
1771 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
1772 or variable identifier (that's being defined)."
1776 java
'("import" "new" "extends" "implements" "throws")
1777 idl
'("manages" "native" "primarykey" "supports"
1779 "as" "implements" "of" "scope")
1782 (c-lang-defconst c-ref-list-kwds
1783 "Keywords that may be followed by a comma separated list of
1784 reference (i.e. namespace/scope/module) identifiers, where each
1785 optionally can be prefixed by keywords. (Can also be used for the
1786 special case when the list can contain only one element.) Assumed to
1787 be mutually exclusive with `c-type-list-kwds'.
1789 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
1790 or variable identifier (that's being defined)."
1794 idl
'("import" "module"
1799 (c-lang-defconst c-colon-type-list-kwds
1800 "Keywords that may be followed (not necessarily directly) by a colon
1801 and then a comma separated list of type identifiers, where each
1802 optionally can be prefixed by keywords. (Can also be used for the
1803 special case when the list can contain only one element.)"
1805 c
++ '("class" "struct")
1806 idl
'("component" "eventtype" "home" "interface" "valuetype"
1808 "storagehome" "storagetype"))
1810 (c-lang-defconst c-colon-type-list-re
1811 "Regexp matched after the keywords in `c-colon-type-list-kwds' to skip
1812 forward to the colon. The end of the match is assumed to be directly
1813 after the colon, so the regexp should end with \":\". Must be a
1814 regexp if `c-colon-type-list-kwds' isn't nil."
1815 t
(if (c-lang-const c-colon-type-list-kwds
)
1816 ;; Disallow various common punctuation chars that can't come
1817 ;; before the ":" that starts the inherit list after "class"
1818 ;; or "struct" in C++. (Also used as default for other
1820 "[^\]\[{}();,/#=:]*:"))
1821 (c-lang-defvar c-colon-type-list-re
(c-lang-const c-colon-type-list-re
))
1823 (c-lang-defconst c-paren-nontype-kwds
1824 "Keywords that may be followed by a parenthesis expression that doesn't
1825 contain type identifiers."
1827 (c c
++) '(;; GCC extension.
1832 (c-lang-defconst c-paren-type-kwds
1833 "Keywords that may be followed by a parenthesis expression containing
1834 type identifiers separated by arbitrary tokens."
1839 pike
'("array" "function" "int" "mapping" "multiset" "object" "program"))
1841 (c-lang-defconst c-paren-any-kwds
1842 t
(delete-duplicates (append (c-lang-const c-paren-nontype-kwds
)
1843 (c-lang-const c-paren-type-kwds
))
1844 :test
'string-equal
))
1846 (c-lang-defconst c-
<>-type-kwds
1847 "Keywords that may be followed by an angle bracket expression
1848 containing type identifiers separated by \",\". The difference from
1849 `c-<>-arglist-kwds' is that unknown names are taken to be types and
1850 not other identifiers. `c-recognize-<>-arglists' is assumed to be set
1858 (c-lang-defconst c-
<>-arglist-kwds
1859 "Keywords that can be followed by a C++ style template arglist; see
1860 `c-recognize-<>-arglists' for details. That language constant is
1861 assumed to be set if this isn't nil."
1864 idl
'("fixed" "string" "wstring"))
1866 (c-lang-defconst c-
<>-sexp-kwds
1867 ;; All keywords that can be followed by an angle bracket sexp.
1868 t
(delete-duplicates (append (c-lang-const c-
<>-type-kwds
)
1869 (c-lang-const c-
<>-arglist-kwds
))
1870 :test
'string-equal
))
1872 (c-lang-defconst c-opt-
<>-sexp-key
1873 ;; Adorned regexp matching keywords that can be followed by an angle
1874 ;; bracket sexp. Always set when `c-recognize-<>-arglists' is.
1875 t
(if (c-lang-const c-recognize-
<>-arglists
)
1876 (c-make-keywords-re t
(c-lang-const c-
<>-sexp-kwds
))))
1877 (c-lang-defvar c-opt-
<>-sexp-key
(c-lang-const c-opt-
<>-sexp-key
))
1879 (c-lang-defconst c-brace-id-list-kwds
1880 "Keywords that may be followed by a brace block containing a comma
1881 separated list of identifier definitions, i.e. like the list of
1882 identifiers that follows the type in a normal declaration."
1883 t
(c-lang-const c-brace-list-decl-kwds
))
1885 (c-lang-defconst c-block-stmt-1-kwds
1886 "Statement keywords followed directly by a substatement."
1888 c
++ '("do" "else" "try")
1889 java
'("do" "else" "finally" "try")
1892 (c-lang-defconst c-block-stmt-1-key
1893 ;; Regexp matching the start of any statement followed directly by a
1894 ;; substatement (doesn't match a bare block, however).
1895 t
(c-make-keywords-re t
(c-lang-const c-block-stmt-1-kwds
)))
1896 (c-lang-defvar c-block-stmt-1-key
(c-lang-const c-block-stmt-1-key
))
1898 (c-lang-defconst c-block-stmt-2-kwds
1899 "Statement keywords followed by a paren sexp and then by a substatement."
1900 t
'("for" "if" "switch" "while")
1901 c
++ '("for" "if" "switch" "while" "catch")
1902 java
'("for" "if" "switch" "while" "catch" "synchronized")
1904 pike
'("for" "if" "switch" "while" "foreach")
1905 awk
'("for" "if" "while"))
1907 (c-lang-defconst c-block-stmt-2-key
1908 ;; Regexp matching the start of any statement followed by a paren sexp
1909 ;; and then by a substatement.
1910 t
(c-make-keywords-re t
(c-lang-const c-block-stmt-2-kwds
)))
1911 (c-lang-defvar c-block-stmt-2-key
(c-lang-const c-block-stmt-2-key
))
1913 (c-lang-defconst c-block-stmt-kwds
1914 ;; Union of `c-block-stmt-1-kwds' and `c-block-stmt-2-kwds'.
1915 t
(delete-duplicates (append (c-lang-const c-block-stmt-1-kwds
)
1916 (c-lang-const c-block-stmt-2-kwds
))
1917 :test
'string-equal
))
1919 (c-lang-defconst c-opt-block-stmt-key
1920 ;; Regexp matching the start of any statement that has a
1921 ;; substatement (except a bare block). Nil in languages that
1922 ;; don't have such constructs.
1923 t
(if (or (c-lang-const c-block-stmt-1-kwds
)
1924 (c-lang-const c-block-stmt-2-kwds
))
1925 (c-make-keywords-re t
1926 (append (c-lang-const c-block-stmt-1-kwds
)
1927 (c-lang-const c-block-stmt-2-kwds
)))))
1928 (c-lang-defvar c-opt-block-stmt-key
(c-lang-const c-opt-block-stmt-key
))
1930 (c-lang-defconst c-simple-stmt-kwds
1931 "Statement keywords followed by an expression or nothing."
1932 t
'("break" "continue" "goto" "return")
1933 ;; Note: `goto' is not valid in Java, but the keyword is still reserved.
1934 java
'("break" "continue" "goto" "return" "throw")
1936 pike
'("break" "continue" "return")
1937 awk
'(;; Not sure about "delete", "exit", "getline", etc. ; ACM 2002/5/30
1938 "break" "continue" "return" "delete" "exit" "getline" "next"
1939 "nextfile" "print" "printf"))
1941 (c-lang-defconst c-simple-stmt-key
1942 ;; Adorned regexp matching `c-simple-stmt-kwds'.
1943 t
(c-make-keywords-re t
(c-lang-const c-simple-stmt-kwds
)))
1944 (c-lang-defvar c-simple-stmt-key
(c-lang-const c-simple-stmt-key
))
1946 (c-lang-defconst c-paren-stmt-kwds
1947 "Statement keywords followed by a parenthesis expression that
1948 nevertheless contains a list separated with ';' and not ','."
1952 (c-lang-defconst c-paren-stmt-key
1953 ;; Adorned regexp matching `c-paren-stmt-kwds'.
1954 t
(c-make-keywords-re t
(c-lang-const c-paren-stmt-kwds
)))
1955 (c-lang-defvar c-paren-stmt-key
(c-lang-const c-paren-stmt-key
))
1957 (c-lang-defconst c-asm-stmt-kwds
1958 "Statement keywords followed by an assembler expression."
1960 (c c
++) '("asm" "__asm__")) ;; Not standard, but common.
1962 (c-lang-defconst c-opt-asm-stmt-key
1963 ;; Regexp matching the start of an assembler statement. Nil in
1964 ;; languages that don't support that.
1965 t
(if (c-lang-const c-asm-stmt-kwds
)
1966 (c-make-keywords-re t
(c-lang-const c-asm-stmt-kwds
))))
1967 (c-lang-defvar c-opt-asm-stmt-key
(c-lang-const c-opt-asm-stmt-key
))
1969 (c-lang-defconst c-label-kwds
1970 "Keywords introducing colon terminated labels in blocks."
1971 t
'("case" "default")
1974 (c-lang-defconst c-label-kwds-regexp
1975 ;; Adorned regexp matching any keyword that introduces a label.
1976 t
(c-make-keywords-re t
(c-lang-const c-label-kwds
)))
1977 (c-lang-defvar c-label-kwds-regexp
(c-lang-const c-label-kwds-regexp
))
1979 (c-lang-defconst c-before-label-kwds
1980 "Keywords that might be followed by a label identifier."
1982 (java pike
) (append '("break" "continue")
1983 (c-lang-const c-before-label-kwds
))
1987 (c-lang-defconst c-constant-kwds
1988 "Keywords for constants."
1990 (c c
++) '("NULL" ;; Not a keyword, but practically works as one.
1991 "false" "true") ; Defined in C99.
1993 idl
'("TRUE" "FALSE")
1994 pike
'("UNDEFINED")) ;; Not a keyword, but practically works as one.
1996 (c-lang-defconst c-primary-expr-kwds
1997 "Keywords besides constants and operators that start primary expressions."
1999 c
++ '("operator" "this")
2000 objc
'("super" "self")
2002 pike
'("this")) ;; Not really a keyword, but practically works as one.
2004 (c-lang-defconst c-expr-kwds
2005 ;; Keywords that can occur anywhere in expressions. Built from
2006 ;; `c-primary-expr-kwds' and all keyword operators in `c-operators'.
2007 t
(delete-duplicates
2008 (append (c-lang-const c-primary-expr-kwds
)
2009 (c-filter-ops (c-lang-const c-operator-list
)
2011 "\\`\\(\\w\\|\\s_\\)+\\'"))
2012 :test
'string-equal
))
2014 (c-lang-defconst c-lambda-kwds
2015 "Keywords that start lambda constructs, i.e. function definitions in
2020 (c-lang-defconst c-inexpr-block-kwds
2021 "Keywords that start constructs followed by statement blocks which can
2022 be used in expressions \(the gcc extension for this in C and C++ is
2023 handled separately by `c-recognize-paren-inexpr-blocks')."
2025 pike
'("catch" "gauge"))
2027 (c-lang-defconst c-inexpr-class-kwds
2028 "Keywords that can start classes inside expressions."
2033 (c-lang-defconst c-inexpr-brace-list-kwds
2034 "Keywords that can start brace list blocks inside expressions.
2035 Note that Java specific rules are currently applied to tell this from
2036 `c-inexpr-class-kwds'."
2040 (c-lang-defconst c-opt-inexpr-brace-list-key
2041 ;; Regexp matching the start of a brace list in an expression, or
2042 ;; nil in languages that don't have such things. This should not
2043 ;; match brace lists recognized through `c-special-brace-lists'.
2044 t
(and (c-lang-const c-inexpr-brace-list-kwds
)
2045 (c-make-keywords-re t
(c-lang-const c-inexpr-brace-list-kwds
))))
2046 (c-lang-defvar c-opt-inexpr-brace-list-key
2047 (c-lang-const c-opt-inexpr-brace-list-key
))
2049 (c-lang-defconst c-decl-block-key
2050 ;; Regexp matching keywords in any construct that contain another
2051 ;; declaration level, i.e. that isn't followed by a function block
2052 ;; or brace list. When the first submatch matches, it's an
2053 ;; unambiguous construct, otherwise it's an ambiguous match that
2054 ;; might also be the return type of a function declaration.
2055 t
(let* ((decl-kwds (append (c-lang-const c-class-decl-kwds
)
2056 (c-lang-const c-other-block-decl-kwds
)
2057 (c-lang-const c-inexpr-class-kwds
)))
2058 (unambiguous (set-difference decl-kwds
2059 (c-lang-const c-type-start-kwds
)
2060 :test
'string-equal
))
2061 (ambiguous (intersection decl-kwds
2062 (c-lang-const c-type-start-kwds
)
2063 :test
'string-equal
)))
2065 (concat (c-make-keywords-re t unambiguous
)
2067 (c-make-keywords-re t ambiguous
))
2068 (c-make-keywords-re t unambiguous
))))
2069 (c-lang-defvar c-decl-block-key
(c-lang-const c-decl-block-key
))
2071 (c-lang-defconst c-bitfield-kwds
2072 "Keywords that can introduce bitfields."
2074 (c c
++ objc
) '("char" "int" "long" "signed" "unsigned"))
2076 (c-lang-defconst c-opt-bitfield-key
2077 ;; Regexp matching the start of a bitfield (not uniquely), or nil in
2078 ;; languages without bitfield support.
2080 (c c
++) (c-make-keywords-re t
(c-lang-const c-bitfield-kwds
)))
2081 (c-lang-defvar c-opt-bitfield-key
(c-lang-const c-opt-bitfield-key
))
2083 (c-lang-defconst c-other-kwds
2084 "Keywords not accounted for by any other `*-kwds' language constant."
2087 ;; In CORBA CIDL: (These are declaration keywords that never
2088 ;; can start a declaration.)
2089 "entity" "process" "service" "session" "storage"))
2092 ;;; Constants built from keywords.
2094 ;; Note: No `*-kwds' language constants may be defined below this point.
2097 (defconst c-kwds-lang-consts
2098 ;; List of all the language constants that contain keyword lists.
2100 (mapatoms (lambda (sym)
2101 (when (and (boundp sym
)
2102 (string-match "-kwds\\'" (symbol-name sym
)))
2103 ;; Make the list of globally interned symbols
2104 ;; instead of ones interned in `c-lang-constants'.
2105 (setq list
(cons (intern (symbol-name sym
)) list
))))
2109 (c-lang-defconst c-keywords
2110 ;; All keywords as a list.
2111 t
(delete-duplicates
2112 (c-lang-defconst-eval-immediately
2113 `(append ,@(mapcar (lambda (kwds-lang-const)
2114 `(c-lang-const ,kwds-lang-const
))
2117 :test
'string-equal
))
2119 (c-lang-defconst c-keywords-regexp
2120 ;; All keywords as an adorned regexp.
2121 t
(c-make-keywords-re t
(c-lang-const c-keywords
)))
2122 (c-lang-defvar c-keywords-regexp
(c-lang-const c-keywords-regexp
))
2124 (c-lang-defconst c-keyword-member-alist
2125 ;; An alist with all the keywords in the cars. The cdr for each
2126 ;; keyword is a list of the symbols for the `*-kwds' lists that
2128 t
(let ((kwd-list-alist
2129 (c-lang-defconst-eval-immediately
2130 `(list ,@(mapcar (lambda (kwds-lang-const)
2131 `(cons ',kwds-lang-const
2132 (c-lang-const ,kwds-lang-const
)))
2133 c-kwds-lang-consts
))))
2134 lang-const kwd-list kwd
2136 (while kwd-list-alist
2137 (setq lang-const
(caar kwd-list-alist
)
2138 kwd-list
(cdar kwd-list-alist
)
2139 kwd-list-alist
(cdr kwd-list-alist
))
2141 (setq kwd
(car kwd-list
)
2142 kwd-list
(cdr kwd-list
))
2143 (unless (setq elem
(assoc kwd result-alist
))
2144 (setq result-alist
(cons (setq elem
(list kwd
)) result-alist
)))
2145 (unless (memq lang-const
(cdr elem
))
2146 (setcdr elem
(cons lang-const
(cdr elem
))))))
2149 (c-lang-defvar c-keywords-obarray
2150 ;; An obarray containing all keywords as symbols. The property list
2151 ;; of each symbol has a non-nil entry for the specific `*-kwds'
2152 ;; lists it's a member of.
2154 ;; E.g. to see whether the string str contains a keyword on
2155 ;; `c-class-decl-kwds', one can do like this:
2156 ;; (get (intern-soft str c-keyword-obarray) 'c-class-decl-kwds)
2157 ;; Which preferably is written using the associated functions in
2159 ;; (c-keyword-member (c-keyword-sym str) 'c-class-decl-kwds)
2161 ;; The obarray is not stored directly as a language constant since
2162 ;; the printed representation for obarrays used in .elc files isn't
2165 (let* ((alist (c-lang-const c-keyword-member-alist
))
2167 (obarray (make-vector (* (length alist
) 2) 0)))
2169 (setq kwd
(caar alist
)
2170 lang-const-list
(cdar alist
)
2172 (setplist (intern kwd obarray
)
2173 ;; Emacs has an odd bug that causes `mapcan' to fail
2174 ;; with unintelligible errors. (XEmacs works.)
2175 ;;(mapcan (lambda (lang-const)
2176 ;; (list lang-const t))
2178 (apply 'nconc
(mapcar (lambda (lang-const)
2179 (list lang-const t
))
2183 (c-lang-defconst c-regular-keywords-regexp
2184 ;; Adorned regexp matching all keywords that should be fontified
2185 ;; with the keywords face. I.e. that aren't types or constants.
2186 t
(c-make-keywords-re t
2187 (set-difference (c-lang-const c-keywords
)
2188 (append (c-lang-const c-primitive-type-kwds
)
2189 (c-lang-const c-constant-kwds
))
2190 :test
'string-equal
)))
2191 (c-lang-defvar c-regular-keywords-regexp
2192 (c-lang-const c-regular-keywords-regexp
))
2194 (c-lang-defconst c-primary-expr-regexp
2195 ;; Regexp matching the start of any primary expression, i.e. any
2196 ;; literal, symbol, prefix operator, and '('. It doesn't need to
2197 ;; exclude keywords; they are excluded afterwards unless the second
2198 ;; submatch matches. If the first but not the second submatch
2199 ;; matches then it is an ambiguous primary expression; it could also
2200 ;; be a match of e.g. an infix operator. (The case with ambiguous
2201 ;; keyword operators isn't handled.)
2203 t
(let* ((prefix-ops
2204 (c-filter-ops (c-lang-const c-operators
)
2207 ;; Filter out the special case prefix
2208 ;; operators that are close parens.
2209 (not (string-match "\\s)" op
)))))
2211 (nonkeyword-prefix-ops
2212 (c-filter-ops prefix-ops
2214 "\\`\\(\\s.\\|\\s(\\|\\s)\\)+\\'"))
2217 (c-filter-ops (c-lang-const c-operators
)
2222 right-assoc-sequence
)
2225 (unambiguous-prefix-ops (set-difference nonkeyword-prefix-ops
2227 :test
'string-equal
))
2228 (ambiguous-prefix-ops (intersection nonkeyword-prefix-ops
2230 :test
'string-equal
)))
2234 ;; Take out all symbol class operators from `prefix-ops' and make the
2235 ;; first submatch from them together with `c-primary-expr-kwds'.
2236 (c-make-keywords-re t
2237 (append (c-lang-const c-primary-expr-kwds
)
2238 (set-difference prefix-ops nonkeyword-prefix-ops
2239 :test
'string-equal
)))
2242 ;; Match all ambiguous operators.
2243 (c-make-keywords-re nil
2244 (intersection nonkeyword-prefix-ops in-or-postfix-ops
2245 :test
'string-equal
))
2249 ;; Now match all other symbols.
2250 (c-lang-const c-symbol-start
)
2253 ;; The chars that can start integer and floating point
2258 ;; The nonambiguous operators from `prefix-ops'.
2259 (c-make-keywords-re nil
2260 (set-difference nonkeyword-prefix-ops in-or-postfix-ops
2261 :test
'string-equal
))
2264 ;; Match string and character literals.
2266 (if (memq 'gen-string-delim c-emacs-features
)
2269 (c-lang-defvar c-primary-expr-regexp
(c-lang-const c-primary-expr-regexp
))
2272 ;;; Additional constants for parser-level constructs.
2274 (c-lang-defconst c-decl-prefix-re
2275 "Regexp matching something that might precede a declaration, cast or
2276 label, such as the last token of a preceding statement or declaration.
2277 This is used in the common situation where a declaration or cast
2278 doesn't start with any specific token that can be searched for.
2280 The regexp should not match bob; that is done implicitly. It can't
2281 require a match longer than one token. The end of the token is taken
2282 to be at the end of the first submatch, which is assumed to always
2283 match. It's undefined whether identifier syntax (see
2284 `c-identifier-syntax-table') is in effect or not. This regexp is
2285 assumed to be a superset of `c-label-prefix-re' if
2286 `c-recognize-colon-labels' is set.
2288 Besides this, `c-decl-start-kwds' is used to find declarations.
2290 Note: This variable together with `c-decl-start-re' and
2291 `c-decl-start-kwds' is only used to detect \"likely\"
2292 declaration/cast/label starts. I.e. they might produce more matches
2293 but should not miss anything (or else it's necessary to use text
2294 properties - see the next note). Wherever they match, the following
2295 construct is analyzed to see if it indeed is a declaration, cast or
2296 label. That analysis is not cheap, so it's important that not too
2297 many false matches are triggered.
2299 Note: If a declaration/cast/label start can't be detected with this
2300 variable, it's necessary to use the `c-type' text property with the
2301 value `c-decl-end' on the last char of the last token preceding the
2302 declaration. See the comment blurb at the start of cc-engine.el for
2305 ;; We match a sequence of characters to skip over things like \"};\"
2306 ;; more quickly. We match ")" in C for K&R region declarations, and
2307 ;; in all languages except Java for when a cpp macro definition
2308 ;; begins with a declaration.
2309 t
"\\([\{\}\(\);,]+\\)"
2310 java
"\\([\{\}\(;,]+\\)"
2311 ;; Match "<" in C++ to get the first argument in a template arglist.
2312 ;; In that case there's an additional check in `c-find-decl-spots'
2313 ;; that it got open paren syntax.
2314 c
++ "\\([\{\}\(\);,<]+\\)"
2315 ;; Additionally match the protection directives in Objective-C.
2316 ;; Note that this doesn't cope with the longer directives, which we
2317 ;; would have to match from start to end since they don't end with
2318 ;; any easily recognized characters.
2319 objc
(concat "\\([\{\}\(\);,]+\\|"
2320 (c-make-keywords-re nil
(c-lang-const c-protection-kwds
))
2322 ;; Pike is like C but we also match "[" for multiple value
2323 ;; assignments and type casts.
2324 pike
"\\([\{\}\(\)\[;,]+\\)")
2325 (c-lang-defvar c-decl-prefix-re
(c-lang-const c-decl-prefix-re
)
2328 (c-lang-defconst c-decl-start-re
2329 "Regexp matching the start of any declaration, cast or label.
2330 It's used on the token after the one `c-decl-prefix-re' matched. This
2331 regexp should not try to match those constructs accurately as it's
2332 only used as a sieve to avoid spending more time checking other
2334 t
(c-lang-const c-identifier-start
))
2335 (c-lang-defvar c-decl-start-re
(c-lang-const c-decl-start-re
))
2337 (c-lang-defconst c-decl-prefix-or-start-re
2338 ;; Regexp matching something that might precede or start a
2339 ;; declaration, cast or label.
2341 ;; If the first submatch matches, it's taken to match the end of a
2342 ;; token that might precede such a construct, e.g. ';', '}' or '{'.
2343 ;; It's built from `c-decl-prefix-re'.
2345 ;; If the first submatch did not match, the match of the whole
2346 ;; regexp is taken to be at the first token in the declaration.
2347 ;; `c-decl-start-re' is not checked in this case.
2349 ;; Design note: The reason the same regexp is used to match both
2350 ;; tokens that precede declarations and start them is to avoid an
2351 ;; extra regexp search from the previous declaration spot in
2352 ;; `c-find-decl-spots'. Users of `c-find-decl-spots' also count on
2353 ;; that it finds all declaration/cast/label starts in approximately
2354 ;; linear order, so we can't do the searches in two separate passes.
2355 t
(if (c-lang-const c-decl-start-kwds
)
2356 (concat (c-lang-const c-decl-prefix-re
)
2358 (c-make-keywords-re t
(c-lang-const c-decl-start-kwds
)))
2359 (c-lang-const c-decl-prefix-re
)))
2360 (c-lang-defvar c-decl-prefix-or-start-re
2361 (c-lang-const c-decl-prefix-or-start-re
)
2364 (c-lang-defconst c-cast-parens
2365 ;; List containing the paren characters that can open a cast, or nil in
2366 ;; languages without casts.
2367 t
(c-filter-ops (c-lang-const c-operators
)
2370 (lambda (op) (elt op
0))))
2371 (c-lang-defvar c-cast-parens
(c-lang-const c-cast-parens
))
2373 (c-lang-defconst c-block-prefix-disallowed-chars
2374 "List of syntactically relevant characters that never can occur before
2375 the open brace in any construct that contains a brace block, e.g. in
2376 the \"class Foo: public Bar\" part of:
2378 class Foo: public Bar {int x();} a, *b;
2380 If parens can occur, the chars inside those aren't filtered with this
2383 '<' and '>' should be disallowed even if angle bracket arglists can
2384 occur. That since the search function needs to stop at them anyway to
2385 ensure they are given paren syntax.
2387 This is used to skip backward from the open brace to find the region
2388 in which to look for a construct like \"class\", \"enum\",
2389 \"namespace\" or whatever. That skipping should be as tight as
2390 possible for good performance."
2392 ;; Default to all chars that only occurs in nonsymbol tokens outside
2395 (c-lang-const c-nonsymbol-token-char-list
)
2396 (c-filter-ops (append (c-lang-const c-identifier-ops
)
2398 (c-lang-const c-after-id-concat-ops
))))
2403 (while (string-match "\\(\\s.\\|\\s(\\|\\s)\\)"
2405 (setq res
(cons (aref op
(match-beginning 1)) res
)
2409 ;; Allow cpp operatios (where applicable).
2410 t
(if (c-lang-const c-opt-cpp-prefix
)
2411 (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2413 (c-lang-const c-block-prefix-disallowed-chars
))
2415 ;; Allow ':' for inherit list starters.
2416 (c++ objc idl
) (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2419 ;; Allow ',' for multiple inherits.
2420 (c++ java
) (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2423 ;; Allow parentheses for anonymous inner classes in Java and class
2424 ;; initializer lists in Pike.
2425 (java pike
) (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2428 ;; Allow '"' for extern clauses (e.g. extern "C" {...}).
2429 (c c
++ objc
) (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2432 (c-lang-defconst c-block-prefix-charset
2433 ;; `c-block-prefix-disallowed-chars' as an inverted charset suitable
2434 ;; for `c-syntactic-skip-backward'.
2435 t
(c-make-bare-char-alt (c-lang-const c-block-prefix-disallowed-chars
) t
))
2436 (c-lang-defvar c-block-prefix-charset
(c-lang-const c-block-prefix-charset
))
2438 (c-lang-defconst c-type-decl-prefix-key
2439 "Regexp matching the declarator operators that might precede the
2440 identifier in a declaration, e.g. the \"*\" in \"char *argv\". This
2441 regexp should match \"(\" if parentheses are valid in declarators.
2442 The end of the first submatch is taken as the end of the operator.
2443 Identifier syntax is in effect when this is matched \(see
2444 `c-identifier-syntax-table')."
2445 t
(if (c-lang-const c-type-modifier-kwds
)
2446 (concat (regexp-opt (c-lang-const c-type-modifier-kwds
) t
) "\\>")
2447 ;; Default to a regexp that never matches.
2449 ;; Check that there's no "=" afterwards to avoid matching tokens
2451 (c objc
) (concat "\\("
2454 (c-lang-const c-type-decl-prefix-key
)
2461 ;; If this matches there's special treatment in
2462 ;; `c-font-lock-declarators' and
2463 ;; `c-font-lock-declarations' that check for a
2464 ;; complete name followed by ":: *".
2465 (c-lang-const c-identifier-start
)
2468 (c-lang-const c-type-decl-prefix-key
)
2471 pike
"\\(\\*\\)\\([^=]\\|$\\)")
2472 (c-lang-defvar c-type-decl-prefix-key
(c-lang-const c-type-decl-prefix-key
)
2475 (c-lang-defconst c-type-decl-suffix-key
2476 "Regexp matching the declarator operators that might follow after the
2477 identifier in a declaration, e.g. the \"[\" in \"char argv[]\". This
2478 regexp should match \")\" if parentheses are valid in declarators. If
2479 it matches an open paren of some kind, the type declaration check
2480 continues at the corresponding close paren, otherwise the end of the
2481 first submatch is taken as the end of the operator. Identifier syntax
2482 is in effect when this is matched (see `c-identifier-syntax-table')."
2483 ;; Default to a regexp that matches `c-type-modifier-kwds' and a
2484 ;; function argument list parenthesis.
2485 t
(if (c-lang-const c-type-modifier-kwds
)
2487 (regexp-opt (c-lang-const c-type-modifier-kwds
) t
) "\\>"
2490 (c c
++ objc
) (concat
2493 (if (c-lang-const c-type-modifier-kwds
)
2496 ;; "throw" in `c-type-modifier-kwds' is followed
2497 ;; by a parenthesis list, but no extra measures
2498 ;; are necessary to handle that.
2499 (regexp-opt (c-lang-const c-type-modifier-kwds
) t
)
2503 (java idl
) "\\([\[\(]\\)")
2504 (c-lang-defvar c-type-decl-suffix-key
(c-lang-const c-type-decl-suffix-key
)
2507 (c-lang-defconst c-after-suffixed-type-decl-key
2508 "This regexp is matched after a declarator expression where
2509 `c-type-decl-suffix-key' has matched. If it matches then the
2510 construct is taken as a declaration. It's typically used to match the
2511 beginning of a function body or whatever might occur after the
2512 function header in a function declaration or definition. It's
2513 undefined whether identifier syntax (see `c-identifier-syntax-table')
2514 is in effect or not.
2516 Note that it's used in cases like after \"foo (bar)\" so it should
2517 only match when it's certain that it's a declaration, e.g \"{\" but
2518 not \",\" or \";\"."
2520 ;; If K&R style declarations should be recognized then one could
2521 ;; consider to match the start of any symbol since we want to match
2522 ;; the start of the first declaration in the "K&R region". That
2523 ;; could however produce false matches on code like "FOO(bar) x"
2524 ;; where FOO is a cpp macro, so it's better to leave it out and rely
2525 ;; on the other heuristics in that case.
2526 t
(if (c-lang-const c-postfix-spec-kwds
)
2527 ;; Add on the keywords in `c-postfix-spec-kwds'.
2528 (concat (c-lang-const c-after-suffixed-type-decl-key
)
2530 (c-make-keywords-re t
(c-lang-const c-postfix-spec-kwds
)))
2531 (c-lang-const c-after-suffixed-type-decl-key
))
2532 ;; Also match the colon that starts a base class initializer list in
2533 ;; C++. That can be confused with a function call before the colon
2534 ;; in a ? : operator, but we count on that `c-decl-prefix-re' won't
2535 ;; match before such a thing (as a declaration-level construct;
2536 ;; matches inside arglist contexts are already excluded).
2538 (c-lang-defvar c-after-suffixed-type-decl-key
2539 (c-lang-const c-after-suffixed-type-decl-key
)
2542 (c-lang-defconst c-after-suffixed-type-maybe-decl-key
2543 ;; Regexp that in addition to `c-after-suffixed-type-decl-key'
2544 ;; matches ";" and ",".
2545 t
(concat "\\(" (c-lang-const c-after-suffixed-type-decl-key
) "\\)"
2547 (c-lang-defvar c-after-suffixed-type-maybe-decl-key
2548 (c-lang-const c-after-suffixed-type-maybe-decl-key
))
2550 (c-lang-defconst c-opt-type-concat-key
2551 "Regexp matching operators that concatenate types, e.g. the \"|\" in
2552 \"int|string\" in Pike. The end of the first submatch is taken as the
2553 end of the operator. nil in languages without such operators. It's
2554 undefined whether identifier syntax (see `c-identifier-syntax-table')
2555 is in effect or not."
2557 pike
"\\([|.&]\\)\\($\\|[^|.&]\\)")
2558 (c-lang-defvar c-opt-type-concat-key
(c-lang-const c-opt-type-concat-key
)
2561 (c-lang-defconst c-opt-type-suffix-key
2562 "Regexp matching operators that might follow after a type, or nil in
2563 languages that don't have such operators. The end of the first
2564 submatch is taken as the end of the operator. This should not match
2565 things like C++ template arglists if `c-recognize-<>-arglists' is set.
2566 It's undefined whether identifier syntax (see `c-identifier-syntax-table')
2567 is in effect or not."
2569 (c c
++ objc pike
) "\\(\\.\\.\\.\\)"
2570 java
(concat "\\(\\[" (c-lang-const c-simple-ws
) "*\\]\\)"))
2571 (c-lang-defvar c-opt-type-suffix-key
(c-lang-const c-opt-type-suffix-key
))
2573 (c-lang-defvar c-known-type-key
2574 ;; Regexp matching the known type identifiers. This is initialized
2575 ;; from the type keywords and `*-font-lock-extra-types'. The first
2576 ;; submatch is the one that matches the type. Note that this regexp
2577 ;; assumes that symbol constituents like '_' and '$' have word
2580 (when (boundp (c-mode-symbol "font-lock-extra-types"))
2581 (c-mode-var "font-lock-extra-types")))
2584 (mapcar (lambda (re)
2585 (when (string-match "[][.*+?^$\\]" re
)
2590 (mapcar (lambda (re)
2591 (unless (string-match "[][.*+?^$\\]" re
)
2596 (append (list (c-make-keywords-re nil
2597 (append (c-lang-const c-primitive-type-kwds
)
2603 (c-lang-defconst c-special-brace-lists
2604 "List of open- and close-chars that makes up a pike-style brace list,
2605 i.e. for a ([Â ]) list there should be a cons (?\\[ . ?\\]) in this
2608 pike
'((?
{ . ?
}) (?\
[ . ?\
]) (?
< . ?
>)))
2609 (c-lang-defvar c-special-brace-lists
(c-lang-const c-special-brace-lists
))
2611 (c-lang-defconst c-recognize-knr-p
2612 "Non-nil means K&R style argument declarations are valid."
2615 (c-lang-defvar c-recognize-knr-p
(c-lang-const c-recognize-knr-p
))
2617 (c-lang-defconst c-recognize-typeless-decls
2618 "Non-nil means function declarations without return type should be
2619 recognized. That can introduce an ambiguity with parenthesized macro
2620 calls before a brace block. This setting does not affect declarations
2621 that are preceded by a declaration starting keyword, so
2622 e.g. `c-typeless-decl-kwds' may still be used when it's set to nil."
2625 (c-lang-defvar c-recognize-typeless-decls
2626 (c-lang-const c-recognize-typeless-decls
))
2628 (c-lang-defconst c-recognize-
<>-arglists
2629 "Non-nil means C++ style template arglists should be handled. More
2630 specifically, this means a comma separated list of types or
2631 expressions surrounded by \"<\" and \">\". It's always preceded by an
2632 identifier or one of the keywords on `c-<>-type-kwds' or
2633 `c-<>-arglist-kwds'. If there's an identifier before then the whole
2634 expression is considered to be a type."
2635 t
(or (consp (c-lang-const c-
<>-type-kwds
))
2636 (consp (c-lang-const c-
<>-arglist-kwds
))))
2637 (c-lang-defvar c-recognize-
<>-arglists
(c-lang-const c-recognize-
<>-arglists
))
2639 (c-lang-defconst c-recognize-paren-inits
2640 "Non-nil means that parenthesis style initializers exist,
2641 i.e. constructs like
2645 in addition to the more classic
2650 (c-lang-defvar c-recognize-paren-inits
(c-lang-const c-recognize-paren-inits
))
2652 (c-lang-defconst c-recognize-paren-inexpr-blocks
2653 "Non-nil to recognize gcc style in-expression blocks,
2654 i.e. compound statements surrounded by parentheses inside expressions."
2657 (c-lang-defvar c-recognize-paren-inexpr-blocks
2658 (c-lang-const c-recognize-paren-inexpr-blocks
))
2660 (c-lang-defconst c-opt-
<>-arglist-start
2661 ;; Regexp matching the start of angle bracket arglists in languages
2662 ;; where `c-recognize-<>-arglists' is set. Does not exclude
2663 ;; keywords outside `c-<>-arglist-kwds'. The first submatch is
2664 ;; assumed to surround the preceding symbol. The whole match is
2665 ;; assumed to end directly after the opening "<".
2666 t
(if (c-lang-const c-recognize-
<>-arglists
)
2668 (c-lang-const c-symbol-key
)
2670 (c-lang-const c-syntactic-ws
)
2672 (c-lang-defvar c-opt-
<>-arglist-start
(c-lang-const c-opt-
<>-arglist-start
))
2674 (c-lang-defconst c-opt-
<>-arglist-start-in-paren
2675 ;; Regexp that in addition to `c-opt-<>-arglist-start' matches close
2676 ;; parens. The first submatch is assumed to surround
2677 ;; `c-opt-<>-arglist-start'.
2678 t
(if (c-lang-const c-opt-
<>-arglist-start
)
2680 (c-lang-const c-opt-
<>-arglist-start
)
2682 (c-lang-defvar c-opt-
<>-arglist-start-in-paren
2683 (c-lang-const c-opt-
<>-arglist-start-in-paren
))
2685 (c-lang-defconst c-opt-postfix-decl-spec-key
2686 ;; Regexp matching the beginning of a declaration specifier in the
2687 ;; region between the header and the body of a declaration.
2689 ;; TODO: This is currently not used uniformly; c++-mode and
2690 ;; java-mode each have their own ways of using it.
2693 (c-lang-const c-simple-ws
) "*"
2694 "\\(virtual" (c-lang-const c-simple-ws
) "+\\)?\\("
2695 (c-make-keywords-re nil
(c-lang-const c-protection-kwds
))
2696 "\\)" (c-lang-const c-simple-ws
) "+"
2697 "\\(" (c-lang-const c-symbol-key
) "\\)")
2698 java
(c-make-keywords-re t
(c-lang-const c-postfix-spec-kwds
)))
2699 (c-lang-defvar c-opt-postfix-decl-spec-key
2700 (c-lang-const c-opt-postfix-decl-spec-key
))
2702 (c-lang-defconst c-recognize-colon-labels
2703 "Non-nil if generic labels ending with \":\" should be recognized.
2704 That includes labels in code and access keys in classes. This does
2705 not apply to labels recognized by `c-label-kwds' and
2706 `c-opt-extra-label-key'."
2708 (c c
++ objc java pike
) t
)
2709 (c-lang-defvar c-recognize-colon-labels
2710 (c-lang-const c-recognize-colon-labels
))
2712 (c-lang-defconst c-label-prefix-re
2713 "Regexp like `c-decl-prefix-re' that matches any token that can precede
2714 a generic colon label. Not used if `c-recognize-colon-labels' is
2717 (c-lang-defvar c-label-prefix-re
2718 (c-lang-const c-label-prefix-re
))
2720 (c-lang-defconst c-nonlabel-token-key
2721 "Regexp matching things that can't occur in generic colon labels,
2722 neither in a statement nor in a declaration context. The regexp is
2723 tested at the beginning of every sexp in a suspected label,
2724 i.e. before \":\". Only used if `c-recognize-colon-labels' is set."
2726 ;; Don't allow string literals.
2728 ;; All keywords except `c-label-kwds' and `c-protection-kwds'.
2729 (c-make-keywords-re t
2730 (set-difference (c-lang-const c-keywords
)
2731 (append (c-lang-const c-label-kwds
)
2732 (c-lang-const c-protection-kwds
))
2733 :test
'string-equal
)))
2734 ;; Also check for open parens in C++, to catch member init lists in
2735 ;; constructors. We normally allow it so that macros with arguments
2737 c
++ (concat "\\s\(\\|" (c-lang-const c-nonlabel-token-key
)))
2738 (c-lang-defvar c-nonlabel-token-key
(c-lang-const c-nonlabel-token-key
))
2740 (c-lang-defconst c-opt-extra-label-key
2741 "Optional regexp matching labels.
2742 Normally, labels are detected according to `c-nonlabel-token-key',
2743 `c-decl-prefix-re' and `c-nonlabel-decl-prefix-re'. This regexp can
2744 be used if there are additional labels that aren't recognized that
2747 objc
(c-make-keywords-re t
(c-lang-const c-protection-kwds
)))
2748 (c-lang-defvar c-opt-extra-label-key
(c-lang-const c-opt-extra-label-key
))
2750 (c-lang-defconst c-opt-friend-key
2751 ;; Regexp describing friend declarations classes, or nil in
2752 ;; languages that don't have such things.
2754 ;; TODO: Ought to use `c-prefix-spec-kwds-re' or similar, and the
2755 ;; template skipping isn't done properly. This will disappear soon.
2757 c
++ (concat "friend" (c-lang-const c-simple-ws
) "+"
2760 (c-lang-const c-simple-ws
) "*"
2762 (c-lang-const c-simple-ws
) "*"
2764 (c-lang-const c-simple-ws
) "+")))
2765 (c-lang-defvar c-opt-friend-key
(c-lang-const c-opt-friend-key
))
2767 (c-lang-defconst c-opt-method-key
2768 ;; Special regexp to match the start of Objective-C methods. The
2769 ;; first submatch is assumed to end after the + or - key.
2772 ;; TODO: Ought to use a better method than anchoring on bol.
2775 (c-lang-const c-simple-ws
) "*"
2776 (concat "\\(" ; Return type.
2778 (c-lang-const c-simple-ws
) "*"
2780 "\\(" (c-lang-const c-symbol-key
) "\\)"))
2781 (c-lang-defvar c-opt-method-key
(c-lang-const c-opt-method-key
))
2783 (c-lang-defconst c-type-decl-end-used
2784 ;; Must be set in buffers where the `c-type' text property might be
2785 ;; used with the value `c-decl-end'.
2787 ;; `c-decl-end' is used to mark the ends of labels and access keys
2788 ;; to make interactive refontification work better.
2789 t
(or (c-lang-const c-recognize-colon-labels
)
2790 (and (c-lang-const c-label-kwds
) t
))
2791 ;; `c-decl-end' is used to mark the end of the @-style directives in
2794 (c-lang-defvar c-type-decl-end-used
(c-lang-const c-type-decl-end-used
))
2797 ;;; Wrap up the `c-lang-defvar' system.
2799 ;; Compile in the list of language variables that has been collected
2800 ;; with the `c-lang-defvar' macro. Note that the first element is
2802 (defconst c-lang-variable-inits
(cc-eval-when-compile c-lang-variable-inits
))
2804 (defun c-make-init-lang-vars-fun (mode)
2805 "Create a function that initializes all the language dependent variables
2808 This function should be evaluated at compile time, so that the
2809 function it returns is byte compiled with all the evaluated results
2810 from the language constants. Use the `c-init-language-vars' macro to
2811 accomplish that conveniently."
2813 (if (and (not load-in-progress
)
2814 (boundp 'byte-compile-dest-file
)
2815 (stringp byte-compile-dest-file
))
2817 ;; No need to byte compile this lambda since the byte compiler is
2818 ;; smart enough to detect the `funcall' construct in the
2819 ;; `c-init-language-vars' macro below and compile it all straight
2820 ;; into the function that contains `c-init-language-vars'.
2823 ;; This let sets up the context for `c-mode-var' and similar
2824 ;; that could be in the result from `cl-macroexpand-all'.
2825 (let ((c-buffer-is-cc-mode ',mode
)
2829 (if (eq c-version-sym
',c-version-sym
)
2830 (setq ,@(let ((c-buffer-is-cc-mode mode
)
2831 (c-lang-const-expansion 'immediate
))
2832 ;; `c-lang-const' will expand to the evaluated
2833 ;; constant immediately in `cl-macroexpand-all'
2837 `(current-var ',(car init
)
2838 ,(car init
) ,(cl-macroexpand-all
2840 (cdr c-lang-variable-inits
))))
2842 ;; This diagnostic message isn't useful for end
2843 ;; users, so it's disabled.
2844 ;;(unless (get ',mode 'c-has-warned-lang-consts)
2845 ;; (message ,(concat "%s compiled with CC Mode %s "
2846 ;; "but loaded with %s - evaluating "
2847 ;; "language constants from source")
2848 ;; ',mode ,c-version c-version)
2849 ;; (put ',mode 'c-has-warned-lang-consts t))
2852 (let ((init (cdr c-lang-variable-inits
)))
2854 (setq current-var
(caar init
))
2855 (set (caar init
) (eval (cadar init
)))
2856 (setq init
(cdr init
)))))
2860 (message "Eval error in the `c-lang-defvar' for `%s': %S"
2862 (signal (car err
) (cdr err
)))))))
2864 ;; Being evaluated from source. Always use the dynamic method to
2865 ;; work well when `c-lang-defvar's in this file are reevaluated
2869 (let ((c-buffer-is-cc-mode ',mode
)
2870 (init (cdr c-lang-variable-inits
))
2875 (setq current-var
(caar init
))
2876 (set (caar init
) (eval (cadar init
)))
2877 (setq init
(cdr init
)))
2881 (message "Eval error in the `c-lang-defvar' for `%s': %S"
2883 (signal (car err
) (cdr err
)))))))
2886 (defmacro c-init-language-vars
(mode)
2887 "Initialize all the language dependent variables for the given mode.
2888 This macro is expanded at compile time to a form tailored for the mode
2889 in question, so MODE must be a constant. Therefore MODE is not
2890 evaluated and should not be quoted."
2891 `(funcall ,(c-make-init-lang-vars-fun mode
)))
2894 (cc-provide 'cc-langs
)
2896 ;;; arch-tag: 1ab57482-cfc2-4c5b-b628-3539c3098822
2897 ;;; cc-langs.el ends here