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