1 rizwank 1.1 /*
2 * C preprocessor line handling. This is shared between C, C++, and
3 * Objective-C highlighting rules.
4 */
5
6 state c_ppline extends CHighlight
7 {
8 BEGIN {
9 require_state (c);
10 }
11 /* Comments within a pre-processor line. */
12 /\/\*/ {
13 comment_face (true);
14 language_print ($0);
15 call (c_comment);
16 comment_face (false);
17 }
18 /* Include line. */
19 /(include)([ \t]+)/ {
20 reference_face (true);
21 language_print ($1);
22 rizwank 1.1 reference_face (false);
23 language_print ($2);
24 call (c_ppline_include);
25 return;
26 }
27 /* Define line. */
28 /(define)([ \t]+)/ {
29 reference_face (true);
30 language_print ($1);
31 reference_face (false);
32 language_print ($2);
33 call (c_ppline_define);
34 return;
35 }
36 /* Simple directives:
37 (build-re '(undef if ifdef ifndef endif elif else line error pragma))
38 */
39 /\b(e(l(if|se)|ndif|rror)|if(|def|ndef)|line|pragma|undef)\b/ {
40 reference_face (true);
41 language_print ($0);
42 reference_face (false);
43 rizwank 1.1 call (c_ppline_tokensequence);
44 return;
45 }
46 /* An unknown pre-processor directive. */
47 /[a-zA-Z_][^ \t\n]*/ {
48 reference_face (true);
49 language_print ($0);
50 reference_face (false);
51 call (c_ppline_tokensequence);
52 return;
53 }
54 /\n/ {
55 language_print ($0);
56 return;
57 }
58 }
59
60 state c_ppline_include extends CHighlight
61 {
62 /\"/ {
63 string_face (true);
64 rizwank 1.1 language_print ($0);
65 call (c_string);
66 string_face (false);
67 call (c_ppline_comments_strings_chars);
68 return;
69 }
70 /<[^<>]+>/ {
71 string_face (true);
72 language_print ($0);
73 string_face (false);
74 call (c_ppline_comments_strings_chars);
75 return;
76 }
77 /[a-zA-Z_][a-zA-Z_0-9]*/ {
78 variable_name_face (true);
79 print ($0);
80 variable_name_face (false);
81 call (c_ppline_comments_strings_chars);
82 return;
83 }
84 /\n/ {
85 rizwank 1.1 language_print ($0);
86 return;
87 }
88 }
89
90 state c_ppline_define extends CHighlight
91 {
92 /([a-zA-Z_][a-zA-Z_0-9]*)(\([^\)]*\))?/ {
93 if (strcmp ($2, "") != 0)
94 {
95 function_name_face (true);
96 language_print ($1);
97 function_name_face (false);
98 language_print ($2);
99 }
100 else
101 {
102 variable_name_face (true);
103 language_print ($1);
104 variable_name_face (false);
105 }
106 rizwank 1.1 call (c_ppline_comments_strings_chars);
107 return;
108 }
109 /\n/ {
110 language_print ($0);
111 return;
112 }
113 }
114
115 state c_ppline_comments_strings_chars extends CHighlight
116 {
117 /* Comments. */
118 /\/\*/ {
119 comment_face (true);
120 language_print ($0);
121 call (c_comment);
122 comment_face (false);
123 }
124 /* String constants. */
125 /\"/ {
126 string_face (true);
127 rizwank 1.1 language_print ($0);
128 call (c_string);
129 string_face (false);
130 }
131 /* Character constants. */
132 /'.'|'\\\\.'/ {
133 string_face (true);
134 language_print ($0);
135 string_face (false);
136 }
137 /\n/ {
138 language_print ($0);
139 return;
140 }
141 }
142
143 state c_ppline_tokensequence extends CHighlight
144 {
145 /* Comments. */
146 /\/\*/ {
147 comment_face (true);
148 rizwank 1.1 language_print ($0);
149 call (c_comment);
150 comment_face (false);
151 }
152 /* String constants. */
153 /\"/ {
154 string_face (true);
155 language_print ($0);
156 call (c_string);
157 string_face (false);
158 }
159 /* Character constants. */
160 /'.'|'\\\\.'/ {
161 string_face (true);
162 language_print ($0);
163 string_face (false);
164 }
165 /* defined() operators. */
166 /(defined)(\()([^\)]+)(\))/ {
167 reference_face (true);
168 language_print ($1);
169 rizwank 1.1 reference_face (false);
170 language_print ($2);
171
172 variable_name_face (true);
173 language_print ($3);
174 variable_name_face (false);
175
176 language_print ($4);
177 }
178 /* Variable references. */
179 /\b[a-zA-Z_][a-zA-Z_0-9]*\b/ {
180 variable_name_face (true);
181 language_print ($0);
182 variable_name_face (false);
183 }
184 /\n/ {
185 language_print ($0);
186 return;
187 }
188 }
189
190 rizwank 1.1
191 /*
192 Local variables:
193 mode: c
194 End:
195 */
|