contrib/objcwrapper: intro objcwrapper base code
[nit.git] / contrib / objcwrapper / grammar / objc.sablecc
1 /* Grammar for Objective-C header files */
2 Grammar objc;
3
4 Lexer
5     upper = 'A'..'Z';
6     lower = 'a'..'z';
7     letter = upper | lower;
8     digit = '0'..'9';
9
10     comma = ',';
11     lpar = '(';
12     rpar = ')';
13     star = '*';
14
15     string = '"' (Any - '"')* '"';
16     class = upper (letter | '_' | digit)*;
17     id = lower (letter | '_' | digit)*;
18
19     private = '_' (letter | digit)+;
20     num = digit+;
21     macro_name = '__' (letter | '_')+;
22     num_typed = num upper+;
23     hexadecimal = '0x' (letter | digit)+;
24     pointer = star+;
25
26     blank = (' ' | '\t' | '\n')+;
27     comments = ('#' (Any - '\n')*);
28
29 Parser
30     Ignored blank, comments;
31
32     prog = lines*;
33
34     lines =
35         {class:} '@class' classes ';' |
36         {protocol:} protocol |
37         {attribute:} attribute |
38         {static:} static |
39         {structure:} structure |
40         {interface:} '@interface' class interface? inheritance? protocols? instance_variables? interface_block* '@end' |
41         {line:} line;
42
43     interface_block =
44         {line:} line |
45         {instance:} instance_declaration;
46
47     line =
48         {library_extern_declaration:} library_extern_declaration |
49         {typedef:} typedef |
50         {extern:} extern |
51         {enum:} 'enum' '{' params '}' attribute? ';';
52
53     typedef =
54         {variable:} 'typedef' 'struct'? declaration ';' |
55         {method:} 'typedef' type method ';' |
56         {structure:} 'typedef' structure |
57         {anonymous:} 'typedef' type anonymous ';';
58
59     instance_declaration =
60         {signature:} signature_block |
61         {property:} property_declaration;
62
63     property_declaration =
64         {property:} optional_method? '@property' property_attribute? property attribute* ';';
65
66     property_attribute =
67         {attribute:} lpar params rpar;
68
69     interface =
70         {interface:} lpar params? rpar;
71
72     library_extern_declaration =
73         {simple:} 'UIKIT_EXTERN' type pointer? 'const'? term attribute? ';' |
74         {method:} 'UIKIT_EXTERN' type method? attribute? ';';
75
76     protocol =
77         {declaration:} '@protocol' type additional_type* ';' |
78         {construction:} '@protocol' type protocols? protocol_block+ '@end';
79
80     additional_type =
81         {type:} comma type;
82
83     protocol_block =
84         {signature:} signature_block |
85         {property:} property_declaration;
86
87     signature_block =
88         {signature:} optional_method? scope signature_return_type? signature+ attribute_list? ';';
89
90     signature_return_type =
91         {return:} lpar type pointer? function_pointer? protocols? rpar;
92
93     optional_method =
94         {required:} '@required' |
95         {optional:} '@optional';
96
97     method =
98         {call:} pointer? term lpar args rpar |
99         {declaration:} pointer? term lpar declarations rpar;
100
101     attribute_list =
102         {attr:} attribute+;
103
104     attribute =
105         {availability:} '__attribute__' lpar lpar 'availability' lpar params rpar rpar rpar |
106         {visibility:} '__attribute__' lpar lpar 'visibility' lpar term rpar rpar rpar |
107         {objc_gc:} '__attribute__' lpar lpar 'objc_gc' lpar term rpar rpar rpar |
108         {attribute_id:} '__attribute__' lpar lpar term rpar rpar |
109         {attribute_method:} '__attribute__' lpar lpar method rpar rpar;
110
111     extern =
112         {method:} 'extern' type method attribute? ';' |
113         {simple:} 'extern' type pointer? 'const'? term attribute? ';';
114
115     static =
116         {method:} 'static' 'inline' type method attribute? ';' |
117         {attr:} 'static' '__inline__' attribute+ type method attribute? ';';
118
119     scope =
120         {class:} '+' |
121         {instance:} '-';
122
123     signature =
124         {named:} [left:]term ':' lpar signature_type rpar attribute? [right:]term |
125         {single:} term |
126         {comma:} comma '...' |
127         {macro:} macro_name;
128
129     signature_type =
130         {anonymous:} type anonymous |
131         {table:} type protocols? '[]' |
132         {pointer:} type pointer |
133         {unsigned:} unsigned pointer |
134         {protocol:} type protocols |
135         {function_pointer:} function_pointer |
136         {normal:} type;
137
138     anonymous =
139         {method:} lpar '^' term? rpar lpar declarations? rpar |
140         {inception:} lpar '^' term? rpar lpar type lpar '^' term? rpar lpar type rpar rpar;
141
142     property =
143         {property:} type protocols? pointer? [left:]term [right:]term? |
144         {anonymous:} type anonymous |
145         {function_pointer:} function_pointer;
146
147     type =
148         {type:} type_annotation? unsigned? data_type;
149
150     type_annotation =
151         {const:} 'const' |
152         {in:} 'in' |
153         {out:} 'out' |
154         {inout:} 'inout' |
155         {bycopy:} 'bycopy' |
156         {byref:} 'byref';
157
158     unsigned =
159         {u:} 'unsigned' |
160         {s:} 'signed';
161
162     data_type =
163         {more:} more_type |
164         {otype:} class;
165
166     more_type =
167         {stype:} specific_type |
168         {ptype:} primitive_type;
169
170     specific_type =
171         {uui:} 'uuid_t' |
172         {i:} 'id' |
173         {b:} '_Bool' |
174         {pth:} 'pthread_mutex_t' |
175         {ds:} 'dispatch_semaphore_t' |
176         {dq:} 'dispatch_queue_t' |
177         {val:} 'va_list' |
178         {identityref:} 'SecIdentityRef' |
179         {trustref:} 'SecTrustRef' |
180         {class:} 'Class' |
181         {protocol:} 'Protocol' |
182         {v:} 'void';
183
184     primitive_type =
185         {ui8:} 'uint8_t' |
186         {ui16:} 'uint16_t' |
187         {ui32:} 'uint32_t' |
188         {ui64:} 'uint64_t' |
189         {i8:} 'int8_t' |
190         {i16:} 'int16_t' |
191         {i32:} 'int32_t' |
192         {i64:} 'int64_t' |
193         {uc:} 'unichar' |
194         {c:} 'char' |
195         {s:} 'short' |
196         {si:} 'short int' |
197         {i:} 'int' |
198         {l:} 'long' |
199         {li:} 'long int' |
200         {ll:} 'long long' |
201         {lli:} 'long long int' |
202         {f:} 'float' |
203         {d:} 'double' |
204         {ld:} 'long double';
205
206     classe =
207         {class:} class |
208         {protocol:} 'Protocol';
209
210     classes =
211         {classes:} classe additional*;
212
213     protocols =
214         {protocols:} '<' classe additional* '>';
215
216     inheritance =
217         {add:} ':' classe additional*;
218
219     additional =
220         {add:} comma classe;
221
222     declarations =
223         {declarations:} declaration additional_declaration*;
224
225     additional_declaration =
226         {add:} comma declaration;
227
228     declaration =
229         {pointer:} type protocols? attribute? pointer? term? '[]'? |
230         {typedef:} type primitive_type |
231         {function_pointer:} function_pointer |
232         {comma:} '...';
233
234     declaration_variable_instance =
235         {unsigned:} type_annotation? unsigned more_type? protocols? attribute? pointer? term '[]'? |
236         {data_type:} type_annotation? data_type protocols? attribute? pointer? term? '[]'?;
237
238     instance_variables =
239         {instance:} '{' instance_variable* '}';
240
241     scope_instance_variable =
242         {package:} '@package' |
243         {public:} '@public' |
244         {private:} '@private' |
245         {protected:} '@protected';
246
247     instance_variable =
248         {scope:} scope_instance_variable |
249         {variable:} attribute? declaration_variable_instance bit_field? additional_variable* ';' |
250         {anonymous:} declaration_variable_instance anonymous ';' |
251         {structure:} structure |
252         {union:} union;
253
254     additional_variable =
255         {add} comma term bit_field?;
256
257     function_pointer =
258         {type:} type pointer? lpar pointer term? rpar lpar declarations rpar;
259
260     union =
261         {name:} 'union' '{' structure_params+ '}' term ';';
262
263     structure =
264         {name:} 'struct' structure_core term ';' |
265         {type:} 'struct' type structure_core term? ';' |
266         {private:} 'struct' private structure_core? term? ';';
267
268     structure_core =
269         {core:} '{' structure_params+ '}';
270
271     structure_params =
272         {value:} declaration bit_field? ';' |
273         {structure:} structure;
274
275     params =
276         {params:} param additional_params*;
277
278     additional_params =
279         {add:} comma param?;
280
281     param =
282         {id:} term |
283         {bitwise:} term '=' bitwise |
284         {term:} term '=' pointer? term+ |
285         {attr:} term attribute |
286         {attrterm:} term attribute '=' term |
287         {attrbitwise:} term attribute '=' bitwise;
288
289     args =
290         {args:} arg additional_arg*;
291
292     additional_arg =
293         {add:} comma arg;
294
295     arg =
296         {num:} num |
297         {macro:} macro_name;
298
299     bitwise =
300         {rterm:} bitwise_operator_not? term bitwise_operator bitwise_operator_not? term |
301         {num:} lpar bitwise_operator_not? term rpar |
302         {term:} lpar bitwise_operator_not? term additional_bitwise+ rpar arithmetic?;
303
304     bitwise_operator =
305         {left_shift:} '<<' |
306         {right_shift:} '>>' |
307         {and:} '&' |
308         {or:} '|' |
309         {xor:} '^';
310
311     bitwise_operator_not =
312         {not:} '~';
313
314     additional_bitwise =
315         {add:} bitwise_operator bitwise_operator_not? term;
316
317     bit_field =
318         {value:} ':' num;
319
320     arithmetic =
321         {add:} '+' num |
322         {minus:} '-' num |
323         {star:} pointer num |
324         {divide:} '/' num;
325
326     term =
327         {num_typed:} '-'? num_typed |
328         {private:} private |
329         {num:} num |
330         {negative:} '-' num |
331         {float:} num '.' num |
332         {string:} string |
333         {hexadecimal:} hexadecimal |
334         {class:} class |
335         {var:} id |
336         {private_table:} private '[' lpar? num rpar? ']' |
337         {table:} id '[' lpar? num rpar? ']';