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 "star-platinum.h"
24 /*
25 * #define YYDEBUG 1
26 * int yydebug = 1;
27 */
29 #define SPECIAL(X) ((struct action){.type = (ASPECIAL), .special = (X) })
30 #define FAKE_KEY(K) ((struct action){.type = (AFAKE), .send_key = (K) })
32 %}
34 %union {
35 struct key key;
36 char *str;
37 struct action action;
38 struct match *match;
39 struct rule *rule;
40 struct group *group;
41 }
43 %token TMATCH TCLASS
44 %token TON TDO
45 %token TTOGGLE TACTIVATE TDEACTIVATE TIGNORE
46 %token TERR
48 %token <key> TKEY
49 %token <str> TSTRING
51 %type <action> action
52 %type <match> matches match
53 %type <rule> keys key
54 %type <group> groups group
56 %%
58 groups : /* empty */ { $$ = NULL; }
59 | groups group { $2->next = $1; config = $$ = $2; }
60 | error '\n'
61 ;
63 group : matches keys { $$ = new_group($1, $2); }
64 ;
66 matches : /* empty */ { $$ = NULL; }
67 | matches '\n' { $$ = $1; }
68 | matches match '\n' { $2->next = $1; $$ = $2; }
69 ;
71 match : TMATCH '*' { $$ = new_match(MANY, NULL); }
72 | TMATCH TCLASS TSTRING { $$ = new_match(MCLASS, $3); }
73 ;
75 keys : /* empty */ { $$ = NULL; }
76 | keys '\n' { $$ = $1; }
77 | keys key '\n' { $2->next = $1; $$ = $2; }
78 ;
80 key : TON TKEY TDO action { $$ = new_rule($2, $4); }
81 ;
83 action : TKEY { $$ = FAKE_KEY($1); }
84 | TTOGGLE { $$ = SPECIAL(ATOGGLE); }
85 | TACTIVATE { $$ = SPECIAL(AACTIVATE); }
86 | TDEACTIVATE { $$ = SPECIAL(ADEACTIVATE); }
87 | TIGNORE { $$ = SPECIAL(AIGNORE); }
88 ;