f5c90c89f57d6396cfc8d44eee623a0321aaf4f6
[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? parameter+ 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     parameter =
124         {named:} [left:]term ':' parameter_type_in_par? attribute? [right:]term |
125         {single:} term |
126         {comma:} comma '...' |
127         {macro:} macro_name;
128
129     parameter_type_in_par = lpar parameter_type rpar;
130
131     parameter_type =
132         {normal:} type |
133         {anonymous:} type anonymous |
134         {table:} type protocols? '[]' |
135         {pointer:} type pointer |
136         {protocol:} type protocols |
137         {unsigned:} unsigned pointer |
138         {function_pointer:} function_pointer;
139
140     anonymous =
141         {method:} lpar '^' term? rpar lpar declarations? rpar |
142         {inception:} lpar '^' term? rpar lpar type lpar '^' term? rpar lpar type rpar rpar;
143
144     property =
145         {property:} type protocols? pointer? [left:]term [right:]term? |
146         {anonymous:} type anonymous |
147         {function_pointer:} function_pointer;
148
149     type =
150         {type:} type_annotation? unsigned? data_type;
151
152     type_annotation =
153         {const:} 'const' |
154         {in:} 'in' |
155         {out:} 'out' |
156         {inout:} 'inout' |
157         {bycopy:} 'bycopy' |
158         {byref:} 'byref';
159
160     unsigned =
161         {u:} 'unsigned' |
162         {s:} 'signed';
163
164     data_type =
165         {more:} more_type |
166         {otype:} class;
167
168     more_type =
169         'uuid_t' |
170         'id' |
171         '_Bool' |
172         'pthread_mutex_t' |
173         'dispatch_semaphore_t' |
174         'dispatch_queue_t' |
175         'va_list' |
176         'SecIdentityRef' |
177         'SecTrustRef' |
178         'Class' |
179         'Protocol' |
180         'void' |
181         'uint8_t' |
182         'uint16_t' |
183         'uint32_t' |
184         'uint64_t' |
185         'int8_t' |
186         'int16_t' |
187         'int32_t' |
188         'int64_t' |
189         'unichar' |
190         'char' |
191         'short' |
192         'short int' |
193         'int' |
194         'long' |
195         'long int' |
196         'long long' |
197         'long long int' |
198         'float' |
199         'double' |
200         'long double';
201
202     classe =
203         {class:} class |
204         {protocol:} 'Protocol';
205
206     classes =
207         {classes:} classe additional*;
208
209     protocols =
210         {protocols:} '<' classe additional* '>';
211
212     inheritance =
213         {add:} ':' classe additional*;
214
215     additional =
216         {add:} comma classe;
217
218     declarations =
219         {declarations:} declaration additional_declaration*;
220
221     additional_declaration =
222         {add:} comma declaration;
223
224     declaration =
225         {pointer:} type protocols? attribute? pointer? term? '[]'? |
226         {typedef:} type more_type |
227         {function_pointer:} function_pointer |
228         {comma:} '...';
229
230     declaration_variable_instance =
231         {unsigned:} type_annotation? unsigned more_type? protocols? attribute? pointer? term '[]'? |
232         {data_type:} type_annotation? data_type protocols? attribute? pointer? term? '[]'?;
233
234     instance_variables =
235         {instance:} '{' instance_variable* '}';
236
237     scope_instance_variable =
238         {package:} '@package' |
239         {public:} '@public' |
240         {private:} '@private' |
241         {protected:} '@protected';
242
243     instance_variable =
244         {scope:} scope_instance_variable |
245         {variable:} attribute? declaration_variable_instance bit_field? additional_variable* ';' |
246         {anonymous:} declaration_variable_instance anonymous ';' |
247         {structure:} structure |
248         {union:} union;
249
250     additional_variable =
251         {add} comma term bit_field?;
252
253     function_pointer =
254         {type:} type pointer? lpar pointer term? rpar lpar declarations rpar;
255
256     union =
257         {name:} 'union' '{' structure_params+ '}' term ';';
258
259     structure =
260         {name:} 'struct' structure_core term ';' |
261         {type:} 'struct' type structure_core term? ';' |
262         {private:} 'struct' private structure_core? term? ';';
263
264     structure_core =
265         {core:} '{' structure_params+ '}';
266
267     structure_params =
268         {value:} declaration bit_field? ';' |
269         {structure:} structure;
270
271     params =
272         {params:} param additional_params*;
273
274     additional_params =
275         {add:} comma param?;
276
277     param =
278         {id:} term |
279         {bitwise:} term '=' bitwise |
280         {term:} term '=' pointer? term+ |
281         {attr:} term attribute |
282         {attrterm:} term attribute '=' term |
283         {attrbitwise:} term attribute '=' bitwise;
284
285     args =
286         {args:} arg additional_arg*;
287
288     additional_arg =
289         {add:} comma arg;
290
291     arg =
292         {num:} num |
293         {macro:} macro_name;
294
295     bitwise =
296         {rterm:} bitwise_operator_not? term bitwise_operator bitwise_operator_not? term |
297         {num:} lpar bitwise_operator_not? term rpar |
298         {term:} lpar bitwise_operator_not? term additional_bitwise+ rpar arithmetic?;
299
300     bitwise_operator =
301         {left_shift:} '<<' |
302         {right_shift:} '>>' |
303         {and:} '&' |
304         {or:} '|' |
305         {xor:} '^';
306
307     bitwise_operator_not =
308         {not:} '~';
309
310     additional_bitwise =
311         {add:} bitwise_operator bitwise_operator_not? term;
312
313     bit_field =
314         {value:} ':' num;
315
316     arithmetic =
317         {add:} '+' num |
318         {minus:} '-' num |
319         {star:} pointer num |
320         {divide:} '/' num;
321
322     term =
323         {num_typed:} '-'? num_typed |
324         {private:} private |
325         {num:} num |
326         {negative:} '-' num |
327         {float:} num '.' num |
328         {string:} string |
329         {hexadecimal:} hexadecimal |
330         {class:} class |
331         {var:} id |
332         {private_table:} private '[' lpar? num rpar? ']' |
333         {table:} id '[' lpar? num rpar? ']';