]> git.sur5r.net Git - i3/i3/blob - src/cfgparse.l
Change workspace assignments to use the RandR output name instead of <screen>
[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 "cfgparse.tab.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 int yycolumn = 1;
22
23 #define YY_DECL int yylex (struct context *context)
24
25 #define YY_USER_ACTION { \
26         context->first_column = yycolumn; \
27         context->last_column = yycolumn+yyleng-1; \
28         yycolumn += yyleng; \
29 }
30
31 %}
32
33 EOL     (\r?\n)
34
35 %s BIND_COND
36 %s BINDSYM_COND
37 %s BIND_AWS_COND
38 %s BINDSYM_AWS_COND
39 %s BIND_A2WS_COND
40 %s ASSIGN_COND
41 %s COLOR_COND
42 %s OUTPUT_COND
43 %s OUTPUT_AWS_COND
44 %x BUFFER_LINE
45
46 %%
47
48         {
49                 /* This is called when a new line is lexed. We only want the
50                  * first line to match to go into state BUFFER_LINE */
51                 if (context->line_number == 0) {
52                         context->line_number = 1;
53                         BEGIN(INITIAL);
54                         yy_push_state(BUFFER_LINE);
55                 }
56         }
57
58 <BUFFER_LINE>^[^\r\n]*/{EOL}? {
59         /* save whole line */
60         context->line_copy = strdup(yytext);
61
62         yyless(0);
63         yy_pop_state();
64         yy_set_bol(true);
65         yycolumn = 1;
66 }
67
68
69 <BIND_A2WS_COND>[^\n]+          { BEGIN(INITIAL); yylval.string = strdup(yytext); return STR; }
70 <OUTPUT_AWS_COND>[a-zA-Z0-9_-]+ { BEGIN(BIND_A2WS_COND); yylval.string = strdup(yytext); return OUTPUT; }
71 ^[ \t]*#[^\n]*                  { return TOKCOMMENT; }
72 <COLOR_COND>[0-9a-fA-F]+        { yylval.string = strdup(yytext); return HEX; }
73 [0-9]+                          { yylval.number = atoi(yytext); return NUMBER; }
74 mode                            { return TOKMODE; }
75 bind                            { BEGIN(BIND_COND); return TOKBIND; }
76 bindsym                         { BEGIN(BINDSYM_COND); return TOKBINDSYM; }
77 floating_modifier               { BEGIN(INITIAL); return TOKFLOATING_MODIFIER; }
78 workspace                       { BEGIN(INITIAL); return TOKWORKSPACE; }
79 output                          { BEGIN(OUTPUT_COND); return TOKOUTPUT; }
80 screen                          {
81                                   /* for compatibility until v3.φ */
82                                   ELOG("Assignments to screens are DEPRECATED and will not work. " \
83                                        "Please replace them with assignments to outputs.\n");
84                                   BEGIN(OUTPUT_COND);
85                                   return TOKOUTPUT;
86                                 }
87 terminal                        { BEGIN(BIND_AWS_COND); return TOKTERMINAL; }
88 font                            { BEGIN(BIND_AWS_COND); return TOKFONT; }
89 assign                          { BEGIN(ASSIGN_COND); return TOKASSIGN; }
90 set[^\n]*                       { return TOKCOMMENT; }
91 ipc-socket                      { BEGIN(BIND_AWS_COND); return TOKIPCSOCKET; }
92 ipc_socket                      { BEGIN(BIND_AWS_COND); return TOKIPCSOCKET; }
93 new_container                   { return TOKNEWCONTAINER; }
94 new_window                      { return TOKNEWWINDOW; }
95 focus_follows_mouse             { return TOKFOCUSFOLLOWSMOUSE; }
96 default                         { yylval.number = MODE_DEFAULT; return TOKCONTAINERMODE; }
97 stacking                        { yylval.number = MODE_STACK; return TOKCONTAINERMODE; }
98 tabbed                          { yylval.number = MODE_TABBED; return TOKCONTAINERMODE; }
99 stack-limit                     { return TOKSTACKLIMIT; }
100 cols                            { yylval.number = STACK_LIMIT_COLS; return TOKSTACKLIMIT; }
101 rows                            { yylval.number = STACK_LIMIT_ROWS; return TOKSTACKLIMIT; }
102 exec                            { BEGIN(BIND_AWS_COND); return TOKEXEC; }
103 client.focused                  { BEGIN(COLOR_COND); yylval.color = &config.client.focused; return TOKCOLOR; }
104 client.focused_inactive         { BEGIN(COLOR_COND); yylval.color = &config.client.focused_inactive; return TOKCOLOR; }
105 client.unfocused                { BEGIN(COLOR_COND); yylval.color = &config.client.unfocused; return TOKCOLOR; }
106 client.urgent                   { BEGIN(COLOR_COND); yylval.color = &config.client.urgent; return TOKCOLOR; }
107 bar.focused                     { BEGIN(COLOR_COND); yylval.color = &config.bar.focused; return TOKCOLOR; }
108 bar.unfocused                   { BEGIN(COLOR_COND); yylval.color = &config.bar.unfocused; return TOKCOLOR; }
109 bar.urgent                      { BEGIN(COLOR_COND); yylval.color = &config.bar.urgent; return TOKCOLOR; }
110 Mod1                            { yylval.number = BIND_MOD1; return MODIFIER; }
111 Mod2                            { yylval.number = BIND_MOD2; return MODIFIER; }
112 Mod3                            { yylval.number = BIND_MOD3; return MODIFIER; }
113 Mod4                            { yylval.number = BIND_MOD4; return MODIFIER; }
114 Mod5                            { yylval.number = BIND_MOD5; return MODIFIER; }
115 Mode_switch                     { yylval.number = BIND_MODE_SWITCH; return MODIFIER; }
116 control                         { return TOKCONTROL; }
117 ctrl                            { return TOKCONTROL; }
118 shift                           { return TOKSHIFT; }
119 →                               { return TOKARROW; }
120 {EOL}                           {
121                                   FREE(context->line_copy);
122                                   context->line_number++;
123                                   BEGIN(INITIAL);
124                                   yy_push_state(BUFFER_LINE);
125                                 }
126 <BIND_COND>[ \t]+               { BEGIN(BIND_AWS_COND); return WHITESPACE; }
127 <BINDSYM_COND>[ \t]+            { BEGIN(BINDSYM_AWS_COND); return WHITESPACE; }
128 <BIND_AWS_COND>[ \t]+           { BEGIN(BIND_A2WS_COND); return WHITESPACE; }
129 <BINDSYM_AWS_COND>[ \t]+        { BEGIN(BIND_A2WS_COND); return WHITESPACE; }
130 <OUTPUT_COND>[ \t]+             { BEGIN(OUTPUT_AWS_COND); return WHITESPACE; }
131 <OUTPUT_AWS_COND>[ \t]+         { BEGIN(BIND_A2WS_COND); return WHITESPACE; }
132 [ \t]+                          { return WHITESPACE; }
133 \"[^\"]+\"                      {
134                                   /* if ASSIGN_COND then */
135                                   BEGIN(INITIAL);
136                                   /* yylval will be the string, but without quotes */
137                                   char *copy = strdup(yytext+1);
138                                   copy[strlen(copy)-1] = '\0';
139                                   yylval.string = copy;
140                                   return QUOTEDSTRING;
141                                 }
142 <ASSIGN_COND>[^ \t]+            { BEGIN(INITIAL); yylval.string = strdup(yytext); return STR_NG; }
143 <BINDSYM_AWS_COND>[a-zA-Z0-9_]+ { yylval.string = strdup(yytext); return WORD; }
144 [a-zA-Z]+                       { yylval.string = strdup(yytext); return WORD; }
145 .                               { return (int)yytext[0]; }
146
147 <<EOF>> {
148         while (yy_start_stack_ptr > 0)
149                 yy_pop_state();
150         yyterminate();
151 }
152
153 %%