summaryrefslogtreecommitdiff
path: root/src/laygram.y
blob: 3644dd446cd500fba297220b36bfa8e0be403b30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
%name-prefix "LayYY"
%defines
%{
#include    <X11/Xlib.h>
#include    <X11/Xresource.h>
#include    <stdio.h>
#include    <X11/IntrinsicP.h>
#include    <X11/cursorfont.h>
#include    <X11/StringDefs.h>

#include    <X11/Xmu/Misc.h>
#include    <X11/Xmu/Converters.h>
#include    <X11/Xaw3d/LayoutP.h>

#define yysetdest LayYYsetdest
#define yywrap LayYYwrap

static LayoutPtr    *dest;

%}

%union {
    int		    ival;
    XrmQuark	    qval;
    BoxPtr	    bval;
    BoxParamsPtr    pval;
    GlueRec	    gval;
    LayoutDirection lval;
    ExprPtr	    eval;
    Operator	    oval;
}

%type	<bval>	    box boxes compositebox
%type	<pval>	    bothparams oneparams
%type	<gval>	    glue opStretch opShrink
%type	<lval>	    orientation
%type	<eval>	    signedExpr simpleExpr expr

%token		    OC CC OA CA OP CP
%token	<qval>	    NAME
%token	<ival>	    NUMBER
%token	<ival>	    INFINITY
%token		    VERTICAL HORIZONTAL

%token		    EQUAL DOLLAR

%left	<oval>	    PLUS MINUS
%left	<oval>	    TIMES DIVIDE PERCENTOF
%right	<oval>	    PERCENT
%nonassoc	    WIDTH HEIGHT
%right	<oval>	    UMINUS UPLUS

%%
layout		:   compositebox
		    { *dest = $1; }
		;
box		:   NAME bothparams
		    {
			BoxPtr	box = New(LBoxRec);
			box->nextSibling = 0;
			box->type = WidgetBox;
			box->params = *$2;
			Dispose ($2);
			box->u.widget.quark = $1;
			$$ = box;
		    }
		|   signedExpr oneparams
		    {
			BoxPtr	box = New(LBoxRec);
			box->nextSibling = 0;
			box->type = GlueBox;
			box->params = *$2;
			Dispose ($2);
			box->u.glue.expr = $1;
			$$ = box;
		    }
		|   NAME EQUAL signedExpr
		    {
			BoxPtr	box = New(LBoxRec);
			box->nextSibling = 0;
			box->type = VariableBox;
			box->u.variable.quark = $1;
			box->u.variable.expr = $3;
			$$ = box;
		    }
		|   compositebox
		    {
			$$ = $1;
		    }
		;
compositebox	:   orientation OC boxes CC
		    {
			BoxPtr	box = New(LBoxRec);
			BoxPtr	child;

			box->nextSibling = 0;
			box->parent = 0;
			box->type = BoxBox;
			box->u.box.dir = $1;
			box->u.box.firstChild = $3;
			for (child = $3; child; child = child->nextSibling)
			{
			    if (child->type == GlueBox)
			    {
				child->params.stretch[!$1].expr = 0;
				child->params.shrink[!$1].expr = 0;
				child->params.stretch[!$1].order = 100000;
				child->params.shrink[!$1].order = 100000;
				child->params.stretch[!$1].value = 1;
				child->params.shrink[!$1].value = 1;
			    }
			    child->parent = box;
			}
			$$ = box;
		    }
		;
boxes		:   box boxes
		    {
			$1->nextSibling = $2;
			$$ = $1;
		    }
		|   box
		    {	$$ = $1; }
		;
