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 "star-platinum.h"
22 #include <X11/Xlib.h>
23 #include <X11/keysymdef.h>
25 #include <err.h>
26 #include <string.h>
28 #include "y.tab.h"
30 int state = 0;
31 KeySym key = 0;
33 %}
35 %x COMMENT
36 %x KEY
38 %%
40 "#" { BEGIN(COMMENT); }
41 <COMMENT>\n { yylineno++; BEGIN(INITIAL); }
42 <COMMENT>. ;
44 [ \t\r\v\f]+ ;
46 "match" return TMATCH;
47 "class" return TCLASS;
48 "on" return TON;
49 "do" return TDO;
50 "toggle" return TTOGGLE;
51 "activate" return TACTIVATE;
52 "deactivate" return TDEACTIVATE;
53 "ignore" return TIGNORE;
55 "\n" yylineno++; return '\n';
57 [-a-zA-Z0-9]+ {
58 char *ident;
59 if ((ident = strdup(yytext)) == NULL)
60 err(1, "strdup");
61 yylval.str = ident;
62 return TSTRING;
63 }
65 "\"" { BEGIN(KEY); }
66 <KEY>"\"" {
67 BEGIN(INITIAL);
69 if (key == NoSymbol)
70 return TERR;
72 yylval.key = (struct key){ state, key };
73 state = 0;
74 key = 0;
75 return TKEY;
76 }
78 <KEY>C- { state |= ControlMask; }
79 <KEY>S- { state |= ShiftMask; }
80 <KEY>M- { state |= Mod1Mask; }
81 <KEY>s- { state |= Mod4Mask; }
83 <KEY><[_a-zA-Z]+> {
84 char *c;
86 if ((c = strdup(yytext)) == NULL)
87 err(1, "strdup");
89 c++; /* skip the < */
90 c[strlen(c)-1] = '\0'; /* trim the > */
92 key = XStringToKeysym(c);
94 free(--c);
95 }
97 <KEY>SPC { key = XK_space; }
98 <KEY>RET { key = XK_Return; }
100 <KEY>"(" { key = XK_parenleft; }
101 <KEY>")" { key = XK_parenright; }
103 <KEY>. { key = XStringToKeysym(yytext); }
106 %%
108 int
109 yywrap(void)
111 return 1;