3 * Description: C programming language.
4 * Author: Markku Rossi <mtr@iki.fi>
9 (build-re '(auto char const double enum extern float int long
10 register short signed static struct typedef union unsigned void
13 /\b(auto|c(har|onst)|double|e(num|xtern)|float|int|long|register\
14 |s(hort|igned|t(atic|ruct))|typedef|un(ion|signed)|vo(id|latile))\b/;
16 /* The super state of all C highlightings. */
17 state CHighlight extends Highlight
20 if (verbose_highlighting)
21 verbose_re = /(->|<=|>=|==|!=|\&\&|\|\||!)/;
28 if (strcmp (match, "->") == 0)
30 else if (strcmp (match, "<=") == 0)
32 else if (strcmp (match, ">=") == 0)
34 else if (strcmp (match, "==") == 0)
36 else if (strcmp (match, "&&") == 0)
38 else if (strcmp (match, "||") == 0)
40 else if (strcmp (match, "!") == 0)
42 else if (strcmp (match, "!=") == 0)
47 if (!str || !language_symbol (str))
53 * The highlight entry for C highlightings. It is a bit ugly to
54 * re-implement the BEGIN and END because they must be kept in sync
55 * with the code in the `HighlightEntry'. But, since we don't support
56 * multiple heritance, we have no choice.
58 state CHighlightEntry extends CHighlight
61 if (highlight_entry_nesting++ == 0)
65 if (--highlight_entry_nesting == 0)
70 state c extends CHighlightEntry
74 * Set the regular expression that is used to highlight types from
75 * the beginning of the on-line function definition. This
76 * variable should be overwritten by each state that extends the
96 /* String constants. */
104 /* Pre-processor lines. */
110 /* Character constants. */
117 /* Keywords, but not types, goto, or case.
118 (build-re '(break continue default do else for if return sizeof
121 /\b(break|continue|d(efault|o)|else|for|if|return|s(izeof|witch)|while)\b/ {
124 keyword_face (false);
134 /* Labels. Emacs accepts also bare numbers. */
135 /^([ \t]*)([a-zA-Z0-9_]+)(:)/ {
138 reference_face (true);
140 reference_face (false);
145 /* Goto, case and the target. */
146 /\<(goto|case)\>([ \t]+)(-?[A-Za-z_0-9]+)?/ {
149 keyword_face (false);
155 reference_face (true);
157 reference_face (false);
162 * Function definitions, but only if you code with the one and only
163 * usable indentation style (GNU).
165 /^([a-zA-Z_][a-zA-Z_0-9]*)([ \t]*\()/ {
166 function_name_face (true);
168 function_name_face (false);
173 /* Function definitions and prototypes for other (loser) coding styles. */
174 /^([A-Za-z][a-zA-Z0-9_\* ]+)([ \*])([a-zA-Z_][a-zA-Z_0-9]*)([ \t]*\()/ {
180 highlight_types (garbage, type_re);
182 language_print (middle_garbage);
184 function_name_face (true);
185 language_print (function_name);
186 function_name_face (false);
188 language_print (tail_garbage);