2 * vim:ts=4:sw=4:expandtab
22 #include "cfgparse.tab.h"
26 #define YY_DECL int yylex (struct context *context)
28 #define YY_USER_ACTION { \
29 context->first_column = yycolumn; \
30 context->last_column = yycolumn+yyleng-1; \
34 /* macro to first eat whitespace, then expect a string */
35 #define WS_STRING do { \
36 yy_push_state(WANT_STRING); \
37 yy_push_state(EAT_WHITESPACE); \
40 #define BAR_DOUBLE_COLOR do { \
41 yy_push_state(BAR_COLOR); \
42 yy_push_state(BAR_COLOR); \
72 /* This is called when a new line is lexed. We only want the
73 * first line to match to go into state BUFFER_LINE */
74 if (context->line_number == 0) {
75 context->line_number = 1;
77 yy_push_state(BUFFER_LINE);
81 <BUFFER_LINE>^[^\r\n]*/{EOL}? {
83 context->line_copy = sstrdup(yytext);
91 /* This part of the lexer handles the bar {} blocks */
92 <BAR,BAR_MODE,BAR_MODIFIER,BAR_POSITION,BAR_COLORS,BAR_COLOR>[ \t]+ { /* ignore whitespace */ ; }
93 <BAR>"{" { return '{'; }
94 <BAR>"}" { yy_pop_state(); return '}'; }
95 <BAR>^[ \t]*#[^\n]* { return TOKCOMMENT; }
96 <BAR>output { WS_STRING; return TOK_BAR_OUTPUT; }
97 <BAR>tray_output { WS_STRING; return TOK_BAR_TRAY_OUTPUT; }
98 <BAR>socket_path { WS_STRING; return TOK_BAR_SOCKET_PATH; }
99 <BAR>mode { yy_push_state(BAR_MODE); return TOK_BAR_MODE; }
100 <BAR_MODE>hide { yy_pop_state(); return TOK_BAR_HIDE; }
101 <BAR_MODE>dock { yy_pop_state(); return TOK_BAR_DOCK; }
102 <BAR>modifier { yy_push_state(BAR_MODIFIER); return TOK_BAR_MODIFIER; }
103 <BAR_MODIFIER>control { yy_pop_state(); return TOK_BAR_CONTROL; }
104 <BAR_MODIFIER>ctrl { yy_pop_state(); return TOK_BAR_CONTROL; }
105 <BAR_MODIFIER>shift { yy_pop_state(); return TOK_BAR_SHIFT; }
106 <BAR_MODIFIER>Mod1 { yy_pop_state(); return TOK_BAR_MOD1; }
107 <BAR_MODIFIER>Mod2 { yy_pop_state(); return TOK_BAR_MOD2; }
108 <BAR_MODIFIER>Mod3 { yy_pop_state(); return TOK_BAR_MOD3; }
109 <BAR_MODIFIER>Mod4 { yy_pop_state(); return TOK_BAR_MOD4; }
110 <BAR_MODIFIER>Mod5 { yy_pop_state(); return TOK_BAR_MOD5; }
111 <BAR>position { yy_push_state(BAR_POSITION); return TOK_BAR_POSITION; }
112 <BAR_POSITION>bottom { yy_pop_state(); return TOK_BAR_BOTTOM; }
113 <BAR_POSITION>top { yy_pop_state(); return TOK_BAR_TOP; }
114 <BAR>status_command { WS_STRING; return TOK_BAR_STATUS_COMMAND; }
115 <BAR>i3bar_command { WS_STRING; return TOK_BAR_I3BAR_COMMAND; }
116 <BAR>font { WS_STRING; return TOK_BAR_FONT; }
117 <BAR>workspace_buttons { return TOK_BAR_WORKSPACE_BUTTONS; }
118 <BAR>verbose { return TOK_BAR_VERBOSE; }
119 <BAR>colors { yy_push_state(BAR_COLORS); return TOK_BAR_COLORS; }
120 <BAR_COLORS>"{" { return '{'; }
121 <BAR_COLORS>"}" { yy_pop_state(); return '}'; }
122 <BAR_COLORS>^[ \t]*#[^\n]* { return TOKCOMMENT; }
123 <BAR_COLORS>background { yy_push_state(BAR_COLOR); return TOK_BAR_COLOR_BACKGROUND; }
124 <BAR_COLORS>statusline { yy_push_state(BAR_COLOR); return TOK_BAR_COLOR_STATUSLINE; }
125 <BAR_COLORS>focused_workspace { BAR_DOUBLE_COLOR; return TOK_BAR_COLOR_FOCUSED_WORKSPACE; }
126 <BAR_COLORS>active_workspace { BAR_DOUBLE_COLOR; return TOK_BAR_COLOR_ACTIVE_WORKSPACE; }
127 <BAR_COLORS>inactive_workspace { BAR_DOUBLE_COLOR; return TOK_BAR_COLOR_INACTIVE_WORKSPACE; }
128 <BAR_COLORS>urgent_workspace { BAR_DOUBLE_COLOR; return TOK_BAR_COLOR_URGENT_WORKSPACE; }
129 <BAR_COLOR>#[0-9a-fA-F]+ { yy_pop_state(); yylval.string = sstrdup(yytext); return HEXCOLOR; }
130 <BAR,BAR_COLORS,BAR_MODE,BAR_MODIFIER,BAR_POSITION>[a-zA-Z]+ { yylval.string = sstrdup(yytext); return WORD; }
134 <FOR_WINDOW_COND>"]" { yy_pop_state(); return ']'; }
136 /* this is the case for the new assign syntax
137 * that uses criteria */
139 yy_push_state(FOR_WINDOW_COND);
140 /* afterwards we will be in ASSIGN_TARGET_COND */
143 <EAT_WHITESPACE>[ \t]* { yy_pop_state(); }
144 <WANT_QSTRING>\"[^\"]+\" {
147 char *copy = sstrdup(yytext+1);
148 copy[strlen(copy)-1] = '\0';
149 yylval.string = copy;
152 <WANT_STRING>[^\n]+ { yy_pop_state(); yylval.string = sstrdup(yytext); return STR; }
153 <OUTPUT_COND>[a-zA-Z0-9_-]+ { yy_pop_state(); yylval.string = sstrdup(yytext); return OUTPUT; }
154 ^[ \t]*#[^\n]* { return TOKCOMMENT; }
155 <COLOR_COND>#[0-9a-fA-F]+ { yy_pop_state(); yylval.string = sstrdup(yytext); return HEXCOLOR; }
156 <ASSIGN_TARGET_COND>[ \t]*→[ \t]* { BEGIN(WANT_STRING); }
157 <ASSIGN_TARGET_COND>[ \t]+ { BEGIN(WANT_STRING); }
158 <EXEC>--no-startup-id { printf("no startup id\n"); yy_pop_state(); return TOK_NO_STARTUP_ID; }
159 <EXEC>. { printf("anything else: *%s*\n", yytext); yyless(0); yy_pop_state(); yy_pop_state(); }
160 [0-9]+ { yylval.number = atoi(yytext); return NUMBER; }
161 bar { yy_push_state(BAR); return TOK_BAR; }
162 mode { return TOKMODE; }
163 bind { yy_push_state(WANT_STRING); yy_push_state(EAT_WHITESPACE); yy_push_state(EAT_WHITESPACE); return TOKBINDCODE; }
164 bindcode { yy_push_state(WANT_STRING); yy_push_state(EAT_WHITESPACE); yy_push_state(EAT_WHITESPACE); return TOKBINDCODE; }
165 bindsym { yy_push_state(BINDSYM_COND); yy_push_state(EAT_WHITESPACE); return TOKBINDSYM; }
166 floating_modifier { return TOKFLOATING_MODIFIER; }
167 workspace { return TOKWORKSPACE; }
168 output { yy_push_state(OUTPUT_COND); yy_push_state(EAT_WHITESPACE); return TOKOUTPUT; }
169 terminal { WS_STRING; return TOKTERMINAL; }
170 font { WS_STRING; return TOKFONT; }
171 assign { yy_push_state(ASSIGN_TARGET_COND); yy_push_state(ASSIGN_COND); return TOKASSIGN; }
172 set[^\n]* { return TOKCOMMENT; }
173 ipc-socket { WS_STRING; return TOKIPCSOCKET; }
174 ipc_socket { WS_STRING; return TOKIPCSOCKET; }
175 restart_state { WS_STRING; return TOKRESTARTSTATE; }
176 default_orientation { return TOK_ORIENTATION; }
177 horizontal { return TOK_HORIZ; }
178 vertical { return TOK_VERT; }
179 auto { return TOK_AUTO; }
180 workspace_layout { return TOK_WORKSPACE_LAYOUT; }
181 new_window { return TOKNEWWINDOW; }
182 new_float { return TOKNEWFLOAT; }
183 normal { return TOK_NORMAL; }
184 none { return TOK_NONE; }
185 1pixel { return TOK_1PIXEL; }
186 focus_follows_mouse { return TOKFOCUSFOLLOWSMOUSE; }
187 force_focus_wrapping { return TOK_FORCE_FOCUS_WRAPPING; }
188 force_xinerama { return TOK_FORCE_XINERAMA; }
189 workspace_auto_back_and_forth { return TOK_WORKSPACE_AUTO_BAF; }
190 workspace_bar { return TOKWORKSPACEBAR; }
191 popup_during_fullscreen { return TOK_POPUP_DURING_FULLSCREEN; }
192 ignore { return TOK_IGNORE; }
193 leave_fullscreen { return TOK_LEAVE_FULLSCREEN; }
195 /* Example: for_window [class="urxvt"] border none
197 * First, we wait for the ']' that finishes a match (FOR_WINDOW_COND)
198 * Then, we require a whitespace (EAT_WHITESPACE)
199 * And the rest of the line is parsed as a string
201 yy_push_state(WANT_STRING);
202 yy_push_state(EAT_WHITESPACE);
203 yy_push_state(FOR_WINDOW_COND);
204 return TOK_FOR_WINDOW;
206 default { /* yylval.number = MODE_DEFAULT; */return TOK_DEFAULT; }
207 stacking { /* yylval.number = MODE_STACK; */return TOK_STACKING; }
208 stacked { return TOK_STACKING; }
209 tabbed { /* yylval.number = MODE_TABBED; */return TOK_TABBED; }
210 stack-limit { return TOKSTACKLIMIT; }
211 cols { /* yylval.number = STACK_LIMIT_COLS; */return TOKSTACKLIMIT; }
212 rows { /* yylval.number = STACK_LIMIT_ROWS; */return TOKSTACKLIMIT; }
213 exec { WS_STRING; yy_push_state(EXEC); yy_push_state(EAT_WHITESPACE); return TOKEXEC; }
214 exec_always { WS_STRING; yy_push_state(EXEC); yy_push_state(EAT_WHITESPACE); return TOKEXEC_ALWAYS; }
215 client.background { yy_push_state(COLOR_COND); yylval.single_color = &config.client.background; return TOKSINGLECOLOR; }
216 client.focused { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.focused; return TOKCOLOR; }
217 client.focused_inactive { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.focused_inactive; return TOKCOLOR; }
218 client.unfocused { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.unfocused; return TOKCOLOR; }
219 client.urgent { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.urgent; return TOKCOLOR; }
220 bar.focused { yy_push_state(COLOR_COND); yylval.color = &config.bar.focused; return TOKCOLOR; }
221 bar.unfocused { yy_push_state(COLOR_COND); yylval.color = &config.bar.unfocused; return TOKCOLOR; }
222 bar.urgent { yy_push_state(COLOR_COND); yylval.color = &config.bar.urgent; return TOKCOLOR; }
223 Mod1 { yylval.number = BIND_MOD1; return MODIFIER; }
224 Mod2 { yylval.number = BIND_MOD2; return MODIFIER; }
225 Mod3 { yylval.number = BIND_MOD3; return MODIFIER; }
226 Mod4 { yylval.number = BIND_MOD4; return MODIFIER; }
227 Mod5 { yylval.number = BIND_MOD5; return MODIFIER; }
228 Mode_switch { yylval.number = BIND_MODE_SWITCH; return MODIFIER; }
229 control { return TOKCONTROL; }
230 ctrl { return TOKCONTROL; }
231 shift { return TOKSHIFT; }
233 class { yy_push_state(WANT_QSTRING); return TOK_CLASS; }
234 instance { yy_push_state(WANT_QSTRING); return TOK_INSTANCE; }
235 window_role { yy_push_state(WANT_QSTRING); return TOK_WINDOW_ROLE; }
236 id { yy_push_state(WANT_QSTRING); return TOK_ID; }
237 con_id { yy_push_state(WANT_QSTRING); return TOK_CON_ID; }
238 con_mark { yy_push_state(WANT_QSTRING); return TOK_MARK; }
239 title { yy_push_state(WANT_QSTRING); return TOK_TITLE; }
242 FREE(context->line_copy);
243 context->line_number++;
244 yy_push_state(BUFFER_LINE);
246 <BINDSYM_COND>[ \t]+ { yy_pop_state(); yy_push_state(WANT_STRING); }
247 <OUTPUT_COND>[ \t]+ { yy_pop_state(); yy_push_state(WANT_STRING); }
248 [ \t]+ { /* ignore whitespace */ ; }
250 /* if ASSIGN_COND then */
251 if (yy_start_stack_ptr > 0)
253 /* yylval will be the string, but without quotes */
254 char *copy = sstrdup(yytext+1);
255 copy[strlen(copy)-1] = '\0';
256 yylval.string = copy;
259 <ASSIGN_COND>[^ \t\"\[]+ { BEGIN(ASSIGN_TARGET_COND); yylval.string = sstrdup(yytext); return STR_NG; }
260 <BINDSYM_COND>[a-zA-Z0-9_]+ { yylval.string = sstrdup(yytext); return WORD; }
261 [a-zA-Z]+ { yylval.string = sstrdup(yytext); return WORD; }
262 . { return (int)yytext[0]; }
265 while (yy_start_stack_ptr > 0)