added fixes for the pushing of arrays and handling non-ref pointers in
[sfrench/samba-autobuild/.git] / source4 / build / pidl / idl.gram
1 {
2         use util;
3 }
4
5 idl: cpp_prefix(s?) module_header interface 
6    { [$item{module_header}, $item{interface}] }
7    | <error>
8
9 module_header: '[' <commit> module_param(s /,/) ']' 
10           {{ 
11               "TYPE" => "MODULEHEADER", 
12               "DATA" => util::FlattenHash($item[3])
13           }}
14               | <error?>
15
16 module_param: identifier '(' text ')'
17           {{ "$item{identifier}" => "$item{text}" }}
18           | <error>
19
20 interface: 'interface' <commit> identifier '{' definition(s?) '}' 
21           {{
22                        "TYPE" => "INTERFACE", 
23                        "NAME" => $item{identifier},
24                        "DATA" => $item[5]
25           }}
26           | <error?>
27
28 definition : cpp_prefix
29              | typedef { $item[1] }
30              | function { $item[1] }
31
32 typedef : 'typedef' <commit> type identifier array_len(?) ';' 
33         {{
34                      "TYPE" => "TYPEDEF", 
35                      "NAME" => $item{identifier},
36                      "DATA" => $item{type},
37                      "ARRAY_LEN" => $item[5][0]
38         }}
39         | <error?>
40
41 struct: 'struct' <commit> '{' element_list1(?) '}' 
42         {{
43                      "TYPE" => "STRUCT", 
44                      "ELEMENTS" => util::FlattenArray2($item[4])
45         }}
46       | <error?>
47
48 union: property_list(s?) 'union' <commit> '{' union_element(s?) '}' 
49          {{
50                 "TYPE" => "UNION",
51                 "PROPERTIES" => util::FlattenArray($item[1]),
52                 "DATA" => $item[5]
53          }}
54          | <error?>
55
56 union_element: '[case(' constant ')]' base_element ';'
57          {{
58                 "TYPE" => "UNION_ELEMENT",
59                 "CASE" => $item{constant},
60                 "DATA" => $item{base_element}
61          }}
62          | 'case(' constant ')' base_element ';'
63          {{
64                 "TYPE" => "UNION_ELEMENT",
65                 "CASE" => $item{constant},
66                 "DATA" => $item{base_element}
67          }}
68
69 base_element: property_list(s?) type pointer(s?) identifier array_len(?) 
70               {{
71                            "NAME" => $item{identifier},
72                            "TYPE" => $item{type},
73                            "PROPERTIES" => util::FlattenArray($item[1]),
74                            "POINTERS" => $#{$item[3]}==-1?undef:$#{$item[3]}+1,
75                            "ARRAY_LEN" => $item[5][0]
76               }}
77             | <error>
78
79 array_len: '[' <commit> constant ']' 
80          { $item{constant} }
81          | <error?>
82
83 element_list1: base_element(s? /;/) ';' 
84                { $item[1] }
85
86 element_list2: 'void' 
87          | base_element(s? /,/)
88          { $item[1] }
89
90 pointer: '*'
91
92 property_list: '[' <commit> property(s /,/) ']' 
93               { $item[3] }
94              | <error?>
95
96 property: 'unique' 
97           | 'in'
98           | 'out'
99           | 'ref'
100           | 'struct_len'
101           | 'context_handle'
102           | 'string'
103           | 'byte_count_pointer' '(' expression ')' {{ "$item[1]" => "$item{expression}" }}
104           | 'size_is' '(' expression ')' {{ "$item[1]" => "$item{expression}" }}
105           | 'length_is' '(' expression ')' {{ "$item[1]" => "$item{expression}" }}
106           | 'switch_is' '(' expression ')' {{ "$item[1]" => "$item{expression}" }}
107           | 'switch_type' '(' type ')' {{ "$item[1]" => $item{type} }}
108
109 identifier: /[\w?]+/
110
111 expression: /[\w?\/+*-]+/
112
113 function : type identifier '(' <commit> element_list2 ');' 
114          {{
115                 "TYPE" => "FUNCTION",
116                 "NAME" => $item{identifier},
117                 "RETURN_TYPE" => $item{type},
118                 "DATA" => $item{element_list2}
119          }}
120          | <error?>
121
122 type : 
123        'unsigned' type { "$item[1] $item[2]" }
124      | 'long'    { $item[1] }
125      | 'string'  { $item[1] }
126      | 'wchar_t' { $item[1] }
127      | struct    { $item[1] }
128      | union     { $item[1] }
129      | identifier { $item[1] }
130      | <error>
131
132 text: /[\w\s.?-]*/
133
134 constant: /-?\d+/
135
136 cpp_prefix: '#' /.*/