Fixed a bug in CoRegisterClassObject.
[wine] / rc / parser.y
1 %{
2 /*
3  *
4  * Copyright  Martin von Loewis, 1994
5  */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "parser.h"
10 #include "windows.h"
11
12 int yylex(void);
13 int yyerror(const char *s);
14
15 %}
16 %union{
17         gen_res *res;
18         char *str;
19         int num;
20         struct rc_style *style;
21 }
22 %token <num> NUMBER
23 %token <str> tSTRING SINGLE_QUOTED IDENT
24 %token ACCELERATORS ALT ASCII tBEGIN tBITMAP CAPTION CHECKBOX CHECKED 
25 %token CLASS COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG 
26 %token DISCARDABLE EDITTEXT tEND tFIXED FONT GRAYED GROUPBOX HELP ICON 
27 %token IDENT INACTIVE LISTBOX LTEXT MENU MENUBARBREAK MENUBREAK MENUITEM 
28 %token MOVEABLE LOADONCALL NOINVERT NOT NOT_SUPPORTED POPUP PRELOAD 
29 %token PURE PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SHIFT SEPARATOR 
30 %token SINGLE_QUOTED tSTRING STRINGTABLE STYLE VERSIONINFO VIRTKEY
31 %type <res> resource_file resource resources resource_definition accelerators
32 %type <res> events bitmap cursor dialog dlg_attributes controls 
33 %type <res> generic_control labeled_control control_desc font icon 
34 %type <res> iconinfo menu menu_body item_definitions rcdata raw_data raw_elements 
35 %type <res> stringtable strings versioninfo
36 %type <num> acc_options item_options
37 %type <style> style style_elm optional_style
38 %%
39
40 resource_file: resources {create_output($1);}
41
42 /*resources are put into a linked list*/
43 resources:      {$$=0;}
44                 |resource resources {$$=add_resource($1,$2);}
45                 ;
46
47 /* get the name for a single resource*/
48 resource:       NUMBER resource_definition
49                 {$$=$2;$$->n.i_name=$1;$$->n_type=0;
50                         if(verbose)fprintf(stderr,"Got %s %d\n",get_typename($2),$1);
51                 }
52                 | IDENT resource_definition
53                 {$$=$2;$$->n.s_name=$1;$$->n_type=1;
54                         if(verbose)fprintf(stderr,"Got %s %s\n",get_typename($2),$1);
55                 }
56                 | stringtable
57                 {$$=$1; /* <-- should be NULL */
58                         if(verbose)fprintf(stderr,"Got STRINGTABLE\n");
59                 }
60                 ;
61
62 /* get the value for a single resource*/
63 resource_definition:    accelerators {$$=$1;}
64                 | bitmap {$$=$1;}
65                 | cursor {$$=$1;}
66                 | dialog {$$=$1;}
67                 | font {$$=$1;}
68                 | icon {$$=$1;}
69                 | menu {$$=$1;}
70                 | rcdata {$$=$1;}
71                 | versioninfo {$$=$1;}
72                 ;
73
74 /* have to use tBEGIN because BEGIN is predefined */
75 accelerators:   ACCELERATORS load_and_memoption tBEGIN  events tEND {$$=$4;$$->type=acc;}
76 /* the events are collected in a gen_res, as the accelerator resource is just
77    an array of events */
78 events:         {$$=new_res();}
79                 | tSTRING ',' NUMBER acc_options  events 
80                         {$$=add_string_accelerator($1,$3,$4,$5);}
81                 | NUMBER ',' NUMBER ',' ASCII acc_options  events 
82                         {$$=add_ascii_accelerator($1,$3,$6,$7);}
83                 | NUMBER ',' NUMBER ',' VIRTKEY acc_options  events 
84                         {$$=add_vk_accelerator($1,$3,$6,$7);}
85 acc_options:    {$$=0;}
86                 | ',' NOINVERT acc_options {$$=$3|2;}
87                 | ',' ALT acc_options      {$$=$3|16;}
88                 | ',' SHIFT acc_options    {$$=$3|4;}
89                 | ',' CONTROL acc_options  {$$=$3|8;}
90
91 bitmap:         tBITMAP load_and_memoption tSTRING {$$=make_bitmap(load_file($3));}
92                 | tBITMAP load_and_memoption raw_data {$$=make_bitmap($3);}
93
94 /* load and memory options are ignored */
95 load_and_memoption:     | lamo load_and_memoption
96 lamo:   PRELOAD | LOADONCALL | tFIXED | MOVEABLE | DISCARDABLE | PURE
97
98 cursor:         CURSOR load_and_memoption tSTRING {$$=make_cursor(load_file($3));}
99                 |CURSOR load_and_memoption raw_data {$$=make_cursor($3);}
100
101 dialog:         DIALOG load_and_memoption NUMBER ',' NUMBER ',' NUMBER ',' NUMBER 
102                 dlg_attributes
103                 tBEGIN  controls tEND 
104                 {$$=make_dialog($10,$3,$5,$7,$9,$12);}
105
106 dlg_attributes: {$$=new_dialog();}
107                 | STYLE style dlg_attributes 
108                   {$$=dialog_style($2,$3);}
109                 | CAPTION tSTRING dlg_attributes
110                   {$$=dialog_caption($2,$3);}
111                 | FONT NUMBER ',' tSTRING dlg_attributes 
112                   {$$=dialog_font($2,$4,$5);}
113                 | CLASS tSTRING dlg_attributes
114                   {$$=dialog_class($2,$3);}
115                 | MENU tSTRING dlg_attributes
116                   {$$=dialog_menu_str($2,$3);}
117                 | MENU NUMBER dlg_attributes
118                   {$$=dialog_menu_id($2,$3);}
119
120 /* the controls are collected into a gen_res, and finally the dialog header 
121    is put at the beginning */
122 controls:       {$$=new_res();}
123                 | CHECKBOX  labeled_control controls 
124                   {$$=add_control(CT_BUTTON, BS_CHECKBOX, $2, $3);}
125                 | COMBOBOX control_desc controls 
126                   {$$=add_control(CT_COMBOBOX, 0, $2, $3);}
127                 | CONTROL generic_control controls
128                   {$$=add_generic_control($2, $3);}
129                 | CTEXT labeled_control controls 
130                   {$$=add_control(CT_STATIC, SS_CENTER, $2, $3);}
131                 | DEFPUSHBUTTON labeled_control controls 
132                   {$$=add_control(CT_BUTTON, BS_DEFPUSHBUTTON, $2, $3);}
133                 | EDITTEXT control_desc controls 
134                   {$$=add_control(CT_EDIT, 0, $2, $3);}
135                 | GROUPBOX labeled_control controls 
136                   {$$=add_control(CT_BUTTON, BS_GROUPBOX, $2, $3);}
137                 /*special treatment for icons, as the extent is optional*/
138                 | ICON tSTRING ',' NUMBER ',' NUMBER ',' NUMBER iconinfo controls
139                   {$$=add_icon($2, $4, $6, $8, $9, $10);}
140                 | LISTBOX control_desc controls 
141                   {$$=add_control(CT_LISTBOX, 0, $2, $3);}
142                 | LTEXT labeled_control controls 
143                   {$$=add_control(CT_STATIC, SS_LEFT, $2, $3);}
144                 | PUSHBUTTON labeled_control controls 
145                   {$$=add_control(CT_BUTTON, BS_PUSHBUTTON, $2, $3);}
146                 | RADIOBUTTON labeled_control controls 
147                   {$$=add_control(CT_BUTTON, BS_RADIOBUTTON, $2, $3);}
148                 | RTEXT labeled_control controls 
149                   {$$=add_control(CT_STATIC, SS_RIGHT, $2, $3);}
150                 | SCROLLBAR control_desc controls               
151                   {$$=add_control(CT_SCROLLBAR, 0, $2, $3);}
152
153
154 labeled_control: tSTRING ',' control_desc {$$=label_control_desc($1,$3);}
155 control_desc:   NUMBER ',' NUMBER ',' NUMBER ',' NUMBER ',' NUMBER optional_style 
156                 {$$=create_control_desc($1,$3,$5,$7,$9,$10);}
157
158 optional_style: {$$=0;}|
159                 ',' style {$$=$2;}
160
161 iconinfo:       /*set extent and style to 0 if they are not provided */
162                 {$$=create_control_desc(0,0,0,0,0,0);} 
163                 /* x and y are overwritten later */
164                 | ',' NUMBER ',' NUMBER optional_style
165         {$$=create_control_desc(0,0,0,$2,$4,$5);}
166
167 generic_control:        tSTRING ',' NUMBER ',' tSTRING ',' style ',' NUMBER
168                 ',' NUMBER ',' NUMBER ',' NUMBER
169                 {$$=create_generic_control($1,$3,$5,$7,$9,$11,$13,$15);}
170
171 font:           FONT load_and_memoption tSTRING {$$=make_font(load_file($3));}
172
173 icon:           ICON load_and_memoption tSTRING {$$=make_icon(load_file($3));}
174                 | ICON load_and_memoption raw_data {$$=make_icon($3);}
175
176 menu:           MENU load_and_memoption menu_body {$$=make_menu($3);}
177 /* menu items are collected in a gen_res and prefixed with the menu header*/
178 menu_body:      tBEGIN item_definitions tEND {$$=$2;}
179 item_definitions:       {$$=new_res();}
180                 | MENUITEM tSTRING ',' NUMBER item_options item_definitions
181                   {$$=add_menuitem($2,$4,$5,$6);}
182                 | MENUITEM SEPARATOR item_definitions
183                   {$$=add_menuitem("",0,0,$3);}
184                 | POPUP tSTRING item_options menu_body item_definitions
185                   {$$=add_popup($2,$3,$4,$5);}
186 item_options:   {$$=0;}
187                 | ',' CHECKED item_options {$$=$3|MF_CHECKED;}
188                 | ',' GRAYED item_options {$$=$3|MF_GRAYED;}
189                 | ',' HELP item_options {$$=$3|MF_HELP;}
190                 | ',' INACTIVE item_options {$$=$3|MF_DISABLED;}
191                 | ',' MENUBARBREAK item_options {$$=$3|MF_MENUBARBREAK;}
192                 | ',' MENUBREAK item_options {$$=$3|MF_MENUBREAK;}
193
194 rcdata:         RCDATA load_and_memoption raw_data {$$=make_raw($3);}
195
196 raw_data:       tBEGIN raw_elements tEND {$$=$2;}
197 raw_elements:   SINGLE_QUOTED {$$=hex_to_raw($1,new_res());}
198                 | NUMBER {$$=int_to_raw($1,new_res());}
199                 | SINGLE_QUOTED raw_elements {$$=hex_to_raw($1,$2);}
200                 | NUMBER ',' raw_elements {$$=int_to_raw($1,$3);}
201
202 stringtable:    STRINGTABLE load_and_memoption tBEGIN strings tEND
203                         {$$=$4;}
204 strings:        {$$=0;}|
205                 NUMBER tSTRING strings {$$=0;add_str_tbl_elm($1,$2);}
206
207 versioninfo:    VERSIONINFO NOT_SUPPORTED {$$=0;}
208
209 /* NOT x | NOT y | a | b means (a|b)& ~x & ~y
210    NOT is used to disable default styles */
211 style:          {$$=new_style();}
212                 | style_elm {$$=$1;}
213                 | style_elm '|' style 
214                 {$$=$1;$$->or|=$3->or;$$->and&=$3->and;free($3);}
215
216 style_elm:      NUMBER {$$=new_style();$$->or=$1;}
217                 | NOT NUMBER {$$=new_style();$$->and=~($2);}
218                 | '(' style ')' {$$=$2;}
219 %%
220 extern int line_number;
221 extern char* yytext;
222
223 int yyerror( const char *s )
224 {
225         fprintf(stderr,"stdin:%d: %s before '%s'\n",line_number,s,yytext);
226         return 0;
227 }
228