21 #include "cfgparse.tab.h"
25 #define YY_DECL int yylex (struct context *context)
27 #define YY_USER_ACTION { \
28 context->first_column = yycolumn; \
29 context->last_column = yycolumn+yyleng-1; \
54 /* This is called when a new line is lexed. We only want the
55 * first line to match to go into state BUFFER_LINE */
56 if (context->line_number == 0) {
57 context->line_number = 1;
59 yy_push_state(BUFFER_LINE);
63 <BUFFER_LINE>^[^\r\n]*/{EOL}? {
65 context->line_copy = strdup(yytext);
74 <FOR_WINDOW_COND>"]" { yy_pop_state(); return ']'; }
75 <REQUIRE_WS>[ \t]* { yy_pop_state(); return WHITESPACE; }
76 <WANT_QSTRING>\"[^\"]+\" {
79 char *copy = sstrdup(yytext+1);
80 copy[strlen(copy)-1] = '\0';
84 <BIND_A2WS_COND>[^\n]+ { BEGIN(INITIAL); yylval.string = strdup(yytext); return STR; }
85 <OUTPUT_AWS_COND>[a-zA-Z0-9_-]+ { yylval.string = strdup(yytext); return OUTPUT; }
86 ^[ \t]*#[^\n]* { return TOKCOMMENT; }
87 <COLOR_COND>[0-9a-fA-F]+ { yylval.string = strdup(yytext); return HEX; }
88 [0-9]+ { yylval.number = atoi(yytext); return NUMBER; }
89 mode { return TOKMODE; }
90 bind { BEGIN(BINDCODE_COND); return TOKBINDCODE; }
91 bindcode { BEGIN(BINDCODE_COND); return TOKBINDCODE; }
92 bindsym { BEGIN(BINDSYM_COND); return TOKBINDSYM; }
93 floating_modifier { BEGIN(INITIAL); return TOKFLOATING_MODIFIER; }
94 workspace { BEGIN(INITIAL); return TOKWORKSPACE; }
95 output { BEGIN(OUTPUT_COND); return TOKOUTPUT; }
97 /* for compatibility until v3.φ */
98 ELOG("Assignments to screens are DEPRECATED and will not work. " \
99 "Please replace them with assignments to outputs.\n");
103 terminal { BEGIN(BIND_AWS_COND); return TOKTERMINAL; }
104 font { BEGIN(BIND_AWS_COND); return TOKFONT; }
105 assign { BEGIN(ASSIGN_COND); return TOKASSIGN; }
106 set[^\n]* { return TOKCOMMENT; }
107 ipc-socket { BEGIN(BIND_AWS_COND); return TOKIPCSOCKET; }
108 ipc_socket { BEGIN(BIND_AWS_COND); return TOKIPCSOCKET; }
109 restart_state { BEGIN(BIND_AWS_COND); return TOKRESTARTSTATE; }
110 default_orientation { return TOK_ORIENTATION; }
111 horizontal { return TOK_HORIZ; }
112 vertical { return TOK_VERT; }
113 auto { return TOK_AUTO; }
114 workspace_layout { return TOK_WORKSPACE_LAYOUT; }
115 new_window { return TOKNEWWINDOW; }
116 normal { return TOK_NORMAL; }
117 none { return TOK_NONE; }
118 1pixel { return TOK_1PIXEL; }
119 focus_follows_mouse { return TOKFOCUSFOLLOWSMOUSE; }
120 workspace_bar { return TOKWORKSPACEBAR; }
121 popup_during_fullscreen { return TOK_POPUP_DURING_FULLSCREEN; }
122 ignore { return TOK_IGNORE; }
123 leave_fullscreen { return TOK_LEAVE_FULLSCREEN; }
125 /* Example: for_window [class="urxvt"] border none
127 * First, we wait for the ']' that finishes a match (FOR_WINDOW_COND)
128 * Then, we require a whitespace (REQUIRE_WS)
129 * And the rest of the line is parsed as a string
131 yy_push_state(BIND_A2WS_COND);
132 yy_push_state(REQUIRE_WS);
133 yy_push_state(FOR_WINDOW_COND);
134 return TOK_FOR_WINDOW;
136 default { /* yylval.number = MODE_DEFAULT; */return TOK_DEFAULT; }
137 stacking { /* yylval.number = MODE_STACK; */return TOK_STACKING; }
138 stacked { return TOK_STACKING; }
139 tabbed { /* yylval.number = MODE_TABBED; */return TOK_TABBED; }
140 stack-limit { return TOKSTACKLIMIT; }
141 cols { /* yylval.number = STACK_LIMIT_COLS; */return TOKSTACKLIMIT; }
142 rows { /* yylval.number = STACK_LIMIT_ROWS; */return TOKSTACKLIMIT; }
143 exec { BEGIN(BIND_AWS_COND); return TOKEXEC; }
144 client.background { BEGIN(COLOR_COND); yylval.single_color = &config.client.background; return TOKSINGLECOLOR; }
145 client.focused { BEGIN(COLOR_COND); yylval.color = &config.client.focused; return TOKCOLOR; }
146 client.focused_inactive { BEGIN(COLOR_COND); yylval.color = &config.client.focused_inactive; return TOKCOLOR; }
147 client.unfocused { BEGIN(COLOR_COND); yylval.color = &config.client.unfocused; return TOKCOLOR; }
148 client.urgent { BEGIN(COLOR_COND); yylval.color = &config.client.urgent; return TOKCOLOR; }
149 bar.focused { BEGIN(COLOR_COND); yylval.color = &config.bar.focused; return TOKCOLOR; }
150 bar.unfocused { BEGIN(COLOR_COND); yylval.color = &config.bar.unfocused; return TOKCOLOR; }
151 bar.urgent { BEGIN(COLOR_COND); yylval.color = &config.bar.urgent; return TOKCOLOR; }
152 Mod1 { yylval.number = BIND_MOD1; return MODIFIER; }
153 Mod2 { yylval.number = BIND_MOD2; return MODIFIER; }
154 Mod3 { yylval.number = BIND_MOD3; return MODIFIER; }
155 Mod4 { yylval.number = BIND_MOD4; return MODIFIER; }
156 Mod5 { yylval.number = BIND_MOD5; return MODIFIER; }
157 Mode_switch { yylval.number = BIND_MODE_SWITCH; return MODIFIER; }
158 control { return TOKCONTROL; }
159 ctrl { return TOKCONTROL; }
160 shift { return TOKSHIFT; }
161 → { return TOKARROW; }
163 class { yy_push_state(WANT_QSTRING); return TOK_CLASS; }
164 id { yy_push_state(WANT_QSTRING); return TOK_ID; }
165 con_id { yy_push_state(WANT_QSTRING); return TOK_CON_ID; }
166 con_mark { yy_push_state(WANT_QSTRING); return TOK_MARK; }
167 title { yy_push_state(WANT_QSTRING); return TOK_TITLE; }
170 FREE(context->line_copy);
171 context->line_number++;
173 yy_push_state(BUFFER_LINE);
175 <BINDCODE_COND>[ \t]+ { BEGIN(BIND_AWS_COND); return WHITESPACE; }
176 <BINDSYM_COND>[ \t]+ { BEGIN(BINDSYM_AWS_COND); return WHITESPACE; }
177 <BIND_AWS_COND>[ \t]+ { BEGIN(BIND_A2WS_COND); return WHITESPACE; }
178 <BINDSYM_AWS_COND>[ \t]+ { BEGIN(BIND_A2WS_COND); return WHITESPACE; }
179 <OUTPUT_COND>[ \t]+ { BEGIN(OUTPUT_AWS_COND); return WHITESPACE; }
180 <OUTPUT_AWS_COND>[ \t]+ { BEGIN(BIND_A2WS_COND); return WHITESPACE; }
181 [ \t]+ { return WHITESPACE; }
183 /* if ASSIGN_COND then */
185 /* yylval will be the string, but without quotes */
186 char *copy = strdup(yytext+1);
187 copy[strlen(copy)-1] = '\0';
188 yylval.string = copy;
191 <ASSIGN_COND>[^ \t]+ { BEGIN(INITIAL); yylval.string = strdup(yytext); return STR_NG; }
192 <BINDSYM_AWS_COND>[a-zA-Z0-9_]+ { yylval.string = strdup(yytext); return WORD; }
193 [a-zA-Z]+ { yylval.string = strdup(yytext); return WORD; }
194 . { return (int)yytext[0]; }
197 while (yy_start_stack_ptr > 0)