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';
56 "*" return '*';
58 [-a-zA-Z0-9]+ {
59 char *ident;
60 if ((ident = strdup(yytext)) == NULL)
61 err(1, "strdup");
62 yylval.str = ident;
63 return TSTRING;
64 }
66 "\"" { BEGIN(KEY); }
67 <KEY>"\"" {
68 BEGIN(INITIAL);
70 if (key == NoSymbol)
71 return TERR;
73 yylval.key = (struct key){ state, key };
74 state = 0;
75 key = 0;
76 return TKEY;
77 }
79 <KEY>C- { state |= ControlMask; }
80 <KEY>S- { state |= ShiftMask; }
81 <KEY>M- { state |= Mod1Mask; }
82 <KEY>s- { state |= Mod4Mask; }
84 <KEY><[_a-zA-Z]+> {
85 char *c;
87 if ((c = strdup(yytext)) == NULL)
88 err(1, "strdup");
90 c++; /* skip the < */
91 c[strlen(c)-1] = '\0'; /* trim the > */
93 key = XStringToKeysym(c);
95 free(--c);
96 }
98 <KEY>SPC { key = XK_space; }
99 <KEY>RET { key = XK_Return; }
101 <KEY>"(" { key = XK_parenleft; }
102 <KEY>")" { key = XK_parenright; }
104 <KEY>. { key = XStringToKeysym(yytext); }
107 %%
109 int
110 yywrap(void)
112 return 1;