Blob


1 /* -*- mode: fundamental; indent-tabs-mode: t; -*- */
2 %{
4 /*
5 * Copyright (c) 2020 Omar Polo <op@omarpolo.com>
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
20 #include <stdio.h>
22 #include <X11/Xlib.h>
24 #include "star-platinum.h"
26 void yyerror(const char*);
28 /*
29 * #define YYDEBUG 1
30 * int yydebug = 1;
31 */
33 #define SPECIAL(X) ((struct action){.type = (ASPECIAL), .special = (X) })
34 #define FAKE_KEY(K) ((struct action){.type = (AFAKE), .send_key = (K) })
36 %}
38 %union {
39 struct key key;
40 char *str;
41 struct action action;
42 struct match *match;
43 struct rule *rule;
44 struct group *group;
45 }
47 %token TMATCH TCLASS
48 %token TON TDO
49 %token TTOGGLE TACTIVATE TDEACTIVATE TIGNORE
50 %token TERR
52 %token <key> TKEY
53 %token <str> TSTRING
55 %type <action> action
56 %type <match> matches match
57 %type <rule> keys key
58 %type <group> groups group
60 %%
62 groups : /* empty */ { $$ = NULL; }
63 | groups group { $2->next = $1; config = $$ = $2; }
64 | error '\n'
65 ;
67 group : matches keys { $$ = new_group($1, $2); }
68 ;
70 matches : /* empty */ { $$ = NULL; }
71 | matches '\n' { $$ = $1; }
72 | matches match '\n' { $2->next = $1; $$ = $2; }
73 ;
75 match : TMATCH '*' { $$ = new_match(MANY, NULL); }
76 | TMATCH TCLASS TSTRING { $$ = new_match(MCLASS, $3); }
77 ;
79 keys : /* empty */ { $$ = NULL; }
80 | keys '\n' { $$ = $1; }
81 | keys key '\n' { $2->next = $1; $$ = $2; }
82 ;
84 key : TON TKEY TDO action { $$ = new_rule($2, $4); }
85 ;
87 action : TKEY { $$ = FAKE_KEY($1); }
88 | TTOGGLE { $$ = SPECIAL(ATOGGLE); }
89 | TACTIVATE { $$ = SPECIAL(AACTIVATE); }
90 | TDEACTIVATE { $$ = SPECIAL(ADEACTIVATE); }
91 | TIGNORE { $$ = SPECIAL(AIGNORE); }
92 ;