]> git.sur5r.net Git - i3/i3/blob - src/cfgparse.l
re-implement assigning windows to workspaces
[i3/i3] / src / cfgparse.l
1 %option nounput
2 %option noinput
3 %option noyy_top_state
4 %option stack
5
6 %{
7 /*
8  * vim:ts=8:expandtab
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 %}
34
35 EOL     (\r?\n)
36
37 %s BINDCODE_COND
38 %s BINDSYM_COND
39 %s BIND_AWS_COND
40 %s BINDSYM_AWS_COND
41 %s BIND_A2WS_COND
42 %s ASSIGN_COND
43 %s COLOR_COND
44 %s OUTPUT_COND
45 %s OUTPUT_AWS_COND
46 %x BUFFER_LINE
47
48 %%
49
50         {
51                 /* This is called when a new line is lexed. We only want the
52                  * first line to match to go into state BUFFER_LINE */
53                 if (context->line_number == 0) {
54                         context->line_number = 1;
55                         BEGIN(INITIAL);
56                         yy_push_state(BUFFER_LINE);
57                 }
58         }
59
60 <BUFFER_LINE>^[^\r\n]*/{EOL}? {
61         /* save whole line */
62         context->line_copy = strdup(yytext);
63
64         yyless(0);
65         yy_pop_state();
66         yy_set_bol(true);
67         yycolumn = 1;
68 }
69
70
71 <BIND_A2WS_COND>[^\n]+          { BEGIN(INITIAL); yylval.string = strdup(yytext); return STR; }
72 <OUTPUT_AWS_COND>[a-zA-Z0-9_-]+ { yylval.string = strdup(yytext); return OUTPUT; }
73 ^[ \t]*#[^\n]*                  { return TOKCOMMENT; }
74 <COLOR_COND>[0-9a-fA-F]+        { yylval.string = strdup(yytext); return HEX; }
75 [0-9]+                          { yylval.number = atoi(yytext); return NUMBER; }
76 mode                            { return TOKMODE; }
77 bind                            { BEGIN(BINDCODE_COND); return TOKBINDCODE; }
78 bindcode                        { BEGIN(BINDCODE_COND); return TOKBINDCODE; }
79 bindsym                         { BEGIN(BINDSYM_COND); return TOKBINDSYM; }
80 floating_modifier               { BEGIN(INITIAL); return TOKFLOATING_MODIFIER; }
81 workspace                       { BEGIN(INITIAL); return TOKWORKSPACE; }
82 output                          { BEGIN(OUTPUT_COND); return TOKOUTPUT; }
83 screen                          {
84                                   /* for compatibility until v3.φ */
85                                   ELOG("Assignments to screens are DEPRECATED and will not work. " \
86                                        "Please replace them with assignments to outputs.\n");
87                                   BEGIN(OUTPUT_COND);
88                                   return TOKOUTPUT;
89                                 }
90 terminal                        { BEGIN(BIND_AWS_COND); return TOKTERMINAL; }
91 font                            { BEGIN(BIND_AWS_COND); return TOKFONT; }
92 assign                          { BEGIN(ASSIGN_COND); return TOKASSIGN; }
93 set[^\n]*                       { return TOKCOMMENT; }
94 ipc-socket                      { BEGIN(BIND_AWS_COND); return TOKIPCSOCKET; }
95 ipc_socket                      { BEGIN(BIND_AWS_COND); return TOKIPCSOCKET; }
96 restart_state                   { BEGIN(BIND_AWS_COND); return TOKRESTARTSTATE; }
97 default_orientation             { return TOK_ORIENTATION; }
98 horizontal                      { return TOK_HORIZ; }
99 vertical                        { return TOK_VERT; }
100 auto                            { return TOK_AUTO; }
101 workspace_layout                { return TOK_WORKSPACE_LAYOUT; }
102 new_window                      { return TOKNEWWINDOW; }
103 normal                          { return TOK_NORMAL; }
104 none                            { return TOK_NONE; }
105 1pixel                          { return TOK_1PIXEL; }
106 focus_follows_mouse             { return TOKFOCUSFOLLOWSMOUSE; }
107 workspace_bar                   { return TOKWORKSPACEBAR; }
108 popup_during_fullscreen         { return TOK_POPUP_DURING_FULLSCREEN; }
109 ignore                          { return TOK_IGNORE; }
110 leave_fullscreen                { return TOK_LEAVE_FULLSCREEN; }
111 default                         { /* yylval.number = MODE_DEFAULT; */return TOK_DEFAULT; }
112 stacking                        { /* yylval.number = MODE_STACK; */return TOK_STACKING; }
113 stacked                         { return TOK_STACKING; }
114 tabbed                          { /* yylval.number = MODE_TABBED; */return TOK_TABBED; }
115 stack-limit                     { return TOKSTACKLIMIT; }
116 cols                            { /* yylval.number = STACK_LIMIT_COLS; */return TOKSTACKLIMIT; }
117 rows                            { /* yylval.number = STACK_LIMIT_ROWS; */return TOKSTACKLIMIT; }
118 exec                            { BEGIN(BIND_AWS_COND); return TOKEXEC; }
119 client.background               { BEGIN(COLOR_COND); yylval.single_color = &config.client.background; return TOKSINGLECOLOR; }
120 client.focused                  { BEGIN(COLOR_COND); yylval.color = &config.client.focused; return TOKCOLOR; }
121 client.focused_inactive         { BEGIN(COLOR_COND); yylval.color = &config.client.focused_inactive; return TOKCOLOR; }
122 client.unfocused                { BEGIN(COLOR_COND); yylval.color = &config.client.unfocused; return TOKCOLOR; }
123 client.urgent                   { BEGIN(COLOR_COND); yylval.color = &config.client.urgent; return TOKCOLOR; }
124 bar.focused                     { BEGIN(COLOR_COND); yylval.color = &config.bar.focused; return TOKCOLOR; }
125 bar.unfocused                   { BEGIN(COLOR_COND); yylval.color = &config.bar.unfocused; return TOKCOLOR; }
126 bar.urgent                      { BEGIN(COLOR_COND); yylval.color = &config.bar.urgent; return TOKCOLOR; }
127 Mod1                            { yylval.number = BIND_MOD1; return MODIFIER; }
128 Mod2                            { yylval.number = BIND_MOD2; return MODIFIER; }
129 Mod3                            { yylval.number = BIND_MOD3; return MODIFIER; }
130 Mod4                            { yylval.number = BIND_MOD4; return MODIFIER; }
131 Mod5                            { yylval.number = BIND_MOD5; return MODIFIER; }
132 Mode_switch                     { yylval.number = BIND_MODE_SWITCH; return MODIFIER; }
133 control                         { return TOKCONTROL; }
134 ctrl                            { return TOKCONTROL; }
135 shift                           { return TOKSHIFT; }
136 →                               { return TOKARROW; }
137 {EOL}                           {
138                                   FREE(context->line_copy);
139                                   context->line_number++;
140                                   BEGIN(INITIAL);
141                                   yy_push_state(BUFFER_LINE);
142                                 }
143 <BINDCODE_COND>[ \t]+           { BEGIN(BIND_AWS_COND); return WHITESPACE; }
144 <BINDSYM_COND>[ \t]+            { BEGIN(BINDSYM_AWS_COND); return WHITESPACE; }
145 <BIND_AWS_COND>[ \t]+           { BEGIN(BIND_A2WS_COND); return WHITESPACE; }
146 <BINDSYM_AWS_COND>[ \t]+        { BEGIN(BIND_A2WS_COND); return WHITESPACE; }
147 <OUTPUT_COND>[ \t]+             { BEGIN(OUTPUT_AWS_COND); return WHITESPACE; }
148 <OUTPUT_AWS_COND>[ \t]+         { BEGIN(BIND_A2WS_COND); return WHITESPACE; }
149 [ \t]+                          { return WHITESPACE; }
150 \"[^\"]+\"                      {
151                                   /* if ASSIGN_COND then */
152                                   BEGIN(INITIAL);
153                                   /* yylval will be the string, but without quotes */
154                                   char *copy = strdup(yytext+1);
155                                   copy[strlen(copy)-1] = '\0';
156                                   yylval.string = copy;
157                                   return QUOTEDSTRING;
158                                 }
159 <ASSIGN_COND>[^ \t]+            { BEGIN(INITIAL); yylval.string = strdup(yytext); return STR_NG; }
160 <BINDSYM_AWS_COND>[a-zA-Z0-9_]+ { yylval.string = strdup(yytext); return WORD; }
161 [a-zA-Z]+                       { yylval.string = strdup(yytext); return WORD; }
162 .                               { return (int)yytext[0]; }
163
164 <<EOF>> {
165         while (yy_start_stack_ptr > 0)
166                 yy_pop_state();
167         yyterminate();
168 }
169
170 %%