]> git.sur5r.net Git - i3/i3/blob - src/cfgparse.l
Merge branch 'fix-float-size'
[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 "data.h"
17 #include "config.h"
18 #include "log.h"
19 #include "util.h"
20
21 #include "cfgparse.tab.h"
22
23 int yycolumn = 1;
24
25 #define YY_DECL int yylex (struct context *context)
26
27 #define YY_USER_ACTION { \
28     context->first_column = yycolumn; \
29     context->last_column = yycolumn+yyleng-1; \
30     yycolumn += yyleng; \
31 }
32
33 /* macro to first eat whitespace, then expect a string */
34 #define WS_STRING do { \
35     yy_push_state(WANT_STRING); \
36     yy_push_state(EAT_WHITESPACE); \
37 } while (0)
38
39 %}
40
41 EOL     (\r?\n)
42
43 %s WANT_STRING
44 %s WANT_QSTRING
45 %s BINDSYM_COND
46 %s ASSIGN_COND
47 %s ASSIGN_TARGET_COND
48 %s COLOR_COND
49 %s OUTPUT_COND
50 %s FOR_WINDOW_COND
51 %s EAT_WHITESPACE
52 %x BUFFER_LINE
53
54 %%
55
56     {
57         /* This is called when a new line is lexed. We only want the
58          * first line to match to go into state BUFFER_LINE */
59         if (context->line_number == 0) {
60             context->line_number = 1;
61             BEGIN(INITIAL);
62             yy_push_state(BUFFER_LINE);
63         }
64     }
65
66 <BUFFER_LINE>^[^\r\n]*/{EOL}? {
67     /* save whole line */
68     context->line_copy = sstrdup(yytext);
69
70     yyless(0);
71     yy_pop_state();
72     yy_set_bol(true);
73     yycolumn = 1;
74 }
75
76
77 <FOR_WINDOW_COND>"]"            { yy_pop_state(); return ']'; }
78 <EAT_WHITESPACE>[ \t]*          { yy_pop_state(); }
79 <WANT_QSTRING>\"[^\"]+\"        {
80                                   yy_pop_state();
81                                   /* strip quotes */
82                                   char *copy = sstrdup(yytext+1);
83                                   copy[strlen(copy)-1] = '\0';
84                                   yylval.string = copy;
85                                   return STR;
86                                 }
87 <WANT_STRING>[^\n]+             { BEGIN(INITIAL); yylval.string = sstrdup(yytext); return STR; }
88 <OUTPUT_COND>[a-zA-Z0-9_-]+     { yylval.string = sstrdup(yytext); return OUTPUT; }
89 ^[ \t]*#[^\n]*                  { return TOKCOMMENT; }
90 <COLOR_COND>[0-9a-fA-F]+        { yylval.string = sstrdup(yytext); return HEX; }
91 <ASSIGN_TARGET_COND>[ \t]*→[ \t]*     { BEGIN(WANT_STRING); }
92 <ASSIGN_TARGET_COND>[ \t]+      { BEGIN(WANT_STRING); }
93 [0-9]+                          { yylval.number = atoi(yytext); return NUMBER; }
94 mode                            { return TOKMODE; }
95 bind                            { yy_push_state(WANT_STRING); yy_push_state(EAT_WHITESPACE); yy_push_state(EAT_WHITESPACE); return TOKBINDCODE; }
96 bindcode                        { yy_push_state(WANT_STRING); yy_push_state(EAT_WHITESPACE); yy_push_state(EAT_WHITESPACE); return TOKBINDCODE; }
97 bindsym                         { yy_push_state(BINDSYM_COND); yy_push_state(EAT_WHITESPACE); return TOKBINDSYM; }
98 floating_modifier               { BEGIN(INITIAL); return TOKFLOATING_MODIFIER; }
99 workspace                       { BEGIN(INITIAL); return TOKWORKSPACE; }
100 output                          { yy_push_state(OUTPUT_COND); yy_push_state(EAT_WHITESPACE); return TOKOUTPUT; }
101 screen                          {
102                                   /* for compatibility until v3.φ */
103                                   ELOG("Assignments to screens are DEPRECATED and will not work. " \
104                                        "Please replace them with assignments to outputs.\n");
105                                   yy_push_state(OUTPUT_COND); yy_push_state(EAT_WHITESPACE);
106                                   return TOKOUTPUT;
107                                 }
108 terminal                        { WS_STRING; return TOKTERMINAL; }
109 font                            { WS_STRING; return TOKFONT; }
110 assign                          { yy_push_state(ASSIGN_TARGET_COND); yy_push_state(ASSIGN_COND); return TOKASSIGN; }
111 set[^\n]*                       { return TOKCOMMENT; }
112 ipc-socket                      { WS_STRING; return TOKIPCSOCKET; }
113 ipc_socket                      { WS_STRING; return TOKIPCSOCKET; }
114 restart_state                   { WS_STRING; return TOKRESTARTSTATE; }
115 default_orientation             { return TOK_ORIENTATION; }
116 horizontal                      { return TOK_HORIZ; }
117 vertical                        { return TOK_VERT; }
118 auto                            { return TOK_AUTO; }
119 workspace_layout                { return TOK_WORKSPACE_LAYOUT; }
120 new_window                      { return TOKNEWWINDOW; }
121 normal                          { return TOK_NORMAL; }
122 none                            { return TOK_NONE; }
123 1pixel                          { return TOK_1PIXEL; }
124 focus_follows_mouse             { return TOKFOCUSFOLLOWSMOUSE; }
125 force_focus_wrapping            { return TOK_FORCE_FOCUS_WRAPPING; }
126 workspace_bar                   { return TOKWORKSPACEBAR; }
127 popup_during_fullscreen         { return TOK_POPUP_DURING_FULLSCREEN; }
128 ignore                          { return TOK_IGNORE; }
129 leave_fullscreen                { return TOK_LEAVE_FULLSCREEN; }
130 for_window                      {
131                                   /* Example: for_window [class="urxvt"] border none
132                                    *
133                                    * First, we wait for the ']' that finishes a match (FOR_WINDOW_COND)
134                                    * Then, we require a whitespace (EAT_WHITESPACE)
135                                    * And the rest of the line is parsed as a string
136                                    */
137                                   yy_push_state(WANT_STRING);
138                                   yy_push_state(EAT_WHITESPACE);
139                                   yy_push_state(FOR_WINDOW_COND);
140                                   return TOK_FOR_WINDOW;
141                                 }
142 default                         { /* yylval.number = MODE_DEFAULT; */return TOK_DEFAULT; }
143 stacking                        { /* yylval.number = MODE_STACK; */return TOK_STACKING; }
144 stacked                         { return TOK_STACKING; }
145 tabbed                          { /* yylval.number = MODE_TABBED; */return TOK_TABBED; }
146 stack-limit                     { return TOKSTACKLIMIT; }
147 cols                            { /* yylval.number = STACK_LIMIT_COLS; */return TOKSTACKLIMIT; }
148 rows                            { /* yylval.number = STACK_LIMIT_ROWS; */return TOKSTACKLIMIT; }
149 exec                            { WS_STRING; return TOKEXEC; }
150 exec_always                     { WS_STRING; return TOKEXEC_ALWAYS; }
151 client.background               { BEGIN(COLOR_COND); yylval.single_color = &config.client.background; return TOKSINGLECOLOR; }
152 client.focused                  { BEGIN(COLOR_COND); yylval.color = &config.client.focused; return TOKCOLOR; }
153 client.focused_inactive         { BEGIN(COLOR_COND); yylval.color = &config.client.focused_inactive; return TOKCOLOR; }
154 client.unfocused                { BEGIN(COLOR_COND); yylval.color = &config.client.unfocused; return TOKCOLOR; }
155 client.urgent                   { BEGIN(COLOR_COND); yylval.color = &config.client.urgent; return TOKCOLOR; }
156 bar.focused                     { BEGIN(COLOR_COND); yylval.color = &config.bar.focused; return TOKCOLOR; }
157 bar.unfocused                   { BEGIN(COLOR_COND); yylval.color = &config.bar.unfocused; return TOKCOLOR; }
158 bar.urgent                      { BEGIN(COLOR_COND); yylval.color = &config.bar.urgent; return TOKCOLOR; }
159 Mod1                            { yylval.number = BIND_MOD1; return MODIFIER; }
160 Mod2                            { yylval.number = BIND_MOD2; return MODIFIER; }
161 Mod3                            { yylval.number = BIND_MOD3; return MODIFIER; }
162 Mod4                            { yylval.number = BIND_MOD4; return MODIFIER; }
163 Mod5                            { yylval.number = BIND_MOD5; return MODIFIER; }
164 Mode_switch                     { yylval.number = BIND_MODE_SWITCH; return MODIFIER; }
165 control                         { return TOKCONTROL; }
166 ctrl                            { return TOKCONTROL; }
167 shift                           { return TOKSHIFT; }
168
169 class                           { yy_push_state(WANT_QSTRING); return TOK_CLASS; }
170 instance                        { yy_push_state(WANT_QSTRING); return TOK_INSTANCE; }
171 id                              { yy_push_state(WANT_QSTRING); return TOK_ID; }
172 con_id                          { yy_push_state(WANT_QSTRING); return TOK_CON_ID; }
173 con_mark                        { yy_push_state(WANT_QSTRING); return TOK_MARK; }
174 title                           { yy_push_state(WANT_QSTRING); return TOK_TITLE; }
175
176 {EOL}                           {
177                                   FREE(context->line_copy);
178                                   context->line_number++;
179                                   BEGIN(INITIAL);
180                                   yy_push_state(BUFFER_LINE);
181                                 }
182 <BINDSYM_COND>[ \t]+            { BEGIN(WANT_STRING); }
183 <OUTPUT_COND>[ \t]+             { BEGIN(WANT_STRING); }
184 [ \t]+                          { /* ignore whitespace */ ; }
185 \"[^\"]+\"                      {
186                                   /* if ASSIGN_COND then */
187                                   if (yy_start_stack_ptr > 0)
188                                       yy_pop_state();
189                                   else BEGIN(INITIAL);
190                                   /* yylval will be the string, but without quotes */
191                                   char *copy = sstrdup(yytext+1);
192                                   copy[strlen(copy)-1] = '\0';
193                                   yylval.string = copy;
194                                   return QUOTEDSTRING;
195                                 }
196 <ASSIGN_COND>[^ \t\"]+          { BEGIN(ASSIGN_TARGET_COND); yylval.string = sstrdup(yytext); return STR_NG; }
197 <BINDSYM_COND>[a-zA-Z0-9_]+     { yylval.string = sstrdup(yytext); return WORD; }
198 [a-zA-Z]+                       { yylval.string = sstrdup(yytext); return WORD; }
199 .                               { return (int)yytext[0]; }
200
201 <<EOF>> {
202     while (yy_start_stack_ptr > 0)
203         yy_pop_state();
204     yyterminate();
205 }
206
207 %%