File: rcparse.y

package info (click to toggle)
twin 0.4.0-4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 3,804 kB
  • ctags: 23,904
  • sloc: ansic: 61,860; cpp: 1,023; makefile: 777; sh: 552; lex: 302; yacc: 231
file content (348 lines) | stat: -rw-r--r-- 9,287 bytes parent folder | download | duplicates (2)
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/* -*-c-*-
 *
 *  rcparse.y  --  bison ~/.twinrc parser for twin
 *
 *  Copyright (C) 2000-2001 by Massimiliano Ghilardi
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 */

%{

/*
 * C declarations
 */

#include <stdlib.h>
#include <sys/stat.h>
#include <sys/socket.h>

#include "Tw/Twkeys.h"
#ifdef CONF__UNICODE
# include "Tutf/Tutf.h"
#endif
    
#include "twin.h"
#include "methods.h"
#include "data.h"
#include "main.h"
#include "printk.h"
#include "util.h"
#include "hw.h"
#include "extensions.h"

#include "rctypes.h"

#include "wm.h"
#include "rcrun.h"

#ifdef CONF_THIS_MODULE
# include "version.h"
#endif

#include "rcparse.h"


/* also put here the CONF_* and DEBUG_* used in rcparse.h so that MkDep catches them */
#if defined(DEBUG_RC) || defined(DEBUG_FORK)
#endif

/*
 * try to get meaningful error messages
 */

#define YYERROR_VERBOSE

#ifdef DEBUG_YACC
# define YYDEBUG 1
  int yydebug = 1;

  static void yyprint(FILE *file, int type, void *value);

# define YYPRINT(file, type, value)   yyprint(file, type, &(value))

#endif

/* twin.h typedefs `msg'... avoid it */
#define msg Msg


%}

/*
 * BISON declarations
 */

%union {
    ldat	 val;
    ldat_list	*val_list;
    str          _string;
    byte         imm;
    hwcol	 color;
    node	 _node;
}

/*
#ifdef PURE_PARSER
%pure_parser
#endif
*/

/* keywords: */


/* tokens not valid in a function: */
%token '(' ')' ADDSCREEN ADDTOMENU ADDTOFUNC
%token BACKGROUND BORDER BUTTON
%token DELETEFUNC DELETEMENU DELETEBUTTON DELETESCREEN
%token READ 

/* tokens valid as first function token */
%token EXEC EXECTTY GLOBALFLAGS INTERACTIVE KEY 
%token MENU MODULE MOUSE MOVE MOVESCREEN NEXT NOP PREV
%token RESTART RESIZE RESIZESCREEN
%token SCREEN SCROLL SENDTOSCREEN SLEEP STDERR
%token SYNTHETICKEY WAIT WINDOW
%token '\n'

%token <val> EASY_FUNC
/* one of or */
%token BEEP CENTER CLOSE KILL QUIT REFRESH WINDOWLIST

%token <val> FLAG_FUNC
/* one of or */
%token FOCUS MAXIMIZE FULLSCREEN LOWER RAISE RAISELOWER ROLL

%token USERFUNC
/* end of tokens valid as first function token */
    
%token '+' '-' FL_ON FL_OFF FL_TOGGLE FL_ACTIVE FL_INACTIVE FL_LEFT FL_RIGHT

%token <val> GLOBAL_FLAG
/* one of */
%token ALTFONT ALWAYSCURSOR BLINK EDGESCROLL HIDEMENU MENUINFO SHADOWS
%token PASTEBUTTON SELECTIONBUTTON

%token <color> COLOR
%token COL_HIGH

%token <val> KBD_FLAG
/* one of KBD_*_FL in twin.h */
    
/* atoms: */
%token <val>    NUMBER
%token <_string> STRING


/* complicated things: */
%type <color>       color high
%type <_string>     string
%type <val>	    interactive_mode move_or_resize
%type <val>         flag opt_flag flag_active opt_flag_toggle flag_lr
%type <val>	    flag_kbd opt_flag_kbd
%type <imm>	    nl opt_nl immediate_line
%type <_node>       func line
%type <_node>       global_flag funcbody menubody textbody
%type <_node>       string_list line_list global_list 
%type <_node>       funcbody_list _funcbody_list
%type <_node>       menubody_list _menubody_list
%type <_node>       textbody_list _textbody_list

%start rcfile

%%

/*
 * Grammar rules
 */

rcfile		: line_list	{ CallList = $1; }
                ;

