1 rizwank 1.1 /**
2 * Name: objc
3 * Description: Objective-C programming language.
4 * Author: Markku Rossi <mtr@iki.fi> with help of Emacs' `font-lock.el'.
5 */
6
7 objc_type_re =
8 /* Types.
9 (build-re '(auto extern register static typedef struct union enum
10 signed unsigned short long int char float double void volatile
11 const id oneway in out inout bycopy byref))
12 */
13 /\b(auto|by(copy|ref)|c(har|onst)|double|e(num|xtern)|float\
14 |i(d|n(|out|t))|long|o(neway|ut)|register|s(hort|igned|t(atic|ruct))\
15 |typedef|un(ion|signed)|vo(id|latile))\b/;
16
17
18 state objc_method_line extends CHighlight
19 {
20 /* Argument declarations after the method.
21 $1 $2 $3 $4 $5 $6 $7 */
22 rizwank 1.1 /([ \t]*)([A-Za-z_][A-Za-z_0-9]*)?(:[ \t]*)(\(([^)\n]+)\))?([ \t]*)([A-Za-z_][A-Za-z_0-9]*)/ {
23 language_print ($1);
24
25 if (length ($2) > 0)
26 {
27 function_name_face (true);
28 language_print ($2);
29 function_name_face (false);
30 }
31
32 language_print ($3);
33
34 if (length ($4) > 0)
35 {
36 language_print ("(");
37 type_face (true);
38 language_print ($5);
39 type_face (false);
40 language_print (")");
41 }
42
43 rizwank 1.1 language_print ($6);
44
45 variable_name_face (true);
46 language_print ($7);
47 variable_name_face (false);
48 }
49
50 /\n/ {
51 language_print ($0);
52 return;
53 }
54 }
55
56 /* This is *not* inherited from CHighlight. */
57 state objc_method_continuation_line
58 {
59 /* Method names and arguments on lines following the function declaration.
60 $1 $2 $3 $4 $5 $6 $7 */
61 /^([ \t]*)([A-Za-z_][A-Za-z_0-9]*)?(:[ \t]*)(\(([^)\n]+)\))?([ \t]*)\
62 ([A-Za-z_][A-Za-z_0-9]*)/ {
63 language_print ($1);
64 rizwank 1.1
65 if (length ($2) > 0)
66 {
67 function_name_face (true);
68 language_print ($2);
69 function_name_face (false);
70 }
71
72 language_print ($3);
73
74 if (length ($4) > 0)
75 {
76 language_print ("(");
77 type_face (true);
78 language_print ($5);
79 type_face (false);
80 language_print (")");
81 }
82
83 language_print ($6);
84
85 rizwank 1.1 variable_name_face (true);
86 language_print ($7);
87 variable_name_face (false);
88
89 /* Highlight all remaining arguments on this line. */
90 call (objc_method_line);
91 }
92
93 /*
94 * If the previous one didn't match, we'r done with this method
95 * declaration.
96 */
97 /()/ {
98 return;
99 }
100 }
101
102 /* This is *not* inherited from CHighlight. */
103 state objc_compiler_directive_line
104 {
105 /([ \t:<(,]*)([A-Za-z_][A-Za-z_0-9]*)/ {
106 rizwank 1.1 language_print ($1);
107
108 function_name_face (true);
109 language_print ($2);
110 function_name_face (false);
111 }
112
113 /*
114 * If the previous one didn't match, we'r done with this directive.
115 * Yes, that should match an empty string.
116 */
117 /()/ {
118 return;
119 }
120 }
121
122 /*
123 * We inherit the Objective-C state from the C state. This gives us
124 * all the defaults, etc. All we have to do here is to overwrite
125 * things that are not implemented, or are broken.
126 */
127 rizwank 1.1 state objc extends c
128 {
129 BEGIN {
130 /* See `c.st' for the comments on this one. */
131 type_re = objc_type_re;
132 }
133
134 /* One line comments. */
135 /\/\// {
136 comment_face (true);
137 language_print ($0);
138 call (eat_one_line);
139 comment_face (false);
140 }
141
142 /* Compiler directives. */
143 /(@)([A-Za-z][A-Za-z0-9]*)\>/ {
144 /* Leading garbage. */
145 language_print ($1);
146
147 /* The directive. */
148 rizwank 1.1 keyword_face (true);
149 language_print ($2);
150 keyword_face (false);
151
152 /* And all the remaining stuff on this line. */
153 call (objc_compiler_directive_line);
154 }
155
156 /* Keywords. Basicly what's missing from C *but* not goto or case.
157 (build-re '(self super _cmd id Class SEL IMP BOOL YES NO nil Nil))
158 */
159 /\b(BOOL|Class|IMP|N(O|il)|SEL|YES|_cmd|id|nil|s(elf|uper))\b/ {
160 keyword_face (true);
161 language_print ($0);
162 keyword_face (false);
163 }
164
165 /* Types. */
166 objc_type_re {
167 type_face (true);
168 language_print ($0);
169 rizwank 1.1 type_face (false);
170 }
171
172 /* Method names. First, on the same line as the function declaration.
173 $1 $2 $3 $4 $5 $6 $7 */
174 /(^[+-][ \t]*)(PRIVATE)?([ \t]*)(\(([^)\n]+)\))?([ \t]*)([A-Za-z_]\
175 [A-Za-z_0-9]*)/ {
176 language_print ($1);
177
178 if (length ($2) > 0)
179 {
180 type_face (true);
181 language_print ($2);
182 type_face (false);
183 }
184
185 language_print ($3);
186
187 if (length ($4) > 0)
188 {
189 language_print ("(");
190 rizwank 1.1 type_face (true);
191 language_print ($5);
192 type_face (false);
193 language_print (")");
194 }
195
196 language_print ($6);
197
198 function_name_face (true);
199 language_print ($7);
200 function_name_face (false);
201
202 /* Highlight arguments from the same line. */
203 call (objc_method_line);
204
205 /*
206 * Method names and arguments on lines following the function declaration.
207 */
208 call (objc_method_continuation_line);
209 }
210
211 rizwank 1.1 /*
212 * Labels and case tags. These must remain as a sole statement on a line,
213 * otherwise we detect selectors. Emacs accepts also bare numbers.
214 */
215 /^([ \t]*)([a-zA-Z0-9_]+)(:[ \t]*)$/ {
216 language_print ($1);
217
218 reference_face (true);
219 language_print ($2);
220 reference_face (false);
221
222 language_print ($3);
223 }
224 }
225
226
227 /*
228 Local variables:
229 mode: c
230 End:
231 */
|