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