-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcc-langs.el
3265 lines (2890 loc) · 126 KB
/
cc-langs.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; cc-langs.el --- language specific settings for CC Mode
;; Copyright (C) 1985, 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
;; 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
;; 2010, 2011 Free Software Foundation, Inc.
;; Authors: 2002- Alan Mackenzie
;; 1998- Martin Stjernholm
;; 1992-1999 Barry A. Warsaw
;; 1987 Dave Detlefs and Stewart Clamen
;; 1985 Richard M. Stallman
;; Maintainer: [email protected]
;; Created: 22-Apr-1997 (split from cc-mode.el)
;; Version: See cc-mode.el
;; Keywords: c languages oop
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, see
;; <http://www.gnu.org/licenses/>.
;;; Commentary:
;; HACKERS NOTE: There's heavy macro magic here. If you need to make
;; changes in this or other files containing `c-lang-defconst' but
;; don't want to read through the longer discussion below then read
;; this:
;;
;; o A change in a `c-lang-defconst' or `c-lang-defvar' will not take
;; effect if the file containing the mode init function (typically
;; cc-mode.el) is byte compiled.
;; o To make changes show in font locking you need to reevaluate the
;; `*-font-lock-keywords-*' constants, which normally is easiest to
;; do with M-x eval-buffer in cc-fonts.el.
;; o In either case it's necessary to reinitialize the mode to make
;; the changes show in an existing buffer.
;;; Introduction to the language dependent variable system:
;;
;; This file contains all the language dependent variables, except
;; those specific for font locking which reside in cc-fonts.el. As
;; far as possible, all the differences between the languages that CC
;; Mode supports are described with these variables only, so that the
;; code can be shared.
;;
;; The language constant system (see cc-defs.el) is used to specify
;; various language dependent info at a high level, such as lists of
;; keywords, and then from them generate - at compile time - the
;; various regexps and other low-level structures actually employed in
;; the code at runtime.
;;
;; This system is also designed to make it easy for developers of
;; derived modes to customize the source constants for new language
;; variants, without having to keep up with the exact regexps etc that
;; are used in each CC Mode version. It's possible from an external
;; package to add a new language by inheriting an existing one, and
;; then change specific constants as necessary for the new language.
;; The old values for those constants (and the values of all the other
;; high-level constants) may be used to build the new ones, and those
;; new values will in turn be used by the low-level definitions here
;; to build the runtime constants appropriately for the new language
;; in the current version of CC Mode.
;;
;; Like elsewhere in CC Mode, the existence of a doc string signifies
;; that a language constant is part of the external API, and that it
;; therefore can be used with a high confidence that it will continue
;; to work with future versions of CC Mode. Even so, it's not
;; unlikely that such constants will change meaning slightly as this
;; system is refined further; a certain degree of dependence on the CC
;; Mode version is unavoidable when hooking in at this level. Also
;; note that there's still work to be done to actually use these
;; constants everywhere inside CC Mode; there are still hardcoded
;; values in many places in the code.
;;
;; Separate packages will also benefit from the compile time
;; evaluation; the byte compiled file(s) for them will contain the
;; compiled runtime constants ready for use by (the byte compiled) CC
;; Mode, and the source definitions in this file don't have to be
;; loaded then. However, if a byte compiled package is loaded that
;; has been compiled with a different version of CC Mode than the one
;; currently loaded, then the compiled-in values will be discarded and
;; new ones will be built when the mode is initialized. That will
;; automatically trig a load of the file(s) containing the source
;; definitions (i.e. this file and/or cc-fonts.el) if necessary.
;;
;; A small example of a derived mode is available at
;; <http://cc-mode.sourceforge.net/derived-mode-ex.el>. It also
;; contains some useful hints for derived mode developers.
;;; Using language variables:
;;
;; The `c-lang-defvar' forms in this file comprise the language
;; variables that CC Mode uses. It does not work to use
;; `c-lang-defvar' anywhere else (which isn't much of a limitation
;; since these variables sole purpose is to interface with the CC Mode
;; core functions). The values in these `c-lang-defvar's are not
;; evaluated right away but instead collected to a single large `setq'
;; that can be inserted for a particular language with the
;; `c-init-language-vars' macro.
;; This file is only required at compile time, or when not running
;; from byte compiled files, or when the source definitions for the
;; language constants are requested.
;;; Code:
(eval-when-compile
(let ((load-path
(if (and (boundp 'byte-compile-dest-file)
(stringp byte-compile-dest-file))
(cons (file-name-directory byte-compile-dest-file) load-path)
load-path)))
(load "cc-bytecomp" nil t)))
(cc-require 'cc-defs)
(cc-require 'cc-vars)
;; This file is not always loaded. See note above.
(cc-external-require 'cl)
;;; Setup for the `c-lang-defvar' system.
(eval-and-compile
;; These are used to collect the init forms from the subsequent
;; `c-lang-defvar' and `c-lang-setvar'. They are used to build the
;; lambda in `c-make-init-lang-vars-fun' below, and to build `defvar's
;; and `make-variable-buffer-local's in cc-engine and
;; `make-local-variable's in `c-init-language-vars-for'.
(defvar c-lang-variable-inits nil)
(defvar c-lang-variable-inits-tail nil)
(setq c-lang-variable-inits (list nil)
c-lang-variable-inits-tail c-lang-variable-inits)
(defvar c-emacs-variable-inits nil)
(defvar c-emacs-variable-inits-tail nil)
(setq c-emacs-variable-inits (list nil)
c-emacs-variable-inits-tail c-emacs-variable-inits))
(defmacro c-lang-defvar (var val &optional doc)
"Declares the buffer local variable VAR to get the value VAL. VAL is
evaluated and assigned at mode initialization. More precisely, VAL is
evaluated and bound to VAR when the result from the macro
`c-init-language-vars' is evaluated.
`c-lang-const' is typically used in VAL to get the right value for the
language being initialized, and such calls will be macro expanded to
the evaluated constant value at compile time."
(when (and (not doc)
(eq (car-safe val) 'c-lang-const)
(eq (nth 1 val) var)
(not (nth 2 val)))
;; Special case: If there's no docstring and the value is a
;; simple (c-lang-const foo) where foo is the same name as VAR
;; then take the docstring from the language constant foo.
(setq doc (get (intern (symbol-name (nth 1 val)) c-lang-constants)
'variable-documentation)))
(or (stringp doc)
(setq doc nil))
(let ((elem (assq var (cdr c-lang-variable-inits))))
(if elem
(setcdr elem (list val doc))
(setcdr c-lang-variable-inits-tail (list (list var val doc)))
(setq c-lang-variable-inits-tail (cdr c-lang-variable-inits-tail))))
;; Return the symbol, like the other def* forms.
`',var)
(defmacro c-lang-setvar (var val)
"Causes the variable VAR to be made buffer local and to get set to the
value VAL. VAL is evaluated and assigned at mode initialization. More
precisely, VAL is evaluated and bound to VAR when the result from the
macro `c-init-language-vars' is evaluated. VAR is typically a standard
Emacs variable like `comment-start'.
`c-lang-const' is typically used in VAL to get the right value for the
language being initialized, and such calls will be macro expanded to
the evaluated constant value at compile time."
(let ((elem (assq var (cdr c-emacs-variable-inits))))
(if elem
(setcdr elem (list val)) ; Maybe remove "list", sometime. 2006-07-19
(setcdr c-emacs-variable-inits-tail (list (list var val)))
(setq c-emacs-variable-inits-tail (cdr c-emacs-variable-inits-tail))))
;; Return the symbol, like the other def* forms.
`',var)
(put 'c-lang-defvar 'lisp-indent-function 'defun)
(eval-after-load "edebug"
'(def-edebug-spec c-lang-defvar
(&define name def-form &optional stringp)))
(eval-and-compile
;; Some helper functions used when building the language constants.
(defun c-filter-ops (ops opgroup-filter op-filter &optional xlate)
;; Extract a subset of the operators in the list OPS in a DWIM:ey
;; way. The return value is a plain list of operators:
;;
;; OPS either has the structure of `c-operators', is a single
;; group in `c-operators', or is a plain list of operators.
;;
;; OPGROUP-FILTER specifies how to select the operator groups. It
;; can be t to choose all groups, a list of group type symbols
;; (such as 'prefix) to accept, or a function which will be called
;; with the group symbol for each group and should return non-nil
;; if that group is to be included.
;;
;; If XLATE is given, it's a function which is called for each
;; matching operator and its return value is collected instead.
;; If it returns a list, the elements are spliced directly into
;; the final result, which is returned as a list with duplicates
;; removed using `equal'.
;;
;; `c-mode-syntax-table' for the current mode is in effect during
;; the whole procedure.
(unless (listp (car-safe ops))
(setq ops (list ops)))
(cond ((eq opgroup-filter t)
(setq opgroup-filter (lambda (opgroup) t)))
((not (functionp opgroup-filter))
(setq opgroup-filter `(lambda (opgroup)
(memq opgroup ',opgroup-filter)))))
(cond ((eq op-filter t)
(setq op-filter (lambda (op) t)))
((stringp op-filter)
(setq op-filter `(lambda (op)
(string-match ,op-filter op)))))
(unless xlate
(setq xlate 'identity))
(c-with-syntax-table (c-lang-const c-mode-syntax-table)
(delete-duplicates
(mapcan (lambda (opgroup)
(when (if (symbolp (car opgroup))
(when (funcall opgroup-filter (car opgroup))
(setq opgroup (cdr opgroup))
t)
t)
(mapcan (lambda (op)
(when (funcall op-filter op)
(let ((res (funcall xlate op)))
(if (listp res) res (list res)))))
opgroup)))
ops)
:test 'equal))))
;;; Various mode specific values that aren't language related.
(c-lang-defconst c-mode-menu
;; The definition for the mode menu. The menu title is prepended to
;; this before it's fed to `easy-menu-define'.
t `(["Comment Out Region" comment-region
(c-fn-region-is-active-p)]
["Uncomment Region" (comment-region (region-beginning)
(region-end) '(4))
(c-fn-region-is-active-p)]
["Indent Expression" c-indent-exp
(memq (char-after) '(?\( ?\[ ?\{))]
["Indent Line or Region" c-indent-line-or-region t]
["Fill Comment Paragraph" c-fill-paragraph t]
"----"
["Backward Statement" c-beginning-of-statement t]
["Forward Statement" c-end-of-statement t]
,@(when (c-lang-const c-opt-cpp-prefix)
;; Only applicable if there's a cpp preprocessor.
`(["Up Conditional" c-up-conditional t]
["Backward Conditional" c-backward-conditional t]
["Forward Conditional" c-forward-conditional t]
"----"
["Macro Expand Region" c-macro-expand
(c-fn-region-is-active-p)]
["Backslashify" c-backslash-region
(c-fn-region-is-active-p)]))
"----"
("Style..."
["Set Style..." c-set-style t]
["Show Current Style Name" (message
"Style Name: %s"
c-indentation-style) t]
["Guess Style from this Buffer" c-guess-buffer-no-install t]
["Install the Last Guessed Style" c-guess-install
(and c-guess-guessed-offsets-alist
c-guess-guessed-basic-offset) ]
["View the Last Guessed Style" c-guess-view
(and c-guess-guessed-offsets-alist
c-guess-guessed-basic-offset) ])
"----"
("Toggle..."
["Syntactic indentation" c-toggle-syntactic-indentation t]
["Electric mode" c-toggle-electric-state t]
["Auto newline" c-toggle-auto-newline t]
["Hungry delete" c-toggle-hungry-state t]
["Subword mode" c-subword-mode t])))
;;; Syntax tables.
(defun c-populate-syntax-table (table)
"Populate the given syntax table as necessary for a C-like language.
This includes setting ' and \" as string delimiters, and setting up
the comment syntax to handle both line style \"//\" and block style
\"/*\" \"*/\" comments."
(modify-syntax-entry ?_ "_" table)
(modify-syntax-entry ?\\ "\\" table)
(modify-syntax-entry ?+ "." table)
(modify-syntax-entry ?- "." table)
(modify-syntax-entry ?= "." table)
(modify-syntax-entry ?% "." table)
(modify-syntax-entry ?< "." table)
(modify-syntax-entry ?> "." table)
(modify-syntax-entry ?& "." table)
(modify-syntax-entry ?| "." table)
(modify-syntax-entry ?\' "\"" table)
(modify-syntax-entry ?\240 "." table)
;; Set up block and line oriented comments. The new C
;; standard mandates both comment styles even in C, so since
;; all languages now require dual comments, we make this the
;; default.
(cond
;; XEmacs
((memq '8-bit c-emacs-features)
(modify-syntax-entry ?/ ". 1456" table)
(modify-syntax-entry ?* ". 23" table))
;; Emacs
((memq '1-bit c-emacs-features)
(modify-syntax-entry ?/ ". 124b" table)
(modify-syntax-entry ?* ". 23" table))
;; incompatible
(t (error "CC Mode is incompatible with this version of Emacs")))
(modify-syntax-entry ?\n "> b" table)
;; Give CR the same syntax as newline, for selective-display
(modify-syntax-entry ?\^m "> b" table))
(c-lang-defconst c-make-mode-syntax-table
"Functions that generates the mode specific syntax tables.
The syntax tables aren't stored directly since they're quite large."
t `(lambda ()
(let ((table (make-syntax-table)))
(c-populate-syntax-table table)
;; Mode specific syntaxes.
,(cond ((or (c-major-mode-is 'objc-mode) (c-major-mode-is 'java-mode))
;; Let '@' be part of symbols in ObjC to cope with
;; its compiler directives as single keyword tokens.
;; This is then necessary since it's assumed that
;; every keyword is a single symbol.
`(modify-syntax-entry ?@ "_" table))
((c-major-mode-is 'pike-mode)
`(modify-syntax-entry ?@ "." table)))
table)))
(c-lang-defconst c-mode-syntax-table
;; The syntax tables in evaluated form. Only used temporarily when
;; the constants in this file are evaluated.
t (funcall (c-lang-const c-make-mode-syntax-table)))
(c-lang-defconst c++-make-template-syntax-table
;; A variant of `c++-mode-syntax-table' that defines `<' and `>' as
;; parenthesis characters. Used temporarily when template argument
;; lists are parsed. Note that this encourages incorrect parsing of
;; templates since they might contain normal operators that uses the
;; '<' and '>' characters. Therefore this syntax table might go
;; away when CC Mode handles templates correctly everywhere. WHILE
;; THIS SYNTAX TABLE IS CURRENT, `c-parse-state' MUST _NOT_ BE
;; CALLED!!!
t nil
(java c++) `(lambda ()
(let ((table (funcall ,(c-lang-const c-make-mode-syntax-table))))
(modify-syntax-entry ?< "(>" table)
(modify-syntax-entry ?> ")<" table)
table)))
(c-lang-defvar c++-template-syntax-table
(and (c-lang-const c++-make-template-syntax-table)
(funcall (c-lang-const c++-make-template-syntax-table))))
(c-lang-defconst c-make-no-parens-syntax-table
;; A variant of the standard syntax table which is used to find matching
;; "<"s and ">"s which have been marked as parens using syntax table
;; properties. The other paren characters (e.g. "{", ")" "]") are given a
;; non-paren syntax here. so that the list commands will work on "< ... >"
;; even when there's unbalanced other parens inside them.
;;
;; This variable is nil for languages which don't have template stuff.
t (if (c-lang-const c-recognize-<>-arglists)
`(lambda ()
(let ((table (funcall ,(c-lang-const c-make-mode-syntax-table))))
(modify-syntax-entry ?\( "." table)
(modify-syntax-entry ?\) "." table)
(modify-syntax-entry ?\[ "." table)
(modify-syntax-entry ?\] "." table)
(modify-syntax-entry ?\{ "." table)
(modify-syntax-entry ?\} "." table)
table))))
(c-lang-defvar c-no-parens-syntax-table
(and (c-lang-const c-make-no-parens-syntax-table)
(funcall (c-lang-const c-make-no-parens-syntax-table))))
(c-lang-defconst c-identifier-syntax-modifications
"A list that describes the modifications that should be done to the
mode syntax table to get a syntax table that matches all identifiers
and keywords as words.
The list is just like the one used in `font-lock-defaults': Each
element is a cons where the car is the character to modify and the cdr
the new syntax, as accepted by `modify-syntax-entry'."
;; The $ character is not allowed in most languages (one exception
;; is Java which allows it for legacy reasons) but we still classify
;; it as an identifier character since it's often used in various
;; machine generated identifiers.
t '((?_ . "w") (?$ . "w"))
(objc java) (append '((?@ . "w"))
(c-lang-const c-identifier-syntax-modifications))
awk '((?_ . "w")))
(c-lang-defvar c-identifier-syntax-modifications
(c-lang-const c-identifier-syntax-modifications))
(c-lang-defvar c-identifier-syntax-table
(let ((table (copy-syntax-table (c-mode-var "mode-syntax-table")))
(mods c-identifier-syntax-modifications)
mod)
(while mods
(setq mod (car mods)
mods (cdr mods))
(modify-syntax-entry (car mod) (cdr mod) table))
table)
"Syntax table built on the mode syntax table but additionally
classifies symbol constituents like '_' and '$' as word constituents,
so that all identifiers are recognized as words.")
(c-lang-defconst c-get-state-before-change-functions
;; For documentation see the following c-lang-defvar of the same name.
;; The value here may be a list of functions or a single function.
t nil
c++ '(c-extend-region-for-CPP
c-before-change-check-<>-operators
c-invalidate-macro-cache)
(c objc) '(c-extend-region-for-CPP c-invalidate-macro-cache)
;; java 'c-before-change-check-<>-operators
awk 'c-awk-record-region-clear-NL)
(c-lang-defvar c-get-state-before-change-functions
(let ((fs (c-lang-const c-get-state-before-change-functions)))
(if (listp fs)
fs
(list fs)))
"If non-nil, a list of functions called from c-before-change-hook.
Typically these will record enough state to allow
`c-before-font-lock-function' to extend the region to fontify,
and may do such things as removing text-properties which must be
recalculated.
These functions will be run in the order given. Each of them
takes 2 parameters, the BEG and END supplied to every
before-change function; on entry, the buffer will have been
widened and match-data will have been saved; point is undefined
on both entry and exit; the return value is ignored.
The functions are called even when font locking isn't enabled.
When the mode is initialized, the functions are called with
parameters \(point-min) and \(point-max).")
(c-lang-defconst c-before-font-lock-functions
;; For documentation see the following c-lang-defvar of the same name.
;; The value here may be a list of functions or a single function.
t 'c-change-set-fl-decl-start
(c c++ objc) '(c-neutralize-syntax-in-and-mark-CPP
c-change-set-fl-decl-start)
awk 'c-awk-extend-and-syntax-tablify-region)
(c-lang-defvar c-before-font-lock-functions
(let ((fs (c-lang-const c-before-font-lock-functions)))
(if (listp fs)
fs
(list fs)))
"If non-nil, a list of functions called just before font locking.
Typically they will extend the region about to be fontified \(see
below) and will set `syntax-table' text properties on the region.
These functions will be run in the order given. Each of them
takes 3 parameters, the BEG, END, and OLD-LEN supplied to every
after-change function; point is undefined on both entry and exit;
on entry, the buffer will have been widened and match-data will
have been saved; the return value is ignored.
The functions may extend the region to be fontified by setting the
buffer local variables c-new-BEG and c-new-END.
The functions are called even when font locking is disabled.
When the mode is initialized, these functions are called with
parameters \(point-min), \(point-max) and <buffer size>.")
(c-lang-defconst c-before-context-fontification-functions
awk nil
t 'c-context-set-fl-decl-start)
;; For documentation see the following c-lang-defvar of the same name.
;; The value here may be a list of functions or a single function.
(c-lang-defvar c-before-context-fontification-functions
(let ((fs (c-lang-const c-before-context-fontification-functions)))
(if (listp fs)
fs
(list fs)))
"If non-nil, a list of functions called just before context (or
other non-change) fontification is done. Typically they will
extend the region.
These functions will be run in the order given. Each of them
takes 2 parameters, the BEG and END of the region to be
fontified. Point is undefined on both entry and exit. On entry,
the buffer will have been widened and match-data will have been
saved; the return value is a cons of the adjusted
region, (NEW-BEG . NEW-END).")
;;; Syntactic analysis ("virtual semicolons") for line-oriented languages (AWK).
(c-lang-defconst c-at-vsemi-p-fn
"Contains a function \"Is there a virtual semicolon at POS or point?\".
Such a function takes one optional parameter, a buffer position (defaults to
point), and returns nil or t. This variable contains nil for languages which
don't have EOL terminated statements. "
t nil
(c c++ objc) 'c-at-macro-vsemi-p
awk 'c-awk-at-vsemi-p)
(c-lang-defvar c-at-vsemi-p-fn (c-lang-const c-at-vsemi-p-fn))
(c-lang-defconst c-vsemi-status-unknown-p-fn
"Contains a function \"are we unsure whether there is a virtual semicolon on this line?\".
The (admittedly kludgy) purpose of such a function is to prevent an infinite
recursion in c-beginning-of-statement-1 when point starts at a `while' token.
The function MUST NOT UNDER ANY CIRCUMSTANCES call c-beginning-of-statement-1,
even indirectly. This variable contains nil for languages which don't have
EOL terminated statements."
t nil
(c c++ objc) 'c-macro-vsemi-status-unknown-p
awk 'c-awk-vsemi-status-unknown-p)
(c-lang-defvar c-vsemi-status-unknown-p-fn
(c-lang-const c-vsemi-status-unknown-p-fn))
;;; Lexer-level syntax (identifiers, tokens etc).
(c-lang-defconst c-has-bitfields
"Whether the language has bitfield declarations."
t nil
(c c++ objc) t)
(c-lang-defvar c-has-bitfields (c-lang-const c-has-bitfields))
(c-lang-defconst c-modified-constant
"Regexp that matches a \"modified\" constant literal such as \"L'a'\",
a \"long character\". In particular, this recognizes forms of constant
which c-backward-sexp needs to be called twice to move backwards over."
t nil
(c c++ objc) "L'\\([^\\'\t\f\n\r]\\|\\\\.\\)'")
;; FIXME!!! Extend this to cover strings, if needed. 2008-04-11
(c-lang-defvar c-modified-constant (c-lang-const c-modified-constant))
(c-lang-defconst c-symbol-start
"Regexp that matches the start of a symbol, i.e. any identifier or
keyword. It's unspecified how far it matches. Does not contain a \\|
operator at the top level."
t (concat "[" c-alpha "_]")
java (concat "[" c-alpha "_@]")
objc (concat "[" c-alpha "@]")
pike (concat "[" c-alpha "_`]"))
(c-lang-defvar c-symbol-start (c-lang-const c-symbol-start))
(c-lang-defconst c-symbol-chars
"Set of characters that can be part of a symbol.
This is of the form that fits inside [ ] in a regexp."
;; Pike note: With the backquote identifiers this would include most
;; operator chars too, but they are handled with other means instead.
t (concat c-alnum "_$")
objc (concat c-alnum "_$@"))
(c-lang-defvar c-symbol-chars (c-lang-const c-symbol-chars))
(c-lang-defconst c-symbol-key
"Regexp matching identifiers and keywords (with submatch 0). Assumed
to match if `c-symbol-start' matches on the same position."
t (concat (c-lang-const c-symbol-start)
"[" (c-lang-const c-symbol-chars) "]*")
pike (concat
;; Use the value from C here since the operator backquote is
;; covered by the other alternative.
(c-lang-const c-symbol-key c)
"\\|"
(c-make-keywords-re nil
(c-lang-const c-overloadable-operators))))
(c-lang-defvar c-symbol-key (c-lang-const c-symbol-key))
(c-lang-defconst c-symbol-key-depth
;; Number of regexp grouping parens in `c-symbol-key'.
t (regexp-opt-depth (c-lang-const c-symbol-key)))
(c-lang-defconst c-nonsymbol-chars
"This is the set of chars that can't be part of a symbol, i.e. the
negation of `c-symbol-chars'."
t (concat "^" (c-lang-const c-symbol-chars)))
(c-lang-defvar c-nonsymbol-chars (c-lang-const c-nonsymbol-chars))
(c-lang-defconst c-nonsymbol-key
"Regexp that matches any character that can't be part of a symbol.
It's usually appended to other regexps to avoid matching a prefix.
It's assumed to not contain any submatchers."
;; The same thing regarding Unicode identifiers applies here as to
;; `c-symbol-key'.
t (concat "[" (c-lang-const c-nonsymbol-chars) "]"))
(c-lang-defconst c-identifier-ops
"The operators that make up fully qualified identifiers. nil in
languages that don't have such things. See `c-operators' for a
description of the format. Binary operators can concatenate symbols,
e.g. \"::\" in \"A::B::C\". Prefix operators can precede identifiers,
e.g. \"~\" in \"~A::B\". Other types of operators aren't supported.
This value is by default merged into `c-operators'."
t nil
c++ '((prefix "~" "??-" "compl")
(right-assoc "::")
(prefix "::"))
;; Java has "." to concatenate identifiers but it's also used for
;; normal indexing. There's special code in the Java font lock
;; rules to fontify qualified identifiers based on the standard
;; naming conventions. We still define "." here to make
;; `c-forward-name' move over as long names as possible which is
;; necessary to e.g. handle throws clauses correctly.
java '((left-assoc "."))
idl '((left-assoc "::")
(prefix "::"))
pike '((left-assoc "::")
(prefix "::")
(left-assoc ".")))
(c-lang-defconst c-opt-identifier-concat-key
;; Appendable adorned regexp matching the operators that join
;; symbols to fully qualified identifiers, or nil in languages that
;; don't have such things.
;;
;; This was a docstring constant in 5.30. It still works but is now
;; considered internal - change `c-identifier-ops' instead.
t (let ((ops (c-filter-ops (c-lang-const c-identifier-ops)
'(left-assoc right-assoc)
t)))
(when ops
(c-make-keywords-re 'appendable ops))))
(c-lang-defvar c-opt-identifier-concat-key
(c-lang-const c-opt-identifier-concat-key)
'dont-doc)
(c-lang-defconst c-opt-identifier-concat-key-depth
;; Number of regexp grouping parens in `c-opt-identifier-concat-key'.
t (regexp-opt-depth (c-lang-const c-opt-identifier-concat-key)))
(c-lang-defconst c-opt-identifier-prefix-key
;; Appendable adorned regexp matching operators that might precede
;; an identifier and that are part of the identifier in that case.
;; nil in languages without such things.
t (let ((ops (c-filter-ops (c-lang-const c-identifier-ops)
'(prefix)
t)))
(when ops
(c-make-keywords-re 'appendable ops))))
(c-lang-defconst c-after-id-concat-ops
"Operators that can occur after a binary operator on `c-identifier-ops'
in identifiers. nil in languages that don't have such things.
Operators here should also have appropriate entries in `c-operators' -
it's not taken care of by default."
t nil
;; '~' for destructors in C++, '*' for member pointers.
c++ '("~" "*")
;; In Java we recognize '*' to deal with "foo.bar.*" that can occur
;; in import declarations. (This will also match bogus things like
;; "foo.*bar" but we don't bother.)
java '("*"))
(c-lang-defconst c-opt-after-id-concat-key
;; Regexp that must match the token after
;; `c-opt-identifier-concat-key' for it to be considered an
;; identifier concatenation operator (which e.g. causes the
;; preceding identifier to be fontified as a reference). Assumed to
;; be a string if `c-opt-identifier-concat-key' is.
;;
;; This was a docstring constant in 5.30. It still works but is now
;; considered internal - change `c-after-id-concat-ops' instead.
t (concat (c-lang-const c-symbol-start)
(if (c-lang-const c-after-id-concat-ops)
(concat "\\|" (c-make-keywords-re 'appendable
(c-lang-const c-after-id-concat-ops)))
"")))
(c-lang-defconst c-identifier-start
"Regexp that matches the start of an (optionally qualified) identifier.
It should also match all keywords. It's unspecified how far it
matches."
t (concat (c-lang-const c-symbol-start)
(if (c-lang-const c-opt-identifier-prefix-key)
(concat "\\|"
(c-lang-const c-opt-identifier-prefix-key))
"")))
(c-lang-defvar c-identifier-start (c-lang-const c-identifier-start))
(c-lang-defconst c-identifier-key
"Regexp matching a fully qualified identifier, like \"A::B::c\" in
C++. It does not recognize the full range of syntactic whitespace
between the tokens; `c-forward-name' has to be used for that. It
should also not match identifiers containing parenthesis groupings,
e.g. identifiers with template arguments such as \"A<X,Y>\" in C++."
;; This regexp is more complex than strictly necessary to ensure
;; that it can be matched with a minimum of backtracking.
t (concat (if (c-lang-const c-opt-identifier-prefix-key)
(concat
"\\("
(c-lang-const c-opt-identifier-prefix-key)
(c-lang-const c-simple-ws) "*"
"\\)?")
"")
"\\(" (c-lang-const c-symbol-key) "\\)"
(if (c-lang-const c-opt-identifier-concat-key)
(concat
"\\("
(c-lang-const c-simple-ws) "*"
(c-lang-const c-opt-identifier-concat-key)
(c-lang-const c-simple-ws) "*"
(if (c-lang-const c-after-id-concat-ops)
(concat
"\\("
(c-make-keywords-re 'appendable
(c-lang-const c-after-id-concat-ops))
(concat
;; For flexibility, consider the symbol match
;; optional if we've hit a
;; `c-after-id-concat-ops' operator. This is
;; also necessary to handle the "*" that can
;; end import declaration identifiers in Java.
"\\("
(c-lang-const c-simple-ws) "*"
"\\(" (c-lang-const c-symbol-key) "\\)"
"\\)?")
"\\|"
"\\(" (c-lang-const c-symbol-key) "\\)"
"\\)")
(concat "\\(" (c-lang-const c-symbol-key) "\\)"))
"\\)*")
"")))
(c-lang-defvar c-identifier-key (c-lang-const c-identifier-key))
(c-lang-defconst c-identifier-last-sym-match
;; This was a docstring constant in 5.30 but it's no longer used.
;; It's only kept to avoid breaking third party code.
;;
;; Used to identify the submatch in `c-identifier-key' that
;; surrounds the last symbol in the qualified identifier. It's a
;; list of submatch numbers, of which the first that has a match is
;; taken. It's assumed that at least one does when the regexp has
;; matched.
t nil)
(c-lang-defconst c-string-escaped-newlines
"Set if the language support backslash escaped newlines inside string
literals."
t nil
(c c++ objc pike) t)
(c-lang-defvar c-string-escaped-newlines
(c-lang-const c-string-escaped-newlines))
(c-lang-defconst c-multiline-string-start-char
"Set if the language supports multiline string literals without escaped
newlines. If t, all string literals are multiline. If a character,
only literals where the open quote is immediately preceded by that
literal are multiline."
t nil
pike ?#)
(c-lang-defvar c-multiline-string-start-char
(c-lang-const c-multiline-string-start-char))
(c-lang-defconst c-opt-cpp-symbol
"The symbol which starts preprocessor constructs when in the margin."
t "#"
(java awk) nil)
(c-lang-defvar c-opt-cpp-symbol (c-lang-const c-opt-cpp-symbol))
(c-lang-defconst c-opt-cpp-prefix
"Regexp matching the prefix of a cpp directive in the languages that
normally use that macro preprocessor. Tested at bol or at boi.
Assumed to not contain any submatches or \\| operators."
;; TODO (ACM, 2005-04-01). Amend the following to recognize escaped NLs;
;; amend all uses of c-opt-cpp-prefix which count regexp-depth.
t "\\s *#\\s *"
(java awk) nil)
(c-lang-defvar c-opt-cpp-prefix (c-lang-const c-opt-cpp-prefix))
(c-lang-defconst c-anchored-cpp-prefix
"Regexp matching the prefix of a cpp directive anchored to BOL,
in the languages that have a macro preprocessor."
t "^\\s *\\(#\\)\\s *"
(java awk) nil)
(c-lang-defvar c-anchored-cpp-prefix (c-lang-const c-anchored-cpp-prefix))
(c-lang-defconst c-opt-cpp-start
"Regexp matching the prefix of a cpp directive including the directive
name, or nil in languages without preprocessor support. The first
submatch surrounds the directive name."
t (if (c-lang-const c-opt-cpp-prefix)
(concat (c-lang-const c-opt-cpp-prefix)
"\\([" c-alnum "]+\\)"))
;; Pike, being a scripting language, recognizes hash-bangs too.
pike (concat (c-lang-const c-opt-cpp-prefix)
"\\([" c-alnum "]+\\|!\\)"))
(c-lang-defvar c-opt-cpp-start (c-lang-const c-opt-cpp-start))
(c-lang-defconst c-cpp-message-directives
"List of cpp directives (without the prefix) that are followed by a
string message."
t (if (c-lang-const c-opt-cpp-prefix)
'("error"))
(c c++ objc pike) '("error" "warning"))
(c-lang-defconst c-cpp-include-directives
"List of cpp directives (without the prefix) that are followed by a
file name in angle brackets or quotes."
t (if (c-lang-const c-opt-cpp-prefix)
'("include"))
objc '("include" "import"))
(c-lang-defconst c-opt-cpp-macro-define
"Cpp directive (without the prefix) that is followed by a macro
definition, or nil if the language doesn't have any."
t (if (c-lang-const c-opt-cpp-prefix)
"define"))
(c-lang-defvar c-opt-cpp-macro-define
(c-lang-const c-opt-cpp-macro-define))
(c-lang-defconst c-opt-cpp-macro-define-start
;; Regexp matching everything up to the macro body of a cpp define, or the
;; end of the logical line if there is none. Submatch 1 is the name of the
;; macro. Set if c-opt-cpp-macro-define is.
t (if (c-lang-const c-opt-cpp-macro-define)
(concat (c-lang-const c-opt-cpp-prefix)
(c-lang-const c-opt-cpp-macro-define)
"[ \t]+\\(\\(\\sw\\|_\\)+\\)\\(\([^\)]*\)\\)?"
;; ^ ^ #defined name
"\\([ \t]\\|\\\\\n\\)*")))
(c-lang-defvar c-opt-cpp-macro-define-start
(c-lang-const c-opt-cpp-macro-define-start))
(c-lang-defconst c-opt-cpp-macro-define-id
;; Regexp matching everything up to the end of the identifier defined
;; by a cpp define.
t (if (c-lang-const c-opt-cpp-macro-define)
(concat (c-lang-const c-opt-cpp-prefix) ; #
(c-lang-const c-opt-cpp-macro-define) ; define
"[ \t]+\\(\\sw\\|_\\)+")))
(c-lang-defvar c-opt-cpp-macro-define-id
(c-lang-const c-opt-cpp-macro-define-id))
(c-lang-defconst c-cpp-expr-directives
"List of cpp directives (without the prefix) that are followed by an
expression."
t (if (c-lang-const c-opt-cpp-prefix)
'("if" "elif")))
(c-lang-defconst c-cpp-expr-intro-re
"Regexp which matches the start of a CPP directive which contains an
expression, or nil if there aren't any in the language."
t (if (c-lang-const c-cpp-expr-directives)
(concat
(c-lang-const c-opt-cpp-prefix)
(c-make-keywords-re t (c-lang-const c-cpp-expr-directives)))))
(c-lang-defvar c-cpp-expr-intro-re
(c-lang-const c-cpp-expr-intro-re))
(c-lang-defconst c-cpp-expr-functions
"List of functions in cpp expressions."
t (if (c-lang-const c-opt-cpp-prefix)
'("defined"))
pike '("defined" "efun" "constant"))
(c-lang-defconst c-assignment-operators
"List of all assignment operators."
t '("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=")
java (append (c-lang-const c-assignment-operators)
'(">>>="))
c++ (append (c-lang-const c-assignment-operators)
'("and_eq" "or_eq" "xor_eq" "??!=" "??'="))
idl nil)
(c-lang-defconst c-operators
"List describing all operators, along with their precedence and
associativity. The order in the list corresponds to the precedence of
the operators: The operators in each element are a group with the same
precedence, and the group has higher precedence than the groups in all
following elements. The car of each element describes the type of the
operator group, and the cdr is a list of the operator tokens in it.
The operator group types are:
'prefix Unary prefix operators.
'postfix Unary postfix operators.
'postfix-if-paren
Unary postfix operators if and only if the chars have
parenthesis syntax.
'left-assoc Binary left associative operators (i.e. a+b+c means (a+b)+c).
'right-assoc Binary right associative operators (i.e. a=b=c means a=(b=c)).
'right-assoc-sequence
Right associative operator that constitutes of a
sequence of tokens that separate expressions. All the
tokens in the group are in this case taken as
describing the sequence in one such operator, and the
order between them is therefore significant.
Operators containing a character with paren syntax are taken to match
with a corresponding open/close paren somewhere else. A postfix
operator with close paren syntax is taken to end a postfix expression
started somewhere earlier, rather than start a new one at point. Vice
versa for prefix operators with open paren syntax.
Note that operators like \".\" and \"->\" which in language references
often are described as postfix operators are considered binary here,
since CC Mode treats every identifier as an expression."
;; There's currently no code in CC Mode that exploits all the info
;; in this variable; precedence, associativity etc are present as a
;; preparation for future work.
t `(;; Preprocessor.
,@(when (c-lang-const c-opt-cpp-prefix)
`((prefix "#"
,@(when (c-major-mode-is '(c-mode c++-mode))
'("%:" "??=")))
(left-assoc "##"
,@(when (c-major-mode-is '(c-mode c++-mode))
'("%:%:" "??=??=")))))
;; Primary.
,@(c-lang-const c-identifier-ops)
,@(cond ((or (c-major-mode-is 'c++-mode) (c-major-mode-is 'java-mode))
`((postfix-if-paren "<" ">"))) ; Templates.
((c-major-mode-is 'pike-mode)
`((prefix "global" "predef")))
((c-major-mode-is 'java-mode)
`((prefix "super"))))
;; Postfix.
,@(when (c-major-mode-is 'c++-mode)
;; The following need special treatment.
`((prefix "dynamic_cast" "static_cast"
"reinterpret_cast" "const_cast" "typeid")))
(left-assoc "."
,@(unless (c-major-mode-is 'java-mode)
'("->")))
(postfix "++" "--" "[" "]" "(" ")"
,@(when (c-major-mode-is '(c-mode c++-mode))
'("<:" ":>" "??(" "??)")))
;; Unary.
(prefix "++" "--" "+" "-" "!" "~"
,@(when (c-major-mode-is 'c++-mode) '("not" "compl"))
,@(when (c-major-mode-is '(c-mode c++-mode))
'("*" "&" "sizeof" "??-"))
,@(when (c-major-mode-is 'objc-mode)
'("@selector" "@protocol" "@encode"))
;; The following need special treatment.
,@(cond ((c-major-mode-is 'c++-mode)
'("new" "delete"))
((c-major-mode-is 'java-mode)
'("new"))
((c-major-mode-is 'pike-mode)
'("class" "lambda" "catch" "throw" "gauge")))
"(" ")" ; Cast.
,@(when (c-major-mode-is 'pike-mode)
'("[" "]"))) ; Type cast.
;; Member selection.
,@(when (c-major-mode-is 'c++-mode)
`((left-assoc ".*" "->*")))
;; Multiplicative.
(left-assoc "*" "/" "%")
;; Additive.
(left-assoc "+" "-")
;; Shift.
(left-assoc "<<" ">>"
,@(when (c-major-mode-is 'java-mode)