initial import
[manmower/obtheme.git] / obtheme.y
1 %pure-parser
2 %name-prefix "obtheme"
3 %parse-param {struct parser_control *pc}
4 %{
5 #include <assert.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <stdlib.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <limits.h>
12 #include <unistd.h>
13 #include "obtheme.h"
14 #include "obtheme.tab.h"
15
16 YY_DECL;
17
18 struct parser_control *parser_init(struct obthemedata *otd)
19 {
20         struct parser_control *out;
21         out = calloc(1, sizeof(struct parser_control));
22         out->include_stack_ptr = 0;
23         out->target = otd;
24         return out;
25 }
26
27 void parser_finish(struct parser_control *c)
28 {
29         free(c);
30 }
31
32 %}
33 %start theme_objects
34
35 %union {
36         int integer;
37         float realnum;
38         char *string;
39         struct decor decor;
40         struct space space;
41         struct theme theme;
42         struct material material;
43         struct class class;
44         GSList *list;
45         GHashTable *hash;
46         struct vector vector;
47 }
48
49 %token LCB RCB LB RB
50 %token LEFT_ARROW RIGHT_ARROW DOUBLE_ARROW
51 %token SEMICOLON AT COLON DEFAULT NOT
52 %token PLUS MINUS
53 %token <string> STRING ID
54 %token <integer> NUMBER SUBST BULK BIG LITTLE
55 %token THEME FRAME SPACE GEOMETRY MATERIAL GRADIENT
56 %token CONTEXT CURSOR UP ANCHOR CLASS TEXTURE OPACITY
57 %token SHAPEOF DECOR
58 %type <decor> decor
59 %type <decor> decoritems classitem
60 %type <space> space
61 %type <class> class classitems
62 %type <hash> classes
63 %type <material> material_props
64 %type <realnum> opacity
65 %type <space> spaceconstraints
66 %type <vector> up anchor
67 %%
68
69 theme_object    : material_decl
70                 | theme
71                 ;
72
73 theme_objects   : /* empty */
74                 | theme_objects theme_object
75                 ;
76
77 theme           : THEME ID LCB classes RCB {
78                         struct theme *out;
79                         out = malloc(sizeof(struct theme));
80                         out->name = $2;
81                         out->classes = $4;
82                         g_hash_table_insert(pc->target->themes, $2, out);
83                 }
84                 ;
85
86 opacity         : OPACITY LB NUMBER RB { $$ = $3; }
87                 ;
88
89 material_props  : /* empty */ { memset(&$$, 0, sizeof($$)); }
90                 | material_props opacity {
91                         $$ = $1;
92                         $$.opacity = $2;
93                 }
94                 ;
95
96 material_decl   : MATERIAL ID LCB material_props RCB {
97                         struct material *out;
98                         out = malloc(sizeof(struct material));
99                         *out = $4;
100                         g_hash_table_insert(pc->target->materials, $2, out);
101                 }
102                 ;
103
104 anchor          : ANCHOR LB NUMBER NUMBER NUMBER RB {
105                         $$.x = $3;
106                         $$.y = $4;
107                         $$.z = $5;
108                 }
109                 ;
110
111 up              : UP LB NUMBER NUMBER NUMBER RB {
112                         $$.x = $3;
113                         $$.y = $4;
114                         $$.z = $5;
115                 }
116                 ;
117
118 spaceconstraints: /* empty */ { memset(&$$, 0, sizeof($$)); }
119                 | spaceconstraints anchor { $1.anchor = $2; $$ = $1; }
120                 | spaceconstraints up     { $1.up = $2; $$ = $1; }
121                 ;
122
123 space           : SPACE LCB spaceconstraints RCB {
124                         $$ = $3;
125                 }
126                 ;
127
128 shape           : SHAPEOF LB ID RB
129                 ;
130
131 geometry_item   : /* empty */
132                 | shape
133                 ;
134
135 geometry        : GEOMETRY LCB geometry_item RCB
136                 ;
137
138 material_use    : MATERIAL LB ID RB
139                 ;
140
141 classitem       : decor
142                 ;
143
144 classitems      : /* empty */ { $$.tree = NULL; $$.name = NULL; }
145                 | classitems classitem {
146                         struct decor *out = malloc(sizeof(struct decor));
147                         *out = $2;
148                         $1.tree = g_slist_prepend($1.tree, out);
149                         $$ = $1;
150                 }
151                 ;
152
153 classes         : /* empty */ { $$ = g_hash_table_new(g_str_hash, g_str_equal); }
154                 | classes class {
155                         struct class *out = malloc(sizeof(struct class));
156                         *out = $2;
157                         $$ = $1;
158                         g_hash_table_insert($1, out->name, out);
159                 }
160                 ;
161
162 class           : CLASS ID LCB classitems RCB {
163                         $$ = $4;
164                         $$.name = $2;
165                 }
166                 ;
167
168 decoritems      : /* empty */ {
169                         memset(&$$, 0, sizeof($$));
170                         $$.space.up.y = -1;
171                 }
172                 | decoritems decor {
173                         struct decor *out = malloc(sizeof(struct decor));
174                         *out = $2;
175                         $$ = $1;
176                         $$.children = g_slist_append($1.children, out);
177                 }
178                 | decoritems space { $1.space = $2; $$ = $1; }
179                 | decoritems material_use
180                 | decoritems geometry
181                 | decoritems texture
182                 | decoritems context
183                 | decoritems gradient
184                 | decoritems cursor
185                 ;
186
187                 ;
188
189 decor           : DECOR ID LCB decoritems RCB {
190                         $$ = $4;
191                         $$.name = $2;
192                 }
193                 ;
194
195 texture         : TEXTURE LCB RCB
196                 ;
197
198 context         : CONTEXT LB ID RB
199                 ;
200
201 cursor          : CURSOR LB ID RB
202
203 gradient        : GRADIENT LB ID RB
204                 ;
205
206 %%