Fix unstable fontification inside templates.
[emacs.git] / lisp / progmodes / cc-langs.el
blob2b6dc7a9df74b4fa663fc9f7880de17194a39203
1 ;;; cc-langs.el --- language specific settings for CC Mode
3 ;; Copyright (C) 1985, 1987, 1992-2011 Free Software Foundation, Inc.
5 ;; Authors: 2002- Alan Mackenzie
6 ;; 1998- Martin Stjernholm
7 ;; 1992-1999 Barry A. Warsaw
8 ;; 1987 Dave Detlefs
9 ;; 1987 Stewart Clamen
10 ;; 1985 Richard M. Stallman
11 ;; Maintainer: bug-cc-mode@gnu.org
12 ;; Created: 22-Apr-1997 (split from cc-mode.el)
13 ;; Keywords: c languages
14 ;; Package: cc-mode
16 ;; This file is part of GNU Emacs.
18 ;; GNU Emacs is free software: you can redistribute it and/or modify
19 ;; it under the terms of the GNU General Public License as published by
20 ;; the Free Software Foundation, either version 3 of the License, or
21 ;; (at your option) any later version.
23 ;; GNU Emacs is distributed in the hope that it will be useful,
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 ;; GNU General Public License for more details.
28 ;; You should have received a copy of the GNU General Public License
29 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
31 ;;; Commentary:
33 ;; HACKERS NOTE: There's heavy macro magic here. If you need to make
34 ;; changes in this or other files containing `c-lang-defconst' but
35 ;; don't want to read through the longer discussion below then read
36 ;; this:
38 ;; o A change in a `c-lang-defconst' or `c-lang-defvar' will not take
39 ;; effect if the file containing the mode init function (typically
40 ;; cc-mode.el) is byte compiled.
41 ;; o To make changes show in font locking you need to reevaluate the
42 ;; `*-font-lock-keywords-*' constants, which normally is easiest to
43 ;; do with M-x eval-buffer in cc-fonts.el.
44 ;; o In either case it's necessary to reinitialize the mode to make
45 ;; the changes show in an existing buffer.
47 ;;; Introduction to the language dependent variable system:
49 ;; This file contains all the language dependent variables, except
50 ;; those specific for font locking which reside in cc-fonts.el. As
51 ;; far as possible, all the differences between the languages that CC
52 ;; Mode supports are described with these variables only, so that the
53 ;; code can be shared.
55 ;; The language constant system (see cc-defs.el) is used to specify
56 ;; various language dependent info at a high level, such as lists of
57 ;; keywords, and then from them generate - at compile time - the
58 ;; various regexps and other low-level structures actually employed in
59 ;; the code at runtime.
61 ;; This system is also designed to make it easy for developers of
62 ;; derived modes to customize the source constants for new language
63 ;; variants, without having to keep up with the exact regexps etc that
64 ;; are used in each CC Mode version. It's possible from an external
65 ;; package to add a new language by inheriting an existing one, and
66 ;; then change specific constants as necessary for the new language.
67 ;; The old values for those constants (and the values of all the other
68 ;; high-level constants) may be used to build the new ones, and those
69 ;; new values will in turn be used by the low-level definitions here
70 ;; to build the runtime constants appropriately for the new language
71 ;; in the current version of CC Mode.
73 ;; Like elsewhere in CC Mode, the existence of a doc string signifies
74 ;; that a language constant is part of the external API, and that it
75 ;; therefore can be used with a high confidence that it will continue
76 ;; to work with future versions of CC Mode. Even so, it's not
77 ;; unlikely that such constants will change meaning slightly as this
78 ;; system is refined further; a certain degree of dependence on the CC
79 ;; Mode version is unavoidable when hooking in at this level. Also
80 ;; note that there's still work to be done to actually use these
81 ;; constants everywhere inside CC Mode; there are still hardcoded
82 ;; values in many places in the code.
84 ;; Separate packages will also benefit from the compile time
85 ;; evaluation; the byte compiled file(s) for them will contain the
86 ;; compiled runtime constants ready for use by (the byte compiled) CC
87 ;; Mode, and the source definitions in this file don't have to be
88 ;; loaded then. However, if a byte compiled package is loaded that
89 ;; has been compiled with a different version of CC Mode than the one
90 ;; currently loaded, then the compiled-in values will be discarded and
91 ;; new ones will be built when the mode is initialized. That will
92 ;; automatically trig a load of the file(s) containing the source
93 ;; definitions (i.e. this file and/or cc-fonts.el) if necessary.
95 ;; A small example of a derived mode is available at
96 ;; <http://cc-mode.sourceforge.net/derived-mode-ex.el>. It also
97 ;; contains some useful hints for derived mode developers.
99 ;;; Using language variables:
101 ;; The `c-lang-defvar' forms in this file comprise the language
102 ;; variables that CC Mode uses. It does not work to use
103 ;; `c-lang-defvar' anywhere else (which isn't much of a limitation
104 ;; since these variables sole purpose is to interface with the CC Mode
105 ;; core functions). The values in these `c-lang-defvar's are not
106 ;; evaluated right away but instead collected to a single large `setq'
107 ;; that can be inserted for a particular language with the
108 ;; `c-init-language-vars' macro.
110 ;; This file is only required at compile time, or when not running
111 ;; from byte compiled files, or when the source definitions for the
112 ;; language constants are requested.
114 ;;; Code:
116 ;; For Emacs < 22.2.
117 (eval-and-compile
118 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
120 (eval-when-compile
121 (let ((load-path
122 (if (and (boundp 'byte-compile-dest-file)
123 (stringp byte-compile-dest-file))
124 (cons (file-name-directory byte-compile-dest-file) load-path)
125 load-path)))
126 (load "cc-bytecomp" nil t)))
128 (cc-require 'cc-defs)
129 (cc-require 'cc-vars)
132 ;; This file is not always loaded. See note above.
133 (cc-external-require 'cl)
136 ;;; Setup for the `c-lang-defvar' system.
138 (eval-and-compile
139 ;; These are used to collect the init forms from the subsequent
140 ;; `c-lang-defvar' and `c-lang-setvar'. They are used to build the
141 ;; lambda in `c-make-init-lang-vars-fun' below, and to build `defvar's
142 ;; and `make-variable-buffer-local's in cc-engine and
143 ;; `make-local-variable's in `c-init-language-vars-for'.
144 (defvar c-lang-variable-inits nil)
145 (defvar c-lang-variable-inits-tail nil)
146 (setq c-lang-variable-inits (list nil)
147 c-lang-variable-inits-tail c-lang-variable-inits)
148 (defvar c-emacs-variable-inits nil)
149 (defvar c-emacs-variable-inits-tail nil)
150 (setq c-emacs-variable-inits (list nil)
151 c-emacs-variable-inits-tail c-emacs-variable-inits))
153 (defmacro c-lang-defvar (var val &optional doc)
154 "Declares the buffer local variable VAR to get the value VAL. VAL is
155 evaluated and assigned at mode initialization. More precisely, VAL is
156 evaluated and bound to VAR when the result from the macro
157 `c-init-language-vars' is evaluated.
159 `c-lang-const' is typically used in VAL to get the right value for the
160 language being initialized, and such calls will be macro expanded to
161 the evaluated constant value at compile time."
163 (when (and (not doc)
164 (eq (car-safe val) 'c-lang-const)
165 (eq (nth 1 val) var)
166 (not (nth 2 val)))
167 ;; Special case: If there's no docstring and the value is a
168 ;; simple (c-lang-const foo) where foo is the same name as VAR
169 ;; then take the docstring from the language constant foo.
170 (setq doc (get (intern (symbol-name (nth 1 val)) c-lang-constants)
171 'variable-documentation)))
172 (or (stringp doc)
173 (setq doc nil))
175 (let ((elem (assq var (cdr c-lang-variable-inits))))
176 (if elem
177 (setcdr elem (list val doc))
178 (setcdr c-lang-variable-inits-tail (list (list var val doc)))
179 (setq c-lang-variable-inits-tail (cdr c-lang-variable-inits-tail))))
181 ;; Return the symbol, like the other def* forms.
182 `',var)
184 (defmacro c-lang-setvar (var val)
185 "Causes the variable VAR to be made buffer local and to get set to the
186 value VAL. VAL is evaluated and assigned at mode initialization. More
187 precisely, VAL is evaluated and bound to VAR when the result from the
188 macro `c-init-language-vars' is evaluated. VAR is typically a standard
189 Emacs variable like `comment-start'.
191 `c-lang-const' is typically used in VAL to get the right value for the
192 language being initialized, and such calls will be macro expanded to
193 the evaluated constant value at compile time."
194 (let ((elem (assq var (cdr c-emacs-variable-inits))))
195 (if elem
196 (setcdr elem (list val)) ; Maybe remove "list", sometime. 2006-07-19
197 (setcdr c-emacs-variable-inits-tail (list (list var val)))
198 (setq c-emacs-variable-inits-tail (cdr c-emacs-variable-inits-tail))))
200 ;; Return the symbol, like the other def* forms.
201 `',var)
203 (put 'c-lang-defvar 'lisp-indent-function 'defun)
204 ; (eval-after-load "edebug" ; 2006-07-09: def-edebug-spec is now in subr.el.
206 (def-edebug-spec c-lang-defvar
207 (&define name def-form &optional stringp)) ;)
209 ;; Suppress "might not be defined at runtime" warning.
210 ;; This file is only used when compiling other cc files.
211 (declare-function delete-duplicates "cl-seq" (cl-seq &rest cl-keys))
212 (declare-function mapcan "cl-extra" (cl-func cl-seq &rest cl-rest))
213 (declare-function cl-macroexpand-all "cl-extra" (form &optional env))
215 (eval-and-compile
216 ;; Some helper functions used when building the language constants.
218 (defun c-filter-ops (ops opgroup-filter op-filter &optional xlate)
219 ;; Extract a subset of the operators in the list OPS in a DWIM:ey
220 ;; way. The return value is a plain list of operators:
222 ;; OPS either has the structure of `c-operators', is a single
223 ;; group in `c-operators', or is a plain list of operators.
225 ;; OPGROUP-FILTER specifies how to select the operator groups. It
226 ;; can be t to choose all groups, a list of group type symbols
227 ;; (such as 'prefix) to accept, or a function which will be called
228 ;; with the group symbol for each group and should return non-nil
229 ;; if that group is to be included.
231 ;; If XLATE is given, it's a function which is called for each
232 ;; matching operator and its return value is collected instead.
233 ;; If it returns a list, the elements are spliced directly into
234 ;; the final result, which is returned as a list with duplicates
235 ;; removed using `equal'.
237 ;; `c-mode-syntax-table' for the current mode is in effect during
238 ;; the whole procedure.
239 (unless (listp (car-safe ops))
240 (setq ops (list ops)))
241 (cond ((eq opgroup-filter t)
242 (setq opgroup-filter (lambda (opgroup) t)))
243 ((not (functionp opgroup-filter))
244 (setq opgroup-filter `(lambda (opgroup)
245 (memq opgroup ',opgroup-filter)))))
246 (cond ((eq op-filter t)
247 (setq op-filter (lambda (op) t)))
248 ((stringp op-filter)
249 (setq op-filter `(lambda (op)
250 (string-match ,op-filter op)))))
251 (unless xlate
252 (setq xlate 'identity))
253 (c-with-syntax-table (c-lang-const c-mode-syntax-table)
254 (delete-duplicates
255 (mapcan (lambda (opgroup)
256 (when (if (symbolp (car opgroup))
257 (when (funcall opgroup-filter (car opgroup))
258 (setq opgroup (cdr opgroup))
261 (mapcan (lambda (op)
262 (when (funcall op-filter op)
263 (let ((res (funcall xlate op)))
264 (if (listp res) res (list res)))))
265 opgroup)))
266 ops)
267 :test 'equal))))
270 ;;; Various mode specific values that aren't language related.
272 (c-lang-defconst c-mode-menu
273 ;; The definition for the mode menu. The menu title is prepended to
274 ;; this before it's fed to `easy-menu-define'.
275 t `(["Comment Out Region" comment-region
276 (c-fn-region-is-active-p)]
277 ["Uncomment Region" (comment-region (region-beginning)
278 (region-end) '(4))
279 (c-fn-region-is-active-p)]
280 ["Indent Expression" c-indent-exp
281 (memq (char-after) '(?\( ?\[ ?\{))]
282 ["Indent Line or Region" c-indent-line-or-region t]
283 ["Fill Comment Paragraph" c-fill-paragraph t]
284 "----"
285 ["Backward Statement" c-beginning-of-statement t]
286 ["Forward Statement" c-end-of-statement t]
287 ,@(when (c-lang-const c-opt-cpp-prefix)
288 ;; Only applicable if there's a cpp preprocessor.
289 `(["Up Conditional" c-up-conditional t]
290 ["Backward Conditional" c-backward-conditional t]
291 ["Forward Conditional" c-forward-conditional t]
292 "----"
293 ["Macro Expand Region" c-macro-expand
294 (c-fn-region-is-active-p)]
295 ["Backslashify" c-backslash-region
296 (c-fn-region-is-active-p)]))
297 "----"
298 ("Style..."
299 ["Set Style..." c-set-style t]
300 ["Show Current Style Name" (message
301 "Style Name: %s"
302 c-indentation-style) t]
303 ["Guess Style from this Buffer" c-guess-buffer-no-install t]
304 ["Install the Last Guessed Style..." c-guess-install
305 (and c-guess-guessed-offsets-alist
306 c-guess-guessed-basic-offset) ]
307 ["View the Last Guessed Style" c-guess-view
308 (and c-guess-guessed-offsets-alist
309 c-guess-guessed-basic-offset) ])
310 "----"
311 ("Toggle..."
312 ["Syntactic indentation" c-toggle-syntactic-indentation
313 :style toggle :selected c-syntactic-indentation]
314 ["Electric mode" c-toggle-electric-state
315 :style toggle :selected c-electric-flag]
316 ["Auto newline" c-toggle-auto-newline
317 :style toggle :selected c-auto-newline]
318 ["Hungry delete" c-toggle-hungry-state
319 :style toggle :selected c-hungry-delete-key]
320 ["Subword mode" subword-mode
321 :style toggle :selected (and (boundp 'subword-mode)
322 subword-mode)])))
325 ;;; Syntax tables.
327 (defun c-populate-syntax-table (table)
328 "Populate the given syntax table as necessary for a C-like language.
329 This includes setting ' and \" as string delimiters, and setting up
330 the comment syntax to handle both line style \"//\" and block style
331 \"/*\" \"*/\" comments."
333 (modify-syntax-entry ?_ "_" table)
334 (modify-syntax-entry ?\\ "\\" table)
335 (modify-syntax-entry ?+ "." table)
336 (modify-syntax-entry ?- "." table)
337 (modify-syntax-entry ?= "." table)
338 (modify-syntax-entry ?% "." table)
339 (modify-syntax-entry ?< "." table)
340 (modify-syntax-entry ?> "." table)
341 (modify-syntax-entry ?& "." table)
342 (modify-syntax-entry ?| "." table)
343 (modify-syntax-entry ?\' "\"" table)
344 (modify-syntax-entry ?\240 "." table)
346 ;; Set up block and line oriented comments. The new C
347 ;; standard mandates both comment styles even in C, so since
348 ;; all languages now require dual comments, we make this the
349 ;; default.
350 (cond
351 ;; XEmacs
352 ((memq '8-bit c-emacs-features)
353 (modify-syntax-entry ?/ ". 1456" table)
354 (modify-syntax-entry ?* ". 23" table))
355 ;; Emacs
356 ((memq '1-bit c-emacs-features)
357 (modify-syntax-entry ?/ ". 124b" table)
358 (modify-syntax-entry ?* ". 23" table))
359 ;; incompatible
360 (t (error "CC Mode is incompatible with this version of Emacs")))
362 (modify-syntax-entry ?\n "> b" table)
363 ;; Give CR the same syntax as newline, for selective-display
364 (modify-syntax-entry ?\^m "> b" table))
366 (c-lang-defconst c-make-mode-syntax-table
367 "Functions that generates the mode specific syntax tables.
368 The syntax tables aren't stored directly since they're quite large."
369 t `(lambda ()
370 (let ((table (make-syntax-table)))
371 (c-populate-syntax-table table)
372 ;; Mode specific syntaxes.
373 ,(cond ((or (c-major-mode-is 'objc-mode) (c-major-mode-is 'java-mode))
374 ;; Let '@' be part of symbols in ObjC to cope with
375 ;; its compiler directives as single keyword tokens.
376 ;; This is then necessary since it's assumed that
377 ;; every keyword is a single symbol.
378 `(modify-syntax-entry ?@ "_" table))
379 ((c-major-mode-is 'pike-mode)
380 `(modify-syntax-entry ?@ "." table)))
381 table)))
383 (c-lang-defconst c-mode-syntax-table
384 ;; The syntax tables in evaluated form. Only used temporarily when
385 ;; the constants in this file are evaluated.
386 t (funcall (c-lang-const c-make-mode-syntax-table)))
388 (c-lang-defconst c++-make-template-syntax-table
389 ;; A variant of `c++-mode-syntax-table' that defines `<' and `>' as
390 ;; parenthesis characters. Used temporarily when template argument
391 ;; lists are parsed. Note that this encourages incorrect parsing of
392 ;; templates since they might contain normal operators that uses the
393 ;; '<' and '>' characters. Therefore this syntax table might go
394 ;; away when CC Mode handles templates correctly everywhere.
395 t nil
396 (java c++) `(lambda ()
397 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table))))
398 (modify-syntax-entry ?< "(>" table)
399 (modify-syntax-entry ?> ")<" table)
400 table)))
401 (c-lang-defvar c++-template-syntax-table
402 (and (c-lang-const c++-make-template-syntax-table)
403 (funcall (c-lang-const c++-make-template-syntax-table))))
405 (c-lang-defconst c-no-parens-syntax-table
406 ;; A variant of the standard syntax table which is used to find matching
407 ;; "<"s and ">"s which have been marked as parens using syntax table
408 ;; properties. The other paren characters (e.g. "{", ")" "]") are given a
409 ;; non-paren syntax here. so that the list commands will work on "< ... >"
410 ;; even when there's unbalanced other parens inside them.
412 ;; This variable is nil for languages which don't have template stuff.
413 t `(lambda ()
414 (if (c-lang-const c-recognize-<>-arglists)
415 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table))))
416 (modify-syntax-entry ?\( "." table)
417 (modify-syntax-entry ?\) "." table)
418 (modify-syntax-entry ?\[ "." table)
419 (modify-syntax-entry ?\] "." table)
420 (modify-syntax-entry ?\{ "." table)
421 (modify-syntax-entry ?\} "." table)
422 table))))
423 (c-lang-defvar c-no-parens-syntax-table
424 (funcall (c-lang-const c-no-parens-syntax-table)))
426 (c-lang-defconst c-identifier-syntax-modifications
427 "A list that describes the modifications that should be done to the
428 mode syntax table to get a syntax table that matches all identifiers
429 and keywords as words.
431 The list is just like the one used in `font-lock-defaults': Each
432 element is a cons where the car is the character to modify and the cdr
433 the new syntax, as accepted by `modify-syntax-entry'."
434 ;; The $ character is not allowed in most languages (one exception
435 ;; is Java which allows it for legacy reasons) but we still classify
436 ;; it as an identifier character since it's often used in various
437 ;; machine generated identifiers.
438 t '((?_ . "w") (?$ . "w"))
439 (objc java) (append '((?@ . "w"))
440 (c-lang-const c-identifier-syntax-modifications))
441 awk '((?_ . "w")))
442 (c-lang-defvar c-identifier-syntax-modifications
443 (c-lang-const c-identifier-syntax-modifications))
445 (c-lang-defvar c-identifier-syntax-table
446 (let ((table (copy-syntax-table (c-mode-var "mode-syntax-table")))
447 (mods c-identifier-syntax-modifications)
448 mod)
449 (while mods
450 (setq mod (car mods)
451 mods (cdr mods))
452 (modify-syntax-entry (car mod) (cdr mod) table))
453 table)
454 "Syntax table built on the mode syntax table but additionally
455 classifies symbol constituents like '_' and '$' as word constituents,
456 so that all identifiers are recognized as words.")
458 (c-lang-defconst c-get-state-before-change-functions
459 ;; For documentation see the following c-lang-defvar of the same name.
460 ;; The value here may be a list of functions or a single function.
461 t nil
462 c++ '(c-extend-region-for-CPP c-before-change-check-<>-operators)
463 (c objc) 'c-extend-region-for-CPP
464 ;; java 'c-before-change-check-<>-operators
465 awk 'c-awk-record-region-clear-NL)
466 (c-lang-defvar c-get-state-before-change-functions
467 (let ((fs (c-lang-const c-get-state-before-change-functions)))
468 (if (listp fs)
470 (list fs)))
471 "If non-nil, a list of functions called from c-before-change-hook.
472 Typically these will record enough state to allow
473 `c-before-font-lock-function' to extend the region to fontify,
474 and may do such things as removing text-properties which must be
475 recalculated.
477 These functions will be run in the order given. Each of them
478 takes 2 parameters, the BEG and END supplied to every
479 before-change function; on entry, the buffer will have been
480 widened and match-data will have been saved; point is undefined
481 on both entry and exit; the return value is ignored.
483 The functions are called even when font locking isn't enabled.
485 When the mode is initialized, the functions are called with
486 parameters \(point-min) and \(point-max).")
488 (c-lang-defconst c-before-font-lock-functions
489 ;; For documentation see the following c-lang-defvar of the same name.
490 ;; The value here may be a list of functions or a single function.
491 t 'c-set-fl-decl-start
492 (c c++ objc) '(c-neutralize-syntax-in-and-mark-CPP c-set-fl-decl-start)
493 awk 'c-awk-extend-and-syntax-tablify-region)
494 (c-lang-defvar c-before-font-lock-functions
495 (let ((fs (c-lang-const c-before-font-lock-functions)))
496 (if (listp fs)
498 (list fs)))
499 "If non-nil, a list of functions called just before font locking.
500 Typically they will extend the region about to be fontified \(see
501 below) and will set `syntax-table' text properties on the region.
503 These functions will be run in the order given. Each of them
504 takes 3 parameters, the BEG, END, and OLD-LEN supplied to every
505 after-change function; point is undefined on both entry and exit;
506 on entry, the buffer will have been widened and match-data will
507 have been saved; the return value is ignored.
509 The functions may extend the region to be fontified by setting the
510 buffer local variables c-new-BEG and c-new-END.
512 The functions are called even when font locking is disabled.
514 When the mode is initialized, these functions are called with
515 parameters \(point-min), \(point-max) and <buffer size>.")
518 ;;; Syntactic analysis ("virtual semicolons") for line-oriented languages (AWK).
519 (c-lang-defconst c-at-vsemi-p-fn
520 "Contains a function \"Is there a virtual semicolon at POS or point?\".
521 Such a function takes one optional parameter, a buffer position (defaults to
522 point), and returns nil or t. This variable contains nil for languages which
523 don't have EOL terminated statements. "
524 t nil
525 (c c++ objc) 'c-at-macro-vsemi-p
526 awk 'c-awk-at-vsemi-p)
527 (c-lang-defvar c-at-vsemi-p-fn (c-lang-const c-at-vsemi-p-fn))
529 (c-lang-defconst c-vsemi-status-unknown-p-fn
530 "Contains a function \"are we unsure whether there is a virtual semicolon on this line?\".
531 The (admittedly kludgy) purpose of such a function is to prevent an infinite
532 recursion in c-beginning-of-statement-1 when point starts at a `while' token.
533 The function MUST NOT UNDER ANY CIRCUMSTANCES call c-beginning-of-statement-1,
534 even indirectly. This variable contains nil for languages which don't have
535 EOL terminated statements."
536 t nil
537 (c c++ objc) 'c-macro-vsemi-status-unknown-p
538 awk 'c-awk-vsemi-status-unknown-p)
539 (c-lang-defvar c-vsemi-status-unknown-p-fn
540 (c-lang-const c-vsemi-status-unknown-p-fn))
543 ;;; Lexer-level syntax (identifiers, tokens etc).
545 (c-lang-defconst c-has-bitfields
546 "Whether the language has bitfield declarations."
547 t nil
548 (c c++ objc) t)
549 (c-lang-defvar c-has-bitfields (c-lang-const c-has-bitfields))
551 (c-lang-defconst c-symbol-start
552 "Regexp that matches the start of a symbol, i.e. any identifier or
553 keyword. It's unspecified how far it matches. Does not contain a \\|
554 operator at the top level."
555 t (concat "[" c-alpha "_]")
556 java (concat "[" c-alpha "_@]")
557 objc (concat "[" c-alpha "@]")
558 pike (concat "[" c-alpha "_`]"))
559 (c-lang-defvar c-symbol-start (c-lang-const c-symbol-start))
561 (c-lang-defconst c-symbol-chars
562 "Set of characters that can be part of a symbol.
563 This is of the form that fits inside [ ] in a regexp."
564 ;; Pike note: With the backquote identifiers this would include most
565 ;; operator chars too, but they are handled with other means instead.
566 t (concat c-alnum "_$")
567 objc (concat c-alnum "_$@"))
568 (c-lang-defvar c-symbol-chars (c-lang-const c-symbol-chars))
570 (c-lang-defconst c-symbol-key
571 "Regexp matching identifiers and keywords (with submatch 0). Assumed
572 to match if `c-symbol-start' matches on the same position."
573 t (concat (c-lang-const c-symbol-start)
574 "[" (c-lang-const c-symbol-chars) "]*")
575 pike (concat
576 ;; Use the value from C here since the operator backquote is
577 ;; covered by the other alternative.
578 (c-lang-const c-symbol-key c)
579 "\\|"
580 (c-make-keywords-re nil
581 (c-lang-const c-overloadable-operators))))
582 (c-lang-defvar c-symbol-key (c-lang-const c-symbol-key))
584 (c-lang-defconst c-symbol-key-depth
585 ;; Number of regexp grouping parens in `c-symbol-key'.
586 t (regexp-opt-depth (c-lang-const c-symbol-key)))
588 (c-lang-defconst c-nonsymbol-chars
589 "This is the set of chars that can't be part of a symbol, i.e. the
590 negation of `c-symbol-chars'."
591 t (concat "^" (c-lang-const c-symbol-chars)))
592 (c-lang-defvar c-nonsymbol-chars (c-lang-const c-nonsymbol-chars))
594 (c-lang-defconst c-nonsymbol-key
595 "Regexp that matches any character that can't be part of a symbol.
596 It's usually appended to other regexps to avoid matching a prefix.
597 It's assumed to not contain any submatchers."
598 ;; The same thing regarding Unicode identifiers applies here as to
599 ;; `c-symbol-key'.
600 t (concat "[" (c-lang-const c-nonsymbol-chars) "]"))
602 (c-lang-defconst c-identifier-ops
603 "The operators that make up fully qualified identifiers. nil in
604 languages that don't have such things. See `c-operators' for a
605 description of the format. Binary operators can concatenate symbols,
606 e.g. \"::\" in \"A::B::C\". Prefix operators can precede identifiers,
607 e.g. \"~\" in \"~A::B\". Other types of operators aren't supported.
609 This value is by default merged into `c-operators'."
610 t nil
611 c++ '((prefix "~" "??-" "compl")
612 (right-assoc "::")
613 (prefix "::"))
614 ;; Java has "." to concatenate identifiers but it's also used for
615 ;; normal indexing. There's special code in the Java font lock
616 ;; rules to fontify qualified identifiers based on the standard
617 ;; naming conventions. We still define "." here to make
618 ;; `c-forward-name' move over as long names as possible which is
619 ;; necessary to e.g. handle throws clauses correctly.
620 java '((left-assoc "."))
621 idl '((left-assoc "::")
622 (prefix "::"))
623 pike '((left-assoc "::")
624 (prefix "::")
625 (left-assoc ".")))
627 (c-lang-defconst c-opt-identifier-concat-key
628 ;; Appendable adorned regexp matching the operators that join
629 ;; symbols to fully qualified identifiers, or nil in languages that
630 ;; don't have such things.
632 ;; This was a docstring constant in 5.30. It still works but is now
633 ;; considered internal - change `c-identifier-ops' instead.
634 t (let ((ops (c-filter-ops (c-lang-const c-identifier-ops)
635 '(left-assoc right-assoc)
636 t)))
637 (when ops
638 (c-make-keywords-re 'appendable ops))))
639 (c-lang-defvar c-opt-identifier-concat-key
640 (c-lang-const c-opt-identifier-concat-key)
641 'dont-doc)
643 (c-lang-defconst c-opt-identifier-concat-key-depth
644 ;; Number of regexp grouping parens in `c-opt-identifier-concat-key'.
645 t (regexp-opt-depth (c-lang-const c-opt-identifier-concat-key)))
647 (c-lang-defconst c-opt-identifier-prefix-key
648 ;; Appendable adorned regexp matching operators that might precede
649 ;; an identifier and that are part of the identifier in that case.
650 ;; nil in languages without such things.
651 t (let ((ops (c-filter-ops (c-lang-const c-identifier-ops)
652 '(prefix)
653 t)))
654 (when ops
655 (c-make-keywords-re 'appendable ops))))
657 (c-lang-defconst c-after-id-concat-ops
658 "Operators that can occur after a binary operator on `c-identifier-ops'
659 in identifiers. nil in languages that don't have such things.
661 Operators here should also have appropriate entries in `c-operators' -
662 it's not taken care of by default."
663 t nil
664 ;; '~' for destructors in C++, '*' for member pointers.
665 c++ '("~" "*")
666 ;; In Java we recognize '*' to deal with "foo.bar.*" that can occur
667 ;; in import declarations. (This will also match bogus things like
668 ;; "foo.*bar" but we don't bother.)
669 java '("*"))
671 (c-lang-defconst c-opt-after-id-concat-key
672 ;; Regexp that must match the token after
673 ;; `c-opt-identifier-concat-key' for it to be considered an
674 ;; identifier concatenation operator (which e.g. causes the
675 ;; preceding identifier to be fontified as a reference). Assumed to
676 ;; be a string if `c-opt-identifier-concat-key' is.
678 ;; This was a docstring constant in 5.30. It still works but is now
679 ;; considered internal - change `c-after-id-concat-ops' instead.
680 t (concat (c-lang-const c-symbol-start)
681 (if (c-lang-const c-after-id-concat-ops)
682 (concat "\\|" (c-make-keywords-re 'appendable
683 (c-lang-const c-after-id-concat-ops)))
684 "")))
686 (c-lang-defconst c-identifier-start
687 "Regexp that matches the start of an (optionally qualified) identifier.
688 It should also match all keywords. It's unspecified how far it
689 matches."
690 t (concat (c-lang-const c-symbol-start)
691 (if (c-lang-const c-opt-identifier-prefix-key)
692 (concat "\\|"
693 (c-lang-const c-opt-identifier-prefix-key))
694 "")))
695 (c-lang-defvar c-identifier-start (c-lang-const c-identifier-start))
697 (c-lang-defconst c-identifier-key
698 "Regexp matching a fully qualified identifier, like \"A::B::c\" in
699 C++. It does not recognize the full range of syntactic whitespace
700 between the tokens; `c-forward-name' has to be used for that. It
701 should also not match identifiers containing parenthesis groupings,
702 e.g. identifiers with template arguments such as \"A<X,Y>\" in C++."
703 ;; This regexp is more complex than strictly necessary to ensure
704 ;; that it can be matched with a minimum of backtracking.
705 t (concat (if (c-lang-const c-opt-identifier-prefix-key)
706 (concat
707 "\\("
708 (c-lang-const c-opt-identifier-prefix-key)
709 (c-lang-const c-simple-ws) "*"
710 "\\)?")
712 "\\(" (c-lang-const c-symbol-key) "\\)"
713 (if (c-lang-const c-opt-identifier-concat-key)
714 (concat
715 "\\("
716 (c-lang-const c-simple-ws) "*"
717 (c-lang-const c-opt-identifier-concat-key)
718 (c-lang-const c-simple-ws) "*"
719 (if (c-lang-const c-after-id-concat-ops)
720 (concat
721 "\\("
722 (c-make-keywords-re 'appendable
723 (c-lang-const c-after-id-concat-ops))
724 (concat
725 ;; For flexibility, consider the symbol match
726 ;; optional if we've hit a
727 ;; `c-after-id-concat-ops' operator. This is
728 ;; also necessary to handle the "*" that can
729 ;; end import declaration identifiers in Java.
730 "\\("
731 (c-lang-const c-simple-ws) "*"
732 "\\(" (c-lang-const c-symbol-key) "\\)"
733 "\\)?")
734 "\\|"
735 "\\(" (c-lang-const c-symbol-key) "\\)"
736 "\\)")
737 (concat "\\(" (c-lang-const c-symbol-key) "\\)"))
738 "\\)*")
739 "")))
740 (c-lang-defvar c-identifier-key (c-lang-const c-identifier-key))
742 (c-lang-defconst c-identifier-last-sym-match
743 ;; This was a docstring constant in 5.30 but it's no longer used.
744 ;; It's only kept to avoid breaking third party code.
746 ;; Used to identify the submatch in `c-identifier-key' that
747 ;; surrounds the last symbol in the qualified identifier. It's a
748 ;; list of submatch numbers, of which the first that has a match is
749 ;; taken. It's assumed that at least one does when the regexp has
750 ;; matched.
751 t nil)
753 (c-lang-defconst c-string-escaped-newlines
754 "Set if the language support backslash escaped newlines inside string
755 literals."
756 t nil
757 (c c++ objc pike) t)
758 (c-lang-defvar c-string-escaped-newlines
759 (c-lang-const c-string-escaped-newlines))
761 (c-lang-defconst c-multiline-string-start-char
762 "Set if the language supports multiline string literals without escaped
763 newlines. If t, all string literals are multiline. If a character,
764 only literals where the open quote is immediately preceded by that
765 literal are multiline."
766 t nil
767 pike ?#)
768 (c-lang-defvar c-multiline-string-start-char
769 (c-lang-const c-multiline-string-start-char))
771 (c-lang-defconst c-opt-cpp-symbol
772 "The symbol which starts preprocessor constructs when in the margin."
773 t "#"
774 (java awk) nil)
775 (c-lang-defvar c-opt-cpp-symbol (c-lang-const c-opt-cpp-symbol))
777 (c-lang-defconst c-opt-cpp-prefix
778 "Regexp matching the prefix of a cpp directive in the languages that
779 normally use that macro preprocessor. Tested at bol or at boi.
780 Assumed to not contain any submatches or \\| operators."
781 ;; TODO (ACM, 2005-04-01). Amend the following to recognize escaped NLs;
782 ;; amend all uses of c-opt-cpp-prefix which count regexp-depth.
783 t "\\s *#\\s *"
784 (java awk) nil)
785 (c-lang-defvar c-opt-cpp-prefix (c-lang-const c-opt-cpp-prefix))
787 (c-lang-defconst c-anchored-cpp-prefix
788 "Regexp matching the prefix of a cpp directive anchored to BOL,
789 in the languages that have a macro preprocessor."
790 t (if (c-lang-const c-opt-cpp-prefix)
791 (concat "^" (c-lang-const c-opt-cpp-prefix))))
792 (c-lang-defvar c-anchored-cpp-prefix (c-lang-const c-anchored-cpp-prefix))
794 (c-lang-defconst c-opt-cpp-start
795 "Regexp matching the prefix of a cpp directive including the directive
796 name, or nil in languages without preprocessor support. The first
797 submatch surrounds the directive name."
798 t (if (c-lang-const c-opt-cpp-prefix)
799 (concat (c-lang-const c-opt-cpp-prefix)
800 "\\([" c-alnum "]+\\)"))
801 ;; Pike, being a scripting language, recognizes hash-bangs too.
802 pike (concat (c-lang-const c-opt-cpp-prefix)
803 "\\([" c-alnum "]+\\|!\\)"))
804 (c-lang-defvar c-opt-cpp-start (c-lang-const c-opt-cpp-start))
806 (c-lang-defconst c-cpp-message-directives
807 "List of cpp directives (without the prefix) that are followed by a
808 string message."
809 t (if (c-lang-const c-opt-cpp-prefix)
810 '("error"))
811 (c c++ objc pike) '("error" "warning"))
813 (c-lang-defconst c-cpp-include-directives
814 "List of cpp directives (without the prefix) that are followed by a
815 file name in angle brackets or quotes."
816 t (if (c-lang-const c-opt-cpp-prefix)
817 '("include"))
818 objc '("include" "import"))
820 (c-lang-defconst c-opt-cpp-macro-define
821 "Cpp directive (without the prefix) that is followed by a macro
822 definition, or nil if the language doesn't have any."
823 t (if (c-lang-const c-opt-cpp-prefix)
824 "define"))
825 (c-lang-defvar c-opt-cpp-macro-define
826 (c-lang-const c-opt-cpp-macro-define))
828 (c-lang-defconst c-opt-cpp-macro-define-start
829 ;; Regexp matching everything up to the macro body of a cpp define, or the
830 ;; end of the logical line if there is none. Submatch 1 is the name of the
831 ;; macro. Set if c-opt-cpp-macro-define is.
832 t (if (c-lang-const c-opt-cpp-macro-define)
833 (concat (c-lang-const c-opt-cpp-prefix)
834 (c-lang-const c-opt-cpp-macro-define)
835 "[ \t]+\\(\\(\\sw\\|_\\)+\\)\\(\([^\)]*\)\\)?"
836 ;; ^ ^ #defined name
837 "\\([ \t]\\|\\\\\n\\)*")))
838 (c-lang-defvar c-opt-cpp-macro-define-start
839 (c-lang-const c-opt-cpp-macro-define-start))
841 (c-lang-defconst c-opt-cpp-macro-define-id
842 ;; Regexp matching everything up to the end of the identifier defined
843 ;; by a cpp define.
844 t (if (c-lang-const c-opt-cpp-macro-define)
845 (concat (c-lang-const c-opt-cpp-prefix) ; #
846 (c-lang-const c-opt-cpp-macro-define) ; define
847 "[ \t]+\\(\\sw\\|_\\)+")))
848 (c-lang-defvar c-opt-cpp-macro-define-id
849 (c-lang-const c-opt-cpp-macro-define-id))
851 (c-lang-defconst c-cpp-expr-directives
852 "List of cpp directives (without the prefix) that are followed by an
853 expression."
854 t (if (c-lang-const c-opt-cpp-prefix)
855 '("if" "elif")))
857 (c-lang-defconst c-cpp-expr-intro-re
858 "Regexp which matches the start of a CPP directive which contains an
859 expression, or nil if there aren't any in the language."
860 t (if (c-lang-const c-cpp-expr-directives)
861 (concat
862 (c-lang-const c-opt-cpp-prefix)
863 (c-make-keywords-re t (c-lang-const c-cpp-expr-directives)))))
864 (c-lang-defvar c-cpp-expr-intro-re
865 (c-lang-const c-cpp-expr-intro-re))
867 (c-lang-defconst c-cpp-expr-functions
868 "List of functions in cpp expressions."
869 t (if (c-lang-const c-opt-cpp-prefix)
870 '("defined"))
871 pike '("defined" "efun" "constant"))
873 (c-lang-defconst c-assignment-operators
874 "List of all assignment operators."
875 t '("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=")
876 java (append (c-lang-const c-assignment-operators)
877 '(">>>="))
878 c++ (append (c-lang-const c-assignment-operators)
879 '("and_eq" "or_eq" "xor_eq" "??!=" "??'="))
880 idl nil)
882 (c-lang-defconst c-operators
883 "List describing all operators, along with their precedence and
884 associativity. The order in the list corresponds to the precedence of
885 the operators: The operators in each element are a group with the same
886 precedence, and the group has higher precedence than the groups in all
887 following elements. The car of each element describes the type of the
888 operator group, and the cdr is a list of the operator tokens in it.
889 The operator group types are:
891 'prefix Unary prefix operators.
892 'postfix Unary postfix operators.
893 'postfix-if-paren
894 Unary postfix operators if and only if the chars have
895 parenthesis syntax.
896 'left-assoc Binary left associative operators (i.e. a+b+c means (a+b)+c).
897 'right-assoc Binary right associative operators (i.e. a=b=c means a=(b=c)).
898 'right-assoc-sequence
899 Right associative operator that constitutes of a
900 sequence of tokens that separate expressions. All the
901 tokens in the group are in this case taken as
902 describing the sequence in one such operator, and the
903 order between them is therefore significant.
905 Operators containing a character with paren syntax are taken to match
906 with a corresponding open/close paren somewhere else. A postfix
907 operator with close paren syntax is taken to end a postfix expression
908 started somewhere earlier, rather than start a new one at point. Vice
909 versa for prefix operators with open paren syntax.
911 Note that operators like \".\" and \"->\" which in language references
912 often are described as postfix operators are considered binary here,
913 since CC Mode treats every identifier as an expression."
915 ;; There's currently no code in CC Mode that exploit all the info
916 ;; in this variable; precedence, associativity etc are present as a
917 ;; preparation for future work.
919 t `(;; Preprocessor.
920 ,@(when (c-lang-const c-opt-cpp-prefix)
921 `((prefix "#"
922 ,@(when (c-major-mode-is '(c-mode c++-mode))
923 '("%:" "??=")))
924 (left-assoc "##"
925 ,@(when (c-major-mode-is '(c-mode c++-mode))
926 '("%:%:" "??=??=")))))
928 ;; Primary.
929 ,@(c-lang-const c-identifier-ops)
930 ,@(cond ((or (c-major-mode-is 'c++-mode) (c-major-mode-is 'java-mode))
931 `((postfix-if-paren "<" ">"))) ; Templates.
932 ((c-major-mode-is 'pike-mode)
933 `((prefix "global" "predef")))
934 ((c-major-mode-is 'java-mode)
935 `((prefix "super"))))
937 ;; Postfix.
938 ,@(when (c-major-mode-is 'c++-mode)
939 ;; The following need special treatment.
940 `((prefix "dynamic_cast" "static_cast"
941 "reinterpret_cast" "const_cast" "typeid")))
942 (left-assoc "."
943 ,@(unless (c-major-mode-is 'java-mode)
944 '("->")))
945 (postfix "++" "--" "[" "]" "(" ")"
946 ,@(when (c-major-mode-is '(c-mode c++-mode))
947 '("<:" ":>" "??(" "??)")))
949 ;; Unary.
950 (prefix "++" "--" "+" "-" "!" "~"
951 ,@(when (c-major-mode-is 'c++-mode) '("not" "compl"))
952 ,@(when (c-major-mode-is '(c-mode c++-mode))
953 '("*" "&" "sizeof" "??-"))
954 ,@(when (c-major-mode-is 'objc-mode)
955 '("@selector" "@protocol" "@encode"))
956 ;; The following need special treatment.
957 ,@(cond ((c-major-mode-is 'c++-mode)
958 '("new" "delete"))
959 ((c-major-mode-is 'java-mode)
960 '("new"))
961 ((c-major-mode-is 'pike-mode)
962 '("class" "lambda" "catch" "throw" "gauge")))
963 "(" ")" ; Cast.
964 ,@(when (c-major-mode-is 'pike-mode)
965 '("[" "]"))) ; Type cast.
967 ;; Member selection.
968 ,@(when (c-major-mode-is 'c++-mode)
969 `((left-assoc ".*" "->*")))
971 ;; Multiplicative.
972 (left-assoc "*" "/" "%")
974 ;; Additive.
975 (left-assoc "+" "-")
977 ;; Shift.
978 (left-assoc "<<" ">>"
979 ,@(when (c-major-mode-is 'java-mode)
980 '(">>>")))
982 ;; Relational.
983 (left-assoc "<" ">" "<=" ">="
984 ,@(when (c-major-mode-is 'java-mode)
985 '("instanceof")))
987 ;; Equality.
988 (left-assoc "==" "!="
989 ,@(when (c-major-mode-is 'c++-mode) '("not_eq")))
991 ;; Bitwise and.
992 (left-assoc "&"
993 ,@(when (c-major-mode-is 'c++-mode) '("bitand")))
995 ;; Bitwise exclusive or.
996 (left-assoc "^"
997 ,@(when (c-major-mode-is '(c-mode c++-mode))
998 '("??'"))
999 ,@(when (c-major-mode-is 'c++-mode) '("xor")))
1001 ;; Bitwise or.
1002 (left-assoc "|"
1003 ,@(when (c-major-mode-is '(c-mode c++-mode))
1004 '("??!"))
1005 ,@(when (c-major-mode-is 'c++-mode) '("bitor")))
1007 ;; Logical and.
1008 (left-assoc "&&"
1009 ,@(when (c-major-mode-is 'c++-mode) '("and")))
1011 ;; Logical or.
1012 (left-assoc "||"
1013 ,@(when (c-major-mode-is '(c-mode c++-mode))
1014 '("??!??!"))
1015 ,@(when (c-major-mode-is 'c++-mode) '("or")))
1017 ;; Conditional.
1018 (right-assoc-sequence "?" ":")
1020 ;; Assignment.
1021 (right-assoc ,@(c-lang-const c-assignment-operators))
1023 ;; Exception.
1024 ,@(when (c-major-mode-is 'c++-mode)
1025 '((prefix "throw")))
1027 ;; Sequence.
1028 (left-assoc ","))
1030 ;; IDL got its own definition since it has a much smaller operator
1031 ;; set than the other languages.
1032 idl `(;; Preprocessor.
1033 (prefix "#")
1034 (left-assoc "##")
1035 ;; Primary.
1036 ,@(c-lang-const c-identifier-ops)
1037 ;; Unary.
1038 (prefix "+" "-" "~")
1039 ;; Multiplicative.
1040 (left-assoc "*" "/" "%")
1041 ;; Additive.
1042 (left-assoc "+" "-")
1043 ;; Shift.
1044 (left-assoc "<<" ">>")
1045 ;; And.
1046 (left-assoc "&")
1047 ;; Xor.
1048 (left-assoc "^")
1049 ;; Or.
1050 (left-assoc "|")))
1052 (c-lang-defconst c-operator-list
1053 ;; The operators as a flat list (without duplicates).
1054 t (c-filter-ops (c-lang-const c-operators) t t))
1056 (c-lang-defconst c-overloadable-operators
1057 "List of the operators that are overloadable, in their \"identifier
1058 form\". See also `c-op-identifier-prefix'."
1059 t nil
1060 c++ '("new" "delete" ;; Can be followed by "[]" but we ignore that.
1061 "+" "-" "*" "/" "%"
1062 "^" "??'" "xor" "&" "bitand" "|" "??!" "bitor" "~" "??-" "compl"
1063 "!" "=" "<" ">" "+=" "-=" "*=" "/=" "%=" "^="
1064 "??'=" "xor_eq" "&=" "and_eq" "|=" "??!=" "or_eq"
1065 "<<" ">>" ">>=" "<<=" "==" "!=" "not_eq" "<=" ">="
1066 "&&" "and" "||" "??!??!" "or" "++" "--" "," "->*" "->"
1067 "()" "[]" "<::>" "??(??)")
1068 ;; These work like identifiers in Pike.
1069 pike '("`+" "`-" "`&" "`|" "`^" "`<<" "`>>" "`*" "`/" "`%" "`~"
1070 "`==" "`<" "`>" "`!" "`[]" "`[]=" "`->" "`->=" "`()" "``+"
1071 "``-" "``&" "``|" "``^" "``<<" "``>>" "``*" "``/" "``%"
1072 "`+="))
1074 (c-lang-defconst c-overloadable-operators-regexp
1075 ;; Regexp tested after an "operator" token in C++.
1076 t nil
1077 c++ (c-make-keywords-re nil (c-lang-const c-overloadable-operators)))
1078 (c-lang-defvar c-overloadable-operators-regexp
1079 (c-lang-const c-overloadable-operators-regexp))
1081 (c-lang-defconst c-opt-op-identifier-prefix
1082 "Regexp matching the token before the ones in
1083 `c-overloadable-operators' when operators are specified in their
1084 \"identifier form\". This typically matches \"operator\" in C++ where
1085 operator functions are specified as e.g. \"operator +\". It's nil in
1086 languages without operator functions or where the complete operator
1087 identifier is listed in `c-overloadable-operators'.
1089 This regexp is assumed to not match any non-operator identifier."
1090 t nil
1091 c++ (c-make-keywords-re t '("operator")))
1092 (c-lang-defvar c-opt-op-identifier-prefix
1093 (c-lang-const c-opt-op-identifier-prefix))
1095 ;; Note: the following alias is an old name which was a mis-spelling. It has
1096 ;; been corrected above and throughout cc-engine.el. It will be removed at
1097 ;; some release very shortly in the future. ACM, 2006-04-14.
1098 (defvaralias 'c-opt-op-identitier-prefix 'c-opt-op-identifier-prefix)
1099 (make-obsolete-variable 'c-opt-op-identitier-prefix 'c-opt-op-identifier-prefix
1100 "CC Mode 5.31.4, 2006-04-14")
1102 (c-lang-defconst c-other-op-syntax-tokens
1103 "List of the tokens made up of characters in the punctuation or
1104 parenthesis syntax classes that have uses other than as expression
1105 operators."
1106 t '("{" "}" "(" ")" "[" "]" ";" ":" "," "=" "/*" "*/" "//")
1107 (c c++ pike) (append '("#" "##" ; Used by cpp.
1108 "::" "...")
1109 (c-lang-const c-other-op-syntax-tokens))
1110 (c c++) (append '("*") (c-lang-const c-other-op-syntax-tokens))
1111 c++ (append '("&" "<%" "%>" "<:" ":>" "%:" "%:%:")
1112 (c-lang-const c-other-op-syntax-tokens))
1113 objc (append '("#" "##" ; Used by cpp.
1114 "+" "-") (c-lang-const c-other-op-syntax-tokens))
1115 idl (append '("#" "##") ; Used by cpp.
1116 (c-lang-const c-other-op-syntax-tokens))
1117 pike (append '("..")
1118 (c-lang-const c-other-op-syntax-tokens)
1119 (c-lang-const c-overloadable-operators))
1120 awk '("{" "}" "(" ")" "[" "]" ";" "," "=" "/"))
1122 (c-lang-defconst c-all-op-syntax-tokens
1123 ;; List of all tokens in the punctuation and parenthesis syntax
1124 ;; classes.
1125 t (delete-duplicates (append (c-lang-const c-other-op-syntax-tokens)
1126 (c-lang-const c-operator-list))
1127 :test 'string-equal))
1129 (c-lang-defconst c-nonsymbol-token-char-list
1130 ;; List containing all chars not in the word, symbol or
1131 ;; syntactically irrelevant syntax classes, i.e. all punctuation,
1132 ;; parenthesis and string delimiter chars.
1133 t (c-with-syntax-table (c-lang-const c-mode-syntax-table)
1134 ;; Only go through the chars in the printable ASCII range. No
1135 ;; language so far has 8-bit or widestring operators.
1136 (let (list (char 32))
1137 (while (< char 127)
1138 (or (memq (char-syntax char) '(?w ?_ ?< ?> ?\ ))
1139 (setq list (cons (c-int-to-char char) list)))
1140 (setq char (1+ char)))
1141 list)))
1143 (c-lang-defconst c-nonsymbol-token-regexp
1144 ;; Regexp matching all tokens in the punctuation and parenthesis
1145 ;; syntax classes. Note that this also matches ".", which can start
1146 ;; a float.
1147 t (c-make-keywords-re nil
1148 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1150 "\\`\\(\\s.\\|\\s\(\\|\\s\)\\)+\\'")))
1151 (c-lang-defvar c-nonsymbol-token-regexp
1152 (c-lang-const c-nonsymbol-token-regexp))
1154 (c-lang-defconst c-assignment-op-regexp
1155 ;; Regexp matching all assignment operators and only them. The
1156 ;; beginning of the first submatch is used to detect the end of the
1157 ;; token, along with the end of the whole match.
1158 t (if (c-lang-const c-assignment-operators)
1159 (concat
1160 ;; Need special case for "=" since it's a prefix of "==".
1161 "=\\([^=]\\|$\\)"
1162 "\\|"
1163 (c-make-keywords-re nil
1164 (set-difference (c-lang-const c-assignment-operators)
1165 '("=")
1166 :test 'string-equal)))
1167 "\\<\\>"))
1168 (c-lang-defvar c-assignment-op-regexp
1169 (c-lang-const c-assignment-op-regexp))
1171 (c-lang-defconst c-<>-multichar-token-regexp
1172 ;; Regexp matching all tokens containing "<" or ">" which are longer
1173 ;; than one char.
1174 t (c-make-keywords-re nil
1175 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1177 ".[<>]\\|[<>].")))
1178 (c-lang-defvar c-<>-multichar-token-regexp
1179 (c-lang-const c-<>-multichar-token-regexp))
1181 (c-lang-defconst c-<-op-cont-regexp
1182 ;; Regexp matching the second and subsequent characters of all
1183 ;; multicharacter tokens that begin with "<".
1184 t (c-make-keywords-re nil
1185 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1187 "\\`<."
1188 (lambda (op) (substring op 1)))))
1190 (c-lang-defvar c-<-op-cont-regexp (c-lang-const c-<-op-cont-regexp))
1192 (c-lang-defconst c->-op-cont-regexp
1193 ;; Regexp matching the second and subsequent characters of all
1194 ;; multicharacter tokens that begin with ">".
1195 t (c-make-keywords-re nil
1196 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1198 "\\`>."
1199 (lambda (op) (substring op 1))))
1200 java (c-make-keywords-re nil
1201 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1203 "\\`>[^>]\\|\\`>>[^>]"
1204 (lambda (op) (substring op 1)))))
1206 (c-lang-defvar c->-op-cont-regexp (c-lang-const c->-op-cont-regexp))
1208 (c-lang-defconst c-stmt-delim-chars
1209 ;; The characters that should be considered to bound statements. To
1210 ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to
1211 ;; begin with "^" to negate the set. If ? : operators should be
1212 ;; detected then the string must end with "?:".
1213 t "^;{}?:")
1214 (c-lang-defvar c-stmt-delim-chars (c-lang-const c-stmt-delim-chars))
1216 (c-lang-defconst c-stmt-delim-chars-with-comma
1217 ;; Variant of `c-stmt-delim-chars' that additionally contains ','.
1218 t "^;,{}?:")
1219 (c-lang-defvar c-stmt-delim-chars-with-comma
1220 (c-lang-const c-stmt-delim-chars-with-comma))
1223 ;;; Syntactic whitespace.
1225 (c-lang-defconst c-simple-ws
1226 "Regexp matching an ordinary whitespace character.
1227 Does not contain a \\| operator at the top level."
1228 ;; "\\s " is not enough since it doesn't match line breaks.
1229 t "\\(\\s \\|[\n\r]\\)")
1231 (c-lang-defconst c-simple-ws-depth
1232 ;; Number of regexp grouping parens in `c-simple-ws'.
1233 t (regexp-opt-depth (c-lang-const c-simple-ws)))
1235 (c-lang-defconst c-line-comment-starter
1236 "String that starts line comments, or nil if such don't exist.
1237 Line comments are always terminated by newlines. At least one of
1238 `c-block-comment-starter' and this one is assumed to be set.
1240 Note that it's currently not enough to set this to support a new
1241 comment style. Other stuff like the syntax table must also be set up
1242 properly."
1243 t "//"
1244 awk "#")
1245 (c-lang-defvar c-line-comment-starter (c-lang-const c-line-comment-starter))
1247 (c-lang-defconst c-block-comment-starter
1248 "String that starts block comments, or nil if such don't exist.
1249 Block comments are ended by `c-block-comment-ender', which is assumed
1250 to be set if this is. At least one of `c-line-comment-starter' and
1251 this one is assumed to be set.
1253 Note that it's currently not enough to set this to support a new
1254 comment style. Other stuff like the syntax table must also be set up
1255 properly."
1256 t "/*"
1257 awk nil)
1259 (c-lang-defconst c-block-comment-ender
1260 "String that ends block comments, or nil if such don't exist.
1262 Note that it's currently not enough to set this to support a new
1263 comment style. Other stuff like the syntax table must also be set up
1264 properly."
1265 t "*/"
1266 awk nil)
1268 (c-lang-defconst c-comment-start-regexp
1269 ;; Regexp to match the start of any type of comment.
1270 t (let ((re (c-make-keywords-re nil
1271 (list (c-lang-const c-line-comment-starter)
1272 (c-lang-const c-block-comment-starter)))))
1273 (if (memq 'gen-comment-delim c-emacs-features)
1274 (concat re "\\|\\s!")
1275 re)))
1276 (c-lang-defvar c-comment-start-regexp (c-lang-const c-comment-start-regexp))
1278 (c-lang-defconst c-block-comment-start-regexp
1279 ;; Regexp which matches the start of a block comment (if such exists in the
1280 ;; language)
1281 t (if (c-lang-const c-block-comment-starter)
1282 (regexp-quote (c-lang-const c-block-comment-starter))
1283 "\\<\\>"))
1284 (c-lang-defvar c-block-comment-start-regexp
1285 (c-lang-const c-block-comment-start-regexp))
1287 (c-lang-defconst c-line-comment-start-regexp
1288 ;; Regexp which matches the start of a line comment (if such exists in the
1289 ;; language; it does in all 7 CC Mode languages).
1290 t (if (c-lang-const c-line-comment-starter)
1291 (regexp-quote (c-lang-const c-line-comment-starter))
1292 "\\<\\>"))
1293 (c-lang-defvar c-line-comment-start-regexp
1294 (c-lang-const c-line-comment-start-regexp))
1296 (c-lang-defconst c-literal-start-regexp
1297 ;; Regexp to match the start of comments and string literals.
1298 t (concat (c-lang-const c-comment-start-regexp)
1299 "\\|"
1300 (if (memq 'gen-string-delim c-emacs-features)
1301 "\"|"
1302 "\"")))
1303 (c-lang-defvar c-literal-start-regexp (c-lang-const c-literal-start-regexp))
1305 (c-lang-defconst c-doc-comment-start-regexp
1306 "Regexp to match the start of documentation comments."
1307 t "\\<\\>"
1308 ;; From font-lock.el: `doxygen' uses /*! while others use /**.
1309 (c c++ objc) "/\\*[*!]"
1310 java "/\\*\\*"
1311 pike "/[/*]!")
1312 (c-lang-defvar c-doc-comment-start-regexp
1313 (c-lang-const c-doc-comment-start-regexp))
1315 (c-lang-defconst comment-start
1316 "String that starts comments inserted with M-; etc.
1317 `comment-start' is initialized from this."
1318 ;; Default: Prefer line comments to block comments, and pad with a space.
1319 t (concat (or (c-lang-const c-line-comment-starter)
1320 (c-lang-const c-block-comment-starter))
1321 " ")
1322 ;; In C we still default to the block comment style since line
1323 ;; comments aren't entirely portable.
1324 c "/* ")
1325 (c-lang-setvar comment-start (c-lang-const comment-start))
1327 (c-lang-defconst comment-end
1328 "String that ends comments inserted with M-; etc.
1329 `comment-end' is initialized from this."
1330 ;; Default: Use block comment style if comment-start uses block
1331 ;; comments, and pad with a space in that case.
1332 t (if (string-match (concat "\\`\\("
1333 (c-lang-const c-block-comment-start-regexp)
1334 "\\)")
1335 (c-lang-const comment-start))
1336 (concat " " (c-lang-const c-block-comment-ender))
1337 ""))
1338 (c-lang-setvar comment-end (c-lang-const comment-end))
1340 (c-lang-defconst comment-start-skip
1341 "Regexp to match the start of a comment plus everything up to its body.
1342 `comment-start-skip' is initialized from this."
1343 ;; Default: Allow the last char of the comment starter(s) to be
1344 ;; repeated, then allow any amount of horizontal whitespace.
1345 t (concat "\\("
1346 (c-concat-separated
1347 (mapcar (lambda (cs)
1348 (when cs
1349 (concat (regexp-quote cs) "+")))
1350 (list (c-lang-const c-line-comment-starter)
1351 (c-lang-const c-block-comment-starter)))
1352 "\\|")
1353 "\\)\\s *"))
1354 (c-lang-setvar comment-start-skip (c-lang-const comment-start-skip))
1356 (c-lang-defconst c-syntactic-ws-start
1357 ;; Regexp matching any sequence that can start syntactic whitespace.
1358 ;; The only uncertain case is '#' when there are cpp directives.
1359 t (concat "\\s \\|"
1360 (c-make-keywords-re nil
1361 (append (list (c-lang-const c-line-comment-starter)
1362 (c-lang-const c-block-comment-starter)
1363 (when (c-lang-const c-opt-cpp-prefix)
1364 "#"))
1365 '("\n" "\r")))
1366 "\\|\\\\[\n\r]"
1367 (when (memq 'gen-comment-delim c-emacs-features)
1368 "\\|\\s!")))
1369 (c-lang-defvar c-syntactic-ws-start (c-lang-const c-syntactic-ws-start))
1371 (c-lang-defconst c-syntactic-ws-end
1372 ;; Regexp matching any single character that might end syntactic whitespace.
1373 t (concat "\\s \\|"
1374 (c-make-keywords-re nil
1375 (append (when (c-lang-const c-block-comment-ender)
1376 (list
1377 (string
1378 (elt (c-lang-const c-block-comment-ender)
1379 (1- (length
1380 (c-lang-const c-block-comment-ender)))))))
1381 '("\n" "\r")))
1382 (when (memq 'gen-comment-delim c-emacs-features)
1383 "\\|\\s!")))
1384 (c-lang-defvar c-syntactic-ws-end (c-lang-const c-syntactic-ws-end))
1386 (c-lang-defconst c-unterminated-block-comment-regexp
1387 ;; Regexp matching an unterminated block comment that doesn't
1388 ;; contain line breaks, or nil in languages without block comments.
1389 ;; Does not contain a \| operator at the top level.
1390 t (when (c-lang-const c-block-comment-starter)
1391 (concat
1392 (regexp-quote (c-lang-const c-block-comment-starter))
1393 ;; It's messy to cook together a regexp that matches anything
1394 ;; but c-block-comment-ender.
1395 (let ((end (c-lang-const c-block-comment-ender)))
1396 (cond ((= (length end) 1)
1397 (concat "[^" end "\n\r]*"))
1398 ((= (length end) 2)
1399 (concat "[^" (substring end 0 1) "\n\r]*"
1400 "\\("
1401 (regexp-quote (substring end 0 1)) "+"
1402 "[^"
1403 ;; The quoting rules inside char classes are silly. :P
1404 (cond ((= (elt end 0) (elt end 1))
1405 (concat (substring end 0 1) "\n\r"))
1406 ((= (elt end 1) ?\])
1407 (concat (substring end 1 2) "\n\r"
1408 (substring end 0 1)))
1410 (concat (substring end 0 1) "\n\r"
1411 (substring end 1 2))))
1413 "[^" (substring end 0 1) "\n\r]*"
1414 "\\)*"))
1416 (error "Can't handle a block comment ender of length %s"
1417 (length end))))))))
1419 (c-lang-defconst c-block-comment-regexp
1420 ;; Regexp matching a block comment that doesn't contain line breaks,
1421 ;; or nil in languages without block comments. The reason we don't
1422 ;; allow line breaks is to avoid going very far and risk running out
1423 ;; of regexp stack; this regexp is intended to handle only short
1424 ;; comments that might be put in the middle of limited constructs
1425 ;; like declarations. Does not contain a \| operator at the top
1426 ;; level.
1427 t (when (c-lang-const c-unterminated-block-comment-regexp)
1428 (concat
1429 (c-lang-const c-unterminated-block-comment-regexp)
1430 (let ((end (c-lang-const c-block-comment-ender)))
1431 (cond ((= (length end) 1)
1432 (regexp-quote end))
1433 ((= (length end) 2)
1434 (concat (regexp-quote (substring end 0 1)) "+"
1435 (regexp-quote (substring end 1 2))))
1437 (error "Can't handle a block comment ender of length %s"
1438 (length end))))))))
1440 (c-lang-defconst c-nonwhite-syntactic-ws
1441 ;; Regexp matching a piece of syntactic whitespace that isn't a
1442 ;; sequence of simple whitespace characters. As opposed to
1443 ;; `c-(forward|backward)-syntactic-ws', this doesn't regard cpp
1444 ;; directives as syntactic whitespace.
1445 t (c-concat-separated
1446 (list (when (c-lang-const c-line-comment-starter)
1447 (concat (regexp-quote (c-lang-const c-line-comment-starter))
1448 "[^\n\r]*[\n\r]"))
1449 (c-lang-const c-block-comment-regexp)
1450 "\\\\[\n\r]"
1451 (when (memq 'gen-comment-delim c-emacs-features)
1452 "\\s!\\S!*\\s!"))
1453 "\\|"))
1455 (c-lang-defconst c-syntactic-ws
1456 ;; Regexp matching syntactic whitespace, including possibly the
1457 ;; empty string. As opposed to `c-(forward|backward)-syntactic-ws',
1458 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1459 ;; not contain a \| operator at the top level.
1460 t (concat (c-lang-const c-simple-ws) "*"
1461 "\\("
1462 (concat "\\(" (c-lang-const c-nonwhite-syntactic-ws) "\\)"
1463 (c-lang-const c-simple-ws) "*")
1464 "\\)*"))
1466 (c-lang-defconst c-syntactic-ws-depth
1467 ;; Number of regexp grouping parens in `c-syntactic-ws'.
1468 t (regexp-opt-depth (c-lang-const c-syntactic-ws)))
1470 (c-lang-defconst c-nonempty-syntactic-ws
1471 ;; Regexp matching syntactic whitespace, which is at least one
1472 ;; character long. As opposed to `c-(forward|backward)-syntactic-ws',
1473 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1474 ;; not contain a \| operator at the top level.
1475 t (concat "\\("
1476 (c-lang-const c-simple-ws)
1477 "\\|"
1478 (c-lang-const c-nonwhite-syntactic-ws)
1479 "\\)+"))
1481 (c-lang-defconst c-nonempty-syntactic-ws-depth
1482 ;; Number of regexp grouping parens in `c-nonempty-syntactic-ws'.
1483 t (regexp-opt-depth (c-lang-const c-nonempty-syntactic-ws)))
1485 (c-lang-defconst c-single-line-syntactic-ws
1486 ;; Regexp matching syntactic whitespace without any line breaks. As
1487 ;; opposed to `c-(forward|backward)-syntactic-ws', this doesn't
1488 ;; regard cpp directives as syntactic whitespace. Does not contain
1489 ;; a \| operator at the top level.
1490 t (if (c-lang-const c-block-comment-regexp)
1491 (concat "\\s *\\("
1492 (c-lang-const c-block-comment-regexp)
1493 "\\s *\\)*")
1494 "\\s *"))
1496 (c-lang-defconst c-single-line-syntactic-ws-depth
1497 ;; Number of regexp grouping parens in `c-single-line-syntactic-ws'.
1498 t (regexp-opt-depth (c-lang-const c-single-line-syntactic-ws)))
1500 (c-lang-defconst c-syntactic-eol
1501 ;; Regexp that matches when there is no syntactically significant
1502 ;; text before eol. Macros are regarded as syntactically
1503 ;; significant text here.
1504 t (concat (c-lang-const c-single-line-syntactic-ws)
1505 ;; Match eol (possibly inside a block comment or preceded
1506 ;; by a line continuation backslash), or the beginning of a
1507 ;; line comment. Note: This has to be modified for awk
1508 ;; where line comments start with '#'.
1509 "\\("
1510 (c-concat-separated
1511 (list (when (c-lang-const c-line-comment-starter)
1512 (regexp-quote (c-lang-const c-line-comment-starter)))
1513 (when (c-lang-const c-unterminated-block-comment-regexp)
1514 (concat (c-lang-const c-unterminated-block-comment-regexp)
1515 "$"))
1516 "\\\\$"
1517 "$")
1518 "\\|")
1519 "\\)"))
1520 (c-lang-defvar c-syntactic-eol (c-lang-const c-syntactic-eol))
1523 ;;; Defun functions
1525 ;; The Emacs variables beginning-of-defun-function and
1526 ;; end-of-defun-function will be set so that commands like
1527 ;; `mark-defun' and `narrow-to-defun' work right. The key sequences
1528 ;; C-M-a and C-M-e are, however, bound directly to the CC Mode
1529 ;; functions, allowing optimization for large n.
1530 (c-lang-defconst beginning-of-defun-function
1531 "Function to which beginning-of-defun-function will be set."
1532 t 'c-beginning-of-defun
1533 awk 'c-awk-beginning-of-defun)
1534 (c-lang-setvar beginning-of-defun-function
1535 (c-lang-const beginning-of-defun-function))
1537 (c-lang-defconst end-of-defun-function
1538 "Function to which end-of-defun-function will be set."
1539 t 'c-end-of-defun
1540 awk 'c-awk-end-of-defun)
1541 (c-lang-setvar end-of-defun-function (c-lang-const end-of-defun-function))
1543 ;;; In-comment text handling.
1545 (c-lang-defconst c-paragraph-start
1546 "Regexp to append to `paragraph-start'."
1547 t "$"
1548 java "\\(@[a-zA-Z]+\\>\\|$\\)" ; For Javadoc.
1549 pike "\\(@[a-zA-Z_-]+\\>\\([^{]\\|$\\)\\|$\\)") ; For Pike refdoc.
1550 (c-lang-defvar c-paragraph-start (c-lang-const c-paragraph-start))
1552 (c-lang-defconst c-paragraph-separate
1553 "Regexp to append to `paragraph-separate'."
1554 t "$"
1555 pike (c-lang-const c-paragraph-start))
1556 (c-lang-defvar c-paragraph-separate (c-lang-const c-paragraph-separate))
1559 ;;; Keyword lists.
1561 ;; Note: All and only all language constants containing keyword lists
1562 ;; should end with "-kwds"; they're automatically collected into the
1563 ;; `c-kwds-lang-consts' list below and used to build `c-keywords' etc.
1565 (c-lang-defconst c-primitive-type-kwds
1566 "Primitive type keywords. As opposed to the other keyword lists, the
1567 keywords listed here are fontified with the type face instead of the
1568 keyword face.
1570 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1571 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1572 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1573 will be handled.
1575 Do not try to modify this list for end user customizations; the
1576 `*-font-lock-extra-types' variable, where `*' is the mode prefix, is
1577 the appropriate place for that."
1578 t '("char" "double" "float" "int" "long" "short" "signed"
1579 "unsigned" "void")
1580 c (append
1581 '("_Bool" "_Complex" "_Imaginary") ; Conditionally defined in C99.
1582 (c-lang-const c-primitive-type-kwds))
1583 c++ (append
1584 '("bool" "wchar_t")
1585 (c-lang-const c-primitive-type-kwds))
1586 ;; Objective-C extends C, but probably not the new stuff in C99.
1587 objc (append
1588 '("id" "Class" "SEL" "IMP" "BOOL")
1589 (c-lang-const c-primitive-type-kwds))
1590 java '("boolean" "byte" "char" "double" "float" "int" "long" "short" "void")
1591 idl '("Object" "ValueBase" "any" "boolean" "char" "double" "fixed" "float"
1592 "long" "octet" "sequence" "short" "string" "void" "wchar" "wstring"
1593 ;; In CORBA PSDL:
1594 "ref"
1595 ;; The following can't really end a type, but we have to specify them
1596 ;; here due to the assumption in `c-primitive-type-prefix-kwds'. It
1597 ;; doesn't matter that much.
1598 "unsigned" "strong")
1599 pike '(;; this_program isn't really a keyword, but it's practically
1600 ;; used as a builtin type.
1601 "array" "float" "function" "int" "mapping" "mixed" "multiset"
1602 "object" "program" "string" "this_program" "void"))
1604 (c-lang-defconst c-primitive-type-key
1605 ;; An adorned regexp that matches `c-primitive-type-kwds'.
1606 t (c-make-keywords-re t (c-lang-const c-primitive-type-kwds)))
1607 (c-lang-defvar c-primitive-type-key (c-lang-const c-primitive-type-key))
1609 (c-lang-defconst c-primitive-type-prefix-kwds
1610 "Keywords that might act as prefixes for primitive types. Assumed to
1611 be a subset of `c-primitive-type-kwds'."
1612 t nil
1613 (c c++) '("long" "short" "signed" "unsigned")
1614 idl '("long" "unsigned"
1615 ;; In CORBA PSDL:
1616 "strong"))
1618 (c-lang-defconst c-typedef-kwds
1619 "Prefix keyword\(s\) like \"typedef\" which make a type declaration out
1620 of a variable declaration."
1621 t '("typedef")
1622 (awk idl java) nil)
1624 (c-lang-defconst c-typedef-key
1625 ;; Adorned regexp matching `c-typedef-kwds'.
1626 t (c-make-keywords-re t (c-lang-const c-typedef-kwds)))
1627 (c-lang-defvar c-typedef-key (c-lang-const c-typedef-key))
1629 (c-lang-defconst c-type-prefix-kwds
1630 "Keywords where the following name - if any - is a type name, and
1631 where the keyword together with the symbol works as a type in
1632 declarations.
1634 Note that an alternative if the second part doesn't hold is
1635 `c-type-list-kwds'. Keywords on this list are typically also present
1636 on one of the `*-decl-kwds' lists."
1637 t nil
1638 c '("struct" "union" "enum")
1639 c++ (append '("class" "typename")
1640 (c-lang-const c-type-prefix-kwds c)))
1642 (c-lang-defconst c-type-prefix-key
1643 ;; Adorned regexp matching `c-type-prefix-kwds'.
1644 t (c-make-keywords-re t (c-lang-const c-type-prefix-kwds)))
1645 (c-lang-defvar c-type-prefix-key (c-lang-const c-type-prefix-key))
1647 (c-lang-defconst c-type-modifier-kwds
1648 "Type modifier keywords. These can occur almost anywhere in types
1649 but they don't build a type of themselves. Unlike the keywords on
1650 `c-primitive-type-kwds', they are fontified with the keyword face and
1651 not the type face."
1652 t nil
1653 c '("const" "restrict" "volatile")
1654 c++ '("const" "volatile" "throw")
1655 objc '("const" "volatile"))
1657 (c-lang-defconst c-opt-type-modifier-key
1658 ;; Adorned regexp matching `c-type-modifier-kwds', or nil in
1659 ;; languages without such keywords.
1660 t (and (c-lang-const c-type-modifier-kwds)
1661 (c-make-keywords-re t (c-lang-const c-type-modifier-kwds))))
1662 (c-lang-defvar c-opt-type-modifier-key (c-lang-const c-opt-type-modifier-key))
1664 (c-lang-defconst c-opt-type-component-key
1665 ;; An adorned regexp that matches `c-primitive-type-prefix-kwds' and
1666 ;; `c-type-modifier-kwds', or nil in languages without any of them.
1667 t (and (or (c-lang-const c-primitive-type-prefix-kwds)
1668 (c-lang-const c-type-modifier-kwds))
1669 (c-make-keywords-re t
1670 (append (c-lang-const c-primitive-type-prefix-kwds)
1671 (c-lang-const c-type-modifier-kwds)))))
1672 (c-lang-defvar c-opt-type-component-key
1673 (c-lang-const c-opt-type-component-key))
1675 (c-lang-defconst c-type-start-kwds
1676 ;; All keywords that can start a type (i.e. are either a type prefix
1677 ;; or a complete type).
1678 t (delete-duplicates (append (c-lang-const c-primitive-type-kwds)
1679 (c-lang-const c-type-prefix-kwds)
1680 (c-lang-const c-type-modifier-kwds))
1681 :test 'string-equal))
1683 (c-lang-defconst c-class-decl-kwds
1684 "Keywords introducing declarations where the following block (if any)
1685 contains another declaration level that should be considered a class.
1687 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1688 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1689 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1690 will be handled.
1692 Note that presence on this list does not automatically treat the
1693 following identifier as a type; the keyword must also be present on
1694 `c-type-prefix-kwds' or `c-type-list-kwds' to accomplish that."
1695 t nil
1696 c '("struct" "union")
1697 c++ '("class" "struct" "union")
1698 objc '("struct" "union"
1699 "@interface" "@implementation" "@protocol")
1700 java '("class" "@interface" "interface")
1701 idl '("component" "eventtype" "exception" "home" "interface" "struct"
1702 "union" "valuetype"
1703 ;; In CORBA PSDL:
1704 "storagehome" "storagetype"
1705 ;; In CORBA CIDL:
1706 "catalog" "executor" "manages" "segment")
1707 pike '("class"))
1709 (c-lang-defconst c-class-key
1710 ;; Regexp matching the start of a class.
1711 t (c-make-keywords-re t (c-lang-const c-class-decl-kwds)))
1712 (c-lang-defvar c-class-key (c-lang-const c-class-key))
1714 (c-lang-defconst c-brace-list-decl-kwds
1715 "Keywords introducing declarations where the following block (if
1716 any) is a brace list.
1718 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1719 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1720 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1721 will be handled."
1722 t '("enum")
1723 (awk) nil)
1725 (c-lang-defconst c-brace-list-key
1726 ;; Regexp matching the start of declarations where the following
1727 ;; block is a brace list.
1728 t (c-make-keywords-re t (c-lang-const c-brace-list-decl-kwds)))
1729 (c-lang-defvar c-brace-list-key (c-lang-const c-brace-list-key))
1731 (c-lang-defconst c-other-block-decl-kwds
1732 "Keywords where the following block (if any) contains another
1733 declaration level that should not be considered a class. For every
1734 keyword here, CC Mode will add a set of special syntactic symbols for
1735 those blocks. E.g. if the keyword is \"foo\" then there will be
1736 `foo-open', `foo-close', and `infoo' symbols.
1738 The intention is that this category should be used for block
1739 constructs that aren't related to object orientation concepts like
1740 classes (which thus also include e.g. interfaces, templates,
1741 contracts, structs, etc). The more pragmatic distinction is that
1742 while most want some indentation inside classes, it's fairly common
1743 that they don't want it in some of these constructs, so it should be
1744 simple to configure that differently from classes. See also
1745 `c-class-decl-kwds'.
1747 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1748 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1749 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1750 will be handled."
1751 t nil
1752 (c objc) '("extern")
1753 c++ '("namespace" "extern")
1754 idl '("module"
1755 ;; In CORBA CIDL:
1756 "composition"))
1758 (c-lang-defconst c-other-decl-block-key
1759 ;; Regexp matching the start of blocks besides classes that contain
1760 ;; another declaration level.
1761 t (c-make-keywords-re t (c-lang-const c-other-block-decl-kwds)))
1762 (c-lang-defvar c-other-decl-block-key (c-lang-const c-other-decl-block-key))
1764 (c-lang-defvar c-other-decl-block-key-in-symbols-alist
1765 (mapcar
1766 (lambda (elt)
1767 (cons elt
1768 (if (string= elt "extern")
1769 'inextern-lang
1770 (intern (concat "in" elt)))))
1771 (c-lang-const c-other-block-decl-kwds))
1772 "Alist associating keywords in c-other-decl-block-decl-kwds with
1773 their matching \"in\" syntactic symbols.")
1775 (c-lang-defconst c-typedef-decl-kwds
1776 "Keywords introducing declarations where the identifier(s) being
1777 declared are types.
1779 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1780 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1781 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1782 will be handled."
1783 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1784 ;; (since e.g. "Foo" is a type that's being defined in "class Foo
1785 ;; {...}").
1786 t (append (c-lang-const c-class-decl-kwds)
1787 (c-lang-const c-brace-list-decl-kwds))
1788 ;; Languages that have a "typedef" construct.
1789 (c c++ objc idl pike) (append (c-lang-const c-typedef-decl-kwds)
1790 '("typedef"))
1791 ;; Unlike most other languages, exception names are not handled as
1792 ;; types in IDL since they only can occur in "raises" specs.
1793 idl (delete "exception" (append (c-lang-const c-typedef-decl-kwds) nil)))
1795 (c-lang-defconst c-typedef-decl-key
1796 t (c-make-keywords-re t (c-lang-const c-typedef-decl-kwds)))
1797 (c-lang-defvar c-typedef-decl-key (c-lang-const c-typedef-decl-key))
1799 (c-lang-defconst c-typeless-decl-kwds
1800 "Keywords introducing declarations where the \(first) identifier
1801 \(declarator) follows directly after the keyword, without any type.
1803 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1804 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1805 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1806 will be handled."
1807 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1808 ;; (since e.g. "Foo" is the identifier being defined in "class Foo
1809 ;; {...}").
1810 t (append (c-lang-const c-class-decl-kwds)
1811 (c-lang-const c-brace-list-decl-kwds))
1812 ;; Note: "manages" for CORBA CIDL clashes with its presence on
1813 ;; `c-type-list-kwds' for IDL.
1814 idl (append (c-lang-const c-typeless-decl-kwds)
1815 '("factory" "finder" "native"
1816 ;; In CORBA PSDL:
1817 "key" "stores"
1818 ;; In CORBA CIDL:
1819 "facet"))
1820 pike (append (c-lang-const c-class-decl-kwds)
1821 '("constant")))
1823 (c-lang-defconst c-modifier-kwds
1824 "Keywords that can prefix normal declarations of identifiers
1825 \(and typically act as flags). Things like argument declarations
1826 inside function headers are also considered declarations in this
1827 sense.
1829 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1830 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1831 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1832 will be handled."
1833 t nil
1834 (c c++) '("auto" "extern" "inline" "register" "static")
1835 c++ (append '("explicit" "friend" "mutable" "template" "using" "virtual")
1836 (c-lang-const c-modifier-kwds))
1837 objc '("auto" "bycopy" "byref" "extern" "in" "inout" "oneway" "out" "static")
1838 ;; FIXME: Some of those below ought to be on `c-other-decl-kwds' instead.
1839 idl '("abstract" "attribute" "const" "consumes" "custom" "emits" "import"
1840 "in" "inout" "local" "multiple" "oneway" "out" "private" "provides"
1841 "public" "publishes" "readonly" "typeid" "typeprefix" "uses"
1842 ;; In CORBA PSDL:
1843 "primary" "state"
1844 ;; In CORBA CIDL:
1845 "bindsTo" "delegatesTo" "implements" "proxy" "storedOn")
1846 ;; Note: "const" is not used in Java, but it's still a reserved keyword.
1847 java '("abstract" "const" "final" "native" "private" "protected" "public"
1848 "static" "strictfp" "synchronized" "transient" "volatile")
1849 pike '("final" "inline" "local" "nomask" "optional" "private" "protected"
1850 "public" "static" "variant"))
1852 (c-lang-defconst c-other-decl-kwds
1853 "Keywords that can start or prefix any declaration level construct,
1854 besides those on `c-class-decl-kwds', `c-brace-list-decl-kwds',
1855 `c-other-block-decl-kwds', `c-typedef-decl-kwds',
1856 `c-typeless-decl-kwds' and `c-modifier-kwds'.
1858 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1859 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1860 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1861 will be handled."
1862 t nil
1863 objc '("@class" "@end" "@defs")
1864 java '("import" "package")
1865 pike '("import" "inherit"))
1867 (c-lang-defconst c-decl-start-kwds
1868 "Keywords that always start declarations, wherever they occur.
1869 This can be used for declarations that aren't recognized by the normal
1870 combination of `c-decl-prefix-re' and `c-decl-start-re'."
1871 t nil
1872 ;; Classes can be declared anywhere in a Pike expression.
1873 pike '("class"))
1875 (c-lang-defconst c-decl-hangon-kwds
1876 "Keywords that can occur anywhere in a declaration level construct.
1877 This is used for self-contained things that can be tacked on anywhere
1878 on a declaration and that should be ignored to be able to recognize it
1879 correctly. Typical cases are compiler extensions like
1880 \"__attribute__\" or \"__declspec\":
1882 __declspec(noreturn) void foo();
1883 class __declspec(dllexport) classname {...};
1884 void foo() __attribute__((noreturn));
1886 Note that unrecognized plain symbols are skipped anyway if they occur
1887 before the type, so such things are not necessary to mention here.
1888 Mentioning them here is necessary only if they can occur in other
1889 places, or if they are followed by a construct that must be skipped
1890 over \(like the parens in the \"__attribute__\" and \"__declspec\"
1891 examples above). In the last case, they alse need to be present on
1892 one of `c-type-list-kwds', `c-ref-list-kwds',
1893 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1894 `c-<>-type-kwds', or `c-<>-arglist-kwds'."
1895 ;; NB: These are currently not recognized in all parts of a
1896 ;; declaration. Specifically, they aren't recognized in the middle
1897 ;; of multi-token types, inside declarators, and between the
1898 ;; identifier and the arglist paren of a function declaration.
1900 ;; FIXME: This ought to be user customizable since compiler stuff
1901 ;; like this usually is wrapped in project specific macros. (It'd
1902 ;; of course be even better if we could cope without knowing this.)
1903 t nil
1904 (c c++) '(;; GCC extension.
1905 "__attribute__"
1906 ;; MSVC extension.
1907 "__declspec"))
1909 (c-lang-defconst c-decl-hangon-key
1910 ;; Adorned regexp matching `c-decl-hangon-kwds'.
1911 t (c-make-keywords-re t (c-lang-const c-decl-hangon-kwds)))
1912 (c-lang-defvar c-decl-hangon-key (c-lang-const c-decl-hangon-key))
1914 (c-lang-defconst c-prefix-spec-kwds
1915 ;; All keywords that can occur in the preamble of a declaration.
1916 ;; They typically occur before the type, but they are also matched
1917 ;; after presumptive types since we often can't be sure that
1918 ;; something is a type or just some sort of macro in front of the
1919 ;; declaration. They might be ambiguous with types or type
1920 ;; prefixes.
1921 t (delete-duplicates (append (c-lang-const c-class-decl-kwds)
1922 (c-lang-const c-brace-list-decl-kwds)
1923 (c-lang-const c-other-block-decl-kwds)
1924 (c-lang-const c-typedef-decl-kwds)
1925 (c-lang-const c-typeless-decl-kwds)
1926 (c-lang-const c-modifier-kwds)
1927 (c-lang-const c-other-decl-kwds)
1928 (c-lang-const c-decl-start-kwds)
1929 (c-lang-const c-decl-hangon-kwds))
1930 :test 'string-equal))
1932 (c-lang-defconst c-prefix-spec-kwds-re
1933 ;; Adorned regexp of `c-prefix-spec-kwds'.
1934 t (c-make-keywords-re t (c-lang-const c-prefix-spec-kwds)))
1936 (c-lang-defvar c-prefix-spec-kwds-re (c-lang-const c-prefix-spec-kwds-re))
1938 (c-lang-defconst c-specifier-key
1939 ;; Adorned regexp of the keywords in `c-prefix-spec-kwds' that aren't
1940 ;; ambiguous with types or type prefixes. These are the keywords (like
1941 ;; extern, namespace, but NOT template) that can modify a declaration.
1942 t (c-make-keywords-re t
1943 (set-difference (c-lang-const c-prefix-spec-kwds)
1944 (append (c-lang-const c-type-start-kwds)
1945 (c-lang-const c-<>-arglist-kwds))
1946 :test 'string-equal)))
1947 (c-lang-defvar c-specifier-key (c-lang-const c-specifier-key))
1949 (c-lang-defconst c-postfix-spec-kwds
1950 ;; Keywords that can occur after argument list of a function header
1951 ;; declaration, i.e. in the "K&R region".
1952 t (append (c-lang-const c-postfix-decl-spec-kwds)
1953 (c-lang-const c-decl-hangon-kwds)))
1955 (c-lang-defconst c-not-decl-init-keywords
1956 ;; Adorned regexp matching all keywords that can't appear at the
1957 ;; start of a declaration.
1958 t (c-make-keywords-re t
1959 (set-difference (c-lang-const c-keywords)
1960 (append (c-lang-const c-type-start-kwds)
1961 (c-lang-const c-prefix-spec-kwds))
1962 :test 'string-equal)))
1963 (c-lang-defvar c-not-decl-init-keywords
1964 (c-lang-const c-not-decl-init-keywords))
1966 (c-lang-defconst c-not-primitive-type-keywords
1967 "List of all keywords apart from primitive types (like \"int\")."
1968 t (set-difference (c-lang-const c-keywords)
1969 (c-lang-const c-primitive-type-kwds)
1970 :test 'string-equal)
1971 ;; The "more" for C++ is the QT keyword (as in "more slots:").
1972 ;; This variable is intended for use in c-beginning-of-statement-1.
1973 c++ (append (c-lang-const c-not-primitive-type-keywords) '("more")))
1975 (c-lang-defconst c-not-primitive-type-keywords-regexp
1976 t (c-make-keywords-re t
1977 (c-lang-const c-not-primitive-type-keywords)))
1978 (c-lang-defvar c-not-primitive-type-keywords-regexp
1979 (c-lang-const c-not-primitive-type-keywords-regexp))
1981 (c-lang-defconst c-protection-kwds
1982 "Access protection label keywords in classes."
1983 t nil
1984 c++ '("private" "protected" "public")
1985 objc '("@private" "@protected" "@public"))
1987 (c-lang-defconst c-block-decls-with-vars
1988 "Keywords introducing declarations that can contain a block which
1989 might be followed by variable declarations, e.g. like \"foo\" in
1990 \"class Foo { ... } foo;\". So if there is a block in a declaration
1991 like that, it ends with the following ';' and not right away.
1993 The keywords on list are assumed to also be present on one of the
1994 `*-decl-kwds' lists."
1995 t nil
1996 (c objc) '("struct" "union" "enum" "typedef")
1997 c++ '("class" "struct" "union" "enum" "typedef"))
1999 (c-lang-defconst c-opt-block-decls-with-vars-key
2000 ;; Regexp matching the `c-block-decls-with-vars' keywords, or nil in
2001 ;; languages without such constructs.
2002 t (and (c-lang-const c-block-decls-with-vars)
2003 (c-make-keywords-re t (c-lang-const c-block-decls-with-vars))))
2004 (c-lang-defvar c-opt-block-decls-with-vars-key
2005 (c-lang-const c-opt-block-decls-with-vars-key))
2007 (c-lang-defconst c-postfix-decl-spec-kwds
2008 "Keywords introducing extra declaration specifiers in the region
2009 between the header and the body \(i.e. the \"K&R-region\") in
2010 declarations."
2011 t nil
2012 java '("extends" "implements" "throws")
2013 idl '("context" "getraises" "manages" "primarykey" "raises" "setraises"
2014 "supports"
2015 ;; In CORBA PSDL:
2016 "as" "const" "implements" "of" "ref"))
2018 (c-lang-defconst c-nonsymbol-sexp-kwds
2019 "Keywords that may be followed by a nonsymbol sexp before whatever
2020 construct it's part of continues."
2021 t nil
2022 (c c++ objc) '("extern"))
2024 (c-lang-defconst c-type-list-kwds
2025 "Keywords that may be followed by a comma separated list of type
2026 identifiers, where each optionally can be prefixed by keywords. (Can
2027 also be used for the special case when the list can contain only one
2028 element.)
2030 Assumed to be mutually exclusive with `c-ref-list-kwds'. There's no
2031 reason to put keywords on this list if they are on `c-type-prefix-kwds'.
2032 There's also no reason to add keywords that prefixes a normal
2033 declaration consisting of a type followed by a declarator (list), so
2034 the keywords on `c-modifier-kwds' should normally not be listed here
2035 either.
2037 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
2038 or variable identifier (that's being defined)."
2039 t nil
2040 c++ '("operator")
2041 objc '("@class")
2042 java '("import" "new" "extends" "super" "implements" "throws")
2043 idl '("manages" "native" "primarykey" "supports"
2044 ;; In CORBA PSDL:
2045 "as" "implements" "of" "scope")
2046 pike '("inherit"))
2048 (c-lang-defconst c-ref-list-kwds
2049 "Keywords that may be followed by a comma separated list of
2050 reference (i.e. namespace/scope/module) identifiers, where each
2051 optionally can be prefixed by keywords. (Can also be used for the
2052 special case when the list can contain only one element.) Assumed to
2053 be mutually exclusive with `c-type-list-kwds'.
2055 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
2056 or variable identifier (that's being defined)."
2057 t nil
2058 c++ '("namespace")
2059 java '("package")
2060 idl '("import" "module"
2061 ;; In CORBA CIDL:
2062 "composition")
2063 pike '("import"))
2065 (c-lang-defconst c-colon-type-list-kwds
2066 "Keywords that may be followed (not necessarily directly) by a colon
2067 and then a comma separated list of type identifiers, where each
2068 optionally can be prefixed by keywords. (Can also be used for the
2069 special case when the list can contain only one element.)"
2070 t nil
2071 c++ '("class" "struct")
2072 idl '("component" "eventtype" "home" "interface" "valuetype"
2073 ;; In CORBA PSDL:
2074 "storagehome" "storagetype"))
2076 (c-lang-defconst c-colon-type-list-re
2077 "Regexp matched after the keywords in `c-colon-type-list-kwds' to skip
2078 forward to the colon. The end of the match is assumed to be directly
2079 after the colon, so the regexp should end with \":\". Must be a
2080 regexp if `c-colon-type-list-kwds' isn't nil."
2081 t (if (c-lang-const c-colon-type-list-kwds)
2082 ;; Disallow various common punctuation chars that can't come
2083 ;; before the ":" that starts the inherit list after "class"
2084 ;; or "struct" in C++. (Also used as default for other
2085 ;; languages.)
2086 "[^\]\[{}();,/#=:]*:"))
2087 (c-lang-defvar c-colon-type-list-re (c-lang-const c-colon-type-list-re))
2089 (c-lang-defconst c-paren-nontype-kwds
2090 "Keywords that may be followed by a parenthesis expression that doesn't
2091 contain type identifiers."
2092 t nil
2093 (c c++) '(;; GCC extension.
2094 "__attribute__"
2095 ;; MSVC extension.
2096 "__declspec"))
2098 (c-lang-defconst c-paren-type-kwds
2099 "Keywords that may be followed by a parenthesis expression containing
2100 type identifiers separated by arbitrary tokens."
2101 t nil
2102 c++ '("throw")
2103 objc '("@defs")
2104 idl '("switch")
2105 pike '("array" "function" "int" "mapping" "multiset" "object" "program"))
2107 (c-lang-defconst c-paren-any-kwds
2108 t (delete-duplicates (append (c-lang-const c-paren-nontype-kwds)
2109 (c-lang-const c-paren-type-kwds))
2110 :test 'string-equal))
2112 (c-lang-defconst c-<>-type-kwds
2113 "Keywords that may be followed by an angle bracket expression
2114 containing type identifiers separated by \",\". The difference from
2115 `c-<>-arglist-kwds' is that unknown names are taken to be types and
2116 not other identifiers. `c-recognize-<>-arglists' is assumed to be set
2117 if this isn't nil."
2118 t nil
2119 objc '("id")
2120 idl '("sequence"
2121 ;; In CORBA PSDL:
2122 "ref"))
2124 (c-lang-defconst c-<>-arglist-kwds
2125 "Keywords that can be followed by a C++ style template arglist; see
2126 `c-recognize-<>-arglists' for details. That language constant is
2127 assumed to be set if this isn't nil."
2128 t nil
2129 c++ '("template")
2130 idl '("fixed" "string" "wstring"))
2132 (c-lang-defconst c-<>-sexp-kwds
2133 ;; All keywords that can be followed by an angle bracket sexp.
2134 t (delete-duplicates (append (c-lang-const c-<>-type-kwds)
2135 (c-lang-const c-<>-arglist-kwds))
2136 :test 'string-equal))
2138 (c-lang-defconst c-opt-<>-sexp-key
2139 ;; Adorned regexp matching keywords that can be followed by an angle
2140 ;; bracket sexp. Always set when `c-recognize-<>-arglists' is.
2141 t (if (c-lang-const c-recognize-<>-arglists)
2142 (c-make-keywords-re t (c-lang-const c-<>-sexp-kwds))))
2143 (c-lang-defvar c-opt-<>-sexp-key (c-lang-const c-opt-<>-sexp-key))
2145 (c-lang-defconst c-brace-id-list-kwds
2146 "Keywords that may be followed by a brace block containing a comma
2147 separated list of identifier definitions, i.e. like the list of
2148 identifiers that follows the type in a normal declaration."
2149 t (c-lang-const c-brace-list-decl-kwds))
2151 (c-lang-defconst c-block-stmt-1-kwds
2152 "Statement keywords followed directly by a substatement."
2153 t '("do" "else")
2154 c++ '("do" "else" "try")
2155 objc '("do" "else" "@finally" "@try")
2156 java '("do" "else" "finally" "try")
2157 idl nil)
2159 (c-lang-defconst c-block-stmt-1-key
2160 ;; Regexp matching the start of any statement followed directly by a
2161 ;; substatement (doesn't match a bare block, however).
2162 t (c-make-keywords-re t (c-lang-const c-block-stmt-1-kwds)))
2163 (c-lang-defvar c-block-stmt-1-key (c-lang-const c-block-stmt-1-key))
2165 (c-lang-defconst c-block-stmt-2-kwds
2166 "Statement keywords followed by a paren sexp and then by a substatement."
2167 t '("for" "if" "switch" "while")
2168 c++ '("for" "if" "switch" "while" "catch")
2169 objc '("for" "if" "switch" "while" "@catch" "@synchronized")
2170 java '("for" "if" "switch" "while" "catch" "synchronized")
2171 idl nil
2172 pike '("for" "if" "switch" "while" "foreach")
2173 awk '("for" "if" "while"))
2175 (c-lang-defconst c-block-stmt-2-key
2176 ;; Regexp matching the start of any statement followed by a paren sexp
2177 ;; and then by a substatement.
2178 t (c-make-keywords-re t (c-lang-const c-block-stmt-2-kwds)))
2179 (c-lang-defvar c-block-stmt-2-key (c-lang-const c-block-stmt-2-key))
2181 (c-lang-defconst c-block-stmt-kwds
2182 ;; Union of `c-block-stmt-1-kwds' and `c-block-stmt-2-kwds'.
2183 t (delete-duplicates (append (c-lang-const c-block-stmt-1-kwds)
2184 (c-lang-const c-block-stmt-2-kwds))
2185 :test 'string-equal))
2187 (c-lang-defconst c-opt-block-stmt-key
2188 ;; Regexp matching the start of any statement that has a
2189 ;; substatement (except a bare block). Nil in languages that
2190 ;; don't have such constructs.
2191 t (if (or (c-lang-const c-block-stmt-1-kwds)
2192 (c-lang-const c-block-stmt-2-kwds))
2193 (c-make-keywords-re t
2194 (append (c-lang-const c-block-stmt-1-kwds)
2195 (c-lang-const c-block-stmt-2-kwds)))))
2196 (c-lang-defvar c-opt-block-stmt-key (c-lang-const c-opt-block-stmt-key))
2198 (c-lang-defconst c-simple-stmt-kwds
2199 "Statement keywords followed by an expression or nothing."
2200 t '("break" "continue" "goto" "return")
2201 objc '("break" "continue" "goto" "return" "@throw")
2202 ;; Note: `goto' is not valid in Java, but the keyword is still reserved.
2203 java '("break" "continue" "goto" "return" "throw")
2204 idl nil
2205 pike '("break" "continue" "return")
2206 awk '(;; Not sure about "delete", "exit", "getline", etc. ; ACM 2002/5/30
2207 "break" "continue" "return" "delete" "exit" "getline" "next"
2208 "nextfile" "print" "printf"))
2210 (c-lang-defconst c-simple-stmt-key
2211 ;; Adorned regexp matching `c-simple-stmt-kwds'.
2212 t (c-make-keywords-re t (c-lang-const c-simple-stmt-kwds)))
2213 (c-lang-defvar c-simple-stmt-key (c-lang-const c-simple-stmt-key))
2215 (c-lang-defconst c-paren-stmt-kwds
2216 "Statement keywords followed by a parenthesis expression that
2217 nevertheless contains a list separated with ';' and not ','."
2218 t '("for")
2219 idl nil)
2221 (c-lang-defconst c-paren-stmt-key
2222 ;; Adorned regexp matching `c-paren-stmt-kwds'.
2223 t (c-make-keywords-re t (c-lang-const c-paren-stmt-kwds)))
2224 (c-lang-defvar c-paren-stmt-key (c-lang-const c-paren-stmt-key))
2226 (c-lang-defconst c-asm-stmt-kwds
2227 "Statement keywords followed by an assembler expression."
2228 t nil
2229 (c c++) '("asm" "__asm__")) ;; Not standard, but common.
2231 (c-lang-defconst c-opt-asm-stmt-key
2232 ;; Regexp matching the start of an assembler statement. Nil in
2233 ;; languages that don't support that.
2234 t (if (c-lang-const c-asm-stmt-kwds)
2235 (c-make-keywords-re t (c-lang-const c-asm-stmt-kwds))))
2236 (c-lang-defvar c-opt-asm-stmt-key (c-lang-const c-opt-asm-stmt-key))
2238 (c-lang-defconst c-case-kwds
2239 "The keyword\(s) which introduce a \"case\" like construct.
2240 This construct is \"<keyword> <expression> :\"."
2241 t '("case")
2242 awk nil)
2244 (c-lang-defconst c-case-kwds-regexp
2245 ;; Adorned regexp matching any "case"-like keyword.
2246 t (c-make-keywords-re t (c-lang-const c-case-kwds)))
2247 (c-lang-defvar c-case-kwds-regexp (c-lang-const c-case-kwds-regexp))
2249 (c-lang-defconst c-label-kwds
2250 "Keywords introducing colon terminated labels in blocks."
2251 t '("case" "default"))
2253 (c-lang-defconst c-label-kwds-regexp
2254 ;; Adorned regexp matching any keyword that introduces a label.
2255 t (c-make-keywords-re t (c-lang-const c-label-kwds)))
2256 (c-lang-defvar c-label-kwds-regexp (c-lang-const c-label-kwds-regexp))
2258 (c-lang-defconst c-before-label-kwds
2259 "Keywords that might be followed by a label identifier."
2260 t '("goto")
2261 (java pike) (append '("break" "continue")
2262 (c-lang-const c-before-label-kwds))
2263 idl nil
2264 awk nil)
2266 (c-lang-defconst c-constant-kwds
2267 "Keywords for constants."
2268 t nil
2269 (c c++) '("NULL" ;; Not a keyword, but practically works as one.
2270 "false" "true") ; Defined in C99.
2271 objc '("nil" "Nil" "YES" "NO" "NS_DURING" "NS_HANDLER" "NS_ENDHANDLER")
2272 idl '("TRUE" "FALSE")
2273 java '("true" "false" "null") ; technically "literals", not keywords
2274 pike '("UNDEFINED")) ;; Not a keyword, but practically works as one.
2276 (c-lang-defconst c-primary-expr-kwds
2277 "Keywords besides constants and operators that start primary expressions."
2278 t nil
2279 c++ '("operator" "this")
2280 objc '("super" "self")
2281 java '("this")
2282 pike '("this")) ;; Not really a keyword, but practically works as one.
2284 (c-lang-defconst c-expr-kwds
2285 ;; Keywords that can occur anywhere in expressions. Built from
2286 ;; `c-primary-expr-kwds' and all keyword operators in `c-operators'.
2287 t (delete-duplicates
2288 (append (c-lang-const c-primary-expr-kwds)
2289 (c-filter-ops (c-lang-const c-operator-list)
2291 "\\`\\(\\w\\|\\s_\\)+\\'"))
2292 :test 'string-equal))
2294 (c-lang-defconst c-lambda-kwds
2295 "Keywords that start lambda constructs, i.e. function definitions in
2296 expressions."
2297 t nil
2298 pike '("lambda"))
2300 (c-lang-defconst c-inexpr-block-kwds
2301 "Keywords that start constructs followed by statement blocks which can
2302 be used in expressions \(the gcc extension for this in C and C++ is
2303 handled separately by `c-recognize-paren-inexpr-blocks')."
2304 t nil
2305 pike '("catch" "gauge"))
2307 (c-lang-defconst c-inexpr-class-kwds
2308 "Keywords that can start classes inside expressions."
2309 t nil
2310 java '("new")
2311 pike '("class"))
2313 (c-lang-defconst c-inexpr-brace-list-kwds
2314 "Keywords that can start brace list blocks inside expressions.
2315 Note that Java specific rules are currently applied to tell this from
2316 `c-inexpr-class-kwds'."
2317 t nil
2318 java '("new"))
2320 (c-lang-defconst c-opt-inexpr-brace-list-key
2321 ;; Regexp matching the start of a brace list in an expression, or
2322 ;; nil in languages that don't have such things. This should not
2323 ;; match brace lists recognized through `c-special-brace-lists'.
2324 t (and (c-lang-const c-inexpr-brace-list-kwds)
2325 (c-make-keywords-re t (c-lang-const c-inexpr-brace-list-kwds))))
2326 (c-lang-defvar c-opt-inexpr-brace-list-key
2327 (c-lang-const c-opt-inexpr-brace-list-key))
2329 (c-lang-defconst c-decl-block-key
2330 ;; Regexp matching keywords in any construct that contain another
2331 ;; declaration level, i.e. that isn't followed by a function block
2332 ;; or brace list. When the first submatch matches, it's an
2333 ;; unambiguous construct, otherwise it's an ambiguous match that
2334 ;; might also be the return type of a function declaration.
2335 t (let* ((decl-kwds (append (c-lang-const c-class-decl-kwds)
2336 (c-lang-const c-other-block-decl-kwds)
2337 (c-lang-const c-inexpr-class-kwds)))
2338 (unambiguous (set-difference decl-kwds
2339 (c-lang-const c-type-start-kwds)
2340 :test 'string-equal))
2341 (ambiguous (intersection decl-kwds
2342 (c-lang-const c-type-start-kwds)
2343 :test 'string-equal)))
2344 (if ambiguous
2345 (concat (c-make-keywords-re t unambiguous)
2346 "\\|"
2347 (c-make-keywords-re t ambiguous))
2348 (c-make-keywords-re t unambiguous))))
2349 (c-lang-defvar c-decl-block-key (c-lang-const c-decl-block-key))
2351 (c-lang-defconst c-bitfield-kwds
2352 "Keywords that can introduce bitfields."
2353 t nil
2354 (c c++ objc) '("char" "int" "long" "signed" "unsigned"))
2356 (c-lang-defconst c-opt-bitfield-key
2357 ;; Regexp matching the start of a bitfield (not uniquely), or nil in
2358 ;; languages without bitfield support.
2359 t nil
2360 (c c++) (c-make-keywords-re t (c-lang-const c-bitfield-kwds)))
2361 (c-lang-defvar c-opt-bitfield-key (c-lang-const c-opt-bitfield-key))
2363 (c-lang-defconst c-other-kwds
2364 "Keywords not accounted for by any other `*-kwds' language constant."
2365 t nil
2366 idl '("truncatable"
2367 ;; In CORBA CIDL: (These are declaration keywords that never
2368 ;; can start a declaration.)
2369 "entity" "process" "service" "session" "storage"))
2372 ;;; Constants built from keywords.
2374 ;; Note: No `*-kwds' language constants may be defined below this point.
2376 (eval-and-compile
2377 (defconst c-kwds-lang-consts
2378 ;; List of all the language constants that contain keyword lists.
2379 (let (list)
2380 (mapatoms (lambda (sym)
2381 (when (and (boundp sym)
2382 (string-match "-kwds\\'" (symbol-name sym)))
2383 ;; Make the list of globally interned symbols
2384 ;; instead of ones interned in `c-lang-constants'.
2385 (setq list (cons (intern (symbol-name sym)) list))))
2386 c-lang-constants)
2387 list)))
2389 (c-lang-defconst c-keywords
2390 ;; All keywords as a list.
2391 t (delete-duplicates
2392 (c-lang-defconst-eval-immediately
2393 `(append ,@(mapcar (lambda (kwds-lang-const)
2394 `(c-lang-const ,kwds-lang-const))
2395 c-kwds-lang-consts)
2396 nil))
2397 :test 'string-equal))
2399 (c-lang-defconst c-keywords-regexp
2400 ;; All keywords as an adorned regexp.
2401 t (c-make-keywords-re t (c-lang-const c-keywords)))
2402 (c-lang-defvar c-keywords-regexp (c-lang-const c-keywords-regexp))
2404 (c-lang-defconst c-keyword-member-alist
2405 ;; An alist with all the keywords in the cars. The cdr for each
2406 ;; keyword is a list of the symbols for the `*-kwds' lists that
2407 ;; contains it.
2408 t (let ((kwd-list-alist
2409 (c-lang-defconst-eval-immediately
2410 `(list ,@(mapcar (lambda (kwds-lang-const)
2411 `(cons ',kwds-lang-const
2412 (c-lang-const ,kwds-lang-const)))
2413 c-kwds-lang-consts))))
2414 lang-const kwd-list kwd
2415 result-alist elem)
2416 (while kwd-list-alist
2417 (setq lang-const (caar kwd-list-alist)
2418 kwd-list (cdar kwd-list-alist)
2419 kwd-list-alist (cdr kwd-list-alist))
2420 (while kwd-list
2421 (setq kwd (car kwd-list)
2422 kwd-list (cdr kwd-list))
2423 (unless (setq elem (assoc kwd result-alist))
2424 (setq result-alist (cons (setq elem (list kwd)) result-alist)))
2425 (unless (memq lang-const (cdr elem))
2426 (setcdr elem (cons lang-const (cdr elem))))))
2427 result-alist))
2429 (c-lang-defvar c-keywords-obarray
2430 ;; An obarray containing all keywords as symbols. The property list
2431 ;; of each symbol has a non-nil entry for the specific `*-kwds'
2432 ;; lists it's a member of.
2434 ;; E.g. to see whether the string str contains a keyword on
2435 ;; `c-class-decl-kwds', one can do like this:
2436 ;; (get (intern-soft str c-keyword-obarray) 'c-class-decl-kwds)
2437 ;; Which preferably is written using the associated functions in
2438 ;; cc-engine:
2439 ;; (c-keyword-member (c-keyword-sym str) 'c-class-decl-kwds)
2441 ;; The obarray is not stored directly as a language constant since
2442 ;; the printed representation for obarrays used in .elc files isn't
2443 ;; complete.
2445 (let* ((alist (c-lang-const c-keyword-member-alist))
2446 kwd lang-const-list
2447 (obarray (make-vector (* (length alist) 2) 0)))
2448 (while alist
2449 (setq kwd (caar alist)
2450 lang-const-list (cdar alist)
2451 alist (cdr alist))
2452 (setplist (intern kwd obarray)
2453 ;; Emacs has an odd bug that causes `mapcan' to fail
2454 ;; with unintelligible errors. (XEmacs works.)
2455 ;;(mapcan (lambda (lang-const)
2456 ;; (list lang-const t))
2457 ;; lang-const-list)
2458 (apply 'nconc (mapcar (lambda (lang-const)
2459 (list lang-const t))
2460 lang-const-list))))
2461 obarray))
2463 (c-lang-defconst c-regular-keywords-regexp
2464 ;; Adorned regexp matching all keywords that should be fontified
2465 ;; with the keywords face. I.e. that aren't types or constants.
2466 t (c-make-keywords-re t
2467 (set-difference (c-lang-const c-keywords)
2468 (append (c-lang-const c-primitive-type-kwds)
2469 (c-lang-const c-constant-kwds))
2470 :test 'string-equal)))
2471 (c-lang-defvar c-regular-keywords-regexp
2472 (c-lang-const c-regular-keywords-regexp))
2474 (c-lang-defconst c-primary-expr-regexp
2475 ;; Regexp matching the start of any primary expression, i.e. any
2476 ;; literal, symbol, prefix operator, and '('. It doesn't need to
2477 ;; exclude keywords; they are excluded afterwards unless the second
2478 ;; submatch matches. If the first but not the second submatch
2479 ;; matches then it is an ambiguous primary expression; it could also
2480 ;; be a match of e.g. an infix operator. (The case with ambiguous
2481 ;; keyword operators isn't handled.)
2483 t (let* ((prefix-ops
2484 (c-filter-ops (c-lang-const c-operators)
2485 '(prefix)
2486 (lambda (op)
2487 ;; Filter out the special case prefix
2488 ;; operators that are close parens.
2489 (not (string-match "\\s)" op)))))
2491 (nonkeyword-prefix-ops
2492 (c-filter-ops prefix-ops
2494 "\\`\\(\\s.\\|\\s(\\|\\s)\\)+\\'"))
2496 (in-or-postfix-ops
2497 (c-filter-ops (c-lang-const c-operators)
2498 '(postfix
2499 postfix-if-paren
2500 left-assoc
2501 right-assoc
2502 right-assoc-sequence)
2505 (unambiguous-prefix-ops (set-difference nonkeyword-prefix-ops
2506 in-or-postfix-ops
2507 :test 'string-equal))
2508 (ambiguous-prefix-ops (intersection nonkeyword-prefix-ops
2509 in-or-postfix-ops
2510 :test 'string-equal)))
2512 (concat
2513 "\\("
2514 ;; Take out all symbol class operators from `prefix-ops' and make the
2515 ;; first submatch from them together with `c-primary-expr-kwds'.
2516 (c-make-keywords-re t
2517 (append (c-lang-const c-primary-expr-kwds)
2518 (set-difference prefix-ops nonkeyword-prefix-ops
2519 :test 'string-equal)))
2521 "\\|"
2522 ;; Match all ambiguous operators.
2523 (c-make-keywords-re nil
2524 (intersection nonkeyword-prefix-ops in-or-postfix-ops
2525 :test 'string-equal))
2526 "\\)"
2528 "\\|"
2529 ;; Now match all other symbols.
2530 (c-lang-const c-symbol-start)
2532 "\\|"
2533 ;; The chars that can start integer and floating point
2534 ;; constants.
2535 "\\.?[0-9]"
2537 "\\|"
2538 ;; The unambiguous operators from `prefix-ops'.
2539 (c-make-keywords-re nil
2540 (set-difference nonkeyword-prefix-ops in-or-postfix-ops
2541 :test 'string-equal))
2543 "\\|"
2544 ;; Match string and character literals.
2545 "\\s\""
2546 (if (memq 'gen-string-delim c-emacs-features)
2547 "\\|\\s|"
2548 ""))))
2549 (c-lang-defvar c-primary-expr-regexp (c-lang-const c-primary-expr-regexp))
2552 ;;; Additional constants for parser-level constructs.
2554 (c-lang-defconst c-decl-prefix-re
2555 "Regexp matching something that might precede a declaration, cast or
2556 label, such as the last token of a preceding statement or declaration.
2557 This is used in the common situation where a declaration or cast
2558 doesn't start with any specific token that can be searched for.
2560 The regexp should not match bob; that is done implicitly. It can't
2561 require a match longer than one token. The end of the token is taken
2562 to be at the end of the first submatch, which is assumed to always
2563 match. It's undefined whether identifier syntax (see
2564 `c-identifier-syntax-table') is in effect or not. This regexp is
2565 assumed to be a superset of `c-label-prefix-re' if
2566 `c-recognize-colon-labels' is set.
2568 Besides this, `c-decl-start-kwds' is used to find declarations.
2570 Note: This variable together with `c-decl-start-re' and
2571 `c-decl-start-kwds' is only used to detect \"likely\"
2572 declaration/cast/label starts. I.e. they might produce more matches
2573 but should not miss anything (or else it's necessary to use text
2574 properties - see the next note). Wherever they match, the following
2575 construct is analyzed to see if it indeed is a declaration, cast or
2576 label. That analysis is not cheap, so it's important that not too
2577 many false matches are triggered.
2579 Note: If a declaration/cast/label start can't be detected with this
2580 variable, it's necessary to use the `c-type' text property with the
2581 value `c-decl-end' on the last char of the last token preceding the
2582 declaration. See the comment blurb at the start of cc-engine.el for
2583 more info."
2585 ;; We match a sequence of characters to skip over things like \"};\"
2586 ;; more quickly. We match ")" in C for K&R region declarations, and
2587 ;; in all languages except Java for when a cpp macro definition
2588 ;; begins with a declaration.
2589 t "\\([\{\}\(\);,]+\\)"
2590 java "\\([\{\}\(;,<]+\\)"
2591 ;; Match "<" in C++ to get the first argument in a template arglist.
2592 ;; In that case there's an additional check in `c-find-decl-spots'
2593 ;; that it got open paren syntax.
2594 c++ "\\([\{\}\(\);,<]+\\)"
2595 ;; Additionally match the protection directives in Objective-C.
2596 ;; Note that this doesn't cope with the longer directives, which we
2597 ;; would have to match from start to end since they don't end with
2598 ;; any easily recognized characters.
2599 objc (concat "\\([\{\}\(\);,]+\\|"
2600 (c-make-keywords-re nil (c-lang-const c-protection-kwds))
2601 "\\)")
2602 ;; Pike is like C but we also match "[" for multiple value
2603 ;; assignments and type casts.
2604 pike "\\([\{\}\(\)\[;,]+\\)")
2605 (c-lang-defvar c-decl-prefix-re (c-lang-const c-decl-prefix-re)
2606 'dont-doc)
2608 (c-lang-defconst c-decl-start-re
2609 "Regexp matching the start of any declaration, cast or label.
2610 It's used on the token after the one `c-decl-prefix-re' matched. This
2611 regexp should not try to match those constructs accurately as it's
2612 only used as a sieve to avoid spending more time checking other
2613 constructs."
2614 t (c-lang-const c-identifier-start))
2615 (c-lang-defvar c-decl-start-re (c-lang-const c-decl-start-re))
2617 (c-lang-defconst c-decl-prefix-or-start-re
2618 ;; Regexp matching something that might precede or start a
2619 ;; declaration, cast or label.
2621 ;; If the first submatch matches, it's taken to match the end of a
2622 ;; token that might precede such a construct, e.g. ';', '}' or '{'.
2623 ;; It's built from `c-decl-prefix-re'.
2625 ;; If the first submatch did not match, the match of the whole
2626 ;; regexp is taken to be at the first token in the declaration.
2627 ;; `c-decl-start-re' is not checked in this case.
2629 ;; Design note: The reason the same regexp is used to match both
2630 ;; tokens that precede declarations and start them is to avoid an
2631 ;; extra regexp search from the previous declaration spot in
2632 ;; `c-find-decl-spots'. Users of `c-find-decl-spots' also count on
2633 ;; that it finds all declaration/cast/label starts in approximately
2634 ;; linear order, so we can't do the searches in two separate passes.
2635 t (if (c-lang-const c-decl-start-kwds)
2636 (concat (c-lang-const c-decl-prefix-re)
2637 "\\|"
2638 (c-make-keywords-re t (c-lang-const c-decl-start-kwds)))
2639 (c-lang-const c-decl-prefix-re)))
2640 (c-lang-defvar c-decl-prefix-or-start-re
2641 (c-lang-const c-decl-prefix-or-start-re)
2642 'dont-doc)
2644 (c-lang-defconst c-cast-parens
2645 ;; List containing the paren characters that can open a cast, or nil in
2646 ;; languages without casts.
2647 t (c-filter-ops (c-lang-const c-operators)
2648 '(prefix)
2649 "\\`\\s\(\\'"
2650 (lambda (op) (elt op 0))))
2651 (c-lang-defvar c-cast-parens (c-lang-const c-cast-parens))
2653 (c-lang-defconst c-block-prefix-disallowed-chars
2654 "List of syntactically relevant characters that never can occur before
2655 the open brace in any construct that contains a brace block, e.g. in
2656 the \"class Foo: public Bar\" part of:
2658 class Foo: public Bar {int x();} a, *b;
2660 If parens can occur, the chars inside those aren't filtered with this
2661 list.
2663 '<' and '>' should be disallowed even if angle bracket arglists can
2664 occur. That since the search function needs to stop at them anyway to
2665 ensure they are given paren syntax.
2667 This is used to skip backward from the open brace to find the region
2668 in which to look for a construct like \"class\", \"enum\",
2669 \"namespace\" or whatever. That skipping should be as tight as
2670 possible for good performance."
2672 ;; Default to all chars that only occurs in nonsymbol tokens outside
2673 ;; identifiers.
2674 t (set-difference
2675 (c-lang-const c-nonsymbol-token-char-list)
2676 (c-filter-ops (append (c-lang-const c-identifier-ops)
2677 (list (cons nil
2678 (c-lang-const c-after-id-concat-ops))))
2681 (lambda (op)
2682 (let ((pos 0) res)
2683 (while (string-match "\\(\\s.\\|\\s(\\|\\s)\\)"
2684 op pos)
2685 (setq res (cons (aref op (match-beginning 1)) res)
2686 pos (match-end 0)))
2687 res))))
2689 ;; Allow cpp operations (where applicable).
2690 t (if (c-lang-const c-opt-cpp-prefix)
2691 (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2692 '(?#))
2693 (c-lang-const c-block-prefix-disallowed-chars))
2695 ;; Allow ':' for inherit list starters.
2696 (c++ objc idl) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2697 '(?:))
2699 ;; Allow ',' for multiple inherits.
2700 (c++ java) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2701 '(?,))
2703 ;; Allow parentheses for anonymous inner classes in Java and class
2704 ;; initializer lists in Pike.
2705 (java pike) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2706 '(?\( ?\)))
2708 ;; Allow '"' for extern clauses (e.g. extern "C" {...}).
2709 (c c++ objc) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2710 '(?\" ?')))
2712 (c-lang-defconst c-block-prefix-charset
2713 ;; `c-block-prefix-disallowed-chars' as an inverted charset suitable
2714 ;; for `c-syntactic-skip-backward'.
2715 t (c-make-bare-char-alt (c-lang-const c-block-prefix-disallowed-chars) t))
2716 (c-lang-defvar c-block-prefix-charset (c-lang-const c-block-prefix-charset))
2718 (c-lang-defconst c-type-decl-prefix-key
2719 "Regexp matching the declarator operators that might precede the
2720 identifier in a declaration, e.g. the \"*\" in \"char *argv\". This
2721 regexp should match \"(\" if parentheses are valid in declarators.
2722 The end of the first submatch is taken as the end of the operator.
2723 Identifier syntax is in effect when this is matched \(see
2724 `c-identifier-syntax-table')."
2725 t (if (c-lang-const c-type-modifier-kwds)
2726 (concat (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>")
2727 ;; Default to a regexp that never matches.
2728 "\\<\\>")
2729 ;; Check that there's no "=" afterwards to avoid matching tokens
2730 ;; like "*=".
2731 (c objc) (concat "\\("
2732 "[*\(]"
2733 "\\|"
2734 (c-lang-const c-type-decl-prefix-key)
2735 "\\)"
2736 "\\([^=]\\|$\\)")
2737 c++ (concat "\\("
2738 "[*\(&]"
2739 "\\|"
2740 (c-lang-const c-type-decl-prefix-key)
2741 "\\|"
2742 (concat "\\(" ; 3
2743 ;; If this matches there's special treatment in
2744 ;; `c-font-lock-declarators' and
2745 ;; `c-font-lock-declarations' that check for a
2746 ;; complete name followed by ":: *".
2747 (c-lang-const c-identifier-start)
2748 "\\)")
2749 "\\)"
2750 "\\([^=]\\|$\\)")
2751 pike "\\(\\*\\)\\([^=]\\|$\\)")
2752 (c-lang-defvar c-type-decl-prefix-key (c-lang-const c-type-decl-prefix-key)
2753 'dont-doc)
2755 (c-lang-defconst c-type-decl-suffix-key
2756 "Regexp matching the declarator operators that might follow after the
2757 identifier in a declaration, e.g. the \"[\" in \"char argv[]\". This
2758 regexp should match \")\" if parentheses are valid in declarators. If
2759 it matches an open paren of some kind, the type declaration check
2760 continues at the corresponding close paren, otherwise the end of the
2761 first submatch is taken as the end of the operator. Identifier syntax
2762 is in effect when this is matched (see `c-identifier-syntax-table')."
2763 ;; Default to a regexp that matches `c-type-modifier-kwds' and a
2764 ;; function argument list parenthesis.
2765 t (if (c-lang-const c-type-modifier-kwds)
2766 (concat "\\(\(\\|"
2767 (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>"
2768 "\\)")
2769 "\\(\(\\)")
2770 (c c++ objc) (concat
2771 "\\("
2772 "[\)\[\(]"
2773 (if (c-lang-const c-type-modifier-kwds)
2774 (concat
2775 "\\|"
2776 ;; "throw" in `c-type-modifier-kwds' is followed
2777 ;; by a parenthesis list, but no extra measures
2778 ;; are necessary to handle that.
2779 (regexp-opt (c-lang-const c-type-modifier-kwds) t)
2780 "\\>")
2782 "\\)")
2783 (java idl) "\\([\[\(]\\)")
2784 (c-lang-defvar c-type-decl-suffix-key (c-lang-const c-type-decl-suffix-key)
2785 'dont-doc)
2787 (c-lang-defconst c-after-suffixed-type-decl-key
2788 "This regexp is matched after a declarator expression where
2789 `c-type-decl-suffix-key' has matched. If it matches then the
2790 construct is taken as a declaration. It's typically used to match the
2791 beginning of a function body or whatever might occur after the
2792 function header in a function declaration or definition. It's
2793 undefined whether identifier syntax (see `c-identifier-syntax-table')
2794 is in effect or not.
2796 Note that it's used in cases like after \"foo (bar)\" so it should
2797 only match when it's certain that it's a declaration, e.g \"{\" but
2798 not \",\" or \";\"."
2799 t "{"
2800 ;; If K&R style declarations should be recognized then one could
2801 ;; consider to match the start of any symbol since we want to match
2802 ;; the start of the first declaration in the "K&R region". That
2803 ;; could however produce false matches on code like "FOO(bar) x"
2804 ;; where FOO is a cpp macro, so it's better to leave it out and rely
2805 ;; on the other heuristics in that case.
2806 t (if (c-lang-const c-postfix-spec-kwds)
2807 ;; Add on the keywords in `c-postfix-spec-kwds'.
2808 (concat (c-lang-const c-after-suffixed-type-decl-key)
2809 "\\|"
2810 (c-make-keywords-re t (c-lang-const c-postfix-spec-kwds)))
2811 (c-lang-const c-after-suffixed-type-decl-key))
2812 ;; Also match the colon that starts a base class initializer list in
2813 ;; C++. That can be confused with a function call before the colon
2814 ;; in a ? : operator, but we count on that `c-decl-prefix-re' won't
2815 ;; match before such a thing (as a declaration-level construct;
2816 ;; matches inside arglist contexts are already excluded).
2817 c++ "[{:]")
2818 (c-lang-defvar c-after-suffixed-type-decl-key
2819 (c-lang-const c-after-suffixed-type-decl-key)
2820 'dont-doc)
2822 (c-lang-defconst c-after-suffixed-type-maybe-decl-key
2823 ;; Regexp that in addition to `c-after-suffixed-type-decl-key'
2824 ;; matches ";" and ",".
2825 t (concat "\\(" (c-lang-const c-after-suffixed-type-decl-key) "\\)"
2826 "\\|[;,]"))
2827 (c-lang-defvar c-after-suffixed-type-maybe-decl-key
2828 (c-lang-const c-after-suffixed-type-maybe-decl-key))
2830 (c-lang-defconst c-opt-type-concat-key
2831 "Regexp matching operators that concatenate types, e.g. the \"|\" in
2832 \"int|string\" in Pike. The end of the first submatch is taken as the
2833 end of the operator. nil in languages without such operators. It's
2834 undefined whether identifier syntax (see `c-identifier-syntax-table')
2835 is in effect or not."
2836 t nil
2837 pike "\\([|.&]\\)\\($\\|[^|.&]\\)")
2838 (c-lang-defvar c-opt-type-concat-key (c-lang-const c-opt-type-concat-key)
2839 'dont-doc)
2841 (c-lang-defconst c-opt-type-suffix-key
2842 "Regexp matching operators that might follow after a type, or nil in
2843 languages that don't have such operators. The end of the first
2844 submatch is taken as the end of the operator. This should not match
2845 things like C++ template arglists if `c-recognize-<>-arglists' is set.
2846 It's undefined whether identifier syntax (see `c-identifier-syntax-table')
2847 is in effect or not."
2848 t nil
2849 (c c++ objc pike) "\\(\\.\\.\\.\\)"
2850 java (concat "\\(\\[" (c-lang-const c-simple-ws) "*\\]\\|\\.\\.\\.\\)"))
2851 (c-lang-defvar c-opt-type-suffix-key (c-lang-const c-opt-type-suffix-key))
2853 (c-lang-defvar c-known-type-key
2854 ;; Regexp matching the known type identifiers. This is initialized
2855 ;; from the type keywords and `*-font-lock-extra-types'. The first
2856 ;; submatch is the one that matches the type. Note that this regexp
2857 ;; assumes that symbol constituents like '_' and '$' have word
2858 ;; syntax.
2859 (let* ((extra-types
2860 (when (boundp (c-mode-symbol "font-lock-extra-types"))
2861 (c-mode-var "font-lock-extra-types")))
2862 (regexp-strings
2863 (apply 'nconc
2864 (mapcar (lambda (re)
2865 (when (string-match "[][.*+?^$\\]" re)
2866 (list re)))
2867 extra-types)))
2868 (plain-strings
2869 (apply 'nconc
2870 (mapcar (lambda (re)
2871 (unless (string-match "[][.*+?^$\\]" re)
2872 (list re)))
2873 extra-types))))
2874 (concat "\\<\\("
2875 (c-concat-separated
2876 (append (list (c-make-keywords-re nil
2877 (append (c-lang-const c-primitive-type-kwds)
2878 plain-strings)))
2879 regexp-strings)
2880 "\\|")
2881 "\\)\\>")))
2883 (c-lang-defconst c-special-brace-lists
2884 "List of open- and close-chars that makes up a pike-style brace list,
2885 i.e. for a ([ ]) list there should be a cons (?\\[ . ?\\]) in this
2886 list."
2887 t nil
2888 pike '((?{ . ?}) (?\[ . ?\]) (?< . ?>)))
2889 (c-lang-defvar c-special-brace-lists (c-lang-const c-special-brace-lists))
2891 (c-lang-defconst c-recognize-knr-p
2892 "Non-nil means K&R style argument declarations are valid."
2893 t nil
2894 c t)
2895 (c-lang-defvar c-recognize-knr-p (c-lang-const c-recognize-knr-p))
2897 (c-lang-defconst c-recognize-typeless-decls
2898 "Non-nil means function declarations without return type should be
2899 recognized. That can introduce an ambiguity with parenthesized macro
2900 calls before a brace block. This setting does not affect declarations
2901 that are preceded by a declaration starting keyword, so
2902 e.g. `c-typeless-decl-kwds' may still be used when it's set to nil."
2903 t nil
2904 (c c++ objc) t)
2905 (c-lang-defvar c-recognize-typeless-decls
2906 (c-lang-const c-recognize-typeless-decls))
2908 (c-lang-defconst c-recognize-<>-arglists
2909 "Non-nil means C++ style template arglists should be handled. More
2910 specifically, this means a comma separated list of types or
2911 expressions surrounded by \"<\" and \">\". It's always preceded by an
2912 identifier or one of the keywords on `c-<>-type-kwds' or
2913 `c-<>-arglist-kwds'. If there's an identifier before then the whole
2914 expression is considered to be a type."
2915 t (or (consp (c-lang-const c-<>-type-kwds))
2916 (consp (c-lang-const c-<>-arglist-kwds))))
2917 (c-lang-defvar c-recognize-<>-arglists (c-lang-const c-recognize-<>-arglists))
2919 (c-lang-defconst c-recognize-paren-inits
2920 "Non-nil means that parenthesis style initializers exist,
2921 i.e. constructs like
2923 Foo bar (gnu);
2925 in addition to the more classic
2927 Foo bar = gnu;"
2928 t nil
2929 c++ t)
2930 (c-lang-defvar c-recognize-paren-inits (c-lang-const c-recognize-paren-inits))
2932 (c-lang-defconst c-recognize-paren-inexpr-blocks
2933 "Non-nil to recognize gcc style in-expression blocks,
2934 i.e. compound statements surrounded by parentheses inside expressions."
2935 t nil
2936 (c c++) t)
2937 (c-lang-defvar c-recognize-paren-inexpr-blocks
2938 (c-lang-const c-recognize-paren-inexpr-blocks))
2940 (c-lang-defconst c-opt-<>-arglist-start
2941 ;; Regexp matching the start of angle bracket arglists in languages
2942 ;; where `c-recognize-<>-arglists' is set. Does not exclude
2943 ;; keywords outside `c-<>-arglist-kwds'. The first submatch is
2944 ;; assumed to surround the preceding symbol. The whole match is
2945 ;; assumed to end directly after the opening "<".
2946 t (if (c-lang-const c-recognize-<>-arglists)
2947 (concat "\\("
2948 (c-lang-const c-symbol-key)
2949 "\\)"
2950 (c-lang-const c-syntactic-ws)
2951 "<")))
2952 (c-lang-defvar c-opt-<>-arglist-start (c-lang-const c-opt-<>-arglist-start))
2954 (c-lang-defconst c-opt-<>-arglist-start-in-paren
2955 ;; Regexp that in addition to `c-opt-<>-arglist-start' matches close
2956 ;; parens. The first submatch is assumed to surround
2957 ;; `c-opt-<>-arglist-start'.
2958 t (if (c-lang-const c-opt-<>-arglist-start)
2959 (concat "\\("
2960 (c-lang-const c-opt-<>-arglist-start)
2961 "\\)\\|\\s\)")))
2962 (c-lang-defvar c-opt-<>-arglist-start-in-paren
2963 (c-lang-const c-opt-<>-arglist-start-in-paren))
2965 (c-lang-defconst c-opt-postfix-decl-spec-key
2966 ;; Regexp matching the beginning of a declaration specifier in the
2967 ;; region between the header and the body of a declaration.
2969 ;; TODO: This is currently not used uniformly; c++-mode and
2970 ;; java-mode each have their own ways of using it.
2971 t nil
2972 c++ (concat ":?"
2973 (c-lang-const c-simple-ws) "*"
2974 "\\(virtual" (c-lang-const c-simple-ws) "+\\)?\\("
2975 (c-make-keywords-re nil (c-lang-const c-protection-kwds))
2976 "\\)" (c-lang-const c-simple-ws) "+"
2977 "\\(" (c-lang-const c-symbol-key) "\\)")
2978 java (c-make-keywords-re t (c-lang-const c-postfix-spec-kwds)))
2979 (c-lang-defvar c-opt-postfix-decl-spec-key
2980 (c-lang-const c-opt-postfix-decl-spec-key))
2982 (c-lang-defconst c-recognize-colon-labels
2983 "Non-nil if generic labels ending with \":\" should be recognized.
2984 That includes labels in code and access keys in classes. This does
2985 not apply to labels recognized by `c-label-kwds' and
2986 `c-opt-extra-label-key'."
2987 t nil
2988 (c c++ objc java pike) t)
2989 (c-lang-defvar c-recognize-colon-labels
2990 (c-lang-const c-recognize-colon-labels))
2992 (c-lang-defconst c-label-prefix-re
2993 "Regexp like `c-decl-prefix-re' that matches any token that can precede
2994 a generic colon label. Not used if `c-recognize-colon-labels' is
2995 nil."
2996 t "\\([{};]+\\)")
2997 (c-lang-defvar c-label-prefix-re
2998 (c-lang-const c-label-prefix-re))
3000 (c-lang-defconst c-nonlabel-token-key
3001 "Regexp matching things that can't occur in generic colon labels,
3002 neither in a statement nor in a declaration context. The regexp is
3003 tested at the beginning of every sexp in a suspected label,
3004 i.e. before \":\". Only used if `c-recognize-colon-labels' is set."
3005 t (concat
3006 ;; All keywords except `c-label-kwds' and `c-protection-kwds'.
3007 (c-make-keywords-re t
3008 (set-difference (c-lang-const c-keywords)
3009 (append (c-lang-const c-label-kwds)
3010 (c-lang-const c-protection-kwds))
3011 :test 'string-equal)))
3012 ;; Don't allow string literals, except in AWK. Character constants are OK.
3013 (c objc java pike idl) (concat "\"\\|"
3014 (c-lang-const c-nonlabel-token-key))
3015 ;; Also check for open parens in C++, to catch member init lists in
3016 ;; constructors. We normally allow it so that macros with arguments
3017 ;; work in labels.
3018 c++ (concat "\\s\(\\|\"\\|" (c-lang-const c-nonlabel-token-key)))
3019 (c-lang-defvar c-nonlabel-token-key (c-lang-const c-nonlabel-token-key))
3021 (c-lang-defconst c-nonlabel-token-2-key
3022 "Regexp matching things that can't occur two symbols before a colon in
3023 a label construct. This catches C++'s inheritance construct \"class foo
3024 : bar\". Only used if `c-recognize-colon-labels' is set."
3025 t "\\<\\>" ; matches nothing
3026 c++ (c-make-keywords-re t '("class")))
3027 (c-lang-defvar c-nonlabel-token-2-key (c-lang-const c-nonlabel-token-2-key))
3029 (c-lang-defconst c-opt-extra-label-key
3030 "Optional regexp matching labels.
3031 Normally, labels are detected according to `c-nonlabel-token-key',
3032 `c-decl-prefix-re' and `c-nonlabel-decl-prefix-re'. This regexp can
3033 be used if there are additional labels that aren't recognized that
3034 way."
3035 t nil
3036 objc (c-make-keywords-re t (c-lang-const c-protection-kwds)))
3037 (c-lang-defvar c-opt-extra-label-key (c-lang-const c-opt-extra-label-key))
3039 (c-lang-defconst c-opt-friend-key
3040 ;; Regexp describing friend declarations classes, or nil in
3041 ;; languages that don't have such things.
3043 ;; TODO: Ought to use `c-prefix-spec-kwds-re' or similar, and the
3044 ;; template skipping isn't done properly. This will disappear soon.
3045 t nil
3046 c++ (concat "friend" (c-lang-const c-simple-ws) "+"
3047 "\\|"
3048 (concat "template"
3049 (c-lang-const c-simple-ws) "*"
3050 "<.+>"
3051 (c-lang-const c-simple-ws) "*"
3052 "friend"
3053 (c-lang-const c-simple-ws) "+")))
3054 (c-lang-defvar c-opt-friend-key (c-lang-const c-opt-friend-key))
3056 (c-lang-defconst c-opt-method-key
3057 ;; Special regexp to match the start of Objective-C methods. The
3058 ;; first submatch is assumed to end after the + or - key.
3059 t nil
3060 objc (concat
3061 ;; TODO: Ought to use a better method than anchoring on bol.
3062 "^\\s *"
3063 "\\([+-]\\)"
3064 (c-lang-const c-simple-ws) "*"
3065 (concat "\\(" ; Return type.
3066 "([^\)]*)"
3067 (c-lang-const c-simple-ws) "*"
3068 "\\)?")
3069 "\\(" (c-lang-const c-symbol-key) "\\)"))
3070 (c-lang-defvar c-opt-method-key (c-lang-const c-opt-method-key))
3072 (c-lang-defconst c-type-decl-end-used
3073 ;; Must be set in buffers where the `c-type' text property might be
3074 ;; used with the value `c-decl-end'.
3076 ;; `c-decl-end' is used to mark the ends of labels and access keys
3077 ;; to make interactive refontification work better.
3078 t (or (c-lang-const c-recognize-colon-labels)
3079 (and (c-lang-const c-label-kwds) t))
3080 ;; `c-decl-end' is used to mark the end of the @-style directives in
3081 ;; Objective-C.
3082 objc t)
3083 (c-lang-defvar c-type-decl-end-used (c-lang-const c-type-decl-end-used))
3086 ;;; Wrap up the `c-lang-defvar' system.
3088 ;; Compile in the list of language variables that has been collected
3089 ;; with the `c-lang-defvar' and `c-lang-setvar' macros. Note that the
3090 ;; first element of each is nil.
3091 (defconst c-lang-variable-inits (cc-eval-when-compile c-lang-variable-inits))
3092 (defconst c-emacs-variable-inits (cc-eval-when-compile c-emacs-variable-inits))
3094 ;; Make the `c-lang-setvar' variables buffer local in the current buffer.
3095 ;; These are typically standard emacs variables such as `comment-start'.
3096 (defmacro c-make-emacs-variables-local ()
3097 `(progn
3098 ,@(mapcar (lambda (init)
3099 `(make-local-variable ',(car init)))
3100 (cdr c-emacs-variable-inits))))
3102 (defun c-make-init-lang-vars-fun (mode)
3103 "Create a function that initializes all the language dependent variables
3104 for the given mode.
3106 This function should be evaluated at compile time, so that the
3107 function it returns is byte compiled with all the evaluated results
3108 from the language constants. Use the `c-init-language-vars' macro to
3109 accomplish that conveniently."
3111 (if (and (not load-in-progress)
3112 (boundp 'byte-compile-dest-file)
3113 (stringp byte-compile-dest-file))
3115 ;; No need to byte compile this lambda since the byte compiler is
3116 ;; smart enough to detect the `funcall' construct in the
3117 ;; `c-init-language-vars' macro below and compile it all straight
3118 ;; into the function that contains `c-init-language-vars'.
3119 `(lambda ()
3121 ;; This let sets up the context for `c-mode-var' and similar
3122 ;; that could be in the result from `cl-macroexpand-all'.
3123 (let ((c-buffer-is-cc-mode ',mode)
3124 current-var source-eval)
3125 (c-make-emacs-variables-local)
3126 (condition-case err
3128 (if (eq c-version-sym ',c-version-sym)
3129 (setq ,@(let ((c-buffer-is-cc-mode mode)
3130 (c-lang-const-expansion 'immediate))
3131 ;; `c-lang-const' will expand to the evaluated
3132 ;; constant immediately in `cl-macroexpand-all'
3133 ;; below.
3134 (mapcan
3135 (lambda (init)
3136 `(current-var ',(car init)
3137 ,(car init) ,(cl-macroexpand-all
3138 (elt init 1))))
3139 ;; Note: The following `append' copies the
3140 ;; first argument. That list is small, so
3141 ;; this doesn't matter too much.
3142 (append (cdr c-emacs-variable-inits)
3143 (cdr c-lang-variable-inits)))))
3145 ;; This diagnostic message isn't useful for end
3146 ;; users, so it's disabled.
3147 ;;(unless (get ',mode 'c-has-warned-lang-consts)
3148 ;; (message ,(concat "%s compiled with CC Mode %s "
3149 ;; "but loaded with %s - evaluating "
3150 ;; "language constants from source")
3151 ;; ',mode ,c-version c-version)
3152 ;; (put ',mode 'c-has-warned-lang-consts t))
3154 (setq source-eval t)
3155 (let ((init ',(append (cdr c-emacs-variable-inits)
3156 (cdr c-lang-variable-inits))))
3157 (while init
3158 (setq current-var (caar init))
3159 (set (caar init) (eval (cadar init)))
3160 (setq init (cdr init)))))
3162 (error
3163 (if current-var
3164 (message "Eval error in the `c-lang-defvar' or `c-lang-setvar' for `%s'%s: %S"
3165 current-var
3166 (if source-eval
3167 (format "\
3168 (fallback source eval - %s compiled with CC Mode %s but loaded with %s)"
3169 ',mode ,c-version c-version)
3171 err)
3172 (signal (car err) (cdr err)))))))
3174 ;; Being evaluated from source. Always use the dynamic method to
3175 ;; work well when `c-lang-defvar's in this file are reevaluated
3176 ;; interactively.
3177 `(lambda ()
3178 (require 'cc-langs)
3179 (let ((c-buffer-is-cc-mode ',mode)
3180 (init (append (cdr c-emacs-variable-inits)
3181 (cdr c-lang-variable-inits)))
3182 current-var)
3183 (c-make-emacs-variables-local)
3184 (condition-case err
3186 (while init
3187 (setq current-var (caar init))
3188 (set (caar init) (eval (cadar init)))
3189 (setq init (cdr init)))
3191 (error
3192 (if current-var
3193 (message
3194 "Eval error in the `c-lang-defvar' or `c-lang-setver' for `%s' (source eval): %S"
3195 current-var err)
3196 (signal (car err) (cdr err)))))))
3199 (defmacro c-init-language-vars (mode)
3200 "Initialize all the language dependent variables for the given mode.
3201 This macro is expanded at compile time to a form tailored for the mode
3202 in question, so MODE must be a constant. Therefore MODE is not
3203 evaluated and should not be quoted."
3204 `(funcall ,(c-make-init-lang-vars-fun mode)))
3207 (cc-provide 'cc-langs)
3209 ;;; cc-langs.el ends here