]> git.sur5r.net Git - i3/i3/blob - src/cfgparse.l
ipc/parser: commands can now return custom JSON replies
[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_-]+ { 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 workspace_bar                   { return TOKWORKSPACEBAR; }
97 default                         { /* yylval.number = MODE_DEFAULT; */return TOKCONTAINERMODE; }
98 stacking                        { /* yylval.number = MODE_STACK; */return TOKCONTAINERMODE; }
99 tabbed                          { /* yylval.number = MODE_TABBED; */return TOKCONTAINERMODE; }
100 stack-limit                     { return TOKSTACKLIMIT; }
101 cols                            { /* yylval.number = STACK_LIMIT_COLS; */return TOKSTACKLIMIT; }
102 rows                            { /* yylval.number = STACK_LIMIT_ROWS; */return TOKSTACKLIMIT; }
103 exec                            { BEGIN(BIND_AWS_COND); return TOKEXEC; }
104 client.focused                  { BEGIN(COLOR_COND); yylval.color = &config.client.focused; return TOKCOLOR; }
105 client.focused_inactive         { BEGIN(COLOR_COND); yylval.color = &config.client.focused_inactive; return TOKCOLOR; }
106 client.unfocused                { BEGIN(COLOR_COND); yylval.color = &config.client.unfocused; return TOKCOLOR; }
107 client.urgent                   { BEGIN(COLOR_COND); yylval.color = &config.client.urgent; return TOKCOLOR; }
108 bar.focused                     { BEGIN(COLOR_COND); yylval.color = &config.bar.focused; return TOKCOLOR; }
109 bar.unfocused                   { BEGIN(COLOR_COND); yylval.color = &config.bar.unfocused; return TOKCOLOR; }
110 bar.urgent                      { BEGIN(COLOR_COND); yylval.color = &config.bar.urgent; return TOKCOLOR; }
111 Mod1                            { yylval.number = BIND_MOD1; return MODIFIER; }
112 Mod2                            { yylval.number = BIND_MOD2; return MODIFIER; }
113 Mod3                            { yylval.number = BIND_MOD3; return MODIFIER; }
114 Mod4                            { yylval.number = BIND_MOD4; return MODIFIER; }
115 Mod5                            { yylval.number = BIND_MOD5; return MODIFIER; }
116 Mode_switch                     { yylval.number = BIND_MODE_SWITCH; return MODIFIER; }
117 control                         { return TOKCONTROL; }
118 ctrl                            { return TOKCONTROL; }
119 shift                           { return TOKSHIFT; }
120 →                               { return TOKARROW; }
121 {EOL}                           {
122                                   FREE(context->line_copy);
123                                   context->line_number++;
124                                   BEGIN(INITIAL);
125                                   yy_push_state(BUFFER_LINE);
126                                 }
127 <BIND_COND>[ \t]+               { BEGIN(BIND_AWS_COND); return WHITESPACE; }
128 <BINDSYM_COND>[ \t]+            { BEGIN(BINDSYM_AWS_COND); return WHITESPACE; }
129 <BIND_AWS_COND>[ \t]+           { BEGIN(BIND_A2WS_COND); return WHITESPACE; }
130 <BINDSYM_AWS_COND>[ \t]+        { BEGIN(BIND_A2WS_COND); return WHITESPACE; }
131 <OUTPUT_COND>[ \t]+             { BEGIN(OUTPUT_AWS_COND); return WHITESPACE; }
132 <OUTPUT_AWS_COND>[ \t]+         { BEGIN(BIND_A2WS_COND); return WHITESPACE; }
133 [ \t]+                          { return WHITESPACE; }
134 \"[^\"]+\"                      {
135                                   /* if ASSIGN_COND then */
136                                   BEGIN(INITIAL);
137                                   /* yylval will be the string, but without quotes */
138                                   char *copy = strdup(yytext+1);
139                                   copy[strlen(copy)-1] = '\0';
140                                   yylval.string = copy;
141                                   return QUOTEDSTRING;
142                                 }
143 <ASSIGN_COND>[^ \t]+            { BEGIN(INITIAL); yylval.string = strdup(yytext); return STR_NG; }
144 <BINDSYM_AWS_COND>[a-zA-Z0-9_]+ { yylval.string = strdup(yytext); return WORD; }
145 [a-zA-Z]+                       { yylval.string = strdup(yytext); return WORD; }
146 .                               { return (int)yytext[0]; }
147
148 <<EOF>> {
149         while (yy_start_stack_ptr > 0)
150                 yy_pop_state();
151         yyterminate();
152 }
153
154 %%