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