contrib/objcwrapper grammar: add the size_t primitive type
[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         'size_t';
202
203     classe =
204         {class:} class |
205         {protocol:} 'Protocol';
206
207     classes =
208         {classes:} classe additional*;
209
210     protocols =
211         {protocols:} '<' classe additional* '>';
212
213     inheritance =
214         {add:} ':' classe additional*;
215
216     additional =
217         {add:} comma classe;
218
219     declarations =
220         {declarations:} declaration additional_declaration*;
221
222     additional_declaration =
223         {add:} comma declaration;
224
225     declaration =
226         {pointer:} type protocols? attribute? pointer? term? '[]'? |
227         {typedef:} type more_type |
228         {function_pointer:} function_pointer |
229         {comma:} '...';
230
231     declaration_variable_instance =
232         {unsigned:} type_annotation? unsigned more_type? protocols? attribute? pointer? term '[]'? |
233         {data_type:} type_annotation? data_type protocols? attribute? pointer? term? '[]'?;
234
235     instance_variables =
236         {instance:} '{' instance_variable* '}';
237
238     scope_instance_variable =
239         {package:} '@package' |
240         {public:} '@public' |
241         {private:} '@private' |
242         {protected:} '@protected';
243
244     instance_variable =
245         {scope:} scope_instance_variable |
246         {variable:} attribute? declaration_variable_instance bit_field? additional_variable* ';' |
247         {anonymous:} declaration_variable_instance anonymous ';' |
248         {structure:} structure |
249         {union:} union;
250
251     additional_variable =
252         {add} comma term bit_field?;
253
254     function_pointer =
255         {type:} type pointer? lpar pointer term? rpar lpar declarations rpar;
256
257     union =
258         {name:} 'union' '{' structure_params+ '}' term ';';
259
260     structure =
261         {name:} 'struct' structure_core term ';' |
262         {type:} 'struct' type structure_core term? ';' |
263         {private:} 'struct' private structure_core? term? ';';
264
265     structure_core =
266         {core:} '{' structure_params+ '}';
267
268     structure_params =
269         {value:} declaration bit_field? ';' |
270         {structure:} structure;
271
272     params =
273         {params:} param additional_params*;
274
275     additional_params =
276         {add:} comma param?;
277
278     param =
279         {id:} term |
280         {bitwise:} term '=' bitwise |
281         {term:} term '=' pointer? term+ |
282         {attr:} term attribute |
283         {attrterm:} term attribute '=' term |
284         {attrbitwise:} term attribute '=' bitwise;
285
286     args =
287         {args:} arg additional_arg*;
288
289     additional_arg =
290         {add:} comma arg;
291
292     arg =
293         {num:} num |
294         {macro:} macro_name;
295
296     bitwise =
297         {rterm:} bitwise_operator_not? term bitwise_operator bitwise_operator_not? term |
298         {num:} lpar bitwise_operator_not? term rpar |
299         {term:} lpar bitwise_operator_not? term additional_bitwise+ rpar arithmetic?;
300
301     bitwise_operator =
302         {left_shift:} '<<' |
303         {right_shift:} '>>' |
304         {and:} '&' |
305         {or:} '|' |
306         {xor:} '^';
307
308     bitwise_operator_not =
309         {not:} '~';
310
311     additional_bitwise =
312         {add:} bitwise_operator bitwise_operator_not? term;
313
314     bit_field =
315         {value:} ':' num;
316
317     arithmetic =
318         {add:} '+' num |
319         {minus:} '-' num |
320         {star:} pointer num |
321         {divide:} '/' num;
322
323     term =
324         {num_typed:} '-'? num_typed |
325         {private:} private |
326         {num:} num |
327         {negative:} '-' num |
328         {float:} num '.' num |
329         {string:} string |
330         {hexadecimal:} hexadecimal |
331         {class:} class |
332         {var:} id |
333         {private_table:} private '[' lpar? num rpar? ']' |
334         {table:} id '[' lpar? num rpar? ']';