line_list	:           line { $$ = AddtoNodeList(NULL, $1); }
                | line_list line { $$ = AddtoNodeList( $1 , $2); }
                ;

line		: immediate_line '\n' { $$ = NULL; }
		| func           '\n' { $$ = $1; }
		| READ string    '\n' { set_yy_file(findfile($2, NULL)); $$ = NULL; }
		| '\n'                { $$ = NULL; }
                ;

nl		:    '\n' {}
		| nl '\n' {}
		;

opt_nl		: /* nothing */ {}
		| nl            {}
		;

immediate_line	: ADDSCREEN  string               { $$ = ImmAddScreen($2); }
		| ADDTOMENU  string               { $$ = MergeMenu($2, NULL); }
		| ADDTOMENU  string menubody_list { $$ = MergeMenu($2,  $3 ); }
		| ADDTOFUNC  string               { $$ = MergeFunc($2, NULL); }
		| ADDTOFUNC  string funcbody_list { $$ = MergeFunc($2,  $3 ); }
		| BACKGROUND string color               { $$ = ImmBackground($2, $3, NULL); }
		| BACKGROUND string color textbody_list { $$ = ImmBackground($2, $3,  $4 ); }
		| BORDER     string flag_active               { $$ = ImmBorder($2, $3, NULL); }
		| BORDER     string flag_active textbody_list { $$ = ImmBorder($2, $3,  $4 ); }
		| BUTTON     NUMBER string flag_lr                 { $$ = ImmButton($2, $3, $4, '+', 0); }
		| BUTTON     NUMBER string flag_lr opt_flag NUMBER { $$ = ImmButton($2, $3, $4, $5, $6); }
		| DELETEFUNC	string { $$ = ImmDeleteFunc($2); }
		| DELETEMENU    string { $$ = ImmDeleteMenu($2); }
		| DELETEBUTTON  NUMBER { $$ = ImmDeleteButton($2); }
		| DELETESCREEN  string { $$ = ImmDeleteScreen($2); }
		| GLOBALFLAGS   global_list { $$ = ImmGlobalFlags($2); }
		| KEY   opt_flag_kbd string func { $$ = BindKey  ($2, $3, $4); }
		| MOUSE string       string func { $$ = BindMouse($2, $3, $4); }
		;

funcbody_list	: '(' opt_nl _funcbody_list ')' { $$ = $3; }
		;

_funcbody_list	:                funcbody { $$ = AddtoNodeList(NULL, $1); }
		| _funcbody_list funcbody { $$ = AddtoNodeList( $1 , $2); }
		;

funcbody	: func nl { $$ = $1; }
		;

menubody_list	: '(' opt_nl _menubody_list ')' { $$ = $3; }
		;

_menubody_list	:                menubody { $$ = AddtoNodeList(NULL, $1); }
		| _menubody_list menubody { $$ = AddtoNodeList( $1 , $2); }
		;

menubody	: string func nl { $$ = MakeNodeBody($1, $2, NULL); }


textbody_list	: '(' opt_nl _textbody_list ')' { $$ = $3; }
		;

_textbody_list	:                textbody { $$ = AddtoNodeList(NULL, $1); }
		| _textbody_list textbody { $$ = AddtoNodeList( $1 , $2); }
		;

textbody	: string nl   { $$ = MakeNode($1); }
		;

color		: NUMBER		      { $$ = (hwcol) $1; }
		| high COLOR		      { $$ = COL($1|$2, BLACK); }
		| high COLOR FL_ON high COLOR { $$ = COL($1|$2, $4|$5); }
		|            FL_ON high COLOR { $$ = COL(WHITE, $2|$3); }
		;

high		: /* nothing */ { $$ = (hwcol)0; }
		| COL_HIGH	{ $$ = HIGH; }
		;

global_list	:             global_flag { $$ = AddtoNodeList(NULL, $1); }
		| global_list global_flag { $$ = AddtoNodeList( $1 , $2); }
		;

global_flag	:      GLOBAL_FLAG { $$ = MakeFlagNode($1,  0); }
		| flag GLOBAL_FLAG { $$ = MakeFlagNode($2, $1); }
		|      SHADOWS NUMBER NUMBER { $$ = MakeShadowsNode($2, $3); }
		| flag SHADOWS     { $$ = MakeFlagNode(SHADOWS, $1); }
		| PASTEBUTTON NUMBER     { $$ = MakeFlagNode(PASTEBUTTON, $2); }
		| SELECTIONBUTTON NUMBER { $$ = MakeFlagNode(SELECTIONBUTTON, $2); }
		;

