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