]> git.sur5r.net Git - i3/i3/blob - src/cfgparse.l
Make horizontal edge-borders hidable too
[i3/i3] / src / cfgparse.l
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  */
5 %option nounput
6 %option noinput
7 %option noyy_top_state
8 %option stack
9
10 %{
11 #include <stdio.h>
12 #include <string.h>
13 #include <stdint.h>
14 #include <xcb/xcb.h>
15
16 #include "log.h"
17 #include "data.h"
18 #include "config.h"
19 #include "util.h"
20 #include "libi3.h"
21
22 #include "cfgparse.tab.h"
23
24 int yycolumn = 1;
25
26 #define YY_DECL int yylex (struct context *context)
27
28 #define YY_USER_ACTION { \
29     context->first_column = yycolumn; \
30     context->last_column = yycolumn+yyleng-1; \
31     yycolumn += yyleng; \
32 }
33
34 /* macro to first eat whitespace, then expect a string */
35 #define WS_STRING do { \
36     yy_push_state(WANT_STRING); \
37     yy_push_state(EAT_WHITESPACE); \
38 } while (0)
39
40 #define BAR_TRIPLE_COLOR do { \
41     yy_push_state(BAR_COLOR); \
42     yy_push_state(BAR_COLOR); \
43     yy_push_state(BAR_COLOR); \
44 } while (0)
45
46 %}
47
48 EOL     (\r?\n)
49
50 %s WANT_STRING
51 %s WANT_QSTRING
52 %s BINDSYM_COND
53 %s ASSIGN_COND
54 %s ASSIGN_TARGET_COND
55 %s COLOR_COND
56 %s OUTPUT_COND
57 %s FOR_WINDOW_COND
58 %s EAT_WHITESPACE
59
60 %x BUFFER_LINE
61 %x BAR
62 %x BAR_MODE
63 %x BAR_MODIFIER
64 %x BAR_POSITION
65 %x BAR_COLORS
66 %x BAR_COLOR
67
68 %x EXEC
69
70 %%
71
72     {
73         /* This is called when a new line is lexed. We only want the
74          * first line to match to go into state BUFFER_LINE */
75         if (context->line_number == 0) {
76             context->line_number = 1;
77             BEGIN(INITIAL);
78             yy_push_state(BUFFER_LINE);
79         }
80     }
81
82 <BUFFER_LINE>^[^\r\n]*/{EOL}? {
83     /* save whole line */
84     context->line_copy = sstrdup(yytext);
85
86     yyless(0);
87     yy_pop_state();
88     yy_set_bol(true);
89     yycolumn = 1;
90 }
91
92  /* This part of the lexer handles the bar {} blocks */
93 <BAR,BAR_MODE,BAR_MODIFIER,BAR_POSITION,BAR_COLORS,BAR_COLOR>[ \t]+ { /* ignore whitespace */ ; }
94 <BAR>"{"                        { return '{'; }
95 <BAR>"}"                        { yy_pop_state(); return '}'; }
96 <BAR>^[ \t]*#[^\n]*             { return TOKCOMMENT; }
97 <BAR>output                     { WS_STRING; return TOK_BAR_OUTPUT; }
98 <BAR>tray_output                { WS_STRING; return TOK_BAR_TRAY_OUTPUT; }
99 <BAR>socket_path                { WS_STRING; return TOK_BAR_SOCKET_PATH; }
100 <BAR>mode                       { yy_push_state(BAR_MODE); return TOK_BAR_MODE; }
101 <BAR_MODE>hide                  { yy_pop_state(); return TOK_BAR_HIDE; }
102 <BAR_MODE>dock                  { yy_pop_state(); return TOK_BAR_DOCK; }
103 <BAR>modifier                   { yy_push_state(BAR_MODIFIER); return TOK_BAR_MODIFIER; }
104 <BAR_MODIFIER>control           { yy_pop_state(); return TOK_BAR_CONTROL; }
105 <BAR_MODIFIER>ctrl              { yy_pop_state(); return TOK_BAR_CONTROL; }
106 <BAR_MODIFIER>shift             { yy_pop_state(); return TOK_BAR_SHIFT; }
107 <BAR_MODIFIER>Mod1              { yy_pop_state(); return TOK_BAR_MOD1; }
108 <BAR_MODIFIER>Mod2              { yy_pop_state(); return TOK_BAR_MOD2; }
109 <BAR_MODIFIER>Mod3              { yy_pop_state(); return TOK_BAR_MOD3; }
110 <BAR_MODIFIER>Mod4              { yy_pop_state(); return TOK_BAR_MOD4; }
111 <BAR_MODIFIER>Mod5              { yy_pop_state(); return TOK_BAR_MOD5; }
112 <BAR>position                   { yy_push_state(BAR_POSITION); return TOK_BAR_POSITION; }
113 <BAR_POSITION>bottom            { yy_pop_state(); return TOK_BAR_BOTTOM; }
114 <BAR_POSITION>top               { yy_pop_state(); return TOK_BAR_TOP; }
115 <BAR>status_command             { WS_STRING; return TOK_BAR_STATUS_COMMAND; }
116 <BAR>i3bar_command              { WS_STRING; return TOK_BAR_I3BAR_COMMAND; }
117 <BAR>font                       { WS_STRING; return TOK_BAR_FONT; }
118 <BAR>workspace_buttons          { return TOK_BAR_WORKSPACE_BUTTONS; }
119 <BAR>verbose                    { return TOK_BAR_VERBOSE; }
120 <BAR>colors                     { yy_push_state(BAR_COLORS); return TOK_BAR_COLORS; }
121 <BAR_COLORS>"{"                 { return '{'; }
122 <BAR_COLORS>"}"                 { yy_pop_state(); return '}'; }
123 <BAR_COLORS>^[ \t]*#[^\n]*      { return TOKCOMMENT; }
124 <BAR_COLORS>background          { yy_push_state(BAR_COLOR); return TOK_BAR_COLOR_BACKGROUND; }
125 <BAR_COLORS>statusline          { yy_push_state(BAR_COLOR); return TOK_BAR_COLOR_STATUSLINE; }
126 <BAR_COLORS>focused_workspace   { BAR_TRIPLE_COLOR; return TOK_BAR_COLOR_FOCUSED_WORKSPACE; }
127 <BAR_COLORS>active_workspace    { BAR_TRIPLE_COLOR; return TOK_BAR_COLOR_ACTIVE_WORKSPACE; }
128 <BAR_COLORS>inactive_workspace  { BAR_TRIPLE_COLOR; return TOK_BAR_COLOR_INACTIVE_WORKSPACE; }
129 <BAR_COLORS>urgent_workspace    { BAR_TRIPLE_COLOR; return TOK_BAR_COLOR_URGENT_WORKSPACE; }
130 <BAR_COLOR>#[0-9a-fA-F]+        { yy_pop_state(); yylval.string = sstrdup(yytext); return HEXCOLOR; }
131 <BAR_COLOR>{EOL}                {
132                                   yy_pop_state();
133                                   FREE(context->line_copy);
134                                   context->line_number++;
135                                   yy_push_state(BUFFER_LINE);
136                                 }
137 <BAR,BAR_COLORS,BAR_MODE,BAR_MODIFIER,BAR_POSITION>[a-zA-Z]+ { yylval.string = sstrdup(yytext); return WORD; }
138
139
140
141 <FOR_WINDOW_COND>"]"            { yy_pop_state(); return ']'; }
142 <ASSIGN_COND>"["                {
143                                   /* this is the case for the new assign syntax
144                                    * that uses criteria */
145                                   yy_pop_state();
146                                   yy_push_state(FOR_WINDOW_COND);
147                                   /* afterwards we will be in ASSIGN_TARGET_COND */
148                                   return '[';
149                                 }
150 <EAT_WHITESPACE>[ \t]*          { yy_pop_state(); }
151 <EAT_WHITESPACE>{EOL}           { yy_pop_state(); }
152 <BINDSYM_COND>{EOL}             { yy_pop_state(); }
153 <WANT_QSTRING>\"[^\"]+\"        {
154                                   yy_pop_state();
155                                   /* strip quotes */
156                                   char *copy = sstrdup(yytext+1);
157                                   copy[strlen(copy)-1] = '\0';
158                                   yylval.string = copy;
159                                   return STR;
160                                 }
161 <WANT_STRING>[^\n]+             { yy_pop_state(); yylval.string = sstrdup(yytext); return STR; }
162 <OUTPUT_COND>[a-zA-Z0-9_-]+     { yy_pop_state(); yylval.string = sstrdup(yytext); return OUTPUT; }
163 ^[ \t]*#[^\n]*                  { return TOKCOMMENT; }
164 <COLOR_COND>#[0-9a-fA-F]+       { yy_pop_state(); yylval.string = sstrdup(yytext); return HEXCOLOR; }
165 <COLOR_COND>{EOL}               {
166                                   yy_pop_state();
167                                   FREE(context->line_copy);
168                                   context->line_number++;
169                                   yy_push_state(BUFFER_LINE);
170                                 }
171 <ASSIGN_TARGET_COND>[ \t]*→[ \t]*     { BEGIN(WANT_STRING); }
172 <ASSIGN_TARGET_COND>[ \t]+      { BEGIN(WANT_STRING); }
173 <EXEC>--no-startup-id           { printf("no startup id\n"); yy_pop_state(); return TOK_NO_STARTUP_ID; }
174 <EXEC>.                         { printf("anything else: *%s*\n", yytext); yyless(0); yy_pop_state(); yy_pop_state(); }
175 [0-9-]+                         { yylval.number = atoi(yytext); return NUMBER; }
176 bar                             { yy_push_state(BAR); return TOK_BAR; }
177 mode                            { return TOKMODE; }
178 bind                            { yy_push_state(WANT_STRING); yy_push_state(EAT_WHITESPACE); yy_push_state(EAT_WHITESPACE); return TOKBINDCODE; }
179 bindcode                        { yy_push_state(WANT_STRING); yy_push_state(EAT_WHITESPACE); yy_push_state(EAT_WHITESPACE); return TOKBINDCODE; }
180 bindsym                         { yy_push_state(BINDSYM_COND); yy_push_state(EAT_WHITESPACE); return TOKBINDSYM; }
181 floating_maximum_size           { return TOKFLOATING_MAXIMUM_SIZE; }
182 floating_minimum_size           { return TOKFLOATING_MINIMUM_SIZE; }
183 floating_modifier               { return TOKFLOATING_MODIFIER; }
184 workspace                       { return TOKWORKSPACE; }
185 output                          { yy_push_state(OUTPUT_COND); yy_push_state(EAT_WHITESPACE); return TOKOUTPUT; }
186 terminal                        { WS_STRING; return TOKTERMINAL; }
187 font                            { WS_STRING; return TOKFONT; }
188 assign                          { yy_push_state(ASSIGN_TARGET_COND); yy_push_state(ASSIGN_COND); return TOKASSIGN; }
189 set[^\n]*                       { return TOKCOMMENT; }
190 ipc-socket                      { WS_STRING; return TOKIPCSOCKET; }
191 ipc_socket                      { WS_STRING; return TOKIPCSOCKET; }
192 restart_state                   { WS_STRING; return TOKRESTARTSTATE; }
193 default_orientation             { return TOK_ORIENTATION; }
194 horizontal                      { return TOK_HORIZ; }
195 vertical                        { return TOK_VERT; }
196 auto                            { return TOK_AUTO; }
197 workspace_layout                { return TOK_WORKSPACE_LAYOUT; }
198 new_window                      { return TOKNEWWINDOW; }
199 new_float                       { return TOKNEWFLOAT; }
200 normal                          { return TOK_NORMAL; }
201 none                            { return TOK_NONE; }
202 1pixel                          { return TOK_1PIXEL; }
203 hide_edge_borders               { return TOK_HIDE_EDGE_BORDERS; }
204 both                            { return TOK_BOTH; }
205 focus_follows_mouse             { return TOKFOCUSFOLLOWSMOUSE; }
206 force_focus_wrapping            { return TOK_FORCE_FOCUS_WRAPPING; }
207 force_xinerama                  { return TOK_FORCE_XINERAMA; }
208 force-xinerama                  { return TOK_FORCE_XINERAMA; }
209 fake_outputs                    { WS_STRING; return TOK_FAKE_OUTPUTS; }
210 fake-outputs                    { WS_STRING; return TOK_FAKE_OUTPUTS; }
211 workspace_auto_back_and_forth   { return TOK_WORKSPACE_AUTO_BAF; }
212 workspace_bar                   { return TOKWORKSPACEBAR; }
213 popup_during_fullscreen         { return TOK_POPUP_DURING_FULLSCREEN; }
214 ignore                          { return TOK_IGNORE; }
215 leave_fullscreen                { return TOK_LEAVE_FULLSCREEN; }
216 for_window                      {
217                                   /* Example: for_window [class="urxvt"] border none
218                                    *
219                                    * First, we wait for the ']' that finishes a match (FOR_WINDOW_COND)
220                                    * Then, we require a whitespace (EAT_WHITESPACE)
221                                    * And the rest of the line is parsed as a string
222                                    */
223                                   yy_push_state(WANT_STRING);
224                                   yy_push_state(EAT_WHITESPACE);
225                                   yy_push_state(FOR_WINDOW_COND);
226                                   return TOK_FOR_WINDOW;
227                                 }
228 default                         { /* yylval.number = MODE_DEFAULT; */return TOK_DEFAULT; }
229 stacking                        { /* yylval.number = MODE_STACK; */return TOK_STACKING; }
230 stacked                         { return TOK_STACKING; }
231 tabbed                          { /* yylval.number = MODE_TABBED; */return TOK_TABBED; }
232 stack-limit                     { return TOKSTACKLIMIT; }
233 cols                            { /* yylval.number = STACK_LIMIT_COLS; */return TOKSTACKLIMIT; }
234 rows                            { /* yylval.number = STACK_LIMIT_ROWS; */return TOKSTACKLIMIT; }
235 exec                            { WS_STRING; yy_push_state(EXEC); yy_push_state(EAT_WHITESPACE); return TOKEXEC; }
236 exec_always                     { WS_STRING; yy_push_state(EXEC); yy_push_state(EAT_WHITESPACE); return TOKEXEC_ALWAYS; }
237 client.background               { yy_push_state(COLOR_COND); yylval.single_color = &config.client.background; return TOKSINGLECOLOR; }
238 client.focused                  { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.focused; return TOKCOLOR; }
239 client.focused_inactive         { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.focused_inactive; return TOKCOLOR; }
240 client.unfocused                { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.unfocused; return TOKCOLOR; }
241 client.urgent                   { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.urgent; return TOKCOLOR; }
242 bar.focused                     { yy_push_state(COLOR_COND); yylval.color = &config.bar.focused; return TOKCOLOR; }
243 bar.unfocused                   { yy_push_state(COLOR_COND); yylval.color = &config.bar.unfocused; return TOKCOLOR; }
244 bar.urgent                      { yy_push_state(COLOR_COND); yylval.color = &config.bar.urgent; return TOKCOLOR; }
245 Mod1                            { yylval.number = BIND_MOD1; return MODIFIER; }
246 Mod2                            { yylval.number = BIND_MOD2; return MODIFIER; }
247 Mod3                            { yylval.number = BIND_MOD3; return MODIFIER; }
248 Mod4                            { yylval.number = BIND_MOD4; return MODIFIER; }
249 Mod5                            { yylval.number = BIND_MOD5; return MODIFIER; }
250 Mode_switch                     { yylval.number = BIND_MODE_SWITCH; return MODIFIER; }
251 control                         { return TOKCONTROL; }
252 ctrl                            { return TOKCONTROL; }
253 shift                           { return TOKSHIFT; }
254
255 class                           { yy_push_state(WANT_QSTRING); return TOK_CLASS; }
256 instance                        { yy_push_state(WANT_QSTRING); return TOK_INSTANCE; }
257 window_role                     { yy_push_state(WANT_QSTRING); return TOK_WINDOW_ROLE; }
258 id                              { yy_push_state(WANT_QSTRING); return TOK_ID; }
259 con_id                          { yy_push_state(WANT_QSTRING); return TOK_CON_ID; }
260 con_mark                        { yy_push_state(WANT_QSTRING); return TOK_MARK; }
261 title                           { yy_push_state(WANT_QSTRING); return TOK_TITLE; }
262 urgent                          { yy_push_state(WANT_QSTRING); return TOK_URGENT; }
263
264 <*>{EOL}                        {
265                                   FREE(context->line_copy);
266                                   context->line_number++;
267                                   yy_push_state(BUFFER_LINE);
268                                 }
269 <BINDSYM_COND>[ \t]+            { yy_pop_state(); yy_push_state(WANT_STRING); }
270 <OUTPUT_COND>[ \t]+             { yy_pop_state(); yy_push_state(WANT_STRING); }
271 [ \t]+                          { /* ignore whitespace */ ; }
272 \"[^\"]+\"                      {
273                                   /* if ASSIGN_COND then */
274                                   if (yy_start_stack_ptr > 0)
275                                       yy_pop_state();
276                                   /* yylval will be the string, but without quotes */
277                                   char *copy = sstrdup(yytext+1);
278                                   copy[strlen(copy)-1] = '\0';
279                                   yylval.string = copy;
280                                   return QUOTEDSTRING;
281                                 }
282 <ASSIGN_COND>[^ \t\"\[]+        { BEGIN(ASSIGN_TARGET_COND); yylval.string = sstrdup(yytext); return STR_NG; }
283 <BINDSYM_COND>[a-zA-Z0-9_]+     { yylval.string = sstrdup(yytext); return WORD; }
284 [a-zA-Z]+                       { yylval.string = sstrdup(yytext); return WORD; }
285 .                               { return (int)yytext[0]; }
286
287 <<EOF>> {
288     while (yy_start_stack_ptr > 0)
289         yy_pop_state();
290     yyterminate();
291 }
292
293 %%