func		: string		{ $$ = MakeUserFunc($1); }
		| EASY_FUNC		{ $$ = MakeBuiltinFunc($1); }
		| EXEC    string_list	{ $$ = MakeExec($2); }
		| EXECTTY string_list	{ $$ = MakeExecTty($2); }
		| FLAG_FUNC opt_flag_toggle { $$ = MakeFlagNode($1, $2); }
		| INTERACTIVE interactive_mode
					{ $$ = MakeFlagNode(INTERACTIVE, $2); }
		| MODULE string	opt_flag_toggle { $$ = MakeModuleNode($2, $3); }
		| MENU			{ $$ = MakeBuiltinFunc(MENU); }
		| move_or_resize opt_flag NUMBER opt_flag NUMBER
					{ $$ = MakeMoveResizeScroll($1, $2, $3, $4, $5); }
		| NEXT			{ $$ = MakeWindowNumber('+', 1); }
		| RESTART string	{ $$ = MakeRestartWM($2); }
		| PREV			{ $$ = MakeWindowNumber('-', 1); }
		| SCROLL opt_flag NUMBER opt_flag NUMBER { $$ = MakeMoveResizeScroll(SCROLL, $2, $3, $4, $5); }
		| SENDTOSCREEN string	{ $$ = MakeSendToScreen($2); }
		| SLEEP NUMBER		{ $$ = MakeSleep($2); }
		| STDERR string_list	{ $$ = MakeStderr($2); }
		| SYNTHETICKEY opt_flag_kbd string  { $$ = MakeSyntheticKey($2, $3); }
		| WAIT string		{ $$ = MakeWait($2); }
		| WINDOW opt_flag NUMBER	{ $$ = MakeWindowNumber($2, $3); }
		| WINDOW STRING			{ $$ = MakeWindow($2); }
		;

string_list	:             string { $$ = AddtoStringList(NULL, $1); }
		| string_list string { $$ = AddtoStringList( $1,  $2); }
		;

string		: STRING
		| NUMBER { $$ = toString($1); }
		;

interactive_mode: SCROLL { $$ = SCROLL; }
		| MENU   { $$ = MENU; }
		| MOVE   { $$ = MOVE; }
		| RESIZE { $$ = RESIZE; }
		| SCREEN { $$ = SCREEN; }
		;

move_or_resize	: MOVE		{ $$ = MOVE; }
		| MOVESCREEN	{ $$ = MOVESCREEN; }
		| RESIZE	{ $$ = RESIZE; }
		| RESIZESCREEN	{ $$ = RESIZESCREEN; }
		;

opt_flag	: /* nothing */ { $$ = 0; }
		| flag
		;

flag		: '+'		{ $$ = '+'; }
		| '-'		{ $$ = '-'; }
		;
		
opt_flag_kbd	: /* nothing */ { $$ = 0; }
		| flag_kbd
		;

flag_kbd	: KBD_FLAG
		| KBD_FLAG flag { $$ = $1 | $2; }
		;

opt_flag_toggle	: /* nothing */ { $$ = FL_ON; }
		| FL_ON		{ $$ = FL_ON; }
		| FL_OFF	{ $$ = FL_OFF; }
		| FL_TOGGLE	{ $$ = FL_TOGGLE; }
		;

flag_active	: FL_ACTIVE	{ $$ = FL_ACTIVE; }
		| FL_INACTIVE	{ $$ = FL_INACTIVE; }
		;

flag_lr		: FL_LEFT	{ $$ = FL_LEFT; }
		| FL_RIGHT	{ $$ = FL_RIGHT; }
		;
		
%%

#ifdef DEBUG_YACC
static void yyprint(FILE *file, int type, void *value) {
    if (type == NUMBER)
	fprintf (file, " %d", ((YYSTYPE *)value)->val);
    else if (type == STRING)
	fprintf (file, " \"%s\"", ((YYSTYPE *)value)->_string);
    else if (type == GLOBAL_FLAG || type == FLAG_FUNC ||
	type == EASY_FUNC || type == COLOR)
	fprintf (file, " %s", TokenName(((YYSTYPE *)value)->val));
}
#endif

static byte rcparse(byte *path) {
    return set_yy_file(path) == 0 && yyparse() == 0;
}