]> git.sur5r.net Git - i3/i3/blob - src/cfgparse.l
Merge branch 'fix-float-close'
[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_DOUBLE_COLOR do { \
41     yy_push_state(BAR_COLOR); \
42     yy_push_state(BAR_COLOR); \
43 } while (0)
44
45 %}
46
47 EOL     (\r?\n)
48
49 %s WANT_STRING
50 %s WANT_QSTRING
51 %s BINDSYM_COND
52 %s ASSIGN_COND
53 %s ASSIGN_TARGET_COND
54 %s COLOR_COND
55 %s OUTPUT_COND
56 %s FOR_WINDOW_COND
57 %s EAT_WHITESPACE
58
59 %x BUFFER_LINE
60 %x BAR
61 %x BAR_MODE
62 %x BAR_POSITION
63 %x BAR_COLORS
64 %x BAR_COLOR
65
66 %x EXEC
67
68 %%
69
70     {
71         /* This is called when a new line is lexed. We only want the
72          * first line to match to go into state BUFFER_LINE */
73         if (context->line_number == 0) {
74             context->line_number = 1;
75             BEGIN(INITIAL);
76             yy_push_state(BUFFER_LINE);
77         }
78     }
79
80 <BUFFER_LINE>^[^\r\n]*/{EOL}? {
81     /* save whole line */
82     context->line_copy = sstrdup(yytext);
83
84     yyless(0);
85     yy_pop_state();
86     yy_set_bol(true);
87     yycolumn = 1;
88 }
89
90  /* This part of the lexer handles the bar {} blocks */
91 <BAR,BAR_MODE,BAR_POSITION,BAR_COLORS,BAR_COLOR>[ \t]+ { /* ignore whitespace */ ; }
92 <BAR>"{"                        { return '{'; }
93 <BAR>"}"                        { yy_pop_state(); return '}'; }
94 <BAR>^[ \t]*#[^\n]*             { return TOKCOMMENT; }
95 <BAR>output                     { WS_STRING; return TOK_BAR_OUTPUT; }
96 <BAR>tray_output                { WS_STRING; return TOK_BAR_TRAY_OUTPUT; }
97 <BAR>socket_path                { WS_STRING; return TOK_BAR_SOCKET_PATH; }
98 <BAR>mode                       { yy_push_state(BAR_MODE); return TOK_BAR_MODE; }
99 <BAR_MODE>hide                  { yy_pop_state(); return TOK_BAR_HIDE; }
100 <BAR_MODE>dock                  { yy_pop_state(); return TOK_BAR_DOCK; }
101 <BAR>position                   { yy_push_state(BAR_POSITION); return TOK_BAR_POSITION; }
102 <BAR_POSITION>bottom            { yy_pop_state(); return TOK_BAR_BOTTOM; }
103 <BAR_POSITION>top               { yy_pop_state(); return TOK_BAR_TOP; }
104 <BAR>status_command             { WS_STRING; return TOK_BAR_STATUS_COMMAND; }
105 <BAR>font                       { WS_STRING; return TOK_BAR_FONT; }
106 <BAR>workspace_buttons          { return TOK_BAR_WORKSPACE_BUTTONS; }
107 <BAR>verbose                    { return TOK_BAR_VERBOSE; }
108 <BAR>colors                     { yy_push_state(BAR_COLORS); return TOK_BAR_COLORS; }
109 <BAR_COLORS>"{"                 { return '{'; }
110 <BAR_COLORS>"}"                 { yy_pop_state(); return '}'; }
111 <BAR_COLORS>^[ \t]*#[^\n]*      { return TOKCOMMENT; }
112 <BAR_COLORS>background          { yy_push_state(BAR_COLOR); return TOK_BAR_COLOR_BACKGROUND; }
113 <BAR_COLORS>statusline          { yy_push_state(BAR_COLOR); return TOK_BAR_COLOR_STATUSLINE; }
114 <BAR_COLORS>focused_workspace   { BAR_DOUBLE_COLOR; return TOK_BAR_COLOR_FOCUSED_WORKSPACE; }
115 <BAR_COLORS>active_workspace    { BAR_DOUBLE_COLOR; return TOK_BAR_COLOR_ACTIVE_WORKSPACE; }
116 <BAR_COLORS>inactive_workspace  { BAR_DOUBLE_COLOR; return TOK_BAR_COLOR_INACTIVE_WORKSPACE; }
117 <BAR_COLORS>urgent_workspace    { BAR_DOUBLE_COLOR; return TOK_BAR_COLOR_URGENT_WORKSPACE; }
118 <BAR_COLOR>#[0-9a-fA-F]+        { yy_pop_state(); yylval.string = sstrdup(yytext); return HEXCOLOR; }
119 <BAR,BAR_COLORS,BAR_MODE,BAR_POSITION>[a-zA-Z]+ { yylval.string = sstrdup(yytext); return WORD; }
120
121
122
123 <FOR_WINDOW_COND>"]"            { yy_pop_state(); return ']'; }
124 <ASSIGN_COND>"["                {
125                                   /* this is the case for the new assign syntax
126                                    * that uses criteria */
127                                   yy_pop_state();
128                                   yy_push_state(FOR_WINDOW_COND);
129                                   /* afterwards we will be in ASSIGN_TARGET_COND */
130                                   return '[';
131                                 }
132 <EAT_WHITESPACE>[ \t]*          { yy_pop_state(); }
133 <WANT_QSTRING>\"[^\"]+\"        {
134                                   yy_pop_state();
135                                   /* strip quotes */
136                                   char *copy = sstrdup(yytext+1);
137                                   copy[strlen(copy)-1] = '\0';
138                                   yylval.string = copy;
139                                   return STR;
140                                 }
141 <WANT_STRING>[^\n]+             { yy_pop_state(); yylval.string = sstrdup(yytext); return STR; }
142 <OUTPUT_COND>[a-zA-Z0-9_-]+     { yy_pop_state(); yylval.string = sstrdup(yytext); return OUTPUT; }
143 ^[ \t]*#[^\n]*                  { return TOKCOMMENT; }
144 <COLOR_COND>#[0-9a-fA-F]+       { yy_pop_state(); yylval.string = sstrdup(yytext); return HEXCOLOR; }
145 <ASSIGN_TARGET_COND>[ \t]*→[ \t]*     { BEGIN(WANT_STRING); }
146 <ASSIGN_TARGET_COND>[ \t]+      { BEGIN(WANT_STRING); }
147 <EXEC>--no-startup-id           { printf("no startup id\n"); yy_pop_state(); return TOK_NO_STARTUP_ID; }
148 <EXEC>.                         { printf("anything else: *%s*\n", yytext); yyless(0); yy_pop_state(); yy_pop_state(); }
149 [0-9]+                          { yylval.number = atoi(yytext); return NUMBER; }
150 bar                             { yy_push_state(BAR); return TOK_BAR; }
151 mode                            { return TOKMODE; }
152 bind                            { yy_push_state(WANT_STRING); yy_push_state(EAT_WHITESPACE); yy_push_state(EAT_WHITESPACE); return TOKBINDCODE; }
153 bindcode                        { yy_push_state(WANT_STRING); yy_push_state(EAT_WHITESPACE); yy_push_state(EAT_WHITESPACE); return TOKBINDCODE; }
154 bindsym                         { yy_push_state(BINDSYM_COND); yy_push_state(EAT_WHITESPACE); return TOKBINDSYM; }
155 floating_modifier               { return TOKFLOATING_MODIFIER; }
156 workspace                       { return TOKWORKSPACE; }
157 output                          { yy_push_state(OUTPUT_COND); yy_push_state(EAT_WHITESPACE); return TOKOUTPUT; }
158 terminal                        { WS_STRING; return TOKTERMINAL; }
159 font                            { WS_STRING; return TOKFONT; }
160 assign                          { yy_push_state(ASSIGN_TARGET_COND); yy_push_state(ASSIGN_COND); return TOKASSIGN; }
161 set[^\n]*                       { return TOKCOMMENT; }
162 ipc-socket                      { WS_STRING; return TOKIPCSOCKET; }
163 ipc_socket                      { WS_STRING; return TOKIPCSOCKET; }
164 restart_state                   { WS_STRING; return TOKRESTARTSTATE; }
165 default_orientation             { return TOK_ORIENTATION; }
166 horizontal                      { return TOK_HORIZ; }
167 vertical                        { return TOK_VERT; }
168 auto                            { return TOK_AUTO; }
169 workspace_layout                { return TOK_WORKSPACE_LAYOUT; }
170 new_window                      { return TOKNEWWINDOW; }
171 new_float                       { return TOKNEWFLOAT; }
172 normal                          { return TOK_NORMAL; }
173 none                            { return TOK_NONE; }
174 1pixel                          { return TOK_1PIXEL; }
175 focus_follows_mouse             { return TOKFOCUSFOLLOWSMOUSE; }
176 force_focus_wrapping            { return TOK_FORCE_FOCUS_WRAPPING; }
177 force_xinerama                  { return TOK_FORCE_XINERAMA; }
178 workspace_auto_back_and_forth   { return TOK_WORKSPACE_AUTO_BAF; }
179 workspace_bar                   { return TOKWORKSPACEBAR; }
180 popup_during_fullscreen         { return TOK_POPUP_DURING_FULLSCREEN; }
181 ignore                          { return TOK_IGNORE; }
182 leave_fullscreen                { return TOK_LEAVE_FULLSCREEN; }
183 for_window                      {
184                                   /* Example: for_window [class="urxvt"] border none
185                                    *
186                                    * First, we wait for the ']' that finishes a match (FOR_WINDOW_COND)
187                                    * Then, we require a whitespace (EAT_WHITESPACE)
188                                    * And the rest of the line is parsed as a string
189                                    */
190                                   yy_push_state(WANT_STRING);
191                                   yy_push_state(EAT_WHITESPACE);
192                                   yy_push_state(FOR_WINDOW_COND);
193                                   return TOK_FOR_WINDOW;
194                                 }
195 default                         { /* yylval.number = MODE_DEFAULT; */return TOK_DEFAULT; }
196 stacking                        { /* yylval.number = MODE_STACK; */return TOK_STACKING; }
197 stacked                         { return TOK_STACKING; }
198 tabbed                          { /* yylval.number = MODE_TABBED; */return TOK_TABBED; }
199 stack-limit                     { return TOKSTACKLIMIT; }
200 cols                            { /* yylval.number = STACK_LIMIT_COLS; */return TOKSTACKLIMIT; }
201 rows                            { /* yylval.number = STACK_LIMIT_ROWS; */return TOKSTACKLIMIT; }
202 exec                            { WS_STRING; yy_push_state(EXEC); yy_push_state(EAT_WHITESPACE); return TOKEXEC; }
203 exec_always                     { WS_STRING; yy_push_state(EXEC); yy_push_state(EAT_WHITESPACE); return TOKEXEC_ALWAYS; }
204 client.background               { yy_push_state(COLOR_COND); yylval.single_color = &config.client.background; return TOKSINGLECOLOR; }
205 client.focused                  { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.focused; return TOKCOLOR; }
206 client.focused_inactive         { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.focused_inactive; return TOKCOLOR; }
207 client.unfocused                { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.unfocused; return TOKCOLOR; }
208 client.urgent                   { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.urgent; return TOKCOLOR; }
209 bar.focused                     { yy_push_state(COLOR_COND); yylval.color = &config.bar.focused; return TOKCOLOR; }
210 bar.unfocused                   { yy_push_state(COLOR_COND); yylval.color = &config.bar.unfocused; return TOKCOLOR; }
211 bar.urgent                      { yy_push_state(COLOR_COND); yylval.color = &config.bar.urgent; return TOKCOLOR; }
212 Mod1                            { yylval.number = BIND_MOD1; return MODIFIER; }
213 Mod2                            { yylval.number = BIND_MOD2; return MODIFIER; }
214 Mod3                            { yylval.number = BIND_MOD3; return MODIFIER; }
215 Mod4                            { yylval.number = BIND_MOD4; return MODIFIER; }
216 Mod5                            { yylval.number = BIND_MOD5; return MODIFIER; }
217 Mode_switch                     { yylval.number = BIND_MODE_SWITCH; return MODIFIER; }
218 control                         { return TOKCONTROL; }
219 ctrl                            { return TOKCONTROL; }
220 shift                           { return TOKSHIFT; }
221
222 class                           { yy_push_state(WANT_QSTRING); return TOK_CLASS; }
223 instance                        { yy_push_state(WANT_QSTRING); return TOK_INSTANCE; }
224 window_role                     { yy_push_state(WANT_QSTRING); return TOK_WINDOW_ROLE; }
225 id                              { yy_push_state(WANT_QSTRING); return TOK_ID; }
226 con_id                          { yy_push_state(WANT_QSTRING); return TOK_CON_ID; }
227 con_mark                        { yy_push_state(WANT_QSTRING); return TOK_MARK; }
228 title                           { yy_push_state(WANT_QSTRING); return TOK_TITLE; }
229
230 <*>{EOL}                        {
231                                   FREE(context->line_copy);
232                                   context->line_number++;
233                                   yy_push_state(BUFFER_LINE);
234                                 }
235 <BINDSYM_COND>[ \t]+            { yy_pop_state(); yy_push_state(WANT_STRING); }
236 <OUTPUT_COND>[ \t]+             { yy_pop_state(); yy_push_state(WANT_STRING); }
237 [ \t]+                          { /* ignore whitespace */ ; }
238 \"[^\"]+\"                      {
239                                   /* if ASSIGN_COND then */
240                                   if (yy_start_stack_ptr > 0)
241                                       yy_pop_state();
242                                   /* yylval will be the string, but without quotes */
243                                   char *copy = sstrdup(yytext+1);
244                                   copy[strlen(copy)-1] = '\0';
245                                   yylval.string = copy;
246                                   return QUOTEDSTRING;
247                                 }
248 <ASSIGN_COND>[^ \t\"\[]+        { BEGIN(ASSIGN_TARGET_COND); yylval.string = sstrdup(yytext); return STR_NG; }
249 <BINDSYM_COND>[a-zA-Z0-9_]+     { yylval.string = sstrdup(yytext); return WORD; }
250 [a-zA-Z]+                       { yylval.string = sstrdup(yytext); return WORD; }
251 .                               { return (int)yytext[0]; }
252
253 <<EOF>> {
254     while (yy_start_stack_ptr > 0)
255         yy_pop_state();
256     yyterminate();
257 }
258
259 %%