bothparams	:   OA opStretch opShrink TIMES opStretch opShrink CA
		    {
			BoxParamsPtr	p = New(BoxParamsRec);

			p->stretch[LayoutHorizontal] = $2;
			p->shrink[LayoutHorizontal] = $3;
			p->stretch[LayoutVertical] = $5;
			p->shrink[LayoutVertical] = $6;
			$$ = p;
		    }
		|
		    {
			BoxParamsPtr	p = New(BoxParamsRec);

			ZeroGlue (p->stretch[LayoutHorizontal]);
			ZeroGlue (p->shrink[LayoutHorizontal]);
			ZeroGlue (p->stretch[LayoutVertical]);
			ZeroGlue (p->shrink[LayoutVertical]);
			$$ = p;
		    }
		;
oneparams 	:   OA opStretch opShrink CA
		    {
			BoxParamsPtr	p = New(BoxParamsRec);

			p->stretch[LayoutHorizontal] = $2;
			p->shrink[LayoutHorizontal] = $3;
			p->stretch[LayoutVertical] = $2;
			p->shrink[LayoutVertical] = $3;
			$$ = p;
		    }
		|
		    {
			BoxParamsPtr	p = New(BoxParamsRec);

			ZeroGlue (p->stretch[LayoutHorizontal]);
			ZeroGlue (p->shrink[LayoutHorizontal]);
			ZeroGlue (p->stretch[LayoutVertical]);
			ZeroGlue (p->shrink[LayoutVertical]);
			$$ = p;
		    }
		;
opStretch	:   PLUS glue
		    { $$ = $2; }
		|
		    { ZeroGlue ($$); }
		;
opShrink	:   MINUS glue
		    { $$ = $2; }
		|
		    { ZeroGlue ($$); }
		;
glue		:   simpleExpr INFINITY
		    { $$.order = $2; $$.expr = $1; }
		|   simpleExpr
		    { $$.order = 0; $$.expr = $1; }
		|   INFINITY
		    { $$.order = $1; $$.expr = 0; $$.value = 1; }
		;
signedExpr	:   MINUS simpleExpr	    %prec UMINUS
		    {
			$$ = New(ExprRec);
			$$->type = Unary;
			$$->u.unary.op = $1;
			$$->u.unary.down = $2;
		    }
		|   PLUS simpleExpr	    %prec UPLUS
		    { $$ = $2; }
		|   simpleExpr
		;
simpleExpr    	:   WIDTH NAME
		    {	$$ = New(ExprRec);
			$$->type = Width;
			$$->u.width = $2;
		    }
		|   HEIGHT NAME
		    {	$$ = New(ExprRec);
			$$->type = Height;
			$$->u.height = $2;
		    }
		|   OP expr CP
		    { $$ = $2; }
		|   simpleExpr PERCENT
		    {
			$$ = New(ExprRec);
			$$->type = Unary;
			$$->u.unary.op = $2;
			$$->u.unary.down = $1;
		    }
		|   NUMBER
		    {	$$ = New(ExprRec);
			$$->type = Constant;
			$$->u.constant = $1;
		    }
		|   DOLLAR NAME
		    {	$$ = New(ExprRec);
			$$->type = Variable;
			$$->u.variable = $2;
		    }
		;
expr		:   expr PLUS expr
		    { binary: ;
			$$ = New(ExprRec);
			$$->type = Binary;
			$$->u.binary.op = $2;
			$$->u.binary.left = $1;
			$$->u.binary.right = $3;
		    }
		|   expr MINUS expr
		    { goto binary; }
		|   expr TIMES expr
		    { goto binary; }
		|   expr DIVIDE expr
		    { goto binary; }
		|   expr PERCENTOF expr
		    { goto binary; }
		|   MINUS expr		    %prec UMINUS
		    { unary: ;
			$$ = New(ExprRec);
			$$->type = Unary;
			$$->u.unary.op = $1;
			$$->u.unary.down = $2;
		    }
		|   PLUS expr		    %prec UPLUS
		    { $$ = $2; }
		|   simpleExpr
		;
orientation	:   VERTICAL
		{   $$ = LayoutVertical; }
		|   HORIZONTAL
		{   $$ = LayoutHorizontal; }
		;
%%

int yywrap (void)
{
    return 1;
}

void yysetdest (LayoutPtr *c)
{
    dest = c;
}