support a new value() attribute that allows us to auto-fill certain
[samba.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: 
80          '[]'
81          { "*" }
82          | '[' <commit> constant ']' 
83          { $item{constant} }
84          | <error?>
85
86 element_list1: base_element(s? /;/) ';' 
87                { $item[1] }
88
89 element_list2: 'void' 
90          | base_element(s? /,/)
91          { $item[1] }
92
93 pointer: '*'
94
95 property_list: '[' <commit> property(s /,/) ']' 
96               { $item[3] }
97              | <error?>
98
99 property: 'unique' 
100           | 'in'
101           | 'out'
102           | 'ref'
103           | 'struct_len'
104           | 'context_handle'
105           | 'string'
106           | 'byte_count_pointer' '(' expression ')' {{ "$item[1]" => "$item{expression}" }}
107           | 'size_is' '(' expression ')' {{ "$item[1]" => "$item{expression}" }}
108           | 'length_is' '(' expression ')' {{ "$item[1]" => "$item{expression}" }}
109           | 'switch_is' '(' expression ')' {{ "$item[1]" => "$item{expression}" }}
110           | 'value' '(' anytext ')' {{ "$item[1]" => "$item{anytext}" }}
111           | 'switch_type' '(' type ')' {{ "$item[1]" => $item{type} }}
112
113 identifier: /[\w?]+/
114
115 expression: /[\w.?\/+*-_]+/
116
117 function : type identifier '(' <commit> element_list2 ');' 
118          {{
119                 "TYPE" => "FUNCTION",
120                 "NAME" => $item{identifier},
121                 "RETURN_TYPE" => $item{type},
122                 "DATA" => $item{element_list2}
123          }}
124          | <error?>
125
126 type : 
127        'unsigned' type { "$item[1] $item[2]" }
128      | 'long'    { $item[1] }
129      | 'string'  { $item[1] }
130      | 'wchar_t' { $item[1] }
131      | struct    { $item[1] }
132      | union     { $item[1] }
133      | identifier { $item[1] }
134      | <error>
135
136 text: /[\w\s\..?-]*/
137
138 anytext: call(s?) 
139          {{ "$item[1][0]" }}
140
141 call: expression '(' <commit> expression ')'
142          {{ "$item[1]($item[4])" }}
143
144 constant: /-?\d+/
145           | '*'
146
147 cpp_prefix: '#' /.*/